blob: ec1b49a7553242d8326a3357d854fed45e9de9a6 [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;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010024 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
25 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020026}
27
28static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
29 unsigned long timeout)
30{
31 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
32 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
33 fsf_req->timer.expires = jiffies + timeout;
34 add_timer(&fsf_req->timer);
35}
36
37static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
38{
39 BUG_ON(!fsf_req->erp_action);
40 fsf_req->timer.function = zfcp_erp_timeout_handler;
41 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
42 fsf_req->timer.expires = jiffies + 30 * HZ;
43 add_timer(&fsf_req->timer);
44}
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/* association between FSF command and FSF QTCB type */
47static u32 fsf_qtcb_type[] = {
48 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
49 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
58 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
59 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
61};
62
Christof Schmitt553448f2008-06-10 18:20:58 +020063static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
64{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020065 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020066 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020067 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020068
Christof Schmittff3b24f2008-10-01 12:42:15 +020069 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020070 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020071 "Access denied according to ACT rule type %s, "
72 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020073}
74
75static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
76 struct zfcp_port *port)
77{
78 struct fsf_qtcb_header *header = &req->qtcb->header;
79 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020080 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020081 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020082 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
83 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010084 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020085 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
86}
87
88static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
89 struct zfcp_unit *unit)
90{
91 struct fsf_qtcb_header *header = &req->qtcb->header;
92 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020093 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020094 (unsigned long long)unit->fcp_lun,
95 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020096 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
97 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010098 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020099 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
100}
101
102static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
103{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200104 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
105 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100106 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200107 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
108}
109
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200110/**
111 * zfcp_fsf_req_free - free memory used by fsf request
112 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200114void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200116 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200117 if (likely(req->qtcb))
118 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200119 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200120 return;
121 }
122
Swen Schilliga4623c42009-08-18 15:43:15 +0200123 if (likely(req->qtcb))
124 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
125 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200128static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Swen Schilligecf0c772009-11-24 16:53:58 +0100130 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200131 struct fsf_status_read_buffer *sr_buf = req->data;
132 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100134 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Swen Schilligecf0c772009-11-24 16:53:58 +0100136 read_lock_irqsave(&adapter->port_list_lock, flags);
137 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200138 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100139 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100140 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200141 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100142 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100145static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200146 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200148 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200150 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
151 return;
152
153 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200154
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100155 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200156
157 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200159
160 switch (link_down->error_code) {
161 case FSF_PSQ_LINK_NO_LIGHT:
162 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200163 "There is no light signal from the local "
164 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200165 break;
166 case FSF_PSQ_LINK_WRAP_PLUG:
167 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200168 "There is a wrap plug instead of a fibre "
169 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200170 break;
171 case FSF_PSQ_LINK_NO_FCP:
172 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200173 "The adjacent fibre channel node does not "
174 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200175 break;
176 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
177 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200178 "The FCP device is suspended because of a "
179 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200180 break;
181 case FSF_PSQ_LINK_INVALID_WWPN:
182 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200183 "The FCP device detected a WWPN that is "
184 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200185 break;
186 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
187 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200188 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200189 break;
190 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
191 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200192 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200193 break;
194 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
195 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200196 "The adjacent switch cannot support "
197 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200198 break;
199 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
200 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200201 "The FCP adapter could not log in to the "
202 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200203 break;
204 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
205 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200206 "The WWPN assignment file on the FCP adapter "
207 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200208 break;
209 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
210 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200211 "The mode table on the FCP adapter "
212 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200213 break;
214 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
215 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200216 "All NPIV ports on the FCP adapter have "
217 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200218 break;
219 default:
220 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200221 "The link between the FCP adapter and "
222 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200223 }
224out:
225 zfcp_erp_adapter_failed(adapter, id, req);
226}
227
228static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
229{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200230 struct fsf_status_read_buffer *sr_buf = req->data;
231 struct fsf_link_down_info *ldi =
232 (struct fsf_link_down_info *) &sr_buf->payload;
233
234 switch (sr_buf->status_subtype) {
235 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100236 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200237 break;
238 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100239 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200240 break;
241 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100242 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200243 };
244}
245
246static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
247{
248 struct zfcp_adapter *adapter = req->adapter;
249 struct fsf_status_read_buffer *sr_buf = req->data;
250
251 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200252 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200253 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200254 zfcp_fsf_req_free(req);
255 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Swen Schillig57717102009-08-18 15:43:21 +0200258 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200259
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200260 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200262 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200265 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200270 dev_warn(&adapter->ccw_device->dev,
271 "The error threshold for checksum statistics "
272 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200273 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200276 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200279 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200280 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100282 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 ZFCP_STATUS_COMMON_RUNNING,
284 ZFCP_SET);
285 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200286 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
287 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100288 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100290 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200291 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100292 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
293 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200294 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100295 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100296 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100298 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200300 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200301 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200302 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200304
Swen Schilliga4623c42009-08-18 15:43:15 +0200305 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200306 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200307
308 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200309 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200312static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200314 switch (req->qtcb->header.fsf_status_qual.word[0]) {
315 case FSF_SQ_FCP_RSP_AVAILABLE:
316 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
317 case FSF_SQ_NO_RETRY_POSSIBLE:
318 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
319 return;
320 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200321 break;
322 case FSF_SQ_NO_RECOM:
323 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200324 "The FCP adapter reported a problem "
325 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100326 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200329 /* all non-return stats set FSFREQ_ERROR*/
330 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
331}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200333static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
334{
335 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
336 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200337
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200338 switch (req->qtcb->header.fsf_status) {
339 case FSF_UNKNOWN_COMMAND:
340 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200341 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200342 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100343 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200344 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200347 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200352static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200354 struct zfcp_adapter *adapter = req->adapter;
355 struct fsf_qtcb *qtcb = req->qtcb;
356 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Swen Schillig57717102009-08-18 15:43:21 +0200358 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200360 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100361 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200362 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200365 switch (qtcb->prefix.prot_status) {
366 case FSF_PROT_GOOD:
367 case FSF_PROT_FSF_STATUS_PRESENTED:
368 return;
369 case FSF_PROT_QTCB_VERSION_ERROR:
370 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200371 "QTCB version 0x%x not supported by FCP adapter "
372 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
373 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100374 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200376 case FSF_PROT_ERROR_STATE:
377 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100378 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100379 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200381 case FSF_PROT_UNSUPP_QTCB_TYPE:
382 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200383 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100384 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200386 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
387 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
388 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200390 case FSF_PROT_DUPLICATE_REQUEST_ID:
391 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200392 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200393 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100394 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200396 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100397 zfcp_fsf_link_down_info_eval(req, "fspse_5",
398 &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100399 /* go through reopen to flush pending requests */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100400 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200402 case FSF_PROT_REEST_QUEUE:
403 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100404 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200405 ZFCP_STATUS_COMMON_RUNNING,
406 ZFCP_SET);
407 zfcp_erp_adapter_reopen(adapter,
408 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100409 ZFCP_STATUS_COMMON_ERP_FAILED,
410 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200411 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200413 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200414 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200415 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100416 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200418 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200422 * zfcp_fsf_req_complete - process completion of a FSF request
423 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200425 * When a request has been completed either from the FCP adapter,
426 * or it has been dismissed due to a queue shutdown, this function
427 * is called to process the completion status and trigger further
428 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200430static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200431{
432 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
433 zfcp_fsf_status_read_handler(req);
434 return;
435 }
436
437 del_timer(&req->timer);
438 zfcp_fsf_protstatus_eval(req);
439 zfcp_fsf_fsfstatus_eval(req);
440 req->handler(req);
441
442 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200443 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200444
445 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
446 zfcp_fsf_req_free(req);
447 else
Swen Schillig058b8642009-08-18 15:43:14 +0200448 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200449}
450
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200451/**
452 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
453 * @adapter: pointer to struct zfcp_adapter
454 *
455 * Never ever call this without shutting down the adapter first.
456 * Otherwise the adapter would continue using and corrupting s390 storage.
457 * Included BUG_ON() call to ensure this is done.
458 * ERP is supposed to be the only user of this function.
459 */
460void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
461{
462 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200463 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200464
465 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100466 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200467
468 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
469 list_del(&req->list);
470 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
471 zfcp_fsf_req_complete(req);
472 }
473}
474
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200475static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100477 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200478 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200479 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100480 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100482 /* adjust pointers for missing command code */
483 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
484 - sizeof(u32));
485 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
486 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200487
488 if (req->data)
489 memcpy(req->data, bottom, sizeof(*bottom));
490
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100491 fc_host_port_name(shost) = nsp->fl_wwpn;
492 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100493 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200494 fc_host_speed(shost) = bottom->fc_link_speed;
495 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
496
497 adapter->hydra_version = bottom->adapter_type;
498 adapter->timer_ticks = bottom->timer_interval;
499
500 if (fc_host_permanent_port_name(shost) == -1)
501 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
502
503 switch (bottom->fc_topology) {
504 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100505 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100506 adapter->peer_wwpn = plogi->fl_wwpn;
507 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200508 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200509 break;
510 case FSF_TOPO_FABRIC:
511 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200512 break;
513 case FSF_TOPO_AL:
514 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200515 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200516 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200518 "Unknown or unsupported arbitrated loop "
519 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100520 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200521 return -EIO;
522 }
523
524 return 0;
525}
526
527static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
528{
529 struct zfcp_adapter *adapter = req->adapter;
530 struct fsf_qtcb *qtcb = req->qtcb;
531 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
532 struct Scsi_Host *shost = adapter->scsi_host;
533
534 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
535 return;
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200538 adapter->adapter_features = bottom->adapter_features;
539 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500540 adapter->peer_wwpn = 0;
541 adapter->peer_wwnn = 0;
542 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200544 switch (qtcb->header.fsf_status) {
545 case FSF_GOOD:
546 if (zfcp_fsf_exchange_config_evaluate(req))
547 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200548
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200549 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
550 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200551 "FCP adapter maximum QTCB size (%d bytes) "
552 "is too small\n",
553 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100554 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200555 return;
556 }
557 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
558 &adapter->status);
559 break;
560 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200561 fc_host_node_name(shost) = 0;
562 fc_host_port_name(shost) = 0;
563 fc_host_port_id(shost) = 0;
564 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100565 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200567
568 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
569 &adapter->status);
570
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100571 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200572 &qtcb->header.fsf_status_qual.link_down_info);
573 break;
574 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100575 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200576 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200579 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200581 memcpy(fc_host_serial_number(shost), bottom->serial_number,
582 min(FC_SERIAL_NUMBER_SIZE, 17));
583 EBCASC(fc_host_serial_number(shost),
584 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200587 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200588 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200589 "The FCP adapter only supports newer "
590 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100591 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200592 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200594 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200595 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200596 "The FCP adapter only supports older "
597 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100598 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200602static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200604 struct zfcp_adapter *adapter = req->adapter;
605 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
606 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200608 if (req->data)
609 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100610
Christof Schmitt02829852009-03-02 13:09:06 +0100611 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100612 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100613 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
614 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100615 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
616 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
617 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100618 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
619 FC_FC4_LIST_SIZE);
620 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
621 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100622}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200624static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200626 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100627
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200628 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return;
630
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200631 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200632 case FSF_GOOD:
633 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200635 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200636 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100637 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200638 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200639 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641}
642
Swen Schillig564e1c82009-08-18 15:43:19 +0200643static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644{
Swen Schillig564e1c82009-08-18 15:43:19 +0200645 struct zfcp_qdio_queue *req_q = &qdio->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200646
Swen Schillig564e1c82009-08-18 15:43:19 +0200647 spin_lock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200648 if (atomic_read(&req_q->count))
649 return 1;
Swen Schillig564e1c82009-08-18 15:43:19 +0200650 spin_unlock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200651 return 0;
652}
653
Swen Schillig564e1c82009-08-18 15:43:19 +0200654static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
Martin Petermann7001f0c2009-04-17 15:08:12 +0200655{
Swen Schillig564e1c82009-08-18 15:43:19 +0200656 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200657 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658
Swen Schillig564e1c82009-08-18 15:43:19 +0200659 spin_unlock_bh(&qdio->req_q_lock);
660 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
661 zfcp_fsf_sbal_check(qdio), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662 if (ret > 0)
663 return 0;
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200664 if (!ret) {
Swen Schillig564e1c82009-08-18 15:43:19 +0200665 atomic_inc(&qdio->req_q_full);
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200666 /* assume hanging outbound queue, try queue recovery */
667 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
668 }
Martin Petermann7001f0c2009-04-17 15:08:12 +0200669
Swen Schillig564e1c82009-08-18 15:43:19 +0200670 spin_lock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200671 return -EIO;
672}
673
Swen Schilliga4623c42009-08-18 15:43:15 +0200674static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200675{
676 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200677
678 if (likely(pool))
679 req = mempool_alloc(pool, GFP_ATOMIC);
680 else
681 req = kmalloc(sizeof(*req), GFP_ATOMIC);
682
683 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200684 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200685
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200686 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100687 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200688 return req;
689}
690
Swen Schilliga4623c42009-08-18 15:43:15 +0200691static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200692{
Swen Schilliga4623c42009-08-18 15:43:15 +0200693 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200694
695 if (likely(pool))
696 qtcb = mempool_alloc(pool, GFP_ATOMIC);
697 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200698 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
699
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200700 if (unlikely(!qtcb))
701 return NULL;
702
703 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200704 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200705}
706
Swen Schillig564e1c82009-08-18 15:43:19 +0200707static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Christof Schmitt1674b402010-04-30 18:09:34 +0200708 u32 fsf_cmd, u32 sbtype,
709 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Swen Schillig564e1c82009-08-18 15:43:19 +0200711 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200712 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200713
714 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200715 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200716
717 if (adapter->req_no == 0)
718 adapter->req_no++;
719
720 INIT_LIST_HEAD(&req->list);
721 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200722 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200723
724 req->adapter = adapter;
725 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100726 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200727
Swen Schilliga4623c42009-08-18 15:43:15 +0200728 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
729 if (likely(pool))
730 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
731 else
732 req->qtcb = zfcp_qtcb_alloc(NULL);
733
734 if (unlikely(!req->qtcb)) {
735 zfcp_fsf_req_free(req);
736 return ERR_PTR(-ENOMEM);
737 }
738
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100739 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200740 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200741 req->qtcb->prefix.req_id = req->req_id;
742 req->qtcb->prefix.ulp_info = 26;
743 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
744 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
745 req->qtcb->header.req_handle = req->req_id;
746 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200747 }
748
Christof Schmitt1674b402010-04-30 18:09:34 +0200749 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
750 req->qtcb, sizeof(struct fsf_qtcb));
751
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200752 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
753 zfcp_fsf_req_free(req);
754 return ERR_PTR(-EIO);
755 }
756
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200757 return req;
758}
759
760static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
761{
762 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200763 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100764 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100765 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200766
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100767 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200768
Christof Schmitt34c2b712010-02-17 11:18:59 +0100769 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200770 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100771 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100773 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100774 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100775 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200776 return -EIO;
777 }
778
779 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200780 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200781 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100782 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200783
784 return 0;
785}
786
787/**
788 * zfcp_fsf_status_read - send status read request
789 * @adapter: pointer to struct zfcp_adapter
790 * @req_flags: request flags
791 * Returns: 0 on success, ERROR otherwise
792 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200793int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200794{
Swen Schillig564e1c82009-08-18 15:43:19 +0200795 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200796 struct zfcp_fsf_req *req;
797 struct fsf_status_read_buffer *sr_buf;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200798 int retval = -EIO;
799
Swen Schillig564e1c82009-08-18 15:43:19 +0200800 spin_lock_bh(&qdio->req_q_lock);
801 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Christof Schmitt1674b402010-04-30 18:09:34 +0200804 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200805 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200806 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200807 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 goto out;
809 }
810
Swen Schilliga4623c42009-08-18 15:43:15 +0200811 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200812 if (!sr_buf) {
813 retval = -ENOMEM;
814 goto failed_buf;
815 }
816 memset(sr_buf, 0, sizeof(*sr_buf));
817 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200818
819 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
820 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200821
822 retval = zfcp_fsf_req_send(req);
823 if (retval)
824 goto failed_req_send;
825
826 goto out;
827
828failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200829 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200830failed_buf:
831 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200832 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200833out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200834 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 return retval;
836}
837
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200838static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200840 struct zfcp_unit *unit = req->data;
841 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200843 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
844 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200846 switch (req->qtcb->header.fsf_status) {
847 case FSF_PORT_HANDLE_NOT_VALID:
848 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100849 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
850 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200851 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200854 case FSF_LUN_HANDLE_NOT_VALID:
855 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100856 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200857 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200860 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
861 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200863 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100864 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100865 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 break;
867 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100868 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200872 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200874 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200875 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200877 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 break;
879 }
880 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
883 break;
884 }
885}
886
887/**
888 * zfcp_fsf_abort_fcp_command - abort running SCSI command
889 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200890 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200891 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200892 */
893
894struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100895 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200896{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200897 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200898 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200899
Swen Schillig564e1c82009-08-18 15:43:19 +0200900 spin_lock_bh(&qdio->req_q_lock);
901 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200902 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200903 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +0200904 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200905 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100906 if (IS_ERR(req)) {
907 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200908 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100909 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200910
911 if (unlikely(!(atomic_read(&unit->status) &
912 ZFCP_STATUS_COMMON_UNBLOCKED)))
913 goto out_error_free;
914
Christof Schmitt1674b402010-04-30 18:09:34 +0200915 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200916
917 req->data = unit;
918 req->handler = zfcp_fsf_abort_fcp_command_handler;
919 req->qtcb->header.lun_handle = unit->handle;
920 req->qtcb->header.port_handle = unit->port->handle;
921 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
922
923 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
924 if (!zfcp_fsf_req_send(req))
925 goto out;
926
927out_error_free:
928 zfcp_fsf_req_free(req);
929 req = NULL;
930out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200931 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200932 return req;
933}
934
935static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
936{
937 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100938 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200939 struct fsf_qtcb_header *header = &req->qtcb->header;
940
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100941 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200942
943 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
944 goto skip_fsfstatus;
945
946 switch (header->fsf_status) {
947 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200948 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100949 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200950 break;
951 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
952 zfcp_fsf_class_not_supp(req);
953 break;
954 case FSF_ADAPTER_STATUS_AVAILABLE:
955 switch (header->fsf_status_qual.word[0]){
956 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200957 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
958 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
959 break;
960 }
961 break;
962 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200963 break;
964 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100965 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200966 break;
967 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100968 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200969 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200970 case FSF_GENERIC_COMMAND_REJECTED:
971 case FSF_PAYLOAD_SIZE_MISMATCH:
972 case FSF_REQUEST_SIZE_TOO_LARGE:
973 case FSF_RESPONSE_SIZE_TOO_LARGE:
974 case FSF_SBAL_MISMATCH:
975 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
976 break;
977 }
978
979skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100980 if (ct->handler)
981 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200982}
983
Christof Schmitt1674b402010-04-30 18:09:34 +0200984static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
985 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200986 struct scatterlist *sg_req,
987 struct scatterlist *sg_resp)
988{
Christof Schmitt1674b402010-04-30 18:09:34 +0200989 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
990 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
991 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200992}
993
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100994static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
995 struct scatterlist *sg_req,
996 struct scatterlist *sg_resp,
997 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200998{
Swen Schillig42428f72009-08-18 15:43:18 +0200999 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig42428f72009-08-18 15:43:18 +02001000 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001001 int bytes;
1002
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001003 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt1674b402010-04-30 18:09:34 +02001004 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
1005 !zfcp_qdio_sg_one_sbale(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001006 return -EOPNOTSUPP;
1007
Christof Schmitt1674b402010-04-30 18:09:34 +02001008 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
1009 sg_req, sg_resp);
Christof Schmitt426f6052009-07-13 15:06:06 +02001010 return 0;
1011 }
1012
1013 /* use single, unchained SBAL if it can hold the request */
Christof Schmitt1674b402010-04-30 18:09:34 +02001014 if (zfcp_qdio_sg_one_sbale(sg_req) || zfcp_qdio_sg_one_sbale(sg_resp)) {
1015 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
1016 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001017 return 0;
1018 }
1019
Christof Schmitt34c2b712010-02-17 11:18:59 +01001020 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001021 sg_req, max_sbals);
1022 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001023 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001024 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt1674b402010-04-30 18:09:34 +02001025 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001026
Christof Schmitt34c2b712010-02-17 11:18:59 +01001027 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001028 sg_resp, max_sbals);
Christof Schmittb1a58982009-09-24 10:23:21 +02001029 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001030 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001031 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001032
Christof Schmittb1a58982009-09-24 10:23:21 +02001033 return 0;
1034}
1035
1036static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1037 struct scatterlist *sg_req,
1038 struct scatterlist *sg_resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001039 int max_sbals, unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001040{
1041 int ret;
1042
1043 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1044 if (ret)
1045 return ret;
1046
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001047 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001048 if (timeout > 255)
1049 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001050 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001051 req->qtcb->bottom.support.timeout = timeout;
1052 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001053
1054 return 0;
1055}
1056
1057/**
1058 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1059 * @ct: pointer to struct zfcp_send_ct with data for request
1060 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001061 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001062int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001063 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1064 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001065{
Swen Schillig564e1c82009-08-18 15:43:19 +02001066 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001067 struct zfcp_fsf_req *req;
1068 int ret = -EIO;
1069
Swen Schillig564e1c82009-08-18 15:43:19 +02001070 spin_lock_bh(&qdio->req_q_lock);
1071 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001072 goto out;
1073
Christof Schmitt1674b402010-04-30 18:09:34 +02001074 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1075 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001076
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001077 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001078 ret = PTR_ERR(req);
1079 goto out;
1080 }
1081
Swen Schillig09a46c62009-08-18 15:43:16 +02001082 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmittb1a58982009-09-24 10:23:21 +02001083 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
Christof Schmitt1674b402010-04-30 18:09:34 +02001084 ZFCP_FSF_MAX_SBALS_PER_REQ, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001085 if (ret)
1086 goto failed_send;
1087
1088 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001089 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001090 req->data = ct;
1091
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001092 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001093
1094 ret = zfcp_fsf_req_send(req);
1095 if (ret)
1096 goto failed_send;
1097
1098 goto out;
1099
1100failed_send:
1101 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001102out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001103 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001104 return ret;
1105}
1106
1107static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1108{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001109 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001110 struct zfcp_port *port = send_els->port;
1111 struct fsf_qtcb_header *header = &req->qtcb->header;
1112
1113 send_els->status = -EINVAL;
1114
1115 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1116 goto skip_fsfstatus;
1117
1118 switch (header->fsf_status) {
1119 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001120 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001121 send_els->status = 0;
1122 break;
1123 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1124 zfcp_fsf_class_not_supp(req);
1125 break;
1126 case FSF_ADAPTER_STATUS_AVAILABLE:
1127 switch (header->fsf_status_qual.word[0]){
1128 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001129 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1130 case FSF_SQ_RETRY_IF_POSSIBLE:
1131 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1132 break;
1133 }
1134 break;
1135 case FSF_ELS_COMMAND_REJECTED:
1136 case FSF_PAYLOAD_SIZE_MISMATCH:
1137 case FSF_REQUEST_SIZE_TOO_LARGE:
1138 case FSF_RESPONSE_SIZE_TOO_LARGE:
1139 break;
1140 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001141 if (port)
1142 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001143 break;
1144 case FSF_SBAL_MISMATCH:
1145 /* should never occure, avoided in zfcp_fsf_send_els */
1146 /* fall through */
1147 default:
1148 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1149 break;
1150 }
1151skip_fsfstatus:
1152 if (send_els->handler)
1153 send_els->handler(send_els->handler_data);
1154}
1155
1156/**
1157 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1158 * @els: pointer to struct zfcp_send_els with data for the command
1159 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001160int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001161 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001162{
1163 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001164 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001165 int ret = -EIO;
1166
Swen Schillig564e1c82009-08-18 15:43:19 +02001167 spin_lock_bh(&qdio->req_q_lock);
1168 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001169 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001170
Christof Schmitt1674b402010-04-30 18:09:34 +02001171 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1172 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001173
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001174 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001175 ret = PTR_ERR(req);
1176 goto out;
1177 }
1178
Swen Schillig09a46c62009-08-18 15:43:16 +02001179 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig51375ee2010-01-14 17:19:02 +01001180 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001181
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001182 if (ret)
1183 goto failed_send;
1184
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001185 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001186 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001187 req->data = els;
1188
Swen Schillig57717102009-08-18 15:43:21 +02001189 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001190
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001191 ret = zfcp_fsf_req_send(req);
1192 if (ret)
1193 goto failed_send;
1194
1195 goto out;
1196
1197failed_send:
1198 zfcp_fsf_req_free(req);
1199out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001200 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001201 return ret;
1202}
1203
1204int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1205{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001207 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001208 int retval = -EIO;
1209
Swen Schillig564e1c82009-08-18 15:43:19 +02001210 spin_lock_bh(&qdio->req_q_lock);
1211 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001212 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001213
Swen Schillig564e1c82009-08-18 15:43:19 +02001214 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001215 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001216 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001217
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001218 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001219 retval = PTR_ERR(req);
1220 goto out;
1221 }
1222
Swen Schillig09a46c62009-08-18 15:43:16 +02001223 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001224 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001225
1226 req->qtcb->bottom.config.feature_selection =
1227 FSF_FEATURE_CFDC |
1228 FSF_FEATURE_LUN_SHARING |
1229 FSF_FEATURE_NOTIFICATION_LOST |
1230 FSF_FEATURE_UPDATE_ALERT;
1231 req->erp_action = erp_action;
1232 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001233 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001234
Christof Schmitt287ac012008-07-02 10:56:40 +02001235 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001236 retval = zfcp_fsf_req_send(req);
1237 if (retval) {
1238 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001239 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001240 }
1241out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001242 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001243 return retval;
1244}
1245
Swen Schillig564e1c82009-08-18 15:43:19 +02001246int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001247 struct fsf_qtcb_bottom_config *data)
1248{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001249 struct zfcp_fsf_req *req = NULL;
1250 int retval = -EIO;
1251
Swen Schillig564e1c82009-08-18 15:43:19 +02001252 spin_lock_bh(&qdio->req_q_lock);
1253 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001254 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001255
Christof Schmitt1674b402010-04-30 18:09:34 +02001256 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1257 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001258
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001259 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001260 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001261 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001262 }
1263
Christof Schmitt1674b402010-04-30 18:09:34 +02001264 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001265 req->handler = zfcp_fsf_exchange_config_data_handler;
1266
1267 req->qtcb->bottom.config.feature_selection =
1268 FSF_FEATURE_CFDC |
1269 FSF_FEATURE_LUN_SHARING |
1270 FSF_FEATURE_NOTIFICATION_LOST |
1271 FSF_FEATURE_UPDATE_ALERT;
1272
1273 if (data)
1274 req->data = data;
1275
1276 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1277 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001278 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001279 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001280 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001281
1282 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001283 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001284
Christof Schmittada81b72009-04-17 15:08:03 +02001285out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001286 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001287 return retval;
1288}
1289
1290/**
1291 * zfcp_fsf_exchange_port_data - request information about local port
1292 * @erp_action: ERP action for the adapter for which port data is requested
1293 * Returns: 0 on success, error otherwise
1294 */
1295int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1296{
Swen Schillig564e1c82009-08-18 15:43:19 +02001297 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001298 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001299 int retval = -EIO;
1300
Swen Schillig564e1c82009-08-18 15:43:19 +02001301 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001302 return -EOPNOTSUPP;
1303
Swen Schillig564e1c82009-08-18 15:43:19 +02001304 spin_lock_bh(&qdio->req_q_lock);
1305 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001306 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001307
Swen Schillig564e1c82009-08-18 15:43:19 +02001308 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001309 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001310 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001311
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001312 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001313 retval = PTR_ERR(req);
1314 goto out;
1315 }
1316
Swen Schillig09a46c62009-08-18 15:43:16 +02001317 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001318 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001319
1320 req->handler = zfcp_fsf_exchange_port_data_handler;
1321 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001322 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323
Christof Schmitt287ac012008-07-02 10:56:40 +02001324 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001325 retval = zfcp_fsf_req_send(req);
1326 if (retval) {
1327 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001328 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 }
1330out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001331 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001332 return retval;
1333}
1334
1335/**
1336 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001337 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001338 * @data: pointer to struct fsf_qtcb_bottom_port
1339 * Returns: 0 on success, error otherwise
1340 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001341int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001342 struct fsf_qtcb_bottom_port *data)
1343{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001344 struct zfcp_fsf_req *req = NULL;
1345 int retval = -EIO;
1346
Swen Schillig564e1c82009-08-18 15:43:19 +02001347 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001348 return -EOPNOTSUPP;
1349
Swen Schillig564e1c82009-08-18 15:43:19 +02001350 spin_lock_bh(&qdio->req_q_lock);
1351 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001352 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001353
Christof Schmitt1674b402010-04-30 18:09:34 +02001354 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1355 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001356
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001357 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001358 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001359 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001360 }
1361
1362 if (data)
1363 req->data = data;
1364
Christof Schmitt1674b402010-04-30 18:09:34 +02001365 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001366
1367 req->handler = zfcp_fsf_exchange_port_data_handler;
1368 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1369 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001370 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001371
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001372 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001373 wait_for_completion(&req->completion);
1374
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001375 zfcp_fsf_req_free(req);
1376
1377 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001378
1379out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001380 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001381 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001382}
1383
1384static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1385{
1386 struct zfcp_port *port = req->data;
1387 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001388 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001389
1390 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001391 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001392
1393 switch (header->fsf_status) {
1394 case FSF_PORT_ALREADY_OPEN:
1395 break;
1396 case FSF_ACCESS_DENIED:
1397 zfcp_fsf_access_denied_port(req, port);
1398 break;
1399 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1400 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001401 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001402 "remote port 0x%016Lx\n",
1403 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001404 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001405 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1406 break;
1407 case FSF_ADAPTER_STATUS_AVAILABLE:
1408 switch (header->fsf_status_qual.word[0]) {
1409 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1410 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001411 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001412 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1413 break;
1414 }
1415 break;
1416 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1419 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001420 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1421 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1422 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 /* check whether D_ID has changed during open */
1424 /*
1425 * FIXME: This check is not airtight, as the FCP channel does
1426 * not monitor closures of target port connections caused on
1427 * the remote side. Thus, they might miss out on invalidating
1428 * locally cached WWPNs (and other N_Port parameters) of gone
1429 * target ports. So, our heroic attempt to make things safe
1430 * could be undermined by 'open port' response data tagged with
1431 * obsolete WWPNs. Another reason to monitor potential
1432 * connection closures ourself at least (by interpreting
1433 * incoming ELS' and unsolicited status). It just crosses my
1434 * mind that one should be able to cross-check by means of
1435 * another GID_PN straight after a port has been opened.
1436 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1437 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001438 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001439 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001440 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001441 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001444 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 break;
1446 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001447
1448out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001449 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450}
1451
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001452/**
1453 * zfcp_fsf_open_port - create and send open port request
1454 * @erp_action: pointer to struct zfcp_erp_action
1455 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001457int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
Swen Schillig564e1c82009-08-18 15:43:19 +02001459 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001460 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001461 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001462 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Swen Schillig564e1c82009-08-18 15:43:19 +02001464 spin_lock_bh(&qdio->req_q_lock);
1465 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Swen Schillig564e1c82009-08-18 15:43:19 +02001468 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001469 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001470 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001471
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001472 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001473 retval = PTR_ERR(req);
1474 goto out;
1475 }
1476
Swen Schillig09a46c62009-08-18 15:43:16 +02001477 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001478 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001480 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001481 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001482 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001483 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001484 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001485 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Christof Schmitt287ac012008-07-02 10:56:40 +02001487 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001488 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001490 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001491 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001492 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001495 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return retval;
1497}
1498
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001499static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001501 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001503 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001504 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001506 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001508 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001509 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001514 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 ZFCP_STATUS_COMMON_OPEN,
1516 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001521/**
1522 * zfcp_fsf_close_port - create and send close port request
1523 * @erp_action: pointer to struct zfcp_erp_action
1524 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001526int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
Swen Schillig564e1c82009-08-18 15:43:19 +02001528 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001529 struct zfcp_fsf_req *req;
1530 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Swen Schillig564e1c82009-08-18 15:43:19 +02001532 spin_lock_bh(&qdio->req_q_lock);
1533 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Swen Schillig564e1c82009-08-18 15:43:19 +02001536 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001537 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001538 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001539
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001540 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001541 retval = PTR_ERR(req);
1542 goto out;
1543 }
1544
Swen Schillig09a46c62009-08-18 15:43:16 +02001545 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001546 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001548 req->handler = zfcp_fsf_close_port_handler;
1549 req->data = erp_action->port;
1550 req->erp_action = erp_action;
1551 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001552 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Christof Schmitt287ac012008-07-02 10:56:40 +02001554 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001555 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001557 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001558 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001560out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001561 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 return retval;
1563}
1564
Swen Schillig5ab944f2008-10-01 12:42:17 +02001565static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1566{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001567 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001568 struct fsf_qtcb_header *header = &req->qtcb->header;
1569
1570 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001571 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001572 goto out;
1573 }
1574
1575 switch (header->fsf_status) {
1576 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1577 dev_warn(&req->adapter->ccw_device->dev,
1578 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001579 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001580 case FSF_ADAPTER_STATUS_AVAILABLE:
1581 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001582 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001583 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001584 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001585 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001586 case FSF_GOOD:
1587 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001588 /* fall through */
1589 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001590 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001591 }
1592out:
1593 wake_up(&wka_port->completion_wq);
1594}
1595
1596/**
1597 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001598 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001599 * Returns: 0 on success, error otherwise
1600 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001601int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001602{
Swen Schillig564e1c82009-08-18 15:43:19 +02001603 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001604 struct zfcp_fsf_req *req;
1605 int retval = -EIO;
1606
Swen Schillig564e1c82009-08-18 15:43:19 +02001607 spin_lock_bh(&qdio->req_q_lock);
1608 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001609 goto out;
1610
Swen Schillig564e1c82009-08-18 15:43:19 +02001611 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001612 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001613 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001614
Swen Schillig5ab944f2008-10-01 12:42:17 +02001615 if (unlikely(IS_ERR(req))) {
1616 retval = PTR_ERR(req);
1617 goto out;
1618 }
1619
Swen Schillig09a46c62009-08-18 15:43:16 +02001620 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001621 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001622
1623 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001624 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001625 req->data = wka_port;
1626
1627 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1628 retval = zfcp_fsf_req_send(req);
1629 if (retval)
1630 zfcp_fsf_req_free(req);
1631out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001632 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001633 return retval;
1634}
1635
1636static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1637{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001638 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001639
1640 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1641 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001642 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001643 }
1644
Christof Schmittbd0072e2009-11-24 16:54:11 +01001645 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001646 wake_up(&wka_port->completion_wq);
1647}
1648
1649/**
1650 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001651 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001652 * Returns: 0 on success, error otherwise
1653 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001654int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001655{
Swen Schillig564e1c82009-08-18 15:43:19 +02001656 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001657 struct zfcp_fsf_req *req;
1658 int retval = -EIO;
1659
Swen Schillig564e1c82009-08-18 15:43:19 +02001660 spin_lock_bh(&qdio->req_q_lock);
1661 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001662 goto out;
1663
Swen Schillig564e1c82009-08-18 15:43:19 +02001664 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001665 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001666 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001667
Swen Schillig5ab944f2008-10-01 12:42:17 +02001668 if (unlikely(IS_ERR(req))) {
1669 retval = PTR_ERR(req);
1670 goto out;
1671 }
1672
Swen Schillig09a46c62009-08-18 15:43:16 +02001673 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001674 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001675
1676 req->handler = zfcp_fsf_close_wka_port_handler;
1677 req->data = wka_port;
1678 req->qtcb->header.port_handle = wka_port->handle;
1679
1680 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1681 retval = zfcp_fsf_req_send(req);
1682 if (retval)
1683 zfcp_fsf_req_free(req);
1684out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001685 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001686 return retval;
1687}
1688
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001689static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001691 struct zfcp_port *port = req->data;
1692 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001695 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001696 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001700 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001701 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001704 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001707 /* can't use generic zfcp_erp_modify_port_status because
1708 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1709 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001710 read_lock(&port->unit_list_lock);
1711 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001712 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1713 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001714 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001715 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001716 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 switch (header->fsf_status_qual.word[0]) {
1720 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001721 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001723 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 }
1726 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 /* can't use generic zfcp_erp_modify_port_status because
1729 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1730 */
1731 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001732 read_lock(&port->unit_list_lock);
1733 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001734 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1735 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001736 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739}
1740
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001741/**
1742 * zfcp_fsf_close_physical_port - close physical port
1743 * @erp_action: pointer to struct zfcp_erp_action
1744 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001746int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
Swen Schillig564e1c82009-08-18 15:43:19 +02001748 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001749 struct zfcp_fsf_req *req;
1750 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Swen Schillig564e1c82009-08-18 15:43:19 +02001752 spin_lock_bh(&qdio->req_q_lock);
1753 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Swen Schillig564e1c82009-08-18 15:43:19 +02001756 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001757 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001758 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001759
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001760 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001761 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 goto out;
1763 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001764
Swen Schillig09a46c62009-08-18 15:43:16 +02001765 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001766 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001767
1768 req->data = erp_action->port;
1769 req->qtcb->header.port_handle = erp_action->port->handle;
1770 req->erp_action = erp_action;
1771 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001772 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001773
Christof Schmitt287ac012008-07-02 10:56:40 +02001774 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001775 retval = zfcp_fsf_req_send(req);
1776 if (retval) {
1777 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001778 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001779 }
1780out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001781 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return retval;
1783}
1784
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001785static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001787 struct zfcp_adapter *adapter = req->adapter;
1788 struct zfcp_unit *unit = req->data;
1789 struct fsf_qtcb_header *header = &req->qtcb->header;
1790 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1791 struct fsf_queue_designator *queue_designator =
1792 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001793 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001795 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001796 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001799 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ZFCP_STATUS_UNIT_SHARED |
1801 ZFCP_STATUS_UNIT_READONLY,
1802 &unit->status);
1803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 switch (header->fsf_status) {
1805
1806 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001807 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001808 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001812 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001814 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001817 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001818 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001821 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001822 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001823 "LUN 0x%Lx on port 0x%Lx is already in "
1824 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001825 (unsigned long long)unit->fcp_lun,
1826 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001827 queue_designator->cssid,
1828 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001829 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001830 zfcp_act_eval_err(adapter,
1831 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001832 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1834 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001835 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001838 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001839 "No handle is available for LUN "
1840 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001841 (unsigned long long)unit->fcp_lun,
1842 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001843 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001844 /* fall through */
1845 case FSF_INVALID_COMMAND_OPTION:
1846 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 switch (header->fsf_status_qual.word[0]) {
1850 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001851 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001852 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001854 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 }
1857 break;
1858
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001862
1863 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1864 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001865 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001866 exclusive = (bottom->lun_access_info &
1867 FSF_UNIT_ACCESS_EXCLUSIVE);
1868 readwrite = (bottom->lun_access_info &
1869 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1870
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 if (!exclusive)
1872 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1873 &unit->status);
1874
1875 if (!readwrite) {
1876 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1877 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001878 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001879 "SCSI device at LUN 0x%016Lx on port "
1880 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001881 (unsigned long long)unit->fcp_lun,
1882 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
1884
1885 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001887 "Exclusive read-only access not "
1888 "supported (unit 0x%016Lx, "
1889 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001890 (unsigned long long)unit->fcp_lun,
1891 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001892 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001893 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001894 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001896 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001897 "Shared read-write access not "
1898 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001899 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001900 (unsigned long long)unit->fcp_lun,
1901 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001902 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001903 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001904 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 }
1906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909}
1910
1911/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001912 * zfcp_fsf_open_unit - open unit
1913 * @erp_action: pointer to struct zfcp_erp_action
1914 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001916int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001918 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001919 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001920 struct zfcp_fsf_req *req;
1921 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Swen Schillig564e1c82009-08-18 15:43:19 +02001923 spin_lock_bh(&qdio->req_q_lock);
1924 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001925 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Swen Schillig564e1c82009-08-18 15:43:19 +02001927 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001928 SBAL_FLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001929 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001930
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001931 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001932 retval = PTR_ERR(req);
1933 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001934 }
1935
Swen Schillig09a46c62009-08-18 15:43:16 +02001936 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001937 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001939 req->qtcb->header.port_handle = erp_action->port->handle;
1940 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1941 req->handler = zfcp_fsf_open_unit_handler;
1942 req->data = erp_action->unit;
1943 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001944 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001945
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001946 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1947 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Christof Schmitt287ac012008-07-02 10:56:40 +02001949 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001950 retval = zfcp_fsf_req_send(req);
1951 if (retval) {
1952 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001953 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001955out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001956 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 return retval;
1958}
1959
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001960static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001962 struct zfcp_unit *unit = req->data;
1963
1964 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001965 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001966
1967 switch (req->qtcb->header.fsf_status) {
1968 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001969 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001970 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1971 break;
1972 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001973 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001974 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1975 break;
1976 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001977 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001978 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001979 break;
1980 case FSF_ADAPTER_STATUS_AVAILABLE:
1981 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1982 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001983 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001984 /* fall through */
1985 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1986 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1987 break;
1988 }
1989 break;
1990 case FSF_GOOD:
1991 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1992 break;
1993 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001994}
1995
1996/**
1997 * zfcp_fsf_close_unit - close zfcp unit
1998 * @erp_action: pointer to struct zfcp_unit
1999 * Returns: 0 on success, error otherwise
2000 */
2001int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2002{
Swen Schillig564e1c82009-08-18 15:43:19 +02002003 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002004 struct zfcp_fsf_req *req;
2005 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Swen Schillig564e1c82009-08-18 15:43:19 +02002007 spin_lock_bh(&qdio->req_q_lock);
2008 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002010
Swen Schillig564e1c82009-08-18 15:43:19 +02002011 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02002012 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02002013 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002014
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002015 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002016 retval = PTR_ERR(req);
2017 goto out;
2018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Swen Schillig09a46c62009-08-18 15:43:16 +02002020 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02002021 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002023 req->qtcb->header.port_handle = erp_action->port->handle;
2024 req->qtcb->header.lun_handle = erp_action->unit->handle;
2025 req->handler = zfcp_fsf_close_unit_handler;
2026 req->data = erp_action->unit;
2027 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002028 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Christof Schmitt287ac012008-07-02 10:56:40 +02002030 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002031 retval = zfcp_fsf_req_send(req);
2032 if (retval) {
2033 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002034 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002035 }
2036out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002037 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002038 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039}
2040
Christof Schmittc9615852008-05-06 11:00:05 +02002041static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2042{
2043 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002044 lat_rec->min = min(lat_rec->min, lat);
2045 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002046}
2047
Christof Schmittd9742b42009-11-24 16:54:03 +01002048static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002049{
Christof Schmittd9742b42009-11-24 16:54:03 +01002050 struct fsf_qual_latency_info *lat_in;
2051 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002052 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002053 struct zfcp_blk_drv_data blktrc;
2054 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002055
Christof Schmittd9742b42009-11-24 16:54:03 +01002056 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002057
Christof Schmittd9742b42009-11-24 16:54:03 +01002058 blktrc.flags = 0;
2059 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2060 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2061 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002062 blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
2063 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002064
2065 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2066 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2067 blktrc.channel_lat = lat_in->channel_lat * ticks;
2068 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2069
2070 switch (req->qtcb->bottom.io.data_direction) {
2071 case FSF_DATADIR_READ:
2072 lat = &unit->latencies.read;
2073 break;
2074 case FSF_DATADIR_WRITE:
2075 lat = &unit->latencies.write;
2076 break;
2077 case FSF_DATADIR_CMND:
2078 lat = &unit->latencies.cmd;
2079 break;
2080 }
2081
2082 if (lat) {
2083 spin_lock(&unit->latencies.lock);
2084 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2085 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2086 lat->counter++;
2087 spin_unlock(&unit->latencies.lock);
2088 }
Christof Schmittc9615852008-05-06 11:00:05 +02002089 }
2090
Christof Schmittd9742b42009-11-24 16:54:03 +01002091 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2092 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002093}
2094
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002095static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002097 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002098 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002101 read_lock_irqsave(&req->adapter->abort_lock, flags);
2102
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002103 scpnt = req->data;
2104 if (unlikely(!scpnt)) {
2105 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2106 return;
2107 }
2108
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002109 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002110 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 goto skip_fsfstatus;
2112 }
2113
Christof Schmitt4318e082009-11-24 16:54:08 +01002114 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2115 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Christof Schmittd9742b42009-11-24 16:54:03 +01002117 zfcp_fsf_req_trace(req, scpnt);
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002118
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002119skip_fsfstatus:
Christof Schmittab725282010-02-17 11:18:57 +01002120 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 /*
2125 * We must hold this lock until scsi_done has been called.
2126 * Otherwise we may call scsi_done after abort regarding this
2127 * command has completed.
2128 * Note: scsi_done must not block!
2129 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002130 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002133static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
Christof Schmitt4318e082009-11-24 16:54:08 +01002135 struct fcp_resp_with_ext *fcp_rsp;
2136 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Christof Schmitt4318e082009-11-24 16:54:08 +01002138 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2139 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2140
2141 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002142 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2143 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
2146
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002147static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2148{
2149 struct zfcp_unit *unit;
2150 struct fsf_qtcb_header *header = &req->qtcb->header;
2151
2152 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2153 unit = req->data;
2154 else
2155 unit = req->unit;
2156
2157 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2158 goto skip_fsfstatus;
2159
2160 switch (header->fsf_status) {
2161 case FSF_HANDLE_MISMATCH:
2162 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002163 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002164 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2165 break;
2166 case FSF_FCPLUN_NOT_VALID:
2167 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002168 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002169 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2170 break;
2171 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2172 zfcp_fsf_class_not_supp(req);
2173 break;
2174 case FSF_ACCESS_DENIED:
2175 zfcp_fsf_access_denied_unit(req, unit);
2176 break;
2177 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2178 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002179 "Incorrect direction %d, unit 0x%016Lx on port "
2180 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002181 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002182 (unsigned long long)unit->fcp_lun,
2183 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002184 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2185 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002186 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2187 break;
2188 case FSF_CMND_LENGTH_NOT_VALID:
2189 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002190 "Incorrect CDB length %d, unit 0x%016Lx on "
2191 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002192 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002193 (unsigned long long)unit->fcp_lun,
2194 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002195 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2196 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002197 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2198 break;
2199 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002200 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002201 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002202 break;
2203 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002204 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002205 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002206 break;
2207 case FSF_ADAPTER_STATUS_AVAILABLE:
2208 if (header->fsf_status_qual.word[0] ==
2209 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002210 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002211 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2212 break;
2213 }
2214skip_fsfstatus:
2215 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2216 zfcp_fsf_send_fcp_ctm_handler(req);
2217 else {
2218 zfcp_fsf_send_fcp_command_task_handler(req);
2219 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002220 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002221 }
2222}
2223
2224/**
2225 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002226 * @unit: unit where command is sent to
2227 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002228 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002229int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2230 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002231{
2232 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002233 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002234 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002235 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002236 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002237 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002238
2239 if (unlikely(!(atomic_read(&unit->status) &
2240 ZFCP_STATUS_COMMON_UNBLOCKED)))
2241 return -EBUSY;
2242
Swen Schillig564e1c82009-08-18 15:43:19 +02002243 spin_lock(&qdio->req_q_lock);
2244 if (atomic_read(&qdio->req_q.count) <= 0) {
2245 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002246 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002247 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002248
Christof Schmitt1674b402010-04-30 18:09:34 +02002249 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2250 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2251
Swen Schillig564e1c82009-08-18 15:43:19 +02002252 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002253 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002254
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002255 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256 retval = PTR_ERR(req);
2257 goto out;
2258 }
2259
Swen Schillig09a46c62009-08-18 15:43:16 +02002260 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002261 req->unit = unit;
2262 req->data = scsi_cmnd;
2263 req->handler = zfcp_fsf_send_fcp_command_handler;
2264 req->qtcb->header.lun_handle = unit->handle;
2265 req->qtcb->header.port_handle = unit->port->handle;
2266 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002267 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002268
2269 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2270
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002271 /*
2272 * set depending on data direction:
2273 * data direction bits in SBALE (SB Type)
2274 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002275 */
2276 switch (scsi_cmnd->sc_data_direction) {
2277 case DMA_NONE:
2278 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002279 break;
2280 case DMA_FROM_DEVICE:
2281 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002282 break;
2283 case DMA_TO_DEVICE:
2284 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002285 break;
2286 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002287 goto failed_scsi_cmnd;
2288 }
2289
Christof Schmitt1674b402010-04-30 18:09:34 +02002290 get_device(&unit->dev);
2291
Christof Schmitt4318e082009-11-24 16:54:08 +01002292 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2293 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002294
Christof Schmitt1674b402010-04-30 18:09:34 +02002295 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002296 scsi_sglist(scsi_cmnd),
Christof Schmitt1674b402010-04-30 18:09:34 +02002297 ZFCP_FSF_MAX_SBALS_PER_REQ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002298 if (unlikely(real_bytes < 0)) {
Christof Schmitt1674b402010-04-30 18:09:34 +02002299 if (req->qdio_req.sbal_number >= ZFCP_FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002300 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002301 "Oversize data package, unit 0x%016Lx "
2302 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002303 (unsigned long long)unit->fcp_lun,
2304 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002305 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002306 retval = -EINVAL;
2307 }
2308 goto failed_scsi_cmnd;
2309 }
2310
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002311 retval = zfcp_fsf_req_send(req);
2312 if (unlikely(retval))
2313 goto failed_scsi_cmnd;
2314
2315 goto out;
2316
2317failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002318 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002319 zfcp_fsf_req_free(req);
2320 scsi_cmnd->host_scribble = NULL;
2321out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002322 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002323 return retval;
2324}
2325
2326/**
2327 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002328 * @unit: pointer to struct zfcp_unit
2329 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002330 * Returns: on success pointer to struct fsf_req, NULL otherwise
2331 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002332struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002333{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002334 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002335 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002336 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002337
2338 if (unlikely(!(atomic_read(&unit->status) &
2339 ZFCP_STATUS_COMMON_UNBLOCKED)))
2340 return NULL;
2341
Swen Schillig564e1c82009-08-18 15:43:19 +02002342 spin_lock_bh(&qdio->req_q_lock);
2343 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002344 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002345
Swen Schillig564e1c82009-08-18 15:43:19 +02002346 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002347 SBAL_FLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002348 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002349
Swen Schillig633528c2008-11-26 18:07:37 +01002350 if (IS_ERR(req)) {
2351 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002352 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002353 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002354
2355 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2356 req->data = unit;
2357 req->handler = zfcp_fsf_send_fcp_command_handler;
2358 req->qtcb->header.lun_handle = unit->handle;
2359 req->qtcb->header.port_handle = unit->port->handle;
2360 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2361 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002362 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002363
Christof Schmitt1674b402010-04-30 18:09:34 +02002364 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002365
Christof Schmitt4318e082009-11-24 16:54:08 +01002366 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2367 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002368
2369 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2370 if (!zfcp_fsf_req_send(req))
2371 goto out;
2372
2373 zfcp_fsf_req_free(req);
2374 req = NULL;
2375out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002376 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002377 return req;
2378}
2379
2380static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2381{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002382}
2383
2384/**
2385 * zfcp_fsf_control_file - control file upload/download
2386 * @adapter: pointer to struct zfcp_adapter
2387 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2388 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002390struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2391 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392{
Swen Schillig564e1c82009-08-18 15:43:19 +02002393 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002394 struct zfcp_fsf_req *req = NULL;
2395 struct fsf_qtcb_bottom_support *bottom;
2396 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Christof Schmitt45633fd2008-06-10 18:20:55 +02002398 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2399 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
Christof Schmitt45633fd2008-06-10 18:20:55 +02002401 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2403 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2406 direction = SBAL_FLAGS0_TYPE_READ;
2407 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002409 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 }
2411
Swen Schillig564e1c82009-08-18 15:43:19 +02002412 spin_lock_bh(&qdio->req_q_lock);
2413 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002414 goto out;
2415
Christof Schmitt1674b402010-04-30 18:09:34 +02002416 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002417 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002419 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 }
2421
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002422 req->handler = zfcp_fsf_control_file_handler;
2423
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002424 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002426 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Christof Schmitt34c2b712010-02-17 11:18:59 +01002428 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +02002429 fsf_cfdc->sg,
2430 ZFCP_FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002431 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002432 zfcp_fsf_req_free(req);
2433 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002436 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2437 retval = zfcp_fsf_req_send(req);
2438out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002439 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002440
2441 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002442 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002443 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002445 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002447
2448/**
2449 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2450 * @adapter: pointer to struct zfcp_adapter
2451 * @sbal_idx: response queue index of SBAL to be processed
2452 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002453void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002454{
Swen Schillig564e1c82009-08-18 15:43:19 +02002455 struct zfcp_adapter *adapter = qdio->adapter;
2456 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002457 struct qdio_buffer_element *sbale;
2458 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002459 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002460 int idx;
2461
2462 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2463
2464 sbale = &sbal->element[idx];
2465 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002466 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002467
2468 if (!fsf_req)
2469 /*
2470 * Unknown request means that we have potentially memory
2471 * corruption and must stop the machine immediately.
2472 */
2473 panic("error: unknown req_id (%lx) on adapter %s.\n",
2474 req_id, dev_name(&adapter->ccw_device->dev));
2475
Christof Schmitt34c2b712010-02-17 11:18:59 +01002476 fsf_req->qdio_req.sbal_response = sbal_idx;
2477 fsf_req->qdio_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002478 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002479 zfcp_fsf_req_complete(fsf_req);
2480
2481 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2482 break;
2483 }
2484}