cxgb4i submission - V2
Subsystems (3)
The following 3 patches add a new iscsi LLD driver cxgb4i to enable iscsi offload support on Chelsio's new 1G and 10G cards. This is updated version of previous cxgb4i patch. Please share you commnets after review.
Signature · 4 lines
You received this message because you are subscribed to the Google Groups "open-iscsi" group. To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To unsubscribe from this group, send email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
A message that is not in the archive (sent off-list or not yet received): 1272991388-8527-1-git-send-email-rakesh-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org
PATCH 1/3 cxgb4i: add build support
From: Rakesh Ranjan <[email protected]>
--- drivers/scsi/Kconfig | 1 + drivers/scsi/Makefile | 1 + drivers/scsi/cxgb4i/Kbuild | 4 ++++ drivers/scsi/cxgb4i/Kconfig | 7 +++++++ 4 files changed, 13 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/cxgb4i/Kbuild create mode 100644 drivers/scsi/cxgb4i/Kconfig
drivers/scsi/Kconfig +1 -0
@@ -371,6 +371,7 @@ config ISCSI_TCP http://open-iscsi.org source "drivers/scsi/cxgb3i/Kconfig" +source "drivers/scsi/cxgb4i/Kconfig" source "drivers/scsi/bnx2i/Kconfig" source "drivers/scsi/be2iscsi/Kconfig"
drivers/scsi/Makefile +1 -0
@@ -133,6 +133,7 @@ obj-$(CONFIG_SCSI_STEX) += stex.o obj-$(CONFIG_SCSI_MVSAS) += mvsas/ obj-$(CONFIG_PS3_ROM) += ps3rom.o obj-$(CONFIG_SCSI_CXGB3_ISCSI) += libiscsi.o libiscsi_tcp.o cxgb3i/ +obj-$(CONFIG_SCSI_CXGB4_ISCSI) += libiscsi.o libiscsi_tcp.o cxgb4i/ obj-$(CONFIG_SCSI_BNX2_ISCSI) += libiscsi.o bnx2i/ obj-$(CONFIG_BE2ISCSI) += libiscsi.o be2iscsi/ obj-$(CONFIG_SCSI_PMCRAID) += pmcraid.o
drivers/scsi/cxgb4i/Kbuild new file +4 -0
@@ -0,0 +1,4 @@ +EXTRA_CFLAGS += -I$(srctree)/drivers/net/cxgb4 + +cxgb4i-y := libcxgbi.o cxgb4i_snic.o cxgb4i_iscsi.o cxgb4i_offload.o cxgb4i_ddp.o +obj-$(CONFIG_SCSI_CXGB4_ISCSI) += cxgb4i.o
drivers/scsi/cxgb4i/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config SCSI_CXGB4_ISCSI + tristate "Chelsio T4 iSCSI support" + depends on CHELSIO_T4_DEPENDS + select CHELSIO_T4 + select SCSI_ISCSI_ATTRS + ---help--- + This driver supports iSCSI offload for the Chelsio T4 series devices.
Signature · 7 lines
1.6.6.1 -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To unsubscribe from this group, send email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
A message that is not in the archive (sent off-list or not yet received): 1272991388-8527-2-git-send-email-rakesh-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org
PATCH 2/3 cxgb4i: main driver files
From: Rakesh Ranjan <[email protected]>
--- drivers/scsi/cxgb4i/cxgb4i.h | 201 ++++ drivers/scsi/cxgb4i/cxgb4i_ddp.c | 696 +++++++++++++ drivers/scsi/cxgb4i/cxgb4i_ddp.h | 238 +++++ drivers/scsi/cxgb4i/cxgb4i_offload.c | 1853 ++++++++++++++++++++++++++++++++++ drivers/scsi/cxgb4i/cxgb4i_offload.h | 171 ++++ drivers/scsi/cxgb4i/cxgb4i_snic.c | 253 +++++ 6 files changed, 3412 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/cxgb4i/cxgb4i.h create mode 100644 drivers/scsi/cxgb4i/cxgb4i_ddp.c create mode 100644 drivers/scsi/cxgb4i/cxgb4i_ddp.h create mode 100644 drivers/scsi/cxgb4i/cxgb4i_offload.c create mode 100644 drivers/scsi/cxgb4i/cxgb4i_offload.h create mode 100644 drivers/scsi/cxgb4i/cxgb4i_snic.c
drivers/scsi/cxgb4i/cxgb4i.h new file +201 -0
@@ -0,0 +1,201 @@ +/* +* cxgb4i.h: Chelsio T4 iSCSI driver. +* +* Copyright (c) 2010 Chelsio Communications, Inc. +* +* 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. +* +* Written by: Karen Xie ([email protected]) +* Written by: Rakesh Ranjan ([email protected]) +*/ + +#ifndef __CXGB4I_H__ +#define __CXGB4I_H__ + +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/errno.h> +#include <linux/types.h> +#include <linux/list.h> +#include <linux/netdevice.h> +#include <linux/if_vlan.h> +#include <linux/scatterlist.h> +#include <linux/skbuff.h> +#include <scsi/libiscsi_tcp.h> + +#include "t4fw_api.h" +#include "t4_msg.h" +#include "l2t.h" +#include "cxgb4.h" +#include "cxgb4_uld.h" + +#include "cxgb4i_ddp.h" +#include "cxgb4i_offload.h" + +#define cxgb4i_log_error(fmt...) printk(KERN_ERR "cxgb4i: ERR! " fmt) +#define cxgb4i_log_warn(fmt...) printk(KERN_WARNING "cxgb4i: WARN! " fmt) +#define cxgb4i_log_info(fmt...) printk(KERN_INFO "cxgb4i: " fmt) +#define cxgb4i_debug_log(fmt, args...) \ + printk(KERN_INFO "cxgb4i: %s - " fmt, __func__ , ## args) + + +#ifdef __DEBUG_CXGB4I__ +#define cxgb4i_log_debug cxgb4i_debug_log +#else +#define cxgb4i_log_debug(fmt...) +#endif + +#ifdef __DEBUG_CXGB4I_TAG__ +#define cxgb4i_tag_debug cxgb4i_log_debug +#else +#define cxgb4i_tag_debug(fmt...) +#endif + +#ifdef __DEBUG_CXGB4I_API__ +#define cxgb4i_api_debug cxgb4i_log_debug +#else +#define cxgb4i_api_debug(fmt...) +#endif + +#ifdef __DEBUG_CXGB4I_CONN__ +#define cxgb4i_conn_debug cxgb4i_log_debug +#else +#define cxgb4i_conn_debug(fmt...) +#endif + +#ifdef __DEBUG_CXGB4I_TX__ +#define cxgb4i_tx_debug cxgb4i_log_debug +#else +#define cxgb4i_tx_debug(fmt...) +#endif + +#ifdef __DEBUG_CXGB4I_RX__ +#define cxgb4i_rx_debug cxgb4i_log_debug +#else +#define cxgb4i_rx_debug(fmt...) +#endif + +#define CXGB4I_SCSI_HOST_QDEPTH 1024 +#define CXGB4I_MAX_TARGET CXGB4I_MAX_CONN +#define CXGB4I_MAX_LUN 512 +#define ISCSI_PDU_NONPAYLOAD_MAX \ + (sizeof(struct iscsi_hdr) + ISCSI_MAX_AHS_SIZE + \ + (2 * ISCSI_DIGEST_SIZE)) + +struct cxgb4i_snic ; +struct cxgb4i_host ; +struct cxgb4i_endpoint ; +typedef int (*cxgb4i_cplhandler_func )(struct cxgb4i_snic *,struct sk_buff *); + + +struct cxgb4i_hba { +struct cxgb4i_snic *snic; +struct net_device *ndev; +struct Scsi_Host *shost; +struct port_info *pinfo; +__be32 ipv4addr; +}; + +struct cxgb4i_ports_map { +spinlock_t lock; +unsigned int next; +struct cxgb4i_sock *port_csk[0 ]; +}; + +struct cxgb4i_snic { +struct list_head list_head; +spinlock_t lock; + +struct cxgb4_lld_info lldi; + +struct cxgb4i_hba *hba[MAX_NPORTS ]; +unsigned char hba_cnt; + +unsigned int flags; +unsigned int tx_max_size; +unsigned int rx_max_size; + +struct cxgb4i_tag_format tag_format; +struct cxgb4i_ddp_info *ddp; + +struct cxgb4i_ports_map *pmap; +cxgb4i_cplhandler_func *funcs; +}; + +struct cxgb4i_conn { +struct list_head list_head; +struct cxgb4i_endpoint *cep; +struct iscsi_conn *iconn; +struct cxgb4i_hba *chba; +u32 task_idx_bits; +}; + +struct cxgb4i_endpoint { +struct cxgb4i_conn *cconn; +struct cxgb4i_hba *chba; +struct cxgb4i_sock *csk; +}; + +#define MAX_PDU_FRAGS ((ULP2_MAX_PDU_PAYLOAD + 512 - 1) / 512) +struct cxgb4i_task_data { +unsigned short nr_frags; +skb_frag_t frags[MAX_PDU_FRAGS ]; +struct sk_buff *skb; +unsigned int offset; +unsigned int count; +unsigned int sgoffset; +}; + +int cxgb4i_ofld_init (struct cxgb4i_snic *); +void cxgb4i_ofld_cleanup (struct cxgb4i_snic *); +struct cxgb4i_snic *cxgb4i_snic_init (const struct cxgb4_lld_info *); +void cxgb4i_snic_cleanup (void ); +struct cxgb4i_snic *cxgb4i_find_snic (struct net_device *,__be32 ); +struct cxgb4i_hba *cxgb4i_hba_find_by_netdev (struct net_device *); +struct cxgb4i_hba *cxgb4i_hba_add (struct cxgb4i_snic *,struct net_device *); +void cxgb4i_hba_remove (struct cxgb4i_hba *); +int cxgb4i_iscsi_init (void ); +void cxgb4i_iscsi_cleanup (void ); + +int cxgb4i_pdu_init (void ); +void cxgb4i_pdu_cleanup (void ); +int cxgb4i_conn_alloc_pdu (struct iscsi_task *,u8 ); +int cxgb4i_conn_init_pdu (struct iscsi_task *,unsigned int ,unsigned int ); +int cxgb4i_conn_xmit_pdu (struct iscsi_task *); +int cxgb4i_xmit_pdu_dummy (struct iscsi_task *task); + +int cxgb4i_reserve_itt (struct iscsi_task *task,itt_t *hdr_itt); +void cxgb4i_release_itt (struct iscsi_task *task,itt_t hdr_itt); + +int cxgb4i_sport_init (struct cxgb4i_snic *); + +static inline void *cplhdr (struct sk_buff *skb) +{ +return skb->data; +} + +static inline void cxgb4i_set_iscsi_ipv4 (struct cxgb4i_hba *chba,__be32 ipaddr) +{ + chba->ipv4addr = ipaddr; +} + +static inline __be32 cxgb4i_get_iscsi_ipv4 (struct cxgb4i_hba *chba) +{ +return chba->ipv4addr; +} + +#define W_TCB_ULP_TYPE 0 +#define TCB_ULP_TYPE_SHIFT 0 +#define TCB_ULP_TYPE_MASK 0xfULL +#define TCB_ULP_TYPE (x) ((x) << TCB_ULP_TYPE_SHIFT) + +#define W_TCB_ULP_RAW 0 +#define TCB_ULP_RAW_SHIFT 4 +#define TCB_ULP_RAW_MASK 0xffULL +#define TCB_ULP_RAW (x) ((x) << TCB_ULP_RAW_SHIFT) + + +#endif /* __CXGB4I_H__ */ +
drivers/scsi/cxgb4i/cxgb4i_ddp.c new file +696 -0
696 lines not on this page · raw message
drivers/scsi/cxgb4i/cxgb4i_ddp.h new file +238 -0
238 lines not on this page · raw message
drivers/scsi/cxgb4i/cxgb4i_offload.c new file +1853 -0
1,853 lines not on this page · raw message
drivers/scsi/cxgb4i/cxgb4i_offload.h new file +171 -0
12 lines not on this page · raw message
drivers/scsi/cxgb4i/cxgb4i_snic.c new file +253 -0
253 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 7 lines
1.6.6.1 -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To unsubscribe from this group, send email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
Part of the diff is not shown here. View the raw message.
A message that is not in the archive (sent off-list or not yet received): 1272991388-8527-3-git-send-email-rakesh-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org
PATCH 3/3 cxgb4i: iscsi and common pdu processing library
From: Rakesh Ranjan <[email protected]>
--- drivers/scsi/cxgb4i/cxgb4i_iscsi.c | 715 ++++++++++++++++++++++++++++++++++++ drivers/scsi/cxgb4i/libcxgbi.c | 464 +++++++++++++++++++++++ drivers/scsi/cxgb4i/libcxgbi.h | 61 +++ 3 files changed, 1240 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/cxgb4i/cxgb4i_iscsi.c create mode 100644 drivers/scsi/cxgb4i/libcxgbi.c create mode 100644 drivers/scsi/cxgb4i/libcxgbi.h
drivers/scsi/cxgb4i/cxgb4i_iscsi.c new file +715 -0
@@ -0,0 +1,715 @@ +/* +* cxgb4i_iscsi.c: Chelsio T4 iSCSI driver. +* +* Copyright (c) 2010 Chelsio Communications, Inc. +* +* 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. +* +* Written by: Karen Xie ([email protected]) +* Written by: Rakesh Ranjan ([email protected]) +*/ + +#include <linux/inet.h> +#include <linux/crypto.h> +#include <linux/if_vlan.h> +#include <net/dst.h> +#include <net/tcp.h> +#include <scsi/scsi_cmnd.h> +#include <scsi/scsi_device.h> +#include <scsi/scsi_eh.h> +#include <scsi/scsi_host.h> +#include <scsi/scsi.h> +#include <scsi/iscsi_proto.h> +#include <scsi/libiscsi.h> +#include <scsi/scsi_transport_iscsi.h> + +#include "cxgb4i.h" + +/* +* align pdu size to multiple of 512 for better performance +*/ +#define cxgb4i_align_pdu_size (n) do { n = (n) & (~511); } while (0) + +static struct scsi_transport_template *cxgb4i_scsi_transport; +static struct scsi_host_template cxgb4i_host_template; +static struct iscsi_transport cxgb4i_iscsi_transport; + +struct cxgb4i_hba *cxgb4i_hba_add (struct cxgb4i_snic *snic, +struct net_device *dev) +{ +struct cxgb4i_hba *chba; +struct Scsi_Host *shost; +int err; + + shost =iscsi_host_alloc (&cxgb4i_host_template,sizeof (*chba),1 ); + +if (!shost) { +cxgb4i_log_info ("snic 0x%p, ndev 0x%p, host alloc failed\n" , + snic, dev); +return NULL ; + } + + shost->transportt = cxgb4i_scsi_transport; + shost->max_lun =CXGB4I_MAX_LUN ; + shost->max_id =CXGB4I_MAX_TARGET ; + shost->max_channel =0 ; + shost->max_cmd_len =16 ; + + chba =iscsi_host_priv (shost); + chba->snic = snic; + chba->ndev = dev; + chba->shost = shost; + +pci_dev_get (snic->lldi.pdev); + err =iscsi_host_add (shost, &snic->lldi.pdev->dev); +if (err) { +cxgb4i_log_info ("snic 0x%p, dev 0x%p, host add failed\n" , + snic, dev); + goto pci_dev_put; + } + +return chba; + +pci_dev_put: +pci_dev_put (snic->lldi.pdev); +scsi_host_put (shost); +return NULL ; +} + +void cxgb4i_hba_remove (struct cxgb4i_hba *chba) +{ +iscsi_host_remove (chba->shost); +pci_dev_put (chba->snic->lldi.pdev); +iscsi_host_free (chba->shost); +} + +static struct iscsi_endpoint *cxgb4i_ep_connect (struct Scsi_Host *shost, +struct sockaddr *dst_addr, +int non_blocking) +{ +struct iscsi_endpoint *iep; +struct cxgb4i_endpoint *cep; +struct cxgb4i_hba *hba =NULL ; +struct cxgb4i_sock *csk =NULL ; +struct cxgb4i_snic *snic; +int err =0 ; + +if (shost) + hba =iscsi_host_priv (shost); + + snic =cxgb4i_find_snic (hba ? hba->ndev :NULL , + ((struct sockaddr_in *)dst_addr)->sin_addr.s_addr); +if (!snic) { +cxgb4i_log_info ("ep connect no snic\n" ); + err = -ENOSPC ; + goto release_conn; + } + + csk =cxgb4i_sock_create (snic); +if (!csk) { +cxgb4i_log_info ("ep connect OOM\n" ); + err = -ENOMEM ; + goto release_conn; + } + err =cxgb4i_sock_connect (hba ? hba->ndev :NULL , csk, + (struct sockaddr_in *)dst_addr); +if (err <0 ) { +cxgb4i_log_info ("ep connect failed\n" ); + goto release_conn; + } + + hba =cxgb4i_hba_find_by_netdev (csk->dst->dev); +if (!hba) { + err = -ENOSPC ; +cxgb4i_log_info ("Not going through cxgb4i device\n" ); + goto release_conn; + } + +if (shost && hba !=iscsi_host_priv (shost)) { + err = -ENOSPC ; +cxgb4i_log_info ("Could not connect through request host %u\n" , + shost->host_no); + goto release_conn; + } + +if (cxgb4i_sock_is_closing (csk)) { + err = -ENOSPC ; +cxgb4i_log_info ("ep connect unable to connect\n" ); + goto release_conn; + } + + iep =iscsi_create_endpoint (sizeof (*cep)); +if (!iep) { + err = -ENOMEM ; +cxgb4i_log_info ("iscsi alloc ep, OOM\n" ); + goto release_conn; + } + + cep = iep->dd_data; + cep->csk = csk; + cep->chba = hba; + +cxgb4i_api_debug ("iep 0x%p, cep 0x%p, csk 0x%p, hba 0x%p\n" , + iep, cep, csk, hba); + +return iep; + +release_conn: +cxgb4i_api_debug ("conn 0x%p failed, release\n" , csk); +if (csk) +cxgb4i_sock_release (csk); + +return ERR_PTR (err); +} + +static int cxgb4i_ep_poll (struct iscsi_endpoint *ep,int timeout_ms) +{ +struct cxgb4i_endpoint *cep = ep->dd_data; +struct cxgb4i_sock *csk = cep->csk; + +if (!cxgb4i_sock_is_established (csk)) +return 0 ; + +return 1 ; +} + +static void cxgb4i_ep_disconnect (struct iscsi_endpoint *ep) +{ +struct cxgb4i_endpoint *cep = ep->dd_data; +struct cxgb4i_conn *cconn = cep->cconn; + +if (cconn && cconn->iconn) { +iscsi_suspend_tx (cconn->iconn); + +write_lock_bh (&cep->csk->callback_lock); + cep->csk->user_data =NULL ; + cconn->cep =NULL ; +write_unlock_bh (&cep->csk->callback_lock); + } + +cxgb4i_sock_release (cep->csk); +iscsi_destroy_endpoint (ep); +} + +static struct iscsi_cls_session * +cxgb4i_create_session (struct iscsi_endpoint *ep,u16 cmds_max,u16 qdepth, +u32 initial_cmdsn) +{ +struct cxgb4i_endpoint *cep; +struct cxgb4i_hba *chba; +struct Scsi_Host *shost; +struct iscsi_cls_session *cls_session; +struct iscsi_session *session; + +if (!ep) { +cxgb4i_log_error ("missing endpoint\n" ); +return NULL ; + } + + cep = ep->dd_data; + chba = cep->chba; + shost = chba->shost; + +BUG_ON (chba !=iscsi_host_priv (shost)); + + cls_session =iscsi_session_setup (&cxgb4i_iscsi_transport, shost, + cmds_max,0 , +sizeof (struct iscsi_tcp_task ) + +sizeof (struct cxgb4i_task_data ), + initial_cmdsn,ISCSI_MAX_TARGET ); +if (!cls_session) +return NULL ; + + session = cls_session->dd_data; +if (iscsi_tcp_r2tpool_alloc (session)) + goto remove_session; + +return cls_session; + +remove_session: +iscsi_session_teardown (cls_session); +return NULL ; +} + +static void cxgb4i_destroy_session (struct iscsi_cls_session *cls_session) +{ +iscsi_tcp_r2tpool_free (cls_session->dd_data); +iscsi_session_teardown (cls_session); +} + +static inline int cxgb4i_conn_max_xmit_dlength (struct iscsi_conn *conn) +{ +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +struct cxgb4i_conn *cconn = tcp_conn->dd_data; +unsigned int max =max (512 *MAX_SKB_FRAGS ,SKB_TX_HEADROOM ); + + max =min (cconn->chba->snic->tx_max_size, max); +if (conn->max_xmit_dlength) + conn->max_xmit_dlength =min (conn->max_xmit_dlength, max); +else + conn->max_xmit_dlength = max; +cxgb4i_align_pdu_size (conn->max_xmit_dlength); +return 0 ; +} + +static inline int cxgb4i_conn_max_recv_dlength (struct iscsi_conn *conn) +{ +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +struct cxgb4i_conn *cconn = tcp_conn->dd_data; +unsigned int max = cconn->chba->snic->rx_max_size; + +cxgb4i_align_pdu_size (max); + +if (conn->max_recv_dlength) { +if (conn->max_recv_dlength > max) { +cxgb4i_log_error ("MaxRecvDataSegmentLength %u too big." +" Need to be <= %u.\n" , + conn->max_recv_dlength, max); +return -EINVAL ; + } + conn->max_recv_dlength =min (conn->max_recv_dlength, max); +cxgb4i_align_pdu_size (conn->max_recv_dlength); + }else + conn->max_recv_dlength = max; + +return 0 ; +} + +static struct iscsi_cls_conn * +cxgb4i_create_conn (struct iscsi_cls_session *cls_session,u32 cid) +{ +struct iscsi_cls_conn *cls_conn; +struct iscsi_conn *conn; +struct iscsi_tcp_conn *tcp_conn; +struct cxgb4i_conn *cconn; + + cls_conn =iscsi_tcp_conn_setup (cls_session,sizeof (*cconn), cid); +if (!cls_conn) +return NULL ; + + conn = cls_conn->dd_data; + tcp_conn = conn->dd_data; + cconn = tcp_conn->dd_data; + + cconn->iconn = conn; +return cls_conn; +} + +static int cxgb4i_bind_conn (struct iscsi_cls_session *cls_session, +struct iscsi_cls_conn *cls_conn, +u64 transport_eph,int is_leading) +{ +struct iscsi_conn *conn = cls_conn->dd_data; +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +struct cxgb4i_conn *cconn = tcp_conn->dd_data; +struct cxgb4i_snic *snic; +struct iscsi_endpoint *ep; +struct cxgb4i_endpoint *cep; +struct cxgb4i_sock *csk; +int err; + + ep =iscsi_lookup_endpoint (transport_eph); +if (!ep) +return -EINVAL ; + +/* setup ddp pagesize */ + cep = ep->dd_data; + csk = cep->csk; + snic = cep->chba->snic; + err =cxgb4i_ddp_setup_conn_host_pagesize (csk, csk->hwtid,0 ); +if (err <0 ) +return err; + + err =iscsi_conn_bind (cls_session, cls_conn, is_leading); +if (err) +return -EINVAL ; + +/* calculate the tag idx bits needed for this conn based on cmds_max */ + cconn->task_idx_bits = (__ilog2_u32 (conn->session->cmds_max -1 )) +1 ; + +read_lock (&csk->callback_lock); + csk->user_data = conn; + cconn->chba = cep->chba; + cconn->cep = cep; + cep->cconn = cconn; +read_unlock (&csk->callback_lock); + +cxgb4i_conn_max_xmit_dlength (conn); +cxgb4i_conn_max_recv_dlength (conn); + +spin_lock_bh (&conn->session->lock); +sprintf (conn->portal_address,"%pI4" , &csk->daddr.sin_addr.s_addr); + conn->portal_port =ntohs (csk->daddr.sin_port); +spin_unlock_bh (&conn->session->lock); + +/* init recv engine */ +iscsi_tcp_hdr_recv_prep (tcp_conn); + +return 0 ; +} + +static int +cxgb4i_get_conn_param (struct iscsi_cls_conn *cls_conn, +enum iscsi_param param,char *buff) +{ +struct iscsi_conn *iconn = cls_conn->dd_data; +int len; + +switch (param) { +case ISCSI_PARAM_CONN_PORT : +spin_lock_bh (&iconn->session->lock); + len =sprintf (buff,"%hu\n" , iconn->portal_port); +spin_unlock_bh (&iconn->session->lock); +break ; +case ISCSI_PARAM_CONN_ADDRESS : +spin_lock_bh (&iconn->session->lock); + len =sprintf (buff,"%s\n" , iconn->portal_address); +spin_unlock_bh (&iconn->session->lock); +break ; +default : +return iscsi_conn_get_param (cls_conn, param, buff); + } +return len; +} + +static int +cxgb4i_set_conn_param (struct iscsi_cls_conn *cls_conn, +enum iscsi_param param,char *buf,int buflen) +{ +struct iscsi_conn *conn = cls_conn->dd_data; +struct iscsi_session *session = conn->session; +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +struct cxgb4i_conn *cconn = tcp_conn->dd_data; +struct cxgb4i_sock *csk = cconn->cep->csk; +int value, err =0 ; + +switch (param) { +case ISCSI_PARAM_HDRDGST_EN : + err =iscsi_set_param (cls_conn, param, buf, buflen); +if (!err && conn->hdrdgst_en) + err =cxgb4i_ddp_setup_conn_digest (csk, csk->hwtid, + conn->hdrdgst_en, + conn->datadgst_en,0 ); +break ; +case ISCSI_PARAM_DATADGST_EN : + err =iscsi_set_param (cls_conn, param, buf, buflen); +if (!err && conn->datadgst_en) + err =cxgb4i_ddp_setup_conn_digest (csk, csk->hwtid, + conn->hdrdgst_en, + conn->datadgst_en,0 ); +break ; +case ISCSI_PARAM_MAX_R2T : +sscanf (buf,"%d" , &value); +if (value <=0 || !is_power_of_2 (value)) +return -EINVAL ; +if (session->max_r2t == value) +break ; +iscsi_tcp_r2tpool_free (session); + err =iscsi_set_param (cls_conn, param, buf, buflen); +if (!err &&iscsi_tcp_r2tpool_alloc (session)) +return -ENOMEM ; +case ISCSI_PARAM_MAX_RECV_DLENGTH : + err =iscsi_set_param (cls_conn, param, buf, buflen); +if (!err) + err =cxgb4i_conn_max_recv_dlength (conn); +break ; +case ISCSI_PARAM_MAX_XMIT_DLENGTH : + err =iscsi_set_param (cls_conn, param, buf, buflen); +if (!err) + err =cxgb4i_conn_max_xmit_dlength (conn); +break ; +default : +return iscsi_set_param (cls_conn, param, buf, buflen); + } +return err; +} + +static int +cxgb4i_set_host_param (struct Scsi_Host *shost, +enum iscsi_host_param param,char *buff,int buflen) +{ +struct cxgb4i_hba *chba =iscsi_host_priv (shost); + +if (!chba->ndev) { +shost_printk (KERN_ERR , shost,"Could not set host param. " +"Netdev for host not set\n" ); +return -ENODEV ; + } + +cxgb4i_api_debug ("param %d, buff %s\n" , param, buff); + +switch (param) { +case ISCSI_HOST_PARAM_IPADDRESS : + { +__be32 addr =in_aton (buff); +cxgb4i_set_iscsi_ipv4 (chba, addr); +return 0 ; + } + +case ISCSI_HOST_PARAM_HWADDRESS : +case ISCSI_HOST_PARAM_NETDEV_NAME : +return 0 ; + +default : +return iscsi_host_set_param (shost, param, buff, buflen); + } +} + +static int +cxgb4i_get_host_param (struct Scsi_Host *shost, +enum iscsi_host_param param,char *buff) +{ +struct cxgb4i_hba *chba =iscsi_host_priv (shost); +int len =0 ; + +if (!chba->ndev) { +shost_printk (KERN_ERR , shost,"Could not set host param. " +"Netdev for host not set\n" ); +return -ENODEV ; + } + +cxgb4i_api_debug ("hba %s, param %d\n" , chba->ndev->name, param); + +switch (param) { +case ISCSI_HOST_PARAM_HWADDRESS : + len =sysfs_format_mac (buff, chba->ndev->dev_addr,6 ); +break ; +case ISCSI_HOST_PARAM_NETDEV_NAME : + len =sprintf (buff,"%s\n" , chba->ndev->name); +break ; +case ISCSI_HOST_PARAM_IPADDRESS : + { +__be32 addr; + + addr =cxgb4i_get_iscsi_ipv4 (chba); + len =sprintf (buff,"%pI4" , &addr); +break ; + } +default : +return iscsi_host_get_param (shost, param, buff); + } + +return len; +} + +static void cxgb4i_get_conn_stats (struct iscsi_cls_conn *cls_conn, +struct iscsi_stats *stats) +{ +struct iscsi_conn *conn = cls_conn->dd_data; + + stats->txdata_octets = conn->txdata_octets; + stats->rxdata_octets = conn->rxdata_octets; + stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; + stats->dataout_pdus = conn->dataout_pdus_cnt; + stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; + stats->datain_pdus = conn->datain_pdus_cnt; + stats->r2t_pdus = conn->r2t_pdus_cnt; + stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; + stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; + stats->digest_err =0 ; + stats->timeout_err =0 ; + stats->custom_length =1 ; +strcpy (stats->custom[0 ].desc,"eh_abort_cnt" ); + stats->custom[0 ].value = conn->eh_abort_cnt; +} + +static void cxgb4i_parse_pdu_itt (struct iscsi_conn *conn,itt_t itt, +int *idx,int *age) +{ +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +struct cxgb4i_conn *cconn = tcp_conn->dd_data; +struct cxgb4i_snic *snic = cconn->chba->snic; +u32 tag =ntohl ((__force u32 ) itt); +u32 sw_bits; + + sw_bits =cxgb4i_tag_nonrsvd_bits (&snic->tag_format, tag); +if (idx) + *idx = sw_bits & ((1 << cconn->task_idx_bits) -1 ); +if (age) + *age = (sw_bits >> cconn->task_idx_bits) &ISCSI_AGE_MASK ; + +cxgb4i_tag_debug ("parse tag 0x%x/0x%x, sw 0x%x, itt 0x%x, age 0x%x.\n" , + tag, itt, sw_bits, idx ? *idx :0xFFFFF , + age ? *age :0xFF ); +} + +int cxgb4i_reserve_itt (struct iscsi_task *task,itt_t *hdr_itt) +{ +struct scsi_cmnd *sc = task->sc; +struct iscsi_conn *conn = task->conn; +struct iscsi_session *sess = conn->session; +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +struct cxgb4i_conn *cconn = tcp_conn->dd_data; +struct cxgb4i_snic *snic = cconn->chba->snic; +struct cxgb4i_tag_format *tformat = &snic->tag_format; +u32 sw_tag = (sess->age << cconn->task_idx_bits) | task->itt; +u32 tag; +int err = -EINVAL ; + +if (sc && + (scsi_bidi_cmnd (sc) || + sc->sc_data_direction ==DMA_FROM_DEVICE ) && +cxgb4i_sw_tag_usable (tformat, sw_tag)) { + +struct cxgb4i_sock *csk = cconn->cep->csk; +struct cxgb4i_gather_list *gl; + + gl =cxgb4i_ddp_make_gl (scsi_in (sc)->length, +scsi_in (sc)->table.sgl, +scsi_in (sc)->table.nents, + snic->lldi.pdev, +GFP_ATOMIC ); +if (gl) { + tag = sw_tag; + err =cxgb4i_ddp_tag_reserve (snic, csk->hwtid, + tformat, &tag, + gl,GFP_ATOMIC ); +if (err <0 ) +cxgb4i_ddp_release_gl (gl, snic->lldi.pdev); + } + } +if (err <0 ) + tag =cxgb4i_set_non_ddp_tag (tformat, sw_tag); +/* the itt need to sent in big-endian order */ + *hdr_itt = (__force itt_t )htonl (tag); + +cxgb4i_tag_debug ("new sc 0x%p tag 0x%x/0x%x (itt 0x%x, age 0x%x).\n" , + sc, tag, *hdr_itt, task->itt, sess->age); +return 0 ; +} + +void cxgb4i_release_itt (struct iscsi_task *task,itt_t hdr_itt) +{ +struct scsi_cmnd *sc = task->sc; +struct iscsi_tcp_conn *tcp_conn = task->conn->dd_data; +struct cxgb4i_conn *cconn = tcp_conn->dd_data; +struct cxgb4i_snic *snic = cconn->chba->snic; +struct cxgb4i_tag_format *tformat = &snic->tag_format; +u32 tag =ntohl ((__force u32 )hdr_itt); + +cxgb4i_tag_debug ("release tag 0x%x.\n" , tag); + +if (sc && + (scsi_bidi_cmnd (sc) || + sc->sc_data_direction ==DMA_FROM_DEVICE ) && +cxgb4i_is_ddp_tag (tformat, tag)) +cxgb4i_ddp_tag_release (snic, tag); +} + +void cxgb4i_cleanup_task (struct iscsi_task *task) +{ +struct cxgb4i_task_data *tdata = task->dd_data + +sizeof (struct iscsi_tcp_task ); + +/* never reached the xmit task callout */ +if (tdata->skb) +__kfree_skb (tdata->skb); +memset (tdata,0 ,sizeof (*tdata)); + +cxgb4i_release_itt (task, task->hdr_itt); +iscsi_tcp_cleanup_task (task); +} + +static struct scsi_host_template cxgb4i_host_template = { + .module =THIS_MODULE , + .name ="Chelsio T4 iSCSI initiator" , + .proc_name ="cxgb4i" , + .queuecommand = iscsi_queuecommand, + .change_queue_depth = iscsi_change_queue_depth, + .can_queue =CXGB4I_SCSI_HOST_QDEPTH , + .sg_tablesize =SG_ALL , + .max_sectors =0xFFFF , + .cmd_per_lun =ISCSI_DEF_CMD_PER_LUN , + .eh_abort_handler = iscsi_eh_abort, + .eh_device_reset_handler = iscsi_eh_device_reset, + .eh_target_reset_handler = iscsi_eh_recover_target, + .target_alloc = iscsi_target_alloc, + .use_clustering =DISABLE_CLUSTERING , + .this_id =-1 , +}; + +#define CXGB4I_CAPS (CAP_RECOVERY_L0 | CAP_MULTI_R2T | \ + CAP_HDRDGST | CAP_DATADGST | \ + CAP_DIGEST_OFFLOAD | CAP_PADDING_OFFLOAD) +#define CXGB4I_PMASK (ISCSI_MAX_RECV_DLENGTH | ISCSI_MAX_XMIT_DLENGTH | \ + ISCSI_HDRDGST_EN | ISCSI_DATADGST_EN | \ + ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T | \ + ISCSI_IMM_DATA_EN | ISCSI_FIRST_BURST | \ + ISCSI_MAX_BURST | ISCSI_PDU_INORDER_EN | \ + ISCSI_DATASEQ_INORDER_EN | ISCSI_ERL | \ + ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS | \ + ISCSI_EXP_STATSN | ISCSI_PERSISTENT_PORT | \ + ISCSI_PERSISTENT_ADDRESS | ISCSI_TARGET_NAME | \ + ISCSI_TPGT | ISCSI_USERNAME | \ + ISCSI_PASSWORD | ISCSI_USERNAME_IN | \ + ISCSI_PASSWORD_IN | ISCSI_FAST_ABORT | \ + ISCSI_ABORT_TMO | ISCSI_LU_RESET_TMO | \ + /*ISCSI_TGT_RESET_TMO |*/ ISCSI_PING_TMO | \ + ISCSI_RECV_TMO | ISCSI_IFACE_NAME | \ + ISCSI_INITIATOR_NAME) +#define CXGB4I_HPMASK (ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | \ + ISCSI_HOST_INITIATOR_NAME | ISCSI_HOST_INITIATOR_NAME) + +static struct iscsi_transport cxgb4i_iscsi_transport = { + .owner =THIS_MODULE , + .name ="cxgb4i" , + .caps =CXGB4I_CAPS , + .param_mask =CXGB4I_PMASK , + .host_param_mask =CXGB4I_HPMASK , + .get_host_param = cxgb4i_get_host_param, + .set_host_param = cxgb4i_set_host_param, + + .create_session = cxgb4i_create_session, + .destroy_session = cxgb4i_destroy_session, + .get_session_param = iscsi_session_get_param, + + .create_conn = cxgb4i_create_conn, + .bind_conn = cxgb4i_bind_conn, + .destroy_conn = iscsi_tcp_conn_teardown, + .start_conn = iscsi_conn_start, + .stop_conn = iscsi_conn_stop, + .get_conn_param = cxgb4i_get_conn_param, + .set_param = cxgb4i_set_conn_param, + .get_stats = cxgb4i_get_conn_stats, + + .send_pdu = iscsi_conn_send_pdu, + + .init_task = iscsi_tcp_task_init, + .xmit_task = iscsi_tcp_task_xmit, + .cleanup_task = cxgb4i_cleanup_task, + + .alloc_pdu = cxgb4i_conn_alloc_pdu, + .init_pdu = cxgb4i_conn_init_pdu, + .xmit_pdu = cxgb4i_conn_xmit_pdu, + .parse_pdu_itt = cxgb4i_parse_pdu_itt, + + .ep_connect = cxgb4i_ep_connect, + .ep_poll = cxgb4i_ep_poll, + .ep_disconnect = cxgb4i_ep_disconnect, + + .session_recovery_timedout = iscsi_session_recovery_timedout, +}; + +int cxgb4i_iscsi_init (void ) +{ + cxgb4i_scsi_transport =iscsi_register_transport ( + &cxgb4i_iscsi_transport); +if (!cxgb4i_scsi_transport) { +cxgb4i_log_error ("Could not register cxgb4i transport\n" ); +return -ENODATA ; + } + +return 0 ; +} + +void cxgb4i_iscsi_cleanup (void ) +{ +if (cxgb4i_scsi_transport) { +cxgb4i_api_debug ("cxgb4i transport 0x%p removed\n" , + cxgb4i_scsi_transport); +iscsi_unregister_transport (&cxgb4i_iscsi_transport); + } +} +
drivers/scsi/cxgb4i/libcxgbi.c new file +464 -0
464 lines not on this page · raw message
drivers/scsi/cxgb4i/libcxgbi.h new file +61 -0
61 lines not on this page · raw message
Signature · 7 lines
1.6.6.1 -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To unsubscribe from this group, send email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.