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