Path: blob/master/drivers/infiniband/ulp/iser/iscsi_iser.h
15112 views
/*1* iSER transport for the Open iSCSI Initiator & iSER transport internals2*3* Copyright (C) 2004 Dmitry Yusupov4* Copyright (C) 2004 Alex Aizman5* Copyright (C) 2005 Mike Christie6* based on code maintained by [email protected]7*8* Copyright (c) 2004, 2005, 2006 Voltaire, Inc. All rights reserved.9* Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.10*11* This software is available to you under a choice of one of two12* licenses. You may choose to be licensed under the terms of the GNU13* General Public License (GPL) Version 2, available from the file14* COPYING in the main directory of this source tree, or the15* OpenIB.org BSD license below:16*17* Redistribution and use in source and binary forms, with or18* without modification, are permitted provided that the following19* conditions are met:20*21* - Redistributions of source code must retain the above22* copyright notice, this list of conditions and the following23* disclaimer.24*25* - Redistributions in binary form must reproduce the above26* copyright notice, this list of conditions and the following27* disclaimer in the documentation and/or other materials28* provided with the distribution.29*30* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,31* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF32* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND33* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS34* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN35* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN36* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE37* SOFTWARE.38*/39#ifndef __ISCSI_ISER_H__40#define __ISCSI_ISER_H__4142#include <linux/types.h>43#include <linux/net.h>44#include <scsi/libiscsi.h>45#include <scsi/scsi_transport_iscsi.h>4647#include <linux/wait.h>48#include <linux/sched.h>49#include <linux/list.h>50#include <linux/slab.h>51#include <linux/dma-mapping.h>52#include <linux/mutex.h>53#include <linux/mempool.h>54#include <linux/uio.h>5556#include <linux/socket.h>57#include <linux/in.h>58#include <linux/in6.h>5960#include <rdma/ib_verbs.h>61#include <rdma/ib_fmr_pool.h>62#include <rdma/rdma_cm.h>6364#define DRV_NAME "iser"65#define PFX DRV_NAME ": "66#define DRV_VER "0.1"67#define DRV_DATE "May 7th, 2006"6869#define iser_dbg(fmt, arg...) \70do { \71if (iser_debug_level > 1) \72printk(KERN_DEBUG PFX "%s:" fmt,\73__func__ , ## arg); \74} while (0)7576#define iser_warn(fmt, arg...) \77do { \78if (iser_debug_level > 0) \79printk(KERN_DEBUG PFX "%s:" fmt,\80__func__ , ## arg); \81} while (0)8283#define iser_err(fmt, arg...) \84do { \85printk(KERN_ERR PFX "%s:" fmt, \86__func__ , ## arg); \87} while (0)8889#define SHIFT_4K 1290#define SIZE_4K (1UL << SHIFT_4K)91#define MASK_4K (~(SIZE_4K-1))9293/* support up to 512KB in one RDMA */94#define ISCSI_ISER_SG_TABLESIZE (0x80000 >> SHIFT_4K)95#define ISER_DEF_CMD_PER_LUN 1289697/* QP settings */98/* Maximal bounds on received asynchronous PDUs */99#define ISER_MAX_RX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */100101#define ISER_MAX_TX_MISC_PDUS 6 /* NOOP_OUT(2), TEXT(1), *102* SCSI_TMFUNC(2), LOGOUT(1) */103104#define ISER_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX)105106#define ISER_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)107108/* the max TX (send) WR supported by the iSER QP is defined by *109* max_send_wr = T * (1 + D) + C ; D is how many inflight dataouts we expect *110* to have at max for SCSI command. The tx posting & completion handling code *111* supports -EAGAIN scheme where tx is suspended till the QP has room for more *112* send WR. D=8 comes from 64K/8K */113114#define ISER_INFLIGHT_DATAOUTS 8115116#define ISER_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX * \117(1 + ISER_INFLIGHT_DATAOUTS) + \118ISER_MAX_TX_MISC_PDUS + \119ISER_MAX_RX_MISC_PDUS)120121#define ISER_VER 0x10122#define ISER_WSV 0x08123#define ISER_RSV 0x04124125struct iser_hdr {126u8 flags;127u8 rsvd[3];128__be32 write_stag; /* write rkey */129__be64 write_va;130__be32 read_stag; /* read rkey */131__be64 read_va;132} __attribute__((packed));133134/* Constant PDU lengths calculations */135#define ISER_HEADERS_LEN (sizeof(struct iser_hdr) + sizeof(struct iscsi_hdr))136137#define ISER_RECV_DATA_SEG_LEN 128138#define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN)139#define ISER_RX_LOGIN_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)140141/* Length of an object name string */142#define ISER_OBJECT_NAME_SIZE 64143144enum iser_ib_conn_state {145ISER_CONN_INIT, /* descriptor allocd, no conn */146ISER_CONN_PENDING, /* in the process of being established */147ISER_CONN_UP, /* up and running */148ISER_CONN_TERMINATING, /* in the process of being terminated */149ISER_CONN_DOWN, /* shut down */150ISER_CONN_STATES_NUM151};152153enum iser_task_status {154ISER_TASK_STATUS_INIT = 0,155ISER_TASK_STATUS_STARTED,156ISER_TASK_STATUS_COMPLETED157};158159enum iser_data_dir {160ISER_DIR_IN = 0, /* to initiator */161ISER_DIR_OUT, /* from initiator */162ISER_DIRS_NUM163};164165struct iser_data_buf {166void *buf; /* pointer to the sg list */167unsigned int size; /* num entries of this sg */168unsigned long data_len; /* total data len */169unsigned int dma_nents; /* returned by dma_map_sg */170char *copy_buf; /* allocated copy buf for SGs unaligned *171* for rdma which are copied */172struct scatterlist sg_single; /* SG-ified clone of a non SG SC or *173* unaligned SG */174};175176/* fwd declarations */177struct iser_device;178struct iscsi_iser_conn;179struct iscsi_iser_task;180struct iscsi_endpoint;181182struct iser_mem_reg {183u32 lkey;184u32 rkey;185u64 va;186u64 len;187void *mem_h;188int is_fmr;189};190191struct iser_regd_buf {192struct iser_mem_reg reg; /* memory registration info */193void *virt_addr;194struct iser_device *device; /* device->device for dma_unmap */195enum dma_data_direction direction; /* direction for dma_unmap */196unsigned int data_size;197};198199enum iser_desc_type {200ISCSI_TX_CONTROL ,201ISCSI_TX_SCSI_COMMAND,202ISCSI_TX_DATAOUT203};204205struct iser_tx_desc {206struct iser_hdr iser_header;207struct iscsi_hdr iscsi_header;208enum iser_desc_type type;209u64 dma_addr;210/* sg[0] points to iser/iscsi headers, sg[1] optionally points to either211of immediate data, unsolicited data-out or control (login,text) */212struct ib_sge tx_sg[2];213int num_sge;214};215216#define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \217sizeof(u64) + sizeof(struct ib_sge)))218struct iser_rx_desc {219struct iser_hdr iser_header;220struct iscsi_hdr iscsi_header;221char data[ISER_RECV_DATA_SEG_LEN];222u64 dma_addr;223struct ib_sge rx_sg;224char pad[ISER_RX_PAD_SIZE];225} __attribute__((packed));226227struct iser_device {228struct ib_device *ib_device;229struct ib_pd *pd;230struct ib_cq *rx_cq;231struct ib_cq *tx_cq;232struct ib_mr *mr;233struct tasklet_struct cq_tasklet;234struct ib_event_handler event_handler;235struct list_head ig_list; /* entry in ig devices list */236int refcount;237};238239struct iser_conn {240struct iscsi_iser_conn *iser_conn; /* iser conn for upcalls */241struct iscsi_endpoint *ep;242enum iser_ib_conn_state state; /* rdma connection state */243atomic_t refcount;244spinlock_t lock; /* used for state changes */245struct iser_device *device; /* device context */246struct rdma_cm_id *cma_id; /* CMA ID */247struct ib_qp *qp; /* QP */248struct ib_fmr_pool *fmr_pool; /* pool of IB FMRs */249wait_queue_head_t wait; /* waitq for conn/disconn */250int post_recv_buf_count; /* posted rx count */251atomic_t post_send_buf_count; /* posted tx count */252char name[ISER_OBJECT_NAME_SIZE];253struct iser_page_vec *page_vec; /* represents SG to fmr maps*254* maps serialized as tx is*/255struct list_head conn_list; /* entry in ig conn list */256257char *login_buf;258u64 login_dma;259unsigned int rx_desc_head;260struct iser_rx_desc *rx_descs;261struct ib_recv_wr rx_wr[ISER_MIN_POSTED_RX];262};263264struct iscsi_iser_conn {265struct iscsi_conn *iscsi_conn;/* ptr to iscsi conn */266struct iser_conn *ib_conn; /* iSER IB conn */267};268269struct iscsi_iser_task {270struct iser_tx_desc desc;271struct iscsi_iser_conn *iser_conn;272enum iser_task_status status;273int command_sent; /* set if command sent */274int dir[ISER_DIRS_NUM]; /* set if dir use*/275struct iser_regd_buf rdma_regd[ISER_DIRS_NUM];/* regd rdma buf */276struct iser_data_buf data[ISER_DIRS_NUM]; /* orig. data des*/277struct iser_data_buf data_copy[ISER_DIRS_NUM];/* contig. copy */278int headers_initialized;279};280281struct iser_page_vec {282u64 *pages;283int length;284int offset;285int data_size;286};287288struct iser_global {289struct mutex device_list_mutex;/* */290struct list_head device_list; /* all iSER devices */291struct mutex connlist_mutex;292struct list_head connlist; /* all iSER IB connections */293294struct kmem_cache *desc_cache;295};296297extern struct iser_global ig;298extern int iser_debug_level;299300/* allocate connection resources needed for rdma functionality */301int iser_conn_set_full_featured_mode(struct iscsi_conn *conn);302303int iser_send_control(struct iscsi_conn *conn,304struct iscsi_task *task);305306int iser_send_command(struct iscsi_conn *conn,307struct iscsi_task *task);308309int iser_send_data_out(struct iscsi_conn *conn,310struct iscsi_task *task,311struct iscsi_data *hdr);312313void iscsi_iser_recv(struct iscsi_conn *conn,314struct iscsi_hdr *hdr,315char *rx_data,316int rx_data_len);317318void iser_conn_init(struct iser_conn *ib_conn);319320void iser_conn_get(struct iser_conn *ib_conn);321322int iser_conn_put(struct iser_conn *ib_conn, int destroy_cma_id_allowed);323324void iser_conn_terminate(struct iser_conn *ib_conn);325326void iser_rcv_completion(struct iser_rx_desc *desc,327unsigned long dto_xfer_len,328struct iser_conn *ib_conn);329330void iser_snd_completion(struct iser_tx_desc *desc, struct iser_conn *ib_conn);331332void iser_task_rdma_init(struct iscsi_iser_task *task);333334void iser_task_rdma_finalize(struct iscsi_iser_task *task);335336void iser_free_rx_descriptors(struct iser_conn *ib_conn);337338void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_task *task,339enum iser_data_dir cmd_dir);340341int iser_reg_rdma_mem(struct iscsi_iser_task *task,342enum iser_data_dir cmd_dir);343344int iser_connect(struct iser_conn *ib_conn,345struct sockaddr_in *src_addr,346struct sockaddr_in *dst_addr,347int non_blocking);348349int iser_reg_page_vec(struct iser_conn *ib_conn,350struct iser_page_vec *page_vec,351struct iser_mem_reg *mem_reg);352353void iser_unreg_mem(struct iser_mem_reg *mem_reg);354355int iser_post_recvl(struct iser_conn *ib_conn);356int iser_post_recvm(struct iser_conn *ib_conn, int count);357int iser_post_send(struct iser_conn *ib_conn, struct iser_tx_desc *tx_desc);358359int iser_dma_map_task_data(struct iscsi_iser_task *iser_task,360struct iser_data_buf *data,361enum iser_data_dir iser_dir,362enum dma_data_direction dma_dir);363364void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task);365int iser_initialize_task_headers(struct iscsi_task *task,366struct iser_tx_desc *tx_desc);367#endif368369370