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 memset(scsi_cmd_priv(sc
), 0, sizeof(struct snic_internal_io_state
));
364 ret
= snic_issue_scsi_req(snic
, tgt
, sc
);
366 SNIC_HOST_ERR(shost
, "Failed to Q, Scsi Req w/ err %d.\n", ret
);
367 ret
= SCSI_MLQUEUE_HOST_BUSY
;
370 atomic_dec(&snic
->ios_inflight
);
373 } /* end of snic_queuecommand */
376 * snic_process_abts_pending_state:
377 * caller should hold IO lock
380 snic_proc_tmreq_pending_state(struct snic
*snic
,
381 struct scsi_cmnd
*sc
,
384 int state
= CMD_STATE(sc
);
386 if (state
== SNIC_IOREQ_ABTS_PENDING
)
387 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_PENDING
;
388 else if (state
== SNIC_IOREQ_LR_PENDING
)
389 CMD_FLAGS(sc
) |= SNIC_DEV_RST_PENDING
;
393 switch (cmpl_status
) {
394 case SNIC_STAT_IO_SUCCESS
:
395 CMD_FLAGS(sc
) |= SNIC_IO_DONE
;
398 case SNIC_STAT_ABORTED
:
399 CMD_FLAGS(sc
) |= SNIC_IO_ABORTED
;
408 * snic_process_io_failed_state:
409 * Processes IO's error states
412 snic_process_io_failed_state(struct snic
*snic
,
413 struct snic_icmnd_cmpl
*icmnd_cmpl
,
414 struct scsi_cmnd
*sc
,
420 case SNIC_STAT_TIMEOUT
: /* Req was timedout */
421 atomic64_inc(&snic
->s_stats
.misc
.io_tmo
);
425 case SNIC_STAT_ABORTED
: /* Req was aborted */
426 atomic64_inc(&snic
->s_stats
.misc
.io_aborted
);
430 case SNIC_STAT_DATA_CNT_MISMATCH
:/* Recv/Sent more/less data than exp */
431 atomic64_inc(&snic
->s_stats
.misc
.data_cnt_mismat
);
432 scsi_set_resid(sc
, le32_to_cpu(icmnd_cmpl
->resid
));
436 case SNIC_STAT_OUT_OF_RES
: /* Out of resources to complete request */
437 atomic64_inc(&snic
->s_stats
.fw
.out_of_res
);
441 case SNIC_STAT_IO_NOT_FOUND
: /* Requested I/O was not found */
442 atomic64_inc(&snic
->s_stats
.io
.io_not_found
);
446 case SNIC_STAT_SGL_INVALID
: /* Req was aborted to due to sgl error*/
447 atomic64_inc(&snic
->s_stats
.misc
.sgl_inval
);
451 case SNIC_STAT_FW_ERR
: /* Req terminated due to FW Error */
452 atomic64_inc(&snic
->s_stats
.fw
.io_errs
);
456 case SNIC_STAT_SCSI_ERR
: /* FW hits SCSI Error */
457 atomic64_inc(&snic
->s_stats
.fw
.scsi_errs
);
460 case SNIC_STAT_NOT_READY
: /* XPT yet to initialize */
461 case SNIC_STAT_DEV_OFFLINE
: /* Device offline */
462 res
= DID_NO_CONNECT
;
465 case SNIC_STAT_INVALID_HDR
: /* Hdr contains invalid data */
466 case SNIC_STAT_INVALID_PARM
: /* Some param in req is invalid */
467 case SNIC_STAT_REQ_NOT_SUP
: /* Req type is not supported */
468 case SNIC_STAT_CMND_REJECT
: /* Req rejected */
469 case SNIC_STAT_FATAL_ERROR
: /* XPT Error */
471 SNIC_SCSI_DBG(snic
->shost
,
472 "Invalid Hdr/Param or Req Not Supported or Cmnd Rejected or Device Offline. or Unknown\n");
477 SNIC_HOST_ERR(snic
->shost
, "fw returns failed status %s flags 0x%llx\n",
478 snic_io_status_to_str(cmpl_stat
), CMD_FLAGS(sc
));
481 sc
->result
= (res
<< 16) | icmnd_cmpl
->scsi_status
;
482 } /* end of snic_process_io_failed_state */
485 * snic_tmreq_pending : is task management in progress.
488 snic_tmreq_pending(struct scsi_cmnd
*sc
)
490 int state
= CMD_STATE(sc
);
492 return ((state
== SNIC_IOREQ_ABTS_PENDING
) ||
493 (state
== SNIC_IOREQ_LR_PENDING
));
497 * snic_process_icmnd_cmpl_status:
498 * Caller should hold io_lock
501 snic_process_icmnd_cmpl_status(struct snic
*snic
,
502 struct snic_icmnd_cmpl
*icmnd_cmpl
,
504 struct scsi_cmnd
*sc
)
506 u8 scsi_stat
= icmnd_cmpl
->scsi_status
;
510 /* Mark the IO as complete */
511 CMD_STATE(sc
) = SNIC_IOREQ_COMPLETE
;
513 if (likely(cmpl_stat
== SNIC_STAT_IO_SUCCESS
)) {
514 sc
->result
= (DID_OK
<< 16) | scsi_stat
;
516 xfer_len
= scsi_bufflen(sc
);
518 /* Update SCSI Cmd with resid value */
519 scsi_set_resid(sc
, le32_to_cpu(icmnd_cmpl
->resid
));
521 if (icmnd_cmpl
->flags
& SNIC_ICMND_CMPL_UNDR_RUN
) {
522 xfer_len
-= le32_to_cpu(icmnd_cmpl
->resid
);
523 atomic64_inc(&snic
->s_stats
.misc
.io_under_run
);
526 if (icmnd_cmpl
->scsi_status
== SAM_STAT_TASK_SET_FULL
)
527 atomic64_inc(&snic
->s_stats
.misc
.qfull
);
531 snic_process_io_failed_state(snic
, icmnd_cmpl
, sc
, cmpl_stat
);
532 atomic64_inc(&snic
->s_stats
.io
.fail
);
533 SNIC_HOST_ERR(snic
->shost
,
534 "icmnd_cmpl: IO Failed : Hdr Status %s flags 0x%llx\n",
535 snic_io_status_to_str(cmpl_stat
), CMD_FLAGS(sc
));
540 } /* end of snic_process_icmnd_cmpl_status */
544 * snic_icmnd_cmpl_handler
545 * Routine to handle icmnd completions
548 snic_icmnd_cmpl_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
553 struct scsi_cmnd
*sc
= NULL
;
554 struct snic_icmnd_cmpl
*icmnd_cmpl
= NULL
;
555 struct snic_host_req
*req
= NULL
;
556 struct snic_req_info
*rqi
= NULL
;
557 unsigned long flags
, start_time
;
561 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
562 icmnd_cmpl
= &fwreq
->u
.icmnd_cmpl
;
563 sc_stat
= icmnd_cmpl
->scsi_status
;
565 SNIC_SCSI_DBG(snic
->shost
,
566 "Icmnd_cmpl: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x,i ctx = %lx\n",
567 typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
569 if (cmnd_id
>= snic
->max_tag_id
) {
570 SNIC_HOST_ERR(snic
->shost
,
571 "Icmnd_cmpl:Tag Error:Out of Range Tag %d, hdr status = %s\n",
572 cmnd_id
, snic_io_status_to_str(hdr_stat
));
576 sc
= scsi_host_find_tag(snic
->shost
, cmnd_id
);
580 atomic64_inc(&snic
->s_stats
.io
.sc_null
);
581 SNIC_HOST_ERR(snic
->shost
,
582 "Icmnd_cmpl: Scsi Cmnd Not found, sc = NULL Hdr Status = %s tag = 0x%x fwreq = 0x%p\n",
583 snic_io_status_to_str(hdr_stat
),
587 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, 0,
588 ((u64
)hdr_stat
<< 16 |
589 (u64
)sc_stat
<< 8 | (u64
)icmnd_cmpl
->flags
),
590 (ulong
) fwreq
, le32_to_cpu(icmnd_cmpl
->resid
), ctx
);
595 io_lock
= snic_io_lock_hash(snic
, sc
);
597 spin_lock_irqsave(io_lock
, flags
);
598 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
599 SNIC_SCSI_DBG(snic
->shost
,
600 "Icmnd_cmpl:lun %lld sc %p cmd %xtag %d flags 0x%llx rqi %p\n",
601 sc
->device
->lun
, sc
, sc
->cmnd
[0], snic_cmd_tag(sc
),
604 if (CMD_FLAGS(sc
) & SNIC_HOST_RESET_CMD_TERM
) {
605 spin_unlock_irqrestore(io_lock
, flags
);
610 SNIC_BUG_ON(rqi
!= (struct snic_req_info
*)ctx
);
613 atomic64_inc(&snic
->s_stats
.io
.req_null
);
614 CMD_FLAGS(sc
) |= SNIC_IO_REQ_NULL
;
615 spin_unlock_irqrestore(io_lock
, flags
);
617 SNIC_HOST_ERR(snic
->shost
,
618 "Icmnd_cmpl:Host Req Not Found(null), Hdr Status %s, Tag 0x%x, sc 0x%p flags 0x%llx\n",
619 snic_io_status_to_str(hdr_stat
),
620 cmnd_id
, sc
, CMD_FLAGS(sc
));
624 rqi
= (struct snic_req_info
*) ctx
;
625 start_time
= rqi
->start_time
;
627 /* firmware completed the io */
631 * if SCSI-ML has already issued abort on this command,
632 * ignore completion of the IO. The abts path will clean it up
634 if (unlikely(snic_tmreq_pending(sc
))) {
635 snic_proc_tmreq_pending_state(snic
, sc
, hdr_stat
);
636 spin_unlock_irqrestore(io_lock
, flags
);
638 snic_stats_update_io_cmpl(&snic
->s_stats
);
640 /* Expected value is SNIC_STAT_ABORTED */
641 if (likely(hdr_stat
== SNIC_STAT_ABORTED
))
644 SNIC_SCSI_DBG(snic
->shost
,
645 "icmnd_cmpl:TM Req Pending(%s), Hdr Status %s sc 0x%p scsi status %x resid %d flags 0x%llx\n",
646 snic_ioreq_state_to_str(CMD_STATE(sc
)),
647 snic_io_status_to_str(hdr_stat
),
648 sc
, sc_stat
, le32_to_cpu(icmnd_cmpl
->resid
),
651 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
652 jiffies_to_msecs(jiffies
- start_time
), (ulong
) fwreq
,
653 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
658 if (snic_process_icmnd_cmpl_status(snic
, icmnd_cmpl
, hdr_stat
, sc
)) {
659 scsi_print_command(sc
);
660 SNIC_HOST_ERR(snic
->shost
,
661 "icmnd_cmpl:IO Failed, sc 0x%p Tag %d Cmd %x Hdr Status %s flags 0x%llx\n",
662 sc
, sc
->cmnd
[0], cmnd_id
,
663 snic_io_status_to_str(hdr_stat
), CMD_FLAGS(sc
));
666 /* Break link with the SCSI Command */
668 CMD_FLAGS(sc
) |= SNIC_IO_DONE
;
670 spin_unlock_irqrestore(io_lock
, flags
);
672 /* For now, consider only successful IO. */
673 snic_calc_io_process_time(snic
, rqi
);
675 snic_release_req_buf(snic
, rqi
, sc
);
677 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
678 jiffies_to_msecs(jiffies
- start_time
), (ulong
) fwreq
,
679 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
685 snic_stats_update_io_cmpl(&snic
->s_stats
);
686 } /* end of snic_icmnd_cmpl_handler */
689 snic_proc_dr_cmpl_locked(struct snic
*snic
,
690 struct snic_fw_req
*fwreq
,
693 struct scsi_cmnd
*sc
)
695 struct snic_req_info
*rqi
= (struct snic_req_info
*) CMD_SP(sc
);
696 u32 start_time
= rqi
->start_time
;
698 CMD_LR_STATUS(sc
) = cmpl_stat
;
700 SNIC_SCSI_DBG(snic
->shost
, "itmf_cmpl: Cmd State = %s\n",
701 snic_ioreq_state_to_str(CMD_STATE(sc
)));
703 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
) {
704 CMD_FLAGS(sc
) |= SNIC_DEV_RST_ABTS_PENDING
;
706 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
707 jiffies_to_msecs(jiffies
- start_time
),
708 (ulong
) fwreq
, 0, SNIC_TRC_CMD_STATE_FLAGS(sc
));
710 SNIC_SCSI_DBG(snic
->shost
,
711 "itmf_cmpl: Terminate Pending Dev Reset Cmpl Recvd.id %x, status %s flags 0x%llx\n",
712 (int)(cmnd_id
& SNIC_TAG_MASK
),
713 snic_io_status_to_str(cmpl_stat
),
720 if (CMD_FLAGS(sc
) & SNIC_DEV_RST_TIMEDOUT
) {
721 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
722 jiffies_to_msecs(jiffies
- start_time
),
723 (ulong
) fwreq
, 0, SNIC_TRC_CMD_STATE_FLAGS(sc
));
725 SNIC_SCSI_DBG(snic
->shost
,
726 "itmf_cmpl:Dev Reset Completion Received after timeout. id %d cmpl status %s flags 0x%llx\n",
727 (int)(cmnd_id
& SNIC_TAG_MASK
),
728 snic_io_status_to_str(cmpl_stat
),
734 CMD_STATE(sc
) = SNIC_IOREQ_LR_COMPLETE
;
735 CMD_FLAGS(sc
) |= SNIC_DEV_RST_DONE
;
737 SNIC_SCSI_DBG(snic
->shost
,
738 "itmf_cmpl:Dev Reset Cmpl Recvd id %d cmpl status %s flags 0x%llx\n",
739 (int)(cmnd_id
& SNIC_TAG_MASK
),
740 snic_io_status_to_str(cmpl_stat
),
744 complete(rqi
->dr_done
);
745 } /* end of snic_proc_dr_cmpl_locked */
748 * snic_update_abort_stats : Updates abort stats based on completion status.
751 snic_update_abort_stats(struct snic
*snic
, u8 cmpl_stat
)
753 struct snic_abort_stats
*abt_stats
= &snic
->s_stats
.abts
;
755 SNIC_SCSI_DBG(snic
->shost
, "Updating Abort stats.\n");
758 case SNIC_STAT_IO_SUCCESS
:
761 case SNIC_STAT_TIMEOUT
:
762 atomic64_inc(&abt_stats
->fw_tmo
);
765 case SNIC_STAT_IO_NOT_FOUND
:
766 atomic64_inc(&abt_stats
->io_not_found
);
770 atomic64_inc(&abt_stats
->fail
);
776 snic_process_itmf_cmpl(struct snic
*snic
,
777 struct snic_fw_req
*fwreq
,
780 struct scsi_cmnd
*sc
)
782 struct snic_req_info
*rqi
= NULL
;
784 spinlock_t
*io_lock
= NULL
;
789 io_lock
= snic_io_lock_hash(snic
, sc
);
790 spin_lock_irqsave(io_lock
, flags
);
791 if (CMD_FLAGS(sc
) & SNIC_HOST_RESET_CMD_TERM
) {
792 spin_unlock_irqrestore(io_lock
, flags
);
796 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
800 atomic64_inc(&snic
->s_stats
.io
.req_null
);
801 spin_unlock_irqrestore(io_lock
, flags
);
802 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
803 SNIC_HOST_ERR(snic
->shost
,
804 "itmf_cmpl: rqi is null,Hdr stat = %s Tag = 0x%x sc = 0x%p flags 0x%llx\n",
805 snic_io_status_to_str(cmpl_stat
), cmnd_id
, sc
,
811 /* Extract task management flags */
812 tm_tags
= cmnd_id
& ~(SNIC_TAG_MASK
);
814 start_time
= rqi
->start_time
;
815 cmnd_id
&= (SNIC_TAG_MASK
);
819 /* Abort only issued on cmd */
820 snic_update_abort_stats(snic
, cmpl_stat
);
822 if (CMD_STATE(sc
) != SNIC_IOREQ_ABTS_PENDING
) {
823 /* This is a late completion. Ignore it. */
825 spin_unlock_irqrestore(io_lock
, flags
);
829 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_COMPLETE
;
830 CMD_ABTS_STATUS(sc
) = cmpl_stat
;
831 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_DONE
;
833 SNIC_SCSI_DBG(snic
->shost
,
834 "itmf_cmpl:Abort Cmpl Recvd.Tag 0x%x Status %s flags 0x%llx\n",
836 snic_io_status_to_str(cmpl_stat
),
840 * If scsi_eh thread is blocked waiting for abts complete,
841 * signal completion to it. IO will be cleaned in the thread,
842 * else clean it in this context.
844 if (rqi
->abts_done
) {
845 complete(rqi
->abts_done
);
846 spin_unlock_irqrestore(io_lock
, flags
);
848 break; /* jump out */
852 sc
->result
= (DID_ERROR
<< 16);
853 SNIC_SCSI_DBG(snic
->shost
,
854 "itmf_cmpl: Completing IO. sc %p flags 0x%llx\n",
857 spin_unlock_irqrestore(io_lock
, flags
);
859 snic_release_req_buf(snic
, rqi
, sc
);
862 SNIC_TRC(snic
->shost
->host_no
, cmnd_id
, (ulong
) sc
,
863 jiffies_to_msecs(jiffies
- start_time
),
864 (ulong
) fwreq
, SNIC_TRC_CMD(sc
),
865 SNIC_TRC_CMD_STATE_FLAGS(sc
));
872 case SNIC_TAG_DEV_RST
:
873 case SNIC_TAG_DEV_RST
| SNIC_TAG_IOCTL_DEV_RST
:
874 snic_proc_dr_cmpl_locked(snic
, fwreq
, cmpl_stat
, cmnd_id
, sc
);
875 spin_unlock_irqrestore(io_lock
, flags
);
880 case SNIC_TAG_ABORT
| SNIC_TAG_DEV_RST
:
881 /* Abort and terminate completion of device reset req */
883 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_COMPLETE
;
884 CMD_ABTS_STATUS(sc
) = cmpl_stat
;
885 CMD_FLAGS(sc
) |= SNIC_DEV_RST_DONE
;
887 SNIC_SCSI_DBG(snic
->shost
,
888 "itmf_cmpl:dev reset abts cmpl recvd. id %d status %s flags 0x%llx\n",
889 cmnd_id
, snic_io_status_to_str(cmpl_stat
),
893 complete(rqi
->abts_done
);
895 spin_unlock_irqrestore(io_lock
, flags
);
900 spin_unlock_irqrestore(io_lock
, flags
);
901 SNIC_HOST_ERR(snic
->shost
,
902 "itmf_cmpl: Unknown TM tag bit 0x%x\n", tm_tags
);
904 SNIC_HOST_ERR(snic
->shost
,
905 "itmf_cmpl:Unexpected itmf io stat %s Tag = 0x%x flags 0x%llx\n",
906 snic_ioreq_state_to_str(CMD_STATE(sc
)),
916 } /* end of snic_process_itmf_cmpl_status */
919 * snic_itmf_cmpl_handler.
920 * Routine to handle itmf completions.
923 snic_itmf_cmpl_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
925 struct scsi_cmnd
*sc
= NULL
;
926 struct snic_req_info
*rqi
= NULL
;
927 struct snic_itmf_cmpl
*itmf_cmpl
= NULL
;
934 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
935 SNIC_SCSI_DBG(snic
->shost
,
936 "Itmf_cmpl: %s: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x,ctx = %lx\n",
937 __func__
, typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
939 itmf_cmpl
= &fwreq
->u
.itmf_cmpl
;
940 SNIC_SCSI_DBG(snic
->shost
,
941 "Itmf_cmpl: nterm %u , flags 0x%x\n",
942 le32_to_cpu(itmf_cmpl
->nterminated
), itmf_cmpl
->flags
);
944 /* spl case, dev reset issued through ioctl */
945 if (cmnd_id
& SNIC_TAG_IOCTL_DEV_RST
) {
946 rqi
= (struct snic_req_info
*) ctx
;
952 if ((cmnd_id
& SNIC_TAG_MASK
) >= snic
->max_tag_id
) {
953 SNIC_HOST_ERR(snic
->shost
,
954 "Itmf_cmpl: Tag 0x%x out of Range,HdrStat %s\n",
955 cmnd_id
, snic_io_status_to_str(hdr_stat
));
961 sc
= scsi_host_find_tag(snic
->shost
, cmnd_id
& SNIC_TAG_MASK
);
966 atomic64_inc(&snic
->s_stats
.io
.sc_null
);
967 SNIC_HOST_ERR(snic
->shost
,
968 "Itmf_cmpl: sc is NULL - Hdr Stat %s Tag 0x%x\n",
969 snic_io_status_to_str(hdr_stat
), cmnd_id
);
974 snic_process_itmf_cmpl(snic
, fwreq
, cmnd_id
, hdr_stat
, sc
);
975 } /* end of snic_itmf_cmpl_handler */
980 snic_hba_reset_scsi_cleanup(struct snic
*snic
, struct scsi_cmnd
*sc
)
982 struct snic_stats
*st
= &snic
->s_stats
;
983 long act_ios
= 0, act_fwreqs
= 0;
985 SNIC_SCSI_DBG(snic
->shost
, "HBA Reset scsi cleanup.\n");
986 snic_scsi_cleanup(snic
, snic_cmd_tag(sc
));
988 /* Update stats on pending IOs */
989 act_ios
= atomic64_read(&st
->io
.active
);
990 atomic64_add(act_ios
, &st
->io
.compl);
991 atomic64_sub(act_ios
, &st
->io
.active
);
993 act_fwreqs
= atomic64_read(&st
->fw
.actv_reqs
);
994 atomic64_sub(act_fwreqs
, &st
->fw
.actv_reqs
);
998 * snic_hba_reset_cmpl_handler :
1001 * 1. Cleanup all the scsi cmds, release all snic specific cmds
1002 * 2. Issue Report Targets in case of SAN targets
1005 snic_hba_reset_cmpl_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
1012 struct scsi_cmnd
*sc
= NULL
;
1013 struct snic_req_info
*rqi
= NULL
;
1014 spinlock_t
*io_lock
= NULL
;
1015 unsigned long flags
, gflags
;
1018 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
1019 SNIC_HOST_INFO(snic
->shost
,
1020 "reset_cmpl:Tag %d ctx %lx cmpl status %s HBA Reset Completion received.\n",
1021 cmnd_id
, ctx
, snic_io_status_to_str(hdr_stat
));
1023 SNIC_SCSI_DBG(snic
->shost
,
1024 "reset_cmpl: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x, ctx = %lx\n",
1025 typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
1027 /* spl case, host reset issued through ioctl */
1028 if (cmnd_id
== SCSI_NO_TAG
) {
1029 rqi
= (struct snic_req_info
*) ctx
;
1030 SNIC_HOST_INFO(snic
->shost
,
1031 "reset_cmpl:Tag %d ctx %lx cmpl stat %s\n",
1032 cmnd_id
, ctx
, snic_io_status_to_str(hdr_stat
));
1038 if (cmnd_id
>= snic
->max_tag_id
) {
1039 SNIC_HOST_ERR(snic
->shost
,
1040 "reset_cmpl: Tag 0x%x out of Range,HdrStat %s\n",
1041 cmnd_id
, snic_io_status_to_str(hdr_stat
));
1047 sc
= scsi_host_find_tag(snic
->shost
, cmnd_id
);
1050 atomic64_inc(&snic
->s_stats
.io
.sc_null
);
1051 SNIC_HOST_ERR(snic
->shost
,
1052 "reset_cmpl: sc is NULL - Hdr Stat %s Tag 0x%x\n",
1053 snic_io_status_to_str(hdr_stat
), cmnd_id
);
1059 SNIC_HOST_INFO(snic
->shost
,
1060 "reset_cmpl: sc %p rqi %p Tag %d flags 0x%llx\n",
1061 sc
, rqi
, cmnd_id
, CMD_FLAGS(sc
));
1063 io_lock
= snic_io_lock_hash(snic
, sc
);
1064 spin_lock_irqsave(io_lock
, flags
);
1066 if (!snic
->remove_wait
) {
1067 spin_unlock_irqrestore(io_lock
, flags
);
1068 SNIC_HOST_ERR(snic
->shost
,
1069 "reset_cmpl:host reset completed after timout\n");
1075 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1079 atomic64_inc(&snic
->s_stats
.io
.req_null
);
1080 spin_unlock_irqrestore(io_lock
, flags
);
1081 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
1082 SNIC_HOST_ERR(snic
->shost
,
1083 "reset_cmpl: rqi is null,Hdr stat %s Tag 0x%x sc 0x%p flags 0x%llx\n",
1084 snic_io_status_to_str(hdr_stat
), cmnd_id
, sc
,
1092 spin_unlock_irqrestore(io_lock
, flags
);
1095 snic_hba_reset_scsi_cleanup(snic
, sc
);
1097 SNIC_BUG_ON(snic_get_state(snic
) != SNIC_OFFLINE
&&
1098 snic_get_state(snic
) != SNIC_FWRESET
);
1100 /* Careful locking between snic_lock and io lock */
1101 spin_lock_irqsave(io_lock
, flags
);
1102 spin_lock_irqsave(&snic
->snic_lock
, gflags
);
1103 if (snic_get_state(snic
) == SNIC_FWRESET
)
1104 snic_set_state(snic
, SNIC_ONLINE
);
1105 spin_unlock_irqrestore(&snic
->snic_lock
, gflags
);
1107 if (snic
->remove_wait
)
1108 complete(snic
->remove_wait
);
1110 spin_unlock_irqrestore(io_lock
, flags
);
1111 atomic64_inc(&snic
->s_stats
.reset
.hba_reset_cmpl
);
1114 /* Rediscovery is for SAN */
1115 if (snic
->config
.xpt_type
== SNIC_DAS
)
1118 SNIC_SCSI_DBG(snic
->shost
, "reset_cmpl: Queuing discovery work.\n");
1119 queue_work(snic_glob
->event_q
, &snic
->disc_work
);
1125 snic_msg_ack_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
1127 SNIC_HOST_INFO(snic
->shost
, "Message Ack Received.\n");
1129 SNIC_ASSERT_NOT_IMPL(1);
1133 snic_aen_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
1138 struct snic_async_evnotify
*aen
= &fwreq
->u
.async_ev
;
1141 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
1142 SNIC_SCSI_DBG(snic
->shost
,
1143 "aen: type = %x, hdr_stat = %x, cmnd_id = %x, hid = %x, ctx = %lx\n",
1144 typ
, hdr_stat
, cmnd_id
, hid
, ctx
);
1146 event_id
= le32_to_cpu(aen
->ev_id
);
1149 case SNIC_EV_TGT_OFFLINE
:
1150 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_OFFLINE Event Recvd.\n");
1153 case SNIC_EV_TGT_ONLINE
:
1154 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_ONLINE Event Recvd.\n");
1157 case SNIC_EV_LUN_OFFLINE
:
1158 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_OFFLINE Event Recvd.\n");
1161 case SNIC_EV_LUN_ONLINE
:
1162 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_ONLINE Event Recvd.\n");
1165 case SNIC_EV_CONF_CHG
:
1166 SNIC_HOST_INFO(snic
->shost
, "aen:Config Change Event Recvd.\n");
1169 case SNIC_EV_TGT_ADDED
:
1170 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_ADD Event Recvd.\n");
1173 case SNIC_EV_TGT_DELTD
:
1174 SNIC_HOST_INFO(snic
->shost
, "aen:TGT_DEL Event Recvd.\n");
1177 case SNIC_EV_LUN_ADDED
:
1178 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_ADD Event Recvd.\n");
1181 case SNIC_EV_LUN_DELTD
:
1182 SNIC_HOST_INFO(snic
->shost
, "aen:LUN_DEL Event Recvd.\n");
1185 case SNIC_EV_DISC_CMPL
:
1186 SNIC_HOST_INFO(snic
->shost
, "aen:DISC_CMPL Event Recvd.\n");
1190 SNIC_HOST_INFO(snic
->shost
, "aen:Unknown Event Recvd.\n");
1195 SNIC_ASSERT_NOT_IMPL(1);
1196 } /* end of snic_aen_handler */
1199 * snic_io_cmpl_handler
1200 * Routine to process CQ entries(IO Completions) posted by fw.
1203 snic_io_cmpl_handler(struct vnic_dev
*vdev
,
1204 unsigned int cq_idx
,
1205 struct snic_fw_req
*fwreq
)
1207 struct snic
*snic
= svnic_dev_priv(vdev
);
1208 u64 start
= jiffies
, cmpl_time
;
1210 snic_print_desc(__func__
, (char *)fwreq
, sizeof(*fwreq
));
1212 /* Update FW Stats */
1213 if ((fwreq
->hdr
.type
>= SNIC_RSP_REPORT_TGTS_CMPL
) &&
1214 (fwreq
->hdr
.type
<= SNIC_RSP_BOOT_LUNS_CMPL
))
1215 atomic64_dec(&snic
->s_stats
.fw
.actv_reqs
);
1217 SNIC_BUG_ON((fwreq
->hdr
.type
> SNIC_RSP_BOOT_LUNS_CMPL
) &&
1218 (fwreq
->hdr
.type
< SNIC_MSG_ASYNC_EVNOTIFY
));
1220 /* Check for snic subsys errors */
1221 switch (fwreq
->hdr
.status
) {
1222 case SNIC_STAT_NOT_READY
: /* XPT yet to initialize */
1223 SNIC_HOST_ERR(snic
->shost
,
1224 "sNIC SubSystem is NOT Ready.\n");
1227 case SNIC_STAT_FATAL_ERROR
: /* XPT Error */
1228 SNIC_HOST_ERR(snic
->shost
,
1229 "sNIC SubSystem in Unrecoverable State.\n");
1233 switch (fwreq
->hdr
.type
) {
1234 case SNIC_RSP_EXCH_VER_CMPL
:
1235 snic_io_exch_ver_cmpl_handler(snic
, fwreq
);
1238 case SNIC_RSP_REPORT_TGTS_CMPL
:
1239 snic_report_tgt_cmpl_handler(snic
, fwreq
);
1242 case SNIC_RSP_ICMND_CMPL
:
1243 snic_icmnd_cmpl_handler(snic
, fwreq
);
1246 case SNIC_RSP_ITMF_CMPL
:
1247 snic_itmf_cmpl_handler(snic
, fwreq
);
1250 case SNIC_RSP_HBA_RESET_CMPL
:
1251 snic_hba_reset_cmpl_handler(snic
, fwreq
);
1255 snic_msg_ack_handler(snic
, fwreq
);
1258 case SNIC_MSG_ASYNC_EVNOTIFY
:
1259 snic_aen_handler(snic
, fwreq
);
1264 SNIC_SCSI_DBG(snic
->shost
,
1265 "Unknown Firmwqre completion request type %d\n",
1271 cmpl_time
= jiffies
- start
;
1272 if (cmpl_time
> atomic64_read(&snic
->s_stats
.io
.max_cmpl_time
))
1273 atomic64_set(&snic
->s_stats
.io
.max_cmpl_time
, cmpl_time
);
1276 } /* end of snic_io_cmpl_handler */
1279 * snic_fwcq_cmpl_handler
1280 * Routine to process fwCQ
1281 * This CQ is independent, and not associated with wq/rq/wq_copy queues
1284 snic_fwcq_cmpl_handler(struct snic
*snic
, int io_cmpl_work
)
1286 unsigned int num_ent
= 0; /* number cq entries processed */
1287 unsigned int cq_idx
;
1288 unsigned int nent_per_cq
;
1289 struct snic_misc_stats
*misc_stats
= &snic
->s_stats
.misc
;
1291 for (cq_idx
= snic
->wq_count
; cq_idx
< snic
->cq_count
; cq_idx
++) {
1292 nent_per_cq
= vnic_cq_fw_service(&snic
->cq
[cq_idx
],
1293 snic_io_cmpl_handler
,
1295 num_ent
+= nent_per_cq
;
1297 if (nent_per_cq
> atomic64_read(&misc_stats
->max_cq_ents
))
1298 atomic64_set(&misc_stats
->max_cq_ents
, nent_per_cq
);
1302 } /* end of snic_fwcq_cmpl_handler */
1305 * snic_queue_itmf_req: Common API to queue Task Management requests.
1306 * Use rqi->tm_tag for passing special tags.
1307 * @req_id : aborted request's tag, -1 for lun reset.
1310 snic_queue_itmf_req(struct snic
*snic
,
1311 struct snic_host_req
*tmreq
,
1312 struct scsi_cmnd
*sc
,
1316 struct snic_req_info
*rqi
= req_to_rqi(tmreq
);
1317 struct scsi_lun lun
;
1318 int tm_tag
= snic_cmd_tag(sc
) | rqi
->tm_tag
;
1322 SNIC_BUG_ON(!rqi
->tm_tag
);
1324 /* fill in lun info */
1325 int_to_scsilun(sc
->device
->lun
, &lun
);
1327 /* Initialize snic_host_req: itmf */
1328 snic_itmf_init(tmreq
,
1333 req_id
, /* Command to be aborted. */
1339 * In case of multiple aborts on same cmd,
1340 * use try_wait_for_completion and completion_done() to check
1341 * whether it queues aborts even after completion of abort issued
1342 * prior.SNIC_BUG_ON(completion_done(&rqi->done));
1345 ret
= snic_queue_wq_desc(snic
, tmreq
, sizeof(*tmreq
));
1347 SNIC_HOST_ERR(snic
->shost
,
1348 "qitmf:Queuing ITMF(%d) Req sc %p, rqi %p, req_id %d tag %d Failed, ret = %d\n",
1349 tmf
, sc
, rqi
, req_id
, snic_cmd_tag(sc
), ret
);
1351 SNIC_SCSI_DBG(snic
->shost
,
1352 "qitmf:Queuing ITMF(%d) Req sc %p, rqi %p, req_id %d, tag %d (req_id)- Success.",
1353 tmf
, sc
, rqi
, req_id
, snic_cmd_tag(sc
));
1356 } /* end of snic_queue_itmf_req */
1359 snic_issue_tm_req(struct snic
*snic
,
1360 struct snic_req_info
*rqi
,
1361 struct scsi_cmnd
*sc
,
1364 struct snic_host_req
*tmreq
= NULL
;
1365 int req_id
= 0, tag
= snic_cmd_tag(sc
);
1368 if (snic_get_state(snic
) == SNIC_FWRESET
)
1371 atomic_inc(&snic
->ios_inflight
);
1373 SNIC_SCSI_DBG(snic
->shost
,
1374 "issu_tmreq: Task mgmt req %d. rqi %p w/ tag %x\n",
1378 if (tmf
== SNIC_ITMF_LUN_RESET
) {
1379 tmreq
= snic_dr_req_init(snic
, rqi
);
1380 req_id
= SCSI_NO_TAG
;
1382 tmreq
= snic_abort_req_init(snic
, rqi
);
1392 ret
= snic_queue_itmf_req(snic
, tmreq
, sc
, tmf
, req_id
);
1400 SNIC_HOST_ERR(snic
->shost
,
1401 "issu_tmreq: Queing ITMF(%d) Req, sc %p rqi %p req_id %d tag %x fails err = %d\n",
1402 tmf
, sc
, rqi
, req_id
, tag
, ret
);
1404 SNIC_SCSI_DBG(snic
->shost
,
1405 "issu_tmreq: Queuing ITMF(%d) Req, sc %p, rqi %p, req_id %d tag %x - Success.\n",
1406 tmf
, sc
, rqi
, req_id
, tag
);
1409 atomic_dec(&snic
->ios_inflight
);
1415 * snic_queue_abort_req : Queues abort req to WQ
1418 snic_queue_abort_req(struct snic
*snic
,
1419 struct snic_req_info
*rqi
,
1420 struct scsi_cmnd
*sc
,
1423 SNIC_SCSI_DBG(snic
->shost
, "q_abtreq: sc %p, rqi %p, tag %x, tmf %d\n",
1424 sc
, rqi
, snic_cmd_tag(sc
), tmf
);
1426 /* Add special tag for abort */
1427 rqi
->tm_tag
|= SNIC_TAG_ABORT
;
1429 return snic_issue_tm_req(snic
, rqi
, sc
, tmf
);
1433 * snic_abort_finish : called by snic_abort_cmd on queuing abort successfully.
1436 snic_abort_finish(struct snic
*snic
, struct scsi_cmnd
*sc
)
1438 struct snic_req_info
*rqi
= NULL
;
1439 spinlock_t
*io_lock
= NULL
;
1440 unsigned long flags
;
1441 int ret
= 0, tag
= snic_cmd_tag(sc
);
1443 io_lock
= snic_io_lock_hash(snic
, sc
);
1444 spin_lock_irqsave(io_lock
, flags
);
1445 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1447 atomic64_inc(&snic
->s_stats
.io
.req_null
);
1448 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
1450 SNIC_SCSI_DBG(snic
->shost
,
1451 "abt_fini:req info is null tag 0x%x, sc 0x%p flags 0x%llx\n",
1452 tag
, sc
, CMD_FLAGS(sc
));
1458 rqi
->abts_done
= NULL
;
1462 /* Check the abort status. */
1463 switch (CMD_ABTS_STATUS(sc
)) {
1464 case SNIC_INVALID_CODE
:
1465 /* Firmware didn't complete abort req, timedout */
1466 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TIMEDOUT
;
1467 atomic64_inc(&snic
->s_stats
.abts
.drv_tmo
);
1468 SNIC_SCSI_DBG(snic
->shost
,
1469 "abt_fini:sc %p Tag %x Driver Timeout.flags 0x%llx\n",
1470 sc
, snic_cmd_tag(sc
), CMD_FLAGS(sc
));
1471 /* do not release snic request in timedout case */
1476 case SNIC_STAT_IO_SUCCESS
:
1477 case SNIC_STAT_IO_NOT_FOUND
:
1480 * If abort path doesn't call scsi_done(),
1481 * the # IO timeouts == 2, will cause the LUN offline.
1482 * Call scsi_done to complete the IO.
1484 sc
->result
= (DID_ERROR
<< 16);
1489 /* Firmware completed abort with error */
1496 SNIC_HOST_INFO(snic
->shost
,
1497 "abt_fini: Tag %x, Cmpl Status %s flags 0x%llx\n",
1498 tag
, snic_io_status_to_str(CMD_ABTS_STATUS(sc
)),
1502 spin_unlock_irqrestore(io_lock
, flags
);
1504 snic_release_req_buf(snic
, rqi
, sc
);
1507 } /* end of snic_abort_finish */
1510 * snic_send_abort_and_wait : Issues Abort, and Waits
1513 snic_send_abort_and_wait(struct snic
*snic
, struct scsi_cmnd
*sc
)
1515 struct snic_req_info
*rqi
= NULL
;
1516 enum snic_ioreq_state sv_state
;
1517 struct snic_tgt
*tgt
= NULL
;
1518 spinlock_t
*io_lock
= NULL
;
1519 DECLARE_COMPLETION_ONSTACK(tm_done
);
1520 unsigned long flags
;
1521 int ret
= 0, tmf
= 0, tag
= snic_cmd_tag(sc
);
1523 tgt
= starget_to_tgt(scsi_target(sc
->device
));
1524 if ((snic_tgt_chkready(tgt
) != 0) && (tgt
->tdata
.typ
== SNIC_TGT_SAN
))
1525 tmf
= SNIC_ITMF_ABTS_TASK_TERM
;
1527 tmf
= SNIC_ITMF_ABTS_TASK
;
1531 io_lock
= snic_io_lock_hash(snic
, sc
);
1534 * Avoid a race between SCSI issuing the abort and the device
1535 * completing the command.
1537 * If the command is already completed by fw_cmpl code,
1538 * we just return SUCCESS from here. This means that the abort
1539 * succeeded. In the SCSI ML, since the timeout for command has
1540 * happend, the completion wont actually complete the command
1541 * and it will be considered as an aborted command
1543 * The CMD_SP will not be cleared except while holding io_lock
1545 spin_lock_irqsave(io_lock
, flags
);
1546 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1548 spin_unlock_irqrestore(io_lock
, flags
);
1550 SNIC_HOST_ERR(snic
->shost
,
1551 "abt_cmd: rqi is null. Tag %d flags 0x%llx\n",
1552 tag
, CMD_FLAGS(sc
));
1559 rqi
->abts_done
= &tm_done
;
1560 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
) {
1561 spin_unlock_irqrestore(io_lock
, flags
);
1566 SNIC_BUG_ON(!rqi
->abts_done
);
1568 /* Save Command State, should be restored on failed to Queue. */
1569 sv_state
= CMD_STATE(sc
);
1572 * Command is still pending, need to abort it
1573 * If the fw completes the command after this point,
1574 * the completion won't be done till mid-layer, since abot
1575 * has already started.
1577 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_PENDING
;
1578 CMD_ABTS_STATUS(sc
) = SNIC_INVALID_CODE
;
1580 SNIC_SCSI_DBG(snic
->shost
, "send_abt_cmd: TAG 0x%x\n", tag
);
1582 spin_unlock_irqrestore(io_lock
, flags
);
1584 /* Now Queue the abort command to firmware */
1585 ret
= snic_queue_abort_req(snic
, rqi
, sc
, tmf
);
1587 atomic64_inc(&snic
->s_stats
.abts
.q_fail
);
1588 SNIC_HOST_ERR(snic
->shost
,
1589 "send_abt_cmd: IO w/ Tag 0x%x fail w/ err %d flags 0x%llx\n",
1590 tag
, ret
, CMD_FLAGS(sc
));
1592 spin_lock_irqsave(io_lock
, flags
);
1593 /* Restore Command's previous state */
1594 CMD_STATE(sc
) = sv_state
;
1595 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1597 rqi
->abts_done
= NULL
;
1598 spin_unlock_irqrestore(io_lock
, flags
);
1604 spin_lock_irqsave(io_lock
, flags
);
1605 if (tmf
== SNIC_ITMF_ABTS_TASK
) {
1606 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_ISSUED
;
1607 atomic64_inc(&snic
->s_stats
.abts
.num
);
1610 CMD_FLAGS(sc
) |= SNIC_IO_TERM_ISSUED
;
1612 spin_unlock_irqrestore(io_lock
, flags
);
1614 SNIC_SCSI_DBG(snic
->shost
,
1615 "send_abt_cmd: sc %p Tag %x flags 0x%llx\n",
1616 sc
, tag
, CMD_FLAGS(sc
));
1623 * Queued an abort IO, wait for its completion.
1624 * Once the fw completes the abort command, it will
1625 * wakeup this thread.
1627 wait_for_completion_timeout(&tm_done
, SNIC_ABTS_TIMEOUT
);
1631 } /* end of snic_send_abort_and_wait */
1634 * This function is exported to SCSI for sending abort cmnds.
1635 * A SCSI IO is represent by snic_ioreq in the driver.
1636 * The snic_ioreq is linked to the SCSI Cmd, thus a link with the ULP'S IO
1639 snic_abort_cmd(struct scsi_cmnd
*sc
)
1641 struct snic
*snic
= shost_priv(sc
->device
->host
);
1642 int ret
= SUCCESS
, tag
= snic_cmd_tag(sc
);
1643 u32 start_time
= jiffies
;
1645 SNIC_SCSI_DBG(snic
->shost
, "abt_cmd:sc %p :0x%x :req = %p :tag = %d\n",
1646 sc
, sc
->cmnd
[0], sc
->request
, tag
);
1648 if (unlikely(snic_get_state(snic
) != SNIC_ONLINE
)) {
1649 SNIC_HOST_ERR(snic
->shost
,
1650 "abt_cmd: tag %x Parent Devs are not rdy\n",
1658 ret
= snic_send_abort_and_wait(snic
, sc
);
1662 ret
= snic_abort_finish(snic
, sc
);
1665 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
,
1666 jiffies_to_msecs(jiffies
- start_time
), 0,
1667 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
1669 SNIC_SCSI_DBG(snic
->shost
,
1670 "abts: Abort Req Status = %s\n",
1671 (ret
== SUCCESS
) ? "SUCCESS" :
1672 ((ret
== FAST_IO_FAIL
) ? "FAST_IO_FAIL" : "FAILED"));
1680 snic_is_abts_pending(struct snic
*snic
, struct scsi_cmnd
*lr_sc
)
1682 struct snic_req_info
*rqi
= NULL
;
1683 struct scsi_cmnd
*sc
= NULL
;
1684 struct scsi_device
*lr_sdev
= NULL
;
1685 spinlock_t
*io_lock
= NULL
;
1687 unsigned long flags
;
1690 lr_sdev
= lr_sc
->device
;
1692 /* walk through the tag map, an dcheck if IOs are still pending in fw*/
1693 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
1694 io_lock
= snic_io_lock_tag(snic
, tag
);
1696 spin_lock_irqsave(io_lock
, flags
);
1697 sc
= scsi_host_find_tag(snic
->shost
, tag
);
1699 if (!sc
|| (lr_sc
&& (sc
->device
!= lr_sdev
|| sc
== lr_sc
))) {
1700 spin_unlock_irqrestore(io_lock
, flags
);
1705 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1707 spin_unlock_irqrestore(io_lock
, flags
);
1713 * Found IO that is still pending w/ firmware and belongs to
1714 * the LUN that is under reset, if lr_sc != NULL
1716 SNIC_SCSI_DBG(snic
->shost
, "Found IO in %s on LUN\n",
1717 snic_ioreq_state_to_str(CMD_STATE(sc
)));
1719 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
) {
1720 spin_unlock_irqrestore(io_lock
, flags
);
1725 spin_unlock_irqrestore(io_lock
, flags
);
1729 } /* end of snic_is_abts_pending */
1732 snic_dr_clean_single_req(struct snic
*snic
,
1734 struct scsi_device
*lr_sdev
)
1736 struct snic_req_info
*rqi
= NULL
;
1737 struct snic_tgt
*tgt
= NULL
;
1738 struct scsi_cmnd
*sc
= NULL
;
1739 spinlock_t
*io_lock
= NULL
;
1740 u32 sv_state
= 0, tmf
= 0;
1741 DECLARE_COMPLETION_ONSTACK(tm_done
);
1742 unsigned long flags
;
1745 io_lock
= snic_io_lock_tag(snic
, tag
);
1746 spin_lock_irqsave(io_lock
, flags
);
1747 sc
= scsi_host_find_tag(snic
->shost
, tag
);
1749 /* Ignore Cmd that don't belong to Lun Reset device */
1750 if (!sc
|| sc
->device
!= lr_sdev
)
1753 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1759 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
1763 if ((CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) &&
1764 (!(CMD_FLAGS(sc
) & SNIC_DEV_RST_ISSUED
))) {
1766 SNIC_SCSI_DBG(snic
->shost
,
1767 "clean_single_req: devrst is not pending sc 0x%p\n",
1773 SNIC_SCSI_DBG(snic
->shost
,
1774 "clean_single_req: Found IO in %s on lun\n",
1775 snic_ioreq_state_to_str(CMD_STATE(sc
)));
1777 /* Save Command State */
1778 sv_state
= CMD_STATE(sc
);
1781 * Any pending IO issued prior to reset is expected to be
1782 * in abts pending state, if not we need to set SNIC_IOREQ_ABTS_PENDING
1783 * to indicate the IO is abort pending.
1784 * When IO is completed, the IO will be handed over and handled
1788 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_PENDING
;
1789 SNIC_BUG_ON(rqi
->abts_done
);
1791 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) {
1792 rqi
->tm_tag
= SNIC_TAG_DEV_RST
;
1794 SNIC_SCSI_DBG(snic
->shost
,
1795 "clean_single_req:devrst sc 0x%p\n", sc
);
1798 CMD_ABTS_STATUS(sc
) = SNIC_INVALID_CODE
;
1799 rqi
->abts_done
= &tm_done
;
1800 spin_unlock_irqrestore(io_lock
, flags
);
1802 tgt
= starget_to_tgt(scsi_target(sc
->device
));
1803 if ((snic_tgt_chkready(tgt
) != 0) && (tgt
->tdata
.typ
== SNIC_TGT_SAN
))
1804 tmf
= SNIC_ITMF_ABTS_TASK_TERM
;
1806 tmf
= SNIC_ITMF_ABTS_TASK
;
1808 /* Now queue the abort command to firmware */
1809 ret
= snic_queue_abort_req(snic
, rqi
, sc
, tmf
);
1811 SNIC_HOST_ERR(snic
->shost
,
1812 "clean_single_req_err:sc %p, tag %d abt failed. tm_tag %d flags 0x%llx\n",
1813 sc
, tag
, rqi
->tm_tag
, CMD_FLAGS(sc
));
1815 spin_lock_irqsave(io_lock
, flags
);
1816 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1818 rqi
->abts_done
= NULL
;
1820 /* Restore Command State */
1821 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
1822 CMD_STATE(sc
) = sv_state
;
1828 spin_lock_irqsave(io_lock
, flags
);
1829 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
)
1830 CMD_FLAGS(sc
) |= SNIC_DEV_RST_TERM_ISSUED
;
1832 CMD_FLAGS(sc
) |= SNIC_IO_INTERNAL_TERM_ISSUED
;
1833 spin_unlock_irqrestore(io_lock
, flags
);
1835 wait_for_completion_timeout(&tm_done
, SNIC_ABTS_TIMEOUT
);
1837 /* Recheck cmd state to check if it now aborted. */
1838 spin_lock_irqsave(io_lock
, flags
);
1839 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1841 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_REQ_NULL
;
1844 rqi
->abts_done
= NULL
;
1846 /* if abort is still pending w/ fw, fail */
1847 if (CMD_ABTS_STATUS(sc
) == SNIC_INVALID_CODE
) {
1848 SNIC_HOST_ERR(snic
->shost
,
1849 "clean_single_req_err:sc %p tag %d abt still pending w/ fw, tm_tag %d flags 0x%llx\n",
1850 sc
, tag
, rqi
->tm_tag
, CMD_FLAGS(sc
));
1852 CMD_FLAGS(sc
) |= SNIC_IO_ABTS_TERM_DONE
;
1858 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_COMPLETE
;
1860 spin_unlock_irqrestore(io_lock
, flags
);
1862 snic_release_req_buf(snic
, rqi
, sc
);
1864 sc
->result
= (DID_ERROR
<< 16);
1872 spin_unlock_irqrestore(io_lock
, flags
);
1875 } /* end of snic_dr_clean_single_req */
1878 snic_dr_clean_pending_req(struct snic
*snic
, struct scsi_cmnd
*lr_sc
)
1880 struct scsi_device
*lr_sdev
= lr_sc
->device
;
1884 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
1885 if (tag
== snic_cmd_tag(lr_sc
))
1888 ret
= snic_dr_clean_single_req(snic
, tag
, lr_sdev
);
1890 SNIC_HOST_ERR(snic
->shost
, "clean_err:tag = %d\n", tag
);
1896 schedule_timeout(msecs_to_jiffies(100));
1898 /* Walk through all the cmds and check abts status. */
1899 if (snic_is_abts_pending(snic
, lr_sc
)) {
1906 SNIC_SCSI_DBG(snic
->shost
, "clean_pending_req: Success.\n");
1912 SNIC_HOST_ERR(snic
->shost
,
1913 "Failed to Clean Pending IOs on %s device.\n",
1914 dev_name(&lr_sdev
->sdev_gendev
));
1918 } /* end of snic_dr_clean_pending_req */
1921 * snic_dr_finish : Called by snic_device_reset
1924 snic_dr_finish(struct snic
*snic
, struct scsi_cmnd
*sc
)
1926 struct snic_req_info
*rqi
= NULL
;
1927 spinlock_t
*io_lock
= NULL
;
1928 unsigned long flags
;
1932 io_lock
= snic_io_lock_hash(snic
, sc
);
1933 spin_lock_irqsave(io_lock
, flags
);
1934 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1936 spin_unlock_irqrestore(io_lock
, flags
);
1937 SNIC_SCSI_DBG(snic
->shost
,
1938 "dr_fini: rqi is null tag 0x%x sc 0x%p flags 0x%llx\n",
1939 snic_cmd_tag(sc
), sc
, CMD_FLAGS(sc
));
1945 rqi
->dr_done
= NULL
;
1947 lr_res
= CMD_LR_STATUS(sc
);
1950 case SNIC_INVALID_CODE
:
1952 SNIC_SCSI_DBG(snic
->shost
,
1953 "dr_fini: Tag %x Dev Reset Timedout. flags 0x%llx\n",
1954 snic_cmd_tag(sc
), CMD_FLAGS(sc
));
1956 CMD_FLAGS(sc
) |= SNIC_DEV_RST_TIMEDOUT
;
1961 case SNIC_STAT_IO_SUCCESS
:
1962 SNIC_SCSI_DBG(snic
->shost
,
1963 "dr_fini: Tag %x Dev Reset cmpl\n",
1969 SNIC_HOST_ERR(snic
->shost
,
1970 "dr_fini:Device Reset completed& failed.Tag = %x lr_status %s flags 0x%llx\n",
1972 snic_io_status_to_str(lr_res
), CMD_FLAGS(sc
));
1976 spin_unlock_irqrestore(io_lock
, flags
);
1979 * Cleanup any IOs on this LUN that have still not completed.
1980 * If any of these fail, then LUN Reset fails.
1981 * Cleanup cleans all commands on this LUN except
1982 * the lun reset command. If all cmds get cleaned, the LUN Reset
1986 ret
= snic_dr_clean_pending_req(snic
, sc
);
1988 spin_lock_irqsave(io_lock
, flags
);
1989 SNIC_SCSI_DBG(snic
->shost
,
1990 "dr_fini: Device Reset Failed since could not abort all IOs. Tag = %x.\n",
1992 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
1996 /* Cleanup LUN Reset Command */
1997 spin_lock_irqsave(io_lock
, flags
);
1998 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2000 ret
= SUCCESS
; /* Completed Successfully */
2006 SNIC_BUG_ON(!spin_is_locked(io_lock
));
2009 spin_unlock_irqrestore(io_lock
, flags
);
2012 snic_release_req_buf(snic
, rqi
, sc
);
2016 } /* end of snic_dr_finish */
2019 snic_queue_dr_req(struct snic
*snic
,
2020 struct snic_req_info
*rqi
,
2021 struct scsi_cmnd
*sc
)
2023 /* Add special tag for device reset */
2024 rqi
->tm_tag
|= SNIC_TAG_DEV_RST
;
2026 return snic_issue_tm_req(snic
, rqi
, sc
, SNIC_ITMF_LUN_RESET
);
2030 snic_send_dr_and_wait(struct snic
*snic
, struct scsi_cmnd
*sc
)
2032 struct snic_req_info
*rqi
= NULL
;
2033 enum snic_ioreq_state sv_state
;
2034 spinlock_t
*io_lock
= NULL
;
2035 unsigned long flags
;
2036 DECLARE_COMPLETION_ONSTACK(tm_done
);
2037 int ret
= FAILED
, tag
= snic_cmd_tag(sc
);
2039 io_lock
= snic_io_lock_hash(snic
, sc
);
2040 spin_lock_irqsave(io_lock
, flags
);
2041 CMD_FLAGS(sc
) |= SNIC_DEVICE_RESET
;
2042 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2044 SNIC_HOST_ERR(snic
->shost
,
2045 "send_dr: rqi is null, Tag 0x%x flags 0x%llx\n",
2046 tag
, CMD_FLAGS(sc
));
2047 spin_unlock_irqrestore(io_lock
, flags
);
2053 /* Save Command state to restore in case Queuing failed. */
2054 sv_state
= CMD_STATE(sc
);
2056 CMD_STATE(sc
) = SNIC_IOREQ_LR_PENDING
;
2057 CMD_LR_STATUS(sc
) = SNIC_INVALID_CODE
;
2059 SNIC_SCSI_DBG(snic
->shost
, "dr: TAG = %x\n", tag
);
2061 rqi
->dr_done
= &tm_done
;
2062 SNIC_BUG_ON(!rqi
->dr_done
);
2064 spin_unlock_irqrestore(io_lock
, flags
);
2066 * The Command state is changed to IOREQ_PENDING,
2067 * in this case, if the command is completed, the icmnd_cmpl will
2068 * mark the cmd as completed.
2069 * This logic still makes LUN Reset is inevitable.
2072 ret
= snic_queue_dr_req(snic
, rqi
, sc
);
2074 SNIC_HOST_ERR(snic
->shost
,
2075 "send_dr: IO w/ Tag 0x%x Failed err = %d. flags 0x%llx\n",
2076 tag
, ret
, CMD_FLAGS(sc
));
2078 spin_lock_irqsave(io_lock
, flags
);
2080 CMD_STATE(sc
) = sv_state
;
2081 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2083 rqi
->dr_done
= NULL
;
2084 /* rqi is freed in caller. */
2085 spin_unlock_irqrestore(io_lock
, flags
);
2091 spin_lock_irqsave(io_lock
, flags
);
2092 CMD_FLAGS(sc
) |= SNIC_DEV_RST_ISSUED
;
2093 spin_unlock_irqrestore(io_lock
, flags
);
2097 wait_for_completion_timeout(&tm_done
, SNIC_LUN_RESET_TIMEOUT
);
2104 * auxillary funciton to check lun reset op is supported or not
2105 * Not supported if returns 0
2108 snic_dev_reset_supported(struct scsi_device
*sdev
)
2110 struct snic_tgt
*tgt
= starget_to_tgt(scsi_target(sdev
));
2112 if (tgt
->tdata
.typ
== SNIC_TGT_DAS
)
2119 snic_unlink_and_release_req(struct snic
*snic
, struct scsi_cmnd
*sc
, int flag
)
2121 struct snic_req_info
*rqi
= NULL
;
2122 spinlock_t
*io_lock
= NULL
;
2123 unsigned long flags
;
2124 u32 start_time
= jiffies
;
2126 io_lock
= snic_io_lock_hash(snic
, sc
);
2127 spin_lock_irqsave(io_lock
, flags
);
2128 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2130 start_time
= rqi
->start_time
;
2134 CMD_FLAGS(sc
) |= flag
;
2135 spin_unlock_irqrestore(io_lock
, flags
);
2138 snic_release_req_buf(snic
, rqi
, sc
);
2140 SNIC_TRC(snic
->shost
->host_no
, snic_cmd_tag(sc
), (ulong
) sc
,
2141 jiffies_to_msecs(jiffies
- start_time
), (ulong
) rqi
,
2142 SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
2146 * SCSI Eh thread issues a LUN Reset when one or more commands on a LUN
2147 * fail to get aborted. It calls driver's eh_device_reset with a SCSI
2148 * command on the LUN.
2151 snic_device_reset(struct scsi_cmnd
*sc
)
2153 struct Scsi_Host
*shost
= sc
->device
->host
;
2154 struct snic
*snic
= shost_priv(shost
);
2155 struct snic_req_info
*rqi
= NULL
;
2156 int tag
= snic_cmd_tag(sc
);
2157 int start_time
= jiffies
;
2161 SNIC_SCSI_DBG(shost
, "dev_reset:sc %p :0x%x :req = %p :tag = %d\n",
2162 sc
, sc
->cmnd
[0], sc
->request
,
2164 dr_supp
= snic_dev_reset_supported(sc
->device
);
2166 /* device reset op is not supported */
2167 SNIC_HOST_INFO(shost
, "LUN Reset Op not supported.\n");
2168 snic_unlink_and_release_req(snic
, sc
, SNIC_DEV_RST_NOTSUP
);
2173 if (unlikely(snic_get_state(snic
) != SNIC_ONLINE
)) {
2174 snic_unlink_and_release_req(snic
, sc
, 0);
2175 SNIC_HOST_ERR(shost
, "Devrst: Parent Devs are not online.\n");
2180 /* There is no tag when lun reset is issue through ioctl. */
2181 if (unlikely(tag
<= SNIC_NO_TAG
)) {
2182 SNIC_HOST_INFO(snic
->shost
,
2183 "Devrst: LUN Reset Recvd thru IOCTL.\n");
2185 rqi
= snic_req_init(snic
, 0);
2189 memset(scsi_cmd_priv(sc
), 0,
2190 sizeof(struct snic_internal_io_state
));
2191 CMD_SP(sc
) = (char *)rqi
;
2192 CMD_FLAGS(sc
) = SNIC_NO_FLAGS
;
2194 /* Add special tag for dr coming from user spc */
2195 rqi
->tm_tag
= SNIC_TAG_IOCTL_DEV_RST
;
2199 ret
= snic_send_dr_and_wait(snic
, sc
);
2201 SNIC_HOST_ERR(snic
->shost
,
2202 "Devrst: IO w/ Tag %x Failed w/ err = %d\n",
2205 snic_unlink_and_release_req(snic
, sc
, 0);
2210 ret
= snic_dr_finish(snic
, sc
);
2213 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
,
2214 jiffies_to_msecs(jiffies
- start_time
),
2215 0, SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
2217 SNIC_SCSI_DBG(snic
->shost
,
2218 "Devrst: Returning from Device Reset : %s\n",
2219 (ret
== SUCCESS
) ? "SUCCESS" : "FAILED");
2222 } /* end of snic_device_reset */
2225 * SCSI Error handling calls driver's eh_host_reset if all prior
2226 * error handling levels return FAILED.
2228 * Host Reset is the highest level of error recovery. If this fails, then
2229 * host is offlined by SCSI.
2232 * snic_issue_hba_reset : Queues FW Reset Request.
2235 snic_issue_hba_reset(struct snic
*snic
, struct scsi_cmnd
*sc
)
2237 struct snic_req_info
*rqi
= NULL
;
2238 struct snic_host_req
*req
= NULL
;
2239 spinlock_t
*io_lock
= NULL
;
2240 DECLARE_COMPLETION_ONSTACK(wait
);
2241 unsigned long flags
;
2244 rqi
= snic_req_init(snic
, 0);
2251 if (snic_cmd_tag(sc
) == SCSI_NO_TAG
) {
2252 memset(scsi_cmd_priv(sc
), 0,
2253 sizeof(struct snic_internal_io_state
));
2254 SNIC_HOST_INFO(snic
->shost
, "issu_hr:Host reset thru ioctl.\n");
2258 req
= rqi_to_req(rqi
);
2260 io_lock
= snic_io_lock_hash(snic
, sc
);
2261 spin_lock_irqsave(io_lock
, flags
);
2262 SNIC_BUG_ON(CMD_SP(sc
) != NULL
);
2263 CMD_STATE(sc
) = SNIC_IOREQ_PENDING
;
2264 CMD_SP(sc
) = (char *) rqi
;
2265 CMD_FLAGS(sc
) |= SNIC_IO_INITIALIZED
;
2266 snic
->remove_wait
= &wait
;
2267 spin_unlock_irqrestore(io_lock
, flags
);
2269 /* Initialize Request */
2270 snic_io_hdr_enc(&req
->hdr
, SNIC_REQ_HBA_RESET
, 0, snic_cmd_tag(sc
),
2271 snic
->config
.hid
, 0, (ulong
) rqi
);
2273 req
->u
.reset
.flags
= 0;
2275 ret
= snic_queue_wq_desc(snic
, req
, sizeof(*req
));
2277 SNIC_HOST_ERR(snic
->shost
,
2278 "issu_hr:Queuing HBA Reset Failed. w err %d\n",
2284 spin_lock_irqsave(io_lock
, flags
);
2285 CMD_FLAGS(sc
) |= SNIC_HOST_RESET_ISSUED
;
2286 spin_unlock_irqrestore(io_lock
, flags
);
2287 atomic64_inc(&snic
->s_stats
.reset
.hba_resets
);
2288 SNIC_HOST_INFO(snic
->shost
, "Queued HBA Reset Successfully.\n");
2290 wait_for_completion_timeout(snic
->remove_wait
,
2291 SNIC_HOST_RESET_TIMEOUT
);
2293 if (snic_get_state(snic
) == SNIC_FWRESET
) {
2294 SNIC_HOST_ERR(snic
->shost
, "reset_cmpl: Reset Timedout.\n");
2300 spin_lock_irqsave(io_lock
, flags
);
2301 snic
->remove_wait
= NULL
;
2302 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2304 spin_unlock_irqrestore(io_lock
, flags
);
2307 snic_req_free(snic
, rqi
);
2314 spin_lock_irqsave(io_lock
, flags
);
2315 snic
->remove_wait
= NULL
;
2316 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2318 spin_unlock_irqrestore(io_lock
, flags
);
2321 snic_req_free(snic
, rqi
);
2324 SNIC_HOST_ERR(snic
->shost
,
2325 "reset:HBA Reset Failed w/ err = %d.\n",
2329 } /* end of snic_issue_hba_reset */
2332 snic_reset(struct Scsi_Host
*shost
, struct scsi_cmnd
*sc
)
2334 struct snic
*snic
= shost_priv(shost
);
2335 enum snic_state sv_state
;
2336 unsigned long flags
;
2339 /* Set snic state as SNIC_FWRESET*/
2340 sv_state
= snic_get_state(snic
);
2342 spin_lock_irqsave(&snic
->snic_lock
, flags
);
2343 if (snic_get_state(snic
) == SNIC_FWRESET
) {
2344 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
2345 SNIC_HOST_INFO(shost
, "reset:prev reset is in progres\n");
2347 msleep(SNIC_HOST_RESET_TIMEOUT
);
2353 snic_set_state(snic
, SNIC_FWRESET
);
2354 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
2357 /* Wait for all the IOs that are entered in Qcmd */
2358 while (atomic_read(&snic
->ios_inflight
))
2359 schedule_timeout(msecs_to_jiffies(1));
2361 ret
= snic_issue_hba_reset(snic
, sc
);
2363 SNIC_HOST_ERR(shost
,
2364 "reset:Host Reset Failed w/ err %d.\n",
2366 spin_lock_irqsave(&snic
->snic_lock
, flags
);
2367 snic_set_state(snic
, sv_state
);
2368 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
2369 atomic64_inc(&snic
->s_stats
.reset
.hba_reset_fail
);
2379 } /* end of snic_reset */
2382 * SCSI Error handling calls driver's eh_host_reset if all prior
2383 * error handling levels return FAILED.
2385 * Host Reset is the highest level of error recovery. If this fails, then
2386 * host is offlined by SCSI.
2389 snic_host_reset(struct scsi_cmnd
*sc
)
2391 struct Scsi_Host
*shost
= sc
->device
->host
;
2392 u32 start_time
= jiffies
;
2395 SNIC_SCSI_DBG(shost
,
2396 "host reset:sc %p sc_cmd 0x%x req %p tag %d flags 0x%llx\n",
2397 sc
, sc
->cmnd
[0], sc
->request
,
2398 snic_cmd_tag(sc
), CMD_FLAGS(sc
));
2400 ret
= snic_reset(shost
, sc
);
2402 SNIC_TRC(shost
->host_no
, snic_cmd_tag(sc
), (ulong
) sc
,
2403 jiffies_to_msecs(jiffies
- start_time
),
2404 0, SNIC_TRC_CMD(sc
), SNIC_TRC_CMD_STATE_FLAGS(sc
));
2407 } /* end of snic_host_reset */
2410 * snic_cmpl_pending_tmreq : Caller should hold io_lock
2413 snic_cmpl_pending_tmreq(struct snic
*snic
, struct scsi_cmnd
*sc
)
2415 struct snic_req_info
*rqi
= NULL
;
2417 SNIC_SCSI_DBG(snic
->shost
,
2418 "Completing Pending TM Req sc %p, state %s flags 0x%llx\n",
2419 sc
, snic_io_status_to_str(CMD_STATE(sc
)), CMD_FLAGS(sc
));
2422 * CASE : FW didn't post itmf completion due to PCIe Errors.
2423 * Marking the abort status as Success to call scsi completion
2424 * in snic_abort_finish()
2426 CMD_ABTS_STATUS(sc
) = SNIC_STAT_IO_SUCCESS
;
2428 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2433 complete(rqi
->dr_done
);
2434 else if (rqi
->abts_done
)
2435 complete(rqi
->abts_done
);
2439 * snic_scsi_cleanup: Walks through tag map and releases the reqs
2442 snic_scsi_cleanup(struct snic
*snic
, int ex_tag
)
2444 struct snic_req_info
*rqi
= NULL
;
2445 struct scsi_cmnd
*sc
= NULL
;
2446 spinlock_t
*io_lock
= NULL
;
2447 unsigned long flags
;
2451 SNIC_SCSI_DBG(snic
->shost
, "sc_clean: scsi cleanup.\n");
2453 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
2458 io_lock
= snic_io_lock_tag(snic
, tag
);
2459 spin_lock_irqsave(io_lock
, flags
);
2460 sc
= scsi_host_find_tag(snic
->shost
, tag
);
2462 spin_unlock_irqrestore(io_lock
, flags
);
2467 if (unlikely(snic_tmreq_pending(sc
))) {
2469 * When FW Completes reset w/o sending completions
2470 * for outstanding ios.
2472 snic_cmpl_pending_tmreq(snic
, sc
);
2473 spin_unlock_irqrestore(io_lock
, flags
);
2478 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2480 spin_unlock_irqrestore(io_lock
, flags
);
2485 SNIC_SCSI_DBG(snic
->shost
,
2486 "sc_clean: sc %p, rqi %p, tag %d flags 0x%llx\n",
2487 sc
, rqi
, tag
, CMD_FLAGS(sc
));
2490 CMD_FLAGS(sc
) |= SNIC_SCSI_CLEANUP
;
2491 spin_unlock_irqrestore(io_lock
, flags
);
2492 st_time
= rqi
->start_time
;
2494 SNIC_HOST_INFO(snic
->shost
,
2495 "sc_clean: Releasing rqi %p : flags 0x%llx\n",
2496 rqi
, CMD_FLAGS(sc
));
2498 snic_release_req_buf(snic
, rqi
, sc
);
2501 sc
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
2502 SNIC_HOST_INFO(snic
->shost
,
2503 "sc_clean: DID_TRANSPORT_DISRUPTED for sc %p, Tag %d flags 0x%llx rqi %p duration %u msecs\n",
2504 sc
, sc
->request
->tag
, CMD_FLAGS(sc
), rqi
,
2505 jiffies_to_msecs(jiffies
- st_time
));
2507 /* Update IO stats */
2508 snic_stats_update_io_cmpl(&snic
->s_stats
);
2510 if (sc
->scsi_done
) {
2511 SNIC_TRC(snic
->shost
->host_no
, tag
, (ulong
) sc
,
2512 jiffies_to_msecs(jiffies
- st_time
), 0,
2514 SNIC_TRC_CMD_STATE_FLAGS(sc
));
2519 } /* end of snic_scsi_cleanup */
2522 snic_shutdown_scsi_cleanup(struct snic
*snic
)
2524 SNIC_HOST_INFO(snic
->shost
, "Shutdown time SCSI Cleanup.\n");
2526 snic_scsi_cleanup(snic
, SCSI_NO_TAG
);
2527 } /* end of snic_shutdown_scsi_cleanup */
2530 * snic_internal_abort_io
2531 * called by : snic_tgt_scsi_abort_io
2534 snic_internal_abort_io(struct snic
*snic
, struct scsi_cmnd
*sc
, int tmf
)
2536 struct snic_req_info
*rqi
= NULL
;
2537 spinlock_t
*io_lock
= NULL
;
2538 unsigned long flags
;
2542 io_lock
= snic_io_lock_hash(snic
, sc
);
2543 spin_lock_irqsave(io_lock
, flags
);
2544 rqi
= (struct snic_req_info
*) CMD_SP(sc
);
2546 goto skip_internal_abts
;
2548 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
2549 goto skip_internal_abts
;
2551 if ((CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) &&
2552 (!(CMD_FLAGS(sc
) & SNIC_DEV_RST_ISSUED
))) {
2554 SNIC_SCSI_DBG(snic
->shost
,
2555 "internal_abts: dev rst not pending sc 0x%p\n",
2558 goto skip_internal_abts
;
2562 if (!(CMD_FLAGS(sc
) & SNIC_IO_ISSUED
)) {
2563 SNIC_SCSI_DBG(snic
->shost
,
2564 "internal_abts: IO not yet issued sc 0x%p tag 0x%x flags 0x%llx state %d\n",
2565 sc
, snic_cmd_tag(sc
), CMD_FLAGS(sc
), CMD_STATE(sc
));
2567 goto skip_internal_abts
;
2570 sv_state
= CMD_STATE(sc
);
2571 CMD_STATE(sc
) = SNIC_IOREQ_ABTS_PENDING
;
2572 CMD_ABTS_STATUS(sc
) = SNIC_INVALID_CODE
;
2573 CMD_FLAGS(sc
) |= SNIC_IO_INTERNAL_TERM_PENDING
;
2575 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
) {
2577 rqi
->tm_tag
= SNIC_TAG_DEV_RST
;
2578 SNIC_SCSI_DBG(snic
->shost
, "internal_abts:dev rst sc %p\n", sc
);
2581 SNIC_SCSI_DBG(snic
->shost
, "internal_abts: Issuing abts tag %x\n",
2583 SNIC_BUG_ON(rqi
->abts_done
);
2584 spin_unlock_irqrestore(io_lock
, flags
);
2586 ret
= snic_queue_abort_req(snic
, rqi
, sc
, tmf
);
2588 SNIC_HOST_ERR(snic
->shost
,
2589 "internal_abts: Tag = %x , Failed w/ err = %d\n",
2590 snic_cmd_tag(sc
), ret
);
2592 spin_lock_irqsave(io_lock
, flags
);
2594 if (CMD_STATE(sc
) == SNIC_IOREQ_ABTS_PENDING
)
2595 CMD_STATE(sc
) = sv_state
;
2597 goto skip_internal_abts
;
2600 spin_lock_irqsave(io_lock
, flags
);
2601 if (CMD_FLAGS(sc
) & SNIC_DEVICE_RESET
)
2602 CMD_FLAGS(sc
) |= SNIC_DEV_RST_TERM_ISSUED
;
2604 CMD_FLAGS(sc
) |= SNIC_IO_INTERNAL_TERM_ISSUED
;
2609 SNIC_BUG_ON(!spin_is_locked(io_lock
));
2610 spin_unlock_irqrestore(io_lock
, flags
);
2613 } /* end of snic_internal_abort_io */
2616 * snic_tgt_scsi_abort_io : called by snic_tgt_del
2619 snic_tgt_scsi_abort_io(struct snic_tgt
*tgt
)
2621 struct snic
*snic
= NULL
;
2622 struct scsi_cmnd
*sc
= NULL
;
2623 struct snic_tgt
*sc_tgt
= NULL
;
2624 spinlock_t
*io_lock
= NULL
;
2625 unsigned long flags
;
2626 int ret
= 0, tag
, abt_cnt
= 0, tmf
= 0;
2631 snic
= shost_priv(snic_tgt_to_shost(tgt
));
2632 SNIC_SCSI_DBG(snic
->shost
, "tgt_abt_io: Cleaning Pending IOs.\n");
2634 if (tgt
->tdata
.typ
== SNIC_TGT_DAS
)
2635 tmf
= SNIC_ITMF_ABTS_TASK
;
2637 tmf
= SNIC_ITMF_ABTS_TASK_TERM
;
2639 for (tag
= 0; tag
< snic
->max_tag_id
; tag
++) {
2640 io_lock
= snic_io_lock_tag(snic
, tag
);
2642 spin_lock_irqsave(io_lock
, flags
);
2643 sc
= scsi_host_find_tag(snic
->shost
, tag
);
2645 spin_unlock_irqrestore(io_lock
, flags
);
2650 sc_tgt
= starget_to_tgt(scsi_target(sc
->device
));
2651 if (sc_tgt
!= tgt
) {
2652 spin_unlock_irqrestore(io_lock
, flags
);
2656 spin_unlock_irqrestore(io_lock
, flags
);
2658 ret
= snic_internal_abort_io(snic
, sc
, tmf
);
2660 SNIC_HOST_ERR(snic
->shost
,
2661 "tgt_abt_io: Tag %x, Failed w err = %d\n",
2671 SNIC_SCSI_DBG(snic
->shost
, "tgt_abt_io: abt_cnt = %d\n", abt_cnt
);
2674 } /* end of snic_tgt_scsi_abort_io */