blob: 9e083a5e2c4e3d3e450dfcb152b512ea24a8a87e [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
Swen Schilligc41f8cb2008-07-02 10:56:39 +020053static const char *zfcp_act_subtable_type[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 "unknown", "OS", "WWPN", "DID", "LUN"
55};
56
Christof Schmitt553448f2008-06-10 18:20:58 +020057static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
58{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020059 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020060 u16 rule = table & 0xffff;
61
Swen Schilligc41f8cb2008-07-02 10:56:39 +020062 if (subtable && subtable < ARRAY_SIZE(zfcp_act_subtable_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020063 dev_warn(&adapter->ccw_device->dev,
64 "Access denied in subtable %s, rule %d.\n",
65 zfcp_act_subtable_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020066}
67
68static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
69 struct zfcp_port *port)
70{
71 struct fsf_qtcb_header *header = &req->qtcb->header;
72 dev_warn(&req->adapter->ccw_device->dev,
73 "Access denied, cannot send command to port 0x%016Lx.\n",
74 port->wwpn);
75 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
76 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
77 zfcp_erp_port_access_denied(port, 55, req);
78 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
79}
80
81static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
82 struct zfcp_unit *unit)
83{
84 struct fsf_qtcb_header *header = &req->qtcb->header;
85 dev_warn(&req->adapter->ccw_device->dev,
86 "Access denied for unit 0x%016Lx on port 0x%016Lx.\n",
87 unit->fcp_lun, unit->port->wwpn);
88 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
89 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
90 zfcp_erp_unit_access_denied(unit, 59, req);
91 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
92}
93
94static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
95{
96 dev_err(&req->adapter->ccw_device->dev,
97 "Required FC class not supported by adapter, "
98 "shutting down adapter.\n");
99 zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
100 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
101}
102
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200103/**
104 * zfcp_fsf_req_free - free memory used by fsf request
105 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200107void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200109 if (likely(req->pool)) {
110 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200111 return;
112 }
113
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200114 if (req->qtcb) {
115 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200116 return;
117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200120/**
121 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
122 * @adapter: pointer to struct zfcp_adapter
123 *
Martin Peschke869b2b42007-05-09 11:01:20 +0200124 * Never ever call this without shutting down the adapter first.
125 * Otherwise the adapter would continue using and corrupting s390 storage.
126 * Included BUG_ON() call to ensure this is done.
127 * ERP is supposed to be the only user of this function.
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200128 */
Swen Schillig6fcc4712007-02-07 13:17:57 +0100129void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200130{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200131 struct zfcp_fsf_req *req, *tmp;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200132 unsigned long flags;
Swen Schillig6fcc4712007-02-07 13:17:57 +0100133 LIST_HEAD(remove_queue);
Martin Peschke869b2b42007-05-09 11:01:20 +0200134 unsigned int i;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200135
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200136 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200137 spin_lock_irqsave(&adapter->req_list_lock, flags);
Martin Peschke869b2b42007-05-09 11:01:20 +0200138 for (i = 0; i < REQUEST_LIST_SIZE; i++)
Swen Schillig6fcc4712007-02-07 13:17:57 +0100139 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200140 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
141
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200142 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
143 list_del(&req->list);
144 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
145 zfcp_fsf_req_complete(req);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100146 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200147}
148
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200149static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200151 struct fsf_status_read_buffer *sr_buf = req->data;
152 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct zfcp_port *port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200154 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 unsigned long flags;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 read_lock_irqsave(&zfcp_data.config_lock, flags);
158 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200159 if (port->d_id == d_id) {
160 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
161 switch (sr_buf->status_subtype) {
162 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
163 zfcp_erp_port_reopen(port, 0, 101, req);
164 break;
165 case FSF_STATUS_READ_SUB_ERROR_PORT:
166 zfcp_erp_port_shutdown(port, 0, 122, req);
167 break;
168 }
169 return;
170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Christof Schmitt553448f2008-06-10 18:20:58 +0200174static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req)
175{
176 struct zfcp_adapter *adapter = req->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200177 struct fsf_status_read_buffer *sr_buf = req->data;
178 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
179
Christof Schmitt553448f2008-06-10 18:20:58 +0200180 dev_warn(&adapter->ccw_device->dev,
181 "Warning: bit error threshold data "
182 "received for the adapter: "
183 "link failures = %i, loss of sync errors = %i, "
184 "loss of signal errors = %i, "
185 "primitive sequence errors = %i, "
186 "invalid transmission word errors = %i, "
187 "CRC errors = %i).\n",
188 err->link_failure_error_count,
189 err->loss_of_sync_error_count,
190 err->loss_of_signal_error_count,
191 err->primitive_sequence_error_count,
192 err->invalid_transmission_word_error_count,
193 err->crc_error_count);
194 dev_warn(&adapter->ccw_device->dev,
195 "Additional bit error threshold data of the adapter: "
196 "primitive sequence event time-outs = %i, "
197 "elastic buffer overrun errors = %i, "
198 "advertised receive buffer-to-buffer credit = %i, "
199 "current receice buffer-to-buffer credit = %i, "
200 "advertised transmit buffer-to-buffer credit = %i, "
201 "current transmit buffer-to-buffer credit = %i).\n",
202 err->primitive_sequence_event_timeout_count,
203 err->elastic_buffer_overrun_error_count,
204 err->advertised_receive_b2b_credit,
205 err->current_receive_b2b_credit,
206 err->advertised_transmit_b2b_credit,
207 err->current_transmit_b2b_credit);
208}
209
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200210static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
211 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200213 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200215 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
216 return;
217
218 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
219
220 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200222
223 switch (link_down->error_code) {
224 case FSF_PSQ_LINK_NO_LIGHT:
225 dev_warn(&req->adapter->ccw_device->dev,
226 "The local link is down: no light detected.\n");
227 break;
228 case FSF_PSQ_LINK_WRAP_PLUG:
229 dev_warn(&req->adapter->ccw_device->dev,
230 "The local link is down: wrap plug detected.\n");
231 break;
232 case FSF_PSQ_LINK_NO_FCP:
233 dev_warn(&req->adapter->ccw_device->dev,
234 "The local link is down: "
235 "adjacent node on link does not support FCP.\n");
236 break;
237 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
238 dev_warn(&req->adapter->ccw_device->dev,
239 "The local link is down: "
240 "firmware update in progress.\n");
241 break;
242 case FSF_PSQ_LINK_INVALID_WWPN:
243 dev_warn(&req->adapter->ccw_device->dev,
244 "The local link is down: "
245 "duplicate or invalid WWPN detected.\n");
246 break;
247 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
248 dev_warn(&req->adapter->ccw_device->dev,
249 "The local link is down: "
250 "no support for NPIV by Fabric.\n");
251 break;
252 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
253 dev_warn(&req->adapter->ccw_device->dev,
254 "The local link is down: "
255 "out of resource in FCP daughtercard.\n");
256 break;
257 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
258 dev_warn(&req->adapter->ccw_device->dev,
259 "The local link is down: "
260 "out of resource in Fabric.\n");
261 break;
262 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
263 dev_warn(&req->adapter->ccw_device->dev,
264 "The local link is down: "
265 "unable to login to Fabric.\n");
266 break;
267 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
268 dev_warn(&req->adapter->ccw_device->dev,
269 "WWPN assignment file corrupted on adapter.\n");
270 break;
271 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
272 dev_warn(&req->adapter->ccw_device->dev,
273 "Mode table corrupted on adapter.\n");
274 break;
275 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
276 dev_warn(&req->adapter->ccw_device->dev,
277 "No WWPN for assignment table on adapter.\n");
278 break;
279 default:
280 dev_warn(&req->adapter->ccw_device->dev,
281 "The local link to adapter is down.\n");
282 }
283out:
284 zfcp_erp_adapter_failed(adapter, id, req);
285}
286
287static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
288{
289 struct zfcp_adapter *adapter = req->adapter;
290 struct fsf_status_read_buffer *sr_buf = req->data;
291 struct fsf_link_down_info *ldi =
292 (struct fsf_link_down_info *) &sr_buf->payload;
293
294 switch (sr_buf->status_subtype) {
295 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
296 dev_warn(&adapter->ccw_device->dev,
297 "Physical link is down.\n");
298 zfcp_fsf_link_down_info_eval(req, 38, ldi);
299 break;
300 case FSF_STATUS_READ_SUB_FDISC_FAILED:
301 dev_warn(&adapter->ccw_device->dev,
302 "Local link is down "
303 "due to failed FDISC login.\n");
304 zfcp_fsf_link_down_info_eval(req, 39, ldi);
305 break;
306 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
307 dev_warn(&adapter->ccw_device->dev,
308 "Local link is down "
309 "due to firmware update on adapter.\n");
310 zfcp_fsf_link_down_info_eval(req, 40, NULL);
311 };
312}
313
314static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
315{
316 struct zfcp_adapter *adapter = req->adapter;
317 struct fsf_status_read_buffer *sr_buf = req->data;
318
319 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
320 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
321 mempool_free(sr_buf, adapter->pool.data_status_read);
322 zfcp_fsf_req_free(req);
323 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
325
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200326 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200327
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200328 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200330 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200333 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200338 zfcp_fsf_bit_error_threshold(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200341 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200344 dev_info(&adapter->ccw_device->dev,
345 "Local link was replugged.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200347 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 ZFCP_STATUS_COMMON_RUNNING,
349 ZFCP_SET);
350 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200351 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
352 ZFCP_STATUS_COMMON_ERP_FAILED,
353 102, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100355 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200356 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
357 zfcp_erp_adapter_access_changed(adapter, 135, req);
358 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200359 schedule_work(&adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200362 zfcp_erp_adapter_access_changed(adapter, 136, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200364 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200365 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200366 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200368
369 mempool_free(sr_buf, adapter->pool.data_status_read);
370 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200371
372 atomic_inc(&adapter->stat_miss);
373 schedule_work(&adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200376static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200378 switch (req->qtcb->header.fsf_status_qual.word[0]) {
379 case FSF_SQ_FCP_RSP_AVAILABLE:
380 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
381 case FSF_SQ_NO_RETRY_POSSIBLE:
382 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
383 return;
384 case FSF_SQ_COMMAND_ABORTED:
385 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
386 break;
387 case FSF_SQ_NO_RECOM:
388 dev_err(&req->adapter->ccw_device->dev,
389 "No recommendation could be given for a "
390 "problem on the adapter.\n");
391 zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
392 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200394 /* all non-return stats set FSFREQ_ERROR*/
395 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
396}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200398static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
399{
400 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
401 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200402
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200403 switch (req->qtcb->header.fsf_status) {
404 case FSF_UNKNOWN_COMMAND:
405 dev_err(&req->adapter->ccw_device->dev,
406 "Command issued by the device driver (0x%x) is "
407 "not known by the adapter.\n",
408 req->qtcb->header.fsf_command);
409 zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
410 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200413 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200418static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200420 struct zfcp_adapter *adapter = req->adapter;
421 struct fsf_qtcb *qtcb = req->qtcb;
422 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200424 zfcp_hba_dbf_event_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200426 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
427 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
428 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
429 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200432 switch (qtcb->prefix.prot_status) {
433 case FSF_PROT_GOOD:
434 case FSF_PROT_FSF_STATUS_PRESENTED:
435 return;
436 case FSF_PROT_QTCB_VERSION_ERROR:
437 dev_err(&adapter->ccw_device->dev,
438 "The QTCB version requested by zfcp (0x%x) is not "
439 "supported by the FCP adapter (lowest supported "
440 "0x%x, highest supported 0x%x).\n",
441 FSF_QTCB_CURRENT_VERSION, psq->word[0],
442 psq->word[1]);
443 zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200445 case FSF_PROT_ERROR_STATE:
446 case FSF_PROT_SEQ_NUMB_ERROR:
447 zfcp_erp_adapter_reopen(adapter, 0, 98, req);
448 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200450 case FSF_PROT_UNSUPP_QTCB_TYPE:
451 dev_err(&adapter->ccw_device->dev,
452 "Packet header type used by the device driver is "
453 "incompatible with that used on the adapter.\n");
454 zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200456 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
457 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
458 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200460 case FSF_PROT_DUPLICATE_REQUEST_ID:
461 dev_err(&adapter->ccw_device->dev,
462 "The request identifier 0x%Lx is ambiguous.\n",
463 (unsigned long long)qtcb->bottom.support.req_handle);
464 zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200466 case FSF_PROT_LINK_DOWN:
467 zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
468 /* FIXME: reopening adapter now? better wait for link up */
469 zfcp_erp_adapter_reopen(adapter, 0, 79, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200471 case FSF_PROT_REEST_QUEUE:
472 /* All ports should be marked as ready to run again */
473 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
474 ZFCP_STATUS_COMMON_RUNNING,
475 ZFCP_SET);
476 zfcp_erp_adapter_reopen(adapter,
477 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
478 ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200481 dev_err(&adapter->ccw_device->dev,
482 "Transfer protocol status information"
483 "provided by the adapter (0x%x) "
484 "is not compatible with the device driver.\n",
485 qtcb->prefix.prot_status);
486 zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200488 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
491/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200492 * zfcp_fsf_req_complete - process completion of a FSF request
493 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200495 * When a request has been completed either from the FCP adapter,
496 * or it has been dismissed due to a queue shutdown, this function
497 * is called to process the completion status and trigger further
498 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200500void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
501{
502 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
503 zfcp_fsf_status_read_handler(req);
504 return;
505 }
506
507 del_timer(&req->timer);
508 zfcp_fsf_protstatus_eval(req);
509 zfcp_fsf_fsfstatus_eval(req);
510 req->handler(req);
511
512 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200513 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200514 req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
515
516 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
517 zfcp_fsf_req_free(req);
518 else
519 /* notify initiator waiting for the requests completion */
520 /*
521 * FIXME: Race! We must not access fsf_req here as it might have been
522 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
523 * flag. It's an improbable case. But, we have the same paranoia for
524 * the cleanup flag already.
525 * Might better be handled using complete()?
526 * (setting the flag and doing wakeup ought to be atomic
527 * with regard to checking the flag as long as waitqueue is
528 * part of the to be released structure)
529 */
530 wake_up(&req->completion_wq);
531}
532
533static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
535 struct fsf_qtcb_bottom_config *bottom;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200536 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200537 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200539 bottom = &req->qtcb->bottom.config;
540
541 if (req->data)
542 memcpy(req->data, bottom, sizeof(*bottom));
543
544 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
545 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
546 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
547 fc_host_speed(shost) = bottom->fc_link_speed;
548 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
549
550 adapter->hydra_version = bottom->adapter_type;
551 adapter->timer_ticks = bottom->timer_interval;
552
553 if (fc_host_permanent_port_name(shost) == -1)
554 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
555
556 switch (bottom->fc_topology) {
557 case FSF_TOPO_P2P:
558 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
559 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
560 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
561 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
562 if (req->erp_action)
563 dev_info(&adapter->ccw_device->dev,
564 "Point-to-Point fibrechannel "
565 "configuration detected.\n");
566 break;
567 case FSF_TOPO_FABRIC:
568 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
569 if (req->erp_action)
570 dev_info(&adapter->ccw_device->dev,
571 "Switched fabric fibrechannel "
572 "network detected.\n");
573 break;
574 case FSF_TOPO_AL:
575 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
576 dev_err(&adapter->ccw_device->dev,
577 "Unsupported arbitrated loop fibrechannel "
578 "topology detected, shutting down "
579 "adapter.\n");
580 zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
581 return -EIO;
582 default:
583 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
584 dev_err(&adapter->ccw_device->dev,
585 "The fibrechannel topology reported by the"
586 " adapter is not known by the zfcp driver,"
587 " shutting down adapter.\n");
588 zfcp_erp_adapter_shutdown(adapter, 0, 128, req);
589 return -EIO;
590 }
591
592 return 0;
593}
594
595static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
596{
597 struct zfcp_adapter *adapter = req->adapter;
598 struct fsf_qtcb *qtcb = req->qtcb;
599 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
600 struct Scsi_Host *shost = adapter->scsi_host;
601
602 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
603 return;
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200606 adapter->adapter_features = bottom->adapter_features;
607 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500608 adapter->peer_wwpn = 0;
609 adapter->peer_wwnn = 0;
610 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200612 switch (qtcb->header.fsf_status) {
613 case FSF_GOOD:
614 if (zfcp_fsf_exchange_config_evaluate(req))
615 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200616
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200617 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
618 dev_err(&adapter->ccw_device->dev,
619 "Maximum QTCB size (%d bytes) allowed by "
620 "the adapter is lower than the minimum "
621 "required by the driver (%ld bytes).\n",
622 bottom->max_qtcb_size,
623 sizeof(struct fsf_qtcb));
624 zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
625 return;
626 }
627 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
628 &adapter->status);
629 break;
630 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200631 fc_host_node_name(shost) = 0;
632 fc_host_port_name(shost) = 0;
633 fc_host_port_id(shost) = 0;
634 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100635 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637
638 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
639 &adapter->status);
640
641 zfcp_fsf_link_down_info_eval(req, 42,
642 &qtcb->header.fsf_status_qual.link_down_info);
643 break;
644 default:
645 zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
646 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200649 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200651 memcpy(fc_host_serial_number(shost), bottom->serial_number,
652 min(FC_SERIAL_NUMBER_SIZE, 17));
653 EBCASC(fc_host_serial_number(shost),
654 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 }
656
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200657 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200658 dev_err(&adapter->ccw_device->dev,
659 "The adapter only supports newer control block "
660 "versions, try updated device driver.\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200661 zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
662 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200664 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200665 dev_err(&adapter->ccw_device->dev,
666 "The adapter only supports older control block "
667 "versions, consider a microcode upgrade.\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200668 zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670}
671
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200672static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200674 struct zfcp_adapter *adapter = req->adapter;
675 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
676 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200678 if (req->data)
679 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100680
681 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
682 fc_host_permanent_port_name(shost) = bottom->wwpn;
683 else
684 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
685 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
686 fc_host_supported_speeds(shost) = bottom->supported_speed;
687}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200689static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200691 struct zfcp_adapter *adapter = req->adapter;
692 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100693
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200694 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 return;
696
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200697 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200698 case FSF_GOOD:
699 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200700 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200701 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200702 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200703 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200704 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200705 zfcp_fsf_link_down_info_eval(req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200706 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200707 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
709}
710
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200711static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
712{
Christof Schmittd4538812008-08-21 13:43:32 +0200713 spin_lock_bh(&queue->lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200714 if (atomic_read(&queue->count))
715 return 1;
Christof Schmittd4538812008-08-21 13:43:32 +0200716 spin_unlock_bh(&queue->lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200717 return 0;
718}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200720static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
721{
722 unsigned int count = atomic_read(&adapter->req_q.count);
723 if (!count)
724 atomic_inc(&adapter->qdio_outb_full);
725 return count > 0;
726}
727
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200728static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
729{
730 long ret;
731 struct zfcp_qdio_queue *req_q = &adapter->req_q;
732
Christof Schmittd4538812008-08-21 13:43:32 +0200733 spin_unlock_bh(&req_q->lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200734 ret = wait_event_interruptible_timeout(adapter->request_wq,
735 zfcp_fsf_sbal_check(req_q), 5 * HZ);
736 if (ret > 0)
737 return 0;
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200738 if (!ret)
739 atomic_inc(&adapter->qdio_outb_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200740
Christof Schmittd4538812008-08-21 13:43:32 +0200741 spin_lock_bh(&req_q->lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200742 return -EIO;
743}
744
745static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
746{
747 struct zfcp_fsf_req *req;
748 req = mempool_alloc(pool, GFP_ATOMIC);
749 if (!req)
750 return NULL;
751 memset(req, 0, sizeof(*req));
752 return req;
753}
754
755static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
756{
757 struct zfcp_fsf_req_qtcb *qtcb;
758
759 if (likely(pool))
760 qtcb = mempool_alloc(pool, GFP_ATOMIC);
761 else
762 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
763 GFP_ATOMIC);
764 if (unlikely(!qtcb))
765 return NULL;
766
767 memset(qtcb, 0, sizeof(*qtcb));
768 qtcb->fsf_req.qtcb = &qtcb->qtcb;
769 qtcb->fsf_req.pool = pool;
770
771 return &qtcb->fsf_req;
772}
773
774static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
775 u32 fsf_cmd, int req_flags,
776 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777{
778 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200780 struct zfcp_fsf_req *req;
781 struct zfcp_qdio_queue *req_q = &adapter->req_q;
782
783 if (req_flags & ZFCP_REQ_NO_QTCB)
784 req = zfcp_fsf_alloc_noqtcb(pool);
785 else
786 req = zfcp_fsf_alloc_qtcb(pool);
787
788 if (unlikely(!req))
789 return ERR_PTR(-EIO);
790
791 if (adapter->req_no == 0)
792 adapter->req_no++;
793
794 INIT_LIST_HEAD(&req->list);
795 init_timer(&req->timer);
796 init_waitqueue_head(&req->completion_wq);
797
798 req->adapter = adapter;
799 req->fsf_command = fsf_cmd;
800 req->req_id = adapter->req_no++;
801 req->sbal_number = 1;
802 req->sbal_first = req_q->first;
803 req->sbal_last = req_q->first;
804 req->sbale_curr = 1;
805
806 sbale = zfcp_qdio_sbale_req(req);
807 sbale[0].addr = (void *) req->req_id;
808 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
809
810 if (likely(req->qtcb)) {
811 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
812 req->qtcb->prefix.req_id = req->req_id;
813 req->qtcb->prefix.ulp_info = 26;
814 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
815 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
816 req->qtcb->header.req_handle = req->req_id;
817 req->qtcb->header.fsf_command = req->fsf_command;
818 req->seq_no = adapter->fsf_req_seq_no;
819 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
820 sbale[1].addr = (void *) req->qtcb;
821 sbale[1].length = sizeof(struct fsf_qtcb);
822 }
823
824 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
825 zfcp_fsf_req_free(req);
826 return ERR_PTR(-EIO);
827 }
828
829 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
830 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
831
832 return req;
833}
834
835static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
836{
837 struct zfcp_adapter *adapter = req->adapter;
838 struct zfcp_qdio_queue *req_q = &adapter->req_q;
839 int idx;
840
841 /* put allocated FSF request into hash table */
842 spin_lock(&adapter->req_list_lock);
843 idx = zfcp_reqlist_hash(req->req_id);
844 list_add_tail(&req->list, &adapter->req_list[idx]);
845 spin_unlock(&adapter->req_list_lock);
846
847 req->issued = get_clock();
848 if (zfcp_qdio_send(req)) {
849 /* Queues are down..... */
850 del_timer(&req->timer);
851 spin_lock(&adapter->req_list_lock);
852 zfcp_reqlist_remove(adapter, req);
853 spin_unlock(&adapter->req_list_lock);
854 /* undo changes in request queue made for this request */
855 atomic_add(req->sbal_number, &req_q->count);
856 req_q->first -= req->sbal_number;
857 req_q->first += QDIO_MAX_BUFFERS_PER_Q;
858 req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
859 zfcp_erp_adapter_reopen(adapter, 0, 116, req);
860 return -EIO;
861 }
862
863 /* Don't increase for unsolicited status */
864 if (req->qtcb)
865 adapter->fsf_req_seq_no++;
866
867 return 0;
868}
869
870/**
871 * zfcp_fsf_status_read - send status read request
872 * @adapter: pointer to struct zfcp_adapter
873 * @req_flags: request flags
874 * Returns: 0 on success, ERROR otherwise
875 */
876int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
877{
878 struct zfcp_fsf_req *req;
879 struct fsf_status_read_buffer *sr_buf;
880 volatile struct qdio_buffer_element *sbale;
881 int retval = -EIO;
882
Christof Schmittd4538812008-08-21 13:43:32 +0200883 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200887 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
888 ZFCP_REQ_NO_QTCB,
889 adapter->pool.fsf_req_status_read);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200890 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200891 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 goto out;
893 }
894
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200895 sbale = zfcp_qdio_sbale_req(req);
896 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
897 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
898 req->sbale_curr = 2;
899
900 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
901 if (!sr_buf) {
902 retval = -ENOMEM;
903 goto failed_buf;
904 }
905 memset(sr_buf, 0, sizeof(*sr_buf));
906 req->data = sr_buf;
907 sbale = zfcp_qdio_sbale_curr(req);
908 sbale->addr = (void *) sr_buf;
909 sbale->length = sizeof(*sr_buf);
910
911 retval = zfcp_fsf_req_send(req);
912 if (retval)
913 goto failed_req_send;
914
915 goto out;
916
917failed_req_send:
918 mempool_free(sr_buf, adapter->pool.data_status_read);
919failed_buf:
920 zfcp_fsf_req_free(req);
921 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
922out:
Christof Schmittd4538812008-08-21 13:43:32 +0200923 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 return retval;
925}
926
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200927static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200929 struct zfcp_unit *unit = req->data;
930 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200932 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
933 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200935 switch (req->qtcb->header.fsf_status) {
936 case FSF_PORT_HANDLE_NOT_VALID:
937 if (fsq->word[0] == fsq->word[1]) {
938 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
939 req);
940 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200943 case FSF_LUN_HANDLE_NOT_VALID:
944 if (fsq->word[0] == fsq->word[1]) {
945 zfcp_erp_port_reopen(unit->port, 0, 105, req);
946 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200949 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
950 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200952 case FSF_PORT_BOXED:
953 zfcp_erp_port_boxed(unit->port, 47, req);
954 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
955 ZFCP_STATUS_FSFREQ_RETRY;
956 break;
957 case FSF_LUN_BOXED:
958 zfcp_erp_unit_boxed(unit, 48, req);
959 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
960 ZFCP_STATUS_FSFREQ_RETRY;
961 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200963 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200965 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200967 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 break;
969 }
970 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200972 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
973 break;
974 }
975}
976
977/**
978 * zfcp_fsf_abort_fcp_command - abort running SCSI command
979 * @old_req_id: unsigned long
980 * @adapter: pointer to struct zfcp_adapter
981 * @unit: pointer to struct zfcp_unit
982 * @req_flags: integer specifying the request flags
983 * Returns: pointer to struct zfcp_fsf_req
984 *
985 * FIXME(design): should be watched by a timeout !!!
986 */
987
988struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
989 struct zfcp_adapter *adapter,
990 struct zfcp_unit *unit,
991 int req_flags)
992{
993 volatile struct qdio_buffer_element *sbale;
994 struct zfcp_fsf_req *req = NULL;
995
996 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200997 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200998 goto out;
999 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1000 req_flags, adapter->pool.fsf_req_abort);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001001 if (IS_ERR(req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001002 goto out;
1003
1004 if (unlikely(!(atomic_read(&unit->status) &
1005 ZFCP_STATUS_COMMON_UNBLOCKED)))
1006 goto out_error_free;
1007
1008 sbale = zfcp_qdio_sbale_req(req);
1009 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1010 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1011
1012 req->data = unit;
1013 req->handler = zfcp_fsf_abort_fcp_command_handler;
1014 req->qtcb->header.lun_handle = unit->handle;
1015 req->qtcb->header.port_handle = unit->port->handle;
1016 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1017
1018 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
1019 if (!zfcp_fsf_req_send(req))
1020 goto out;
1021
1022out_error_free:
1023 zfcp_fsf_req_free(req);
1024 req = NULL;
1025out:
1026 spin_unlock(&adapter->req_q.lock);
1027 return req;
1028}
1029
1030static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
1031{
1032 struct zfcp_adapter *adapter = req->adapter;
1033 struct zfcp_send_ct *send_ct = req->data;
1034 struct zfcp_port *port = send_ct->port;
1035 struct fsf_qtcb_header *header = &req->qtcb->header;
1036
1037 send_ct->status = -EINVAL;
1038
1039 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1040 goto skip_fsfstatus;
1041
1042 switch (header->fsf_status) {
1043 case FSF_GOOD:
1044 zfcp_san_dbf_event_ct_response(req);
1045 send_ct->status = 0;
1046 break;
1047 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1048 zfcp_fsf_class_not_supp(req);
1049 break;
1050 case FSF_ADAPTER_STATUS_AVAILABLE:
1051 switch (header->fsf_status_qual.word[0]){
1052 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1053 zfcp_test_link(port);
1054 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1055 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1056 break;
1057 }
1058 break;
1059 case FSF_ACCESS_DENIED:
1060 zfcp_fsf_access_denied_port(req, port);
1061 break;
1062 case FSF_PORT_BOXED:
1063 zfcp_erp_port_boxed(port, 49, req);
1064 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1065 ZFCP_STATUS_FSFREQ_RETRY;
1066 break;
1067 case FSF_PORT_HANDLE_NOT_VALID:
1068 zfcp_erp_adapter_reopen(adapter, 0, 106, req);
1069 case FSF_GENERIC_COMMAND_REJECTED:
1070 case FSF_PAYLOAD_SIZE_MISMATCH:
1071 case FSF_REQUEST_SIZE_TOO_LARGE:
1072 case FSF_RESPONSE_SIZE_TOO_LARGE:
1073 case FSF_SBAL_MISMATCH:
1074 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1075 break;
1076 }
1077
1078skip_fsfstatus:
1079 if (send_ct->handler)
1080 send_ct->handler(send_ct->handler_data);
1081}
1082
1083static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
1084 struct scatterlist *sg_req,
1085 struct scatterlist *sg_resp, int max_sbals)
1086{
1087 int bytes;
1088
1089 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1090 sg_req, max_sbals);
1091 if (bytes <= 0)
1092 return -ENOMEM;
1093 req->qtcb->bottom.support.req_buf_length = bytes;
1094 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1095
1096 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1097 sg_resp, max_sbals);
1098 if (bytes <= 0)
1099 return -ENOMEM;
1100 req->qtcb->bottom.support.resp_buf_length = bytes;
1101
1102 return 0;
1103}
1104
1105/**
1106 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1107 * @ct: pointer to struct zfcp_send_ct with data for request
1108 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1109 * @erp_action: if non-null the Generic Service request sent within ERP
1110 */
1111int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1112 struct zfcp_erp_action *erp_action)
1113{
1114 struct zfcp_port *port = ct->port;
1115 struct zfcp_adapter *adapter = port->adapter;
1116 struct zfcp_fsf_req *req;
1117 int ret = -EIO;
1118
Christof Schmittd4538812008-08-21 13:43:32 +02001119 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001120 if (zfcp_fsf_req_sbal_get(adapter))
1121 goto out;
1122
1123 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1124 ZFCP_REQ_AUTO_CLEANUP, pool);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001125 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001126 ret = PTR_ERR(req);
1127 goto out;
1128 }
1129
1130 ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
1131 FSF_MAX_SBALS_PER_REQ);
1132 if (ret)
1133 goto failed_send;
1134
1135 req->handler = zfcp_fsf_send_ct_handler;
1136 req->qtcb->header.port_handle = port->handle;
1137 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1138 req->qtcb->bottom.support.timeout = ct->timeout;
1139 req->data = ct;
1140
1141 zfcp_san_dbf_event_ct_request(req);
1142
1143 if (erp_action) {
1144 erp_action->fsf_req = req;
1145 req->erp_action = erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +02001146 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001147 } else
1148 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1149
1150 ret = zfcp_fsf_req_send(req);
1151 if (ret)
1152 goto failed_send;
1153
1154 goto out;
1155
1156failed_send:
1157 zfcp_fsf_req_free(req);
1158 if (erp_action)
1159 erp_action->fsf_req = NULL;
1160out:
Christof Schmittd4538812008-08-21 13:43:32 +02001161 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001162 return ret;
1163}
1164
1165static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1166{
1167 struct zfcp_send_els *send_els = req->data;
1168 struct zfcp_port *port = send_els->port;
1169 struct fsf_qtcb_header *header = &req->qtcb->header;
1170
1171 send_els->status = -EINVAL;
1172
1173 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1174 goto skip_fsfstatus;
1175
1176 switch (header->fsf_status) {
1177 case FSF_GOOD:
1178 zfcp_san_dbf_event_els_response(req);
1179 send_els->status = 0;
1180 break;
1181 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1182 zfcp_fsf_class_not_supp(req);
1183 break;
1184 case FSF_ADAPTER_STATUS_AVAILABLE:
1185 switch (header->fsf_status_qual.word[0]){
1186 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1187 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1188 zfcp_test_link(port);
1189 /*fall through */
1190 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1191 case FSF_SQ_RETRY_IF_POSSIBLE:
1192 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1193 break;
1194 }
1195 break;
1196 case FSF_ELS_COMMAND_REJECTED:
1197 case FSF_PAYLOAD_SIZE_MISMATCH:
1198 case FSF_REQUEST_SIZE_TOO_LARGE:
1199 case FSF_RESPONSE_SIZE_TOO_LARGE:
1200 break;
1201 case FSF_ACCESS_DENIED:
1202 zfcp_fsf_access_denied_port(req, port);
1203 break;
1204 case FSF_SBAL_MISMATCH:
1205 /* should never occure, avoided in zfcp_fsf_send_els */
1206 /* fall through */
1207 default:
1208 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1209 break;
1210 }
1211skip_fsfstatus:
1212 if (send_els->handler)
1213 send_els->handler(send_els->handler_data);
1214}
1215
1216/**
1217 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1218 * @els: pointer to struct zfcp_send_els with data for the command
1219 */
1220int zfcp_fsf_send_els(struct zfcp_send_els *els)
1221{
1222 struct zfcp_fsf_req *req;
1223 struct zfcp_adapter *adapter = els->adapter;
1224 struct fsf_qtcb_bottom_support *bottom;
1225 int ret = -EIO;
1226
1227 if (unlikely(!(atomic_read(&els->port->status) &
1228 ZFCP_STATUS_COMMON_UNBLOCKED)))
1229 return -EBUSY;
1230
1231 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001232 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001233 goto out;
1234 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1235 ZFCP_REQ_AUTO_CLEANUP, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001236 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001237 ret = PTR_ERR(req);
1238 goto out;
1239 }
1240
1241 ret = zfcp_fsf_setup_sbals(req, els->req, els->resp,
1242 FSF_MAX_SBALS_PER_ELS_REQ);
1243 if (ret)
1244 goto failed_send;
1245
1246 bottom = &req->qtcb->bottom.support;
1247 req->handler = zfcp_fsf_send_els_handler;
1248 bottom->d_id = els->d_id;
1249 bottom->service_class = FSF_CLASS_3;
1250 bottom->timeout = 2 * R_A_TOV;
1251 req->data = els;
1252
1253 zfcp_san_dbf_event_els_request(req);
1254
1255 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1256 ret = zfcp_fsf_req_send(req);
1257 if (ret)
1258 goto failed_send;
1259
1260 goto out;
1261
1262failed_send:
1263 zfcp_fsf_req_free(req);
1264out:
1265 spin_unlock(&adapter->req_q.lock);
1266 return ret;
1267}
1268
1269int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1270{
1271 volatile struct qdio_buffer_element *sbale;
1272 struct zfcp_fsf_req *req;
1273 struct zfcp_adapter *adapter = erp_action->adapter;
1274 int retval = -EIO;
1275
Christof Schmittd4538812008-08-21 13:43:32 +02001276 spin_lock_bh(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001277 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001278 goto out;
1279 req = zfcp_fsf_req_create(adapter,
1280 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1281 ZFCP_REQ_AUTO_CLEANUP,
1282 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001283 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001284 retval = PTR_ERR(req);
1285 goto out;
1286 }
1287
1288 sbale = zfcp_qdio_sbale_req(req);
1289 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1290 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1291
1292 req->qtcb->bottom.config.feature_selection =
1293 FSF_FEATURE_CFDC |
1294 FSF_FEATURE_LUN_SHARING |
1295 FSF_FEATURE_NOTIFICATION_LOST |
1296 FSF_FEATURE_UPDATE_ALERT;
1297 req->erp_action = erp_action;
1298 req->handler = zfcp_fsf_exchange_config_data_handler;
1299 erp_action->fsf_req = req;
1300
Christof Schmitt287ac012008-07-02 10:56:40 +02001301 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001302 retval = zfcp_fsf_req_send(req);
1303 if (retval) {
1304 zfcp_fsf_req_free(req);
1305 erp_action->fsf_req = NULL;
1306 }
1307out:
Christof Schmittd4538812008-08-21 13:43:32 +02001308 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001309 return retval;
1310}
1311
1312int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1313 struct fsf_qtcb_bottom_config *data)
1314{
1315 volatile struct qdio_buffer_element *sbale;
1316 struct zfcp_fsf_req *req = NULL;
1317 int retval = -EIO;
1318
Christof Schmittd4538812008-08-21 13:43:32 +02001319 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001320 if (zfcp_fsf_req_sbal_get(adapter))
1321 goto out;
1322
1323 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1324 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001325 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001326 retval = PTR_ERR(req);
1327 goto out;
1328 }
1329
1330 sbale = zfcp_qdio_sbale_req(req);
1331 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1332 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1333 req->handler = zfcp_fsf_exchange_config_data_handler;
1334
1335 req->qtcb->bottom.config.feature_selection =
1336 FSF_FEATURE_CFDC |
1337 FSF_FEATURE_LUN_SHARING |
1338 FSF_FEATURE_NOTIFICATION_LOST |
1339 FSF_FEATURE_UPDATE_ALERT;
1340
1341 if (data)
1342 req->data = data;
1343
1344 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1345 retval = zfcp_fsf_req_send(req);
1346out:
Christof Schmittd4538812008-08-21 13:43:32 +02001347 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001348 if (!retval)
1349 wait_event(req->completion_wq,
1350 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1351
1352 zfcp_fsf_req_free(req);
1353
1354 return retval;
1355}
1356
1357/**
1358 * zfcp_fsf_exchange_port_data - request information about local port
1359 * @erp_action: ERP action for the adapter for which port data is requested
1360 * Returns: 0 on success, error otherwise
1361 */
1362int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1363{
1364 volatile struct qdio_buffer_element *sbale;
1365 struct zfcp_fsf_req *req;
1366 struct zfcp_adapter *adapter = erp_action->adapter;
1367 int retval = -EIO;
1368
1369 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1370 return -EOPNOTSUPP;
1371
Christof Schmittd4538812008-08-21 13:43:32 +02001372 spin_lock_bh(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001373 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001374 goto out;
1375 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1376 ZFCP_REQ_AUTO_CLEANUP,
1377 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001378 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001379 retval = PTR_ERR(req);
1380 goto out;
1381 }
1382
1383 sbale = zfcp_qdio_sbale_req(req);
1384 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1385 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1386
1387 req->handler = zfcp_fsf_exchange_port_data_handler;
1388 req->erp_action = erp_action;
1389 erp_action->fsf_req = req;
1390
Christof Schmitt287ac012008-07-02 10:56:40 +02001391 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001392 retval = zfcp_fsf_req_send(req);
1393 if (retval) {
1394 zfcp_fsf_req_free(req);
1395 erp_action->fsf_req = NULL;
1396 }
1397out:
Christof Schmittd4538812008-08-21 13:43:32 +02001398 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001399 return retval;
1400}
1401
1402/**
1403 * zfcp_fsf_exchange_port_data_sync - request information about local port
1404 * @adapter: pointer to struct zfcp_adapter
1405 * @data: pointer to struct fsf_qtcb_bottom_port
1406 * Returns: 0 on success, error otherwise
1407 */
1408int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1409 struct fsf_qtcb_bottom_port *data)
1410{
1411 volatile struct qdio_buffer_element *sbale;
1412 struct zfcp_fsf_req *req = NULL;
1413 int retval = -EIO;
1414
1415 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1416 return -EOPNOTSUPP;
1417
Christof Schmittd4538812008-08-21 13:43:32 +02001418 spin_lock_bh(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02001419 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001420 goto out;
1421
1422 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1423 NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001424 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001425 retval = PTR_ERR(req);
1426 goto out;
1427 }
1428
1429 if (data)
1430 req->data = data;
1431
1432 sbale = zfcp_qdio_sbale_req(req);
1433 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1434 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1435
1436 req->handler = zfcp_fsf_exchange_port_data_handler;
1437 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1438 retval = zfcp_fsf_req_send(req);
1439out:
Christof Schmittd4538812008-08-21 13:43:32 +02001440 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001441 if (!retval)
1442 wait_event(req->completion_wq,
1443 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1444 zfcp_fsf_req_free(req);
1445
1446 return retval;
1447}
1448
1449static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1450{
1451 struct zfcp_port *port = req->data;
1452 struct fsf_qtcb_header *header = &req->qtcb->header;
1453 struct fsf_plogi *plogi;
1454
1455 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1456 goto skip_fsfstatus;
1457
1458 switch (header->fsf_status) {
1459 case FSF_PORT_ALREADY_OPEN:
1460 break;
1461 case FSF_ACCESS_DENIED:
1462 zfcp_fsf_access_denied_port(req, port);
1463 break;
1464 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1465 dev_warn(&req->adapter->ccw_device->dev,
1466 "The adapter is out of resources. The remote port "
1467 "0x%016Lx could not be opened, disabling it.\n",
1468 port->wwpn);
1469 zfcp_erp_port_failed(port, 31, req);
1470 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1471 break;
1472 case FSF_ADAPTER_STATUS_AVAILABLE:
1473 switch (header->fsf_status_qual.word[0]) {
1474 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1475 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1476 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1477 break;
1478 case FSF_SQ_NO_RETRY_POSSIBLE:
1479 dev_warn(&req->adapter->ccw_device->dev,
1480 "The remote port 0x%016Lx could not be "
1481 "opened. Disabling it.\n", port->wwpn);
1482 zfcp_erp_port_failed(port, 32, req);
1483 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1484 break;
1485 }
1486 break;
1487 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1490 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001491 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1492 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1493 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 /* check whether D_ID has changed during open */
1495 /*
1496 * FIXME: This check is not airtight, as the FCP channel does
1497 * not monitor closures of target port connections caused on
1498 * the remote side. Thus, they might miss out on invalidating
1499 * locally cached WWPNs (and other N_Port parameters) of gone
1500 * target ports. So, our heroic attempt to make things safe
1501 * could be undermined by 'open port' response data tagged with
1502 * obsolete WWPNs. Another reason to monitor potential
1503 * connection closures ourself at least (by interpreting
1504 * incoming ELS' and unsolicited status). It just crosses my
1505 * mind that one should be able to cross-check by means of
1506 * another GID_PN straight after a port has been opened.
1507 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1508 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001509 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN)
1510 break;
1511
1512 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1513 if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
1514 if (plogi->serv_param.wwpn != port->wwpn)
1515 atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
1516 &port->status);
1517 else {
1518 port->wwnn = plogi->serv_param.wwnn;
1519 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521 }
1522 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 break;
1526 }
1527
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001528skip_fsfstatus:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001532/**
1533 * zfcp_fsf_open_port - create and send open port request
1534 * @erp_action: pointer to struct zfcp_erp_action
1535 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001537int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538{
1539 volatile struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001540 struct zfcp_adapter *adapter = erp_action->adapter;
1541 struct zfcp_fsf_req *req;
1542 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Christof Schmittd4538812008-08-21 13:43:32 +02001544 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001545 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001548 req = zfcp_fsf_req_create(adapter,
1549 FSF_QTCB_OPEN_PORT_WITH_DID,
1550 ZFCP_REQ_AUTO_CLEANUP,
1551 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001552 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001553 retval = PTR_ERR(req);
1554 goto out;
1555 }
1556
1557 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1559 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1560
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001561 req->handler = zfcp_fsf_open_port_handler;
1562 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
1563 req->data = erp_action->port;
1564 req->erp_action = erp_action;
1565 erp_action->fsf_req = req;
1566 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Christof Schmitt287ac012008-07-02 10:56:40 +02001568 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001569 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001571 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001574out:
Christof Schmittd4538812008-08-21 13:43:32 +02001575 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 return retval;
1577}
1578
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001579static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001581 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001583 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001586 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001588 zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
1589 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001594 zfcp_erp_modify_port_status(port, 33, req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 ZFCP_STATUS_COMMON_OPEN,
1596 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 }
1599
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001600skip_fsfstatus:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
1603
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001604/**
1605 * zfcp_fsf_close_port - create and send close port request
1606 * @erp_action: pointer to struct zfcp_erp_action
1607 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001609int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 volatile struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001612 struct zfcp_adapter *adapter = erp_action->adapter;
1613 struct zfcp_fsf_req *req;
1614 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Christof Schmittd4538812008-08-21 13:43:32 +02001616 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001617 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001620 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1621 ZFCP_REQ_AUTO_CLEANUP,
1622 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001623 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001624 retval = PTR_ERR(req);
1625 goto out;
1626 }
1627
1628 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1630 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1631
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001632 req->handler = zfcp_fsf_close_port_handler;
1633 req->data = erp_action->port;
1634 req->erp_action = erp_action;
1635 req->qtcb->header.port_handle = erp_action->port->handle;
1636 erp_action->fsf_req = req;
1637 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Christof Schmitt287ac012008-07-02 10:56:40 +02001639 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001640 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001642 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001645out:
Christof Schmittd4538812008-08-21 13:43:32 +02001646 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 return retval;
1648}
1649
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001650static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001652 struct zfcp_port *port = req->data;
1653 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001656 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001661 zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
1662 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001665 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 case FSF_PORT_BOXED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001668 zfcp_erp_port_boxed(port, 50, req);
1669 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1670 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01001671 /* can't use generic zfcp_erp_modify_port_status because
1672 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1673 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1674 list_for_each_entry(unit, &port->unit_list_head, list)
1675 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1676 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 switch (header->fsf_status_qual.word[0]) {
1680 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001681 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001683 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 }
1686 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 /* can't use generic zfcp_erp_modify_port_status because
1689 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1690 */
1691 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1692 list_for_each_entry(unit, &port->unit_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001693 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1694 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001697skip_fsfstatus:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001701/**
1702 * zfcp_fsf_close_physical_port - close physical port
1703 * @erp_action: pointer to struct zfcp_erp_action
1704 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001706int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707{
1708 volatile struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001709 struct zfcp_adapter *adapter = erp_action->adapter;
1710 struct zfcp_fsf_req *req;
1711 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Christof Schmittd4538812008-08-21 13:43:32 +02001713 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001714 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001717 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1718 ZFCP_REQ_AUTO_CLEANUP,
1719 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001720 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001721 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 goto out;
1723 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001724
1725 sbale = zfcp_qdio_sbale_req(req);
1726 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1727 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1728
1729 req->data = erp_action->port;
1730 req->qtcb->header.port_handle = erp_action->port->handle;
1731 req->erp_action = erp_action;
1732 req->handler = zfcp_fsf_close_physical_port_handler;
1733 erp_action->fsf_req = req;
1734 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
1735 &erp_action->port->status);
1736
Christof Schmitt287ac012008-07-02 10:56:40 +02001737 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001738 retval = zfcp_fsf_req_send(req);
1739 if (retval) {
1740 zfcp_fsf_req_free(req);
1741 erp_action->fsf_req = NULL;
1742 }
1743out:
Christof Schmittd4538812008-08-21 13:43:32 +02001744 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 return retval;
1746}
1747
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001748static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001750 struct zfcp_adapter *adapter = req->adapter;
1751 struct zfcp_unit *unit = req->data;
1752 struct fsf_qtcb_header *header = &req->qtcb->header;
1753 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1754 struct fsf_queue_designator *queue_designator =
1755 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001756 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001758 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001762 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 ZFCP_STATUS_UNIT_SHARED |
1764 ZFCP_STATUS_UNIT_READONLY,
1765 &unit->status);
1766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 switch (header->fsf_status) {
1768
1769 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001770 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
1771 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001775 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001777 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 case FSF_PORT_BOXED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001780 zfcp_erp_port_boxed(unit->port, 51, req);
1781 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1782 ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001785 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001786 dev_warn(&adapter->ccw_device->dev,
1787 "FCP-LUN 0x%Lx at the remote port "
1788 "with WWPN 0x%Lx "
1789 "connected to the adapter "
1790 "is already in use in LPAR%d, CSS%d.\n",
1791 unit->fcp_lun,
1792 unit->port->wwpn,
1793 queue_designator->hla,
1794 queue_designator->cssid);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001795 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001796 zfcp_act_eval_err(adapter,
1797 header->fsf_status_qual.word[2]);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001798 zfcp_erp_unit_access_denied(unit, 60, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1800 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001801 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001804 dev_warn(&adapter->ccw_device->dev,
Christof Schmitt553448f2008-06-10 18:20:58 +02001805 "The adapter ran out of resources. There is no "
1806 "handle available for unit 0x%016Lx on port 0x%016Lx.",
1807 unit->fcp_lun, unit->port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001808 zfcp_erp_unit_failed(unit, 34, req);
1809 /* fall through */
1810 case FSF_INVALID_COMMAND_OPTION:
1811 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 switch (header->fsf_status_qual.word[0]) {
1815 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001816 zfcp_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001817 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001819 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 }
1822 break;
1823
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001827
1828 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1829 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1830 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
1831 exclusive = (bottom->lun_access_info &
1832 FSF_UNIT_ACCESS_EXCLUSIVE);
1833 readwrite = (bottom->lun_access_info &
1834 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 if (!exclusive)
1837 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1838 &unit->status);
1839
1840 if (!readwrite) {
1841 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1842 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001843 dev_info(&adapter->ccw_device->dev,
Christof Schmitt553448f2008-06-10 18:20:58 +02001844 "Read-only access for unit 0x%016Lx "
1845 "on port 0x%016Lx.\n",
1846 unit->fcp_lun, unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 }
1848
1849 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001850 dev_err(&adapter->ccw_device->dev,
Christof Schmitt553448f2008-06-10 18:20:58 +02001851 "Exclusive access of read-only unit "
1852 "0x%016Lx on port 0x%016Lx not "
1853 "supported, disabling unit.\n",
1854 unit->fcp_lun, unit->port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001855 zfcp_erp_unit_failed(unit, 35, req);
1856 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1857 zfcp_erp_unit_shutdown(unit, 0, 80, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001859 dev_err(&adapter->ccw_device->dev,
Christof Schmitt553448f2008-06-10 18:20:58 +02001860 "Shared access of read-write unit "
1861 "0x%016Lx on port 0x%016Lx not "
1862 "supported, disabling unit.\n",
1863 unit->fcp_lun, unit->port->wwpn);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001864 zfcp_erp_unit_failed(unit, 36, req);
1865 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1866 zfcp_erp_unit_shutdown(unit, 0, 81, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 }
1868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 }
1871
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001872skip_fsfstatus:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874}
1875
1876/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001877 * zfcp_fsf_open_unit - open unit
1878 * @erp_action: pointer to struct zfcp_erp_action
1879 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001881int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001883 volatile struct qdio_buffer_element *sbale;
1884 struct zfcp_adapter *adapter = erp_action->adapter;
1885 struct zfcp_fsf_req *req;
1886 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Christof Schmittd4538812008-08-21 13:43:32 +02001888 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001889 if (zfcp_fsf_req_sbal_get(adapter))
1890 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001892 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1893 ZFCP_REQ_AUTO_CLEANUP,
1894 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001895 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001896 retval = PTR_ERR(req);
1897 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001898 }
1899
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001900 sbale = zfcp_qdio_sbale_req(req);
1901 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1902 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001904 req->qtcb->header.port_handle = erp_action->port->handle;
1905 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1906 req->handler = zfcp_fsf_open_unit_handler;
1907 req->data = erp_action->unit;
1908 req->erp_action = erp_action;
1909 erp_action->fsf_req = req;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001910
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001911 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1912 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001914 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Christof Schmitt287ac012008-07-02 10:56:40 +02001916 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001917 retval = zfcp_fsf_req_send(req);
1918 if (retval) {
1919 zfcp_fsf_req_free(req);
1920 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001922out:
Christof Schmittd4538812008-08-21 13:43:32 +02001923 spin_unlock_bh(&adapter->req_q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 return retval;
1925}
1926
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001927static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001929 struct zfcp_unit *unit = req->data;
1930
1931 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1932 goto skip_fsfstatus;
1933
1934 switch (req->qtcb->header.fsf_status) {
1935 case FSF_PORT_HANDLE_NOT_VALID:
1936 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
1937 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1938 break;
1939 case FSF_LUN_HANDLE_NOT_VALID:
1940 zfcp_erp_port_reopen(unit->port, 0, 111, req);
1941 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1942 break;
1943 case FSF_PORT_BOXED:
1944 zfcp_erp_port_boxed(unit->port, 52, req);
1945 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1946 ZFCP_STATUS_FSFREQ_RETRY;
1947 break;
1948 case FSF_ADAPTER_STATUS_AVAILABLE:
1949 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1950 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1951 zfcp_test_link(unit->port);
1952 /* fall through */
1953 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1954 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1955 break;
1956 }
1957 break;
1958 case FSF_GOOD:
1959 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1960 break;
1961 }
1962skip_fsfstatus:
1963 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
1964}
1965
1966/**
1967 * zfcp_fsf_close_unit - close zfcp unit
1968 * @erp_action: pointer to struct zfcp_unit
1969 * Returns: 0 on success, error otherwise
1970 */
1971int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1972{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 volatile struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001974 struct zfcp_adapter *adapter = erp_action->adapter;
1975 struct zfcp_fsf_req *req;
1976 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Christof Schmittd4538812008-08-21 13:43:32 +02001978 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001979 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001981 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
1982 ZFCP_REQ_AUTO_CLEANUP,
1983 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001984 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001985 retval = PTR_ERR(req);
1986 goto out;
1987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001989 sbale = zfcp_qdio_sbale_req(req);
1990 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1992
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001993 req->qtcb->header.port_handle = erp_action->port->handle;
1994 req->qtcb->header.lun_handle = erp_action->unit->handle;
1995 req->handler = zfcp_fsf_close_unit_handler;
1996 req->data = erp_action->unit;
1997 req->erp_action = erp_action;
1998 erp_action->fsf_req = req;
1999 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Christof Schmitt287ac012008-07-02 10:56:40 +02002001 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002002 retval = zfcp_fsf_req_send(req);
2003 if (retval) {
2004 zfcp_fsf_req_free(req);
2005 erp_action->fsf_req = NULL;
2006 }
2007out:
Christof Schmittd4538812008-08-21 13:43:32 +02002008 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002009 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010}
2011
Christof Schmittc9615852008-05-06 11:00:05 +02002012static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2013{
2014 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002015 lat_rec->min = min(lat_rec->min, lat);
2016 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002017}
2018
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002019static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
Christof Schmittc9615852008-05-06 11:00:05 +02002020{
2021 struct fsf_qual_latency_info *lat_inf;
2022 struct latency_cont *lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002023 struct zfcp_unit *unit = req->unit;
Christof Schmittc9615852008-05-06 11:00:05 +02002024 unsigned long flags;
2025
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002026 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002027
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002028 switch (req->qtcb->bottom.io.data_direction) {
Christof Schmittc9615852008-05-06 11:00:05 +02002029 case FSF_DATADIR_READ:
2030 lat = &unit->latencies.read;
2031 break;
2032 case FSF_DATADIR_WRITE:
2033 lat = &unit->latencies.write;
2034 break;
2035 case FSF_DATADIR_CMND:
2036 lat = &unit->latencies.cmd;
2037 break;
2038 default:
2039 return;
2040 }
2041
2042 spin_lock_irqsave(&unit->latencies.lock, flags);
2043 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2044 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2045 lat->counter++;
2046 spin_unlock_irqrestore(&unit->latencies.lock, flags);
2047}
2048
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002049static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002051 struct scsi_cmnd *scpnt = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002053 &(req->qtcb->bottom.io.fcp_rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 u32 sns_len;
Martin Petermannf76af7d72008-07-02 10:56:36 +02002055 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Christof Schmitt553448f2008-06-10 18:20:58 +02002058 if (unlikely(!scpnt))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002059 return;
Christof Schmitt553448f2008-06-10 18:20:58 +02002060
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002061 read_lock_irqsave(&req->adapter->abort_lock, flags);
2062
2063 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002064 set_host_byte(scpnt, DID_SOFT_ERROR);
2065 set_driver_byte(scpnt, SUGGEST_RETRY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 goto skip_fsfstatus;
2067 }
2068
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002069 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002070 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 goto skip_fsfstatus;
2072 }
2073
Martin Petermannfeac6a02008-07-02 10:56:35 +02002074 set_msg_byte(scpnt, COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 scpnt->result |= fcp_rsp_iu->scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002078 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2079 zfcp_fsf_req_latency(req);
Christof Schmittc9615852008-05-06 11:00:05 +02002080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002082 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002083 set_host_byte(scpnt, DID_OK);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002084 else {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002085 set_host_byte(scpnt, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05002086 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 }
2088 }
2089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002091 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2092 fcp_rsp_iu->fcp_rsp_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09002096 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 }
2099
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
FUJITA Tomonori7936a892007-07-29 16:46:28 +09002101 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2102 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2103 scpnt->underflow)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002104 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002106skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002107 if (scpnt->result != 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002108 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002109 else if (scpnt->retries > 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002110 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002111 else
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002112 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 /*
2117 * We must hold this lock until scsi_done has been called.
2118 * Otherwise we may call scsi_done after abort regarding this
2119 * command has completed.
2120 * Note: scsi_done must not block!
2121 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002122 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002125static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002128 &(req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d72008-07-02 10:56:36 +02002129 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002131 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2132 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2133 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
2136
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002137static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2138{
2139 struct zfcp_unit *unit;
2140 struct fsf_qtcb_header *header = &req->qtcb->header;
2141
2142 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2143 unit = req->data;
2144 else
2145 unit = req->unit;
2146
2147 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2148 goto skip_fsfstatus;
2149
2150 switch (header->fsf_status) {
2151 case FSF_HANDLE_MISMATCH:
2152 case FSF_PORT_HANDLE_NOT_VALID:
2153 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
2154 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2155 break;
2156 case FSF_FCPLUN_NOT_VALID:
2157 case FSF_LUN_HANDLE_NOT_VALID:
2158 zfcp_erp_port_reopen(unit->port, 0, 113, req);
2159 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2160 break;
2161 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2162 zfcp_fsf_class_not_supp(req);
2163 break;
2164 case FSF_ACCESS_DENIED:
2165 zfcp_fsf_access_denied_unit(req, unit);
2166 break;
2167 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2168 dev_err(&req->adapter->ccw_device->dev,
2169 "Invalid data direction (%d) given for unit "
2170 "0x%016Lx on port 0x%016Lx, shutting down "
2171 "adapter.\n",
2172 req->qtcb->bottom.io.data_direction,
2173 unit->fcp_lun, unit->port->wwpn);
2174 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
2175 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2176 break;
2177 case FSF_CMND_LENGTH_NOT_VALID:
2178 dev_err(&req->adapter->ccw_device->dev,
2179 "An invalid control-data-block length field (%d) "
2180 "was found in a command for unit 0x%016Lx on port "
2181 "0x%016Lx. Shutting down adapter.\n",
2182 req->qtcb->bottom.io.fcp_cmnd_length,
2183 unit->fcp_lun, unit->port->wwpn);
2184 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
2185 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2186 break;
2187 case FSF_PORT_BOXED:
2188 zfcp_erp_port_boxed(unit->port, 53, req);
2189 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2190 ZFCP_STATUS_FSFREQ_RETRY;
2191 break;
2192 case FSF_LUN_BOXED:
2193 zfcp_erp_unit_boxed(unit, 54, req);
2194 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2195 ZFCP_STATUS_FSFREQ_RETRY;
2196 break;
2197 case FSF_ADAPTER_STATUS_AVAILABLE:
2198 if (header->fsf_status_qual.word[0] ==
2199 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2200 zfcp_test_link(unit->port);
2201 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2202 break;
2203 }
2204skip_fsfstatus:
2205 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2206 zfcp_fsf_send_fcp_ctm_handler(req);
2207 else {
2208 zfcp_fsf_send_fcp_command_task_handler(req);
2209 req->unit = NULL;
2210 zfcp_unit_put(unit);
2211 }
2212}
2213
2214/**
2215 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2216 * @adapter: adapter where scsi command is issued
2217 * @unit: unit where command is sent to
2218 * @scsi_cmnd: scsi command to be sent
2219 * @timer: timer to be started when request is initiated
2220 * @req_flags: flags for fsf_request
2221 */
2222int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
2223 struct zfcp_unit *unit,
2224 struct scsi_cmnd *scsi_cmnd,
2225 int use_timer, int req_flags)
2226{
2227 struct zfcp_fsf_req *req;
2228 struct fcp_cmnd_iu *fcp_cmnd_iu;
2229 unsigned int sbtype;
2230 int real_bytes, retval = -EIO;
2231
2232 if (unlikely(!(atomic_read(&unit->status) &
2233 ZFCP_STATUS_COMMON_UNBLOCKED)))
2234 return -EBUSY;
2235
2236 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02002237 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002238 goto out;
2239 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2240 adapter->pool.fsf_req_scsi);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002241 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002242 retval = PTR_ERR(req);
2243 goto out;
2244 }
2245
2246 zfcp_unit_get(unit);
2247 req->unit = unit;
2248 req->data = scsi_cmnd;
2249 req->handler = zfcp_fsf_send_fcp_command_handler;
2250 req->qtcb->header.lun_handle = unit->handle;
2251 req->qtcb->header.port_handle = unit->port->handle;
2252 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2253
2254 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2255
2256 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2257 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2258 /*
2259 * set depending on data direction:
2260 * data direction bits in SBALE (SB Type)
2261 * data direction bits in QTCB
2262 * data direction bits in FCP_CMND IU
2263 */
2264 switch (scsi_cmnd->sc_data_direction) {
2265 case DMA_NONE:
2266 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2267 sbtype = SBAL_FLAGS0_TYPE_READ;
2268 break;
2269 case DMA_FROM_DEVICE:
2270 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2271 sbtype = SBAL_FLAGS0_TYPE_READ;
2272 fcp_cmnd_iu->rddata = 1;
2273 break;
2274 case DMA_TO_DEVICE:
2275 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2276 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2277 fcp_cmnd_iu->wddata = 1;
2278 break;
2279 case DMA_BIDIRECTIONAL:
2280 default:
2281 retval = -EIO;
2282 goto failed_scsi_cmnd;
2283 }
2284
2285 if (likely((scsi_cmnd->device->simple_tags) ||
2286 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2287 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2288 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2289 else
2290 fcp_cmnd_iu->task_attribute = UNTAGGED;
2291
2292 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2293 fcp_cmnd_iu->add_fcp_cdb_length =
2294 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2295
2296 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2297
2298 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2299 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
2300
2301 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2302 scsi_sglist(scsi_cmnd),
2303 FSF_MAX_SBALS_PER_REQ);
2304 if (unlikely(real_bytes < 0)) {
2305 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2306 retval = -EIO;
2307 else {
2308 dev_err(&adapter->ccw_device->dev,
2309 "SCSI request too large. "
2310 "Shutting down unit 0x%016Lx on port "
2311 "0x%016Lx.\n", unit->fcp_lun,
2312 unit->port->wwpn);
2313 zfcp_erp_unit_shutdown(unit, 0, 131, req);
2314 retval = -EINVAL;
2315 }
2316 goto failed_scsi_cmnd;
2317 }
2318
2319 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2320
2321 if (use_timer)
2322 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2323
2324 retval = zfcp_fsf_req_send(req);
2325 if (unlikely(retval))
2326 goto failed_scsi_cmnd;
2327
2328 goto out;
2329
2330failed_scsi_cmnd:
2331 zfcp_unit_put(unit);
2332 zfcp_fsf_req_free(req);
2333 scsi_cmnd->host_scribble = NULL;
2334out:
2335 spin_unlock(&adapter->req_q.lock);
2336 return retval;
2337}
2338
2339/**
2340 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2341 * @adapter: pointer to struct zfcp-adapter
2342 * @unit: pointer to struct zfcp_unit
2343 * @tm_flags: unsigned byte for task management flags
2344 * @req_flags: int request flags
2345 * Returns: on success pointer to struct fsf_req, NULL otherwise
2346 */
2347struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
2348 struct zfcp_unit *unit,
2349 u8 tm_flags, int req_flags)
2350{
2351 volatile struct qdio_buffer_element *sbale;
2352 struct zfcp_fsf_req *req = NULL;
2353 struct fcp_cmnd_iu *fcp_cmnd_iu;
2354
2355 if (unlikely(!(atomic_read(&unit->status) &
2356 ZFCP_STATUS_COMMON_UNBLOCKED)))
2357 return NULL;
2358
2359 spin_lock(&adapter->req_q.lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +02002360 if (!zfcp_fsf_sbal_available(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002361 goto out;
2362 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2363 adapter->pool.fsf_req_scsi);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002364 if (IS_ERR(req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002365 goto out;
2366
2367 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2368 req->data = unit;
2369 req->handler = zfcp_fsf_send_fcp_command_handler;
2370 req->qtcb->header.lun_handle = unit->handle;
2371 req->qtcb->header.port_handle = unit->port->handle;
2372 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2373 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2374 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2375 sizeof(fcp_dl_t);
2376
2377 sbale = zfcp_qdio_sbale_req(req);
2378 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2379 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2380
2381 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2382 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2383 fcp_cmnd_iu->task_management_flags = tm_flags;
2384
2385 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2386 if (!zfcp_fsf_req_send(req))
2387 goto out;
2388
2389 zfcp_fsf_req_free(req);
2390 req = NULL;
2391out:
2392 spin_unlock(&adapter->req_q.lock);
2393 return req;
2394}
2395
2396static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2397{
2398 if (req->qtcb->header.fsf_status != FSF_GOOD)
2399 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2400}
2401
2402/**
2403 * zfcp_fsf_control_file - control file upload/download
2404 * @adapter: pointer to struct zfcp_adapter
2405 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2406 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002408struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2409 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 volatile struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002412 struct zfcp_fsf_req *req = NULL;
2413 struct fsf_qtcb_bottom_support *bottom;
2414 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
Christof Schmitt45633fd2008-06-10 18:20:55 +02002416 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2417 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Christof Schmitt45633fd2008-06-10 18:20:55 +02002419 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2421 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2424 direction = SBAL_FLAGS0_TYPE_READ;
2425 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002427 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 }
2429
Christof Schmittd4538812008-08-21 13:43:32 +02002430 spin_lock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002431 if (zfcp_fsf_req_sbal_get(adapter))
2432 goto out;
2433
2434 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002435 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002437 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 }
2439
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002440 req->handler = zfcp_fsf_control_file_handler;
2441
2442 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 sbale[0].flags |= direction;
2444
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002445 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002447 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002449 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2450 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002451 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2452 retval = -ENOMEM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002453 zfcp_fsf_req_free(req);
2454 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002457 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2458 retval = zfcp_fsf_req_send(req);
2459out:
Christof Schmittd4538812008-08-21 13:43:32 +02002460 spin_unlock_bh(&adapter->req_q.lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002461
2462 if (!retval) {
2463 wait_event(req->completion_wq,
2464 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2465 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002467 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468}