blob: 2b9dfea9f254e60ff2219a7094d0163e65460a19 [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 *
Christof Schmitt615f59e2010-02-17 11:18:56 +01006 * Copyright IBM Corporation 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 Schmitt287ac012008-07-02 10:56:40 +020021static void zfcp_fsf_request_timeout_handler(unsigned long data)
22{
23 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Christof Schmitt339f4f42010-07-16 15:37:43 +020024 zfcp_qdio_siosl(adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010025 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
26 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020027}
28
29static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
30 unsigned long timeout)
31{
32 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
33 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
34 fsf_req->timer.expires = jiffies + timeout;
35 add_timer(&fsf_req->timer);
36}
37
38static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
39{
40 BUG_ON(!fsf_req->erp_action);
41 fsf_req->timer.function = zfcp_erp_timeout_handler;
42 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
43 fsf_req->timer.expires = jiffies + 30 * HZ;
44 add_timer(&fsf_req->timer);
45}
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/* association between FSF command and FSF QTCB type */
48static u32 fsf_qtcb_type[] = {
49 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
50 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
59 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
60 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
62};
63
Christof Schmitt553448f2008-06-10 18:20:58 +020064static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
65{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020066 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020067 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020068 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020069
Christof Schmittff3b24f2008-10-01 12:42:15 +020070 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020071 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020072 "Access denied according to ACT rule type %s, "
73 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020074}
75
76static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
77 struct zfcp_port *port)
78{
79 struct fsf_qtcb_header *header = &req->qtcb->header;
80 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020081 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020082 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020083 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
84 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010085 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020086 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
87}
88
Christof Schmittb62a8d92010-09-08 14:39:55 +020089static void zfcp_fsf_access_denied_lun(struct zfcp_fsf_req *req,
90 struct scsi_device *sdev)
Christof Schmitt553448f2008-06-10 18:20:58 +020091{
Christof Schmittb62a8d92010-09-08 14:39:55 +020092 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
93
Christof Schmitt553448f2008-06-10 18:20:58 +020094 struct fsf_qtcb_header *header = &req->qtcb->header;
95 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +020096 "Access denied to LUN 0x%016Lx on port 0x%016Lx\n",
97 (unsigned long long)zfcp_scsi_dev_lun(sdev),
98 (unsigned long long)zfcp_sdev->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020099 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
100 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Christof Schmittb62a8d92010-09-08 14:39:55 +0200101 zfcp_erp_lun_access_denied(sdev, "fsadl_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200102 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
103}
104
105static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
106{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200107 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
108 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100109 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200110 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
111}
112
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200113/**
114 * zfcp_fsf_req_free - free memory used by fsf request
115 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200117void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200119 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200120 if (likely(req->qtcb))
121 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200122 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200123 return;
124 }
125
Swen Schilliga4623c42009-08-18 15:43:15 +0200126 if (likely(req->qtcb))
127 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
128 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200131static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Swen Schilligecf0c772009-11-24 16:53:58 +0100133 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200134 struct fsf_status_read_buffer *sr_buf = req->data;
135 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100137 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Swen Schilligecf0c772009-11-24 16:53:58 +0100139 read_lock_irqsave(&adapter->port_list_lock, flags);
140 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200141 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100142 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100143 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200144 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100145 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100148static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200149 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200151 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200153 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
154 return;
155
156 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200157
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100158 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200159
160 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200162
163 switch (link_down->error_code) {
164 case FSF_PSQ_LINK_NO_LIGHT:
165 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200166 "There is no light signal from the local "
167 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200168 break;
169 case FSF_PSQ_LINK_WRAP_PLUG:
170 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200171 "There is a wrap plug instead of a fibre "
172 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200173 break;
174 case FSF_PSQ_LINK_NO_FCP:
175 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200176 "The adjacent fibre channel node does not "
177 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200178 break;
179 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
180 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200181 "The FCP device is suspended because of a "
182 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200183 break;
184 case FSF_PSQ_LINK_INVALID_WWPN:
185 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200186 "The FCP device detected a WWPN that is "
187 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200188 break;
189 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
190 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200191 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200192 break;
193 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
194 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200195 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200196 break;
197 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
198 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200199 "The adjacent switch cannot support "
200 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200201 break;
202 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
203 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200204 "The FCP adapter could not log in to the "
205 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200206 break;
207 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
208 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200209 "The WWPN assignment file on the FCP adapter "
210 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200211 break;
212 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
213 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200214 "The mode table on the FCP adapter "
215 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200216 break;
217 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
218 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200219 "All NPIV ports on the FCP adapter have "
220 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200221 break;
222 default:
223 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200224 "The link between the FCP adapter and "
225 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200226 }
227out:
228 zfcp_erp_adapter_failed(adapter, id, req);
229}
230
231static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
232{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200233 struct fsf_status_read_buffer *sr_buf = req->data;
234 struct fsf_link_down_info *ldi =
235 (struct fsf_link_down_info *) &sr_buf->payload;
236
237 switch (sr_buf->status_subtype) {
238 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100239 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200240 break;
241 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100242 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200243 break;
244 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100245 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200246 };
247}
248
249static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
250{
251 struct zfcp_adapter *adapter = req->adapter;
252 struct fsf_status_read_buffer *sr_buf = req->data;
253
254 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200255 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200256 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200257 zfcp_fsf_req_free(req);
258 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
260
Swen Schillig57717102009-08-18 15:43:21 +0200261 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200262
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200263 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200265 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200268 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200273 dev_warn(&adapter->ccw_device->dev,
274 "The error threshold for checksum statistics "
275 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200276 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200279 zfcp_fsf_status_read_link_down(req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200280 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200283 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200284 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100286 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 ZFCP_STATUS_COMMON_RUNNING,
288 ZFCP_SET);
289 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200290 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
291 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100292 "fssrh_2", req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200293 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100296 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200297 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100298 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
299 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200300 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100301 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100302 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100304 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200306 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200307 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200308 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200310
Swen Schilliga4623c42009-08-18 15:43:15 +0200311 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200312 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200313
314 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200315 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200318static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200320 switch (req->qtcb->header.fsf_status_qual.word[0]) {
321 case FSF_SQ_FCP_RSP_AVAILABLE:
322 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
323 case FSF_SQ_NO_RETRY_POSSIBLE:
324 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
325 return;
326 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200327 break;
328 case FSF_SQ_NO_RECOM:
329 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200330 "The FCP adapter reported a problem "
331 "that cannot be recovered\n");
Christof Schmitt339f4f42010-07-16 15:37:43 +0200332 zfcp_qdio_siosl(req->adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100333 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200334 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200336 /* all non-return stats set FSFREQ_ERROR*/
337 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
338}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200340static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
341{
342 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
343 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200344
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200345 switch (req->qtcb->header.fsf_status) {
346 case FSF_UNKNOWN_COMMAND:
347 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200348 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200349 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100350 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200351 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200354 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200359static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200361 struct zfcp_adapter *adapter = req->adapter;
362 struct fsf_qtcb *qtcb = req->qtcb;
363 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Swen Schillig57717102009-08-18 15:43:21 +0200365 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200367 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100368 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200369 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
371
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200372 switch (qtcb->prefix.prot_status) {
373 case FSF_PROT_GOOD:
374 case FSF_PROT_FSF_STATUS_PRESENTED:
375 return;
376 case FSF_PROT_QTCB_VERSION_ERROR:
377 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200378 "QTCB version 0x%x not supported by FCP adapter "
379 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
380 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100381 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200383 case FSF_PROT_ERROR_STATE:
384 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100385 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100386 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200388 case FSF_PROT_UNSUPP_QTCB_TYPE:
389 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200390 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100391 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200393 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
394 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
395 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200397 case FSF_PROT_DUPLICATE_REQUEST_ID:
398 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200399 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200400 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100401 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200403 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100404 zfcp_fsf_link_down_info_eval(req, "fspse_5",
405 &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100406 /* go through reopen to flush pending requests */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100407 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200409 case FSF_PROT_REEST_QUEUE:
410 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100411 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200412 ZFCP_STATUS_COMMON_RUNNING,
413 ZFCP_SET);
414 zfcp_erp_adapter_reopen(adapter,
415 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100416 ZFCP_STATUS_COMMON_ERP_FAILED,
417 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200418 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200420 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200421 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200422 qtcb->prefix.prot_status);
Christof Schmitt339f4f42010-07-16 15:37:43 +0200423 zfcp_qdio_siosl(adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100424 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200426 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
429/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200430 * zfcp_fsf_req_complete - process completion of a FSF request
431 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200433 * When a request has been completed either from the FCP adapter,
434 * or it has been dismissed due to a queue shutdown, this function
435 * is called to process the completion status and trigger further
436 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200438static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200439{
440 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
441 zfcp_fsf_status_read_handler(req);
442 return;
443 }
444
445 del_timer(&req->timer);
446 zfcp_fsf_protstatus_eval(req);
447 zfcp_fsf_fsfstatus_eval(req);
448 req->handler(req);
449
450 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200451 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200452
453 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
454 zfcp_fsf_req_free(req);
455 else
Swen Schillig058b8642009-08-18 15:43:14 +0200456 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200457}
458
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200459/**
460 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
461 * @adapter: pointer to struct zfcp_adapter
462 *
463 * Never ever call this without shutting down the adapter first.
464 * Otherwise the adapter would continue using and corrupting s390 storage.
465 * Included BUG_ON() call to ensure this is done.
466 * ERP is supposed to be the only user of this function.
467 */
468void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
469{
470 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200471 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200472
473 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100474 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200475
476 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
477 list_del(&req->list);
478 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
479 zfcp_fsf_req_complete(req);
480 }
481}
482
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200483static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100485 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200486 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200487 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100488 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100490 /* adjust pointers for missing command code */
491 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
492 - sizeof(u32));
493 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
494 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200495
496 if (req->data)
497 memcpy(req->data, bottom, sizeof(*bottom));
498
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100499 fc_host_port_name(shost) = nsp->fl_wwpn;
500 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100501 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200502 fc_host_speed(shost) = bottom->fc_link_speed;
503 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
504
505 adapter->hydra_version = bottom->adapter_type;
Christof Schmittfaf4cd82010-07-16 15:37:36 +0200506 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200507 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
508 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200509
510 if (fc_host_permanent_port_name(shost) == -1)
511 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
512
513 switch (bottom->fc_topology) {
514 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100515 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100516 adapter->peer_wwpn = plogi->fl_wwpn;
517 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200518 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200519 break;
520 case FSF_TOPO_FABRIC:
521 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200522 break;
523 case FSF_TOPO_AL:
524 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200525 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200526 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200527 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200528 "Unknown or unsupported arbitrated loop "
529 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100530 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200531 return -EIO;
532 }
533
Felix Beckef3eb712010-07-16 15:37:42 +0200534 zfcp_scsi_set_prot(adapter);
535
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200536 return 0;
537}
538
539static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
540{
541 struct zfcp_adapter *adapter = req->adapter;
542 struct fsf_qtcb *qtcb = req->qtcb;
543 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
544 struct Scsi_Host *shost = adapter->scsi_host;
545
546 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
547 return;
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200550 adapter->adapter_features = bottom->adapter_features;
551 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500552 adapter->peer_wwpn = 0;
553 adapter->peer_wwnn = 0;
554 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200556 switch (qtcb->header.fsf_status) {
557 case FSF_GOOD:
558 if (zfcp_fsf_exchange_config_evaluate(req))
559 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200560
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200561 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
562 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200563 "FCP adapter maximum QTCB size (%d bytes) "
564 "is too small\n",
565 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100566 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200567 return;
568 }
569 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
570 &adapter->status);
571 break;
572 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200573 fc_host_node_name(shost) = 0;
574 fc_host_port_name(shost) = 0;
575 fc_host_port_id(shost) = 0;
576 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100577 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200579
580 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
581 &adapter->status);
582
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100583 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200584 &qtcb->header.fsf_status_qual.link_down_info);
585 break;
586 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100587 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200588 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
590
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200591 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200593 memcpy(fc_host_serial_number(shost), bottom->serial_number,
594 min(FC_SERIAL_NUMBER_SIZE, 17));
595 EBCASC(fc_host_serial_number(shost),
596 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200599 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200600 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200601 "The FCP adapter only supports newer "
602 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100603 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200604 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200606 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200607 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200608 "The FCP adapter only supports older "
609 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100610 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612}
613
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200614static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200616 struct zfcp_adapter *adapter = req->adapter;
617 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
618 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200620 if (req->data)
621 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100622
Christof Schmitt02829852009-03-02 13:09:06 +0100623 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100624 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100625 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
626 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100627 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
628 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
629 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100630 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
631 FC_FC4_LIST_SIZE);
632 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
633 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100634}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200636static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200638 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100639
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200640 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return;
642
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200643 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644 case FSF_GOOD:
645 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200646 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200647 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200648 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100649 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200650 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200651 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653}
654
Swen Schilliga4623c42009-08-18 15:43:15 +0200655static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200656{
657 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200658
659 if (likely(pool))
660 req = mempool_alloc(pool, GFP_ATOMIC);
661 else
662 req = kmalloc(sizeof(*req), GFP_ATOMIC);
663
664 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200665 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200666
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200667 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100668 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200669 return req;
670}
671
Swen Schilliga4623c42009-08-18 15:43:15 +0200672static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200673{
Swen Schilliga4623c42009-08-18 15:43:15 +0200674 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200675
676 if (likely(pool))
677 qtcb = mempool_alloc(pool, GFP_ATOMIC);
678 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200679 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
680
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200681 if (unlikely(!qtcb))
682 return NULL;
683
684 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200685 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200686}
687
Swen Schillig564e1c82009-08-18 15:43:19 +0200688static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Christof Schmitt1674b402010-04-30 18:09:34 +0200689 u32 fsf_cmd, u32 sbtype,
690 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Swen Schillig564e1c82009-08-18 15:43:19 +0200692 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200693 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200694
695 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200696 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200697
698 if (adapter->req_no == 0)
699 adapter->req_no++;
700
701 INIT_LIST_HEAD(&req->list);
702 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200703 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200704
705 req->adapter = adapter;
706 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100707 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200708
Swen Schilliga4623c42009-08-18 15:43:15 +0200709 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
710 if (likely(pool))
711 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
712 else
713 req->qtcb = zfcp_qtcb_alloc(NULL);
714
715 if (unlikely(!req->qtcb)) {
716 zfcp_fsf_req_free(req);
717 return ERR_PTR(-ENOMEM);
718 }
719
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100720 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200721 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200722 req->qtcb->prefix.req_id = req->req_id;
723 req->qtcb->prefix.ulp_info = 26;
724 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
725 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
726 req->qtcb->header.req_handle = req->req_id;
727 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200728 }
729
Christof Schmitt1674b402010-04-30 18:09:34 +0200730 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
731 req->qtcb, sizeof(struct fsf_qtcb));
732
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200733 return req;
734}
735
736static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
737{
738 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200739 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100740 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100741 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200742
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100743 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200744
Swen Schillig706eca42010-07-16 15:37:38 +0200745 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200746 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100747 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200748 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100749 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100750 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100751 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200752 return -EIO;
753 }
754
755 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200756 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200757 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100758 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200759
760 return 0;
761}
762
763/**
764 * zfcp_fsf_status_read - send status read request
765 * @adapter: pointer to struct zfcp_adapter
766 * @req_flags: request flags
767 * Returns: 0 on success, ERROR otherwise
768 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200769int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200770{
Swen Schillig564e1c82009-08-18 15:43:19 +0200771 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772 struct zfcp_fsf_req *req;
773 struct fsf_status_read_buffer *sr_buf;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200774 int retval = -EIO;
775
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200776 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200777 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Christof Schmitt1674b402010-04-30 18:09:34 +0200780 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200781 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200782 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200783 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 goto out;
785 }
786
Swen Schilliga4623c42009-08-18 15:43:15 +0200787 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200788 if (!sr_buf) {
789 retval = -ENOMEM;
790 goto failed_buf;
791 }
792 memset(sr_buf, 0, sizeof(*sr_buf));
793 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200794
795 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
796 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200797
798 retval = zfcp_fsf_req_send(req);
799 if (retval)
800 goto failed_req_send;
801
802 goto out;
803
804failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200805 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200806failed_buf:
807 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200808 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200809out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200810 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 return retval;
812}
813
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200814static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200816 struct scsi_device *sdev = req->data;
817 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200818 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
821 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200823 switch (req->qtcb->header.fsf_status) {
824 case FSF_PORT_HANDLE_NOT_VALID:
825 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200826 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100827 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200828 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200831 case FSF_LUN_HANDLE_NOT_VALID:
832 if (fsq->word[0] == fsq->word[1]) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200833 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2",
834 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200835 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200838 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
839 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200841 case FSF_PORT_BOXED:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200842 zfcp_erp_port_boxed(zfcp_sdev->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100843 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200844 break;
845 case FSF_LUN_BOXED:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200846 zfcp_erp_lun_boxed(sdev, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100847 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200848 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200850 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +0200852 zfcp_fc_test_link(zfcp_sdev->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200853 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 break;
857 }
858 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200860 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
861 break;
862 }
863}
864
865/**
Christof Schmittb62a8d92010-09-08 14:39:55 +0200866 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
867 * @scmnd: The SCSI command to abort
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200868 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200869 */
870
Christof Schmittb62a8d92010-09-08 14:39:55 +0200871struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200872{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200873 struct zfcp_fsf_req *req = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200874 struct scsi_device *sdev = scmnd->device;
875 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
876 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
877 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200879 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200880 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200881 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200882 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +0200883 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200884 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100885 if (IS_ERR(req)) {
886 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200887 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100888 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200889
Christof Schmittb62a8d92010-09-08 14:39:55 +0200890 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200891 ZFCP_STATUS_COMMON_UNBLOCKED)))
892 goto out_error_free;
893
Christof Schmitt1674b402010-04-30 18:09:34 +0200894 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200895
Christof Schmittb62a8d92010-09-08 14:39:55 +0200896 req->data = zfcp_sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200897 req->handler = zfcp_fsf_abort_fcp_command_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200898 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
899 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200900 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
901
902 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
903 if (!zfcp_fsf_req_send(req))
904 goto out;
905
906out_error_free:
907 zfcp_fsf_req_free(req);
908 req = NULL;
909out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +0200910 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200911 return req;
912}
913
914static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
915{
916 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100917 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200918 struct fsf_qtcb_header *header = &req->qtcb->header;
919
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100920 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200921
922 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
923 goto skip_fsfstatus;
924
925 switch (header->fsf_status) {
926 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200927 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100928 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200929 break;
930 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
931 zfcp_fsf_class_not_supp(req);
932 break;
933 case FSF_ADAPTER_STATUS_AVAILABLE:
934 switch (header->fsf_status_qual.word[0]){
935 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200936 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
937 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
938 break;
939 }
940 break;
941 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200942 break;
943 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200945 break;
946 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100947 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200948 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200949 case FSF_GENERIC_COMMAND_REJECTED:
950 case FSF_PAYLOAD_SIZE_MISMATCH:
951 case FSF_REQUEST_SIZE_TOO_LARGE:
952 case FSF_RESPONSE_SIZE_TOO_LARGE:
953 case FSF_SBAL_MISMATCH:
954 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
955 break;
956 }
957
958skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100959 if (ct->handler)
960 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200961}
962
Christof Schmitt1674b402010-04-30 18:09:34 +0200963static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
964 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200965 struct scatterlist *sg_req,
966 struct scatterlist *sg_resp)
967{
Christof Schmitt1674b402010-04-30 18:09:34 +0200968 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
969 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
970 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200971}
972
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100973static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
974 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200975 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200976{
Swen Schillig42428f72009-08-18 15:43:18 +0200977 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig42428f72009-08-18 15:43:18 +0200978 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200979 int bytes;
980
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100981 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200982 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
983 !zfcp_qdio_sg_one_sbale(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100984 return -EOPNOTSUPP;
985
Christof Schmitt1674b402010-04-30 18:09:34 +0200986 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
987 sg_req, sg_resp);
Christof Schmitt426f6052009-07-13 15:06:06 +0200988 return 0;
989 }
990
991 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200992 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200993 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
994 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100995 return 0;
996 }
997
Swen Schillig01b04752010-07-16 15:37:37 +0200998 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200999 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001000 return -EIO;
Felix Beckef3eb712010-07-16 15:37:42 +02001001 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001002 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt1674b402010-04-30 18:09:34 +02001003 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001004
Christof Schmitt34c2b712010-02-17 11:18:59 +01001005 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +02001006 sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001007 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001008 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001009 return -EIO;
Felix Beckef3eb712010-07-16 15:37:42 +02001010 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001011
Christof Schmittb1a58982009-09-24 10:23:21 +02001012 return 0;
1013}
1014
1015static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1016 struct scatterlist *sg_req,
1017 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001018 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001019{
1020 int ret;
1021
Swen Schillig01b04752010-07-16 15:37:37 +02001022 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001023 if (ret)
1024 return ret;
1025
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001026 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001027 if (timeout > 255)
1028 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001029 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001030 req->qtcb->bottom.support.timeout = timeout;
1031 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001032
1033 return 0;
1034}
1035
1036/**
1037 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1038 * @ct: pointer to struct zfcp_send_ct with data for request
1039 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001040 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001041int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001042 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1043 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001044{
Swen Schillig564e1c82009-08-18 15:43:19 +02001045 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001046 struct zfcp_fsf_req *req;
1047 int ret = -EIO;
1048
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001049 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001050 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001051 goto out;
1052
Christof Schmitt1674b402010-04-30 18:09:34 +02001053 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1054 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001055
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001056 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001057 ret = PTR_ERR(req);
1058 goto out;
1059 }
1060
Swen Schillig09a46c62009-08-18 15:43:16 +02001061 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001062 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001063 if (ret)
1064 goto failed_send;
1065
1066 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001067 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001068 req->data = ct;
1069
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001070 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001071
1072 ret = zfcp_fsf_req_send(req);
1073 if (ret)
1074 goto failed_send;
1075
1076 goto out;
1077
1078failed_send:
1079 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001080out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001081 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001082 return ret;
1083}
1084
1085static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1086{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001087 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001088 struct zfcp_port *port = send_els->port;
1089 struct fsf_qtcb_header *header = &req->qtcb->header;
1090
1091 send_els->status = -EINVAL;
1092
1093 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1094 goto skip_fsfstatus;
1095
1096 switch (header->fsf_status) {
1097 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001098 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001099 send_els->status = 0;
1100 break;
1101 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1102 zfcp_fsf_class_not_supp(req);
1103 break;
1104 case FSF_ADAPTER_STATUS_AVAILABLE:
1105 switch (header->fsf_status_qual.word[0]){
1106 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001107 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1108 case FSF_SQ_RETRY_IF_POSSIBLE:
1109 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1110 break;
1111 }
1112 break;
1113 case FSF_ELS_COMMAND_REJECTED:
1114 case FSF_PAYLOAD_SIZE_MISMATCH:
1115 case FSF_REQUEST_SIZE_TOO_LARGE:
1116 case FSF_RESPONSE_SIZE_TOO_LARGE:
1117 break;
1118 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001119 if (port)
1120 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001121 break;
1122 case FSF_SBAL_MISMATCH:
1123 /* should never occure, avoided in zfcp_fsf_send_els */
1124 /* fall through */
1125 default:
1126 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1127 break;
1128 }
1129skip_fsfstatus:
1130 if (send_els->handler)
1131 send_els->handler(send_els->handler_data);
1132}
1133
1134/**
1135 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1136 * @els: pointer to struct zfcp_send_els with data for the command
1137 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001138int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001139 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001140{
1141 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001142 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001143 int ret = -EIO;
1144
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001145 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001146 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001147 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001148
Christof Schmitt1674b402010-04-30 18:09:34 +02001149 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1150 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001151
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001152 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001153 ret = PTR_ERR(req);
1154 goto out;
1155 }
1156
Swen Schillig09a46c62009-08-18 15:43:16 +02001157 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001158
1159 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1160
1161 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001162
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001163 if (ret)
1164 goto failed_send;
1165
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001166 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001167 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001168 req->data = els;
1169
Swen Schillig57717102009-08-18 15:43:21 +02001170 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001171
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001172 ret = zfcp_fsf_req_send(req);
1173 if (ret)
1174 goto failed_send;
1175
1176 goto out;
1177
1178failed_send:
1179 zfcp_fsf_req_free(req);
1180out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001181 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001182 return ret;
1183}
1184
1185int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1186{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001187 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001188 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001189 int retval = -EIO;
1190
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001191 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001192 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001193 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001194
Swen Schillig564e1c82009-08-18 15:43:19 +02001195 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001196 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001197 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001198
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001199 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001200 retval = PTR_ERR(req);
1201 goto out;
1202 }
1203
Swen Schillig09a46c62009-08-18 15:43:16 +02001204 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001205 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206
1207 req->qtcb->bottom.config.feature_selection =
1208 FSF_FEATURE_CFDC |
1209 FSF_FEATURE_LUN_SHARING |
1210 FSF_FEATURE_NOTIFICATION_LOST |
1211 FSF_FEATURE_UPDATE_ALERT;
1212 req->erp_action = erp_action;
1213 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001214 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001215
Christof Schmitt287ac012008-07-02 10:56:40 +02001216 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001217 retval = zfcp_fsf_req_send(req);
1218 if (retval) {
1219 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001220 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001221 }
1222out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001223 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001224 return retval;
1225}
1226
Swen Schillig564e1c82009-08-18 15:43:19 +02001227int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001228 struct fsf_qtcb_bottom_config *data)
1229{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001230 struct zfcp_fsf_req *req = NULL;
1231 int retval = -EIO;
1232
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001233 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001234 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001235 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001236
Christof Schmitt1674b402010-04-30 18:09:34 +02001237 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1238 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001239
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001240 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001241 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001242 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001243 }
1244
Christof Schmitt1674b402010-04-30 18:09:34 +02001245 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001246 req->handler = zfcp_fsf_exchange_config_data_handler;
1247
1248 req->qtcb->bottom.config.feature_selection =
1249 FSF_FEATURE_CFDC |
1250 FSF_FEATURE_LUN_SHARING |
1251 FSF_FEATURE_NOTIFICATION_LOST |
1252 FSF_FEATURE_UPDATE_ALERT;
1253
1254 if (data)
1255 req->data = data;
1256
1257 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1258 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001259 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001260 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001261 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001262
1263 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001264 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001265
Christof Schmittada81b72009-04-17 15:08:03 +02001266out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001267 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268 return retval;
1269}
1270
1271/**
1272 * zfcp_fsf_exchange_port_data - request information about local port
1273 * @erp_action: ERP action for the adapter for which port data is requested
1274 * Returns: 0 on success, error otherwise
1275 */
1276int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1277{
Swen Schillig564e1c82009-08-18 15:43:19 +02001278 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001279 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001280 int retval = -EIO;
1281
Swen Schillig564e1c82009-08-18 15:43:19 +02001282 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001283 return -EOPNOTSUPP;
1284
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001285 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001286 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001287 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001288
Swen Schillig564e1c82009-08-18 15:43:19 +02001289 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001290 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001291 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001292
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001293 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001294 retval = PTR_ERR(req);
1295 goto out;
1296 }
1297
Swen Schillig09a46c62009-08-18 15:43:16 +02001298 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001299 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001300
1301 req->handler = zfcp_fsf_exchange_port_data_handler;
1302 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001303 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001304
Christof Schmitt287ac012008-07-02 10:56:40 +02001305 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001306 retval = zfcp_fsf_req_send(req);
1307 if (retval) {
1308 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001309 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001310 }
1311out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001312 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001313 return retval;
1314}
1315
1316/**
1317 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001318 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001319 * @data: pointer to struct fsf_qtcb_bottom_port
1320 * Returns: 0 on success, error otherwise
1321 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001322int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323 struct fsf_qtcb_bottom_port *data)
1324{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001325 struct zfcp_fsf_req *req = NULL;
1326 int retval = -EIO;
1327
Swen Schillig564e1c82009-08-18 15:43:19 +02001328 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 return -EOPNOTSUPP;
1330
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001331 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001332 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001333 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001334
Christof Schmitt1674b402010-04-30 18:09:34 +02001335 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1336 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001337
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001338 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001339 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001340 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001341 }
1342
1343 if (data)
1344 req->data = data;
1345
Christof Schmitt1674b402010-04-30 18:09:34 +02001346 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001347
1348 req->handler = zfcp_fsf_exchange_port_data_handler;
1349 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1350 retval = zfcp_fsf_req_send(req);
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001351 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001352
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001353 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001354 wait_for_completion(&req->completion);
1355
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001356 zfcp_fsf_req_free(req);
1357
1358 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001359
1360out_unlock:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001361 spin_unlock_irq(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001362 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001363}
1364
1365static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1366{
1367 struct zfcp_port *port = req->data;
1368 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001369 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001370
1371 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001372 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001373
1374 switch (header->fsf_status) {
1375 case FSF_PORT_ALREADY_OPEN:
1376 break;
1377 case FSF_ACCESS_DENIED:
1378 zfcp_fsf_access_denied_port(req, port);
1379 break;
1380 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1381 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001382 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001383 "remote port 0x%016Lx\n",
1384 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001385 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001386 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1387 break;
1388 case FSF_ADAPTER_STATUS_AVAILABLE:
1389 switch (header->fsf_status_qual.word[0]) {
1390 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1391 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001392 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001393 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1394 break;
1395 }
1396 break;
1397 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1400 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001401 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1402 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1403 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 /* check whether D_ID has changed during open */
1405 /*
1406 * FIXME: This check is not airtight, as the FCP channel does
1407 * not monitor closures of target port connections caused on
1408 * the remote side. Thus, they might miss out on invalidating
1409 * locally cached WWPNs (and other N_Port parameters) of gone
1410 * target ports. So, our heroic attempt to make things safe
1411 * could be undermined by 'open port' response data tagged with
1412 * obsolete WWPNs. Another reason to monitor potential
1413 * connection closures ourself at least (by interpreting
1414 * incoming ELS' and unsolicited status). It just crosses my
1415 * mind that one should be able to cross-check by means of
1416 * another GID_PN straight after a port has been opened.
1417 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1418 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001419 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001420 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001421 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001422 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001425 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 break;
1427 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001428
1429out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001430 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001433/**
1434 * zfcp_fsf_open_port - create and send open port request
1435 * @erp_action: pointer to struct zfcp_erp_action
1436 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001438int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Swen Schillig564e1c82009-08-18 15:43:19 +02001440 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001441 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001442 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001443 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001445 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001446 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Swen Schillig564e1c82009-08-18 15:43:19 +02001449 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001450 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001451 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001452
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001453 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001454 retval = PTR_ERR(req);
1455 goto out;
1456 }
1457
Swen Schillig09a46c62009-08-18 15:43:16 +02001458 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001459 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001461 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001462 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001463 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001464 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001465 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001466 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Christof Schmitt287ac012008-07-02 10:56:40 +02001468 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001469 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001471 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001472 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001473 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001476 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 return retval;
1478}
1479
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001480static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001482 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001484 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001485 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001487 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001489 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001490 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001495 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 ZFCP_STATUS_COMMON_OPEN,
1497 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001502/**
1503 * zfcp_fsf_close_port - create and send close port request
1504 * @erp_action: pointer to struct zfcp_erp_action
1505 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001507int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Swen Schillig564e1c82009-08-18 15:43:19 +02001509 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001510 struct zfcp_fsf_req *req;
1511 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001513 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001514 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Swen Schillig564e1c82009-08-18 15:43:19 +02001517 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001518 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001519 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001520
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001521 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001522 retval = PTR_ERR(req);
1523 goto out;
1524 }
1525
Swen Schillig09a46c62009-08-18 15:43:16 +02001526 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001527 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001529 req->handler = zfcp_fsf_close_port_handler;
1530 req->data = erp_action->port;
1531 req->erp_action = erp_action;
1532 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001533 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Christof Schmitt287ac012008-07-02 10:56:40 +02001535 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001536 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001538 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001539 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001541out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001542 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 return retval;
1544}
1545
Swen Schillig5ab944f2008-10-01 12:42:17 +02001546static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1547{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001548 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001549 struct fsf_qtcb_header *header = &req->qtcb->header;
1550
1551 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001552 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001553 goto out;
1554 }
1555
1556 switch (header->fsf_status) {
1557 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1558 dev_warn(&req->adapter->ccw_device->dev,
1559 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001560 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001561 case FSF_ADAPTER_STATUS_AVAILABLE:
1562 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001563 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001564 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001565 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001566 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001567 case FSF_GOOD:
1568 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001569 /* fall through */
1570 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001571 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001572 }
1573out:
1574 wake_up(&wka_port->completion_wq);
1575}
1576
1577/**
1578 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001579 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001580 * Returns: 0 on success, error otherwise
1581 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001582int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001583{
Swen Schillig564e1c82009-08-18 15:43:19 +02001584 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001585 struct zfcp_fsf_req *req;
1586 int retval = -EIO;
1587
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001588 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001589 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001590 goto out;
1591
Swen Schillig564e1c82009-08-18 15:43:19 +02001592 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001593 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001594 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001595
Swen Schillig5ab944f2008-10-01 12:42:17 +02001596 if (unlikely(IS_ERR(req))) {
1597 retval = PTR_ERR(req);
1598 goto out;
1599 }
1600
Swen Schillig09a46c62009-08-18 15:43:16 +02001601 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001602 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001603
1604 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001605 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001606 req->data = wka_port;
1607
1608 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1609 retval = zfcp_fsf_req_send(req);
1610 if (retval)
1611 zfcp_fsf_req_free(req);
1612out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001613 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001614 return retval;
1615}
1616
1617static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1618{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001619 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001620
1621 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1622 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001623 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001624 }
1625
Christof Schmittbd0072e2009-11-24 16:54:11 +01001626 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001627 wake_up(&wka_port->completion_wq);
1628}
1629
1630/**
1631 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001632 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001633 * Returns: 0 on success, error otherwise
1634 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001635int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001636{
Swen Schillig564e1c82009-08-18 15:43:19 +02001637 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001638 struct zfcp_fsf_req *req;
1639 int retval = -EIO;
1640
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001641 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001642 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001643 goto out;
1644
Swen Schillig564e1c82009-08-18 15:43:19 +02001645 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001646 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001647 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001648
Swen Schillig5ab944f2008-10-01 12:42:17 +02001649 if (unlikely(IS_ERR(req))) {
1650 retval = PTR_ERR(req);
1651 goto out;
1652 }
1653
Swen Schillig09a46c62009-08-18 15:43:16 +02001654 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001655 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001656
1657 req->handler = zfcp_fsf_close_wka_port_handler;
1658 req->data = wka_port;
1659 req->qtcb->header.port_handle = wka_port->handle;
1660
1661 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1662 retval = zfcp_fsf_req_send(req);
1663 if (retval)
1664 zfcp_fsf_req_free(req);
1665out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001666 spin_unlock_irq(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001667 return retval;
1668}
1669
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001670static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001672 struct zfcp_port *port = req->data;
1673 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001674 struct scsi_device *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001676 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001677 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001681 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001682 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001685 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001688 /* can't use generic zfcp_erp_modify_port_status because
1689 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1690 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001691 shost_for_each_device(sdev, port->adapter->scsi_host)
1692 if (sdev_to_zfcp(sdev)->port == port)
1693 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1694 &sdev_to_zfcp(sdev)->status);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001695 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001696 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 switch (header->fsf_status_qual.word[0]) {
1700 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001701 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001703 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 }
1706 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 /* can't use generic zfcp_erp_modify_port_status because
1709 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1710 */
1711 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001712 shost_for_each_device(sdev, port->adapter->scsi_host)
1713 if (sdev_to_zfcp(sdev)->port == port)
1714 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1715 &sdev_to_zfcp(sdev)->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718}
1719
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001720/**
1721 * zfcp_fsf_close_physical_port - close physical port
1722 * @erp_action: pointer to struct zfcp_erp_action
1723 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001725int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726{
Swen Schillig564e1c82009-08-18 15:43:19 +02001727 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001728 struct zfcp_fsf_req *req;
1729 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001731 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001732 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Swen Schillig564e1c82009-08-18 15:43:19 +02001735 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001736 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001737 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001738
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001739 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001740 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 goto out;
1742 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001743
Swen Schillig09a46c62009-08-18 15:43:16 +02001744 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001745 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001746
1747 req->data = erp_action->port;
1748 req->qtcb->header.port_handle = erp_action->port->handle;
1749 req->erp_action = erp_action;
1750 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001751 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001752
Christof Schmitt287ac012008-07-02 10:56:40 +02001753 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001754 retval = zfcp_fsf_req_send(req);
1755 if (retval) {
1756 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001757 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001758 }
1759out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001760 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 return retval;
1762}
1763
Christof Schmittb62a8d92010-09-08 14:39:55 +02001764static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001766 struct zfcp_adapter *adapter = req->adapter;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001767 struct scsi_device *sdev = req->data;
1768 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001769 struct fsf_qtcb_header *header = &req->qtcb->header;
1770 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1771 struct fsf_queue_designator *queue_designator =
1772 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001773 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001775 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001776 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001779 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Christof Schmittb62a8d92010-09-08 14:39:55 +02001780 ZFCP_STATUS_LUN_SHARED |
1781 ZFCP_STATUS_LUN_READONLY,
1782 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 switch (header->fsf_status) {
1785
1786 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001787 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001788 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 case FSF_ACCESS_DENIED:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001792 zfcp_fsf_access_denied_lun(req, sdev);
1793 atomic_clear_mask(ZFCP_STATUS_LUN_SHARED, &zfcp_sdev->status);
1794 atomic_clear_mask(ZFCP_STATUS_LUN_READONLY, &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 case FSF_PORT_BOXED:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001797 zfcp_erp_port_boxed(zfcp_sdev->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001798 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001801 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001802 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001803 "LUN 0x%Lx on port 0x%Lx is already in "
1804 "use by CSS%d, MIF Image ID %x\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001805 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1806 (unsigned long long)zfcp_sdev->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001807 queue_designator->cssid,
1808 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001809 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001810 zfcp_act_eval_err(adapter,
1811 header->fsf_status_qual.word[2]);
Christof Schmittb62a8d92010-09-08 14:39:55 +02001812 zfcp_erp_lun_access_denied(sdev, "fsolh_3", req);
1813 atomic_clear_mask(ZFCP_STATUS_LUN_SHARED, &zfcp_sdev->status);
1814 atomic_clear_mask(ZFCP_STATUS_LUN_READONLY, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001815 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001818 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001819 "No handle is available for LUN "
1820 "0x%016Lx on port 0x%016Lx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001821 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1822 (unsigned long long)zfcp_sdev->port->wwpn);
1823 zfcp_erp_lun_failed(sdev, "fsolh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001824 /* fall through */
1825 case FSF_INVALID_COMMAND_OPTION:
1826 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 switch (header->fsf_status_qual.word[0]) {
1830 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001831 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001832 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001834 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 }
1837 break;
1838
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001840 zfcp_sdev->lun_handle = header->lun_handle;
1841 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001842
1843 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1844 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001845 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001846 exclusive = (bottom->lun_access_info &
1847 FSF_UNIT_ACCESS_EXCLUSIVE);
1848 readwrite = (bottom->lun_access_info &
1849 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1850
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 if (!exclusive)
Christof Schmittb62a8d92010-09-08 14:39:55 +02001852 atomic_set_mask(ZFCP_STATUS_LUN_SHARED,
1853 &zfcp_sdev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
1855 if (!readwrite) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02001856 atomic_set_mask(ZFCP_STATUS_LUN_READONLY,
1857 &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001858 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001859 "SCSI device at LUN 0x%016Lx on port "
1860 "0x%016Lx opened read-only\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001861 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1862 (unsigned long long)zfcp_sdev->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 }
1864
1865 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001866 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001867 "Exclusive read-only access not "
Christof Schmittb62a8d92010-09-08 14:39:55 +02001868 "supported (LUN 0x%016Lx, "
Christof Schmittff3b24f2008-10-01 12:42:15 +02001869 "port 0x%016Lx)\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001870 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1871 (unsigned long long)zfcp_sdev->port->wwpn);
1872 zfcp_erp_lun_failed(sdev, "fsolh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001873 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001874 zfcp_erp_lun_shutdown(sdev, 0, "fsolh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001876 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001877 "Shared read-write access not "
Christof Schmittb62a8d92010-09-08 14:39:55 +02001878 "supported (LUN 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001879 "0x%016Lx)\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +02001880 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1881 (unsigned long long)zfcp_sdev->port->wwpn);
1882 zfcp_erp_lun_failed(sdev, "fsolh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001883 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001884 zfcp_erp_lun_shutdown(sdev, 0, "fsolh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 }
1886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889}
1890
1891/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001892 * zfcp_fsf_open_lun - open LUN
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001893 * @erp_action: pointer to struct zfcp_erp_action
1894 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001896int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001898 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001899 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001900 struct zfcp_fsf_req *req;
1901 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001903 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001904 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001905 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Swen Schillig564e1c82009-08-18 15:43:19 +02001907 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001908 SBAL_FLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001909 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001910
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001911 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001912 retval = PTR_ERR(req);
1913 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001914 }
1915
Swen Schillig09a46c62009-08-18 15:43:16 +02001916 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001917 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001919 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001920 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1921 req->handler = zfcp_fsf_open_lun_handler;
1922 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001923 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001924 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001925
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001926 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1927 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
Christof Schmitt287ac012008-07-02 10:56:40 +02001929 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001930 retval = zfcp_fsf_req_send(req);
1931 if (retval) {
1932 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001933 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001935out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001936 spin_unlock_irq(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 return retval;
1938}
1939
Christof Schmittb62a8d92010-09-08 14:39:55 +02001940static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941{
Christof Schmittb62a8d92010-09-08 14:39:55 +02001942 struct scsi_device *sdev = req->data;
1943 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001944
1945 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001946 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001947
1948 switch (req->qtcb->header.fsf_status) {
1949 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001950 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1",
1951 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001952 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1953 break;
1954 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001955 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001956 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1957 break;
1958 case FSF_PORT_BOXED:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001959 zfcp_erp_port_boxed(zfcp_sdev->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001960 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001961 break;
1962 case FSF_ADAPTER_STATUS_AVAILABLE:
1963 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1964 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001965 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001966 /* fall through */
1967 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1968 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1969 break;
1970 }
1971 break;
1972 case FSF_GOOD:
Christof Schmittb62a8d92010-09-08 14:39:55 +02001973 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001974 break;
1975 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001976}
1977
1978/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02001979 * zfcp_fsf_close_LUN - close LUN
1980 * @erp_action: pointer to erp_action triggering the "close LUN"
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001981 * Returns: 0 on success, error otherwise
1982 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02001983int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001984{
Swen Schillig564e1c82009-08-18 15:43:19 +02001985 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Christof Schmittb62a8d92010-09-08 14:39:55 +02001986 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001987 struct zfcp_fsf_req *req;
1988 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Christof Schmitt44a24cb2010-09-08 14:39:57 +02001990 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001991 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001993
Swen Schillig564e1c82009-08-18 15:43:19 +02001994 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001995 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001996 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001997
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001998 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001999 retval = PTR_ERR(req);
2000 goto out;
2001 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
Swen Schillig09a46c62009-08-18 15:43:16 +02002003 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02002004 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002006 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002007 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2008 req->handler = zfcp_fsf_close_lun_handler;
2009 req->data = erp_action->sdev;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002010 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002011 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Christof Schmitt287ac012008-07-02 10:56:40 +02002013 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002014 retval = zfcp_fsf_req_send(req);
2015 if (retval) {
2016 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002017 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002018 }
2019out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002020 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002021 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022}
2023
Christof Schmittc9615852008-05-06 11:00:05 +02002024static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2025{
2026 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002027 lat_rec->min = min(lat_rec->min, lat);
2028 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002029}
2030
Christof Schmittd9742b42009-11-24 16:54:03 +01002031static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002032{
Christof Schmittd9742b42009-11-24 16:54:03 +01002033 struct fsf_qual_latency_info *lat_in;
2034 struct latency_cont *lat = NULL;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002035 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scsi->device);
Christof Schmittd9742b42009-11-24 16:54:03 +01002036 struct zfcp_blk_drv_data blktrc;
2037 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002038
Christof Schmittd9742b42009-11-24 16:54:03 +01002039 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002040
Christof Schmittd9742b42009-11-24 16:54:03 +01002041 blktrc.flags = 0;
2042 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2043 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2044 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02002045 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002046 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002047
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002048 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2049 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmittd9742b42009-11-24 16:54:03 +01002050 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2051 blktrc.channel_lat = lat_in->channel_lat * ticks;
2052 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2053
2054 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002055 case FSF_DATADIR_DIF_READ_STRIP:
2056 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002057 case FSF_DATADIR_READ:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002058 lat = &zfcp_sdev->latencies.read;
Christof Schmittd9742b42009-11-24 16:54:03 +01002059 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002060 case FSF_DATADIR_DIF_WRITE_INSERT:
2061 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002062 case FSF_DATADIR_WRITE:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002063 lat = &zfcp_sdev->latencies.write;
Christof Schmittd9742b42009-11-24 16:54:03 +01002064 break;
2065 case FSF_DATADIR_CMND:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002066 lat = &zfcp_sdev->latencies.cmd;
Christof Schmittd9742b42009-11-24 16:54:03 +01002067 break;
2068 }
2069
2070 if (lat) {
Christof Schmittb62a8d92010-09-08 14:39:55 +02002071 spin_lock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002072 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2073 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2074 lat->counter++;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002075 spin_unlock(&zfcp_sdev->latencies.lock);
Christof Schmittd9742b42009-11-24 16:54:03 +01002076 }
Christof Schmittc9615852008-05-06 11:00:05 +02002077 }
2078
Christof Schmittd9742b42009-11-24 16:54:03 +01002079 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2080 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002081}
2082
Christof Schmittc61b5362010-09-08 14:39:58 +02002083static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002084{
Christof Schmittb62a8d92010-09-08 14:39:55 +02002085 struct scsi_cmnd *scmnd = req->data;
2086 struct scsi_device *sdev = scmnd->device;
2087 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002088 struct fsf_qtcb_header *header = &req->qtcb->header;
2089
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002090 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
Christof Schmittc61b5362010-09-08 14:39:58 +02002091 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002092
2093 switch (header->fsf_status) {
2094 case FSF_HANDLE_MISMATCH:
2095 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002096 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1",
2097 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002098 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2099 break;
2100 case FSF_FCPLUN_NOT_VALID:
2101 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002102 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002103 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2104 break;
2105 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2106 zfcp_fsf_class_not_supp(req);
2107 break;
2108 case FSF_ACCESS_DENIED:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002109 zfcp_fsf_access_denied_lun(req, sdev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002110 break;
2111 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2112 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002113 "Incorrect direction %d, LUN 0x%016Lx on port "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002114 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002115 req->qtcb->bottom.io.data_direction,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002116 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2117 (unsigned long long)zfcp_sdev->port->wwpn);
2118 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
2119 "fssfch3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002120 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2121 break;
2122 case FSF_CMND_LENGTH_NOT_VALID:
2123 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002124 "Incorrect CDB length %d, LUN 0x%016Lx on "
Christof Schmittff3b24f2008-10-01 12:42:15 +02002125 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002126 req->qtcb->bottom.io.fcp_cmnd_length,
Christof Schmittb62a8d92010-09-08 14:39:55 +02002127 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2128 (unsigned long long)zfcp_sdev->port->wwpn);
2129 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
2130 "fssfch4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002131 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2132 break;
2133 case FSF_PORT_BOXED:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002134 zfcp_erp_port_boxed(zfcp_sdev->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002135 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002136 break;
2137 case FSF_LUN_BOXED:
Christof Schmittb62a8d92010-09-08 14:39:55 +02002138 zfcp_erp_lun_boxed(sdev, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002139 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002140 break;
2141 case FSF_ADAPTER_STATUS_AVAILABLE:
2142 if (header->fsf_status_qual.word[0] ==
2143 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Christof Schmittb62a8d92010-09-08 14:39:55 +02002144 zfcp_fc_test_link(zfcp_sdev->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002145 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2146 break;
2147 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002148}
2149
2150static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2151{
2152 struct scsi_cmnd *scpnt;
2153 struct fcp_resp_with_ext *fcp_rsp;
2154 unsigned long flags;
2155
2156 zfcp_fsf_fcp_handler_common(req);
2157
2158 read_lock_irqsave(&req->adapter->abort_lock, flags);
2159
2160 scpnt = req->data;
2161 if (unlikely(!scpnt)) {
2162 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2163 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002164 }
Christof Schmittc61b5362010-09-08 14:39:58 +02002165
2166 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2167 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2168 goto skip_fsfstatus;
2169 }
2170
2171 switch (req->qtcb->header.fsf_status) {
2172 case FSF_INCONSISTENT_PROT_DATA:
2173 case FSF_INVALID_PROT_PARM:
2174 set_host_byte(scpnt, DID_ERROR);
2175 goto skip_fsfstatus;
2176 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2177 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2178 goto skip_fsfstatus;
2179 case FSF_APP_TAG_CHECK_FAILURE:
2180 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2181 goto skip_fsfstatus;
2182 case FSF_REF_TAG_CHECK_FAILURE:
2183 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2184 goto skip_fsfstatus;
2185 }
2186 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2187 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2188
2189skip_fsfstatus:
2190 zfcp_fsf_req_trace(req, scpnt);
2191 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
2192
2193 scpnt->host_scribble = NULL;
2194 (scpnt->scsi_done) (scpnt);
2195 /*
2196 * We must hold this lock until scsi_done has been called.
2197 * Otherwise we may call scsi_done after abort regarding this
2198 * command has completed.
2199 * Note: scsi_done must not block!
2200 */
2201 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002202}
2203
Felix Beckef3eb712010-07-16 15:37:42 +02002204static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2205{
2206 switch (scsi_get_prot_op(scsi_cmnd)) {
2207 case SCSI_PROT_NORMAL:
2208 switch (scsi_cmnd->sc_data_direction) {
2209 case DMA_NONE:
2210 *data_dir = FSF_DATADIR_CMND;
2211 break;
2212 case DMA_FROM_DEVICE:
2213 *data_dir = FSF_DATADIR_READ;
2214 break;
2215 case DMA_TO_DEVICE:
2216 *data_dir = FSF_DATADIR_WRITE;
2217 break;
2218 case DMA_BIDIRECTIONAL:
2219 return -EINVAL;
2220 }
2221 break;
2222
2223 case SCSI_PROT_READ_STRIP:
2224 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2225 break;
2226 case SCSI_PROT_WRITE_INSERT:
2227 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2228 break;
2229 case SCSI_PROT_READ_PASS:
2230 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2231 break;
2232 case SCSI_PROT_WRITE_PASS:
2233 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2234 break;
2235 default:
2236 return -EINVAL;
2237 }
2238
2239 return 0;
2240}
2241
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002242/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002243 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002244 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002245 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002246int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002247{
2248 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002249 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002250 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Felix Beckef3eb712010-07-16 15:37:42 +02002251 int real_bytes, retval = -EIO, dix_bytes = 0;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002252 struct scsi_device *sdev = scsi_cmnd->device;
2253 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2254 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002255 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002256 struct fsf_qtcb_bottom_io *io;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002257
Christof Schmittb62a8d92010-09-08 14:39:55 +02002258 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002259 ZFCP_STATUS_COMMON_UNBLOCKED)))
2260 return -EBUSY;
2261
Swen Schillig564e1c82009-08-18 15:43:19 +02002262 spin_lock(&qdio->req_q_lock);
Swen Schillig706eca42010-07-16 15:37:38 +02002263 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002264 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002265 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002266 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002267
Christof Schmitt1674b402010-04-30 18:09:34 +02002268 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2269 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2270
Swen Schillig564e1c82009-08-18 15:43:19 +02002271 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002272 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002273
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002274 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002275 retval = PTR_ERR(req);
2276 goto out;
2277 }
2278
Felix Beckef3eb712010-07-16 15:37:42 +02002279 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2280
2281 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002282 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002283 req->data = scsi_cmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002284 req->handler = zfcp_fsf_fcp_cmnd_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002285 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2286 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002287 io->service_class = FSF_CLASS_3;
2288 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002289
Felix Beckef3eb712010-07-16 15:37:42 +02002290 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2291 io->data_block_length = scsi_cmnd->device->sector_size;
2292 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002293 }
2294
Felix Beckef3eb712010-07-16 15:37:42 +02002295 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
2296
Christof Schmitt4318e082009-11-24 16:54:08 +01002297 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2298 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002299
Felix Beckef3eb712010-07-16 15:37:42 +02002300 if (scsi_prot_sg_count(scsi_cmnd)) {
2301 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2302 scsi_prot_sg_count(scsi_cmnd));
2303 dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2304 scsi_prot_sglist(scsi_cmnd));
2305 io->prot_data_length = dix_bytes;
2306 }
2307
Christof Schmitt1674b402010-04-30 18:09:34 +02002308 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +02002309 scsi_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002310
2311 if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002312 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002313
Felix Beckef3eb712010-07-16 15:37:42 +02002314 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2315
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002316 retval = zfcp_fsf_req_send(req);
2317 if (unlikely(retval))
2318 goto failed_scsi_cmnd;
2319
2320 goto out;
2321
2322failed_scsi_cmnd:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002323 zfcp_fsf_req_free(req);
2324 scsi_cmnd->host_scribble = NULL;
2325out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002326 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002327 return retval;
2328}
2329
Christof Schmittc61b5362010-09-08 14:39:58 +02002330static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2331{
2332 struct fcp_resp_with_ext *fcp_rsp;
2333 struct fcp_resp_rsp_info *rsp_info;
2334
2335 zfcp_fsf_fcp_handler_common(req);
2336
2337 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2338 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2339
2340 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2341 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2342 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2343}
2344
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002345/**
Christof Schmittb62a8d92010-09-08 14:39:55 +02002346 * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
2347 * @scmnd: SCSI command to send the task management command for
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002349 * Returns: on success pointer to struct fsf_req, NULL otherwise
2350 */
Christof Schmittb62a8d92010-09-08 14:39:55 +02002351struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2352 u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002353{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002354 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002355 struct fcp_cmnd *fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002356 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2357 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002358
Christof Schmittb62a8d92010-09-08 14:39:55 +02002359 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002360 ZFCP_STATUS_COMMON_UNBLOCKED)))
2361 return NULL;
2362
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002363 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002364 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002365 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002366
Swen Schillig564e1c82009-08-18 15:43:19 +02002367 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002368 SBAL_FLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002369 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002370
Swen Schillig633528c2008-11-26 18:07:37 +01002371 if (IS_ERR(req)) {
2372 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002373 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002374 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002375
2376 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002377 req->data = scmnd;
Christof Schmittc61b5362010-09-08 14:39:58 +02002378 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002379 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2380 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002381 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2382 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002383 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002384
Christof Schmitt1674b402010-04-30 18:09:34 +02002385 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002386
Christof Schmitt4318e082009-11-24 16:54:08 +01002387 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
Christof Schmittb62a8d92010-09-08 14:39:55 +02002388 zfcp_fc_fcp_tm(fcp_cmnd, scmnd->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002389
2390 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2391 if (!zfcp_fsf_req_send(req))
2392 goto out;
2393
2394 zfcp_fsf_req_free(req);
2395 req = NULL;
2396out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002397 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002398 return req;
2399}
2400
2401static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2402{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002403}
2404
2405/**
2406 * zfcp_fsf_control_file - control file upload/download
2407 * @adapter: pointer to struct zfcp_adapter
2408 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2409 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002411struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2412 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413{
Swen Schillig564e1c82009-08-18 15:43:19 +02002414 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002415 struct zfcp_fsf_req *req = NULL;
2416 struct fsf_qtcb_bottom_support *bottom;
2417 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Christof Schmitt45633fd2008-06-10 18:20:55 +02002419 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2420 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Christof Schmitt45633fd2008-06-10 18:20:55 +02002422 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2424 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2427 direction = SBAL_FLAGS0_TYPE_READ;
2428 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002430 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 }
2432
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002433 spin_lock_irq(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002434 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002435 goto out;
2436
Christof Schmitt1674b402010-04-30 18:09:34 +02002437 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002438 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002440 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 }
2442
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002443 req->handler = zfcp_fsf_control_file_handler;
2444
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002445 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002447 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Swen Schillig01b04752010-07-16 15:37:37 +02002449 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
2450
Christof Schmitt45633fd2008-06-10 18:20:55 +02002451 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002452 zfcp_fsf_req_free(req);
2453 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002454 }
Felix Beckef3eb712010-07-16 15:37:42 +02002455 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002457 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2458 retval = zfcp_fsf_req_send(req);
2459out:
Christof Schmitt44a24cb2010-09-08 14:39:57 +02002460 spin_unlock_irq(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002461
2462 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002463 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002464 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002466 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002468
2469/**
2470 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2471 * @adapter: pointer to struct zfcp_adapter
2472 * @sbal_idx: response queue index of SBAL to be processed
2473 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002474void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002475{
Swen Schillig564e1c82009-08-18 15:43:19 +02002476 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002477 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002478 struct qdio_buffer_element *sbale;
2479 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002480 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002481 int idx;
2482
2483 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2484
2485 sbale = &sbal->element[idx];
2486 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002487 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002488
Christof Schmitt339f4f42010-07-16 15:37:43 +02002489 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002490 /*
2491 * Unknown request means that we have potentially memory
2492 * corruption and must stop the machine immediately.
2493 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002494 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002495 panic("error: unknown req_id (%lx) on adapter %s.\n",
2496 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002497 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002498
Christof Schmitt34c2b712010-02-17 11:18:59 +01002499 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002500 zfcp_fsf_req_complete(fsf_req);
2501
2502 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2503 break;
2504 }
2505}