]>
Commit | Line | Data |
---|---|---|
2d70c103 NB |
1 | /* |
2 | * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx | |
3 | * | |
4 | * based on qla2x00t.c code: | |
5 | * | |
6 | * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net> | |
7 | * Copyright (C) 2004 - 2005 Leonid Stoljar | |
8 | * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us> | |
9 | * Copyright (C) 2006 - 2010 ID7 Ltd. | |
10 | * | |
11 | * Forward port and refactoring to modern qla2xxx and target/configfs | |
12 | * | |
4c76251e | 13 | * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org> |
2d70c103 NB |
14 | * |
15 | * This program is free software; you can redistribute it and/or | |
16 | * modify it under the terms of the GNU General Public License | |
17 | * as published by the Free Software Foundation, version 2 | |
18 | * of the License. | |
19 | * | |
20 | * This program is distributed in the hope that it will be useful, | |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | * GNU General Public License for more details. | |
24 | */ | |
25 | ||
26 | #include <linux/module.h> | |
27 | #include <linux/init.h> | |
28 | #include <linux/types.h> | |
2d70c103 NB |
29 | #include <linux/blkdev.h> |
30 | #include <linux/interrupt.h> | |
31 | #include <linux/pci.h> | |
32 | #include <linux/delay.h> | |
33 | #include <linux/list.h> | |
34 | #include <linux/workqueue.h> | |
35 | #include <asm/unaligned.h> | |
36 | #include <scsi/scsi.h> | |
37 | #include <scsi/scsi_host.h> | |
38 | #include <scsi/scsi_tcq.h> | |
39 | #include <target/target_core_base.h> | |
40 | #include <target/target_core_fabric.h> | |
41 | ||
42 | #include "qla_def.h" | |
43 | #include "qla_target.h" | |
44 | ||
d154f350 AE |
45 | static int ql2xtgt_tape_enable; |
46 | module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR); | |
47 | MODULE_PARM_DESC(ql2xtgt_tape_enable, | |
48 | "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER."); | |
49 | ||
2d70c103 NB |
50 | static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED; |
51 | module_param(qlini_mode, charp, S_IRUGO); | |
52 | MODULE_PARM_DESC(qlini_mode, | |
53 | "Determines when initiator mode will be enabled. Possible values: " | |
54 | "\"exclusive\" - initiator mode will be enabled on load, " | |
55 | "disabled on enabling target mode and then on disabling target mode " | |
56 | "enabled back; " | |
57 | "\"disabled\" - initiator mode will never be enabled; " | |
58 | "\"enabled\" (default) - initiator mode will always stay enabled."); | |
59 | ||
aa230bc5 | 60 | int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
2d70c103 | 61 | |
33e79977 QT |
62 | static int temp_sam_status = SAM_STAT_BUSY; |
63 | ||
2d70c103 NB |
64 | /* |
65 | * From scsi/fc/fc_fcp.h | |
66 | */ | |
67 | enum fcp_resp_rsp_codes { | |
68 | FCP_TMF_CMPL = 0, | |
69 | FCP_DATA_LEN_INVALID = 1, | |
70 | FCP_CMND_FIELDS_INVALID = 2, | |
71 | FCP_DATA_PARAM_MISMATCH = 3, | |
72 | FCP_TMF_REJECTED = 4, | |
73 | FCP_TMF_FAILED = 5, | |
74 | FCP_TMF_INVALID_LUN = 9, | |
75 | }; | |
76 | ||
77 | /* | |
78 | * fc_pri_ta from scsi/fc/fc_fcp.h | |
79 | */ | |
80 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ | |
81 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ | |
82 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ | |
6efb3c0a | 83 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
2d70c103 NB |
84 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
85 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ | |
86 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ | |
87 | ||
88 | /* | |
89 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which | |
90 | * must be called under HW lock and could unlock/lock it inside. | |
91 | * It isn't an issue, since in the current implementation on the time when | |
92 | * those functions are called: | |
93 | * | |
94 | * - Either context is IRQ and only IRQ handler can modify HW data, | |
95 | * including rings related fields, | |
96 | * | |
97 | * - Or access to target mode variables from struct qla_tgt doesn't | |
98 | * cross those functions boundaries, except tgt_stop, which | |
99 | * additionally protected by irq_cmd_count. | |
100 | */ | |
101 | /* Predefs for callbacks handed to qla2xxx LLD */ | |
102 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, | |
103 | struct atio_from_isp *pkt); | |
104 | static void qlt_response_pkt(struct scsi_qla_host *ha, response_t *pkt); | |
105 | static int qlt_issue_task_mgmt(struct qla_tgt_sess *sess, uint32_t lun, | |
106 | int fn, void *iocb, int flags); | |
107 | static void qlt_send_term_exchange(struct scsi_qla_host *ha, struct qla_tgt_cmd | |
108 | *cmd, struct atio_from_isp *atio, int ha_locked); | |
109 | static void qlt_reject_free_srr_imm(struct scsi_qla_host *ha, | |
110 | struct qla_tgt_srr_imm *imm, int ha_lock); | |
b6a029e1 AE |
111 | static void qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, |
112 | struct qla_tgt_cmd *cmd); | |
33e79977 QT |
113 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
114 | struct atio_from_isp *atio, uint16_t status, int qfull); | |
55a9066f | 115 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
2d70c103 NB |
116 | /* |
117 | * Global Variables | |
118 | */ | |
2d70c103 NB |
119 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
120 | static mempool_t *qla_tgt_mgmt_cmd_mempool; | |
121 | static struct workqueue_struct *qla_tgt_wq; | |
122 | static DEFINE_MUTEX(qla_tgt_mutex); | |
123 | static LIST_HEAD(qla_tgt_glist); | |
124 | ||
125 | /* ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) */ | |
126 | static struct qla_tgt_sess *qlt_find_sess_by_port_name( | |
127 | struct qla_tgt *tgt, | |
128 | const uint8_t *port_name) | |
129 | { | |
130 | struct qla_tgt_sess *sess; | |
131 | ||
132 | list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) { | |
133 | if (!memcmp(sess->port_name, port_name, WWN_SIZE)) | |
134 | return sess; | |
135 | } | |
136 | ||
137 | return NULL; | |
138 | } | |
139 | ||
140 | /* Might release hw lock, then reaquire!! */ | |
141 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) | |
142 | { | |
143 | /* Send marker if required */ | |
144 | if (unlikely(vha->marker_needed != 0)) { | |
145 | int rc = qla2x00_issue_marker(vha, vha_locked); | |
146 | if (rc != QLA_SUCCESS) { | |
147 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, | |
148 | "qla_target(%d): issue_marker() failed\n", | |
149 | vha->vp_idx); | |
150 | } | |
151 | return rc; | |
152 | } | |
153 | return QLA_SUCCESS; | |
154 | } | |
155 | ||
156 | static inline | |
157 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, | |
158 | uint8_t *d_id) | |
159 | { | |
160 | struct qla_hw_data *ha = vha->hw; | |
161 | uint8_t vp_idx; | |
162 | ||
163 | if ((vha->d_id.b.area != d_id[1]) || (vha->d_id.b.domain != d_id[0])) | |
164 | return NULL; | |
165 | ||
166 | if (vha->d_id.b.al_pa == d_id[2]) | |
167 | return vha; | |
168 | ||
169 | BUG_ON(ha->tgt.tgt_vp_map == NULL); | |
170 | vp_idx = ha->tgt.tgt_vp_map[d_id[2]].idx; | |
171 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) | |
172 | return ha->tgt.tgt_vp_map[vp_idx].vha; | |
173 | ||
174 | return NULL; | |
175 | } | |
176 | ||
177 | static inline | |
178 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, | |
179 | uint16_t vp_idx) | |
180 | { | |
181 | struct qla_hw_data *ha = vha->hw; | |
182 | ||
183 | if (vha->vp_idx == vp_idx) | |
184 | return vha; | |
185 | ||
186 | BUG_ON(ha->tgt.tgt_vp_map == NULL); | |
187 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) | |
188 | return ha->tgt.tgt_vp_map[vp_idx].vha; | |
189 | ||
190 | return NULL; | |
191 | } | |
192 | ||
33e79977 QT |
193 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
194 | { | |
195 | unsigned long flags; | |
196 | ||
197 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); | |
198 | ||
199 | vha->hw->tgt.num_pend_cmds++; | |
200 | if (vha->hw->tgt.num_pend_cmds > vha->hw->qla_stats.stat_max_pend_cmds) | |
201 | vha->hw->qla_stats.stat_max_pend_cmds = | |
202 | vha->hw->tgt.num_pend_cmds; | |
203 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); | |
204 | } | |
205 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) | |
206 | { | |
207 | unsigned long flags; | |
208 | ||
209 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); | |
210 | vha->hw->tgt.num_pend_cmds--; | |
211 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); | |
212 | } | |
213 | ||
55a9066f | 214 | static void qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha, |
2d70c103 NB |
215 | struct atio_from_isp *atio) |
216 | { | |
f83adb61 QT |
217 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
218 | "%s: qla_target(%d): type %x ox_id %04x\n", | |
219 | __func__, vha->vp_idx, atio->u.raw.entry_type, | |
220 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); | |
221 | ||
2d70c103 NB |
222 | switch (atio->u.raw.entry_type) { |
223 | case ATIO_TYPE7: | |
224 | { | |
225 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, | |
226 | atio->u.isp24.fcp_hdr.d_id); | |
227 | if (unlikely(NULL == host)) { | |
228 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, | |
229 | "qla_target(%d): Received ATIO_TYPE7 " | |
230 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, | |
231 | atio->u.isp24.fcp_hdr.d_id[0], | |
232 | atio->u.isp24.fcp_hdr.d_id[1], | |
233 | atio->u.isp24.fcp_hdr.d_id[2]); | |
234 | break; | |
235 | } | |
236 | qlt_24xx_atio_pkt(host, atio); | |
237 | break; | |
238 | } | |
239 | ||
240 | case IMMED_NOTIFY_TYPE: | |
241 | { | |
242 | struct scsi_qla_host *host = vha; | |
243 | struct imm_ntfy_from_isp *entry = | |
244 | (struct imm_ntfy_from_isp *)atio; | |
245 | ||
246 | if ((entry->u.isp24.vp_index != 0xFF) && | |
247 | (entry->u.isp24.nport_handle != 0xFFFF)) { | |
248 | host = qlt_find_host_by_vp_idx(vha, | |
249 | entry->u.isp24.vp_index); | |
250 | if (unlikely(!host)) { | |
251 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, | |
252 | "qla_target(%d): Received " | |
253 | "ATIO (IMMED_NOTIFY_TYPE) " | |
254 | "with unknown vp_index %d\n", | |
255 | vha->vp_idx, entry->u.isp24.vp_index); | |
256 | break; | |
257 | } | |
258 | } | |
259 | qlt_24xx_atio_pkt(host, atio); | |
260 | break; | |
261 | } | |
262 | ||
263 | default: | |
264 | ql_dbg(ql_dbg_tgt, vha, 0xe040, | |
265 | "qla_target(%d): Received unknown ATIO atio " | |
266 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); | |
267 | break; | |
268 | } | |
269 | ||
270 | return; | |
271 | } | |
272 | ||
273 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, response_t *pkt) | |
274 | { | |
275 | switch (pkt->entry_type) { | |
f83adb61 QT |
276 | case CTIO_CRC2: |
277 | ql_dbg(ql_dbg_tgt, vha, 0xe073, | |
278 | "qla_target(%d):%s: CRC2 Response pkt\n", | |
279 | vha->vp_idx, __func__); | |
2d70c103 NB |
280 | case CTIO_TYPE7: |
281 | { | |
282 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; | |
283 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, | |
284 | entry->vp_index); | |
285 | if (unlikely(!host)) { | |
286 | ql_dbg(ql_dbg_tgt, vha, 0xe041, | |
287 | "qla_target(%d): Response pkt (CTIO_TYPE7) " | |
288 | "received, with unknown vp_index %d\n", | |
289 | vha->vp_idx, entry->vp_index); | |
290 | break; | |
291 | } | |
292 | qlt_response_pkt(host, pkt); | |
293 | break; | |
294 | } | |
295 | ||
296 | case IMMED_NOTIFY_TYPE: | |
297 | { | |
298 | struct scsi_qla_host *host = vha; | |
299 | struct imm_ntfy_from_isp *entry = | |
300 | (struct imm_ntfy_from_isp *)pkt; | |
301 | ||
302 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); | |
303 | if (unlikely(!host)) { | |
304 | ql_dbg(ql_dbg_tgt, vha, 0xe042, | |
305 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " | |
306 | "received, with unknown vp_index %d\n", | |
307 | vha->vp_idx, entry->u.isp24.vp_index); | |
308 | break; | |
309 | } | |
310 | qlt_response_pkt(host, pkt); | |
311 | break; | |
312 | } | |
313 | ||
314 | case NOTIFY_ACK_TYPE: | |
315 | { | |
316 | struct scsi_qla_host *host = vha; | |
317 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; | |
318 | ||
319 | if (0xFF != entry->u.isp24.vp_index) { | |
320 | host = qlt_find_host_by_vp_idx(vha, | |
321 | entry->u.isp24.vp_index); | |
322 | if (unlikely(!host)) { | |
323 | ql_dbg(ql_dbg_tgt, vha, 0xe043, | |
324 | "qla_target(%d): Response " | |
325 | "pkt (NOTIFY_ACK_TYPE) " | |
326 | "received, with unknown " | |
327 | "vp_index %d\n", vha->vp_idx, | |
328 | entry->u.isp24.vp_index); | |
329 | break; | |
330 | } | |
331 | } | |
332 | qlt_response_pkt(host, pkt); | |
333 | break; | |
334 | } | |
335 | ||
336 | case ABTS_RECV_24XX: | |
337 | { | |
338 | struct abts_recv_from_24xx *entry = | |
339 | (struct abts_recv_from_24xx *)pkt; | |
340 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, | |
341 | entry->vp_index); | |
342 | if (unlikely(!host)) { | |
343 | ql_dbg(ql_dbg_tgt, vha, 0xe044, | |
344 | "qla_target(%d): Response pkt " | |
345 | "(ABTS_RECV_24XX) received, with unknown " | |
346 | "vp_index %d\n", vha->vp_idx, entry->vp_index); | |
347 | break; | |
348 | } | |
349 | qlt_response_pkt(host, pkt); | |
350 | break; | |
351 | } | |
352 | ||
353 | case ABTS_RESP_24XX: | |
354 | { | |
355 | struct abts_resp_to_24xx *entry = | |
356 | (struct abts_resp_to_24xx *)pkt; | |
357 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, | |
358 | entry->vp_index); | |
359 | if (unlikely(!host)) { | |
360 | ql_dbg(ql_dbg_tgt, vha, 0xe045, | |
361 | "qla_target(%d): Response pkt " | |
362 | "(ABTS_RECV_24XX) received, with unknown " | |
363 | "vp_index %d\n", vha->vp_idx, entry->vp_index); | |
364 | break; | |
365 | } | |
366 | qlt_response_pkt(host, pkt); | |
367 | break; | |
368 | } | |
369 | ||
370 | default: | |
371 | qlt_response_pkt(vha, pkt); | |
372 | break; | |
373 | } | |
374 | ||
375 | } | |
376 | ||
377 | static void qlt_free_session_done(struct work_struct *work) | |
378 | { | |
379 | struct qla_tgt_sess *sess = container_of(work, struct qla_tgt_sess, | |
380 | free_work); | |
381 | struct qla_tgt *tgt = sess->tgt; | |
382 | struct scsi_qla_host *vha = sess->vha; | |
383 | struct qla_hw_data *ha = vha->hw; | |
384 | ||
385 | BUG_ON(!tgt); | |
386 | /* | |
387 | * Release the target session for FC Nexus from fabric module code. | |
388 | */ | |
389 | if (sess->se_sess != NULL) | |
390 | ha->tgt.tgt_ops->free_session(sess); | |
391 | ||
392 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, | |
393 | "Unregistration of sess %p finished\n", sess); | |
394 | ||
395 | kfree(sess); | |
396 | /* | |
397 | * We need to protect against race, when tgt is freed before or | |
398 | * inside wake_up() | |
399 | */ | |
400 | tgt->sess_count--; | |
401 | if (tgt->sess_count == 0) | |
402 | wake_up_all(&tgt->waitQ); | |
403 | } | |
404 | ||
405 | /* ha->hardware_lock supposed to be held on entry */ | |
406 | void qlt_unreg_sess(struct qla_tgt_sess *sess) | |
407 | { | |
408 | struct scsi_qla_host *vha = sess->vha; | |
409 | ||
410 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); | |
411 | ||
412 | list_del(&sess->sess_list_entry); | |
413 | if (sess->deleted) | |
414 | list_del(&sess->del_list_entry); | |
415 | ||
416 | INIT_WORK(&sess->free_work, qlt_free_session_done); | |
417 | schedule_work(&sess->free_work); | |
418 | } | |
419 | EXPORT_SYMBOL(qlt_unreg_sess); | |
420 | ||
421 | /* ha->hardware_lock supposed to be held on entry */ | |
422 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) | |
423 | { | |
424 | struct qla_hw_data *ha = vha->hw; | |
425 | struct qla_tgt_sess *sess = NULL; | |
426 | uint32_t unpacked_lun, lun = 0; | |
427 | uint16_t loop_id; | |
428 | int res = 0; | |
429 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; | |
430 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; | |
431 | ||
432 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); | |
433 | if (loop_id == 0xFFFF) { | |
434 | #if 0 /* FIXME: Re-enable Global event handling.. */ | |
435 | /* Global event */ | |
436 | atomic_inc(&ha->tgt.qla_tgt->tgt_global_resets_count); | |
c5701042 | 437 | qlt_clear_tgt_db(ha->tgt.qla_tgt); |
2d70c103 NB |
438 | if (!list_empty(&ha->tgt.qla_tgt->sess_list)) { |
439 | sess = list_entry(ha->tgt.qla_tgt->sess_list.next, | |
440 | typeof(*sess), sess_list_entry); | |
441 | switch (mcmd) { | |
442 | case QLA_TGT_NEXUS_LOSS_SESS: | |
443 | mcmd = QLA_TGT_NEXUS_LOSS; | |
444 | break; | |
445 | case QLA_TGT_ABORT_ALL_SESS: | |
446 | mcmd = QLA_TGT_ABORT_ALL; | |
447 | break; | |
448 | case QLA_TGT_NEXUS_LOSS: | |
449 | case QLA_TGT_ABORT_ALL: | |
450 | break; | |
451 | default: | |
452 | ql_dbg(ql_dbg_tgt, vha, 0xe046, | |
453 | "qla_target(%d): Not allowed " | |
454 | "command %x in %s", vha->vp_idx, | |
455 | mcmd, __func__); | |
456 | sess = NULL; | |
457 | break; | |
458 | } | |
459 | } else | |
460 | sess = NULL; | |
461 | #endif | |
462 | } else { | |
463 | sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id); | |
464 | } | |
465 | ||
466 | ql_dbg(ql_dbg_tgt, vha, 0xe000, | |
467 | "Using sess for qla_tgt_reset: %p\n", sess); | |
468 | if (!sess) { | |
469 | res = -ESRCH; | |
470 | return res; | |
471 | } | |
472 | ||
473 | ql_dbg(ql_dbg_tgt, vha, 0xe047, | |
7b833558 OK |
474 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
475 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, | |
2d70c103 NB |
476 | mcmd, loop_id); |
477 | ||
478 | lun = a->u.isp24.fcp_cmnd.lun; | |
479 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | |
480 | ||
481 | return qlt_issue_task_mgmt(sess, unpacked_lun, mcmd, | |
482 | iocb, QLA24XX_MGMT_SEND_NACK); | |
483 | } | |
484 | ||
485 | /* ha->hardware_lock supposed to be held on entry */ | |
486 | static void qlt_schedule_sess_for_deletion(struct qla_tgt_sess *sess, | |
487 | bool immediate) | |
488 | { | |
489 | struct qla_tgt *tgt = sess->tgt; | |
490 | uint32_t dev_loss_tmo = tgt->ha->port_down_retry_count + 5; | |
491 | ||
492 | if (sess->deleted) | |
493 | return; | |
494 | ||
495 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, | |
496 | "Scheduling sess %p for deletion\n", sess); | |
497 | list_add_tail(&sess->del_list_entry, &tgt->del_sess_list); | |
498 | sess->deleted = 1; | |
499 | ||
500 | if (immediate) | |
501 | dev_loss_tmo = 0; | |
502 | ||
503 | sess->expires = jiffies + dev_loss_tmo * HZ; | |
504 | ||
505 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe048, | |
7b833558 | 506 | "qla_target(%d): session for port %8phC (loop ID %d) scheduled for " |
2d70c103 | 507 | "deletion in %u secs (expires: %lu) immed: %d\n", |
7b833558 OK |
508 | sess->vha->vp_idx, sess->port_name, sess->loop_id, dev_loss_tmo, |
509 | sess->expires, immediate); | |
2d70c103 NB |
510 | |
511 | if (immediate) | |
512 | schedule_delayed_work(&tgt->sess_del_work, 0); | |
513 | else | |
514 | schedule_delayed_work(&tgt->sess_del_work, | |
63832aab | 515 | sess->expires - jiffies); |
2d70c103 NB |
516 | } |
517 | ||
518 | /* ha->hardware_lock supposed to be held on entry */ | |
c5701042 | 519 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
2d70c103 NB |
520 | { |
521 | struct qla_tgt_sess *sess; | |
522 | ||
523 | list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) | |
524 | qlt_schedule_sess_for_deletion(sess, true); | |
525 | ||
526 | /* At this point tgt could be already dead */ | |
527 | } | |
528 | ||
529 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, | |
530 | uint16_t *loop_id) | |
531 | { | |
532 | struct qla_hw_data *ha = vha->hw; | |
533 | dma_addr_t gid_list_dma; | |
534 | struct gid_list_info *gid_list; | |
535 | char *id_iter; | |
536 | int res, rc, i; | |
537 | uint16_t entries; | |
538 | ||
539 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), | |
540 | &gid_list_dma, GFP_KERNEL); | |
541 | if (!gid_list) { | |
542 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, | |
543 | "qla_target(%d): DMA Alloc failed of %u\n", | |
544 | vha->vp_idx, qla2x00_gid_list_size(ha)); | |
545 | return -ENOMEM; | |
546 | } | |
547 | ||
548 | /* Get list of logged in devices */ | |
549 | rc = qla2x00_get_id_list(vha, gid_list, gid_list_dma, &entries); | |
550 | if (rc != QLA_SUCCESS) { | |
551 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, | |
552 | "qla_target(%d): get_id_list() failed: %x\n", | |
553 | vha->vp_idx, rc); | |
554 | res = -1; | |
555 | goto out_free_id_list; | |
556 | } | |
557 | ||
558 | id_iter = (char *)gid_list; | |
559 | res = -1; | |
560 | for (i = 0; i < entries; i++) { | |
561 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; | |
562 | if ((gid->al_pa == s_id[2]) && | |
563 | (gid->area == s_id[1]) && | |
564 | (gid->domain == s_id[0])) { | |
565 | *loop_id = le16_to_cpu(gid->loop_id); | |
566 | res = 0; | |
567 | break; | |
568 | } | |
569 | id_iter += ha->gid_list_info_size; | |
570 | } | |
571 | ||
572 | out_free_id_list: | |
573 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), | |
574 | gid_list, gid_list_dma); | |
575 | return res; | |
576 | } | |
577 | ||
2d70c103 NB |
578 | /* ha->hardware_lock supposed to be held on entry */ |
579 | static void qlt_undelete_sess(struct qla_tgt_sess *sess) | |
580 | { | |
581 | BUG_ON(!sess->deleted); | |
582 | ||
583 | list_del(&sess->del_list_entry); | |
584 | sess->deleted = 0; | |
585 | } | |
586 | ||
587 | static void qlt_del_sess_work_fn(struct delayed_work *work) | |
588 | { | |
589 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, | |
590 | sess_del_work); | |
591 | struct scsi_qla_host *vha = tgt->vha; | |
592 | struct qla_hw_data *ha = vha->hw; | |
593 | struct qla_tgt_sess *sess; | |
63832aab | 594 | unsigned long flags, elapsed; |
2d70c103 NB |
595 | |
596 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
597 | while (!list_empty(&tgt->del_sess_list)) { | |
598 | sess = list_entry(tgt->del_sess_list.next, typeof(*sess), | |
599 | del_list_entry); | |
63832aab SU |
600 | elapsed = jiffies; |
601 | if (time_after_eq(elapsed, sess->expires)) { | |
2d70c103 NB |
602 | qlt_undelete_sess(sess); |
603 | ||
08234e3a JE |
604 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
605 | "Timeout: sess %p about to be deleted\n", | |
606 | sess); | |
607 | ha->tgt.tgt_ops->shutdown_sess(sess); | |
608 | ha->tgt.tgt_ops->put_sess(sess); | |
2d70c103 NB |
609 | } else { |
610 | schedule_delayed_work(&tgt->sess_del_work, | |
63832aab | 611 | sess->expires - elapsed); |
2d70c103 NB |
612 | break; |
613 | } | |
614 | } | |
615 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
616 | } | |
617 | ||
618 | /* | |
619 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. | |
620 | * Caller must put it. | |
621 | */ | |
622 | static struct qla_tgt_sess *qlt_create_sess( | |
623 | struct scsi_qla_host *vha, | |
624 | fc_port_t *fcport, | |
625 | bool local) | |
626 | { | |
627 | struct qla_hw_data *ha = vha->hw; | |
628 | struct qla_tgt_sess *sess; | |
629 | unsigned long flags; | |
630 | unsigned char be_sid[3]; | |
631 | ||
632 | /* Check to avoid double sessions */ | |
633 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
0e8cd71c | 634 | list_for_each_entry(sess, &vha->vha_tgt.qla_tgt->sess_list, |
2d70c103 NB |
635 | sess_list_entry) { |
636 | if (!memcmp(sess->port_name, fcport->port_name, WWN_SIZE)) { | |
637 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005, | |
638 | "Double sess %p found (s_id %x:%x:%x, " | |
639 | "loop_id %d), updating to d_id %x:%x:%x, " | |
640 | "loop_id %d", sess, sess->s_id.b.domain, | |
641 | sess->s_id.b.al_pa, sess->s_id.b.area, | |
642 | sess->loop_id, fcport->d_id.b.domain, | |
643 | fcport->d_id.b.al_pa, fcport->d_id.b.area, | |
644 | fcport->loop_id); | |
645 | ||
646 | if (sess->deleted) | |
647 | qlt_undelete_sess(sess); | |
648 | ||
649 | kref_get(&sess->se_sess->sess_kref); | |
c8292d1d RD |
650 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, fcport->loop_id, |
651 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); | |
652 | ||
2d70c103 NB |
653 | if (sess->local && !local) |
654 | sess->local = 0; | |
655 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
656 | ||
657 | return sess; | |
658 | } | |
659 | } | |
660 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
661 | ||
662 | sess = kzalloc(sizeof(*sess), GFP_KERNEL); | |
663 | if (!sess) { | |
664 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04a, | |
7b833558 OK |
665 | "qla_target(%u): session allocation failed, all commands " |
666 | "from port %8phC will be refused", vha->vp_idx, | |
667 | fcport->port_name); | |
2d70c103 NB |
668 | |
669 | return NULL; | |
670 | } | |
0e8cd71c | 671 | sess->tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
672 | sess->vha = vha; |
673 | sess->s_id = fcport->d_id; | |
674 | sess->loop_id = fcport->loop_id; | |
675 | sess->local = local; | |
676 | ||
677 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, | |
678 | "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n", | |
0e8cd71c | 679 | sess, vha->vha_tgt.qla_tgt); |
2d70c103 NB |
680 | |
681 | be_sid[0] = sess->s_id.b.domain; | |
682 | be_sid[1] = sess->s_id.b.area; | |
683 | be_sid[2] = sess->s_id.b.al_pa; | |
684 | /* | |
685 | * Determine if this fc_port->port_name is allowed to access | |
686 | * target mode using explict NodeACLs+MappedLUNs, or using | |
687 | * TPG demo mode. If this is successful a target mode FC nexus | |
688 | * is created. | |
689 | */ | |
690 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, | |
691 | &fcport->port_name[0], sess, &be_sid[0], fcport->loop_id) < 0) { | |
692 | kfree(sess); | |
693 | return NULL; | |
694 | } | |
695 | /* | |
696 | * Take an extra reference to ->sess_kref here to handle qla_tgt_sess | |
697 | * access across ->hardware_lock reaquire. | |
698 | */ | |
699 | kref_get(&sess->se_sess->sess_kref); | |
700 | ||
c8292d1d | 701 | sess->conf_compl_supported = (fcport->flags & FCF_CONF_COMP_SUPPORTED); |
2d70c103 NB |
702 | BUILD_BUG_ON(sizeof(sess->port_name) != sizeof(fcport->port_name)); |
703 | memcpy(sess->port_name, fcport->port_name, sizeof(sess->port_name)); | |
704 | ||
705 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
0e8cd71c SK |
706 | list_add_tail(&sess->sess_list_entry, &vha->vha_tgt.qla_tgt->sess_list); |
707 | vha->vha_tgt.qla_tgt->sess_count++; | |
2d70c103 NB |
708 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
709 | ||
710 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, | |
7b833558 OK |
711 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
712 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", | |
713 | vha->vp_idx, local ? "local " : "", fcport->port_name, | |
714 | fcport->loop_id, sess->s_id.b.domain, sess->s_id.b.area, | |
715 | sess->s_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); | |
2d70c103 NB |
716 | |
717 | return sess; | |
718 | } | |
719 | ||
720 | /* | |
721 | * Called from drivers/scsi/qla2xxx/qla_init.c:qla2x00_reg_remote_port() | |
722 | */ | |
723 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) | |
724 | { | |
725 | struct qla_hw_data *ha = vha->hw; | |
0e8cd71c | 726 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
727 | struct qla_tgt_sess *sess; |
728 | unsigned long flags; | |
729 | ||
730 | if (!vha->hw->tgt.tgt_ops) | |
731 | return; | |
732 | ||
733 | if (!tgt || (fcport->port_type != FCT_INITIATOR)) | |
734 | return; | |
735 | ||
0e8cd71c SK |
736 | if (qla_ini_mode_enabled(vha)) |
737 | return; | |
738 | ||
2d70c103 NB |
739 | spin_lock_irqsave(&ha->hardware_lock, flags); |
740 | if (tgt->tgt_stop) { | |
741 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
742 | return; | |
743 | } | |
744 | sess = qlt_find_sess_by_port_name(tgt, fcport->port_name); | |
745 | if (!sess) { | |
746 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
747 | ||
0e8cd71c | 748 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
2d70c103 | 749 | sess = qlt_create_sess(vha, fcport, false); |
0e8cd71c | 750 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
2d70c103 NB |
751 | |
752 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
753 | } else { | |
754 | kref_get(&sess->se_sess->sess_kref); | |
755 | ||
756 | if (sess->deleted) { | |
757 | qlt_undelete_sess(sess); | |
758 | ||
759 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, | |
7b833558 OK |
760 | "qla_target(%u): %ssession for port %8phC " |
761 | "(loop ID %d) reappeared\n", vha->vp_idx, | |
762 | sess->local ? "local " : "", sess->port_name, | |
2d70c103 NB |
763 | sess->loop_id); |
764 | ||
765 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, | |
766 | "Reappeared sess %p\n", sess); | |
767 | } | |
c8292d1d RD |
768 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, fcport->loop_id, |
769 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); | |
2d70c103 NB |
770 | } |
771 | ||
772 | if (sess && sess->local) { | |
773 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, | |
774 | "qla_target(%u): local session for " | |
7b833558 OK |
775 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
776 | fcport->port_name, sess->loop_id); | |
2d70c103 NB |
777 | sess->local = 0; |
778 | } | |
2d70c103 | 779 | ha->tgt.tgt_ops->put_sess(sess); |
08234e3a | 780 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2d70c103 NB |
781 | } |
782 | ||
783 | void qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport) | |
784 | { | |
0e8cd71c | 785 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 | 786 | struct qla_tgt_sess *sess; |
2d70c103 NB |
787 | |
788 | if (!vha->hw->tgt.tgt_ops) | |
789 | return; | |
790 | ||
791 | if (!tgt || (fcport->port_type != FCT_INITIATOR)) | |
792 | return; | |
793 | ||
2d70c103 | 794 | if (tgt->tgt_stop) { |
2d70c103 NB |
795 | return; |
796 | } | |
797 | sess = qlt_find_sess_by_port_name(tgt, fcport->port_name); | |
798 | if (!sess) { | |
2d70c103 NB |
799 | return; |
800 | } | |
801 | ||
802 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); | |
803 | ||
804 | sess->local = 1; | |
805 | qlt_schedule_sess_for_deletion(sess, false); | |
2d70c103 NB |
806 | } |
807 | ||
808 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) | |
809 | { | |
810 | struct qla_hw_data *ha = tgt->ha; | |
811 | unsigned long flags; | |
812 | int res; | |
813 | /* | |
814 | * We need to protect against race, when tgt is freed before or | |
815 | * inside wake_up() | |
816 | */ | |
817 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
818 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, | |
819 | "tgt %p, empty(sess_list)=%d sess_count=%d\n", | |
820 | tgt, list_empty(&tgt->sess_list), tgt->sess_count); | |
821 | res = (tgt->sess_count == 0); | |
822 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
823 | ||
824 | return res; | |
825 | } | |
826 | ||
827 | /* Called by tcm_qla2xxx configfs code */ | |
3c231bda | 828 | int qlt_stop_phase1(struct qla_tgt *tgt) |
2d70c103 NB |
829 | { |
830 | struct scsi_qla_host *vha = tgt->vha; | |
831 | struct qla_hw_data *ha = tgt->ha; | |
832 | unsigned long flags; | |
833 | ||
3c231bda NB |
834 | mutex_lock(&qla_tgt_mutex); |
835 | if (!vha->fc_vport) { | |
836 | struct Scsi_Host *sh = vha->host; | |
837 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); | |
838 | bool npiv_vports; | |
839 | ||
840 | spin_lock_irqsave(sh->host_lock, flags); | |
841 | npiv_vports = (fc_host->npiv_vports_inuse); | |
842 | spin_unlock_irqrestore(sh->host_lock, flags); | |
843 | ||
844 | if (npiv_vports) { | |
845 | mutex_unlock(&qla_tgt_mutex); | |
846 | return -EPERM; | |
847 | } | |
848 | } | |
2d70c103 NB |
849 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
850 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, | |
851 | "Already in tgt->tgt_stop or tgt_stopped state\n"); | |
3c231bda NB |
852 | mutex_unlock(&qla_tgt_mutex); |
853 | return -EPERM; | |
2d70c103 NB |
854 | } |
855 | ||
856 | ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", | |
857 | vha->host_no, vha); | |
858 | /* | |
859 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. | |
860 | * Lock is needed, because we still can get an incoming packet. | |
861 | */ | |
0e8cd71c | 862 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
2d70c103 NB |
863 | spin_lock_irqsave(&ha->hardware_lock, flags); |
864 | tgt->tgt_stop = 1; | |
c5701042 | 865 | qlt_clear_tgt_db(tgt); |
2d70c103 | 866 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
0e8cd71c | 867 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
3c231bda | 868 | mutex_unlock(&qla_tgt_mutex); |
2d70c103 | 869 | |
43829731 | 870 | flush_delayed_work(&tgt->sess_del_work); |
2d70c103 NB |
871 | |
872 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, | |
873 | "Waiting for sess works (tgt %p)", tgt); | |
874 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | |
875 | while (!list_empty(&tgt->sess_works_list)) { | |
876 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | |
877 | flush_scheduled_work(); | |
878 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | |
879 | } | |
880 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | |
881 | ||
882 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, | |
883 | "Waiting for tgt %p: list_empty(sess_list)=%d " | |
884 | "sess_count=%d\n", tgt, list_empty(&tgt->sess_list), | |
885 | tgt->sess_count); | |
886 | ||
887 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); | |
888 | ||
889 | /* Big hammer */ | |
890 | if (!ha->flags.host_shutting_down && qla_tgt_mode_enabled(vha)) | |
891 | qlt_disable_vha(vha); | |
892 | ||
893 | /* Wait for sessions to clear out (just in case) */ | |
894 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); | |
3c231bda | 895 | return 0; |
2d70c103 NB |
896 | } |
897 | EXPORT_SYMBOL(qlt_stop_phase1); | |
898 | ||
899 | /* Called by tcm_qla2xxx configfs code */ | |
900 | void qlt_stop_phase2(struct qla_tgt *tgt) | |
901 | { | |
902 | struct qla_hw_data *ha = tgt->ha; | |
0e8cd71c | 903 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
2d70c103 NB |
904 | unsigned long flags; |
905 | ||
906 | if (tgt->tgt_stopped) { | |
0e8cd71c | 907 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
2d70c103 NB |
908 | "Already in tgt->tgt_stopped state\n"); |
909 | dump_stack(); | |
910 | return; | |
911 | } | |
912 | ||
0e8cd71c | 913 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
2d70c103 NB |
914 | "Waiting for %d IRQ commands to complete (tgt %p)", |
915 | tgt->irq_cmd_count, tgt); | |
916 | ||
0e8cd71c | 917 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
2d70c103 NB |
918 | spin_lock_irqsave(&ha->hardware_lock, flags); |
919 | while (tgt->irq_cmd_count != 0) { | |
920 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
921 | udelay(2); | |
922 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
923 | } | |
924 | tgt->tgt_stop = 0; | |
925 | tgt->tgt_stopped = 1; | |
926 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
0e8cd71c | 927 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
2d70c103 | 928 | |
0e8cd71c | 929 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished", |
2d70c103 NB |
930 | tgt); |
931 | } | |
932 | EXPORT_SYMBOL(qlt_stop_phase2); | |
933 | ||
934 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ | |
fa492630 | 935 | static void qlt_release(struct qla_tgt *tgt) |
2d70c103 | 936 | { |
0e8cd71c | 937 | scsi_qla_host_t *vha = tgt->vha; |
2d70c103 | 938 | |
0e8cd71c | 939 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
2d70c103 NB |
940 | qlt_stop_phase2(tgt); |
941 | ||
0e8cd71c | 942 | vha->vha_tgt.qla_tgt = NULL; |
2d70c103 | 943 | |
0e8cd71c | 944 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
2d70c103 NB |
945 | "Release of tgt %p finished\n", tgt); |
946 | ||
947 | kfree(tgt); | |
948 | } | |
949 | ||
950 | /* ha->hardware_lock supposed to be held on entry */ | |
951 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, | |
952 | const void *param, unsigned int param_size) | |
953 | { | |
954 | struct qla_tgt_sess_work_param *prm; | |
955 | unsigned long flags; | |
956 | ||
957 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); | |
958 | if (!prm) { | |
959 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, | |
960 | "qla_target(%d): Unable to create session " | |
961 | "work, command will be refused", 0); | |
962 | return -ENOMEM; | |
963 | } | |
964 | ||
965 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, | |
966 | "Scheduling work (type %d, prm %p)" | |
967 | " to find session for param %p (size %d, tgt %p)\n", | |
968 | type, prm, param, param_size, tgt); | |
969 | ||
970 | prm->type = type; | |
971 | memcpy(&prm->tm_iocb, param, param_size); | |
972 | ||
973 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | |
974 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); | |
975 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | |
976 | ||
977 | schedule_work(&tgt->sess_work); | |
978 | ||
979 | return 0; | |
980 | } | |
981 | ||
982 | /* | |
983 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
984 | */ | |
985 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, | |
986 | struct imm_ntfy_from_isp *ntfy, | |
987 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, | |
988 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) | |
989 | { | |
990 | struct qla_hw_data *ha = vha->hw; | |
991 | request_t *pkt; | |
992 | struct nack_to_isp *nack; | |
993 | ||
994 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); | |
995 | ||
996 | /* Send marker if required */ | |
997 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) | |
998 | return; | |
999 | ||
1000 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); | |
1001 | if (!pkt) { | |
1002 | ql_dbg(ql_dbg_tgt, vha, 0xe049, | |
1003 | "qla_target(%d): %s failed: unable to allocate " | |
1004 | "request packet\n", vha->vp_idx, __func__); | |
1005 | return; | |
1006 | } | |
1007 | ||
0e8cd71c SK |
1008 | if (vha->vha_tgt.qla_tgt != NULL) |
1009 | vha->vha_tgt.qla_tgt->notify_ack_expected++; | |
2d70c103 NB |
1010 | |
1011 | pkt->entry_type = NOTIFY_ACK_TYPE; | |
1012 | pkt->entry_count = 1; | |
1013 | ||
1014 | nack = (struct nack_to_isp *)pkt; | |
1015 | nack->ox_id = ntfy->ox_id; | |
1016 | ||
1017 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; | |
1018 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { | |
1019 | nack->u.isp24.flags = ntfy->u.isp24.flags & | |
1020 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); | |
1021 | } | |
1022 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; | |
1023 | nack->u.isp24.status = ntfy->u.isp24.status; | |
1024 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; | |
aa230bc5 | 1025 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
2d70c103 NB |
1026 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
1027 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; | |
1028 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; | |
1029 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); | |
1030 | nack->u.isp24.srr_reject_code = srr_reject_code; | |
1031 | nack->u.isp24.srr_reject_code_expl = srr_explan; | |
1032 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; | |
1033 | ||
1034 | ql_dbg(ql_dbg_tgt, vha, 0xe005, | |
1035 | "qla_target(%d): Sending 24xx Notify Ack %d\n", | |
1036 | vha->vp_idx, nack->u.isp24.status); | |
1037 | ||
63163e06 HM |
1038 | /* Memory Barrier */ |
1039 | wmb(); | |
2d70c103 NB |
1040 | qla2x00_start_iocbs(vha, vha->req); |
1041 | } | |
1042 | ||
1043 | /* | |
1044 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
1045 | */ | |
1046 | static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha, | |
1047 | struct abts_recv_from_24xx *abts, uint32_t status, | |
1048 | bool ids_reversed) | |
1049 | { | |
1050 | struct qla_hw_data *ha = vha->hw; | |
1051 | struct abts_resp_to_24xx *resp; | |
1052 | uint32_t f_ctl; | |
1053 | uint8_t *p; | |
1054 | ||
1055 | ql_dbg(ql_dbg_tgt, vha, 0xe006, | |
1056 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", | |
1057 | ha, abts, status); | |
1058 | ||
1059 | /* Send marker if required */ | |
1060 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) | |
1061 | return; | |
1062 | ||
b6a029e1 | 1063 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
2d70c103 NB |
1064 | if (!resp) { |
1065 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, | |
1066 | "qla_target(%d): %s failed: unable to allocate " | |
1067 | "request packet", vha->vp_idx, __func__); | |
1068 | return; | |
1069 | } | |
1070 | ||
1071 | resp->entry_type = ABTS_RESP_24XX; | |
1072 | resp->entry_count = 1; | |
1073 | resp->nport_handle = abts->nport_handle; | |
1074 | resp->vp_index = vha->vp_idx; | |
1075 | resp->sof_type = abts->sof_type; | |
1076 | resp->exchange_address = abts->exchange_address; | |
1077 | resp->fcp_hdr_le = abts->fcp_hdr_le; | |
1078 | f_ctl = __constant_cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | | |
1079 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | | |
1080 | F_CTL_SEQ_INITIATIVE); | |
1081 | p = (uint8_t *)&f_ctl; | |
1082 | resp->fcp_hdr_le.f_ctl[0] = *p++; | |
1083 | resp->fcp_hdr_le.f_ctl[1] = *p++; | |
1084 | resp->fcp_hdr_le.f_ctl[2] = *p; | |
1085 | if (ids_reversed) { | |
1086 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; | |
1087 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; | |
1088 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; | |
1089 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; | |
1090 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; | |
1091 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; | |
1092 | } else { | |
1093 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; | |
1094 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; | |
1095 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; | |
1096 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; | |
1097 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; | |
1098 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; | |
1099 | } | |
1100 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; | |
1101 | if (status == FCP_TMF_CMPL) { | |
1102 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; | |
1103 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; | |
1104 | resp->payload.ba_acct.low_seq_cnt = 0x0000; | |
1105 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; | |
1106 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; | |
1107 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; | |
1108 | } else { | |
1109 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; | |
1110 | resp->payload.ba_rjt.reason_code = | |
1111 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; | |
1112 | /* Other bytes are zero */ | |
1113 | } | |
1114 | ||
0e8cd71c | 1115 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
2d70c103 | 1116 | |
63163e06 HM |
1117 | /* Memory Barrier */ |
1118 | wmb(); | |
2d70c103 NB |
1119 | qla2x00_start_iocbs(vha, vha->req); |
1120 | } | |
1121 | ||
1122 | /* | |
1123 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
1124 | */ | |
1125 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, | |
1126 | struct abts_resp_from_24xx_fw *entry) | |
1127 | { | |
1128 | struct ctio7_to_24xx *ctio; | |
1129 | ||
1130 | ql_dbg(ql_dbg_tgt, vha, 0xe007, | |
1131 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); | |
1132 | /* Send marker if required */ | |
1133 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) | |
1134 | return; | |
1135 | ||
b6a029e1 | 1136 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
2d70c103 NB |
1137 | if (ctio == NULL) { |
1138 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, | |
1139 | "qla_target(%d): %s failed: unable to allocate " | |
1140 | "request packet\n", vha->vp_idx, __func__); | |
1141 | return; | |
1142 | } | |
1143 | ||
1144 | /* | |
1145 | * We've got on entrance firmware's response on by us generated | |
1146 | * ABTS response. So, in it ID fields are reversed. | |
1147 | */ | |
1148 | ||
1149 | ctio->entry_type = CTIO_TYPE7; | |
1150 | ctio->entry_count = 1; | |
1151 | ctio->nport_handle = entry->nport_handle; | |
1152 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | |
1153 | ctio->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | |
1154 | ctio->vp_index = vha->vp_idx; | |
1155 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; | |
1156 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; | |
1157 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; | |
1158 | ctio->exchange_addr = entry->exchange_addr_to_abort; | |
1159 | ctio->u.status1.flags = | |
1160 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | | |
1161 | CTIO7_FLAGS_TERMINATE); | |
33a5fcee | 1162 | ctio->u.status1.ox_id = cpu_to_le16(entry->fcp_hdr_le.ox_id); |
2d70c103 | 1163 | |
63163e06 HM |
1164 | /* Memory Barrier */ |
1165 | wmb(); | |
2d70c103 NB |
1166 | qla2x00_start_iocbs(vha, vha->req); |
1167 | ||
1168 | qlt_24xx_send_abts_resp(vha, (struct abts_recv_from_24xx *)entry, | |
1169 | FCP_TMF_CMPL, true); | |
1170 | } | |
1171 | ||
1172 | /* ha->hardware_lock supposed to be held on entry */ | |
1173 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, | |
1174 | struct abts_recv_from_24xx *abts, struct qla_tgt_sess *sess) | |
1175 | { | |
1176 | struct qla_hw_data *ha = vha->hw; | |
06e97b48 | 1177 | struct se_session *se_sess = sess->se_sess; |
2d70c103 | 1178 | struct qla_tgt_mgmt_cmd *mcmd; |
06e97b48 SH |
1179 | struct se_cmd *se_cmd; |
1180 | u32 lun = 0; | |
2d70c103 | 1181 | int rc; |
06e97b48 SH |
1182 | bool found_lun = false; |
1183 | ||
1184 | spin_lock(&se_sess->sess_cmd_lock); | |
1185 | list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { | |
1186 | struct qla_tgt_cmd *cmd = | |
1187 | container_of(se_cmd, struct qla_tgt_cmd, se_cmd); | |
649ee054 | 1188 | if (se_cmd->tag == abts->exchange_addr_to_abort) { |
06e97b48 SH |
1189 | lun = cmd->unpacked_lun; |
1190 | found_lun = true; | |
1191 | break; | |
1192 | } | |
1193 | } | |
1194 | spin_unlock(&se_sess->sess_cmd_lock); | |
1195 | ||
1196 | if (!found_lun) | |
1197 | return -ENOENT; | |
2d70c103 NB |
1198 | |
1199 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, | |
1200 | "qla_target(%d): task abort (tag=%d)\n", | |
1201 | vha->vp_idx, abts->exchange_addr_to_abort); | |
1202 | ||
1203 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); | |
1204 | if (mcmd == NULL) { | |
1205 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, | |
1206 | "qla_target(%d): %s: Allocation of ABORT cmd failed", | |
1207 | vha->vp_idx, __func__); | |
1208 | return -ENOMEM; | |
1209 | } | |
1210 | memset(mcmd, 0, sizeof(*mcmd)); | |
1211 | ||
1212 | mcmd->sess = sess; | |
1213 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); | |
80187f8e | 1214 | mcmd->reset_count = vha->hw->chip_reset; |
2d70c103 | 1215 | |
06e97b48 | 1216 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, TMR_ABORT_TASK, |
2d70c103 NB |
1217 | abts->exchange_addr_to_abort); |
1218 | if (rc != 0) { | |
1219 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, | |
1220 | "qla_target(%d): tgt_ops->handle_tmr()" | |
1221 | " failed: %d", vha->vp_idx, rc); | |
1222 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | |
1223 | return -EFAULT; | |
1224 | } | |
1225 | ||
1226 | return 0; | |
1227 | } | |
1228 | ||
1229 | /* | |
1230 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
1231 | */ | |
1232 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, | |
1233 | struct abts_recv_from_24xx *abts) | |
1234 | { | |
1235 | struct qla_hw_data *ha = vha->hw; | |
1236 | struct qla_tgt_sess *sess; | |
1237 | uint32_t tag = abts->exchange_addr_to_abort; | |
1238 | uint8_t s_id[3]; | |
1239 | int rc; | |
1240 | ||
1241 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { | |
1242 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, | |
1243 | "qla_target(%d): ABTS: Abort Sequence not " | |
1244 | "supported\n", vha->vp_idx); | |
1245 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); | |
1246 | return; | |
1247 | } | |
1248 | ||
1249 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { | |
1250 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, | |
1251 | "qla_target(%d): ABTS: Unknown Exchange " | |
1252 | "Address received\n", vha->vp_idx); | |
1253 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); | |
1254 | return; | |
1255 | } | |
1256 | ||
1257 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, | |
1258 | "qla_target(%d): task abort (s_id=%x:%x:%x, " | |
1259 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], | |
1260 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, | |
1261 | le32_to_cpu(abts->fcp_hdr_le.parameter)); | |
1262 | ||
1263 | s_id[0] = abts->fcp_hdr_le.s_id[2]; | |
1264 | s_id[1] = abts->fcp_hdr_le.s_id[1]; | |
1265 | s_id[2] = abts->fcp_hdr_le.s_id[0]; | |
1266 | ||
1267 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); | |
1268 | if (!sess) { | |
1269 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, | |
1270 | "qla_target(%d): task abort for non-existant session\n", | |
1271 | vha->vp_idx); | |
0e8cd71c | 1272 | rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
2d70c103 NB |
1273 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); |
1274 | if (rc != 0) { | |
1275 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, | |
1276 | false); | |
1277 | } | |
1278 | return; | |
1279 | } | |
1280 | ||
1281 | rc = __qlt_24xx_handle_abts(vha, abts, sess); | |
1282 | if (rc != 0) { | |
1283 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, | |
1284 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", | |
1285 | vha->vp_idx, rc); | |
1286 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); | |
1287 | return; | |
1288 | } | |
1289 | } | |
1290 | ||
1291 | /* | |
1292 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
1293 | */ | |
1294 | static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host *ha, | |
1295 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) | |
1296 | { | |
1297 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; | |
1298 | struct ctio7_to_24xx *ctio; | |
33a5fcee | 1299 | uint16_t temp; |
2d70c103 NB |
1300 | |
1301 | ql_dbg(ql_dbg_tgt, ha, 0xe008, | |
1302 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", | |
1303 | ha, atio, resp_code); | |
1304 | ||
1305 | /* Send marker if required */ | |
1306 | if (qlt_issue_marker(ha, 1) != QLA_SUCCESS) | |
1307 | return; | |
1308 | ||
1309 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(ha, NULL); | |
1310 | if (ctio == NULL) { | |
1311 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, | |
1312 | "qla_target(%d): %s failed: unable to allocate " | |
1313 | "request packet\n", ha->vp_idx, __func__); | |
1314 | return; | |
1315 | } | |
1316 | ||
1317 | ctio->entry_type = CTIO_TYPE7; | |
1318 | ctio->entry_count = 1; | |
1319 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | |
1320 | ctio->nport_handle = mcmd->sess->loop_id; | |
1321 | ctio->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | |
1322 | ctio->vp_index = ha->vp_idx; | |
1323 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | |
1324 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | |
1325 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | |
1326 | ctio->exchange_addr = atio->u.isp24.exchange_addr; | |
1327 | ctio->u.status1.flags = (atio->u.isp24.attr << 9) | | |
1328 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | | |
1329 | CTIO7_FLAGS_SEND_STATUS); | |
33a5fcee QT |
1330 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
1331 | ctio->u.status1.ox_id = cpu_to_le16(temp); | |
2d70c103 NB |
1332 | ctio->u.status1.scsi_status = |
1333 | __constant_cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); | |
1334 | ctio->u.status1.response_len = __constant_cpu_to_le16(8); | |
e4b11b89 | 1335 | ctio->u.status1.sense_data[0] = resp_code; |
2d70c103 | 1336 | |
63163e06 HM |
1337 | /* Memory Barrier */ |
1338 | wmb(); | |
2d70c103 NB |
1339 | qla2x00_start_iocbs(ha, ha->req); |
1340 | } | |
1341 | ||
1342 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) | |
1343 | { | |
1344 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | |
1345 | } | |
1346 | EXPORT_SYMBOL(qlt_free_mcmd); | |
1347 | ||
1348 | /* callback from target fabric module code */ | |
1349 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) | |
1350 | { | |
1351 | struct scsi_qla_host *vha = mcmd->sess->vha; | |
1352 | struct qla_hw_data *ha = vha->hw; | |
1353 | unsigned long flags; | |
1354 | ||
1355 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, | |
1356 | "TM response mcmd (%p) status %#x state %#x", | |
1357 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); | |
1358 | ||
1359 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
b6a029e1 AE |
1360 | |
1361 | if (qla2x00_reset_active(vha) || mcmd->reset_count != ha->chip_reset) { | |
1362 | /* | |
1363 | * Either a chip reset is active or this request was from | |
1364 | * previous life, just abort the processing. | |
1365 | */ | |
1366 | ql_dbg(ql_dbg_async, vha, 0xe100, | |
1367 | "RESET-TMR active/old-count/new-count = %d/%d/%d.\n", | |
1368 | qla2x00_reset_active(vha), mcmd->reset_count, | |
1369 | ha->chip_reset); | |
1370 | ha->tgt.tgt_ops->free_mcmd(mcmd); | |
1371 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1372 | return; | |
1373 | } | |
1374 | ||
2d70c103 NB |
1375 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) |
1376 | qlt_send_notify_ack(vha, &mcmd->orig_iocb.imm_ntfy, | |
1377 | 0, 0, 0, 0, 0, 0); | |
1378 | else { | |
1379 | if (mcmd->se_cmd.se_tmr_req->function == TMR_ABORT_TASK) | |
1380 | qlt_24xx_send_abts_resp(vha, &mcmd->orig_iocb.abts, | |
1381 | mcmd->fc_tm_rsp, false); | |
1382 | else | |
1383 | qlt_24xx_send_task_mgmt_ctio(vha, mcmd, | |
1384 | mcmd->fc_tm_rsp); | |
1385 | } | |
1386 | /* | |
1387 | * Make the callback for ->free_mcmd() to queue_work() and invoke | |
1388 | * target_put_sess_cmd() to drop cmd_kref to 1. The final | |
1389 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() | |
1390 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd | |
1391 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> | |
1392 | * qlt_xmit_tm_rsp() returns here.. | |
1393 | */ | |
1394 | ha->tgt.tgt_ops->free_mcmd(mcmd); | |
1395 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1396 | } | |
1397 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); | |
1398 | ||
1399 | /* No locks */ | |
1400 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) | |
1401 | { | |
1402 | struct qla_tgt_cmd *cmd = prm->cmd; | |
1403 | ||
1404 | BUG_ON(cmd->sg_cnt == 0); | |
1405 | ||
1406 | prm->sg = (struct scatterlist *)cmd->sg; | |
1407 | prm->seg_cnt = pci_map_sg(prm->tgt->ha->pdev, cmd->sg, | |
1408 | cmd->sg_cnt, cmd->dma_data_direction); | |
1409 | if (unlikely(prm->seg_cnt == 0)) | |
1410 | goto out_err; | |
1411 | ||
1412 | prm->cmd->sg_mapped = 1; | |
1413 | ||
f83adb61 QT |
1414 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
1415 | /* | |
1416 | * If greater than four sg entries then we need to allocate | |
1417 | * the continuation entries | |
1418 | */ | |
1419 | if (prm->seg_cnt > prm->tgt->datasegs_per_cmd) | |
1420 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - | |
1421 | prm->tgt->datasegs_per_cmd, | |
1422 | prm->tgt->datasegs_per_cont); | |
1423 | } else { | |
1424 | /* DIF */ | |
1425 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || | |
1426 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { | |
1427 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); | |
1428 | prm->tot_dsds = prm->seg_cnt; | |
1429 | } else | |
1430 | prm->tot_dsds = prm->seg_cnt; | |
1431 | ||
1432 | if (cmd->prot_sg_cnt) { | |
1433 | prm->prot_sg = cmd->prot_sg; | |
1434 | prm->prot_seg_cnt = pci_map_sg(prm->tgt->ha->pdev, | |
1435 | cmd->prot_sg, cmd->prot_sg_cnt, | |
1436 | cmd->dma_data_direction); | |
1437 | if (unlikely(prm->prot_seg_cnt == 0)) | |
1438 | goto out_err; | |
1439 | ||
1440 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || | |
1441 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { | |
1442 | /* Dif Bundling not support here */ | |
1443 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, | |
1444 | cmd->blk_sz); | |
1445 | prm->tot_dsds += prm->prot_seg_cnt; | |
1446 | } else | |
1447 | prm->tot_dsds += prm->prot_seg_cnt; | |
1448 | } | |
1449 | } | |
2d70c103 | 1450 | |
2d70c103 NB |
1451 | return 0; |
1452 | ||
1453 | out_err: | |
1454 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe04d, | |
1455 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", | |
1456 | 0, prm->cmd->sg_cnt); | |
1457 | return -1; | |
1458 | } | |
1459 | ||
f9b6721a | 1460 | static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
2d70c103 NB |
1461 | { |
1462 | struct qla_hw_data *ha = vha->hw; | |
1463 | ||
f9b6721a JE |
1464 | if (!cmd->sg_mapped) |
1465 | return; | |
1466 | ||
2d70c103 NB |
1467 | pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); |
1468 | cmd->sg_mapped = 0; | |
f83adb61 QT |
1469 | |
1470 | if (cmd->prot_sg_cnt) | |
1471 | pci_unmap_sg(ha->pdev, cmd->prot_sg, cmd->prot_sg_cnt, | |
1472 | cmd->dma_data_direction); | |
1473 | ||
1474 | if (cmd->ctx_dsd_alloced) | |
1475 | qla2x00_clean_dsd_pool(ha, NULL, cmd); | |
1476 | ||
1477 | if (cmd->ctx) | |
1478 | dma_pool_free(ha->dl_dma_pool, cmd->ctx, cmd->ctx->crc_ctx_dma); | |
2d70c103 NB |
1479 | } |
1480 | ||
1481 | static int qlt_check_reserve_free_req(struct scsi_qla_host *vha, | |
1482 | uint32_t req_cnt) | |
1483 | { | |
d29fb736 | 1484 | uint32_t cnt, cnt_in; |
2d70c103 NB |
1485 | |
1486 | if (vha->req->cnt < (req_cnt + 2)) { | |
75554b68 | 1487 | cnt = (uint16_t)RD_REG_DWORD(vha->req->req_q_out); |
d29fb736 | 1488 | cnt_in = (uint16_t)RD_REG_DWORD(vha->req->req_q_in); |
2d70c103 | 1489 | |
2d70c103 NB |
1490 | if (vha->req->ring_index < cnt) |
1491 | vha->req->cnt = cnt - vha->req->ring_index; | |
1492 | else | |
1493 | vha->req->cnt = vha->req->length - | |
1494 | (vha->req->ring_index - cnt); | |
1495 | } | |
1496 | ||
1497 | if (unlikely(vha->req->cnt < (req_cnt + 2))) { | |
667024a3 | 1498 | ql_dbg(ql_dbg_io, vha, 0x305a, |
d29fb736 SK |
1499 | "qla_target(%d): There is no room in the request ring: vha->req->ring_index=%d, vha->req->cnt=%d, req_cnt=%d Req-out=%d Req-in=%d Req-Length=%d\n", |
1500 | vha->vp_idx, vha->req->ring_index, | |
1501 | vha->req->cnt, req_cnt, cnt, cnt_in, vha->req->length); | |
2d70c103 NB |
1502 | return -EAGAIN; |
1503 | } | |
1504 | vha->req->cnt -= req_cnt; | |
1505 | ||
1506 | return 0; | |
1507 | } | |
1508 | ||
1509 | /* | |
1510 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
1511 | */ | |
1512 | static inline void *qlt_get_req_pkt(struct scsi_qla_host *vha) | |
1513 | { | |
1514 | /* Adjust ring index. */ | |
1515 | vha->req->ring_index++; | |
1516 | if (vha->req->ring_index == vha->req->length) { | |
1517 | vha->req->ring_index = 0; | |
1518 | vha->req->ring_ptr = vha->req->ring; | |
1519 | } else { | |
1520 | vha->req->ring_ptr++; | |
1521 | } | |
1522 | return (cont_entry_t *)vha->req->ring_ptr; | |
1523 | } | |
1524 | ||
1525 | /* ha->hardware_lock supposed to be held on entry */ | |
1526 | static inline uint32_t qlt_make_handle(struct scsi_qla_host *vha) | |
1527 | { | |
1528 | struct qla_hw_data *ha = vha->hw; | |
1529 | uint32_t h; | |
1530 | ||
1531 | h = ha->tgt.current_handle; | |
1532 | /* always increment cmd handle */ | |
1533 | do { | |
1534 | ++h; | |
8d93f550 | 1535 | if (h > DEFAULT_OUTSTANDING_COMMANDS) |
2d70c103 NB |
1536 | h = 1; /* 0 is QLA_TGT_NULL_HANDLE */ |
1537 | if (h == ha->tgt.current_handle) { | |
667024a3 | 1538 | ql_dbg(ql_dbg_io, vha, 0x305b, |
2d70c103 NB |
1539 | "qla_target(%d): Ran out of " |
1540 | "empty cmd slots in ha %p\n", vha->vp_idx, ha); | |
1541 | h = QLA_TGT_NULL_HANDLE; | |
1542 | break; | |
1543 | } | |
1544 | } while ((h == QLA_TGT_NULL_HANDLE) || | |
1545 | (h == QLA_TGT_SKIP_HANDLE) || | |
1546 | (ha->tgt.cmds[h-1] != NULL)); | |
1547 | ||
1548 | if (h != QLA_TGT_NULL_HANDLE) | |
1549 | ha->tgt.current_handle = h; | |
1550 | ||
1551 | return h; | |
1552 | } | |
1553 | ||
1554 | /* ha->hardware_lock supposed to be held on entry */ | |
1555 | static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm *prm, | |
1556 | struct scsi_qla_host *vha) | |
1557 | { | |
1558 | uint32_t h; | |
1559 | struct ctio7_to_24xx *pkt; | |
1560 | struct qla_hw_data *ha = vha->hw; | |
1561 | struct atio_from_isp *atio = &prm->cmd->atio; | |
33a5fcee | 1562 | uint16_t temp; |
2d70c103 NB |
1563 | |
1564 | pkt = (struct ctio7_to_24xx *)vha->req->ring_ptr; | |
1565 | prm->pkt = pkt; | |
1566 | memset(pkt, 0, sizeof(*pkt)); | |
1567 | ||
1568 | pkt->entry_type = CTIO_TYPE7; | |
1569 | pkt->entry_count = (uint8_t)prm->req_cnt; | |
1570 | pkt->vp_index = vha->vp_idx; | |
1571 | ||
1572 | h = qlt_make_handle(vha); | |
1573 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { | |
1574 | /* | |
1575 | * CTIO type 7 from the firmware doesn't provide a way to | |
1576 | * know the initiator's LOOP ID, hence we can't find | |
1577 | * the session and, so, the command. | |
1578 | */ | |
1579 | return -EAGAIN; | |
1580 | } else | |
1581 | ha->tgt.cmds[h-1] = prm->cmd; | |
1582 | ||
1583 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; | |
1584 | pkt->nport_handle = prm->cmd->loop_id; | |
1585 | pkt->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | |
1586 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | |
1587 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | |
1588 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | |
1589 | pkt->exchange_addr = atio->u.isp24.exchange_addr; | |
1590 | pkt->u.status0.flags |= (atio->u.isp24.attr << 9); | |
33a5fcee QT |
1591 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
1592 | pkt->u.status0.ox_id = cpu_to_le16(temp); | |
2d70c103 NB |
1593 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
1594 | ||
2d70c103 NB |
1595 | return 0; |
1596 | } | |
1597 | ||
1598 | /* | |
1599 | * ha->hardware_lock supposed to be held on entry. We have already made sure | |
1600 | * that there is sufficient amount of request entries to not drop it. | |
1601 | */ | |
1602 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm, | |
1603 | struct scsi_qla_host *vha) | |
1604 | { | |
1605 | int cnt; | |
1606 | uint32_t *dword_ptr; | |
1607 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; | |
1608 | ||
1609 | /* Build continuation packets */ | |
1610 | while (prm->seg_cnt > 0) { | |
1611 | cont_a64_entry_t *cont_pkt64 = | |
1612 | (cont_a64_entry_t *)qlt_get_req_pkt(vha); | |
1613 | ||
1614 | /* | |
1615 | * Make sure that from cont_pkt64 none of | |
1616 | * 64-bit specific fields used for 32-bit | |
1617 | * addressing. Cast to (cont_entry_t *) for | |
1618 | * that. | |
1619 | */ | |
1620 | ||
1621 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); | |
1622 | ||
1623 | cont_pkt64->entry_count = 1; | |
1624 | cont_pkt64->sys_define = 0; | |
1625 | ||
1626 | if (enable_64bit_addressing) { | |
1627 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; | |
1628 | dword_ptr = | |
1629 | (uint32_t *)&cont_pkt64->dseg_0_address; | |
1630 | } else { | |
1631 | cont_pkt64->entry_type = CONTINUE_TYPE; | |
1632 | dword_ptr = | |
1633 | (uint32_t *)&((cont_entry_t *) | |
1634 | cont_pkt64)->dseg_0_address; | |
1635 | } | |
1636 | ||
1637 | /* Load continuation entry data segments */ | |
1638 | for (cnt = 0; | |
1639 | cnt < prm->tgt->datasegs_per_cont && prm->seg_cnt; | |
1640 | cnt++, prm->seg_cnt--) { | |
1641 | *dword_ptr++ = | |
1642 | cpu_to_le32(pci_dma_lo32 | |
1643 | (sg_dma_address(prm->sg))); | |
1644 | if (enable_64bit_addressing) { | |
1645 | *dword_ptr++ = | |
1646 | cpu_to_le32(pci_dma_hi32 | |
1647 | (sg_dma_address | |
1648 | (prm->sg))); | |
1649 | } | |
1650 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); | |
1651 | ||
2d70c103 NB |
1652 | prm->sg = sg_next(prm->sg); |
1653 | } | |
1654 | } | |
1655 | } | |
1656 | ||
1657 | /* | |
1658 | * ha->hardware_lock supposed to be held on entry. We have already made sure | |
1659 | * that there is sufficient amount of request entries to not drop it. | |
1660 | */ | |
1661 | static void qlt_load_data_segments(struct qla_tgt_prm *prm, | |
1662 | struct scsi_qla_host *vha) | |
1663 | { | |
1664 | int cnt; | |
1665 | uint32_t *dword_ptr; | |
1666 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; | |
1667 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; | |
1668 | ||
2d70c103 NB |
1669 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
1670 | ||
1671 | /* Setup packet address segment pointer */ | |
1672 | dword_ptr = pkt24->u.status0.dseg_0_address; | |
1673 | ||
1674 | /* Set total data segment count */ | |
1675 | if (prm->seg_cnt) | |
1676 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); | |
1677 | ||
1678 | if (prm->seg_cnt == 0) { | |
1679 | /* No data transfer */ | |
1680 | *dword_ptr++ = 0; | |
1681 | *dword_ptr = 0; | |
1682 | return; | |
1683 | } | |
1684 | ||
1685 | /* If scatter gather */ | |
2d70c103 NB |
1686 | |
1687 | /* Load command entry data segments */ | |
1688 | for (cnt = 0; | |
1689 | (cnt < prm->tgt->datasegs_per_cmd) && prm->seg_cnt; | |
1690 | cnt++, prm->seg_cnt--) { | |
1691 | *dword_ptr++ = | |
1692 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); | |
1693 | if (enable_64bit_addressing) { | |
1694 | *dword_ptr++ = | |
1695 | cpu_to_le32(pci_dma_hi32( | |
1696 | sg_dma_address(prm->sg))); | |
1697 | } | |
1698 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); | |
1699 | ||
2d70c103 NB |
1700 | prm->sg = sg_next(prm->sg); |
1701 | } | |
1702 | ||
1703 | qlt_load_cont_data_segments(prm, vha); | |
1704 | } | |
1705 | ||
1706 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) | |
1707 | { | |
1708 | return cmd->bufflen > 0; | |
1709 | } | |
1710 | ||
1711 | /* | |
1712 | * Called without ha->hardware_lock held | |
1713 | */ | |
1714 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, | |
1715 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, | |
1716 | uint32_t *full_req_cnt) | |
1717 | { | |
1718 | struct qla_tgt *tgt = cmd->tgt; | |
1719 | struct scsi_qla_host *vha = tgt->vha; | |
1720 | struct qla_hw_data *ha = vha->hw; | |
1721 | struct se_cmd *se_cmd = &cmd->se_cmd; | |
1722 | ||
1723 | if (unlikely(cmd->aborted)) { | |
1724 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, | |
649ee054 BVA |
1725 | "qla_target(%d): terminating exchange for aborted cmd=%p (se_cmd=%p, tag=%lld)", |
1726 | vha->vp_idx, cmd, se_cmd, se_cmd->tag); | |
2d70c103 NB |
1727 | |
1728 | cmd->state = QLA_TGT_STATE_ABORTED; | |
e07f8f65 | 1729 | cmd->cmd_flags |= BIT_6; |
2d70c103 NB |
1730 | |
1731 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 0); | |
1732 | ||
1733 | /* !! At this point cmd could be already freed !! */ | |
1734 | return QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED; | |
1735 | } | |
1736 | ||
2d70c103 NB |
1737 | prm->cmd = cmd; |
1738 | prm->tgt = tgt; | |
1739 | prm->rq_result = scsi_status; | |
1740 | prm->sense_buffer = &cmd->sense_buffer[0]; | |
1741 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; | |
1742 | prm->sg = NULL; | |
1743 | prm->seg_cnt = -1; | |
1744 | prm->req_cnt = 1; | |
1745 | prm->add_status_pkt = 0; | |
1746 | ||
2d70c103 NB |
1747 | /* Send marker if required */ |
1748 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) | |
1749 | return -EFAULT; | |
1750 | ||
2d70c103 NB |
1751 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
1752 | if (qlt_pci_map_calc_cnt(prm) != 0) | |
1753 | return -EAGAIN; | |
1754 | } | |
1755 | ||
1756 | *full_req_cnt = prm->req_cnt; | |
1757 | ||
1758 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { | |
1759 | prm->residual = se_cmd->residual_count; | |
667024a3 | 1760 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x305c, |
649ee054 BVA |
1761 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
1762 | prm->residual, se_cmd->tag, | |
1763 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, | |
1764 | cmd->bufflen, prm->rq_result); | |
2d70c103 NB |
1765 | prm->rq_result |= SS_RESIDUAL_UNDER; |
1766 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { | |
1767 | prm->residual = se_cmd->residual_count; | |
667024a3 | 1768 | ql_dbg(ql_dbg_io, vha, 0x305d, |
649ee054 BVA |
1769 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
1770 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? | |
1771 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); | |
2d70c103 NB |
1772 | prm->rq_result |= SS_RESIDUAL_OVER; |
1773 | } | |
1774 | ||
1775 | if (xmit_type & QLA_TGT_XMIT_STATUS) { | |
1776 | /* | |
1777 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be | |
1778 | * ignored in *xmit_response() below | |
1779 | */ | |
1780 | if (qlt_has_data(cmd)) { | |
1781 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || | |
1782 | (IS_FWI2_CAPABLE(ha) && | |
1783 | (prm->rq_result != 0))) { | |
1784 | prm->add_status_pkt = 1; | |
1785 | (*full_req_cnt)++; | |
1786 | } | |
1787 | } | |
1788 | } | |
1789 | ||
2d70c103 NB |
1790 | return 0; |
1791 | } | |
1792 | ||
1793 | static inline int qlt_need_explicit_conf(struct qla_hw_data *ha, | |
1794 | struct qla_tgt_cmd *cmd, int sending_sense) | |
1795 | { | |
1796 | if (ha->tgt.enable_class_2) | |
1797 | return 0; | |
1798 | ||
1799 | if (sending_sense) | |
1800 | return cmd->conf_compl_supported; | |
1801 | else | |
1802 | return ha->tgt.enable_explicit_conf && | |
1803 | cmd->conf_compl_supported; | |
1804 | } | |
1805 | ||
1806 | #ifdef CONFIG_QLA_TGT_DEBUG_SRR | |
1807 | /* | |
1808 | * Original taken from the XFS code | |
1809 | */ | |
1810 | static unsigned long qlt_srr_random(void) | |
1811 | { | |
1812 | static int Inited; | |
1813 | static unsigned long RandomValue; | |
1814 | static DEFINE_SPINLOCK(lock); | |
1815 | /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */ | |
1816 | register long rv; | |
1817 | register long lo; | |
1818 | register long hi; | |
1819 | unsigned long flags; | |
1820 | ||
1821 | spin_lock_irqsave(&lock, flags); | |
1822 | if (!Inited) { | |
1823 | RandomValue = jiffies; | |
1824 | Inited = 1; | |
1825 | } | |
1826 | rv = RandomValue; | |
1827 | hi = rv / 127773; | |
1828 | lo = rv % 127773; | |
1829 | rv = 16807 * lo - 2836 * hi; | |
1830 | if (rv <= 0) | |
1831 | rv += 2147483647; | |
1832 | RandomValue = rv; | |
1833 | spin_unlock_irqrestore(&lock, flags); | |
1834 | return rv; | |
1835 | } | |
1836 | ||
1837 | static void qlt_check_srr_debug(struct qla_tgt_cmd *cmd, int *xmit_type) | |
1838 | { | |
1839 | #if 0 /* This is not a real status packets lost, so it won't lead to SRR */ | |
1840 | if ((*xmit_type & QLA_TGT_XMIT_STATUS) && (qlt_srr_random() % 200) | |
1841 | == 50) { | |
1842 | *xmit_type &= ~QLA_TGT_XMIT_STATUS; | |
1843 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf015, | |
649ee054 | 1844 | "Dropping cmd %p (tag %d) status", cmd, se_cmd->tag); |
2d70c103 NB |
1845 | } |
1846 | #endif | |
1847 | /* | |
1848 | * It's currently not possible to simulate SRRs for FCP_WRITE without | |
1849 | * a physical link layer failure, so don't even try here.. | |
1850 | */ | |
1851 | if (cmd->dma_data_direction != DMA_FROM_DEVICE) | |
1852 | return; | |
1853 | ||
1854 | if (qlt_has_data(cmd) && (cmd->sg_cnt > 1) && | |
1855 | ((qlt_srr_random() % 100) == 20)) { | |
1856 | int i, leave = 0; | |
1857 | unsigned int tot_len = 0; | |
1858 | ||
1859 | while (leave == 0) | |
1860 | leave = qlt_srr_random() % cmd->sg_cnt; | |
1861 | ||
1862 | for (i = 0; i < leave; i++) | |
1863 | tot_len += cmd->sg[i].length; | |
1864 | ||
1865 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf016, | |
1866 | "Cutting cmd %p (tag %d) buffer" | |
1867 | " tail to len %d, sg_cnt %d (cmd->bufflen %d," | |
649ee054 | 1868 | " cmd->sg_cnt %d)", cmd, se_cmd->tag, tot_len, leave, |
2d70c103 NB |
1869 | cmd->bufflen, cmd->sg_cnt); |
1870 | ||
1871 | cmd->bufflen = tot_len; | |
1872 | cmd->sg_cnt = leave; | |
1873 | } | |
1874 | ||
1875 | if (qlt_has_data(cmd) && ((qlt_srr_random() % 100) == 70)) { | |
1876 | unsigned int offset = qlt_srr_random() % cmd->bufflen; | |
1877 | ||
1878 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf017, | |
1879 | "Cutting cmd %p (tag %d) buffer head " | |
649ee054 | 1880 | "to offset %d (cmd->bufflen %d)", cmd, se_cmd->tag, offset, |
2d70c103 NB |
1881 | cmd->bufflen); |
1882 | if (offset == 0) | |
1883 | *xmit_type &= ~QLA_TGT_XMIT_DATA; | |
1884 | else if (qlt_set_data_offset(cmd, offset)) { | |
1885 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf018, | |
649ee054 | 1886 | "qlt_set_data_offset() failed (tag %d)", se_cmd->tag); |
2d70c103 NB |
1887 | } |
1888 | } | |
1889 | } | |
1890 | #else | |
1891 | static inline void qlt_check_srr_debug(struct qla_tgt_cmd *cmd, int *xmit_type) | |
1892 | {} | |
1893 | #endif | |
1894 | ||
1895 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, | |
1896 | struct qla_tgt_prm *prm) | |
1897 | { | |
1898 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, | |
1899 | (uint32_t)sizeof(ctio->u.status1.sense_data)); | |
1900 | ctio->u.status0.flags |= | |
1901 | __constant_cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); | |
1902 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 0)) { | |
1903 | ctio->u.status0.flags |= __constant_cpu_to_le16( | |
1904 | CTIO7_FLAGS_EXPLICIT_CONFORM | | |
1905 | CTIO7_FLAGS_CONFORM_REQ); | |
1906 | } | |
1907 | ctio->u.status0.residual = cpu_to_le32(prm->residual); | |
1908 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); | |
1909 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { | |
1910 | int i; | |
1911 | ||
1912 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 1)) { | |
1913 | if (prm->cmd->se_cmd.scsi_status != 0) { | |
1914 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe017, | |
1915 | "Skipping EXPLICIT_CONFORM and " | |
1916 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " | |
1917 | "non GOOD status\n"); | |
1918 | goto skip_explict_conf; | |
1919 | } | |
1920 | ctio->u.status1.flags |= __constant_cpu_to_le16( | |
1921 | CTIO7_FLAGS_EXPLICIT_CONFORM | | |
1922 | CTIO7_FLAGS_CONFORM_REQ); | |
1923 | } | |
1924 | skip_explict_conf: | |
1925 | ctio->u.status1.flags &= | |
1926 | ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); | |
1927 | ctio->u.status1.flags |= | |
1928 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); | |
1929 | ctio->u.status1.scsi_status |= | |
1930 | __constant_cpu_to_le16(SS_SENSE_LEN_VALID); | |
1931 | ctio->u.status1.sense_length = | |
1932 | cpu_to_le16(prm->sense_buffer_len); | |
1933 | for (i = 0; i < prm->sense_buffer_len/4; i++) | |
1934 | ((uint32_t *)ctio->u.status1.sense_data)[i] = | |
1935 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); | |
1936 | #if 0 | |
1937 | if (unlikely((prm->sense_buffer_len % 4) != 0)) { | |
1938 | static int q; | |
1939 | if (q < 10) { | |
1940 | ql_dbg(ql_dbg_tgt, vha, 0xe04f, | |
1941 | "qla_target(%d): %d bytes of sense " | |
1942 | "lost", prm->tgt->ha->vp_idx, | |
1943 | prm->sense_buffer_len % 4); | |
1944 | q++; | |
1945 | } | |
1946 | } | |
1947 | #endif | |
1948 | } else { | |
1949 | ctio->u.status1.flags &= | |
1950 | ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); | |
1951 | ctio->u.status1.flags |= | |
1952 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); | |
1953 | ctio->u.status1.sense_length = 0; | |
1954 | memset(ctio->u.status1.sense_data, 0, | |
1955 | sizeof(ctio->u.status1.sense_data)); | |
1956 | } | |
1957 | ||
1958 | /* Sense with len > 24, is it possible ??? */ | |
1959 | } | |
1960 | ||
f83adb61 QT |
1961 | |
1962 | ||
1963 | /* diff */ | |
1964 | static inline int | |
1965 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) | |
1966 | { | |
1967 | /* | |
1968 | * Uncomment when corresponding SCSI changes are done. | |
1969 | * | |
1970 | if (!sp->cmd->prot_chk) | |
1971 | return 0; | |
1972 | * | |
1973 | */ | |
1974 | switch (se_cmd->prot_op) { | |
1975 | case TARGET_PROT_DOUT_INSERT: | |
1976 | case TARGET_PROT_DIN_STRIP: | |
1977 | if (ql2xenablehba_err_chk >= 1) | |
1978 | return 1; | |
1979 | break; | |
1980 | case TARGET_PROT_DOUT_PASS: | |
1981 | case TARGET_PROT_DIN_PASS: | |
1982 | if (ql2xenablehba_err_chk >= 2) | |
1983 | return 1; | |
1984 | break; | |
1985 | case TARGET_PROT_DIN_INSERT: | |
1986 | case TARGET_PROT_DOUT_STRIP: | |
1987 | return 1; | |
1988 | default: | |
1989 | break; | |
1990 | } | |
1991 | return 0; | |
1992 | } | |
1993 | ||
1994 | /* | |
1995 | * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command | |
1996 | * | |
1997 | */ | |
1998 | static inline void | |
1999 | qlt_set_t10dif_tags(struct se_cmd *se_cmd, struct crc_context *ctx) | |
2000 | { | |
2001 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; | |
2002 | ||
2003 | /* wait til Mode Sense/Select cmd, modepage Ah, subpage 2 | |
2004 | * have been immplemented by TCM, before AppTag is avail. | |
2005 | * Look for modesense_handlers[] | |
2006 | */ | |
c7ee3bd4 | 2007 | ctx->app_tag = 0; |
f83adb61 QT |
2008 | ctx->app_tag_mask[0] = 0x0; |
2009 | ctx->app_tag_mask[1] = 0x0; | |
2010 | ||
2011 | switch (se_cmd->prot_type) { | |
2012 | case TARGET_DIF_TYPE0_PROT: | |
2013 | /* | |
2014 | * No check for ql2xenablehba_err_chk, as it would be an | |
2015 | * I/O error if hba tag generation is not done. | |
2016 | */ | |
2017 | ctx->ref_tag = cpu_to_le32(lba); | |
2018 | ||
2019 | if (!qlt_hba_err_chk_enabled(se_cmd)) | |
2020 | break; | |
2021 | ||
2022 | /* enable ALL bytes of the ref tag */ | |
2023 | ctx->ref_tag_mask[0] = 0xff; | |
2024 | ctx->ref_tag_mask[1] = 0xff; | |
2025 | ctx->ref_tag_mask[2] = 0xff; | |
2026 | ctx->ref_tag_mask[3] = 0xff; | |
2027 | break; | |
2028 | /* | |
2029 | * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and | |
2030 | * 16 bit app tag. | |
2031 | */ | |
2032 | case TARGET_DIF_TYPE1_PROT: | |
2033 | ctx->ref_tag = cpu_to_le32(lba); | |
2034 | ||
2035 | if (!qlt_hba_err_chk_enabled(se_cmd)) | |
2036 | break; | |
2037 | ||
2038 | /* enable ALL bytes of the ref tag */ | |
2039 | ctx->ref_tag_mask[0] = 0xff; | |
2040 | ctx->ref_tag_mask[1] = 0xff; | |
2041 | ctx->ref_tag_mask[2] = 0xff; | |
2042 | ctx->ref_tag_mask[3] = 0xff; | |
2043 | break; | |
2044 | /* | |
2045 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to | |
2046 | * match LBA in CDB + N | |
2047 | */ | |
2048 | case TARGET_DIF_TYPE2_PROT: | |
2049 | ctx->ref_tag = cpu_to_le32(lba); | |
2050 | ||
2051 | if (!qlt_hba_err_chk_enabled(se_cmd)) | |
2052 | break; | |
2053 | ||
2054 | /* enable ALL bytes of the ref tag */ | |
2055 | ctx->ref_tag_mask[0] = 0xff; | |
2056 | ctx->ref_tag_mask[1] = 0xff; | |
2057 | ctx->ref_tag_mask[2] = 0xff; | |
2058 | ctx->ref_tag_mask[3] = 0xff; | |
2059 | break; | |
2060 | ||
2061 | /* For Type 3 protection: 16 bit GUARD only */ | |
2062 | case TARGET_DIF_TYPE3_PROT: | |
2063 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = | |
2064 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; | |
2065 | break; | |
2066 | } | |
2067 | } | |
2068 | ||
2069 | ||
2070 | static inline int | |
2071 | qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) | |
2072 | { | |
2073 | uint32_t *cur_dsd; | |
2074 | int sgc; | |
2075 | uint32_t transfer_length = 0; | |
2076 | uint32_t data_bytes; | |
2077 | uint32_t dif_bytes; | |
2078 | uint8_t bundling = 1; | |
2079 | uint8_t *clr_ptr; | |
2080 | struct crc_context *crc_ctx_pkt = NULL; | |
2081 | struct qla_hw_data *ha; | |
2082 | struct ctio_crc2_to_fw *pkt; | |
2083 | dma_addr_t crc_ctx_dma; | |
2084 | uint16_t fw_prot_opts = 0; | |
2085 | struct qla_tgt_cmd *cmd = prm->cmd; | |
2086 | struct se_cmd *se_cmd = &cmd->se_cmd; | |
2087 | uint32_t h; | |
2088 | struct atio_from_isp *atio = &prm->cmd->atio; | |
c7ee3bd4 | 2089 | uint16_t t16; |
f83adb61 QT |
2090 | |
2091 | sgc = 0; | |
2092 | ha = vha->hw; | |
2093 | ||
2094 | pkt = (struct ctio_crc2_to_fw *)vha->req->ring_ptr; | |
2095 | prm->pkt = pkt; | |
2096 | memset(pkt, 0, sizeof(*pkt)); | |
2097 | ||
2098 | ql_dbg(ql_dbg_tgt, vha, 0xe071, | |
2099 | "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n", | |
2100 | vha->vp_idx, __func__, se_cmd, se_cmd->prot_op, | |
2101 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); | |
2102 | ||
2103 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || | |
2104 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) | |
2105 | bundling = 0; | |
2106 | ||
2107 | /* Compute dif len and adjust data len to incude protection */ | |
2108 | data_bytes = cmd->bufflen; | |
2109 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; | |
2110 | ||
2111 | switch (se_cmd->prot_op) { | |
2112 | case TARGET_PROT_DIN_INSERT: | |
2113 | case TARGET_PROT_DOUT_STRIP: | |
2114 | transfer_length = data_bytes; | |
2115 | data_bytes += dif_bytes; | |
2116 | break; | |
2117 | ||
2118 | case TARGET_PROT_DIN_STRIP: | |
2119 | case TARGET_PROT_DOUT_INSERT: | |
2120 | case TARGET_PROT_DIN_PASS: | |
2121 | case TARGET_PROT_DOUT_PASS: | |
2122 | transfer_length = data_bytes + dif_bytes; | |
2123 | break; | |
2124 | ||
2125 | default: | |
2126 | BUG(); | |
2127 | break; | |
2128 | } | |
2129 | ||
2130 | if (!qlt_hba_err_chk_enabled(se_cmd)) | |
2131 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ | |
2132 | /* HBA error checking enabled */ | |
2133 | else if (IS_PI_UNINIT_CAPABLE(ha)) { | |
2134 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || | |
2135 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) | |
2136 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; | |
2137 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) | |
2138 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; | |
2139 | } | |
2140 | ||
2141 | switch (se_cmd->prot_op) { | |
2142 | case TARGET_PROT_DIN_INSERT: | |
2143 | case TARGET_PROT_DOUT_INSERT: | |
2144 | fw_prot_opts |= PO_MODE_DIF_INSERT; | |
2145 | break; | |
2146 | case TARGET_PROT_DIN_STRIP: | |
2147 | case TARGET_PROT_DOUT_STRIP: | |
2148 | fw_prot_opts |= PO_MODE_DIF_REMOVE; | |
2149 | break; | |
2150 | case TARGET_PROT_DIN_PASS: | |
2151 | case TARGET_PROT_DOUT_PASS: | |
2152 | fw_prot_opts |= PO_MODE_DIF_PASS; | |
2153 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ | |
2154 | break; | |
2155 | default:/* Normal Request */ | |
2156 | fw_prot_opts |= PO_MODE_DIF_PASS; | |
2157 | break; | |
2158 | } | |
2159 | ||
2160 | ||
2161 | /* ---- PKT ---- */ | |
2162 | /* Update entry type to indicate Command Type CRC_2 IOCB */ | |
2163 | pkt->entry_type = CTIO_CRC2; | |
2164 | pkt->entry_count = 1; | |
2165 | pkt->vp_index = vha->vp_idx; | |
2166 | ||
2167 | h = qlt_make_handle(vha); | |
2168 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { | |
2169 | /* | |
2170 | * CTIO type 7 from the firmware doesn't provide a way to | |
2171 | * know the initiator's LOOP ID, hence we can't find | |
2172 | * the session and, so, the command. | |
2173 | */ | |
2174 | return -EAGAIN; | |
2175 | } else | |
2176 | ha->tgt.cmds[h-1] = prm->cmd; | |
2177 | ||
2178 | ||
2179 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; | |
2180 | pkt->nport_handle = prm->cmd->loop_id; | |
2181 | pkt->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | |
2182 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | |
2183 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | |
2184 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | |
2185 | pkt->exchange_addr = atio->u.isp24.exchange_addr; | |
c7ee3bd4 QT |
2186 | |
2187 | /* silence compile warning */ | |
2188 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); | |
2189 | pkt->ox_id = cpu_to_le16(t16); | |
2190 | ||
2191 | t16 = (atio->u.isp24.attr << 9); | |
2192 | pkt->flags |= cpu_to_le16(t16); | |
f83adb61 QT |
2193 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
2194 | ||
2195 | /* Set transfer direction */ | |
2196 | if (cmd->dma_data_direction == DMA_TO_DEVICE) | |
2197 | pkt->flags = __constant_cpu_to_le16(CTIO7_FLAGS_DATA_IN); | |
2198 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) | |
2199 | pkt->flags = __constant_cpu_to_le16(CTIO7_FLAGS_DATA_OUT); | |
2200 | ||
2201 | ||
2202 | pkt->dseg_count = prm->tot_dsds; | |
2203 | /* Fibre channel byte count */ | |
2204 | pkt->transfer_length = cpu_to_le32(transfer_length); | |
2205 | ||
2206 | ||
2207 | /* ----- CRC context -------- */ | |
2208 | ||
2209 | /* Allocate CRC context from global pool */ | |
2210 | crc_ctx_pkt = cmd->ctx = | |
2211 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); | |
2212 | ||
2213 | if (!crc_ctx_pkt) | |
2214 | goto crc_queuing_error; | |
2215 | ||
2216 | /* Zero out CTX area. */ | |
2217 | clr_ptr = (uint8_t *)crc_ctx_pkt; | |
2218 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); | |
2219 | ||
2220 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; | |
2221 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); | |
2222 | ||
2223 | /* Set handle */ | |
2224 | crc_ctx_pkt->handle = pkt->handle; | |
2225 | ||
2226 | qlt_set_t10dif_tags(se_cmd, crc_ctx_pkt); | |
2227 | ||
2228 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); | |
2229 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); | |
2230 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; | |
2231 | ||
2232 | ||
2233 | if (!bundling) { | |
2234 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; | |
2235 | } else { | |
2236 | /* | |
2237 | * Configure Bundling if we need to fetch interlaving | |
2238 | * protection PCI accesses | |
2239 | */ | |
2240 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; | |
2241 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); | |
2242 | crc_ctx_pkt->u.bundling.dseg_count = | |
2243 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); | |
2244 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; | |
2245 | } | |
2246 | ||
2247 | /* Finish the common fields of CRC pkt */ | |
2248 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); | |
2249 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); | |
2250 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); | |
2251 | crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0); | |
2252 | ||
2253 | ||
2254 | /* Walks data segments */ | |
2255 | pkt->flags |= __constant_cpu_to_le16(CTIO7_FLAGS_DSD_PTR); | |
2256 | ||
2257 | if (!bundling && prm->prot_seg_cnt) { | |
2258 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, | |
2259 | prm->tot_dsds, cmd)) | |
2260 | goto crc_queuing_error; | |
2261 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, | |
2262 | (prm->tot_dsds - prm->prot_seg_cnt), cmd)) | |
2263 | goto crc_queuing_error; | |
2264 | ||
2265 | if (bundling && prm->prot_seg_cnt) { | |
2266 | /* Walks dif segments */ | |
c7ee3bd4 | 2267 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
f83adb61 QT |
2268 | |
2269 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; | |
2270 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, | |
2271 | prm->prot_seg_cnt, cmd)) | |
2272 | goto crc_queuing_error; | |
2273 | } | |
2274 | return QLA_SUCCESS; | |
2275 | ||
2276 | crc_queuing_error: | |
2277 | /* Cleanup will be performed by the caller */ | |
2278 | ||
2279 | return QLA_FUNCTION_FAILED; | |
2280 | } | |
2281 | ||
2282 | ||
2d70c103 NB |
2283 | /* |
2284 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * | |
2285 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon | |
2286 | */ | |
2287 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, | |
2288 | uint8_t scsi_status) | |
2289 | { | |
2290 | struct scsi_qla_host *vha = cmd->vha; | |
2291 | struct qla_hw_data *ha = vha->hw; | |
2292 | struct ctio7_to_24xx *pkt; | |
2293 | struct qla_tgt_prm prm; | |
2294 | uint32_t full_req_cnt = 0; | |
2295 | unsigned long flags = 0; | |
2296 | int res; | |
2297 | ||
2298 | memset(&prm, 0, sizeof(prm)); | |
2299 | qlt_check_srr_debug(cmd, &xmit_type); | |
2300 | ||
2301 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe018, | |
f83adb61 QT |
2302 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p]\n", |
2303 | (xmit_type & QLA_TGT_XMIT_STATUS) ? | |
2304 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, | |
2305 | &cmd->se_cmd); | |
2d70c103 NB |
2306 | |
2307 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, | |
2308 | &full_req_cnt); | |
2309 | if (unlikely(res != 0)) { | |
2310 | if (res == QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED) | |
2311 | return 0; | |
2312 | ||
2313 | return res; | |
2314 | } | |
2315 | ||
2316 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
2317 | ||
b6a029e1 AE |
2318 | if (qla2x00_reset_active(vha) || cmd->reset_count != ha->chip_reset) { |
2319 | /* | |
2320 | * Either a chip reset is active or this request was from | |
2321 | * previous life, just abort the processing. | |
2322 | */ | |
2323 | cmd->state = QLA_TGT_STATE_PROCESSED; | |
2324 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); | |
2325 | ql_dbg(ql_dbg_async, vha, 0xe101, | |
2326 | "RESET-RSP active/old-count/new-count = %d/%d/%d.\n", | |
2327 | qla2x00_reset_active(vha), cmd->reset_count, | |
2328 | ha->chip_reset); | |
2329 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2330 | return 0; | |
2331 | } | |
2332 | ||
2d70c103 NB |
2333 | /* Does F/W have an IOCBs for this request */ |
2334 | res = qlt_check_reserve_free_req(vha, full_req_cnt); | |
2335 | if (unlikely(res)) | |
2336 | goto out_unmap_unlock; | |
2337 | ||
f83adb61 QT |
2338 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
2339 | res = qlt_build_ctio_crc2_pkt(&prm, vha); | |
2340 | else | |
2341 | res = qlt_24xx_build_ctio_pkt(&prm, vha); | |
810e30bc QT |
2342 | if (unlikely(res != 0)) { |
2343 | vha->req->cnt += full_req_cnt; | |
2d70c103 | 2344 | goto out_unmap_unlock; |
810e30bc | 2345 | } |
2d70c103 NB |
2346 | |
2347 | pkt = (struct ctio7_to_24xx *)prm.pkt; | |
2348 | ||
2349 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { | |
2350 | pkt->u.status0.flags |= | |
2351 | __constant_cpu_to_le16(CTIO7_FLAGS_DATA_IN | | |
2352 | CTIO7_FLAGS_STATUS_MODE_0); | |
2353 | ||
f83adb61 QT |
2354 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
2355 | qlt_load_data_segments(&prm, vha); | |
2d70c103 NB |
2356 | |
2357 | if (prm.add_status_pkt == 0) { | |
2358 | if (xmit_type & QLA_TGT_XMIT_STATUS) { | |
2359 | pkt->u.status0.scsi_status = | |
2360 | cpu_to_le16(prm.rq_result); | |
2361 | pkt->u.status0.residual = | |
2362 | cpu_to_le32(prm.residual); | |
2363 | pkt->u.status0.flags |= __constant_cpu_to_le16( | |
2364 | CTIO7_FLAGS_SEND_STATUS); | |
2365 | if (qlt_need_explicit_conf(ha, cmd, 0)) { | |
2366 | pkt->u.status0.flags |= | |
2367 | __constant_cpu_to_le16( | |
2368 | CTIO7_FLAGS_EXPLICIT_CONFORM | | |
2369 | CTIO7_FLAGS_CONFORM_REQ); | |
2370 | } | |
2371 | } | |
2372 | ||
2373 | } else { | |
2374 | /* | |
2375 | * We have already made sure that there is sufficient | |
2376 | * amount of request entries to not drop HW lock in | |
2377 | * req_pkt(). | |
2378 | */ | |
2379 | struct ctio7_to_24xx *ctio = | |
2380 | (struct ctio7_to_24xx *)qlt_get_req_pkt(vha); | |
2381 | ||
667024a3 AE |
2382 | ql_dbg(ql_dbg_io, vha, 0x305e, |
2383 | "Building additional status packet 0x%p.\n", | |
2384 | ctio); | |
2d70c103 | 2385 | |
f83adb61 QT |
2386 | /* |
2387 | * T10Dif: ctio_crc2_to_fw overlay ontop of | |
2388 | * ctio7_to_24xx | |
2389 | */ | |
2d70c103 | 2390 | memcpy(ctio, pkt, sizeof(*ctio)); |
f83adb61 | 2391 | /* reset back to CTIO7 */ |
2d70c103 | 2392 | ctio->entry_count = 1; |
f83adb61 | 2393 | ctio->entry_type = CTIO_TYPE7; |
2d70c103 NB |
2394 | ctio->dseg_count = 0; |
2395 | ctio->u.status1.flags &= ~__constant_cpu_to_le16( | |
2396 | CTIO7_FLAGS_DATA_IN); | |
2397 | ||
2398 | /* Real finish is ctio_m1's finish */ | |
2399 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; | |
2400 | pkt->u.status0.flags |= __constant_cpu_to_le16( | |
2401 | CTIO7_FLAGS_DONT_RET_CTIO); | |
f83adb61 QT |
2402 | |
2403 | /* qlt_24xx_init_ctio_to_isp will correct | |
2404 | * all neccessary fields that's part of CTIO7. | |
2405 | * There should be no residual of CTIO-CRC2 data. | |
2406 | */ | |
2d70c103 NB |
2407 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
2408 | &prm); | |
2409 | pr_debug("Status CTIO7: %p\n", ctio); | |
2410 | } | |
2411 | } else | |
2412 | qlt_24xx_init_ctio_to_isp(pkt, &prm); | |
2413 | ||
2414 | ||
2415 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ | |
d564a372 | 2416 | cmd->cmd_sent_to_fw = 1; |
2d70c103 | 2417 | |
63163e06 HM |
2418 | /* Memory Barrier */ |
2419 | wmb(); | |
2d70c103 NB |
2420 | qla2x00_start_iocbs(vha, vha->req); |
2421 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2422 | ||
2423 | return 0; | |
2424 | ||
2425 | out_unmap_unlock: | |
f9b6721a | 2426 | qlt_unmap_sg(vha, cmd); |
2d70c103 NB |
2427 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2428 | ||
2429 | return res; | |
2430 | } | |
2431 | EXPORT_SYMBOL(qlt_xmit_response); | |
2432 | ||
2433 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) | |
2434 | { | |
2435 | struct ctio7_to_24xx *pkt; | |
2436 | struct scsi_qla_host *vha = cmd->vha; | |
2437 | struct qla_hw_data *ha = vha->hw; | |
2438 | struct qla_tgt *tgt = cmd->tgt; | |
2439 | struct qla_tgt_prm prm; | |
2440 | unsigned long flags; | |
2441 | int res = 0; | |
2442 | ||
2443 | memset(&prm, 0, sizeof(prm)); | |
2444 | prm.cmd = cmd; | |
2445 | prm.tgt = tgt; | |
2446 | prm.sg = NULL; | |
2447 | prm.req_cnt = 1; | |
2448 | ||
2449 | /* Send marker if required */ | |
2450 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) | |
2451 | return -EIO; | |
2452 | ||
2d70c103 NB |
2453 | /* Calculate number of entries and segments required */ |
2454 | if (qlt_pci_map_calc_cnt(&prm) != 0) | |
2455 | return -EAGAIN; | |
2456 | ||
2457 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
2458 | ||
b6a029e1 AE |
2459 | if (qla2x00_reset_active(vha) || cmd->reset_count != ha->chip_reset) { |
2460 | /* | |
2461 | * Either a chip reset is active or this request was from | |
2462 | * previous life, just abort the processing. | |
2463 | */ | |
2464 | cmd->state = QLA_TGT_STATE_NEED_DATA; | |
2465 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); | |
2466 | ql_dbg(ql_dbg_async, vha, 0xe102, | |
2467 | "RESET-XFR active/old-count/new-count = %d/%d/%d.\n", | |
2468 | qla2x00_reset_active(vha), cmd->reset_count, | |
2469 | ha->chip_reset); | |
2470 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2471 | return 0; | |
2472 | } | |
2473 | ||
2d70c103 NB |
2474 | /* Does F/W have an IOCBs for this request */ |
2475 | res = qlt_check_reserve_free_req(vha, prm.req_cnt); | |
2476 | if (res != 0) | |
2477 | goto out_unlock_free_unmap; | |
f83adb61 QT |
2478 | if (cmd->se_cmd.prot_op) |
2479 | res = qlt_build_ctio_crc2_pkt(&prm, vha); | |
2480 | else | |
2481 | res = qlt_24xx_build_ctio_pkt(&prm, vha); | |
2d70c103 | 2482 | |
810e30bc QT |
2483 | if (unlikely(res != 0)) { |
2484 | vha->req->cnt += prm.req_cnt; | |
2d70c103 | 2485 | goto out_unlock_free_unmap; |
810e30bc QT |
2486 | } |
2487 | ||
2d70c103 NB |
2488 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
2489 | pkt->u.status0.flags |= __constant_cpu_to_le16(CTIO7_FLAGS_DATA_OUT | | |
2490 | CTIO7_FLAGS_STATUS_MODE_0); | |
f83adb61 QT |
2491 | |
2492 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) | |
2493 | qlt_load_data_segments(&prm, vha); | |
2d70c103 NB |
2494 | |
2495 | cmd->state = QLA_TGT_STATE_NEED_DATA; | |
d564a372 | 2496 | cmd->cmd_sent_to_fw = 1; |
2d70c103 | 2497 | |
63163e06 HM |
2498 | /* Memory Barrier */ |
2499 | wmb(); | |
2d70c103 NB |
2500 | qla2x00_start_iocbs(vha, vha->req); |
2501 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2502 | ||
2503 | return res; | |
2504 | ||
2505 | out_unlock_free_unmap: | |
f9b6721a | 2506 | qlt_unmap_sg(vha, cmd); |
2d70c103 NB |
2507 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2508 | ||
2509 | return res; | |
2510 | } | |
2511 | EXPORT_SYMBOL(qlt_rdy_to_xfer); | |
2512 | ||
f83adb61 QT |
2513 | |
2514 | /* | |
2515 | * Checks the guard or meta-data for the type of error | |
2516 | * detected by the HBA. | |
2517 | */ | |
2518 | static inline int | |
2519 | qlt_handle_dif_error(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd, | |
2520 | struct ctio_crc_from_fw *sts) | |
2521 | { | |
2522 | uint8_t *ap = &sts->actual_dif[0]; | |
2523 | uint8_t *ep = &sts->expected_dif[0]; | |
2524 | uint32_t e_ref_tag, a_ref_tag; | |
2525 | uint16_t e_app_tag, a_app_tag; | |
2526 | uint16_t e_guard, a_guard; | |
2527 | uint64_t lba = cmd->se_cmd.t_task_lba; | |
2528 | ||
2529 | a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); | |
2530 | a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); | |
2531 | a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); | |
2532 | ||
2533 | e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); | |
2534 | e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); | |
2535 | e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); | |
2536 | ||
2537 | ql_dbg(ql_dbg_tgt, vha, 0xe075, | |
2538 | "iocb(s) %p Returned STATUS.\n", sts); | |
2539 | ||
2540 | ql_dbg(ql_dbg_tgt, vha, 0xf075, | |
fc385045 | 2541 | "dif check TGT cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x]\n", |
f83adb61 QT |
2542 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
2543 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, a_guard, e_guard); | |
2544 | ||
2545 | /* | |
2546 | * Ignore sector if: | |
2547 | * For type 3: ref & app tag is all 'f's | |
2548 | * For type 0,1,2: app tag is all 'f's | |
2549 | */ | |
2550 | if ((a_app_tag == 0xffff) && | |
2551 | ((cmd->se_cmd.prot_type != TARGET_DIF_TYPE3_PROT) || | |
2552 | (a_ref_tag == 0xffffffff))) { | |
2553 | uint32_t blocks_done; | |
2554 | ||
2555 | /* 2TB boundary case covered automatically with this */ | |
2556 | blocks_done = e_ref_tag - (uint32_t)lba + 1; | |
2557 | cmd->se_cmd.bad_sector = e_ref_tag; | |
2558 | cmd->se_cmd.pi_err = 0; | |
2559 | ql_dbg(ql_dbg_tgt, vha, 0xf074, | |
2560 | "need to return scsi good\n"); | |
2561 | ||
2562 | /* Update protection tag */ | |
2563 | if (cmd->prot_sg_cnt) { | |
2564 | uint32_t i, j = 0, k = 0, num_ent; | |
2565 | struct scatterlist *sg, *sgl; | |
2566 | ||
2567 | ||
2568 | sgl = cmd->prot_sg; | |
2569 | ||
2570 | /* Patch the corresponding protection tags */ | |
2571 | for_each_sg(sgl, sg, cmd->prot_sg_cnt, i) { | |
2572 | num_ent = sg_dma_len(sg) / 8; | |
2573 | if (k + num_ent < blocks_done) { | |
2574 | k += num_ent; | |
2575 | continue; | |
2576 | } | |
2577 | j = blocks_done - k - 1; | |
2578 | k = blocks_done; | |
2579 | break; | |
2580 | } | |
2581 | ||
2582 | if (k != blocks_done) { | |
2583 | ql_log(ql_log_warn, vha, 0xf076, | |
2584 | "unexpected tag values tag:lba=%u:%llu)\n", | |
2585 | e_ref_tag, (unsigned long long)lba); | |
2586 | goto out; | |
2587 | } | |
2588 | ||
2589 | #if 0 | |
2590 | struct sd_dif_tuple *spt; | |
2591 | /* TODO: | |
2592 | * This section came from initiator. Is it valid here? | |
2593 | * should ulp be override with actual val??? | |
2594 | */ | |
2595 | spt = page_address(sg_page(sg)) + sg->offset; | |
2596 | spt += j; | |
2597 | ||
2598 | spt->app_tag = 0xffff; | |
2599 | if (cmd->se_cmd.prot_type == SCSI_PROT_DIF_TYPE3) | |
2600 | spt->ref_tag = 0xffffffff; | |
2601 | #endif | |
2602 | } | |
2603 | ||
2604 | return 0; | |
2605 | } | |
2606 | ||
2607 | /* check guard */ | |
2608 | if (e_guard != a_guard) { | |
2609 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED; | |
2610 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; | |
2611 | ||
2612 | ql_log(ql_log_warn, vha, 0xe076, | |
2613 | "Guard ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n", | |
2614 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, | |
2615 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, | |
2616 | a_guard, e_guard, cmd); | |
2617 | goto out; | |
2618 | } | |
2619 | ||
2620 | /* check ref tag */ | |
2621 | if (e_ref_tag != a_ref_tag) { | |
2622 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED; | |
2623 | cmd->se_cmd.bad_sector = e_ref_tag; | |
2624 | ||
2625 | ql_log(ql_log_warn, vha, 0xe077, | |
2626 | "Ref Tag ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n", | |
2627 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, | |
2628 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, | |
2629 | a_guard, e_guard, cmd); | |
2630 | goto out; | |
2631 | } | |
2632 | ||
2633 | /* check appl tag */ | |
2634 | if (e_app_tag != a_app_tag) { | |
2635 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED; | |
2636 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; | |
2637 | ||
2638 | ql_log(ql_log_warn, vha, 0xe078, | |
2639 | "App Tag ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n", | |
2640 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, | |
2641 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, | |
2642 | a_guard, e_guard, cmd); | |
2643 | goto out; | |
2644 | } | |
2645 | out: | |
2646 | return 1; | |
2647 | } | |
2648 | ||
2649 | ||
2d70c103 NB |
2650 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
2651 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ | |
2652 | static int __qlt_send_term_exchange(struct scsi_qla_host *vha, | |
2653 | struct qla_tgt_cmd *cmd, | |
2654 | struct atio_from_isp *atio) | |
2655 | { | |
2656 | struct ctio7_to_24xx *ctio24; | |
2657 | struct qla_hw_data *ha = vha->hw; | |
2658 | request_t *pkt; | |
2659 | int ret = 0; | |
33a5fcee | 2660 | uint16_t temp; |
2d70c103 NB |
2661 | |
2662 | ql_dbg(ql_dbg_tgt, vha, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha); | |
2663 | ||
b6a029e1 | 2664 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
2d70c103 NB |
2665 | if (pkt == NULL) { |
2666 | ql_dbg(ql_dbg_tgt, vha, 0xe050, | |
2667 | "qla_target(%d): %s failed: unable to allocate " | |
2668 | "request packet\n", vha->vp_idx, __func__); | |
2669 | return -ENOMEM; | |
2670 | } | |
2671 | ||
2672 | if (cmd != NULL) { | |
2673 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { | |
2674 | ql_dbg(ql_dbg_tgt, vha, 0xe051, | |
2675 | "qla_target(%d): Terminating cmd %p with " | |
2676 | "incorrect state %d\n", vha->vp_idx, cmd, | |
2677 | cmd->state); | |
2678 | } else | |
2679 | ret = 1; | |
2680 | } | |
2681 | ||
2682 | pkt->entry_count = 1; | |
2683 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | |
2684 | ||
2685 | ctio24 = (struct ctio7_to_24xx *)pkt; | |
2686 | ctio24->entry_type = CTIO_TYPE7; | |
2687 | ctio24->nport_handle = cmd ? cmd->loop_id : CTIO7_NHANDLE_UNRECOGNIZED; | |
2688 | ctio24->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | |
2689 | ctio24->vp_index = vha->vp_idx; | |
2690 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | |
2691 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | |
2692 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | |
2693 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; | |
2694 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | | |
2695 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | | |
2696 | CTIO7_FLAGS_TERMINATE); | |
33a5fcee QT |
2697 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
2698 | ctio24->u.status1.ox_id = cpu_to_le16(temp); | |
2d70c103 NB |
2699 | |
2700 | /* Most likely, it isn't needed */ | |
2701 | ctio24->u.status1.residual = get_unaligned((uint32_t *) | |
2702 | &atio->u.isp24.fcp_cmnd.add_cdb[ | |
2703 | atio->u.isp24.fcp_cmnd.add_cdb_len]); | |
2704 | if (ctio24->u.status1.residual != 0) | |
2705 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; | |
2706 | ||
63163e06 HM |
2707 | /* Memory Barrier */ |
2708 | wmb(); | |
2d70c103 NB |
2709 | qla2x00_start_iocbs(vha, vha->req); |
2710 | return ret; | |
2711 | } | |
2712 | ||
2713 | static void qlt_send_term_exchange(struct scsi_qla_host *vha, | |
2714 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked) | |
2715 | { | |
2716 | unsigned long flags; | |
2717 | int rc; | |
2718 | ||
2719 | if (qlt_issue_marker(vha, ha_locked) < 0) | |
2720 | return; | |
2721 | ||
2722 | if (ha_locked) { | |
2723 | rc = __qlt_send_term_exchange(vha, cmd, atio); | |
33e79977 QT |
2724 | if (rc == -ENOMEM) |
2725 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); | |
2d70c103 NB |
2726 | goto done; |
2727 | } | |
2728 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); | |
2729 | rc = __qlt_send_term_exchange(vha, cmd, atio); | |
33e79977 QT |
2730 | if (rc == -ENOMEM) |
2731 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); | |
2d70c103 | 2732 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
d564a372 | 2733 | |
2d70c103 | 2734 | done: |
d564a372 QT |
2735 | if (cmd && ((cmd->state != QLA_TGT_STATE_ABORTED) || |
2736 | !cmd->cmd_sent_to_fw)) { | |
2d70c103 NB |
2737 | if (!ha_locked && !in_interrupt()) |
2738 | msleep(250); /* just in case */ | |
2739 | ||
f9b6721a | 2740 | qlt_unmap_sg(vha, cmd); |
2d70c103 NB |
2741 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
2742 | } | |
7b898542 | 2743 | return; |
2d70c103 NB |
2744 | } |
2745 | ||
33e79977 QT |
2746 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
2747 | { | |
2748 | struct list_head free_list; | |
2749 | struct qla_tgt_cmd *cmd, *tcmd; | |
2750 | ||
2751 | vha->hw->tgt.leak_exchg_thresh_hold = | |
2752 | (vha->hw->fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; | |
2753 | ||
2754 | cmd = tcmd = NULL; | |
2755 | if (!list_empty(&vha->hw->tgt.q_full_list)) { | |
2756 | INIT_LIST_HEAD(&free_list); | |
2757 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); | |
2758 | ||
2759 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { | |
2760 | list_del(&cmd->cmd_list); | |
2761 | /* This cmd was never sent to TCM. There is no need | |
2762 | * to schedule free or call free_cmd | |
2763 | */ | |
2764 | qlt_free_cmd(cmd); | |
2765 | vha->hw->tgt.num_qfull_cmds_alloc--; | |
2766 | } | |
2767 | } | |
2768 | vha->hw->tgt.num_qfull_cmds_dropped = 0; | |
2769 | } | |
2770 | ||
2771 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) | |
2772 | { | |
2773 | uint32_t total_leaked; | |
2774 | ||
2775 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; | |
2776 | ||
2777 | if (vha->hw->tgt.leak_exchg_thresh_hold && | |
2778 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { | |
2779 | ||
2780 | ql_dbg(ql_dbg_tgt, vha, 0xe079, | |
2781 | "Chip reset due to exchange starvation: %d/%d.\n", | |
2782 | total_leaked, vha->hw->fw_xcb_count); | |
2783 | ||
2784 | if (IS_P3P_TYPE(vha->hw)) | |
2785 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); | |
2786 | else | |
2787 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
2788 | qla2xxx_wake_dpc(vha); | |
2789 | } | |
2790 | ||
2791 | } | |
2792 | ||
2d70c103 NB |
2793 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
2794 | { | |
51a07f84 NB |
2795 | struct qla_tgt_sess *sess = cmd->sess; |
2796 | ||
f83adb61 QT |
2797 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
2798 | "%s: se_cmd[%p] ox_id %04x\n", | |
2799 | __func__, &cmd->se_cmd, | |
2800 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); | |
2d70c103 | 2801 | |
e07f8f65 SK |
2802 | BUG_ON(cmd->cmd_in_wq); |
2803 | ||
33e79977 QT |
2804 | if (!cmd->q_full) |
2805 | qlt_decr_num_pend_cmds(cmd->vha); | |
2806 | ||
f83adb61 | 2807 | BUG_ON(cmd->sg_mapped); |
e07f8f65 | 2808 | cmd->jiffies_at_free = get_jiffies_64(); |
2d70c103 NB |
2809 | if (unlikely(cmd->free_sg)) |
2810 | kfree(cmd->sg); | |
51a07f84 NB |
2811 | |
2812 | if (!sess || !sess->se_sess) { | |
2813 | WARN_ON(1); | |
2814 | return; | |
2815 | } | |
e07f8f65 | 2816 | cmd->jiffies_at_free = get_jiffies_64(); |
51a07f84 | 2817 | percpu_ida_free(&sess->se_sess->sess_tag_pool, cmd->se_cmd.map_tag); |
2d70c103 NB |
2818 | } |
2819 | EXPORT_SYMBOL(qlt_free_cmd); | |
2820 | ||
2821 | /* ha->hardware_lock supposed to be held on entry */ | |
2822 | static int qlt_prepare_srr_ctio(struct scsi_qla_host *vha, | |
2823 | struct qla_tgt_cmd *cmd, void *ctio) | |
2824 | { | |
2825 | struct qla_tgt_srr_ctio *sc; | |
0e8cd71c | 2826 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
2827 | struct qla_tgt_srr_imm *imm; |
2828 | ||
2829 | tgt->ctio_srr_id++; | |
e07f8f65 | 2830 | cmd->cmd_flags |= BIT_15; |
2d70c103 NB |
2831 | |
2832 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, | |
2833 | "qla_target(%d): CTIO with SRR status received\n", vha->vp_idx); | |
2834 | ||
2835 | if (!ctio) { | |
2836 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf055, | |
2837 | "qla_target(%d): SRR CTIO, but ctio is NULL\n", | |
2838 | vha->vp_idx); | |
2839 | return -EINVAL; | |
2840 | } | |
2841 | ||
2842 | sc = kzalloc(sizeof(*sc), GFP_ATOMIC); | |
2843 | if (sc != NULL) { | |
2844 | sc->cmd = cmd; | |
2845 | /* IRQ is already OFF */ | |
2846 | spin_lock(&tgt->srr_lock); | |
2847 | sc->srr_id = tgt->ctio_srr_id; | |
2848 | list_add_tail(&sc->srr_list_entry, | |
2849 | &tgt->srr_ctio_list); | |
2850 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, | |
2851 | "CTIO SRR %p added (id %d)\n", sc, sc->srr_id); | |
2852 | if (tgt->imm_srr_id == tgt->ctio_srr_id) { | |
2853 | int found = 0; | |
2854 | list_for_each_entry(imm, &tgt->srr_imm_list, | |
2855 | srr_list_entry) { | |
2856 | if (imm->srr_id == sc->srr_id) { | |
2857 | found = 1; | |
2858 | break; | |
2859 | } | |
2860 | } | |
2861 | if (found) { | |
2862 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01b, | |
2863 | "Scheduling srr work\n"); | |
2864 | schedule_work(&tgt->srr_work); | |
2865 | } else { | |
2866 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf056, | |
2867 | "qla_target(%d): imm_srr_id " | |
2868 | "== ctio_srr_id (%d), but there is no " | |
2869 | "corresponding SRR IMM, deleting CTIO " | |
2870 | "SRR %p\n", vha->vp_idx, | |
2871 | tgt->ctio_srr_id, sc); | |
2872 | list_del(&sc->srr_list_entry); | |
2873 | spin_unlock(&tgt->srr_lock); | |
2874 | ||
2875 | kfree(sc); | |
2876 | return -EINVAL; | |
2877 | } | |
2878 | } | |
2879 | spin_unlock(&tgt->srr_lock); | |
2880 | } else { | |
2881 | struct qla_tgt_srr_imm *ti; | |
2882 | ||
2883 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf057, | |
2884 | "qla_target(%d): Unable to allocate SRR CTIO entry\n", | |
2885 | vha->vp_idx); | |
2886 | spin_lock(&tgt->srr_lock); | |
2887 | list_for_each_entry_safe(imm, ti, &tgt->srr_imm_list, | |
2888 | srr_list_entry) { | |
2889 | if (imm->srr_id == tgt->ctio_srr_id) { | |
2890 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01c, | |
2891 | "IMM SRR %p deleted (id %d)\n", | |
2892 | imm, imm->srr_id); | |
2893 | list_del(&imm->srr_list_entry); | |
2894 | qlt_reject_free_srr_imm(vha, imm, 1); | |
2895 | } | |
2896 | } | |
2897 | spin_unlock(&tgt->srr_lock); | |
2898 | ||
2899 | return -ENOMEM; | |
2900 | } | |
2901 | ||
2902 | return 0; | |
2903 | } | |
2904 | ||
2905 | /* | |
2906 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
2907 | */ | |
2908 | static int qlt_term_ctio_exchange(struct scsi_qla_host *vha, void *ctio, | |
2909 | struct qla_tgt_cmd *cmd, uint32_t status) | |
2910 | { | |
2911 | int term = 0; | |
2912 | ||
2913 | if (ctio != NULL) { | |
2914 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; | |
2915 | term = !(c->flags & | |
2916 | __constant_cpu_to_le16(OF_TERM_EXCH)); | |
2917 | } else | |
2918 | term = 1; | |
2919 | ||
2920 | if (term) | |
2921 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1); | |
2922 | ||
2923 | return term; | |
2924 | } | |
2925 | ||
2926 | /* ha->hardware_lock supposed to be held on entry */ | |
2927 | static inline struct qla_tgt_cmd *qlt_get_cmd(struct scsi_qla_host *vha, | |
2928 | uint32_t handle) | |
2929 | { | |
2930 | struct qla_hw_data *ha = vha->hw; | |
2931 | ||
2932 | handle--; | |
2933 | if (ha->tgt.cmds[handle] != NULL) { | |
2934 | struct qla_tgt_cmd *cmd = ha->tgt.cmds[handle]; | |
2935 | ha->tgt.cmds[handle] = NULL; | |
2936 | return cmd; | |
2937 | } else | |
2938 | return NULL; | |
2939 | } | |
2940 | ||
2941 | /* ha->hardware_lock supposed to be held on entry */ | |
2942 | static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha, | |
2943 | uint32_t handle, void *ctio) | |
2944 | { | |
2945 | struct qla_tgt_cmd *cmd = NULL; | |
2946 | ||
2947 | /* Clear out internal marks */ | |
2948 | handle &= ~(CTIO_COMPLETION_HANDLE_MARK | | |
2949 | CTIO_INTERMEDIATE_HANDLE_MARK); | |
2950 | ||
2951 | if (handle != QLA_TGT_NULL_HANDLE) { | |
667024a3 | 2952 | if (unlikely(handle == QLA_TGT_SKIP_HANDLE)) |
2d70c103 | 2953 | return NULL; |
667024a3 | 2954 | |
2d70c103 | 2955 | /* handle-1 is actually used */ |
8d93f550 | 2956 | if (unlikely(handle > DEFAULT_OUTSTANDING_COMMANDS)) { |
2d70c103 NB |
2957 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
2958 | "qla_target(%d): Wrong handle %x received\n", | |
2959 | vha->vp_idx, handle); | |
2960 | return NULL; | |
2961 | } | |
2962 | cmd = qlt_get_cmd(vha, handle); | |
2963 | if (unlikely(cmd == NULL)) { | |
2964 | ql_dbg(ql_dbg_tgt, vha, 0xe053, | |
2965 | "qla_target(%d): Suspicious: unable to " | |
2966 | "find the command with handle %x\n", vha->vp_idx, | |
2967 | handle); | |
2968 | return NULL; | |
2969 | } | |
2970 | } else if (ctio != NULL) { | |
2971 | /* We can't get loop ID from CTIO7 */ | |
2972 | ql_dbg(ql_dbg_tgt, vha, 0xe054, | |
2973 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " | |
2974 | "support NULL handles\n", vha->vp_idx); | |
2975 | return NULL; | |
2976 | } | |
2977 | ||
2978 | return cmd; | |
2979 | } | |
2980 | ||
c0cb4496 AE |
2981 | /* hardware_lock should be held by caller. */ |
2982 | static void | |
2983 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) | |
2984 | { | |
2985 | struct qla_hw_data *ha = vha->hw; | |
2986 | uint32_t handle; | |
2987 | ||
2988 | if (cmd->sg_mapped) | |
2989 | qlt_unmap_sg(vha, cmd); | |
2990 | ||
2991 | handle = qlt_make_handle(vha); | |
2992 | ||
2993 | /* TODO: fix debug message type and ids. */ | |
2994 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { | |
2995 | ql_dbg(ql_dbg_io, vha, 0xff00, | |
2996 | "HOST-ABORT: handle=%d, state=PROCESSED.\n", handle); | |
2997 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { | |
2998 | cmd->write_data_transferred = 0; | |
2999 | cmd->state = QLA_TGT_STATE_DATA_IN; | |
3000 | ||
3001 | ql_dbg(ql_dbg_io, vha, 0xff01, | |
3002 | "HOST-ABORT: handle=%d, state=DATA_IN.\n", handle); | |
3003 | ||
3004 | ha->tgt.tgt_ops->handle_data(cmd); | |
3005 | return; | |
3006 | } else if (cmd->state == QLA_TGT_STATE_ABORTED) { | |
3007 | ql_dbg(ql_dbg_io, vha, 0xff02, | |
3008 | "HOST-ABORT: handle=%d, state=ABORTED.\n", handle); | |
3009 | } else { | |
3010 | ql_dbg(ql_dbg_io, vha, 0xff03, | |
3011 | "HOST-ABORT: handle=%d, state=BAD(%d).\n", handle, | |
3012 | cmd->state); | |
3013 | dump_stack(); | |
3014 | } | |
3015 | ||
e5fdee87 | 3016 | cmd->cmd_flags |= BIT_17; |
c0cb4496 AE |
3017 | ha->tgt.tgt_ops->free_cmd(cmd); |
3018 | } | |
3019 | ||
3020 | void | |
3021 | qlt_host_reset_handler(struct qla_hw_data *ha) | |
3022 | { | |
3023 | struct qla_tgt_cmd *cmd; | |
3024 | unsigned long flags; | |
3025 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
3026 | scsi_qla_host_t *vha = NULL; | |
3027 | struct qla_tgt *tgt = base_vha->vha_tgt.qla_tgt; | |
3028 | uint32_t i; | |
3029 | ||
3030 | if (!base_vha->hw->tgt.tgt_ops) | |
3031 | return; | |
3032 | ||
3033 | if (!tgt || qla_ini_mode_enabled(base_vha)) { | |
3034 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003, | |
3035 | "Target mode disabled\n"); | |
3036 | return; | |
3037 | } | |
3038 | ||
3039 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xff10, | |
3040 | "HOST-ABORT-HNDLR: base_vha->dpc_flags=%lx.\n", | |
3041 | base_vha->dpc_flags); | |
3042 | ||
3043 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3044 | for (i = 1; i < DEFAULT_OUTSTANDING_COMMANDS + 1; i++) { | |
3045 | cmd = qlt_get_cmd(base_vha, i); | |
3046 | if (!cmd) | |
3047 | continue; | |
3048 | /* ha->tgt.cmds entry is cleared by qlt_get_cmd. */ | |
3049 | vha = cmd->vha; | |
3050 | qlt_abort_cmd_on_host_reset(vha, cmd); | |
3051 | } | |
3052 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
3053 | } | |
3054 | ||
3055 | ||
2d70c103 NB |
3056 | /* |
3057 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
3058 | */ | |
3059 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, | |
3060 | uint32_t status, void *ctio) | |
3061 | { | |
3062 | struct qla_hw_data *ha = vha->hw; | |
3063 | struct se_cmd *se_cmd; | |
9ac8928e | 3064 | const struct target_core_fabric_ops *tfo; |
2d70c103 NB |
3065 | struct qla_tgt_cmd *cmd; |
3066 | ||
2d70c103 NB |
3067 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
3068 | /* That could happen only in case of an error/reset/abort */ | |
3069 | if (status != CTIO_SUCCESS) { | |
3070 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, | |
3071 | "Intermediate CTIO received" | |
3072 | " (status %x)\n", status); | |
3073 | } | |
3074 | return; | |
3075 | } | |
3076 | ||
3077 | cmd = qlt_ctio_to_cmd(vha, handle, ctio); | |
092e1dc3 | 3078 | if (cmd == NULL) |
2d70c103 | 3079 | return; |
092e1dc3 | 3080 | |
2d70c103 NB |
3081 | se_cmd = &cmd->se_cmd; |
3082 | tfo = se_cmd->se_tfo; | |
d564a372 | 3083 | cmd->cmd_sent_to_fw = 0; |
2d70c103 | 3084 | |
f9b6721a | 3085 | qlt_unmap_sg(vha, cmd); |
2d70c103 NB |
3086 | |
3087 | if (unlikely(status != CTIO_SUCCESS)) { | |
3088 | switch (status & 0xFFFF) { | |
3089 | case CTIO_LIP_RESET: | |
3090 | case CTIO_TARGET_RESET: | |
3091 | case CTIO_ABORTED: | |
7b898542 | 3092 | /* driver request abort via Terminate exchange */ |
2d70c103 NB |
3093 | case CTIO_TIMEOUT: |
3094 | case CTIO_INVALID_RX_ID: | |
3095 | /* They are OK */ | |
3096 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, | |
3097 | "qla_target(%d): CTIO with " | |
3098 | "status %#x received, state %x, se_cmd %p, " | |
3099 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " | |
3100 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, | |
3101 | status, cmd->state, se_cmd); | |
3102 | break; | |
3103 | ||
3104 | case CTIO_PORT_LOGGED_OUT: | |
3105 | case CTIO_PORT_UNAVAILABLE: | |
3106 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, | |
3107 | "qla_target(%d): CTIO with PORT LOGGED " | |
3108 | "OUT (29) or PORT UNAVAILABLE (28) status %x " | |
3109 | "received (state %x, se_cmd %p)\n", vha->vp_idx, | |
3110 | status, cmd->state, se_cmd); | |
3111 | break; | |
3112 | ||
3113 | case CTIO_SRR_RECEIVED: | |
3114 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05a, | |
3115 | "qla_target(%d): CTIO with SRR_RECEIVED" | |
3116 | " status %x received (state %x, se_cmd %p)\n", | |
3117 | vha->vp_idx, status, cmd->state, se_cmd); | |
3118 | if (qlt_prepare_srr_ctio(vha, cmd, ctio) != 0) | |
3119 | break; | |
3120 | else | |
3121 | return; | |
3122 | ||
f83adb61 QT |
3123 | case CTIO_DIF_ERROR: { |
3124 | struct ctio_crc_from_fw *crc = | |
3125 | (struct ctio_crc_from_fw *)ctio; | |
3126 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, | |
3127 | "qla_target(%d): CTIO with DIF_ERROR status %x received (state %x, se_cmd %p) actual_dif[0x%llx] expect_dif[0x%llx]\n", | |
3128 | vha->vp_idx, status, cmd->state, se_cmd, | |
3129 | *((u64 *)&crc->actual_dif[0]), | |
3130 | *((u64 *)&crc->expected_dif[0])); | |
3131 | ||
3132 | if (qlt_handle_dif_error(vha, cmd, ctio)) { | |
3133 | if (cmd->state == QLA_TGT_STATE_NEED_DATA) { | |
3134 | /* scsi Write/xfer rdy complete */ | |
3135 | goto skip_term; | |
3136 | } else { | |
3137 | /* scsi read/xmit respond complete | |
3138 | * call handle dif to send scsi status | |
3139 | * rather than terminate exchange. | |
3140 | */ | |
3141 | cmd->state = QLA_TGT_STATE_PROCESSED; | |
3142 | ha->tgt.tgt_ops->handle_dif_err(cmd); | |
3143 | return; | |
3144 | } | |
3145 | } else { | |
3146 | /* Need to generate a SCSI good completion. | |
3147 | * because FW did not send scsi status. | |
3148 | */ | |
3149 | status = 0; | |
3150 | goto skip_term; | |
3151 | } | |
3152 | break; | |
3153 | } | |
2d70c103 NB |
3154 | default: |
3155 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, | |
f83adb61 | 3156 | "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n", |
2d70c103 NB |
3157 | vha->vp_idx, status, cmd->state, se_cmd); |
3158 | break; | |
3159 | } | |
3160 | ||
7b898542 QT |
3161 | |
3162 | /* "cmd->state == QLA_TGT_STATE_ABORTED" means | |
3163 | * cmd is already aborted/terminated, we don't | |
3164 | * need to terminate again. The exchange is already | |
3165 | * cleaned up/freed at FW level. Just cleanup at driver | |
3166 | * level. | |
3167 | */ | |
3168 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && | |
33e79977 | 3169 | (cmd->state != QLA_TGT_STATE_ABORTED)) { |
e07f8f65 | 3170 | cmd->cmd_flags |= BIT_13; |
2d70c103 NB |
3171 | if (qlt_term_ctio_exchange(vha, ctio, cmd, status)) |
3172 | return; | |
7b898542 | 3173 | } |
2d70c103 | 3174 | } |
f83adb61 | 3175 | skip_term: |
2d70c103 NB |
3176 | |
3177 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { | |
e5fdee87 | 3178 | cmd->cmd_flags |= BIT_12; |
2d70c103 NB |
3179 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
3180 | int rx_status = 0; | |
3181 | ||
3182 | cmd->state = QLA_TGT_STATE_DATA_IN; | |
3183 | ||
3184 | if (unlikely(status != CTIO_SUCCESS)) | |
3185 | rx_status = -EIO; | |
3186 | else | |
3187 | cmd->write_data_transferred = 1; | |
3188 | ||
2d70c103 NB |
3189 | ha->tgt.tgt_ops->handle_data(cmd); |
3190 | return; | |
3191 | } else if (cmd->state == QLA_TGT_STATE_ABORTED) { | |
e5fdee87 | 3192 | cmd->cmd_flags |= BIT_18; |
2d70c103 | 3193 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
649ee054 | 3194 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
2d70c103 | 3195 | } else { |
e5fdee87 | 3196 | cmd->cmd_flags |= BIT_19; |
2d70c103 NB |
3197 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
3198 | "qla_target(%d): A command in state (%d) should " | |
3199 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); | |
3200 | } | |
3201 | ||
7b898542 QT |
3202 | if (unlikely(status != CTIO_SUCCESS) && |
3203 | (cmd->state != QLA_TGT_STATE_ABORTED)) { | |
2d70c103 NB |
3204 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
3205 | dump_stack(); | |
3206 | } | |
3207 | ||
3208 | ha->tgt.tgt_ops->free_cmd(cmd); | |
3209 | } | |
3210 | ||
2d70c103 NB |
3211 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
3212 | uint8_t task_codes) | |
3213 | { | |
3214 | int fcp_task_attr; | |
3215 | ||
3216 | switch (task_codes) { | |
3217 | case ATIO_SIMPLE_QUEUE: | |
68d81f40 | 3218 | fcp_task_attr = TCM_SIMPLE_TAG; |
2d70c103 NB |
3219 | break; |
3220 | case ATIO_HEAD_OF_QUEUE: | |
68d81f40 | 3221 | fcp_task_attr = TCM_HEAD_TAG; |
2d70c103 NB |
3222 | break; |
3223 | case ATIO_ORDERED_QUEUE: | |
68d81f40 | 3224 | fcp_task_attr = TCM_ORDERED_TAG; |
2d70c103 NB |
3225 | break; |
3226 | case ATIO_ACA_QUEUE: | |
68d81f40 | 3227 | fcp_task_attr = TCM_ACA_TAG; |
2d70c103 NB |
3228 | break; |
3229 | case ATIO_UNTAGGED: | |
68d81f40 | 3230 | fcp_task_attr = TCM_SIMPLE_TAG; |
2d70c103 NB |
3231 | break; |
3232 | default: | |
3233 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, | |
3234 | "qla_target: unknown task code %x, use ORDERED instead\n", | |
3235 | task_codes); | |
68d81f40 | 3236 | fcp_task_attr = TCM_ORDERED_TAG; |
2d70c103 NB |
3237 | break; |
3238 | } | |
3239 | ||
3240 | return fcp_task_attr; | |
3241 | } | |
3242 | ||
3243 | static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *, | |
3244 | uint8_t *); | |
3245 | /* | |
3246 | * Process context for I/O path into tcm_qla2xxx code | |
3247 | */ | |
51a07f84 | 3248 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
2d70c103 | 3249 | { |
2d70c103 NB |
3250 | scsi_qla_host_t *vha = cmd->vha; |
3251 | struct qla_hw_data *ha = vha->hw; | |
0e8cd71c | 3252 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
51a07f84 | 3253 | struct qla_tgt_sess *sess = cmd->sess; |
2d70c103 NB |
3254 | struct atio_from_isp *atio = &cmd->atio; |
3255 | unsigned char *cdb; | |
3256 | unsigned long flags; | |
3257 | uint32_t data_length; | |
3258 | int ret, fcp_task_attr, data_dir, bidi = 0; | |
3259 | ||
e07f8f65 SK |
3260 | cmd->cmd_in_wq = 0; |
3261 | cmd->cmd_flags |= BIT_1; | |
2d70c103 NB |
3262 | if (tgt->tgt_stop) |
3263 | goto out_term; | |
3264 | ||
2d70c103 | 3265 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
649ee054 | 3266 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
2d70c103 NB |
3267 | cmd->unpacked_lun = scsilun_to_int( |
3268 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); | |
3269 | ||
3270 | if (atio->u.isp24.fcp_cmnd.rddata && | |
3271 | atio->u.isp24.fcp_cmnd.wrdata) { | |
3272 | bidi = 1; | |
3273 | data_dir = DMA_TO_DEVICE; | |
3274 | } else if (atio->u.isp24.fcp_cmnd.rddata) | |
3275 | data_dir = DMA_FROM_DEVICE; | |
3276 | else if (atio->u.isp24.fcp_cmnd.wrdata) | |
3277 | data_dir = DMA_TO_DEVICE; | |
3278 | else | |
3279 | data_dir = DMA_NONE; | |
3280 | ||
3281 | fcp_task_attr = qlt_get_fcp_task_attr(vha, | |
3282 | atio->u.isp24.fcp_cmnd.task_attr); | |
3283 | data_length = be32_to_cpu(get_unaligned((uint32_t *) | |
3284 | &atio->u.isp24.fcp_cmnd.add_cdb[ | |
3285 | atio->u.isp24.fcp_cmnd.add_cdb_len])); | |
3286 | ||
51a07f84 NB |
3287 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
3288 | fcp_task_attr, data_dir, bidi); | |
2d70c103 NB |
3289 | if (ret != 0) |
3290 | goto out_term; | |
3291 | /* | |
3292 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( | |
3293 | */ | |
08234e3a | 3294 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2d70c103 | 3295 | ha->tgt.tgt_ops->put_sess(sess); |
08234e3a | 3296 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2d70c103 NB |
3297 | return; |
3298 | ||
3299 | out_term: | |
667024a3 | 3300 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
2d70c103 | 3301 | /* |
fae9eaf8 RD |
3302 | * cmd has not sent to target yet, so pass NULL as the second |
3303 | * argument to qlt_send_term_exchange() and free the memory here. | |
2d70c103 | 3304 | */ |
e07f8f65 | 3305 | cmd->cmd_flags |= BIT_2; |
2d70c103 NB |
3306 | spin_lock_irqsave(&ha->hardware_lock, flags); |
3307 | qlt_send_term_exchange(vha, NULL, &cmd->atio, 1); | |
33e79977 QT |
3308 | |
3309 | qlt_decr_num_pend_cmds(vha); | |
51a07f84 NB |
3310 | percpu_ida_free(&sess->se_sess->sess_tag_pool, cmd->se_cmd.map_tag); |
3311 | ha->tgt.tgt_ops->put_sess(sess); | |
3312 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
3313 | } | |
3314 | ||
3315 | static void qlt_do_work(struct work_struct *work) | |
3316 | { | |
3317 | struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work); | |
3318 | ||
3319 | __qlt_do_work(cmd); | |
3320 | } | |
3321 | ||
3322 | static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha, | |
3323 | struct qla_tgt_sess *sess, | |
3324 | struct atio_from_isp *atio) | |
3325 | { | |
3326 | struct se_session *se_sess = sess->se_sess; | |
3327 | struct qla_tgt_cmd *cmd; | |
3328 | int tag; | |
3329 | ||
3330 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); | |
3331 | if (tag < 0) | |
3332 | return NULL; | |
3333 | ||
3334 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; | |
3335 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); | |
3336 | ||
3337 | memcpy(&cmd->atio, atio, sizeof(*atio)); | |
3338 | cmd->state = QLA_TGT_STATE_NEW; | |
3339 | cmd->tgt = vha->vha_tgt.qla_tgt; | |
33e79977 | 3340 | qlt_incr_num_pend_cmds(vha); |
51a07f84 NB |
3341 | cmd->vha = vha; |
3342 | cmd->se_cmd.map_tag = tag; | |
3343 | cmd->sess = sess; | |
3344 | cmd->loop_id = sess->loop_id; | |
3345 | cmd->conf_compl_supported = sess->conf_compl_supported; | |
3346 | ||
3347 | return cmd; | |
3348 | } | |
3349 | ||
3350 | static void qlt_send_busy(struct scsi_qla_host *, struct atio_from_isp *, | |
3351 | uint16_t); | |
3352 | ||
3353 | static void qlt_create_sess_from_atio(struct work_struct *work) | |
3354 | { | |
3355 | struct qla_tgt_sess_op *op = container_of(work, | |
3356 | struct qla_tgt_sess_op, work); | |
3357 | scsi_qla_host_t *vha = op->vha; | |
3358 | struct qla_hw_data *ha = vha->hw; | |
3359 | struct qla_tgt_sess *sess; | |
3360 | struct qla_tgt_cmd *cmd; | |
3361 | unsigned long flags; | |
3362 | uint8_t *s_id = op->atio.u.isp24.fcp_hdr.s_id; | |
3363 | ||
3364 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, | |
3365 | "qla_target(%d): Unable to find wwn login" | |
3366 | " (s_id %x:%x:%x), trying to create it manually\n", | |
3367 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); | |
3368 | ||
3369 | if (op->atio.u.raw.entry_count > 1) { | |
3370 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, | |
3371 | "Dropping multy entry atio %p\n", &op->atio); | |
3372 | goto out_term; | |
3373 | } | |
3374 | ||
3375 | mutex_lock(&vha->vha_tgt.tgt_mutex); | |
3376 | sess = qlt_make_local_sess(vha, s_id); | |
3377 | /* sess has an extra creation ref. */ | |
3378 | mutex_unlock(&vha->vha_tgt.tgt_mutex); | |
3379 | ||
3380 | if (!sess) | |
3381 | goto out_term; | |
3382 | /* | |
3383 | * Now obtain a pre-allocated session tag using the original op->atio | |
3384 | * packet header, and dispatch into __qlt_do_work() using the existing | |
3385 | * process context. | |
3386 | */ | |
3387 | cmd = qlt_get_tag(vha, sess, &op->atio); | |
3388 | if (!cmd) { | |
3389 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3390 | qlt_send_busy(vha, &op->atio, SAM_STAT_BUSY); | |
2d70c103 | 3391 | ha->tgt.tgt_ops->put_sess(sess); |
51a07f84 NB |
3392 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
3393 | kfree(op); | |
3394 | return; | |
3395 | } | |
3396 | /* | |
3397 | * __qlt_do_work() will call ha->tgt.tgt_ops->put_sess() to release | |
3398 | * the extra reference taken above by qlt_make_local_sess() | |
3399 | */ | |
3400 | __qlt_do_work(cmd); | |
3401 | kfree(op); | |
3402 | return; | |
3403 | ||
3404 | out_term: | |
3405 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3406 | qlt_send_term_exchange(vha, NULL, &op->atio, 1); | |
08234e3a | 3407 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
51a07f84 NB |
3408 | kfree(op); |
3409 | ||
2d70c103 NB |
3410 | } |
3411 | ||
3412 | /* ha->hardware_lock supposed to be held on entry */ | |
3413 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, | |
3414 | struct atio_from_isp *atio) | |
3415 | { | |
51a07f84 | 3416 | struct qla_hw_data *ha = vha->hw; |
0e8cd71c | 3417 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
51a07f84 | 3418 | struct qla_tgt_sess *sess; |
2d70c103 NB |
3419 | struct qla_tgt_cmd *cmd; |
3420 | ||
3421 | if (unlikely(tgt->tgt_stop)) { | |
667024a3 | 3422 | ql_dbg(ql_dbg_io, vha, 0x3061, |
2d70c103 NB |
3423 | "New command while device %p is shutting down\n", tgt); |
3424 | return -EFAULT; | |
3425 | } | |
3426 | ||
51a07f84 NB |
3427 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
3428 | if (unlikely(!sess)) { | |
3429 | struct qla_tgt_sess_op *op = kzalloc(sizeof(struct qla_tgt_sess_op), | |
3430 | GFP_ATOMIC); | |
3431 | if (!op) | |
3432 | return -ENOMEM; | |
3433 | ||
3434 | memcpy(&op->atio, atio, sizeof(*atio)); | |
78c2106a | 3435 | op->vha = vha; |
51a07f84 NB |
3436 | INIT_WORK(&op->work, qlt_create_sess_from_atio); |
3437 | queue_work(qla_tgt_wq, &op->work); | |
3438 | return 0; | |
3439 | } | |
3440 | /* | |
3441 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. | |
3442 | */ | |
3443 | kref_get(&sess->se_sess->sess_kref); | |
3444 | ||
3445 | cmd = qlt_get_tag(vha, sess, atio); | |
2d70c103 | 3446 | if (!cmd) { |
667024a3 | 3447 | ql_dbg(ql_dbg_io, vha, 0x3062, |
2d70c103 | 3448 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
51a07f84 | 3449 | ha->tgt.tgt_ops->put_sess(sess); |
2d70c103 NB |
3450 | return -ENOMEM; |
3451 | } | |
3452 | ||
e07f8f65 SK |
3453 | cmd->cmd_flags = 0; |
3454 | cmd->jiffies_at_alloc = get_jiffies_64(); | |
3455 | ||
b6a029e1 AE |
3456 | cmd->reset_count = vha->hw->chip_reset; |
3457 | ||
e07f8f65 SK |
3458 | cmd->cmd_in_wq = 1; |
3459 | cmd->cmd_flags |= BIT_0; | |
2d70c103 NB |
3460 | INIT_WORK(&cmd->work, qlt_do_work); |
3461 | queue_work(qla_tgt_wq, &cmd->work); | |
3462 | return 0; | |
3463 | ||
3464 | } | |
3465 | ||
3466 | /* ha->hardware_lock supposed to be held on entry */ | |
3467 | static int qlt_issue_task_mgmt(struct qla_tgt_sess *sess, uint32_t lun, | |
3468 | int fn, void *iocb, int flags) | |
3469 | { | |
3470 | struct scsi_qla_host *vha = sess->vha; | |
3471 | struct qla_hw_data *ha = vha->hw; | |
3472 | struct qla_tgt_mgmt_cmd *mcmd; | |
3473 | int res; | |
3474 | uint8_t tmr_func; | |
3475 | ||
3476 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); | |
3477 | if (!mcmd) { | |
3478 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, | |
3479 | "qla_target(%d): Allocation of management " | |
3480 | "command failed, some commands and their data could " | |
3481 | "leak\n", vha->vp_idx); | |
3482 | return -ENOMEM; | |
3483 | } | |
3484 | memset(mcmd, 0, sizeof(*mcmd)); | |
3485 | mcmd->sess = sess; | |
3486 | ||
3487 | if (iocb) { | |
3488 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, | |
3489 | sizeof(mcmd->orig_iocb.imm_ntfy)); | |
3490 | } | |
3491 | mcmd->tmr_func = fn; | |
3492 | mcmd->flags = flags; | |
b6a029e1 | 3493 | mcmd->reset_count = vha->hw->chip_reset; |
2d70c103 NB |
3494 | |
3495 | switch (fn) { | |
3496 | case QLA_TGT_CLEAR_ACA: | |
3497 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10000, | |
3498 | "qla_target(%d): CLEAR_ACA received\n", sess->vha->vp_idx); | |
3499 | tmr_func = TMR_CLEAR_ACA; | |
3500 | break; | |
3501 | ||
3502 | case QLA_TGT_TARGET_RESET: | |
3503 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10001, | |
3504 | "qla_target(%d): TARGET_RESET received\n", | |
3505 | sess->vha->vp_idx); | |
3506 | tmr_func = TMR_TARGET_WARM_RESET; | |
3507 | break; | |
3508 | ||
3509 | case QLA_TGT_LUN_RESET: | |
3510 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10002, | |
3511 | "qla_target(%d): LUN_RESET received\n", sess->vha->vp_idx); | |
3512 | tmr_func = TMR_LUN_RESET; | |
3513 | break; | |
3514 | ||
3515 | case QLA_TGT_CLEAR_TS: | |
3516 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10003, | |
3517 | "qla_target(%d): CLEAR_TS received\n", sess->vha->vp_idx); | |
3518 | tmr_func = TMR_CLEAR_TASK_SET; | |
3519 | break; | |
3520 | ||
3521 | case QLA_TGT_ABORT_TS: | |
3522 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10004, | |
3523 | "qla_target(%d): ABORT_TS received\n", sess->vha->vp_idx); | |
3524 | tmr_func = TMR_ABORT_TASK_SET; | |
3525 | break; | |
3526 | #if 0 | |
3527 | case QLA_TGT_ABORT_ALL: | |
3528 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10005, | |
3529 | "qla_target(%d): Doing ABORT_ALL_TASKS\n", | |
3530 | sess->vha->vp_idx); | |
3531 | tmr_func = 0; | |
3532 | break; | |
3533 | ||
3534 | case QLA_TGT_ABORT_ALL_SESS: | |
3535 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10006, | |
3536 | "qla_target(%d): Doing ABORT_ALL_TASKS_SESS\n", | |
3537 | sess->vha->vp_idx); | |
3538 | tmr_func = 0; | |
3539 | break; | |
3540 | ||
3541 | case QLA_TGT_NEXUS_LOSS_SESS: | |
3542 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10007, | |
3543 | "qla_target(%d): Doing NEXUS_LOSS_SESS\n", | |
3544 | sess->vha->vp_idx); | |
3545 | tmr_func = 0; | |
3546 | break; | |
3547 | ||
3548 | case QLA_TGT_NEXUS_LOSS: | |
3549 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10008, | |
3550 | "qla_target(%d): Doing NEXUS_LOSS\n", sess->vha->vp_idx); | |
3551 | tmr_func = 0; | |
3552 | break; | |
3553 | #endif | |
3554 | default: | |
3555 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000a, | |
3556 | "qla_target(%d): Unknown task mgmt fn 0x%x\n", | |
3557 | sess->vha->vp_idx, fn); | |
3558 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | |
3559 | return -ENOSYS; | |
3560 | } | |
3561 | ||
3562 | res = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, tmr_func, 0); | |
3563 | if (res != 0) { | |
3564 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, | |
3565 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", | |
3566 | sess->vha->vp_idx, res); | |
3567 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | |
3568 | return -EFAULT; | |
3569 | } | |
3570 | ||
3571 | return 0; | |
3572 | } | |
3573 | ||
3574 | /* ha->hardware_lock supposed to be held on entry */ | |
3575 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) | |
3576 | { | |
3577 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; | |
3578 | struct qla_hw_data *ha = vha->hw; | |
3579 | struct qla_tgt *tgt; | |
3580 | struct qla_tgt_sess *sess; | |
3581 | uint32_t lun, unpacked_lun; | |
3582 | int lun_size, fn; | |
3583 | ||
0e8cd71c | 3584 | tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
3585 | |
3586 | lun = a->u.isp24.fcp_cmnd.lun; | |
3587 | lun_size = sizeof(a->u.isp24.fcp_cmnd.lun); | |
3588 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; | |
3589 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, | |
3590 | a->u.isp24.fcp_hdr.s_id); | |
3591 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | |
3592 | ||
3593 | if (!sess) { | |
3594 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, | |
3595 | "qla_target(%d): task mgmt fn 0x%x for " | |
3596 | "non-existant session\n", vha->vp_idx, fn); | |
3597 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, | |
3598 | sizeof(struct atio_from_isp)); | |
3599 | } | |
3600 | ||
3601 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); | |
3602 | } | |
3603 | ||
3604 | /* ha->hardware_lock supposed to be held on entry */ | |
3605 | static int __qlt_abort_task(struct scsi_qla_host *vha, | |
3606 | struct imm_ntfy_from_isp *iocb, struct qla_tgt_sess *sess) | |
3607 | { | |
3608 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; | |
3609 | struct qla_hw_data *ha = vha->hw; | |
3610 | struct qla_tgt_mgmt_cmd *mcmd; | |
3611 | uint32_t lun, unpacked_lun; | |
3612 | int rc; | |
3613 | ||
3614 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); | |
3615 | if (mcmd == NULL) { | |
3616 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, | |
3617 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", | |
3618 | vha->vp_idx, __func__); | |
3619 | return -ENOMEM; | |
3620 | } | |
3621 | memset(mcmd, 0, sizeof(*mcmd)); | |
3622 | ||
3623 | mcmd->sess = sess; | |
3624 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, | |
3625 | sizeof(mcmd->orig_iocb.imm_ntfy)); | |
3626 | ||
3627 | lun = a->u.isp24.fcp_cmnd.lun; | |
3628 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | |
80187f8e | 3629 | mcmd->reset_count = vha->hw->chip_reset; |
2d70c103 NB |
3630 | |
3631 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, TMR_ABORT_TASK, | |
3632 | le16_to_cpu(iocb->u.isp2x.seq_id)); | |
3633 | if (rc != 0) { | |
3634 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, | |
3635 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", | |
3636 | vha->vp_idx, rc); | |
3637 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | |
3638 | return -EFAULT; | |
3639 | } | |
3640 | ||
3641 | return 0; | |
3642 | } | |
3643 | ||
3644 | /* ha->hardware_lock supposed to be held on entry */ | |
3645 | static int qlt_abort_task(struct scsi_qla_host *vha, | |
3646 | struct imm_ntfy_from_isp *iocb) | |
3647 | { | |
3648 | struct qla_hw_data *ha = vha->hw; | |
3649 | struct qla_tgt_sess *sess; | |
3650 | int loop_id; | |
3651 | ||
3652 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); | |
3653 | ||
3654 | sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id); | |
3655 | if (sess == NULL) { | |
3656 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, | |
3657 | "qla_target(%d): task abort for unexisting " | |
3658 | "session\n", vha->vp_idx); | |
0e8cd71c | 3659 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
2d70c103 NB |
3660 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
3661 | } | |
3662 | ||
3663 | return __qlt_abort_task(vha, iocb, sess); | |
3664 | } | |
3665 | ||
3666 | /* | |
3667 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
3668 | */ | |
3669 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, | |
3670 | struct imm_ntfy_from_isp *iocb) | |
3671 | { | |
2d70c103 NB |
3672 | int res = 0; |
3673 | ||
3674 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf026, | |
7b833558 OK |
3675 | "qla_target(%d): Port ID: 0x%3phC ELS opcode: 0x%02x\n", |
3676 | vha->vp_idx, iocb->u.isp24.port_id, iocb->u.isp24.status_subcode); | |
2d70c103 NB |
3677 | |
3678 | switch (iocb->u.isp24.status_subcode) { | |
3679 | case ELS_PLOGI: | |
3680 | case ELS_FLOGI: | |
3681 | case ELS_PRLI: | |
3682 | case ELS_LOGO: | |
3683 | case ELS_PRLO: | |
3684 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); | |
3685 | break; | |
3686 | case ELS_PDISC: | |
3687 | case ELS_ADISC: | |
3688 | { | |
0e8cd71c | 3689 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
3690 | if (tgt->link_reinit_iocb_pending) { |
3691 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, | |
3692 | 0, 0, 0, 0, 0, 0); | |
3693 | tgt->link_reinit_iocb_pending = 0; | |
3694 | } | |
3695 | res = 1; /* send notify ack */ | |
3696 | break; | |
3697 | } | |
3698 | ||
3699 | default: | |
3700 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, | |
3701 | "qla_target(%d): Unsupported ELS command %x " | |
3702 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); | |
3703 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); | |
3704 | break; | |
3705 | } | |
3706 | ||
3707 | return res; | |
3708 | } | |
3709 | ||
3710 | static int qlt_set_data_offset(struct qla_tgt_cmd *cmd, uint32_t offset) | |
3711 | { | |
5897cb2f BVA |
3712 | #if 1 |
3713 | /* | |
3714 | * FIXME: Reject non zero SRR relative offset until we can test | |
3715 | * this code properly. | |
3716 | */ | |
3717 | pr_debug("Rejecting non zero SRR rel_offs: %u\n", offset); | |
3718 | return -1; | |
3719 | #else | |
2d70c103 NB |
3720 | struct scatterlist *sg, *sgp, *sg_srr, *sg_srr_start = NULL; |
3721 | size_t first_offset = 0, rem_offset = offset, tmp = 0; | |
3722 | int i, sg_srr_cnt, bufflen = 0; | |
3723 | ||
3724 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe023, | |
3725 | "Entering qla_tgt_set_data_offset: cmd: %p, cmd->sg: %p, " | |
3726 | "cmd->sg_cnt: %u, direction: %d\n", | |
3727 | cmd, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); | |
3728 | ||
2d70c103 NB |
3729 | if (!cmd->sg || !cmd->sg_cnt) { |
3730 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe055, | |
3731 | "Missing cmd->sg or zero cmd->sg_cnt in" | |
3732 | " qla_tgt_set_data_offset\n"); | |
3733 | return -EINVAL; | |
3734 | } | |
3735 | /* | |
3736 | * Walk the current cmd->sg list until we locate the new sg_srr_start | |
3737 | */ | |
3738 | for_each_sg(cmd->sg, sg, cmd->sg_cnt, i) { | |
3739 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe024, | |
3740 | "sg[%d]: %p page: %p, length: %d, offset: %d\n", | |
3741 | i, sg, sg_page(sg), sg->length, sg->offset); | |
3742 | ||
3743 | if ((sg->length + tmp) > offset) { | |
3744 | first_offset = rem_offset; | |
3745 | sg_srr_start = sg; | |
3746 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe025, | |
3747 | "Found matching sg[%d], using %p as sg_srr_start, " | |
3748 | "and using first_offset: %zu\n", i, sg, | |
3749 | first_offset); | |
3750 | break; | |
3751 | } | |
3752 | tmp += sg->length; | |
3753 | rem_offset -= sg->length; | |
3754 | } | |
3755 | ||
3756 | if (!sg_srr_start) { | |
3757 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe056, | |
3758 | "Unable to locate sg_srr_start for offset: %u\n", offset); | |
3759 | return -EINVAL; | |
3760 | } | |
3761 | sg_srr_cnt = (cmd->sg_cnt - i); | |
3762 | ||
3763 | sg_srr = kzalloc(sizeof(struct scatterlist) * sg_srr_cnt, GFP_KERNEL); | |
3764 | if (!sg_srr) { | |
3765 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe057, | |
3766 | "Unable to allocate sgp\n"); | |
3767 | return -ENOMEM; | |
3768 | } | |
3769 | sg_init_table(sg_srr, sg_srr_cnt); | |
3770 | sgp = &sg_srr[0]; | |
3771 | /* | |
3772 | * Walk the remaining list for sg_srr_start, mapping to the newly | |
3773 | * allocated sg_srr taking first_offset into account. | |
3774 | */ | |
3775 | for_each_sg(sg_srr_start, sg, sg_srr_cnt, i) { | |
3776 | if (first_offset) { | |
3777 | sg_set_page(sgp, sg_page(sg), | |
3778 | (sg->length - first_offset), first_offset); | |
3779 | first_offset = 0; | |
3780 | } else { | |
3781 | sg_set_page(sgp, sg_page(sg), sg->length, 0); | |
3782 | } | |
3783 | bufflen += sgp->length; | |
3784 | ||
3785 | sgp = sg_next(sgp); | |
3786 | if (!sgp) | |
3787 | break; | |
3788 | } | |
3789 | ||
3790 | cmd->sg = sg_srr; | |
3791 | cmd->sg_cnt = sg_srr_cnt; | |
3792 | cmd->bufflen = bufflen; | |
3793 | cmd->offset += offset; | |
3794 | cmd->free_sg = 1; | |
3795 | ||
3796 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe026, "New cmd->sg: %p\n", cmd->sg); | |
3797 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe027, "New cmd->sg_cnt: %u\n", | |
3798 | cmd->sg_cnt); | |
3799 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe028, "New cmd->bufflen: %u\n", | |
3800 | cmd->bufflen); | |
3801 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe029, "New cmd->offset: %u\n", | |
3802 | cmd->offset); | |
3803 | ||
3804 | if (cmd->sg_cnt < 0) | |
3805 | BUG(); | |
3806 | ||
3807 | if (cmd->bufflen < 0) | |
3808 | BUG(); | |
3809 | ||
3810 | return 0; | |
5897cb2f | 3811 | #endif |
2d70c103 NB |
3812 | } |
3813 | ||
3814 | static inline int qlt_srr_adjust_data(struct qla_tgt_cmd *cmd, | |
3815 | uint32_t srr_rel_offs, int *xmit_type) | |
3816 | { | |
3817 | int res = 0, rel_offs; | |
3818 | ||
3819 | rel_offs = srr_rel_offs - cmd->offset; | |
3820 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf027, "srr_rel_offs=%d, rel_offs=%d", | |
3821 | srr_rel_offs, rel_offs); | |
3822 | ||
3823 | *xmit_type = QLA_TGT_XMIT_ALL; | |
3824 | ||
3825 | if (rel_offs < 0) { | |
3826 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf062, | |
3827 | "qla_target(%d): SRR rel_offs (%d) < 0", | |
3828 | cmd->vha->vp_idx, rel_offs); | |
3829 | res = -1; | |
3830 | } else if (rel_offs == cmd->bufflen) | |
3831 | *xmit_type = QLA_TGT_XMIT_STATUS; | |
3832 | else if (rel_offs > 0) | |
3833 | res = qlt_set_data_offset(cmd, rel_offs); | |
3834 | ||
3835 | return res; | |
3836 | } | |
3837 | ||
3838 | /* No locks, thread context */ | |
3839 | static void qlt_handle_srr(struct scsi_qla_host *vha, | |
3840 | struct qla_tgt_srr_ctio *sctio, struct qla_tgt_srr_imm *imm) | |
3841 | { | |
3842 | struct imm_ntfy_from_isp *ntfy = | |
3843 | (struct imm_ntfy_from_isp *)&imm->imm_ntfy; | |
3844 | struct qla_hw_data *ha = vha->hw; | |
3845 | struct qla_tgt_cmd *cmd = sctio->cmd; | |
3846 | struct se_cmd *se_cmd = &cmd->se_cmd; | |
3847 | unsigned long flags; | |
3848 | int xmit_type = 0, resp = 0; | |
3849 | uint32_t offset; | |
3850 | uint16_t srr_ui; | |
3851 | ||
3852 | offset = le32_to_cpu(ntfy->u.isp24.srr_rel_offs); | |
3853 | srr_ui = ntfy->u.isp24.srr_ui; | |
3854 | ||
3855 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf028, "SRR cmd %p, srr_ui %x\n", | |
3856 | cmd, srr_ui); | |
3857 | ||
3858 | switch (srr_ui) { | |
3859 | case SRR_IU_STATUS: | |
3860 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3861 | qlt_send_notify_ack(vha, ntfy, | |
3862 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); | |
3863 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
3864 | xmit_type = QLA_TGT_XMIT_STATUS; | |
3865 | resp = 1; | |
3866 | break; | |
3867 | case SRR_IU_DATA_IN: | |
3868 | if (!cmd->sg || !cmd->sg_cnt) { | |
3869 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf063, | |
3870 | "Unable to process SRR_IU_DATA_IN due to" | |
3871 | " missing cmd->sg, state: %d\n", cmd->state); | |
3872 | dump_stack(); | |
3873 | goto out_reject; | |
3874 | } | |
3875 | if (se_cmd->scsi_status != 0) { | |
3876 | ql_dbg(ql_dbg_tgt, vha, 0xe02a, | |
3877 | "Rejecting SRR_IU_DATA_IN with non GOOD " | |
3878 | "scsi_status\n"); | |
3879 | goto out_reject; | |
3880 | } | |
3881 | cmd->bufflen = se_cmd->data_length; | |
3882 | ||
3883 | if (qlt_has_data(cmd)) { | |
3884 | if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0) | |
3885 | goto out_reject; | |
3886 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3887 | qlt_send_notify_ack(vha, ntfy, | |
3888 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); | |
3889 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
3890 | resp = 1; | |
3891 | } else { | |
3892 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf064, | |
649ee054 BVA |
3893 | "qla_target(%d): SRR for in data for cmd without them (tag %lld, SCSI status %d), reject", |
3894 | vha->vp_idx, se_cmd->tag, | |
2d70c103 NB |
3895 | cmd->se_cmd.scsi_status); |
3896 | goto out_reject; | |
3897 | } | |
3898 | break; | |
3899 | case SRR_IU_DATA_OUT: | |
3900 | if (!cmd->sg || !cmd->sg_cnt) { | |
3901 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf065, | |
3902 | "Unable to process SRR_IU_DATA_OUT due to" | |
3903 | " missing cmd->sg\n"); | |
3904 | dump_stack(); | |
3905 | goto out_reject; | |
3906 | } | |
3907 | if (se_cmd->scsi_status != 0) { | |
3908 | ql_dbg(ql_dbg_tgt, vha, 0xe02b, | |
3909 | "Rejecting SRR_IU_DATA_OUT" | |
3910 | " with non GOOD scsi_status\n"); | |
3911 | goto out_reject; | |
3912 | } | |
3913 | cmd->bufflen = se_cmd->data_length; | |
3914 | ||
3915 | if (qlt_has_data(cmd)) { | |
3916 | if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0) | |
3917 | goto out_reject; | |
3918 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3919 | qlt_send_notify_ack(vha, ntfy, | |
3920 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); | |
3921 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
e07f8f65 SK |
3922 | if (xmit_type & QLA_TGT_XMIT_DATA) { |
3923 | cmd->cmd_flags |= BIT_8; | |
2d70c103 | 3924 | qlt_rdy_to_xfer(cmd); |
e07f8f65 | 3925 | } |
2d70c103 NB |
3926 | } else { |
3927 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf066, | |
649ee054 BVA |
3928 | "qla_target(%d): SRR for out data for cmd without them (tag %lld, SCSI status %d), reject", |
3929 | vha->vp_idx, se_cmd->tag, cmd->se_cmd.scsi_status); | |
2d70c103 NB |
3930 | goto out_reject; |
3931 | } | |
3932 | break; | |
3933 | default: | |
3934 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf067, | |
3935 | "qla_target(%d): Unknown srr_ui value %x", | |
3936 | vha->vp_idx, srr_ui); | |
3937 | goto out_reject; | |
3938 | } | |
3939 | ||
3940 | /* Transmit response in case of status and data-in cases */ | |
e07f8f65 SK |
3941 | if (resp) { |
3942 | cmd->cmd_flags |= BIT_7; | |
2d70c103 | 3943 | qlt_xmit_response(cmd, xmit_type, se_cmd->scsi_status); |
e07f8f65 | 3944 | } |
2d70c103 NB |
3945 | |
3946 | return; | |
3947 | ||
3948 | out_reject: | |
3949 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3950 | qlt_send_notify_ack(vha, ntfy, 0, 0, 0, | |
3951 | NOTIFY_ACK_SRR_FLAGS_REJECT, | |
3952 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, | |
3953 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); | |
3954 | if (cmd->state == QLA_TGT_STATE_NEED_DATA) { | |
3955 | cmd->state = QLA_TGT_STATE_DATA_IN; | |
3956 | dump_stack(); | |
e07f8f65 SK |
3957 | } else { |
3958 | cmd->cmd_flags |= BIT_9; | |
2d70c103 | 3959 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1); |
e07f8f65 | 3960 | } |
2d70c103 NB |
3961 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
3962 | } | |
3963 | ||
3964 | static void qlt_reject_free_srr_imm(struct scsi_qla_host *vha, | |
3965 | struct qla_tgt_srr_imm *imm, int ha_locked) | |
3966 | { | |
3967 | struct qla_hw_data *ha = vha->hw; | |
3968 | unsigned long flags = 0; | |
3969 | ||
3970 | if (!ha_locked) | |
3971 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3972 | ||
3973 | qlt_send_notify_ack(vha, (void *)&imm->imm_ntfy, 0, 0, 0, | |
3974 | NOTIFY_ACK_SRR_FLAGS_REJECT, | |
3975 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, | |
3976 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); | |
3977 | ||
3978 | if (!ha_locked) | |
3979 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
3980 | ||
3981 | kfree(imm); | |
3982 | } | |
3983 | ||
3984 | static void qlt_handle_srr_work(struct work_struct *work) | |
3985 | { | |
3986 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, srr_work); | |
3987 | struct scsi_qla_host *vha = tgt->vha; | |
3988 | struct qla_tgt_srr_ctio *sctio; | |
3989 | unsigned long flags; | |
3990 | ||
3991 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf029, "Entering SRR work (tgt %p)\n", | |
3992 | tgt); | |
3993 | ||
3994 | restart: | |
3995 | spin_lock_irqsave(&tgt->srr_lock, flags); | |
3996 | list_for_each_entry(sctio, &tgt->srr_ctio_list, srr_list_entry) { | |
3997 | struct qla_tgt_srr_imm *imm, *i, *ti; | |
3998 | struct qla_tgt_cmd *cmd; | |
3999 | struct se_cmd *se_cmd; | |
4000 | ||
4001 | imm = NULL; | |
4002 | list_for_each_entry_safe(i, ti, &tgt->srr_imm_list, | |
4003 | srr_list_entry) { | |
4004 | if (i->srr_id == sctio->srr_id) { | |
4005 | list_del(&i->srr_list_entry); | |
4006 | if (imm) { | |
4007 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf068, | |
4008 | "qla_target(%d): There must be " | |
4009 | "only one IMM SRR per CTIO SRR " | |
4010 | "(IMM SRR %p, id %d, CTIO %p\n", | |
4011 | vha->vp_idx, i, i->srr_id, sctio); | |
4012 | qlt_reject_free_srr_imm(tgt->vha, i, 0); | |
4013 | } else | |
4014 | imm = i; | |
4015 | } | |
4016 | } | |
4017 | ||
4018 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02a, | |
4019 | "IMM SRR %p, CTIO SRR %p (id %d)\n", imm, sctio, | |
4020 | sctio->srr_id); | |
4021 | ||
4022 | if (imm == NULL) { | |
4023 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02b, | |
4024 | "Not found matching IMM for SRR CTIO (id %d)\n", | |
4025 | sctio->srr_id); | |
4026 | continue; | |
4027 | } else | |
4028 | list_del(&sctio->srr_list_entry); | |
4029 | ||
4030 | spin_unlock_irqrestore(&tgt->srr_lock, flags); | |
4031 | ||
4032 | cmd = sctio->cmd; | |
4033 | /* | |
4034 | * Reset qla_tgt_cmd SRR values and SGL pointer+count to follow | |
4035 | * tcm_qla2xxx_write_pending() and tcm_qla2xxx_queue_data_in() | |
4036 | * logic.. | |
4037 | */ | |
4038 | cmd->offset = 0; | |
4039 | if (cmd->free_sg) { | |
4040 | kfree(cmd->sg); | |
4041 | cmd->sg = NULL; | |
4042 | cmd->free_sg = 0; | |
4043 | } | |
4044 | se_cmd = &cmd->se_cmd; | |
4045 | ||
4046 | cmd->sg_cnt = se_cmd->t_data_nents; | |
4047 | cmd->sg = se_cmd->t_data_sg; | |
4048 | ||
4049 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c, | |
649ee054 BVA |
4050 | "SRR cmd %p (se_cmd %p, tag %lld, op %x), sg_cnt=%d, offset=%d", |
4051 | cmd, &cmd->se_cmd, se_cmd->tag, se_cmd->t_task_cdb ? | |
4052 | se_cmd->t_task_cdb[0] : 0, cmd->sg_cnt, cmd->offset); | |
2d70c103 NB |
4053 | |
4054 | qlt_handle_srr(vha, sctio, imm); | |
4055 | ||
4056 | kfree(imm); | |
4057 | kfree(sctio); | |
4058 | goto restart; | |
4059 | } | |
4060 | spin_unlock_irqrestore(&tgt->srr_lock, flags); | |
4061 | } | |
4062 | ||
4063 | /* ha->hardware_lock supposed to be held on entry */ | |
4064 | static void qlt_prepare_srr_imm(struct scsi_qla_host *vha, | |
4065 | struct imm_ntfy_from_isp *iocb) | |
4066 | { | |
4067 | struct qla_tgt_srr_imm *imm; | |
0e8cd71c | 4068 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
4069 | struct qla_tgt_srr_ctio *sctio; |
4070 | ||
4071 | tgt->imm_srr_id++; | |
4072 | ||
e07f8f65 | 4073 | ql_log(ql_log_warn, vha, 0xf02d, "qla_target(%d): SRR received\n", |
2d70c103 NB |
4074 | vha->vp_idx); |
4075 | ||
4076 | imm = kzalloc(sizeof(*imm), GFP_ATOMIC); | |
4077 | if (imm != NULL) { | |
4078 | memcpy(&imm->imm_ntfy, iocb, sizeof(imm->imm_ntfy)); | |
4079 | ||
4080 | /* IRQ is already OFF */ | |
4081 | spin_lock(&tgt->srr_lock); | |
4082 | imm->srr_id = tgt->imm_srr_id; | |
4083 | list_add_tail(&imm->srr_list_entry, | |
4084 | &tgt->srr_imm_list); | |
4085 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02e, | |
4086 | "IMM NTFY SRR %p added (id %d, ui %x)\n", | |
4087 | imm, imm->srr_id, iocb->u.isp24.srr_ui); | |
4088 | if (tgt->imm_srr_id == tgt->ctio_srr_id) { | |
4089 | int found = 0; | |
4090 | list_for_each_entry(sctio, &tgt->srr_ctio_list, | |
4091 | srr_list_entry) { | |
4092 | if (sctio->srr_id == imm->srr_id) { | |
4093 | found = 1; | |
4094 | break; | |
4095 | } | |
4096 | } | |
4097 | if (found) { | |
4098 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02f, "%s", | |
4099 | "Scheduling srr work\n"); | |
4100 | schedule_work(&tgt->srr_work); | |
4101 | } else { | |
4102 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf030, | |
4103 | "qla_target(%d): imm_srr_id " | |
4104 | "== ctio_srr_id (%d), but there is no " | |
4105 | "corresponding SRR CTIO, deleting IMM " | |
4106 | "SRR %p\n", vha->vp_idx, tgt->ctio_srr_id, | |
4107 | imm); | |
4108 | list_del(&imm->srr_list_entry); | |
4109 | ||
4110 | kfree(imm); | |
4111 | ||
4112 | spin_unlock(&tgt->srr_lock); | |
4113 | goto out_reject; | |
4114 | } | |
4115 | } | |
4116 | spin_unlock(&tgt->srr_lock); | |
4117 | } else { | |
4118 | struct qla_tgt_srr_ctio *ts; | |
4119 | ||
4120 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf069, | |
4121 | "qla_target(%d): Unable to allocate SRR IMM " | |
4122 | "entry, SRR request will be rejected\n", vha->vp_idx); | |
4123 | ||
4124 | /* IRQ is already OFF */ | |
4125 | spin_lock(&tgt->srr_lock); | |
4126 | list_for_each_entry_safe(sctio, ts, &tgt->srr_ctio_list, | |
4127 | srr_list_entry) { | |
4128 | if (sctio->srr_id == tgt->imm_srr_id) { | |
4129 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf031, | |
4130 | "CTIO SRR %p deleted (id %d)\n", | |
4131 | sctio, sctio->srr_id); | |
4132 | list_del(&sctio->srr_list_entry); | |
4133 | qlt_send_term_exchange(vha, sctio->cmd, | |
4134 | &sctio->cmd->atio, 1); | |
4135 | kfree(sctio); | |
4136 | } | |
4137 | } | |
4138 | spin_unlock(&tgt->srr_lock); | |
4139 | goto out_reject; | |
4140 | } | |
4141 | ||
4142 | return; | |
4143 | ||
4144 | out_reject: | |
4145 | qlt_send_notify_ack(vha, iocb, 0, 0, 0, | |
4146 | NOTIFY_ACK_SRR_FLAGS_REJECT, | |
4147 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, | |
4148 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); | |
4149 | } | |
4150 | ||
4151 | /* | |
4152 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
4153 | */ | |
4154 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, | |
4155 | struct imm_ntfy_from_isp *iocb) | |
4156 | { | |
4157 | struct qla_hw_data *ha = vha->hw; | |
4158 | uint32_t add_flags = 0; | |
4159 | int send_notify_ack = 1; | |
4160 | uint16_t status; | |
4161 | ||
4162 | status = le16_to_cpu(iocb->u.isp2x.status); | |
4163 | switch (status) { | |
4164 | case IMM_NTFY_LIP_RESET: | |
4165 | { | |
4166 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, | |
4167 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", | |
4168 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), | |
4169 | iocb->u.isp24.status_subcode); | |
4170 | ||
4171 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) | |
4172 | send_notify_ack = 0; | |
4173 | break; | |
4174 | } | |
4175 | ||
4176 | case IMM_NTFY_LIP_LINK_REINIT: | |
4177 | { | |
0e8cd71c | 4178 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
4179 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
4180 | "qla_target(%d): LINK REINIT (loop %#x, " | |
4181 | "subcode %x)\n", vha->vp_idx, | |
4182 | le16_to_cpu(iocb->u.isp24.nport_handle), | |
4183 | iocb->u.isp24.status_subcode); | |
4184 | if (tgt->link_reinit_iocb_pending) { | |
4185 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, | |
4186 | 0, 0, 0, 0, 0, 0); | |
4187 | } | |
4188 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); | |
4189 | tgt->link_reinit_iocb_pending = 1; | |
4190 | /* | |
4191 | * QLogic requires to wait after LINK REINIT for possible | |
4192 | * PDISC or ADISC ELS commands | |
4193 | */ | |
4194 | send_notify_ack = 0; | |
4195 | break; | |
4196 | } | |
4197 | ||
4198 | case IMM_NTFY_PORT_LOGOUT: | |
4199 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, | |
4200 | "qla_target(%d): Port logout (loop " | |
4201 | "%#x, subcode %x)\n", vha->vp_idx, | |
4202 | le16_to_cpu(iocb->u.isp24.nport_handle), | |
4203 | iocb->u.isp24.status_subcode); | |
4204 | ||
4205 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) | |
4206 | send_notify_ack = 0; | |
4207 | /* The sessions will be cleared in the callback, if needed */ | |
4208 | break; | |
4209 | ||
4210 | case IMM_NTFY_GLBL_TPRLO: | |
4211 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, | |
4212 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); | |
4213 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) | |
4214 | send_notify_ack = 0; | |
4215 | /* The sessions will be cleared in the callback, if needed */ | |
4216 | break; | |
4217 | ||
4218 | case IMM_NTFY_PORT_CONFIG: | |
4219 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, | |
4220 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, | |
4221 | status); | |
4222 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) | |
4223 | send_notify_ack = 0; | |
4224 | /* The sessions will be cleared in the callback, if needed */ | |
4225 | break; | |
4226 | ||
4227 | case IMM_NTFY_GLBL_LOGO: | |
4228 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, | |
4229 | "qla_target(%d): Link failure detected\n", | |
4230 | vha->vp_idx); | |
4231 | /* I_T nexus loss */ | |
4232 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) | |
4233 | send_notify_ack = 0; | |
4234 | break; | |
4235 | ||
4236 | case IMM_NTFY_IOCB_OVERFLOW: | |
4237 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, | |
4238 | "qla_target(%d): Cannot provide requested " | |
4239 | "capability (IOCB overflowed the immediate notify " | |
4240 | "resource count)\n", vha->vp_idx); | |
4241 | break; | |
4242 | ||
4243 | case IMM_NTFY_ABORT_TASK: | |
4244 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, | |
4245 | "qla_target(%d): Abort Task (S %08x I %#x -> " | |
4246 | "L %#x)\n", vha->vp_idx, | |
4247 | le16_to_cpu(iocb->u.isp2x.seq_id), | |
4248 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), | |
4249 | le16_to_cpu(iocb->u.isp2x.lun)); | |
4250 | if (qlt_abort_task(vha, iocb) == 0) | |
4251 | send_notify_ack = 0; | |
4252 | break; | |
4253 | ||
4254 | case IMM_NTFY_RESOURCE: | |
4255 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, | |
4256 | "qla_target(%d): Out of resources, host %ld\n", | |
4257 | vha->vp_idx, vha->host_no); | |
4258 | break; | |
4259 | ||
4260 | case IMM_NTFY_MSG_RX: | |
4261 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, | |
4262 | "qla_target(%d): Immediate notify task %x\n", | |
4263 | vha->vp_idx, iocb->u.isp2x.task_flags); | |
4264 | if (qlt_handle_task_mgmt(vha, iocb) == 0) | |
4265 | send_notify_ack = 0; | |
4266 | break; | |
4267 | ||
4268 | case IMM_NTFY_ELS: | |
4269 | if (qlt_24xx_handle_els(vha, iocb) == 0) | |
4270 | send_notify_ack = 0; | |
4271 | break; | |
4272 | ||
4273 | case IMM_NTFY_SRR: | |
4274 | qlt_prepare_srr_imm(vha, iocb); | |
4275 | send_notify_ack = 0; | |
4276 | break; | |
4277 | ||
4278 | default: | |
4279 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, | |
4280 | "qla_target(%d): Received unknown immediate " | |
4281 | "notify status %x\n", vha->vp_idx, status); | |
4282 | break; | |
4283 | } | |
4284 | ||
4285 | if (send_notify_ack) | |
4286 | qlt_send_notify_ack(vha, iocb, add_flags, 0, 0, 0, 0, 0); | |
4287 | } | |
4288 | ||
4289 | /* | |
4290 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
4291 | * This function sends busy to ISP 2xxx or 24xx. | |
4292 | */ | |
33e79977 | 4293 | static int __qlt_send_busy(struct scsi_qla_host *vha, |
2d70c103 NB |
4294 | struct atio_from_isp *atio, uint16_t status) |
4295 | { | |
4296 | struct ctio7_to_24xx *ctio24; | |
4297 | struct qla_hw_data *ha = vha->hw; | |
4298 | request_t *pkt; | |
4299 | struct qla_tgt_sess *sess = NULL; | |
4300 | ||
4301 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, | |
4302 | atio->u.isp24.fcp_hdr.s_id); | |
4303 | if (!sess) { | |
4304 | qlt_send_term_exchange(vha, NULL, atio, 1); | |
33e79977 | 4305 | return 0; |
2d70c103 NB |
4306 | } |
4307 | /* Sending marker isn't necessary, since we called from ISR */ | |
4308 | ||
4309 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); | |
4310 | if (!pkt) { | |
667024a3 | 4311 | ql_dbg(ql_dbg_io, vha, 0x3063, |
2d70c103 NB |
4312 | "qla_target(%d): %s failed: unable to allocate " |
4313 | "request packet", vha->vp_idx, __func__); | |
33e79977 | 4314 | return -ENOMEM; |
2d70c103 NB |
4315 | } |
4316 | ||
4317 | pkt->entry_count = 1; | |
4318 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | |
4319 | ||
4320 | ctio24 = (struct ctio7_to_24xx *)pkt; | |
4321 | ctio24->entry_type = CTIO_TYPE7; | |
4322 | ctio24->nport_handle = sess->loop_id; | |
4323 | ctio24->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | |
4324 | ctio24->vp_index = vha->vp_idx; | |
4325 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | |
4326 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | |
4327 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | |
4328 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; | |
4329 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | | |
4330 | __constant_cpu_to_le16( | |
4331 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | | |
4332 | CTIO7_FLAGS_DONT_RET_CTIO); | |
4333 | /* | |
4334 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, | |
4335 | * if the explicit conformation is used. | |
4336 | */ | |
4337 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); | |
4338 | ctio24->u.status1.scsi_status = cpu_to_le16(status); | |
63163e06 HM |
4339 | /* Memory Barrier */ |
4340 | wmb(); | |
2d70c103 | 4341 | qla2x00_start_iocbs(vha, vha->req); |
33e79977 QT |
4342 | return 0; |
4343 | } | |
4344 | ||
4345 | /* | |
4346 | * This routine is used to allocate a command for either a QFull condition | |
4347 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go | |
4348 | * out previously. | |
4349 | */ | |
4350 | static void | |
4351 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, | |
4352 | struct atio_from_isp *atio, uint16_t status, int qfull) | |
4353 | { | |
4354 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; | |
4355 | struct qla_hw_data *ha = vha->hw; | |
4356 | struct qla_tgt_sess *sess; | |
4357 | struct se_session *se_sess; | |
4358 | struct qla_tgt_cmd *cmd; | |
4359 | int tag; | |
4360 | ||
4361 | if (unlikely(tgt->tgt_stop)) { | |
4362 | ql_dbg(ql_dbg_io, vha, 0x300a, | |
4363 | "New command while device %p is shutting down\n", tgt); | |
4364 | return; | |
4365 | } | |
4366 | ||
4367 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { | |
4368 | vha->hw->tgt.num_qfull_cmds_dropped++; | |
4369 | if (vha->hw->tgt.num_qfull_cmds_dropped > | |
4370 | vha->hw->qla_stats.stat_max_qfull_cmds_dropped) | |
4371 | vha->hw->qla_stats.stat_max_qfull_cmds_dropped = | |
4372 | vha->hw->tgt.num_qfull_cmds_dropped; | |
4373 | ||
4374 | ql_dbg(ql_dbg_io, vha, 0x3068, | |
4375 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", | |
4376 | vha->vp_idx, __func__, | |
4377 | vha->hw->tgt.num_qfull_cmds_dropped); | |
4378 | ||
4379 | qlt_chk_exch_leak_thresh_hold(vha); | |
4380 | return; | |
4381 | } | |
4382 | ||
4383 | sess = ha->tgt.tgt_ops->find_sess_by_s_id | |
4384 | (vha, atio->u.isp24.fcp_hdr.s_id); | |
4385 | if (!sess) | |
4386 | return; | |
4387 | ||
4388 | se_sess = sess->se_sess; | |
4389 | ||
4390 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); | |
4391 | if (tag < 0) | |
4392 | return; | |
4393 | ||
4394 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; | |
4395 | if (!cmd) { | |
4396 | ql_dbg(ql_dbg_io, vha, 0x3009, | |
4397 | "qla_target(%d): %s: Allocation of cmd failed\n", | |
4398 | vha->vp_idx, __func__); | |
4399 | ||
4400 | vha->hw->tgt.num_qfull_cmds_dropped++; | |
4401 | if (vha->hw->tgt.num_qfull_cmds_dropped > | |
4402 | vha->hw->qla_stats.stat_max_qfull_cmds_dropped) | |
4403 | vha->hw->qla_stats.stat_max_qfull_cmds_dropped = | |
4404 | vha->hw->tgt.num_qfull_cmds_dropped; | |
4405 | ||
4406 | qlt_chk_exch_leak_thresh_hold(vha); | |
4407 | return; | |
4408 | } | |
4409 | ||
4410 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); | |
4411 | ||
4412 | qlt_incr_num_pend_cmds(vha); | |
4413 | INIT_LIST_HEAD(&cmd->cmd_list); | |
4414 | memcpy(&cmd->atio, atio, sizeof(*atio)); | |
4415 | ||
4416 | cmd->tgt = vha->vha_tgt.qla_tgt; | |
4417 | cmd->vha = vha; | |
4418 | cmd->reset_count = vha->hw->chip_reset; | |
4419 | cmd->q_full = 1; | |
4420 | ||
4421 | if (qfull) { | |
4422 | cmd->q_full = 1; | |
4423 | /* NOTE: borrowing the state field to carry the status */ | |
4424 | cmd->state = status; | |
4425 | } else | |
4426 | cmd->term_exchg = 1; | |
4427 | ||
4428 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); | |
4429 | ||
4430 | vha->hw->tgt.num_qfull_cmds_alloc++; | |
4431 | if (vha->hw->tgt.num_qfull_cmds_alloc > | |
4432 | vha->hw->qla_stats.stat_max_qfull_cmds_alloc) | |
4433 | vha->hw->qla_stats.stat_max_qfull_cmds_alloc = | |
4434 | vha->hw->tgt.num_qfull_cmds_alloc; | |
4435 | } | |
4436 | ||
4437 | int | |
4438 | qlt_free_qfull_cmds(struct scsi_qla_host *vha) | |
4439 | { | |
4440 | struct qla_hw_data *ha = vha->hw; | |
4441 | unsigned long flags; | |
4442 | struct qla_tgt_cmd *cmd, *tcmd; | |
4443 | struct list_head free_list; | |
4444 | int rc = 0; | |
4445 | ||
4446 | if (list_empty(&ha->tgt.q_full_list)) | |
4447 | return 0; | |
4448 | ||
4449 | INIT_LIST_HEAD(&free_list); | |
4450 | ||
4451 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); | |
4452 | ||
4453 | if (list_empty(&ha->tgt.q_full_list)) { | |
4454 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); | |
4455 | return 0; | |
4456 | } | |
4457 | ||
4458 | list_for_each_entry_safe(cmd, tcmd, &ha->tgt.q_full_list, cmd_list) { | |
4459 | if (cmd->q_full) | |
4460 | /* cmd->state is a borrowed field to hold status */ | |
4461 | rc = __qlt_send_busy(vha, &cmd->atio, cmd->state); | |
4462 | else if (cmd->term_exchg) | |
4463 | rc = __qlt_send_term_exchange(vha, NULL, &cmd->atio); | |
4464 | ||
4465 | if (rc == -ENOMEM) | |
4466 | break; | |
4467 | ||
4468 | if (cmd->q_full) | |
4469 | ql_dbg(ql_dbg_io, vha, 0x3006, | |
4470 | "%s: busy sent for ox_id[%04x]\n", __func__, | |
4471 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); | |
4472 | else if (cmd->term_exchg) | |
4473 | ql_dbg(ql_dbg_io, vha, 0x3007, | |
4474 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, | |
4475 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); | |
4476 | else | |
4477 | ql_dbg(ql_dbg_io, vha, 0x3008, | |
4478 | "%s: Unexpected cmd in QFull list %p\n", __func__, | |
4479 | cmd); | |
4480 | ||
4481 | list_del(&cmd->cmd_list); | |
4482 | list_add_tail(&cmd->cmd_list, &free_list); | |
4483 | ||
4484 | /* piggy back on hardware_lock for protection */ | |
4485 | vha->hw->tgt.num_qfull_cmds_alloc--; | |
4486 | } | |
4487 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); | |
4488 | ||
4489 | cmd = NULL; | |
4490 | ||
4491 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { | |
4492 | list_del(&cmd->cmd_list); | |
4493 | /* This cmd was never sent to TCM. There is no need | |
4494 | * to schedule free or call free_cmd | |
4495 | */ | |
4496 | qlt_free_cmd(cmd); | |
4497 | } | |
4498 | return rc; | |
4499 | } | |
4500 | ||
4501 | static void | |
4502 | qlt_send_busy(struct scsi_qla_host *vha, | |
4503 | struct atio_from_isp *atio, uint16_t status) | |
4504 | { | |
4505 | int rc = 0; | |
4506 | ||
4507 | rc = __qlt_send_busy(vha, atio, status); | |
4508 | if (rc == -ENOMEM) | |
4509 | qlt_alloc_qfull_cmd(vha, atio, status, 1); | |
4510 | } | |
4511 | ||
4512 | static int | |
4513 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, | |
4514 | struct atio_from_isp *atio) | |
4515 | { | |
4516 | struct qla_hw_data *ha = vha->hw; | |
4517 | uint16_t status; | |
4518 | ||
4519 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) | |
4520 | return 0; | |
4521 | ||
4522 | status = temp_sam_status; | |
4523 | qlt_send_busy(vha, atio, status); | |
4524 | return 1; | |
2d70c103 NB |
4525 | } |
4526 | ||
4527 | /* ha->hardware_lock supposed to be held on entry */ | |
4528 | /* called via callback from qla2xxx */ | |
4529 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, | |
4530 | struct atio_from_isp *atio) | |
4531 | { | |
4532 | struct qla_hw_data *ha = vha->hw; | |
0e8cd71c | 4533 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
4534 | int rc; |
4535 | ||
4536 | if (unlikely(tgt == NULL)) { | |
667024a3 | 4537 | ql_dbg(ql_dbg_io, vha, 0x3064, |
2d70c103 NB |
4538 | "ATIO pkt, but no tgt (ha %p)", ha); |
4539 | return; | |
4540 | } | |
2d70c103 NB |
4541 | /* |
4542 | * In tgt_stop mode we also should allow all requests to pass. | |
4543 | * Otherwise, some commands can stuck. | |
4544 | */ | |
4545 | ||
4546 | tgt->irq_cmd_count++; | |
4547 | ||
4548 | switch (atio->u.raw.entry_type) { | |
4549 | case ATIO_TYPE7: | |
2d70c103 NB |
4550 | if (unlikely(atio->u.isp24.exchange_addr == |
4551 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { | |
667024a3 | 4552 | ql_dbg(ql_dbg_io, vha, 0x3065, |
2d70c103 NB |
4553 | "qla_target(%d): ATIO_TYPE7 " |
4554 | "received with UNKNOWN exchange address, " | |
4555 | "sending QUEUE_FULL\n", vha->vp_idx); | |
4556 | qlt_send_busy(vha, atio, SAM_STAT_TASK_SET_FULL); | |
4557 | break; | |
4558 | } | |
33e79977 QT |
4559 | |
4560 | ||
4561 | ||
4562 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { | |
4563 | rc = qlt_chk_qfull_thresh_hold(vha, atio); | |
4564 | if (rc != 0) { | |
4565 | tgt->irq_cmd_count--; | |
4566 | return; | |
4567 | } | |
2d70c103 | 4568 | rc = qlt_handle_cmd_for_atio(vha, atio); |
33e79977 | 4569 | } else { |
2d70c103 | 4570 | rc = qlt_handle_task_mgmt(vha, atio); |
33e79977 | 4571 | } |
2d70c103 NB |
4572 | if (unlikely(rc != 0)) { |
4573 | if (rc == -ESRCH) { | |
4574 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ | |
4575 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); | |
4576 | #else | |
4577 | qlt_send_term_exchange(vha, NULL, atio, 1); | |
4578 | #endif | |
4579 | } else { | |
4580 | if (tgt->tgt_stop) { | |
4581 | ql_dbg(ql_dbg_tgt, vha, 0xe059, | |
4582 | "qla_target: Unable to send " | |
4583 | "command to target for req, " | |
4584 | "ignoring.\n"); | |
4585 | } else { | |
4586 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, | |
4587 | "qla_target(%d): Unable to send " | |
4588 | "command to target, sending BUSY " | |
4589 | "status.\n", vha->vp_idx); | |
4590 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); | |
4591 | } | |
4592 | } | |
4593 | } | |
4594 | break; | |
4595 | ||
4596 | case IMMED_NOTIFY_TYPE: | |
4597 | { | |
4598 | if (unlikely(atio->u.isp2x.entry_status != 0)) { | |
4599 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, | |
4600 | "qla_target(%d): Received ATIO packet %x " | |
4601 | "with error status %x\n", vha->vp_idx, | |
4602 | atio->u.raw.entry_type, | |
4603 | atio->u.isp2x.entry_status); | |
4604 | break; | |
4605 | } | |
4606 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); | |
4607 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); | |
4608 | break; | |
4609 | } | |
4610 | ||
4611 | default: | |
4612 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, | |
4613 | "qla_target(%d): Received unknown ATIO atio " | |
4614 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); | |
4615 | break; | |
4616 | } | |
4617 | ||
4618 | tgt->irq_cmd_count--; | |
4619 | } | |
4620 | ||
4621 | /* ha->hardware_lock supposed to be held on entry */ | |
4622 | /* called via callback from qla2xxx */ | |
4623 | static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) | |
4624 | { | |
4625 | struct qla_hw_data *ha = vha->hw; | |
0e8cd71c | 4626 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
4627 | |
4628 | if (unlikely(tgt == NULL)) { | |
4629 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, | |
4630 | "qla_target(%d): Response pkt %x received, but no " | |
4631 | "tgt (ha %p)\n", vha->vp_idx, pkt->entry_type, ha); | |
4632 | return; | |
4633 | } | |
4634 | ||
2d70c103 NB |
4635 | /* |
4636 | * In tgt_stop mode we also should allow all requests to pass. | |
4637 | * Otherwise, some commands can stuck. | |
4638 | */ | |
4639 | ||
4640 | tgt->irq_cmd_count++; | |
4641 | ||
4642 | switch (pkt->entry_type) { | |
f83adb61 | 4643 | case CTIO_CRC2: |
2d70c103 NB |
4644 | case CTIO_TYPE7: |
4645 | { | |
4646 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; | |
2d70c103 NB |
4647 | qlt_do_ctio_completion(vha, entry->handle, |
4648 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), | |
4649 | entry); | |
4650 | break; | |
4651 | } | |
4652 | ||
4653 | case ACCEPT_TGT_IO_TYPE: | |
4654 | { | |
4655 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; | |
4656 | int rc; | |
2d70c103 NB |
4657 | if (atio->u.isp2x.status != |
4658 | __constant_cpu_to_le16(ATIO_CDB_VALID)) { | |
4659 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, | |
4660 | "qla_target(%d): ATIO with error " | |
4661 | "status %x received\n", vha->vp_idx, | |
4662 | le16_to_cpu(atio->u.isp2x.status)); | |
4663 | break; | |
4664 | } | |
2d70c103 | 4665 | |
33e79977 QT |
4666 | rc = qlt_chk_qfull_thresh_hold(vha, atio); |
4667 | if (rc != 0) { | |
4668 | tgt->irq_cmd_count--; | |
4669 | return; | |
4670 | } | |
4671 | ||
2d70c103 NB |
4672 | rc = qlt_handle_cmd_for_atio(vha, atio); |
4673 | if (unlikely(rc != 0)) { | |
4674 | if (rc == -ESRCH) { | |
4675 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ | |
4676 | qlt_send_busy(vha, atio, 0); | |
4677 | #else | |
4678 | qlt_send_term_exchange(vha, NULL, atio, 1); | |
4679 | #endif | |
4680 | } else { | |
4681 | if (tgt->tgt_stop) { | |
4682 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, | |
4683 | "qla_target: Unable to send " | |
4684 | "command to target, sending TERM " | |
4685 | "EXCHANGE for rsp\n"); | |
4686 | qlt_send_term_exchange(vha, NULL, | |
4687 | atio, 1); | |
4688 | } else { | |
4689 | ql_dbg(ql_dbg_tgt, vha, 0xe060, | |
4690 | "qla_target(%d): Unable to send " | |
4691 | "command to target, sending BUSY " | |
4692 | "status\n", vha->vp_idx); | |
4693 | qlt_send_busy(vha, atio, 0); | |
4694 | } | |
4695 | } | |
4696 | } | |
4697 | } | |
4698 | break; | |
4699 | ||
4700 | case CONTINUE_TGT_IO_TYPE: | |
4701 | { | |
4702 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; | |
2d70c103 NB |
4703 | qlt_do_ctio_completion(vha, entry->handle, |
4704 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), | |
4705 | entry); | |
4706 | break; | |
4707 | } | |
4708 | ||
4709 | case CTIO_A64_TYPE: | |
4710 | { | |
4711 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; | |
2d70c103 NB |
4712 | qlt_do_ctio_completion(vha, entry->handle, |
4713 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), | |
4714 | entry); | |
4715 | break; | |
4716 | } | |
4717 | ||
4718 | case IMMED_NOTIFY_TYPE: | |
4719 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); | |
4720 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); | |
4721 | break; | |
4722 | ||
4723 | case NOTIFY_ACK_TYPE: | |
4724 | if (tgt->notify_ack_expected > 0) { | |
4725 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; | |
4726 | ql_dbg(ql_dbg_tgt, vha, 0xe036, | |
4727 | "NOTIFY_ACK seq %08x status %x\n", | |
4728 | le16_to_cpu(entry->u.isp2x.seq_id), | |
4729 | le16_to_cpu(entry->u.isp2x.status)); | |
4730 | tgt->notify_ack_expected--; | |
4731 | if (entry->u.isp2x.status != | |
4732 | __constant_cpu_to_le16(NOTIFY_ACK_SUCCESS)) { | |
4733 | ql_dbg(ql_dbg_tgt, vha, 0xe061, | |
4734 | "qla_target(%d): NOTIFY_ACK " | |
4735 | "failed %x\n", vha->vp_idx, | |
4736 | le16_to_cpu(entry->u.isp2x.status)); | |
4737 | } | |
4738 | } else { | |
4739 | ql_dbg(ql_dbg_tgt, vha, 0xe062, | |
4740 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", | |
4741 | vha->vp_idx); | |
4742 | } | |
4743 | break; | |
4744 | ||
4745 | case ABTS_RECV_24XX: | |
4746 | ql_dbg(ql_dbg_tgt, vha, 0xe037, | |
4747 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); | |
4748 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); | |
4749 | break; | |
4750 | ||
4751 | case ABTS_RESP_24XX: | |
4752 | if (tgt->abts_resp_expected > 0) { | |
4753 | struct abts_resp_from_24xx_fw *entry = | |
4754 | (struct abts_resp_from_24xx_fw *)pkt; | |
4755 | ql_dbg(ql_dbg_tgt, vha, 0xe038, | |
4756 | "ABTS_RESP_24XX: compl_status %x\n", | |
4757 | entry->compl_status); | |
4758 | tgt->abts_resp_expected--; | |
4759 | if (le16_to_cpu(entry->compl_status) != | |
4760 | ABTS_RESP_COMPL_SUCCESS) { | |
4761 | if ((entry->error_subcode1 == 0x1E) && | |
4762 | (entry->error_subcode2 == 0)) { | |
4763 | /* | |
4764 | * We've got a race here: aborted | |
4765 | * exchange not terminated, i.e. | |
4766 | * response for the aborted command was | |
4767 | * sent between the abort request was | |
4768 | * received and processed. | |
4769 | * Unfortunately, the firmware has a | |
4770 | * silly requirement that all aborted | |
4771 | * exchanges must be explicitely | |
4772 | * terminated, otherwise it refuses to | |
4773 | * send responses for the abort | |
4774 | * requests. So, we have to | |
4775 | * (re)terminate the exchange and retry | |
4776 | * the abort response. | |
4777 | */ | |
4778 | qlt_24xx_retry_term_exchange(vha, | |
4779 | entry); | |
4780 | } else | |
4781 | ql_dbg(ql_dbg_tgt, vha, 0xe063, | |
4782 | "qla_target(%d): ABTS_RESP_24XX " | |
4783 | "failed %x (subcode %x:%x)", | |
4784 | vha->vp_idx, entry->compl_status, | |
4785 | entry->error_subcode1, | |
4786 | entry->error_subcode2); | |
4787 | } | |
4788 | } else { | |
4789 | ql_dbg(ql_dbg_tgt, vha, 0xe064, | |
4790 | "qla_target(%d): Unexpected ABTS_RESP_24XX " | |
4791 | "received\n", vha->vp_idx); | |
4792 | } | |
4793 | break; | |
4794 | ||
4795 | default: | |
4796 | ql_dbg(ql_dbg_tgt, vha, 0xe065, | |
4797 | "qla_target(%d): Received unknown response pkt " | |
4798 | "type %x\n", vha->vp_idx, pkt->entry_type); | |
4799 | break; | |
4800 | } | |
4801 | ||
4802 | tgt->irq_cmd_count--; | |
4803 | } | |
4804 | ||
4805 | /* | |
4806 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | |
4807 | */ | |
4808 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, | |
4809 | uint16_t *mailbox) | |
4810 | { | |
4811 | struct qla_hw_data *ha = vha->hw; | |
0e8cd71c | 4812 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
4f1d0f19 | 4813 | int login_code; |
2d70c103 | 4814 | |
2d70c103 NB |
4815 | if (!ha->tgt.tgt_ops) |
4816 | return; | |
4817 | ||
4818 | if (unlikely(tgt == NULL)) { | |
4819 | ql_dbg(ql_dbg_tgt, vha, 0xe03a, | |
4820 | "ASYNC EVENT %#x, but no tgt (ha %p)\n", code, ha); | |
4821 | return; | |
4822 | } | |
4823 | ||
4824 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && | |
4825 | IS_QLA2100(ha)) | |
4826 | return; | |
4827 | /* | |
4828 | * In tgt_stop mode we also should allow all requests to pass. | |
4829 | * Otherwise, some commands can stuck. | |
4830 | */ | |
4831 | ||
4832 | tgt->irq_cmd_count++; | |
4833 | ||
4834 | switch (code) { | |
4835 | case MBA_RESET: /* Reset */ | |
4836 | case MBA_SYSTEM_ERR: /* System Error */ | |
4837 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ | |
4838 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ | |
4839 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, | |
4840 | "qla_target(%d): System error async event %#x " | |
6efb3c0a | 4841 | "occurred", vha->vp_idx, code); |
2d70c103 NB |
4842 | break; |
4843 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ | |
4844 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
4845 | break; | |
4846 | ||
4847 | case MBA_LOOP_UP: | |
4848 | { | |
4849 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, | |
6efb3c0a | 4850 | "qla_target(%d): Async LOOP_UP occurred " |
4f1d0f19 AC |
4851 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
4852 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), | |
4853 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); | |
2d70c103 NB |
4854 | if (tgt->link_reinit_iocb_pending) { |
4855 | qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb, | |
4856 | 0, 0, 0, 0, 0, 0); | |
4857 | tgt->link_reinit_iocb_pending = 0; | |
4858 | } | |
4859 | break; | |
4860 | } | |
4861 | ||
4862 | case MBA_LIP_OCCURRED: | |
4863 | case MBA_LOOP_DOWN: | |
4864 | case MBA_LIP_RESET: | |
4865 | case MBA_RSCN_UPDATE: | |
4866 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, | |
6efb3c0a | 4867 | "qla_target(%d): Async event %#x occurred " |
4f1d0f19 AC |
4868 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
4869 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), | |
4870 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); | |
2d70c103 NB |
4871 | break; |
4872 | ||
4873 | case MBA_PORT_UPDATE: | |
4874 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, | |
4875 | "qla_target(%d): Port update async event %#x " | |
6efb3c0a | 4876 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
4f1d0f19 AC |
4877 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
4878 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), | |
4879 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); | |
4880 | ||
4881 | login_code = le16_to_cpu(mailbox[2]); | |
4882 | if (login_code == 0x4) | |
2d70c103 NB |
4883 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
4884 | "Async MB 2: Got PLOGI Complete\n"); | |
4f1d0f19 | 4885 | else if (login_code == 0x7) |
2d70c103 NB |
4886 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
4887 | "Async MB 2: Port Logged Out\n"); | |
4888 | break; | |
4889 | ||
4890 | default: | |
2d70c103 NB |
4891 | break; |
4892 | } | |
4893 | ||
4894 | tgt->irq_cmd_count--; | |
4895 | } | |
4896 | ||
4897 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, | |
4898 | uint16_t loop_id) | |
4899 | { | |
4900 | fc_port_t *fcport; | |
4901 | int rc; | |
4902 | ||
4903 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); | |
4904 | if (!fcport) { | |
4905 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, | |
4906 | "qla_target(%d): Allocation of tmp FC port failed", | |
4907 | vha->vp_idx); | |
4908 | return NULL; | |
4909 | } | |
4910 | ||
2d70c103 NB |
4911 | fcport->loop_id = loop_id; |
4912 | ||
4913 | rc = qla2x00_get_port_database(vha, fcport, 0); | |
4914 | if (rc != QLA_SUCCESS) { | |
4915 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, | |
4916 | "qla_target(%d): Failed to retrieve fcport " | |
4917 | "information -- get_port_database() returned %x " | |
4918 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); | |
4919 | kfree(fcport); | |
4920 | return NULL; | |
4921 | } | |
4922 | ||
4923 | return fcport; | |
4924 | } | |
4925 | ||
4926 | /* Must be called under tgt_mutex */ | |
4927 | static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *vha, | |
4928 | uint8_t *s_id) | |
4929 | { | |
2d70c103 NB |
4930 | struct qla_tgt_sess *sess = NULL; |
4931 | fc_port_t *fcport = NULL; | |
4932 | int rc, global_resets; | |
4933 | uint16_t loop_id = 0; | |
4934 | ||
4935 | retry: | |
0e8cd71c SK |
4936 | global_resets = |
4937 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); | |
2d70c103 NB |
4938 | |
4939 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); | |
4940 | if (rc != 0) { | |
4941 | if ((s_id[0] == 0xFF) && | |
4942 | (s_id[1] == 0xFC)) { | |
4943 | /* | |
4944 | * This is Domain Controller, so it should be | |
4945 | * OK to drop SCSI commands from it. | |
4946 | */ | |
4947 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, | |
4948 | "Unable to find initiator with S_ID %x:%x:%x", | |
4949 | s_id[0], s_id[1], s_id[2]); | |
4950 | } else | |
4951 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf071, | |
4952 | "qla_target(%d): Unable to find " | |
4953 | "initiator with S_ID %x:%x:%x", | |
4954 | vha->vp_idx, s_id[0], s_id[1], | |
4955 | s_id[2]); | |
4956 | return NULL; | |
4957 | } | |
4958 | ||
4959 | fcport = qlt_get_port_database(vha, loop_id); | |
4960 | if (!fcport) | |
4961 | return NULL; | |
4962 | ||
4963 | if (global_resets != | |
0e8cd71c | 4964 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
2d70c103 NB |
4965 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
4966 | "qla_target(%d): global reset during session discovery " | |
4967 | "(counter was %d, new %d), retrying", vha->vp_idx, | |
4968 | global_resets, | |
0e8cd71c SK |
4969 | atomic_read(&vha->vha_tgt. |
4970 | qla_tgt->tgt_global_resets_count)); | |
2d70c103 NB |
4971 | goto retry; |
4972 | } | |
4973 | ||
4974 | sess = qlt_create_sess(vha, fcport, true); | |
4975 | ||
4976 | kfree(fcport); | |
4977 | return sess; | |
4978 | } | |
4979 | ||
4980 | static void qlt_abort_work(struct qla_tgt *tgt, | |
4981 | struct qla_tgt_sess_work_param *prm) | |
4982 | { | |
4983 | struct scsi_qla_host *vha = tgt->vha; | |
4984 | struct qla_hw_data *ha = vha->hw; | |
4985 | struct qla_tgt_sess *sess = NULL; | |
4986 | unsigned long flags; | |
4987 | uint32_t be_s_id; | |
4988 | uint8_t s_id[3]; | |
4989 | int rc; | |
4990 | ||
4991 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
4992 | ||
4993 | if (tgt->tgt_stop) | |
4994 | goto out_term; | |
4995 | ||
4996 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; | |
4997 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; | |
4998 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; | |
4999 | ||
5000 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, | |
5001 | (unsigned char *)&be_s_id); | |
5002 | if (!sess) { | |
5003 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
5004 | ||
0e8cd71c | 5005 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
2d70c103 NB |
5006 | sess = qlt_make_local_sess(vha, s_id); |
5007 | /* sess has got an extra creation ref */ | |
0e8cd71c | 5008 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
2d70c103 NB |
5009 | |
5010 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
5011 | if (!sess) | |
5012 | goto out_term; | |
5013 | } else { | |
5014 | kref_get(&sess->se_sess->sess_kref); | |
5015 | } | |
5016 | ||
5017 | if (tgt->tgt_stop) | |
5018 | goto out_term; | |
5019 | ||
5020 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); | |
5021 | if (rc != 0) | |
5022 | goto out_term; | |
2d70c103 NB |
5023 | |
5024 | ha->tgt.tgt_ops->put_sess(sess); | |
08234e3a | 5025 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2d70c103 NB |
5026 | return; |
5027 | ||
5028 | out_term: | |
5029 | qlt_24xx_send_abts_resp(vha, &prm->abts, FCP_TMF_REJECTED, false); | |
2d70c103 NB |
5030 | if (sess) |
5031 | ha->tgt.tgt_ops->put_sess(sess); | |
08234e3a | 5032 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2d70c103 NB |
5033 | } |
5034 | ||
5035 | static void qlt_tmr_work(struct qla_tgt *tgt, | |
5036 | struct qla_tgt_sess_work_param *prm) | |
5037 | { | |
5038 | struct atio_from_isp *a = &prm->tm_iocb2; | |
5039 | struct scsi_qla_host *vha = tgt->vha; | |
5040 | struct qla_hw_data *ha = vha->hw; | |
5041 | struct qla_tgt_sess *sess = NULL; | |
5042 | unsigned long flags; | |
5043 | uint8_t *s_id = NULL; /* to hide compiler warnings */ | |
5044 | int rc; | |
5045 | uint32_t lun, unpacked_lun; | |
5046 | int lun_size, fn; | |
5047 | void *iocb; | |
5048 | ||
5049 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
5050 | ||
5051 | if (tgt->tgt_stop) | |
5052 | goto out_term; | |
5053 | ||
5054 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; | |
5055 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); | |
5056 | if (!sess) { | |
5057 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
5058 | ||
0e8cd71c | 5059 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
2d70c103 NB |
5060 | sess = qlt_make_local_sess(vha, s_id); |
5061 | /* sess has got an extra creation ref */ | |
0e8cd71c | 5062 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
2d70c103 NB |
5063 | |
5064 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
5065 | if (!sess) | |
5066 | goto out_term; | |
5067 | } else { | |
5068 | kref_get(&sess->se_sess->sess_kref); | |
5069 | } | |
5070 | ||
5071 | iocb = a; | |
5072 | lun = a->u.isp24.fcp_cmnd.lun; | |
5073 | lun_size = sizeof(lun); | |
5074 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; | |
5075 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | |
5076 | ||
5077 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); | |
5078 | if (rc != 0) | |
5079 | goto out_term; | |
2d70c103 NB |
5080 | |
5081 | ha->tgt.tgt_ops->put_sess(sess); | |
08234e3a | 5082 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2d70c103 NB |
5083 | return; |
5084 | ||
5085 | out_term: | |
5086 | qlt_send_term_exchange(vha, NULL, &prm->tm_iocb2, 1); | |
2d70c103 NB |
5087 | if (sess) |
5088 | ha->tgt.tgt_ops->put_sess(sess); | |
08234e3a | 5089 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
2d70c103 NB |
5090 | } |
5091 | ||
5092 | static void qlt_sess_work_fn(struct work_struct *work) | |
5093 | { | |
5094 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); | |
5095 | struct scsi_qla_host *vha = tgt->vha; | |
5096 | unsigned long flags; | |
5097 | ||
5098 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); | |
5099 | ||
5100 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | |
5101 | while (!list_empty(&tgt->sess_works_list)) { | |
5102 | struct qla_tgt_sess_work_param *prm = list_entry( | |
5103 | tgt->sess_works_list.next, typeof(*prm), | |
5104 | sess_works_list_entry); | |
5105 | ||
5106 | /* | |
5107 | * This work can be scheduled on several CPUs at time, so we | |
5108 | * must delete the entry to eliminate double processing | |
5109 | */ | |
5110 | list_del(&prm->sess_works_list_entry); | |
5111 | ||
5112 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | |
5113 | ||
5114 | switch (prm->type) { | |
5115 | case QLA_TGT_SESS_WORK_ABORT: | |
5116 | qlt_abort_work(tgt, prm); | |
5117 | break; | |
5118 | case QLA_TGT_SESS_WORK_TM: | |
5119 | qlt_tmr_work(tgt, prm); | |
5120 | break; | |
5121 | default: | |
5122 | BUG_ON(1); | |
5123 | break; | |
5124 | } | |
5125 | ||
5126 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | |
5127 | ||
5128 | kfree(prm); | |
5129 | } | |
5130 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | |
5131 | } | |
5132 | ||
5133 | /* Must be called under tgt_host_action_mutex */ | |
5134 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) | |
5135 | { | |
5136 | struct qla_tgt *tgt; | |
5137 | ||
5138 | if (!QLA_TGT_MODE_ENABLED()) | |
5139 | return 0; | |
5140 | ||
33c36c0a AE |
5141 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
5142 | ql_log(ql_log_warn, base_vha, 0xe070, | |
5143 | "This adapter does not support target mode.\n"); | |
5144 | return 0; | |
5145 | } | |
5146 | ||
2d70c103 | 5147 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
0e8cd71c | 5148 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
2d70c103 | 5149 | |
0e8cd71c | 5150 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
2d70c103 NB |
5151 | |
5152 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); | |
5153 | if (!tgt) { | |
5154 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, | |
5155 | "Unable to allocate struct qla_tgt\n"); | |
5156 | return -ENOMEM; | |
5157 | } | |
5158 | ||
5159 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) | |
5160 | base_vha->host->hostt->supported_mode |= MODE_TARGET; | |
5161 | ||
5162 | tgt->ha = ha; | |
5163 | tgt->vha = base_vha; | |
5164 | init_waitqueue_head(&tgt->waitQ); | |
5165 | INIT_LIST_HEAD(&tgt->sess_list); | |
5166 | INIT_LIST_HEAD(&tgt->del_sess_list); | |
5167 | INIT_DELAYED_WORK(&tgt->sess_del_work, | |
5168 | (void (*)(struct work_struct *))qlt_del_sess_work_fn); | |
5169 | spin_lock_init(&tgt->sess_work_lock); | |
5170 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); | |
5171 | INIT_LIST_HEAD(&tgt->sess_works_list); | |
5172 | spin_lock_init(&tgt->srr_lock); | |
5173 | INIT_LIST_HEAD(&tgt->srr_ctio_list); | |
5174 | INIT_LIST_HEAD(&tgt->srr_imm_list); | |
5175 | INIT_WORK(&tgt->srr_work, qlt_handle_srr_work); | |
5176 | atomic_set(&tgt->tgt_global_resets_count, 0); | |
5177 | ||
0e8cd71c | 5178 | base_vha->vha_tgt.qla_tgt = tgt; |
2d70c103 NB |
5179 | |
5180 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, | |
5181 | "qla_target(%d): using 64 Bit PCI addressing", | |
5182 | base_vha->vp_idx); | |
5183 | tgt->tgt_enable_64bit_addr = 1; | |
5184 | /* 3 is reserved */ | |
5185 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); | |
5186 | tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; | |
5187 | tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; | |
5188 | ||
ddb95145 NB |
5189 | if (base_vha->fc_vport) |
5190 | return 0; | |
5191 | ||
2d70c103 NB |
5192 | mutex_lock(&qla_tgt_mutex); |
5193 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); | |
5194 | mutex_unlock(&qla_tgt_mutex); | |
5195 | ||
5196 | return 0; | |
5197 | } | |
5198 | ||
5199 | /* Must be called under tgt_host_action_mutex */ | |
5200 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) | |
5201 | { | |
0e8cd71c | 5202 | if (!vha->vha_tgt.qla_tgt) |
2d70c103 NB |
5203 | return 0; |
5204 | ||
ddb95145 NB |
5205 | if (vha->fc_vport) { |
5206 | qlt_release(vha->vha_tgt.qla_tgt); | |
5207 | return 0; | |
5208 | } | |
33e79977 QT |
5209 | |
5210 | /* free left over qfull cmds */ | |
5211 | qlt_init_term_exchange(vha); | |
5212 | ||
2d70c103 | 5213 | mutex_lock(&qla_tgt_mutex); |
0e8cd71c | 5214 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
2d70c103 NB |
5215 | mutex_unlock(&qla_tgt_mutex); |
5216 | ||
5217 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", | |
5218 | vha->host_no, ha); | |
0e8cd71c | 5219 | qlt_release(vha->vha_tgt.qla_tgt); |
2d70c103 NB |
5220 | |
5221 | return 0; | |
5222 | } | |
5223 | ||
5224 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, | |
5225 | unsigned char *b) | |
5226 | { | |
5227 | int i; | |
5228 | ||
5229 | pr_debug("qla2xxx HW vha->node_name: "); | |
5230 | for (i = 0; i < WWN_SIZE; i++) | |
5231 | pr_debug("%02x ", vha->node_name[i]); | |
5232 | pr_debug("\n"); | |
5233 | pr_debug("qla2xxx HW vha->port_name: "); | |
5234 | for (i = 0; i < WWN_SIZE; i++) | |
5235 | pr_debug("%02x ", vha->port_name[i]); | |
5236 | pr_debug("\n"); | |
5237 | ||
5238 | pr_debug("qla2xxx passed configfs WWPN: "); | |
5239 | put_unaligned_be64(wwpn, b); | |
5240 | for (i = 0; i < WWN_SIZE; i++) | |
5241 | pr_debug("%02x ", b[i]); | |
5242 | pr_debug("\n"); | |
5243 | } | |
5244 | ||
5245 | /** | |
5246 | * qla_tgt_lport_register - register lport with external module | |
5247 | * | |
5248 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops | |
5249 | * @wwpn: Passwd FC target WWPN | |
5250 | * @callback: lport initialization callback for tcm_qla2xxx code | |
5251 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data | |
5252 | */ | |
49a47f2c NB |
5253 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
5254 | u64 npiv_wwpn, u64 npiv_wwnn, | |
5255 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) | |
2d70c103 NB |
5256 | { |
5257 | struct qla_tgt *tgt; | |
5258 | struct scsi_qla_host *vha; | |
5259 | struct qla_hw_data *ha; | |
5260 | struct Scsi_Host *host; | |
5261 | unsigned long flags; | |
5262 | int rc; | |
5263 | u8 b[WWN_SIZE]; | |
5264 | ||
5265 | mutex_lock(&qla_tgt_mutex); | |
5266 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { | |
5267 | vha = tgt->vha; | |
5268 | ha = vha->hw; | |
5269 | ||
5270 | host = vha->host; | |
5271 | if (!host) | |
5272 | continue; | |
5273 | ||
2d70c103 NB |
5274 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
5275 | continue; | |
5276 | ||
5277 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
49a47f2c | 5278 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
2d70c103 NB |
5279 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
5280 | host->host_no); | |
5281 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
5282 | continue; | |
5283 | } | |
ddb95145 NB |
5284 | if (tgt->tgt_stop) { |
5285 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", | |
5286 | host->host_no); | |
5287 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
5288 | continue; | |
5289 | } | |
2d70c103 NB |
5290 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
5291 | ||
5292 | if (!scsi_host_get(host)) { | |
5293 | ql_dbg(ql_dbg_tgt, vha, 0xe068, | |
5294 | "Unable to scsi_host_get() for" | |
5295 | " qla2xxx scsi_host\n"); | |
5296 | continue; | |
5297 | } | |
49a47f2c | 5298 | qlt_lport_dump(vha, phys_wwpn, b); |
2d70c103 NB |
5299 | |
5300 | if (memcmp(vha->port_name, b, WWN_SIZE)) { | |
5301 | scsi_host_put(host); | |
5302 | continue; | |
5303 | } | |
49a47f2c NB |
5304 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
5305 | if (rc != 0) | |
5306 | scsi_host_put(host); | |
5307 | ||
ddb95145 | 5308 | mutex_unlock(&qla_tgt_mutex); |
2d70c103 NB |
5309 | return rc; |
5310 | } | |
5311 | mutex_unlock(&qla_tgt_mutex); | |
5312 | ||
5313 | return -ENODEV; | |
5314 | } | |
5315 | EXPORT_SYMBOL(qlt_lport_register); | |
5316 | ||
5317 | /** | |
5318 | * qla_tgt_lport_deregister - Degister lport | |
5319 | * | |
5320 | * @vha: Registered scsi_qla_host pointer | |
5321 | */ | |
5322 | void qlt_lport_deregister(struct scsi_qla_host *vha) | |
5323 | { | |
5324 | struct qla_hw_data *ha = vha->hw; | |
5325 | struct Scsi_Host *sh = vha->host; | |
5326 | /* | |
5327 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data | |
5328 | */ | |
0e8cd71c | 5329 | vha->vha_tgt.target_lport_ptr = NULL; |
2d70c103 NB |
5330 | ha->tgt.tgt_ops = NULL; |
5331 | /* | |
5332 | * Release the Scsi_Host reference for the underlying qla2xxx host | |
5333 | */ | |
5334 | scsi_host_put(sh); | |
5335 | } | |
5336 | EXPORT_SYMBOL(qlt_lport_deregister); | |
5337 | ||
5338 | /* Must be called under HW lock */ | |
55a9066f | 5339 | static void qlt_set_mode(struct scsi_qla_host *vha) |
2d70c103 NB |
5340 | { |
5341 | struct qla_hw_data *ha = vha->hw; | |
5342 | ||
5343 | switch (ql2x_ini_mode) { | |
5344 | case QLA2XXX_INI_MODE_DISABLED: | |
5345 | case QLA2XXX_INI_MODE_EXCLUSIVE: | |
5346 | vha->host->active_mode = MODE_TARGET; | |
5347 | break; | |
5348 | case QLA2XXX_INI_MODE_ENABLED: | |
5349 | vha->host->active_mode |= MODE_TARGET; | |
5350 | break; | |
5351 | default: | |
5352 | break; | |
5353 | } | |
5354 | ||
5355 | if (ha->tgt.ini_mode_force_reverse) | |
5356 | qla_reverse_ini_mode(vha); | |
5357 | } | |
5358 | ||
5359 | /* Must be called under HW lock */ | |
55a9066f | 5360 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
2d70c103 NB |
5361 | { |
5362 | struct qla_hw_data *ha = vha->hw; | |
5363 | ||
5364 | switch (ql2x_ini_mode) { | |
5365 | case QLA2XXX_INI_MODE_DISABLED: | |
5366 | vha->host->active_mode = MODE_UNKNOWN; | |
5367 | break; | |
5368 | case QLA2XXX_INI_MODE_EXCLUSIVE: | |
5369 | vha->host->active_mode = MODE_INITIATOR; | |
5370 | break; | |
5371 | case QLA2XXX_INI_MODE_ENABLED: | |
5372 | vha->host->active_mode &= ~MODE_TARGET; | |
5373 | break; | |
5374 | default: | |
5375 | break; | |
5376 | } | |
5377 | ||
5378 | if (ha->tgt.ini_mode_force_reverse) | |
5379 | qla_reverse_ini_mode(vha); | |
5380 | } | |
5381 | ||
5382 | /* | |
5383 | * qla_tgt_enable_vha - NO LOCK HELD | |
5384 | * | |
5385 | * host_reset, bring up w/ Target Mode Enabled | |
5386 | */ | |
5387 | void | |
5388 | qlt_enable_vha(struct scsi_qla_host *vha) | |
5389 | { | |
5390 | struct qla_hw_data *ha = vha->hw; | |
0e8cd71c | 5391 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 | 5392 | unsigned long flags; |
0e8cd71c | 5393 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
2d70c103 NB |
5394 | |
5395 | if (!tgt) { | |
5396 | ql_dbg(ql_dbg_tgt, vha, 0xe069, | |
5397 | "Unable to locate qla_tgt pointer from" | |
5398 | " struct qla_hw_data\n"); | |
5399 | dump_stack(); | |
5400 | return; | |
5401 | } | |
5402 | ||
5403 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
5404 | tgt->tgt_stopped = 0; | |
5405 | qlt_set_mode(vha); | |
5406 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
5407 | ||
0e8cd71c SK |
5408 | if (vha->vp_idx) { |
5409 | qla24xx_disable_vp(vha); | |
5410 | qla24xx_enable_vp(vha); | |
5411 | } else { | |
5412 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); | |
5413 | qla2xxx_wake_dpc(base_vha); | |
5414 | qla2x00_wait_for_hba_online(base_vha); | |
5415 | } | |
2d70c103 NB |
5416 | } |
5417 | EXPORT_SYMBOL(qlt_enable_vha); | |
5418 | ||
5419 | /* | |
5420 | * qla_tgt_disable_vha - NO LOCK HELD | |
5421 | * | |
5422 | * Disable Target Mode and reset the adapter | |
5423 | */ | |
55a9066f | 5424 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
2d70c103 NB |
5425 | { |
5426 | struct qla_hw_data *ha = vha->hw; | |
0e8cd71c | 5427 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
2d70c103 NB |
5428 | unsigned long flags; |
5429 | ||
5430 | if (!tgt) { | |
5431 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, | |
5432 | "Unable to locate qla_tgt pointer from" | |
5433 | " struct qla_hw_data\n"); | |
5434 | dump_stack(); | |
5435 | return; | |
5436 | } | |
5437 | ||
5438 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
5439 | qlt_clear_mode(vha); | |
5440 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
5441 | ||
5442 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
5443 | qla2xxx_wake_dpc(vha); | |
5444 | qla2x00_wait_for_hba_online(vha); | |
5445 | } | |
5446 | ||
5447 | /* | |
5448 | * Called from qla_init.c:qla24xx_vport_create() contex to setup | |
5449 | * the target mode specific struct scsi_qla_host and struct qla_hw_data | |
5450 | * members. | |
5451 | */ | |
5452 | void | |
5453 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) | |
5454 | { | |
5455 | if (!qla_tgt_mode_enabled(vha)) | |
5456 | return; | |
5457 | ||
0e8cd71c SK |
5458 | vha->vha_tgt.qla_tgt = NULL; |
5459 | ||
5460 | mutex_init(&vha->vha_tgt.tgt_mutex); | |
5461 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); | |
2d70c103 NB |
5462 | |
5463 | qlt_clear_mode(vha); | |
5464 | ||
5465 | /* | |
5466 | * NOTE: Currently the value is kept the same for <24xx and | |
5467 | * >=24xx ISPs. If it is necessary to change it, | |
5468 | * the check should be added for specific ISPs, | |
5469 | * assigning the value appropriately. | |
5470 | */ | |
5471 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; | |
0e8cd71c SK |
5472 | |
5473 | qlt_add_target(ha, vha); | |
2d70c103 NB |
5474 | } |
5475 | ||
5476 | void | |
5477 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) | |
5478 | { | |
5479 | /* | |
5480 | * FC-4 Feature bit 0 indicates target functionality to the name server. | |
5481 | */ | |
5482 | if (qla_tgt_mode_enabled(vha)) { | |
5483 | if (qla_ini_mode_enabled(vha)) | |
5484 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; | |
5485 | else | |
5486 | ct_req->req.rff_id.fc4_feature = BIT_0; | |
5487 | } else if (qla_ini_mode_enabled(vha)) { | |
5488 | ct_req->req.rff_id.fc4_feature = BIT_1; | |
5489 | } | |
5490 | } | |
5491 | ||
5492 | /* | |
5493 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. | |
5494 | * @ha: HA context | |
5495 | * | |
5496 | * Beginning of ATIO ring has initialization control block already built | |
5497 | * by nvram config routine. | |
5498 | * | |
5499 | * Returns 0 on success. | |
5500 | */ | |
5501 | void | |
5502 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) | |
5503 | { | |
5504 | struct qla_hw_data *ha = vha->hw; | |
5505 | uint16_t cnt; | |
5506 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; | |
5507 | ||
5508 | if (!qla_tgt_mode_enabled(vha)) | |
5509 | return; | |
5510 | ||
5511 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { | |
5512 | pkt->u.raw.signature = ATIO_PROCESSED; | |
5513 | pkt++; | |
5514 | } | |
5515 | ||
5516 | } | |
5517 | ||
5518 | /* | |
5519 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. | |
5520 | * @ha: SCSI driver HA context | |
5521 | */ | |
5522 | void | |
5523 | qlt_24xx_process_atio_queue(struct scsi_qla_host *vha) | |
5524 | { | |
5525 | struct qla_hw_data *ha = vha->hw; | |
2d70c103 NB |
5526 | struct atio_from_isp *pkt; |
5527 | int cnt, i; | |
5528 | ||
5529 | if (!vha->flags.online) | |
5530 | return; | |
5531 | ||
5532 | while (ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) { | |
5533 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; | |
5534 | cnt = pkt->u.raw.entry_count; | |
5535 | ||
5536 | qlt_24xx_atio_pkt_all_vps(vha, (struct atio_from_isp *)pkt); | |
5537 | ||
5538 | for (i = 0; i < cnt; i++) { | |
5539 | ha->tgt.atio_ring_index++; | |
5540 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { | |
5541 | ha->tgt.atio_ring_index = 0; | |
5542 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; | |
5543 | } else | |
5544 | ha->tgt.atio_ring_ptr++; | |
5545 | ||
5546 | pkt->u.raw.signature = ATIO_PROCESSED; | |
5547 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; | |
5548 | } | |
5549 | wmb(); | |
5550 | } | |
5551 | ||
5552 | /* Adjust ring index */ | |
aa230bc5 | 5553 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index); |
3761f3e8 | 5554 | RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha)); |
2d70c103 NB |
5555 | } |
5556 | ||
5557 | void | |
aa230bc5 | 5558 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
2d70c103 NB |
5559 | { |
5560 | struct qla_hw_data *ha = vha->hw; | |
aa230bc5 AE |
5561 | if (!QLA_TGT_MODE_ENABLED()) |
5562 | return; | |
2d70c103 | 5563 | |
aa230bc5 AE |
5564 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
5565 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); | |
5566 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); | |
5567 | ||
5568 | if (IS_ATIO_MSIX_CAPABLE(ha)) { | |
5569 | struct qla_msix_entry *msix = &ha->msix_entries[2]; | |
5570 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; | |
5571 | ||
5572 | icb->msix_atio = cpu_to_le16(msix->entry); | |
5573 | ql_dbg(ql_dbg_init, vha, 0xf072, | |
5574 | "Registering ICB vector 0x%x for atio que.\n", | |
5575 | msix->entry); | |
2d70c103 NB |
5576 | } |
5577 | } | |
5578 | ||
5579 | void | |
5580 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) | |
5581 | { | |
5582 | struct qla_hw_data *ha = vha->hw; | |
5583 | ||
5584 | if (qla_tgt_mode_enabled(vha)) { | |
5585 | if (!ha->tgt.saved_set) { | |
5586 | /* We save only once */ | |
5587 | ha->tgt.saved_exchange_count = nv->exchange_count; | |
5588 | ha->tgt.saved_firmware_options_1 = | |
5589 | nv->firmware_options_1; | |
5590 | ha->tgt.saved_firmware_options_2 = | |
5591 | nv->firmware_options_2; | |
5592 | ha->tgt.saved_firmware_options_3 = | |
5593 | nv->firmware_options_3; | |
5594 | ha->tgt.saved_set = 1; | |
5595 | } | |
5596 | ||
5597 | nv->exchange_count = __constant_cpu_to_le16(0xFFFF); | |
5598 | ||
5599 | /* Enable target mode */ | |
5600 | nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_4); | |
5601 | ||
5602 | /* Disable ini mode, if requested */ | |
5603 | if (!qla_ini_mode_enabled(vha)) | |
5604 | nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_5); | |
5605 | ||
5606 | /* Disable Full Login after LIP */ | |
5607 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); | |
5608 | /* Enable initial LIP */ | |
5609 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_9); | |
d154f350 AE |
5610 | if (ql2xtgt_tape_enable) |
5611 | /* Enable FC Tape support */ | |
5612 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); | |
5613 | else | |
5614 | /* Disable FC Tape support */ | |
5615 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); | |
5616 | ||
2d70c103 NB |
5617 | /* Disable Full Login after LIP */ |
5618 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); | |
5619 | /* Enable target PRLI control */ | |
5620 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_14); | |
5621 | } else { | |
5622 | if (ha->tgt.saved_set) { | |
5623 | nv->exchange_count = ha->tgt.saved_exchange_count; | |
5624 | nv->firmware_options_1 = | |
5625 | ha->tgt.saved_firmware_options_1; | |
5626 | nv->firmware_options_2 = | |
5627 | ha->tgt.saved_firmware_options_2; | |
5628 | nv->firmware_options_3 = | |
5629 | ha->tgt.saved_firmware_options_3; | |
5630 | } | |
5631 | return; | |
5632 | } | |
5633 | ||
5634 | /* out-of-order frames reassembly */ | |
5635 | nv->firmware_options_3 |= BIT_6|BIT_9; | |
5636 | ||
5637 | if (ha->tgt.enable_class_2) { | |
5638 | if (vha->flags.init_done) | |
5639 | fc_host_supported_classes(vha->host) = | |
5640 | FC_COS_CLASS2 | FC_COS_CLASS3; | |
5641 | ||
5642 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_8); | |
5643 | } else { | |
5644 | if (vha->flags.init_done) | |
5645 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; | |
5646 | ||
5647 | nv->firmware_options_2 &= ~__constant_cpu_to_le32(BIT_8); | |
5648 | } | |
5649 | } | |
5650 | ||
5651 | void | |
5652 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, | |
5653 | struct init_cb_24xx *icb) | |
5654 | { | |
5655 | struct qla_hw_data *ha = vha->hw; | |
5656 | ||
5657 | if (ha->tgt.node_name_set) { | |
5658 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); | |
5659 | icb->firmware_options_1 |= __constant_cpu_to_le32(BIT_14); | |
5660 | } | |
5661 | } | |
5662 | ||
aa230bc5 AE |
5663 | void |
5664 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) | |
5665 | { | |
5666 | struct qla_hw_data *ha = vha->hw; | |
5667 | ||
5668 | if (!QLA_TGT_MODE_ENABLED()) | |
5669 | return; | |
5670 | ||
5671 | if (qla_tgt_mode_enabled(vha)) { | |
5672 | if (!ha->tgt.saved_set) { | |
5673 | /* We save only once */ | |
5674 | ha->tgt.saved_exchange_count = nv->exchange_count; | |
5675 | ha->tgt.saved_firmware_options_1 = | |
5676 | nv->firmware_options_1; | |
5677 | ha->tgt.saved_firmware_options_2 = | |
5678 | nv->firmware_options_2; | |
5679 | ha->tgt.saved_firmware_options_3 = | |
5680 | nv->firmware_options_3; | |
5681 | ha->tgt.saved_set = 1; | |
5682 | } | |
5683 | ||
5684 | nv->exchange_count = __constant_cpu_to_le16(0xFFFF); | |
5685 | ||
5686 | /* Enable target mode */ | |
5687 | nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_4); | |
5688 | ||
5689 | /* Disable ini mode, if requested */ | |
5690 | if (!qla_ini_mode_enabled(vha)) | |
5691 | nv->firmware_options_1 |= | |
5692 | __constant_cpu_to_le32(BIT_5); | |
5693 | ||
5694 | /* Disable Full Login after LIP */ | |
5695 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); | |
5696 | /* Enable initial LIP */ | |
5697 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_9); | |
d154f350 AE |
5698 | if (ql2xtgt_tape_enable) |
5699 | /* Enable FC tape support */ | |
5700 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); | |
5701 | else | |
5702 | /* Disable FC tape support */ | |
5703 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); | |
5704 | ||
aa230bc5 AE |
5705 | /* Disable Full Login after LIP */ |
5706 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); | |
5707 | /* Enable target PRLI control */ | |
5708 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_14); | |
5709 | } else { | |
5710 | if (ha->tgt.saved_set) { | |
5711 | nv->exchange_count = ha->tgt.saved_exchange_count; | |
5712 | nv->firmware_options_1 = | |
5713 | ha->tgt.saved_firmware_options_1; | |
5714 | nv->firmware_options_2 = | |
5715 | ha->tgt.saved_firmware_options_2; | |
5716 | nv->firmware_options_3 = | |
5717 | ha->tgt.saved_firmware_options_3; | |
5718 | } | |
5719 | return; | |
5720 | } | |
5721 | ||
5722 | /* out-of-order frames reassembly */ | |
5723 | nv->firmware_options_3 |= BIT_6|BIT_9; | |
5724 | ||
5725 | if (ha->tgt.enable_class_2) { | |
5726 | if (vha->flags.init_done) | |
5727 | fc_host_supported_classes(vha->host) = | |
5728 | FC_COS_CLASS2 | FC_COS_CLASS3; | |
5729 | ||
5730 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_8); | |
5731 | } else { | |
5732 | if (vha->flags.init_done) | |
5733 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; | |
5734 | ||
5735 | nv->firmware_options_2 &= ~__constant_cpu_to_le32(BIT_8); | |
5736 | } | |
5737 | } | |
5738 | ||
5739 | void | |
5740 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, | |
5741 | struct init_cb_81xx *icb) | |
5742 | { | |
5743 | struct qla_hw_data *ha = vha->hw; | |
5744 | ||
5745 | if (!QLA_TGT_MODE_ENABLED()) | |
5746 | return; | |
5747 | ||
5748 | if (ha->tgt.node_name_set) { | |
5749 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); | |
5750 | icb->firmware_options_1 |= __constant_cpu_to_le32(BIT_14); | |
5751 | } | |
5752 | } | |
5753 | ||
5754 | void | |
5755 | qlt_83xx_iospace_config(struct qla_hw_data *ha) | |
5756 | { | |
5757 | if (!QLA_TGT_MODE_ENABLED()) | |
5758 | return; | |
5759 | ||
5760 | ha->msix_count += 1; /* For ATIO Q */ | |
5761 | } | |
5762 | ||
2d70c103 NB |
5763 | int |
5764 | qlt_24xx_process_response_error(struct scsi_qla_host *vha, | |
5765 | struct sts_entry_24xx *pkt) | |
5766 | { | |
5767 | switch (pkt->entry_type) { | |
5768 | case ABTS_RECV_24XX: | |
5769 | case ABTS_RESP_24XX: | |
5770 | case CTIO_TYPE7: | |
5771 | case NOTIFY_ACK_TYPE: | |
f83adb61 | 5772 | case CTIO_CRC2: |
2d70c103 NB |
5773 | return 1; |
5774 | default: | |
5775 | return 0; | |
5776 | } | |
5777 | } | |
5778 | ||
5779 | void | |
5780 | qlt_modify_vp_config(struct scsi_qla_host *vha, | |
5781 | struct vp_config_entry_24xx *vpmod) | |
5782 | { | |
5783 | if (qla_tgt_mode_enabled(vha)) | |
5784 | vpmod->options_idx1 &= ~BIT_5; | |
5785 | /* Disable ini mode, if requested */ | |
5786 | if (!qla_ini_mode_enabled(vha)) | |
5787 | vpmod->options_idx1 &= ~BIT_4; | |
5788 | } | |
5789 | ||
5790 | void | |
5791 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) | |
5792 | { | |
5793 | if (!QLA_TGT_MODE_ENABLED()) | |
5794 | return; | |
5795 | ||
b20f02e1 | 5796 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
aa230bc5 AE |
5797 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
5798 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; | |
5799 | } else { | |
5800 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; | |
5801 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; | |
5802 | } | |
5803 | ||
0e8cd71c SK |
5804 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
5805 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); | |
2d70c103 NB |
5806 | qlt_clear_mode(base_vha); |
5807 | } | |
5808 | ||
aa230bc5 AE |
5809 | irqreturn_t |
5810 | qla83xx_msix_atio_q(int irq, void *dev_id) | |
5811 | { | |
5812 | struct rsp_que *rsp; | |
5813 | scsi_qla_host_t *vha; | |
5814 | struct qla_hw_data *ha; | |
5815 | unsigned long flags; | |
5816 | ||
5817 | rsp = (struct rsp_que *) dev_id; | |
5818 | ha = rsp->hw; | |
5819 | vha = pci_get_drvdata(ha->pdev); | |
5820 | ||
5821 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
5822 | ||
5823 | qlt_24xx_process_atio_queue(vha); | |
5824 | qla24xx_process_response_queue(vha, rsp); | |
5825 | ||
5826 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
5827 | ||
5828 | return IRQ_HANDLED; | |
5829 | } | |
5830 | ||
2d70c103 NB |
5831 | int |
5832 | qlt_mem_alloc(struct qla_hw_data *ha) | |
5833 | { | |
5834 | if (!QLA_TGT_MODE_ENABLED()) | |
5835 | return 0; | |
5836 | ||
5837 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * | |
5838 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); | |
5839 | if (!ha->tgt.tgt_vp_map) | |
5840 | return -ENOMEM; | |
5841 | ||
5842 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, | |
5843 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), | |
5844 | &ha->tgt.atio_dma, GFP_KERNEL); | |
5845 | if (!ha->tgt.atio_ring) { | |
5846 | kfree(ha->tgt.tgt_vp_map); | |
5847 | return -ENOMEM; | |
5848 | } | |
5849 | return 0; | |
5850 | } | |
5851 | ||
5852 | void | |
5853 | qlt_mem_free(struct qla_hw_data *ha) | |
5854 | { | |
5855 | if (!QLA_TGT_MODE_ENABLED()) | |
5856 | return; | |
5857 | ||
5858 | if (ha->tgt.atio_ring) { | |
5859 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * | |
5860 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, | |
5861 | ha->tgt.atio_dma); | |
5862 | } | |
5863 | kfree(ha->tgt.tgt_vp_map); | |
5864 | } | |
5865 | ||
5866 | /* vport_slock to be held by the caller */ | |
5867 | void | |
5868 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) | |
5869 | { | |
5870 | if (!QLA_TGT_MODE_ENABLED()) | |
5871 | return; | |
5872 | ||
5873 | switch (cmd) { | |
5874 | case SET_VP_IDX: | |
5875 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; | |
5876 | break; | |
5877 | case SET_AL_PA: | |
5878 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = vha->vp_idx; | |
5879 | break; | |
5880 | case RESET_VP_IDX: | |
5881 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; | |
5882 | break; | |
5883 | case RESET_AL_PA: | |
5884 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = 0; | |
5885 | break; | |
5886 | } | |
5887 | } | |
5888 | ||
5889 | static int __init qlt_parse_ini_mode(void) | |
5890 | { | |
5891 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) | |
5892 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; | |
5893 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) | |
5894 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; | |
5895 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) | |
5896 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; | |
5897 | else | |
5898 | return false; | |
5899 | ||
5900 | return true; | |
5901 | } | |
5902 | ||
5903 | int __init qlt_init(void) | |
5904 | { | |
5905 | int ret; | |
5906 | ||
5907 | if (!qlt_parse_ini_mode()) { | |
5908 | ql_log(ql_log_fatal, NULL, 0xe06b, | |
5909 | "qlt_parse_ini_mode() failed\n"); | |
5910 | return -EINVAL; | |
5911 | } | |
5912 | ||
5913 | if (!QLA_TGT_MODE_ENABLED()) | |
5914 | return 0; | |
5915 | ||
2d70c103 NB |
5916 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
5917 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct | |
5918 | qla_tgt_mgmt_cmd), 0, NULL); | |
5919 | if (!qla_tgt_mgmt_cmd_cachep) { | |
5920 | ql_log(ql_log_fatal, NULL, 0xe06d, | |
5921 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); | |
51a07f84 | 5922 | return -ENOMEM; |
2d70c103 NB |
5923 | } |
5924 | ||
5925 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, | |
5926 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); | |
5927 | if (!qla_tgt_mgmt_cmd_mempool) { | |
5928 | ql_log(ql_log_fatal, NULL, 0xe06e, | |
5929 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); | |
5930 | ret = -ENOMEM; | |
5931 | goto out_mgmt_cmd_cachep; | |
5932 | } | |
5933 | ||
5934 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); | |
5935 | if (!qla_tgt_wq) { | |
5936 | ql_log(ql_log_fatal, NULL, 0xe06f, | |
5937 | "alloc_workqueue for qla_tgt_wq failed\n"); | |
5938 | ret = -ENOMEM; | |
5939 | goto out_cmd_mempool; | |
5940 | } | |
5941 | /* | |
5942 | * Return 1 to signal that initiator-mode is being disabled | |
5943 | */ | |
5944 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; | |
5945 | ||
5946 | out_cmd_mempool: | |
5947 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); | |
5948 | out_mgmt_cmd_cachep: | |
5949 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); | |
2d70c103 NB |
5950 | return ret; |
5951 | } | |
5952 | ||
5953 | void qlt_exit(void) | |
5954 | { | |
5955 | if (!QLA_TGT_MODE_ENABLED()) | |
5956 | return; | |
5957 | ||
5958 | destroy_workqueue(qla_tgt_wq); | |
5959 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); | |
5960 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); | |
2d70c103 | 5961 | } |