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