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_sbal_available(struct zfcp_adapter *adapter)
652 if (atomic_read(&adapter->req_q.count) > 0)
654 atomic_inc(&adapter->qdio_outb_full);
658 static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
659 __releases(&adapter->req_q_lock)
660 __acquires(&adapter->req_q_lock)
662 struct zfcp_qdio_queue *req_q = &adapter->req_q;
665 if (atomic_read(&req_q->count) <= -REQUEST_LIST_SIZE)
667 if (atomic_read(&req_q->count) > 0)
670 atomic_dec(&req_q->count);
671 spin_unlock_bh(&adapter->req_q_lock);
672 ret = wait_event_interruptible_timeout(adapter->request_wq,
673 atomic_read(&req_q->count) >= 0,
675 spin_lock_bh(&adapter->req_q_lock);
676 atomic_inc(&req_q->count);
681 atomic_inc(&adapter->qdio_outb_full);
685 static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
687 struct zfcp_fsf_req *req;
688 req = mempool_alloc(pool, GFP_ATOMIC);
691 memset(req, 0, sizeof(*req));
696 static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
698 struct zfcp_fsf_req_qtcb *qtcb;
701 qtcb = mempool_alloc(pool, GFP_ATOMIC);
703 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
708 memset(qtcb, 0, sizeof(*qtcb));
709 qtcb->fsf_req.qtcb = &qtcb->qtcb;
710 qtcb->fsf_req.pool = pool;
712 return &qtcb->fsf_req;
715 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
716 u32 fsf_cmd, int req_flags,
719 struct qdio_buffer_element *sbale;
721 struct zfcp_fsf_req *req;
722 struct zfcp_qdio_queue *req_q = &adapter->req_q;
724 if (req_flags & ZFCP_REQ_NO_QTCB)
725 req = zfcp_fsf_alloc_noqtcb(pool);
727 req = zfcp_fsf_alloc_qtcb(pool);
730 return ERR_PTR(-EIO);
732 if (adapter->req_no == 0)
735 INIT_LIST_HEAD(&req->list);
736 init_timer(&req->timer);
737 init_waitqueue_head(&req->completion_wq);
739 req->adapter = adapter;
740 req->fsf_command = fsf_cmd;
741 req->req_id = adapter->req_no;
742 req->sbal_number = 1;
743 req->sbal_first = req_q->first;
744 req->sbal_last = req_q->first;
747 sbale = zfcp_qdio_sbale_req(req);
748 sbale[0].addr = (void *) req->req_id;
749 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
751 if (likely(req->qtcb)) {
752 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
753 req->qtcb->prefix.req_id = req->req_id;
754 req->qtcb->prefix.ulp_info = 26;
755 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
756 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
757 req->qtcb->header.req_handle = req->req_id;
758 req->qtcb->header.fsf_command = req->fsf_command;
759 req->seq_no = adapter->fsf_req_seq_no;
760 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
761 sbale[1].addr = (void *) req->qtcb;
762 sbale[1].length = sizeof(struct fsf_qtcb);
765 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
766 zfcp_fsf_req_free(req);
767 return ERR_PTR(-EIO);
770 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
771 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
776 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
778 struct zfcp_adapter *adapter = req->adapter;
782 /* put allocated FSF request into hash table */
783 spin_lock_irqsave(&adapter->req_list_lock, flags);
784 idx = zfcp_reqlist_hash(req->req_id);
785 list_add_tail(&req->list, &adapter->req_list[idx]);
786 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
788 req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
789 req->issued = get_clock();
790 if (zfcp_qdio_send(req)) {
791 del_timer(&req->timer);
792 spin_lock_irqsave(&adapter->req_list_lock, flags);
793 /* lookup request again, list might have changed */
794 if (zfcp_reqlist_find_safe(adapter, req))
795 zfcp_reqlist_remove(adapter, req);
796 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
797 zfcp_erp_adapter_reopen(adapter, 0, 116, req);
801 /* Don't increase for unsolicited status */
803 adapter->fsf_req_seq_no++;
810 * zfcp_fsf_status_read - send status read request
811 * @adapter: pointer to struct zfcp_adapter
812 * @req_flags: request flags
813 * Returns: 0 on success, ERROR otherwise
815 int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
817 struct zfcp_fsf_req *req;
818 struct fsf_status_read_buffer *sr_buf;
819 struct qdio_buffer_element *sbale;
822 spin_lock_bh(&adapter->req_q_lock);
823 if (zfcp_fsf_req_sbal_get(adapter))
826 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
828 adapter->pool.fsf_req_status_read);
830 retval = PTR_ERR(req);
834 sbale = zfcp_qdio_sbale_req(req);
835 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
836 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
839 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
844 memset(sr_buf, 0, sizeof(*sr_buf));
846 sbale = zfcp_qdio_sbale_curr(req);
847 sbale->addr = (void *) sr_buf;
848 sbale->length = sizeof(*sr_buf);
850 retval = zfcp_fsf_req_send(req);
852 goto failed_req_send;
857 mempool_free(sr_buf, adapter->pool.data_status_read);
859 zfcp_fsf_req_free(req);
860 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
862 spin_unlock_bh(&adapter->req_q_lock);
866 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
868 struct zfcp_unit *unit = req->data;
869 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
871 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
874 switch (req->qtcb->header.fsf_status) {
875 case FSF_PORT_HANDLE_NOT_VALID:
876 if (fsq->word[0] == fsq->word[1]) {
877 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
879 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
882 case FSF_LUN_HANDLE_NOT_VALID:
883 if (fsq->word[0] == fsq->word[1]) {
884 zfcp_erp_port_reopen(unit->port, 0, 105, req);
885 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
888 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
889 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
892 zfcp_erp_port_boxed(unit->port, 47, req);
893 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
894 ZFCP_STATUS_FSFREQ_RETRY;
897 zfcp_erp_unit_boxed(unit, 48, req);
898 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
899 ZFCP_STATUS_FSFREQ_RETRY;
901 case FSF_ADAPTER_STATUS_AVAILABLE:
902 switch (fsq->word[0]) {
903 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
904 zfcp_test_link(unit->port);
905 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
906 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
911 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
917 * zfcp_fsf_abort_fcp_command - abort running SCSI command
918 * @old_req_id: unsigned long
919 * @unit: pointer to struct zfcp_unit
920 * Returns: pointer to struct zfcp_fsf_req
923 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
924 struct zfcp_unit *unit)
926 struct qdio_buffer_element *sbale;
927 struct zfcp_fsf_req *req = NULL;
928 struct zfcp_adapter *adapter = unit->port->adapter;
930 spin_lock_bh(&adapter->req_q_lock);
931 if (zfcp_fsf_req_sbal_get(adapter))
933 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
934 0, adapter->pool.fsf_req_abort);
940 if (unlikely(!(atomic_read(&unit->status) &
941 ZFCP_STATUS_COMMON_UNBLOCKED)))
944 sbale = zfcp_qdio_sbale_req(req);
945 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
946 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
949 req->handler = zfcp_fsf_abort_fcp_command_handler;
950 req->qtcb->header.lun_handle = unit->handle;
951 req->qtcb->header.port_handle = unit->port->handle;
952 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
954 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
955 if (!zfcp_fsf_req_send(req))
959 zfcp_fsf_req_free(req);
962 spin_unlock_bh(&adapter->req_q_lock);
966 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
968 struct zfcp_adapter *adapter = req->adapter;
969 struct zfcp_send_ct *send_ct = req->data;
970 struct fsf_qtcb_header *header = &req->qtcb->header;
972 send_ct->status = -EINVAL;
974 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
977 switch (header->fsf_status) {
979 zfcp_san_dbf_event_ct_response(req);
982 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
983 zfcp_fsf_class_not_supp(req);
985 case FSF_ADAPTER_STATUS_AVAILABLE:
986 switch (header->fsf_status_qual.word[0]){
987 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
988 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
989 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
993 case FSF_ACCESS_DENIED:
996 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
997 ZFCP_STATUS_FSFREQ_RETRY;
999 case FSF_PORT_HANDLE_NOT_VALID:
1000 zfcp_erp_adapter_reopen(adapter, 0, 106, req);
1001 case FSF_GENERIC_COMMAND_REJECTED:
1002 case FSF_PAYLOAD_SIZE_MISMATCH:
1003 case FSF_REQUEST_SIZE_TOO_LARGE:
1004 case FSF_RESPONSE_SIZE_TOO_LARGE:
1005 case FSF_SBAL_MISMATCH:
1006 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1011 if (send_ct->handler)
1012 send_ct->handler(send_ct->handler_data);
1015 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1016 struct scatterlist *sg_req,
1017 struct scatterlist *sg_resp,
1020 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
1021 u32 feat = req->adapter->adapter_features;
1024 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1025 if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
1026 !sg_is_last(sg_req) || !sg_is_last(sg_resp))
1029 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1030 sbale[2].addr = sg_virt(sg_req);
1031 sbale[2].length = sg_req->length;
1032 sbale[3].addr = sg_virt(sg_resp);
1033 sbale[3].length = sg_resp->length;
1034 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1038 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1042 req->qtcb->bottom.support.req_buf_length = bytes;
1043 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1045 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1046 sg_resp, max_sbals);
1049 req->qtcb->bottom.support.resp_buf_length = bytes;
1055 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1056 * @ct: pointer to struct zfcp_send_ct with data for request
1057 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1058 * @erp_action: if non-null the Generic Service request sent within ERP
1060 int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1061 struct zfcp_erp_action *erp_action)
1063 struct zfcp_wka_port *wka_port = ct->wka_port;
1064 struct zfcp_adapter *adapter = wka_port->adapter;
1065 struct zfcp_fsf_req *req;
1068 spin_lock_bh(&adapter->req_q_lock);
1069 if (zfcp_fsf_req_sbal_get(adapter))
1072 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1073 ZFCP_REQ_AUTO_CLEANUP, pool);
1079 ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
1080 FSF_MAX_SBALS_PER_REQ);
1084 req->handler = zfcp_fsf_send_ct_handler;
1085 req->qtcb->header.port_handle = wka_port->handle;
1086 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1087 req->qtcb->bottom.support.timeout = ct->timeout;
1090 zfcp_san_dbf_event_ct_request(req);
1093 erp_action->fsf_req = req;
1094 req->erp_action = erp_action;
1095 zfcp_fsf_start_erp_timer(req);
1097 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1099 ret = zfcp_fsf_req_send(req);
1106 zfcp_fsf_req_free(req);
1108 erp_action->fsf_req = NULL;
1110 spin_unlock_bh(&adapter->req_q_lock);
1114 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1116 struct zfcp_send_els *send_els = req->data;
1117 struct zfcp_port *port = send_els->port;
1118 struct fsf_qtcb_header *header = &req->qtcb->header;
1120 send_els->status = -EINVAL;
1122 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1123 goto skip_fsfstatus;
1125 switch (header->fsf_status) {
1127 zfcp_san_dbf_event_els_response(req);
1128 send_els->status = 0;
1130 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1131 zfcp_fsf_class_not_supp(req);
1133 case FSF_ADAPTER_STATUS_AVAILABLE:
1134 switch (header->fsf_status_qual.word[0]){
1135 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1136 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1137 zfcp_test_link(port);
1139 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1140 case FSF_SQ_RETRY_IF_POSSIBLE:
1141 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1145 case FSF_ELS_COMMAND_REJECTED:
1146 case FSF_PAYLOAD_SIZE_MISMATCH:
1147 case FSF_REQUEST_SIZE_TOO_LARGE:
1148 case FSF_RESPONSE_SIZE_TOO_LARGE:
1150 case FSF_ACCESS_DENIED:
1151 zfcp_fsf_access_denied_port(req, port);
1153 case FSF_SBAL_MISMATCH:
1154 /* should never occure, avoided in zfcp_fsf_send_els */
1157 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1161 if (send_els->handler)
1162 send_els->handler(send_els->handler_data);
1166 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1167 * @els: pointer to struct zfcp_send_els with data for the command
1169 int zfcp_fsf_send_els(struct zfcp_send_els *els)
1171 struct zfcp_fsf_req *req;
1172 struct zfcp_adapter *adapter = els->adapter;
1173 struct fsf_qtcb_bottom_support *bottom;
1176 if (unlikely(!(atomic_read(&els->port->status) &
1177 ZFCP_STATUS_COMMON_UNBLOCKED)))
1180 spin_lock(&adapter->req_q_lock);
1181 if (!zfcp_fsf_sbal_available(adapter))
1183 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1184 ZFCP_REQ_AUTO_CLEANUP, NULL);
1190 ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
1195 bottom = &req->qtcb->bottom.support;
1196 req->handler = zfcp_fsf_send_els_handler;
1197 bottom->d_id = els->d_id;
1198 bottom->service_class = FSF_CLASS_3;
1199 bottom->timeout = 2 * R_A_TOV;
1202 zfcp_san_dbf_event_els_request(req);
1204 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1205 ret = zfcp_fsf_req_send(req);
1212 zfcp_fsf_req_free(req);
1214 spin_unlock(&adapter->req_q_lock);
1218 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1220 struct qdio_buffer_element *sbale;
1221 struct zfcp_fsf_req *req;
1222 struct zfcp_adapter *adapter = erp_action->adapter;
1225 spin_lock_bh(&adapter->req_q_lock);
1226 if (zfcp_fsf_req_sbal_get(adapter))
1228 req = zfcp_fsf_req_create(adapter,
1229 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1230 ZFCP_REQ_AUTO_CLEANUP,
1231 adapter->pool.fsf_req_erp);
1233 retval = PTR_ERR(req);
1237 sbale = zfcp_qdio_sbale_req(req);
1238 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1239 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1241 req->qtcb->bottom.config.feature_selection =
1243 FSF_FEATURE_LUN_SHARING |
1244 FSF_FEATURE_NOTIFICATION_LOST |
1245 FSF_FEATURE_UPDATE_ALERT;
1246 req->erp_action = erp_action;
1247 req->handler = zfcp_fsf_exchange_config_data_handler;
1248 erp_action->fsf_req = req;
1250 zfcp_fsf_start_erp_timer(req);
1251 retval = zfcp_fsf_req_send(req);
1253 zfcp_fsf_req_free(req);
1254 erp_action->fsf_req = NULL;
1257 spin_unlock_bh(&adapter->req_q_lock);
1261 int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1262 struct fsf_qtcb_bottom_config *data)
1264 struct qdio_buffer_element *sbale;
1265 struct zfcp_fsf_req *req = NULL;
1268 spin_lock_bh(&adapter->req_q_lock);
1269 if (zfcp_fsf_req_sbal_get(adapter))
1272 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1275 retval = PTR_ERR(req);
1279 sbale = zfcp_qdio_sbale_req(req);
1280 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1281 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1282 req->handler = zfcp_fsf_exchange_config_data_handler;
1284 req->qtcb->bottom.config.feature_selection =
1286 FSF_FEATURE_LUN_SHARING |
1287 FSF_FEATURE_NOTIFICATION_LOST |
1288 FSF_FEATURE_UPDATE_ALERT;
1293 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1294 retval = zfcp_fsf_req_send(req);
1296 spin_unlock_bh(&adapter->req_q_lock);
1298 wait_event(req->completion_wq,
1299 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1301 zfcp_fsf_req_free(req);
1307 * zfcp_fsf_exchange_port_data - request information about local port
1308 * @erp_action: ERP action for the adapter for which port data is requested
1309 * Returns: 0 on success, error otherwise
1311 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1313 struct qdio_buffer_element *sbale;
1314 struct zfcp_fsf_req *req;
1315 struct zfcp_adapter *adapter = erp_action->adapter;
1318 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1321 spin_lock_bh(&adapter->req_q_lock);
1322 if (zfcp_fsf_req_sbal_get(adapter))
1324 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1325 ZFCP_REQ_AUTO_CLEANUP,
1326 adapter->pool.fsf_req_erp);
1328 retval = PTR_ERR(req);
1332 sbale = zfcp_qdio_sbale_req(req);
1333 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1334 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1336 req->handler = zfcp_fsf_exchange_port_data_handler;
1337 req->erp_action = erp_action;
1338 erp_action->fsf_req = req;
1340 zfcp_fsf_start_erp_timer(req);
1341 retval = zfcp_fsf_req_send(req);
1343 zfcp_fsf_req_free(req);
1344 erp_action->fsf_req = NULL;
1347 spin_unlock_bh(&adapter->req_q_lock);
1352 * zfcp_fsf_exchange_port_data_sync - request information about local port
1353 * @adapter: pointer to struct zfcp_adapter
1354 * @data: pointer to struct fsf_qtcb_bottom_port
1355 * Returns: 0 on success, error otherwise
1357 int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1358 struct fsf_qtcb_bottom_port *data)
1360 struct qdio_buffer_element *sbale;
1361 struct zfcp_fsf_req *req = NULL;
1364 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1367 spin_lock_bh(&adapter->req_q_lock);
1368 if (zfcp_fsf_req_sbal_get(adapter))
1371 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1374 retval = PTR_ERR(req);
1381 sbale = zfcp_qdio_sbale_req(req);
1382 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1383 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1385 req->handler = zfcp_fsf_exchange_port_data_handler;
1386 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1387 retval = zfcp_fsf_req_send(req);
1389 spin_unlock_bh(&adapter->req_q_lock);
1391 wait_event(req->completion_wq,
1392 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1393 zfcp_fsf_req_free(req);
1398 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1400 struct zfcp_port *port = req->data;
1401 struct fsf_qtcb_header *header = &req->qtcb->header;
1402 struct fsf_plogi *plogi;
1404 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1407 switch (header->fsf_status) {
1408 case FSF_PORT_ALREADY_OPEN:
1410 case FSF_ACCESS_DENIED:
1411 zfcp_fsf_access_denied_port(req, port);
1413 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1414 dev_warn(&req->adapter->ccw_device->dev,
1415 "Not enough FCP adapter resources to open "
1416 "remote port 0x%016Lx\n",
1417 (unsigned long long)port->wwpn);
1418 zfcp_erp_port_failed(port, 31, req);
1419 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1421 case FSF_ADAPTER_STATUS_AVAILABLE:
1422 switch (header->fsf_status_qual.word[0]) {
1423 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1424 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1425 case FSF_SQ_NO_RETRY_POSSIBLE:
1426 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1431 port->handle = header->port_handle;
1432 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1433 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1434 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1435 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1437 /* check whether D_ID has changed during open */
1439 * FIXME: This check is not airtight, as the FCP channel does
1440 * not monitor closures of target port connections caused on
1441 * the remote side. Thus, they might miss out on invalidating
1442 * locally cached WWPNs (and other N_Port parameters) of gone
1443 * target ports. So, our heroic attempt to make things safe
1444 * could be undermined by 'open port' response data tagged with
1445 * obsolete WWPNs. Another reason to monitor potential
1446 * connection closures ourself at least (by interpreting
1447 * incoming ELS' and unsolicited status). It just crosses my
1448 * mind that one should be able to cross-check by means of
1449 * another GID_PN straight after a port has been opened.
1450 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1452 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1453 if (req->qtcb->bottom.support.els1_length >=
1454 FSF_PLOGI_MIN_LEN) {
1455 if (plogi->serv_param.wwpn != port->wwpn)
1458 port->wwnn = plogi->serv_param.wwnn;
1459 zfcp_fc_plogi_evaluate(port, plogi);
1463 case FSF_UNKNOWN_OP_SUBTYPE:
1464 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1470 * zfcp_fsf_open_port - create and send open port request
1471 * @erp_action: pointer to struct zfcp_erp_action
1472 * Returns: 0 on success, error otherwise
1474 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1476 struct qdio_buffer_element *sbale;
1477 struct zfcp_adapter *adapter = erp_action->adapter;
1478 struct zfcp_fsf_req *req;
1481 spin_lock_bh(&adapter->req_q_lock);
1482 if (zfcp_fsf_req_sbal_get(adapter))
1485 req = zfcp_fsf_req_create(adapter,
1486 FSF_QTCB_OPEN_PORT_WITH_DID,
1487 ZFCP_REQ_AUTO_CLEANUP,
1488 adapter->pool.fsf_req_erp);
1490 retval = PTR_ERR(req);
1494 sbale = zfcp_qdio_sbale_req(req);
1495 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1496 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1498 req->handler = zfcp_fsf_open_port_handler;
1499 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
1500 req->data = erp_action->port;
1501 req->erp_action = erp_action;
1502 erp_action->fsf_req = req;
1504 zfcp_fsf_start_erp_timer(req);
1505 retval = zfcp_fsf_req_send(req);
1507 zfcp_fsf_req_free(req);
1508 erp_action->fsf_req = NULL;
1511 spin_unlock_bh(&adapter->req_q_lock);
1515 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1517 struct zfcp_port *port = req->data;
1519 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1522 switch (req->qtcb->header.fsf_status) {
1523 case FSF_PORT_HANDLE_NOT_VALID:
1524 zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
1525 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1527 case FSF_ADAPTER_STATUS_AVAILABLE:
1530 zfcp_erp_modify_port_status(port, 33, req,
1531 ZFCP_STATUS_COMMON_OPEN,
1538 * zfcp_fsf_close_port - create and send close port request
1539 * @erp_action: pointer to struct zfcp_erp_action
1540 * Returns: 0 on success, error otherwise
1542 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1544 struct qdio_buffer_element *sbale;
1545 struct zfcp_adapter *adapter = erp_action->adapter;
1546 struct zfcp_fsf_req *req;
1549 spin_lock_bh(&adapter->req_q_lock);
1550 if (zfcp_fsf_req_sbal_get(adapter))
1553 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1554 ZFCP_REQ_AUTO_CLEANUP,
1555 adapter->pool.fsf_req_erp);
1557 retval = PTR_ERR(req);
1561 sbale = zfcp_qdio_sbale_req(req);
1562 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1563 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1565 req->handler = zfcp_fsf_close_port_handler;
1566 req->data = erp_action->port;
1567 req->erp_action = erp_action;
1568 req->qtcb->header.port_handle = erp_action->port->handle;
1569 erp_action->fsf_req = req;
1571 zfcp_fsf_start_erp_timer(req);
1572 retval = zfcp_fsf_req_send(req);
1574 zfcp_fsf_req_free(req);
1575 erp_action->fsf_req = NULL;
1578 spin_unlock_bh(&adapter->req_q_lock);
1582 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1584 struct zfcp_wka_port *wka_port = req->data;
1585 struct fsf_qtcb_header *header = &req->qtcb->header;
1587 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1588 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1592 switch (header->fsf_status) {
1593 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1594 dev_warn(&req->adapter->ccw_device->dev,
1595 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1596 case FSF_ADAPTER_STATUS_AVAILABLE:
1597 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1598 case FSF_ACCESS_DENIED:
1599 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1601 case FSF_PORT_ALREADY_OPEN:
1604 wka_port->handle = header->port_handle;
1605 wka_port->status = ZFCP_WKA_PORT_ONLINE;
1608 wake_up(&wka_port->completion_wq);
1612 * zfcp_fsf_open_wka_port - create and send open wka-port request
1613 * @wka_port: pointer to struct zfcp_wka_port
1614 * Returns: 0 on success, error otherwise
1616 int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1618 struct qdio_buffer_element *sbale;
1619 struct zfcp_adapter *adapter = wka_port->adapter;
1620 struct zfcp_fsf_req *req;
1623 spin_lock_bh(&adapter->req_q_lock);
1624 if (zfcp_fsf_req_sbal_get(adapter))
1627 req = zfcp_fsf_req_create(adapter,
1628 FSF_QTCB_OPEN_PORT_WITH_DID,
1629 ZFCP_REQ_AUTO_CLEANUP,
1630 adapter->pool.fsf_req_erp);
1631 if (unlikely(IS_ERR(req))) {
1632 retval = PTR_ERR(req);
1636 sbale = zfcp_qdio_sbale_req(req);
1637 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1638 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1640 req->handler = zfcp_fsf_open_wka_port_handler;
1641 req->qtcb->bottom.support.d_id = wka_port->d_id;
1642 req->data = wka_port;
1644 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1645 retval = zfcp_fsf_req_send(req);
1647 zfcp_fsf_req_free(req);
1649 spin_unlock_bh(&adapter->req_q_lock);
1653 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1655 struct zfcp_wka_port *wka_port = req->data;
1657 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1658 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1659 zfcp_erp_adapter_reopen(wka_port->adapter, 0, 84, req);
1662 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1663 wake_up(&wka_port->completion_wq);
1667 * zfcp_fsf_close_wka_port - create and send close wka port request
1668 * @erp_action: pointer to struct zfcp_erp_action
1669 * Returns: 0 on success, error otherwise
1671 int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
1673 struct qdio_buffer_element *sbale;
1674 struct zfcp_adapter *adapter = wka_port->adapter;
1675 struct zfcp_fsf_req *req;
1678 spin_lock_bh(&adapter->req_q_lock);
1679 if (zfcp_fsf_req_sbal_get(adapter))
1682 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1683 ZFCP_REQ_AUTO_CLEANUP,
1684 adapter->pool.fsf_req_erp);
1685 if (unlikely(IS_ERR(req))) {
1686 retval = PTR_ERR(req);
1690 sbale = zfcp_qdio_sbale_req(req);
1691 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1692 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1694 req->handler = zfcp_fsf_close_wka_port_handler;
1695 req->data = wka_port;
1696 req->qtcb->header.port_handle = wka_port->handle;
1698 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1699 retval = zfcp_fsf_req_send(req);
1701 zfcp_fsf_req_free(req);
1703 spin_unlock_bh(&adapter->req_q_lock);
1707 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1709 struct zfcp_port *port = req->data;
1710 struct fsf_qtcb_header *header = &req->qtcb->header;
1711 struct zfcp_unit *unit;
1713 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1716 switch (header->fsf_status) {
1717 case FSF_PORT_HANDLE_NOT_VALID:
1718 zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
1719 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1721 case FSF_ACCESS_DENIED:
1722 zfcp_fsf_access_denied_port(req, port);
1724 case FSF_PORT_BOXED:
1725 zfcp_erp_port_boxed(port, 50, req);
1726 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1727 ZFCP_STATUS_FSFREQ_RETRY;
1728 /* can't use generic zfcp_erp_modify_port_status because
1729 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1730 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1731 list_for_each_entry(unit, &port->unit_list_head, list)
1732 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1735 case FSF_ADAPTER_STATUS_AVAILABLE:
1736 switch (header->fsf_status_qual.word[0]) {
1737 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1739 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1740 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1745 /* can't use generic zfcp_erp_modify_port_status because
1746 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1748 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1749 list_for_each_entry(unit, &port->unit_list_head, list)
1750 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1757 * zfcp_fsf_close_physical_port - close physical port
1758 * @erp_action: pointer to struct zfcp_erp_action
1759 * Returns: 0 on success
1761 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1763 struct qdio_buffer_element *sbale;
1764 struct zfcp_adapter *adapter = erp_action->adapter;
1765 struct zfcp_fsf_req *req;
1768 spin_lock_bh(&adapter->req_q_lock);
1769 if (zfcp_fsf_req_sbal_get(adapter))
1772 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1773 ZFCP_REQ_AUTO_CLEANUP,
1774 adapter->pool.fsf_req_erp);
1776 retval = PTR_ERR(req);
1780 sbale = zfcp_qdio_sbale_req(req);
1781 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1782 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1784 req->data = erp_action->port;
1785 req->qtcb->header.port_handle = erp_action->port->handle;
1786 req->erp_action = erp_action;
1787 req->handler = zfcp_fsf_close_physical_port_handler;
1788 erp_action->fsf_req = req;
1790 zfcp_fsf_start_erp_timer(req);
1791 retval = zfcp_fsf_req_send(req);
1793 zfcp_fsf_req_free(req);
1794 erp_action->fsf_req = NULL;
1797 spin_unlock_bh(&adapter->req_q_lock);
1801 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1803 struct zfcp_adapter *adapter = req->adapter;
1804 struct zfcp_unit *unit = req->data;
1805 struct fsf_qtcb_header *header = &req->qtcb->header;
1806 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1807 struct fsf_queue_designator *queue_designator =
1808 &header->fsf_status_qual.fsf_queue_designator;
1809 int exclusive, readwrite;
1811 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1814 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1815 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1816 ZFCP_STATUS_UNIT_SHARED |
1817 ZFCP_STATUS_UNIT_READONLY,
1820 switch (header->fsf_status) {
1822 case FSF_PORT_HANDLE_NOT_VALID:
1823 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
1825 case FSF_LUN_ALREADY_OPEN:
1827 case FSF_ACCESS_DENIED:
1828 zfcp_fsf_access_denied_unit(req, unit);
1829 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1830 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1832 case FSF_PORT_BOXED:
1833 zfcp_erp_port_boxed(unit->port, 51, req);
1834 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1835 ZFCP_STATUS_FSFREQ_RETRY;
1837 case FSF_LUN_SHARING_VIOLATION:
1838 if (header->fsf_status_qual.word[0])
1839 dev_warn(&adapter->ccw_device->dev,
1840 "LUN 0x%Lx on port 0x%Lx is already in "
1841 "use by CSS%d, MIF Image ID %x\n",
1842 (unsigned long long)unit->fcp_lun,
1843 (unsigned long long)unit->port->wwpn,
1844 queue_designator->cssid,
1845 queue_designator->hla);
1847 zfcp_act_eval_err(adapter,
1848 header->fsf_status_qual.word[2]);
1849 zfcp_erp_unit_access_denied(unit, 60, req);
1850 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1851 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1852 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1854 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1855 dev_warn(&adapter->ccw_device->dev,
1856 "No handle is available for LUN "
1857 "0x%016Lx on port 0x%016Lx\n",
1858 (unsigned long long)unit->fcp_lun,
1859 (unsigned long long)unit->port->wwpn);
1860 zfcp_erp_unit_failed(unit, 34, req);
1862 case FSF_INVALID_COMMAND_OPTION:
1863 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1865 case FSF_ADAPTER_STATUS_AVAILABLE:
1866 switch (header->fsf_status_qual.word[0]) {
1867 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1868 zfcp_test_link(unit->port);
1870 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1871 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1877 unit->handle = header->lun_handle;
1878 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1880 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1881 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1882 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
1883 exclusive = (bottom->lun_access_info &
1884 FSF_UNIT_ACCESS_EXCLUSIVE);
1885 readwrite = (bottom->lun_access_info &
1886 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1889 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1893 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1895 dev_info(&adapter->ccw_device->dev,
1896 "SCSI device at LUN 0x%016Lx on port "
1897 "0x%016Lx opened read-only\n",
1898 (unsigned long long)unit->fcp_lun,
1899 (unsigned long long)unit->port->wwpn);
1902 if (exclusive && !readwrite) {
1903 dev_err(&adapter->ccw_device->dev,
1904 "Exclusive read-only access not "
1905 "supported (unit 0x%016Lx, "
1907 (unsigned long long)unit->fcp_lun,
1908 (unsigned long long)unit->port->wwpn);
1909 zfcp_erp_unit_failed(unit, 35, req);
1910 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1911 zfcp_erp_unit_shutdown(unit, 0, 80, req);
1912 } else if (!exclusive && readwrite) {
1913 dev_err(&adapter->ccw_device->dev,
1914 "Shared read-write access not "
1915 "supported (unit 0x%016Lx, port "
1917 (unsigned long long)unit->fcp_lun,
1918 (unsigned long long)unit->port->wwpn);
1919 zfcp_erp_unit_failed(unit, 36, req);
1920 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1921 zfcp_erp_unit_shutdown(unit, 0, 81, req);
1929 * zfcp_fsf_open_unit - open unit
1930 * @erp_action: pointer to struct zfcp_erp_action
1931 * Returns: 0 on success, error otherwise
1933 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1935 struct qdio_buffer_element *sbale;
1936 struct zfcp_adapter *adapter = erp_action->adapter;
1937 struct zfcp_fsf_req *req;
1940 spin_lock_bh(&adapter->req_q_lock);
1941 if (zfcp_fsf_req_sbal_get(adapter))
1944 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1945 ZFCP_REQ_AUTO_CLEANUP,
1946 adapter->pool.fsf_req_erp);
1948 retval = PTR_ERR(req);
1952 sbale = zfcp_qdio_sbale_req(req);
1953 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1954 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1956 req->qtcb->header.port_handle = erp_action->port->handle;
1957 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1958 req->handler = zfcp_fsf_open_unit_handler;
1959 req->data = erp_action->unit;
1960 req->erp_action = erp_action;
1961 erp_action->fsf_req = req;
1963 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1964 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1966 zfcp_fsf_start_erp_timer(req);
1967 retval = zfcp_fsf_req_send(req);
1969 zfcp_fsf_req_free(req);
1970 erp_action->fsf_req = NULL;
1973 spin_unlock_bh(&adapter->req_q_lock);
1977 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
1979 struct zfcp_unit *unit = req->data;
1981 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1984 switch (req->qtcb->header.fsf_status) {
1985 case FSF_PORT_HANDLE_NOT_VALID:
1986 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
1987 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1989 case FSF_LUN_HANDLE_NOT_VALID:
1990 zfcp_erp_port_reopen(unit->port, 0, 111, req);
1991 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1993 case FSF_PORT_BOXED:
1994 zfcp_erp_port_boxed(unit->port, 52, req);
1995 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1996 ZFCP_STATUS_FSFREQ_RETRY;
1998 case FSF_ADAPTER_STATUS_AVAILABLE:
1999 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2000 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2001 zfcp_test_link(unit->port);
2003 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2004 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2009 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2015 * zfcp_fsf_close_unit - close zfcp unit
2016 * @erp_action: pointer to struct zfcp_unit
2017 * Returns: 0 on success, error otherwise
2019 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2021 struct qdio_buffer_element *sbale;
2022 struct zfcp_adapter *adapter = erp_action->adapter;
2023 struct zfcp_fsf_req *req;
2026 spin_lock_bh(&adapter->req_q_lock);
2027 if (zfcp_fsf_req_sbal_get(adapter))
2029 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
2030 ZFCP_REQ_AUTO_CLEANUP,
2031 adapter->pool.fsf_req_erp);
2033 retval = PTR_ERR(req);
2037 sbale = zfcp_qdio_sbale_req(req);
2038 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2039 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2041 req->qtcb->header.port_handle = erp_action->port->handle;
2042 req->qtcb->header.lun_handle = erp_action->unit->handle;
2043 req->handler = zfcp_fsf_close_unit_handler;
2044 req->data = erp_action->unit;
2045 req->erp_action = erp_action;
2046 erp_action->fsf_req = req;
2048 zfcp_fsf_start_erp_timer(req);
2049 retval = zfcp_fsf_req_send(req);
2051 zfcp_fsf_req_free(req);
2052 erp_action->fsf_req = NULL;
2055 spin_unlock_bh(&adapter->req_q_lock);
2059 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2061 lat_rec->sum += lat;
2062 lat_rec->min = min(lat_rec->min, lat);
2063 lat_rec->max = max(lat_rec->max, lat);
2066 static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
2068 struct fsf_qual_latency_info *lat_inf;
2069 struct latency_cont *lat;
2070 struct zfcp_unit *unit = req->unit;
2072 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
2074 switch (req->qtcb->bottom.io.data_direction) {
2075 case FSF_DATADIR_READ:
2076 lat = &unit->latencies.read;
2078 case FSF_DATADIR_WRITE:
2079 lat = &unit->latencies.write;
2081 case FSF_DATADIR_CMND:
2082 lat = &unit->latencies.cmd;
2088 spin_lock(&unit->latencies.lock);
2089 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2090 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2092 spin_unlock(&unit->latencies.lock);
2095 #ifdef CONFIG_BLK_DEV_IO_TRACE
2096 static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2098 struct fsf_qual_latency_info *lat_inf;
2099 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
2100 struct request *req = scsi_cmnd->request;
2101 struct zfcp_blk_drv_data trace;
2102 int ticks = fsf_req->adapter->timer_ticks;
2105 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2106 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2107 trace.flags |= ZFCP_BLK_LAT_VALID;
2108 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2109 trace.channel_lat = lat_inf->channel_lat * ticks;
2110 trace.fabric_lat = lat_inf->fabric_lat * ticks;
2112 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2113 trace.flags |= ZFCP_BLK_REQ_ERROR;
2114 trace.inb_usage = fsf_req->qdio_inb_usage;
2115 trace.outb_usage = fsf_req->qdio_outb_usage;
2117 blk_add_driver_data(req->q, req, &trace, sizeof(trace));
2120 static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2125 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2127 struct scsi_cmnd *scpnt;
2128 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2129 &(req->qtcb->bottom.io.fcp_rsp);
2131 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2132 unsigned long flags;
2134 read_lock_irqsave(&req->adapter->abort_lock, flags);
2137 if (unlikely(!scpnt)) {
2138 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2142 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
2143 set_host_byte(scpnt, DID_SOFT_ERROR);
2144 goto skip_fsfstatus;
2147 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2148 set_host_byte(scpnt, DID_ERROR);
2149 goto skip_fsfstatus;
2152 set_msg_byte(scpnt, COMMAND_COMPLETE);
2154 scpnt->result |= fcp_rsp_iu->scsi_status;
2156 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2157 zfcp_fsf_req_latency(req);
2159 zfcp_fsf_trace_latency(req);
2161 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
2162 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
2163 set_host_byte(scpnt, DID_OK);
2165 set_host_byte(scpnt, DID_ERROR);
2166 goto skip_fsfstatus;
2170 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
2171 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2172 fcp_rsp_iu->fcp_rsp_len;
2173 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
2174 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
2176 memcpy(scpnt->sense_buffer,
2177 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
2180 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
2181 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2182 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2184 set_host_byte(scpnt, DID_ERROR);
2187 if (scpnt->result != 0)
2188 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
2189 else if (scpnt->retries > 0)
2190 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
2192 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
2194 scpnt->host_scribble = NULL;
2195 (scpnt->scsi_done) (scpnt);
2197 * We must hold this lock until scsi_done has been called.
2198 * Otherwise we may call scsi_done after abort regarding this
2199 * command has completed.
2200 * Note: scsi_done must not block!
2202 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2205 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2207 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2208 &(req->qtcb->bottom.io.fcp_rsp);
2209 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2211 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2212 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2213 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2217 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2219 struct zfcp_unit *unit;
2220 struct fsf_qtcb_header *header = &req->qtcb->header;
2222 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2227 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2228 goto skip_fsfstatus;
2230 switch (header->fsf_status) {
2231 case FSF_HANDLE_MISMATCH:
2232 case FSF_PORT_HANDLE_NOT_VALID:
2233 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
2234 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2236 case FSF_FCPLUN_NOT_VALID:
2237 case FSF_LUN_HANDLE_NOT_VALID:
2238 zfcp_erp_port_reopen(unit->port, 0, 113, req);
2239 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2241 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2242 zfcp_fsf_class_not_supp(req);
2244 case FSF_ACCESS_DENIED:
2245 zfcp_fsf_access_denied_unit(req, unit);
2247 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2248 dev_err(&req->adapter->ccw_device->dev,
2249 "Incorrect direction %d, unit 0x%016Lx on port "
2250 "0x%016Lx closed\n",
2251 req->qtcb->bottom.io.data_direction,
2252 (unsigned long long)unit->fcp_lun,
2253 (unsigned long long)unit->port->wwpn);
2254 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
2255 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2257 case FSF_CMND_LENGTH_NOT_VALID:
2258 dev_err(&req->adapter->ccw_device->dev,
2259 "Incorrect CDB length %d, unit 0x%016Lx on "
2260 "port 0x%016Lx closed\n",
2261 req->qtcb->bottom.io.fcp_cmnd_length,
2262 (unsigned long long)unit->fcp_lun,
2263 (unsigned long long)unit->port->wwpn);
2264 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
2265 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2267 case FSF_PORT_BOXED:
2268 zfcp_erp_port_boxed(unit->port, 53, req);
2269 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2270 ZFCP_STATUS_FSFREQ_RETRY;
2273 zfcp_erp_unit_boxed(unit, 54, req);
2274 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2275 ZFCP_STATUS_FSFREQ_RETRY;
2277 case FSF_ADAPTER_STATUS_AVAILABLE:
2278 if (header->fsf_status_qual.word[0] ==
2279 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2280 zfcp_test_link(unit->port);
2281 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2285 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2286 zfcp_fsf_send_fcp_ctm_handler(req);
2288 zfcp_fsf_send_fcp_command_task_handler(req);
2290 zfcp_unit_put(unit);
2294 static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2299 * fcp_dl_addr = start address of fcp_cmnd structure +
2300 * size of fixed part + size of dynamically sized add_dcp_cdb field
2301 * SEE FCP-2 documentation
2303 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2304 (fcp_cmd->add_fcp_cdb_length << 2));
2305 *fcp_dl_ptr = fcp_dl;
2309 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2310 * @unit: unit where command is sent to
2311 * @scsi_cmnd: scsi command to be sent
2313 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2314 struct scsi_cmnd *scsi_cmnd)
2316 struct zfcp_fsf_req *req;
2317 struct fcp_cmnd_iu *fcp_cmnd_iu;
2318 unsigned int sbtype;
2319 int real_bytes, retval = -EIO;
2320 struct zfcp_adapter *adapter = unit->port->adapter;
2322 if (unlikely(!(atomic_read(&unit->status) &
2323 ZFCP_STATUS_COMMON_UNBLOCKED)))
2326 spin_lock(&adapter->req_q_lock);
2327 if (!zfcp_fsf_sbal_available(adapter))
2329 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
2330 ZFCP_REQ_AUTO_CLEANUP,
2331 adapter->pool.fsf_req_scsi);
2333 retval = PTR_ERR(req);
2337 zfcp_unit_get(unit);
2339 req->data = scsi_cmnd;
2340 req->handler = zfcp_fsf_send_fcp_command_handler;
2341 req->qtcb->header.lun_handle = unit->handle;
2342 req->qtcb->header.port_handle = unit->port->handle;
2343 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2345 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2347 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2348 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2350 * set depending on data direction:
2351 * data direction bits in SBALE (SB Type)
2352 * data direction bits in QTCB
2353 * data direction bits in FCP_CMND IU
2355 switch (scsi_cmnd->sc_data_direction) {
2357 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2358 sbtype = SBAL_FLAGS0_TYPE_READ;
2360 case DMA_FROM_DEVICE:
2361 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2362 sbtype = SBAL_FLAGS0_TYPE_READ;
2363 fcp_cmnd_iu->rddata = 1;
2366 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2367 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2368 fcp_cmnd_iu->wddata = 1;
2370 case DMA_BIDIRECTIONAL:
2373 goto failed_scsi_cmnd;
2376 if (likely((scsi_cmnd->device->simple_tags) ||
2377 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2378 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2379 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2381 fcp_cmnd_iu->task_attribute = UNTAGGED;
2383 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2384 fcp_cmnd_iu->add_fcp_cdb_length =
2385 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2387 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2389 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2390 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
2392 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2393 scsi_sglist(scsi_cmnd),
2394 FSF_MAX_SBALS_PER_REQ);
2395 if (unlikely(real_bytes < 0)) {
2396 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2399 dev_err(&adapter->ccw_device->dev,
2400 "Oversize data package, unit 0x%016Lx "
2401 "on port 0x%016Lx closed\n",
2402 (unsigned long long)unit->fcp_lun,
2403 (unsigned long long)unit->port->wwpn);
2404 zfcp_erp_unit_shutdown(unit, 0, 131, req);
2407 goto failed_scsi_cmnd;
2410 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2412 retval = zfcp_fsf_req_send(req);
2413 if (unlikely(retval))
2414 goto failed_scsi_cmnd;
2419 zfcp_unit_put(unit);
2420 zfcp_fsf_req_free(req);
2421 scsi_cmnd->host_scribble = NULL;
2423 spin_unlock(&adapter->req_q_lock);
2428 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2429 * @unit: pointer to struct zfcp_unit
2430 * @tm_flags: unsigned byte for task management flags
2431 * Returns: on success pointer to struct fsf_req, NULL otherwise
2433 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2435 struct qdio_buffer_element *sbale;
2436 struct zfcp_fsf_req *req = NULL;
2437 struct fcp_cmnd_iu *fcp_cmnd_iu;
2438 struct zfcp_adapter *adapter = unit->port->adapter;
2440 if (unlikely(!(atomic_read(&unit->status) &
2441 ZFCP_STATUS_COMMON_UNBLOCKED)))
2444 spin_lock_bh(&adapter->req_q_lock);
2445 if (zfcp_fsf_req_sbal_get(adapter))
2447 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
2448 adapter->pool.fsf_req_scsi);
2454 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2456 req->handler = zfcp_fsf_send_fcp_command_handler;
2457 req->qtcb->header.lun_handle = unit->handle;
2458 req->qtcb->header.port_handle = unit->port->handle;
2459 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2460 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2461 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2464 sbale = zfcp_qdio_sbale_req(req);
2465 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2466 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2468 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2469 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2470 fcp_cmnd_iu->task_management_flags = tm_flags;
2472 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2473 if (!zfcp_fsf_req_send(req))
2476 zfcp_fsf_req_free(req);
2479 spin_unlock_bh(&adapter->req_q_lock);
2483 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2485 if (req->qtcb->header.fsf_status != FSF_GOOD)
2486 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2490 * zfcp_fsf_control_file - control file upload/download
2491 * @adapter: pointer to struct zfcp_adapter
2492 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2493 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2495 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2496 struct zfcp_fsf_cfdc *fsf_cfdc)
2498 struct qdio_buffer_element *sbale;
2499 struct zfcp_fsf_req *req = NULL;
2500 struct fsf_qtcb_bottom_support *bottom;
2501 int direction, retval = -EIO, bytes;
2503 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2504 return ERR_PTR(-EOPNOTSUPP);
2506 switch (fsf_cfdc->command) {
2507 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2508 direction = SBAL_FLAGS0_TYPE_WRITE;
2510 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2511 direction = SBAL_FLAGS0_TYPE_READ;
2514 return ERR_PTR(-EINVAL);
2517 spin_lock_bh(&adapter->req_q_lock);
2518 if (zfcp_fsf_req_sbal_get(adapter))
2521 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
2527 req->handler = zfcp_fsf_control_file_handler;
2529 sbale = zfcp_qdio_sbale_req(req);
2530 sbale[0].flags |= direction;
2532 bottom = &req->qtcb->bottom.support;
2533 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2534 bottom->option = fsf_cfdc->option;
2536 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2537 FSF_MAX_SBALS_PER_REQ);
2538 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2540 zfcp_fsf_req_free(req);
2544 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2545 retval = zfcp_fsf_req_send(req);
2547 spin_unlock_bh(&adapter->req_q_lock);
2550 wait_event(req->completion_wq,
2551 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2554 return ERR_PTR(retval);