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