blob: 06760e435259042778d8dcba7dc147670479dad2 [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
Daniel Hanself76ccaa2013-04-26 17:32:14 +0200566 /* avoids adapter shutdown to be able to recognize
567 * events such as LINK UP */
568 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
569 &adapter->status);
Swen Schilligedaed852010-09-08 14:40:01 +0200570 zfcp_fsf_link_down_info_eval(req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200571 &qtcb->header.fsf_status_qual.link_down_info);
572 break;
573 default:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100574 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200575 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200578 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200580 memcpy(fc_host_serial_number(shost), bottom->serial_number,
581 min(FC_SERIAL_NUMBER_SIZE, 17));
582 EBCASC(fc_host_serial_number(shost),
583 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200586 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200587 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200588 "The FCP adapter only supports newer "
589 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100590 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200591 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200593 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200594 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200595 "The FCP adapter only supports older "
596 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100597 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200601static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200603 struct zfcp_adapter *adapter = req->adapter;
604 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
605 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200607 if (req->data)
608 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100609
Christof Schmitt02829852009-03-02 13:09:06 +0100610 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100611 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100612 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
613 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100614 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
615 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
Steffen Maierd2201972012-09-04 15:23:29 +0200616 fc_host_supported_speeds(shost) =
617 zfcp_fsf_convert_portspeed(bottom->supported_speed);
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100618 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
619 FC_FC4_LIST_SIZE);
620 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
621 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100622}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200624static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200626 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100627
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200628 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return;
630
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200631 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200632 case FSF_GOOD:
633 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200635 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200636 zfcp_fsf_exchange_port_evaluate(req);
Swen Schilligedaed852010-09-08 14:40:01 +0200637 zfcp_fsf_link_down_info_eval(req,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200638 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200639 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641}
642
Swen Schilliga4623c42009-08-18 15:43:15 +0200643static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644{
645 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200646
647 if (likely(pool))
648 req = mempool_alloc(pool, GFP_ATOMIC);
649 else
650 req = kmalloc(sizeof(*req), GFP_ATOMIC);
651
652 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200653 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200654
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200655 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100656 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200657 return req;
658}
659
Swen Schilliga4623c42009-08-18 15:43:15 +0200660static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200661{
Swen Schilliga4623c42009-08-18 15:43:15 +0200662 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200663
664 if (likely(pool))
665 qtcb = mempool_alloc(pool, GFP_ATOMIC);
666 else
Christof Schmitt259afe22011-02-22 19:54:44 +0100667 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
Swen Schilliga4623c42009-08-18 15:43:15 +0200668
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200669 if (unlikely(!qtcb))
670 return NULL;
671
672 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200673 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200674}
675
Swen Schillig564e1c82009-08-18 15:43:19 +0200676static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Jan Glauber3ec90872011-06-06 14:14:40 +0200677 u32 fsf_cmd, u8 sbtype,
Christof Schmitt1674b402010-04-30 18:09:34 +0200678 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Swen Schillig564e1c82009-08-18 15:43:19 +0200680 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200681 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200682
683 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200684 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200685
686 if (adapter->req_no == 0)
687 adapter->req_no++;
688
689 INIT_LIST_HEAD(&req->list);
690 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200691 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200692
693 req->adapter = adapter;
694 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100695 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200696
Swen Schilliga4623c42009-08-18 15:43:15 +0200697 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
698 if (likely(pool))
699 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
700 else
701 req->qtcb = zfcp_qtcb_alloc(NULL);
702
703 if (unlikely(!req->qtcb)) {
704 zfcp_fsf_req_free(req);
705 return ERR_PTR(-ENOMEM);
706 }
707
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100708 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200709 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200710 req->qtcb->prefix.req_id = req->req_id;
711 req->qtcb->prefix.ulp_info = 26;
712 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
713 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
714 req->qtcb->header.req_handle = req->req_id;
715 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200716 }
717
Christof Schmitt1674b402010-04-30 18:09:34 +0200718 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
719 req->qtcb, sizeof(struct fsf_qtcb));
720
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200721 return req;
722}
723
724static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
725{
726 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200727 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100728 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100729 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200730
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100731 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200732
Swen Schillig706eca42010-07-16 15:37:38 +0200733 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Heiko Carstens1aae0562013-01-30 09:49:40 +0100734 req->issued = get_tod_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100735 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200736 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100737 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100738 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100739 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200740 return -EIO;
741 }
742
743 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200744 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200745 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100746 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200747
748 return 0;
749}
750
751/**
752 * zfcp_fsf_status_read - send status read request
753 * @adapter: pointer to struct zfcp_adapter
754 * @req_flags: request flags
755 * Returns: 0 on success, ERROR otherwise
756 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200757int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200758{
Swen Schillig564e1c82009-08-18 15:43:19 +0200759 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200760 struct zfcp_fsf_req *req;
761 struct fsf_status_read_buffer *sr_buf;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100762 struct page *page;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200763 int retval = -EIO;
764
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200765 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200766 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Christof Schmitt1674b402010-04-30 18:09:34 +0200769 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200770 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200771 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 goto out;
774 }
775
Christof Schmittc7b279a2011-02-22 19:54:40 +0100776 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
777 if (!page) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200778 retval = -ENOMEM;
779 goto failed_buf;
780 }
Christof Schmittc7b279a2011-02-22 19:54:40 +0100781 sr_buf = page_address(page);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200782 memset(sr_buf, 0, sizeof(*sr_buf));
783 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200784
785 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
786 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200787
788 retval = zfcp_fsf_req_send(req);
789 if (retval)
790 goto failed_req_send;
791
792 goto out;
793
794failed_req_send:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100795 req->data = NULL;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100796 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200797failed_buf:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100798 zfcp_dbf_hba_fsf_uss("fssr__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200799 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200800out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200801 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 return retval;
803}
804
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200805static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200807 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +0200808 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200809 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200811 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
812 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Martin Peschked436de82012-09-04 15:23:36 +0200814 zfcp_sdev = sdev_to_zfcp(sdev);
815
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200816 switch (req->qtcb->header.fsf_status) {
817 case FSF_PORT_HANDLE_NOT_VALID:
818 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200819 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100820 "fsafch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200821 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200824 case FSF_LUN_HANDLE_NOT_VALID:
825 if (fsq->word[0] == fsq->word[1]) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100826 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200827 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200830 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
831 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200833 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200834 zfcp_erp_set_port_status(zfcp_sdev->port,
835 ZFCP_STATUS_COMMON_ACCESS_BOXED);
836 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100837 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100838 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200839 break;
840 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200841 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
842 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100843 "fsafch4");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100844 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200845 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200847 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200849 zfcp_fc_test_link(zfcp_sdev->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200850 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200852 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 break;
854 }
855 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200857 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
858 break;
859 }
860}
861
862/**
Christof Schmittb62a8d92010-09-08 14:39:55 +0200863 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
864 * @scmnd: The SCSI command to abort
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 */
867
Christof Schmittb62a8d92010-09-08 14:39:55 +0200868struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200869{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870 struct zfcp_fsf_req *req = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200871 struct scsi_device *sdev = scmnd->device;
872 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
873 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
874 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200875
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200876 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200877 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200879 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Jan Glauber3ec90872011-06-06 14:14:40 +0200880 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200881 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100882 if (IS_ERR(req)) {
883 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100885 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200886
Christof Schmittb62a8d92010-09-08 14:39:55 +0200887 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200888 ZFCP_STATUS_COMMON_UNBLOCKED)))
889 goto out_error_free;
890
Christof Schmitt1674b402010-04-30 18:09:34 +0200891 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200892
Swen Schillig6fbf25e2010-11-17 14:23:41 +0100893 req->data = sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200894 req->handler = zfcp_fsf_abort_fcp_command_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200895 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
896 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200897 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
898
899 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
900 if (!zfcp_fsf_req_send(req))
901 goto out;
902
903out_error_free:
904 zfcp_fsf_req_free(req);
905 req = NULL;
906out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200907 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200908 return req;
909}
910
911static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
912{
913 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100914 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200915 struct fsf_qtcb_header *header = &req->qtcb->header;
916
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100917 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200918
919 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
920 goto skip_fsfstatus;
921
922 switch (header->fsf_status) {
923 case FSF_GOOD:
Steffen Maier01009982012-09-04 15:23:30 +0200924 zfcp_dbf_san_res("fsscth2", req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100925 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200926 break;
927 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
928 zfcp_fsf_class_not_supp(req);
929 break;
930 case FSF_ADAPTER_STATUS_AVAILABLE:
931 switch (header->fsf_status_qual.word[0]){
932 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200933 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
934 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
935 break;
936 }
937 break;
938 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200939 break;
940 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100941 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200942 break;
943 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100944 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
Christof Schmittdceab652009-05-15 13:18:18 +0200945 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200946 case FSF_GENERIC_COMMAND_REJECTED:
947 case FSF_PAYLOAD_SIZE_MISMATCH:
948 case FSF_REQUEST_SIZE_TOO_LARGE:
949 case FSF_RESPONSE_SIZE_TOO_LARGE:
950 case FSF_SBAL_MISMATCH:
951 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
952 break;
953 }
954
955skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100956 if (ct->handler)
957 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200958}
959
Christof Schmitt1674b402010-04-30 18:09:34 +0200960static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
961 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200962 struct scatterlist *sg_req,
963 struct scatterlist *sg_resp)
964{
Christof Schmitt1674b402010-04-30 18:09:34 +0200965 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
966 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
967 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200968}
969
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100970static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
971 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200972 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200973{
Swen Schillig42428f72009-08-18 15:43:18 +0200974 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig86a96682011-08-15 14:40:32 +0200975 struct zfcp_qdio *qdio = adapter->qdio;
976 struct fsf_qtcb *qtcb = req->qtcb;
Swen Schillig42428f72009-08-18 15:43:18 +0200977 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200978
Swen Schillig86a96682011-08-15 14:40:32 +0200979 if (zfcp_adapter_multi_buffer_active(adapter)) {
980 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
981 return -EIO;
982 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
983 return -EIO;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100984
Swen Schillig86a96682011-08-15 14:40:32 +0200985 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
986 zfcp_qdio_sbale_count(sg_req));
987 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
988 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200989 return 0;
990 }
991
992 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200993 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Swen Schillig86a96682011-08-15 14:40:32 +0200994 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +0200995 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100996 return 0;
997 }
998
Swen Schillig86a96682011-08-15 14:40:32 +0200999 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
1000 return -EOPNOTSUPP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001001
Swen Schillig86a96682011-08-15 14:40:32 +02001002 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
Christof Schmitt9072df42009-07-13 15:06:07 +02001003 return -EIO;
Swen Schillig86a96682011-08-15 14:40:32 +02001004
1005 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1006
1007 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1008 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1009
1010 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1011 return -EIO;
1012
1013 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1014
1015 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001016
Christof Schmittb1a58982009-09-24 10:23:21 +02001017 return 0;
1018}
1019
1020static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1021 struct scatterlist *sg_req,
1022 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001023 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001024{
1025 int ret;
1026
Swen Schillig01b04752010-07-16 15:37:37 +02001027 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001028 if (ret)
1029 return ret;
1030
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001031 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001032 if (timeout > 255)
1033 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001034 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001035 req->qtcb->bottom.support.timeout = timeout;
1036 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001037
1038 return 0;
1039}
1040
1041/**
1042 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1043 * @ct: pointer to struct zfcp_send_ct with data for request
1044 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001045 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001046int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001047 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1048 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001049{
Swen Schillig564e1c82009-08-18 15:43:19 +02001050 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001051 struct zfcp_fsf_req *req;
1052 int ret = -EIO;
1053
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001054 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001055 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001056 goto out;
1057
Christof Schmitt1674b402010-04-30 18:09:34 +02001058 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
Jan Glauber3ec90872011-06-06 14:14:40 +02001059 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001060
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001061 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001062 ret = PTR_ERR(req);
1063 goto out;
1064 }
1065
Swen Schillig09a46c62009-08-18 15:43:16 +02001066 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001067 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001068 if (ret)
1069 goto failed_send;
1070
1071 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001072 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001073 req->data = ct;
1074
Swen Schillig2c55b752010-12-02 15:16:13 +01001075 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001076
1077 ret = zfcp_fsf_req_send(req);
1078 if (ret)
1079 goto failed_send;
1080
1081 goto out;
1082
1083failed_send:
1084 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001085out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001086 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087 return ret;
1088}
1089
1090static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1091{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001092 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001093 struct zfcp_port *port = send_els->port;
1094 struct fsf_qtcb_header *header = &req->qtcb->header;
1095
1096 send_els->status = -EINVAL;
1097
1098 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1099 goto skip_fsfstatus;
1100
1101 switch (header->fsf_status) {
1102 case FSF_GOOD:
Swen Schillig2c55b752010-12-02 15:16:13 +01001103 zfcp_dbf_san_res("fsselh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001104 send_els->status = 0;
1105 break;
1106 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1107 zfcp_fsf_class_not_supp(req);
1108 break;
1109 case FSF_ADAPTER_STATUS_AVAILABLE:
1110 switch (header->fsf_status_qual.word[0]){
1111 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001112 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1113 case FSF_SQ_RETRY_IF_POSSIBLE:
1114 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1115 break;
1116 }
1117 break;
1118 case FSF_ELS_COMMAND_REJECTED:
1119 case FSF_PAYLOAD_SIZE_MISMATCH:
1120 case FSF_REQUEST_SIZE_TOO_LARGE:
1121 case FSF_RESPONSE_SIZE_TOO_LARGE:
1122 break;
1123 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001124 if (port) {
1125 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1126 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1127 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001128 break;
1129 case FSF_SBAL_MISMATCH:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001130 /* should never occur, avoided in zfcp_fsf_send_els */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001131 /* fall through */
1132 default:
1133 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1134 break;
1135 }
1136skip_fsfstatus:
1137 if (send_els->handler)
1138 send_els->handler(send_els->handler_data);
1139}
1140
1141/**
1142 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1143 * @els: pointer to struct zfcp_send_els with data for the command
1144 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001145int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001146 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001147{
1148 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001149 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001150 int ret = -EIO;
1151
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001152 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001153 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001154 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001155
Christof Schmitt1674b402010-04-30 18:09:34 +02001156 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
Jan Glauber3ec90872011-06-06 14:14:40 +02001157 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001158
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001159 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001160 ret = PTR_ERR(req);
1161 goto out;
1162 }
1163
Swen Schillig09a46c62009-08-18 15:43:16 +02001164 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001165
Swen Schillig86a96682011-08-15 14:40:32 +02001166 if (!zfcp_adapter_multi_buffer_active(adapter))
1167 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
Swen Schillig01b04752010-07-16 15:37:37 +02001168
1169 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001170
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001171 if (ret)
1172 goto failed_send;
1173
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001174 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001175 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001176 req->data = els;
1177
Swen Schillig2c55b752010-12-02 15:16:13 +01001178 zfcp_dbf_san_req("fssels1", req, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001179
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001180 ret = zfcp_fsf_req_send(req);
1181 if (ret)
1182 goto failed_send;
1183
1184 goto out;
1185
1186failed_send:
1187 zfcp_fsf_req_free(req);
1188out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001189 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001190 return ret;
1191}
1192
1193int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1194{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001195 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001196 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001197 int retval = -EIO;
1198
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001199 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001200 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001201 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001202
Swen Schillig564e1c82009-08-18 15:43:19 +02001203 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001204 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001205 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001206
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001207 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001208 retval = PTR_ERR(req);
1209 goto out;
1210 }
1211
Swen Schillig09a46c62009-08-18 15:43:16 +02001212 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001213 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001214
1215 req->qtcb->bottom.config.feature_selection =
1216 FSF_FEATURE_CFDC |
1217 FSF_FEATURE_LUN_SHARING |
1218 FSF_FEATURE_NOTIFICATION_LOST |
1219 FSF_FEATURE_UPDATE_ALERT;
1220 req->erp_action = erp_action;
1221 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001222 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001223
Christof Schmitt287ac012008-07-02 10:56:40 +02001224 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001225 retval = zfcp_fsf_req_send(req);
1226 if (retval) {
1227 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001228 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001229 }
1230out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001231 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232 return retval;
1233}
1234
Swen Schillig564e1c82009-08-18 15:43:19 +02001235int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001236 struct fsf_qtcb_bottom_config *data)
1237{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 struct zfcp_fsf_req *req = NULL;
1239 int retval = -EIO;
1240
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001241 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001242 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001243 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001244
Christof Schmitt1674b402010-04-30 18:09:34 +02001245 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001246 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001247
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001248 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001249 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001250 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001251 }
1252
Christof Schmitt1674b402010-04-30 18:09:34 +02001253 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001254 req->handler = zfcp_fsf_exchange_config_data_handler;
1255
1256 req->qtcb->bottom.config.feature_selection =
1257 FSF_FEATURE_CFDC |
1258 FSF_FEATURE_LUN_SHARING |
1259 FSF_FEATURE_NOTIFICATION_LOST |
1260 FSF_FEATURE_UPDATE_ALERT;
1261
1262 if (data)
1263 req->data = data;
1264
1265 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1266 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001267 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001269 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001270
1271 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001272 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001273
Christof Schmittada81b72009-04-17 15:08:03 +02001274out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001275 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001276 return retval;
1277}
1278
1279/**
1280 * zfcp_fsf_exchange_port_data - request information about local port
1281 * @erp_action: ERP action for the adapter for which port data is requested
1282 * Returns: 0 on success, error otherwise
1283 */
1284int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1285{
Swen Schillig564e1c82009-08-18 15:43:19 +02001286 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001287 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001288 int retval = -EIO;
1289
Swen Schillig564e1c82009-08-18 15:43:19 +02001290 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001291 return -EOPNOTSUPP;
1292
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001293 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001294 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001295 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001296
Swen Schillig564e1c82009-08-18 15:43:19 +02001297 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001298 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001299 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001300
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001301 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001302 retval = PTR_ERR(req);
1303 goto out;
1304 }
1305
Swen Schillig09a46c62009-08-18 15:43:16 +02001306 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001307 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001308
1309 req->handler = zfcp_fsf_exchange_port_data_handler;
1310 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001311 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001312
Christof Schmitt287ac012008-07-02 10:56:40 +02001313 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001314 retval = zfcp_fsf_req_send(req);
1315 if (retval) {
1316 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001317 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001318 }
1319out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001320 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001321 return retval;
1322}
1323
1324/**
1325 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001326 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001327 * @data: pointer to struct fsf_qtcb_bottom_port
1328 * Returns: 0 on success, error otherwise
1329 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001330int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001331 struct fsf_qtcb_bottom_port *data)
1332{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001333 struct zfcp_fsf_req *req = NULL;
1334 int retval = -EIO;
1335
Swen Schillig564e1c82009-08-18 15:43:19 +02001336 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001337 return -EOPNOTSUPP;
1338
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001339 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001340 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001341 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001342
Christof Schmitt1674b402010-04-30 18:09:34 +02001343 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001344 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001345
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001346 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001347 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001348 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001349 }
1350
1351 if (data)
1352 req->data = data;
1353
Christof Schmitt1674b402010-04-30 18:09:34 +02001354 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001355
1356 req->handler = zfcp_fsf_exchange_port_data_handler;
1357 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1358 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001359 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001360
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001361 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001362 wait_for_completion(&req->completion);
1363
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001364 zfcp_fsf_req_free(req);
1365
1366 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001367
1368out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001369 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001370 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001371}
1372
1373static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1374{
1375 struct zfcp_port *port = req->data;
1376 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001377 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001378
1379 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001380 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001381
1382 switch (header->fsf_status) {
1383 case FSF_PORT_ALREADY_OPEN:
1384 break;
1385 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001386 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
1387 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001388 break;
1389 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1390 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001391 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001392 "remote port 0x%016Lx\n",
1393 (unsigned long long)port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001394 zfcp_erp_set_port_status(port,
1395 ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001396 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1397 break;
1398 case FSF_ADAPTER_STATUS_AVAILABLE:
1399 switch (header->fsf_status_qual.word[0]) {
1400 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1401 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001402 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001403 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1404 break;
1405 }
1406 break;
1407 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1410 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001411 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1412 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1413 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 /* check whether D_ID has changed during open */
1415 /*
1416 * FIXME: This check is not airtight, as the FCP channel does
1417 * not monitor closures of target port connections caused on
1418 * the remote side. Thus, they might miss out on invalidating
1419 * locally cached WWPNs (and other N_Port parameters) of gone
1420 * target ports. So, our heroic attempt to make things safe
1421 * could be undermined by 'open port' response data tagged with
1422 * obsolete WWPNs. Another reason to monitor potential
1423 * connection closures ourself at least (by interpreting
1424 * incoming ELS' and unsolicited status). It just crosses my
1425 * mind that one should be able to cross-check by means of
1426 * another GID_PN straight after a port has been opened.
1427 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1428 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001429 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001430 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001431 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001432 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001435 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 break;
1437 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001438
1439out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001440 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001443/**
1444 * zfcp_fsf_open_port - create and send open port request
1445 * @erp_action: pointer to struct zfcp_erp_action
1446 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001448int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449{
Swen Schillig564e1c82009-08-18 15:43:19 +02001450 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001451 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001452 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001453 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001455 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001456 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Swen Schillig564e1c82009-08-18 15:43:19 +02001459 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec90872011-06-06 14:14:40 +02001460 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001461 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001462
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001463 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001464 retval = PTR_ERR(req);
1465 goto out;
1466 }
1467
Swen Schillig09a46c62009-08-18 15:43:16 +02001468 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001469 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001471 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001472 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001473 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001474 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001475 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001476 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Christof Schmitt287ac012008-07-02 10:56:40 +02001478 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001481 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001482 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001483 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001485out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001486 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 return retval;
1488}
1489
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001490static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001492 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001495 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001497 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001499 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001500 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 case FSF_GOOD:
Swen Schilligedaed852010-09-08 14:40:01 +02001505 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508}
1509
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001510/**
1511 * zfcp_fsf_close_port - create and send close port request
1512 * @erp_action: pointer to struct zfcp_erp_action
1513 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001515int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516{
Swen Schillig564e1c82009-08-18 15:43:19 +02001517 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001518 struct zfcp_fsf_req *req;
1519 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001521 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001522 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
Swen Schillig564e1c82009-08-18 15:43:19 +02001525 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001526 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001527 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001528
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001529 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001530 retval = PTR_ERR(req);
1531 goto out;
1532 }
1533
Swen Schillig09a46c62009-08-18 15:43:16 +02001534 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001535 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001537 req->handler = zfcp_fsf_close_port_handler;
1538 req->data = erp_action->port;
1539 req->erp_action = erp_action;
1540 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001541 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Christof Schmitt287ac012008-07-02 10:56:40 +02001543 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001544 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001546 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001547 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001549out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001550 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 return retval;
1552}
1553
Swen Schillig5ab944f2008-10-01 12:42:17 +02001554static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1555{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001556 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001557 struct fsf_qtcb_header *header = &req->qtcb->header;
1558
1559 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001560 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001561 goto out;
1562 }
1563
1564 switch (header->fsf_status) {
1565 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1566 dev_warn(&req->adapter->ccw_device->dev,
1567 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001568 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001569 case FSF_ADAPTER_STATUS_AVAILABLE:
1570 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001571 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001572 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001573 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001574 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001575 case FSF_GOOD:
1576 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001577 /* fall through */
1578 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001579 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001580 }
1581out:
1582 wake_up(&wka_port->completion_wq);
1583}
1584
1585/**
1586 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001587 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001588 * Returns: 0 on success, error otherwise
1589 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001590int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001591{
Swen Schillig564e1c82009-08-18 15:43:19 +02001592 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001593 struct zfcp_fsf_req *req;
1594 int retval = -EIO;
1595
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001596 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001597 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001598 goto out;
1599
Swen Schillig564e1c82009-08-18 15:43:19 +02001600 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec90872011-06-06 14:14:40 +02001601 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001602 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001603
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001604 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001605 retval = PTR_ERR(req);
1606 goto out;
1607 }
1608
Swen Schillig09a46c62009-08-18 15:43:16 +02001609 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001610 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001611
1612 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001613 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001614 req->data = wka_port;
1615
1616 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1617 retval = zfcp_fsf_req_send(req);
1618 if (retval)
1619 zfcp_fsf_req_free(req);
1620out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001621 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001622 return retval;
1623}
1624
1625static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1626{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001627 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001628
1629 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1630 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligea4a3a62010-12-02 15:16:16 +01001631 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
Swen Schillig5ab944f2008-10-01 12:42:17 +02001632 }
1633
Christof Schmittbd0072e2009-11-24 16:54:11 +01001634 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001635 wake_up(&wka_port->completion_wq);
1636}
1637
1638/**
1639 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001640 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001641 * Returns: 0 on success, error otherwise
1642 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001643int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001644{
Swen Schillig564e1c82009-08-18 15:43:19 +02001645 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001646 struct zfcp_fsf_req *req;
1647 int retval = -EIO;
1648
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001649 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001650 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001651 goto out;
1652
Swen Schillig564e1c82009-08-18 15:43:19 +02001653 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001654 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001655 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001656
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001657 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001658 retval = PTR_ERR(req);
1659 goto out;
1660 }
1661
Swen Schillig09a46c62009-08-18 15:43:16 +02001662 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001663 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001664
1665 req->handler = zfcp_fsf_close_wka_port_handler;
1666 req->data = wka_port;
1667 req->qtcb->header.port_handle = wka_port->handle;
1668
1669 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1670 retval = zfcp_fsf_req_send(req);
1671 if (retval)
1672 zfcp_fsf_req_free(req);
1673out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001674 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001675 return retval;
1676}
1677
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001678static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001680 struct zfcp_port *port = req->data;
1681 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001682 struct scsi_device *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001684 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001685 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001689 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001690 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001693 zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001696 /* can't use generic zfcp_erp_modify_port_status because
1697 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1698 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001699 shost_for_each_device(sdev, port->adapter->scsi_host)
1700 if (sdev_to_zfcp(sdev)->port == port)
1701 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1702 &sdev_to_zfcp(sdev)->status);
Swen Schilligedaed852010-09-08 14:40:01 +02001703 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
1704 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001705 "fscpph2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001706 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 switch (header->fsf_status_qual.word[0]) {
1710 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001711 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001713 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 }
1716 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 /* can't use generic zfcp_erp_modify_port_status because
1719 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1720 */
1721 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001722 shost_for_each_device(sdev, port->adapter->scsi_host)
1723 if (sdev_to_zfcp(sdev)->port == port)
1724 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1725 &sdev_to_zfcp(sdev)->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001730/**
1731 * zfcp_fsf_close_physical_port - close physical port
1732 * @erp_action: pointer to struct zfcp_erp_action
1733 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001735int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
Swen Schillig564e1c82009-08-18 15:43:19 +02001737 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001738 struct zfcp_fsf_req *req;
1739 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001741 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001742 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Swen Schillig564e1c82009-08-18 15:43:19 +02001745 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001746 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001747 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001748
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001749 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001750 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 goto out;
1752 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001753
Swen Schillig09a46c62009-08-18 15:43:16 +02001754 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001755 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001756
1757 req->data = erp_action->port;
1758 req->qtcb->header.port_handle = erp_action->port->handle;
1759 req->erp_action = erp_action;
1760 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001761 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001762
Christof Schmitt287ac012008-07-02 10:56:40 +02001763 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001764 retval = zfcp_fsf_req_send(req);
1765 if (retval) {
1766 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001767 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001768 }
1769out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001770 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 return retval;
1772}
1773
Christof Schmittb62a8d92010-09-08 14:39:55 +02001774static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001776 struct zfcp_adapter *adapter = req->adapter;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001777 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001778 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001779 struct fsf_qtcb_header *header = &req->qtcb->header;
1780 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001782 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001783 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Martin Peschked436de82012-09-04 15:23:36 +02001785 zfcp_sdev = sdev_to_zfcp(sdev);
1786
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001788 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Christof Schmittb62a8d92010-09-08 14:39:55 +02001789 ZFCP_STATUS_LUN_SHARED |
1790 ZFCP_STATUS_LUN_READONLY,
1791 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 switch (header->fsf_status) {
1794
1795 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001796 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001797 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001801 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
1802 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001805 zfcp_erp_set_port_status(zfcp_sdev->port,
1806 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1807 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001808 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001809 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_LUN_SHARING_VIOLATION:
Christof Schmitta1ca4832010-09-08 14:39:59 +02001812 zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001813 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001816 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001817 "No handle is available for LUN "
1818 "0x%016Lx on port 0x%016Lx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001819 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1820 (unsigned long long)zfcp_sdev->port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001821 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001822 /* fall through */
1823 case FSF_INVALID_COMMAND_OPTION:
1824 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 switch (header->fsf_status_qual.word[0]) {
1828 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001829 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001830 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001832 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 }
1835 break;
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001838 zfcp_sdev->lun_handle = header->lun_handle;
1839 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Christof Schmitta1ca4832010-09-08 14:39:59 +02001840 zfcp_cfdc_open_lun_eval(sdev, bottom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843}
1844
1845/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001846 * zfcp_fsf_open_lun - open LUN
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001847 * @erp_action: pointer to struct zfcp_erp_action
1848 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001850int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001852 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001853 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001854 struct zfcp_fsf_req *req;
1855 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001857 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001858 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001859 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
Swen Schillig564e1c82009-08-18 15:43:19 +02001861 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Jan Glauber3ec90872011-06-06 14:14:40 +02001862 SBAL_SFLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001863 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001864
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001865 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001866 retval = PTR_ERR(req);
1867 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001868 }
1869
Swen Schillig09a46c62009-08-18 15:43:16 +02001870 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001871 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001873 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001874 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1875 req->handler = zfcp_fsf_open_lun_handler;
1876 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001877 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001878 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001879
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001880 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1881 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Christof Schmitt287ac012008-07-02 10:56:40 +02001883 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001884 retval = zfcp_fsf_req_send(req);
1885 if (retval) {
1886 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001887 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001889out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001890 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 return retval;
1892}
1893
Christof Schmittb62a8d92010-09-08 14:39:55 +02001894static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895{
Christof Schmittb62a8d92010-09-08 14:39:55 +02001896 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001897 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001898
1899 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001900 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001901
Martin Peschked436de82012-09-04 15:23:36 +02001902 zfcp_sdev = sdev_to_zfcp(sdev);
1903
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001904 switch (req->qtcb->header.fsf_status) {
1905 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001906 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001907 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1908 break;
1909 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001910 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001911 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1912 break;
1913 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001914 zfcp_erp_set_port_status(zfcp_sdev->port,
1915 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1916 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001917 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001918 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001919 break;
1920 case FSF_ADAPTER_STATUS_AVAILABLE:
1921 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1922 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001923 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001924 /* fall through */
1925 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1926 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1927 break;
1928 }
1929 break;
1930 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001931 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001932 break;
1933 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001934}
1935
1936/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001937 * zfcp_fsf_close_LUN - close LUN
1938 * @erp_action: pointer to erp_action triggering the "close LUN"
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001939 * Returns: 0 on success, error otherwise
1940 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001941int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001942{
Swen Schillig564e1c82009-08-18 15:43:19 +02001943 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001944 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001945 struct zfcp_fsf_req *req;
1946 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001948 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001949 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001951
Swen Schillig564e1c82009-08-18 15:43:19 +02001952 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Jan Glauber3ec90872011-06-06 14:14:40 +02001953 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001954 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001955
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001956 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001957 retval = PTR_ERR(req);
1958 goto out;
1959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Swen Schillig09a46c62009-08-18 15:43:16 +02001961 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001962 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001964 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001965 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1966 req->handler = zfcp_fsf_close_lun_handler;
1967 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001968 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001969 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
Christof Schmitt287ac012008-07-02 10:56:40 +02001971 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001972 retval = zfcp_fsf_req_send(req);
1973 if (retval) {
1974 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001975 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001976 }
1977out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001978 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001979 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980}
1981
Christof Schmittc9615852008-05-06 11:00:05 +02001982static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1983{
1984 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001985 lat_rec->min = min(lat_rec->min, lat);
1986 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02001987}
1988
Christof Schmittd9742b42009-11-24 16:54:03 +01001989static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02001990{
Christof Schmittd9742b42009-11-24 16:54:03 +01001991 struct fsf_qual_latency_info *lat_in;
1992 struct latency_cont *lat = NULL;
Martin Peschked436de82012-09-04 15:23:36 +02001993 struct zfcp_scsi_dev *zfcp_sdev;
Christof Schmittd9742b42009-11-24 16:54:03 +01001994 struct zfcp_blk_drv_data blktrc;
1995 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02001996
Christof Schmittd9742b42009-11-24 16:54:03 +01001997 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02001998
Christof Schmittd9742b42009-11-24 16:54:03 +01001999 blktrc.flags = 0;
2000 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2001 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2002 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02002003 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002004 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002005
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002006 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2007 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Peschked436de82012-09-04 15:23:36 +02002008 zfcp_sdev = sdev_to_zfcp(scsi->device);
Christof Schmittd9742b42009-11-24 16:54:03 +01002009 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2010 blktrc.channel_lat = lat_in->channel_lat * ticks;
2011 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2012
2013 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002014 case FSF_DATADIR_DIF_READ_STRIP:
2015 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002016 case FSF_DATADIR_READ:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002017 lat = &zfcp_sdev->latencies.read;
Christof Schmittd9742b42009-11-24 16:54:03 +01002018 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002019 case FSF_DATADIR_DIF_WRITE_INSERT:
2020 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002021 case FSF_DATADIR_WRITE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002022 lat = &zfcp_sdev->latencies.write;
Christof Schmittd9742b42009-11-24 16:54:03 +01002023 break;
2024 case FSF_DATADIR_CMND:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002025 lat = &zfcp_sdev->latencies.cmd;
Christof Schmittd9742b42009-11-24 16:54:03 +01002026 break;
2027 }
2028
2029 if (lat) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02002030 spin_lock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002031 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2032 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2033 lat->counter++;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002034 spin_unlock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002035 }
Christof Schmittc9615852008-05-06 11:00:05 +02002036 }
2037
Christof Schmittd9742b42009-11-24 16:54:03 +01002038 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2039 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002040}
2041
Christof Schmittc61b5362010-09-08 14:39:58 +02002042static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002043{
Christof Schmittb62a8d92010-09-08 14:39:55 +02002044 struct scsi_cmnd *scmnd = req->data;
2045 struct scsi_device *sdev = scmnd->device;
Martin Peschked436de82012-09-04 15:23:36 +02002046 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002047 struct fsf_qtcb_header *header = &req->qtcb->header;
2048
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002049 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
Christof Schmittc61b5362010-09-08 14:39:58 +02002050 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002051
Martin Peschked436de82012-09-04 15:23:36 +02002052 zfcp_sdev = sdev_to_zfcp(sdev);
2053
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002054 switch (header->fsf_status) {
2055 case FSF_HANDLE_MISMATCH:
2056 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002057 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002058 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2059 break;
2060 case FSF_FCPLUN_NOT_VALID:
2061 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002062 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002063 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2064 break;
2065 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2066 zfcp_fsf_class_not_supp(req);
2067 break;
2068 case FSF_ACCESS_DENIED:
Christof Schmitta1ca4832010-09-08 14:39:59 +02002069 zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
2070 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002071 break;
2072 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2073 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002074 "Incorrect direction %d, LUN 0x%016Lx on port "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002075 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002076 req->qtcb->bottom.io.data_direction,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002077 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2078 (unsigned long long)zfcp_sdev->port->wwpn);
2079 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002080 "fssfch3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002081 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2082 break;
2083 case FSF_CMND_LENGTH_NOT_VALID:
2084 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002085 "Incorrect CDB length %d, LUN 0x%016Lx on "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002086 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002087 req->qtcb->bottom.io.fcp_cmnd_length,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002088 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2089 (unsigned long long)zfcp_sdev->port->wwpn);
2090 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002091 "fssfch4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002092 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2093 break;
2094 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002095 zfcp_erp_set_port_status(zfcp_sdev->port,
2096 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2097 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002098 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002099 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002100 break;
2101 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002102 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2103 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002104 "fssfch6");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002105 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002106 break;
2107 case FSF_ADAPTER_STATUS_AVAILABLE:
2108 if (header->fsf_status_qual.word[0] ==
2109 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Christof Schmittb62a8d92010-09-08 14:39:55 +02002110 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002111 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2112 break;
2113 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002114}
2115
2116static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2117{
2118 struct scsi_cmnd *scpnt;
2119 struct fcp_resp_with_ext *fcp_rsp;
2120 unsigned long flags;
2121
Christof Schmittc61b5362010-09-08 14:39:58 +02002122 read_lock_irqsave(&req->adapter->abort_lock, flags);
2123
2124 scpnt = req->data;
2125 if (unlikely(!scpnt)) {
2126 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2127 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002128 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002129
Swen Schillig5bfb2c32010-11-17 14:23:40 +01002130 zfcp_fsf_fcp_handler_common(req);
2131
Christof Schmittc61b5362010-09-08 14:39:58 +02002132 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2133 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2134 goto skip_fsfstatus;
2135 }
2136
2137 switch (req->qtcb->header.fsf_status) {
2138 case FSF_INCONSISTENT_PROT_DATA:
2139 case FSF_INVALID_PROT_PARM:
2140 set_host_byte(scpnt, DID_ERROR);
2141 goto skip_fsfstatus;
2142 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2143 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2144 goto skip_fsfstatus;
2145 case FSF_APP_TAG_CHECK_FAILURE:
2146 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2147 goto skip_fsfstatus;
2148 case FSF_REF_TAG_CHECK_FAILURE:
2149 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2150 goto skip_fsfstatus;
2151 }
2152 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2153 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2154
2155skip_fsfstatus:
2156 zfcp_fsf_req_trace(req, scpnt);
Swen Schillig250a1352010-12-02 15:16:15 +01002157 zfcp_dbf_scsi_result(scpnt, req);
Christof Schmittc61b5362010-09-08 14:39:58 +02002158
2159 scpnt->host_scribble = NULL;
2160 (scpnt->scsi_done) (scpnt);
2161 /*
2162 * We must hold this lock until scsi_done has been called.
2163 * Otherwise we may call scsi_done after abort regarding this
2164 * command has completed.
2165 * Note: scsi_done must not block!
2166 */
2167 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002168}
2169
Felix Beckef3eb712010-07-16 15:37:42 +02002170static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2171{
2172 switch (scsi_get_prot_op(scsi_cmnd)) {
2173 case SCSI_PROT_NORMAL:
2174 switch (scsi_cmnd->sc_data_direction) {
2175 case DMA_NONE:
2176 *data_dir = FSF_DATADIR_CMND;
2177 break;
2178 case DMA_FROM_DEVICE:
2179 *data_dir = FSF_DATADIR_READ;
2180 break;
2181 case DMA_TO_DEVICE:
2182 *data_dir = FSF_DATADIR_WRITE;
2183 break;
2184 case DMA_BIDIRECTIONAL:
2185 return -EINVAL;
2186 }
2187 break;
2188
2189 case SCSI_PROT_READ_STRIP:
2190 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2191 break;
2192 case SCSI_PROT_WRITE_INSERT:
2193 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2194 break;
2195 case SCSI_PROT_READ_PASS:
2196 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2197 break;
2198 case SCSI_PROT_WRITE_PASS:
2199 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2200 break;
2201 default:
2202 return -EINVAL;
2203 }
2204
2205 return 0;
2206}
2207
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002208/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002209 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002210 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002211 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002212int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002213{
2214 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002215 struct fcp_cmnd *fcp_cmnd;
Jan Glauber3ec90872011-06-06 14:14:40 +02002216 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
Swen Schillig86a96682011-08-15 14:40:32 +02002217 int retval = -EIO;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002218 struct scsi_device *sdev = scsi_cmnd->device;
2219 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2220 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002221 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002222 struct fsf_qtcb_bottom_io *io;
Christof Schmitte55f8752010-11-18 14:53:18 +01002223 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002224
Christof Schmittb62a8d92010-09-08 14:39:55 +02002225 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002226 ZFCP_STATUS_COMMON_UNBLOCKED)))
2227 return -EBUSY;
2228
Christof Schmitte55f8752010-11-18 14:53:18 +01002229 spin_lock_irqsave(&qdio->req_q_lock, flags);
Swen Schillig706eca42010-07-16 15:37:38 +02002230 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002231 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002232 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002233 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002234
Christof Schmitt1674b402010-04-30 18:09:34 +02002235 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
Jan Glauber3ec90872011-06-06 14:14:40 +02002236 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
Christof Schmitt1674b402010-04-30 18:09:34 +02002237
Swen Schillig564e1c82009-08-18 15:43:19 +02002238 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002239 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002240
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002241 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002242 retval = PTR_ERR(req);
2243 goto out;
2244 }
2245
Felix Beckef3eb712010-07-16 15:37:42 +02002246 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2247
2248 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002249 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002250 req->data = scsi_cmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002251 req->handler = zfcp_fsf_fcp_cmnd_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002252 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2253 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002254 io->service_class = FSF_CLASS_3;
2255 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256
Felix Beckef3eb712010-07-16 15:37:42 +02002257 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2258 io->data_block_length = scsi_cmnd->device->sector_size;
2259 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002260 }
2261
Steffen Maiercc405ac2011-08-15 14:40:30 +02002262 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2263 goto failed_scsi_cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +02002264
Christof Schmitt4318e082009-11-24 16:54:08 +01002265 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002266 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002267
Felix Beckef3eb712010-07-16 15:37:42 +02002268 if (scsi_prot_sg_count(scsi_cmnd)) {
2269 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2270 scsi_prot_sg_count(scsi_cmnd));
Swen Schillig86a96682011-08-15 14:40:32 +02002271 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2272 scsi_prot_sglist(scsi_cmnd));
2273 if (retval)
2274 goto failed_scsi_cmnd;
2275 io->prot_data_length = zfcp_qdio_real_bytes(
Felix Beckef3eb712010-07-16 15:37:42 +02002276 scsi_prot_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002277 }
2278
Swen Schillig86a96682011-08-15 14:40:32 +02002279 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2280 scsi_sglist(scsi_cmnd));
2281 if (unlikely(retval))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002282 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002283
Felix Beckef3eb712010-07-16 15:37:42 +02002284 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schillig86a96682011-08-15 14:40:32 +02002285 if (zfcp_adapter_multi_buffer_active(adapter))
2286 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Felix Beckef3eb712010-07-16 15:37:42 +02002287
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002288 retval = zfcp_fsf_req_send(req);
2289 if (unlikely(retval))
2290 goto failed_scsi_cmnd;
2291
2292 goto out;
2293
2294failed_scsi_cmnd:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002295 zfcp_fsf_req_free(req);
2296 scsi_cmnd->host_scribble = NULL;
2297out:
Christof Schmitte55f8752010-11-18 14:53:18 +01002298 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002299 return retval;
2300}
2301
Christof Schmittc61b5362010-09-08 14:39:58 +02002302static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2303{
2304 struct fcp_resp_with_ext *fcp_rsp;
2305 struct fcp_resp_rsp_info *rsp_info;
2306
2307 zfcp_fsf_fcp_handler_common(req);
2308
2309 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2310 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2311
2312 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2313 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2314 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2315}
2316
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002317/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002318 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2319 * @scmnd: SCSI command to send the task management command for
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002320 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002321 * Returns: on success pointer to struct fsf_req, NULL otherwise
2322 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002323struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2324 u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002325{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002326 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002327 struct fcp_cmnd *fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002328 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2329 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002330
Christof Schmittb62a8d92010-09-08 14:39:55 +02002331 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002332 ZFCP_STATUS_COMMON_UNBLOCKED)))
2333 return NULL;
2334
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002335 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002336 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002337 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002338
Swen Schillig564e1c82009-08-18 15:43:19 +02002339 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Jan Glauber3ec90872011-06-06 14:14:40 +02002340 SBAL_SFLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002341 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002342
Swen Schillig633528c2008-11-26 18:07:37 +01002343 if (IS_ERR(req)) {
2344 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002345 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002346 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002347
Christof Schmittb62a8d92010-09-08 14:39:55 +02002348 req->data = scmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002349 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002350 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2351 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002352 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2353 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002354 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002355
Christof Schmitt1674b402010-04-30 18:09:34 +02002356 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002357
Christof Schmitt4318e082009-11-24 16:54:08 +01002358 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002359 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002360
2361 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2362 if (!zfcp_fsf_req_send(req))
2363 goto out;
2364
2365 zfcp_fsf_req_free(req);
2366 req = NULL;
2367out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002368 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002369 return req;
2370}
2371
2372static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2373{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002374}
2375
2376/**
2377 * zfcp_fsf_control_file - control file upload/download
2378 * @adapter: pointer to struct zfcp_adapter
2379 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2380 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002382struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2383 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
Swen Schillig564e1c82009-08-18 15:43:19 +02002385 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002386 struct zfcp_fsf_req *req = NULL;
2387 struct fsf_qtcb_bottom_support *bottom;
Swen Schillig86a96682011-08-15 14:40:32 +02002388 int retval = -EIO;
Jan Glauber3ec90872011-06-06 14:14:40 +02002389 u8 direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Christof Schmitt45633fd2008-06-10 18:20:55 +02002391 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2392 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Christof Schmitt45633fd2008-06-10 18:20:55 +02002394 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Jan Glauber3ec90872011-06-06 14:14:40 +02002396 direction = SBAL_SFLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Jan Glauber3ec90872011-06-06 14:14:40 +02002399 direction = SBAL_SFLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002402 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 }
2404
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002405 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002406 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002407 goto out;
2408
Christof Schmitt1674b402010-04-30 18:09:34 +02002409 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002410 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002412 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 }
2414
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002415 req->handler = zfcp_fsf_control_file_handler;
2416
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002417 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002419 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Swen Schillig86a96682011-08-15 14:40:32 +02002421 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
Swen Schillig01b04752010-07-16 15:37:37 +02002422
Swen Schillig86a96682011-08-15 14:40:32 +02002423 if (retval ||
2424 (zfcp_qdio_real_bytes(fsf_cfdc->sg) != ZFCP_CFDC_MAX_SIZE)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002425 zfcp_fsf_req_free(req);
Swen Schillig86a96682011-08-15 14:40:32 +02002426 retval = -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002427 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002428 }
Swen Schillig86a96682011-08-15 14:40:32 +02002429 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2430 if (zfcp_adapter_multi_buffer_active(adapter))
2431 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002433 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2434 retval = zfcp_fsf_req_send(req);
2435out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002436 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002437
2438 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002439 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002440 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002442 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002444
2445/**
2446 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2447 * @adapter: pointer to struct zfcp_adapter
2448 * @sbal_idx: response queue index of SBAL to be processed
2449 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002450void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002451{
Swen Schillig564e1c82009-08-18 15:43:19 +02002452 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002453 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002454 struct qdio_buffer_element *sbale;
2455 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002456 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002457 int idx;
2458
2459 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2460
2461 sbale = &sbal->element[idx];
2462 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002463 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002464
Christof Schmitt339f4f42010-07-16 15:37:43 +02002465 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002466 /*
2467 * Unknown request means that we have potentially memory
2468 * corruption and must stop the machine immediately.
2469 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002470 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002471 panic("error: unknown req_id (%lx) on adapter %s.\n",
2472 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002473 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002474
Christof Schmitt34c2b712010-02-17 11:18:59 +01002475 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002476 zfcp_fsf_req_complete(fsf_req);
2477
Jan Glauber3ec90872011-06-06 14:14:40 +02002478 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002479 break;
2480 }
2481}
Swen Schilliga54ca0f2010-12-02 15:16:14 +01002482
2483struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
2484 struct qdio_buffer *sbal)
2485{
2486 struct qdio_buffer_element *sbale = &sbal->element[0];
2487 u64 req_id = (unsigned long) sbale->addr;
2488
2489 return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
2490}