aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2006-08-31 18:09:28 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-09-02 14:37:18 -0400
commitdd8c0d958621e3137f3e3302f7b8952041a4a1d7 (patch)
tree30b943eebcc044cb3305c449d7eea00376115a22 /drivers
parent62f383003c22cd34920d0412465eddcb1223da0d (diff)
[SCSI] scsi_tcp: rm data rx and tx tfms
We currently allocated seperate tfms for data and header digests. There is no reason for this since we can never calculate a rx header and digest at the same time. Same for sends. So this patch removes the data tfms and has the send and recv sides use the rx_tfm or tx_tfm. I also made the connection creation code preallocate the tfms because I thought I hit a bug where I changed the digests settings during a relogin but could not allocate the tfm and then we just failed. Signed-off-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/iscsi_tcp.c102
-rw-r--r--drivers/scsi/iscsi_tcp.h8
2 files changed, 38 insertions, 72 deletions
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 290c1d76cd40..82399f71028d 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -693,7 +693,7 @@ iscsi_recv_digest_update(struct iscsi_tcp_conn *tcp_conn, char* buf, int len)
693 struct scatterlist tmp; 693 struct scatterlist tmp;
694 694
695 sg_init_one(&tmp, buf, len); 695 sg_init_one(&tmp, buf, len);
696 crypto_digest_update(tcp_conn->data_rx_tfm, &tmp, 1); 696 crypto_digest_update(tcp_conn->rx_tfm, &tmp, 1);
697} 697}
698 698
699static int iscsi_scsi_data_in(struct iscsi_conn *conn) 699static int iscsi_scsi_data_in(struct iscsi_conn *conn)
@@ -748,11 +748,11 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
748 if (conn->datadgst_en) { 748 if (conn->datadgst_en) {
749 if (!offset) 749 if (!offset)
750 crypto_digest_update( 750 crypto_digest_update(
751 tcp_conn->data_rx_tfm, 751 tcp_conn->rx_tfm,
752 &sg[i], 1); 752 &sg[i], 1);
753 else 753 else
754 partial_sg_digest_update( 754 partial_sg_digest_update(
755 tcp_conn->data_rx_tfm, 755 tcp_conn->rx_tfm,
756 &sg[i], 756 &sg[i],
757 sg[i].offset + offset, 757 sg[i].offset + offset,
758 sg[i].length - offset); 758 sg[i].length - offset);
@@ -766,7 +766,7 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
766 /* 766 /*
767 * data-in is complete, but buffer not... 767 * data-in is complete, but buffer not...
768 */ 768 */
769 partial_sg_digest_update(tcp_conn->data_rx_tfm, 769 partial_sg_digest_update(tcp_conn->rx_tfm,
770 &sg[i], 770 &sg[i],
771 sg[i].offset, sg[i].length-rc); 771 sg[i].offset, sg[i].length-rc);
772 rc = 0; 772 rc = 0;
@@ -885,10 +885,8 @@ more:
885 */ 885 */
886 rc = iscsi_tcp_hdr_recv(conn); 886 rc = iscsi_tcp_hdr_recv(conn);
887 if (!rc && tcp_conn->in.datalen) { 887 if (!rc && tcp_conn->in.datalen) {
888 if (conn->datadgst_en) { 888 if (conn->datadgst_en)
889 BUG_ON(!tcp_conn->data_rx_tfm); 889 crypto_digest_init(tcp_conn->rx_tfm);
890 crypto_digest_init(tcp_conn->data_rx_tfm);
891 }
892 tcp_conn->in_progress = IN_PROGRESS_DATA_RECV; 890 tcp_conn->in_progress = IN_PROGRESS_DATA_RECV;
893 } else if (rc) { 891 } else if (rc) {
894 iscsi_conn_failure(conn, rc); 892 iscsi_conn_failure(conn, rc);
@@ -940,10 +938,10 @@ more:
940 tcp_conn->in.padding); 938 tcp_conn->in.padding);
941 memset(pad, 0, tcp_conn->in.padding); 939 memset(pad, 0, tcp_conn->in.padding);
942 sg_init_one(&sg, pad, tcp_conn->in.padding); 940 sg_init_one(&sg, pad, tcp_conn->in.padding);
943 crypto_digest_update(tcp_conn->data_rx_tfm, 941 crypto_digest_update(tcp_conn->rx_tfm,
944 &sg, 1); 942 &sg, 1);
945 } 943 }
946 crypto_digest_final(tcp_conn->data_rx_tfm, 944 crypto_digest_final(tcp_conn->rx_tfm,
947 (u8 *) & tcp_conn->in.datadgst); 945 (u8 *) & tcp_conn->in.datadgst);
948 debug_tcp("rx digest 0x%x\n", tcp_conn->in.datadgst); 946 debug_tcp("rx digest 0x%x\n", tcp_conn->in.datadgst);
949 tcp_conn->in_progress = IN_PROGRESS_DDIGEST_RECV; 947 tcp_conn->in_progress = IN_PROGRESS_DDIGEST_RECV;
@@ -1188,7 +1186,7 @@ static inline void
1188iscsi_data_digest_init(struct iscsi_tcp_conn *tcp_conn, 1186iscsi_data_digest_init(struct iscsi_tcp_conn *tcp_conn,
1189 struct iscsi_tcp_cmd_task *tcp_ctask) 1187 struct iscsi_tcp_cmd_task *tcp_ctask)
1190{ 1188{
1191 crypto_digest_init(tcp_conn->data_tx_tfm); 1189 crypto_digest_init(tcp_conn->tx_tfm);
1192 tcp_ctask->digest_count = 4; 1190 tcp_ctask->digest_count = 4;
1193} 1191}
1194 1192
@@ -1444,7 +1442,7 @@ iscsi_send_padding(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1444 iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad, 1442 iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad,
1445 tcp_ctask->pad_count); 1443 tcp_ctask->pad_count);
1446 if (conn->datadgst_en) 1444 if (conn->datadgst_en)
1447 crypto_digest_update(tcp_conn->data_tx_tfm, 1445 crypto_digest_update(tcp_conn->tx_tfm,
1448 &tcp_ctask->sendbuf.sg, 1); 1446 &tcp_ctask->sendbuf.sg, 1);
1449 } else if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_PAD)) 1447 } else if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_PAD))
1450 return 0; 1448 return 0;
@@ -1477,7 +1475,7 @@ iscsi_send_digest(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1477 tcp_conn = conn->dd_data; 1475 tcp_conn = conn->dd_data;
1478 1476
1479 if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_DATA_DIGEST)) { 1477 if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_DATA_DIGEST)) {
1480 crypto_digest_final(tcp_conn->data_tx_tfm, (u8*)digest); 1478 crypto_digest_final(tcp_conn->tx_tfm, (u8*)digest);
1481 iscsi_buf_init_iov(buf, (char*)digest, 4); 1479 iscsi_buf_init_iov(buf, (char*)digest, 4);
1482 } 1480 }
1483 tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_DATA_DIGEST; 1481 tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_DATA_DIGEST;
@@ -1511,7 +1509,7 @@ iscsi_send_data(struct iscsi_cmd_task *ctask, struct iscsi_buf *sendbuf,
1511 rc = iscsi_sendpage(conn, sendbuf, count, &buf_sent); 1509 rc = iscsi_sendpage(conn, sendbuf, count, &buf_sent);
1512 *sent = *sent + buf_sent; 1510 *sent = *sent + buf_sent;
1513 if (buf_sent && conn->datadgst_en) 1511 if (buf_sent && conn->datadgst_en)
1514 partial_sg_digest_update(tcp_conn->data_tx_tfm, 1512 partial_sg_digest_update(tcp_conn->tx_tfm,
1515 &sendbuf->sg, sendbuf->sg.offset + offset, 1513 &sendbuf->sg, sendbuf->sg.offset + offset,
1516 buf_sent); 1514 buf_sent);
1517 if (!iscsi_buf_left(sendbuf) && *sg != tcp_ctask->bad_sg) { 1515 if (!iscsi_buf_left(sendbuf) && *sg != tcp_ctask->bad_sg) {
@@ -1547,10 +1545,6 @@ iscsi_send_unsol_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1547 if (conn->hdrdgst_en) 1545 if (conn->hdrdgst_en)
1548 iscsi_hdr_digest(conn, &tcp_ctask->headbuf, 1546 iscsi_hdr_digest(conn, &tcp_ctask->headbuf,
1549 (u8*)dtask->hdrext); 1547 (u8*)dtask->hdrext);
1550 if (conn->datadgst_en) {
1551 iscsi_data_digest_init(ctask->conn->dd_data, tcp_ctask);
1552 dtask->digest = 0;
1553 }
1554 1548
1555 tcp_ctask->xmstate &= ~XMSTATE_UNS_INIT; 1549 tcp_ctask->xmstate &= ~XMSTATE_UNS_INIT;
1556 iscsi_set_padding(tcp_ctask, ctask->data_count); 1550 iscsi_set_padding(tcp_ctask, ctask->data_count);
@@ -1563,6 +1557,12 @@ iscsi_send_unsol_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1563 return rc; 1557 return rc;
1564 } 1558 }
1565 1559
1560 if (conn->datadgst_en) {
1561 dtask = &tcp_ctask->unsol_dtask;
1562 iscsi_data_digest_init(ctask->conn->dd_data, tcp_ctask);
1563 dtask->digest = 0;
1564 }
1565
1566 debug_scsi("uns dout [itt 0x%x dlen %d sent %d]\n", 1566 debug_scsi("uns dout [itt 0x%x dlen %d sent %d]\n",
1567 ctask->itt, ctask->unsol_count, tcp_ctask->sent); 1567 ctask->itt, ctask->unsol_count, tcp_ctask->sent);
1568 return 0; 1568 return 0;
@@ -1629,12 +1629,6 @@ send_hdr:
1629 if (conn->hdrdgst_en) 1629 if (conn->hdrdgst_en)
1630 iscsi_hdr_digest(conn, &r2t->headbuf, 1630 iscsi_hdr_digest(conn, &r2t->headbuf,
1631 (u8*)dtask->hdrext); 1631 (u8*)dtask->hdrext);
1632
1633 if (conn->datadgst_en) {
1634 iscsi_data_digest_init(conn->dd_data, tcp_ctask);
1635 dtask->digest = 0;
1636 }
1637
1638 rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count); 1632 rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count);
1639 if (rc) { 1633 if (rc) {
1640 tcp_ctask->xmstate &= ~XMSTATE_SOL_DATA; 1634 tcp_ctask->xmstate &= ~XMSTATE_SOL_DATA;
@@ -1642,6 +1636,11 @@ send_hdr:
1642 return rc; 1636 return rc;
1643 } 1637 }
1644 1638
1639 if (conn->datadgst_en) {
1640 iscsi_data_digest_init(conn->dd_data, tcp_ctask);
1641 dtask->digest = 0;
1642 }
1643
1645 iscsi_set_padding(tcp_ctask, r2t->data_count); 1644 iscsi_set_padding(tcp_ctask, r2t->data_count);
1646 debug_scsi("sol dout [dsn %d itt 0x%x dlen %d sent %d]\n", 1645 debug_scsi("sol dout [dsn %d itt 0x%x dlen %d sent %d]\n",
1647 r2t->solicit_datasn - 1, ctask->itt, r2t->data_count, 1646 r2t->solicit_datasn - 1, ctask->itt, r2t->data_count,
@@ -1764,8 +1763,20 @@ iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1764 /* initial operational parameters */ 1763 /* initial operational parameters */
1765 tcp_conn->hdr_size = sizeof(struct iscsi_hdr); 1764 tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
1766 1765
1766 tcp_conn->tx_tfm = crypto_alloc_tfm("crc32c", 0);
1767 if (!tcp_conn->tx_tfm)
1768 goto free_tcp_conn;
1769
1770 tcp_conn->rx_tfm = crypto_alloc_tfm("crc32c", 0);
1771 if (!tcp_conn->rx_tfm)
1772 goto free_tx_tfm;
1773
1767 return cls_conn; 1774 return cls_conn;
1768 1775
1776free_tx_tfm:
1777 crypto_free_tfm(tcp_conn->tx_tfm);
1778free_tcp_conn:
1779 kfree(tcp_conn);
1769tcp_conn_alloc_fail: 1780tcp_conn_alloc_fail:
1770 iscsi_conn_teardown(cls_conn); 1781 iscsi_conn_teardown(cls_conn);
1771 return NULL; 1782 return NULL;
@@ -1807,10 +1818,6 @@ iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
1807 crypto_free_tfm(tcp_conn->tx_tfm); 1818 crypto_free_tfm(tcp_conn->tx_tfm);
1808 if (tcp_conn->rx_tfm) 1819 if (tcp_conn->rx_tfm)
1809 crypto_free_tfm(tcp_conn->rx_tfm); 1820 crypto_free_tfm(tcp_conn->rx_tfm);
1810 if (tcp_conn->data_tx_tfm)
1811 crypto_free_tfm(tcp_conn->data_tx_tfm);
1812 if (tcp_conn->data_rx_tfm)
1813 crypto_free_tfm(tcp_conn->data_rx_tfm);
1814 } 1821 }
1815 1822
1816 kfree(tcp_conn); 1823 kfree(tcp_conn);
@@ -1968,48 +1975,11 @@ iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param,
1968 case ISCSI_PARAM_HDRDGST_EN: 1975 case ISCSI_PARAM_HDRDGST_EN:
1969 iscsi_set_param(cls_conn, param, buf, buflen); 1976 iscsi_set_param(cls_conn, param, buf, buflen);
1970 tcp_conn->hdr_size = sizeof(struct iscsi_hdr); 1977 tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
1971 if (conn->hdrdgst_en) { 1978 if (conn->hdrdgst_en)
1972 tcp_conn->hdr_size += sizeof(__u32); 1979 tcp_conn->hdr_size += sizeof(__u32);
1973 if (!tcp_conn->tx_tfm)
1974 tcp_conn->tx_tfm = crypto_alloc_tfm("crc32c",
1975 0);
1976 if (!tcp_conn->tx_tfm)
1977 return -ENOMEM;
1978 if (!tcp_conn->rx_tfm)
1979 tcp_conn->rx_tfm = crypto_alloc_tfm("crc32c",
1980 0);
1981 if (!tcp_conn->rx_tfm) {
1982 crypto_free_tfm(tcp_conn->tx_tfm);
1983 return -ENOMEM;
1984 }
1985 } else {
1986 if (tcp_conn->tx_tfm)
1987 crypto_free_tfm(tcp_conn->tx_tfm);
1988 if (tcp_conn->rx_tfm)
1989 crypto_free_tfm(tcp_conn->rx_tfm);
1990 }
1991 break; 1980 break;
1992 case ISCSI_PARAM_DATADGST_EN: 1981 case ISCSI_PARAM_DATADGST_EN:
1993 iscsi_set_param(cls_conn, param, buf, buflen); 1982 iscsi_set_param(cls_conn, param, buf, buflen);
1994 if (conn->datadgst_en) {
1995 if (!tcp_conn->data_tx_tfm)
1996 tcp_conn->data_tx_tfm =
1997 crypto_alloc_tfm("crc32c", 0);
1998 if (!tcp_conn->data_tx_tfm)
1999 return -ENOMEM;
2000 if (!tcp_conn->data_rx_tfm)
2001 tcp_conn->data_rx_tfm =
2002 crypto_alloc_tfm("crc32c", 0);
2003 if (!tcp_conn->data_rx_tfm) {
2004 crypto_free_tfm(tcp_conn->data_tx_tfm);
2005 return -ENOMEM;
2006 }
2007 } else {
2008 if (tcp_conn->data_tx_tfm)
2009 crypto_free_tfm(tcp_conn->data_tx_tfm);
2010 if (tcp_conn->data_rx_tfm)
2011 crypto_free_tfm(tcp_conn->data_rx_tfm);
2012 }
2013 tcp_conn->sendpage = conn->datadgst_en ? 1983 tcp_conn->sendpage = conn->datadgst_en ?
2014 sock_no_sendpage : tcp_conn->sock->ops->sendpage; 1984 sock_no_sendpage : tcp_conn->sock->ops->sendpage;
2015 break; 1985 break;
diff --git a/drivers/scsi/iscsi_tcp.h b/drivers/scsi/iscsi_tcp.h
index 7e40e94d9fdc..609f4778d125 100644
--- a/drivers/scsi/iscsi_tcp.h
+++ b/drivers/scsi/iscsi_tcp.h
@@ -81,10 +81,6 @@ struct iscsi_tcp_conn {
81 * stop to terminate */ 81 * stop to terminate */
82 /* iSCSI connection-wide sequencing */ 82 /* iSCSI connection-wide sequencing */
83 int hdr_size; /* PDU header size */ 83 int hdr_size; /* PDU header size */
84
85 struct crypto_tfm *rx_tfm; /* CRC32C (Rx) */
86 struct crypto_tfm *data_rx_tfm; /* CRC32C (Rx) for data */
87
88 /* control data */ 84 /* control data */
89 struct iscsi_tcp_recv in; /* TCP receive context */ 85 struct iscsi_tcp_recv in; /* TCP receive context */
90 int in_progress; /* connection state machine */ 86 int in_progress; /* connection state machine */
@@ -94,9 +90,9 @@ struct iscsi_tcp_conn {
94 void (*old_state_change)(struct sock *); 90 void (*old_state_change)(struct sock *);
95 void (*old_write_space)(struct sock *); 91 void (*old_write_space)(struct sock *);
96 92
97 /* xmit */ 93 /* data and header digests */
98 struct crypto_tfm *tx_tfm; /* CRC32C (Tx) */ 94 struct crypto_tfm *tx_tfm; /* CRC32C (Tx) */
99 struct crypto_tfm *data_tx_tfm; /* CRC32C (Tx) for data */ 95 struct crypto_tfm *rx_tfm; /* CRC32C (Rx) */
100 96
101 /* MIB custom statistics */ 97 /* MIB custom statistics */
102 uint32_t sendpage_failures_cnt; 98 uint32_t sendpage_failures_cnt;