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