Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
553448f6 | 3 | * zfcp device driver |
1da177e4 | 4 | * |
553448f6 | 5 | * Implementation of FSF commands. |
1da177e4 | 6 | * |
6e2e4900 | 7 | * Copyright IBM Corp. 2002, 2018 |
1da177e4 LT |
8 | */ |
9 | ||
ecf39d42 CS |
10 | #define KMSG_COMPONENT "zfcp" |
11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
12 | ||
0997f1c5 | 13 | #include <linux/blktrace_api.h> |
7e418833 | 14 | #include <linux/jiffies.h> |
b76becde | 15 | #include <linux/types.h> |
5a0e3ad6 | 16 | #include <linux/slab.h> |
9d05ce2c | 17 | #include <scsi/fc/fc_els.h> |
1da177e4 | 18 | #include "zfcp_ext.h" |
4318e08c | 19 | #include "zfcp_fc.h" |
dcd20e23 | 20 | #include "zfcp_dbf.h" |
34c2b712 | 21 | #include "zfcp_qdio.h" |
b6bd2fb9 | 22 | #include "zfcp_reqlist.h" |
7e418833 | 23 | #include "zfcp_diag.h" |
1da177e4 | 24 | |
a0e86d95 SM |
25 | /* timeout for FSF requests sent during scsi_eh: abort or FCP TMF */ |
26 | #define ZFCP_FSF_SCSI_ER_TIMEOUT (10*HZ) | |
27 | /* timeout for: exchange config/port data outside ERP, or open/close WKA port */ | |
28 | #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ) | |
29 | ||
259afe2e CS |
30 | struct kmem_cache *zfcp_fsf_qtcb_cache; |
31 | ||
2190168a SM |
32 | static bool ber_stop = true; |
33 | module_param(ber_stop, bool, 0600); | |
34 | MODULE_PARM_DESC(ber_stop, | |
35 | "Shuts down FCP devices for FCP channels that report a bit-error count in excess of its threshold (default on)"); | |
36 | ||
75492a51 | 37 | static void zfcp_fsf_request_timeout_handler(struct timer_list *t) |
287ac01a | 38 | { |
75492a51 KC |
39 | struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer); |
40 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
5c13db9b | 41 | |
339f4f4e | 42 | zfcp_qdio_siosl(adapter); |
5ffd51a5 | 43 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, |
ea4a3a6a | 44 | "fsrth_1"); |
287ac01a CS |
45 | } |
46 | ||
47 | static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, | |
48 | unsigned long timeout) | |
49 | { | |
841b86f3 | 50 | fsf_req->timer.function = zfcp_fsf_request_timeout_handler; |
287ac01a CS |
51 | fsf_req->timer.expires = jiffies + timeout; |
52 | add_timer(&fsf_req->timer); | |
53 | } | |
54 | ||
55 | static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req) | |
56 | { | |
57 | BUG_ON(!fsf_req->erp_action); | |
841b86f3 | 58 | fsf_req->timer.function = zfcp_erp_timeout_handler; |
287ac01a CS |
59 | fsf_req->timer.expires = jiffies + 30 * HZ; |
60 | add_timer(&fsf_req->timer); | |
61 | } | |
62 | ||
1da177e4 LT |
63 | /* association between FSF command and FSF QTCB type */ |
64 | static u32 fsf_qtcb_type[] = { | |
65 | [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND, | |
66 | [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND, | |
67 | [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND, | |
68 | [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND, | |
69 | [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND, | |
70 | [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND, | |
71 | [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND, | |
72 | [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND, | |
73 | [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND, | |
74 | [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND, | |
75 | [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND, | |
76 | [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND, | |
77 | [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND | |
78 | }; | |
79 | ||
553448f6 CS |
80 | static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req) |
81 | { | |
ff3b24fa CS |
82 | dev_err(&req->adapter->ccw_device->dev, "FCP device not " |
83 | "operational because of an unsupported FC class\n"); | |
ea4a3a6a | 84 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1"); |
553448f6 CS |
85 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
86 | } | |
87 | ||
c41f8cbd SS |
88 | /** |
89 | * zfcp_fsf_req_free - free memory used by fsf request | |
8684d614 | 90 | * @req: pointer to struct zfcp_fsf_req |
1da177e4 | 91 | */ |
c41f8cbd | 92 | void zfcp_fsf_req_free(struct zfcp_fsf_req *req) |
1da177e4 | 93 | { |
c41f8cbd | 94 | if (likely(req->pool)) { |
f9eca022 | 95 | if (likely(!zfcp_fsf_req_is_status_read_buffer(req))) |
a4623c46 | 96 | mempool_free(req->qtcb, req->adapter->pool.qtcb_pool); |
c41f8cbd | 97 | mempool_free(req, req->pool); |
dd52e0ea HC |
98 | return; |
99 | } | |
100 | ||
f9eca022 | 101 | if (likely(!zfcp_fsf_req_is_status_read_buffer(req))) |
259afe2e | 102 | kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb); |
a4623c46 | 103 | kfree(req); |
1da177e4 LT |
104 | } |
105 | ||
c41f8cbd | 106 | static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req) |
1da177e4 | 107 | { |
ecf0c772 | 108 | unsigned long flags; |
c41f8cbd SS |
109 | struct fsf_status_read_buffer *sr_buf = req->data; |
110 | struct zfcp_adapter *adapter = req->adapter; | |
111 | struct zfcp_port *port; | |
800c0cad | 112 | int d_id = ntoh24(sr_buf->d_id); |
1da177e4 | 113 | |
ecf0c772 SS |
114 | read_lock_irqsave(&adapter->port_list_lock, flags); |
115 | list_for_each_entry(port, &adapter->port_list, list) | |
c41f8cbd | 116 | if (port->d_id == d_id) { |
ea4a3a6a | 117 | zfcp_erp_port_reopen(port, 0, "fssrpc1"); |
ecf0c772 | 118 | break; |
c41f8cbd | 119 | } |
ecf0c772 | 120 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
1da177e4 LT |
121 | } |
122 | ||
edaed859 | 123 | static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, |
c41f8cbd | 124 | struct fsf_link_down_info *link_down) |
aef4a983 | 125 | { |
c41f8cbd | 126 | struct zfcp_adapter *adapter = req->adapter; |
698ec016 | 127 | |
c41f8cbd | 128 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) |
ee69ab7a MS |
129 | return; |
130 | ||
805de8f4 | 131 | atomic_or(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); |
70932935 | 132 | |
a2fa0aed | 133 | zfcp_scsi_schedule_rports_block(adapter); |
ee69ab7a | 134 | |
c41f8cbd | 135 | if (!link_down) |
2f8f3ed5 | 136 | goto out; |
ee69ab7a | 137 | |
aef4a983 MS |
138 | switch (link_down->error_code) { |
139 | case FSF_PSQ_LINK_NO_LIGHT: | |
c41f8cbd | 140 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
141 | "There is no light signal from the local " |
142 | "fibre channel cable\n"); | |
aef4a983 MS |
143 | break; |
144 | case FSF_PSQ_LINK_WRAP_PLUG: | |
c41f8cbd | 145 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
146 | "There is a wrap plug instead of a fibre " |
147 | "channel cable\n"); | |
aef4a983 MS |
148 | break; |
149 | case FSF_PSQ_LINK_NO_FCP: | |
c41f8cbd | 150 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
151 | "The adjacent fibre channel node does not " |
152 | "support FCP\n"); | |
aef4a983 MS |
153 | break; |
154 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: | |
c41f8cbd | 155 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
156 | "The FCP device is suspended because of a " |
157 | "firmware update\n"); | |
553448f6 | 158 | break; |
aef4a983 | 159 | case FSF_PSQ_LINK_INVALID_WWPN: |
c41f8cbd | 160 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
161 | "The FCP device detected a WWPN that is " |
162 | "duplicate or not valid\n"); | |
aef4a983 MS |
163 | break; |
164 | case FSF_PSQ_LINK_NO_NPIV_SUPPORT: | |
c41f8cbd | 165 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa | 166 | "The fibre channel fabric does not support NPIV\n"); |
aef4a983 MS |
167 | break; |
168 | case FSF_PSQ_LINK_NO_FCP_RESOURCES: | |
c41f8cbd | 169 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa | 170 | "The FCP adapter cannot support more NPIV ports\n"); |
aef4a983 MS |
171 | break; |
172 | case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: | |
c41f8cbd | 173 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
174 | "The adjacent switch cannot support " |
175 | "more NPIV ports\n"); | |
aef4a983 MS |
176 | break; |
177 | case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: | |
c41f8cbd | 178 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
179 | "The FCP adapter could not log in to the " |
180 | "fibre channel fabric\n"); | |
aef4a983 MS |
181 | break; |
182 | case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: | |
c41f8cbd | 183 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
184 | "The WWPN assignment file on the FCP adapter " |
185 | "has been damaged\n"); | |
aef4a983 MS |
186 | break; |
187 | case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: | |
c41f8cbd | 188 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
189 | "The mode table on the FCP adapter " |
190 | "has been damaged\n"); | |
aef4a983 MS |
191 | break; |
192 | case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: | |
c41f8cbd | 193 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
194 | "All NPIV ports on the FCP adapter have " |
195 | "been assigned\n"); | |
aef4a983 MS |
196 | break; |
197 | default: | |
c41f8cbd | 198 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa CS |
199 | "The link between the FCP adapter and " |
200 | "the FC fabric is down\n"); | |
aef4a983 | 201 | } |
c41f8cbd | 202 | out: |
edaed859 | 203 | zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED); |
aef4a983 MS |
204 | } |
205 | ||
c41f8cbd | 206 | static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req) |
1da177e4 | 207 | { |
c41f8cbd SS |
208 | struct fsf_status_read_buffer *sr_buf = req->data; |
209 | struct fsf_link_down_info *ldi = | |
210 | (struct fsf_link_down_info *) &sr_buf->payload; | |
1da177e4 | 211 | |
c41f8cbd SS |
212 | switch (sr_buf->status_subtype) { |
213 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: | |
c41f8cbd | 214 | case FSF_STATUS_READ_SUB_FDISC_FAILED: |
edaed859 | 215 | zfcp_fsf_link_down_info_eval(req, ldi); |
1da177e4 | 216 | break; |
c41f8cbd | 217 | case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE: |
edaed859 | 218 | zfcp_fsf_link_down_info_eval(req, NULL); |
3b974874 | 219 | } |
c41f8cbd | 220 | } |
1da177e4 | 221 | |
c41f8cbd SS |
222 | static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req) |
223 | { | |
224 | struct zfcp_adapter *adapter = req->adapter; | |
225 | struct fsf_status_read_buffer *sr_buf = req->data; | |
1da177e4 | 226 | |
c41f8cbd | 227 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
a54ca0f6 | 228 | zfcp_dbf_hba_fsf_uss("fssrh_1", req); |
c7b279ae | 229 | mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data); |
c41f8cbd SS |
230 | zfcp_fsf_req_free(req); |
231 | return; | |
232 | } | |
1da177e4 | 233 | |
0100998d | 234 | zfcp_dbf_hba_fsf_uss("fssrh_4", req); |
1da177e4 | 235 | |
c41f8cbd SS |
236 | switch (sr_buf->status_type) { |
237 | case FSF_STATUS_READ_PORT_CLOSED: | |
238 | zfcp_fsf_status_read_port_closed(req); | |
1da177e4 | 239 | break; |
c41f8cbd SS |
240 | case FSF_STATUS_READ_INCOMING_ELS: |
241 | zfcp_fc_incoming_els(req); | |
1da177e4 | 242 | break; |
c41f8cbd | 243 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: |
1da177e4 | 244 | break; |
c41f8cbd | 245 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: |
a54ca0f6 | 246 | zfcp_dbf_hba_bit_err("fssrh_3", req); |
2190168a SM |
247 | if (ber_stop) { |
248 | dev_warn(&adapter->ccw_device->dev, | |
249 | "All paths over this FCP device are disused because of excessive bit errors\n"); | |
250 | zfcp_erp_adapter_shutdown(adapter, 0, "fssrh_b"); | |
251 | } else { | |
252 | dev_warn(&adapter->ccw_device->dev, | |
253 | "The error threshold for checksum statistics has been exceeded\n"); | |
254 | } | |
1da177e4 | 255 | break; |
c41f8cbd SS |
256 | case FSF_STATUS_READ_LINK_DOWN: |
257 | zfcp_fsf_status_read_link_down(req); | |
2d1e547f | 258 | zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0); |
c41f8cbd SS |
259 | break; |
260 | case FSF_STATUS_READ_LINK_UP: | |
261 | dev_info(&adapter->ccw_device->dev, | |
ff3b24fa | 262 | "The local link has been restored\n"); |
c41f8cbd | 263 | /* All ports should be marked as ready to run again */ |
edaed859 SS |
264 | zfcp_erp_set_adapter_status(adapter, |
265 | ZFCP_STATUS_COMMON_RUNNING); | |
c41f8cbd SS |
266 | zfcp_erp_adapter_reopen(adapter, |
267 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | | |
268 | ZFCP_STATUS_COMMON_ERP_FAILED, | |
ea4a3a6a | 269 | "fssrh_2"); |
2d1e547f SS |
270 | zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0); |
271 | ||
c41f8cbd SS |
272 | break; |
273 | case FSF_STATUS_READ_NOTIFICATION_LOST: | |
c41f8cbd | 274 | if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS) |
43f60cbd | 275 | zfcp_fc_conditional_port_scan(adapter); |
c41f8cbd | 276 | break; |
c41f8cbd SS |
277 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: |
278 | adapter->adapter_features = sr_buf->payload.word[0]; | |
1da177e4 | 279 | break; |
1da177e4 LT |
280 | } |
281 | ||
c7b279ae | 282 | mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data); |
c41f8cbd | 283 | zfcp_fsf_req_free(req); |
1da177e4 | 284 | |
c41f8cbd | 285 | atomic_inc(&adapter->stat_miss); |
4544683a | 286 | queue_work(adapter->work_queue, &adapter->stat_work); |
c41f8cbd | 287 | } |
1da177e4 | 288 | |
c41f8cbd SS |
289 | static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req) |
290 | { | |
291 | switch (req->qtcb->header.fsf_status_qual.word[0]) { | |
292 | case FSF_SQ_FCP_RSP_AVAILABLE: | |
293 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
294 | case FSF_SQ_NO_RETRY_POSSIBLE: | |
295 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
296 | return; | |
297 | case FSF_SQ_COMMAND_ABORTED: | |
c41f8cbd SS |
298 | break; |
299 | case FSF_SQ_NO_RECOM: | |
300 | dev_err(&req->adapter->ccw_device->dev, | |
ff3b24fa CS |
301 | "The FCP adapter reported a problem " |
302 | "that cannot be recovered\n"); | |
339f4f4e | 303 | zfcp_qdio_siosl(req->adapter); |
ea4a3a6a | 304 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1"); |
c41f8cbd SS |
305 | break; |
306 | } | |
307 | /* all non-return stats set FSFREQ_ERROR*/ | |
308 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1da177e4 LT |
309 | } |
310 | ||
c41f8cbd | 311 | static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req) |
1da177e4 | 312 | { |
c41f8cbd SS |
313 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
314 | return; | |
1da177e4 | 315 | |
c41f8cbd SS |
316 | switch (req->qtcb->header.fsf_status) { |
317 | case FSF_UNKNOWN_COMMAND: | |
318 | dev_err(&req->adapter->ccw_device->dev, | |
ff3b24fa | 319 | "The FCP adapter does not recognize the command 0x%x\n", |
c41f8cbd | 320 | req->qtcb->header.fsf_command); |
ea4a3a6a | 321 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1"); |
c41f8cbd SS |
322 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
323 | break; | |
324 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
325 | zfcp_fsf_fsfstatus_qual_eval(req); | |
326 | break; | |
327 | } | |
328 | } | |
1da177e4 | 329 | |
c41f8cbd SS |
330 | static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req) |
331 | { | |
332 | struct zfcp_adapter *adapter = req->adapter; | |
333 | struct fsf_qtcb *qtcb = req->qtcb; | |
334 | union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual; | |
1da177e4 | 335 | |
5771710b | 336 | zfcp_dbf_hba_fsf_response(req); |
1da177e4 | 337 | |
c41f8cbd | 338 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
4c571c65 | 339 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
c41f8cbd SS |
340 | return; |
341 | } | |
1da177e4 | 342 | |
c41f8cbd SS |
343 | switch (qtcb->prefix.prot_status) { |
344 | case FSF_PROT_GOOD: | |
345 | case FSF_PROT_FSF_STATUS_PRESENTED: | |
346 | return; | |
347 | case FSF_PROT_QTCB_VERSION_ERROR: | |
348 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa CS |
349 | "QTCB version 0x%x not supported by FCP adapter " |
350 | "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION, | |
351 | psq->word[0], psq->word[1]); | |
ea4a3a6a | 352 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1"); |
c41f8cbd SS |
353 | break; |
354 | case FSF_PROT_ERROR_STATE: | |
355 | case FSF_PROT_SEQ_NUMB_ERROR: | |
ea4a3a6a | 356 | zfcp_erp_adapter_reopen(adapter, 0, "fspse_2"); |
4c571c65 | 357 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
c41f8cbd SS |
358 | break; |
359 | case FSF_PROT_UNSUPP_QTCB_TYPE: | |
360 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa | 361 | "The QTCB type is not supported by the FCP adapter\n"); |
ea4a3a6a | 362 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3"); |
c41f8cbd SS |
363 | break; |
364 | case FSF_PROT_HOST_CONNECTION_INITIALIZING: | |
805de8f4 | 365 | atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
c41f8cbd SS |
366 | &adapter->status); |
367 | break; | |
368 | case FSF_PROT_DUPLICATE_REQUEST_ID: | |
369 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa | 370 | "0x%Lx is an ambiguous request identifier\n", |
c41f8cbd | 371 | (unsigned long long)qtcb->bottom.support.req_handle); |
ea4a3a6a | 372 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4"); |
c41f8cbd SS |
373 | break; |
374 | case FSF_PROT_LINK_DOWN: | |
edaed859 | 375 | zfcp_fsf_link_down_info_eval(req, &psq->link_down_info); |
452b505c | 376 | /* go through reopen to flush pending requests */ |
ea4a3a6a | 377 | zfcp_erp_adapter_reopen(adapter, 0, "fspse_6"); |
c41f8cbd SS |
378 | break; |
379 | case FSF_PROT_REEST_QUEUE: | |
380 | /* All ports should be marked as ready to run again */ | |
edaed859 SS |
381 | zfcp_erp_set_adapter_status(adapter, |
382 | ZFCP_STATUS_COMMON_RUNNING); | |
c41f8cbd SS |
383 | zfcp_erp_adapter_reopen(adapter, |
384 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | | |
5ffd51a5 | 385 | ZFCP_STATUS_COMMON_ERP_FAILED, |
ea4a3a6a | 386 | "fspse_8"); |
c41f8cbd SS |
387 | break; |
388 | default: | |
389 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa | 390 | "0x%x is not a valid transfer protocol status\n", |
c41f8cbd | 391 | qtcb->prefix.prot_status); |
339f4f4e | 392 | zfcp_qdio_siosl(adapter); |
ea4a3a6a | 393 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9"); |
c41f8cbd SS |
394 | } |
395 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1da177e4 LT |
396 | } |
397 | ||
c41f8cbd SS |
398 | /** |
399 | * zfcp_fsf_req_complete - process completion of a FSF request | |
8684d614 | 400 | * @req: The FSF request that has been completed. |
c41f8cbd SS |
401 | * |
402 | * When a request has been completed either from the FCP adapter, | |
403 | * or it has been dismissed due to a queue shutdown, this function | |
404 | * is called to process the completion status and trigger further | |
405 | * events related to the FSF request. | |
406 | */ | |
bd63eaf4 | 407 | static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req) |
1da177e4 | 408 | { |
f9eca022 | 409 | if (unlikely(zfcp_fsf_req_is_status_read_buffer(req))) { |
c41f8cbd SS |
410 | zfcp_fsf_status_read_handler(req); |
411 | return; | |
412 | } | |
1da177e4 | 413 | |
c41f8cbd SS |
414 | del_timer(&req->timer); |
415 | zfcp_fsf_protstatus_eval(req); | |
416 | zfcp_fsf_fsfstatus_eval(req); | |
417 | req->handler(req); | |
1da177e4 | 418 | |
c41f8cbd | 419 | if (req->erp_action) |
287ac01a | 420 | zfcp_erp_notify(req->erp_action, 0); |
1da177e4 | 421 | |
c41f8cbd SS |
422 | if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP)) |
423 | zfcp_fsf_req_free(req); | |
424 | else | |
058b8647 | 425 | complete(&req->completion); |
c41f8cbd | 426 | } |
1da177e4 | 427 | |
bd63eaf4 SS |
428 | /** |
429 | * zfcp_fsf_req_dismiss_all - dismiss all fsf requests | |
430 | * @adapter: pointer to struct zfcp_adapter | |
431 | * | |
432 | * Never ever call this without shutting down the adapter first. | |
433 | * Otherwise the adapter would continue using and corrupting s390 storage. | |
434 | * Included BUG_ON() call to ensure this is done. | |
435 | * ERP is supposed to be the only user of this function. | |
436 | */ | |
437 | void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) | |
438 | { | |
439 | struct zfcp_fsf_req *req, *tmp; | |
bd63eaf4 | 440 | LIST_HEAD(remove_queue); |
bd63eaf4 SS |
441 | |
442 | BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP); | |
b6bd2fb9 | 443 | zfcp_reqlist_move(adapter->req_list, &remove_queue); |
bd63eaf4 SS |
444 | |
445 | list_for_each_entry_safe(req, tmp, &remove_queue, list) { | |
446 | list_del(&req->list); | |
447 | req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; | |
448 | zfcp_fsf_req_complete(req); | |
449 | } | |
450 | } | |
451 | ||
d2201977 SM |
452 | #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0) |
453 | #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1) | |
454 | #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2) | |
455 | #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3) | |
456 | #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4) | |
457 | #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5) | |
6e2e4900 JR |
458 | #define ZFCP_FSF_PORTSPEED_32GBIT (1 << 6) |
459 | #define ZFCP_FSF_PORTSPEED_64GBIT (1 << 7) | |
460 | #define ZFCP_FSF_PORTSPEED_128GBIT (1 << 8) | |
d2201977 SM |
461 | #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15) |
462 | ||
463 | static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed) | |
464 | { | |
465 | u32 fdmi_speed = 0; | |
466 | if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT) | |
467 | fdmi_speed |= FC_PORTSPEED_1GBIT; | |
468 | if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT) | |
469 | fdmi_speed |= FC_PORTSPEED_2GBIT; | |
470 | if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT) | |
471 | fdmi_speed |= FC_PORTSPEED_4GBIT; | |
472 | if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT) | |
473 | fdmi_speed |= FC_PORTSPEED_10GBIT; | |
474 | if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT) | |
475 | fdmi_speed |= FC_PORTSPEED_8GBIT; | |
476 | if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT) | |
477 | fdmi_speed |= FC_PORTSPEED_16GBIT; | |
6e2e4900 JR |
478 | if (fsf_speed & ZFCP_FSF_PORTSPEED_32GBIT) |
479 | fdmi_speed |= FC_PORTSPEED_32GBIT; | |
480 | if (fsf_speed & ZFCP_FSF_PORTSPEED_64GBIT) | |
481 | fdmi_speed |= FC_PORTSPEED_64GBIT; | |
482 | if (fsf_speed & ZFCP_FSF_PORTSPEED_128GBIT) | |
483 | fdmi_speed |= FC_PORTSPEED_128GBIT; | |
d2201977 SM |
484 | if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED) |
485 | fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED; | |
486 | return fdmi_speed; | |
487 | } | |
488 | ||
c41f8cbd SS |
489 | static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req) |
490 | { | |
9d05ce2c | 491 | struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config; |
c41f8cbd SS |
492 | struct zfcp_adapter *adapter = req->adapter; |
493 | struct Scsi_Host *shost = adapter->scsi_host; | |
9d05ce2c | 494 | struct fc_els_flogi *nsp, *plogi; |
1da177e4 | 495 | |
9d05ce2c CS |
496 | /* adjust pointers for missing command code */ |
497 | nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param | |
498 | - sizeof(u32)); | |
499 | plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload | |
500 | - sizeof(u32)); | |
1da177e4 | 501 | |
c41f8cbd SS |
502 | if (req->data) |
503 | memcpy(req->data, bottom, sizeof(*bottom)); | |
504 | ||
9d464fc1 SM |
505 | fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn); |
506 | fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn); | |
c41f8cbd SS |
507 | fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; |
508 | ||
faf4cd85 | 509 | adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK; |
8d88cf3f CS |
510 | adapter->stat_read_buf_num = max(bottom->status_read_buf_num, |
511 | (u16)FSF_STATUS_READS_RECOM); | |
c41f8cbd SS |
512 | |
513 | if (fc_host_permanent_port_name(shost) == -1) | |
514 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); | |
515 | ||
9edf7d75 SM |
516 | zfcp_scsi_set_prot(adapter); |
517 | ||
518 | /* no error return above here, otherwise must fix call chains */ | |
519 | /* do not evaluate invalid fields */ | |
520 | if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE) | |
521 | return 0; | |
522 | ||
523 | fc_host_port_id(shost) = ntoh24(bottom->s_id); | |
524 | fc_host_speed(shost) = | |
525 | zfcp_fsf_convert_portspeed(bottom->fc_link_speed); | |
526 | ||
527 | adapter->hydra_version = bottom->adapter_type; | |
528 | ||
c41f8cbd SS |
529 | switch (bottom->fc_topology) { |
530 | case FSF_TOPO_P2P: | |
800c0cad | 531 | adapter->peer_d_id = ntoh24(bottom->peer_d_id); |
9d464fc1 SM |
532 | adapter->peer_wwpn = be64_to_cpu(plogi->fl_wwpn); |
533 | adapter->peer_wwnn = be64_to_cpu(plogi->fl_wwnn); | |
c41f8cbd | 534 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; |
c41f8cbd SS |
535 | break; |
536 | case FSF_TOPO_FABRIC: | |
bd77befa SM |
537 | if (bottom->connection_features & FSF_FEATURE_NPIV_MODE) |
538 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | |
539 | else | |
540 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; | |
c41f8cbd SS |
541 | break; |
542 | case FSF_TOPO_AL: | |
543 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; | |
dceab655 | 544 | /* fall through */ |
c41f8cbd | 545 | default: |
c41f8cbd | 546 | dev_err(&adapter->ccw_device->dev, |
ff3b24fa CS |
547 | "Unknown or unsupported arbitrated loop " |
548 | "fibre channel topology detected\n"); | |
ea4a3a6a | 549 | zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1"); |
c41f8cbd | 550 | return -EIO; |
1da177e4 | 551 | } |
c41f8cbd | 552 | |
1da177e4 LT |
553 | return 0; |
554 | } | |
555 | ||
c41f8cbd | 556 | static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req) |
553448f6 CS |
557 | { |
558 | struct zfcp_adapter *adapter = req->adapter; | |
08821023 BB |
559 | struct zfcp_diag_header *const diag_hdr = |
560 | &adapter->diagnostics->config_data.header; | |
c41f8cbd SS |
561 | struct fsf_qtcb *qtcb = req->qtcb; |
562 | struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config; | |
563 | struct Scsi_Host *shost = adapter->scsi_host; | |
553448f6 | 564 | |
c41f8cbd SS |
565 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
566 | return; | |
1da177e4 | 567 | |
c41f8cbd SS |
568 | adapter->fsf_lic_version = bottom->lic_version; |
569 | adapter->adapter_features = bottom->adapter_features; | |
570 | adapter->connection_features = bottom->connection_features; | |
571 | adapter->peer_wwpn = 0; | |
572 | adapter->peer_wwnn = 0; | |
573 | adapter->peer_d_id = 0; | |
8a36e453 | 574 | |
c41f8cbd SS |
575 | switch (qtcb->header.fsf_status) { |
576 | case FSF_GOOD: | |
08821023 BB |
577 | /* |
578 | * usually we wait with an update till the cache is too old, | |
579 | * but because we have the data available, update it anyway | |
580 | */ | |
581 | zfcp_diag_update_xdata(diag_hdr, bottom, false); | |
582 | ||
c41f8cbd SS |
583 | if (zfcp_fsf_exchange_config_evaluate(req)) |
584 | return; | |
1da177e4 | 585 | |
c41f8cbd SS |
586 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { |
587 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa CS |
588 | "FCP adapter maximum QTCB size (%d bytes) " |
589 | "is too small\n", | |
590 | bottom->max_qtcb_size); | |
ea4a3a6a | 591 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1"); |
c41f8cbd SS |
592 | return; |
593 | } | |
805de8f4 | 594 | atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
c41f8cbd | 595 | &adapter->status); |
1da177e4 | 596 | break; |
c41f8cbd | 597 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
08821023 | 598 | zfcp_diag_update_xdata(diag_hdr, bottom, true); |
92953c6e BB |
599 | req->status |= ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE; |
600 | ||
c41f8cbd SS |
601 | fc_host_node_name(shost) = 0; |
602 | fc_host_port_name(shost) = 0; | |
603 | fc_host_port_id(shost) = 0; | |
604 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
605 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | |
606 | adapter->hydra_version = 0; | |
1da177e4 | 607 | |
f76ccaac DH |
608 | /* avoids adapter shutdown to be able to recognize |
609 | * events such as LINK UP */ | |
805de8f4 | 610 | atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
f76ccaac | 611 | &adapter->status); |
edaed859 | 612 | zfcp_fsf_link_down_info_eval(req, |
c41f8cbd | 613 | &qtcb->header.fsf_status_qual.link_down_info); |
9edf7d75 SM |
614 | if (zfcp_fsf_exchange_config_evaluate(req)) |
615 | return; | |
1da177e4 | 616 | break; |
c41f8cbd | 617 | default: |
ea4a3a6a | 618 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3"); |
c41f8cbd SS |
619 | return; |
620 | } | |
1da177e4 | 621 | |
c41f8cbd SS |
622 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { |
623 | adapter->hardware_version = bottom->hardware_version; | |
624 | memcpy(fc_host_serial_number(shost), bottom->serial_number, | |
625 | min(FC_SERIAL_NUMBER_SIZE, 17)); | |
626 | EBCASC(fc_host_serial_number(shost), | |
627 | min(FC_SERIAL_NUMBER_SIZE, 17)); | |
628 | } | |
1da177e4 | 629 | |
c41f8cbd SS |
630 | if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) { |
631 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa CS |
632 | "The FCP adapter only supports newer " |
633 | "control block versions\n"); | |
ea4a3a6a | 634 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4"); |
c41f8cbd SS |
635 | return; |
636 | } | |
637 | if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) { | |
638 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa CS |
639 | "The FCP adapter only supports older " |
640 | "control block versions\n"); | |
ea4a3a6a | 641 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5"); |
c41f8cbd SS |
642 | } |
643 | } | |
1da177e4 | 644 | |
c41f8cbd SS |
645 | static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req) |
646 | { | |
647 | struct zfcp_adapter *adapter = req->adapter; | |
648 | struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port; | |
649 | struct Scsi_Host *shost = adapter->scsi_host; | |
1da177e4 | 650 | |
c41f8cbd SS |
651 | if (req->data) |
652 | memcpy(req->data, bottom, sizeof(*bottom)); | |
9eb69aff | 653 | |
0282985d | 654 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) { |
c41f8cbd | 655 | fc_host_permanent_port_name(shost) = bottom->wwpn; |
0282985d | 656 | } else |
c41f8cbd SS |
657 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); |
658 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; | |
d2201977 SM |
659 | fc_host_supported_speeds(shost) = |
660 | zfcp_fsf_convert_portspeed(bottom->supported_speed); | |
2d8e62bb CS |
661 | memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types, |
662 | FC_FC4_LIST_SIZE); | |
663 | memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types, | |
664 | FC_FC4_LIST_SIZE); | |
c41f8cbd | 665 | } |
1da177e4 | 666 | |
c41f8cbd SS |
667 | static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req) |
668 | { | |
7e418833 BB |
669 | struct zfcp_diag_header *const diag_hdr = |
670 | &req->adapter->diagnostics->port_data.header; | |
c41f8cbd | 671 | struct fsf_qtcb *qtcb = req->qtcb; |
7e418833 | 672 | struct fsf_qtcb_bottom_port *bottom = &qtcb->bottom.port; |
c41f8cbd SS |
673 | |
674 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
675 | return; | |
676 | ||
677 | switch (qtcb->header.fsf_status) { | |
678 | case FSF_GOOD: | |
7e418833 BB |
679 | /* |
680 | * usually we wait with an update till the cache is too old, | |
681 | * but because we have the data available, update it anyway | |
682 | */ | |
683 | zfcp_diag_update_xdata(diag_hdr, bottom, false); | |
684 | ||
c41f8cbd | 685 | zfcp_fsf_exchange_port_evaluate(req); |
c41f8cbd SS |
686 | break; |
687 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | |
7e418833 | 688 | zfcp_diag_update_xdata(diag_hdr, bottom, true); |
92953c6e BB |
689 | req->status |= ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE; |
690 | ||
c41f8cbd | 691 | zfcp_fsf_exchange_port_evaluate(req); |
edaed859 | 692 | zfcp_fsf_link_down_info_eval(req, |
c41f8cbd | 693 | &qtcb->header.fsf_status_qual.link_down_info); |
aef4a983 | 694 | break; |
1da177e4 | 695 | } |
c41f8cbd | 696 | } |
d26ab06e | 697 | |
a4623c46 | 698 | static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool) |
c41f8cbd SS |
699 | { |
700 | struct zfcp_fsf_req *req; | |
a4623c46 SS |
701 | |
702 | if (likely(pool)) | |
703 | req = mempool_alloc(pool, GFP_ATOMIC); | |
704 | else | |
705 | req = kmalloc(sizeof(*req), GFP_ATOMIC); | |
706 | ||
707 | if (unlikely(!req)) | |
c41f8cbd | 708 | return NULL; |
a4623c46 | 709 | |
c41f8cbd | 710 | memset(req, 0, sizeof(*req)); |
88f2a977 | 711 | req->pool = pool; |
c41f8cbd SS |
712 | return req; |
713 | } | |
714 | ||
d39eda54 | 715 | static struct fsf_qtcb *zfcp_fsf_qtcb_alloc(mempool_t *pool) |
c41f8cbd | 716 | { |
a4623c46 | 717 | struct fsf_qtcb *qtcb; |
c41f8cbd SS |
718 | |
719 | if (likely(pool)) | |
720 | qtcb = mempool_alloc(pool, GFP_ATOMIC); | |
721 | else | |
259afe2e | 722 | qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC); |
a4623c46 | 723 | |
c41f8cbd SS |
724 | if (unlikely(!qtcb)) |
725 | return NULL; | |
726 | ||
727 | memset(qtcb, 0, sizeof(*qtcb)); | |
a4623c46 | 728 | return qtcb; |
c41f8cbd SS |
729 | } |
730 | ||
564e1c86 | 731 | static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio, |
3ec90878 | 732 | u32 fsf_cmd, u8 sbtype, |
1674b405 | 733 | mempool_t *pool) |
1da177e4 | 734 | { |
564e1c86 | 735 | struct zfcp_adapter *adapter = qdio->adapter; |
a4623c46 | 736 | struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool); |
1da177e4 | 737 | |
c41f8cbd | 738 | if (unlikely(!req)) |
1e9b1643 | 739 | return ERR_PTR(-ENOMEM); |
1da177e4 | 740 | |
c41f8cbd SS |
741 | if (adapter->req_no == 0) |
742 | adapter->req_no++; | |
1da177e4 | 743 | |
c41f8cbd | 744 | INIT_LIST_HEAD(&req->list); |
75492a51 | 745 | timer_setup(&req->timer, NULL, 0); |
058b8647 | 746 | init_completion(&req->completion); |
1da177e4 | 747 | |
c41f8cbd | 748 | req->adapter = adapter; |
52bfb558 | 749 | req->req_id = adapter->req_no; |
c41f8cbd | 750 | |
a4623c46 SS |
751 | if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) { |
752 | if (likely(pool)) | |
d39eda54 SM |
753 | req->qtcb = zfcp_fsf_qtcb_alloc( |
754 | adapter->pool.qtcb_pool); | |
a4623c46 | 755 | else |
d39eda54 | 756 | req->qtcb = zfcp_fsf_qtcb_alloc(NULL); |
a4623c46 SS |
757 | |
758 | if (unlikely(!req->qtcb)) { | |
759 | zfcp_fsf_req_free(req); | |
760 | return ERR_PTR(-ENOMEM); | |
761 | } | |
762 | ||
564e1c86 | 763 | req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; |
c41f8cbd SS |
764 | req->qtcb->prefix.req_id = req->req_id; |
765 | req->qtcb->prefix.ulp_info = 26; | |
f9eca022 | 766 | req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd]; |
c41f8cbd SS |
767 | req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION; |
768 | req->qtcb->header.req_handle = req->req_id; | |
f9eca022 | 769 | req->qtcb->header.fsf_command = fsf_cmd; |
c41f8cbd SS |
770 | } |
771 | ||
1674b405 CS |
772 | zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype, |
773 | req->qtcb, sizeof(struct fsf_qtcb)); | |
774 | ||
c41f8cbd | 775 | return req; |
1da177e4 LT |
776 | } |
777 | ||
c41f8cbd SS |
778 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *req) |
779 | { | |
b76becde | 780 | const bool is_srb = zfcp_fsf_req_is_status_read_buffer(req); |
c41f8cbd | 781 | struct zfcp_adapter *adapter = req->adapter; |
564e1c86 | 782 | struct zfcp_qdio *qdio = adapter->qdio; |
e60a6d69 | 783 | int req_id = req->req_id; |
c41f8cbd | 784 | |
b6bd2fb9 | 785 | zfcp_reqlist_add(adapter->req_list, req); |
c41f8cbd | 786 | |
706eca49 | 787 | req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free); |
1aae0560 | 788 | req->issued = get_tod_clock(); |
34c2b712 | 789 | if (zfcp_qdio_send(qdio, &req->qdio_req)) { |
c41f8cbd | 790 | del_timer(&req->timer); |
3765138a | 791 | /* lookup request again, list might have changed */ |
b6bd2fb9 | 792 | zfcp_reqlist_find_rm(adapter->req_list, req_id); |
ea4a3a6a | 793 | zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1"); |
c41f8cbd SS |
794 | return -EIO; |
795 | } | |
796 | ||
b76becde BB |
797 | /* |
798 | * NOTE: DO NOT TOUCH ASYNC req PAST THIS POINT. | |
799 | * ONLY TOUCH SYNC req AGAIN ON req->completion. | |
800 | * | |
801 | * The request might complete and be freed concurrently at any point | |
802 | * now. This is not protected by the QDIO-lock (req_q_lock). So any | |
803 | * uncontrolled access after this might result in an use-after-free bug. | |
804 | * Only if the request doesn't have ZFCP_STATUS_FSFREQ_CLEANUP set, and | |
805 | * when it is completed via req->completion, is it safe to use req | |
806 | * again. | |
807 | */ | |
808 | ||
c41f8cbd | 809 | /* Don't increase for unsolicited status */ |
b76becde | 810 | if (!is_srb) |
c41f8cbd | 811 | adapter->fsf_req_seq_no++; |
52bfb558 | 812 | adapter->req_no++; |
c41f8cbd SS |
813 | |
814 | return 0; | |
815 | } | |
816 | ||
817 | /** | |
818 | * zfcp_fsf_status_read - send status read request | |
8684d614 | 819 | * @qdio: pointer to struct zfcp_qdio |
c41f8cbd | 820 | * Returns: 0 on success, ERROR otherwise |
1da177e4 | 821 | */ |
564e1c86 | 822 | int zfcp_fsf_status_read(struct zfcp_qdio *qdio) |
1da177e4 | 823 | { |
564e1c86 | 824 | struct zfcp_adapter *adapter = qdio->adapter; |
c41f8cbd SS |
825 | struct zfcp_fsf_req *req; |
826 | struct fsf_status_read_buffer *sr_buf; | |
c7b279ae | 827 | struct page *page; |
c41f8cbd | 828 | int retval = -EIO; |
1da177e4 | 829 | |
44a24cb3 | 830 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 831 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd SS |
832 | goto out; |
833 | ||
75a1408d MP |
834 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, |
835 | SBAL_SFLAGS0_TYPE_STATUS, | |
a4623c46 | 836 | adapter->pool.status_read_req); |
025270f0 | 837 | if (IS_ERR(req)) { |
c41f8cbd SS |
838 | retval = PTR_ERR(req); |
839 | goto out; | |
1da177e4 LT |
840 | } |
841 | ||
c7b279ae CS |
842 | page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC); |
843 | if (!page) { | |
c41f8cbd SS |
844 | retval = -ENOMEM; |
845 | goto failed_buf; | |
846 | } | |
c7b279ae | 847 | sr_buf = page_address(page); |
c41f8cbd SS |
848 | memset(sr_buf, 0, sizeof(*sr_buf)); |
849 | req->data = sr_buf; | |
1674b405 CS |
850 | |
851 | zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf)); | |
852 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); | |
059c97d0 | 853 | |
c41f8cbd SS |
854 | retval = zfcp_fsf_req_send(req); |
855 | if (retval) | |
856 | goto failed_req_send; | |
b76becde | 857 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
1da177e4 | 858 | |
c41f8cbd SS |
859 | goto out; |
860 | ||
861 | failed_req_send: | |
a54ca0f6 | 862 | req->data = NULL; |
c7b279ae | 863 | mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data); |
c41f8cbd | 864 | failed_buf: |
a54ca0f6 | 865 | zfcp_dbf_hba_fsf_uss("fssr__1", req); |
c41f8cbd | 866 | zfcp_fsf_req_free(req); |
c41f8cbd | 867 | out: |
44a24cb3 | 868 | spin_unlock_irq(&qdio->req_q_lock); |
c41f8cbd SS |
869 | return retval; |
870 | } | |
871 | ||
872 | static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req) | |
873 | { | |
b62a8d9b | 874 | struct scsi_device *sdev = req->data; |
d436de8c | 875 | struct zfcp_scsi_dev *zfcp_sdev; |
c41f8cbd SS |
876 | union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual; |
877 | ||
878 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
879 | return; | |
880 | ||
d436de8c MP |
881 | zfcp_sdev = sdev_to_zfcp(sdev); |
882 | ||
c41f8cbd | 883 | switch (req->qtcb->header.fsf_status) { |
1da177e4 | 884 | case FSF_PORT_HANDLE_NOT_VALID: |
c41f8cbd | 885 | if (fsq->word[0] == fsq->word[1]) { |
b62a8d9b | 886 | zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, |
ea4a3a6a | 887 | "fsafch1"); |
c41f8cbd | 888 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
889 | } |
890 | break; | |
1da177e4 | 891 | case FSF_LUN_HANDLE_NOT_VALID: |
c41f8cbd | 892 | if (fsq->word[0] == fsq->word[1]) { |
ea4a3a6a | 893 | zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2"); |
c41f8cbd | 894 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
895 | } |
896 | break; | |
1da177e4 | 897 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: |
c41f8cbd | 898 | req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; |
1da177e4 | 899 | break; |
1da177e4 | 900 | case FSF_PORT_BOXED: |
edaed859 SS |
901 | zfcp_erp_set_port_status(zfcp_sdev->port, |
902 | ZFCP_STATUS_COMMON_ACCESS_BOXED); | |
903 | zfcp_erp_port_reopen(zfcp_sdev->port, | |
ea4a3a6a | 904 | ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3"); |
4c571c65 | 905 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 906 | break; |
1da177e4 | 907 | case FSF_LUN_BOXED: |
edaed859 SS |
908 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED); |
909 | zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED, | |
ea4a3a6a | 910 | "fsafch4"); |
4c571c65 | 911 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 912 | break; |
1da177e4 | 913 | case FSF_ADAPTER_STATUS_AVAILABLE: |
c41f8cbd | 914 | switch (fsq->word[0]) { |
1da177e4 | 915 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
b62a8d9b | 916 | zfcp_fc_test_link(zfcp_sdev->port); |
dceab655 | 917 | /* fall through */ |
1da177e4 | 918 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 919 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 920 | break; |
1da177e4 LT |
921 | } |
922 | break; | |
1da177e4 | 923 | case FSF_GOOD: |
c41f8cbd | 924 | req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; |
1da177e4 | 925 | break; |
1da177e4 | 926 | } |
1da177e4 LT |
927 | } |
928 | ||
929 | /** | |
b62a8d9b CS |
930 | * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command |
931 | * @scmnd: The SCSI command to abort | |
c41f8cbd | 932 | * Returns: pointer to struct zfcp_fsf_req |
1da177e4 | 933 | */ |
1da177e4 | 934 | |
b62a8d9b | 935 | struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd) |
1da177e4 | 936 | { |
c41f8cbd | 937 | struct zfcp_fsf_req *req = NULL; |
b62a8d9b CS |
938 | struct scsi_device *sdev = scmnd->device; |
939 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); | |
940 | struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio; | |
941 | unsigned long old_req_id = (unsigned long) scmnd->host_scribble; | |
8a36e453 | 942 | |
44a24cb3 | 943 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 944 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd | 945 | goto out; |
564e1c86 | 946 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND, |
3ec90878 | 947 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 948 | qdio->adapter->pool.scsi_abort); |
633528c3 SS |
949 | if (IS_ERR(req)) { |
950 | req = NULL; | |
c41f8cbd | 951 | goto out; |
633528c3 | 952 | } |
2abbe866 | 953 | |
b62a8d9b | 954 | if (unlikely(!(atomic_read(&zfcp_sdev->status) & |
c41f8cbd SS |
955 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
956 | goto out_error_free; | |
1da177e4 | 957 | |
1674b405 | 958 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 959 | |
6fbf25e8 | 960 | req->data = sdev; |
c41f8cbd | 961 | req->handler = zfcp_fsf_abort_fcp_command_handler; |
b62a8d9b CS |
962 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
963 | req->qtcb->header.port_handle = zfcp_sdev->port->handle; | |
c41f8cbd SS |
964 | req->qtcb->bottom.support.req_handle = (u64) old_req_id; |
965 | ||
a0e86d95 | 966 | zfcp_fsf_start_timer(req, ZFCP_FSF_SCSI_ER_TIMEOUT); |
b76becde BB |
967 | if (!zfcp_fsf_req_send(req)) { |
968 | /* NOTE: DO NOT TOUCH req, UNTIL IT COMPLETES! */ | |
c41f8cbd | 969 | goto out; |
b76becde | 970 | } |
c41f8cbd SS |
971 | |
972 | out_error_free: | |
973 | zfcp_fsf_req_free(req); | |
974 | req = NULL; | |
975 | out: | |
44a24cb3 | 976 | spin_unlock_irq(&qdio->req_q_lock); |
c41f8cbd | 977 | return req; |
1da177e4 LT |
978 | } |
979 | ||
c41f8cbd | 980 | static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) |
1da177e4 | 981 | { |
c41f8cbd | 982 | struct zfcp_adapter *adapter = req->adapter; |
7c7dc196 | 983 | struct zfcp_fsf_ct_els *ct = req->data; |
c41f8cbd | 984 | struct fsf_qtcb_header *header = &req->qtcb->header; |
1da177e4 | 985 | |
7c7dc196 | 986 | ct->status = -EINVAL; |
1da177e4 | 987 | |
c41f8cbd | 988 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
1da177e4 LT |
989 | goto skip_fsfstatus; |
990 | ||
1da177e4 | 991 | switch (header->fsf_status) { |
1da177e4 | 992 | case FSF_GOOD: |
7c7dc196 | 993 | ct->status = 0; |
975171b4 | 994 | zfcp_dbf_san_res("fsscth2", req); |
1da177e4 | 995 | break; |
1da177e4 | 996 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
c41f8cbd | 997 | zfcp_fsf_class_not_supp(req); |
1da177e4 | 998 | break; |
1da177e4 | 999 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1000 | switch (header->fsf_status_qual.word[0]){ |
1001 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 | 1002 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 1003 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1004 | break; |
1da177e4 LT |
1005 | } |
1006 | break; | |
1da177e4 | 1007 | case FSF_PORT_BOXED: |
4c571c65 | 1008 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1009 | break; |
c41f8cbd | 1010 | case FSF_PORT_HANDLE_NOT_VALID: |
ea4a3a6a | 1011 | zfcp_erp_adapter_reopen(adapter, 0, "fsscth1"); |
dceab655 | 1012 | /* fall through */ |
c41f8cbd | 1013 | case FSF_GENERIC_COMMAND_REJECTED: |
1da177e4 | 1014 | case FSF_PAYLOAD_SIZE_MISMATCH: |
1da177e4 | 1015 | case FSF_REQUEST_SIZE_TOO_LARGE: |
1da177e4 | 1016 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
1da177e4 | 1017 | case FSF_SBAL_MISMATCH: |
c41f8cbd | 1018 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1019 | break; |
1020 | } | |
1021 | ||
1022 | skip_fsfstatus: | |
7c7dc196 CS |
1023 | if (ct->handler) |
1024 | ct->handler(ct->handler_data); | |
c41f8cbd | 1025 | } |
1da177e4 | 1026 | |
1674b405 CS |
1027 | static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio, |
1028 | struct zfcp_qdio_req *q_req, | |
426f6059 CS |
1029 | struct scatterlist *sg_req, |
1030 | struct scatterlist *sg_resp) | |
1031 | { | |
1674b405 CS |
1032 | zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length); |
1033 | zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length); | |
1034 | zfcp_qdio_set_sbale_last(qdio, q_req); | |
426f6059 CS |
1035 | } |
1036 | ||
39eb7e9a CS |
1037 | static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req, |
1038 | struct scatterlist *sg_req, | |
01b04759 | 1039 | struct scatterlist *sg_resp) |
c41f8cbd | 1040 | { |
42428f74 | 1041 | struct zfcp_adapter *adapter = req->adapter; |
86a9668a SS |
1042 | struct zfcp_qdio *qdio = adapter->qdio; |
1043 | struct fsf_qtcb *qtcb = req->qtcb; | |
42428f74 | 1044 | u32 feat = adapter->adapter_features; |
c41f8cbd | 1045 | |
86a9668a SS |
1046 | if (zfcp_adapter_multi_buffer_active(adapter)) { |
1047 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req)) | |
1048 | return -EIO; | |
70369f8e SM |
1049 | qtcb->bottom.support.req_buf_length = |
1050 | zfcp_qdio_real_bytes(sg_req); | |
86a9668a SS |
1051 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp)) |
1052 | return -EIO; | |
70369f8e SM |
1053 | qtcb->bottom.support.resp_buf_length = |
1054 | zfcp_qdio_real_bytes(sg_resp); | |
39eb7e9a | 1055 | |
7d91869c | 1056 | zfcp_qdio_set_data_div(qdio, &req->qdio_req, sg_nents(sg_req)); |
86a9668a SS |
1057 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1058 | zfcp_qdio_set_scount(qdio, &req->qdio_req); | |
426f6059 CS |
1059 | return 0; |
1060 | } | |
1061 | ||
1062 | /* use single, unchained SBAL if it can hold the request */ | |
30b6777b | 1063 | if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) { |
86a9668a | 1064 | zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req, |
1674b405 | 1065 | sg_req, sg_resp); |
39eb7e9a CS |
1066 | return 0; |
1067 | } | |
1068 | ||
86a9668a SS |
1069 | if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) |
1070 | return -EOPNOTSUPP; | |
1071 | ||
1072 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req)) | |
9072df4d | 1073 | return -EIO; |
c41f8cbd | 1074 | |
86a9668a SS |
1075 | qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req); |
1076 | ||
1077 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); | |
1078 | zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req); | |
1079 | ||
1080 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp)) | |
9072df4d | 1081 | return -EIO; |
86a9668a SS |
1082 | |
1083 | qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp); | |
1084 | ||
1085 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); | |
98fc4d5c | 1086 | |
b1a58985 CS |
1087 | return 0; |
1088 | } | |
1089 | ||
1090 | static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req, | |
1091 | struct scatterlist *sg_req, | |
1092 | struct scatterlist *sg_resp, | |
01b04759 | 1093 | unsigned int timeout) |
b1a58985 CS |
1094 | { |
1095 | int ret; | |
1096 | ||
01b04759 | 1097 | ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp); |
b1a58985 CS |
1098 | if (ret) |
1099 | return ret; | |
1100 | ||
98fc4d5c | 1101 | /* common settings for ct/gs and els requests */ |
51375ee8 SS |
1102 | if (timeout > 255) |
1103 | timeout = 255; /* max value accepted by hardware */ | |
98fc4d5c | 1104 | req->qtcb->bottom.support.service_class = FSF_CLASS_3; |
51375ee8 SS |
1105 | req->qtcb->bottom.support.timeout = timeout; |
1106 | zfcp_fsf_start_timer(req, (timeout + 10) * HZ); | |
c41f8cbd SS |
1107 | |
1108 | return 0; | |
1da177e4 LT |
1109 | } |
1110 | ||
1111 | /** | |
c41f8cbd | 1112 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) |
8684d614 | 1113 | * @wka_port: pointer to zfcp WKA port to send CT/GS to |
c41f8cbd SS |
1114 | * @ct: pointer to struct zfcp_send_ct with data for request |
1115 | * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req | |
8684d614 | 1116 | * @timeout: timeout that hardware should use, and a later software timeout |
1da177e4 | 1117 | */ |
7c7dc196 | 1118 | int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port, |
51375ee8 SS |
1119 | struct zfcp_fsf_ct_els *ct, mempool_t *pool, |
1120 | unsigned int timeout) | |
1da177e4 | 1121 | { |
564e1c86 | 1122 | struct zfcp_qdio *qdio = wka_port->adapter->qdio; |
c41f8cbd SS |
1123 | struct zfcp_fsf_req *req; |
1124 | int ret = -EIO; | |
1da177e4 | 1125 | |
44a24cb3 | 1126 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1127 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd | 1128 | goto out; |
1da177e4 | 1129 | |
1674b405 | 1130 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, |
3ec90878 | 1131 | SBAL_SFLAGS0_TYPE_WRITE_READ, pool); |
09a46c6e | 1132 | |
025270f0 | 1133 | if (IS_ERR(req)) { |
c41f8cbd SS |
1134 | ret = PTR_ERR(req); |
1135 | goto out; | |
3f0ca62a CS |
1136 | } |
1137 | ||
09a46c6e | 1138 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
01b04759 | 1139 | ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout); |
553448f6 | 1140 | if (ret) |
1da177e4 | 1141 | goto failed_send; |
1da177e4 | 1142 | |
c41f8cbd | 1143 | req->handler = zfcp_fsf_send_ct_handler; |
5ab944f9 | 1144 | req->qtcb->header.port_handle = wka_port->handle; |
771bf035 | 1145 | ct->d_id = wka_port->d_id; |
c41f8cbd SS |
1146 | req->data = ct; |
1147 | ||
2c55b750 | 1148 | zfcp_dbf_san_req("fssct_1", req, wka_port->d_id); |
1da177e4 | 1149 | |
c41f8cbd SS |
1150 | ret = zfcp_fsf_req_send(req); |
1151 | if (ret) | |
1152 | goto failed_send; | |
b76becde | 1153 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
1da177e4 | 1154 | |
c41f8cbd | 1155 | goto out; |
1da177e4 | 1156 | |
c41f8cbd SS |
1157 | failed_send: |
1158 | zfcp_fsf_req_free(req); | |
c41f8cbd | 1159 | out: |
44a24cb3 | 1160 | spin_unlock_irq(&qdio->req_q_lock); |
c41f8cbd | 1161 | return ret; |
1da177e4 LT |
1162 | } |
1163 | ||
c41f8cbd | 1164 | static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1165 | { |
7c7dc196 | 1166 | struct zfcp_fsf_ct_els *send_els = req->data; |
c41f8cbd | 1167 | struct fsf_qtcb_header *header = &req->qtcb->header; |
1da177e4 | 1168 | |
c41f8cbd | 1169 | send_els->status = -EINVAL; |
1da177e4 | 1170 | |
c41f8cbd | 1171 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
1da177e4 LT |
1172 | goto skip_fsfstatus; |
1173 | ||
1174 | switch (header->fsf_status) { | |
1da177e4 | 1175 | case FSF_GOOD: |
c41f8cbd | 1176 | send_els->status = 0; |
975171b4 | 1177 | zfcp_dbf_san_res("fsselh1", req); |
1da177e4 | 1178 | break; |
1da177e4 | 1179 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
c41f8cbd | 1180 | zfcp_fsf_class_not_supp(req); |
1da177e4 | 1181 | break; |
1da177e4 | 1182 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1183 | switch (header->fsf_status_qual.word[0]){ |
1184 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 | 1185 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1da177e4 | 1186 | case FSF_SQ_RETRY_IF_POSSIBLE: |
c41f8cbd | 1187 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1188 | break; |
1da177e4 LT |
1189 | } |
1190 | break; | |
1da177e4 | 1191 | case FSF_ELS_COMMAND_REJECTED: |
1da177e4 | 1192 | case FSF_PAYLOAD_SIZE_MISMATCH: |
1da177e4 | 1193 | case FSF_REQUEST_SIZE_TOO_LARGE: |
1da177e4 | 1194 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
1da177e4 | 1195 | break; |
c41f8cbd | 1196 | case FSF_SBAL_MISMATCH: |
25985edc | 1197 | /* should never occur, avoided in zfcp_fsf_send_els */ |
c41f8cbd | 1198 | /* fall through */ |
1da177e4 | 1199 | default: |
c41f8cbd | 1200 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1201 | break; |
1202 | } | |
1da177e4 | 1203 | skip_fsfstatus: |
aa551daf | 1204 | if (send_els->handler) |
1da177e4 | 1205 | send_els->handler(send_els->handler_data); |
c41f8cbd | 1206 | } |
1da177e4 | 1207 | |
c41f8cbd SS |
1208 | /** |
1209 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) | |
8684d614 SM |
1210 | * @adapter: pointer to zfcp adapter |
1211 | * @d_id: N_Port_ID to send ELS to | |
c41f8cbd | 1212 | * @els: pointer to struct zfcp_send_els with data for the command |
8684d614 | 1213 | * @timeout: timeout that hardware should use, and a later software timeout |
c41f8cbd | 1214 | */ |
7c7dc196 | 1215 | int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id, |
51375ee8 | 1216 | struct zfcp_fsf_ct_els *els, unsigned int timeout) |
c41f8cbd SS |
1217 | { |
1218 | struct zfcp_fsf_req *req; | |
7c7dc196 | 1219 | struct zfcp_qdio *qdio = adapter->qdio; |
c41f8cbd SS |
1220 | int ret = -EIO; |
1221 | ||
44a24cb3 | 1222 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1223 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd | 1224 | goto out; |
09a46c6e | 1225 | |
1674b405 | 1226 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, |
3ec90878 | 1227 | SBAL_SFLAGS0_TYPE_WRITE_READ, NULL); |
09a46c6e | 1228 | |
025270f0 | 1229 | if (IS_ERR(req)) { |
c41f8cbd SS |
1230 | ret = PTR_ERR(req); |
1231 | goto out; | |
1232 | } | |
1233 | ||
09a46c6e | 1234 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
01b04759 | 1235 | |
86a9668a SS |
1236 | if (!zfcp_adapter_multi_buffer_active(adapter)) |
1237 | zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2); | |
01b04759 SS |
1238 | |
1239 | ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout); | |
44cc76f2 | 1240 | |
c41f8cbd SS |
1241 | if (ret) |
1242 | goto failed_send; | |
1243 | ||
7c7dc196 | 1244 | hton24(req->qtcb->bottom.support.d_id, d_id); |
c41f8cbd | 1245 | req->handler = zfcp_fsf_send_els_handler; |
771bf035 | 1246 | els->d_id = d_id; |
c41f8cbd SS |
1247 | req->data = els; |
1248 | ||
2c55b750 | 1249 | zfcp_dbf_san_req("fssels1", req, d_id); |
c41f8cbd | 1250 | |
c41f8cbd SS |
1251 | ret = zfcp_fsf_req_send(req); |
1252 | if (ret) | |
1253 | goto failed_send; | |
b76becde | 1254 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd SS |
1255 | |
1256 | goto out; | |
1257 | ||
1258 | failed_send: | |
1259 | zfcp_fsf_req_free(req); | |
1260 | out: | |
44a24cb3 | 1261 | spin_unlock_irq(&qdio->req_q_lock); |
c41f8cbd | 1262 | return ret; |
1da177e4 LT |
1263 | } |
1264 | ||
c41f8cbd | 1265 | int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) |
1da177e4 | 1266 | { |
c41f8cbd | 1267 | struct zfcp_fsf_req *req; |
564e1c86 | 1268 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
c41f8cbd SS |
1269 | int retval = -EIO; |
1270 | ||
44a24cb3 | 1271 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1272 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd | 1273 | goto out; |
09a46c6e | 1274 | |
564e1c86 | 1275 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
3ec90878 | 1276 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 1277 | qdio->adapter->pool.erp_req); |
09a46c6e | 1278 | |
025270f0 | 1279 | if (IS_ERR(req)) { |
c41f8cbd SS |
1280 | retval = PTR_ERR(req); |
1281 | goto out; | |
1da177e4 LT |
1282 | } |
1283 | ||
09a46c6e | 1284 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1285 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 1286 | |
c41f8cbd | 1287 | req->qtcb->bottom.config.feature_selection = |
9eb69aff | 1288 | FSF_FEATURE_NOTIFICATION_LOST | |
a10a61e8 BB |
1289 | FSF_FEATURE_UPDATE_ALERT | |
1290 | FSF_FEATURE_REQUEST_SFP_DATA; | |
c41f8cbd SS |
1291 | req->erp_action = erp_action; |
1292 | req->handler = zfcp_fsf_exchange_config_data_handler; | |
e60a6d69 | 1293 | erp_action->fsf_req_id = req->req_id; |
1da177e4 | 1294 | |
287ac01a | 1295 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1296 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1297 | if (retval) { |
c41f8cbd | 1298 | zfcp_fsf_req_free(req); |
e60a6d69 | 1299 | erp_action->fsf_req_id = 0; |
1da177e4 | 1300 | } |
b76becde | 1301 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd | 1302 | out: |
44a24cb3 | 1303 | spin_unlock_irq(&qdio->req_q_lock); |
52ef11a7 SS |
1304 | return retval; |
1305 | } | |
1da177e4 | 1306 | |
92953c6e BB |
1307 | |
1308 | /** | |
1309 | * zfcp_fsf_exchange_config_data_sync() - Request information about FCP channel. | |
1310 | * @qdio: pointer to the QDIO-Queue to use for sending the command. | |
1311 | * @data: pointer to the QTCB-Bottom for storing the result of the command, | |
1312 | * might be %NULL. | |
1313 | * | |
1314 | * Returns: | |
1315 | * * 0 - Exchange Config Data was successful, @data is complete | |
1316 | * * -EIO - Exchange Config Data was not successful, @data is invalid | |
1317 | * * -EAGAIN - @data contains incomplete data | |
1318 | * * -ENOMEM - Some memory allocation failed along the way | |
1319 | */ | |
564e1c86 | 1320 | int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio, |
c41f8cbd | 1321 | struct fsf_qtcb_bottom_config *data) |
52ef11a7 | 1322 | { |
c41f8cbd SS |
1323 | struct zfcp_fsf_req *req = NULL; |
1324 | int retval = -EIO; | |
1325 | ||
44a24cb3 | 1326 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1327 | if (zfcp_qdio_sbal_get(qdio)) |
ada81b74 | 1328 | goto out_unlock; |
c41f8cbd | 1329 | |
1674b405 | 1330 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
3ec90878 | 1331 | SBAL_SFLAGS0_TYPE_READ, NULL); |
09a46c6e | 1332 | |
025270f0 | 1333 | if (IS_ERR(req)) { |
c41f8cbd | 1334 | retval = PTR_ERR(req); |
ada81b74 | 1335 | goto out_unlock; |
52ef11a7 SS |
1336 | } |
1337 | ||
1674b405 | 1338 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
c41f8cbd | 1339 | req->handler = zfcp_fsf_exchange_config_data_handler; |
52ef11a7 | 1340 | |
c41f8cbd | 1341 | req->qtcb->bottom.config.feature_selection = |
52ef11a7 | 1342 | FSF_FEATURE_NOTIFICATION_LOST | |
a10a61e8 BB |
1343 | FSF_FEATURE_UPDATE_ALERT | |
1344 | FSF_FEATURE_REQUEST_SFP_DATA; | |
52ef11a7 SS |
1345 | |
1346 | if (data) | |
c41f8cbd | 1347 | req->data = data; |
52ef11a7 | 1348 | |
c41f8cbd SS |
1349 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
1350 | retval = zfcp_fsf_req_send(req); | |
44a24cb3 | 1351 | spin_unlock_irq(&qdio->req_q_lock); |
92953c6e | 1352 | |
b76becde BB |
1353 | if (!retval) { |
1354 | /* NOTE: ONLY TOUCH SYNC req AGAIN ON req->completion. */ | |
058b8647 | 1355 | wait_for_completion(&req->completion); |
92953c6e BB |
1356 | |
1357 | if (req->status & | |
1358 | (ZFCP_STATUS_FSFREQ_ERROR | ZFCP_STATUS_FSFREQ_DISMISSED)) | |
1359 | retval = -EIO; | |
1360 | else if (req->status & ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE) | |
1361 | retval = -EAGAIN; | |
b76becde | 1362 | } |
52ef11a7 | 1363 | |
c41f8cbd | 1364 | zfcp_fsf_req_free(req); |
ada81b74 | 1365 | return retval; |
52ef11a7 | 1366 | |
ada81b74 | 1367 | out_unlock: |
44a24cb3 | 1368 | spin_unlock_irq(&qdio->req_q_lock); |
1da177e4 LT |
1369 | return retval; |
1370 | } | |
1371 | ||
1da177e4 LT |
1372 | /** |
1373 | * zfcp_fsf_exchange_port_data - request information about local port | |
aef4a983 | 1374 | * @erp_action: ERP action for the adapter for which port data is requested |
c41f8cbd | 1375 | * Returns: 0 on success, error otherwise |
1da177e4 | 1376 | */ |
c41f8cbd | 1377 | int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) |
1da177e4 | 1378 | { |
564e1c86 | 1379 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
c41f8cbd | 1380 | struct zfcp_fsf_req *req; |
c41f8cbd | 1381 | int retval = -EIO; |
1da177e4 | 1382 | |
564e1c86 | 1383 | if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
52ef11a7 | 1384 | return -EOPNOTSUPP; |
1da177e4 | 1385 | |
44a24cb3 | 1386 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1387 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd | 1388 | goto out; |
09a46c6e | 1389 | |
564e1c86 | 1390 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, |
3ec90878 | 1391 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 1392 | qdio->adapter->pool.erp_req); |
09a46c6e | 1393 | |
025270f0 | 1394 | if (IS_ERR(req)) { |
c41f8cbd SS |
1395 | retval = PTR_ERR(req); |
1396 | goto out; | |
aef4a983 MS |
1397 | } |
1398 | ||
09a46c6e | 1399 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1400 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 1401 | |
c41f8cbd SS |
1402 | req->handler = zfcp_fsf_exchange_port_data_handler; |
1403 | req->erp_action = erp_action; | |
e60a6d69 | 1404 | erp_action->fsf_req_id = req->req_id; |
52ef11a7 | 1405 | |
287ac01a | 1406 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1407 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1408 | if (retval) { |
c41f8cbd | 1409 | zfcp_fsf_req_free(req); |
e60a6d69 | 1410 | erp_action->fsf_req_id = 0; |
52ef11a7 | 1411 | } |
b76becde | 1412 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd | 1413 | out: |
44a24cb3 | 1414 | spin_unlock_irq(&qdio->req_q_lock); |
52ef11a7 SS |
1415 | return retval; |
1416 | } | |
1417 | ||
52ef11a7 | 1418 | /** |
92953c6e BB |
1419 | * zfcp_fsf_exchange_port_data_sync() - Request information about local port. |
1420 | * @qdio: pointer to the QDIO-Queue to use for sending the command. | |
1421 | * @data: pointer to the QTCB-Bottom for storing the result of the command, | |
1422 | * might be %NULL. | |
1423 | * | |
1424 | * Returns: | |
1425 | * * 0 - Exchange Port Data was successful, @data is complete | |
1426 | * * -EIO - Exchange Port Data was not successful, @data is invalid | |
1427 | * * -EAGAIN - @data contains incomplete data | |
1428 | * * -ENOMEM - Some memory allocation failed along the way | |
1429 | * * -EOPNOTSUPP - This operation is not supported | |
52ef11a7 | 1430 | */ |
564e1c86 | 1431 | int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio, |
c41f8cbd | 1432 | struct fsf_qtcb_bottom_port *data) |
52ef11a7 | 1433 | { |
c41f8cbd SS |
1434 | struct zfcp_fsf_req *req = NULL; |
1435 | int retval = -EIO; | |
52ef11a7 | 1436 | |
564e1c86 | 1437 | if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
52ef11a7 | 1438 | return -EOPNOTSUPP; |
52ef11a7 | 1439 | |
44a24cb3 | 1440 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1441 | if (zfcp_qdio_sbal_get(qdio)) |
ada81b74 | 1442 | goto out_unlock; |
c41f8cbd | 1443 | |
1674b405 | 1444 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, |
3ec90878 | 1445 | SBAL_SFLAGS0_TYPE_READ, NULL); |
09a46c6e | 1446 | |
025270f0 | 1447 | if (IS_ERR(req)) { |
c41f8cbd | 1448 | retval = PTR_ERR(req); |
ada81b74 | 1449 | goto out_unlock; |
1da177e4 LT |
1450 | } |
1451 | ||
52ef11a7 | 1452 | if (data) |
c41f8cbd | 1453 | req->data = data; |
52ef11a7 | 1454 | |
1674b405 | 1455 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
52ef11a7 | 1456 | |
c41f8cbd SS |
1457 | req->handler = zfcp_fsf_exchange_port_data_handler; |
1458 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | |
1459 | retval = zfcp_fsf_req_send(req); | |
44a24cb3 | 1460 | spin_unlock_irq(&qdio->req_q_lock); |
ada81b74 | 1461 | |
b76becde BB |
1462 | if (!retval) { |
1463 | /* NOTE: ONLY TOUCH SYNC req AGAIN ON req->completion. */ | |
058b8647 | 1464 | wait_for_completion(&req->completion); |
92953c6e BB |
1465 | |
1466 | if (req->status & | |
1467 | (ZFCP_STATUS_FSFREQ_ERROR | ZFCP_STATUS_FSFREQ_DISMISSED)) | |
1468 | retval = -EIO; | |
1469 | else if (req->status & ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE) | |
1470 | retval = -EAGAIN; | |
b76becde | 1471 | } |
058b8647 | 1472 | |
c41f8cbd | 1473 | zfcp_fsf_req_free(req); |
1da177e4 | 1474 | return retval; |
ada81b74 CS |
1475 | |
1476 | out_unlock: | |
44a24cb3 | 1477 | spin_unlock_irq(&qdio->req_q_lock); |
ada81b74 | 1478 | return retval; |
1da177e4 LT |
1479 | } |
1480 | ||
c41f8cbd | 1481 | static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1482 | { |
c41f8cbd SS |
1483 | struct zfcp_port *port = req->data; |
1484 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
9d05ce2c | 1485 | struct fc_els_flogi *plogi; |
1da177e4 | 1486 | |
c41f8cbd | 1487 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
a17c5855 | 1488 | goto out; |
1da177e4 | 1489 | |
1da177e4 | 1490 | switch (header->fsf_status) { |
1da177e4 | 1491 | case FSF_PORT_ALREADY_OPEN: |
1da177e4 | 1492 | break; |
1da177e4 | 1493 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
c41f8cbd | 1494 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa | 1495 | "Not enough FCP adapter resources to open " |
7ba58c9c SS |
1496 | "remote port 0x%016Lx\n", |
1497 | (unsigned long long)port->wwpn); | |
edaed859 SS |
1498 | zfcp_erp_set_port_status(port, |
1499 | ZFCP_STATUS_COMMON_ERP_FAILED); | |
c41f8cbd | 1500 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1501 | break; |
1da177e4 | 1502 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1503 | switch (header->fsf_status_qual.word[0]) { |
1504 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
394134fd SM |
1505 | /* no zfcp_fc_test_link() with failed open port */ |
1506 | /* fall through */ | |
1da177e4 | 1507 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1da177e4 | 1508 | case FSF_SQ_NO_RETRY_POSSIBLE: |
c41f8cbd | 1509 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1510 | break; |
1511 | } | |
1512 | break; | |
1da177e4 | 1513 | case FSF_GOOD: |
1da177e4 | 1514 | port->handle = header->port_handle; |
805de8f4 | 1515 | atomic_or(ZFCP_STATUS_COMMON_OPEN | |
1da177e4 | 1516 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
805de8f4 | 1517 | atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED, |
d736a27b | 1518 | &port->status); |
1da177e4 LT |
1519 | /* check whether D_ID has changed during open */ |
1520 | /* | |
1521 | * FIXME: This check is not airtight, as the FCP channel does | |
1522 | * not monitor closures of target port connections caused on | |
1523 | * the remote side. Thus, they might miss out on invalidating | |
1524 | * locally cached WWPNs (and other N_Port parameters) of gone | |
1525 | * target ports. So, our heroic attempt to make things safe | |
1526 | * could be undermined by 'open port' response data tagged with | |
1527 | * obsolete WWPNs. Another reason to monitor potential | |
1528 | * connection closures ourself at least (by interpreting | |
1529 | * incoming ELS' and unsolicited status). It just crosses my | |
1530 | * mind that one should be able to cross-check by means of | |
1531 | * another GID_PN straight after a port has been opened. | |
1532 | * Alternately, an ADISC/PDISC ELS should suffice, as well. | |
1533 | */ | |
9d05ce2c | 1534 | plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els; |
39eb7e9a | 1535 | if (req->qtcb->bottom.support.els1_length >= |
9d05ce2c | 1536 | FSF_PLOGI_MIN_LEN) |
c41f8cbd | 1537 | zfcp_fc_plogi_evaluate(port, plogi); |
1da177e4 | 1538 | break; |
1da177e4 | 1539 | case FSF_UNKNOWN_OP_SUBTYPE: |
c41f8cbd | 1540 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1541 | break; |
1542 | } | |
a17c5855 MP |
1543 | |
1544 | out: | |
615f59e0 | 1545 | put_device(&port->dev); |
1da177e4 LT |
1546 | } |
1547 | ||
c41f8cbd SS |
1548 | /** |
1549 | * zfcp_fsf_open_port - create and send open port request | |
1550 | * @erp_action: pointer to struct zfcp_erp_action | |
1551 | * Returns: 0 on success, error otherwise | |
1da177e4 | 1552 | */ |
c41f8cbd | 1553 | int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
1da177e4 | 1554 | { |
564e1c86 | 1555 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
a17c5855 | 1556 | struct zfcp_port *port = erp_action->port; |
564e1c86 | 1557 | struct zfcp_fsf_req *req; |
c41f8cbd SS |
1558 | int retval = -EIO; |
1559 | ||
44a24cb3 | 1560 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1561 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd SS |
1562 | goto out; |
1563 | ||
564e1c86 | 1564 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID, |
3ec90878 | 1565 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 1566 | qdio->adapter->pool.erp_req); |
09a46c6e | 1567 | |
025270f0 | 1568 | if (IS_ERR(req)) { |
c41f8cbd | 1569 | retval = PTR_ERR(req); |
1da177e4 | 1570 | goto out; |
c41f8cbd | 1571 | } |
1da177e4 | 1572 | |
09a46c6e | 1573 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1574 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 1575 | |
c41f8cbd | 1576 | req->handler = zfcp_fsf_open_port_handler; |
800c0cad | 1577 | hton24(req->qtcb->bottom.support.d_id, port->d_id); |
a17c5855 | 1578 | req->data = port; |
c41f8cbd | 1579 | req->erp_action = erp_action; |
e60a6d69 | 1580 | erp_action->fsf_req_id = req->req_id; |
615f59e0 | 1581 | get_device(&port->dev); |
c41f8cbd | 1582 | |
287ac01a | 1583 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1584 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1585 | if (retval) { |
c41f8cbd | 1586 | zfcp_fsf_req_free(req); |
e60a6d69 | 1587 | erp_action->fsf_req_id = 0; |
615f59e0 | 1588 | put_device(&port->dev); |
1da177e4 | 1589 | } |
b76becde | 1590 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd | 1591 | out: |
44a24cb3 | 1592 | spin_unlock_irq(&qdio->req_q_lock); |
1da177e4 LT |
1593 | return retval; |
1594 | } | |
1595 | ||
c41f8cbd | 1596 | static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1597 | { |
c41f8cbd | 1598 | struct zfcp_port *port = req->data; |
1da177e4 | 1599 | |
c41f8cbd | 1600 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
44cc76f2 | 1601 | return; |
1da177e4 | 1602 | |
c41f8cbd | 1603 | switch (req->qtcb->header.fsf_status) { |
1da177e4 | 1604 | case FSF_PORT_HANDLE_NOT_VALID: |
ea4a3a6a | 1605 | zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1"); |
c41f8cbd | 1606 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1607 | break; |
1da177e4 | 1608 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 | 1609 | break; |
1da177e4 | 1610 | case FSF_GOOD: |
edaed859 | 1611 | zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN); |
1da177e4 | 1612 | break; |
1da177e4 | 1613 | } |
1da177e4 LT |
1614 | } |
1615 | ||
c41f8cbd SS |
1616 | /** |
1617 | * zfcp_fsf_close_port - create and send close port request | |
1618 | * @erp_action: pointer to struct zfcp_erp_action | |
1619 | * Returns: 0 on success, error otherwise | |
1da177e4 | 1620 | */ |
c41f8cbd | 1621 | int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
1da177e4 | 1622 | { |
564e1c86 | 1623 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
c41f8cbd SS |
1624 | struct zfcp_fsf_req *req; |
1625 | int retval = -EIO; | |
1626 | ||
44a24cb3 | 1627 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1628 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd SS |
1629 | goto out; |
1630 | ||
564e1c86 | 1631 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT, |
3ec90878 | 1632 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 1633 | qdio->adapter->pool.erp_req); |
09a46c6e | 1634 | |
025270f0 | 1635 | if (IS_ERR(req)) { |
c41f8cbd | 1636 | retval = PTR_ERR(req); |
1da177e4 | 1637 | goto out; |
c41f8cbd | 1638 | } |
1da177e4 | 1639 | |
09a46c6e | 1640 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1641 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 1642 | |
c41f8cbd SS |
1643 | req->handler = zfcp_fsf_close_port_handler; |
1644 | req->data = erp_action->port; | |
1645 | req->erp_action = erp_action; | |
1646 | req->qtcb->header.port_handle = erp_action->port->handle; | |
e60a6d69 | 1647 | erp_action->fsf_req_id = req->req_id; |
c41f8cbd | 1648 | |
287ac01a | 1649 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1650 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1651 | if (retval) { |
c41f8cbd | 1652 | zfcp_fsf_req_free(req); |
e60a6d69 | 1653 | erp_action->fsf_req_id = 0; |
1da177e4 | 1654 | } |
b76becde | 1655 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd | 1656 | out: |
44a24cb3 | 1657 | spin_unlock_irq(&qdio->req_q_lock); |
1da177e4 LT |
1658 | return retval; |
1659 | } | |
1660 | ||
5ab944f9 SS |
1661 | static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req) |
1662 | { | |
bd0072ec | 1663 | struct zfcp_fc_wka_port *wka_port = req->data; |
5ab944f9 SS |
1664 | struct fsf_qtcb_header *header = &req->qtcb->header; |
1665 | ||
1666 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
bd0072ec | 1667 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
5ab944f9 SS |
1668 | goto out; |
1669 | } | |
1670 | ||
1671 | switch (header->fsf_status) { | |
1672 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: | |
1673 | dev_warn(&req->adapter->ccw_device->dev, | |
1674 | "Opening WKA port 0x%x failed\n", wka_port->d_id); | |
dceab655 | 1675 | /* fall through */ |
5ab944f9 SS |
1676 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1677 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
bd0072ec | 1678 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
5ab944f9 | 1679 | break; |
5ab944f9 SS |
1680 | case FSF_GOOD: |
1681 | wka_port->handle = header->port_handle; | |
27f492cc SS |
1682 | /* fall through */ |
1683 | case FSF_PORT_ALREADY_OPEN: | |
bd0072ec | 1684 | wka_port->status = ZFCP_FC_WKA_PORT_ONLINE; |
5ab944f9 SS |
1685 | } |
1686 | out: | |
1687 | wake_up(&wka_port->completion_wq); | |
1688 | } | |
1689 | ||
1690 | /** | |
1691 | * zfcp_fsf_open_wka_port - create and send open wka-port request | |
bd0072ec | 1692 | * @wka_port: pointer to struct zfcp_fc_wka_port |
5ab944f9 SS |
1693 | * Returns: 0 on success, error otherwise |
1694 | */ | |
bd0072ec | 1695 | int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port) |
5ab944f9 | 1696 | { |
564e1c86 | 1697 | struct zfcp_qdio *qdio = wka_port->adapter->qdio; |
2dfa6688 | 1698 | struct zfcp_fsf_req *req; |
106d45f3 | 1699 | unsigned long req_id = 0; |
5ab944f9 SS |
1700 | int retval = -EIO; |
1701 | ||
44a24cb3 | 1702 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1703 | if (zfcp_qdio_sbal_get(qdio)) |
5ab944f9 SS |
1704 | goto out; |
1705 | ||
564e1c86 | 1706 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID, |
3ec90878 | 1707 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 1708 | qdio->adapter->pool.erp_req); |
09a46c6e | 1709 | |
4e7d7af4 | 1710 | if (IS_ERR(req)) { |
5ab944f9 SS |
1711 | retval = PTR_ERR(req); |
1712 | goto out; | |
1713 | } | |
1714 | ||
09a46c6e | 1715 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1716 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
5ab944f9 SS |
1717 | |
1718 | req->handler = zfcp_fsf_open_wka_port_handler; | |
800c0cad | 1719 | hton24(req->qtcb->bottom.support.d_id, wka_port->d_id); |
5ab944f9 SS |
1720 | req->data = wka_port; |
1721 | ||
106d45f3 BB |
1722 | req_id = req->req_id; |
1723 | ||
5ab944f9 SS |
1724 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
1725 | retval = zfcp_fsf_req_send(req); | |
1726 | if (retval) | |
1727 | zfcp_fsf_req_free(req); | |
b76becde | 1728 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
5ab944f9 | 1729 | out: |
44a24cb3 | 1730 | spin_unlock_irq(&qdio->req_q_lock); |
2dfa6688 | 1731 | if (!retval) |
106d45f3 | 1732 | zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req_id); |
5ab944f9 SS |
1733 | return retval; |
1734 | } | |
1735 | ||
1736 | static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req) | |
1737 | { | |
bd0072ec | 1738 | struct zfcp_fc_wka_port *wka_port = req->data; |
5ab944f9 SS |
1739 | |
1740 | if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) { | |
1741 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
ea4a3a6a | 1742 | zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1"); |
5ab944f9 SS |
1743 | } |
1744 | ||
bd0072ec | 1745 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
5ab944f9 SS |
1746 | wake_up(&wka_port->completion_wq); |
1747 | } | |
1748 | ||
1749 | /** | |
1750 | * zfcp_fsf_close_wka_port - create and send close wka port request | |
bd0072ec | 1751 | * @wka_port: WKA port to open |
5ab944f9 SS |
1752 | * Returns: 0 on success, error otherwise |
1753 | */ | |
bd0072ec | 1754 | int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port) |
5ab944f9 | 1755 | { |
564e1c86 | 1756 | struct zfcp_qdio *qdio = wka_port->adapter->qdio; |
2dfa6688 | 1757 | struct zfcp_fsf_req *req; |
106d45f3 | 1758 | unsigned long req_id = 0; |
5ab944f9 SS |
1759 | int retval = -EIO; |
1760 | ||
44a24cb3 | 1761 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1762 | if (zfcp_qdio_sbal_get(qdio)) |
5ab944f9 SS |
1763 | goto out; |
1764 | ||
564e1c86 | 1765 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT, |
3ec90878 | 1766 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 1767 | qdio->adapter->pool.erp_req); |
09a46c6e | 1768 | |
4e7d7af4 | 1769 | if (IS_ERR(req)) { |
5ab944f9 SS |
1770 | retval = PTR_ERR(req); |
1771 | goto out; | |
1772 | } | |
1773 | ||
09a46c6e | 1774 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1775 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
5ab944f9 SS |
1776 | |
1777 | req->handler = zfcp_fsf_close_wka_port_handler; | |
1778 | req->data = wka_port; | |
1779 | req->qtcb->header.port_handle = wka_port->handle; | |
1780 | ||
106d45f3 BB |
1781 | req_id = req->req_id; |
1782 | ||
5ab944f9 SS |
1783 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
1784 | retval = zfcp_fsf_req_send(req); | |
1785 | if (retval) | |
1786 | zfcp_fsf_req_free(req); | |
b76becde | 1787 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
5ab944f9 | 1788 | out: |
44a24cb3 | 1789 | spin_unlock_irq(&qdio->req_q_lock); |
2dfa6688 | 1790 | if (!retval) |
106d45f3 | 1791 | zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req_id); |
5ab944f9 SS |
1792 | return retval; |
1793 | } | |
1794 | ||
c41f8cbd | 1795 | static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1796 | { |
c41f8cbd SS |
1797 | struct zfcp_port *port = req->data; |
1798 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
b62a8d9b | 1799 | struct scsi_device *sdev; |
1da177e4 | 1800 | |
c41f8cbd | 1801 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
a5b11dda | 1802 | return; |
1da177e4 | 1803 | |
1da177e4 | 1804 | switch (header->fsf_status) { |
1da177e4 | 1805 | case FSF_PORT_HANDLE_NOT_VALID: |
ea4a3a6a | 1806 | zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1"); |
c41f8cbd | 1807 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1808 | break; |
1da177e4 | 1809 | case FSF_PORT_BOXED: |
5c815d15 CS |
1810 | /* can't use generic zfcp_erp_modify_port_status because |
1811 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ | |
805de8f4 | 1812 | atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
b62a8d9b CS |
1813 | shost_for_each_device(sdev, port->adapter->scsi_host) |
1814 | if (sdev_to_zfcp(sdev)->port == port) | |
805de8f4 | 1815 | atomic_andnot(ZFCP_STATUS_COMMON_OPEN, |
b62a8d9b | 1816 | &sdev_to_zfcp(sdev)->status); |
edaed859 SS |
1817 | zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED); |
1818 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, | |
ea4a3a6a | 1819 | "fscpph2"); |
4c571c65 | 1820 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1821 | break; |
1da177e4 | 1822 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1823 | switch (header->fsf_status_qual.word[0]) { |
1824 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
c41f8cbd | 1825 | /* fall through */ |
1da177e4 | 1826 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 1827 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1828 | break; |
1da177e4 LT |
1829 | } |
1830 | break; | |
1da177e4 | 1831 | case FSF_GOOD: |
1da177e4 LT |
1832 | /* can't use generic zfcp_erp_modify_port_status because |
1833 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port | |
1834 | */ | |
805de8f4 | 1835 | atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
b62a8d9b CS |
1836 | shost_for_each_device(sdev, port->adapter->scsi_host) |
1837 | if (sdev_to_zfcp(sdev)->port == port) | |
805de8f4 | 1838 | atomic_andnot(ZFCP_STATUS_COMMON_OPEN, |
b62a8d9b | 1839 | &sdev_to_zfcp(sdev)->status); |
1da177e4 | 1840 | break; |
1da177e4 | 1841 | } |
1da177e4 LT |
1842 | } |
1843 | ||
c41f8cbd SS |
1844 | /** |
1845 | * zfcp_fsf_close_physical_port - close physical port | |
1846 | * @erp_action: pointer to struct zfcp_erp_action | |
1847 | * Returns: 0 on success | |
1da177e4 | 1848 | */ |
c41f8cbd | 1849 | int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
1da177e4 | 1850 | { |
564e1c86 | 1851 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
c41f8cbd SS |
1852 | struct zfcp_fsf_req *req; |
1853 | int retval = -EIO; | |
1854 | ||
44a24cb3 | 1855 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1856 | if (zfcp_qdio_sbal_get(qdio)) |
1da177e4 | 1857 | goto out; |
1da177e4 | 1858 | |
564e1c86 | 1859 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT, |
3ec90878 | 1860 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 1861 | qdio->adapter->pool.erp_req); |
09a46c6e | 1862 | |
025270f0 | 1863 | if (IS_ERR(req)) { |
c41f8cbd SS |
1864 | retval = PTR_ERR(req); |
1865 | goto out; | |
1866 | } | |
1da177e4 | 1867 | |
09a46c6e | 1868 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1869 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 1870 | |
c41f8cbd SS |
1871 | req->data = erp_action->port; |
1872 | req->qtcb->header.port_handle = erp_action->port->handle; | |
1873 | req->erp_action = erp_action; | |
1874 | req->handler = zfcp_fsf_close_physical_port_handler; | |
e60a6d69 | 1875 | erp_action->fsf_req_id = req->req_id; |
c41f8cbd | 1876 | |
287ac01a | 1877 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1878 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1879 | if (retval) { |
c41f8cbd | 1880 | zfcp_fsf_req_free(req); |
e60a6d69 | 1881 | erp_action->fsf_req_id = 0; |
1da177e4 | 1882 | } |
b76becde | 1883 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd | 1884 | out: |
44a24cb3 | 1885 | spin_unlock_irq(&qdio->req_q_lock); |
1da177e4 LT |
1886 | return retval; |
1887 | } | |
1888 | ||
b62a8d9b | 1889 | static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1890 | { |
c41f8cbd | 1891 | struct zfcp_adapter *adapter = req->adapter; |
b62a8d9b | 1892 | struct scsi_device *sdev = req->data; |
d436de8c | 1893 | struct zfcp_scsi_dev *zfcp_sdev; |
c41f8cbd | 1894 | struct fsf_qtcb_header *header = &req->qtcb->header; |
663e0890 | 1895 | union fsf_status_qual *qual = &header->fsf_status_qual; |
1da177e4 | 1896 | |
c41f8cbd | 1897 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
44cc76f2 | 1898 | return; |
1da177e4 | 1899 | |
d436de8c MP |
1900 | zfcp_sdev = sdev_to_zfcp(sdev); |
1901 | ||
805de8f4 | 1902 | atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
663e0890 | 1903 | ZFCP_STATUS_COMMON_ACCESS_BOXED, |
b62a8d9b | 1904 | &zfcp_sdev->status); |
1da177e4 | 1905 | |
1da177e4 LT |
1906 | switch (header->fsf_status) { |
1907 | ||
1908 | case FSF_PORT_HANDLE_NOT_VALID: | |
ea4a3a6a | 1909 | zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1"); |
c41f8cbd | 1910 | /* fall through */ |
1da177e4 | 1911 | case FSF_LUN_ALREADY_OPEN: |
1da177e4 | 1912 | break; |
1da177e4 | 1913 | case FSF_PORT_BOXED: |
edaed859 SS |
1914 | zfcp_erp_set_port_status(zfcp_sdev->port, |
1915 | ZFCP_STATUS_COMMON_ACCESS_BOXED); | |
1916 | zfcp_erp_port_reopen(zfcp_sdev->port, | |
ea4a3a6a | 1917 | ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2"); |
4c571c65 | 1918 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1919 | break; |
1da177e4 | 1920 | case FSF_LUN_SHARING_VIOLATION: |
663e0890 MP |
1921 | if (qual->word[0]) |
1922 | dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev, | |
e0effe89 | 1923 | "LUN 0x%016Lx on port 0x%016Lx is already in " |
663e0890 MP |
1924 | "use by CSS%d, MIF Image ID %x\n", |
1925 | zfcp_scsi_dev_lun(sdev), | |
1926 | (unsigned long long)zfcp_sdev->port->wwpn, | |
1927 | qual->fsf_queue_designator.cssid, | |
1928 | qual->fsf_queue_designator.hla); | |
1929 | zfcp_erp_set_lun_status(sdev, | |
1930 | ZFCP_STATUS_COMMON_ERP_FAILED | | |
1931 | ZFCP_STATUS_COMMON_ACCESS_DENIED); | |
c41f8cbd | 1932 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1933 | break; |
1da177e4 | 1934 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
c41f8cbd | 1935 | dev_warn(&adapter->ccw_device->dev, |
ff3b24fa CS |
1936 | "No handle is available for LUN " |
1937 | "0x%016Lx on port 0x%016Lx\n", | |
b62a8d9b CS |
1938 | (unsigned long long)zfcp_scsi_dev_lun(sdev), |
1939 | (unsigned long long)zfcp_sdev->port->wwpn); | |
edaed859 | 1940 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED); |
c41f8cbd SS |
1941 | /* fall through */ |
1942 | case FSF_INVALID_COMMAND_OPTION: | |
1943 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1da177e4 | 1944 | break; |
1da177e4 | 1945 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1946 | switch (header->fsf_status_qual.word[0]) { |
1947 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
b62a8d9b | 1948 | zfcp_fc_test_link(zfcp_sdev->port); |
c41f8cbd | 1949 | /* fall through */ |
1da177e4 | 1950 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 1951 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1952 | break; |
1da177e4 LT |
1953 | } |
1954 | break; | |
1955 | ||
1da177e4 | 1956 | case FSF_GOOD: |
b62a8d9b | 1957 | zfcp_sdev->lun_handle = header->lun_handle; |
805de8f4 | 1958 | atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status); |
1da177e4 | 1959 | break; |
1da177e4 | 1960 | } |
1da177e4 LT |
1961 | } |
1962 | ||
c41f8cbd | 1963 | /** |
b62a8d9b | 1964 | * zfcp_fsf_open_lun - open LUN |
c41f8cbd SS |
1965 | * @erp_action: pointer to struct zfcp_erp_action |
1966 | * Returns: 0 on success, error otherwise | |
1da177e4 | 1967 | */ |
b62a8d9b | 1968 | int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action) |
1da177e4 | 1969 | { |
c41f8cbd | 1970 | struct zfcp_adapter *adapter = erp_action->adapter; |
564e1c86 | 1971 | struct zfcp_qdio *qdio = adapter->qdio; |
c41f8cbd SS |
1972 | struct zfcp_fsf_req *req; |
1973 | int retval = -EIO; | |
1974 | ||
44a24cb3 | 1975 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 1976 | if (zfcp_qdio_sbal_get(qdio)) |
1da177e4 | 1977 | goto out; |
1da177e4 | 1978 | |
564e1c86 | 1979 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN, |
3ec90878 | 1980 | SBAL_SFLAGS0_TYPE_READ, |
a4623c46 | 1981 | adapter->pool.erp_req); |
09a46c6e | 1982 | |
025270f0 | 1983 | if (IS_ERR(req)) { |
c41f8cbd SS |
1984 | retval = PTR_ERR(req); |
1985 | goto out; | |
1986 | } | |
1987 | ||
09a46c6e | 1988 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 1989 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 1990 | |
c41f8cbd | 1991 | req->qtcb->header.port_handle = erp_action->port->handle; |
b62a8d9b CS |
1992 | req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev); |
1993 | req->handler = zfcp_fsf_open_lun_handler; | |
1994 | req->data = erp_action->sdev; | |
c41f8cbd | 1995 | req->erp_action = erp_action; |
e60a6d69 | 1996 | erp_action->fsf_req_id = req->req_id; |
c41f8cbd SS |
1997 | |
1998 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) | |
1999 | req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING; | |
2000 | ||
287ac01a | 2001 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 2002 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 2003 | if (retval) { |
c41f8cbd | 2004 | zfcp_fsf_req_free(req); |
e60a6d69 | 2005 | erp_action->fsf_req_id = 0; |
1da177e4 | 2006 | } |
b76becde | 2007 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd | 2008 | out: |
44a24cb3 | 2009 | spin_unlock_irq(&qdio->req_q_lock); |
1da177e4 LT |
2010 | return retval; |
2011 | } | |
2012 | ||
b62a8d9b | 2013 | static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req) |
1da177e4 | 2014 | { |
b62a8d9b | 2015 | struct scsi_device *sdev = req->data; |
d436de8c | 2016 | struct zfcp_scsi_dev *zfcp_sdev; |
1da177e4 | 2017 | |
c41f8cbd | 2018 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
44cc76f2 | 2019 | return; |
1da177e4 | 2020 | |
d436de8c MP |
2021 | zfcp_sdev = sdev_to_zfcp(sdev); |
2022 | ||
c41f8cbd | 2023 | switch (req->qtcb->header.fsf_status) { |
1da177e4 | 2024 | case FSF_PORT_HANDLE_NOT_VALID: |
ea4a3a6a | 2025 | zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1"); |
c41f8cbd | 2026 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 2027 | break; |
1da177e4 | 2028 | case FSF_LUN_HANDLE_NOT_VALID: |
ea4a3a6a | 2029 | zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2"); |
c41f8cbd | 2030 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 2031 | break; |
1da177e4 | 2032 | case FSF_PORT_BOXED: |
edaed859 SS |
2033 | zfcp_erp_set_port_status(zfcp_sdev->port, |
2034 | ZFCP_STATUS_COMMON_ACCESS_BOXED); | |
2035 | zfcp_erp_port_reopen(zfcp_sdev->port, | |
ea4a3a6a | 2036 | ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3"); |
4c571c65 | 2037 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 2038 | break; |
1da177e4 | 2039 | case FSF_ADAPTER_STATUS_AVAILABLE: |
c41f8cbd | 2040 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
1da177e4 | 2041 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
b62a8d9b | 2042 | zfcp_fc_test_link(zfcp_sdev->port); |
c41f8cbd | 2043 | /* fall through */ |
1da177e4 | 2044 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 2045 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
2046 | break; |
2047 | } | |
2048 | break; | |
1da177e4 | 2049 | case FSF_GOOD: |
805de8f4 | 2050 | atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status); |
1da177e4 | 2051 | break; |
1da177e4 | 2052 | } |
1da177e4 LT |
2053 | } |
2054 | ||
2055 | /** | |
b62a8d9b CS |
2056 | * zfcp_fsf_close_LUN - close LUN |
2057 | * @erp_action: pointer to erp_action triggering the "close LUN" | |
c41f8cbd | 2058 | * Returns: 0 on success, error otherwise |
1da177e4 | 2059 | */ |
b62a8d9b | 2060 | int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action) |
1da177e4 | 2061 | { |
564e1c86 | 2062 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
b62a8d9b | 2063 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev); |
c41f8cbd SS |
2064 | struct zfcp_fsf_req *req; |
2065 | int retval = -EIO; | |
1da177e4 | 2066 | |
44a24cb3 | 2067 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 2068 | if (zfcp_qdio_sbal_get(qdio)) |
1da177e4 | 2069 | goto out; |
09a46c6e | 2070 | |
564e1c86 | 2071 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN, |
3ec90878 | 2072 | SBAL_SFLAGS0_TYPE_READ, |
564e1c86 | 2073 | qdio->adapter->pool.erp_req); |
09a46c6e | 2074 | |
025270f0 | 2075 | if (IS_ERR(req)) { |
c41f8cbd SS |
2076 | retval = PTR_ERR(req); |
2077 | goto out; | |
2078 | } | |
1da177e4 | 2079 | |
09a46c6e | 2080 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
1674b405 | 2081 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 2082 | |
c41f8cbd | 2083 | req->qtcb->header.port_handle = erp_action->port->handle; |
b62a8d9b CS |
2084 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
2085 | req->handler = zfcp_fsf_close_lun_handler; | |
2086 | req->data = erp_action->sdev; | |
c41f8cbd | 2087 | req->erp_action = erp_action; |
e60a6d69 | 2088 | erp_action->fsf_req_id = req->req_id; |
fdf23452 | 2089 | |
287ac01a | 2090 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd SS |
2091 | retval = zfcp_fsf_req_send(req); |
2092 | if (retval) { | |
2093 | zfcp_fsf_req_free(req); | |
e60a6d69 | 2094 | erp_action->fsf_req_id = 0; |
c41f8cbd | 2095 | } |
b76becde | 2096 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
c41f8cbd | 2097 | out: |
44a24cb3 | 2098 | spin_unlock_irq(&qdio->req_q_lock); |
c41f8cbd | 2099 | return retval; |
1da177e4 LT |
2100 | } |
2101 | ||
eb67f93f | 2102 | static void zfcp_fsf_update_lat(struct zfcp_latency_record *lat_rec, u32 lat) |
c9615858 CS |
2103 | { |
2104 | lat_rec->sum += lat; | |
c41f8cbd SS |
2105 | lat_rec->min = min(lat_rec->min, lat); |
2106 | lat_rec->max = max(lat_rec->max, lat); | |
c9615858 CS |
2107 | } |
2108 | ||
d9742b42 | 2109 | static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi) |
c9615858 | 2110 | { |
d9742b42 | 2111 | struct fsf_qual_latency_info *lat_in; |
eb67f93f | 2112 | struct zfcp_latency_cont *lat = NULL; |
d436de8c | 2113 | struct zfcp_scsi_dev *zfcp_sdev; |
d9742b42 CS |
2114 | struct zfcp_blk_drv_data blktrc; |
2115 | int ticks = req->adapter->timer_ticks; | |
c9615858 | 2116 | |
d9742b42 | 2117 | lat_in = &req->qtcb->prefix.prot_status_qual.latency_info; |
c9615858 | 2118 | |
d9742b42 CS |
2119 | blktrc.flags = 0; |
2120 | blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC; | |
2121 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
2122 | blktrc.flags |= ZFCP_BLK_REQ_ERROR; | |
706eca49 | 2123 | blktrc.inb_usage = 0; |
34c2b712 | 2124 | blktrc.outb_usage = req->qdio_req.qdio_outb_usage; |
d9742b42 | 2125 | |
5bbf297c CS |
2126 | if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA && |
2127 | !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { | |
d436de8c | 2128 | zfcp_sdev = sdev_to_zfcp(scsi->device); |
d9742b42 CS |
2129 | blktrc.flags |= ZFCP_BLK_LAT_VALID; |
2130 | blktrc.channel_lat = lat_in->channel_lat * ticks; | |
2131 | blktrc.fabric_lat = lat_in->fabric_lat * ticks; | |
2132 | ||
2133 | switch (req->qtcb->bottom.io.data_direction) { | |
ef3eb71d FB |
2134 | case FSF_DATADIR_DIF_READ_STRIP: |
2135 | case FSF_DATADIR_DIF_READ_CONVERT: | |
d9742b42 | 2136 | case FSF_DATADIR_READ: |
b62a8d9b | 2137 | lat = &zfcp_sdev->latencies.read; |
d9742b42 | 2138 | break; |
ef3eb71d FB |
2139 | case FSF_DATADIR_DIF_WRITE_INSERT: |
2140 | case FSF_DATADIR_DIF_WRITE_CONVERT: | |
d9742b42 | 2141 | case FSF_DATADIR_WRITE: |
b62a8d9b | 2142 | lat = &zfcp_sdev->latencies.write; |
d9742b42 CS |
2143 | break; |
2144 | case FSF_DATADIR_CMND: | |
b62a8d9b | 2145 | lat = &zfcp_sdev->latencies.cmd; |
d9742b42 CS |
2146 | break; |
2147 | } | |
1da177e4 | 2148 | |
d9742b42 | 2149 | if (lat) { |
b62a8d9b | 2150 | spin_lock(&zfcp_sdev->latencies.lock); |
d9742b42 CS |
2151 | zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat); |
2152 | zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat); | |
2153 | lat->counter++; | |
b62a8d9b | 2154 | spin_unlock(&zfcp_sdev->latencies.lock); |
d9742b42 | 2155 | } |
0997f1c5 | 2156 | } |
0997f1c5 | 2157 | |
d9742b42 CS |
2158 | blk_add_driver_data(scsi->request->q, scsi->request, &blktrc, |
2159 | sizeof(blktrc)); | |
0997f1c5 | 2160 | } |
0997f1c5 | 2161 | |
266883f2 SM |
2162 | /** |
2163 | * zfcp_fsf_fcp_handler_common() - FCP response handler common to I/O and TMF. | |
2164 | * @req: Pointer to FSF request. | |
2165 | * @sdev: Pointer to SCSI device as request context. | |
2166 | */ | |
2167 | static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req, | |
2168 | struct scsi_device *sdev) | |
c41f8cbd | 2169 | { |
d436de8c | 2170 | struct zfcp_scsi_dev *zfcp_sdev; |
c41f8cbd SS |
2171 | struct fsf_qtcb_header *header = &req->qtcb->header; |
2172 | ||
c41f8cbd | 2173 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
c61b536c | 2174 | return; |
1da177e4 | 2175 | |
d436de8c MP |
2176 | zfcp_sdev = sdev_to_zfcp(sdev); |
2177 | ||
c41f8cbd SS |
2178 | switch (header->fsf_status) { |
2179 | case FSF_HANDLE_MISMATCH: | |
2180 | case FSF_PORT_HANDLE_NOT_VALID: | |
266883f2 | 2181 | zfcp_erp_adapter_reopen(req->adapter, 0, "fssfch1"); |
c41f8cbd SS |
2182 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2183 | break; | |
2184 | case FSF_FCPLUN_NOT_VALID: | |
2185 | case FSF_LUN_HANDLE_NOT_VALID: | |
ea4a3a6a | 2186 | zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2"); |
c41f8cbd | 2187 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 2188 | break; |
c41f8cbd SS |
2189 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
2190 | zfcp_fsf_class_not_supp(req); | |
1da177e4 | 2191 | break; |
c41f8cbd SS |
2192 | case FSF_DIRECTION_INDICATOR_NOT_VALID: |
2193 | dev_err(&req->adapter->ccw_device->dev, | |
b62a8d9b | 2194 | "Incorrect direction %d, LUN 0x%016Lx on port " |
ff3b24fa | 2195 | "0x%016Lx closed\n", |
c41f8cbd | 2196 | req->qtcb->bottom.io.data_direction, |
b62a8d9b CS |
2197 | (unsigned long long)zfcp_scsi_dev_lun(sdev), |
2198 | (unsigned long long)zfcp_sdev->port->wwpn); | |
266883f2 | 2199 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch3"); |
c41f8cbd SS |
2200 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2201 | break; | |
2202 | case FSF_CMND_LENGTH_NOT_VALID: | |
2203 | dev_err(&req->adapter->ccw_device->dev, | |
724e1443 SM |
2204 | "Incorrect FCP_CMND length %d, FCP device closed\n", |
2205 | req->qtcb->bottom.io.fcp_cmnd_length); | |
266883f2 | 2206 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch4"); |
c41f8cbd SS |
2207 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2208 | break; | |
2209 | case FSF_PORT_BOXED: | |
edaed859 SS |
2210 | zfcp_erp_set_port_status(zfcp_sdev->port, |
2211 | ZFCP_STATUS_COMMON_ACCESS_BOXED); | |
2212 | zfcp_erp_port_reopen(zfcp_sdev->port, | |
ea4a3a6a | 2213 | ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5"); |
4c571c65 | 2214 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
c41f8cbd SS |
2215 | break; |
2216 | case FSF_LUN_BOXED: | |
edaed859 SS |
2217 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED); |
2218 | zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED, | |
ea4a3a6a | 2219 | "fssfch6"); |
4c571c65 | 2220 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
c41f8cbd SS |
2221 | break; |
2222 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
2223 | if (header->fsf_status_qual.word[0] == | |
2224 | FSF_SQ_INVOKE_LINK_TEST_PROCEDURE) | |
b62a8d9b | 2225 | zfcp_fc_test_link(zfcp_sdev->port); |
c41f8cbd | 2226 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 2227 | break; |
1da177e4 | 2228 | } |
c61b536c CS |
2229 | } |
2230 | ||
2231 | static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req) | |
2232 | { | |
2233 | struct scsi_cmnd *scpnt; | |
2234 | struct fcp_resp_with_ext *fcp_rsp; | |
2235 | unsigned long flags; | |
2236 | ||
c61b536c CS |
2237 | read_lock_irqsave(&req->adapter->abort_lock, flags); |
2238 | ||
2239 | scpnt = req->data; | |
2240 | if (unlikely(!scpnt)) { | |
2241 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); | |
2242 | return; | |
c41f8cbd | 2243 | } |
c61b536c | 2244 | |
266883f2 | 2245 | zfcp_fsf_fcp_handler_common(req, scpnt->device); |
5bfb2c31 | 2246 | |
c61b536c CS |
2247 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
2248 | set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED); | |
2249 | goto skip_fsfstatus; | |
2250 | } | |
2251 | ||
2252 | switch (req->qtcb->header.fsf_status) { | |
2253 | case FSF_INCONSISTENT_PROT_DATA: | |
2254 | case FSF_INVALID_PROT_PARM: | |
2255 | set_host_byte(scpnt, DID_ERROR); | |
2256 | goto skip_fsfstatus; | |
2257 | case FSF_BLOCK_GUARD_CHECK_FAILURE: | |
2258 | zfcp_scsi_dif_sense_error(scpnt, 0x1); | |
2259 | goto skip_fsfstatus; | |
2260 | case FSF_APP_TAG_CHECK_FAILURE: | |
2261 | zfcp_scsi_dif_sense_error(scpnt, 0x2); | |
2262 | goto skip_fsfstatus; | |
2263 | case FSF_REF_TAG_CHECK_FAILURE: | |
2264 | zfcp_scsi_dif_sense_error(scpnt, 0x3); | |
2265 | goto skip_fsfstatus; | |
2266 | } | |
df00d7b8 SM |
2267 | BUILD_BUG_ON(sizeof(struct fcp_resp_with_ext) > FSF_FCP_RSP_SIZE); |
2268 | fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu; | |
c61b536c CS |
2269 | zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt); |
2270 | ||
2271 | skip_fsfstatus: | |
2272 | zfcp_fsf_req_trace(req, scpnt); | |
250a1352 | 2273 | zfcp_dbf_scsi_result(scpnt, req); |
c61b536c CS |
2274 | |
2275 | scpnt->host_scribble = NULL; | |
2276 | (scpnt->scsi_done) (scpnt); | |
2277 | /* | |
2278 | * We must hold this lock until scsi_done has been called. | |
2279 | * Otherwise we may call scsi_done after abort regarding this | |
2280 | * command has completed. | |
2281 | * Note: scsi_done must not block! | |
2282 | */ | |
2283 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); | |
1da177e4 LT |
2284 | } |
2285 | ||
ef3eb71d FB |
2286 | static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir) |
2287 | { | |
2288 | switch (scsi_get_prot_op(scsi_cmnd)) { | |
2289 | case SCSI_PROT_NORMAL: | |
2290 | switch (scsi_cmnd->sc_data_direction) { | |
2291 | case DMA_NONE: | |
2292 | *data_dir = FSF_DATADIR_CMND; | |
2293 | break; | |
2294 | case DMA_FROM_DEVICE: | |
2295 | *data_dir = FSF_DATADIR_READ; | |
2296 | break; | |
2297 | case DMA_TO_DEVICE: | |
2298 | *data_dir = FSF_DATADIR_WRITE; | |
2299 | break; | |
2300 | case DMA_BIDIRECTIONAL: | |
2301 | return -EINVAL; | |
2302 | } | |
2303 | break; | |
2304 | ||
2305 | case SCSI_PROT_READ_STRIP: | |
2306 | *data_dir = FSF_DATADIR_DIF_READ_STRIP; | |
2307 | break; | |
2308 | case SCSI_PROT_WRITE_INSERT: | |
2309 | *data_dir = FSF_DATADIR_DIF_WRITE_INSERT; | |
2310 | break; | |
2311 | case SCSI_PROT_READ_PASS: | |
2312 | *data_dir = FSF_DATADIR_DIF_READ_CONVERT; | |
2313 | break; | |
2314 | case SCSI_PROT_WRITE_PASS: | |
2315 | *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT; | |
2316 | break; | |
2317 | default: | |
2318 | return -EINVAL; | |
2319 | } | |
2320 | ||
2321 | return 0; | |
2322 | } | |
2323 | ||
c41f8cbd | 2324 | /** |
b62a8d9b | 2325 | * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command) |
c41f8cbd | 2326 | * @scsi_cmnd: scsi command to be sent |
1da177e4 | 2327 | */ |
b62a8d9b | 2328 | int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd) |
1da177e4 | 2329 | { |
c41f8cbd | 2330 | struct zfcp_fsf_req *req; |
4318e08c | 2331 | struct fcp_cmnd *fcp_cmnd; |
3ec90878 | 2332 | u8 sbtype = SBAL_SFLAGS0_TYPE_READ; |
86a9668a | 2333 | int retval = -EIO; |
b62a8d9b CS |
2334 | struct scsi_device *sdev = scsi_cmnd->device; |
2335 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); | |
2336 | struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; | |
564e1c86 | 2337 | struct zfcp_qdio *qdio = adapter->qdio; |
ef3eb71d | 2338 | struct fsf_qtcb_bottom_io *io; |
e55f8753 | 2339 | unsigned long flags; |
1da177e4 | 2340 | |
b62a8d9b | 2341 | if (unlikely(!(atomic_read(&zfcp_sdev->status) & |
c41f8cbd SS |
2342 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
2343 | return -EBUSY; | |
1da177e4 | 2344 | |
e55f8753 | 2345 | spin_lock_irqsave(&qdio->req_q_lock, flags); |
706eca49 | 2346 | if (atomic_read(&qdio->req_q_free) <= 0) { |
564e1c86 | 2347 | atomic_inc(&qdio->req_q_full); |
c41f8cbd | 2348 | goto out; |
8fdf30d5 | 2349 | } |
09a46c6e | 2350 | |
1674b405 | 2351 | if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) |
3ec90878 | 2352 | sbtype = SBAL_SFLAGS0_TYPE_WRITE; |
1674b405 | 2353 | |
564e1c86 | 2354 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND, |
1674b405 | 2355 | sbtype, adapter->pool.scsi_req); |
09a46c6e | 2356 | |
025270f0 | 2357 | if (IS_ERR(req)) { |
c41f8cbd SS |
2358 | retval = PTR_ERR(req); |
2359 | goto out; | |
2360 | } | |
2361 | ||
ef3eb71d FB |
2362 | scsi_cmnd->host_scribble = (unsigned char *) req->req_id; |
2363 | ||
2364 | io = &req->qtcb->bottom.io; | |
09a46c6e | 2365 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
c41f8cbd | 2366 | req->data = scsi_cmnd; |
c61b536c | 2367 | req->handler = zfcp_fsf_fcp_cmnd_handler; |
b62a8d9b CS |
2368 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
2369 | req->qtcb->header.port_handle = zfcp_sdev->port->handle; | |
ef3eb71d FB |
2370 | io->service_class = FSF_CLASS_3; |
2371 | io->fcp_cmnd_length = FCP_CMND_LEN; | |
c41f8cbd | 2372 | |
ef3eb71d FB |
2373 | if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) { |
2374 | io->data_block_length = scsi_cmnd->device->sector_size; | |
2375 | io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF; | |
1da177e4 LT |
2376 | } |
2377 | ||
cc405ace SM |
2378 | if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction)) |
2379 | goto failed_scsi_cmnd; | |
ef3eb71d | 2380 | |
df00d7b8 SM |
2381 | BUILD_BUG_ON(sizeof(struct fcp_cmnd) > FSF_FCP_CMND_SIZE); |
2382 | fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu; | |
e0116c91 | 2383 | zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd); |
1da177e4 | 2384 | |
71b8e45d SM |
2385 | if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) && |
2386 | scsi_prot_sg_count(scsi_cmnd)) { | |
ef3eb71d FB |
2387 | zfcp_qdio_set_data_div(qdio, &req->qdio_req, |
2388 | scsi_prot_sg_count(scsi_cmnd)); | |
86a9668a SS |
2389 | retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, |
2390 | scsi_prot_sglist(scsi_cmnd)); | |
2391 | if (retval) | |
2392 | goto failed_scsi_cmnd; | |
2393 | io->prot_data_length = zfcp_qdio_real_bytes( | |
ef3eb71d | 2394 | scsi_prot_sglist(scsi_cmnd)); |
ef3eb71d FB |
2395 | } |
2396 | ||
86a9668a SS |
2397 | retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, |
2398 | scsi_sglist(scsi_cmnd)); | |
2399 | if (unlikely(retval)) | |
c41f8cbd | 2400 | goto failed_scsi_cmnd; |
1da177e4 | 2401 | |
ef3eb71d | 2402 | zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req); |
86a9668a SS |
2403 | if (zfcp_adapter_multi_buffer_active(adapter)) |
2404 | zfcp_qdio_set_scount(qdio, &req->qdio_req); | |
ef3eb71d | 2405 | |
c41f8cbd SS |
2406 | retval = zfcp_fsf_req_send(req); |
2407 | if (unlikely(retval)) | |
2408 | goto failed_scsi_cmnd; | |
b76becde | 2409 | /* NOTE: DO NOT TOUCH req PAST THIS POINT! */ |
1da177e4 | 2410 | |
c41f8cbd | 2411 | goto out; |
1da177e4 | 2412 | |
c41f8cbd | 2413 | failed_scsi_cmnd: |
c41f8cbd SS |
2414 | zfcp_fsf_req_free(req); |
2415 | scsi_cmnd->host_scribble = NULL; | |
2416 | out: | |
e55f8753 | 2417 | spin_unlock_irqrestore(&qdio->req_q_lock, flags); |
c41f8cbd | 2418 | return retval; |
1da177e4 LT |
2419 | } |
2420 | ||
c61b536c CS |
2421 | static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req) |
2422 | { | |
266883f2 | 2423 | struct scsi_device *sdev = req->data; |
c61b536c CS |
2424 | struct fcp_resp_with_ext *fcp_rsp; |
2425 | struct fcp_resp_rsp_info *rsp_info; | |
2426 | ||
266883f2 | 2427 | zfcp_fsf_fcp_handler_common(req, sdev); |
c61b536c | 2428 | |
df00d7b8 | 2429 | fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu; |
c61b536c CS |
2430 | rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1]; |
2431 | ||
2432 | if ((rsp_info->rsp_code != FCP_TMF_CMPL) || | |
2433 | (req->status & ZFCP_STATUS_FSFREQ_ERROR)) | |
2434 | req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | |
2435 | } | |
2436 | ||
1da177e4 | 2437 | /** |
26f5fa9d SM |
2438 | * zfcp_fsf_fcp_task_mgmt() - Send SCSI task management command (TMF). |
2439 | * @sdev: Pointer to SCSI device to send the task management command to. | |
2440 | * @tm_flags: Unsigned byte for task management flags. | |
2441 | * | |
2442 | * Return: On success pointer to struct zfcp_fsf_req, %NULL otherwise. | |
1da177e4 | 2443 | */ |
26f5fa9d | 2444 | struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_device *sdev, |
b62a8d9b | 2445 | u8 tm_flags) |
1da177e4 | 2446 | { |
c41f8cbd | 2447 | struct zfcp_fsf_req *req = NULL; |
4318e08c | 2448 | struct fcp_cmnd *fcp_cmnd; |
39abb11a | 2449 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
b62a8d9b | 2450 | struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio; |
1da177e4 | 2451 | |
b62a8d9b | 2452 | if (unlikely(!(atomic_read(&zfcp_sdev->status) & |
c41f8cbd SS |
2453 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
2454 | return NULL; | |
1da177e4 | 2455 | |
44a24cb3 | 2456 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 | 2457 | if (zfcp_qdio_sbal_get(qdio)) |
c41f8cbd | 2458 | goto out; |
09a46c6e | 2459 | |
564e1c86 | 2460 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND, |
3ec90878 | 2461 | SBAL_SFLAGS0_TYPE_WRITE, |
564e1c86 | 2462 | qdio->adapter->pool.scsi_req); |
09a46c6e | 2463 | |
633528c3 SS |
2464 | if (IS_ERR(req)) { |
2465 | req = NULL; | |
c41f8cbd | 2466 | goto out; |
633528c3 | 2467 | } |
1da177e4 | 2468 | |
39abb11a SM |
2469 | req->data = sdev; |
2470 | ||
c61b536c | 2471 | req->handler = zfcp_fsf_fcp_task_mgmt_handler; |
b62a8d9b CS |
2472 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
2473 | req->qtcb->header.port_handle = zfcp_sdev->port->handle; | |
c41f8cbd SS |
2474 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
2475 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; | |
4318e08c | 2476 | req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN; |
c41f8cbd | 2477 | |
1674b405 | 2478 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
1da177e4 | 2479 | |
df00d7b8 | 2480 | fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu; |
39abb11a | 2481 | zfcp_fc_fcp_tm(fcp_cmnd, sdev, tm_flags); |
1da177e4 | 2482 | |
a0e86d95 | 2483 | zfcp_fsf_start_timer(req, ZFCP_FSF_SCSI_ER_TIMEOUT); |
b76becde BB |
2484 | if (!zfcp_fsf_req_send(req)) { |
2485 | /* NOTE: DO NOT TOUCH req, UNTIL IT COMPLETES! */ | |
c41f8cbd | 2486 | goto out; |
b76becde | 2487 | } |
1da177e4 | 2488 | |
c41f8cbd SS |
2489 | zfcp_fsf_req_free(req); |
2490 | req = NULL; | |
2491 | out: | |
44a24cb3 | 2492 | spin_unlock_irq(&qdio->req_q_lock); |
c41f8cbd SS |
2493 | return req; |
2494 | } | |
1da177e4 | 2495 | |
bd63eaf4 SS |
2496 | /** |
2497 | * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO | |
8684d614 | 2498 | * @qdio: pointer to struct zfcp_qdio |
bd63eaf4 SS |
2499 | * @sbal_idx: response queue index of SBAL to be processed |
2500 | */ | |
564e1c86 | 2501 | void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx) |
bd63eaf4 | 2502 | { |
564e1c86 | 2503 | struct zfcp_adapter *adapter = qdio->adapter; |
706eca49 | 2504 | struct qdio_buffer *sbal = qdio->res_q[sbal_idx]; |
bd63eaf4 SS |
2505 | struct qdio_buffer_element *sbale; |
2506 | struct zfcp_fsf_req *fsf_req; | |
b6bd2fb9 | 2507 | unsigned long req_id; |
bd63eaf4 SS |
2508 | int idx; |
2509 | ||
2510 | for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) { | |
2511 | ||
2512 | sbale = &sbal->element[idx]; | |
2db01da8 | 2513 | req_id = sbale->addr; |
b6bd2fb9 | 2514 | fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id); |
bd63eaf4 | 2515 | |
339f4f4e | 2516 | if (!fsf_req) { |
bd63eaf4 SS |
2517 | /* |
2518 | * Unknown request means that we have potentially memory | |
2519 | * corruption and must stop the machine immediately. | |
2520 | */ | |
339f4f4e | 2521 | zfcp_qdio_siosl(adapter); |
bd63eaf4 SS |
2522 | panic("error: unknown req_id (%lx) on adapter %s.\n", |
2523 | req_id, dev_name(&adapter->ccw_device->dev)); | |
339f4f4e | 2524 | } |
bd63eaf4 | 2525 | |
bd63eaf4 SS |
2526 | zfcp_fsf_req_complete(fsf_req); |
2527 | ||
3ec90878 | 2528 | if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY)) |
bd63eaf4 SS |
2529 | break; |
2530 | } | |
2531 | } |