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