4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2010
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <scsi/fc/fc_els.h>
17 #include "zfcp_qdio.h"
18 #include "zfcp_reqlist.h"
20 static void zfcp_fsf_request_timeout_handler(unsigned long data)
22 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
23 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
27 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
28 unsigned long timeout)
30 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
31 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
32 fsf_req->timer.expires = jiffies + timeout;
33 add_timer(&fsf_req->timer);
36 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
38 BUG_ON(!fsf_req->erp_action);
39 fsf_req->timer.function = zfcp_erp_timeout_handler;
40 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
41 fsf_req->timer.expires = jiffies + 30 * HZ;
42 add_timer(&fsf_req->timer);
45 /* association between FSF command and FSF QTCB type */
46 static u32 fsf_qtcb_type[] = {
47 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
48 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
57 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
58 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
62 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
64 u16 subtable = table >> 16;
65 u16 rule = table & 0xffff;
66 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
68 if (subtable && subtable < ARRAY_SIZE(act_type))
69 dev_warn(&adapter->ccw_device->dev,
70 "Access denied according to ACT rule type %s, "
71 "rule %d\n", act_type[subtable], rule);
74 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
75 struct zfcp_port *port)
77 struct fsf_qtcb_header *header = &req->qtcb->header;
78 dev_warn(&req->adapter->ccw_device->dev,
79 "Access denied to port 0x%016Lx\n",
80 (unsigned long long)port->wwpn);
81 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
82 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
83 zfcp_erp_port_access_denied(port, "fspad_1", req);
84 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
87 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
88 struct zfcp_unit *unit)
90 struct fsf_qtcb_header *header = &req->qtcb->header;
91 dev_warn(&req->adapter->ccw_device->dev,
92 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
93 (unsigned long long)unit->fcp_lun,
94 (unsigned long long)unit->port->wwpn);
95 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
96 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
97 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
98 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
101 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
103 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
104 "operational because of an unsupported FC class\n");
105 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
106 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
110 * zfcp_fsf_req_free - free memory used by fsf request
111 * @fsf_req: pointer to struct zfcp_fsf_req
113 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
115 if (likely(req->pool)) {
116 if (likely(req->qtcb))
117 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
118 mempool_free(req, req->pool);
122 if (likely(req->qtcb))
123 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
127 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
130 struct fsf_status_read_buffer *sr_buf = req->data;
131 struct zfcp_adapter *adapter = req->adapter;
132 struct zfcp_port *port;
133 int d_id = ntoh24(sr_buf->d_id);
135 read_lock_irqsave(&adapter->port_list_lock, flags);
136 list_for_each_entry(port, &adapter->port_list, list)
137 if (port->d_id == d_id) {
138 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
141 read_unlock_irqrestore(&adapter->port_list_lock, flags);
144 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
145 struct fsf_link_down_info *link_down)
147 struct zfcp_adapter *adapter = req->adapter;
149 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
152 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
154 zfcp_scsi_schedule_rports_block(adapter);
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_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
252 mempool_free(sr_buf, adapter->pool.status_read_data);
253 zfcp_fsf_req_free(req);
257 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, 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_dbf_hba_berr(adapter->dbf, 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 queue_work(adapter->work_queue, &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:
321 case FSF_SQ_NO_RECOM:
322 dev_err(&req->adapter->ccw_device->dev,
323 "The FCP adapter reported a problem "
324 "that cannot be recovered\n");
325 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
328 /* all non-return stats set FSFREQ_ERROR*/
329 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
332 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
334 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
337 switch (req->qtcb->header.fsf_status) {
338 case FSF_UNKNOWN_COMMAND:
339 dev_err(&req->adapter->ccw_device->dev,
340 "The FCP adapter does not recognize the command 0x%x\n",
341 req->qtcb->header.fsf_command);
342 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
343 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
345 case FSF_ADAPTER_STATUS_AVAILABLE:
346 zfcp_fsf_fsfstatus_qual_eval(req);
351 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
353 struct zfcp_adapter *adapter = req->adapter;
354 struct fsf_qtcb *qtcb = req->qtcb;
355 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
357 zfcp_dbf_hba_fsf_response(req);
359 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
360 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
364 switch (qtcb->prefix.prot_status) {
366 case FSF_PROT_FSF_STATUS_PRESENTED:
368 case FSF_PROT_QTCB_VERSION_ERROR:
369 dev_err(&adapter->ccw_device->dev,
370 "QTCB version 0x%x not supported by FCP adapter "
371 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
372 psq->word[0], psq->word[1]);
373 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
375 case FSF_PROT_ERROR_STATE:
376 case FSF_PROT_SEQ_NUMB_ERROR:
377 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
378 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
380 case FSF_PROT_UNSUPP_QTCB_TYPE:
381 dev_err(&adapter->ccw_device->dev,
382 "The QTCB type is not supported by the FCP adapter\n");
383 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
385 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
386 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
389 case FSF_PROT_DUPLICATE_REQUEST_ID:
390 dev_err(&adapter->ccw_device->dev,
391 "0x%Lx is an ambiguous request identifier\n",
392 (unsigned long long)qtcb->bottom.support.req_handle);
393 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
395 case FSF_PROT_LINK_DOWN:
396 zfcp_fsf_link_down_info_eval(req, "fspse_5",
397 &psq->link_down_info);
398 /* go through reopen to flush pending requests */
399 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
401 case FSF_PROT_REEST_QUEUE:
402 /* All ports should be marked as ready to run again */
403 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
404 ZFCP_STATUS_COMMON_RUNNING,
406 zfcp_erp_adapter_reopen(adapter,
407 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
408 ZFCP_STATUS_COMMON_ERP_FAILED,
412 dev_err(&adapter->ccw_device->dev,
413 "0x%x is not a valid transfer protocol status\n",
414 qtcb->prefix.prot_status);
415 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
417 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
421 * zfcp_fsf_req_complete - process completion of a FSF request
422 * @fsf_req: The FSF request that has been completed.
424 * When a request has been completed either from the FCP adapter,
425 * or it has been dismissed due to a queue shutdown, this function
426 * is called to process the completion status and trigger further
427 * events related to the FSF request.
429 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
431 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
432 zfcp_fsf_status_read_handler(req);
436 del_timer(&req->timer);
437 zfcp_fsf_protstatus_eval(req);
438 zfcp_fsf_fsfstatus_eval(req);
442 zfcp_erp_notify(req->erp_action, 0);
444 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
445 zfcp_fsf_req_free(req);
447 complete(&req->completion);
451 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
452 * @adapter: pointer to struct zfcp_adapter
454 * Never ever call this without shutting down the adapter first.
455 * Otherwise the adapter would continue using and corrupting s390 storage.
456 * Included BUG_ON() call to ensure this is done.
457 * ERP is supposed to be the only user of this function.
459 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
461 struct zfcp_fsf_req *req, *tmp;
462 LIST_HEAD(remove_queue);
464 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
465 zfcp_reqlist_move(adapter->req_list, &remove_queue);
467 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
468 list_del(&req->list);
469 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
470 zfcp_fsf_req_complete(req);
474 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
476 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
477 struct zfcp_adapter *adapter = req->adapter;
478 struct Scsi_Host *shost = adapter->scsi_host;
479 struct fc_els_flogi *nsp, *plogi;
481 /* adjust pointers for missing command code */
482 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
484 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
488 memcpy(req->data, bottom, sizeof(*bottom));
490 fc_host_port_name(shost) = nsp->fl_wwpn;
491 fc_host_node_name(shost) = nsp->fl_wwnn;
492 fc_host_port_id(shost) = ntoh24(bottom->s_id);
493 fc_host_speed(shost) = bottom->fc_link_speed;
494 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
496 adapter->hydra_version = bottom->adapter_type;
497 adapter->timer_ticks = bottom->timer_interval;
499 if (fc_host_permanent_port_name(shost) == -1)
500 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
502 switch (bottom->fc_topology) {
504 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
505 adapter->peer_wwpn = plogi->fl_wwpn;
506 adapter->peer_wwnn = plogi->fl_wwnn;
507 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
509 case FSF_TOPO_FABRIC:
510 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
513 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
516 dev_err(&adapter->ccw_device->dev,
517 "Unknown or unsupported arbitrated loop "
518 "fibre channel topology detected\n");
519 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
526 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
528 struct zfcp_adapter *adapter = req->adapter;
529 struct fsf_qtcb *qtcb = req->qtcb;
530 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
531 struct Scsi_Host *shost = adapter->scsi_host;
533 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
536 adapter->fsf_lic_version = bottom->lic_version;
537 adapter->adapter_features = bottom->adapter_features;
538 adapter->connection_features = bottom->connection_features;
539 adapter->peer_wwpn = 0;
540 adapter->peer_wwnn = 0;
541 adapter->peer_d_id = 0;
543 switch (qtcb->header.fsf_status) {
545 if (zfcp_fsf_exchange_config_evaluate(req))
548 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
549 dev_err(&adapter->ccw_device->dev,
550 "FCP adapter maximum QTCB size (%d bytes) "
552 bottom->max_qtcb_size);
553 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
556 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
559 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
560 fc_host_node_name(shost) = 0;
561 fc_host_port_name(shost) = 0;
562 fc_host_port_id(shost) = 0;
563 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
564 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
565 adapter->hydra_version = 0;
567 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
570 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
571 &qtcb->header.fsf_status_qual.link_down_info);
574 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
578 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
579 adapter->hardware_version = bottom->hardware_version;
580 memcpy(fc_host_serial_number(shost), bottom->serial_number,
581 min(FC_SERIAL_NUMBER_SIZE, 17));
582 EBCASC(fc_host_serial_number(shost),
583 min(FC_SERIAL_NUMBER_SIZE, 17));
586 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
587 dev_err(&adapter->ccw_device->dev,
588 "The FCP adapter only supports newer "
589 "control block versions\n");
590 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
593 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
594 dev_err(&adapter->ccw_device->dev,
595 "The FCP adapter only supports older "
596 "control block versions\n");
597 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
601 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
603 struct zfcp_adapter *adapter = req->adapter;
604 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
605 struct Scsi_Host *shost = adapter->scsi_host;
608 memcpy(req->data, bottom, sizeof(*bottom));
610 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
611 fc_host_permanent_port_name(shost) = bottom->wwpn;
612 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
614 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
615 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
616 fc_host_supported_speeds(shost) = bottom->supported_speed;
617 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
619 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
623 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
625 struct fsf_qtcb *qtcb = req->qtcb;
627 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
630 switch (qtcb->header.fsf_status) {
632 zfcp_fsf_exchange_port_evaluate(req);
634 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
635 zfcp_fsf_exchange_port_evaluate(req);
636 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
637 &qtcb->header.fsf_status_qual.link_down_info);
642 static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
644 struct zfcp_qdio_queue *req_q = &qdio->req_q;
646 spin_lock_bh(&qdio->req_q_lock);
647 if (atomic_read(&req_q->count))
649 spin_unlock_bh(&qdio->req_q_lock);
653 static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
655 struct zfcp_adapter *adapter = qdio->adapter;
658 spin_unlock_bh(&qdio->req_q_lock);
659 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
660 zfcp_fsf_sbal_check(qdio), 5 * HZ);
664 atomic_inc(&qdio->req_q_full);
665 /* assume hanging outbound queue, try queue recovery */
666 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
669 spin_lock_bh(&qdio->req_q_lock);
673 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
675 struct zfcp_fsf_req *req;
678 req = mempool_alloc(pool, GFP_ATOMIC);
680 req = kmalloc(sizeof(*req), GFP_ATOMIC);
685 memset(req, 0, sizeof(*req));
690 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
692 struct fsf_qtcb *qtcb;
695 qtcb = mempool_alloc(pool, GFP_ATOMIC);
697 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
702 memset(qtcb, 0, sizeof(*qtcb));
706 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
707 u32 fsf_cmd, mempool_t *pool)
709 struct qdio_buffer_element *sbale;
710 struct zfcp_qdio_queue *req_q = &qdio->req_q;
711 struct zfcp_adapter *adapter = qdio->adapter;
712 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
715 return ERR_PTR(-ENOMEM);
717 if (adapter->req_no == 0)
720 INIT_LIST_HEAD(&req->list);
721 init_timer(&req->timer);
722 init_completion(&req->completion);
724 req->adapter = adapter;
725 req->fsf_command = fsf_cmd;
726 req->req_id = adapter->req_no;
727 req->qdio_req.sbal_number = 1;
728 req->qdio_req.sbal_first = req_q->first;
729 req->qdio_req.sbal_last = req_q->first;
730 req->qdio_req.sbale_curr = 1;
732 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
733 sbale[0].addr = (void *) req->req_id;
734 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
736 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
738 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
740 req->qtcb = zfcp_qtcb_alloc(NULL);
742 if (unlikely(!req->qtcb)) {
743 zfcp_fsf_req_free(req);
744 return ERR_PTR(-ENOMEM);
747 req->seq_no = adapter->fsf_req_seq_no;
748 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
749 req->qtcb->prefix.req_id = req->req_id;
750 req->qtcb->prefix.ulp_info = 26;
751 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
752 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
753 req->qtcb->header.req_handle = req->req_id;
754 req->qtcb->header.fsf_command = req->fsf_command;
755 sbale[1].addr = (void *) req->qtcb;
756 sbale[1].length = sizeof(struct fsf_qtcb);
759 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
760 zfcp_fsf_req_free(req);
761 return ERR_PTR(-EIO);
767 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
769 struct zfcp_adapter *adapter = req->adapter;
770 struct zfcp_qdio *qdio = adapter->qdio;
771 int with_qtcb = (req->qtcb != NULL);
772 int req_id = req->req_id;
774 zfcp_reqlist_add(adapter->req_list, req);
776 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
777 req->issued = get_clock();
778 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
779 del_timer(&req->timer);
780 /* lookup request again, list might have changed */
781 zfcp_reqlist_find_rm(adapter->req_list, req_id);
782 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
786 /* Don't increase for unsolicited status */
788 adapter->fsf_req_seq_no++;
795 * zfcp_fsf_status_read - send status read request
796 * @adapter: pointer to struct zfcp_adapter
797 * @req_flags: request flags
798 * Returns: 0 on success, ERROR otherwise
800 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
802 struct zfcp_adapter *adapter = qdio->adapter;
803 struct zfcp_fsf_req *req;
804 struct fsf_status_read_buffer *sr_buf;
805 struct qdio_buffer_element *sbale;
808 spin_lock_bh(&qdio->req_q_lock);
809 if (zfcp_fsf_req_sbal_get(qdio))
812 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
813 adapter->pool.status_read_req);
815 retval = PTR_ERR(req);
819 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
820 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
821 req->qdio_req.sbale_curr = 2;
823 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
828 memset(sr_buf, 0, sizeof(*sr_buf));
830 sbale = zfcp_qdio_sbale_curr(qdio, &req->qdio_req);
831 sbale->addr = (void *) sr_buf;
832 sbale->length = sizeof(*sr_buf);
834 retval = zfcp_fsf_req_send(req);
836 goto failed_req_send;
841 mempool_free(sr_buf, adapter->pool.status_read_data);
843 zfcp_fsf_req_free(req);
844 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
846 spin_unlock_bh(&qdio->req_q_lock);
850 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
852 struct zfcp_unit *unit = req->data;
853 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
855 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
858 switch (req->qtcb->header.fsf_status) {
859 case FSF_PORT_HANDLE_NOT_VALID:
860 if (fsq->word[0] == fsq->word[1]) {
861 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
863 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
866 case FSF_LUN_HANDLE_NOT_VALID:
867 if (fsq->word[0] == fsq->word[1]) {
868 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
872 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
873 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
876 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
877 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
880 zfcp_erp_unit_boxed(unit, "fsafch4", req);
881 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
883 case FSF_ADAPTER_STATUS_AVAILABLE:
884 switch (fsq->word[0]) {
885 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
886 zfcp_fc_test_link(unit->port);
888 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
889 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
894 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
900 * zfcp_fsf_abort_fcp_command - abort running SCSI command
901 * @old_req_id: unsigned long
902 * @unit: pointer to struct zfcp_unit
903 * Returns: pointer to struct zfcp_fsf_req
906 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
907 struct zfcp_unit *unit)
909 struct qdio_buffer_element *sbale;
910 struct zfcp_fsf_req *req = NULL;
911 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
913 spin_lock_bh(&qdio->req_q_lock);
914 if (zfcp_fsf_req_sbal_get(qdio))
916 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
917 qdio->adapter->pool.scsi_abort);
923 if (unlikely(!(atomic_read(&unit->status) &
924 ZFCP_STATUS_COMMON_UNBLOCKED)))
927 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
928 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
929 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
932 req->handler = zfcp_fsf_abort_fcp_command_handler;
933 req->qtcb->header.lun_handle = unit->handle;
934 req->qtcb->header.port_handle = unit->port->handle;
935 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
937 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
938 if (!zfcp_fsf_req_send(req))
942 zfcp_fsf_req_free(req);
945 spin_unlock_bh(&qdio->req_q_lock);
949 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
951 struct zfcp_adapter *adapter = req->adapter;
952 struct zfcp_fsf_ct_els *ct = req->data;
953 struct fsf_qtcb_header *header = &req->qtcb->header;
955 ct->status = -EINVAL;
957 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
960 switch (header->fsf_status) {
962 zfcp_dbf_san_ct_response(req);
965 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
966 zfcp_fsf_class_not_supp(req);
968 case FSF_ADAPTER_STATUS_AVAILABLE:
969 switch (header->fsf_status_qual.word[0]){
970 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
971 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
972 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
976 case FSF_ACCESS_DENIED:
979 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
981 case FSF_PORT_HANDLE_NOT_VALID:
982 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
984 case FSF_GENERIC_COMMAND_REJECTED:
985 case FSF_PAYLOAD_SIZE_MISMATCH:
986 case FSF_REQUEST_SIZE_TOO_LARGE:
987 case FSF_RESPONSE_SIZE_TOO_LARGE:
988 case FSF_SBAL_MISMATCH:
989 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
995 ct->handler(ct->handler_data);
998 static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
999 struct scatterlist *sg_req,
1000 struct scatterlist *sg_resp)
1002 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1003 sbale[2].addr = sg_virt(sg_req);
1004 sbale[2].length = sg_req->length;
1005 sbale[3].addr = sg_virt(sg_resp);
1006 sbale[3].length = sg_resp->length;
1007 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1010 static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1012 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1015 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1016 struct scatterlist *sg_req,
1017 struct scatterlist *sg_resp,
1020 struct zfcp_adapter *adapter = req->adapter;
1021 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
1023 u32 feat = adapter->adapter_features;
1026 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1027 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
1030 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1034 /* use single, unchained SBAL if it can hold the request */
1035 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1036 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1040 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
1041 SBAL_FLAGS0_TYPE_WRITE_READ,
1045 req->qtcb->bottom.support.req_buf_length = bytes;
1046 req->qdio_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1048 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
1049 SBAL_FLAGS0_TYPE_WRITE_READ,
1050 sg_resp, max_sbals);
1051 req->qtcb->bottom.support.resp_buf_length = bytes;
1058 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1059 struct scatterlist *sg_req,
1060 struct scatterlist *sg_resp,
1061 int max_sbals, unsigned int timeout)
1065 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1069 /* common settings for ct/gs and els requests */
1071 timeout = 255; /* max value accepted by hardware */
1072 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1073 req->qtcb->bottom.support.timeout = timeout;
1074 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1080 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1081 * @ct: pointer to struct zfcp_send_ct with data for request
1082 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1084 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1085 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1086 unsigned int timeout)
1088 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1089 struct zfcp_fsf_req *req;
1092 spin_lock_bh(&qdio->req_q_lock);
1093 if (zfcp_fsf_req_sbal_get(qdio))
1096 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
1103 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1104 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
1105 FSF_MAX_SBALS_PER_REQ, timeout);
1109 req->handler = zfcp_fsf_send_ct_handler;
1110 req->qtcb->header.port_handle = wka_port->handle;
1113 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1115 ret = zfcp_fsf_req_send(req);
1122 zfcp_fsf_req_free(req);
1124 spin_unlock_bh(&qdio->req_q_lock);
1128 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1130 struct zfcp_fsf_ct_els *send_els = req->data;
1131 struct zfcp_port *port = send_els->port;
1132 struct fsf_qtcb_header *header = &req->qtcb->header;
1134 send_els->status = -EINVAL;
1136 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1137 goto skip_fsfstatus;
1139 switch (header->fsf_status) {
1141 zfcp_dbf_san_els_response(req);
1142 send_els->status = 0;
1144 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1145 zfcp_fsf_class_not_supp(req);
1147 case FSF_ADAPTER_STATUS_AVAILABLE:
1148 switch (header->fsf_status_qual.word[0]){
1149 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1150 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1151 case FSF_SQ_RETRY_IF_POSSIBLE:
1152 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1156 case FSF_ELS_COMMAND_REJECTED:
1157 case FSF_PAYLOAD_SIZE_MISMATCH:
1158 case FSF_REQUEST_SIZE_TOO_LARGE:
1159 case FSF_RESPONSE_SIZE_TOO_LARGE:
1161 case FSF_ACCESS_DENIED:
1163 zfcp_fsf_access_denied_port(req, port);
1165 case FSF_SBAL_MISMATCH:
1166 /* should never occure, avoided in zfcp_fsf_send_els */
1169 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1173 if (send_els->handler)
1174 send_els->handler(send_els->handler_data);
1178 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1179 * @els: pointer to struct zfcp_send_els with data for the command
1181 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1182 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1184 struct zfcp_fsf_req *req;
1185 struct zfcp_qdio *qdio = adapter->qdio;
1188 spin_lock_bh(&qdio->req_q_lock);
1189 if (zfcp_fsf_req_sbal_get(qdio))
1192 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
1199 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1200 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
1205 hton24(req->qtcb->bottom.support.d_id, d_id);
1206 req->handler = zfcp_fsf_send_els_handler;
1209 zfcp_dbf_san_els_request(req);
1211 ret = zfcp_fsf_req_send(req);
1218 zfcp_fsf_req_free(req);
1220 spin_unlock_bh(&qdio->req_q_lock);
1224 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1226 struct qdio_buffer_element *sbale;
1227 struct zfcp_fsf_req *req;
1228 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1231 spin_lock_bh(&qdio->req_q_lock);
1232 if (zfcp_fsf_req_sbal_get(qdio))
1235 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1236 qdio->adapter->pool.erp_req);
1239 retval = PTR_ERR(req);
1243 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1244 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1245 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1246 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1248 req->qtcb->bottom.config.feature_selection =
1250 FSF_FEATURE_LUN_SHARING |
1251 FSF_FEATURE_NOTIFICATION_LOST |
1252 FSF_FEATURE_UPDATE_ALERT;
1253 req->erp_action = erp_action;
1254 req->handler = zfcp_fsf_exchange_config_data_handler;
1255 erp_action->fsf_req_id = req->req_id;
1257 zfcp_fsf_start_erp_timer(req);
1258 retval = zfcp_fsf_req_send(req);
1260 zfcp_fsf_req_free(req);
1261 erp_action->fsf_req_id = 0;
1264 spin_unlock_bh(&qdio->req_q_lock);
1268 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1269 struct fsf_qtcb_bottom_config *data)
1271 struct qdio_buffer_element *sbale;
1272 struct zfcp_fsf_req *req = NULL;
1275 spin_lock_bh(&qdio->req_q_lock);
1276 if (zfcp_fsf_req_sbal_get(qdio))
1279 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
1282 retval = PTR_ERR(req);
1286 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1287 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1288 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1289 req->handler = zfcp_fsf_exchange_config_data_handler;
1291 req->qtcb->bottom.config.feature_selection =
1293 FSF_FEATURE_LUN_SHARING |
1294 FSF_FEATURE_NOTIFICATION_LOST |
1295 FSF_FEATURE_UPDATE_ALERT;
1300 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1301 retval = zfcp_fsf_req_send(req);
1302 spin_unlock_bh(&qdio->req_q_lock);
1304 wait_for_completion(&req->completion);
1306 zfcp_fsf_req_free(req);
1310 spin_unlock_bh(&qdio->req_q_lock);
1315 * zfcp_fsf_exchange_port_data - request information about local port
1316 * @erp_action: ERP action for the adapter for which port data is requested
1317 * Returns: 0 on success, error otherwise
1319 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1321 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1322 struct qdio_buffer_element *sbale;
1323 struct zfcp_fsf_req *req;
1326 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1329 spin_lock_bh(&qdio->req_q_lock);
1330 if (zfcp_fsf_req_sbal_get(qdio))
1333 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1334 qdio->adapter->pool.erp_req);
1337 retval = PTR_ERR(req);
1341 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1342 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1343 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1344 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1346 req->handler = zfcp_fsf_exchange_port_data_handler;
1347 req->erp_action = erp_action;
1348 erp_action->fsf_req_id = req->req_id;
1350 zfcp_fsf_start_erp_timer(req);
1351 retval = zfcp_fsf_req_send(req);
1353 zfcp_fsf_req_free(req);
1354 erp_action->fsf_req_id = 0;
1357 spin_unlock_bh(&qdio->req_q_lock);
1362 * zfcp_fsf_exchange_port_data_sync - request information about local port
1363 * @qdio: pointer to struct zfcp_qdio
1364 * @data: pointer to struct fsf_qtcb_bottom_port
1365 * Returns: 0 on success, error otherwise
1367 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1368 struct fsf_qtcb_bottom_port *data)
1370 struct qdio_buffer_element *sbale;
1371 struct zfcp_fsf_req *req = NULL;
1374 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1377 spin_lock_bh(&qdio->req_q_lock);
1378 if (zfcp_fsf_req_sbal_get(qdio))
1381 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
1384 retval = PTR_ERR(req);
1391 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1392 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1393 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1395 req->handler = zfcp_fsf_exchange_port_data_handler;
1396 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1397 retval = zfcp_fsf_req_send(req);
1398 spin_unlock_bh(&qdio->req_q_lock);
1401 wait_for_completion(&req->completion);
1403 zfcp_fsf_req_free(req);
1408 spin_unlock_bh(&qdio->req_q_lock);
1412 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1414 struct zfcp_port *port = req->data;
1415 struct fsf_qtcb_header *header = &req->qtcb->header;
1416 struct fc_els_flogi *plogi;
1418 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1421 switch (header->fsf_status) {
1422 case FSF_PORT_ALREADY_OPEN:
1424 case FSF_ACCESS_DENIED:
1425 zfcp_fsf_access_denied_port(req, port);
1427 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1428 dev_warn(&req->adapter->ccw_device->dev,
1429 "Not enough FCP adapter resources to open "
1430 "remote port 0x%016Lx\n",
1431 (unsigned long long)port->wwpn);
1432 zfcp_erp_port_failed(port, "fsoph_1", req);
1433 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1435 case FSF_ADAPTER_STATUS_AVAILABLE:
1436 switch (header->fsf_status_qual.word[0]) {
1437 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1438 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1439 case FSF_SQ_NO_RETRY_POSSIBLE:
1440 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1445 port->handle = header->port_handle;
1446 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1447 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1448 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1449 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1451 /* check whether D_ID has changed during open */
1453 * FIXME: This check is not airtight, as the FCP channel does
1454 * not monitor closures of target port connections caused on
1455 * the remote side. Thus, they might miss out on invalidating
1456 * locally cached WWPNs (and other N_Port parameters) of gone
1457 * target ports. So, our heroic attempt to make things safe
1458 * could be undermined by 'open port' response data tagged with
1459 * obsolete WWPNs. Another reason to monitor potential
1460 * connection closures ourself at least (by interpreting
1461 * incoming ELS' and unsolicited status). It just crosses my
1462 * mind that one should be able to cross-check by means of
1463 * another GID_PN straight after a port has been opened.
1464 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1466 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1467 if (req->qtcb->bottom.support.els1_length >=
1469 zfcp_fc_plogi_evaluate(port, plogi);
1471 case FSF_UNKNOWN_OP_SUBTYPE:
1472 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1477 put_device(&port->dev);
1481 * zfcp_fsf_open_port - create and send open port request
1482 * @erp_action: pointer to struct zfcp_erp_action
1483 * Returns: 0 on success, error otherwise
1485 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1487 struct qdio_buffer_element *sbale;
1488 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1489 struct zfcp_port *port = erp_action->port;
1490 struct zfcp_fsf_req *req;
1493 spin_lock_bh(&qdio->req_q_lock);
1494 if (zfcp_fsf_req_sbal_get(qdio))
1497 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1498 qdio->adapter->pool.erp_req);
1501 retval = PTR_ERR(req);
1505 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1506 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1507 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1508 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1510 req->handler = zfcp_fsf_open_port_handler;
1511 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1513 req->erp_action = erp_action;
1514 erp_action->fsf_req_id = req->req_id;
1515 get_device(&port->dev);
1517 zfcp_fsf_start_erp_timer(req);
1518 retval = zfcp_fsf_req_send(req);
1520 zfcp_fsf_req_free(req);
1521 erp_action->fsf_req_id = 0;
1522 put_device(&port->dev);
1525 spin_unlock_bh(&qdio->req_q_lock);
1529 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1531 struct zfcp_port *port = req->data;
1533 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1536 switch (req->qtcb->header.fsf_status) {
1537 case FSF_PORT_HANDLE_NOT_VALID:
1538 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1539 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1541 case FSF_ADAPTER_STATUS_AVAILABLE:
1544 zfcp_erp_modify_port_status(port, "fscph_2", req,
1545 ZFCP_STATUS_COMMON_OPEN,
1552 * zfcp_fsf_close_port - create and send close port request
1553 * @erp_action: pointer to struct zfcp_erp_action
1554 * Returns: 0 on success, error otherwise
1556 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1558 struct qdio_buffer_element *sbale;
1559 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1560 struct zfcp_fsf_req *req;
1563 spin_lock_bh(&qdio->req_q_lock);
1564 if (zfcp_fsf_req_sbal_get(qdio))
1567 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1568 qdio->adapter->pool.erp_req);
1571 retval = PTR_ERR(req);
1575 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1576 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1577 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1578 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1580 req->handler = zfcp_fsf_close_port_handler;
1581 req->data = erp_action->port;
1582 req->erp_action = erp_action;
1583 req->qtcb->header.port_handle = erp_action->port->handle;
1584 erp_action->fsf_req_id = req->req_id;
1586 zfcp_fsf_start_erp_timer(req);
1587 retval = zfcp_fsf_req_send(req);
1589 zfcp_fsf_req_free(req);
1590 erp_action->fsf_req_id = 0;
1593 spin_unlock_bh(&qdio->req_q_lock);
1597 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1599 struct zfcp_fc_wka_port *wka_port = req->data;
1600 struct fsf_qtcb_header *header = &req->qtcb->header;
1602 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1603 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1607 switch (header->fsf_status) {
1608 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1609 dev_warn(&req->adapter->ccw_device->dev,
1610 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1612 case FSF_ADAPTER_STATUS_AVAILABLE:
1613 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1615 case FSF_ACCESS_DENIED:
1616 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1619 wka_port->handle = header->port_handle;
1621 case FSF_PORT_ALREADY_OPEN:
1622 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1625 wake_up(&wka_port->completion_wq);
1629 * zfcp_fsf_open_wka_port - create and send open wka-port request
1630 * @wka_port: pointer to struct zfcp_fc_wka_port
1631 * Returns: 0 on success, error otherwise
1633 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1635 struct qdio_buffer_element *sbale;
1636 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1637 struct zfcp_fsf_req *req;
1640 spin_lock_bh(&qdio->req_q_lock);
1641 if (zfcp_fsf_req_sbal_get(qdio))
1644 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1645 qdio->adapter->pool.erp_req);
1647 if (unlikely(IS_ERR(req))) {
1648 retval = PTR_ERR(req);
1652 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1653 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1654 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1655 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1657 req->handler = zfcp_fsf_open_wka_port_handler;
1658 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1659 req->data = wka_port;
1661 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1662 retval = zfcp_fsf_req_send(req);
1664 zfcp_fsf_req_free(req);
1666 spin_unlock_bh(&qdio->req_q_lock);
1670 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1672 struct zfcp_fc_wka_port *wka_port = req->data;
1674 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1675 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1676 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1679 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1680 wake_up(&wka_port->completion_wq);
1684 * zfcp_fsf_close_wka_port - create and send close wka port request
1685 * @wka_port: WKA port to open
1686 * Returns: 0 on success, error otherwise
1688 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1690 struct qdio_buffer_element *sbale;
1691 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1692 struct zfcp_fsf_req *req;
1695 spin_lock_bh(&qdio->req_q_lock);
1696 if (zfcp_fsf_req_sbal_get(qdio))
1699 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1700 qdio->adapter->pool.erp_req);
1702 if (unlikely(IS_ERR(req))) {
1703 retval = PTR_ERR(req);
1707 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1708 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1709 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1710 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1712 req->handler = zfcp_fsf_close_wka_port_handler;
1713 req->data = wka_port;
1714 req->qtcb->header.port_handle = wka_port->handle;
1716 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1717 retval = zfcp_fsf_req_send(req);
1719 zfcp_fsf_req_free(req);
1721 spin_unlock_bh(&qdio->req_q_lock);
1725 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1727 struct zfcp_port *port = req->data;
1728 struct fsf_qtcb_header *header = &req->qtcb->header;
1729 struct zfcp_unit *unit;
1731 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1734 switch (header->fsf_status) {
1735 case FSF_PORT_HANDLE_NOT_VALID:
1736 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1737 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1739 case FSF_ACCESS_DENIED:
1740 zfcp_fsf_access_denied_port(req, port);
1742 case FSF_PORT_BOXED:
1743 /* can't use generic zfcp_erp_modify_port_status because
1744 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1745 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1746 read_lock(&port->unit_list_lock);
1747 list_for_each_entry(unit, &port->unit_list, list)
1748 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1750 read_unlock(&port->unit_list_lock);
1751 zfcp_erp_port_boxed(port, "fscpph2", req);
1752 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1754 case FSF_ADAPTER_STATUS_AVAILABLE:
1755 switch (header->fsf_status_qual.word[0]) {
1756 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1758 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1759 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1764 /* can't use generic zfcp_erp_modify_port_status because
1765 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1767 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1768 read_lock(&port->unit_list_lock);
1769 list_for_each_entry(unit, &port->unit_list, list)
1770 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1772 read_unlock(&port->unit_list_lock);
1778 * zfcp_fsf_close_physical_port - close physical port
1779 * @erp_action: pointer to struct zfcp_erp_action
1780 * Returns: 0 on success
1782 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1784 struct qdio_buffer_element *sbale;
1785 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1786 struct zfcp_fsf_req *req;
1789 spin_lock_bh(&qdio->req_q_lock);
1790 if (zfcp_fsf_req_sbal_get(qdio))
1793 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1794 qdio->adapter->pool.erp_req);
1797 retval = PTR_ERR(req);
1801 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1802 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1803 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1804 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1806 req->data = erp_action->port;
1807 req->qtcb->header.port_handle = erp_action->port->handle;
1808 req->erp_action = erp_action;
1809 req->handler = zfcp_fsf_close_physical_port_handler;
1810 erp_action->fsf_req_id = req->req_id;
1812 zfcp_fsf_start_erp_timer(req);
1813 retval = zfcp_fsf_req_send(req);
1815 zfcp_fsf_req_free(req);
1816 erp_action->fsf_req_id = 0;
1819 spin_unlock_bh(&qdio->req_q_lock);
1823 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1825 struct zfcp_adapter *adapter = req->adapter;
1826 struct zfcp_unit *unit = req->data;
1827 struct fsf_qtcb_header *header = &req->qtcb->header;
1828 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1829 struct fsf_queue_designator *queue_designator =
1830 &header->fsf_status_qual.fsf_queue_designator;
1831 int exclusive, readwrite;
1833 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1836 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1837 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1838 ZFCP_STATUS_UNIT_SHARED |
1839 ZFCP_STATUS_UNIT_READONLY,
1842 switch (header->fsf_status) {
1844 case FSF_PORT_HANDLE_NOT_VALID:
1845 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1847 case FSF_LUN_ALREADY_OPEN:
1849 case FSF_ACCESS_DENIED:
1850 zfcp_fsf_access_denied_unit(req, unit);
1851 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1852 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1854 case FSF_PORT_BOXED:
1855 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1856 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1858 case FSF_LUN_SHARING_VIOLATION:
1859 if (header->fsf_status_qual.word[0])
1860 dev_warn(&adapter->ccw_device->dev,
1861 "LUN 0x%Lx on port 0x%Lx is already in "
1862 "use by CSS%d, MIF Image ID %x\n",
1863 (unsigned long long)unit->fcp_lun,
1864 (unsigned long long)unit->port->wwpn,
1865 queue_designator->cssid,
1866 queue_designator->hla);
1868 zfcp_act_eval_err(adapter,
1869 header->fsf_status_qual.word[2]);
1870 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1871 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1872 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1873 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1875 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1876 dev_warn(&adapter->ccw_device->dev,
1877 "No handle is available for LUN "
1878 "0x%016Lx on port 0x%016Lx\n",
1879 (unsigned long long)unit->fcp_lun,
1880 (unsigned long long)unit->port->wwpn);
1881 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1883 case FSF_INVALID_COMMAND_OPTION:
1884 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1886 case FSF_ADAPTER_STATUS_AVAILABLE:
1887 switch (header->fsf_status_qual.word[0]) {
1888 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1889 zfcp_fc_test_link(unit->port);
1891 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1892 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1898 unit->handle = header->lun_handle;
1899 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1901 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1902 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1903 !zfcp_ccw_priv_sch(adapter)) {
1904 exclusive = (bottom->lun_access_info &
1905 FSF_UNIT_ACCESS_EXCLUSIVE);
1906 readwrite = (bottom->lun_access_info &
1907 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1910 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1914 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1916 dev_info(&adapter->ccw_device->dev,
1917 "SCSI device at LUN 0x%016Lx on port "
1918 "0x%016Lx opened read-only\n",
1919 (unsigned long long)unit->fcp_lun,
1920 (unsigned long long)unit->port->wwpn);
1923 if (exclusive && !readwrite) {
1924 dev_err(&adapter->ccw_device->dev,
1925 "Exclusive read-only access not "
1926 "supported (unit 0x%016Lx, "
1928 (unsigned long long)unit->fcp_lun,
1929 (unsigned long long)unit->port->wwpn);
1930 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1931 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1932 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1933 } else if (!exclusive && readwrite) {
1934 dev_err(&adapter->ccw_device->dev,
1935 "Shared read-write access not "
1936 "supported (unit 0x%016Lx, port "
1938 (unsigned long long)unit->fcp_lun,
1939 (unsigned long long)unit->port->wwpn);
1940 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1941 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1942 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1950 * zfcp_fsf_open_unit - open unit
1951 * @erp_action: pointer to struct zfcp_erp_action
1952 * Returns: 0 on success, error otherwise
1954 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1956 struct qdio_buffer_element *sbale;
1957 struct zfcp_adapter *adapter = erp_action->adapter;
1958 struct zfcp_qdio *qdio = adapter->qdio;
1959 struct zfcp_fsf_req *req;
1962 spin_lock_bh(&qdio->req_q_lock);
1963 if (zfcp_fsf_req_sbal_get(qdio))
1966 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1967 adapter->pool.erp_req);
1970 retval = PTR_ERR(req);
1974 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1975 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1976 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1977 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1979 req->qtcb->header.port_handle = erp_action->port->handle;
1980 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1981 req->handler = zfcp_fsf_open_unit_handler;
1982 req->data = erp_action->unit;
1983 req->erp_action = erp_action;
1984 erp_action->fsf_req_id = req->req_id;
1986 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1987 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1989 zfcp_fsf_start_erp_timer(req);
1990 retval = zfcp_fsf_req_send(req);
1992 zfcp_fsf_req_free(req);
1993 erp_action->fsf_req_id = 0;
1996 spin_unlock_bh(&qdio->req_q_lock);
2000 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
2002 struct zfcp_unit *unit = req->data;
2004 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2007 switch (req->qtcb->header.fsf_status) {
2008 case FSF_PORT_HANDLE_NOT_VALID:
2009 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
2010 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2012 case FSF_LUN_HANDLE_NOT_VALID:
2013 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
2014 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2016 case FSF_PORT_BOXED:
2017 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2018 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2020 case FSF_ADAPTER_STATUS_AVAILABLE:
2021 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2022 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2023 zfcp_fc_test_link(unit->port);
2025 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2026 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2031 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2037 * zfcp_fsf_close_unit - close zfcp unit
2038 * @erp_action: pointer to struct zfcp_unit
2039 * Returns: 0 on success, error otherwise
2041 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2043 struct qdio_buffer_element *sbale;
2044 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2045 struct zfcp_fsf_req *req;
2048 spin_lock_bh(&qdio->req_q_lock);
2049 if (zfcp_fsf_req_sbal_get(qdio))
2052 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2053 qdio->adapter->pool.erp_req);
2056 retval = PTR_ERR(req);
2060 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2061 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
2062 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2063 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2065 req->qtcb->header.port_handle = erp_action->port->handle;
2066 req->qtcb->header.lun_handle = erp_action->unit->handle;
2067 req->handler = zfcp_fsf_close_unit_handler;
2068 req->data = erp_action->unit;
2069 req->erp_action = erp_action;
2070 erp_action->fsf_req_id = req->req_id;
2072 zfcp_fsf_start_erp_timer(req);
2073 retval = zfcp_fsf_req_send(req);
2075 zfcp_fsf_req_free(req);
2076 erp_action->fsf_req_id = 0;
2079 spin_unlock_bh(&qdio->req_q_lock);
2083 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2085 lat_rec->sum += lat;
2086 lat_rec->min = min(lat_rec->min, lat);
2087 lat_rec->max = max(lat_rec->max, lat);
2090 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2092 struct fsf_qual_latency_info *lat_in;
2093 struct latency_cont *lat = NULL;
2094 struct zfcp_unit *unit = req->unit;
2095 struct zfcp_blk_drv_data blktrc;
2096 int ticks = req->adapter->timer_ticks;
2098 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2101 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2102 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2103 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2104 blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
2105 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
2107 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2108 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2109 blktrc.channel_lat = lat_in->channel_lat * ticks;
2110 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
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;
2125 spin_lock(&unit->latencies.lock);
2126 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2127 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2129 spin_unlock(&unit->latencies.lock);
2133 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2137 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2139 struct scsi_cmnd *scpnt;
2140 struct fcp_resp_with_ext *fcp_rsp;
2141 unsigned long flags;
2143 read_lock_irqsave(&req->adapter->abort_lock, flags);
2146 if (unlikely(!scpnt)) {
2147 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2151 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2152 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2153 goto skip_fsfstatus;
2156 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2157 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2159 zfcp_fsf_req_trace(req, scpnt);
2162 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
2164 scpnt->host_scribble = NULL;
2165 (scpnt->scsi_done) (scpnt);
2167 * We must hold this lock until scsi_done has been called.
2168 * Otherwise we may call scsi_done after abort regarding this
2169 * command has completed.
2170 * Note: scsi_done must not block!
2172 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2175 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2177 struct fcp_resp_with_ext *fcp_rsp;
2178 struct fcp_resp_rsp_info *rsp_info;
2180 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2181 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2183 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2184 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2185 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2189 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2191 struct zfcp_unit *unit;
2192 struct fsf_qtcb_header *header = &req->qtcb->header;
2194 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2199 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2200 goto skip_fsfstatus;
2202 switch (header->fsf_status) {
2203 case FSF_HANDLE_MISMATCH:
2204 case FSF_PORT_HANDLE_NOT_VALID:
2205 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2206 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2208 case FSF_FCPLUN_NOT_VALID:
2209 case FSF_LUN_HANDLE_NOT_VALID:
2210 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2211 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2213 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2214 zfcp_fsf_class_not_supp(req);
2216 case FSF_ACCESS_DENIED:
2217 zfcp_fsf_access_denied_unit(req, unit);
2219 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2220 dev_err(&req->adapter->ccw_device->dev,
2221 "Incorrect direction %d, unit 0x%016Lx on port "
2222 "0x%016Lx closed\n",
2223 req->qtcb->bottom.io.data_direction,
2224 (unsigned long long)unit->fcp_lun,
2225 (unsigned long long)unit->port->wwpn);
2226 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2228 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2230 case FSF_CMND_LENGTH_NOT_VALID:
2231 dev_err(&req->adapter->ccw_device->dev,
2232 "Incorrect CDB length %d, unit 0x%016Lx on "
2233 "port 0x%016Lx closed\n",
2234 req->qtcb->bottom.io.fcp_cmnd_length,
2235 (unsigned long long)unit->fcp_lun,
2236 (unsigned long long)unit->port->wwpn);
2237 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2239 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2241 case FSF_PORT_BOXED:
2242 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2243 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2246 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2247 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2249 case FSF_ADAPTER_STATUS_AVAILABLE:
2250 if (header->fsf_status_qual.word[0] ==
2251 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2252 zfcp_fc_test_link(unit->port);
2253 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2257 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2258 zfcp_fsf_send_fcp_ctm_handler(req);
2260 zfcp_fsf_send_fcp_command_task_handler(req);
2262 put_device(&unit->dev);
2267 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2268 * @unit: unit where command is sent to
2269 * @scsi_cmnd: scsi command to be sent
2271 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2272 struct scsi_cmnd *scsi_cmnd)
2274 struct zfcp_fsf_req *req;
2275 struct fcp_cmnd *fcp_cmnd;
2276 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2277 int real_bytes, retval = -EIO;
2278 struct zfcp_adapter *adapter = unit->port->adapter;
2279 struct zfcp_qdio *qdio = adapter->qdio;
2281 if (unlikely(!(atomic_read(&unit->status) &
2282 ZFCP_STATUS_COMMON_UNBLOCKED)))
2285 spin_lock(&qdio->req_q_lock);
2286 if (atomic_read(&qdio->req_q.count) <= 0) {
2287 atomic_inc(&qdio->req_q_full);
2291 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2292 adapter->pool.scsi_req);
2295 retval = PTR_ERR(req);
2299 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2300 get_device(&unit->dev);
2302 req->data = scsi_cmnd;
2303 req->handler = zfcp_fsf_send_fcp_command_handler;
2304 req->qtcb->header.lun_handle = unit->handle;
2305 req->qtcb->header.port_handle = unit->port->handle;
2306 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2307 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2309 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2312 * set depending on data direction:
2313 * data direction bits in SBALE (SB Type)
2314 * data direction bits in QTCB
2316 switch (scsi_cmnd->sc_data_direction) {
2318 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2320 case DMA_FROM_DEVICE:
2321 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2324 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2325 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2327 case DMA_BIDIRECTIONAL:
2328 goto failed_scsi_cmnd;
2331 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2332 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2334 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sbtype,
2335 scsi_sglist(scsi_cmnd),
2336 FSF_MAX_SBALS_PER_REQ);
2337 if (unlikely(real_bytes < 0)) {
2338 if (req->qdio_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2339 dev_err(&adapter->ccw_device->dev,
2340 "Oversize data package, unit 0x%016Lx "
2341 "on port 0x%016Lx closed\n",
2342 (unsigned long long)unit->fcp_lun,
2343 (unsigned long long)unit->port->wwpn);
2344 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
2347 goto failed_scsi_cmnd;
2350 retval = zfcp_fsf_req_send(req);
2351 if (unlikely(retval))
2352 goto failed_scsi_cmnd;
2357 put_device(&unit->dev);
2358 zfcp_fsf_req_free(req);
2359 scsi_cmnd->host_scribble = NULL;
2361 spin_unlock(&qdio->req_q_lock);
2366 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2367 * @unit: pointer to struct zfcp_unit
2368 * @tm_flags: unsigned byte for task management flags
2369 * Returns: on success pointer to struct fsf_req, NULL otherwise
2371 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2373 struct qdio_buffer_element *sbale;
2374 struct zfcp_fsf_req *req = NULL;
2375 struct fcp_cmnd *fcp_cmnd;
2376 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2378 if (unlikely(!(atomic_read(&unit->status) &
2379 ZFCP_STATUS_COMMON_UNBLOCKED)))
2382 spin_lock_bh(&qdio->req_q_lock);
2383 if (zfcp_fsf_req_sbal_get(qdio))
2386 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2387 qdio->adapter->pool.scsi_req);
2394 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2396 req->handler = zfcp_fsf_send_fcp_command_handler;
2397 req->qtcb->header.lun_handle = unit->handle;
2398 req->qtcb->header.port_handle = unit->port->handle;
2399 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2400 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2401 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2403 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
2404 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2405 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2407 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2408 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2410 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2411 if (!zfcp_fsf_req_send(req))
2414 zfcp_fsf_req_free(req);
2417 spin_unlock_bh(&qdio->req_q_lock);
2421 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2426 * zfcp_fsf_control_file - control file upload/download
2427 * @adapter: pointer to struct zfcp_adapter
2428 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2429 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2431 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2432 struct zfcp_fsf_cfdc *fsf_cfdc)
2434 struct qdio_buffer_element *sbale;
2435 struct zfcp_qdio *qdio = adapter->qdio;
2436 struct zfcp_fsf_req *req = NULL;
2437 struct fsf_qtcb_bottom_support *bottom;
2438 int direction, retval = -EIO, bytes;
2440 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2441 return ERR_PTR(-EOPNOTSUPP);
2443 switch (fsf_cfdc->command) {
2444 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2445 direction = SBAL_FLAGS0_TYPE_WRITE;
2447 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2448 direction = SBAL_FLAGS0_TYPE_READ;
2451 return ERR_PTR(-EINVAL);
2454 spin_lock_bh(&qdio->req_q_lock);
2455 if (zfcp_fsf_req_sbal_get(qdio))
2458 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
2464 req->handler = zfcp_fsf_control_file_handler;
2466 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
2467 sbale[0].flags |= direction;
2469 bottom = &req->qtcb->bottom.support;
2470 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2471 bottom->option = fsf_cfdc->option;
2473 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2474 direction, fsf_cfdc->sg,
2475 FSF_MAX_SBALS_PER_REQ);
2476 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2477 zfcp_fsf_req_free(req);
2481 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2482 retval = zfcp_fsf_req_send(req);
2484 spin_unlock_bh(&qdio->req_q_lock);
2487 wait_for_completion(&req->completion);
2490 return ERR_PTR(retval);
2494 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2495 * @adapter: pointer to struct zfcp_adapter
2496 * @sbal_idx: response queue index of SBAL to be processed
2498 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2500 struct zfcp_adapter *adapter = qdio->adapter;
2501 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
2502 struct qdio_buffer_element *sbale;
2503 struct zfcp_fsf_req *fsf_req;
2504 unsigned long req_id;
2507 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2509 sbale = &sbal->element[idx];
2510 req_id = (unsigned long) sbale->addr;
2511 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2515 * Unknown request means that we have potentially memory
2516 * corruption and must stop the machine immediately.
2518 panic("error: unknown req_id (%lx) on adapter %s.\n",
2519 req_id, dev_name(&adapter->ccw_device->dev));
2521 fsf_req->qdio_req.sbal_response = sbal_idx;
2522 fsf_req->qdio_req.qdio_inb_usage =
2523 atomic_read(&qdio->resp_q.count);
2524 zfcp_fsf_req_complete(fsf_req);
2526 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))