blob: 51b81c0a06520bfaa55446aa443b3d394f4c120e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Christof Schmitt553448f2008-06-10 18:20:58 +02003 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Christof Schmitt553448f2008-06-10 18:20:58 +02005 * Implementation of FSF commands.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
Steffen Maier394134f2017-07-28 12:31:00 +02007 * Copyright IBM Corp. 2002, 2017
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Christof Schmittecf39d42008-12-25 13:39:53 +010010#define KMSG_COMPONENT "zfcp"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Stefan Raspl0997f1c2008-10-16 08:23:39 +020013#include <linux/blktrace_api.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Christof Schmitt9d05ce22009-11-24 16:54:09 +010015#include <scsi/fc/fc_els.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "zfcp_ext.h"
Christof Schmitt4318e082009-11-24 16:54:08 +010017#include "zfcp_fc.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020018#include "zfcp_dbf.h"
Christof Schmitt34c2b712010-02-17 11:18:59 +010019#include "zfcp_qdio.h"
Christof Schmittb6bd2fb92010-02-17 11:18:50 +010020#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Christof Schmitt259afe22011-02-22 19:54:44 +010022struct kmem_cache *zfcp_fsf_qtcb_cache;
23
Kees Cook75492a52017-10-16 16:44:34 -070024static void zfcp_fsf_request_timeout_handler(struct timer_list *t)
Christof Schmitt287ac012008-07-02 10:56:40 +020025{
Kees Cook75492a52017-10-16 16:44:34 -070026 struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer);
27 struct zfcp_adapter *adapter = fsf_req->adapter;
Steffen Maier5c13db92017-10-17 18:40:51 +020028
Christof Schmitt339f4f42010-07-16 15:37:43 +020029 zfcp_qdio_siosl(adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010030 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +010031 "fsrth_1");
Christof Schmitt287ac012008-07-02 10:56:40 +020032}
33
34static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
35 unsigned long timeout)
36{
Kees Cook75492a52017-10-16 16:44:34 -070037 fsf_req->timer.function = (TIMER_FUNC_TYPE)zfcp_fsf_request_timeout_handler;
Christof Schmitt287ac012008-07-02 10:56:40 +020038 fsf_req->timer.expires = jiffies + timeout;
39 add_timer(&fsf_req->timer);
40}
41
42static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
43{
44 BUG_ON(!fsf_req->erp_action);
Kees Cook75492a52017-10-16 16:44:34 -070045 fsf_req->timer.function = (TIMER_FUNC_TYPE)zfcp_erp_timeout_handler;
Christof Schmitt287ac012008-07-02 10:56:40 +020046 fsf_req->timer.expires = jiffies + 30 * HZ;
47 add_timer(&fsf_req->timer);
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/* association between FSF command and FSF QTCB type */
51static u32 fsf_qtcb_type[] = {
52 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
53 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
62 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
63 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
64 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
65};
66
Christof Schmitt553448f2008-06-10 18:20:58 +020067static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
68{
Christof Schmittff3b24f2008-10-01 12:42:15 +020069 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
70 "operational because of an unsupported FC class\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +010071 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
Christof Schmitt553448f2008-06-10 18:20:58 +020072 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
73}
74
Swen Schilligc41f8cb2008-07-02 10:56:39 +020075/**
76 * zfcp_fsf_req_free - free memory used by fsf request
77 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +020079void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020081 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +020082 if (likely(req->qtcb))
83 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +020084 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020085 return;
86 }
87
Swen Schilliga4623c42009-08-18 15:43:15 +020088 if (likely(req->qtcb))
Christof Schmitt259afe22011-02-22 19:54:44 +010089 kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
Swen Schilliga4623c42009-08-18 15:43:15 +020090 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Swen Schilligc41f8cb2008-07-02 10:56:39 +020093static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Swen Schilligecf0c772009-11-24 16:53:58 +010095 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +020096 struct fsf_status_read_buffer *sr_buf = req->data;
97 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +010099 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Swen Schilligecf0c772009-11-24 16:53:58 +0100101 read_lock_irqsave(&adapter->port_list_lock, flags);
102 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200103 if (port->d_id == d_id) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100104 zfcp_erp_port_reopen(port, 0, "fssrpc1");
Swen Schilligecf0c772009-11-24 16:53:58 +0100105 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200106 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100107 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
Swen Schilligedaed852010-09-08 14:40:01 +0200110static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200111 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200113 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200115 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
116 return;
117
Peter Zijlstra805de8f42015-04-24 01:12:32 +0200118 atomic_or(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200119
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100120 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200121
122 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200124
125 switch (link_down->error_code) {
126 case FSF_PSQ_LINK_NO_LIGHT:
127 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200128 "There is no light signal from the local "
129 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200130 break;
131 case FSF_PSQ_LINK_WRAP_PLUG:
132 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200133 "There is a wrap plug instead of a fibre "
134 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200135 break;
136 case FSF_PSQ_LINK_NO_FCP:
137 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200138 "The adjacent fibre channel node does not "
139 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200140 break;
141 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
142 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200143 "The FCP device is suspended because of a "
144 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200145 break;
146 case FSF_PSQ_LINK_INVALID_WWPN:
147 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200148 "The FCP device detected a WWPN that is "
149 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200150 break;
151 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
152 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200153 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200154 break;
155 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
156 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200157 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200158 break;
159 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
160 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200161 "The adjacent switch cannot support "
162 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200163 break;
164 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
165 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200166 "The FCP adapter could not log in to the "
167 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200168 break;
169 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
170 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200171 "The WWPN assignment file on the FCP adapter "
172 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200173 break;
174 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
175 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200176 "The mode table on the FCP adapter "
177 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200178 break;
179 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
180 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200181 "All NPIV ports on the FCP adapter have "
182 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200183 break;
184 default:
185 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200186 "The link between the FCP adapter and "
187 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200188 }
189out:
Swen Schilligedaed852010-09-08 14:40:01 +0200190 zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200191}
192
193static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
194{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200195 struct fsf_status_read_buffer *sr_buf = req->data;
196 struct fsf_link_down_info *ldi =
197 (struct fsf_link_down_info *) &sr_buf->payload;
198
199 switch (sr_buf->status_subtype) {
200 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200201 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schilligedaed852010-09-08 14:40:01 +0200202 zfcp_fsf_link_down_info_eval(req, ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200203 break;
204 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schilligedaed852010-09-08 14:40:01 +0200205 zfcp_fsf_link_down_info_eval(req, NULL);
Peter Senna Tschudin3b974872015-08-04 17:11:15 +0200206 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200207}
208
209static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
210{
211 struct zfcp_adapter *adapter = req->adapter;
212 struct fsf_status_read_buffer *sr_buf = req->data;
213
214 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100215 zfcp_dbf_hba_fsf_uss("fssrh_1", req);
Christof Schmittc7b279a2011-02-22 19:54:40 +0100216 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200217 zfcp_fsf_req_free(req);
218 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
220
Steffen Maier01009982012-09-04 15:23:30 +0200221 zfcp_dbf_hba_fsf_uss("fssrh_4", req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200222
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200223 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200225 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200228 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200233 dev_warn(&adapter->ccw_device->dev,
234 "The error threshold for checksum statistics "
235 "has been exceeded\n");
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100236 zfcp_dbf_hba_bit_err("fssrh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200239 zfcp_fsf_status_read_link_down(req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200240 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200243 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200244 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 /* All ports should be marked as ready to run again */
Swen Schilligedaed852010-09-08 14:40:01 +0200246 zfcp_erp_set_adapter_status(adapter,
247 ZFCP_STATUS_COMMON_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200249 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
250 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100251 "fssrh_2");
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200252 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100255 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200256 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Steffen Maier43f60cb2012-09-04 15:23:35 +0200257 zfcp_fc_conditional_port_scan(adapter);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100258 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200259 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200260 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200261 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200263
Christof Schmittc7b279a2011-02-22 19:54:40 +0100264 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200265 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200266
267 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200268 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200271static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200273 switch (req->qtcb->header.fsf_status_qual.word[0]) {
274 case FSF_SQ_FCP_RSP_AVAILABLE:
275 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
276 case FSF_SQ_NO_RETRY_POSSIBLE:
277 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
278 return;
279 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200280 break;
281 case FSF_SQ_NO_RECOM:
282 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200283 "The FCP adapter reported a problem "
284 "that cannot be recovered\n");
Christof Schmitt339f4f42010-07-16 15:37:43 +0200285 zfcp_qdio_siosl(req->adapter);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100286 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200287 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200289 /* all non-return stats set FSFREQ_ERROR*/
290 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
291}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200293static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
294{
295 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
296 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200297
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200298 switch (req->qtcb->header.fsf_status) {
299 case FSF_UNKNOWN_COMMAND:
300 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200301 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200302 req->qtcb->header.fsf_command);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100303 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200304 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200307 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200312static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200314 struct zfcp_adapter *adapter = req->adapter;
315 struct fsf_qtcb *qtcb = req->qtcb;
316 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Swen Schillig57717102009-08-18 15:43:21 +0200318 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200320 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100321 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200322 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200325 switch (qtcb->prefix.prot_status) {
326 case FSF_PROT_GOOD:
327 case FSF_PROT_FSF_STATUS_PRESENTED:
328 return;
329 case FSF_PROT_QTCB_VERSION_ERROR:
330 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200331 "QTCB version 0x%x not supported by FCP adapter "
332 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
333 psq->word[0], psq->word[1]);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100334 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200336 case FSF_PROT_ERROR_STATE:
337 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100338 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100339 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200341 case FSF_PROT_UNSUPP_QTCB_TYPE:
342 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200343 "The QTCB type is not supported by the FCP adapter\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100344 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200346 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Peter Zijlstra805de8f42015-04-24 01:12:32 +0200347 atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200348 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200350 case FSF_PROT_DUPLICATE_REQUEST_ID:
351 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200352 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200353 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100354 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200356 case FSF_PROT_LINK_DOWN:
Swen Schilligedaed852010-09-08 14:40:01 +0200357 zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100358 /* go through reopen to flush pending requests */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100359 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200361 case FSF_PROT_REEST_QUEUE:
362 /* All ports should be marked as ready to run again */
Swen Schilligedaed852010-09-08 14:40:01 +0200363 zfcp_erp_set_adapter_status(adapter,
364 ZFCP_STATUS_COMMON_RUNNING);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200365 zfcp_erp_adapter_reopen(adapter,
366 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100367 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100368 "fspse_8");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200369 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200371 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200372 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200373 qtcb->prefix.prot_status);
Christof Schmitt339f4f42010-07-16 15:37:43 +0200374 zfcp_qdio_siosl(adapter);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100375 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200377 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200381 * zfcp_fsf_req_complete - process completion of a FSF request
382 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200384 * When a request has been completed either from the FCP adapter,
385 * or it has been dismissed due to a queue shutdown, this function
386 * is called to process the completion status and trigger further
387 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200389static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200390{
391 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
392 zfcp_fsf_status_read_handler(req);
393 return;
394 }
395
396 del_timer(&req->timer);
397 zfcp_fsf_protstatus_eval(req);
398 zfcp_fsf_fsfstatus_eval(req);
399 req->handler(req);
400
401 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200402 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200403
404 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
405 zfcp_fsf_req_free(req);
406 else
Swen Schillig058b8642009-08-18 15:43:14 +0200407 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200408}
409
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200410/**
411 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
412 * @adapter: pointer to struct zfcp_adapter
413 *
414 * Never ever call this without shutting down the adapter first.
415 * Otherwise the adapter would continue using and corrupting s390 storage.
416 * Included BUG_ON() call to ensure this is done.
417 * ERP is supposed to be the only user of this function.
418 */
419void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
420{
421 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200422 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200423
424 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100425 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200426
427 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
428 list_del(&req->list);
429 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
430 zfcp_fsf_req_complete(req);
431 }
432}
433
Steffen Maierd2201972012-09-04 15:23:29 +0200434#define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
435#define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
436#define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
437#define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
438#define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
439#define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
440#define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
441
442static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
443{
444 u32 fdmi_speed = 0;
445 if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
446 fdmi_speed |= FC_PORTSPEED_1GBIT;
447 if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
448 fdmi_speed |= FC_PORTSPEED_2GBIT;
449 if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
450 fdmi_speed |= FC_PORTSPEED_4GBIT;
451 if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
452 fdmi_speed |= FC_PORTSPEED_10GBIT;
453 if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
454 fdmi_speed |= FC_PORTSPEED_8GBIT;
455 if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
456 fdmi_speed |= FC_PORTSPEED_16GBIT;
457 if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
458 fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
459 return fdmi_speed;
460}
461
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200462static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100464 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200465 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200466 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100467 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100469 /* adjust pointers for missing command code */
470 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
471 - sizeof(u32));
472 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
473 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200474
475 if (req->data)
476 memcpy(req->data, bottom, sizeof(*bottom));
477
Steffen Maier9d464fc2017-07-28 12:31:02 +0200478 fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn);
479 fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200480 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
481
Christof Schmittfaf4cd82010-07-16 15:37:36 +0200482 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200483 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
484 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200485
486 if (fc_host_permanent_port_name(shost) == -1)
487 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
488
Steffen Maier9edf7d72013-04-26 17:34:54 +0200489 zfcp_scsi_set_prot(adapter);
490
491 /* no error return above here, otherwise must fix call chains */
492 /* do not evaluate invalid fields */
493 if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
494 return 0;
495
496 fc_host_port_id(shost) = ntoh24(bottom->s_id);
497 fc_host_speed(shost) =
498 zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
499
500 adapter->hydra_version = bottom->adapter_type;
501
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200502 switch (bottom->fc_topology) {
503 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100504 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Steffen Maier9d464fc2017-07-28 12:31:02 +0200505 adapter->peer_wwpn = be64_to_cpu(plogi->fl_wwpn);
506 adapter->peer_wwnn = be64_to_cpu(plogi->fl_wwnn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200507 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200508 break;
509 case FSF_TOPO_FABRIC:
Steffen Maierbd77bef2016-08-10 18:30:44 +0200510 if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
511 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
512 else
513 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200514 break;
515 case FSF_TOPO_AL:
516 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200517 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200518 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200519 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200520 "Unknown or unsupported arbitrated loop "
521 "fibre channel topology detected\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100522 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200523 return -EIO;
524 }
525
526 return 0;
527}
528
529static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
530{
531 struct zfcp_adapter *adapter = req->adapter;
532 struct fsf_qtcb *qtcb = req->qtcb;
533 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
534 struct Scsi_Host *shost = adapter->scsi_host;
535
536 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
537 return;
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200540 adapter->adapter_features = bottom->adapter_features;
541 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500542 adapter->peer_wwpn = 0;
543 adapter->peer_wwnn = 0;
544 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200546 switch (qtcb->header.fsf_status) {
547 case FSF_GOOD:
548 if (zfcp_fsf_exchange_config_evaluate(req))
549 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200550
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200551 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
552 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200553 "FCP adapter maximum QTCB size (%d bytes) "
554 "is too small\n",
555 bottom->max_qtcb_size);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100556 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200557 return;
558 }
Peter Zijlstra805de8f42015-04-24 01:12:32 +0200559 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200560 &adapter->status);
561 break;
562 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200563 fc_host_node_name(shost) = 0;
564 fc_host_port_name(shost) = 0;
565 fc_host_port_id(shost) = 0;
566 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100567 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200569
Daniel Hanself76ccaa2013-04-26 17:32:14 +0200570 /* avoids adapter shutdown to be able to recognize
571 * events such as LINK UP */
Peter Zijlstra805de8f42015-04-24 01:12:32 +0200572 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
Daniel Hanself76ccaa2013-04-26 17:32:14 +0200573 &adapter->status);
Swen Schilligedaed852010-09-08 14:40:01 +0200574 zfcp_fsf_link_down_info_eval(req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200575 &qtcb->header.fsf_status_qual.link_down_info);
Steffen Maier9edf7d72013-04-26 17:34:54 +0200576 if (zfcp_fsf_exchange_config_evaluate(req))
577 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200578 break;
579 default:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100580 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200581 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
583
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200584 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200586 memcpy(fc_host_serial_number(shost), bottom->serial_number,
587 min(FC_SERIAL_NUMBER_SIZE, 17));
588 EBCASC(fc_host_serial_number(shost),
589 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200592 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200593 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200594 "The FCP adapter only supports newer "
595 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100596 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200597 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200599 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200600 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200601 "The FCP adapter only supports older "
602 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100603 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
606
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200607static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200609 struct zfcp_adapter *adapter = req->adapter;
610 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
611 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200613 if (req->data)
614 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100615
Christof Schmitt02829852009-03-02 13:09:06 +0100616 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100617 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100618 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100619 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
620 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
Steffen Maierd2201972012-09-04 15:23:29 +0200621 fc_host_supported_speeds(shost) =
622 zfcp_fsf_convert_portspeed(bottom->supported_speed);
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100623 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
624 FC_FC4_LIST_SIZE);
625 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
626 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100627}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200629static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200631 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100632
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200633 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return;
635
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637 case FSF_GOOD:
638 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200639 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200640 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200641 zfcp_fsf_exchange_port_evaluate(req);
Swen Schilligedaed852010-09-08 14:40:01 +0200642 zfcp_fsf_link_down_info_eval(req,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200643 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646}
647
Swen Schilliga4623c42009-08-18 15:43:15 +0200648static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200649{
650 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200651
652 if (likely(pool))
653 req = mempool_alloc(pool, GFP_ATOMIC);
654 else
655 req = kmalloc(sizeof(*req), GFP_ATOMIC);
656
657 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200659
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200660 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100661 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662 return req;
663}
664
Swen Schilliga4623c42009-08-18 15:43:15 +0200665static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200666{
Swen Schilliga4623c42009-08-18 15:43:15 +0200667 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200668
669 if (likely(pool))
670 qtcb = mempool_alloc(pool, GFP_ATOMIC);
671 else
Christof Schmitt259afe22011-02-22 19:54:44 +0100672 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
Swen Schilliga4623c42009-08-18 15:43:15 +0200673
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200674 if (unlikely(!qtcb))
675 return NULL;
676
677 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200678 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200679}
680
Swen Schillig564e1c82009-08-18 15:43:19 +0200681static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Jan Glauber3ec908782011-06-06 14:14:40 +0200682 u32 fsf_cmd, u8 sbtype,
Christof Schmitt1674b402010-04-30 18:09:34 +0200683 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Swen Schillig564e1c82009-08-18 15:43:19 +0200685 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200686 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200687
688 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200689 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200690
691 if (adapter->req_no == 0)
692 adapter->req_no++;
693
694 INIT_LIST_HEAD(&req->list);
Kees Cook75492a52017-10-16 16:44:34 -0700695 timer_setup(&req->timer, NULL, 0);
Swen Schillig058b8642009-08-18 15:43:14 +0200696 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200697
698 req->adapter = adapter;
699 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100700 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200701
Swen Schilliga4623c42009-08-18 15:43:15 +0200702 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
703 if (likely(pool))
704 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
705 else
706 req->qtcb = zfcp_qtcb_alloc(NULL);
707
708 if (unlikely(!req->qtcb)) {
709 zfcp_fsf_req_free(req);
710 return ERR_PTR(-ENOMEM);
711 }
712
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100713 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200714 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200715 req->qtcb->prefix.req_id = req->req_id;
716 req->qtcb->prefix.ulp_info = 26;
717 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
718 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
719 req->qtcb->header.req_handle = req->req_id;
720 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200721 }
722
Christof Schmitt1674b402010-04-30 18:09:34 +0200723 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
724 req->qtcb, sizeof(struct fsf_qtcb));
725
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200726 return req;
727}
728
729static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
730{
731 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200732 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100733 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100734 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200735
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100736 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200737
Swen Schillig706eca42010-07-16 15:37:38 +0200738 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Heiko Carstens1aae0562013-01-30 09:49:40 +0100739 req->issued = get_tod_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100740 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200741 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100742 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100743 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100744 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200745 return -EIO;
746 }
747
748 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200749 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200750 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100751 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200752
753 return 0;
754}
755
756/**
757 * zfcp_fsf_status_read - send status read request
758 * @adapter: pointer to struct zfcp_adapter
759 * @req_flags: request flags
760 * Returns: 0 on success, ERROR otherwise
761 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200762int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200763{
Swen Schillig564e1c82009-08-18 15:43:19 +0200764 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200765 struct zfcp_fsf_req *req;
766 struct fsf_status_read_buffer *sr_buf;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100767 struct page *page;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200768 int retval = -EIO;
769
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200770 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200771 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Martin Peschke75a14082013-08-22 17:49:31 +0200774 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
775 SBAL_SFLAGS0_TYPE_STATUS,
Swen Schilliga4623c42009-08-18 15:43:15 +0200776 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200777 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200778 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 goto out;
780 }
781
Christof Schmittc7b279a2011-02-22 19:54:40 +0100782 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
783 if (!page) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200784 retval = -ENOMEM;
785 goto failed_buf;
786 }
Christof Schmittc7b279a2011-02-22 19:54:40 +0100787 sr_buf = page_address(page);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200788 memset(sr_buf, 0, sizeof(*sr_buf));
789 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200790
791 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
792 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200793
794 retval = zfcp_fsf_req_send(req);
795 if (retval)
796 goto failed_req_send;
797
798 goto out;
799
800failed_req_send:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100801 req->data = NULL;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100802 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200803failed_buf:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100804 zfcp_dbf_hba_fsf_uss("fssr__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200805 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200806out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200807 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return retval;
809}
810
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200811static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200813 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +0200814 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200815 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200817 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
818 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Martin Peschked436de82012-09-04 15:23:36 +0200820 zfcp_sdev = sdev_to_zfcp(sdev);
821
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200822 switch (req->qtcb->header.fsf_status) {
823 case FSF_PORT_HANDLE_NOT_VALID:
824 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200825 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100826 "fsafch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200827 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200830 case FSF_LUN_HANDLE_NOT_VALID:
831 if (fsq->word[0] == fsq->word[1]) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100832 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200833 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200836 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
837 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200839 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200840 zfcp_erp_set_port_status(zfcp_sdev->port,
841 ZFCP_STATUS_COMMON_ACCESS_BOXED);
842 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100843 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100844 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200845 break;
846 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200847 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
848 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100849 "fsafch4");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100850 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200851 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200853 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200855 zfcp_fc_test_link(zfcp_sdev->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200856 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200858 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 break;
860 }
861 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200863 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
864 break;
865 }
866}
867
868/**
Christof Schmittb62a8d92010-09-08 14:39:55 +0200869 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
870 * @scmnd: The SCSI command to abort
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200871 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200872 */
873
Christof Schmittb62a8d92010-09-08 14:39:55 +0200874struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200875{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200876 struct zfcp_fsf_req *req = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200877 struct scsi_device *sdev = scmnd->device;
878 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
879 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
880 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200881
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200882 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200883 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200885 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Jan Glauber3ec908782011-06-06 14:14:40 +0200886 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200887 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100888 if (IS_ERR(req)) {
889 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200890 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100891 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200892
Christof Schmittb62a8d92010-09-08 14:39:55 +0200893 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200894 ZFCP_STATUS_COMMON_UNBLOCKED)))
895 goto out_error_free;
896
Christof Schmitt1674b402010-04-30 18:09:34 +0200897 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200898
Swen Schillig6fbf25e2010-11-17 14:23:41 +0100899 req->data = sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200900 req->handler = zfcp_fsf_abort_fcp_command_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200901 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
902 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200903 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
904
905 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
906 if (!zfcp_fsf_req_send(req))
907 goto out;
908
909out_error_free:
910 zfcp_fsf_req_free(req);
911 req = NULL;
912out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200913 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200914 return req;
915}
916
917static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
918{
919 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100920 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200921 struct fsf_qtcb_header *header = &req->qtcb->header;
922
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100923 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200924
925 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
926 goto skip_fsfstatus;
927
928 switch (header->fsf_status) {
929 case FSF_GOOD:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100930 ct->status = 0;
Steffen Maier975171b2017-07-28 12:30:53 +0200931 zfcp_dbf_san_res("fsscth2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200932 break;
933 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
934 zfcp_fsf_class_not_supp(req);
935 break;
936 case FSF_ADAPTER_STATUS_AVAILABLE:
937 switch (header->fsf_status_qual.word[0]){
938 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200939 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
940 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
941 break;
942 }
943 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200944 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100945 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200946 break;
947 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100948 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
Christof Schmittdceab652009-05-15 13:18:18 +0200949 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200950 case FSF_GENERIC_COMMAND_REJECTED:
951 case FSF_PAYLOAD_SIZE_MISMATCH:
952 case FSF_REQUEST_SIZE_TOO_LARGE:
953 case FSF_RESPONSE_SIZE_TOO_LARGE:
954 case FSF_SBAL_MISMATCH:
955 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
956 break;
957 }
958
959skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100960 if (ct->handler)
961 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200962}
963
Christof Schmitt1674b402010-04-30 18:09:34 +0200964static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
965 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200966 struct scatterlist *sg_req,
967 struct scatterlist *sg_resp)
968{
Christof Schmitt1674b402010-04-30 18:09:34 +0200969 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
970 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
971 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200972}
973
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100974static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
975 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200976 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200977{
Swen Schillig42428f72009-08-18 15:43:18 +0200978 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig86a96682011-08-15 14:40:32 +0200979 struct zfcp_qdio *qdio = adapter->qdio;
980 struct fsf_qtcb *qtcb = req->qtcb;
Swen Schillig42428f72009-08-18 15:43:18 +0200981 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200982
Swen Schillig86a96682011-08-15 14:40:32 +0200983 if (zfcp_adapter_multi_buffer_active(adapter)) {
984 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
985 return -EIO;
Steffen Maier70369f82016-08-10 18:30:45 +0200986 qtcb->bottom.support.req_buf_length =
987 zfcp_qdio_real_bytes(sg_req);
Swen Schillig86a96682011-08-15 14:40:32 +0200988 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
989 return -EIO;
Steffen Maier70369f82016-08-10 18:30:45 +0200990 qtcb->bottom.support.resp_buf_length =
991 zfcp_qdio_real_bytes(sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100992
LABBE Corentin7d918692017-07-28 12:30:47 +0200993 zfcp_qdio_set_data_div(qdio, &req->qdio_req, sg_nents(sg_req));
Swen Schillig86a96682011-08-15 14:40:32 +0200994 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
995 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200996 return 0;
997 }
998
999 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +02001000 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Swen Schillig86a96682011-08-15 14:40:32 +02001001 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +02001002 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001003 return 0;
1004 }
1005
Swen Schillig86a96682011-08-15 14:40:32 +02001006 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
1007 return -EOPNOTSUPP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001008
Swen Schillig86a96682011-08-15 14:40:32 +02001009 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
Christof Schmitt9072df42009-07-13 15:06:07 +02001010 return -EIO;
Swen Schillig86a96682011-08-15 14:40:32 +02001011
1012 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1013
1014 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1015 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1016
1017 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1018 return -EIO;
1019
1020 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1021
1022 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001023
Christof Schmittb1a58982009-09-24 10:23:21 +02001024 return 0;
1025}
1026
1027static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1028 struct scatterlist *sg_req,
1029 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001030 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001031{
1032 int ret;
1033
Swen Schillig01b04752010-07-16 15:37:37 +02001034 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001035 if (ret)
1036 return ret;
1037
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001038 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001039 if (timeout > 255)
1040 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001041 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001042 req->qtcb->bottom.support.timeout = timeout;
1043 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001044
1045 return 0;
1046}
1047
1048/**
1049 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1050 * @ct: pointer to struct zfcp_send_ct with data for request
1051 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001052 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001053int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001054 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1055 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001056{
Swen Schillig564e1c82009-08-18 15:43:19 +02001057 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001058 struct zfcp_fsf_req *req;
1059 int ret = -EIO;
1060
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001061 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001062 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001063 goto out;
1064
Christof Schmitt1674b402010-04-30 18:09:34 +02001065 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
Jan Glauber3ec908782011-06-06 14:14:40 +02001066 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001067
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001068 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001069 ret = PTR_ERR(req);
1070 goto out;
1071 }
1072
Swen Schillig09a46c62009-08-18 15:43:16 +02001073 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001074 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001075 if (ret)
1076 goto failed_send;
1077
1078 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001079 req->qtcb->header.port_handle = wka_port->handle;
Steffen Maier771bf032016-08-10 18:30:51 +02001080 ct->d_id = wka_port->d_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001081 req->data = ct;
1082
Swen Schillig2c55b752010-12-02 15:16:13 +01001083 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001084
1085 ret = zfcp_fsf_req_send(req);
1086 if (ret)
1087 goto failed_send;
1088
1089 goto out;
1090
1091failed_send:
1092 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001093out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001094 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001095 return ret;
1096}
1097
1098static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1099{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001100 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001101 struct fsf_qtcb_header *header = &req->qtcb->header;
1102
1103 send_els->status = -EINVAL;
1104
1105 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1106 goto skip_fsfstatus;
1107
1108 switch (header->fsf_status) {
1109 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001110 send_els->status = 0;
Steffen Maier975171b2017-07-28 12:30:53 +02001111 zfcp_dbf_san_res("fsselh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001112 break;
1113 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1114 zfcp_fsf_class_not_supp(req);
1115 break;
1116 case FSF_ADAPTER_STATUS_AVAILABLE:
1117 switch (header->fsf_status_qual.word[0]){
1118 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001119 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1120 case FSF_SQ_RETRY_IF_POSSIBLE:
1121 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1122 break;
1123 }
1124 break;
1125 case FSF_ELS_COMMAND_REJECTED:
1126 case FSF_PAYLOAD_SIZE_MISMATCH:
1127 case FSF_REQUEST_SIZE_TOO_LARGE:
1128 case FSF_RESPONSE_SIZE_TOO_LARGE:
1129 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001130 case FSF_SBAL_MISMATCH:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001131 /* should never occur, avoided in zfcp_fsf_send_els */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001132 /* fall through */
1133 default:
1134 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1135 break;
1136 }
1137skip_fsfstatus:
1138 if (send_els->handler)
1139 send_els->handler(send_els->handler_data);
1140}
1141
1142/**
1143 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1144 * @els: pointer to struct zfcp_send_els with data for the command
1145 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001146int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001147 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001148{
1149 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001150 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001151 int ret = -EIO;
1152
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001153 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001154 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001155 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001156
Christof Schmitt1674b402010-04-30 18:09:34 +02001157 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
Jan Glauber3ec908782011-06-06 14:14:40 +02001158 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001159
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001160 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001161 ret = PTR_ERR(req);
1162 goto out;
1163 }
1164
Swen Schillig09a46c62009-08-18 15:43:16 +02001165 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001166
Swen Schillig86a96682011-08-15 14:40:32 +02001167 if (!zfcp_adapter_multi_buffer_active(adapter))
1168 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
Swen Schillig01b04752010-07-16 15:37:37 +02001169
1170 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001171
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001172 if (ret)
1173 goto failed_send;
1174
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001175 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001176 req->handler = zfcp_fsf_send_els_handler;
Steffen Maier771bf032016-08-10 18:30:51 +02001177 els->d_id = d_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001178 req->data = els;
1179
Swen Schillig2c55b752010-12-02 15:16:13 +01001180 zfcp_dbf_san_req("fssels1", req, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001181
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001182 ret = zfcp_fsf_req_send(req);
1183 if (ret)
1184 goto failed_send;
1185
1186 goto out;
1187
1188failed_send:
1189 zfcp_fsf_req_free(req);
1190out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001191 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001192 return ret;
1193}
1194
1195int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1196{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001197 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001198 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001199 int retval = -EIO;
1200
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001201 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001202 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001203 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001204
Swen Schillig564e1c82009-08-18 15:43:19 +02001205 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001206 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001207 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001208
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001209 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001210 retval = PTR_ERR(req);
1211 goto out;
1212 }
1213
Swen Schillig09a46c62009-08-18 15:43:16 +02001214 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001215 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001216
1217 req->qtcb->bottom.config.feature_selection =
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001218 FSF_FEATURE_NOTIFICATION_LOST |
1219 FSF_FEATURE_UPDATE_ALERT;
1220 req->erp_action = erp_action;
1221 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001222 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001223
Christof Schmitt287ac012008-07-02 10:56:40 +02001224 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001225 retval = zfcp_fsf_req_send(req);
1226 if (retval) {
1227 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001228 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001229 }
1230out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001231 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232 return retval;
1233}
1234
Swen Schillig564e1c82009-08-18 15:43:19 +02001235int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001236 struct fsf_qtcb_bottom_config *data)
1237{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 struct zfcp_fsf_req *req = NULL;
1239 int retval = -EIO;
1240
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001241 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001242 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001243 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001244
Christof Schmitt1674b402010-04-30 18:09:34 +02001245 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001246 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001247
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001248 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001249 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001250 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001251 }
1252
Christof Schmitt1674b402010-04-30 18:09:34 +02001253 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001254 req->handler = zfcp_fsf_exchange_config_data_handler;
1255
1256 req->qtcb->bottom.config.feature_selection =
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001257 FSF_FEATURE_NOTIFICATION_LOST |
1258 FSF_FEATURE_UPDATE_ALERT;
1259
1260 if (data)
1261 req->data = data;
1262
1263 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1264 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001265 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001266 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001267 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268
1269 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001270 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001271
Christof Schmittada81b72009-04-17 15:08:03 +02001272out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001273 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001274 return retval;
1275}
1276
1277/**
1278 * zfcp_fsf_exchange_port_data - request information about local port
1279 * @erp_action: ERP action for the adapter for which port data is requested
1280 * Returns: 0 on success, error otherwise
1281 */
1282int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1283{
Swen Schillig564e1c82009-08-18 15:43:19 +02001284 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001285 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001286 int retval = -EIO;
1287
Swen Schillig564e1c82009-08-18 15:43:19 +02001288 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001289 return -EOPNOTSUPP;
1290
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001291 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001292 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001293 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001294
Swen Schillig564e1c82009-08-18 15:43:19 +02001295 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001296 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001297 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001298
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001299 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001300 retval = PTR_ERR(req);
1301 goto out;
1302 }
1303
Swen Schillig09a46c62009-08-18 15:43:16 +02001304 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001305 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001306
1307 req->handler = zfcp_fsf_exchange_port_data_handler;
1308 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001309 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001310
Christof Schmitt287ac012008-07-02 10:56:40 +02001311 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001312 retval = zfcp_fsf_req_send(req);
1313 if (retval) {
1314 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001315 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001316 }
1317out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001318 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001319 return retval;
1320}
1321
1322/**
1323 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001324 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001325 * @data: pointer to struct fsf_qtcb_bottom_port
1326 * Returns: 0 on success, error otherwise
1327 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001328int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 struct fsf_qtcb_bottom_port *data)
1330{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001331 struct zfcp_fsf_req *req = NULL;
1332 int retval = -EIO;
1333
Swen Schillig564e1c82009-08-18 15:43:19 +02001334 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001335 return -EOPNOTSUPP;
1336
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001337 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001338 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001339 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001340
Christof Schmitt1674b402010-04-30 18:09:34 +02001341 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001342 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001343
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001344 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001345 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001346 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001347 }
1348
1349 if (data)
1350 req->data = data;
1351
Christof Schmitt1674b402010-04-30 18:09:34 +02001352 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001353
1354 req->handler = zfcp_fsf_exchange_port_data_handler;
1355 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1356 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001357 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001358
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001359 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001360 wait_for_completion(&req->completion);
1361
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001362 zfcp_fsf_req_free(req);
1363
1364 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001365
1366out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001367 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001368 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001369}
1370
1371static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1372{
1373 struct zfcp_port *port = req->data;
1374 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001375 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001376
1377 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001378 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001379
1380 switch (header->fsf_status) {
1381 case FSF_PORT_ALREADY_OPEN:
1382 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001383 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1384 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001385 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001386 "remote port 0x%016Lx\n",
1387 (unsigned long long)port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001388 zfcp_erp_set_port_status(port,
1389 ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001390 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1391 break;
1392 case FSF_ADAPTER_STATUS_AVAILABLE:
1393 switch (header->fsf_status_qual.word[0]) {
1394 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Steffen Maier394134f2017-07-28 12:31:00 +02001395 /* no zfcp_fc_test_link() with failed open port */
1396 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001397 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001398 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001399 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1400 break;
1401 }
1402 break;
1403 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 port->handle = header->port_handle;
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001405 atomic_or(ZFCP_STATUS_COMMON_OPEN |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001407 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED,
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001408 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 /* check whether D_ID has changed during open */
1410 /*
1411 * FIXME: This check is not airtight, as the FCP channel does
1412 * not monitor closures of target port connections caused on
1413 * the remote side. Thus, they might miss out on invalidating
1414 * locally cached WWPNs (and other N_Port parameters) of gone
1415 * target ports. So, our heroic attempt to make things safe
1416 * could be undermined by 'open port' response data tagged with
1417 * obsolete WWPNs. Another reason to monitor potential
1418 * connection closures ourself at least (by interpreting
1419 * incoming ELS' and unsolicited status). It just crosses my
1420 * mind that one should be able to cross-check by means of
1421 * another GID_PN straight after a port has been opened.
1422 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1423 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001424 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001425 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001426 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001427 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001430 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 break;
1432 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001433
1434out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001435 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001438/**
1439 * zfcp_fsf_open_port - create and send open port request
1440 * @erp_action: pointer to struct zfcp_erp_action
1441 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001443int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Swen Schillig564e1c82009-08-18 15:43:19 +02001445 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001446 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001447 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001448 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001450 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001451 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Swen Schillig564e1c82009-08-18 15:43:19 +02001454 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec908782011-06-06 14:14:40 +02001455 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001456 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001457
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001458 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001459 retval = PTR_ERR(req);
1460 goto out;
1461 }
1462
Swen Schillig09a46c62009-08-18 15:43:16 +02001463 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001464 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001466 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001467 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001468 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001469 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001470 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001471 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Christof Schmitt287ac012008-07-02 10:56:40 +02001473 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001474 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001476 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001477 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001478 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001480out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001481 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 return retval;
1483}
1484
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001485static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001487 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001489 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001490 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001492 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001494 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001495 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 case FSF_GOOD:
Swen Schilligedaed852010-09-08 14:40:01 +02001500 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001505/**
1506 * zfcp_fsf_close_port - create and send close port request
1507 * @erp_action: pointer to struct zfcp_erp_action
1508 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001510int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Swen Schillig564e1c82009-08-18 15:43:19 +02001512 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001513 struct zfcp_fsf_req *req;
1514 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001516 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001517 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Swen Schillig564e1c82009-08-18 15:43:19 +02001520 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001521 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001522 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001523
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001524 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001525 retval = PTR_ERR(req);
1526 goto out;
1527 }
1528
Swen Schillig09a46c62009-08-18 15:43:16 +02001529 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001530 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001532 req->handler = zfcp_fsf_close_port_handler;
1533 req->data = erp_action->port;
1534 req->erp_action = erp_action;
1535 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001536 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Christof Schmitt287ac012008-07-02 10:56:40 +02001538 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001539 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001541 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001542 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001544out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001545 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 return retval;
1547}
1548
Swen Schillig5ab944f2008-10-01 12:42:17 +02001549static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1550{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001551 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001552 struct fsf_qtcb_header *header = &req->qtcb->header;
1553
1554 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001555 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001556 goto out;
1557 }
1558
1559 switch (header->fsf_status) {
1560 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1561 dev_warn(&req->adapter->ccw_device->dev,
1562 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001563 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001564 case FSF_ADAPTER_STATUS_AVAILABLE:
1565 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittbd0072e2009-11-24 16:54:11 +01001566 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001567 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001568 case FSF_GOOD:
1569 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001570 /* fall through */
1571 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001572 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001573 }
1574out:
1575 wake_up(&wka_port->completion_wq);
1576}
1577
1578/**
1579 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001580 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001581 * Returns: 0 on success, error otherwise
1582 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001583int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001584{
Swen Schillig564e1c82009-08-18 15:43:19 +02001585 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Steffen Maier2dfa6682017-02-08 15:34:22 +01001586 struct zfcp_fsf_req *req;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001587 int retval = -EIO;
1588
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001589 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001590 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001591 goto out;
1592
Swen Schillig564e1c82009-08-18 15:43:19 +02001593 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec908782011-06-06 14:14:40 +02001594 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001595 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001596
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001597 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001598 retval = PTR_ERR(req);
1599 goto out;
1600 }
1601
Swen Schillig09a46c62009-08-18 15:43:16 +02001602 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001603 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001604
1605 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001606 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001607 req->data = wka_port;
1608
1609 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1610 retval = zfcp_fsf_req_send(req);
1611 if (retval)
1612 zfcp_fsf_req_free(req);
1613out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001614 spin_unlock_irq(&qdio->req_q_lock);
Steffen Maier2dfa6682017-02-08 15:34:22 +01001615 if (!retval)
Steffen Maierd27a7cb2016-08-10 18:30:49 +02001616 zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req->req_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001617 return retval;
1618}
1619
1620static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1621{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001622 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001623
1624 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1625 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligea4a3a62010-12-02 15:16:16 +01001626 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
Swen Schillig5ab944f2008-10-01 12:42:17 +02001627 }
1628
Christof Schmittbd0072e2009-11-24 16:54:11 +01001629 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001630 wake_up(&wka_port->completion_wq);
1631}
1632
1633/**
1634 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001635 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001636 * Returns: 0 on success, error otherwise
1637 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001638int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001639{
Swen Schillig564e1c82009-08-18 15:43:19 +02001640 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Steffen Maier2dfa6682017-02-08 15:34:22 +01001641 struct zfcp_fsf_req *req;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001642 int retval = -EIO;
1643
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001644 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001645 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001646 goto out;
1647
Swen Schillig564e1c82009-08-18 15:43:19 +02001648 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001649 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001650 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001651
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001652 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001653 retval = PTR_ERR(req);
1654 goto out;
1655 }
1656
Swen Schillig09a46c62009-08-18 15:43:16 +02001657 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001658 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001659
1660 req->handler = zfcp_fsf_close_wka_port_handler;
1661 req->data = wka_port;
1662 req->qtcb->header.port_handle = wka_port->handle;
1663
1664 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1665 retval = zfcp_fsf_req_send(req);
1666 if (retval)
1667 zfcp_fsf_req_free(req);
1668out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001669 spin_unlock_irq(&qdio->req_q_lock);
Steffen Maier2dfa6682017-02-08 15:34:22 +01001670 if (!retval)
Steffen Maierd27a7cb2016-08-10 18:30:49 +02001671 zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req->req_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001672 return retval;
1673}
1674
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001675static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001677 struct zfcp_port *port = req->data;
1678 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001679 struct scsi_device *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001681 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001682 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001686 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001687 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001690 /* can't use generic zfcp_erp_modify_port_status because
1691 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001692 atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001693 shost_for_each_device(sdev, port->adapter->scsi_host)
1694 if (sdev_to_zfcp(sdev)->port == port)
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001695 atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
Christof Schmittb62a8d92010-09-08 14:39:55 +02001696 &sdev_to_zfcp(sdev)->status);
Swen Schilligedaed852010-09-08 14:40:01 +02001697 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
1698 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001699 "fscpph2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001700 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 switch (header->fsf_status_qual.word[0]) {
1704 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001705 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001707 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 }
1710 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 /* can't use generic zfcp_erp_modify_port_status because
1713 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1714 */
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001715 atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001716 shost_for_each_device(sdev, port->adapter->scsi_host)
1717 if (sdev_to_zfcp(sdev)->port == port)
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001718 atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
Christof Schmittb62a8d92010-09-08 14:39:55 +02001719 &sdev_to_zfcp(sdev)->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001724/**
1725 * zfcp_fsf_close_physical_port - close physical port
1726 * @erp_action: pointer to struct zfcp_erp_action
1727 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001729int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
Swen Schillig564e1c82009-08-18 15:43:19 +02001731 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001732 struct zfcp_fsf_req *req;
1733 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001735 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001736 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Swen Schillig564e1c82009-08-18 15:43:19 +02001739 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001740 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001741 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001742
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001743 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001744 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 goto out;
1746 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001747
Swen Schillig09a46c62009-08-18 15:43:16 +02001748 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001749 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001750
1751 req->data = erp_action->port;
1752 req->qtcb->header.port_handle = erp_action->port->handle;
1753 req->erp_action = erp_action;
1754 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001755 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001756
Christof Schmitt287ac012008-07-02 10:56:40 +02001757 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001758 retval = zfcp_fsf_req_send(req);
1759 if (retval) {
1760 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001761 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001762 }
1763out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001764 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 return retval;
1766}
1767
Christof Schmittb62a8d92010-09-08 14:39:55 +02001768static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001770 struct zfcp_adapter *adapter = req->adapter;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001771 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001772 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001773 struct fsf_qtcb_header *header = &req->qtcb->header;
Martin Peschke663e0892013-04-26 16:13:54 +02001774 union fsf_status_qual *qual = &header->fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001776 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001777 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Martin Peschked436de82012-09-04 15:23:36 +02001779 zfcp_sdev = sdev_to_zfcp(sdev);
1780
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001781 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Martin Peschke663e0892013-04-26 16:13:54 +02001782 ZFCP_STATUS_COMMON_ACCESS_BOXED,
Christof Schmittb62a8d92010-09-08 14:39:55 +02001783 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 switch (header->fsf_status) {
1786
1787 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001788 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001789 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001793 zfcp_erp_set_port_status(zfcp_sdev->port,
1794 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1795 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001796 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001797 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 case FSF_LUN_SHARING_VIOLATION:
Martin Peschke663e0892013-04-26 16:13:54 +02001800 if (qual->word[0])
1801 dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
1802 "LUN 0x%Lx on port 0x%Lx is already in "
1803 "use by CSS%d, MIF Image ID %x\n",
1804 zfcp_scsi_dev_lun(sdev),
1805 (unsigned long long)zfcp_sdev->port->wwpn,
1806 qual->fsf_queue_designator.cssid,
1807 qual->fsf_queue_designator.hla);
1808 zfcp_erp_set_lun_status(sdev,
1809 ZFCP_STATUS_COMMON_ERP_FAILED |
1810 ZFCP_STATUS_COMMON_ACCESS_DENIED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001811 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001814 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001815 "No handle is available for LUN "
1816 "0x%016Lx on port 0x%016Lx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001817 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1818 (unsigned long long)zfcp_sdev->port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001819 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001820 /* fall through */
1821 case FSF_INVALID_COMMAND_OPTION:
1822 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 switch (header->fsf_status_qual.word[0]) {
1826 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001827 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001828 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001830 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 }
1833 break;
1834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001836 zfcp_sdev->lun_handle = header->lun_handle;
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001837 atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840}
1841
1842/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001843 * zfcp_fsf_open_lun - open LUN
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001844 * @erp_action: pointer to struct zfcp_erp_action
1845 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001847int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001849 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001850 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001851 struct zfcp_fsf_req *req;
1852 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001854 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001855 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001856 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
Swen Schillig564e1c82009-08-18 15:43:19 +02001858 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Jan Glauber3ec908782011-06-06 14:14:40 +02001859 SBAL_SFLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001860 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001861
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001862 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001863 retval = PTR_ERR(req);
1864 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001865 }
1866
Swen Schillig09a46c62009-08-18 15:43:16 +02001867 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001868 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001870 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001871 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1872 req->handler = zfcp_fsf_open_lun_handler;
1873 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001874 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001875 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001876
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001877 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1878 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
Christof Schmitt287ac012008-07-02 10:56:40 +02001880 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001881 retval = zfcp_fsf_req_send(req);
1882 if (retval) {
1883 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001884 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001887 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 return retval;
1889}
1890
Christof Schmittb62a8d92010-09-08 14:39:55 +02001891static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
Christof Schmittb62a8d92010-09-08 14:39:55 +02001893 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001894 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001895
1896 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001897 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001898
Martin Peschked436de82012-09-04 15:23:36 +02001899 zfcp_sdev = sdev_to_zfcp(sdev);
1900
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001901 switch (req->qtcb->header.fsf_status) {
1902 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001903 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001904 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1905 break;
1906 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001907 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001908 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1909 break;
1910 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001911 zfcp_erp_set_port_status(zfcp_sdev->port,
1912 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1913 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001914 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001915 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001916 break;
1917 case FSF_ADAPTER_STATUS_AVAILABLE:
1918 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1919 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001920 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001921 /* fall through */
1922 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1923 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1924 break;
1925 }
1926 break;
1927 case FSF_GOOD:
Peter Zijlstra805de8f42015-04-24 01:12:32 +02001928 atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001929 break;
1930 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001931}
1932
1933/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001934 * zfcp_fsf_close_LUN - close LUN
1935 * @erp_action: pointer to erp_action triggering the "close LUN"
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001936 * Returns: 0 on success, error otherwise
1937 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001938int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001939{
Swen Schillig564e1c82009-08-18 15:43:19 +02001940 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001941 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001942 struct zfcp_fsf_req *req;
1943 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001945 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001946 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001948
Swen Schillig564e1c82009-08-18 15:43:19 +02001949 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Jan Glauber3ec908782011-06-06 14:14:40 +02001950 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001951 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001952
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001953 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001954 retval = PTR_ERR(req);
1955 goto out;
1956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Swen Schillig09a46c62009-08-18 15:43:16 +02001958 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001959 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001961 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001962 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1963 req->handler = zfcp_fsf_close_lun_handler;
1964 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001965 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001966 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Christof Schmitt287ac012008-07-02 10:56:40 +02001968 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001969 retval = zfcp_fsf_req_send(req);
1970 if (retval) {
1971 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001972 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001973 }
1974out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001975 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001976 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977}
1978
Christof Schmittc9615852008-05-06 11:00:05 +02001979static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1980{
1981 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001982 lat_rec->min = min(lat_rec->min, lat);
1983 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02001984}
1985
Christof Schmittd9742b42009-11-24 16:54:03 +01001986static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02001987{
Christof Schmittd9742b42009-11-24 16:54:03 +01001988 struct fsf_qual_latency_info *lat_in;
1989 struct latency_cont *lat = NULL;
Martin Peschked436de82012-09-04 15:23:36 +02001990 struct zfcp_scsi_dev *zfcp_sdev;
Christof Schmittd9742b42009-11-24 16:54:03 +01001991 struct zfcp_blk_drv_data blktrc;
1992 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02001993
Christof Schmittd9742b42009-11-24 16:54:03 +01001994 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02001995
Christof Schmittd9742b42009-11-24 16:54:03 +01001996 blktrc.flags = 0;
1997 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
1998 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1999 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02002000 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002001 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002002
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002003 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2004 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Peschked436de82012-09-04 15:23:36 +02002005 zfcp_sdev = sdev_to_zfcp(scsi->device);
Christof Schmittd9742b42009-11-24 16:54:03 +01002006 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2007 blktrc.channel_lat = lat_in->channel_lat * ticks;
2008 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2009
2010 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002011 case FSF_DATADIR_DIF_READ_STRIP:
2012 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002013 case FSF_DATADIR_READ:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002014 lat = &zfcp_sdev->latencies.read;
Christof Schmittd9742b42009-11-24 16:54:03 +01002015 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002016 case FSF_DATADIR_DIF_WRITE_INSERT:
2017 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002018 case FSF_DATADIR_WRITE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002019 lat = &zfcp_sdev->latencies.write;
Christof Schmittd9742b42009-11-24 16:54:03 +01002020 break;
2021 case FSF_DATADIR_CMND:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002022 lat = &zfcp_sdev->latencies.cmd;
Christof Schmittd9742b42009-11-24 16:54:03 +01002023 break;
2024 }
2025
2026 if (lat) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02002027 spin_lock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002028 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2029 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2030 lat->counter++;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002031 spin_unlock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002032 }
Christof Schmittc9615852008-05-06 11:00:05 +02002033 }
2034
Christof Schmittd9742b42009-11-24 16:54:03 +01002035 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2036 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002037}
2038
Christof Schmittc61b5362010-09-08 14:39:58 +02002039static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002040{
Christof Schmittb62a8d92010-09-08 14:39:55 +02002041 struct scsi_cmnd *scmnd = req->data;
2042 struct scsi_device *sdev = scmnd->device;
Martin Peschked436de82012-09-04 15:23:36 +02002043 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002044 struct fsf_qtcb_header *header = &req->qtcb->header;
2045
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002046 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
Christof Schmittc61b5362010-09-08 14:39:58 +02002047 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002048
Martin Peschked436de82012-09-04 15:23:36 +02002049 zfcp_sdev = sdev_to_zfcp(sdev);
2050
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002051 switch (header->fsf_status) {
2052 case FSF_HANDLE_MISMATCH:
2053 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002054 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002055 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2056 break;
2057 case FSF_FCPLUN_NOT_VALID:
2058 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002059 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002060 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2061 break;
2062 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2063 zfcp_fsf_class_not_supp(req);
2064 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002065 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2066 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002067 "Incorrect direction %d, LUN 0x%016Lx on port "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002068 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002069 req->qtcb->bottom.io.data_direction,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002070 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2071 (unsigned long long)zfcp_sdev->port->wwpn);
2072 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002073 "fssfch3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002074 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2075 break;
2076 case FSF_CMND_LENGTH_NOT_VALID:
2077 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002078 "Incorrect CDB length %d, LUN 0x%016Lx on "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002079 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002080 req->qtcb->bottom.io.fcp_cmnd_length,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002081 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2082 (unsigned long long)zfcp_sdev->port->wwpn);
2083 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002084 "fssfch4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002085 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2086 break;
2087 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002088 zfcp_erp_set_port_status(zfcp_sdev->port,
2089 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2090 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002091 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002092 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002093 break;
2094 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002095 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2096 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002097 "fssfch6");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002098 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002099 break;
2100 case FSF_ADAPTER_STATUS_AVAILABLE:
2101 if (header->fsf_status_qual.word[0] ==
2102 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Christof Schmittb62a8d92010-09-08 14:39:55 +02002103 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2105 break;
2106 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002107}
2108
2109static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2110{
2111 struct scsi_cmnd *scpnt;
2112 struct fcp_resp_with_ext *fcp_rsp;
2113 unsigned long flags;
2114
Christof Schmittc61b5362010-09-08 14:39:58 +02002115 read_lock_irqsave(&req->adapter->abort_lock, flags);
2116
2117 scpnt = req->data;
2118 if (unlikely(!scpnt)) {
2119 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2120 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002121 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002122
Swen Schillig5bfb2c32010-11-17 14:23:40 +01002123 zfcp_fsf_fcp_handler_common(req);
2124
Christof Schmittc61b5362010-09-08 14:39:58 +02002125 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2126 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2127 goto skip_fsfstatus;
2128 }
2129
2130 switch (req->qtcb->header.fsf_status) {
2131 case FSF_INCONSISTENT_PROT_DATA:
2132 case FSF_INVALID_PROT_PARM:
2133 set_host_byte(scpnt, DID_ERROR);
2134 goto skip_fsfstatus;
2135 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2136 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2137 goto skip_fsfstatus;
2138 case FSF_APP_TAG_CHECK_FAILURE:
2139 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2140 goto skip_fsfstatus;
2141 case FSF_REF_TAG_CHECK_FAILURE:
2142 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2143 goto skip_fsfstatus;
2144 }
Steffen Maierdf00d7b2017-07-28 12:31:01 +02002145 BUILD_BUG_ON(sizeof(struct fcp_resp_with_ext) > FSF_FCP_RSP_SIZE);
2146 fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
Christof Schmittc61b5362010-09-08 14:39:58 +02002147 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2148
2149skip_fsfstatus:
2150 zfcp_fsf_req_trace(req, scpnt);
Swen Schillig250a1352010-12-02 15:16:15 +01002151 zfcp_dbf_scsi_result(scpnt, req);
Christof Schmittc61b5362010-09-08 14:39:58 +02002152
2153 scpnt->host_scribble = NULL;
2154 (scpnt->scsi_done) (scpnt);
2155 /*
2156 * We must hold this lock until scsi_done has been called.
2157 * Otherwise we may call scsi_done after abort regarding this
2158 * command has completed.
2159 * Note: scsi_done must not block!
2160 */
2161 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002162}
2163
Felix Beckef3eb712010-07-16 15:37:42 +02002164static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2165{
2166 switch (scsi_get_prot_op(scsi_cmnd)) {
2167 case SCSI_PROT_NORMAL:
2168 switch (scsi_cmnd->sc_data_direction) {
2169 case DMA_NONE:
2170 *data_dir = FSF_DATADIR_CMND;
2171 break;
2172 case DMA_FROM_DEVICE:
2173 *data_dir = FSF_DATADIR_READ;
2174 break;
2175 case DMA_TO_DEVICE:
2176 *data_dir = FSF_DATADIR_WRITE;
2177 break;
2178 case DMA_BIDIRECTIONAL:
2179 return -EINVAL;
2180 }
2181 break;
2182
2183 case SCSI_PROT_READ_STRIP:
2184 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2185 break;
2186 case SCSI_PROT_WRITE_INSERT:
2187 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2188 break;
2189 case SCSI_PROT_READ_PASS:
2190 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2191 break;
2192 case SCSI_PROT_WRITE_PASS:
2193 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2194 break;
2195 default:
2196 return -EINVAL;
2197 }
2198
2199 return 0;
2200}
2201
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002202/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002203 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002204 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002205 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002206int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002207{
2208 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002209 struct fcp_cmnd *fcp_cmnd;
Jan Glauber3ec908782011-06-06 14:14:40 +02002210 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
Swen Schillig86a96682011-08-15 14:40:32 +02002211 int retval = -EIO;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002212 struct scsi_device *sdev = scsi_cmnd->device;
2213 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2214 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002215 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002216 struct fsf_qtcb_bottom_io *io;
Christof Schmitte55f8752010-11-18 14:53:18 +01002217 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002218
Christof Schmittb62a8d92010-09-08 14:39:55 +02002219 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002220 ZFCP_STATUS_COMMON_UNBLOCKED)))
2221 return -EBUSY;
2222
Christof Schmitte55f8752010-11-18 14:53:18 +01002223 spin_lock_irqsave(&qdio->req_q_lock, flags);
Swen Schillig706eca42010-07-16 15:37:38 +02002224 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002225 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002226 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002227 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002228
Christof Schmitt1674b402010-04-30 18:09:34 +02002229 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
Jan Glauber3ec908782011-06-06 14:14:40 +02002230 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
Christof Schmitt1674b402010-04-30 18:09:34 +02002231
Swen Schillig564e1c82009-08-18 15:43:19 +02002232 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002233 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002234
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002235 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002236 retval = PTR_ERR(req);
2237 goto out;
2238 }
2239
Felix Beckef3eb712010-07-16 15:37:42 +02002240 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2241
2242 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002243 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002244 req->data = scsi_cmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002245 req->handler = zfcp_fsf_fcp_cmnd_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002246 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2247 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002248 io->service_class = FSF_CLASS_3;
2249 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002250
Felix Beckef3eb712010-07-16 15:37:42 +02002251 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2252 io->data_block_length = scsi_cmnd->device->sector_size;
2253 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002254 }
2255
Steffen Maiercc405ac2011-08-15 14:40:30 +02002256 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2257 goto failed_scsi_cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +02002258
Steffen Maierdf00d7b2017-07-28 12:31:01 +02002259 BUILD_BUG_ON(sizeof(struct fcp_cmnd) > FSF_FCP_CMND_SIZE);
2260 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002261 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002262
Steffen Maier71b8e452017-07-28 12:30:51 +02002263 if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
2264 scsi_prot_sg_count(scsi_cmnd)) {
Felix Beckef3eb712010-07-16 15:37:42 +02002265 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2266 scsi_prot_sg_count(scsi_cmnd));
Swen Schillig86a96682011-08-15 14:40:32 +02002267 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2268 scsi_prot_sglist(scsi_cmnd));
2269 if (retval)
2270 goto failed_scsi_cmnd;
2271 io->prot_data_length = zfcp_qdio_real_bytes(
Felix Beckef3eb712010-07-16 15:37:42 +02002272 scsi_prot_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002273 }
2274
Swen Schillig86a96682011-08-15 14:40:32 +02002275 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2276 scsi_sglist(scsi_cmnd));
2277 if (unlikely(retval))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002278 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002279
Felix Beckef3eb712010-07-16 15:37:42 +02002280 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schillig86a96682011-08-15 14:40:32 +02002281 if (zfcp_adapter_multi_buffer_active(adapter))
2282 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Felix Beckef3eb712010-07-16 15:37:42 +02002283
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002284 retval = zfcp_fsf_req_send(req);
2285 if (unlikely(retval))
2286 goto failed_scsi_cmnd;
2287
2288 goto out;
2289
2290failed_scsi_cmnd:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002291 zfcp_fsf_req_free(req);
2292 scsi_cmnd->host_scribble = NULL;
2293out:
Christof Schmitte55f8752010-11-18 14:53:18 +01002294 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002295 return retval;
2296}
2297
Christof Schmittc61b5362010-09-08 14:39:58 +02002298static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2299{
2300 struct fcp_resp_with_ext *fcp_rsp;
2301 struct fcp_resp_rsp_info *rsp_info;
2302
2303 zfcp_fsf_fcp_handler_common(req);
2304
Steffen Maierdf00d7b2017-07-28 12:31:01 +02002305 fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
Christof Schmittc61b5362010-09-08 14:39:58 +02002306 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2307
2308 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2309 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2310 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2311}
2312
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002313/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002314 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2315 * @scmnd: SCSI command to send the task management command for
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002316 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002317 * Returns: on success pointer to struct fsf_req, NULL otherwise
2318 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002319struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2320 u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002321{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002322 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002323 struct fcp_cmnd *fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002324 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2325 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002326
Christof Schmittb62a8d92010-09-08 14:39:55 +02002327 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002328 ZFCP_STATUS_COMMON_UNBLOCKED)))
2329 return NULL;
2330
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002331 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002332 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002333 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002334
Swen Schillig564e1c82009-08-18 15:43:19 +02002335 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Jan Glauber3ec908782011-06-06 14:14:40 +02002336 SBAL_SFLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002337 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002338
Swen Schillig633528c2008-11-26 18:07:37 +01002339 if (IS_ERR(req)) {
2340 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002341 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002342 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002343
Christof Schmittb62a8d92010-09-08 14:39:55 +02002344 req->data = scmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002345 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002346 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2347 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2349 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002350 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002351
Christof Schmitt1674b402010-04-30 18:09:34 +02002352 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002353
Steffen Maierdf00d7b2017-07-28 12:31:01 +02002354 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002355 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002356
2357 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2358 if (!zfcp_fsf_req_send(req))
2359 goto out;
2360
2361 zfcp_fsf_req_free(req);
2362 req = NULL;
2363out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002364 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002365 return req;
2366}
2367
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002368/**
2369 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2370 * @adapter: pointer to struct zfcp_adapter
2371 * @sbal_idx: response queue index of SBAL to be processed
2372 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002373void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002374{
Swen Schillig564e1c82009-08-18 15:43:19 +02002375 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002376 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002377 struct qdio_buffer_element *sbale;
2378 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb92010-02-17 11:18:50 +01002379 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002380 int idx;
2381
2382 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2383
2384 sbale = &sbal->element[idx];
2385 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb92010-02-17 11:18:50 +01002386 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002387
Christof Schmitt339f4f42010-07-16 15:37:43 +02002388 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002389 /*
2390 * Unknown request means that we have potentially memory
2391 * corruption and must stop the machine immediately.
2392 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002393 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002394 panic("error: unknown req_id (%lx) on adapter %s.\n",
2395 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002396 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002397
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002398 zfcp_fsf_req_complete(fsf_req);
2399
Jan Glauber3ec908782011-06-06 14:14:40 +02002400 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002401 break;
2402 }
2403}