4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2008
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
15 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
16 #define ZFCP_REQ_NO_QTCB 0x00000008
18 static void zfcp_fsf_request_timeout_handler(unsigned long data)
20 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
21 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
25 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
26 unsigned long timeout)
28 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
29 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
30 fsf_req->timer.expires = jiffies + timeout;
31 add_timer(&fsf_req->timer);
34 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
36 BUG_ON(!fsf_req->erp_action);
37 fsf_req->timer.function = zfcp_erp_timeout_handler;
38 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
39 fsf_req->timer.expires = jiffies + 30 * HZ;
40 add_timer(&fsf_req->timer);
43 /* association between FSF command and FSF QTCB type */
44 static u32 fsf_qtcb_type[] = {
45 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
46 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
55 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
56 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
60 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
62 u16 subtable = table >> 16;
63 u16 rule = table & 0xffff;
64 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
66 if (subtable && subtable < ARRAY_SIZE(act_type))
67 dev_warn(&adapter->ccw_device->dev,
68 "Access denied according to ACT rule type %s, "
69 "rule %d\n", act_type[subtable], rule);
72 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
73 struct zfcp_port *port)
75 struct fsf_qtcb_header *header = &req->qtcb->header;
76 dev_warn(&req->adapter->ccw_device->dev,
77 "Access denied to port 0x%016Lx\n",
78 (unsigned long long)port->wwpn);
79 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
80 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
81 zfcp_erp_port_access_denied(port, 55, req);
82 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
85 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
86 struct zfcp_unit *unit)
88 struct fsf_qtcb_header *header = &req->qtcb->header;
89 dev_warn(&req->adapter->ccw_device->dev,
90 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
91 (unsigned long long)unit->fcp_lun,
92 (unsigned long long)unit->port->wwpn);
93 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
95 zfcp_erp_unit_access_denied(unit, 59, req);
96 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
99 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
101 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
102 "operational because of an unsupported FC class\n");
103 zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
108 * zfcp_fsf_req_free - free memory used by fsf request
109 * @fsf_req: pointer to struct zfcp_fsf_req
111 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
113 if (likely(req->pool)) {
114 mempool_free(req, req->pool);
119 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
125 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
126 * @adapter: pointer to struct zfcp_adapter
128 * Never ever call this without shutting down the adapter first.
129 * Otherwise the adapter would continue using and corrupting s390 storage.
130 * Included BUG_ON() call to ensure this is done.
131 * ERP is supposed to be the only user of this function.
133 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
135 struct zfcp_fsf_req *req, *tmp;
137 LIST_HEAD(remove_queue);
140 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
141 spin_lock_irqsave(&adapter->req_list_lock, flags);
142 for (i = 0; i < REQUEST_LIST_SIZE; i++)
143 list_splice_init(&adapter->req_list[i], &remove_queue);
144 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
146 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
147 list_del(&req->list);
148 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
149 zfcp_fsf_req_complete(req);
153 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
155 struct fsf_status_read_buffer *sr_buf = req->data;
156 struct zfcp_adapter *adapter = req->adapter;
157 struct zfcp_port *port;
158 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
161 read_lock_irqsave(&zfcp_data.config_lock, flags);
162 list_for_each_entry(port, &adapter->port_list_head, list)
163 if (port->d_id == d_id) {
164 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
165 switch (sr_buf->status_subtype) {
166 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
167 zfcp_erp_port_reopen(port, 0, 101, req);
169 case FSF_STATUS_READ_SUB_ERROR_PORT:
170 zfcp_erp_port_shutdown(port, 0, 122, req);
175 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
178 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
179 struct fsf_link_down_info *link_down)
181 struct zfcp_adapter *adapter = req->adapter;
183 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
186 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
191 switch (link_down->error_code) {
192 case FSF_PSQ_LINK_NO_LIGHT:
193 dev_warn(&req->adapter->ccw_device->dev,
194 "There is no light signal from the local "
195 "fibre channel cable\n");
197 case FSF_PSQ_LINK_WRAP_PLUG:
198 dev_warn(&req->adapter->ccw_device->dev,
199 "There is a wrap plug instead of a fibre "
202 case FSF_PSQ_LINK_NO_FCP:
203 dev_warn(&req->adapter->ccw_device->dev,
204 "The adjacent fibre channel node does not "
207 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
208 dev_warn(&req->adapter->ccw_device->dev,
209 "The FCP device is suspended because of a "
210 "firmware update\n");
212 case FSF_PSQ_LINK_INVALID_WWPN:
213 dev_warn(&req->adapter->ccw_device->dev,
214 "The FCP device detected a WWPN that is "
215 "duplicate or not valid\n");
217 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
218 dev_warn(&req->adapter->ccw_device->dev,
219 "The fibre channel fabric does not support NPIV\n");
221 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
222 dev_warn(&req->adapter->ccw_device->dev,
223 "The FCP adapter cannot support more NPIV ports\n");
225 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
226 dev_warn(&req->adapter->ccw_device->dev,
227 "The adjacent switch cannot support "
228 "more NPIV ports\n");
230 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
231 dev_warn(&req->adapter->ccw_device->dev,
232 "The FCP adapter could not log in to the "
233 "fibre channel fabric\n");
235 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
236 dev_warn(&req->adapter->ccw_device->dev,
237 "The WWPN assignment file on the FCP adapter "
238 "has been damaged\n");
240 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
241 dev_warn(&req->adapter->ccw_device->dev,
242 "The mode table on the FCP adapter "
243 "has been damaged\n");
245 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
246 dev_warn(&req->adapter->ccw_device->dev,
247 "All NPIV ports on the FCP adapter have "
251 dev_warn(&req->adapter->ccw_device->dev,
252 "The link between the FCP adapter and "
253 "the FC fabric is down\n");
256 zfcp_erp_adapter_failed(adapter, id, req);
259 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
261 struct fsf_status_read_buffer *sr_buf = req->data;
262 struct fsf_link_down_info *ldi =
263 (struct fsf_link_down_info *) &sr_buf->payload;
265 switch (sr_buf->status_subtype) {
266 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
267 zfcp_fsf_link_down_info_eval(req, 38, ldi);
269 case FSF_STATUS_READ_SUB_FDISC_FAILED:
270 zfcp_fsf_link_down_info_eval(req, 39, ldi);
272 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
273 zfcp_fsf_link_down_info_eval(req, 40, NULL);
277 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
279 struct zfcp_adapter *adapter = req->adapter;
280 struct fsf_status_read_buffer *sr_buf = req->data;
282 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
283 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
284 mempool_free(sr_buf, adapter->pool.data_status_read);
285 zfcp_fsf_req_free(req);
289 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
291 switch (sr_buf->status_type) {
292 case FSF_STATUS_READ_PORT_CLOSED:
293 zfcp_fsf_status_read_port_closed(req);
295 case FSF_STATUS_READ_INCOMING_ELS:
296 zfcp_fc_incoming_els(req);
298 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
300 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
301 dev_warn(&adapter->ccw_device->dev,
302 "The error threshold for checksum statistics "
303 "has been exceeded\n");
304 zfcp_hba_dbf_event_berr(adapter, req);
306 case FSF_STATUS_READ_LINK_DOWN:
307 zfcp_fsf_status_read_link_down(req);
309 case FSF_STATUS_READ_LINK_UP:
310 dev_info(&adapter->ccw_device->dev,
311 "The local link has been restored\n");
312 /* All ports should be marked as ready to run again */
313 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
314 ZFCP_STATUS_COMMON_RUNNING,
316 zfcp_erp_adapter_reopen(adapter,
317 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
318 ZFCP_STATUS_COMMON_ERP_FAILED,
321 case FSF_STATUS_READ_NOTIFICATION_LOST:
322 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
323 zfcp_erp_adapter_access_changed(adapter, 135, req);
324 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
325 schedule_work(&adapter->scan_work);
327 case FSF_STATUS_READ_CFDC_UPDATED:
328 zfcp_erp_adapter_access_changed(adapter, 136, req);
330 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
331 adapter->adapter_features = sr_buf->payload.word[0];
335 mempool_free(sr_buf, adapter->pool.data_status_read);
336 zfcp_fsf_req_free(req);
338 atomic_inc(&adapter->stat_miss);
339 queue_work(zfcp_data.work_queue, &adapter->stat_work);
342 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
344 switch (req->qtcb->header.fsf_status_qual.word[0]) {
345 case FSF_SQ_FCP_RSP_AVAILABLE:
346 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
347 case FSF_SQ_NO_RETRY_POSSIBLE:
348 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
350 case FSF_SQ_COMMAND_ABORTED:
351 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
353 case FSF_SQ_NO_RECOM:
354 dev_err(&req->adapter->ccw_device->dev,
355 "The FCP adapter reported a problem "
356 "that cannot be recovered\n");
357 zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
360 /* all non-return stats set FSFREQ_ERROR*/
361 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
364 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
366 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
369 switch (req->qtcb->header.fsf_status) {
370 case FSF_UNKNOWN_COMMAND:
371 dev_err(&req->adapter->ccw_device->dev,
372 "The FCP adapter does not recognize the command 0x%x\n",
373 req->qtcb->header.fsf_command);
374 zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
375 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
377 case FSF_ADAPTER_STATUS_AVAILABLE:
378 zfcp_fsf_fsfstatus_qual_eval(req);
383 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
385 struct zfcp_adapter *adapter = req->adapter;
386 struct fsf_qtcb *qtcb = req->qtcb;
387 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
389 zfcp_hba_dbf_event_fsf_response(req);
391 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
392 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
393 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
397 switch (qtcb->prefix.prot_status) {
399 case FSF_PROT_FSF_STATUS_PRESENTED:
401 case FSF_PROT_QTCB_VERSION_ERROR:
402 dev_err(&adapter->ccw_device->dev,
403 "QTCB version 0x%x not supported by FCP adapter "
404 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
405 psq->word[0], psq->word[1]);
406 zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
408 case FSF_PROT_ERROR_STATE:
409 case FSF_PROT_SEQ_NUMB_ERROR:
410 zfcp_erp_adapter_reopen(adapter, 0, 98, req);
411 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
413 case FSF_PROT_UNSUPP_QTCB_TYPE:
414 dev_err(&adapter->ccw_device->dev,
415 "The QTCB type is not supported by the FCP adapter\n");
416 zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
418 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
419 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
422 case FSF_PROT_DUPLICATE_REQUEST_ID:
423 dev_err(&adapter->ccw_device->dev,
424 "0x%Lx is an ambiguous request identifier\n",
425 (unsigned long long)qtcb->bottom.support.req_handle);
426 zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
428 case FSF_PROT_LINK_DOWN:
429 zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
430 /* FIXME: reopening adapter now? better wait for link up */
431 zfcp_erp_adapter_reopen(adapter, 0, 79, req);
433 case FSF_PROT_REEST_QUEUE:
434 /* All ports should be marked as ready to run again */
435 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
436 ZFCP_STATUS_COMMON_RUNNING,
438 zfcp_erp_adapter_reopen(adapter,
439 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
440 ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
443 dev_err(&adapter->ccw_device->dev,
444 "0x%x is not a valid transfer protocol status\n",
445 qtcb->prefix.prot_status);
446 zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
448 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
452 * zfcp_fsf_req_complete - process completion of a FSF request
453 * @fsf_req: The FSF request that has been completed.
455 * When a request has been completed either from the FCP adapter,
456 * or it has been dismissed due to a queue shutdown, this function
457 * is called to process the completion status and trigger further
458 * events related to the FSF request.
460 void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
462 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
463 zfcp_fsf_status_read_handler(req);
467 del_timer(&req->timer);
468 zfcp_fsf_protstatus_eval(req);
469 zfcp_fsf_fsfstatus_eval(req);
473 zfcp_erp_notify(req->erp_action, 0);
474 req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
476 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
477 zfcp_fsf_req_free(req);
479 /* notify initiator waiting for the requests completion */
481 * FIXME: Race! We must not access fsf_req here as it might have been
482 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
483 * flag. It's an improbable case. But, we have the same paranoia for
484 * the cleanup flag already.
485 * Might better be handled using complete()?
486 * (setting the flag and doing wakeup ought to be atomic
487 * with regard to checking the flag as long as waitqueue is
488 * part of the to be released structure)
490 wake_up(&req->completion_wq);
493 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
495 struct fsf_qtcb_bottom_config *bottom;
496 struct zfcp_adapter *adapter = req->adapter;
497 struct Scsi_Host *shost = adapter->scsi_host;
499 bottom = &req->qtcb->bottom.config;
502 memcpy(req->data, bottom, sizeof(*bottom));
504 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
505 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
506 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
507 fc_host_speed(shost) = bottom->fc_link_speed;
508 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
510 adapter->hydra_version = bottom->adapter_type;
511 adapter->timer_ticks = bottom->timer_interval;
513 if (fc_host_permanent_port_name(shost) == -1)
514 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
516 switch (bottom->fc_topology) {
518 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
519 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
520 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
521 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
523 case FSF_TOPO_FABRIC:
524 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
527 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
529 dev_err(&adapter->ccw_device->dev,
530 "Unknown or unsupported arbitrated loop "
531 "fibre channel topology detected\n");
532 zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
539 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
541 struct zfcp_adapter *adapter = req->adapter;
542 struct fsf_qtcb *qtcb = req->qtcb;
543 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
544 struct Scsi_Host *shost = adapter->scsi_host;
546 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
549 adapter->fsf_lic_version = bottom->lic_version;
550 adapter->adapter_features = bottom->adapter_features;
551 adapter->connection_features = bottom->connection_features;
552 adapter->peer_wwpn = 0;
553 adapter->peer_wwnn = 0;
554 adapter->peer_d_id = 0;
556 switch (qtcb->header.fsf_status) {
558 if (zfcp_fsf_exchange_config_evaluate(req))
561 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
562 dev_err(&adapter->ccw_device->dev,
563 "FCP adapter maximum QTCB size (%d bytes) "
565 bottom->max_qtcb_size);
566 zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
569 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
572 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
573 fc_host_node_name(shost) = 0;
574 fc_host_port_name(shost) = 0;
575 fc_host_port_id(shost) = 0;
576 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
577 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
578 adapter->hydra_version = 0;
580 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
583 zfcp_fsf_link_down_info_eval(req, 42,
584 &qtcb->header.fsf_status_qual.link_down_info);
587 zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
591 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
592 adapter->hardware_version = bottom->hardware_version;
593 memcpy(fc_host_serial_number(shost), bottom->serial_number,
594 min(FC_SERIAL_NUMBER_SIZE, 17));
595 EBCASC(fc_host_serial_number(shost),
596 min(FC_SERIAL_NUMBER_SIZE, 17));
599 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
600 dev_err(&adapter->ccw_device->dev,
601 "The FCP adapter only supports newer "
602 "control block versions\n");
603 zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
606 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
607 dev_err(&adapter->ccw_device->dev,
608 "The FCP adapter only supports older "
609 "control block versions\n");
610 zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
614 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
616 struct zfcp_adapter *adapter = req->adapter;
617 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
618 struct Scsi_Host *shost = adapter->scsi_host;
621 memcpy(req->data, bottom, sizeof(*bottom));
623 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
624 fc_host_permanent_port_name(shost) = bottom->wwpn;
626 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
627 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
628 fc_host_supported_speeds(shost) = bottom->supported_speed;
631 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
633 struct fsf_qtcb *qtcb = req->qtcb;
635 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
638 switch (qtcb->header.fsf_status) {
640 zfcp_fsf_exchange_port_evaluate(req);
642 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
643 zfcp_fsf_exchange_port_evaluate(req);
644 zfcp_fsf_link_down_info_eval(req, 43,
645 &qtcb->header.fsf_status_qual.link_down_info);
650 static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
651 __releases(&adapter->req_q_lock)
652 __acquires(&adapter->req_q_lock)
654 struct zfcp_qdio_queue *req_q = &adapter->req_q;
657 if (atomic_read(&req_q->count) <= -REQUEST_LIST_SIZE)
659 if (atomic_read(&req_q->count) > 0)
662 atomic_dec(&req_q->count);
663 spin_unlock_bh(&adapter->req_q_lock);
664 ret = wait_event_interruptible_timeout(adapter->request_wq,
665 atomic_read(&req_q->count) >= 0,
667 spin_lock_bh(&adapter->req_q_lock);
668 atomic_inc(&req_q->count);
673 atomic_inc(&adapter->qdio_outb_full);
677 static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
679 struct zfcp_fsf_req *req;
680 req = mempool_alloc(pool, GFP_ATOMIC);
683 memset(req, 0, sizeof(*req));
688 static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
690 struct zfcp_fsf_req_qtcb *qtcb;
693 qtcb = mempool_alloc(pool, GFP_ATOMIC);
695 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
700 memset(qtcb, 0, sizeof(*qtcb));
701 qtcb->fsf_req.qtcb = &qtcb->qtcb;
702 qtcb->fsf_req.pool = pool;
704 return &qtcb->fsf_req;
707 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
708 u32 fsf_cmd, int req_flags,
711 struct qdio_buffer_element *sbale;
713 struct zfcp_fsf_req *req;
714 struct zfcp_qdio_queue *req_q = &adapter->req_q;
716 if (req_flags & ZFCP_REQ_NO_QTCB)
717 req = zfcp_fsf_alloc_noqtcb(pool);
719 req = zfcp_fsf_alloc_qtcb(pool);
722 return ERR_PTR(-EIO);
724 if (adapter->req_no == 0)
727 INIT_LIST_HEAD(&req->list);
728 init_timer(&req->timer);
729 init_waitqueue_head(&req->completion_wq);
731 req->adapter = adapter;
732 req->fsf_command = fsf_cmd;
733 req->req_id = adapter->req_no;
734 req->sbal_number = 1;
735 req->sbal_first = req_q->first;
736 req->sbal_last = req_q->first;
739 sbale = zfcp_qdio_sbale_req(req);
740 sbale[0].addr = (void *) req->req_id;
741 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
743 if (likely(req->qtcb)) {
744 req->qtcb->prefix.req_seq_no = req->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);
762 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
763 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
768 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
770 struct zfcp_adapter *adapter = req->adapter;
774 /* put allocated FSF request into hash table */
775 spin_lock_irqsave(&adapter->req_list_lock, flags);
776 idx = zfcp_reqlist_hash(req->req_id);
777 list_add_tail(&req->list, &adapter->req_list[idx]);
778 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
780 req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
781 req->issued = get_clock();
782 if (zfcp_qdio_send(req)) {
783 del_timer(&req->timer);
784 spin_lock_irqsave(&adapter->req_list_lock, flags);
785 /* lookup request again, list might have changed */
786 if (zfcp_reqlist_find_safe(adapter, req))
787 zfcp_reqlist_remove(adapter, req);
788 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
789 zfcp_erp_adapter_reopen(adapter, 0, 116, req);
793 /* Don't increase for unsolicited status */
795 adapter->fsf_req_seq_no++;
802 * zfcp_fsf_status_read - send status read request
803 * @adapter: pointer to struct zfcp_adapter
804 * @req_flags: request flags
805 * Returns: 0 on success, ERROR otherwise
807 int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
809 struct zfcp_fsf_req *req;
810 struct fsf_status_read_buffer *sr_buf;
811 struct qdio_buffer_element *sbale;
814 spin_lock_bh(&adapter->req_q_lock);
815 if (zfcp_fsf_req_sbal_get(adapter))
818 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
820 adapter->pool.fsf_req_status_read);
822 retval = PTR_ERR(req);
826 sbale = zfcp_qdio_sbale_req(req);
827 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
828 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
831 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
836 memset(sr_buf, 0, sizeof(*sr_buf));
838 sbale = zfcp_qdio_sbale_curr(req);
839 sbale->addr = (void *) sr_buf;
840 sbale->length = sizeof(*sr_buf);
842 retval = zfcp_fsf_req_send(req);
844 goto failed_req_send;
849 mempool_free(sr_buf, adapter->pool.data_status_read);
851 zfcp_fsf_req_free(req);
852 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
854 spin_unlock_bh(&adapter->req_q_lock);
858 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
860 struct zfcp_unit *unit = req->data;
861 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
863 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
866 switch (req->qtcb->header.fsf_status) {
867 case FSF_PORT_HANDLE_NOT_VALID:
868 if (fsq->word[0] == fsq->word[1]) {
869 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
871 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
874 case FSF_LUN_HANDLE_NOT_VALID:
875 if (fsq->word[0] == fsq->word[1]) {
876 zfcp_erp_port_reopen(unit->port, 0, 105, req);
877 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
880 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
881 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
884 zfcp_erp_port_boxed(unit->port, 47, req);
885 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
886 ZFCP_STATUS_FSFREQ_RETRY;
889 zfcp_erp_unit_boxed(unit, 48, req);
890 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
891 ZFCP_STATUS_FSFREQ_RETRY;
893 case FSF_ADAPTER_STATUS_AVAILABLE:
894 switch (fsq->word[0]) {
895 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
896 zfcp_test_link(unit->port);
897 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
898 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
903 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
909 * zfcp_fsf_abort_fcp_command - abort running SCSI command
910 * @old_req_id: unsigned long
911 * @unit: pointer to struct zfcp_unit
912 * Returns: pointer to struct zfcp_fsf_req
915 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
916 struct zfcp_unit *unit)
918 struct qdio_buffer_element *sbale;
919 struct zfcp_fsf_req *req = NULL;
920 struct zfcp_adapter *adapter = unit->port->adapter;
922 spin_lock_bh(&adapter->req_q_lock);
923 if (zfcp_fsf_req_sbal_get(adapter))
925 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
926 0, adapter->pool.fsf_req_abort);
932 if (unlikely(!(atomic_read(&unit->status) &
933 ZFCP_STATUS_COMMON_UNBLOCKED)))
936 sbale = zfcp_qdio_sbale_req(req);
937 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
938 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
941 req->handler = zfcp_fsf_abort_fcp_command_handler;
942 req->qtcb->header.lun_handle = unit->handle;
943 req->qtcb->header.port_handle = unit->port->handle;
944 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
946 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
947 if (!zfcp_fsf_req_send(req))
951 zfcp_fsf_req_free(req);
954 spin_unlock_bh(&adapter->req_q_lock);
958 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
960 struct zfcp_adapter *adapter = req->adapter;
961 struct zfcp_send_ct *send_ct = req->data;
962 struct fsf_qtcb_header *header = &req->qtcb->header;
964 send_ct->status = -EINVAL;
966 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
969 switch (header->fsf_status) {
971 zfcp_san_dbf_event_ct_response(req);
974 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
975 zfcp_fsf_class_not_supp(req);
977 case FSF_ADAPTER_STATUS_AVAILABLE:
978 switch (header->fsf_status_qual.word[0]){
979 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
980 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
981 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
985 case FSF_ACCESS_DENIED:
988 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
989 ZFCP_STATUS_FSFREQ_RETRY;
991 case FSF_PORT_HANDLE_NOT_VALID:
992 zfcp_erp_adapter_reopen(adapter, 0, 106, req);
993 case FSF_GENERIC_COMMAND_REJECTED:
994 case FSF_PAYLOAD_SIZE_MISMATCH:
995 case FSF_REQUEST_SIZE_TOO_LARGE:
996 case FSF_RESPONSE_SIZE_TOO_LARGE:
997 case FSF_SBAL_MISMATCH:
998 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1003 if (send_ct->handler)
1004 send_ct->handler(send_ct->handler_data);
1007 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1008 struct scatterlist *sg_req,
1009 struct scatterlist *sg_resp,
1012 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
1013 u32 feat = req->adapter->adapter_features;
1016 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1017 if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
1018 !sg_is_last(sg_req) || !sg_is_last(sg_resp))
1021 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1022 sbale[2].addr = sg_virt(sg_req);
1023 sbale[2].length = sg_req->length;
1024 sbale[3].addr = sg_virt(sg_resp);
1025 sbale[3].length = sg_resp->length;
1026 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1030 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1034 req->qtcb->bottom.support.req_buf_length = bytes;
1035 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1037 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1038 sg_resp, max_sbals);
1041 req->qtcb->bottom.support.resp_buf_length = bytes;
1047 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1048 * @ct: pointer to struct zfcp_send_ct with data for request
1049 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1050 * @erp_action: if non-null the Generic Service request sent within ERP
1052 int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1053 struct zfcp_erp_action *erp_action)
1055 struct zfcp_wka_port *wka_port = ct->wka_port;
1056 struct zfcp_adapter *adapter = wka_port->adapter;
1057 struct zfcp_fsf_req *req;
1060 spin_lock_bh(&adapter->req_q_lock);
1061 if (zfcp_fsf_req_sbal_get(adapter))
1064 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1065 ZFCP_REQ_AUTO_CLEANUP, pool);
1071 ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
1072 FSF_MAX_SBALS_PER_REQ);
1076 req->handler = zfcp_fsf_send_ct_handler;
1077 req->qtcb->header.port_handle = wka_port->handle;
1078 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1079 req->qtcb->bottom.support.timeout = ct->timeout;
1082 zfcp_san_dbf_event_ct_request(req);
1085 erp_action->fsf_req = req;
1086 req->erp_action = erp_action;
1087 zfcp_fsf_start_erp_timer(req);
1089 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1091 ret = zfcp_fsf_req_send(req);
1098 zfcp_fsf_req_free(req);
1100 erp_action->fsf_req = NULL;
1102 spin_unlock_bh(&adapter->req_q_lock);
1106 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1108 struct zfcp_send_els *send_els = req->data;
1109 struct zfcp_port *port = send_els->port;
1110 struct fsf_qtcb_header *header = &req->qtcb->header;
1112 send_els->status = -EINVAL;
1114 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1115 goto skip_fsfstatus;
1117 switch (header->fsf_status) {
1119 zfcp_san_dbf_event_els_response(req);
1120 send_els->status = 0;
1122 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1123 zfcp_fsf_class_not_supp(req);
1125 case FSF_ADAPTER_STATUS_AVAILABLE:
1126 switch (header->fsf_status_qual.word[0]){
1127 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1128 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1129 zfcp_test_link(port);
1131 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1132 case FSF_SQ_RETRY_IF_POSSIBLE:
1133 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1137 case FSF_ELS_COMMAND_REJECTED:
1138 case FSF_PAYLOAD_SIZE_MISMATCH:
1139 case FSF_REQUEST_SIZE_TOO_LARGE:
1140 case FSF_RESPONSE_SIZE_TOO_LARGE:
1142 case FSF_ACCESS_DENIED:
1143 zfcp_fsf_access_denied_port(req, port);
1145 case FSF_SBAL_MISMATCH:
1146 /* should never occure, avoided in zfcp_fsf_send_els */
1149 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1153 if (send_els->handler)
1154 send_els->handler(send_els->handler_data);
1158 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1159 * @els: pointer to struct zfcp_send_els with data for the command
1161 int zfcp_fsf_send_els(struct zfcp_send_els *els)
1163 struct zfcp_fsf_req *req;
1164 struct zfcp_adapter *adapter = els->adapter;
1165 struct fsf_qtcb_bottom_support *bottom;
1168 if (unlikely(!(atomic_read(&els->port->status) &
1169 ZFCP_STATUS_COMMON_UNBLOCKED)))
1172 spin_lock_bh(&adapter->req_q_lock);
1173 if (zfcp_fsf_req_sbal_get(adapter))
1175 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1176 ZFCP_REQ_AUTO_CLEANUP, NULL);
1182 ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
1187 bottom = &req->qtcb->bottom.support;
1188 req->handler = zfcp_fsf_send_els_handler;
1189 bottom->d_id = els->d_id;
1190 bottom->service_class = FSF_CLASS_3;
1191 bottom->timeout = 2 * R_A_TOV;
1194 zfcp_san_dbf_event_els_request(req);
1196 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1197 ret = zfcp_fsf_req_send(req);
1204 zfcp_fsf_req_free(req);
1206 spin_unlock_bh(&adapter->req_q_lock);
1210 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1212 struct qdio_buffer_element *sbale;
1213 struct zfcp_fsf_req *req;
1214 struct zfcp_adapter *adapter = erp_action->adapter;
1217 spin_lock_bh(&adapter->req_q_lock);
1218 if (zfcp_fsf_req_sbal_get(adapter))
1220 req = zfcp_fsf_req_create(adapter,
1221 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1222 ZFCP_REQ_AUTO_CLEANUP,
1223 adapter->pool.fsf_req_erp);
1225 retval = PTR_ERR(req);
1229 sbale = zfcp_qdio_sbale_req(req);
1230 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1231 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1233 req->qtcb->bottom.config.feature_selection =
1235 FSF_FEATURE_LUN_SHARING |
1236 FSF_FEATURE_NOTIFICATION_LOST |
1237 FSF_FEATURE_UPDATE_ALERT;
1238 req->erp_action = erp_action;
1239 req->handler = zfcp_fsf_exchange_config_data_handler;
1240 erp_action->fsf_req = req;
1242 zfcp_fsf_start_erp_timer(req);
1243 retval = zfcp_fsf_req_send(req);
1245 zfcp_fsf_req_free(req);
1246 erp_action->fsf_req = NULL;
1249 spin_unlock_bh(&adapter->req_q_lock);
1253 int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1254 struct fsf_qtcb_bottom_config *data)
1256 struct qdio_buffer_element *sbale;
1257 struct zfcp_fsf_req *req = NULL;
1260 spin_lock_bh(&adapter->req_q_lock);
1261 if (zfcp_fsf_req_sbal_get(adapter))
1264 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1267 retval = PTR_ERR(req);
1271 sbale = zfcp_qdio_sbale_req(req);
1272 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1273 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1274 req->handler = zfcp_fsf_exchange_config_data_handler;
1276 req->qtcb->bottom.config.feature_selection =
1278 FSF_FEATURE_LUN_SHARING |
1279 FSF_FEATURE_NOTIFICATION_LOST |
1280 FSF_FEATURE_UPDATE_ALERT;
1285 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1286 retval = zfcp_fsf_req_send(req);
1288 spin_unlock_bh(&adapter->req_q_lock);
1290 wait_event(req->completion_wq,
1291 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1293 zfcp_fsf_req_free(req);
1299 * zfcp_fsf_exchange_port_data - request information about local port
1300 * @erp_action: ERP action for the adapter for which port data is requested
1301 * Returns: 0 on success, error otherwise
1303 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1305 struct qdio_buffer_element *sbale;
1306 struct zfcp_fsf_req *req;
1307 struct zfcp_adapter *adapter = erp_action->adapter;
1310 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1313 spin_lock_bh(&adapter->req_q_lock);
1314 if (zfcp_fsf_req_sbal_get(adapter))
1316 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1317 ZFCP_REQ_AUTO_CLEANUP,
1318 adapter->pool.fsf_req_erp);
1320 retval = PTR_ERR(req);
1324 sbale = zfcp_qdio_sbale_req(req);
1325 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1326 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1328 req->handler = zfcp_fsf_exchange_port_data_handler;
1329 req->erp_action = erp_action;
1330 erp_action->fsf_req = req;
1332 zfcp_fsf_start_erp_timer(req);
1333 retval = zfcp_fsf_req_send(req);
1335 zfcp_fsf_req_free(req);
1336 erp_action->fsf_req = NULL;
1339 spin_unlock_bh(&adapter->req_q_lock);
1344 * zfcp_fsf_exchange_port_data_sync - request information about local port
1345 * @adapter: pointer to struct zfcp_adapter
1346 * @data: pointer to struct fsf_qtcb_bottom_port
1347 * Returns: 0 on success, error otherwise
1349 int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1350 struct fsf_qtcb_bottom_port *data)
1352 struct qdio_buffer_element *sbale;
1353 struct zfcp_fsf_req *req = NULL;
1356 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1359 spin_lock_bh(&adapter->req_q_lock);
1360 if (zfcp_fsf_req_sbal_get(adapter))
1363 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1366 retval = PTR_ERR(req);
1373 sbale = zfcp_qdio_sbale_req(req);
1374 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1375 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1377 req->handler = zfcp_fsf_exchange_port_data_handler;
1378 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1379 retval = zfcp_fsf_req_send(req);
1381 spin_unlock_bh(&adapter->req_q_lock);
1383 wait_event(req->completion_wq,
1384 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1385 zfcp_fsf_req_free(req);
1390 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1392 struct zfcp_port *port = req->data;
1393 struct fsf_qtcb_header *header = &req->qtcb->header;
1394 struct fsf_plogi *plogi;
1396 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1399 switch (header->fsf_status) {
1400 case FSF_PORT_ALREADY_OPEN:
1402 case FSF_ACCESS_DENIED:
1403 zfcp_fsf_access_denied_port(req, port);
1405 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1406 dev_warn(&req->adapter->ccw_device->dev,
1407 "Not enough FCP adapter resources to open "
1408 "remote port 0x%016Lx\n",
1409 (unsigned long long)port->wwpn);
1410 zfcp_erp_port_failed(port, 31, req);
1411 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1413 case FSF_ADAPTER_STATUS_AVAILABLE:
1414 switch (header->fsf_status_qual.word[0]) {
1415 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1416 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1417 case FSF_SQ_NO_RETRY_POSSIBLE:
1418 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1423 port->handle = header->port_handle;
1424 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1425 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1426 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1427 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1429 /* check whether D_ID has changed during open */
1431 * FIXME: This check is not airtight, as the FCP channel does
1432 * not monitor closures of target port connections caused on
1433 * the remote side. Thus, they might miss out on invalidating
1434 * locally cached WWPNs (and other N_Port parameters) of gone
1435 * target ports. So, our heroic attempt to make things safe
1436 * could be undermined by 'open port' response data tagged with
1437 * obsolete WWPNs. Another reason to monitor potential
1438 * connection closures ourself at least (by interpreting
1439 * incoming ELS' and unsolicited status). It just crosses my
1440 * mind that one should be able to cross-check by means of
1441 * another GID_PN straight after a port has been opened.
1442 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1444 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1445 if (req->qtcb->bottom.support.els1_length >=
1446 FSF_PLOGI_MIN_LEN) {
1447 if (plogi->serv_param.wwpn != port->wwpn)
1450 port->wwnn = plogi->serv_param.wwnn;
1451 zfcp_fc_plogi_evaluate(port, plogi);
1455 case FSF_UNKNOWN_OP_SUBTYPE:
1456 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1462 * zfcp_fsf_open_port - create and send open port request
1463 * @erp_action: pointer to struct zfcp_erp_action
1464 * Returns: 0 on success, error otherwise
1466 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1468 struct qdio_buffer_element *sbale;
1469 struct zfcp_adapter *adapter = erp_action->adapter;
1470 struct zfcp_fsf_req *req;
1473 spin_lock_bh(&adapter->req_q_lock);
1474 if (zfcp_fsf_req_sbal_get(adapter))
1477 req = zfcp_fsf_req_create(adapter,
1478 FSF_QTCB_OPEN_PORT_WITH_DID,
1479 ZFCP_REQ_AUTO_CLEANUP,
1480 adapter->pool.fsf_req_erp);
1482 retval = PTR_ERR(req);
1486 sbale = zfcp_qdio_sbale_req(req);
1487 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1488 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1490 req->handler = zfcp_fsf_open_port_handler;
1491 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
1492 req->data = erp_action->port;
1493 req->erp_action = erp_action;
1494 erp_action->fsf_req = req;
1496 zfcp_fsf_start_erp_timer(req);
1497 retval = zfcp_fsf_req_send(req);
1499 zfcp_fsf_req_free(req);
1500 erp_action->fsf_req = NULL;
1503 spin_unlock_bh(&adapter->req_q_lock);
1507 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1509 struct zfcp_port *port = req->data;
1511 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1514 switch (req->qtcb->header.fsf_status) {
1515 case FSF_PORT_HANDLE_NOT_VALID:
1516 zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
1517 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1519 case FSF_ADAPTER_STATUS_AVAILABLE:
1522 zfcp_erp_modify_port_status(port, 33, req,
1523 ZFCP_STATUS_COMMON_OPEN,
1530 * zfcp_fsf_close_port - create and send close port request
1531 * @erp_action: pointer to struct zfcp_erp_action
1532 * Returns: 0 on success, error otherwise
1534 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1536 struct qdio_buffer_element *sbale;
1537 struct zfcp_adapter *adapter = erp_action->adapter;
1538 struct zfcp_fsf_req *req;
1541 spin_lock_bh(&adapter->req_q_lock);
1542 if (zfcp_fsf_req_sbal_get(adapter))
1545 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1546 ZFCP_REQ_AUTO_CLEANUP,
1547 adapter->pool.fsf_req_erp);
1549 retval = PTR_ERR(req);
1553 sbale = zfcp_qdio_sbale_req(req);
1554 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1555 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1557 req->handler = zfcp_fsf_close_port_handler;
1558 req->data = erp_action->port;
1559 req->erp_action = erp_action;
1560 req->qtcb->header.port_handle = erp_action->port->handle;
1561 erp_action->fsf_req = req;
1563 zfcp_fsf_start_erp_timer(req);
1564 retval = zfcp_fsf_req_send(req);
1566 zfcp_fsf_req_free(req);
1567 erp_action->fsf_req = NULL;
1570 spin_unlock_bh(&adapter->req_q_lock);
1574 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1576 struct zfcp_wka_port *wka_port = req->data;
1577 struct fsf_qtcb_header *header = &req->qtcb->header;
1579 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1580 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1584 switch (header->fsf_status) {
1585 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1586 dev_warn(&req->adapter->ccw_device->dev,
1587 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1588 case FSF_ADAPTER_STATUS_AVAILABLE:
1589 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1590 case FSF_ACCESS_DENIED:
1591 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1593 case FSF_PORT_ALREADY_OPEN:
1596 wka_port->handle = header->port_handle;
1597 wka_port->status = ZFCP_WKA_PORT_ONLINE;
1600 wake_up(&wka_port->completion_wq);
1604 * zfcp_fsf_open_wka_port - create and send open wka-port request
1605 * @wka_port: pointer to struct zfcp_wka_port
1606 * Returns: 0 on success, error otherwise
1608 int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1610 struct qdio_buffer_element *sbale;
1611 struct zfcp_adapter *adapter = wka_port->adapter;
1612 struct zfcp_fsf_req *req;
1615 spin_lock_bh(&adapter->req_q_lock);
1616 if (zfcp_fsf_req_sbal_get(adapter))
1619 req = zfcp_fsf_req_create(adapter,
1620 FSF_QTCB_OPEN_PORT_WITH_DID,
1621 ZFCP_REQ_AUTO_CLEANUP,
1622 adapter->pool.fsf_req_erp);
1623 if (unlikely(IS_ERR(req))) {
1624 retval = PTR_ERR(req);
1628 sbale = zfcp_qdio_sbale_req(req);
1629 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1630 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1632 req->handler = zfcp_fsf_open_wka_port_handler;
1633 req->qtcb->bottom.support.d_id = wka_port->d_id;
1634 req->data = wka_port;
1636 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1637 retval = zfcp_fsf_req_send(req);
1639 zfcp_fsf_req_free(req);
1641 spin_unlock_bh(&adapter->req_q_lock);
1645 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1647 struct zfcp_wka_port *wka_port = req->data;
1649 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1650 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1651 zfcp_erp_adapter_reopen(wka_port->adapter, 0, 84, req);
1654 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1655 wake_up(&wka_port->completion_wq);
1659 * zfcp_fsf_close_wka_port - create and send close wka port request
1660 * @erp_action: pointer to struct zfcp_erp_action
1661 * Returns: 0 on success, error otherwise
1663 int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
1665 struct qdio_buffer_element *sbale;
1666 struct zfcp_adapter *adapter = wka_port->adapter;
1667 struct zfcp_fsf_req *req;
1670 spin_lock_bh(&adapter->req_q_lock);
1671 if (zfcp_fsf_req_sbal_get(adapter))
1674 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1675 ZFCP_REQ_AUTO_CLEANUP,
1676 adapter->pool.fsf_req_erp);
1677 if (unlikely(IS_ERR(req))) {
1678 retval = PTR_ERR(req);
1682 sbale = zfcp_qdio_sbale_req(req);
1683 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1684 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1686 req->handler = zfcp_fsf_close_wka_port_handler;
1687 req->data = wka_port;
1688 req->qtcb->header.port_handle = wka_port->handle;
1690 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1691 retval = zfcp_fsf_req_send(req);
1693 zfcp_fsf_req_free(req);
1695 spin_unlock_bh(&adapter->req_q_lock);
1699 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1701 struct zfcp_port *port = req->data;
1702 struct fsf_qtcb_header *header = &req->qtcb->header;
1703 struct zfcp_unit *unit;
1705 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1708 switch (header->fsf_status) {
1709 case FSF_PORT_HANDLE_NOT_VALID:
1710 zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
1711 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1713 case FSF_ACCESS_DENIED:
1714 zfcp_fsf_access_denied_port(req, port);
1716 case FSF_PORT_BOXED:
1717 zfcp_erp_port_boxed(port, 50, req);
1718 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1719 ZFCP_STATUS_FSFREQ_RETRY;
1720 /* can't use generic zfcp_erp_modify_port_status because
1721 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1722 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1723 list_for_each_entry(unit, &port->unit_list_head, list)
1724 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1727 case FSF_ADAPTER_STATUS_AVAILABLE:
1728 switch (header->fsf_status_qual.word[0]) {
1729 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1731 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1732 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1737 /* can't use generic zfcp_erp_modify_port_status because
1738 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1740 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1741 list_for_each_entry(unit, &port->unit_list_head, list)
1742 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1749 * zfcp_fsf_close_physical_port - close physical port
1750 * @erp_action: pointer to struct zfcp_erp_action
1751 * Returns: 0 on success
1753 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1755 struct qdio_buffer_element *sbale;
1756 struct zfcp_adapter *adapter = erp_action->adapter;
1757 struct zfcp_fsf_req *req;
1760 spin_lock_bh(&adapter->req_q_lock);
1761 if (zfcp_fsf_req_sbal_get(adapter))
1764 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1765 ZFCP_REQ_AUTO_CLEANUP,
1766 adapter->pool.fsf_req_erp);
1768 retval = PTR_ERR(req);
1772 sbale = zfcp_qdio_sbale_req(req);
1773 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1774 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1776 req->data = erp_action->port;
1777 req->qtcb->header.port_handle = erp_action->port->handle;
1778 req->erp_action = erp_action;
1779 req->handler = zfcp_fsf_close_physical_port_handler;
1780 erp_action->fsf_req = req;
1782 zfcp_fsf_start_erp_timer(req);
1783 retval = zfcp_fsf_req_send(req);
1785 zfcp_fsf_req_free(req);
1786 erp_action->fsf_req = NULL;
1789 spin_unlock_bh(&adapter->req_q_lock);
1793 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1795 struct zfcp_adapter *adapter = req->adapter;
1796 struct zfcp_unit *unit = req->data;
1797 struct fsf_qtcb_header *header = &req->qtcb->header;
1798 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1799 struct fsf_queue_designator *queue_designator =
1800 &header->fsf_status_qual.fsf_queue_designator;
1801 int exclusive, readwrite;
1803 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1806 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1807 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1808 ZFCP_STATUS_UNIT_SHARED |
1809 ZFCP_STATUS_UNIT_READONLY,
1812 switch (header->fsf_status) {
1814 case FSF_PORT_HANDLE_NOT_VALID:
1815 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
1817 case FSF_LUN_ALREADY_OPEN:
1819 case FSF_ACCESS_DENIED:
1820 zfcp_fsf_access_denied_unit(req, unit);
1821 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1822 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1824 case FSF_PORT_BOXED:
1825 zfcp_erp_port_boxed(unit->port, 51, req);
1826 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1827 ZFCP_STATUS_FSFREQ_RETRY;
1829 case FSF_LUN_SHARING_VIOLATION:
1830 if (header->fsf_status_qual.word[0])
1831 dev_warn(&adapter->ccw_device->dev,
1832 "LUN 0x%Lx on port 0x%Lx is already in "
1833 "use by CSS%d, MIF Image ID %x\n",
1834 (unsigned long long)unit->fcp_lun,
1835 (unsigned long long)unit->port->wwpn,
1836 queue_designator->cssid,
1837 queue_designator->hla);
1839 zfcp_act_eval_err(adapter,
1840 header->fsf_status_qual.word[2]);
1841 zfcp_erp_unit_access_denied(unit, 60, req);
1842 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1843 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1844 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1846 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1847 dev_warn(&adapter->ccw_device->dev,
1848 "No handle is available for LUN "
1849 "0x%016Lx on port 0x%016Lx\n",
1850 (unsigned long long)unit->fcp_lun,
1851 (unsigned long long)unit->port->wwpn);
1852 zfcp_erp_unit_failed(unit, 34, req);
1854 case FSF_INVALID_COMMAND_OPTION:
1855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1857 case FSF_ADAPTER_STATUS_AVAILABLE:
1858 switch (header->fsf_status_qual.word[0]) {
1859 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1860 zfcp_test_link(unit->port);
1862 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1863 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1869 unit->handle = header->lun_handle;
1870 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1872 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1873 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1874 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
1875 exclusive = (bottom->lun_access_info &
1876 FSF_UNIT_ACCESS_EXCLUSIVE);
1877 readwrite = (bottom->lun_access_info &
1878 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1881 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1885 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1887 dev_info(&adapter->ccw_device->dev,
1888 "SCSI device at LUN 0x%016Lx on port "
1889 "0x%016Lx opened read-only\n",
1890 (unsigned long long)unit->fcp_lun,
1891 (unsigned long long)unit->port->wwpn);
1894 if (exclusive && !readwrite) {
1895 dev_err(&adapter->ccw_device->dev,
1896 "Exclusive read-only access not "
1897 "supported (unit 0x%016Lx, "
1899 (unsigned long long)unit->fcp_lun,
1900 (unsigned long long)unit->port->wwpn);
1901 zfcp_erp_unit_failed(unit, 35, req);
1902 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1903 zfcp_erp_unit_shutdown(unit, 0, 80, req);
1904 } else if (!exclusive && readwrite) {
1905 dev_err(&adapter->ccw_device->dev,
1906 "Shared read-write access not "
1907 "supported (unit 0x%016Lx, port "
1909 (unsigned long long)unit->fcp_lun,
1910 (unsigned long long)unit->port->wwpn);
1911 zfcp_erp_unit_failed(unit, 36, req);
1912 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1913 zfcp_erp_unit_shutdown(unit, 0, 81, req);
1921 * zfcp_fsf_open_unit - open unit
1922 * @erp_action: pointer to struct zfcp_erp_action
1923 * Returns: 0 on success, error otherwise
1925 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1927 struct qdio_buffer_element *sbale;
1928 struct zfcp_adapter *adapter = erp_action->adapter;
1929 struct zfcp_fsf_req *req;
1932 spin_lock_bh(&adapter->req_q_lock);
1933 if (zfcp_fsf_req_sbal_get(adapter))
1936 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1937 ZFCP_REQ_AUTO_CLEANUP,
1938 adapter->pool.fsf_req_erp);
1940 retval = PTR_ERR(req);
1944 sbale = zfcp_qdio_sbale_req(req);
1945 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1946 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1948 req->qtcb->header.port_handle = erp_action->port->handle;
1949 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1950 req->handler = zfcp_fsf_open_unit_handler;
1951 req->data = erp_action->unit;
1952 req->erp_action = erp_action;
1953 erp_action->fsf_req = req;
1955 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1956 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1958 zfcp_fsf_start_erp_timer(req);
1959 retval = zfcp_fsf_req_send(req);
1961 zfcp_fsf_req_free(req);
1962 erp_action->fsf_req = NULL;
1965 spin_unlock_bh(&adapter->req_q_lock);
1969 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
1971 struct zfcp_unit *unit = req->data;
1973 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1976 switch (req->qtcb->header.fsf_status) {
1977 case FSF_PORT_HANDLE_NOT_VALID:
1978 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
1979 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1981 case FSF_LUN_HANDLE_NOT_VALID:
1982 zfcp_erp_port_reopen(unit->port, 0, 111, req);
1983 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1985 case FSF_PORT_BOXED:
1986 zfcp_erp_port_boxed(unit->port, 52, req);
1987 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1988 ZFCP_STATUS_FSFREQ_RETRY;
1990 case FSF_ADAPTER_STATUS_AVAILABLE:
1991 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1992 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1993 zfcp_test_link(unit->port);
1995 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1996 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2001 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2007 * zfcp_fsf_close_unit - close zfcp unit
2008 * @erp_action: pointer to struct zfcp_unit
2009 * Returns: 0 on success, error otherwise
2011 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2013 struct qdio_buffer_element *sbale;
2014 struct zfcp_adapter *adapter = erp_action->adapter;
2015 struct zfcp_fsf_req *req;
2018 spin_lock_bh(&adapter->req_q_lock);
2019 if (zfcp_fsf_req_sbal_get(adapter))
2021 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
2022 ZFCP_REQ_AUTO_CLEANUP,
2023 adapter->pool.fsf_req_erp);
2025 retval = PTR_ERR(req);
2029 sbale = zfcp_qdio_sbale_req(req);
2030 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2031 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2033 req->qtcb->header.port_handle = erp_action->port->handle;
2034 req->qtcb->header.lun_handle = erp_action->unit->handle;
2035 req->handler = zfcp_fsf_close_unit_handler;
2036 req->data = erp_action->unit;
2037 req->erp_action = erp_action;
2038 erp_action->fsf_req = req;
2040 zfcp_fsf_start_erp_timer(req);
2041 retval = zfcp_fsf_req_send(req);
2043 zfcp_fsf_req_free(req);
2044 erp_action->fsf_req = NULL;
2047 spin_unlock_bh(&adapter->req_q_lock);
2051 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2053 lat_rec->sum += lat;
2054 lat_rec->min = min(lat_rec->min, lat);
2055 lat_rec->max = max(lat_rec->max, lat);
2058 static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
2060 struct fsf_qual_latency_info *lat_inf;
2061 struct latency_cont *lat;
2062 struct zfcp_unit *unit = req->unit;
2064 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
2066 switch (req->qtcb->bottom.io.data_direction) {
2067 case FSF_DATADIR_READ:
2068 lat = &unit->latencies.read;
2070 case FSF_DATADIR_WRITE:
2071 lat = &unit->latencies.write;
2073 case FSF_DATADIR_CMND:
2074 lat = &unit->latencies.cmd;
2080 spin_lock(&unit->latencies.lock);
2081 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2082 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2084 spin_unlock(&unit->latencies.lock);
2087 #ifdef CONFIG_BLK_DEV_IO_TRACE
2088 static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2090 struct fsf_qual_latency_info *lat_inf;
2091 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
2092 struct request *req = scsi_cmnd->request;
2093 struct zfcp_blk_drv_data trace;
2094 int ticks = fsf_req->adapter->timer_ticks;
2097 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2098 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2099 trace.flags |= ZFCP_BLK_LAT_VALID;
2100 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2101 trace.channel_lat = lat_inf->channel_lat * ticks;
2102 trace.fabric_lat = lat_inf->fabric_lat * ticks;
2104 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2105 trace.flags |= ZFCP_BLK_REQ_ERROR;
2106 trace.inb_usage = fsf_req->qdio_inb_usage;
2107 trace.outb_usage = fsf_req->qdio_outb_usage;
2109 blk_add_driver_data(req->q, req, &trace, sizeof(trace));
2112 static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2117 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2119 struct scsi_cmnd *scpnt;
2120 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2121 &(req->qtcb->bottom.io.fcp_rsp);
2123 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2124 unsigned long flags;
2126 read_lock_irqsave(&req->adapter->abort_lock, flags);
2129 if (unlikely(!scpnt)) {
2130 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2134 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
2135 set_host_byte(scpnt, DID_SOFT_ERROR);
2136 goto skip_fsfstatus;
2139 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2140 set_host_byte(scpnt, DID_ERROR);
2141 goto skip_fsfstatus;
2144 set_msg_byte(scpnt, COMMAND_COMPLETE);
2146 scpnt->result |= fcp_rsp_iu->scsi_status;
2148 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2149 zfcp_fsf_req_latency(req);
2151 zfcp_fsf_trace_latency(req);
2153 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
2154 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
2155 set_host_byte(scpnt, DID_OK);
2157 set_host_byte(scpnt, DID_ERROR);
2158 goto skip_fsfstatus;
2162 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
2163 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2164 fcp_rsp_iu->fcp_rsp_len;
2165 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
2166 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
2168 memcpy(scpnt->sense_buffer,
2169 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
2172 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
2173 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2174 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2176 set_host_byte(scpnt, DID_ERROR);
2179 if (scpnt->result != 0)
2180 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
2181 else if (scpnt->retries > 0)
2182 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
2184 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
2186 scpnt->host_scribble = NULL;
2187 (scpnt->scsi_done) (scpnt);
2189 * We must hold this lock until scsi_done has been called.
2190 * Otherwise we may call scsi_done after abort regarding this
2191 * command has completed.
2192 * Note: scsi_done must not block!
2194 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2197 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2199 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2200 &(req->qtcb->bottom.io.fcp_rsp);
2201 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2203 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2204 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2205 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2209 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2211 struct zfcp_unit *unit;
2212 struct fsf_qtcb_header *header = &req->qtcb->header;
2214 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2219 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2220 goto skip_fsfstatus;
2222 switch (header->fsf_status) {
2223 case FSF_HANDLE_MISMATCH:
2224 case FSF_PORT_HANDLE_NOT_VALID:
2225 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
2226 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2228 case FSF_FCPLUN_NOT_VALID:
2229 case FSF_LUN_HANDLE_NOT_VALID:
2230 zfcp_erp_port_reopen(unit->port, 0, 113, req);
2231 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2233 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2234 zfcp_fsf_class_not_supp(req);
2236 case FSF_ACCESS_DENIED:
2237 zfcp_fsf_access_denied_unit(req, unit);
2239 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2240 dev_err(&req->adapter->ccw_device->dev,
2241 "Incorrect direction %d, unit 0x%016Lx on port "
2242 "0x%016Lx closed\n",
2243 req->qtcb->bottom.io.data_direction,
2244 (unsigned long long)unit->fcp_lun,
2245 (unsigned long long)unit->port->wwpn);
2246 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
2247 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2249 case FSF_CMND_LENGTH_NOT_VALID:
2250 dev_err(&req->adapter->ccw_device->dev,
2251 "Incorrect CDB length %d, unit 0x%016Lx on "
2252 "port 0x%016Lx closed\n",
2253 req->qtcb->bottom.io.fcp_cmnd_length,
2254 (unsigned long long)unit->fcp_lun,
2255 (unsigned long long)unit->port->wwpn);
2256 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
2257 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2259 case FSF_PORT_BOXED:
2260 zfcp_erp_port_boxed(unit->port, 53, req);
2261 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2262 ZFCP_STATUS_FSFREQ_RETRY;
2265 zfcp_erp_unit_boxed(unit, 54, req);
2266 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2267 ZFCP_STATUS_FSFREQ_RETRY;
2269 case FSF_ADAPTER_STATUS_AVAILABLE:
2270 if (header->fsf_status_qual.word[0] ==
2271 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2272 zfcp_test_link(unit->port);
2273 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2277 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2278 zfcp_fsf_send_fcp_ctm_handler(req);
2280 zfcp_fsf_send_fcp_command_task_handler(req);
2282 zfcp_unit_put(unit);
2286 static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2291 * fcp_dl_addr = start address of fcp_cmnd structure +
2292 * size of fixed part + size of dynamically sized add_dcp_cdb field
2293 * SEE FCP-2 documentation
2295 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2296 (fcp_cmd->add_fcp_cdb_length << 2));
2297 *fcp_dl_ptr = fcp_dl;
2301 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2302 * @unit: unit where command is sent to
2303 * @scsi_cmnd: scsi command to be sent
2305 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2306 struct scsi_cmnd *scsi_cmnd)
2308 struct zfcp_fsf_req *req;
2309 struct fcp_cmnd_iu *fcp_cmnd_iu;
2310 unsigned int sbtype;
2311 int real_bytes, retval = -EIO;
2312 struct zfcp_adapter *adapter = unit->port->adapter;
2314 if (unlikely(!(atomic_read(&unit->status) &
2315 ZFCP_STATUS_COMMON_UNBLOCKED)))
2318 spin_lock(&adapter->req_q_lock);
2319 if (atomic_read(&adapter->req_q.count) <= 0) {
2320 atomic_inc(&adapter->qdio_outb_full);
2323 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
2324 ZFCP_REQ_AUTO_CLEANUP,
2325 adapter->pool.fsf_req_scsi);
2327 retval = PTR_ERR(req);
2331 zfcp_unit_get(unit);
2333 req->data = scsi_cmnd;
2334 req->handler = zfcp_fsf_send_fcp_command_handler;
2335 req->qtcb->header.lun_handle = unit->handle;
2336 req->qtcb->header.port_handle = unit->port->handle;
2337 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2339 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2341 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2342 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2344 * set depending on data direction:
2345 * data direction bits in SBALE (SB Type)
2346 * data direction bits in QTCB
2347 * data direction bits in FCP_CMND IU
2349 switch (scsi_cmnd->sc_data_direction) {
2351 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2352 sbtype = SBAL_FLAGS0_TYPE_READ;
2354 case DMA_FROM_DEVICE:
2355 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2356 sbtype = SBAL_FLAGS0_TYPE_READ;
2357 fcp_cmnd_iu->rddata = 1;
2360 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2361 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2362 fcp_cmnd_iu->wddata = 1;
2364 case DMA_BIDIRECTIONAL:
2367 goto failed_scsi_cmnd;
2370 if (likely((scsi_cmnd->device->simple_tags) ||
2371 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2372 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2373 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2375 fcp_cmnd_iu->task_attribute = UNTAGGED;
2377 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2378 fcp_cmnd_iu->add_fcp_cdb_length =
2379 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2381 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2383 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2384 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
2386 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2387 scsi_sglist(scsi_cmnd),
2388 FSF_MAX_SBALS_PER_REQ);
2389 if (unlikely(real_bytes < 0)) {
2390 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2393 dev_err(&adapter->ccw_device->dev,
2394 "Oversize data package, unit 0x%016Lx "
2395 "on port 0x%016Lx closed\n",
2396 (unsigned long long)unit->fcp_lun,
2397 (unsigned long long)unit->port->wwpn);
2398 zfcp_erp_unit_shutdown(unit, 0, 131, req);
2401 goto failed_scsi_cmnd;
2404 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2406 retval = zfcp_fsf_req_send(req);
2407 if (unlikely(retval))
2408 goto failed_scsi_cmnd;
2413 zfcp_unit_put(unit);
2414 zfcp_fsf_req_free(req);
2415 scsi_cmnd->host_scribble = NULL;
2417 spin_unlock(&adapter->req_q_lock);
2422 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2423 * @unit: pointer to struct zfcp_unit
2424 * @tm_flags: unsigned byte for task management flags
2425 * Returns: on success pointer to struct fsf_req, NULL otherwise
2427 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2429 struct qdio_buffer_element *sbale;
2430 struct zfcp_fsf_req *req = NULL;
2431 struct fcp_cmnd_iu *fcp_cmnd_iu;
2432 struct zfcp_adapter *adapter = unit->port->adapter;
2434 if (unlikely(!(atomic_read(&unit->status) &
2435 ZFCP_STATUS_COMMON_UNBLOCKED)))
2438 spin_lock_bh(&adapter->req_q_lock);
2439 if (zfcp_fsf_req_sbal_get(adapter))
2441 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
2442 adapter->pool.fsf_req_scsi);
2448 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2450 req->handler = zfcp_fsf_send_fcp_command_handler;
2451 req->qtcb->header.lun_handle = unit->handle;
2452 req->qtcb->header.port_handle = unit->port->handle;
2453 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2454 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2455 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2458 sbale = zfcp_qdio_sbale_req(req);
2459 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2460 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2462 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2463 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2464 fcp_cmnd_iu->task_management_flags = tm_flags;
2466 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2467 if (!zfcp_fsf_req_send(req))
2470 zfcp_fsf_req_free(req);
2473 spin_unlock_bh(&adapter->req_q_lock);
2477 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2479 if (req->qtcb->header.fsf_status != FSF_GOOD)
2480 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2484 * zfcp_fsf_control_file - control file upload/download
2485 * @adapter: pointer to struct zfcp_adapter
2486 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2487 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2489 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2490 struct zfcp_fsf_cfdc *fsf_cfdc)
2492 struct qdio_buffer_element *sbale;
2493 struct zfcp_fsf_req *req = NULL;
2494 struct fsf_qtcb_bottom_support *bottom;
2495 int direction, retval = -EIO, bytes;
2497 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2498 return ERR_PTR(-EOPNOTSUPP);
2500 switch (fsf_cfdc->command) {
2501 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2502 direction = SBAL_FLAGS0_TYPE_WRITE;
2504 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2505 direction = SBAL_FLAGS0_TYPE_READ;
2508 return ERR_PTR(-EINVAL);
2511 spin_lock_bh(&adapter->req_q_lock);
2512 if (zfcp_fsf_req_sbal_get(adapter))
2515 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
2521 req->handler = zfcp_fsf_control_file_handler;
2523 sbale = zfcp_qdio_sbale_req(req);
2524 sbale[0].flags |= direction;
2526 bottom = &req->qtcb->bottom.support;
2527 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2528 bottom->option = fsf_cfdc->option;
2530 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2531 FSF_MAX_SBALS_PER_REQ);
2532 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2534 zfcp_fsf_req_free(req);
2538 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2539 retval = zfcp_fsf_req_send(req);
2541 spin_unlock_bh(&adapter->req_q_lock);
2544 wait_event(req->completion_wq,
2545 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2548 return ERR_PTR(retval);