blob: 6e2892e7c4be966097e64f0b73065d03d51cf9ab [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 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02006 * Copyright IBM Corp. 2002, 2010
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 Maier01009982012-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 Maierd2201972012-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;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100486 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Steffen Maierd2201972012-09-04 15:23:29 +0200487 fc_host_speed(shost) =
488 zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200489 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
490
491 adapter->hydra_version = bottom->adapter_type;
Christof Schmittfaf4cd82010-07-16 15:37:36 +0200492 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200493 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
494 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200495
496 if (fc_host_permanent_port_name(shost) == -1)
497 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
498
499 switch (bottom->fc_topology) {
500 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100501 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100502 adapter->peer_wwpn = plogi->fl_wwpn;
503 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200504 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200505 break;
506 case FSF_TOPO_FABRIC:
507 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200508 break;
509 case FSF_TOPO_AL:
510 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200511 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200512 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200513 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200514 "Unknown or unsupported arbitrated loop "
515 "fibre channel topology detected\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100516 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 return -EIO;
518 }
519
Felix Beckef3eb712010-07-16 15:37:42 +0200520 zfcp_scsi_set_prot(adapter);
521
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200522 return 0;
523}
524
525static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
526{
527 struct zfcp_adapter *adapter = req->adapter;
528 struct fsf_qtcb *qtcb = req->qtcb;
529 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
530 struct Scsi_Host *shost = adapter->scsi_host;
531
532 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
533 return;
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200536 adapter->adapter_features = bottom->adapter_features;
537 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500538 adapter->peer_wwpn = 0;
539 adapter->peer_wwnn = 0;
540 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200542 switch (qtcb->header.fsf_status) {
543 case FSF_GOOD:
544 if (zfcp_fsf_exchange_config_evaluate(req))
545 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200546
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200547 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
548 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200549 "FCP adapter maximum QTCB size (%d bytes) "
550 "is too small\n",
551 bottom->max_qtcb_size);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100552 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200553 return;
554 }
555 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
556 &adapter->status);
557 break;
558 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200559 fc_host_node_name(shost) = 0;
560 fc_host_port_name(shost) = 0;
561 fc_host_port_id(shost) = 0;
562 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100563 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200565
Swen Schilligedaed852010-09-08 14:40:01 +0200566 zfcp_fsf_link_down_info_eval(req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200567 &qtcb->header.fsf_status_qual.link_down_info);
568 break;
569 default:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100570 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200571 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 }
573
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200574 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200576 memcpy(fc_host_serial_number(shost), bottom->serial_number,
577 min(FC_SERIAL_NUMBER_SIZE, 17));
578 EBCASC(fc_host_serial_number(shost),
579 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200582 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200583 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200584 "The FCP adapter only supports newer "
585 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100586 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200587 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200589 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200590 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200591 "The FCP adapter only supports older "
592 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100593 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200597static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200599 struct zfcp_adapter *adapter = req->adapter;
600 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
601 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200603 if (req->data)
604 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100605
Christof Schmitt02829852009-03-02 13:09:06 +0100606 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100607 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100608 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
609 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100610 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
611 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
Steffen Maierd2201972012-09-04 15:23:29 +0200612 fc_host_supported_speeds(shost) =
613 zfcp_fsf_convert_portspeed(bottom->supported_speed);
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100614 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
615 FC_FC4_LIST_SIZE);
616 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
617 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100618}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200620static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200622 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100623
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200624 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return;
626
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200627 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200628 case FSF_GOOD:
629 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200630 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200631 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200632 zfcp_fsf_exchange_port_evaluate(req);
Swen Schilligedaed852010-09-08 14:40:01 +0200633 zfcp_fsf_link_down_info_eval(req,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200635 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637}
638
Swen Schilliga4623c42009-08-18 15:43:15 +0200639static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200640{
641 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200642
643 if (likely(pool))
644 req = mempool_alloc(pool, GFP_ATOMIC);
645 else
646 req = kmalloc(sizeof(*req), GFP_ATOMIC);
647
648 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200649 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200650
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200651 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100652 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200653 return req;
654}
655
Swen Schilliga4623c42009-08-18 15:43:15 +0200656static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200657{
Swen Schilliga4623c42009-08-18 15:43:15 +0200658 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200659
660 if (likely(pool))
661 qtcb = mempool_alloc(pool, GFP_ATOMIC);
662 else
Christof Schmitt259afe22011-02-22 19:54:44 +0100663 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
Swen Schilliga4623c42009-08-18 15:43:15 +0200664
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200665 if (unlikely(!qtcb))
666 return NULL;
667
668 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200669 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200670}
671
Swen Schillig564e1c82009-08-18 15:43:19 +0200672static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Jan Glauber3ec908782011-06-06 14:14:40 +0200673 u32 fsf_cmd, u8 sbtype,
Christof Schmitt1674b402010-04-30 18:09:34 +0200674 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Swen Schillig564e1c82009-08-18 15:43:19 +0200676 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200677 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200678
679 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200680 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200681
682 if (adapter->req_no == 0)
683 adapter->req_no++;
684
685 INIT_LIST_HEAD(&req->list);
686 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200687 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200688
689 req->adapter = adapter;
690 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100691 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200692
Swen Schilliga4623c42009-08-18 15:43:15 +0200693 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
694 if (likely(pool))
695 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
696 else
697 req->qtcb = zfcp_qtcb_alloc(NULL);
698
699 if (unlikely(!req->qtcb)) {
700 zfcp_fsf_req_free(req);
701 return ERR_PTR(-ENOMEM);
702 }
703
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100704 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200705 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200706 req->qtcb->prefix.req_id = req->req_id;
707 req->qtcb->prefix.ulp_info = 26;
708 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
709 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
710 req->qtcb->header.req_handle = req->req_id;
711 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200712 }
713
Christof Schmitt1674b402010-04-30 18:09:34 +0200714 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
715 req->qtcb, sizeof(struct fsf_qtcb));
716
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200717 return req;
718}
719
720static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
721{
722 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200723 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100724 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100725 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200726
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100727 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200728
Swen Schillig706eca42010-07-16 15:37:38 +0200729 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200730 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100731 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200732 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100733 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100734 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100735 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200736 return -EIO;
737 }
738
739 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200740 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200741 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100742 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200743
744 return 0;
745}
746
747/**
748 * zfcp_fsf_status_read - send status read request
749 * @adapter: pointer to struct zfcp_adapter
750 * @req_flags: request flags
751 * Returns: 0 on success, ERROR otherwise
752 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200753int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200754{
Swen Schillig564e1c82009-08-18 15:43:19 +0200755 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200756 struct zfcp_fsf_req *req;
757 struct fsf_status_read_buffer *sr_buf;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100758 struct page *page;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200759 int retval = -EIO;
760
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200761 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200762 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Christof Schmitt1674b402010-04-30 18:09:34 +0200765 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200766 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200767 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200768 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 goto out;
770 }
771
Christof Schmittc7b279a2011-02-22 19:54:40 +0100772 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
773 if (!page) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200774 retval = -ENOMEM;
775 goto failed_buf;
776 }
Christof Schmittc7b279a2011-02-22 19:54:40 +0100777 sr_buf = page_address(page);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200778 memset(sr_buf, 0, sizeof(*sr_buf));
779 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200780
781 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
782 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200783
784 retval = zfcp_fsf_req_send(req);
785 if (retval)
786 goto failed_req_send;
787
788 goto out;
789
790failed_req_send:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100791 req->data = NULL;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100792 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200793failed_buf:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100794 zfcp_dbf_hba_fsf_uss("fssr__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200795 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200796out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200797 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return retval;
799}
800
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200801static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200803 struct scsi_device *sdev = req->data;
804 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200805 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200807 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
808 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200810 switch (req->qtcb->header.fsf_status) {
811 case FSF_PORT_HANDLE_NOT_VALID:
812 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200813 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100814 "fsafch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200815 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200818 case FSF_LUN_HANDLE_NOT_VALID:
819 if (fsq->word[0] == fsq->word[1]) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100820 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200821 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200824 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
825 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200827 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200828 zfcp_erp_set_port_status(zfcp_sdev->port,
829 ZFCP_STATUS_COMMON_ACCESS_BOXED);
830 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100831 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100832 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200833 break;
834 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200835 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
836 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100837 "fsafch4");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100838 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200839 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200841 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200843 zfcp_fc_test_link(zfcp_sdev->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200844 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200846 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 break;
848 }
849 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200851 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
852 break;
853 }
854}
855
856/**
Christof Schmittb62a8d92010-09-08 14:39:55 +0200857 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
858 * @scmnd: The SCSI command to abort
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200859 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200860 */
861
Christof Schmittb62a8d92010-09-08 14:39:55 +0200862struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200863{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200864 struct zfcp_fsf_req *req = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200865 struct scsi_device *sdev = scmnd->device;
866 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
867 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
868 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200869
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200870 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200871 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200872 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200873 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Jan Glauber3ec908782011-06-06 14:14:40 +0200874 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200875 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100876 if (IS_ERR(req)) {
877 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100879 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200880
Christof Schmittb62a8d92010-09-08 14:39:55 +0200881 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882 ZFCP_STATUS_COMMON_UNBLOCKED)))
883 goto out_error_free;
884
Christof Schmitt1674b402010-04-30 18:09:34 +0200885 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200886
Swen Schillig6fbf25e2010-11-17 14:23:41 +0100887 req->data = sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200888 req->handler = zfcp_fsf_abort_fcp_command_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200889 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
890 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200891 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
892
893 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
894 if (!zfcp_fsf_req_send(req))
895 goto out;
896
897out_error_free:
898 zfcp_fsf_req_free(req);
899 req = NULL;
900out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200901 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200902 return req;
903}
904
905static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
906{
907 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100908 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200909 struct fsf_qtcb_header *header = &req->qtcb->header;
910
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100911 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200912
913 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
914 goto skip_fsfstatus;
915
916 switch (header->fsf_status) {
917 case FSF_GOOD:
Steffen Maier01009982012-09-04 15:23:30 +0200918 zfcp_dbf_san_res("fsscth2", req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100919 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200920 break;
921 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
922 zfcp_fsf_class_not_supp(req);
923 break;
924 case FSF_ADAPTER_STATUS_AVAILABLE:
925 switch (header->fsf_status_qual.word[0]){
926 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200927 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
928 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
929 break;
930 }
931 break;
932 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200933 break;
934 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100935 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200936 break;
937 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100938 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
Christof Schmittdceab652009-05-15 13:18:18 +0200939 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200940 case FSF_GENERIC_COMMAND_REJECTED:
941 case FSF_PAYLOAD_SIZE_MISMATCH:
942 case FSF_REQUEST_SIZE_TOO_LARGE:
943 case FSF_RESPONSE_SIZE_TOO_LARGE:
944 case FSF_SBAL_MISMATCH:
945 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
946 break;
947 }
948
949skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100950 if (ct->handler)
951 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200952}
953
Christof Schmitt1674b402010-04-30 18:09:34 +0200954static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
955 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200956 struct scatterlist *sg_req,
957 struct scatterlist *sg_resp)
958{
Christof Schmitt1674b402010-04-30 18:09:34 +0200959 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
960 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
961 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200962}
963
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100964static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
965 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200966 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200967{
Swen Schillig42428f72009-08-18 15:43:18 +0200968 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig86a96682011-08-15 14:40:32 +0200969 struct zfcp_qdio *qdio = adapter->qdio;
970 struct fsf_qtcb *qtcb = req->qtcb;
Swen Schillig42428f72009-08-18 15:43:18 +0200971 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200972
Swen Schillig86a96682011-08-15 14:40:32 +0200973 if (zfcp_adapter_multi_buffer_active(adapter)) {
974 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
975 return -EIO;
976 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
977 return -EIO;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100978
Swen Schillig86a96682011-08-15 14:40:32 +0200979 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
980 zfcp_qdio_sbale_count(sg_req));
981 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
982 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200983 return 0;
984 }
985
986 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200987 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Swen Schillig86a96682011-08-15 14:40:32 +0200988 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +0200989 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100990 return 0;
991 }
992
Swen Schillig86a96682011-08-15 14:40:32 +0200993 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
994 return -EOPNOTSUPP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200995
Swen Schillig86a96682011-08-15 14:40:32 +0200996 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
Christof Schmitt9072df42009-07-13 15:06:07 +0200997 return -EIO;
Swen Schillig86a96682011-08-15 14:40:32 +0200998
999 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1000
1001 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1002 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1003
1004 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1005 return -EIO;
1006
1007 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1008
1009 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001010
Christof Schmittb1a58982009-09-24 10:23:21 +02001011 return 0;
1012}
1013
1014static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1015 struct scatterlist *sg_req,
1016 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001017 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001018{
1019 int ret;
1020
Swen Schillig01b04752010-07-16 15:37:37 +02001021 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001022 if (ret)
1023 return ret;
1024
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001025 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001026 if (timeout > 255)
1027 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001028 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001029 req->qtcb->bottom.support.timeout = timeout;
1030 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001031
1032 return 0;
1033}
1034
1035/**
1036 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1037 * @ct: pointer to struct zfcp_send_ct with data for request
1038 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001039 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001040int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001041 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1042 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001043{
Swen Schillig564e1c82009-08-18 15:43:19 +02001044 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001045 struct zfcp_fsf_req *req;
1046 int ret = -EIO;
1047
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001048 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001049 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001050 goto out;
1051
Christof Schmitt1674b402010-04-30 18:09:34 +02001052 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
Jan Glauber3ec908782011-06-06 14:14:40 +02001053 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001054
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001055 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001056 ret = PTR_ERR(req);
1057 goto out;
1058 }
1059
Swen Schillig09a46c62009-08-18 15:43:16 +02001060 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001061 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001062 if (ret)
1063 goto failed_send;
1064
1065 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001066 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001067 req->data = ct;
1068
Swen Schillig2c55b752010-12-02 15:16:13 +01001069 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001070
1071 ret = zfcp_fsf_req_send(req);
1072 if (ret)
1073 goto failed_send;
1074
1075 goto out;
1076
1077failed_send:
1078 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001079out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001080 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001081 return ret;
1082}
1083
1084static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1085{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001086 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087 struct zfcp_port *port = send_els->port;
1088 struct fsf_qtcb_header *header = &req->qtcb->header;
1089
1090 send_els->status = -EINVAL;
1091
1092 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1093 goto skip_fsfstatus;
1094
1095 switch (header->fsf_status) {
1096 case FSF_GOOD:
Swen Schillig2c55b752010-12-02 15:16:13 +01001097 zfcp_dbf_san_res("fsselh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001098 send_els->status = 0;
1099 break;
1100 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1101 zfcp_fsf_class_not_supp(req);
1102 break;
1103 case FSF_ADAPTER_STATUS_AVAILABLE:
1104 switch (header->fsf_status_qual.word[0]){
1105 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001106 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1107 case FSF_SQ_RETRY_IF_POSSIBLE:
1108 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1109 break;
1110 }
1111 break;
1112 case FSF_ELS_COMMAND_REJECTED:
1113 case FSF_PAYLOAD_SIZE_MISMATCH:
1114 case FSF_REQUEST_SIZE_TOO_LARGE:
1115 case FSF_RESPONSE_SIZE_TOO_LARGE:
1116 break;
1117 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001118 if (port) {
1119 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1120 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1121 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001122 break;
1123 case FSF_SBAL_MISMATCH:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001124 /* should never occur, avoided in zfcp_fsf_send_els */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001125 /* fall through */
1126 default:
1127 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1128 break;
1129 }
1130skip_fsfstatus:
1131 if (send_els->handler)
1132 send_els->handler(send_els->handler_data);
1133}
1134
1135/**
1136 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1137 * @els: pointer to struct zfcp_send_els with data for the command
1138 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001139int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001140 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001141{
1142 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001143 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001144 int ret = -EIO;
1145
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001146 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001147 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001148 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001149
Christof Schmitt1674b402010-04-30 18:09:34 +02001150 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
Jan Glauber3ec908782011-06-06 14:14:40 +02001151 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001152
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001153 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001154 ret = PTR_ERR(req);
1155 goto out;
1156 }
1157
Swen Schillig09a46c62009-08-18 15:43:16 +02001158 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001159
Swen Schillig86a96682011-08-15 14:40:32 +02001160 if (!zfcp_adapter_multi_buffer_active(adapter))
1161 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
Swen Schillig01b04752010-07-16 15:37:37 +02001162
1163 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001164
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001165 if (ret)
1166 goto failed_send;
1167
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001168 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001169 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001170 req->data = els;
1171
Swen Schillig2c55b752010-12-02 15:16:13 +01001172 zfcp_dbf_san_req("fssels1", req, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001173
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001174 ret = zfcp_fsf_req_send(req);
1175 if (ret)
1176 goto failed_send;
1177
1178 goto out;
1179
1180failed_send:
1181 zfcp_fsf_req_free(req);
1182out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001183 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001184 return ret;
1185}
1186
1187int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1188{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001189 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001190 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001191 int retval = -EIO;
1192
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001193 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001194 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001195 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001196
Swen Schillig564e1c82009-08-18 15:43:19 +02001197 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001198 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001199 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001200
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001201 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001202 retval = PTR_ERR(req);
1203 goto out;
1204 }
1205
Swen Schillig09a46c62009-08-18 15:43:16 +02001206 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001207 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001208
1209 req->qtcb->bottom.config.feature_selection =
1210 FSF_FEATURE_CFDC |
1211 FSF_FEATURE_LUN_SHARING |
1212 FSF_FEATURE_NOTIFICATION_LOST |
1213 FSF_FEATURE_UPDATE_ALERT;
1214 req->erp_action = erp_action;
1215 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001216 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001217
Christof Schmitt287ac012008-07-02 10:56:40 +02001218 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001219 retval = zfcp_fsf_req_send(req);
1220 if (retval) {
1221 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001222 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001223 }
1224out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001225 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001226 return retval;
1227}
1228
Swen Schillig564e1c82009-08-18 15:43:19 +02001229int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001230 struct fsf_qtcb_bottom_config *data)
1231{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232 struct zfcp_fsf_req *req = NULL;
1233 int retval = -EIO;
1234
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001235 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001236 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001237 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238
Christof Schmitt1674b402010-04-30 18:09:34 +02001239 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001240 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001241
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001242 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001243 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001244 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001245 }
1246
Christof Schmitt1674b402010-04-30 18:09:34 +02001247 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001248 req->handler = zfcp_fsf_exchange_config_data_handler;
1249
1250 req->qtcb->bottom.config.feature_selection =
1251 FSF_FEATURE_CFDC |
1252 FSF_FEATURE_LUN_SHARING |
1253 FSF_FEATURE_NOTIFICATION_LOST |
1254 FSF_FEATURE_UPDATE_ALERT;
1255
1256 if (data)
1257 req->data = data;
1258
1259 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1260 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001261 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001262 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001263 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001264
1265 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001266 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001267
Christof Schmittada81b72009-04-17 15:08:03 +02001268out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001269 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001270 return retval;
1271}
1272
1273/**
1274 * zfcp_fsf_exchange_port_data - request information about local port
1275 * @erp_action: ERP action for the adapter for which port data is requested
1276 * Returns: 0 on success, error otherwise
1277 */
1278int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1279{
Swen Schillig564e1c82009-08-18 15:43:19 +02001280 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001281 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001282 int retval = -EIO;
1283
Swen Schillig564e1c82009-08-18 15:43:19 +02001284 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001285 return -EOPNOTSUPP;
1286
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001287 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001288 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001289 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001290
Swen Schillig564e1c82009-08-18 15:43:19 +02001291 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001292 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001293 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001294
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001295 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001296 retval = PTR_ERR(req);
1297 goto out;
1298 }
1299
Swen Schillig09a46c62009-08-18 15:43:16 +02001300 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001301 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001302
1303 req->handler = zfcp_fsf_exchange_port_data_handler;
1304 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001305 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001306
Christof Schmitt287ac012008-07-02 10:56:40 +02001307 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001308 retval = zfcp_fsf_req_send(req);
1309 if (retval) {
1310 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001311 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001312 }
1313out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001314 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001315 return retval;
1316}
1317
1318/**
1319 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001320 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001321 * @data: pointer to struct fsf_qtcb_bottom_port
1322 * Returns: 0 on success, error otherwise
1323 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001324int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001325 struct fsf_qtcb_bottom_port *data)
1326{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001327 struct zfcp_fsf_req *req = NULL;
1328 int retval = -EIO;
1329
Swen Schillig564e1c82009-08-18 15:43:19 +02001330 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001331 return -EOPNOTSUPP;
1332
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001333 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001334 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001335 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001336
Christof Schmitt1674b402010-04-30 18:09:34 +02001337 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001338 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001339
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001340 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001341 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001342 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001343 }
1344
1345 if (data)
1346 req->data = data;
1347
Christof Schmitt1674b402010-04-30 18:09:34 +02001348 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001349
1350 req->handler = zfcp_fsf_exchange_port_data_handler;
1351 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1352 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001353 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001354
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001355 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001356 wait_for_completion(&req->completion);
1357
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001358 zfcp_fsf_req_free(req);
1359
1360 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001361
1362out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001363 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001364 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001365}
1366
1367static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1368{
1369 struct zfcp_port *port = req->data;
1370 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001371 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001372
1373 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001374 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001375
1376 switch (header->fsf_status) {
1377 case FSF_PORT_ALREADY_OPEN:
1378 break;
1379 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001380 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1381 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001382 break;
1383 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1384 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001385 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001386 "remote port 0x%016Lx\n",
1387 (unsigned long long)port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001388 zfcp_erp_set_port_status(port,
1389 ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001390 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1391 break;
1392 case FSF_ADAPTER_STATUS_AVAILABLE:
1393 switch (header->fsf_status_qual.word[0]) {
1394 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1395 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001396 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001397 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1398 break;
1399 }
1400 break;
1401 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1404 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001405 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1406 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1407 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 /* check whether D_ID has changed during open */
1409 /*
1410 * FIXME: This check is not airtight, as the FCP channel does
1411 * not monitor closures of target port connections caused on
1412 * the remote side. Thus, they might miss out on invalidating
1413 * locally cached WWPNs (and other N_Port parameters) of gone
1414 * target ports. So, our heroic attempt to make things safe
1415 * could be undermined by 'open port' response data tagged with
1416 * obsolete WWPNs. Another reason to monitor potential
1417 * connection closures ourself at least (by interpreting
1418 * incoming ELS' and unsolicited status). It just crosses my
1419 * mind that one should be able to cross-check by means of
1420 * another GID_PN straight after a port has been opened.
1421 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1422 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001423 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001424 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001425 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001426 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001429 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 break;
1431 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001432
1433out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001434 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435}
1436
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001437/**
1438 * zfcp_fsf_open_port - create and send open port request
1439 * @erp_action: pointer to struct zfcp_erp_action
1440 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001442int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
Swen Schillig564e1c82009-08-18 15:43:19 +02001444 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001445 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001446 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001447 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001449 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001450 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Swen Schillig564e1c82009-08-18 15:43:19 +02001453 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec908782011-06-06 14:14:40 +02001454 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001455 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001456
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001457 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001458 retval = PTR_ERR(req);
1459 goto out;
1460 }
1461
Swen Schillig09a46c62009-08-18 15:43:16 +02001462 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001463 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001465 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001466 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001467 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001468 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001469 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001470 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Christof Schmitt287ac012008-07-02 10:56:40 +02001472 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001473 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001476 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001477 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001480 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 return retval;
1482}
1483
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001484static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001486 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001488 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001489 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001491 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001493 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 case FSF_GOOD:
Swen Schilligedaed852010-09-08 14:40:01 +02001499 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001504/**
1505 * zfcp_fsf_close_port - create and send close port request
1506 * @erp_action: pointer to struct zfcp_erp_action
1507 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001509int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Swen Schillig564e1c82009-08-18 15:43:19 +02001511 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001512 struct zfcp_fsf_req *req;
1513 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001515 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001516 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Swen Schillig564e1c82009-08-18 15:43:19 +02001519 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001520 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001521 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001522
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001523 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524 retval = PTR_ERR(req);
1525 goto out;
1526 }
1527
Swen Schillig09a46c62009-08-18 15:43:16 +02001528 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001529 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001531 req->handler = zfcp_fsf_close_port_handler;
1532 req->data = erp_action->port;
1533 req->erp_action = erp_action;
1534 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001535 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Christof Schmitt287ac012008-07-02 10:56:40 +02001537 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001538 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001540 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001541 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001543out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001544 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 return retval;
1546}
1547
Swen Schillig5ab944f2008-10-01 12:42:17 +02001548static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1549{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001550 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001551 struct fsf_qtcb_header *header = &req->qtcb->header;
1552
1553 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001554 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001555 goto out;
1556 }
1557
1558 switch (header->fsf_status) {
1559 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1560 dev_warn(&req->adapter->ccw_device->dev,
1561 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001562 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001563 case FSF_ADAPTER_STATUS_AVAILABLE:
1564 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001565 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001566 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001567 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001568 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001569 case FSF_GOOD:
1570 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001571 /* fall through */
1572 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001573 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001574 }
1575out:
1576 wake_up(&wka_port->completion_wq);
1577}
1578
1579/**
1580 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001581 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001582 * Returns: 0 on success, error otherwise
1583 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001584int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001585{
Swen Schillig564e1c82009-08-18 15:43:19 +02001586 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001587 struct zfcp_fsf_req *req;
1588 int retval = -EIO;
1589
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001590 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001591 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001592 goto out;
1593
Swen Schillig564e1c82009-08-18 15:43:19 +02001594 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec908782011-06-06 14:14:40 +02001595 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001596 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001597
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001598 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001599 retval = PTR_ERR(req);
1600 goto out;
1601 }
1602
Swen Schillig09a46c62009-08-18 15:43:16 +02001603 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001604 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001605
1606 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001607 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001608 req->data = wka_port;
1609
1610 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1611 retval = zfcp_fsf_req_send(req);
1612 if (retval)
1613 zfcp_fsf_req_free(req);
1614out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001615 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001616 return retval;
1617}
1618
1619static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1620{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001621 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001622
1623 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1624 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligea4a3a62010-12-02 15:16:16 +01001625 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
Swen Schillig5ab944f2008-10-01 12:42:17 +02001626 }
1627
Christof Schmittbd0072e2009-11-24 16:54:11 +01001628 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001629 wake_up(&wka_port->completion_wq);
1630}
1631
1632/**
1633 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001634 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001635 * Returns: 0 on success, error otherwise
1636 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001637int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001638{
Swen Schillig564e1c82009-08-18 15:43:19 +02001639 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001640 struct zfcp_fsf_req *req;
1641 int retval = -EIO;
1642
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001643 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001644 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001645 goto out;
1646
Swen Schillig564e1c82009-08-18 15:43:19 +02001647 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001648 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001649 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001650
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001651 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001652 retval = PTR_ERR(req);
1653 goto out;
1654 }
1655
Swen Schillig09a46c62009-08-18 15:43:16 +02001656 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001657 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001658
1659 req->handler = zfcp_fsf_close_wka_port_handler;
1660 req->data = wka_port;
1661 req->qtcb->header.port_handle = wka_port->handle;
1662
1663 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1664 retval = zfcp_fsf_req_send(req);
1665 if (retval)
1666 zfcp_fsf_req_free(req);
1667out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001668 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001669 return retval;
1670}
1671
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001672static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001674 struct zfcp_port *port = req->data;
1675 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001676 struct scsi_device *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001678 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001679 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001683 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001684 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001687 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001690 /* can't use generic zfcp_erp_modify_port_status because
1691 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1692 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001693 shost_for_each_device(sdev, port->adapter->scsi_host)
1694 if (sdev_to_zfcp(sdev)->port == port)
1695 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1696 &sdev_to_zfcp(sdev)->status);
Swen Schilligedaed852010-09-08 14:40:01 +02001697 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
1698 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001699 "fscpph2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001700 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 switch (header->fsf_status_qual.word[0]) {
1704 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001705 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001707 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 }
1710 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 /* can't use generic zfcp_erp_modify_port_status because
1713 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1714 */
1715 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001716 shost_for_each_device(sdev, port->adapter->scsi_host)
1717 if (sdev_to_zfcp(sdev)->port == port)
1718 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1719 &sdev_to_zfcp(sdev)->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001724/**
1725 * zfcp_fsf_close_physical_port - close physical port
1726 * @erp_action: pointer to struct zfcp_erp_action
1727 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001729int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
Swen Schillig564e1c82009-08-18 15:43:19 +02001731 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001732 struct zfcp_fsf_req *req;
1733 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001735 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001736 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Swen Schillig564e1c82009-08-18 15:43:19 +02001739 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001740 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001741 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001742
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001743 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001744 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 goto out;
1746 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001747
Swen Schillig09a46c62009-08-18 15:43:16 +02001748 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001749 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001750
1751 req->data = erp_action->port;
1752 req->qtcb->header.port_handle = erp_action->port->handle;
1753 req->erp_action = erp_action;
1754 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001755 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001756
Christof Schmitt287ac012008-07-02 10:56:40 +02001757 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001758 retval = zfcp_fsf_req_send(req);
1759 if (retval) {
1760 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001761 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001762 }
1763out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001764 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 return retval;
1766}
1767
Christof Schmittb62a8d92010-09-08 14:39:55 +02001768static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001770 struct zfcp_adapter *adapter = req->adapter;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001771 struct scsi_device *sdev = req->data;
1772 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001773 struct fsf_qtcb_header *header = &req->qtcb->header;
1774 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001776 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001777 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001780 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Christof Schmittb62a8d92010-09-08 14:39:55 +02001781 ZFCP_STATUS_LUN_SHARED |
1782 ZFCP_STATUS_LUN_READONLY,
1783 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 switch (header->fsf_status) {
1786
1787 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001788 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001789 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001793 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
1794 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001797 zfcp_erp_set_port_status(zfcp_sdev->port,
1798 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1799 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001800 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001801 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 case FSF_LUN_SHARING_VIOLATION:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001804 zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001805 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001808 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001809 "No handle is available for LUN "
1810 "0x%016Lx on port 0x%016Lx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001811 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1812 (unsigned long long)zfcp_sdev->port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001813 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001814 /* fall through */
1815 case FSF_INVALID_COMMAND_OPTION:
1816 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 switch (header->fsf_status_qual.word[0]) {
1820 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001821 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001822 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001824 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 }
1827 break;
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001830 zfcp_sdev->lun_handle = header->lun_handle;
1831 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Christof Schmitta1ca4832010-09-08 14:39:59 +02001832 zfcp_cfdc_open_lun_eval(sdev, bottom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
1836
1837/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001838 * zfcp_fsf_open_lun - open LUN
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001839 * @erp_action: pointer to struct zfcp_erp_action
1840 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001842int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001844 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001845 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001846 struct zfcp_fsf_req *req;
1847 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001849 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001850 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001851 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
Swen Schillig564e1c82009-08-18 15:43:19 +02001853 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Jan Glauber3ec908782011-06-06 14:14:40 +02001854 SBAL_SFLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001855 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001856
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001857 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001858 retval = PTR_ERR(req);
1859 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001860 }
1861
Swen Schillig09a46c62009-08-18 15:43:16 +02001862 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001863 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001865 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001866 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1867 req->handler = zfcp_fsf_open_lun_handler;
1868 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001869 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001870 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001871
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001872 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1873 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Christof Schmitt287ac012008-07-02 10:56:40 +02001875 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001876 retval = zfcp_fsf_req_send(req);
1877 if (retval) {
1878 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001879 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001881out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001882 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 return retval;
1884}
1885
Christof Schmittb62a8d92010-09-08 14:39:55 +02001886static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
Christof Schmittb62a8d92010-09-08 14:39:55 +02001888 struct scsi_device *sdev = req->data;
1889 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001890
1891 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001892 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001893
1894 switch (req->qtcb->header.fsf_status) {
1895 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001896 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001897 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1898 break;
1899 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001900 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001901 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1902 break;
1903 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001904 zfcp_erp_set_port_status(zfcp_sdev->port,
1905 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1906 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001907 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001908 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001909 break;
1910 case FSF_ADAPTER_STATUS_AVAILABLE:
1911 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1912 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001913 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001914 /* fall through */
1915 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1916 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1917 break;
1918 }
1919 break;
1920 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001921 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001922 break;
1923 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001924}
1925
1926/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001927 * zfcp_fsf_close_LUN - close LUN
1928 * @erp_action: pointer to erp_action triggering the "close LUN"
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001929 * Returns: 0 on success, error otherwise
1930 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001931int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001932{
Swen Schillig564e1c82009-08-18 15:43:19 +02001933 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001934 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001935 struct zfcp_fsf_req *req;
1936 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001938 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001939 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001941
Swen Schillig564e1c82009-08-18 15:43:19 +02001942 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Jan Glauber3ec908782011-06-06 14:14:40 +02001943 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001944 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001945
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001946 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001947 retval = PTR_ERR(req);
1948 goto out;
1949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Swen Schillig09a46c62009-08-18 15:43:16 +02001951 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001952 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001954 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001955 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1956 req->handler = zfcp_fsf_close_lun_handler;
1957 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001958 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001959 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Christof Schmitt287ac012008-07-02 10:56:40 +02001961 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001962 retval = zfcp_fsf_req_send(req);
1963 if (retval) {
1964 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001965 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001966 }
1967out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001968 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001969 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970}
1971
Christof Schmittc9615852008-05-06 11:00:05 +02001972static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1973{
1974 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001975 lat_rec->min = min(lat_rec->min, lat);
1976 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02001977}
1978
Christof Schmittd9742b42009-11-24 16:54:03 +01001979static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02001980{
Christof Schmittd9742b42009-11-24 16:54:03 +01001981 struct fsf_qual_latency_info *lat_in;
1982 struct latency_cont *lat = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001983 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scsi->device);
Christof Schmittd9742b42009-11-24 16:54:03 +01001984 struct zfcp_blk_drv_data blktrc;
1985 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02001986
Christof Schmittd9742b42009-11-24 16:54:03 +01001987 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02001988
Christof Schmittd9742b42009-11-24 16:54:03 +01001989 blktrc.flags = 0;
1990 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
1991 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1992 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02001993 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001994 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01001995
Christof Schmitt5bbf2972010-04-01 13:04:08 +02001996 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
1997 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmittd9742b42009-11-24 16:54:03 +01001998 blktrc.flags |= ZFCP_BLK_LAT_VALID;
1999 blktrc.channel_lat = lat_in->channel_lat * ticks;
2000 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2001
2002 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002003 case FSF_DATADIR_DIF_READ_STRIP:
2004 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002005 case FSF_DATADIR_READ:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002006 lat = &zfcp_sdev->latencies.read;
Christof Schmittd9742b42009-11-24 16:54:03 +01002007 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002008 case FSF_DATADIR_DIF_WRITE_INSERT:
2009 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002010 case FSF_DATADIR_WRITE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002011 lat = &zfcp_sdev->latencies.write;
Christof Schmittd9742b42009-11-24 16:54:03 +01002012 break;
2013 case FSF_DATADIR_CMND:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002014 lat = &zfcp_sdev->latencies.cmd;
Christof Schmittd9742b42009-11-24 16:54:03 +01002015 break;
2016 }
2017
2018 if (lat) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02002019 spin_lock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002020 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2021 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2022 lat->counter++;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002023 spin_unlock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002024 }
Christof Schmittc9615852008-05-06 11:00:05 +02002025 }
2026
Christof Schmittd9742b42009-11-24 16:54:03 +01002027 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2028 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002029}
2030
Christof Schmittc61b5362010-09-08 14:39:58 +02002031static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002032{
Christof Schmittb62a8d92010-09-08 14:39:55 +02002033 struct scsi_cmnd *scmnd = req->data;
2034 struct scsi_device *sdev = scmnd->device;
2035 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002036 struct fsf_qtcb_header *header = &req->qtcb->header;
2037
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002038 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
Christof Schmittc61b5362010-09-08 14:39:58 +02002039 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002040
2041 switch (header->fsf_status) {
2042 case FSF_HANDLE_MISMATCH:
2043 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002044 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002045 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2046 break;
2047 case FSF_FCPLUN_NOT_VALID:
2048 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002049 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002050 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2051 break;
2052 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2053 zfcp_fsf_class_not_supp(req);
2054 break;
2055 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02002056 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
2057 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002058 break;
2059 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2060 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002061 "Incorrect direction %d, LUN 0x%016Lx on port "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002062 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002063 req->qtcb->bottom.io.data_direction,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002064 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2065 (unsigned long long)zfcp_sdev->port->wwpn);
2066 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002067 "fssfch3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002068 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2069 break;
2070 case FSF_CMND_LENGTH_NOT_VALID:
2071 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002072 "Incorrect CDB length %d, LUN 0x%016Lx on "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002073 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002074 req->qtcb->bottom.io.fcp_cmnd_length,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002075 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2076 (unsigned long long)zfcp_sdev->port->wwpn);
2077 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002078 "fssfch4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002079 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2080 break;
2081 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002082 zfcp_erp_set_port_status(zfcp_sdev->port,
2083 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2084 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002085 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002086 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002087 break;
2088 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002089 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2090 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002091 "fssfch6");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002092 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002093 break;
2094 case FSF_ADAPTER_STATUS_AVAILABLE:
2095 if (header->fsf_status_qual.word[0] ==
2096 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Christof Schmittb62a8d92010-09-08 14:39:55 +02002097 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002098 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2099 break;
2100 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002101}
2102
2103static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2104{
2105 struct scsi_cmnd *scpnt;
2106 struct fcp_resp_with_ext *fcp_rsp;
2107 unsigned long flags;
2108
Christof Schmittc61b5362010-09-08 14:39:58 +02002109 read_lock_irqsave(&req->adapter->abort_lock, flags);
2110
2111 scpnt = req->data;
2112 if (unlikely(!scpnt)) {
2113 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2114 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002115 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002116
Swen Schillig5bfb2c32010-11-17 14:23:40 +01002117 zfcp_fsf_fcp_handler_common(req);
2118
Christof Schmittc61b5362010-09-08 14:39:58 +02002119 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2120 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2121 goto skip_fsfstatus;
2122 }
2123
2124 switch (req->qtcb->header.fsf_status) {
2125 case FSF_INCONSISTENT_PROT_DATA:
2126 case FSF_INVALID_PROT_PARM:
2127 set_host_byte(scpnt, DID_ERROR);
2128 goto skip_fsfstatus;
2129 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2130 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2131 goto skip_fsfstatus;
2132 case FSF_APP_TAG_CHECK_FAILURE:
2133 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2134 goto skip_fsfstatus;
2135 case FSF_REF_TAG_CHECK_FAILURE:
2136 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2137 goto skip_fsfstatus;
2138 }
2139 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2140 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2141
2142skip_fsfstatus:
2143 zfcp_fsf_req_trace(req, scpnt);
Swen Schillig250a1352010-12-02 15:16:15 +01002144 zfcp_dbf_scsi_result(scpnt, req);
Christof Schmittc61b5362010-09-08 14:39:58 +02002145
2146 scpnt->host_scribble = NULL;
2147 (scpnt->scsi_done) (scpnt);
2148 /*
2149 * We must hold this lock until scsi_done has been called.
2150 * Otherwise we may call scsi_done after abort regarding this
2151 * command has completed.
2152 * Note: scsi_done must not block!
2153 */
2154 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002155}
2156
Felix Beckef3eb712010-07-16 15:37:42 +02002157static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2158{
2159 switch (scsi_get_prot_op(scsi_cmnd)) {
2160 case SCSI_PROT_NORMAL:
2161 switch (scsi_cmnd->sc_data_direction) {
2162 case DMA_NONE:
2163 *data_dir = FSF_DATADIR_CMND;
2164 break;
2165 case DMA_FROM_DEVICE:
2166 *data_dir = FSF_DATADIR_READ;
2167 break;
2168 case DMA_TO_DEVICE:
2169 *data_dir = FSF_DATADIR_WRITE;
2170 break;
2171 case DMA_BIDIRECTIONAL:
2172 return -EINVAL;
2173 }
2174 break;
2175
2176 case SCSI_PROT_READ_STRIP:
2177 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2178 break;
2179 case SCSI_PROT_WRITE_INSERT:
2180 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2181 break;
2182 case SCSI_PROT_READ_PASS:
2183 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2184 break;
2185 case SCSI_PROT_WRITE_PASS:
2186 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2187 break;
2188 default:
2189 return -EINVAL;
2190 }
2191
2192 return 0;
2193}
2194
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002195/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002196 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002197 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002198 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002199int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002200{
2201 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002202 struct fcp_cmnd *fcp_cmnd;
Jan Glauber3ec908782011-06-06 14:14:40 +02002203 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
Swen Schillig86a96682011-08-15 14:40:32 +02002204 int retval = -EIO;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002205 struct scsi_device *sdev = scsi_cmnd->device;
2206 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2207 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002208 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002209 struct fsf_qtcb_bottom_io *io;
Christof Schmitte55f8752010-11-18 14:53:18 +01002210 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002211
Christof Schmittb62a8d92010-09-08 14:39:55 +02002212 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002213 ZFCP_STATUS_COMMON_UNBLOCKED)))
2214 return -EBUSY;
2215
Christof Schmitte55f8752010-11-18 14:53:18 +01002216 spin_lock_irqsave(&qdio->req_q_lock, flags);
Swen Schillig706eca42010-07-16 15:37:38 +02002217 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002218 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002219 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002220 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002221
Christof Schmitt1674b402010-04-30 18:09:34 +02002222 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
Jan Glauber3ec908782011-06-06 14:14:40 +02002223 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
Christof Schmitt1674b402010-04-30 18:09:34 +02002224
Swen Schillig564e1c82009-08-18 15:43:19 +02002225 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002226 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002227
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002228 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002229 retval = PTR_ERR(req);
2230 goto out;
2231 }
2232
Felix Beckef3eb712010-07-16 15:37:42 +02002233 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2234
2235 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002236 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002237 req->data = scsi_cmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002238 req->handler = zfcp_fsf_fcp_cmnd_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002239 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2240 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002241 io->service_class = FSF_CLASS_3;
2242 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002243
Felix Beckef3eb712010-07-16 15:37:42 +02002244 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2245 io->data_block_length = scsi_cmnd->device->sector_size;
2246 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002247 }
2248
Steffen Maiercc405ac2011-08-15 14:40:30 +02002249 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2250 goto failed_scsi_cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +02002251
Christof Schmitt4318e082009-11-24 16:54:08 +01002252 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002253 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002254
Felix Beckef3eb712010-07-16 15:37:42 +02002255 if (scsi_prot_sg_count(scsi_cmnd)) {
2256 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2257 scsi_prot_sg_count(scsi_cmnd));
Swen Schillig86a96682011-08-15 14:40:32 +02002258 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2259 scsi_prot_sglist(scsi_cmnd));
2260 if (retval)
2261 goto failed_scsi_cmnd;
2262 io->prot_data_length = zfcp_qdio_real_bytes(
Felix Beckef3eb712010-07-16 15:37:42 +02002263 scsi_prot_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002264 }
2265
Swen Schillig86a96682011-08-15 14:40:32 +02002266 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2267 scsi_sglist(scsi_cmnd));
2268 if (unlikely(retval))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002269 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002270
Felix Beckef3eb712010-07-16 15:37:42 +02002271 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schillig86a96682011-08-15 14:40:32 +02002272 if (zfcp_adapter_multi_buffer_active(adapter))
2273 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Felix Beckef3eb712010-07-16 15:37:42 +02002274
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002275 retval = zfcp_fsf_req_send(req);
2276 if (unlikely(retval))
2277 goto failed_scsi_cmnd;
2278
2279 goto out;
2280
2281failed_scsi_cmnd:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002282 zfcp_fsf_req_free(req);
2283 scsi_cmnd->host_scribble = NULL;
2284out:
Christof Schmitte55f8752010-11-18 14:53:18 +01002285 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002286 return retval;
2287}
2288
Christof Schmittc61b5362010-09-08 14:39:58 +02002289static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2290{
2291 struct fcp_resp_with_ext *fcp_rsp;
2292 struct fcp_resp_rsp_info *rsp_info;
2293
2294 zfcp_fsf_fcp_handler_common(req);
2295
2296 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2297 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2298
2299 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2300 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2301 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2302}
2303
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002304/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002305 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2306 * @scmnd: SCSI command to send the task management command for
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002307 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002308 * Returns: on success pointer to struct fsf_req, NULL otherwise
2309 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002310struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2311 u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002312{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002313 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002314 struct fcp_cmnd *fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002315 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2316 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002317
Christof Schmittb62a8d92010-09-08 14:39:55 +02002318 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002319 ZFCP_STATUS_COMMON_UNBLOCKED)))
2320 return NULL;
2321
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002322 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002323 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002324 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002325
Swen Schillig564e1c82009-08-18 15:43:19 +02002326 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Jan Glauber3ec908782011-06-06 14:14:40 +02002327 SBAL_SFLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002328 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002329
Swen Schillig633528c2008-11-26 18:07:37 +01002330 if (IS_ERR(req)) {
2331 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002332 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002333 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002334
Christof Schmittb62a8d92010-09-08 14:39:55 +02002335 req->data = scmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002336 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002337 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2338 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002339 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2340 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002341 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002342
Christof Schmitt1674b402010-04-30 18:09:34 +02002343 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002344
Christof Schmitt4318e082009-11-24 16:54:08 +01002345 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002346 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002347
2348 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2349 if (!zfcp_fsf_req_send(req))
2350 goto out;
2351
2352 zfcp_fsf_req_free(req);
2353 req = NULL;
2354out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002355 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002356 return req;
2357}
2358
2359static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2360{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002361}
2362
2363/**
2364 * zfcp_fsf_control_file - control file upload/download
2365 * @adapter: pointer to struct zfcp_adapter
2366 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2367 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002369struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2370 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
Swen Schillig564e1c82009-08-18 15:43:19 +02002372 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002373 struct zfcp_fsf_req *req = NULL;
2374 struct fsf_qtcb_bottom_support *bottom;
Swen Schillig86a96682011-08-15 14:40:32 +02002375 int retval = -EIO;
Jan Glauber3ec908782011-06-06 14:14:40 +02002376 u8 direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
Christof Schmitt45633fd2008-06-10 18:20:55 +02002378 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2379 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
Christof Schmitt45633fd2008-06-10 18:20:55 +02002381 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Jan Glauber3ec908782011-06-06 14:14:40 +02002383 direction = SBAL_SFLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Jan Glauber3ec908782011-06-06 14:14:40 +02002386 direction = SBAL_SFLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002389 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 }
2391
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002392 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002393 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002394 goto out;
2395
Christof Schmitt1674b402010-04-30 18:09:34 +02002396 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002397 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002399 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 }
2401
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002402 req->handler = zfcp_fsf_control_file_handler;
2403
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002404 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002406 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Swen Schillig86a96682011-08-15 14:40:32 +02002408 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
Swen Schillig01b04752010-07-16 15:37:37 +02002409
Swen Schillig86a96682011-08-15 14:40:32 +02002410 if (retval ||
2411 (zfcp_qdio_real_bytes(fsf_cfdc->sg) != ZFCP_CFDC_MAX_SIZE)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002412 zfcp_fsf_req_free(req);
Swen Schillig86a96682011-08-15 14:40:32 +02002413 retval = -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002414 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002415 }
Swen Schillig86a96682011-08-15 14:40:32 +02002416 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2417 if (zfcp_adapter_multi_buffer_active(adapter))
2418 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002420 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2421 retval = zfcp_fsf_req_send(req);
2422out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002423 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002424
2425 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002426 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002427 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002429 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002431
2432/**
2433 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2434 * @adapter: pointer to struct zfcp_adapter
2435 * @sbal_idx: response queue index of SBAL to be processed
2436 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002437void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002438{
Swen Schillig564e1c82009-08-18 15:43:19 +02002439 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002440 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002441 struct qdio_buffer_element *sbale;
2442 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002443 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002444 int idx;
2445
2446 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2447
2448 sbale = &sbal->element[idx];
2449 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002450 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002451
Christof Schmitt339f4f42010-07-16 15:37:43 +02002452 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002453 /*
2454 * Unknown request means that we have potentially memory
2455 * corruption and must stop the machine immediately.
2456 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002457 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002458 panic("error: unknown req_id (%lx) on adapter %s.\n",
2459 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002460 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002461
Christof Schmitt34c2b712010-02-17 11:18:59 +01002462 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002463 zfcp_fsf_req_complete(fsf_req);
2464
Jan Glauber3ec908782011-06-06 14:14:40 +02002465 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002466 break;
2467 }
2468}
Swen Schilliga54ca0f2010-12-02 15:16:14 +01002469
2470struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
2471 struct qdio_buffer *sbal)
2472{
2473 struct qdio_buffer_element *sbale = &sbal->element[0];
2474 u64 req_id = (unsigned long) sbale->addr;
2475
2476 return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
2477}