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