4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2010
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <linux/slab.h>
14 #include <scsi/fc/fc_els.h>
18 #include "zfcp_qdio.h"
19 #include "zfcp_reqlist.h"
21 static void zfcp_fsf_request_timeout_handler(unsigned long data)
23 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
24 zfcp_qdio_siosl(adapter);
25 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
29 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
30 unsigned long timeout)
32 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
33 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
34 fsf_req->timer.expires = jiffies + timeout;
35 add_timer(&fsf_req->timer);
38 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
40 BUG_ON(!fsf_req->erp_action);
41 fsf_req->timer.function = zfcp_erp_timeout_handler;
42 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
43 fsf_req->timer.expires = jiffies + 30 * HZ;
44 add_timer(&fsf_req->timer);
47 /* association between FSF command and FSF QTCB type */
48 static u32 fsf_qtcb_type[] = {
49 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
50 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
59 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
60 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
64 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
66 u16 subtable = table >> 16;
67 u16 rule = table & 0xffff;
68 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
70 if (subtable && subtable < ARRAY_SIZE(act_type))
71 dev_warn(&adapter->ccw_device->dev,
72 "Access denied according to ACT rule type %s, "
73 "rule %d\n", act_type[subtable], rule);
76 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
77 struct zfcp_port *port)
79 struct fsf_qtcb_header *header = &req->qtcb->header;
80 dev_warn(&req->adapter->ccw_device->dev,
81 "Access denied to port 0x%016Lx\n",
82 (unsigned long long)port->wwpn);
83 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
84 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
85 zfcp_erp_port_access_denied(port, "fspad_1", req);
86 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
89 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
90 struct zfcp_unit *unit)
92 struct fsf_qtcb_header *header = &req->qtcb->header;
93 dev_warn(&req->adapter->ccw_device->dev,
94 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
95 (unsigned long long)unit->fcp_lun,
96 (unsigned long long)unit->port->wwpn);
97 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
98 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
99 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
100 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
103 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
105 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
106 "operational because of an unsupported FC class\n");
107 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
108 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
112 * zfcp_fsf_req_free - free memory used by fsf request
113 * @fsf_req: pointer to struct zfcp_fsf_req
115 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
117 if (likely(req->pool)) {
118 if (likely(req->qtcb))
119 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
120 mempool_free(req, req->pool);
124 if (likely(req->qtcb))
125 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
129 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
132 struct fsf_status_read_buffer *sr_buf = req->data;
133 struct zfcp_adapter *adapter = req->adapter;
134 struct zfcp_port *port;
135 int d_id = ntoh24(sr_buf->d_id);
137 read_lock_irqsave(&adapter->port_list_lock, flags);
138 list_for_each_entry(port, &adapter->port_list, list)
139 if (port->d_id == d_id) {
140 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
143 read_unlock_irqrestore(&adapter->port_list_lock, flags);
146 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
147 struct fsf_link_down_info *link_down)
149 struct zfcp_adapter *adapter = req->adapter;
151 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
154 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
156 zfcp_scsi_schedule_rports_block(adapter);
161 switch (link_down->error_code) {
162 case FSF_PSQ_LINK_NO_LIGHT:
163 dev_warn(&req->adapter->ccw_device->dev,
164 "There is no light signal from the local "
165 "fibre channel cable\n");
167 case FSF_PSQ_LINK_WRAP_PLUG:
168 dev_warn(&req->adapter->ccw_device->dev,
169 "There is a wrap plug instead of a fibre "
172 case FSF_PSQ_LINK_NO_FCP:
173 dev_warn(&req->adapter->ccw_device->dev,
174 "The adjacent fibre channel node does not "
177 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
178 dev_warn(&req->adapter->ccw_device->dev,
179 "The FCP device is suspended because of a "
180 "firmware update\n");
182 case FSF_PSQ_LINK_INVALID_WWPN:
183 dev_warn(&req->adapter->ccw_device->dev,
184 "The FCP device detected a WWPN that is "
185 "duplicate or not valid\n");
187 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
188 dev_warn(&req->adapter->ccw_device->dev,
189 "The fibre channel fabric does not support NPIV\n");
191 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
193 "The FCP adapter cannot support more NPIV ports\n");
195 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
196 dev_warn(&req->adapter->ccw_device->dev,
197 "The adjacent switch cannot support "
198 "more NPIV ports\n");
200 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
201 dev_warn(&req->adapter->ccw_device->dev,
202 "The FCP adapter could not log in to the "
203 "fibre channel fabric\n");
205 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
206 dev_warn(&req->adapter->ccw_device->dev,
207 "The WWPN assignment file on the FCP adapter "
208 "has been damaged\n");
210 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
211 dev_warn(&req->adapter->ccw_device->dev,
212 "The mode table on the FCP adapter "
213 "has been damaged\n");
215 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
216 dev_warn(&req->adapter->ccw_device->dev,
217 "All NPIV ports on the FCP adapter have "
221 dev_warn(&req->adapter->ccw_device->dev,
222 "The link between the FCP adapter and "
223 "the FC fabric is down\n");
226 zfcp_erp_adapter_failed(adapter, id, req);
229 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
231 struct fsf_status_read_buffer *sr_buf = req->data;
232 struct fsf_link_down_info *ldi =
233 (struct fsf_link_down_info *) &sr_buf->payload;
235 switch (sr_buf->status_subtype) {
236 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
237 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
239 case FSF_STATUS_READ_SUB_FDISC_FAILED:
240 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
242 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
243 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
247 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
249 struct zfcp_adapter *adapter = req->adapter;
250 struct fsf_status_read_buffer *sr_buf = req->data;
252 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
253 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
254 mempool_free(sr_buf, adapter->pool.status_read_data);
255 zfcp_fsf_req_free(req);
259 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
261 switch (sr_buf->status_type) {
262 case FSF_STATUS_READ_PORT_CLOSED:
263 zfcp_fsf_status_read_port_closed(req);
265 case FSF_STATUS_READ_INCOMING_ELS:
266 zfcp_fc_incoming_els(req);
268 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
270 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
271 dev_warn(&adapter->ccw_device->dev,
272 "The error threshold for checksum statistics "
273 "has been exceeded\n");
274 zfcp_dbf_hba_berr(adapter->dbf, req);
276 case FSF_STATUS_READ_LINK_DOWN:
277 zfcp_fsf_status_read_link_down(req);
278 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
280 case FSF_STATUS_READ_LINK_UP:
281 dev_info(&adapter->ccw_device->dev,
282 "The local link has been restored\n");
283 /* All ports should be marked as ready to run again */
284 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
285 ZFCP_STATUS_COMMON_RUNNING,
287 zfcp_erp_adapter_reopen(adapter,
288 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
289 ZFCP_STATUS_COMMON_ERP_FAILED,
291 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
294 case FSF_STATUS_READ_NOTIFICATION_LOST:
295 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
296 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
298 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
299 queue_work(adapter->work_queue, &adapter->scan_work);
301 case FSF_STATUS_READ_CFDC_UPDATED:
302 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
304 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
305 adapter->adapter_features = sr_buf->payload.word[0];
309 mempool_free(sr_buf, adapter->pool.status_read_data);
310 zfcp_fsf_req_free(req);
312 atomic_inc(&adapter->stat_miss);
313 queue_work(adapter->work_queue, &adapter->stat_work);
316 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
318 switch (req->qtcb->header.fsf_status_qual.word[0]) {
319 case FSF_SQ_FCP_RSP_AVAILABLE:
320 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
321 case FSF_SQ_NO_RETRY_POSSIBLE:
322 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
324 case FSF_SQ_COMMAND_ABORTED:
326 case FSF_SQ_NO_RECOM:
327 dev_err(&req->adapter->ccw_device->dev,
328 "The FCP adapter reported a problem "
329 "that cannot be recovered\n");
330 zfcp_qdio_siosl(req->adapter);
331 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
334 /* all non-return stats set FSFREQ_ERROR*/
335 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
338 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
340 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
343 switch (req->qtcb->header.fsf_status) {
344 case FSF_UNKNOWN_COMMAND:
345 dev_err(&req->adapter->ccw_device->dev,
346 "The FCP adapter does not recognize the command 0x%x\n",
347 req->qtcb->header.fsf_command);
348 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
349 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
351 case FSF_ADAPTER_STATUS_AVAILABLE:
352 zfcp_fsf_fsfstatus_qual_eval(req);
357 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
359 struct zfcp_adapter *adapter = req->adapter;
360 struct fsf_qtcb *qtcb = req->qtcb;
361 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
363 zfcp_dbf_hba_fsf_response(req);
365 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
366 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
370 switch (qtcb->prefix.prot_status) {
372 case FSF_PROT_FSF_STATUS_PRESENTED:
374 case FSF_PROT_QTCB_VERSION_ERROR:
375 dev_err(&adapter->ccw_device->dev,
376 "QTCB version 0x%x not supported by FCP adapter "
377 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
378 psq->word[0], psq->word[1]);
379 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
381 case FSF_PROT_ERROR_STATE:
382 case FSF_PROT_SEQ_NUMB_ERROR:
383 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
384 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
386 case FSF_PROT_UNSUPP_QTCB_TYPE:
387 dev_err(&adapter->ccw_device->dev,
388 "The QTCB type is not supported by the FCP adapter\n");
389 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
391 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
392 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
395 case FSF_PROT_DUPLICATE_REQUEST_ID:
396 dev_err(&adapter->ccw_device->dev,
397 "0x%Lx is an ambiguous request identifier\n",
398 (unsigned long long)qtcb->bottom.support.req_handle);
399 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
401 case FSF_PROT_LINK_DOWN:
402 zfcp_fsf_link_down_info_eval(req, "fspse_5",
403 &psq->link_down_info);
404 /* go through reopen to flush pending requests */
405 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
407 case FSF_PROT_REEST_QUEUE:
408 /* All ports should be marked as ready to run again */
409 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
410 ZFCP_STATUS_COMMON_RUNNING,
412 zfcp_erp_adapter_reopen(adapter,
413 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
414 ZFCP_STATUS_COMMON_ERP_FAILED,
418 dev_err(&adapter->ccw_device->dev,
419 "0x%x is not a valid transfer protocol status\n",
420 qtcb->prefix.prot_status);
421 zfcp_qdio_siosl(adapter);
422 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
424 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
428 * zfcp_fsf_req_complete - process completion of a FSF request
429 * @fsf_req: The FSF request that has been completed.
431 * When a request has been completed either from the FCP adapter,
432 * or it has been dismissed due to a queue shutdown, this function
433 * is called to process the completion status and trigger further
434 * events related to the FSF request.
436 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
438 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
439 zfcp_fsf_status_read_handler(req);
443 del_timer(&req->timer);
444 zfcp_fsf_protstatus_eval(req);
445 zfcp_fsf_fsfstatus_eval(req);
449 zfcp_erp_notify(req->erp_action, 0);
451 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
452 zfcp_fsf_req_free(req);
454 complete(&req->completion);
458 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
459 * @adapter: pointer to struct zfcp_adapter
461 * Never ever call this without shutting down the adapter first.
462 * Otherwise the adapter would continue using and corrupting s390 storage.
463 * Included BUG_ON() call to ensure this is done.
464 * ERP is supposed to be the only user of this function.
466 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
468 struct zfcp_fsf_req *req, *tmp;
469 LIST_HEAD(remove_queue);
471 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
472 zfcp_reqlist_move(adapter->req_list, &remove_queue);
474 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
475 list_del(&req->list);
476 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
477 zfcp_fsf_req_complete(req);
481 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
483 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
484 struct zfcp_adapter *adapter = req->adapter;
485 struct Scsi_Host *shost = adapter->scsi_host;
486 struct fc_els_flogi *nsp, *plogi;
488 /* adjust pointers for missing command code */
489 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
491 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
495 memcpy(req->data, bottom, sizeof(*bottom));
497 fc_host_port_name(shost) = nsp->fl_wwpn;
498 fc_host_node_name(shost) = nsp->fl_wwnn;
499 fc_host_port_id(shost) = ntoh24(bottom->s_id);
500 fc_host_speed(shost) = bottom->fc_link_speed;
501 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
503 adapter->hydra_version = bottom->adapter_type;
504 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
505 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
506 (u16)FSF_STATUS_READS_RECOM);
508 if (fc_host_permanent_port_name(shost) == -1)
509 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
511 switch (bottom->fc_topology) {
513 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
514 adapter->peer_wwpn = plogi->fl_wwpn;
515 adapter->peer_wwnn = plogi->fl_wwnn;
516 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
518 case FSF_TOPO_FABRIC:
519 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
522 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
525 dev_err(&adapter->ccw_device->dev,
526 "Unknown or unsupported arbitrated loop "
527 "fibre channel topology detected\n");
528 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
532 zfcp_scsi_set_prot(adapter);
537 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
539 struct zfcp_adapter *adapter = req->adapter;
540 struct fsf_qtcb *qtcb = req->qtcb;
541 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
542 struct Scsi_Host *shost = adapter->scsi_host;
544 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
547 adapter->fsf_lic_version = bottom->lic_version;
548 adapter->adapter_features = bottom->adapter_features;
549 adapter->connection_features = bottom->connection_features;
550 adapter->peer_wwpn = 0;
551 adapter->peer_wwnn = 0;
552 adapter->peer_d_id = 0;
554 switch (qtcb->header.fsf_status) {
556 if (zfcp_fsf_exchange_config_evaluate(req))
559 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
560 dev_err(&adapter->ccw_device->dev,
561 "FCP adapter maximum QTCB size (%d bytes) "
563 bottom->max_qtcb_size);
564 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
567 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
570 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
571 fc_host_node_name(shost) = 0;
572 fc_host_port_name(shost) = 0;
573 fc_host_port_id(shost) = 0;
574 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
575 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
576 adapter->hydra_version = 0;
578 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
581 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
582 &qtcb->header.fsf_status_qual.link_down_info);
585 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
589 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
590 adapter->hardware_version = bottom->hardware_version;
591 memcpy(fc_host_serial_number(shost), bottom->serial_number,
592 min(FC_SERIAL_NUMBER_SIZE, 17));
593 EBCASC(fc_host_serial_number(shost),
594 min(FC_SERIAL_NUMBER_SIZE, 17));
597 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
598 dev_err(&adapter->ccw_device->dev,
599 "The FCP adapter only supports newer "
600 "control block versions\n");
601 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
604 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
605 dev_err(&adapter->ccw_device->dev,
606 "The FCP adapter only supports older "
607 "control block versions\n");
608 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
612 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
614 struct zfcp_adapter *adapter = req->adapter;
615 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
616 struct Scsi_Host *shost = adapter->scsi_host;
619 memcpy(req->data, bottom, sizeof(*bottom));
621 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
622 fc_host_permanent_port_name(shost) = bottom->wwpn;
623 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
625 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
626 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
627 fc_host_supported_speeds(shost) = bottom->supported_speed;
628 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
630 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
634 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
636 struct fsf_qtcb *qtcb = req->qtcb;
638 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
641 switch (qtcb->header.fsf_status) {
643 zfcp_fsf_exchange_port_evaluate(req);
645 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
646 zfcp_fsf_exchange_port_evaluate(req);
647 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
648 &qtcb->header.fsf_status_qual.link_down_info);
653 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
655 struct zfcp_fsf_req *req;
658 req = mempool_alloc(pool, GFP_ATOMIC);
660 req = kmalloc(sizeof(*req), GFP_ATOMIC);
665 memset(req, 0, sizeof(*req));
670 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
672 struct fsf_qtcb *qtcb;
675 qtcb = mempool_alloc(pool, GFP_ATOMIC);
677 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
682 memset(qtcb, 0, sizeof(*qtcb));
686 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
687 u32 fsf_cmd, u32 sbtype,
690 struct zfcp_adapter *adapter = qdio->adapter;
691 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
694 return ERR_PTR(-ENOMEM);
696 if (adapter->req_no == 0)
699 INIT_LIST_HEAD(&req->list);
700 init_timer(&req->timer);
701 init_completion(&req->completion);
703 req->adapter = adapter;
704 req->fsf_command = fsf_cmd;
705 req->req_id = adapter->req_no;
707 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
709 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
711 req->qtcb = zfcp_qtcb_alloc(NULL);
713 if (unlikely(!req->qtcb)) {
714 zfcp_fsf_req_free(req);
715 return ERR_PTR(-ENOMEM);
718 req->seq_no = adapter->fsf_req_seq_no;
719 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
720 req->qtcb->prefix.req_id = req->req_id;
721 req->qtcb->prefix.ulp_info = 26;
722 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
723 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
724 req->qtcb->header.req_handle = req->req_id;
725 req->qtcb->header.fsf_command = req->fsf_command;
728 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
729 req->qtcb, sizeof(struct fsf_qtcb));
734 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
736 struct zfcp_adapter *adapter = req->adapter;
737 struct zfcp_qdio *qdio = adapter->qdio;
738 int with_qtcb = (req->qtcb != NULL);
739 int req_id = req->req_id;
741 zfcp_reqlist_add(adapter->req_list, req);
743 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
744 req->issued = get_clock();
745 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
746 del_timer(&req->timer);
747 /* lookup request again, list might have changed */
748 zfcp_reqlist_find_rm(adapter->req_list, req_id);
749 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
753 /* Don't increase for unsolicited status */
755 adapter->fsf_req_seq_no++;
762 * zfcp_fsf_status_read - send status read request
763 * @adapter: pointer to struct zfcp_adapter
764 * @req_flags: request flags
765 * Returns: 0 on success, ERROR otherwise
767 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
769 struct zfcp_adapter *adapter = qdio->adapter;
770 struct zfcp_fsf_req *req;
771 struct fsf_status_read_buffer *sr_buf;
774 spin_lock_bh(&qdio->req_q_lock);
775 if (zfcp_qdio_sbal_get(qdio))
778 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
779 adapter->pool.status_read_req);
781 retval = PTR_ERR(req);
785 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
790 memset(sr_buf, 0, sizeof(*sr_buf));
793 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
794 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
796 retval = zfcp_fsf_req_send(req);
798 goto failed_req_send;
803 mempool_free(sr_buf, adapter->pool.status_read_data);
805 zfcp_fsf_req_free(req);
806 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
808 spin_unlock_bh(&qdio->req_q_lock);
812 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
814 struct zfcp_unit *unit = req->data;
815 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
817 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
820 switch (req->qtcb->header.fsf_status) {
821 case FSF_PORT_HANDLE_NOT_VALID:
822 if (fsq->word[0] == fsq->word[1]) {
823 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
825 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
828 case FSF_LUN_HANDLE_NOT_VALID:
829 if (fsq->word[0] == fsq->word[1]) {
830 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
831 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
834 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
835 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
838 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
839 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
842 zfcp_erp_unit_boxed(unit, "fsafch4", req);
843 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
845 case FSF_ADAPTER_STATUS_AVAILABLE:
846 switch (fsq->word[0]) {
847 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
848 zfcp_fc_test_link(unit->port);
850 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
851 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
856 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
862 * zfcp_fsf_abort_fcp_command - abort running SCSI command
863 * @old_req_id: unsigned long
864 * @unit: pointer to struct zfcp_unit
865 * Returns: pointer to struct zfcp_fsf_req
868 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
869 struct zfcp_unit *unit)
871 struct zfcp_fsf_req *req = NULL;
872 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
874 spin_lock_bh(&qdio->req_q_lock);
875 if (zfcp_qdio_sbal_get(qdio))
877 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
878 SBAL_FLAGS0_TYPE_READ,
879 qdio->adapter->pool.scsi_abort);
885 if (unlikely(!(atomic_read(&unit->status) &
886 ZFCP_STATUS_COMMON_UNBLOCKED)))
889 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
892 req->handler = zfcp_fsf_abort_fcp_command_handler;
893 req->qtcb->header.lun_handle = unit->handle;
894 req->qtcb->header.port_handle = unit->port->handle;
895 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
897 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
898 if (!zfcp_fsf_req_send(req))
902 zfcp_fsf_req_free(req);
905 spin_unlock_bh(&qdio->req_q_lock);
909 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
911 struct zfcp_adapter *adapter = req->adapter;
912 struct zfcp_fsf_ct_els *ct = req->data;
913 struct fsf_qtcb_header *header = &req->qtcb->header;
915 ct->status = -EINVAL;
917 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
920 switch (header->fsf_status) {
922 zfcp_dbf_san_ct_response(req);
925 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
926 zfcp_fsf_class_not_supp(req);
928 case FSF_ADAPTER_STATUS_AVAILABLE:
929 switch (header->fsf_status_qual.word[0]){
930 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
931 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
932 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
936 case FSF_ACCESS_DENIED:
939 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
941 case FSF_PORT_HANDLE_NOT_VALID:
942 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
944 case FSF_GENERIC_COMMAND_REJECTED:
945 case FSF_PAYLOAD_SIZE_MISMATCH:
946 case FSF_REQUEST_SIZE_TOO_LARGE:
947 case FSF_RESPONSE_SIZE_TOO_LARGE:
948 case FSF_SBAL_MISMATCH:
949 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
955 ct->handler(ct->handler_data);
958 static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
959 struct zfcp_qdio_req *q_req,
960 struct scatterlist *sg_req,
961 struct scatterlist *sg_resp)
963 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
964 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
965 zfcp_qdio_set_sbale_last(qdio, q_req);
968 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
969 struct scatterlist *sg_req,
970 struct scatterlist *sg_resp)
972 struct zfcp_adapter *adapter = req->adapter;
973 u32 feat = adapter->adapter_features;
976 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
977 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
978 !zfcp_qdio_sg_one_sbale(sg_resp))
981 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
986 /* use single, unchained SBAL if it can hold the request */
987 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
988 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
993 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
996 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
997 req->qtcb->bottom.support.req_buf_length = bytes;
998 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
1000 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
1002 req->qtcb->bottom.support.resp_buf_length = bytes;
1005 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
1010 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1011 struct scatterlist *sg_req,
1012 struct scatterlist *sg_resp,
1013 unsigned int timeout)
1017 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
1021 /* common settings for ct/gs and els requests */
1023 timeout = 255; /* max value accepted by hardware */
1024 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1025 req->qtcb->bottom.support.timeout = timeout;
1026 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1032 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1033 * @ct: pointer to struct zfcp_send_ct with data for request
1034 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1036 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1037 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1038 unsigned int timeout)
1040 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1041 struct zfcp_fsf_req *req;
1044 spin_lock_bh(&qdio->req_q_lock);
1045 if (zfcp_qdio_sbal_get(qdio))
1048 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1049 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
1056 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1057 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
1061 req->handler = zfcp_fsf_send_ct_handler;
1062 req->qtcb->header.port_handle = wka_port->handle;
1065 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1067 ret = zfcp_fsf_req_send(req);
1074 zfcp_fsf_req_free(req);
1076 spin_unlock_bh(&qdio->req_q_lock);
1080 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1082 struct zfcp_fsf_ct_els *send_els = req->data;
1083 struct zfcp_port *port = send_els->port;
1084 struct fsf_qtcb_header *header = &req->qtcb->header;
1086 send_els->status = -EINVAL;
1088 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1089 goto skip_fsfstatus;
1091 switch (header->fsf_status) {
1093 zfcp_dbf_san_els_response(req);
1094 send_els->status = 0;
1096 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1097 zfcp_fsf_class_not_supp(req);
1099 case FSF_ADAPTER_STATUS_AVAILABLE:
1100 switch (header->fsf_status_qual.word[0]){
1101 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1102 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1103 case FSF_SQ_RETRY_IF_POSSIBLE:
1104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1108 case FSF_ELS_COMMAND_REJECTED:
1109 case FSF_PAYLOAD_SIZE_MISMATCH:
1110 case FSF_REQUEST_SIZE_TOO_LARGE:
1111 case FSF_RESPONSE_SIZE_TOO_LARGE:
1113 case FSF_ACCESS_DENIED:
1115 zfcp_fsf_access_denied_port(req, port);
1117 case FSF_SBAL_MISMATCH:
1118 /* should never occure, avoided in zfcp_fsf_send_els */
1121 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1125 if (send_els->handler)
1126 send_els->handler(send_els->handler_data);
1130 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1131 * @els: pointer to struct zfcp_send_els with data for the command
1133 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1134 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1136 struct zfcp_fsf_req *req;
1137 struct zfcp_qdio *qdio = adapter->qdio;
1140 spin_lock_bh(&qdio->req_q_lock);
1141 if (zfcp_qdio_sbal_get(qdio))
1144 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1145 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
1152 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1154 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1156 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
1161 hton24(req->qtcb->bottom.support.d_id, d_id);
1162 req->handler = zfcp_fsf_send_els_handler;
1165 zfcp_dbf_san_els_request(req);
1167 ret = zfcp_fsf_req_send(req);
1174 zfcp_fsf_req_free(req);
1176 spin_unlock_bh(&qdio->req_q_lock);
1180 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1182 struct zfcp_fsf_req *req;
1183 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1186 spin_lock_bh(&qdio->req_q_lock);
1187 if (zfcp_qdio_sbal_get(qdio))
1190 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1191 SBAL_FLAGS0_TYPE_READ,
1192 qdio->adapter->pool.erp_req);
1195 retval = PTR_ERR(req);
1199 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1200 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1202 req->qtcb->bottom.config.feature_selection =
1204 FSF_FEATURE_LUN_SHARING |
1205 FSF_FEATURE_NOTIFICATION_LOST |
1206 FSF_FEATURE_UPDATE_ALERT;
1207 req->erp_action = erp_action;
1208 req->handler = zfcp_fsf_exchange_config_data_handler;
1209 erp_action->fsf_req_id = req->req_id;
1211 zfcp_fsf_start_erp_timer(req);
1212 retval = zfcp_fsf_req_send(req);
1214 zfcp_fsf_req_free(req);
1215 erp_action->fsf_req_id = 0;
1218 spin_unlock_bh(&qdio->req_q_lock);
1222 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1223 struct fsf_qtcb_bottom_config *data)
1225 struct zfcp_fsf_req *req = NULL;
1228 spin_lock_bh(&qdio->req_q_lock);
1229 if (zfcp_qdio_sbal_get(qdio))
1232 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1233 SBAL_FLAGS0_TYPE_READ, NULL);
1236 retval = PTR_ERR(req);
1240 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1241 req->handler = zfcp_fsf_exchange_config_data_handler;
1243 req->qtcb->bottom.config.feature_selection =
1245 FSF_FEATURE_LUN_SHARING |
1246 FSF_FEATURE_NOTIFICATION_LOST |
1247 FSF_FEATURE_UPDATE_ALERT;
1252 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1253 retval = zfcp_fsf_req_send(req);
1254 spin_unlock_bh(&qdio->req_q_lock);
1256 wait_for_completion(&req->completion);
1258 zfcp_fsf_req_free(req);
1262 spin_unlock_bh(&qdio->req_q_lock);
1267 * zfcp_fsf_exchange_port_data - request information about local port
1268 * @erp_action: ERP action for the adapter for which port data is requested
1269 * Returns: 0 on success, error otherwise
1271 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1273 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1274 struct zfcp_fsf_req *req;
1277 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1280 spin_lock_bh(&qdio->req_q_lock);
1281 if (zfcp_qdio_sbal_get(qdio))
1284 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1285 SBAL_FLAGS0_TYPE_READ,
1286 qdio->adapter->pool.erp_req);
1289 retval = PTR_ERR(req);
1293 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1294 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1296 req->handler = zfcp_fsf_exchange_port_data_handler;
1297 req->erp_action = erp_action;
1298 erp_action->fsf_req_id = req->req_id;
1300 zfcp_fsf_start_erp_timer(req);
1301 retval = zfcp_fsf_req_send(req);
1303 zfcp_fsf_req_free(req);
1304 erp_action->fsf_req_id = 0;
1307 spin_unlock_bh(&qdio->req_q_lock);
1312 * zfcp_fsf_exchange_port_data_sync - request information about local port
1313 * @qdio: pointer to struct zfcp_qdio
1314 * @data: pointer to struct fsf_qtcb_bottom_port
1315 * Returns: 0 on success, error otherwise
1317 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1318 struct fsf_qtcb_bottom_port *data)
1320 struct zfcp_fsf_req *req = NULL;
1323 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1326 spin_lock_bh(&qdio->req_q_lock);
1327 if (zfcp_qdio_sbal_get(qdio))
1330 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1331 SBAL_FLAGS0_TYPE_READ, NULL);
1334 retval = PTR_ERR(req);
1341 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1343 req->handler = zfcp_fsf_exchange_port_data_handler;
1344 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1345 retval = zfcp_fsf_req_send(req);
1346 spin_unlock_bh(&qdio->req_q_lock);
1349 wait_for_completion(&req->completion);
1351 zfcp_fsf_req_free(req);
1356 spin_unlock_bh(&qdio->req_q_lock);
1360 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1362 struct zfcp_port *port = req->data;
1363 struct fsf_qtcb_header *header = &req->qtcb->header;
1364 struct fc_els_flogi *plogi;
1366 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1369 switch (header->fsf_status) {
1370 case FSF_PORT_ALREADY_OPEN:
1372 case FSF_ACCESS_DENIED:
1373 zfcp_fsf_access_denied_port(req, port);
1375 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1376 dev_warn(&req->adapter->ccw_device->dev,
1377 "Not enough FCP adapter resources to open "
1378 "remote port 0x%016Lx\n",
1379 (unsigned long long)port->wwpn);
1380 zfcp_erp_port_failed(port, "fsoph_1", req);
1381 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1383 case FSF_ADAPTER_STATUS_AVAILABLE:
1384 switch (header->fsf_status_qual.word[0]) {
1385 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1386 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1387 case FSF_SQ_NO_RETRY_POSSIBLE:
1388 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1393 port->handle = header->port_handle;
1394 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1395 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1396 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1397 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1399 /* check whether D_ID has changed during open */
1401 * FIXME: This check is not airtight, as the FCP channel does
1402 * not monitor closures of target port connections caused on
1403 * the remote side. Thus, they might miss out on invalidating
1404 * locally cached WWPNs (and other N_Port parameters) of gone
1405 * target ports. So, our heroic attempt to make things safe
1406 * could be undermined by 'open port' response data tagged with
1407 * obsolete WWPNs. Another reason to monitor potential
1408 * connection closures ourself at least (by interpreting
1409 * incoming ELS' and unsolicited status). It just crosses my
1410 * mind that one should be able to cross-check by means of
1411 * another GID_PN straight after a port has been opened.
1412 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1414 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1415 if (req->qtcb->bottom.support.els1_length >=
1417 zfcp_fc_plogi_evaluate(port, plogi);
1419 case FSF_UNKNOWN_OP_SUBTYPE:
1420 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1425 put_device(&port->dev);
1429 * zfcp_fsf_open_port - create and send open port request
1430 * @erp_action: pointer to struct zfcp_erp_action
1431 * Returns: 0 on success, error otherwise
1433 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1435 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1436 struct zfcp_port *port = erp_action->port;
1437 struct zfcp_fsf_req *req;
1440 spin_lock_bh(&qdio->req_q_lock);
1441 if (zfcp_qdio_sbal_get(qdio))
1444 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1445 SBAL_FLAGS0_TYPE_READ,
1446 qdio->adapter->pool.erp_req);
1449 retval = PTR_ERR(req);
1453 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1454 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1456 req->handler = zfcp_fsf_open_port_handler;
1457 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1459 req->erp_action = erp_action;
1460 erp_action->fsf_req_id = req->req_id;
1461 get_device(&port->dev);
1463 zfcp_fsf_start_erp_timer(req);
1464 retval = zfcp_fsf_req_send(req);
1466 zfcp_fsf_req_free(req);
1467 erp_action->fsf_req_id = 0;
1468 put_device(&port->dev);
1471 spin_unlock_bh(&qdio->req_q_lock);
1475 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1477 struct zfcp_port *port = req->data;
1479 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1482 switch (req->qtcb->header.fsf_status) {
1483 case FSF_PORT_HANDLE_NOT_VALID:
1484 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1485 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1487 case FSF_ADAPTER_STATUS_AVAILABLE:
1490 zfcp_erp_modify_port_status(port, "fscph_2", req,
1491 ZFCP_STATUS_COMMON_OPEN,
1498 * zfcp_fsf_close_port - create and send close port request
1499 * @erp_action: pointer to struct zfcp_erp_action
1500 * Returns: 0 on success, error otherwise
1502 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1504 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1505 struct zfcp_fsf_req *req;
1508 spin_lock_bh(&qdio->req_q_lock);
1509 if (zfcp_qdio_sbal_get(qdio))
1512 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1513 SBAL_FLAGS0_TYPE_READ,
1514 qdio->adapter->pool.erp_req);
1517 retval = PTR_ERR(req);
1521 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1522 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1524 req->handler = zfcp_fsf_close_port_handler;
1525 req->data = erp_action->port;
1526 req->erp_action = erp_action;
1527 req->qtcb->header.port_handle = erp_action->port->handle;
1528 erp_action->fsf_req_id = req->req_id;
1530 zfcp_fsf_start_erp_timer(req);
1531 retval = zfcp_fsf_req_send(req);
1533 zfcp_fsf_req_free(req);
1534 erp_action->fsf_req_id = 0;
1537 spin_unlock_bh(&qdio->req_q_lock);
1541 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1543 struct zfcp_fc_wka_port *wka_port = req->data;
1544 struct fsf_qtcb_header *header = &req->qtcb->header;
1546 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1547 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1551 switch (header->fsf_status) {
1552 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1553 dev_warn(&req->adapter->ccw_device->dev,
1554 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1556 case FSF_ADAPTER_STATUS_AVAILABLE:
1557 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1559 case FSF_ACCESS_DENIED:
1560 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1563 wka_port->handle = header->port_handle;
1565 case FSF_PORT_ALREADY_OPEN:
1566 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1569 wake_up(&wka_port->completion_wq);
1573 * zfcp_fsf_open_wka_port - create and send open wka-port request
1574 * @wka_port: pointer to struct zfcp_fc_wka_port
1575 * Returns: 0 on success, error otherwise
1577 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1579 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1580 struct zfcp_fsf_req *req;
1583 spin_lock_bh(&qdio->req_q_lock);
1584 if (zfcp_qdio_sbal_get(qdio))
1587 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1588 SBAL_FLAGS0_TYPE_READ,
1589 qdio->adapter->pool.erp_req);
1591 if (unlikely(IS_ERR(req))) {
1592 retval = PTR_ERR(req);
1596 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1597 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1599 req->handler = zfcp_fsf_open_wka_port_handler;
1600 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1601 req->data = wka_port;
1603 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1604 retval = zfcp_fsf_req_send(req);
1606 zfcp_fsf_req_free(req);
1608 spin_unlock_bh(&qdio->req_q_lock);
1612 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1614 struct zfcp_fc_wka_port *wka_port = req->data;
1616 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1617 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1618 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1621 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1622 wake_up(&wka_port->completion_wq);
1626 * zfcp_fsf_close_wka_port - create and send close wka port request
1627 * @wka_port: WKA port to open
1628 * Returns: 0 on success, error otherwise
1630 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1632 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1633 struct zfcp_fsf_req *req;
1636 spin_lock_bh(&qdio->req_q_lock);
1637 if (zfcp_qdio_sbal_get(qdio))
1640 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1641 SBAL_FLAGS0_TYPE_READ,
1642 qdio->adapter->pool.erp_req);
1644 if (unlikely(IS_ERR(req))) {
1645 retval = PTR_ERR(req);
1649 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1650 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1652 req->handler = zfcp_fsf_close_wka_port_handler;
1653 req->data = wka_port;
1654 req->qtcb->header.port_handle = wka_port->handle;
1656 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1657 retval = zfcp_fsf_req_send(req);
1659 zfcp_fsf_req_free(req);
1661 spin_unlock_bh(&qdio->req_q_lock);
1665 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1667 struct zfcp_port *port = req->data;
1668 struct fsf_qtcb_header *header = &req->qtcb->header;
1669 struct zfcp_unit *unit;
1671 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1674 switch (header->fsf_status) {
1675 case FSF_PORT_HANDLE_NOT_VALID:
1676 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1677 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1679 case FSF_ACCESS_DENIED:
1680 zfcp_fsf_access_denied_port(req, port);
1682 case FSF_PORT_BOXED:
1683 /* can't use generic zfcp_erp_modify_port_status because
1684 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1685 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1686 read_lock(&port->unit_list_lock);
1687 list_for_each_entry(unit, &port->unit_list, list)
1688 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1690 read_unlock(&port->unit_list_lock);
1691 zfcp_erp_port_boxed(port, "fscpph2", req);
1692 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1694 case FSF_ADAPTER_STATUS_AVAILABLE:
1695 switch (header->fsf_status_qual.word[0]) {
1696 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1698 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1699 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1704 /* can't use generic zfcp_erp_modify_port_status because
1705 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1707 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1708 read_lock(&port->unit_list_lock);
1709 list_for_each_entry(unit, &port->unit_list, list)
1710 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1712 read_unlock(&port->unit_list_lock);
1718 * zfcp_fsf_close_physical_port - close physical port
1719 * @erp_action: pointer to struct zfcp_erp_action
1720 * Returns: 0 on success
1722 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1724 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1725 struct zfcp_fsf_req *req;
1728 spin_lock_bh(&qdio->req_q_lock);
1729 if (zfcp_qdio_sbal_get(qdio))
1732 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1733 SBAL_FLAGS0_TYPE_READ,
1734 qdio->adapter->pool.erp_req);
1737 retval = PTR_ERR(req);
1741 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1742 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1744 req->data = erp_action->port;
1745 req->qtcb->header.port_handle = erp_action->port->handle;
1746 req->erp_action = erp_action;
1747 req->handler = zfcp_fsf_close_physical_port_handler;
1748 erp_action->fsf_req_id = req->req_id;
1750 zfcp_fsf_start_erp_timer(req);
1751 retval = zfcp_fsf_req_send(req);
1753 zfcp_fsf_req_free(req);
1754 erp_action->fsf_req_id = 0;
1757 spin_unlock_bh(&qdio->req_q_lock);
1761 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1763 struct zfcp_adapter *adapter = req->adapter;
1764 struct zfcp_unit *unit = req->data;
1765 struct fsf_qtcb_header *header = &req->qtcb->header;
1766 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1767 struct fsf_queue_designator *queue_designator =
1768 &header->fsf_status_qual.fsf_queue_designator;
1769 int exclusive, readwrite;
1771 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1774 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1775 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1776 ZFCP_STATUS_UNIT_SHARED |
1777 ZFCP_STATUS_UNIT_READONLY,
1780 switch (header->fsf_status) {
1782 case FSF_PORT_HANDLE_NOT_VALID:
1783 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1785 case FSF_LUN_ALREADY_OPEN:
1787 case FSF_ACCESS_DENIED:
1788 zfcp_fsf_access_denied_unit(req, unit);
1789 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1790 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1792 case FSF_PORT_BOXED:
1793 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1794 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1796 case FSF_LUN_SHARING_VIOLATION:
1797 if (header->fsf_status_qual.word[0])
1798 dev_warn(&adapter->ccw_device->dev,
1799 "LUN 0x%Lx on port 0x%Lx is already in "
1800 "use by CSS%d, MIF Image ID %x\n",
1801 (unsigned long long)unit->fcp_lun,
1802 (unsigned long long)unit->port->wwpn,
1803 queue_designator->cssid,
1804 queue_designator->hla);
1806 zfcp_act_eval_err(adapter,
1807 header->fsf_status_qual.word[2]);
1808 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1809 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1810 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1811 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1813 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1814 dev_warn(&adapter->ccw_device->dev,
1815 "No handle is available for LUN "
1816 "0x%016Lx on port 0x%016Lx\n",
1817 (unsigned long long)unit->fcp_lun,
1818 (unsigned long long)unit->port->wwpn);
1819 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1821 case FSF_INVALID_COMMAND_OPTION:
1822 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1824 case FSF_ADAPTER_STATUS_AVAILABLE:
1825 switch (header->fsf_status_qual.word[0]) {
1826 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1827 zfcp_fc_test_link(unit->port);
1829 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1830 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1836 unit->handle = header->lun_handle;
1837 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1839 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1840 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1841 !zfcp_ccw_priv_sch(adapter)) {
1842 exclusive = (bottom->lun_access_info &
1843 FSF_UNIT_ACCESS_EXCLUSIVE);
1844 readwrite = (bottom->lun_access_info &
1845 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1848 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1852 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1854 dev_info(&adapter->ccw_device->dev,
1855 "SCSI device at LUN 0x%016Lx on port "
1856 "0x%016Lx opened read-only\n",
1857 (unsigned long long)unit->fcp_lun,
1858 (unsigned long long)unit->port->wwpn);
1861 if (exclusive && !readwrite) {
1862 dev_err(&adapter->ccw_device->dev,
1863 "Exclusive read-only access not "
1864 "supported (unit 0x%016Lx, "
1866 (unsigned long long)unit->fcp_lun,
1867 (unsigned long long)unit->port->wwpn);
1868 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1870 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1871 } else if (!exclusive && readwrite) {
1872 dev_err(&adapter->ccw_device->dev,
1873 "Shared read-write access not "
1874 "supported (unit 0x%016Lx, port "
1876 (unsigned long long)unit->fcp_lun,
1877 (unsigned long long)unit->port->wwpn);
1878 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1879 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1880 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1888 * zfcp_fsf_open_unit - open unit
1889 * @erp_action: pointer to struct zfcp_erp_action
1890 * Returns: 0 on success, error otherwise
1892 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1894 struct zfcp_adapter *adapter = erp_action->adapter;
1895 struct zfcp_qdio *qdio = adapter->qdio;
1896 struct zfcp_fsf_req *req;
1899 spin_lock_bh(&qdio->req_q_lock);
1900 if (zfcp_qdio_sbal_get(qdio))
1903 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1904 SBAL_FLAGS0_TYPE_READ,
1905 adapter->pool.erp_req);
1908 retval = PTR_ERR(req);
1912 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1913 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1915 req->qtcb->header.port_handle = erp_action->port->handle;
1916 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1917 req->handler = zfcp_fsf_open_unit_handler;
1918 req->data = erp_action->unit;
1919 req->erp_action = erp_action;
1920 erp_action->fsf_req_id = req->req_id;
1922 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1923 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1925 zfcp_fsf_start_erp_timer(req);
1926 retval = zfcp_fsf_req_send(req);
1928 zfcp_fsf_req_free(req);
1929 erp_action->fsf_req_id = 0;
1932 spin_unlock_bh(&qdio->req_q_lock);
1936 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
1938 struct zfcp_unit *unit = req->data;
1940 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1943 switch (req->qtcb->header.fsf_status) {
1944 case FSF_PORT_HANDLE_NOT_VALID:
1945 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
1946 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1948 case FSF_LUN_HANDLE_NOT_VALID:
1949 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
1950 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1952 case FSF_PORT_BOXED:
1953 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
1954 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1956 case FSF_ADAPTER_STATUS_AVAILABLE:
1957 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1958 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1959 zfcp_fc_test_link(unit->port);
1961 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1962 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1967 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1973 * zfcp_fsf_close_unit - close zfcp unit
1974 * @erp_action: pointer to struct zfcp_unit
1975 * Returns: 0 on success, error otherwise
1977 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1979 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1980 struct zfcp_fsf_req *req;
1983 spin_lock_bh(&qdio->req_q_lock);
1984 if (zfcp_qdio_sbal_get(qdio))
1987 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
1988 SBAL_FLAGS0_TYPE_READ,
1989 qdio->adapter->pool.erp_req);
1992 retval = PTR_ERR(req);
1996 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1997 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1999 req->qtcb->header.port_handle = erp_action->port->handle;
2000 req->qtcb->header.lun_handle = erp_action->unit->handle;
2001 req->handler = zfcp_fsf_close_unit_handler;
2002 req->data = erp_action->unit;
2003 req->erp_action = erp_action;
2004 erp_action->fsf_req_id = req->req_id;
2006 zfcp_fsf_start_erp_timer(req);
2007 retval = zfcp_fsf_req_send(req);
2009 zfcp_fsf_req_free(req);
2010 erp_action->fsf_req_id = 0;
2013 spin_unlock_bh(&qdio->req_q_lock);
2017 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2019 lat_rec->sum += lat;
2020 lat_rec->min = min(lat_rec->min, lat);
2021 lat_rec->max = max(lat_rec->max, lat);
2024 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2026 struct fsf_qual_latency_info *lat_in;
2027 struct latency_cont *lat = NULL;
2028 struct zfcp_unit *unit = req->unit;
2029 struct zfcp_blk_drv_data blktrc;
2030 int ticks = req->adapter->timer_ticks;
2032 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2035 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2036 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2037 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2038 blktrc.inb_usage = 0;
2039 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
2041 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2042 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2043 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2044 blktrc.channel_lat = lat_in->channel_lat * ticks;
2045 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2047 switch (req->qtcb->bottom.io.data_direction) {
2048 case FSF_DATADIR_DIF_READ_STRIP:
2049 case FSF_DATADIR_DIF_READ_CONVERT:
2050 case FSF_DATADIR_READ:
2051 lat = &unit->latencies.read;
2053 case FSF_DATADIR_DIF_WRITE_INSERT:
2054 case FSF_DATADIR_DIF_WRITE_CONVERT:
2055 case FSF_DATADIR_WRITE:
2056 lat = &unit->latencies.write;
2058 case FSF_DATADIR_CMND:
2059 lat = &unit->latencies.cmd;
2064 spin_lock(&unit->latencies.lock);
2065 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2066 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2068 spin_unlock(&unit->latencies.lock);
2072 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2076 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2078 struct scsi_cmnd *scpnt;
2079 struct fcp_resp_with_ext *fcp_rsp;
2080 unsigned long flags;
2082 read_lock_irqsave(&req->adapter->abort_lock, flags);
2085 if (unlikely(!scpnt)) {
2086 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2090 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2091 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2092 goto skip_fsfstatus;
2095 switch (req->qtcb->header.fsf_status) {
2096 case FSF_INCONSISTENT_PROT_DATA:
2097 case FSF_INVALID_PROT_PARM:
2098 set_host_byte(scpnt, DID_ERROR);
2099 goto skip_fsfstatus;
2100 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2101 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2102 goto skip_fsfstatus;
2103 case FSF_APP_TAG_CHECK_FAILURE:
2104 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2105 goto skip_fsfstatus;
2106 case FSF_REF_TAG_CHECK_FAILURE:
2107 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2108 goto skip_fsfstatus;
2110 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2111 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2114 zfcp_fsf_req_trace(req, scpnt);
2115 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
2117 scpnt->host_scribble = NULL;
2118 (scpnt->scsi_done) (scpnt);
2120 * We must hold this lock until scsi_done has been called.
2121 * Otherwise we may call scsi_done after abort regarding this
2122 * command has completed.
2123 * Note: scsi_done must not block!
2125 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2128 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2130 struct fcp_resp_with_ext *fcp_rsp;
2131 struct fcp_resp_rsp_info *rsp_info;
2133 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2134 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2136 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2137 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2138 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2142 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2144 struct zfcp_unit *unit;
2145 struct fsf_qtcb_header *header = &req->qtcb->header;
2147 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2152 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2153 goto skip_fsfstatus;
2155 switch (header->fsf_status) {
2156 case FSF_HANDLE_MISMATCH:
2157 case FSF_PORT_HANDLE_NOT_VALID:
2158 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2159 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2161 case FSF_FCPLUN_NOT_VALID:
2162 case FSF_LUN_HANDLE_NOT_VALID:
2163 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2164 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2166 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2167 zfcp_fsf_class_not_supp(req);
2169 case FSF_ACCESS_DENIED:
2170 zfcp_fsf_access_denied_unit(req, unit);
2172 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2173 dev_err(&req->adapter->ccw_device->dev,
2174 "Incorrect direction %d, unit 0x%016Lx on port "
2175 "0x%016Lx closed\n",
2176 req->qtcb->bottom.io.data_direction,
2177 (unsigned long long)unit->fcp_lun,
2178 (unsigned long long)unit->port->wwpn);
2179 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2181 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2183 case FSF_CMND_LENGTH_NOT_VALID:
2184 dev_err(&req->adapter->ccw_device->dev,
2185 "Incorrect CDB length %d, unit 0x%016Lx on "
2186 "port 0x%016Lx closed\n",
2187 req->qtcb->bottom.io.fcp_cmnd_length,
2188 (unsigned long long)unit->fcp_lun,
2189 (unsigned long long)unit->port->wwpn);
2190 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2192 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2194 case FSF_PORT_BOXED:
2195 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2196 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2199 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2200 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2202 case FSF_ADAPTER_STATUS_AVAILABLE:
2203 if (header->fsf_status_qual.word[0] ==
2204 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2205 zfcp_fc_test_link(unit->port);
2206 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2210 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2211 zfcp_fsf_send_fcp_ctm_handler(req);
2213 zfcp_fsf_send_fcp_command_task_handler(req);
2215 put_device(&unit->dev);
2219 static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2221 switch (scsi_get_prot_op(scsi_cmnd)) {
2222 case SCSI_PROT_NORMAL:
2223 switch (scsi_cmnd->sc_data_direction) {
2225 *data_dir = FSF_DATADIR_CMND;
2227 case DMA_FROM_DEVICE:
2228 *data_dir = FSF_DATADIR_READ;
2231 *data_dir = FSF_DATADIR_WRITE;
2233 case DMA_BIDIRECTIONAL:
2238 case SCSI_PROT_READ_STRIP:
2239 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2241 case SCSI_PROT_WRITE_INSERT:
2242 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2244 case SCSI_PROT_READ_PASS:
2245 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2247 case SCSI_PROT_WRITE_PASS:
2248 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2258 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2259 * @unit: unit where command is sent to
2260 * @scsi_cmnd: scsi command to be sent
2262 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2263 struct scsi_cmnd *scsi_cmnd)
2265 struct zfcp_fsf_req *req;
2266 struct fcp_cmnd *fcp_cmnd;
2267 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2268 int real_bytes, retval = -EIO, dix_bytes = 0;
2269 struct zfcp_adapter *adapter = unit->port->adapter;
2270 struct zfcp_qdio *qdio = adapter->qdio;
2271 struct fsf_qtcb_bottom_io *io;
2273 if (unlikely(!(atomic_read(&unit->status) &
2274 ZFCP_STATUS_COMMON_UNBLOCKED)))
2277 spin_lock(&qdio->req_q_lock);
2278 if (atomic_read(&qdio->req_q_free) <= 0) {
2279 atomic_inc(&qdio->req_q_full);
2283 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2284 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2286 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2287 sbtype, adapter->pool.scsi_req);
2290 retval = PTR_ERR(req);
2294 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2296 io = &req->qtcb->bottom.io;
2297 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2299 req->data = scsi_cmnd;
2300 req->handler = zfcp_fsf_send_fcp_command_handler;
2301 req->qtcb->header.lun_handle = unit->handle;
2302 req->qtcb->header.port_handle = unit->port->handle;
2303 io->service_class = FSF_CLASS_3;
2304 io->fcp_cmnd_length = FCP_CMND_LEN;
2306 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2307 io->data_block_length = scsi_cmnd->device->sector_size;
2308 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
2311 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
2313 get_device(&unit->dev);
2315 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2316 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2318 if (scsi_prot_sg_count(scsi_cmnd)) {
2319 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2320 scsi_prot_sg_count(scsi_cmnd));
2321 dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2322 scsi_prot_sglist(scsi_cmnd));
2323 io->prot_data_length = dix_bytes;
2326 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2327 scsi_sglist(scsi_cmnd));
2329 if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
2330 goto failed_scsi_cmnd;
2332 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2334 retval = zfcp_fsf_req_send(req);
2335 if (unlikely(retval))
2336 goto failed_scsi_cmnd;
2341 put_device(&unit->dev);
2342 zfcp_fsf_req_free(req);
2343 scsi_cmnd->host_scribble = NULL;
2345 spin_unlock(&qdio->req_q_lock);
2350 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2351 * @unit: pointer to struct zfcp_unit
2352 * @tm_flags: unsigned byte for task management flags
2353 * Returns: on success pointer to struct fsf_req, NULL otherwise
2355 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2357 struct zfcp_fsf_req *req = NULL;
2358 struct fcp_cmnd *fcp_cmnd;
2359 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2361 if (unlikely(!(atomic_read(&unit->status) &
2362 ZFCP_STATUS_COMMON_UNBLOCKED)))
2365 spin_lock_bh(&qdio->req_q_lock);
2366 if (zfcp_qdio_sbal_get(qdio))
2369 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2370 SBAL_FLAGS0_TYPE_WRITE,
2371 qdio->adapter->pool.scsi_req);
2378 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2380 req->handler = zfcp_fsf_send_fcp_command_handler;
2381 req->qtcb->header.lun_handle = unit->handle;
2382 req->qtcb->header.port_handle = unit->port->handle;
2383 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2384 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2385 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2387 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2389 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2390 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2392 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2393 if (!zfcp_fsf_req_send(req))
2396 zfcp_fsf_req_free(req);
2399 spin_unlock_bh(&qdio->req_q_lock);
2403 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2408 * zfcp_fsf_control_file - control file upload/download
2409 * @adapter: pointer to struct zfcp_adapter
2410 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2411 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2413 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2414 struct zfcp_fsf_cfdc *fsf_cfdc)
2416 struct zfcp_qdio *qdio = adapter->qdio;
2417 struct zfcp_fsf_req *req = NULL;
2418 struct fsf_qtcb_bottom_support *bottom;
2419 int direction, retval = -EIO, bytes;
2421 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2422 return ERR_PTR(-EOPNOTSUPP);
2424 switch (fsf_cfdc->command) {
2425 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2426 direction = SBAL_FLAGS0_TYPE_WRITE;
2428 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2429 direction = SBAL_FLAGS0_TYPE_READ;
2432 return ERR_PTR(-EINVAL);
2435 spin_lock_bh(&qdio->req_q_lock);
2436 if (zfcp_qdio_sbal_get(qdio))
2439 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
2445 req->handler = zfcp_fsf_control_file_handler;
2447 bottom = &req->qtcb->bottom.support;
2448 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2449 bottom->option = fsf_cfdc->option;
2451 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
2453 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2454 zfcp_fsf_req_free(req);
2457 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2459 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2460 retval = zfcp_fsf_req_send(req);
2462 spin_unlock_bh(&qdio->req_q_lock);
2465 wait_for_completion(&req->completion);
2468 return ERR_PTR(retval);
2472 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2473 * @adapter: pointer to struct zfcp_adapter
2474 * @sbal_idx: response queue index of SBAL to be processed
2476 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2478 struct zfcp_adapter *adapter = qdio->adapter;
2479 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
2480 struct qdio_buffer_element *sbale;
2481 struct zfcp_fsf_req *fsf_req;
2482 unsigned long req_id;
2485 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2487 sbale = &sbal->element[idx];
2488 req_id = (unsigned long) sbale->addr;
2489 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2493 * Unknown request means that we have potentially memory
2494 * corruption and must stop the machine immediately.
2496 zfcp_qdio_siosl(adapter);
2497 panic("error: unknown req_id (%lx) on adapter %s.\n",
2498 req_id, dev_name(&adapter->ccw_device->dev));
2501 fsf_req->qdio_req.sbal_response = sbal_idx;
2502 zfcp_fsf_req_complete(fsf_req);
2504 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))