blob: 0bb40c9dbd0c9e842ea314bdadb84996f9260723 [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_INCOMING_ELS)
Steffen Maier43f60cb2012-09-04 15:23:35 +0200258 zfcp_fc_conditional_port_scan(adapter);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100259 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200260 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200261 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200262 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200264
Christof Schmittc7b279a2011-02-22 19:54:40 +0100265 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200266 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200267
268 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200269 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200272static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200274 switch (req->qtcb->header.fsf_status_qual.word[0]) {
275 case FSF_SQ_FCP_RSP_AVAILABLE:
276 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
277 case FSF_SQ_NO_RETRY_POSSIBLE:
278 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
279 return;
280 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200281 break;
282 case FSF_SQ_NO_RECOM:
283 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200284 "The FCP adapter reported a problem "
285 "that cannot be recovered\n");
Christof Schmitt339f4f42010-07-16 15:37:43 +0200286 zfcp_qdio_siosl(req->adapter);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100287 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200288 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200290 /* all non-return stats set FSFREQ_ERROR*/
291 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
292}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200294static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
295{
296 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
297 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200298
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200299 switch (req->qtcb->header.fsf_status) {
300 case FSF_UNKNOWN_COMMAND:
301 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200302 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200303 req->qtcb->header.fsf_command);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100304 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200305 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200308 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200313static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200315 struct zfcp_adapter *adapter = req->adapter;
316 struct fsf_qtcb *qtcb = req->qtcb;
317 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Swen Schillig57717102009-08-18 15:43:21 +0200319 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200321 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100322 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200323 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
325
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200326 switch (qtcb->prefix.prot_status) {
327 case FSF_PROT_GOOD:
328 case FSF_PROT_FSF_STATUS_PRESENTED:
329 return;
330 case FSF_PROT_QTCB_VERSION_ERROR:
331 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200332 "QTCB version 0x%x not supported by FCP adapter "
333 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
334 psq->word[0], psq->word[1]);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100335 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200337 case FSF_PROT_ERROR_STATE:
338 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100339 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100340 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200342 case FSF_PROT_UNSUPP_QTCB_TYPE:
343 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200344 "The QTCB type is not supported by the FCP adapter\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100345 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200347 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
348 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
349 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200351 case FSF_PROT_DUPLICATE_REQUEST_ID:
352 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200353 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200354 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100355 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200357 case FSF_PROT_LINK_DOWN:
Swen Schilligedaed852010-09-08 14:40:01 +0200358 zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100359 /* go through reopen to flush pending requests */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100360 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200362 case FSF_PROT_REEST_QUEUE:
363 /* All ports should be marked as ready to run again */
Swen Schilligedaed852010-09-08 14:40:01 +0200364 zfcp_erp_set_adapter_status(adapter,
365 ZFCP_STATUS_COMMON_RUNNING);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200366 zfcp_erp_adapter_reopen(adapter,
367 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100368 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100369 "fspse_8");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200370 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200372 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200373 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200374 qtcb->prefix.prot_status);
Christof Schmitt339f4f42010-07-16 15:37:43 +0200375 zfcp_qdio_siosl(adapter);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100376 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200378 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
381/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200382 * zfcp_fsf_req_complete - process completion of a FSF request
383 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200385 * When a request has been completed either from the FCP adapter,
386 * or it has been dismissed due to a queue shutdown, this function
387 * is called to process the completion status and trigger further
388 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200390static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200391{
392 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
393 zfcp_fsf_status_read_handler(req);
394 return;
395 }
396
397 del_timer(&req->timer);
398 zfcp_fsf_protstatus_eval(req);
399 zfcp_fsf_fsfstatus_eval(req);
400 req->handler(req);
401
402 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200403 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200404
405 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
406 zfcp_fsf_req_free(req);
407 else
Swen Schillig058b8642009-08-18 15:43:14 +0200408 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200409}
410
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200411/**
412 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
413 * @adapter: pointer to struct zfcp_adapter
414 *
415 * Never ever call this without shutting down the adapter first.
416 * Otherwise the adapter would continue using and corrupting s390 storage.
417 * Included BUG_ON() call to ensure this is done.
418 * ERP is supposed to be the only user of this function.
419 */
420void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
421{
422 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200423 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200424
425 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100426 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200427
428 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
429 list_del(&req->list);
430 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
431 zfcp_fsf_req_complete(req);
432 }
433}
434
Steffen Maierd2201972012-09-04 15:23:29 +0200435#define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
436#define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
437#define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
438#define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
439#define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
440#define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
441#define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
442
443static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
444{
445 u32 fdmi_speed = 0;
446 if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
447 fdmi_speed |= FC_PORTSPEED_1GBIT;
448 if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
449 fdmi_speed |= FC_PORTSPEED_2GBIT;
450 if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
451 fdmi_speed |= FC_PORTSPEED_4GBIT;
452 if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
453 fdmi_speed |= FC_PORTSPEED_10GBIT;
454 if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
455 fdmi_speed |= FC_PORTSPEED_8GBIT;
456 if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
457 fdmi_speed |= FC_PORTSPEED_16GBIT;
458 if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
459 fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
460 return fdmi_speed;
461}
462
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200463static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100465 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200466 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200467 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100468 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100470 /* adjust pointers for missing command code */
471 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
472 - sizeof(u32));
473 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
474 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200475
476 if (req->data)
477 memcpy(req->data, bottom, sizeof(*bottom));
478
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100479 fc_host_port_name(shost) = nsp->fl_wwpn;
480 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100481 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Steffen Maierd2201972012-09-04 15:23:29 +0200482 fc_host_speed(shost) =
483 zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200484 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
485
486 adapter->hydra_version = bottom->adapter_type;
Christof Schmittfaf4cd82010-07-16 15:37:36 +0200487 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200488 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
489 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200490
491 if (fc_host_permanent_port_name(shost) == -1)
492 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
493
494 switch (bottom->fc_topology) {
495 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100496 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100497 adapter->peer_wwpn = plogi->fl_wwpn;
498 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200499 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200500 break;
501 case FSF_TOPO_FABRIC:
502 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200503 break;
504 case FSF_TOPO_AL:
505 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200506 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200507 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200508 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200509 "Unknown or unsupported arbitrated loop "
510 "fibre channel topology detected\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100511 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200512 return -EIO;
513 }
514
Felix Beckef3eb712010-07-16 15:37:42 +0200515 zfcp_scsi_set_prot(adapter);
516
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 return 0;
518}
519
520static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
521{
522 struct zfcp_adapter *adapter = req->adapter;
523 struct fsf_qtcb *qtcb = req->qtcb;
524 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
525 struct Scsi_Host *shost = adapter->scsi_host;
526
527 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
528 return;
529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200531 adapter->adapter_features = bottom->adapter_features;
532 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500533 adapter->peer_wwpn = 0;
534 adapter->peer_wwnn = 0;
535 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200537 switch (qtcb->header.fsf_status) {
538 case FSF_GOOD:
539 if (zfcp_fsf_exchange_config_evaluate(req))
540 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200541
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200542 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
543 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200544 "FCP adapter maximum QTCB size (%d bytes) "
545 "is too small\n",
546 bottom->max_qtcb_size);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100547 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200548 return;
549 }
550 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
551 &adapter->status);
552 break;
553 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200554 fc_host_node_name(shost) = 0;
555 fc_host_port_name(shost) = 0;
556 fc_host_port_id(shost) = 0;
557 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100558 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200560
Daniel Hanself76ccaa2013-04-26 17:32:14 +0200561 /* avoids adapter shutdown to be able to recognize
562 * events such as LINK UP */
563 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
564 &adapter->status);
Swen Schilligedaed852010-09-08 14:40:01 +0200565 zfcp_fsf_link_down_info_eval(req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200566 &qtcb->header.fsf_status_qual.link_down_info);
567 break;
568 default:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100569 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200570 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
572
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200573 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200575 memcpy(fc_host_serial_number(shost), bottom->serial_number,
576 min(FC_SERIAL_NUMBER_SIZE, 17));
577 EBCASC(fc_host_serial_number(shost),
578 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200581 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200582 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200583 "The FCP adapter only supports newer "
584 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100585 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200586 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200588 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200589 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200590 "The FCP adapter only supports older "
591 "control block versions\n");
Swen Schilligea4a3a62010-12-02 15:16:16 +0100592 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200596static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200598 struct zfcp_adapter *adapter = req->adapter;
599 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
600 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200602 if (req->data)
603 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100604
Christof Schmitt02829852009-03-02 13:09:06 +0100605 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100606 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100607 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
608 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100609 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
610 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
Steffen Maierd2201972012-09-04 15:23:29 +0200611 fc_host_supported_speeds(shost) =
612 zfcp_fsf_convert_portspeed(bottom->supported_speed);
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100613 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
614 FC_FC4_LIST_SIZE);
615 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
616 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100617}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200619static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200621 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100622
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200623 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return;
625
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200626 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200627 case FSF_GOOD:
628 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200629 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200630 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200631 zfcp_fsf_exchange_port_evaluate(req);
Swen Schilligedaed852010-09-08 14:40:01 +0200632 zfcp_fsf_link_down_info_eval(req,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200633 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200634 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636}
637
Swen Schilliga4623c42009-08-18 15:43:15 +0200638static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200639{
640 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200641
642 if (likely(pool))
643 req = mempool_alloc(pool, GFP_ATOMIC);
644 else
645 req = kmalloc(sizeof(*req), GFP_ATOMIC);
646
647 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200648 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200649
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200650 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100651 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200652 return req;
653}
654
Swen Schilliga4623c42009-08-18 15:43:15 +0200655static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200656{
Swen Schilliga4623c42009-08-18 15:43:15 +0200657 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658
659 if (likely(pool))
660 qtcb = mempool_alloc(pool, GFP_ATOMIC);
661 else
Christof Schmitt259afe22011-02-22 19:54:44 +0100662 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
Swen Schilliga4623c42009-08-18 15:43:15 +0200663
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200664 if (unlikely(!qtcb))
665 return NULL;
666
667 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200668 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200669}
670
Swen Schillig564e1c82009-08-18 15:43:19 +0200671static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Jan Glauber3ec90872011-06-06 14:14:40 +0200672 u32 fsf_cmd, u8 sbtype,
Christof Schmitt1674b402010-04-30 18:09:34 +0200673 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
Swen Schillig564e1c82009-08-18 15:43:19 +0200675 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200676 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200677
678 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200679 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200680
681 if (adapter->req_no == 0)
682 adapter->req_no++;
683
684 INIT_LIST_HEAD(&req->list);
685 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200686 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200687
688 req->adapter = adapter;
689 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100690 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200691
Swen Schilliga4623c42009-08-18 15:43:15 +0200692 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
693 if (likely(pool))
694 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
695 else
696 req->qtcb = zfcp_qtcb_alloc(NULL);
697
698 if (unlikely(!req->qtcb)) {
699 zfcp_fsf_req_free(req);
700 return ERR_PTR(-ENOMEM);
701 }
702
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100703 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200704 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200705 req->qtcb->prefix.req_id = req->req_id;
706 req->qtcb->prefix.ulp_info = 26;
707 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
708 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
709 req->qtcb->header.req_handle = req->req_id;
710 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200711 }
712
Christof Schmitt1674b402010-04-30 18:09:34 +0200713 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
714 req->qtcb, sizeof(struct fsf_qtcb));
715
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200716 return req;
717}
718
719static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
720{
721 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200722 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100723 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100724 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200725
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100726 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200727
Swen Schillig706eca42010-07-16 15:37:38 +0200728 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Heiko Carstens1aae0562013-01-30 09:49:40 +0100729 req->issued = get_tod_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100730 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200731 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100732 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100733 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100734 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200735 return -EIO;
736 }
737
738 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200739 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200740 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100741 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200742
743 return 0;
744}
745
746/**
747 * zfcp_fsf_status_read - send status read request
748 * @adapter: pointer to struct zfcp_adapter
749 * @req_flags: request flags
750 * Returns: 0 on success, ERROR otherwise
751 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200752int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200753{
Swen Schillig564e1c82009-08-18 15:43:19 +0200754 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200755 struct zfcp_fsf_req *req;
756 struct fsf_status_read_buffer *sr_buf;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100757 struct page *page;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200758 int retval = -EIO;
759
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200760 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200761 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Christof Schmitt1674b402010-04-30 18:09:34 +0200764 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200765 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200766 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200767 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 goto out;
769 }
770
Christof Schmittc7b279a2011-02-22 19:54:40 +0100771 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
772 if (!page) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200773 retval = -ENOMEM;
774 goto failed_buf;
775 }
Christof Schmittc7b279a2011-02-22 19:54:40 +0100776 sr_buf = page_address(page);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200777 memset(sr_buf, 0, sizeof(*sr_buf));
778 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200779
780 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
781 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200782
783 retval = zfcp_fsf_req_send(req);
784 if (retval)
785 goto failed_req_send;
786
787 goto out;
788
789failed_req_send:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100790 req->data = NULL;
Christof Schmittc7b279a2011-02-22 19:54:40 +0100791 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200792failed_buf:
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100793 zfcp_dbf_hba_fsf_uss("fssr__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200794 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200795out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200796 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 return retval;
798}
799
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200800static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200802 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +0200803 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200804 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200806 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
807 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Martin Peschked436de82012-09-04 15:23:36 +0200809 zfcp_sdev = sdev_to_zfcp(sdev);
810
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200811 switch (req->qtcb->header.fsf_status) {
812 case FSF_PORT_HANDLE_NOT_VALID:
813 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200814 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100815 "fsafch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200816 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200819 case FSF_LUN_HANDLE_NOT_VALID:
820 if (fsq->word[0] == fsq->word[1]) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100821 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200822 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200825 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
826 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200828 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200829 zfcp_erp_set_port_status(zfcp_sdev->port,
830 ZFCP_STATUS_COMMON_ACCESS_BOXED);
831 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100832 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100833 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200834 break;
835 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +0200836 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
837 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +0100838 "fsafch4");
Christof Schmitt4c571c62009-11-24 16:54:15 +0100839 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200840 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200842 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200844 zfcp_fc_test_link(zfcp_sdev->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200845 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200847 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 break;
849 }
850 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200852 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
853 break;
854 }
855}
856
857/**
Christof Schmittb62a8d92010-09-08 14:39:55 +0200858 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
859 * @scmnd: The SCSI command to abort
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200860 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 */
862
Christof Schmittb62a8d92010-09-08 14:39:55 +0200863struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200864{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865 struct zfcp_fsf_req *req = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200866 struct scsi_device *sdev = scmnd->device;
867 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
868 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
869 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200871 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200872 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200873 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200874 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Jan Glauber3ec90872011-06-06 14:14:40 +0200875 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200876 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100877 if (IS_ERR(req)) {
878 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200879 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100880 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200881
Christof Schmittb62a8d92010-09-08 14:39:55 +0200882 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200883 ZFCP_STATUS_COMMON_UNBLOCKED)))
884 goto out_error_free;
885
Christof Schmitt1674b402010-04-30 18:09:34 +0200886 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200887
Swen Schillig6fbf25e2010-11-17 14:23:41 +0100888 req->data = sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200889 req->handler = zfcp_fsf_abort_fcp_command_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200890 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
891 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200892 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
893
894 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
895 if (!zfcp_fsf_req_send(req))
896 goto out;
897
898out_error_free:
899 zfcp_fsf_req_free(req);
900 req = NULL;
901out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200902 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200903 return req;
904}
905
906static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
907{
908 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100909 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200910 struct fsf_qtcb_header *header = &req->qtcb->header;
911
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100912 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200913
914 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
915 goto skip_fsfstatus;
916
917 switch (header->fsf_status) {
918 case FSF_GOOD:
Steffen Maier01009982012-09-04 15:23:30 +0200919 zfcp_dbf_san_res("fsscth2", req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100920 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200921 break;
922 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
923 zfcp_fsf_class_not_supp(req);
924 break;
925 case FSF_ADAPTER_STATUS_AVAILABLE:
926 switch (header->fsf_status_qual.word[0]){
927 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200928 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
929 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
930 break;
931 }
932 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200933 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100934 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200935 break;
936 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100937 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
Christof Schmittdceab652009-05-15 13:18:18 +0200938 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200939 case FSF_GENERIC_COMMAND_REJECTED:
940 case FSF_PAYLOAD_SIZE_MISMATCH:
941 case FSF_REQUEST_SIZE_TOO_LARGE:
942 case FSF_RESPONSE_SIZE_TOO_LARGE:
943 case FSF_SBAL_MISMATCH:
944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
945 break;
946 }
947
948skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100949 if (ct->handler)
950 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200951}
952
Christof Schmitt1674b402010-04-30 18:09:34 +0200953static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
954 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200955 struct scatterlist *sg_req,
956 struct scatterlist *sg_resp)
957{
Christof Schmitt1674b402010-04-30 18:09:34 +0200958 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
959 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
960 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200961}
962
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100963static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
964 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200965 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200966{
Swen Schillig42428f72009-08-18 15:43:18 +0200967 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig86a96682011-08-15 14:40:32 +0200968 struct zfcp_qdio *qdio = adapter->qdio;
969 struct fsf_qtcb *qtcb = req->qtcb;
Swen Schillig42428f72009-08-18 15:43:18 +0200970 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200971
Swen Schillig86a96682011-08-15 14:40:32 +0200972 if (zfcp_adapter_multi_buffer_active(adapter)) {
973 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
974 return -EIO;
975 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
976 return -EIO;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100977
Swen Schillig86a96682011-08-15 14:40:32 +0200978 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
979 zfcp_qdio_sbale_count(sg_req));
980 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
981 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200982 return 0;
983 }
984
985 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200986 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Swen Schillig86a96682011-08-15 14:40:32 +0200987 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +0200988 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100989 return 0;
990 }
991
Swen Schillig86a96682011-08-15 14:40:32 +0200992 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
993 return -EOPNOTSUPP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200994
Swen Schillig86a96682011-08-15 14:40:32 +0200995 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
Christof Schmitt9072df42009-07-13 15:06:07 +0200996 return -EIO;
Swen Schillig86a96682011-08-15 14:40:32 +0200997
998 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
999
1000 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1001 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1002
1003 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1004 return -EIO;
1005
1006 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1007
1008 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001009
Christof Schmittb1a58982009-09-24 10:23:21 +02001010 return 0;
1011}
1012
1013static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1014 struct scatterlist *sg_req,
1015 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001016 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001017{
1018 int ret;
1019
Swen Schillig01b04752010-07-16 15:37:37 +02001020 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001021 if (ret)
1022 return ret;
1023
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001024 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001025 if (timeout > 255)
1026 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001027 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001028 req->qtcb->bottom.support.timeout = timeout;
1029 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001030
1031 return 0;
1032}
1033
1034/**
1035 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1036 * @ct: pointer to struct zfcp_send_ct with data for request
1037 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001038 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001039int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001040 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1041 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001042{
Swen Schillig564e1c82009-08-18 15:43:19 +02001043 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001044 struct zfcp_fsf_req *req;
1045 int ret = -EIO;
1046
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001047 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001048 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001049 goto out;
1050
Christof Schmitt1674b402010-04-30 18:09:34 +02001051 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
Jan Glauber3ec90872011-06-06 14:14:40 +02001052 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001053
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001054 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001055 ret = PTR_ERR(req);
1056 goto out;
1057 }
1058
Swen Schillig09a46c62009-08-18 15:43:16 +02001059 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001060 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001061 if (ret)
1062 goto failed_send;
1063
1064 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001065 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001066 req->data = ct;
1067
Swen Schillig2c55b752010-12-02 15:16:13 +01001068 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001069
1070 ret = zfcp_fsf_req_send(req);
1071 if (ret)
1072 goto failed_send;
1073
1074 goto out;
1075
1076failed_send:
1077 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001078out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001079 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001080 return ret;
1081}
1082
1083static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1084{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001085 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001086 struct fsf_qtcb_header *header = &req->qtcb->header;
1087
1088 send_els->status = -EINVAL;
1089
1090 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1091 goto skip_fsfstatus;
1092
1093 switch (header->fsf_status) {
1094 case FSF_GOOD:
Swen Schillig2c55b752010-12-02 15:16:13 +01001095 zfcp_dbf_san_res("fsselh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001096 send_els->status = 0;
1097 break;
1098 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1099 zfcp_fsf_class_not_supp(req);
1100 break;
1101 case FSF_ADAPTER_STATUS_AVAILABLE:
1102 switch (header->fsf_status_qual.word[0]){
1103 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001104 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1105 case FSF_SQ_RETRY_IF_POSSIBLE:
1106 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1107 break;
1108 }
1109 break;
1110 case FSF_ELS_COMMAND_REJECTED:
1111 case FSF_PAYLOAD_SIZE_MISMATCH:
1112 case FSF_REQUEST_SIZE_TOO_LARGE:
1113 case FSF_RESPONSE_SIZE_TOO_LARGE:
1114 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001115 case FSF_SBAL_MISMATCH:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001116 /* should never occur, avoided in zfcp_fsf_send_els */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001117 /* fall through */
1118 default:
1119 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1120 break;
1121 }
1122skip_fsfstatus:
1123 if (send_els->handler)
1124 send_els->handler(send_els->handler_data);
1125}
1126
1127/**
1128 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1129 * @els: pointer to struct zfcp_send_els with data for the command
1130 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001131int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001132 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001133{
1134 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001135 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001136 int ret = -EIO;
1137
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001138 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001139 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001140 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001141
Christof Schmitt1674b402010-04-30 18:09:34 +02001142 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
Jan Glauber3ec90872011-06-06 14:14:40 +02001143 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001144
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001145 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001146 ret = PTR_ERR(req);
1147 goto out;
1148 }
1149
Swen Schillig09a46c62009-08-18 15:43:16 +02001150 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001151
Swen Schillig86a96682011-08-15 14:40:32 +02001152 if (!zfcp_adapter_multi_buffer_active(adapter))
1153 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
Swen Schillig01b04752010-07-16 15:37:37 +02001154
1155 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001156
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001157 if (ret)
1158 goto failed_send;
1159
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001160 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001161 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001162 req->data = els;
1163
Swen Schillig2c55b752010-12-02 15:16:13 +01001164 zfcp_dbf_san_req("fssels1", req, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001165
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001166 ret = zfcp_fsf_req_send(req);
1167 if (ret)
1168 goto failed_send;
1169
1170 goto out;
1171
1172failed_send:
1173 zfcp_fsf_req_free(req);
1174out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001175 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001176 return ret;
1177}
1178
1179int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1180{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001181 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001182 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001183 int retval = -EIO;
1184
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001185 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001186 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001187 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001188
Swen Schillig564e1c82009-08-18 15:43:19 +02001189 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001190 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001191 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001192
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001193 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001194 retval = PTR_ERR(req);
1195 goto out;
1196 }
1197
Swen Schillig09a46c62009-08-18 15:43:16 +02001198 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001199 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001200
1201 req->qtcb->bottom.config.feature_selection =
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001202 FSF_FEATURE_NOTIFICATION_LOST |
1203 FSF_FEATURE_UPDATE_ALERT;
1204 req->erp_action = erp_action;
1205 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001206 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001207
Christof Schmitt287ac012008-07-02 10:56:40 +02001208 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001209 retval = zfcp_fsf_req_send(req);
1210 if (retval) {
1211 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001212 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001213 }
1214out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001215 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001216 return retval;
1217}
1218
Swen Schillig564e1c82009-08-18 15:43:19 +02001219int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001220 struct fsf_qtcb_bottom_config *data)
1221{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001222 struct zfcp_fsf_req *req = NULL;
1223 int retval = -EIO;
1224
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001225 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001226 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001227 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001228
Christof Schmitt1674b402010-04-30 18:09:34 +02001229 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001230 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001231
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001232 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001233 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001234 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001235 }
1236
Christof Schmitt1674b402010-04-30 18:09:34 +02001237 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 req->handler = zfcp_fsf_exchange_config_data_handler;
1239
1240 req->qtcb->bottom.config.feature_selection =
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001241 FSF_FEATURE_NOTIFICATION_LOST |
1242 FSF_FEATURE_UPDATE_ALERT;
1243
1244 if (data)
1245 req->data = data;
1246
1247 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1248 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001249 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001250 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001251 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001252
1253 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001254 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001255
Christof Schmittada81b72009-04-17 15:08:03 +02001256out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001257 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001258 return retval;
1259}
1260
1261/**
1262 * zfcp_fsf_exchange_port_data - request information about local port
1263 * @erp_action: ERP action for the adapter for which port data is requested
1264 * Returns: 0 on success, error otherwise
1265 */
1266int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1267{
Swen Schillig564e1c82009-08-18 15:43:19 +02001268 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001269 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001270 int retval = -EIO;
1271
Swen Schillig564e1c82009-08-18 15:43:19 +02001272 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001273 return -EOPNOTSUPP;
1274
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001275 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001276 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001277 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001278
Swen Schillig564e1c82009-08-18 15:43:19 +02001279 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001280 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001281 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001282
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001283 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001284 retval = PTR_ERR(req);
1285 goto out;
1286 }
1287
Swen Schillig09a46c62009-08-18 15:43:16 +02001288 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001289 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001290
1291 req->handler = zfcp_fsf_exchange_port_data_handler;
1292 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001293 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001294
Christof Schmitt287ac012008-07-02 10:56:40 +02001295 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001296 retval = zfcp_fsf_req_send(req);
1297 if (retval) {
1298 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001299 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001300 }
1301out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001302 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001303 return retval;
1304}
1305
1306/**
1307 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001308 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001309 * @data: pointer to struct fsf_qtcb_bottom_port
1310 * Returns: 0 on success, error otherwise
1311 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001312int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001313 struct fsf_qtcb_bottom_port *data)
1314{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001315 struct zfcp_fsf_req *req = NULL;
1316 int retval = -EIO;
1317
Swen Schillig564e1c82009-08-18 15:43:19 +02001318 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001319 return -EOPNOTSUPP;
1320
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001321 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001322 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001323 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001324
Christof Schmitt1674b402010-04-30 18:09:34 +02001325 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Jan Glauber3ec90872011-06-06 14:14:40 +02001326 SBAL_SFLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001327
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001328 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001330 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001331 }
1332
1333 if (data)
1334 req->data = data;
1335
Christof Schmitt1674b402010-04-30 18:09:34 +02001336 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001337
1338 req->handler = zfcp_fsf_exchange_port_data_handler;
1339 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1340 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001341 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001342
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001343 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001344 wait_for_completion(&req->completion);
1345
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001346 zfcp_fsf_req_free(req);
1347
1348 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001349
1350out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001351 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001352 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001353}
1354
1355static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1356{
1357 struct zfcp_port *port = req->data;
1358 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001359 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001360
1361 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001362 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001363
1364 switch (header->fsf_status) {
1365 case FSF_PORT_ALREADY_OPEN:
1366 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001367 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1368 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001369 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001370 "remote port 0x%016Lx\n",
1371 (unsigned long long)port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001372 zfcp_erp_set_port_status(port,
1373 ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001374 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1375 break;
1376 case FSF_ADAPTER_STATUS_AVAILABLE:
1377 switch (header->fsf_status_qual.word[0]) {
1378 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1379 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001380 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001381 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1382 break;
1383 }
1384 break;
1385 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1388 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001389 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1390 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1391 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 /* check whether D_ID has changed during open */
1393 /*
1394 * FIXME: This check is not airtight, as the FCP channel does
1395 * not monitor closures of target port connections caused on
1396 * the remote side. Thus, they might miss out on invalidating
1397 * locally cached WWPNs (and other N_Port parameters) of gone
1398 * target ports. So, our heroic attempt to make things safe
1399 * could be undermined by 'open port' response data tagged with
1400 * obsolete WWPNs. Another reason to monitor potential
1401 * connection closures ourself at least (by interpreting
1402 * incoming ELS' and unsolicited status). It just crosses my
1403 * mind that one should be able to cross-check by means of
1404 * another GID_PN straight after a port has been opened.
1405 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1406 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001407 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001408 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001409 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001410 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001413 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 break;
1415 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001416
1417out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001418 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419}
1420
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001421/**
1422 * zfcp_fsf_open_port - create and send open port request
1423 * @erp_action: pointer to struct zfcp_erp_action
1424 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001426int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Swen Schillig564e1c82009-08-18 15:43:19 +02001428 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001429 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001430 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001431 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001433 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001434 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Swen Schillig564e1c82009-08-18 15:43:19 +02001437 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec90872011-06-06 14:14:40 +02001438 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001439 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001440
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001441 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001442 retval = PTR_ERR(req);
1443 goto out;
1444 }
1445
Swen Schillig09a46c62009-08-18 15:43:16 +02001446 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001447 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001449 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001450 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001451 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001452 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001453 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001454 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Christof Schmitt287ac012008-07-02 10:56:40 +02001456 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001457 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001459 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001460 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001461 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001463out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001464 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 return retval;
1466}
1467
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001468static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001470 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001472 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001473 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001477 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001478 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 case FSF_GOOD:
Swen Schilligedaed852010-09-08 14:40:01 +02001483 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486}
1487
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001488/**
1489 * zfcp_fsf_close_port - create and send close port request
1490 * @erp_action: pointer to struct zfcp_erp_action
1491 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001493int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Swen Schillig564e1c82009-08-18 15:43:19 +02001495 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001496 struct zfcp_fsf_req *req;
1497 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001499 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001500 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Swen Schillig564e1c82009-08-18 15:43:19 +02001503 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001504 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001505 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001506
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001507 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001508 retval = PTR_ERR(req);
1509 goto out;
1510 }
1511
Swen Schillig09a46c62009-08-18 15:43:16 +02001512 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001513 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001515 req->handler = zfcp_fsf_close_port_handler;
1516 req->data = erp_action->port;
1517 req->erp_action = erp_action;
1518 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001519 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Christof Schmitt287ac012008-07-02 10:56:40 +02001521 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001522 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001525 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001527out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001528 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 return retval;
1530}
1531
Swen Schillig5ab944f2008-10-01 12:42:17 +02001532static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1533{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001534 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001535 struct fsf_qtcb_header *header = &req->qtcb->header;
1536
1537 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001538 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001539 goto out;
1540 }
1541
1542 switch (header->fsf_status) {
1543 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1544 dev_warn(&req->adapter->ccw_device->dev,
1545 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001546 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001547 case FSF_ADAPTER_STATUS_AVAILABLE:
1548 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittbd0072e2009-11-24 16:54:11 +01001549 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001550 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001551 case FSF_GOOD:
1552 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001553 /* fall through */
1554 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001555 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001556 }
1557out:
1558 wake_up(&wka_port->completion_wq);
1559}
1560
1561/**
1562 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001563 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001564 * Returns: 0 on success, error otherwise
1565 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001566int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001567{
Swen Schillig564e1c82009-08-18 15:43:19 +02001568 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001569 struct zfcp_fsf_req *req;
1570 int retval = -EIO;
1571
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001572 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001573 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001574 goto out;
1575
Swen Schillig564e1c82009-08-18 15:43:19 +02001576 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Jan Glauber3ec90872011-06-06 14:14:40 +02001577 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001578 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001579
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001580 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001581 retval = PTR_ERR(req);
1582 goto out;
1583 }
1584
Swen Schillig09a46c62009-08-18 15:43:16 +02001585 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001586 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001587
1588 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001589 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001590 req->data = wka_port;
1591
1592 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1593 retval = zfcp_fsf_req_send(req);
1594 if (retval)
1595 zfcp_fsf_req_free(req);
1596out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001597 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001598 return retval;
1599}
1600
1601static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1602{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001603 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001604
1605 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1606 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligea4a3a62010-12-02 15:16:16 +01001607 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
Swen Schillig5ab944f2008-10-01 12:42:17 +02001608 }
1609
Christof Schmittbd0072e2009-11-24 16:54:11 +01001610 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001611 wake_up(&wka_port->completion_wq);
1612}
1613
1614/**
1615 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001616 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001617 * Returns: 0 on success, error otherwise
1618 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001619int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001620{
Swen Schillig564e1c82009-08-18 15:43:19 +02001621 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001622 struct zfcp_fsf_req *req;
1623 int retval = -EIO;
1624
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001625 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001626 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001627 goto out;
1628
Swen Schillig564e1c82009-08-18 15:43:19 +02001629 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001630 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001631 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001632
Tobias Klauser4e7d7af2011-02-22 19:54:38 +01001633 if (IS_ERR(req)) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001634 retval = PTR_ERR(req);
1635 goto out;
1636 }
1637
Swen Schillig09a46c62009-08-18 15:43:16 +02001638 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001639 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001640
1641 req->handler = zfcp_fsf_close_wka_port_handler;
1642 req->data = wka_port;
1643 req->qtcb->header.port_handle = wka_port->handle;
1644
1645 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1646 retval = zfcp_fsf_req_send(req);
1647 if (retval)
1648 zfcp_fsf_req_free(req);
1649out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001650 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001651 return retval;
1652}
1653
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001654static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001656 struct zfcp_port *port = req->data;
1657 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001658 struct scsi_device *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001660 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001661 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001665 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001666 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001669 /* can't use generic zfcp_erp_modify_port_status because
1670 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1671 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001672 shost_for_each_device(sdev, port->adapter->scsi_host)
1673 if (sdev_to_zfcp(sdev)->port == port)
1674 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1675 &sdev_to_zfcp(sdev)->status);
Swen Schilligedaed852010-09-08 14:40:01 +02001676 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
1677 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001678 "fscpph2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001679 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 switch (header->fsf_status_qual.word[0]) {
1683 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001684 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001686 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 }
1689 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 /* can't use generic zfcp_erp_modify_port_status because
1692 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1693 */
1694 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001695 shost_for_each_device(sdev, port->adapter->scsi_host)
1696 if (sdev_to_zfcp(sdev)->port == port)
1697 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1698 &sdev_to_zfcp(sdev)->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001703/**
1704 * zfcp_fsf_close_physical_port - close physical port
1705 * @erp_action: pointer to struct zfcp_erp_action
1706 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001708int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
Swen Schillig564e1c82009-08-18 15:43:19 +02001710 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001711 struct zfcp_fsf_req *req;
1712 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001714 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001715 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Swen Schillig564e1c82009-08-18 15:43:19 +02001718 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Jan Glauber3ec90872011-06-06 14:14:40 +02001719 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001720 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001721
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001722 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001723 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 goto out;
1725 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001726
Swen Schillig09a46c62009-08-18 15:43:16 +02001727 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001728 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001729
1730 req->data = erp_action->port;
1731 req->qtcb->header.port_handle = erp_action->port->handle;
1732 req->erp_action = erp_action;
1733 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001734 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001735
Christof Schmitt287ac012008-07-02 10:56:40 +02001736 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001737 retval = zfcp_fsf_req_send(req);
1738 if (retval) {
1739 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001740 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001741 }
1742out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001743 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 return retval;
1745}
1746
Christof Schmittb62a8d92010-09-08 14:39:55 +02001747static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001749 struct zfcp_adapter *adapter = req->adapter;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001750 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001751 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001752 struct fsf_qtcb_header *header = &req->qtcb->header;
Martin Peschke663e0892013-04-26 16:13:54 +02001753 union fsf_status_qual *qual = &header->fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001755 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001756 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Martin Peschked436de82012-09-04 15:23:36 +02001758 zfcp_sdev = sdev_to_zfcp(sdev);
1759
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Martin Peschke663e0892013-04-26 16:13:54 +02001761 ZFCP_STATUS_COMMON_ACCESS_BOXED,
Christof Schmittb62a8d92010-09-08 14:39:55 +02001762 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 switch (header->fsf_status) {
1765
1766 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001767 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001768 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001772 zfcp_erp_set_port_status(zfcp_sdev->port,
1773 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1774 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001775 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001776 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 case FSF_LUN_SHARING_VIOLATION:
Martin Peschke663e0892013-04-26 16:13:54 +02001779 if (qual->word[0])
1780 dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
1781 "LUN 0x%Lx on port 0x%Lx is already in "
1782 "use by CSS%d, MIF Image ID %x\n",
1783 zfcp_scsi_dev_lun(sdev),
1784 (unsigned long long)zfcp_sdev->port->wwpn,
1785 qual->fsf_queue_designator.cssid,
1786 qual->fsf_queue_designator.hla);
1787 zfcp_erp_set_lun_status(sdev,
1788 ZFCP_STATUS_COMMON_ERP_FAILED |
1789 ZFCP_STATUS_COMMON_ACCESS_DENIED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001790 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001793 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001794 "No handle is available for LUN "
1795 "0x%016Lx on port 0x%016Lx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001796 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1797 (unsigned long long)zfcp_sdev->port->wwpn);
Swen Schilligedaed852010-09-08 14:40:01 +02001798 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001799 /* fall through */
1800 case FSF_INVALID_COMMAND_OPTION:
1801 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 switch (header->fsf_status_qual.word[0]) {
1805 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001806 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001807 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001809 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 }
1812 break;
1813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001815 zfcp_sdev->lun_handle = header->lun_handle;
1816 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819}
1820
1821/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001822 * zfcp_fsf_open_lun - open LUN
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001823 * @erp_action: pointer to struct zfcp_erp_action
1824 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001826int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001828 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001829 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001830 struct zfcp_fsf_req *req;
1831 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001833 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001834 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001835 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Swen Schillig564e1c82009-08-18 15:43:19 +02001837 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Jan Glauber3ec90872011-06-06 14:14:40 +02001838 SBAL_SFLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001839 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001840
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001841 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001842 retval = PTR_ERR(req);
1843 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001844 }
1845
Swen Schillig09a46c62009-08-18 15:43:16 +02001846 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001847 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001849 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001850 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1851 req->handler = zfcp_fsf_open_lun_handler;
1852 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001853 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001854 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001855
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001856 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1857 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Christof Schmitt287ac012008-07-02 10:56:40 +02001859 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001860 retval = zfcp_fsf_req_send(req);
1861 if (retval) {
1862 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001863 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001865out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001866 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 return retval;
1868}
1869
Christof Schmittb62a8d92010-09-08 14:39:55 +02001870static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
Christof Schmittb62a8d92010-09-08 14:39:55 +02001872 struct scsi_device *sdev = req->data;
Martin Peschked436de82012-09-04 15:23:36 +02001873 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001874
1875 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001876 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001877
Martin Peschked436de82012-09-04 15:23:36 +02001878 zfcp_sdev = sdev_to_zfcp(sdev);
1879
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001880 switch (req->qtcb->header.fsf_status) {
1881 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001882 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001883 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1884 break;
1885 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01001886 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001887 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1888 break;
1889 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02001890 zfcp_erp_set_port_status(zfcp_sdev->port,
1891 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1892 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01001893 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
Christof Schmitt4c571c62009-11-24 16:54:15 +01001894 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001895 break;
1896 case FSF_ADAPTER_STATUS_AVAILABLE:
1897 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1898 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001899 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001900 /* fall through */
1901 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1902 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1903 break;
1904 }
1905 break;
1906 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001907 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001908 break;
1909 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001910}
1911
1912/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001913 * zfcp_fsf_close_LUN - close LUN
1914 * @erp_action: pointer to erp_action triggering the "close LUN"
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001915 * Returns: 0 on success, error otherwise
1916 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001917int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001918{
Swen Schillig564e1c82009-08-18 15:43:19 +02001919 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001920 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001921 struct zfcp_fsf_req *req;
1922 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001924 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001925 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001927
Swen Schillig564e1c82009-08-18 15:43:19 +02001928 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Jan Glauber3ec90872011-06-06 14:14:40 +02001929 SBAL_SFLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001930 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001931
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001932 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001933 retval = PTR_ERR(req);
1934 goto out;
1935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Swen Schillig09a46c62009-08-18 15:43:16 +02001937 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001938 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001940 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001941 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1942 req->handler = zfcp_fsf_close_lun_handler;
1943 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001944 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001945 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Christof Schmitt287ac012008-07-02 10:56:40 +02001947 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001948 retval = zfcp_fsf_req_send(req);
1949 if (retval) {
1950 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001951 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001952 }
1953out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001954 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001955 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
Christof Schmittc9615852008-05-06 11:00:05 +02001958static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1959{
1960 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001961 lat_rec->min = min(lat_rec->min, lat);
1962 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02001963}
1964
Christof Schmittd9742b42009-11-24 16:54:03 +01001965static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02001966{
Christof Schmittd9742b42009-11-24 16:54:03 +01001967 struct fsf_qual_latency_info *lat_in;
1968 struct latency_cont *lat = NULL;
Martin Peschked436de82012-09-04 15:23:36 +02001969 struct zfcp_scsi_dev *zfcp_sdev;
Christof Schmittd9742b42009-11-24 16:54:03 +01001970 struct zfcp_blk_drv_data blktrc;
1971 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02001972
Christof Schmittd9742b42009-11-24 16:54:03 +01001973 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02001974
Christof Schmittd9742b42009-11-24 16:54:03 +01001975 blktrc.flags = 0;
1976 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
1977 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1978 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02001979 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001980 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01001981
Christof Schmitt5bbf2972010-04-01 13:04:08 +02001982 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
1983 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Peschked436de82012-09-04 15:23:36 +02001984 zfcp_sdev = sdev_to_zfcp(scsi->device);
Christof Schmittd9742b42009-11-24 16:54:03 +01001985 blktrc.flags |= ZFCP_BLK_LAT_VALID;
1986 blktrc.channel_lat = lat_in->channel_lat * ticks;
1987 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
1988
1989 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02001990 case FSF_DATADIR_DIF_READ_STRIP:
1991 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01001992 case FSF_DATADIR_READ:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001993 lat = &zfcp_sdev->latencies.read;
Christof Schmittd9742b42009-11-24 16:54:03 +01001994 break;
Felix Beckef3eb712010-07-16 15:37:42 +02001995 case FSF_DATADIR_DIF_WRITE_INSERT:
1996 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01001997 case FSF_DATADIR_WRITE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001998 lat = &zfcp_sdev->latencies.write;
Christof Schmittd9742b42009-11-24 16:54:03 +01001999 break;
2000 case FSF_DATADIR_CMND:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002001 lat = &zfcp_sdev->latencies.cmd;
Christof Schmittd9742b42009-11-24 16:54:03 +01002002 break;
2003 }
2004
2005 if (lat) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02002006 spin_lock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002007 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2008 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2009 lat->counter++;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002010 spin_unlock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002011 }
Christof Schmittc9615852008-05-06 11:00:05 +02002012 }
2013
Christof Schmittd9742b42009-11-24 16:54:03 +01002014 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2015 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002016}
2017
Christof Schmittc61b5362010-09-08 14:39:58 +02002018static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002019{
Christof Schmittb62a8d92010-09-08 14:39:55 +02002020 struct scsi_cmnd *scmnd = req->data;
2021 struct scsi_device *sdev = scmnd->device;
Martin Peschked436de82012-09-04 15:23:36 +02002022 struct zfcp_scsi_dev *zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002023 struct fsf_qtcb_header *header = &req->qtcb->header;
2024
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002025 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
Christof Schmittc61b5362010-09-08 14:39:58 +02002026 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002027
Martin Peschked436de82012-09-04 15:23:36 +02002028 zfcp_sdev = sdev_to_zfcp(sdev);
2029
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002030 switch (header->fsf_status) {
2031 case FSF_HANDLE_MISMATCH:
2032 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002033 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002034 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2035 break;
2036 case FSF_FCPLUN_NOT_VALID:
2037 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schilligea4a3a62010-12-02 15:16:16 +01002038 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002039 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2040 break;
2041 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2042 zfcp_fsf_class_not_supp(req);
2043 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002044 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2045 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002046 "Incorrect direction %d, LUN 0x%016Lx on port "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002047 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002048 req->qtcb->bottom.io.data_direction,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002049 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2050 (unsigned long long)zfcp_sdev->port->wwpn);
2051 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002052 "fssfch3");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002053 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2054 break;
2055 case FSF_CMND_LENGTH_NOT_VALID:
2056 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002057 "Incorrect CDB length %d, LUN 0x%016Lx on "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002058 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002059 req->qtcb->bottom.io.fcp_cmnd_length,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002060 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2061 (unsigned long long)zfcp_sdev->port->wwpn);
2062 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002063 "fssfch4");
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002064 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2065 break;
2066 case FSF_PORT_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002067 zfcp_erp_set_port_status(zfcp_sdev->port,
2068 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2069 zfcp_erp_port_reopen(zfcp_sdev->port,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002070 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002071 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002072 break;
2073 case FSF_LUN_BOXED:
Swen Schilligedaed852010-09-08 14:40:01 +02002074 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2075 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schilligea4a3a62010-12-02 15:16:16 +01002076 "fssfch6");
Christof Schmitt4c571c62009-11-24 16:54:15 +01002077 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002078 break;
2079 case FSF_ADAPTER_STATUS_AVAILABLE:
2080 if (header->fsf_status_qual.word[0] ==
2081 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Christof Schmittb62a8d92010-09-08 14:39:55 +02002082 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002083 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2084 break;
2085 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002086}
2087
2088static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2089{
2090 struct scsi_cmnd *scpnt;
2091 struct fcp_resp_with_ext *fcp_rsp;
2092 unsigned long flags;
2093
Christof Schmittc61b5362010-09-08 14:39:58 +02002094 read_lock_irqsave(&req->adapter->abort_lock, flags);
2095
2096 scpnt = req->data;
2097 if (unlikely(!scpnt)) {
2098 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2099 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002100 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002101
Swen Schillig5bfb2c32010-11-17 14:23:40 +01002102 zfcp_fsf_fcp_handler_common(req);
2103
Christof Schmittc61b5362010-09-08 14:39:58 +02002104 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2105 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2106 goto skip_fsfstatus;
2107 }
2108
2109 switch (req->qtcb->header.fsf_status) {
2110 case FSF_INCONSISTENT_PROT_DATA:
2111 case FSF_INVALID_PROT_PARM:
2112 set_host_byte(scpnt, DID_ERROR);
2113 goto skip_fsfstatus;
2114 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2115 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2116 goto skip_fsfstatus;
2117 case FSF_APP_TAG_CHECK_FAILURE:
2118 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2119 goto skip_fsfstatus;
2120 case FSF_REF_TAG_CHECK_FAILURE:
2121 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2122 goto skip_fsfstatus;
2123 }
2124 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2125 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2126
2127skip_fsfstatus:
2128 zfcp_fsf_req_trace(req, scpnt);
Swen Schillig250a1352010-12-02 15:16:15 +01002129 zfcp_dbf_scsi_result(scpnt, req);
Christof Schmittc61b5362010-09-08 14:39:58 +02002130
2131 scpnt->host_scribble = NULL;
2132 (scpnt->scsi_done) (scpnt);
2133 /*
2134 * We must hold this lock until scsi_done has been called.
2135 * Otherwise we may call scsi_done after abort regarding this
2136 * command has completed.
2137 * Note: scsi_done must not block!
2138 */
2139 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002140}
2141
Felix Beckef3eb712010-07-16 15:37:42 +02002142static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2143{
2144 switch (scsi_get_prot_op(scsi_cmnd)) {
2145 case SCSI_PROT_NORMAL:
2146 switch (scsi_cmnd->sc_data_direction) {
2147 case DMA_NONE:
2148 *data_dir = FSF_DATADIR_CMND;
2149 break;
2150 case DMA_FROM_DEVICE:
2151 *data_dir = FSF_DATADIR_READ;
2152 break;
2153 case DMA_TO_DEVICE:
2154 *data_dir = FSF_DATADIR_WRITE;
2155 break;
2156 case DMA_BIDIRECTIONAL:
2157 return -EINVAL;
2158 }
2159 break;
2160
2161 case SCSI_PROT_READ_STRIP:
2162 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2163 break;
2164 case SCSI_PROT_WRITE_INSERT:
2165 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2166 break;
2167 case SCSI_PROT_READ_PASS:
2168 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2169 break;
2170 case SCSI_PROT_WRITE_PASS:
2171 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2172 break;
2173 default:
2174 return -EINVAL;
2175 }
2176
2177 return 0;
2178}
2179
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002180/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002181 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002182 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002183 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002184int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002185{
2186 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002187 struct fcp_cmnd *fcp_cmnd;
Jan Glauber3ec90872011-06-06 14:14:40 +02002188 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
Swen Schillig86a96682011-08-15 14:40:32 +02002189 int retval = -EIO;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002190 struct scsi_device *sdev = scsi_cmnd->device;
2191 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2192 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002193 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002194 struct fsf_qtcb_bottom_io *io;
Christof Schmitte55f8752010-11-18 14:53:18 +01002195 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002196
Christof Schmittb62a8d92010-09-08 14:39:55 +02002197 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002198 ZFCP_STATUS_COMMON_UNBLOCKED)))
2199 return -EBUSY;
2200
Christof Schmitte55f8752010-11-18 14:53:18 +01002201 spin_lock_irqsave(&qdio->req_q_lock, flags);
Swen Schillig706eca42010-07-16 15:37:38 +02002202 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002203 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002204 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002205 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002206
Christof Schmitt1674b402010-04-30 18:09:34 +02002207 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
Jan Glauber3ec90872011-06-06 14:14:40 +02002208 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
Christof Schmitt1674b402010-04-30 18:09:34 +02002209
Swen Schillig564e1c82009-08-18 15:43:19 +02002210 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002211 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002212
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002213 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002214 retval = PTR_ERR(req);
2215 goto out;
2216 }
2217
Felix Beckef3eb712010-07-16 15:37:42 +02002218 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2219
2220 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002221 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002222 req->data = scsi_cmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002223 req->handler = zfcp_fsf_fcp_cmnd_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002224 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2225 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002226 io->service_class = FSF_CLASS_3;
2227 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002228
Felix Beckef3eb712010-07-16 15:37:42 +02002229 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2230 io->data_block_length = scsi_cmnd->device->sector_size;
2231 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002232 }
2233
Steffen Maiercc405ac2011-08-15 14:40:30 +02002234 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2235 goto failed_scsi_cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +02002236
Christof Schmitt4318e082009-11-24 16:54:08 +01002237 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002238 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002239
Felix Beckef3eb712010-07-16 15:37:42 +02002240 if (scsi_prot_sg_count(scsi_cmnd)) {
2241 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2242 scsi_prot_sg_count(scsi_cmnd));
Swen Schillig86a96682011-08-15 14:40:32 +02002243 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2244 scsi_prot_sglist(scsi_cmnd));
2245 if (retval)
2246 goto failed_scsi_cmnd;
2247 io->prot_data_length = zfcp_qdio_real_bytes(
Felix Beckef3eb712010-07-16 15:37:42 +02002248 scsi_prot_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002249 }
2250
Swen Schillig86a96682011-08-15 14:40:32 +02002251 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2252 scsi_sglist(scsi_cmnd));
2253 if (unlikely(retval))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002254 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002255
Felix Beckef3eb712010-07-16 15:37:42 +02002256 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schillig86a96682011-08-15 14:40:32 +02002257 if (zfcp_adapter_multi_buffer_active(adapter))
2258 zfcp_qdio_set_scount(qdio, &req->qdio_req);
Felix Beckef3eb712010-07-16 15:37:42 +02002259
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002260 retval = zfcp_fsf_req_send(req);
2261 if (unlikely(retval))
2262 goto failed_scsi_cmnd;
2263
2264 goto out;
2265
2266failed_scsi_cmnd:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002267 zfcp_fsf_req_free(req);
2268 scsi_cmnd->host_scribble = NULL;
2269out:
Christof Schmitte55f8752010-11-18 14:53:18 +01002270 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002271 return retval;
2272}
2273
Christof Schmittc61b5362010-09-08 14:39:58 +02002274static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2275{
2276 struct fcp_resp_with_ext *fcp_rsp;
2277 struct fcp_resp_rsp_info *rsp_info;
2278
2279 zfcp_fsf_fcp_handler_common(req);
2280
2281 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2282 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2283
2284 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2285 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2286 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2287}
2288
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002289/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002290 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2291 * @scmnd: SCSI command to send the task management command for
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002292 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002293 * Returns: on success pointer to struct fsf_req, NULL otherwise
2294 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002295struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2296 u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002297{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002298 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002299 struct fcp_cmnd *fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002300 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2301 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002302
Christof Schmittb62a8d92010-09-08 14:39:55 +02002303 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002304 ZFCP_STATUS_COMMON_UNBLOCKED)))
2305 return NULL;
2306
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002307 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002308 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002309 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002310
Swen Schillig564e1c82009-08-18 15:43:19 +02002311 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Jan Glauber3ec90872011-06-06 14:14:40 +02002312 SBAL_SFLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002313 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002314
Swen Schillig633528c2008-11-26 18:07:37 +01002315 if (IS_ERR(req)) {
2316 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002317 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002318 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002319
Christof Schmittb62a8d92010-09-08 14:39:55 +02002320 req->data = scmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002321 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002322 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2323 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002324 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2325 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002326 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002327
Christof Schmitt1674b402010-04-30 18:09:34 +02002328 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002329
Christof Schmitt4318e082009-11-24 16:54:08 +01002330 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmitt2443c8b2011-02-22 19:54:45 +01002331 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002332
2333 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2334 if (!zfcp_fsf_req_send(req))
2335 goto out;
2336
2337 zfcp_fsf_req_free(req);
2338 req = NULL;
2339out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002340 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002341 return req;
2342}
2343
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002344/**
2345 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2346 * @adapter: pointer to struct zfcp_adapter
2347 * @sbal_idx: response queue index of SBAL to be processed
2348 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002349void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002350{
Swen Schillig564e1c82009-08-18 15:43:19 +02002351 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002352 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002353 struct qdio_buffer_element *sbale;
2354 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002355 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002356 int idx;
2357
2358 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2359
2360 sbale = &sbal->element[idx];
2361 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002362 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002363
Christof Schmitt339f4f42010-07-16 15:37:43 +02002364 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002365 /*
2366 * Unknown request means that we have potentially memory
2367 * corruption and must stop the machine immediately.
2368 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002369 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002370 panic("error: unknown req_id (%lx) on adapter %s.\n",
2371 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002372 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002373
Christof Schmitt34c2b712010-02-17 11:18:59 +01002374 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002375 zfcp_fsf_req_complete(fsf_req);
2376
Jan Glauber3ec90872011-06-06 14:14:40 +02002377 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002378 break;
2379 }
2380}
Swen Schilliga54ca0f2010-12-02 15:16:14 +01002381
2382struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
2383 struct qdio_buffer *sbal)
2384{
2385 struct qdio_buffer_element *sbale = &sbal->element[0];
2386 u64 req_id = (unsigned long) sbale->addr;
2387
2388 return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
2389}