/*
* iSCSI over TCP/IP Data-Path lib
*
* 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 <crypto/hash.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/inet.h>
#include <linux/slab.h>
#include <linux/file.h>
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <linux/kfifo.h>
#include <linux/scatterlist.h>
#include <linux/module.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 <trace/events/iscsi.h>
#include "iscsi_tcp.h"
MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
"Dmitry Yusupov <dmitry_yus@yahoo.com>, "
"Alex Aizman <itn780@yahoo.com>");
MODULE_DESCRIPTION("iSCSI/TCP data-path");
MODULE_LICENSE("GPL");
static int iscsi_dbg_libtcp;
module_param_named(debug_libiscsi_tcp, iscsi_dbg_libtcp, int,
S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(debug_libiscsi_tcp, "Turn on debugging for libiscsi_tcp "
"module. Set to 1 to turn on, and zero to turn off. Default "
"is off.");
#define ISCSI_DBG_TCP(_conn, dbg_fmt, arg...) \
do { \
if (iscsi_dbg_libtcp) \
iscsi_conn_printk(KERN_INFO, _conn, \
"%s " dbg_fmt, \
__func__, ##arg); \
iscsi_dbg_trace(trace_iscsi_dbg_tcp, \
&(_conn)->cls_conn->dev, \
"%s " dbg_fmt, __func__, ##arg);\
} while (0);
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 void iscsi_tcp_segment_map(struct iscsi_segment *segment, int recv)
{
struct scatterlist *sg;
if (segment->data != NULL || !segment->sg)
return;
sg = segment->sg;
BUG_ON(segment->sg_mapped);
BUG_ON(sg->length == 0);
/*
* We always map for the recv path.
*
* 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.
*
* Same goes for slab pages: skb_can_coalesce() allows
* coalescing neighboring slab objects into a single frag which
* triggers one of hardened usercopy checks.
*/
if (!recv && page_count(sg_page(sg)) >= 1 && !PageSlab(sg_page(sg)))
return;
if (recv) {
segment->atomic_mapped = true;