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 <scsi/fc/fc_els.h>
17 #include "zfcp_reqlist.h"
19 static void zfcp_fsf_request_timeout_handler(unsigned long data)
21 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
22 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
26 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
27 unsigned long timeout)
29 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
30 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
31 fsf_req->timer.expires = jiffies + timeout;
32 add_timer(&fsf_req->timer);
35 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
37 BUG_ON(!fsf_req->erp_action);
38 fsf_req->timer.function = zfcp_erp_timeout_handler;
39 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
40 fsf_req->timer.expires = jiffies + 30 * HZ;
41 add_timer(&fsf_req->timer);
44 /* association between FSF command and FSF QTCB type */
45 static u32 fsf_qtcb_type[] = {
46 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
47 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
56 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
57 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
61 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
63 u16 subtable = table >> 16;
64 u16 rule = table & 0xffff;
65 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
67 if (subtable && subtable < ARRAY_SIZE(act_type))
68 dev_warn(&adapter->ccw_device->dev,
69 "Access denied according to ACT rule type %s, "
70 "rule %d\n", act_type[subtable], rule);
73 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
74 struct zfcp_port *port)
76 struct fsf_qtcb_header *header = &req->qtcb->header;
77 dev_warn(&req->adapter->ccw_device->dev,
78 "Access denied to port 0x%016Lx\n",
79 (unsigned long long)port->wwpn);
80 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
81 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
82 zfcp_erp_port_access_denied(port, "fspad_1", req);
83 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
86 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
87 struct zfcp_unit *unit)
89 struct fsf_qtcb_header *header = &req->qtcb->header;
90 dev_warn(&req->adapter->ccw_device->dev,
91 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
92 (unsigned long long)unit->fcp_lun,
93 (unsigned long long)unit->port->wwpn);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
95 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
96 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
97 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
100 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
102 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
103 "operational because of an unsupported FC class\n");
104 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
105 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
109 * zfcp_fsf_req_free - free memory used by fsf request
110 * @fsf_req: pointer to struct zfcp_fsf_req
112 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
114 if (likely(req->pool)) {
115 if (likely(req->qtcb))
116 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
117 mempool_free(req, req->pool);
121 if (likely(req->qtcb))
122 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
126 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
129 struct fsf_status_read_buffer *sr_buf = req->data;
130 struct zfcp_adapter *adapter = req->adapter;
131 struct zfcp_port *port;
132 int d_id = ntoh24(sr_buf->d_id);
134 read_lock_irqsave(&adapter->port_list_lock, flags);
135 list_for_each_entry(port, &adapter->port_list, list)
136 if (port->d_id == d_id) {
137 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
140 read_unlock_irqrestore(&adapter->port_list_lock, flags);
143 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
144 struct fsf_link_down_info *link_down)
146 struct zfcp_adapter *adapter = req->adapter;
148 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
151 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
153 zfcp_scsi_schedule_rports_block(adapter);
158 switch (link_down->error_code) {
159 case FSF_PSQ_LINK_NO_LIGHT:
160 dev_warn(&req->adapter->ccw_device->dev,
161 "There is no light signal from the local "
162 "fibre channel cable\n");
164 case FSF_PSQ_LINK_WRAP_PLUG:
165 dev_warn(&req->adapter->ccw_device->dev,
166 "There is a wrap plug instead of a fibre "
169 case FSF_PSQ_LINK_NO_FCP:
170 dev_warn(&req->adapter->ccw_device->dev,
171 "The adjacent fibre channel node does not "
174 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
175 dev_warn(&req->adapter->ccw_device->dev,
176 "The FCP device is suspended because of a "
177 "firmware update\n");
179 case FSF_PSQ_LINK_INVALID_WWPN:
180 dev_warn(&req->adapter->ccw_device->dev,
181 "The FCP device detected a WWPN that is "
182 "duplicate or not valid\n");
184 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
185 dev_warn(&req->adapter->ccw_device->dev,
186 "The fibre channel fabric does not support NPIV\n");
188 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
189 dev_warn(&req->adapter->ccw_device->dev,
190 "The FCP adapter cannot support more NPIV ports\n");
192 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
193 dev_warn(&req->adapter->ccw_device->dev,
194 "The adjacent switch cannot support "
195 "more NPIV ports\n");
197 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
198 dev_warn(&req->adapter->ccw_device->dev,
199 "The FCP adapter could not log in to the "
200 "fibre channel fabric\n");
202 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
203 dev_warn(&req->adapter->ccw_device->dev,
204 "The WWPN assignment file on the FCP adapter "
205 "has been damaged\n");
207 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
208 dev_warn(&req->adapter->ccw_device->dev,
209 "The mode table on the FCP adapter "
210 "has been damaged\n");
212 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
213 dev_warn(&req->adapter->ccw_device->dev,
214 "All NPIV ports on the FCP adapter have "
218 dev_warn(&req->adapter->ccw_device->dev,
219 "The link between the FCP adapter and "
220 "the FC fabric is down\n");
223 zfcp_erp_adapter_failed(adapter, id, req);
226 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
228 struct fsf_status_read_buffer *sr_buf = req->data;
229 struct fsf_link_down_info *ldi =
230 (struct fsf_link_down_info *) &sr_buf->payload;
232 switch (sr_buf->status_subtype) {
233 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
234 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
236 case FSF_STATUS_READ_SUB_FDISC_FAILED:
237 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
239 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
240 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
244 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
246 struct zfcp_adapter *adapter = req->adapter;
247 struct fsf_status_read_buffer *sr_buf = req->data;
249 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
250 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
251 mempool_free(sr_buf, adapter->pool.status_read_data);
252 zfcp_fsf_req_free(req);
256 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
258 switch (sr_buf->status_type) {
259 case FSF_STATUS_READ_PORT_CLOSED:
260 zfcp_fsf_status_read_port_closed(req);
262 case FSF_STATUS_READ_INCOMING_ELS:
263 zfcp_fc_incoming_els(req);
265 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
267 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
268 dev_warn(&adapter->ccw_device->dev,
269 "The error threshold for checksum statistics "
270 "has been exceeded\n");
271 zfcp_dbf_hba_berr(adapter->dbf, req);
273 case FSF_STATUS_READ_LINK_DOWN:
274 zfcp_fsf_status_read_link_down(req);
276 case FSF_STATUS_READ_LINK_UP:
277 dev_info(&adapter->ccw_device->dev,
278 "The local link has been restored\n");
279 /* All ports should be marked as ready to run again */
280 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
281 ZFCP_STATUS_COMMON_RUNNING,
283 zfcp_erp_adapter_reopen(adapter,
284 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
285 ZFCP_STATUS_COMMON_ERP_FAILED,
288 case FSF_STATUS_READ_NOTIFICATION_LOST:
289 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
290 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
292 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
293 queue_work(adapter->work_queue, &adapter->scan_work);
295 case FSF_STATUS_READ_CFDC_UPDATED:
296 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
298 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
299 adapter->adapter_features = sr_buf->payload.word[0];
303 mempool_free(sr_buf, adapter->pool.status_read_data);
304 zfcp_fsf_req_free(req);
306 atomic_inc(&adapter->stat_miss);
307 queue_work(adapter->work_queue, &adapter->stat_work);
310 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
312 switch (req->qtcb->header.fsf_status_qual.word[0]) {
313 case FSF_SQ_FCP_RSP_AVAILABLE:
314 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
315 case FSF_SQ_NO_RETRY_POSSIBLE:
316 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
318 case FSF_SQ_COMMAND_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;
363 switch (qtcb->prefix.prot_status) {
365 case FSF_PROT_FSF_STATUS_PRESENTED:
367 case FSF_PROT_QTCB_VERSION_ERROR:
368 dev_err(&adapter->ccw_device->dev,
369 "QTCB version 0x%x not supported by FCP adapter "
370 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
371 psq->word[0], psq->word[1]);
372 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
374 case FSF_PROT_ERROR_STATE:
375 case FSF_PROT_SEQ_NUMB_ERROR:
376 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
377 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
379 case FSF_PROT_UNSUPP_QTCB_TYPE:
380 dev_err(&adapter->ccw_device->dev,
381 "The QTCB type is not supported by the FCP adapter\n");
382 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
384 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
385 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
388 case FSF_PROT_DUPLICATE_REQUEST_ID:
389 dev_err(&adapter->ccw_device->dev,
390 "0x%Lx is an ambiguous request identifier\n",
391 (unsigned long long)qtcb->bottom.support.req_handle);
392 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
394 case FSF_PROT_LINK_DOWN:
395 zfcp_fsf_link_down_info_eval(req, "fspse_5",
396 &psq->link_down_info);
397 /* go through reopen to flush pending requests */
398 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
400 case FSF_PROT_REEST_QUEUE:
401 /* All ports should be marked as ready to run again */
402 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
403 ZFCP_STATUS_COMMON_RUNNING,
405 zfcp_erp_adapter_reopen(adapter,
406 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
407 ZFCP_STATUS_COMMON_ERP_FAILED,
411 dev_err(&adapter->ccw_device->dev,
412 "0x%x is not a valid transfer protocol status\n",
413 qtcb->prefix.prot_status);
414 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
416 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
420 * zfcp_fsf_req_complete - process completion of a FSF request
421 * @fsf_req: The FSF request that has been completed.
423 * When a request has been completed either from the FCP adapter,
424 * or it has been dismissed due to a queue shutdown, this function
425 * is called to process the completion status and trigger further
426 * events related to the FSF request.
428 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
430 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
431 zfcp_fsf_status_read_handler(req);
435 del_timer(&req->timer);
436 zfcp_fsf_protstatus_eval(req);
437 zfcp_fsf_fsfstatus_eval(req);
441 zfcp_erp_notify(req->erp_action, 0);
443 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
444 zfcp_fsf_req_free(req);
446 complete(&req->completion);
450 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
451 * @adapter: pointer to struct zfcp_adapter
453 * Never ever call this without shutting down the adapter first.
454 * Otherwise the adapter would continue using and corrupting s390 storage.
455 * Included BUG_ON() call to ensure this is done.
456 * ERP is supposed to be the only user of this function.
458 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
460 struct zfcp_fsf_req *req, *tmp;
461 LIST_HEAD(remove_queue);
463 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
464 zfcp_reqlist_move(adapter->req_list, &remove_queue);
466 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
467 list_del(&req->list);
468 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
469 zfcp_fsf_req_complete(req);
473 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
475 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
476 struct zfcp_adapter *adapter = req->adapter;
477 struct Scsi_Host *shost = adapter->scsi_host;
478 struct fc_els_flogi *nsp, *plogi;
480 /* adjust pointers for missing command code */
481 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
483 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
487 memcpy(req->data, bottom, sizeof(*bottom));
489 fc_host_port_name(shost) = nsp->fl_wwpn;
490 fc_host_node_name(shost) = nsp->fl_wwnn;
491 fc_host_port_id(shost) = ntoh24(bottom->s_id);
492 fc_host_speed(shost) = bottom->fc_link_speed;
493 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
495 adapter->hydra_version = bottom->adapter_type;
496 adapter->timer_ticks = bottom->timer_interval;
498 if (fc_host_permanent_port_name(shost) == -1)
499 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
501 switch (bottom->fc_topology) {
503 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
504 adapter->peer_wwpn = plogi->fl_wwpn;
505 adapter->peer_wwnn = plogi->fl_wwnn;
506 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
508 case FSF_TOPO_FABRIC:
509 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
512 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
515 dev_err(&adapter->ccw_device->dev,
516 "Unknown or unsupported arbitrated loop "
517 "fibre channel topology detected\n");
518 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
525 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
527 struct zfcp_adapter *adapter = req->adapter;
528 struct fsf_qtcb *qtcb = req->qtcb;
529 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
530 struct Scsi_Host *shost = adapter->scsi_host;
532 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
535 adapter->fsf_lic_version = bottom->lic_version;
536 adapter->adapter_features = bottom->adapter_features;
537 adapter->connection_features = bottom->connection_features;
538 adapter->peer_wwpn = 0;
539 adapter->peer_wwnn = 0;
540 adapter->peer_d_id = 0;
542 switch (qtcb->header.fsf_status) {
544 if (zfcp_fsf_exchange_config_evaluate(req))
547 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
548 dev_err(&adapter->ccw_device->dev,
549 "FCP adapter maximum QTCB size (%d bytes) "
551 bottom->max_qtcb_size);
552 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
555 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
558 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
559 fc_host_node_name(shost) = 0;
560 fc_host_port_name(shost) = 0;
561 fc_host_port_id(shost) = 0;
562 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
563 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
564 adapter->hydra_version = 0;
566 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
569 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
570 &qtcb->header.fsf_status_qual.link_down_info);
573 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
577 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
578 adapter->hardware_version = bottom->hardware_version;
579 memcpy(fc_host_serial_number(shost), bottom->serial_number,
580 min(FC_SERIAL_NUMBER_SIZE, 17));
581 EBCASC(fc_host_serial_number(shost),
582 min(FC_SERIAL_NUMBER_SIZE, 17));
585 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
586 dev_err(&adapter->ccw_device->dev,
587 "The FCP adapter only supports newer "
588 "control block versions\n");
589 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
592 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
593 dev_err(&adapter->ccw_device->dev,
594 "The FCP adapter only supports older "
595 "control block versions\n");
596 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
600 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
602 struct zfcp_adapter *adapter = req->adapter;
603 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
604 struct Scsi_Host *shost = adapter->scsi_host;
607 memcpy(req->data, bottom, sizeof(*bottom));
609 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
610 fc_host_permanent_port_name(shost) = bottom->wwpn;
611 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
613 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
614 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
615 fc_host_supported_speeds(shost) = bottom->supported_speed;
616 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
618 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
622 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
624 struct fsf_qtcb *qtcb = req->qtcb;
626 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
629 switch (qtcb->header.fsf_status) {
631 zfcp_fsf_exchange_port_evaluate(req);
633 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
634 zfcp_fsf_exchange_port_evaluate(req);
635 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
636 &qtcb->header.fsf_status_qual.link_down_info);
641 static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
643 struct zfcp_qdio_queue *req_q = &qdio->req_q;
645 spin_lock_bh(&qdio->req_q_lock);
646 if (atomic_read(&req_q->count))
648 spin_unlock_bh(&qdio->req_q_lock);
652 static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
654 struct zfcp_adapter *adapter = qdio->adapter;
657 spin_unlock_bh(&qdio->req_q_lock);
658 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
659 zfcp_fsf_sbal_check(qdio), 5 * HZ);
663 atomic_inc(&qdio->req_q_full);
664 /* assume hanging outbound queue, try queue recovery */
665 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
668 spin_lock_bh(&qdio->req_q_lock);
672 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
674 struct zfcp_fsf_req *req;
677 req = mempool_alloc(pool, GFP_ATOMIC);
679 req = kmalloc(sizeof(*req), GFP_ATOMIC);
684 memset(req, 0, sizeof(*req));
689 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
691 struct fsf_qtcb *qtcb;
694 qtcb = mempool_alloc(pool, GFP_ATOMIC);
696 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
701 memset(qtcb, 0, sizeof(*qtcb));
705 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
706 u32 fsf_cmd, mempool_t *pool)
708 struct qdio_buffer_element *sbale;
709 struct zfcp_qdio_queue *req_q = &qdio->req_q;
710 struct zfcp_adapter *adapter = qdio->adapter;
711 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
714 return ERR_PTR(-ENOMEM);
716 if (adapter->req_no == 0)
719 INIT_LIST_HEAD(&req->list);
720 init_timer(&req->timer);
721 init_completion(&req->completion);
723 req->adapter = adapter;
724 req->fsf_command = fsf_cmd;
725 req->req_id = adapter->req_no;
726 req->queue_req.sbal_number = 1;
727 req->queue_req.sbal_first = req_q->first;
728 req->queue_req.sbal_last = req_q->first;
729 req->queue_req.sbale_curr = 1;
731 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
732 sbale[0].addr = (void *) req->req_id;
733 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
735 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
737 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
739 req->qtcb = zfcp_qtcb_alloc(NULL);
741 if (unlikely(!req->qtcb)) {
742 zfcp_fsf_req_free(req);
743 return ERR_PTR(-ENOMEM);
746 req->seq_no = adapter->fsf_req_seq_no;
747 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
748 req->qtcb->prefix.req_id = req->req_id;
749 req->qtcb->prefix.ulp_info = 26;
750 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
751 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
752 req->qtcb->header.req_handle = req->req_id;
753 req->qtcb->header.fsf_command = req->fsf_command;
754 sbale[1].addr = (void *) req->qtcb;
755 sbale[1].length = sizeof(struct fsf_qtcb);
758 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
759 zfcp_fsf_req_free(req);
760 return ERR_PTR(-EIO);
766 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
768 struct zfcp_adapter *adapter = req->adapter;
769 struct zfcp_qdio *qdio = adapter->qdio;
770 int with_qtcb = (req->qtcb != NULL);
771 int req_id = req->req_id;
773 zfcp_reqlist_add(adapter->req_list, req);
775 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
776 req->issued = get_clock();
777 if (zfcp_qdio_send(qdio, &req->queue_req)) {
778 del_timer(&req->timer);
779 /* lookup request again, list might have changed */
780 zfcp_reqlist_find_rm(adapter->req_list, req_id);
781 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
785 /* Don't increase for unsolicited status */
787 adapter->fsf_req_seq_no++;
794 * zfcp_fsf_status_read - send status read request
795 * @adapter: pointer to struct zfcp_adapter
796 * @req_flags: request flags
797 * Returns: 0 on success, ERROR otherwise
799 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
801 struct zfcp_adapter *adapter = qdio->adapter;
802 struct zfcp_fsf_req *req;
803 struct fsf_status_read_buffer *sr_buf;
804 struct qdio_buffer_element *sbale;
807 spin_lock_bh(&qdio->req_q_lock);
808 if (zfcp_fsf_req_sbal_get(qdio))
811 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
812 adapter->pool.status_read_req);
814 retval = PTR_ERR(req);
818 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
819 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
820 req->queue_req.sbale_curr = 2;
822 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
827 memset(sr_buf, 0, sizeof(*sr_buf));
829 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
830 sbale->addr = (void *) sr_buf;
831 sbale->length = sizeof(*sr_buf);
833 retval = zfcp_fsf_req_send(req);
835 goto failed_req_send;
840 mempool_free(sr_buf, adapter->pool.status_read_data);
842 zfcp_fsf_req_free(req);
843 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
845 spin_unlock_bh(&qdio->req_q_lock);
849 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
851 struct zfcp_unit *unit = req->data;
852 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
854 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
857 switch (req->qtcb->header.fsf_status) {
858 case FSF_PORT_HANDLE_NOT_VALID:
859 if (fsq->word[0] == fsq->word[1]) {
860 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
862 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
865 case FSF_LUN_HANDLE_NOT_VALID:
866 if (fsq->word[0] == fsq->word[1]) {
867 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
868 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
871 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
872 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
875 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
876 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
879 zfcp_erp_unit_boxed(unit, "fsafch4", req);
880 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
882 case FSF_ADAPTER_STATUS_AVAILABLE:
883 switch (fsq->word[0]) {
884 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
885 zfcp_fc_test_link(unit->port);
887 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
888 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
893 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
899 * zfcp_fsf_abort_fcp_command - abort running SCSI command
900 * @old_req_id: unsigned long
901 * @unit: pointer to struct zfcp_unit
902 * Returns: pointer to struct zfcp_fsf_req
905 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
906 struct zfcp_unit *unit)
908 struct qdio_buffer_element *sbale;
909 struct zfcp_fsf_req *req = NULL;
910 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
912 spin_lock_bh(&qdio->req_q_lock);
913 if (zfcp_fsf_req_sbal_get(qdio))
915 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
916 qdio->adapter->pool.scsi_abort);
922 if (unlikely(!(atomic_read(&unit->status) &
923 ZFCP_STATUS_COMMON_UNBLOCKED)))
926 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
927 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
928 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
931 req->handler = zfcp_fsf_abort_fcp_command_handler;
932 req->qtcb->header.lun_handle = unit->handle;
933 req->qtcb->header.port_handle = unit->port->handle;
934 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
936 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
937 if (!zfcp_fsf_req_send(req))
941 zfcp_fsf_req_free(req);
944 spin_unlock_bh(&qdio->req_q_lock);
948 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
950 struct zfcp_adapter *adapter = req->adapter;
951 struct zfcp_fsf_ct_els *ct = req->data;
952 struct fsf_qtcb_header *header = &req->qtcb->header;
954 ct->status = -EINVAL;
956 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
959 switch (header->fsf_status) {
961 zfcp_dbf_san_ct_response(req);
964 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
965 zfcp_fsf_class_not_supp(req);
967 case FSF_ADAPTER_STATUS_AVAILABLE:
968 switch (header->fsf_status_qual.word[0]){
969 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
970 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
971 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
975 case FSF_ACCESS_DENIED:
978 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
980 case FSF_PORT_HANDLE_NOT_VALID:
981 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
983 case FSF_GENERIC_COMMAND_REJECTED:
984 case FSF_PAYLOAD_SIZE_MISMATCH:
985 case FSF_REQUEST_SIZE_TOO_LARGE:
986 case FSF_RESPONSE_SIZE_TOO_LARGE:
987 case FSF_SBAL_MISMATCH:
988 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
994 ct->handler(ct->handler_data);
997 static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
998 struct scatterlist *sg_req,
999 struct scatterlist *sg_resp)
1001 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1002 sbale[2].addr = sg_virt(sg_req);
1003 sbale[2].length = sg_req->length;
1004 sbale[3].addr = sg_virt(sg_resp);
1005 sbale[3].length = sg_resp->length;
1006 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1009 static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1011 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1014 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1015 struct scatterlist *sg_req,
1016 struct scatterlist *sg_resp,
1019 struct zfcp_adapter *adapter = req->adapter;
1020 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
1022 u32 feat = adapter->adapter_features;
1025 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1026 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
1029 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1033 /* use single, unchained SBAL if it can hold the request */
1034 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1035 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1039 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1040 SBAL_FLAGS0_TYPE_WRITE_READ,
1044 req->qtcb->bottom.support.req_buf_length = bytes;
1045 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1047 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1048 SBAL_FLAGS0_TYPE_WRITE_READ,
1049 sg_resp, max_sbals);
1050 req->qtcb->bottom.support.resp_buf_length = bytes;
1057 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1058 struct scatterlist *sg_req,
1059 struct scatterlist *sg_resp,
1060 int max_sbals, unsigned int timeout)
1064 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1068 /* common settings for ct/gs and els requests */
1070 timeout = 255; /* max value accepted by hardware */
1071 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1072 req->qtcb->bottom.support.timeout = timeout;
1073 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1079 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1080 * @ct: pointer to struct zfcp_send_ct with data for request
1081 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1083 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1084 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1085 unsigned int timeout)
1087 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1088 struct zfcp_fsf_req *req;
1091 spin_lock_bh(&qdio->req_q_lock);
1092 if (zfcp_fsf_req_sbal_get(qdio))
1095 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
1102 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1103 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
1104 FSF_MAX_SBALS_PER_REQ, timeout);
1108 req->handler = zfcp_fsf_send_ct_handler;
1109 req->qtcb->header.port_handle = wka_port->handle;
1112 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1114 ret = zfcp_fsf_req_send(req);
1121 zfcp_fsf_req_free(req);
1123 spin_unlock_bh(&qdio->req_q_lock);
1127 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1129 struct zfcp_fsf_ct_els *send_els = req->data;
1130 struct zfcp_port *port = send_els->port;
1131 struct fsf_qtcb_header *header = &req->qtcb->header;
1133 send_els->status = -EINVAL;
1135 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1136 goto skip_fsfstatus;
1138 switch (header->fsf_status) {
1140 zfcp_dbf_san_els_response(req);
1141 send_els->status = 0;
1143 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1144 zfcp_fsf_class_not_supp(req);
1146 case FSF_ADAPTER_STATUS_AVAILABLE:
1147 switch (header->fsf_status_qual.word[0]){
1148 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1149 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1150 case FSF_SQ_RETRY_IF_POSSIBLE:
1151 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1155 case FSF_ELS_COMMAND_REJECTED:
1156 case FSF_PAYLOAD_SIZE_MISMATCH:
1157 case FSF_REQUEST_SIZE_TOO_LARGE:
1158 case FSF_RESPONSE_SIZE_TOO_LARGE:
1160 case FSF_ACCESS_DENIED:
1162 zfcp_fsf_access_denied_port(req, port);
1164 case FSF_SBAL_MISMATCH:
1165 /* should never occure, avoided in zfcp_fsf_send_els */
1168 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1172 if (send_els->handler)
1173 send_els->handler(send_els->handler_data);
1177 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1178 * @els: pointer to struct zfcp_send_els with data for the command
1180 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1181 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1183 struct zfcp_fsf_req *req;
1184 struct zfcp_qdio *qdio = adapter->qdio;
1187 spin_lock_bh(&qdio->req_q_lock);
1188 if (zfcp_fsf_req_sbal_get(qdio))
1191 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
1198 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1199 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
1204 hton24(req->qtcb->bottom.support.d_id, d_id);
1205 req->handler = zfcp_fsf_send_els_handler;
1208 zfcp_dbf_san_els_request(req);
1210 ret = zfcp_fsf_req_send(req);
1217 zfcp_fsf_req_free(req);
1219 spin_unlock_bh(&qdio->req_q_lock);
1223 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1225 struct qdio_buffer_element *sbale;
1226 struct zfcp_fsf_req *req;
1227 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1230 spin_lock_bh(&qdio->req_q_lock);
1231 if (zfcp_fsf_req_sbal_get(qdio))
1234 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1235 qdio->adapter->pool.erp_req);
1238 retval = PTR_ERR(req);
1242 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1243 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1244 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1245 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1247 req->qtcb->bottom.config.feature_selection =
1249 FSF_FEATURE_LUN_SHARING |
1250 FSF_FEATURE_NOTIFICATION_LOST |
1251 FSF_FEATURE_UPDATE_ALERT;
1252 req->erp_action = erp_action;
1253 req->handler = zfcp_fsf_exchange_config_data_handler;
1254 erp_action->fsf_req_id = req->req_id;
1256 zfcp_fsf_start_erp_timer(req);
1257 retval = zfcp_fsf_req_send(req);
1259 zfcp_fsf_req_free(req);
1260 erp_action->fsf_req_id = 0;
1263 spin_unlock_bh(&qdio->req_q_lock);
1267 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1268 struct fsf_qtcb_bottom_config *data)
1270 struct qdio_buffer_element *sbale;
1271 struct zfcp_fsf_req *req = NULL;
1274 spin_lock_bh(&qdio->req_q_lock);
1275 if (zfcp_fsf_req_sbal_get(qdio))
1278 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
1281 retval = PTR_ERR(req);
1285 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1286 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1287 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1288 req->handler = zfcp_fsf_exchange_config_data_handler;
1290 req->qtcb->bottom.config.feature_selection =
1292 FSF_FEATURE_LUN_SHARING |
1293 FSF_FEATURE_NOTIFICATION_LOST |
1294 FSF_FEATURE_UPDATE_ALERT;
1299 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1300 retval = zfcp_fsf_req_send(req);
1301 spin_unlock_bh(&qdio->req_q_lock);
1303 wait_for_completion(&req->completion);
1305 zfcp_fsf_req_free(req);
1309 spin_unlock_bh(&qdio->req_q_lock);
1314 * zfcp_fsf_exchange_port_data - request information about local port
1315 * @erp_action: ERP action for the adapter for which port data is requested
1316 * Returns: 0 on success, error otherwise
1318 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1320 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1321 struct qdio_buffer_element *sbale;
1322 struct zfcp_fsf_req *req;
1325 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1328 spin_lock_bh(&qdio->req_q_lock);
1329 if (zfcp_fsf_req_sbal_get(qdio))
1332 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1333 qdio->adapter->pool.erp_req);
1336 retval = PTR_ERR(req);
1340 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1341 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1342 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1343 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1345 req->handler = zfcp_fsf_exchange_port_data_handler;
1346 req->erp_action = erp_action;
1347 erp_action->fsf_req_id = req->req_id;
1349 zfcp_fsf_start_erp_timer(req);
1350 retval = zfcp_fsf_req_send(req);
1352 zfcp_fsf_req_free(req);
1353 erp_action->fsf_req_id = 0;
1356 spin_unlock_bh(&qdio->req_q_lock);
1361 * zfcp_fsf_exchange_port_data_sync - request information about local port
1362 * @qdio: pointer to struct zfcp_qdio
1363 * @data: pointer to struct fsf_qtcb_bottom_port
1364 * Returns: 0 on success, error otherwise
1366 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1367 struct fsf_qtcb_bottom_port *data)
1369 struct qdio_buffer_element *sbale;
1370 struct zfcp_fsf_req *req = NULL;
1373 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1376 spin_lock_bh(&qdio->req_q_lock);
1377 if (zfcp_fsf_req_sbal_get(qdio))
1380 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
1383 retval = PTR_ERR(req);
1390 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1391 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1392 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1394 req->handler = zfcp_fsf_exchange_port_data_handler;
1395 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1396 retval = zfcp_fsf_req_send(req);
1397 spin_unlock_bh(&qdio->req_q_lock);
1400 wait_for_completion(&req->completion);
1402 zfcp_fsf_req_free(req);
1407 spin_unlock_bh(&qdio->req_q_lock);
1411 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1413 struct zfcp_port *port = req->data;
1414 struct fsf_qtcb_header *header = &req->qtcb->header;
1415 struct fc_els_flogi *plogi;
1417 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1420 switch (header->fsf_status) {
1421 case FSF_PORT_ALREADY_OPEN:
1423 case FSF_ACCESS_DENIED:
1424 zfcp_fsf_access_denied_port(req, port);
1426 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1427 dev_warn(&req->adapter->ccw_device->dev,
1428 "Not enough FCP adapter resources to open "
1429 "remote port 0x%016Lx\n",
1430 (unsigned long long)port->wwpn);
1431 zfcp_erp_port_failed(port, "fsoph_1", req);
1432 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1434 case FSF_ADAPTER_STATUS_AVAILABLE:
1435 switch (header->fsf_status_qual.word[0]) {
1436 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1437 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1438 case FSF_SQ_NO_RETRY_POSSIBLE:
1439 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1444 port->handle = header->port_handle;
1445 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1446 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1447 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1448 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1450 /* check whether D_ID has changed during open */
1452 * FIXME: This check is not airtight, as the FCP channel does
1453 * not monitor closures of target port connections caused on
1454 * the remote side. Thus, they might miss out on invalidating
1455 * locally cached WWPNs (and other N_Port parameters) of gone
1456 * target ports. So, our heroic attempt to make things safe
1457 * could be undermined by 'open port' response data tagged with
1458 * obsolete WWPNs. Another reason to monitor potential
1459 * connection closures ourself at least (by interpreting
1460 * incoming ELS' and unsolicited status). It just crosses my
1461 * mind that one should be able to cross-check by means of
1462 * another GID_PN straight after a port has been opened.
1463 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1465 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1466 if (req->qtcb->bottom.support.els1_length >=
1468 zfcp_fc_plogi_evaluate(port, plogi);
1470 case FSF_UNKNOWN_OP_SUBTYPE:
1471 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1476 put_device(&port->dev);
1480 * zfcp_fsf_open_port - create and send open port request
1481 * @erp_action: pointer to struct zfcp_erp_action
1482 * Returns: 0 on success, error otherwise
1484 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1486 struct qdio_buffer_element *sbale;
1487 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1488 struct zfcp_port *port = erp_action->port;
1489 struct zfcp_fsf_req *req;
1492 spin_lock_bh(&qdio->req_q_lock);
1493 if (zfcp_fsf_req_sbal_get(qdio))
1496 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1497 qdio->adapter->pool.erp_req);
1500 retval = PTR_ERR(req);
1504 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1505 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1506 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1507 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1509 req->handler = zfcp_fsf_open_port_handler;
1510 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1512 req->erp_action = erp_action;
1513 erp_action->fsf_req_id = req->req_id;
1514 get_device(&port->dev);
1516 zfcp_fsf_start_erp_timer(req);
1517 retval = zfcp_fsf_req_send(req);
1519 zfcp_fsf_req_free(req);
1520 erp_action->fsf_req_id = 0;
1521 put_device(&port->dev);
1524 spin_unlock_bh(&qdio->req_q_lock);
1528 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1530 struct zfcp_port *port = req->data;
1532 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1535 switch (req->qtcb->header.fsf_status) {
1536 case FSF_PORT_HANDLE_NOT_VALID:
1537 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1538 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1540 case FSF_ADAPTER_STATUS_AVAILABLE:
1543 zfcp_erp_modify_port_status(port, "fscph_2", req,
1544 ZFCP_STATUS_COMMON_OPEN,
1551 * zfcp_fsf_close_port - create and send close port request
1552 * @erp_action: pointer to struct zfcp_erp_action
1553 * Returns: 0 on success, error otherwise
1555 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1557 struct qdio_buffer_element *sbale;
1558 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1559 struct zfcp_fsf_req *req;
1562 spin_lock_bh(&qdio->req_q_lock);
1563 if (zfcp_fsf_req_sbal_get(qdio))
1566 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1567 qdio->adapter->pool.erp_req);
1570 retval = PTR_ERR(req);
1574 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1575 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1576 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1577 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1579 req->handler = zfcp_fsf_close_port_handler;
1580 req->data = erp_action->port;
1581 req->erp_action = erp_action;
1582 req->qtcb->header.port_handle = erp_action->port->handle;
1583 erp_action->fsf_req_id = req->req_id;
1585 zfcp_fsf_start_erp_timer(req);
1586 retval = zfcp_fsf_req_send(req);
1588 zfcp_fsf_req_free(req);
1589 erp_action->fsf_req_id = 0;
1592 spin_unlock_bh(&qdio->req_q_lock);
1596 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1598 struct zfcp_fc_wka_port *wka_port = req->data;
1599 struct fsf_qtcb_header *header = &req->qtcb->header;
1601 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1602 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1606 switch (header->fsf_status) {
1607 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1608 dev_warn(&req->adapter->ccw_device->dev,
1609 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1611 case FSF_ADAPTER_STATUS_AVAILABLE:
1612 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1614 case FSF_ACCESS_DENIED:
1615 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1618 wka_port->handle = header->port_handle;
1620 case FSF_PORT_ALREADY_OPEN:
1621 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1624 wake_up(&wka_port->completion_wq);
1628 * zfcp_fsf_open_wka_port - create and send open wka-port request
1629 * @wka_port: pointer to struct zfcp_fc_wka_port
1630 * Returns: 0 on success, error otherwise
1632 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1634 struct qdio_buffer_element *sbale;
1635 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1636 struct zfcp_fsf_req *req;
1639 spin_lock_bh(&qdio->req_q_lock);
1640 if (zfcp_fsf_req_sbal_get(qdio))
1643 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1644 qdio->adapter->pool.erp_req);
1646 if (unlikely(IS_ERR(req))) {
1647 retval = PTR_ERR(req);
1651 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1652 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1653 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1654 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1656 req->handler = zfcp_fsf_open_wka_port_handler;
1657 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1658 req->data = wka_port;
1660 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1661 retval = zfcp_fsf_req_send(req);
1663 zfcp_fsf_req_free(req);
1665 spin_unlock_bh(&qdio->req_q_lock);
1669 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1671 struct zfcp_fc_wka_port *wka_port = req->data;
1673 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1674 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1675 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1678 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1679 wake_up(&wka_port->completion_wq);
1683 * zfcp_fsf_close_wka_port - create and send close wka port request
1684 * @wka_port: WKA port to open
1685 * Returns: 0 on success, error otherwise
1687 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1689 struct qdio_buffer_element *sbale;
1690 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1691 struct zfcp_fsf_req *req;
1694 spin_lock_bh(&qdio->req_q_lock);
1695 if (zfcp_fsf_req_sbal_get(qdio))
1698 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1699 qdio->adapter->pool.erp_req);
1701 if (unlikely(IS_ERR(req))) {
1702 retval = PTR_ERR(req);
1706 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1707 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1708 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1709 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1711 req->handler = zfcp_fsf_close_wka_port_handler;
1712 req->data = wka_port;
1713 req->qtcb->header.port_handle = wka_port->handle;
1715 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1716 retval = zfcp_fsf_req_send(req);
1718 zfcp_fsf_req_free(req);
1720 spin_unlock_bh(&qdio->req_q_lock);
1724 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1726 struct zfcp_port *port = req->data;
1727 struct fsf_qtcb_header *header = &req->qtcb->header;
1728 struct zfcp_unit *unit;
1730 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1733 switch (header->fsf_status) {
1734 case FSF_PORT_HANDLE_NOT_VALID:
1735 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1736 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1738 case FSF_ACCESS_DENIED:
1739 zfcp_fsf_access_denied_port(req, port);
1741 case FSF_PORT_BOXED:
1742 /* can't use generic zfcp_erp_modify_port_status because
1743 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1744 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1745 read_lock(&port->unit_list_lock);
1746 list_for_each_entry(unit, &port->unit_list, list)
1747 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1749 read_unlock(&port->unit_list_lock);
1750 zfcp_erp_port_boxed(port, "fscpph2", req);
1751 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1753 case FSF_ADAPTER_STATUS_AVAILABLE:
1754 switch (header->fsf_status_qual.word[0]) {
1755 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1757 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1758 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1763 /* can't use generic zfcp_erp_modify_port_status because
1764 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1766 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1767 read_lock(&port->unit_list_lock);
1768 list_for_each_entry(unit, &port->unit_list, list)
1769 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1771 read_unlock(&port->unit_list_lock);
1777 * zfcp_fsf_close_physical_port - close physical port
1778 * @erp_action: pointer to struct zfcp_erp_action
1779 * Returns: 0 on success
1781 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1783 struct qdio_buffer_element *sbale;
1784 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1785 struct zfcp_fsf_req *req;
1788 spin_lock_bh(&qdio->req_q_lock);
1789 if (zfcp_fsf_req_sbal_get(qdio))
1792 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1793 qdio->adapter->pool.erp_req);
1796 retval = PTR_ERR(req);
1800 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1801 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1802 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1803 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1805 req->data = erp_action->port;
1806 req->qtcb->header.port_handle = erp_action->port->handle;
1807 req->erp_action = erp_action;
1808 req->handler = zfcp_fsf_close_physical_port_handler;
1809 erp_action->fsf_req_id = req->req_id;
1811 zfcp_fsf_start_erp_timer(req);
1812 retval = zfcp_fsf_req_send(req);
1814 zfcp_fsf_req_free(req);
1815 erp_action->fsf_req_id = 0;
1818 spin_unlock_bh(&qdio->req_q_lock);
1822 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1824 struct zfcp_adapter *adapter = req->adapter;
1825 struct zfcp_unit *unit = req->data;
1826 struct fsf_qtcb_header *header = &req->qtcb->header;
1827 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1828 struct fsf_queue_designator *queue_designator =
1829 &header->fsf_status_qual.fsf_queue_designator;
1830 int exclusive, readwrite;
1832 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1835 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1836 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1837 ZFCP_STATUS_UNIT_SHARED |
1838 ZFCP_STATUS_UNIT_READONLY,
1841 switch (header->fsf_status) {
1843 case FSF_PORT_HANDLE_NOT_VALID:
1844 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1846 case FSF_LUN_ALREADY_OPEN:
1848 case FSF_ACCESS_DENIED:
1849 zfcp_fsf_access_denied_unit(req, unit);
1850 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1851 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1853 case FSF_PORT_BOXED:
1854 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1857 case FSF_LUN_SHARING_VIOLATION:
1858 if (header->fsf_status_qual.word[0])
1859 dev_warn(&adapter->ccw_device->dev,
1860 "LUN 0x%Lx on port 0x%Lx is already in "
1861 "use by CSS%d, MIF Image ID %x\n",
1862 (unsigned long long)unit->fcp_lun,
1863 (unsigned long long)unit->port->wwpn,
1864 queue_designator->cssid,
1865 queue_designator->hla);
1867 zfcp_act_eval_err(adapter,
1868 header->fsf_status_qual.word[2]);
1869 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1870 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1871 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1872 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1874 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1875 dev_warn(&adapter->ccw_device->dev,
1876 "No handle is available for LUN "
1877 "0x%016Lx on port 0x%016Lx\n",
1878 (unsigned long long)unit->fcp_lun,
1879 (unsigned long long)unit->port->wwpn);
1880 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1882 case FSF_INVALID_COMMAND_OPTION:
1883 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1885 case FSF_ADAPTER_STATUS_AVAILABLE:
1886 switch (header->fsf_status_qual.word[0]) {
1887 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1888 zfcp_fc_test_link(unit->port);
1890 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1891 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1897 unit->handle = header->lun_handle;
1898 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1900 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1901 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1902 !zfcp_ccw_priv_sch(adapter)) {
1903 exclusive = (bottom->lun_access_info &
1904 FSF_UNIT_ACCESS_EXCLUSIVE);
1905 readwrite = (bottom->lun_access_info &
1906 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1909 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1913 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1915 dev_info(&adapter->ccw_device->dev,
1916 "SCSI device at LUN 0x%016Lx on port "
1917 "0x%016Lx opened read-only\n",
1918 (unsigned long long)unit->fcp_lun,
1919 (unsigned long long)unit->port->wwpn);
1922 if (exclusive && !readwrite) {
1923 dev_err(&adapter->ccw_device->dev,
1924 "Exclusive read-only access not "
1925 "supported (unit 0x%016Lx, "
1927 (unsigned long long)unit->fcp_lun,
1928 (unsigned long long)unit->port->wwpn);
1929 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1930 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1931 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1932 } else if (!exclusive && readwrite) {
1933 dev_err(&adapter->ccw_device->dev,
1934 "Shared read-write access not "
1935 "supported (unit 0x%016Lx, port "
1937 (unsigned long long)unit->fcp_lun,
1938 (unsigned long long)unit->port->wwpn);
1939 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1940 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1941 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1949 * zfcp_fsf_open_unit - open unit
1950 * @erp_action: pointer to struct zfcp_erp_action
1951 * Returns: 0 on success, error otherwise
1953 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1955 struct qdio_buffer_element *sbale;
1956 struct zfcp_adapter *adapter = erp_action->adapter;
1957 struct zfcp_qdio *qdio = adapter->qdio;
1958 struct zfcp_fsf_req *req;
1961 spin_lock_bh(&qdio->req_q_lock);
1962 if (zfcp_fsf_req_sbal_get(qdio))
1965 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1966 adapter->pool.erp_req);
1969 retval = PTR_ERR(req);
1973 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1974 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1975 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1976 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1978 req->qtcb->header.port_handle = erp_action->port->handle;
1979 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1980 req->handler = zfcp_fsf_open_unit_handler;
1981 req->data = erp_action->unit;
1982 req->erp_action = erp_action;
1983 erp_action->fsf_req_id = req->req_id;
1985 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1986 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1988 zfcp_fsf_start_erp_timer(req);
1989 retval = zfcp_fsf_req_send(req);
1991 zfcp_fsf_req_free(req);
1992 erp_action->fsf_req_id = 0;
1995 spin_unlock_bh(&qdio->req_q_lock);
1999 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
2001 struct zfcp_unit *unit = req->data;
2003 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2006 switch (req->qtcb->header.fsf_status) {
2007 case FSF_PORT_HANDLE_NOT_VALID:
2008 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
2009 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2011 case FSF_LUN_HANDLE_NOT_VALID:
2012 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
2013 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2015 case FSF_PORT_BOXED:
2016 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2017 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2019 case FSF_ADAPTER_STATUS_AVAILABLE:
2020 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2021 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2022 zfcp_fc_test_link(unit->port);
2024 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2025 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2030 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2036 * zfcp_fsf_close_unit - close zfcp unit
2037 * @erp_action: pointer to struct zfcp_unit
2038 * Returns: 0 on success, error otherwise
2040 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2042 struct qdio_buffer_element *sbale;
2043 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2044 struct zfcp_fsf_req *req;
2047 spin_lock_bh(&qdio->req_q_lock);
2048 if (zfcp_fsf_req_sbal_get(qdio))
2051 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2052 qdio->adapter->pool.erp_req);
2055 retval = PTR_ERR(req);
2059 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2060 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2061 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2062 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2064 req->qtcb->header.port_handle = erp_action->port->handle;
2065 req->qtcb->header.lun_handle = erp_action->unit->handle;
2066 req->handler = zfcp_fsf_close_unit_handler;
2067 req->data = erp_action->unit;
2068 req->erp_action = erp_action;
2069 erp_action->fsf_req_id = req->req_id;
2071 zfcp_fsf_start_erp_timer(req);
2072 retval = zfcp_fsf_req_send(req);
2074 zfcp_fsf_req_free(req);
2075 erp_action->fsf_req_id = 0;
2078 spin_unlock_bh(&qdio->req_q_lock);
2082 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2084 lat_rec->sum += lat;
2085 lat_rec->min = min(lat_rec->min, lat);
2086 lat_rec->max = max(lat_rec->max, lat);
2089 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2091 struct fsf_qual_latency_info *lat_in;
2092 struct latency_cont *lat = NULL;
2093 struct zfcp_unit *unit = req->unit;
2094 struct zfcp_blk_drv_data blktrc;
2095 int ticks = req->adapter->timer_ticks;
2097 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2100 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2101 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2102 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2103 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2104 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2106 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2107 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2108 blktrc.channel_lat = lat_in->channel_lat * ticks;
2109 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2111 switch (req->qtcb->bottom.io.data_direction) {
2112 case FSF_DATADIR_READ:
2113 lat = &unit->latencies.read;
2115 case FSF_DATADIR_WRITE:
2116 lat = &unit->latencies.write;
2118 case FSF_DATADIR_CMND:
2119 lat = &unit->latencies.cmd;
2124 spin_lock(&unit->latencies.lock);
2125 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2126 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2128 spin_unlock(&unit->latencies.lock);
2132 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2136 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2138 struct scsi_cmnd *scpnt;
2139 struct fcp_resp_with_ext *fcp_rsp;
2140 unsigned long flags;
2142 read_lock_irqsave(&req->adapter->abort_lock, flags);
2145 if (unlikely(!scpnt)) {
2146 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2150 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2151 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2152 goto skip_fsfstatus;
2155 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2156 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2158 zfcp_fsf_req_trace(req, scpnt);
2161 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
2163 scpnt->host_scribble = NULL;
2164 (scpnt->scsi_done) (scpnt);
2166 * We must hold this lock until scsi_done has been called.
2167 * Otherwise we may call scsi_done after abort regarding this
2168 * command has completed.
2169 * Note: scsi_done must not block!
2171 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2174 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2176 struct fcp_resp_with_ext *fcp_rsp;
2177 struct fcp_resp_rsp_info *rsp_info;
2179 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2180 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2182 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2183 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2184 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2188 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2190 struct zfcp_unit *unit;
2191 struct fsf_qtcb_header *header = &req->qtcb->header;
2193 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2198 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2199 goto skip_fsfstatus;
2201 switch (header->fsf_status) {
2202 case FSF_HANDLE_MISMATCH:
2203 case FSF_PORT_HANDLE_NOT_VALID:
2204 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2205 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2207 case FSF_FCPLUN_NOT_VALID:
2208 case FSF_LUN_HANDLE_NOT_VALID:
2209 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2210 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2212 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2213 zfcp_fsf_class_not_supp(req);
2215 case FSF_ACCESS_DENIED:
2216 zfcp_fsf_access_denied_unit(req, unit);
2218 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2219 dev_err(&req->adapter->ccw_device->dev,
2220 "Incorrect direction %d, unit 0x%016Lx on port "
2221 "0x%016Lx closed\n",
2222 req->qtcb->bottom.io.data_direction,
2223 (unsigned long long)unit->fcp_lun,
2224 (unsigned long long)unit->port->wwpn);
2225 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2227 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2229 case FSF_CMND_LENGTH_NOT_VALID:
2230 dev_err(&req->adapter->ccw_device->dev,
2231 "Incorrect CDB length %d, unit 0x%016Lx on "
2232 "port 0x%016Lx closed\n",
2233 req->qtcb->bottom.io.fcp_cmnd_length,
2234 (unsigned long long)unit->fcp_lun,
2235 (unsigned long long)unit->port->wwpn);
2236 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2238 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2240 case FSF_PORT_BOXED:
2241 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2242 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2245 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2246 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2248 case FSF_ADAPTER_STATUS_AVAILABLE:
2249 if (header->fsf_status_qual.word[0] ==
2250 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2251 zfcp_fc_test_link(unit->port);
2252 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2256 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2257 zfcp_fsf_send_fcp_ctm_handler(req);
2259 zfcp_fsf_send_fcp_command_task_handler(req);
2261 put_device(&unit->dev);
2266 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2267 * @unit: unit where command is sent to
2268 * @scsi_cmnd: scsi command to be sent
2270 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2271 struct scsi_cmnd *scsi_cmnd)
2273 struct zfcp_fsf_req *req;
2274 struct fcp_cmnd *fcp_cmnd;
2275 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2276 int real_bytes, retval = -EIO;
2277 struct zfcp_adapter *adapter = unit->port->adapter;
2278 struct zfcp_qdio *qdio = adapter->qdio;
2280 if (unlikely(!(atomic_read(&unit->status) &
2281 ZFCP_STATUS_COMMON_UNBLOCKED)))
2284 spin_lock(&qdio->req_q_lock);
2285 if (atomic_read(&qdio->req_q.count) <= 0) {
2286 atomic_inc(&qdio->req_q_full);
2290 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2291 adapter->pool.scsi_req);
2294 retval = PTR_ERR(req);
2298 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2299 get_device(&unit->dev);
2301 req->data = scsi_cmnd;
2302 req->handler = zfcp_fsf_send_fcp_command_handler;
2303 req->qtcb->header.lun_handle = unit->handle;
2304 req->qtcb->header.port_handle = unit->port->handle;
2305 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2306 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2308 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2311 * set depending on data direction:
2312 * data direction bits in SBALE (SB Type)
2313 * data direction bits in QTCB
2315 switch (scsi_cmnd->sc_data_direction) {
2317 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2319 case DMA_FROM_DEVICE:
2320 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2323 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2324 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2326 case DMA_BIDIRECTIONAL:
2327 goto failed_scsi_cmnd;
2330 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2331 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2333 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
2334 scsi_sglist(scsi_cmnd),
2335 FSF_MAX_SBALS_PER_REQ);
2336 if (unlikely(real_bytes < 0)) {
2337 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2338 dev_err(&adapter->ccw_device->dev,
2339 "Oversize data package, unit 0x%016Lx "
2340 "on port 0x%016Lx closed\n",
2341 (unsigned long long)unit->fcp_lun,
2342 (unsigned long long)unit->port->wwpn);
2343 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
2346 goto failed_scsi_cmnd;
2349 retval = zfcp_fsf_req_send(req);
2350 if (unlikely(retval))
2351 goto failed_scsi_cmnd;
2356 put_device(&unit->dev);
2357 zfcp_fsf_req_free(req);
2358 scsi_cmnd->host_scribble = NULL;
2360 spin_unlock(&qdio->req_q_lock);
2365 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2366 * @unit: pointer to struct zfcp_unit
2367 * @tm_flags: unsigned byte for task management flags
2368 * Returns: on success pointer to struct fsf_req, NULL otherwise
2370 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2372 struct qdio_buffer_element *sbale;
2373 struct zfcp_fsf_req *req = NULL;
2374 struct fcp_cmnd *fcp_cmnd;
2375 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2377 if (unlikely(!(atomic_read(&unit->status) &
2378 ZFCP_STATUS_COMMON_UNBLOCKED)))
2381 spin_lock_bh(&qdio->req_q_lock);
2382 if (zfcp_fsf_req_sbal_get(qdio))
2385 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2386 qdio->adapter->pool.scsi_req);
2393 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2395 req->handler = zfcp_fsf_send_fcp_command_handler;
2396 req->qtcb->header.lun_handle = unit->handle;
2397 req->qtcb->header.port_handle = unit->port->handle;
2398 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2399 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2400 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2402 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2403 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2404 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2406 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2407 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2409 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2410 if (!zfcp_fsf_req_send(req))
2413 zfcp_fsf_req_free(req);
2416 spin_unlock_bh(&qdio->req_q_lock);
2420 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2425 * zfcp_fsf_control_file - control file upload/download
2426 * @adapter: pointer to struct zfcp_adapter
2427 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2428 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2430 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2431 struct zfcp_fsf_cfdc *fsf_cfdc)
2433 struct qdio_buffer_element *sbale;
2434 struct zfcp_qdio *qdio = adapter->qdio;
2435 struct zfcp_fsf_req *req = NULL;
2436 struct fsf_qtcb_bottom_support *bottom;
2437 int direction, retval = -EIO, bytes;
2439 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2440 return ERR_PTR(-EOPNOTSUPP);
2442 switch (fsf_cfdc->command) {
2443 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2444 direction = SBAL_FLAGS0_TYPE_WRITE;
2446 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2447 direction = SBAL_FLAGS0_TYPE_READ;
2450 return ERR_PTR(-EINVAL);
2453 spin_lock_bh(&qdio->req_q_lock);
2454 if (zfcp_fsf_req_sbal_get(qdio))
2457 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
2463 req->handler = zfcp_fsf_control_file_handler;
2465 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2466 sbale[0].flags |= direction;
2468 bottom = &req->qtcb->bottom.support;
2469 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2470 bottom->option = fsf_cfdc->option;
2472 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2473 direction, fsf_cfdc->sg,
2474 FSF_MAX_SBALS_PER_REQ);
2475 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2476 zfcp_fsf_req_free(req);
2480 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2481 retval = zfcp_fsf_req_send(req);
2483 spin_unlock_bh(&qdio->req_q_lock);
2486 wait_for_completion(&req->completion);
2489 return ERR_PTR(retval);
2493 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2494 * @adapter: pointer to struct zfcp_adapter
2495 * @sbal_idx: response queue index of SBAL to be processed
2497 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2499 struct zfcp_adapter *adapter = qdio->adapter;
2500 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
2501 struct qdio_buffer_element *sbale;
2502 struct zfcp_fsf_req *fsf_req;
2503 unsigned long req_id;
2506 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2508 sbale = &sbal->element[idx];
2509 req_id = (unsigned long) sbale->addr;
2510 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2514 * Unknown request means that we have potentially memory
2515 * corruption and must stop the machine immediately.
2517 panic("error: unknown req_id (%lx) on adapter %s.\n",
2518 req_id, dev_name(&adapter->ccw_device->dev));
2520 fsf_req->queue_req.sbal_response = sbal_idx;
2521 fsf_req->queue_req.qdio_inb_usage =
2522 atomic_read(&qdio->resp_q.count);
2523 zfcp_fsf_req_complete(fsf_req);
2525 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))