blob: af75fd2ef1e2ae1be16211c0ea1f63b587c19ad1 [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 Schmitt553448f2008-06-10 18:20:58 +02006 * Copyright IBM Corporation 2002, 2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include "zfcp_ext.h"
10
Christof Schmitt287ac012008-07-02 10:56:40 +020011static void zfcp_fsf_request_timeout_handler(unsigned long data)
12{
13 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
14 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
15 NULL);
16}
17
18static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
19 unsigned long timeout)
20{
21 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
22 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
23 fsf_req->timer.expires = jiffies + timeout;
24 add_timer(&fsf_req->timer);
25}
26
27static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
28{
29 BUG_ON(!fsf_req->erp_action);
30 fsf_req->timer.function = zfcp_erp_timeout_handler;
31 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
32 fsf_req->timer.expires = jiffies + 30 * HZ;
33 add_timer(&fsf_req->timer);
34}
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/* association between FSF command and FSF QTCB type */
37static u32 fsf_qtcb_type[] = {
38 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
39 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
40 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
41 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
42 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
43 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
44 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
45 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
46 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
48 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
49 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
51};
52
Christof Schmitt553448f2008-06-10 18:20:58 +020053static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
54{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020055 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020056 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020057 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020058
Christof Schmittff3b24f2008-10-01 12:42:15 +020059 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020060 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020061 "Access denied according to ACT rule type %s, "
62 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020063}
64
65static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
66 struct zfcp_port *port)
67{
68 struct fsf_qtcb_header *header = &req->qtcb->header;
69 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020070 "Access denied to port 0x%016Lx\n",
Christof Schmitt553448f2008-06-10 18:20:58 +020071 port->wwpn);
72 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
73 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
74 zfcp_erp_port_access_denied(port, 55, req);
75 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
76}
77
78static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
79 struct zfcp_unit *unit)
80{
81 struct fsf_qtcb_header *header = &req->qtcb->header;
82 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020083 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Christof Schmitt553448f2008-06-10 18:20:58 +020084 unit->fcp_lun, unit->port->wwpn);
85 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
86 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
87 zfcp_erp_unit_access_denied(unit, 59, req);
88 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
89}
90
91static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
92{
Christof Schmittff3b24f2008-10-01 12:42:15 +020093 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
94 "operational because of an unsupported FC class\n");
Christof Schmitt553448f2008-06-10 18:20:58 +020095 zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
96 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
97}
98
Swen Schilligc41f8cb2008-07-02 10:56:39 +020099/**
100 * zfcp_fsf_req_free - free memory used by fsf request
101 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200103void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200105 if (likely(req->pool)) {
106 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200107 return;
108 }
109
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200110 if (req->qtcb) {
111 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200112 return;
113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200116/**
117 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
118 * @adapter: pointer to struct zfcp_adapter
119 *
Martin Peschke869b2b42007-05-09 11:01:20 +0200120 * Never ever call this without shutting down the adapter first.
121 * Otherwise the adapter would continue using and corrupting s390 storage.
122 * Included BUG_ON() call to ensure this is done.
123 * ERP is supposed to be the only user of this function.
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200124 */
Swen Schillig6fcc4712007-02-07 13:17:57 +0100125void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200126{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200127 struct zfcp_fsf_req *req, *tmp;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200128 unsigned long flags;
Swen Schillig6fcc4712007-02-07 13:17:57 +0100129 LIST_HEAD(remove_queue);
Martin Peschke869b2b42007-05-09 11:01:20 +0200130 unsigned int i;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200131
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200132 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200133 spin_lock_irqsave(&adapter->req_list_lock, flags);
Martin Peschke869b2b42007-05-09 11:01:20 +0200134 for (i = 0; i < REQUEST_LIST_SIZE; i++)
Swen Schillig6fcc4712007-02-07 13:17:57 +0100135 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200136 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
137
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200138 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
139 list_del(&req->list);
140 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
141 zfcp_fsf_req_complete(req);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100142 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200143}
144
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200145static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200147 struct fsf_status_read_buffer *sr_buf = req->data;
148 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 struct zfcp_port *port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200150 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 unsigned long flags;
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 read_lock_irqsave(&zfcp_data.config_lock, flags);
154 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200155 if (port->d_id == d_id) {
156 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
157 switch (sr_buf->status_subtype) {
158 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
159 zfcp_erp_port_reopen(port, 0, 101, req);
160 break;
161 case FSF_STATUS_READ_SUB_ERROR_PORT:
162 zfcp_erp_port_shutdown(port, 0, 122, req);
163 break;
164 }
165 return;
166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200170static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
171 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200173 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200175 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
176 return;
177
178 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
179
180 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200182
183 switch (link_down->error_code) {
184 case FSF_PSQ_LINK_NO_LIGHT:
185 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200186 "There is no light signal from the local "
187 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200188 break;
189 case FSF_PSQ_LINK_WRAP_PLUG:
190 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200191 "There is a wrap plug instead of a fibre "
192 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200193 break;
194 case FSF_PSQ_LINK_NO_FCP:
195 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200196 "The adjacent fibre channel node does not "
197 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200198 break;
199 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
200 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200201 "The FCP device is suspended because of a "
202 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200203 break;
204 case FSF_PSQ_LINK_INVALID_WWPN:
205 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200206 "The FCP device detected a WWPN that is "
207 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200208 break;
209 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
210 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200211 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200212 break;
213 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
214 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200215 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200216 break;
217 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
218 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200219 "The adjacent switch cannot support "
220 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200221 break;
222 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
223 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200224 "The FCP adapter could not log in to the "
225 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200226 break;
227 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
228 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200229 "The WWPN assignment file on the FCP adapter "
230 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200231 break;
232 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
233 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200234 "The mode table on the FCP adapter "
235 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200236 break;
237 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
238 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200239 "All NPIV ports on the FCP adapter have "
240 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200241 break;
242 default:
243 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200244 "The link between the FCP adapter and "
245 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200246 }
247out:
248 zfcp_erp_adapter_failed(adapter, id, req);
249}
250
251static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
252{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200253 struct fsf_status_read_buffer *sr_buf = req->data;
254 struct fsf_link_down_info *ldi =
255 (struct fsf_link_down_info *) &sr_buf->payload;
256
257 switch (sr_buf->status_subtype) {
258 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200259 zfcp_fsf_link_down_info_eval(req, 38, ldi);
260 break;
261 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200262 zfcp_fsf_link_down_info_eval(req, 39, ldi);
263 break;
264 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200265 zfcp_fsf_link_down_info_eval(req, 40, NULL);
266 };
267}
268
269static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
270{
271 struct zfcp_adapter *adapter = req->adapter;
272 struct fsf_status_read_buffer *sr_buf = req->data;
273
274 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
275 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
276 mempool_free(sr_buf, adapter->pool.data_status_read);
277 zfcp_fsf_req_free(req);
278 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200281 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200282
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200283 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200285 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200288 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200293 dev_warn(&adapter->ccw_device->dev,
294 "The error threshold for checksum statistics "
295 "has been exceeded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200298 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200301 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200302 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200304 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 ZFCP_STATUS_COMMON_RUNNING,
306 ZFCP_SET);
307 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200308 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
309 ZFCP_STATUS_COMMON_ERP_FAILED,
310 102, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100312 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200313 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
314 zfcp_erp_adapter_access_changed(adapter, 135, req);
315 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200316 schedule_work(&adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100317 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200319 zfcp_erp_adapter_access_changed(adapter, 136, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200321 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200322 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200323 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200325
326 mempool_free(sr_buf, adapter->pool.data_status_read);
327 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200328
329 atomic_inc(&adapter->stat_miss);
330 schedule_work(&adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
332
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200333static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200335 switch (req->qtcb->header.fsf_status_qual.word[0]) {
336 case FSF_SQ_FCP_RSP_AVAILABLE:
337 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
338 case FSF_SQ_NO_RETRY_POSSIBLE:
339 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
340 return;
341 case FSF_SQ_COMMAND_ABORTED:
342 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
343 break;
344 case FSF_SQ_NO_RECOM:
345 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200346 "The FCP adapter reported a problem "
347 "that cannot be recovered\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200348 zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
349 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200351 /* all non-return stats set FSFREQ_ERROR*/
352 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
353}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200355static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
356{
357 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
358 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200359
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200360 switch (req->qtcb->header.fsf_status) {
361 case FSF_UNKNOWN_COMMAND:
362 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200363 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200364 req->qtcb->header.fsf_command);
365 zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
366 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200369 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200374static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200376 struct zfcp_adapter *adapter = req->adapter;
377 struct fsf_qtcb *qtcb = req->qtcb;
378 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200380 zfcp_hba_dbf_event_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200382 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
383 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
384 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
385 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
387
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200388 switch (qtcb->prefix.prot_status) {
389 case FSF_PROT_GOOD:
390 case FSF_PROT_FSF_STATUS_PRESENTED:
391 return;
392 case FSF_PROT_QTCB_VERSION_ERROR:
393 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200394 "QTCB version 0x%x not supported by FCP adapter "
395 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
396 psq->word[0], psq->word[1]);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200397 zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200399 case FSF_PROT_ERROR_STATE:
400 case FSF_PROT_SEQ_NUMB_ERROR:
401 zfcp_erp_adapter_reopen(adapter, 0, 98, req);
402 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200404 case FSF_PROT_UNSUPP_QTCB_TYPE:
405 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200406 "The QTCB type is not supported by the FCP adapter\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200407 zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200409 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
410 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
411 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200413 case FSF_PROT_DUPLICATE_REQUEST_ID:
414 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200415 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200416 (unsigned long long)qtcb->bottom.support.req_handle);
417 zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200419 case FSF_PROT_LINK_DOWN:
420 zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
421 /* FIXME: reopening adapter now? better wait for link up */
422 zfcp_erp_adapter_reopen(adapter, 0, 79, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200424 case FSF_PROT_REEST_QUEUE:
425 /* All ports should be marked as ready to run again */
426 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
427 ZFCP_STATUS_COMMON_RUNNING,
428 ZFCP_SET);
429 zfcp_erp_adapter_reopen(adapter,
430 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
431 ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
432 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200434 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200435 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200436 qtcb->prefix.prot_status);
437 zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200439 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200443 * zfcp_fsf_req_complete - process completion of a FSF request
444 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200446 * When a request has been completed either from the FCP adapter,
447 * or it has been dismissed due to a queue shutdown, this function
448 * is called to process the completion status and trigger further
449 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200451void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
452{
453 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
454 zfcp_fsf_status_read_handler(req);
455 return;
456 }
457
458 del_timer(&req->timer);
459 zfcp_fsf_protstatus_eval(req);
460 zfcp_fsf_fsfstatus_eval(req);
461 req->handler(req);
462
463 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200464 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200465 req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
466
467 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
468 zfcp_fsf_req_free(req);
469 else
470 /* notify initiator waiting for the requests completion */
471 /*
472 * FIXME: Race! We must not access fsf_req here as it might have been
473 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
474 * flag. It's an improbable case. But, we have the same paranoia for
475 * the cleanup flag already.
476 * Might better be handled using complete()?
477 * (setting the flag and doing wakeup ought to be atomic
478 * with regard to checking the flag as long as waitqueue is
479 * part of the to be released structure)
480 */
481 wake_up(&req->completion_wq);
482}
483
484static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
486 struct fsf_qtcb_bottom_config *bottom;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200487 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200488 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200490 bottom = &req->qtcb->bottom.config;
491
492 if (req->data)
493 memcpy(req->data, bottom, sizeof(*bottom));
494
495 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
496 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
497 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
498 fc_host_speed(shost) = bottom->fc_link_speed;
499 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
500
501 adapter->hydra_version = bottom->adapter_type;
502 adapter->timer_ticks = bottom->timer_interval;
503
504 if (fc_host_permanent_port_name(shost) == -1)
505 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
506
507 switch (bottom->fc_topology) {
508 case FSF_TOPO_P2P:
509 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
510 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
511 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
512 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200513 break;
514 case FSF_TOPO_FABRIC:
515 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200516 break;
517 case FSF_TOPO_AL:
518 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200519 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200520 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200521 "Unknown or unsupported arbitrated loop "
522 "fibre channel topology detected\n");
523 zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200524 return -EIO;
525 }
526
527 return 0;
528}
529
530static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
531{
532 struct zfcp_adapter *adapter = req->adapter;
533 struct fsf_qtcb *qtcb = req->qtcb;
534 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
535 struct Scsi_Host *shost = adapter->scsi_host;
536
537 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
538 return;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200541 adapter->adapter_features = bottom->adapter_features;
542 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500543 adapter->peer_wwpn = 0;
544 adapter->peer_wwnn = 0;
545 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200547 switch (qtcb->header.fsf_status) {
548 case FSF_GOOD:
549 if (zfcp_fsf_exchange_config_evaluate(req))
550 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200551
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200552 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
553 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200554 "FCP adapter maximum QTCB size (%d bytes) "
555 "is too small\n",
556 bottom->max_qtcb_size);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200557 zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
558 return;
559 }
560 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
561 &adapter->status);
562 break;
563 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200564 fc_host_node_name(shost) = 0;
565 fc_host_port_name(shost) = 0;
566 fc_host_port_id(shost) = 0;
567 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100568 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200570
571 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
572 &adapter->status);
573
574 zfcp_fsf_link_down_info_eval(req, 42,
575 &qtcb->header.fsf_status_qual.link_down_info);
576 break;
577 default:
578 zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
579 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200582 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200584 memcpy(fc_host_serial_number(shost), bottom->serial_number,
585 min(FC_SERIAL_NUMBER_SIZE, 17));
586 EBCASC(fc_host_serial_number(shost),
587 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200590 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200591 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200592 "The FCP adapter only supports newer "
593 "control block versions\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200594 zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
595 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200597 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200598 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200599 "The FCP adapter only supports older "
600 "control block versions\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200601 zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
604
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200605static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200607 struct zfcp_adapter *adapter = req->adapter;
608 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
609 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200611 if (req->data)
612 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100613
614 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
615 fc_host_permanent_port_name(shost) = bottom->wwpn;
616 else
617 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
618 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
619 fc_host_supported_speeds(shost) = bottom->supported_speed;
620}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200622static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200624 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100625
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200626 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return;
628
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200629 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200630 case FSF_GOOD:
631 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200632 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200633 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200634 zfcp_fsf_exchange_port_evaluate(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200635 zfcp_fsf_link_down_info_eval(req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
639}
640
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200641static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
642{
Christof Schmittd4538812008-08-21 13:43:32 +0200643 spin_lock_bh(&queue->lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644 if (atomic_read(&queue->count))
645 return 1;
Christof Schmittd4538812008-08-21 13:43:32 +0200646 spin_unlock_bh(&queue->lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200647 return 0;
648}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200650static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
651{
652 unsigned int count = atomic_read(&adapter->req_q.count);
653 if (!count)
654 atomic_inc(&adapter->qdio_outb_full);
655 return count > 0;
656}
657
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
659{
660 long ret;
661 struct zfcp_qdio_queue *req_q = &adapter->req_q;
662
Christof Schmittd4538812008-08-21 13:43:32 +0200663 spin_unlock_bh(&req_q->lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200664 ret = wait_event_interruptible_timeout(adapter->request_wq,
665 zfcp_fsf_sbal_check(req_q), 5 * HZ);
666 if (ret > 0)
667 return 0;
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200668 if (!ret)
669 atomic_inc(&adapter->qdio_outb_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200670
Christof Schmittd4538812008-08-21 13:43:32 +0200671 spin_lock_bh(&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));
682 return req;
683}
684
685static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
686{
687 struct zfcp_fsf_req_qtcb *qtcb;
688
689 if (likely(pool))
690 qtcb = mempool_alloc(pool, GFP_ATOMIC);
691 else
692 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
693 GFP_ATOMIC);
694 if (unlikely(!qtcb))
695 return NULL;
696
697 memset(qtcb, 0, sizeof(*qtcb));
698 qtcb->fsf_req.qtcb = &qtcb->qtcb;
699 qtcb->fsf_req.pool = pool;
700
701 return &qtcb->fsf_req;
702}
703
704static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
705 u32 fsf_cmd, int req_flags,
706 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200708 struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200710 struct zfcp_fsf_req *req;
711 struct zfcp_qdio_queue *req_q = &adapter->req_q;
712
713 if (req_flags & ZFCP_REQ_NO_QTCB)
714 req = zfcp_fsf_alloc_noqtcb(pool);
715 else
716 req = zfcp_fsf_alloc_qtcb(pool);
717
718 if (unlikely(!req))
719 return ERR_PTR(-EIO);
720
721 if (adapter->req_no == 0)
722 adapter->req_no++;
723
724 INIT_LIST_HEAD(&req->list);
725 init_timer(&req->timer);
726 init_waitqueue_head(&req->completion_wq);
727
728 req->adapter = adapter;
729 req->fsf_command = fsf_cmd;
730 req->req_id = adapter->req_no++;
731 req->sbal_number = 1;
732 req->sbal_first = req_q->first;
733 req->sbal_last = req_q->first;
734 req->sbale_curr = 1;
735
736 sbale = zfcp_qdio_sbale_req(req);
737 sbale[0].addr = (void *) req->req_id;
738 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
739
740 if (likely(req->qtcb)) {
741 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
742 req->qtcb->prefix.req_id = req->req_id;
743 req->qtcb->prefix.ulp_info = 26;
744 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
745 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
746 req->qtcb->header.req_handle = req->req_id;
747 req->qtcb->header.fsf_command = req->fsf_command;
748 req->seq_no = adapter->fsf_req_seq_no;
749 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
750 sbale[1].addr = (void *) req->qtcb;
751 sbale[1].length = sizeof(struct fsf_qtcb);
752 }
753
754 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
755 zfcp_fsf_req_free(req);
756 return ERR_PTR(-EIO);
757 }
758
759 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
760 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
761
762 return req;
763}
764
765static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
766{
767 struct zfcp_adapter *adapter = req->adapter;
768 struct zfcp_qdio_queue *req_q = &adapter->req_q;
769 int idx;
770
771 /* put allocated FSF request into hash table */
772 spin_lock(&adapter->req_list_lock);
773 idx = zfcp_reqlist_hash(req->req_id);
774 list_add_tail(&req->list, &adapter->req_list[idx]);
775 spin_unlock(&adapter->req_list_lock);
776
777 req->issued = get_clock();
778 if (zfcp_qdio_send(req)) {
779 /* Queues are down..... */
780 del_timer(&req->timer);
781 spin_lock(&adapter->req_list_lock);
782 zfcp_reqlist_remove(adapter, req);
783 spin_unlock(&adapter->req_list_lock);
784 /* undo changes in request queue made for this request */
785 atomic_add(req->sbal_number, &req_q->count);
786 req_q->first -= req->sbal_number;
787 req_q->first += QDIO_MAX_BUFFERS_PER_Q;
788 req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
789 zfcp_erp_adapter_reopen(adapter, 0, 116, req);
790 return -EIO;
791 }
792
793 /* Don't increase for unsolicited status */
794 if (req->qtcb)
795 adapter->fsf_req_seq_no++;
796
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 Schmittd4538812008-08-21 13:43:32 +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 Schmittd4538812008-08-21 13:43:32 +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]) {
868 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
869 req);
870 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]) {
875 zfcp_erp_port_reopen(unit->port, 0, 105, req);
876 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:
883 zfcp_erp_port_boxed(unit->port, 47, req);
884 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
885 ZFCP_STATUS_FSFREQ_RETRY;
886 break;
887 case FSF_LUN_BOXED:
888 zfcp_erp_unit_boxed(unit, 48, req);
889 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
910 * @adapter: pointer to struct zfcp_adapter
911 * @unit: pointer to struct zfcp_unit
912 * @req_flags: integer specifying the request flags
913 * Returns: pointer to struct zfcp_fsf_req
914 *
915 * FIXME(design): should be watched by a timeout !!!
916 */
917
918struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
919 struct zfcp_adapter *adapter,
920 struct zfcp_unit *unit,
921 int req_flags)
922{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200923 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200924 struct zfcp_fsf_req *req = NULL;
925
926 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200927 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200928 goto out;
929 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
930 req_flags, adapter->pool.fsf_req_abort);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200931 if (IS_ERR(req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200932 goto out;
933
934 if (unlikely(!(atomic_read(&unit->status) &
935 ZFCP_STATUS_COMMON_UNBLOCKED)))
936 goto out_error_free;
937
938 sbale = zfcp_qdio_sbale_req(req);
939 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
940 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
941
942 req->data = unit;
943 req->handler = zfcp_fsf_abort_fcp_command_handler;
944 req->qtcb->header.lun_handle = unit->handle;
945 req->qtcb->header.port_handle = unit->port->handle;
946 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
947
948 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
949 if (!zfcp_fsf_req_send(req))
950 goto out;
951
952out_error_free:
953 zfcp_fsf_req_free(req);
954 req = NULL;
955out:
956 spin_unlock(&adapter->req_q.lock);
957 return req;
958}
959
960static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
961{
962 struct zfcp_adapter *adapter = req->adapter;
963 struct zfcp_send_ct *send_ct = req->data;
964 struct zfcp_port *port = send_ct->port;
965 struct fsf_qtcb_header *header = &req->qtcb->header;
966
967 send_ct->status = -EINVAL;
968
969 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
970 goto skip_fsfstatus;
971
972 switch (header->fsf_status) {
973 case FSF_GOOD:
974 zfcp_san_dbf_event_ct_response(req);
975 send_ct->status = 0;
976 break;
977 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
978 zfcp_fsf_class_not_supp(req);
979 break;
980 case FSF_ADAPTER_STATUS_AVAILABLE:
981 switch (header->fsf_status_qual.word[0]){
982 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
983 zfcp_test_link(port);
984 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
985 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
986 break;
987 }
988 break;
989 case FSF_ACCESS_DENIED:
990 zfcp_fsf_access_denied_port(req, port);
991 break;
992 case FSF_PORT_BOXED:
993 zfcp_erp_port_boxed(port, 49, req);
994 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
995 ZFCP_STATUS_FSFREQ_RETRY;
996 break;
997 case FSF_PORT_HANDLE_NOT_VALID:
998 zfcp_erp_adapter_reopen(adapter, 0, 106, req);
999 case FSF_GENERIC_COMMAND_REJECTED:
1000 case FSF_PAYLOAD_SIZE_MISMATCH:
1001 case FSF_REQUEST_SIZE_TOO_LARGE:
1002 case FSF_RESPONSE_SIZE_TOO_LARGE:
1003 case FSF_SBAL_MISMATCH:
1004 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1005 break;
1006 }
1007
1008skip_fsfstatus:
1009 if (send_ct->handler)
1010 send_ct->handler(send_ct->handler_data);
1011}
1012
1013static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
1014 struct scatterlist *sg_req,
1015 struct scatterlist *sg_resp, int max_sbals)
1016{
1017 int bytes;
1018
1019 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1020 sg_req, max_sbals);
1021 if (bytes <= 0)
1022 return -ENOMEM;
1023 req->qtcb->bottom.support.req_buf_length = bytes;
1024 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1025
1026 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1027 sg_resp, max_sbals);
1028 if (bytes <= 0)
1029 return -ENOMEM;
1030 req->qtcb->bottom.support.resp_buf_length = bytes;
1031
1032 return 0;
1033}
1034
1035/**
1036 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1037 * @ct: pointer to struct zfcp_send_ct with data for request
1038 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1039 * @erp_action: if non-null the Generic Service request sent within ERP
1040 */
1041int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1042 struct zfcp_erp_action *erp_action)
1043{
1044 struct zfcp_port *port = ct->port;
1045 struct zfcp_adapter *adapter = port->adapter;
1046 struct zfcp_fsf_req *req;
1047 int ret = -EIO;
1048
Christof Schmittd4538812008-08-21 13:43:32 +02001049 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001050 if (zfcp_fsf_req_sbal_get(adapter))
1051 goto out;
1052
1053 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1054 ZFCP_REQ_AUTO_CLEANUP, pool);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001055 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001056 ret = PTR_ERR(req);
1057 goto out;
1058 }
1059
1060 ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
1061 FSF_MAX_SBALS_PER_REQ);
1062 if (ret)
1063 goto failed_send;
1064
1065 req->handler = zfcp_fsf_send_ct_handler;
1066 req->qtcb->header.port_handle = port->handle;
1067 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1068 req->qtcb->bottom.support.timeout = ct->timeout;
1069 req->data = ct;
1070
1071 zfcp_san_dbf_event_ct_request(req);
1072
1073 if (erp_action) {
1074 erp_action->fsf_req = req;
1075 req->erp_action = erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +02001076 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001077 } else
1078 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1079
1080 ret = zfcp_fsf_req_send(req);
1081 if (ret)
1082 goto failed_send;
1083
1084 goto out;
1085
1086failed_send:
1087 zfcp_fsf_req_free(req);
1088 if (erp_action)
1089 erp_action->fsf_req = NULL;
1090out:
Christof Schmittd4538812008-08-21 13:43:32 +02001091 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001092 return ret;
1093}
1094
1095static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1096{
1097 struct zfcp_send_els *send_els = req->data;
1098 struct zfcp_port *port = send_els->port;
1099 struct fsf_qtcb_header *header = &req->qtcb->header;
1100
1101 send_els->status = -EINVAL;
1102
1103 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1104 goto skip_fsfstatus;
1105
1106 switch (header->fsf_status) {
1107 case FSF_GOOD:
1108 zfcp_san_dbf_event_els_response(req);
1109 send_els->status = 0;
1110 break;
1111 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1112 zfcp_fsf_class_not_supp(req);
1113 break;
1114 case FSF_ADAPTER_STATUS_AVAILABLE:
1115 switch (header->fsf_status_qual.word[0]){
1116 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1117 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1118 zfcp_test_link(port);
1119 /*fall through */
1120 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1121 case FSF_SQ_RETRY_IF_POSSIBLE:
1122 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1123 break;
1124 }
1125 break;
1126 case FSF_ELS_COMMAND_REJECTED:
1127 case FSF_PAYLOAD_SIZE_MISMATCH:
1128 case FSF_REQUEST_SIZE_TOO_LARGE:
1129 case FSF_RESPONSE_SIZE_TOO_LARGE:
1130 break;
1131 case FSF_ACCESS_DENIED:
1132 zfcp_fsf_access_denied_port(req, port);
1133 break;
1134 case FSF_SBAL_MISMATCH:
1135 /* should never occure, avoided in zfcp_fsf_send_els */
1136 /* fall through */
1137 default:
1138 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1139 break;
1140 }
1141skip_fsfstatus:
1142 if (send_els->handler)
1143 send_els->handler(send_els->handler_data);
1144}
1145
1146/**
1147 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1148 * @els: pointer to struct zfcp_send_els with data for the command
1149 */
1150int zfcp_fsf_send_els(struct zfcp_send_els *els)
1151{
1152 struct zfcp_fsf_req *req;
1153 struct zfcp_adapter *adapter = els->adapter;
1154 struct fsf_qtcb_bottom_support *bottom;
1155 int ret = -EIO;
1156
1157 if (unlikely(!(atomic_read(&els->port->status) &
1158 ZFCP_STATUS_COMMON_UNBLOCKED)))
1159 return -EBUSY;
1160
1161 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001162 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001163 goto out;
1164 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1165 ZFCP_REQ_AUTO_CLEANUP, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001166 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001167 ret = PTR_ERR(req);
1168 goto out;
1169 }
1170
Swen Schillig44cc76f2008-10-01 12:42:16 +02001171 ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, 2);
1172
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001173 if (ret)
1174 goto failed_send;
1175
1176 bottom = &req->qtcb->bottom.support;
1177 req->handler = zfcp_fsf_send_els_handler;
1178 bottom->d_id = els->d_id;
1179 bottom->service_class = FSF_CLASS_3;
1180 bottom->timeout = 2 * R_A_TOV;
1181 req->data = els;
1182
1183 zfcp_san_dbf_event_els_request(req);
1184
1185 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1186 ret = zfcp_fsf_req_send(req);
1187 if (ret)
1188 goto failed_send;
1189
1190 goto out;
1191
1192failed_send:
1193 zfcp_fsf_req_free(req);
1194out:
1195 spin_unlock(&adapter->req_q.lock);
1196 return ret;
1197}
1198
1199int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1200{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001201 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001202 struct zfcp_fsf_req *req;
1203 struct zfcp_adapter *adapter = erp_action->adapter;
1204 int retval = -EIO;
1205
Christof Schmittd4538812008-08-21 13:43:32 +02001206 spin_lock_bh(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001207 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001208 goto out;
1209 req = zfcp_fsf_req_create(adapter,
1210 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1211 ZFCP_REQ_AUTO_CLEANUP,
1212 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001213 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001214 retval = PTR_ERR(req);
1215 goto out;
1216 }
1217
1218 sbale = zfcp_qdio_sbale_req(req);
1219 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1220 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1221
1222 req->qtcb->bottom.config.feature_selection =
1223 FSF_FEATURE_CFDC |
1224 FSF_FEATURE_LUN_SHARING |
1225 FSF_FEATURE_NOTIFICATION_LOST |
1226 FSF_FEATURE_UPDATE_ALERT;
1227 req->erp_action = erp_action;
1228 req->handler = zfcp_fsf_exchange_config_data_handler;
1229 erp_action->fsf_req = req;
1230
Christof Schmitt287ac012008-07-02 10:56:40 +02001231 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232 retval = zfcp_fsf_req_send(req);
1233 if (retval) {
1234 zfcp_fsf_req_free(req);
1235 erp_action->fsf_req = NULL;
1236 }
1237out:
Christof Schmittd4538812008-08-21 13:43:32 +02001238 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001239 return retval;
1240}
1241
1242int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1243 struct fsf_qtcb_bottom_config *data)
1244{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001245 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001246 struct zfcp_fsf_req *req = NULL;
1247 int retval = -EIO;
1248
Christof Schmittd4538812008-08-21 13:43:32 +02001249 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001250 if (zfcp_fsf_req_sbal_get(adapter))
1251 goto out;
1252
1253 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1254 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001255 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001256 retval = PTR_ERR(req);
1257 goto out;
1258 }
1259
1260 sbale = zfcp_qdio_sbale_req(req);
1261 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1262 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1263 req->handler = zfcp_fsf_exchange_config_data_handler;
1264
1265 req->qtcb->bottom.config.feature_selection =
1266 FSF_FEATURE_CFDC |
1267 FSF_FEATURE_LUN_SHARING |
1268 FSF_FEATURE_NOTIFICATION_LOST |
1269 FSF_FEATURE_UPDATE_ALERT;
1270
1271 if (data)
1272 req->data = data;
1273
1274 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1275 retval = zfcp_fsf_req_send(req);
1276out:
Christof Schmittd4538812008-08-21 13:43:32 +02001277 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001278 if (!retval)
1279 wait_event(req->completion_wq,
1280 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1281
1282 zfcp_fsf_req_free(req);
1283
1284 return retval;
1285}
1286
1287/**
1288 * zfcp_fsf_exchange_port_data - request information about local port
1289 * @erp_action: ERP action for the adapter for which port data is requested
1290 * Returns: 0 on success, error otherwise
1291 */
1292int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1293{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001294 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001295 struct zfcp_fsf_req *req;
1296 struct zfcp_adapter *adapter = erp_action->adapter;
1297 int retval = -EIO;
1298
1299 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1300 return -EOPNOTSUPP;
1301
Christof Schmittd4538812008-08-21 13:43:32 +02001302 spin_lock_bh(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001303 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001304 goto out;
1305 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1306 ZFCP_REQ_AUTO_CLEANUP,
1307 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001308 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001309 retval = PTR_ERR(req);
1310 goto out;
1311 }
1312
1313 sbale = zfcp_qdio_sbale_req(req);
1314 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1315 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1316
1317 req->handler = zfcp_fsf_exchange_port_data_handler;
1318 req->erp_action = erp_action;
1319 erp_action->fsf_req = req;
1320
Christof Schmitt287ac012008-07-02 10:56:40 +02001321 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001322 retval = zfcp_fsf_req_send(req);
1323 if (retval) {
1324 zfcp_fsf_req_free(req);
1325 erp_action->fsf_req = NULL;
1326 }
1327out:
Christof Schmittd4538812008-08-21 13:43:32 +02001328 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 return retval;
1330}
1331
1332/**
1333 * zfcp_fsf_exchange_port_data_sync - request information about local port
1334 * @adapter: pointer to struct zfcp_adapter
1335 * @data: pointer to struct fsf_qtcb_bottom_port
1336 * Returns: 0 on success, error otherwise
1337 */
1338int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1339 struct fsf_qtcb_bottom_port *data)
1340{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001341 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001342 struct zfcp_fsf_req *req = NULL;
1343 int retval = -EIO;
1344
1345 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1346 return -EOPNOTSUPP;
1347
Christof Schmittd4538812008-08-21 13:43:32 +02001348 spin_lock_bh(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001349 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001350 goto out;
1351
1352 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1353 NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001354 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001355 retval = PTR_ERR(req);
1356 goto out;
1357 }
1358
1359 if (data)
1360 req->data = data;
1361
1362 sbale = zfcp_qdio_sbale_req(req);
1363 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1364 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1365
1366 req->handler = zfcp_fsf_exchange_port_data_handler;
1367 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1368 retval = zfcp_fsf_req_send(req);
1369out:
Christof Schmittd4538812008-08-21 13:43:32 +02001370 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001371 if (!retval)
1372 wait_event(req->completion_wq,
1373 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1374 zfcp_fsf_req_free(req);
1375
1376 return retval;
1377}
1378
1379static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1380{
1381 struct zfcp_port *port = req->data;
1382 struct fsf_qtcb_header *header = &req->qtcb->header;
1383 struct fsf_plogi *plogi;
1384
1385 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001386 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001387
1388 switch (header->fsf_status) {
1389 case FSF_PORT_ALREADY_OPEN:
1390 break;
1391 case FSF_ACCESS_DENIED:
1392 zfcp_fsf_access_denied_port(req, port);
1393 break;
1394 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1395 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001396 "Not enough FCP adapter resources to open "
1397 "remote port 0x%016Lx\n", port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001398 zfcp_erp_port_failed(port, 31, req);
1399 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1400 break;
1401 case FSF_ADAPTER_STATUS_AVAILABLE:
1402 switch (header->fsf_status_qual.word[0]) {
1403 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1404 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1405 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1406 break;
1407 case FSF_SQ_NO_RETRY_POSSIBLE:
1408 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001409 "Remote port 0x%016Lx could not be opened\n",
1410 port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001411 zfcp_erp_port_failed(port, 32, req);
1412 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1413 break;
1414 }
1415 break;
1416 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1419 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001420 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1421 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1422 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 /* check whether D_ID has changed during open */
1424 /*
1425 * FIXME: This check is not airtight, as the FCP channel does
1426 * not monitor closures of target port connections caused on
1427 * the remote side. Thus, they might miss out on invalidating
1428 * locally cached WWPNs (and other N_Port parameters) of gone
1429 * target ports. So, our heroic attempt to make things safe
1430 * could be undermined by 'open port' response data tagged with
1431 * obsolete WWPNs. Another reason to monitor potential
1432 * connection closures ourself at least (by interpreting
1433 * incoming ELS' and unsolicited status). It just crosses my
1434 * mind that one should be able to cross-check by means of
1435 * another GID_PN straight after a port has been opened.
1436 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1437 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001438 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN)
1439 break;
1440
1441 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1442 if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
1443 if (plogi->serv_param.wwpn != port->wwpn)
1444 atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
1445 &port->status);
1446 else {
1447 port->wwnn = plogi->serv_param.wwnn;
1448 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450 }
1451 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001453 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 break;
1455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
1457
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001458/**
1459 * zfcp_fsf_open_port - create and send open port request
1460 * @erp_action: pointer to struct zfcp_erp_action
1461 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001463int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001465 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001466 struct zfcp_adapter *adapter = erp_action->adapter;
1467 struct zfcp_fsf_req *req;
1468 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Christof Schmittd4538812008-08-21 13:43:32 +02001470 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001471 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001474 req = zfcp_fsf_req_create(adapter,
1475 FSF_QTCB_OPEN_PORT_WITH_DID,
1476 ZFCP_REQ_AUTO_CLEANUP,
1477 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001478 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479 retval = PTR_ERR(req);
1480 goto out;
1481 }
1482
1483 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1485 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1486
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001487 req->handler = zfcp_fsf_open_port_handler;
1488 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
1489 req->data = erp_action->port;
1490 req->erp_action = erp_action;
1491 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Christof Schmitt287ac012008-07-02 10:56:40 +02001493 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001496 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001499out:
Christof Schmittd4538812008-08-21 13:43:32 +02001500 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 return retval;
1502}
1503
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001504static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001506 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001508 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001509 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001511 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001513 zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
1514 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001519 zfcp_erp_modify_port_status(port, 33, req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 ZFCP_STATUS_COMMON_OPEN,
1521 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524}
1525
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001526/**
1527 * zfcp_fsf_close_port - create and send close port request
1528 * @erp_action: pointer to struct zfcp_erp_action
1529 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001531int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001533 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001534 struct zfcp_adapter *adapter = erp_action->adapter;
1535 struct zfcp_fsf_req *req;
1536 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Christof Schmittd4538812008-08-21 13:43:32 +02001538 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001539 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001542 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1543 ZFCP_REQ_AUTO_CLEANUP,
1544 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001545 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001546 retval = PTR_ERR(req);
1547 goto out;
1548 }
1549
1550 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1552 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1553
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001554 req->handler = zfcp_fsf_close_port_handler;
1555 req->data = erp_action->port;
1556 req->erp_action = erp_action;
1557 req->qtcb->header.port_handle = erp_action->port->handle;
1558 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Christof Schmitt287ac012008-07-02 10:56:40 +02001560 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001561 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001563 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001566out:
Christof Schmittd4538812008-08-21 13:43:32 +02001567 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 return retval;
1569}
1570
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001571static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001573 struct zfcp_port *port = req->data;
1574 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001577 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001582 zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
1583 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001586 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 case FSF_PORT_BOXED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001589 zfcp_erp_port_boxed(port, 50, req);
1590 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1591 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01001592 /* can't use generic zfcp_erp_modify_port_status because
1593 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1594 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1595 list_for_each_entry(unit, &port->unit_list_head, list)
1596 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1597 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 switch (header->fsf_status_qual.word[0]) {
1601 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001602 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001604 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 }
1607 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 /* can't use generic zfcp_erp_modify_port_status because
1610 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1611 */
1612 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1613 list_for_each_entry(unit, &port->unit_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001614 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1615 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001618skip_fsfstatus:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001622/**
1623 * zfcp_fsf_close_physical_port - close physical port
1624 * @erp_action: pointer to struct zfcp_erp_action
1625 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001627int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001629 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001630 struct zfcp_adapter *adapter = erp_action->adapter;
1631 struct zfcp_fsf_req *req;
1632 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
Christof Schmittd4538812008-08-21 13:43:32 +02001634 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001635 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001638 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1639 ZFCP_REQ_AUTO_CLEANUP,
1640 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001641 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001642 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 goto out;
1644 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001645
1646 sbale = zfcp_qdio_sbale_req(req);
1647 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1648 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1649
1650 req->data = erp_action->port;
1651 req->qtcb->header.port_handle = erp_action->port->handle;
1652 req->erp_action = erp_action;
1653 req->handler = zfcp_fsf_close_physical_port_handler;
1654 erp_action->fsf_req = req;
1655 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
1656 &erp_action->port->status);
1657
Christof Schmitt287ac012008-07-02 10:56:40 +02001658 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001659 retval = zfcp_fsf_req_send(req);
1660 if (retval) {
1661 zfcp_fsf_req_free(req);
1662 erp_action->fsf_req = NULL;
1663 }
1664out:
Christof Schmittd4538812008-08-21 13:43:32 +02001665 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 return retval;
1667}
1668
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001669static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001671 struct zfcp_adapter *adapter = req->adapter;
1672 struct zfcp_unit *unit = req->data;
1673 struct fsf_qtcb_header *header = &req->qtcb->header;
1674 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1675 struct fsf_queue_designator *queue_designator =
1676 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001677 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001679 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001680 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001683 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 ZFCP_STATUS_UNIT_SHARED |
1685 ZFCP_STATUS_UNIT_READONLY,
1686 &unit->status);
1687
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 switch (header->fsf_status) {
1689
1690 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001691 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
1692 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001696 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001698 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 case FSF_PORT_BOXED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001701 zfcp_erp_port_boxed(unit->port, 51, req);
1702 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1703 ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001706 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001707 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001708 "LUN 0x%Lx on port 0x%Lx is already in "
1709 "use by CSS%d, MIF Image ID %x\n",
Christof Schmitt553448f2008-06-10 18:20:58 +02001710 unit->fcp_lun,
1711 unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001712 queue_designator->cssid,
1713 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001714 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001715 zfcp_act_eval_err(adapter,
1716 header->fsf_status_qual.word[2]);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001717 zfcp_erp_unit_access_denied(unit, 60, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1719 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001720 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001723 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001724 "No handle is available for LUN "
1725 "0x%016Lx on port 0x%016Lx\n",
Christof Schmitt553448f2008-06-10 18:20:58 +02001726 unit->fcp_lun, unit->port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001727 zfcp_erp_unit_failed(unit, 34, req);
1728 /* fall through */
1729 case FSF_INVALID_COMMAND_OPTION:
1730 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 switch (header->fsf_status_qual.word[0]) {
1734 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001735 zfcp_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001736 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001738 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 }
1741 break;
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001746
1747 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1748 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1749 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
1750 exclusive = (bottom->lun_access_info &
1751 FSF_UNIT_ACCESS_EXCLUSIVE);
1752 readwrite = (bottom->lun_access_info &
1753 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 if (!exclusive)
1756 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1757 &unit->status);
1758
1759 if (!readwrite) {
1760 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1761 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001762 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001763 "SCSI device at LUN 0x%016Lx on port "
1764 "0x%016Lx opened read-only\n",
Christof Schmitt553448f2008-06-10 18:20:58 +02001765 unit->fcp_lun, unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 }
1767
1768 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001769 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001770 "Exclusive read-only access not "
1771 "supported (unit 0x%016Lx, "
1772 "port 0x%016Lx)\n",
Christof Schmitt553448f2008-06-10 18:20:58 +02001773 unit->fcp_lun, unit->port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001774 zfcp_erp_unit_failed(unit, 35, req);
1775 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1776 zfcp_erp_unit_shutdown(unit, 0, 80, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001778 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001779 "Shared read-write access not "
1780 "supported (unit 0x%016Lx, port "
1781 "0x%016Lx\n)",
Christof Schmitt553448f2008-06-10 18:20:58 +02001782 unit->fcp_lun, unit->port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001783 zfcp_erp_unit_failed(unit, 36, req);
1784 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1785 zfcp_erp_unit_shutdown(unit, 0, 81, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 }
1787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790}
1791
1792/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001793 * zfcp_fsf_open_unit - open unit
1794 * @erp_action: pointer to struct zfcp_erp_action
1795 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001797int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001799 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001800 struct zfcp_adapter *adapter = erp_action->adapter;
1801 struct zfcp_fsf_req *req;
1802 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Christof Schmittd4538812008-08-21 13:43:32 +02001804 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001805 if (zfcp_fsf_req_sbal_get(adapter))
1806 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001808 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1809 ZFCP_REQ_AUTO_CLEANUP,
1810 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001811 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001812 retval = PTR_ERR(req);
1813 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001814 }
1815
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001816 sbale = zfcp_qdio_sbale_req(req);
1817 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1818 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001820 req->qtcb->header.port_handle = erp_action->port->handle;
1821 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1822 req->handler = zfcp_fsf_open_unit_handler;
1823 req->data = erp_action->unit;
1824 req->erp_action = erp_action;
1825 erp_action->fsf_req = req;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001826
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001827 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1828 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Christof Schmitt287ac012008-07-02 10:56:40 +02001830 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001831 retval = zfcp_fsf_req_send(req);
1832 if (retval) {
1833 zfcp_fsf_req_free(req);
1834 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001836out:
Christof Schmittd4538812008-08-21 13:43:32 +02001837 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 return retval;
1839}
1840
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001841static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001843 struct zfcp_unit *unit = req->data;
1844
1845 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001846 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001847
1848 switch (req->qtcb->header.fsf_status) {
1849 case FSF_PORT_HANDLE_NOT_VALID:
1850 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
1851 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1852 break;
1853 case FSF_LUN_HANDLE_NOT_VALID:
1854 zfcp_erp_port_reopen(unit->port, 0, 111, req);
1855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1856 break;
1857 case FSF_PORT_BOXED:
1858 zfcp_erp_port_boxed(unit->port, 52, req);
1859 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1860 ZFCP_STATUS_FSFREQ_RETRY;
1861 break;
1862 case FSF_ADAPTER_STATUS_AVAILABLE:
1863 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1864 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1865 zfcp_test_link(unit->port);
1866 /* fall through */
1867 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1868 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1869 break;
1870 }
1871 break;
1872 case FSF_GOOD:
1873 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1874 break;
1875 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001876}
1877
1878/**
1879 * zfcp_fsf_close_unit - close zfcp unit
1880 * @erp_action: pointer to struct zfcp_unit
1881 * Returns: 0 on success, error otherwise
1882 */
1883int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1884{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001885 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886 struct zfcp_adapter *adapter = erp_action->adapter;
1887 struct zfcp_fsf_req *req;
1888 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Christof Schmittd4538812008-08-21 13:43:32 +02001890 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001891 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001893 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
1894 ZFCP_REQ_AUTO_CLEANUP,
1895 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001896 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001897 retval = PTR_ERR(req);
1898 goto out;
1899 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001901 sbale = zfcp_qdio_sbale_req(req);
1902 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1904
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001905 req->qtcb->header.port_handle = erp_action->port->handle;
1906 req->qtcb->header.lun_handle = erp_action->unit->handle;
1907 req->handler = zfcp_fsf_close_unit_handler;
1908 req->data = erp_action->unit;
1909 req->erp_action = erp_action;
1910 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
Christof Schmitt287ac012008-07-02 10:56:40 +02001912 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001913 retval = zfcp_fsf_req_send(req);
1914 if (retval) {
1915 zfcp_fsf_req_free(req);
1916 erp_action->fsf_req = NULL;
1917 }
1918out:
Christof Schmittd4538812008-08-21 13:43:32 +02001919 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001920 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921}
1922
Christof Schmittc9615852008-05-06 11:00:05 +02001923static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
1924{
1925 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001926 lat_rec->min = min(lat_rec->min, lat);
1927 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02001928}
1929
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001930static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
Christof Schmittc9615852008-05-06 11:00:05 +02001931{
1932 struct fsf_qual_latency_info *lat_inf;
1933 struct latency_cont *lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001934 struct zfcp_unit *unit = req->unit;
Christof Schmittc9615852008-05-06 11:00:05 +02001935 unsigned long flags;
1936
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001937 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02001938
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001939 switch (req->qtcb->bottom.io.data_direction) {
Christof Schmittc9615852008-05-06 11:00:05 +02001940 case FSF_DATADIR_READ:
1941 lat = &unit->latencies.read;
1942 break;
1943 case FSF_DATADIR_WRITE:
1944 lat = &unit->latencies.write;
1945 break;
1946 case FSF_DATADIR_CMND:
1947 lat = &unit->latencies.cmd;
1948 break;
1949 default:
1950 return;
1951 }
1952
1953 spin_lock_irqsave(&unit->latencies.lock, flags);
1954 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
1955 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
1956 lat->counter++;
1957 spin_unlock_irqrestore(&unit->latencies.lock, flags);
1958}
1959
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001960static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001962 struct scsi_cmnd *scpnt = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001964 &(req->qtcb->bottom.io.fcp_rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 u32 sns_len;
Martin Petermannf76af7d72008-07-02 10:56:36 +02001966 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
Christof Schmitt553448f2008-06-10 18:20:58 +02001969 if (unlikely(!scpnt))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001970 return;
Christof Schmitt553448f2008-06-10 18:20:58 +02001971
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001972 read_lock_irqsave(&req->adapter->abort_lock, flags);
1973
1974 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02001975 set_host_byte(scpnt, DID_SOFT_ERROR);
1976 set_driver_byte(scpnt, SUGGEST_RETRY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 goto skip_fsfstatus;
1978 }
1979
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001980 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02001981 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 goto skip_fsfstatus;
1983 }
1984
Martin Petermannfeac6a02008-07-02 10:56:35 +02001985 set_msg_byte(scpnt, COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 scpnt->result |= fcp_rsp_iu->scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001989 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
1990 zfcp_fsf_req_latency(req);
Christof Schmittc9615852008-05-06 11:00:05 +02001991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001993 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
Martin Petermannfeac6a02008-07-02 10:56:35 +02001994 set_host_byte(scpnt, DID_OK);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001995 else {
Martin Petermannfeac6a02008-07-02 10:56:35 +02001996 set_host_byte(scpnt, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05001997 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 }
1999 }
2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002002 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2003 fcp_rsp_iu->fcp_rsp_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09002007 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
FUJITA Tomonori7936a892007-07-29 16:46:28 +09002012 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2013 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2014 scpnt->underflow)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002015 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002017skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002018 if (scpnt->result != 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002019 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002020 else if (scpnt->retries > 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002021 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002022 else
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002023 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 /*
2028 * We must hold this lock until scsi_done has been called.
2029 * Otherwise we may call scsi_done after abort regarding this
2030 * command has completed.
2031 * Note: scsi_done must not block!
2032 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002033 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034}
2035
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002036static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002039 &(req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d72008-07-02 10:56:36 +02002040 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002042 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2043 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2044 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
2047
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002048static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2049{
2050 struct zfcp_unit *unit;
2051 struct fsf_qtcb_header *header = &req->qtcb->header;
2052
2053 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2054 unit = req->data;
2055 else
2056 unit = req->unit;
2057
2058 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2059 goto skip_fsfstatus;
2060
2061 switch (header->fsf_status) {
2062 case FSF_HANDLE_MISMATCH:
2063 case FSF_PORT_HANDLE_NOT_VALID:
2064 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
2065 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2066 break;
2067 case FSF_FCPLUN_NOT_VALID:
2068 case FSF_LUN_HANDLE_NOT_VALID:
2069 zfcp_erp_port_reopen(unit->port, 0, 113, req);
2070 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2071 break;
2072 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2073 zfcp_fsf_class_not_supp(req);
2074 break;
2075 case FSF_ACCESS_DENIED:
2076 zfcp_fsf_access_denied_unit(req, unit);
2077 break;
2078 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2079 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002080 "Incorrect direction %d, unit 0x%016Lx on port "
2081 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002082 req->qtcb->bottom.io.data_direction,
2083 unit->fcp_lun, unit->port->wwpn);
2084 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
2085 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2086 break;
2087 case FSF_CMND_LENGTH_NOT_VALID:
2088 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002089 "Incorrect CDB length %d, unit 0x%016Lx on "
2090 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002091 req->qtcb->bottom.io.fcp_cmnd_length,
2092 unit->fcp_lun, unit->port->wwpn);
2093 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
2094 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2095 break;
2096 case FSF_PORT_BOXED:
2097 zfcp_erp_port_boxed(unit->port, 53, req);
2098 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2099 ZFCP_STATUS_FSFREQ_RETRY;
2100 break;
2101 case FSF_LUN_BOXED:
2102 zfcp_erp_unit_boxed(unit, 54, req);
2103 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2104 ZFCP_STATUS_FSFREQ_RETRY;
2105 break;
2106 case FSF_ADAPTER_STATUS_AVAILABLE:
2107 if (header->fsf_status_qual.word[0] ==
2108 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2109 zfcp_test_link(unit->port);
2110 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2111 break;
2112 }
2113skip_fsfstatus:
2114 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2115 zfcp_fsf_send_fcp_ctm_handler(req);
2116 else {
2117 zfcp_fsf_send_fcp_command_task_handler(req);
2118 req->unit = NULL;
2119 zfcp_unit_put(unit);
2120 }
2121}
2122
2123/**
2124 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2125 * @adapter: adapter where scsi command is issued
2126 * @unit: unit where command is sent to
2127 * @scsi_cmnd: scsi command to be sent
2128 * @timer: timer to be started when request is initiated
2129 * @req_flags: flags for fsf_request
2130 */
2131int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
2132 struct zfcp_unit *unit,
2133 struct scsi_cmnd *scsi_cmnd,
2134 int use_timer, int req_flags)
2135{
2136 struct zfcp_fsf_req *req;
2137 struct fcp_cmnd_iu *fcp_cmnd_iu;
2138 unsigned int sbtype;
2139 int real_bytes, retval = -EIO;
2140
2141 if (unlikely(!(atomic_read(&unit->status) &
2142 ZFCP_STATUS_COMMON_UNBLOCKED)))
2143 return -EBUSY;
2144
2145 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02002146 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002147 goto out;
2148 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2149 adapter->pool.fsf_req_scsi);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002150 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002151 retval = PTR_ERR(req);
2152 goto out;
2153 }
2154
2155 zfcp_unit_get(unit);
2156 req->unit = unit;
2157 req->data = scsi_cmnd;
2158 req->handler = zfcp_fsf_send_fcp_command_handler;
2159 req->qtcb->header.lun_handle = unit->handle;
2160 req->qtcb->header.port_handle = unit->port->handle;
2161 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2162
2163 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2164
2165 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2166 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2167 /*
2168 * set depending on data direction:
2169 * data direction bits in SBALE (SB Type)
2170 * data direction bits in QTCB
2171 * data direction bits in FCP_CMND IU
2172 */
2173 switch (scsi_cmnd->sc_data_direction) {
2174 case DMA_NONE:
2175 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2176 sbtype = SBAL_FLAGS0_TYPE_READ;
2177 break;
2178 case DMA_FROM_DEVICE:
2179 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2180 sbtype = SBAL_FLAGS0_TYPE_READ;
2181 fcp_cmnd_iu->rddata = 1;
2182 break;
2183 case DMA_TO_DEVICE:
2184 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2185 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2186 fcp_cmnd_iu->wddata = 1;
2187 break;
2188 case DMA_BIDIRECTIONAL:
2189 default:
2190 retval = -EIO;
2191 goto failed_scsi_cmnd;
2192 }
2193
2194 if (likely((scsi_cmnd->device->simple_tags) ||
2195 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2196 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2197 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2198 else
2199 fcp_cmnd_iu->task_attribute = UNTAGGED;
2200
2201 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2202 fcp_cmnd_iu->add_fcp_cdb_length =
2203 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2204
2205 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2206
2207 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2208 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
2209
2210 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2211 scsi_sglist(scsi_cmnd),
2212 FSF_MAX_SBALS_PER_REQ);
2213 if (unlikely(real_bytes < 0)) {
2214 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2215 retval = -EIO;
2216 else {
2217 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002218 "Oversize data package, unit 0x%016Lx "
2219 "on port 0x%016Lx closed\n",
2220 unit->fcp_lun, unit->port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002221 zfcp_erp_unit_shutdown(unit, 0, 131, req);
2222 retval = -EINVAL;
2223 }
2224 goto failed_scsi_cmnd;
2225 }
2226
2227 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2228
2229 if (use_timer)
2230 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2231
2232 retval = zfcp_fsf_req_send(req);
2233 if (unlikely(retval))
2234 goto failed_scsi_cmnd;
2235
2236 goto out;
2237
2238failed_scsi_cmnd:
2239 zfcp_unit_put(unit);
2240 zfcp_fsf_req_free(req);
2241 scsi_cmnd->host_scribble = NULL;
2242out:
2243 spin_unlock(&adapter->req_q.lock);
2244 return retval;
2245}
2246
2247/**
2248 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2249 * @adapter: pointer to struct zfcp-adapter
2250 * @unit: pointer to struct zfcp_unit
2251 * @tm_flags: unsigned byte for task management flags
2252 * @req_flags: int request flags
2253 * Returns: on success pointer to struct fsf_req, NULL otherwise
2254 */
2255struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
2256 struct zfcp_unit *unit,
2257 u8 tm_flags, int req_flags)
2258{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002259 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002260 struct zfcp_fsf_req *req = NULL;
2261 struct fcp_cmnd_iu *fcp_cmnd_iu;
2262
2263 if (unlikely(!(atomic_read(&unit->status) &
2264 ZFCP_STATUS_COMMON_UNBLOCKED)))
2265 return NULL;
2266
2267 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02002268 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002269 goto out;
2270 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2271 adapter->pool.fsf_req_scsi);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002272 if (IS_ERR(req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002273 goto out;
2274
2275 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2276 req->data = unit;
2277 req->handler = zfcp_fsf_send_fcp_command_handler;
2278 req->qtcb->header.lun_handle = unit->handle;
2279 req->qtcb->header.port_handle = unit->port->handle;
2280 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2281 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2282 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2283 sizeof(fcp_dl_t);
2284
2285 sbale = zfcp_qdio_sbale_req(req);
2286 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2287 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2288
2289 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2290 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2291 fcp_cmnd_iu->task_management_flags = tm_flags;
2292
2293 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2294 if (!zfcp_fsf_req_send(req))
2295 goto out;
2296
2297 zfcp_fsf_req_free(req);
2298 req = NULL;
2299out:
2300 spin_unlock(&adapter->req_q.lock);
2301 return req;
2302}
2303
2304static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2305{
2306 if (req->qtcb->header.fsf_status != FSF_GOOD)
2307 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2308}
2309
2310/**
2311 * zfcp_fsf_control_file - control file upload/download
2312 * @adapter: pointer to struct zfcp_adapter
2313 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2314 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002316struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2317 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002319 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002320 struct zfcp_fsf_req *req = NULL;
2321 struct fsf_qtcb_bottom_support *bottom;
2322 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
Christof Schmitt45633fd2008-06-10 18:20:55 +02002324 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2325 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
Christof Schmitt45633fd2008-06-10 18:20:55 +02002327 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2329 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2332 direction = SBAL_FLAGS0_TYPE_READ;
2333 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002335 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 }
2337
Christof Schmittd4538812008-08-21 13:43:32 +02002338 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002339 if (zfcp_fsf_req_sbal_get(adapter))
2340 goto out;
2341
2342 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002343 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002345 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 }
2347
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348 req->handler = zfcp_fsf_control_file_handler;
2349
2350 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 sbale[0].flags |= direction;
2352
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002353 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002355 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002357 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2358 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002359 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2360 retval = -ENOMEM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002361 zfcp_fsf_req_free(req);
2362 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002365 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2366 retval = zfcp_fsf_req_send(req);
2367out:
Christof Schmittd4538812008-08-21 13:43:32 +02002368 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002369
2370 if (!retval) {
2371 wait_event(req->completion_wq,
2372 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2373 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002375 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376}