9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <linux/slab.h>
23 static void zfcp_fsf_request_timeout_handler(
unsigned long data)
31 static void zfcp_fsf_start_timer(
struct zfcp_fsf_req *fsf_req,
32 unsigned long timeout)
34 fsf_req->
timer.function = zfcp_fsf_request_timeout_handler;
36 fsf_req->
timer.expires = jiffies + timeout;
40 static void zfcp_fsf_start_erp_timer(
struct zfcp_fsf_req *fsf_req)
45 fsf_req->
timer.expires = jiffies + 30 *
HZ;
50 static u32 fsf_qtcb_type[] = {
69 "operational because of an unsupported FC class\n");
102 if (port->d_id == d_id) {
127 "There is no light signal from the local "
128 "fibre channel cable\n");
132 "There is a wrap plug instead of a fibre "
137 "The adjacent fibre channel node does not "
142 "The FCP device is suspended because of a "
143 "firmware update\n");
147 "The FCP device detected a WWPN that is "
148 "duplicate or not valid\n");
152 "The fibre channel fabric does not support NPIV\n");
156 "The FCP adapter cannot support more NPIV ports\n");
160 "The adjacent switch cannot support "
161 "more NPIV ports\n");
165 "The FCP adapter could not log in to the "
166 "fibre channel fabric\n");
170 "The WWPN assignment file on the FCP adapter "
171 "has been damaged\n");
175 "The mode table on the FCP adapter "
176 "has been damaged\n");
180 "All NPIV ports on the FCP adapter have "
185 "The link between the FCP adapter and "
186 "the FC fabric is down\n");
192 static void zfcp_fsf_status_read_link_down(
struct zfcp_fsf_req *req)
200 zfcp_fsf_link_down_info_eval(req, ldi);
203 zfcp_fsf_link_down_info_eval(req, ldi);
206 zfcp_fsf_link_down_info_eval(req,
NULL);
210 static void zfcp_fsf_status_read_handler(
struct zfcp_fsf_req *req)
226 zfcp_fsf_status_read_port_closed(req);
235 "The error threshold for checksum statistics "
236 "has been exceeded\n");
240 zfcp_fsf_status_read_link_down(req);
245 "The local link has been restored\n");
277 static void zfcp_fsf_fsfstatus_qual_eval(
struct zfcp_fsf_req *req)
279 switch (req->
qtcb->header.fsf_status_qual.word[0]) {
289 "The FCP adapter reported a problem "
290 "that cannot be recovered\n");
299 static void zfcp_fsf_fsfstatus_eval(
struct zfcp_fsf_req *req)
304 switch (req->
qtcb->header.fsf_status) {
307 "The FCP adapter does not recognize the command 0x%x\n",
308 req->
qtcb->header.fsf_command);
313 zfcp_fsf_fsfstatus_qual_eval(req);
318 static void zfcp_fsf_protstatus_eval(
struct zfcp_fsf_req *req)
324 zfcp_dbf_hba_fsf_response(req);
331 switch (qtcb->
prefix.prot_status) {
337 "QTCB version 0x%x not supported by FCP adapter "
349 "The QTCB type is not supported by the FCP adapter\n");
358 "0x%Lx is an ambiguous request identifier\n",
378 "0x%x is not a valid transfer protocol status\n",
379 qtcb->
prefix.prot_status);
395 static void zfcp_fsf_req_complete(
struct zfcp_fsf_req *req)
398 zfcp_fsf_status_read_handler(req);
403 zfcp_fsf_protstatus_eval(req);
404 zfcp_fsf_fsfstatus_eval(req);
431 zfcp_reqlist_move(adapter->
req_list, &remove_queue);
436 zfcp_fsf_req_complete(req);
440 #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
441 #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
442 #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
443 #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
444 #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
445 #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
446 #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
448 static u32 zfcp_fsf_convert_portspeed(
u32 fsf_speed)
468 static int zfcp_fsf_exchange_config_evaluate(
struct zfcp_fsf_req *req)
514 "Unknown or unsupported arbitrated loop "
515 "fibre channel topology detected\n");
525 static void zfcp_fsf_exchange_config_data_handler(
struct zfcp_fsf_req *req)
542 switch (qtcb->
header.fsf_status) {
544 if (zfcp_fsf_exchange_config_evaluate(req))
549 "FCP adapter maximum QTCB size (%d bytes) "
566 zfcp_fsf_link_down_info_eval(req,
567 &qtcb->
header.fsf_status_qual.link_down_info);
584 "The FCP adapter only supports newer "
585 "control block versions\n");
591 "The FCP adapter only supports older "
592 "control block versions\n");
597 static void zfcp_fsf_exchange_port_evaluate(
struct zfcp_fsf_req *req)
620 static void zfcp_fsf_exchange_port_data_handler(
struct zfcp_fsf_req *req)
627 switch (qtcb->
header.fsf_status) {
629 zfcp_fsf_exchange_port_evaluate(req);
632 zfcp_fsf_exchange_port_evaluate(req);
633 zfcp_fsf_link_down_info_eval(req,
634 &qtcb->
header.fsf_status_qual.link_down_info);
651 memset(req, 0,
sizeof(*req));
668 memset(qtcb, 0,
sizeof(*qtcb));
673 u32 fsf_cmd,
u8 sbtype,
685 INIT_LIST_HEAD(&req->
list);
695 req->
qtcb = zfcp_qtcb_alloc(adapter->
pool.qtcb_pool);
707 req->
qtcb->prefix.ulp_info = 26;
724 int with_qtcb = (req->
qtcb !=
NULL);
727 zfcp_reqlist_add(adapter->
req_list, req);
734 zfcp_reqlist_find_rm(adapter->
req_list, req_id);
766 adapter->
pool.status_read_req);
768 retval = PTR_ERR(req);
778 memset(sr_buf, 0,
sizeof(*sr_buf));
781 zfcp_qdio_fill_next(qdio, &req->
qdio_req, sr_buf,
sizeof(*sr_buf));
782 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
784 retval = zfcp_fsf_req_send(req);
786 goto failed_req_send;
801 static void zfcp_fsf_abort_fcp_command_handler(
struct zfcp_fsf_req *req)
810 zfcp_sdev = sdev_to_zfcp(sdev);
812 switch (req->
qtcb->header.fsf_status) {
843 switch (fsq->
word[0]) {
877 qdio->
adapter->pool.scsi_abort);
887 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
890 req->
handler = zfcp_fsf_abort_fcp_command_handler;
892 req->
qtcb->header.port_handle = zfcp_sdev->
port->handle;
893 req->
qtcb->bottom.support.req_handle = (
u64) old_req_id;
896 if (!zfcp_fsf_req_send(req))
907 static void zfcp_fsf_send_ct_handler(
struct zfcp_fsf_req *req)
924 zfcp_fsf_class_not_supp(req);
956 static void zfcp_fsf_setup_ct_els_unchained(
struct zfcp_qdio *qdio,
961 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->
length);
962 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->
length);
963 zfcp_qdio_set_sbale_last(qdio, q_req);
966 static int zfcp_fsf_setup_ct_els_sbals(
struct zfcp_fsf_req *req,
975 if (zfcp_adapter_multi_buffer_active(adapter)) {
981 zfcp_qdio_set_data_div(qdio, &req->
qdio_req,
982 zfcp_qdio_sbale_count(sg_req));
983 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
984 zfcp_qdio_set_scount(qdio, &req->
qdio_req);
989 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
990 zfcp_fsf_setup_ct_els_unchained(qdio, &req->
qdio_req,
1001 qtcb->
bottom.
support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1003 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1004 zfcp_qdio_skip_to_last_sbale(qdio, &req->
qdio_req);
1009 qtcb->
bottom.
support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1011 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1016 static int zfcp_fsf_setup_ct_els(
struct zfcp_fsf_req *req,
1019 unsigned int timeout)
1023 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
1031 req->
qtcb->bottom.support.timeout = timeout;
1032 zfcp_fsf_start_timer(req, (timeout + 10) *
HZ);
1044 unsigned int timeout)
1063 ret = zfcp_fsf_setup_ct_els(req, ct->
req, ct->
resp, timeout);
1067 req->
handler = zfcp_fsf_send_ct_handler;
1068 req->
qtcb->header.port_handle = wka_port->handle;
1073 ret = zfcp_fsf_req_send(req);
1086 static void zfcp_fsf_send_els_handler(
struct zfcp_fsf_req *req)
1095 goto skip_fsfstatus;
1103 zfcp_fsf_class_not_supp(req);
1162 if (!zfcp_adapter_multi_buffer_active(adapter))
1163 zfcp_qdio_sbal_limit(qdio, &req->
qdio_req, 2);
1165 ret = zfcp_fsf_setup_ct_els(req, els->
req, els->
resp, timeout);
1170 hton24(req->
qtcb->bottom.support.d_id, d_id);
1171 req->
handler = zfcp_fsf_send_els_handler;
1176 ret = zfcp_fsf_req_send(req);
1204 retval = PTR_ERR(req);
1209 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1211 req->
qtcb->bottom.config.feature_selection =
1217 req->
handler = zfcp_fsf_exchange_config_data_handler;
1220 zfcp_fsf_start_erp_timer(req);
1221 retval = zfcp_fsf_req_send(req);
1245 retval = PTR_ERR(req);
1249 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1250 req->
handler = zfcp_fsf_exchange_config_data_handler;
1252 req->
qtcb->bottom.config.feature_selection =
1262 retval = zfcp_fsf_req_send(req);
1298 retval = PTR_ERR(req);
1303 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1305 req->
handler = zfcp_fsf_exchange_port_data_handler;
1309 zfcp_fsf_start_erp_timer(req);
1310 retval = zfcp_fsf_req_send(req);
1343 retval = PTR_ERR(req);
1350 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1352 req->
handler = zfcp_fsf_exchange_port_data_handler;
1354 retval = zfcp_fsf_req_send(req);
1369 static void zfcp_fsf_open_port_handler(
struct zfcp_fsf_req *req)
1387 "Not enough FCP adapter resources to open "
1388 "remote port 0x%016Lx\n",
1389 (
unsigned long long)port->
wwpn);
1426 if (req->
qtcb->bottom.support.els1_length >=
1460 retval = PTR_ERR(req);
1465 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1467 req->
handler = zfcp_fsf_open_port_handler;
1474 zfcp_fsf_start_erp_timer(req);
1475 retval = zfcp_fsf_req_send(req);
1486 static void zfcp_fsf_close_port_handler(
struct zfcp_fsf_req *req)
1493 switch (req->
qtcb->header.fsf_status) {
1526 retval = PTR_ERR(req);
1531 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1533 req->
handler = zfcp_fsf_close_port_handler;
1536 req->
qtcb->header.port_handle = erp_action->
port->handle;
1539 zfcp_fsf_start_erp_timer(req);
1540 retval = zfcp_fsf_req_send(req);
1550 static void zfcp_fsf_open_wka_port_handler(
struct zfcp_fsf_req *req)
1552 struct zfcp_fc_wka_port *wka_port = req->
data;
1556 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1563 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1569 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1575 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1578 wake_up(&wka_port->completion_wq);
1601 retval = PTR_ERR(req);
1606 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1608 req->
handler = zfcp_fsf_open_wka_port_handler;
1609 hton24(req->
qtcb->bottom.support.d_id, wka_port->d_id);
1610 req->
data = wka_port;
1613 retval = zfcp_fsf_req_send(req);
1621 static void zfcp_fsf_close_wka_port_handler(
struct zfcp_fsf_req *req)
1623 struct zfcp_fc_wka_port *wka_port = req->
data;
1630 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1631 wake_up(&wka_port->completion_wq);
1654 retval = PTR_ERR(req);
1659 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1661 req->
handler = zfcp_fsf_close_wka_port_handler;
1662 req->
data = wka_port;
1663 req->
qtcb->header.port_handle = wka_port->handle;
1666 retval = zfcp_fsf_req_send(req);
1674 static void zfcp_fsf_close_physical_port_handler(
struct zfcp_fsf_req *req)
1696 if (sdev_to_zfcp(sdev)->port == port)
1698 &sdev_to_zfcp(sdev)->
status);
1719 if (sdev_to_zfcp(sdev)->port == port)
1721 &sdev_to_zfcp(sdev)->
status);
1746 retval = PTR_ERR(req);
1751 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1753 req->
data = erp_action->port;
1754 req->
qtcb->header.port_handle = erp_action->port->handle;
1756 req->
handler = zfcp_fsf_close_physical_port_handler;
1757 erp_action->fsf_req_id = req->
req_id;
1759 zfcp_fsf_start_erp_timer(req);
1760 retval = zfcp_fsf_req_send(req);
1763 erp_action->fsf_req_id = 0;
1770 static void zfcp_fsf_open_lun_handler(
struct zfcp_fsf_req *req)
1781 zfcp_sdev = sdev_to_zfcp(sdev);
1813 "No handle is available for LUN "
1814 "0x%016Lx on port 0x%016Lx\n",
1815 (
unsigned long long)zfcp_scsi_dev_lun(sdev),
1816 (
unsigned long long)zfcp_sdev->
port->wwpn);
1859 adapter->
pool.erp_req);
1862 retval = PTR_ERR(req);
1867 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1869 req->
qtcb->header.port_handle = erp_action->
port->handle;
1870 req->
qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->
sdev);
1871 req->
handler = zfcp_fsf_open_lun_handler;
1879 zfcp_fsf_start_erp_timer(req);
1880 retval = zfcp_fsf_req_send(req);
1890 static void zfcp_fsf_close_lun_handler(
struct zfcp_fsf_req *req)
1898 zfcp_sdev = sdev_to_zfcp(sdev);
1900 switch (req->
qtcb->header.fsf_status) {
1917 switch (req->
qtcb->header.fsf_status_qual.word[0]) {
1953 retval = PTR_ERR(req);
1958 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
1960 req->
qtcb->header.port_handle = erp_action->
port->handle;
1962 req->
handler = zfcp_fsf_close_lun_handler;
1967 zfcp_fsf_start_erp_timer(req);
1968 retval = zfcp_fsf_req_send(req);
1980 lat_rec->
sum += lat;
1993 lat_in = &req->
qtcb->prefix.prot_status_qual.latency_info;
1999 blktrc.inb_usage = 0;
2000 blktrc.outb_usage = req->
qdio_req.qdio_outb_usage;
2004 zfcp_sdev = sdev_to_zfcp(scsi->
device);
2009 switch (req->
qtcb->bottom.io.data_direction) {
2030 spin_unlock(&zfcp_sdev->
latencies.lock);
2038 static void zfcp_fsf_fcp_handler_common(
struct zfcp_fsf_req *req)
2048 zfcp_sdev = sdev_to_zfcp(sdev);
2062 zfcp_fsf_class_not_supp(req);
2070 "Incorrect direction %d, LUN 0x%016Lx on port "
2071 "0x%016Lx closed\n",
2072 req->
qtcb->bottom.io.data_direction,
2073 (
unsigned long long)zfcp_scsi_dev_lun(sdev),
2074 (
unsigned long long)zfcp_sdev->
port->wwpn);
2081 "Incorrect CDB length %d, LUN 0x%016Lx on "
2082 "port 0x%016Lx closed\n",
2083 req->
qtcb->bottom.io.fcp_cmnd_length,
2084 (
unsigned long long)zfcp_scsi_dev_lun(sdev),
2085 (
unsigned long long)zfcp_sdev->
port->wwpn);
2112 static void zfcp_fsf_fcp_cmnd_handler(
struct zfcp_fsf_req *req)
2116 unsigned long flags;
2126 zfcp_fsf_fcp_handler_common(req);
2130 goto skip_fsfstatus;
2133 switch (req->
qtcb->header.fsf_status) {
2137 goto skip_fsfstatus;
2140 goto skip_fsfstatus;
2143 goto skip_fsfstatus;
2146 goto skip_fsfstatus;
2149 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2152 zfcp_fsf_req_trace(req, scpnt);
2153 zfcp_dbf_scsi_result(scpnt, req);
2168 switch (scsi_get_prot_op(scsi_cmnd)) {
2219 unsigned long flags;
2235 sbtype, adapter->
pool.scsi_req);
2238 retval = PTR_ERR(req);
2244 io = &req->
qtcb->bottom.io;
2246 req->
data = scsi_cmnd;
2247 req->
handler = zfcp_fsf_fcp_cmnd_handler;
2249 req->
qtcb->header.port_handle = zfcp_sdev->
port->handle;
2259 goto failed_scsi_cmnd;
2261 fcp_cmnd = (
struct fcp_cmnd *) &req->
qtcb->bottom.io.fcp_cmnd;
2262 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
2264 if (scsi_prot_sg_count(scsi_cmnd)) {
2265 zfcp_qdio_set_data_div(qdio, &req->
qdio_req,
2266 scsi_prot_sg_count(scsi_cmnd));
2268 scsi_prot_sglist(scsi_cmnd));
2270 goto failed_scsi_cmnd;
2272 scsi_prot_sglist(scsi_cmnd));
2276 scsi_sglist(scsi_cmnd));
2278 goto failed_scsi_cmnd;
2280 zfcp_qdio_set_sbale_last(adapter->
qdio, &req->
qdio_req);
2281 if (zfcp_adapter_multi_buffer_active(adapter))
2282 zfcp_qdio_set_scount(qdio, &req->
qdio_req);
2284 retval = zfcp_fsf_req_send(req);
2286 goto failed_scsi_cmnd;
2294 spin_unlock_irqrestore(&qdio->
req_q_lock, flags);
2298 static void zfcp_fsf_fcp_task_mgmt_handler(
struct zfcp_fsf_req *req)
2303 zfcp_fsf_fcp_handler_common(req);
2337 qdio->
adapter->pool.scsi_req);
2345 req->
handler = zfcp_fsf_fcp_task_mgmt_handler;
2347 req->
qtcb->header.port_handle = zfcp_sdev->
port->handle;
2352 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
2354 fcp_cmnd = (
struct fcp_cmnd *) &req->
qtcb->bottom.io.fcp_cmnd;
2355 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
2358 if (!zfcp_fsf_req_send(req))
2368 static void zfcp_fsf_control_file_handler(
struct zfcp_fsf_req *req)
2405 req = zfcp_fsf_req_create(qdio, fsf_cfdc->
command, direction,
NULL);
2411 req->
handler = zfcp_fsf_control_file_handler;
2413 bottom = &req->
qtcb->bottom.support;
2425 zfcp_qdio_set_sbale_last(qdio, &req->
qdio_req);
2426 if (zfcp_adapter_multi_buffer_active(adapter))
2427 zfcp_qdio_set_scount(qdio, &req->
qdio_req);
2430 retval = zfcp_fsf_req_send(req);
2438 return ERR_PTR(retval);
2458 req_id = (
unsigned long) sbale->
addr;
2459 fsf_req = zfcp_reqlist_find_rm(adapter->
req_list, req_id);
2467 panic(
"error: unknown req_id (%lx) on adapter %s.\n",
2468 req_id, dev_name(&adapter->
ccw_device->dev));
2471 fsf_req->
qdio_req.sbal_response = sbal_idx;
2472 zfcp_fsf_req_complete(fsf_req);
2485 return zfcp_reqlist_find(qdio->
adapter->req_list, req_id);