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