4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2008
11 static void zfcp_fsf_request_timeout_handler(unsigned long data)
13 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
14 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
18 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
19 unsigned long timeout)
21 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
22 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
23 fsf_req->timer.expires = jiffies + timeout;
24 add_timer(&fsf_req->timer);
27 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
29 BUG_ON(!fsf_req->erp_action);
30 fsf_req->timer.function = zfcp_erp_timeout_handler;
31 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
32 fsf_req->timer.expires = jiffies + 30 * HZ;
33 add_timer(&fsf_req->timer);
36 /* association between FSF command and FSF QTCB type */
37 static u32 fsf_qtcb_type[] = {
38 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
39 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
40 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
41 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
42 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
43 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
44 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
45 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
46 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
48 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
49 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
53 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
55 u16 subtable = table >> 16;
56 u16 rule = table & 0xffff;
57 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
59 if (subtable && subtable < ARRAY_SIZE(act_type))
60 dev_warn(&adapter->ccw_device->dev,
61 "Access denied according to ACT rule type %s, "
62 "rule %d\n", act_type[subtable], rule);
65 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
66 struct zfcp_port *port)
68 struct fsf_qtcb_header *header = &req->qtcb->header;
69 dev_warn(&req->adapter->ccw_device->dev,
70 "Access denied to port 0x%016Lx\n",
72 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
73 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
74 zfcp_erp_port_access_denied(port, 55, req);
75 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
78 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
79 struct zfcp_unit *unit)
81 struct fsf_qtcb_header *header = &req->qtcb->header;
82 dev_warn(&req->adapter->ccw_device->dev,
83 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
84 unit->fcp_lun, unit->port->wwpn);
85 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
86 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
87 zfcp_erp_unit_access_denied(unit, 59, req);
88 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
91 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
93 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
94 "operational because of an unsupported FC class\n");
95 zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
96 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
100 * zfcp_fsf_req_free - free memory used by fsf request
101 * @fsf_req: pointer to struct zfcp_fsf_req
103 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
105 if (likely(req->pool)) {
106 mempool_free(req, req->pool);
111 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
117 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
118 * @adapter: pointer to struct zfcp_adapter
120 * Never ever call this without shutting down the adapter first.
121 * Otherwise the adapter would continue using and corrupting s390 storage.
122 * Included BUG_ON() call to ensure this is done.
123 * ERP is supposed to be the only user of this function.
125 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
127 struct zfcp_fsf_req *req, *tmp;
129 LIST_HEAD(remove_queue);
132 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
133 spin_lock_irqsave(&adapter->req_list_lock, flags);
134 for (i = 0; i < REQUEST_LIST_SIZE; i++)
135 list_splice_init(&adapter->req_list[i], &remove_queue);
136 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
138 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
139 list_del(&req->list);
140 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
141 zfcp_fsf_req_complete(req);
145 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
147 struct fsf_status_read_buffer *sr_buf = req->data;
148 struct zfcp_adapter *adapter = req->adapter;
149 struct zfcp_port *port;
150 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
153 read_lock_irqsave(&zfcp_data.config_lock, flags);
154 list_for_each_entry(port, &adapter->port_list_head, list)
155 if (port->d_id == d_id) {
156 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
157 switch (sr_buf->status_subtype) {
158 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
159 zfcp_erp_port_reopen(port, 0, 101, req);
161 case FSF_STATUS_READ_SUB_ERROR_PORT:
162 zfcp_erp_port_shutdown(port, 0, 122, req);
167 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
170 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
171 struct fsf_link_down_info *link_down)
173 struct zfcp_adapter *adapter = req->adapter;
175 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
178 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
183 switch (link_down->error_code) {
184 case FSF_PSQ_LINK_NO_LIGHT:
185 dev_warn(&req->adapter->ccw_device->dev,
186 "There is no light signal from the local "
187 "fibre channel cable\n");
189 case FSF_PSQ_LINK_WRAP_PLUG:
190 dev_warn(&req->adapter->ccw_device->dev,
191 "There is a wrap plug instead of a fibre "
194 case FSF_PSQ_LINK_NO_FCP:
195 dev_warn(&req->adapter->ccw_device->dev,
196 "The adjacent fibre channel node does not "
199 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
200 dev_warn(&req->adapter->ccw_device->dev,
201 "The FCP device is suspended because of a "
202 "firmware update\n");
204 case FSF_PSQ_LINK_INVALID_WWPN:
205 dev_warn(&req->adapter->ccw_device->dev,
206 "The FCP device detected a WWPN that is "
207 "duplicate or not valid\n");
209 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
210 dev_warn(&req->adapter->ccw_device->dev,
211 "The fibre channel fabric does not support NPIV\n");
213 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
214 dev_warn(&req->adapter->ccw_device->dev,
215 "The FCP adapter cannot support more NPIV ports\n");
217 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
218 dev_warn(&req->adapter->ccw_device->dev,
219 "The adjacent switch cannot support "
220 "more NPIV ports\n");
222 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
223 dev_warn(&req->adapter->ccw_device->dev,
224 "The FCP adapter could not log in to the "
225 "fibre channel fabric\n");
227 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
228 dev_warn(&req->adapter->ccw_device->dev,
229 "The WWPN assignment file on the FCP adapter "
230 "has been damaged\n");
232 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
233 dev_warn(&req->adapter->ccw_device->dev,
234 "The mode table on the FCP adapter "
235 "has been damaged\n");
237 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
238 dev_warn(&req->adapter->ccw_device->dev,
239 "All NPIV ports on the FCP adapter have "
243 dev_warn(&req->adapter->ccw_device->dev,
244 "The link between the FCP adapter and "
245 "the FC fabric is down\n");
248 zfcp_erp_adapter_failed(adapter, id, req);
251 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
253 struct fsf_status_read_buffer *sr_buf = req->data;
254 struct fsf_link_down_info *ldi =
255 (struct fsf_link_down_info *) &sr_buf->payload;
257 switch (sr_buf->status_subtype) {
258 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
259 zfcp_fsf_link_down_info_eval(req, 38, ldi);
261 case FSF_STATUS_READ_SUB_FDISC_FAILED:
262 zfcp_fsf_link_down_info_eval(req, 39, ldi);
264 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
265 zfcp_fsf_link_down_info_eval(req, 40, NULL);
269 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
271 struct zfcp_adapter *adapter = req->adapter;
272 struct fsf_status_read_buffer *sr_buf = req->data;
274 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
275 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
276 mempool_free(sr_buf, adapter->pool.data_status_read);
277 zfcp_fsf_req_free(req);
281 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
283 switch (sr_buf->status_type) {
284 case FSF_STATUS_READ_PORT_CLOSED:
285 zfcp_fsf_status_read_port_closed(req);
287 case FSF_STATUS_READ_INCOMING_ELS:
288 zfcp_fc_incoming_els(req);
290 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
292 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
293 dev_warn(&adapter->ccw_device->dev,
294 "The error threshold for checksum statistics "
295 "has been exceeded\n");
297 case FSF_STATUS_READ_LINK_DOWN:
298 zfcp_fsf_status_read_link_down(req);
300 case FSF_STATUS_READ_LINK_UP:
301 dev_info(&adapter->ccw_device->dev,
302 "The local link has been restored\n");
303 /* All ports should be marked as ready to run again */
304 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
305 ZFCP_STATUS_COMMON_RUNNING,
307 zfcp_erp_adapter_reopen(adapter,
308 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
309 ZFCP_STATUS_COMMON_ERP_FAILED,
312 case FSF_STATUS_READ_NOTIFICATION_LOST:
313 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
314 zfcp_erp_adapter_access_changed(adapter, 135, req);
315 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
316 schedule_work(&adapter->scan_work);
318 case FSF_STATUS_READ_CFDC_UPDATED:
319 zfcp_erp_adapter_access_changed(adapter, 136, req);
321 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
322 adapter->adapter_features = sr_buf->payload.word[0];
326 mempool_free(sr_buf, adapter->pool.data_status_read);
327 zfcp_fsf_req_free(req);
329 atomic_inc(&adapter->stat_miss);
330 schedule_work(&adapter->stat_work);
333 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
335 switch (req->qtcb->header.fsf_status_qual.word[0]) {
336 case FSF_SQ_FCP_RSP_AVAILABLE:
337 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
338 case FSF_SQ_NO_RETRY_POSSIBLE:
339 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
341 case FSF_SQ_COMMAND_ABORTED:
342 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
344 case FSF_SQ_NO_RECOM:
345 dev_err(&req->adapter->ccw_device->dev,
346 "The FCP adapter reported a problem "
347 "that cannot be recovered\n");
348 zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
351 /* all non-return stats set FSFREQ_ERROR*/
352 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
355 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
357 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
360 switch (req->qtcb->header.fsf_status) {
361 case FSF_UNKNOWN_COMMAND:
362 dev_err(&req->adapter->ccw_device->dev,
363 "The FCP adapter does not recognize the command 0x%x\n",
364 req->qtcb->header.fsf_command);
365 zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
366 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
368 case FSF_ADAPTER_STATUS_AVAILABLE:
369 zfcp_fsf_fsfstatus_qual_eval(req);
374 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
376 struct zfcp_adapter *adapter = req->adapter;
377 struct fsf_qtcb *qtcb = req->qtcb;
378 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
380 zfcp_hba_dbf_event_fsf_response(req);
382 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
383 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
384 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
388 switch (qtcb->prefix.prot_status) {
390 case FSF_PROT_FSF_STATUS_PRESENTED:
392 case FSF_PROT_QTCB_VERSION_ERROR:
393 dev_err(&adapter->ccw_device->dev,
394 "QTCB version 0x%x not supported by FCP adapter "
395 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
396 psq->word[0], psq->word[1]);
397 zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
399 case FSF_PROT_ERROR_STATE:
400 case FSF_PROT_SEQ_NUMB_ERROR:
401 zfcp_erp_adapter_reopen(adapter, 0, 98, req);
402 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
404 case FSF_PROT_UNSUPP_QTCB_TYPE:
405 dev_err(&adapter->ccw_device->dev,
406 "The QTCB type is not supported by the FCP adapter\n");
407 zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
409 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
410 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
413 case FSF_PROT_DUPLICATE_REQUEST_ID:
414 dev_err(&adapter->ccw_device->dev,
415 "0x%Lx is an ambiguous request identifier\n",
416 (unsigned long long)qtcb->bottom.support.req_handle);
417 zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
419 case FSF_PROT_LINK_DOWN:
420 zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
421 /* FIXME: reopening adapter now? better wait for link up */
422 zfcp_erp_adapter_reopen(adapter, 0, 79, req);
424 case FSF_PROT_REEST_QUEUE:
425 /* All ports should be marked as ready to run again */
426 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
427 ZFCP_STATUS_COMMON_RUNNING,
429 zfcp_erp_adapter_reopen(adapter,
430 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
431 ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
434 dev_err(&adapter->ccw_device->dev,
435 "0x%x is not a valid transfer protocol status\n",
436 qtcb->prefix.prot_status);
437 zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
439 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
443 * zfcp_fsf_req_complete - process completion of a FSF request
444 * @fsf_req: The FSF request that has been completed.
446 * When a request has been completed either from the FCP adapter,
447 * or it has been dismissed due to a queue shutdown, this function
448 * is called to process the completion status and trigger further
449 * events related to the FSF request.
451 void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
453 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
454 zfcp_fsf_status_read_handler(req);
458 del_timer(&req->timer);
459 zfcp_fsf_protstatus_eval(req);
460 zfcp_fsf_fsfstatus_eval(req);
464 zfcp_erp_notify(req->erp_action, 0);
465 req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
467 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
468 zfcp_fsf_req_free(req);
470 /* notify initiator waiting for the requests completion */
472 * FIXME: Race! We must not access fsf_req here as it might have been
473 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
474 * flag. It's an improbable case. But, we have the same paranoia for
475 * the cleanup flag already.
476 * Might better be handled using complete()?
477 * (setting the flag and doing wakeup ought to be atomic
478 * with regard to checking the flag as long as waitqueue is
479 * part of the to be released structure)
481 wake_up(&req->completion_wq);
484 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
486 struct fsf_qtcb_bottom_config *bottom;
487 struct zfcp_adapter *adapter = req->adapter;
488 struct Scsi_Host *shost = adapter->scsi_host;
490 bottom = &req->qtcb->bottom.config;
493 memcpy(req->data, bottom, sizeof(*bottom));
495 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
496 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
497 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
498 fc_host_speed(shost) = bottom->fc_link_speed;
499 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
501 adapter->hydra_version = bottom->adapter_type;
502 adapter->timer_ticks = bottom->timer_interval;
504 if (fc_host_permanent_port_name(shost) == -1)
505 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
507 switch (bottom->fc_topology) {
509 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
510 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
511 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
512 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
514 case FSF_TOPO_FABRIC:
515 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
518 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
520 dev_err(&adapter->ccw_device->dev,
521 "Unknown or unsupported arbitrated loop "
522 "fibre channel topology detected\n");
523 zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
530 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
532 struct zfcp_adapter *adapter = req->adapter;
533 struct fsf_qtcb *qtcb = req->qtcb;
534 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
535 struct Scsi_Host *shost = adapter->scsi_host;
537 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
540 adapter->fsf_lic_version = bottom->lic_version;
541 adapter->adapter_features = bottom->adapter_features;
542 adapter->connection_features = bottom->connection_features;
543 adapter->peer_wwpn = 0;
544 adapter->peer_wwnn = 0;
545 adapter->peer_d_id = 0;
547 switch (qtcb->header.fsf_status) {
549 if (zfcp_fsf_exchange_config_evaluate(req))
552 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
553 dev_err(&adapter->ccw_device->dev,
554 "FCP adapter maximum QTCB size (%d bytes) "
556 bottom->max_qtcb_size);
557 zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
560 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
563 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
564 fc_host_node_name(shost) = 0;
565 fc_host_port_name(shost) = 0;
566 fc_host_port_id(shost) = 0;
567 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
568 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
569 adapter->hydra_version = 0;
571 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
574 zfcp_fsf_link_down_info_eval(req, 42,
575 &qtcb->header.fsf_status_qual.link_down_info);
578 zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
582 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
583 adapter->hardware_version = bottom->hardware_version;
584 memcpy(fc_host_serial_number(shost), bottom->serial_number,
585 min(FC_SERIAL_NUMBER_SIZE, 17));
586 EBCASC(fc_host_serial_number(shost),
587 min(FC_SERIAL_NUMBER_SIZE, 17));
590 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
591 dev_err(&adapter->ccw_device->dev,
592 "The FCP adapter only supports newer "
593 "control block versions\n");
594 zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
597 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
598 dev_err(&adapter->ccw_device->dev,
599 "The FCP adapter only supports older "
600 "control block versions\n");
601 zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
605 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
607 struct zfcp_adapter *adapter = req->adapter;
608 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
609 struct Scsi_Host *shost = adapter->scsi_host;
612 memcpy(req->data, bottom, sizeof(*bottom));
614 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
615 fc_host_permanent_port_name(shost) = bottom->wwpn;
617 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
618 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
619 fc_host_supported_speeds(shost) = bottom->supported_speed;
622 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
624 struct zfcp_adapter *adapter = req->adapter;
625 struct fsf_qtcb *qtcb = req->qtcb;
627 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
630 switch (qtcb->header.fsf_status) {
632 zfcp_fsf_exchange_port_evaluate(req);
633 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
635 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
636 zfcp_fsf_exchange_port_evaluate(req);
637 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
638 zfcp_fsf_link_down_info_eval(req, 43,
639 &qtcb->header.fsf_status_qual.link_down_info);
644 static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
646 spin_lock_bh(&queue->lock);
647 if (atomic_read(&queue->count))
649 spin_unlock_bh(&queue->lock);
653 static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
655 unsigned int count = atomic_read(&adapter->req_q.count);
657 atomic_inc(&adapter->qdio_outb_full);
661 static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
664 struct zfcp_qdio_queue *req_q = &adapter->req_q;
666 spin_unlock_bh(&req_q->lock);
667 ret = wait_event_interruptible_timeout(adapter->request_wq,
668 zfcp_fsf_sbal_check(req_q), 5 * HZ);
672 atomic_inc(&adapter->qdio_outb_full);
674 spin_lock_bh(&req_q->lock);
678 static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
680 struct zfcp_fsf_req *req;
681 req = mempool_alloc(pool, GFP_ATOMIC);
684 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 volatile 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;
771 struct zfcp_qdio_queue *req_q = &adapter->req_q;
774 /* put allocated FSF request into hash table */
775 spin_lock(&adapter->req_list_lock);
776 idx = zfcp_reqlist_hash(req->req_id);
777 list_add_tail(&req->list, &adapter->req_list[idx]);
778 spin_unlock(&adapter->req_list_lock);
780 req->issued = get_clock();
781 if (zfcp_qdio_send(req)) {
782 /* Queues are down..... */
783 del_timer(&req->timer);
784 spin_lock(&adapter->req_list_lock);
785 zfcp_reqlist_remove(adapter, req);
786 spin_unlock(&adapter->req_list_lock);
787 /* undo changes in request queue made for this request */
788 atomic_add(req->sbal_number, &req_q->count);
789 req_q->first -= req->sbal_number;
790 req_q->first += QDIO_MAX_BUFFERS_PER_Q;
791 req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
792 zfcp_erp_adapter_reopen(adapter, 0, 116, req);
796 /* Don't increase for unsolicited status */
798 adapter->fsf_req_seq_no++;
804 * zfcp_fsf_status_read - send status read request
805 * @adapter: pointer to struct zfcp_adapter
806 * @req_flags: request flags
807 * Returns: 0 on success, ERROR otherwise
809 int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
811 struct zfcp_fsf_req *req;
812 struct fsf_status_read_buffer *sr_buf;
813 volatile struct qdio_buffer_element *sbale;
816 spin_lock_bh(&adapter->req_q.lock);
817 if (zfcp_fsf_req_sbal_get(adapter))
820 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
822 adapter->pool.fsf_req_status_read);
824 retval = PTR_ERR(req);
828 sbale = zfcp_qdio_sbale_req(req);
829 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
830 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
833 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
838 memset(sr_buf, 0, sizeof(*sr_buf));
840 sbale = zfcp_qdio_sbale_curr(req);
841 sbale->addr = (void *) sr_buf;
842 sbale->length = sizeof(*sr_buf);
844 retval = zfcp_fsf_req_send(req);
846 goto failed_req_send;
851 mempool_free(sr_buf, adapter->pool.data_status_read);
853 zfcp_fsf_req_free(req);
854 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
856 spin_unlock_bh(&adapter->req_q.lock);
860 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
862 struct zfcp_unit *unit = req->data;
863 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
865 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
868 switch (req->qtcb->header.fsf_status) {
869 case FSF_PORT_HANDLE_NOT_VALID:
870 if (fsq->word[0] == fsq->word[1]) {
871 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
873 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
876 case FSF_LUN_HANDLE_NOT_VALID:
877 if (fsq->word[0] == fsq->word[1]) {
878 zfcp_erp_port_reopen(unit->port, 0, 105, req);
879 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
882 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
883 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
886 zfcp_erp_port_boxed(unit->port, 47, req);
887 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
888 ZFCP_STATUS_FSFREQ_RETRY;
891 zfcp_erp_unit_boxed(unit, 48, req);
892 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
893 ZFCP_STATUS_FSFREQ_RETRY;
895 case FSF_ADAPTER_STATUS_AVAILABLE:
896 switch (fsq->word[0]) {
897 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
898 zfcp_test_link(unit->port);
899 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
900 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
905 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
911 * zfcp_fsf_abort_fcp_command - abort running SCSI command
912 * @old_req_id: unsigned long
913 * @adapter: pointer to struct zfcp_adapter
914 * @unit: pointer to struct zfcp_unit
915 * @req_flags: integer specifying the request flags
916 * Returns: pointer to struct zfcp_fsf_req
918 * FIXME(design): should be watched by a timeout !!!
921 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
922 struct zfcp_adapter *adapter,
923 struct zfcp_unit *unit,
926 volatile struct qdio_buffer_element *sbale;
927 struct zfcp_fsf_req *req = NULL;
929 spin_lock(&adapter->req_q.lock);
930 if (!zfcp_fsf_sbal_available(adapter))
932 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
933 req_flags, adapter->pool.fsf_req_abort);
937 if (unlikely(!(atomic_read(&unit->status) &
938 ZFCP_STATUS_COMMON_UNBLOCKED)))
941 sbale = zfcp_qdio_sbale_req(req);
942 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
943 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
946 req->handler = zfcp_fsf_abort_fcp_command_handler;
947 req->qtcb->header.lun_handle = unit->handle;
948 req->qtcb->header.port_handle = unit->port->handle;
949 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
951 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
952 if (!zfcp_fsf_req_send(req))
956 zfcp_fsf_req_free(req);
959 spin_unlock(&adapter->req_q.lock);
963 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
965 struct zfcp_adapter *adapter = req->adapter;
966 struct zfcp_send_ct *send_ct = req->data;
967 struct zfcp_port *port = send_ct->port;
968 struct fsf_qtcb_header *header = &req->qtcb->header;
970 send_ct->status = -EINVAL;
972 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
975 switch (header->fsf_status) {
977 zfcp_san_dbf_event_ct_response(req);
980 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
981 zfcp_fsf_class_not_supp(req);
983 case FSF_ADAPTER_STATUS_AVAILABLE:
984 switch (header->fsf_status_qual.word[0]){
985 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
986 zfcp_test_link(port);
987 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
988 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
992 case FSF_ACCESS_DENIED:
993 zfcp_fsf_access_denied_port(req, port);
996 zfcp_erp_port_boxed(port, 49, req);
997 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
998 ZFCP_STATUS_FSFREQ_RETRY;
1000 case FSF_PORT_HANDLE_NOT_VALID:
1001 zfcp_erp_adapter_reopen(adapter, 0, 106, req);
1002 case FSF_GENERIC_COMMAND_REJECTED:
1003 case FSF_PAYLOAD_SIZE_MISMATCH:
1004 case FSF_REQUEST_SIZE_TOO_LARGE:
1005 case FSF_RESPONSE_SIZE_TOO_LARGE:
1006 case FSF_SBAL_MISMATCH:
1007 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1012 if (send_ct->handler)
1013 send_ct->handler(send_ct->handler_data);
1016 static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
1017 struct scatterlist *sg_req,
1018 struct scatterlist *sg_resp, int max_sbals)
1022 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1026 req->qtcb->bottom.support.req_buf_length = bytes;
1027 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1029 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1030 sg_resp, max_sbals);
1033 req->qtcb->bottom.support.resp_buf_length = bytes;
1039 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1040 * @ct: pointer to struct zfcp_send_ct with data for request
1041 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1042 * @erp_action: if non-null the Generic Service request sent within ERP
1044 int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1045 struct zfcp_erp_action *erp_action)
1047 struct zfcp_port *port = ct->port;
1048 struct zfcp_adapter *adapter = port->adapter;
1049 struct zfcp_fsf_req *req;
1052 spin_lock_bh(&adapter->req_q.lock);
1053 if (zfcp_fsf_req_sbal_get(adapter))
1056 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1057 ZFCP_REQ_AUTO_CLEANUP, pool);
1063 ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
1064 FSF_MAX_SBALS_PER_REQ);
1068 req->handler = zfcp_fsf_send_ct_handler;
1069 req->qtcb->header.port_handle = port->handle;
1070 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1071 req->qtcb->bottom.support.timeout = ct->timeout;
1074 zfcp_san_dbf_event_ct_request(req);
1077 erp_action->fsf_req = req;
1078 req->erp_action = erp_action;
1079 zfcp_fsf_start_erp_timer(req);
1081 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1083 ret = zfcp_fsf_req_send(req);
1090 zfcp_fsf_req_free(req);
1092 erp_action->fsf_req = NULL;
1094 spin_unlock_bh(&adapter->req_q.lock);
1098 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1100 struct zfcp_send_els *send_els = req->data;
1101 struct zfcp_port *port = send_els->port;
1102 struct fsf_qtcb_header *header = &req->qtcb->header;
1104 send_els->status = -EINVAL;
1106 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1107 goto skip_fsfstatus;
1109 switch (header->fsf_status) {
1111 zfcp_san_dbf_event_els_response(req);
1112 send_els->status = 0;
1114 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1115 zfcp_fsf_class_not_supp(req);
1117 case FSF_ADAPTER_STATUS_AVAILABLE:
1118 switch (header->fsf_status_qual.word[0]){
1119 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1120 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1121 zfcp_test_link(port);
1123 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1124 case FSF_SQ_RETRY_IF_POSSIBLE:
1125 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1129 case FSF_ELS_COMMAND_REJECTED:
1130 case FSF_PAYLOAD_SIZE_MISMATCH:
1131 case FSF_REQUEST_SIZE_TOO_LARGE:
1132 case FSF_RESPONSE_SIZE_TOO_LARGE:
1134 case FSF_ACCESS_DENIED:
1135 zfcp_fsf_access_denied_port(req, port);
1137 case FSF_SBAL_MISMATCH:
1138 /* should never occure, avoided in zfcp_fsf_send_els */
1141 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1145 if (send_els->handler)
1146 send_els->handler(send_els->handler_data);
1150 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1151 * @els: pointer to struct zfcp_send_els with data for the command
1153 int zfcp_fsf_send_els(struct zfcp_send_els *els)
1155 struct zfcp_fsf_req *req;
1156 struct zfcp_adapter *adapter = els->adapter;
1157 struct fsf_qtcb_bottom_support *bottom;
1160 if (unlikely(!(atomic_read(&els->port->status) &
1161 ZFCP_STATUS_COMMON_UNBLOCKED)))
1164 spin_lock(&adapter->req_q.lock);
1165 if (!zfcp_fsf_sbal_available(adapter))
1167 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1168 ZFCP_REQ_AUTO_CLEANUP, NULL);
1174 ret = zfcp_fsf_setup_sbals(req, els->req, els->resp,
1175 FSF_MAX_SBALS_PER_ELS_REQ);
1179 bottom = &req->qtcb->bottom.support;
1180 req->handler = zfcp_fsf_send_els_handler;
1181 bottom->d_id = els->d_id;
1182 bottom->service_class = FSF_CLASS_3;
1183 bottom->timeout = 2 * R_A_TOV;
1186 zfcp_san_dbf_event_els_request(req);
1188 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1189 ret = zfcp_fsf_req_send(req);
1196 zfcp_fsf_req_free(req);
1198 spin_unlock(&adapter->req_q.lock);
1202 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1204 volatile struct qdio_buffer_element *sbale;
1205 struct zfcp_fsf_req *req;
1206 struct zfcp_adapter *adapter = erp_action->adapter;
1209 spin_lock_bh(&adapter->req_q.lock);
1210 if (!zfcp_fsf_sbal_available(adapter))
1212 req = zfcp_fsf_req_create(adapter,
1213 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1214 ZFCP_REQ_AUTO_CLEANUP,
1215 adapter->pool.fsf_req_erp);
1217 retval = PTR_ERR(req);
1221 sbale = zfcp_qdio_sbale_req(req);
1222 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1223 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1225 req->qtcb->bottom.config.feature_selection =
1227 FSF_FEATURE_LUN_SHARING |
1228 FSF_FEATURE_NOTIFICATION_LOST |
1229 FSF_FEATURE_UPDATE_ALERT;
1230 req->erp_action = erp_action;
1231 req->handler = zfcp_fsf_exchange_config_data_handler;
1232 erp_action->fsf_req = req;
1234 zfcp_fsf_start_erp_timer(req);
1235 retval = zfcp_fsf_req_send(req);
1237 zfcp_fsf_req_free(req);
1238 erp_action->fsf_req = NULL;
1241 spin_unlock_bh(&adapter->req_q.lock);
1245 int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1246 struct fsf_qtcb_bottom_config *data)
1248 volatile struct qdio_buffer_element *sbale;
1249 struct zfcp_fsf_req *req = NULL;
1252 spin_lock_bh(&adapter->req_q.lock);
1253 if (zfcp_fsf_req_sbal_get(adapter))
1256 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1259 retval = PTR_ERR(req);
1263 sbale = zfcp_qdio_sbale_req(req);
1264 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1265 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1266 req->handler = zfcp_fsf_exchange_config_data_handler;
1268 req->qtcb->bottom.config.feature_selection =
1270 FSF_FEATURE_LUN_SHARING |
1271 FSF_FEATURE_NOTIFICATION_LOST |
1272 FSF_FEATURE_UPDATE_ALERT;
1277 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1278 retval = zfcp_fsf_req_send(req);
1280 spin_unlock_bh(&adapter->req_q.lock);
1282 wait_event(req->completion_wq,
1283 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1285 zfcp_fsf_req_free(req);
1291 * zfcp_fsf_exchange_port_data - request information about local port
1292 * @erp_action: ERP action for the adapter for which port data is requested
1293 * Returns: 0 on success, error otherwise
1295 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1297 volatile struct qdio_buffer_element *sbale;
1298 struct zfcp_fsf_req *req;
1299 struct zfcp_adapter *adapter = erp_action->adapter;
1302 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1305 spin_lock_bh(&adapter->req_q.lock);
1306 if (!zfcp_fsf_sbal_available(adapter))
1308 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1309 ZFCP_REQ_AUTO_CLEANUP,
1310 adapter->pool.fsf_req_erp);
1312 retval = PTR_ERR(req);
1316 sbale = zfcp_qdio_sbale_req(req);
1317 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1318 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1320 req->handler = zfcp_fsf_exchange_port_data_handler;
1321 req->erp_action = erp_action;
1322 erp_action->fsf_req = req;
1324 zfcp_fsf_start_erp_timer(req);
1325 retval = zfcp_fsf_req_send(req);
1327 zfcp_fsf_req_free(req);
1328 erp_action->fsf_req = NULL;
1331 spin_unlock_bh(&adapter->req_q.lock);
1336 * zfcp_fsf_exchange_port_data_sync - request information about local port
1337 * @adapter: pointer to struct zfcp_adapter
1338 * @data: pointer to struct fsf_qtcb_bottom_port
1339 * Returns: 0 on success, error otherwise
1341 int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1342 struct fsf_qtcb_bottom_port *data)
1344 volatile struct qdio_buffer_element *sbale;
1345 struct zfcp_fsf_req *req = NULL;
1348 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1351 spin_lock_bh(&adapter->req_q.lock);
1352 if (!zfcp_fsf_sbal_available(adapter))
1355 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1358 retval = PTR_ERR(req);
1365 sbale = zfcp_qdio_sbale_req(req);
1366 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1367 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1369 req->handler = zfcp_fsf_exchange_port_data_handler;
1370 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1371 retval = zfcp_fsf_req_send(req);
1373 spin_unlock_bh(&adapter->req_q.lock);
1375 wait_event(req->completion_wq,
1376 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1377 zfcp_fsf_req_free(req);
1382 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1384 struct zfcp_port *port = req->data;
1385 struct fsf_qtcb_header *header = &req->qtcb->header;
1386 struct fsf_plogi *plogi;
1388 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1389 goto skip_fsfstatus;
1391 switch (header->fsf_status) {
1392 case FSF_PORT_ALREADY_OPEN:
1394 case FSF_ACCESS_DENIED:
1395 zfcp_fsf_access_denied_port(req, port);
1397 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1398 dev_warn(&req->adapter->ccw_device->dev,
1399 "Not enough FCP adapter resources to open "
1400 "remote port 0x%016Lx\n", port->wwpn);
1401 zfcp_erp_port_failed(port, 31, req);
1402 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1404 case FSF_ADAPTER_STATUS_AVAILABLE:
1405 switch (header->fsf_status_qual.word[0]) {
1406 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1407 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1408 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1410 case FSF_SQ_NO_RETRY_POSSIBLE:
1411 dev_warn(&req->adapter->ccw_device->dev,
1412 "Remote port 0x%016Lx could not be opened\n",
1414 zfcp_erp_port_failed(port, 32, req);
1415 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1420 port->handle = header->port_handle;
1421 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1422 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1423 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1424 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1426 /* check whether D_ID has changed during open */
1428 * FIXME: This check is not airtight, as the FCP channel does
1429 * not monitor closures of target port connections caused on
1430 * the remote side. Thus, they might miss out on invalidating
1431 * locally cached WWPNs (and other N_Port parameters) of gone
1432 * target ports. So, our heroic attempt to make things safe
1433 * could be undermined by 'open port' response data tagged with
1434 * obsolete WWPNs. Another reason to monitor potential
1435 * connection closures ourself at least (by interpreting
1436 * incoming ELS' and unsolicited status). It just crosses my
1437 * mind that one should be able to cross-check by means of
1438 * another GID_PN straight after a port has been opened.
1439 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1441 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN)
1444 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1445 if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
1446 if (plogi->serv_param.wwpn != port->wwpn)
1447 atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
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;
1461 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
1465 * zfcp_fsf_open_port - create and send open port request
1466 * @erp_action: pointer to struct zfcp_erp_action
1467 * Returns: 0 on success, error otherwise
1469 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1471 volatile struct qdio_buffer_element *sbale;
1472 struct zfcp_adapter *adapter = erp_action->adapter;
1473 struct zfcp_fsf_req *req;
1476 spin_lock_bh(&adapter->req_q.lock);
1477 if (zfcp_fsf_req_sbal_get(adapter))
1480 req = zfcp_fsf_req_create(adapter,
1481 FSF_QTCB_OPEN_PORT_WITH_DID,
1482 ZFCP_REQ_AUTO_CLEANUP,
1483 adapter->pool.fsf_req_erp);
1485 retval = PTR_ERR(req);
1489 sbale = zfcp_qdio_sbale_req(req);
1490 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1491 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1493 req->handler = zfcp_fsf_open_port_handler;
1494 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
1495 req->data = erp_action->port;
1496 req->erp_action = erp_action;
1497 erp_action->fsf_req = req;
1498 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
1500 zfcp_fsf_start_erp_timer(req);
1501 retval = zfcp_fsf_req_send(req);
1503 zfcp_fsf_req_free(req);
1504 erp_action->fsf_req = NULL;
1507 spin_unlock_bh(&adapter->req_q.lock);
1511 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1513 struct zfcp_port *port = req->data;
1515 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1516 goto skip_fsfstatus;
1518 switch (req->qtcb->header.fsf_status) {
1519 case FSF_PORT_HANDLE_NOT_VALID:
1520 zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
1521 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1523 case FSF_ADAPTER_STATUS_AVAILABLE:
1526 zfcp_erp_modify_port_status(port, 33, req,
1527 ZFCP_STATUS_COMMON_OPEN,
1533 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
1537 * zfcp_fsf_close_port - create and send close port request
1538 * @erp_action: pointer to struct zfcp_erp_action
1539 * Returns: 0 on success, error otherwise
1541 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1543 volatile struct qdio_buffer_element *sbale;
1544 struct zfcp_adapter *adapter = erp_action->adapter;
1545 struct zfcp_fsf_req *req;
1548 spin_lock_bh(&adapter->req_q.lock);
1549 if (zfcp_fsf_req_sbal_get(adapter))
1552 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1553 ZFCP_REQ_AUTO_CLEANUP,
1554 adapter->pool.fsf_req_erp);
1556 retval = PTR_ERR(req);
1560 sbale = zfcp_qdio_sbale_req(req);
1561 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1562 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1564 req->handler = zfcp_fsf_close_port_handler;
1565 req->data = erp_action->port;
1566 req->erp_action = erp_action;
1567 req->qtcb->header.port_handle = erp_action->port->handle;
1568 erp_action->fsf_req = req;
1569 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
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_close_physical_port_handler(struct zfcp_fsf_req *req)
1584 struct zfcp_port *port = req->data;
1585 struct fsf_qtcb_header *header = &req->qtcb->header;
1586 struct zfcp_unit *unit;
1588 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1589 goto skip_fsfstatus;
1591 switch (header->fsf_status) {
1592 case FSF_PORT_HANDLE_NOT_VALID:
1593 zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
1594 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1596 case FSF_ACCESS_DENIED:
1597 zfcp_fsf_access_denied_port(req, port);
1599 case FSF_PORT_BOXED:
1600 zfcp_erp_port_boxed(port, 50, req);
1601 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1602 ZFCP_STATUS_FSFREQ_RETRY;
1603 /* can't use generic zfcp_erp_modify_port_status because
1604 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1605 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1606 list_for_each_entry(unit, &port->unit_list_head, list)
1607 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1610 case FSF_ADAPTER_STATUS_AVAILABLE:
1611 switch (header->fsf_status_qual.word[0]) {
1612 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1614 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1615 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1620 /* can't use generic zfcp_erp_modify_port_status because
1621 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1623 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1624 list_for_each_entry(unit, &port->unit_list_head, list)
1625 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1630 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
1634 * zfcp_fsf_close_physical_port - close physical port
1635 * @erp_action: pointer to struct zfcp_erp_action
1636 * Returns: 0 on success
1638 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1640 volatile struct qdio_buffer_element *sbale;
1641 struct zfcp_adapter *adapter = erp_action->adapter;
1642 struct zfcp_fsf_req *req;
1645 spin_lock_bh(&adapter->req_q.lock);
1646 if (zfcp_fsf_req_sbal_get(adapter))
1649 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1650 ZFCP_REQ_AUTO_CLEANUP,
1651 adapter->pool.fsf_req_erp);
1653 retval = PTR_ERR(req);
1657 sbale = zfcp_qdio_sbale_req(req);
1658 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1659 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1661 req->data = erp_action->port;
1662 req->qtcb->header.port_handle = erp_action->port->handle;
1663 req->erp_action = erp_action;
1664 req->handler = zfcp_fsf_close_physical_port_handler;
1665 erp_action->fsf_req = req;
1666 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
1667 &erp_action->port->status);
1669 zfcp_fsf_start_erp_timer(req);
1670 retval = zfcp_fsf_req_send(req);
1672 zfcp_fsf_req_free(req);
1673 erp_action->fsf_req = NULL;
1676 spin_unlock_bh(&adapter->req_q.lock);
1680 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1682 struct zfcp_adapter *adapter = req->adapter;
1683 struct zfcp_unit *unit = req->data;
1684 struct fsf_qtcb_header *header = &req->qtcb->header;
1685 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1686 struct fsf_queue_designator *queue_designator =
1687 &header->fsf_status_qual.fsf_queue_designator;
1688 int exclusive, readwrite;
1690 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1691 goto skip_fsfstatus;
1693 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1694 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1695 ZFCP_STATUS_UNIT_SHARED |
1696 ZFCP_STATUS_UNIT_READONLY,
1699 switch (header->fsf_status) {
1701 case FSF_PORT_HANDLE_NOT_VALID:
1702 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
1704 case FSF_LUN_ALREADY_OPEN:
1706 case FSF_ACCESS_DENIED:
1707 zfcp_fsf_access_denied_unit(req, unit);
1708 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1709 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1711 case FSF_PORT_BOXED:
1712 zfcp_erp_port_boxed(unit->port, 51, req);
1713 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1714 ZFCP_STATUS_FSFREQ_RETRY;
1716 case FSF_LUN_SHARING_VIOLATION:
1717 if (header->fsf_status_qual.word[0])
1718 dev_warn(&adapter->ccw_device->dev,
1719 "LUN 0x%Lx on port 0x%Lx is already in "
1720 "use by CSS%d, MIF Image ID %x\n",
1723 queue_designator->cssid,
1724 queue_designator->hla);
1726 zfcp_act_eval_err(adapter,
1727 header->fsf_status_qual.word[2]);
1728 zfcp_erp_unit_access_denied(unit, 60, req);
1729 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1730 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1731 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1733 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1734 dev_warn(&adapter->ccw_device->dev,
1735 "No handle is available for LUN "
1736 "0x%016Lx on port 0x%016Lx\n",
1737 unit->fcp_lun, unit->port->wwpn);
1738 zfcp_erp_unit_failed(unit, 34, req);
1740 case FSF_INVALID_COMMAND_OPTION:
1741 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1743 case FSF_ADAPTER_STATUS_AVAILABLE:
1744 switch (header->fsf_status_qual.word[0]) {
1745 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1746 zfcp_test_link(unit->port);
1748 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1749 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1755 unit->handle = header->lun_handle;
1756 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1758 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1759 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1760 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
1761 exclusive = (bottom->lun_access_info &
1762 FSF_UNIT_ACCESS_EXCLUSIVE);
1763 readwrite = (bottom->lun_access_info &
1764 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1767 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1771 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1773 dev_info(&adapter->ccw_device->dev,
1774 "SCSI device at LUN 0x%016Lx on port "
1775 "0x%016Lx opened read-only\n",
1776 unit->fcp_lun, unit->port->wwpn);
1779 if (exclusive && !readwrite) {
1780 dev_err(&adapter->ccw_device->dev,
1781 "Exclusive read-only access not "
1782 "supported (unit 0x%016Lx, "
1784 unit->fcp_lun, unit->port->wwpn);
1785 zfcp_erp_unit_failed(unit, 35, req);
1786 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1787 zfcp_erp_unit_shutdown(unit, 0, 80, req);
1788 } else if (!exclusive && readwrite) {
1789 dev_err(&adapter->ccw_device->dev,
1790 "Shared read-write access not "
1791 "supported (unit 0x%016Lx, port "
1793 unit->fcp_lun, unit->port->wwpn);
1794 zfcp_erp_unit_failed(unit, 36, req);
1795 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1796 zfcp_erp_unit_shutdown(unit, 0, 81, req);
1803 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
1807 * zfcp_fsf_open_unit - open unit
1808 * @erp_action: pointer to struct zfcp_erp_action
1809 * Returns: 0 on success, error otherwise
1811 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1813 volatile struct qdio_buffer_element *sbale;
1814 struct zfcp_adapter *adapter = erp_action->adapter;
1815 struct zfcp_fsf_req *req;
1818 spin_lock_bh(&adapter->req_q.lock);
1819 if (zfcp_fsf_req_sbal_get(adapter))
1822 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1823 ZFCP_REQ_AUTO_CLEANUP,
1824 adapter->pool.fsf_req_erp);
1826 retval = PTR_ERR(req);
1830 sbale = zfcp_qdio_sbale_req(req);
1831 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1832 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1834 req->qtcb->header.port_handle = erp_action->port->handle;
1835 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1836 req->handler = zfcp_fsf_open_unit_handler;
1837 req->data = erp_action->unit;
1838 req->erp_action = erp_action;
1839 erp_action->fsf_req = req;
1841 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1842 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1844 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
1846 zfcp_fsf_start_erp_timer(req);
1847 retval = zfcp_fsf_req_send(req);
1849 zfcp_fsf_req_free(req);
1850 erp_action->fsf_req = NULL;
1853 spin_unlock_bh(&adapter->req_q.lock);
1857 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
1859 struct zfcp_unit *unit = req->data;
1861 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1862 goto skip_fsfstatus;
1864 switch (req->qtcb->header.fsf_status) {
1865 case FSF_PORT_HANDLE_NOT_VALID:
1866 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
1867 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1869 case FSF_LUN_HANDLE_NOT_VALID:
1870 zfcp_erp_port_reopen(unit->port, 0, 111, req);
1871 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1873 case FSF_PORT_BOXED:
1874 zfcp_erp_port_boxed(unit->port, 52, req);
1875 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1876 ZFCP_STATUS_FSFREQ_RETRY;
1878 case FSF_ADAPTER_STATUS_AVAILABLE:
1879 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1880 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1881 zfcp_test_link(unit->port);
1883 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1884 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1889 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1893 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
1897 * zfcp_fsf_close_unit - close zfcp unit
1898 * @erp_action: pointer to struct zfcp_unit
1899 * Returns: 0 on success, error otherwise
1901 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1903 volatile struct qdio_buffer_element *sbale;
1904 struct zfcp_adapter *adapter = erp_action->adapter;
1905 struct zfcp_fsf_req *req;
1908 spin_lock_bh(&adapter->req_q.lock);
1909 if (zfcp_fsf_req_sbal_get(adapter))
1911 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
1912 ZFCP_REQ_AUTO_CLEANUP,
1913 adapter->pool.fsf_req_erp);
1915 retval = PTR_ERR(req);
1919 sbale = zfcp_qdio_sbale_req(req);
1920 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1921 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1923 req->qtcb->header.port_handle = erp_action->port->handle;
1924 req->qtcb->header.lun_handle = erp_action->unit->handle;
1925 req->handler = zfcp_fsf_close_unit_handler;
1926 req->data = erp_action->unit;
1927 req->erp_action = erp_action;
1928 erp_action->fsf_req = req;
1929 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
1931 zfcp_fsf_start_erp_timer(req);
1932 retval = zfcp_fsf_req_send(req);
1934 zfcp_fsf_req_free(req);
1935 erp_action->fsf_req = NULL;
1938 spin_unlock_bh(&adapter->req_q.lock);
1942 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1944 lat_rec->sum += lat;
1945 lat_rec->min = min(lat_rec->min, lat);
1946 lat_rec->max = max(lat_rec->max, lat);
1949 static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
1951 struct fsf_qual_latency_info *lat_inf;
1952 struct latency_cont *lat;
1953 struct zfcp_unit *unit = req->unit;
1954 unsigned long flags;
1956 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
1958 switch (req->qtcb->bottom.io.data_direction) {
1959 case FSF_DATADIR_READ:
1960 lat = &unit->latencies.read;
1962 case FSF_DATADIR_WRITE:
1963 lat = &unit->latencies.write;
1965 case FSF_DATADIR_CMND:
1966 lat = &unit->latencies.cmd;
1972 spin_lock_irqsave(&unit->latencies.lock, flags);
1973 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
1974 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
1976 spin_unlock_irqrestore(&unit->latencies.lock, flags);
1979 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
1981 struct scsi_cmnd *scpnt = req->data;
1982 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
1983 &(req->qtcb->bottom.io.fcp_rsp);
1985 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
1986 unsigned long flags;
1988 if (unlikely(!scpnt))
1991 read_lock_irqsave(&req->adapter->abort_lock, flags);
1993 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
1994 set_host_byte(scpnt, DID_SOFT_ERROR);
1995 set_driver_byte(scpnt, SUGGEST_RETRY);
1996 goto skip_fsfstatus;
1999 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2000 set_host_byte(scpnt, DID_ERROR);
2001 goto skip_fsfstatus;
2004 set_msg_byte(scpnt, COMMAND_COMPLETE);
2006 scpnt->result |= fcp_rsp_iu->scsi_status;
2008 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2009 zfcp_fsf_req_latency(req);
2011 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
2012 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
2013 set_host_byte(scpnt, DID_OK);
2015 set_host_byte(scpnt, DID_ERROR);
2016 goto skip_fsfstatus;
2020 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
2021 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2022 fcp_rsp_iu->fcp_rsp_len;
2023 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
2024 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
2026 memcpy(scpnt->sense_buffer,
2027 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
2030 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
2031 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2032 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2034 set_host_byte(scpnt, DID_ERROR);
2037 if (scpnt->result != 0)
2038 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
2039 else if (scpnt->retries > 0)
2040 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
2042 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
2044 scpnt->host_scribble = NULL;
2045 (scpnt->scsi_done) (scpnt);
2047 * We must hold this lock until scsi_done has been called.
2048 * Otherwise we may call scsi_done after abort regarding this
2049 * command has completed.
2050 * Note: scsi_done must not block!
2052 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2055 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2057 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2058 &(req->qtcb->bottom.io.fcp_rsp);
2059 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2061 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2062 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2063 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2067 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2069 struct zfcp_unit *unit;
2070 struct fsf_qtcb_header *header = &req->qtcb->header;
2072 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2077 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2078 goto skip_fsfstatus;
2080 switch (header->fsf_status) {
2081 case FSF_HANDLE_MISMATCH:
2082 case FSF_PORT_HANDLE_NOT_VALID:
2083 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
2084 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2086 case FSF_FCPLUN_NOT_VALID:
2087 case FSF_LUN_HANDLE_NOT_VALID:
2088 zfcp_erp_port_reopen(unit->port, 0, 113, req);
2089 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2091 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2092 zfcp_fsf_class_not_supp(req);
2094 case FSF_ACCESS_DENIED:
2095 zfcp_fsf_access_denied_unit(req, unit);
2097 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2098 dev_err(&req->adapter->ccw_device->dev,
2099 "Incorrect direction %d, unit 0x%016Lx on port "
2100 "0x%016Lx closed\n",
2101 req->qtcb->bottom.io.data_direction,
2102 unit->fcp_lun, unit->port->wwpn);
2103 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
2104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2106 case FSF_CMND_LENGTH_NOT_VALID:
2107 dev_err(&req->adapter->ccw_device->dev,
2108 "Incorrect CDB length %d, unit 0x%016Lx on "
2109 "port 0x%016Lx closed\n",
2110 req->qtcb->bottom.io.fcp_cmnd_length,
2111 unit->fcp_lun, unit->port->wwpn);
2112 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
2113 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2115 case FSF_PORT_BOXED:
2116 zfcp_erp_port_boxed(unit->port, 53, req);
2117 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2118 ZFCP_STATUS_FSFREQ_RETRY;
2121 zfcp_erp_unit_boxed(unit, 54, req);
2122 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2123 ZFCP_STATUS_FSFREQ_RETRY;
2125 case FSF_ADAPTER_STATUS_AVAILABLE:
2126 if (header->fsf_status_qual.word[0] ==
2127 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2128 zfcp_test_link(unit->port);
2129 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2133 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2134 zfcp_fsf_send_fcp_ctm_handler(req);
2136 zfcp_fsf_send_fcp_command_task_handler(req);
2138 zfcp_unit_put(unit);
2143 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2144 * @adapter: adapter where scsi command is issued
2145 * @unit: unit where command is sent to
2146 * @scsi_cmnd: scsi command to be sent
2147 * @timer: timer to be started when request is initiated
2148 * @req_flags: flags for fsf_request
2150 int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
2151 struct zfcp_unit *unit,
2152 struct scsi_cmnd *scsi_cmnd,
2153 int use_timer, int req_flags)
2155 struct zfcp_fsf_req *req;
2156 struct fcp_cmnd_iu *fcp_cmnd_iu;
2157 unsigned int sbtype;
2158 int real_bytes, retval = -EIO;
2160 if (unlikely(!(atomic_read(&unit->status) &
2161 ZFCP_STATUS_COMMON_UNBLOCKED)))
2164 spin_lock(&adapter->req_q.lock);
2165 if (!zfcp_fsf_sbal_available(adapter))
2167 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2168 adapter->pool.fsf_req_scsi);
2170 retval = PTR_ERR(req);
2174 zfcp_unit_get(unit);
2176 req->data = scsi_cmnd;
2177 req->handler = zfcp_fsf_send_fcp_command_handler;
2178 req->qtcb->header.lun_handle = unit->handle;
2179 req->qtcb->header.port_handle = unit->port->handle;
2180 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2182 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2184 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2185 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2187 * set depending on data direction:
2188 * data direction bits in SBALE (SB Type)
2189 * data direction bits in QTCB
2190 * data direction bits in FCP_CMND IU
2192 switch (scsi_cmnd->sc_data_direction) {
2194 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2195 sbtype = SBAL_FLAGS0_TYPE_READ;
2197 case DMA_FROM_DEVICE:
2198 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2199 sbtype = SBAL_FLAGS0_TYPE_READ;
2200 fcp_cmnd_iu->rddata = 1;
2203 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2204 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2205 fcp_cmnd_iu->wddata = 1;
2207 case DMA_BIDIRECTIONAL:
2210 goto failed_scsi_cmnd;
2213 if (likely((scsi_cmnd->device->simple_tags) ||
2214 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2215 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2216 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2218 fcp_cmnd_iu->task_attribute = UNTAGGED;
2220 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2221 fcp_cmnd_iu->add_fcp_cdb_length =
2222 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2224 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2226 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2227 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
2229 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2230 scsi_sglist(scsi_cmnd),
2231 FSF_MAX_SBALS_PER_REQ);
2232 if (unlikely(real_bytes < 0)) {
2233 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2236 dev_err(&adapter->ccw_device->dev,
2237 "Oversize data package, unit 0x%016Lx "
2238 "on port 0x%016Lx closed\n",
2239 unit->fcp_lun, unit->port->wwpn);
2240 zfcp_erp_unit_shutdown(unit, 0, 131, req);
2243 goto failed_scsi_cmnd;
2246 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2249 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2251 retval = zfcp_fsf_req_send(req);
2252 if (unlikely(retval))
2253 goto failed_scsi_cmnd;
2258 zfcp_unit_put(unit);
2259 zfcp_fsf_req_free(req);
2260 scsi_cmnd->host_scribble = NULL;
2262 spin_unlock(&adapter->req_q.lock);
2267 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2268 * @adapter: pointer to struct zfcp-adapter
2269 * @unit: pointer to struct zfcp_unit
2270 * @tm_flags: unsigned byte for task management flags
2271 * @req_flags: int request flags
2272 * Returns: on success pointer to struct fsf_req, NULL otherwise
2274 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
2275 struct zfcp_unit *unit,
2276 u8 tm_flags, int req_flags)
2278 volatile struct qdio_buffer_element *sbale;
2279 struct zfcp_fsf_req *req = NULL;
2280 struct fcp_cmnd_iu *fcp_cmnd_iu;
2282 if (unlikely(!(atomic_read(&unit->status) &
2283 ZFCP_STATUS_COMMON_UNBLOCKED)))
2286 spin_lock(&adapter->req_q.lock);
2287 if (!zfcp_fsf_sbal_available(adapter))
2289 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2290 adapter->pool.fsf_req_scsi);
2294 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2296 req->handler = zfcp_fsf_send_fcp_command_handler;
2297 req->qtcb->header.lun_handle = unit->handle;
2298 req->qtcb->header.port_handle = unit->port->handle;
2299 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2300 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2301 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2304 sbale = zfcp_qdio_sbale_req(req);
2305 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2306 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2308 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2309 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2310 fcp_cmnd_iu->task_management_flags = tm_flags;
2312 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2313 if (!zfcp_fsf_req_send(req))
2316 zfcp_fsf_req_free(req);
2319 spin_unlock(&adapter->req_q.lock);
2323 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2325 if (req->qtcb->header.fsf_status != FSF_GOOD)
2326 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2330 * zfcp_fsf_control_file - control file upload/download
2331 * @adapter: pointer to struct zfcp_adapter
2332 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2333 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2335 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2336 struct zfcp_fsf_cfdc *fsf_cfdc)
2338 volatile struct qdio_buffer_element *sbale;
2339 struct zfcp_fsf_req *req = NULL;
2340 struct fsf_qtcb_bottom_support *bottom;
2341 int direction, retval = -EIO, bytes;
2343 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2344 return ERR_PTR(-EOPNOTSUPP);
2346 switch (fsf_cfdc->command) {
2347 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2348 direction = SBAL_FLAGS0_TYPE_WRITE;
2350 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2351 direction = SBAL_FLAGS0_TYPE_READ;
2354 return ERR_PTR(-EINVAL);
2357 spin_lock_bh(&adapter->req_q.lock);
2358 if (zfcp_fsf_req_sbal_get(adapter))
2361 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
2367 req->handler = zfcp_fsf_control_file_handler;
2369 sbale = zfcp_qdio_sbale_req(req);
2370 sbale[0].flags |= direction;
2372 bottom = &req->qtcb->bottom.support;
2373 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2374 bottom->option = fsf_cfdc->option;
2376 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2377 FSF_MAX_SBALS_PER_REQ);
2378 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2380 zfcp_fsf_req_free(req);
2384 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2385 retval = zfcp_fsf_req_send(req);
2387 spin_unlock_bh(&adapter->req_q.lock);
2390 wait_event(req->completion_wq,
2391 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2394 return ERR_PTR(retval);