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