blob: 961e327b692831ba122bd021c28d7f66064cbd25 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Implementation of FSF commands.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Steffen Maier17a9afa2013-04-26 17:34:54 +02006 * Copyright IBM Corp. 2002, 2013
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Stefan Raspl0997f1c2008-10-16 08:23:39 +020012#include <linux/blktrace_api.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Christof Schmitt9d05ce22009-11-24 16:54:09 +010014#include <scsi/fc/fc_els.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "zfcp_ext.h"
Christof Schmitt4318e082009-11-24 16:54:08 +010016#include "zfcp_fc.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020017#include "zfcp_dbf.h"
Christof Schmitt34c2b712010-02-17 11:18:59 +010018#include "zfcp_qdio.h"
Christof Schmittb6bd2fb2010-02-17 11:18:50 +010019#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Christof Schmitt259afe22011-02-22 19:54:44 +010021struct kmem_cache *zfcp_fsf_qtcb_cache;
22
Christof Schmitt287ac012008-07-02 10:56:40 +020023static void zfcp_fsf_request_timeout_handler(unsigned long data)
24{
25 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Christof Schmitt339f4f42010-07-16 15:37:43 +020026 zfcp_qdio_siosl(adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010027 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +010028 "fsrth_1");
Christof Schmitt287ac012008-07-02 10:56:40 +020029}
30
31static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
32 unsigned long timeout)
33{
34 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
35 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
36 fsf_req->timer.expires = jiffies + timeout;
37 add_timer(&fsf_req->timer);
38}
39
40static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
41{
42 BUG_ON(!fsf_req->erp_action);
43 fsf_req->timer.function = zfcp_erp_timeout_handler;
44 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
45 fsf_req->timer.expires = jiffies + 30 * HZ;
46 add_timer(&fsf_req->timer);
47}
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/* association between FSF command and FSF QTCB type */
50static u32 fsf_qtcb_type[] = {
51 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
52 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
61 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
62 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
63 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
64};
65
Christof Schmitt553448f2008-06-10 18:20:58 +020066static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
67{
Christof Schmittff3b24f2008-10-01 12:42:15 +020068 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
69 "operational because of an unsupported FC class\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +010070 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
Christof Schmitt553448f2008-06-10 18:20:58 +020071 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
72}
73
Swen Schilligc41f8cb2008-07-02 10:56:39 +020074/**
75 * zfcp_fsf_req_free - free memory used by fsf request
76 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +020078void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020080 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +020081 if (likely(req->qtcb))
82 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +020083 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020084 return;
85 }
86
Swen Schilliga4623c42009-08-18 15:43:15 +020087 if (likely(req->qtcb))
Christof Schmitt259afe22011-02-22 19:54:44 +010088 kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
Swen Schilliga4623c42009-08-18 15:43:15 +020089 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Swen Schilligc41f8cb2008-07-02 10:56:39 +020092static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Swen Schilligecf0c772009-11-24 16:53:58 +010094 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +020095 struct fsf_status_read_buffer *sr_buf = req->data;
96 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +010098 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Swen Schilligecf0c772009-11-24 16:53:58 +0100100 read_lock_irqsave(&adapter->port_list_lock, flags);
101 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200102 if (port->d_id == d_id) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100103 zfcp_erp_port_reopen(port, 0, "fssrpc1");
Swen Schilligecf0c772009-11-24 16:53:58 +0100104 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200105 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100106 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Swen Schilligedaed852010-09-08 14:40:01 +0200109static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200110 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200112 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200114 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
115 return;
116
117 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200118
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100119 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200120
121 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200123
124 switch (link_down->error_code) {
125 case FSF_PSQ_LINK_NO_LIGHT:
126 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200127 "There is no light signal from the local "
128 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200129 break;
130 case FSF_PSQ_LINK_WRAP_PLUG:
131 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200132 "There is a wrap plug instead of a fibre "
133 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200134 break;
135 case FSF_PSQ_LINK_NO_FCP:
136 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200137 "The adjacent fibre channel node does not "
138 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200139 break;
140 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
141 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200142 "The FCP device is suspended because of a "
143 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200144 break;
145 case FSF_PSQ_LINK_INVALID_WWPN:
146 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200147 "The FCP device detected a WWPN that is "
148 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200149 break;
150 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
151 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200152 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200153 break;
154 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
155 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200156 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200157 break;
158 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
159 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200160 "The adjacent switch cannot support "
161 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200162 break;
163 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
164 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200165 "The FCP adapter could not log in to the "
166 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200167 break;
168 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
169 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200170 "The WWPN assignment file on the FCP adapter "
171 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200172 break;
173 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
174 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200175 "The mode table on the FCP adapter "
176 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200177 break;
178 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
179 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200180 "All NPIV ports on the FCP adapter have "
181 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200182 break;
183 default:
184 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200185 "The link between the FCP adapter and "
186 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200187 }
188out:
Swen Schilligedaed852010-09-08 14:40:01 +0200189 zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200190}
191
192static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
193{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200194 struct fsf_status_read_buffer *sr_buf = req->data;
195 struct fsf_link_down_info *ldi =
196 (struct fsf_link_down_info *) &sr_buf->payload;
197
198 switch (sr_buf->status_subtype) {
199 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schilligedaed852010-09-08 14:40:01 +0200200 zfcp_fsf_link_down_info_eval(req, ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200201 break;
202 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schilligedaed852010-09-08 14:40:01 +0200203 zfcp_fsf_link_down_info_eval(req, ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200204 break;
205 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schilligedaed852010-09-08 14:40:01 +0200206 zfcp_fsf_link_down_info_eval(req, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200207 };
208}
209
210static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
211{
212 struct zfcp_adapter *adapter = req->adapter;
213 struct fsf_status_read_buffer *sr_buf = req->data;
214
215 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100216 zfcp_dbf_hba_fsf_uss("fssrh_1", req);
Christof Schmittc7b279a2011-02-22 19:54:40 +0100217 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200218 zfcp_fsf_req_free(req);
219 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
221
Steffen Maier1afbcbd2012-09-04 15:23:30 +0200222 zfcp_dbf_hba_fsf_uss("fssrh_4", req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200223
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200224 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200226 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200229 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200234 dev_warn(&adapter->ccw_device->dev,
235 "The error threshold for checksum statistics "
236 "has been exceeded\n");
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100237 zfcp_dbf_hba_bit_err("fssrh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200240 zfcp_fsf_status_read_link_down(req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200241 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200244 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200245 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /* All ports should be marked as ready to run again */
Swen Schilligedaed852010-09-08 14:40:01 +0200247 zfcp_erp_set_adapter_status(adapter,
248 ZFCP_STATUS_COMMON_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200250 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
251 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100252 "fssrh_2");
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200253 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100256 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200257 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Christof Schmitta1ca4832010-09-08 14:39:59 +0200258 zfcp_cfdc_adapter_access_changed(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200259 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100260 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100261 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case FSF_STATUS_READ_CFDC_UPDATED:
Christof Schmitta1ca4832010-09-08 14:39:59 +0200263 zfcp_cfdc_adapter_access_changed(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200265 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200266 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200269
Christof Schmittc7b279a2011-02-22 19:54:40 +0100270 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200271 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200272
273 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200274 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200277static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200279 switch (req->qtcb->header.fsf_status_qual.word[0]) {
280 case FSF_SQ_FCP_RSP_AVAILABLE:
281 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
282 case FSF_SQ_NO_RETRY_POSSIBLE:
283 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
284 return;
285 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200286 break;
287 case FSF_SQ_NO_RECOM:
288 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200289 "The FCP adapter reported a problem "
290 "that cannot be recovered\n");
Christof Schmitt339f4f42010-07-16 15:37:43 +0200291 zfcp_qdio_siosl(req->adapter);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100292 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200293 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200295 /* all non-return stats set FSFREQ_ERROR*/
296 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
297}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200299static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
300{
301 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
302 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200303
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200304 switch (req->qtcb->header.fsf_status) {
305 case FSF_UNKNOWN_COMMAND:
306 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200307 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200308 req->qtcb->header.fsf_command);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100309 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200310 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200313 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200318static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200320 struct zfcp_adapter *adapter = req->adapter;
321 struct fsf_qtcb *qtcb = req->qtcb;
322 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Swen Schillig57717102009-08-18 15:43:21 +0200324 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200326 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100327 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200328 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
330
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200331 switch (qtcb->prefix.prot_status) {
332 case FSF_PROT_GOOD:
333 case FSF_PROT_FSF_STATUS_PRESENTED:
334 return;
335 case FSF_PROT_QTCB_VERSION_ERROR:
336 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200337 "QTCB version 0x%x not supported by FCP adapter "
338 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
339 psq->word[0], psq->word[1]);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100340 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200342 case FSF_PROT_ERROR_STATE:
343 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100344 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100345 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200347 case FSF_PROT_UNSUPP_QTCB_TYPE:
348 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200349 "The QTCB type is not supported by the FCP adapter\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100350 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200352 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
353 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
354 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200356 case FSF_PROT_DUPLICATE_REQUEST_ID:
357 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200358 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200359 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100360 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200362 case FSF_PROT_LINK_DOWN:
Swen Schilligedaed852010-09-08 14:40:01 +0200363 zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100364 /* go through reopen to flush pending requests */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100365 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200367 case FSF_PROT_REEST_QUEUE:
368 /* All ports should be marked as ready to run again */
Swen Schilligedaed852010-09-08 14:40:01 +0200369 zfcp_erp_set_adapter_status(adapter,
370 ZFCP_STATUS_COMMON_RUNNING);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200371 zfcp_erp_adapter_reopen(adapter,
372 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100373 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100374 "fspse_8");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200375 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200377 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200378 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200379 qtcb->prefix.prot_status);
Christof Schmitt339f4f42010-07-16 15:37:43 +0200380 zfcp_qdio_siosl(adapter);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100381 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200383 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
386/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200387 * zfcp_fsf_req_complete - process completion of a FSF request
388 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200390 * When a request has been completed either from the FCP adapter,
391 * or it has been dismissed due to a queue shutdown, this function
392 * is called to process the completion status and trigger further
393 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200395static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200396{
397 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
398 zfcp_fsf_status_read_handler(req);
399 return;
400 }
401
402 del_timer(&req->timer);
403 zfcp_fsf_protstatus_eval(req);
404 zfcp_fsf_fsfstatus_eval(req);
405 req->handler(req);
406
407 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200408 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200409
410 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
411 zfcp_fsf_req_free(req);
412 else
Swen Schillig058b8642009-08-18 15:43:14 +0200413 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200414}
415
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200416/**
417 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
418 * @adapter: pointer to struct zfcp_adapter
419 *
420 * Never ever call this without shutting down the adapter first.
421 * Otherwise the adapter would continue using and corrupting s390 storage.
422 * Included BUG_ON() call to ensure this is done.
423 * ERP is supposed to be the only user of this function.
424 */
425void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
426{
427 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200428 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200429
430 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100431 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200432
433 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
434 list_del(&req->list);
435 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
436 zfcp_fsf_req_complete(req);
437 }
438}
439
Steffen Maierab617442012-09-04 15:23:29 +0200440#define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
441#define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
442#define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
443#define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
444#define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
445#define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
446#define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
447
448static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
449{
450 u32 fdmi_speed = 0;
451 if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
452 fdmi_speed |= FC_PORTSPEED_1GBIT;
453 if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
454 fdmi_speed |= FC_PORTSPEED_2GBIT;
455 if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
456 fdmi_speed |= FC_PORTSPEED_4GBIT;
457 if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
458 fdmi_speed |= FC_PORTSPEED_10GBIT;
459 if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
460 fdmi_speed |= FC_PORTSPEED_8GBIT;
461 if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
462 fdmi_speed |= FC_PORTSPEED_16GBIT;
463 if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
464 fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
465 return fdmi_speed;
466}
467
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200468static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100470 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200471 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200472 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100473 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100475 /* adjust pointers for missing command code */
476 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
477 - sizeof(u32));
478 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
479 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200480
481 if (req->data)
482 memcpy(req->data, bottom, sizeof(*bottom));
483
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100484 fc_host_port_name(shost) = nsp->fl_wwpn;
485 fc_host_node_name(shost) = nsp->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200486 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
487
Christof Schmittfaf4cd82010-07-16 15:37:36 +0200488 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200489 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
490 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200491
492 if (fc_host_permanent_port_name(shost) == -1)
493 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
494
Steffen Maier17a9afa2013-04-26 17:34:54 +0200495 zfcp_scsi_set_prot(adapter);
496
497 /* no error return above here, otherwise must fix call chains */
498 /* do not evaluate invalid fields */
499 if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
500 return 0;
501
502 fc_host_port_id(shost) = ntoh24(bottom->s_id);
503 fc_host_speed(shost) =
504 zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
505
506 adapter->hydra_version = bottom->adapter_type;
507
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200508 switch (bottom->fc_topology) {
509 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100510 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100511 adapter->peer_wwpn = plogi->fl_wwpn;
512 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200513 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200514 break;
515 case FSF_TOPO_FABRIC:
516 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 break;
518 case FSF_TOPO_AL:
519 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200520 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200521 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200522 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200523 "Unknown or unsupported arbitrated loop "
524 "fibre channel topology detected\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100525 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200526 return -EIO;
527 }
528
529 return 0;
530}
531
532static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
533{
534 struct zfcp_adapter *adapter = req->adapter;
535 struct fsf_qtcb *qtcb = req->qtcb;
536 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
537 struct Scsi_Host *shost = adapter->scsi_host;
538
539 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
540 return;
541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200543 adapter->adapter_features = bottom->adapter_features;
544 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500545 adapter->peer_wwpn = 0;
546 adapter->peer_wwnn = 0;
547 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200549 switch (qtcb->header.fsf_status) {
550 case FSF_GOOD:
551 if (zfcp_fsf_exchange_config_evaluate(req))
552 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200553
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200554 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
555 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200556 "FCP adapter maximum QTCB size (%d bytes) "
557 "is too small\n",
558 bottom->max_qtcb_size);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100559 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200560 return;
561 }
562 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
563 &adapter->status);
564 break;
565 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200566 fc_host_node_name(shost) = 0;
567 fc_host_port_name(shost) = 0;
568 fc_host_port_id(shost) = 0;
569 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100570 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200572
Daniel Hansele09e21a2013-04-26 17:32:14 +0200573 /* avoids adapter shutdown to be able to recognize
574 * events such as LINK UP */
575 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
576 &adapter->status);
Swen Schilligedaed852010-09-08 14:40:01 +0200577 zfcp_fsf_link_down_info_eval(req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200578 &qtcb->header.fsf_status_qual.link_down_info);
Steffen Maier17a9afa2013-04-26 17:34:54 +0200579 if (zfcp_fsf_exchange_config_evaluate(req))
580 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200581 break;
582 default:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100583 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200584 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200587 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200589 memcpy(fc_host_serial_number(shost), bottom->serial_number,
590 min(FC_SERIAL_NUMBER_SIZE, 17));
591 EBCASC(fc_host_serial_number(shost),
592 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
594
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200595 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200596 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200597 "The FCP adapter only supports newer "
598 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100599 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200600 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200602 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200603 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200604 "The FCP adapter only supports older "
605 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100606 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200610static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200612 struct zfcp_adapter *adapter = req->adapter;
613 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
614 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200616 if (req->data)
617 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100618
Christof Schmitt02829852009-03-02 13:09:06 +0100619 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100620 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100621 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
622 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100623 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
624 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
Steffen Maierab617442012-09-04 15:23:29 +0200625 fc_host_supported_speeds(shost) =
626 zfcp_fsf_convert_portspeed(bottom->supported_speed);
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100627 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
628 FC_FC4_LIST_SIZE);
629 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
630 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100631}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200633static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200635 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100636
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 return;
639
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200640 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200641 case FSF_GOOD:
642 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200643 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200644 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200645 zfcp_fsf_exchange_port_evaluate(req);
Swen Schilligedaed852010-09-08 14:40:01 +0200646 zfcp_fsf_link_down_info_eval(req,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200647 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200648 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650}
651
Swen Schilliga4623c42009-08-18 15:43:15 +0200652static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200653{
654 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200655
656 if (likely(pool))
657 req = mempool_alloc(pool, GFP_ATOMIC);
658 else
659 req = kmalloc(sizeof(*req), GFP_ATOMIC);
660
661 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200663
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200664 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100665 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200666 return req;
667}
668
Swen Schilliga4623c42009-08-18 15:43:15 +0200669static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200670{
Swen Schilliga4623c42009-08-18 15:43:15 +0200671 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200672
673 if (likely(pool))
674 qtcb = mempool_alloc(pool, GFP_ATOMIC);
675 else
Christof Schmitt259afe22011-02-22 19:54:44 +0100676 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
Swen Schilliga4623c42009-08-18 15:43:15 +0200677
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200678 if (unlikely(!qtcb))
679 return NULL;
680
681 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200682 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200683}
684
Swen Schillig564e1c82009-08-18 15:43:19 +0200685static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Jan Glauber3ec90872011-06-06 14:14:40 +0200686 u32 fsf_cmd, u8 sbtype,
Christof Schmitt1674b402010-04-30 18:09:34 +0200687 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Swen Schillig564e1c82009-08-18 15:43:19 +0200689 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200690 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200691
692 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200693 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200694
695 if (adapter->req_no == 0)
696 adapter->req_no++;
697
698 INIT_LIST_HEAD(&req->list);
699 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200700 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200701
702 req->adapter = adapter;
703 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100704 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200705
Swen Schilliga4623c42009-08-18 15:43:15 +0200706 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
707 if (likely(pool))
708 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
709 else
710 req->qtcb = zfcp_qtcb_alloc(NULL);
711
712 if (unlikely(!req->qtcb)) {
713 zfcp_fsf_req_free(req);
714 return ERR_PTR(-ENOMEM);
715 }
716
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100717 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200718 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200719 req->qtcb->prefix.req_id = req->req_id;
720 req->qtcb->prefix.ulp_info = 26;
721 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
722 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
723 req->qtcb->header.req_handle = req->req_id;
724 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200725 }
726
Christof Schmitt1674b402010-04-30 18:09:34 +0200727 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
728 req->qtcb, sizeof(struct fsf_qtcb));
729
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200730 return req;
731}
732
733static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
734{
735 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200736 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100737 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100738 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200739
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100740 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200741
Swen Schillig706eca42010-07-16 15:37:38 +0200742 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200743 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100744 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200745 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100746 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100747 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100748 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200749 return -EIO;
750 }
751
752 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200753 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200754 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100755 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200756
757 return 0;
758}
759
760/**
761 * zfcp_fsf_status_read - send status read request
762 * @adapter: pointer to struct zfcp_adapter
763 * @req_flags: request flags
764 * Returns: 0 on success, ERROR otherwise
765 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200766int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200767{
Swen Schillig564e1c82009-08-18 15:43:19 +0200768 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200769 struct zfcp_fsf_req *req;
770 struct fsf_status_read_buffer *sr_buf;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100771 struct page *page;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772 int retval = -EIO;
773
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200774 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200775 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Christof Schmitt1674b402010-04-30 18:09:34 +0200778 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200779 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200780 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200781 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 goto out;
783 }
784
Christof Schmittc7b279a2011-02-22 19:54:40 +0100785 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
786 if (!page) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200787 retval = -ENOMEM;
788 goto failed_buf;
789 }
Christof Schmittc7b279a2011-02-22 19:54:40 +0100790 sr_buf = page_address(page);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200791 memset(sr_buf, 0, sizeof(*sr_buf));
792 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200793
794 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
795 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200796
797 retval = zfcp_fsf_req_send(req);
798 if (retval)
799 goto failed_req_send;
800
801 goto out;
802
803failed_req_send:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100804 req->data = NULL;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100805 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200806failed_buf:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100807 zfcp_dbf_hba_fsf_uss("fssr__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200808 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200809out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200810 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 return retval;
812}
813
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200814static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200816 struct scsi_device *sdev = req->data;
Martin Peschke82e05512012-09-04 15:23:36 +0200817 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200818 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
821 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Martin Peschke82e05512012-09-04 15:23:36 +0200823 zfcp_sdev = sdev_to_zfcp(sdev);
824
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200825 switch (req->qtcb->header.fsf_status) {
826 case FSF_PORT_HANDLE_NOT_VALID:
827 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200828 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100829 "fsafch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200830 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200833 case FSF_LUN_HANDLE_NOT_VALID:
834 if (fsq->word[0] == fsq->word[1]) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100835 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200836 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200839 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
840 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200842 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200843 zfcp_erp_set_port_status(zfcp_sdev->port,
844 ZFCP_STATUS_COMMON_ACCESS_BOXED);
845 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100846 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100847 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200848 break;
849 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200850 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
851 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100852 "fsafch4");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100853 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200854 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200856 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200858 zfcp_fc_test_link(zfcp_sdev->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200859 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
863 }
864 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
867 break;
868 }
869}
870
871/**
Christof Schmittb62a8d92010-09-08 14:39:55 +0200872 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
873 * @scmnd: The SCSI command to abort
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200874 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200875 */
876
Christof Schmittb62a8d92010-09-08 14:39:55 +0200877struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200879 struct zfcp_fsf_req *req = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200880 struct scsi_device *sdev = scmnd->device;
881 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
882 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
883 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200885 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200886 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200887 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200888 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Jan Glauber3ec90872011-06-06 14:14:40 +0200889 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200890 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100891 if (IS_ERR(req)) {
892 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200893 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100894 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200895
Christof Schmittb62a8d92010-09-08 14:39:55 +0200896 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200897 ZFCP_STATUS_COMMON_UNBLOCKED)))
898 goto out_error_free;
899
Christof Schmitt1674b402010-04-30 18:09:34 +0200900 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200901
Swen Schillig6fbf25e2010-11-17 14:23:41 +0100902 req->data = sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200903 req->handler = zfcp_fsf_abort_fcp_command_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200904 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
905 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200906 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
907
908 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
909 if (!zfcp_fsf_req_send(req))
910 goto out;
911
912out_error_free:
913 zfcp_fsf_req_free(req);
914 req = NULL;
915out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200916 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200917 return req;
918}
919
920static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
921{
922 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100923 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200924 struct fsf_qtcb_header *header = &req->qtcb->header;
925
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100926 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200927
928 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
929 goto skip_fsfstatus;
930
931 switch (header->fsf_status) {
932 case FSF_GOOD:
Steffen Maier1afbcbd2012-09-04 15:23:30 +0200933 zfcp_dbf_san_res("fsscth2", req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100934 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200935 break;
936 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
937 zfcp_fsf_class_not_supp(req);
938 break;
939 case FSF_ADAPTER_STATUS_AVAILABLE:
940 switch (header->fsf_status_qual.word[0]){
941 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200942 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
943 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
944 break;
945 }
946 break;
947 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200948 break;
949 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100950 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200951 break;
952 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100953 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
Christof Schmittdceab652009-05-15 13:18:18 +0200954 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200955 case FSF_GENERIC_COMMAND_REJECTED:
956 case FSF_PAYLOAD_SIZE_MISMATCH:
957 case FSF_REQUEST_SIZE_TOO_LARGE:
958 case FSF_RESPONSE_SIZE_TOO_LARGE:
959 case FSF_SBAL_MISMATCH:
960 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
961 break;
962 }
963
964skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100965 if (ct->handler)
966 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200967}
968
Christof Schmitt1674b402010-04-30 18:09:34 +0200969static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
970 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200971 struct scatterlist *sg_req,
972 struct scatterlist *sg_resp)
973{
Christof Schmitt1674b402010-04-30 18:09:34 +0200974 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
975 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
976 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200977}
978
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100979static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
980 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200981 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200982{
Swen Schillig42428f72009-08-18 15:43:18 +0200983 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig86a96682011-08-15 14:40:32 +0200984 struct zfcp_qdio *qdio = adapter->qdio;
985 struct fsf_qtcb *qtcb = req->qtcb;
Swen Schillig42428f72009-08-18 15:43:18 +0200986 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200987
Swen Schillig86a96682011-08-15 14:40:32 +0200988 if (zfcp_adapter_multi_buffer_active(adapter)) {
989 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
990 return -EIO;
991 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
992 return -EIO;
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100993
Swen Schillig86a96682011-08-15 14:40:32 +0200994 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
995 zfcp_qdio_sbale_count(sg_req));
996 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
997 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200998 return 0;
999 }
1000
1001 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +02001002 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Swen Schillig86a96682011-08-15 14:40:32 +02001003 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +02001004 sg_req, sg_resp);
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001005 return 0;
1006 }
1007
Swen Schillig86a96682011-08-15 14:40:32 +02001008 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
1009 return -EOPNOTSUPP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001010
Swen Schillig86a96682011-08-15 14:40:32 +02001011 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
Christof Schmitt9072df42009-07-13 15:06:07 +02001012 return -EIO;
Swen Schillig86a96682011-08-15 14:40:32 +02001013
1014 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1015
1016 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1017 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1018
1019 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1020 return -EIO;
1021
1022 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1023
1024 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001025
Christof Schmittb1a58982009-09-24 10:23:21 +02001026 return 0;
1027}
1028
1029static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1030 struct scatterlist *sg_req,
1031 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001032 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001033{
1034 int ret;
1035
Swen Schillig01b04752010-07-16 15:37:37 +02001036 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001037 if (ret)
1038 return ret;
1039
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001040 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001041 if (timeout > 255)
1042 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001043 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001044 req->qtcb->bottom.support.timeout = timeout;
1045 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001046
1047 return 0;
1048}
1049
1050/**
1051 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1052 * @ct: pointer to struct zfcp_send_ct with data for request
1053 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001054 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001055int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001056 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1057 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001058{
Swen Schillig564e1c82009-08-18 15:43:19 +02001059 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001060 struct zfcp_fsf_req *req;
1061 int ret = -EIO;
1062
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001063 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001064 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001065 goto out;
1066
Christof Schmitt1674b402010-04-30 18:09:34 +02001067 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
Jan Glauber3ec90872011-06-06 14:14:40 +02001068 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001069
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001070 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001071 ret = PTR_ERR(req);
1072 goto out;
1073 }
1074
Swen Schillig09a46c62009-08-18 15:43:16 +02001075 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001076 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001077 if (ret)
1078 goto failed_send;
1079
1080 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001081 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001082 req->data = ct;
1083
Swen Schillig2c55b752010-12-02 15:16:13 +01001084 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001085
1086 ret = zfcp_fsf_req_send(req);
1087 if (ret)
1088 goto failed_send;
1089
1090 goto out;
1091
1092failed_send:
1093 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001094out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001095 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001096 return ret;
1097}
1098
1099static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1100{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001101 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001102 struct zfcp_port *port = send_els->port;
1103 struct fsf_qtcb_header *header = &req->qtcb->header;
1104
1105 send_els->status = -EINVAL;
1106
1107 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1108 goto skip_fsfstatus;
1109
1110 switch (header->fsf_status) {
1111 case FSF_GOOD:
Swen Schillig2c55b752010-12-02 15:16:13 +01001112 zfcp_dbf_san_res("fsselh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001113 send_els->status = 0;
1114 break;
1115 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1116 zfcp_fsf_class_not_supp(req);
1117 break;
1118 case FSF_ADAPTER_STATUS_AVAILABLE:
1119 switch (header->fsf_status_qual.word[0]){
1120 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001121 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1122 case FSF_SQ_RETRY_IF_POSSIBLE:
1123 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1124 break;
1125 }
1126 break;
1127 case FSF_ELS_COMMAND_REJECTED:
1128 case FSF_PAYLOAD_SIZE_MISMATCH:
1129 case FSF_REQUEST_SIZE_TOO_LARGE:
1130 case FSF_RESPONSE_SIZE_TOO_LARGE:
1131 break;
1132 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001133 if (port) {
1134 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1135 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1136 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001137 break;
1138 case FSF_SBAL_MISMATCH:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001139 /* should never occur, avoided in zfcp_fsf_send_els */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001140 /* fall through */
1141 default:
1142 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1143 break;
1144 }
1145skip_fsfstatus:
1146 if (send_els->handler)
1147 send_els->handler(send_els->handler_data);
1148}
1149
1150/**
1151 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1152 * @els: pointer to struct zfcp_send_els with data for the command
1153 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001154int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001155 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001156{
1157 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001158 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001159 int ret = -EIO;
1160
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001161 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001162 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001163 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001164
Christof Schmitt1674b402010-04-30 18:09:34 +02001165 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
Jan Glauber3ec90872011-06-06 14:14:40 +02001166 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001167
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001168 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001169 ret = PTR_ERR(req);
1170 goto out;
1171 }
1172
Swen Schillig09a46c62009-08-18 15:43:16 +02001173 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001174
Swen Schillig86a96682011-08-15 14:40:32 +02001175 if (!zfcp_adapter_multi_buffer_active(adapter))
1176 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
Swen Schillig01b04752010-07-16 15:37:37 +02001177
1178 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001179
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001180 if (ret)
1181 goto failed_send;
1182
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001183 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001184 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001185 req->data = els;
1186
Swen Schillig2c55b752010-12-02 15:16:13 +01001187 zfcp_dbf_san_req("fssels1", req, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001188
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001189 ret = zfcp_fsf_req_send(req);
1190 if (ret)
1191 goto failed_send;
1192
1193 goto out;
1194
1195failed_send:
1196 zfcp_fsf_req_free(req);
1197out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001198 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001199 return ret;
1200}
1201
1202int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1203{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001204 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001205 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206 int retval = -EIO;
1207
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001208 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001209 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001210 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001211
Swen Schillig564e1c82009-08-18 15:43:19 +02001212 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001213 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001214 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001215
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001216 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001217 retval = PTR_ERR(req);
1218 goto out;
1219 }
1220
Swen Schillig09a46c62009-08-18 15:43:16 +02001221 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001222 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001223
1224 req->qtcb->bottom.config.feature_selection =
1225 FSF_FEATURE_CFDC |
1226 FSF_FEATURE_LUN_SHARING |
1227 FSF_FEATURE_NOTIFICATION_LOST |
1228 FSF_FEATURE_UPDATE_ALERT;
1229 req->erp_action = erp_action;
1230 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001231 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232
Christof Schmitt287ac012008-07-02 10:56:40 +02001233 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001234 retval = zfcp_fsf_req_send(req);
1235 if (retval) {
1236 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001237 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 }
1239out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001240 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001241 return retval;
1242}
1243
Swen Schillig564e1c82009-08-18 15:43:19 +02001244int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001245 struct fsf_qtcb_bottom_config *data)
1246{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001247 struct zfcp_fsf_req *req = NULL;
1248 int retval = -EIO;
1249
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001250 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001251 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001252 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001253
Christof Schmitt1674b402010-04-30 18:09:34 +02001254 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001255 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001256
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001257 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001258 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001259 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001260 }
1261
Christof Schmitt1674b402010-04-30 18:09:34 +02001262 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001263 req->handler = zfcp_fsf_exchange_config_data_handler;
1264
1265 req->qtcb->bottom.config.feature_selection =
1266 FSF_FEATURE_CFDC |
1267 FSF_FEATURE_LUN_SHARING |
1268 FSF_FEATURE_NOTIFICATION_LOST |
1269 FSF_FEATURE_UPDATE_ALERT;
1270
1271 if (data)
1272 req->data = data;
1273
1274 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1275 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001276 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001277 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001278 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001279
1280 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001281 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001282
Christof Schmittada81b72009-04-17 15:08:03 +02001283out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001284 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001285 return retval;
1286}
1287
1288/**
1289 * zfcp_fsf_exchange_port_data - request information about local port
1290 * @erp_action: ERP action for the adapter for which port data is requested
1291 * Returns: 0 on success, error otherwise
1292 */
1293int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1294{
Swen Schillig564e1c82009-08-18 15:43:19 +02001295 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001296 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001297 int retval = -EIO;
1298
Swen Schillig564e1c82009-08-18 15:43:19 +02001299 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001300 return -EOPNOTSUPP;
1301
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001302 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001303 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001304 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001305
Swen Schillig564e1c82009-08-18 15:43:19 +02001306 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001307 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001308 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001309
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001310 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001311 retval = PTR_ERR(req);
1312 goto out;
1313 }
1314
Swen Schillig09a46c62009-08-18 15:43:16 +02001315 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001316 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001317
1318 req->handler = zfcp_fsf_exchange_port_data_handler;
1319 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001320 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001321
Christof Schmitt287ac012008-07-02 10:56:40 +02001322 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323 retval = zfcp_fsf_req_send(req);
1324 if (retval) {
1325 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001326 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001327 }
1328out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001329 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001330 return retval;
1331}
1332
1333/**
1334 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001335 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001336 * @data: pointer to struct fsf_qtcb_bottom_port
1337 * Returns: 0 on success, error otherwise
1338 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001339int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001340 struct fsf_qtcb_bottom_port *data)
1341{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001342 struct zfcp_fsf_req *req = NULL;
1343 int retval = -EIO;
1344
Swen Schillig564e1c82009-08-18 15:43:19 +02001345 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001346 return -EOPNOTSUPP;
1347
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001348 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001349 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001350 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001351
Christof Schmitt1674b402010-04-30 18:09:34 +02001352 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001353 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001354
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001355 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001356 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001357 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001358 }
1359
1360 if (data)
1361 req->data = data;
1362
Christof Schmitt1674b402010-04-30 18:09:34 +02001363 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001364
1365 req->handler = zfcp_fsf_exchange_port_data_handler;
1366 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1367 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001368 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001369
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001370 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001371 wait_for_completion(&req->completion);
1372
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001373 zfcp_fsf_req_free(req);
1374
1375 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001376
1377out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001378 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001379 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001380}
1381
1382static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1383{
1384 struct zfcp_port *port = req->data;
1385 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001386 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001387
1388 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001389 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001390
1391 switch (header->fsf_status) {
1392 case FSF_PORT_ALREADY_OPEN:
1393 break;
1394 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001395 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1396 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001397 break;
1398 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1399 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001400 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001401 "remote port 0x%016Lx\n",
1402 (unsigned long long)port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001403 zfcp_erp_set_port_status(port,
1404 ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001405 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1406 break;
1407 case FSF_ADAPTER_STATUS_AVAILABLE:
1408 switch (header->fsf_status_qual.word[0]) {
1409 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1410 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001411 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001412 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1413 break;
1414 }
1415 break;
1416 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1419 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001420 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1421 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1422 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 /* check whether D_ID has changed during open */
1424 /*
1425 * FIXME: This check is not airtight, as the FCP channel does
1426 * not monitor closures of target port connections caused on
1427 * the remote side. Thus, they might miss out on invalidating
1428 * locally cached WWPNs (and other N_Port parameters) of gone
1429 * target ports. So, our heroic attempt to make things safe
1430 * could be undermined by 'open port' response data tagged with
1431 * obsolete WWPNs. Another reason to monitor potential
1432 * connection closures ourself at least (by interpreting
1433 * incoming ELS' and unsolicited status). It just crosses my
1434 * mind that one should be able to cross-check by means of
1435 * another GID_PN straight after a port has been opened.
1436 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1437 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001438 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001439 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001440 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001441 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001444 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 break;
1446 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001447
1448out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001449 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450}
1451
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001452/**
1453 * zfcp_fsf_open_port - create and send open port request
1454 * @erp_action: pointer to struct zfcp_erp_action
1455 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001457int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
Swen Schillig564e1c82009-08-18 15:43:19 +02001459 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001460 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001461 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001462 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001464 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001465 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Swen Schillig564e1c82009-08-18 15:43:19 +02001468 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec90872011-06-06 14:14:40 +02001469 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001470 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001471
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001472 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001473 retval = PTR_ERR(req);
1474 goto out;
1475 }
1476
Swen Schillig09a46c62009-08-18 15:43:16 +02001477 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001478 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001480 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001481 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001482 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001483 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001484 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001485 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Christof Schmitt287ac012008-07-02 10:56:40 +02001487 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001488 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001490 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001491 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001492 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001495 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return retval;
1497}
1498
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001499static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001501 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001503 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001504 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001506 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001508 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001509 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 case FSF_GOOD:
Swen Schilligedaed852010-09-08 14:40:01 +02001514 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
1518
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001519/**
1520 * zfcp_fsf_close_port - create and send close port request
1521 * @erp_action: pointer to struct zfcp_erp_action
1522 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Swen Schillig564e1c82009-08-18 15:43:19 +02001526 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001527 struct zfcp_fsf_req *req;
1528 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001530 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001531 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Swen Schillig564e1c82009-08-18 15:43:19 +02001534 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001535 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001536 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001537
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001538 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001539 retval = PTR_ERR(req);
1540 goto out;
1541 }
1542
Swen Schillig09a46c62009-08-18 15:43:16 +02001543 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001544 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001546 req->handler = zfcp_fsf_close_port_handler;
1547 req->data = erp_action->port;
1548 req->erp_action = erp_action;
1549 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001550 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Christof Schmitt287ac012008-07-02 10:56:40 +02001552 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001553 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001555 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001556 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001558out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001559 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 return retval;
1561}
1562
Swen Schillig5ab944f2008-10-01 12:42:17 +02001563static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1564{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001565 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001566 struct fsf_qtcb_header *header = &req->qtcb->header;
1567
1568 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001569 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001570 goto out;
1571 }
1572
1573 switch (header->fsf_status) {
1574 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1575 dev_warn(&req->adapter->ccw_device->dev,
1576 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001577 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001578 case FSF_ADAPTER_STATUS_AVAILABLE:
1579 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001580 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001581 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001582 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001583 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001584 case FSF_GOOD:
1585 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001586 /* fall through */
1587 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001588 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001589 }
1590out:
1591 wake_up(&wka_port->completion_wq);
1592}
1593
1594/**
1595 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001596 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001597 * Returns: 0 on success, error otherwise
1598 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001599int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001600{
Swen Schillig564e1c82009-08-18 15:43:19 +02001601 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001602 struct zfcp_fsf_req *req;
1603 int retval = -EIO;
1604
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001605 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001606 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001607 goto out;
1608
Swen Schillig564e1c82009-08-18 15:43:19 +02001609 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec90872011-06-06 14:14:40 +02001610 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001611 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001612
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001613 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001614 retval = PTR_ERR(req);
1615 goto out;
1616 }
1617
Swen Schillig09a46c62009-08-18 15:43:16 +02001618 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001619 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001620
1621 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001622 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001623 req->data = wka_port;
1624
1625 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1626 retval = zfcp_fsf_req_send(req);
1627 if (retval)
1628 zfcp_fsf_req_free(req);
1629out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001630 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001631 return retval;
1632}
1633
1634static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1635{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001636 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001637
1638 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1639 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligea4a3a62010-12-02 15:16:16 +01001640 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
Swen Schillig5ab944f2008-10-01 12:42:17 +02001641 }
1642
Christof Schmittbd0072e2009-11-24 16:54:11 +01001643 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001644 wake_up(&wka_port->completion_wq);
1645}
1646
1647/**
1648 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001649 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001650 * Returns: 0 on success, error otherwise
1651 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001652int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001653{
Swen Schillig564e1c82009-08-18 15:43:19 +02001654 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001655 struct zfcp_fsf_req *req;
1656 int retval = -EIO;
1657
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001658 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001659 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001660 goto out;
1661
Swen Schillig564e1c82009-08-18 15:43:19 +02001662 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001663 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001664 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001665
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001666 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001667 retval = PTR_ERR(req);
1668 goto out;
1669 }
1670
Swen Schillig09a46c62009-08-18 15:43:16 +02001671 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001672 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001673
1674 req->handler = zfcp_fsf_close_wka_port_handler;
1675 req->data = wka_port;
1676 req->qtcb->header.port_handle = wka_port->handle;
1677
1678 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1679 retval = zfcp_fsf_req_send(req);
1680 if (retval)
1681 zfcp_fsf_req_free(req);
1682out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001683 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001684 return retval;
1685}
1686
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001687static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001689 struct zfcp_port *port = req->data;
1690 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001691 struct scsi_device *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001693 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001694 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001698 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001699 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001702 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001705 /* can't use generic zfcp_erp_modify_port_status because
1706 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1707 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001708 shost_for_each_device(sdev, port->adapter->scsi_host)
1709 if (sdev_to_zfcp(sdev)->port == port)
1710 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1711 &sdev_to_zfcp(sdev)->status);
Swen Schilligedaed852010-09-08 14:40:01 +02001712 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
1713 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001714 "fscpph2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001715 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 switch (header->fsf_status_qual.word[0]) {
1719 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001720 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001722 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 }
1725 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 /* can't use generic zfcp_erp_modify_port_status because
1728 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1729 */
1730 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001731 shost_for_each_device(sdev, port->adapter->scsi_host)
1732 if (sdev_to_zfcp(sdev)->port == port)
1733 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1734 &sdev_to_zfcp(sdev)->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737}
1738
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001739/**
1740 * zfcp_fsf_close_physical_port - close physical port
1741 * @erp_action: pointer to struct zfcp_erp_action
1742 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001744int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745{
Swen Schillig564e1c82009-08-18 15:43:19 +02001746 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001747 struct zfcp_fsf_req *req;
1748 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001750 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001751 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Swen Schillig564e1c82009-08-18 15:43:19 +02001754 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001755 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001756 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001757
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001758 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001759 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 goto out;
1761 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001762
Swen Schillig09a46c62009-08-18 15:43:16 +02001763 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001764 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001765
1766 req->data = erp_action->port;
1767 req->qtcb->header.port_handle = erp_action->port->handle;
1768 req->erp_action = erp_action;
1769 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001770 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001771
Christof Schmitt287ac012008-07-02 10:56:40 +02001772 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001773 retval = zfcp_fsf_req_send(req);
1774 if (retval) {
1775 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001776 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001777 }
1778out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001779 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 return retval;
1781}
1782
Christof Schmittb62a8d92010-09-08 14:39:55 +02001783static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001785 struct zfcp_adapter *adapter = req->adapter;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001786 struct scsi_device *sdev = req->data;
Martin Peschke82e05512012-09-04 15:23:36 +02001787 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001788 struct fsf_qtcb_header *header = &req->qtcb->header;
1789 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001791 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001792 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Martin Peschke82e05512012-09-04 15:23:36 +02001794 zfcp_sdev = sdev_to_zfcp(sdev);
1795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001797 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Christof Schmittb62a8d92010-09-08 14:39:55 +02001798 ZFCP_STATUS_LUN_SHARED |
1799 ZFCP_STATUS_LUN_READONLY,
1800 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 switch (header->fsf_status) {
1803
1804 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001805 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001806 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001810 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
1811 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_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001814 zfcp_erp_set_port_status(zfcp_sdev->port,
1815 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1816 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001817 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001818 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 case FSF_LUN_SHARING_VIOLATION:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001821 zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001822 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_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001825 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001826 "No handle is available for LUN "
1827 "0x%016Lx on port 0x%016Lx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001828 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1829 (unsigned long long)zfcp_sdev->port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001830 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001831 /* fall through */
1832 case FSF_INVALID_COMMAND_OPTION:
1833 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 switch (header->fsf_status_qual.word[0]) {
1837 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001838 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001839 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001841 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 }
1844 break;
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001847 zfcp_sdev->lun_handle = header->lun_handle;
1848 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Christof Schmitta1ca4832010-09-08 14:39:59 +02001849 zfcp_cfdc_open_lun_eval(sdev, bottom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852}
1853
1854/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001855 * zfcp_fsf_open_lun - open LUN
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001856 * @erp_action: pointer to struct zfcp_erp_action
1857 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001859int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001861 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001862 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001863 struct zfcp_fsf_req *req;
1864 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001866 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001867 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001868 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Swen Schillig564e1c82009-08-18 15:43:19 +02001870 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Jan Glauber3ec90872011-06-06 14:14:40 +02001871 SBAL_SFLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001872 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001873
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001874 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001875 retval = PTR_ERR(req);
1876 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001877 }
1878
Swen Schillig09a46c62009-08-18 15:43:16 +02001879 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001880 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001882 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001883 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1884 req->handler = zfcp_fsf_open_lun_handler;
1885 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001887 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001888
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001889 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1890 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
Christof Schmitt287ac012008-07-02 10:56:40 +02001892 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001893 retval = zfcp_fsf_req_send(req);
1894 if (retval) {
1895 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001896 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001898out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001899 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 return retval;
1901}
1902
Christof Schmittb62a8d92010-09-08 14:39:55 +02001903static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
Christof Schmittb62a8d92010-09-08 14:39:55 +02001905 struct scsi_device *sdev = req->data;
Martin Peschke82e05512012-09-04 15:23:36 +02001906 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001907
1908 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001909 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001910
Martin Peschke82e05512012-09-04 15:23:36 +02001911 zfcp_sdev = sdev_to_zfcp(sdev);
1912
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001913 switch (req->qtcb->header.fsf_status) {
1914 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001915 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001916 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1917 break;
1918 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001919 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001920 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1921 break;
1922 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001923 zfcp_erp_set_port_status(zfcp_sdev->port,
1924 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1925 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001926 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001927 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001928 break;
1929 case FSF_ADAPTER_STATUS_AVAILABLE:
1930 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1931 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001932 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001933 /* fall through */
1934 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1935 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1936 break;
1937 }
1938 break;
1939 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001940 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001941 break;
1942 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001943}
1944
1945/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001946 * zfcp_fsf_close_LUN - close LUN
1947 * @erp_action: pointer to erp_action triggering the "close LUN"
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001948 * Returns: 0 on success, error otherwise
1949 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001950int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001951{
Swen Schillig564e1c82009-08-18 15:43:19 +02001952 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001953 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001954 struct zfcp_fsf_req *req;
1955 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001957 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001958 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001960
Swen Schillig564e1c82009-08-18 15:43:19 +02001961 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Jan Glauber3ec90872011-06-06 14:14:40 +02001962 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001963 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001964
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001965 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001966 retval = PTR_ERR(req);
1967 goto out;
1968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
Swen Schillig09a46c62009-08-18 15:43:16 +02001970 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001971 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001973 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001974 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1975 req->handler = zfcp_fsf_close_lun_handler;
1976 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001977 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001978 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Christof Schmitt287ac012008-07-02 10:56:40 +02001980 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001981 retval = zfcp_fsf_req_send(req);
1982 if (retval) {
1983 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001984 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001985 }
1986out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001987 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001988 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989}
1990
Christof Schmittc9615852008-05-06 11:00:05 +02001991static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1992{
1993 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001994 lat_rec->min = min(lat_rec->min, lat);
1995 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02001996}
1997
Christof Schmittd9742b42009-11-24 16:54:03 +01001998static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02001999{
Christof Schmittd9742b42009-11-24 16:54:03 +01002000 struct fsf_qual_latency_info *lat_in;
2001 struct latency_cont *lat = NULL;
Martin Peschke82e05512012-09-04 15:23:36 +02002002 struct zfcp_scsi_dev *zfcp_sdev;
Christof Schmittd9742b42009-11-24 16:54:03 +01002003 struct zfcp_blk_drv_data blktrc;
2004 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002005
Christof Schmittd9742b42009-11-24 16:54:03 +01002006 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002007
Christof Schmittd9742b42009-11-24 16:54:03 +01002008 blktrc.flags = 0;
2009 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2010 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2011 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02002012 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002013 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002014
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002015 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2016 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Peschke82e05512012-09-04 15:23:36 +02002017 zfcp_sdev = sdev_to_zfcp(scsi->device);
Christof Schmittd9742b42009-11-24 16:54:03 +01002018 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2019 blktrc.channel_lat = lat_in->channel_lat * ticks;
2020 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2021
2022 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002023 case FSF_DATADIR_DIF_READ_STRIP:
2024 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002025 case FSF_DATADIR_READ:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002026 lat = &zfcp_sdev->latencies.read;
Christof Schmittd9742b42009-11-24 16:54:03 +01002027 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002028 case FSF_DATADIR_DIF_WRITE_INSERT:
2029 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002030 case FSF_DATADIR_WRITE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002031 lat = &zfcp_sdev->latencies.write;
Christof Schmittd9742b42009-11-24 16:54:03 +01002032 break;
2033 case FSF_DATADIR_CMND:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002034 lat = &zfcp_sdev->latencies.cmd;
Christof Schmittd9742b42009-11-24 16:54:03 +01002035 break;
2036 }
2037
2038 if (lat) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02002039 spin_lock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002040 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2041 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2042 lat->counter++;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002043 spin_unlock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002044 }
Christof Schmittc9615852008-05-06 11:00:05 +02002045 }
2046
Christof Schmittd9742b42009-11-24 16:54:03 +01002047 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2048 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002049}
2050
Christof Schmittc61b5362010-09-08 14:39:58 +02002051static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002052{
Christof Schmittb62a8d92010-09-08 14:39:55 +02002053 struct scsi_cmnd *scmnd = req->data;
2054 struct scsi_device *sdev = scmnd->device;
Martin Peschke82e05512012-09-04 15:23:36 +02002055 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002056 struct fsf_qtcb_header *header = &req->qtcb->header;
2057
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002058 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
Christof Schmittc61b5362010-09-08 14:39:58 +02002059 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002060
Martin Peschke82e05512012-09-04 15:23:36 +02002061 zfcp_sdev = sdev_to_zfcp(sdev);
2062
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002063 switch (header->fsf_status) {
2064 case FSF_HANDLE_MISMATCH:
2065 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002066 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002067 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2068 break;
2069 case FSF_FCPLUN_NOT_VALID:
2070 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002071 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002072 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2073 break;
2074 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2075 zfcp_fsf_class_not_supp(req);
2076 break;
2077 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02002078 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
2079 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002080 break;
2081 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2082 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002083 "Incorrect direction %d, LUN 0x%016Lx on port "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002084 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002085 req->qtcb->bottom.io.data_direction,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002086 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2087 (unsigned long long)zfcp_sdev->port->wwpn);
2088 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002089 "fssfch3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002090 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2091 break;
2092 case FSF_CMND_LENGTH_NOT_VALID:
2093 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002094 "Incorrect CDB length %d, LUN 0x%016Lx on "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002095 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002096 req->qtcb->bottom.io.fcp_cmnd_length,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002097 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2098 (unsigned long long)zfcp_sdev->port->wwpn);
2099 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002100 "fssfch4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002101 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2102 break;
2103 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002104 zfcp_erp_set_port_status(zfcp_sdev->port,
2105 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2106 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002107 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002108 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002109 break;
2110 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002111 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2112 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002113 "fssfch6");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002114 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002115 break;
2116 case FSF_ADAPTER_STATUS_AVAILABLE:
2117 if (header->fsf_status_qual.word[0] ==
2118 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Christof Schmittb62a8d92010-09-08 14:39:55 +02002119 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002120 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2121 break;
2122 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002123}
2124
2125static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2126{
2127 struct scsi_cmnd *scpnt;
2128 struct fcp_resp_with_ext *fcp_rsp;
2129 unsigned long flags;
2130
Christof Schmittc61b5362010-09-08 14:39:58 +02002131 read_lock_irqsave(&req->adapter->abort_lock, flags);
2132
2133 scpnt = req->data;
2134 if (unlikely(!scpnt)) {
2135 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2136 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002137 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002138
Swen Schillig5bfb2c32010-11-17 14:23:40 +01002139 zfcp_fsf_fcp_handler_common(req);
2140
Christof Schmittc61b5362010-09-08 14:39:58 +02002141 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2142 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2143 goto skip_fsfstatus;
2144 }
2145
2146 switch (req->qtcb->header.fsf_status) {
2147 case FSF_INCONSISTENT_PROT_DATA:
2148 case FSF_INVALID_PROT_PARM:
2149 set_host_byte(scpnt, DID_ERROR);
2150 goto skip_fsfstatus;
2151 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2152 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2153 goto skip_fsfstatus;
2154 case FSF_APP_TAG_CHECK_FAILURE:
2155 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2156 goto skip_fsfstatus;
2157 case FSF_REF_TAG_CHECK_FAILURE:
2158 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2159 goto skip_fsfstatus;
2160 }
2161 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2162 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2163
2164skip_fsfstatus:
2165 zfcp_fsf_req_trace(req, scpnt);
Swen Schillig250a1352010-12-02 15:16:15 +01002166 zfcp_dbf_scsi_result(scpnt, req);
Christof Schmittc61b5362010-09-08 14:39:58 +02002167
2168 scpnt->host_scribble = NULL;
2169 (scpnt->scsi_done) (scpnt);
2170 /*
2171 * We must hold this lock until scsi_done has been called.
2172 * Otherwise we may call scsi_done after abort regarding this
2173 * command has completed.
2174 * Note: scsi_done must not block!
2175 */
2176 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002177}
2178
Felix Beckef3eb712010-07-16 15:37:42 +02002179static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2180{
2181 switch (scsi_get_prot_op(scsi_cmnd)) {
2182 case SCSI_PROT_NORMAL:
2183 switch (scsi_cmnd->sc_data_direction) {
2184 case DMA_NONE:
2185 *data_dir = FSF_DATADIR_CMND;
2186 break;
2187 case DMA_FROM_DEVICE:
2188 *data_dir = FSF_DATADIR_READ;
2189 break;
2190 case DMA_TO_DEVICE:
2191 *data_dir = FSF_DATADIR_WRITE;
2192 break;
2193 case DMA_BIDIRECTIONAL:
2194 return -EINVAL;
2195 }
2196 break;
2197
2198 case SCSI_PROT_READ_STRIP:
2199 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2200 break;
2201 case SCSI_PROT_WRITE_INSERT:
2202 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2203 break;
2204 case SCSI_PROT_READ_PASS:
2205 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2206 break;
2207 case SCSI_PROT_WRITE_PASS:
2208 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2209 break;
2210 default:
2211 return -EINVAL;
2212 }
2213
2214 return 0;
2215}
2216
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002217/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002218 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002219 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002220 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002221int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002222{
2223 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002224 struct fcp_cmnd *fcp_cmnd;
Jan Glauber3ec90872011-06-06 14:14:40 +02002225 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
Swen Schillig86a96682011-08-15 14:40:32 +02002226 int retval = -EIO;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002227 struct scsi_device *sdev = scsi_cmnd->device;
2228 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2229 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002230 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002231 struct fsf_qtcb_bottom_io *io;
Christof Schmitte55f8752010-11-18 14:53:18 +01002232 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002233
Christof Schmittb62a8d92010-09-08 14:39:55 +02002234 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002235 ZFCP_STATUS_COMMON_UNBLOCKED)))
2236 return -EBUSY;
2237
Christof Schmitte55f8752010-11-18 14:53:18 +01002238 spin_lock_irqsave(&qdio->req_q_lock, flags);
Swen Schillig706eca42010-07-16 15:37:38 +02002239 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002240 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002241 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002242 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002243
Christof Schmitt1674b402010-04-30 18:09:34 +02002244 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
Jan Glauber3ec90872011-06-06 14:14:40 +02002245 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
Christof Schmitt1674b402010-04-30 18:09:34 +02002246
Swen Schillig564e1c82009-08-18 15:43:19 +02002247 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002248 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002249
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002250 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002251 retval = PTR_ERR(req);
2252 goto out;
2253 }
2254
Felix Beckef3eb712010-07-16 15:37:42 +02002255 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2256
2257 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002258 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002259 req->data = scsi_cmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002260 req->handler = zfcp_fsf_fcp_cmnd_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002261 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2262 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002263 io->service_class = FSF_CLASS_3;
2264 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002265
Felix Beckef3eb712010-07-16 15:37:42 +02002266 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2267 io->data_block_length = scsi_cmnd->device->sector_size;
2268 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002269 }
2270
Steffen Maiercc405ac2011-08-15 14:40:30 +02002271 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2272 goto failed_scsi_cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +02002273
Christof Schmitt4318e082009-11-24 16:54:08 +01002274 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002275 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002276
Felix Beckef3eb712010-07-16 15:37:42 +02002277 if (scsi_prot_sg_count(scsi_cmnd)) {
2278 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2279 scsi_prot_sg_count(scsi_cmnd));
Swen Schillig86a96682011-08-15 14:40:32 +02002280 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2281 scsi_prot_sglist(scsi_cmnd));
2282 if (retval)
2283 goto failed_scsi_cmnd;
2284 io->prot_data_length = zfcp_qdio_real_bytes(
Felix Beckef3eb712010-07-16 15:37:42 +02002285 scsi_prot_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002286 }
2287
Swen Schillig86a96682011-08-15 14:40:32 +02002288 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2289 scsi_sglist(scsi_cmnd));
2290 if (unlikely(retval))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002291 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002292
Felix Beckef3eb712010-07-16 15:37:42 +02002293 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schillig86a96682011-08-15 14:40:32 +02002294 if (zfcp_adapter_multi_buffer_active(adapter))
2295 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Felix Beckef3eb712010-07-16 15:37:42 +02002296
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002297 retval = zfcp_fsf_req_send(req);
2298 if (unlikely(retval))
2299 goto failed_scsi_cmnd;
2300
2301 goto out;
2302
2303failed_scsi_cmnd:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002304 zfcp_fsf_req_free(req);
2305 scsi_cmnd->host_scribble = NULL;
2306out:
Christof Schmitte55f8752010-11-18 14:53:18 +01002307 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002308 return retval;
2309}
2310
Christof Schmittc61b5362010-09-08 14:39:58 +02002311static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2312{
2313 struct fcp_resp_with_ext *fcp_rsp;
2314 struct fcp_resp_rsp_info *rsp_info;
2315
2316 zfcp_fsf_fcp_handler_common(req);
2317
2318 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2319 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2320
2321 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2322 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2323 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2324}
2325
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002326/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002327 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2328 * @scmnd: SCSI command to send the task management command for
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002329 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002330 * Returns: on success pointer to struct fsf_req, NULL otherwise
2331 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002332struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2333 u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002334{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002335 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002336 struct fcp_cmnd *fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002337 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2338 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002339
Christof Schmittb62a8d92010-09-08 14:39:55 +02002340 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002341 ZFCP_STATUS_COMMON_UNBLOCKED)))
2342 return NULL;
2343
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002344 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002345 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002346 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002347
Swen Schillig564e1c82009-08-18 15:43:19 +02002348 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Jan Glauber3ec90872011-06-06 14:14:40 +02002349 SBAL_SFLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002350 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002351
Swen Schillig633528c2008-11-26 18:07:37 +01002352 if (IS_ERR(req)) {
2353 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002354 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002355 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002356
Christof Schmittb62a8d92010-09-08 14:39:55 +02002357 req->data = scmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002358 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002359 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2360 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002361 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2362 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002363 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002364
Christof Schmitt1674b402010-04-30 18:09:34 +02002365 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002366
Christof Schmitt4318e082009-11-24 16:54:08 +01002367 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002368 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002369
2370 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2371 if (!zfcp_fsf_req_send(req))
2372 goto out;
2373
2374 zfcp_fsf_req_free(req);
2375 req = NULL;
2376out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002377 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002378 return req;
2379}
2380
2381static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2382{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002383}
2384
2385/**
2386 * zfcp_fsf_control_file - control file upload/download
2387 * @adapter: pointer to struct zfcp_adapter
2388 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2389 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002391struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2392 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393{
Swen Schillig564e1c82009-08-18 15:43:19 +02002394 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002395 struct zfcp_fsf_req *req = NULL;
2396 struct fsf_qtcb_bottom_support *bottom;
Swen Schillig86a96682011-08-15 14:40:32 +02002397 int retval = -EIO;
Jan Glauber3ec90872011-06-06 14:14:40 +02002398 u8 direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Christof Schmitt45633fd2008-06-10 18:20:55 +02002400 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2401 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Christof Schmitt45633fd2008-06-10 18:20:55 +02002403 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Jan Glauber3ec90872011-06-06 14:14:40 +02002405 direction = SBAL_SFLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Jan Glauber3ec90872011-06-06 14:14:40 +02002408 direction = SBAL_SFLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002411 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 }
2413
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002414 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002415 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002416 goto out;
2417
Christof Schmitt1674b402010-04-30 18:09:34 +02002418 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002419 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002421 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 }
2423
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002424 req->handler = zfcp_fsf_control_file_handler;
2425
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002426 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002428 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Swen Schillig86a96682011-08-15 14:40:32 +02002430 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
Swen Schillig01b04752010-07-16 15:37:37 +02002431
Swen Schillig86a96682011-08-15 14:40:32 +02002432 if (retval ||
2433 (zfcp_qdio_real_bytes(fsf_cfdc->sg) != ZFCP_CFDC_MAX_SIZE)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002434 zfcp_fsf_req_free(req);
Swen Schillig86a96682011-08-15 14:40:32 +02002435 retval = -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002436 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002437 }
Swen Schillig86a96682011-08-15 14:40:32 +02002438 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2439 if (zfcp_adapter_multi_buffer_active(adapter))
2440 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002442 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2443 retval = zfcp_fsf_req_send(req);
2444out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002445 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002446
2447 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002448 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002449 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002451 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002453
2454/**
2455 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2456 * @adapter: pointer to struct zfcp_adapter
2457 * @sbal_idx: response queue index of SBAL to be processed
2458 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002459void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002460{
Swen Schillig564e1c82009-08-18 15:43:19 +02002461 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002462 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002463 struct qdio_buffer_element *sbale;
2464 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002465 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002466 int idx;
2467
2468 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2469
2470 sbale = &sbal->element[idx];
2471 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002472 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002473
Christof Schmitt339f4f42010-07-16 15:37:43 +02002474 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002475 /*
2476 * Unknown request means that we have potentially memory
2477 * corruption and must stop the machine immediately.
2478 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002479 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002480 panic("error: unknown req_id (%lx) on adapter %s.\n",
2481 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002482 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002483
Christof Schmitt34c2b712010-02-17 11:18:59 +01002484 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002485 zfcp_fsf_req_complete(fsf_req);
2486
Jan Glauber3ec90872011-06-06 14:14:40 +02002487 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002488 break;
2489 }
2490}
Swen Schilliga54ca0f2010-12-02 15:16:14 +01002491
2492struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
2493 struct qdio_buffer *sbal)
2494{
2495 struct qdio_buffer_element *sbale = &sbal->element[0];
2496 u64 req_id = (unsigned long) sbale->addr;
2497
2498 return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
2499}