Lines Matching refs:io_req

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,
27 void bnx2fc_cmd_timer_set(struct bnx2fc_cmd *io_req,
30 struct bnx2fc_interface *interface = io_req->port->priv;
33 &io_req->timeout_work,
35 kref_get(&io_req->refcount);
40 struct bnx2fc_cmd *io_req = container_of(work, struct bnx2fc_cmd,
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);
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.
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");
71 &io_req->req_flags)) {
73 BNX2FC_IO_DBG(io_req, "eh_abort timed out\n");
74 complete(&io_req->tm_done);
76 &io_req->req_flags)) {
78 BNX2FC_IO_DBG(io_req, "ABTS timed out refcnt = %d\n",
79 io_req->refcount.refcount.counter);
81 &io_req->req_flags))) {
83 lport = io_req->port->lport;
84 rdata = io_req->tgt->rdata;
88 kref_put(&io_req->refcount, bnx2fc_cmd_release);
93 BNX2FC_IO_DBG(io_req, "Explicit "
105 BNX2FC_IO_DBG(io_req, "IO timed out. issue ABTS\n");
107 &io_req->req_flags)) {
108 BNX2FC_IO_DBG(io_req, "IO completed before "
114 &io_req->req_flags)) {
115 rc = bnx2fc_initiate_abts(io_req);
122 lport = io_req->port->lport;
123 rdata = io_req->tgt->rdata;
127 kref_put(&io_req->refcount, bnx2fc_cmd_release);
131 BNX2FC_IO_DBG(io_req, "Explicit "
142 BNX2FC_IO_DBG(io_req, "IO already in "
149 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
150 BNX2FC_IO_DBG(io_req, "ABTS for ELS timed out\n");
153 &io_req->req_flags)) {
154 lport = io_req->port->lport;
155 rdata = io_req->tgt->rdata;
159 kref_put(&io_req->refcount, bnx2fc_cmd_release);
164 BNX2FC_IO_DBG(io_req, "Explicitly logo"
179 BNX2FC_IO_DBG(io_req, "ELS timed out\n");
181 &io_req->req_flags))
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;
201 kref_put(&io_req->refcount, bnx2fc_cmd_release);
205 static void bnx2fc_scsi_done(struct bnx2fc_cmd *io_req, int err_code)
208 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
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)) {
224 bnx2fc_unmap_sg_list(io_req);
225 io_req->sc_cmd = NULL;
229 io_req->xid);
234 BNX2FC_IO_DBG(io_req, "sc=%p, result=0x%x, retries=%d, allowed=%d\n",
247 struct bnx2fc_cmd *io_req;
303 io_req = kzalloc(sizeof(*io_req), GFP_KERNEL);
305 if (!io_req) {
306 printk(KERN_ERR PFX "failed to alloc io_req\n");
310 INIT_LIST_HEAD(&io_req->link);
311 INIT_DELAYED_WORK(&io_req->timeout_work, bnx2fc_cmd_timeout);
313 io_req->xid = xid++;
315 list_add_tail(&io_req->link,
316 &cmgr->free_list[io_req->xid %
319 list_add_tail(&io_req->link,
321 io_req++;
412 struct bnx2fc_cmd *io_req = (struct bnx2fc_cmd *)list;
413 list_del(&io_req->link);
414 kfree(io_req);
428 struct bnx2fc_cmd *io_req;
469 io_req = (struct bnx2fc_cmd *) listp;
470 xid = io_req->xid;
471 cmd_mgr->cmds[xid] = io_req;
476 INIT_LIST_HEAD(&io_req->link);
478 io_req->port = port;
479 io_req->cmd_mgr = cmd_mgr;
480 io_req->req_flags = 0;
481 io_req->cmd_type = type;
483 /* Bind io_bdt for this io_req */
484 /* Have a static link between io_req and io_bdt_pool */
485 bd_tbl = io_req->bd_tbl = cmd_mgr->io_bdt_pool[xid];
486 bd_tbl->io_req = io_req;
488 /* Hold the io_req against deletion */
489 kref_init(&io_req->refcount);
490 return io_req;
498 struct bnx2fc_cmd *io_req;
524 io_req = (struct bnx2fc_cmd *) listp;
525 xid = io_req->xid;
526 cmd_mgr->cmds[xid] = io_req;
532 INIT_LIST_HEAD(&io_req->link);
534 io_req->port = port;
535 io_req->cmd_mgr = cmd_mgr;
536 io_req->req_flags = 0;
538 /* Bind io_bdt for this io_req */
539 /* Have a static link between io_req and io_bdt_pool */
540 bd_tbl = io_req->bd_tbl = cmd_mgr->io_bdt_pool[xid];
541 bd_tbl->io_req = io_req;
543 /* Hold the io_req against deletion */
544 kref_init(&io_req->refcount);
545 return io_req;
550 struct bnx2fc_cmd *io_req = container_of(ref,
552 struct bnx2fc_cmd_mgr *cmd_mgr = io_req->cmd_mgr;
555 if (io_req->cmd_type == BNX2FC_SCSI_CMD)
556 index = io_req->xid % num_possible_cpus();
562 if (io_req->cmd_type != BNX2FC_SCSI_CMD)
563 bnx2fc_free_mp_resc(io_req);
564 cmd_mgr->cmds[io_req->xid] = NULL;
566 list_del_init(&io_req->link);
568 list_add(&io_req->link,
570 atomic_dec(&io_req->tgt->num_active_ios);
575 static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req)
577 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
578 struct bnx2fc_interface *interface = io_req->port->priv;
610 int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
615 struct bnx2fc_interface *interface = io_req->port->priv;
620 mp_req = (struct bnx2fc_mp_req *)&(io_req->mp_req);
624 io_req->data_xfer_len = mp_req->req_len;
630 bnx2fc_free_mp_resc(io_req);
639 bnx2fc_free_mp_resc(io_req);
652 bnx2fc_free_mp_resc(io_req);
660 bnx2fc_free_mp_resc(io_req);
694 struct bnx2fc_cmd *io_req;
735 io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_TASK_MGMT_CMD);
736 if (!io_req) {
745 /* Initialize rest of io_req fields */
746 io_req->sc_cmd = sc_cmd;
747 io_req->port = port;
748 io_req->tgt = tgt;
750 tm_req = (struct bnx2fc_mp_req *)&(io_req->mp_req);
752 rc = bnx2fc_init_mp_req(io_req);
756 kref_put(&io_req->refcount, bnx2fc_cmd_release);
762 io_req->io_req_flags = 0;
766 bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)tm_req->req_buf);
779 xid = io_req->xid;
789 bnx2fc_init_mp_task(io_req, task);
791 sc_cmd->SCp.ptr = (char *)io_req;
797 /* Enqueue the io_req to active_tm_queue */
798 io_req->on_tmf_queue = 1;
799 list_add_tail(&io_req->link, &tgt->active_tm_queue);
801 init_completion(&io_req->tm_done);
802 io_req->wait_for_comp = 1;
808 rc = wait_for_completion_timeout(&io_req->tm_done,
812 io_req->wait_for_comp = 0;
813 if (!(test_bit(BNX2FC_FLAG_TM_COMPL, &io_req->req_flags)))
814 set_bit(BNX2FC_FLAG_TM_TIMEOUT, &io_req->req_flags);
829 int bnx2fc_initiate_abts(struct bnx2fc_cmd *io_req)
832 struct bnx2fc_rport *tgt = io_req->tgt;
849 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_abts\n");
851 port = io_req->port;
880 /* Initialize rest of io_req fields */
893 fc_hdr->fh_ox_id = htons(io_req->xid);
894 fc_hdr->fh_rx_id = htons(io_req->task->rxwr_txrd.var_ctx.rx_id);
904 BNX2FC_IO_DBG(abts_io_req, "ABTS io_req\n");
925 /* if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags))*/
926 bnx2fc_cmd_timer_set(io_req, 2 * r_a_tov);
975 /* Initialize rest of io_req fields */
991 cb_arg->io_req = seq_clnp_req;
1008 int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
1011 struct bnx2fc_rport *tgt = io_req->tgt;
1022 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_cleanup\n");
1024 port = io_req->port;
1035 /* Initialize rest of io_req fields */
1050 orig_xid = io_req->xid;
1052 BNX2FC_IO_DBG(io_req, "CLEANUP io_req xid = 0x%x\n", xid);
1104 struct bnx2fc_cmd *io_req;
1128 io_req = (struct bnx2fc_cmd *)sc_cmd->SCp.ptr;
1129 if (!io_req) {
1131 printk(KERN_ERR PFX "eh_abort: io_req is NULL\n");
1135 BNX2FC_IO_DBG(io_req, "eh_abort - refcnt = %d\n",
1136 io_req->refcount.refcount.counter);
1139 kref_get(&io_req->refcount);
1141 BUG_ON(tgt != io_req->tgt);
1143 /* Remove the io_req from the active_q. */
1147 * io_req is no longer in the active_q.
1150 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
1151 "flush in progress\n", io_req->xid);
1152 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1157 if (io_req->on_active_queue == 0) {
1158 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
1159 "not on active_q\n", io_req->xid);
1166 bnx2fc_scsi_done(io_req, DID_ABORT);
1168 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1180 list_del_init(&io_req->link);
1181 io_req->on_active_queue = 0;
1183 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1185 init_completion(&io_req->tm_done);
1186 io_req->wait_for_comp = 1;
1188 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
1189 /* Cancel the current timer running on this io_req */
1190 if (cancel_delayed_work(&io_req->timeout_work))
1191 kref_put(&io_req->refcount,
1193 set_bit(BNX2FC_FLAG_EH_ABORT, &io_req->req_flags);
1194 rc = bnx2fc_initiate_abts(io_req);
1196 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
1197 "already in abts processing\n", io_req->xid);
1198 if (cancel_delayed_work(&io_req->timeout_work))
1199 kref_put(&io_req->refcount,
1201 bnx2fc_initiate_cleanup(io_req);
1205 wait_for_completion(&io_req->tm_done);
1208 io_req->wait_for_comp = 0;
1209 rdata = io_req->tgt->rdata;
1212 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1216 BNX2FC_IO_DBG(io_req, "Expl logo - tgt flags = 0x%lx\n",
1235 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1241 wait_for_completion(&io_req->tm_done);
1244 io_req->wait_for_comp = 0;
1246 &io_req->req_flags))) {
1249 io_req->xid);
1257 BNX2FC_IO_DBG(io_req, "abort succeeded\n");
1259 bnx2fc_scsi_done(io_req, DID_ABORT);
1260 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1264 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1304 void bnx2fc_process_cleanup_compl(struct bnx2fc_cmd *io_req,
1308 BNX2FC_IO_DBG(io_req, "Entered process_cleanup_compl "
1310 io_req->refcount.refcount.counter, io_req->cmd_type);
1311 bnx2fc_scsi_done(io_req, DID_ERROR);
1312 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1313 if (io_req->wait_for_comp)
1314 complete(&io_req->tm_done);
1317 void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
1324 struct bnx2fc_rport *tgt = io_req->tgt;
1326 BNX2FC_IO_DBG(io_req, "Entered process_abts_compl xid = 0x%x"
1328 io_req->xid,
1329 io_req->refcount.refcount.counter, io_req->cmd_type);
1332 &io_req->req_flags)) {
1333 BNX2FC_IO_DBG(io_req, "Timer context finished processing"
1340 &io_req->req_flags))
1349 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags))
1350 if (cancel_delayed_work(&io_req->timeout_work))
1351 kref_put(&io_req->refcount,
1362 BNX2FC_IO_DBG(io_req, "ABTS response - ACC Send RRQ\n");
1367 BNX2FC_IO_DBG(io_req, "ABTS response - RJT\n");
1375 BNX2FC_IO_DBG(io_req, "Issue RRQ after R_A_TOV\n");
1376 set_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
1378 set_bit(BNX2FC_FLAG_RETIRE_OXID, &io_req->req_flags);
1379 bnx2fc_cmd_timer_set(io_req, r_a_tov);
1382 if (io_req->wait_for_comp) {
1384 &io_req->req_flags))
1385 complete(&io_req->tm_done);
1396 if (io_req->on_active_queue) {
1397 list_del_init(&io_req->link);
1398 io_req->on_active_queue = 0;
1400 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1402 bnx2fc_scsi_done(io_req, DID_ERROR);
1403 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1407 static void bnx2fc_lun_reset_cmpl(struct bnx2fc_cmd *io_req)
1409 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1410 struct bnx2fc_rport *tgt = io_req->tgt;
1419 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_lun_reset_cmpl\n");
1433 if (cancel_delayed_work(&io_req->timeout_work))
1434 kref_put(&io_req->refcount,
1448 static void bnx2fc_tgt_reset_cmpl(struct bnx2fc_cmd *io_req)
1450 struct bnx2fc_rport *tgt = io_req->tgt;
1457 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_tgt_reset_cmpl\n");
1469 if (cancel_delayed_work(&io_req->timeout_work))
1470 kref_put(&io_req->refcount,
1482 void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
1487 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1493 BNX2FC_IO_DBG(io_req, "Entered process_tm_compl\n");
1495 if (!(test_bit(BNX2FC_FLAG_TM_TIMEOUT, &io_req->req_flags)))
1496 set_bit(BNX2FC_FLAG_TM_COMPL, &io_req->req_flags);
1505 tm_req = &(io_req->mp_req);
1520 bnx2fc_parse_fcp_rsp(io_req,
1523 if (io_req->fcp_rsp_code == 0) {
1526 bnx2fc_lun_reset_cmpl(io_req);
1528 bnx2fc_tgt_reset_cmpl(io_req);
1538 switch (io_req->fcp_status) {
1540 if (io_req->cdb_status == 0) {
1545 sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
1547 if (io_req->fcp_resid)
1548 scsi_set_resid(sc_cmd, io_req->fcp_resid);
1552 BNX2FC_IO_DBG(io_req, "process_tm_compl: fcp_status = %d\n",
1553 io_req->fcp_status);
1557 sc_cmd = io_req->sc_cmd;
1558 io_req->sc_cmd = NULL;
1560 /* check if the io_req exists in tgt's tmf_q */
1561 if (io_req->on_tmf_queue) {
1563 list_del_init(&io_req->link);
1564 io_req->on_tmf_queue = 0;
1574 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1575 if (io_req->wait_for_comp) {
1576 BNX2FC_IO_DBG(io_req, "tm_compl - wake up the waiter\n");
1577 complete(&io_req->tm_done);
1581 static int bnx2fc_split_bd(struct bnx2fc_cmd *io_req, u64 addr, int sg_len,
1584 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1606 static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req)
1608 struct bnx2fc_interface *interface = io_req->port->priv;
1610 struct scsi_cmnd *sc = io_req->sc_cmd;
1611 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1627 sg_frags = bnx2fc_split_bd(io_req, addr, sg_len,
1643 io_req->xid);
1647 static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req)
1649 struct scsi_cmnd *sc = io_req->sc_cmd;
1650 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1654 bd_count = bnx2fc_map_sg(io_req);
1662 io_req->bd_tbl->bd_valid = bd_count;
1667 static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req)
1669 struct scsi_cmnd *sc = io_req->sc_cmd;
1671 if (io_req->bd_tbl->bd_valid && sc) {
1673 io_req->bd_tbl->bd_valid = 0;
1677 void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
1680 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1687 fcp_cmnd->fc_dl = htonl(io_req->data_xfer_len);
1692 fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags;
1693 fcp_cmnd->fc_flags = io_req->io_req_flags;
1712 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
1716 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1717 struct bnx2fc_rport *tgt = io_req->tgt;
1726 io_req->fcp_status = FC_GOOD;
1727 io_req->fcp_resid = fcp_rsp->fcp_resid;
1729 io_req->scsi_comp_flags = rsp_flags;
1730 CMD_SCSI_STATUS(sc_cmd) = io_req->cdb_status =
1754 io_req->fcp_rsp_len = fcp_rsp_len;
1755 io_req->fcp_sns_len = fcp_sns_len;
1776 io_req->fcp_rsp_code = rq_data[3];
1778 io_req->fcp_rsp_code);
1814 struct bnx2fc_cmd *io_req;
1842 io_req = bnx2fc_cmd_alloc(tgt);
1843 if (!io_req) {
1847 io_req->sc_cmd = sc_cmd;
1849 if (bnx2fc_post_io_req(tgt, io_req)) {
1850 printk(KERN_ERR PFX "Unable to post io_req\n");
1858 void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
1863 struct bnx2fc_rport *tgt = io_req->tgt;
1870 if (test_and_set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags)) {
1872 BNX2FC_IO_DBG(io_req, "Timer context finished processing "
1877 if (cancel_delayed_work(&io_req->timeout_work))
1878 kref_put(&io_req->refcount,
1881 sc_cmd = io_req->sc_cmd;
1892 bnx2fc_parse_fcp_rsp(io_req, fcp_rsp, num_rq);
1900 if (io_req->on_active_queue) {
1901 list_del_init(&io_req->link);
1902 io_req->on_active_queue = 0;
1904 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1910 BNX2FC_IO_DBG(io_req, "xid not on active_cmd_queue\n");
1911 if (io_req->wait_for_comp)
1913 &io_req->req_flags))
1914 complete(&io_req->tm_done);
1917 bnx2fc_unmap_sg_list(io_req);
1918 io_req->sc_cmd = NULL;
1920 switch (io_req->fcp_status) {
1922 if (io_req->cdb_status == 0) {
1927 BNX2FC_IO_DBG(io_req, "scsi_cmpl: cdb_status = %d"
1929 io_req->cdb_status, io_req->fcp_resid);
1930 sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
1932 if (io_req->fcp_resid)
1933 scsi_set_resid(sc_cmd, io_req->fcp_resid);
1937 io_req->fcp_status);
1942 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1946 struct bnx2fc_cmd *io_req)
1950 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1959 /* Initialize rest of io_req fields */
1960 io_req->cmd_type = BNX2FC_SCSI_CMD;
1961 io_req->port = port;
1962 io_req->tgt = tgt;
1963 io_req->data_xfer_len = scsi_bufflen(sc_cmd);
1964 sc_cmd->SCp.ptr = (char *)io_req;
1968 io_req->io_req_flags = BNX2FC_READ;
1970 stats->InputBytes += io_req->data_xfer_len;
1972 io_req->io_req_flags = BNX2FC_WRITE;
1974 stats->OutputBytes += io_req->data_xfer_len;
1976 io_req->io_req_flags = 0;
1981 xid = io_req->xid;
1984 if (bnx2fc_build_bd_list_from_sg(io_req)) {
1987 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1998 bnx2fc_init_task(io_req, task);
2004 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2011 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2018 bnx2fc_cmd_timer_set(io_req, BNX2FC_IO_TIMEOUT);
2022 /* Enqueue the io_req to active_cmd_queue */
2024 io_req->on_active_queue = 1;
2025 /* move io_req from pending_queue to active_queue */
2026 list_add_tail(&io_req->link, &tgt->active_cmd_queue);