2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * 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/scatterlist.h>
24 #include <linux/skbuff.h>
25 #include <linux/spinlock.h>
26 #include <linux/if_ether.h>
27 #include <linux/if_vlan.h>
28 #include <linux/delay.h>
29 #include <linux/gfp.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_cmnd.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/fc/fc_els.h>
36 #include <scsi/fc/fc_fcoe.h>
37 #include <scsi/libfc.h>
38 #include <scsi/fc_frame.h>
42 const char *fnic_state_str[] = {
43 [FNIC_IN_FC_MODE] = "FNIC_IN_FC_MODE",
44 [FNIC_IN_FC_TRANS_ETH_MODE] = "FNIC_IN_FC_TRANS_ETH_MODE",
45 [FNIC_IN_ETH_MODE] = "FNIC_IN_ETH_MODE",
46 [FNIC_IN_ETH_TRANS_FC_MODE] = "FNIC_IN_ETH_TRANS_FC_MODE",
49 static const char *fnic_ioreq_state_str[] = {
50 [FNIC_IOREQ_CMD_PENDING] = "FNIC_IOREQ_CMD_PENDING",
51 [FNIC_IOREQ_ABTS_PENDING] = "FNIC_IOREQ_ABTS_PENDING",
52 [FNIC_IOREQ_ABTS_COMPLETE] = "FNIC_IOREQ_ABTS_COMPLETE",
53 [FNIC_IOREQ_CMD_COMPLETE] = "FNIC_IOREQ_CMD_COMPLETE",
56 static const char *fcpio_status_str[] = {
57 [FCPIO_SUCCESS] = "FCPIO_SUCCESS", /*0x0*/
58 [FCPIO_INVALID_HEADER] = "FCPIO_INVALID_HEADER",
59 [FCPIO_OUT_OF_RESOURCE] = "FCPIO_OUT_OF_RESOURCE",
60 [FCPIO_INVALID_PARAM] = "FCPIO_INVALID_PARAM]",
61 [FCPIO_REQ_NOT_SUPPORTED] = "FCPIO_REQ_NOT_SUPPORTED",
62 [FCPIO_IO_NOT_FOUND] = "FCPIO_IO_NOT_FOUND",
63 [FCPIO_ABORTED] = "FCPIO_ABORTED", /*0x41*/
64 [FCPIO_TIMEOUT] = "FCPIO_TIMEOUT",
65 [FCPIO_SGL_INVALID] = "FCPIO_SGL_INVALID",
66 [FCPIO_MSS_INVALID] = "FCPIO_MSS_INVALID",
67 [FCPIO_DATA_CNT_MISMATCH] = "FCPIO_DATA_CNT_MISMATCH",
68 [FCPIO_FW_ERR] = "FCPIO_FW_ERR",
69 [FCPIO_ITMF_REJECTED] = "FCPIO_ITMF_REJECTED",
70 [FCPIO_ITMF_FAILED] = "FCPIO_ITMF_FAILED",
71 [FCPIO_ITMF_INCORRECT_LUN] = "FCPIO_ITMF_INCORRECT_LUN",
72 [FCPIO_CMND_REJECTED] = "FCPIO_CMND_REJECTED",
73 [FCPIO_NO_PATH_AVAIL] = "FCPIO_NO_PATH_AVAIL",
74 [FCPIO_PATH_FAILED] = "FCPIO_PATH_FAILED",
75 [FCPIO_LUNMAP_CHNG_PEND] = "FCPIO_LUNHMAP_CHNG_PEND",
78 const char *fnic_state_to_str(unsigned int state)
80 if (state >= ARRAY_SIZE(fnic_state_str) || !fnic_state_str[state])
83 return fnic_state_str[state];
86 static const char *fnic_ioreq_state_to_str(unsigned int state)
88 if (state >= ARRAY_SIZE(fnic_ioreq_state_str) ||
89 !fnic_ioreq_state_str[state])
92 return fnic_ioreq_state_str[state];
95 static const char *fnic_fcpio_status_to_str(unsigned int status)
97 if (status >= ARRAY_SIZE(fcpio_status_str) || !fcpio_status_str[status])
100 return fcpio_status_str[status];
103 static void fnic_cleanup_io(struct fnic *fnic, int exclude_id);
105 static inline spinlock_t *fnic_io_lock_hash(struct fnic *fnic,
106 struct scsi_cmnd *sc)
108 u32 hash = sc->request->tag & (FNIC_IO_LOCKS - 1);
110 return &fnic->io_req_lock[hash];
114 * Unmap the data buffer and sense buffer for an io_req,
115 * also unmap and free the device-private scatter/gather list.
117 static void fnic_release_ioreq_buf(struct fnic *fnic,
118 struct fnic_io_req *io_req,
119 struct scsi_cmnd *sc)
121 if (io_req->sgl_list_pa)
122 pci_unmap_single(fnic->pdev, io_req->sgl_list_pa,
123 sizeof(io_req->sgl_list[0]) * io_req->sgl_cnt,
128 mempool_free(io_req->sgl_list_alloc,
129 fnic->io_sgl_pool[io_req->sgl_type]);
130 if (io_req->sense_buf_pa)
131 pci_unmap_single(fnic->pdev, io_req->sense_buf_pa,
132 SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE);
135 /* Free up Copy Wq descriptors. Called with copy_wq lock held */
136 static int free_wq_copy_descs(struct fnic *fnic, struct vnic_wq_copy *wq)
138 /* if no Ack received from firmware, then nothing to clean */
139 if (!fnic->fw_ack_recd[0])
143 * Update desc_available count based on number of freed descriptors
144 * Account for wraparound
146 if (wq->to_clean_index <= fnic->fw_ack_index[0])
147 wq->ring.desc_avail += (fnic->fw_ack_index[0]
148 - wq->to_clean_index + 1);
150 wq->ring.desc_avail += (wq->ring.desc_count
152 + fnic->fw_ack_index[0] + 1);
155 * just bump clean index to ack_index+1 accounting for wraparound
156 * this will essentially free up all descriptors between
157 * to_clean_index and fw_ack_index, both inclusive
160 (fnic->fw_ack_index[0] + 1) % wq->ring.desc_count;
162 /* we have processed the acks received so far */
163 fnic->fw_ack_recd[0] = 0;
169 * __fnic_set_state_flags
170 * Sets/Clears bits in fnic's state_flags
173 __fnic_set_state_flags(struct fnic *fnic, unsigned long st_flags,
174 unsigned long clearbits)
176 struct Scsi_Host *host = fnic->lport->host;
177 int sh_locked = spin_is_locked(host->host_lock);
178 unsigned long flags = 0;
181 spin_lock_irqsave(host->host_lock, flags);
184 fnic->state_flags &= ~st_flags;
186 fnic->state_flags |= st_flags;
189 spin_unlock_irqrestore(host->host_lock, flags);
196 * fnic_fw_reset_handler
197 * Routine to send reset msg to fw
199 int fnic_fw_reset_handler(struct fnic *fnic)
201 struct vnic_wq_copy *wq = &fnic->wq_copy[0];
205 /* indicate fwreset to io path */
206 fnic_set_state_flags(fnic, FNIC_FLAGS_FWRESET);
208 skb_queue_purge(&fnic->frame_queue);
209 skb_queue_purge(&fnic->tx_queue);
211 /* wait for io cmpl */
212 while (atomic_read(&fnic->in_flight))
213 schedule_timeout(msecs_to_jiffies(1));
215 spin_lock_irqsave(&fnic->wq_copy_lock[0], flags);
217 if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0])
218 free_wq_copy_descs(fnic, wq);
220 if (!vnic_wq_copy_desc_avail(wq))
223 fnic_queue_wq_copy_desc_fw_reset(wq, SCSI_NO_TAG);
225 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags);
228 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
229 "Issued fw reset\n");
231 fnic_clear_state_flags(fnic, FNIC_FLAGS_FWRESET);
232 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
233 "Failed to issue fw reset\n");
241 * fnic_flogi_reg_handler
242 * Routine to send flogi register msg to fw
244 int fnic_flogi_reg_handler(struct fnic *fnic, u32 fc_id)
246 struct vnic_wq_copy *wq = &fnic->wq_copy[0];
247 enum fcpio_flogi_reg_format_type format;
248 struct fc_lport *lp = fnic->lport;
253 spin_lock_irqsave(&fnic->wq_copy_lock[0], flags);
255 if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0])
256 free_wq_copy_descs(fnic, wq);
258 if (!vnic_wq_copy_desc_avail(wq)) {
260 goto flogi_reg_ioreq_end;
263 if (fnic->ctlr.map_dest) {
264 memset(gw_mac, 0xff, ETH_ALEN);
265 format = FCPIO_FLOGI_REG_DEF_DEST;
267 memcpy(gw_mac, fnic->ctlr.dest_addr, ETH_ALEN);
268 format = FCPIO_FLOGI_REG_GW_DEST;
271 if ((fnic->config.flags & VFCF_FIP_CAPABLE) && !fnic->ctlr.map_dest) {
272 fnic_queue_wq_copy_desc_fip_reg(wq, SCSI_NO_TAG,
275 lp->r_a_tov, lp->e_d_tov);
276 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
277 "FLOGI FIP reg issued fcid %x src %pM dest %pM\n",
278 fc_id, fnic->data_src_addr, gw_mac);
280 fnic_queue_wq_copy_desc_flogi_reg(wq, SCSI_NO_TAG,
281 format, fc_id, gw_mac);
282 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
283 "FLOGI reg issued fcid %x map %d dest %pM\n",
284 fc_id, fnic->ctlr.map_dest, gw_mac);
288 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags);
293 * fnic_queue_wq_copy_desc
294 * Routine to enqueue a wq copy desc
296 static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
297 struct vnic_wq_copy *wq,
298 struct fnic_io_req *io_req,
299 struct scsi_cmnd *sc,
302 struct scatterlist *sg;
303 struct fc_rport *rport = starget_to_rport(scsi_target(sc->device));
304 struct fc_rport_libfc_priv *rp = rport->dd_data;
305 struct host_sg_desc *desc;
308 unsigned long intr_flags;
311 struct scsi_lun fc_lun;
315 /* For each SGE, create a device desc entry */
316 desc = io_req->sgl_list;
317 for_each_sg(scsi_sglist(sc), sg, sg_count, i) {
318 desc->addr = cpu_to_le64(sg_dma_address(sg));
319 desc->len = cpu_to_le32(sg_dma_len(sg));
324 io_req->sgl_list_pa = pci_map_single
327 sizeof(io_req->sgl_list[0]) * sg_count,
331 io_req->sense_buf_pa = pci_map_single(fnic->pdev,
333 SCSI_SENSE_BUFFERSIZE,
336 int_to_scsilun(sc->device->lun, &fc_lun);
338 pri_tag = FCPIO_ICMND_PTA_SIMPLE;
339 msg[0] = MSG_SIMPLE_TAG;
340 scsi_populate_tag_msg(sc, msg);
341 if (msg[0] == MSG_ORDERED_TAG)
342 pri_tag = FCPIO_ICMND_PTA_ORDERED;
344 /* Enqueue the descriptor in the Copy WQ */
345 spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags);
347 if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0])
348 free_wq_copy_descs(fnic, wq);
350 if (unlikely(!vnic_wq_copy_desc_avail(wq))) {
351 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags);
352 return SCSI_MLQUEUE_HOST_BUSY;
356 if (sc->sc_data_direction == DMA_FROM_DEVICE)
357 flags = FCPIO_ICMND_RDDATA;
358 else if (sc->sc_data_direction == DMA_TO_DEVICE)
359 flags = FCPIO_ICMND_WRDATA;
362 if ((fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR) &&
363 (rp->flags & FC_RP_FLAGS_RETRY))
364 exch_flags |= FCPIO_ICMND_SRFLAG_RETRY;
366 fnic_queue_wq_copy_desc_icmnd_16(wq, sc->request->tag,
367 0, exch_flags, io_req->sgl_cnt,
368 SCSI_SENSE_BUFFERSIZE,
370 io_req->sense_buf_pa,
371 0, /* scsi cmd ref, always 0 */
372 pri_tag, /* scsi pri and tag */
373 flags, /* command flags */
374 sc->cmnd, sc->cmd_len,
376 fc_lun.scsi_lun, io_req->port_id,
377 rport->maxframe_size, rp->r_a_tov,
380 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags);
386 * Routine to send a scsi cdb
387 * Called with host_lock held and interrupts disabled.
389 static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
391 struct fc_lport *lp = shost_priv(sc->device->host);
392 struct fc_rport *rport;
393 struct fnic_io_req *io_req;
394 struct fnic *fnic = lport_priv(lp);
395 struct vnic_wq_copy *wq;
401 if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED)))
402 return SCSI_MLQUEUE_HOST_BUSY;
404 rport = starget_to_rport(scsi_target(sc->device));
405 ret = fc_remote_port_chkready(rport);
412 if (lp->state != LPORT_ST_READY || !(lp->link_up))
413 return SCSI_MLQUEUE_HOST_BUSY;
415 atomic_inc(&fnic->in_flight);
418 * Release host lock, use driver resource specific locks from here.
419 * Don't re-enable interrupts in case they were disabled prior to the
420 * caller disabling them.
422 spin_unlock(lp->host->host_lock);
423 CMD_FLAGS(sc) = FNIC_CDB_REQ;
425 /* Get a new io_req for this SCSI IO */
426 io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC);
428 ret = SCSI_MLQUEUE_HOST_BUSY;
431 memset(io_req, 0, sizeof(*io_req));
433 /* Map the data buffer */
434 sg_count = scsi_dma_map(sc);
436 mempool_free(io_req, fnic->io_req_pool);
440 /* Determine the type of scatter/gather list we need */
441 io_req->sgl_cnt = sg_count;
442 io_req->sgl_type = FNIC_SGL_CACHE_DFLT;
443 if (sg_count > FNIC_DFLT_SG_DESC_CNT)
444 io_req->sgl_type = FNIC_SGL_CACHE_MAX;
448 mempool_alloc(fnic->io_sgl_pool[io_req->sgl_type],
450 if (!io_req->sgl_list) {
451 ret = SCSI_MLQUEUE_HOST_BUSY;
453 mempool_free(io_req, fnic->io_req_pool);
457 /* Cache sgl list allocated address before alignment */
458 io_req->sgl_list_alloc = io_req->sgl_list;
459 ptr = (unsigned long) io_req->sgl_list;
460 if (ptr % FNIC_SG_DESC_ALIGN) {
461 io_req->sgl_list = (struct host_sg_desc *)
462 (((unsigned long) ptr
463 + FNIC_SG_DESC_ALIGN - 1)
464 & ~(FNIC_SG_DESC_ALIGN - 1));
468 /* initialize rest of io_req */
469 io_req->port_id = rport->port_id;
470 CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING;
471 CMD_SP(sc) = (char *)io_req;
472 sc->scsi_done = done;
474 /* create copy wq desc and enqueue it */
475 wq = &fnic->wq_copy[0];
476 ret = fnic_queue_wq_copy_desc(fnic, wq, io_req, sc, sg_count);
479 * In case another thread cancelled the request,
480 * refetch the pointer under the lock.
482 spinlock_t *io_lock = fnic_io_lock_hash(fnic, sc);
484 spin_lock_irqsave(io_lock, flags);
485 io_req = (struct fnic_io_req *)CMD_SP(sc);
487 CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE;
488 spin_unlock_irqrestore(io_lock, flags);
490 fnic_release_ioreq_buf(fnic, io_req, sc);
491 mempool_free(io_req, fnic->io_req_pool);
495 atomic_dec(&fnic->in_flight);
496 /* acquire host lock before returning to SCSI */
497 spin_lock(lp->host->host_lock);
501 DEF_SCSI_QCMD(fnic_queuecommand)
504 * fnic_fcpio_fw_reset_cmpl_handler
505 * Routine to handle fw reset completion
507 static int fnic_fcpio_fw_reset_cmpl_handler(struct fnic *fnic,
508 struct fcpio_fw_req *desc)
512 struct fcpio_tag tag;
516 fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag);
518 /* Clean up all outstanding io requests */
519 fnic_cleanup_io(fnic, SCSI_NO_TAG);
521 spin_lock_irqsave(&fnic->fnic_lock, flags);
523 /* fnic should be in FC_TRANS_ETH_MODE */
524 if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE) {
525 /* Check status of reset completion */
527 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
528 "reset cmpl success\n");
529 /* Ready to send flogi out */
530 fnic->state = FNIC_IN_ETH_MODE;
532 FNIC_SCSI_DBG(KERN_DEBUG,
534 "fnic fw_reset : failed %s\n",
535 fnic_fcpio_status_to_str(hdr_status));
538 * Unable to change to eth mode, cannot send out flogi
539 * Change state to fc mode, so that subsequent Flogi
540 * requests from libFC will cause more attempts to
541 * reset the firmware. Free the cached flogi
543 fnic->state = FNIC_IN_FC_MODE;
547 FNIC_SCSI_DBG(KERN_DEBUG,
549 "Unexpected state %s while processing"
550 " reset cmpl\n", fnic_state_to_str(fnic->state));
554 /* Thread removing device blocks till firmware reset is complete */
555 if (fnic->remove_wait)
556 complete(fnic->remove_wait);
559 * If fnic is being removed, or fw reset failed
560 * free the flogi frame. Else, send it out
562 if (fnic->remove_wait || ret) {
563 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
564 skb_queue_purge(&fnic->tx_queue);
565 goto reset_cmpl_handler_end;
568 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
572 reset_cmpl_handler_end:
573 fnic_clear_state_flags(fnic, FNIC_FLAGS_FWRESET);
579 * fnic_fcpio_flogi_reg_cmpl_handler
580 * Routine to handle flogi register completion
582 static int fnic_fcpio_flogi_reg_cmpl_handler(struct fnic *fnic,
583 struct fcpio_fw_req *desc)
587 struct fcpio_tag tag;
591 fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag);
593 /* Update fnic state based on status of flogi reg completion */
594 spin_lock_irqsave(&fnic->fnic_lock, flags);
596 if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE) {
598 /* Check flogi registration completion status */
600 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
601 "flog reg succeeded\n");
602 fnic->state = FNIC_IN_FC_MODE;
604 FNIC_SCSI_DBG(KERN_DEBUG,
606 "fnic flogi reg :failed %s\n",
607 fnic_fcpio_status_to_str(hdr_status));
608 fnic->state = FNIC_IN_ETH_MODE;
612 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
613 "Unexpected fnic state %s while"
614 " processing flogi reg completion\n",
615 fnic_state_to_str(fnic->state));
620 if (fnic->stop_rx_link_events) {
621 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
622 goto reg_cmpl_handler_end;
624 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
627 queue_work(fnic_event_queue, &fnic->frame_work);
629 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
632 reg_cmpl_handler_end:
636 static inline int is_ack_index_in_range(struct vnic_wq_copy *wq,
639 if (wq->to_clean_index <= wq->to_use_index) {
640 /* out of range, stale request_out index */
641 if (request_out < wq->to_clean_index ||
642 request_out >= wq->to_use_index)
645 /* out of range, stale request_out index */
646 if (request_out < wq->to_clean_index &&
647 request_out >= wq->to_use_index)
650 /* request_out index is in range */
656 * Mark that ack received and store the Ack index. If there are multiple
657 * acks received before Tx thread cleans it up, the latest value will be
658 * used which is correct behavior. This state should be in the copy Wq
659 * instead of in the fnic
661 static inline void fnic_fcpio_ack_handler(struct fnic *fnic,
662 unsigned int cq_index,
663 struct fcpio_fw_req *desc)
665 struct vnic_wq_copy *wq;
666 u16 request_out = desc->u.ack.request_out;
669 /* mark the ack state */
670 wq = &fnic->wq_copy[cq_index - fnic->raw_wq_count - fnic->rq_count];
671 spin_lock_irqsave(&fnic->wq_copy_lock[0], flags);
673 if (is_ack_index_in_range(wq, request_out)) {
674 fnic->fw_ack_index[0] = request_out;
675 fnic->fw_ack_recd[0] = 1;
677 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags);
681 * fnic_fcpio_icmnd_cmpl_handler
682 * Routine to handle icmnd completions
684 static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
685 struct fcpio_fw_req *desc)
689 struct fcpio_tag tag;
692 struct fcpio_icmnd_cmpl *icmnd_cmpl;
693 struct fnic_io_req *io_req;
694 struct scsi_cmnd *sc;
698 /* Decode the cmpl description to get the io_req id */
699 fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag);
700 fcpio_tag_id_dec(&tag, &id);
702 if (id >= FNIC_MAX_IO_REQ) {
703 shost_printk(KERN_ERR, fnic->lport->host,
704 "Tag out of range tag %x hdr status = %s\n",
705 id, fnic_fcpio_status_to_str(hdr_status));
709 sc = scsi_host_find_tag(fnic->lport->host, id);
714 io_lock = fnic_io_lock_hash(fnic, sc);
715 spin_lock_irqsave(io_lock, flags);
716 io_req = (struct fnic_io_req *)CMD_SP(sc);
717 WARN_ON_ONCE(!io_req);
719 spin_unlock_irqrestore(io_lock, flags);
723 /* firmware completed the io */
724 io_req->io_completed = 1;
727 * if SCSI-ML has already issued abort on this command,
728 * ignore completion of the IO. The abts path will clean it up
730 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) {
731 spin_unlock_irqrestore(io_lock, flags);
735 /* Mark the IO as complete */
736 CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE;
738 icmnd_cmpl = &desc->u.icmnd_cmpl;
740 switch (hdr_status) {
742 sc->result = (DID_OK << 16) | icmnd_cmpl->scsi_status;
743 xfer_len = scsi_bufflen(sc);
744 scsi_set_resid(sc, icmnd_cmpl->residual);
746 if (icmnd_cmpl->flags & FCPIO_ICMND_CMPL_RESID_UNDER)
747 xfer_len -= icmnd_cmpl->residual;
750 * If queue_full, then try to reduce queue depth for all
751 * LUNS on the target. Todo: this should be accompanied
752 * by a periodic queue_depth rampup based on successful
755 if (icmnd_cmpl->scsi_status == QUEUE_FULL) {
756 struct scsi_device *t_sdev;
759 shost_for_each_device(t_sdev, sc->device->host) {
760 if (t_sdev->id != sc->device->id)
763 if (t_sdev->queue_depth > 1) {
764 qd = scsi_track_queue_full
766 t_sdev->queue_depth - 1);
768 qd = t_sdev->host->cmd_per_lun;
769 shost_printk(KERN_INFO,
772 "] queue full detected,"
774 t_sdev->host->host_no,
776 t_sdev->id, t_sdev->lun,
777 t_sdev->queue_depth);
783 case FCPIO_TIMEOUT: /* request was timed out */
784 sc->result = (DID_TIME_OUT << 16) | icmnd_cmpl->scsi_status;
787 case FCPIO_ABORTED: /* request was aborted */
788 sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
791 case FCPIO_DATA_CNT_MISMATCH: /* recv/sent more/less data than exp. */
792 scsi_set_resid(sc, icmnd_cmpl->residual);
793 sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
796 case FCPIO_OUT_OF_RESOURCE: /* out of resources to complete request */
797 sc->result = (DID_REQUEUE << 16) | icmnd_cmpl->scsi_status;
799 case FCPIO_INVALID_HEADER: /* header contains invalid data */
800 case FCPIO_INVALID_PARAM: /* some parameter in request invalid */
801 case FCPIO_REQ_NOT_SUPPORTED:/* request type is not supported */
802 case FCPIO_IO_NOT_FOUND: /* requested I/O was not found */
803 case FCPIO_SGL_INVALID: /* request was aborted due to sgl error */
804 case FCPIO_MSS_INVALID: /* request was aborted due to mss error */
805 case FCPIO_FW_ERR: /* request was terminated due fw error */
807 shost_printk(KERN_ERR, fnic->lport->host, "hdr status = %s\n",
808 fnic_fcpio_status_to_str(hdr_status));
809 sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
813 /* Break link with the SCSI command */
816 spin_unlock_irqrestore(io_lock, flags);
818 fnic_release_ioreq_buf(fnic, io_req, sc);
820 mempool_free(io_req, fnic->io_req_pool);
822 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
823 fnic->lport->host_stats.fcp_input_requests++;
824 fnic->fcp_input_bytes += xfer_len;
825 } else if (sc->sc_data_direction == DMA_TO_DEVICE) {
826 fnic->lport->host_stats.fcp_output_requests++;
827 fnic->fcp_output_bytes += xfer_len;
829 fnic->lport->host_stats.fcp_control_requests++;
831 /* Call SCSI completion function to complete the IO */
837 /* fnic_fcpio_itmf_cmpl_handler
838 * Routine to handle itmf completions
840 static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
841 struct fcpio_fw_req *desc)
845 struct fcpio_tag tag;
847 struct scsi_cmnd *sc;
848 struct fnic_io_req *io_req;
852 fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag);
853 fcpio_tag_id_dec(&tag, &id);
855 if ((id & FNIC_TAG_MASK) >= FNIC_MAX_IO_REQ) {
856 shost_printk(KERN_ERR, fnic->lport->host,
857 "Tag out of range tag %x hdr status = %s\n",
858 id, fnic_fcpio_status_to_str(hdr_status));
862 sc = scsi_host_find_tag(fnic->lport->host, id & FNIC_TAG_MASK);
867 io_lock = fnic_io_lock_hash(fnic, sc);
868 spin_lock_irqsave(io_lock, flags);
869 io_req = (struct fnic_io_req *)CMD_SP(sc);
870 WARN_ON_ONCE(!io_req);
872 spin_unlock_irqrestore(io_lock, flags);
876 if ((id & FNIC_TAG_ABORT) && (id & FNIC_TAG_DEV_RST)) {
877 /* Abort and terminate completion of device reset req */
878 /* REVISIT : Add asserts about various flags */
879 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
880 "dev reset abts cmpl recd. id %x status %s\n",
881 id, fnic_fcpio_status_to_str(hdr_status));
882 CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE;
883 CMD_ABTS_STATUS(sc) = hdr_status;
884 CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE;
885 if (io_req->abts_done)
886 complete(io_req->abts_done);
887 spin_unlock_irqrestore(io_lock, flags);
888 } else if (id & FNIC_TAG_ABORT) {
889 /* Completion of abort cmd */
890 if (CMD_STATE(sc) != FNIC_IOREQ_ABTS_PENDING) {
891 /* This is a late completion. Ignore it */
892 spin_unlock_irqrestore(io_lock, flags);
895 CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE;
896 CMD_ABTS_STATUS(sc) = hdr_status;
898 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
899 "abts cmpl recd. id %d status %s\n",
900 (int)(id & FNIC_TAG_MASK),
901 fnic_fcpio_status_to_str(hdr_status));
904 * If scsi_eh thread is blocked waiting for abts to complete,
905 * signal completion to it. IO will be cleaned in the thread
906 * else clean it in this context
908 if (io_req->abts_done) {
909 complete(io_req->abts_done);
910 spin_unlock_irqrestore(io_lock, flags);
912 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
913 "abts cmpl, completing IO\n");
915 sc->result = (DID_ERROR << 16);
917 spin_unlock_irqrestore(io_lock, flags);
919 fnic_release_ioreq_buf(fnic, io_req, sc);
920 mempool_free(io_req, fnic->io_req_pool);
925 } else if (id & FNIC_TAG_DEV_RST) {
926 /* Completion of device reset */
927 CMD_LR_STATUS(sc) = hdr_status;
928 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) {
929 spin_unlock_irqrestore(io_lock, flags);
930 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
932 "dev reset cmpl recd. id %d status %s\n",
933 (int)(id & FNIC_TAG_MASK),
934 fnic_fcpio_status_to_str(hdr_status));
937 if (CMD_FLAGS(sc) & FNIC_DEV_RST_TIMED_OUT) {
938 /* Need to wait for terminate completion */
939 spin_unlock_irqrestore(io_lock, flags);
940 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
941 "dev reset cmpl recd after time out. "
943 (int)(id & FNIC_TAG_MASK),
944 fnic_fcpio_status_to_str(hdr_status));
947 CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE;
948 CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE;
949 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
950 "dev reset cmpl recd. id %d status %s\n",
951 (int)(id & FNIC_TAG_MASK),
952 fnic_fcpio_status_to_str(hdr_status));
954 complete(io_req->dr_done);
955 spin_unlock_irqrestore(io_lock, flags);
958 shost_printk(KERN_ERR, fnic->lport->host,
959 "Unexpected itmf io state %s tag %x\n",
960 fnic_ioreq_state_to_str(CMD_STATE(sc)), id);
961 spin_unlock_irqrestore(io_lock, flags);
967 * fnic_fcpio_cmpl_handler
968 * Routine to service the cq for wq_copy
970 static int fnic_fcpio_cmpl_handler(struct vnic_dev *vdev,
971 unsigned int cq_index,
972 struct fcpio_fw_req *desc)
974 struct fnic *fnic = vnic_dev_priv(vdev);
976 switch (desc->hdr.type) {
977 case FCPIO_ACK: /* fw copied copy wq desc to its queue */
978 fnic_fcpio_ack_handler(fnic, cq_index, desc);
981 case FCPIO_ICMND_CMPL: /* fw completed a command */
982 fnic_fcpio_icmnd_cmpl_handler(fnic, desc);
985 case FCPIO_ITMF_CMPL: /* fw completed itmf (abort cmd, lun reset)*/
986 fnic_fcpio_itmf_cmpl_handler(fnic, desc);
989 case FCPIO_FLOGI_REG_CMPL: /* fw completed flogi_reg */
990 case FCPIO_FLOGI_FIP_REG_CMPL: /* fw completed flogi_fip_reg */
991 fnic_fcpio_flogi_reg_cmpl_handler(fnic, desc);
994 case FCPIO_RESET_CMPL: /* fw completed reset */
995 fnic_fcpio_fw_reset_cmpl_handler(fnic, desc);
999 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1000 "firmware completion type %d\n",
1009 * fnic_wq_copy_cmpl_handler
1010 * Routine to process wq copy
1012 int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int copy_work_to_do)
1014 unsigned int wq_work_done = 0;
1015 unsigned int i, cq_index;
1016 unsigned int cur_work_done;
1018 for (i = 0; i < fnic->wq_copy_count; i++) {
1019 cq_index = i + fnic->raw_wq_count + fnic->rq_count;
1020 cur_work_done = vnic_cq_copy_service(&fnic->cq[cq_index],
1021 fnic_fcpio_cmpl_handler,
1023 wq_work_done += cur_work_done;
1025 return wq_work_done;
1028 static void fnic_cleanup_io(struct fnic *fnic, int exclude_id)
1031 struct fnic_io_req *io_req;
1032 unsigned long flags = 0;
1033 struct scsi_cmnd *sc;
1034 spinlock_t *io_lock;
1036 for (i = 0; i < FNIC_MAX_IO_REQ; i++) {
1037 if (i == exclude_id)
1040 sc = scsi_host_find_tag(fnic->lport->host, i);
1044 io_lock = fnic_io_lock_hash(fnic, sc);
1045 spin_lock_irqsave(io_lock, flags);
1046 io_req = (struct fnic_io_req *)CMD_SP(sc);
1047 if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) &&
1048 !(CMD_FLAGS(sc) & FNIC_DEV_RST_DONE)) {
1050 * We will be here only when FW completes reset
1051 * without sending completions for outstanding ios.
1053 CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE;
1054 if (io_req && io_req->dr_done)
1055 complete(io_req->dr_done);
1056 else if (io_req && io_req->abts_done)
1057 complete(io_req->abts_done);
1058 spin_unlock_irqrestore(io_lock, flags);
1060 } else if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) {
1061 spin_unlock_irqrestore(io_lock, flags);
1065 spin_unlock_irqrestore(io_lock, flags);
1066 goto cleanup_scsi_cmd;
1071 spin_unlock_irqrestore(io_lock, flags);
1074 * If there is a scsi_cmnd associated with this io_req, then
1075 * free the corresponding state
1077 fnic_release_ioreq_buf(fnic, io_req, sc);
1078 mempool_free(io_req, fnic->io_req_pool);
1081 sc->result = DID_TRANSPORT_DISRUPTED << 16;
1082 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "fnic_cleanup_io:"
1083 " DID_TRANSPORT_DISRUPTED\n");
1085 /* Complete the command to SCSI */
1091 void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
1092 struct fcpio_host_req *desc)
1095 struct fnic *fnic = vnic_dev_priv(wq->vdev);
1096 struct fnic_io_req *io_req;
1097 struct scsi_cmnd *sc;
1098 unsigned long flags;
1099 spinlock_t *io_lock;
1101 /* get the tag reference */
1102 fcpio_tag_id_dec(&desc->hdr.tag, &id);
1103 id &= FNIC_TAG_MASK;
1105 if (id >= FNIC_MAX_IO_REQ)
1108 sc = scsi_host_find_tag(fnic->lport->host, id);
1112 io_lock = fnic_io_lock_hash(fnic, sc);
1113 spin_lock_irqsave(io_lock, flags);
1115 /* Get the IO context which this desc refers to */
1116 io_req = (struct fnic_io_req *)CMD_SP(sc);
1118 /* fnic interrupts are turned off by now */
1121 spin_unlock_irqrestore(io_lock, flags);
1122 goto wq_copy_cleanup_scsi_cmd;
1127 spin_unlock_irqrestore(io_lock, flags);
1129 fnic_release_ioreq_buf(fnic, io_req, sc);
1130 mempool_free(io_req, fnic->io_req_pool);
1132 wq_copy_cleanup_scsi_cmd:
1133 sc->result = DID_NO_CONNECT << 16;
1134 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "wq_copy_cleanup_handler:"
1135 " DID_NO_CONNECT\n");
1141 static inline int fnic_queue_abort_io_req(struct fnic *fnic, int tag,
1142 u32 task_req, u8 *fc_lun,
1143 struct fnic_io_req *io_req)
1145 struct vnic_wq_copy *wq = &fnic->wq_copy[0];
1146 struct Scsi_Host *host = fnic->lport->host;
1147 unsigned long flags;
1149 spin_lock_irqsave(host->host_lock, flags);
1150 if (unlikely(fnic_chk_state_flags_locked(fnic,
1151 FNIC_FLAGS_IO_BLOCKED))) {
1152 spin_unlock_irqrestore(host->host_lock, flags);
1155 atomic_inc(&fnic->in_flight);
1156 spin_unlock_irqrestore(host->host_lock, flags);
1158 spin_lock_irqsave(&fnic->wq_copy_lock[0], flags);
1160 if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0])
1161 free_wq_copy_descs(fnic, wq);
1163 if (!vnic_wq_copy_desc_avail(wq)) {
1164 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags);
1165 atomic_dec(&fnic->in_flight);
1166 shost_printk(KERN_DEBUG, fnic->lport->host,
1167 "fnic_queue_abort_io_req: failure: no descriptors\n");
1170 fnic_queue_wq_copy_desc_itmf(wq, tag | FNIC_TAG_ABORT,
1171 0, task_req, tag, fc_lun, io_req->port_id,
1172 fnic->config.ra_tov, fnic->config.ed_tov);
1174 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags);
1175 atomic_dec(&fnic->in_flight);
1180 static void fnic_rport_exch_reset(struct fnic *fnic, u32 port_id)
1184 struct fnic_io_req *io_req;
1185 spinlock_t *io_lock;
1186 unsigned long flags;
1187 struct scsi_cmnd *sc;
1188 struct scsi_lun fc_lun;
1189 enum fnic_ioreq_state old_ioreq_state;
1191 FNIC_SCSI_DBG(KERN_DEBUG,
1193 "fnic_rport_exch_reset called portid 0x%06x\n",
1196 if (fnic->in_remove)
1199 for (tag = 0; tag < FNIC_MAX_IO_REQ; tag++) {
1201 sc = scsi_host_find_tag(fnic->lport->host, tag);
1205 io_lock = fnic_io_lock_hash(fnic, sc);
1206 spin_lock_irqsave(io_lock, flags);
1208 io_req = (struct fnic_io_req *)CMD_SP(sc);
1210 if (!io_req || io_req->port_id != port_id) {
1211 spin_unlock_irqrestore(io_lock, flags);
1215 if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) &&
1216 (!(CMD_FLAGS(sc) & FNIC_DEV_RST_PENDING))) {
1217 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1218 "fnic_rport_exch_reset dev rst not pending sc 0x%p\n",
1220 spin_unlock_irqrestore(io_lock, flags);
1225 * Found IO that is still pending with firmware and
1226 * belongs to rport that went away
1228 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) {
1229 spin_unlock_irqrestore(io_lock, flags);
1232 if (io_req->abts_done) {
1233 shost_printk(KERN_ERR, fnic->lport->host,
1234 "fnic_rport_exch_reset: io_req->abts_done is set "
1236 fnic_ioreq_state_to_str(CMD_STATE(sc)));
1239 old_ioreq_state = CMD_STATE(sc);
1240 CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING;
1241 CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE;
1242 if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) {
1243 abt_tag = (tag | FNIC_TAG_DEV_RST);
1244 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1245 "fnic_rport_exch_reset dev rst sc 0x%p\n",
1249 BUG_ON(io_req->abts_done);
1251 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1252 "fnic_rport_reset_exch: Issuing abts\n");
1254 spin_unlock_irqrestore(io_lock, flags);
1256 /* Now queue the abort command to firmware */
1257 int_to_scsilun(sc->device->lun, &fc_lun);
1259 if (fnic_queue_abort_io_req(fnic, abt_tag,
1260 FCPIO_ITMF_ABT_TASK_TERM,
1261 fc_lun.scsi_lun, io_req)) {
1263 * Revert the cmd state back to old state, if
1264 * it hasn't changed in between. This cmd will get
1265 * aborted later by scsi_eh, or cleaned up during
1268 spin_lock_irqsave(io_lock, flags);
1269 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING)
1270 CMD_STATE(sc) = old_ioreq_state;
1271 spin_unlock_irqrestore(io_lock, flags);
1273 spin_lock_irqsave(io_lock, flags);
1274 CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED;
1275 spin_unlock_irqrestore(io_lock, flags);
1281 void fnic_terminate_rport_io(struct fc_rport *rport)
1285 struct fnic_io_req *io_req;
1286 spinlock_t *io_lock;
1287 unsigned long flags;
1288 struct scsi_cmnd *sc;
1289 struct scsi_lun fc_lun;
1290 struct fc_rport_libfc_priv *rdata = rport->dd_data;
1291 struct fc_lport *lport = rdata->local_port;
1292 struct fnic *fnic = lport_priv(lport);
1293 struct fc_rport *cmd_rport;
1294 enum fnic_ioreq_state old_ioreq_state;
1296 FNIC_SCSI_DBG(KERN_DEBUG,
1297 fnic->lport->host, "fnic_terminate_rport_io called"
1298 " wwpn 0x%llx, wwnn0x%llx, rport 0x%p, portid 0x%06x\n",
1299 rport->port_name, rport->node_name, rport,
1302 if (fnic->in_remove)
1305 for (tag = 0; tag < FNIC_MAX_IO_REQ; tag++) {
1307 sc = scsi_host_find_tag(fnic->lport->host, tag);
1311 cmd_rport = starget_to_rport(scsi_target(sc->device));
1312 if (rport != cmd_rport)
1315 io_lock = fnic_io_lock_hash(fnic, sc);
1316 spin_lock_irqsave(io_lock, flags);
1318 io_req = (struct fnic_io_req *)CMD_SP(sc);
1320 if (!io_req || rport != cmd_rport) {
1321 spin_unlock_irqrestore(io_lock, flags);
1325 if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) &&
1326 (!(CMD_FLAGS(sc) & FNIC_DEV_RST_PENDING))) {
1327 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1328 "fnic_terminate_rport_io dev rst not pending sc 0x%p\n",
1330 spin_unlock_irqrestore(io_lock, flags);
1334 * Found IO that is still pending with firmware and
1335 * belongs to rport that went away
1337 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) {
1338 spin_unlock_irqrestore(io_lock, flags);
1341 if (io_req->abts_done) {
1342 shost_printk(KERN_ERR, fnic->lport->host,
1343 "fnic_terminate_rport_io: io_req->abts_done is set "
1345 fnic_ioreq_state_to_str(CMD_STATE(sc)));
1347 old_ioreq_state = CMD_STATE(sc);
1348 CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING;
1349 CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE;
1350 if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) {
1351 abt_tag = (tag | FNIC_TAG_DEV_RST);
1352 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1353 "fnic_terminate_rport_io dev rst sc 0x%p\n", sc);
1356 BUG_ON(io_req->abts_done);
1358 FNIC_SCSI_DBG(KERN_DEBUG,
1360 "fnic_terminate_rport_io: Issuing abts\n");
1362 spin_unlock_irqrestore(io_lock, flags);
1364 /* Now queue the abort command to firmware */
1365 int_to_scsilun(sc->device->lun, &fc_lun);
1367 if (fnic_queue_abort_io_req(fnic, abt_tag,
1368 FCPIO_ITMF_ABT_TASK_TERM,
1369 fc_lun.scsi_lun, io_req)) {
1371 * Revert the cmd state back to old state, if
1372 * it hasn't changed in between. This cmd will get
1373 * aborted later by scsi_eh, or cleaned up during
1376 spin_lock_irqsave(io_lock, flags);
1377 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING)
1378 CMD_STATE(sc) = old_ioreq_state;
1379 spin_unlock_irqrestore(io_lock, flags);
1381 spin_lock_irqsave(io_lock, flags);
1382 CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED;
1383 spin_unlock_irqrestore(io_lock, flags);
1390 * This function is exported to SCSI for sending abort cmnds.
1391 * A SCSI IO is represented by a io_req in the driver.
1392 * The ioreq is linked to the SCSI Cmd, thus a link with the ULP's IO.
1394 int fnic_abort_cmd(struct scsi_cmnd *sc)
1396 struct fc_lport *lp;
1398 struct fnic_io_req *io_req;
1399 struct fc_rport *rport;
1400 spinlock_t *io_lock;
1401 unsigned long flags;
1404 struct scsi_lun fc_lun;
1406 DECLARE_COMPLETION_ONSTACK(tm_done);
1408 /* Wait for rport to unblock */
1409 fc_block_scsi_eh(sc);
1411 /* Get local-port, check ready and link up */
1412 lp = shost_priv(sc->device->host);
1414 fnic = lport_priv(lp);
1415 rport = starget_to_rport(scsi_target(sc->device));
1416 tag = sc->request->tag;
1417 FNIC_SCSI_DBG(KERN_DEBUG,
1419 "Abort Cmd called FCID 0x%x, LUN 0x%x TAG %x flags %x\n",
1420 rport->port_id, sc->device->lun, tag, CMD_FLAGS(sc));
1422 CMD_FLAGS(sc) = FNIC_NO_FLAGS;
1425 if (lp->state != LPORT_ST_READY || !(lp->link_up)) {
1427 goto fnic_abort_cmd_end;
1431 * Avoid a race between SCSI issuing the abort and the device
1432 * completing the command.
1434 * If the command is already completed by the fw cmpl code,
1435 * we just return SUCCESS from here. This means that the abort
1436 * succeeded. In the SCSI ML, since the timeout for command has
1437 * happened, the completion wont actually complete the command
1438 * and it will be considered as an aborted command
1440 * The CMD_SP will not be cleared except while holding io_req_lock.
1442 io_lock = fnic_io_lock_hash(fnic, sc);
1443 spin_lock_irqsave(io_lock, flags);
1444 io_req = (struct fnic_io_req *)CMD_SP(sc);
1446 spin_unlock_irqrestore(io_lock, flags);
1447 goto fnic_abort_cmd_end;
1450 io_req->abts_done = &tm_done;
1452 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) {
1453 spin_unlock_irqrestore(io_lock, flags);
1457 * Command is still pending, need to abort it
1458 * If the firmware completes the command after this point,
1459 * the completion wont be done till mid-layer, since abort
1460 * has already started.
1462 CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING;
1463 CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE;
1465 spin_unlock_irqrestore(io_lock, flags);
1468 * Check readiness of the remote port. If the path to remote
1469 * port is up, then send abts to the remote port to terminate
1470 * the IO. Else, just locally terminate the IO in the firmware
1472 if (fc_remote_port_chkready(rport) == 0)
1473 task_req = FCPIO_ITMF_ABT_TASK;
1475 task_req = FCPIO_ITMF_ABT_TASK_TERM;
1477 /* Now queue the abort command to firmware */
1478 int_to_scsilun(sc->device->lun, &fc_lun);
1480 if (fnic_queue_abort_io_req(fnic, sc->request->tag, task_req,
1481 fc_lun.scsi_lun, io_req)) {
1482 spin_lock_irqsave(io_lock, flags);
1483 io_req = (struct fnic_io_req *)CMD_SP(sc);
1485 io_req->abts_done = NULL;
1486 spin_unlock_irqrestore(io_lock, flags);
1488 goto fnic_abort_cmd_end;
1492 * We queued an abort IO, wait for its completion.
1493 * Once the firmware completes the abort command, it will
1494 * wake up this thread.
1497 wait_for_completion_timeout(&tm_done,
1499 (2 * fnic->config.ra_tov +
1500 fnic->config.ed_tov));
1502 /* Check the abort status */
1503 spin_lock_irqsave(io_lock, flags);
1505 io_req = (struct fnic_io_req *)CMD_SP(sc);
1507 spin_unlock_irqrestore(io_lock, flags);
1509 goto fnic_abort_cmd_end;
1511 io_req->abts_done = NULL;
1513 /* fw did not complete abort, timed out */
1514 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) {
1515 spin_unlock_irqrestore(io_lock, flags);
1517 goto fnic_abort_cmd_end;
1521 * firmware completed the abort, check the status,
1522 * free the io_req irrespective of failure or success
1524 if (CMD_ABTS_STATUS(sc) != FCPIO_SUCCESS)
1529 spin_unlock_irqrestore(io_lock, flags);
1531 fnic_release_ioreq_buf(fnic, io_req, sc);
1532 mempool_free(io_req, fnic->io_req_pool);
1535 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1536 "Returning from abort cmd %s\n",
1538 "SUCCESS" : "FAILED");
1542 static inline int fnic_queue_dr_io_req(struct fnic *fnic,
1543 struct scsi_cmnd *sc,
1544 struct fnic_io_req *io_req)
1546 struct vnic_wq_copy *wq = &fnic->wq_copy[0];
1547 struct Scsi_Host *host = fnic->lport->host;
1548 struct scsi_lun fc_lun;
1550 unsigned long intr_flags;
1552 spin_lock_irqsave(host->host_lock, intr_flags);
1553 if (unlikely(fnic_chk_state_flags_locked(fnic,
1554 FNIC_FLAGS_IO_BLOCKED))) {
1555 spin_unlock_irqrestore(host->host_lock, intr_flags);
1558 atomic_inc(&fnic->in_flight);
1559 spin_unlock_irqrestore(host->host_lock, intr_flags);
1561 spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags);
1563 if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0])
1564 free_wq_copy_descs(fnic, wq);
1566 if (!vnic_wq_copy_desc_avail(wq)) {
1571 /* fill in the lun info */
1572 int_to_scsilun(sc->device->lun, &fc_lun);
1574 fnic_queue_wq_copy_desc_itmf(wq, sc->request->tag | FNIC_TAG_DEV_RST,
1575 0, FCPIO_ITMF_LUN_RESET, SCSI_NO_TAG,
1576 fc_lun.scsi_lun, io_req->port_id,
1577 fnic->config.ra_tov, fnic->config.ed_tov);
1580 spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags);
1581 atomic_dec(&fnic->in_flight);
1587 * Clean up any pending aborts on the lun
1588 * For each outstanding IO on this lun, whose abort is not completed by fw,
1589 * issue a local abort. Wait for abort to complete. Return 0 if all commands
1590 * successfully aborted, 1 otherwise
1592 static int fnic_clean_pending_aborts(struct fnic *fnic,
1593 struct scsi_cmnd *lr_sc)
1596 struct fnic_io_req *io_req;
1597 spinlock_t *io_lock;
1598 unsigned long flags;
1600 struct scsi_cmnd *sc;
1601 struct scsi_lun fc_lun;
1602 struct scsi_device *lun_dev = lr_sc->device;
1603 DECLARE_COMPLETION_ONSTACK(tm_done);
1605 for (tag = 0; tag < FNIC_MAX_IO_REQ; tag++) {
1606 sc = scsi_host_find_tag(fnic->lport->host, tag);
1608 * ignore this lun reset cmd or cmds that do not belong to
1611 if (!sc || sc == lr_sc || sc->device != lun_dev)
1614 io_lock = fnic_io_lock_hash(fnic, sc);
1615 spin_lock_irqsave(io_lock, flags);
1617 io_req = (struct fnic_io_req *)CMD_SP(sc);
1619 if (!io_req || sc->device != lun_dev) {
1620 spin_unlock_irqrestore(io_lock, flags);
1625 * Found IO that is still pending with firmware and
1626 * belongs to the LUN that we are resetting
1628 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1629 "Found IO in %s on lun\n",
1630 fnic_ioreq_state_to_str(CMD_STATE(sc)));
1632 BUG_ON(CMD_STATE(sc) != FNIC_IOREQ_ABTS_PENDING);
1634 CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE;
1635 io_req->abts_done = &tm_done;
1636 spin_unlock_irqrestore(io_lock, flags);
1638 /* Now queue the abort command to firmware */
1639 int_to_scsilun(sc->device->lun, &fc_lun);
1641 if (fnic_queue_abort_io_req(fnic, tag,
1642 FCPIO_ITMF_ABT_TASK_TERM,
1643 fc_lun.scsi_lun, io_req)) {
1644 spin_lock_irqsave(io_lock, flags);
1645 io_req = (struct fnic_io_req *)CMD_SP(sc);
1647 io_req->abts_done = NULL;
1648 spin_unlock_irqrestore(io_lock, flags);
1650 goto clean_pending_aborts_end;
1653 wait_for_completion_timeout(&tm_done,
1655 (fnic->config.ed_tov));
1657 /* Recheck cmd state to check if it is now aborted */
1658 spin_lock_irqsave(io_lock, flags);
1659 io_req = (struct fnic_io_req *)CMD_SP(sc);
1661 spin_unlock_irqrestore(io_lock, flags);
1663 goto clean_pending_aborts_end;
1666 io_req->abts_done = NULL;
1668 /* if abort is still pending with fw, fail */
1669 if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) {
1670 spin_unlock_irqrestore(io_lock, flags);
1672 goto clean_pending_aborts_end;
1675 spin_unlock_irqrestore(io_lock, flags);
1677 fnic_release_ioreq_buf(fnic, io_req, sc);
1678 mempool_free(io_req, fnic->io_req_pool);
1681 clean_pending_aborts_end:
1686 * fnic_scsi_host_start_tag
1687 * Allocates tagid from host's tag list
1690 fnic_scsi_host_start_tag(struct fnic *fnic, struct scsi_cmnd *sc)
1692 struct blk_queue_tag *bqt = fnic->lport->host->bqt;
1693 int tag, ret = SCSI_NO_TAG;
1697 pr_err("Tags are not supported\n");
1702 tag = find_next_zero_bit(bqt->tag_map, bqt->max_depth, 1);
1703 if (tag >= bqt->max_depth) {
1704 pr_err("Tag allocation failure\n");
1707 } while (test_and_set_bit(tag, bqt->tag_map));
1709 bqt->tag_index[tag] = sc->request;
1710 sc->request->tag = tag;
1712 if (!sc->request->special)
1713 sc->request->special = sc;
1722 * fnic_scsi_host_end_tag
1723 * frees tag allocated by fnic_scsi_host_start_tag.
1726 fnic_scsi_host_end_tag(struct fnic *fnic, struct scsi_cmnd *sc)
1728 struct blk_queue_tag *bqt = fnic->lport->host->bqt;
1729 int tag = sc->request->tag;
1731 if (tag == SCSI_NO_TAG)
1734 BUG_ON(!bqt || !bqt->tag_index[tag]);
1738 bqt->tag_index[tag] = NULL;
1739 clear_bit(tag, bqt->tag_map);
1745 * SCSI Eh thread issues a Lun Reset when one or more commands on a LUN
1746 * fail to get aborted. It calls driver's eh_device_reset with a SCSI command
1749 int fnic_device_reset(struct scsi_cmnd *sc)
1751 struct fc_lport *lp;
1753 struct fnic_io_req *io_req;
1754 struct fc_rport *rport;
1757 spinlock_t *io_lock;
1758 unsigned long flags;
1759 struct scsi_lun fc_lun;
1761 DECLARE_COMPLETION_ONSTACK(tm_done);
1762 int tag_gen_flag = 0; /*to track tags allocated by fnic driver*/
1764 /* Wait for rport to unblock */
1765 fc_block_scsi_eh(sc);
1767 /* Get local-port, check ready and link up */
1768 lp = shost_priv(sc->device->host);
1770 fnic = lport_priv(lp);
1772 rport = starget_to_rport(scsi_target(sc->device));
1773 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1774 "Device reset called FCID 0x%x, LUN 0x%x sc 0x%p\n",
1775 rport->port_id, sc->device->lun, sc);
1777 if (lp->state != LPORT_ST_READY || !(lp->link_up))
1778 goto fnic_device_reset_end;
1780 /* Check if remote port up */
1781 if (fc_remote_port_chkready(rport))
1782 goto fnic_device_reset_end;
1784 CMD_FLAGS(sc) = (FNIC_DEVICE_RESET | FNIC_BLOCKING_REQ);
1785 /* Allocate tag if not present */
1787 tag = sc->request->tag;
1788 if (unlikely(tag < 0)) {
1789 tag = fnic_scsi_host_start_tag(fnic, sc);
1790 if (unlikely(tag == SCSI_NO_TAG))
1791 goto fnic_device_reset_end;
1794 io_lock = fnic_io_lock_hash(fnic, sc);
1795 spin_lock_irqsave(io_lock, flags);
1796 io_req = (struct fnic_io_req *)CMD_SP(sc);
1799 * If there is a io_req attached to this command, then use it,
1800 * else allocate a new one.
1803 io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC);
1805 spin_unlock_irqrestore(io_lock, flags);
1806 goto fnic_device_reset_end;
1808 memset(io_req, 0, sizeof(*io_req));
1809 io_req->port_id = rport->port_id;
1810 CMD_SP(sc) = (char *)io_req;
1812 io_req->dr_done = &tm_done;
1813 CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING;
1814 CMD_LR_STATUS(sc) = FCPIO_INVALID_CODE;
1815 spin_unlock_irqrestore(io_lock, flags);
1817 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "TAG %x\n", tag);
1820 * issue the device reset, if enqueue failed, clean up the ioreq
1821 * and break assoc with scsi cmd
1823 if (fnic_queue_dr_io_req(fnic, sc, io_req)) {
1824 spin_lock_irqsave(io_lock, flags);
1825 io_req = (struct fnic_io_req *)CMD_SP(sc);
1827 io_req->dr_done = NULL;
1828 goto fnic_device_reset_clean;
1830 spin_lock_irqsave(io_lock, flags);
1831 CMD_FLAGS(sc) |= FNIC_DEV_RST_PENDING;
1832 spin_unlock_irqrestore(io_lock, flags);
1835 * Wait on the local completion for LUN reset. The io_req may be
1836 * freed while we wait since we hold no lock.
1838 wait_for_completion_timeout(&tm_done,
1839 msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT));
1841 spin_lock_irqsave(io_lock, flags);
1842 io_req = (struct fnic_io_req *)CMD_SP(sc);
1844 spin_unlock_irqrestore(io_lock, flags);
1845 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1846 "io_req is null tag 0x%x sc 0x%p\n", tag, sc);
1847 goto fnic_device_reset_end;
1849 io_req->dr_done = NULL;
1851 status = CMD_LR_STATUS(sc);
1854 * If lun reset not completed, bail out with failed. io_req
1855 * gets cleaned up during higher levels of EH
1857 if (status == FCPIO_INVALID_CODE) {
1858 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1859 "Device reset timed out\n");
1860 CMD_FLAGS(sc) |= FNIC_DEV_RST_TIMED_OUT;
1861 spin_unlock_irqrestore(io_lock, flags);
1862 int_to_scsilun(sc->device->lun, &fc_lun);
1864 * Issue abort and terminate on the device reset request.
1865 * If q'ing of the abort fails, retry issue it after a delay.
1868 spin_lock_irqsave(io_lock, flags);
1869 if (CMD_FLAGS(sc) & FNIC_DEV_RST_TERM_ISSUED) {
1870 spin_unlock_irqrestore(io_lock, flags);
1873 spin_unlock_irqrestore(io_lock, flags);
1874 if (fnic_queue_abort_io_req(fnic,
1875 tag | FNIC_TAG_DEV_RST,
1876 FCPIO_ITMF_ABT_TASK_TERM,
1877 fc_lun.scsi_lun, io_req)) {
1878 wait_for_completion_timeout(&tm_done,
1879 msecs_to_jiffies(FNIC_ABT_TERM_DELAY_TIMEOUT));
1881 spin_lock_irqsave(io_lock, flags);
1882 CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED;
1883 CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING;
1884 io_req->abts_done = &tm_done;
1885 spin_unlock_irqrestore(io_lock, flags);
1886 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1887 "Abort and terminate issued on Device reset "
1888 "tag 0x%x sc 0x%p\n", tag, sc);
1893 spin_lock_irqsave(io_lock, flags);
1894 if (!(CMD_FLAGS(sc) & FNIC_DEV_RST_DONE)) {
1895 spin_unlock_irqrestore(io_lock, flags);
1896 wait_for_completion_timeout(&tm_done,
1897 msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT));
1900 io_req = (struct fnic_io_req *)CMD_SP(sc);
1901 io_req->abts_done = NULL;
1902 goto fnic_device_reset_clean;
1906 spin_unlock_irqrestore(io_lock, flags);
1909 /* Completed, but not successful, clean up the io_req, return fail */
1910 if (status != FCPIO_SUCCESS) {
1911 spin_lock_irqsave(io_lock, flags);
1912 FNIC_SCSI_DBG(KERN_DEBUG,
1914 "Device reset completed - failed\n");
1915 io_req = (struct fnic_io_req *)CMD_SP(sc);
1916 goto fnic_device_reset_clean;
1920 * Clean up any aborts on this lun that have still not
1921 * completed. If any of these fail, then LUN reset fails.
1922 * clean_pending_aborts cleans all cmds on this lun except
1923 * the lun reset cmd. If all cmds get cleaned, the lun reset
1926 if (fnic_clean_pending_aborts(fnic, sc)) {
1927 spin_lock_irqsave(io_lock, flags);
1928 io_req = (struct fnic_io_req *)CMD_SP(sc);
1929 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1930 "Device reset failed"
1931 " since could not abort all IOs\n");
1932 goto fnic_device_reset_clean;
1935 /* Clean lun reset command */
1936 spin_lock_irqsave(io_lock, flags);
1937 io_req = (struct fnic_io_req *)CMD_SP(sc);
1939 /* Completed, and successful */
1942 fnic_device_reset_clean:
1946 spin_unlock_irqrestore(io_lock, flags);
1949 fnic_release_ioreq_buf(fnic, io_req, sc);
1950 mempool_free(io_req, fnic->io_req_pool);
1953 fnic_device_reset_end:
1954 /* free tag if it is allocated */
1955 if (unlikely(tag_gen_flag))
1956 fnic_scsi_host_end_tag(fnic, sc);
1958 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1959 "Returning from device reset %s\n",
1961 "SUCCESS" : "FAILED");
1965 /* Clean up all IOs, clean up libFC local port */
1966 int fnic_reset(struct Scsi_Host *shost)
1968 struct fc_lport *lp;
1972 lp = shost_priv(shost);
1973 fnic = lport_priv(lp);
1975 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1976 "fnic_reset called\n");
1979 * Reset local port, this will clean up libFC exchanges,
1980 * reset remote port sessions, and if link is up, begin flogi
1982 if (lp->tt.lport_reset(lp))
1985 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
1986 "Returning from fnic reset %s\n",
1988 "SUCCESS" : "FAILED");
1994 * SCSI Error handling calls driver's eh_host_reset if all prior
1995 * error handling levels return FAILED. If host reset completes
1996 * successfully, and if link is up, then Fabric login begins.
1998 * Host Reset is the highest level of error recovery. If this fails, then
1999 * host is offlined by SCSI.
2002 int fnic_host_reset(struct scsi_cmnd *sc)
2005 unsigned long wait_host_tmo;
2006 struct Scsi_Host *shost = sc->device->host;
2007 struct fc_lport *lp = shost_priv(shost);
2010 * If fnic_reset is successful, wait for fabric login to complete
2011 * scsi-ml tries to send a TUR to every device if host reset is
2012 * successful, so before returning to scsi, fabric should be up
2014 ret = fnic_reset(shost);
2015 if (ret == SUCCESS) {
2016 wait_host_tmo = jiffies + FNIC_HOST_RESET_SETTLE_TIME * HZ;
2018 while (time_before(jiffies, wait_host_tmo)) {
2019 if ((lp->state == LPORT_ST_READY) &&
2032 * This fxn is called from libFC when host is removed
2034 void fnic_scsi_abort_io(struct fc_lport *lp)
2037 unsigned long flags;
2038 enum fnic_state old_state;
2039 struct fnic *fnic = lport_priv(lp);
2040 DECLARE_COMPLETION_ONSTACK(remove_wait);
2042 /* Issue firmware reset for fnic, wait for reset to complete */
2044 spin_lock_irqsave(&fnic->fnic_lock, flags);
2045 if (unlikely(fnic->state == FNIC_IN_FC_TRANS_ETH_MODE)) {
2046 /* fw reset is in progress, poll for its completion */
2047 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2048 schedule_timeout(msecs_to_jiffies(100));
2049 goto retry_fw_reset;
2052 fnic->remove_wait = &remove_wait;
2053 old_state = fnic->state;
2054 fnic->state = FNIC_IN_FC_TRANS_ETH_MODE;
2055 fnic_update_mac_locked(fnic, fnic->ctlr.ctl_src_addr);
2056 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2058 err = fnic_fw_reset_handler(fnic);
2060 spin_lock_irqsave(&fnic->fnic_lock, flags);
2061 if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE)
2062 fnic->state = old_state;
2063 fnic->remove_wait = NULL;
2064 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2068 /* Wait for firmware reset to complete */
2069 wait_for_completion_timeout(&remove_wait,
2070 msecs_to_jiffies(FNIC_RMDEVICE_TIMEOUT));
2072 spin_lock_irqsave(&fnic->fnic_lock, flags);
2073 fnic->remove_wait = NULL;
2074 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
2075 "fnic_scsi_abort_io %s\n",
2076 (fnic->state == FNIC_IN_ETH_MODE) ?
2077 "SUCCESS" : "FAILED");
2078 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2083 * This fxn called from libFC to clean up driver IO state on link down
2085 void fnic_scsi_cleanup(struct fc_lport *lp)
2087 unsigned long flags;
2088 enum fnic_state old_state;
2089 struct fnic *fnic = lport_priv(lp);
2091 /* issue fw reset */
2093 spin_lock_irqsave(&fnic->fnic_lock, flags);
2094 if (unlikely(fnic->state == FNIC_IN_FC_TRANS_ETH_MODE)) {
2095 /* fw reset is in progress, poll for its completion */
2096 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2097 schedule_timeout(msecs_to_jiffies(100));
2098 goto retry_fw_reset;
2100 old_state = fnic->state;
2101 fnic->state = FNIC_IN_FC_TRANS_ETH_MODE;
2102 fnic_update_mac_locked(fnic, fnic->ctlr.ctl_src_addr);
2103 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2105 if (fnic_fw_reset_handler(fnic)) {
2106 spin_lock_irqsave(&fnic->fnic_lock, flags);
2107 if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE)
2108 fnic->state = old_state;
2109 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2114 void fnic_empty_scsi_cleanup(struct fc_lport *lp)
2118 void fnic_exch_mgr_reset(struct fc_lport *lp, u32 sid, u32 did)
2120 struct fnic *fnic = lport_priv(lp);
2122 /* Non-zero sid, nothing to do */
2124 goto call_fc_exch_mgr_reset;
2127 fnic_rport_exch_reset(fnic, did);
2128 goto call_fc_exch_mgr_reset;
2133 * link down or device being removed
2135 if (!fnic->in_remove)
2136 fnic_scsi_cleanup(lp);
2138 fnic_scsi_abort_io(lp);
2140 /* call libFC exch mgr reset to reset its exchanges */
2141 call_fc_exch_mgr_reset:
2142 fc_exch_mgr_reset(lp, sid, did);