1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
4 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
6 #include <linux/mempool.h>
7 #include <linux/errno.h>
8 #include <linux/init.h>
9 #include <linux/workqueue.h>
10 #include <linux/pci.h>
11 #include <linux/scatterlist.h>
12 #include <linux/skbuff.h>
13 #include <linux/spinlock.h>
14 #include <linux/etherdevice.h>
15 #include <linux/if_ether.h>
16 #include <linux/if_vlan.h>
17 #include <linux/delay.h>
18 #include <linux/gfp.h>
19 #include <scsi/scsi.h>
20 #include <scsi/scsi_host.h>
21 #include <scsi/scsi_device.h>
22 #include <scsi/scsi_cmnd.h>
23 #include <scsi/scsi_tcq.h>
24 #include <scsi/fc/fc_els.h>
25 #include <scsi/fc/fc_fcoe.h>
26 #include <scsi/libfc.h>
27 #include <scsi/fc_frame.h>
31 const char *fnic_state_str
[] = {
32 [FNIC_IN_FC_MODE
] = "FNIC_IN_FC_MODE",
33 [FNIC_IN_FC_TRANS_ETH_MODE
] = "FNIC_IN_FC_TRANS_ETH_MODE",
34 [FNIC_IN_ETH_MODE
] = "FNIC_IN_ETH_MODE",
35 [FNIC_IN_ETH_TRANS_FC_MODE
] = "FNIC_IN_ETH_TRANS_FC_MODE",
38 static const char *fnic_ioreq_state_str
[] = {
39 [FNIC_IOREQ_NOT_INITED
] = "FNIC_IOREQ_NOT_INITED",
40 [FNIC_IOREQ_CMD_PENDING
] = "FNIC_IOREQ_CMD_PENDING",
41 [FNIC_IOREQ_ABTS_PENDING
] = "FNIC_IOREQ_ABTS_PENDING",
42 [FNIC_IOREQ_ABTS_COMPLETE
] = "FNIC_IOREQ_ABTS_COMPLETE",
43 [FNIC_IOREQ_CMD_COMPLETE
] = "FNIC_IOREQ_CMD_COMPLETE",
46 static const char *fcpio_status_str
[] = {
47 [FCPIO_SUCCESS
] = "FCPIO_SUCCESS", /*0x0*/
48 [FCPIO_INVALID_HEADER
] = "FCPIO_INVALID_HEADER",
49 [FCPIO_OUT_OF_RESOURCE
] = "FCPIO_OUT_OF_RESOURCE",
50 [FCPIO_INVALID_PARAM
] = "FCPIO_INVALID_PARAM]",
51 [FCPIO_REQ_NOT_SUPPORTED
] = "FCPIO_REQ_NOT_SUPPORTED",
52 [FCPIO_IO_NOT_FOUND
] = "FCPIO_IO_NOT_FOUND",
53 [FCPIO_ABORTED
] = "FCPIO_ABORTED", /*0x41*/
54 [FCPIO_TIMEOUT
] = "FCPIO_TIMEOUT",
55 [FCPIO_SGL_INVALID
] = "FCPIO_SGL_INVALID",
56 [FCPIO_MSS_INVALID
] = "FCPIO_MSS_INVALID",
57 [FCPIO_DATA_CNT_MISMATCH
] = "FCPIO_DATA_CNT_MISMATCH",
58 [FCPIO_FW_ERR
] = "FCPIO_FW_ERR",
59 [FCPIO_ITMF_REJECTED
] = "FCPIO_ITMF_REJECTED",
60 [FCPIO_ITMF_FAILED
] = "FCPIO_ITMF_FAILED",
61 [FCPIO_ITMF_INCORRECT_LUN
] = "FCPIO_ITMF_INCORRECT_LUN",
62 [FCPIO_CMND_REJECTED
] = "FCPIO_CMND_REJECTED",
63 [FCPIO_NO_PATH_AVAIL
] = "FCPIO_NO_PATH_AVAIL",
64 [FCPIO_PATH_FAILED
] = "FCPIO_PATH_FAILED",
65 [FCPIO_LUNMAP_CHNG_PEND
] = "FCPIO_LUNHMAP_CHNG_PEND",
68 const char *fnic_state_to_str(unsigned int state
)
70 if (state
>= ARRAY_SIZE(fnic_state_str
) || !fnic_state_str
[state
])
73 return fnic_state_str
[state
];
76 static const char *fnic_ioreq_state_to_str(unsigned int state
)
78 if (state
>= ARRAY_SIZE(fnic_ioreq_state_str
) ||
79 !fnic_ioreq_state_str
[state
])
82 return fnic_ioreq_state_str
[state
];
85 static const char *fnic_fcpio_status_to_str(unsigned int status
)
87 if (status
>= ARRAY_SIZE(fcpio_status_str
) || !fcpio_status_str
[status
])
90 return fcpio_status_str
[status
];
93 static void fnic_cleanup_io(struct fnic
*fnic
);
96 * Unmap the data buffer and sense buffer for an io_req,
97 * also unmap and free the device-private scatter/gather list.
99 static void fnic_release_ioreq_buf(struct fnic
*fnic
,
100 struct fnic_io_req
*io_req
,
101 struct scsi_cmnd
*sc
)
103 if (io_req
->sgl_list_pa
)
104 dma_unmap_single(&fnic
->pdev
->dev
, io_req
->sgl_list_pa
,
105 sizeof(io_req
->sgl_list
[0]) * io_req
->sgl_cnt
,
110 mempool_free(io_req
->sgl_list_alloc
,
111 fnic
->io_sgl_pool
[io_req
->sgl_type
]);
112 if (io_req
->sense_buf_pa
)
113 dma_unmap_single(&fnic
->pdev
->dev
, io_req
->sense_buf_pa
,
114 SCSI_SENSE_BUFFERSIZE
, DMA_FROM_DEVICE
);
117 /* Free up Copy Wq descriptors. Called with copy_wq lock held */
118 static int free_wq_copy_descs(struct fnic
*fnic
, struct vnic_wq_copy
*wq
, unsigned int hwq
)
120 /* if no Ack received from firmware, then nothing to clean */
121 if (!fnic
->fw_ack_recd
[hwq
])
125 * Update desc_available count based on number of freed descriptors
126 * Account for wraparound
128 if (wq
->to_clean_index
<= fnic
->fw_ack_index
[hwq
])
129 wq
->ring
.desc_avail
+= (fnic
->fw_ack_index
[hwq
]
130 - wq
->to_clean_index
+ 1);
132 wq
->ring
.desc_avail
+= (wq
->ring
.desc_count
134 + fnic
->fw_ack_index
[hwq
] + 1);
137 * just bump clean index to ack_index+1 accounting for wraparound
138 * this will essentially free up all descriptors between
139 * to_clean_index and fw_ack_index, both inclusive
142 (fnic
->fw_ack_index
[hwq
] + 1) % wq
->ring
.desc_count
;
144 /* we have processed the acks received so far */
145 fnic
->fw_ack_recd
[hwq
] = 0;
151 * __fnic_set_state_flags
152 * Sets/Clears bits in fnic's state_flags
155 __fnic_set_state_flags(struct fnic
*fnic
, unsigned long st_flags
,
156 unsigned long clearbits
)
158 unsigned long flags
= 0;
160 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
163 fnic
->state_flags
&= ~st_flags
;
165 fnic
->state_flags
|= st_flags
;
167 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
174 * fnic_fw_reset_handler
175 * Routine to send reset msg to fw
177 int fnic_fw_reset_handler(struct fnic
*fnic
)
179 struct vnic_wq_copy
*wq
= &fnic
->hw_copy_wq
[0];
183 /* indicate fwreset to io path */
184 fnic_set_state_flags(fnic
, FNIC_FLAGS_FWRESET
);
186 skb_queue_purge(&fnic
->frame_queue
);
187 skb_queue_purge(&fnic
->tx_queue
);
189 /* wait for io cmpl */
190 while (atomic_read(&fnic
->in_flight
))
191 schedule_timeout(msecs_to_jiffies(1));
193 spin_lock_irqsave(&fnic
->wq_copy_lock
[0], flags
);
195 if (vnic_wq_copy_desc_avail(wq
) <= fnic
->wq_copy_desc_low
[0])
196 free_wq_copy_descs(fnic
, wq
, 0);
198 if (!vnic_wq_copy_desc_avail(wq
))
201 fnic_queue_wq_copy_desc_fw_reset(wq
, SCSI_NO_TAG
);
202 atomic64_inc(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
);
203 if (atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
) >
204 atomic64_read(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
))
205 atomic64_set(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
,
207 &fnic
->fnic_stats
.fw_stats
.active_fw_reqs
));
210 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[0], flags
);
213 atomic64_inc(&fnic
->fnic_stats
.reset_stats
.fw_resets
);
214 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
215 "Issued fw reset\n");
217 fnic_clear_state_flags(fnic
, FNIC_FLAGS_FWRESET
);
218 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
219 "Failed to issue fw reset\n");
227 * fnic_flogi_reg_handler
228 * Routine to send flogi register msg to fw
230 int fnic_flogi_reg_handler(struct fnic
*fnic
, u32 fc_id
)
232 struct vnic_wq_copy
*wq
= &fnic
->hw_copy_wq
[0];
233 enum fcpio_flogi_reg_format_type format
;
234 struct fc_lport
*lp
= fnic
->lport
;
239 spin_lock_irqsave(&fnic
->wq_copy_lock
[0], flags
);
241 if (vnic_wq_copy_desc_avail(wq
) <= fnic
->wq_copy_desc_low
[0])
242 free_wq_copy_descs(fnic
, wq
, 0);
244 if (!vnic_wq_copy_desc_avail(wq
)) {
246 goto flogi_reg_ioreq_end
;
249 if (fnic
->ctlr
.map_dest
) {
250 eth_broadcast_addr(gw_mac
);
251 format
= FCPIO_FLOGI_REG_DEF_DEST
;
253 memcpy(gw_mac
, fnic
->ctlr
.dest_addr
, ETH_ALEN
);
254 format
= FCPIO_FLOGI_REG_GW_DEST
;
257 if ((fnic
->config
.flags
& VFCF_FIP_CAPABLE
) && !fnic
->ctlr
.map_dest
) {
258 fnic_queue_wq_copy_desc_fip_reg(wq
, SCSI_NO_TAG
,
261 lp
->r_a_tov
, lp
->e_d_tov
);
262 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
263 "FLOGI FIP reg issued fcid %x src %pM dest %pM\n",
264 fc_id
, fnic
->data_src_addr
, gw_mac
);
266 fnic_queue_wq_copy_desc_flogi_reg(wq
, SCSI_NO_TAG
,
267 format
, fc_id
, gw_mac
);
268 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
269 "FLOGI reg issued fcid 0x%x map %d dest 0x%p\n",
270 fc_id
, fnic
->ctlr
.map_dest
, gw_mac
);
273 atomic64_inc(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
);
274 if (atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
) >
275 atomic64_read(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
))
276 atomic64_set(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
,
277 atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
));
280 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[0], flags
);
285 * fnic_queue_wq_copy_desc
286 * Routine to enqueue a wq copy desc
288 static inline int fnic_queue_wq_copy_desc(struct fnic
*fnic
,
289 struct vnic_wq_copy
*wq
,
290 struct fnic_io_req
*io_req
,
291 struct scsi_cmnd
*sc
,
296 struct scatterlist
*sg
;
297 struct fc_rport
*rport
= starget_to_rport(scsi_target(sc
->device
));
298 struct fc_rport_libfc_priv
*rp
= rport
->dd_data
;
299 struct host_sg_desc
*desc
;
300 struct misc_stats
*misc_stats
= &fnic
->fnic_stats
.misc_stats
;
304 struct scsi_lun fc_lun
;
307 /* For each SGE, create a device desc entry */
308 desc
= io_req
->sgl_list
;
309 for_each_sg(scsi_sglist(sc
), sg
, sg_count
, i
) {
310 desc
->addr
= cpu_to_le64(sg_dma_address(sg
));
311 desc
->len
= cpu_to_le32(sg_dma_len(sg
));
316 io_req
->sgl_list_pa
= dma_map_single(&fnic
->pdev
->dev
,
318 sizeof(io_req
->sgl_list
[0]) * sg_count
,
320 if (dma_mapping_error(&fnic
->pdev
->dev
, io_req
->sgl_list_pa
)) {
321 printk(KERN_ERR
"DMA mapping failed\n");
322 return SCSI_MLQUEUE_HOST_BUSY
;
326 io_req
->sense_buf_pa
= dma_map_single(&fnic
->pdev
->dev
,
328 SCSI_SENSE_BUFFERSIZE
,
330 if (dma_mapping_error(&fnic
->pdev
->dev
, io_req
->sense_buf_pa
)) {
331 dma_unmap_single(&fnic
->pdev
->dev
, io_req
->sgl_list_pa
,
332 sizeof(io_req
->sgl_list
[0]) * sg_count
,
334 printk(KERN_ERR
"DMA mapping failed\n");
335 return SCSI_MLQUEUE_HOST_BUSY
;
338 int_to_scsilun(sc
->device
->lun
, &fc_lun
);
340 /* Enqueue the descriptor in the Copy WQ */
341 if (vnic_wq_copy_desc_avail(wq
) <= fnic
->wq_copy_desc_low
[hwq
])
342 free_wq_copy_descs(fnic
, wq
, hwq
);
344 if (unlikely(!vnic_wq_copy_desc_avail(wq
))) {
345 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
346 "fnic_queue_wq_copy_desc failure - no descriptors\n");
347 atomic64_inc(&misc_stats
->io_cpwq_alloc_failures
);
348 return SCSI_MLQUEUE_HOST_BUSY
;
352 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
)
353 flags
= FCPIO_ICMND_RDDATA
;
354 else if (sc
->sc_data_direction
== DMA_TO_DEVICE
)
355 flags
= FCPIO_ICMND_WRDATA
;
358 if ((fnic
->config
.flags
& VFCF_FCP_SEQ_LVL_ERR
) &&
359 (rp
->flags
& FC_RP_FLAGS_RETRY
))
360 exch_flags
|= FCPIO_ICMND_SRFLAG_RETRY
;
362 fnic_queue_wq_copy_desc_icmnd_16(wq
, mqtag
,
363 0, exch_flags
, io_req
->sgl_cnt
,
364 SCSI_SENSE_BUFFERSIZE
,
366 io_req
->sense_buf_pa
,
367 0, /* scsi cmd ref, always 0 */
368 FCPIO_ICMND_PTA_SIMPLE
,
369 /* scsi pri and tag */
370 flags
, /* command flags */
371 sc
->cmnd
, sc
->cmd_len
,
373 fc_lun
.scsi_lun
, io_req
->port_id
,
374 rport
->maxframe_size
, rp
->r_a_tov
,
377 atomic64_inc(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
);
378 if (atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
) >
379 atomic64_read(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
))
380 atomic64_set(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
,
381 atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
));
386 int fnic_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*sc
)
388 struct request
*const rq
= scsi_cmd_to_rq(sc
);
390 void (*done
)(struct scsi_cmnd
*) = scsi_done
;
391 struct fc_lport
*lp
= shost_priv(sc
->device
->host
);
392 struct fc_rport
*rport
;
393 struct fnic_io_req
*io_req
= NULL
;
394 struct fnic
*fnic
= lport_priv(lp
);
395 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
396 struct vnic_wq_copy
*wq
;
400 unsigned long flags
= 0;
402 int io_lock_acquired
= 0;
403 struct fc_rport_libfc_priv
*rp
;
406 mqtag
= blk_mq_unique_tag(rq
);
407 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
409 if (unlikely(fnic_chk_state_flags_locked(fnic
, FNIC_FLAGS_IO_BLOCKED
))) {
410 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
411 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
412 "fnic IO blocked flags: 0x%lx. Returning SCSI_MLQUEUE_HOST_BUSY\n",
414 return SCSI_MLQUEUE_HOST_BUSY
;
417 if (unlikely(fnic_chk_state_flags_locked(fnic
, FNIC_FLAGS_FWRESET
))) {
418 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
419 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
420 "fnic flags: 0x%lx. Returning SCSI_MLQUEUE_HOST_BUSY\n",
422 return SCSI_MLQUEUE_HOST_BUSY
;
425 rport
= starget_to_rport(scsi_target(sc
->device
));
427 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
428 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
429 "returning DID_NO_CONNECT for IO as rport is NULL\n");
430 sc
->result
= DID_NO_CONNECT
<< 16;
435 ret
= fc_remote_port_chkready(rport
);
437 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
438 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
439 "rport is not ready\n");
440 atomic64_inc(&fnic_stats
->misc_stats
.rport_not_ready
);
447 if (!rp
|| rp
->rp_state
== RPORT_ST_DELETE
) {
448 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
449 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
450 "rport 0x%x removed, returning DID_NO_CONNECT\n",
453 atomic64_inc(&fnic_stats
->misc_stats
.rport_not_ready
);
454 sc
->result
= DID_NO_CONNECT
<<16;
459 if (rp
->rp_state
!= RPORT_ST_READY
) {
460 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
461 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
462 "rport 0x%x in state 0x%x, returning DID_IMM_RETRY\n",
463 rport
->port_id
, rp
->rp_state
);
465 sc
->result
= DID_IMM_RETRY
<< 16;
470 if (lp
->state
!= LPORT_ST_READY
|| !(lp
->link_up
)) {
471 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
472 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
473 "state not ready: %d/link not up: %d Returning HOST_BUSY\n",
474 lp
->state
, lp
->link_up
);
475 return SCSI_MLQUEUE_HOST_BUSY
;
478 atomic_inc(&fnic
->in_flight
);
480 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
481 fnic_priv(sc
)->state
= FNIC_IOREQ_NOT_INITED
;
482 fnic_priv(sc
)->flags
= FNIC_NO_FLAGS
;
484 /* Get a new io_req for this SCSI IO */
485 io_req
= mempool_alloc(fnic
->io_req_pool
, GFP_ATOMIC
);
487 atomic64_inc(&fnic_stats
->io_stats
.alloc_failures
);
488 ret
= SCSI_MLQUEUE_HOST_BUSY
;
491 memset(io_req
, 0, sizeof(*io_req
));
493 /* Map the data buffer */
494 sg_count
= scsi_dma_map(sc
);
496 FNIC_TRACE(fnic_queuecommand
, sc
->device
->host
->host_no
,
497 mqtag
, sc
, 0, sc
->cmnd
[0], sg_count
, fnic_priv(sc
)->state
);
498 mempool_free(io_req
, fnic
->io_req_pool
);
502 /* Determine the type of scatter/gather list we need */
503 io_req
->sgl_cnt
= sg_count
;
504 io_req
->sgl_type
= FNIC_SGL_CACHE_DFLT
;
505 if (sg_count
> FNIC_DFLT_SG_DESC_CNT
)
506 io_req
->sgl_type
= FNIC_SGL_CACHE_MAX
;
510 mempool_alloc(fnic
->io_sgl_pool
[io_req
->sgl_type
],
512 if (!io_req
->sgl_list
) {
513 atomic64_inc(&fnic_stats
->io_stats
.alloc_failures
);
514 ret
= SCSI_MLQUEUE_HOST_BUSY
;
516 mempool_free(io_req
, fnic
->io_req_pool
);
520 /* Cache sgl list allocated address before alignment */
521 io_req
->sgl_list_alloc
= io_req
->sgl_list
;
522 ptr
= (unsigned long) io_req
->sgl_list
;
523 if (ptr
% FNIC_SG_DESC_ALIGN
) {
524 io_req
->sgl_list
= (struct host_sg_desc
*)
525 (((unsigned long) ptr
526 + FNIC_SG_DESC_ALIGN
- 1)
527 & ~(FNIC_SG_DESC_ALIGN
- 1));
532 * Will acquire lock before setting to IO initialized.
534 hwq
= blk_mq_unique_tag_to_hwq(mqtag
);
535 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
537 /* initialize rest of io_req */
538 io_lock_acquired
= 1;
539 io_req
->port_id
= rport
->port_id
;
540 io_req
->start_time
= jiffies
;
541 fnic_priv(sc
)->state
= FNIC_IOREQ_CMD_PENDING
;
542 fnic_priv(sc
)->io_req
= io_req
;
543 fnic_priv(sc
)->flags
|= FNIC_IO_INITIALIZED
;
546 if (fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(mqtag
)] != NULL
) {
547 WARN(1, "fnic<%d>: %s: hwq: %d tag 0x%x already exists\n",
548 fnic
->fnic_num
, __func__
, hwq
, blk_mq_unique_tag_to_tag(mqtag
));
549 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
550 return SCSI_MLQUEUE_HOST_BUSY
;
553 fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(mqtag
)] = io_req
;
556 /* create copy wq desc and enqueue it */
557 wq
= &fnic
->hw_copy_wq
[hwq
];
558 atomic64_inc(&fnic_stats
->io_stats
.ios
[hwq
]);
559 ret
= fnic_queue_wq_copy_desc(fnic
, wq
, io_req
, sc
, sg_count
, mqtag
, hwq
);
562 * In case another thread cancelled the request,
563 * refetch the pointer under the lock.
565 FNIC_TRACE(fnic_queuecommand
, sc
->device
->host
->host_no
,
566 mqtag
, sc
, 0, 0, 0, fnic_flags_and_state(sc
));
567 io_req
= fnic_priv(sc
)->io_req
;
568 fnic_priv(sc
)->io_req
= NULL
;
570 fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(mqtag
)] = NULL
;
571 fnic_priv(sc
)->state
= FNIC_IOREQ_CMD_COMPLETE
;
572 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
574 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
575 mempool_free(io_req
, fnic
->io_req_pool
);
577 atomic_dec(&fnic
->in_flight
);
580 atomic64_inc(&fnic_stats
->io_stats
.active_ios
);
581 atomic64_inc(&fnic_stats
->io_stats
.num_ios
);
582 if (atomic64_read(&fnic_stats
->io_stats
.active_ios
) >
583 atomic64_read(&fnic_stats
->io_stats
.max_active_ios
))
584 atomic64_set(&fnic_stats
->io_stats
.max_active_ios
,
585 atomic64_read(&fnic_stats
->io_stats
.active_ios
));
587 /* REVISIT: Use per IO lock in the final code */
588 fnic_priv(sc
)->flags
|= FNIC_IO_ISSUED
;
591 cmd_trace
= ((u64
)sc
->cmnd
[0] << 56 | (u64
)sc
->cmnd
[7] << 40 |
592 (u64
)sc
->cmnd
[8] << 32 | (u64
)sc
->cmnd
[2] << 24 |
593 (u64
)sc
->cmnd
[3] << 16 | (u64
)sc
->cmnd
[4] << 8 |
596 FNIC_TRACE(fnic_queuecommand
, sc
->device
->host
->host_no
,
597 mqtag
, sc
, io_req
, sg_count
, cmd_trace
,
598 fnic_flags_and_state(sc
));
600 /* if only we issued IO, will we have the io lock */
601 if (io_lock_acquired
)
602 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
604 atomic_dec(&fnic
->in_flight
);
610 * fnic_fcpio_fw_reset_cmpl_handler
611 * Routine to handle fw reset completion
613 static int fnic_fcpio_fw_reset_cmpl_handler(struct fnic
*fnic
,
614 struct fcpio_fw_req
*desc
)
618 struct fcpio_tag tag
;
621 struct reset_stats
*reset_stats
= &fnic
->fnic_stats
.reset_stats
;
623 fcpio_header_dec(&desc
->hdr
, &type
, &hdr_status
, &tag
);
625 atomic64_inc(&reset_stats
->fw_reset_completions
);
627 /* Clean up all outstanding io requests */
628 fnic_cleanup_io(fnic
);
630 atomic64_set(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
, 0);
631 atomic64_set(&fnic
->fnic_stats
.io_stats
.active_ios
, 0);
632 atomic64_set(&fnic
->io_cmpl_skip
, 0);
634 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
636 /* fnic should be in FC_TRANS_ETH_MODE */
637 if (fnic
->state
== FNIC_IN_FC_TRANS_ETH_MODE
) {
638 /* Check status of reset completion */
640 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
641 "reset cmpl success\n");
642 /* Ready to send flogi out */
643 fnic
->state
= FNIC_IN_ETH_MODE
;
645 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
646 "reset failed with header status: %s\n",
647 fnic_fcpio_status_to_str(hdr_status
));
650 * Unable to change to eth mode, cannot send out flogi
651 * Change state to fc mode, so that subsequent Flogi
652 * requests from libFC will cause more attempts to
653 * reset the firmware. Free the cached flogi
655 fnic
->state
= FNIC_IN_FC_MODE
;
656 atomic64_inc(&reset_stats
->fw_reset_failures
);
660 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
661 "Unexpected state while processing reset completion: %s\n",
662 fnic_state_to_str(fnic
->state
));
663 atomic64_inc(&reset_stats
->fw_reset_failures
);
667 /* Thread removing device blocks till firmware reset is complete */
668 if (fnic
->remove_wait
)
669 complete(fnic
->remove_wait
);
672 * If fnic is being removed, or fw reset failed
673 * free the flogi frame. Else, send it out
675 if (fnic
->remove_wait
|| ret
) {
676 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
677 skb_queue_purge(&fnic
->tx_queue
);
678 goto reset_cmpl_handler_end
;
681 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
683 queue_work(fnic_event_queue
, &fnic
->flush_work
);
685 reset_cmpl_handler_end
:
686 fnic_clear_state_flags(fnic
, FNIC_FLAGS_FWRESET
);
692 * fnic_fcpio_flogi_reg_cmpl_handler
693 * Routine to handle flogi register completion
695 static int fnic_fcpio_flogi_reg_cmpl_handler(struct fnic
*fnic
,
696 struct fcpio_fw_req
*desc
)
700 struct fcpio_tag tag
;
704 fcpio_header_dec(&desc
->hdr
, &type
, &hdr_status
, &tag
);
706 /* Update fnic state based on status of flogi reg completion */
707 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
709 if (fnic
->state
== FNIC_IN_ETH_TRANS_FC_MODE
) {
711 /* Check flogi registration completion status */
713 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
714 "flog reg succeeded\n");
715 fnic
->state
= FNIC_IN_FC_MODE
;
717 FNIC_SCSI_DBG(KERN_DEBUG
,
718 fnic
->lport
->host
, fnic
->fnic_num
,
719 "fnic flogi reg :failed %s\n",
720 fnic_fcpio_status_to_str(hdr_status
));
721 fnic
->state
= FNIC_IN_ETH_MODE
;
725 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
726 "Unexpected fnic state %s while"
727 " processing flogi reg completion\n",
728 fnic_state_to_str(fnic
->state
));
733 if (fnic
->stop_rx_link_events
) {
734 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
735 goto reg_cmpl_handler_end
;
737 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
739 queue_work(fnic_event_queue
, &fnic
->flush_work
);
740 queue_work(fnic_event_queue
, &fnic
->frame_work
);
742 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
745 reg_cmpl_handler_end
:
749 static inline int is_ack_index_in_range(struct vnic_wq_copy
*wq
,
752 if (wq
->to_clean_index
<= wq
->to_use_index
) {
753 /* out of range, stale request_out index */
754 if (request_out
< wq
->to_clean_index
||
755 request_out
>= wq
->to_use_index
)
758 /* out of range, stale request_out index */
759 if (request_out
< wq
->to_clean_index
&&
760 request_out
>= wq
->to_use_index
)
763 /* request_out index is in range */
769 * Mark that ack received and store the Ack index. If there are multiple
770 * acks received before Tx thread cleans it up, the latest value will be
771 * used which is correct behavior. This state should be in the copy Wq
772 * instead of in the fnic
774 static inline void fnic_fcpio_ack_handler(struct fnic
*fnic
,
775 unsigned int cq_index
,
776 struct fcpio_fw_req
*desc
)
778 struct vnic_wq_copy
*wq
;
779 u16 request_out
= desc
->u
.ack
.request_out
;
781 u64
*ox_id_tag
= (u64
*)(void *)desc
;
782 unsigned int wq_index
= cq_index
;
784 /* mark the ack state */
785 wq
= &fnic
->hw_copy_wq
[cq_index
];
786 spin_lock_irqsave(&fnic
->wq_copy_lock
[wq_index
], flags
);
788 fnic
->fnic_stats
.misc_stats
.last_ack_time
= jiffies
;
789 if (is_ack_index_in_range(wq
, request_out
)) {
790 fnic
->fw_ack_index
[wq_index
] = request_out
;
791 fnic
->fw_ack_recd
[wq_index
] = 1;
794 &fnic
->fnic_stats
.misc_stats
.ack_index_out_of_range
);
796 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[wq_index
], flags
);
797 FNIC_TRACE(fnic_fcpio_ack_handler
,
798 fnic
->lport
->host
->host_no
, 0, 0, ox_id_tag
[2], ox_id_tag
[3],
799 ox_id_tag
[4], ox_id_tag
[5]);
803 * fnic_fcpio_icmnd_cmpl_handler
804 * Routine to handle icmnd completions
806 static void fnic_fcpio_icmnd_cmpl_handler(struct fnic
*fnic
, unsigned int cq_index
,
807 struct fcpio_fw_req
*desc
)
811 struct fcpio_tag ftag
;
814 struct fcpio_icmnd_cmpl
*icmnd_cmpl
;
815 struct fnic_io_req
*io_req
;
816 struct scsi_cmnd
*sc
;
817 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
820 unsigned long start_time
;
821 unsigned long io_duration_time
;
822 unsigned int hwq
= 0;
823 unsigned int mqtag
= 0;
824 unsigned int tag
= 0;
826 /* Decode the cmpl description to get the io_req id */
827 fcpio_header_dec(&desc
->hdr
, &type
, &hdr_status
, &ftag
);
828 fcpio_tag_id_dec(&ftag
, &id
);
829 icmnd_cmpl
= &desc
->u
.icmnd_cmpl
;
832 tag
= blk_mq_unique_tag_to_tag(mqtag
);
833 hwq
= blk_mq_unique_tag_to_hwq(mqtag
);
835 if (hwq
!= cq_index
) {
836 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
837 "hwq: %d mqtag: 0x%x tag: 0x%x cq index: %d ",
838 hwq
, mqtag
, tag
, cq_index
);
839 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
840 "hdr status: %s icmnd completion on the wrong queue\n",
841 fnic_fcpio_status_to_str(hdr_status
));
844 if (tag
>= fnic
->fnic_max_tag_id
) {
845 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
846 "hwq: %d mqtag: 0x%x tag: 0x%x cq index: %d ",
847 hwq
, mqtag
, tag
, cq_index
);
848 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
849 "hdr status: %s Out of range tag\n",
850 fnic_fcpio_status_to_str(hdr_status
));
853 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
855 sc
= scsi_host_find_tag(fnic
->lport
->host
, id
);
858 atomic64_inc(&fnic_stats
->io_stats
.sc_null
);
859 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
860 shost_printk(KERN_ERR
, fnic
->lport
->host
,
861 "icmnd_cmpl sc is null - "
862 "hdr status = %s tag = 0x%x desc = 0x%p\n",
863 fnic_fcpio_status_to_str(hdr_status
), id
, desc
);
864 FNIC_TRACE(fnic_fcpio_icmnd_cmpl_handler
,
865 fnic
->lport
->host
->host_no
, id
,
866 ((u64
)icmnd_cmpl
->_resvd0
[1] << 16 |
867 (u64
)icmnd_cmpl
->_resvd0
[0]),
868 ((u64
)hdr_status
<< 16 |
869 (u64
)icmnd_cmpl
->scsi_status
<< 8 |
870 (u64
)icmnd_cmpl
->flags
), desc
,
871 (u64
)icmnd_cmpl
->residual
, 0);
875 io_req
= fnic_priv(sc
)->io_req
;
876 if (fnic
->sw_copy_wq
[hwq
].io_req_table
[tag
] != io_req
) {
877 WARN(1, "%s: %d: hwq: %d mqtag: 0x%x tag: 0x%x io_req tag mismatch\n",
878 __func__
, __LINE__
, hwq
, mqtag
, tag
);
879 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
883 WARN_ON_ONCE(!io_req
);
885 atomic64_inc(&fnic_stats
->io_stats
.ioreq_null
);
886 fnic_priv(sc
)->flags
|= FNIC_IO_REQ_NULL
;
887 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
888 shost_printk(KERN_ERR
, fnic
->lport
->host
,
889 "icmnd_cmpl io_req is null - "
890 "hdr status = %s tag = 0x%x sc 0x%p\n",
891 fnic_fcpio_status_to_str(hdr_status
), id
, sc
);
894 start_time
= io_req
->start_time
;
896 /* firmware completed the io */
897 io_req
->io_completed
= 1;
900 * if SCSI-ML has already issued abort on this command,
901 * set completion of the IO. The abts path will clean it up
903 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
) {
906 * set the FNIC_IO_DONE so that this doesn't get
907 * flagged as 'out of order' if it was not aborted
909 fnic_priv(sc
)->flags
|= FNIC_IO_DONE
;
910 fnic_priv(sc
)->flags
|= FNIC_IO_ABTS_PENDING
;
911 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
912 if(FCPIO_ABORTED
== hdr_status
)
913 fnic_priv(sc
)->flags
|= FNIC_IO_ABORTED
;
915 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
916 "icmnd_cmpl abts pending "
917 "hdr status = %s tag = 0x%x sc = 0x%p "
918 "scsi_status = %x residual = %d\n",
919 fnic_fcpio_status_to_str(hdr_status
),
921 icmnd_cmpl
->scsi_status
,
922 icmnd_cmpl
->residual
);
926 /* Mark the IO as complete */
927 fnic_priv(sc
)->state
= FNIC_IOREQ_CMD_COMPLETE
;
929 icmnd_cmpl
= &desc
->u
.icmnd_cmpl
;
931 switch (hdr_status
) {
933 sc
->result
= (DID_OK
<< 16) | icmnd_cmpl
->scsi_status
;
934 xfer_len
= scsi_bufflen(sc
);
936 if (icmnd_cmpl
->flags
& FCPIO_ICMND_CMPL_RESID_UNDER
) {
937 xfer_len
-= icmnd_cmpl
->residual
;
938 scsi_set_resid(sc
, icmnd_cmpl
->residual
);
941 if (icmnd_cmpl
->scsi_status
== SAM_STAT_CHECK_CONDITION
)
942 atomic64_inc(&fnic_stats
->misc_stats
.check_condition
);
944 if (icmnd_cmpl
->scsi_status
== SAM_STAT_TASK_SET_FULL
)
945 atomic64_inc(&fnic_stats
->misc_stats
.queue_fulls
);
948 case FCPIO_TIMEOUT
: /* request was timed out */
949 atomic64_inc(&fnic_stats
->misc_stats
.fcpio_timeout
);
950 sc
->result
= (DID_TIME_OUT
<< 16) | icmnd_cmpl
->scsi_status
;
953 case FCPIO_ABORTED
: /* request was aborted */
954 atomic64_inc(&fnic_stats
->misc_stats
.fcpio_aborted
);
955 sc
->result
= (DID_ERROR
<< 16) | icmnd_cmpl
->scsi_status
;
958 case FCPIO_DATA_CNT_MISMATCH
: /* recv/sent more/less data than exp. */
959 atomic64_inc(&fnic_stats
->misc_stats
.data_count_mismatch
);
960 scsi_set_resid(sc
, icmnd_cmpl
->residual
);
961 sc
->result
= (DID_ERROR
<< 16) | icmnd_cmpl
->scsi_status
;
964 case FCPIO_OUT_OF_RESOURCE
: /* out of resources to complete request */
965 atomic64_inc(&fnic_stats
->fw_stats
.fw_out_of_resources
);
966 sc
->result
= (DID_REQUEUE
<< 16) | icmnd_cmpl
->scsi_status
;
969 case FCPIO_IO_NOT_FOUND
: /* requested I/O was not found */
970 atomic64_inc(&fnic_stats
->io_stats
.io_not_found
);
971 sc
->result
= (DID_ERROR
<< 16) | icmnd_cmpl
->scsi_status
;
974 case FCPIO_SGL_INVALID
: /* request was aborted due to sgl error */
975 atomic64_inc(&fnic_stats
->misc_stats
.sgl_invalid
);
976 sc
->result
= (DID_ERROR
<< 16) | icmnd_cmpl
->scsi_status
;
979 case FCPIO_FW_ERR
: /* request was terminated due fw error */
980 atomic64_inc(&fnic_stats
->fw_stats
.io_fw_errs
);
981 sc
->result
= (DID_ERROR
<< 16) | icmnd_cmpl
->scsi_status
;
984 case FCPIO_MSS_INVALID
: /* request was aborted due to mss error */
985 atomic64_inc(&fnic_stats
->misc_stats
.mss_invalid
);
986 sc
->result
= (DID_ERROR
<< 16) | icmnd_cmpl
->scsi_status
;
989 case FCPIO_INVALID_HEADER
: /* header contains invalid data */
990 case FCPIO_INVALID_PARAM
: /* some parameter in request invalid */
991 case FCPIO_REQ_NOT_SUPPORTED
:/* request type is not supported */
993 sc
->result
= (DID_ERROR
<< 16) | icmnd_cmpl
->scsi_status
;
997 /* Break link with the SCSI command */
998 fnic_priv(sc
)->io_req
= NULL
;
1000 fnic_priv(sc
)->flags
|= FNIC_IO_DONE
;
1001 fnic
->sw_copy_wq
[hwq
].io_req_table
[tag
] = NULL
;
1003 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1005 if (hdr_status
!= FCPIO_SUCCESS
) {
1006 atomic64_inc(&fnic_stats
->io_stats
.io_failures
);
1007 shost_printk(KERN_ERR
, fnic
->lport
->host
, "hdr status = %s\n",
1008 fnic_fcpio_status_to_str(hdr_status
));
1011 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
1013 cmd_trace
= ((u64
)hdr_status
<< 56) |
1014 (u64
)icmnd_cmpl
->scsi_status
<< 48 |
1015 (u64
)icmnd_cmpl
->flags
<< 40 | (u64
)sc
->cmnd
[0] << 32 |
1016 (u64
)sc
->cmnd
[2] << 24 | (u64
)sc
->cmnd
[3] << 16 |
1017 (u64
)sc
->cmnd
[4] << 8 | sc
->cmnd
[5];
1019 FNIC_TRACE(fnic_fcpio_icmnd_cmpl_handler
,
1020 sc
->device
->host
->host_no
, id
, sc
,
1021 ((u64
)icmnd_cmpl
->_resvd0
[1] << 56 |
1022 (u64
)icmnd_cmpl
->_resvd0
[0] << 48 |
1023 jiffies_to_msecs(jiffies
- start_time
)),
1024 desc
, cmd_trace
, fnic_flags_and_state(sc
));
1026 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
1027 fnic
->lport
->host_stats
.fcp_input_requests
++;
1028 fnic
->fcp_input_bytes
+= xfer_len
;
1029 } else if (sc
->sc_data_direction
== DMA_TO_DEVICE
) {
1030 fnic
->lport
->host_stats
.fcp_output_requests
++;
1031 fnic
->fcp_output_bytes
+= xfer_len
;
1033 fnic
->lport
->host_stats
.fcp_control_requests
++;
1035 /* Call SCSI completion function to complete the IO */
1038 mempool_free(io_req
, fnic
->io_req_pool
);
1040 atomic64_dec(&fnic_stats
->io_stats
.active_ios
);
1041 if (atomic64_read(&fnic
->io_cmpl_skip
))
1042 atomic64_dec(&fnic
->io_cmpl_skip
);
1044 atomic64_inc(&fnic_stats
->io_stats
.io_completions
);
1047 io_duration_time
= jiffies_to_msecs(jiffies
) -
1048 jiffies_to_msecs(start_time
);
1050 if(io_duration_time
<= 10)
1051 atomic64_inc(&fnic_stats
->io_stats
.io_btw_0_to_10_msec
);
1052 else if(io_duration_time
<= 100)
1053 atomic64_inc(&fnic_stats
->io_stats
.io_btw_10_to_100_msec
);
1054 else if(io_duration_time
<= 500)
1055 atomic64_inc(&fnic_stats
->io_stats
.io_btw_100_to_500_msec
);
1056 else if(io_duration_time
<= 5000)
1057 atomic64_inc(&fnic_stats
->io_stats
.io_btw_500_to_5000_msec
);
1058 else if(io_duration_time
<= 10000)
1059 atomic64_inc(&fnic_stats
->io_stats
.io_btw_5000_to_10000_msec
);
1060 else if(io_duration_time
<= 30000)
1061 atomic64_inc(&fnic_stats
->io_stats
.io_btw_10000_to_30000_msec
);
1063 atomic64_inc(&fnic_stats
->io_stats
.io_greater_than_30000_msec
);
1065 if(io_duration_time
> atomic64_read(&fnic_stats
->io_stats
.current_max_io_time
))
1066 atomic64_set(&fnic_stats
->io_stats
.current_max_io_time
, io_duration_time
);
1070 /* fnic_fcpio_itmf_cmpl_handler
1071 * Routine to handle itmf completions
1073 static void fnic_fcpio_itmf_cmpl_handler(struct fnic
*fnic
, unsigned int cq_index
,
1074 struct fcpio_fw_req
*desc
)
1078 struct fcpio_tag ftag
;
1080 struct scsi_cmnd
*sc
= NULL
;
1081 struct fnic_io_req
*io_req
;
1082 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
1083 struct abort_stats
*abts_stats
= &fnic
->fnic_stats
.abts_stats
;
1084 struct terminate_stats
*term_stats
= &fnic
->fnic_stats
.term_stats
;
1085 struct misc_stats
*misc_stats
= &fnic
->fnic_stats
.misc_stats
;
1086 unsigned long flags
;
1087 unsigned long start_time
;
1088 unsigned int hwq
= cq_index
;
1092 fcpio_header_dec(&desc
->hdr
, &type
, &hdr_status
, &ftag
);
1093 fcpio_tag_id_dec(&ftag
, &id
);
1095 mqtag
= id
& FNIC_TAG_MASK
;
1096 tag
= blk_mq_unique_tag_to_tag(id
& FNIC_TAG_MASK
);
1097 hwq
= blk_mq_unique_tag_to_hwq(id
& FNIC_TAG_MASK
);
1099 if (hwq
!= cq_index
) {
1100 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1101 "hwq: %d mqtag: 0x%x tag: 0x%x cq index: %d ",
1102 hwq
, mqtag
, tag
, cq_index
);
1103 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1104 "hdr status: %s ITMF completion on the wrong queue\n",
1105 fnic_fcpio_status_to_str(hdr_status
));
1108 if (tag
> fnic
->fnic_max_tag_id
) {
1109 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1110 "hwq: %d mqtag: 0x%x tag: 0x%x cq index: %d ",
1111 hwq
, mqtag
, tag
, cq_index
);
1112 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1113 "hdr status: %s Tag out of range\n",
1114 fnic_fcpio_status_to_str(hdr_status
));
1116 } else if ((tag
== fnic
->fnic_max_tag_id
) && !(id
& FNIC_TAG_DEV_RST
)) {
1117 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1118 "hwq: %d mqtag: 0x%x tag: 0x%x cq index: %d ",
1119 hwq
, mqtag
, tag
, cq_index
);
1120 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1121 "hdr status: %s Tag out of range\n",
1122 fnic_fcpio_status_to_str(hdr_status
));
1126 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1128 /* If it is sg3utils allocated SC then tag_id
1129 * is max_tag_id and SC is retrieved from io_req
1131 if ((mqtag
== fnic
->fnic_max_tag_id
) && (id
& FNIC_TAG_DEV_RST
)) {
1132 io_req
= fnic
->sw_copy_wq
[hwq
].io_req_table
[tag
];
1136 sc
= scsi_host_find_tag(fnic
->lport
->host
, id
& FNIC_TAG_MASK
);
1141 atomic64_inc(&fnic_stats
->io_stats
.sc_null
);
1142 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1143 shost_printk(KERN_ERR
, fnic
->lport
->host
,
1144 "itmf_cmpl sc is null - hdr status = %s tag = 0x%x\n",
1145 fnic_fcpio_status_to_str(hdr_status
), tag
);
1149 io_req
= fnic_priv(sc
)->io_req
;
1150 WARN_ON_ONCE(!io_req
);
1152 atomic64_inc(&fnic_stats
->io_stats
.ioreq_null
);
1153 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1154 fnic_priv(sc
)->flags
|= FNIC_IO_ABT_TERM_REQ_NULL
;
1155 shost_printk(KERN_ERR
, fnic
->lport
->host
,
1156 "itmf_cmpl io_req is null - "
1157 "hdr status = %s tag = 0x%x sc 0x%p\n",
1158 fnic_fcpio_status_to_str(hdr_status
), tag
, sc
);
1161 start_time
= io_req
->start_time
;
1163 if ((id
& FNIC_TAG_ABORT
) && (id
& FNIC_TAG_DEV_RST
)) {
1164 /* Abort and terminate completion of device reset req */
1165 /* REVISIT : Add asserts about various flags */
1166 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
1167 "hwq: %d mqtag: 0x%x tag: 0x%x hst: %s Abt/term completion received\n",
1169 fnic_fcpio_status_to_str(hdr_status
));
1170 fnic_priv(sc
)->state
= FNIC_IOREQ_ABTS_COMPLETE
;
1171 fnic_priv(sc
)->abts_status
= hdr_status
;
1172 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_DONE
;
1173 if (io_req
->abts_done
)
1174 complete(io_req
->abts_done
);
1175 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1176 } else if (id
& FNIC_TAG_ABORT
) {
1177 /* Completion of abort cmd */
1178 shost_printk(KERN_DEBUG
, fnic
->lport
->host
,
1179 "hwq: %d mqtag: 0x%x tag: 0x%x Abort header status: %s\n",
1181 fnic_fcpio_status_to_str(hdr_status
));
1182 switch (hdr_status
) {
1186 if (fnic_priv(sc
)->flags
& FNIC_IO_ABTS_ISSUED
)
1187 atomic64_inc(&abts_stats
->abort_fw_timeouts
);
1190 &term_stats
->terminate_fw_timeouts
);
1192 case FCPIO_ITMF_REJECTED
:
1193 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
1194 "abort reject recd. id %d\n",
1195 (int)(id
& FNIC_TAG_MASK
));
1197 case FCPIO_IO_NOT_FOUND
:
1198 if (fnic_priv(sc
)->flags
& FNIC_IO_ABTS_ISSUED
)
1199 atomic64_inc(&abts_stats
->abort_io_not_found
);
1202 &term_stats
->terminate_io_not_found
);
1205 if (fnic_priv(sc
)->flags
& FNIC_IO_ABTS_ISSUED
)
1206 atomic64_inc(&abts_stats
->abort_failures
);
1209 &term_stats
->terminate_failures
);
1212 if (fnic_priv(sc
)->state
!= FNIC_IOREQ_ABTS_PENDING
) {
1213 /* This is a late completion. Ignore it */
1214 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1218 fnic_priv(sc
)->flags
|= FNIC_IO_ABT_TERM_DONE
;
1219 fnic_priv(sc
)->abts_status
= hdr_status
;
1221 /* If the status is IO not found consider it as success */
1222 if (hdr_status
== FCPIO_IO_NOT_FOUND
)
1223 fnic_priv(sc
)->abts_status
= FCPIO_SUCCESS
;
1225 if (!(fnic_priv(sc
)->flags
& (FNIC_IO_ABORTED
| FNIC_IO_DONE
)))
1226 atomic64_inc(&misc_stats
->no_icmnd_itmf_cmpls
);
1228 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1229 "abts cmpl recd. id %d status %s\n",
1230 (int)(id
& FNIC_TAG_MASK
),
1231 fnic_fcpio_status_to_str(hdr_status
));
1234 * If scsi_eh thread is blocked waiting for abts to complete,
1235 * signal completion to it. IO will be cleaned in the thread
1236 * else clean it in this context
1238 if (io_req
->abts_done
) {
1239 complete(io_req
->abts_done
);
1240 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1241 shost_printk(KERN_INFO
, fnic
->lport
->host
,
1242 "hwq: %d mqtag: 0x%x tag: 0x%x Waking up abort thread\n",
1245 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1246 "hwq: %d mqtag: 0x%x tag: 0x%x hst: %s Completing IO\n",
1248 tag
, fnic_fcpio_status_to_str(hdr_status
));
1249 fnic_priv(sc
)->io_req
= NULL
;
1250 sc
->result
= (DID_ERROR
<< 16);
1251 fnic
->sw_copy_wq
[hwq
].io_req_table
[tag
] = NULL
;
1252 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1254 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
1255 mempool_free(io_req
, fnic
->io_req_pool
);
1256 FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler
,
1257 sc
->device
->host
->host_no
, id
,
1259 jiffies_to_msecs(jiffies
- start_time
),
1261 (((u64
)hdr_status
<< 40) |
1262 (u64
)sc
->cmnd
[0] << 32 |
1263 (u64
)sc
->cmnd
[2] << 24 |
1264 (u64
)sc
->cmnd
[3] << 16 |
1265 (u64
)sc
->cmnd
[4] << 8 | sc
->cmnd
[5]),
1266 fnic_flags_and_state(sc
));
1268 atomic64_dec(&fnic_stats
->io_stats
.active_ios
);
1269 if (atomic64_read(&fnic
->io_cmpl_skip
))
1270 atomic64_dec(&fnic
->io_cmpl_skip
);
1272 atomic64_inc(&fnic_stats
->io_stats
.io_completions
);
1274 } else if (id
& FNIC_TAG_DEV_RST
) {
1275 /* Completion of device reset */
1276 shost_printk(KERN_INFO
, fnic
->lport
->host
,
1277 "hwq: %d mqtag: 0x%x tag: 0x%x DR hst: %s\n",
1279 tag
, fnic_fcpio_status_to_str(hdr_status
));
1280 fnic_priv(sc
)->lr_status
= hdr_status
;
1281 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
) {
1282 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1283 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_ABTS_PENDING
;
1284 FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler
,
1285 sc
->device
->host
->host_no
, id
, sc
,
1286 jiffies_to_msecs(jiffies
- start_time
),
1287 desc
, 0, fnic_flags_and_state(sc
));
1288 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1289 "hwq: %d mqtag: 0x%x tag: 0x%x hst: %s Terminate pending\n",
1291 tag
, fnic_fcpio_status_to_str(hdr_status
));
1294 if (fnic_priv(sc
)->flags
& FNIC_DEV_RST_TIMED_OUT
) {
1295 /* Need to wait for terminate completion */
1296 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1297 FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler
,
1298 sc
->device
->host
->host_no
, id
, sc
,
1299 jiffies_to_msecs(jiffies
- start_time
),
1300 desc
, 0, fnic_flags_and_state(sc
));
1301 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1302 "dev reset cmpl recd after time out. "
1303 "id %d status %s\n",
1304 (int)(id
& FNIC_TAG_MASK
),
1305 fnic_fcpio_status_to_str(hdr_status
));
1308 fnic_priv(sc
)->state
= FNIC_IOREQ_CMD_COMPLETE
;
1309 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_DONE
;
1310 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
1311 "hwq: %d mqtag: 0x%x tag: 0x%x hst: %s DR completion received\n",
1313 tag
, fnic_fcpio_status_to_str(hdr_status
));
1314 if (io_req
->dr_done
)
1315 complete(io_req
->dr_done
);
1316 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1319 shost_printk(KERN_ERR
, fnic
->lport
->host
,
1320 "%s: Unexpected itmf io state: hwq: %d tag 0x%x %s\n",
1321 __func__
, hwq
, id
, fnic_ioreq_state_to_str(fnic_priv(sc
)->state
));
1322 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1328 * fnic_fcpio_cmpl_handler
1329 * Routine to service the cq for wq_copy
1331 static int fnic_fcpio_cmpl_handler(struct vnic_dev
*vdev
,
1332 unsigned int cq_index
,
1333 struct fcpio_fw_req
*desc
)
1335 struct fnic
*fnic
= vnic_dev_priv(vdev
);
1337 switch (desc
->hdr
.type
) {
1338 case FCPIO_ICMND_CMPL
: /* fw completed a command */
1339 case FCPIO_ITMF_CMPL
: /* fw completed itmf (abort cmd, lun reset)*/
1340 case FCPIO_FLOGI_REG_CMPL
: /* fw completed flogi_reg */
1341 case FCPIO_FLOGI_FIP_REG_CMPL
: /* fw completed flogi_fip_reg */
1342 case FCPIO_RESET_CMPL
: /* fw completed reset */
1343 atomic64_dec(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
);
1349 cq_index
-= fnic
->copy_wq_base
;
1351 switch (desc
->hdr
.type
) {
1352 case FCPIO_ACK
: /* fw copied copy wq desc to its queue */
1353 fnic_fcpio_ack_handler(fnic
, cq_index
, desc
);
1356 case FCPIO_ICMND_CMPL
: /* fw completed a command */
1357 fnic_fcpio_icmnd_cmpl_handler(fnic
, cq_index
, desc
);
1360 case FCPIO_ITMF_CMPL
: /* fw completed itmf (abort cmd, lun reset)*/
1361 fnic_fcpio_itmf_cmpl_handler(fnic
, cq_index
, desc
);
1364 case FCPIO_FLOGI_REG_CMPL
: /* fw completed flogi_reg */
1365 case FCPIO_FLOGI_FIP_REG_CMPL
: /* fw completed flogi_fip_reg */
1366 fnic_fcpio_flogi_reg_cmpl_handler(fnic
, desc
);
1369 case FCPIO_RESET_CMPL
: /* fw completed reset */
1370 fnic_fcpio_fw_reset_cmpl_handler(fnic
, desc
);
1374 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1375 "firmware completion type %d\n",
1384 * fnic_wq_copy_cmpl_handler
1385 * Routine to process wq copy
1387 int fnic_wq_copy_cmpl_handler(struct fnic
*fnic
, int copy_work_to_do
, unsigned int cq_index
)
1389 unsigned int cur_work_done
;
1390 struct misc_stats
*misc_stats
= &fnic
->fnic_stats
.misc_stats
;
1391 u64 start_jiffies
= 0;
1392 u64 end_jiffies
= 0;
1393 u64 delta_jiffies
= 0;
1396 start_jiffies
= jiffies
;
1397 cur_work_done
= vnic_cq_copy_service(&fnic
->cq
[cq_index
],
1398 fnic_fcpio_cmpl_handler
,
1400 end_jiffies
= jiffies
;
1401 delta_jiffies
= end_jiffies
- start_jiffies
;
1402 if (delta_jiffies
> (u64
) atomic64_read(&misc_stats
->max_isr_jiffies
)) {
1403 atomic64_set(&misc_stats
->max_isr_jiffies
, delta_jiffies
);
1404 delta_ms
= jiffies_to_msecs(delta_jiffies
);
1405 atomic64_set(&misc_stats
->max_isr_time_ms
, delta_ms
);
1406 atomic64_set(&misc_stats
->corr_work_done
, cur_work_done
);
1409 return cur_work_done
;
1412 static bool fnic_cleanup_io_iter(struct scsi_cmnd
*sc
, void *data
)
1414 struct request
*const rq
= scsi_cmd_to_rq(sc
);
1415 struct fnic
*fnic
= data
;
1416 struct fnic_io_req
*io_req
;
1417 unsigned long flags
= 0;
1418 unsigned long start_time
= 0;
1419 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
1424 mqtag
= blk_mq_unique_tag(rq
);
1425 hwq
= blk_mq_unique_tag_to_hwq(mqtag
);
1426 tag
= blk_mq_unique_tag_to_tag(mqtag
);
1428 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1430 fnic
->sw_copy_wq
[hwq
].io_req_table
[tag
] = NULL
;
1432 io_req
= fnic_priv(sc
)->io_req
;
1434 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1435 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1436 "hwq: %d mqtag: 0x%x tag: 0x%x flags: 0x%x No ioreq. Returning\n",
1437 hwq
, mqtag
, tag
, fnic_priv(sc
)->flags
);
1441 if ((fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
) &&
1442 !(fnic_priv(sc
)->flags
& FNIC_DEV_RST_DONE
)) {
1444 * We will be here only when FW completes reset
1445 * without sending completions for outstanding ios.
1447 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_DONE
;
1448 if (io_req
&& io_req
->dr_done
)
1449 complete(io_req
->dr_done
);
1450 else if (io_req
&& io_req
->abts_done
)
1451 complete(io_req
->abts_done
);
1452 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1454 } else if (fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
) {
1455 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1459 fnic_priv(sc
)->io_req
= NULL
;
1461 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1464 * If there is a scsi_cmnd associated with this io_req, then
1465 * free the corresponding state
1467 start_time
= io_req
->start_time
;
1468 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
1469 mempool_free(io_req
, fnic
->io_req_pool
);
1471 sc
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
1472 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1473 "mqtag:0x%x tag: 0x%x sc:0x%p duration = %lu DID_TRANSPORT_DISRUPTED\n",
1474 mqtag
, tag
, sc
, (jiffies
- start_time
));
1476 if (atomic64_read(&fnic
->io_cmpl_skip
))
1477 atomic64_dec(&fnic
->io_cmpl_skip
);
1479 atomic64_inc(&fnic_stats
->io_stats
.io_completions
);
1481 FNIC_TRACE(fnic_cleanup_io
,
1482 sc
->device
->host
->host_no
, tag
, sc
,
1483 jiffies_to_msecs(jiffies
- start_time
),
1484 0, ((u64
)sc
->cmnd
[0] << 32 |
1485 (u64
)sc
->cmnd
[2] << 24 |
1486 (u64
)sc
->cmnd
[3] << 16 |
1487 (u64
)sc
->cmnd
[4] << 8 | sc
->cmnd
[5]),
1488 fnic_flags_and_state(sc
));
1495 static void fnic_cleanup_io(struct fnic
*fnic
)
1497 scsi_host_busy_iter(fnic
->lport
->host
,
1498 fnic_cleanup_io_iter
, fnic
);
1501 void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy
*wq
,
1502 struct fcpio_host_req
*desc
)
1505 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1506 struct fnic_io_req
*io_req
;
1507 struct scsi_cmnd
*sc
;
1508 unsigned long flags
;
1509 unsigned long start_time
= 0;
1512 /* get the tag reference */
1513 fcpio_tag_id_dec(&desc
->hdr
.tag
, &id
);
1514 id
&= FNIC_TAG_MASK
;
1516 if (id
>= fnic
->fnic_max_tag_id
)
1519 sc
= scsi_host_find_tag(fnic
->lport
->host
, id
);
1523 hwq
= blk_mq_unique_tag_to_hwq(id
);
1524 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1526 /* Get the IO context which this desc refers to */
1527 io_req
= fnic_priv(sc
)->io_req
;
1529 /* fnic interrupts are turned off by now */
1532 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1533 goto wq_copy_cleanup_scsi_cmd
;
1536 fnic_priv(sc
)->io_req
= NULL
;
1538 fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(id
)] = NULL
;
1540 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1542 start_time
= io_req
->start_time
;
1543 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
1544 mempool_free(io_req
, fnic
->io_req_pool
);
1546 wq_copy_cleanup_scsi_cmd
:
1547 sc
->result
= DID_NO_CONNECT
<< 16;
1548 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
, "wq_copy_cleanup_handler:"
1549 " DID_NO_CONNECT\n");
1551 FNIC_TRACE(fnic_wq_copy_cleanup_handler
,
1552 sc
->device
->host
->host_no
, id
, sc
,
1553 jiffies_to_msecs(jiffies
- start_time
),
1554 0, ((u64
)sc
->cmnd
[0] << 32 |
1555 (u64
)sc
->cmnd
[2] << 24 | (u64
)sc
->cmnd
[3] << 16 |
1556 (u64
)sc
->cmnd
[4] << 8 | sc
->cmnd
[5]),
1557 fnic_flags_and_state(sc
));
1562 static inline int fnic_queue_abort_io_req(struct fnic
*fnic
, int tag
,
1563 u32 task_req
, u8
*fc_lun
,
1564 struct fnic_io_req
*io_req
,
1567 struct vnic_wq_copy
*wq
= &fnic
->hw_copy_wq
[hwq
];
1568 struct misc_stats
*misc_stats
= &fnic
->fnic_stats
.misc_stats
;
1569 unsigned long flags
;
1571 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1572 if (unlikely(fnic_chk_state_flags_locked(fnic
,
1573 FNIC_FLAGS_IO_BLOCKED
))) {
1574 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1577 atomic_inc(&fnic
->in_flight
);
1578 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1580 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1582 if (vnic_wq_copy_desc_avail(wq
) <= fnic
->wq_copy_desc_low
[hwq
])
1583 free_wq_copy_descs(fnic
, wq
, hwq
);
1585 if (!vnic_wq_copy_desc_avail(wq
)) {
1586 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1587 atomic_dec(&fnic
->in_flight
);
1588 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1589 "fnic_queue_abort_io_req: failure: no descriptors\n");
1590 atomic64_inc(&misc_stats
->abts_cpwq_alloc_failures
);
1593 fnic_queue_wq_copy_desc_itmf(wq
, tag
| FNIC_TAG_ABORT
,
1594 0, task_req
, tag
, fc_lun
, io_req
->port_id
,
1595 fnic
->config
.ra_tov
, fnic
->config
.ed_tov
);
1597 atomic64_inc(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
);
1598 if (atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
) >
1599 atomic64_read(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
))
1600 atomic64_set(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
,
1601 atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
));
1603 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1604 atomic_dec(&fnic
->in_flight
);
1609 struct fnic_rport_abort_io_iter_data
{
1615 static bool fnic_rport_abort_io_iter(struct scsi_cmnd
*sc
, void *data
)
1617 struct request
*const rq
= scsi_cmd_to_rq(sc
);
1618 struct fnic_rport_abort_io_iter_data
*iter_data
= data
;
1619 struct fnic
*fnic
= iter_data
->fnic
;
1621 struct fnic_io_req
*io_req
;
1622 unsigned long flags
;
1623 struct reset_stats
*reset_stats
= &fnic
->fnic_stats
.reset_stats
;
1624 struct terminate_stats
*term_stats
= &fnic
->fnic_stats
.term_stats
;
1625 struct scsi_lun fc_lun
;
1626 enum fnic_ioreq_state old_ioreq_state
;
1629 abt_tag
= blk_mq_unique_tag(rq
);
1630 hwq
= blk_mq_unique_tag_to_hwq(abt_tag
);
1632 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1634 io_req
= fnic_priv(sc
)->io_req
;
1636 if (!io_req
|| io_req
->port_id
!= iter_data
->port_id
) {
1637 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1641 if ((fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
) &&
1642 !(fnic_priv(sc
)->flags
& FNIC_DEV_RST_ISSUED
)) {
1643 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1644 "hwq: %d abt_tag: 0x%x flags: 0x%x Device reset is not pending\n",
1645 hwq
, abt_tag
, fnic_priv(sc
)->flags
);
1646 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1651 * Found IO that is still pending with firmware and
1652 * belongs to rport that went away
1654 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
) {
1655 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1658 if (io_req
->abts_done
) {
1659 shost_printk(KERN_ERR
, fnic
->lport
->host
,
1660 "fnic_rport_exch_reset: io_req->abts_done is set "
1662 fnic_ioreq_state_to_str(fnic_priv(sc
)->state
));
1665 if (!(fnic_priv(sc
)->flags
& FNIC_IO_ISSUED
)) {
1666 shost_printk(KERN_ERR
, fnic
->lport
->host
,
1668 "IO not yet issued %p tag 0x%x flags "
1670 sc
, abt_tag
, fnic_priv(sc
)->flags
, fnic_priv(sc
)->state
);
1672 old_ioreq_state
= fnic_priv(sc
)->state
;
1673 fnic_priv(sc
)->state
= FNIC_IOREQ_ABTS_PENDING
;
1674 fnic_priv(sc
)->abts_status
= FCPIO_INVALID_CODE
;
1675 if (fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
) {
1676 atomic64_inc(&reset_stats
->device_reset_terminates
);
1677 abt_tag
|= FNIC_TAG_DEV_RST
;
1679 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1680 "fnic_rport_exch_reset dev rst sc 0x%p\n", sc
);
1681 BUG_ON(io_req
->abts_done
);
1683 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1684 "fnic_rport_reset_exch: Issuing abts\n");
1686 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1688 /* Now queue the abort command to firmware */
1689 int_to_scsilun(sc
->device
->lun
, &fc_lun
);
1691 if (fnic_queue_abort_io_req(fnic
, abt_tag
,
1692 FCPIO_ITMF_ABT_TASK_TERM
,
1693 fc_lun
.scsi_lun
, io_req
, hwq
)) {
1695 * Revert the cmd state back to old state, if
1696 * it hasn't changed in between. This cmd will get
1697 * aborted later by scsi_eh, or cleaned up during
1700 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1701 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1702 "hwq: %d abt_tag: 0x%x flags: 0x%x Queuing abort failed\n",
1703 hwq
, abt_tag
, fnic_priv(sc
)->flags
);
1704 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
)
1705 fnic_priv(sc
)->state
= old_ioreq_state
;
1706 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1708 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1709 if (fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
)
1710 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_TERM_ISSUED
;
1712 fnic_priv(sc
)->flags
|= FNIC_IO_INTERNAL_TERM_ISSUED
;
1713 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1714 atomic64_inc(&term_stats
->terminates
);
1715 iter_data
->term_cnt
++;
1720 static void fnic_rport_exch_reset(struct fnic
*fnic
, u32 port_id
)
1722 struct terminate_stats
*term_stats
= &fnic
->fnic_stats
.term_stats
;
1723 struct fnic_rport_abort_io_iter_data iter_data
= {
1729 FNIC_SCSI_DBG(KERN_DEBUG
,
1730 fnic
->lport
->host
, fnic
->fnic_num
,
1731 "fnic_rport_exch_reset called portid 0x%06x\n",
1734 if (fnic
->in_remove
)
1737 scsi_host_busy_iter(fnic
->lport
->host
, fnic_rport_abort_io_iter
,
1739 if (iter_data
.term_cnt
> atomic64_read(&term_stats
->max_terminates
))
1740 atomic64_set(&term_stats
->max_terminates
, iter_data
.term_cnt
);
1744 void fnic_terminate_rport_io(struct fc_rport
*rport
)
1746 struct fc_rport_libfc_priv
*rdata
;
1747 struct fc_lport
*lport
;
1751 printk(KERN_ERR
"fnic_terminate_rport_io: rport is NULL\n");
1754 rdata
= rport
->dd_data
;
1757 printk(KERN_ERR
"fnic_terminate_rport_io: rdata is NULL\n");
1760 lport
= rdata
->local_port
;
1763 printk(KERN_ERR
"fnic_terminate_rport_io: lport is NULL\n");
1766 fnic
= lport_priv(lport
);
1767 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1768 "wwpn 0x%llx, wwnn0x%llx, rport 0x%p, portid 0x%06x\n",
1769 rport
->port_name
, rport
->node_name
, rport
,
1772 if (fnic
->in_remove
)
1775 fnic_rport_exch_reset(fnic
, rport
->port_id
);
1779 * This function is exported to SCSI for sending abort cmnds.
1780 * A SCSI IO is represented by a io_req in the driver.
1781 * The ioreq is linked to the SCSI Cmd, thus a link with the ULP's IO.
1783 int fnic_abort_cmd(struct scsi_cmnd
*sc
)
1785 struct request
*const rq
= scsi_cmd_to_rq(sc
);
1786 struct fc_lport
*lp
;
1788 struct fnic_io_req
*io_req
= NULL
;
1789 struct fc_rport
*rport
;
1790 unsigned long flags
;
1791 unsigned long start_time
= 0;
1794 struct scsi_lun fc_lun
;
1795 struct fnic_stats
*fnic_stats
;
1796 struct abort_stats
*abts_stats
;
1797 struct terminate_stats
*term_stats
;
1798 enum fnic_ioreq_state old_ioreq_state
;
1800 unsigned long abt_issued_time
;
1803 DECLARE_COMPLETION_ONSTACK(tm_done
);
1805 /* Wait for rport to unblock */
1806 fc_block_scsi_eh(sc
);
1808 /* Get local-port, check ready and link up */
1809 lp
= shost_priv(sc
->device
->host
);
1811 fnic
= lport_priv(lp
);
1813 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1814 fnic_stats
= &fnic
->fnic_stats
;
1815 abts_stats
= &fnic
->fnic_stats
.abts_stats
;
1816 term_stats
= &fnic
->fnic_stats
.term_stats
;
1818 rport
= starget_to_rport(scsi_target(sc
->device
));
1819 mqtag
= blk_mq_unique_tag(rq
);
1820 hwq
= blk_mq_unique_tag_to_hwq(mqtag
);
1822 fnic_priv(sc
)->flags
= FNIC_NO_FLAGS
;
1824 if (lp
->state
!= LPORT_ST_READY
|| !(lp
->link_up
)) {
1826 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1827 goto fnic_abort_cmd_end
;
1830 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1832 * Avoid a race between SCSI issuing the abort and the device
1833 * completing the command.
1835 * If the command is already completed by the fw cmpl code,
1836 * we just return SUCCESS from here. This means that the abort
1837 * succeeded. In the SCSI ML, since the timeout for command has
1838 * happened, the completion wont actually complete the command
1839 * and it will be considered as an aborted command
1841 * .io_req will not be cleared except while holding io_req_lock.
1843 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1844 io_req
= fnic_priv(sc
)->io_req
;
1846 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1847 goto fnic_abort_cmd_end
;
1850 io_req
->abts_done
= &tm_done
;
1852 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
) {
1853 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1857 abt_issued_time
= jiffies_to_msecs(jiffies
) - jiffies_to_msecs(io_req
->start_time
);
1858 if (abt_issued_time
<= 6000)
1859 atomic64_inc(&abts_stats
->abort_issued_btw_0_to_6_sec
);
1860 else if (abt_issued_time
> 6000 && abt_issued_time
<= 20000)
1861 atomic64_inc(&abts_stats
->abort_issued_btw_6_to_20_sec
);
1862 else if (abt_issued_time
> 20000 && abt_issued_time
<= 30000)
1863 atomic64_inc(&abts_stats
->abort_issued_btw_20_to_30_sec
);
1864 else if (abt_issued_time
> 30000 && abt_issued_time
<= 40000)
1865 atomic64_inc(&abts_stats
->abort_issued_btw_30_to_40_sec
);
1866 else if (abt_issued_time
> 40000 && abt_issued_time
<= 50000)
1867 atomic64_inc(&abts_stats
->abort_issued_btw_40_to_50_sec
);
1868 else if (abt_issued_time
> 50000 && abt_issued_time
<= 60000)
1869 atomic64_inc(&abts_stats
->abort_issued_btw_50_to_60_sec
);
1871 atomic64_inc(&abts_stats
->abort_issued_greater_than_60_sec
);
1873 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1874 "CDB Opcode: 0x%02x Abort issued time: %lu msec\n",
1875 sc
->cmnd
[0], abt_issued_time
);
1877 * Command is still pending, need to abort it
1878 * If the firmware completes the command after this point,
1879 * the completion wont be done till mid-layer, since abort
1880 * has already started.
1882 old_ioreq_state
= fnic_priv(sc
)->state
;
1883 fnic_priv(sc
)->state
= FNIC_IOREQ_ABTS_PENDING
;
1884 fnic_priv(sc
)->abts_status
= FCPIO_INVALID_CODE
;
1886 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1889 * Check readiness of the remote port. If the path to remote
1890 * port is up, then send abts to the remote port to terminate
1891 * the IO. Else, just locally terminate the IO in the firmware
1893 if (fc_remote_port_chkready(rport
) == 0)
1894 task_req
= FCPIO_ITMF_ABT_TASK
;
1896 atomic64_inc(&fnic_stats
->misc_stats
.rport_not_ready
);
1897 task_req
= FCPIO_ITMF_ABT_TASK_TERM
;
1900 /* Now queue the abort command to firmware */
1901 int_to_scsilun(sc
->device
->lun
, &fc_lun
);
1903 if (fnic_queue_abort_io_req(fnic
, mqtag
, task_req
, fc_lun
.scsi_lun
,
1905 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1906 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
)
1907 fnic_priv(sc
)->state
= old_ioreq_state
;
1908 io_req
= fnic_priv(sc
)->io_req
;
1910 io_req
->abts_done
= NULL
;
1911 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1913 goto fnic_abort_cmd_end
;
1915 if (task_req
== FCPIO_ITMF_ABT_TASK
) {
1916 fnic_priv(sc
)->flags
|= FNIC_IO_ABTS_ISSUED
;
1917 atomic64_inc(&fnic_stats
->abts_stats
.aborts
);
1919 fnic_priv(sc
)->flags
|= FNIC_IO_TERM_ISSUED
;
1920 atomic64_inc(&fnic_stats
->term_stats
.terminates
);
1924 * We queued an abort IO, wait for its completion.
1925 * Once the firmware completes the abort command, it will
1926 * wake up this thread.
1929 wait_for_completion_timeout(&tm_done
,
1931 (2 * fnic
->config
.ra_tov
+
1932 fnic
->config
.ed_tov
));
1934 /* Check the abort status */
1935 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
1937 io_req
= fnic_priv(sc
)->io_req
;
1939 atomic64_inc(&fnic_stats
->io_stats
.ioreq_null
);
1940 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1941 fnic_priv(sc
)->flags
|= FNIC_IO_ABT_TERM_REQ_NULL
;
1943 goto fnic_abort_cmd_end
;
1945 io_req
->abts_done
= NULL
;
1947 /* fw did not complete abort, timed out */
1948 if (fnic_priv(sc
)->abts_status
== FCPIO_INVALID_CODE
) {
1949 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1950 if (task_req
== FCPIO_ITMF_ABT_TASK
) {
1951 atomic64_inc(&abts_stats
->abort_drv_timeouts
);
1953 atomic64_inc(&term_stats
->terminate_drv_timeouts
);
1955 fnic_priv(sc
)->flags
|= FNIC_IO_ABT_TERM_TIMED_OUT
;
1957 goto fnic_abort_cmd_end
;
1960 /* IO out of order */
1962 if (!(fnic_priv(sc
)->flags
& (FNIC_IO_ABORTED
| FNIC_IO_DONE
))) {
1963 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1964 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
1965 "Issuing host reset due to out of order IO\n");
1968 goto fnic_abort_cmd_end
;
1971 fnic_priv(sc
)->state
= FNIC_IOREQ_ABTS_COMPLETE
;
1973 start_time
= io_req
->start_time
;
1975 * firmware completed the abort, check the status,
1976 * free the io_req if successful. If abort fails,
1977 * Device reset will clean the I/O.
1979 if (fnic_priv(sc
)->abts_status
== FCPIO_SUCCESS
||
1980 (fnic_priv(sc
)->abts_status
== FCPIO_ABORTED
)) {
1981 fnic_priv(sc
)->io_req
= NULL
;
1985 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1986 goto fnic_abort_cmd_end
;
1989 fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(mqtag
)] = NULL
;
1990 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
1992 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
1993 mempool_free(io_req
, fnic
->io_req_pool
);
1995 /* Call SCSI completion function to complete the IO */
1996 sc
->result
= DID_ABORT
<< 16;
1998 atomic64_dec(&fnic_stats
->io_stats
.active_ios
);
1999 if (atomic64_read(&fnic
->io_cmpl_skip
))
2000 atomic64_dec(&fnic
->io_cmpl_skip
);
2002 atomic64_inc(&fnic_stats
->io_stats
.io_completions
);
2005 FNIC_TRACE(fnic_abort_cmd
, sc
->device
->host
->host_no
, mqtag
, sc
,
2006 jiffies_to_msecs(jiffies
- start_time
),
2007 0, ((u64
)sc
->cmnd
[0] << 32 |
2008 (u64
)sc
->cmnd
[2] << 24 | (u64
)sc
->cmnd
[3] << 16 |
2009 (u64
)sc
->cmnd
[4] << 8 | sc
->cmnd
[5]),
2010 fnic_flags_and_state(sc
));
2012 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2013 "Returning from abort cmd type %x %s\n", task_req
,
2015 "SUCCESS" : "FAILED");
2019 static inline int fnic_queue_dr_io_req(struct fnic
*fnic
,
2020 struct scsi_cmnd
*sc
,
2021 struct fnic_io_req
*io_req
)
2023 struct vnic_wq_copy
*wq
;
2024 struct misc_stats
*misc_stats
= &fnic
->fnic_stats
.misc_stats
;
2025 struct scsi_lun fc_lun
;
2027 unsigned long flags
;
2032 hwq
= blk_mq_unique_tag_to_hwq(tag
);
2033 wq
= &fnic
->hw_copy_wq
[hwq
];
2035 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2036 if (unlikely(fnic_chk_state_flags_locked(fnic
,
2037 FNIC_FLAGS_IO_BLOCKED
))) {
2038 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2041 atomic_inc(&fnic
->in_flight
);
2042 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2044 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2046 if (vnic_wq_copy_desc_avail(wq
) <= fnic
->wq_copy_desc_low
[hwq
])
2047 free_wq_copy_descs(fnic
, wq
, hwq
);
2049 if (!vnic_wq_copy_desc_avail(wq
)) {
2050 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2051 "queue_dr_io_req failure - no descriptors\n");
2052 atomic64_inc(&misc_stats
->devrst_cpwq_alloc_failures
);
2057 /* fill in the lun info */
2058 int_to_scsilun(sc
->device
->lun
, &fc_lun
);
2060 tag
|= FNIC_TAG_DEV_RST
;
2061 fnic_queue_wq_copy_desc_itmf(wq
, tag
,
2062 0, FCPIO_ITMF_LUN_RESET
, SCSI_NO_TAG
,
2063 fc_lun
.scsi_lun
, io_req
->port_id
,
2064 fnic
->config
.ra_tov
, fnic
->config
.ed_tov
);
2066 atomic64_inc(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
);
2067 if (atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
) >
2068 atomic64_read(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
))
2069 atomic64_set(&fnic
->fnic_stats
.fw_stats
.max_fw_reqs
,
2070 atomic64_read(&fnic
->fnic_stats
.fw_stats
.active_fw_reqs
));
2073 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2074 atomic_dec(&fnic
->in_flight
);
2079 struct fnic_pending_aborts_iter_data
{
2081 struct scsi_cmnd
*lr_sc
;
2082 struct scsi_device
*lun_dev
;
2086 static bool fnic_pending_aborts_iter(struct scsi_cmnd
*sc
, void *data
)
2088 struct request
*const rq
= scsi_cmd_to_rq(sc
);
2089 struct fnic_pending_aborts_iter_data
*iter_data
= data
;
2090 struct fnic
*fnic
= iter_data
->fnic
;
2091 struct scsi_device
*lun_dev
= iter_data
->lun_dev
;
2092 unsigned long abt_tag
= 0;
2094 struct fnic_io_req
*io_req
;
2095 unsigned long flags
;
2096 struct scsi_lun fc_lun
;
2097 DECLARE_COMPLETION_ONSTACK(tm_done
);
2098 enum fnic_ioreq_state old_ioreq_state
;
2100 if (sc
== iter_data
->lr_sc
|| sc
->device
!= lun_dev
)
2103 abt_tag
= blk_mq_unique_tag(rq
);
2104 hwq
= blk_mq_unique_tag_to_hwq(abt_tag
);
2106 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2107 io_req
= fnic_priv(sc
)->io_req
;
2109 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2114 * Found IO that is still pending with firmware and
2115 * belongs to the LUN that we are resetting
2117 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2118 "Found IO in %s on lun\n",
2119 fnic_ioreq_state_to_str(fnic_priv(sc
)->state
));
2121 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
) {
2122 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2125 if ((fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
) &&
2126 (!(fnic_priv(sc
)->flags
& FNIC_DEV_RST_ISSUED
))) {
2127 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
2128 "dev rst not pending sc 0x%p\n", sc
);
2129 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2133 if (io_req
->abts_done
)
2134 shost_printk(KERN_ERR
, fnic
->lport
->host
,
2135 "%s: io_req->abts_done is set state is %s\n",
2136 __func__
, fnic_ioreq_state_to_str(fnic_priv(sc
)->state
));
2137 old_ioreq_state
= fnic_priv(sc
)->state
;
2139 * Any pending IO issued prior to reset is expected to be
2140 * in abts pending state, if not we need to set
2141 * FNIC_IOREQ_ABTS_PENDING to indicate the IO is abort pending.
2142 * When IO is completed, the IO will be handed over and
2143 * handled in this function.
2145 fnic_priv(sc
)->state
= FNIC_IOREQ_ABTS_PENDING
;
2147 BUG_ON(io_req
->abts_done
);
2149 if (fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
) {
2150 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
2151 "dev rst sc 0x%p\n", sc
);
2154 fnic_priv(sc
)->abts_status
= FCPIO_INVALID_CODE
;
2155 io_req
->abts_done
= &tm_done
;
2156 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2158 /* Now queue the abort command to firmware */
2159 int_to_scsilun(sc
->device
->lun
, &fc_lun
);
2161 if (fnic_queue_abort_io_req(fnic
, abt_tag
,
2162 FCPIO_ITMF_ABT_TASK_TERM
,
2163 fc_lun
.scsi_lun
, io_req
, hwq
)) {
2164 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2165 io_req
= fnic_priv(sc
)->io_req
;
2167 io_req
->abts_done
= NULL
;
2168 if (fnic_priv(sc
)->state
== FNIC_IOREQ_ABTS_PENDING
)
2169 fnic_priv(sc
)->state
= old_ioreq_state
;
2170 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2171 iter_data
->ret
= FAILED
;
2172 FNIC_SCSI_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
2173 "hwq: %d abt_tag: 0x%lx Abort could not be queued\n",
2177 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2178 if (fnic_priv(sc
)->flags
& FNIC_DEVICE_RESET
)
2179 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_TERM_ISSUED
;
2180 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2182 fnic_priv(sc
)->flags
|= FNIC_IO_INTERNAL_TERM_ISSUED
;
2184 wait_for_completion_timeout(&tm_done
, msecs_to_jiffies
2185 (fnic
->config
.ed_tov
));
2187 /* Recheck cmd state to check if it is now aborted */
2188 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2189 io_req
= fnic_priv(sc
)->io_req
;
2191 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2192 fnic_priv(sc
)->flags
|= FNIC_IO_ABT_TERM_REQ_NULL
;
2196 io_req
->abts_done
= NULL
;
2198 /* if abort is still pending with fw, fail */
2199 if (fnic_priv(sc
)->abts_status
== FCPIO_INVALID_CODE
) {
2200 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2201 fnic_priv(sc
)->flags
|= FNIC_IO_ABT_TERM_DONE
;
2202 iter_data
->ret
= FAILED
;
2205 fnic_priv(sc
)->state
= FNIC_IOREQ_ABTS_COMPLETE
;
2207 /* original sc used for lr is handled by dev reset code */
2208 if (sc
!= iter_data
->lr_sc
) {
2209 fnic_priv(sc
)->io_req
= NULL
;
2210 fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(abt_tag
)] = NULL
;
2212 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2214 /* original sc used for lr is handled by dev reset code */
2215 if (sc
!= iter_data
->lr_sc
) {
2216 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
2217 mempool_free(io_req
, fnic
->io_req_pool
);
2221 * Any IO is returned during reset, it needs to call scsi_done
2222 * to return the scsi_cmnd to upper layer.
2224 /* Set result to let upper SCSI layer retry */
2225 sc
->result
= DID_RESET
<< 16;
2232 * Clean up any pending aborts on the lun
2233 * For each outstanding IO on this lun, whose abort is not completed by fw,
2234 * issue a local abort. Wait for abort to complete. Return 0 if all commands
2235 * successfully aborted, 1 otherwise
2237 static int fnic_clean_pending_aborts(struct fnic
*fnic
,
2238 struct scsi_cmnd
*lr_sc
,
2243 struct fnic_pending_aborts_iter_data iter_data
= {
2245 .lun_dev
= lr_sc
->device
,
2249 iter_data
.lr_sc
= lr_sc
;
2251 scsi_host_busy_iter(fnic
->lport
->host
,
2252 fnic_pending_aborts_iter
, &iter_data
);
2253 if (iter_data
.ret
== FAILED
) {
2254 ret
= iter_data
.ret
;
2255 goto clean_pending_aborts_end
;
2257 schedule_timeout(msecs_to_jiffies(2 * fnic
->config
.ed_tov
));
2259 /* walk again to check, if IOs are still pending in fw */
2260 if (fnic_is_abts_pending(fnic
, lr_sc
))
2263 clean_pending_aborts_end
:
2264 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
2265 "exit status: %d\n", ret
);
2270 * SCSI Eh thread issues a Lun Reset when one or more commands on a LUN
2271 * fail to get aborted. It calls driver's eh_device_reset with a SCSI command
2274 int fnic_device_reset(struct scsi_cmnd
*sc
)
2276 struct request
*rq
= scsi_cmd_to_rq(sc
);
2277 struct fc_lport
*lp
;
2279 struct fnic_io_req
*io_req
= NULL
;
2280 struct fc_rport
*rport
;
2283 unsigned long flags
;
2284 unsigned long start_time
= 0;
2285 struct scsi_lun fc_lun
;
2286 struct fnic_stats
*fnic_stats
;
2287 struct reset_stats
*reset_stats
;
2288 int mqtag
= rq
->tag
;
2289 DECLARE_COMPLETION_ONSTACK(tm_done
);
2293 /* Wait for rport to unblock */
2294 fc_block_scsi_eh(sc
);
2296 /* Get local-port, check ready and link up */
2297 lp
= shost_priv(sc
->device
->host
);
2299 fnic
= lport_priv(lp
);
2300 fnic_stats
= &fnic
->fnic_stats
;
2301 reset_stats
= &fnic
->fnic_stats
.reset_stats
;
2303 atomic64_inc(&reset_stats
->device_resets
);
2305 rport
= starget_to_rport(scsi_target(sc
->device
));
2306 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2307 "fcid: 0x%x lun: 0x%llx hwq: %d mqtag: 0x%x flags: 0x%x Device reset\n",
2308 rport
->port_id
, sc
->device
->lun
, hwq
, mqtag
,
2309 fnic_priv(sc
)->flags
);
2311 if (lp
->state
!= LPORT_ST_READY
|| !(lp
->link_up
))
2312 goto fnic_device_reset_end
;
2314 /* Check if remote port up */
2315 if (fc_remote_port_chkready(rport
)) {
2316 atomic64_inc(&fnic_stats
->misc_stats
.rport_not_ready
);
2317 goto fnic_device_reset_end
;
2320 fnic_priv(sc
)->flags
= FNIC_DEVICE_RESET
;
2322 if (unlikely(mqtag
< 0)) {
2324 * For device reset issued through sg3utils, we let
2325 * only one LUN_RESET to go through and use a special
2326 * tag equal to max_tag_id so that we don't have to allocate
2327 * or free it. It won't interact with tags
2328 * allocated by mid layer.
2330 mutex_lock(&fnic
->sgreset_mutex
);
2331 mqtag
= fnic
->fnic_max_tag_id
;
2334 mqtag
= blk_mq_unique_tag(rq
);
2335 hwq
= blk_mq_unique_tag_to_hwq(mqtag
);
2338 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2339 io_req
= fnic_priv(sc
)->io_req
;
2342 * If there is a io_req attached to this command, then use it,
2343 * else allocate a new one.
2346 io_req
= mempool_alloc(fnic
->io_req_pool
, GFP_ATOMIC
);
2348 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2349 goto fnic_device_reset_end
;
2351 memset(io_req
, 0, sizeof(*io_req
));
2352 io_req
->port_id
= rport
->port_id
;
2353 io_req
->tag
= mqtag
;
2354 fnic_priv(sc
)->io_req
= io_req
;
2357 if (fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(mqtag
)] != NULL
)
2358 WARN(1, "fnic<%d>: %s: tag 0x%x already exists\n",
2359 fnic
->fnic_num
, __func__
, blk_mq_unique_tag_to_tag(mqtag
));
2361 fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(mqtag
)] =
2364 io_req
->dr_done
= &tm_done
;
2365 fnic_priv(sc
)->state
= FNIC_IOREQ_CMD_PENDING
;
2366 fnic_priv(sc
)->lr_status
= FCPIO_INVALID_CODE
;
2367 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2369 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
, "TAG %x\n", mqtag
);
2372 * issue the device reset, if enqueue failed, clean up the ioreq
2373 * and break assoc with scsi cmd
2375 if (fnic_queue_dr_io_req(fnic
, sc
, io_req
)) {
2376 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2377 io_req
= fnic_priv(sc
)->io_req
;
2379 io_req
->dr_done
= NULL
;
2380 goto fnic_device_reset_clean
;
2382 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2383 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_ISSUED
;
2384 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2387 * Wait on the local completion for LUN reset. The io_req may be
2388 * freed while we wait since we hold no lock.
2390 wait_for_completion_timeout(&tm_done
,
2391 msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT
));
2393 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2394 io_req
= fnic_priv(sc
)->io_req
;
2396 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2397 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2398 "io_req is null mqtag 0x%x sc 0x%p\n", mqtag
, sc
);
2399 goto fnic_device_reset_end
;
2401 io_req
->dr_done
= NULL
;
2403 status
= fnic_priv(sc
)->lr_status
;
2406 * If lun reset not completed, bail out with failed. io_req
2407 * gets cleaned up during higher levels of EH
2409 if (status
== FCPIO_INVALID_CODE
) {
2410 atomic64_inc(&reset_stats
->device_reset_timeouts
);
2411 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2412 "Device reset timed out\n");
2413 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_TIMED_OUT
;
2414 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2415 int_to_scsilun(sc
->device
->lun
, &fc_lun
);
2417 * Issue abort and terminate on device reset request.
2418 * If q'ing of terminate fails, retry it after a delay.
2421 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2422 if (fnic_priv(sc
)->flags
& FNIC_DEV_RST_TERM_ISSUED
) {
2423 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2426 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2427 if (fnic_queue_abort_io_req(fnic
,
2428 mqtag
| FNIC_TAG_DEV_RST
,
2429 FCPIO_ITMF_ABT_TASK_TERM
,
2430 fc_lun
.scsi_lun
, io_req
, hwq
)) {
2431 wait_for_completion_timeout(&tm_done
,
2432 msecs_to_jiffies(FNIC_ABT_TERM_DELAY_TIMEOUT
));
2434 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2435 fnic_priv(sc
)->flags
|= FNIC_DEV_RST_TERM_ISSUED
;
2436 fnic_priv(sc
)->state
= FNIC_IOREQ_ABTS_PENDING
;
2437 io_req
->abts_done
= &tm_done
;
2438 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2439 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2440 "Abort and terminate issued on Device reset mqtag 0x%x sc 0x%p\n",
2446 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2447 if (!(fnic_priv(sc
)->flags
& FNIC_DEV_RST_DONE
)) {
2448 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2449 wait_for_completion_timeout(&tm_done
,
2450 msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT
));
2453 io_req
= fnic_priv(sc
)->io_req
;
2454 io_req
->abts_done
= NULL
;
2455 goto fnic_device_reset_clean
;
2459 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2462 /* Completed, but not successful, clean up the io_req, return fail */
2463 if (status
!= FCPIO_SUCCESS
) {
2464 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2465 FNIC_SCSI_DBG(KERN_DEBUG
,
2466 fnic
->lport
->host
, fnic
->fnic_num
,
2467 "Device reset completed - failed\n");
2468 io_req
= fnic_priv(sc
)->io_req
;
2469 goto fnic_device_reset_clean
;
2473 * Clean up any aborts on this lun that have still not
2474 * completed. If any of these fail, then LUN reset fails.
2475 * clean_pending_aborts cleans all cmds on this lun except
2476 * the lun reset cmd. If all cmds get cleaned, the lun reset
2479 if (fnic_clean_pending_aborts(fnic
, sc
, new_sc
)) {
2480 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2481 io_req
= fnic_priv(sc
)->io_req
;
2482 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2483 "Device reset failed"
2484 " since could not abort all IOs\n");
2485 goto fnic_device_reset_clean
;
2488 /* Clean lun reset command */
2489 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2490 io_req
= fnic_priv(sc
)->io_req
;
2492 /* Completed, and successful */
2495 fnic_device_reset_clean
:
2497 fnic_priv(sc
)->io_req
= NULL
;
2499 fnic
->sw_copy_wq
[hwq
].io_req_table
[blk_mq_unique_tag_to_tag(io_req
->tag
)] = NULL
;
2502 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2505 start_time
= io_req
->start_time
;
2506 fnic_release_ioreq_buf(fnic
, io_req
, sc
);
2507 mempool_free(io_req
, fnic
->io_req_pool
);
2510 fnic_device_reset_end
:
2511 FNIC_TRACE(fnic_device_reset
, sc
->device
->host
->host_no
, rq
->tag
, sc
,
2512 jiffies_to_msecs(jiffies
- start_time
),
2513 0, ((u64
)sc
->cmnd
[0] << 32 |
2514 (u64
)sc
->cmnd
[2] << 24 | (u64
)sc
->cmnd
[3] << 16 |
2515 (u64
)sc
->cmnd
[4] << 8 | sc
->cmnd
[5]),
2516 fnic_flags_and_state(sc
));
2519 fnic
->sgreset_sc
= NULL
;
2520 mutex_unlock(&fnic
->sgreset_mutex
);
2523 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2524 "Returning from device reset %s\n",
2526 "SUCCESS" : "FAILED");
2529 atomic64_inc(&reset_stats
->device_reset_failures
);
2534 /* Clean up all IOs, clean up libFC local port */
2535 int fnic_reset(struct Scsi_Host
*shost
)
2537 struct fc_lport
*lp
;
2540 struct reset_stats
*reset_stats
;
2542 lp
= shost_priv(shost
);
2543 fnic
= lport_priv(lp
);
2544 reset_stats
= &fnic
->fnic_stats
.reset_stats
;
2546 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
2547 "Issuing fnic reset\n");
2549 atomic64_inc(&reset_stats
->fnic_resets
);
2552 * Reset local port, this will clean up libFC exchanges,
2553 * reset remote port sessions, and if link is up, begin flogi
2555 ret
= fc_lport_reset(lp
);
2557 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
2558 "Returning from fnic reset with: %s\n",
2559 (ret
== 0) ? "SUCCESS" : "FAILED");
2562 atomic64_inc(&reset_stats
->fnic_reset_completions
);
2564 atomic64_inc(&reset_stats
->fnic_reset_failures
);
2570 * SCSI Error handling calls driver's eh_host_reset if all prior
2571 * error handling levels return FAILED. If host reset completes
2572 * successfully, and if link is up, then Fabric login begins.
2574 * Host Reset is the highest level of error recovery. If this fails, then
2575 * host is offlined by SCSI.
2578 int fnic_host_reset(struct scsi_cmnd
*sc
)
2581 unsigned long wait_host_tmo
;
2582 struct Scsi_Host
*shost
= sc
->device
->host
;
2583 struct fc_lport
*lp
= shost_priv(shost
);
2584 struct fnic
*fnic
= lport_priv(lp
);
2585 unsigned long flags
;
2587 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2588 if (!fnic
->internal_reset_inprogress
) {
2589 fnic
->internal_reset_inprogress
= true;
2591 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2592 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2593 "host reset in progress skipping another host reset\n");
2596 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2599 * If fnic_reset is successful, wait for fabric login to complete
2600 * scsi-ml tries to send a TUR to every device if host reset is
2601 * successful, so before returning to scsi, fabric should be up
2603 ret
= (fnic_reset(shost
) == 0) ? SUCCESS
: FAILED
;
2604 if (ret
== SUCCESS
) {
2605 wait_host_tmo
= jiffies
+ FNIC_HOST_RESET_SETTLE_TIME
* HZ
;
2607 while (time_before(jiffies
, wait_host_tmo
)) {
2608 if ((lp
->state
== LPORT_ST_READY
) &&
2617 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2618 fnic
->internal_reset_inprogress
= false;
2619 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2624 * This fxn is called from libFC when host is removed
2626 void fnic_scsi_abort_io(struct fc_lport
*lp
)
2629 unsigned long flags
;
2630 enum fnic_state old_state
;
2631 struct fnic
*fnic
= lport_priv(lp
);
2632 DECLARE_COMPLETION_ONSTACK(remove_wait
);
2634 /* Issue firmware reset for fnic, wait for reset to complete */
2636 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2637 if (unlikely(fnic
->state
== FNIC_IN_FC_TRANS_ETH_MODE
) &&
2638 fnic
->link_events
) {
2639 /* fw reset is in progress, poll for its completion */
2640 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2641 schedule_timeout(msecs_to_jiffies(100));
2642 goto retry_fw_reset
;
2645 fnic
->remove_wait
= &remove_wait
;
2646 old_state
= fnic
->state
;
2647 fnic
->state
= FNIC_IN_FC_TRANS_ETH_MODE
;
2648 fnic_update_mac_locked(fnic
, fnic
->ctlr
.ctl_src_addr
);
2649 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2651 err
= fnic_fw_reset_handler(fnic
);
2653 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2654 if (fnic
->state
== FNIC_IN_FC_TRANS_ETH_MODE
)
2655 fnic
->state
= old_state
;
2656 fnic
->remove_wait
= NULL
;
2657 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2661 /* Wait for firmware reset to complete */
2662 wait_for_completion_timeout(&remove_wait
,
2663 msecs_to_jiffies(FNIC_RMDEVICE_TIMEOUT
));
2665 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2666 fnic
->remove_wait
= NULL
;
2667 FNIC_SCSI_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
2668 "fnic_scsi_abort_io %s\n",
2669 (fnic
->state
== FNIC_IN_ETH_MODE
) ?
2670 "SUCCESS" : "FAILED");
2671 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2676 * This fxn called from libFC to clean up driver IO state on link down
2678 void fnic_scsi_cleanup(struct fc_lport
*lp
)
2680 unsigned long flags
;
2681 enum fnic_state old_state
;
2682 struct fnic
*fnic
= lport_priv(lp
);
2684 /* issue fw reset */
2686 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2687 if (unlikely(fnic
->state
== FNIC_IN_FC_TRANS_ETH_MODE
)) {
2688 /* fw reset is in progress, poll for its completion */
2689 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2690 schedule_timeout(msecs_to_jiffies(100));
2691 goto retry_fw_reset
;
2693 old_state
= fnic
->state
;
2694 fnic
->state
= FNIC_IN_FC_TRANS_ETH_MODE
;
2695 fnic_update_mac_locked(fnic
, fnic
->ctlr
.ctl_src_addr
);
2696 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2698 if (fnic_fw_reset_handler(fnic
)) {
2699 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
2700 if (fnic
->state
== FNIC_IN_FC_TRANS_ETH_MODE
)
2701 fnic
->state
= old_state
;
2702 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
2707 void fnic_empty_scsi_cleanup(struct fc_lport
*lp
)
2711 void fnic_exch_mgr_reset(struct fc_lport
*lp
, u32 sid
, u32 did
)
2713 struct fnic
*fnic
= lport_priv(lp
);
2715 /* Non-zero sid, nothing to do */
2717 goto call_fc_exch_mgr_reset
;
2720 fnic_rport_exch_reset(fnic
, did
);
2721 goto call_fc_exch_mgr_reset
;
2726 * link down or device being removed
2728 if (!fnic
->in_remove
)
2729 fnic_scsi_cleanup(lp
);
2731 fnic_scsi_abort_io(lp
);
2733 /* call libFC exch mgr reset to reset its exchanges */
2734 call_fc_exch_mgr_reset
:
2735 fc_exch_mgr_reset(lp
, sid
, did
);
2739 static bool fnic_abts_pending_iter(struct scsi_cmnd
*sc
, void *data
)
2741 struct request
*const rq
= scsi_cmd_to_rq(sc
);
2742 struct fnic_pending_aborts_iter_data
*iter_data
= data
;
2743 struct fnic
*fnic
= iter_data
->fnic
;
2745 struct fnic_io_req
*io_req
;
2746 unsigned long flags
;
2750 tag
= blk_mq_unique_tag(rq
);
2751 hwq
= blk_mq_unique_tag_to_hwq(tag
);
2754 * ignore this lun reset cmd or cmds that do not belong to
2757 if (iter_data
->lr_sc
&& sc
== iter_data
->lr_sc
)
2759 if (iter_data
->lun_dev
&& sc
->device
!= iter_data
->lun_dev
)
2762 spin_lock_irqsave(&fnic
->wq_copy_lock
[hwq
], flags
);
2764 io_req
= fnic_priv(sc
)->io_req
;
2766 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2771 * Found IO that is still pending with firmware and
2772 * belongs to the LUN that we are resetting
2774 FNIC_SCSI_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
2775 "hwq: %d tag: 0x%x Found IO in state: %s on lun\n",
2777 fnic_ioreq_state_to_str(fnic_priv(sc
)->state
));
2778 cmd_state
= fnic_priv(sc
)->state
;
2779 spin_unlock_irqrestore(&fnic
->wq_copy_lock
[hwq
], flags
);
2780 if (cmd_state
== FNIC_IOREQ_ABTS_PENDING
)
2783 return iter_data
->ret
? false : true;
2787 * fnic_is_abts_pending() is a helper function that
2788 * walks through tag map to check if there is any IOs pending,if there is one,
2789 * then it returns 1 (true), otherwise 0 (false)
2790 * if @lr_sc is non NULL, then it checks IOs specific to particular LUN,
2791 * otherwise, it checks for all IOs.
2793 int fnic_is_abts_pending(struct fnic
*fnic
, struct scsi_cmnd
*lr_sc
)
2795 struct fnic_pending_aborts_iter_data iter_data
= {
2802 iter_data
.lun_dev
= lr_sc
->device
;
2803 iter_data
.lr_sc
= lr_sc
;
2806 /* walk again to check, if IOs are still pending in fw */
2807 scsi_host_busy_iter(fnic
->lport
->host
,
2808 fnic_abts_pending_iter
, &iter_data
);
2810 return iter_data
.ret
;