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