4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2010
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <linux/slab.h>
14 #include <scsi/fc/fc_els.h>
18 #include "zfcp_qdio.h"
19 #include "zfcp_reqlist.h"
21 static void zfcp_fsf_request_timeout_handler(unsigned long data)
23 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
24 zfcp_qdio_siosl(adapter);
25 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
29 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
30 unsigned long timeout)
32 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
33 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
34 fsf_req->timer.expires = jiffies + timeout;
35 add_timer(&fsf_req->timer);
38 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
40 BUG_ON(!fsf_req->erp_action);
41 fsf_req->timer.function = zfcp_erp_timeout_handler;
42 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
43 fsf_req->timer.expires = jiffies + 30 * HZ;
44 add_timer(&fsf_req->timer);
47 /* association between FSF command and FSF QTCB type */
48 static u32 fsf_qtcb_type[] = {
49 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
50 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
59 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
60 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
64 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
66 u16 subtable = table >> 16;
67 u16 rule = table & 0xffff;
68 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
70 if (subtable && subtable < ARRAY_SIZE(act_type))
71 dev_warn(&adapter->ccw_device->dev,
72 "Access denied according to ACT rule type %s, "
73 "rule %d\n", act_type[subtable], rule);
76 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
77 struct zfcp_port *port)
79 struct fsf_qtcb_header *header = &req->qtcb->header;
80 dev_warn(&req->adapter->ccw_device->dev,
81 "Access denied to port 0x%016Lx\n",
82 (unsigned long long)port->wwpn);
83 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
84 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
85 zfcp_erp_port_access_denied(port, "fspad_1", req);
86 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
89 static void zfcp_fsf_access_denied_lun(struct zfcp_fsf_req *req,
90 struct scsi_device *sdev)
92 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
94 struct fsf_qtcb_header *header = &req->qtcb->header;
95 dev_warn(&req->adapter->ccw_device->dev,
96 "Access denied to LUN 0x%016Lx on port 0x%016Lx\n",
97 (unsigned long long)zfcp_scsi_dev_lun(sdev),
98 (unsigned long long)zfcp_sdev->port->wwpn);
99 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
100 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
101 zfcp_erp_lun_access_denied(sdev, "fsadl_1", req);
102 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
105 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
107 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
108 "operational because of an unsupported FC class\n");
109 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
110 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
114 * zfcp_fsf_req_free - free memory used by fsf request
115 * @fsf_req: pointer to struct zfcp_fsf_req
117 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
119 if (likely(req->pool)) {
120 if (likely(req->qtcb))
121 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
122 mempool_free(req, req->pool);
126 if (likely(req->qtcb))
127 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
131 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
134 struct fsf_status_read_buffer *sr_buf = req->data;
135 struct zfcp_adapter *adapter = req->adapter;
136 struct zfcp_port *port;
137 int d_id = ntoh24(sr_buf->d_id);
139 read_lock_irqsave(&adapter->port_list_lock, flags);
140 list_for_each_entry(port, &adapter->port_list, list)
141 if (port->d_id == d_id) {
142 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
145 read_unlock_irqrestore(&adapter->port_list_lock, flags);
148 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
149 struct fsf_link_down_info *link_down)
151 struct zfcp_adapter *adapter = req->adapter;
153 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
156 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
158 zfcp_scsi_schedule_rports_block(adapter);
163 switch (link_down->error_code) {
164 case FSF_PSQ_LINK_NO_LIGHT:
165 dev_warn(&req->adapter->ccw_device->dev,
166 "There is no light signal from the local "
167 "fibre channel cable\n");
169 case FSF_PSQ_LINK_WRAP_PLUG:
170 dev_warn(&req->adapter->ccw_device->dev,
171 "There is a wrap plug instead of a fibre "
174 case FSF_PSQ_LINK_NO_FCP:
175 dev_warn(&req->adapter->ccw_device->dev,
176 "The adjacent fibre channel node does not "
179 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
180 dev_warn(&req->adapter->ccw_device->dev,
181 "The FCP device is suspended because of a "
182 "firmware update\n");
184 case FSF_PSQ_LINK_INVALID_WWPN:
185 dev_warn(&req->adapter->ccw_device->dev,
186 "The FCP device detected a WWPN that is "
187 "duplicate or not valid\n");
189 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
190 dev_warn(&req->adapter->ccw_device->dev,
191 "The fibre channel fabric does not support NPIV\n");
193 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
194 dev_warn(&req->adapter->ccw_device->dev,
195 "The FCP adapter cannot support more NPIV ports\n");
197 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
198 dev_warn(&req->adapter->ccw_device->dev,
199 "The adjacent switch cannot support "
200 "more NPIV ports\n");
202 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
203 dev_warn(&req->adapter->ccw_device->dev,
204 "The FCP adapter could not log in to the "
205 "fibre channel fabric\n");
207 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
208 dev_warn(&req->adapter->ccw_device->dev,
209 "The WWPN assignment file on the FCP adapter "
210 "has been damaged\n");
212 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
213 dev_warn(&req->adapter->ccw_device->dev,
214 "The mode table on the FCP adapter "
215 "has been damaged\n");
217 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
218 dev_warn(&req->adapter->ccw_device->dev,
219 "All NPIV ports on the FCP adapter have "
223 dev_warn(&req->adapter->ccw_device->dev,
224 "The link between the FCP adapter and "
225 "the FC fabric is down\n");
228 zfcp_erp_adapter_failed(adapter, id, req);
231 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
233 struct fsf_status_read_buffer *sr_buf = req->data;
234 struct fsf_link_down_info *ldi =
235 (struct fsf_link_down_info *) &sr_buf->payload;
237 switch (sr_buf->status_subtype) {
238 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
239 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
241 case FSF_STATUS_READ_SUB_FDISC_FAILED:
242 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
244 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
245 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
249 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
251 struct zfcp_adapter *adapter = req->adapter;
252 struct fsf_status_read_buffer *sr_buf = req->data;
254 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
255 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
256 mempool_free(sr_buf, adapter->pool.status_read_data);
257 zfcp_fsf_req_free(req);
261 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
263 switch (sr_buf->status_type) {
264 case FSF_STATUS_READ_PORT_CLOSED:
265 zfcp_fsf_status_read_port_closed(req);
267 case FSF_STATUS_READ_INCOMING_ELS:
268 zfcp_fc_incoming_els(req);
270 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
272 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
273 dev_warn(&adapter->ccw_device->dev,
274 "The error threshold for checksum statistics "
275 "has been exceeded\n");
276 zfcp_dbf_hba_berr(adapter->dbf, req);
278 case FSF_STATUS_READ_LINK_DOWN:
279 zfcp_fsf_status_read_link_down(req);
280 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
282 case FSF_STATUS_READ_LINK_UP:
283 dev_info(&adapter->ccw_device->dev,
284 "The local link has been restored\n");
285 /* All ports should be marked as ready to run again */
286 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
287 ZFCP_STATUS_COMMON_RUNNING,
289 zfcp_erp_adapter_reopen(adapter,
290 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
291 ZFCP_STATUS_COMMON_ERP_FAILED,
293 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
296 case FSF_STATUS_READ_NOTIFICATION_LOST:
297 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
298 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
300 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
301 queue_work(adapter->work_queue, &adapter->scan_work);
303 case FSF_STATUS_READ_CFDC_UPDATED:
304 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
306 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
307 adapter->adapter_features = sr_buf->payload.word[0];
311 mempool_free(sr_buf, adapter->pool.status_read_data);
312 zfcp_fsf_req_free(req);
314 atomic_inc(&adapter->stat_miss);
315 queue_work(adapter->work_queue, &adapter->stat_work);
318 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
320 switch (req->qtcb->header.fsf_status_qual.word[0]) {
321 case FSF_SQ_FCP_RSP_AVAILABLE:
322 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
323 case FSF_SQ_NO_RETRY_POSSIBLE:
324 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
326 case FSF_SQ_COMMAND_ABORTED:
328 case FSF_SQ_NO_RECOM:
329 dev_err(&req->adapter->ccw_device->dev,
330 "The FCP adapter reported a problem "
331 "that cannot be recovered\n");
332 zfcp_qdio_siosl(req->adapter);
333 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
336 /* all non-return stats set FSFREQ_ERROR*/
337 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
340 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
342 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
345 switch (req->qtcb->header.fsf_status) {
346 case FSF_UNKNOWN_COMMAND:
347 dev_err(&req->adapter->ccw_device->dev,
348 "The FCP adapter does not recognize the command 0x%x\n",
349 req->qtcb->header.fsf_command);
350 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
351 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
353 case FSF_ADAPTER_STATUS_AVAILABLE:
354 zfcp_fsf_fsfstatus_qual_eval(req);
359 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
361 struct zfcp_adapter *adapter = req->adapter;
362 struct fsf_qtcb *qtcb = req->qtcb;
363 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
365 zfcp_dbf_hba_fsf_response(req);
367 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
368 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
372 switch (qtcb->prefix.prot_status) {
374 case FSF_PROT_FSF_STATUS_PRESENTED:
376 case FSF_PROT_QTCB_VERSION_ERROR:
377 dev_err(&adapter->ccw_device->dev,
378 "QTCB version 0x%x not supported by FCP adapter "
379 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
380 psq->word[0], psq->word[1]);
381 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
383 case FSF_PROT_ERROR_STATE:
384 case FSF_PROT_SEQ_NUMB_ERROR:
385 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
386 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
388 case FSF_PROT_UNSUPP_QTCB_TYPE:
389 dev_err(&adapter->ccw_device->dev,
390 "The QTCB type is not supported by the FCP adapter\n");
391 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
393 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
394 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
397 case FSF_PROT_DUPLICATE_REQUEST_ID:
398 dev_err(&adapter->ccw_device->dev,
399 "0x%Lx is an ambiguous request identifier\n",
400 (unsigned long long)qtcb->bottom.support.req_handle);
401 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
403 case FSF_PROT_LINK_DOWN:
404 zfcp_fsf_link_down_info_eval(req, "fspse_5",
405 &psq->link_down_info);
406 /* go through reopen to flush pending requests */
407 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
409 case FSF_PROT_REEST_QUEUE:
410 /* All ports should be marked as ready to run again */
411 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
412 ZFCP_STATUS_COMMON_RUNNING,
414 zfcp_erp_adapter_reopen(adapter,
415 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
416 ZFCP_STATUS_COMMON_ERP_FAILED,
420 dev_err(&adapter->ccw_device->dev,
421 "0x%x is not a valid transfer protocol status\n",
422 qtcb->prefix.prot_status);
423 zfcp_qdio_siosl(adapter);
424 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
426 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
430 * zfcp_fsf_req_complete - process completion of a FSF request
431 * @fsf_req: The FSF request that has been completed.
433 * When a request has been completed either from the FCP adapter,
434 * or it has been dismissed due to a queue shutdown, this function
435 * is called to process the completion status and trigger further
436 * events related to the FSF request.
438 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
440 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
441 zfcp_fsf_status_read_handler(req);
445 del_timer(&req->timer);
446 zfcp_fsf_protstatus_eval(req);
447 zfcp_fsf_fsfstatus_eval(req);
451 zfcp_erp_notify(req->erp_action, 0);
453 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
454 zfcp_fsf_req_free(req);
456 complete(&req->completion);
460 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
461 * @adapter: pointer to struct zfcp_adapter
463 * Never ever call this without shutting down the adapter first.
464 * Otherwise the adapter would continue using and corrupting s390 storage.
465 * Included BUG_ON() call to ensure this is done.
466 * ERP is supposed to be the only user of this function.
468 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
470 struct zfcp_fsf_req *req, *tmp;
471 LIST_HEAD(remove_queue);
473 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
474 zfcp_reqlist_move(adapter->req_list, &remove_queue);
476 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
477 list_del(&req->list);
478 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
479 zfcp_fsf_req_complete(req);
483 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
485 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
486 struct zfcp_adapter *adapter = req->adapter;
487 struct Scsi_Host *shost = adapter->scsi_host;
488 struct fc_els_flogi *nsp, *plogi;
490 /* adjust pointers for missing command code */
491 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
493 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
497 memcpy(req->data, bottom, sizeof(*bottom));
499 fc_host_port_name(shost) = nsp->fl_wwpn;
500 fc_host_node_name(shost) = nsp->fl_wwnn;
501 fc_host_port_id(shost) = ntoh24(bottom->s_id);
502 fc_host_speed(shost) = bottom->fc_link_speed;
503 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
505 adapter->hydra_version = bottom->adapter_type;
506 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
507 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
508 (u16)FSF_STATUS_READS_RECOM);
510 if (fc_host_permanent_port_name(shost) == -1)
511 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
513 switch (bottom->fc_topology) {
515 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
516 adapter->peer_wwpn = plogi->fl_wwpn;
517 adapter->peer_wwnn = plogi->fl_wwnn;
518 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
520 case FSF_TOPO_FABRIC:
521 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
524 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
527 dev_err(&adapter->ccw_device->dev,
528 "Unknown or unsupported arbitrated loop "
529 "fibre channel topology detected\n");
530 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
534 zfcp_scsi_set_prot(adapter);
539 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
541 struct zfcp_adapter *adapter = req->adapter;
542 struct fsf_qtcb *qtcb = req->qtcb;
543 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
544 struct Scsi_Host *shost = adapter->scsi_host;
546 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
549 adapter->fsf_lic_version = bottom->lic_version;
550 adapter->adapter_features = bottom->adapter_features;
551 adapter->connection_features = bottom->connection_features;
552 adapter->peer_wwpn = 0;
553 adapter->peer_wwnn = 0;
554 adapter->peer_d_id = 0;
556 switch (qtcb->header.fsf_status) {
558 if (zfcp_fsf_exchange_config_evaluate(req))
561 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
562 dev_err(&adapter->ccw_device->dev,
563 "FCP adapter maximum QTCB size (%d bytes) "
565 bottom->max_qtcb_size);
566 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
569 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
572 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
573 fc_host_node_name(shost) = 0;
574 fc_host_port_name(shost) = 0;
575 fc_host_port_id(shost) = 0;
576 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
577 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
578 adapter->hydra_version = 0;
580 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
583 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
584 &qtcb->header.fsf_status_qual.link_down_info);
587 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
591 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
592 adapter->hardware_version = bottom->hardware_version;
593 memcpy(fc_host_serial_number(shost), bottom->serial_number,
594 min(FC_SERIAL_NUMBER_SIZE, 17));
595 EBCASC(fc_host_serial_number(shost),
596 min(FC_SERIAL_NUMBER_SIZE, 17));
599 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
600 dev_err(&adapter->ccw_device->dev,
601 "The FCP adapter only supports newer "
602 "control block versions\n");
603 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
606 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
607 dev_err(&adapter->ccw_device->dev,
608 "The FCP adapter only supports older "
609 "control block versions\n");
610 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
614 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
616 struct zfcp_adapter *adapter = req->adapter;
617 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
618 struct Scsi_Host *shost = adapter->scsi_host;
621 memcpy(req->data, bottom, sizeof(*bottom));
623 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
624 fc_host_permanent_port_name(shost) = bottom->wwpn;
625 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
627 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
628 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
629 fc_host_supported_speeds(shost) = bottom->supported_speed;
630 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
632 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
636 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
638 struct fsf_qtcb *qtcb = req->qtcb;
640 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
643 switch (qtcb->header.fsf_status) {
645 zfcp_fsf_exchange_port_evaluate(req);
647 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
648 zfcp_fsf_exchange_port_evaluate(req);
649 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
650 &qtcb->header.fsf_status_qual.link_down_info);
655 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
657 struct zfcp_fsf_req *req;
660 req = mempool_alloc(pool, GFP_ATOMIC);
662 req = kmalloc(sizeof(*req), GFP_ATOMIC);
667 memset(req, 0, sizeof(*req));
672 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
674 struct fsf_qtcb *qtcb;
677 qtcb = mempool_alloc(pool, GFP_ATOMIC);
679 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
684 memset(qtcb, 0, sizeof(*qtcb));
688 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
689 u32 fsf_cmd, u32 sbtype,
692 struct zfcp_adapter *adapter = qdio->adapter;
693 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
696 return ERR_PTR(-ENOMEM);
698 if (adapter->req_no == 0)
701 INIT_LIST_HEAD(&req->list);
702 init_timer(&req->timer);
703 init_completion(&req->completion);
705 req->adapter = adapter;
706 req->fsf_command = fsf_cmd;
707 req->req_id = adapter->req_no;
709 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
711 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
713 req->qtcb = zfcp_qtcb_alloc(NULL);
715 if (unlikely(!req->qtcb)) {
716 zfcp_fsf_req_free(req);
717 return ERR_PTR(-ENOMEM);
720 req->seq_no = adapter->fsf_req_seq_no;
721 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
722 req->qtcb->prefix.req_id = req->req_id;
723 req->qtcb->prefix.ulp_info = 26;
724 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
725 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
726 req->qtcb->header.req_handle = req->req_id;
727 req->qtcb->header.fsf_command = req->fsf_command;
730 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
731 req->qtcb, sizeof(struct fsf_qtcb));
736 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
738 struct zfcp_adapter *adapter = req->adapter;
739 struct zfcp_qdio *qdio = adapter->qdio;
740 int with_qtcb = (req->qtcb != NULL);
741 int req_id = req->req_id;
743 zfcp_reqlist_add(adapter->req_list, req);
745 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
746 req->issued = get_clock();
747 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
748 del_timer(&req->timer);
749 /* lookup request again, list might have changed */
750 zfcp_reqlist_find_rm(adapter->req_list, req_id);
751 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
755 /* Don't increase for unsolicited status */
757 adapter->fsf_req_seq_no++;
764 * zfcp_fsf_status_read - send status read request
765 * @adapter: pointer to struct zfcp_adapter
766 * @req_flags: request flags
767 * Returns: 0 on success, ERROR otherwise
769 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
771 struct zfcp_adapter *adapter = qdio->adapter;
772 struct zfcp_fsf_req *req;
773 struct fsf_status_read_buffer *sr_buf;
776 spin_lock_irq(&qdio->req_q_lock);
777 if (zfcp_qdio_sbal_get(qdio))
780 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
781 adapter->pool.status_read_req);
783 retval = PTR_ERR(req);
787 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
792 memset(sr_buf, 0, sizeof(*sr_buf));
795 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
796 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
798 retval = zfcp_fsf_req_send(req);
800 goto failed_req_send;
805 mempool_free(sr_buf, adapter->pool.status_read_data);
807 zfcp_fsf_req_free(req);
808 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
810 spin_unlock_irq(&qdio->req_q_lock);
814 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
816 struct scsi_device *sdev = req->data;
817 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
818 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
820 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
823 switch (req->qtcb->header.fsf_status) {
824 case FSF_PORT_HANDLE_NOT_VALID:
825 if (fsq->word[0] == fsq->word[1]) {
826 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
828 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
831 case FSF_LUN_HANDLE_NOT_VALID:
832 if (fsq->word[0] == fsq->word[1]) {
833 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2",
835 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
838 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
839 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
842 zfcp_erp_port_boxed(zfcp_sdev->port, "fsafch3", req);
843 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
846 zfcp_erp_lun_boxed(sdev, "fsafch4", req);
847 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
849 case FSF_ADAPTER_STATUS_AVAILABLE:
850 switch (fsq->word[0]) {
851 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
852 zfcp_fc_test_link(zfcp_sdev->port);
854 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
860 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
866 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
867 * @scmnd: The SCSI command to abort
868 * Returns: pointer to struct zfcp_fsf_req
871 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
873 struct zfcp_fsf_req *req = NULL;
874 struct scsi_device *sdev = scmnd->device;
875 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
876 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
877 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
879 spin_lock_irq(&qdio->req_q_lock);
880 if (zfcp_qdio_sbal_get(qdio))
882 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
883 SBAL_FLAGS0_TYPE_READ,
884 qdio->adapter->pool.scsi_abort);
890 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
891 ZFCP_STATUS_COMMON_UNBLOCKED)))
894 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
896 req->data = zfcp_sdev;
897 req->handler = zfcp_fsf_abort_fcp_command_handler;
898 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
899 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
900 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
902 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
903 if (!zfcp_fsf_req_send(req))
907 zfcp_fsf_req_free(req);
910 spin_unlock_irq(&qdio->req_q_lock);
914 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
916 struct zfcp_adapter *adapter = req->adapter;
917 struct zfcp_fsf_ct_els *ct = req->data;
918 struct fsf_qtcb_header *header = &req->qtcb->header;
920 ct->status = -EINVAL;
922 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
925 switch (header->fsf_status) {
927 zfcp_dbf_san_ct_response(req);
930 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
931 zfcp_fsf_class_not_supp(req);
933 case FSF_ADAPTER_STATUS_AVAILABLE:
934 switch (header->fsf_status_qual.word[0]){
935 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
936 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
937 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
941 case FSF_ACCESS_DENIED:
944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
946 case FSF_PORT_HANDLE_NOT_VALID:
947 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
949 case FSF_GENERIC_COMMAND_REJECTED:
950 case FSF_PAYLOAD_SIZE_MISMATCH:
951 case FSF_REQUEST_SIZE_TOO_LARGE:
952 case FSF_RESPONSE_SIZE_TOO_LARGE:
953 case FSF_SBAL_MISMATCH:
954 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
960 ct->handler(ct->handler_data);
963 static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
964 struct zfcp_qdio_req *q_req,
965 struct scatterlist *sg_req,
966 struct scatterlist *sg_resp)
968 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
969 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
970 zfcp_qdio_set_sbale_last(qdio, q_req);
973 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
974 struct scatterlist *sg_req,
975 struct scatterlist *sg_resp)
977 struct zfcp_adapter *adapter = req->adapter;
978 u32 feat = adapter->adapter_features;
981 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
982 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
983 !zfcp_qdio_sg_one_sbale(sg_resp))
986 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
991 /* use single, unchained SBAL if it can hold the request */
992 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
993 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
998 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
1001 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
1002 req->qtcb->bottom.support.req_buf_length = bytes;
1003 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
1005 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
1007 req->qtcb->bottom.support.resp_buf_length = bytes;
1010 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
1015 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1016 struct scatterlist *sg_req,
1017 struct scatterlist *sg_resp,
1018 unsigned int timeout)
1022 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
1026 /* common settings for ct/gs and els requests */
1028 timeout = 255; /* max value accepted by hardware */
1029 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1030 req->qtcb->bottom.support.timeout = timeout;
1031 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1037 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1038 * @ct: pointer to struct zfcp_send_ct with data for request
1039 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1041 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1042 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1043 unsigned int timeout)
1045 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1046 struct zfcp_fsf_req *req;
1049 spin_lock_irq(&qdio->req_q_lock);
1050 if (zfcp_qdio_sbal_get(qdio))
1053 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1054 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
1061 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1062 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
1066 req->handler = zfcp_fsf_send_ct_handler;
1067 req->qtcb->header.port_handle = wka_port->handle;
1070 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1072 ret = zfcp_fsf_req_send(req);
1079 zfcp_fsf_req_free(req);
1081 spin_unlock_irq(&qdio->req_q_lock);
1085 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1087 struct zfcp_fsf_ct_els *send_els = req->data;
1088 struct zfcp_port *port = send_els->port;
1089 struct fsf_qtcb_header *header = &req->qtcb->header;
1091 send_els->status = -EINVAL;
1093 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1094 goto skip_fsfstatus;
1096 switch (header->fsf_status) {
1098 zfcp_dbf_san_els_response(req);
1099 send_els->status = 0;
1101 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1102 zfcp_fsf_class_not_supp(req);
1104 case FSF_ADAPTER_STATUS_AVAILABLE:
1105 switch (header->fsf_status_qual.word[0]){
1106 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1107 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1108 case FSF_SQ_RETRY_IF_POSSIBLE:
1109 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1113 case FSF_ELS_COMMAND_REJECTED:
1114 case FSF_PAYLOAD_SIZE_MISMATCH:
1115 case FSF_REQUEST_SIZE_TOO_LARGE:
1116 case FSF_RESPONSE_SIZE_TOO_LARGE:
1118 case FSF_ACCESS_DENIED:
1120 zfcp_fsf_access_denied_port(req, port);
1122 case FSF_SBAL_MISMATCH:
1123 /* should never occure, avoided in zfcp_fsf_send_els */
1126 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1130 if (send_els->handler)
1131 send_els->handler(send_els->handler_data);
1135 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1136 * @els: pointer to struct zfcp_send_els with data for the command
1138 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1139 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1141 struct zfcp_fsf_req *req;
1142 struct zfcp_qdio *qdio = adapter->qdio;
1145 spin_lock_irq(&qdio->req_q_lock);
1146 if (zfcp_qdio_sbal_get(qdio))
1149 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1150 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
1157 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1159 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1161 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
1166 hton24(req->qtcb->bottom.support.d_id, d_id);
1167 req->handler = zfcp_fsf_send_els_handler;
1170 zfcp_dbf_san_els_request(req);
1172 ret = zfcp_fsf_req_send(req);
1179 zfcp_fsf_req_free(req);
1181 spin_unlock_irq(&qdio->req_q_lock);
1185 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1187 struct zfcp_fsf_req *req;
1188 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1191 spin_lock_irq(&qdio->req_q_lock);
1192 if (zfcp_qdio_sbal_get(qdio))
1195 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1196 SBAL_FLAGS0_TYPE_READ,
1197 qdio->adapter->pool.erp_req);
1200 retval = PTR_ERR(req);
1204 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1205 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1207 req->qtcb->bottom.config.feature_selection =
1209 FSF_FEATURE_LUN_SHARING |
1210 FSF_FEATURE_NOTIFICATION_LOST |
1211 FSF_FEATURE_UPDATE_ALERT;
1212 req->erp_action = erp_action;
1213 req->handler = zfcp_fsf_exchange_config_data_handler;
1214 erp_action->fsf_req_id = req->req_id;
1216 zfcp_fsf_start_erp_timer(req);
1217 retval = zfcp_fsf_req_send(req);
1219 zfcp_fsf_req_free(req);
1220 erp_action->fsf_req_id = 0;
1223 spin_unlock_irq(&qdio->req_q_lock);
1227 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1228 struct fsf_qtcb_bottom_config *data)
1230 struct zfcp_fsf_req *req = NULL;
1233 spin_lock_irq(&qdio->req_q_lock);
1234 if (zfcp_qdio_sbal_get(qdio))
1237 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1238 SBAL_FLAGS0_TYPE_READ, NULL);
1241 retval = PTR_ERR(req);
1245 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1246 req->handler = zfcp_fsf_exchange_config_data_handler;
1248 req->qtcb->bottom.config.feature_selection =
1250 FSF_FEATURE_LUN_SHARING |
1251 FSF_FEATURE_NOTIFICATION_LOST |
1252 FSF_FEATURE_UPDATE_ALERT;
1257 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1258 retval = zfcp_fsf_req_send(req);
1259 spin_unlock_irq(&qdio->req_q_lock);
1261 wait_for_completion(&req->completion);
1263 zfcp_fsf_req_free(req);
1267 spin_unlock_irq(&qdio->req_q_lock);
1272 * zfcp_fsf_exchange_port_data - request information about local port
1273 * @erp_action: ERP action for the adapter for which port data is requested
1274 * Returns: 0 on success, error otherwise
1276 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1278 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1279 struct zfcp_fsf_req *req;
1282 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1285 spin_lock_irq(&qdio->req_q_lock);
1286 if (zfcp_qdio_sbal_get(qdio))
1289 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1290 SBAL_FLAGS0_TYPE_READ,
1291 qdio->adapter->pool.erp_req);
1294 retval = PTR_ERR(req);
1298 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1299 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1301 req->handler = zfcp_fsf_exchange_port_data_handler;
1302 req->erp_action = erp_action;
1303 erp_action->fsf_req_id = req->req_id;
1305 zfcp_fsf_start_erp_timer(req);
1306 retval = zfcp_fsf_req_send(req);
1308 zfcp_fsf_req_free(req);
1309 erp_action->fsf_req_id = 0;
1312 spin_unlock_irq(&qdio->req_q_lock);
1317 * zfcp_fsf_exchange_port_data_sync - request information about local port
1318 * @qdio: pointer to struct zfcp_qdio
1319 * @data: pointer to struct fsf_qtcb_bottom_port
1320 * Returns: 0 on success, error otherwise
1322 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1323 struct fsf_qtcb_bottom_port *data)
1325 struct zfcp_fsf_req *req = NULL;
1328 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1331 spin_lock_irq(&qdio->req_q_lock);
1332 if (zfcp_qdio_sbal_get(qdio))
1335 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1336 SBAL_FLAGS0_TYPE_READ, NULL);
1339 retval = PTR_ERR(req);
1346 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1348 req->handler = zfcp_fsf_exchange_port_data_handler;
1349 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1350 retval = zfcp_fsf_req_send(req);
1351 spin_unlock_irq(&qdio->req_q_lock);
1354 wait_for_completion(&req->completion);
1356 zfcp_fsf_req_free(req);
1361 spin_unlock_irq(&qdio->req_q_lock);
1365 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1367 struct zfcp_port *port = req->data;
1368 struct fsf_qtcb_header *header = &req->qtcb->header;
1369 struct fc_els_flogi *plogi;
1371 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1374 switch (header->fsf_status) {
1375 case FSF_PORT_ALREADY_OPEN:
1377 case FSF_ACCESS_DENIED:
1378 zfcp_fsf_access_denied_port(req, port);
1380 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1381 dev_warn(&req->adapter->ccw_device->dev,
1382 "Not enough FCP adapter resources to open "
1383 "remote port 0x%016Lx\n",
1384 (unsigned long long)port->wwpn);
1385 zfcp_erp_port_failed(port, "fsoph_1", req);
1386 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1388 case FSF_ADAPTER_STATUS_AVAILABLE:
1389 switch (header->fsf_status_qual.word[0]) {
1390 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1391 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1392 case FSF_SQ_NO_RETRY_POSSIBLE:
1393 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1398 port->handle = header->port_handle;
1399 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1400 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1401 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1402 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1404 /* check whether D_ID has changed during open */
1406 * FIXME: This check is not airtight, as the FCP channel does
1407 * not monitor closures of target port connections caused on
1408 * the remote side. Thus, they might miss out on invalidating
1409 * locally cached WWPNs (and other N_Port parameters) of gone
1410 * target ports. So, our heroic attempt to make things safe
1411 * could be undermined by 'open port' response data tagged with
1412 * obsolete WWPNs. Another reason to monitor potential
1413 * connection closures ourself at least (by interpreting
1414 * incoming ELS' and unsolicited status). It just crosses my
1415 * mind that one should be able to cross-check by means of
1416 * another GID_PN straight after a port has been opened.
1417 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1419 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1420 if (req->qtcb->bottom.support.els1_length >=
1422 zfcp_fc_plogi_evaluate(port, plogi);
1424 case FSF_UNKNOWN_OP_SUBTYPE:
1425 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1430 put_device(&port->dev);
1434 * zfcp_fsf_open_port - create and send open port request
1435 * @erp_action: pointer to struct zfcp_erp_action
1436 * Returns: 0 on success, error otherwise
1438 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1440 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1441 struct zfcp_port *port = erp_action->port;
1442 struct zfcp_fsf_req *req;
1445 spin_lock_irq(&qdio->req_q_lock);
1446 if (zfcp_qdio_sbal_get(qdio))
1449 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1450 SBAL_FLAGS0_TYPE_READ,
1451 qdio->adapter->pool.erp_req);
1454 retval = PTR_ERR(req);
1458 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1459 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1461 req->handler = zfcp_fsf_open_port_handler;
1462 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1464 req->erp_action = erp_action;
1465 erp_action->fsf_req_id = req->req_id;
1466 get_device(&port->dev);
1468 zfcp_fsf_start_erp_timer(req);
1469 retval = zfcp_fsf_req_send(req);
1471 zfcp_fsf_req_free(req);
1472 erp_action->fsf_req_id = 0;
1473 put_device(&port->dev);
1476 spin_unlock_irq(&qdio->req_q_lock);
1480 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1482 struct zfcp_port *port = req->data;
1484 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1487 switch (req->qtcb->header.fsf_status) {
1488 case FSF_PORT_HANDLE_NOT_VALID:
1489 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1490 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1492 case FSF_ADAPTER_STATUS_AVAILABLE:
1495 zfcp_erp_modify_port_status(port, "fscph_2", req,
1496 ZFCP_STATUS_COMMON_OPEN,
1503 * zfcp_fsf_close_port - create and send close port request
1504 * @erp_action: pointer to struct zfcp_erp_action
1505 * Returns: 0 on success, error otherwise
1507 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1509 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1510 struct zfcp_fsf_req *req;
1513 spin_lock_irq(&qdio->req_q_lock);
1514 if (zfcp_qdio_sbal_get(qdio))
1517 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1518 SBAL_FLAGS0_TYPE_READ,
1519 qdio->adapter->pool.erp_req);
1522 retval = PTR_ERR(req);
1526 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1527 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1529 req->handler = zfcp_fsf_close_port_handler;
1530 req->data = erp_action->port;
1531 req->erp_action = erp_action;
1532 req->qtcb->header.port_handle = erp_action->port->handle;
1533 erp_action->fsf_req_id = req->req_id;
1535 zfcp_fsf_start_erp_timer(req);
1536 retval = zfcp_fsf_req_send(req);
1538 zfcp_fsf_req_free(req);
1539 erp_action->fsf_req_id = 0;
1542 spin_unlock_irq(&qdio->req_q_lock);
1546 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1548 struct zfcp_fc_wka_port *wka_port = req->data;
1549 struct fsf_qtcb_header *header = &req->qtcb->header;
1551 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1552 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1556 switch (header->fsf_status) {
1557 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1558 dev_warn(&req->adapter->ccw_device->dev,
1559 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1561 case FSF_ADAPTER_STATUS_AVAILABLE:
1562 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1564 case FSF_ACCESS_DENIED:
1565 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1568 wka_port->handle = header->port_handle;
1570 case FSF_PORT_ALREADY_OPEN:
1571 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1574 wake_up(&wka_port->completion_wq);
1578 * zfcp_fsf_open_wka_port - create and send open wka-port request
1579 * @wka_port: pointer to struct zfcp_fc_wka_port
1580 * Returns: 0 on success, error otherwise
1582 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1584 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1585 struct zfcp_fsf_req *req;
1588 spin_lock_irq(&qdio->req_q_lock);
1589 if (zfcp_qdio_sbal_get(qdio))
1592 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1593 SBAL_FLAGS0_TYPE_READ,
1594 qdio->adapter->pool.erp_req);
1596 if (unlikely(IS_ERR(req))) {
1597 retval = PTR_ERR(req);
1601 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1602 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1604 req->handler = zfcp_fsf_open_wka_port_handler;
1605 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1606 req->data = wka_port;
1608 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1609 retval = zfcp_fsf_req_send(req);
1611 zfcp_fsf_req_free(req);
1613 spin_unlock_irq(&qdio->req_q_lock);
1617 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1619 struct zfcp_fc_wka_port *wka_port = req->data;
1621 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1622 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1623 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1626 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1627 wake_up(&wka_port->completion_wq);
1631 * zfcp_fsf_close_wka_port - create and send close wka port request
1632 * @wka_port: WKA port to open
1633 * Returns: 0 on success, error otherwise
1635 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1637 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1638 struct zfcp_fsf_req *req;
1641 spin_lock_irq(&qdio->req_q_lock);
1642 if (zfcp_qdio_sbal_get(qdio))
1645 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1646 SBAL_FLAGS0_TYPE_READ,
1647 qdio->adapter->pool.erp_req);
1649 if (unlikely(IS_ERR(req))) {
1650 retval = PTR_ERR(req);
1654 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1655 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1657 req->handler = zfcp_fsf_close_wka_port_handler;
1658 req->data = wka_port;
1659 req->qtcb->header.port_handle = wka_port->handle;
1661 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1662 retval = zfcp_fsf_req_send(req);
1664 zfcp_fsf_req_free(req);
1666 spin_unlock_irq(&qdio->req_q_lock);
1670 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1672 struct zfcp_port *port = req->data;
1673 struct fsf_qtcb_header *header = &req->qtcb->header;
1674 struct scsi_device *sdev;
1676 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1679 switch (header->fsf_status) {
1680 case FSF_PORT_HANDLE_NOT_VALID:
1681 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1682 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1684 case FSF_ACCESS_DENIED:
1685 zfcp_fsf_access_denied_port(req, port);
1687 case FSF_PORT_BOXED:
1688 /* can't use generic zfcp_erp_modify_port_status because
1689 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1690 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1691 shost_for_each_device(sdev, port->adapter->scsi_host)
1692 if (sdev_to_zfcp(sdev)->port == port)
1693 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1694 &sdev_to_zfcp(sdev)->status);
1695 zfcp_erp_port_boxed(port, "fscpph2", req);
1696 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1698 case FSF_ADAPTER_STATUS_AVAILABLE:
1699 switch (header->fsf_status_qual.word[0]) {
1700 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1702 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1703 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1708 /* can't use generic zfcp_erp_modify_port_status because
1709 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1711 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1712 shost_for_each_device(sdev, port->adapter->scsi_host)
1713 if (sdev_to_zfcp(sdev)->port == port)
1714 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1715 &sdev_to_zfcp(sdev)->status);
1721 * zfcp_fsf_close_physical_port - close physical port
1722 * @erp_action: pointer to struct zfcp_erp_action
1723 * Returns: 0 on success
1725 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1727 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1728 struct zfcp_fsf_req *req;
1731 spin_lock_irq(&qdio->req_q_lock);
1732 if (zfcp_qdio_sbal_get(qdio))
1735 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1736 SBAL_FLAGS0_TYPE_READ,
1737 qdio->adapter->pool.erp_req);
1740 retval = PTR_ERR(req);
1744 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1745 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1747 req->data = erp_action->port;
1748 req->qtcb->header.port_handle = erp_action->port->handle;
1749 req->erp_action = erp_action;
1750 req->handler = zfcp_fsf_close_physical_port_handler;
1751 erp_action->fsf_req_id = req->req_id;
1753 zfcp_fsf_start_erp_timer(req);
1754 retval = zfcp_fsf_req_send(req);
1756 zfcp_fsf_req_free(req);
1757 erp_action->fsf_req_id = 0;
1760 spin_unlock_irq(&qdio->req_q_lock);
1764 static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
1766 struct zfcp_adapter *adapter = req->adapter;
1767 struct scsi_device *sdev = req->data;
1768 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
1769 struct fsf_qtcb_header *header = &req->qtcb->header;
1770 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1771 struct fsf_queue_designator *queue_designator =
1772 &header->fsf_status_qual.fsf_queue_designator;
1773 int exclusive, readwrite;
1775 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1778 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1779 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1780 ZFCP_STATUS_LUN_SHARED |
1781 ZFCP_STATUS_LUN_READONLY,
1782 &zfcp_sdev->status);
1784 switch (header->fsf_status) {
1786 case FSF_PORT_HANDLE_NOT_VALID:
1787 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1", req);
1789 case FSF_LUN_ALREADY_OPEN:
1791 case FSF_ACCESS_DENIED:
1792 zfcp_fsf_access_denied_lun(req, sdev);
1793 atomic_clear_mask(ZFCP_STATUS_LUN_SHARED, &zfcp_sdev->status);
1794 atomic_clear_mask(ZFCP_STATUS_LUN_READONLY, &zfcp_sdev->status);
1796 case FSF_PORT_BOXED:
1797 zfcp_erp_port_boxed(zfcp_sdev->port, "fsouh_2", req);
1798 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1800 case FSF_LUN_SHARING_VIOLATION:
1801 if (header->fsf_status_qual.word[0])
1802 dev_warn(&adapter->ccw_device->dev,
1803 "LUN 0x%Lx on port 0x%Lx is already in "
1804 "use by CSS%d, MIF Image ID %x\n",
1805 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1806 (unsigned long long)zfcp_sdev->port->wwpn,
1807 queue_designator->cssid,
1808 queue_designator->hla);
1810 zfcp_act_eval_err(adapter,
1811 header->fsf_status_qual.word[2]);
1812 zfcp_erp_lun_access_denied(sdev, "fsolh_3", req);
1813 atomic_clear_mask(ZFCP_STATUS_LUN_SHARED, &zfcp_sdev->status);
1814 atomic_clear_mask(ZFCP_STATUS_LUN_READONLY, &zfcp_sdev->status);
1815 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1817 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1818 dev_warn(&adapter->ccw_device->dev,
1819 "No handle is available for LUN "
1820 "0x%016Lx on port 0x%016Lx\n",
1821 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1822 (unsigned long long)zfcp_sdev->port->wwpn);
1823 zfcp_erp_lun_failed(sdev, "fsolh_4", req);
1825 case FSF_INVALID_COMMAND_OPTION:
1826 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1828 case FSF_ADAPTER_STATUS_AVAILABLE:
1829 switch (header->fsf_status_qual.word[0]) {
1830 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1831 zfcp_fc_test_link(zfcp_sdev->port);
1833 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1834 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1840 zfcp_sdev->lun_handle = header->lun_handle;
1841 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
1843 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1844 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1845 !zfcp_ccw_priv_sch(adapter)) {
1846 exclusive = (bottom->lun_access_info &
1847 FSF_UNIT_ACCESS_EXCLUSIVE);
1848 readwrite = (bottom->lun_access_info &
1849 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1852 atomic_set_mask(ZFCP_STATUS_LUN_SHARED,
1853 &zfcp_sdev->status);
1856 atomic_set_mask(ZFCP_STATUS_LUN_READONLY,
1857 &zfcp_sdev->status);
1858 dev_info(&adapter->ccw_device->dev,
1859 "SCSI device at LUN 0x%016Lx on port "
1860 "0x%016Lx opened read-only\n",
1861 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1862 (unsigned long long)zfcp_sdev->port->wwpn);
1865 if (exclusive && !readwrite) {
1866 dev_err(&adapter->ccw_device->dev,
1867 "Exclusive read-only access not "
1868 "supported (LUN 0x%016Lx, "
1870 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1871 (unsigned long long)zfcp_sdev->port->wwpn);
1872 zfcp_erp_lun_failed(sdev, "fsolh_5", req);
1873 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1874 zfcp_erp_lun_shutdown(sdev, 0, "fsolh_6", req);
1875 } else if (!exclusive && readwrite) {
1876 dev_err(&adapter->ccw_device->dev,
1877 "Shared read-write access not "
1878 "supported (LUN 0x%016Lx, port "
1880 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1881 (unsigned long long)zfcp_sdev->port->wwpn);
1882 zfcp_erp_lun_failed(sdev, "fsolh_7", req);
1883 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1884 zfcp_erp_lun_shutdown(sdev, 0, "fsolh_8", req);
1892 * zfcp_fsf_open_lun - open LUN
1893 * @erp_action: pointer to struct zfcp_erp_action
1894 * Returns: 0 on success, error otherwise
1896 int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
1898 struct zfcp_adapter *adapter = erp_action->adapter;
1899 struct zfcp_qdio *qdio = adapter->qdio;
1900 struct zfcp_fsf_req *req;
1903 spin_lock_irq(&qdio->req_q_lock);
1904 if (zfcp_qdio_sbal_get(qdio))
1907 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1908 SBAL_FLAGS0_TYPE_READ,
1909 adapter->pool.erp_req);
1912 retval = PTR_ERR(req);
1916 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1917 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1919 req->qtcb->header.port_handle = erp_action->port->handle;
1920 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1921 req->handler = zfcp_fsf_open_lun_handler;
1922 req->data = erp_action->sdev;
1923 req->erp_action = erp_action;
1924 erp_action->fsf_req_id = req->req_id;
1926 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1927 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1929 zfcp_fsf_start_erp_timer(req);
1930 retval = zfcp_fsf_req_send(req);
1932 zfcp_fsf_req_free(req);
1933 erp_action->fsf_req_id = 0;
1936 spin_unlock_irq(&qdio->req_q_lock);
1940 static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
1942 struct scsi_device *sdev = req->data;
1943 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
1945 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1948 switch (req->qtcb->header.fsf_status) {
1949 case FSF_PORT_HANDLE_NOT_VALID:
1950 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1",
1952 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1954 case FSF_LUN_HANDLE_NOT_VALID:
1955 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2", req);
1956 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1958 case FSF_PORT_BOXED:
1959 zfcp_erp_port_boxed(zfcp_sdev->port, "fscuh_3", req);
1960 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1962 case FSF_ADAPTER_STATUS_AVAILABLE:
1963 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1964 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1965 zfcp_fc_test_link(zfcp_sdev->port);
1967 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1968 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1973 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
1979 * zfcp_fsf_close_LUN - close LUN
1980 * @erp_action: pointer to erp_action triggering the "close LUN"
1981 * Returns: 0 on success, error otherwise
1983 int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
1985 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1986 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
1987 struct zfcp_fsf_req *req;
1990 spin_lock_irq(&qdio->req_q_lock);
1991 if (zfcp_qdio_sbal_get(qdio))
1994 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
1995 SBAL_FLAGS0_TYPE_READ,
1996 qdio->adapter->pool.erp_req);
1999 retval = PTR_ERR(req);
2003 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2004 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2006 req->qtcb->header.port_handle = erp_action->port->handle;
2007 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2008 req->handler = zfcp_fsf_close_lun_handler;
2009 req->data = erp_action->sdev;
2010 req->erp_action = erp_action;
2011 erp_action->fsf_req_id = req->req_id;
2013 zfcp_fsf_start_erp_timer(req);
2014 retval = zfcp_fsf_req_send(req);
2016 zfcp_fsf_req_free(req);
2017 erp_action->fsf_req_id = 0;
2020 spin_unlock_irq(&qdio->req_q_lock);
2024 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2026 lat_rec->sum += lat;
2027 lat_rec->min = min(lat_rec->min, lat);
2028 lat_rec->max = max(lat_rec->max, lat);
2031 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2033 struct fsf_qual_latency_info *lat_in;
2034 struct latency_cont *lat = NULL;
2035 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scsi->device);
2036 struct zfcp_blk_drv_data blktrc;
2037 int ticks = req->adapter->timer_ticks;
2039 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2042 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2043 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2044 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2045 blktrc.inb_usage = 0;
2046 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
2048 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2049 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2050 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2051 blktrc.channel_lat = lat_in->channel_lat * ticks;
2052 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2054 switch (req->qtcb->bottom.io.data_direction) {
2055 case FSF_DATADIR_DIF_READ_STRIP:
2056 case FSF_DATADIR_DIF_READ_CONVERT:
2057 case FSF_DATADIR_READ:
2058 lat = &zfcp_sdev->latencies.read;
2060 case FSF_DATADIR_DIF_WRITE_INSERT:
2061 case FSF_DATADIR_DIF_WRITE_CONVERT:
2062 case FSF_DATADIR_WRITE:
2063 lat = &zfcp_sdev->latencies.write;
2065 case FSF_DATADIR_CMND:
2066 lat = &zfcp_sdev->latencies.cmd;
2071 spin_lock(&zfcp_sdev->latencies.lock);
2072 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2073 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2075 spin_unlock(&zfcp_sdev->latencies.lock);
2079 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2083 static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
2085 struct scsi_cmnd *scmnd = req->data;
2086 struct scsi_device *sdev = scmnd->device;
2087 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2088 struct fsf_qtcb_header *header = &req->qtcb->header;
2090 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2093 switch (header->fsf_status) {
2094 case FSF_HANDLE_MISMATCH:
2095 case FSF_PORT_HANDLE_NOT_VALID:
2096 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1",
2098 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2100 case FSF_FCPLUN_NOT_VALID:
2101 case FSF_LUN_HANDLE_NOT_VALID:
2102 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2", req);
2103 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2105 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2106 zfcp_fsf_class_not_supp(req);
2108 case FSF_ACCESS_DENIED:
2109 zfcp_fsf_access_denied_lun(req, sdev);
2111 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2112 dev_err(&req->adapter->ccw_device->dev,
2113 "Incorrect direction %d, LUN 0x%016Lx on port "
2114 "0x%016Lx closed\n",
2115 req->qtcb->bottom.io.data_direction,
2116 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2117 (unsigned long long)zfcp_sdev->port->wwpn);
2118 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
2120 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2122 case FSF_CMND_LENGTH_NOT_VALID:
2123 dev_err(&req->adapter->ccw_device->dev,
2124 "Incorrect CDB length %d, LUN 0x%016Lx on "
2125 "port 0x%016Lx closed\n",
2126 req->qtcb->bottom.io.fcp_cmnd_length,
2127 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2128 (unsigned long long)zfcp_sdev->port->wwpn);
2129 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
2131 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2133 case FSF_PORT_BOXED:
2134 zfcp_erp_port_boxed(zfcp_sdev->port, "fssfch5", req);
2135 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2138 zfcp_erp_lun_boxed(sdev, "fssfch6", req);
2139 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2141 case FSF_ADAPTER_STATUS_AVAILABLE:
2142 if (header->fsf_status_qual.word[0] ==
2143 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2144 zfcp_fc_test_link(zfcp_sdev->port);
2145 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2150 static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2152 struct scsi_cmnd *scpnt;
2153 struct fcp_resp_with_ext *fcp_rsp;
2154 unsigned long flags;
2156 zfcp_fsf_fcp_handler_common(req);
2158 read_lock_irqsave(&req->adapter->abort_lock, flags);
2161 if (unlikely(!scpnt)) {
2162 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2166 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2167 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2168 goto skip_fsfstatus;
2171 switch (req->qtcb->header.fsf_status) {
2172 case FSF_INCONSISTENT_PROT_DATA:
2173 case FSF_INVALID_PROT_PARM:
2174 set_host_byte(scpnt, DID_ERROR);
2175 goto skip_fsfstatus;
2176 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2177 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2178 goto skip_fsfstatus;
2179 case FSF_APP_TAG_CHECK_FAILURE:
2180 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2181 goto skip_fsfstatus;
2182 case FSF_REF_TAG_CHECK_FAILURE:
2183 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2184 goto skip_fsfstatus;
2186 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2187 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2190 zfcp_fsf_req_trace(req, scpnt);
2191 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
2193 scpnt->host_scribble = NULL;
2194 (scpnt->scsi_done) (scpnt);
2196 * We must hold this lock until scsi_done has been called.
2197 * Otherwise we may call scsi_done after abort regarding this
2198 * command has completed.
2199 * Note: scsi_done must not block!
2201 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2204 static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2206 switch (scsi_get_prot_op(scsi_cmnd)) {
2207 case SCSI_PROT_NORMAL:
2208 switch (scsi_cmnd->sc_data_direction) {
2210 *data_dir = FSF_DATADIR_CMND;
2212 case DMA_FROM_DEVICE:
2213 *data_dir = FSF_DATADIR_READ;
2216 *data_dir = FSF_DATADIR_WRITE;
2218 case DMA_BIDIRECTIONAL:
2223 case SCSI_PROT_READ_STRIP:
2224 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2226 case SCSI_PROT_WRITE_INSERT:
2227 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2229 case SCSI_PROT_READ_PASS:
2230 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2232 case SCSI_PROT_WRITE_PASS:
2233 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2243 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
2244 * @scsi_cmnd: scsi command to be sent
2246 int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
2248 struct zfcp_fsf_req *req;
2249 struct fcp_cmnd *fcp_cmnd;
2250 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2251 int real_bytes, retval = -EIO, dix_bytes = 0;
2252 struct scsi_device *sdev = scsi_cmnd->device;
2253 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2254 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
2255 struct zfcp_qdio *qdio = adapter->qdio;
2256 struct fsf_qtcb_bottom_io *io;
2258 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2259 ZFCP_STATUS_COMMON_UNBLOCKED)))
2262 spin_lock(&qdio->req_q_lock);
2263 if (atomic_read(&qdio->req_q_free) <= 0) {
2264 atomic_inc(&qdio->req_q_full);
2268 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2269 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2271 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2272 sbtype, adapter->pool.scsi_req);
2275 retval = PTR_ERR(req);
2279 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2281 io = &req->qtcb->bottom.io;
2282 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2283 req->data = scsi_cmnd;
2284 req->handler = zfcp_fsf_fcp_cmnd_handler;
2285 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2286 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2287 io->service_class = FSF_CLASS_3;
2288 io->fcp_cmnd_length = FCP_CMND_LEN;
2290 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2291 io->data_block_length = scsi_cmnd->device->sector_size;
2292 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
2295 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
2297 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2298 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2300 if (scsi_prot_sg_count(scsi_cmnd)) {
2301 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2302 scsi_prot_sg_count(scsi_cmnd));
2303 dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2304 scsi_prot_sglist(scsi_cmnd));
2305 io->prot_data_length = dix_bytes;
2308 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2309 scsi_sglist(scsi_cmnd));
2311 if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
2312 goto failed_scsi_cmnd;
2314 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2316 retval = zfcp_fsf_req_send(req);
2317 if (unlikely(retval))
2318 goto failed_scsi_cmnd;
2323 zfcp_fsf_req_free(req);
2324 scsi_cmnd->host_scribble = NULL;
2326 spin_unlock(&qdio->req_q_lock);
2330 static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2332 struct fcp_resp_with_ext *fcp_rsp;
2333 struct fcp_resp_rsp_info *rsp_info;
2335 zfcp_fsf_fcp_handler_common(req);
2337 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2338 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2340 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2341 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2342 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2346 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2347 * @scmnd: SCSI command to send the task management command for
2348 * @tm_flags: unsigned byte for task management flags
2349 * Returns: on success pointer to struct fsf_req, NULL otherwise
2351 struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2354 struct zfcp_fsf_req *req = NULL;
2355 struct fcp_cmnd *fcp_cmnd;
2356 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2357 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
2359 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2360 ZFCP_STATUS_COMMON_UNBLOCKED)))
2363 spin_lock_irq(&qdio->req_q_lock);
2364 if (zfcp_qdio_sbal_get(qdio))
2367 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2368 SBAL_FLAGS0_TYPE_WRITE,
2369 qdio->adapter->pool.scsi_req);
2376 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2378 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
2379 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2380 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2381 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2382 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2383 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2385 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2387 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2388 zfcp_fc_fcp_tm(fcp_cmnd, scmnd->device, tm_flags);
2390 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2391 if (!zfcp_fsf_req_send(req))
2394 zfcp_fsf_req_free(req);
2397 spin_unlock_irq(&qdio->req_q_lock);
2401 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2406 * zfcp_fsf_control_file - control file upload/download
2407 * @adapter: pointer to struct zfcp_adapter
2408 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2409 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2411 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2412 struct zfcp_fsf_cfdc *fsf_cfdc)
2414 struct zfcp_qdio *qdio = adapter->qdio;
2415 struct zfcp_fsf_req *req = NULL;
2416 struct fsf_qtcb_bottom_support *bottom;
2417 int direction, retval = -EIO, bytes;
2419 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2420 return ERR_PTR(-EOPNOTSUPP);
2422 switch (fsf_cfdc->command) {
2423 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2424 direction = SBAL_FLAGS0_TYPE_WRITE;
2426 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2427 direction = SBAL_FLAGS0_TYPE_READ;
2430 return ERR_PTR(-EINVAL);
2433 spin_lock_irq(&qdio->req_q_lock);
2434 if (zfcp_qdio_sbal_get(qdio))
2437 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
2443 req->handler = zfcp_fsf_control_file_handler;
2445 bottom = &req->qtcb->bottom.support;
2446 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2447 bottom->option = fsf_cfdc->option;
2449 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
2451 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2452 zfcp_fsf_req_free(req);
2455 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2457 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2458 retval = zfcp_fsf_req_send(req);
2460 spin_unlock_irq(&qdio->req_q_lock);
2463 wait_for_completion(&req->completion);
2466 return ERR_PTR(retval);
2470 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2471 * @adapter: pointer to struct zfcp_adapter
2472 * @sbal_idx: response queue index of SBAL to be processed
2474 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2476 struct zfcp_adapter *adapter = qdio->adapter;
2477 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
2478 struct qdio_buffer_element *sbale;
2479 struct zfcp_fsf_req *fsf_req;
2480 unsigned long req_id;
2483 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2485 sbale = &sbal->element[idx];
2486 req_id = (unsigned long) sbale->addr;
2487 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2491 * Unknown request means that we have potentially memory
2492 * corruption and must stop the machine immediately.
2494 zfcp_qdio_siosl(adapter);
2495 panic("error: unknown req_id (%lx) on adapter %s.\n",
2496 req_id, dev_name(&adapter->ccw_device->dev));
2499 fsf_req->qdio_req.sbal_response = sbal_idx;
2500 zfcp_fsf_req_complete(fsf_req);
2502 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))