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:
319 case FSF_SQ_NO_RECOM:
320 dev_err(&req->adapter->ccw_device->dev,
321 "The FCP adapter reported a problem "
322 "that cannot be recovered\n");
323 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
326 /* all non-return stats set FSFREQ_ERROR*/
327 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
330 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
332 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
335 switch (req->qtcb->header.fsf_status) {
336 case FSF_UNKNOWN_COMMAND:
337 dev_err(&req->adapter->ccw_device->dev,
338 "The FCP adapter does not recognize the command 0x%x\n",
339 req->qtcb->header.fsf_command);
340 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
341 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
343 case FSF_ADAPTER_STATUS_AVAILABLE:
344 zfcp_fsf_fsfstatus_qual_eval(req);
349 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
351 struct zfcp_adapter *adapter = req->adapter;
352 struct fsf_qtcb *qtcb = req->qtcb;
353 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
355 zfcp_dbf_hba_fsf_response(req);
357 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
358 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
362 switch (qtcb->prefix.prot_status) {
364 case FSF_PROT_FSF_STATUS_PRESENTED:
366 case FSF_PROT_QTCB_VERSION_ERROR:
367 dev_err(&adapter->ccw_device->dev,
368 "QTCB version 0x%x not supported by FCP adapter "
369 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
370 psq->word[0], psq->word[1]);
371 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
373 case FSF_PROT_ERROR_STATE:
374 case FSF_PROT_SEQ_NUMB_ERROR:
375 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
376 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
378 case FSF_PROT_UNSUPP_QTCB_TYPE:
379 dev_err(&adapter->ccw_device->dev,
380 "The QTCB type is not supported by the FCP adapter\n");
381 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
383 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
384 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
387 case FSF_PROT_DUPLICATE_REQUEST_ID:
388 dev_err(&adapter->ccw_device->dev,
389 "0x%Lx is an ambiguous request identifier\n",
390 (unsigned long long)qtcb->bottom.support.req_handle);
391 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
393 case FSF_PROT_LINK_DOWN:
394 zfcp_fsf_link_down_info_eval(req, "fspse_5",
395 &psq->link_down_info);
396 /* FIXME: reopening adapter now? better wait for link up */
397 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
399 case FSF_PROT_REEST_QUEUE:
400 /* All ports should be marked as ready to run again */
401 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
402 ZFCP_STATUS_COMMON_RUNNING,
404 zfcp_erp_adapter_reopen(adapter,
405 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
406 ZFCP_STATUS_COMMON_ERP_FAILED,
410 dev_err(&adapter->ccw_device->dev,
411 "0x%x is not a valid transfer protocol status\n",
412 qtcb->prefix.prot_status);
413 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
415 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
419 * zfcp_fsf_req_complete - process completion of a FSF request
420 * @fsf_req: The FSF request that has been completed.
422 * When a request has been completed either from the FCP adapter,
423 * or it has been dismissed due to a queue shutdown, this function
424 * is called to process the completion status and trigger further
425 * events related to the FSF request.
427 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
429 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
430 zfcp_fsf_status_read_handler(req);
434 del_timer(&req->timer);
435 zfcp_fsf_protstatus_eval(req);
436 zfcp_fsf_fsfstatus_eval(req);
440 zfcp_erp_notify(req->erp_action, 0);
442 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
443 zfcp_fsf_req_free(req);
445 complete(&req->completion);
449 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
450 * @adapter: pointer to struct zfcp_adapter
452 * Never ever call this without shutting down the adapter first.
453 * Otherwise the adapter would continue using and corrupting s390 storage.
454 * Included BUG_ON() call to ensure this is done.
455 * ERP is supposed to be the only user of this function.
457 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
459 struct zfcp_fsf_req *req, *tmp;
461 LIST_HEAD(remove_queue);
464 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
465 spin_lock_irqsave(&adapter->req_list_lock, flags);
466 for (i = 0; i < REQUEST_LIST_SIZE; i++)
467 list_splice_init(&adapter->req_list[i], &remove_queue);
468 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
470 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
471 list_del(&req->list);
472 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
473 zfcp_fsf_req_complete(req);
477 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
479 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
480 struct zfcp_adapter *adapter = req->adapter;
481 struct Scsi_Host *shost = adapter->scsi_host;
482 struct fc_els_flogi *nsp, *plogi;
484 /* adjust pointers for missing command code */
485 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
487 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
491 memcpy(req->data, bottom, sizeof(*bottom));
493 fc_host_port_name(shost) = nsp->fl_wwpn;
494 fc_host_node_name(shost) = nsp->fl_wwnn;
495 fc_host_port_id(shost) = ntoh24(bottom->s_id);
496 fc_host_speed(shost) = bottom->fc_link_speed;
497 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
498 fc_host_supported_fc4s(shost)[2] = 1; /* FCP */
499 fc_host_active_fc4s(shost)[2] = 1; /* FCP */
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;
890 zfcp_erp_unit_boxed(unit, "fsafch4", req);
891 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
893 case FSF_ADAPTER_STATUS_AVAILABLE:
894 switch (fsq->word[0]) {
895 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
896 zfcp_fc_test_link(unit->port);
898 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
899 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
904 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
910 * zfcp_fsf_abort_fcp_command - abort running SCSI command
911 * @old_req_id: unsigned long
912 * @unit: pointer to struct zfcp_unit
913 * Returns: pointer to struct zfcp_fsf_req
916 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
917 struct zfcp_unit *unit)
919 struct qdio_buffer_element *sbale;
920 struct zfcp_fsf_req *req = NULL;
921 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
923 spin_lock_bh(&qdio->req_q_lock);
924 if (zfcp_fsf_req_sbal_get(qdio))
926 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
927 qdio->adapter->pool.scsi_abort);
933 if (unlikely(!(atomic_read(&unit->status) &
934 ZFCP_STATUS_COMMON_UNBLOCKED)))
937 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
938 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
939 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
942 req->handler = zfcp_fsf_abort_fcp_command_handler;
943 req->qtcb->header.lun_handle = unit->handle;
944 req->qtcb->header.port_handle = unit->port->handle;
945 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
947 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
948 if (!zfcp_fsf_req_send(req))
952 zfcp_fsf_req_free(req);
955 spin_unlock_bh(&qdio->req_q_lock);
959 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
961 struct zfcp_adapter *adapter = req->adapter;
962 struct zfcp_fsf_ct_els *ct = req->data;
963 struct fsf_qtcb_header *header = &req->qtcb->header;
965 ct->status = -EINVAL;
967 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
970 switch (header->fsf_status) {
972 zfcp_dbf_san_ct_response(req);
975 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
976 zfcp_fsf_class_not_supp(req);
978 case FSF_ADAPTER_STATUS_AVAILABLE:
979 switch (header->fsf_status_qual.word[0]){
980 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
981 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
982 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
986 case FSF_ACCESS_DENIED:
989 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
991 case FSF_PORT_HANDLE_NOT_VALID:
992 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
994 case FSF_GENERIC_COMMAND_REJECTED:
995 case FSF_PAYLOAD_SIZE_MISMATCH:
996 case FSF_REQUEST_SIZE_TOO_LARGE:
997 case FSF_RESPONSE_SIZE_TOO_LARGE:
998 case FSF_SBAL_MISMATCH:
999 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1005 ct->handler(ct->handler_data);
1008 static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
1009 struct scatterlist *sg_req,
1010 struct scatterlist *sg_resp)
1012 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1013 sbale[2].addr = sg_virt(sg_req);
1014 sbale[2].length = sg_req->length;
1015 sbale[3].addr = sg_virt(sg_resp);
1016 sbale[3].length = sg_resp->length;
1017 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1020 static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1022 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1025 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1026 struct scatterlist *sg_req,
1027 struct scatterlist *sg_resp,
1030 struct zfcp_adapter *adapter = req->adapter;
1031 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
1033 u32 feat = adapter->adapter_features;
1036 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1037 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
1040 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1044 /* use single, unchained SBAL if it can hold the request */
1045 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1046 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1050 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1051 SBAL_FLAGS0_TYPE_WRITE_READ,
1055 req->qtcb->bottom.support.req_buf_length = bytes;
1056 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1058 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1059 SBAL_FLAGS0_TYPE_WRITE_READ,
1060 sg_resp, max_sbals);
1061 req->qtcb->bottom.support.resp_buf_length = bytes;
1068 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1069 struct scatterlist *sg_req,
1070 struct scatterlist *sg_resp,
1071 int max_sbals, unsigned int timeout)
1075 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1079 /* common settings for ct/gs and els requests */
1081 timeout = 255; /* max value accepted by hardware */
1082 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1083 req->qtcb->bottom.support.timeout = timeout;
1084 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1090 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1091 * @ct: pointer to struct zfcp_send_ct with data for request
1092 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1094 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1095 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1096 unsigned int timeout)
1098 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1099 struct zfcp_fsf_req *req;
1102 spin_lock_bh(&qdio->req_q_lock);
1103 if (zfcp_fsf_req_sbal_get(qdio))
1106 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
1113 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1114 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
1115 FSF_MAX_SBALS_PER_REQ, timeout);
1119 req->handler = zfcp_fsf_send_ct_handler;
1120 req->qtcb->header.port_handle = wka_port->handle;
1123 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1125 ret = zfcp_fsf_req_send(req);
1132 zfcp_fsf_req_free(req);
1134 spin_unlock_bh(&qdio->req_q_lock);
1138 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1140 struct zfcp_fsf_ct_els *send_els = req->data;
1141 struct zfcp_port *port = send_els->port;
1142 struct fsf_qtcb_header *header = &req->qtcb->header;
1144 send_els->status = -EINVAL;
1146 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1147 goto skip_fsfstatus;
1149 switch (header->fsf_status) {
1151 zfcp_dbf_san_els_response(req);
1152 send_els->status = 0;
1154 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1155 zfcp_fsf_class_not_supp(req);
1157 case FSF_ADAPTER_STATUS_AVAILABLE:
1158 switch (header->fsf_status_qual.word[0]){
1159 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1160 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1161 case FSF_SQ_RETRY_IF_POSSIBLE:
1162 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1166 case FSF_ELS_COMMAND_REJECTED:
1167 case FSF_PAYLOAD_SIZE_MISMATCH:
1168 case FSF_REQUEST_SIZE_TOO_LARGE:
1169 case FSF_RESPONSE_SIZE_TOO_LARGE:
1171 case FSF_ACCESS_DENIED:
1173 zfcp_fsf_access_denied_port(req, port);
1175 case FSF_SBAL_MISMATCH:
1176 /* should never occure, avoided in zfcp_fsf_send_els */
1179 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1183 if (send_els->handler)
1184 send_els->handler(send_els->handler_data);
1188 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1189 * @els: pointer to struct zfcp_send_els with data for the command
1191 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1192 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1194 struct zfcp_fsf_req *req;
1195 struct zfcp_qdio *qdio = adapter->qdio;
1198 spin_lock_bh(&qdio->req_q_lock);
1199 if (zfcp_fsf_req_sbal_get(qdio))
1202 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
1209 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1210 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
1215 hton24(req->qtcb->bottom.support.d_id, d_id);
1216 req->handler = zfcp_fsf_send_els_handler;
1219 zfcp_dbf_san_els_request(req);
1221 ret = zfcp_fsf_req_send(req);
1228 zfcp_fsf_req_free(req);
1230 spin_unlock_bh(&qdio->req_q_lock);
1234 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1236 struct qdio_buffer_element *sbale;
1237 struct zfcp_fsf_req *req;
1238 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1241 spin_lock_bh(&qdio->req_q_lock);
1242 if (zfcp_fsf_req_sbal_get(qdio))
1245 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1246 qdio->adapter->pool.erp_req);
1249 retval = PTR_ERR(req);
1253 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1254 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1255 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1256 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1258 req->qtcb->bottom.config.feature_selection =
1260 FSF_FEATURE_LUN_SHARING |
1261 FSF_FEATURE_NOTIFICATION_LOST |
1262 FSF_FEATURE_UPDATE_ALERT;
1263 req->erp_action = erp_action;
1264 req->handler = zfcp_fsf_exchange_config_data_handler;
1265 erp_action->fsf_req = req;
1267 zfcp_fsf_start_erp_timer(req);
1268 retval = zfcp_fsf_req_send(req);
1270 zfcp_fsf_req_free(req);
1271 erp_action->fsf_req = NULL;
1274 spin_unlock_bh(&qdio->req_q_lock);
1278 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1279 struct fsf_qtcb_bottom_config *data)
1281 struct qdio_buffer_element *sbale;
1282 struct zfcp_fsf_req *req = NULL;
1285 spin_lock_bh(&qdio->req_q_lock);
1286 if (zfcp_fsf_req_sbal_get(qdio))
1289 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
1292 retval = PTR_ERR(req);
1296 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1297 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1298 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1299 req->handler = zfcp_fsf_exchange_config_data_handler;
1301 req->qtcb->bottom.config.feature_selection =
1303 FSF_FEATURE_LUN_SHARING |
1304 FSF_FEATURE_NOTIFICATION_LOST |
1305 FSF_FEATURE_UPDATE_ALERT;
1310 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1311 retval = zfcp_fsf_req_send(req);
1312 spin_unlock_bh(&qdio->req_q_lock);
1314 wait_for_completion(&req->completion);
1316 zfcp_fsf_req_free(req);
1320 spin_unlock_bh(&qdio->req_q_lock);
1325 * zfcp_fsf_exchange_port_data - request information about local port
1326 * @erp_action: ERP action for the adapter for which port data is requested
1327 * Returns: 0 on success, error otherwise
1329 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1331 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1332 struct qdio_buffer_element *sbale;
1333 struct zfcp_fsf_req *req;
1336 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1339 spin_lock_bh(&qdio->req_q_lock);
1340 if (zfcp_fsf_req_sbal_get(qdio))
1343 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1344 qdio->adapter->pool.erp_req);
1347 retval = PTR_ERR(req);
1351 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1352 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1353 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1354 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1356 req->handler = zfcp_fsf_exchange_port_data_handler;
1357 req->erp_action = erp_action;
1358 erp_action->fsf_req = req;
1360 zfcp_fsf_start_erp_timer(req);
1361 retval = zfcp_fsf_req_send(req);
1363 zfcp_fsf_req_free(req);
1364 erp_action->fsf_req = NULL;
1367 spin_unlock_bh(&qdio->req_q_lock);
1372 * zfcp_fsf_exchange_port_data_sync - request information about local port
1373 * @qdio: pointer to struct zfcp_qdio
1374 * @data: pointer to struct fsf_qtcb_bottom_port
1375 * Returns: 0 on success, error otherwise
1377 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1378 struct fsf_qtcb_bottom_port *data)
1380 struct qdio_buffer_element *sbale;
1381 struct zfcp_fsf_req *req = NULL;
1384 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1387 spin_lock_bh(&qdio->req_q_lock);
1388 if (zfcp_fsf_req_sbal_get(qdio))
1391 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
1394 retval = PTR_ERR(req);
1401 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1402 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1403 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1405 req->handler = zfcp_fsf_exchange_port_data_handler;
1406 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1407 retval = zfcp_fsf_req_send(req);
1408 spin_unlock_bh(&qdio->req_q_lock);
1411 wait_for_completion(&req->completion);
1413 zfcp_fsf_req_free(req);
1418 spin_unlock_bh(&qdio->req_q_lock);
1422 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1424 struct zfcp_port *port = req->data;
1425 struct fsf_qtcb_header *header = &req->qtcb->header;
1426 struct fc_els_flogi *plogi;
1428 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1431 switch (header->fsf_status) {
1432 case FSF_PORT_ALREADY_OPEN:
1434 case FSF_ACCESS_DENIED:
1435 zfcp_fsf_access_denied_port(req, port);
1437 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1438 dev_warn(&req->adapter->ccw_device->dev,
1439 "Not enough FCP adapter resources to open "
1440 "remote port 0x%016Lx\n",
1441 (unsigned long long)port->wwpn);
1442 zfcp_erp_port_failed(port, "fsoph_1", req);
1443 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1445 case FSF_ADAPTER_STATUS_AVAILABLE:
1446 switch (header->fsf_status_qual.word[0]) {
1447 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1448 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1449 case FSF_SQ_NO_RETRY_POSSIBLE:
1450 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1455 port->handle = header->port_handle;
1456 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1457 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1458 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1459 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1461 /* check whether D_ID has changed during open */
1463 * FIXME: This check is not airtight, as the FCP channel does
1464 * not monitor closures of target port connections caused on
1465 * the remote side. Thus, they might miss out on invalidating
1466 * locally cached WWPNs (and other N_Port parameters) of gone
1467 * target ports. So, our heroic attempt to make things safe
1468 * could be undermined by 'open port' response data tagged with
1469 * obsolete WWPNs. Another reason to monitor potential
1470 * connection closures ourself at least (by interpreting
1471 * incoming ELS' and unsolicited status). It just crosses my
1472 * mind that one should be able to cross-check by means of
1473 * another GID_PN straight after a port has been opened.
1474 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1476 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1477 if (req->qtcb->bottom.support.els1_length >=
1479 zfcp_fc_plogi_evaluate(port, plogi);
1481 case FSF_UNKNOWN_OP_SUBTYPE:
1482 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1487 put_device(&port->sysfs_device);
1491 * zfcp_fsf_open_port - create and send open port request
1492 * @erp_action: pointer to struct zfcp_erp_action
1493 * Returns: 0 on success, error otherwise
1495 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1497 struct qdio_buffer_element *sbale;
1498 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1499 struct zfcp_port *port = erp_action->port;
1500 struct zfcp_fsf_req *req;
1503 spin_lock_bh(&qdio->req_q_lock);
1504 if (zfcp_fsf_req_sbal_get(qdio))
1507 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1508 qdio->adapter->pool.erp_req);
1511 retval = PTR_ERR(req);
1515 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1516 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1517 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1518 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1520 req->handler = zfcp_fsf_open_port_handler;
1521 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1523 req->erp_action = erp_action;
1524 erp_action->fsf_req = req;
1525 get_device(&port->sysfs_device);
1527 zfcp_fsf_start_erp_timer(req);
1528 retval = zfcp_fsf_req_send(req);
1530 zfcp_fsf_req_free(req);
1531 erp_action->fsf_req = NULL;
1532 put_device(&port->sysfs_device);
1535 spin_unlock_bh(&qdio->req_q_lock);
1539 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1541 struct zfcp_port *port = req->data;
1543 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1546 switch (req->qtcb->header.fsf_status) {
1547 case FSF_PORT_HANDLE_NOT_VALID:
1548 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1549 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1551 case FSF_ADAPTER_STATUS_AVAILABLE:
1554 zfcp_erp_modify_port_status(port, "fscph_2", req,
1555 ZFCP_STATUS_COMMON_OPEN,
1562 * zfcp_fsf_close_port - create and send close port request
1563 * @erp_action: pointer to struct zfcp_erp_action
1564 * Returns: 0 on success, error otherwise
1566 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1568 struct qdio_buffer_element *sbale;
1569 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1570 struct zfcp_fsf_req *req;
1573 spin_lock_bh(&qdio->req_q_lock);
1574 if (zfcp_fsf_req_sbal_get(qdio))
1577 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1578 qdio->adapter->pool.erp_req);
1581 retval = PTR_ERR(req);
1585 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1586 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1587 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1588 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1590 req->handler = zfcp_fsf_close_port_handler;
1591 req->data = erp_action->port;
1592 req->erp_action = erp_action;
1593 req->qtcb->header.port_handle = erp_action->port->handle;
1594 erp_action->fsf_req = req;
1596 zfcp_fsf_start_erp_timer(req);
1597 retval = zfcp_fsf_req_send(req);
1599 zfcp_fsf_req_free(req);
1600 erp_action->fsf_req = NULL;
1603 spin_unlock_bh(&qdio->req_q_lock);
1607 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1609 struct zfcp_fc_wka_port *wka_port = req->data;
1610 struct fsf_qtcb_header *header = &req->qtcb->header;
1612 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1613 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1617 switch (header->fsf_status) {
1618 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1619 dev_warn(&req->adapter->ccw_device->dev,
1620 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1622 case FSF_ADAPTER_STATUS_AVAILABLE:
1623 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1625 case FSF_ACCESS_DENIED:
1626 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1629 wka_port->handle = header->port_handle;
1631 case FSF_PORT_ALREADY_OPEN:
1632 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1635 wake_up(&wka_port->completion_wq);
1639 * zfcp_fsf_open_wka_port - create and send open wka-port request
1640 * @wka_port: pointer to struct zfcp_fc_wka_port
1641 * Returns: 0 on success, error otherwise
1643 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1645 struct qdio_buffer_element *sbale;
1646 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1647 struct zfcp_fsf_req *req;
1650 spin_lock_bh(&qdio->req_q_lock);
1651 if (zfcp_fsf_req_sbal_get(qdio))
1654 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1655 qdio->adapter->pool.erp_req);
1657 if (unlikely(IS_ERR(req))) {
1658 retval = PTR_ERR(req);
1662 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1663 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1664 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1665 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1667 req->handler = zfcp_fsf_open_wka_port_handler;
1668 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1669 req->data = wka_port;
1671 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1672 retval = zfcp_fsf_req_send(req);
1674 zfcp_fsf_req_free(req);
1676 spin_unlock_bh(&qdio->req_q_lock);
1680 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1682 struct zfcp_fc_wka_port *wka_port = req->data;
1684 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1685 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1686 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1689 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1690 wake_up(&wka_port->completion_wq);
1694 * zfcp_fsf_close_wka_port - create and send close wka port request
1695 * @wka_port: WKA port to open
1696 * Returns: 0 on success, error otherwise
1698 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1700 struct qdio_buffer_element *sbale;
1701 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1702 struct zfcp_fsf_req *req;
1705 spin_lock_bh(&qdio->req_q_lock);
1706 if (zfcp_fsf_req_sbal_get(qdio))
1709 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1710 qdio->adapter->pool.erp_req);
1712 if (unlikely(IS_ERR(req))) {
1713 retval = PTR_ERR(req);
1717 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1718 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1719 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1720 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1722 req->handler = zfcp_fsf_close_wka_port_handler;
1723 req->data = wka_port;
1724 req->qtcb->header.port_handle = wka_port->handle;
1726 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1727 retval = zfcp_fsf_req_send(req);
1729 zfcp_fsf_req_free(req);
1731 spin_unlock_bh(&qdio->req_q_lock);
1735 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1737 struct zfcp_port *port = req->data;
1738 struct fsf_qtcb_header *header = &req->qtcb->header;
1739 struct zfcp_unit *unit;
1741 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1744 switch (header->fsf_status) {
1745 case FSF_PORT_HANDLE_NOT_VALID:
1746 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1747 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1749 case FSF_ACCESS_DENIED:
1750 zfcp_fsf_access_denied_port(req, port);
1752 case FSF_PORT_BOXED:
1753 /* can't use generic zfcp_erp_modify_port_status because
1754 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1755 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1756 read_lock(&port->unit_list_lock);
1757 list_for_each_entry(unit, &port->unit_list, list)
1758 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1760 read_unlock(&port->unit_list_lock);
1761 zfcp_erp_port_boxed(port, "fscpph2", req);
1762 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1764 case FSF_ADAPTER_STATUS_AVAILABLE:
1765 switch (header->fsf_status_qual.word[0]) {
1766 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1768 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1769 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1774 /* can't use generic zfcp_erp_modify_port_status because
1775 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1777 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1778 read_lock(&port->unit_list_lock);
1779 list_for_each_entry(unit, &port->unit_list, list)
1780 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1782 read_unlock(&port->unit_list_lock);
1788 * zfcp_fsf_close_physical_port - close physical port
1789 * @erp_action: pointer to struct zfcp_erp_action
1790 * Returns: 0 on success
1792 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1794 struct qdio_buffer_element *sbale;
1795 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1796 struct zfcp_fsf_req *req;
1799 spin_lock_bh(&qdio->req_q_lock);
1800 if (zfcp_fsf_req_sbal_get(qdio))
1803 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1804 qdio->adapter->pool.erp_req);
1807 retval = PTR_ERR(req);
1811 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1812 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1813 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1814 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1816 req->data = erp_action->port;
1817 req->qtcb->header.port_handle = erp_action->port->handle;
1818 req->erp_action = erp_action;
1819 req->handler = zfcp_fsf_close_physical_port_handler;
1820 erp_action->fsf_req = req;
1822 zfcp_fsf_start_erp_timer(req);
1823 retval = zfcp_fsf_req_send(req);
1825 zfcp_fsf_req_free(req);
1826 erp_action->fsf_req = NULL;
1829 spin_unlock_bh(&qdio->req_q_lock);
1833 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1835 struct zfcp_adapter *adapter = req->adapter;
1836 struct zfcp_unit *unit = req->data;
1837 struct fsf_qtcb_header *header = &req->qtcb->header;
1838 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1839 struct fsf_queue_designator *queue_designator =
1840 &header->fsf_status_qual.fsf_queue_designator;
1841 int exclusive, readwrite;
1843 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1846 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1847 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1848 ZFCP_STATUS_UNIT_SHARED |
1849 ZFCP_STATUS_UNIT_READONLY,
1852 switch (header->fsf_status) {
1854 case FSF_PORT_HANDLE_NOT_VALID:
1855 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1857 case FSF_LUN_ALREADY_OPEN:
1859 case FSF_ACCESS_DENIED:
1860 zfcp_fsf_access_denied_unit(req, unit);
1861 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1862 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1864 case FSF_PORT_BOXED:
1865 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1866 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1868 case FSF_LUN_SHARING_VIOLATION:
1869 if (header->fsf_status_qual.word[0])
1870 dev_warn(&adapter->ccw_device->dev,
1871 "LUN 0x%Lx on port 0x%Lx is already in "
1872 "use by CSS%d, MIF Image ID %x\n",
1873 (unsigned long long)unit->fcp_lun,
1874 (unsigned long long)unit->port->wwpn,
1875 queue_designator->cssid,
1876 queue_designator->hla);
1878 zfcp_act_eval_err(adapter,
1879 header->fsf_status_qual.word[2]);
1880 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1881 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1882 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1883 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1885 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1886 dev_warn(&adapter->ccw_device->dev,
1887 "No handle is available for LUN "
1888 "0x%016Lx on port 0x%016Lx\n",
1889 (unsigned long long)unit->fcp_lun,
1890 (unsigned long long)unit->port->wwpn);
1891 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1893 case FSF_INVALID_COMMAND_OPTION:
1894 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1896 case FSF_ADAPTER_STATUS_AVAILABLE:
1897 switch (header->fsf_status_qual.word[0]) {
1898 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1899 zfcp_fc_test_link(unit->port);
1901 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1902 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1908 unit->handle = header->lun_handle;
1909 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1911 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1912 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1913 !zfcp_ccw_priv_sch(adapter)) {
1914 exclusive = (bottom->lun_access_info &
1915 FSF_UNIT_ACCESS_EXCLUSIVE);
1916 readwrite = (bottom->lun_access_info &
1917 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1920 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1924 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1926 dev_info(&adapter->ccw_device->dev,
1927 "SCSI device at LUN 0x%016Lx on port "
1928 "0x%016Lx opened read-only\n",
1929 (unsigned long long)unit->fcp_lun,
1930 (unsigned long long)unit->port->wwpn);
1933 if (exclusive && !readwrite) {
1934 dev_err(&adapter->ccw_device->dev,
1935 "Exclusive read-only access not "
1936 "supported (unit 0x%016Lx, "
1938 (unsigned long long)unit->fcp_lun,
1939 (unsigned long long)unit->port->wwpn);
1940 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1941 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1942 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1943 } else if (!exclusive && readwrite) {
1944 dev_err(&adapter->ccw_device->dev,
1945 "Shared read-write access not "
1946 "supported (unit 0x%016Lx, port "
1948 (unsigned long long)unit->fcp_lun,
1949 (unsigned long long)unit->port->wwpn);
1950 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1951 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1952 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1960 * zfcp_fsf_open_unit - open unit
1961 * @erp_action: pointer to struct zfcp_erp_action
1962 * Returns: 0 on success, error otherwise
1964 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1966 struct qdio_buffer_element *sbale;
1967 struct zfcp_adapter *adapter = erp_action->adapter;
1968 struct zfcp_qdio *qdio = adapter->qdio;
1969 struct zfcp_fsf_req *req;
1972 spin_lock_bh(&qdio->req_q_lock);
1973 if (zfcp_fsf_req_sbal_get(qdio))
1976 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1977 adapter->pool.erp_req);
1980 retval = PTR_ERR(req);
1984 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1985 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1986 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1987 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1989 req->qtcb->header.port_handle = erp_action->port->handle;
1990 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1991 req->handler = zfcp_fsf_open_unit_handler;
1992 req->data = erp_action->unit;
1993 req->erp_action = erp_action;
1994 erp_action->fsf_req = req;
1996 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1997 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1999 zfcp_fsf_start_erp_timer(req);
2000 retval = zfcp_fsf_req_send(req);
2002 zfcp_fsf_req_free(req);
2003 erp_action->fsf_req = NULL;
2006 spin_unlock_bh(&qdio->req_q_lock);
2010 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
2012 struct zfcp_unit *unit = req->data;
2014 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2017 switch (req->qtcb->header.fsf_status) {
2018 case FSF_PORT_HANDLE_NOT_VALID:
2019 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
2020 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2022 case FSF_LUN_HANDLE_NOT_VALID:
2023 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
2024 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2026 case FSF_PORT_BOXED:
2027 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2028 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2030 case FSF_ADAPTER_STATUS_AVAILABLE:
2031 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2032 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2033 zfcp_fc_test_link(unit->port);
2035 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2036 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2041 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2047 * zfcp_fsf_close_unit - close zfcp unit
2048 * @erp_action: pointer to struct zfcp_unit
2049 * Returns: 0 on success, error otherwise
2051 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2053 struct qdio_buffer_element *sbale;
2054 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2055 struct zfcp_fsf_req *req;
2058 spin_lock_bh(&qdio->req_q_lock);
2059 if (zfcp_fsf_req_sbal_get(qdio))
2062 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2063 qdio->adapter->pool.erp_req);
2066 retval = PTR_ERR(req);
2070 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2071 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2072 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2073 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2075 req->qtcb->header.port_handle = erp_action->port->handle;
2076 req->qtcb->header.lun_handle = erp_action->unit->handle;
2077 req->handler = zfcp_fsf_close_unit_handler;
2078 req->data = erp_action->unit;
2079 req->erp_action = erp_action;
2080 erp_action->fsf_req = req;
2082 zfcp_fsf_start_erp_timer(req);
2083 retval = zfcp_fsf_req_send(req);
2085 zfcp_fsf_req_free(req);
2086 erp_action->fsf_req = NULL;
2089 spin_unlock_bh(&qdio->req_q_lock);
2093 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2095 lat_rec->sum += lat;
2096 lat_rec->min = min(lat_rec->min, lat);
2097 lat_rec->max = max(lat_rec->max, lat);
2100 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2102 struct fsf_qual_latency_info *lat_in;
2103 struct latency_cont *lat = NULL;
2104 struct zfcp_unit *unit = req->unit;
2105 struct zfcp_blk_drv_data blktrc;
2106 int ticks = req->adapter->timer_ticks;
2108 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2111 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2112 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2113 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2114 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2115 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2117 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2118 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2119 blktrc.channel_lat = lat_in->channel_lat * ticks;
2120 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2122 switch (req->qtcb->bottom.io.data_direction) {
2123 case FSF_DATADIR_READ:
2124 lat = &unit->latencies.read;
2126 case FSF_DATADIR_WRITE:
2127 lat = &unit->latencies.write;
2129 case FSF_DATADIR_CMND:
2130 lat = &unit->latencies.cmd;
2135 spin_lock(&unit->latencies.lock);
2136 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2137 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2139 spin_unlock(&unit->latencies.lock);
2143 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2147 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2149 struct scsi_cmnd *scpnt;
2150 struct fcp_resp_with_ext *fcp_rsp;
2151 unsigned long flags;
2153 read_lock_irqsave(&req->adapter->abort_lock, flags);
2156 if (unlikely(!scpnt)) {
2157 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2161 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2162 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2163 goto skip_fsfstatus;
2166 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2167 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2169 zfcp_fsf_req_trace(req, scpnt);
2172 if (scpnt->result != 0)
2173 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
2174 else if (scpnt->retries > 0)
2175 zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
2177 zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
2179 scpnt->host_scribble = NULL;
2180 (scpnt->scsi_done) (scpnt);
2182 * We must hold this lock until scsi_done has been called.
2183 * Otherwise we may call scsi_done after abort regarding this
2184 * command has completed.
2185 * Note: scsi_done must not block!
2187 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2190 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2192 struct fcp_resp_with_ext *fcp_rsp;
2193 struct fcp_resp_rsp_info *rsp_info;
2195 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2196 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2198 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2199 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2200 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2204 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2206 struct zfcp_unit *unit;
2207 struct fsf_qtcb_header *header = &req->qtcb->header;
2209 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2214 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2215 goto skip_fsfstatus;
2217 switch (header->fsf_status) {
2218 case FSF_HANDLE_MISMATCH:
2219 case FSF_PORT_HANDLE_NOT_VALID:
2220 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2221 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2223 case FSF_FCPLUN_NOT_VALID:
2224 case FSF_LUN_HANDLE_NOT_VALID:
2225 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2226 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2228 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2229 zfcp_fsf_class_not_supp(req);
2231 case FSF_ACCESS_DENIED:
2232 zfcp_fsf_access_denied_unit(req, unit);
2234 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2235 dev_err(&req->adapter->ccw_device->dev,
2236 "Incorrect direction %d, unit 0x%016Lx on port "
2237 "0x%016Lx closed\n",
2238 req->qtcb->bottom.io.data_direction,
2239 (unsigned long long)unit->fcp_lun,
2240 (unsigned long long)unit->port->wwpn);
2241 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2243 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2245 case FSF_CMND_LENGTH_NOT_VALID:
2246 dev_err(&req->adapter->ccw_device->dev,
2247 "Incorrect CDB length %d, unit 0x%016Lx on "
2248 "port 0x%016Lx closed\n",
2249 req->qtcb->bottom.io.fcp_cmnd_length,
2250 (unsigned long long)unit->fcp_lun,
2251 (unsigned long long)unit->port->wwpn);
2252 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2254 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2256 case FSF_PORT_BOXED:
2257 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2258 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2261 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2262 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2264 case FSF_ADAPTER_STATUS_AVAILABLE:
2265 if (header->fsf_status_qual.word[0] ==
2266 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2267 zfcp_fc_test_link(unit->port);
2268 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2272 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2273 zfcp_fsf_send_fcp_ctm_handler(req);
2275 zfcp_fsf_send_fcp_command_task_handler(req);
2277 put_device(&unit->sysfs_device);
2282 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2283 * @unit: unit where command is sent to
2284 * @scsi_cmnd: scsi command to be sent
2286 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2287 struct scsi_cmnd *scsi_cmnd)
2289 struct zfcp_fsf_req *req;
2290 struct fcp_cmnd *fcp_cmnd;
2291 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2292 int real_bytes, retval = -EIO;
2293 struct zfcp_adapter *adapter = unit->port->adapter;
2294 struct zfcp_qdio *qdio = adapter->qdio;
2296 if (unlikely(!(atomic_read(&unit->status) &
2297 ZFCP_STATUS_COMMON_UNBLOCKED)))
2300 spin_lock(&qdio->req_q_lock);
2301 if (atomic_read(&qdio->req_q.count) <= 0) {
2302 atomic_inc(&qdio->req_q_full);
2306 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2307 adapter->pool.scsi_req);
2310 retval = PTR_ERR(req);
2314 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2315 get_device(&unit->sysfs_device);
2317 req->data = scsi_cmnd;
2318 req->handler = zfcp_fsf_send_fcp_command_handler;
2319 req->qtcb->header.lun_handle = unit->handle;
2320 req->qtcb->header.port_handle = unit->port->handle;
2321 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2322 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2324 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2327 * set depending on data direction:
2328 * data direction bits in SBALE (SB Type)
2329 * data direction bits in QTCB
2331 switch (scsi_cmnd->sc_data_direction) {
2333 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2335 case DMA_FROM_DEVICE:
2336 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2339 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2340 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2342 case DMA_BIDIRECTIONAL:
2343 goto failed_scsi_cmnd;
2346 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2347 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2349 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
2350 scsi_sglist(scsi_cmnd),
2351 FSF_MAX_SBALS_PER_REQ);
2352 if (unlikely(real_bytes < 0)) {
2353 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2354 dev_err(&adapter->ccw_device->dev,
2355 "Oversize data package, unit 0x%016Lx "
2356 "on port 0x%016Lx closed\n",
2357 (unsigned long long)unit->fcp_lun,
2358 (unsigned long long)unit->port->wwpn);
2359 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
2362 goto failed_scsi_cmnd;
2365 retval = zfcp_fsf_req_send(req);
2366 if (unlikely(retval))
2367 goto failed_scsi_cmnd;
2372 put_device(&unit->sysfs_device);
2373 zfcp_fsf_req_free(req);
2374 scsi_cmnd->host_scribble = NULL;
2376 spin_unlock(&qdio->req_q_lock);
2381 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2382 * @unit: pointer to struct zfcp_unit
2383 * @tm_flags: unsigned byte for task management flags
2384 * Returns: on success pointer to struct fsf_req, NULL otherwise
2386 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2388 struct qdio_buffer_element *sbale;
2389 struct zfcp_fsf_req *req = NULL;
2390 struct fcp_cmnd *fcp_cmnd;
2391 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2393 if (unlikely(!(atomic_read(&unit->status) &
2394 ZFCP_STATUS_COMMON_UNBLOCKED)))
2397 spin_lock_bh(&qdio->req_q_lock);
2398 if (zfcp_fsf_req_sbal_get(qdio))
2401 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2402 qdio->adapter->pool.scsi_req);
2409 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2411 req->handler = zfcp_fsf_send_fcp_command_handler;
2412 req->qtcb->header.lun_handle = unit->handle;
2413 req->qtcb->header.port_handle = unit->port->handle;
2414 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2415 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2416 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2418 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2419 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2420 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2422 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2423 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2425 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2426 if (!zfcp_fsf_req_send(req))
2429 zfcp_fsf_req_free(req);
2432 spin_unlock_bh(&qdio->req_q_lock);
2436 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2441 * zfcp_fsf_control_file - control file upload/download
2442 * @adapter: pointer to struct zfcp_adapter
2443 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2444 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2446 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2447 struct zfcp_fsf_cfdc *fsf_cfdc)
2449 struct qdio_buffer_element *sbale;
2450 struct zfcp_qdio *qdio = adapter->qdio;
2451 struct zfcp_fsf_req *req = NULL;
2452 struct fsf_qtcb_bottom_support *bottom;
2453 int direction, retval = -EIO, bytes;
2455 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2456 return ERR_PTR(-EOPNOTSUPP);
2458 switch (fsf_cfdc->command) {
2459 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2460 direction = SBAL_FLAGS0_TYPE_WRITE;
2462 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2463 direction = SBAL_FLAGS0_TYPE_READ;
2466 return ERR_PTR(-EINVAL);
2469 spin_lock_bh(&qdio->req_q_lock);
2470 if (zfcp_fsf_req_sbal_get(qdio))
2473 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
2479 req->handler = zfcp_fsf_control_file_handler;
2481 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2482 sbale[0].flags |= direction;
2484 bottom = &req->qtcb->bottom.support;
2485 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2486 bottom->option = fsf_cfdc->option;
2488 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2489 direction, fsf_cfdc->sg,
2490 FSF_MAX_SBALS_PER_REQ);
2491 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2492 zfcp_fsf_req_free(req);
2496 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2497 retval = zfcp_fsf_req_send(req);
2499 spin_unlock_bh(&qdio->req_q_lock);
2502 wait_for_completion(&req->completion);
2505 return ERR_PTR(retval);
2509 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2510 * @adapter: pointer to struct zfcp_adapter
2511 * @sbal_idx: response queue index of SBAL to be processed
2513 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2515 struct zfcp_adapter *adapter = qdio->adapter;
2516 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
2517 struct qdio_buffer_element *sbale;
2518 struct zfcp_fsf_req *fsf_req;
2519 unsigned long flags, req_id;
2522 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2524 sbale = &sbal->element[idx];
2525 req_id = (unsigned long) sbale->addr;
2526 spin_lock_irqsave(&adapter->req_list_lock, flags);
2527 fsf_req = zfcp_reqlist_find(adapter, req_id);
2531 * Unknown request means that we have potentially memory
2532 * corruption and must stop the machine immediately.
2534 panic("error: unknown req_id (%lx) on adapter %s.\n",
2535 req_id, dev_name(&adapter->ccw_device->dev));
2537 list_del(&fsf_req->list);
2538 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
2540 fsf_req->queue_req.sbal_response = sbal_idx;
2541 fsf_req->queue_req.qdio_inb_usage =
2542 atomic_read(&qdio->resp_q.count);
2543 zfcp_fsf_req_complete(fsf_req);
2545 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))