aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/scsi/zfcp_fsf.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/s390/scsi/zfcp_fsf.c')
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c5573
1 files changed, 1668 insertions, 3905 deletions
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index b2ea4ea051f5..19c1ca913874 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -1,54 +1,37 @@
1/* 1/*
2 * This file is part of the zfcp device driver for 2 * zfcp device driver
3 * FCP adapters for IBM System z9 and zSeries.
4 * 3 *
5 * (C) Copyright IBM Corp. 2002, 2006 4 * Implementation of FSF commands.
6 * 5 *
7 * This program is free software; you can redistribute it and/or modify 6 * Copyright IBM Corporation 2002, 2008
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 7 */
21 8
22#include "zfcp_ext.h" 9#include "zfcp_ext.h"
23 10
24static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *); 11static void zfcp_fsf_request_timeout_handler(unsigned long data)
25static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *); 12{
26static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *); 13 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
27static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *); 14 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
28static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *); 15 NULL);
29static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *); 16}
30static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *); 17
31static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *); 18static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
32static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *); 19 unsigned long timeout)
33static int zfcp_fsf_send_fcp_command_task_management_handler( 20{
34 struct zfcp_fsf_req *); 21 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
35static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *); 22 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
36static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *); 23 fsf_req->timer.expires = jiffies + timeout;
37static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *); 24 add_timer(&fsf_req->timer);
38static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *); 25}
39static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *); 26
40static inline int zfcp_fsf_req_sbal_check( 27static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
41 unsigned long *, struct zfcp_qdio_queue *, int); 28{
42static inline int zfcp_use_one_sbal( 29 BUG_ON(!fsf_req->erp_action);
43 struct scatterlist *, int, struct scatterlist *, int); 30 fsf_req->timer.function = zfcp_erp_timeout_handler;
44static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int); 31 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
45static int zfcp_fsf_req_send(struct zfcp_fsf_req *); 32 fsf_req->timer.expires = jiffies + 30 * HZ;
46static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *); 33 add_timer(&fsf_req->timer);
47static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *); 34}
48static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
49static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *, u8,
50 struct fsf_link_down_info *);
51static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
52 35
53/* association between FSF command and FSF QTCB type */ 36/* association between FSF command and FSF QTCB type */
54static u32 fsf_qtcb_type[] = { 37static u32 fsf_qtcb_type[] = {
@@ -67,96 +50,77 @@ static u32 fsf_qtcb_type[] = {
67 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND 50 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
68}; 51};
69 52
70static const char zfcp_act_subtable_type[5][8] = { 53static const char *zfcp_act_subtable_type[] = {
71 "unknown", "OS", "WWPN", "DID", "LUN" 54 "unknown", "OS", "WWPN", "DID", "LUN"
72}; 55};
73 56
74/****************************************************************/ 57static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
75/*************** FSF related Functions *************************/
76/****************************************************************/
77
78#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
79
80/*
81 * function: zfcp_fsf_req_alloc
82 *
83 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
84 * unsolicited requests) via helper functions
85 * Does some initial fsf request set-up.
86 *
87 * returns: pointer to allocated fsf_req if successfull
88 * NULL otherwise
89 *
90 * locks: none
91 *
92 */
93static struct zfcp_fsf_req *
94zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
95{ 58{
96 size_t size; 59 u16 subtable = table >> 16;
97 void *ptr; 60 u16 rule = table & 0xffff;
98 struct zfcp_fsf_req *fsf_req = NULL;
99 61
100 if (req_flags & ZFCP_REQ_NO_QTCB) 62 if (subtable && subtable < ARRAY_SIZE(zfcp_act_subtable_type))
101 size = sizeof(struct zfcp_fsf_req); 63 dev_warn(&adapter->ccw_device->dev,
102 else 64 "Access denied in subtable %s, rule %d.\n",
103 size = sizeof(struct zfcp_fsf_req_qtcb); 65 zfcp_act_subtable_type[subtable], rule);
104 66}
105 if (likely(pool))
106 ptr = mempool_alloc(pool, GFP_ATOMIC);
107 else {
108 if (req_flags & ZFCP_REQ_NO_QTCB)
109 ptr = kmalloc(size, GFP_ATOMIC);
110 else
111 ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
112 GFP_ATOMIC);
113 }
114
115 if (unlikely(!ptr))
116 goto out;
117
118 memset(ptr, 0, size);
119 67
120 if (req_flags & ZFCP_REQ_NO_QTCB) { 68static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
121 fsf_req = (struct zfcp_fsf_req *) ptr; 69 struct zfcp_port *port)
122 } else { 70{
123 fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req; 71 struct fsf_qtcb_header *header = &req->qtcb->header;
124 fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb; 72 dev_warn(&req->adapter->ccw_device->dev,
125 } 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}
126 80
127 fsf_req->pool = pool; 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}
128 93
129 out: 94static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
130 return fsf_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;
131} 101}
132 102
133/* 103/**
134 * function: zfcp_fsf_req_free 104 * zfcp_fsf_req_free - free memory used by fsf request
135 * 105 * @fsf_req: pointer to struct zfcp_fsf_req
136 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
137 * returns it into the pool via helper functions.
138 *
139 * returns: sod all
140 *
141 * locks: none
142 */ 106 */
143void 107void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
144zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
145{ 108{
146 if (likely(fsf_req->pool)) { 109 if (likely(req->pool)) {
147 mempool_free(fsf_req, fsf_req->pool); 110 mempool_free(req, req->pool);
148 return; 111 return;
149 } 112 }
150 113
151 if (fsf_req->qtcb) { 114 if (req->qtcb) {
152 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req); 115 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
153 return; 116 return;
154 } 117 }
155
156 kfree(fsf_req);
157} 118}
158 119
159/* 120/**
121 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
122 * @adapter: pointer to struct zfcp_adapter
123 *
160 * Never ever call this without shutting down the adapter first. 124 * Never ever call this without shutting down the adapter first.
161 * Otherwise the adapter would continue using and corrupting s390 storage. 125 * Otherwise the adapter would continue using and corrupting s390 storage.
162 * Included BUG_ON() call to ensure this is done. 126 * Included BUG_ON() call to ensure this is done.
@@ -164,2353 +128,1359 @@ zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
164 */ 128 */
165void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) 129void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
166{ 130{
167 struct zfcp_fsf_req *fsf_req, *tmp; 131 struct zfcp_fsf_req *req, *tmp;
168 unsigned long flags; 132 unsigned long flags;
169 LIST_HEAD(remove_queue); 133 LIST_HEAD(remove_queue);
170 unsigned int i; 134 unsigned int i;
171 135
172 BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)); 136 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
173 spin_lock_irqsave(&adapter->req_list_lock, flags); 137 spin_lock_irqsave(&adapter->req_list_lock, flags);
174 atomic_set(&adapter->reqs_active, 0);
175 for (i = 0; i < REQUEST_LIST_SIZE; i++) 138 for (i = 0; i < REQUEST_LIST_SIZE; i++)
176 list_splice_init(&adapter->req_list[i], &remove_queue); 139 list_splice_init(&adapter->req_list[i], &remove_queue);
177 spin_unlock_irqrestore(&adapter->req_list_lock, flags); 140 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
178 141
179 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) { 142 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
180 list_del(&fsf_req->list); 143 list_del(&req->list);
181 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; 144 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
182 zfcp_fsf_req_complete(fsf_req); 145 zfcp_fsf_req_complete(req);
183 } 146 }
184} 147}
185 148
186/* 149static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
187 * function: zfcp_fsf_req_complete
188 *
189 * purpose: Updates active counts and timers for openfcp-reqs
190 * May cleanup request after req_eval returns
191 *
192 * returns: 0 - success
193 * !0 - failure
194 *
195 * context:
196 */
197int
198zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
199{ 150{
200 int retval = 0; 151 struct fsf_status_read_buffer *sr_buf = req->data;
201 int cleanup; 152 struct zfcp_adapter *adapter = req->adapter;
202 153 struct zfcp_port *port;
203 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) { 154 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
204 ZFCP_LOG_DEBUG("Status read response received\n"); 155 unsigned long flags;
205 /*
206 * Note: all cleanup handling is done in the callchain of
207 * the function call-chain below.
208 */
209 zfcp_fsf_status_read_handler(fsf_req);
210 goto out;
211 } else {
212 del_timer(&fsf_req->timer);
213 zfcp_fsf_protstatus_eval(fsf_req);
214 }
215
216 /*
217 * fsf_req may be deleted due to waking up functions, so
218 * cleanup is saved here and used later
219 */
220 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
221 cleanup = 1;
222 else
223 cleanup = 0;
224
225 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
226 156
227 /* cleanup request if requested by initiator */ 157 read_lock_irqsave(&zfcp_data.config_lock, flags);
228 if (likely(cleanup)) { 158 list_for_each_entry(port, &adapter->port_list_head, list)
229 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req); 159 if (port->d_id == d_id) {
230 /* 160 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
231 * lock must not be held here since it will be 161 switch (sr_buf->status_subtype) {
232 * grabed by the called routine, too 162 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
233 */ 163 zfcp_erp_port_reopen(port, 0, 101, req);
234 zfcp_fsf_req_free(fsf_req); 164 break;
235 } else { 165 case FSF_STATUS_READ_SUB_ERROR_PORT:
236 /* notify initiator waiting for the requests completion */ 166 zfcp_erp_port_shutdown(port, 0, 122, req);
237 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req); 167 break;
238 /* 168 }
239 * FIXME: Race! We must not access fsf_req here as it might have been 169 return;
240 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED 170 }
241 * flag. It's an improbable case. But, we have the same paranoia for 171 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
242 * the cleanup flag already. 172}
243 * Might better be handled using complete()?
244 * (setting the flag and doing wakeup ought to be atomic
245 * with regard to checking the flag as long as waitqueue is
246 * part of the to be released structure)
247 */
248 wake_up(&fsf_req->completion_wq);
249 }
250 173
251 out: 174static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req)
252 return retval; 175{
176 struct zfcp_adapter *adapter = req->adapter;
177 struct fsf_status_read_buffer *sr_buf = req->data;
178 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
179
180 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);
253} 208}
254 209
255/* 210static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
256 * function: zfcp_fsf_protstatus_eval 211 struct fsf_link_down_info *link_down)
257 *
258 * purpose: evaluates the QTCB of the finished FSF request
259 * and initiates appropriate actions
260 * (usually calling FSF command specific handlers)
261 *
262 * returns:
263 *
264 * context:
265 *
266 * locks:
267 */
268static int
269zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
270{ 212{
271 int retval = 0; 213 struct zfcp_adapter *adapter = req->adapter;
272 struct zfcp_adapter *adapter = fsf_req->adapter;
273 struct fsf_qtcb *qtcb = fsf_req->qtcb;
274 union fsf_prot_status_qual *prot_status_qual =
275 &qtcb->prefix.prot_status_qual;
276
277 zfcp_hba_dbf_event_fsf_response(fsf_req);
278
279 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
280 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
281 (unsigned long) fsf_req);
282 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
283 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
284 goto skip_protstatus;
285 }
286 214
287 /* evaluate FSF Protocol Status */ 215 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
288 switch (qtcb->prefix.prot_status) { 216 return;
289 217
290 case FSF_PROT_GOOD: 218 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
291 case FSF_PROT_FSF_STATUS_PRESENTED:
292 break;
293 219
294 case FSF_PROT_QTCB_VERSION_ERROR: 220 if (!link_down)
295 ZFCP_LOG_NORMAL("error: The adapter %s contains " 221 goto out;
296 "microcode of version 0x%x, the device driver "
297 "only supports 0x%x. Aborting.\n",
298 zfcp_get_busid_by_adapter(adapter),
299 prot_status_qual->version_error.fsf_version,
300 ZFCP_QTCB_VERSION);
301 zfcp_erp_adapter_shutdown(adapter, 0, 117, fsf_req);
302 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
303 break;
304 222
305 case FSF_PROT_SEQ_NUMB_ERROR: 223 switch (link_down->error_code) {
306 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between " 224 case FSF_PSQ_LINK_NO_LIGHT:
307 "driver (0x%x) and adapter %s (0x%x). " 225 dev_warn(&req->adapter->ccw_device->dev,
308 "Restarting all operations on this adapter.\n", 226 "The local link is down: no light detected.\n");
309 qtcb->prefix.req_seq_no,
310 zfcp_get_busid_by_adapter(adapter),
311 prot_status_qual->sequence_error.exp_req_seq_no);
312 zfcp_erp_adapter_reopen(adapter, 0, 98, fsf_req);
313 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
314 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
315 break; 227 break;
316 228 case FSF_PSQ_LINK_WRAP_PLUG:
317 case FSF_PROT_UNSUPP_QTCB_TYPE: 229 dev_warn(&req->adapter->ccw_device->dev,
318 ZFCP_LOG_NORMAL("error: Packet header type used by the " 230 "The local link is down: wrap plug detected.\n");
319 "device driver is incompatible with "
320 "that used on adapter %s. "
321 "Stopping all operations on this adapter.\n",
322 zfcp_get_busid_by_adapter(adapter));
323 zfcp_erp_adapter_shutdown(adapter, 0, 118, fsf_req);
324 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
325 break; 231 break;
326 232 case FSF_PSQ_LINK_NO_FCP:
327 case FSF_PROT_HOST_CONNECTION_INITIALIZING: 233 dev_warn(&req->adapter->ccw_device->dev,
328 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 234 "The local link is down: "
329 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, 235 "adjacent node on link does not support FCP.\n");
330 &(adapter->status));
331 break; 236 break;
332 237 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
333 case FSF_PROT_DUPLICATE_REQUEST_ID: 238 dev_warn(&req->adapter->ccw_device->dev,
334 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx " 239 "The local link is down: "
335 "to the adapter %s is ambiguous. " 240 "firmware update in progress.\n");
336 "Stopping all operations on this adapter.\n",
337 *(unsigned long long*)
338 (&qtcb->bottom.support.req_handle),
339 zfcp_get_busid_by_adapter(adapter));
340 zfcp_erp_adapter_shutdown(adapter, 0, 78, fsf_req);
341 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
342 break; 241 break;
343 242 case FSF_PSQ_LINK_INVALID_WWPN:
344 case FSF_PROT_LINK_DOWN: 243 dev_warn(&req->adapter->ccw_device->dev,
345 zfcp_fsf_link_down_info_eval(fsf_req, 37, 244 "The local link is down: "
346 &prot_status_qual->link_down_info); 245 "duplicate or invalid WWPN detected.\n");
347 /* FIXME: reopening adapter now? better wait for link up */
348 zfcp_erp_adapter_reopen(adapter, 0, 79, fsf_req);
349 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
350 break; 246 break;
351 247 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
352 case FSF_PROT_REEST_QUEUE: 248 dev_warn(&req->adapter->ccw_device->dev,
353 ZFCP_LOG_NORMAL("The local link to adapter with " 249 "The local link is down: "
354 "%s was re-plugged. " 250 "no support for NPIV by Fabric.\n");
355 "Re-starting operations on this adapter.\n",
356 zfcp_get_busid_by_adapter(adapter));
357 /* All ports should be marked as ready to run again */
358 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
359 ZFCP_STATUS_COMMON_RUNNING,
360 ZFCP_SET);
361 zfcp_erp_adapter_reopen(adapter,
362 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
363 | ZFCP_STATUS_COMMON_ERP_FAILED,
364 99, fsf_req);
365 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
366 break; 251 break;
367 252 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
368 case FSF_PROT_ERROR_STATE: 253 dev_warn(&req->adapter->ccw_device->dev,
369 ZFCP_LOG_NORMAL("error: The adapter %s " 254 "The local link is down: "
370 "has entered the error state. " 255 "out of resource in FCP daughtercard.\n");
371 "Restarting all operations on this " 256 break;
372 "adapter.\n", 257 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
373 zfcp_get_busid_by_adapter(adapter)); 258 dev_warn(&req->adapter->ccw_device->dev,
374 zfcp_erp_adapter_reopen(adapter, 0, 100, fsf_req); 259 "The local link is down: "
375 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY; 260 "out of resource in Fabric.\n");
376 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 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");
377 break; 278 break;
378
379 default: 279 default:
380 ZFCP_LOG_NORMAL("bug: Transfer protocol status information " 280 dev_warn(&req->adapter->ccw_device->dev,
381 "provided by the adapter %s " 281 "The local link to adapter is down.\n");
382 "is not compatible with the device driver. "
383 "Stopping all operations on this adapter. "
384 "(debug info 0x%x).\n",
385 zfcp_get_busid_by_adapter(adapter),
386 qtcb->prefix.prot_status);
387 zfcp_erp_adapter_shutdown(adapter, 0, 119, fsf_req);
388 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
389 } 282 }
283out:
284 zfcp_erp_adapter_failed(adapter, id, req);
285}
390 286
391 skip_protstatus: 287static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
392 /* 288{
393 * always call specific handlers to give them a chance to do 289 struct zfcp_adapter *adapter = req->adapter;
394 * something meaningful even in error cases 290 struct fsf_status_read_buffer *sr_buf = req->data;
395 */ 291 struct fsf_link_down_info *ldi =
396 zfcp_fsf_fsfstatus_eval(fsf_req); 292 (struct fsf_link_down_info *) &sr_buf->payload;
397 return retval; 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 };
398} 312}
399 313
400/* 314static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
401 * function: zfcp_fsf_fsfstatus_eval
402 *
403 * purpose: evaluates FSF status of completed FSF request
404 * and acts accordingly
405 *
406 * returns:
407 */
408static int
409zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
410{ 315{
411 int retval = 0; 316 struct zfcp_adapter *adapter = req->adapter;
317 struct fsf_status_read_buffer *sr_buf = req->data;
412 318
413 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { 319 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
414 goto skip_fsfstatus; 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;
415 } 324 }
416 325
417 /* evaluate FSF Status */ 326 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
418 switch (fsf_req->qtcb->header.fsf_status) {
419 case FSF_UNKNOWN_COMMAND:
420 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
421 "not known by the adapter %s "
422 "Stopping all operations on this adapter. "
423 "(debug info 0x%x).\n",
424 zfcp_get_busid_by_adapter(fsf_req->adapter),
425 fsf_req->qtcb->header.fsf_command);
426 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req);
427 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
428 break;
429 327
430 case FSF_FCP_RSP_AVAILABLE: 328 switch (sr_buf->status_type) {
431 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the " 329 case FSF_STATUS_READ_PORT_CLOSED:
432 "SCSI stack.\n"); 330 zfcp_fsf_status_read_port_closed(req);
433 break; 331 break;
434 332 case FSF_STATUS_READ_INCOMING_ELS:
435 case FSF_ADAPTER_STATUS_AVAILABLE: 333 zfcp_fc_incoming_els(req);
436 zfcp_fsf_fsfstatus_qual_eval(fsf_req); 334 break;
335 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
336 break;
337 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
338 zfcp_fsf_bit_error_threshold(req);
339 break;
340 case FSF_STATUS_READ_LINK_DOWN:
341 zfcp_fsf_status_read_link_down(req);
342 break;
343 case FSF_STATUS_READ_LINK_UP:
344 dev_info(&adapter->ccw_device->dev,
345 "Local link was replugged.\n");
346 /* All ports should be marked as ready to run again */
347 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
348 ZFCP_STATUS_COMMON_RUNNING,
349 ZFCP_SET);
350 zfcp_erp_adapter_reopen(adapter,
351 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
352 ZFCP_STATUS_COMMON_ERP_FAILED,
353 102, req);
354 break;
355 case FSF_STATUS_READ_NOTIFICATION_LOST:
356 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)
359 schedule_work(&adapter->scan_work);
360 break;
361 case FSF_STATUS_READ_CFDC_UPDATED:
362 zfcp_erp_adapter_access_changed(adapter, 136, req);
363 break;
364 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
365 adapter->adapter_features = sr_buf->payload.word[0];
437 break; 366 break;
438 } 367 }
439 368
440 skip_fsfstatus: 369 mempool_free(sr_buf, adapter->pool.data_status_read);
441 /* 370 zfcp_fsf_req_free(req);
442 * always call specific handlers to give them a chance to do
443 * something meaningful even in error cases
444 */
445 zfcp_fsf_req_dispatch(fsf_req);
446 371
447 return retval; 372 atomic_inc(&adapter->stat_miss);
373 schedule_work(&adapter->stat_work);
448} 374}
449 375
450/* 376static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
451 * function: zfcp_fsf_fsfstatus_qual_eval
452 *
453 * purpose: evaluates FSF status-qualifier of completed FSF request
454 * and acts accordingly
455 *
456 * returns:
457 */
458static int
459zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
460{ 377{
461 int retval = 0; 378 switch (req->qtcb->header.fsf_status_qual.word[0]) {
462
463 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
464 case FSF_SQ_FCP_RSP_AVAILABLE: 379 case FSF_SQ_FCP_RSP_AVAILABLE:
465 break;
466 case FSF_SQ_RETRY_IF_POSSIBLE:
467 /* The SCSI-stack may now issue retries or escalate */
468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
469 break;
470 case FSF_SQ_COMMAND_ABORTED:
471 /* Carry the aborted state on to upper layer */
472 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
474 break;
475 case FSF_SQ_NO_RECOM:
476 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
477 "problem on the adapter %s "
478 "Stopping all operations on this adapter. ",
479 zfcp_get_busid_by_adapter(fsf_req->adapter));
480 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
482 break;
483 case FSF_SQ_ULP_PROGRAMMING_ERROR:
484 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
485 "(adapter %s)\n",
486 zfcp_get_busid_by_adapter(fsf_req->adapter));
487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
488 break;
489 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 380 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
490 case FSF_SQ_NO_RETRY_POSSIBLE: 381 case FSF_SQ_NO_RETRY_POSSIBLE:
491 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 382 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
492 /* dealt with in the respective functions */ 383 return;
384 case FSF_SQ_COMMAND_ABORTED:
385 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
493 break; 386 break;
494 default: 387 case FSF_SQ_NO_RECOM:
495 ZFCP_LOG_NORMAL("bug: Additional status info could " 388 dev_err(&req->adapter->ccw_device->dev,
496 "not be interpreted properly.\n"); 389 "No recommendation could be given for a "
497 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, 390 "problem on the adapter.\n");
498 (char *) &fsf_req->qtcb->header.fsf_status_qual, 391 zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
499 sizeof (union fsf_status_qual));
500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
501 break; 392 break;
502 } 393 }
503 394 /* all non-return stats set FSFREQ_ERROR*/
504 return retval; 395 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
505} 396}
506 397
507/** 398static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
508 * zfcp_fsf_link_down_info_eval - evaluate link down information block
509 */
510static void
511zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
512 struct fsf_link_down_info *link_down)
513{ 399{
514 struct zfcp_adapter *adapter = fsf_req->adapter; 400 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
515
516 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
517 &adapter->status))
518 return; 401 return;
519 402
520 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); 403 switch (req->qtcb->header.fsf_status) {
521 404 case FSF_UNKNOWN_COMMAND:
522 if (link_down == NULL) 405 dev_err(&req->adapter->ccw_device->dev,
523 goto out; 406 "Command issued by the device driver (0x%x) is "
524 407 "not known by the adapter.\n",
525 switch (link_down->error_code) { 408 req->qtcb->header.fsf_command);
526 case FSF_PSQ_LINK_NO_LIGHT: 409 zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
527 ZFCP_LOG_NORMAL("The local link to adapter %s is down " 410 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
528 "(no light detected)\n",
529 zfcp_get_busid_by_adapter(adapter));
530 break;
531 case FSF_PSQ_LINK_WRAP_PLUG:
532 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
533 "(wrap plug detected)\n",
534 zfcp_get_busid_by_adapter(adapter));
535 break;
536 case FSF_PSQ_LINK_NO_FCP:
537 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
538 "(adjacent node on link does not support FCP)\n",
539 zfcp_get_busid_by_adapter(adapter));
540 break; 411 break;
541 case FSF_PSQ_LINK_FIRMWARE_UPDATE: 412 case FSF_ADAPTER_STATUS_AVAILABLE:
542 ZFCP_LOG_NORMAL("The local link to adapter %s is down " 413 zfcp_fsf_fsfstatus_qual_eval(req);
543 "(firmware update in progress)\n",
544 zfcp_get_busid_by_adapter(adapter));
545 break;
546 case FSF_PSQ_LINK_INVALID_WWPN:
547 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
548 "(duplicate or invalid WWPN detected)\n",
549 zfcp_get_busid_by_adapter(adapter));
550 break; 414 break;
551 case FSF_PSQ_LINK_NO_NPIV_SUPPORT: 415 }
552 ZFCP_LOG_NORMAL("The local link to adapter %s is down " 416}
553 "(no support for NPIV by Fabric)\n", 417
554 zfcp_get_busid_by_adapter(adapter)); 418static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
419{
420 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;
423
424 zfcp_hba_dbf_event_fsf_response(req);
425
426 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;
430 }
431
432 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);
555 break; 444 break;
556 case FSF_PSQ_LINK_NO_FCP_RESOURCES: 445 case FSF_PROT_ERROR_STATE:
557 ZFCP_LOG_NORMAL("The local link to adapter %s is down " 446 case FSF_PROT_SEQ_NUMB_ERROR:
558 "(out of resource in FCP daughtercard)\n", 447 zfcp_erp_adapter_reopen(adapter, 0, 98, req);
559 zfcp_get_busid_by_adapter(adapter)); 448 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
560 break; 449 break;
561 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: 450 case FSF_PROT_UNSUPP_QTCB_TYPE:
562 ZFCP_LOG_NORMAL("The local link to adapter %s is down " 451 dev_err(&adapter->ccw_device->dev,
563 "(out of resource in Fabric)\n", 452 "Packet header type used by the device driver is "
564 zfcp_get_busid_by_adapter(adapter)); 453 "incompatible with that used on the adapter.\n");
454 zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
565 break; 455 break;
566 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: 456 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
567 ZFCP_LOG_NORMAL("The local link to adapter %s is down " 457 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
568 "(unable to Fabric login)\n", 458 &adapter->status);
569 zfcp_get_busid_by_adapter(adapter));
570 break; 459 break;
571 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: 460 case FSF_PROT_DUPLICATE_REQUEST_ID:
572 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n", 461 dev_err(&adapter->ccw_device->dev,
573 zfcp_get_busid_by_adapter(adapter)); 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);
574 break; 465 break;
575 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: 466 case FSF_PROT_LINK_DOWN:
576 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n", 467 zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
577 zfcp_get_busid_by_adapter(adapter)); 468 /* FIXME: reopening adapter now? better wait for link up */
469 zfcp_erp_adapter_reopen(adapter, 0, 79, req);
578 break; 470 break;
579 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: 471 case FSF_PROT_REEST_QUEUE:
580 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n", 472 /* All ports should be marked as ready to run again */
581 zfcp_get_busid_by_adapter(adapter)); 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);
582 break; 479 break;
583 default: 480 default:
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down " 481 dev_err(&adapter->ccw_device->dev,
585 "(warning: unknown reason code %d)\n", 482 "Transfer protocol status information"
586 zfcp_get_busid_by_adapter(adapter), 483 "provided by the adapter (0x%x) "
587 link_down->error_code); 484 "is not compatible with the device driver.\n",
588 } 485 qtcb->prefix.prot_status);
589 486 zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
590 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) 487 }
591 ZFCP_LOG_DEBUG("Debug information to link down: " 488 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
592 "primary_status=0x%02x "
593 "ioerr_code=0x%02x "
594 "action_code=0x%02x "
595 "reason_code=0x%02x "
596 "explanation_code=0x%02x "
597 "vendor_specific_code=0x%02x\n",
598 link_down->primary_status,
599 link_down->ioerr_code,
600 link_down->action_code,
601 link_down->reason_code,
602 link_down->explanation_code,
603 link_down->vendor_specific_code);
604
605 out:
606 zfcp_erp_adapter_failed(adapter, id, fsf_req);
607} 489}
608 490
609/* 491/**
610 * function: zfcp_fsf_req_dispatch 492 * zfcp_fsf_req_complete - process completion of a FSF request
611 * 493 * @fsf_req: The FSF request that has been completed.
612 * purpose: calls the appropriate command specific handler
613 * 494 *
614 * returns: 495 * 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.
615 */ 499 */
616static int 500void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
617zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
618{ 501{
619 struct zfcp_erp_action *erp_action = fsf_req->erp_action; 502 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
620 struct zfcp_adapter *adapter = fsf_req->adapter; 503 zfcp_fsf_status_read_handler(req);
621 int retval = 0; 504 return;
505 }
622 506
507 del_timer(&req->timer);
508 zfcp_fsf_protstatus_eval(req);
509 zfcp_fsf_fsfstatus_eval(req);
510 req->handler(req);
623 511
624 switch (fsf_req->fsf_command) { 512 if (req->erp_action)
513 zfcp_erp_notify(req->erp_action, 0);
514 req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
625 515
626 case FSF_QTCB_FCP_CMND: 516 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
627 zfcp_fsf_send_fcp_command_handler(fsf_req); 517 zfcp_fsf_req_free(req);
628 break; 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}
629 532
630 case FSF_QTCB_ABORT_FCP_CMND: 533static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
631 zfcp_fsf_abort_fcp_command_handler(fsf_req); 534{
632 break; 535 struct fsf_qtcb_bottom_config *bottom;
536 struct zfcp_adapter *adapter = req->adapter;
537 struct Scsi_Host *shost = adapter->scsi_host;
633 538
634 case FSF_QTCB_SEND_GENERIC: 539 bottom = &req->qtcb->bottom.config;
635 zfcp_fsf_send_ct_handler(fsf_req);
636 break;
637 540
638 case FSF_QTCB_OPEN_PORT_WITH_DID: 541 if (req->data)
639 zfcp_fsf_open_port_handler(fsf_req); 542 memcpy(req->data, bottom, sizeof(*bottom));
640 break;
641 543
642 case FSF_QTCB_OPEN_LUN: 544 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
643 zfcp_fsf_open_unit_handler(fsf_req); 545 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
644 break; 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;
645 549
646 case FSF_QTCB_CLOSE_LUN: 550 adapter->hydra_version = bottom->adapter_type;
647 zfcp_fsf_close_unit_handler(fsf_req); 551 adapter->timer_ticks = bottom->timer_interval;
648 break;
649 552
650 case FSF_QTCB_CLOSE_PORT: 553 if (fc_host_permanent_port_name(shost) == -1)
651 zfcp_fsf_close_port_handler(fsf_req); 554 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
652 break;
653 555
654 case FSF_QTCB_CLOSE_PHYSICAL_PORT: 556 switch (bottom->fc_topology) {
655 zfcp_fsf_close_physical_port_handler(fsf_req); 557 case FSF_TOPO_P2P:
656 break; 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 }
657 591
658 case FSF_QTCB_EXCHANGE_CONFIG_DATA: 592 return 0;
659 zfcp_fsf_exchange_config_data_handler(fsf_req); 593}
660 break;
661 594
662 case FSF_QTCB_EXCHANGE_PORT_DATA: 595static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
663 zfcp_fsf_exchange_port_data_handler(fsf_req); 596{
664 break; 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;
665 601
666 case FSF_QTCB_SEND_ELS: 602 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
667 zfcp_fsf_send_els_handler(fsf_req); 603 return;
668 break;
669 604
670 case FSF_QTCB_DOWNLOAD_CONTROL_FILE: 605 adapter->fsf_lic_version = bottom->lic_version;
671 zfcp_fsf_control_file_handler(fsf_req); 606 adapter->adapter_features = bottom->adapter_features;
672 break; 607 adapter->connection_features = bottom->connection_features;
608 adapter->peer_wwpn = 0;
609 adapter->peer_wwnn = 0;
610 adapter->peer_d_id = 0;
673 611
674 case FSF_QTCB_UPLOAD_CONTROL_FILE: 612 switch (qtcb->header.fsf_status) {
675 zfcp_fsf_control_file_handler(fsf_req); 613 case FSF_GOOD:
614 if (zfcp_fsf_exchange_config_evaluate(req))
615 return;
616
617 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);
676 break; 629 break;
630 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
631 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;
635 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
636 adapter->hydra_version = 0;
677 637
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;
678 default: 644 default:
679 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 645 zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
680 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is " 646 return;
681 "not supported by the adapter %s\n",
682 zfcp_get_busid_by_adapter(adapter));
683 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
684 ZFCP_LOG_NORMAL
685 ("bug: Command issued by the device driver differs "
686 "from the command returned by the adapter %s "
687 "(debug info 0x%x, 0x%x).\n",
688 zfcp_get_busid_by_adapter(adapter),
689 fsf_req->fsf_command,
690 fsf_req->qtcb->header.fsf_command);
691 } 647 }
692 648
693 if (!erp_action) 649 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
694 return retval; 650 adapter->hardware_version = bottom->hardware_version;
695 651 memcpy(fc_host_serial_number(shost), bottom->serial_number,
696 zfcp_erp_async_handler(erp_action, 0); 652 min(FC_SERIAL_NUMBER_SIZE, 17));
653 EBCASC(fc_host_serial_number(shost),
654 min(FC_SERIAL_NUMBER_SIZE, 17));
655 }
697 656
698 return retval; 657 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
658 dev_err(&adapter->ccw_device->dev,
659 "The adapter only supports newer control block "
660 "versions, try updated device driver.\n");
661 zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
662 return;
663 }
664 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
665 dev_err(&adapter->ccw_device->dev,
666 "The adapter only supports older control block "
667 "versions, consider a microcode upgrade.\n");
668 zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
669 }
699} 670}
700 671
701/* 672static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
702 * function: zfcp_fsf_status_read
703 *
704 * purpose: initiates a Status Read command at the specified adapter
705 *
706 * returns:
707 */
708int
709zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
710{ 673{
711 struct zfcp_fsf_req *fsf_req; 674 struct zfcp_adapter *adapter = req->adapter;
712 struct fsf_status_read_buffer *status_buffer; 675 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
713 unsigned long lock_flags; 676 struct Scsi_Host *shost = adapter->scsi_host;
714 volatile struct qdio_buffer_element *sbale;
715 int retval = 0;
716
717 /* setup new FSF request */
718 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
719 req_flags | ZFCP_REQ_NO_QTCB,
720 adapter->pool.fsf_req_status_read,
721 &lock_flags, &fsf_req);
722 if (retval < 0) {
723 ZFCP_LOG_INFO("error: Could not create unsolicited status "
724 "buffer for adapter %s.\n",
725 zfcp_get_busid_by_adapter(adapter));
726 goto failed_req_create;
727 }
728
729 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
730 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
731 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
732 fsf_req->sbale_curr = 2;
733 677
734 status_buffer = 678 if (req->data)
735 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); 679 memcpy(req->data, bottom, sizeof(*bottom));
736 if (!status_buffer) {
737 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
738 goto failed_buf;
739 }
740 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
741 fsf_req->data = (unsigned long) status_buffer;
742 680
743 /* insert pointer to respective buffer */ 681 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
744 sbale = zfcp_qdio_sbale_curr(fsf_req); 682 fc_host_permanent_port_name(shost) = bottom->wwpn;
745 sbale->addr = (void *) status_buffer; 683 else
746 sbale->length = sizeof(struct fsf_status_read_buffer); 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}
747 688
748 retval = zfcp_fsf_req_send(fsf_req); 689static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
749 if (retval) { 690{
750 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status " 691 struct zfcp_adapter *adapter = req->adapter;
751 "environment.\n"); 692 struct fsf_qtcb *qtcb = req->qtcb;
752 goto failed_req_send;
753 }
754 693
755 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n", 694 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
756 zfcp_get_busid_by_adapter(adapter)); 695 return;
757 goto out;
758 696
759 failed_req_send: 697 switch (qtcb->header.fsf_status) {
760 mempool_free(status_buffer, adapter->pool.data_status_read); 698 case FSF_GOOD:
699 zfcp_fsf_exchange_port_evaluate(req);
700 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
701 break;
702 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
703 zfcp_fsf_exchange_port_evaluate(req);
704 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
705 zfcp_fsf_link_down_info_eval(req, 43,
706 &qtcb->header.fsf_status_qual.link_down_info);
707 break;
708 }
709}
761 710
762 failed_buf: 711static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
763 zfcp_fsf_req_free(fsf_req); 712{
764 failed_req_create: 713 spin_lock(&queue->lock);
765 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); 714 if (atomic_read(&queue->count))
766 out: 715 return 1;
767 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); 716 spin_unlock(&queue->lock);
768 return retval; 717 return 0;
769} 718}
770 719
771static int 720static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
772zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
773{ 721{
774 struct fsf_status_read_buffer *status_buffer; 722 long ret;
775 struct zfcp_adapter *adapter; 723 struct zfcp_qdio_queue *req_q = &adapter->req_q;
776 struct zfcp_port *port;
777 unsigned long flags;
778 724
779 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data; 725 spin_unlock(&req_q->lock);
780 adapter = fsf_req->adapter; 726 ret = wait_event_interruptible_timeout(adapter->request_wq,
727 zfcp_fsf_sbal_check(req_q), 5 * HZ);
728 if (ret > 0)
729 return 0;
781 730
782 read_lock_irqsave(&zfcp_data.config_lock, flags); 731 spin_lock(&req_q->lock);
783 list_for_each_entry(port, &adapter->port_list_head, list) 732 return -EIO;
784 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK)) 733}
785 break;
786 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
787 734
788 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) { 735static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
789 ZFCP_LOG_NORMAL("bug: Reopen port indication received for " 736{
790 "nonexisting port with d_id 0x%06x on " 737 struct zfcp_fsf_req *req;
791 "adapter %s. Ignored.\n", 738 req = mempool_alloc(pool, GFP_ATOMIC);
792 status_buffer->d_id & ZFCP_DID_MASK, 739 if (!req)
793 zfcp_get_busid_by_adapter(adapter)); 740 return NULL;
794 goto out; 741 memset(req, 0, sizeof(*req));
795 } 742 return req;
743}
796 744
797 switch (status_buffer->status_subtype) { 745static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
746{
747 struct zfcp_fsf_req_qtcb *qtcb;
798 748
799 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT: 749 if (likely(pool))
800 zfcp_erp_port_reopen(port, 0, 101, fsf_req); 750 qtcb = mempool_alloc(pool, GFP_ATOMIC);
801 break; 751 else
752 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
753 GFP_ATOMIC);
754 if (unlikely(!qtcb))
755 return NULL;
802 756
803 case FSF_STATUS_READ_SUB_ERROR_PORT: 757 memset(qtcb, 0, sizeof(*qtcb));
804 zfcp_erp_port_shutdown(port, 0, 122, fsf_req); 758 qtcb->fsf_req.qtcb = &qtcb->qtcb;
805 break; 759 qtcb->fsf_req.pool = pool;
806 760
807 default: 761 return &qtcb->fsf_req;
808 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
809 "for a reopen indication on port with "
810 "d_id 0x%06x on the adapter %s. "
811 "Ignored. (debug info 0x%x)\n",
812 status_buffer->d_id,
813 zfcp_get_busid_by_adapter(adapter),
814 status_buffer->status_subtype);
815 }
816 out:
817 return 0;
818} 762}
819 763
820/* 764static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
821 * function: zfcp_fsf_status_read_handler 765 u32 fsf_cmd, int req_flags,
822 * 766 mempool_t *pool)
823 * purpose: is called for finished Open Port command
824 *
825 * returns:
826 */
827static int
828zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
829{ 767{
830 int retval = 0; 768 volatile struct qdio_buffer_element *sbale;
831 struct zfcp_adapter *adapter = fsf_req->adapter;
832 struct fsf_status_read_buffer *status_buffer =
833 (struct fsf_status_read_buffer *) fsf_req->data;
834 struct fsf_bit_error_payload *fsf_bit_error;
835
836 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
837 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
838 mempool_free(status_buffer, adapter->pool.data_status_read);
839 zfcp_fsf_req_free(fsf_req);
840 goto out;
841 }
842 769
843 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer); 770 struct zfcp_fsf_req *req;
771 struct zfcp_qdio_queue *req_q = &adapter->req_q;
844 772
845 switch (status_buffer->status_type) { 773 if (req_flags & ZFCP_REQ_NO_QTCB)
774 req = zfcp_fsf_alloc_noqtcb(pool);
775 else
776 req = zfcp_fsf_alloc_qtcb(pool);
846 777
847 case FSF_STATUS_READ_PORT_CLOSED: 778 if (unlikely(!req))
848 zfcp_fsf_status_read_port_closed(fsf_req); 779 return ERR_PTR(-EIO);
849 break;
850 780
851 case FSF_STATUS_READ_INCOMING_ELS: 781 if (adapter->req_no == 0)
852 zfcp_fsf_incoming_els(fsf_req); 782 adapter->req_no++;
853 break;
854 783
855 case FSF_STATUS_READ_SENSE_DATA_AVAIL: 784 INIT_LIST_HEAD(&req->list);
856 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n", 785 init_timer(&req->timer);
857 zfcp_get_busid_by_adapter(adapter)); 786 init_waitqueue_head(&req->completion_wq);
858 break;
859 787
860 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: 788 req->adapter = adapter;
861 fsf_bit_error = (struct fsf_bit_error_payload *) 789 req->fsf_command = fsf_cmd;
862 status_buffer->payload; 790 req->req_id = adapter->req_no++;
863 ZFCP_LOG_NORMAL("Warning: bit error threshold data " 791 req->sbal_number = 1;
864 "received (adapter %s, " 792 req->sbal_first = req_q->first;
865 "link failures = %i, loss of sync errors = %i, " 793 req->sbal_last = req_q->first;
866 "loss of signal errors = %i, " 794 req->sbale_curr = 1;
867 "primitive sequence errors = %i, "
868 "invalid transmission word errors = %i, "
869 "CRC errors = %i)\n",
870 zfcp_get_busid_by_adapter(adapter),
871 fsf_bit_error->link_failure_error_count,
872 fsf_bit_error->loss_of_sync_error_count,
873 fsf_bit_error->loss_of_signal_error_count,
874 fsf_bit_error->primitive_sequence_error_count,
875 fsf_bit_error->invalid_transmission_word_error_count,
876 fsf_bit_error->crc_error_count);
877 ZFCP_LOG_INFO("Additional bit error threshold data "
878 "(adapter %s, "
879 "primitive sequence event time-outs = %i, "
880 "elastic buffer overrun errors = %i, "
881 "advertised receive buffer-to-buffer credit = %i, "
882 "current receice buffer-to-buffer credit = %i, "
883 "advertised transmit buffer-to-buffer credit = %i, "
884 "current transmit buffer-to-buffer credit = %i)\n",
885 zfcp_get_busid_by_adapter(adapter),
886 fsf_bit_error->primitive_sequence_event_timeout_count,
887 fsf_bit_error->elastic_buffer_overrun_error_count,
888 fsf_bit_error->advertised_receive_b2b_credit,
889 fsf_bit_error->current_receive_b2b_credit,
890 fsf_bit_error->advertised_transmit_b2b_credit,
891 fsf_bit_error->current_transmit_b2b_credit);
892 break;
893 795
894 case FSF_STATUS_READ_LINK_DOWN: 796 sbale = zfcp_qdio_sbale_req(req);
895 switch (status_buffer->status_subtype) { 797 sbale[0].addr = (void *) req->req_id;
896 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: 798 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
897 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
898 zfcp_get_busid_by_adapter(adapter));
899 zfcp_fsf_link_down_info_eval(fsf_req, 38,
900 (struct fsf_link_down_info *)
901 &status_buffer->payload);
902 break;
903 case FSF_STATUS_READ_SUB_FDISC_FAILED:
904 ZFCP_LOG_INFO("Local link to adapter %s is down "
905 "due to failed FDISC login\n",
906 zfcp_get_busid_by_adapter(adapter));
907 zfcp_fsf_link_down_info_eval(fsf_req, 39,
908 (struct fsf_link_down_info *)
909 &status_buffer->payload);
910 break;
911 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
912 ZFCP_LOG_INFO("Local link to adapter %s is down "
913 "due to firmware update on adapter\n",
914 zfcp_get_busid_by_adapter(adapter));
915 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
916 break;
917 default:
918 ZFCP_LOG_INFO("Local link to adapter %s is down "
919 "due to unknown reason\n",
920 zfcp_get_busid_by_adapter(adapter));
921 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
922 };
923 break;
924 799
925 case FSF_STATUS_READ_LINK_UP: 800 if (likely(req->qtcb)) {
926 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. " 801 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
927 "Restarting operations on this adapter\n", 802 req->qtcb->prefix.req_id = req->req_id;
928 zfcp_get_busid_by_adapter(adapter)); 803 req->qtcb->prefix.ulp_info = 26;
929 /* All ports should be marked as ready to run again */ 804 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
930 zfcp_erp_modify_adapter_status(adapter, 30, NULL, 805 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
931 ZFCP_STATUS_COMMON_RUNNING, 806 req->qtcb->header.req_handle = req->req_id;
932 ZFCP_SET); 807 req->qtcb->header.fsf_command = req->fsf_command;
933 zfcp_erp_adapter_reopen(adapter, 808 req->seq_no = adapter->fsf_req_seq_no;
934 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 809 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
935 | ZFCP_STATUS_COMMON_ERP_FAILED, 810 sbale[1].addr = (void *) req->qtcb;
936 102, fsf_req); 811 sbale[1].length = sizeof(struct fsf_qtcb);
937 break; 812 }
938 813
939 case FSF_STATUS_READ_NOTIFICATION_LOST: 814 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
940 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: " 815 zfcp_fsf_req_free(req);
941 "adapter %s%s%s%s%s%s%s%s%s\n", 816 return ERR_PTR(-EIO);
942 zfcp_get_busid_by_adapter(adapter), 817 }
943 (status_buffer->status_subtype &
944 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
945 ", incoming ELS" : "",
946 (status_buffer->status_subtype &
947 FSF_STATUS_READ_SUB_SENSE_DATA) ?
948 ", sense data" : "",
949 (status_buffer->status_subtype &
950 FSF_STATUS_READ_SUB_LINK_STATUS) ?
951 ", link status change" : "",
952 (status_buffer->status_subtype &
953 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
954 ", port close" : "",
955 (status_buffer->status_subtype &
956 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
957 ", bit error exception" : "",
958 (status_buffer->status_subtype &
959 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
960 ", ACT update" : "",
961 (status_buffer->status_subtype &
962 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
963 ", ACT hardening" : "",
964 (status_buffer->status_subtype &
965 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
966 ", adapter feature change" : "");
967
968 if (status_buffer->status_subtype &
969 FSF_STATUS_READ_SUB_ACT_UPDATED)
970 zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
971 break;
972 818
973 case FSF_STATUS_READ_CFDC_UPDATED: 819 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
974 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n", 820 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
975 zfcp_get_busid_by_adapter(adapter));
976 zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
977 break;
978 821
979 case FSF_STATUS_READ_CFDC_HARDENED: 822 return req;
980 switch (status_buffer->status_subtype) { 823}
981 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
982 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
983 zfcp_get_busid_by_adapter(adapter));
984 break;
985 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
986 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
987 "to the secondary SE\n",
988 zfcp_get_busid_by_adapter(adapter));
989 break;
990 default:
991 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
992 zfcp_get_busid_by_adapter(adapter));
993 }
994 break;
995 824
996 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: 825static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
997 ZFCP_LOG_INFO("List of supported features on adapter %s has " 826{
998 "been changed from 0x%08X to 0x%08X\n", 827 struct zfcp_adapter *adapter = req->adapter;
999 zfcp_get_busid_by_adapter(adapter), 828 struct zfcp_qdio_queue *req_q = &adapter->req_q;
1000 *(u32*) (status_buffer->payload + 4), 829 int idx;
1001 *(u32*) (status_buffer->payload));
1002 adapter->adapter_features = *(u32*) status_buffer->payload;
1003 break;
1004 830
1005 default: 831 /* put allocated FSF request into hash table */
1006 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown " 832 spin_lock(&adapter->req_list_lock);
1007 "type was received (debug info 0x%x)\n", 833 idx = zfcp_reqlist_hash(req->req_id);
1008 status_buffer->status_type); 834 list_add_tail(&req->list, &adapter->req_list[idx]);
1009 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n", 835 spin_unlock(&adapter->req_list_lock);
1010 status_buffer); 836
1011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, 837 req->issued = get_clock();
1012 (char *) status_buffer, 838 if (zfcp_qdio_send(req)) {
1013 sizeof (struct fsf_status_read_buffer)); 839 /* Queues are down..... */
1014 break; 840 del_timer(&req->timer);
1015 } 841 spin_lock(&adapter->req_list_lock);
1016 mempool_free(status_buffer, adapter->pool.data_status_read); 842 zfcp_reqlist_remove(adapter, req);
1017 zfcp_fsf_req_free(fsf_req); 843 spin_unlock(&adapter->req_list_lock);
1018 /* 844 /* undo changes in request queue made for this request */
1019 * recycle buffer and start new request repeat until outbound 845 atomic_add(req->sbal_number, &req_q->count);
1020 * queue is empty or adapter shutdown is requested 846 req_q->first -= req->sbal_number;
1021 */ 847 req_q->first += QDIO_MAX_BUFFERS_PER_Q;
1022 /* 848 req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
1023 * FIXME(qdio): 849 zfcp_erp_adapter_reopen(adapter, 0, 116, req);
1024 * we may wait in the req_create for 5s during shutdown, so 850 return -EIO;
1025 * qdio_cleanup will have to wait at least that long before returning
1026 * with failure to allow us a proper cleanup under all circumstances
1027 */
1028 /*
1029 * FIXME:
1030 * allocation failure possible? (Is this code needed?)
1031 */
1032 retval = zfcp_fsf_status_read(adapter, 0);
1033 if (retval < 0) {
1034 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1035 "request for the adapter %s.\n",
1036 zfcp_get_busid_by_adapter(adapter));
1037 /* temporary fix to avoid status read buffer shortage */
1038 adapter->status_read_failed++;
1039 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1040 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1041 ZFCP_LOG_INFO("restart adapter %s due to status read "
1042 "buffer shortage\n",
1043 zfcp_get_busid_by_adapter(adapter));
1044 zfcp_erp_adapter_reopen(adapter, 0, 103, fsf_req);
1045 }
1046 } 851 }
1047 out: 852
1048 return retval; 853 /* Don't increase for unsolicited status */
854 if (req->qtcb)
855 adapter->fsf_req_seq_no++;
856
857 return 0;
1049} 858}
1050 859
1051/* 860/**
1052 * function: zfcp_fsf_abort_fcp_command 861 * zfcp_fsf_status_read - send status read request
1053 * 862 * @adapter: pointer to struct zfcp_adapter
1054 * purpose: tells FSF to abort a running SCSI command 863 * @req_flags: request flags
1055 * 864 * Returns: 0 on success, ERROR otherwise
1056 * returns: address of initiated FSF request
1057 * NULL - request could not be initiated
1058 *
1059 * FIXME(design): should be watched by a timeout !!!
1060 * FIXME(design) shouldn't this be modified to return an int
1061 * also...don't know how though
1062 */ 865 */
1063struct zfcp_fsf_req * 866int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
1064zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1065 struct zfcp_adapter *adapter,
1066 struct zfcp_unit *unit, int req_flags)
1067{ 867{
868 struct zfcp_fsf_req *req;
869 struct fsf_status_read_buffer *sr_buf;
1068 volatile struct qdio_buffer_element *sbale; 870 volatile struct qdio_buffer_element *sbale;
1069 struct zfcp_fsf_req *fsf_req = NULL; 871 int retval = -EIO;
1070 unsigned long lock_flags;
1071 int retval = 0;
1072
1073 /* setup new FSF request */
1074 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1075 req_flags, adapter->pool.fsf_req_abort,
1076 &lock_flags, &fsf_req);
1077 if (retval < 0) {
1078 ZFCP_LOG_INFO("error: Failed to create an abort command "
1079 "request for lun 0x%016Lx on port 0x%016Lx "
1080 "on adapter %s.\n",
1081 unit->fcp_lun,
1082 unit->port->wwpn,
1083 zfcp_get_busid_by_adapter(adapter));
1084 goto out;
1085 }
1086
1087 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1088 &unit->status)))
1089 goto unit_blocked;
1090 872
1091 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 873 spin_lock(&adapter->req_q.lock);
1092 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 874 if (zfcp_fsf_req_sbal_get(adapter))
1093 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 875 goto out;
1094 876
1095 fsf_req->data = (unsigned long) unit; 877 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
878 ZFCP_REQ_NO_QTCB,
879 adapter->pool.fsf_req_status_read);
880 if (unlikely(IS_ERR(req))) {
881 retval = PTR_ERR(req);
882 goto out;
883 }
1096 884
1097 /* set handles of unit and its parent port in QTCB */ 885 sbale = zfcp_qdio_sbale_req(req);
1098 fsf_req->qtcb->header.lun_handle = unit->handle; 886 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
1099 fsf_req->qtcb->header.port_handle = unit->port->handle; 887 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
888 req->sbale_curr = 2;
1100 889
1101 /* set handle of request which should be aborted */ 890 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
1102 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id; 891 if (!sr_buf) {
892 retval = -ENOMEM;
893 goto failed_buf;
894 }
895 memset(sr_buf, 0, sizeof(*sr_buf));
896 req->data = sr_buf;
897 sbale = zfcp_qdio_sbale_curr(req);
898 sbale->addr = (void *) sr_buf;
899 sbale->length = sizeof(*sr_buf);
1103 900
1104 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT); 901 retval = zfcp_fsf_req_send(req);
1105 retval = zfcp_fsf_req_send(fsf_req); 902 if (retval)
1106 if (!retval) 903 goto failed_req_send;
1107 goto out;
1108 904
1109 unit_blocked: 905 goto out;
1110 zfcp_fsf_req_free(fsf_req);
1111 fsf_req = NULL;
1112 906
1113 out: 907failed_req_send:
1114 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); 908 mempool_free(sr_buf, adapter->pool.data_status_read);
1115 return fsf_req; 909failed_buf:
910 zfcp_fsf_req_free(req);
911 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
912out:
913 spin_unlock(&adapter->req_q.lock);
914 return retval;
1116} 915}
1117 916
1118/* 917static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
1119 * function: zfcp_fsf_abort_fcp_command_handler
1120 *
1121 * purpose: is called for finished Abort FCP Command request
1122 *
1123 * returns:
1124 */
1125static int
1126zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1127{ 918{
1128 int retval = -EINVAL; 919 struct zfcp_unit *unit = req->data;
1129 struct zfcp_unit *unit; 920 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
1130 union fsf_status_qual *fsf_stat_qual =
1131 &new_fsf_req->qtcb->header.fsf_status_qual;
1132
1133 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1134 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1135 goto skip_fsfstatus;
1136 }
1137
1138 unit = (struct zfcp_unit *) new_fsf_req->data;
1139 921
1140 /* evaluate FSF status in QTCB */ 922 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1141 switch (new_fsf_req->qtcb->header.fsf_status) { 923 return;
1142 924
925 switch (req->qtcb->header.fsf_status) {
1143 case FSF_PORT_HANDLE_NOT_VALID: 926 case FSF_PORT_HANDLE_NOT_VALID:
1144 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) { 927 if (fsq->word[0] == fsq->word[1]) {
1145 /*
1146 * In this case a command that was sent prior to a port
1147 * reopen was aborted (handles are different). This is
1148 * fine.
1149 */
1150 } else {
1151 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1152 "port 0x%016Lx on adapter %s invalid. "
1153 "This may happen occasionally.\n",
1154 unit->port->handle,
1155 unit->port->wwpn,
1156 zfcp_get_busid_by_unit(unit));
1157 ZFCP_LOG_INFO("status qualifier:\n");
1158 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1159 (char *) &new_fsf_req->qtcb->header.
1160 fsf_status_qual,
1161 sizeof (union fsf_status_qual));
1162 /* Let's hope this sorts out the mess */
1163 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104, 928 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
1164 new_fsf_req); 929 req);
1165 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 930 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1166 } 931 }
1167 break; 932 break;
1168
1169 case FSF_LUN_HANDLE_NOT_VALID: 933 case FSF_LUN_HANDLE_NOT_VALID:
1170 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) { 934 if (fsq->word[0] == fsq->word[1]) {
1171 /* 935 zfcp_erp_port_reopen(unit->port, 0, 105, req);
1172 * In this case a command that was sent prior to a unit 936 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1173 * reopen was aborted (handles are different).
1174 * This is fine.
1175 */
1176 } else {
1177 ZFCP_LOG_INFO
1178 ("Warning: Temporary LUN identifier 0x%x of LUN "
1179 "0x%016Lx on port 0x%016Lx on adapter %s is "
1180 "invalid. This may happen in rare cases. "
1181 "Trying to re-establish link.\n",
1182 unit->handle,
1183 unit->fcp_lun,
1184 unit->port->wwpn,
1185 zfcp_get_busid_by_unit(unit));
1186 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1187 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1188 (char *) &new_fsf_req->qtcb->header.
1189 fsf_status_qual,
1190 sizeof (union fsf_status_qual));
1191 /* Let's hope this sorts out the mess */
1192 zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
1193 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1194 } 937 }
1195 break; 938 break;
1196
1197 case FSF_FCP_COMMAND_DOES_NOT_EXIST: 939 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1198 retval = 0; 940 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1199 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1200 break; 941 break;
1201
1202 case FSF_PORT_BOXED: 942 case FSF_PORT_BOXED:
1203 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to " 943 zfcp_erp_port_boxed(unit->port, 47, req);
1204 "be reopened\n", unit->port->wwpn, 944 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1205 zfcp_get_busid_by_unit(unit)); 945 ZFCP_STATUS_FSFREQ_RETRY;
1206 zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
1207 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1208 | ZFCP_STATUS_FSFREQ_RETRY;
1209 break; 946 break;
1210
1211 case FSF_LUN_BOXED: 947 case FSF_LUN_BOXED:
1212 ZFCP_LOG_INFO( 948 zfcp_erp_unit_boxed(unit, 48, req);
1213 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs " 949 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1214 "to be reopened\n", 950 ZFCP_STATUS_FSFREQ_RETRY;
1215 unit->fcp_lun, unit->port->wwpn,
1216 zfcp_get_busid_by_unit(unit));
1217 zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
1218 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1219 | ZFCP_STATUS_FSFREQ_RETRY;
1220 break; 951 break;
1221
1222 case FSF_ADAPTER_STATUS_AVAILABLE: 952 case FSF_ADAPTER_STATUS_AVAILABLE:
1223 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) { 953 switch (fsq->word[0]) {
1224 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 954 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1225 zfcp_test_link(unit->port); 955 zfcp_test_link(unit->port);
1226 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1227 break;
1228 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 956 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1229 /* SCSI stack will escalate */ 957 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1230 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1231 break;
1232 default:
1233 ZFCP_LOG_NORMAL
1234 ("bug: Wrong status qualifier 0x%x arrived.\n",
1235 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1236 break; 958 break;
1237 } 959 }
1238 break; 960 break;
1239
1240 case FSF_GOOD: 961 case FSF_GOOD:
1241 retval = 0; 962 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1242 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1243 break;
1244
1245 default:
1246 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1247 "(debug info 0x%x)\n",
1248 new_fsf_req->qtcb->header.fsf_status);
1249 break; 963 break;
1250 } 964 }
1251 skip_fsfstatus:
1252 return retval;
1253} 965}
1254 966
1255/** 967/**
1256 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into 968 * zfcp_fsf_abort_fcp_command - abort running SCSI command
1257 * one SBALE 969 * @old_req_id: unsigned long
1258 * Two scatter-gather lists are passed, one for the reqeust and one for the 970 * @adapter: pointer to struct zfcp_adapter
1259 * response. 971 * @unit: pointer to struct zfcp_unit
972 * @req_flags: integer specifying the request flags
973 * Returns: pointer to struct zfcp_fsf_req
974 *
975 * FIXME(design): should be watched by a timeout !!!
1260 */ 976 */
1261static inline int
1262zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1263 struct scatterlist *resp, int resp_count)
1264{
1265 return ((req_count == 1) &&
1266 (resp_count == 1) &&
1267 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1268 PAGE_MASK) ==
1269 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1270 req[0].length - 1) & PAGE_MASK)) &&
1271 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1272 PAGE_MASK) ==
1273 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1274 resp[0].length - 1) & PAGE_MASK)));
1275}
1276 977
1277/** 978struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1278 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) 979 struct zfcp_adapter *adapter,
1279 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for 980 struct zfcp_unit *unit,
1280 * the request 981 int req_flags)
1281 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1282 * a struct zfcp_fsf_req
1283 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1284 * is sent within error recovery
1285 */
1286int
1287zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1288 struct zfcp_erp_action *erp_action)
1289{ 982{
1290 volatile struct qdio_buffer_element *sbale; 983 volatile struct qdio_buffer_element *sbale;
1291 struct zfcp_port *port; 984 struct zfcp_fsf_req *req = NULL;
1292 struct zfcp_adapter *adapter;
1293 struct zfcp_fsf_req *fsf_req;
1294 unsigned long lock_flags;
1295 int bytes;
1296 int ret = 0;
1297
1298 port = ct->port;
1299 adapter = port->adapter;
1300
1301 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1302 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1303 pool, &lock_flags, &fsf_req);
1304 if (ret < 0) {
1305 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1306 "adapter: %s\n",
1307 zfcp_get_busid_by_adapter(adapter));
1308 goto failed_req;
1309 }
1310 985
1311 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 986 spin_lock(&adapter->req_q.lock);
1312 if (zfcp_use_one_sbal(ct->req, ct->req_count, 987 if (!atomic_read(&adapter->req_q.count))
1313 ct->resp, ct->resp_count)){ 988 goto out;
1314 /* both request buffer and response buffer 989 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1315 fit into one sbale each */ 990 req_flags, adapter->pool.fsf_req_abort);
1316 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ; 991 if (unlikely(IS_ERR(req)))
1317 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]); 992 goto out;
1318 sbale[2].length = ct->req[0].length;
1319 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1320 sbale[3].length = ct->resp[0].length;
1321 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1322 } else if (adapter->adapter_features &
1323 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1324 /* try to use chained SBALs */
1325 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1326 SBAL_FLAGS0_TYPE_WRITE_READ,
1327 ct->req, ct->req_count,
1328 ZFCP_MAX_SBALS_PER_CT_REQ);
1329 if (bytes <= 0) {
1330 ZFCP_LOG_INFO("error: creation of CT request failed "
1331 "on adapter %s\n",
1332 zfcp_get_busid_by_adapter(adapter));
1333 if (bytes == 0)
1334 ret = -ENOMEM;
1335 else
1336 ret = bytes;
1337
1338 goto failed_send;
1339 }
1340 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1341 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1342 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1343 SBAL_FLAGS0_TYPE_WRITE_READ,
1344 ct->resp, ct->resp_count,
1345 ZFCP_MAX_SBALS_PER_CT_REQ);
1346 if (bytes <= 0) {
1347 ZFCP_LOG_INFO("error: creation of CT request failed "
1348 "on adapter %s\n",
1349 zfcp_get_busid_by_adapter(adapter));
1350 if (bytes == 0)
1351 ret = -ENOMEM;
1352 else
1353 ret = bytes;
1354
1355 goto failed_send;
1356 }
1357 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1358 } else {
1359 /* reject send generic request */
1360 ZFCP_LOG_INFO(
1361 "error: microcode does not support chained SBALs,"
1362 "CT request too big (adapter %s)\n",
1363 zfcp_get_busid_by_adapter(adapter));
1364 ret = -EOPNOTSUPP;
1365 goto failed_send;
1366 }
1367
1368 /* settings in QTCB */
1369 fsf_req->qtcb->header.port_handle = port->handle;
1370 fsf_req->qtcb->bottom.support.service_class =
1371 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1372 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1373 fsf_req->data = (unsigned long) ct;
1374
1375 zfcp_san_dbf_event_ct_request(fsf_req);
1376 993
1377 if (erp_action) { 994 if (unlikely(!(atomic_read(&unit->status) &
1378 erp_action->fsf_req = fsf_req; 995 ZFCP_STATUS_COMMON_UNBLOCKED)))
1379 fsf_req->erp_action = erp_action; 996 goto out_error_free;
1380 zfcp_erp_start_timer(fsf_req);
1381 } else
1382 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1383 997
1384 ret = zfcp_fsf_req_send(fsf_req); 998 sbale = zfcp_qdio_sbale_req(req);
1385 if (ret) { 999 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1386 ZFCP_LOG_DEBUG("error: initiation of CT request failed " 1000 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1387 "(adapter %s, port 0x%016Lx)\n",
1388 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1389 goto failed_send;
1390 }
1391 1001
1392 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n", 1002 req->data = unit;
1393 zfcp_get_busid_by_adapter(adapter), port->wwpn); 1003 req->handler = zfcp_fsf_abort_fcp_command_handler;
1394 goto out; 1004 req->qtcb->header.lun_handle = unit->handle;
1005 req->qtcb->header.port_handle = unit->port->handle;
1006 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1395 1007
1396 failed_send: 1008 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
1397 zfcp_fsf_req_free(fsf_req); 1009 if (!zfcp_fsf_req_send(req))
1398 if (erp_action != NULL) { 1010 goto out;
1399 erp_action->fsf_req = NULL; 1011
1400 } 1012out_error_free:
1401 failed_req: 1013 zfcp_fsf_req_free(req);
1402 out: 1014 req = NULL;
1403 write_unlock_irqrestore(&adapter->request_queue.queue_lock, 1015out:
1404 lock_flags); 1016 spin_unlock(&adapter->req_q.lock);
1405 return ret; 1017 return req;
1406} 1018}
1407 1019
1408/** 1020static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
1409 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1410 * @fsf_req: pointer to struct zfcp_fsf_req
1411 *
1412 * Data specific for the Generic Service request is passed using
1413 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1414 * Usually a specific handler for the CT request is called which is
1415 * found in this structure.
1416 */
1417static int
1418zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1419{ 1021{
1420 struct zfcp_port *port; 1022 struct zfcp_adapter *adapter = req->adapter;
1421 struct zfcp_adapter *adapter; 1023 struct zfcp_send_ct *send_ct = req->data;
1422 struct zfcp_send_ct *send_ct; 1024 struct zfcp_port *port = send_ct->port;
1423 struct fsf_qtcb_header *header; 1025 struct fsf_qtcb_header *header = &req->qtcb->header;
1424 struct fsf_qtcb_bottom_support *bottom;
1425 int retval = -EINVAL;
1426 u16 subtable, rule, counter;
1427 1026
1428 adapter = fsf_req->adapter; 1027 send_ct->status = -EINVAL;
1429 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1430 port = send_ct->port;
1431 header = &fsf_req->qtcb->header;
1432 bottom = &fsf_req->qtcb->bottom.support;
1433 1028
1434 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) 1029 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1435 goto skip_fsfstatus; 1030 goto skip_fsfstatus;
1436 1031
1437 /* evaluate FSF status in QTCB */
1438 switch (header->fsf_status) { 1032 switch (header->fsf_status) {
1439
1440 case FSF_GOOD: 1033 case FSF_GOOD:
1441 zfcp_san_dbf_event_ct_response(fsf_req); 1034 zfcp_san_dbf_event_ct_response(req);
1442 retval = 0; 1035 send_ct->status = 0;
1443 break; 1036 break;
1444
1445 case FSF_SERVICE_CLASS_NOT_SUPPORTED: 1037 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1446 ZFCP_LOG_INFO("error: adapter %s does not support fc " 1038 zfcp_fsf_class_not_supp(req);
1447 "class %d.\n",
1448 zfcp_get_busid_by_port(port),
1449 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1450 /* stop operation for this adapter */
1451 zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
1452 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1453 break; 1039 break;
1454
1455 case FSF_ADAPTER_STATUS_AVAILABLE: 1040 case FSF_ADAPTER_STATUS_AVAILABLE:
1456 switch (header->fsf_status_qual.word[0]){ 1041 switch (header->fsf_status_qual.word[0]){
1457 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 1042 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1458 /* reopening link to port */
1459 zfcp_test_link(port); 1043 zfcp_test_link(port);
1460 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1461 break;
1462 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 1044 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1463 /* ERP strategy will escalate */ 1045 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1465 break;
1466 default:
1467 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1468 "arrived.\n",
1469 header->fsf_status_qual.word[0]);
1470 break; 1046 break;
1471 } 1047 }
1472 break; 1048 break;
1473
1474 case FSF_ACCESS_DENIED: 1049 case FSF_ACCESS_DENIED:
1475 ZFCP_LOG_NORMAL("access denied, cannot send generic service " 1050 zfcp_fsf_access_denied_port(req, port);
1476 "command (adapter %s, port d_id=0x%06x)\n",
1477 zfcp_get_busid_by_port(port), port->d_id);
1478 for (counter = 0; counter < 2; counter++) {
1479 subtable = header->fsf_status_qual.halfword[counter * 2];
1480 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1481 switch (subtable) {
1482 case FSF_SQ_CFDC_SUBTABLE_OS:
1483 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1484 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1485 case FSF_SQ_CFDC_SUBTABLE_LUN:
1486 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1487 zfcp_act_subtable_type[subtable], rule);
1488 break;
1489 }
1490 }
1491 zfcp_erp_port_access_denied(port, 55, fsf_req);
1492 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1493 break;
1494
1495 case FSF_GENERIC_COMMAND_REJECTED:
1496 ZFCP_LOG_INFO("generic service command rejected "
1497 "(adapter %s, port d_id=0x%06x)\n",
1498 zfcp_get_busid_by_port(port), port->d_id);
1499 ZFCP_LOG_INFO("status qualifier:\n");
1500 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1501 (char *) &header->fsf_status_qual,
1502 sizeof (union fsf_status_qual));
1503 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1504 break;
1505
1506 case FSF_PORT_HANDLE_NOT_VALID:
1507 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1508 "0x%016Lx on adapter %s invalid. This may "
1509 "happen occasionally.\n", port->handle,
1510 port->wwpn, zfcp_get_busid_by_port(port));
1511 ZFCP_LOG_INFO("status qualifier:\n");
1512 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1513 (char *) &header->fsf_status_qual,
1514 sizeof (union fsf_status_qual));
1515 zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
1516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1517 break; 1051 break;
1518
1519 case FSF_PORT_BOXED: 1052 case FSF_PORT_BOXED:
1520 ZFCP_LOG_INFO("port needs to be reopened " 1053 zfcp_erp_port_boxed(port, 49, req);
1521 "(adapter %s, port d_id=0x%06x)\n", 1054 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1522 zfcp_get_busid_by_port(port), port->d_id); 1055 ZFCP_STATUS_FSFREQ_RETRY;
1523 zfcp_erp_port_boxed(port, 49, fsf_req);
1524 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1525 | ZFCP_STATUS_FSFREQ_RETRY;
1526 break; 1056 break;
1527 1057 case FSF_PORT_HANDLE_NOT_VALID:
1528 /* following states should never occure, all cases avoided 1058 zfcp_erp_adapter_reopen(adapter, 0, 106, req);
1529 in zfcp_fsf_send_ct - but who knows ... */ 1059 case FSF_GENERIC_COMMAND_REJECTED:
1530 case FSF_PAYLOAD_SIZE_MISMATCH: 1060 case FSF_PAYLOAD_SIZE_MISMATCH:
1531 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1532 "req_buf_length=%d, resp_buf_length=%d)\n",
1533 zfcp_get_busid_by_adapter(adapter),
1534 bottom->req_buf_length, bottom->resp_buf_length);
1535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1536 break;
1537 case FSF_REQUEST_SIZE_TOO_LARGE: 1061 case FSF_REQUEST_SIZE_TOO_LARGE:
1538 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1539 "req_buf_length=%d)\n",
1540 zfcp_get_busid_by_adapter(adapter),
1541 bottom->req_buf_length);
1542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1543 break;
1544 case FSF_RESPONSE_SIZE_TOO_LARGE: 1062 case FSF_RESPONSE_SIZE_TOO_LARGE:
1545 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1546 "resp_buf_length=%d)\n",
1547 zfcp_get_busid_by_adapter(adapter),
1548 bottom->resp_buf_length);
1549 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1550 break;
1551 case FSF_SBAL_MISMATCH: 1063 case FSF_SBAL_MISMATCH:
1552 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, " 1064 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1553 "resp_buf_length=%d)\n",
1554 zfcp_get_busid_by_adapter(adapter),
1555 bottom->req_buf_length, bottom->resp_buf_length);
1556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1557 break;
1558
1559 default:
1560 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1561 "(debug info 0x%x)\n", header->fsf_status);
1562 break; 1065 break;
1563 } 1066 }
1564 1067
1565skip_fsfstatus: 1068skip_fsfstatus:
1566 send_ct->status = retval; 1069 if (send_ct->handler)
1567
1568 if (send_ct->handler != NULL)
1569 send_ct->handler(send_ct->handler_data); 1070 send_ct->handler(send_ct->handler_data);
1071}
1570 1072
1571 return retval; 1073static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
1074 struct scatterlist *sg_req,
1075 struct scatterlist *sg_resp, int max_sbals)
1076{
1077 int bytes;
1078
1079 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1080 sg_req, max_sbals);
1081 if (bytes <= 0)
1082 return -ENOMEM;
1083 req->qtcb->bottom.support.req_buf_length = bytes;
1084 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1085
1086 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1087 sg_resp, max_sbals);
1088 if (bytes <= 0)
1089 return -ENOMEM;
1090 req->qtcb->bottom.support.resp_buf_length = bytes;
1091
1092 return 0;
1572} 1093}
1573 1094
1574/** 1095/**
1575 * zfcp_fsf_send_els - initiate an ELS command (FC-FS) 1096 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1576 * @els: pointer to struct zfcp_send_els which contains all needed data for 1097 * @ct: pointer to struct zfcp_send_ct with data for request
1577 * the command. 1098 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1099 * @erp_action: if non-null the Generic Service request sent within ERP
1578 */ 1100 */
1579int 1101int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1580zfcp_fsf_send_els(struct zfcp_send_els *els) 1102 struct zfcp_erp_action *erp_action)
1581{ 1103{
1582 volatile struct qdio_buffer_element *sbale; 1104 struct zfcp_port *port = ct->port;
1583 struct zfcp_fsf_req *fsf_req; 1105 struct zfcp_adapter *adapter = port->adapter;
1584 u32 d_id; 1106 struct zfcp_fsf_req *req;
1585 struct zfcp_adapter *adapter; 1107 int ret = -EIO;
1586 unsigned long lock_flags;
1587 int bytes;
1588 int ret = 0;
1589
1590 d_id = els->d_id;
1591 adapter = els->adapter;
1592 1108
1593 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, 1109 spin_lock(&adapter->req_q.lock);
1594 ZFCP_REQ_AUTO_CLEANUP, 1110 if (zfcp_fsf_req_sbal_get(adapter))
1595 NULL, &lock_flags, &fsf_req); 1111 goto out;
1596 if (ret < 0) {
1597 ZFCP_LOG_INFO("error: creation of ELS request failed "
1598 "(adapter %s, port d_id: 0x%06x)\n",
1599 zfcp_get_busid_by_adapter(adapter), d_id);
1600 goto failed_req;
1601 }
1602 1112
1603 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, 1113 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1604 &els->port->status))) { 1114 ZFCP_REQ_AUTO_CLEANUP, pool);
1605 ret = -EBUSY; 1115 if (unlikely(IS_ERR(req))) {
1606 goto port_blocked; 1116 ret = PTR_ERR(req);
1117 goto out;
1607 } 1118 }
1608 1119
1609 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1120 ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
1610 if (zfcp_use_one_sbal(els->req, els->req_count, 1121 FSF_MAX_SBALS_PER_REQ);
1611 els->resp, els->resp_count)){ 1122 if (ret)
1612 /* both request buffer and response buffer
1613 fit into one sbale each */
1614 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1615 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1616 sbale[2].length = els->req[0].length;
1617 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1618 sbale[3].length = els->resp[0].length;
1619 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1620 } else if (adapter->adapter_features &
1621 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1622 /* try to use chained SBALs */
1623 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1624 SBAL_FLAGS0_TYPE_WRITE_READ,
1625 els->req, els->req_count,
1626 ZFCP_MAX_SBALS_PER_ELS_REQ);
1627 if (bytes <= 0) {
1628 ZFCP_LOG_INFO("error: creation of ELS request failed "
1629 "(adapter %s, port d_id: 0x%06x)\n",
1630 zfcp_get_busid_by_adapter(adapter), d_id);
1631 if (bytes == 0) {
1632 ret = -ENOMEM;
1633 } else {
1634 ret = bytes;
1635 }
1636 goto failed_send;
1637 }
1638 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1639 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1640 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1641 SBAL_FLAGS0_TYPE_WRITE_READ,
1642 els->resp, els->resp_count,
1643 ZFCP_MAX_SBALS_PER_ELS_REQ);
1644 if (bytes <= 0) {
1645 ZFCP_LOG_INFO("error: creation of ELS request failed "
1646 "(adapter %s, port d_id: 0x%06x)\n",
1647 zfcp_get_busid_by_adapter(adapter), d_id);
1648 if (bytes == 0) {
1649 ret = -ENOMEM;
1650 } else {
1651 ret = bytes;
1652 }
1653 goto failed_send;
1654 }
1655 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1656 } else {
1657 /* reject request */
1658 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1659 ", ELS request too big (adapter %s, "
1660 "port d_id: 0x%06x)\n",
1661 zfcp_get_busid_by_adapter(adapter), d_id);
1662 ret = -EOPNOTSUPP;
1663 goto failed_send;
1664 }
1665
1666 /* settings in QTCB */
1667 fsf_req->qtcb->bottom.support.d_id = d_id;
1668 fsf_req->qtcb->bottom.support.service_class =
1669 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1670 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1671 fsf_req->data = (unsigned long) els;
1672
1673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1674
1675 zfcp_san_dbf_event_els_request(fsf_req);
1676
1677 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1678 ret = zfcp_fsf_req_send(fsf_req);
1679 if (ret) {
1680 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1681 "(adapter %s, port d_id: 0x%06x)\n",
1682 zfcp_get_busid_by_adapter(adapter), d_id);
1683 goto failed_send; 1123 goto failed_send;
1684 }
1685 1124
1686 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: " 1125 req->handler = zfcp_fsf_send_ct_handler;
1687 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id); 1126 req->qtcb->header.port_handle = port->handle;
1688 goto out; 1127 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1128 req->qtcb->bottom.support.timeout = ct->timeout;
1129 req->data = ct;
1689 1130
1690 port_blocked: 1131 zfcp_san_dbf_event_ct_request(req);
1691 failed_send:
1692 zfcp_fsf_req_free(fsf_req);
1693 1132
1694 failed_req: 1133 if (erp_action) {
1695 out: 1134 erp_action->fsf_req = req;
1696 write_unlock_irqrestore(&adapter->request_queue.queue_lock, 1135 req->erp_action = erp_action;
1697 lock_flags); 1136 zfcp_fsf_start_erp_timer(req);
1137 } else
1138 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1139
1140 ret = zfcp_fsf_req_send(req);
1141 if (ret)
1142 goto failed_send;
1143
1144 goto out;
1698 1145
1699 return ret; 1146failed_send:
1147 zfcp_fsf_req_free(req);
1148 if (erp_action)
1149 erp_action->fsf_req = NULL;
1150out:
1151 spin_unlock(&adapter->req_q.lock);
1152 return ret;
1700} 1153}
1701 1154
1702/** 1155static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1703 * zfcp_fsf_send_els_handler - handler for ELS commands
1704 * @fsf_req: pointer to struct zfcp_fsf_req
1705 *
1706 * Data specific for the ELS command is passed using
1707 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1708 * Usually a specific handler for the ELS command is called which is
1709 * found in this structure.
1710 */
1711static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1712{ 1156{
1713 struct zfcp_adapter *adapter; 1157 struct zfcp_send_els *send_els = req->data;
1714 struct zfcp_port *port; 1158 struct zfcp_port *port = send_els->port;
1715 u32 d_id; 1159 struct fsf_qtcb_header *header = &req->qtcb->header;
1716 struct fsf_qtcb_header *header; 1160
1717 struct fsf_qtcb_bottom_support *bottom; 1161 send_els->status = -EINVAL;
1718 struct zfcp_send_els *send_els; 1162
1719 int retval = -EINVAL; 1163 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1720 u16 subtable, rule, counter;
1721
1722 send_els = (struct zfcp_send_els *) fsf_req->data;
1723 adapter = send_els->adapter;
1724 port = send_els->port;
1725 d_id = send_els->d_id;
1726 header = &fsf_req->qtcb->header;
1727 bottom = &fsf_req->qtcb->bottom.support;
1728
1729 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1730 goto skip_fsfstatus; 1164 goto skip_fsfstatus;
1731 1165
1732 switch (header->fsf_status) { 1166 switch (header->fsf_status) {
1733
1734 case FSF_GOOD: 1167 case FSF_GOOD:
1735 zfcp_san_dbf_event_els_response(fsf_req); 1168 zfcp_san_dbf_event_els_response(req);
1736 retval = 0; 1169 send_els->status = 0;
1737 break; 1170 break;
1738
1739 case FSF_SERVICE_CLASS_NOT_SUPPORTED: 1171 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1740 ZFCP_LOG_INFO("error: adapter %s does not support fc " 1172 zfcp_fsf_class_not_supp(req);
1741 "class %d.\n",
1742 zfcp_get_busid_by_adapter(adapter),
1743 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1744 /* stop operation for this adapter */
1745 zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
1746 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1747 break; 1173 break;
1748
1749 case FSF_ADAPTER_STATUS_AVAILABLE: 1174 case FSF_ADAPTER_STATUS_AVAILABLE:
1750 switch (header->fsf_status_qual.word[0]){ 1175 switch (header->fsf_status_qual.word[0]){
1751 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 1176 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1752 if (port && (send_els->ls_code != ZFCP_LS_ADISC)) 1177 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1753 zfcp_test_link(port); 1178 zfcp_test_link(port);
1754 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1179 /*fall through */
1755 break;
1756 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 1180 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1757 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1758 retval =
1759 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1760 (struct zfcp_ls_rjt_par *)
1761 &header->fsf_status_qual.word[2]);
1762 break;
1763 case FSF_SQ_RETRY_IF_POSSIBLE: 1181 case FSF_SQ_RETRY_IF_POSSIBLE:
1764 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1182 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1765 break; 1183 break;
1766 default:
1767 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1768 header->fsf_status_qual.word[0]);
1769 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1770 (char*)header->fsf_status_qual.word, 16);
1771 } 1184 }
1772 break; 1185 break;
1773
1774 case FSF_ELS_COMMAND_REJECTED: 1186 case FSF_ELS_COMMAND_REJECTED:
1775 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1776 "prohibited sending "
1777 "(adapter: %s, port d_id: 0x%06x)\n",
1778 zfcp_get_busid_by_adapter(adapter), d_id);
1779
1780 break;
1781
1782 case FSF_PAYLOAD_SIZE_MISMATCH: 1187 case FSF_PAYLOAD_SIZE_MISMATCH:
1783 ZFCP_LOG_INFO(
1784 "ELS request size and ELS response size must be either "
1785 "both 0, or both greater than 0 "
1786 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1787 zfcp_get_busid_by_adapter(adapter),
1788 bottom->req_buf_length,
1789 bottom->resp_buf_length);
1790 break;
1791
1792 case FSF_REQUEST_SIZE_TOO_LARGE: 1188 case FSF_REQUEST_SIZE_TOO_LARGE:
1793 ZFCP_LOG_INFO(
1794 "Length of the ELS request buffer, "
1795 "specified in QTCB bottom, "
1796 "exceeds the size of the buffers "
1797 "that have been allocated for ELS request data "
1798 "(adapter: %s, req_buf_length=%d)\n",
1799 zfcp_get_busid_by_adapter(adapter),
1800 bottom->req_buf_length);
1801 break;
1802
1803 case FSF_RESPONSE_SIZE_TOO_LARGE: 1189 case FSF_RESPONSE_SIZE_TOO_LARGE:
1804 ZFCP_LOG_INFO(
1805 "Length of the ELS response buffer, "
1806 "specified in QTCB bottom, "
1807 "exceeds the size of the buffers "
1808 "that have been allocated for ELS response data "
1809 "(adapter: %s, resp_buf_length=%d)\n",
1810 zfcp_get_busid_by_adapter(adapter),
1811 bottom->resp_buf_length);
1812 break;
1813
1814 case FSF_SBAL_MISMATCH:
1815 /* should never occure, avoided in zfcp_fsf_send_els */
1816 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1817 "resp_buf_length=%d)\n",
1818 zfcp_get_busid_by_adapter(adapter),
1819 bottom->req_buf_length, bottom->resp_buf_length);
1820 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1821 break; 1190 break;
1822
1823 case FSF_ACCESS_DENIED: 1191 case FSF_ACCESS_DENIED:
1824 ZFCP_LOG_NORMAL("access denied, cannot send ELS command " 1192 zfcp_fsf_access_denied_port(req, port);
1825 "(adapter %s, port d_id=0x%06x)\n",
1826 zfcp_get_busid_by_adapter(adapter), d_id);
1827 for (counter = 0; counter < 2; counter++) {
1828 subtable = header->fsf_status_qual.halfword[counter * 2];
1829 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1830 switch (subtable) {
1831 case FSF_SQ_CFDC_SUBTABLE_OS:
1832 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1833 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1834 case FSF_SQ_CFDC_SUBTABLE_LUN:
1835 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1836 zfcp_act_subtable_type[subtable], rule);
1837 break;
1838 }
1839 }
1840 if (port != NULL)
1841 zfcp_erp_port_access_denied(port, 56, fsf_req);
1842 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1843 break; 1193 break;
1844 1194 case FSF_SBAL_MISMATCH:
1195 /* should never occure, avoided in zfcp_fsf_send_els */
1196 /* fall through */
1845 default: 1197 default:
1846 ZFCP_LOG_NORMAL( 1198 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1847 "bug: An unknown FSF Status was presented "
1848 "(adapter: %s, fsf_status=0x%08x)\n",
1849 zfcp_get_busid_by_adapter(adapter),
1850 header->fsf_status);
1851 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1852 break; 1199 break;
1853 } 1200 }
1854
1855skip_fsfstatus: 1201skip_fsfstatus:
1856 send_els->status = retval;
1857
1858 if (send_els->handler) 1202 if (send_els->handler)
1859 send_els->handler(send_els->handler_data); 1203 send_els->handler(send_els->handler_data);
1204}
1860 1205
1861 return retval; 1206/**
1207 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1208 * @els: pointer to struct zfcp_send_els with data for the command
1209 */
1210int zfcp_fsf_send_els(struct zfcp_send_els *els)
1211{
1212 struct zfcp_fsf_req *req;
1213 struct zfcp_adapter *adapter = els->adapter;
1214 struct fsf_qtcb_bottom_support *bottom;
1215 int ret = -EIO;
1216
1217 if (unlikely(!(atomic_read(&els->port->status) &
1218 ZFCP_STATUS_COMMON_UNBLOCKED)))
1219 return -EBUSY;
1220
1221 spin_lock(&adapter->req_q.lock);
1222 if (!atomic_read(&adapter->req_q.count))
1223 goto out;
1224 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1225 ZFCP_REQ_AUTO_CLEANUP, NULL);
1226 if (unlikely(IS_ERR(req))) {
1227 ret = PTR_ERR(req);
1228 goto out;
1229 }
1230
1231 ret = zfcp_fsf_setup_sbals(req, els->req, els->resp,
1232 FSF_MAX_SBALS_PER_ELS_REQ);
1233 if (ret)
1234 goto failed_send;
1235
1236 bottom = &req->qtcb->bottom.support;
1237 req->handler = zfcp_fsf_send_els_handler;
1238 bottom->d_id = els->d_id;
1239 bottom->service_class = FSF_CLASS_3;
1240 bottom->timeout = 2 * R_A_TOV;
1241 req->data = els;
1242
1243 zfcp_san_dbf_event_els_request(req);
1244
1245 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1246 ret = zfcp_fsf_req_send(req);
1247 if (ret)
1248 goto failed_send;
1249
1250 goto out;
1251
1252failed_send:
1253 zfcp_fsf_req_free(req);
1254out:
1255 spin_unlock(&adapter->req_q.lock);
1256 return ret;
1862} 1257}
1863 1258
1864int 1259int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1865zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1866{ 1260{
1867 volatile struct qdio_buffer_element *sbale; 1261 volatile struct qdio_buffer_element *sbale;
1868 struct zfcp_fsf_req *fsf_req; 1262 struct zfcp_fsf_req *req;
1869 struct zfcp_adapter *adapter = erp_action->adapter; 1263 struct zfcp_adapter *adapter = erp_action->adapter;
1870 unsigned long lock_flags; 1264 int retval = -EIO;
1871 int retval; 1265
1872 1266 spin_lock(&adapter->req_q.lock);
1873 /* setup new FSF request */ 1267 if (!atomic_read(&adapter->req_q.count))
1874 retval = zfcp_fsf_req_create(adapter, 1268 goto out;
1875 FSF_QTCB_EXCHANGE_CONFIG_DATA, 1269 req = zfcp_fsf_req_create(adapter,
1876 ZFCP_REQ_AUTO_CLEANUP, 1270 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1877 adapter->pool.fsf_req_erp, 1271 ZFCP_REQ_AUTO_CLEANUP,
1878 &lock_flags, &fsf_req); 1272 adapter->pool.fsf_req_erp);
1879 if (retval) { 1273 if (unlikely(IS_ERR(req))) {
1880 ZFCP_LOG_INFO("error: Could not create exchange configuration " 1274 retval = PTR_ERR(req);
1881 "data request for adapter %s.\n", 1275 goto out;
1882 zfcp_get_busid_by_adapter(adapter));
1883 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1884 lock_flags);
1885 return retval;
1886 } 1276 }
1887 1277
1888 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1278 sbale = zfcp_qdio_sbale_req(req);
1889 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1279 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1890 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1280 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1891 1281
1892 fsf_req->qtcb->bottom.config.feature_selection = 1282 req->qtcb->bottom.config.feature_selection =
1893 FSF_FEATURE_CFDC | 1283 FSF_FEATURE_CFDC |
1894 FSF_FEATURE_LUN_SHARING | 1284 FSF_FEATURE_LUN_SHARING |
1895 FSF_FEATURE_NOTIFICATION_LOST | 1285 FSF_FEATURE_NOTIFICATION_LOST |
1896 FSF_FEATURE_UPDATE_ALERT; 1286 FSF_FEATURE_UPDATE_ALERT;
1897 fsf_req->erp_action = erp_action; 1287 req->erp_action = erp_action;
1898 erp_action->fsf_req = fsf_req; 1288 req->handler = zfcp_fsf_exchange_config_data_handler;
1289 erp_action->fsf_req = req;
1899 1290
1900 zfcp_erp_start_timer(fsf_req); 1291 zfcp_fsf_start_erp_timer(req);
1901 retval = zfcp_fsf_req_send(fsf_req); 1292 retval = zfcp_fsf_req_send(req);
1902 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1903 lock_flags);
1904 if (retval) { 1293 if (retval) {
1905 ZFCP_LOG_INFO("error: Could not send exchange configuration " 1294 zfcp_fsf_req_free(req);
1906 "data command on the adapter %s\n",
1907 zfcp_get_busid_by_adapter(adapter));
1908 zfcp_fsf_req_free(fsf_req);
1909 erp_action->fsf_req = NULL; 1295 erp_action->fsf_req = NULL;
1910 } 1296 }
1911 else 1297out:
1912 ZFCP_LOG_DEBUG("exchange configuration data request initiated " 1298 spin_unlock(&adapter->req_q.lock);
1913 "(adapter %s)\n",
1914 zfcp_get_busid_by_adapter(adapter));
1915
1916 return retval; 1299 return retval;
1917} 1300}
1918 1301
1919int 1302int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1920zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter, 1303 struct fsf_qtcb_bottom_config *data)
1921 struct fsf_qtcb_bottom_config *data)
1922{ 1304{
1923 volatile struct qdio_buffer_element *sbale; 1305 volatile struct qdio_buffer_element *sbale;
1924 struct zfcp_fsf_req *fsf_req; 1306 struct zfcp_fsf_req *req = NULL;
1925 unsigned long lock_flags; 1307 int retval = -EIO;
1926 int retval; 1308
1927 1309 spin_lock(&adapter->req_q.lock);
1928 /* setup new FSF request */ 1310 if (zfcp_fsf_req_sbal_get(adapter))
1929 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA, 1311 goto out;
1930 ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags, 1312
1931 &fsf_req); 1313 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1932 if (retval) { 1314 0, NULL);
1933 ZFCP_LOG_INFO("error: Could not create exchange configuration " 1315 if (unlikely(IS_ERR(req))) {
1934 "data request for adapter %s.\n", 1316 retval = PTR_ERR(req);
1935 zfcp_get_busid_by_adapter(adapter)); 1317 goto out;
1936 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1937 lock_flags);
1938 return retval;
1939 } 1318 }
1940 1319
1941 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1320 sbale = zfcp_qdio_sbale_req(req);
1942 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1321 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1943 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1322 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1323 req->handler = zfcp_fsf_exchange_config_data_handler;
1944 1324
1945 fsf_req->qtcb->bottom.config.feature_selection = 1325 req->qtcb->bottom.config.feature_selection =
1946 FSF_FEATURE_CFDC | 1326 FSF_FEATURE_CFDC |
1947 FSF_FEATURE_LUN_SHARING | 1327 FSF_FEATURE_LUN_SHARING |
1948 FSF_FEATURE_NOTIFICATION_LOST | 1328 FSF_FEATURE_NOTIFICATION_LOST |
1949 FSF_FEATURE_UPDATE_ALERT; 1329 FSF_FEATURE_UPDATE_ALERT;
1950 1330
1951 if (data) 1331 if (data)
1952 fsf_req->data = (unsigned long) data; 1332 req->data = data;
1953 1333
1954 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); 1334 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1955 retval = zfcp_fsf_req_send(fsf_req); 1335 retval = zfcp_fsf_req_send(req);
1956 write_unlock_irqrestore(&adapter->request_queue.queue_lock, 1336out:
1957 lock_flags); 1337 spin_unlock(&adapter->req_q.lock);
1958 if (retval) 1338 if (!retval)
1959 ZFCP_LOG_INFO("error: Could not send exchange configuration " 1339 wait_event(req->completion_wq,
1960 "data command on the adapter %s\n", 1340 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1961 zfcp_get_busid_by_adapter(adapter));
1962 else
1963 wait_event(fsf_req->completion_wq,
1964 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1965 1341
1966 zfcp_fsf_req_free(fsf_req); 1342 zfcp_fsf_req_free(req);
1967 1343
1968 return retval; 1344 return retval;
1969} 1345}
1970 1346
1971/** 1347/**
1972 * zfcp_fsf_exchange_config_evaluate
1973 * @fsf_req: fsf_req which belongs to xchg config data request
1974 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1975 *
1976 * returns: -EIO on error, 0 otherwise
1977 */
1978static int
1979zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1980{
1981 struct fsf_qtcb_bottom_config *bottom;
1982 struct zfcp_adapter *adapter = fsf_req->adapter;
1983 struct Scsi_Host *shost = adapter->scsi_host;
1984
1985 bottom = &fsf_req->qtcb->bottom.config;
1986 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1987 bottom->low_qtcb_version, bottom->high_qtcb_version);
1988 adapter->fsf_lic_version = bottom->lic_version;
1989 adapter->adapter_features = bottom->adapter_features;
1990 adapter->connection_features = bottom->connection_features;
1991 adapter->peer_wwpn = 0;
1992 adapter->peer_wwnn = 0;
1993 adapter->peer_d_id = 0;
1994
1995 if (xchg_ok) {
1996
1997 if (fsf_req->data)
1998 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
1999 bottom, sizeof (struct fsf_qtcb_bottom_config));
2000
2001 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2002 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2003 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2004 fc_host_speed(shost) = bottom->fc_link_speed;
2005 fc_host_supported_classes(shost) =
2006 FC_COS_CLASS2 | FC_COS_CLASS3;
2007 adapter->hydra_version = bottom->adapter_type;
2008 if (fc_host_permanent_port_name(shost) == -1)
2009 fc_host_permanent_port_name(shost) =
2010 fc_host_port_name(shost);
2011 if (bottom->fc_topology == FSF_TOPO_P2P) {
2012 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2013 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2014 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2015 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2016 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2017 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2018 else if (bottom->fc_topology == FSF_TOPO_AL)
2019 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2020 else
2021 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2022 } else {
2023 fc_host_node_name(shost) = 0;
2024 fc_host_port_name(shost) = 0;
2025 fc_host_port_id(shost) = 0;
2026 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2027 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2028 adapter->hydra_version = 0;
2029 }
2030
2031 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2032 adapter->hardware_version = bottom->hardware_version;
2033 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2034 min(FC_SERIAL_NUMBER_SIZE, 17));
2035 EBCASC(fc_host_serial_number(shost),
2036 min(FC_SERIAL_NUMBER_SIZE, 17));
2037 }
2038
2039 if (fsf_req->erp_action)
2040 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2041 "characteristics:\n"
2042 "WWNN 0x%016Lx, WWPN 0x%016Lx, "
2043 "S_ID 0x%06x,\n"
2044 "adapter version 0x%x, "
2045 "LIC version 0x%x, "
2046 "FC link speed %d Gb/s\n",
2047 zfcp_get_busid_by_adapter(adapter),
2048 (wwn_t) fc_host_node_name(shost),
2049 (wwn_t) fc_host_port_name(shost),
2050 fc_host_port_id(shost),
2051 adapter->hydra_version,
2052 adapter->fsf_lic_version,
2053 fc_host_speed(shost));
2054 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2055 ZFCP_LOG_NORMAL("error: the adapter %s "
2056 "only supports newer control block "
2057 "versions in comparison to this device "
2058 "driver (try updated device driver)\n",
2059 zfcp_get_busid_by_adapter(adapter));
2060 zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
2061 return -EIO;
2062 }
2063 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2064 ZFCP_LOG_NORMAL("error: the adapter %s "
2065 "only supports older control block "
2066 "versions than this device driver uses"
2067 "(consider a microcode upgrade)\n",
2068 zfcp_get_busid_by_adapter(adapter));
2069 zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
2070 return -EIO;
2071 }
2072 return 0;
2073}
2074
2075/**
2076 * function: zfcp_fsf_exchange_config_data_handler
2077 *
2078 * purpose: is called for finished Exchange Configuration Data command
2079 *
2080 * returns:
2081 */
2082static int
2083zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2084{
2085 struct fsf_qtcb_bottom_config *bottom;
2086 struct zfcp_adapter *adapter = fsf_req->adapter;
2087 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2088
2089 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2090 return -EIO;
2091
2092 switch (qtcb->header.fsf_status) {
2093
2094 case FSF_GOOD:
2095 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2096 return -EIO;
2097
2098 switch (fc_host_port_type(adapter->scsi_host)) {
2099 case FC_PORTTYPE_PTP:
2100 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2101 "configuration detected at adapter %s\n"
2102 "Peer WWNN 0x%016llx, "
2103 "peer WWPN 0x%016llx, "
2104 "peer d_id 0x%06x\n",
2105 zfcp_get_busid_by_adapter(adapter),
2106 adapter->peer_wwnn,
2107 adapter->peer_wwpn,
2108 adapter->peer_d_id);
2109 break;
2110 case FC_PORTTYPE_NLPORT:
2111 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2112 "topology detected at adapter %s "
2113 "unsupported, shutting down adapter\n",
2114 zfcp_get_busid_by_adapter(adapter));
2115 zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
2116 return -EIO;
2117 case FC_PORTTYPE_NPORT:
2118 if (fsf_req->erp_action)
2119 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2120 "network detected at adapter "
2121 "%s.\n",
2122 zfcp_get_busid_by_adapter(adapter));
2123 break;
2124 default:
2125 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2126 "reported by the exchange "
2127 "configuration command for "
2128 "the adapter %s is not "
2129 "of a type known to the zfcp "
2130 "driver, shutting down adapter\n",
2131 zfcp_get_busid_by_adapter(adapter));
2132 zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
2133 return -EIO;
2134 }
2135 bottom = &qtcb->bottom.config;
2136 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2137 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2138 "allowed by the adapter %s "
2139 "is lower than the minimum "
2140 "required by the driver (%ld bytes).\n",
2141 bottom->max_qtcb_size,
2142 zfcp_get_busid_by_adapter(adapter),
2143 sizeof(struct fsf_qtcb));
2144 zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
2145 return -EIO;
2146 }
2147 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2148 &adapter->status);
2149 break;
2150 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2151 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2152 return -EIO;
2153
2154 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2155 &adapter->status);
2156
2157 zfcp_fsf_link_down_info_eval(fsf_req, 42,
2158 &qtcb->header.fsf_status_qual.link_down_info);
2159 break;
2160 default:
2161 zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
2162 return -EIO;
2163 }
2164 return 0;
2165}
2166
2167/**
2168 * zfcp_fsf_exchange_port_data - request information about local port 1348 * zfcp_fsf_exchange_port_data - request information about local port
2169 * @erp_action: ERP action for the adapter for which port data is requested 1349 * @erp_action: ERP action for the adapter for which port data is requested
1350 * Returns: 0 on success, error otherwise
2170 */ 1351 */
2171int 1352int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
2172zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
2173{ 1353{
2174 volatile struct qdio_buffer_element *sbale; 1354 volatile struct qdio_buffer_element *sbale;
2175 struct zfcp_fsf_req *fsf_req; 1355 struct zfcp_fsf_req *req;
2176 struct zfcp_adapter *adapter = erp_action->adapter; 1356 struct zfcp_adapter *adapter = erp_action->adapter;
2177 unsigned long lock_flags; 1357 int retval = -EIO;
2178 int retval;
2179 1358
2180 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) { 1359 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
2181 ZFCP_LOG_INFO("error: exchange port data "
2182 "command not supported by adapter %s\n",
2183 zfcp_get_busid_by_adapter(adapter));
2184 return -EOPNOTSUPP; 1360 return -EOPNOTSUPP;
2185 }
2186 1361
2187 /* setup new FSF request */ 1362 spin_lock(&adapter->req_q.lock);
2188 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 1363 if (!atomic_read(&adapter->req_q.count))
2189 ZFCP_REQ_AUTO_CLEANUP, 1364 goto out;
2190 adapter->pool.fsf_req_erp, 1365 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2191 &lock_flags, &fsf_req); 1366 ZFCP_REQ_AUTO_CLEANUP,
2192 if (retval) { 1367 adapter->pool.fsf_req_erp);
2193 ZFCP_LOG_INFO("error: Out of resources. Could not create an " 1368 if (unlikely(IS_ERR(req))) {
2194 "exchange port data request for " 1369 retval = PTR_ERR(req);
2195 "the adapter %s.\n", 1370 goto out;
2196 zfcp_get_busid_by_adapter(adapter));
2197 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2198 lock_flags);
2199 return retval;
2200 } 1371 }
2201 1372
2202 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1373 sbale = zfcp_qdio_sbale_req(req);
2203 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1374 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2204 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1375 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2205 1376
2206 erp_action->fsf_req = fsf_req; 1377 req->handler = zfcp_fsf_exchange_port_data_handler;
2207 fsf_req->erp_action = erp_action; 1378 req->erp_action = erp_action;
2208 zfcp_erp_start_timer(fsf_req); 1379 erp_action->fsf_req = req;
2209
2210 retval = zfcp_fsf_req_send(fsf_req);
2211 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2212 1380
1381 zfcp_fsf_start_erp_timer(req);
1382 retval = zfcp_fsf_req_send(req);
2213 if (retval) { 1383 if (retval) {
2214 ZFCP_LOG_INFO("error: Could not send an exchange port data " 1384 zfcp_fsf_req_free(req);
2215 "command on the adapter %s\n",
2216 zfcp_get_busid_by_adapter(adapter));
2217 zfcp_fsf_req_free(fsf_req);
2218 erp_action->fsf_req = NULL; 1385 erp_action->fsf_req = NULL;
2219 } 1386 }
2220 else 1387out:
2221 ZFCP_LOG_DEBUG("exchange port data request initiated " 1388 spin_unlock(&adapter->req_q.lock);
2222 "(adapter %s)\n",
2223 zfcp_get_busid_by_adapter(adapter));
2224 return retval; 1389 return retval;
2225} 1390}
2226 1391
2227
2228/** 1392/**
2229 * zfcp_fsf_exchange_port_data_sync - request information about local port 1393 * zfcp_fsf_exchange_port_data_sync - request information about local port
2230 * and wait until information is ready 1394 * @adapter: pointer to struct zfcp_adapter
1395 * @data: pointer to struct fsf_qtcb_bottom_port
1396 * Returns: 0 on success, error otherwise
2231 */ 1397 */
2232int 1398int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2233zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter, 1399 struct fsf_qtcb_bottom_port *data)
2234 struct fsf_qtcb_bottom_port *data)
2235{ 1400{
2236 volatile struct qdio_buffer_element *sbale; 1401 volatile struct qdio_buffer_element *sbale;
2237 struct zfcp_fsf_req *fsf_req; 1402 struct zfcp_fsf_req *req = NULL;
2238 unsigned long lock_flags; 1403 int retval = -EIO;
2239 int retval; 1404
2240 1405 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
2241 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2242 ZFCP_LOG_INFO("error: exchange port data "
2243 "command not supported by adapter %s\n",
2244 zfcp_get_busid_by_adapter(adapter));
2245 return -EOPNOTSUPP; 1406 return -EOPNOTSUPP;
2246 }
2247 1407
2248 /* setup new FSF request */ 1408 spin_lock(&adapter->req_q.lock);
2249 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 1409 if (!atomic_read(&adapter->req_q.count))
2250 0, NULL, &lock_flags, &fsf_req); 1410 goto out;
2251 if (retval) { 1411
2252 ZFCP_LOG_INFO("error: Out of resources. Could not create an " 1412 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
2253 "exchange port data request for " 1413 NULL);
2254 "the adapter %s.\n", 1414 if (unlikely(IS_ERR(req))) {
2255 zfcp_get_busid_by_adapter(adapter)); 1415 retval = PTR_ERR(req);
2256 write_unlock_irqrestore(&adapter->request_queue.queue_lock, 1416 goto out;
2257 lock_flags);
2258 return retval;
2259 } 1417 }
2260 1418
2261 if (data) 1419 if (data)
2262 fsf_req->data = (unsigned long) data; 1420 req->data = data;
2263 1421
2264 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1422 sbale = zfcp_qdio_sbale_req(req);
2265 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1423 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2266 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1424 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2267 1425
2268 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); 1426 req->handler = zfcp_fsf_exchange_port_data_handler;
2269 retval = zfcp_fsf_req_send(fsf_req); 1427 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2270 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); 1428 retval = zfcp_fsf_req_send(req);
2271 1429out:
2272 if (retval) 1430 spin_unlock(&adapter->req_q.lock);
2273 ZFCP_LOG_INFO("error: Could not send an exchange port data " 1431 if (!retval)
2274 "command on the adapter %s\n", 1432 wait_event(req->completion_wq,
2275 zfcp_get_busid_by_adapter(adapter)); 1433 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2276 else 1434 zfcp_fsf_req_free(req);
2277 wait_event(fsf_req->completion_wq,
2278 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2279
2280 zfcp_fsf_req_free(fsf_req);
2281
2282 return retval;
2283}
2284
2285/**
2286 * zfcp_fsf_exchange_port_evaluate
2287 * @fsf_req: fsf_req which belongs to xchg port data request
2288 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2289 */
2290static void
2291zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2292{
2293 struct zfcp_adapter *adapter;
2294 struct fsf_qtcb_bottom_port *bottom;
2295 struct Scsi_Host *shost;
2296
2297 adapter = fsf_req->adapter;
2298 bottom = &fsf_req->qtcb->bottom.port;
2299 shost = adapter->scsi_host;
2300
2301 if (fsf_req->data)
2302 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2303 sizeof(struct fsf_qtcb_bottom_port));
2304
2305 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2306 fc_host_permanent_port_name(shost) = bottom->wwpn;
2307 else
2308 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2309 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2310 fc_host_supported_speeds(shost) = bottom->supported_speed;
2311}
2312
2313/**
2314 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2315 * @fsf_req: pointer to struct zfcp_fsf_req
2316 */
2317static void
2318zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2319{
2320 struct zfcp_adapter *adapter;
2321 struct fsf_qtcb *qtcb;
2322
2323 adapter = fsf_req->adapter;
2324 qtcb = fsf_req->qtcb;
2325
2326 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2327 return;
2328
2329 switch (qtcb->header.fsf_status) {
2330 case FSF_GOOD:
2331 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
2332 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2333 break;
2334 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2335 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
2336 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2337 zfcp_fsf_link_down_info_eval(fsf_req, 43,
2338 &qtcb->header.fsf_status_qual.link_down_info);
2339 break;
2340 }
2341}
2342
2343
2344/*
2345 * function: zfcp_fsf_open_port
2346 *
2347 * purpose:
2348 *
2349 * returns: address of initiated FSF request
2350 * NULL - request could not be initiated
2351 */
2352int
2353zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2354{
2355 volatile struct qdio_buffer_element *sbale;
2356 struct zfcp_fsf_req *fsf_req;
2357 unsigned long lock_flags;
2358 int retval = 0;
2359
2360 /* setup new FSF request */
2361 retval = zfcp_fsf_req_create(erp_action->adapter,
2362 FSF_QTCB_OPEN_PORT_WITH_DID,
2363 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2364 erp_action->adapter->pool.fsf_req_erp,
2365 &lock_flags, &fsf_req);
2366 if (retval < 0) {
2367 ZFCP_LOG_INFO("error: Could not create open port request "
2368 "for port 0x%016Lx on adapter %s.\n",
2369 erp_action->port->wwpn,
2370 zfcp_get_busid_by_adapter(erp_action->adapter));
2371 goto out;
2372 }
2373
2374 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2375 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2376 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2377
2378 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2379 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2380 fsf_req->data = (unsigned long) erp_action->port;
2381 fsf_req->erp_action = erp_action;
2382 erp_action->fsf_req = fsf_req;
2383
2384 zfcp_erp_start_timer(fsf_req);
2385 retval = zfcp_fsf_req_send(fsf_req);
2386 if (retval) {
2387 ZFCP_LOG_INFO("error: Could not send open port request for "
2388 "port 0x%016Lx on adapter %s.\n",
2389 erp_action->port->wwpn,
2390 zfcp_get_busid_by_adapter(erp_action->adapter));
2391 zfcp_fsf_req_free(fsf_req);
2392 erp_action->fsf_req = NULL;
2393 goto out;
2394 }
2395 1435
2396 ZFCP_LOG_DEBUG("open port request initiated "
2397 "(adapter %s, port 0x%016Lx)\n",
2398 zfcp_get_busid_by_adapter(erp_action->adapter),
2399 erp_action->port->wwpn);
2400 out:
2401 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2402 lock_flags);
2403 return retval; 1436 return retval;
2404} 1437}
2405 1438
2406/* 1439static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
2407 * function: zfcp_fsf_open_port_handler
2408 *
2409 * purpose: is called for finished Open Port command
2410 *
2411 * returns:
2412 */
2413static int
2414zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2415{ 1440{
2416 int retval = -EINVAL; 1441 struct zfcp_port *port = req->data;
2417 struct zfcp_port *port; 1442 struct fsf_qtcb_header *header = &req->qtcb->header;
2418 struct fsf_plogi *plogi; 1443 struct fsf_plogi *plogi;
2419 struct fsf_qtcb_header *header;
2420 u16 subtable, rule, counter;
2421 1444
2422 port = (struct zfcp_port *) fsf_req->data; 1445 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2423 header = &fsf_req->qtcb->header;
2424
2425 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2426 /* don't change port status in our bookkeeping */
2427 goto skip_fsfstatus; 1446 goto skip_fsfstatus;
2428 }
2429 1447
2430 /* evaluate FSF status in QTCB */
2431 switch (header->fsf_status) { 1448 switch (header->fsf_status) {
2432
2433 case FSF_PORT_ALREADY_OPEN: 1449 case FSF_PORT_ALREADY_OPEN:
2434 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2435 "is already open.\n",
2436 port->wwpn, zfcp_get_busid_by_port(port));
2437 /*
2438 * This is a bug, however operation should continue normally
2439 * if it is simply ignored
2440 */
2441 break; 1450 break;
2442
2443 case FSF_ACCESS_DENIED: 1451 case FSF_ACCESS_DENIED:
2444 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx " 1452 zfcp_fsf_access_denied_port(req, port);
2445 "on adapter %s\n",
2446 port->wwpn, zfcp_get_busid_by_port(port));
2447 for (counter = 0; counter < 2; counter++) {
2448 subtable = header->fsf_status_qual.halfword[counter * 2];
2449 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2450 switch (subtable) {
2451 case FSF_SQ_CFDC_SUBTABLE_OS:
2452 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2453 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2454 case FSF_SQ_CFDC_SUBTABLE_LUN:
2455 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2456 zfcp_act_subtable_type[subtable], rule);
2457 break;
2458 }
2459 }
2460 zfcp_erp_port_access_denied(port, 57, fsf_req);
2461 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2462 break; 1453 break;
2463
2464 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: 1454 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2465 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. " 1455 dev_warn(&req->adapter->ccw_device->dev,
2466 "The remote port 0x%016Lx on adapter %s " 1456 "The adapter is out of resources. The remote port "
2467 "could not be opened. Disabling it.\n", 1457 "0x%016Lx could not be opened, disabling it.\n",
2468 port->wwpn, zfcp_get_busid_by_port(port)); 1458 port->wwpn);
2469 zfcp_erp_port_failed(port, 31, fsf_req); 1459 zfcp_erp_port_failed(port, 31, req);
2470 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1460 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2471 break; 1461 break;
2472
2473 case FSF_ADAPTER_STATUS_AVAILABLE: 1462 case FSF_ADAPTER_STATUS_AVAILABLE:
2474 switch (header->fsf_status_qual.word[0]) { 1463 switch (header->fsf_status_qual.word[0]) {
2475 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 1464 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2476 /* ERP strategy will escalate */
2477 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2478 break;
2479 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 1465 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2480 /* ERP strategy will escalate */ 1466 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2482 break; 1467 break;
2483 case FSF_SQ_NO_RETRY_POSSIBLE: 1468 case FSF_SQ_NO_RETRY_POSSIBLE:
2484 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on " 1469 dev_warn(&req->adapter->ccw_device->dev,
2485 "adapter %s could not be opened. " 1470 "The remote port 0x%016Lx could not be "
2486 "Disabling it.\n", 1471 "opened. Disabling it.\n", port->wwpn);
2487 port->wwpn, 1472 zfcp_erp_port_failed(port, 32, req);
2488 zfcp_get_busid_by_port(port)); 1473 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2489 zfcp_erp_port_failed(port, 32, fsf_req);
2490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2491 break;
2492 default:
2493 ZFCP_LOG_NORMAL
2494 ("bug: Wrong status qualifier 0x%x arrived.\n",
2495 header->fsf_status_qual.word[0]);
2496 break; 1474 break;
2497 } 1475 }
2498 break; 1476 break;
2499
2500 case FSF_GOOD: 1477 case FSF_GOOD:
2501 /* save port handle assigned by FSF */
2502 port->handle = header->port_handle; 1478 port->handle = header->port_handle;
2503 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2504 "was opened, it's port handle is 0x%x\n",
2505 port->wwpn, zfcp_get_busid_by_port(port),
2506 port->handle);
2507 /* mark port as open */
2508 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | 1479 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2509 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); 1480 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2510 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | 1481 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2511 ZFCP_STATUS_COMMON_ACCESS_BOXED, 1482 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2512 &port->status); 1483 &port->status);
2513 retval = 0;
2514 /* check whether D_ID has changed during open */ 1484 /* check whether D_ID has changed during open */
2515 /* 1485 /*
2516 * FIXME: This check is not airtight, as the FCP channel does 1486 * FIXME: This check is not airtight, as the FCP channel does
@@ -2526,320 +1496,168 @@ zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2526 * another GID_PN straight after a port has been opened. 1496 * another GID_PN straight after a port has been opened.
2527 * Alternately, an ADISC/PDISC ELS should suffice, as well. 1497 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2528 */ 1498 */
2529 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els; 1499 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN)
2530 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status)) 1500 break;
2531 { 1501
2532 if (fsf_req->qtcb->bottom.support.els1_length < 1502 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
2533 sizeof (struct fsf_plogi)) { 1503 if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
2534 ZFCP_LOG_INFO( 1504 if (plogi->serv_param.wwpn != port->wwpn)
2535 "warning: insufficient length of " 1505 atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
2536 "PLOGI payload (%i)\n", 1506 &port->status);
2537 fsf_req->qtcb->bottom.support.els1_length); 1507 else {
2538 /* skip sanity check and assume wwpn is ok */ 1508 port->wwnn = plogi->serv_param.wwnn;
2539 } else { 1509 zfcp_fc_plogi_evaluate(port, plogi);
2540 if (plogi->serv_param.wwpn != port->wwpn) {
2541 ZFCP_LOG_INFO("warning: d_id of port "
2542 "0x%016Lx changed during "
2543 "open\n", port->wwpn);
2544 atomic_clear_mask(
2545 ZFCP_STATUS_PORT_DID_DID,
2546 &port->status);
2547 } else {
2548 port->wwnn = plogi->serv_param.wwnn;
2549 zfcp_plogi_evaluate(port, plogi);
2550 }
2551 } 1510 }
2552 } 1511 }
2553 break; 1512 break;
2554
2555 case FSF_UNKNOWN_OP_SUBTYPE: 1513 case FSF_UNKNOWN_OP_SUBTYPE:
2556 /* should never occure, subtype not set in zfcp_fsf_open_port */ 1514 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2557 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2558 "op_subtype=0x%x)\n",
2559 zfcp_get_busid_by_port(port),
2560 fsf_req->qtcb->bottom.support.operation_subtype);
2561 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2562 break;
2563
2564 default:
2565 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2566 "(debug info 0x%x)\n",
2567 header->fsf_status);
2568 break; 1515 break;
2569 } 1516 }
2570 1517
2571 skip_fsfstatus: 1518skip_fsfstatus:
2572 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status); 1519 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2573 return retval;
2574} 1520}
2575 1521
2576/* 1522/**
2577 * function: zfcp_fsf_close_port 1523 * zfcp_fsf_open_port - create and send open port request
2578 * 1524 * @erp_action: pointer to struct zfcp_erp_action
2579 * purpose: submit FSF command "close port" 1525 * Returns: 0 on success, error otherwise
2580 *
2581 * returns: address of initiated FSF request
2582 * NULL - request could not be initiated
2583 */ 1526 */
2584int 1527int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2585zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2586{ 1528{
2587 volatile struct qdio_buffer_element *sbale; 1529 volatile struct qdio_buffer_element *sbale;
2588 struct zfcp_fsf_req *fsf_req; 1530 struct zfcp_adapter *adapter = erp_action->adapter;
2589 unsigned long lock_flags; 1531 struct zfcp_fsf_req *req;
2590 int retval = 0; 1532 int retval = -EIO;
2591 1533
2592 /* setup new FSF request */ 1534 spin_lock(&adapter->req_q.lock);
2593 retval = zfcp_fsf_req_create(erp_action->adapter, 1535 if (zfcp_fsf_req_sbal_get(adapter))
2594 FSF_QTCB_CLOSE_PORT, 1536 goto out;
2595 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, 1537
2596 erp_action->adapter->pool.fsf_req_erp, 1538 req = zfcp_fsf_req_create(adapter,
2597 &lock_flags, &fsf_req); 1539 FSF_QTCB_OPEN_PORT_WITH_DID,
2598 if (retval < 0) { 1540 ZFCP_REQ_AUTO_CLEANUP,
2599 ZFCP_LOG_INFO("error: Could not create a close port request " 1541 adapter->pool.fsf_req_erp);
2600 "for port 0x%016Lx on adapter %s.\n", 1542 if (unlikely(IS_ERR(req))) {
2601 erp_action->port->wwpn, 1543 retval = PTR_ERR(req);
2602 zfcp_get_busid_by_adapter(erp_action->adapter));
2603 goto out; 1544 goto out;
2604 } 1545 }
2605 1546
2606 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1547 sbale = zfcp_qdio_sbale_req(req);
2607 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1548 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2608 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1549 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2609 1550
2610 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status); 1551 req->handler = zfcp_fsf_open_port_handler;
2611 fsf_req->data = (unsigned long) erp_action->port; 1552 req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2612 fsf_req->erp_action = erp_action; 1553 req->data = erp_action->port;
2613 fsf_req->qtcb->header.port_handle = erp_action->port->handle; 1554 req->erp_action = erp_action;
2614 fsf_req->erp_action = erp_action; 1555 erp_action->fsf_req = req;
2615 erp_action->fsf_req = fsf_req; 1556 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2616 1557
2617 zfcp_erp_start_timer(fsf_req); 1558 zfcp_fsf_start_erp_timer(req);
2618 retval = zfcp_fsf_req_send(fsf_req); 1559 retval = zfcp_fsf_req_send(req);
2619 if (retval) { 1560 if (retval) {
2620 ZFCP_LOG_INFO("error: Could not send a close port request for " 1561 zfcp_fsf_req_free(req);
2621 "port 0x%016Lx on adapter %s.\n",
2622 erp_action->port->wwpn,
2623 zfcp_get_busid_by_adapter(erp_action->adapter));
2624 zfcp_fsf_req_free(fsf_req);
2625 erp_action->fsf_req = NULL; 1562 erp_action->fsf_req = NULL;
2626 goto out;
2627 } 1563 }
2628 1564out:
2629 ZFCP_LOG_TRACE("close port request initiated " 1565 spin_unlock(&adapter->req_q.lock);
2630 "(adapter %s, port 0x%016Lx)\n",
2631 zfcp_get_busid_by_adapter(erp_action->adapter),
2632 erp_action->port->wwpn);
2633 out:
2634 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2635 lock_flags);
2636 return retval; 1566 return retval;
2637} 1567}
2638 1568
2639/* 1569static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
2640 * function: zfcp_fsf_close_port_handler
2641 *
2642 * purpose: is called for finished Close Port FSF command
2643 *
2644 * returns:
2645 */
2646static int
2647zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2648{ 1570{
2649 int retval = -EINVAL; 1571 struct zfcp_port *port = req->data;
2650 struct zfcp_port *port;
2651 1572
2652 port = (struct zfcp_port *) fsf_req->data; 1573 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2653
2654 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2655 /* don't change port status in our bookkeeping */
2656 goto skip_fsfstatus; 1574 goto skip_fsfstatus;
2657 }
2658
2659 /* evaluate FSF status in QTCB */
2660 switch (fsf_req->qtcb->header.fsf_status) {
2661 1575
1576 switch (req->qtcb->header.fsf_status) {
2662 case FSF_PORT_HANDLE_NOT_VALID: 1577 case FSF_PORT_HANDLE_NOT_VALID:
2663 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " 1578 zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
2664 "0x%016Lx on adapter %s invalid. This may happen " 1579 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2665 "occasionally.\n", port->handle,
2666 port->wwpn, zfcp_get_busid_by_port(port));
2667 ZFCP_LOG_DEBUG("status qualifier:\n");
2668 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2669 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2670 sizeof (union fsf_status_qual));
2671 zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
2672 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2673 break; 1580 break;
2674
2675 case FSF_ADAPTER_STATUS_AVAILABLE: 1581 case FSF_ADAPTER_STATUS_AVAILABLE:
2676 /* Note: FSF has actually closed the port in this case.
2677 * The status code is just daft. Fingers crossed for a change
2678 */
2679 retval = 0;
2680 break; 1582 break;
2681
2682 case FSF_GOOD: 1583 case FSF_GOOD:
2683 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, " 1584 zfcp_erp_modify_port_status(port, 33, req,
2684 "port handle 0x%x\n", port->wwpn,
2685 zfcp_get_busid_by_port(port), port->handle);
2686 zfcp_erp_modify_port_status(port, 33, fsf_req,
2687 ZFCP_STATUS_COMMON_OPEN, 1585 ZFCP_STATUS_COMMON_OPEN,
2688 ZFCP_CLEAR); 1586 ZFCP_CLEAR);
2689 retval = 0;
2690 break;
2691
2692 default:
2693 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2694 "(debug info 0x%x)\n",
2695 fsf_req->qtcb->header.fsf_status);
2696 break; 1587 break;
2697 } 1588 }
2698 1589
2699 skip_fsfstatus: 1590skip_fsfstatus:
2700 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status); 1591 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2701 return retval;
2702} 1592}
2703 1593
2704/* 1594/**
2705 * function: zfcp_fsf_close_physical_port 1595 * zfcp_fsf_close_port - create and send close port request
2706 * 1596 * @erp_action: pointer to struct zfcp_erp_action
2707 * purpose: submit FSF command "close physical port" 1597 * Returns: 0 on success, error otherwise
2708 *
2709 * returns: address of initiated FSF request
2710 * NULL - request could not be initiated
2711 */ 1598 */
2712int 1599int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2713zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2714{ 1600{
2715 volatile struct qdio_buffer_element *sbale; 1601 volatile struct qdio_buffer_element *sbale;
2716 struct zfcp_fsf_req *fsf_req; 1602 struct zfcp_adapter *adapter = erp_action->adapter;
2717 unsigned long lock_flags; 1603 struct zfcp_fsf_req *req;
2718 int retval = 0; 1604 int retval = -EIO;
2719
2720 /* setup new FSF request */
2721 retval = zfcp_fsf_req_create(erp_action->adapter,
2722 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2723 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2724 erp_action->adapter->pool.fsf_req_erp,
2725 &lock_flags, &fsf_req);
2726 if (retval < 0) {
2727 ZFCP_LOG_INFO("error: Could not create close physical port "
2728 "request (adapter %s, port 0x%016Lx)\n",
2729 zfcp_get_busid_by_adapter(erp_action->adapter),
2730 erp_action->port->wwpn);
2731 1605
1606 spin_lock(&adapter->req_q.lock);
1607 if (zfcp_fsf_req_sbal_get(adapter))
1608 goto out;
1609
1610 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1611 ZFCP_REQ_AUTO_CLEANUP,
1612 adapter->pool.fsf_req_erp);
1613 if (unlikely(IS_ERR(req))) {
1614 retval = PTR_ERR(req);
2732 goto out; 1615 goto out;
2733 } 1616 }
2734 1617
2735 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1618 sbale = zfcp_qdio_sbale_req(req);
2736 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1619 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2737 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1620 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2738 1621
2739 /* mark port as being closed */ 1622 req->handler = zfcp_fsf_close_port_handler;
2740 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, 1623 req->data = erp_action->port;
2741 &erp_action->port->status); 1624 req->erp_action = erp_action;
2742 /* save a pointer to this port */ 1625 req->qtcb->header.port_handle = erp_action->port->handle;
2743 fsf_req->data = (unsigned long) erp_action->port; 1626 erp_action->fsf_req = req;
2744 fsf_req->qtcb->header.port_handle = erp_action->port->handle; 1627 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2745 fsf_req->erp_action = erp_action; 1628
2746 erp_action->fsf_req = fsf_req; 1629 zfcp_fsf_start_erp_timer(req);
2747 1630 retval = zfcp_fsf_req_send(req);
2748 zfcp_erp_start_timer(fsf_req);
2749 retval = zfcp_fsf_req_send(fsf_req);
2750 if (retval) { 1631 if (retval) {
2751 ZFCP_LOG_INFO("error: Could not send close physical port " 1632 zfcp_fsf_req_free(req);
2752 "request (adapter %s, port 0x%016Lx)\n",
2753 zfcp_get_busid_by_adapter(erp_action->adapter),
2754 erp_action->port->wwpn);
2755 zfcp_fsf_req_free(fsf_req);
2756 erp_action->fsf_req = NULL; 1633 erp_action->fsf_req = NULL;
2757 goto out;
2758 } 1634 }
2759 1635out:
2760 ZFCP_LOG_TRACE("close physical port request initiated " 1636 spin_unlock(&adapter->req_q.lock);
2761 "(adapter %s, port 0x%016Lx)\n",
2762 zfcp_get_busid_by_adapter(erp_action->adapter),
2763 erp_action->port->wwpn);
2764 out:
2765 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2766 lock_flags);
2767 return retval; 1637 return retval;
2768} 1638}
2769 1639
2770/* 1640static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
2771 * function: zfcp_fsf_close_physical_port_handler
2772 *
2773 * purpose: is called for finished Close Physical Port FSF command
2774 *
2775 * returns:
2776 */
2777static int
2778zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2779{ 1641{
2780 int retval = -EINVAL; 1642 struct zfcp_port *port = req->data;
2781 struct zfcp_port *port; 1643 struct fsf_qtcb_header *header = &req->qtcb->header;
2782 struct zfcp_unit *unit; 1644 struct zfcp_unit *unit;
2783 struct fsf_qtcb_header *header;
2784 u16 subtable, rule, counter;
2785 1645
2786 port = (struct zfcp_port *) fsf_req->data; 1646 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2787 header = &fsf_req->qtcb->header;
2788
2789 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2790 /* don't change port status in our bookkeeping */
2791 goto skip_fsfstatus; 1647 goto skip_fsfstatus;
2792 }
2793 1648
2794 /* evaluate FSF status in QTCB */
2795 switch (header->fsf_status) { 1649 switch (header->fsf_status) {
2796
2797 case FSF_PORT_HANDLE_NOT_VALID: 1650 case FSF_PORT_HANDLE_NOT_VALID:
2798 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid" 1651 zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
2799 "(adapter %s, port 0x%016Lx). " 1652 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2800 "This may happen occasionally.\n",
2801 port->handle,
2802 zfcp_get_busid_by_port(port),
2803 port->wwpn);
2804 ZFCP_LOG_DEBUG("status qualifier:\n");
2805 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2806 (char *) &header->fsf_status_qual,
2807 sizeof (union fsf_status_qual));
2808 zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
2809 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2810 break; 1653 break;
2811
2812 case FSF_ACCESS_DENIED: 1654 case FSF_ACCESS_DENIED:
2813 ZFCP_LOG_NORMAL("Access denied, cannot close " 1655 zfcp_fsf_access_denied_port(req, port);
2814 "physical port 0x%016Lx on adapter %s\n",
2815 port->wwpn, zfcp_get_busid_by_port(port));
2816 for (counter = 0; counter < 2; counter++) {
2817 subtable = header->fsf_status_qual.halfword[counter * 2];
2818 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2819 switch (subtable) {
2820 case FSF_SQ_CFDC_SUBTABLE_OS:
2821 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2822 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2823 case FSF_SQ_CFDC_SUBTABLE_LUN:
2824 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2825 zfcp_act_subtable_type[subtable], rule);
2826 break;
2827 }
2828 }
2829 zfcp_erp_port_access_denied(port, 58, fsf_req);
2830 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2831 break; 1656 break;
2832
2833 case FSF_PORT_BOXED: 1657 case FSF_PORT_BOXED:
2834 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter " 1658 zfcp_erp_port_boxed(port, 50, req);
2835 "%s needs to be reopened but it was attempted " 1659 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2836 "to close it physically.\n", 1660 ZFCP_STATUS_FSFREQ_RETRY;
2837 port->wwpn,
2838 zfcp_get_busid_by_port(port));
2839 zfcp_erp_port_boxed(port, 50, fsf_req);
2840 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2841 ZFCP_STATUS_FSFREQ_RETRY;
2842
2843 /* can't use generic zfcp_erp_modify_port_status because 1661 /* can't use generic zfcp_erp_modify_port_status because
2844 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ 1662 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2845 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); 1663 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
@@ -2847,154 +1665,88 @@ zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2847 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, 1665 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2848 &unit->status); 1666 &unit->status);
2849 break; 1667 break;
2850
2851 case FSF_ADAPTER_STATUS_AVAILABLE: 1668 case FSF_ADAPTER_STATUS_AVAILABLE:
2852 switch (header->fsf_status_qual.word[0]) { 1669 switch (header->fsf_status_qual.word[0]) {
2853 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 1670 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2854 /* This will now be escalated by ERP */ 1671 /* fall through */
2855 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2856 break;
2857 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 1672 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2858 /* ERP strategy will escalate */ 1673 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2860 break;
2861 default:
2862 ZFCP_LOG_NORMAL
2863 ("bug: Wrong status qualifier 0x%x arrived.\n",
2864 header->fsf_status_qual.word[0]);
2865 break; 1674 break;
2866 } 1675 }
2867 break; 1676 break;
2868
2869 case FSF_GOOD: 1677 case FSF_GOOD:
2870 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2871 "physically closed, port handle 0x%x\n",
2872 port->wwpn,
2873 zfcp_get_busid_by_port(port), port->handle);
2874 /* can't use generic zfcp_erp_modify_port_status because 1678 /* can't use generic zfcp_erp_modify_port_status because
2875 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port 1679 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2876 */ 1680 */
2877 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); 1681 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2878 list_for_each_entry(unit, &port->unit_list_head, list) 1682 list_for_each_entry(unit, &port->unit_list_head, list)
2879 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); 1683 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2880 retval = 0; 1684 &unit->status);
2881 break;
2882
2883 default:
2884 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2885 "(debug info 0x%x)\n",
2886 header->fsf_status);
2887 break; 1685 break;
2888 } 1686 }
2889 1687skip_fsfstatus:
2890 skip_fsfstatus:
2891 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); 1688 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2892 return retval;
2893} 1689}
2894 1690
2895/* 1691/**
2896 * function: zfcp_fsf_open_unit 1692 * zfcp_fsf_close_physical_port - close physical port
2897 * 1693 * @erp_action: pointer to struct zfcp_erp_action
2898 * purpose: 1694 * Returns: 0 on success
2899 *
2900 * returns:
2901 *
2902 * assumptions: This routine does not check whether the associated
2903 * remote port has already been opened. This should be
2904 * done by calling routines. Otherwise some status
2905 * may be presented by FSF
2906 */ 1695 */
2907int 1696int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2908zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2909{ 1697{
2910 volatile struct qdio_buffer_element *sbale; 1698 volatile struct qdio_buffer_element *sbale;
2911 struct zfcp_fsf_req *fsf_req; 1699 struct zfcp_adapter *adapter = erp_action->adapter;
2912 unsigned long lock_flags; 1700 struct zfcp_fsf_req *req;
2913 int retval = 0; 1701 int retval = -EIO;
2914 1702
2915 /* setup new FSF request */ 1703 spin_lock(&adapter->req_q.lock);
2916 retval = zfcp_fsf_req_create(erp_action->adapter, 1704 if (zfcp_fsf_req_sbal_get(adapter))
2917 FSF_QTCB_OPEN_LUN, 1705 goto out;
2918 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, 1706
2919 erp_action->adapter->pool.fsf_req_erp, 1707 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
2920 &lock_flags, &fsf_req); 1708 ZFCP_REQ_AUTO_CLEANUP,
2921 if (retval < 0) { 1709 adapter->pool.fsf_req_erp);
2922 ZFCP_LOG_INFO("error: Could not create open unit request for " 1710 if (unlikely(IS_ERR(req))) {
2923 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", 1711 retval = PTR_ERR(req);
2924 erp_action->unit->fcp_lun,
2925 erp_action->unit->port->wwpn,
2926 zfcp_get_busid_by_adapter(erp_action->adapter));
2927 goto out; 1712 goto out;
2928 } 1713 }
2929 1714
2930 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1715 sbale = zfcp_qdio_sbale_req(req);
2931 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1716 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2932 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1717 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2933 1718
2934 fsf_req->qtcb->header.port_handle = erp_action->port->handle; 1719 req->data = erp_action->port;
2935 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun; 1720 req->qtcb->header.port_handle = erp_action->port->handle;
2936 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE)) 1721 req->erp_action = erp_action;
2937 fsf_req->qtcb->bottom.support.option = 1722 req->handler = zfcp_fsf_close_physical_port_handler;
2938 FSF_OPEN_LUN_SUPPRESS_BOXING; 1723 erp_action->fsf_req = req;
2939 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status); 1724 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2940 fsf_req->data = (unsigned long) erp_action->unit; 1725 &erp_action->port->status);
2941 fsf_req->erp_action = erp_action;
2942 erp_action->fsf_req = fsf_req;
2943 1726
2944 zfcp_erp_start_timer(fsf_req); 1727 zfcp_fsf_start_erp_timer(req);
2945 retval = zfcp_fsf_req_send(erp_action->fsf_req); 1728 retval = zfcp_fsf_req_send(req);
2946 if (retval) { 1729 if (retval) {
2947 ZFCP_LOG_INFO("error: Could not send an open unit request " 1730 zfcp_fsf_req_free(req);
2948 "on the adapter %s, port 0x%016Lx for "
2949 "unit 0x%016Lx\n",
2950 zfcp_get_busid_by_adapter(erp_action->adapter),
2951 erp_action->port->wwpn,
2952 erp_action->unit->fcp_lun);
2953 zfcp_fsf_req_free(fsf_req);
2954 erp_action->fsf_req = NULL; 1731 erp_action->fsf_req = NULL;
2955 goto out;
2956 } 1732 }
2957 1733out:
2958 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, " 1734 spin_unlock(&adapter->req_q.lock);
2959 "port 0x%016Lx, unit 0x%016Lx)\n",
2960 zfcp_get_busid_by_adapter(erp_action->adapter),
2961 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2962 out:
2963 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2964 lock_flags);
2965 return retval; 1735 return retval;
2966} 1736}
2967 1737
2968/* 1738static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
2969 * function: zfcp_fsf_open_unit_handler
2970 *
2971 * purpose: is called for finished Open LUN command
2972 *
2973 * returns:
2974 */
2975static int
2976zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2977{ 1739{
2978 int retval = -EINVAL; 1740 struct zfcp_adapter *adapter = req->adapter;
2979 struct zfcp_adapter *adapter; 1741 struct zfcp_unit *unit = req->data;
2980 struct zfcp_unit *unit; 1742 struct fsf_qtcb_header *header = &req->qtcb->header;
2981 struct fsf_qtcb_header *header; 1743 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
2982 struct fsf_qtcb_bottom_support *bottom; 1744 struct fsf_queue_designator *queue_designator =
2983 struct fsf_queue_designator *queue_designator; 1745 &header->fsf_status_qual.fsf_queue_designator;
2984 u16 subtable, rule, counter;
2985 int exclusive, readwrite; 1746 int exclusive, readwrite;
2986 1747
2987 unit = (struct zfcp_unit *) fsf_req->data; 1748 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2988
2989 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2990 /* don't change unit status in our bookkeeping */
2991 goto skip_fsfstatus; 1749 goto skip_fsfstatus;
2992 }
2993
2994 adapter = fsf_req->adapter;
2995 header = &fsf_req->qtcb->header;
2996 bottom = &fsf_req->qtcb->bottom.support;
2997 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2998 1750
2999 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | 1751 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3000 ZFCP_STATUS_COMMON_ACCESS_BOXED | 1752 ZFCP_STATUS_COMMON_ACCESS_BOXED |
@@ -3002,155 +1754,65 @@ zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3002 ZFCP_STATUS_UNIT_READONLY, 1754 ZFCP_STATUS_UNIT_READONLY,
3003 &unit->status); 1755 &unit->status);
3004 1756
3005 /* evaluate FSF status in QTCB */
3006 switch (header->fsf_status) { 1757 switch (header->fsf_status) {
3007 1758
3008 case FSF_PORT_HANDLE_NOT_VALID: 1759 case FSF_PORT_HANDLE_NOT_VALID:
3009 ZFCP_LOG_INFO("Temporary port identifier 0x%x " 1760 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
3010 "for port 0x%016Lx on adapter %s invalid " 1761 /* fall through */
3011 "This may happen occasionally\n",
3012 unit->port->handle,
3013 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3014 ZFCP_LOG_DEBUG("status qualifier:\n");
3015 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3016 (char *) &header->fsf_status_qual,
3017 sizeof (union fsf_status_qual));
3018 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
3019 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3020 break;
3021
3022 case FSF_LUN_ALREADY_OPEN: 1762 case FSF_LUN_ALREADY_OPEN:
3023 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3024 "remote port 0x%016Lx on adapter %s twice.\n",
3025 unit->fcp_lun,
3026 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3027 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3028 break; 1763 break;
3029
3030 case FSF_ACCESS_DENIED: 1764 case FSF_ACCESS_DENIED:
3031 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on " 1765 zfcp_fsf_access_denied_unit(req, unit);
3032 "remote port 0x%016Lx on adapter %s\n",
3033 unit->fcp_lun, unit->port->wwpn,
3034 zfcp_get_busid_by_unit(unit));
3035 for (counter = 0; counter < 2; counter++) {
3036 subtable = header->fsf_status_qual.halfword[counter * 2];
3037 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3038 switch (subtable) {
3039 case FSF_SQ_CFDC_SUBTABLE_OS:
3040 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3041 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3042 case FSF_SQ_CFDC_SUBTABLE_LUN:
3043 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3044 zfcp_act_subtable_type[subtable], rule);
3045 break;
3046 }
3047 }
3048 zfcp_erp_unit_access_denied(unit, 59, fsf_req);
3049 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); 1766 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3050 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); 1767 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3051 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3052 break; 1768 break;
3053
3054 case FSF_PORT_BOXED: 1769 case FSF_PORT_BOXED:
3055 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " 1770 zfcp_erp_port_boxed(unit->port, 51, req);
3056 "needs to be reopened\n", 1771 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3057 unit->port->wwpn, zfcp_get_busid_by_unit(unit)); 1772 ZFCP_STATUS_FSFREQ_RETRY;
3058 zfcp_erp_port_boxed(unit->port, 51, fsf_req);
3059 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3060 ZFCP_STATUS_FSFREQ_RETRY;
3061 break; 1773 break;
3062
3063 case FSF_LUN_SHARING_VIOLATION: 1774 case FSF_LUN_SHARING_VIOLATION:
3064 if (header->fsf_status_qual.word[0] != 0) { 1775 if (header->fsf_status_qual.word[0])
3065 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port " 1776 dev_warn(&adapter->ccw_device->dev,
3066 "with WWPN 0x%Lx " 1777 "FCP-LUN 0x%Lx at the remote port "
3067 "connected to the adapter %s " 1778 "with WWPN 0x%Lx "
3068 "is already in use in LPAR%d, CSS%d\n", 1779 "connected to the adapter "
3069 unit->fcp_lun, 1780 "is already in use in LPAR%d, CSS%d.\n",
3070 unit->port->wwpn, 1781 unit->fcp_lun,
3071 zfcp_get_busid_by_unit(unit), 1782 unit->port->wwpn,
3072 queue_designator->hla, 1783 queue_designator->hla,
3073 queue_designator->cssid); 1784 queue_designator->cssid);
3074 } else { 1785 else
3075 subtable = header->fsf_status_qual.halfword[4]; 1786 zfcp_act_eval_err(adapter,
3076 rule = header->fsf_status_qual.halfword[5]; 1787 header->fsf_status_qual.word[2]);
3077 switch (subtable) { 1788 zfcp_erp_unit_access_denied(unit, 60, req);
3078 case FSF_SQ_CFDC_SUBTABLE_OS:
3079 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3080 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3081 case FSF_SQ_CFDC_SUBTABLE_LUN:
3082 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3083 "remote port with WWPN 0x%Lx "
3084 "connected to the adapter %s "
3085 "is denied (%s rule %d)\n",
3086 unit->fcp_lun,
3087 unit->port->wwpn,
3088 zfcp_get_busid_by_unit(unit),
3089 zfcp_act_subtable_type[subtable],
3090 rule);
3091 break;
3092 }
3093 }
3094 ZFCP_LOG_DEBUG("status qualifier:\n");
3095 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3096 (char *) &header->fsf_status_qual,
3097 sizeof (union fsf_status_qual));
3098 zfcp_erp_unit_access_denied(unit, 60, fsf_req);
3099 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); 1789 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3100 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); 1790 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3101 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1791 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3102 break; 1792 break;
3103
3104 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: 1793 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3105 ZFCP_LOG_INFO("error: The adapter ran out of resources. " 1794 dev_warn(&adapter->ccw_device->dev,
3106 "There is no handle (temporary port identifier) " 1795 "The adapter ran out of resources. There is no "
3107 "available for unit 0x%016Lx on port 0x%016Lx " 1796 "handle available for unit 0x%016Lx on port 0x%016Lx.",
3108 "on adapter %s\n", 1797 unit->fcp_lun, unit->port->wwpn);
3109 unit->fcp_lun, 1798 zfcp_erp_unit_failed(unit, 34, req);
3110 unit->port->wwpn, 1799 /* fall through */
3111 zfcp_get_busid_by_unit(unit)); 1800 case FSF_INVALID_COMMAND_OPTION:
3112 zfcp_erp_unit_failed(unit, 34, fsf_req); 1801 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3113 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3114 break; 1802 break;
3115
3116 case FSF_ADAPTER_STATUS_AVAILABLE: 1803 case FSF_ADAPTER_STATUS_AVAILABLE:
3117 switch (header->fsf_status_qual.word[0]) { 1804 switch (header->fsf_status_qual.word[0]) {
3118 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 1805 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3119 /* Re-establish link to port */
3120 zfcp_test_link(unit->port); 1806 zfcp_test_link(unit->port);
3121 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1807 /* fall through */
3122 break;
3123 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 1808 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3124 /* ERP strategy will escalate */ 1809 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3125 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3126 break; 1810 break;
3127 default:
3128 ZFCP_LOG_NORMAL
3129 ("bug: Wrong status qualifier 0x%x arrived.\n",
3130 header->fsf_status_qual.word[0]);
3131 } 1811 }
3132 break; 1812 break;
3133 1813
3134 case FSF_INVALID_COMMAND_OPTION:
3135 ZFCP_LOG_NORMAL(
3136 "Invalid option 0x%x has been specified "
3137 "in QTCB bottom sent to the adapter %s\n",
3138 bottom->option,
3139 zfcp_get_busid_by_adapter(adapter));
3140 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3141 retval = -EINVAL;
3142 break;
3143
3144 case FSF_GOOD: 1814 case FSF_GOOD:
3145 /* save LUN handle assigned by FSF */
3146 unit->handle = header->lun_handle; 1815 unit->handle = header->lun_handle;
3147 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3148 "adapter %s opened, port handle 0x%x\n",
3149 unit->fcp_lun,
3150 unit->port->wwpn,
3151 zfcp_get_busid_by_unit(unit),
3152 unit->handle);
3153 /* mark unit as open */
3154 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); 1816 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3155 1817
3156 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && 1818 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
@@ -3168,1528 +1830,629 @@ zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3168 if (!readwrite) { 1830 if (!readwrite) {
3169 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, 1831 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3170 &unit->status); 1832 &unit->status);
3171 ZFCP_LOG_NORMAL("read-only access for unit " 1833 dev_info(&adapter->ccw_device->dev,
3172 "(adapter %s, wwpn=0x%016Lx, " 1834 "Read-only access for unit 0x%016Lx "
3173 "fcp_lun=0x%016Lx)\n", 1835 "on port 0x%016Lx.\n",
3174 zfcp_get_busid_by_unit(unit), 1836 unit->fcp_lun, unit->port->wwpn);
3175 unit->port->wwpn,
3176 unit->fcp_lun);
3177 } 1837 }
3178 1838
3179 if (exclusive && !readwrite) { 1839 if (exclusive && !readwrite) {
3180 ZFCP_LOG_NORMAL("exclusive access of read-only " 1840 dev_err(&adapter->ccw_device->dev,
3181 "unit not supported\n"); 1841 "Exclusive access of read-only unit "
3182 zfcp_erp_unit_failed(unit, 35, fsf_req); 1842 "0x%016Lx on port 0x%016Lx not "
3183 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1843 "supported, disabling unit.\n",
3184 zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req); 1844 unit->fcp_lun, unit->port->wwpn);
1845 zfcp_erp_unit_failed(unit, 35, req);
1846 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1847 zfcp_erp_unit_shutdown(unit, 0, 80, req);
3185 } else if (!exclusive && readwrite) { 1848 } else if (!exclusive && readwrite) {
3186 ZFCP_LOG_NORMAL("shared access of read-write " 1849 dev_err(&adapter->ccw_device->dev,
3187 "unit not supported\n"); 1850 "Shared access of read-write unit "
3188 zfcp_erp_unit_failed(unit, 36, fsf_req); 1851 "0x%016Lx on port 0x%016Lx not "
3189 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1852 "supported, disabling unit.\n",
3190 zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req); 1853 unit->fcp_lun, unit->port->wwpn);
1854 zfcp_erp_unit_failed(unit, 36, req);
1855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1856 zfcp_erp_unit_shutdown(unit, 0, 81, req);
3191 } 1857 }
3192 } 1858 }
3193
3194 retval = 0;
3195 break;
3196
3197 default:
3198 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3199 "(debug info 0x%x)\n",
3200 header->fsf_status);
3201 break; 1859 break;
3202 } 1860 }
3203 1861
3204 skip_fsfstatus: 1862skip_fsfstatus:
3205 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status); 1863 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3206 return retval;
3207} 1864}
3208 1865
3209/* 1866/**
3210 * function: zfcp_fsf_close_unit 1867 * zfcp_fsf_open_unit - open unit
3211 * 1868 * @erp_action: pointer to struct zfcp_erp_action
3212 * purpose: 1869 * Returns: 0 on success, error otherwise
3213 *
3214 * returns: address of fsf_req - request successfully initiated
3215 * NULL -
3216 *
3217 * assumptions: This routine does not check whether the associated
3218 * remote port/lun has already been opened. This should be
3219 * done by calling routines. Otherwise some status
3220 * may be presented by FSF
3221 */ 1870 */
3222int 1871int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3223zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3224{ 1872{
3225 volatile struct qdio_buffer_element *sbale; 1873 volatile struct qdio_buffer_element *sbale;
3226 struct zfcp_fsf_req *fsf_req; 1874 struct zfcp_adapter *adapter = erp_action->adapter;
3227 unsigned long lock_flags; 1875 struct zfcp_fsf_req *req;
3228 int retval = 0; 1876 int retval = -EIO;
3229 1877
3230 /* setup new FSF request */ 1878 spin_lock(&adapter->req_q.lock);
3231 retval = zfcp_fsf_req_create(erp_action->adapter, 1879 if (zfcp_fsf_req_sbal_get(adapter))
3232 FSF_QTCB_CLOSE_LUN, 1880 goto out;
3233 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, 1881
3234 erp_action->adapter->pool.fsf_req_erp, 1882 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
3235 &lock_flags, &fsf_req); 1883 ZFCP_REQ_AUTO_CLEANUP,
3236 if (retval < 0) { 1884 adapter->pool.fsf_req_erp);
3237 ZFCP_LOG_INFO("error: Could not create close unit request for " 1885 if (unlikely(IS_ERR(req))) {
3238 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", 1886 retval = PTR_ERR(req);
3239 erp_action->unit->fcp_lun,
3240 erp_action->port->wwpn,
3241 zfcp_get_busid_by_adapter(erp_action->adapter));
3242 goto out; 1887 goto out;
3243 } 1888 }
3244 1889
3245 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 1890 sbale = zfcp_qdio_sbale_req(req);
3246 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1891 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3247 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1892 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3248 1893
3249 fsf_req->qtcb->header.port_handle = erp_action->port->handle; 1894 req->qtcb->header.port_handle = erp_action->port->handle;
3250 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle; 1895 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
3251 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status); 1896 req->handler = zfcp_fsf_open_unit_handler;
3252 fsf_req->data = (unsigned long) erp_action->unit; 1897 req->data = erp_action->unit;
3253 fsf_req->erp_action = erp_action; 1898 req->erp_action = erp_action;
3254 erp_action->fsf_req = fsf_req; 1899 erp_action->fsf_req = req;
3255 1900
3256 zfcp_erp_start_timer(fsf_req); 1901 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
3257 retval = zfcp_fsf_req_send(erp_action->fsf_req); 1902 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1903
1904 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
1905
1906 zfcp_fsf_start_erp_timer(req);
1907 retval = zfcp_fsf_req_send(req);
3258 if (retval) { 1908 if (retval) {
3259 ZFCP_LOG_INFO("error: Could not send a close unit request for " 1909 zfcp_fsf_req_free(req);
3260 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3261 erp_action->unit->fcp_lun,
3262 erp_action->port->wwpn,
3263 zfcp_get_busid_by_adapter(erp_action->adapter));
3264 zfcp_fsf_req_free(fsf_req);
3265 erp_action->fsf_req = NULL; 1910 erp_action->fsf_req = NULL;
3266 goto out;
3267 } 1911 }
3268 1912out:
3269 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, " 1913 spin_unlock(&adapter->req_q.lock);
3270 "port 0x%016Lx, unit 0x%016Lx)\n",
3271 zfcp_get_busid_by_adapter(erp_action->adapter),
3272 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3273 out:
3274 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3275 lock_flags);
3276 return retval; 1914 return retval;
3277} 1915}
3278 1916
3279/* 1917static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
3280 * function: zfcp_fsf_close_unit_handler
3281 *
3282 * purpose: is called for finished Close LUN FSF command
3283 *
3284 * returns:
3285 */
3286static int
3287zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3288{ 1918{
3289 int retval = -EINVAL; 1919 struct zfcp_unit *unit = req->data;
3290 struct zfcp_unit *unit;
3291
3292 unit = (struct zfcp_unit *) fsf_req->data;
3293 1920
3294 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { 1921 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
3295 /* don't change unit status in our bookkeeping */
3296 goto skip_fsfstatus; 1922 goto skip_fsfstatus;
3297 }
3298
3299 /* evaluate FSF status in QTCB */
3300 switch (fsf_req->qtcb->header.fsf_status) {
3301 1923
1924 switch (req->qtcb->header.fsf_status) {
3302 case FSF_PORT_HANDLE_NOT_VALID: 1925 case FSF_PORT_HANDLE_NOT_VALID:
3303 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " 1926 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
3304 "0x%016Lx on adapter %s invalid. This may " 1927 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3305 "happen in rare circumstances\n",
3306 unit->port->handle,
3307 unit->port->wwpn,
3308 zfcp_get_busid_by_unit(unit));
3309 ZFCP_LOG_DEBUG("status qualifier:\n");
3310 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3311 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3312 sizeof (union fsf_status_qual));
3313 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
3314 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3315 break; 1928 break;
3316
3317 case FSF_LUN_HANDLE_NOT_VALID: 1929 case FSF_LUN_HANDLE_NOT_VALID:
3318 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit " 1930 zfcp_erp_port_reopen(unit->port, 0, 111, req);
3319 "0x%016Lx on port 0x%016Lx on adapter %s is " 1931 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3320 "invalid. This may happen occasionally.\n",
3321 unit->handle,
3322 unit->fcp_lun,
3323 unit->port->wwpn,
3324 zfcp_get_busid_by_unit(unit));
3325 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3326 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3327 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3328 sizeof (union fsf_status_qual));
3329 zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
3330 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3331 break; 1932 break;
3332
3333 case FSF_PORT_BOXED: 1933 case FSF_PORT_BOXED:
3334 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " 1934 zfcp_erp_port_boxed(unit->port, 52, req);
3335 "needs to be reopened\n", 1935 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3336 unit->port->wwpn, 1936 ZFCP_STATUS_FSFREQ_RETRY;
3337 zfcp_get_busid_by_unit(unit));
3338 zfcp_erp_port_boxed(unit->port, 52, fsf_req);
3339 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3340 ZFCP_STATUS_FSFREQ_RETRY;
3341 break; 1937 break;
3342
3343 case FSF_ADAPTER_STATUS_AVAILABLE: 1938 case FSF_ADAPTER_STATUS_AVAILABLE:
3344 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { 1939 switch (req->qtcb->header.fsf_status_qual.word[0]) {
3345 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 1940 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3346 /* re-establish link to port */
3347 zfcp_test_link(unit->port); 1941 zfcp_test_link(unit->port);
3348 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1942 /* fall through */
3349 break;
3350 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 1943 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3351 /* ERP strategy will escalate */ 1944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3352 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3353 break;
3354 default:
3355 ZFCP_LOG_NORMAL
3356 ("bug: Wrong status qualifier 0x%x arrived.\n",
3357 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3358 break; 1945 break;
3359 } 1946 }
3360 break; 1947 break;
3361
3362 case FSF_GOOD: 1948 case FSF_GOOD:
3363 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3364 "closed, port handle 0x%x\n",
3365 unit->fcp_lun,
3366 unit->port->wwpn,
3367 zfcp_get_busid_by_unit(unit),
3368 unit->handle);
3369 /* mark unit as closed */
3370 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); 1949 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3371 retval = 0;
3372 break;
3373
3374 default:
3375 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3376 "(debug info 0x%x)\n",
3377 fsf_req->qtcb->header.fsf_status);
3378 break; 1950 break;
3379 } 1951 }
3380 1952skip_fsfstatus:
3381 skip_fsfstatus:
3382 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status); 1953 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3383 return retval;
3384} 1954}
3385 1955
3386/** 1956/**
3387 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) 1957 * zfcp_fsf_close_unit - close zfcp unit
3388 * @adapter: adapter where scsi command is issued 1958 * @erp_action: pointer to struct zfcp_unit
3389 * @unit: unit where command is sent to 1959 * Returns: 0 on success, error otherwise
3390 * @scsi_cmnd: scsi command to be sent
3391 * @timer: timer to be started when request is initiated
3392 * @req_flags: flags for fsf_request
3393 */ 1960 */
3394int 1961int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3395zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3396 struct zfcp_unit *unit,
3397 struct scsi_cmnd * scsi_cmnd,
3398 int use_timer, int req_flags)
3399{ 1962{
3400 struct zfcp_fsf_req *fsf_req = NULL; 1963 volatile struct qdio_buffer_element *sbale;
3401 struct fcp_cmnd_iu *fcp_cmnd_iu; 1964 struct zfcp_adapter *adapter = erp_action->adapter;
3402 unsigned int sbtype; 1965 struct zfcp_fsf_req *req;
3403 unsigned long lock_flags; 1966 int retval = -EIO;
3404 int real_bytes = 0;
3405 int retval = 0;
3406 int mask;
3407
3408 /* setup new FSF request */
3409 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3410 adapter->pool.fsf_req_scsi,
3411 &lock_flags, &fsf_req);
3412 if (unlikely(retval < 0)) {
3413 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3414 "for unit 0x%016Lx on port 0x%016Lx on "
3415 "adapter %s\n",
3416 unit->fcp_lun,
3417 unit->port->wwpn,
3418 zfcp_get_busid_by_adapter(adapter));
3419 goto failed_req_create;
3420 }
3421
3422 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3423 &unit->status))) {
3424 retval = -EBUSY;
3425 goto unit_blocked;
3426 }
3427
3428 zfcp_unit_get(unit);
3429 fsf_req->unit = unit;
3430
3431 /* associate FSF request with SCSI request (for look up on abort) */
3432 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
3433
3434 /* associate SCSI command with FSF request */
3435 fsf_req->data = (unsigned long) scsi_cmnd;
3436
3437 /* set handles of unit and its parent port in QTCB */
3438 fsf_req->qtcb->header.lun_handle = unit->handle;
3439 fsf_req->qtcb->header.port_handle = unit->port->handle;
3440
3441 /* FSF does not define the structure of the FCP_CMND IU */
3442 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3443 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3444
3445 /*
3446 * set depending on data direction:
3447 * data direction bits in SBALE (SB Type)
3448 * data direction bits in QTCB
3449 * data direction bits in FCP_CMND IU
3450 */
3451 switch (scsi_cmnd->sc_data_direction) {
3452 case DMA_NONE:
3453 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3454 /*
3455 * FIXME(qdio):
3456 * what is the correct type for commands
3457 * without 'real' data buffers?
3458 */
3459 sbtype = SBAL_FLAGS0_TYPE_READ;
3460 break;
3461 case DMA_FROM_DEVICE:
3462 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3463 sbtype = SBAL_FLAGS0_TYPE_READ;
3464 fcp_cmnd_iu->rddata = 1;
3465 break;
3466 case DMA_TO_DEVICE:
3467 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3468 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3469 fcp_cmnd_iu->wddata = 1;
3470 break;
3471 case DMA_BIDIRECTIONAL:
3472 default:
3473 /*
3474 * dummy, catch this condition earlier
3475 * in zfcp_scsi_queuecommand
3476 */
3477 goto failed_scsi_cmnd;
3478 }
3479
3480 /* set FC service class in QTCB (3 per default) */
3481 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3482
3483 /* set FCP_LUN in FCP_CMND IU in QTCB */
3484 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3485
3486 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3487
3488 /* set task attributes in FCP_CMND IU in QTCB */
3489 if (likely((scsi_cmnd->device->simple_tags) ||
3490 (atomic_test_mask(mask, &unit->status))))
3491 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3492 else
3493 fcp_cmnd_iu->task_attribute = UNTAGGED;
3494
3495 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3496 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3497 fcp_cmnd_iu->add_fcp_cdb_length
3498 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3499 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3500 "additional FCP_CDB length is 0x%x "
3501 "(shifted right 2 bits)\n",
3502 scsi_cmnd->cmd_len,
3503 fcp_cmnd_iu->add_fcp_cdb_length);
3504 }
3505 /*
3506 * copy SCSI CDB (including additional length, if any) to
3507 * FCP_CDB in FCP_CMND IU in QTCB
3508 */
3509 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3510
3511 /* FCP CMND IU length in QTCB */
3512 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3513 sizeof (struct fcp_cmnd_iu) +
3514 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3515 1967
3516 /* generate SBALEs from data buffer */ 1968 spin_lock(&adapter->req_q.lock);
3517 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd); 1969 if (zfcp_fsf_req_sbal_get(adapter))
3518 if (unlikely(real_bytes < 0)) { 1970 goto out;
3519 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) { 1971 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
3520 ZFCP_LOG_DEBUG( 1972 ZFCP_REQ_AUTO_CLEANUP,
3521 "Data did not fit into available buffer(s), " 1973 adapter->pool.fsf_req_erp);
3522 "waiting for more...\n"); 1974 if (unlikely(IS_ERR(req))) {
3523 retval = -EIO; 1975 retval = PTR_ERR(req);
3524 } else { 1976 goto out;
3525 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3526 "required. Shutting down unit "
3527 "(adapter %s, port 0x%016Lx, "
3528 "unit 0x%016Lx)\n",
3529 zfcp_get_busid_by_unit(unit),
3530 unit->port->wwpn,
3531 unit->fcp_lun);
3532 zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
3533 retval = -EINVAL;
3534 }
3535 goto no_fit;
3536 } 1977 }
3537 1978
3538 /* set length of FCP data length in FCP_CMND IU in QTCB */ 1979 sbale = zfcp_qdio_sbale_req(req);
3539 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); 1980 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1981 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3540 1982
3541 ZFCP_LOG_DEBUG("Sending SCSI command:\n"); 1983 req->qtcb->header.port_handle = erp_action->port->handle;
3542 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, 1984 req->qtcb->header.lun_handle = erp_action->unit->handle;
3543 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len); 1985 req->handler = zfcp_fsf_close_unit_handler;
1986 req->data = erp_action->unit;
1987 req->erp_action = erp_action;
1988 erp_action->fsf_req = req;
1989 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3544 1990
3545 if (use_timer) 1991 zfcp_fsf_start_erp_timer(req);
3546 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); 1992 retval = zfcp_fsf_req_send(req);
3547 1993 if (retval) {
3548 retval = zfcp_fsf_req_send(fsf_req); 1994 zfcp_fsf_req_free(req);
3549 if (unlikely(retval < 0)) { 1995 erp_action->fsf_req = NULL;
3550 ZFCP_LOG_INFO("error: Could not send FCP command request "
3551 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3552 zfcp_get_busid_by_adapter(adapter),
3553 unit->port->wwpn,
3554 unit->fcp_lun);
3555 goto send_failed;
3556 } 1996 }
3557 1997out:
3558 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, " 1998 spin_unlock(&adapter->req_q.lock);
3559 "port 0x%016Lx, unit 0x%016Lx)\n",
3560 zfcp_get_busid_by_adapter(adapter),
3561 unit->port->wwpn,
3562 unit->fcp_lun);
3563 goto success;
3564
3565 send_failed:
3566 no_fit:
3567 failed_scsi_cmnd:
3568 zfcp_unit_put(unit);
3569 unit_blocked:
3570 zfcp_fsf_req_free(fsf_req);
3571 fsf_req = NULL;
3572 scsi_cmnd->host_scribble = NULL;
3573 success:
3574 failed_req_create:
3575 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3576 return retval; 1999 return retval;
3577} 2000}
3578 2001
3579struct zfcp_fsf_req * 2002static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
3580zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3581 struct zfcp_unit *unit,
3582 u8 tm_flags, int req_flags)
3583{ 2003{
3584 struct zfcp_fsf_req *fsf_req = NULL; 2004 lat_rec->sum += lat;
3585 int retval = 0; 2005 lat_rec->min = min(lat_rec->min, lat);
3586 struct fcp_cmnd_iu *fcp_cmnd_iu; 2006 lat_rec->max = max(lat_rec->max, lat);
3587 unsigned long lock_flags;
3588 volatile struct qdio_buffer_element *sbale;
3589
3590 /* setup new FSF request */
3591 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3592 adapter->pool.fsf_req_scsi,
3593 &lock_flags, &fsf_req);
3594 if (retval < 0) {
3595 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3596 "management) request for adapter %s, port "
3597 " 0x%016Lx, unit 0x%016Lx.\n",
3598 zfcp_get_busid_by_adapter(adapter),
3599 unit->port->wwpn, unit->fcp_lun);
3600 goto out;
3601 }
3602
3603 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3604 &unit->status)))
3605 goto unit_blocked;
3606
3607 /*
3608 * Used to decide on proper handler in the return path,
3609 * could be either zfcp_fsf_send_fcp_command_task_handler or
3610 * zfcp_fsf_send_fcp_command_task_management_handler */
3611
3612 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3613
3614 /*
3615 * hold a pointer to the unit being target of this
3616 * task management request
3617 */
3618 fsf_req->data = (unsigned long) unit;
3619
3620 /* set FSF related fields in QTCB */
3621 fsf_req->qtcb->header.lun_handle = unit->handle;
3622 fsf_req->qtcb->header.port_handle = unit->port->handle;
3623 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3624 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3625 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3626 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3627
3628 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3629 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3630 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3631
3632 /* set FCP related fields in FCP_CMND IU in QTCB */
3633 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3634 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3635 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3636 fcp_cmnd_iu->task_management_flags = tm_flags;
3637
3638 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3639 retval = zfcp_fsf_req_send(fsf_req);
3640 if (!retval)
3641 goto out;
3642
3643 unit_blocked:
3644 zfcp_fsf_req_free(fsf_req);
3645 fsf_req = NULL;
3646
3647 out:
3648 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3649 return fsf_req;
3650} 2007}
3651 2008
3652/* 2009static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
3653 * function: zfcp_fsf_send_fcp_command_handler
3654 *
3655 * purpose: is called for finished Send FCP Command
3656 *
3657 * returns:
3658 */
3659static int
3660zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3661{ 2010{
3662 int retval = -EINVAL; 2011 struct fsf_qual_latency_info *lat_inf;
3663 struct zfcp_unit *unit; 2012 struct latency_cont *lat;
3664 struct fsf_qtcb_header *header; 2013 struct zfcp_unit *unit = req->unit;
3665 u16 subtable, rule, counter; 2014 unsigned long flags;
3666
3667 header = &fsf_req->qtcb->header;
3668
3669 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3670 unit = (struct zfcp_unit *) fsf_req->data;
3671 else
3672 unit = fsf_req->unit;
3673
3674 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3675 /* go directly to calls of special handlers */
3676 goto skip_fsfstatus;
3677 }
3678
3679 /* evaluate FSF status in QTCB */
3680 switch (header->fsf_status) {
3681
3682 case FSF_PORT_HANDLE_NOT_VALID:
3683 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3684 "0x%016Lx on adapter %s invalid\n",
3685 unit->port->handle,
3686 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3687 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3688 (char *) &header->fsf_status_qual,
3689 sizeof (union fsf_status_qual));
3690 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
3691 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3692 break;
3693
3694 case FSF_LUN_HANDLE_NOT_VALID:
3695 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3696 "0x%016Lx on port 0x%016Lx on adapter %s is "
3697 "invalid. This may happen occasionally.\n",
3698 unit->handle,
3699 unit->fcp_lun,
3700 unit->port->wwpn,
3701 zfcp_get_busid_by_unit(unit));
3702 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3703 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3704 (char *) &header->fsf_status_qual,
3705 sizeof (union fsf_status_qual));
3706 zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
3707 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3708 break;
3709
3710 case FSF_HANDLE_MISMATCH:
3711 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3712 "unexpectedly. (adapter %s, port 0x%016Lx, "
3713 "unit 0x%016Lx)\n",
3714 unit->port->handle,
3715 zfcp_get_busid_by_unit(unit),
3716 unit->port->wwpn,
3717 unit->fcp_lun);
3718 ZFCP_LOG_NORMAL("status qualifier:\n");
3719 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3720 (char *) &header->fsf_status_qual,
3721 sizeof (union fsf_status_qual));
3722 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
3723 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3724 break;
3725
3726 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3727 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3728 "class %d.\n",
3729 zfcp_get_busid_by_unit(unit),
3730 ZFCP_FC_SERVICE_CLASS_DEFAULT);
3731 /* stop operation for this adapter */
3732 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
3733 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3734 break;
3735
3736 case FSF_FCPLUN_NOT_VALID:
3737 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3738 "adapter %s does not have correct unit "
3739 "handle 0x%x\n",
3740 unit->fcp_lun,
3741 unit->port->wwpn,
3742 zfcp_get_busid_by_unit(unit),
3743 unit->handle);
3744 ZFCP_LOG_DEBUG("status qualifier:\n");
3745 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3746 (char *) &header->fsf_status_qual,
3747 sizeof (union fsf_status_qual));
3748 zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
3749 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3750 break;
3751
3752 case FSF_ACCESS_DENIED:
3753 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3754 "unit 0x%016Lx on port 0x%016Lx on "
3755 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3756 zfcp_get_busid_by_unit(unit));
3757 for (counter = 0; counter < 2; counter++) {
3758 subtable = header->fsf_status_qual.halfword[counter * 2];
3759 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3760 switch (subtable) {
3761 case FSF_SQ_CFDC_SUBTABLE_OS:
3762 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3763 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3764 case FSF_SQ_CFDC_SUBTABLE_LUN:
3765 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3766 zfcp_act_subtable_type[subtable], rule);
3767 break;
3768 }
3769 }
3770 zfcp_erp_unit_access_denied(unit, 61, fsf_req);
3771 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3772 break;
3773
3774 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3775 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3776 "0x%016Lx on port 0x%016Lx on adapter %s "
3777 "(debug info %d)\n",
3778 unit->fcp_lun,
3779 unit->port->wwpn,
3780 zfcp_get_busid_by_unit(unit),
3781 fsf_req->qtcb->bottom.io.data_direction);
3782 /* stop operation for this adapter */
3783 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
3784 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3785 break;
3786
3787 case FSF_CMND_LENGTH_NOT_VALID:
3788 ZFCP_LOG_NORMAL
3789 ("bug: An invalid control-data-block length field "
3790 "was found in a command for unit 0x%016Lx on port "
3791 "0x%016Lx on adapter %s " "(debug info %d)\n",
3792 unit->fcp_lun, unit->port->wwpn,
3793 zfcp_get_busid_by_unit(unit),
3794 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3795 /* stop operation for this adapter */
3796 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
3797 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3798 break;
3799 2015
3800 case FSF_PORT_BOXED: 2016 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
3801 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3802 "needs to be reopened\n",
3803 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3804 zfcp_erp_port_boxed(unit->port, 53, fsf_req);
3805 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3806 ZFCP_STATUS_FSFREQ_RETRY;
3807 break;
3808 2017
3809 case FSF_LUN_BOXED: 2018 switch (req->qtcb->bottom.io.data_direction) {
3810 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, " 2019 case FSF_DATADIR_READ:
3811 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n", 2020 lat = &unit->latencies.read;
3812 zfcp_get_busid_by_unit(unit),
3813 unit->port->wwpn, unit->fcp_lun);
3814 zfcp_erp_unit_boxed(unit, 54, fsf_req);
3815 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3816 | ZFCP_STATUS_FSFREQ_RETRY;
3817 break;
3818
3819 case FSF_ADAPTER_STATUS_AVAILABLE:
3820 switch (header->fsf_status_qual.word[0]) {
3821 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3822 /* re-establish link to port */
3823 zfcp_test_link(unit->port);
3824 break;
3825 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3826 /* FIXME(hw) need proper specs for proper action */
3827 /* let scsi stack deal with retries and escalation */
3828 break;
3829 default:
3830 ZFCP_LOG_NORMAL
3831 ("Unknown status qualifier 0x%x arrived.\n",
3832 header->fsf_status_qual.word[0]);
3833 break;
3834 }
3835 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3836 break; 2021 break;
3837 2022 case FSF_DATADIR_WRITE:
3838 case FSF_GOOD: 2023 lat = &unit->latencies.write;
3839 break; 2024 break;
3840 2025 case FSF_DATADIR_CMND:
3841 case FSF_FCP_RSP_AVAILABLE: 2026 lat = &unit->latencies.cmd;
3842 break; 2027 break;
2028 default:
2029 return;
3843 } 2030 }
3844 2031
3845 skip_fsfstatus: 2032 spin_lock_irqsave(&unit->latencies.lock, flags);
3846 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) { 2033 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
3847 retval = 2034 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
3848 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req); 2035 lat->counter++;
3849 } else { 2036 spin_unlock_irqrestore(&unit->latencies.lock, flags);
3850 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3851 fsf_req->unit = NULL;
3852 zfcp_unit_put(unit);
3853 }
3854 return retval;
3855} 2037}
3856 2038
3857/* 2039static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
3858 * function: zfcp_fsf_send_fcp_command_task_handler
3859 *
3860 * purpose: evaluates FCP_RSP IU
3861 *
3862 * returns:
3863 */
3864static int
3865zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3866{ 2040{
3867 int retval = 0; 2041 struct scsi_cmnd *scpnt = req->data;
3868 struct scsi_cmnd *scpnt;
3869 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) 2042 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3870 &(fsf_req->qtcb->bottom.io.fcp_rsp); 2043 &(req->qtcb->bottom.io.fcp_rsp);
3871 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3872 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3873 u32 sns_len; 2044 u32 sns_len;
3874 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); 2045 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
3875 unsigned long flags; 2046 unsigned long flags;
3876 struct zfcp_unit *unit = fsf_req->unit; 2047
3877 2048 if (unlikely(!scpnt))
3878 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags); 2049 return;
3879 scpnt = (struct scsi_cmnd *) fsf_req->data; 2050
3880 if (unlikely(!scpnt)) { 2051 read_lock_irqsave(&req->adapter->abort_lock, flags);
3881 ZFCP_LOG_DEBUG 2052
3882 ("Command with fsf_req %p is not associated to " 2053 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3883 "a scsi command anymore. Aborted?\n", fsf_req); 2054 set_host_byte(scpnt, DID_SOFT_ERROR);
3884 goto out; 2055 set_driver_byte(scpnt, SUGGEST_RETRY);
3885 }
3886 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3887 /* FIXME: (design) mid-layer should handle DID_ABORT like
3888 * DID_SOFT_ERROR by retrying the request for devices
3889 * that allow retries.
3890 */
3891 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3892 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3893 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3894 goto skip_fsfstatus; 2056 goto skip_fsfstatus;
3895 } 2057 }
3896 2058
3897 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { 2059 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3898 ZFCP_LOG_DEBUG("Setting DID_ERROR\n"); 2060 set_host_byte(scpnt, DID_ERROR);
3899 set_host_byte(&scpnt->result, DID_ERROR);
3900 goto skip_fsfstatus; 2061 goto skip_fsfstatus;
3901 } 2062 }
3902 2063
3903 /* set message byte of result in SCSI command */ 2064 set_msg_byte(scpnt, COMMAND_COMPLETE);
3904 scpnt->result |= COMMAND_COMPLETE << 8;
3905 2065
3906 /*
3907 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3908 * of result in SCSI command
3909 */
3910 scpnt->result |= fcp_rsp_iu->scsi_status; 2066 scpnt->result |= fcp_rsp_iu->scsi_status;
3911 if (unlikely(fcp_rsp_iu->scsi_status)) {
3912 /* DEBUG */
3913 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
3914 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3915 scpnt->cmnd, scpnt->cmd_len);
3916 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
3917 fcp_rsp_iu->scsi_status);
3918 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3919 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
3920 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3921 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
3922 fcp_rsp_iu->fcp_sns_len);
3923 }
3924 2067
3925 /* check FCP_RSP_INFO */ 2068 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2069 zfcp_fsf_req_latency(req);
2070
3926 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { 2071 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
3927 ZFCP_LOG_DEBUG("rsp_len is valid\n"); 2072 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
3928 switch (fcp_rsp_info[3]) { 2073 set_host_byte(scpnt, DID_OK);
3929 case RSP_CODE_GOOD: 2074 else {
3930 /* ok, continue */ 2075 set_host_byte(scpnt, DID_ERROR);
3931 ZFCP_LOG_TRACE("no failure or Task Management "
3932 "Function complete\n");
3933 set_host_byte(&scpnt->result, DID_OK);
3934 break;
3935 case RSP_CODE_LENGTH_MISMATCH:
3936 /* hardware bug */
3937 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3938 "that the fibrechannel protocol data "
3939 "length differs from the burst length. "
3940 "The problem occured on unit 0x%016Lx "
3941 "on port 0x%016Lx on adapter %s",
3942 unit->fcp_lun,
3943 unit->port->wwpn,
3944 zfcp_get_busid_by_unit(unit));
3945 /* dump SCSI CDB as prepared by zfcp */
3946 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3947 (char *) &fsf_req->qtcb->
3948 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3949 set_host_byte(&scpnt->result, DID_ERROR);
3950 goto skip_fsfstatus;
3951 case RSP_CODE_FIELD_INVALID:
3952 /* driver or hardware bug */
3953 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3954 "that the fibrechannel protocol data "
3955 "fields were incorrectly set up. "
3956 "The problem occured on the unit "
3957 "0x%016Lx on port 0x%016Lx on "
3958 "adapter %s",
3959 unit->fcp_lun,
3960 unit->port->wwpn,
3961 zfcp_get_busid_by_unit(unit));
3962 /* dump SCSI CDB as prepared by zfcp */
3963 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3964 (char *) &fsf_req->qtcb->
3965 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3966 set_host_byte(&scpnt->result, DID_ERROR);
3967 goto skip_fsfstatus;
3968 case RSP_CODE_RO_MISMATCH:
3969 /* hardware bug */
3970 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
3971 "that conflicting values for the "
3972 "fibrechannel payload offset from the "
3973 "header were found. "
3974 "The problem occured on unit 0x%016Lx "
3975 "on port 0x%016Lx on adapter %s.\n",
3976 unit->fcp_lun,
3977 unit->port->wwpn,
3978 zfcp_get_busid_by_unit(unit));
3979 /* dump SCSI CDB as prepared by zfcp */
3980 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3981 (char *) &fsf_req->qtcb->
3982 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3983 set_host_byte(&scpnt->result, DID_ERROR);
3984 goto skip_fsfstatus;
3985 default:
3986 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
3987 "code was detected for a command. "
3988 "The problem occured on the unit "
3989 "0x%016Lx on port 0x%016Lx on "
3990 "adapter %s (debug info 0x%x)\n",
3991 unit->fcp_lun,
3992 unit->port->wwpn,
3993 zfcp_get_busid_by_unit(unit),
3994 fcp_rsp_info[3]);
3995 /* dump SCSI CDB as prepared by zfcp */
3996 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3997 (char *) &fsf_req->qtcb->
3998 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3999 set_host_byte(&scpnt->result, DID_ERROR);
4000 goto skip_fsfstatus; 2076 goto skip_fsfstatus;
4001 } 2077 }
4002 } 2078 }
4003 2079
4004 /* check for sense data */
4005 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { 2080 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4006 sns_len = FSF_FCP_RSP_SIZE - 2081 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
4007 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len; 2082 fcp_rsp_iu->fcp_rsp_len;
4008 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4009 sns_len);
4010 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); 2083 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4011 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4012 SCSI_SENSE_BUFFERSIZE);
4013 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); 2084 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4014 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4015 scpnt->result);
4016 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4017 scpnt->cmnd, scpnt->cmd_len);
4018 2085
4019 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4020 fcp_rsp_iu->fcp_sns_len);
4021 memcpy(scpnt->sense_buffer, 2086 memcpy(scpnt->sense_buffer,
4022 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); 2087 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4023 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4024 (void *)scpnt->sense_buffer, sns_len);
4025 }
4026
4027 /* check for overrun */
4028 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4029 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4030 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4031 "The response data length is "
4032 "%d, the original length was %d.\n",
4033 unit->fcp_lun,
4034 unit->port->wwpn,
4035 zfcp_get_busid_by_unit(unit),
4036 fcp_rsp_iu->fcp_resid,
4037 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4038 } 2088 }
4039 2089
4040 /* check for underrun */
4041 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { 2090 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4042 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4043 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4044 "The response data length is "
4045 "%d, the original length was %d.\n",
4046 unit->fcp_lun,
4047 unit->port->wwpn,
4048 zfcp_get_busid_by_unit(unit),
4049 fcp_rsp_iu->fcp_resid,
4050 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4051
4052 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid); 2091 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4053 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) < 2092 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4054 scpnt->underflow) 2093 scpnt->underflow)
4055 set_host_byte(&scpnt->result, DID_ERROR); 2094 set_host_byte(scpnt, DID_ERROR);
4056 } 2095 }
4057 2096skip_fsfstatus:
4058 skip_fsfstatus:
4059 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4060
4061 if (scpnt->result != 0) 2097 if (scpnt->result != 0)
4062 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req); 2098 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
4063 else if (scpnt->retries > 0) 2099 else if (scpnt->retries > 0)
4064 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req); 2100 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
4065 else 2101 else
4066 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req); 2102 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
4067 2103
4068 /* cleanup pointer (need this especially for abort) */
4069 scpnt->host_scribble = NULL; 2104 scpnt->host_scribble = NULL;
4070
4071 /* always call back */
4072 (scpnt->scsi_done) (scpnt); 2105 (scpnt->scsi_done) (scpnt);
4073
4074 /* 2106 /*
4075 * We must hold this lock until scsi_done has been called. 2107 * We must hold this lock until scsi_done has been called.
4076 * Otherwise we may call scsi_done after abort regarding this 2108 * Otherwise we may call scsi_done after abort regarding this
4077 * command has completed. 2109 * command has completed.
4078 * Note: scsi_done must not block! 2110 * Note: scsi_done must not block!
4079 */ 2111 */
4080 out: 2112 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
4081 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4082 return retval;
4083} 2113}
4084 2114
4085/* 2115static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
4086 * function: zfcp_fsf_send_fcp_command_task_management_handler
4087 *
4088 * purpose: evaluates FCP_RSP IU
4089 *
4090 * returns:
4091 */
4092static int
4093zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4094{ 2116{
4095 int retval = 0;
4096 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) 2117 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4097 &(fsf_req->qtcb->bottom.io.fcp_rsp); 2118 &(req->qtcb->bottom.io.fcp_rsp);
4098 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); 2119 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
4099 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4100
4101 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4102 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4103 goto skip_fsfstatus;
4104 }
4105 2120
4106 /* check FCP_RSP_INFO */ 2121 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
4107 switch (fcp_rsp_info[3]) { 2122 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
4108 case RSP_CODE_GOOD: 2123 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4109 /* ok, continue */
4110 ZFCP_LOG_DEBUG("no failure or Task Management "
4111 "Function complete\n");
4112 break;
4113 case RSP_CODE_TASKMAN_UNSUPP:
4114 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4115 "is not supported on the target device "
4116 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4117 unit->fcp_lun,
4118 unit->port->wwpn,
4119 zfcp_get_busid_by_unit(unit));
4120 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4121 break;
4122 case RSP_CODE_TASKMAN_FAILED:
4123 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4124 "failed to complete successfully. "
4125 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4126 unit->fcp_lun,
4127 unit->port->wwpn,
4128 zfcp_get_busid_by_unit(unit));
4129 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4130 break;
4131 default:
4132 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4133 "code was detected for a command. "
4134 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4135 "(debug info 0x%x)\n",
4136 unit->fcp_lun,
4137 unit->port->wwpn,
4138 zfcp_get_busid_by_unit(unit),
4139 fcp_rsp_info[3]);
4140 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4141 }
4142
4143 skip_fsfstatus:
4144 return retval;
4145} 2124}
4146 2125
4147 2126
4148/* 2127static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
4149 * function: zfcp_fsf_control_file
4150 *
4151 * purpose: Initiator of the control file upload/download FSF requests
4152 *
4153 * returns: 0 - FSF request is successfuly created and queued
4154 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4155 * -EINVAL - Invalid direction specified
4156 * -ENOMEM - Insufficient memory
4157 * -EPERM - Cannot create FSF request or place it in QDIO queue
4158 */
4159int
4160zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4161 struct zfcp_fsf_req **fsf_req_ptr,
4162 u32 fsf_command,
4163 u32 option,
4164 struct zfcp_sg_list *sg_list)
4165{ 2128{
4166 struct zfcp_fsf_req *fsf_req; 2129 struct zfcp_unit *unit;
4167 struct fsf_qtcb_bottom_support *bottom; 2130 struct fsf_qtcb_header *header = &req->qtcb->header;
4168 volatile struct qdio_buffer_element *sbale;
4169 unsigned long lock_flags;
4170 int req_flags = 0;
4171 int direction;
4172 int retval = 0;
4173
4174 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4175 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4176 zfcp_get_busid_by_adapter(adapter));
4177 retval = -EOPNOTSUPP;
4178 goto out;
4179 }
4180
4181 switch (fsf_command) {
4182
4183 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4184 direction = SBAL_FLAGS0_TYPE_WRITE;
4185 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4186 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4187 req_flags = ZFCP_WAIT_FOR_SBAL;
4188 break;
4189
4190 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4191 direction = SBAL_FLAGS0_TYPE_READ;
4192 break;
4193
4194 default:
4195 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4196 retval = -EINVAL;
4197 goto out;
4198 }
4199
4200 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4201 NULL, &lock_flags, &fsf_req);
4202 if (retval < 0) {
4203 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4204 "adapter %s\n",
4205 zfcp_get_busid_by_adapter(adapter));
4206 retval = -EPERM;
4207 goto unlock_queue_lock;
4208 }
4209
4210 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4211 sbale[0].flags |= direction;
4212
4213 bottom = &fsf_req->qtcb->bottom.support;
4214 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4215 bottom->option = option;
4216
4217 if (sg_list->count > 0) {
4218 int bytes;
4219
4220 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4221 sg_list->sg, sg_list->count,
4222 ZFCP_MAX_SBALS_PER_REQ);
4223 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4224 ZFCP_LOG_INFO(
4225 "error: Could not create sufficient number of "
4226 "SBALS for an FSF request to the adapter %s\n",
4227 zfcp_get_busid_by_adapter(adapter));
4228 retval = -ENOMEM;
4229 goto free_fsf_req;
4230 }
4231 } else
4232 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4233
4234 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4235 retval = zfcp_fsf_req_send(fsf_req);
4236 if (retval < 0) {
4237 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4238 "(adapter %s)\n",
4239 zfcp_get_busid_by_adapter(adapter));
4240 retval = -EPERM;
4241 goto free_fsf_req;
4242 }
4243 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4244
4245 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4246 "adapter %s\n",
4247 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4248 "download" : "upload",
4249 zfcp_get_busid_by_adapter(adapter));
4250
4251 wait_event(fsf_req->completion_wq,
4252 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4253
4254 *fsf_req_ptr = fsf_req;
4255 goto out;
4256
4257 free_fsf_req:
4258 zfcp_fsf_req_free(fsf_req);
4259 unlock_queue_lock:
4260 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4261 out:
4262 return retval;
4263}
4264
4265 2131
4266/* 2132 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
4267 * function: zfcp_fsf_control_file_handler 2133 unit = req->data;
4268 * 2134 else
4269 * purpose: Handler of the control file upload/download FSF requests 2135 unit = req->unit;
4270 *
4271 * returns: 0 - FSF request successfuly processed
4272 * -EAGAIN - Operation has to be repeated because of a temporary problem
4273 * -EACCES - There is no permission to execute an operation
4274 * -EPERM - The control file is not in a right format
4275 * -EIO - There is a problem with the FCP adapter
4276 * -EINVAL - Invalid operation
4277 * -EFAULT - User space memory I/O operation fault
4278 */
4279static int
4280zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4281{
4282 struct zfcp_adapter *adapter = fsf_req->adapter;
4283 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4284 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4285 int retval = 0;
4286 2136
4287 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { 2137 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
4288 retval = -EINVAL;
4289 goto skip_fsfstatus; 2138 goto skip_fsfstatus;
4290 }
4291 2139
4292 switch (header->fsf_status) { 2140 switch (header->fsf_status) {
4293 2141 case FSF_HANDLE_MISMATCH:
4294 case FSF_GOOD: 2142 case FSF_PORT_HANDLE_NOT_VALID:
4295 ZFCP_LOG_NORMAL( 2143 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
4296 "The FSF request has been successfully completed " 2144 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4297 "on the adapter %s\n",
4298 zfcp_get_busid_by_adapter(adapter));
4299 break;
4300
4301 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4302 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4303 switch (header->fsf_status_qual.word[0]) {
4304
4305 case FSF_SQ_CFDC_HARDENED_ON_SE:
4306 ZFCP_LOG_NORMAL(
4307 "CFDC on the adapter %s has being "
4308 "hardened on primary and secondary SE\n",
4309 zfcp_get_busid_by_adapter(adapter));
4310 break;
4311
4312 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4313 ZFCP_LOG_NORMAL(
4314 "CFDC of the adapter %s could not "
4315 "be saved on the SE\n",
4316 zfcp_get_busid_by_adapter(adapter));
4317 break;
4318
4319 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4320 ZFCP_LOG_NORMAL(
4321 "CFDC of the adapter %s could not "
4322 "be copied to the secondary SE\n",
4323 zfcp_get_busid_by_adapter(adapter));
4324 break;
4325
4326 default:
4327 ZFCP_LOG_NORMAL(
4328 "CFDC could not be hardened "
4329 "on the adapter %s\n",
4330 zfcp_get_busid_by_adapter(adapter));
4331 }
4332 }
4333 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4334 retval = -EAGAIN;
4335 break;
4336
4337 case FSF_AUTHORIZATION_FAILURE:
4338 ZFCP_LOG_NORMAL(
4339 "Adapter %s does not accept privileged commands\n",
4340 zfcp_get_busid_by_adapter(adapter));
4341 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4342 retval = -EACCES;
4343 break; 2145 break;
4344 2146 case FSF_FCPLUN_NOT_VALID:
4345 case FSF_CFDC_ERROR_DETECTED: 2147 case FSF_LUN_HANDLE_NOT_VALID:
4346 ZFCP_LOG_NORMAL( 2148 zfcp_erp_port_reopen(unit->port, 0, 113, req);
4347 "Error at position %d in the CFDC, " 2149 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4348 "CFDC is discarded by the adapter %s\n",
4349 header->fsf_status_qual.word[0],
4350 zfcp_get_busid_by_adapter(adapter));
4351 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4352 retval = -EPERM;
4353 break; 2150 break;
4354 2151 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
4355 case FSF_CONTROL_FILE_UPDATE_ERROR: 2152 zfcp_fsf_class_not_supp(req);
4356 ZFCP_LOG_NORMAL(
4357 "Adapter %s cannot harden the control file, "
4358 "file is discarded\n",
4359 zfcp_get_busid_by_adapter(adapter));
4360 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4361 retval = -EIO;
4362 break; 2153 break;
4363 2154 case FSF_ACCESS_DENIED:
4364 case FSF_CONTROL_FILE_TOO_LARGE: 2155 zfcp_fsf_access_denied_unit(req, unit);
4365 ZFCP_LOG_NORMAL(
4366 "Control file is too large, file is discarded "
4367 "by the adapter %s\n",
4368 zfcp_get_busid_by_adapter(adapter));
4369 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4370 retval = -EIO;
4371 break; 2156 break;
4372 2157 case FSF_DIRECTION_INDICATOR_NOT_VALID:
4373 case FSF_ACCESS_CONFLICT_DETECTED: 2158 dev_err(&req->adapter->ccw_device->dev,
4374 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) 2159 "Invalid data direction (%d) given for unit "
4375 ZFCP_LOG_NORMAL( 2160 "0x%016Lx on port 0x%016Lx, shutting down "
4376 "CFDC has been discarded by the adapter %s, " 2161 "adapter.\n",
4377 "because activation would impact " 2162 req->qtcb->bottom.io.data_direction,
4378 "%d active connection(s)\n", 2163 unit->fcp_lun, unit->port->wwpn);
4379 zfcp_get_busid_by_adapter(adapter), 2164 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
4380 header->fsf_status_qual.word[0]); 2165 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4381 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4382 retval = -EIO;
4383 break; 2166 break;
4384 2167 case FSF_CMND_LENGTH_NOT_VALID:
4385 case FSF_CONFLICTS_OVERRULED: 2168 dev_err(&req->adapter->ccw_device->dev,
4386 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) 2169 "An invalid control-data-block length field (%d) "
4387 ZFCP_LOG_NORMAL( 2170 "was found in a command for unit 0x%016Lx on port "
4388 "CFDC has been activated on the adapter %s, " 2171 "0x%016Lx. Shutting down adapter.\n",
4389 "but activation has impacted " 2172 req->qtcb->bottom.io.fcp_cmnd_length,
4390 "%d active connection(s)\n", 2173 unit->fcp_lun, unit->port->wwpn);
4391 zfcp_get_busid_by_adapter(adapter), 2174 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
4392 header->fsf_status_qual.word[0]); 2175 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4393 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4394 retval = -EIO;
4395 break; 2176 break;
4396 2177 case FSF_PORT_BOXED:
4397 case FSF_UNKNOWN_OP_SUBTYPE: 2178 zfcp_erp_port_boxed(unit->port, 53, req);
4398 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, " 2179 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
4399 "op_subtype=0x%x)\n", 2180 ZFCP_STATUS_FSFREQ_RETRY;
4400 zfcp_get_busid_by_adapter(adapter),
4401 bottom->operation_subtype);
4402 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4403 retval = -EINVAL;
4404 break; 2181 break;
4405 2182 case FSF_LUN_BOXED:
4406 case FSF_INVALID_COMMAND_OPTION: 2183 zfcp_erp_unit_boxed(unit, 54, req);
4407 ZFCP_LOG_NORMAL( 2184 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
4408 "Invalid option 0x%x has been specified " 2185 ZFCP_STATUS_FSFREQ_RETRY;
4409 "in QTCB bottom sent to the adapter %s\n",
4410 bottom->option,
4411 zfcp_get_busid_by_adapter(adapter));
4412 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4413 retval = -EINVAL;
4414 break; 2186 break;
4415 2187 case FSF_ADAPTER_STATUS_AVAILABLE:
4416 default: 2188 if (header->fsf_status_qual.word[0] ==
4417 ZFCP_LOG_NORMAL( 2189 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
4418 "bug: An unknown/unexpected FSF status 0x%08x " 2190 zfcp_test_link(unit->port);
4419 "was presented on the adapter %s\n", 2191 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4420 header->fsf_status,
4421 zfcp_get_busid_by_adapter(adapter));
4422 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4423 retval = -EINVAL;
4424 break; 2192 break;
4425 } 2193 }
4426
4427skip_fsfstatus: 2194skip_fsfstatus:
4428 return retval; 2195 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
4429} 2196 zfcp_fsf_send_fcp_ctm_handler(req);
4430 2197 else {
4431static inline int 2198 zfcp_fsf_send_fcp_command_task_handler(req);
4432zfcp_fsf_req_sbal_check(unsigned long *flags, 2199 req->unit = NULL;
4433 struct zfcp_qdio_queue *queue, int needed) 2200 zfcp_unit_put(unit);
4434{
4435 write_lock_irqsave(&queue->queue_lock, *flags);
4436 if (likely(atomic_read(&queue->free_count) >= needed))
4437 return 1;
4438 write_unlock_irqrestore(&queue->queue_lock, *flags);
4439 return 0;
4440}
4441
4442/*
4443 * set qtcb pointer in fsf_req and initialize QTCB
4444 */
4445static void
4446zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4447{
4448 if (likely(fsf_req->qtcb != NULL)) {
4449 fsf_req->qtcb->prefix.req_seq_no =
4450 fsf_req->adapter->fsf_req_seq_no;
4451 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
4452 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4453 fsf_req->qtcb->prefix.qtcb_type =
4454 fsf_qtcb_type[fsf_req->fsf_command];
4455 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4456 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
4457 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4458 } 2201 }
4459} 2202}
4460 2203
4461/** 2204/**
4462 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue 2205 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
4463 * @adapter: adapter for which request queue is examined 2206 * @adapter: adapter where scsi command is issued
4464 * @req_flags: flags indicating whether to wait for needed SBAL or not 2207 * @unit: unit where command is sent to
4465 * @lock_flags: lock_flags if queue_lock is taken 2208 * @scsi_cmnd: scsi command to be sent
4466 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS 2209 * @timer: timer to be started when request is initiated
4467 * Locks: lock adapter->request_queue->queue_lock on success 2210 * @req_flags: flags for fsf_request
4468 */
4469static int
4470zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4471 unsigned long *lock_flags)
4472{
4473 long ret;
4474 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4475
4476 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4477 ret = wait_event_interruptible_timeout(adapter->request_wq,
4478 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4479 ZFCP_SBAL_TIMEOUT);
4480 if (ret < 0)
4481 return ret;
4482 if (!ret)
4483 return -EIO;
4484 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4485 return -EIO;
4486
4487 return 0;
4488}
4489
4490/*
4491 * function: zfcp_fsf_req_create
4492 *
4493 * purpose: create an FSF request at the specified adapter and
4494 * setup common fields
4495 *
4496 * returns: -ENOMEM if there was insufficient memory for a request
4497 * -EIO if no qdio buffers could be allocate to the request
4498 * -EINVAL/-EPERM on bug conditions in req_dequeue
4499 * 0 in success
4500 *
4501 * note: The created request is returned by reference.
4502 *
4503 * locks: lock of concerned request queue must not be held,
4504 * but is held on completion (write, irqsave)
4505 */ 2211 */
4506int 2212int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
4507zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags, 2213 struct zfcp_unit *unit,
4508 mempool_t *pool, unsigned long *lock_flags, 2214 struct scsi_cmnd *scsi_cmnd,
4509 struct zfcp_fsf_req **fsf_req_p) 2215 int use_timer, int req_flags)
4510{ 2216{
4511 volatile struct qdio_buffer_element *sbale; 2217 struct zfcp_fsf_req *req;
4512 struct zfcp_fsf_req *fsf_req = NULL; 2218 struct fcp_cmnd_iu *fcp_cmnd_iu;
4513 int ret = 0; 2219 unsigned int sbtype;
4514 struct zfcp_qdio_queue *req_queue = &adapter->request_queue; 2220 int real_bytes, retval = -EIO;
4515
4516 /* allocate new FSF request */
4517 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4518 if (unlikely(NULL == fsf_req)) {
4519 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
4520 "the outbound (send) queue.\n");
4521 ret = -ENOMEM;
4522 goto failed_fsf_req;
4523 }
4524
4525 fsf_req->adapter = adapter;
4526 fsf_req->fsf_command = fsf_cmd;
4527 INIT_LIST_HEAD(&fsf_req->list);
4528 init_timer(&fsf_req->timer);
4529 2221
4530 /* initialize waitqueue which may be used to wait on 2222 if (unlikely(!(atomic_read(&unit->status) &
4531 this request completion */ 2223 ZFCP_STATUS_COMMON_UNBLOCKED)))
4532 init_waitqueue_head(&fsf_req->completion_wq); 2224 return -EBUSY;
4533 2225
4534 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags); 2226 spin_lock(&adapter->req_q.lock);
4535 if (ret < 0) 2227 if (!atomic_read(&adapter->req_q.count))
4536 goto failed_sbals; 2228 goto out;
2229 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2230 adapter->pool.fsf_req_scsi);
2231 if (unlikely(IS_ERR(req))) {
2232 retval = PTR_ERR(req);
2233 goto out;
2234 }
4537 2235
4538 /* this is serialized (we are holding req_queue-lock of adapter) */ 2236 zfcp_unit_get(unit);
4539 if (adapter->req_no == 0) 2237 req->unit = unit;
4540 adapter->req_no++; 2238 req->data = scsi_cmnd;
4541 fsf_req->req_id = adapter->req_no++; 2239 req->handler = zfcp_fsf_send_fcp_command_handler;
2240 req->qtcb->header.lun_handle = unit->handle;
2241 req->qtcb->header.port_handle = unit->port->handle;
2242 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
4542 2243
4543 zfcp_fsf_req_qtcb_init(fsf_req); 2244 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
4544 2245
2246 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2247 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
4545 /* 2248 /*
4546 * We hold queue_lock here. Check if QDIOUP is set and let request fail 2249 * set depending on data direction:
4547 * if it is not set (see also *_open_qdio and *_close_qdio). 2250 * data direction bits in SBALE (SB Type)
2251 * data direction bits in QTCB
2252 * data direction bits in FCP_CMND IU
4548 */ 2253 */
4549 2254 switch (scsi_cmnd->sc_data_direction) {
4550 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) { 2255 case DMA_NONE:
4551 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags); 2256 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
4552 ret = -EIO; 2257 sbtype = SBAL_FLAGS0_TYPE_READ;
4553 goto failed_sbals; 2258 break;
2259 case DMA_FROM_DEVICE:
2260 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2261 sbtype = SBAL_FLAGS0_TYPE_READ;
2262 fcp_cmnd_iu->rddata = 1;
2263 break;
2264 case DMA_TO_DEVICE:
2265 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2266 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2267 fcp_cmnd_iu->wddata = 1;
2268 break;
2269 case DMA_BIDIRECTIONAL:
2270 default:
2271 retval = -EIO;
2272 goto failed_scsi_cmnd;
4554 } 2273 }
4555 2274
4556 if (fsf_req->qtcb) { 2275 if (likely((scsi_cmnd->device->simple_tags) ||
4557 fsf_req->seq_no = adapter->fsf_req_seq_no; 2276 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
4558 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; 2277 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
4559 } 2278 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
4560 fsf_req->sbal_number = 1; 2279 else
4561 fsf_req->sbal_first = req_queue->free_index; 2280 fcp_cmnd_iu->task_attribute = UNTAGGED;
4562 fsf_req->sbal_curr = req_queue->free_index;
4563 fsf_req->sbale_curr = 1;
4564 2281
4565 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) { 2282 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
4566 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 2283 fcp_cmnd_iu->add_fcp_cdb_length =
4567 } 2284 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
4568 2285
4569 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 2286 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
4570 2287
4571 /* setup common SBALE fields */ 2288 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
4572 sbale[0].addr = (void *) fsf_req->req_id; 2289 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
4573 sbale[0].flags |= SBAL_FLAGS0_COMMAND; 2290
4574 if (likely(fsf_req->qtcb != NULL)) { 2291 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
4575 sbale[1].addr = (void *) fsf_req->qtcb; 2292 scsi_sglist(scsi_cmnd),
4576 sbale[1].length = sizeof(struct fsf_qtcb); 2293 FSF_MAX_SBALS_PER_REQ);
2294 if (unlikely(real_bytes < 0)) {
2295 if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
2296 retval = -EIO;
2297 else {
2298 dev_err(&adapter->ccw_device->dev,
2299 "SCSI request too large. "
2300 "Shutting down unit 0x%016Lx on port "
2301 "0x%016Lx.\n", unit->fcp_lun,
2302 unit->port->wwpn);
2303 zfcp_erp_unit_shutdown(unit, 0, 131, req);
2304 retval = -EINVAL;
2305 }
2306 goto failed_scsi_cmnd;
4577 } 2307 }
4578 2308
4579 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n", 2309 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
4580 fsf_req->sbal_number, fsf_req->sbal_first);
4581 2310
4582 goto success; 2311 if (use_timer)
2312 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
4583 2313
4584 failed_sbals: 2314 retval = zfcp_fsf_req_send(req);
4585/* dequeue new FSF request previously enqueued */ 2315 if (unlikely(retval))
4586 zfcp_fsf_req_free(fsf_req); 2316 goto failed_scsi_cmnd;
4587 fsf_req = NULL;
4588 2317
4589 failed_fsf_req: 2318 goto out;
4590 write_lock_irqsave(&req_queue->queue_lock, *lock_flags); 2319
4591 success: 2320failed_scsi_cmnd:
4592 *fsf_req_p = fsf_req; 2321 zfcp_unit_put(unit);
4593 return ret; 2322 zfcp_fsf_req_free(req);
2323 scsi_cmnd->host_scribble = NULL;
2324out:
2325 spin_unlock(&adapter->req_q.lock);
2326 return retval;
4594} 2327}
4595 2328
4596/* 2329/**
4597 * function: zfcp_fsf_req_send 2330 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
4598 * 2331 * @adapter: pointer to struct zfcp-adapter
4599 * purpose: start transfer of FSF request via QDIO 2332 * @unit: pointer to struct zfcp_unit
4600 * 2333 * @tm_flags: unsigned byte for task management flags
4601 * returns: 0 - request transfer succesfully started 2334 * @req_flags: int request flags
4602 * !0 - start of request transfer failed 2335 * Returns: on success pointer to struct fsf_req, NULL otherwise
4603 */ 2336 */
4604static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req) 2337struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
2338 struct zfcp_unit *unit,
2339 u8 tm_flags, int req_flags)
4605{ 2340{
4606 struct zfcp_adapter *adapter;
4607 struct zfcp_qdio_queue *req_queue;
4608 volatile struct qdio_buffer_element *sbale; 2341 volatile struct qdio_buffer_element *sbale;
4609 int inc_seq_no; 2342 struct zfcp_fsf_req *req = NULL;
4610 int new_distance_from_int; 2343 struct fcp_cmnd_iu *fcp_cmnd_iu;
4611 int retval = 0;
4612 2344
4613 adapter = fsf_req->adapter; 2345 if (unlikely(!(atomic_read(&unit->status) &
4614 req_queue = &adapter->request_queue, 2346 ZFCP_STATUS_COMMON_UNBLOCKED)))
2347 return NULL;
4615 2348
2349 spin_lock(&adapter->req_q.lock);
2350 if (!atomic_read(&adapter->req_q.count))
2351 goto out;
2352 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2353 adapter->pool.fsf_req_scsi);
2354 if (unlikely(IS_ERR(req)))
2355 goto out;
4616 2356
4617 /* FIXME(debug): remove it later */ 2357 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
4618 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0); 2358 req->data = unit;
4619 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags); 2359 req->handler = zfcp_fsf_send_fcp_command_handler;
4620 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n"); 2360 req->qtcb->header.lun_handle = unit->handle;
4621 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr, 2361 req->qtcb->header.port_handle = unit->port->handle;
4622 sbale[1].length); 2362 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2363 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2364 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2365 sizeof(fcp_dl_t);
2366
2367 sbale = zfcp_qdio_sbale_req(req);
2368 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2369 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4623 2370
4624 /* put allocated FSF request into hash table */ 2371 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
4625 spin_lock(&adapter->req_list_lock); 2372 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
4626 zfcp_reqlist_add(adapter, fsf_req); 2373 fcp_cmnd_iu->task_management_flags = tm_flags;
4627 spin_unlock(&adapter->req_list_lock);
4628 2374
4629 inc_seq_no = (fsf_req->qtcb != NULL); 2375 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2376 if (!zfcp_fsf_req_send(req))
2377 goto out;
4630 2378
4631 ZFCP_LOG_TRACE("request queue of adapter %s: " 2379 zfcp_fsf_req_free(req);
4632 "next free SBAL is %i, %i free SBALs\n", 2380 req = NULL;
4633 zfcp_get_busid_by_adapter(adapter), 2381out:
4634 req_queue->free_index, 2382 spin_unlock(&adapter->req_q.lock);
4635 atomic_read(&req_queue->free_count)); 2383 return req;
2384}
4636 2385
4637 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, " 2386static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
4638 "index_in_queue=%i, count=%i, buffers=%p\n", 2387{
4639 zfcp_get_busid_by_adapter(adapter), 2388 if (req->qtcb->header.fsf_status != FSF_GOOD)
4640 QDIO_FLAG_SYNC_OUTPUT, 2389 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4641 0, fsf_req->sbal_first, fsf_req->sbal_number, 2390}
4642 &req_queue->buffer[fsf_req->sbal_first]);
4643 2391
4644 /* 2392/**
4645 * adjust the number of free SBALs in request queue as well as 2393 * zfcp_fsf_control_file - control file upload/download
4646 * position of first one 2394 * @adapter: pointer to struct zfcp_adapter
4647 */ 2395 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
4648 atomic_sub(fsf_req->sbal_number, &req_queue->free_count); 2396 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
4649 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count)); 2397 */
4650 req_queue->free_index += fsf_req->sbal_number; /* increase */ 2398struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4651 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */ 2399 struct zfcp_fsf_cfdc *fsf_cfdc)
4652 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req); 2400{
2401 volatile struct qdio_buffer_element *sbale;
2402 struct zfcp_fsf_req *req = NULL;
2403 struct fsf_qtcb_bottom_support *bottom;
2404 int direction, retval = -EIO, bytes;
2405
2406 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2407 return ERR_PTR(-EOPNOTSUPP);
2408
2409 switch (fsf_cfdc->command) {
2410 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2411 direction = SBAL_FLAGS0_TYPE_WRITE;
2412 break;
2413 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2414 direction = SBAL_FLAGS0_TYPE_READ;
2415 break;
2416 default:
2417 return ERR_PTR(-EINVAL);
2418 }
4653 2419
4654 fsf_req->issued = get_clock(); 2420 spin_lock(&adapter->req_q.lock);
2421 if (zfcp_fsf_req_sbal_get(adapter))
2422 goto out;
4655 2423
4656 retval = do_QDIO(adapter->ccw_device, 2424 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
4657 QDIO_FLAG_SYNC_OUTPUT, 2425 if (unlikely(IS_ERR(req))) {
4658 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL); 2426 retval = -EPERM;
2427 goto out;
2428 }
4659 2429
4660 if (unlikely(retval)) { 2430 req->handler = zfcp_fsf_control_file_handler;
4661 /* Queues are down..... */ 2431
4662 retval = -EIO; 2432 sbale = zfcp_qdio_sbale_req(req);
4663 del_timer(&fsf_req->timer); 2433 sbale[0].flags |= direction;
4664 spin_lock(&adapter->req_list_lock);
4665 zfcp_reqlist_remove(adapter, fsf_req);
4666 spin_unlock(&adapter->req_list_lock);
4667 /* undo changes in request queue made for this request */
4668 zfcp_qdio_zero_sbals(req_queue->buffer,
4669 fsf_req->sbal_first, fsf_req->sbal_number);
4670 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4671 req_queue->free_index -= fsf_req->sbal_number;
4672 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4673 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4674 zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
4675 } else {
4676 req_queue->distance_from_int = new_distance_from_int;
4677 /*
4678 * increase FSF sequence counter -
4679 * this must only be done for request successfully enqueued to
4680 * QDIO this rejected requests may be cleaned up by calling
4681 * routines resulting in missing sequence counter values
4682 * otherwise,
4683 */
4684 2434
4685 /* Don't increase for unsolicited status */ 2435 bottom = &req->qtcb->bottom.support;
4686 if (inc_seq_no) 2436 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4687 adapter->fsf_req_seq_no++; 2437 bottom->option = fsf_cfdc->option;
4688 2438
4689 /* count FSF requests pending */ 2439 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
4690 atomic_inc(&adapter->reqs_active); 2440 FSF_MAX_SBALS_PER_REQ);
2441 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2442 retval = -ENOMEM;
2443 zfcp_fsf_req_free(req);
2444 goto out;
4691 } 2445 }
4692 return retval;
4693}
4694 2446
4695#undef ZFCP_LOG_AREA 2447 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2448 retval = zfcp_fsf_req_send(req);
2449out:
2450 spin_unlock(&adapter->req_q.lock);
2451
2452 if (!retval) {
2453 wait_event(req->completion_wq,
2454 req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2455 return req;
2456 }
2457 return ERR_PTR(retval);
2458}