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