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