]>
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 | |
c41f8cbd SS |
620 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
621 | fc_host_permanent_port_name(shost) = bottom->wwpn; | |
622 | else | |
623 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); | |
624 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; | |
625 | fc_host_supported_speeds(shost) = bottom->supported_speed; | |
626 | } | |
1da177e4 | 627 | |
c41f8cbd SS |
628 | static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req) |
629 | { | |
c41f8cbd SS |
630 | struct fsf_qtcb *qtcb = req->qtcb; |
631 | ||
632 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
633 | return; | |
634 | ||
635 | switch (qtcb->header.fsf_status) { | |
636 | case FSF_GOOD: | |
637 | zfcp_fsf_exchange_port_evaluate(req); | |
c41f8cbd SS |
638 | break; |
639 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | |
640 | zfcp_fsf_exchange_port_evaluate(req); | |
5ffd51a5 | 641 | zfcp_fsf_link_down_info_eval(req, "fsepdh1", |
c41f8cbd | 642 | &qtcb->header.fsf_status_qual.link_down_info); |
aef4a983 | 643 | break; |
1da177e4 | 644 | } |
c41f8cbd | 645 | } |
d26ab06e | 646 | |
c41f8cbd | 647 | static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter) |
dedbc2b3 CS |
648 | __releases(&adapter->req_q_lock) |
649 | __acquires(&adapter->req_q_lock) | |
c41f8cbd | 650 | { |
dedbc2b3 | 651 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
c41f8cbd | 652 | long ret; |
c41f8cbd | 653 | |
dedbc2b3 CS |
654 | if (atomic_read(&req_q->count) <= -REQUEST_LIST_SIZE) |
655 | return -EIO; | |
656 | if (atomic_read(&req_q->count) > 0) | |
657 | return 0; | |
658 | ||
659 | atomic_dec(&req_q->count); | |
0406289e | 660 | spin_unlock_bh(&adapter->req_q_lock); |
c41f8cbd | 661 | ret = wait_event_interruptible_timeout(adapter->request_wq, |
dedbc2b3 CS |
662 | atomic_read(&req_q->count) >= 0, |
663 | 5 * HZ); | |
664 | spin_lock_bh(&adapter->req_q_lock); | |
665 | atomic_inc(&req_q->count); | |
666 | ||
c41f8cbd SS |
667 | if (ret > 0) |
668 | return 0; | |
2450d3e7 SR |
669 | if (!ret) |
670 | atomic_inc(&adapter->qdio_outb_full); | |
c41f8cbd SS |
671 | return -EIO; |
672 | } | |
673 | ||
674 | static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool) | |
675 | { | |
676 | struct zfcp_fsf_req *req; | |
677 | req = mempool_alloc(pool, GFP_ATOMIC); | |
678 | if (!req) | |
679 | return NULL; | |
680 | memset(req, 0, sizeof(*req)); | |
88f2a977 | 681 | req->pool = pool; |
c41f8cbd SS |
682 | return req; |
683 | } | |
684 | ||
685 | static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool) | |
686 | { | |
687 | struct zfcp_fsf_req_qtcb *qtcb; | |
688 | ||
689 | if (likely(pool)) | |
690 | qtcb = mempool_alloc(pool, GFP_ATOMIC); | |
691 | else | |
692 | qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache, | |
693 | GFP_ATOMIC); | |
694 | if (unlikely(!qtcb)) | |
695 | return NULL; | |
696 | ||
697 | memset(qtcb, 0, sizeof(*qtcb)); | |
698 | qtcb->fsf_req.qtcb = &qtcb->qtcb; | |
699 | qtcb->fsf_req.pool = pool; | |
700 | ||
701 | return &qtcb->fsf_req; | |
702 | } | |
703 | ||
704 | static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter, | |
705 | u32 fsf_cmd, int req_flags, | |
706 | mempool_t *pool) | |
1da177e4 | 707 | { |
44cc76f2 | 708 | struct qdio_buffer_element *sbale; |
1da177e4 | 709 | |
c41f8cbd SS |
710 | struct zfcp_fsf_req *req; |
711 | struct zfcp_qdio_queue *req_q = &adapter->req_q; | |
951f746f | 712 | |
c41f8cbd SS |
713 | if (req_flags & ZFCP_REQ_NO_QTCB) |
714 | req = zfcp_fsf_alloc_noqtcb(pool); | |
715 | else | |
716 | req = zfcp_fsf_alloc_qtcb(pool); | |
1da177e4 | 717 | |
c41f8cbd SS |
718 | if (unlikely(!req)) |
719 | return ERR_PTR(-EIO); | |
1da177e4 | 720 | |
c41f8cbd SS |
721 | if (adapter->req_no == 0) |
722 | adapter->req_no++; | |
1da177e4 | 723 | |
c41f8cbd SS |
724 | INIT_LIST_HEAD(&req->list); |
725 | init_timer(&req->timer); | |
726 | init_waitqueue_head(&req->completion_wq); | |
1da177e4 | 727 | |
c41f8cbd SS |
728 | req->adapter = adapter; |
729 | req->fsf_command = fsf_cmd; | |
52bfb558 | 730 | req->req_id = adapter->req_no; |
c41f8cbd SS |
731 | req->sbal_number = 1; |
732 | req->sbal_first = req_q->first; | |
733 | req->sbal_last = req_q->first; | |
734 | req->sbale_curr = 1; | |
735 | ||
736 | sbale = zfcp_qdio_sbale_req(req); | |
737 | sbale[0].addr = (void *) req->req_id; | |
738 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; | |
739 | ||
740 | if (likely(req->qtcb)) { | |
741 | req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no; | |
742 | req->qtcb->prefix.req_id = req->req_id; | |
743 | req->qtcb->prefix.ulp_info = 26; | |
744 | req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command]; | |
745 | req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION; | |
746 | req->qtcb->header.req_handle = req->req_id; | |
747 | req->qtcb->header.fsf_command = req->fsf_command; | |
748 | req->seq_no = adapter->fsf_req_seq_no; | |
749 | req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; | |
750 | sbale[1].addr = (void *) req->qtcb; | |
751 | sbale[1].length = sizeof(struct fsf_qtcb); | |
752 | } | |
753 | ||
754 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) { | |
755 | zfcp_fsf_req_free(req); | |
756 | return ERR_PTR(-EIO); | |
757 | } | |
951f746f | 758 | |
c41f8cbd SS |
759 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) |
760 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; | |
1da177e4 | 761 | |
c41f8cbd | 762 | return req; |
1da177e4 LT |
763 | } |
764 | ||
c41f8cbd SS |
765 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *req) |
766 | { | |
767 | struct zfcp_adapter *adapter = req->adapter; | |
45316a86 | 768 | unsigned long flags; |
c41f8cbd SS |
769 | int idx; |
770 | ||
771 | /* put allocated FSF request into hash table */ | |
45316a86 | 772 | spin_lock_irqsave(&adapter->req_list_lock, flags); |
c41f8cbd SS |
773 | idx = zfcp_reqlist_hash(req->req_id); |
774 | list_add_tail(&req->list, &adapter->req_list[idx]); | |
45316a86 | 775 | spin_unlock_irqrestore(&adapter->req_list_lock, flags); |
c41f8cbd | 776 | |
3765138a | 777 | req->qdio_outb_usage = atomic_read(&adapter->req_q.count); |
c41f8cbd SS |
778 | req->issued = get_clock(); |
779 | if (zfcp_qdio_send(req)) { | |
c41f8cbd | 780 | del_timer(&req->timer); |
3765138a CS |
781 | spin_lock_irqsave(&adapter->req_list_lock, flags); |
782 | /* lookup request again, list might have changed */ | |
783 | if (zfcp_reqlist_find_safe(adapter, req)) | |
784 | zfcp_reqlist_remove(adapter, req); | |
785 | spin_unlock_irqrestore(&adapter->req_list_lock, flags); | |
5ffd51a5 | 786 | zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req); |
c41f8cbd SS |
787 | return -EIO; |
788 | } | |
789 | ||
790 | /* Don't increase for unsolicited status */ | |
791 | if (req->qtcb) | |
792 | adapter->fsf_req_seq_no++; | |
52bfb558 | 793 | adapter->req_no++; |
c41f8cbd SS |
794 | |
795 | return 0; | |
796 | } | |
797 | ||
798 | /** | |
799 | * zfcp_fsf_status_read - send status read request | |
800 | * @adapter: pointer to struct zfcp_adapter | |
801 | * @req_flags: request flags | |
802 | * Returns: 0 on success, ERROR otherwise | |
1da177e4 | 803 | */ |
c41f8cbd | 804 | int zfcp_fsf_status_read(struct zfcp_adapter *adapter) |
1da177e4 | 805 | { |
c41f8cbd SS |
806 | struct zfcp_fsf_req *req; |
807 | struct fsf_status_read_buffer *sr_buf; | |
44cc76f2 | 808 | struct qdio_buffer_element *sbale; |
c41f8cbd | 809 | int retval = -EIO; |
1da177e4 | 810 | |
0406289e | 811 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
812 | if (zfcp_fsf_req_sbal_get(adapter)) |
813 | goto out; | |
814 | ||
815 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS, | |
816 | ZFCP_REQ_NO_QTCB, | |
817 | adapter->pool.fsf_req_status_read); | |
025270f0 | 818 | if (IS_ERR(req)) { |
c41f8cbd SS |
819 | retval = PTR_ERR(req); |
820 | goto out; | |
1da177e4 LT |
821 | } |
822 | ||
c41f8cbd SS |
823 | sbale = zfcp_qdio_sbale_req(req); |
824 | sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS; | |
825 | sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; | |
826 | req->sbale_curr = 2; | |
827 | ||
828 | sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); | |
829 | if (!sr_buf) { | |
830 | retval = -ENOMEM; | |
831 | goto failed_buf; | |
832 | } | |
833 | memset(sr_buf, 0, sizeof(*sr_buf)); | |
834 | req->data = sr_buf; | |
835 | sbale = zfcp_qdio_sbale_curr(req); | |
836 | sbale->addr = (void *) sr_buf; | |
837 | sbale->length = sizeof(*sr_buf); | |
059c97d0 | 838 | |
c41f8cbd SS |
839 | retval = zfcp_fsf_req_send(req); |
840 | if (retval) | |
841 | goto failed_req_send; | |
1da177e4 | 842 | |
c41f8cbd SS |
843 | goto out; |
844 | ||
845 | failed_req_send: | |
846 | mempool_free(sr_buf, adapter->pool.data_status_read); | |
847 | failed_buf: | |
848 | zfcp_fsf_req_free(req); | |
849 | zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); | |
850 | out: | |
0406289e | 851 | spin_unlock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
852 | return retval; |
853 | } | |
854 | ||
855 | static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req) | |
856 | { | |
857 | struct zfcp_unit *unit = req->data; | |
858 | union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual; | |
859 | ||
860 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
861 | return; | |
862 | ||
863 | switch (req->qtcb->header.fsf_status) { | |
1da177e4 | 864 | case FSF_PORT_HANDLE_NOT_VALID: |
c41f8cbd | 865 | if (fsq->word[0] == fsq->word[1]) { |
5ffd51a5 SS |
866 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, |
867 | "fsafch1", req); | |
c41f8cbd | 868 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
869 | } |
870 | break; | |
1da177e4 | 871 | case FSF_LUN_HANDLE_NOT_VALID: |
c41f8cbd | 872 | if (fsq->word[0] == fsq->word[1]) { |
5ffd51a5 | 873 | zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req); |
c41f8cbd | 874 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
875 | } |
876 | break; | |
1da177e4 | 877 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: |
c41f8cbd | 878 | req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; |
1da177e4 | 879 | break; |
1da177e4 | 880 | case FSF_PORT_BOXED: |
5ffd51a5 | 881 | zfcp_erp_port_boxed(unit->port, "fsafch3", req); |
c41f8cbd SS |
882 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
883 | ZFCP_STATUS_FSFREQ_RETRY; | |
1da177e4 | 884 | break; |
1da177e4 | 885 | case FSF_LUN_BOXED: |
5ffd51a5 | 886 | zfcp_erp_unit_boxed(unit, "fsafch4", req); |
c41f8cbd SS |
887 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
888 | ZFCP_STATUS_FSFREQ_RETRY; | |
1da177e4 | 889 | break; |
1da177e4 | 890 | case FSF_ADAPTER_STATUS_AVAILABLE: |
c41f8cbd | 891 | switch (fsq->word[0]) { |
1da177e4 | 892 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
65a8d4e1 | 893 | zfcp_test_link(unit->port); |
1da177e4 | 894 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 895 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 896 | break; |
1da177e4 LT |
897 | } |
898 | break; | |
1da177e4 | 899 | case FSF_GOOD: |
c41f8cbd | 900 | req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; |
1da177e4 | 901 | break; |
1da177e4 | 902 | } |
1da177e4 LT |
903 | } |
904 | ||
905 | /** | |
c41f8cbd SS |
906 | * zfcp_fsf_abort_fcp_command - abort running SCSI command |
907 | * @old_req_id: unsigned long | |
c41f8cbd | 908 | * @unit: pointer to struct zfcp_unit |
c41f8cbd | 909 | * Returns: pointer to struct zfcp_fsf_req |
1da177e4 | 910 | */ |
1da177e4 | 911 | |
c41f8cbd | 912 | struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id, |
63caf367 | 913 | struct zfcp_unit *unit) |
1da177e4 | 914 | { |
44cc76f2 | 915 | struct qdio_buffer_element *sbale; |
c41f8cbd | 916 | struct zfcp_fsf_req *req = NULL; |
63caf367 | 917 | struct zfcp_adapter *adapter = unit->port->adapter; |
8a36e453 | 918 | |
92cab0d9 CS |
919 | spin_lock_bh(&adapter->req_q_lock); |
920 | if (zfcp_fsf_req_sbal_get(adapter)) | |
c41f8cbd SS |
921 | goto out; |
922 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND, | |
63caf367 | 923 | 0, adapter->pool.fsf_req_abort); |
633528c3 SS |
924 | if (IS_ERR(req)) { |
925 | req = NULL; | |
c41f8cbd | 926 | goto out; |
633528c3 | 927 | } |
2abbe866 | 928 | |
c41f8cbd SS |
929 | if (unlikely(!(atomic_read(&unit->status) & |
930 | ZFCP_STATUS_COMMON_UNBLOCKED))) | |
931 | goto out_error_free; | |
1da177e4 | 932 | |
c41f8cbd SS |
933 | sbale = zfcp_qdio_sbale_req(req); |
934 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
935 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1da177e4 | 936 | |
c41f8cbd SS |
937 | req->data = unit; |
938 | req->handler = zfcp_fsf_abort_fcp_command_handler; | |
939 | req->qtcb->header.lun_handle = unit->handle; | |
940 | req->qtcb->header.port_handle = unit->port->handle; | |
941 | req->qtcb->bottom.support.req_handle = (u64) old_req_id; | |
942 | ||
943 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); | |
944 | if (!zfcp_fsf_req_send(req)) | |
945 | goto out; | |
946 | ||
947 | out_error_free: | |
948 | zfcp_fsf_req_free(req); | |
949 | req = NULL; | |
950 | out: | |
92cab0d9 | 951 | spin_unlock_bh(&adapter->req_q_lock); |
c41f8cbd | 952 | return req; |
1da177e4 LT |
953 | } |
954 | ||
c41f8cbd | 955 | static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) |
1da177e4 | 956 | { |
c41f8cbd SS |
957 | struct zfcp_adapter *adapter = req->adapter; |
958 | struct zfcp_send_ct *send_ct = req->data; | |
c41f8cbd | 959 | struct fsf_qtcb_header *header = &req->qtcb->header; |
1da177e4 | 960 | |
c41f8cbd | 961 | send_ct->status = -EINVAL; |
1da177e4 | 962 | |
c41f8cbd | 963 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
1da177e4 LT |
964 | goto skip_fsfstatus; |
965 | ||
1da177e4 | 966 | switch (header->fsf_status) { |
1da177e4 | 967 | case FSF_GOOD: |
c41f8cbd SS |
968 | zfcp_san_dbf_event_ct_response(req); |
969 | send_ct->status = 0; | |
1da177e4 | 970 | break; |
1da177e4 | 971 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
c41f8cbd | 972 | zfcp_fsf_class_not_supp(req); |
1da177e4 | 973 | break; |
1da177e4 | 974 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
975 | switch (header->fsf_status_qual.word[0]){ |
976 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 | 977 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 978 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 979 | break; |
1da177e4 LT |
980 | } |
981 | break; | |
1da177e4 | 982 | case FSF_ACCESS_DENIED: |
1da177e4 | 983 | break; |
1da177e4 | 984 | case FSF_PORT_BOXED: |
c41f8cbd SS |
985 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
986 | ZFCP_STATUS_FSFREQ_RETRY; | |
1da177e4 | 987 | break; |
c41f8cbd | 988 | case FSF_PORT_HANDLE_NOT_VALID: |
5ffd51a5 | 989 | zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req); |
c41f8cbd | 990 | case FSF_GENERIC_COMMAND_REJECTED: |
1da177e4 | 991 | case FSF_PAYLOAD_SIZE_MISMATCH: |
1da177e4 | 992 | case FSF_REQUEST_SIZE_TOO_LARGE: |
1da177e4 | 993 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
1da177e4 | 994 | case FSF_SBAL_MISMATCH: |
c41f8cbd | 995 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
996 | break; |
997 | } | |
998 | ||
999 | skip_fsfstatus: | |
c41f8cbd | 1000 | if (send_ct->handler) |
1da177e4 | 1001 | send_ct->handler(send_ct->handler_data); |
c41f8cbd | 1002 | } |
1da177e4 | 1003 | |
39eb7e9a CS |
1004 | static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req, |
1005 | struct scatterlist *sg_req, | |
1006 | struct scatterlist *sg_resp, | |
1007 | int max_sbals) | |
c41f8cbd | 1008 | { |
39eb7e9a CS |
1009 | struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req); |
1010 | u32 feat = req->adapter->adapter_features; | |
c41f8cbd SS |
1011 | int bytes; |
1012 | ||
39eb7e9a CS |
1013 | if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) { |
1014 | if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE || | |
1015 | !sg_is_last(sg_req) || !sg_is_last(sg_resp)) | |
1016 | return -EOPNOTSUPP; | |
1017 | ||
1018 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ; | |
1019 | sbale[2].addr = sg_virt(sg_req); | |
1020 | sbale[2].length = sg_req->length; | |
1021 | sbale[3].addr = sg_virt(sg_resp); | |
1022 | sbale[3].length = sg_resp->length; | |
1023 | sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1024 | return 0; | |
1025 | } | |
1026 | ||
c41f8cbd SS |
1027 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, |
1028 | sg_req, max_sbals); | |
1029 | if (bytes <= 0) | |
1030 | return -ENOMEM; | |
1031 | req->qtcb->bottom.support.req_buf_length = bytes; | |
1032 | req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; | |
1033 | ||
1034 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, | |
1035 | sg_resp, max_sbals); | |
1036 | if (bytes <= 0) | |
1037 | return -ENOMEM; | |
1038 | req->qtcb->bottom.support.resp_buf_length = bytes; | |
1039 | ||
1040 | return 0; | |
1da177e4 LT |
1041 | } |
1042 | ||
1043 | /** | |
c41f8cbd SS |
1044 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) |
1045 | * @ct: pointer to struct zfcp_send_ct with data for request | |
1046 | * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req | |
1047 | * @erp_action: if non-null the Generic Service request sent within ERP | |
1da177e4 | 1048 | */ |
c41f8cbd SS |
1049 | int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool, |
1050 | struct zfcp_erp_action *erp_action) | |
1da177e4 | 1051 | { |
5ab944f9 SS |
1052 | struct zfcp_wka_port *wka_port = ct->wka_port; |
1053 | struct zfcp_adapter *adapter = wka_port->adapter; | |
c41f8cbd SS |
1054 | struct zfcp_fsf_req *req; |
1055 | int ret = -EIO; | |
1da177e4 | 1056 | |
0406289e | 1057 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
1058 | if (zfcp_fsf_req_sbal_get(adapter)) |
1059 | goto out; | |
1da177e4 | 1060 | |
c41f8cbd SS |
1061 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC, |
1062 | ZFCP_REQ_AUTO_CLEANUP, pool); | |
025270f0 | 1063 | if (IS_ERR(req)) { |
c41f8cbd SS |
1064 | ret = PTR_ERR(req); |
1065 | goto out; | |
3f0ca62a CS |
1066 | } |
1067 | ||
39eb7e9a CS |
1068 | ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp, |
1069 | FSF_MAX_SBALS_PER_REQ); | |
553448f6 | 1070 | if (ret) |
1da177e4 | 1071 | goto failed_send; |
1da177e4 | 1072 | |
c41f8cbd | 1073 | req->handler = zfcp_fsf_send_ct_handler; |
5ab944f9 | 1074 | req->qtcb->header.port_handle = wka_port->handle; |
c41f8cbd SS |
1075 | req->qtcb->bottom.support.service_class = FSF_CLASS_3; |
1076 | req->qtcb->bottom.support.timeout = ct->timeout; | |
1077 | req->data = ct; | |
1078 | ||
1079 | zfcp_san_dbf_event_ct_request(req); | |
1080 | ||
1081 | if (erp_action) { | |
1082 | erp_action->fsf_req = req; | |
1083 | req->erp_action = erp_action; | |
287ac01a | 1084 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd SS |
1085 | } else |
1086 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | |
1da177e4 | 1087 | |
c41f8cbd SS |
1088 | ret = zfcp_fsf_req_send(req); |
1089 | if (ret) | |
1090 | goto failed_send; | |
1da177e4 | 1091 | |
c41f8cbd | 1092 | goto out; |
1da177e4 | 1093 | |
c41f8cbd SS |
1094 | failed_send: |
1095 | zfcp_fsf_req_free(req); | |
1096 | if (erp_action) | |
1097 | erp_action->fsf_req = NULL; | |
1098 | out: | |
0406289e | 1099 | spin_unlock_bh(&adapter->req_q_lock); |
c41f8cbd | 1100 | return ret; |
1da177e4 LT |
1101 | } |
1102 | ||
c41f8cbd | 1103 | static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1104 | { |
c41f8cbd SS |
1105 | struct zfcp_send_els *send_els = req->data; |
1106 | struct zfcp_port *port = send_els->port; | |
1107 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
1da177e4 | 1108 | |
c41f8cbd | 1109 | send_els->status = -EINVAL; |
1da177e4 | 1110 | |
c41f8cbd | 1111 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
1da177e4 LT |
1112 | goto skip_fsfstatus; |
1113 | ||
1114 | switch (header->fsf_status) { | |
1da177e4 | 1115 | case FSF_GOOD: |
c41f8cbd SS |
1116 | zfcp_san_dbf_event_els_response(req); |
1117 | send_els->status = 0; | |
1da177e4 | 1118 | break; |
1da177e4 | 1119 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
c41f8cbd | 1120 | zfcp_fsf_class_not_supp(req); |
1da177e4 | 1121 | break; |
1da177e4 | 1122 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1123 | switch (header->fsf_status_qual.word[0]){ |
1124 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
64b29a13 AH |
1125 | if (port && (send_els->ls_code != ZFCP_LS_ADISC)) |
1126 | zfcp_test_link(port); | |
c41f8cbd | 1127 | /*fall through */ |
1da177e4 | 1128 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1da177e4 | 1129 | case FSF_SQ_RETRY_IF_POSSIBLE: |
c41f8cbd | 1130 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1131 | break; |
1da177e4 LT |
1132 | } |
1133 | break; | |
1da177e4 | 1134 | case FSF_ELS_COMMAND_REJECTED: |
1da177e4 | 1135 | case FSF_PAYLOAD_SIZE_MISMATCH: |
1da177e4 | 1136 | case FSF_REQUEST_SIZE_TOO_LARGE: |
1da177e4 | 1137 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
1da177e4 | 1138 | break; |
1da177e4 | 1139 | case FSF_ACCESS_DENIED: |
c41f8cbd | 1140 | zfcp_fsf_access_denied_port(req, port); |
1da177e4 | 1141 | break; |
c41f8cbd SS |
1142 | case FSF_SBAL_MISMATCH: |
1143 | /* should never occure, avoided in zfcp_fsf_send_els */ | |
1144 | /* fall through */ | |
1da177e4 | 1145 | default: |
c41f8cbd | 1146 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1147 | break; |
1148 | } | |
1da177e4 | 1149 | skip_fsfstatus: |
aa551daf | 1150 | if (send_els->handler) |
1da177e4 | 1151 | send_els->handler(send_els->handler_data); |
c41f8cbd | 1152 | } |
1da177e4 | 1153 | |
c41f8cbd SS |
1154 | /** |
1155 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) | |
1156 | * @els: pointer to struct zfcp_send_els with data for the command | |
1157 | */ | |
1158 | int zfcp_fsf_send_els(struct zfcp_send_els *els) | |
1159 | { | |
1160 | struct zfcp_fsf_req *req; | |
1161 | struct zfcp_adapter *adapter = els->adapter; | |
1162 | struct fsf_qtcb_bottom_support *bottom; | |
1163 | int ret = -EIO; | |
1164 | ||
8fdf30d5 CS |
1165 | spin_lock_bh(&adapter->req_q_lock); |
1166 | if (zfcp_fsf_req_sbal_get(adapter)) | |
c41f8cbd SS |
1167 | goto out; |
1168 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, | |
1169 | ZFCP_REQ_AUTO_CLEANUP, NULL); | |
025270f0 | 1170 | if (IS_ERR(req)) { |
c41f8cbd SS |
1171 | ret = PTR_ERR(req); |
1172 | goto out; | |
1173 | } | |
1174 | ||
39eb7e9a | 1175 | ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2); |
44cc76f2 | 1176 | |
c41f8cbd SS |
1177 | if (ret) |
1178 | goto failed_send; | |
1179 | ||
1180 | bottom = &req->qtcb->bottom.support; | |
1181 | req->handler = zfcp_fsf_send_els_handler; | |
1182 | bottom->d_id = els->d_id; | |
1183 | bottom->service_class = FSF_CLASS_3; | |
1184 | bottom->timeout = 2 * R_A_TOV; | |
1185 | req->data = els; | |
1186 | ||
1187 | zfcp_san_dbf_event_els_request(req); | |
1188 | ||
1189 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | |
1190 | ret = zfcp_fsf_req_send(req); | |
1191 | if (ret) | |
1192 | goto failed_send; | |
1193 | ||
1194 | goto out; | |
1195 | ||
1196 | failed_send: | |
1197 | zfcp_fsf_req_free(req); | |
1198 | out: | |
8fdf30d5 | 1199 | spin_unlock_bh(&adapter->req_q_lock); |
c41f8cbd | 1200 | return ret; |
1da177e4 LT |
1201 | } |
1202 | ||
c41f8cbd | 1203 | int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) |
1da177e4 | 1204 | { |
44cc76f2 | 1205 | struct qdio_buffer_element *sbale; |
c41f8cbd | 1206 | struct zfcp_fsf_req *req; |
52ef11a7 | 1207 | struct zfcp_adapter *adapter = erp_action->adapter; |
c41f8cbd SS |
1208 | int retval = -EIO; |
1209 | ||
0406289e | 1210 | spin_lock_bh(&adapter->req_q_lock); |
92cab0d9 | 1211 | if (zfcp_fsf_req_sbal_get(adapter)) |
c41f8cbd SS |
1212 | goto out; |
1213 | req = zfcp_fsf_req_create(adapter, | |
1214 | FSF_QTCB_EXCHANGE_CONFIG_DATA, | |
1215 | ZFCP_REQ_AUTO_CLEANUP, | |
1216 | adapter->pool.fsf_req_erp); | |
025270f0 | 1217 | if (IS_ERR(req)) { |
c41f8cbd SS |
1218 | retval = PTR_ERR(req); |
1219 | goto out; | |
1da177e4 LT |
1220 | } |
1221 | ||
c41f8cbd | 1222 | sbale = zfcp_qdio_sbale_req(req); |
52ef11a7 SS |
1223 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1224 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1da177e4 | 1225 | |
c41f8cbd | 1226 | req->qtcb->bottom.config.feature_selection = |
aef4a983 MS |
1227 | FSF_FEATURE_CFDC | |
1228 | FSF_FEATURE_LUN_SHARING | | |
9eb69aff | 1229 | FSF_FEATURE_NOTIFICATION_LOST | |
aef4a983 | 1230 | FSF_FEATURE_UPDATE_ALERT; |
c41f8cbd SS |
1231 | req->erp_action = erp_action; |
1232 | req->handler = zfcp_fsf_exchange_config_data_handler; | |
1233 | erp_action->fsf_req = req; | |
1da177e4 | 1234 | |
287ac01a | 1235 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1236 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1237 | if (retval) { |
c41f8cbd | 1238 | zfcp_fsf_req_free(req); |
1da177e4 | 1239 | erp_action->fsf_req = NULL; |
1da177e4 | 1240 | } |
c41f8cbd | 1241 | out: |
0406289e | 1242 | spin_unlock_bh(&adapter->req_q_lock); |
52ef11a7 SS |
1243 | return retval; |
1244 | } | |
1da177e4 | 1245 | |
c41f8cbd SS |
1246 | int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter, |
1247 | struct fsf_qtcb_bottom_config *data) | |
52ef11a7 | 1248 | { |
44cc76f2 | 1249 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
1250 | struct zfcp_fsf_req *req = NULL; |
1251 | int retval = -EIO; | |
1252 | ||
0406289e | 1253 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
1254 | if (zfcp_fsf_req_sbal_get(adapter)) |
1255 | goto out; | |
1256 | ||
1257 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA, | |
1258 | 0, NULL); | |
025270f0 | 1259 | if (IS_ERR(req)) { |
c41f8cbd SS |
1260 | retval = PTR_ERR(req); |
1261 | goto out; | |
52ef11a7 SS |
1262 | } |
1263 | ||
c41f8cbd | 1264 | sbale = zfcp_qdio_sbale_req(req); |
52ef11a7 SS |
1265 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1266 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
c41f8cbd | 1267 | req->handler = zfcp_fsf_exchange_config_data_handler; |
52ef11a7 | 1268 | |
c41f8cbd | 1269 | req->qtcb->bottom.config.feature_selection = |
52ef11a7 SS |
1270 | FSF_FEATURE_CFDC | |
1271 | FSF_FEATURE_LUN_SHARING | | |
1272 | FSF_FEATURE_NOTIFICATION_LOST | | |
1273 | FSF_FEATURE_UPDATE_ALERT; | |
1274 | ||
1275 | if (data) | |
c41f8cbd | 1276 | req->data = data; |
52ef11a7 | 1277 | |
c41f8cbd SS |
1278 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
1279 | retval = zfcp_fsf_req_send(req); | |
1280 | out: | |
0406289e | 1281 | spin_unlock_bh(&adapter->req_q_lock); |
553448f6 | 1282 | if (!retval) |
c41f8cbd SS |
1283 | wait_event(req->completion_wq, |
1284 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | |
52ef11a7 | 1285 | |
c41f8cbd | 1286 | zfcp_fsf_req_free(req); |
52ef11a7 | 1287 | |
1da177e4 LT |
1288 | return retval; |
1289 | } | |
1290 | ||
1da177e4 LT |
1291 | /** |
1292 | * zfcp_fsf_exchange_port_data - request information about local port | |
aef4a983 | 1293 | * @erp_action: ERP action for the adapter for which port data is requested |
c41f8cbd | 1294 | * Returns: 0 on success, error otherwise |
1da177e4 | 1295 | */ |
c41f8cbd | 1296 | int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) |
1da177e4 | 1297 | { |
44cc76f2 | 1298 | struct qdio_buffer_element *sbale; |
c41f8cbd | 1299 | struct zfcp_fsf_req *req; |
52ef11a7 | 1300 | struct zfcp_adapter *adapter = erp_action->adapter; |
c41f8cbd | 1301 | int retval = -EIO; |
1da177e4 | 1302 | |
553448f6 | 1303 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
52ef11a7 | 1304 | return -EOPNOTSUPP; |
1da177e4 | 1305 | |
0406289e | 1306 | spin_lock_bh(&adapter->req_q_lock); |
92cab0d9 | 1307 | if (zfcp_fsf_req_sbal_get(adapter)) |
c41f8cbd SS |
1308 | goto out; |
1309 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, | |
1310 | ZFCP_REQ_AUTO_CLEANUP, | |
1311 | adapter->pool.fsf_req_erp); | |
025270f0 | 1312 | if (IS_ERR(req)) { |
c41f8cbd SS |
1313 | retval = PTR_ERR(req); |
1314 | goto out; | |
aef4a983 MS |
1315 | } |
1316 | ||
c41f8cbd | 1317 | sbale = zfcp_qdio_sbale_req(req); |
52ef11a7 SS |
1318 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1319 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1da177e4 | 1320 | |
c41f8cbd SS |
1321 | req->handler = zfcp_fsf_exchange_port_data_handler; |
1322 | req->erp_action = erp_action; | |
1323 | erp_action->fsf_req = req; | |
52ef11a7 | 1324 | |
287ac01a | 1325 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1326 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1327 | if (retval) { |
c41f8cbd | 1328 | zfcp_fsf_req_free(req); |
52ef11a7 SS |
1329 | erp_action->fsf_req = NULL; |
1330 | } | |
c41f8cbd | 1331 | out: |
0406289e | 1332 | spin_unlock_bh(&adapter->req_q_lock); |
52ef11a7 SS |
1333 | return retval; |
1334 | } | |
1335 | ||
52ef11a7 SS |
1336 | /** |
1337 | * zfcp_fsf_exchange_port_data_sync - request information about local port | |
c41f8cbd SS |
1338 | * @adapter: pointer to struct zfcp_adapter |
1339 | * @data: pointer to struct fsf_qtcb_bottom_port | |
1340 | * Returns: 0 on success, error otherwise | |
52ef11a7 | 1341 | */ |
c41f8cbd SS |
1342 | int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter, |
1343 | struct fsf_qtcb_bottom_port *data) | |
52ef11a7 | 1344 | { |
44cc76f2 | 1345 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
1346 | struct zfcp_fsf_req *req = NULL; |
1347 | int retval = -EIO; | |
52ef11a7 | 1348 | |
553448f6 | 1349 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
52ef11a7 | 1350 | return -EOPNOTSUPP; |
52ef11a7 | 1351 | |
0406289e | 1352 | spin_lock_bh(&adapter->req_q_lock); |
92cab0d9 | 1353 | if (zfcp_fsf_req_sbal_get(adapter)) |
c41f8cbd SS |
1354 | goto out; |
1355 | ||
1356 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0, | |
1357 | NULL); | |
025270f0 | 1358 | if (IS_ERR(req)) { |
c41f8cbd SS |
1359 | retval = PTR_ERR(req); |
1360 | goto out; | |
1da177e4 LT |
1361 | } |
1362 | ||
52ef11a7 | 1363 | if (data) |
c41f8cbd | 1364 | req->data = data; |
52ef11a7 | 1365 | |
c41f8cbd | 1366 | sbale = zfcp_qdio_sbale_req(req); |
52ef11a7 SS |
1367 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1368 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1369 | ||
c41f8cbd SS |
1370 | req->handler = zfcp_fsf_exchange_port_data_handler; |
1371 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | |
1372 | retval = zfcp_fsf_req_send(req); | |
1373 | out: | |
0406289e | 1374 | spin_unlock_bh(&adapter->req_q_lock); |
553448f6 | 1375 | if (!retval) |
c41f8cbd SS |
1376 | wait_event(req->completion_wq, |
1377 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | |
1378 | zfcp_fsf_req_free(req); | |
1da177e4 | 1379 | |
1da177e4 LT |
1380 | return retval; |
1381 | } | |
1382 | ||
c41f8cbd | 1383 | static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1384 | { |
c41f8cbd SS |
1385 | struct zfcp_port *port = req->data; |
1386 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
1da177e4 | 1387 | struct fsf_plogi *plogi; |
1da177e4 | 1388 | |
c41f8cbd | 1389 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
44cc76f2 | 1390 | return; |
1da177e4 | 1391 | |
1da177e4 | 1392 | switch (header->fsf_status) { |
1da177e4 | 1393 | case FSF_PORT_ALREADY_OPEN: |
1da177e4 | 1394 | break; |
1da177e4 | 1395 | case FSF_ACCESS_DENIED: |
c41f8cbd | 1396 | zfcp_fsf_access_denied_port(req, port); |
1da177e4 | 1397 | break; |
1da177e4 | 1398 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
c41f8cbd | 1399 | dev_warn(&req->adapter->ccw_device->dev, |
ff3b24fa | 1400 | "Not enough FCP adapter resources to open " |
7ba58c9c SS |
1401 | "remote port 0x%016Lx\n", |
1402 | (unsigned long long)port->wwpn); | |
5ffd51a5 | 1403 | zfcp_erp_port_failed(port, "fsoph_1", req); |
c41f8cbd | 1404 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1405 | break; |
1da177e4 | 1406 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1407 | switch (header->fsf_status_qual.word[0]) { |
1408 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 | 1409 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1da177e4 | 1410 | case FSF_SQ_NO_RETRY_POSSIBLE: |
c41f8cbd | 1411 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1412 | break; |
1413 | } | |
1414 | break; | |
1da177e4 | 1415 | case FSF_GOOD: |
1da177e4 | 1416 | port->handle = header->port_handle; |
1da177e4 LT |
1417 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | |
1418 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | |
d736a27b AH |
1419 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
1420 | ZFCP_STATUS_COMMON_ACCESS_BOXED, | |
1421 | &port->status); | |
1da177e4 LT |
1422 | /* check whether D_ID has changed during open */ |
1423 | /* | |
1424 | * FIXME: This check is not airtight, as the FCP channel does | |
1425 | * not monitor closures of target port connections caused on | |
1426 | * the remote side. Thus, they might miss out on invalidating | |
1427 | * locally cached WWPNs (and other N_Port parameters) of gone | |
1428 | * target ports. So, our heroic attempt to make things safe | |
1429 | * could be undermined by 'open port' response data tagged with | |
1430 | * obsolete WWPNs. Another reason to monitor potential | |
1431 | * connection closures ourself at least (by interpreting | |
1432 | * incoming ELS' and unsolicited status). It just crosses my | |
1433 | * mind that one should be able to cross-check by means of | |
1434 | * another GID_PN straight after a port has been opened. | |
1435 | * Alternately, an ADISC/PDISC ELS should suffice, as well. | |
1436 | */ | |
c41f8cbd | 1437 | plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els; |
39eb7e9a CS |
1438 | if (req->qtcb->bottom.support.els1_length >= |
1439 | FSF_PLOGI_MIN_LEN) { | |
c41f8cbd | 1440 | if (plogi->serv_param.wwpn != port->wwpn) |
b98478d7 | 1441 | port->d_id = 0; |
c41f8cbd SS |
1442 | else { |
1443 | port->wwnn = plogi->serv_param.wwnn; | |
1444 | zfcp_fc_plogi_evaluate(port, plogi); | |
1da177e4 LT |
1445 | } |
1446 | } | |
1447 | break; | |
1da177e4 | 1448 | case FSF_UNKNOWN_OP_SUBTYPE: |
c41f8cbd | 1449 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1450 | break; |
1451 | } | |
1da177e4 LT |
1452 | } |
1453 | ||
c41f8cbd SS |
1454 | /** |
1455 | * zfcp_fsf_open_port - create and send open port request | |
1456 | * @erp_action: pointer to struct zfcp_erp_action | |
1457 | * Returns: 0 on success, error otherwise | |
1da177e4 | 1458 | */ |
c41f8cbd | 1459 | int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
1da177e4 | 1460 | { |
44cc76f2 | 1461 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
1462 | struct zfcp_adapter *adapter = erp_action->adapter; |
1463 | struct zfcp_fsf_req *req; | |
1464 | int retval = -EIO; | |
1465 | ||
0406289e | 1466 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
1467 | if (zfcp_fsf_req_sbal_get(adapter)) |
1468 | goto out; | |
1469 | ||
1470 | req = zfcp_fsf_req_create(adapter, | |
1471 | FSF_QTCB_OPEN_PORT_WITH_DID, | |
1472 | ZFCP_REQ_AUTO_CLEANUP, | |
1473 | adapter->pool.fsf_req_erp); | |
025270f0 | 1474 | if (IS_ERR(req)) { |
c41f8cbd | 1475 | retval = PTR_ERR(req); |
1da177e4 | 1476 | goto out; |
c41f8cbd | 1477 | } |
1da177e4 | 1478 | |
c41f8cbd | 1479 | sbale = zfcp_qdio_sbale_req(req); |
1da177e4 LT |
1480 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1481 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1482 | ||
c41f8cbd SS |
1483 | req->handler = zfcp_fsf_open_port_handler; |
1484 | req->qtcb->bottom.support.d_id = erp_action->port->d_id; | |
1485 | req->data = erp_action->port; | |
1486 | req->erp_action = erp_action; | |
1487 | erp_action->fsf_req = req; | |
c41f8cbd | 1488 | |
287ac01a | 1489 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1490 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1491 | if (retval) { |
c41f8cbd | 1492 | zfcp_fsf_req_free(req); |
1da177e4 | 1493 | erp_action->fsf_req = NULL; |
1da177e4 | 1494 | } |
c41f8cbd | 1495 | out: |
0406289e | 1496 | spin_unlock_bh(&adapter->req_q_lock); |
1da177e4 LT |
1497 | return retval; |
1498 | } | |
1499 | ||
c41f8cbd | 1500 | static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1501 | { |
c41f8cbd | 1502 | struct zfcp_port *port = req->data; |
1da177e4 | 1503 | |
c41f8cbd | 1504 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
44cc76f2 | 1505 | return; |
1da177e4 | 1506 | |
c41f8cbd | 1507 | switch (req->qtcb->header.fsf_status) { |
1da177e4 | 1508 | case FSF_PORT_HANDLE_NOT_VALID: |
5ffd51a5 | 1509 | zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req); |
c41f8cbd | 1510 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1511 | break; |
1da177e4 | 1512 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 | 1513 | break; |
1da177e4 | 1514 | case FSF_GOOD: |
5ffd51a5 | 1515 | zfcp_erp_modify_port_status(port, "fscph_2", req, |
1da177e4 LT |
1516 | ZFCP_STATUS_COMMON_OPEN, |
1517 | ZFCP_CLEAR); | |
1da177e4 | 1518 | break; |
1da177e4 | 1519 | } |
1da177e4 LT |
1520 | } |
1521 | ||
c41f8cbd SS |
1522 | /** |
1523 | * zfcp_fsf_close_port - create and send close port request | |
1524 | * @erp_action: pointer to struct zfcp_erp_action | |
1525 | * Returns: 0 on success, error otherwise | |
1da177e4 | 1526 | */ |
c41f8cbd | 1527 | int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
1da177e4 | 1528 | { |
44cc76f2 | 1529 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
1530 | struct zfcp_adapter *adapter = erp_action->adapter; |
1531 | struct zfcp_fsf_req *req; | |
1532 | int retval = -EIO; | |
1533 | ||
0406289e | 1534 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
1535 | if (zfcp_fsf_req_sbal_get(adapter)) |
1536 | goto out; | |
1537 | ||
1538 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT, | |
1539 | ZFCP_REQ_AUTO_CLEANUP, | |
1540 | adapter->pool.fsf_req_erp); | |
025270f0 | 1541 | if (IS_ERR(req)) { |
c41f8cbd | 1542 | retval = PTR_ERR(req); |
1da177e4 | 1543 | goto out; |
c41f8cbd | 1544 | } |
1da177e4 | 1545 | |
c41f8cbd | 1546 | sbale = zfcp_qdio_sbale_req(req); |
1da177e4 LT |
1547 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1548 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1549 | ||
c41f8cbd SS |
1550 | req->handler = zfcp_fsf_close_port_handler; |
1551 | req->data = erp_action->port; | |
1552 | req->erp_action = erp_action; | |
1553 | req->qtcb->header.port_handle = erp_action->port->handle; | |
1554 | erp_action->fsf_req = req; | |
c41f8cbd | 1555 | |
287ac01a | 1556 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1557 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1558 | if (retval) { |
c41f8cbd | 1559 | zfcp_fsf_req_free(req); |
1da177e4 | 1560 | erp_action->fsf_req = NULL; |
1da177e4 | 1561 | } |
c41f8cbd | 1562 | out: |
0406289e | 1563 | spin_unlock_bh(&adapter->req_q_lock); |
1da177e4 LT |
1564 | return retval; |
1565 | } | |
1566 | ||
5ab944f9 SS |
1567 | static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req) |
1568 | { | |
1569 | struct zfcp_wka_port *wka_port = req->data; | |
1570 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
1571 | ||
1572 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
1573 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; | |
1574 | goto out; | |
1575 | } | |
1576 | ||
1577 | switch (header->fsf_status) { | |
1578 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: | |
1579 | dev_warn(&req->adapter->ccw_device->dev, | |
1580 | "Opening WKA port 0x%x failed\n", wka_port->d_id); | |
1581 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1582 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1583 | case FSF_ACCESS_DENIED: | |
1584 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; | |
1585 | break; | |
1586 | case FSF_PORT_ALREADY_OPEN: | |
1c1cba17 | 1587 | break; |
5ab944f9 SS |
1588 | case FSF_GOOD: |
1589 | wka_port->handle = header->port_handle; | |
1590 | wka_port->status = ZFCP_WKA_PORT_ONLINE; | |
1591 | } | |
1592 | out: | |
1593 | wake_up(&wka_port->completion_wq); | |
1594 | } | |
1595 | ||
1596 | /** | |
1597 | * zfcp_fsf_open_wka_port - create and send open wka-port request | |
1598 | * @wka_port: pointer to struct zfcp_wka_port | |
1599 | * Returns: 0 on success, error otherwise | |
1600 | */ | |
1601 | int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port) | |
1602 | { | |
1603 | struct qdio_buffer_element *sbale; | |
1604 | struct zfcp_adapter *adapter = wka_port->adapter; | |
1605 | struct zfcp_fsf_req *req; | |
1606 | int retval = -EIO; | |
1607 | ||
0406289e | 1608 | spin_lock_bh(&adapter->req_q_lock); |
5ab944f9 SS |
1609 | if (zfcp_fsf_req_sbal_get(adapter)) |
1610 | goto out; | |
1611 | ||
1612 | req = zfcp_fsf_req_create(adapter, | |
1613 | FSF_QTCB_OPEN_PORT_WITH_DID, | |
1614 | ZFCP_REQ_AUTO_CLEANUP, | |
1615 | adapter->pool.fsf_req_erp); | |
1616 | if (unlikely(IS_ERR(req))) { | |
1617 | retval = PTR_ERR(req); | |
1618 | goto out; | |
1619 | } | |
1620 | ||
1621 | sbale = zfcp_qdio_sbale_req(req); | |
1622 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
1623 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1624 | ||
1625 | req->handler = zfcp_fsf_open_wka_port_handler; | |
1626 | req->qtcb->bottom.support.d_id = wka_port->d_id; | |
1627 | req->data = wka_port; | |
1628 | ||
1629 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | |
1630 | retval = zfcp_fsf_req_send(req); | |
1631 | if (retval) | |
1632 | zfcp_fsf_req_free(req); | |
1633 | out: | |
0406289e | 1634 | spin_unlock_bh(&adapter->req_q_lock); |
5ab944f9 SS |
1635 | return retval; |
1636 | } | |
1637 | ||
1638 | static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req) | |
1639 | { | |
1640 | struct zfcp_wka_port *wka_port = req->data; | |
1641 | ||
1642 | if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) { | |
1643 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
5ffd51a5 | 1644 | zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req); |
5ab944f9 SS |
1645 | } |
1646 | ||
1647 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; | |
1648 | wake_up(&wka_port->completion_wq); | |
1649 | } | |
1650 | ||
1651 | /** | |
1652 | * zfcp_fsf_close_wka_port - create and send close wka port request | |
1653 | * @erp_action: pointer to struct zfcp_erp_action | |
1654 | * Returns: 0 on success, error otherwise | |
1655 | */ | |
1656 | int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port) | |
1657 | { | |
1658 | struct qdio_buffer_element *sbale; | |
1659 | struct zfcp_adapter *adapter = wka_port->adapter; | |
1660 | struct zfcp_fsf_req *req; | |
1661 | int retval = -EIO; | |
1662 | ||
0406289e | 1663 | spin_lock_bh(&adapter->req_q_lock); |
5ab944f9 SS |
1664 | if (zfcp_fsf_req_sbal_get(adapter)) |
1665 | goto out; | |
1666 | ||
1667 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT, | |
1668 | ZFCP_REQ_AUTO_CLEANUP, | |
1669 | adapter->pool.fsf_req_erp); | |
1670 | if (unlikely(IS_ERR(req))) { | |
1671 | retval = PTR_ERR(req); | |
1672 | goto out; | |
1673 | } | |
1674 | ||
1675 | sbale = zfcp_qdio_sbale_req(req); | |
1676 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
1677 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1678 | ||
1679 | req->handler = zfcp_fsf_close_wka_port_handler; | |
1680 | req->data = wka_port; | |
1681 | req->qtcb->header.port_handle = wka_port->handle; | |
1682 | ||
1683 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | |
1684 | retval = zfcp_fsf_req_send(req); | |
1685 | if (retval) | |
1686 | zfcp_fsf_req_free(req); | |
1687 | out: | |
0406289e | 1688 | spin_unlock_bh(&adapter->req_q_lock); |
5ab944f9 SS |
1689 | return retval; |
1690 | } | |
1691 | ||
c41f8cbd | 1692 | static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1693 | { |
c41f8cbd SS |
1694 | struct zfcp_port *port = req->data; |
1695 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
1da177e4 | 1696 | struct zfcp_unit *unit; |
1da177e4 | 1697 | |
c41f8cbd | 1698 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
a5b11dda | 1699 | return; |
1da177e4 | 1700 | |
1da177e4 | 1701 | switch (header->fsf_status) { |
1da177e4 | 1702 | case FSF_PORT_HANDLE_NOT_VALID: |
5ffd51a5 | 1703 | zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req); |
c41f8cbd | 1704 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1705 | break; |
1da177e4 | 1706 | case FSF_ACCESS_DENIED: |
c41f8cbd | 1707 | zfcp_fsf_access_denied_port(req, port); |
1da177e4 | 1708 | break; |
1da177e4 | 1709 | case FSF_PORT_BOXED: |
5ffd51a5 | 1710 | zfcp_erp_port_boxed(port, "fscpph2", req); |
c41f8cbd SS |
1711 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
1712 | ZFCP_STATUS_FSFREQ_RETRY; | |
5c815d15 CS |
1713 | /* can't use generic zfcp_erp_modify_port_status because |
1714 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ | |
1715 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | |
1716 | list_for_each_entry(unit, &port->unit_list_head, list) | |
1717 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, | |
1718 | &unit->status); | |
1da177e4 | 1719 | break; |
1da177e4 | 1720 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1721 | switch (header->fsf_status_qual.word[0]) { |
1722 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
c41f8cbd | 1723 | /* fall through */ |
1da177e4 | 1724 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 1725 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1726 | break; |
1da177e4 LT |
1727 | } |
1728 | break; | |
1da177e4 | 1729 | case FSF_GOOD: |
1da177e4 LT |
1730 | /* can't use generic zfcp_erp_modify_port_status because |
1731 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port | |
1732 | */ | |
1733 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | |
1734 | list_for_each_entry(unit, &port->unit_list_head, list) | |
c41f8cbd SS |
1735 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
1736 | &unit->status); | |
1da177e4 | 1737 | break; |
1da177e4 | 1738 | } |
1da177e4 LT |
1739 | } |
1740 | ||
c41f8cbd SS |
1741 | /** |
1742 | * zfcp_fsf_close_physical_port - close physical port | |
1743 | * @erp_action: pointer to struct zfcp_erp_action | |
1744 | * Returns: 0 on success | |
1da177e4 | 1745 | */ |
c41f8cbd | 1746 | int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
1da177e4 | 1747 | { |
44cc76f2 | 1748 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
1749 | struct zfcp_adapter *adapter = erp_action->adapter; |
1750 | struct zfcp_fsf_req *req; | |
1751 | int retval = -EIO; | |
1752 | ||
0406289e | 1753 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd | 1754 | if (zfcp_fsf_req_sbal_get(adapter)) |
1da177e4 | 1755 | goto out; |
1da177e4 | 1756 | |
c41f8cbd SS |
1757 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT, |
1758 | ZFCP_REQ_AUTO_CLEANUP, | |
1759 | adapter->pool.fsf_req_erp); | |
025270f0 | 1760 | if (IS_ERR(req)) { |
c41f8cbd SS |
1761 | retval = PTR_ERR(req); |
1762 | goto out; | |
1763 | } | |
1da177e4 | 1764 | |
c41f8cbd SS |
1765 | sbale = zfcp_qdio_sbale_req(req); |
1766 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
1767 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1da177e4 | 1768 | |
c41f8cbd SS |
1769 | req->data = erp_action->port; |
1770 | req->qtcb->header.port_handle = erp_action->port->handle; | |
1771 | req->erp_action = erp_action; | |
1772 | req->handler = zfcp_fsf_close_physical_port_handler; | |
1773 | erp_action->fsf_req = req; | |
c41f8cbd | 1774 | |
287ac01a | 1775 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1776 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1777 | if (retval) { |
c41f8cbd | 1778 | zfcp_fsf_req_free(req); |
1da177e4 | 1779 | erp_action->fsf_req = NULL; |
1da177e4 | 1780 | } |
c41f8cbd | 1781 | out: |
0406289e | 1782 | spin_unlock_bh(&adapter->req_q_lock); |
1da177e4 LT |
1783 | return retval; |
1784 | } | |
1785 | ||
c41f8cbd | 1786 | static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1787 | { |
c41f8cbd SS |
1788 | struct zfcp_adapter *adapter = req->adapter; |
1789 | struct zfcp_unit *unit = req->data; | |
1790 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
1791 | struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support; | |
1792 | struct fsf_queue_designator *queue_designator = | |
1793 | &header->fsf_status_qual.fsf_queue_designator; | |
aef4a983 | 1794 | int exclusive, readwrite; |
1da177e4 | 1795 | |
c41f8cbd | 1796 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
44cc76f2 | 1797 | return; |
1da177e4 | 1798 | |
1da177e4 | 1799 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
b64ddf96 | 1800 | ZFCP_STATUS_COMMON_ACCESS_BOXED | |
1da177e4 LT |
1801 | ZFCP_STATUS_UNIT_SHARED | |
1802 | ZFCP_STATUS_UNIT_READONLY, | |
1803 | &unit->status); | |
1804 | ||
1da177e4 LT |
1805 | switch (header->fsf_status) { |
1806 | ||
1807 | case FSF_PORT_HANDLE_NOT_VALID: | |
5ffd51a5 | 1808 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req); |
c41f8cbd | 1809 | /* fall through */ |
1da177e4 | 1810 | case FSF_LUN_ALREADY_OPEN: |
1da177e4 | 1811 | break; |
1da177e4 | 1812 | case FSF_ACCESS_DENIED: |
c41f8cbd | 1813 | zfcp_fsf_access_denied_unit(req, unit); |
1da177e4 | 1814 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
553448f6 | 1815 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
1da177e4 | 1816 | break; |
1da177e4 | 1817 | case FSF_PORT_BOXED: |
5ffd51a5 | 1818 | zfcp_erp_port_boxed(unit->port, "fsouh_2", req); |
c41f8cbd SS |
1819 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
1820 | ZFCP_STATUS_FSFREQ_RETRY; | |
1da177e4 | 1821 | break; |
1da177e4 | 1822 | case FSF_LUN_SHARING_VIOLATION: |
c41f8cbd | 1823 | if (header->fsf_status_qual.word[0]) |
553448f6 | 1824 | dev_warn(&adapter->ccw_device->dev, |
ff3b24fa CS |
1825 | "LUN 0x%Lx on port 0x%Lx is already in " |
1826 | "use by CSS%d, MIF Image ID %x\n", | |
7ba58c9c SS |
1827 | (unsigned long long)unit->fcp_lun, |
1828 | (unsigned long long)unit->port->wwpn, | |
ff3b24fa CS |
1829 | queue_designator->cssid, |
1830 | queue_designator->hla); | |
c41f8cbd | 1831 | else |
553448f6 CS |
1832 | zfcp_act_eval_err(adapter, |
1833 | header->fsf_status_qual.word[2]); | |
5ffd51a5 | 1834 | zfcp_erp_unit_access_denied(unit, "fsouh_3", req); |
1da177e4 LT |
1835 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
1836 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); | |
c41f8cbd | 1837 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1838 | break; |
1da177e4 | 1839 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
c41f8cbd | 1840 | dev_warn(&adapter->ccw_device->dev, |
ff3b24fa CS |
1841 | "No handle is available for LUN " |
1842 | "0x%016Lx on port 0x%016Lx\n", | |
7ba58c9c SS |
1843 | (unsigned long long)unit->fcp_lun, |
1844 | (unsigned long long)unit->port->wwpn); | |
5ffd51a5 | 1845 | zfcp_erp_unit_failed(unit, "fsouh_4", req); |
c41f8cbd SS |
1846 | /* fall through */ |
1847 | case FSF_INVALID_COMMAND_OPTION: | |
1848 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1da177e4 | 1849 | break; |
1da177e4 | 1850 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1da177e4 LT |
1851 | switch (header->fsf_status_qual.word[0]) { |
1852 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
65a8d4e1 | 1853 | zfcp_test_link(unit->port); |
c41f8cbd | 1854 | /* fall through */ |
1da177e4 | 1855 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 1856 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1857 | break; |
1da177e4 LT |
1858 | } |
1859 | break; | |
1860 | ||
1da177e4 | 1861 | case FSF_GOOD: |
1da177e4 | 1862 | unit->handle = header->lun_handle; |
1da177e4 | 1863 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
aef4a983 MS |
1864 | |
1865 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && | |
1866 | (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) && | |
1867 | (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) { | |
1868 | exclusive = (bottom->lun_access_info & | |
1869 | FSF_UNIT_ACCESS_EXCLUSIVE); | |
1870 | readwrite = (bottom->lun_access_info & | |
1871 | FSF_UNIT_ACCESS_OUTBOUND_TRANSFER); | |
1872 | ||
1da177e4 LT |
1873 | if (!exclusive) |
1874 | atomic_set_mask(ZFCP_STATUS_UNIT_SHARED, | |
1875 | &unit->status); | |
1876 | ||
1877 | if (!readwrite) { | |
1878 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, | |
1879 | &unit->status); | |
c41f8cbd | 1880 | dev_info(&adapter->ccw_device->dev, |
ff3b24fa CS |
1881 | "SCSI device at LUN 0x%016Lx on port " |
1882 | "0x%016Lx opened read-only\n", | |
7ba58c9c SS |
1883 | (unsigned long long)unit->fcp_lun, |
1884 | (unsigned long long)unit->port->wwpn); | |
1da177e4 LT |
1885 | } |
1886 | ||
1887 | if (exclusive && !readwrite) { | |
c41f8cbd | 1888 | dev_err(&adapter->ccw_device->dev, |
ff3b24fa CS |
1889 | "Exclusive read-only access not " |
1890 | "supported (unit 0x%016Lx, " | |
1891 | "port 0x%016Lx)\n", | |
7ba58c9c SS |
1892 | (unsigned long long)unit->fcp_lun, |
1893 | (unsigned long long)unit->port->wwpn); | |
5ffd51a5 | 1894 | zfcp_erp_unit_failed(unit, "fsouh_5", req); |
c41f8cbd | 1895 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
5ffd51a5 | 1896 | zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req); |
1da177e4 | 1897 | } else if (!exclusive && readwrite) { |
c41f8cbd | 1898 | dev_err(&adapter->ccw_device->dev, |
ff3b24fa CS |
1899 | "Shared read-write access not " |
1900 | "supported (unit 0x%016Lx, port " | |
27c3f0a6 | 1901 | "0x%016Lx)\n", |
7ba58c9c SS |
1902 | (unsigned long long)unit->fcp_lun, |
1903 | (unsigned long long)unit->port->wwpn); | |
5ffd51a5 | 1904 | zfcp_erp_unit_failed(unit, "fsouh_7", req); |
c41f8cbd | 1905 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
5ffd51a5 | 1906 | zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req); |
1da177e4 LT |
1907 | } |
1908 | } | |
1da177e4 | 1909 | break; |
1da177e4 | 1910 | } |
1da177e4 LT |
1911 | } |
1912 | ||
c41f8cbd SS |
1913 | /** |
1914 | * zfcp_fsf_open_unit - open unit | |
1915 | * @erp_action: pointer to struct zfcp_erp_action | |
1916 | * Returns: 0 on success, error otherwise | |
1da177e4 | 1917 | */ |
c41f8cbd | 1918 | int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) |
1da177e4 | 1919 | { |
44cc76f2 | 1920 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
1921 | struct zfcp_adapter *adapter = erp_action->adapter; |
1922 | struct zfcp_fsf_req *req; | |
1923 | int retval = -EIO; | |
1924 | ||
0406289e | 1925 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd | 1926 | if (zfcp_fsf_req_sbal_get(adapter)) |
1da177e4 | 1927 | goto out; |
1da177e4 | 1928 | |
c41f8cbd SS |
1929 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN, |
1930 | ZFCP_REQ_AUTO_CLEANUP, | |
1931 | adapter->pool.fsf_req_erp); | |
025270f0 | 1932 | if (IS_ERR(req)) { |
c41f8cbd SS |
1933 | retval = PTR_ERR(req); |
1934 | goto out; | |
1935 | } | |
1936 | ||
1937 | sbale = zfcp_qdio_sbale_req(req); | |
1da177e4 LT |
1938 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1939 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1940 | ||
c41f8cbd SS |
1941 | req->qtcb->header.port_handle = erp_action->port->handle; |
1942 | req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun; | |
1943 | req->handler = zfcp_fsf_open_unit_handler; | |
1944 | req->data = erp_action->unit; | |
1945 | req->erp_action = erp_action; | |
1946 | erp_action->fsf_req = req; | |
1947 | ||
1948 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) | |
1949 | req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING; | |
1950 | ||
287ac01a | 1951 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd | 1952 | retval = zfcp_fsf_req_send(req); |
1da177e4 | 1953 | if (retval) { |
c41f8cbd | 1954 | zfcp_fsf_req_free(req); |
1da177e4 | 1955 | erp_action->fsf_req = NULL; |
1da177e4 | 1956 | } |
c41f8cbd | 1957 | out: |
0406289e | 1958 | spin_unlock_bh(&adapter->req_q_lock); |
1da177e4 LT |
1959 | return retval; |
1960 | } | |
1961 | ||
c41f8cbd | 1962 | static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req) |
1da177e4 | 1963 | { |
c41f8cbd | 1964 | struct zfcp_unit *unit = req->data; |
1da177e4 | 1965 | |
c41f8cbd | 1966 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
44cc76f2 | 1967 | return; |
1da177e4 | 1968 | |
c41f8cbd | 1969 | switch (req->qtcb->header.fsf_status) { |
1da177e4 | 1970 | case FSF_PORT_HANDLE_NOT_VALID: |
5ffd51a5 | 1971 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req); |
c41f8cbd | 1972 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1973 | break; |
1da177e4 | 1974 | case FSF_LUN_HANDLE_NOT_VALID: |
5ffd51a5 | 1975 | zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req); |
c41f8cbd | 1976 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 1977 | break; |
1da177e4 | 1978 | case FSF_PORT_BOXED: |
5ffd51a5 | 1979 | zfcp_erp_port_boxed(unit->port, "fscuh_3", req); |
c41f8cbd SS |
1980 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
1981 | ZFCP_STATUS_FSFREQ_RETRY; | |
1da177e4 | 1982 | break; |
1da177e4 | 1983 | case FSF_ADAPTER_STATUS_AVAILABLE: |
c41f8cbd | 1984 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
1da177e4 | 1985 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
65a8d4e1 | 1986 | zfcp_test_link(unit->port); |
c41f8cbd | 1987 | /* fall through */ |
1da177e4 | 1988 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
c41f8cbd | 1989 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
1990 | break; |
1991 | } | |
1992 | break; | |
1da177e4 | 1993 | case FSF_GOOD: |
1da177e4 | 1994 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
1da177e4 | 1995 | break; |
1da177e4 | 1996 | } |
1da177e4 LT |
1997 | } |
1998 | ||
1999 | /** | |
c41f8cbd SS |
2000 | * zfcp_fsf_close_unit - close zfcp unit |
2001 | * @erp_action: pointer to struct zfcp_unit | |
2002 | * Returns: 0 on success, error otherwise | |
1da177e4 | 2003 | */ |
c41f8cbd | 2004 | int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) |
1da177e4 | 2005 | { |
44cc76f2 | 2006 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
2007 | struct zfcp_adapter *adapter = erp_action->adapter; |
2008 | struct zfcp_fsf_req *req; | |
2009 | int retval = -EIO; | |
1da177e4 | 2010 | |
0406289e | 2011 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd | 2012 | if (zfcp_fsf_req_sbal_get(adapter)) |
1da177e4 | 2013 | goto out; |
c41f8cbd SS |
2014 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN, |
2015 | ZFCP_REQ_AUTO_CLEANUP, | |
2016 | adapter->pool.fsf_req_erp); | |
025270f0 | 2017 | if (IS_ERR(req)) { |
c41f8cbd SS |
2018 | retval = PTR_ERR(req); |
2019 | goto out; | |
2020 | } | |
1da177e4 | 2021 | |
c41f8cbd SS |
2022 | sbale = zfcp_qdio_sbale_req(req); |
2023 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
1da177e4 LT |
2024 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
2025 | ||
c41f8cbd SS |
2026 | req->qtcb->header.port_handle = erp_action->port->handle; |
2027 | req->qtcb->header.lun_handle = erp_action->unit->handle; | |
2028 | req->handler = zfcp_fsf_close_unit_handler; | |
2029 | req->data = erp_action->unit; | |
2030 | req->erp_action = erp_action; | |
2031 | erp_action->fsf_req = req; | |
fdf23452 | 2032 | |
287ac01a | 2033 | zfcp_fsf_start_erp_timer(req); |
c41f8cbd SS |
2034 | retval = zfcp_fsf_req_send(req); |
2035 | if (retval) { | |
2036 | zfcp_fsf_req_free(req); | |
2037 | erp_action->fsf_req = NULL; | |
2038 | } | |
2039 | out: | |
0406289e | 2040 | spin_unlock_bh(&adapter->req_q_lock); |
c41f8cbd | 2041 | return retval; |
1da177e4 LT |
2042 | } |
2043 | ||
c9615858 CS |
2044 | static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat) |
2045 | { | |
2046 | lat_rec->sum += lat; | |
c41f8cbd SS |
2047 | lat_rec->min = min(lat_rec->min, lat); |
2048 | lat_rec->max = max(lat_rec->max, lat); | |
c9615858 CS |
2049 | } |
2050 | ||
c41f8cbd | 2051 | static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req) |
c9615858 CS |
2052 | { |
2053 | struct fsf_qual_latency_info *lat_inf; | |
2054 | struct latency_cont *lat; | |
c41f8cbd | 2055 | struct zfcp_unit *unit = req->unit; |
c9615858 | 2056 | |
c41f8cbd | 2057 | lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info; |
c9615858 | 2058 | |
c41f8cbd | 2059 | switch (req->qtcb->bottom.io.data_direction) { |
c9615858 CS |
2060 | case FSF_DATADIR_READ: |
2061 | lat = &unit->latencies.read; | |
2062 | break; | |
2063 | case FSF_DATADIR_WRITE: | |
2064 | lat = &unit->latencies.write; | |
2065 | break; | |
2066 | case FSF_DATADIR_CMND: | |
2067 | lat = &unit->latencies.cmd; | |
2068 | break; | |
2069 | default: | |
2070 | return; | |
2071 | } | |
2072 | ||
49f0f01c | 2073 | spin_lock(&unit->latencies.lock); |
c9615858 CS |
2074 | zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat); |
2075 | zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat); | |
2076 | lat->counter++; | |
49f0f01c | 2077 | spin_unlock(&unit->latencies.lock); |
1da177e4 LT |
2078 | } |
2079 | ||
0997f1c5 SR |
2080 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
2081 | static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req) | |
2082 | { | |
2083 | struct fsf_qual_latency_info *lat_inf; | |
2084 | struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data; | |
2085 | struct request *req = scsi_cmnd->request; | |
2086 | struct zfcp_blk_drv_data trace; | |
2087 | int ticks = fsf_req->adapter->timer_ticks; | |
2088 | ||
2089 | trace.flags = 0; | |
2090 | trace.magic = ZFCP_BLK_DRV_DATA_MAGIC; | |
2091 | if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) { | |
2092 | trace.flags |= ZFCP_BLK_LAT_VALID; | |
2093 | lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info; | |
2094 | trace.channel_lat = lat_inf->channel_lat * ticks; | |
2095 | trace.fabric_lat = lat_inf->fabric_lat * ticks; | |
2096 | } | |
2097 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
2098 | trace.flags |= ZFCP_BLK_REQ_ERROR; | |
2099 | trace.inb_usage = fsf_req->qdio_inb_usage; | |
2100 | trace.outb_usage = fsf_req->qdio_outb_usage; | |
2101 | ||
2102 | blk_add_driver_data(req->q, req, &trace, sizeof(trace)); | |
2103 | } | |
2104 | #else | |
2105 | static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req) | |
2106 | { | |
2107 | } | |
2108 | #endif | |
2109 | ||
c41f8cbd | 2110 | static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req) |
1da177e4 | 2111 | { |
0ac55aa9 | 2112 | struct scsi_cmnd *scpnt; |
1da177e4 | 2113 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
c41f8cbd | 2114 | &(req->qtcb->bottom.io.fcp_rsp); |
1da177e4 | 2115 | u32 sns_len; |
f76af7d7 | 2116 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
1da177e4 | 2117 | unsigned long flags; |
1da177e4 | 2118 | |
c41f8cbd SS |
2119 | read_lock_irqsave(&req->adapter->abort_lock, flags); |
2120 | ||
0ac55aa9 SS |
2121 | scpnt = req->data; |
2122 | if (unlikely(!scpnt)) { | |
2123 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); | |
2124 | return; | |
2125 | } | |
2126 | ||
c41f8cbd | 2127 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { |
feac6a07 | 2128 | set_host_byte(scpnt, DID_SOFT_ERROR); |
1da177e4 LT |
2129 | goto skip_fsfstatus; |
2130 | } | |
2131 | ||
c41f8cbd | 2132 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
feac6a07 | 2133 | set_host_byte(scpnt, DID_ERROR); |
1da177e4 LT |
2134 | goto skip_fsfstatus; |
2135 | } | |
2136 | ||
feac6a07 | 2137 | set_msg_byte(scpnt, COMMAND_COMPLETE); |
1da177e4 | 2138 | |
1da177e4 | 2139 | scpnt->result |= fcp_rsp_iu->scsi_status; |
1da177e4 | 2140 | |
c41f8cbd SS |
2141 | if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) |
2142 | zfcp_fsf_req_latency(req); | |
c9615858 | 2143 | |
0997f1c5 SR |
2144 | zfcp_fsf_trace_latency(req); |
2145 | ||
1da177e4 | 2146 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { |
c41f8cbd | 2147 | if (fcp_rsp_info[3] == RSP_CODE_GOOD) |
feac6a07 | 2148 | set_host_byte(scpnt, DID_OK); |
c41f8cbd | 2149 | else { |
feac6a07 | 2150 | set_host_byte(scpnt, DID_ERROR); |
6f71d9bc | 2151 | goto skip_fsfstatus; |
1da177e4 LT |
2152 | } |
2153 | } | |
2154 | ||
1da177e4 | 2155 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { |
c41f8cbd SS |
2156 | sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) + |
2157 | fcp_rsp_iu->fcp_rsp_len; | |
1da177e4 | 2158 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); |
1da177e4 | 2159 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); |
1da177e4 | 2160 | |
9d058ecf | 2161 | memcpy(scpnt->sense_buffer, |
1da177e4 | 2162 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); |
1da177e4 LT |
2163 | } |
2164 | ||
1da177e4 | 2165 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { |
7936a892 FT |
2166 | scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid); |
2167 | if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) < | |
2168 | scpnt->underflow) | |
feac6a07 | 2169 | set_host_byte(scpnt, DID_ERROR); |
1da177e4 | 2170 | } |
c41f8cbd | 2171 | skip_fsfstatus: |
8a36e453 | 2172 | if (scpnt->result != 0) |
c41f8cbd | 2173 | zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req); |
8a36e453 | 2174 | else if (scpnt->retries > 0) |
c41f8cbd | 2175 | zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req); |
8a36e453 | 2176 | else |
c41f8cbd | 2177 | zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req); |
1da177e4 | 2178 | |
1da177e4 | 2179 | scpnt->host_scribble = NULL; |
1da177e4 | 2180 | (scpnt->scsi_done) (scpnt); |
1da177e4 LT |
2181 | /* |
2182 | * We must hold this lock until scsi_done has been called. | |
2183 | * Otherwise we may call scsi_done after abort regarding this | |
2184 | * command has completed. | |
2185 | * Note: scsi_done must not block! | |
2186 | */ | |
c41f8cbd | 2187 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); |
1da177e4 LT |
2188 | } |
2189 | ||
c41f8cbd | 2190 | static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req) |
1da177e4 | 2191 | { |
1da177e4 | 2192 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
c41f8cbd | 2193 | &(req->qtcb->bottom.io.fcp_rsp); |
f76af7d7 | 2194 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
1da177e4 | 2195 | |
c41f8cbd SS |
2196 | if ((fcp_rsp_info[3] != RSP_CODE_GOOD) || |
2197 | (req->status & ZFCP_STATUS_FSFREQ_ERROR)) | |
2198 | req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | |
2199 | } | |
2200 | ||
2201 | ||
2202 | static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req) | |
2203 | { | |
2204 | struct zfcp_unit *unit; | |
2205 | struct fsf_qtcb_header *header = &req->qtcb->header; | |
2206 | ||
2207 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) | |
2208 | unit = req->data; | |
2209 | else | |
2210 | unit = req->unit; | |
2211 | ||
2212 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) | |
1da177e4 | 2213 | goto skip_fsfstatus; |
1da177e4 | 2214 | |
c41f8cbd SS |
2215 | switch (header->fsf_status) { |
2216 | case FSF_HANDLE_MISMATCH: | |
2217 | case FSF_PORT_HANDLE_NOT_VALID: | |
5ffd51a5 | 2218 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req); |
c41f8cbd SS |
2219 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2220 | break; | |
2221 | case FSF_FCPLUN_NOT_VALID: | |
2222 | case FSF_LUN_HANDLE_NOT_VALID: | |
5ffd51a5 | 2223 | zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req); |
c41f8cbd | 2224 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 | 2225 | break; |
c41f8cbd SS |
2226 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
2227 | zfcp_fsf_class_not_supp(req); | |
1da177e4 | 2228 | break; |
c41f8cbd SS |
2229 | case FSF_ACCESS_DENIED: |
2230 | zfcp_fsf_access_denied_unit(req, unit); | |
2231 | break; | |
2232 | case FSF_DIRECTION_INDICATOR_NOT_VALID: | |
2233 | dev_err(&req->adapter->ccw_device->dev, | |
ff3b24fa CS |
2234 | "Incorrect direction %d, unit 0x%016Lx on port " |
2235 | "0x%016Lx closed\n", | |
c41f8cbd | 2236 | req->qtcb->bottom.io.data_direction, |
7ba58c9c SS |
2237 | (unsigned long long)unit->fcp_lun, |
2238 | (unsigned long long)unit->port->wwpn); | |
5ffd51a5 SS |
2239 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3", |
2240 | req); | |
c41f8cbd SS |
2241 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2242 | break; | |
2243 | case FSF_CMND_LENGTH_NOT_VALID: | |
2244 | dev_err(&req->adapter->ccw_device->dev, | |
ff3b24fa CS |
2245 | "Incorrect CDB length %d, unit 0x%016Lx on " |
2246 | "port 0x%016Lx closed\n", | |
c41f8cbd | 2247 | req->qtcb->bottom.io.fcp_cmnd_length, |
7ba58c9c SS |
2248 | (unsigned long long)unit->fcp_lun, |
2249 | (unsigned long long)unit->port->wwpn); | |
5ffd51a5 SS |
2250 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4", |
2251 | req); | |
c41f8cbd SS |
2252 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2253 | break; | |
2254 | case FSF_PORT_BOXED: | |
5ffd51a5 | 2255 | zfcp_erp_port_boxed(unit->port, "fssfch5", req); |
c41f8cbd SS |
2256 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
2257 | ZFCP_STATUS_FSFREQ_RETRY; | |
2258 | break; | |
2259 | case FSF_LUN_BOXED: | |
5ffd51a5 | 2260 | zfcp_erp_unit_boxed(unit, "fssfch6", req); |
c41f8cbd SS |
2261 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
2262 | ZFCP_STATUS_FSFREQ_RETRY; | |
2263 | break; | |
2264 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
2265 | if (header->fsf_status_qual.word[0] == | |
2266 | FSF_SQ_INVOKE_LINK_TEST_PROCEDURE) | |
2267 | zfcp_test_link(unit->port); | |
2268 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1da177e4 | 2269 | break; |
1da177e4 | 2270 | } |
c41f8cbd SS |
2271 | skip_fsfstatus: |
2272 | if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) | |
2273 | zfcp_fsf_send_fcp_ctm_handler(req); | |
2274 | else { | |
2275 | zfcp_fsf_send_fcp_command_task_handler(req); | |
2276 | req->unit = NULL; | |
2277 | zfcp_unit_put(unit); | |
2278 | } | |
1da177e4 LT |
2279 | } |
2280 | ||
7ba58c9c SS |
2281 | static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl) |
2282 | { | |
2283 | u32 *fcp_dl_ptr; | |
2284 | ||
2285 | /* | |
2286 | * fcp_dl_addr = start address of fcp_cmnd structure + | |
2287 | * size of fixed part + size of dynamically sized add_dcp_cdb field | |
2288 | * SEE FCP-2 documentation | |
2289 | */ | |
2290 | fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] + | |
2291 | (fcp_cmd->add_fcp_cdb_length << 2)); | |
2292 | *fcp_dl_ptr = fcp_dl; | |
2293 | } | |
2294 | ||
c41f8cbd SS |
2295 | /** |
2296 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) | |
c41f8cbd SS |
2297 | * @unit: unit where command is sent to |
2298 | * @scsi_cmnd: scsi command to be sent | |
1da177e4 | 2299 | */ |
63caf367 CS |
2300 | int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit, |
2301 | struct scsi_cmnd *scsi_cmnd) | |
1da177e4 | 2302 | { |
c41f8cbd SS |
2303 | struct zfcp_fsf_req *req; |
2304 | struct fcp_cmnd_iu *fcp_cmnd_iu; | |
2305 | unsigned int sbtype; | |
2306 | int real_bytes, retval = -EIO; | |
63caf367 | 2307 | struct zfcp_adapter *adapter = unit->port->adapter; |
1da177e4 | 2308 | |
c41f8cbd SS |
2309 | if (unlikely(!(atomic_read(&unit->status) & |
2310 | ZFCP_STATUS_COMMON_UNBLOCKED))) | |
2311 | return -EBUSY; | |
1da177e4 | 2312 | |
0406289e | 2313 | spin_lock(&adapter->req_q_lock); |
8fdf30d5 CS |
2314 | if (atomic_read(&adapter->req_q.count) <= 0) { |
2315 | atomic_inc(&adapter->qdio_outb_full); | |
c41f8cbd | 2316 | goto out; |
8fdf30d5 | 2317 | } |
63caf367 CS |
2318 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, |
2319 | ZFCP_REQ_AUTO_CLEANUP, | |
c41f8cbd | 2320 | adapter->pool.fsf_req_scsi); |
025270f0 | 2321 | if (IS_ERR(req)) { |
c41f8cbd SS |
2322 | retval = PTR_ERR(req); |
2323 | goto out; | |
2324 | } | |
2325 | ||
2326 | zfcp_unit_get(unit); | |
2327 | req->unit = unit; | |
2328 | req->data = scsi_cmnd; | |
2329 | req->handler = zfcp_fsf_send_fcp_command_handler; | |
2330 | req->qtcb->header.lun_handle = unit->handle; | |
2331 | req->qtcb->header.port_handle = unit->port->handle; | |
2332 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; | |
2333 | ||
2334 | scsi_cmnd->host_scribble = (unsigned char *) req->req_id; | |
2335 | ||
2336 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd); | |
2337 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; | |
2338 | /* | |
2339 | * set depending on data direction: | |
2340 | * data direction bits in SBALE (SB Type) | |
2341 | * data direction bits in QTCB | |
2342 | * data direction bits in FCP_CMND IU | |
2343 | */ | |
2344 | switch (scsi_cmnd->sc_data_direction) { | |
2345 | case DMA_NONE: | |
2346 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; | |
2347 | sbtype = SBAL_FLAGS0_TYPE_READ; | |
1da177e4 | 2348 | break; |
c41f8cbd SS |
2349 | case DMA_FROM_DEVICE: |
2350 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; | |
2351 | sbtype = SBAL_FLAGS0_TYPE_READ; | |
2352 | fcp_cmnd_iu->rddata = 1; | |
2353 | break; | |
2354 | case DMA_TO_DEVICE: | |
2355 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; | |
2356 | sbtype = SBAL_FLAGS0_TYPE_WRITE; | |
2357 | fcp_cmnd_iu->wddata = 1; | |
1da177e4 | 2358 | break; |
c41f8cbd | 2359 | case DMA_BIDIRECTIONAL: |
1da177e4 | 2360 | default: |
c41f8cbd SS |
2361 | retval = -EIO; |
2362 | goto failed_scsi_cmnd; | |
1da177e4 LT |
2363 | } |
2364 | ||
c41f8cbd SS |
2365 | if (likely((scsi_cmnd->device->simple_tags) || |
2366 | ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) && | |
2367 | (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED)))) | |
2368 | fcp_cmnd_iu->task_attribute = SIMPLE_Q; | |
2369 | else | |
2370 | fcp_cmnd_iu->task_attribute = UNTAGGED; | |
1da177e4 | 2371 | |
c41f8cbd SS |
2372 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) |
2373 | fcp_cmnd_iu->add_fcp_cdb_length = | |
2374 | (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; | |
1da177e4 | 2375 | |
c41f8cbd | 2376 | memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
45633fdc | 2377 | |
c41f8cbd | 2378 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + |
7ba58c9c | 2379 | fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32); |
1da177e4 | 2380 | |
c41f8cbd SS |
2381 | real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype, |
2382 | scsi_sglist(scsi_cmnd), | |
2383 | FSF_MAX_SBALS_PER_REQ); | |
2384 | if (unlikely(real_bytes < 0)) { | |
2385 | if (req->sbal_number < FSF_MAX_SBALS_PER_REQ) | |
2386 | retval = -EIO; | |
2387 | else { | |
2388 | dev_err(&adapter->ccw_device->dev, | |
ff3b24fa CS |
2389 | "Oversize data package, unit 0x%016Lx " |
2390 | "on port 0x%016Lx closed\n", | |
7ba58c9c SS |
2391 | (unsigned long long)unit->fcp_lun, |
2392 | (unsigned long long)unit->port->wwpn); | |
5ffd51a5 | 2393 | zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req); |
c41f8cbd SS |
2394 | retval = -EINVAL; |
2395 | } | |
2396 | goto failed_scsi_cmnd; | |
1da177e4 | 2397 | } |
1da177e4 | 2398 | |
c41f8cbd | 2399 | zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); |
1da177e4 | 2400 | |
c41f8cbd SS |
2401 | retval = zfcp_fsf_req_send(req); |
2402 | if (unlikely(retval)) | |
2403 | goto failed_scsi_cmnd; | |
1da177e4 | 2404 | |
c41f8cbd | 2405 | goto out; |
1da177e4 | 2406 | |
c41f8cbd SS |
2407 | failed_scsi_cmnd: |
2408 | zfcp_unit_put(unit); | |
2409 | zfcp_fsf_req_free(req); | |
2410 | scsi_cmnd->host_scribble = NULL; | |
2411 | out: | |
0406289e | 2412 | spin_unlock(&adapter->req_q_lock); |
c41f8cbd | 2413 | return retval; |
1da177e4 LT |
2414 | } |
2415 | ||
2416 | /** | |
c41f8cbd | 2417 | * zfcp_fsf_send_fcp_ctm - send SCSI task management command |
c41f8cbd SS |
2418 | * @unit: pointer to struct zfcp_unit |
2419 | * @tm_flags: unsigned byte for task management flags | |
c41f8cbd | 2420 | * Returns: on success pointer to struct fsf_req, NULL otherwise |
1da177e4 | 2421 | */ |
63caf367 | 2422 | struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags) |
1da177e4 | 2423 | { |
44cc76f2 | 2424 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
2425 | struct zfcp_fsf_req *req = NULL; |
2426 | struct fcp_cmnd_iu *fcp_cmnd_iu; | |
63caf367 | 2427 | struct zfcp_adapter *adapter = unit->port->adapter; |
1da177e4 | 2428 | |
c41f8cbd SS |
2429 | if (unlikely(!(atomic_read(&unit->status) & |
2430 | ZFCP_STATUS_COMMON_UNBLOCKED))) | |
2431 | return NULL; | |
1da177e4 | 2432 | |
92cab0d9 CS |
2433 | spin_lock_bh(&adapter->req_q_lock); |
2434 | if (zfcp_fsf_req_sbal_get(adapter)) | |
c41f8cbd | 2435 | goto out; |
63caf367 | 2436 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0, |
c41f8cbd | 2437 | adapter->pool.fsf_req_scsi); |
633528c3 SS |
2438 | if (IS_ERR(req)) { |
2439 | req = NULL; | |
c41f8cbd | 2440 | goto out; |
633528c3 | 2441 | } |
1da177e4 | 2442 | |
c41f8cbd SS |
2443 | req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT; |
2444 | req->data = unit; | |
2445 | req->handler = zfcp_fsf_send_fcp_command_handler; | |
2446 | req->qtcb->header.lun_handle = unit->handle; | |
2447 | req->qtcb->header.port_handle = unit->port->handle; | |
2448 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; | |
2449 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; | |
2450 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + | |
7ba58c9c | 2451 | sizeof(u32); |
c41f8cbd SS |
2452 | |
2453 | sbale = zfcp_qdio_sbale_req(req); | |
2454 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; | |
2455 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1da177e4 | 2456 | |
c41f8cbd SS |
2457 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd; |
2458 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; | |
2459 | fcp_cmnd_iu->task_management_flags = tm_flags; | |
1da177e4 | 2460 | |
c41f8cbd SS |
2461 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
2462 | if (!zfcp_fsf_req_send(req)) | |
2463 | goto out; | |
1da177e4 | 2464 | |
c41f8cbd SS |
2465 | zfcp_fsf_req_free(req); |
2466 | req = NULL; | |
2467 | out: | |
92cab0d9 | 2468 | spin_unlock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
2469 | return req; |
2470 | } | |
1da177e4 | 2471 | |
c41f8cbd SS |
2472 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req) |
2473 | { | |
2474 | if (req->qtcb->header.fsf_status != FSF_GOOD) | |
2475 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1da177e4 LT |
2476 | } |
2477 | ||
c41f8cbd SS |
2478 | /** |
2479 | * zfcp_fsf_control_file - control file upload/download | |
2480 | * @adapter: pointer to struct zfcp_adapter | |
2481 | * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc | |
2482 | * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise | |
1da177e4 | 2483 | */ |
c41f8cbd SS |
2484 | struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter, |
2485 | struct zfcp_fsf_cfdc *fsf_cfdc) | |
1da177e4 | 2486 | { |
44cc76f2 | 2487 | struct qdio_buffer_element *sbale; |
c41f8cbd SS |
2488 | struct zfcp_fsf_req *req = NULL; |
2489 | struct fsf_qtcb_bottom_support *bottom; | |
2490 | int direction, retval = -EIO, bytes; | |
2491 | ||
2492 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) | |
2493 | return ERR_PTR(-EOPNOTSUPP); | |
2494 | ||
2495 | switch (fsf_cfdc->command) { | |
2496 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | |
2497 | direction = SBAL_FLAGS0_TYPE_WRITE; | |
2498 | break; | |
2499 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | |
2500 | direction = SBAL_FLAGS0_TYPE_READ; | |
2501 | break; | |
2502 | default: | |
2503 | return ERR_PTR(-EINVAL); | |
2504 | } | |
1da177e4 | 2505 | |
0406289e | 2506 | spin_lock_bh(&adapter->req_q_lock); |
c41f8cbd SS |
2507 | if (zfcp_fsf_req_sbal_get(adapter)) |
2508 | goto out; | |
1da177e4 | 2509 | |
c41f8cbd | 2510 | req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL); |
025270f0 | 2511 | if (IS_ERR(req)) { |
c41f8cbd SS |
2512 | retval = -EPERM; |
2513 | goto out; | |
2514 | } | |
1da177e4 | 2515 | |
c41f8cbd | 2516 | req->handler = zfcp_fsf_control_file_handler; |
1da177e4 | 2517 | |
c41f8cbd SS |
2518 | sbale = zfcp_qdio_sbale_req(req); |
2519 | sbale[0].flags |= direction; | |
8a36e453 | 2520 | |
c41f8cbd SS |
2521 | bottom = &req->qtcb->bottom.support; |
2522 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; | |
2523 | bottom->option = fsf_cfdc->option; | |
8a36e453 | 2524 | |
c41f8cbd SS |
2525 | bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg, |
2526 | FSF_MAX_SBALS_PER_REQ); | |
2527 | if (bytes != ZFCP_CFDC_MAX_SIZE) { | |
2528 | retval = -ENOMEM; | |
2529 | zfcp_fsf_req_free(req); | |
2530 | goto out; | |
2531 | } | |
1da177e4 | 2532 | |
c41f8cbd SS |
2533 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
2534 | retval = zfcp_fsf_req_send(req); | |
2535 | out: | |
0406289e | 2536 | spin_unlock_bh(&adapter->req_q_lock); |
8a36e453 | 2537 | |
c41f8cbd SS |
2538 | if (!retval) { |
2539 | wait_event(req->completion_wq, | |
2540 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | |
2541 | return req; | |
1da177e4 | 2542 | } |
c41f8cbd | 2543 | return ERR_PTR(retval); |
1da177e4 | 2544 | } |