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