cxgb3i - cxgb3i iscsi driver
Subsystems (3)
PATCH 4/4 cxgb3i - cxgb3i iscsi driver
[PATCH 4/4 2.6.28] cxgb3i - cxgb3i iscsi driver
From: Karen Xie <[email protected]>
cxgb3i iSCSI driver.
---
drivers/scsi/Kconfig | 2 drivers/scsi/Makefile | 1 drivers/scsi/cxgb3i/Kconfig | 6 drivers/scsi/cxgb3i/Makefile | 5 drivers/scsi/cxgb3i/cxgb3i.h | 155 +++ drivers/scsi/cxgb3i/cxgb3i_init.c | 109 ++ drivers/scsi/cxgb3i/cxgb3i_iscsi.c | 824 ++++++++++++++ drivers/scsi/cxgb3i/cxgb3i_offload.c | 1985 ++++++++++++++++++++++++++++++++++ drivers/scsi/cxgb3i/cxgb3i_offload.h | 252 ++++ drivers/scsi/cxgb3i/cxgb3i_ulp2.c | 692 ++++++++++++ drivers/scsi/cxgb3i/cxgb3i_ulp2.h | 106 ++ 11 files changed, 4137 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/cxgb3i/Kconfig create mode 100644 drivers/scsi/cxgb3i/Makefile create mode 100644 drivers/scsi/cxgb3i/cxgb3i.h create mode 100644 drivers/scsi/cxgb3i/cxgb3i_init.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_iscsi.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_offload.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_offload.h create mode 100644 drivers/scsi/cxgb3i/cxgb3i_ulp2.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_ulp2.h
drivers/scsi/Kconfig +2 -0
@@ -1779,6 +1779,8 @@ config ZFCP called zfcp. If you want to compile it as a module, say M here and read <file:Documentation/kbuild/modules.txt>. +source "drivers/scsi/cxgb3i/Kconfig" + config SCSI_SRP tristate "SCSI RDMA Protocol helper library" depends on SCSI && PCI
drivers/scsi/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_SCSI_SRP_ATTRS) += scsi_transport_srp.o obj-$(CONFIG_SCSI_DH) += device_handler/ obj-$(CONFIG_ISCSI_TCP) += libiscsi.o iscsi_tcp.o +obj-$(CONFIG_SCSI_CXGB3_ISCSI) += libiscsi.o cxgb3i/ obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o obj-$(CONFIG_SCSI_A4000T) += 53c700.o a4000t.o obj-$(CONFIG_SCSI_ZORRO7XX) += 53c700.o zorro7xx.o
drivers/scsi/cxgb3i/Kconfig new file +6 -0
@@ -0,0 +1,6 @@ +config SCSI_CXGB3_ISCSI + tristate "Chelsio S3xx iSCSI support" + select CHELSIO_T3 + select SCSI_ISCSI_ATTRS + ---help--- + This driver supports iSCSI offload for the Chelsio S3 series devices.
drivers/scsi/cxgb3i/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +EXTRA_CFLAGS += -I$(TOPDIR)/drivers/net/cxgb3 + +cxgb3i-y := cxgb3i_init.o cxgb3i_iscsi.o cxgb3i_ulp2.o cxgb3i_offload.o + +obj-$(CONFIG_SCSI_CXGB3_ISCSI) += cxgb3i.o
drivers/scsi/cxgb3i/cxgb3i.h new file +155 -0
155 lines not on this page · raw message
drivers/scsi/cxgb3i/cxgb3i_init.c new file +109 -0
109 lines not on this page · raw message
drivers/scsi/cxgb3i/cxgb3i_iscsi.c new file +824 -0
824 lines not on this page · raw message
drivers/scsi/cxgb3i/cxgb3i_offload.c new file +1985 -0
1,886 lines not on this page · raw message
drivers/scsi/cxgb3i/cxgb3i_offload.h new file +252 -0
252 lines not on this page · raw message
drivers/scsi/cxgb3i/cxgb3i_ulp2.c new file +692 -0
692 lines not on this page · raw message
drivers/scsi/cxgb3i/cxgb3i_ulp2.h new file +106 -0
106 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 7 lines · On Fri, 22 Aug 2008 11:40:56 -0700 Karen Xie <[email protected]> wrote:
[PATCH 4/4 2.6.28] cxgb3i - cxgb3i iscsi driver
From: Karen Xie <[email protected]>
cxgb3i iSCSI driver.
Signed-off-by Karen Xie <[email protected]>
I'm going to suggest that this not be merged in this form due to the __GFP_NOFAIL issues identified below.
Quoted 14 lines
drivers/scsi/Kconfig | 2 drivers/scsi/Makefile | 1 drivers/scsi/cxgb3i/Kconfig | 6 drivers/scsi/cxgb3i/Makefile | 5 drivers/scsi/cxgb3i/cxgb3i.h | 155 +++ drivers/scsi/cxgb3i/cxgb3i_init.c | 109 ++ drivers/scsi/cxgb3i/cxgb3i_iscsi.c | 824 ++++++++++++++ drivers/scsi/cxgb3i/cxgb3i_offload.c | 1985 ++++++++++++++++++++++++++++++++++ drivers/scsi/cxgb3i/cxgb3i_offload.h | 252 ++++ drivers/scsi/cxgb3i/cxgb3i_ulp2.c | 692 ++++++++++++ drivers/scsi/cxgb3i/cxgb3i_ulp2.h | 106 ++ 11 files changed, 4137 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/cxgb3i/Kconfig
Quoted 9 lines
create mode 100644 drivers/scsi/cxgb3i/Makefile create mode 100644 drivers/scsi/cxgb3i/cxgb3i.h create mode 100644 drivers/scsi/cxgb3i/cxgb3i_init.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_iscsi.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_offload.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_offload.h create mode 100644 drivers/scsi/cxgb3i/cxgb3i_ulp2.c create mode 100644 drivers/scsi/cxgb3i/cxgb3i_ulp2.h
Please use scripts/checkpatch.pl. It finds things which should be fixed.
Quoted 8 lines
...
drivers/scsi/cxgb3i/cxgb3i.h new file +5
-0+/** +* struct cxgb3i_tag_format - cxgb3i ulp tag for steering pdu payload +* +* @rsvd_bits: # of bits used by h/w +* @rsvd_shift: shift left
drivers/scsi/cxgb3i/cxgb3i.h line 54
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i.h new file +10
-0+* @rsvd_mask: bit mask +* +*/ +struct cxgb3i_tag_format { +unsigned char idx_bits; +unsigned char age_bits; +unsigned char rsvd_bits; +unsigned char rsvd_shift; +u32 rsvd_mask; +};
Only three of the five fields were documented.
Quoted 46 lines
drivers/scsi/cxgb3i/cxgb3i.h new file +46
-0+/** +* struct cxgb3i_ddp_info - cxgb3i direct data placement for pdu payload +* +* @llimit: lower bound of the page pod memory +* @ulimit: upper bound of the page pod memory +* @nppods: # of page pod entries +* @idx_last: page pod entry last used +* @map_lock: lock to synchonize access to the page pod map +* @map: page pod map +*/ +struct cxgb3i_ddp_info { +unsigned int llimit; +unsigned int ulimit; +unsigned int nppods; +unsigned int idx_last; +spinlock_t map_lock; +u8 *map; +}; + +struct cxgb3i_hba { +struct cxgb3i_adapter *snic; +struct net_device *ndev; +struct Scsi_Host *shost; + +rwlock_t cconn_rwlock; +struct list_head cconn_list; +}; + +struct cxgb3i_adapter { +struct list_head list_head; +spinlock_t lock; +struct t3cdev *tdev; +struct pci_dev *pdev; +unsigned char hba_cnt; +struct cxgb3i_hba *hba[MAX_NPORTS ]; + +unsigned int tx_max_size; +unsigned int rx_max_size; + +struct cxgb3i_tag_format tag_format; +struct cxgb3i_ddp_info ddp; +}; + +struct cxgb3i_conn { +struct list_head list_head; +
drivers/scsi/cxgb3i/cxgb3i.h line 111
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i.h new file +10
-0+struct cxgb3i_endpoint *cep; +struct iscsi_conn *conn; +struct cxgb3i_hba *hba; +}; + +struct cxgb3i_endpoint { +struct s3_conn *c3cn; +struct cxgb3i_hba *hba; +struct cxgb3i_conn *cconn; +};
We got bored of documenting, I see ;)
It's a shame, because documenting the data structures is very useful. More important than documenting code flow, for example.
Quoted 4 lines
...
drivers/scsi/cxgb3i/cxgb3i.h new file +1
-0+static inline void cxgb3i_parse_tag(struct cxgb3i_tag_format *format,
drivers/scsi/cxgb3i/cxgb3i.h line 149
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i.h new file +10
-0+ u32 tag, u32 *rsvd_bits, u32 *sw_bits) +{ + if (rsvd_bits) + *rsvd_bits = (tag >> format->rsvd_shift) & format->rsvd_mask; +if (sw_bits) { + *sw_bits = (tag >> (format->rsvd_shift + format->rsvd_bits)) + << format->rsvd_shift; + *sw_bits |= tag & ((1 << format->rsvd_shift) -1 ); + } +}
Far too large to inline, has only one call site. Can be made static non-inline in cxgb3i_iscsi.c.
Quoted 16 lines
drivers/scsi/cxgb3i/cxgb3i.h new file +5
-0+int cxgb3i_conn_ulp2_xmit (struct iscsi_conn *); + +void cxgb3i_display_byte_string (char *,unsigned char *,int ,int ); + +#endif drivers/scsi/cxgb3i/cxgb3i_init.c new file +5
-0@@ -0,0 +1,109 @@ +/* cxgb3i_init.c: Chelsio S3xx iSCSI driver. +* +* Copyright (c) 2008 Chelsio Communications, Inc. +* +* This program is free software; you can redistribute it and/or modify
drivers/scsi/cxgb3i/cxgb3i_init.c line 15
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+* it under the terms of the GNU General Public License as published by +* the Free Software Foundation. +* +* Written by: Karen Xie ([email protected]) +*/ + +#include "cxgb3i.h" + +#define DRV_MODULE_NAME "cxgb3i" +#define DRV_MODULE_VERSION "1.0.0"
I'd suggest that the version number just be removed. It becomes meaningless (and often misleading) once a driver is in the mainline kernel. People will update the driver without changing the version number. Code external to the driver but which affects it can change.
The kernel version identifier is really the only way in whcih you and your support people can reproduce a user's code.
drivers/scsi/cxgb3i/cxgb3i_init.c line 16
Quoted 1 line
drivers/scsi/cxgb3i/cxgb3i_init.c new file +1
-0+#define DRV_MODULE_RELDATE "May 1, 2008"
Ditto.
Quoted 19 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +19
-0+static char version[] = +"Chelsio S3xx iSCSI Driver " DRV_MODULE_NAME +" v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n" ; + +MODULE_AUTHOR ("Karen Xie <[email protected]>" ); +MODULE_DESCRIPTION ("Chelsio S3xx iSCSI Driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION (DRV_MODULE_VERSION ); + +static void open_s3_dev (struct t3cdev *); +static void close_s3_dev (struct t3cdev *); +cxgb3_cpl_handler_func cxgb3i_cpl_handlers[NUM_CPL_CMDS ]; +struct cxgb3_client t3c_client = { + .name ="iscsi_cxgb3" , + .handlers = cxgb3i_cpl_handlers, + .add = open_s3_dev, + .remove = close_s3_dev, +}; +
drivers/scsi/cxgb3i/cxgb3i_init.c line 46
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+/** +* open_s3_dev - register with cxgb3 LLD +* @t3dev cxgb3 adapter instance +*/ +static void open_s3_dev (struct t3cdev *t3dev) +{ +static int vers_printed; + +if (!vers_printed) { +printk (KERN_INFO "%s" , version);
This is normally done at module_init() time.
Quoted 11 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +11
-0+ vers_printed =1 ; + } + +cxgb3i_log_debug ("open cxgb3 %s.\n" , t3dev->name); + +cxgb3i_sdev_add (t3dev, &t3c_client); +cxgb3i_adapter_add (t3dev); +} + +/** +* close_s3_dev - de-register with cxgb3 LLD
drivers/scsi/cxgb3i/cxgb3i_init.c line 67
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+* @t3dev cxgb3 adapter instance +*/ +static void close_s3_dev (struct t3cdev *t3dev) +{ +struct cxgb3i_adapter *snic =cxgb3i_adapter_find_by_tdev (t3dev); +cxgb3i_log_debug ("close cxgb3 %s.\n" , t3dev->name); +if (snic) +cxgb3i_adapter_remove (snic); +cxgb3i_sdev_remove (t3dev); +}
It is conventional to put a single blank line between end-of-locals and start-of-code.
drivers/scsi/cxgb3i/cxgb3i_init.c line 79
Quoted 11 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +11
-0+/** +* cxgb3i_init_module - module init entry point +* +* initialize any driver wide global data structures and register itself +* with the cxgb3 module +*/ +static int __init cxgb3i_init_module (void ) +{ +int err; + + err =cxgb3i_sdev_init (cxgb3i_cpl_handlers);
like that.
Quoted 23 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +20
-0+if (err <0 ) +return err; + + err =cxgb3i_iscsi_init (); +if (err <0 ) +return err; + + err =cxgb3i_ulp2_init (); +if (err <0 ) +return err; + +cxgb3_register_client (&t3c_client); +return 0 ; +} + +struct cxgb3i_adapter *cxgb3i_adapter_find_by_tdev (struct t3cdev *t3dev) +{ +struct cxgb3i_adapter *snic; + +read_lock (&cxgb3i_snic_rwlock);
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+list_for_each_entry (snic, &cxgb3i_snic_list, list_head) { +if (snic->tdev == t3dev) { +read_unlock (&cxgb3i_snic_rwlock); +return snic; + } + } +read_unlock (&cxgb3i_snic_rwlock); + +return NULL ; +}
Is this racy? We look up a device then return it after having unlocked the lock. The caller of this fucntion is handed a pointer to a think which can now be freed by cxgb3i_adapter_remove().
Quoted 21 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +21
-0+struct cxgb3i_hba *cxgb3i_hba_find_by_netdev (struct net_device *ndev) +{ +struct cxgb3i_adapter *snic; +int i; + +read_lock (&cxgb3i_snic_rwlock); +list_for_each_entry (snic, &cxgb3i_snic_list, list_head) { +for (i =0 ; i < snic->hba_cnt; i++) { +if (snic->hba[i]->ndev == ndev) { +read_unlock (&cxgb3i_snic_rwlock); +return (snic->hba[i]); + } + } + } +read_unlock (&cxgb3i_snic_rwlock); +return NULL ; +} + +void cxgb3i_hba_conn_add (struct cxgb3i_conn *cconn,struct cxgb3i_hba *hba) +{ + cconn->hba = hba;
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+write_lock (&hba->cconn_rwlock); +list_add_tail (&cconn->list_head, &hba->cconn_list); +write_unlock (&hba->cconn_rwlock); +} + +void cxgb3i_hba_conn_remove (struct cxgb3i_conn *cconn) +{ +struct cxgb3i_hba *hba = cconn->hba; + +if (hba) {
Can `hba' really be NULL here?
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 12 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +9
-0+write_lock (&hba->cconn_rwlock); +list_del (&cconn->list_head); +write_unlock (&hba->cconn_rwlock); + } +} + +void cxgb3i_hba_host_remove (struct cxgb3i_hba *hba) +{ +if (hba->shost) {
Can hba->shost really be NULL here?
Quoted 23 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +23
-0+cxgb3i_log_debug ("shost 0x%p, hba 0x%p, no %u.\n" , + hba->shost, hba, hba->shost->host_no); +iscsi_host_remove (hba->shost); +pci_dev_put (hba->snic->pdev); +/* cleanup connections ? */ +iscsi_host_free (hba->shost); + } +} + +/** +* cxgb3i_ep_connect - establish TCP connection to target portal +* @dst_addr: target IP address +* @non_blocking: blocking or non-blocking call +* +* Initiates a TCP/IP connection to the dst_addr +*/ +static struct iscsi_endpoint *cxgb3i_ep_connect (struct sockaddr *dst_addr, +int non_blocking) +{ +struct iscsi_endpoint *ep; +struct cxgb3i_endpoint *cep; +struct cxgb3i_hba *hba; +struct s3_conn *c3cn =NULL ;
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+int err =0 ; + + c3cn =cxgb3i_c3cn_create (); +if (!c3cn) { +cxgb3i_log_info ("ep connect OOM.\n" ); + err = -ENOMEM ; + goto release_conn; + } + + err =cxgb3i_c3cn_connect (c3cn, (struct sockaddr_in *)dst_addr);
hm, I'm surprised that networking doesn't provide a neater, typesafe way of converting a sockaddr to a sockaddr_in. union, anonymous union or even a plain old inlined C function. Casts are dangerous.
Quoted 37 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +37
-0+if (err <0 ) { +cxgb3i_log_info ("ep connect failed.\n" ); + goto release_conn; + } + hba =cxgb3i_hba_find_by_netdev (c3cn->dst_cache->dev); +if (!hba) { + err = -ENOSPC ; +cxgb3i_log_info ("NOT going through cxgbi device.\n" ); + goto release_conn; + } +if (c3cn_in_state (c3cn,C3CN_STATE_CLOSE )) { + err = -ENOSPC ; +cxgb3i_log_info ("ep connect unable to connect.\n" ); + goto release_conn; + } + + ep =iscsi_create_endpoint (sizeof (*cep)); +if (!ep) { + err = -ENOMEM ; +cxgb3i_log_info ("iscsi alloc ep, OOM.\n" ); + goto release_conn; + } + cep = ep->dd_data; + cep->c3cn = c3cn; + cep->hba = hba; + +cxgb3i_log_debug ("ep 0x%p, 0x%p, c3cn 0x%p, hba 0x%p.\n" , + ep, cep, c3cn, hba); +return ep; + +release_conn: +cxgb3i_log_debug ("conn failed release.\n" ); +if (c3cn) +c3cn_release (c3cn); +return ERR_PTR (err); +} +
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+/** +* cxgb3i_ep_poll - polls for TCP connection establishement +* @ep: TCP connection (endpoint) handle +* @timeout_ms: timeout value in milli secs +* +* polls for TCP connect request to complete +*/ +static int cxgb3i_ep_poll (struct iscsi_endpoint *ep,int timeout_ms) +{ +struct cxgb3i_endpoint *cep = (struct cxgb3i_endpoint *)ep->dd_data;
dd_data is void*, so no cast is needed.
The unneeded cast is actually a little bit dangerous because it suppresses a compiler warning which we'd get if dd_data has any type other than cxgb3i_endpoint* or void*.
Quoted 11 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +11
-0+struct s3_conn *c3cn = cep->c3cn; + +cxgb3i_log_debug ("ep 0x%p, timeout %d, c3cn 0x%p, state 0x%x.\n" , + ep, timeout_ms, c3cn, c3cn->state); + +if (!c3cn_in_state (c3cn,C3CN_STATE_ESTABLISHED )) { +cxgb3i_log_info ("not in established state.\n" ); +return 0 ; + } +return 1 ; +}
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+ +/** +* cxgb3i_ep_disconnect - teardown TCP connection +* @ep: TCP connection (endpoint) handle +* +* teardown TCP connection +*/ +static void cxgb3i_ep_disconnect (struct iscsi_endpoint *ep) +{ +struct cxgb3i_endpoint *cep = (struct cxgb3i_endpoint *)ep->dd_data;
Please check the whole patch for unneeded casts of void*.
Quoted 4 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +4
-0+struct cxgb3i_conn *cconn = cep->cconn; + +cxgb3i_log_debug ("ep 0x%p, cep 0x%p.\n" , ep, cep); +
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+if (cconn && cconn->conn) { +struct iscsi_conn *conn = cconn->conn; +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +write_lock_bh (&cep->c3cn->callback_lock); + cep->c3cn->user_data =NULL ; +set_bit (ISCSI_SUSPEND_BIT , &conn->suspend_rx); + cconn->cep =NULL ; + tcp_conn->sock =NULL ; +write_unlock_bh (&cep->c3cn->callback_lock); + }
if (cconn && cconn->conn) {
struct iscsi_conn *conn = cconn->conn;
struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
write_lock_bh(&cep->c3cn->callback_lock);
cep->c3cn->user_data = NULL;
set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
cconn->cep = NULL;
tcp_conn->sock = NULL;
write_unlock_bh(&cep->c3cn->callback_lock);
}is easier to read, no?
Quoted 11 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +11
-0+ +cxgb3i_log_debug ("ep 0x%p, cep 0x%p, release c3cn 0x%p.\n" , + ep, cep, cep->c3cn); +c3cn_release (cep->c3cn); +iscsi_destroy_endpoint (ep); +} + +/** +* cxgb3i_session_create - create a new iscsi session +* @cmds_max: max # of commands +* @qdepth: scsi queue depth
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+* @initial_cmdsn: initial iscsi CMDSN for this session +* @host_no: pointer to return host no +* +* Creates a new iSCSI session +*/ +static struct iscsi_cls_session *cxgb3i_session_create (struct iscsi_endpoint + *ep,uint16_t cmds_max, +uint16_t qdepth, +uint32_t initial_cmdsn, +uint32_t *host_no)
Code uses a mixture of uint16_t and u16.
u16 is usually preferred for in-kernel work.
Quoted 4 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +4
-0+{ +struct cxgb3i_endpoint *cep; +struct cxgb3i_hba *hba; +struct Scsi_Host *shost;
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+struct iscsi_cls_session *cls_session; +struct iscsi_session *session; +int i; + +if (!ep) { +cxgb3i_log_error ("%s, missing endpoint.\n" , __func__); +return NULL ; + } + + cep = (struct cxgb3i_endpoint *)ep->dd_data;
cast..
Quoted 5 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +5
-0+ hba = cep->hba; + shost = hba->shost; +cxgb3i_log_debug ("ep 0x%p, cep 0x%p, hba 0x%p.\n" , ep, cep, hba); +BUG_ON (hba !=iscsi_host_priv (shost)); +
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+ *host_no = shost->host_no; + + cls_session =iscsi_session_setup (&cxgb3i_iscsi_transport, shost, + cmds_max, +sizeof (struct iscsi_tcp_task ), + initial_cmdsn,ISCSI_MAX_TARGET ); +if (!cls_session) +return NULL ; + + session = cls_session->dd_data;
you forgot the typecast :)
Quoted 30 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +27
-0+for (i =0 ; i < session->cmds_max; i++) { +struct iscsi_task *task = session->cmds[i]; +struct iscsi_tcp_task *tcp_task = task->dd_data; + + task->hdr = &tcp_task->hdr.cmd_hdr; + task->hdr_max =sizeof (tcp_task->hdr) -ISCSI_DIGEST_SIZE ; + } + +if (iscsi_r2tpool_alloc (session)) + goto remove_session; + +return cls_session; + +remove_session: +iscsi_session_teardown (cls_session); +return NULL ; +} + +/** +* cxgb3i_conn_bind - binds iscsi sess, conn and endpoint together +* @cls_session: pointer to iscsi cls session +* @cls_conn: pointer to iscsi cls conn +* @transport_eph: 64-bit EP handle +* @is_leading: leading connection on this session? +* +* Binds together an iSCSI session, an iSCSI connection and a +* TCP connection. This routine returns error code if the TCP
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+* connection does not belong on the device iSCSI sess/conn is bound +*/ + +static int cxgb3i_conn_bind (struct iscsi_cls_session *cls_session, +struct iscsi_cls_conn *cls_conn, +uint64_t transport_eph,int is_leading) +{ +struct iscsi_conn *conn = cls_conn->dd_data; +struct iscsi_tcp_conn *tcp_conn = conn->dd_data; +struct cxgb3i_conn *cconn = (struct cxgb3i_conn *)(tcp_conn +1 );
This looks a bit bizarre. We somehow got a `struct iscsi_tcp_conn' and a 'struct cxgb3i_conn' laid out contiguously in memory? I don't think I want to know how that happened, but it can all be done very nicely using the C type system, rather than abusing it.
Quoted 47 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +44
-0+struct iscsi_endpoint *ep; +struct cxgb3i_endpoint *cep; +struct s3_conn *c3cn; +int err; + + ep =iscsi_lookup_endpoint (transport_eph); +if (!ep) +return -EINVAL ; + +cxgb3i_log_debug ("ep 0x%p, cls sess 0x%p, cls conn 0x%p.\n" , + ep, cls_session, cls_conn); + + err =iscsi_conn_bind (cls_session, cls_conn, is_leading); +if (err) +return -EINVAL ; + + cep = (struct cxgb3i_endpoint *)ep->dd_data; + c3cn = cep->c3cn; + +read_lock (&c3cn->callback_lock); + tcp_conn->sock = (struct socket *)c3cn; + c3cn->user_data = conn; +read_unlock (&c3cn->callback_lock); + + cconn->hba = cep->hba; + cconn->cep = cep; + cep->cconn = cconn; + + conn->max_recv_dlength = cconn->hba->snic->rx_max_size -ISCSI_PDU_HEADER_MAX ; + conn->max_xmit_dlength = cconn->hba->snic->tx_max_size -ISCSI_PDU_HEADER_MAX ; + +spin_lock_bh (&conn->session->lock); +sprintf (conn->portal_address,NIPQUAD_FMT , +NIPQUAD (c3cn->daddr.sin_addr.s_addr)); + conn->portal_port =ntohs (c3cn->daddr.sin_port); +spin_unlock_bh (&conn->session->lock); + +iscsi_tcp_hdr_recv_prep (tcp_conn); + +return 0 ; +} + +/* +* Deallocate a source port from the allocation map. If the source port is
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+* outside our allocation range just return -- the caller is responsible for +* keeping track of their port usage outside of our allocation map. +*/ +static void c3cn_put_port (struct s3_conn *c3cn) +{ +int old =ntohs (c3cn->saddr.sin_port) - sport_base; + c3cn->saddr.sin_port =0 ; + +if (old <0 || old >= max_connect) +return ;
Is this covering up a bug?
Quoted 6 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +5
-0+spin_lock (&sport_map_lock); +__clear_bit (old, sport_map); +spin_unlock (&sport_map_lock); +} +
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +8
-0+/* +* large memory chunk allocation/release +*/ +void *cxgb3i_alloc_big_mem (unsigned int size) +{ +void *p =kmalloc (size,GFP_KERNEL ); +if (!p) + p =vmalloc (size);
erk.
Yes, it happens. We should provide this in core kernel. We shouldn't be open-coding it in a remote driver.
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 13 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +13
-0+if (p) +memset (p,0 , size); +return p; +} + +void cxgb3i_free_big_mem (void *addr) +{ +unsigned long p = (unsigned long )addr; +if (p >=VMALLOC_START && p <VMALLOC_END ) +vfree (addr); +else +kfree (addr); +}
y:/usr/src/linux-2.6.27-rc4> grep -r VMALLOC_START drivers | wc -l 1
Now it's two. That's a big hint that something is wrong here.
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 6 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +6
-0+void cxgb3i_sdev_cleanup (cxgb3_cpl_handler_func *cpl_handlers) +{ +memset (cpl_handlers,0 ,NUM_CPL_CMDS *(sizeof (*cpl_handlers))); +if (sport_map) +cxgb3i_free_big_mem (sport_map); +}
This function is odd. cpl_handlers[] is already all-zeroes, so why are we rezeroing it all?
The function has no callers so I'm at a loss.
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 12 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +12
-0+int cxgb3i_sdev_init (cxgb3_cpl_handler_func *cpl_handlers) +{ + cpl_handlers[CPL_ACT_ESTABLISH ] = do_act_establish; + cpl_handlers[CPL_ACT_OPEN_RPL ] = do_act_open_rpl; + cpl_handlers[CPL_PEER_CLOSE ] = do_peer_close; + cpl_handlers[CPL_ABORT_REQ_RSS ] = do_abort_req; + cpl_handlers[CPL_ABORT_RPL_RSS ] = do_abort_rpl; + cpl_handlers[CPL_CLOSE_CON_RPL ] = do_close_con_rpl; + cpl_handlers[CPL_TX_DMA_ACK ] = do_wr_ack; + cpl_handlers[CPL_ISCSI_HDR ] = do_iscsi_hdr; + + sport_map =cxgb3i_alloc_big_mem ((max_connect +7 )/8 );
That's DIV_ROUND_UP().
Quoted 25 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +22
-0+if (!sport_map) +return -ENOMEM ; +return 0 ; +} + +/* +* Send an active open request. +*/ +static int act_open (struct s3_conn *c3cn,struct net_device *dev) +{ +struct cxgb3i_sdev_data *cdata =NDEV2CDATA (dev); +struct t3cdev *cdev = cdata->cdev; +struct dst_entry *dst = c3cn->dst_cache; +struct sk_buff *skb; + +c3cn_conn_debug ("c3cn 0x%p.\n" , c3cn); +/* +* Initialize connection data. Note that the flags and ULP mode are +* initialized higher up ... +*/ + c3cn->dev = dev; + c3cn->cdev = cdev;
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+ c3cn->tid =cxgb3_alloc_atid (cdev, cdata->client, c3cn); +if (c3cn->tid <0 ) + goto out_err; + c3cn->qset =0 ; + c3cn->l2t =t3_l2t_get (cdev, dst->neighbour, dev); +if (!c3cn->l2t) + goto free_tid; + + skb =alloc_skb (sizeof (struct cpl_act_open_req ), +GFP_KERNEL | __GFP_NOFAIL);
__GFP_NOFAIL is unusual. Should be commented, or removed. Preferably removed - __GFP_NOFAIL is a hack for callsites which haven't been fixed yet.
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 1 line
drivers/scsi/cxgb3i/cxgb3i_init.c new file +1
-0+ skb->sk = (struct sock *)c3cn;
This callsite should be fixed. Allocations can fail.
Quoted 25 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +25
-0+set_arp_failure_handler (skb, act_open_req_arp_failure); + +c3cn_hold (c3cn); + +init_offload_conn (c3cn, cdev, dst); + c3cn->err =0 ; +c3cn_reset_flag (c3cn,C3CN_DONE ); + +mk_act_open_req (c3cn, skb, c3cn->tid, c3cn->l2t); +l2t_send (cdev, skb, c3cn->l2t); +return 0 ; + +free_tid: +free_atid (cdev, c3cn->tid); + c3cn->tid =0 ; +out_err: +return -1 ; +} + +/* +* Close a connection by sending a CPL_CLOSE_CON_REQ message. Cannot fail +* under any circumstances. We take the easy way out and always queue the +* message to the write_queue. We can optimize the case where the queue is +* already empty though the optimization is probably not worth it. +*/
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+static void mk_close_req (struct s3_conn *c3cn) +{ +struct sk_buff *skb; +struct cpl_close_con_req *req; +unsigned int tid = c3cn->tid; + +c3cn_conn_debug ("c3cn 0x%p.\n" , c3cn); + + skb =alloc_skb (sizeof (struct cpl_close_con_req ), +GFP_KERNEL | __GFP_NOFAIL);
dittoes
Quoted 22 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +22
-0+ req = (struct cpl_close_con_req *)__skb_put (skb,sizeof (*req)); + req->wr.wr_hi =htonl (V_WR_OP (FW_WROPCODE_OFLD_CLOSE_CON )); + req->wr.wr_lo =htonl (V_WR_TID (tid)); +OPCODE_TID (req) =htonl (MK_OPCODE_TID (CPL_CLOSE_CON_REQ , tid)); + req->rsvd =htonl (c3cn->write_seq); + +skb_entail (c3cn, skb,C3CB_FLAG_NO_APPEND ); +if (c3cn->state !=C3CN_STATE_SYN_SENT ) +s3_push_frames (c3cn,1 ); +} + +static void skb_entail (struct s3_conn *c3cn,struct sk_buff *skb, +int flags) +{ +CXGB3_SKB_CB (skb)->seq = c3cn->write_seq; +CXGB3_SKB_CB (skb)->flags = flags; +__skb_queue_tail (&c3cn->write_queue, skb); +} + +/* +* Send RX credits through an RX_DATA_ACK CPL message. If nofail is 0 we are +* permitted to return without sending the message in case we cannot allocate
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +10
-0+* an sk_buff. Returns the number of credits sent. +*/ +static u32 s3_send_rx_credits (struct s3_conn *c3cn,u32 credits,u32 dack, +int nofail) +{ +struct sk_buff *skb; +struct cpl_rx_data_ack *req; + + skb = (nofail ?alloc_ctrl_skb (c3cn,sizeof (*req)) + :alloc_skb (sizeof (*req),GFP_ATOMIC ));
ug. All this nofail stuff seems to go pretty deep. Sorry, but it all should go away and the driver should be coded to handle allocation failures.
Quoted 5 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +4
-0+if (!skb) +return 0 ; + + req = (struct cpl_rx_data_ack *)__skb_put (skb,sizeof (*req));
drivers/scsi/cxgb3i/cxgb3i_init.c
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c new file +8
-0+ req->wr.wr_hi =htonl (V_WR_OP (FW_WROPCODE_FORWARD )); +OPCODE_TID (req) =htonl (MK_OPCODE_TID (CPL_RX_DATA_ACK , c3cn->tid)); + req->credit_dack =htonl (dack |V_RX_CREDITS (credits)); + skb->priority =CPL_PRIORITY_ACK ; +cxgb3_ofld_send (c3cn->cdev, skb); +return credits; +} +
(attention span ran out, sorry)
Quoted 10 lines
drivers/scsi/cxgb3i/cxgb3i_init.c line 15
Quoted 7 lines · Andrew Morton
+ *
+ * Written by: Karen Xie ([email protected]) */drivers/scsi/cxgb3i/cxgb3i_init.c new file +5
-0+ +#include "cxgb3i.h" + +#define DRV_MODULE_NAME "cxgb3i" +#define DRV_MODULE_VERSION "1.0.0"I'd suggest that the version number just be removed. It becomes
meaningless (and often misleading) once a driver is in the mainline kernel. People will >update the driver without changing the version number. Code external to the driver but which affects it can change.
Quoted 1 line
The kernel version identifier is really the only way in whcih you and
your support people can reproduce a user's code.
Quoted 3 lines
Quoted 1 line
+#define
DRV_MODULE_RELDATE"May 1, 2008"Ditto.
It gives us a stick to ask vendors to maintain upstream versions of driver code in the distros.
While we are at this. I believe that there is not much of a standard for driver versioning. If we automatically get a driver version from the kernel version then it solves both problems. Thoughts ??
Thanks,
Shyam
David Miller
maintainerFrom: <[email protected]>
Date: Sat, 23 Aug 2008 13:52:26 +0530
Quoted 4 lines
Quoted 1 line
I'd suggest that the version number just be removed. It becomes
meaningless (and often misleading) once a driver is in the mainline kernel. People will >update the driver without changing the version number. Code external to the driver but which affects it can change.
I totally disagree. I find it very useful when I get a debugging dump from the user and they have no idea where their kernel came from nor can figure out how to determine the kernel version.
Sure it might sometimes not get updated for trivial patches that bypass the maintainer, but the maintainer is always going to bump it after non-trivial changes.
Quoted 8 lines
Quoted 2 lines · David Miller
Andrew Morton wrote:
I'd suggest that the version number just be removed. It becomesmeaningless (and often misleading) once a driver is in the mainline kernel. People will >update the driver without changing the version number. Code external to the driver but which affects it can change.
I totally disagree. I find it very useful when I get a debugging dump
from the user and they have no idea where their kernel came from nor can figure
Quoted 3 lines
out how to determine the kernel version.
Sure it might sometimes not get updated for trivial patches that bypass
the maintainer, but the maintainer is always going to bump it after non-trivial
Quoted 1 line
changes.
Exactly. And I am also suggesting that the driver version is not standard among different vendors. So, why not get them generated in an automatic build process.
Something like "kernel-version.driver-version". I am just imagining here. The details can be worked out.
-Shyam
David Miller
maintainerFrom: <[email protected]>
Date: Sat, 23 Aug 2008 14:37:53 +0530
Quoted 2 lines
Exactly. And I am also suggesting that the driver version is not standard among different vendors.
It should not be standardized because every driver maintainer works differently, and every driver is developed differently, and therefore has different needs and desires for the version number.
All that matters is that the driver version makes sense to the person maintaining the driver, and works for them when reviewing bug reports.
Look, what you're suggesting is to change existing practice and that doesn't belong in the discussion of the review of a specific driver. If you want to bring that up as a topic and change globally how that is handled, bring that up as a seperate topic on linux-kernel.
Don't bug the poor driver submitter who is just following existing and accepted practice.
Quoted 1 line
Look, what you're suggesting is to change existing practice and that
doesn't belong in the discussion of the review of a specific driver.
Quoted 1 line
If you want to bring that up as a topic and change globally how that is
handled, bring that up as a seperate topic on linux-kernel.
Sounds reasonable.
Quoted 1 line
Don't bug the poor driver submitter who is just following existing and
accepted practice.
That wasn't the intention here. It rose out of the discussion that was being suggested that DRV_MODULE_VERSION be removed and I don't think should be done.
So, I suggested a followup suggestion from there. Will take that up as you suggested.
-Shyam
Quoted 5 lines · Andrew Morton
On Fri, 22 Aug 2008 11:40:56 -0700
Quoted 2 lines · Karen Xie
[PATCH 4/4 2.6.28] cxgb3i - cxgb3i iscsi driver
Quoted 9 lines
Quoted 5 lines
From: Karen Xie <[email protected]>
cxgb3i iSCSI driver.
Signed-off-by Karen Xie <[email protected]>I'm going to suggest that this not be merged in this form due to the
__GFP_NOFAILissues identified below.
Hi Andrew,
thanks for the review. We've started fixing the obvious and looking at alternatives for the nofail allocations.
Cheers,
Divy