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