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