1 /* bnx2fc_io.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * IO manager and SCSI IO processing.
4 * Copyright (c) 2008 - 2013 Broadcom Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
10 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
15 #define RESERVE_FREE_LIST_INDEX num_possible_cpus()
17 static int bnx2fc_split_bd(struct bnx2fc_cmd *io_req, u64 addr, int sg_len,
19 static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req);
20 static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req);
21 static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req);
22 static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req);
23 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
24 struct fcoe_fcp_rsp_payload *fcp_rsp,
27 void bnx2fc_cmd_timer_set(struct bnx2fc_cmd *io_req,
28 unsigned int timer_msec)
30 struct bnx2fc_interface *interface = io_req->port->priv;
32 if (queue_delayed_work(interface->timer_work_queue,
33 &io_req->timeout_work,
34 msecs_to_jiffies(timer_msec)))
35 kref_get(&io_req->refcount);
38 static void bnx2fc_cmd_timeout(struct work_struct *work)
40 struct bnx2fc_cmd *io_req = container_of(work, struct bnx2fc_cmd,
42 struct fc_lport *lport;
43 struct fc_rport_priv *rdata;
44 u8 cmd_type = io_req->cmd_type;
45 struct bnx2fc_rport *tgt = io_req->tgt;
49 BNX2FC_IO_DBG(io_req, "cmd_timeout, cmd_type = %d,"
50 "req_flags = %lx\n", cmd_type, io_req->req_flags);
52 spin_lock_bh(&tgt->tgt_lock);
53 if (test_and_clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags)) {
54 clear_bit(BNX2FC_FLAG_RETIRE_OXID, &io_req->req_flags);
56 * ideally we should hold the io_req until RRQ complets,
57 * and release io_req from timeout hold.
59 spin_unlock_bh(&tgt->tgt_lock);
60 bnx2fc_send_rrq(io_req);
63 if (test_and_clear_bit(BNX2FC_FLAG_RETIRE_OXID, &io_req->req_flags)) {
64 BNX2FC_IO_DBG(io_req, "IO ready for reuse now\n");
70 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
71 &io_req->req_flags)) {
72 /* Handle eh_abort timeout */
73 BNX2FC_IO_DBG(io_req, "eh_abort timed out\n");
74 complete(&io_req->tm_done);
75 } else if (test_bit(BNX2FC_FLAG_ISSUE_ABTS,
76 &io_req->req_flags)) {
77 /* Handle internally generated ABTS timeout */
78 BNX2FC_IO_DBG(io_req, "ABTS timed out refcnt = %d\n",
79 io_req->refcount.refcount.counter);
80 if (!(test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
81 &io_req->req_flags))) {
83 lport = io_req->port->lport;
84 rdata = io_req->tgt->rdata;
85 logo_issued = test_and_set_bit(
86 BNX2FC_FLAG_EXPL_LOGO,
88 kref_put(&io_req->refcount, bnx2fc_cmd_release);
89 spin_unlock_bh(&tgt->tgt_lock);
91 /* Explicitly logo the target */
93 BNX2FC_IO_DBG(io_req, "Explicit "
94 "logo - tgt flags = 0x%lx\n",
97 mutex_lock(&lport->disc.disc_mutex);
98 lport->tt.rport_logoff(rdata);
99 mutex_unlock(&lport->disc.disc_mutex);
104 /* Hanlde IO timeout */
105 BNX2FC_IO_DBG(io_req, "IO timed out. issue ABTS\n");
106 if (test_and_set_bit(BNX2FC_FLAG_IO_COMPL,
107 &io_req->req_flags)) {
108 BNX2FC_IO_DBG(io_req, "IO completed before "
113 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
114 &io_req->req_flags)) {
115 rc = bnx2fc_initiate_abts(io_req);
119 * Explicitly logo the target if
120 * abts initiation fails
122 lport = io_req->port->lport;
123 rdata = io_req->tgt->rdata;
124 logo_issued = test_and_set_bit(
125 BNX2FC_FLAG_EXPL_LOGO,
127 kref_put(&io_req->refcount, bnx2fc_cmd_release);
128 spin_unlock_bh(&tgt->tgt_lock);
131 BNX2FC_IO_DBG(io_req, "Explicit "
132 "logo - tgt flags = 0x%lx\n",
136 mutex_lock(&lport->disc.disc_mutex);
137 lport->tt.rport_logoff(rdata);
138 mutex_unlock(&lport->disc.disc_mutex);
142 BNX2FC_IO_DBG(io_req, "IO already in "
143 "ABTS processing\n");
149 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
150 BNX2FC_IO_DBG(io_req, "ABTS for ELS timed out\n");
152 if (!test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
153 &io_req->req_flags)) {
154 lport = io_req->port->lport;
155 rdata = io_req->tgt->rdata;
156 logo_issued = test_and_set_bit(
157 BNX2FC_FLAG_EXPL_LOGO,
159 kref_put(&io_req->refcount, bnx2fc_cmd_release);
160 spin_unlock_bh(&tgt->tgt_lock);
162 /* Explicitly logo the target */
164 BNX2FC_IO_DBG(io_req, "Explicitly logo"
166 mutex_lock(&lport->disc.disc_mutex);
167 lport->tt.rport_logoff(rdata);
168 mutex_unlock(&lport->disc.disc_mutex);
174 * Handle ELS timeout.
175 * tgt_lock is used to sync compl path and timeout
176 * path. If els compl path is processing this IO, we
177 * have nothing to do here, just release the timer hold
179 BNX2FC_IO_DBG(io_req, "ELS timed out\n");
180 if (test_and_set_bit(BNX2FC_FLAG_ELS_DONE,
184 /* Indicate the cb_func that this ELS is timed out */
185 set_bit(BNX2FC_FLAG_ELS_TIMEOUT, &io_req->req_flags);
187 if ((io_req->cb_func) && (io_req->cb_arg)) {
188 io_req->cb_func(io_req->cb_arg);
189 io_req->cb_arg = NULL;
194 printk(KERN_ERR PFX "cmd_timeout: invalid cmd_type %d\n",
200 /* release the cmd that was held when timer was set */
201 kref_put(&io_req->refcount, bnx2fc_cmd_release);
202 spin_unlock_bh(&tgt->tgt_lock);
205 static void bnx2fc_scsi_done(struct bnx2fc_cmd *io_req, int err_code)
207 /* Called with host lock held */
208 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
211 * active_cmd_queue may have other command types as well,
212 * and during flush operation, we want to error back only
215 if (io_req->cmd_type != BNX2FC_SCSI_CMD)
218 BNX2FC_IO_DBG(io_req, "scsi_done. err_code = 0x%x\n", err_code);
219 if (test_bit(BNX2FC_FLAG_CMD_LOST, &io_req->req_flags)) {
220 /* Do not call scsi done for this IO */
224 bnx2fc_unmap_sg_list(io_req);
225 io_req->sc_cmd = NULL;
227 printk(KERN_ERR PFX "scsi_done - sc_cmd NULL. "
228 "IO(0x%x) already cleaned up\n",
232 sc_cmd->result = err_code << 16;
234 BNX2FC_IO_DBG(io_req, "sc=%p, result=0x%x, retries=%d, allowed=%d\n",
235 sc_cmd, host_byte(sc_cmd->result), sc_cmd->retries,
237 scsi_set_resid(sc_cmd, scsi_bufflen(sc_cmd));
238 sc_cmd->SCp.ptr = NULL;
239 sc_cmd->scsi_done(sc_cmd);
242 struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba)
244 struct bnx2fc_cmd_mgr *cmgr;
245 struct io_bdt *bdt_info;
246 struct bnx2fc_cmd *io_req;
251 int num_ios, num_pri_ios;
253 int arr_sz = num_possible_cpus() + 1;
254 u16 min_xid = BNX2FC_MIN_XID;
255 u16 max_xid = hba->max_xid;
257 if (max_xid <= min_xid || max_xid == FC_XID_UNKNOWN) {
258 printk(KERN_ERR PFX "cmd_mgr_alloc: Invalid min_xid 0x%x \
259 and max_xid 0x%x\n", min_xid, max_xid);
262 BNX2FC_MISC_DBG("min xid 0x%x, max xid 0x%x\n", min_xid, max_xid);
264 num_ios = max_xid - min_xid + 1;
265 len = (num_ios * (sizeof(struct bnx2fc_cmd *)));
266 len += sizeof(struct bnx2fc_cmd_mgr);
268 cmgr = kzalloc(len, GFP_KERNEL);
270 printk(KERN_ERR PFX "failed to alloc cmgr\n");
274 cmgr->free_list = kzalloc(sizeof(*cmgr->free_list) *
276 if (!cmgr->free_list) {
277 printk(KERN_ERR PFX "failed to alloc free_list\n");
281 cmgr->free_list_lock = kzalloc(sizeof(*cmgr->free_list_lock) *
283 if (!cmgr->free_list_lock) {
284 printk(KERN_ERR PFX "failed to alloc free_list_lock\n");
285 kfree(cmgr->free_list);
286 cmgr->free_list = NULL;
291 cmgr->cmds = (struct bnx2fc_cmd **)(cmgr + 1);
293 for (i = 0; i < arr_sz; i++) {
294 INIT_LIST_HEAD(&cmgr->free_list[i]);
295 spin_lock_init(&cmgr->free_list_lock[i]);
299 * Pre-allocated pool of bnx2fc_cmds.
300 * Last entry in the free list array is the free list
301 * of slow path requests.
303 xid = BNX2FC_MIN_XID;
304 num_pri_ios = num_ios - hba->elstm_xids;
305 for (i = 0; i < num_ios; i++) {
306 io_req = kzalloc(sizeof(*io_req), GFP_KERNEL);
309 printk(KERN_ERR PFX "failed to alloc io_req\n");
313 INIT_LIST_HEAD(&io_req->link);
314 INIT_DELAYED_WORK(&io_req->timeout_work, bnx2fc_cmd_timeout);
318 list_add_tail(&io_req->link,
319 &cmgr->free_list[io_req->xid %
320 num_possible_cpus()]);
322 list_add_tail(&io_req->link,
323 &cmgr->free_list[num_possible_cpus()]);
327 /* Allocate pool of io_bdts - one for each bnx2fc_cmd */
328 mem_size = num_ios * sizeof(struct io_bdt *);
329 cmgr->io_bdt_pool = kmalloc(mem_size, GFP_KERNEL);
330 if (!cmgr->io_bdt_pool) {
331 printk(KERN_ERR PFX "failed to alloc io_bdt_pool\n");
335 mem_size = sizeof(struct io_bdt);
336 for (i = 0; i < num_ios; i++) {
337 cmgr->io_bdt_pool[i] = kmalloc(mem_size, GFP_KERNEL);
338 if (!cmgr->io_bdt_pool[i]) {
339 printk(KERN_ERR PFX "failed to alloc "
340 "io_bdt_pool[%d]\n", i);
345 /* Allocate an map fcoe_bdt_ctx structures */
346 bd_tbl_sz = BNX2FC_MAX_BDS_PER_CMD * sizeof(struct fcoe_bd_ctx);
347 for (i = 0; i < num_ios; i++) {
348 bdt_info = cmgr->io_bdt_pool[i];
349 bdt_info->bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
351 &bdt_info->bd_tbl_dma,
353 if (!bdt_info->bd_tbl) {
354 printk(KERN_ERR PFX "failed to alloc "
363 bnx2fc_cmd_mgr_free(cmgr);
367 void bnx2fc_cmd_mgr_free(struct bnx2fc_cmd_mgr *cmgr)
369 struct io_bdt *bdt_info;
370 struct bnx2fc_hba *hba = cmgr->hba;
372 u16 min_xid = BNX2FC_MIN_XID;
373 u16 max_xid = hba->max_xid;
377 num_ios = max_xid - min_xid + 1;
379 /* Free fcoe_bdt_ctx structures */
380 if (!cmgr->io_bdt_pool)
383 bd_tbl_sz = BNX2FC_MAX_BDS_PER_CMD * sizeof(struct fcoe_bd_ctx);
384 for (i = 0; i < num_ios; i++) {
385 bdt_info = cmgr->io_bdt_pool[i];
386 if (bdt_info->bd_tbl) {
387 dma_free_coherent(&hba->pcidev->dev, bd_tbl_sz,
389 bdt_info->bd_tbl_dma);
390 bdt_info->bd_tbl = NULL;
394 /* Destroy io_bdt pool */
395 for (i = 0; i < num_ios; i++) {
396 kfree(cmgr->io_bdt_pool[i]);
397 cmgr->io_bdt_pool[i] = NULL;
400 kfree(cmgr->io_bdt_pool);
401 cmgr->io_bdt_pool = NULL;
404 kfree(cmgr->free_list_lock);
406 /* Destroy cmd pool */
407 if (!cmgr->free_list)
410 for (i = 0; i < num_possible_cpus() + 1; i++) {
411 struct bnx2fc_cmd *tmp, *io_req;
413 list_for_each_entry_safe(io_req, tmp,
414 &cmgr->free_list[i], link) {
415 list_del(&io_req->link);
419 kfree(cmgr->free_list);
421 /* Free command manager itself */
425 struct bnx2fc_cmd *bnx2fc_elstm_alloc(struct bnx2fc_rport *tgt, int type)
427 struct fcoe_port *port = tgt->port;
428 struct bnx2fc_interface *interface = port->priv;
429 struct bnx2fc_cmd_mgr *cmd_mgr = interface->hba->cmd_mgr;
430 struct bnx2fc_cmd *io_req;
431 struct list_head *listp;
432 struct io_bdt *bd_tbl;
433 int index = RESERVE_FREE_LIST_INDEX;
438 max_sqes = tgt->max_sqes;
440 case BNX2FC_TASK_MGMT_CMD:
441 max_sqes = BNX2FC_TM_MAX_SQES;
444 max_sqes = BNX2FC_ELS_MAX_SQES;
451 * NOTE: Free list insertions and deletions are protected with
454 spin_lock_bh(&cmd_mgr->free_list_lock[index]);
455 free_sqes = atomic_read(&tgt->free_sqes);
456 if ((list_empty(&(cmd_mgr->free_list[index]))) ||
457 (tgt->num_active_ios.counter >= max_sqes) ||
458 (free_sqes + max_sqes <= BNX2FC_SQ_WQES_MAX)) {
459 BNX2FC_TGT_DBG(tgt, "No free els_tm cmds available "
460 "ios(%d):sqes(%d)\n",
461 tgt->num_active_ios.counter, tgt->max_sqes);
462 if (list_empty(&(cmd_mgr->free_list[index])))
463 printk(KERN_ERR PFX "elstm_alloc: list_empty\n");
464 spin_unlock_bh(&cmd_mgr->free_list_lock[index]);
468 listp = (struct list_head *)
469 cmd_mgr->free_list[index].next;
470 list_del_init(listp);
471 io_req = (struct bnx2fc_cmd *) listp;
473 cmd_mgr->cmds[xid] = io_req;
474 atomic_inc(&tgt->num_active_ios);
475 atomic_dec(&tgt->free_sqes);
476 spin_unlock_bh(&cmd_mgr->free_list_lock[index]);
478 INIT_LIST_HEAD(&io_req->link);
481 io_req->cmd_mgr = cmd_mgr;
482 io_req->req_flags = 0;
483 io_req->cmd_type = type;
485 /* Bind io_bdt for this io_req */
486 /* Have a static link between io_req and io_bdt_pool */
487 bd_tbl = io_req->bd_tbl = cmd_mgr->io_bdt_pool[xid];
488 bd_tbl->io_req = io_req;
490 /* Hold the io_req against deletion */
491 kref_init(&io_req->refcount);
495 struct bnx2fc_cmd *bnx2fc_cmd_alloc(struct bnx2fc_rport *tgt)
497 struct fcoe_port *port = tgt->port;
498 struct bnx2fc_interface *interface = port->priv;
499 struct bnx2fc_cmd_mgr *cmd_mgr = interface->hba->cmd_mgr;
500 struct bnx2fc_cmd *io_req;
501 struct list_head *listp;
502 struct io_bdt *bd_tbl;
506 int index = get_cpu();
508 max_sqes = BNX2FC_SCSI_MAX_SQES;
510 * NOTE: Free list insertions and deletions are protected with
513 spin_lock_bh(&cmd_mgr->free_list_lock[index]);
514 free_sqes = atomic_read(&tgt->free_sqes);
515 if ((list_empty(&cmd_mgr->free_list[index])) ||
516 (tgt->num_active_ios.counter >= max_sqes) ||
517 (free_sqes + max_sqes <= BNX2FC_SQ_WQES_MAX)) {
518 spin_unlock_bh(&cmd_mgr->free_list_lock[index]);
523 listp = (struct list_head *)
524 cmd_mgr->free_list[index].next;
525 list_del_init(listp);
526 io_req = (struct bnx2fc_cmd *) listp;
528 cmd_mgr->cmds[xid] = io_req;
529 atomic_inc(&tgt->num_active_ios);
530 atomic_dec(&tgt->free_sqes);
531 spin_unlock_bh(&cmd_mgr->free_list_lock[index]);
534 INIT_LIST_HEAD(&io_req->link);
537 io_req->cmd_mgr = cmd_mgr;
538 io_req->req_flags = 0;
540 /* Bind io_bdt for this io_req */
541 /* Have a static link between io_req and io_bdt_pool */
542 bd_tbl = io_req->bd_tbl = cmd_mgr->io_bdt_pool[xid];
543 bd_tbl->io_req = io_req;
545 /* Hold the io_req against deletion */
546 kref_init(&io_req->refcount);
550 void bnx2fc_cmd_release(struct kref *ref)
552 struct bnx2fc_cmd *io_req = container_of(ref,
553 struct bnx2fc_cmd, refcount);
554 struct bnx2fc_cmd_mgr *cmd_mgr = io_req->cmd_mgr;
557 if (io_req->cmd_type == BNX2FC_SCSI_CMD)
558 index = io_req->xid % num_possible_cpus();
560 index = RESERVE_FREE_LIST_INDEX;
563 spin_lock_bh(&cmd_mgr->free_list_lock[index]);
564 if (io_req->cmd_type != BNX2FC_SCSI_CMD)
565 bnx2fc_free_mp_resc(io_req);
566 cmd_mgr->cmds[io_req->xid] = NULL;
567 /* Delete IO from retire queue */
568 list_del_init(&io_req->link);
569 /* Add it to the free list */
570 list_add(&io_req->link,
571 &cmd_mgr->free_list[index]);
572 atomic_dec(&io_req->tgt->num_active_ios);
573 spin_unlock_bh(&cmd_mgr->free_list_lock[index]);
577 static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req)
579 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
580 struct bnx2fc_interface *interface = io_req->port->priv;
581 struct bnx2fc_hba *hba = interface->hba;
582 size_t sz = sizeof(struct fcoe_bd_ctx);
585 mp_req->tm_flags = 0;
586 if (mp_req->mp_req_bd) {
587 dma_free_coherent(&hba->pcidev->dev, sz,
589 mp_req->mp_req_bd_dma);
590 mp_req->mp_req_bd = NULL;
592 if (mp_req->mp_resp_bd) {
593 dma_free_coherent(&hba->pcidev->dev, sz,
595 mp_req->mp_resp_bd_dma);
596 mp_req->mp_resp_bd = NULL;
598 if (mp_req->req_buf) {
599 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
601 mp_req->req_buf_dma);
602 mp_req->req_buf = NULL;
604 if (mp_req->resp_buf) {
605 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
607 mp_req->resp_buf_dma);
608 mp_req->resp_buf = NULL;
612 int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
614 struct bnx2fc_mp_req *mp_req;
615 struct fcoe_bd_ctx *mp_req_bd;
616 struct fcoe_bd_ctx *mp_resp_bd;
617 struct bnx2fc_interface *interface = io_req->port->priv;
618 struct bnx2fc_hba *hba = interface->hba;
622 mp_req = (struct bnx2fc_mp_req *)&(io_req->mp_req);
623 memset(mp_req, 0, sizeof(struct bnx2fc_mp_req));
625 mp_req->req_len = sizeof(struct fcp_cmnd);
626 io_req->data_xfer_len = mp_req->req_len;
627 mp_req->req_buf = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
628 &mp_req->req_buf_dma,
630 if (!mp_req->req_buf) {
631 printk(KERN_ERR PFX "unable to alloc MP req buffer\n");
632 bnx2fc_free_mp_resc(io_req);
636 mp_req->resp_buf = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
637 &mp_req->resp_buf_dma,
639 if (!mp_req->resp_buf) {
640 printk(KERN_ERR PFX "unable to alloc TM resp buffer\n");
641 bnx2fc_free_mp_resc(io_req);
644 memset(mp_req->req_buf, 0, CNIC_PAGE_SIZE);
645 memset(mp_req->resp_buf, 0, CNIC_PAGE_SIZE);
647 /* Allocate and map mp_req_bd and mp_resp_bd */
648 sz = sizeof(struct fcoe_bd_ctx);
649 mp_req->mp_req_bd = dma_alloc_coherent(&hba->pcidev->dev, sz,
650 &mp_req->mp_req_bd_dma,
652 if (!mp_req->mp_req_bd) {
653 printk(KERN_ERR PFX "unable to alloc MP req bd\n");
654 bnx2fc_free_mp_resc(io_req);
657 mp_req->mp_resp_bd = dma_alloc_coherent(&hba->pcidev->dev, sz,
658 &mp_req->mp_resp_bd_dma,
660 if (!mp_req->mp_resp_bd) {
661 printk(KERN_ERR PFX "unable to alloc MP resp bd\n");
662 bnx2fc_free_mp_resc(io_req);
666 addr = mp_req->req_buf_dma;
667 mp_req_bd = mp_req->mp_req_bd;
668 mp_req_bd->buf_addr_lo = (u32)addr & 0xffffffff;
669 mp_req_bd->buf_addr_hi = (u32)((u64)addr >> 32);
670 mp_req_bd->buf_len = CNIC_PAGE_SIZE;
671 mp_req_bd->flags = 0;
674 * MP buffer is either a task mgmt command or an ELS.
675 * So the assumption is that it consumes a single bd
676 * entry in the bd table
678 mp_resp_bd = mp_req->mp_resp_bd;
679 addr = mp_req->resp_buf_dma;
680 mp_resp_bd->buf_addr_lo = (u32)addr & 0xffffffff;
681 mp_resp_bd->buf_addr_hi = (u32)((u64)addr >> 32);
682 mp_resp_bd->buf_len = CNIC_PAGE_SIZE;
683 mp_resp_bd->flags = 0;
688 static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
690 struct fc_lport *lport;
691 struct fc_rport *rport;
692 struct fc_rport_libfc_priv *rp;
693 struct fcoe_port *port;
694 struct bnx2fc_interface *interface;
695 struct bnx2fc_rport *tgt;
696 struct bnx2fc_cmd *io_req;
697 struct bnx2fc_mp_req *tm_req;
698 struct fcoe_task_ctx_entry *task;
699 struct fcoe_task_ctx_entry *task_page;
700 struct Scsi_Host *host = sc_cmd->device->host;
701 struct fc_frame_header *fc_hdr;
702 struct fcp_cmnd *fcp_cmnd;
707 unsigned long start = jiffies;
709 lport = shost_priv(host);
710 rport = starget_to_rport(scsi_target(sc_cmd->device));
711 port = lport_priv(lport);
712 interface = port->priv;
715 printk(KERN_ERR PFX "device_reset: rport is NULL\n");
721 rc = fc_block_scsi_eh(sc_cmd);
725 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
726 printk(KERN_ERR PFX "device_reset: link is not ready\n");
730 /* rport and tgt are allocated together, so tgt should be non-NULL */
731 tgt = (struct bnx2fc_rport *)&rp[1];
733 if (!(test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
734 printk(KERN_ERR PFX "device_reset: tgt not offloaded\n");
739 io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_TASK_MGMT_CMD);
741 if (time_after(jiffies, start + HZ)) {
742 printk(KERN_ERR PFX "tmf: Failed TMF");
749 /* Initialize rest of io_req fields */
750 io_req->sc_cmd = sc_cmd;
754 tm_req = (struct bnx2fc_mp_req *)&(io_req->mp_req);
756 rc = bnx2fc_init_mp_req(io_req);
758 printk(KERN_ERR PFX "Task mgmt MP request init failed\n");
759 spin_lock_bh(&tgt->tgt_lock);
760 kref_put(&io_req->refcount, bnx2fc_cmd_release);
761 spin_unlock_bh(&tgt->tgt_lock);
766 io_req->io_req_flags = 0;
767 tm_req->tm_flags = tm_flags;
770 bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)tm_req->req_buf);
771 fcp_cmnd = (struct fcp_cmnd *)tm_req->req_buf;
772 memset(fcp_cmnd->fc_cdb, 0, sc_cmd->cmd_len);
776 fc_hdr = &(tm_req->req_fc_hdr);
778 did = rport->port_id;
779 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_DD_UNSOL_CMD, did, sid,
780 FC_TYPE_FCP, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
782 /* Obtain exchange id */
785 BNX2FC_TGT_DBG(tgt, "Initiate TMF - xid = 0x%x\n", xid);
786 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
787 index = xid % BNX2FC_TASKS_PER_PAGE;
789 /* Initialize task context for this IO request */
790 task_page = (struct fcoe_task_ctx_entry *)
791 interface->hba->task_ctx[task_idx];
792 task = &(task_page[index]);
793 bnx2fc_init_mp_task(io_req, task);
795 sc_cmd->SCp.ptr = (char *)io_req;
797 /* Obtain free SQ entry */
798 spin_lock_bh(&tgt->tgt_lock);
799 bnx2fc_add_2_sq(tgt, xid);
801 /* Enqueue the io_req to active_tm_queue */
802 io_req->on_tmf_queue = 1;
803 list_add_tail(&io_req->link, &tgt->active_tm_queue);
805 init_completion(&io_req->tm_done);
806 io_req->wait_for_comp = 1;
809 bnx2fc_ring_doorbell(tgt);
810 spin_unlock_bh(&tgt->tgt_lock);
812 rc = wait_for_completion_timeout(&io_req->tm_done,
813 BNX2FC_TM_TIMEOUT * HZ);
814 spin_lock_bh(&tgt->tgt_lock);
816 io_req->wait_for_comp = 0;
817 if (!(test_bit(BNX2FC_FLAG_TM_COMPL, &io_req->req_flags))) {
818 set_bit(BNX2FC_FLAG_TM_TIMEOUT, &io_req->req_flags);
819 if (io_req->on_tmf_queue) {
820 list_del_init(&io_req->link);
821 io_req->on_tmf_queue = 0;
823 io_req->wait_for_comp = 1;
824 bnx2fc_initiate_cleanup(io_req);
825 spin_unlock_bh(&tgt->tgt_lock);
826 rc = wait_for_completion_timeout(&io_req->tm_done,
828 spin_lock_bh(&tgt->tgt_lock);
829 io_req->wait_for_comp = 0;
831 kref_put(&io_req->refcount, bnx2fc_cmd_release);
834 spin_unlock_bh(&tgt->tgt_lock);
837 BNX2FC_TGT_DBG(tgt, "task mgmt command failed...\n");
840 BNX2FC_TGT_DBG(tgt, "task mgmt command success...\n");
847 int bnx2fc_initiate_abts(struct bnx2fc_cmd *io_req)
849 struct fc_lport *lport;
850 struct bnx2fc_rport *tgt = io_req->tgt;
851 struct fc_rport *rport = tgt->rport;
852 struct fc_rport_priv *rdata = tgt->rdata;
853 struct bnx2fc_interface *interface;
854 struct fcoe_port *port;
855 struct bnx2fc_cmd *abts_io_req;
856 struct fcoe_task_ctx_entry *task;
857 struct fcoe_task_ctx_entry *task_page;
858 struct fc_frame_header *fc_hdr;
859 struct bnx2fc_mp_req *abts_req;
864 u32 r_a_tov = rdata->r_a_tov;
866 /* called with tgt_lock held */
867 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_abts\n");
870 interface = port->priv;
873 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
874 printk(KERN_ERR PFX "initiate_abts: tgt not offloaded\n");
880 printk(KERN_ERR PFX "initiate_abts: rport is NULL\n");
885 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
886 printk(KERN_ERR PFX "initiate_abts: link is not ready\n");
891 abts_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_ABTS);
893 printk(KERN_ERR PFX "abts: couldnt allocate cmd\n");
898 /* Initialize rest of io_req fields */
899 abts_io_req->sc_cmd = NULL;
900 abts_io_req->port = port;
901 abts_io_req->tgt = tgt;
902 abts_io_req->data_xfer_len = 0; /* No data transfer for ABTS */
904 abts_req = (struct bnx2fc_mp_req *)&(abts_io_req->mp_req);
905 memset(abts_req, 0, sizeof(struct bnx2fc_mp_req));
908 fc_hdr = &(abts_req->req_fc_hdr);
910 /* Obtain oxid and rxid for the original exchange to be aborted */
911 fc_hdr->fh_ox_id = htons(io_req->xid);
912 fc_hdr->fh_rx_id = htons(io_req->task->rxwr_txrd.var_ctx.rx_id);
915 did = rport->port_id;
917 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_BA_ABTS, did, sid,
918 FC_TYPE_BLS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
921 xid = abts_io_req->xid;
922 BNX2FC_IO_DBG(abts_io_req, "ABTS io_req\n");
923 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
924 index = xid % BNX2FC_TASKS_PER_PAGE;
926 /* Initialize task context for this IO request */
927 task_page = (struct fcoe_task_ctx_entry *)
928 interface->hba->task_ctx[task_idx];
929 task = &(task_page[index]);
930 bnx2fc_init_mp_task(abts_io_req, task);
933 * ABTS task is a temporary task that will be cleaned up
934 * irrespective of ABTS response. We need to start the timer
935 * for the original exchange, as the CQE is posted for the original
938 * Timer for ABTS is started only when it is originated by a
939 * TM request. For the ABTS issued as part of ULP timeout,
940 * scsi-ml maintains the timers.
943 /* if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags))*/
944 bnx2fc_cmd_timer_set(io_req, 2 * r_a_tov);
946 /* Obtain free SQ entry */
947 bnx2fc_add_2_sq(tgt, xid);
950 bnx2fc_ring_doorbell(tgt);
956 int bnx2fc_initiate_seq_cleanup(struct bnx2fc_cmd *orig_io_req, u32 offset,
959 struct fc_lport *lport;
960 struct bnx2fc_rport *tgt = orig_io_req->tgt;
961 struct bnx2fc_interface *interface;
962 struct fcoe_port *port;
963 struct bnx2fc_cmd *seq_clnp_req;
964 struct fcoe_task_ctx_entry *task;
965 struct fcoe_task_ctx_entry *task_page;
966 struct bnx2fc_els_cb_arg *cb_arg = NULL;
971 BNX2FC_IO_DBG(orig_io_req, "bnx2fc_initiate_seq_cleanup xid = 0x%x\n",
973 kref_get(&orig_io_req->refcount);
975 port = orig_io_req->port;
976 interface = port->priv;
979 cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
981 printk(KERN_ERR PFX "Unable to alloc cb_arg for seq clnup\n");
986 seq_clnp_req = bnx2fc_elstm_alloc(tgt, BNX2FC_SEQ_CLEANUP);
988 printk(KERN_ERR PFX "cleanup: couldnt allocate cmd\n");
993 /* Initialize rest of io_req fields */
994 seq_clnp_req->sc_cmd = NULL;
995 seq_clnp_req->port = port;
996 seq_clnp_req->tgt = tgt;
997 seq_clnp_req->data_xfer_len = 0; /* No data transfer for cleanup */
999 xid = seq_clnp_req->xid;
1001 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
1002 index = xid % BNX2FC_TASKS_PER_PAGE;
1004 /* Initialize task context for this IO request */
1005 task_page = (struct fcoe_task_ctx_entry *)
1006 interface->hba->task_ctx[task_idx];
1007 task = &(task_page[index]);
1008 cb_arg->aborted_io_req = orig_io_req;
1009 cb_arg->io_req = seq_clnp_req;
1010 cb_arg->r_ctl = r_ctl;
1011 cb_arg->offset = offset;
1012 seq_clnp_req->cb_arg = cb_arg;
1014 printk(KERN_ERR PFX "call init_seq_cleanup_task\n");
1015 bnx2fc_init_seq_cleanup_task(seq_clnp_req, task, orig_io_req, offset);
1017 /* Obtain free SQ entry */
1018 bnx2fc_add_2_sq(tgt, xid);
1021 bnx2fc_ring_doorbell(tgt);
1026 int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
1028 struct fc_lport *lport;
1029 struct bnx2fc_rport *tgt = io_req->tgt;
1030 struct bnx2fc_interface *interface;
1031 struct fcoe_port *port;
1032 struct bnx2fc_cmd *cleanup_io_req;
1033 struct fcoe_task_ctx_entry *task;
1034 struct fcoe_task_ctx_entry *task_page;
1035 int task_idx, index;
1039 /* ASSUMPTION: called with tgt_lock held */
1040 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_cleanup\n");
1042 port = io_req->port;
1043 interface = port->priv;
1044 lport = port->lport;
1046 cleanup_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_CLEANUP);
1047 if (!cleanup_io_req) {
1048 printk(KERN_ERR PFX "cleanup: couldnt allocate cmd\n");
1053 /* Initialize rest of io_req fields */
1054 cleanup_io_req->sc_cmd = NULL;
1055 cleanup_io_req->port = port;
1056 cleanup_io_req->tgt = tgt;
1057 cleanup_io_req->data_xfer_len = 0; /* No data transfer for cleanup */
1059 xid = cleanup_io_req->xid;
1061 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
1062 index = xid % BNX2FC_TASKS_PER_PAGE;
1064 /* Initialize task context for this IO request */
1065 task_page = (struct fcoe_task_ctx_entry *)
1066 interface->hba->task_ctx[task_idx];
1067 task = &(task_page[index]);
1068 orig_xid = io_req->xid;
1070 BNX2FC_IO_DBG(io_req, "CLEANUP io_req xid = 0x%x\n", xid);
1072 bnx2fc_init_cleanup_task(cleanup_io_req, task, orig_xid);
1074 /* Obtain free SQ entry */
1075 bnx2fc_add_2_sq(tgt, xid);
1078 bnx2fc_ring_doorbell(tgt);
1085 * bnx2fc_eh_target_reset: Reset a target
1087 * @sc_cmd: SCSI command
1089 * Set from SCSI host template to send task mgmt command to the target
1090 * and wait for the response
1092 int bnx2fc_eh_target_reset(struct scsi_cmnd *sc_cmd)
1094 return bnx2fc_initiate_tmf(sc_cmd, FCP_TMF_TGT_RESET);
1098 * bnx2fc_eh_device_reset - Reset a single LUN
1100 * @sc_cmd: SCSI command
1102 * Set from SCSI host template to send task mgmt command to the target
1103 * and wait for the response
1105 int bnx2fc_eh_device_reset(struct scsi_cmnd *sc_cmd)
1107 return bnx2fc_initiate_tmf(sc_cmd, FCP_TMF_LUN_RESET);
1110 int bnx2fc_expl_logo(struct fc_lport *lport, struct bnx2fc_cmd *io_req)
1112 struct bnx2fc_rport *tgt = io_req->tgt;
1113 struct fc_rport_priv *rdata = tgt->rdata;
1118 BNX2FC_IO_DBG(io_req, "Expl logo - tgt flags = 0x%lx\n",
1120 logo_issued = test_and_set_bit(BNX2FC_FLAG_EXPL_LOGO,
1122 io_req->wait_for_comp = 1;
1123 bnx2fc_initiate_cleanup(io_req);
1125 spin_unlock_bh(&tgt->tgt_lock);
1127 wait_for_completion(&io_req->tm_done);
1129 io_req->wait_for_comp = 0;
1131 * release the reference taken in eh_abort to allow the
1132 * target to re-login after flushing IOs
1134 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1137 clear_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
1138 mutex_lock(&lport->disc.disc_mutex);
1139 lport->tt.rport_logoff(rdata);
1140 mutex_unlock(&lport->disc.disc_mutex);
1142 msleep(BNX2FC_RELOGIN_WAIT_TIME);
1143 if (wait_cnt++ > BNX2FC_RELOGIN_WAIT_CNT) {
1147 } while (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags));
1149 spin_lock_bh(&tgt->tgt_lock);
1153 * bnx2fc_eh_abort - eh_abort_handler api to abort an outstanding
1156 * @sc_cmd: SCSI_ML command pointer
1158 * SCSI abort request handler
1160 int bnx2fc_eh_abort(struct scsi_cmnd *sc_cmd)
1162 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
1163 struct fc_rport_libfc_priv *rp = rport->dd_data;
1164 struct bnx2fc_cmd *io_req;
1165 struct fc_lport *lport;
1166 struct bnx2fc_rport *tgt;
1170 rc = fc_block_scsi_eh(sc_cmd);
1174 lport = shost_priv(sc_cmd->device->host);
1175 if ((lport->state != LPORT_ST_READY) || !(lport->link_up)) {
1176 printk(KERN_ERR PFX "eh_abort: link not ready\n");
1180 tgt = (struct bnx2fc_rport *)&rp[1];
1182 BNX2FC_TGT_DBG(tgt, "Entered bnx2fc_eh_abort\n");
1184 spin_lock_bh(&tgt->tgt_lock);
1185 io_req = (struct bnx2fc_cmd *)sc_cmd->SCp.ptr;
1187 /* Command might have just completed */
1188 printk(KERN_ERR PFX "eh_abort: io_req is NULL\n");
1189 spin_unlock_bh(&tgt->tgt_lock);
1192 BNX2FC_IO_DBG(io_req, "eh_abort - refcnt = %d\n",
1193 io_req->refcount.refcount.counter);
1195 /* Hold IO request across abort processing */
1196 kref_get(&io_req->refcount);
1198 BUG_ON(tgt != io_req->tgt);
1200 /* Remove the io_req from the active_q. */
1202 * Task Mgmt functions (LUN RESET & TGT RESET) will not
1203 * issue an ABTS on this particular IO req, as the
1204 * io_req is no longer in the active_q.
1206 if (tgt->flush_in_prog) {
1207 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
1208 "flush in progress\n", io_req->xid);
1209 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1210 spin_unlock_bh(&tgt->tgt_lock);
1214 if (io_req->on_active_queue == 0) {
1215 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
1216 "not on active_q\n", io_req->xid);
1218 * This condition can happen only due to the FW bug,
1219 * where we do not receive cleanup response from
1220 * the FW. Handle this case gracefully by erroring
1221 * back the IO request to SCSI-ml
1223 bnx2fc_scsi_done(io_req, DID_ABORT);
1225 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1226 spin_unlock_bh(&tgt->tgt_lock);
1231 * Only eh_abort processing will remove the IO from
1232 * active_cmd_q before processing the request. this is
1233 * done to avoid race conditions between IOs aborted
1234 * as part of task management completion and eh_abort
1237 list_del_init(&io_req->link);
1238 io_req->on_active_queue = 0;
1239 /* Move IO req to retire queue */
1240 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1242 init_completion(&io_req->tm_done);
1244 if (test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
1245 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
1246 "already in abts processing\n", io_req->xid);
1247 if (cancel_delayed_work(&io_req->timeout_work))
1248 kref_put(&io_req->refcount,
1249 bnx2fc_cmd_release); /* drop timer hold */
1250 rc = bnx2fc_expl_logo(lport, io_req);
1251 /* This only occurs when an task abort was requested while ABTS
1252 is in progress. Setting the IO_CLEANUP flag will skip the
1253 RRQ process in the case when the fw generated SCSI_CMD cmpl
1254 was a result from the ABTS request rather than the CLEANUP
1256 set_bit(BNX2FC_FLAG_IO_CLEANUP, &io_req->req_flags);
1260 /* Cancel the current timer running on this io_req */
1261 if (cancel_delayed_work(&io_req->timeout_work))
1262 kref_put(&io_req->refcount,
1263 bnx2fc_cmd_release); /* drop timer hold */
1264 set_bit(BNX2FC_FLAG_EH_ABORT, &io_req->req_flags);
1265 io_req->wait_for_comp = 1;
1266 rc = bnx2fc_initiate_abts(io_req);
1268 bnx2fc_initiate_cleanup(io_req);
1269 spin_unlock_bh(&tgt->tgt_lock);
1270 wait_for_completion(&io_req->tm_done);
1271 spin_lock_bh(&tgt->tgt_lock);
1272 io_req->wait_for_comp = 0;
1275 spin_unlock_bh(&tgt->tgt_lock);
1277 wait_for_completion(&io_req->tm_done);
1279 spin_lock_bh(&tgt->tgt_lock);
1280 io_req->wait_for_comp = 0;
1281 if (test_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags)) {
1282 BNX2FC_IO_DBG(io_req, "IO completed in a different context\n");
1284 } else if (!(test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
1285 &io_req->req_flags))) {
1286 /* Let the scsi-ml try to recover this command */
1287 printk(KERN_ERR PFX "abort failed, xid = 0x%x\n",
1289 rc = bnx2fc_expl_logo(lport, io_req);
1293 * We come here even when there was a race condition
1294 * between timeout and abts completion, and abts
1295 * completion happens just in time.
1297 BNX2FC_IO_DBG(io_req, "abort succeeded\n");
1299 bnx2fc_scsi_done(io_req, DID_ABORT);
1300 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1303 /* release the reference taken in eh_abort */
1304 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1306 spin_unlock_bh(&tgt->tgt_lock);
1310 void bnx2fc_process_seq_cleanup_compl(struct bnx2fc_cmd *seq_clnp_req,
1311 struct fcoe_task_ctx_entry *task,
1314 struct bnx2fc_els_cb_arg *cb_arg = seq_clnp_req->cb_arg;
1315 struct bnx2fc_cmd *orig_io_req = cb_arg->aborted_io_req;
1316 u32 offset = cb_arg->offset;
1317 enum fc_rctl r_ctl = cb_arg->r_ctl;
1319 struct bnx2fc_rport *tgt = orig_io_req->tgt;
1321 BNX2FC_IO_DBG(orig_io_req, "Entered process_cleanup_compl xid = 0x%x"
1323 seq_clnp_req->xid, seq_clnp_req->cmd_type);
1325 if (rx_state == FCOE_TASK_RX_STATE_IGNORED_SEQUENCE_CLEANUP) {
1326 printk(KERN_ERR PFX "seq cleanup ignored - xid = 0x%x\n",
1331 spin_unlock_bh(&tgt->tgt_lock);
1332 rc = bnx2fc_send_srr(orig_io_req, offset, r_ctl);
1333 spin_lock_bh(&tgt->tgt_lock);
1336 printk(KERN_ERR PFX "clnup_compl: Unable to send SRR"
1337 " IO will abort\n");
1338 seq_clnp_req->cb_arg = NULL;
1339 kref_put(&orig_io_req->refcount, bnx2fc_cmd_release);
1345 void bnx2fc_process_cleanup_compl(struct bnx2fc_cmd *io_req,
1346 struct fcoe_task_ctx_entry *task,
1349 BNX2FC_IO_DBG(io_req, "Entered process_cleanup_compl "
1350 "refcnt = %d, cmd_type = %d\n",
1351 io_req->refcount.refcount.counter, io_req->cmd_type);
1352 bnx2fc_scsi_done(io_req, DID_ERROR);
1353 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1354 if (io_req->wait_for_comp)
1355 complete(&io_req->tm_done);
1358 void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
1359 struct fcoe_task_ctx_entry *task,
1363 u32 r_a_tov = FC_DEF_R_A_TOV;
1365 struct bnx2fc_rport *tgt = io_req->tgt;
1367 BNX2FC_IO_DBG(io_req, "Entered process_abts_compl xid = 0x%x"
1368 "refcnt = %d, cmd_type = %d\n",
1370 io_req->refcount.refcount.counter, io_req->cmd_type);
1372 if (test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
1373 &io_req->req_flags)) {
1374 BNX2FC_IO_DBG(io_req, "Timer context finished processing"
1379 /* Do not issue RRQ as this IO is already cleanedup */
1380 if (test_and_set_bit(BNX2FC_FLAG_IO_CLEANUP,
1381 &io_req->req_flags))
1385 * For ABTS issued due to SCSI eh_abort_handler, timeout
1386 * values are maintained by scsi-ml itself. Cancel timeout
1387 * in case ABTS issued as part of task management function
1388 * or due to FW error.
1390 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags))
1391 if (cancel_delayed_work(&io_req->timeout_work))
1392 kref_put(&io_req->refcount,
1393 bnx2fc_cmd_release); /* drop timer hold */
1395 r_ctl = (u8)task->rxwr_only.union_ctx.comp_info.abts_rsp.r_ctl;
1398 case FC_RCTL_BA_ACC:
1400 * Dont release this cmd yet. It will be relesed
1401 * after we get RRQ response
1403 BNX2FC_IO_DBG(io_req, "ABTS response - ACC Send RRQ\n");
1407 case FC_RCTL_BA_RJT:
1408 BNX2FC_IO_DBG(io_req, "ABTS response - RJT\n");
1411 printk(KERN_ERR PFX "Unknown ABTS response\n");
1416 BNX2FC_IO_DBG(io_req, "Issue RRQ after R_A_TOV\n");
1417 set_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
1419 set_bit(BNX2FC_FLAG_RETIRE_OXID, &io_req->req_flags);
1420 bnx2fc_cmd_timer_set(io_req, r_a_tov);
1423 if (io_req->wait_for_comp) {
1424 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
1425 &io_req->req_flags))
1426 complete(&io_req->tm_done);
1429 * We end up here when ABTS is issued as
1430 * in asynchronous context, i.e., as part
1431 * of task management completion, or
1432 * when FW error is received or when the
1433 * ABTS is issued when the IO is timed
1437 if (io_req->on_active_queue) {
1438 list_del_init(&io_req->link);
1439 io_req->on_active_queue = 0;
1440 /* Move IO req to retire queue */
1441 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1443 bnx2fc_scsi_done(io_req, DID_ERROR);
1444 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1448 static void bnx2fc_lun_reset_cmpl(struct bnx2fc_cmd *io_req)
1450 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1451 struct bnx2fc_rport *tgt = io_req->tgt;
1452 struct bnx2fc_cmd *cmd, *tmp;
1453 int tm_lun = sc_cmd->device->lun;
1457 /* called with tgt_lock held */
1458 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_lun_reset_cmpl\n");
1460 * Walk thru the active_ios queue and ABORT the IO
1461 * that matches with the LUN that was reset
1463 list_for_each_entry_safe(cmd, tmp, &tgt->active_cmd_queue, link) {
1464 BNX2FC_TGT_DBG(tgt, "LUN RST cmpl: scan for pending IOs\n");
1465 lun = cmd->sc_cmd->device->lun;
1466 if (lun == tm_lun) {
1467 /* Initiate ABTS on this cmd */
1468 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
1470 /* cancel the IO timeout */
1471 if (cancel_delayed_work(&io_req->timeout_work))
1472 kref_put(&io_req->refcount,
1473 bnx2fc_cmd_release);
1475 rc = bnx2fc_initiate_abts(cmd);
1476 /* abts shouldn't fail in this context */
1477 WARN_ON(rc != SUCCESS);
1479 printk(KERN_ERR PFX "lun_rst: abts already in"
1480 " progress for this IO 0x%x\n",
1486 static void bnx2fc_tgt_reset_cmpl(struct bnx2fc_cmd *io_req)
1488 struct bnx2fc_rport *tgt = io_req->tgt;
1489 struct bnx2fc_cmd *cmd, *tmp;
1492 /* called with tgt_lock held */
1493 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_tgt_reset_cmpl\n");
1495 * Walk thru the active_ios queue and ABORT the IO
1496 * that matches with the LUN that was reset
1498 list_for_each_entry_safe(cmd, tmp, &tgt->active_cmd_queue, link) {
1499 BNX2FC_TGT_DBG(tgt, "TGT RST cmpl: scan for pending IOs\n");
1501 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
1503 /* cancel the IO timeout */
1504 if (cancel_delayed_work(&io_req->timeout_work))
1505 kref_put(&io_req->refcount,
1506 bnx2fc_cmd_release); /* timer hold */
1507 rc = bnx2fc_initiate_abts(cmd);
1508 /* abts shouldn't fail in this context */
1509 WARN_ON(rc != SUCCESS);
1512 printk(KERN_ERR PFX "tgt_rst: abts already in progress"
1513 " for this IO 0x%x\n", cmd->xid);
1517 void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
1518 struct fcoe_task_ctx_entry *task, u8 num_rq)
1520 struct bnx2fc_mp_req *tm_req;
1521 struct fc_frame_header *fc_hdr;
1522 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1527 /* Called with tgt_lock held */
1528 BNX2FC_IO_DBG(io_req, "Entered process_tm_compl\n");
1530 if (!(test_bit(BNX2FC_FLAG_TM_TIMEOUT, &io_req->req_flags)))
1531 set_bit(BNX2FC_FLAG_TM_COMPL, &io_req->req_flags);
1533 /* TM has already timed out and we got
1534 * delayed completion. Ignore completion
1540 tm_req = &(io_req->mp_req);
1541 fc_hdr = &(tm_req->resp_fc_hdr);
1542 hdr = (u64 *)fc_hdr;
1544 &task->rxwr_only.union_ctx.comp_info.mp_rsp.fc_hdr;
1545 hdr[0] = cpu_to_be64(temp_hdr[0]);
1546 hdr[1] = cpu_to_be64(temp_hdr[1]);
1547 hdr[2] = cpu_to_be64(temp_hdr[2]);
1550 task->rxwr_only.union_ctx.comp_info.mp_rsp.mp_payload_len;
1552 rsp_buf = tm_req->resp_buf;
1554 if (fc_hdr->fh_r_ctl == FC_RCTL_DD_CMD_STATUS) {
1555 bnx2fc_parse_fcp_rsp(io_req,
1556 (struct fcoe_fcp_rsp_payload *)
1558 if (io_req->fcp_rsp_code == 0) {
1560 if (tm_req->tm_flags & FCP_TMF_LUN_RESET)
1561 bnx2fc_lun_reset_cmpl(io_req);
1562 else if (tm_req->tm_flags & FCP_TMF_TGT_RESET)
1563 bnx2fc_tgt_reset_cmpl(io_req);
1566 printk(KERN_ERR PFX "tmf's fc_hdr r_ctl = 0x%x\n",
1569 if (!sc_cmd->SCp.ptr) {
1570 printk(KERN_ERR PFX "tm_compl: SCp.ptr is NULL\n");
1573 switch (io_req->fcp_status) {
1575 if (io_req->cdb_status == 0) {
1576 /* Good IO completion */
1577 sc_cmd->result = DID_OK << 16;
1579 /* Transport status is good, SCSI status not good */
1580 sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
1582 if (io_req->fcp_resid)
1583 scsi_set_resid(sc_cmd, io_req->fcp_resid);
1587 BNX2FC_IO_DBG(io_req, "process_tm_compl: fcp_status = %d\n",
1588 io_req->fcp_status);
1592 sc_cmd = io_req->sc_cmd;
1593 io_req->sc_cmd = NULL;
1595 /* check if the io_req exists in tgt's tmf_q */
1596 if (io_req->on_tmf_queue) {
1598 list_del_init(&io_req->link);
1599 io_req->on_tmf_queue = 0;
1602 printk(KERN_ERR PFX "Command not on active_cmd_queue!\n");
1606 sc_cmd->SCp.ptr = NULL;
1607 sc_cmd->scsi_done(sc_cmd);
1609 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1610 if (io_req->wait_for_comp) {
1611 BNX2FC_IO_DBG(io_req, "tm_compl - wake up the waiter\n");
1612 complete(&io_req->tm_done);
1616 static int bnx2fc_split_bd(struct bnx2fc_cmd *io_req, u64 addr, int sg_len,
1619 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1620 int frag_size, sg_frags;
1624 if (sg_len >= BNX2FC_BD_SPLIT_SZ)
1625 frag_size = BNX2FC_BD_SPLIT_SZ;
1628 bd[bd_index + sg_frags].buf_addr_lo = addr & 0xffffffff;
1629 bd[bd_index + sg_frags].buf_addr_hi = addr >> 32;
1630 bd[bd_index + sg_frags].buf_len = (u16)frag_size;
1631 bd[bd_index + sg_frags].flags = 0;
1633 addr += (u64) frag_size;
1635 sg_len -= frag_size;
1641 static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req)
1643 struct bnx2fc_interface *interface = io_req->port->priv;
1644 struct bnx2fc_hba *hba = interface->hba;
1645 struct scsi_cmnd *sc = io_req->sc_cmd;
1646 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1647 struct scatterlist *sg;
1652 unsigned int sg_len;
1656 sg_count = dma_map_sg(&hba->pcidev->dev, scsi_sglist(sc),
1657 scsi_sg_count(sc), sc->sc_data_direction);
1658 scsi_for_each_sg(sc, sg, sg_count, i) {
1659 sg_len = sg_dma_len(sg);
1660 addr = sg_dma_address(sg);
1661 if (sg_len > BNX2FC_MAX_BD_LEN) {
1662 sg_frags = bnx2fc_split_bd(io_req, addr, sg_len,
1667 bd[bd_count].buf_addr_lo = addr & 0xffffffff;
1668 bd[bd_count].buf_addr_hi = addr >> 32;
1669 bd[bd_count].buf_len = (u16)sg_len;
1670 bd[bd_count].flags = 0;
1672 bd_count += sg_frags;
1673 byte_count += sg_len;
1675 if (byte_count != scsi_bufflen(sc))
1676 printk(KERN_ERR PFX "byte_count = %d != scsi_bufflen = %d, "
1677 "task_id = 0x%x\n", byte_count, scsi_bufflen(sc),
1682 static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req)
1684 struct scsi_cmnd *sc = io_req->sc_cmd;
1685 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1688 if (scsi_sg_count(sc)) {
1689 bd_count = bnx2fc_map_sg(io_req);
1694 bd[0].buf_addr_lo = bd[0].buf_addr_hi = 0;
1695 bd[0].buf_len = bd[0].flags = 0;
1697 io_req->bd_tbl->bd_valid = bd_count;
1702 static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req)
1704 struct scsi_cmnd *sc = io_req->sc_cmd;
1706 if (io_req->bd_tbl->bd_valid && sc) {
1708 io_req->bd_tbl->bd_valid = 0;
1712 void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
1713 struct fcp_cmnd *fcp_cmnd)
1715 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1718 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
1720 int_to_scsilun(sc_cmd->device->lun, &fcp_cmnd->fc_lun);
1722 fcp_cmnd->fc_dl = htonl(io_req->data_xfer_len);
1723 memcpy(fcp_cmnd->fc_cdb, sc_cmd->cmnd, sc_cmd->cmd_len);
1725 fcp_cmnd->fc_cmdref = 0;
1726 fcp_cmnd->fc_pri_ta = 0;
1727 fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags;
1728 fcp_cmnd->fc_flags = io_req->io_req_flags;
1730 if (scsi_populate_tag_msg(sc_cmd, tag)) {
1732 case HEAD_OF_QUEUE_TAG:
1733 fcp_cmnd->fc_pri_ta = FCP_PTA_HEADQ;
1735 case ORDERED_QUEUE_TAG:
1736 fcp_cmnd->fc_pri_ta = FCP_PTA_ORDERED;
1739 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
1743 fcp_cmnd->fc_pri_ta = 0;
1747 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
1748 struct fcoe_fcp_rsp_payload *fcp_rsp,
1751 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1752 struct bnx2fc_rport *tgt = io_req->tgt;
1753 u8 rsp_flags = fcp_rsp->fcp_flags.flags;
1754 u32 rq_buff_len = 0;
1756 unsigned char *rq_data;
1757 unsigned char *dummy;
1758 int fcp_sns_len = 0;
1759 int fcp_rsp_len = 0;
1761 io_req->fcp_status = FC_GOOD;
1762 io_req->fcp_resid = fcp_rsp->fcp_resid;
1764 io_req->scsi_comp_flags = rsp_flags;
1765 CMD_SCSI_STATUS(sc_cmd) = io_req->cdb_status =
1766 fcp_rsp->scsi_status_code;
1768 /* Fetch fcp_rsp_info and fcp_sns_info if available */
1772 * We do not anticipate num_rq >1, as the linux defined
1773 * SCSI_SENSE_BUFFERSIZE is 96 bytes + 8 bytes of FCP_RSP_INFO
1774 * 256 bytes of single rq buffer is good enough to hold this.
1778 FCOE_FCP_RSP_FLAGS_FCP_RSP_LEN_VALID) {
1779 fcp_rsp_len = rq_buff_len
1780 = fcp_rsp->fcp_rsp_len;
1784 FCOE_FCP_RSP_FLAGS_FCP_SNS_LEN_VALID) {
1785 fcp_sns_len = fcp_rsp->fcp_sns_len;
1786 rq_buff_len += fcp_rsp->fcp_sns_len;
1789 io_req->fcp_rsp_len = fcp_rsp_len;
1790 io_req->fcp_sns_len = fcp_sns_len;
1792 if (rq_buff_len > num_rq * BNX2FC_RQ_BUF_SZ) {
1793 /* Invalid sense sense length. */
1794 printk(KERN_ERR PFX "invalid sns length %d\n",
1796 /* reset rq_buff_len */
1797 rq_buff_len = num_rq * BNX2FC_RQ_BUF_SZ;
1800 rq_data = bnx2fc_get_next_rqe(tgt, 1);
1803 /* We do not need extra sense data */
1804 for (i = 1; i < num_rq; i++)
1805 dummy = bnx2fc_get_next_rqe(tgt, 1);
1808 /* fetch fcp_rsp_code */
1809 if ((fcp_rsp_len == 4) || (fcp_rsp_len == 8)) {
1810 /* Only for task management function */
1811 io_req->fcp_rsp_code = rq_data[3];
1812 printk(KERN_ERR PFX "fcp_rsp_code = %d\n",
1813 io_req->fcp_rsp_code);
1816 /* fetch sense data */
1817 rq_data += fcp_rsp_len;
1819 if (fcp_sns_len > SCSI_SENSE_BUFFERSIZE) {
1820 printk(KERN_ERR PFX "Truncating sense buffer\n");
1821 fcp_sns_len = SCSI_SENSE_BUFFERSIZE;
1824 memset(sc_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1826 memcpy(sc_cmd->sense_buffer, rq_data, fcp_sns_len);
1828 /* return RQ entries */
1829 for (i = 0; i < num_rq; i++)
1830 bnx2fc_return_rqe(tgt, 1);
1835 * bnx2fc_queuecommand - Queuecommand function of the scsi template
1837 * @host: The Scsi_Host the command was issued to
1838 * @sc_cmd: struct scsi_cmnd to be executed
1840 * This is the IO strategy routine, called by SCSI-ML
1842 int bnx2fc_queuecommand(struct Scsi_Host *host,
1843 struct scsi_cmnd *sc_cmd)
1845 struct fc_lport *lport = shost_priv(host);
1846 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
1847 struct fc_rport_libfc_priv *rp = rport->dd_data;
1848 struct bnx2fc_rport *tgt;
1849 struct bnx2fc_cmd *io_req;
1853 rval = fc_remote_port_chkready(rport);
1855 sc_cmd->result = rval;
1856 sc_cmd->scsi_done(sc_cmd);
1860 if ((lport->state != LPORT_ST_READY) || !(lport->link_up)) {
1861 rc = SCSI_MLQUEUE_HOST_BUSY;
1865 /* rport and tgt are allocated together, so tgt should be non-NULL */
1866 tgt = (struct bnx2fc_rport *)&rp[1];
1868 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
1870 * Session is not offloaded yet. Let SCSI-ml retry
1873 rc = SCSI_MLQUEUE_TARGET_BUSY;
1876 if (tgt->retry_delay_timestamp) {
1877 if (time_after(jiffies, tgt->retry_delay_timestamp)) {
1878 tgt->retry_delay_timestamp = 0;
1880 /* If retry_delay timer is active, flow off the ML */
1881 rc = SCSI_MLQUEUE_TARGET_BUSY;
1885 io_req = bnx2fc_cmd_alloc(tgt);
1887 rc = SCSI_MLQUEUE_HOST_BUSY;
1890 io_req->sc_cmd = sc_cmd;
1892 if (bnx2fc_post_io_req(tgt, io_req)) {
1893 printk(KERN_ERR PFX "Unable to post io_req\n");
1894 rc = SCSI_MLQUEUE_HOST_BUSY;
1901 void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
1902 struct fcoe_task_ctx_entry *task,
1905 struct fcoe_fcp_rsp_payload *fcp_rsp;
1906 struct bnx2fc_rport *tgt = io_req->tgt;
1907 struct scsi_cmnd *sc_cmd;
1908 struct Scsi_Host *host;
1911 /* scsi_cmd_cmpl is called with tgt lock held */
1913 if (test_and_set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags)) {
1914 /* we will not receive ABTS response for this IO */
1915 BNX2FC_IO_DBG(io_req, "Timer context finished processing "
1919 /* Cancel the timeout_work, as we received IO completion */
1920 if (cancel_delayed_work(&io_req->timeout_work))
1921 kref_put(&io_req->refcount,
1922 bnx2fc_cmd_release); /* drop timer hold */
1924 sc_cmd = io_req->sc_cmd;
1925 if (sc_cmd == NULL) {
1926 printk(KERN_ERR PFX "scsi_cmd_compl - sc_cmd is NULL\n");
1930 /* Fetch fcp_rsp from task context and perform cmd completion */
1931 fcp_rsp = (struct fcoe_fcp_rsp_payload *)
1932 &(task->rxwr_only.union_ctx.comp_info.fcp_rsp.payload);
1934 /* parse fcp_rsp and obtain sense data from RQ if available */
1935 bnx2fc_parse_fcp_rsp(io_req, fcp_rsp, num_rq);
1937 host = sc_cmd->device->host;
1938 if (!sc_cmd->SCp.ptr) {
1939 printk(KERN_ERR PFX "SCp.ptr is NULL\n");
1943 if (io_req->on_active_queue) {
1944 list_del_init(&io_req->link);
1945 io_req->on_active_queue = 0;
1946 /* Move IO req to retire queue */
1947 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1949 /* This should not happen, but could have been pulled
1950 * by bnx2fc_flush_active_ios(), or during a race
1951 * between command abort and (late) completion.
1953 BNX2FC_IO_DBG(io_req, "xid not on active_cmd_queue\n");
1954 if (io_req->wait_for_comp)
1955 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
1956 &io_req->req_flags))
1957 complete(&io_req->tm_done);
1960 bnx2fc_unmap_sg_list(io_req);
1961 io_req->sc_cmd = NULL;
1963 switch (io_req->fcp_status) {
1965 if (io_req->cdb_status == 0) {
1966 /* Good IO completion */
1967 sc_cmd->result = DID_OK << 16;
1969 /* Transport status is good, SCSI status not good */
1970 BNX2FC_IO_DBG(io_req, "scsi_cmpl: cdb_status = %d"
1971 " fcp_resid = 0x%x\n",
1972 io_req->cdb_status, io_req->fcp_resid);
1973 sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
1975 if (io_req->cdb_status == SAM_STAT_TASK_SET_FULL ||
1976 io_req->cdb_status == SAM_STAT_BUSY) {
1977 /* Set the jiffies + retry_delay_timer * 100ms
1978 for the rport/tgt */
1979 tgt->retry_delay_timestamp = jiffies +
1980 fcp_rsp->retry_delay_timer * HZ / 10;
1984 if (io_req->fcp_resid)
1985 scsi_set_resid(sc_cmd, io_req->fcp_resid);
1988 printk(KERN_ERR PFX "scsi_cmd_compl: fcp_status = %d\n",
1989 io_req->fcp_status);
1992 sc_cmd->SCp.ptr = NULL;
1993 sc_cmd->scsi_done(sc_cmd);
1994 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1997 int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
1998 struct bnx2fc_cmd *io_req)
2000 struct fcoe_task_ctx_entry *task;
2001 struct fcoe_task_ctx_entry *task_page;
2002 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
2003 struct fcoe_port *port = tgt->port;
2004 struct bnx2fc_interface *interface = port->priv;
2005 struct bnx2fc_hba *hba = interface->hba;
2006 struct fc_lport *lport = port->lport;
2007 struct fc_stats *stats;
2008 int task_idx, index;
2011 /* Initialize rest of io_req fields */
2012 io_req->cmd_type = BNX2FC_SCSI_CMD;
2013 io_req->port = port;
2015 io_req->data_xfer_len = scsi_bufflen(sc_cmd);
2016 sc_cmd->SCp.ptr = (char *)io_req;
2018 stats = per_cpu_ptr(lport->stats, get_cpu());
2019 if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) {
2020 io_req->io_req_flags = BNX2FC_READ;
2021 stats->InputRequests++;
2022 stats->InputBytes += io_req->data_xfer_len;
2023 } else if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
2024 io_req->io_req_flags = BNX2FC_WRITE;
2025 stats->OutputRequests++;
2026 stats->OutputBytes += io_req->data_xfer_len;
2028 io_req->io_req_flags = 0;
2029 stats->ControlRequests++;
2035 /* Build buffer descriptor list for firmware from sg list */
2036 if (bnx2fc_build_bd_list_from_sg(io_req)) {
2037 printk(KERN_ERR PFX "BD list creation failed\n");
2038 spin_lock_bh(&tgt->tgt_lock);
2039 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2040 spin_unlock_bh(&tgt->tgt_lock);
2044 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
2045 index = xid % BNX2FC_TASKS_PER_PAGE;
2047 /* Initialize task context for this IO request */
2048 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx];
2049 task = &(task_page[index]);
2050 bnx2fc_init_task(io_req, task);
2052 spin_lock_bh(&tgt->tgt_lock);
2054 if (tgt->flush_in_prog) {
2055 printk(KERN_ERR PFX "Flush in progress..Host Busy\n");
2056 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2057 spin_unlock_bh(&tgt->tgt_lock);
2061 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
2062 printk(KERN_ERR PFX "Session not ready...post_io\n");
2063 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2064 spin_unlock_bh(&tgt->tgt_lock);
2069 if (tgt->io_timeout)
2070 bnx2fc_cmd_timer_set(io_req, BNX2FC_IO_TIMEOUT);
2071 /* Obtain free SQ entry */
2072 bnx2fc_add_2_sq(tgt, xid);
2074 /* Enqueue the io_req to active_cmd_queue */
2076 io_req->on_active_queue = 1;
2077 /* move io_req from pending_queue to active_queue */
2078 list_add_tail(&io_req->link, &tgt->active_cmd_queue);
2081 bnx2fc_ring_doorbell(tgt);
2082 spin_unlock_bh(&tgt->tgt_lock);