4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2008
11 /* association between FSF command and FSF QTCB type */
12 static u32 fsf_qtcb_type[] = {
13 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
14 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
15 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
16 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
17 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
18 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
19 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
20 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
21 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
22 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
23 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
24 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
25 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
28 static const char *zfcp_act_subtable_type[] = {
29 "unknown", "OS", "WWPN", "DID", "LUN"
32 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
34 u16 subtable = table >> 16;
35 u16 rule = table & 0xffff;
37 if (subtable && subtable < ARRAY_SIZE(zfcp_act_subtable_type))
38 dev_warn(&adapter->ccw_device->dev,
39 "Access denied in subtable %s, rule %d.\n",
40 zfcp_act_subtable_type[subtable], rule);
43 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
44 struct zfcp_port *port)
46 struct fsf_qtcb_header *header = &req->qtcb->header;
47 dev_warn(&req->adapter->ccw_device->dev,
48 "Access denied, cannot send command to port 0x%016Lx.\n",
50 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
51 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
52 zfcp_erp_port_access_denied(port, 55, req);
53 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
56 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
57 struct zfcp_unit *unit)
59 struct fsf_qtcb_header *header = &req->qtcb->header;
60 dev_warn(&req->adapter->ccw_device->dev,
61 "Access denied for unit 0x%016Lx on port 0x%016Lx.\n",
62 unit->fcp_lun, unit->port->wwpn);
63 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
64 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
65 zfcp_erp_unit_access_denied(unit, 59, req);
66 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
69 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
71 dev_err(&req->adapter->ccw_device->dev,
72 "Required FC class not supported by adapter, "
73 "shutting down adapter.\n");
74 zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
75 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
79 * zfcp_fsf_req_free - free memory used by fsf request
80 * @fsf_req: pointer to struct zfcp_fsf_req
82 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
84 if (likely(req->pool)) {
85 mempool_free(req, req->pool);
90 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
96 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
97 * @adapter: pointer to struct zfcp_adapter
99 * Never ever call this without shutting down the adapter first.
100 * Otherwise the adapter would continue using and corrupting s390 storage.
101 * Included BUG_ON() call to ensure this is done.
102 * ERP is supposed to be the only user of this function.
104 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
106 struct zfcp_fsf_req *req, *tmp;
108 LIST_HEAD(remove_queue);
111 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
112 spin_lock_irqsave(&adapter->req_list_lock, flags);
113 for (i = 0; i < REQUEST_LIST_SIZE; i++)
114 list_splice_init(&adapter->req_list[i], &remove_queue);
115 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
117 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
118 list_del(&req->list);
119 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
120 zfcp_fsf_req_complete(req);
124 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
126 struct fsf_status_read_buffer *sr_buf = req->data;
127 struct zfcp_adapter *adapter = req->adapter;
128 struct zfcp_port *port;
129 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
132 read_lock_irqsave(&zfcp_data.config_lock, flags);
133 list_for_each_entry(port, &adapter->port_list_head, list)
134 if (port->d_id == d_id) {
135 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
136 switch (sr_buf->status_subtype) {
137 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
138 zfcp_erp_port_reopen(port, 0, 101, req);
140 case FSF_STATUS_READ_SUB_ERROR_PORT:
141 zfcp_erp_port_shutdown(port, 0, 122, req);
146 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
149 static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req)
151 struct zfcp_adapter *adapter = req->adapter;
152 struct fsf_status_read_buffer *sr_buf = req->data;
153 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
155 dev_warn(&adapter->ccw_device->dev,
156 "Warning: bit error threshold data "
157 "received for the adapter: "
158 "link failures = %i, loss of sync errors = %i, "
159 "loss of signal errors = %i, "
160 "primitive sequence errors = %i, "
161 "invalid transmission word errors = %i, "
162 "CRC errors = %i).\n",
163 err->link_failure_error_count,
164 err->loss_of_sync_error_count,
165 err->loss_of_signal_error_count,
166 err->primitive_sequence_error_count,
167 err->invalid_transmission_word_error_count,
168 err->crc_error_count);
169 dev_warn(&adapter->ccw_device->dev,
170 "Additional bit error threshold data of the adapter: "
171 "primitive sequence event time-outs = %i, "
172 "elastic buffer overrun errors = %i, "
173 "advertised receive buffer-to-buffer credit = %i, "
174 "current receice buffer-to-buffer credit = %i, "
175 "advertised transmit buffer-to-buffer credit = %i, "
176 "current transmit buffer-to-buffer credit = %i).\n",
177 err->primitive_sequence_event_timeout_count,
178 err->elastic_buffer_overrun_error_count,
179 err->advertised_receive_b2b_credit,
180 err->current_receive_b2b_credit,
181 err->advertised_transmit_b2b_credit,
182 err->current_transmit_b2b_credit);
185 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
186 struct fsf_link_down_info *link_down)
188 struct zfcp_adapter *adapter = req->adapter;
190 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
193 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
198 switch (link_down->error_code) {
199 case FSF_PSQ_LINK_NO_LIGHT:
200 dev_warn(&req->adapter->ccw_device->dev,
201 "The local link is down: no light detected.\n");
203 case FSF_PSQ_LINK_WRAP_PLUG:
204 dev_warn(&req->adapter->ccw_device->dev,
205 "The local link is down: wrap plug detected.\n");
207 case FSF_PSQ_LINK_NO_FCP:
208 dev_warn(&req->adapter->ccw_device->dev,
209 "The local link is down: "
210 "adjacent node on link does not support FCP.\n");
212 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
213 dev_warn(&req->adapter->ccw_device->dev,
214 "The local link is down: "
215 "firmware update in progress.\n");
217 case FSF_PSQ_LINK_INVALID_WWPN:
218 dev_warn(&req->adapter->ccw_device->dev,
219 "The local link is down: "
220 "duplicate or invalid WWPN detected.\n");
222 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
223 dev_warn(&req->adapter->ccw_device->dev,
224 "The local link is down: "
225 "no support for NPIV by Fabric.\n");
227 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
228 dev_warn(&req->adapter->ccw_device->dev,
229 "The local link is down: "
230 "out of resource in FCP daughtercard.\n");
232 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
233 dev_warn(&req->adapter->ccw_device->dev,
234 "The local link is down: "
235 "out of resource in Fabric.\n");
237 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
238 dev_warn(&req->adapter->ccw_device->dev,
239 "The local link is down: "
240 "unable to login to Fabric.\n");
242 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
243 dev_warn(&req->adapter->ccw_device->dev,
244 "WWPN assignment file corrupted on adapter.\n");
246 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
247 dev_warn(&req->adapter->ccw_device->dev,
248 "Mode table corrupted on adapter.\n");
250 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
251 dev_warn(&req->adapter->ccw_device->dev,
252 "No WWPN for assignment table on adapter.\n");
255 dev_warn(&req->adapter->ccw_device->dev,
256 "The local link to adapter is down.\n");
259 zfcp_erp_adapter_failed(adapter, id, req);
262 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
264 struct zfcp_adapter *adapter = req->adapter;
265 struct fsf_status_read_buffer *sr_buf = req->data;
266 struct fsf_link_down_info *ldi =
267 (struct fsf_link_down_info *) &sr_buf->payload;
269 switch (sr_buf->status_subtype) {
270 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
271 dev_warn(&adapter->ccw_device->dev,
272 "Physical link is down.\n");
273 zfcp_fsf_link_down_info_eval(req, 38, ldi);
275 case FSF_STATUS_READ_SUB_FDISC_FAILED:
276 dev_warn(&adapter->ccw_device->dev,
277 "Local link is down "
278 "due to failed FDISC login.\n");
279 zfcp_fsf_link_down_info_eval(req, 39, ldi);
281 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
282 dev_warn(&adapter->ccw_device->dev,
283 "Local link is down "
284 "due to firmware update on adapter.\n");
285 zfcp_fsf_link_down_info_eval(req, 40, NULL);
289 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
291 struct zfcp_adapter *adapter = req->adapter;
292 struct fsf_status_read_buffer *sr_buf = req->data;
294 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
295 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
296 mempool_free(sr_buf, adapter->pool.data_status_read);
297 zfcp_fsf_req_free(req);
301 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
303 switch (sr_buf->status_type) {
304 case FSF_STATUS_READ_PORT_CLOSED:
305 zfcp_fsf_status_read_port_closed(req);
307 case FSF_STATUS_READ_INCOMING_ELS:
308 zfcp_fc_incoming_els(req);
310 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
312 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
313 zfcp_fsf_bit_error_threshold(req);
315 case FSF_STATUS_READ_LINK_DOWN:
316 zfcp_fsf_status_read_link_down(req);
318 case FSF_STATUS_READ_LINK_UP:
319 dev_info(&adapter->ccw_device->dev,
320 "Local link was replugged.\n");
321 /* All ports should be marked as ready to run again */
322 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
323 ZFCP_STATUS_COMMON_RUNNING,
325 zfcp_erp_adapter_reopen(adapter,
326 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
327 ZFCP_STATUS_COMMON_ERP_FAILED,
330 case FSF_STATUS_READ_NOTIFICATION_LOST:
331 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
332 zfcp_erp_adapter_access_changed(adapter, 135, req);
333 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
334 schedule_work(&adapter->scan_work);
336 case FSF_STATUS_READ_CFDC_UPDATED:
337 zfcp_erp_adapter_access_changed(adapter, 136, req);
339 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
340 adapter->adapter_features = sr_buf->payload.word[0];
344 mempool_free(sr_buf, adapter->pool.data_status_read);
345 zfcp_fsf_req_free(req);
347 atomic_inc(&adapter->stat_miss);
348 schedule_work(&adapter->stat_work);
351 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
353 switch (req->qtcb->header.fsf_status_qual.word[0]) {
354 case FSF_SQ_FCP_RSP_AVAILABLE:
355 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
356 case FSF_SQ_NO_RETRY_POSSIBLE:
357 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
359 case FSF_SQ_COMMAND_ABORTED:
360 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
362 case FSF_SQ_NO_RECOM:
363 dev_err(&req->adapter->ccw_device->dev,
364 "No recommendation could be given for a "
365 "problem on the adapter.\n");
366 zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
369 /* all non-return stats set FSFREQ_ERROR*/
370 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
373 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
375 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
378 switch (req->qtcb->header.fsf_status) {
379 case FSF_UNKNOWN_COMMAND:
380 dev_err(&req->adapter->ccw_device->dev,
381 "Command issued by the device driver (0x%x) is "
382 "not known by the adapter.\n",
383 req->qtcb->header.fsf_command);
384 zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
385 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
387 case FSF_ADAPTER_STATUS_AVAILABLE:
388 zfcp_fsf_fsfstatus_qual_eval(req);
393 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
395 struct zfcp_adapter *adapter = req->adapter;
396 struct fsf_qtcb *qtcb = req->qtcb;
397 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
399 zfcp_hba_dbf_event_fsf_response(req);
401 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
402 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
403 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
407 switch (qtcb->prefix.prot_status) {
409 case FSF_PROT_FSF_STATUS_PRESENTED:
411 case FSF_PROT_QTCB_VERSION_ERROR:
412 dev_err(&adapter->ccw_device->dev,
413 "The QTCB version requested by zfcp (0x%x) is not "
414 "supported by the FCP adapter (lowest supported "
415 "0x%x, highest supported 0x%x).\n",
416 FSF_QTCB_CURRENT_VERSION, psq->word[0],
418 zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
420 case FSF_PROT_ERROR_STATE:
421 case FSF_PROT_SEQ_NUMB_ERROR:
422 zfcp_erp_adapter_reopen(adapter, 0, 98, req);
423 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
425 case FSF_PROT_UNSUPP_QTCB_TYPE:
426 dev_err(&adapter->ccw_device->dev,
427 "Packet header type used by the device driver is "
428 "incompatible with that used on the adapter.\n");
429 zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
431 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
432 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
435 case FSF_PROT_DUPLICATE_REQUEST_ID:
436 dev_err(&adapter->ccw_device->dev,
437 "The request identifier 0x%Lx is ambiguous.\n",
438 (unsigned long long)qtcb->bottom.support.req_handle);
439 zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
441 case FSF_PROT_LINK_DOWN:
442 zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
443 /* FIXME: reopening adapter now? better wait for link up */
444 zfcp_erp_adapter_reopen(adapter, 0, 79, req);
446 case FSF_PROT_REEST_QUEUE:
447 /* All ports should be marked as ready to run again */
448 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
449 ZFCP_STATUS_COMMON_RUNNING,
451 zfcp_erp_adapter_reopen(adapter,
452 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
453 ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
456 dev_err(&adapter->ccw_device->dev,
457 "Transfer protocol status information"
458 "provided by the adapter (0x%x) "
459 "is not compatible with the device driver.\n",
460 qtcb->prefix.prot_status);
461 zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
463 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
467 * zfcp_fsf_req_complete - process completion of a FSF request
468 * @fsf_req: The FSF request that has been completed.
470 * When a request has been completed either from the FCP adapter,
471 * or it has been dismissed due to a queue shutdown, this function
472 * is called to process the completion status and trigger further
473 * events related to the FSF request.
475 void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
477 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
478 zfcp_fsf_status_read_handler(req);
482 del_timer(&req->timer);
483 zfcp_fsf_protstatus_eval(req);
484 zfcp_fsf_fsfstatus_eval(req);
488 zfcp_erp_async_handler(req->erp_action, 0);
489 req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
491 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
492 zfcp_fsf_req_free(req);
494 /* notify initiator waiting for the requests completion */
496 * FIXME: Race! We must not access fsf_req here as it might have been
497 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
498 * flag. It's an improbable case. But, we have the same paranoia for
499 * the cleanup flag already.
500 * Might better be handled using complete()?
501 * (setting the flag and doing wakeup ought to be atomic
502 * with regard to checking the flag as long as waitqueue is
503 * part of the to be released structure)
505 wake_up(&req->completion_wq);
508 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
510 struct fsf_qtcb_bottom_config *bottom;
511 struct zfcp_adapter *adapter = req->adapter;
512 struct Scsi_Host *shost = adapter->scsi_host;
514 bottom = &req->qtcb->bottom.config;
517 memcpy(req->data, bottom, sizeof(*bottom));
519 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
520 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
521 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
522 fc_host_speed(shost) = bottom->fc_link_speed;
523 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
525 adapter->hydra_version = bottom->adapter_type;
526 adapter->timer_ticks = bottom->timer_interval;
528 if (fc_host_permanent_port_name(shost) == -1)
529 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
531 switch (bottom->fc_topology) {
533 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
534 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
535 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
536 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
538 dev_info(&adapter->ccw_device->dev,
539 "Point-to-Point fibrechannel "
540 "configuration detected.\n");
542 case FSF_TOPO_FABRIC:
543 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
545 dev_info(&adapter->ccw_device->dev,
546 "Switched fabric fibrechannel "
547 "network detected.\n");
550 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
551 dev_err(&adapter->ccw_device->dev,
552 "Unsupported arbitrated loop fibrechannel "
553 "topology detected, shutting down "
555 zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
558 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
559 dev_err(&adapter->ccw_device->dev,
560 "The fibrechannel topology reported by the"
561 " adapter is not known by the zfcp driver,"
562 " shutting down adapter.\n");
563 zfcp_erp_adapter_shutdown(adapter, 0, 128, req);
570 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
572 struct zfcp_adapter *adapter = req->adapter;
573 struct fsf_qtcb *qtcb = req->qtcb;
574 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
575 struct Scsi_Host *shost = adapter->scsi_host;
577 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
580 adapter->fsf_lic_version = bottom->lic_version;
581 adapter->adapter_features = bottom->adapter_features;
582 adapter->connection_features = bottom->connection_features;
583 adapter->peer_wwpn = 0;
584 adapter->peer_wwnn = 0;
585 adapter->peer_d_id = 0;
587 switch (qtcb->header.fsf_status) {
589 if (zfcp_fsf_exchange_config_evaluate(req))
592 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
593 dev_err(&adapter->ccw_device->dev,
594 "Maximum QTCB size (%d bytes) allowed by "
595 "the adapter is lower than the minimum "
596 "required by the driver (%ld bytes).\n",
597 bottom->max_qtcb_size,
598 sizeof(struct fsf_qtcb));
599 zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
602 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
605 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
606 fc_host_node_name(shost) = 0;
607 fc_host_port_name(shost) = 0;
608 fc_host_port_id(shost) = 0;
609 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
610 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
611 adapter->hydra_version = 0;
613 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
616 zfcp_fsf_link_down_info_eval(req, 42,
617 &qtcb->header.fsf_status_qual.link_down_info);
620 zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
624 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
625 adapter->hardware_version = bottom->hardware_version;
626 memcpy(fc_host_serial_number(shost), bottom->serial_number,
627 min(FC_SERIAL_NUMBER_SIZE, 17));
628 EBCASC(fc_host_serial_number(shost),
629 min(FC_SERIAL_NUMBER_SIZE, 17));
632 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
633 dev_err(&adapter->ccw_device->dev,
634 "The adapter only supports newer control block "
635 "versions, try updated device driver.\n");
636 zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
639 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
640 dev_err(&adapter->ccw_device->dev,
641 "The adapter only supports older control block "
642 "versions, consider a microcode upgrade.\n");
643 zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
647 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
649 struct zfcp_adapter *adapter = req->adapter;
650 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
651 struct Scsi_Host *shost = adapter->scsi_host;
654 memcpy(req->data, bottom, sizeof(*bottom));
656 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
657 fc_host_permanent_port_name(shost) = bottom->wwpn;
659 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
660 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
661 fc_host_supported_speeds(shost) = bottom->supported_speed;
664 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
666 struct zfcp_adapter *adapter = req->adapter;
667 struct fsf_qtcb *qtcb = req->qtcb;
669 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
672 switch (qtcb->header.fsf_status) {
674 zfcp_fsf_exchange_port_evaluate(req);
675 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
677 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
678 zfcp_fsf_exchange_port_evaluate(req);
679 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
680 zfcp_fsf_link_down_info_eval(req, 43,
681 &qtcb->header.fsf_status_qual.link_down_info);
686 static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
688 spin_lock(&queue->lock);
689 if (atomic_read(&queue->count))
691 spin_unlock(&queue->lock);
695 static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
698 struct zfcp_qdio_queue *req_q = &adapter->req_q;
700 spin_unlock(&req_q->lock);
701 ret = wait_event_interruptible_timeout(adapter->request_wq,
702 zfcp_fsf_sbal_check(req_q), 5 * HZ);
706 spin_lock(&req_q->lock);
710 static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
712 struct zfcp_fsf_req *req;
713 req = mempool_alloc(pool, GFP_ATOMIC);
716 memset(req, 0, sizeof(*req));
720 static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
722 struct zfcp_fsf_req_qtcb *qtcb;
725 qtcb = mempool_alloc(pool, GFP_ATOMIC);
727 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
732 memset(qtcb, 0, sizeof(*qtcb));
733 qtcb->fsf_req.qtcb = &qtcb->qtcb;
734 qtcb->fsf_req.pool = pool;
736 return &qtcb->fsf_req;
739 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
740 u32 fsf_cmd, int req_flags,
743 volatile struct qdio_buffer_element *sbale;
745 struct zfcp_fsf_req *req;
746 struct zfcp_qdio_queue *req_q = &adapter->req_q;
748 if (req_flags & ZFCP_REQ_NO_QTCB)
749 req = zfcp_fsf_alloc_noqtcb(pool);
751 req = zfcp_fsf_alloc_qtcb(pool);
754 return ERR_PTR(-EIO);
756 if (adapter->req_no == 0)
759 INIT_LIST_HEAD(&req->list);
760 init_timer(&req->timer);
761 init_waitqueue_head(&req->completion_wq);
763 req->adapter = adapter;
764 req->fsf_command = fsf_cmd;
765 req->req_id = adapter->req_no++;
766 req->sbal_number = 1;
767 req->sbal_first = req_q->first;
768 req->sbal_last = req_q->first;
771 sbale = zfcp_qdio_sbale_req(req);
772 sbale[0].addr = (void *) req->req_id;
773 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
775 if (likely(req->qtcb)) {
776 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
777 req->qtcb->prefix.req_id = req->req_id;
778 req->qtcb->prefix.ulp_info = 26;
779 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
780 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
781 req->qtcb->header.req_handle = req->req_id;
782 req->qtcb->header.fsf_command = req->fsf_command;
783 req->seq_no = adapter->fsf_req_seq_no;
784 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
785 sbale[1].addr = (void *) req->qtcb;
786 sbale[1].length = sizeof(struct fsf_qtcb);
789 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
790 zfcp_fsf_req_free(req);
791 return ERR_PTR(-EIO);
794 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
795 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
800 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
802 struct zfcp_adapter *adapter = req->adapter;
803 struct zfcp_qdio_queue *req_q = &adapter->req_q;
806 /* put allocated FSF request into hash table */
807 spin_lock(&adapter->req_list_lock);
808 idx = zfcp_reqlist_hash(req->req_id);
809 list_add_tail(&req->list, &adapter->req_list[idx]);
810 spin_unlock(&adapter->req_list_lock);
812 req->issued = get_clock();
813 if (zfcp_qdio_send(req)) {
814 /* Queues are down..... */
815 del_timer(&req->timer);
816 spin_lock(&adapter->req_list_lock);
817 zfcp_reqlist_remove(adapter, req);
818 spin_unlock(&adapter->req_list_lock);
819 /* undo changes in request queue made for this request */
820 atomic_add(req->sbal_number, &req_q->count);
821 req_q->first -= req->sbal_number;
822 req_q->first += QDIO_MAX_BUFFERS_PER_Q;
823 req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
824 zfcp_erp_adapter_reopen(adapter, 0, 116, req);
828 /* Don't increase for unsolicited status */
830 adapter->fsf_req_seq_no++;
836 * zfcp_fsf_status_read - send status read request
837 * @adapter: pointer to struct zfcp_adapter
838 * @req_flags: request flags
839 * Returns: 0 on success, ERROR otherwise
841 int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
843 struct zfcp_fsf_req *req;
844 struct fsf_status_read_buffer *sr_buf;
845 volatile struct qdio_buffer_element *sbale;
848 spin_lock(&adapter->req_q.lock);
849 if (zfcp_fsf_req_sbal_get(adapter))
852 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
854 adapter->pool.fsf_req_status_read);
855 if (unlikely(IS_ERR(req))) {
856 retval = PTR_ERR(req);
860 sbale = zfcp_qdio_sbale_req(req);
861 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
862 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
865 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
870 memset(sr_buf, 0, sizeof(*sr_buf));
872 sbale = zfcp_qdio_sbale_curr(req);
873 sbale->addr = (void *) sr_buf;
874 sbale->length = sizeof(*sr_buf);
876 retval = zfcp_fsf_req_send(req);
878 goto failed_req_send;
883 mempool_free(sr_buf, adapter->pool.data_status_read);
885 zfcp_fsf_req_free(req);
886 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
888 spin_unlock(&adapter->req_q.lock);
892 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
894 struct zfcp_unit *unit = req->data;
895 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
897 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
900 switch (req->qtcb->header.fsf_status) {
901 case FSF_PORT_HANDLE_NOT_VALID:
902 if (fsq->word[0] == fsq->word[1]) {
903 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
905 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
908 case FSF_LUN_HANDLE_NOT_VALID:
909 if (fsq->word[0] == fsq->word[1]) {
910 zfcp_erp_port_reopen(unit->port, 0, 105, req);
911 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
914 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
915 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
918 zfcp_erp_port_boxed(unit->port, 47, req);
919 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
920 ZFCP_STATUS_FSFREQ_RETRY;
923 zfcp_erp_unit_boxed(unit, 48, req);
924 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
925 ZFCP_STATUS_FSFREQ_RETRY;
927 case FSF_ADAPTER_STATUS_AVAILABLE:
928 switch (fsq->word[0]) {
929 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
930 zfcp_test_link(unit->port);
931 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
932 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
937 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
943 * zfcp_fsf_abort_fcp_command - abort running SCSI command
944 * @old_req_id: unsigned long
945 * @adapter: pointer to struct zfcp_adapter
946 * @unit: pointer to struct zfcp_unit
947 * @req_flags: integer specifying the request flags
948 * Returns: pointer to struct zfcp_fsf_req
950 * FIXME(design): should be watched by a timeout !!!
953 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
954 struct zfcp_adapter *adapter,
955 struct zfcp_unit *unit,
958 volatile struct qdio_buffer_element *sbale;
959 struct zfcp_fsf_req *req = NULL;
961 spin_lock(&adapter->req_q.lock);
962 if (!atomic_read(&adapter->req_q.count))
964 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
965 req_flags, adapter->pool.fsf_req_abort);
966 if (unlikely(IS_ERR(req)))
969 if (unlikely(!(atomic_read(&unit->status) &
970 ZFCP_STATUS_COMMON_UNBLOCKED)))
973 sbale = zfcp_qdio_sbale_req(req);
974 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
975 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
978 req->handler = zfcp_fsf_abort_fcp_command_handler;
979 req->qtcb->header.lun_handle = unit->handle;
980 req->qtcb->header.port_handle = unit->port->handle;
981 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
983 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
984 if (!zfcp_fsf_req_send(req))
988 zfcp_fsf_req_free(req);
991 spin_unlock(&adapter->req_q.lock);
995 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
997 struct zfcp_adapter *adapter = req->adapter;
998 struct zfcp_send_ct *send_ct = req->data;
999 struct zfcp_port *port = send_ct->port;
1000 struct fsf_qtcb_header *header = &req->qtcb->header;
1002 send_ct->status = -EINVAL;
1004 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1005 goto skip_fsfstatus;
1007 switch (header->fsf_status) {
1009 zfcp_san_dbf_event_ct_response(req);
1010 send_ct->status = 0;
1012 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1013 zfcp_fsf_class_not_supp(req);
1015 case FSF_ADAPTER_STATUS_AVAILABLE:
1016 switch (header->fsf_status_qual.word[0]){
1017 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1018 zfcp_test_link(port);
1019 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1020 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1024 case FSF_ACCESS_DENIED:
1025 zfcp_fsf_access_denied_port(req, port);
1027 case FSF_PORT_BOXED:
1028 zfcp_erp_port_boxed(port, 49, req);
1029 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1030 ZFCP_STATUS_FSFREQ_RETRY;
1032 case FSF_PORT_HANDLE_NOT_VALID:
1033 zfcp_erp_adapter_reopen(adapter, 0, 106, req);
1034 case FSF_GENERIC_COMMAND_REJECTED:
1035 case FSF_PAYLOAD_SIZE_MISMATCH:
1036 case FSF_REQUEST_SIZE_TOO_LARGE:
1037 case FSF_RESPONSE_SIZE_TOO_LARGE:
1038 case FSF_SBAL_MISMATCH:
1039 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1044 if (send_ct->handler)
1045 send_ct->handler(send_ct->handler_data);
1048 static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
1049 struct scatterlist *sg_req,
1050 struct scatterlist *sg_resp, int max_sbals)
1054 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1058 req->qtcb->bottom.support.req_buf_length = bytes;
1059 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1061 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1062 sg_resp, max_sbals);
1065 req->qtcb->bottom.support.resp_buf_length = bytes;
1071 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1072 * @ct: pointer to struct zfcp_send_ct with data for request
1073 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1074 * @erp_action: if non-null the Generic Service request sent within ERP
1076 int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1077 struct zfcp_erp_action *erp_action)
1079 struct zfcp_port *port = ct->port;
1080 struct zfcp_adapter *adapter = port->adapter;
1081 struct zfcp_fsf_req *req;
1084 spin_lock(&adapter->req_q.lock);
1085 if (zfcp_fsf_req_sbal_get(adapter))
1088 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1089 ZFCP_REQ_AUTO_CLEANUP, pool);
1090 if (unlikely(IS_ERR(req))) {
1095 ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
1096 FSF_MAX_SBALS_PER_REQ);
1100 req->handler = zfcp_fsf_send_ct_handler;
1101 req->qtcb->header.port_handle = port->handle;
1102 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1103 req->qtcb->bottom.support.timeout = ct->timeout;
1106 zfcp_san_dbf_event_ct_request(req);
1109 erp_action->fsf_req = req;
1110 req->erp_action = erp_action;
1111 zfcp_erp_start_timer(req);
1113 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1115 ret = zfcp_fsf_req_send(req);
1122 zfcp_fsf_req_free(req);
1124 erp_action->fsf_req = NULL;
1126 spin_unlock(&adapter->req_q.lock);
1130 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1132 struct zfcp_send_els *send_els = req->data;
1133 struct zfcp_port *port = send_els->port;
1134 struct fsf_qtcb_header *header = &req->qtcb->header;
1136 send_els->status = -EINVAL;
1138 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1139 goto skip_fsfstatus;
1141 switch (header->fsf_status) {
1143 zfcp_san_dbf_event_els_response(req);
1144 send_els->status = 0;
1146 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1147 zfcp_fsf_class_not_supp(req);
1149 case FSF_ADAPTER_STATUS_AVAILABLE:
1150 switch (header->fsf_status_qual.word[0]){
1151 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1152 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1153 zfcp_test_link(port);
1155 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1156 case FSF_SQ_RETRY_IF_POSSIBLE:
1157 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1161 case FSF_ELS_COMMAND_REJECTED:
1162 case FSF_PAYLOAD_SIZE_MISMATCH:
1163 case FSF_REQUEST_SIZE_TOO_LARGE:
1164 case FSF_RESPONSE_SIZE_TOO_LARGE:
1166 case FSF_ACCESS_DENIED:
1167 zfcp_fsf_access_denied_port(req, port);
1169 case FSF_SBAL_MISMATCH:
1170 /* should never occure, avoided in zfcp_fsf_send_els */
1173 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1177 if (send_els->handler)
1178 send_els->handler(send_els->handler_data);
1182 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1183 * @els: pointer to struct zfcp_send_els with data for the command
1185 int zfcp_fsf_send_els(struct zfcp_send_els *els)
1187 struct zfcp_fsf_req *req;
1188 struct zfcp_adapter *adapter = els->adapter;
1189 struct fsf_qtcb_bottom_support *bottom;
1192 if (unlikely(!(atomic_read(&els->port->status) &
1193 ZFCP_STATUS_COMMON_UNBLOCKED)))
1196 spin_lock(&adapter->req_q.lock);
1197 if (!atomic_read(&adapter->req_q.count))
1199 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1200 ZFCP_REQ_AUTO_CLEANUP, NULL);
1201 if (unlikely(IS_ERR(req))) {
1206 ret = zfcp_fsf_setup_sbals(req, els->req, els->resp,
1207 FSF_MAX_SBALS_PER_ELS_REQ);
1211 bottom = &req->qtcb->bottom.support;
1212 req->handler = zfcp_fsf_send_els_handler;
1213 bottom->d_id = els->d_id;
1214 bottom->service_class = FSF_CLASS_3;
1215 bottom->timeout = 2 * R_A_TOV;
1218 zfcp_san_dbf_event_els_request(req);
1220 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1221 ret = zfcp_fsf_req_send(req);
1228 zfcp_fsf_req_free(req);
1230 spin_unlock(&adapter->req_q.lock);
1234 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1236 volatile struct qdio_buffer_element *sbale;
1237 struct zfcp_fsf_req *req;
1238 struct zfcp_adapter *adapter = erp_action->adapter;
1241 spin_lock(&adapter->req_q.lock);
1242 if (!atomic_read(&adapter->req_q.count))
1244 req = zfcp_fsf_req_create(adapter,
1245 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1246 ZFCP_REQ_AUTO_CLEANUP,
1247 adapter->pool.fsf_req_erp);
1248 if (unlikely(IS_ERR(req))) {
1249 retval = PTR_ERR(req);
1253 sbale = zfcp_qdio_sbale_req(req);
1254 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1255 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1257 req->qtcb->bottom.config.feature_selection =
1259 FSF_FEATURE_LUN_SHARING |
1260 FSF_FEATURE_NOTIFICATION_LOST |
1261 FSF_FEATURE_UPDATE_ALERT;
1262 req->erp_action = erp_action;
1263 req->handler = zfcp_fsf_exchange_config_data_handler;
1264 erp_action->fsf_req = req;
1266 zfcp_erp_start_timer(req);
1267 retval = zfcp_fsf_req_send(req);
1269 zfcp_fsf_req_free(req);
1270 erp_action->fsf_req = NULL;
1273 spin_unlock(&adapter->req_q.lock);
1277 int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1278 struct fsf_qtcb_bottom_config *data)
1280 volatile struct qdio_buffer_element *sbale;
1281 struct zfcp_fsf_req *req = NULL;
1284 spin_lock(&adapter->req_q.lock);
1285 if (zfcp_fsf_req_sbal_get(adapter))
1288 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1290 if (unlikely(IS_ERR(req))) {
1291 retval = PTR_ERR(req);
1295 sbale = zfcp_qdio_sbale_req(req);
1296 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1297 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1298 req->handler = zfcp_fsf_exchange_config_data_handler;
1300 req->qtcb->bottom.config.feature_selection =
1302 FSF_FEATURE_LUN_SHARING |
1303 FSF_FEATURE_NOTIFICATION_LOST |
1304 FSF_FEATURE_UPDATE_ALERT;
1309 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1310 retval = zfcp_fsf_req_send(req);
1312 spin_unlock(&adapter->req_q.lock);
1314 wait_event(req->completion_wq,
1315 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1317 zfcp_fsf_req_free(req);
1323 * zfcp_fsf_exchange_port_data - request information about local port
1324 * @erp_action: ERP action for the adapter for which port data is requested
1325 * Returns: 0 on success, error otherwise
1327 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1329 volatile struct qdio_buffer_element *sbale;
1330 struct zfcp_fsf_req *req;
1331 struct zfcp_adapter *adapter = erp_action->adapter;
1334 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1337 spin_lock(&adapter->req_q.lock);
1338 if (!atomic_read(&adapter->req_q.count))
1340 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1341 ZFCP_REQ_AUTO_CLEANUP,
1342 adapter->pool.fsf_req_erp);
1343 if (unlikely(IS_ERR(req))) {
1344 retval = PTR_ERR(req);
1348 sbale = zfcp_qdio_sbale_req(req);
1349 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1350 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1352 req->handler = zfcp_fsf_exchange_port_data_handler;
1353 req->erp_action = erp_action;
1354 erp_action->fsf_req = req;
1356 zfcp_erp_start_timer(req);
1357 retval = zfcp_fsf_req_send(req);
1359 zfcp_fsf_req_free(req);
1360 erp_action->fsf_req = NULL;
1363 spin_unlock(&adapter->req_q.lock);
1368 * zfcp_fsf_exchange_port_data_sync - request information about local port
1369 * @adapter: pointer to struct zfcp_adapter
1370 * @data: pointer to struct fsf_qtcb_bottom_port
1371 * Returns: 0 on success, error otherwise
1373 int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1374 struct fsf_qtcb_bottom_port *data)
1376 volatile struct qdio_buffer_element *sbale;
1377 struct zfcp_fsf_req *req = NULL;
1380 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1383 spin_lock(&adapter->req_q.lock);
1384 if (!atomic_read(&adapter->req_q.count))
1387 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1389 if (unlikely(IS_ERR(req))) {
1390 retval = PTR_ERR(req);
1397 sbale = zfcp_qdio_sbale_req(req);
1398 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1399 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1401 req->handler = zfcp_fsf_exchange_port_data_handler;
1402 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1403 retval = zfcp_fsf_req_send(req);
1405 spin_unlock(&adapter->req_q.lock);
1407 wait_event(req->completion_wq,
1408 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1409 zfcp_fsf_req_free(req);
1414 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1416 struct zfcp_port *port = req->data;
1417 struct fsf_qtcb_header *header = &req->qtcb->header;
1418 struct fsf_plogi *plogi;
1420 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1421 goto skip_fsfstatus;
1423 switch (header->fsf_status) {
1424 case FSF_PORT_ALREADY_OPEN:
1426 case FSF_ACCESS_DENIED:
1427 zfcp_fsf_access_denied_port(req, port);
1429 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1430 dev_warn(&req->adapter->ccw_device->dev,
1431 "The adapter is out of resources. The remote port "
1432 "0x%016Lx could not be opened, disabling it.\n",
1434 zfcp_erp_port_failed(port, 31, req);
1435 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1437 case FSF_ADAPTER_STATUS_AVAILABLE:
1438 switch (header->fsf_status_qual.word[0]) {
1439 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1440 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1441 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1443 case FSF_SQ_NO_RETRY_POSSIBLE:
1444 dev_warn(&req->adapter->ccw_device->dev,
1445 "The remote port 0x%016Lx could not be "
1446 "opened. Disabling it.\n", port->wwpn);
1447 zfcp_erp_port_failed(port, 32, req);
1448 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1453 port->handle = header->port_handle;
1454 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1455 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1456 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1457 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1459 /* check whether D_ID has changed during open */
1461 * FIXME: This check is not airtight, as the FCP channel does
1462 * not monitor closures of target port connections caused on
1463 * the remote side. Thus, they might miss out on invalidating
1464 * locally cached WWPNs (and other N_Port parameters) of gone
1465 * target ports. So, our heroic attempt to make things safe
1466 * could be undermined by 'open port' response data tagged with
1467 * obsolete WWPNs. Another reason to monitor potential
1468 * connection closures ourself at least (by interpreting
1469 * incoming ELS' and unsolicited status). It just crosses my
1470 * mind that one should be able to cross-check by means of
1471 * another GID_PN straight after a port has been opened.
1472 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1474 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN)
1477 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1478 if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
1479 if (plogi->serv_param.wwpn != port->wwpn)
1480 atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
1483 port->wwnn = plogi->serv_param.wwnn;
1484 zfcp_fc_plogi_evaluate(port, plogi);
1488 case FSF_UNKNOWN_OP_SUBTYPE:
1489 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1494 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
1498 * zfcp_fsf_open_port - create and send open port request
1499 * @erp_action: pointer to struct zfcp_erp_action
1500 * Returns: 0 on success, error otherwise
1502 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1504 volatile struct qdio_buffer_element *sbale;
1505 struct zfcp_adapter *adapter = erp_action->adapter;
1506 struct zfcp_fsf_req *req;
1509 spin_lock(&adapter->req_q.lock);
1510 if (zfcp_fsf_req_sbal_get(adapter))
1513 req = zfcp_fsf_req_create(adapter,
1514 FSF_QTCB_OPEN_PORT_WITH_DID,
1515 ZFCP_REQ_AUTO_CLEANUP,
1516 adapter->pool.fsf_req_erp);
1517 if (unlikely(IS_ERR(req))) {
1518 retval = PTR_ERR(req);
1522 sbale = zfcp_qdio_sbale_req(req);
1523 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1524 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1526 req->handler = zfcp_fsf_open_port_handler;
1527 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
1528 req->data = erp_action->port;
1529 req->erp_action = erp_action;
1530 erp_action->fsf_req = req;
1531 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
1533 zfcp_erp_start_timer(req);
1534 retval = zfcp_fsf_req_send(req);
1536 zfcp_fsf_req_free(req);
1537 erp_action->fsf_req = NULL;
1540 spin_unlock(&adapter->req_q.lock);
1544 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1546 struct zfcp_port *port = req->data;
1548 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1549 goto skip_fsfstatus;
1551 switch (req->qtcb->header.fsf_status) {
1552 case FSF_PORT_HANDLE_NOT_VALID:
1553 zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
1554 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1556 case FSF_ADAPTER_STATUS_AVAILABLE:
1559 zfcp_erp_modify_port_status(port, 33, req,
1560 ZFCP_STATUS_COMMON_OPEN,
1566 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
1570 * zfcp_fsf_close_port - create and send close port request
1571 * @erp_action: pointer to struct zfcp_erp_action
1572 * Returns: 0 on success, error otherwise
1574 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1576 volatile struct qdio_buffer_element *sbale;
1577 struct zfcp_adapter *adapter = erp_action->adapter;
1578 struct zfcp_fsf_req *req;
1581 spin_lock(&adapter->req_q.lock);
1582 if (zfcp_fsf_req_sbal_get(adapter))
1585 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1586 ZFCP_REQ_AUTO_CLEANUP,
1587 adapter->pool.fsf_req_erp);
1588 if (unlikely(IS_ERR(req))) {
1589 retval = PTR_ERR(req);
1593 sbale = zfcp_qdio_sbale_req(req);
1594 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1595 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1597 req->handler = zfcp_fsf_close_port_handler;
1598 req->data = erp_action->port;
1599 req->erp_action = erp_action;
1600 req->qtcb->header.port_handle = erp_action->port->handle;
1601 erp_action->fsf_req = req;
1602 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
1604 zfcp_erp_start_timer(req);
1605 retval = zfcp_fsf_req_send(req);
1607 zfcp_fsf_req_free(req);
1608 erp_action->fsf_req = NULL;
1611 spin_unlock(&adapter->req_q.lock);
1615 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1617 struct zfcp_port *port = req->data;
1618 struct fsf_qtcb_header *header = &req->qtcb->header;
1619 struct zfcp_unit *unit;
1621 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1622 goto skip_fsfstatus;
1624 switch (header->fsf_status) {
1625 case FSF_PORT_HANDLE_NOT_VALID:
1626 zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
1627 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1629 case FSF_ACCESS_DENIED:
1630 zfcp_fsf_access_denied_port(req, port);
1632 case FSF_PORT_BOXED:
1633 zfcp_erp_port_boxed(port, 50, req);
1634 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1635 ZFCP_STATUS_FSFREQ_RETRY;
1636 /* can't use generic zfcp_erp_modify_port_status because
1637 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1638 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1639 list_for_each_entry(unit, &port->unit_list_head, list)
1640 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1643 case FSF_ADAPTER_STATUS_AVAILABLE:
1644 switch (header->fsf_status_qual.word[0]) {
1645 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1647 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1648 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1653 /* can't use generic zfcp_erp_modify_port_status because
1654 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1656 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1657 list_for_each_entry(unit, &port->unit_list_head, list)
1658 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1663 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
1667 * zfcp_fsf_close_physical_port - close physical port
1668 * @erp_action: pointer to struct zfcp_erp_action
1669 * Returns: 0 on success
1671 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1673 volatile struct qdio_buffer_element *sbale;
1674 struct zfcp_adapter *adapter = erp_action->adapter;
1675 struct zfcp_fsf_req *req;
1678 spin_lock(&adapter->req_q.lock);
1679 if (zfcp_fsf_req_sbal_get(adapter))
1682 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_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->data = erp_action->port;
1695 req->qtcb->header.port_handle = erp_action->port->handle;
1696 req->erp_action = erp_action;
1697 req->handler = zfcp_fsf_close_physical_port_handler;
1698 erp_action->fsf_req = req;
1699 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
1700 &erp_action->port->status);
1702 zfcp_erp_start_timer(req);
1703 retval = zfcp_fsf_req_send(req);
1705 zfcp_fsf_req_free(req);
1706 erp_action->fsf_req = NULL;
1709 spin_unlock(&adapter->req_q.lock);
1713 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1715 struct zfcp_adapter *adapter = req->adapter;
1716 struct zfcp_unit *unit = req->data;
1717 struct fsf_qtcb_header *header = &req->qtcb->header;
1718 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1719 struct fsf_queue_designator *queue_designator =
1720 &header->fsf_status_qual.fsf_queue_designator;
1721 int exclusive, readwrite;
1723 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1724 goto skip_fsfstatus;
1726 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1727 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1728 ZFCP_STATUS_UNIT_SHARED |
1729 ZFCP_STATUS_UNIT_READONLY,
1732 switch (header->fsf_status) {
1734 case FSF_PORT_HANDLE_NOT_VALID:
1735 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
1737 case FSF_LUN_ALREADY_OPEN:
1739 case FSF_ACCESS_DENIED:
1740 zfcp_fsf_access_denied_unit(req, unit);
1741 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1742 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1744 case FSF_PORT_BOXED:
1745 zfcp_erp_port_boxed(unit->port, 51, req);
1746 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1747 ZFCP_STATUS_FSFREQ_RETRY;
1749 case FSF_LUN_SHARING_VIOLATION:
1750 if (header->fsf_status_qual.word[0])
1751 dev_warn(&adapter->ccw_device->dev,
1752 "FCP-LUN 0x%Lx at the remote port "
1754 "connected to the adapter "
1755 "is already in use in LPAR%d, CSS%d.\n",
1758 queue_designator->hla,
1759 queue_designator->cssid);
1761 zfcp_act_eval_err(adapter,
1762 header->fsf_status_qual.word[2]);
1763 zfcp_erp_unit_access_denied(unit, 60, req);
1764 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1765 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1766 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1768 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1769 dev_warn(&adapter->ccw_device->dev,
1770 "The adapter ran out of resources. There is no "
1771 "handle available for unit 0x%016Lx on port 0x%016Lx.",
1772 unit->fcp_lun, unit->port->wwpn);
1773 zfcp_erp_unit_failed(unit, 34, req);
1775 case FSF_INVALID_COMMAND_OPTION:
1776 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1778 case FSF_ADAPTER_STATUS_AVAILABLE:
1779 switch (header->fsf_status_qual.word[0]) {
1780 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1781 zfcp_test_link(unit->port);
1783 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1784 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1790 unit->handle = header->lun_handle;
1791 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1793 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1794 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1795 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
1796 exclusive = (bottom->lun_access_info &
1797 FSF_UNIT_ACCESS_EXCLUSIVE);
1798 readwrite = (bottom->lun_access_info &
1799 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1802 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1806 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1808 dev_info(&adapter->ccw_device->dev,
1809 "Read-only access for unit 0x%016Lx "
1810 "on port 0x%016Lx.\n",
1811 unit->fcp_lun, unit->port->wwpn);
1814 if (exclusive && !readwrite) {
1815 dev_err(&adapter->ccw_device->dev,
1816 "Exclusive access of read-only unit "
1817 "0x%016Lx on port 0x%016Lx not "
1818 "supported, disabling unit.\n",
1819 unit->fcp_lun, unit->port->wwpn);
1820 zfcp_erp_unit_failed(unit, 35, req);
1821 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1822 zfcp_erp_unit_shutdown(unit, 0, 80, req);
1823 } else if (!exclusive && readwrite) {
1824 dev_err(&adapter->ccw_device->dev,
1825 "Shared access of read-write unit "
1826 "0x%016Lx on port 0x%016Lx not "
1827 "supported, disabling unit.\n",
1828 unit->fcp_lun, unit->port->wwpn);
1829 zfcp_erp_unit_failed(unit, 36, req);
1830 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1831 zfcp_erp_unit_shutdown(unit, 0, 81, req);
1838 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
1842 * zfcp_fsf_open_unit - open unit
1843 * @erp_action: pointer to struct zfcp_erp_action
1844 * Returns: 0 on success, error otherwise
1846 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1848 volatile struct qdio_buffer_element *sbale;
1849 struct zfcp_adapter *adapter = erp_action->adapter;
1850 struct zfcp_fsf_req *req;
1853 spin_lock(&adapter->req_q.lock);
1854 if (zfcp_fsf_req_sbal_get(adapter))
1857 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1858 ZFCP_REQ_AUTO_CLEANUP,
1859 adapter->pool.fsf_req_erp);
1860 if (unlikely(IS_ERR(req))) {
1861 retval = PTR_ERR(req);
1865 sbale = zfcp_qdio_sbale_req(req);
1866 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1867 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1869 req->qtcb->header.port_handle = erp_action->port->handle;
1870 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1871 req->handler = zfcp_fsf_open_unit_handler;
1872 req->data = erp_action->unit;
1873 req->erp_action = erp_action;
1874 erp_action->fsf_req = req;
1876 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1877 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1879 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
1881 zfcp_erp_start_timer(req);
1882 retval = zfcp_fsf_req_send(req);
1884 zfcp_fsf_req_free(req);
1885 erp_action->fsf_req = NULL;
1888 spin_unlock(&adapter->req_q.lock);
1892 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
1894 struct zfcp_unit *unit = req->data;
1896 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1897 goto skip_fsfstatus;
1899 switch (req->qtcb->header.fsf_status) {
1900 case FSF_PORT_HANDLE_NOT_VALID:
1901 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
1902 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1904 case FSF_LUN_HANDLE_NOT_VALID:
1905 zfcp_erp_port_reopen(unit->port, 0, 111, req);
1906 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1908 case FSF_PORT_BOXED:
1909 zfcp_erp_port_boxed(unit->port, 52, req);
1910 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1911 ZFCP_STATUS_FSFREQ_RETRY;
1913 case FSF_ADAPTER_STATUS_AVAILABLE:
1914 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1915 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1916 zfcp_test_link(unit->port);
1918 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1919 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1924 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1928 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
1932 * zfcp_fsf_close_unit - close zfcp unit
1933 * @erp_action: pointer to struct zfcp_unit
1934 * Returns: 0 on success, error otherwise
1936 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1938 volatile struct qdio_buffer_element *sbale;
1939 struct zfcp_adapter *adapter = erp_action->adapter;
1940 struct zfcp_fsf_req *req;
1943 spin_lock(&adapter->req_q.lock);
1944 if (zfcp_fsf_req_sbal_get(adapter))
1946 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
1947 ZFCP_REQ_AUTO_CLEANUP,
1948 adapter->pool.fsf_req_erp);
1949 if (unlikely(IS_ERR(req))) {
1950 retval = PTR_ERR(req);
1954 sbale = zfcp_qdio_sbale_req(req);
1955 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1956 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1958 req->qtcb->header.port_handle = erp_action->port->handle;
1959 req->qtcb->header.lun_handle = erp_action->unit->handle;
1960 req->handler = zfcp_fsf_close_unit_handler;
1961 req->data = erp_action->unit;
1962 req->erp_action = erp_action;
1963 erp_action->fsf_req = req;
1964 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
1966 zfcp_erp_start_timer(req);
1967 retval = zfcp_fsf_req_send(req);
1969 zfcp_fsf_req_free(req);
1970 erp_action->fsf_req = NULL;
1973 spin_unlock(&adapter->req_q.lock);
1977 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1979 lat_rec->sum += lat;
1980 lat_rec->min = min(lat_rec->min, lat);
1981 lat_rec->max = max(lat_rec->max, lat);
1984 static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
1986 struct fsf_qual_latency_info *lat_inf;
1987 struct latency_cont *lat;
1988 struct zfcp_unit *unit = req->unit;
1989 unsigned long flags;
1991 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
1993 switch (req->qtcb->bottom.io.data_direction) {
1994 case FSF_DATADIR_READ:
1995 lat = &unit->latencies.read;
1997 case FSF_DATADIR_WRITE:
1998 lat = &unit->latencies.write;
2000 case FSF_DATADIR_CMND:
2001 lat = &unit->latencies.cmd;
2007 spin_lock_irqsave(&unit->latencies.lock, flags);
2008 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2009 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2011 spin_unlock_irqrestore(&unit->latencies.lock, flags);
2014 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2016 struct scsi_cmnd *scpnt = req->data;
2017 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2018 &(req->qtcb->bottom.io.fcp_rsp);
2020 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2021 unsigned long flags;
2023 if (unlikely(!scpnt))
2026 read_lock_irqsave(&req->adapter->abort_lock, flags);
2028 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
2029 set_host_byte(scpnt, DID_SOFT_ERROR);
2030 set_driver_byte(scpnt, SUGGEST_RETRY);
2031 goto skip_fsfstatus;
2034 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2035 set_host_byte(scpnt, DID_ERROR);
2036 goto skip_fsfstatus;
2039 set_msg_byte(scpnt, COMMAND_COMPLETE);
2041 scpnt->result |= fcp_rsp_iu->scsi_status;
2043 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2044 zfcp_fsf_req_latency(req);
2046 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
2047 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
2048 set_host_byte(scpnt, DID_OK);
2050 set_host_byte(scpnt, DID_ERROR);
2051 goto skip_fsfstatus;
2055 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
2056 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2057 fcp_rsp_iu->fcp_rsp_len;
2058 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
2059 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
2061 memcpy(scpnt->sense_buffer,
2062 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
2065 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
2066 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2067 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2069 set_host_byte(scpnt, DID_ERROR);
2072 if (scpnt->result != 0)
2073 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
2074 else if (scpnt->retries > 0)
2075 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
2077 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
2079 scpnt->host_scribble = NULL;
2080 (scpnt->scsi_done) (scpnt);
2082 * We must hold this lock until scsi_done has been called.
2083 * Otherwise we may call scsi_done after abort regarding this
2084 * command has completed.
2085 * Note: scsi_done must not block!
2087 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2090 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2092 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2093 &(req->qtcb->bottom.io.fcp_rsp);
2094 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2096 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2097 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2098 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2102 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2104 struct zfcp_unit *unit;
2105 struct fsf_qtcb_header *header = &req->qtcb->header;
2107 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2112 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2113 goto skip_fsfstatus;
2115 switch (header->fsf_status) {
2116 case FSF_HANDLE_MISMATCH:
2117 case FSF_PORT_HANDLE_NOT_VALID:
2118 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
2119 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2121 case FSF_FCPLUN_NOT_VALID:
2122 case FSF_LUN_HANDLE_NOT_VALID:
2123 zfcp_erp_port_reopen(unit->port, 0, 113, req);
2124 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2126 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2127 zfcp_fsf_class_not_supp(req);
2129 case FSF_ACCESS_DENIED:
2130 zfcp_fsf_access_denied_unit(req, unit);
2132 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2133 dev_err(&req->adapter->ccw_device->dev,
2134 "Invalid data direction (%d) given for unit "
2135 "0x%016Lx on port 0x%016Lx, shutting down "
2137 req->qtcb->bottom.io.data_direction,
2138 unit->fcp_lun, unit->port->wwpn);
2139 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
2140 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2142 case FSF_CMND_LENGTH_NOT_VALID:
2143 dev_err(&req->adapter->ccw_device->dev,
2144 "An invalid control-data-block length field (%d) "
2145 "was found in a command for unit 0x%016Lx on port "
2146 "0x%016Lx. Shutting down adapter.\n",
2147 req->qtcb->bottom.io.fcp_cmnd_length,
2148 unit->fcp_lun, unit->port->wwpn);
2149 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
2150 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2152 case FSF_PORT_BOXED:
2153 zfcp_erp_port_boxed(unit->port, 53, req);
2154 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2155 ZFCP_STATUS_FSFREQ_RETRY;
2158 zfcp_erp_unit_boxed(unit, 54, req);
2159 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2160 ZFCP_STATUS_FSFREQ_RETRY;
2162 case FSF_ADAPTER_STATUS_AVAILABLE:
2163 if (header->fsf_status_qual.word[0] ==
2164 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2165 zfcp_test_link(unit->port);
2166 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2170 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2171 zfcp_fsf_send_fcp_ctm_handler(req);
2173 zfcp_fsf_send_fcp_command_task_handler(req);
2175 zfcp_unit_put(unit);
2180 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2181 * @adapter: adapter where scsi command is issued
2182 * @unit: unit where command is sent to
2183 * @scsi_cmnd: scsi command to be sent
2184 * @timer: timer to be started when request is initiated
2185 * @req_flags: flags for fsf_request
2187 int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
2188 struct zfcp_unit *unit,
2189 struct scsi_cmnd *scsi_cmnd,
2190 int use_timer, int req_flags)
2192 struct zfcp_fsf_req *req;
2193 struct fcp_cmnd_iu *fcp_cmnd_iu;
2194 unsigned int sbtype;
2195 int real_bytes, retval = -EIO;
2197 if (unlikely(!(atomic_read(&unit->status) &
2198 ZFCP_STATUS_COMMON_UNBLOCKED)))
2201 spin_lock(&adapter->req_q.lock);
2202 if (!atomic_read(&adapter->req_q.count))
2204 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2205 adapter->pool.fsf_req_scsi);
2206 if (unlikely(IS_ERR(req))) {
2207 retval = PTR_ERR(req);
2211 zfcp_unit_get(unit);
2213 req->data = scsi_cmnd;
2214 req->handler = zfcp_fsf_send_fcp_command_handler;
2215 req->qtcb->header.lun_handle = unit->handle;
2216 req->qtcb->header.port_handle = unit->port->handle;
2217 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2219 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2221 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2222 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2224 * set depending on data direction:
2225 * data direction bits in SBALE (SB Type)
2226 * data direction bits in QTCB
2227 * data direction bits in FCP_CMND IU
2229 switch (scsi_cmnd->sc_data_direction) {
2231 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2232 sbtype = SBAL_FLAGS0_TYPE_READ;
2234 case DMA_FROM_DEVICE:
2235 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2236 sbtype = SBAL_FLAGS0_TYPE_READ;
2237 fcp_cmnd_iu->rddata = 1;
2240 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2241 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2242 fcp_cmnd_iu->wddata = 1;
2244 case DMA_BIDIRECTIONAL:
2247 goto failed_scsi_cmnd;
2250 if (likely((scsi_cmnd->device->simple_tags) ||
2251 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2252 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2253 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2255 fcp_cmnd_iu->task_attribute = UNTAGGED;
2257 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2258 fcp_cmnd_iu->add_fcp_cdb_length =
2259 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2261 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2263 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2264 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
2266 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2267 scsi_sglist(scsi_cmnd),
2268 FSF_MAX_SBALS_PER_REQ);
2269 if (unlikely(real_bytes < 0)) {
2270 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2273 dev_err(&adapter->ccw_device->dev,
2274 "SCSI request too large. "
2275 "Shutting down unit 0x%016Lx on port "
2276 "0x%016Lx.\n", unit->fcp_lun,
2278 zfcp_erp_unit_shutdown(unit, 0, 131, req);
2281 goto failed_scsi_cmnd;
2284 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2287 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2289 retval = zfcp_fsf_req_send(req);
2290 if (unlikely(retval))
2291 goto failed_scsi_cmnd;
2296 zfcp_unit_put(unit);
2297 zfcp_fsf_req_free(req);
2298 scsi_cmnd->host_scribble = NULL;
2300 spin_unlock(&adapter->req_q.lock);
2305 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2306 * @adapter: pointer to struct zfcp-adapter
2307 * @unit: pointer to struct zfcp_unit
2308 * @tm_flags: unsigned byte for task management flags
2309 * @req_flags: int request flags
2310 * Returns: on success pointer to struct fsf_req, NULL otherwise
2312 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
2313 struct zfcp_unit *unit,
2314 u8 tm_flags, int req_flags)
2316 volatile struct qdio_buffer_element *sbale;
2317 struct zfcp_fsf_req *req = NULL;
2318 struct fcp_cmnd_iu *fcp_cmnd_iu;
2320 if (unlikely(!(atomic_read(&unit->status) &
2321 ZFCP_STATUS_COMMON_UNBLOCKED)))
2324 spin_lock(&adapter->req_q.lock);
2325 if (!atomic_read(&adapter->req_q.count))
2327 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2328 adapter->pool.fsf_req_scsi);
2329 if (unlikely(IS_ERR(req)))
2332 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2334 req->handler = zfcp_fsf_send_fcp_command_handler;
2335 req->qtcb->header.lun_handle = unit->handle;
2336 req->qtcb->header.port_handle = unit->port->handle;
2337 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2338 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2339 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2342 sbale = zfcp_qdio_sbale_req(req);
2343 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2344 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2346 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2347 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2348 fcp_cmnd_iu->task_management_flags = tm_flags;
2350 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2351 if (!zfcp_fsf_req_send(req))
2354 zfcp_fsf_req_free(req);
2357 spin_unlock(&adapter->req_q.lock);
2361 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2363 if (req->qtcb->header.fsf_status != FSF_GOOD)
2364 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2368 * zfcp_fsf_control_file - control file upload/download
2369 * @adapter: pointer to struct zfcp_adapter
2370 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2371 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2373 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2374 struct zfcp_fsf_cfdc *fsf_cfdc)
2376 volatile struct qdio_buffer_element *sbale;
2377 struct zfcp_fsf_req *req = NULL;
2378 struct fsf_qtcb_bottom_support *bottom;
2379 int direction, retval = -EIO, bytes;
2381 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2382 return ERR_PTR(-EOPNOTSUPP);
2384 switch (fsf_cfdc->command) {
2385 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2386 direction = SBAL_FLAGS0_TYPE_WRITE;
2388 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2389 direction = SBAL_FLAGS0_TYPE_READ;
2392 return ERR_PTR(-EINVAL);
2395 spin_lock(&adapter->req_q.lock);
2396 if (zfcp_fsf_req_sbal_get(adapter))
2399 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
2400 if (unlikely(IS_ERR(req))) {
2405 req->handler = zfcp_fsf_control_file_handler;
2407 sbale = zfcp_qdio_sbale_req(req);
2408 sbale[0].flags |= direction;
2410 bottom = &req->qtcb->bottom.support;
2411 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2412 bottom->option = fsf_cfdc->option;
2414 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2415 FSF_MAX_SBALS_PER_REQ);
2416 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2418 zfcp_fsf_req_free(req);
2422 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2423 retval = zfcp_fsf_req_send(req);
2425 spin_unlock(&adapter->req_q.lock);
2428 wait_event(req->completion_wq,
2429 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2432 return ERR_PTR(retval);