hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/scsi/bnx2fc/bnx2fc_io.c
....@@ -24,7 +24,7 @@
2424 static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req);
2525 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
2626 struct fcoe_fcp_rsp_payload *fcp_rsp,
27
- u8 num_rq);
27
+ u8 num_rq, unsigned char *rq_data);
2828
2929 void bnx2fc_cmd_timer_set(struct bnx2fc_cmd *io_req,
3030 unsigned int timer_msec)
....@@ -70,7 +70,7 @@
7070 &io_req->req_flags)) {
7171 /* Handle eh_abort timeout */
7272 BNX2FC_IO_DBG(io_req, "eh_abort timed out\n");
73
- complete(&io_req->tm_done);
73
+ complete(&io_req->abts_done);
7474 } else if (test_bit(BNX2FC_FLAG_ISSUE_ABTS,
7575 &io_req->req_flags)) {
7676 /* Handle internally generated ABTS timeout */
....@@ -775,31 +775,32 @@
775775 io_req->on_tmf_queue = 1;
776776 list_add_tail(&io_req->link, &tgt->active_tm_queue);
777777
778
- init_completion(&io_req->tm_done);
779
- io_req->wait_for_comp = 1;
778
+ init_completion(&io_req->abts_done);
779
+ io_req->wait_for_abts_comp = 1;
780780
781781 /* Ring doorbell */
782782 bnx2fc_ring_doorbell(tgt);
783783 spin_unlock_bh(&tgt->tgt_lock);
784784
785
- rc = wait_for_completion_timeout(&io_req->tm_done,
785
+ rc = wait_for_completion_timeout(&io_req->abts_done,
786786 interface->tm_timeout * HZ);
787787 spin_lock_bh(&tgt->tgt_lock);
788788
789
- io_req->wait_for_comp = 0;
789
+ io_req->wait_for_abts_comp = 0;
790790 if (!(test_bit(BNX2FC_FLAG_TM_COMPL, &io_req->req_flags))) {
791791 set_bit(BNX2FC_FLAG_TM_TIMEOUT, &io_req->req_flags);
792792 if (io_req->on_tmf_queue) {
793793 list_del_init(&io_req->link);
794794 io_req->on_tmf_queue = 0;
795795 }
796
- io_req->wait_for_comp = 1;
796
+ io_req->wait_for_cleanup_comp = 1;
797
+ init_completion(&io_req->cleanup_done);
797798 bnx2fc_initiate_cleanup(io_req);
798799 spin_unlock_bh(&tgt->tgt_lock);
799
- rc = wait_for_completion_timeout(&io_req->tm_done,
800
+ rc = wait_for_completion_timeout(&io_req->cleanup_done,
800801 BNX2FC_FW_TIMEOUT);
801802 spin_lock_bh(&tgt->tgt_lock);
802
- io_req->wait_for_comp = 0;
803
+ io_req->wait_for_cleanup_comp = 0;
803804 if (!rc)
804805 kref_put(&io_req->refcount, bnx2fc_cmd_release);
805806 }
....@@ -863,7 +864,7 @@
863864
864865 abts_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_ABTS);
865866 if (!abts_io_req) {
866
- printk(KERN_ERR PFX "abts: couldnt allocate cmd\n");
867
+ printk(KERN_ERR PFX "abts: couldn't allocate cmd\n");
867868 rc = FAILED;
868869 goto abts_err;
869870 }
....@@ -929,7 +930,6 @@
929930 int bnx2fc_initiate_seq_cleanup(struct bnx2fc_cmd *orig_io_req, u32 offset,
930931 enum fc_rctl r_ctl)
931932 {
932
- struct fc_lport *lport;
933933 struct bnx2fc_rport *tgt = orig_io_req->tgt;
934934 struct bnx2fc_interface *interface;
935935 struct fcoe_port *port;
....@@ -947,7 +947,6 @@
947947
948948 port = orig_io_req->port;
949949 interface = port->priv;
950
- lport = port->lport;
951950
952951 cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
953952 if (!cb_arg) {
....@@ -958,7 +957,7 @@
958957
959958 seq_clnp_req = bnx2fc_elstm_alloc(tgt, BNX2FC_SEQ_CLEANUP);
960959 if (!seq_clnp_req) {
961
- printk(KERN_ERR PFX "cleanup: couldnt allocate cmd\n");
960
+ printk(KERN_ERR PFX "cleanup: couldn't allocate cmd\n");
962961 rc = -ENOMEM;
963962 kfree(cb_arg);
964963 goto cleanup_err;
....@@ -998,7 +997,6 @@
998997
999998 int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
1000999 {
1001
- struct fc_lport *lport;
10021000 struct bnx2fc_rport *tgt = io_req->tgt;
10031001 struct bnx2fc_interface *interface;
10041002 struct fcoe_port *port;
....@@ -1014,11 +1012,10 @@
10141012
10151013 port = io_req->port;
10161014 interface = port->priv;
1017
- lport = port->lport;
10181015
10191016 cleanup_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_CLEANUP);
10201017 if (!cleanup_io_req) {
1021
- printk(KERN_ERR PFX "cleanup: couldnt allocate cmd\n");
1018
+ printk(KERN_ERR PFX "cleanup: couldn't allocate cmd\n");
10221019 rc = -1;
10231020 goto cleanup_err;
10241021 }
....@@ -1046,6 +1043,9 @@
10461043
10471044 /* Obtain free SQ entry */
10481045 bnx2fc_add_2_sq(tgt, xid);
1046
+
1047
+ /* Set flag that cleanup request is pending with the firmware */
1048
+ set_bit(BNX2FC_FLAG_ISSUE_CLEANUP_REQ, &io_req->req_flags);
10491049
10501050 /* Ring doorbell */
10511051 bnx2fc_ring_doorbell(tgt);
....@@ -1081,12 +1081,13 @@
10811081 }
10821082
10831083 static int bnx2fc_abts_cleanup(struct bnx2fc_cmd *io_req)
1084
+ __must_hold(&tgt->tgt_lock)
10841085 {
10851086 struct bnx2fc_rport *tgt = io_req->tgt;
1086
- int rc = SUCCESS;
10871087 unsigned int time_left;
10881088
1089
- io_req->wait_for_comp = 1;
1089
+ init_completion(&io_req->cleanup_done);
1090
+ io_req->wait_for_cleanup_comp = 1;
10901091 bnx2fc_initiate_cleanup(io_req);
10911092
10921093 spin_unlock_bh(&tgt->tgt_lock);
....@@ -1095,22 +1096,22 @@
10951096 * Can't wait forever on cleanup response lest we let the SCSI error
10961097 * handler wait forever
10971098 */
1098
- time_left = wait_for_completion_timeout(&io_req->tm_done,
1099
+ time_left = wait_for_completion_timeout(&io_req->cleanup_done,
10991100 BNX2FC_FW_TIMEOUT);
1100
- io_req->wait_for_comp = 0;
1101
- if (!time_left)
1101
+ if (!time_left) {
11021102 BNX2FC_IO_DBG(io_req, "%s(): Wait for cleanup timed out.\n",
11031103 __func__);
11041104
1105
- /*
1106
- * Release reference held by SCSI command the cleanup completion
1107
- * hits the BNX2FC_CLEANUP case in bnx2fc_process_cq_compl() and
1108
- * thus the SCSI command is not returnedi by bnx2fc_scsi_done().
1109
- */
1110
- kref_put(&io_req->refcount, bnx2fc_cmd_release);
1105
+ /*
1106
+ * Put the extra reference to the SCSI command since it would
1107
+ * not have been returned in this case.
1108
+ */
1109
+ kref_put(&io_req->refcount, bnx2fc_cmd_release);
1110
+ }
11111111
11121112 spin_lock_bh(&tgt->tgt_lock);
1113
- return rc;
1113
+ io_req->wait_for_cleanup_comp = 0;
1114
+ return SUCCESS;
11141115 }
11151116
11161117 /**
....@@ -1198,7 +1199,8 @@
11981199 /* Move IO req to retire queue */
11991200 list_add_tail(&io_req->link, &tgt->io_retire_queue);
12001201
1201
- init_completion(&io_req->tm_done);
1202
+ init_completion(&io_req->abts_done);
1203
+ init_completion(&io_req->cleanup_done);
12021204
12031205 if (test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
12041206 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
....@@ -1227,26 +1229,28 @@
12271229 kref_put(&io_req->refcount,
12281230 bnx2fc_cmd_release); /* drop timer hold */
12291231 set_bit(BNX2FC_FLAG_EH_ABORT, &io_req->req_flags);
1230
- io_req->wait_for_comp = 1;
1232
+ io_req->wait_for_abts_comp = 1;
12311233 rc = bnx2fc_initiate_abts(io_req);
12321234 if (rc == FAILED) {
1235
+ io_req->wait_for_cleanup_comp = 1;
12331236 bnx2fc_initiate_cleanup(io_req);
12341237 spin_unlock_bh(&tgt->tgt_lock);
1235
- wait_for_completion(&io_req->tm_done);
1238
+ wait_for_completion(&io_req->cleanup_done);
12361239 spin_lock_bh(&tgt->tgt_lock);
1237
- io_req->wait_for_comp = 0;
1240
+ io_req->wait_for_cleanup_comp = 0;
12381241 goto done;
12391242 }
12401243 spin_unlock_bh(&tgt->tgt_lock);
12411244
12421245 /* Wait 2 * RA_TOV + 1 to be sure timeout function hasn't fired */
1243
- time_left = wait_for_completion_timeout(&io_req->tm_done,
1244
- (2 * rp->r_a_tov + 1) * HZ);
1246
+ time_left = wait_for_completion_timeout(&io_req->abts_done,
1247
+ msecs_to_jiffies(2 * rp->r_a_tov + 1));
12451248 if (time_left)
1246
- BNX2FC_IO_DBG(io_req, "Timed out in eh_abort waiting for tm_done");
1249
+ BNX2FC_IO_DBG(io_req,
1250
+ "Timed out in eh_abort waiting for abts_done");
12471251
12481252 spin_lock_bh(&tgt->tgt_lock);
1249
- io_req->wait_for_comp = 0;
1253
+ io_req->wait_for_abts_comp = 0;
12501254 if (test_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags)) {
12511255 BNX2FC_IO_DBG(io_req, "IO completed in a different context\n");
12521256 rc = SUCCESS;
....@@ -1321,10 +1325,29 @@
13211325 BNX2FC_IO_DBG(io_req, "Entered process_cleanup_compl "
13221326 "refcnt = %d, cmd_type = %d\n",
13231327 kref_read(&io_req->refcount), io_req->cmd_type);
1328
+ /*
1329
+ * Test whether there is a cleanup request pending. If not just
1330
+ * exit.
1331
+ */
1332
+ if (!test_and_clear_bit(BNX2FC_FLAG_ISSUE_CLEANUP_REQ,
1333
+ &io_req->req_flags))
1334
+ return;
1335
+ /*
1336
+ * If we receive a cleanup completion for this request then the
1337
+ * firmware will not give us an abort completion for this request
1338
+ * so clear any ABTS pending flags.
1339
+ */
1340
+ if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags) &&
1341
+ !test_bit(BNX2FC_FLAG_ABTS_DONE, &io_req->req_flags)) {
1342
+ set_bit(BNX2FC_FLAG_ABTS_DONE, &io_req->req_flags);
1343
+ if (io_req->wait_for_abts_comp)
1344
+ complete(&io_req->abts_done);
1345
+ }
1346
+
13241347 bnx2fc_scsi_done(io_req, DID_ERROR);
13251348 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1326
- if (io_req->wait_for_comp)
1327
- complete(&io_req->tm_done);
1349
+ if (io_req->wait_for_cleanup_comp)
1350
+ complete(&io_req->cleanup_done);
13281351 }
13291352
13301353 void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
....@@ -1346,6 +1369,16 @@
13461369 BNX2FC_IO_DBG(io_req, "Timer context finished processing"
13471370 " this io\n");
13481371 return;
1372
+ }
1373
+
1374
+ /*
1375
+ * If we receive an ABTS completion here then we will not receive
1376
+ * a cleanup completion so clear any cleanup pending flags.
1377
+ */
1378
+ if (test_bit(BNX2FC_FLAG_ISSUE_CLEANUP_REQ, &io_req->req_flags)) {
1379
+ clear_bit(BNX2FC_FLAG_ISSUE_CLEANUP_REQ, &io_req->req_flags);
1380
+ if (io_req->wait_for_cleanup_comp)
1381
+ complete(&io_req->cleanup_done);
13491382 }
13501383
13511384 /* Do not issue RRQ as this IO is already cleanedup */
....@@ -1392,10 +1425,10 @@
13921425 bnx2fc_cmd_timer_set(io_req, r_a_tov);
13931426
13941427 io_compl:
1395
- if (io_req->wait_for_comp) {
1428
+ if (io_req->wait_for_abts_comp) {
13961429 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
13971430 &io_req->req_flags))
1398
- complete(&io_req->tm_done);
1431
+ complete(&io_req->abts_done);
13991432 } else {
14001433 /*
14011434 * We end up here when ABTS is issued as
....@@ -1487,7 +1520,8 @@
14871520 }
14881521
14891522 void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
1490
- struct fcoe_task_ctx_entry *task, u8 num_rq)
1523
+ struct fcoe_task_ctx_entry *task, u8 num_rq,
1524
+ unsigned char *rq_data)
14911525 {
14921526 struct bnx2fc_mp_req *tm_req;
14931527 struct fc_frame_header *fc_hdr;
....@@ -1526,7 +1560,7 @@
15261560 if (fc_hdr->fh_r_ctl == FC_RCTL_DD_CMD_STATUS) {
15271561 bnx2fc_parse_fcp_rsp(io_req,
15281562 (struct fcoe_fcp_rsp_payload *)
1529
- rsp_buf, num_rq);
1563
+ rsp_buf, num_rq, rq_data);
15301564 if (io_req->fcp_rsp_code == 0) {
15311565 /* TM successful */
15321566 if (tm_req->tm_flags & FCP_TMF_LUN_RESET)
....@@ -1579,9 +1613,9 @@
15791613 sc_cmd->scsi_done(sc_cmd);
15801614
15811615 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1582
- if (io_req->wait_for_comp) {
1616
+ if (io_req->wait_for_abts_comp) {
15831617 BNX2FC_IO_DBG(io_req, "tm_compl - wake up the waiter\n");
1584
- complete(&io_req->tm_done);
1618
+ complete(&io_req->abts_done);
15851619 }
15861620 }
15871621
....@@ -1625,6 +1659,7 @@
16251659 u64 addr;
16261660 int i;
16271661
1662
+ WARN_ON(scsi_sg_count(sc) > BNX2FC_MAX_BDS_PER_CMD);
16281663 /*
16291664 * Use dma_map_sg directly to ensure we're using the correct
16301665 * dev struct off of pcidev.
....@@ -1672,6 +1707,16 @@
16721707 }
16731708 io_req->bd_tbl->bd_valid = bd_count;
16741709
1710
+ /*
1711
+ * Return the command to ML if BD count exceeds the max number
1712
+ * that can be handled by FW.
1713
+ */
1714
+ if (bd_count > BNX2FC_FW_MAX_BDS_PER_CMD) {
1715
+ pr_err("bd_count = %d exceeded FW supported max BD(255), task_id = 0x%x\n",
1716
+ bd_count, io_req->xid);
1717
+ return -ENOMEM;
1718
+ }
1719
+
16751720 return 0;
16761721 }
16771722
....@@ -1713,15 +1758,11 @@
17131758
17141759 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
17151760 struct fcoe_fcp_rsp_payload *fcp_rsp,
1716
- u8 num_rq)
1761
+ u8 num_rq, unsigned char *rq_data)
17171762 {
17181763 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1719
- struct bnx2fc_rport *tgt = io_req->tgt;
17201764 u8 rsp_flags = fcp_rsp->fcp_flags.flags;
17211765 u32 rq_buff_len = 0;
1722
- int i;
1723
- unsigned char *rq_data;
1724
- unsigned char *dummy;
17251766 int fcp_sns_len = 0;
17261767 int fcp_rsp_len = 0;
17271768
....@@ -1767,14 +1808,6 @@
17671808 rq_buff_len = num_rq * BNX2FC_RQ_BUF_SZ;
17681809 }
17691810
1770
- rq_data = bnx2fc_get_next_rqe(tgt, 1);
1771
-
1772
- if (num_rq > 1) {
1773
- /* We do not need extra sense data */
1774
- for (i = 1; i < num_rq; i++)
1775
- dummy = bnx2fc_get_next_rqe(tgt, 1);
1776
- }
1777
-
17781811 /* fetch fcp_rsp_code */
17791812 if ((fcp_rsp_len == 4) || (fcp_rsp_len == 8)) {
17801813 /* Only for task management function */
....@@ -1795,9 +1828,6 @@
17951828 if (fcp_sns_len)
17961829 memcpy(sc_cmd->sense_buffer, rq_data, fcp_sns_len);
17971830
1798
- /* return RQ entries */
1799
- for (i = 0; i < num_rq; i++)
1800
- bnx2fc_return_rqe(tgt, 1);
18011831 }
18021832 }
18031833
....@@ -1876,13 +1906,12 @@
18761906
18771907 void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
18781908 struct fcoe_task_ctx_entry *task,
1879
- u8 num_rq)
1909
+ u8 num_rq, unsigned char *rq_data)
18801910 {
18811911 struct fcoe_fcp_rsp_payload *fcp_rsp;
18821912 struct bnx2fc_rport *tgt = io_req->tgt;
18831913 struct scsi_cmnd *sc_cmd;
1884
- struct Scsi_Host *host;
1885
-
1914
+ u16 scope = 0, qualifier = 0;
18861915
18871916 /* scsi_cmd_cmpl is called with tgt lock held */
18881917
....@@ -1890,6 +1919,12 @@
18901919 /* we will not receive ABTS response for this IO */
18911920 BNX2FC_IO_DBG(io_req, "Timer context finished processing "
18921921 "this scsi cmd\n");
1922
+ if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
1923
+ &io_req->req_flags)) {
1924
+ BNX2FC_IO_DBG(io_req,
1925
+ "Actual completion after cleanup request cleaning up\n");
1926
+ bnx2fc_process_cleanup_compl(io_req, task, num_rq);
1927
+ }
18931928 return;
18941929 }
18951930
....@@ -1909,9 +1944,8 @@
19091944 &(task->rxwr_only.union_ctx.comp_info.fcp_rsp.payload);
19101945
19111946 /* parse fcp_rsp and obtain sense data from RQ if available */
1912
- bnx2fc_parse_fcp_rsp(io_req, fcp_rsp, num_rq);
1947
+ bnx2fc_parse_fcp_rsp(io_req, fcp_rsp, num_rq, rq_data);
19131948
1914
- host = sc_cmd->device->host;
19151949 if (!sc_cmd->SCp.ptr) {
19161950 printk(KERN_ERR PFX "SCp.ptr is NULL\n");
19171951 return;
....@@ -1928,10 +1962,10 @@
19281962 * between command abort and (late) completion.
19291963 */
19301964 BNX2FC_IO_DBG(io_req, "xid not on active_cmd_queue\n");
1931
- if (io_req->wait_for_comp)
1965
+ if (io_req->wait_for_abts_comp)
19321966 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
19331967 &io_req->req_flags))
1934
- complete(&io_req->tm_done);
1968
+ complete(&io_req->abts_done);
19351969 }
19361970
19371971 bnx2fc_unmap_sg_list(io_req);
....@@ -1951,12 +1985,30 @@
19511985
19521986 if (io_req->cdb_status == SAM_STAT_TASK_SET_FULL ||
19531987 io_req->cdb_status == SAM_STAT_BUSY) {
1954
- /* Set the jiffies + retry_delay_timer * 100ms
1955
- for the rport/tgt */
1956
- tgt->retry_delay_timestamp = jiffies +
1957
- fcp_rsp->retry_delay_timer * HZ / 10;
1988
+ /* Newer array firmware with BUSY or
1989
+ * TASK_SET_FULL may return a status that needs
1990
+ * the scope bits masked.
1991
+ * Or a huge delay timestamp up to 27 minutes
1992
+ * can result.
1993
+ */
1994
+ if (fcp_rsp->retry_delay_timer) {
1995
+ /* Upper 2 bits */
1996
+ scope = fcp_rsp->retry_delay_timer
1997
+ & 0xC000;
1998
+ /* Lower 14 bits */
1999
+ qualifier = fcp_rsp->retry_delay_timer
2000
+ & 0x3FFF;
2001
+ }
2002
+ if (scope > 0 && qualifier > 0 &&
2003
+ qualifier <= 0x3FEF) {
2004
+ /* Set the jiffies +
2005
+ * retry_delay_timer * 100ms
2006
+ * for the rport/tgt
2007
+ */
2008
+ tgt->retry_delay_timestamp = jiffies +
2009
+ (qualifier * HZ / 10);
2010
+ }
19582011 }
1959
-
19602012 }
19612013 if (io_req->fcp_resid)
19622014 scsi_set_resid(sc_cmd, io_req->fcp_resid);