blob: c7e148f33b2a8afbcd319689434b707a835e0645 [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)
Steffen Maier43f60cb2012-09-04 15:23:35 +0200260 zfcp_fc_conditional_port_scan(adapter);
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);
Heiko Carstens1aae0562013-01-30 09:49:40 +0100730 req->issued = get_tod_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;
Martin Peschked436de82012-09-04 15:23:36 +0200804 struct zfcp_scsi_dev *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
Martin Peschked436de82012-09-04 15:23:36 +0200810 zfcp_sdev = sdev_to_zfcp(sdev);
811
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200812 switch (req->qtcb->header.fsf_status) {
813 case FSF_PORT_HANDLE_NOT_VALID:
814 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200815 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100816 "fsafch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200817 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820 case FSF_LUN_HANDLE_NOT_VALID:
821 if (fsq->word[0] == fsq->word[1]) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100822 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200823 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200826 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
827 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200829 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200830 zfcp_erp_set_port_status(zfcp_sdev->port,
831 ZFCP_STATUS_COMMON_ACCESS_BOXED);
832 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100833 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100834 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200835 break;
836 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200837 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
838 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100839 "fsafch4");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100840 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200841 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200843 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200845 zfcp_fc_test_link(zfcp_sdev->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200846 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200848 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 break;
850 }
851 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200853 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
854 break;
855 }
856}
857
858/**
Christof Schmittb62a8d92010-09-08 14:39:55 +0200859 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
860 * @scmnd: The SCSI command to abort
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862 */
863
Christof Schmittb62a8d92010-09-08 14:39:55 +0200864struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 struct zfcp_fsf_req *req = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200867 struct scsi_device *sdev = scmnd->device;
868 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
869 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
870 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200871
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200872 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200873 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200874 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200875 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Jan Glauber3ec908782011-06-06 14:14:40 +0200876 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200877 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100878 if (IS_ERR(req)) {
879 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200880 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100881 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882
Christof Schmittb62a8d92010-09-08 14:39:55 +0200883 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 ZFCP_STATUS_COMMON_UNBLOCKED)))
885 goto out_error_free;
886
Christof Schmitt1674b402010-04-30 18:09:34 +0200887 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200888
Swen Schillig6fbf25e2010-11-17 14:23:41 +0100889 req->data = sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200890 req->handler = zfcp_fsf_abort_fcp_command_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200891 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
892 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200893 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
894
895 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
896 if (!zfcp_fsf_req_send(req))
897 goto out;
898
899out_error_free:
900 zfcp_fsf_req_free(req);
901 req = NULL;
902out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200903 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200904 return req;
905}
906
907static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
908{
909 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100910 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200911 struct fsf_qtcb_header *header = &req->qtcb->header;
912
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100913 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200914
915 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
916 goto skip_fsfstatus;
917
918 switch (header->fsf_status) {
919 case FSF_GOOD:
Steffen Maier01009982012-09-04 15:23:30 +0200920 zfcp_dbf_san_res("fsscth2", req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100921 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200922 break;
923 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
924 zfcp_fsf_class_not_supp(req);
925 break;
926 case FSF_ADAPTER_STATUS_AVAILABLE:
927 switch (header->fsf_status_qual.word[0]){
928 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200929 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
930 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
931 break;
932 }
933 break;
934 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200935 break;
936 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100937 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200938 break;
939 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100940 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
Christof Schmittdceab652009-05-15 13:18:18 +0200941 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200942 case FSF_GENERIC_COMMAND_REJECTED:
943 case FSF_PAYLOAD_SIZE_MISMATCH:
944 case FSF_REQUEST_SIZE_TOO_LARGE:
945 case FSF_RESPONSE_SIZE_TOO_LARGE:
946 case FSF_SBAL_MISMATCH:
947 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
948 break;
949 }
950
951skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100952 if (ct->handler)
953 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200954}
955
Christof Schmitt1674b402010-04-30 18:09:34 +0200956static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
957 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200958 struct scatterlist *sg_req,
959 struct scatterlist *sg_resp)
960{
Christof Schmitt1674b402010-04-30 18:09:34 +0200961 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
962 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
963 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200964}
965
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100966static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
967 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200968 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200969{
Swen Schillig42428f72009-08-18 15:43:18 +0200970 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig86a96682011-08-15 14:40:32 +0200971 struct zfcp_qdio *qdio = adapter->qdio;
972 struct fsf_qtcb *qtcb = req->qtcb;
Swen Schillig42428f72009-08-18 15:43:18 +0200973 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200974
Swen Schillig86a96682011-08-15 14:40:32 +0200975 if (zfcp_adapter_multi_buffer_active(adapter)) {
976 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
977 return -EIO;
978 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
979 return -EIO;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100980
Swen Schillig86a96682011-08-15 14:40:32 +0200981 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
982 zfcp_qdio_sbale_count(sg_req));
983 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
984 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200985 return 0;
986 }
987
988 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200989 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Swen Schillig86a96682011-08-15 14:40:32 +0200990 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +0200991 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100992 return 0;
993 }
994
Swen Schillig86a96682011-08-15 14:40:32 +0200995 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
996 return -EOPNOTSUPP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200997
Swen Schillig86a96682011-08-15 14:40:32 +0200998 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
Christof Schmitt9072df42009-07-13 15:06:07 +0200999 return -EIO;
Swen Schillig86a96682011-08-15 14:40:32 +02001000
1001 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1002
1003 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1004 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1005
1006 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1007 return -EIO;
1008
1009 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1010
1011 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001012
Christof Schmittb1a58982009-09-24 10:23:21 +02001013 return 0;
1014}
1015
1016static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1017 struct scatterlist *sg_req,
1018 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001019 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001020{
1021 int ret;
1022
Swen Schillig01b04752010-07-16 15:37:37 +02001023 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001024 if (ret)
1025 return ret;
1026
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001027 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001028 if (timeout > 255)
1029 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001030 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001031 req->qtcb->bottom.support.timeout = timeout;
1032 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001033
1034 return 0;
1035}
1036
1037/**
1038 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1039 * @ct: pointer to struct zfcp_send_ct with data for request
1040 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001041 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001042int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001043 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1044 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001045{
Swen Schillig564e1c82009-08-18 15:43:19 +02001046 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001047 struct zfcp_fsf_req *req;
1048 int ret = -EIO;
1049
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001050 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001051 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001052 goto out;
1053
Christof Schmitt1674b402010-04-30 18:09:34 +02001054 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
Jan Glauber3ec908782011-06-06 14:14:40 +02001055 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001056
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001057 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001058 ret = PTR_ERR(req);
1059 goto out;
1060 }
1061
Swen Schillig09a46c62009-08-18 15:43:16 +02001062 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001063 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001064 if (ret)
1065 goto failed_send;
1066
1067 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001068 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001069 req->data = ct;
1070
Swen Schillig2c55b752010-12-02 15:16:13 +01001071 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001072
1073 ret = zfcp_fsf_req_send(req);
1074 if (ret)
1075 goto failed_send;
1076
1077 goto out;
1078
1079failed_send:
1080 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001081out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001082 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001083 return ret;
1084}
1085
1086static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1087{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001088 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001089 struct zfcp_port *port = send_els->port;
1090 struct fsf_qtcb_header *header = &req->qtcb->header;
1091
1092 send_els->status = -EINVAL;
1093
1094 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1095 goto skip_fsfstatus;
1096
1097 switch (header->fsf_status) {
1098 case FSF_GOOD:
Swen Schillig2c55b752010-12-02 15:16:13 +01001099 zfcp_dbf_san_res("fsselh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001100 send_els->status = 0;
1101 break;
1102 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1103 zfcp_fsf_class_not_supp(req);
1104 break;
1105 case FSF_ADAPTER_STATUS_AVAILABLE:
1106 switch (header->fsf_status_qual.word[0]){
1107 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001108 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1109 case FSF_SQ_RETRY_IF_POSSIBLE:
1110 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1111 break;
1112 }
1113 break;
1114 case FSF_ELS_COMMAND_REJECTED:
1115 case FSF_PAYLOAD_SIZE_MISMATCH:
1116 case FSF_REQUEST_SIZE_TOO_LARGE:
1117 case FSF_RESPONSE_SIZE_TOO_LARGE:
1118 break;
1119 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001120 if (port) {
1121 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1122 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1123 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001124 break;
1125 case FSF_SBAL_MISMATCH:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001126 /* should never occur, avoided in zfcp_fsf_send_els */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001127 /* fall through */
1128 default:
1129 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1130 break;
1131 }
1132skip_fsfstatus:
1133 if (send_els->handler)
1134 send_els->handler(send_els->handler_data);
1135}
1136
1137/**
1138 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1139 * @els: pointer to struct zfcp_send_els with data for the command
1140 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001141int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001142 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001143{
1144 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001145 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001146 int ret = -EIO;
1147
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001148 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001149 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001150 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001151
Christof Schmitt1674b402010-04-30 18:09:34 +02001152 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
Jan Glauber3ec908782011-06-06 14:14:40 +02001153 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001154
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001155 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001156 ret = PTR_ERR(req);
1157 goto out;
1158 }
1159
Swen Schillig09a46c62009-08-18 15:43:16 +02001160 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001161
Swen Schillig86a96682011-08-15 14:40:32 +02001162 if (!zfcp_adapter_multi_buffer_active(adapter))
1163 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
Swen Schillig01b04752010-07-16 15:37:37 +02001164
1165 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001166
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001167 if (ret)
1168 goto failed_send;
1169
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001170 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001171 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001172 req->data = els;
1173
Swen Schillig2c55b752010-12-02 15:16:13 +01001174 zfcp_dbf_san_req("fssels1", req, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001175
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001176 ret = zfcp_fsf_req_send(req);
1177 if (ret)
1178 goto failed_send;
1179
1180 goto out;
1181
1182failed_send:
1183 zfcp_fsf_req_free(req);
1184out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001185 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001186 return ret;
1187}
1188
1189int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1190{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001191 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001192 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001193 int retval = -EIO;
1194
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001195 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001196 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001197 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001198
Swen Schillig564e1c82009-08-18 15:43:19 +02001199 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001200 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001201 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001202
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001203 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001204 retval = PTR_ERR(req);
1205 goto out;
1206 }
1207
Swen Schillig09a46c62009-08-18 15:43:16 +02001208 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001209 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001210
1211 req->qtcb->bottom.config.feature_selection =
1212 FSF_FEATURE_CFDC |
1213 FSF_FEATURE_LUN_SHARING |
1214 FSF_FEATURE_NOTIFICATION_LOST |
1215 FSF_FEATURE_UPDATE_ALERT;
1216 req->erp_action = erp_action;
1217 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001218 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001219
Christof Schmitt287ac012008-07-02 10:56:40 +02001220 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001221 retval = zfcp_fsf_req_send(req);
1222 if (retval) {
1223 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001224 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001225 }
1226out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001227 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001228 return retval;
1229}
1230
Swen Schillig564e1c82009-08-18 15:43:19 +02001231int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232 struct fsf_qtcb_bottom_config *data)
1233{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001234 struct zfcp_fsf_req *req = NULL;
1235 int retval = -EIO;
1236
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001237 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001238 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001239 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001240
Christof Schmitt1674b402010-04-30 18:09:34 +02001241 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001242 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001243
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001244 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001245 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001246 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001247 }
1248
Christof Schmitt1674b402010-04-30 18:09:34 +02001249 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001250 req->handler = zfcp_fsf_exchange_config_data_handler;
1251
1252 req->qtcb->bottom.config.feature_selection =
1253 FSF_FEATURE_CFDC |
1254 FSF_FEATURE_LUN_SHARING |
1255 FSF_FEATURE_NOTIFICATION_LOST |
1256 FSF_FEATURE_UPDATE_ALERT;
1257
1258 if (data)
1259 req->data = data;
1260
1261 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1262 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001263 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001264 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001265 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001266
1267 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001268 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001269
Christof Schmittada81b72009-04-17 15:08:03 +02001270out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001271 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001272 return retval;
1273}
1274
1275/**
1276 * zfcp_fsf_exchange_port_data - request information about local port
1277 * @erp_action: ERP action for the adapter for which port data is requested
1278 * Returns: 0 on success, error otherwise
1279 */
1280int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1281{
Swen Schillig564e1c82009-08-18 15:43:19 +02001282 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001283 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001284 int retval = -EIO;
1285
Swen Schillig564e1c82009-08-18 15:43:19 +02001286 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001287 return -EOPNOTSUPP;
1288
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001289 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001290 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001291 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001292
Swen Schillig564e1c82009-08-18 15:43:19 +02001293 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001294 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001295 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001296
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001297 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001298 retval = PTR_ERR(req);
1299 goto out;
1300 }
1301
Swen Schillig09a46c62009-08-18 15:43:16 +02001302 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001303 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001304
1305 req->handler = zfcp_fsf_exchange_port_data_handler;
1306 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001307 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001308
Christof Schmitt287ac012008-07-02 10:56:40 +02001309 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001310 retval = zfcp_fsf_req_send(req);
1311 if (retval) {
1312 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001313 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001314 }
1315out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001316 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001317 return retval;
1318}
1319
1320/**
1321 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001322 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323 * @data: pointer to struct fsf_qtcb_bottom_port
1324 * Returns: 0 on success, error otherwise
1325 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001326int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001327 struct fsf_qtcb_bottom_port *data)
1328{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 struct zfcp_fsf_req *req = NULL;
1330 int retval = -EIO;
1331
Swen Schillig564e1c82009-08-18 15:43:19 +02001332 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001333 return -EOPNOTSUPP;
1334
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001335 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001336 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001337 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001338
Christof Schmitt1674b402010-04-30 18:09:34 +02001339 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec908782011-06-06 14:14:40 +02001340 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001341
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001342 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001343 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001344 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001345 }
1346
1347 if (data)
1348 req->data = data;
1349
Christof Schmitt1674b402010-04-30 18:09:34 +02001350 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001351
1352 req->handler = zfcp_fsf_exchange_port_data_handler;
1353 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1354 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001355 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001356
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001357 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001358 wait_for_completion(&req->completion);
1359
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001360 zfcp_fsf_req_free(req);
1361
1362 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001363
1364out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001365 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001366 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001367}
1368
1369static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1370{
1371 struct zfcp_port *port = req->data;
1372 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001373 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001374
1375 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001376 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001377
1378 switch (header->fsf_status) {
1379 case FSF_PORT_ALREADY_OPEN:
1380 break;
1381 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001382 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1383 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001384 break;
1385 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1386 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001387 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001388 "remote port 0x%016Lx\n",
1389 (unsigned long long)port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001390 zfcp_erp_set_port_status(port,
1391 ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001392 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1393 break;
1394 case FSF_ADAPTER_STATUS_AVAILABLE:
1395 switch (header->fsf_status_qual.word[0]) {
1396 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1397 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001398 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001399 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1400 break;
1401 }
1402 break;
1403 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1406 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001407 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1408 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1409 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 /* check whether D_ID has changed during open */
1411 /*
1412 * FIXME: This check is not airtight, as the FCP channel does
1413 * not monitor closures of target port connections caused on
1414 * the remote side. Thus, they might miss out on invalidating
1415 * locally cached WWPNs (and other N_Port parameters) of gone
1416 * target ports. So, our heroic attempt to make things safe
1417 * could be undermined by 'open port' response data tagged with
1418 * obsolete WWPNs. Another reason to monitor potential
1419 * connection closures ourself at least (by interpreting
1420 * incoming ELS' and unsolicited status). It just crosses my
1421 * mind that one should be able to cross-check by means of
1422 * another GID_PN straight after a port has been opened.
1423 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1424 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001425 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001426 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001427 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001428 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001431 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 break;
1433 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001434
1435out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001436 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
1438
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001439/**
1440 * zfcp_fsf_open_port - create and send open port request
1441 * @erp_action: pointer to struct zfcp_erp_action
1442 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001444int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Swen Schillig564e1c82009-08-18 15:43:19 +02001446 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001447 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001448 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001449 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001451 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001452 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Swen Schillig564e1c82009-08-18 15:43:19 +02001455 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec908782011-06-06 14:14:40 +02001456 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001457 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001458
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001459 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001460 retval = PTR_ERR(req);
1461 goto out;
1462 }
1463
Swen Schillig09a46c62009-08-18 15:43:16 +02001464 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001465 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001467 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001468 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001469 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001470 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001471 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001472 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Christof Schmitt287ac012008-07-02 10:56:40 +02001474 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001477 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001478 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001479 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001481out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001482 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 return retval;
1484}
1485
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001486static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001488 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001490 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001491 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001493 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001495 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001496 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 case FSF_GOOD:
Swen Schilligedaed852010-09-08 14:40:01 +02001501 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504}
1505
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001506/**
1507 * zfcp_fsf_close_port - create and send close port request
1508 * @erp_action: pointer to struct zfcp_erp_action
1509 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001511int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
Swen Schillig564e1c82009-08-18 15:43:19 +02001513 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001514 struct zfcp_fsf_req *req;
1515 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001517 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001518 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Swen Schillig564e1c82009-08-18 15:43:19 +02001521 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001522 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001523 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001524
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001525 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001526 retval = PTR_ERR(req);
1527 goto out;
1528 }
1529
Swen Schillig09a46c62009-08-18 15:43:16 +02001530 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001531 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001533 req->handler = zfcp_fsf_close_port_handler;
1534 req->data = erp_action->port;
1535 req->erp_action = erp_action;
1536 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001537 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Christof Schmitt287ac012008-07-02 10:56:40 +02001539 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001540 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001542 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001543 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001545out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001546 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 return retval;
1548}
1549
Swen Schillig5ab944f2008-10-01 12:42:17 +02001550static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1551{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001552 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001553 struct fsf_qtcb_header *header = &req->qtcb->header;
1554
1555 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001556 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001557 goto out;
1558 }
1559
1560 switch (header->fsf_status) {
1561 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1562 dev_warn(&req->adapter->ccw_device->dev,
1563 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001564 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001565 case FSF_ADAPTER_STATUS_AVAILABLE:
1566 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001567 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001568 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001569 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001570 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001571 case FSF_GOOD:
1572 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001573 /* fall through */
1574 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001575 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001576 }
1577out:
1578 wake_up(&wka_port->completion_wq);
1579}
1580
1581/**
1582 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001583 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001584 * Returns: 0 on success, error otherwise
1585 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001586int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001587{
Swen Schillig564e1c82009-08-18 15:43:19 +02001588 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001589 struct zfcp_fsf_req *req;
1590 int retval = -EIO;
1591
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001592 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001593 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001594 goto out;
1595
Swen Schillig564e1c82009-08-18 15:43:19 +02001596 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec908782011-06-06 14:14:40 +02001597 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001598 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001599
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001600 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001601 retval = PTR_ERR(req);
1602 goto out;
1603 }
1604
Swen Schillig09a46c62009-08-18 15:43:16 +02001605 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001606 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001607
1608 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001609 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001610 req->data = wka_port;
1611
1612 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1613 retval = zfcp_fsf_req_send(req);
1614 if (retval)
1615 zfcp_fsf_req_free(req);
1616out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001617 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001618 return retval;
1619}
1620
1621static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1622{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001623 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001624
1625 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1626 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligea4a3a62010-12-02 15:16:16 +01001627 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
Swen Schillig5ab944f2008-10-01 12:42:17 +02001628 }
1629
Christof Schmittbd0072e2009-11-24 16:54:11 +01001630 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001631 wake_up(&wka_port->completion_wq);
1632}
1633
1634/**
1635 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001636 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001637 * Returns: 0 on success, error otherwise
1638 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001639int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001640{
Swen Schillig564e1c82009-08-18 15:43:19 +02001641 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001642 struct zfcp_fsf_req *req;
1643 int retval = -EIO;
1644
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001645 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001646 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001647 goto out;
1648
Swen Schillig564e1c82009-08-18 15:43:19 +02001649 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001650 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001651 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001652
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001653 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001654 retval = PTR_ERR(req);
1655 goto out;
1656 }
1657
Swen Schillig09a46c62009-08-18 15:43:16 +02001658 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001659 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001660
1661 req->handler = zfcp_fsf_close_wka_port_handler;
1662 req->data = wka_port;
1663 req->qtcb->header.port_handle = wka_port->handle;
1664
1665 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1666 retval = zfcp_fsf_req_send(req);
1667 if (retval)
1668 zfcp_fsf_req_free(req);
1669out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001670 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001671 return retval;
1672}
1673
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001674static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001676 struct zfcp_port *port = req->data;
1677 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001678 struct scsi_device *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001680 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001681 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001685 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001686 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001689 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001692 /* can't use generic zfcp_erp_modify_port_status because
1693 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1694 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001695 shost_for_each_device(sdev, port->adapter->scsi_host)
1696 if (sdev_to_zfcp(sdev)->port == port)
1697 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1698 &sdev_to_zfcp(sdev)->status);
Swen Schilligedaed852010-09-08 14:40:01 +02001699 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
1700 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001701 "fscpph2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001702 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 switch (header->fsf_status_qual.word[0]) {
1706 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001707 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001709 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 }
1712 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 /* can't use generic zfcp_erp_modify_port_status because
1715 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1716 */
1717 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001718 shost_for_each_device(sdev, port->adapter->scsi_host)
1719 if (sdev_to_zfcp(sdev)->port == port)
1720 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1721 &sdev_to_zfcp(sdev)->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
1725
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001726/**
1727 * zfcp_fsf_close_physical_port - close physical port
1728 * @erp_action: pointer to struct zfcp_erp_action
1729 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001731int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732{
Swen Schillig564e1c82009-08-18 15:43:19 +02001733 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001734 struct zfcp_fsf_req *req;
1735 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001737 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001738 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Swen Schillig564e1c82009-08-18 15:43:19 +02001741 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Jan Glauber3ec908782011-06-06 14:14:40 +02001742 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001743 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001744
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001745 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001746 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 goto out;
1748 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001749
Swen Schillig09a46c62009-08-18 15:43:16 +02001750 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001751 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001752
1753 req->data = erp_action->port;
1754 req->qtcb->header.port_handle = erp_action->port->handle;
1755 req->erp_action = erp_action;
1756 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001757 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001758
Christof Schmitt287ac012008-07-02 10:56:40 +02001759 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001760 retval = zfcp_fsf_req_send(req);
1761 if (retval) {
1762 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001763 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001764 }
1765out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001766 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 return retval;
1768}
1769
Christof Schmittb62a8d92010-09-08 14:39:55 +02001770static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001772 struct zfcp_adapter *adapter = req->adapter;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001773 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001774 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001775 struct fsf_qtcb_header *header = &req->qtcb->header;
1776 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001778 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001779 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
Martin Peschked436de82012-09-04 15:23:36 +02001781 zfcp_sdev = sdev_to_zfcp(sdev);
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001784 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Christof Schmittb62a8d92010-09-08 14:39:55 +02001785 ZFCP_STATUS_LUN_SHARED |
1786 ZFCP_STATUS_LUN_READONLY,
1787 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 switch (header->fsf_status) {
1790
1791 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001792 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001793 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001797 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
1798 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001801 zfcp_erp_set_port_status(zfcp_sdev->port,
1802 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1803 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001804 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001805 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_LUN_SHARING_VIOLATION:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001808 zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001809 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001812 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001813 "No handle is available for LUN "
1814 "0x%016Lx on port 0x%016Lx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001815 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1816 (unsigned long long)zfcp_sdev->port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001817 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001818 /* fall through */
1819 case FSF_INVALID_COMMAND_OPTION:
1820 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 switch (header->fsf_status_qual.word[0]) {
1824 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001825 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001826 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001828 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 }
1831 break;
1832
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001834 zfcp_sdev->lun_handle = header->lun_handle;
1835 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Christof Schmitta1ca4832010-09-08 14:39:59 +02001836 zfcp_cfdc_open_lun_eval(sdev, bottom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839}
1840
1841/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001842 * zfcp_fsf_open_lun - open LUN
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001843 * @erp_action: pointer to struct zfcp_erp_action
1844 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001846int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001848 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001849 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001850 struct zfcp_fsf_req *req;
1851 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001853 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001854 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001855 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Swen Schillig564e1c82009-08-18 15:43:19 +02001857 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Jan Glauber3ec908782011-06-06 14:14:40 +02001858 SBAL_SFLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001859 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001860
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001861 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001862 retval = PTR_ERR(req);
1863 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001864 }
1865
Swen Schillig09a46c62009-08-18 15:43:16 +02001866 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001867 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001869 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001870 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1871 req->handler = zfcp_fsf_open_lun_handler;
1872 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001873 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001874 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001875
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001876 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1877 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Christof Schmitt287ac012008-07-02 10:56:40 +02001879 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001880 retval = zfcp_fsf_req_send(req);
1881 if (retval) {
1882 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001883 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001885out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001886 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 return retval;
1888}
1889
Christof Schmittb62a8d92010-09-08 14:39:55 +02001890static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
Christof Schmittb62a8d92010-09-08 14:39:55 +02001892 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001893 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001894
1895 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001896 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001897
Martin Peschked436de82012-09-04 15:23:36 +02001898 zfcp_sdev = sdev_to_zfcp(sdev);
1899
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001900 switch (req->qtcb->header.fsf_status) {
1901 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001902 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001903 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1904 break;
1905 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001906 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001907 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1908 break;
1909 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001910 zfcp_erp_set_port_status(zfcp_sdev->port,
1911 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1912 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001913 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001914 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001915 break;
1916 case FSF_ADAPTER_STATUS_AVAILABLE:
1917 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1918 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001919 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001920 /* fall through */
1921 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1922 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1923 break;
1924 }
1925 break;
1926 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001927 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001928 break;
1929 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001930}
1931
1932/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001933 * zfcp_fsf_close_LUN - close LUN
1934 * @erp_action: pointer to erp_action triggering the "close LUN"
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001935 * Returns: 0 on success, error otherwise
1936 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001937int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001938{
Swen Schillig564e1c82009-08-18 15:43:19 +02001939 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001940 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001941 struct zfcp_fsf_req *req;
1942 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001944 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001945 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001947
Swen Schillig564e1c82009-08-18 15:43:19 +02001948 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Jan Glauber3ec908782011-06-06 14:14:40 +02001949 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001950 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001951
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001952 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001953 retval = PTR_ERR(req);
1954 goto out;
1955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Swen Schillig09a46c62009-08-18 15:43:16 +02001957 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001958 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001960 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001961 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1962 req->handler = zfcp_fsf_close_lun_handler;
1963 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001964 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001965 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Christof Schmitt287ac012008-07-02 10:56:40 +02001967 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001968 retval = zfcp_fsf_req_send(req);
1969 if (retval) {
1970 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001971 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001972 }
1973out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001974 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001975 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976}
1977
Christof Schmittc9615852008-05-06 11:00:05 +02001978static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1979{
1980 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001981 lat_rec->min = min(lat_rec->min, lat);
1982 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02001983}
1984
Christof Schmittd9742b42009-11-24 16:54:03 +01001985static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02001986{
Christof Schmittd9742b42009-11-24 16:54:03 +01001987 struct fsf_qual_latency_info *lat_in;
1988 struct latency_cont *lat = NULL;
Martin Peschked436de82012-09-04 15:23:36 +02001989 struct zfcp_scsi_dev *zfcp_sdev;
Christof Schmittd9742b42009-11-24 16:54:03 +01001990 struct zfcp_blk_drv_data blktrc;
1991 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02001992
Christof Schmittd9742b42009-11-24 16:54:03 +01001993 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02001994
Christof Schmittd9742b42009-11-24 16:54:03 +01001995 blktrc.flags = 0;
1996 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
1997 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1998 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02001999 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002000 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002001
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002002 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2003 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Peschked436de82012-09-04 15:23:36 +02002004 zfcp_sdev = sdev_to_zfcp(scsi->device);
Christof Schmittd9742b42009-11-24 16:54:03 +01002005 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2006 blktrc.channel_lat = lat_in->channel_lat * ticks;
2007 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2008
2009 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002010 case FSF_DATADIR_DIF_READ_STRIP:
2011 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002012 case FSF_DATADIR_READ:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002013 lat = &zfcp_sdev->latencies.read;
Christof Schmittd9742b42009-11-24 16:54:03 +01002014 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002015 case FSF_DATADIR_DIF_WRITE_INSERT:
2016 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002017 case FSF_DATADIR_WRITE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002018 lat = &zfcp_sdev->latencies.write;
Christof Schmittd9742b42009-11-24 16:54:03 +01002019 break;
2020 case FSF_DATADIR_CMND:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002021 lat = &zfcp_sdev->latencies.cmd;
Christof Schmittd9742b42009-11-24 16:54:03 +01002022 break;
2023 }
2024
2025 if (lat) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02002026 spin_lock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002027 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2028 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2029 lat->counter++;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002030 spin_unlock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002031 }
Christof Schmittc9615852008-05-06 11:00:05 +02002032 }
2033
Christof Schmittd9742b42009-11-24 16:54:03 +01002034 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2035 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002036}
2037
Christof Schmittc61b5362010-09-08 14:39:58 +02002038static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002039{
Christof Schmittb62a8d92010-09-08 14:39:55 +02002040 struct scsi_cmnd *scmnd = req->data;
2041 struct scsi_device *sdev = scmnd->device;
Martin Peschked436de82012-09-04 15:23:36 +02002042 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002043 struct fsf_qtcb_header *header = &req->qtcb->header;
2044
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002045 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
Christof Schmittc61b5362010-09-08 14:39:58 +02002046 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002047
Martin Peschked436de82012-09-04 15:23:36 +02002048 zfcp_sdev = sdev_to_zfcp(sdev);
2049
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002050 switch (header->fsf_status) {
2051 case FSF_HANDLE_MISMATCH:
2052 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002053 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002054 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2055 break;
2056 case FSF_FCPLUN_NOT_VALID:
2057 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002058 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002059 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2060 break;
2061 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2062 zfcp_fsf_class_not_supp(req);
2063 break;
2064 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02002065 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
2066 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002067 break;
2068 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2069 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002070 "Incorrect direction %d, LUN 0x%016Lx on port "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002071 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002072 req->qtcb->bottom.io.data_direction,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002073 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2074 (unsigned long long)zfcp_sdev->port->wwpn);
2075 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002076 "fssfch3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002077 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2078 break;
2079 case FSF_CMND_LENGTH_NOT_VALID:
2080 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002081 "Incorrect CDB length %d, LUN 0x%016Lx on "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002082 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002083 req->qtcb->bottom.io.fcp_cmnd_length,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002084 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2085 (unsigned long long)zfcp_sdev->port->wwpn);
2086 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002087 "fssfch4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002088 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2089 break;
2090 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002091 zfcp_erp_set_port_status(zfcp_sdev->port,
2092 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2093 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002094 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002095 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002096 break;
2097 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002098 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2099 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002100 "fssfch6");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002101 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002102 break;
2103 case FSF_ADAPTER_STATUS_AVAILABLE:
2104 if (header->fsf_status_qual.word[0] ==
2105 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Christof Schmittb62a8d92010-09-08 14:39:55 +02002106 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002107 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2108 break;
2109 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002110}
2111
2112static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2113{
2114 struct scsi_cmnd *scpnt;
2115 struct fcp_resp_with_ext *fcp_rsp;
2116 unsigned long flags;
2117
Christof Schmittc61b5362010-09-08 14:39:58 +02002118 read_lock_irqsave(&req->adapter->abort_lock, flags);
2119
2120 scpnt = req->data;
2121 if (unlikely(!scpnt)) {
2122 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2123 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002124 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002125
Swen Schillig5bfb2c32010-11-17 14:23:40 +01002126 zfcp_fsf_fcp_handler_common(req);
2127
Christof Schmittc61b5362010-09-08 14:39:58 +02002128 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2129 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2130 goto skip_fsfstatus;
2131 }
2132
2133 switch (req->qtcb->header.fsf_status) {
2134 case FSF_INCONSISTENT_PROT_DATA:
2135 case FSF_INVALID_PROT_PARM:
2136 set_host_byte(scpnt, DID_ERROR);
2137 goto skip_fsfstatus;
2138 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2139 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2140 goto skip_fsfstatus;
2141 case FSF_APP_TAG_CHECK_FAILURE:
2142 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2143 goto skip_fsfstatus;
2144 case FSF_REF_TAG_CHECK_FAILURE:
2145 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2146 goto skip_fsfstatus;
2147 }
2148 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2149 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2150
2151skip_fsfstatus:
2152 zfcp_fsf_req_trace(req, scpnt);
Swen Schillig250a1352010-12-02 15:16:15 +01002153 zfcp_dbf_scsi_result(scpnt, req);
Christof Schmittc61b5362010-09-08 14:39:58 +02002154
2155 scpnt->host_scribble = NULL;
2156 (scpnt->scsi_done) (scpnt);
2157 /*
2158 * We must hold this lock until scsi_done has been called.
2159 * Otherwise we may call scsi_done after abort regarding this
2160 * command has completed.
2161 * Note: scsi_done must not block!
2162 */
2163 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002164}
2165
Felix Beckef3eb712010-07-16 15:37:42 +02002166static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2167{
2168 switch (scsi_get_prot_op(scsi_cmnd)) {
2169 case SCSI_PROT_NORMAL:
2170 switch (scsi_cmnd->sc_data_direction) {
2171 case DMA_NONE:
2172 *data_dir = FSF_DATADIR_CMND;
2173 break;
2174 case DMA_FROM_DEVICE:
2175 *data_dir = FSF_DATADIR_READ;
2176 break;
2177 case DMA_TO_DEVICE:
2178 *data_dir = FSF_DATADIR_WRITE;
2179 break;
2180 case DMA_BIDIRECTIONAL:
2181 return -EINVAL;
2182 }
2183 break;
2184
2185 case SCSI_PROT_READ_STRIP:
2186 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2187 break;
2188 case SCSI_PROT_WRITE_INSERT:
2189 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2190 break;
2191 case SCSI_PROT_READ_PASS:
2192 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2193 break;
2194 case SCSI_PROT_WRITE_PASS:
2195 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2196 break;
2197 default:
2198 return -EINVAL;
2199 }
2200
2201 return 0;
2202}
2203
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002204/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002205 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002206 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002207 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002208int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002209{
2210 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002211 struct fcp_cmnd *fcp_cmnd;
Jan Glauber3ec908782011-06-06 14:14:40 +02002212 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
Swen Schillig86a96682011-08-15 14:40:32 +02002213 int retval = -EIO;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002214 struct scsi_device *sdev = scsi_cmnd->device;
2215 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2216 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002217 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002218 struct fsf_qtcb_bottom_io *io;
Christof Schmitte55f8752010-11-18 14:53:18 +01002219 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002220
Christof Schmittb62a8d92010-09-08 14:39:55 +02002221 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002222 ZFCP_STATUS_COMMON_UNBLOCKED)))
2223 return -EBUSY;
2224
Christof Schmitte55f8752010-11-18 14:53:18 +01002225 spin_lock_irqsave(&qdio->req_q_lock, flags);
Swen Schillig706eca42010-07-16 15:37:38 +02002226 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002227 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002228 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002229 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002230
Christof Schmitt1674b402010-04-30 18:09:34 +02002231 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
Jan Glauber3ec908782011-06-06 14:14:40 +02002232 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
Christof Schmitt1674b402010-04-30 18:09:34 +02002233
Swen Schillig564e1c82009-08-18 15:43:19 +02002234 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002235 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002236
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002237 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002238 retval = PTR_ERR(req);
2239 goto out;
2240 }
2241
Felix Beckef3eb712010-07-16 15:37:42 +02002242 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2243
2244 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002245 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002246 req->data = scsi_cmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002247 req->handler = zfcp_fsf_fcp_cmnd_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002248 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2249 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002250 io->service_class = FSF_CLASS_3;
2251 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002252
Felix Beckef3eb712010-07-16 15:37:42 +02002253 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2254 io->data_block_length = scsi_cmnd->device->sector_size;
2255 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256 }
2257
Steffen Maiercc405ac2011-08-15 14:40:30 +02002258 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2259 goto failed_scsi_cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +02002260
Christof Schmitt4318e082009-11-24 16:54:08 +01002261 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002262 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002263
Felix Beckef3eb712010-07-16 15:37:42 +02002264 if (scsi_prot_sg_count(scsi_cmnd)) {
2265 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2266 scsi_prot_sg_count(scsi_cmnd));
Swen Schillig86a96682011-08-15 14:40:32 +02002267 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2268 scsi_prot_sglist(scsi_cmnd));
2269 if (retval)
2270 goto failed_scsi_cmnd;
2271 io->prot_data_length = zfcp_qdio_real_bytes(
Felix Beckef3eb712010-07-16 15:37:42 +02002272 scsi_prot_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002273 }
2274
Swen Schillig86a96682011-08-15 14:40:32 +02002275 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2276 scsi_sglist(scsi_cmnd));
2277 if (unlikely(retval))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002278 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002279
Felix Beckef3eb712010-07-16 15:37:42 +02002280 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schillig86a96682011-08-15 14:40:32 +02002281 if (zfcp_adapter_multi_buffer_active(adapter))
2282 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Felix Beckef3eb712010-07-16 15:37:42 +02002283
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002284 retval = zfcp_fsf_req_send(req);
2285 if (unlikely(retval))
2286 goto failed_scsi_cmnd;
2287
2288 goto out;
2289
2290failed_scsi_cmnd:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002291 zfcp_fsf_req_free(req);
2292 scsi_cmnd->host_scribble = NULL;
2293out:
Christof Schmitte55f8752010-11-18 14:53:18 +01002294 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002295 return retval;
2296}
2297
Christof Schmittc61b5362010-09-08 14:39:58 +02002298static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2299{
2300 struct fcp_resp_with_ext *fcp_rsp;
2301 struct fcp_resp_rsp_info *rsp_info;
2302
2303 zfcp_fsf_fcp_handler_common(req);
2304
2305 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2306 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2307
2308 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2309 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2310 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2311}
2312
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002313/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002314 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2315 * @scmnd: SCSI command to send the task management command for
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002316 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002317 * Returns: on success pointer to struct fsf_req, NULL otherwise
2318 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002319struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2320 u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002321{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002322 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002323 struct fcp_cmnd *fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002324 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2325 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002326
Christof Schmittb62a8d92010-09-08 14:39:55 +02002327 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002328 ZFCP_STATUS_COMMON_UNBLOCKED)))
2329 return NULL;
2330
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002331 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002332 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002333 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002334
Swen Schillig564e1c82009-08-18 15:43:19 +02002335 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Jan Glauber3ec908782011-06-06 14:14:40 +02002336 SBAL_SFLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002337 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002338
Swen Schillig633528c2008-11-26 18:07:37 +01002339 if (IS_ERR(req)) {
2340 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002341 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002342 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002343
Christof Schmittb62a8d92010-09-08 14:39:55 +02002344 req->data = scmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002345 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002346 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2347 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2349 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002350 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002351
Christof Schmitt1674b402010-04-30 18:09:34 +02002352 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002353
Christof Schmitt4318e082009-11-24 16:54:08 +01002354 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002355 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002356
2357 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2358 if (!zfcp_fsf_req_send(req))
2359 goto out;
2360
2361 zfcp_fsf_req_free(req);
2362 req = NULL;
2363out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002364 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002365 return req;
2366}
2367
2368static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2369{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002370}
2371
2372/**
2373 * zfcp_fsf_control_file - control file upload/download
2374 * @adapter: pointer to struct zfcp_adapter
2375 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2376 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002378struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2379 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380{
Swen Schillig564e1c82009-08-18 15:43:19 +02002381 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002382 struct zfcp_fsf_req *req = NULL;
2383 struct fsf_qtcb_bottom_support *bottom;
Swen Schillig86a96682011-08-15 14:40:32 +02002384 int retval = -EIO;
Jan Glauber3ec908782011-06-06 14:14:40 +02002385 u8 direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Christof Schmitt45633fd2008-06-10 18:20:55 +02002387 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2388 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Christof Schmitt45633fd2008-06-10 18:20:55 +02002390 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Jan Glauber3ec908782011-06-06 14:14:40 +02002392 direction = SBAL_SFLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Jan Glauber3ec908782011-06-06 14:14:40 +02002395 direction = SBAL_SFLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002398 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 }
2400
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002401 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002402 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002403 goto out;
2404
Christof Schmitt1674b402010-04-30 18:09:34 +02002405 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002406 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002408 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 }
2410
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002411 req->handler = zfcp_fsf_control_file_handler;
2412
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002413 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002415 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Swen Schillig86a96682011-08-15 14:40:32 +02002417 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
Swen Schillig01b04752010-07-16 15:37:37 +02002418
Swen Schillig86a96682011-08-15 14:40:32 +02002419 if (retval ||
2420 (zfcp_qdio_real_bytes(fsf_cfdc->sg) != ZFCP_CFDC_MAX_SIZE)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002421 zfcp_fsf_req_free(req);
Swen Schillig86a96682011-08-15 14:40:32 +02002422 retval = -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002423 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002424 }
Swen Schillig86a96682011-08-15 14:40:32 +02002425 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2426 if (zfcp_adapter_multi_buffer_active(adapter))
2427 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002429 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2430 retval = zfcp_fsf_req_send(req);
2431out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002432 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002433
2434 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002435 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002436 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002438 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002440
2441/**
2442 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2443 * @adapter: pointer to struct zfcp_adapter
2444 * @sbal_idx: response queue index of SBAL to be processed
2445 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002446void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002447{
Swen Schillig564e1c82009-08-18 15:43:19 +02002448 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002449 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002450 struct qdio_buffer_element *sbale;
2451 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002452 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002453 int idx;
2454
2455 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2456
2457 sbale = &sbal->element[idx];
2458 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002459 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002460
Christof Schmitt339f4f42010-07-16 15:37:43 +02002461 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002462 /*
2463 * Unknown request means that we have potentially memory
2464 * corruption and must stop the machine immediately.
2465 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002466 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002467 panic("error: unknown req_id (%lx) on adapter %s.\n",
2468 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002469 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002470
Christof Schmitt34c2b712010-02-17 11:18:59 +01002471 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002472 zfcp_fsf_req_complete(fsf_req);
2473
Jan Glauber3ec908782011-06-06 14:14:40 +02002474 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002475 break;
2476 }
2477}
Swen Schilliga54ca0f2010-12-02 15:16:14 +01002478
2479struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
2480 struct qdio_buffer *sbal)
2481{
2482 struct qdio_buffer_element *sbale = &sbal->element[0];
2483 u64 req_id = (unsigned long) sbale->addr;
2484
2485 return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
2486}