29 #include <linux/types.h>
30 #include <linux/list.h>
32 #include <linux/slab.h>
39 #include <linux/module.h>
44 #include <scsi/scsi.h>
55 static int iscsi_dbg_libtcp;
59 "module. Set to 1 to turn on, and zero to turn off. Default "
62 #define ISCSI_DBG_TCP(_conn, dbg_fmt, arg...) \
64 if (iscsi_dbg_libtcp) \
65 iscsi_conn_printk(KERN_INFO, _conn, \
70 static int iscsi_tcp_hdr_recv_done(
struct iscsi_tcp_conn *tcp_conn,
133 if (page_count(sg_page(sg)) >= 1 && !recv)
201 recv ?
"recv" :
"xmit");
202 if (segment->
hash && copied) {
209 if (!segment->
data) {
211 sg_set_page(&sg, sg_page(segment->
sg), copied,
213 segment->
sg->offset);
217 crypto_hash_update(segment->
hash, &sg, copied);
220 segment->
copied += copied;
222 iscsi_tcp_segment_map(segment, recv);
238 iscsi_tcp_segment_init_sg(segment,
sg_next(segment->
sg),
240 iscsi_tcp_segment_map(segment, recv);
250 "consume %d pad bytes\n", pad);
263 crypto_hash_final(segment->
hash, segment->
digest);
264 iscsi_tcp_segment_splice_digest(segment,
295 unsigned int copy = 0, copied = 0;
300 "copied %d bytes\n", len);
319 crypto_hash_digest(hash, &sg, hdrlen,
digest);
346 memset(segment, 0,
sizeof(*segment));
352 crypto_hash_init(hash);
361 __iscsi_segment_init(segment, size, done, hash);
370 unsigned int offset,
size_t size,
376 __iscsi_segment_init(segment, size, done, hash);
379 iscsi_tcp_segment_init_sg(segment, sg, offset);
401 "digest enabled" :
"digest disabled");
404 iscsi_tcp_hdr_recv_done,
NULL);
418 if (!iscsi_tcp_dgst_verify(tcp_conn, segment))
422 conn->
data, tcp_conn->
in.datalen);
441 conn->
data, tcp_conn->
in.datalen,
442 iscsi_tcp_data_recv_done, rx_hash);
487 unsigned total_in_length = scsi_in(task->
sc)->length;
496 if (tcp_conn->
in.datalen == 0)
500 ISCSI_DBG_TCP(conn,
"task->exp_datasn(%d) != rhdr->datasn(%d)"
508 if (tcp_task->
data_offset + tcp_conn->
in.datalen > total_in_length) {
511 tcp_conn->
in.datalen, total_in_length);
534 if (tcp_conn->
in.datalen) {
536 "invalid R2t with datalen %d\n",
537 tcp_conn->
in.datalen);
542 ISCSI_DBG_TCP(conn,
"task->exp_datasn(%d) != rhdr->r2tsn(%d)\n",
552 "dropping R2T itt %d in recovery.\n",
560 "Target has sent more R2Ts than it "
561 "negotiated for or driver has has leaked.\n");
565 r2t->exp_statsn = rhdr->
statsn;
567 if (r2t->data_length == 0) {
569 "invalid R2T with zero data len\n");
575 if (r2t->data_length > session->
max_burst)
577 "burst %u. Attempting to execute request.\n",
581 if (r2t->data_offset + r2t->data_length > scsi_out(task->
sc)->length) {
583 "invalid R2T with data len %u at offset %u "
584 "and total length %d\n", r2t->data_length,
585 r2t->data_offset, scsi_out(task->
sc)->length);
591 r2t->ttt = rhdr->
ttt;
614 if (!iscsi_tcp_dgst_verify(tcp_conn, segment))
641 int rc = 0,
opcode, ahslen;
649 "iscsi_tcp: datalen %d > %d\n",
666 opcode, ahslen, tcp_conn->
in.datalen);
670 spin_lock(&conn->
session->lock);
675 rc = iscsi_tcp_data_in(conn, task);
677 spin_unlock(&conn->
session->lock);
681 if (tcp_conn->
in.datalen) {
699 "offset=%d, datalen=%d)\n",
701 tcp_conn->
in.datalen);
707 tcp_conn->
in.datalen,
708 iscsi_tcp_process_data_in,
710 spin_unlock(&conn->
session->lock);
714 spin_unlock(&conn->
session->lock);
717 if (tcp_conn->
in.datalen) {
718 iscsi_tcp_data_recv_prep(tcp_conn);
724 spin_lock(&conn->
session->lock);
732 rc = iscsi_tcp_r2t_rsp(conn, task);
735 spin_unlock(&conn->
session->lock);
746 if (ISCSI_DEF_MAX_RECV_SEG_LEN < tcp_conn->
in.datalen) {
748 "iscsi_tcp: received buffer of "
749 "len %u but conn buffer is only %u "
751 tcp_conn->
in.datalen,
760 if (tcp_conn->
in.datalen) {
761 iscsi_tcp_data_recv_prep(tcp_conn);
778 if (tcp_conn->
in.datalen)
809 unsigned int ahslen = hdr->
hlength << 2;
812 if (
sizeof(*hdr) + ahslen >
sizeof(tcp_conn->
in.hdr_buf))
816 segment->
size += ahslen;
831 iscsi_tcp_segment_splice_digest(segment,
840 if (!iscsi_tcp_dgst_verify(tcp_conn, segment))
844 tcp_conn->
in.hdr =
hdr;
845 return iscsi_tcp_hdr_dissect(conn, hdr);
857 return tcp_conn->
in.segment.done == iscsi_tcp_hdr_recv_done;
876 struct skb_seq_state seq;
877 unsigned int consumed = 0;
916 rc = iscsi_tcp_segment_recv(tcp_conn, segment, ptr, avail);
929 rc = segment->
done(tcp_conn, segment);
988 if (iscsi_task_has_unsol_data(task))
991 spin_lock_bh(&session->
lock);
997 " done with r2t %p\n", r2t);
999 (
void *)&tcp_task->
r2t,
1007 (
void *)&tcp_task->
r2t,
sizeof(
void *)) !=
1011 r2t = tcp_task->
r2t;
1013 spin_unlock_bh(&session->
lock);
1036 rc = session->
tt->xmit_pdu(task);
1051 r2t = iscsi_tcp_get_curr_r2t(task);
1063 ISCSI_DBG_TCP(conn,
"sol dout %p [dsn %d itt 0x%x doff %d dlen %d]\n",
1089 sizeof(*tcp_conn) + dd_data_size, conn_idx);
1120 for (cmd_i = 0; cmd_i < session->
cmds_max; cmd_i++) {
1134 goto r2t_alloc_fail;
1141 goto r2t_alloc_fail;
1148 for (i = 0; i < cmd_i; i++) {
1163 for (i = 0; i < session->
cmds_max; i++) {
1176 unsigned short r2ts = 0;
1178 sscanf(buf,
"%hu", &r2ts);