blob: 3f365ace7711cafcb6c3cd341076d1bbb3a8e737 [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 Schmitta2fa0ae2009-03-02 13:09:08 +01006 * Copyright IBM Corporation 2002, 2009
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "zfcp_ext.h"
14
Christof Schmitt63caf362009-03-02 13:09:00 +010015#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
16#define ZFCP_REQ_NO_QTCB 0x00000008
17
Christof Schmitt287ac012008-07-02 10:56:40 +020018static void zfcp_fsf_request_timeout_handler(unsigned long data)
19{
20 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010021 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
22 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020023}
24
25static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
26 unsigned long timeout)
27{
28 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
29 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
30 fsf_req->timer.expires = jiffies + timeout;
31 add_timer(&fsf_req->timer);
32}
33
34static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
35{
36 BUG_ON(!fsf_req->erp_action);
37 fsf_req->timer.function = zfcp_erp_timeout_handler;
38 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
39 fsf_req->timer.expires = jiffies + 30 * HZ;
40 add_timer(&fsf_req->timer);
41}
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/* association between FSF command and FSF QTCB type */
44static u32 fsf_qtcb_type[] = {
45 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
46 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
55 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
56 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
58};
59
Christof Schmitt553448f2008-06-10 18:20:58 +020060static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
61{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020062 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020063 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020064 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020065
Christof Schmittff3b24f2008-10-01 12:42:15 +020066 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020067 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020068 "Access denied according to ACT rule type %s, "
69 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020070}
71
72static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
73 struct zfcp_port *port)
74{
75 struct fsf_qtcb_header *header = &req->qtcb->header;
76 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020077 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020078 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020079 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
80 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010081 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020082 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
83}
84
85static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
86 struct zfcp_unit *unit)
87{
88 struct fsf_qtcb_header *header = &req->qtcb->header;
89 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020090 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020091 (unsigned long long)unit->fcp_lun,
92 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020093 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010095 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020096 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
97}
98
99static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
100{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200101 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
102 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100103 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
105}
106
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200107/**
108 * zfcp_fsf_req_free - free memory used by fsf request
109 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200111void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200113 if (likely(req->pool)) {
114 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200115 return;
116 }
117
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200118 if (req->qtcb) {
119 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200120 return;
121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200124/**
125 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
126 * @adapter: pointer to struct zfcp_adapter
127 *
Martin Peschke869b2b42007-05-09 11:01:20 +0200128 * Never ever call this without shutting down the adapter first.
129 * Otherwise the adapter would continue using and corrupting s390 storage.
130 * Included BUG_ON() call to ensure this is done.
131 * ERP is supposed to be the only user of this function.
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200132 */
Swen Schillig6fcc4712007-02-07 13:17:57 +0100133void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200134{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200135 struct zfcp_fsf_req *req, *tmp;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200136 unsigned long flags;
Swen Schillig6fcc4712007-02-07 13:17:57 +0100137 LIST_HEAD(remove_queue);
Martin Peschke869b2b42007-05-09 11:01:20 +0200138 unsigned int i;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200139
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200140 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200141 spin_lock_irqsave(&adapter->req_list_lock, flags);
Martin Peschke869b2b42007-05-09 11:01:20 +0200142 for (i = 0; i < REQUEST_LIST_SIZE; i++)
Swen Schillig6fcc4712007-02-07 13:17:57 +0100143 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200144 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
145
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200146 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
147 list_del(&req->list);
148 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
149 zfcp_fsf_req_complete(req);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100150 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200151}
152
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200153static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200155 struct fsf_status_read_buffer *sr_buf = req->data;
156 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 struct zfcp_port *port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200158 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 unsigned long flags;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 read_lock_irqsave(&zfcp_data.config_lock, flags);
162 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200163 if (port->d_id == d_id) {
164 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100165 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200166 return;
167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100171static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200172 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200174 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200176 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
177 return;
178
179 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100180 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200181
182 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200184
185 switch (link_down->error_code) {
186 case FSF_PSQ_LINK_NO_LIGHT:
187 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200188 "There is no light signal from the local "
189 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200190 break;
191 case FSF_PSQ_LINK_WRAP_PLUG:
192 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200193 "There is a wrap plug instead of a fibre "
194 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200195 break;
196 case FSF_PSQ_LINK_NO_FCP:
197 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200198 "The adjacent fibre channel node does not "
199 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200200 break;
201 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
202 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200203 "The FCP device is suspended because of a "
204 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200205 break;
206 case FSF_PSQ_LINK_INVALID_WWPN:
207 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200208 "The FCP device detected a WWPN that is "
209 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200210 break;
211 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
212 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200213 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200214 break;
215 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
216 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200217 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200218 break;
219 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
220 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200221 "The adjacent switch cannot support "
222 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200223 break;
224 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
225 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200226 "The FCP adapter could not log in to the "
227 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200228 break;
229 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
230 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200231 "The WWPN assignment file on the FCP adapter "
232 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200233 break;
234 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
235 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200236 "The mode table on the FCP adapter "
237 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200238 break;
239 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
240 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200241 "All NPIV ports on the FCP adapter have "
242 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200243 break;
244 default:
245 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200246 "The link between the FCP adapter and "
247 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200248 }
249out:
250 zfcp_erp_adapter_failed(adapter, id, req);
251}
252
253static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
254{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200255 struct fsf_status_read_buffer *sr_buf = req->data;
256 struct fsf_link_down_info *ldi =
257 (struct fsf_link_down_info *) &sr_buf->payload;
258
259 switch (sr_buf->status_subtype) {
260 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100261 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200262 break;
263 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100264 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200265 break;
266 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100267 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200268 };
269}
270
271static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
272{
273 struct zfcp_adapter *adapter = req->adapter;
274 struct fsf_status_read_buffer *sr_buf = req->data;
275
276 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
277 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
278 mempool_free(sr_buf, adapter->pool.data_status_read);
279 zfcp_fsf_req_free(req);
280 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200283 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200284
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200285 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200287 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200290 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200295 dev_warn(&adapter->ccw_device->dev,
296 "The error threshold for checksum statistics "
297 "has been exceeded\n");
Swen Schillig57069382008-10-01 12:42:21 +0200298 zfcp_hba_dbf_event_berr(adapter, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200301 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200304 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200305 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100307 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 ZFCP_STATUS_COMMON_RUNNING,
309 ZFCP_SET);
310 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200311 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
312 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100313 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100315 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200316 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100317 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
318 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200319 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200320 schedule_work(&adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100321 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100323 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200325 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200326 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200329
330 mempool_free(sr_buf, adapter->pool.data_status_read);
331 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200332
333 atomic_inc(&adapter->stat_miss);
Swen Schilligb7f15f32008-10-01 12:42:22 +0200334 queue_work(zfcp_data.work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200337static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200339 switch (req->qtcb->header.fsf_status_qual.word[0]) {
340 case FSF_SQ_FCP_RSP_AVAILABLE:
341 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
342 case FSF_SQ_NO_RETRY_POSSIBLE:
343 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
344 return;
345 case FSF_SQ_COMMAND_ABORTED:
346 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
347 break;
348 case FSF_SQ_NO_RECOM:
349 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200350 "The FCP adapter reported a problem "
351 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100352 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200353 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200355 /* all non-return stats set FSFREQ_ERROR*/
356 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
357}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200359static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
360{
361 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
362 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200363
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200364 switch (req->qtcb->header.fsf_status) {
365 case FSF_UNKNOWN_COMMAND:
366 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200367 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200368 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100369 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200370 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200373 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200378static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200380 struct zfcp_adapter *adapter = req->adapter;
381 struct fsf_qtcb *qtcb = req->qtcb;
382 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200384 zfcp_hba_dbf_event_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200386 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
387 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
388 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
389 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200392 switch (qtcb->prefix.prot_status) {
393 case FSF_PROT_GOOD:
394 case FSF_PROT_FSF_STATUS_PRESENTED:
395 return;
396 case FSF_PROT_QTCB_VERSION_ERROR:
397 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200398 "QTCB version 0x%x not supported by FCP adapter "
399 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
400 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100401 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200403 case FSF_PROT_ERROR_STATE:
404 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100405 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200406 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200408 case FSF_PROT_UNSUPP_QTCB_TYPE:
409 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200410 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100411 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200413 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
414 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
415 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200417 case FSF_PROT_DUPLICATE_REQUEST_ID:
418 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200419 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200420 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100421 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200423 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100424 zfcp_fsf_link_down_info_eval(req, "fspse_5",
425 &psq->link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200426 /* FIXME: reopening adapter now? better wait for link up */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100427 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200429 case FSF_PROT_REEST_QUEUE:
430 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100431 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200432 ZFCP_STATUS_COMMON_RUNNING,
433 ZFCP_SET);
434 zfcp_erp_adapter_reopen(adapter,
435 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100436 ZFCP_STATUS_COMMON_ERP_FAILED,
437 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200438 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200440 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200441 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200442 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100443 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200445 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
448/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200449 * zfcp_fsf_req_complete - process completion of a FSF request
450 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200452 * When a request has been completed either from the FCP adapter,
453 * or it has been dismissed due to a queue shutdown, this function
454 * is called to process the completion status and trigger further
455 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200457void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
458{
459 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
460 zfcp_fsf_status_read_handler(req);
461 return;
462 }
463
464 del_timer(&req->timer);
465 zfcp_fsf_protstatus_eval(req);
466 zfcp_fsf_fsfstatus_eval(req);
467 req->handler(req);
468
469 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200470 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200471 req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
472
473 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
474 zfcp_fsf_req_free(req);
475 else
476 /* notify initiator waiting for the requests completion */
477 /*
478 * FIXME: Race! We must not access fsf_req here as it might have been
479 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
480 * flag. It's an improbable case. But, we have the same paranoia for
481 * the cleanup flag already.
482 * Might better be handled using complete()?
483 * (setting the flag and doing wakeup ought to be atomic
484 * with regard to checking the flag as long as waitqueue is
485 * part of the to be released structure)
486 */
487 wake_up(&req->completion_wq);
488}
489
490static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 struct fsf_qtcb_bottom_config *bottom;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200493 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200494 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200496 bottom = &req->qtcb->bottom.config;
497
498 if (req->data)
499 memcpy(req->data, bottom, sizeof(*bottom));
500
501 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
502 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
503 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
504 fc_host_speed(shost) = bottom->fc_link_speed;
505 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
506
507 adapter->hydra_version = bottom->adapter_type;
508 adapter->timer_ticks = bottom->timer_interval;
509
510 if (fc_host_permanent_port_name(shost) == -1)
511 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
512
513 switch (bottom->fc_topology) {
514 case FSF_TOPO_P2P:
515 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
516 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
517 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
518 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200519 break;
520 case FSF_TOPO_FABRIC:
521 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200522 break;
523 case FSF_TOPO_AL:
524 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200525 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200526 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200527 "Unknown or unsupported arbitrated loop "
528 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100529 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200530 return -EIO;
531 }
532
533 return 0;
534}
535
536static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
537{
538 struct zfcp_adapter *adapter = req->adapter;
539 struct fsf_qtcb *qtcb = req->qtcb;
540 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
541 struct Scsi_Host *shost = adapter->scsi_host;
542
543 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
544 return;
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200547 adapter->adapter_features = bottom->adapter_features;
548 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500549 adapter->peer_wwpn = 0;
550 adapter->peer_wwnn = 0;
551 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200553 switch (qtcb->header.fsf_status) {
554 case FSF_GOOD:
555 if (zfcp_fsf_exchange_config_evaluate(req))
556 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200557
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200558 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
559 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200560 "FCP adapter maximum QTCB size (%d bytes) "
561 "is too small\n",
562 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100563 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200564 return;
565 }
566 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
567 &adapter->status);
568 break;
569 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200570 fc_host_node_name(shost) = 0;
571 fc_host_port_name(shost) = 0;
572 fc_host_port_id(shost) = 0;
573 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100574 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200576
577 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
578 &adapter->status);
579
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100580 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200581 &qtcb->header.fsf_status_qual.link_down_info);
582 break;
583 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100584 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200585 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
587
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200588 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200590 memcpy(fc_host_serial_number(shost), bottom->serial_number,
591 min(FC_SERIAL_NUMBER_SIZE, 17));
592 EBCASC(fc_host_serial_number(shost),
593 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
595
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200596 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200597 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200598 "The FCP adapter only supports newer "
599 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100600 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200601 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200603 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200604 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200605 "The FCP adapter only supports older "
606 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100607 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200611static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200613 struct zfcp_adapter *adapter = req->adapter;
614 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
615 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200617 if (req->data)
618 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100619
Christof Schmitt02829852009-03-02 13:09:06 +0100620 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100621 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100622 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
623 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100624 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
625 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
626 fc_host_supported_speeds(shost) = bottom->supported_speed;
627}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200629static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200631 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100632
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200633 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return;
635
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637 case FSF_GOOD:
638 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200639 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200640 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200641 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100642 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200643 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646}
647
Martin Petermann7001f0c2009-04-17 15:08:12 +0200648static int zfcp_fsf_sbal_check(struct zfcp_adapter *adapter)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200649{
Christof Schmittdedbc2b2008-12-19 16:56:54 +0100650 struct zfcp_qdio_queue *req_q = &adapter->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200651
652 spin_lock_bh(&adapter->req_q_lock);
653 if (atomic_read(&req_q->count))
654 return 1;
655 spin_unlock_bh(&adapter->req_q_lock);
656 return 0;
657}
658
659static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
660{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200661 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662
Christof Schmitt04062892008-10-01 12:42:20 +0200663 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200664 ret = wait_event_interruptible_timeout(adapter->request_wq,
Martin Petermann7001f0c2009-04-17 15:08:12 +0200665 zfcp_fsf_sbal_check(adapter), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200666 if (ret > 0)
667 return 0;
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200668 if (!ret)
669 atomic_inc(&adapter->qdio_outb_full);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200670
671 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200672 return -EIO;
673}
674
675static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
676{
677 struct zfcp_fsf_req *req;
678 req = mempool_alloc(pool, GFP_ATOMIC);
679 if (!req)
680 return NULL;
681 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100682 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200683 return req;
684}
685
686static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
687{
688 struct zfcp_fsf_req_qtcb *qtcb;
689
690 if (likely(pool))
691 qtcb = mempool_alloc(pool, GFP_ATOMIC);
692 else
693 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
694 GFP_ATOMIC);
695 if (unlikely(!qtcb))
696 return NULL;
697
698 memset(qtcb, 0, sizeof(*qtcb));
699 qtcb->fsf_req.qtcb = &qtcb->qtcb;
700 qtcb->fsf_req.pool = pool;
701
702 return &qtcb->fsf_req;
703}
704
705static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
706 u32 fsf_cmd, int req_flags,
707 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200709 struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200711 struct zfcp_fsf_req *req;
712 struct zfcp_qdio_queue *req_q = &adapter->req_q;
713
714 if (req_flags & ZFCP_REQ_NO_QTCB)
715 req = zfcp_fsf_alloc_noqtcb(pool);
716 else
717 req = zfcp_fsf_alloc_qtcb(pool);
718
719 if (unlikely(!req))
720 return ERR_PTR(-EIO);
721
722 if (adapter->req_no == 0)
723 adapter->req_no++;
724
725 INIT_LIST_HEAD(&req->list);
726 init_timer(&req->timer);
727 init_waitqueue_head(&req->completion_wq);
728
729 req->adapter = adapter;
730 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100731 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200732 req->sbal_number = 1;
733 req->sbal_first = req_q->first;
734 req->sbal_last = req_q->first;
735 req->sbale_curr = 1;
736
737 sbale = zfcp_qdio_sbale_req(req);
738 sbale[0].addr = (void *) req->req_id;
739 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
740
741 if (likely(req->qtcb)) {
742 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
743 req->qtcb->prefix.req_id = req->req_id;
744 req->qtcb->prefix.ulp_info = 26;
745 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
746 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
747 req->qtcb->header.req_handle = req->req_id;
748 req->qtcb->header.fsf_command = req->fsf_command;
749 req->seq_no = adapter->fsf_req_seq_no;
750 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
751 sbale[1].addr = (void *) req->qtcb;
752 sbale[1].length = sizeof(struct fsf_qtcb);
753 }
754
755 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
756 zfcp_fsf_req_free(req);
757 return ERR_PTR(-EIO);
758 }
759
760 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
761 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
762
763 return req;
764}
765
766static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
767{
768 struct zfcp_adapter *adapter = req->adapter;
Martin Petermann135ea132009-04-17 15:08:01 +0200769 unsigned long flags;
770 int idx;
771 int with_qtcb = (req->qtcb != NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772
773 /* put allocated FSF request into hash table */
Heiko Carstens45316a82008-11-04 16:35:06 +0100774 spin_lock_irqsave(&adapter->req_list_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200775 idx = zfcp_reqlist_hash(req->req_id);
776 list_add_tail(&req->list, &adapter->req_list[idx]);
Heiko Carstens45316a82008-11-04 16:35:06 +0100777 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200778
Christof Schmitt37651382008-11-04 16:35:08 +0100779 req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200780 req->issued = get_clock();
781 if (zfcp_qdio_send(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200782 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100783 spin_lock_irqsave(&adapter->req_list_lock, flags);
784 /* lookup request again, list might have changed */
785 if (zfcp_reqlist_find_safe(adapter, req))
786 zfcp_reqlist_remove(adapter, req);
787 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100788 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200789 return -EIO;
790 }
791
792 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200793 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200794 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100795 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200796
797 return 0;
798}
799
800/**
801 * zfcp_fsf_status_read - send status read request
802 * @adapter: pointer to struct zfcp_adapter
803 * @req_flags: request flags
804 * Returns: 0 on success, ERROR otherwise
805 */
806int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
807{
808 struct zfcp_fsf_req *req;
809 struct fsf_status_read_buffer *sr_buf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200810 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200811 int retval = -EIO;
812
Christof Schmitt04062892008-10-01 12:42:20 +0200813 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200814 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200817 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
818 ZFCP_REQ_NO_QTCB,
819 adapter->pool.fsf_req_status_read);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200820 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200821 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 goto out;
823 }
824
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200825 sbale = zfcp_qdio_sbale_req(req);
826 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
827 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
828 req->sbale_curr = 2;
829
830 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
831 if (!sr_buf) {
832 retval = -ENOMEM;
833 goto failed_buf;
834 }
835 memset(sr_buf, 0, sizeof(*sr_buf));
836 req->data = sr_buf;
837 sbale = zfcp_qdio_sbale_curr(req);
838 sbale->addr = (void *) sr_buf;
839 sbale->length = sizeof(*sr_buf);
840
841 retval = zfcp_fsf_req_send(req);
842 if (retval)
843 goto failed_req_send;
844
845 goto out;
846
847failed_req_send:
848 mempool_free(sr_buf, adapter->pool.data_status_read);
849failed_buf:
850 zfcp_fsf_req_free(req);
851 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
852out:
Christof Schmitt04062892008-10-01 12:42:20 +0200853 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 return retval;
855}
856
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200857static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200859 struct zfcp_unit *unit = req->data;
860 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
863 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865 switch (req->qtcb->header.fsf_status) {
866 case FSF_PORT_HANDLE_NOT_VALID:
867 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100868 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
869 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200873 case FSF_LUN_HANDLE_NOT_VALID:
874 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100875 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200876 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
877 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200879 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
880 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100883 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
885 ZFCP_STATUS_FSFREQ_RETRY;
886 break;
887 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100888 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200889 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
890 ZFCP_STATUS_FSFREQ_RETRY;
891 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200893 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200895 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200897 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 break;
899 }
900 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200902 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
903 break;
904 }
905}
906
907/**
908 * zfcp_fsf_abort_fcp_command - abort running SCSI command
909 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200910 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200911 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200912 */
913
914struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100915 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200916{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200917 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200918 struct zfcp_fsf_req *req = NULL;
Christof Schmitt63caf362009-03-02 13:09:00 +0100919 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200920
Christof Schmitt92cab0d2009-03-02 13:08:59 +0100921 spin_lock_bh(&adapter->req_q_lock);
922 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200923 goto out;
924 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt63caf362009-03-02 13:09:00 +0100925 0, adapter->pool.fsf_req_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100926 if (IS_ERR(req)) {
927 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200928 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100929 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200930
931 if (unlikely(!(atomic_read(&unit->status) &
932 ZFCP_STATUS_COMMON_UNBLOCKED)))
933 goto out_error_free;
934
935 sbale = zfcp_qdio_sbale_req(req);
936 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
937 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
938
939 req->data = unit;
940 req->handler = zfcp_fsf_abort_fcp_command_handler;
941 req->qtcb->header.lun_handle = unit->handle;
942 req->qtcb->header.port_handle = unit->port->handle;
943 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
944
945 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
946 if (!zfcp_fsf_req_send(req))
947 goto out;
948
949out_error_free:
950 zfcp_fsf_req_free(req);
951 req = NULL;
952out:
Christof Schmitt92cab0d2009-03-02 13:08:59 +0100953 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200954 return req;
955}
956
957static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
958{
959 struct zfcp_adapter *adapter = req->adapter;
960 struct zfcp_send_ct *send_ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200961 struct fsf_qtcb_header *header = &req->qtcb->header;
962
963 send_ct->status = -EINVAL;
964
965 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
966 goto skip_fsfstatus;
967
968 switch (header->fsf_status) {
969 case FSF_GOOD:
970 zfcp_san_dbf_event_ct_response(req);
971 send_ct->status = 0;
972 break;
973 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
974 zfcp_fsf_class_not_supp(req);
975 break;
976 case FSF_ADAPTER_STATUS_AVAILABLE:
977 switch (header->fsf_status_qual.word[0]){
978 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200979 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
980 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
981 break;
982 }
983 break;
984 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200985 break;
986 case FSF_PORT_BOXED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200987 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
988 ZFCP_STATUS_FSFREQ_RETRY;
989 break;
990 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100991 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200992 case FSF_GENERIC_COMMAND_REJECTED:
993 case FSF_PAYLOAD_SIZE_MISMATCH:
994 case FSF_REQUEST_SIZE_TOO_LARGE:
995 case FSF_RESPONSE_SIZE_TOO_LARGE:
996 case FSF_SBAL_MISMATCH:
997 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
998 break;
999 }
1000
1001skip_fsfstatus:
1002 if (send_ct->handler)
1003 send_ct->handler(send_ct->handler_data);
1004}
1005
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001006static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1007 struct scatterlist *sg_req,
1008 struct scatterlist *sg_resp,
1009 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001010{
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001011 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
1012 u32 feat = req->adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001013 int bytes;
1014
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001015 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1016 if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
1017 !sg_is_last(sg_req) || !sg_is_last(sg_resp))
1018 return -EOPNOTSUPP;
1019
1020 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1021 sbale[2].addr = sg_virt(sg_req);
1022 sbale[2].length = sg_req->length;
1023 sbale[3].addr = sg_virt(sg_resp);
1024 sbale[3].length = sg_resp->length;
1025 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1026 return 0;
1027 }
1028
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001029 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1030 sg_req, max_sbals);
1031 if (bytes <= 0)
1032 return -ENOMEM;
1033 req->qtcb->bottom.support.req_buf_length = bytes;
1034 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1035
1036 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1037 sg_resp, max_sbals);
1038 if (bytes <= 0)
1039 return -ENOMEM;
1040 req->qtcb->bottom.support.resp_buf_length = bytes;
1041
1042 return 0;
1043}
1044
1045/**
1046 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1047 * @ct: pointer to struct zfcp_send_ct with data for request
1048 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1049 * @erp_action: if non-null the Generic Service request sent within ERP
1050 */
1051int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1052 struct zfcp_erp_action *erp_action)
1053{
Swen Schillig5ab944f2008-10-01 12:42:17 +02001054 struct zfcp_wka_port *wka_port = ct->wka_port;
1055 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001056 struct zfcp_fsf_req *req;
1057 int ret = -EIO;
1058
Christof Schmitt04062892008-10-01 12:42:20 +02001059 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001060 if (zfcp_fsf_req_sbal_get(adapter))
1061 goto out;
1062
1063 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1064 ZFCP_REQ_AUTO_CLEANUP, pool);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001065 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001066 ret = PTR_ERR(req);
1067 goto out;
1068 }
1069
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001070 ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
1071 FSF_MAX_SBALS_PER_REQ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001072 if (ret)
1073 goto failed_send;
1074
1075 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001076 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001077 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1078 req->qtcb->bottom.support.timeout = ct->timeout;
1079 req->data = ct;
1080
1081 zfcp_san_dbf_event_ct_request(req);
1082
1083 if (erp_action) {
1084 erp_action->fsf_req = req;
1085 req->erp_action = erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +02001086 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087 } else
1088 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1089
1090 ret = zfcp_fsf_req_send(req);
1091 if (ret)
1092 goto failed_send;
1093
1094 goto out;
1095
1096failed_send:
1097 zfcp_fsf_req_free(req);
1098 if (erp_action)
1099 erp_action->fsf_req = NULL;
1100out:
Christof Schmitt04062892008-10-01 12:42:20 +02001101 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001102 return ret;
1103}
1104
1105static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1106{
1107 struct zfcp_send_els *send_els = req->data;
1108 struct zfcp_port *port = send_els->port;
1109 struct fsf_qtcb_header *header = &req->qtcb->header;
1110
1111 send_els->status = -EINVAL;
1112
1113 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1114 goto skip_fsfstatus;
1115
1116 switch (header->fsf_status) {
1117 case FSF_GOOD:
1118 zfcp_san_dbf_event_els_response(req);
1119 send_els->status = 0;
1120 break;
1121 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1122 zfcp_fsf_class_not_supp(req);
1123 break;
1124 case FSF_ADAPTER_STATUS_AVAILABLE:
1125 switch (header->fsf_status_qual.word[0]){
1126 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1127 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1128 zfcp_test_link(port);
1129 /*fall through */
1130 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1131 case FSF_SQ_RETRY_IF_POSSIBLE:
1132 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1133 break;
1134 }
1135 break;
1136 case FSF_ELS_COMMAND_REJECTED:
1137 case FSF_PAYLOAD_SIZE_MISMATCH:
1138 case FSF_REQUEST_SIZE_TOO_LARGE:
1139 case FSF_RESPONSE_SIZE_TOO_LARGE:
1140 break;
1141 case FSF_ACCESS_DENIED:
1142 zfcp_fsf_access_denied_port(req, port);
1143 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 */
1160int zfcp_fsf_send_els(struct zfcp_send_els *els)
1161{
1162 struct zfcp_fsf_req *req;
1163 struct zfcp_adapter *adapter = els->adapter;
1164 struct fsf_qtcb_bottom_support *bottom;
1165 int ret = -EIO;
1166
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01001167 spin_lock_bh(&adapter->req_q_lock);
1168 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001169 goto out;
1170 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1171 ZFCP_REQ_AUTO_CLEANUP, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001172 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001173 ret = PTR_ERR(req);
1174 goto out;
1175 }
1176
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001177 ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001178
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001179 if (ret)
1180 goto failed_send;
1181
1182 bottom = &req->qtcb->bottom.support;
1183 req->handler = zfcp_fsf_send_els_handler;
1184 bottom->d_id = els->d_id;
1185 bottom->service_class = FSF_CLASS_3;
1186 bottom->timeout = 2 * R_A_TOV;
1187 req->data = els;
1188
1189 zfcp_san_dbf_event_els_request(req);
1190
1191 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1192 ret = zfcp_fsf_req_send(req);
1193 if (ret)
1194 goto failed_send;
1195
1196 goto out;
1197
1198failed_send:
1199 zfcp_fsf_req_free(req);
1200out:
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01001201 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001202 return ret;
1203}
1204
1205int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1206{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001207 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001208 struct zfcp_fsf_req *req;
1209 struct zfcp_adapter *adapter = erp_action->adapter;
1210 int retval = -EIO;
1211
Christof Schmitt04062892008-10-01 12:42:20 +02001212 spin_lock_bh(&adapter->req_q_lock);
Christof Schmitt92cab0d2009-03-02 13:08:59 +01001213 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001214 goto out;
1215 req = zfcp_fsf_req_create(adapter,
1216 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1217 ZFCP_REQ_AUTO_CLEANUP,
1218 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001219 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001220 retval = PTR_ERR(req);
1221 goto out;
1222 }
1223
1224 sbale = zfcp_qdio_sbale_req(req);
1225 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1226 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1227
1228 req->qtcb->bottom.config.feature_selection =
1229 FSF_FEATURE_CFDC |
1230 FSF_FEATURE_LUN_SHARING |
1231 FSF_FEATURE_NOTIFICATION_LOST |
1232 FSF_FEATURE_UPDATE_ALERT;
1233 req->erp_action = erp_action;
1234 req->handler = zfcp_fsf_exchange_config_data_handler;
1235 erp_action->fsf_req = req;
1236
Christof Schmitt287ac012008-07-02 10:56:40 +02001237 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 retval = zfcp_fsf_req_send(req);
1239 if (retval) {
1240 zfcp_fsf_req_free(req);
1241 erp_action->fsf_req = NULL;
1242 }
1243out:
Christof Schmitt04062892008-10-01 12:42:20 +02001244 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001245 return retval;
1246}
1247
1248int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1249 struct fsf_qtcb_bottom_config *data)
1250{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001251 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001252 struct zfcp_fsf_req *req = NULL;
1253 int retval = -EIO;
1254
Christof Schmitt04062892008-10-01 12:42:20 +02001255 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001256 if (zfcp_fsf_req_sbal_get(adapter))
Christof Schmittada81b72009-04-17 15:08:03 +02001257 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001258
1259 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1260 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001261 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001262 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001263 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001264 }
1265
1266 sbale = zfcp_qdio_sbale_req(req);
1267 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1268 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1269 req->handler = zfcp_fsf_exchange_config_data_handler;
1270
1271 req->qtcb->bottom.config.feature_selection =
1272 FSF_FEATURE_CFDC |
1273 FSF_FEATURE_LUN_SHARING |
1274 FSF_FEATURE_NOTIFICATION_LOST |
1275 FSF_FEATURE_UPDATE_ALERT;
1276
1277 if (data)
1278 req->data = data;
1279
1280 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1281 retval = zfcp_fsf_req_send(req);
Christof Schmitt04062892008-10-01 12:42:20 +02001282 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001283 if (!retval)
1284 wait_event(req->completion_wq,
1285 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1286
1287 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001288 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001289
Christof Schmittada81b72009-04-17 15:08:03 +02001290out_unlock:
1291 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001292 return retval;
1293}
1294
1295/**
1296 * zfcp_fsf_exchange_port_data - request information about local port
1297 * @erp_action: ERP action for the adapter for which port data is requested
1298 * Returns: 0 on success, error otherwise
1299 */
1300int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1301{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001302 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001303 struct zfcp_fsf_req *req;
1304 struct zfcp_adapter *adapter = erp_action->adapter;
1305 int retval = -EIO;
1306
1307 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1308 return -EOPNOTSUPP;
1309
Christof Schmitt04062892008-10-01 12:42:20 +02001310 spin_lock_bh(&adapter->req_q_lock);
Christof Schmitt92cab0d2009-03-02 13:08:59 +01001311 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001312 goto out;
1313 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1314 ZFCP_REQ_AUTO_CLEANUP,
1315 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001316 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001317 retval = PTR_ERR(req);
1318 goto out;
1319 }
1320
1321 sbale = zfcp_qdio_sbale_req(req);
1322 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1323 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1324
1325 req->handler = zfcp_fsf_exchange_port_data_handler;
1326 req->erp_action = erp_action;
1327 erp_action->fsf_req = req;
1328
Christof Schmitt287ac012008-07-02 10:56:40 +02001329 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001330 retval = zfcp_fsf_req_send(req);
1331 if (retval) {
1332 zfcp_fsf_req_free(req);
1333 erp_action->fsf_req = NULL;
1334 }
1335out:
Christof Schmitt04062892008-10-01 12:42:20 +02001336 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001337 return retval;
1338}
1339
1340/**
1341 * zfcp_fsf_exchange_port_data_sync - request information about local port
1342 * @adapter: pointer to struct zfcp_adapter
1343 * @data: pointer to struct fsf_qtcb_bottom_port
1344 * Returns: 0 on success, error otherwise
1345 */
1346int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1347 struct fsf_qtcb_bottom_port *data)
1348{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001349 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001350 struct zfcp_fsf_req *req = NULL;
1351 int retval = -EIO;
1352
1353 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1354 return -EOPNOTSUPP;
1355
Christof Schmitt04062892008-10-01 12:42:20 +02001356 spin_lock_bh(&adapter->req_q_lock);
Christof Schmitt92cab0d2009-03-02 13:08:59 +01001357 if (zfcp_fsf_req_sbal_get(adapter))
Christof Schmittada81b72009-04-17 15:08:03 +02001358 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001359
1360 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1361 NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001362 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001363 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001364 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001365 }
1366
1367 if (data)
1368 req->data = data;
1369
1370 sbale = zfcp_qdio_sbale_req(req);
1371 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1372 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1373
1374 req->handler = zfcp_fsf_exchange_port_data_handler;
1375 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1376 retval = zfcp_fsf_req_send(req);
Christof Schmitt04062892008-10-01 12:42:20 +02001377 spin_unlock_bh(&adapter->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001378
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001379 if (!retval)
1380 wait_event(req->completion_wq,
1381 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1382 zfcp_fsf_req_free(req);
1383
1384 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001385
1386out_unlock:
1387 spin_unlock_bh(&adapter->req_q_lock);
1388 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001389}
1390
1391static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1392{
1393 struct zfcp_port *port = req->data;
1394 struct fsf_qtcb_header *header = &req->qtcb->header;
1395 struct fsf_plogi *plogi;
1396
1397 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001398 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001399
1400 switch (header->fsf_status) {
1401 case FSF_PORT_ALREADY_OPEN:
1402 break;
1403 case FSF_ACCESS_DENIED:
1404 zfcp_fsf_access_denied_port(req, port);
1405 break;
1406 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1407 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001408 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001409 "remote port 0x%016Lx\n",
1410 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001411 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001412 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1413 break;
1414 case FSF_ADAPTER_STATUS_AVAILABLE:
1415 switch (header->fsf_status_qual.word[0]) {
1416 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1417 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001418 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001419 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1420 break;
1421 }
1422 break;
1423 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1426 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001427 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1428 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1429 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 /* check whether D_ID has changed during open */
1431 /*
1432 * FIXME: This check is not airtight, as the FCP channel does
1433 * not monitor closures of target port connections caused on
1434 * the remote side. Thus, they might miss out on invalidating
1435 * locally cached WWPNs (and other N_Port parameters) of gone
1436 * target ports. So, our heroic attempt to make things safe
1437 * could be undermined by 'open port' response data tagged with
1438 * obsolete WWPNs. Another reason to monitor potential
1439 * connection closures ourself at least (by interpreting
1440 * incoming ELS' and unsolicited status). It just crosses my
1441 * mind that one should be able to cross-check by means of
1442 * another GID_PN straight after a port has been opened.
1443 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1444 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001445 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001446 if (req->qtcb->bottom.support.els1_length >=
1447 FSF_PLOGI_MIN_LEN) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001448 if (plogi->serv_param.wwpn != port->wwpn)
Christof Schmittb98478d2008-12-19 16:56:59 +01001449 port->d_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001450 else {
1451 port->wwnn = plogi->serv_param.wwnn;
1452 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454 }
1455 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001457 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 break;
1459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460}
1461
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001462/**
1463 * zfcp_fsf_open_port - create and send open port request
1464 * @erp_action: pointer to struct zfcp_erp_action
1465 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001467int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001469 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001470 struct zfcp_adapter *adapter = erp_action->adapter;
1471 struct zfcp_fsf_req *req;
1472 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Christof Schmitt04062892008-10-01 12:42:20 +02001474 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001478 req = zfcp_fsf_req_create(adapter,
1479 FSF_QTCB_OPEN_PORT_WITH_DID,
1480 ZFCP_REQ_AUTO_CLEANUP,
1481 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001482 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001483 retval = PTR_ERR(req);
1484 goto out;
1485 }
1486
1487 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1489 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1490
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001491 req->handler = zfcp_fsf_open_port_handler;
1492 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
1493 req->data = erp_action->port;
1494 req->erp_action = erp_action;
1495 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Christof Schmitt287ac012008-07-02 10:56:40 +02001497 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001498 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001500 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001503out:
Christof Schmitt04062892008-10-01 12:42:20 +02001504 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 return retval;
1506}
1507
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001508static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001510 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001512 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001513 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001515 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001517 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001518 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001523 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 ZFCP_STATUS_COMMON_OPEN,
1525 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001530/**
1531 * zfcp_fsf_close_port - create and send close port request
1532 * @erp_action: pointer to struct zfcp_erp_action
1533 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001535int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001537 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001538 struct zfcp_adapter *adapter = erp_action->adapter;
1539 struct zfcp_fsf_req *req;
1540 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Christof Schmitt04062892008-10-01 12:42:20 +02001542 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001543 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001546 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1547 ZFCP_REQ_AUTO_CLEANUP,
1548 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001549 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001550 retval = PTR_ERR(req);
1551 goto out;
1552 }
1553
1554 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1556 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1557
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001558 req->handler = zfcp_fsf_close_port_handler;
1559 req->data = erp_action->port;
1560 req->erp_action = erp_action;
1561 req->qtcb->header.port_handle = erp_action->port->handle;
1562 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Christof Schmitt287ac012008-07-02 10:56:40 +02001564 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001565 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001567 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001570out:
Christof Schmitt04062892008-10-01 12:42:20 +02001571 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 return retval;
1573}
1574
Swen Schillig5ab944f2008-10-01 12:42:17 +02001575static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1576{
1577 struct zfcp_wka_port *wka_port = req->data;
1578 struct fsf_qtcb_header *header = &req->qtcb->header;
1579
1580 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1581 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1582 goto out;
1583 }
1584
1585 switch (header->fsf_status) {
1586 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1587 dev_warn(&req->adapter->ccw_device->dev,
1588 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1589 case FSF_ADAPTER_STATUS_AVAILABLE:
1590 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1591 case FSF_ACCESS_DENIED:
1592 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1593 break;
1594 case FSF_PORT_ALREADY_OPEN:
Christof Schmitt1c1cba12008-11-26 18:07:36 +01001595 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001596 case FSF_GOOD:
1597 wka_port->handle = header->port_handle;
1598 wka_port->status = ZFCP_WKA_PORT_ONLINE;
1599 }
1600out:
1601 wake_up(&wka_port->completion_wq);
1602}
1603
1604/**
1605 * zfcp_fsf_open_wka_port - create and send open wka-port request
1606 * @wka_port: pointer to struct zfcp_wka_port
1607 * Returns: 0 on success, error otherwise
1608 */
1609int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1610{
1611 struct qdio_buffer_element *sbale;
1612 struct zfcp_adapter *adapter = wka_port->adapter;
1613 struct zfcp_fsf_req *req;
1614 int retval = -EIO;
1615
Christof Schmitt04062892008-10-01 12:42:20 +02001616 spin_lock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001617 if (zfcp_fsf_req_sbal_get(adapter))
1618 goto out;
1619
1620 req = zfcp_fsf_req_create(adapter,
1621 FSF_QTCB_OPEN_PORT_WITH_DID,
1622 ZFCP_REQ_AUTO_CLEANUP,
1623 adapter->pool.fsf_req_erp);
1624 if (unlikely(IS_ERR(req))) {
1625 retval = PTR_ERR(req);
1626 goto out;
1627 }
1628
1629 sbale = zfcp_qdio_sbale_req(req);
1630 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1631 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1632
1633 req->handler = zfcp_fsf_open_wka_port_handler;
1634 req->qtcb->bottom.support.d_id = wka_port->d_id;
1635 req->data = wka_port;
1636
1637 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1638 retval = zfcp_fsf_req_send(req);
1639 if (retval)
1640 zfcp_fsf_req_free(req);
1641out:
Christof Schmitt04062892008-10-01 12:42:20 +02001642 spin_unlock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001643 return retval;
1644}
1645
1646static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1647{
1648 struct zfcp_wka_port *wka_port = req->data;
1649
1650 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1651 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001652 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001653 }
1654
1655 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1656 wake_up(&wka_port->completion_wq);
1657}
1658
1659/**
1660 * zfcp_fsf_close_wka_port - create and send close wka port request
1661 * @erp_action: pointer to struct zfcp_erp_action
1662 * Returns: 0 on success, error otherwise
1663 */
1664int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
1665{
1666 struct qdio_buffer_element *sbale;
1667 struct zfcp_adapter *adapter = wka_port->adapter;
1668 struct zfcp_fsf_req *req;
1669 int retval = -EIO;
1670
Christof Schmitt04062892008-10-01 12:42:20 +02001671 spin_lock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001672 if (zfcp_fsf_req_sbal_get(adapter))
1673 goto out;
1674
1675 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1676 ZFCP_REQ_AUTO_CLEANUP,
1677 adapter->pool.fsf_req_erp);
1678 if (unlikely(IS_ERR(req))) {
1679 retval = PTR_ERR(req);
1680 goto out;
1681 }
1682
1683 sbale = zfcp_qdio_sbale_req(req);
1684 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1685 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1686
1687 req->handler = zfcp_fsf_close_wka_port_handler;
1688 req->data = wka_port;
1689 req->qtcb->header.port_handle = wka_port->handle;
1690
1691 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1692 retval = zfcp_fsf_req_send(req);
1693 if (retval)
1694 zfcp_fsf_req_free(req);
1695out:
Christof Schmitt04062892008-10-01 12:42:20 +02001696 spin_unlock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001697 return retval;
1698}
1699
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001700static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001702 struct zfcp_port *port = req->data;
1703 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001706 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001707 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001711 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001712 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001715 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001718 zfcp_erp_port_boxed(port, "fscpph2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001719 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1720 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01001721 /* can't use generic zfcp_erp_modify_port_status because
1722 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1723 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1724 list_for_each_entry(unit, &port->unit_list_head, list)
1725 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1726 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 switch (header->fsf_status_qual.word[0]) {
1730 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001731 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001733 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 }
1736 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 /* can't use generic zfcp_erp_modify_port_status because
1739 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1740 */
1741 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1742 list_for_each_entry(unit, &port->unit_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001743 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1744 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
1748
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001749/**
1750 * zfcp_fsf_close_physical_port - close physical port
1751 * @erp_action: pointer to struct zfcp_erp_action
1752 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001754int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001756 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001757 struct zfcp_adapter *adapter = erp_action->adapter;
1758 struct zfcp_fsf_req *req;
1759 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
Christof Schmitt04062892008-10-01 12:42:20 +02001761 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001762 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001765 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1766 ZFCP_REQ_AUTO_CLEANUP,
1767 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001768 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001769 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 goto out;
1771 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001772
1773 sbale = zfcp_qdio_sbale_req(req);
1774 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1775 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1776
1777 req->data = erp_action->port;
1778 req->qtcb->header.port_handle = erp_action->port->handle;
1779 req->erp_action = erp_action;
1780 req->handler = zfcp_fsf_close_physical_port_handler;
1781 erp_action->fsf_req = req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001782
Christof Schmitt287ac012008-07-02 10:56:40 +02001783 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001784 retval = zfcp_fsf_req_send(req);
1785 if (retval) {
1786 zfcp_fsf_req_free(req);
1787 erp_action->fsf_req = NULL;
1788 }
1789out:
Christof Schmitt04062892008-10-01 12:42:20 +02001790 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 return retval;
1792}
1793
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001794static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001796 struct zfcp_adapter *adapter = req->adapter;
1797 struct zfcp_unit *unit = req->data;
1798 struct fsf_qtcb_header *header = &req->qtcb->header;
1799 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1800 struct fsf_queue_designator *queue_designator =
1801 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001802 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001804 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001805 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001808 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 ZFCP_STATUS_UNIT_SHARED |
1810 ZFCP_STATUS_UNIT_READONLY,
1811 &unit->status);
1812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 switch (header->fsf_status) {
1814
1815 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001816 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001817 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001821 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001823 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001826 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001827 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1828 ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001831 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001832 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001833 "LUN 0x%Lx on port 0x%Lx is already in "
1834 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001835 (unsigned long long)unit->fcp_lun,
1836 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001837 queue_designator->cssid,
1838 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001839 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001840 zfcp_act_eval_err(adapter,
1841 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001842 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1844 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001845 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001848 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001849 "No handle is available for LUN "
1850 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001851 (unsigned long long)unit->fcp_lun,
1852 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001853 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001854 /* fall through */
1855 case FSF_INVALID_COMMAND_OPTION:
1856 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 switch (header->fsf_status_qual.word[0]) {
1860 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001861 zfcp_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001862 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001864 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
1867 break;
1868
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001872
1873 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1874 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1875 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
1876 exclusive = (bottom->lun_access_info &
1877 FSF_UNIT_ACCESS_EXCLUSIVE);
1878 readwrite = (bottom->lun_access_info &
1879 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1880
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 if (!exclusive)
1882 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1883 &unit->status);
1884
1885 if (!readwrite) {
1886 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1887 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001888 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001889 "SCSI device at LUN 0x%016Lx on port "
1890 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001891 (unsigned long long)unit->fcp_lun,
1892 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 }
1894
1895 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 "Exclusive read-only access not "
1898 "supported (unit 0x%016Lx, "
1899 "port 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_5", 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_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001906 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001907 "Shared read-write access not "
1908 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001909 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001910 (unsigned long long)unit->fcp_lun,
1911 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001912 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001913 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001914 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 }
1916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
1921/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001922 * zfcp_fsf_open_unit - open unit
1923 * @erp_action: pointer to struct zfcp_erp_action
1924 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001926int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001928 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001929 struct zfcp_adapter *adapter = erp_action->adapter;
1930 struct zfcp_fsf_req *req;
1931 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Christof Schmitt04062892008-10-01 12:42:20 +02001933 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001934 if (zfcp_fsf_req_sbal_get(adapter))
1935 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001937 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1938 ZFCP_REQ_AUTO_CLEANUP,
1939 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001940 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001941 retval = PTR_ERR(req);
1942 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001943 }
1944
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001945 sbale = zfcp_qdio_sbale_req(req);
1946 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1947 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001949 req->qtcb->header.port_handle = erp_action->port->handle;
1950 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1951 req->handler = zfcp_fsf_open_unit_handler;
1952 req->data = erp_action->unit;
1953 req->erp_action = erp_action;
1954 erp_action->fsf_req = req;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001955
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001956 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1957 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Christof Schmitt287ac012008-07-02 10:56:40 +02001959 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001960 retval = zfcp_fsf_req_send(req);
1961 if (retval) {
1962 zfcp_fsf_req_free(req);
1963 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001965out:
Christof Schmitt04062892008-10-01 12:42:20 +02001966 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 return retval;
1968}
1969
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001970static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001972 struct zfcp_unit *unit = req->data;
1973
1974 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001975 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001976
1977 switch (req->qtcb->header.fsf_status) {
1978 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001979 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001980 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1981 break;
1982 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001983 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001984 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1985 break;
1986 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001987 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001988 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1989 ZFCP_STATUS_FSFREQ_RETRY;
1990 break;
1991 case FSF_ADAPTER_STATUS_AVAILABLE:
1992 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1993 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1994 zfcp_test_link(unit->port);
1995 /* fall through */
1996 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1997 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1998 break;
1999 }
2000 break;
2001 case FSF_GOOD:
2002 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2003 break;
2004 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002005}
2006
2007/**
2008 * zfcp_fsf_close_unit - close zfcp unit
2009 * @erp_action: pointer to struct zfcp_unit
2010 * Returns: 0 on success, error otherwise
2011 */
2012int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2013{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002014 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002015 struct zfcp_adapter *adapter = erp_action->adapter;
2016 struct zfcp_fsf_req *req;
2017 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Christof Schmitt04062892008-10-01 12:42:20 +02002019 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002020 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002022 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
2023 ZFCP_REQ_AUTO_CLEANUP,
2024 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002025 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002026 retval = PTR_ERR(req);
2027 goto out;
2028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002030 sbale = zfcp_qdio_sbale_req(req);
2031 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2033
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002034 req->qtcb->header.port_handle = erp_action->port->handle;
2035 req->qtcb->header.lun_handle = erp_action->unit->handle;
2036 req->handler = zfcp_fsf_close_unit_handler;
2037 req->data = erp_action->unit;
2038 req->erp_action = erp_action;
2039 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Christof Schmitt287ac012008-07-02 10:56:40 +02002041 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002042 retval = zfcp_fsf_req_send(req);
2043 if (retval) {
2044 zfcp_fsf_req_free(req);
2045 erp_action->fsf_req = NULL;
2046 }
2047out:
Christof Schmitt04062892008-10-01 12:42:20 +02002048 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002049 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050}
2051
Christof Schmittc9615852008-05-06 11:00:05 +02002052static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2053{
2054 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002055 lat_rec->min = min(lat_rec->min, lat);
2056 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002057}
2058
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002059static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
Christof Schmittc9615852008-05-06 11:00:05 +02002060{
2061 struct fsf_qual_latency_info *lat_inf;
2062 struct latency_cont *lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002063 struct zfcp_unit *unit = req->unit;
Christof Schmittc9615852008-05-06 11:00:05 +02002064
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002065 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002066
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002067 switch (req->qtcb->bottom.io.data_direction) {
Christof Schmittc9615852008-05-06 11:00:05 +02002068 case FSF_DATADIR_READ:
2069 lat = &unit->latencies.read;
2070 break;
2071 case FSF_DATADIR_WRITE:
2072 lat = &unit->latencies.write;
2073 break;
2074 case FSF_DATADIR_CMND:
2075 lat = &unit->latencies.cmd;
2076 break;
2077 default:
2078 return;
2079 }
2080
Christof Schmitt49f0f012009-03-02 13:08:57 +01002081 spin_lock(&unit->latencies.lock);
Christof Schmittc9615852008-05-06 11:00:05 +02002082 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2083 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2084 lat->counter++;
Christof Schmitt49f0f012009-03-02 13:08:57 +01002085 spin_unlock(&unit->latencies.lock);
Christof Schmittc9615852008-05-06 11:00:05 +02002086}
2087
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002088#ifdef CONFIG_BLK_DEV_IO_TRACE
2089static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2090{
2091 struct fsf_qual_latency_info *lat_inf;
2092 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
2093 struct request *req = scsi_cmnd->request;
2094 struct zfcp_blk_drv_data trace;
2095 int ticks = fsf_req->adapter->timer_ticks;
2096
2097 trace.flags = 0;
2098 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2099 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2100 trace.flags |= ZFCP_BLK_LAT_VALID;
2101 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2102 trace.channel_lat = lat_inf->channel_lat * ticks;
2103 trace.fabric_lat = lat_inf->fabric_lat * ticks;
2104 }
2105 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2106 trace.flags |= ZFCP_BLK_REQ_ERROR;
2107 trace.inb_usage = fsf_req->qdio_inb_usage;
2108 trace.outb_usage = fsf_req->qdio_outb_usage;
2109
2110 blk_add_driver_data(req->q, req, &trace, sizeof(trace));
2111}
2112#else
2113static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2114{
2115}
2116#endif
2117
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002118static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002120 struct scsi_cmnd *scpnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002122 &(req->qtcb->bottom.io.fcp_rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 u32 sns_len;
Martin Petermannf76af7d2008-07-02 10:56:36 +02002124 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002127 read_lock_irqsave(&req->adapter->abort_lock, flags);
2128
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002129 scpnt = req->data;
2130 if (unlikely(!scpnt)) {
2131 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2132 return;
2133 }
2134
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002135 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002136 set_host_byte(scpnt, DID_SOFT_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 goto skip_fsfstatus;
2138 }
2139
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002140 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002141 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 goto skip_fsfstatus;
2143 }
2144
Martin Petermannfeac6a02008-07-02 10:56:35 +02002145 set_msg_byte(scpnt, COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 scpnt->result |= fcp_rsp_iu->scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002149 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2150 zfcp_fsf_req_latency(req);
Christof Schmittc9615852008-05-06 11:00:05 +02002151
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002152 zfcp_fsf_trace_latency(req);
2153
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002155 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002156 set_host_byte(scpnt, DID_OK);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002157 else {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002158 set_host_byte(scpnt, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05002159 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 }
2161 }
2162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002164 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2165 fcp_rsp_iu->fcp_rsp_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09002169 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 }
2172
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
FUJITA Tomonori7936a892007-07-29 16:46:28 +09002174 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2175 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2176 scpnt->underflow)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002177 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002179skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002180 if (scpnt->result != 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002181 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002182 else if (scpnt->retries > 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002183 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002184 else
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002185 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 /*
2190 * We must hold this lock until scsi_done has been called.
2191 * Otherwise we may call scsi_done after abort regarding this
2192 * command has completed.
2193 * Note: scsi_done must not block!
2194 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002195 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196}
2197
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002198static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002201 &(req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d2008-07-02 10:56:36 +02002202 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002204 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2205 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2206 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207}
2208
2209
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002210static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2211{
2212 struct zfcp_unit *unit;
2213 struct fsf_qtcb_header *header = &req->qtcb->header;
2214
2215 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2216 unit = req->data;
2217 else
2218 unit = req->unit;
2219
2220 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2221 goto skip_fsfstatus;
2222
2223 switch (header->fsf_status) {
2224 case FSF_HANDLE_MISMATCH:
2225 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002226 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002227 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2228 break;
2229 case FSF_FCPLUN_NOT_VALID:
2230 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002231 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002232 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2233 break;
2234 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2235 zfcp_fsf_class_not_supp(req);
2236 break;
2237 case FSF_ACCESS_DENIED:
2238 zfcp_fsf_access_denied_unit(req, unit);
2239 break;
2240 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2241 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002242 "Incorrect direction %d, unit 0x%016Lx on port "
2243 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002244 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002245 (unsigned long long)unit->fcp_lun,
2246 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002247 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2248 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002249 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2250 break;
2251 case FSF_CMND_LENGTH_NOT_VALID:
2252 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002253 "Incorrect CDB length %d, unit 0x%016Lx on "
2254 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002255 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002256 (unsigned long long)unit->fcp_lun,
2257 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002258 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2259 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002260 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2261 break;
2262 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002263 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002264 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2265 ZFCP_STATUS_FSFREQ_RETRY;
2266 break;
2267 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002268 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002269 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2270 ZFCP_STATUS_FSFREQ_RETRY;
2271 break;
2272 case FSF_ADAPTER_STATUS_AVAILABLE:
2273 if (header->fsf_status_qual.word[0] ==
2274 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2275 zfcp_test_link(unit->port);
2276 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2277 break;
2278 }
2279skip_fsfstatus:
2280 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2281 zfcp_fsf_send_fcp_ctm_handler(req);
2282 else {
2283 zfcp_fsf_send_fcp_command_task_handler(req);
2284 req->unit = NULL;
2285 zfcp_unit_put(unit);
2286 }
2287}
2288
Swen Schillig7ba58c92008-10-01 12:42:18 +02002289static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2290{
2291 u32 *fcp_dl_ptr;
2292
2293 /*
2294 * fcp_dl_addr = start address of fcp_cmnd structure +
2295 * size of fixed part + size of dynamically sized add_dcp_cdb field
2296 * SEE FCP-2 documentation
2297 */
2298 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2299 (fcp_cmd->add_fcp_cdb_length << 2));
2300 *fcp_dl_ptr = fcp_dl;
2301}
2302
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002303/**
2304 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002305 * @unit: unit where command is sent to
2306 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002307 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002308int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2309 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002310{
2311 struct zfcp_fsf_req *req;
2312 struct fcp_cmnd_iu *fcp_cmnd_iu;
2313 unsigned int sbtype;
2314 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002315 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002316
2317 if (unlikely(!(atomic_read(&unit->status) &
2318 ZFCP_STATUS_COMMON_UNBLOCKED)))
2319 return -EBUSY;
2320
Christof Schmitt04062892008-10-01 12:42:20 +02002321 spin_lock(&adapter->req_q_lock);
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002322 if (atomic_read(&adapter->req_q.count) <= 0) {
2323 atomic_inc(&adapter->qdio_outb_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002324 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002325 }
Christof Schmitt63caf362009-03-02 13:09:00 +01002326 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
2327 ZFCP_REQ_AUTO_CLEANUP,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002328 adapter->pool.fsf_req_scsi);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002329 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002330 retval = PTR_ERR(req);
2331 goto out;
2332 }
2333
2334 zfcp_unit_get(unit);
2335 req->unit = unit;
2336 req->data = scsi_cmnd;
2337 req->handler = zfcp_fsf_send_fcp_command_handler;
2338 req->qtcb->header.lun_handle = unit->handle;
2339 req->qtcb->header.port_handle = unit->port->handle;
2340 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2341
2342 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2343
2344 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2345 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2346 /*
2347 * set depending on data direction:
2348 * data direction bits in SBALE (SB Type)
2349 * data direction bits in QTCB
2350 * data direction bits in FCP_CMND IU
2351 */
2352 switch (scsi_cmnd->sc_data_direction) {
2353 case DMA_NONE:
2354 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2355 sbtype = SBAL_FLAGS0_TYPE_READ;
2356 break;
2357 case DMA_FROM_DEVICE:
2358 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2359 sbtype = SBAL_FLAGS0_TYPE_READ;
2360 fcp_cmnd_iu->rddata = 1;
2361 break;
2362 case DMA_TO_DEVICE:
2363 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2364 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2365 fcp_cmnd_iu->wddata = 1;
2366 break;
2367 case DMA_BIDIRECTIONAL:
2368 default:
2369 retval = -EIO;
2370 goto failed_scsi_cmnd;
2371 }
2372
2373 if (likely((scsi_cmnd->device->simple_tags) ||
2374 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2375 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2376 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2377 else
2378 fcp_cmnd_iu->task_attribute = UNTAGGED;
2379
2380 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2381 fcp_cmnd_iu->add_fcp_cdb_length =
2382 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2383
2384 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2385
2386 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
Swen Schillig7ba58c92008-10-01 12:42:18 +02002387 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002388
2389 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2390 scsi_sglist(scsi_cmnd),
2391 FSF_MAX_SBALS_PER_REQ);
2392 if (unlikely(real_bytes < 0)) {
2393 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2394 retval = -EIO;
2395 else {
2396 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002397 "Oversize data package, unit 0x%016Lx "
2398 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002399 (unsigned long long)unit->fcp_lun,
2400 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002401 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002402 retval = -EINVAL;
2403 }
2404 goto failed_scsi_cmnd;
2405 }
2406
2407 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2408
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002409 retval = zfcp_fsf_req_send(req);
2410 if (unlikely(retval))
2411 goto failed_scsi_cmnd;
2412
2413 goto out;
2414
2415failed_scsi_cmnd:
2416 zfcp_unit_put(unit);
2417 zfcp_fsf_req_free(req);
2418 scsi_cmnd->host_scribble = NULL;
2419out:
Christof Schmitt04062892008-10-01 12:42:20 +02002420 spin_unlock(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002421 return retval;
2422}
2423
2424/**
2425 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002426 * @unit: pointer to struct zfcp_unit
2427 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002428 * Returns: on success pointer to struct fsf_req, NULL otherwise
2429 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002430struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002431{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002432 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002433 struct zfcp_fsf_req *req = NULL;
2434 struct fcp_cmnd_iu *fcp_cmnd_iu;
Christof Schmitt63caf362009-03-02 13:09:00 +01002435 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002436
2437 if (unlikely(!(atomic_read(&unit->status) &
2438 ZFCP_STATUS_COMMON_UNBLOCKED)))
2439 return NULL;
2440
Christof Schmitt92cab0d2009-03-02 13:08:59 +01002441 spin_lock_bh(&adapter->req_q_lock);
2442 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002443 goto out;
Christof Schmitt63caf362009-03-02 13:09:00 +01002444 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002445 adapter->pool.fsf_req_scsi);
Swen Schillig633528c2008-11-26 18:07:37 +01002446 if (IS_ERR(req)) {
2447 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002448 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002449 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002450
2451 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2452 req->data = unit;
2453 req->handler = zfcp_fsf_send_fcp_command_handler;
2454 req->qtcb->header.lun_handle = unit->handle;
2455 req->qtcb->header.port_handle = unit->port->handle;
2456 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2457 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2458 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
Swen Schillig7ba58c92008-10-01 12:42:18 +02002459 sizeof(u32);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002460
2461 sbale = zfcp_qdio_sbale_req(req);
2462 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2463 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2464
2465 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2466 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2467 fcp_cmnd_iu->task_management_flags = tm_flags;
2468
2469 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2470 if (!zfcp_fsf_req_send(req))
2471 goto out;
2472
2473 zfcp_fsf_req_free(req);
2474 req = NULL;
2475out:
Christof Schmitt92cab0d2009-03-02 13:08:59 +01002476 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002477 return req;
2478}
2479
2480static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2481{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002482}
2483
2484/**
2485 * zfcp_fsf_control_file - control file upload/download
2486 * @adapter: pointer to struct zfcp_adapter
2487 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2488 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002490struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2491 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002493 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002494 struct zfcp_fsf_req *req = NULL;
2495 struct fsf_qtcb_bottom_support *bottom;
2496 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Christof Schmitt45633fd2008-06-10 18:20:55 +02002498 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2499 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
Christof Schmitt45633fd2008-06-10 18:20:55 +02002501 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2503 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2506 direction = SBAL_FLAGS0_TYPE_READ;
2507 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002509 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 }
2511
Christof Schmitt04062892008-10-01 12:42:20 +02002512 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002513 if (zfcp_fsf_req_sbal_get(adapter))
2514 goto out;
2515
2516 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002517 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002519 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 }
2521
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002522 req->handler = zfcp_fsf_control_file_handler;
2523
2524 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 sbale[0].flags |= direction;
2526
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002527 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002529 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002531 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2532 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002533 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2534 retval = -ENOMEM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002535 zfcp_fsf_req_free(req);
2536 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002539 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2540 retval = zfcp_fsf_req_send(req);
2541out:
Christof Schmitt04062892008-10-01 12:42:20 +02002542 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002543
2544 if (!retval) {
2545 wait_event(req->completion_wq,
2546 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2547 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002549 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550}