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>
16 static void zfcp_fsf_request_timeout_handler(unsigned long data)
18 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
19 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
23 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
24 unsigned long timeout)
26 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
27 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
28 fsf_req->timer.expires = jiffies + timeout;
29 add_timer(&fsf_req->timer);
32 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
34 BUG_ON(!fsf_req->erp_action);
35 fsf_req->timer.function = zfcp_erp_timeout_handler;
36 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
37 fsf_req->timer.expires = jiffies + 30 * HZ;
38 add_timer(&fsf_req->timer);
41 /* association between FSF command and FSF QTCB type */
42 static u32 fsf_qtcb_type[] = {
43 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
44 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
45 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
46 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
53 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
54 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
58 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
60 u16 subtable = table >> 16;
61 u16 rule = table & 0xffff;
62 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
64 if (subtable && subtable < ARRAY_SIZE(act_type))
65 dev_warn(&adapter->ccw_device->dev,
66 "Access denied according to ACT rule type %s, "
67 "rule %d\n", act_type[subtable], rule);
70 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
71 struct zfcp_port *port)
73 struct fsf_qtcb_header *header = &req->qtcb->header;
74 dev_warn(&req->adapter->ccw_device->dev,
75 "Access denied to port 0x%016Lx\n",
76 (unsigned long long)port->wwpn);
77 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
78 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
79 zfcp_erp_port_access_denied(port, "fspad_1", req);
80 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
83 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
84 struct zfcp_unit *unit)
86 struct fsf_qtcb_header *header = &req->qtcb->header;
87 dev_warn(&req->adapter->ccw_device->dev,
88 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
89 (unsigned long long)unit->fcp_lun,
90 (unsigned long long)unit->port->wwpn);
91 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
92 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
93 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
94 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
97 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
99 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
100 "operational because of an unsupported FC class\n");
101 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
102 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
106 * zfcp_fsf_req_free - free memory used by fsf request
107 * @fsf_req: pointer to struct zfcp_fsf_req
109 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
111 if (likely(req->pool)) {
112 if (likely(req->qtcb))
113 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
114 mempool_free(req, req->pool);
118 if (likely(req->qtcb))
119 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
123 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
125 struct fsf_status_read_buffer *sr_buf = req->data;
126 struct zfcp_adapter *adapter = req->adapter;
127 struct zfcp_port *port;
128 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
131 read_lock_irqsave(&zfcp_data.config_lock, flags);
132 list_for_each_entry(port, &adapter->port_list_head, list)
133 if (port->d_id == d_id) {
134 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
135 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
138 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
141 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
142 struct fsf_link_down_info *link_down)
144 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 read_lock_irqsave(&zfcp_data.config_lock, flags);
153 zfcp_scsi_schedule_rports_block(adapter);
154 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
159 switch (link_down->error_code) {
160 case FSF_PSQ_LINK_NO_LIGHT:
161 dev_warn(&req->adapter->ccw_device->dev,
162 "There is no light signal from the local "
163 "fibre channel cable\n");
165 case FSF_PSQ_LINK_WRAP_PLUG:
166 dev_warn(&req->adapter->ccw_device->dev,
167 "There is a wrap plug instead of a fibre "
170 case FSF_PSQ_LINK_NO_FCP:
171 dev_warn(&req->adapter->ccw_device->dev,
172 "The adjacent fibre channel node does not "
175 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
176 dev_warn(&req->adapter->ccw_device->dev,
177 "The FCP device is suspended because of a "
178 "firmware update\n");
180 case FSF_PSQ_LINK_INVALID_WWPN:
181 dev_warn(&req->adapter->ccw_device->dev,
182 "The FCP device detected a WWPN that is "
183 "duplicate or not valid\n");
185 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
186 dev_warn(&req->adapter->ccw_device->dev,
187 "The fibre channel fabric does not support NPIV\n");
189 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
190 dev_warn(&req->adapter->ccw_device->dev,
191 "The FCP adapter cannot support more NPIV ports\n");
193 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
194 dev_warn(&req->adapter->ccw_device->dev,
195 "The adjacent switch cannot support "
196 "more NPIV ports\n");
198 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
199 dev_warn(&req->adapter->ccw_device->dev,
200 "The FCP adapter could not log in to the "
201 "fibre channel fabric\n");
203 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
204 dev_warn(&req->adapter->ccw_device->dev,
205 "The WWPN assignment file on the FCP adapter "
206 "has been damaged\n");
208 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
209 dev_warn(&req->adapter->ccw_device->dev,
210 "The mode table on the FCP adapter "
211 "has been damaged\n");
213 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
214 dev_warn(&req->adapter->ccw_device->dev,
215 "All NPIV ports on the FCP adapter have "
219 dev_warn(&req->adapter->ccw_device->dev,
220 "The link between the FCP adapter and "
221 "the FC fabric is down\n");
224 zfcp_erp_adapter_failed(adapter, id, req);
227 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
229 struct fsf_status_read_buffer *sr_buf = req->data;
230 struct fsf_link_down_info *ldi =
231 (struct fsf_link_down_info *) &sr_buf->payload;
233 switch (sr_buf->status_subtype) {
234 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
235 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
237 case FSF_STATUS_READ_SUB_FDISC_FAILED:
238 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
240 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
241 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
245 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
247 struct zfcp_adapter *adapter = req->adapter;
248 struct fsf_status_read_buffer *sr_buf = req->data;
250 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
251 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
252 mempool_free(sr_buf, adapter->pool.status_read_data);
253 zfcp_fsf_req_free(req);
257 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
259 switch (sr_buf->status_type) {
260 case FSF_STATUS_READ_PORT_CLOSED:
261 zfcp_fsf_status_read_port_closed(req);
263 case FSF_STATUS_READ_INCOMING_ELS:
264 zfcp_fc_incoming_els(req);
266 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
268 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
269 dev_warn(&adapter->ccw_device->dev,
270 "The error threshold for checksum statistics "
271 "has been exceeded\n");
272 zfcp_hba_dbf_event_berr(adapter, req);
274 case FSF_STATUS_READ_LINK_DOWN:
275 zfcp_fsf_status_read_link_down(req);
277 case FSF_STATUS_READ_LINK_UP:
278 dev_info(&adapter->ccw_device->dev,
279 "The local link has been restored\n");
280 /* All ports should be marked as ready to run again */
281 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
282 ZFCP_STATUS_COMMON_RUNNING,
284 zfcp_erp_adapter_reopen(adapter,
285 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
286 ZFCP_STATUS_COMMON_ERP_FAILED,
289 case FSF_STATUS_READ_NOTIFICATION_LOST:
290 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
291 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
293 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
294 schedule_work(&adapter->scan_work);
296 case FSF_STATUS_READ_CFDC_UPDATED:
297 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
299 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
300 adapter->adapter_features = sr_buf->payload.word[0];
304 mempool_free(sr_buf, adapter->pool.status_read_data);
305 zfcp_fsf_req_free(req);
307 atomic_inc(&adapter->stat_miss);
308 queue_work(adapter->work_queue, &adapter->stat_work);
311 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
313 switch (req->qtcb->header.fsf_status_qual.word[0]) {
314 case FSF_SQ_FCP_RSP_AVAILABLE:
315 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
316 case FSF_SQ_NO_RETRY_POSSIBLE:
317 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
319 case FSF_SQ_COMMAND_ABORTED:
320 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
322 case FSF_SQ_NO_RECOM:
323 dev_err(&req->adapter->ccw_device->dev,
324 "The FCP adapter reported a problem "
325 "that cannot be recovered\n");
326 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
329 /* all non-return stats set FSFREQ_ERROR*/
330 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
333 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
335 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
338 switch (req->qtcb->header.fsf_status) {
339 case FSF_UNKNOWN_COMMAND:
340 dev_err(&req->adapter->ccw_device->dev,
341 "The FCP adapter does not recognize the command 0x%x\n",
342 req->qtcb->header.fsf_command);
343 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
344 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
346 case FSF_ADAPTER_STATUS_AVAILABLE:
347 zfcp_fsf_fsfstatus_qual_eval(req);
352 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
354 struct zfcp_adapter *adapter = req->adapter;
355 struct fsf_qtcb *qtcb = req->qtcb;
356 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
358 zfcp_hba_dbf_event_fsf_response(req);
360 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
361 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
362 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
366 switch (qtcb->prefix.prot_status) {
368 case FSF_PROT_FSF_STATUS_PRESENTED:
370 case FSF_PROT_QTCB_VERSION_ERROR:
371 dev_err(&adapter->ccw_device->dev,
372 "QTCB version 0x%x not supported by FCP adapter "
373 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
374 psq->word[0], psq->word[1]);
375 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
377 case FSF_PROT_ERROR_STATE:
378 case FSF_PROT_SEQ_NUMB_ERROR:
379 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
380 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
382 case FSF_PROT_UNSUPP_QTCB_TYPE:
383 dev_err(&adapter->ccw_device->dev,
384 "The QTCB type is not supported by the FCP adapter\n");
385 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
387 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
388 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
391 case FSF_PROT_DUPLICATE_REQUEST_ID:
392 dev_err(&adapter->ccw_device->dev,
393 "0x%Lx is an ambiguous request identifier\n",
394 (unsigned long long)qtcb->bottom.support.req_handle);
395 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
397 case FSF_PROT_LINK_DOWN:
398 zfcp_fsf_link_down_info_eval(req, "fspse_5",
399 &psq->link_down_info);
400 /* FIXME: reopening adapter now? better wait for link up */
401 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
403 case FSF_PROT_REEST_QUEUE:
404 /* All ports should be marked as ready to run again */
405 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
406 ZFCP_STATUS_COMMON_RUNNING,
408 zfcp_erp_adapter_reopen(adapter,
409 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
410 ZFCP_STATUS_COMMON_ERP_FAILED,
414 dev_err(&adapter->ccw_device->dev,
415 "0x%x is not a valid transfer protocol status\n",
416 qtcb->prefix.prot_status);
417 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
419 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
423 * zfcp_fsf_req_complete - process completion of a FSF request
424 * @fsf_req: The FSF request that has been completed.
426 * When a request has been completed either from the FCP adapter,
427 * or it has been dismissed due to a queue shutdown, this function
428 * is called to process the completion status and trigger further
429 * events related to the FSF request.
431 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
433 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
434 zfcp_fsf_status_read_handler(req);
438 del_timer(&req->timer);
439 zfcp_fsf_protstatus_eval(req);
440 zfcp_fsf_fsfstatus_eval(req);
444 zfcp_erp_notify(req->erp_action, 0);
446 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
447 zfcp_fsf_req_free(req);
449 complete(&req->completion);
453 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
454 * @adapter: pointer to struct zfcp_adapter
456 * Never ever call this without shutting down the adapter first.
457 * Otherwise the adapter would continue using and corrupting s390 storage.
458 * Included BUG_ON() call to ensure this is done.
459 * ERP is supposed to be the only user of this function.
461 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
463 struct zfcp_fsf_req *req, *tmp;
465 LIST_HEAD(remove_queue);
468 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
469 spin_lock_irqsave(&adapter->req_list_lock, flags);
470 for (i = 0; i < REQUEST_LIST_SIZE; i++)
471 list_splice_init(&adapter->req_list[i], &remove_queue);
472 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
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;
484 struct zfcp_adapter *adapter = req->adapter;
485 struct Scsi_Host *shost = adapter->scsi_host;
487 bottom = &req->qtcb->bottom.config;
490 memcpy(req->data, bottom, sizeof(*bottom));
492 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
493 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
494 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
495 fc_host_speed(shost) = bottom->fc_link_speed;
496 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
498 adapter->hydra_version = bottom->adapter_type;
499 adapter->timer_ticks = bottom->timer_interval;
501 if (fc_host_permanent_port_name(shost) == -1)
502 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
504 switch (bottom->fc_topology) {
506 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
507 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
508 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
509 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
511 case FSF_TOPO_FABRIC:
512 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
515 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
518 dev_err(&adapter->ccw_device->dev,
519 "Unknown or unsupported arbitrated loop "
520 "fibre channel topology detected\n");
521 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
528 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
530 struct zfcp_adapter *adapter = req->adapter;
531 struct fsf_qtcb *qtcb = req->qtcb;
532 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
533 struct Scsi_Host *shost = adapter->scsi_host;
535 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
538 adapter->fsf_lic_version = bottom->lic_version;
539 adapter->adapter_features = bottom->adapter_features;
540 adapter->connection_features = bottom->connection_features;
541 adapter->peer_wwpn = 0;
542 adapter->peer_wwnn = 0;
543 adapter->peer_d_id = 0;
545 switch (qtcb->header.fsf_status) {
547 if (zfcp_fsf_exchange_config_evaluate(req))
550 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
551 dev_err(&adapter->ccw_device->dev,
552 "FCP adapter maximum QTCB size (%d bytes) "
554 bottom->max_qtcb_size);
555 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
558 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
561 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
562 fc_host_node_name(shost) = 0;
563 fc_host_port_name(shost) = 0;
564 fc_host_port_id(shost) = 0;
565 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
566 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
567 adapter->hydra_version = 0;
569 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
572 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
573 &qtcb->header.fsf_status_qual.link_down_info);
576 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
580 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
581 adapter->hardware_version = bottom->hardware_version;
582 memcpy(fc_host_serial_number(shost), bottom->serial_number,
583 min(FC_SERIAL_NUMBER_SIZE, 17));
584 EBCASC(fc_host_serial_number(shost),
585 min(FC_SERIAL_NUMBER_SIZE, 17));
588 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
589 dev_err(&adapter->ccw_device->dev,
590 "The FCP adapter only supports newer "
591 "control block versions\n");
592 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
595 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
596 dev_err(&adapter->ccw_device->dev,
597 "The FCP adapter only supports older "
598 "control block versions\n");
599 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
603 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
605 struct zfcp_adapter *adapter = req->adapter;
606 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
607 struct Scsi_Host *shost = adapter->scsi_host;
610 memcpy(req->data, bottom, sizeof(*bottom));
612 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
613 fc_host_permanent_port_name(shost) = bottom->wwpn;
614 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
616 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
617 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
618 fc_host_supported_speeds(shost) = bottom->supported_speed;
621 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
623 struct fsf_qtcb *qtcb = req->qtcb;
625 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
628 switch (qtcb->header.fsf_status) {
630 zfcp_fsf_exchange_port_evaluate(req);
632 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
633 zfcp_fsf_exchange_port_evaluate(req);
634 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
635 &qtcb->header.fsf_status_qual.link_down_info);
640 static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
642 struct zfcp_qdio_queue *req_q = &qdio->req_q;
644 spin_lock_bh(&qdio->req_q_lock);
645 if (atomic_read(&req_q->count))
647 spin_unlock_bh(&qdio->req_q_lock);
651 static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
653 struct zfcp_adapter *adapter = qdio->adapter;
656 spin_unlock_bh(&qdio->req_q_lock);
657 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
658 zfcp_fsf_sbal_check(qdio), 5 * HZ);
662 atomic_inc(&qdio->req_q_full);
663 /* assume hanging outbound queue, try queue recovery */
664 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
667 spin_lock_bh(&qdio->req_q_lock);
671 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
673 struct zfcp_fsf_req *req;
676 req = mempool_alloc(pool, GFP_ATOMIC);
678 req = kmalloc(sizeof(*req), GFP_ATOMIC);
683 memset(req, 0, sizeof(*req));
688 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
690 struct fsf_qtcb *qtcb;
693 qtcb = mempool_alloc(pool, GFP_ATOMIC);
695 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
700 memset(qtcb, 0, sizeof(*qtcb));
704 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
705 u32 fsf_cmd, mempool_t *pool)
707 struct qdio_buffer_element *sbale;
708 struct zfcp_qdio_queue *req_q = &qdio->req_q;
709 struct zfcp_adapter *adapter = qdio->adapter;
710 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
713 return ERR_PTR(-ENOMEM);
715 if (adapter->req_no == 0)
718 INIT_LIST_HEAD(&req->list);
719 init_timer(&req->timer);
720 init_completion(&req->completion);
722 req->adapter = adapter;
723 req->fsf_command = fsf_cmd;
724 req->req_id = adapter->req_no;
725 req->queue_req.sbal_number = 1;
726 req->queue_req.sbal_first = req_q->first;
727 req->queue_req.sbal_last = req_q->first;
728 req->queue_req.sbale_curr = 1;
730 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
731 sbale[0].addr = (void *) req->req_id;
732 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
734 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
736 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
738 req->qtcb = zfcp_qtcb_alloc(NULL);
740 if (unlikely(!req->qtcb)) {
741 zfcp_fsf_req_free(req);
742 return ERR_PTR(-ENOMEM);
745 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
746 req->qtcb->prefix.req_id = req->req_id;
747 req->qtcb->prefix.ulp_info = 26;
748 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
749 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
750 req->qtcb->header.req_handle = req->req_id;
751 req->qtcb->header.fsf_command = req->fsf_command;
752 req->seq_no = adapter->fsf_req_seq_no;
753 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
754 sbale[1].addr = (void *) req->qtcb;
755 sbale[1].length = sizeof(struct fsf_qtcb);
758 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
759 zfcp_fsf_req_free(req);
760 return ERR_PTR(-EIO);
766 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
768 struct zfcp_adapter *adapter = req->adapter;
769 struct zfcp_qdio *qdio = adapter->qdio;
772 int with_qtcb = (req->qtcb != NULL);
774 /* put allocated FSF request into hash table */
775 spin_lock_irqsave(&adapter->req_list_lock, flags);
776 idx = zfcp_reqlist_hash(req->req_id);
777 list_add_tail(&req->list, &adapter->req_list[idx]);
778 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
780 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
781 req->issued = get_clock();
782 if (zfcp_qdio_send(qdio, &req->queue_req)) {
783 del_timer(&req->timer);
784 spin_lock_irqsave(&adapter->req_list_lock, flags);
785 /* lookup request again, list might have changed */
786 if (zfcp_reqlist_find_safe(adapter, req))
787 zfcp_reqlist_remove(adapter, req);
788 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
789 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
793 /* Don't increase for unsolicited status */
795 adapter->fsf_req_seq_no++;
802 * zfcp_fsf_status_read - send status read request
803 * @adapter: pointer to struct zfcp_adapter
804 * @req_flags: request flags
805 * Returns: 0 on success, ERROR otherwise
807 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
809 struct zfcp_adapter *adapter = qdio->adapter;
810 struct zfcp_fsf_req *req;
811 struct fsf_status_read_buffer *sr_buf;
812 struct qdio_buffer_element *sbale;
815 spin_lock_bh(&qdio->req_q_lock);
816 if (zfcp_fsf_req_sbal_get(qdio))
819 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
820 adapter->pool.status_read_req);
822 retval = PTR_ERR(req);
826 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
827 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
828 req->queue_req.sbale_curr = 2;
830 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
835 memset(sr_buf, 0, sizeof(*sr_buf));
837 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
838 sbale->addr = (void *) sr_buf;
839 sbale->length = sizeof(*sr_buf);
841 retval = zfcp_fsf_req_send(req);
843 goto failed_req_send;
848 mempool_free(sr_buf, adapter->pool.status_read_data);
850 zfcp_fsf_req_free(req);
851 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
853 spin_unlock_bh(&qdio->req_q_lock);
857 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
859 struct zfcp_unit *unit = req->data;
860 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
862 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
865 switch (req->qtcb->header.fsf_status) {
866 case FSF_PORT_HANDLE_NOT_VALID:
867 if (fsq->word[0] == fsq->word[1]) {
868 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
870 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
873 case FSF_LUN_HANDLE_NOT_VALID:
874 if (fsq->word[0] == fsq->word[1]) {
875 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
876 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
879 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
880 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
883 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
884 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
885 ZFCP_STATUS_FSFREQ_RETRY;
888 zfcp_erp_unit_boxed(unit, "fsafch4", req);
889 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
890 ZFCP_STATUS_FSFREQ_RETRY;
892 case FSF_ADAPTER_STATUS_AVAILABLE:
893 switch (fsq->word[0]) {
894 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
895 zfcp_test_link(unit->port);
897 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
898 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
903 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
909 * zfcp_fsf_abort_fcp_command - abort running SCSI command
910 * @old_req_id: unsigned long
911 * @unit: pointer to struct zfcp_unit
912 * Returns: pointer to struct zfcp_fsf_req
915 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
916 struct zfcp_unit *unit)
918 struct qdio_buffer_element *sbale;
919 struct zfcp_fsf_req *req = NULL;
920 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
922 spin_lock_bh(&qdio->req_q_lock);
923 if (zfcp_fsf_req_sbal_get(qdio))
925 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
926 qdio->adapter->pool.scsi_abort);
932 if (unlikely(!(atomic_read(&unit->status) &
933 ZFCP_STATUS_COMMON_UNBLOCKED)))
936 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
937 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
938 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
941 req->handler = zfcp_fsf_abort_fcp_command_handler;
942 req->qtcb->header.lun_handle = unit->handle;
943 req->qtcb->header.port_handle = unit->port->handle;
944 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
946 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
947 if (!zfcp_fsf_req_send(req))
951 zfcp_fsf_req_free(req);
954 spin_unlock_bh(&qdio->req_q_lock);
958 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
960 struct zfcp_adapter *adapter = req->adapter;
961 struct zfcp_send_ct *send_ct = req->data;
962 struct fsf_qtcb_header *header = &req->qtcb->header;
964 send_ct->status = -EINVAL;
966 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
969 switch (header->fsf_status) {
971 zfcp_san_dbf_event_ct_response(req);
974 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
975 zfcp_fsf_class_not_supp(req);
977 case FSF_ADAPTER_STATUS_AVAILABLE:
978 switch (header->fsf_status_qual.word[0]){
979 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
980 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
981 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
985 case FSF_ACCESS_DENIED:
988 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
989 ZFCP_STATUS_FSFREQ_RETRY;
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;
1004 if (send_ct->handler)
1005 send_ct->handler(send_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);
1063 req->qtcb->bottom.support.resp_buf_length = bytes;
1069 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1070 * @ct: pointer to struct zfcp_send_ct with data for request
1071 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1072 * @erp_action: if non-null the Generic Service request sent within ERP
1074 int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1075 struct zfcp_erp_action *erp_action)
1077 struct zfcp_wka_port *wka_port = ct->wka_port;
1078 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1079 struct zfcp_fsf_req *req;
1082 spin_lock_bh(&qdio->req_q_lock);
1083 if (zfcp_fsf_req_sbal_get(qdio))
1086 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
1093 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1094 ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
1095 FSF_MAX_SBALS_PER_REQ);
1099 req->handler = zfcp_fsf_send_ct_handler;
1100 req->qtcb->header.port_handle = wka_port->handle;
1101 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1102 req->qtcb->bottom.support.timeout = ct->timeout;
1105 zfcp_san_dbf_event_ct_request(req);
1108 erp_action->fsf_req = req;
1109 req->erp_action = erp_action;
1110 zfcp_fsf_start_erp_timer(req);
1112 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1114 ret = zfcp_fsf_req_send(req);
1121 zfcp_fsf_req_free(req);
1123 erp_action->fsf_req = NULL;
1125 spin_unlock_bh(&qdio->req_q_lock);
1129 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1131 struct zfcp_send_els *send_els = req->data;
1132 struct zfcp_port *port = send_els->port;
1133 struct fsf_qtcb_header *header = &req->qtcb->header;
1135 send_els->status = -EINVAL;
1137 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1138 goto skip_fsfstatus;
1140 switch (header->fsf_status) {
1142 zfcp_san_dbf_event_els_response(req);
1143 send_els->status = 0;
1145 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1146 zfcp_fsf_class_not_supp(req);
1148 case FSF_ADAPTER_STATUS_AVAILABLE:
1149 switch (header->fsf_status_qual.word[0]){
1150 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1151 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1152 zfcp_test_link(port);
1154 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1155 case FSF_SQ_RETRY_IF_POSSIBLE:
1156 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1160 case FSF_ELS_COMMAND_REJECTED:
1161 case FSF_PAYLOAD_SIZE_MISMATCH:
1162 case FSF_REQUEST_SIZE_TOO_LARGE:
1163 case FSF_RESPONSE_SIZE_TOO_LARGE:
1165 case FSF_ACCESS_DENIED:
1167 zfcp_fsf_access_denied_port(req, port);
1169 case FSF_SBAL_MISMATCH:
1170 /* should never occure, avoided in zfcp_fsf_send_els */
1173 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1177 if (send_els->handler)
1178 send_els->handler(send_els->handler_data);
1182 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1183 * @els: pointer to struct zfcp_send_els with data for the command
1185 int zfcp_fsf_send_els(struct zfcp_send_els *els)
1187 struct zfcp_fsf_req *req;
1188 struct zfcp_qdio *qdio = els->adapter->qdio;
1189 struct fsf_qtcb_bottom_support *bottom;
1192 spin_lock_bh(&qdio->req_q_lock);
1193 if (zfcp_fsf_req_sbal_get(qdio))
1196 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
1203 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1204 ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
1209 bottom = &req->qtcb->bottom.support;
1210 req->handler = zfcp_fsf_send_els_handler;
1211 bottom->d_id = els->d_id;
1212 bottom->service_class = FSF_CLASS_3;
1213 bottom->timeout = 2 * R_A_TOV;
1216 zfcp_san_dbf_event_els_request(req);
1218 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1219 ret = zfcp_fsf_req_send(req);
1226 zfcp_fsf_req_free(req);
1228 spin_unlock_bh(&qdio->req_q_lock);
1232 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1234 struct qdio_buffer_element *sbale;
1235 struct zfcp_fsf_req *req;
1236 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1239 spin_lock_bh(&qdio->req_q_lock);
1240 if (zfcp_fsf_req_sbal_get(qdio))
1243 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1244 qdio->adapter->pool.erp_req);
1247 retval = PTR_ERR(req);
1251 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1252 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1253 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1254 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1256 req->qtcb->bottom.config.feature_selection =
1258 FSF_FEATURE_LUN_SHARING |
1259 FSF_FEATURE_NOTIFICATION_LOST |
1260 FSF_FEATURE_UPDATE_ALERT;
1261 req->erp_action = erp_action;
1262 req->handler = zfcp_fsf_exchange_config_data_handler;
1263 erp_action->fsf_req = req;
1265 zfcp_fsf_start_erp_timer(req);
1266 retval = zfcp_fsf_req_send(req);
1268 zfcp_fsf_req_free(req);
1269 erp_action->fsf_req = NULL;
1272 spin_unlock_bh(&qdio->req_q_lock);
1276 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1277 struct fsf_qtcb_bottom_config *data)
1279 struct qdio_buffer_element *sbale;
1280 struct zfcp_fsf_req *req = NULL;
1283 spin_lock_bh(&qdio->req_q_lock);
1284 if (zfcp_fsf_req_sbal_get(qdio))
1287 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
1290 retval = PTR_ERR(req);
1294 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1295 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1296 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1297 req->handler = zfcp_fsf_exchange_config_data_handler;
1299 req->qtcb->bottom.config.feature_selection =
1301 FSF_FEATURE_LUN_SHARING |
1302 FSF_FEATURE_NOTIFICATION_LOST |
1303 FSF_FEATURE_UPDATE_ALERT;
1308 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1309 retval = zfcp_fsf_req_send(req);
1310 spin_unlock_bh(&qdio->req_q_lock);
1312 wait_for_completion(&req->completion);
1314 zfcp_fsf_req_free(req);
1318 spin_unlock_bh(&qdio->req_q_lock);
1323 * zfcp_fsf_exchange_port_data - request information about local port
1324 * @erp_action: ERP action for the adapter for which port data is requested
1325 * Returns: 0 on success, error otherwise
1327 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1329 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1330 struct qdio_buffer_element *sbale;
1331 struct zfcp_fsf_req *req;
1334 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1337 spin_lock_bh(&qdio->req_q_lock);
1338 if (zfcp_fsf_req_sbal_get(qdio))
1341 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1342 qdio->adapter->pool.erp_req);
1345 retval = PTR_ERR(req);
1349 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1350 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1351 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1352 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1354 req->handler = zfcp_fsf_exchange_port_data_handler;
1355 req->erp_action = erp_action;
1356 erp_action->fsf_req = req;
1358 zfcp_fsf_start_erp_timer(req);
1359 retval = zfcp_fsf_req_send(req);
1361 zfcp_fsf_req_free(req);
1362 erp_action->fsf_req = NULL;
1365 spin_unlock_bh(&qdio->req_q_lock);
1370 * zfcp_fsf_exchange_port_data_sync - request information about local port
1371 * @qdio: pointer to struct zfcp_qdio
1372 * @data: pointer to struct fsf_qtcb_bottom_port
1373 * Returns: 0 on success, error otherwise
1375 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1376 struct fsf_qtcb_bottom_port *data)
1378 struct qdio_buffer_element *sbale;
1379 struct zfcp_fsf_req *req = NULL;
1382 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1385 spin_lock_bh(&qdio->req_q_lock);
1386 if (zfcp_fsf_req_sbal_get(qdio))
1389 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
1392 retval = PTR_ERR(req);
1399 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1400 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1401 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1403 req->handler = zfcp_fsf_exchange_port_data_handler;
1404 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1405 retval = zfcp_fsf_req_send(req);
1406 spin_unlock_bh(&qdio->req_q_lock);
1409 wait_for_completion(&req->completion);
1411 zfcp_fsf_req_free(req);
1416 spin_unlock_bh(&qdio->req_q_lock);
1420 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1422 struct zfcp_port *port = req->data;
1423 struct fsf_qtcb_header *header = &req->qtcb->header;
1424 struct fsf_plogi *plogi;
1426 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1429 switch (header->fsf_status) {
1430 case FSF_PORT_ALREADY_OPEN:
1432 case FSF_ACCESS_DENIED:
1433 zfcp_fsf_access_denied_port(req, port);
1435 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1436 dev_warn(&req->adapter->ccw_device->dev,
1437 "Not enough FCP adapter resources to open "
1438 "remote port 0x%016Lx\n",
1439 (unsigned long long)port->wwpn);
1440 zfcp_erp_port_failed(port, "fsoph_1", req);
1441 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1443 case FSF_ADAPTER_STATUS_AVAILABLE:
1444 switch (header->fsf_status_qual.word[0]) {
1445 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1446 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1447 case FSF_SQ_NO_RETRY_POSSIBLE:
1448 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1453 port->handle = header->port_handle;
1454 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1455 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1456 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1457 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1459 /* check whether D_ID has changed during open */
1461 * FIXME: This check is not airtight, as the FCP channel does
1462 * not monitor closures of target port connections caused on
1463 * the remote side. Thus, they might miss out on invalidating
1464 * locally cached WWPNs (and other N_Port parameters) of gone
1465 * target ports. So, our heroic attempt to make things safe
1466 * could be undermined by 'open port' response data tagged with
1467 * obsolete WWPNs. Another reason to monitor potential
1468 * connection closures ourself at least (by interpreting
1469 * incoming ELS' and unsolicited status). It just crosses my
1470 * mind that one should be able to cross-check by means of
1471 * another GID_PN straight after a port has been opened.
1472 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1474 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1475 if (req->qtcb->bottom.support.els1_length >=
1476 FSF_PLOGI_MIN_LEN) {
1477 if (plogi->serv_param.wwpn != port->wwpn)
1480 port->wwnn = plogi->serv_param.wwnn;
1481 zfcp_fc_plogi_evaluate(port, plogi);
1485 case FSF_UNKNOWN_OP_SUBTYPE:
1486 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1491 zfcp_port_put(port);
1495 * zfcp_fsf_open_port - create and send open port request
1496 * @erp_action: pointer to struct zfcp_erp_action
1497 * Returns: 0 on success, error otherwise
1499 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1501 struct qdio_buffer_element *sbale;
1502 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1503 struct zfcp_port *port = erp_action->port;
1504 struct zfcp_fsf_req *req;
1507 spin_lock_bh(&qdio->req_q_lock);
1508 if (zfcp_fsf_req_sbal_get(qdio))
1511 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1512 qdio->adapter->pool.erp_req);
1515 retval = PTR_ERR(req);
1519 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1520 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1521 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1522 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1524 req->handler = zfcp_fsf_open_port_handler;
1525 req->qtcb->bottom.support.d_id = port->d_id;
1527 req->erp_action = erp_action;
1528 erp_action->fsf_req = req;
1529 zfcp_port_get(port);
1531 zfcp_fsf_start_erp_timer(req);
1532 retval = zfcp_fsf_req_send(req);
1534 zfcp_fsf_req_free(req);
1535 erp_action->fsf_req = NULL;
1536 zfcp_port_put(port);
1539 spin_unlock_bh(&qdio->req_q_lock);
1543 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1545 struct zfcp_port *port = req->data;
1547 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1550 switch (req->qtcb->header.fsf_status) {
1551 case FSF_PORT_HANDLE_NOT_VALID:
1552 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1553 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1555 case FSF_ADAPTER_STATUS_AVAILABLE:
1558 zfcp_erp_modify_port_status(port, "fscph_2", req,
1559 ZFCP_STATUS_COMMON_OPEN,
1566 * zfcp_fsf_close_port - create and send close port request
1567 * @erp_action: pointer to struct zfcp_erp_action
1568 * Returns: 0 on success, error otherwise
1570 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1572 struct qdio_buffer_element *sbale;
1573 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1574 struct zfcp_fsf_req *req;
1577 spin_lock_bh(&qdio->req_q_lock);
1578 if (zfcp_fsf_req_sbal_get(qdio))
1581 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1582 qdio->adapter->pool.erp_req);
1585 retval = PTR_ERR(req);
1589 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1590 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1591 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1592 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1594 req->handler = zfcp_fsf_close_port_handler;
1595 req->data = erp_action->port;
1596 req->erp_action = erp_action;
1597 req->qtcb->header.port_handle = erp_action->port->handle;
1598 erp_action->fsf_req = req;
1600 zfcp_fsf_start_erp_timer(req);
1601 retval = zfcp_fsf_req_send(req);
1603 zfcp_fsf_req_free(req);
1604 erp_action->fsf_req = NULL;
1607 spin_unlock_bh(&qdio->req_q_lock);
1611 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1613 struct zfcp_wka_port *wka_port = req->data;
1614 struct fsf_qtcb_header *header = &req->qtcb->header;
1616 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1617 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1621 switch (header->fsf_status) {
1622 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1623 dev_warn(&req->adapter->ccw_device->dev,
1624 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1626 case FSF_ADAPTER_STATUS_AVAILABLE:
1627 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1629 case FSF_ACCESS_DENIED:
1630 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1633 wka_port->handle = header->port_handle;
1635 case FSF_PORT_ALREADY_OPEN:
1636 wka_port->status = ZFCP_WKA_PORT_ONLINE;
1639 wake_up(&wka_port->completion_wq);
1643 * zfcp_fsf_open_wka_port - create and send open wka-port request
1644 * @wka_port: pointer to struct zfcp_wka_port
1645 * Returns: 0 on success, error otherwise
1647 int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1649 struct qdio_buffer_element *sbale;
1650 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1651 struct zfcp_fsf_req *req;
1654 spin_lock_bh(&qdio->req_q_lock);
1655 if (zfcp_fsf_req_sbal_get(qdio))
1658 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1659 qdio->adapter->pool.erp_req);
1661 if (unlikely(IS_ERR(req))) {
1662 retval = PTR_ERR(req);
1666 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1667 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1668 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1669 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1671 req->handler = zfcp_fsf_open_wka_port_handler;
1672 req->qtcb->bottom.support.d_id = wka_port->d_id;
1673 req->data = wka_port;
1675 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1676 retval = zfcp_fsf_req_send(req);
1678 zfcp_fsf_req_free(req);
1680 spin_unlock_bh(&qdio->req_q_lock);
1684 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1686 struct zfcp_wka_port *wka_port = req->data;
1688 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1689 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1690 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1693 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1694 wake_up(&wka_port->completion_wq);
1698 * zfcp_fsf_close_wka_port - create and send close wka port request
1699 * @erp_action: pointer to struct zfcp_erp_action
1700 * Returns: 0 on success, error otherwise
1702 int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
1704 struct qdio_buffer_element *sbale;
1705 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1706 struct zfcp_fsf_req *req;
1709 spin_lock_bh(&qdio->req_q_lock);
1710 if (zfcp_fsf_req_sbal_get(qdio))
1713 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1714 qdio->adapter->pool.erp_req);
1716 if (unlikely(IS_ERR(req))) {
1717 retval = PTR_ERR(req);
1721 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1722 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1723 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1724 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1726 req->handler = zfcp_fsf_close_wka_port_handler;
1727 req->data = wka_port;
1728 req->qtcb->header.port_handle = wka_port->handle;
1730 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1731 retval = zfcp_fsf_req_send(req);
1733 zfcp_fsf_req_free(req);
1735 spin_unlock_bh(&qdio->req_q_lock);
1739 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1741 struct zfcp_port *port = req->data;
1742 struct fsf_qtcb_header *header = &req->qtcb->header;
1743 struct zfcp_unit *unit;
1745 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1748 switch (header->fsf_status) {
1749 case FSF_PORT_HANDLE_NOT_VALID:
1750 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1751 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1753 case FSF_ACCESS_DENIED:
1754 zfcp_fsf_access_denied_port(req, port);
1756 case FSF_PORT_BOXED:
1757 /* can't use generic zfcp_erp_modify_port_status because
1758 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1759 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1760 list_for_each_entry(unit, &port->unit_list_head, list)
1761 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1763 zfcp_erp_port_boxed(port, "fscpph2", req);
1764 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1765 ZFCP_STATUS_FSFREQ_RETRY;
1768 case FSF_ADAPTER_STATUS_AVAILABLE:
1769 switch (header->fsf_status_qual.word[0]) {
1770 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1772 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1773 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1778 /* can't use generic zfcp_erp_modify_port_status because
1779 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1781 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1782 list_for_each_entry(unit, &port->unit_list_head, list)
1783 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1790 * zfcp_fsf_close_physical_port - close physical port
1791 * @erp_action: pointer to struct zfcp_erp_action
1792 * Returns: 0 on success
1794 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1796 struct qdio_buffer_element *sbale;
1797 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1798 struct zfcp_fsf_req *req;
1801 spin_lock_bh(&qdio->req_q_lock);
1802 if (zfcp_fsf_req_sbal_get(qdio))
1805 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1806 qdio->adapter->pool.erp_req);
1809 retval = PTR_ERR(req);
1813 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1814 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1815 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1816 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1818 req->data = erp_action->port;
1819 req->qtcb->header.port_handle = erp_action->port->handle;
1820 req->erp_action = erp_action;
1821 req->handler = zfcp_fsf_close_physical_port_handler;
1822 erp_action->fsf_req = req;
1824 zfcp_fsf_start_erp_timer(req);
1825 retval = zfcp_fsf_req_send(req);
1827 zfcp_fsf_req_free(req);
1828 erp_action->fsf_req = NULL;
1831 spin_unlock_bh(&qdio->req_q_lock);
1835 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1837 struct zfcp_adapter *adapter = req->adapter;
1838 struct zfcp_unit *unit = req->data;
1839 struct fsf_qtcb_header *header = &req->qtcb->header;
1840 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1841 struct fsf_queue_designator *queue_designator =
1842 &header->fsf_status_qual.fsf_queue_designator;
1843 int exclusive, readwrite;
1845 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1848 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1849 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1850 ZFCP_STATUS_UNIT_SHARED |
1851 ZFCP_STATUS_UNIT_READONLY,
1854 switch (header->fsf_status) {
1856 case FSF_PORT_HANDLE_NOT_VALID:
1857 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1859 case FSF_LUN_ALREADY_OPEN:
1861 case FSF_ACCESS_DENIED:
1862 zfcp_fsf_access_denied_unit(req, unit);
1863 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1864 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1866 case FSF_PORT_BOXED:
1867 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1868 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1869 ZFCP_STATUS_FSFREQ_RETRY;
1871 case FSF_LUN_SHARING_VIOLATION:
1872 if (header->fsf_status_qual.word[0])
1873 dev_warn(&adapter->ccw_device->dev,
1874 "LUN 0x%Lx on port 0x%Lx is already in "
1875 "use by CSS%d, MIF Image ID %x\n",
1876 (unsigned long long)unit->fcp_lun,
1877 (unsigned long long)unit->port->wwpn,
1878 queue_designator->cssid,
1879 queue_designator->hla);
1881 zfcp_act_eval_err(adapter,
1882 header->fsf_status_qual.word[2]);
1883 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1884 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1885 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1886 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1888 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1889 dev_warn(&adapter->ccw_device->dev,
1890 "No handle is available for LUN "
1891 "0x%016Lx on port 0x%016Lx\n",
1892 (unsigned long long)unit->fcp_lun,
1893 (unsigned long long)unit->port->wwpn);
1894 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1896 case FSF_INVALID_COMMAND_OPTION:
1897 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1899 case FSF_ADAPTER_STATUS_AVAILABLE:
1900 switch (header->fsf_status_qual.word[0]) {
1901 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1902 zfcp_test_link(unit->port);
1904 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1905 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1911 unit->handle = header->lun_handle;
1912 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1914 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1915 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1916 !zfcp_ccw_priv_sch(adapter)) {
1917 exclusive = (bottom->lun_access_info &
1918 FSF_UNIT_ACCESS_EXCLUSIVE);
1919 readwrite = (bottom->lun_access_info &
1920 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1923 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1927 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1929 dev_info(&adapter->ccw_device->dev,
1930 "SCSI device at LUN 0x%016Lx on port "
1931 "0x%016Lx opened read-only\n",
1932 (unsigned long long)unit->fcp_lun,
1933 (unsigned long long)unit->port->wwpn);
1936 if (exclusive && !readwrite) {
1937 dev_err(&adapter->ccw_device->dev,
1938 "Exclusive read-only access not "
1939 "supported (unit 0x%016Lx, "
1941 (unsigned long long)unit->fcp_lun,
1942 (unsigned long long)unit->port->wwpn);
1943 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1945 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1946 } else if (!exclusive && readwrite) {
1947 dev_err(&adapter->ccw_device->dev,
1948 "Shared read-write access not "
1949 "supported (unit 0x%016Lx, port "
1951 (unsigned long long)unit->fcp_lun,
1952 (unsigned long long)unit->port->wwpn);
1953 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1954 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1955 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1963 * zfcp_fsf_open_unit - open unit
1964 * @erp_action: pointer to struct zfcp_erp_action
1965 * Returns: 0 on success, error otherwise
1967 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1969 struct qdio_buffer_element *sbale;
1970 struct zfcp_adapter *adapter = erp_action->adapter;
1971 struct zfcp_qdio *qdio = adapter->qdio;
1972 struct zfcp_fsf_req *req;
1975 spin_lock_bh(&qdio->req_q_lock);
1976 if (zfcp_fsf_req_sbal_get(qdio))
1979 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1980 adapter->pool.erp_req);
1983 retval = PTR_ERR(req);
1987 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1988 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1989 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1990 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1992 req->qtcb->header.port_handle = erp_action->port->handle;
1993 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1994 req->handler = zfcp_fsf_open_unit_handler;
1995 req->data = erp_action->unit;
1996 req->erp_action = erp_action;
1997 erp_action->fsf_req = req;
1999 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2000 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
2002 zfcp_fsf_start_erp_timer(req);
2003 retval = zfcp_fsf_req_send(req);
2005 zfcp_fsf_req_free(req);
2006 erp_action->fsf_req = NULL;
2009 spin_unlock_bh(&qdio->req_q_lock);
2013 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
2015 struct zfcp_unit *unit = req->data;
2017 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2020 switch (req->qtcb->header.fsf_status) {
2021 case FSF_PORT_HANDLE_NOT_VALID:
2022 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
2023 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2025 case FSF_LUN_HANDLE_NOT_VALID:
2026 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
2027 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2029 case FSF_PORT_BOXED:
2030 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2031 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2032 ZFCP_STATUS_FSFREQ_RETRY;
2034 case FSF_ADAPTER_STATUS_AVAILABLE:
2035 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2036 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2037 zfcp_test_link(unit->port);
2039 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2040 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2045 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2051 * zfcp_fsf_close_unit - close zfcp unit
2052 * @erp_action: pointer to struct zfcp_unit
2053 * Returns: 0 on success, error otherwise
2055 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2057 struct qdio_buffer_element *sbale;
2058 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2059 struct zfcp_fsf_req *req;
2062 spin_lock_bh(&qdio->req_q_lock);
2063 if (zfcp_fsf_req_sbal_get(qdio))
2066 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2067 qdio->adapter->pool.erp_req);
2070 retval = PTR_ERR(req);
2074 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2075 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2076 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2077 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2079 req->qtcb->header.port_handle = erp_action->port->handle;
2080 req->qtcb->header.lun_handle = erp_action->unit->handle;
2081 req->handler = zfcp_fsf_close_unit_handler;
2082 req->data = erp_action->unit;
2083 req->erp_action = erp_action;
2084 erp_action->fsf_req = req;
2086 zfcp_fsf_start_erp_timer(req);
2087 retval = zfcp_fsf_req_send(req);
2089 zfcp_fsf_req_free(req);
2090 erp_action->fsf_req = NULL;
2093 spin_unlock_bh(&qdio->req_q_lock);
2097 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2099 lat_rec->sum += lat;
2100 lat_rec->min = min(lat_rec->min, lat);
2101 lat_rec->max = max(lat_rec->max, lat);
2104 static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
2106 struct fsf_qual_latency_info *lat_inf;
2107 struct latency_cont *lat;
2108 struct zfcp_unit *unit = req->unit;
2110 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
2112 switch (req->qtcb->bottom.io.data_direction) {
2113 case FSF_DATADIR_READ:
2114 lat = &unit->latencies.read;
2116 case FSF_DATADIR_WRITE:
2117 lat = &unit->latencies.write;
2119 case FSF_DATADIR_CMND:
2120 lat = &unit->latencies.cmd;
2126 spin_lock(&unit->latencies.lock);
2127 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2128 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2130 spin_unlock(&unit->latencies.lock);
2133 #ifdef CONFIG_BLK_DEV_IO_TRACE
2134 static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2136 struct fsf_qual_latency_info *lat_inf;
2137 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
2138 struct request *req = scsi_cmnd->request;
2139 struct zfcp_blk_drv_data trace;
2140 int ticks = fsf_req->adapter->timer_ticks;
2143 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2144 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2145 trace.flags |= ZFCP_BLK_LAT_VALID;
2146 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2147 trace.channel_lat = lat_inf->channel_lat * ticks;
2148 trace.fabric_lat = lat_inf->fabric_lat * ticks;
2150 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2151 trace.flags |= ZFCP_BLK_REQ_ERROR;
2152 trace.inb_usage = fsf_req->queue_req.qdio_inb_usage;
2153 trace.outb_usage = fsf_req->queue_req.qdio_outb_usage;
2155 blk_add_driver_data(req->q, req, &trace, sizeof(trace));
2158 static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2163 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2165 struct scsi_cmnd *scpnt;
2166 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2167 &(req->qtcb->bottom.io.fcp_rsp);
2169 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2170 unsigned long flags;
2172 read_lock_irqsave(&req->adapter->abort_lock, flags);
2175 if (unlikely(!scpnt)) {
2176 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2180 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
2181 set_host_byte(scpnt, DID_SOFT_ERROR);
2182 goto skip_fsfstatus;
2185 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2186 set_host_byte(scpnt, DID_ERROR);
2187 goto skip_fsfstatus;
2190 set_msg_byte(scpnt, COMMAND_COMPLETE);
2192 scpnt->result |= fcp_rsp_iu->scsi_status;
2194 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2195 zfcp_fsf_req_latency(req);
2197 zfcp_fsf_trace_latency(req);
2199 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
2200 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
2201 set_host_byte(scpnt, DID_OK);
2203 set_host_byte(scpnt, DID_ERROR);
2204 goto skip_fsfstatus;
2208 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
2209 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2210 fcp_rsp_iu->fcp_rsp_len;
2211 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
2212 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
2214 memcpy(scpnt->sense_buffer,
2215 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
2218 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
2219 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2220 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2222 set_host_byte(scpnt, DID_ERROR);
2225 if (scpnt->result != 0)
2226 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
2227 else if (scpnt->retries > 0)
2228 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
2230 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
2232 scpnt->host_scribble = NULL;
2233 (scpnt->scsi_done) (scpnt);
2235 * We must hold this lock until scsi_done has been called.
2236 * Otherwise we may call scsi_done after abort regarding this
2237 * command has completed.
2238 * Note: scsi_done must not block!
2240 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2243 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2245 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2246 &(req->qtcb->bottom.io.fcp_rsp);
2247 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2249 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2250 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2251 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2255 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2257 struct zfcp_unit *unit;
2258 struct fsf_qtcb_header *header = &req->qtcb->header;
2260 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2265 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2266 goto skip_fsfstatus;
2268 switch (header->fsf_status) {
2269 case FSF_HANDLE_MISMATCH:
2270 case FSF_PORT_HANDLE_NOT_VALID:
2271 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2272 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2274 case FSF_FCPLUN_NOT_VALID:
2275 case FSF_LUN_HANDLE_NOT_VALID:
2276 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2277 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2279 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2280 zfcp_fsf_class_not_supp(req);
2282 case FSF_ACCESS_DENIED:
2283 zfcp_fsf_access_denied_unit(req, unit);
2285 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2286 dev_err(&req->adapter->ccw_device->dev,
2287 "Incorrect direction %d, unit 0x%016Lx on port "
2288 "0x%016Lx closed\n",
2289 req->qtcb->bottom.io.data_direction,
2290 (unsigned long long)unit->fcp_lun,
2291 (unsigned long long)unit->port->wwpn);
2292 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2294 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2296 case FSF_CMND_LENGTH_NOT_VALID:
2297 dev_err(&req->adapter->ccw_device->dev,
2298 "Incorrect CDB length %d, unit 0x%016Lx on "
2299 "port 0x%016Lx closed\n",
2300 req->qtcb->bottom.io.fcp_cmnd_length,
2301 (unsigned long long)unit->fcp_lun,
2302 (unsigned long long)unit->port->wwpn);
2303 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2305 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2307 case FSF_PORT_BOXED:
2308 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2309 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2310 ZFCP_STATUS_FSFREQ_RETRY;
2313 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2314 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2315 ZFCP_STATUS_FSFREQ_RETRY;
2317 case FSF_ADAPTER_STATUS_AVAILABLE:
2318 if (header->fsf_status_qual.word[0] ==
2319 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2320 zfcp_test_link(unit->port);
2321 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2325 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2326 zfcp_fsf_send_fcp_ctm_handler(req);
2328 zfcp_fsf_send_fcp_command_task_handler(req);
2330 zfcp_unit_put(unit);
2334 static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2339 * fcp_dl_addr = start address of fcp_cmnd structure +
2340 * size of fixed part + size of dynamically sized add_dcp_cdb field
2341 * SEE FCP-2 documentation
2343 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2344 (fcp_cmd->add_fcp_cdb_length << 2));
2345 *fcp_dl_ptr = fcp_dl;
2349 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2350 * @unit: unit where command is sent to
2351 * @scsi_cmnd: scsi command to be sent
2353 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2354 struct scsi_cmnd *scsi_cmnd)
2356 struct zfcp_fsf_req *req;
2357 struct fcp_cmnd_iu *fcp_cmnd_iu;
2358 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2359 int real_bytes, retval = -EIO;
2360 struct zfcp_adapter *adapter = unit->port->adapter;
2361 struct zfcp_qdio *qdio = adapter->qdio;
2363 if (unlikely(!(atomic_read(&unit->status) &
2364 ZFCP_STATUS_COMMON_UNBLOCKED)))
2367 spin_lock(&qdio->req_q_lock);
2368 if (atomic_read(&qdio->req_q.count) <= 0) {
2369 atomic_inc(&qdio->req_q_full);
2373 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2374 adapter->pool.scsi_req);
2377 retval = PTR_ERR(req);
2381 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2382 zfcp_unit_get(unit);
2384 req->data = scsi_cmnd;
2385 req->handler = zfcp_fsf_send_fcp_command_handler;
2386 req->qtcb->header.lun_handle = unit->handle;
2387 req->qtcb->header.port_handle = unit->port->handle;
2388 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2390 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2392 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2393 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2395 * set depending on data direction:
2396 * data direction bits in SBALE (SB Type)
2397 * data direction bits in QTCB
2398 * data direction bits in FCP_CMND IU
2400 switch (scsi_cmnd->sc_data_direction) {
2402 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2404 case DMA_FROM_DEVICE:
2405 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2406 fcp_cmnd_iu->rddata = 1;
2409 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2410 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2411 fcp_cmnd_iu->wddata = 1;
2413 case DMA_BIDIRECTIONAL:
2414 goto failed_scsi_cmnd;
2417 if (likely((scsi_cmnd->device->simple_tags) ||
2418 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2419 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2420 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2422 fcp_cmnd_iu->task_attribute = UNTAGGED;
2424 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2425 fcp_cmnd_iu->add_fcp_cdb_length =
2426 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2428 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2430 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2431 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
2433 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
2434 scsi_sglist(scsi_cmnd),
2435 FSF_MAX_SBALS_PER_REQ);
2436 if (unlikely(real_bytes < 0)) {
2437 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2438 dev_err(&adapter->ccw_device->dev,
2439 "Oversize data package, unit 0x%016Lx "
2440 "on port 0x%016Lx closed\n",
2441 (unsigned long long)unit->fcp_lun,
2442 (unsigned long long)unit->port->wwpn);
2443 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
2446 goto failed_scsi_cmnd;
2449 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2451 retval = zfcp_fsf_req_send(req);
2452 if (unlikely(retval))
2453 goto failed_scsi_cmnd;
2458 zfcp_unit_put(unit);
2459 zfcp_fsf_req_free(req);
2460 scsi_cmnd->host_scribble = NULL;
2462 spin_unlock(&qdio->req_q_lock);
2467 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2468 * @unit: pointer to struct zfcp_unit
2469 * @tm_flags: unsigned byte for task management flags
2470 * Returns: on success pointer to struct fsf_req, NULL otherwise
2472 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2474 struct qdio_buffer_element *sbale;
2475 struct zfcp_fsf_req *req = NULL;
2476 struct fcp_cmnd_iu *fcp_cmnd_iu;
2477 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2479 if (unlikely(!(atomic_read(&unit->status) &
2480 ZFCP_STATUS_COMMON_UNBLOCKED)))
2483 spin_lock_bh(&qdio->req_q_lock);
2484 if (zfcp_fsf_req_sbal_get(qdio))
2487 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2488 qdio->adapter->pool.scsi_req);
2495 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2497 req->handler = zfcp_fsf_send_fcp_command_handler;
2498 req->qtcb->header.lun_handle = unit->handle;
2499 req->qtcb->header.port_handle = unit->port->handle;
2500 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2501 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2502 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2505 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2506 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2507 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2509 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2510 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2511 fcp_cmnd_iu->task_management_flags = tm_flags;
2513 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2514 if (!zfcp_fsf_req_send(req))
2517 zfcp_fsf_req_free(req);
2520 spin_unlock_bh(&qdio->req_q_lock);
2524 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2529 * zfcp_fsf_control_file - control file upload/download
2530 * @adapter: pointer to struct zfcp_adapter
2531 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2532 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2534 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2535 struct zfcp_fsf_cfdc *fsf_cfdc)
2537 struct qdio_buffer_element *sbale;
2538 struct zfcp_qdio *qdio = adapter->qdio;
2539 struct zfcp_fsf_req *req = NULL;
2540 struct fsf_qtcb_bottom_support *bottom;
2541 int direction, retval = -EIO, bytes;
2543 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2544 return ERR_PTR(-EOPNOTSUPP);
2546 switch (fsf_cfdc->command) {
2547 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2548 direction = SBAL_FLAGS0_TYPE_WRITE;
2550 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2551 direction = SBAL_FLAGS0_TYPE_READ;
2554 return ERR_PTR(-EINVAL);
2557 spin_lock_bh(&qdio->req_q_lock);
2558 if (zfcp_fsf_req_sbal_get(qdio))
2561 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
2567 req->handler = zfcp_fsf_control_file_handler;
2569 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2570 sbale[0].flags |= direction;
2572 bottom = &req->qtcb->bottom.support;
2573 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2574 bottom->option = fsf_cfdc->option;
2576 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2577 direction, fsf_cfdc->sg,
2578 FSF_MAX_SBALS_PER_REQ);
2579 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2580 zfcp_fsf_req_free(req);
2584 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2585 retval = zfcp_fsf_req_send(req);
2587 spin_unlock_bh(&qdio->req_q_lock);
2590 wait_for_completion(&req->completion);
2593 return ERR_PTR(retval);
2597 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2598 * @adapter: pointer to struct zfcp_adapter
2599 * @sbal_idx: response queue index of SBAL to be processed
2601 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2603 struct zfcp_adapter *adapter = qdio->adapter;
2604 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
2605 struct qdio_buffer_element *sbale;
2606 struct zfcp_fsf_req *fsf_req;
2607 unsigned long flags, req_id;
2610 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2612 sbale = &sbal->element[idx];
2613 req_id = (unsigned long) sbale->addr;
2614 spin_lock_irqsave(&adapter->req_list_lock, flags);
2615 fsf_req = zfcp_reqlist_find(adapter, req_id);
2619 * Unknown request means that we have potentially memory
2620 * corruption and must stop the machine immediately.
2622 panic("error: unknown req_id (%lx) on adapter %s.\n",
2623 req_id, dev_name(&adapter->ccw_device->dev));
2625 list_del(&fsf_req->list);
2626 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
2628 fsf_req->queue_req.sbal_response = sbal_idx;
2629 fsf_req->queue_req.qdio_inb_usage =
2630 atomic_read(&qdio->resp_q.count);
2631 zfcp_fsf_req_complete(fsf_req);
2633 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))