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