4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2009
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <scsi/fc/fc_els.h>
18 static void zfcp_fsf_request_timeout_handler(unsigned long data)
20 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
21 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
25 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
26 unsigned long timeout)
28 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
29 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
30 fsf_req->timer.expires = jiffies + timeout;
31 add_timer(&fsf_req->timer);
34 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
36 BUG_ON(!fsf_req->erp_action);
37 fsf_req->timer.function = zfcp_erp_timeout_handler;
38 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
39 fsf_req->timer.expires = jiffies + 30 * HZ;
40 add_timer(&fsf_req->timer);
43 /* association between FSF command and FSF QTCB type */
44 static u32 fsf_qtcb_type[] = {
45 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
46 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
55 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
56 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
60 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
62 u16 subtable = table >> 16;
63 u16 rule = table & 0xffff;
64 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
66 if (subtable && subtable < ARRAY_SIZE(act_type))
67 dev_warn(&adapter->ccw_device->dev,
68 "Access denied according to ACT rule type %s, "
69 "rule %d\n", act_type[subtable], rule);
72 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
73 struct zfcp_port *port)
75 struct fsf_qtcb_header *header = &req->qtcb->header;
76 dev_warn(&req->adapter->ccw_device->dev,
77 "Access denied to port 0x%016Lx\n",
78 (unsigned long long)port->wwpn);
79 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
80 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
81 zfcp_erp_port_access_denied(port, "fspad_1", req);
82 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
85 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
86 struct zfcp_unit *unit)
88 struct fsf_qtcb_header *header = &req->qtcb->header;
89 dev_warn(&req->adapter->ccw_device->dev,
90 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
91 (unsigned long long)unit->fcp_lun,
92 (unsigned long long)unit->port->wwpn);
93 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
95 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
96 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
99 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
101 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
102 "operational because of an unsupported FC class\n");
103 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
108 * zfcp_fsf_req_free - free memory used by fsf request
109 * @fsf_req: pointer to struct zfcp_fsf_req
111 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
113 if (likely(req->pool)) {
114 if (likely(req->qtcb))
115 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
116 mempool_free(req, req->pool);
120 if (likely(req->qtcb))
121 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
125 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
128 struct fsf_status_read_buffer *sr_buf = req->data;
129 struct zfcp_adapter *adapter = req->adapter;
130 struct zfcp_port *port;
131 int d_id = ntoh24(sr_buf->d_id);
133 read_lock_irqsave(&adapter->port_list_lock, flags);
134 list_for_each_entry(port, &adapter->port_list, list)
135 if (port->d_id == d_id) {
136 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
139 read_unlock_irqrestore(&adapter->port_list_lock, flags);
142 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
143 struct fsf_link_down_info *link_down)
145 struct zfcp_adapter *adapter = req->adapter;
147 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
150 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
152 zfcp_scsi_schedule_rports_block(adapter);
157 switch (link_down->error_code) {
158 case FSF_PSQ_LINK_NO_LIGHT:
159 dev_warn(&req->adapter->ccw_device->dev,
160 "There is no light signal from the local "
161 "fibre channel cable\n");
163 case FSF_PSQ_LINK_WRAP_PLUG:
164 dev_warn(&req->adapter->ccw_device->dev,
165 "There is a wrap plug instead of a fibre "
168 case FSF_PSQ_LINK_NO_FCP:
169 dev_warn(&req->adapter->ccw_device->dev,
170 "The adjacent fibre channel node does not "
173 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
174 dev_warn(&req->adapter->ccw_device->dev,
175 "The FCP device is suspended because of a "
176 "firmware update\n");
178 case FSF_PSQ_LINK_INVALID_WWPN:
179 dev_warn(&req->adapter->ccw_device->dev,
180 "The FCP device detected a WWPN that is "
181 "duplicate or not valid\n");
183 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
184 dev_warn(&req->adapter->ccw_device->dev,
185 "The fibre channel fabric does not support NPIV\n");
187 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
188 dev_warn(&req->adapter->ccw_device->dev,
189 "The FCP adapter cannot support more NPIV ports\n");
191 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
193 "The adjacent switch cannot support "
194 "more NPIV ports\n");
196 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
197 dev_warn(&req->adapter->ccw_device->dev,
198 "The FCP adapter could not log in to the "
199 "fibre channel fabric\n");
201 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
202 dev_warn(&req->adapter->ccw_device->dev,
203 "The WWPN assignment file on the FCP adapter "
204 "has been damaged\n");
206 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
207 dev_warn(&req->adapter->ccw_device->dev,
208 "The mode table on the FCP adapter "
209 "has been damaged\n");
211 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
212 dev_warn(&req->adapter->ccw_device->dev,
213 "All NPIV ports on the FCP adapter have "
217 dev_warn(&req->adapter->ccw_device->dev,
218 "The link between the FCP adapter and "
219 "the FC fabric is down\n");
222 zfcp_erp_adapter_failed(adapter, id, req);
225 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
227 struct fsf_status_read_buffer *sr_buf = req->data;
228 struct fsf_link_down_info *ldi =
229 (struct fsf_link_down_info *) &sr_buf->payload;
231 switch (sr_buf->status_subtype) {
232 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
233 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
235 case FSF_STATUS_READ_SUB_FDISC_FAILED:
236 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
238 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
239 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
243 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
245 struct zfcp_adapter *adapter = req->adapter;
246 struct fsf_status_read_buffer *sr_buf = req->data;
248 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
249 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
250 mempool_free(sr_buf, adapter->pool.status_read_data);
251 zfcp_fsf_req_free(req);
255 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
257 switch (sr_buf->status_type) {
258 case FSF_STATUS_READ_PORT_CLOSED:
259 zfcp_fsf_status_read_port_closed(req);
261 case FSF_STATUS_READ_INCOMING_ELS:
262 zfcp_fc_incoming_els(req);
264 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
266 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
267 dev_warn(&adapter->ccw_device->dev,
268 "The error threshold for checksum statistics "
269 "has been exceeded\n");
270 zfcp_dbf_hba_berr(adapter->dbf, req);
272 case FSF_STATUS_READ_LINK_DOWN:
273 zfcp_fsf_status_read_link_down(req);
275 case FSF_STATUS_READ_LINK_UP:
276 dev_info(&adapter->ccw_device->dev,
277 "The local link has been restored\n");
278 /* All ports should be marked as ready to run again */
279 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
280 ZFCP_STATUS_COMMON_RUNNING,
282 zfcp_erp_adapter_reopen(adapter,
283 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
284 ZFCP_STATUS_COMMON_ERP_FAILED,
287 case FSF_STATUS_READ_NOTIFICATION_LOST:
288 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
289 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
291 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
292 queue_work(adapter->work_queue, &adapter->scan_work);
294 case FSF_STATUS_READ_CFDC_UPDATED:
295 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
297 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
298 adapter->adapter_features = sr_buf->payload.word[0];
302 mempool_free(sr_buf, adapter->pool.status_read_data);
303 zfcp_fsf_req_free(req);
305 atomic_inc(&adapter->stat_miss);
306 queue_work(adapter->work_queue, &adapter->stat_work);
309 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
311 switch (req->qtcb->header.fsf_status_qual.word[0]) {
312 case FSF_SQ_FCP_RSP_AVAILABLE:
313 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
314 case FSF_SQ_NO_RETRY_POSSIBLE:
315 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
317 case FSF_SQ_COMMAND_ABORTED:
318 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
320 case FSF_SQ_NO_RECOM:
321 dev_err(&req->adapter->ccw_device->dev,
322 "The FCP adapter reported a problem "
323 "that cannot be recovered\n");
324 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
327 /* all non-return stats set FSFREQ_ERROR*/
328 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
331 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
333 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
336 switch (req->qtcb->header.fsf_status) {
337 case FSF_UNKNOWN_COMMAND:
338 dev_err(&req->adapter->ccw_device->dev,
339 "The FCP adapter does not recognize the command 0x%x\n",
340 req->qtcb->header.fsf_command);
341 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
342 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
344 case FSF_ADAPTER_STATUS_AVAILABLE:
345 zfcp_fsf_fsfstatus_qual_eval(req);
350 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
352 struct zfcp_adapter *adapter = req->adapter;
353 struct fsf_qtcb *qtcb = req->qtcb;
354 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
356 zfcp_dbf_hba_fsf_response(req);
358 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
359 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
360 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
364 switch (qtcb->prefix.prot_status) {
366 case FSF_PROT_FSF_STATUS_PRESENTED:
368 case FSF_PROT_QTCB_VERSION_ERROR:
369 dev_err(&adapter->ccw_device->dev,
370 "QTCB version 0x%x not supported by FCP adapter "
371 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
372 psq->word[0], psq->word[1]);
373 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
375 case FSF_PROT_ERROR_STATE:
376 case FSF_PROT_SEQ_NUMB_ERROR:
377 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
378 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
380 case FSF_PROT_UNSUPP_QTCB_TYPE:
381 dev_err(&adapter->ccw_device->dev,
382 "The QTCB type is not supported by the FCP adapter\n");
383 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
385 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
386 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
389 case FSF_PROT_DUPLICATE_REQUEST_ID:
390 dev_err(&adapter->ccw_device->dev,
391 "0x%Lx is an ambiguous request identifier\n",
392 (unsigned long long)qtcb->bottom.support.req_handle);
393 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
395 case FSF_PROT_LINK_DOWN:
396 zfcp_fsf_link_down_info_eval(req, "fspse_5",
397 &psq->link_down_info);
398 /* FIXME: reopening adapter now? better wait for link up */
399 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
401 case FSF_PROT_REEST_QUEUE:
402 /* All ports should be marked as ready to run again */
403 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
404 ZFCP_STATUS_COMMON_RUNNING,
406 zfcp_erp_adapter_reopen(adapter,
407 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
408 ZFCP_STATUS_COMMON_ERP_FAILED,
412 dev_err(&adapter->ccw_device->dev,
413 "0x%x is not a valid transfer protocol status\n",
414 qtcb->prefix.prot_status);
415 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
417 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
421 * zfcp_fsf_req_complete - process completion of a FSF request
422 * @fsf_req: The FSF request that has been completed.
424 * When a request has been completed either from the FCP adapter,
425 * or it has been dismissed due to a queue shutdown, this function
426 * is called to process the completion status and trigger further
427 * events related to the FSF request.
429 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
431 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
432 zfcp_fsf_status_read_handler(req);
436 del_timer(&req->timer);
437 zfcp_fsf_protstatus_eval(req);
438 zfcp_fsf_fsfstatus_eval(req);
442 zfcp_erp_notify(req->erp_action, 0);
444 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
445 zfcp_fsf_req_free(req);
447 complete(&req->completion);
451 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
452 * @adapter: pointer to struct zfcp_adapter
454 * Never ever call this without shutting down the adapter first.
455 * Otherwise the adapter would continue using and corrupting s390 storage.
456 * Included BUG_ON() call to ensure this is done.
457 * ERP is supposed to be the only user of this function.
459 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
461 struct zfcp_fsf_req *req, *tmp;
463 LIST_HEAD(remove_queue);
466 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
467 spin_lock_irqsave(&adapter->req_list_lock, flags);
468 for (i = 0; i < REQUEST_LIST_SIZE; i++)
469 list_splice_init(&adapter->req_list[i], &remove_queue);
470 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
472 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
473 list_del(&req->list);
474 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
475 zfcp_fsf_req_complete(req);
479 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
481 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
482 struct zfcp_adapter *adapter = req->adapter;
483 struct Scsi_Host *shost = adapter->scsi_host;
484 struct fc_els_flogi *nsp, *plogi;
486 /* adjust pointers for missing command code */
487 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
489 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
493 memcpy(req->data, bottom, sizeof(*bottom));
495 fc_host_port_name(shost) = nsp->fl_wwpn;
496 fc_host_node_name(shost) = nsp->fl_wwnn;
497 fc_host_port_id(shost) = ntoh24(bottom->s_id);
498 fc_host_speed(shost) = bottom->fc_link_speed;
499 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
501 adapter->hydra_version = bottom->adapter_type;
502 adapter->timer_ticks = bottom->timer_interval;
504 if (fc_host_permanent_port_name(shost) == -1)
505 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
507 switch (bottom->fc_topology) {
509 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
510 adapter->peer_wwpn = plogi->fl_wwpn;
511 adapter->peer_wwnn = plogi->fl_wwnn;
512 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
514 case FSF_TOPO_FABRIC:
515 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
518 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
521 dev_err(&adapter->ccw_device->dev,
522 "Unknown or unsupported arbitrated loop "
523 "fibre channel topology detected\n");
524 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
531 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
533 struct zfcp_adapter *adapter = req->adapter;
534 struct fsf_qtcb *qtcb = req->qtcb;
535 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
536 struct Scsi_Host *shost = adapter->scsi_host;
538 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
541 adapter->fsf_lic_version = bottom->lic_version;
542 adapter->adapter_features = bottom->adapter_features;
543 adapter->connection_features = bottom->connection_features;
544 adapter->peer_wwpn = 0;
545 adapter->peer_wwnn = 0;
546 adapter->peer_d_id = 0;
548 switch (qtcb->header.fsf_status) {
550 if (zfcp_fsf_exchange_config_evaluate(req))
553 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
554 dev_err(&adapter->ccw_device->dev,
555 "FCP adapter maximum QTCB size (%d bytes) "
557 bottom->max_qtcb_size);
558 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
561 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
564 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
565 fc_host_node_name(shost) = 0;
566 fc_host_port_name(shost) = 0;
567 fc_host_port_id(shost) = 0;
568 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
569 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
570 adapter->hydra_version = 0;
572 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
575 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
576 &qtcb->header.fsf_status_qual.link_down_info);
579 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
583 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
584 adapter->hardware_version = bottom->hardware_version;
585 memcpy(fc_host_serial_number(shost), bottom->serial_number,
586 min(FC_SERIAL_NUMBER_SIZE, 17));
587 EBCASC(fc_host_serial_number(shost),
588 min(FC_SERIAL_NUMBER_SIZE, 17));
591 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
592 dev_err(&adapter->ccw_device->dev,
593 "The FCP adapter only supports newer "
594 "control block versions\n");
595 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
598 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
599 dev_err(&adapter->ccw_device->dev,
600 "The FCP adapter only supports older "
601 "control block versions\n");
602 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
606 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
608 struct zfcp_adapter *adapter = req->adapter;
609 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
610 struct Scsi_Host *shost = adapter->scsi_host;
613 memcpy(req->data, bottom, sizeof(*bottom));
615 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
616 fc_host_permanent_port_name(shost) = bottom->wwpn;
617 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
619 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
620 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
621 fc_host_supported_speeds(shost) = bottom->supported_speed;
624 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
626 struct fsf_qtcb *qtcb = req->qtcb;
628 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
631 switch (qtcb->header.fsf_status) {
633 zfcp_fsf_exchange_port_evaluate(req);
635 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
636 zfcp_fsf_exchange_port_evaluate(req);
637 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
638 &qtcb->header.fsf_status_qual.link_down_info);
643 static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
645 struct zfcp_qdio_queue *req_q = &qdio->req_q;
647 spin_lock_bh(&qdio->req_q_lock);
648 if (atomic_read(&req_q->count))
650 spin_unlock_bh(&qdio->req_q_lock);
654 static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
656 struct zfcp_adapter *adapter = qdio->adapter;
659 spin_unlock_bh(&qdio->req_q_lock);
660 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
661 zfcp_fsf_sbal_check(qdio), 5 * HZ);
665 atomic_inc(&qdio->req_q_full);
666 /* assume hanging outbound queue, try queue recovery */
667 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
670 spin_lock_bh(&qdio->req_q_lock);
674 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
676 struct zfcp_fsf_req *req;
679 req = mempool_alloc(pool, GFP_ATOMIC);
681 req = kmalloc(sizeof(*req), GFP_ATOMIC);
686 memset(req, 0, sizeof(*req));
691 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
693 struct fsf_qtcb *qtcb;
696 qtcb = mempool_alloc(pool, GFP_ATOMIC);
698 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
703 memset(qtcb, 0, sizeof(*qtcb));
707 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
708 u32 fsf_cmd, mempool_t *pool)
710 struct qdio_buffer_element *sbale;
711 struct zfcp_qdio_queue *req_q = &qdio->req_q;
712 struct zfcp_adapter *adapter = qdio->adapter;
713 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
716 return ERR_PTR(-ENOMEM);
718 if (adapter->req_no == 0)
721 INIT_LIST_HEAD(&req->list);
722 init_timer(&req->timer);
723 init_completion(&req->completion);
725 req->adapter = adapter;
726 req->fsf_command = fsf_cmd;
727 req->req_id = adapter->req_no;
728 req->queue_req.sbal_number = 1;
729 req->queue_req.sbal_first = req_q->first;
730 req->queue_req.sbal_last = req_q->first;
731 req->queue_req.sbale_curr = 1;
733 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
734 sbale[0].addr = (void *) req->req_id;
735 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
737 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
739 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
741 req->qtcb = zfcp_qtcb_alloc(NULL);
743 if (unlikely(!req->qtcb)) {
744 zfcp_fsf_req_free(req);
745 return ERR_PTR(-ENOMEM);
748 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
749 req->qtcb->prefix.req_id = req->req_id;
750 req->qtcb->prefix.ulp_info = 26;
751 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
752 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
753 req->qtcb->header.req_handle = req->req_id;
754 req->qtcb->header.fsf_command = req->fsf_command;
755 req->seq_no = adapter->fsf_req_seq_no;
756 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
757 sbale[1].addr = (void *) req->qtcb;
758 sbale[1].length = sizeof(struct fsf_qtcb);
761 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
762 zfcp_fsf_req_free(req);
763 return ERR_PTR(-EIO);
769 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
771 struct zfcp_adapter *adapter = req->adapter;
772 struct zfcp_qdio *qdio = adapter->qdio;
775 int with_qtcb = (req->qtcb != NULL);
777 /* put allocated FSF request into hash table */
778 spin_lock_irqsave(&adapter->req_list_lock, flags);
779 idx = zfcp_reqlist_hash(req->req_id);
780 list_add_tail(&req->list, &adapter->req_list[idx]);
781 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
783 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
784 req->issued = get_clock();
785 if (zfcp_qdio_send(qdio, &req->queue_req)) {
786 del_timer(&req->timer);
787 spin_lock_irqsave(&adapter->req_list_lock, flags);
788 /* lookup request again, list might have changed */
789 if (zfcp_reqlist_find_safe(adapter, req))
790 zfcp_reqlist_remove(adapter, req);
791 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
792 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
796 /* Don't increase for unsolicited status */
798 adapter->fsf_req_seq_no++;
805 * zfcp_fsf_status_read - send status read request
806 * @adapter: pointer to struct zfcp_adapter
807 * @req_flags: request flags
808 * Returns: 0 on success, ERROR otherwise
810 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
812 struct zfcp_adapter *adapter = qdio->adapter;
813 struct zfcp_fsf_req *req;
814 struct fsf_status_read_buffer *sr_buf;
815 struct qdio_buffer_element *sbale;
818 spin_lock_bh(&qdio->req_q_lock);
819 if (zfcp_fsf_req_sbal_get(qdio))
822 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
823 adapter->pool.status_read_req);
825 retval = PTR_ERR(req);
829 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
830 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
831 req->queue_req.sbale_curr = 2;
833 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
838 memset(sr_buf, 0, sizeof(*sr_buf));
840 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
841 sbale->addr = (void *) sr_buf;
842 sbale->length = sizeof(*sr_buf);
844 retval = zfcp_fsf_req_send(req);
846 goto failed_req_send;
851 mempool_free(sr_buf, adapter->pool.status_read_data);
853 zfcp_fsf_req_free(req);
854 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
856 spin_unlock_bh(&qdio->req_q_lock);
860 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
862 struct zfcp_unit *unit = req->data;
863 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
865 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
868 switch (req->qtcb->header.fsf_status) {
869 case FSF_PORT_HANDLE_NOT_VALID:
870 if (fsq->word[0] == fsq->word[1]) {
871 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
873 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
876 case FSF_LUN_HANDLE_NOT_VALID:
877 if (fsq->word[0] == fsq->word[1]) {
878 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
879 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
882 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
883 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
886 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
887 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
888 ZFCP_STATUS_FSFREQ_RETRY;
891 zfcp_erp_unit_boxed(unit, "fsafch4", req);
892 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
893 ZFCP_STATUS_FSFREQ_RETRY;
895 case FSF_ADAPTER_STATUS_AVAILABLE:
896 switch (fsq->word[0]) {
897 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
898 zfcp_fc_test_link(unit->port);
900 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
901 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
906 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
912 * zfcp_fsf_abort_fcp_command - abort running SCSI command
913 * @old_req_id: unsigned long
914 * @unit: pointer to struct zfcp_unit
915 * Returns: pointer to struct zfcp_fsf_req
918 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
919 struct zfcp_unit *unit)
921 struct qdio_buffer_element *sbale;
922 struct zfcp_fsf_req *req = NULL;
923 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
925 spin_lock_bh(&qdio->req_q_lock);
926 if (zfcp_fsf_req_sbal_get(qdio))
928 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
929 qdio->adapter->pool.scsi_abort);
935 if (unlikely(!(atomic_read(&unit->status) &
936 ZFCP_STATUS_COMMON_UNBLOCKED)))
939 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
940 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
941 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
944 req->handler = zfcp_fsf_abort_fcp_command_handler;
945 req->qtcb->header.lun_handle = unit->handle;
946 req->qtcb->header.port_handle = unit->port->handle;
947 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
949 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
950 if (!zfcp_fsf_req_send(req))
954 zfcp_fsf_req_free(req);
957 spin_unlock_bh(&qdio->req_q_lock);
961 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
963 struct zfcp_adapter *adapter = req->adapter;
964 struct zfcp_fsf_ct_els *ct = req->data;
965 struct fsf_qtcb_header *header = &req->qtcb->header;
967 ct->status = -EINVAL;
969 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
972 switch (header->fsf_status) {
974 zfcp_dbf_san_ct_response(req);
977 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
978 zfcp_fsf_class_not_supp(req);
980 case FSF_ADAPTER_STATUS_AVAILABLE:
981 switch (header->fsf_status_qual.word[0]){
982 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
983 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
984 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
988 case FSF_ACCESS_DENIED:
991 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
992 ZFCP_STATUS_FSFREQ_RETRY;
994 case FSF_PORT_HANDLE_NOT_VALID:
995 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
997 case FSF_GENERIC_COMMAND_REJECTED:
998 case FSF_PAYLOAD_SIZE_MISMATCH:
999 case FSF_REQUEST_SIZE_TOO_LARGE:
1000 case FSF_RESPONSE_SIZE_TOO_LARGE:
1001 case FSF_SBAL_MISMATCH:
1002 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1008 ct->handler(ct->handler_data);
1011 static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
1012 struct scatterlist *sg_req,
1013 struct scatterlist *sg_resp)
1015 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1016 sbale[2].addr = sg_virt(sg_req);
1017 sbale[2].length = sg_req->length;
1018 sbale[3].addr = sg_virt(sg_resp);
1019 sbale[3].length = sg_resp->length;
1020 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1023 static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1025 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1028 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1029 struct scatterlist *sg_req,
1030 struct scatterlist *sg_resp,
1033 struct zfcp_adapter *adapter = req->adapter;
1034 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
1036 u32 feat = adapter->adapter_features;
1039 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1040 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
1043 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1047 /* use single, unchained SBAL if it can hold the request */
1048 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1049 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1053 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1054 SBAL_FLAGS0_TYPE_WRITE_READ,
1058 req->qtcb->bottom.support.req_buf_length = bytes;
1059 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1061 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1062 SBAL_FLAGS0_TYPE_WRITE_READ,
1063 sg_resp, max_sbals);
1064 req->qtcb->bottom.support.resp_buf_length = bytes;
1071 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1072 struct scatterlist *sg_req,
1073 struct scatterlist *sg_resp,
1077 unsigned int fcp_chan_timeout;
1079 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1083 /* common settings for ct/gs and els requests */
1084 fcp_chan_timeout = 2 * FC_DEF_R_A_TOV / 1000;
1085 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1086 req->qtcb->bottom.support.timeout = fcp_chan_timeout;
1087 zfcp_fsf_start_timer(req, (fcp_chan_timeout + 10) * HZ);
1093 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1094 * @ct: pointer to struct zfcp_send_ct with data for request
1095 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1097 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1098 struct zfcp_fsf_ct_els *ct, mempool_t *pool)
1100 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1101 struct zfcp_fsf_req *req;
1104 spin_lock_bh(&qdio->req_q_lock);
1105 if (zfcp_fsf_req_sbal_get(qdio))
1108 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
1115 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1116 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
1117 FSF_MAX_SBALS_PER_REQ);
1121 req->handler = zfcp_fsf_send_ct_handler;
1122 req->qtcb->header.port_handle = wka_port->handle;
1125 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1127 ret = zfcp_fsf_req_send(req);
1134 zfcp_fsf_req_free(req);
1136 spin_unlock_bh(&qdio->req_q_lock);
1140 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1142 struct zfcp_fsf_ct_els *send_els = req->data;
1143 struct zfcp_port *port = send_els->port;
1144 struct fsf_qtcb_header *header = &req->qtcb->header;
1146 send_els->status = -EINVAL;
1148 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1149 goto skip_fsfstatus;
1151 switch (header->fsf_status) {
1153 zfcp_dbf_san_els_response(req);
1154 send_els->status = 0;
1156 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1157 zfcp_fsf_class_not_supp(req);
1159 case FSF_ADAPTER_STATUS_AVAILABLE:
1160 switch (header->fsf_status_qual.word[0]){
1161 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1162 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1163 case FSF_SQ_RETRY_IF_POSSIBLE:
1164 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1168 case FSF_ELS_COMMAND_REJECTED:
1169 case FSF_PAYLOAD_SIZE_MISMATCH:
1170 case FSF_REQUEST_SIZE_TOO_LARGE:
1171 case FSF_RESPONSE_SIZE_TOO_LARGE:
1173 case FSF_ACCESS_DENIED:
1175 zfcp_fsf_access_denied_port(req, port);
1177 case FSF_SBAL_MISMATCH:
1178 /* should never occure, avoided in zfcp_fsf_send_els */
1181 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1185 if (send_els->handler)
1186 send_els->handler(send_els->handler_data);
1190 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1191 * @els: pointer to struct zfcp_send_els with data for the command
1193 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1194 struct zfcp_fsf_ct_els *els)
1196 struct zfcp_fsf_req *req;
1197 struct zfcp_qdio *qdio = adapter->qdio;
1200 spin_lock_bh(&qdio->req_q_lock);
1201 if (zfcp_fsf_req_sbal_get(qdio))
1204 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
1211 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1212 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2);
1217 hton24(req->qtcb->bottom.support.d_id, d_id);
1218 req->handler = zfcp_fsf_send_els_handler;
1221 zfcp_dbf_san_els_request(req);
1223 ret = zfcp_fsf_req_send(req);
1230 zfcp_fsf_req_free(req);
1232 spin_unlock_bh(&qdio->req_q_lock);
1236 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1238 struct qdio_buffer_element *sbale;
1239 struct zfcp_fsf_req *req;
1240 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1243 spin_lock_bh(&qdio->req_q_lock);
1244 if (zfcp_fsf_req_sbal_get(qdio))
1247 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1248 qdio->adapter->pool.erp_req);
1251 retval = PTR_ERR(req);
1255 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1256 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1257 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1258 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1260 req->qtcb->bottom.config.feature_selection =
1262 FSF_FEATURE_LUN_SHARING |
1263 FSF_FEATURE_NOTIFICATION_LOST |
1264 FSF_FEATURE_UPDATE_ALERT;
1265 req->erp_action = erp_action;
1266 req->handler = zfcp_fsf_exchange_config_data_handler;
1267 erp_action->fsf_req = req;
1269 zfcp_fsf_start_erp_timer(req);
1270 retval = zfcp_fsf_req_send(req);
1272 zfcp_fsf_req_free(req);
1273 erp_action->fsf_req = NULL;
1276 spin_unlock_bh(&qdio->req_q_lock);
1280 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1281 struct fsf_qtcb_bottom_config *data)
1283 struct qdio_buffer_element *sbale;
1284 struct zfcp_fsf_req *req = NULL;
1287 spin_lock_bh(&qdio->req_q_lock);
1288 if (zfcp_fsf_req_sbal_get(qdio))
1291 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
1294 retval = PTR_ERR(req);
1298 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1299 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1300 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1301 req->handler = zfcp_fsf_exchange_config_data_handler;
1303 req->qtcb->bottom.config.feature_selection =
1305 FSF_FEATURE_LUN_SHARING |
1306 FSF_FEATURE_NOTIFICATION_LOST |
1307 FSF_FEATURE_UPDATE_ALERT;
1312 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1313 retval = zfcp_fsf_req_send(req);
1314 spin_unlock_bh(&qdio->req_q_lock);
1316 wait_for_completion(&req->completion);
1318 zfcp_fsf_req_free(req);
1322 spin_unlock_bh(&qdio->req_q_lock);
1327 * zfcp_fsf_exchange_port_data - request information about local port
1328 * @erp_action: ERP action for the adapter for which port data is requested
1329 * Returns: 0 on success, error otherwise
1331 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1333 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1334 struct qdio_buffer_element *sbale;
1335 struct zfcp_fsf_req *req;
1338 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1341 spin_lock_bh(&qdio->req_q_lock);
1342 if (zfcp_fsf_req_sbal_get(qdio))
1345 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1346 qdio->adapter->pool.erp_req);
1349 retval = PTR_ERR(req);
1353 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1354 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1355 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1356 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1358 req->handler = zfcp_fsf_exchange_port_data_handler;
1359 req->erp_action = erp_action;
1360 erp_action->fsf_req = req;
1362 zfcp_fsf_start_erp_timer(req);
1363 retval = zfcp_fsf_req_send(req);
1365 zfcp_fsf_req_free(req);
1366 erp_action->fsf_req = NULL;
1369 spin_unlock_bh(&qdio->req_q_lock);
1374 * zfcp_fsf_exchange_port_data_sync - request information about local port
1375 * @qdio: pointer to struct zfcp_qdio
1376 * @data: pointer to struct fsf_qtcb_bottom_port
1377 * Returns: 0 on success, error otherwise
1379 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1380 struct fsf_qtcb_bottom_port *data)
1382 struct qdio_buffer_element *sbale;
1383 struct zfcp_fsf_req *req = NULL;
1386 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1389 spin_lock_bh(&qdio->req_q_lock);
1390 if (zfcp_fsf_req_sbal_get(qdio))
1393 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
1396 retval = PTR_ERR(req);
1403 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1404 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1405 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1407 req->handler = zfcp_fsf_exchange_port_data_handler;
1408 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1409 retval = zfcp_fsf_req_send(req);
1410 spin_unlock_bh(&qdio->req_q_lock);
1413 wait_for_completion(&req->completion);
1415 zfcp_fsf_req_free(req);
1420 spin_unlock_bh(&qdio->req_q_lock);
1424 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1426 struct zfcp_port *port = req->data;
1427 struct fsf_qtcb_header *header = &req->qtcb->header;
1428 struct fc_els_flogi *plogi;
1430 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1433 switch (header->fsf_status) {
1434 case FSF_PORT_ALREADY_OPEN:
1436 case FSF_ACCESS_DENIED:
1437 zfcp_fsf_access_denied_port(req, port);
1439 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1440 dev_warn(&req->adapter->ccw_device->dev,
1441 "Not enough FCP adapter resources to open "
1442 "remote port 0x%016Lx\n",
1443 (unsigned long long)port->wwpn);
1444 zfcp_erp_port_failed(port, "fsoph_1", req);
1445 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1447 case FSF_ADAPTER_STATUS_AVAILABLE:
1448 switch (header->fsf_status_qual.word[0]) {
1449 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1450 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1451 case FSF_SQ_NO_RETRY_POSSIBLE:
1452 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1457 port->handle = header->port_handle;
1458 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1459 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1460 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1461 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1463 /* check whether D_ID has changed during open */
1465 * FIXME: This check is not airtight, as the FCP channel does
1466 * not monitor closures of target port connections caused on
1467 * the remote side. Thus, they might miss out on invalidating
1468 * locally cached WWPNs (and other N_Port parameters) of gone
1469 * target ports. So, our heroic attempt to make things safe
1470 * could be undermined by 'open port' response data tagged with
1471 * obsolete WWPNs. Another reason to monitor potential
1472 * connection closures ourself at least (by interpreting
1473 * incoming ELS' and unsolicited status). It just crosses my
1474 * mind that one should be able to cross-check by means of
1475 * another GID_PN straight after a port has been opened.
1476 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1478 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1479 if (req->qtcb->bottom.support.els1_length >=
1481 zfcp_fc_plogi_evaluate(port, plogi);
1483 case FSF_UNKNOWN_OP_SUBTYPE:
1484 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1489 put_device(&port->sysfs_device);
1493 * zfcp_fsf_open_port - create and send open port request
1494 * @erp_action: pointer to struct zfcp_erp_action
1495 * Returns: 0 on success, error otherwise
1497 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1499 struct qdio_buffer_element *sbale;
1500 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1501 struct zfcp_port *port = erp_action->port;
1502 struct zfcp_fsf_req *req;
1505 spin_lock_bh(&qdio->req_q_lock);
1506 if (zfcp_fsf_req_sbal_get(qdio))
1509 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1510 qdio->adapter->pool.erp_req);
1513 retval = PTR_ERR(req);
1517 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1518 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1519 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1520 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1522 req->handler = zfcp_fsf_open_port_handler;
1523 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1525 req->erp_action = erp_action;
1526 erp_action->fsf_req = req;
1527 get_device(&port->sysfs_device);
1529 zfcp_fsf_start_erp_timer(req);
1530 retval = zfcp_fsf_req_send(req);
1532 zfcp_fsf_req_free(req);
1533 erp_action->fsf_req = NULL;
1534 put_device(&port->sysfs_device);
1537 spin_unlock_bh(&qdio->req_q_lock);
1541 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1543 struct zfcp_port *port = req->data;
1545 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1548 switch (req->qtcb->header.fsf_status) {
1549 case FSF_PORT_HANDLE_NOT_VALID:
1550 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1551 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1553 case FSF_ADAPTER_STATUS_AVAILABLE:
1556 zfcp_erp_modify_port_status(port, "fscph_2", req,
1557 ZFCP_STATUS_COMMON_OPEN,
1564 * zfcp_fsf_close_port - create and send close port request
1565 * @erp_action: pointer to struct zfcp_erp_action
1566 * Returns: 0 on success, error otherwise
1568 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1570 struct qdio_buffer_element *sbale;
1571 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1572 struct zfcp_fsf_req *req;
1575 spin_lock_bh(&qdio->req_q_lock);
1576 if (zfcp_fsf_req_sbal_get(qdio))
1579 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1580 qdio->adapter->pool.erp_req);
1583 retval = PTR_ERR(req);
1587 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1588 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1589 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1590 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1592 req->handler = zfcp_fsf_close_port_handler;
1593 req->data = erp_action->port;
1594 req->erp_action = erp_action;
1595 req->qtcb->header.port_handle = erp_action->port->handle;
1596 erp_action->fsf_req = req;
1598 zfcp_fsf_start_erp_timer(req);
1599 retval = zfcp_fsf_req_send(req);
1601 zfcp_fsf_req_free(req);
1602 erp_action->fsf_req = NULL;
1605 spin_unlock_bh(&qdio->req_q_lock);
1609 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1611 struct zfcp_fc_wka_port *wka_port = req->data;
1612 struct fsf_qtcb_header *header = &req->qtcb->header;
1614 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1615 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1619 switch (header->fsf_status) {
1620 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1621 dev_warn(&req->adapter->ccw_device->dev,
1622 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1624 case FSF_ADAPTER_STATUS_AVAILABLE:
1625 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1627 case FSF_ACCESS_DENIED:
1628 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1631 wka_port->handle = header->port_handle;
1633 case FSF_PORT_ALREADY_OPEN:
1634 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1637 wake_up(&wka_port->completion_wq);
1641 * zfcp_fsf_open_wka_port - create and send open wka-port request
1642 * @wka_port: pointer to struct zfcp_fc_wka_port
1643 * Returns: 0 on success, error otherwise
1645 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1647 struct qdio_buffer_element *sbale;
1648 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1649 struct zfcp_fsf_req *req;
1652 spin_lock_bh(&qdio->req_q_lock);
1653 if (zfcp_fsf_req_sbal_get(qdio))
1656 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1657 qdio->adapter->pool.erp_req);
1659 if (unlikely(IS_ERR(req))) {
1660 retval = PTR_ERR(req);
1664 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1665 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1666 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1667 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1669 req->handler = zfcp_fsf_open_wka_port_handler;
1670 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1671 req->data = wka_port;
1673 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1674 retval = zfcp_fsf_req_send(req);
1676 zfcp_fsf_req_free(req);
1678 spin_unlock_bh(&qdio->req_q_lock);
1682 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1684 struct zfcp_fc_wka_port *wka_port = req->data;
1686 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1687 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1688 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1691 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1692 wake_up(&wka_port->completion_wq);
1696 * zfcp_fsf_close_wka_port - create and send close wka port request
1697 * @wka_port: WKA port to open
1698 * Returns: 0 on success, error otherwise
1700 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1702 struct qdio_buffer_element *sbale;
1703 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1704 struct zfcp_fsf_req *req;
1707 spin_lock_bh(&qdio->req_q_lock);
1708 if (zfcp_fsf_req_sbal_get(qdio))
1711 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1712 qdio->adapter->pool.erp_req);
1714 if (unlikely(IS_ERR(req))) {
1715 retval = PTR_ERR(req);
1719 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1720 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1721 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1722 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1724 req->handler = zfcp_fsf_close_wka_port_handler;
1725 req->data = wka_port;
1726 req->qtcb->header.port_handle = wka_port->handle;
1728 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1729 retval = zfcp_fsf_req_send(req);
1731 zfcp_fsf_req_free(req);
1733 spin_unlock_bh(&qdio->req_q_lock);
1737 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1739 struct zfcp_port *port = req->data;
1740 struct fsf_qtcb_header *header = &req->qtcb->header;
1741 struct zfcp_unit *unit;
1743 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1746 switch (header->fsf_status) {
1747 case FSF_PORT_HANDLE_NOT_VALID:
1748 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1749 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1751 case FSF_ACCESS_DENIED:
1752 zfcp_fsf_access_denied_port(req, port);
1754 case FSF_PORT_BOXED:
1755 /* can't use generic zfcp_erp_modify_port_status because
1756 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1757 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1758 read_lock(&port->unit_list_lock);
1759 list_for_each_entry(unit, &port->unit_list, list)
1760 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1762 read_unlock(&port->unit_list_lock);
1763 zfcp_erp_port_boxed(port, "fscpph2", req);
1764 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1765 ZFCP_STATUS_FSFREQ_RETRY;
1768 case FSF_ADAPTER_STATUS_AVAILABLE:
1769 switch (header->fsf_status_qual.word[0]) {
1770 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1772 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1773 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1778 /* can't use generic zfcp_erp_modify_port_status because
1779 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1781 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1782 read_lock(&port->unit_list_lock);
1783 list_for_each_entry(unit, &port->unit_list, list)
1784 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1786 read_unlock(&port->unit_list_lock);
1792 * zfcp_fsf_close_physical_port - close physical port
1793 * @erp_action: pointer to struct zfcp_erp_action
1794 * Returns: 0 on success
1796 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1798 struct qdio_buffer_element *sbale;
1799 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1800 struct zfcp_fsf_req *req;
1803 spin_lock_bh(&qdio->req_q_lock);
1804 if (zfcp_fsf_req_sbal_get(qdio))
1807 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1808 qdio->adapter->pool.erp_req);
1811 retval = PTR_ERR(req);
1815 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1816 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1817 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1818 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1820 req->data = erp_action->port;
1821 req->qtcb->header.port_handle = erp_action->port->handle;
1822 req->erp_action = erp_action;
1823 req->handler = zfcp_fsf_close_physical_port_handler;
1824 erp_action->fsf_req = req;
1826 zfcp_fsf_start_erp_timer(req);
1827 retval = zfcp_fsf_req_send(req);
1829 zfcp_fsf_req_free(req);
1830 erp_action->fsf_req = NULL;
1833 spin_unlock_bh(&qdio->req_q_lock);
1837 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1839 struct zfcp_adapter *adapter = req->adapter;
1840 struct zfcp_unit *unit = req->data;
1841 struct fsf_qtcb_header *header = &req->qtcb->header;
1842 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1843 struct fsf_queue_designator *queue_designator =
1844 &header->fsf_status_qual.fsf_queue_designator;
1845 int exclusive, readwrite;
1847 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1850 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1851 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1852 ZFCP_STATUS_UNIT_SHARED |
1853 ZFCP_STATUS_UNIT_READONLY,
1856 switch (header->fsf_status) {
1858 case FSF_PORT_HANDLE_NOT_VALID:
1859 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1861 case FSF_LUN_ALREADY_OPEN:
1863 case FSF_ACCESS_DENIED:
1864 zfcp_fsf_access_denied_unit(req, unit);
1865 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1866 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1868 case FSF_PORT_BOXED:
1869 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1870 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1871 ZFCP_STATUS_FSFREQ_RETRY;
1873 case FSF_LUN_SHARING_VIOLATION:
1874 if (header->fsf_status_qual.word[0])
1875 dev_warn(&adapter->ccw_device->dev,
1876 "LUN 0x%Lx on port 0x%Lx is already in "
1877 "use by CSS%d, MIF Image ID %x\n",
1878 (unsigned long long)unit->fcp_lun,
1879 (unsigned long long)unit->port->wwpn,
1880 queue_designator->cssid,
1881 queue_designator->hla);
1883 zfcp_act_eval_err(adapter,
1884 header->fsf_status_qual.word[2]);
1885 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1886 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1887 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1888 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1890 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1891 dev_warn(&adapter->ccw_device->dev,
1892 "No handle is available for LUN "
1893 "0x%016Lx on port 0x%016Lx\n",
1894 (unsigned long long)unit->fcp_lun,
1895 (unsigned long long)unit->port->wwpn);
1896 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1898 case FSF_INVALID_COMMAND_OPTION:
1899 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1901 case FSF_ADAPTER_STATUS_AVAILABLE:
1902 switch (header->fsf_status_qual.word[0]) {
1903 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1904 zfcp_fc_test_link(unit->port);
1906 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1907 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1913 unit->handle = header->lun_handle;
1914 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1916 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1917 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1918 !zfcp_ccw_priv_sch(adapter)) {
1919 exclusive = (bottom->lun_access_info &
1920 FSF_UNIT_ACCESS_EXCLUSIVE);
1921 readwrite = (bottom->lun_access_info &
1922 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1925 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1929 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1931 dev_info(&adapter->ccw_device->dev,
1932 "SCSI device at LUN 0x%016Lx on port "
1933 "0x%016Lx opened read-only\n",
1934 (unsigned long long)unit->fcp_lun,
1935 (unsigned long long)unit->port->wwpn);
1938 if (exclusive && !readwrite) {
1939 dev_err(&adapter->ccw_device->dev,
1940 "Exclusive read-only access not "
1941 "supported (unit 0x%016Lx, "
1943 (unsigned long long)unit->fcp_lun,
1944 (unsigned long long)unit->port->wwpn);
1945 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1946 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1947 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1948 } else if (!exclusive && readwrite) {
1949 dev_err(&adapter->ccw_device->dev,
1950 "Shared read-write access not "
1951 "supported (unit 0x%016Lx, port "
1953 (unsigned long long)unit->fcp_lun,
1954 (unsigned long long)unit->port->wwpn);
1955 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1956 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1957 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1965 * zfcp_fsf_open_unit - open unit
1966 * @erp_action: pointer to struct zfcp_erp_action
1967 * Returns: 0 on success, error otherwise
1969 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1971 struct qdio_buffer_element *sbale;
1972 struct zfcp_adapter *adapter = erp_action->adapter;
1973 struct zfcp_qdio *qdio = adapter->qdio;
1974 struct zfcp_fsf_req *req;
1977 spin_lock_bh(&qdio->req_q_lock);
1978 if (zfcp_fsf_req_sbal_get(qdio))
1981 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1982 adapter->pool.erp_req);
1985 retval = PTR_ERR(req);
1989 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1990 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1991 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1992 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1994 req->qtcb->header.port_handle = erp_action->port->handle;
1995 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1996 req->handler = zfcp_fsf_open_unit_handler;
1997 req->data = erp_action->unit;
1998 req->erp_action = erp_action;
1999 erp_action->fsf_req = req;
2001 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2002 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
2004 zfcp_fsf_start_erp_timer(req);
2005 retval = zfcp_fsf_req_send(req);
2007 zfcp_fsf_req_free(req);
2008 erp_action->fsf_req = NULL;
2011 spin_unlock_bh(&qdio->req_q_lock);
2015 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
2017 struct zfcp_unit *unit = req->data;
2019 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2022 switch (req->qtcb->header.fsf_status) {
2023 case FSF_PORT_HANDLE_NOT_VALID:
2024 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
2025 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2027 case FSF_LUN_HANDLE_NOT_VALID:
2028 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
2029 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2031 case FSF_PORT_BOXED:
2032 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2033 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2034 ZFCP_STATUS_FSFREQ_RETRY;
2036 case FSF_ADAPTER_STATUS_AVAILABLE:
2037 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2038 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2039 zfcp_fc_test_link(unit->port);
2041 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2042 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2047 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2053 * zfcp_fsf_close_unit - close zfcp unit
2054 * @erp_action: pointer to struct zfcp_unit
2055 * Returns: 0 on success, error otherwise
2057 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2059 struct qdio_buffer_element *sbale;
2060 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2061 struct zfcp_fsf_req *req;
2064 spin_lock_bh(&qdio->req_q_lock);
2065 if (zfcp_fsf_req_sbal_get(qdio))
2068 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2069 qdio->adapter->pool.erp_req);
2072 retval = PTR_ERR(req);
2076 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2077 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2078 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2079 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2081 req->qtcb->header.port_handle = erp_action->port->handle;
2082 req->qtcb->header.lun_handle = erp_action->unit->handle;
2083 req->handler = zfcp_fsf_close_unit_handler;
2084 req->data = erp_action->unit;
2085 req->erp_action = erp_action;
2086 erp_action->fsf_req = req;
2088 zfcp_fsf_start_erp_timer(req);
2089 retval = zfcp_fsf_req_send(req);
2091 zfcp_fsf_req_free(req);
2092 erp_action->fsf_req = NULL;
2095 spin_unlock_bh(&qdio->req_q_lock);
2099 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2101 lat_rec->sum += lat;
2102 lat_rec->min = min(lat_rec->min, lat);
2103 lat_rec->max = max(lat_rec->max, lat);
2106 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2108 struct fsf_qual_latency_info *lat_in;
2109 struct latency_cont *lat = NULL;
2110 struct zfcp_unit *unit = req->unit;
2111 struct zfcp_blk_drv_data blktrc;
2112 int ticks = req->adapter->timer_ticks;
2114 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2117 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2118 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2119 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2120 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2121 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2123 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2124 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2125 blktrc.channel_lat = lat_in->channel_lat * ticks;
2126 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2128 switch (req->qtcb->bottom.io.data_direction) {
2129 case FSF_DATADIR_READ:
2130 lat = &unit->latencies.read;
2132 case FSF_DATADIR_WRITE:
2133 lat = &unit->latencies.write;
2135 case FSF_DATADIR_CMND:
2136 lat = &unit->latencies.cmd;
2141 spin_lock(&unit->latencies.lock);
2142 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2143 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2145 spin_unlock(&unit->latencies.lock);
2149 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2153 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2155 struct scsi_cmnd *scpnt;
2156 struct fcp_resp_with_ext *fcp_rsp;
2157 unsigned long flags;
2159 read_lock_irqsave(&req->adapter->abort_lock, flags);
2162 if (unlikely(!scpnt)) {
2163 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2167 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
2168 set_host_byte(scpnt, DID_SOFT_ERROR);
2169 goto skip_fsfstatus;
2172 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2173 set_host_byte(scpnt, DID_ERROR);
2174 goto skip_fsfstatus;
2177 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2178 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2180 zfcp_fsf_req_trace(req, scpnt);
2183 if (scpnt->result != 0)
2184 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
2185 else if (scpnt->retries > 0)
2186 zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
2188 zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
2190 scpnt->host_scribble = NULL;
2191 (scpnt->scsi_done) (scpnt);
2193 * We must hold this lock until scsi_done has been called.
2194 * Otherwise we may call scsi_done after abort regarding this
2195 * command has completed.
2196 * Note: scsi_done must not block!
2198 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2201 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2203 struct fcp_resp_with_ext *fcp_rsp;
2204 struct fcp_resp_rsp_info *rsp_info;
2206 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2207 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2209 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2210 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2211 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2215 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2217 struct zfcp_unit *unit;
2218 struct fsf_qtcb_header *header = &req->qtcb->header;
2220 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2225 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2226 goto skip_fsfstatus;
2228 switch (header->fsf_status) {
2229 case FSF_HANDLE_MISMATCH:
2230 case FSF_PORT_HANDLE_NOT_VALID:
2231 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2232 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2234 case FSF_FCPLUN_NOT_VALID:
2235 case FSF_LUN_HANDLE_NOT_VALID:
2236 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2237 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2239 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2240 zfcp_fsf_class_not_supp(req);
2242 case FSF_ACCESS_DENIED:
2243 zfcp_fsf_access_denied_unit(req, unit);
2245 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2246 dev_err(&req->adapter->ccw_device->dev,
2247 "Incorrect direction %d, unit 0x%016Lx on port "
2248 "0x%016Lx closed\n",
2249 req->qtcb->bottom.io.data_direction,
2250 (unsigned long long)unit->fcp_lun,
2251 (unsigned long long)unit->port->wwpn);
2252 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2254 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2256 case FSF_CMND_LENGTH_NOT_VALID:
2257 dev_err(&req->adapter->ccw_device->dev,
2258 "Incorrect CDB length %d, unit 0x%016Lx on "
2259 "port 0x%016Lx closed\n",
2260 req->qtcb->bottom.io.fcp_cmnd_length,
2261 (unsigned long long)unit->fcp_lun,
2262 (unsigned long long)unit->port->wwpn);
2263 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2265 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2267 case FSF_PORT_BOXED:
2268 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2269 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2270 ZFCP_STATUS_FSFREQ_RETRY;
2273 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2274 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2275 ZFCP_STATUS_FSFREQ_RETRY;
2277 case FSF_ADAPTER_STATUS_AVAILABLE:
2278 if (header->fsf_status_qual.word[0] ==
2279 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2280 zfcp_fc_test_link(unit->port);
2281 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2285 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2286 zfcp_fsf_send_fcp_ctm_handler(req);
2288 zfcp_fsf_send_fcp_command_task_handler(req);
2290 put_device(&unit->sysfs_device);
2295 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2296 * @unit: unit where command is sent to
2297 * @scsi_cmnd: scsi command to be sent
2299 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2300 struct scsi_cmnd *scsi_cmnd)
2302 struct zfcp_fsf_req *req;
2303 struct fcp_cmnd *fcp_cmnd;
2304 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2305 int real_bytes, retval = -EIO;
2306 struct zfcp_adapter *adapter = unit->port->adapter;
2307 struct zfcp_qdio *qdio = adapter->qdio;
2309 if (unlikely(!(atomic_read(&unit->status) &
2310 ZFCP_STATUS_COMMON_UNBLOCKED)))
2313 spin_lock(&qdio->req_q_lock);
2314 if (atomic_read(&qdio->req_q.count) <= 0) {
2315 atomic_inc(&qdio->req_q_full);
2319 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2320 adapter->pool.scsi_req);
2323 retval = PTR_ERR(req);
2327 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2328 get_device(&unit->sysfs_device);
2330 req->data = scsi_cmnd;
2331 req->handler = zfcp_fsf_send_fcp_command_handler;
2332 req->qtcb->header.lun_handle = unit->handle;
2333 req->qtcb->header.port_handle = unit->port->handle;
2334 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2335 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2337 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2340 * set depending on data direction:
2341 * data direction bits in SBALE (SB Type)
2342 * data direction bits in QTCB
2344 switch (scsi_cmnd->sc_data_direction) {
2346 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2348 case DMA_FROM_DEVICE:
2349 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2352 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2353 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2355 case DMA_BIDIRECTIONAL:
2356 goto failed_scsi_cmnd;
2359 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2360 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2362 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
2363 scsi_sglist(scsi_cmnd),
2364 FSF_MAX_SBALS_PER_REQ);
2365 if (unlikely(real_bytes < 0)) {
2366 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2367 dev_err(&adapter->ccw_device->dev,
2368 "Oversize data package, unit 0x%016Lx "
2369 "on port 0x%016Lx closed\n",
2370 (unsigned long long)unit->fcp_lun,
2371 (unsigned long long)unit->port->wwpn);
2372 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
2375 goto failed_scsi_cmnd;
2378 retval = zfcp_fsf_req_send(req);
2379 if (unlikely(retval))
2380 goto failed_scsi_cmnd;
2385 put_device(&unit->sysfs_device);
2386 zfcp_fsf_req_free(req);
2387 scsi_cmnd->host_scribble = NULL;
2389 spin_unlock(&qdio->req_q_lock);
2394 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2395 * @unit: pointer to struct zfcp_unit
2396 * @tm_flags: unsigned byte for task management flags
2397 * Returns: on success pointer to struct fsf_req, NULL otherwise
2399 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2401 struct qdio_buffer_element *sbale;
2402 struct zfcp_fsf_req *req = NULL;
2403 struct fcp_cmnd *fcp_cmnd;
2404 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2406 if (unlikely(!(atomic_read(&unit->status) &
2407 ZFCP_STATUS_COMMON_UNBLOCKED)))
2410 spin_lock_bh(&qdio->req_q_lock);
2411 if (zfcp_fsf_req_sbal_get(qdio))
2414 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2415 qdio->adapter->pool.scsi_req);
2422 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2424 req->handler = zfcp_fsf_send_fcp_command_handler;
2425 req->qtcb->header.lun_handle = unit->handle;
2426 req->qtcb->header.port_handle = unit->port->handle;
2427 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2428 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2429 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2431 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2432 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2433 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2435 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2436 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2438 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2439 if (!zfcp_fsf_req_send(req))
2442 zfcp_fsf_req_free(req);
2445 spin_unlock_bh(&qdio->req_q_lock);
2449 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2454 * zfcp_fsf_control_file - control file upload/download
2455 * @adapter: pointer to struct zfcp_adapter
2456 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2457 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2459 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2460 struct zfcp_fsf_cfdc *fsf_cfdc)
2462 struct qdio_buffer_element *sbale;
2463 struct zfcp_qdio *qdio = adapter->qdio;
2464 struct zfcp_fsf_req *req = NULL;
2465 struct fsf_qtcb_bottom_support *bottom;
2466 int direction, retval = -EIO, bytes;
2468 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2469 return ERR_PTR(-EOPNOTSUPP);
2471 switch (fsf_cfdc->command) {
2472 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2473 direction = SBAL_FLAGS0_TYPE_WRITE;
2475 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2476 direction = SBAL_FLAGS0_TYPE_READ;
2479 return ERR_PTR(-EINVAL);
2482 spin_lock_bh(&qdio->req_q_lock);
2483 if (zfcp_fsf_req_sbal_get(qdio))
2486 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
2492 req->handler = zfcp_fsf_control_file_handler;
2494 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2495 sbale[0].flags |= direction;
2497 bottom = &req->qtcb->bottom.support;
2498 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2499 bottom->option = fsf_cfdc->option;
2501 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2502 direction, fsf_cfdc->sg,
2503 FSF_MAX_SBALS_PER_REQ);
2504 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2505 zfcp_fsf_req_free(req);
2509 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2510 retval = zfcp_fsf_req_send(req);
2512 spin_unlock_bh(&qdio->req_q_lock);
2515 wait_for_completion(&req->completion);
2518 return ERR_PTR(retval);
2522 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2523 * @adapter: pointer to struct zfcp_adapter
2524 * @sbal_idx: response queue index of SBAL to be processed
2526 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2528 struct zfcp_adapter *adapter = qdio->adapter;
2529 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
2530 struct qdio_buffer_element *sbale;
2531 struct zfcp_fsf_req *fsf_req;
2532 unsigned long flags, req_id;
2535 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2537 sbale = &sbal->element[idx];
2538 req_id = (unsigned long) sbale->addr;
2539 spin_lock_irqsave(&adapter->req_list_lock, flags);
2540 fsf_req = zfcp_reqlist_find(adapter, req_id);
2544 * Unknown request means that we have potentially memory
2545 * corruption and must stop the machine immediately.
2547 panic("error: unknown req_id (%lx) on adapter %s.\n",
2548 req_id, dev_name(&adapter->ccw_device->dev));
2550 list_del(&fsf_req->list);
2551 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
2553 fsf_req->queue_req.sbal_response = sbal_idx;
2554 fsf_req->queue_req.qdio_inb_usage =
2555 atomic_read(&qdio->resp_q.count);
2556 zfcp_fsf_req_complete(fsf_req);
2558 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))