2 * Copyright 2014 Cisco Systems, Inc. All rights reserved.
4 * This program is free software; you may redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 #include <linux/mempool.h>
19 #include <linux/errno.h>
20 #include <linux/init.h>
21 #include <linux/workqueue.h>
22 #include <linux/pci.h>
23 #include <linux/spinlock.h>
24 #include <linux/delay.h>
25 #include <linux/gfp.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_host.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_tcq.h>
31 #include <scsi/scsi_dbg.h>
36 #define snic_cmd_tag(sc) (((struct scsi_cmnd *) sc)->request->tag)
38 const char *snic_state_str
[] = {
39 [SNIC_INIT
] = "SNIC_INIT",
40 [SNIC_ERROR
] = "SNIC_ERROR",
41 [SNIC_ONLINE
] = "SNIC_ONLINE",
42 [SNIC_OFFLINE
] = "SNIC_OFFLINE",
43 [SNIC_FWRESET
] = "SNIC_FWRESET",
46 static const char * const snic_req_state_str
[] = {
47 [SNIC_IOREQ_NOT_INITED
] = "SNIC_IOREQ_NOT_INITED",
48 [SNIC_IOREQ_PENDING
] = "SNIC_IOREQ_PENDING",
49 [SNIC_IOREQ_ABTS_PENDING
] = "SNIC_IOREQ_ABTS_PENDING",
50 [SNIC_IOREQ_ABTS_COMPLETE
] = "SNIC_IOREQ_ABTS_COMPELTE",
51 [SNIC_IOREQ_LR_PENDING
] = "SNIC_IOREQ_LR_PENDING",
52 [SNIC_IOREQ_LR_COMPLETE
] = "SNIC_IOREQ_LR_COMPELTE",
53 [SNIC_IOREQ_COMPLETE
] = "SNIC_IOREQ_CMD_COMPELTE",
56 /* snic cmd status strings */
57 static const char * const snic_io_status_str
[] = {
58 [SNIC_STAT_IO_SUCCESS
] = "SNIC_STAT_IO_SUCCESS", /* 0x0 */
59 [SNIC_STAT_INVALID_HDR
] = "SNIC_STAT_INVALID_HDR",
60 [SNIC_STAT_OUT_OF_RES
] = "SNIC_STAT_OUT_OF_RES",
61 [SNIC_STAT_INVALID_PARM
] = "SNIC_STAT_INVALID_PARM",
62 [SNIC_STAT_REQ_NOT_SUP
] = "SNIC_STAT_REQ_NOT_SUP",
63 [SNIC_STAT_IO_NOT_FOUND
] = "SNIC_STAT_IO_NOT_FOUND",
64 [SNIC_STAT_ABORTED
] = "SNIC_STAT_ABORTED",
65 [SNIC_STAT_TIMEOUT
] = "SNIC_STAT_TIMEOUT",
66 [SNIC_STAT_SGL_INVALID
] = "SNIC_STAT_SGL_INVALID",
67 [SNIC_STAT_DATA_CNT_MISMATCH
] = "SNIC_STAT_DATA_CNT_MISMATCH",
68 [SNIC_STAT_FW_ERR
] = "SNIC_STAT_FW_ERR",
69 [SNIC_STAT_ITMF_REJECT
] = "SNIC_STAT_ITMF_REJECT",
70 [SNIC_STAT_ITMF_FAIL
] = "SNIC_STAT_ITMF_FAIL",
71 [SNIC_STAT_ITMF_INCORRECT_LUN
] = "SNIC_STAT_ITMF_INCORRECT_LUN",
72 [SNIC_STAT_CMND_REJECT
] = "SNIC_STAT_CMND_REJECT",
73 [SNIC_STAT_DEV_OFFLINE
] = "SNIC_STAT_DEV_OFFLINE",
74 [SNIC_STAT_NO_BOOTLUN
] = "SNIC_STAT_NO_BOOTLUN",
75 [SNIC_STAT_SCSI_ERR
] = "SNIC_STAT_SCSI_ERR",
76 [SNIC_STAT_NOT_READY
] = "SNIC_STAT_NOT_READY",
77 [SNIC_STAT_FATAL_ERROR
] = "SNIC_STAT_FATAL_ERROR",
80 static void snic_scsi_cleanup(struct snic
*, int);
83 snic_state_to_str(unsigned int state
)
85 if (state
>= ARRAY_SIZE(snic_state_str
) || !snic_state_str
[state
])
88 return snic_state_str
[state
];
92 snic_io_status_to_str(unsigned int state
)
94 if ((state
>= ARRAY_SIZE(snic_io_status_str
)) ||
95 (!snic_io_status_str
[state
]))
98 return snic_io_status_str
[state
];
102 snic_ioreq_state_to_str(unsigned int state
)
104 if (state
>= ARRAY_SIZE(snic_req_state_str
) ||
105 !snic_req_state_str
[state
])
108 return snic_req_state_str
[state
];
111 static inline spinlock_t
*
112 snic_io_lock_hash(struct snic
*snic
, struct scsi_cmnd
*sc
)
114 u32 hash
= snic_cmd_tag(sc
) & (SNIC_IO_LOCKS
- 1);
116 return &snic
->io_req_lock
[hash
];
119 static inline spinlock_t
*
120 snic_io_lock_tag(struct snic
*snic
, int tag
)
122 return &snic
->io_req_lock
[tag
& (SNIC_IO_LOCKS
- 1)];
125 /* snic_release_req_buf : Releases snic_req_info */
127 snic_release_req_buf(struct snic
*snic
,
128 struct snic_req_info
*rqi
,
129 struct scsi_cmnd
*sc
)
131 struct snic_host_req
*req
= rqi_to_req(rqi
);
133 /* Freeing cmd without marking completion, not okay */
134 SNIC_BUG_ON(!((CMD_STATE(sc
) == SNIC_IOREQ_COMPLETE
) ||
135 (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_COMPLETE
) ||
136 (CMD_FLAGS(sc
) & SNIC_DEV_RST_NOTSUP
) ||
137 (CMD_FLAGS(sc
) & SNIC_IO_INTERNAL_TERM_ISSUED
) ||
138 (CMD_FLAGS(sc
) & SNIC_DEV_RST_TERM_ISSUED
) ||
139 (CMD_FLAGS(sc
) & SNIC_SCSI_CLEANUP
) ||
140 (CMD_STATE(sc
) == SNIC_IOREQ_LR_COMPLETE
)));
142 SNIC_SCSI_DBG(snic
->shost
,
143 "Rel_req:sc %p:tag %x:rqi %p:ioreq %p:abt %p:dr %p: state %s:flags 0x%llx\n",
144 sc
, snic_cmd_tag(sc
), rqi
, rqi
->req
, rqi
->abort_req
,
145 rqi
->dr_req
, snic_ioreq_state_to_str(CMD_STATE(sc
)),
148 if (req
->u
.icmnd
.sense_addr
)
149 pci_unmap_single(snic
->pdev
,
150 le64_to_cpu(req
->u
.icmnd
.sense_addr
),
151 SCSI_SENSE_BUFFERSIZE
,
156 snic_req_free(snic
, rqi
);
157 } /* end of snic_release_req_buf */
160 * snic_queue_icmnd_req : Queues snic_icmnd request
163 snic_queue_icmnd_req(struct snic
*snic
,
164 struct snic_req_info
*rqi
,
165 struct scsi_cmnd
*sc
,
168 struct scatterlist
*sg
;
169 struct snic_sg_desc
*sgd
;
177 flags
= SNIC_ICMND_ESGL
;
178 sgd
= (struct snic_sg_desc
*) req_to_sgl(rqi
->req
);
180 for_each_sg(scsi_sglist(sc
), sg
, sg_cnt
, i
) {
181 sgd
->addr
= cpu_to_le64(sg_dma_address(sg
));
182 sgd
->len
= cpu_to_le32(sg_dma_len(sg
));
188 pa
= pci_map_single(snic
->pdev
,
190 SCSI_SENSE_BUFFERSIZE
,
193 if (pci_dma_mapping_error(snic
->pdev
, pa
)) {
194 SNIC_HOST_ERR(snic
->shost
,
195 "QIcmnd:PCI Map Failed for sns buf %p tag %x\n",
196 sc
->sense_buffer
, snic_cmd_tag(sc
));
202 int_to_scsilun(sc
->device
->lun
, &lun
);
203 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
)
204 flags
|= SNIC_ICMND_RD
;
205 if (sc
->sc_data_direction
== DMA_TO_DEVICE
)
206 flags
|= SNIC_ICMND_WR
;
208 /* Initialize icmnd */
209 snic_icmnd_init(rqi
->req
,
211 snic
->config
.hid
, /* hid */
213 flags
, /* command flags */
220 (ulong
) req_to_sgl(rqi
->req
),
221 pa
, /* sense buffer pa */
222 SCSI_SENSE_BUFFERSIZE
);
224 atomic64_inc(&snic
->s_stats
.io
.active
);
225 ret
= snic_queue_wq_desc(snic
, rqi
->req
, rqi
->req_len
);
227 atomic64_dec(&snic
->s_stats
.io
.active
);
228 SNIC_HOST_ERR(snic
->shost
,
229 "QIcmnd: Queuing Icmnd Failed. ret = %d\n",
232 snic_stats_update_active_ios(&snic
->s_stats
);
235 } /* end of snic_queue_icmnd_req */
238 * snic_issue_scsi_req : Prepares IO request and Issues to FW.
241 snic_issue_scsi_req(struct snic
*snic
,
242 struct snic_tgt
*tgt
,
243 struct scsi_cmnd
*sc
)
245 struct snic_req_info
*rqi
= NULL
;
248 u32 tag
= snic_cmd_tag(sc
);
249 u64 cmd_trc
= 0, cmd_st_flags
= 0;
250 spinlock_t
*io_lock
= NULL
;
253 CMD_STATE(sc
) = SNIC_IOREQ_NOT_INITED
;
254 CMD_FLAGS(sc
) = SNIC_NO_FLAGS
;
255 sg_cnt
= scsi_dma_map(sc
);
257 SNIC_TRC((u16
)snic
->shost
->host_no
, tag
, (ulong
) sc
, 0,
258 sc
->cmnd
[0], sg_cnt
, CMD_STATE(sc
));
260 SNIC_HOST_ERR(snic
->shost
, "issue_sc:Failed to map SG List.\n");
266 rqi
= snic_req_init(snic
, sg_cnt
);
274 rqi
->tgt_id
= tgt
->id
;
277 CMD_STATE(sc
) = SNIC_IOREQ_PENDING
;
278 CMD_SP(sc
) = (char *) rqi
;
279 cmd_trc
= SNIC_TRC_CMD(sc
);
280 CMD_FLAGS(sc
) |= (SNIC_IO_INITIALIZED
| SNIC_IO_ISSUED
);
281 cmd_st_flags
= SNIC_TRC_CMD_STATE_FLAGS(sc
);
282 io_lock
= snic_io_lock_hash(snic
, sc
);
284 /* create wq desc and enqueue it */
285 ret
= snic_queue_icmnd_req(snic
, rqi
, sc
, sg_cnt
);
287 SNIC_HOST_ERR(snic
->shost
,
288 "issue_sc: icmnd qing Failed for sc %p, err %d\n",
291 spin_lock_irqsave(io_lock
, flags
);
292 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
294 CMD_STATE(sc
) = SNIC_IOREQ_COMPLETE
;
295 CMD_FLAGS(sc
) &= ~SNIC_IO_ISSUED
; /* turn off the flag */
296 spin_unlock_irqrestore(io_lock
, flags
);
299 snic_release_req_buf(snic
, rqi
, sc
);
301 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
, 0, 0, 0,
302 SNIC_TRC_CMD_STATE_FLAGS(sc
));
304 u32 io_sz
= scsi_bufflen(sc
) >> 9;
305 u32 qtime
= jiffies
- rqi
->start_time
;
306 struct snic_io_stats
*iostats
= &snic
->s_stats
.io
;
308 if (io_sz
> atomic64_read(&iostats
->max_io_sz
))
309 atomic64_set(&iostats
->max_io_sz
, io_sz
);
311 if (qtime
> atomic64_read(&iostats
->max_qtime
))
312 atomic64_set(&iostats
->max_qtime
, qtime
);
314 SNIC_SCSI_DBG(snic
->shost
,
315 "issue_sc:sc %p, tag %d queued to WQ.\n",
318 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
, (ulong
) rqi
,
319 sg_cnt
, cmd_trc
, cmd_st_flags
);
325 } /* end of snic_issue_scsi_req */
330 * Routine to send a scsi cdb to LLD
331 * Called with host_lock held and interrupts disabled
334 snic_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*sc
)
336 struct snic_tgt
*tgt
= NULL
;
337 struct snic
*snic
= shost_priv(shost
);
340 tgt
= starget_to_tgt(scsi_target(sc
->device
));
341 ret
= snic_tgt_chkready(tgt
);
343 SNIC_HOST_ERR(shost
, "Tgt %p id %d Not Ready.\n", tgt
, tgt
->id
);
344 atomic64_inc(&snic
->s_stats
.misc
.tgt_not_rdy
);
351 if (snic_get_state(snic
) != SNIC_ONLINE
) {
352 SNIC_HOST_ERR(shost
, "snic state is %s\n",
353 snic_state_str
[snic_get_state(snic
)]);
355 return SCSI_MLQUEUE_HOST_BUSY
;
357 atomic_inc(&snic
->ios_inflight
);
359 SNIC_SCSI_DBG(shost
, "sc %p Tag %d (sc %0x) lun %lld in snic_qcmd\n",
360 sc
, snic_cmd_tag(sc
), sc
->cmnd
[0], sc
->device
->lun
);
362 ret
= snic_issue_scsi_req(snic
, tgt
, sc
);
364 SNIC_HOST_ERR(shost
, "Failed to Q, Scsi Req w/ err %d.\n", ret
);
365 ret
= SCSI_MLQUEUE_HOST_BUSY
;
368 atomic_dec(&snic
->ios_inflight
);
371 } /* end of snic_queuecommand */
374 * snic_process_abts_pending_state:
375 * caller should hold IO lock
378 snic_proc_tmreq_pending_state(struct snic
*snic
,
379 struct scsi_cmnd
*sc
,
382 int state
= CMD_STATE(sc
);
384 if (state
== SNIC_IOREQ_ABTS_PENDING
)
385 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_PENDING
;
386 else if (state
== SNIC_IOREQ_LR_PENDING
)
387 CMD_FLAGS(sc
) |= SNIC_DEV_RST_PENDING
;
391 switch (cmpl_status
) {
392 case SNIC_STAT_IO_SUCCESS
:
393 CMD_FLAGS(sc
) |= SNIC_IO_DONE
;
396 case SNIC_STAT_ABORTED
:
397 CMD_FLAGS(sc
) |= SNIC_IO_ABORTED
;
406 * snic_process_io_failed_state:
407 * Processes IO's error states
410 snic_process_io_failed_state(struct snic
*snic
,
411 struct snic_icmnd_cmpl
*icmnd_cmpl
,
412 struct scsi_cmnd
*sc
,
418 case SNIC_STAT_TIMEOUT
: /* Req was timedout */
419 atomic64_inc(&snic
->s_stats
.misc
.io_tmo
);
423 case SNIC_STAT_ABORTED
: /* Req was aborted */
424 atomic64_inc(&snic
->s_stats
.misc
.io_aborted
);
428 case SNIC_STAT_DATA_CNT_MISMATCH
:/* Recv/Sent more/less data than exp */
429 atomic64_inc(&snic
->s_stats
.misc
.data_cnt_mismat
);
430 scsi_set_resid(sc
, le32_to_cpu(icmnd_cmpl
->resid
));
434 case SNIC_STAT_OUT_OF_RES
: /* Out of resources to complete request */
435 atomic64_inc(&snic
->s_stats
.fw
.out_of_res
);
439 case SNIC_STAT_IO_NOT_FOUND
: /* Requested I/O was not found */
440 atomic64_inc(&snic
->s_stats
.io
.io_not_found
);
444 case SNIC_STAT_SGL_INVALID
: /* Req was aborted to due to sgl error*/
445 atomic64_inc(&snic
->s_stats
.misc
.sgl_inval
);
449 case SNIC_STAT_FW_ERR
: /* Req terminated due to FW Error */
450 atomic64_inc(&snic
->s_stats
.fw
.io_errs
);
454 case SNIC_STAT_SCSI_ERR
: /* FW hits SCSI Error */
455 atomic64_inc(&snic
->s_stats
.fw
.scsi_errs
);
458 case SNIC_STAT_NOT_READY
: /* XPT yet to initialize */
459 case SNIC_STAT_DEV_OFFLINE
: /* Device offline */
460 res
= DID_NO_CONNECT
;
463 case SNIC_STAT_INVALID_HDR
: /* Hdr contains invalid data */
464 case SNIC_STAT_INVALID_PARM
: /* Some param in req is invalid */
465 case SNIC_STAT_REQ_NOT_SUP
: /* Req type is not supported */
466 case SNIC_STAT_CMND_REJECT
: /* Req rejected */
467 case SNIC_STAT_FATAL_ERROR
: /* XPT Error */
469 SNIC_SCSI_DBG(snic
->shost
,
470 "Invalid Hdr/Param or Req Not Supported or Cmnd Rejected or Device Offline. or Unknown\n");
475 SNIC_HOST_ERR(snic
->shost
, "fw returns failed status %s flags 0x%llx\n",
476 snic_io_status_to_str(cmpl_stat
), CMD_FLAGS(sc
));
479 sc
->result
= (res
<< 16) | icmnd_cmpl
->scsi_status
;
480 } /* end of snic_process_io_failed_state */
483 * snic_tmreq_pending : is task management in progress.
486 snic_tmreq_pending(struct scsi_cmnd
*sc
)
488 int state
= CMD_STATE(sc
);
490 return ((state
== SNIC_IOREQ_ABTS_PENDING
) ||
491 (state
== SNIC_IOREQ_LR_PENDING
));
495 * snic_process_icmnd_cmpl_status:
496 * Caller should hold io_lock
499 snic_process_icmnd_cmpl_status(struct snic
*snic
,
500 struct snic_icmnd_cmpl
*icmnd_cmpl
,
502 struct scsi_cmnd
*sc
)
504 u8 scsi_stat
= icmnd_cmpl
->scsi_status
;
508 /* Mark the IO as complete */
509 CMD_STATE(sc
) = SNIC_IOREQ_COMPLETE
;
511 if (likely(cmpl_stat
== SNIC_STAT_IO_SUCCESS
)) {
512 sc
->result
= (DID_OK
<< 16) | scsi_stat
;
514 xfer_len
= scsi_bufflen(sc
);
516 /* Update SCSI Cmd with resid value */
517 scsi_set_resid(sc
, le32_to_cpu(icmnd_cmpl
->resid
));
519 if (icmnd_cmpl
->flags
& SNIC_ICMND_CMPL_UNDR_RUN
) {
520 xfer_len
-= le32_to_cpu(icmnd_cmpl
->resid
);
521 atomic64_inc(&snic
->s_stats
.misc
.io_under_run
);
524 if (icmnd_cmpl
->scsi_status
== SAM_STAT_TASK_SET_FULL
)
525 atomic64_inc(&snic
->s_stats
.misc
.qfull
);
529 snic_process_io_failed_state(snic
, icmnd_cmpl
, sc
, cmpl_stat
);
530 atomic64_inc(&snic
->s_stats
.io
.fail
);
531 SNIC_HOST_ERR(snic
->shost
,
532 "icmnd_cmpl: IO Failed : Hdr Status %s flags 0x%llx\n",
533 snic_io_status_to_str(cmpl_stat
), CMD_FLAGS(sc
));
538 } /* end of snic_process_icmnd_cmpl_status */
542 * snic_icmnd_cmpl_handler
543 * Routine to handle icmnd completions
546 snic_icmnd_cmpl_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
551 struct scsi_cmnd
*sc
= NULL
;
552 struct snic_icmnd_cmpl
*icmnd_cmpl
= NULL
;
553 struct snic_host_req
*req
= NULL
;
554 struct snic_req_info
*rqi
= NULL
;
555 unsigned long flags
, start_time
;
559 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
560 icmnd_cmpl
= &fwreq
->u
.icmnd_cmpl
;
561 sc_stat
= icmnd_cmpl
->scsi_status
;
563 SNIC_SCSI_DBG(snic
->shost
,
564 "Icmnd_cmpl: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x,i ctx = %lx\n",
565 typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
567 if (cmnd_id
>= snic
->max_tag_id
) {
568 SNIC_HOST_ERR(snic
->shost
,
569 "Icmnd_cmpl:Tag Error:Out of Range Tag %d, hdr status = %s\n",
570 cmnd_id
, snic_io_status_to_str(hdr_stat
));
574 sc
= scsi_host_find_tag(snic
->shost
, cmnd_id
);
578 atomic64_inc(&snic
->s_stats
.io
.sc_null
);
579 SNIC_HOST_ERR(snic
->shost
,
580 "Icmnd_cmpl: Scsi Cmnd Not found, sc = NULL Hdr Status = %s tag = 0x%x fwreq = 0x%p\n",
581 snic_io_status_to_str(hdr_stat
),
585 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, 0,
586 ((u64
)hdr_stat
<< 16 |
587 (u64
)sc_stat
<< 8 | (u64
)icmnd_cmpl
->flags
),
588 (ulong
) fwreq
, le32_to_cpu(icmnd_cmpl
->resid
), ctx
);
593 io_lock
= snic_io_lock_hash(snic
, sc
);
595 spin_lock_irqsave(io_lock
, flags
);
596 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
597 SNIC_SCSI_DBG(snic
->shost
,
598 "Icmnd_cmpl:lun %lld sc %p cmd %xtag %d flags 0x%llx rqi %p\n",
599 sc
->device
->lun
, sc
, sc
->cmnd
[0], snic_cmd_tag(sc
),
602 if (CMD_FLAGS(sc
) & SNIC_HOST_RESET_CMD_TERM
) {
603 spin_unlock_irqrestore(io_lock
, flags
);
608 SNIC_BUG_ON(rqi
!= (struct snic_req_info
*)ctx
);
611 atomic64_inc(&snic
->s_stats
.io
.req_null
);
612 CMD_FLAGS(sc
) |= SNIC_IO_REQ_NULL
;
613 spin_unlock_irqrestore(io_lock
, flags
);
615 SNIC_HOST_ERR(snic
->shost
,
616 "Icmnd_cmpl:Host Req Not Found(null), Hdr Status %s, Tag 0x%x, sc 0x%p flags 0x%llx\n",
617 snic_io_status_to_str(hdr_stat
),
618 cmnd_id
, sc
, CMD_FLAGS(sc
));
622 rqi
= (struct snic_req_info
*) ctx
;
623 start_time
= rqi
->start_time
;
625 /* firmware completed the io */
629 * if SCSI-ML has already issued abort on this command,
630 * ignore completion of the IO. The abts path will clean it up
632 if (unlikely(snic_tmreq_pending(sc
))) {
633 snic_proc_tmreq_pending_state(snic
, sc
, hdr_stat
);
634 spin_unlock_irqrestore(io_lock
, flags
);
636 snic_stats_update_io_cmpl(&snic
->s_stats
);
638 /* Expected value is SNIC_STAT_ABORTED */
639 if (likely(hdr_stat
== SNIC_STAT_ABORTED
))
642 SNIC_SCSI_DBG(snic
->shost
,
643 "icmnd_cmpl:TM Req Pending(%s), Hdr Status %s sc 0x%p scsi status %x resid %d flags 0x%llx\n",
644 snic_ioreq_state_to_str(CMD_STATE(sc
)),
645 snic_io_status_to_str(hdr_stat
),
646 sc
, sc_stat
, le32_to_cpu(icmnd_cmpl
->resid
),
649 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
650 jiffies_to_msecs(jiffies
- start_time
), (ulong
) fwreq
,
651 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
656 if (snic_process_icmnd_cmpl_status(snic
, icmnd_cmpl
, hdr_stat
, sc
)) {
657 scsi_print_command(sc
);
658 SNIC_HOST_ERR(snic
->shost
,
659 "icmnd_cmpl:IO Failed, sc 0x%p Tag %d Cmd %x Hdr Status %s flags 0x%llx\n",
660 sc
, sc
->cmnd
[0], cmnd_id
,
661 snic_io_status_to_str(hdr_stat
), CMD_FLAGS(sc
));
664 /* Break link with the SCSI Command */
666 CMD_FLAGS(sc
) |= SNIC_IO_DONE
;
668 spin_unlock_irqrestore(io_lock
, flags
);
670 /* For now, consider only successful IO. */
671 snic_calc_io_process_time(snic
, rqi
);
673 snic_release_req_buf(snic
, rqi
, sc
);
675 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
676 jiffies_to_msecs(jiffies
- start_time
), (ulong
) fwreq
,
677 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
683 snic_stats_update_io_cmpl(&snic
->s_stats
);
684 } /* end of snic_icmnd_cmpl_handler */
687 snic_proc_dr_cmpl_locked(struct snic
*snic
,
688 struct snic_fw_req
*fwreq
,
691 struct scsi_cmnd
*sc
)
693 struct snic_req_info
*rqi
= (struct snic_req_info
*) CMD_SP(sc
);
694 u32 start_time
= rqi
->start_time
;
696 CMD_LR_STATUS(sc
) = cmpl_stat
;
698 SNIC_SCSI_DBG(snic
->shost
, "itmf_cmpl: Cmd State = %s\n",
699 snic_ioreq_state_to_str(CMD_STATE(sc
)));
701 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
) {
702 CMD_FLAGS(sc
) |= SNIC_DEV_RST_ABTS_PENDING
;
704 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
705 jiffies_to_msecs(jiffies
- start_time
),
706 (ulong
) fwreq
, 0, SNIC_TRC_CMD_STATE_FLAGS(sc
));
708 SNIC_SCSI_DBG(snic
->shost
,
709 "itmf_cmpl: Terminate Pending Dev Reset Cmpl Recvd.id %x, status %s flags 0x%llx\n",
710 (int)(cmnd_id
& SNIC_TAG_MASK
),
711 snic_io_status_to_str(cmpl_stat
),
718 if (CMD_FLAGS(sc
) & SNIC_DEV_RST_TIMEDOUT
) {
719 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
720 jiffies_to_msecs(jiffies
- start_time
),
721 (ulong
) fwreq
, 0, SNIC_TRC_CMD_STATE_FLAGS(sc
));
723 SNIC_SCSI_DBG(snic
->shost
,
724 "itmf_cmpl:Dev Reset Completion Received after timeout. id %d cmpl status %s flags 0x%llx\n",
725 (int)(cmnd_id
& SNIC_TAG_MASK
),
726 snic_io_status_to_str(cmpl_stat
),
732 CMD_STATE(sc
) = SNIC_IOREQ_LR_COMPLETE
;
733 CMD_FLAGS(sc
) |= SNIC_DEV_RST_DONE
;
735 SNIC_SCSI_DBG(snic
->shost
,
736 "itmf_cmpl:Dev Reset Cmpl Recvd id %d cmpl status %s flags 0x%llx\n",
737 (int)(cmnd_id
& SNIC_TAG_MASK
),
738 snic_io_status_to_str(cmpl_stat
),
742 complete(rqi
->dr_done
);
743 } /* end of snic_proc_dr_cmpl_locked */
746 * snic_update_abort_stats : Updates abort stats based on completion status.
749 snic_update_abort_stats(struct snic
*snic
, u8 cmpl_stat
)
751 struct snic_abort_stats
*abt_stats
= &snic
->s_stats
.abts
;
753 SNIC_SCSI_DBG(snic
->shost
, "Updating Abort stats.\n");
756 case SNIC_STAT_IO_SUCCESS
:
759 case SNIC_STAT_TIMEOUT
:
760 atomic64_inc(&abt_stats
->fw_tmo
);
763 case SNIC_STAT_IO_NOT_FOUND
:
764 atomic64_inc(&abt_stats
->io_not_found
);
768 atomic64_inc(&abt_stats
->fail
);
774 snic_process_itmf_cmpl(struct snic
*snic
,
775 struct snic_fw_req
*fwreq
,
778 struct scsi_cmnd
*sc
)
780 struct snic_req_info
*rqi
= NULL
;
782 spinlock_t
*io_lock
= NULL
;
787 io_lock
= snic_io_lock_hash(snic
, sc
);
788 spin_lock_irqsave(io_lock
, flags
);
789 if (CMD_FLAGS(sc
) & SNIC_HOST_RESET_CMD_TERM
) {
790 spin_unlock_irqrestore(io_lock
, flags
);
794 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
798 atomic64_inc(&snic
->s_stats
.io
.req_null
);
799 spin_unlock_irqrestore(io_lock
, flags
);
800 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
801 SNIC_HOST_ERR(snic
->shost
,
802 "itmf_cmpl: rqi is null,Hdr stat = %s Tag = 0x%x sc = 0x%p flags 0x%llx\n",
803 snic_io_status_to_str(cmpl_stat
), cmnd_id
, sc
,
809 /* Extract task management flags */
810 tm_tags
= cmnd_id
& ~(SNIC_TAG_MASK
);
812 start_time
= rqi
->start_time
;
813 cmnd_id
&= (SNIC_TAG_MASK
);
817 /* Abort only issued on cmd */
818 snic_update_abort_stats(snic
, cmpl_stat
);
820 if (CMD_STATE(sc
) != SNIC_IOREQ_ABTS_PENDING
) {
821 /* This is a late completion. Ignore it. */
823 spin_unlock_irqrestore(io_lock
, flags
);
827 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_COMPLETE
;
828 CMD_ABTS_STATUS(sc
) = cmpl_stat
;
829 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_DONE
;
831 SNIC_SCSI_DBG(snic
->shost
,
832 "itmf_cmpl:Abort Cmpl Recvd.Tag 0x%x Status %s flags 0x%llx\n",
834 snic_io_status_to_str(cmpl_stat
),
838 * If scsi_eh thread is blocked waiting for abts complete,
839 * signal completion to it. IO will be cleaned in the thread,
840 * else clean it in this context.
842 if (rqi
->abts_done
) {
843 complete(rqi
->abts_done
);
844 spin_unlock_irqrestore(io_lock
, flags
);
846 break; /* jump out */
850 sc
->result
= (DID_ERROR
<< 16);
851 SNIC_SCSI_DBG(snic
->shost
,
852 "itmf_cmpl: Completing IO. sc %p flags 0x%llx\n",
855 spin_unlock_irqrestore(io_lock
, flags
);
857 snic_release_req_buf(snic
, rqi
, sc
);
860 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
861 jiffies_to_msecs(jiffies
- start_time
),
862 (ulong
) fwreq
, SNIC_TRC_CMD(sc
),
863 SNIC_TRC_CMD_STATE_FLAGS(sc
));
870 case SNIC_TAG_DEV_RST
:
871 case SNIC_TAG_DEV_RST
| SNIC_TAG_IOCTL_DEV_RST
:
872 snic_proc_dr_cmpl_locked(snic
, fwreq
, cmpl_stat
, cmnd_id
, sc
);
873 spin_unlock_irqrestore(io_lock
, flags
);
878 case SNIC_TAG_ABORT
| SNIC_TAG_DEV_RST
:
879 /* Abort and terminate completion of device reset req */
881 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_COMPLETE
;
882 CMD_ABTS_STATUS(sc
) = cmpl_stat
;
883 CMD_FLAGS(sc
) |= SNIC_DEV_RST_DONE
;
885 SNIC_SCSI_DBG(snic
->shost
,
886 "itmf_cmpl:dev reset abts cmpl recvd. id %d status %s flags 0x%llx\n",
887 cmnd_id
, snic_io_status_to_str(cmpl_stat
),
891 complete(rqi
->abts_done
);
893 spin_unlock_irqrestore(io_lock
, flags
);
898 spin_unlock_irqrestore(io_lock
, flags
);
899 SNIC_HOST_ERR(snic
->shost
,
900 "itmf_cmpl: Unknown TM tag bit 0x%x\n", tm_tags
);
902 SNIC_HOST_ERR(snic
->shost
,
903 "itmf_cmpl:Unexpected itmf io stat %s Tag = 0x%x flags 0x%llx\n",
904 snic_ioreq_state_to_str(CMD_STATE(sc
)),
914 } /* end of snic_process_itmf_cmpl_status */
917 * snic_itmf_cmpl_handler.
918 * Routine to handle itmf completions.
921 snic_itmf_cmpl_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
923 struct scsi_cmnd
*sc
= NULL
;
924 struct snic_req_info
*rqi
= NULL
;
925 struct snic_itmf_cmpl
*itmf_cmpl
= NULL
;
932 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
933 SNIC_SCSI_DBG(snic
->shost
,
934 "Itmf_cmpl: %s: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x,ctx = %lx\n",
935 __func__
, typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
937 itmf_cmpl
= &fwreq
->u
.itmf_cmpl
;
938 SNIC_SCSI_DBG(snic
->shost
,
939 "Itmf_cmpl: nterm %u , flags 0x%x\n",
940 le32_to_cpu(itmf_cmpl
->nterminated
), itmf_cmpl
->flags
);
942 /* spl case, dev reset issued through ioctl */
943 if (cmnd_id
& SNIC_TAG_IOCTL_DEV_RST
) {
944 rqi
= (struct snic_req_info
*) ctx
;
950 if ((cmnd_id
& SNIC_TAG_MASK
) >= snic
->max_tag_id
) {
951 SNIC_HOST_ERR(snic
->shost
,
952 "Itmf_cmpl: Tag 0x%x out of Range,HdrStat %s\n",
953 cmnd_id
, snic_io_status_to_str(hdr_stat
));
959 sc
= scsi_host_find_tag(snic
->shost
, cmnd_id
& SNIC_TAG_MASK
);
964 atomic64_inc(&snic
->s_stats
.io
.sc_null
);
965 SNIC_HOST_ERR(snic
->shost
,
966 "Itmf_cmpl: sc is NULL - Hdr Stat %s Tag 0x%x\n",
967 snic_io_status_to_str(hdr_stat
), cmnd_id
);
972 snic_process_itmf_cmpl(snic
, fwreq
, cmnd_id
, hdr_stat
, sc
);
973 } /* end of snic_itmf_cmpl_handler */
978 snic_hba_reset_scsi_cleanup(struct snic
*snic
, struct scsi_cmnd
*sc
)
980 struct snic_stats
*st
= &snic
->s_stats
;
981 long act_ios
= 0, act_fwreqs
= 0;
983 SNIC_SCSI_DBG(snic
->shost
, "HBA Reset scsi cleanup.\n");
984 snic_scsi_cleanup(snic
, snic_cmd_tag(sc
));
986 /* Update stats on pending IOs */
987 act_ios
= atomic64_read(&st
->io
.active
);
988 atomic64_add(act_ios
, &st
->io
.compl);
989 atomic64_sub(act_ios
, &st
->io
.active
);
991 act_fwreqs
= atomic64_read(&st
->fw
.actv_reqs
);
992 atomic64_sub(act_fwreqs
, &st
->fw
.actv_reqs
);
996 * snic_hba_reset_cmpl_handler :
999 * 1. Cleanup all the scsi cmds, release all snic specific cmds
1000 * 2. Issue Report Targets in case of SAN targets
1003 snic_hba_reset_cmpl_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
1010 struct scsi_cmnd
*sc
= NULL
;
1011 struct snic_req_info
*rqi
= NULL
;
1012 spinlock_t
*io_lock
= NULL
;
1013 unsigned long flags
, gflags
;
1016 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
1017 SNIC_HOST_INFO(snic
->shost
,
1018 "reset_cmpl:Tag %d ctx %lx cmpl status %s HBA Reset Completion received.\n",
1019 cmnd_id
, ctx
, snic_io_status_to_str(hdr_stat
));
1021 SNIC_SCSI_DBG(snic
->shost
,
1022 "reset_cmpl: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x, ctx = %lx\n",
1023 typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
1025 /* spl case, host reset issued through ioctl */
1026 if (cmnd_id
== SCSI_NO_TAG
) {
1027 rqi
= (struct snic_req_info
*) ctx
;
1028 SNIC_HOST_INFO(snic
->shost
,
1029 "reset_cmpl:Tag %d ctx %lx cmpl stat %s\n",
1030 cmnd_id
, ctx
, snic_io_status_to_str(hdr_stat
));
1036 if (cmnd_id
>= snic
->max_tag_id
) {
1037 SNIC_HOST_ERR(snic
->shost
,
1038 "reset_cmpl: Tag 0x%x out of Range,HdrStat %s\n",
1039 cmnd_id
, snic_io_status_to_str(hdr_stat
));
1045 sc
= scsi_host_find_tag(snic
->shost
, cmnd_id
);
1048 atomic64_inc(&snic
->s_stats
.io
.sc_null
);
1049 SNIC_HOST_ERR(snic
->shost
,
1050 "reset_cmpl: sc is NULL - Hdr Stat %s Tag 0x%x\n",
1051 snic_io_status_to_str(hdr_stat
), cmnd_id
);
1057 SNIC_HOST_INFO(snic
->shost
,
1058 "reset_cmpl: sc %p rqi %p Tag %d flags 0x%llx\n",
1059 sc
, rqi
, cmnd_id
, CMD_FLAGS(sc
));
1061 io_lock
= snic_io_lock_hash(snic
, sc
);
1062 spin_lock_irqsave(io_lock
, flags
);
1064 if (!snic
->remove_wait
) {
1065 spin_unlock_irqrestore(io_lock
, flags
);
1066 SNIC_HOST_ERR(snic
->shost
,
1067 "reset_cmpl:host reset completed after timeout\n");
1073 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1077 atomic64_inc(&snic
->s_stats
.io
.req_null
);
1078 spin_unlock_irqrestore(io_lock
, flags
);
1079 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
1080 SNIC_HOST_ERR(snic
->shost
,
1081 "reset_cmpl: rqi is null,Hdr stat %s Tag 0x%x sc 0x%p flags 0x%llx\n",
1082 snic_io_status_to_str(hdr_stat
), cmnd_id
, sc
,
1090 spin_unlock_irqrestore(io_lock
, flags
);
1093 snic_hba_reset_scsi_cleanup(snic
, sc
);
1095 SNIC_BUG_ON(snic_get_state(snic
) != SNIC_OFFLINE
&&
1096 snic_get_state(snic
) != SNIC_FWRESET
);
1098 /* Careful locking between snic_lock and io lock */
1099 spin_lock_irqsave(io_lock
, flags
);
1100 spin_lock_irqsave(&snic
->snic_lock
, gflags
);
1101 if (snic_get_state(snic
) == SNIC_FWRESET
)
1102 snic_set_state(snic
, SNIC_ONLINE
);
1103 spin_unlock_irqrestore(&snic
->snic_lock
, gflags
);
1105 if (snic
->remove_wait
)
1106 complete(snic
->remove_wait
);
1108 spin_unlock_irqrestore(io_lock
, flags
);
1109 atomic64_inc(&snic
->s_stats
.reset
.hba_reset_cmpl
);
1112 /* Rediscovery is for SAN */
1113 if (snic
->config
.xpt_type
== SNIC_DAS
)
1116 SNIC_SCSI_DBG(snic
->shost
, "reset_cmpl: Queuing discovery work.\n");
1117 queue_work(snic_glob
->event_q
, &snic
->disc_work
);
1123 snic_msg_ack_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
1125 SNIC_HOST_INFO(snic
->shost
, "Message Ack Received.\n");
1127 SNIC_ASSERT_NOT_IMPL(1);
1131 snic_aen_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
1136 struct snic_async_evnotify
*aen
= &fwreq
->u
.async_ev
;
1139 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
1140 SNIC_SCSI_DBG(snic
->shost
,
1141 "aen: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x, ctx = %lx\n",
1142 typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
1144 event_id
= le32_to_cpu(aen
->ev_id
);
1147 case SNIC_EV_TGT_OFFLINE
:
1148 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_OFFLINE Event Recvd.\n");
1151 case SNIC_EV_TGT_ONLINE
:
1152 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_ONLINE Event Recvd.\n");
1155 case SNIC_EV_LUN_OFFLINE
:
1156 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_OFFLINE Event Recvd.\n");
1159 case SNIC_EV_LUN_ONLINE
:
1160 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_ONLINE Event Recvd.\n");
1163 case SNIC_EV_CONF_CHG
:
1164 SNIC_HOST_INFO(snic
->shost
, "aen:Config Change Event Recvd.\n");
1167 case SNIC_EV_TGT_ADDED
:
1168 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_ADD Event Recvd.\n");
1171 case SNIC_EV_TGT_DELTD
:
1172 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_DEL Event Recvd.\n");
1175 case SNIC_EV_LUN_ADDED
:
1176 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_ADD Event Recvd.\n");
1179 case SNIC_EV_LUN_DELTD
:
1180 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_DEL Event Recvd.\n");
1183 case SNIC_EV_DISC_CMPL
:
1184 SNIC_HOST_INFO(snic
->shost
, "aen:DISC_CMPL Event Recvd.\n");
1188 SNIC_HOST_INFO(snic
->shost
, "aen:Unknown Event Recvd.\n");
1193 SNIC_ASSERT_NOT_IMPL(1);
1194 } /* end of snic_aen_handler */
1197 * snic_io_cmpl_handler
1198 * Routine to process CQ entries(IO Completions) posted by fw.
1201 snic_io_cmpl_handler(struct vnic_dev
*vdev
,
1202 unsigned int cq_idx
,
1203 struct snic_fw_req
*fwreq
)
1205 struct snic
*snic
= svnic_dev_priv(vdev
);
1206 u64 start
= jiffies
, cmpl_time
;
1208 snic_print_desc(__func__
, (char *)fwreq
, sizeof(*fwreq
));
1210 /* Update FW Stats */
1211 if ((fwreq
->hdr
.type
>= SNIC_RSP_REPORT_TGTS_CMPL
) &&
1212 (fwreq
->hdr
.type
<= SNIC_RSP_BOOT_LUNS_CMPL
))
1213 atomic64_dec(&snic
->s_stats
.fw
.actv_reqs
);
1215 SNIC_BUG_ON((fwreq
->hdr
.type
> SNIC_RSP_BOOT_LUNS_CMPL
) &&
1216 (fwreq
->hdr
.type
< SNIC_MSG_ASYNC_EVNOTIFY
));
1218 /* Check for snic subsys errors */
1219 switch (fwreq
->hdr
.status
) {
1220 case SNIC_STAT_NOT_READY
: /* XPT yet to initialize */
1221 SNIC_HOST_ERR(snic
->shost
,
1222 "sNIC SubSystem is NOT Ready.\n");
1225 case SNIC_STAT_FATAL_ERROR
: /* XPT Error */
1226 SNIC_HOST_ERR(snic
->shost
,
1227 "sNIC SubSystem in Unrecoverable State.\n");
1231 switch (fwreq
->hdr
.type
) {
1232 case SNIC_RSP_EXCH_VER_CMPL
:
1233 snic_io_exch_ver_cmpl_handler(snic
, fwreq
);
1236 case SNIC_RSP_REPORT_TGTS_CMPL
:
1237 snic_report_tgt_cmpl_handler(snic
, fwreq
);
1240 case SNIC_RSP_ICMND_CMPL
:
1241 snic_icmnd_cmpl_handler(snic
, fwreq
);
1244 case SNIC_RSP_ITMF_CMPL
:
1245 snic_itmf_cmpl_handler(snic
, fwreq
);
1248 case SNIC_RSP_HBA_RESET_CMPL
:
1249 snic_hba_reset_cmpl_handler(snic
, fwreq
);
1253 snic_msg_ack_handler(snic
, fwreq
);
1256 case SNIC_MSG_ASYNC_EVNOTIFY
:
1257 snic_aen_handler(snic
, fwreq
);
1262 SNIC_SCSI_DBG(snic
->shost
,
1263 "Unknown Firmware completion request type %d\n",
1269 cmpl_time
= jiffies
- start
;
1270 if (cmpl_time
> atomic64_read(&snic
->s_stats
.io
.max_cmpl_time
))
1271 atomic64_set(&snic
->s_stats
.io
.max_cmpl_time
, cmpl_time
);
1274 } /* end of snic_io_cmpl_handler */
1277 * snic_fwcq_cmpl_handler
1278 * Routine to process fwCQ
1279 * This CQ is independent, and not associated with wq/rq/wq_copy queues
1282 snic_fwcq_cmpl_handler(struct snic
*snic
, int io_cmpl_work
)
1284 unsigned int num_ent
= 0; /* number cq entries processed */
1285 unsigned int cq_idx
;
1286 unsigned int nent_per_cq
;
1287 struct snic_misc_stats
*misc_stats
= &snic
->s_stats
.misc
;
1289 for (cq_idx
= snic
->wq_count
; cq_idx
< snic
->cq_count
; cq_idx
++) {
1290 nent_per_cq
= vnic_cq_fw_service(&snic
->cq
[cq_idx
],
1291 snic_io_cmpl_handler
,
1293 num_ent
+= nent_per_cq
;
1295 if (nent_per_cq
> atomic64_read(&misc_stats
->max_cq_ents
))
1296 atomic64_set(&misc_stats
->max_cq_ents
, nent_per_cq
);
1300 } /* end of snic_fwcq_cmpl_handler */
1303 * snic_queue_itmf_req: Common API to queue Task Management requests.
1304 * Use rqi->tm_tag for passing special tags.
1305 * @req_id : aborted request's tag, -1 for lun reset.
1308 snic_queue_itmf_req(struct snic
*snic
,
1309 struct snic_host_req
*tmreq
,
1310 struct scsi_cmnd
*sc
,
1314 struct snic_req_info
*rqi
= req_to_rqi(tmreq
);
1315 struct scsi_lun lun
;
1316 int tm_tag
= snic_cmd_tag(sc
) | rqi
->tm_tag
;
1320 SNIC_BUG_ON(!rqi
->tm_tag
);
1322 /* fill in lun info */
1323 int_to_scsilun(sc
->device
->lun
, &lun
);
1325 /* Initialize snic_host_req: itmf */
1326 snic_itmf_init(tmreq
,
1331 req_id
, /* Command to be aborted. */
1337 * In case of multiple aborts on same cmd,
1338 * use try_wait_for_completion and completion_done() to check
1339 * whether it queues aborts even after completion of abort issued
1340 * prior.SNIC_BUG_ON(completion_done(&rqi->done));
1343 ret
= snic_queue_wq_desc(snic
, tmreq
, sizeof(*tmreq
));
1345 SNIC_HOST_ERR(snic
->shost
,
1346 "qitmf:Queuing ITMF(%d) Req sc %p, rqi %p, req_id %d tag %d Failed, ret = %d\n",
1347 tmf
, sc
, rqi
, req_id
, snic_cmd_tag(sc
), ret
);
1349 SNIC_SCSI_DBG(snic
->shost
,
1350 "qitmf:Queuing ITMF(%d) Req sc %p, rqi %p, req_id %d, tag %d (req_id)- Success.",
1351 tmf
, sc
, rqi
, req_id
, snic_cmd_tag(sc
));
1354 } /* end of snic_queue_itmf_req */
1357 snic_issue_tm_req(struct snic
*snic
,
1358 struct snic_req_info
*rqi
,
1359 struct scsi_cmnd
*sc
,
1362 struct snic_host_req
*tmreq
= NULL
;
1363 int req_id
= 0, tag
= snic_cmd_tag(sc
);
1366 if (snic_get_state(snic
) == SNIC_FWRESET
)
1369 atomic_inc(&snic
->ios_inflight
);
1371 SNIC_SCSI_DBG(snic
->shost
,
1372 "issu_tmreq: Task mgmt req %d. rqi %p w/ tag %x\n",
1376 if (tmf
== SNIC_ITMF_LUN_RESET
) {
1377 tmreq
= snic_dr_req_init(snic
, rqi
);
1378 req_id
= SCSI_NO_TAG
;
1380 tmreq
= snic_abort_req_init(snic
, rqi
);
1390 ret
= snic_queue_itmf_req(snic
, tmreq
, sc
, tmf
, req_id
);
1398 SNIC_HOST_ERR(snic
->shost
,
1399 "issu_tmreq: Queing ITMF(%d) Req, sc %p rqi %p req_id %d tag %x fails err = %d\n",
1400 tmf
, sc
, rqi
, req_id
, tag
, ret
);
1402 SNIC_SCSI_DBG(snic
->shost
,
1403 "issu_tmreq: Queuing ITMF(%d) Req, sc %p, rqi %p, req_id %d tag %x - Success.\n",
1404 tmf
, sc
, rqi
, req_id
, tag
);
1407 atomic_dec(&snic
->ios_inflight
);
1413 * snic_queue_abort_req : Queues abort req to WQ
1416 snic_queue_abort_req(struct snic
*snic
,
1417 struct snic_req_info
*rqi
,
1418 struct scsi_cmnd
*sc
,
1421 SNIC_SCSI_DBG(snic
->shost
, "q_abtreq: sc %p, rqi %p, tag %x, tmf %d\n",
1422 sc
, rqi
, snic_cmd_tag(sc
), tmf
);
1424 /* Add special tag for abort */
1425 rqi
->tm_tag
|= SNIC_TAG_ABORT
;
1427 return snic_issue_tm_req(snic
, rqi
, sc
, tmf
);
1431 * snic_abort_finish : called by snic_abort_cmd on queuing abort successfully.
1434 snic_abort_finish(struct snic
*snic
, struct scsi_cmnd
*sc
)
1436 struct snic_req_info
*rqi
= NULL
;
1437 spinlock_t
*io_lock
= NULL
;
1438 unsigned long flags
;
1439 int ret
= 0, tag
= snic_cmd_tag(sc
);
1441 io_lock
= snic_io_lock_hash(snic
, sc
);
1442 spin_lock_irqsave(io_lock
, flags
);
1443 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1445 atomic64_inc(&snic
->s_stats
.io
.req_null
);
1446 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
1448 SNIC_SCSI_DBG(snic
->shost
,
1449 "abt_fini:req info is null tag 0x%x, sc 0x%p flags 0x%llx\n",
1450 tag
, sc
, CMD_FLAGS(sc
));
1456 rqi
->abts_done
= NULL
;
1460 /* Check the abort status. */
1461 switch (CMD_ABTS_STATUS(sc
)) {
1462 case SNIC_INVALID_CODE
:
1463 /* Firmware didn't complete abort req, timedout */
1464 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TIMEDOUT
;
1465 atomic64_inc(&snic
->s_stats
.abts
.drv_tmo
);
1466 SNIC_SCSI_DBG(snic
->shost
,
1467 "abt_fini:sc %p Tag %x Driver Timeout.flags 0x%llx\n",
1468 sc
, snic_cmd_tag(sc
), CMD_FLAGS(sc
));
1469 /* do not release snic request in timedout case */
1474 case SNIC_STAT_IO_SUCCESS
:
1475 case SNIC_STAT_IO_NOT_FOUND
:
1478 * If abort path doesn't call scsi_done(),
1479 * the # IO timeouts == 2, will cause the LUN offline.
1480 * Call scsi_done to complete the IO.
1482 sc
->result
= (DID_ERROR
<< 16);
1487 /* Firmware completed abort with error */
1494 SNIC_HOST_INFO(snic
->shost
,
1495 "abt_fini: Tag %x, Cmpl Status %s flags 0x%llx\n",
1496 tag
, snic_io_status_to_str(CMD_ABTS_STATUS(sc
)),
1500 spin_unlock_irqrestore(io_lock
, flags
);
1502 snic_release_req_buf(snic
, rqi
, sc
);
1505 } /* end of snic_abort_finish */
1508 * snic_send_abort_and_wait : Issues Abort, and Waits
1511 snic_send_abort_and_wait(struct snic
*snic
, struct scsi_cmnd
*sc
)
1513 struct snic_req_info
*rqi
= NULL
;
1514 enum snic_ioreq_state sv_state
;
1515 struct snic_tgt
*tgt
= NULL
;
1516 spinlock_t
*io_lock
= NULL
;
1517 DECLARE_COMPLETION_ONSTACK(tm_done
);
1518 unsigned long flags
;
1519 int ret
= 0, tmf
= 0, tag
= snic_cmd_tag(sc
);
1521 tgt
= starget_to_tgt(scsi_target(sc
->device
));
1522 if ((snic_tgt_chkready(tgt
) != 0) && (tgt
->tdata
.typ
== SNIC_TGT_SAN
))
1523 tmf
= SNIC_ITMF_ABTS_TASK_TERM
;
1525 tmf
= SNIC_ITMF_ABTS_TASK
;
1529 io_lock
= snic_io_lock_hash(snic
, sc
);
1532 * Avoid a race between SCSI issuing the abort and the device
1533 * completing the command.
1535 * If the command is already completed by fw_cmpl code,
1536 * we just return SUCCESS from here. This means that the abort
1537 * succeeded. In the SCSI ML, since the timeout for command has
1538 * happend, the completion wont actually complete the command
1539 * and it will be considered as an aborted command
1541 * The CMD_SP will not be cleared except while holding io_lock
1543 spin_lock_irqsave(io_lock
, flags
);
1544 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1546 spin_unlock_irqrestore(io_lock
, flags
);
1548 SNIC_HOST_ERR(snic
->shost
,
1549 "abt_cmd: rqi is null. Tag %d flags 0x%llx\n",
1550 tag
, CMD_FLAGS(sc
));
1557 rqi
->abts_done
= &tm_done
;
1558 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
) {
1559 spin_unlock_irqrestore(io_lock
, flags
);
1564 SNIC_BUG_ON(!rqi
->abts_done
);
1566 /* Save Command State, should be restored on failed to Queue. */
1567 sv_state
= CMD_STATE(sc
);
1570 * Command is still pending, need to abort it
1571 * If the fw completes the command after this point,
1572 * the completion won't be done till mid-layer, since abot
1573 * has already started.
1575 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_PENDING
;
1576 CMD_ABTS_STATUS(sc
) = SNIC_INVALID_CODE
;
1578 SNIC_SCSI_DBG(snic
->shost
, "send_abt_cmd: TAG 0x%x\n", tag
);
1580 spin_unlock_irqrestore(io_lock
, flags
);
1582 /* Now Queue the abort command to firmware */
1583 ret
= snic_queue_abort_req(snic
, rqi
, sc
, tmf
);
1585 atomic64_inc(&snic
->s_stats
.abts
.q_fail
);
1586 SNIC_HOST_ERR(snic
->shost
,
1587 "send_abt_cmd: IO w/ Tag 0x%x fail w/ err %d flags 0x%llx\n",
1588 tag
, ret
, CMD_FLAGS(sc
));
1590 spin_lock_irqsave(io_lock
, flags
);
1591 /* Restore Command's previous state */
1592 CMD_STATE(sc
) = sv_state
;
1593 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1595 rqi
->abts_done
= NULL
;
1596 spin_unlock_irqrestore(io_lock
, flags
);
1602 spin_lock_irqsave(io_lock
, flags
);
1603 if (tmf
== SNIC_ITMF_ABTS_TASK
) {
1604 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_ISSUED
;
1605 atomic64_inc(&snic
->s_stats
.abts
.num
);
1608 CMD_FLAGS(sc
) |= SNIC_IO_TERM_ISSUED
;
1610 spin_unlock_irqrestore(io_lock
, flags
);
1612 SNIC_SCSI_DBG(snic
->shost
,
1613 "send_abt_cmd: sc %p Tag %x flags 0x%llx\n",
1614 sc
, tag
, CMD_FLAGS(sc
));
1621 * Queued an abort IO, wait for its completion.
1622 * Once the fw completes the abort command, it will
1623 * wakeup this thread.
1625 wait_for_completion_timeout(&tm_done
, SNIC_ABTS_TIMEOUT
);
1629 } /* end of snic_send_abort_and_wait */
1632 * This function is exported to SCSI for sending abort cmnds.
1633 * A SCSI IO is represent by snic_ioreq in the driver.
1634 * The snic_ioreq is linked to the SCSI Cmd, thus a link with the ULP'S IO
1637 snic_abort_cmd(struct scsi_cmnd
*sc
)
1639 struct snic
*snic
= shost_priv(sc
->device
->host
);
1640 int ret
= SUCCESS
, tag
= snic_cmd_tag(sc
);
1641 u32 start_time
= jiffies
;
1643 SNIC_SCSI_DBG(snic
->shost
, "abt_cmd:sc %p :0x%x :req = %p :tag = %d\n",
1644 sc
, sc
->cmnd
[0], sc
->request
, tag
);
1646 if (unlikely(snic_get_state(snic
) != SNIC_ONLINE
)) {
1647 SNIC_HOST_ERR(snic
->shost
,
1648 "abt_cmd: tag %x Parent Devs are not rdy\n",
1656 ret
= snic_send_abort_and_wait(snic
, sc
);
1660 ret
= snic_abort_finish(snic
, sc
);
1663 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
,
1664 jiffies_to_msecs(jiffies
- start_time
), 0,
1665 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
1667 SNIC_SCSI_DBG(snic
->shost
,
1668 "abts: Abort Req Status = %s\n",
1669 (ret
== SUCCESS
) ? "SUCCESS" :
1670 ((ret
== FAST_IO_FAIL
) ? "FAST_IO_FAIL" : "FAILED"));
1678 snic_is_abts_pending(struct snic
*snic
, struct scsi_cmnd
*lr_sc
)
1680 struct snic_req_info
*rqi
= NULL
;
1681 struct scsi_cmnd
*sc
= NULL
;
1682 struct scsi_device
*lr_sdev
= NULL
;
1683 spinlock_t
*io_lock
= NULL
;
1685 unsigned long flags
;
1688 lr_sdev
= lr_sc
->device
;
1690 /* walk through the tag map, an dcheck if IOs are still pending in fw*/
1691 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
1692 io_lock
= snic_io_lock_tag(snic
, tag
);
1694 spin_lock_irqsave(io_lock
, flags
);
1695 sc
= scsi_host_find_tag(snic
->shost
, tag
);
1697 if (!sc
|| (lr_sc
&& (sc
->device
!= lr_sdev
|| sc
== lr_sc
))) {
1698 spin_unlock_irqrestore(io_lock
, flags
);
1703 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1705 spin_unlock_irqrestore(io_lock
, flags
);
1711 * Found IO that is still pending w/ firmware and belongs to
1712 * the LUN that is under reset, if lr_sc != NULL
1714 SNIC_SCSI_DBG(snic
->shost
, "Found IO in %s on LUN\n",
1715 snic_ioreq_state_to_str(CMD_STATE(sc
)));
1717 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
) {
1718 spin_unlock_irqrestore(io_lock
, flags
);
1723 spin_unlock_irqrestore(io_lock
, flags
);
1727 } /* end of snic_is_abts_pending */
1730 snic_dr_clean_single_req(struct snic
*snic
,
1732 struct scsi_device
*lr_sdev
)
1734 struct snic_req_info
*rqi
= NULL
;
1735 struct snic_tgt
*tgt
= NULL
;
1736 struct scsi_cmnd
*sc
= NULL
;
1737 spinlock_t
*io_lock
= NULL
;
1738 u32 sv_state
= 0, tmf
= 0;
1739 DECLARE_COMPLETION_ONSTACK(tm_done
);
1740 unsigned long flags
;
1743 io_lock
= snic_io_lock_tag(snic
, tag
);
1744 spin_lock_irqsave(io_lock
, flags
);
1745 sc
= scsi_host_find_tag(snic
->shost
, tag
);
1747 /* Ignore Cmd that don't belong to Lun Reset device */
1748 if (!sc
|| sc
->device
!= lr_sdev
)
1751 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1757 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
1761 if ((CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) &&
1762 (!(CMD_FLAGS(sc
) & SNIC_DEV_RST_ISSUED
))) {
1764 SNIC_SCSI_DBG(snic
->shost
,
1765 "clean_single_req: devrst is not pending sc 0x%p\n",
1771 SNIC_SCSI_DBG(snic
->shost
,
1772 "clean_single_req: Found IO in %s on lun\n",
1773 snic_ioreq_state_to_str(CMD_STATE(sc
)));
1775 /* Save Command State */
1776 sv_state
= CMD_STATE(sc
);
1779 * Any pending IO issued prior to reset is expected to be
1780 * in abts pending state, if not we need to set SNIC_IOREQ_ABTS_PENDING
1781 * to indicate the IO is abort pending.
1782 * When IO is completed, the IO will be handed over and handled
1786 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_PENDING
;
1787 SNIC_BUG_ON(rqi
->abts_done
);
1789 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) {
1790 rqi
->tm_tag
= SNIC_TAG_DEV_RST
;
1792 SNIC_SCSI_DBG(snic
->shost
,
1793 "clean_single_req:devrst sc 0x%p\n", sc
);
1796 CMD_ABTS_STATUS(sc
) = SNIC_INVALID_CODE
;
1797 rqi
->abts_done
= &tm_done
;
1798 spin_unlock_irqrestore(io_lock
, flags
);
1800 tgt
= starget_to_tgt(scsi_target(sc
->device
));
1801 if ((snic_tgt_chkready(tgt
) != 0) && (tgt
->tdata
.typ
== SNIC_TGT_SAN
))
1802 tmf
= SNIC_ITMF_ABTS_TASK_TERM
;
1804 tmf
= SNIC_ITMF_ABTS_TASK
;
1806 /* Now queue the abort command to firmware */
1807 ret
= snic_queue_abort_req(snic
, rqi
, sc
, tmf
);
1809 SNIC_HOST_ERR(snic
->shost
,
1810 "clean_single_req_err:sc %p, tag %d abt failed. tm_tag %d flags 0x%llx\n",
1811 sc
, tag
, rqi
->tm_tag
, CMD_FLAGS(sc
));
1813 spin_lock_irqsave(io_lock
, flags
);
1814 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1816 rqi
->abts_done
= NULL
;
1818 /* Restore Command State */
1819 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
1820 CMD_STATE(sc
) = sv_state
;
1826 spin_lock_irqsave(io_lock
, flags
);
1827 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
)
1828 CMD_FLAGS(sc
) |= SNIC_DEV_RST_TERM_ISSUED
;
1830 CMD_FLAGS(sc
) |= SNIC_IO_INTERNAL_TERM_ISSUED
;
1831 spin_unlock_irqrestore(io_lock
, flags
);
1833 wait_for_completion_timeout(&tm_done
, SNIC_ABTS_TIMEOUT
);
1835 /* Recheck cmd state to check if it now aborted. */
1836 spin_lock_irqsave(io_lock
, flags
);
1837 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1839 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
1842 rqi
->abts_done
= NULL
;
1844 /* if abort is still pending w/ fw, fail */
1845 if (CMD_ABTS_STATUS(sc
) == SNIC_INVALID_CODE
) {
1846 SNIC_HOST_ERR(snic
->shost
,
1847 "clean_single_req_err:sc %p tag %d abt still pending w/ fw, tm_tag %d flags 0x%llx\n",
1848 sc
, tag
, rqi
->tm_tag
, CMD_FLAGS(sc
));
1850 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_DONE
;
1856 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_COMPLETE
;
1858 spin_unlock_irqrestore(io_lock
, flags
);
1860 snic_release_req_buf(snic
, rqi
, sc
);
1862 sc
->result
= (DID_ERROR
<< 16);
1870 spin_unlock_irqrestore(io_lock
, flags
);
1873 } /* end of snic_dr_clean_single_req */
1876 snic_dr_clean_pending_req(struct snic
*snic
, struct scsi_cmnd
*lr_sc
)
1878 struct scsi_device
*lr_sdev
= lr_sc
->device
;
1882 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
1883 if (tag
== snic_cmd_tag(lr_sc
))
1886 ret
= snic_dr_clean_single_req(snic
, tag
, lr_sdev
);
1888 SNIC_HOST_ERR(snic
->shost
, "clean_err:tag = %d\n", tag
);
1894 schedule_timeout(msecs_to_jiffies(100));
1896 /* Walk through all the cmds and check abts status. */
1897 if (snic_is_abts_pending(snic
, lr_sc
)) {
1904 SNIC_SCSI_DBG(snic
->shost
, "clean_pending_req: Success.\n");
1910 SNIC_HOST_ERR(snic
->shost
,
1911 "Failed to Clean Pending IOs on %s device.\n",
1912 dev_name(&lr_sdev
->sdev_gendev
));
1916 } /* end of snic_dr_clean_pending_req */
1919 * snic_dr_finish : Called by snic_device_reset
1922 snic_dr_finish(struct snic
*snic
, struct scsi_cmnd
*sc
)
1924 struct snic_req_info
*rqi
= NULL
;
1925 spinlock_t
*io_lock
= NULL
;
1926 unsigned long flags
;
1930 io_lock
= snic_io_lock_hash(snic
, sc
);
1931 spin_lock_irqsave(io_lock
, flags
);
1932 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1934 spin_unlock_irqrestore(io_lock
, flags
);
1935 SNIC_SCSI_DBG(snic
->shost
,
1936 "dr_fini: rqi is null tag 0x%x sc 0x%p flags 0x%llx\n",
1937 snic_cmd_tag(sc
), sc
, CMD_FLAGS(sc
));
1943 rqi
->dr_done
= NULL
;
1945 lr_res
= CMD_LR_STATUS(sc
);
1948 case SNIC_INVALID_CODE
:
1950 SNIC_SCSI_DBG(snic
->shost
,
1951 "dr_fini: Tag %x Dev Reset Timedout. flags 0x%llx\n",
1952 snic_cmd_tag(sc
), CMD_FLAGS(sc
));
1954 CMD_FLAGS(sc
) |= SNIC_DEV_RST_TIMEDOUT
;
1959 case SNIC_STAT_IO_SUCCESS
:
1960 SNIC_SCSI_DBG(snic
->shost
,
1961 "dr_fini: Tag %x Dev Reset cmpl\n",
1967 SNIC_HOST_ERR(snic
->shost
,
1968 "dr_fini:Device Reset completed& failed.Tag = %x lr_status %s flags 0x%llx\n",
1970 snic_io_status_to_str(lr_res
), CMD_FLAGS(sc
));
1974 spin_unlock_irqrestore(io_lock
, flags
);
1977 * Cleanup any IOs on this LUN that have still not completed.
1978 * If any of these fail, then LUN Reset fails.
1979 * Cleanup cleans all commands on this LUN except
1980 * the lun reset command. If all cmds get cleaned, the LUN Reset
1984 ret
= snic_dr_clean_pending_req(snic
, sc
);
1986 spin_lock_irqsave(io_lock
, flags
);
1987 SNIC_SCSI_DBG(snic
->shost
,
1988 "dr_fini: Device Reset Failed since could not abort all IOs. Tag = %x.\n",
1990 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1994 /* Cleanup LUN Reset Command */
1995 spin_lock_irqsave(io_lock
, flags
);
1996 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1998 ret
= SUCCESS
; /* Completed Successfully */
2004 SNIC_BUG_ON(!spin_is_locked(io_lock
));
2007 spin_unlock_irqrestore(io_lock
, flags
);
2010 snic_release_req_buf(snic
, rqi
, sc
);
2014 } /* end of snic_dr_finish */
2017 snic_queue_dr_req(struct snic
*snic
,
2018 struct snic_req_info
*rqi
,
2019 struct scsi_cmnd
*sc
)
2021 /* Add special tag for device reset */
2022 rqi
->tm_tag
|= SNIC_TAG_DEV_RST
;
2024 return snic_issue_tm_req(snic
, rqi
, sc
, SNIC_ITMF_LUN_RESET
);
2028 snic_send_dr_and_wait(struct snic
*snic
, struct scsi_cmnd
*sc
)
2030 struct snic_req_info
*rqi
= NULL
;
2031 enum snic_ioreq_state sv_state
;
2032 spinlock_t
*io_lock
= NULL
;
2033 unsigned long flags
;
2034 DECLARE_COMPLETION_ONSTACK(tm_done
);
2035 int ret
= FAILED
, tag
= snic_cmd_tag(sc
);
2037 io_lock
= snic_io_lock_hash(snic
, sc
);
2038 spin_lock_irqsave(io_lock
, flags
);
2039 CMD_FLAGS(sc
) |= SNIC_DEVICE_RESET
;
2040 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2042 SNIC_HOST_ERR(snic
->shost
,
2043 "send_dr: rqi is null, Tag 0x%x flags 0x%llx\n",
2044 tag
, CMD_FLAGS(sc
));
2045 spin_unlock_irqrestore(io_lock
, flags
);
2051 /* Save Command state to restore in case Queuing failed. */
2052 sv_state
= CMD_STATE(sc
);
2054 CMD_STATE(sc
) = SNIC_IOREQ_LR_PENDING
;
2055 CMD_LR_STATUS(sc
) = SNIC_INVALID_CODE
;
2057 SNIC_SCSI_DBG(snic
->shost
, "dr: TAG = %x\n", tag
);
2059 rqi
->dr_done
= &tm_done
;
2060 SNIC_BUG_ON(!rqi
->dr_done
);
2062 spin_unlock_irqrestore(io_lock
, flags
);
2064 * The Command state is changed to IOREQ_PENDING,
2065 * in this case, if the command is completed, the icmnd_cmpl will
2066 * mark the cmd as completed.
2067 * This logic still makes LUN Reset is inevitable.
2070 ret
= snic_queue_dr_req(snic
, rqi
, sc
);
2072 SNIC_HOST_ERR(snic
->shost
,
2073 "send_dr: IO w/ Tag 0x%x Failed err = %d. flags 0x%llx\n",
2074 tag
, ret
, CMD_FLAGS(sc
));
2076 spin_lock_irqsave(io_lock
, flags
);
2078 CMD_STATE(sc
) = sv_state
;
2079 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2081 rqi
->dr_done
= NULL
;
2082 /* rqi is freed in caller. */
2083 spin_unlock_irqrestore(io_lock
, flags
);
2089 spin_lock_irqsave(io_lock
, flags
);
2090 CMD_FLAGS(sc
) |= SNIC_DEV_RST_ISSUED
;
2091 spin_unlock_irqrestore(io_lock
, flags
);
2095 wait_for_completion_timeout(&tm_done
, SNIC_LUN_RESET_TIMEOUT
);
2102 * auxillary funciton to check lun reset op is supported or not
2103 * Not supported if returns 0
2106 snic_dev_reset_supported(struct scsi_device
*sdev
)
2108 struct snic_tgt
*tgt
= starget_to_tgt(scsi_target(sdev
));
2110 if (tgt
->tdata
.typ
== SNIC_TGT_DAS
)
2117 snic_unlink_and_release_req(struct snic
*snic
, struct scsi_cmnd
*sc
, int flag
)
2119 struct snic_req_info
*rqi
= NULL
;
2120 spinlock_t
*io_lock
= NULL
;
2121 unsigned long flags
;
2122 u32 start_time
= jiffies
;
2124 io_lock
= snic_io_lock_hash(snic
, sc
);
2125 spin_lock_irqsave(io_lock
, flags
);
2126 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2128 start_time
= rqi
->start_time
;
2132 CMD_FLAGS(sc
) |= flag
;
2133 spin_unlock_irqrestore(io_lock
, flags
);
2136 snic_release_req_buf(snic
, rqi
, sc
);
2138 SNIC_TRC(snic
->shost
->host_no
, snic_cmd_tag(sc
), (ulong
) sc
,
2139 jiffies_to_msecs(jiffies
- start_time
), (ulong
) rqi
,
2140 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
2144 * SCSI Eh thread issues a LUN Reset when one or more commands on a LUN
2145 * fail to get aborted. It calls driver's eh_device_reset with a SCSI
2146 * command on the LUN.
2149 snic_device_reset(struct scsi_cmnd
*sc
)
2151 struct Scsi_Host
*shost
= sc
->device
->host
;
2152 struct snic
*snic
= shost_priv(shost
);
2153 struct snic_req_info
*rqi
= NULL
;
2154 int tag
= snic_cmd_tag(sc
);
2155 int start_time
= jiffies
;
2159 SNIC_SCSI_DBG(shost
, "dev_reset:sc %p :0x%x :req = %p :tag = %d\n",
2160 sc
, sc
->cmnd
[0], sc
->request
,
2162 dr_supp
= snic_dev_reset_supported(sc
->device
);
2164 /* device reset op is not supported */
2165 SNIC_HOST_INFO(shost
, "LUN Reset Op not supported.\n");
2166 snic_unlink_and_release_req(snic
, sc
, SNIC_DEV_RST_NOTSUP
);
2171 if (unlikely(snic_get_state(snic
) != SNIC_ONLINE
)) {
2172 snic_unlink_and_release_req(snic
, sc
, 0);
2173 SNIC_HOST_ERR(shost
, "Devrst: Parent Devs are not online.\n");
2178 /* There is no tag when lun reset is issue through ioctl. */
2179 if (unlikely(tag
<= SNIC_NO_TAG
)) {
2180 SNIC_HOST_INFO(snic
->shost
,
2181 "Devrst: LUN Reset Recvd thru IOCTL.\n");
2183 rqi
= snic_req_init(snic
, 0);
2187 memset(scsi_cmd_priv(sc
), 0,
2188 sizeof(struct snic_internal_io_state
));
2189 CMD_SP(sc
) = (char *)rqi
;
2190 CMD_FLAGS(sc
) = SNIC_NO_FLAGS
;
2192 /* Add special tag for dr coming from user spc */
2193 rqi
->tm_tag
= SNIC_TAG_IOCTL_DEV_RST
;
2197 ret
= snic_send_dr_and_wait(snic
, sc
);
2199 SNIC_HOST_ERR(snic
->shost
,
2200 "Devrst: IO w/ Tag %x Failed w/ err = %d\n",
2203 snic_unlink_and_release_req(snic
, sc
, 0);
2208 ret
= snic_dr_finish(snic
, sc
);
2211 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
,
2212 jiffies_to_msecs(jiffies
- start_time
),
2213 0, SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
2215 SNIC_SCSI_DBG(snic
->shost
,
2216 "Devrst: Returning from Device Reset : %s\n",
2217 (ret
== SUCCESS
) ? "SUCCESS" : "FAILED");
2220 } /* end of snic_device_reset */
2223 * SCSI Error handling calls driver's eh_host_reset if all prior
2224 * error handling levels return FAILED.
2226 * Host Reset is the highest level of error recovery. If this fails, then
2227 * host is offlined by SCSI.
2230 * snic_issue_hba_reset : Queues FW Reset Request.
2233 snic_issue_hba_reset(struct snic
*snic
, struct scsi_cmnd
*sc
)
2235 struct snic_req_info
*rqi
= NULL
;
2236 struct snic_host_req
*req
= NULL
;
2237 spinlock_t
*io_lock
= NULL
;
2238 DECLARE_COMPLETION_ONSTACK(wait
);
2239 unsigned long flags
;
2242 rqi
= snic_req_init(snic
, 0);
2249 if (snic_cmd_tag(sc
) == SCSI_NO_TAG
) {
2250 memset(scsi_cmd_priv(sc
), 0,
2251 sizeof(struct snic_internal_io_state
));
2252 SNIC_HOST_INFO(snic
->shost
, "issu_hr:Host reset thru ioctl.\n");
2256 req
= rqi_to_req(rqi
);
2258 io_lock
= snic_io_lock_hash(snic
, sc
);
2259 spin_lock_irqsave(io_lock
, flags
);
2260 SNIC_BUG_ON(CMD_SP(sc
) != NULL
);
2261 CMD_STATE(sc
) = SNIC_IOREQ_PENDING
;
2262 CMD_SP(sc
) = (char *) rqi
;
2263 CMD_FLAGS(sc
) |= SNIC_IO_INITIALIZED
;
2264 snic
->remove_wait
= &wait
;
2265 spin_unlock_irqrestore(io_lock
, flags
);
2267 /* Initialize Request */
2268 snic_io_hdr_enc(&req
->hdr
, SNIC_REQ_HBA_RESET
, 0, snic_cmd_tag(sc
),
2269 snic
->config
.hid
, 0, (ulong
) rqi
);
2271 req
->u
.reset
.flags
= 0;
2273 ret
= snic_queue_wq_desc(snic
, req
, sizeof(*req
));
2275 SNIC_HOST_ERR(snic
->shost
,
2276 "issu_hr:Queuing HBA Reset Failed. w err %d\n",
2282 spin_lock_irqsave(io_lock
, flags
);
2283 CMD_FLAGS(sc
) |= SNIC_HOST_RESET_ISSUED
;
2284 spin_unlock_irqrestore(io_lock
, flags
);
2285 atomic64_inc(&snic
->s_stats
.reset
.hba_resets
);
2286 SNIC_HOST_INFO(snic
->shost
, "Queued HBA Reset Successfully.\n");
2288 wait_for_completion_timeout(snic
->remove_wait
,
2289 SNIC_HOST_RESET_TIMEOUT
);
2291 if (snic_get_state(snic
) == SNIC_FWRESET
) {
2292 SNIC_HOST_ERR(snic
->shost
, "reset_cmpl: Reset Timedout.\n");
2298 spin_lock_irqsave(io_lock
, flags
);
2299 snic
->remove_wait
= NULL
;
2300 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2302 spin_unlock_irqrestore(io_lock
, flags
);
2305 snic_req_free(snic
, rqi
);
2312 spin_lock_irqsave(io_lock
, flags
);
2313 snic
->remove_wait
= NULL
;
2314 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2316 spin_unlock_irqrestore(io_lock
, flags
);
2319 snic_req_free(snic
, rqi
);
2322 SNIC_HOST_ERR(snic
->shost
,
2323 "reset:HBA Reset Failed w/ err = %d.\n",
2327 } /* end of snic_issue_hba_reset */
2330 snic_reset(struct Scsi_Host
*shost
, struct scsi_cmnd
*sc
)
2332 struct snic
*snic
= shost_priv(shost
);
2333 enum snic_state sv_state
;
2334 unsigned long flags
;
2337 /* Set snic state as SNIC_FWRESET*/
2338 sv_state
= snic_get_state(snic
);
2340 spin_lock_irqsave(&snic
->snic_lock
, flags
);
2341 if (snic_get_state(snic
) == SNIC_FWRESET
) {
2342 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
2343 SNIC_HOST_INFO(shost
, "reset:prev reset is in progres\n");
2345 msleep(SNIC_HOST_RESET_TIMEOUT
);
2351 snic_set_state(snic
, SNIC_FWRESET
);
2352 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
2355 /* Wait for all the IOs that are entered in Qcmd */
2356 while (atomic_read(&snic
->ios_inflight
))
2357 schedule_timeout(msecs_to_jiffies(1));
2359 ret
= snic_issue_hba_reset(snic
, sc
);
2361 SNIC_HOST_ERR(shost
,
2362 "reset:Host Reset Failed w/ err %d.\n",
2364 spin_lock_irqsave(&snic
->snic_lock
, flags
);
2365 snic_set_state(snic
, sv_state
);
2366 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
2367 atomic64_inc(&snic
->s_stats
.reset
.hba_reset_fail
);
2377 } /* end of snic_reset */
2380 * SCSI Error handling calls driver's eh_host_reset if all prior
2381 * error handling levels return FAILED.
2383 * Host Reset is the highest level of error recovery. If this fails, then
2384 * host is offlined by SCSI.
2387 snic_host_reset(struct scsi_cmnd
*sc
)
2389 struct Scsi_Host
*shost
= sc
->device
->host
;
2390 u32 start_time
= jiffies
;
2393 SNIC_SCSI_DBG(shost
,
2394 "host reset:sc %p sc_cmd 0x%x req %p tag %d flags 0x%llx\n",
2395 sc
, sc
->cmnd
[0], sc
->request
,
2396 snic_cmd_tag(sc
), CMD_FLAGS(sc
));
2398 ret
= snic_reset(shost
, sc
);
2400 SNIC_TRC(shost
->host_no
, snic_cmd_tag(sc
), (ulong
) sc
,
2401 jiffies_to_msecs(jiffies
- start_time
),
2402 0, SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
2405 } /* end of snic_host_reset */
2408 * snic_cmpl_pending_tmreq : Caller should hold io_lock
2411 snic_cmpl_pending_tmreq(struct snic
*snic
, struct scsi_cmnd
*sc
)
2413 struct snic_req_info
*rqi
= NULL
;
2415 SNIC_SCSI_DBG(snic
->shost
,
2416 "Completing Pending TM Req sc %p, state %s flags 0x%llx\n",
2417 sc
, snic_io_status_to_str(CMD_STATE(sc
)), CMD_FLAGS(sc
));
2420 * CASE : FW didn't post itmf completion due to PCIe Errors.
2421 * Marking the abort status as Success to call scsi completion
2422 * in snic_abort_finish()
2424 CMD_ABTS_STATUS(sc
) = SNIC_STAT_IO_SUCCESS
;
2426 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2431 complete(rqi
->dr_done
);
2432 else if (rqi
->abts_done
)
2433 complete(rqi
->abts_done
);
2437 * snic_scsi_cleanup: Walks through tag map and releases the reqs
2440 snic_scsi_cleanup(struct snic
*snic
, int ex_tag
)
2442 struct snic_req_info
*rqi
= NULL
;
2443 struct scsi_cmnd
*sc
= NULL
;
2444 spinlock_t
*io_lock
= NULL
;
2445 unsigned long flags
;
2449 SNIC_SCSI_DBG(snic
->shost
, "sc_clean: scsi cleanup.\n");
2451 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
2456 io_lock
= snic_io_lock_tag(snic
, tag
);
2457 spin_lock_irqsave(io_lock
, flags
);
2458 sc
= scsi_host_find_tag(snic
->shost
, tag
);
2460 spin_unlock_irqrestore(io_lock
, flags
);
2465 if (unlikely(snic_tmreq_pending(sc
))) {
2467 * When FW Completes reset w/o sending completions
2468 * for outstanding ios.
2470 snic_cmpl_pending_tmreq(snic
, sc
);
2471 spin_unlock_irqrestore(io_lock
, flags
);
2476 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2478 spin_unlock_irqrestore(io_lock
, flags
);
2483 SNIC_SCSI_DBG(snic
->shost
,
2484 "sc_clean: sc %p, rqi %p, tag %d flags 0x%llx\n",
2485 sc
, rqi
, tag
, CMD_FLAGS(sc
));
2488 CMD_FLAGS(sc
) |= SNIC_SCSI_CLEANUP
;
2489 spin_unlock_irqrestore(io_lock
, flags
);
2490 st_time
= rqi
->start_time
;
2492 SNIC_HOST_INFO(snic
->shost
,
2493 "sc_clean: Releasing rqi %p : flags 0x%llx\n",
2494 rqi
, CMD_FLAGS(sc
));
2496 snic_release_req_buf(snic
, rqi
, sc
);
2499 sc
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
2500 SNIC_HOST_INFO(snic
->shost
,
2501 "sc_clean: DID_TRANSPORT_DISRUPTED for sc %p, Tag %d flags 0x%llx rqi %p duration %u msecs\n",
2502 sc
, sc
->request
->tag
, CMD_FLAGS(sc
), rqi
,
2503 jiffies_to_msecs(jiffies
- st_time
));
2505 /* Update IO stats */
2506 snic_stats_update_io_cmpl(&snic
->s_stats
);
2508 if (sc
->scsi_done
) {
2509 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
,
2510 jiffies_to_msecs(jiffies
- st_time
), 0,
2512 SNIC_TRC_CMD_STATE_FLAGS(sc
));
2517 } /* end of snic_scsi_cleanup */
2520 snic_shutdown_scsi_cleanup(struct snic
*snic
)
2522 SNIC_HOST_INFO(snic
->shost
, "Shutdown time SCSI Cleanup.\n");
2524 snic_scsi_cleanup(snic
, SCSI_NO_TAG
);
2525 } /* end of snic_shutdown_scsi_cleanup */
2528 * snic_internal_abort_io
2529 * called by : snic_tgt_scsi_abort_io
2532 snic_internal_abort_io(struct snic
*snic
, struct scsi_cmnd
*sc
, int tmf
)
2534 struct snic_req_info
*rqi
= NULL
;
2535 spinlock_t
*io_lock
= NULL
;
2536 unsigned long flags
;
2540 io_lock
= snic_io_lock_hash(snic
, sc
);
2541 spin_lock_irqsave(io_lock
, flags
);
2542 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2544 goto skip_internal_abts
;
2546 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
2547 goto skip_internal_abts
;
2549 if ((CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) &&
2550 (!(CMD_FLAGS(sc
) & SNIC_DEV_RST_ISSUED
))) {
2552 SNIC_SCSI_DBG(snic
->shost
,
2553 "internal_abts: dev rst not pending sc 0x%p\n",
2556 goto skip_internal_abts
;
2560 if (!(CMD_FLAGS(sc
) & SNIC_IO_ISSUED
)) {
2561 SNIC_SCSI_DBG(snic
->shost
,
2562 "internal_abts: IO not yet issued sc 0x%p tag 0x%x flags 0x%llx state %d\n",
2563 sc
, snic_cmd_tag(sc
), CMD_FLAGS(sc
), CMD_STATE(sc
));
2565 goto skip_internal_abts
;
2568 sv_state
= CMD_STATE(sc
);
2569 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_PENDING
;
2570 CMD_ABTS_STATUS(sc
) = SNIC_INVALID_CODE
;
2571 CMD_FLAGS(sc
) |= SNIC_IO_INTERNAL_TERM_PENDING
;
2573 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) {
2575 rqi
->tm_tag
= SNIC_TAG_DEV_RST
;
2576 SNIC_SCSI_DBG(snic
->shost
, "internal_abts:dev rst sc %p\n", sc
);
2579 SNIC_SCSI_DBG(snic
->shost
, "internal_abts: Issuing abts tag %x\n",
2581 SNIC_BUG_ON(rqi
->abts_done
);
2582 spin_unlock_irqrestore(io_lock
, flags
);
2584 ret
= snic_queue_abort_req(snic
, rqi
, sc
, tmf
);
2586 SNIC_HOST_ERR(snic
->shost
,
2587 "internal_abts: Tag = %x , Failed w/ err = %d\n",
2588 snic_cmd_tag(sc
), ret
);
2590 spin_lock_irqsave(io_lock
, flags
);
2592 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
2593 CMD_STATE(sc
) = sv_state
;
2595 goto skip_internal_abts
;
2598 spin_lock_irqsave(io_lock
, flags
);
2599 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
)
2600 CMD_FLAGS(sc
) |= SNIC_DEV_RST_TERM_ISSUED
;
2602 CMD_FLAGS(sc
) |= SNIC_IO_INTERNAL_TERM_ISSUED
;
2607 SNIC_BUG_ON(!spin_is_locked(io_lock
));
2608 spin_unlock_irqrestore(io_lock
, flags
);
2611 } /* end of snic_internal_abort_io */
2614 * snic_tgt_scsi_abort_io : called by snic_tgt_del
2617 snic_tgt_scsi_abort_io(struct snic_tgt
*tgt
)
2619 struct snic
*snic
= NULL
;
2620 struct scsi_cmnd
*sc
= NULL
;
2621 struct snic_tgt
*sc_tgt
= NULL
;
2622 spinlock_t
*io_lock
= NULL
;
2623 unsigned long flags
;
2624 int ret
= 0, tag
, abt_cnt
= 0, tmf
= 0;
2629 snic
= shost_priv(snic_tgt_to_shost(tgt
));
2630 SNIC_SCSI_DBG(snic
->shost
, "tgt_abt_io: Cleaning Pending IOs.\n");
2632 if (tgt
->tdata
.typ
== SNIC_TGT_DAS
)
2633 tmf
= SNIC_ITMF_ABTS_TASK
;
2635 tmf
= SNIC_ITMF_ABTS_TASK_TERM
;
2637 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
2638 io_lock
= snic_io_lock_tag(snic
, tag
);
2640 spin_lock_irqsave(io_lock
, flags
);
2641 sc
= scsi_host_find_tag(snic
->shost
, tag
);
2643 spin_unlock_irqrestore(io_lock
, flags
);
2648 sc_tgt
= starget_to_tgt(scsi_target(sc
->device
));
2649 if (sc_tgt
!= tgt
) {
2650 spin_unlock_irqrestore(io_lock
, flags
);
2654 spin_unlock_irqrestore(io_lock
, flags
);
2656 ret
= snic_internal_abort_io(snic
, sc
, tmf
);
2658 SNIC_HOST_ERR(snic
->shost
,
2659 "tgt_abt_io: Tag %x, Failed w err = %d\n",
2669 SNIC_SCSI_DBG(snic
->shost
, "tgt_abt_io: abt_cnt = %d\n", abt_cnt
);
2672 } /* end of snic_tgt_scsi_abort_io */