Newer
Older
/*
* iSCSI Initiator over TCP/IP Data-Path
*
* Copyright (C) 2004 Dmitry Yusupov
* Copyright (C) 2004 Alex Aizman
* Copyright (C) 2005 - 2006 Mike Christie
* Copyright (C) 2006 Red Hat, Inc. All rights reserved.
* maintained by open-iscsi@googlegroups.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See the file COPYING included with this distribution for more details.
*
* Credits:
* Christoph Hellwig
* FUJITA Tomonori
* Arne Redlich
* Zhenyu Wang
*/
#include <linux/types.h>
#include <linux/list.h>
#include <linux/inet.h>
#include <linux/blkdev.h>
#include <linux/crypto.h>
#include <linux/delay.h>
#include <linux/kfifo.h>
#include <linux/scatterlist.h>
#include <net/tcp.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi.h>
#include <scsi/scsi_transport_iscsi.h>
#include "iscsi_tcp.h"
MODULE_AUTHOR("Dmitry Yusupov <dmitry_yus@yahoo.com>, "
"Alex Aizman <itn780@yahoo.com>");
MODULE_DESCRIPTION("iSCSI/TCP data-path");
MODULE_LICENSE("GPL");
#define DEBUG_ASSERT
#ifdef DEBUG_TCP
#define debug_tcp(fmt...) printk(KERN_INFO "tcp: " fmt)
#else
#define debug_tcp(fmt...)
#endif
#ifndef DEBUG_ASSERT
#ifdef BUG_ON
#undef BUG_ON
#endif
#define BUG_ON(expr)
#endif
static struct scsi_transport_template *iscsi_tcp_scsi_transport;
static struct scsi_host_template iscsi_sht;
static struct iscsi_transport iscsi_tcp_transport;
static unsigned int iscsi_max_lun = 512;
module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
static int iscsi_tcp_hdr_recv_done(struct iscsi_tcp_conn *tcp_conn,
struct iscsi_segment *segment);
* Scatterlist handling: inside the iscsi_segment, we
* remember an index into the scatterlist, and set data/size
* to the current scatterlist entry. For highmem pages, we
* kmap as needed.
*
* Note that the page is unmapped when we return from
* TCP's data_ready handler, so we may end up mapping and
* unmapping the same page repeatedly. The whole reason
* for this is that we shouldn't keep the page mapped
* outside the softirq.
*/
/**
* iscsi_tcp_segment_init_sg - init indicated scatterlist entry
* @segment: the buffer object
* @sg: scatterlist
* @offset: byte offset into that sg entry
*
* This function sets up the segment so that subsequent
* data is copied to the indicated sg entry, at the given
* offset.
*/
static inline void
iscsi_tcp_segment_init_sg(struct iscsi_segment *segment,
struct scatterlist *sg, unsigned int offset)
segment->sg = sg;
segment->sg_offset = offset;
segment->size = min(sg->length - offset,
segment->total_size - segment->total_copied);
segment->data = NULL;
* iscsi_tcp_segment_map - map the current S/G page
* @segment: iscsi_segment
* @recv: 1 if called from recv path
*
* We only need to possibly kmap data if scatter lists are being used,
* because the iscsi passthrough and internal IO paths will never use high
* mem pages.
*/
static inline void
iscsi_tcp_segment_map(struct iscsi_segment *segment, int recv)
if (segment->data != NULL || !segment->sg)
sg = segment->sg;
BUG_ON(segment->sg_mapped);
/*
* If the page count is greater than one it is ok to send
* to the network layer's zero copy send path. If not we
* have to go the slow sendmsg path. We always map for the
* recv path.
*/
if (page_count(sg_page(sg)) >= 1 && !recv)
return;
debug_tcp("iscsi_tcp_segment_map %s %p\n", recv ? "recv" : "xmit",
segment);
segment->sg_mapped = kmap_atomic(sg_page(sg), KM_SOFTIRQ0);
segment->data = segment->sg_mapped + sg->offset + segment->sg_offset;
iscsi_tcp_segment_unmap(struct iscsi_segment *segment)
debug_tcp("iscsi_tcp_segment_unmap %p\n", segment);
if (segment->sg_mapped) {
debug_tcp("iscsi_tcp_segment_unmap valid\n");
kunmap_atomic(segment->sg_mapped, KM_SOFTIRQ0);
segment->sg_mapped = NULL;
segment->data = NULL;
}
}
/*
* Splice the digest buffer into the buffer
*/
static inline void
iscsi_tcp_segment_splice_digest(struct iscsi_segment *segment, void *digest)
segment->data = digest;
segment->digest_len = ISCSI_DIGEST_SIZE;
segment->total_size += ISCSI_DIGEST_SIZE;
segment->size = ISCSI_DIGEST_SIZE;
segment->copied = 0;
segment->sg = NULL;
segment->hash = NULL;
* iscsi_tcp_segment_done - check whether the segment is complete
* @segment: iscsi segment to check
* @recv: set to one of this is called from the recv path
* @copied: number of bytes copied
* Check if we're done receiving this segment. If the receive
* buffer is full but we expect more data, move on to the
* next entry in the scatterlist.
*
* If the amount of data we received isn't a multiple of 4,
* we will transparently receive the pad bytes, too.
*
* This function must be re-entrant.
*/
static inline int
iscsi_tcp_segment_done(struct iscsi_segment *segment, int recv, unsigned copied)
static unsigned char padbuf[ISCSI_PAD_LEN];
debug_tcp("copied %u %u size %u %s\n", segment->copied, copied,
segment->size, recv ? "recv" : "xmit");
if (segment->hash && copied) {
/*
Loading
Loading full blame...