bnx2: Add iSCSI support.
cover bnx2: Add iSCSI support.
Please review our new version of the iSCSI drivers for Broadcom BNX2 devices. We've reworked the bnx2i driver quite a bit with the help of Mike Christie in the last few months. It is now one scsi host per adapter and has a single iscsi transport name. It is also more tightly coupled to scsi_transport_iscsi and libiscsi.
The bnx2i driver depends on the latest patches in Mike Christie's git tree.
Thanks.
PATCH 2/3 cnic: Add CNIC driver.
The CNIC driver controls BNX2 hardware rings and resources used by iSCSI. It depends on the BNX2 driver to reset the chip and set up the proper link speed.
All hardware resources for iSCSI are separate from those used for ethernet networking. If MSI-X is used, the CNIC driver will register its own MSI-X vector for iSCSI interrupts. If MSI-X is not used, the single interrupt will be shared between the BNX2 driver and the CNIC driver.
--- drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 + drivers/net/cnic.c | 2439 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/cnic.h | 221 +++++ drivers/net/cnic_defs.h | 553 +++++++++++ drivers/net/cnic_drv.h | 112 +++ drivers/net/cnic_if.h | 171 ++++ 7 files changed, 3507 insertions(+), 0 deletions(-) create mode 100644 drivers/net/cnic.c create mode 100644 drivers/net/cnic.h create mode 100644 drivers/net/cnic_defs.h create mode 100644 drivers/net/cnic_drv.h create mode 100644 drivers/net/cnic_if.h
drivers/net/Kconfig +10 -0
@@ -2245,6 +2245,16 @@ config BNX2 To compile this driver as a module, choose M here: the module will be called bnx2. This is recommended. +config CNIC + tristate "Broadcom CNIC support" + depends on BNX2 + help + This driver supports offload features of Broadcom NetXtremeII + gigabit Ethernet cards. + + To compile this driver as a module, choose M here: the module + will be called cnic. This is recommended. + config SPIDER_NET tristate "Spider Gigabit Ethernet driver" depends on PCI && (PPC_IBM_CELL_BLADE || PPC_CELLEB)
drivers/net/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-$(CONFIG_FEALNX) += fealnx.o obj-$(CONFIG_TIGON3) += tg3.o obj-$(CONFIG_BNX2) += bnx2.o obj-$(CONFIG_BNX2X) += bnx2x.o +obj-$(CONFIG_CNIC) += cnic.o spidernet-y += spider_net.o spider_net_ethtool.o obj-$(CONFIG_SPIDER_NET) += spidernet.o sungem_phy.o obj-$(CONFIG_GELIC_NET) += ps3_gelic.o
drivers/net/cnic.c new file +2439 -0
2,439 lines not on this page · raw message
drivers/net/cnic.h new file +221 -0
221 lines not on this page · raw message
drivers/net/cnic_defs.h new file +553 -0
317 lines not on this page · raw message
drivers/net/cnic_drv.h new file +112 -0
112 lines not on this page · raw message
drivers/net/cnic_if.h new file +171 -0
171 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.5.5.GIT
Part of the diff is not shown here. View the raw message.
Re: [PATCH 2/3] cnic: Add CNIC driver.
Quoted 9 lines · Michael Chan
The CNIC driver controls BNX2 hardware rings and resources used by iSCSI. It depends on the BNX2 driver to reset the chip and set up the proper link speed.
All hardware resources for iSCSI are separate from those used for ethernet networking. If MSI-X is used, the CNIC driver will register its own MSI-X vector for iSCSI interrupts. If MSI-X is not used, the single interrupt will be shared between the BNX2 driver and the CNIC driver.
Some questions interspersed below.
Thanx, Paul
Quoted 237 lines
Signed-off-by Michael Chan <[email protected]>--- drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 + drivers/net/cnic.c | 2439 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/cnic.h | 221 +++++ drivers/net/cnic_defs.h | 553 +++++++++++ drivers/net/cnic_drv.h | 112 +++ drivers/net/cnic_if.h | 171 ++++ 7 files changed, 3507 insertions(+), 0 deletions(-) create mode 100644 drivers/net/cnic.c create mode 100644 drivers/net/cnic.h create mode 100644 drivers/net/cnic_defs.h create mode 100644 drivers/net/cnic_drv.h create mode 100644 drivers/net/cnic_if.hdrivers/net/Kconfig +10
-0@@ -2245,6 +2245,16 @@ config BNX2 To compile this driver as a module, choose M here: the module will be called bnx2. This is recommended. +config CNIC + tristate "Broadcom CNIC support" + depends on BNX2 + help + This driver supports offload features of Broadcom NetXtremeII + gigabit Ethernet cards. + + To compile this driver as a module, choose M here: the module + will be called cnic. This is recommended. + config SPIDER_NET tristate "Spider Gigabit Ethernet driver" depends on PCI && (PPC_IBM_CELL_BLADE || PPC_CELLEB)drivers/net/Makefile +1
-0@@ -67,6 +67,7 @@ obj-$(CONFIG_FEALNX) += fealnx.o obj-$(CONFIG_TIGON3) += tg3.o obj-$(CONFIG_BNX2) += bnx2.o obj-$(CONFIG_BNX2X) += bnx2x.o +obj-$(CONFIG_CNIC) += cnic.o spidernet-y += spider_net.o spider_net_ethtool.o obj-$(CONFIG_SPIDER_NET) += spidernet.o sungem_phy.o obj-$(CONFIG_GELIC_NET) += ps3_gelic.odrivers/net/cnic.c new file +182
-0@@ -0,0 +1,2439 @@ +/* cnic.c: Broadcom CNIC core network driver. +* +* Copyright (c) 2006-2007 Broadcom Corporation +* +* 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: John(Zongxi) Chen ([email protected]) +* Modified and maintained by: Michael Chan <[email protected]> +*/ + +#include <linux/module.h> + +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/netdevice.h> +#include <linux/inetdevice.h> +#include <linux/in.h> +#include <linux/dma-mapping.h> +#include <asm/byteorder.h> +#include <linux/delay.h> +#include <linux/ethtool.h> +#include <linux/if_vlan.h> +#define BCM_VLAN 1 +#include <net/ip.h> +#include <net/tcp.h> +#include <net/arp.h> +#include <net/neighbour.h> +#include <net/route.h> +#include <net/ipv6.h> +#include <net/ip6_route.h> +#include <net/addrconf.h> +#include <net/netevent.h> + +#define BCM_CNIC 1 +#include "cnic_drv.h" +#include "bnx2.h" +#include "cnic_if.h" +#include "cnic.h" +#include "cnic_defs.h" + +#define DRV_MODULE_NAME "cnic" +#define PFX DRV_MODULE_NAME ": " + +static char version[]__devinitdata = +"Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME " v" CNIC_MODULE_VERSION " (" CNIC_MODULE_RELDATE ")\n" ; + +MODULE_AUTHOR ("John(Zongxi) Chen <[email protected]>" ); +MODULE_DESCRIPTION ("Broadcom NetXtreme II CNIC Driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION (CNIC_MODULE_VERSION ); + +static LIST_HEAD (cnic_dev_list); +static DEFINE_RWLOCK (cnic_dev_lock); +static DEFINE_MUTEX (cnic_lock); + +struct cnic_ulp_ops *cnic_ulp_tbl[MAX_CNIC_ULP_TYPE ]; + +static int cnic_service_bnx2 (void *,void *); +static int cnic_ctl (void *,struct cnic_ctl_info *); + +static struct cnic_ops cnic_bnx2_ops = { + .cnic_owner =THIS_MODULE , + .cnic_handler = cnic_service_bnx2, + .cnic_ctl = cnic_ctl, +}; + +static inline void cnic_hold (struct cnic_dev *dev) +{ +atomic_inc (&dev->ref_count); +} + +static inline void cnic_put (struct cnic_dev *dev) +{ +atomic_dec (&dev->ref_count); +} + +static inline void csk_hold (struct cnic_sock *csk) +{ +atomic_inc (&csk->ref_count); +} + +static inline void csk_put (struct cnic_sock *csk) +{ +atomic_dec (&csk->ref_count); +} + +static void cnic_bnx2_ctx_wr (struct cnic_dev *dev,u32 cid_addr,u32 off, +u32 val) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; +struct drv_ctl_info info; +struct drv_ctl_io *io = &info.data.io; + + info.cmd =DRV_CTL_CTX_WR_CMD ; + io->cid_addr = cid_addr; + io->offset = off; + io->data = val; + ethdev->drv_ctl (dev->netdev, &info); +} + +static void cnic_bnx2_reg_wr_ind (struct cnic_dev *dev,u32 off,u32 val) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; +struct drv_ctl_info info; +struct drv_ctl_io *io = &info.data.io; + + info.cmd =DRV_CTL_IO_WR_CMD ; + io->offset = off; + io->data = val; + ethdev->drv_ctl (dev->netdev, &info); +} + +static u32 cnic_bnx2_reg_rd_ind (struct cnic_dev *dev,u32 off) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; +struct drv_ctl_info info; +struct drv_ctl_io *io = &info.data.io; + + info.cmd =DRV_CTL_IO_WR_CMD ; + io->offset = off; + ethdev->drv_ctl (dev->netdev, &info); +return io->data; +} + +static int cnic_in_use (struct cnic_sock *csk) +{ +return (test_bit (SK_F_INUSE , &csk->flags)); +} + +static int cnic_offld_prep (struct cnic_sock *csk) +{ +if (!test_bit (SK_F_CONNECT_START , &csk->flags)) +return 0 ; + +if (test_and_set_bit (SK_F_OFFLD_SCHED , &csk->flags)) +return 0 ; + +return 1 ; +} + +static int cnic_abort_prep (struct cnic_sock *csk) +{ +while (test_and_set_bit (SK_F_OFFLD_SCHED , &csk->flags)) +msleep (1 ); + +if (test_bit (SK_F_OFFLD_COMPLETE , &csk->flags)) +return 1 ; + +return 0 ; +} + +static void cnic_abort_done (struct cnic_sock *csk) +{ +smp_mb__before_clear_bit (); +clear_bit (SK_F_OFFLD_SCHED , &csk->flags); +} + +int cnic_register_driver (int ulp_type,struct cnic_ulp_ops *ulp_ops) +{ +struct cnic_dev *dev; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_register_driver: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (cnic_ulp_tbl[ulp_type]) { + printk(KERN_ERR PFX "cnic_register_driver: Type %d has already " + "been registered\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EBUSY ; + }
drivers/net/cnic.c line 192
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+ +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +clear_bit (ULP_F_INIT , &cp->ulp_flags[ulp_type]); + } +read_unlock (&cnic_dev_lock); + +rcu_assign_pointer (cnic_ulp_tbl[ulp_type], ulp_ops);
OK, protected by cnic_lock.
Quoted 27 lines
drivers/net/cnic.c new file +27
-0+mutex_unlock (&cnic_lock); + +/* Prevent race conditions with netdev_event */ +rtnl_lock (); +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +if (!test_and_set_bit (ULP_F_INIT , &cp->ulp_flags[ulp_type])) + ulp_ops->cnic_init (dev); + } +read_unlock (&cnic_dev_lock); +rtnl_unlock (); + +return 0 ; +} + +int cnic_unregister_driver (int ulp_type) +{ +struct cnic_dev *dev; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_unregister_driver: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock);
drivers/net/cnic.c line 229
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+if (!cnic_ulp_tbl[ulp_type]) { + printk(KERN_ERR PFX "cnic_unregister_driver: Type %d has not " + "been registered\n", ulp_type); + goto out_unlock; + } +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +if (rcu_dereference (cp->ulp_ops[ulp_type])) {
The rcu_dereference() is redundant because we hold cnic_lock. (Which is OK, just wanting to make sure I understand the code.)
drivers/net/cnic.c line 238
Quoted 9 lines
drivers/net/cnic.c new file +9
-0+ printk(KERN_ERR PFX "cnic_unregister_driver: Type %d " + "still has devices registered\n", ulp_type); +read_unlock (&cnic_dev_lock); + goto out_unlock; + } + } +read_unlock (&cnic_dev_lock); + +rcu_assign_pointer (cnic_ulp_tbl[ulp_type],NULL );
OK, protected by cnic_lock.
drivers/net/cnic.c line 241
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+ +mutex_unlock (&cnic_lock); +synchronize_rcu ();
The caller is responsible for freeing up cnic_ulp_tbl[ulp_type]? If so, the caller had better have kept a pointer to it...
But the caller would need to snapshot the pointer before the cnic_lock was acquired, which means that some other pointer might in fact be in place by the time this function returns.
So, is this data element statically allocated? Or is there some other trick being used?
Or is the whole point of this code simply to ensure that any calls to the old cnic_ulp_tbl[ulp_type] functions have completed before this function returns? If so, please add a comment to this effect.
Quoted 22 lines
drivers/net/cnic.c new file +22
-0+return 0 ; + +out_unlock: +mutex_unlock (&cnic_lock); +return -EINVAL ; +} + +EXPORT_SYMBOL (cnic_register_driver); +EXPORT_SYMBOL (cnic_unregister_driver); + +static int cnic_start_hw (struct cnic_dev *); +static void cnic_stop_hw (struct cnic_dev *); + +static int cnic_register_device (struct cnic_dev *dev,int ulp_type, +void *ulp_ctx) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_ulp_ops *ulp_ops; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_register_device: Bad type %d\n", + ulp_type);
drivers/net/cnic.c line 273
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (cnic_ulp_tbl[ulp_type] ==NULL ) { + printk(KERN_ERR PFX "cnic_register_device: Driver with type %d " + "has not been registered\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EAGAIN ; + } +if (rcu_dereference (cp->ulp_ops[ulp_type])) {
Again, the rcu_dereference() is redundant due to the cnic_lock being held, and again, this is OK, just checking to make sure I understand it.
Quoted 4 lines
drivers/net/cnic.c new file +4
-0+ printk(KERN_ERR PFX "cnic_register_device: Type %d has already " + "been registered to this device\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EBUSY ;
drivers/net/cnic.c line 287
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+ } +if (!try_module_get (cnic_ulp_tbl[ulp_type]->owner)) { +mutex_unlock (&cnic_lock); +return -EBUSY ; + } + +clear_bit (ULP_F_START , &cp->ulp_flags[ulp_type]); + cp->ulp_handle[ulp_type] = ulp_ctx; + ulp_ops = cnic_ulp_tbl[ulp_type]; +rcu_assign_pointer (cp->ulp_ops[ulp_type], ulp_ops);
Good, protected by cnic_lock.
Quoted 25 lines
drivers/net/cnic.c new file +25
-0+cnic_hold (dev); +if (!dev->use_count) { +if (!test_bit (CNIC_F_IF_GOING_DOWN , &dev->flags)) { +if (dev->netdev->flags &IFF_UP ) +set_bit (CNIC_F_IF_UP , &dev->flags); + } + } + dev->use_count++; + +if (dev->use_count ==1 ) { +if (test_bit (CNIC_F_IF_UP , &dev->flags)) +cnic_start_hw (dev); + } + +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) +if (!test_and_set_bit (ULP_F_START , &cp->ulp_flags[ulp_type])) + ulp_ops->cnic_start (cp->ulp_handle[ulp_type]); + +mutex_unlock (&cnic_lock); + +return 0 ; + +} + +static int cnic_unregister_device (struct cnic_dev *dev,int ulp_type)
drivers/net/cnic.c line 322
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+{ +struct cnic_local *cp = dev->cnic_priv; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_unregister_device: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (rcu_dereference (cp->ulp_ops[ulp_type])) {
Ditto...
drivers/net/cnic.c line 325
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+ dev->use_count--; +module_put (cp->ulp_ops[ulp_type]->owner); +rcu_assign_pointer (cp->ulp_ops[ulp_type],NULL );
OK, cnic_lock held...
drivers/net/cnic.c line 337
Quoted 12 lines
drivers/net/cnic.c new file +12
-0+if (dev->use_count ==0 ) +cnic_stop_hw (dev); +cnic_put (dev); + }else { + printk(KERN_ERR PFX "cnic_unregister_device: device not " + "registered to this ulp type %d\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EINVAL ; + } +mutex_unlock (&cnic_lock); + +synchronize_rcu ();
Caller is again responsible for freeing up cp->ulp_ops[ulp_type]? If so, the caller had better have obtained a reference to it beforehand. But it might have changed in the meantime. So, how is this freed?
Or is this statically allocated with the only purpose of the synchronize_rcu() being to ensure that calls though the old ops vector have completed before this function returns? If so, please add a comment to this effect.
Quoted 1,416 lines
drivers/net/cnic.c new file +1416
-0+ +return 0 ; +} + +static void cnic_free_dma (struct cnic_dev *dev,struct cnic_dma *dma) +{ +int i; + +if (!dma->pg_arr) +return ; + +for (i =0 ; i < dma->num_pages; i++) { +if (dma->pg_arr[i]) { +pci_free_consistent (dev->pcidev,BCM_PAGE_SIZE , + dma->pg_arr[i], dma->pg_map_arr[i]); + dma->pg_arr[i] =NULL ; + } + } +if (dma->pgtbl) { +pci_free_consistent (dev->pcidev, dma->pgtbl_size, + dma->pgtbl, dma->pgtbl_map); + dma->pgtbl =NULL ; + } +kfree (dma->pg_arr); + dma->pg_arr =NULL ; + dma->num_pages =0 ; +} + +static void cnic_setup_page_tbl (struct cnic_dev *dev,struct cnic_dma *dma) +{ +int i; +u32 *page_table = dma->pgtbl; + +for (i =0 ; i < dma->num_pages; i++) { +/* Each entry needs to be in big endian format. */ + *page_table = (u32) ((u64 ) dma->pg_map_arr[i] >>32 ); + page_table++; + *page_table = (u32 ) dma->pg_map_arr[i]; + page_table++; + } +} + +static int cnic_alloc_dma (struct cnic_dev *dev,struct cnic_dma *dma, +int pages,int use_pg_tbl) +{ +int i, size; +struct cnic_local *cp = dev->cnic_priv; + + size = pages * (sizeof (void *) +sizeof (dma_addr_t)); + dma->pg_arr =kzalloc (size,GFP_ATOMIC ); +if (dma->pg_arr ==NULL ) +return -ENOMEM ; + + dma->pg_map_arr = (dma_addr_t *) (dma->pg_arr + pages); + dma->num_pages = pages; + +for (i =0 ; i < pages; i++) { + dma->pg_arr[i] =pci_alloc_consistent (dev->pcidev, +BCM_PAGE_SIZE , + &dma->pg_map_arr[i]); +if (dma->pg_arr[i] ==NULL ) + goto error; + } +if (!use_pg_tbl) +return 0 ; + + dma->pgtbl_size = ((pages *8 ) +BCM_PAGE_SIZE -1 ) & + (BCM_PAGE_SIZE -1 ); + dma->pgtbl =pci_alloc_consistent (dev->pcidev, dma->pgtbl_size, + &dma->pgtbl_map); +if (dma->pgtbl ==NULL ) + goto error; + + cp->setup_pgtbl (dev, dma); + +return 0 ; + +error: +cnic_free_dma (dev, dma); +return -ENOMEM ; +} + +static void cnic_free_resc (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int i; + +for (i =0 ; i < cp->ctx_blks; i++) { +if (cp->ctx_arr[i].ctx) { +pci_free_consistent (dev->pcidev, cp->ctx_blk_size, + cp->ctx_arr[i].ctx, + cp->ctx_arr[i].mapping); + cp->ctx_arr[i].ctx =NULL ; + } + } +kfree (cp->ctx_arr); + cp->ctx_arr =NULL ; + cp->ctx_blks =0 ; + +cnic_free_dma (dev, &cp->kwq_info); +cnic_free_dma (dev, &cp->kcq_info); +return ; +} + +static int cnic_alloc_context (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; + +if (CHIP_NUM (cp) ==CHIP_NUM_5709 ) { +int i, k, arr_size; + + cp->ctx_blk_size =BCM_PAGE_SIZE ; + cp->cids_per_blk =BCM_PAGE_SIZE /128 ; + arr_size =BNX2_MAX_CID / cp->cids_per_blk * +sizeof (struct cnic_ctx ); + cp->ctx_arr =kmalloc (arr_size,GFP_KERNEL ); +if (cp->ctx_arr ==NULL ) +return -ENOMEM ; + +memset (cp->ctx_arr,0 , arr_size); + + k =0 ; +for (i =0 ; i <2 ; i++) { +u32 j, reg, off, lo, hi; + +if (i ==0 ) + off =BNX2_PG_CTX_MAP ; +else + off =BNX2_ISCSI_CTX_MAP ; + + reg =cnic_bnx2_reg_rd_ind (dev, off); + lo = reg >>16 ; + hi = reg &0xffff ; +for (j = lo; j < hi; j += cp->cids_per_blk, k++) + cp->ctx_arr[k].cid = j; + } + + cp->ctx_blks = k; + +for (i =0 ; i < cp->ctx_blks; i++) { + cp->ctx_arr[i].ctx = +pci_alloc_consistent (dev->pcidev,BCM_PAGE_SIZE , + &cp->ctx_arr[i].mapping); +if (cp->ctx_arr[i].ctx ==NULL ) +return -ENOMEM ; + } + } +return 0 ; +} + +static int cnic_alloc_bnx2_resc (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int ret; + + ret =cnic_alloc_dma (dev, &cp->kwq_info,KWQ_PAGE_CNT ,1 ); +if (ret) + goto error; + cp->kwq = (struct kwqe **) cp->kwq_info.pg_arr; + + ret =cnic_alloc_dma (dev, &cp->kcq_info,KCQ_PAGE_CNT ,1 ); +if (ret) + goto error; + cp->kcq = (struct kcqe **) cp->kcq_info.pg_arr; + + ret =cnic_alloc_context (dev); +if (ret) + goto error; + +return 0 ; + +error: +cnic_free_resc (dev); +return ret; +} + +static inline u32 cnic_kwq_avail (struct cnic_local *cp) +{ +return (cp->max_kwq_idx - + ((cp->kwq_prod_idx - cp->kwq_con_idx) & cp->max_kwq_idx)); +} + +static int cnic_submit_bnx2_kwqes (struct cnic_dev *dev,struct kwqe *wqes[], +u32 num_wqes) +{ +struct cnic_local *cp = dev->cnic_priv; +struct kwqe *prod_qe; +u16 prod, sw_prod, i; + +if (!test_bit (CNIC_F_CNIC_UP , &dev->flags)) +return -EAGAIN ;/* bnx2 is down */ + +spin_lock_bh (&cp->cnic_ulp_lock); +if (num_wqes >cnic_kwq_avail (cp) && + !(cp->cnic_local_flags &CNIC_LCL_FL_KWQ_INIT )) { +spin_unlock_bh (&cp->cnic_ulp_lock); +return -EAGAIN ; + } + + cp->cnic_local_flags &= ~CNIC_LCL_FL_KWQ_INIT ; + + prod = cp->kwq_prod_idx; + sw_prod = prod &MAX_KWQ_IDX ; +for (i =0 ; i < num_wqes; i++) { + prod_qe = &cp->kwq[KWQ_PG (sw_prod)][KWQ_IDX (sw_prod)]; +memcpy (prod_qe, wqes[i],sizeof (struct kwqe )); + prod++; + sw_prod = prod &MAX_KWQ_IDX ; + } + cp->kwq_prod_idx = prod; + +CNIC_WR16 (dev, cp->kwq_io_addr, cp->kwq_prod_idx); + +spin_unlock_bh (&cp->cnic_ulp_lock); +return 0 ; +} + +static void service_kcqes (struct cnic_dev *dev,int num_cqes) +{ +struct cnic_local *cp = dev->cnic_priv; +int i, j; + + i =0 ; + j =1 ; +while (num_cqes) { +struct cnic_ulp_ops *ulp_ops; +int ulp_type; +u32 kcqe_op_flag = cp->completed_kcq[i]->kcqe_op_flag; +u32 kcqe_layer = kcqe_op_flag &KCQE_FLAGS_LAYER_MASK ; + +while (j < num_cqes) { +u32 next_op = cp->completed_kcq[i + j]->kcqe_op_flag; + +if ((next_op &KCQE_FLAGS_LAYER_MASK ) != kcqe_layer) +break ; + j++; + } + +if (kcqe_layer ==KCQE_FLAGS_LAYER_MASK_L5_RDMA ) + ulp_type =CNIC_ULP_RDMA ; +else if (kcqe_layer ==KCQE_FLAGS_LAYER_MASK_L5_ISCSI ) + ulp_type =CNIC_ULP_ISCSI ; +else if (kcqe_layer ==KCQE_FLAGS_LAYER_MASK_L4 ) + ulp_type =CNIC_ULP_L4 ; +else { + printk(KERN_ERR PFX "%s: Unknown type of KCQE(0x%x)\n", + dev->netdev->name, kcqe_op_flag); + goto end; + } + +rcu_read_lock (); + ulp_ops =rcu_dereference (cp->ulp_ops[ulp_type]); +if (likely (ulp_ops)) { + ulp_ops->indicate_kcqes (cp->ulp_handle[ulp_type], + cp->completed_kcq + i, j); + } +rcu_read_unlock (); +end: + num_cqes -= j; + i += j; + j =1 ; + } +return ; +} + +static int cnic_get_kcqes (struct cnic_dev *dev,u16 hw_prod,u16 sw_prod) +{ +struct cnic_local *cp = dev->cnic_priv; +u16 i, max; +struct kcqe *kcqe; +int kcqe_cnt =0 ; + + i = sw_prod &MAX_KCQ_IDX ; + max = hw_prod &MAX_KCQ_IDX ; +while ((i != max) && (kcqe_cnt <MAX_COMPLETED_KCQE )) { + cp->completed_kcq[kcqe_cnt++] = &cp->kcq[KCQ_PG (i)][KCQ_IDX (i)]; + i = (i +1 ) &MAX_KCQ_IDX ; + } + + kcqe = cp->completed_kcq[kcqe_cnt -1 ]; +while (kcqe->kcqe_op_flag &KCQE_FLAGS_NEXT ) { + kcqe_cnt--; +if (kcqe_cnt ==0 ) + goto done; + kcqe = cp->completed_kcq[kcqe_cnt -1 ]; + } +done: +return kcqe_cnt; +} + +static int cnic_service_bnx2 (void *data,void *status_blk) +{ +struct cnic_dev *dev = data; +struct status_block *sblk = status_blk; +struct cnic_local *cp = dev->cnic_priv; +u32 status_idx = sblk->status_idx; +u16 hw_prod, sw_prod; +int kcqe_cnt; + +if (unlikely (!test_bit (CNIC_F_CNIC_UP , &dev->flags))) +return status_idx; + + cp->kwq_con_idx = sblk->status_rx_quick_consumer_index15; + + hw_prod = sblk->status_completion_producer_index; + sw_prod = cp->kcq_prod_idx; +while (sw_prod != hw_prod) { + kcqe_cnt =cnic_get_kcqes (dev, hw_prod, sw_prod); +if (kcqe_cnt ==0 ) + goto done; + sw_prod += kcqe_cnt; + +service_kcqes (dev, kcqe_cnt); + +/* Tell compiler that status_blk fields can change. */ +barrier (); +if (status_idx != sblk->status_idx) { + status_idx = sblk->status_idx; + cp->kwq_con_idx = + sblk->status_rx_quick_consumer_index15; + hw_prod = sblk->status_completion_producer_index; + }else +break ; + } + +done: +CNIC_WR16 (dev, cp->kcq_io_addr, sw_prod); + + cp->kcq_prod_idx = sw_prod; +return status_idx; +} + +static void cnic_service_bnx2_msix (unsigned long data) +{ +struct cnic_dev *dev = (struct cnic_dev *) data; +struct cnic_local *cp = dev->cnic_priv; +struct status_block_msix *status_blk = cp->bnx2_status_blk; +u32 status_idx = status_blk->status_idx; +u16 hw_prod, sw_prod; +int kcqe_cnt; + + cp->kwq_con_idx = status_blk->status_cmd_consumer_index; + + hw_prod = status_blk->status_completion_producer_index; + sw_prod = cp->kcq_prod_idx; +while (sw_prod != hw_prod) { + kcqe_cnt =cnic_get_kcqes (dev, hw_prod, sw_prod); +if (kcqe_cnt ==0 ) + goto done; + sw_prod += kcqe_cnt; + +service_kcqes (dev, kcqe_cnt); + +/* Tell compiler that status_blk fields can change. */ +barrier (); +if (status_idx != status_blk->status_idx) { + status_idx = status_blk->status_idx; + cp->kwq_con_idx = status_blk->status_cmd_consumer_index; + hw_prod = status_blk->status_completion_producer_index; + }else +break ; + } + +done: +CNIC_WR16 (dev, cp->kcq_io_addr, sw_prod); + + cp->kcq_prod_idx = sw_prod; + cp->last_status_idx = status_idx; +CNIC_WR (dev,BNX2_PCICFG_INT_ACK_CMD ,BNX2_CNIC_INT_NUM | +BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx); +} + +static irqreturn_t cnic_irq (int irq,void *dev_instance) +{ +struct cnic_dev *dev = dev_instance; +struct cnic_local *cp = dev->cnic_priv; +u16 prod = cp->kcq_prod_idx &MAX_KCQ_IDX ; + +if (cp->ack_int) + cp->ack_int (dev); + +prefetch (cp->status_blk); +prefetch (&cp->kcq[KCQ_PG (prod)][KCQ_IDX (prod)]); + +if (likely (test_bit (CNIC_F_CNIC_UP , &dev->flags))) +tasklet_schedule (&cp->cnic_irq_task); + +return IRQ_HANDLED ; +} + +static void cnic_ulp_stop (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int if_type; + +rcu_read_lock (); +for (if_type =0 ; if_type <MAX_CNIC_ULP_TYPE ; if_type++) { +struct cnic_ulp_ops *ulp_ops; + + ulp_ops =rcu_dereference (cp->ulp_ops[if_type]); +if (!ulp_ops) +continue ; + +if (test_and_clear_bit (ULP_F_START , &cp->ulp_flags[if_type])) + ulp_ops->cnic_stop (cp->ulp_handle[if_type]); + } +rcu_read_unlock (); +} + +static void cnic_ulp_start (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int if_type; + +rcu_read_lock (); +for (if_type =0 ; if_type <MAX_CNIC_ULP_TYPE ; if_type++) { +struct cnic_ulp_ops *ulp_ops; + + ulp_ops =rcu_dereference (cp->ulp_ops[if_type]); +if (!ulp_ops) +continue ; + +if (!test_and_set_bit (ULP_F_START , &cp->ulp_flags[if_type])) + ulp_ops->cnic_start (cp->ulp_handle[if_type]); + } +rcu_read_unlock (); +} + +static int cnic_ctl (void *data,struct cnic_ctl_info *info) +{ +struct cnic_dev *dev = data; + +switch (info->cmd) { +case CNIC_CTL_STOP_CMD : +cnic_hold (dev); +mutex_lock (&cnic_lock); + +clear_bit (CNIC_F_IF_UP , &dev->flags); +cnic_ulp_stop (dev); +cnic_stop_hw (dev); + +mutex_unlock (&cnic_lock); +cnic_put (dev); +break ; +case CNIC_CTL_START_CMD : +cnic_hold (dev); +mutex_lock (&cnic_lock); + +set_bit (CNIC_F_IF_UP , &dev->flags); +if (dev->use_count) { +if (!cnic_start_hw (dev)) +cnic_ulp_start (dev); + } +mutex_unlock (&cnic_lock); +cnic_put (dev); +break ; +default : +return -EINVAL ; + } +return 0 ; +} + + +static void cnic_ulp_init (struct cnic_dev *dev) +{ +int i; +struct cnic_local *cp = dev->cnic_priv; + +rcu_read_lock (); +for (i =0 ; i <MAX_CNIC_ULP_TYPE_EXT ; i++) { +struct cnic_ulp_ops *ulp_ops; + + ulp_ops =rcu_dereference (cnic_ulp_tbl[i]); +if (!ulp_ops || !try_module_get (ulp_ops->owner)) +continue ; + +if (!test_and_set_bit (ULP_F_INIT , &cp->ulp_flags[i])) + ulp_ops->cnic_init (dev); + +module_put (ulp_ops->owner); + } +rcu_read_unlock (); +} + +static void cnic_ulp_exit (struct cnic_dev *dev) +{ +int i; +struct cnic_local *cp = dev->cnic_priv; + +rcu_read_lock (); +for (i =0 ; i <MAX_CNIC_ULP_TYPE_EXT ; i++) { +struct cnic_ulp_ops *ulp_ops; + + ulp_ops =rcu_dereference (cnic_ulp_tbl[i]); +if (!ulp_ops || !try_module_get (ulp_ops->owner)) +continue ; + +if (test_and_clear_bit (ULP_F_INIT , &cp->ulp_flags[i])) + ulp_ops->cnic_exit (dev); + +module_put (ulp_ops->owner); + } +rcu_read_unlock (); +} + +static int cnic_queue_work (struct cnic_local *cp,u32 work_type,void *data) +{ +struct cnic_work_node *node; +int bytes =sizeof (u32 *); + +spin_lock_bh (&cp->wr_lock); + + node = &cp->cnic_work_ring[cp->cnic_wr_prod]; + node->work_type = work_type; +if (work_type ==WORK_TYPE_KCQE ) + bytes =sizeof (struct kcqe ); +if (work_type ==WORK_TYPE_REDIRECT ) + bytes =sizeof (struct cnic_redirect_entry ); +memcpy (&node->work_data, data, bytes); + cp->cnic_wr_prod++; + cp->cnic_wr_prod &=WORK_RING_SIZE_MASK ; + +spin_unlock_bh (&cp->wr_lock); +return 0 ; +} + +static int cnic_cm_offload_pg (struct cnic_sock *csk) +{ +struct cnic_dev *dev = csk->dev; +struct l4_kwq_offload_pg *l4kwqe; +struct kwqe *wqes[1 ]; +struct neighbour *neigh = csk->dst->neighbour; +struct net_device *netdev = neigh->dev; + + l4kwqe = (struct l4_kwq_offload_pg *) &csk->kwqe1; +memset (l4kwqe,0 ,sizeof (*l4kwqe)); + wqes[0 ] = (struct kwqe *) l4kwqe; + + l4kwqe->op_code =L4_KWQE_OPCODE_VALUE_OFFLOAD_PG ; + l4kwqe->flags = +L4_LAYER_CODE <<L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT ; + l4kwqe->l2hdr_nbytes =ETH_HLEN ; + l4kwqe->da0 = neigh->ha[0 ]; + l4kwqe->da1 = neigh->ha[1 ]; + l4kwqe->da2 = neigh->ha[2 ]; + l4kwqe->da3 = neigh->ha[3 ]; + l4kwqe->da4 = neigh->ha[4 ]; + l4kwqe->da5 = neigh->ha[5 ]; + + l4kwqe->sa0 = netdev->dev_addr[0 ]; + l4kwqe->sa1 = netdev->dev_addr[1 ]; + l4kwqe->sa2 = netdev->dev_addr[2 ]; + l4kwqe->sa3 = netdev->dev_addr[3 ]; + l4kwqe->sa4 = netdev->dev_addr[4 ]; + l4kwqe->sa5 = netdev->dev_addr[5 ]; + + l4kwqe->etype =ETH_P_IP ; + l4kwqe->ipid_count =DEF_IPID_COUNT ; + l4kwqe->host_opaque = csk->l5_cid; + +if (csk->vlan_id) { + l4kwqe->pg_flags |=L4_KWQ_OFFLOAD_PG_VLAN_TAGGING ; + l4kwqe->vlan_tag = csk->vlan_id; + l4kwqe->l2hdr_nbytes +=4 ; + } + +return (dev->submit_kwqes (dev, wqes,1 )); +} + +static int cnic_cm_update_pg (struct cnic_sock *csk) +{ +struct cnic_dev *dev = csk->dev; +struct l4_kwq_update_pg *l4kwqe; +struct kwqe *wqes[1 ]; +struct neighbour *neigh = csk->dst->neighbour; + + l4kwqe = (struct l4_kwq_update_pg *) &csk->kwqe1; +memset (l4kwqe,0 ,sizeof (*l4kwqe)); + wqes[0 ] = (struct kwqe *) l4kwqe; + + l4kwqe->opcode =L4_KWQE_OPCODE_VALUE_UPDATE_PG ; + l4kwqe->flags = +L4_LAYER_CODE <<L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT ; + l4kwqe->pg_cid = csk->pg_cid; + l4kwqe->da0 = neigh->ha[0 ]; + l4kwqe->da1 = neigh->ha[1 ]; + l4kwqe->da2 = neigh->ha[2 ]; + l4kwqe->da3 = neigh->ha[3 ]; + l4kwqe->da4 = neigh->ha[4 ]; + l4kwqe->da5 = neigh->ha[5 ]; + + l4kwqe->pg_host_opaque =0 ; + l4kwqe->pg_valids =L4_KWQ_UPDATE_PG_VALIDS_DA ; + +return (dev->submit_kwqes (dev, wqes,1 )); +} + +static int cnic_cm_upload_pg (struct cnic_sock *csk) +{ +struct cnic_dev *dev = csk->dev; +struct l4_kwq_upload *l4kwqe; +struct kwqe *wqes[1 ]; + + l4kwqe = (struct l4_kwq_upload *) &csk->kwqe1; +memset (l4kwqe,0 ,sizeof (*l4kwqe)); + wqes[0 ] = (struct kwqe *) l4kwqe; + + l4kwqe->opcode =L4_KWQE_OPCODE_VALUE_UPLOAD_PG ; + l4kwqe->flags = +L4_LAYER_CODE <<L4_KWQ_UPLOAD_LAYER_CODE_SHIFT ; + l4kwqe->cid = csk->pg_cid; + +return (dev->submit_kwqes (dev, wqes,1 )); +} + +static void cnic_redirect (struct cnic_local *cp,struct dst_entry *new, +struct dst_entry *old) +{ +int i, found =0 ; + +for (i =0 ; i <MAX_CM_SK_TBL_SZ && !found; i++) { +struct cnic_sock *csk; +struct cnic_redirect_entry cnic_redir; + + csk = &cp->csk_tbl[i]; +csk_hold (csk); +if (cnic_in_use (csk) && csk->dst == old) { + found =1 ; +dst_hold (new); +dst_hold (old); + + cnic_redir.old_dst = old; + cnic_redir.new_dst = new; +cnic_queue_work (cp,WORK_TYPE_REDIRECT , &cnic_redir); +tasklet_schedule (&cp->cnic_task); + } +csk_put (csk); + } +} + +static void cnic_update_neigh (struct cnic_local *cp,struct neighbour *neigh) +{ +int i, found =0 ; + +for (i =0 ; i <MAX_CM_SK_TBL_SZ && !found; i++) { +struct cnic_sock *csk; + + csk = &cp->csk_tbl[i]; +csk_hold (csk); +if (cnic_in_use (csk) && csk->dst) { +if (csk->dst->neighbour == neigh) { + found =1 ; +neigh_hold (neigh); + +cnic_queue_work (cp,WORK_TYPE_NEIGH_UPDATE , + &neigh); +tasklet_schedule (&cp->cnic_task); + } + } +csk_put (csk); + } +} + +static int cnic_net_callback (struct notifier_block *this,unsigned long event, +void *ptr) +{ + struct cnic_local *cp = container_of(this, struct cnic_local, cm_nb); + +if (event ==NETEVENT_NEIGH_UPDATE ) { +struct neighbour *neigh = ptr; + +cnic_update_neigh (cp, neigh); + + }else if (event ==NETEVENT_REDIRECT ) { +struct netevent_redirect *netevent = ptr; +struct dst_entry *old_dst = netevent->old; +struct dst_entry *new_dst = netevent->new; + +cnic_redirect (cp, new_dst, old_dst); + } +return 0 ; +} + +static int cnic_cm_conn_req (struct cnic_sock *csk) +{ +struct cnic_dev *dev = csk->dev; +struct l4_kwq_connect_req1 *l4kwqe1; +struct l4_kwq_connect_req2 *l4kwqe2; +struct l4_kwq_connect_req3 *l4kwqe3; +struct kwqe *wqes[3 ]; +u8 tcp_flags =0 ; +int num_wqes =2 ; + + l4kwqe1 = (struct l4_kwq_connect_req1 *) &csk->kwqe1; + l4kwqe2 = (struct l4_kwq_connect_req2 *) &csk->kwqe2; + l4kwqe3 = (struct l4_kwq_connect_req3 *) &csk->kwqe3; +memset (l4kwqe1,0 ,sizeof (*l4kwqe1)); +memset (l4kwqe2,0 ,sizeof (*l4kwqe2)); +memset (l4kwqe3,0 ,sizeof (*l4kwqe3)); + + l4kwqe3->op_code =L4_KWQE_OPCODE_VALUE_CONNECT3 ; + l4kwqe3->flags = +L4_LAYER_CODE <<L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT ; + l4kwqe3->ka_timeout = csk->ka_timeout; + l4kwqe3->ka_interval = csk->ka_interval; + l4kwqe3->ka_max_probe_count = csk->ka_max_probe_count; + l4kwqe3->tos = csk->tos; + l4kwqe3->ttl = csk->ttl; + l4kwqe3->snd_seq_scale = csk->snd_seq_scale; + l4kwqe3->pmtu =dst_mtu (csk->dst); + l4kwqe3->rcv_buf = csk->rcv_buf; + l4kwqe3->snd_buf = csk->snd_buf; + l4kwqe3->seed = csk->seed; + + wqes[0 ] = (struct kwqe *) l4kwqe1; +if (test_bit (SK_F_IPV6 , &csk->flags)) { + wqes[1 ] = (struct kwqe *) l4kwqe2; + wqes[2 ] = (struct kwqe *) l4kwqe3; + num_wqes =3 ; + + l4kwqe1->conn_flags =L4_KWQ_CONNECT_REQ1_IP_V6 ; + l4kwqe2->op_code =L4_KWQE_OPCODE_VALUE_CONNECT2 ; + l4kwqe2->flags = +L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT | +L4_LAYER_CODE <<L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT ; + l4kwqe2->src_ip_v6_2 =be32_to_cpu (csk->src_ip[1 ]); + l4kwqe2->src_ip_v6_3 =be32_to_cpu (csk->src_ip[2 ]); + l4kwqe2->src_ip_v6_4 =be32_to_cpu (csk->src_ip[3 ]); + l4kwqe2->dst_ip_v6_2 =be32_to_cpu (csk->dst_ip[1 ]); + l4kwqe2->dst_ip_v6_3 =be32_to_cpu (csk->dst_ip[2 ]); + l4kwqe2->dst_ip_v6_4 =be32_to_cpu (csk->dst_ip[3 ]); + l4kwqe3->mss = l4kwqe3->pmtu -sizeof (struct ipv6hdr ) - +sizeof (struct tcphdr ); + }else { + wqes[1 ] = (struct kwqe *) l4kwqe3; + l4kwqe3->mss = l4kwqe3->pmtu -sizeof (struct iphdr ) - +sizeof (struct tcphdr ); + } + + l4kwqe1->op_code =L4_KWQE_OPCODE_VALUE_CONNECT1 ; + l4kwqe1->flags = + (L4_LAYER_CODE <<L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT ) | +L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT ; + l4kwqe1->cid = csk->cid; + l4kwqe1->pg_cid = csk->pg_cid; + l4kwqe1->src_ip =be32_to_cpu (csk->src_ip[0 ]); + l4kwqe1->dst_ip =be32_to_cpu (csk->dst_ip[0 ]); + l4kwqe1->src_port =be16_to_cpu (csk->src_port); + l4kwqe1->dst_port =be16_to_cpu (csk->dst_port); +if (csk->tcp_flags &SK_TCP_NO_DELAY_ACK ) + tcp_flags |=L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK ; +if (csk->tcp_flags &SK_TCP_KEEP_ALIVE ) + tcp_flags |=L4_KWQ_CONNECT_REQ1_KEEP_ALIVE ; +if (csk->tcp_flags &SK_TCP_NAGLE ) + tcp_flags |=L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE ; +if (csk->tcp_flags &SK_TCP_TIMESTAMP ) + tcp_flags |=L4_KWQ_CONNECT_REQ1_TIME_STAMP ; +if (csk->tcp_flags &SK_TCP_SACK ) + tcp_flags |=L4_KWQ_CONNECT_REQ1_SACK ; +if (csk->tcp_flags &SK_TCP_SEG_SCALING ) + tcp_flags |=L4_KWQ_CONNECT_REQ1_SEG_SCALING ; + + l4kwqe1->tcp_flags = tcp_flags; + +return (dev->submit_kwqes (dev, wqes, num_wqes)); +} + +static int cnic_cm_close_req (struct cnic_sock *csk) +{ +struct cnic_dev *dev = csk->dev; +struct l4_kwq_close_req *l4kwqe; +struct kwqe *wqes[1 ]; + + l4kwqe = (struct l4_kwq_close_req *) &csk->kwqe2; +memset (l4kwqe,0 ,sizeof (*l4kwqe)); + wqes[0 ] = (struct kwqe *) l4kwqe; + + l4kwqe->op_code =L4_KWQE_OPCODE_VALUE_CLOSE ; + l4kwqe->flags =L4_LAYER_CODE <<L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT ; + l4kwqe->cid = csk->cid; + +return (dev->submit_kwqes (dev, wqes,1 )); +} + +static int cnic_cm_abort_req (struct cnic_sock *csk) +{ +struct cnic_dev *dev = csk->dev; +struct l4_kwq_reset_req *l4kwqe; +struct kwqe *wqes[1 ]; + + l4kwqe = (struct l4_kwq_reset_req *) &csk->kwqe2; +memset (l4kwqe,0 ,sizeof (*l4kwqe)); + wqes[0 ] = (struct kwqe *) l4kwqe; + + l4kwqe->op_code =L4_KWQE_OPCODE_VALUE_RESET ; + l4kwqe->flags =L4_LAYER_CODE <<L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT ; + l4kwqe->cid = csk->cid; + +return (dev->submit_kwqes (dev, wqes,1 )); +} + +static int cnic_cm_create (struct cnic_dev *dev,int ulp_type,u32 cid, +u32 l5_cid,struct cnic_sock **csk,void *context) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_sock *csk1; + +if (l5_cid >=MAX_CM_SK_TBL_SZ ) +return -EINVAL ; + + csk1 = &cp->csk_tbl[l5_cid]; +if (test_and_set_bit (SK_F_INUSE , &csk1->flags)) +return -EINVAL ; + + csk1->dev = dev; + csk1->cid = cid; + csk1->l5_cid = l5_cid; + csk1->ulp_type = ulp_type; + csk1->context = context; + + csk1->ka_timeout =DEF_KA_TIMEOUT ; + csk1->ka_interval =DEF_KA_INTERVAL ; + csk1->ka_max_probe_count =DEF_KA_MAX_PROBE_COUNT ; + csk1->tos =DEF_TOS ; + csk1->ttl =DEF_TTL ; + csk1->snd_seq_scale =DEF_SND_SEQ_SCALE ; + csk1->rcv_buf =DEF_RCV_BUF ; + csk1->snd_buf =DEF_SND_BUF ; + csk1->seed =DEF_SEED ; + + *csk = csk1; + +return 0 ; +} + +static void cnic_close_conn (struct cnic_sock *csk) +{ +clear_bit (SK_F_OFFLD_COMPLETE , &csk->flags); +cnic_cm_upload_pg (csk); +clear_bit (SK_F_PG_OFFLD_COMPLETE , &csk->flags); +clear_bit (SK_F_OFFLD_SCHED , &csk->flags); +} + +static void cnic_cm_cleanup (struct cnic_sock *csk) +{ +if (csk->dst) { +if (csk->dst->neighbour) +neigh_release (csk->dst->neighbour); +dst_release (csk->dst); + csk->dst =NULL ; + } +} + +static int cnic_cm_destroy (struct cnic_sock *csk) +{ +if (!cnic_in_use (csk)) +return -EINVAL ; + +clear_bit (SK_F_INUSE , &csk->flags); +smp_mb__after_clear_bit (); +while (atomic_read (&csk->ref_count) !=0 ) +msleep (1 ); +cnic_cm_cleanup (csk); + + csk->flags =0 ; +return 0 ; +} + +static inline u16 cnic_get_vlan (struct net_device *dev, +struct net_device **vlan_dev) +{ +if (dev->priv_flags &IFF_802_1Q_VLAN ) { + *vlan_dev =vlan_dev_info (dev)->real_dev; +return vlan_dev_info (dev)->vlan_id; + } + *vlan_dev = dev; +return 0 ; +} + +static int cnic_get_v4_route (struct sockaddr_in *dst_addr, +struct sockaddr_in *src_addr, +struct dst_entry **dst) +{ +struct flowi fl; +int err; +struct rtable *rt; + +memset (&fl,0 ,sizeof (fl)); + fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr; +if (src_addr) + fl.nl_u.ip4_u.saddr = src_addr->sin_addr.s_addr; + + err =ip_route_output_key (&init_net, &rt, &fl); +if (!err) + *dst = &rt->u.dst; +return err; +} + +static int cnic_get_v6_route (struct sockaddr_in6 *dst_addr, +struct sockaddr_in6 *src_addr, +struct dst_entry **dst) +{ +#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) +struct flowi fl; + +memset (&fl,0 ,sizeof (fl)); +ipv6_addr_copy (&fl.fl6_dst, &dst_addr->sin6_addr); +if (ipv6_addr_type (&fl.fl6_dst) &IPV6_ADDR_LINKLOCAL ) + fl.oif = dst_addr->sin6_scope_id; + +if (src_addr) +ipv6_addr_copy (&fl.fl6_src, &src_addr->sin6_addr); + + *dst =ip6_route_output (NULL , &fl); +if (*dst) +return 0 ; +#endif + +return -ENETUNREACH ; +} + +static struct cnic_dev *cnic_cm_select_dev (struct sockaddr_in *dst_addr, +int ulp_type) +{ +struct cnic_dev *dev =NULL ; +struct dst_entry *dst; +struct net_device *netdev =NULL ; +int err = -ENETUNREACH , found =0 ; + +if (dst_addr->sin_family ==AF_INET ) + err =cnic_get_v4_route (dst_addr,NULL , &dst); +else if (dst_addr->sin_family ==AF_INET6 ) { +struct sockaddr_in6 *dst_addr6 = + (struct sockaddr_in6 *) dst_addr; + + err =cnic_get_v6_route (dst_addr6,NULL , &dst); + }else +return NULL ; + +if (err) +return NULL ; + +if (!dst->dev) + goto done; + +cnic_get_vlan (dst->dev, &netdev); + +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +if (netdev == dev->netdev) { + found =1 ; +break ; + } + } +read_unlock (&cnic_dev_lock); + +done: +dst_release (dst); +if (!found) + dev =NULL ; +return dev; +} + +static int cnic_resolve_addr (struct cnic_sock *csk) +{ +struct neighbour *neigh = csk->dst->neighbour; +int err =0 ; + +if (neigh->nud_state &NUD_VALID ) { + err = -EINVAL ; +if (cnic_offld_prep (csk)) + err =cnic_cm_offload_pg (csk); + goto done; + } + +set_bit (SK_F_NDISC_WAITING , &csk->flags); +neigh_event_send (neigh,NULL ); +done: +return err; +} + +static int cnic_get_route (struct cnic_sock *csk,struct cnic_sockaddr *saddr) +{ +struct cnic_dev *dev = csk->dev; +int is_v6, err; +struct dst_entry *dst; +struct net_device *realdev; + +if (saddr->local.v6.sin6_family ==AF_INET6 && + saddr->remote.v6.sin6_family ==AF_INET6 ) + is_v6 =1 ; +else if (saddr->local.v4.sin_family ==AF_INET && + saddr->remote.v4.sin_family ==AF_INET ) + is_v6 =0 ; +else +return -EINVAL ; + +clear_bit (SK_F_IPV6 , &csk->flags); + +if (is_v6) { +set_bit (SK_F_IPV6 , &csk->flags); + err =cnic_get_v6_route (&saddr->remote.v6, + &saddr->local.v6, &dst); +if (err) +return err; + +if (!dst || dst->error || !dst->dev) + goto err_out; + +ipv6_get_saddr (dst, &saddr->remote.v6.sin6_addr, + &saddr->local.v6.sin6_addr); + +memcpy (&csk->src_ip[0 ], &saddr->local.v6.sin6_addr, +sizeof (struct in6_addr )); +memcpy (&csk->dst_ip[0 ], &saddr->remote.v6.sin6_addr, +sizeof (struct in6_addr )); + csk->src_port = saddr->local.v6.sin6_port; + csk->dst_port = saddr->remote.v6.sin6_port; + + }else { + err =cnic_get_v4_route (&saddr->remote.v4, &saddr->local.v4, + &dst); +if (err) +return err; + +if (!dst || dst->error || !dst->dev) + goto err_out; + + csk->dst_ip[0 ] = saddr->remote.v4.sin_addr.s_addr; + csk->src_ip[0 ] = saddr->local.v4.sin_addr.s_addr; + csk->src_port = saddr->local.v4.sin_port; + csk->dst_port = saddr->remote.v4.sin_port; + +if (csk->src_ip[0 ] ==0 ) { + csk->src_ip[0 ] = +inet_select_addr (dst->dev, csk->dst_ip[0 ], +RT_SCOPE_LINK ); + } + } + + csk->vlan_id =cnic_get_vlan (dst->dev, &realdev); +if (realdev != dev->netdev) + goto err_out; + + csk->dst = dst; +return 0 ; + +err_out: +dst_release (dst); +return -ENETUNREACH ; +} + +static int cnic_cm_connect (struct cnic_sock *csk,struct cnic_sockaddr *saddr) +{ +struct neighbour *neigh; +int err =0 ; + +if (!cnic_in_use (csk)) +return -EINVAL ; + +if (test_and_set_bit (SK_F_CONNECT_START , &csk->flags)) +return -EINVAL ; + +clear_bit (SK_F_OFFLD_SCHED , &csk->flags); + + err =cnic_get_route (csk, saddr); +if (err) + goto err_out; + + neigh = csk->dst->neighbour; +if (!neigh) + goto err_out; + +neigh_hold (neigh); + + err =cnic_resolve_addr (csk); +if (!err) +return 0 ; + +neigh_release (neigh); + +err_out: +if (csk->dst) { +dst_release (csk->dst); + csk->dst =NULL ; + } +clear_bit (SK_F_CONNECT_START , &csk->flags); +return err; +} + +static int cnic_cm_abort (struct cnic_sock *csk) +{ +if (!cnic_in_use (csk)) +return -EINVAL ; + +clear_bit (SK_F_NDISC_WAITING , &csk->flags); +clear_bit (SK_F_CONNECT_START , &csk->flags); +smp_mb__after_clear_bit (); +if (cnic_abort_prep (csk)) +return (cnic_cm_abort_req (csk)); + +/* Getting here means that we haven't started connect, or +* connect was not successful. +*/ + +if (test_bit (SK_F_PG_OFFLD_COMPLETE , &csk->flags)) +cnic_close_conn (csk); + +cnic_cm_cleanup (csk); +cnic_abort_done (csk); + +return 0 ; +} + +static int cnic_cm_close (struct cnic_sock *csk) +{ +if (!cnic_in_use (csk)) +return -EINVAL ; + +if (test_bit (SK_F_OFFLD_COMPLETE , &csk->flags)) +return (cnic_cm_close_req (csk)); + +return -EINVAL ; +} + +static void cnic_cm_upcall (struct cnic_local *cp,struct cnic_sock *csk, +u8 opcode) +{ +struct cnic_ulp_ops *ulp_ops; +int ulp_type = csk->ulp_type; + +rcu_read_lock (); + ulp_ops =rcu_dereference (cp->ulp_ops[ulp_type]); +if (ulp_ops) { +if (opcode ==L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE ) + ulp_ops->cm_connect_complete (csk); +else if (opcode ==L4_KCQE_OPCODE_VALUE_CLOSE_COMP ) + ulp_ops->cm_close_complete (csk); +else if (opcode ==L4_KCQE_OPCODE_VALUE_RESET_RECEIVED ) + ulp_ops->cm_remote_abort (csk); +else if (opcode ==L4_KCQE_OPCODE_VALUE_RESET_COMP ) + ulp_ops->cm_abort_complete (csk); +else if (opcode ==L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED ) + ulp_ops->cm_remote_close (csk); + } +rcu_read_unlock (); +} + +static int cnic_cm_set_pg (struct cnic_sock *csk) +{ +struct neighbour *neigh = csk->dst->neighbour; +int valid = neigh->nud_state &NUD_VALID ; + +if (!valid) { +if (test_and_clear_bit (SK_F_NDISC_WAITING , &csk->flags)) { +clear_bit (SK_F_CONNECT_START , &csk->flags); +cnic_cm_cleanup (csk); +return -ETIMEDOUT ; + } + } + +if (cnic_offld_prep (csk)) { +if (test_bit (SK_F_PG_OFFLD_COMPLETE , &csk->flags)) +cnic_cm_update_pg (csk); +else +cnic_cm_offload_pg (csk); + } +clear_bit (SK_F_NDISC_WAITING , &csk->flags); +return 0 ; +} + +static void cnic_cm_process_neigh (struct cnic_dev *dev,struct neighbour *neigh) +{ +struct cnic_local *cp = dev->cnic_priv; +int i; + +for (i =0 ; i <MAX_CM_SK_TBL_SZ ; i++) { +struct cnic_sock *csk; +int abort =0 ; + + csk = &cp->csk_tbl[i]; +csk_hold (csk); +if (cnic_in_use (csk) && csk->dst && + csk->dst->neighbour == neigh) { +if (cnic_cm_set_pg (csk)) + abort =1 ; + } +if (abort) +cnic_cm_upcall (cp, csk, +L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE ); +csk_put (csk); + } +neigh_release (neigh); +} + +static void cnic_cm_process_redirect (struct cnic_dev *dev, +struct cnic_redirect_entry *redir) +{ +struct cnic_local *cp = dev->cnic_priv; +int i; + +for (i =0 ; i <MAX_CM_SK_TBL_SZ ; i++) { +struct cnic_sock *csk; +int abort =0 ; + + csk = &cp->csk_tbl[i]; +csk_hold (csk); +if (cnic_in_use (csk) && + csk->dst == redir->old_dst) { + csk->dst = redir->new_dst; +dst_hold (csk->dst); +neigh_hold (csk->dst->neighbour); +if (redir->old_dst->neighbour); +neigh_release (redir->old_dst->neighbour); +dst_release (redir->old_dst); +if (cnic_cm_set_pg (csk)) + abort =1 ; + } +if (abort) +cnic_cm_upcall (cp, csk, +L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE ); +csk_put (csk); + } + +dst_release (redir->new_dst); +dst_release (redir->old_dst); +} + +static void cnic_cm_process_offld_pg (struct cnic_dev *dev,struct l4_kcq *kcqe) +{ +struct cnic_local *cp = dev->cnic_priv; +u32 l5_cid = kcqe->pg_host_opaque; +u8 opcode = kcqe->op_code; +struct cnic_sock *csk = &cp->csk_tbl[l5_cid]; + +if (!cnic_in_use (csk)) +return ; + + csk->pg_cid = kcqe->pg_cid; +if (opcode ==L4_KCQE_OPCODE_VALUE_UPDATE_PG ) { +clear_bit (SK_F_OFFLD_SCHED , &csk->flags); +return ; + } +set_bit (SK_F_PG_OFFLD_COMPLETE , &csk->flags); +cnic_cm_conn_req (csk); +} + +static void cnic_cm_process_kcqe (struct cnic_dev *dev,struct kcqe *kcqe) +{ +struct cnic_local *cp = dev->cnic_priv; +struct l4_kcq *l4kcqe = (struct l4_kcq *) kcqe; +u8 opcode = l4kcqe->op_code; +u32 l5_cid; +struct cnic_sock *csk; + +if (opcode ==L4_KCQE_OPCODE_VALUE_OFFLOAD_PG || + opcode ==L4_KCQE_OPCODE_VALUE_UPDATE_PG ) { +cnic_cm_process_offld_pg (dev, l4kcqe); +return ; + } + + l5_cid = l4kcqe->conn_id; +if (l5_cid >=MAX_CM_SK_TBL_SZ ) +return ; + + csk = &cp->csk_tbl[l5_cid]; + +if (!cnic_in_use (csk)) +return ; + +if (opcode ==L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE ) { + +if (l4kcqe->status ==0 ) +set_bit (SK_F_OFFLD_COMPLETE , &csk->flags); + +smp_mb__before_clear_bit (); +clear_bit (SK_F_OFFLD_SCHED , &csk->flags); +cnic_cm_upcall (cp, csk, opcode); + + }else if (opcode ==L4_KCQE_OPCODE_VALUE_CLOSE_COMP || + opcode ==L4_KCQE_OPCODE_VALUE_RESET_COMP || + opcode ==L4_KCQE_OPCODE_VALUE_RESET_RECEIVED ) { + +clear_bit (SK_F_CONNECT_START , &csk->flags); +cnic_close_conn (csk); +cnic_cm_cleanup (csk); +cnic_abort_done (csk); +cnic_cm_upcall (cp, csk, opcode); + + }else if (opcode ==L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED ) { +cnic_cm_upcall (cp, csk, opcode); + } +} + +static void cnic_cm_indicate_kcqe (void *data,struct kcqe *kcqe[],u32 num_cqe) +{ +struct cnic_dev *dev = data; +int i; +struct cnic_local *cp = dev->cnic_priv; + +for (i =0 ; i < num_cqe; i++) +cnic_queue_work (cp,WORK_TYPE_KCQE , kcqe[i]); + +tasklet_schedule (&cp->cnic_task); +} + +static void cnic_cm_indicate_event (void *data,unsigned long event) +{ +} + +static void cnic_cm_dummy (void *data) +{ +} + +static struct cnic_ulp_ops cm_ulp_ops = { + .cnic_start = cnic_cm_dummy, + .cnic_stop = cnic_cm_dummy, + .indicate_kcqes = cnic_cm_indicate_kcqe, + .indicate_netevent = cnic_cm_indicate_event, + .indicate_inetevent = cnic_cm_indicate_event, +}; + +static void cnic_task (unsigned long data) +{ +struct cnic_local *cp = (struct cnic_local *) data; +struct cnic_dev *dev = cp->dev; +u32 cons = cp->cnic_wr_cons; +u32 prod = cp->cnic_wr_prod; + +while (cons != prod) { +struct cnic_work_node *node; + + node = &cp->cnic_work_ring[cons]; +if (node->work_type ==WORK_TYPE_KCQE ) +cnic_cm_process_kcqe (dev, &node->work_data.kcqe); +else if (node->work_type ==WORK_TYPE_NEIGH_UPDATE ) +cnic_cm_process_neigh (dev, node->work_data.neigh); +else if (node->work_type ==WORK_TYPE_REDIRECT ) +cnic_cm_process_redirect (dev, + &node->work_data.cnic_redir); + cons++; + cons &=WORK_RING_SIZE_MASK ; + } + cp->cnic_wr_cons = cons; +} + +static void cnic_free_dev (struct cnic_dev *dev) +{ +int i =0 ; + +while ((atomic_read (&dev->ref_count) !=0 ) && i <10 ) { +msleep (100 ); + i++; + } +if (atomic_read (&dev->ref_count) !=0 ) + printk(KERN_ERR PFX "%s: Failed waiting for ref count to go" +" to zero.\n" , dev->netdev->name); + + printk(KERN_INFO PFX "Removed CNIC device: %s\n", dev->netdev->name); +dev_put (dev->netdev); +kfree (dev); +} + +static void cnic_cm_free_mem (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; + +kfree (cp->csk_tbl); + cp->csk_tbl =NULL ; +} + +static int cnic_cm_alloc_mem (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; + + cp->csk_tbl =kmalloc (sizeof (struct cnic_sock ) *MAX_CM_SK_TBL_SZ , +GFP_KERNEL ); +if (!cp->csk_tbl) +return -ENOMEM ; +memset (cp->csk_tbl,0 ,sizeof (struct cnic_sock ) *MAX_CM_SK_TBL_SZ ); +return 0 ; +} + +static void cnic_cm_stop_bnx2_hw (struct cnic_dev *dev) +{ +} + +static int cnic_cm_init_bnx2_hw (struct cnic_dev *dev) +{ +u32 seed; + +get_random_bytes (&seed,4 ); +cnic_bnx2_ctx_wr (dev,45 ,0 , seed); +return 0 ; +} + +static int cnic_cm_open (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int err; + + err =cnic_cm_alloc_mem (dev); +if (err) +return err; + + err = cp->start_cm (dev); + +if (err) + goto err_out; + +spin_lock_init (&cp->wr_lock); + +tasklet_init (&cp->cnic_task, &cnic_task, (unsigned long ) cp); + + cp->cm_nb.notifier_call = cnic_net_callback; +register_netevent_notifier (&cp->cm_nb);
drivers/net/cnic.c line 1763
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+ + dev->cm_create = cnic_cm_create; + dev->cm_destroy = cnic_cm_destroy; + dev->cm_connect = cnic_cm_connect; + dev->cm_abort = cnic_cm_abort; + dev->cm_close = cnic_cm_close; + dev->cm_select_dev = cnic_cm_select_dev; + + cp->ulp_handle[CNIC_ULP_L4 ] = dev; +rcu_assign_pointer (cp->ulp_ops[CNIC_ULP_L4 ], &cm_ulp_ops);
The cnic_lock is not held due to this being initialization time, and that no one else can be messing with this until initialization is complete?
Quoted 364 lines
drivers/net/cnic.c new file +364
-0+return 0 ; + +err_out: +cnic_cm_free_mem (dev); +return err; +} + +static int cnic_cm_shutdown (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int i; + + cp->stop_cm (dev); + +unregister_netevent_notifier (&cp->cm_nb); + +tasklet_disable (&cp->cnic_task); + +if (!cp->csk_tbl) +return 0 ; + +for (i =0 ; i <MAX_CM_SK_TBL_SZ ; i++) { +struct cnic_sock *csk = &cp->csk_tbl[i]; + +clear_bit (SK_F_INUSE , &csk->flags); +cnic_cm_cleanup (csk); + } +cnic_cm_free_mem (dev); + +return 0 ; +} + +static void cnic_init_context (struct cnic_dev *dev,u32 cid) +{ +u32 cid_addr; +int i; + + cid_addr =GET_CID_ADDR (cid); + +for (i =0 ; i <CTX_SIZE ; i +=4 ) +cnic_bnx2_ctx_wr (dev, cid_addr, i,0 ); +} + +static int cnic_setup_5709_context (struct cnic_dev *dev,int valid) +{ +struct cnic_local *cp = dev->cnic_priv; +int ret =0 , i; +u32 valid_bit = valid ?BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID :0 ; + +if (CHIP_NUM (cp) !=CHIP_NUM_5709 ) +return 0 ; + +for (i =0 ; i < cp->ctx_blks; i++) { +int j; +u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk; +u32 val; + +memset (cp->ctx_arr[i].ctx,0 ,BCM_PAGE_SIZE ); + +CNIC_WR (dev,BNX2_CTX_HOST_PAGE_TBL_DATA0 , + (cp->ctx_arr[i].mapping &0xffffffff ) | valid_bit); +CNIC_WR (dev,BNX2_CTX_HOST_PAGE_TBL_DATA1 , + (u64 ) cp->ctx_arr[i].mapping >>32 ); +CNIC_WR (dev,BNX2_CTX_HOST_PAGE_TBL_CTRL , idx | +BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ ); +for (j =0 ; j <10 ; j++) { + + val =CNIC_RD (dev,BNX2_CTX_HOST_PAGE_TBL_CTRL ); +if (!(val &BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ )) +break ; +udelay (5 ); + } +if (val &BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ ) { + ret = -EBUSY ; +break ; + } + } +return ret; +} + +static void cnic_free_irq (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; + +if (ethdev->drv_state &CNIC_DRV_STATE_USING_MSIX ) { + cp->disable_int_sync (dev); +tasklet_disable (&cp->cnic_irq_task); +free_irq (ethdev->irq_arr[0 ].vector, dev); + } +} + +static int cnic_init_bnx2_irq (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; + +if (ethdev->drv_state &CNIC_DRV_STATE_USING_MSIX ) { +int err, i =0 ; +int sblk_num = cp->status_blk_num; +u32 base = ((sblk_num -1 ) *BNX2_HC_SB_CONFIG_SIZE ) + +BNX2_HC_SB_CONFIG_1 ; + +CNIC_WR (dev, base,BNX2_HC_SB_CONFIG_1_ONE_SHOT ); + +CNIC_WR (dev, base +BNX2_HC_COMP_PROD_TRIP_OFF , (2 <<16 ) |8 ); +CNIC_WR (dev, base +BNX2_HC_COM_TICKS_OFF , (64 <<16 ) |220 ); +CNIC_WR (dev, base +BNX2_HC_CMD_TICKS_OFF , (64 <<16 ) |220 ); + + cp->bnx2_status_blk = cp->status_blk; + cp->last_status_idx = cp->bnx2_status_blk->status_idx; +tasklet_init (&cp->cnic_irq_task, &cnic_service_bnx2_msix, + (unsigned long ) dev); + err =request_irq (ethdev->irq_arr[0 ].vector, cnic_irq,0 , +"cnic" , dev); +if (err) { +tasklet_disable (&cp->cnic_irq_task); +return err; + } +while (cp->bnx2_status_blk->status_completion_producer_index && + i <10 ) { +CNIC_WR (dev,BNX2_HC_COALESCE_NOW , +1 << (11 + sblk_num)); +udelay (10 ); + i++; +barrier (); + } +if (cp->bnx2_status_blk->status_completion_producer_index) { +cnic_free_irq (dev); + goto failed; + } + + }else { +struct status_block *sblk = cp->status_blk; +u32 hc_cmd =CNIC_RD (dev,BNX2_HC_COMMAND ); +int i =0 ; + +while (sblk->status_completion_producer_index && i <10 ) { +CNIC_WR (dev,BNX2_HC_COMMAND , + hc_cmd |BNX2_HC_COMMAND_COAL_NOW_WO_INT ); +udelay (10 ); + i++; +barrier (); + } +if (sblk->status_completion_producer_index) + goto failed; + + } +return 0 ; + +failed: + printk(KERN_ERR PFX "%s: " "KCQ index not resetting to 0.\n", + dev->netdev->name); +return -EBUSY ; +} + +static void cnic_enable_bnx2_int (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; + +if (!(ethdev->drv_state &CNIC_DRV_STATE_USING_MSIX )) +return ; + +CNIC_WR (dev,BNX2_PCICFG_INT_ACK_CMD ,BNX2_CNIC_INT_NUM | +BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx); +} + +static void cnic_disable_bnx2_int_sync (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; + +if (!(ethdev->drv_state &CNIC_DRV_STATE_USING_MSIX )) +return ; + +CNIC_WR (dev,BNX2_PCICFG_INT_ACK_CMD ,BNX2_CNIC_INT_NUM | +BNX2_PCICFG_INT_ACK_CMD_MASK_INT ); +CNIC_RD (dev,BNX2_PCICFG_INT_ACK_CMD ); +synchronize_irq (ethdev->irq_arr[0 ].vector); +} + +static int cnic_start_bnx2_hw (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; +u32 val; +int err; + + val =CNIC_RD (dev,BNX2_MQ_CONFIG ); + val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE ; +if (BCM_PAGE_BITS >12 ) + val |= (12 -8 ) <<4 ; +else + val |= (BCM_PAGE_BITS -8 ) <<4 ; + +CNIC_WR (dev,BNX2_MQ_CONFIG , val); + +CNIC_WR (dev,BNX2_HC_COMP_PROD_TRIP , (2 <<16 ) |8 ); +CNIC_WR (dev,BNX2_HC_COM_TICKS , (64 <<16 ) |220 ); +CNIC_WR (dev,BNX2_HC_CMD_TICKS , (64 <<16 ) |220 ); + + err =cnic_setup_5709_context (dev,1 ); +if (err) +return err; + +cnic_init_context (dev,KWQ_CID ); +cnic_init_context (dev,KCQ_CID ); + + cp->kwq_cid_addr =GET_CID_ADDR (KWQ_CID ); + cp->kwq_io_addr =MB_GET_CID_ADDR (KWQ_CID ) +L5_KRNLQ_HOST_QIDX ; + + cp->max_kwq_idx =MAX_KWQ_IDX ; + cp->kwq_prod_idx =0 ; + cp->kwq_con_idx =0 ; + cp->cnic_local_flags |=CNIC_LCL_FL_KWQ_INIT ; + +/* Initialize the kernel work queue context. */ + val =KRNLQ_TYPE_TYPE_KRNLQ |KRNLQ_SIZE_TYPE_SIZE | + (BCM_PAGE_BITS -8 ) |KRNLQ_FLAGS_QE_SELF_SEQ ; +cnic_bnx2_ctx_wr (dev, cp->kwq_cid_addr,L5_KRNLQ_TYPE , val); + + val = (BCM_PAGE_SIZE /sizeof (struct kwqe ) -1 ) <<16 ; +cnic_bnx2_ctx_wr (dev, cp->kwq_cid_addr,L5_KRNLQ_QE_SELF_SEQ_MAX , val); + + val = ((BCM_PAGE_SIZE /sizeof (struct kwqe )) <<16 ) |KWQ_PAGE_CNT ; +cnic_bnx2_ctx_wr (dev, cp->kwq_cid_addr,L5_KRNLQ_PGTBL_NPAGES , val); + + val = (u32) ((u64 ) cp->kwq_info.pgtbl_map >>32 ); +cnic_bnx2_ctx_wr (dev, cp->kwq_cid_addr,L5_KRNLQ_PGTBL_HADDR_HI , val); + + val = (u32 ) cp->kwq_info.pgtbl_map; +cnic_bnx2_ctx_wr (dev, cp->kwq_cid_addr,L5_KRNLQ_PGTBL_HADDR_LO , val); + + cp->kcq_cid_addr =GET_CID_ADDR (KCQ_CID ); + cp->kcq_io_addr =MB_GET_CID_ADDR (KCQ_CID ) +L5_KRNLQ_HOST_QIDX ; + + cp->kcq_prod_idx =0 ; + +/* Initialize the kernel complete queue context. */ + val =KRNLQ_TYPE_TYPE_KRNLQ |KRNLQ_SIZE_TYPE_SIZE | + (BCM_PAGE_BITS -8 ) |KRNLQ_FLAGS_QE_SELF_SEQ ; +cnic_bnx2_ctx_wr (dev, cp->kcq_cid_addr,L5_KRNLQ_TYPE , val); + + val = (BCM_PAGE_SIZE /sizeof (struct kcqe ) -1 ) <<16 ; +cnic_bnx2_ctx_wr (dev, cp->kcq_cid_addr,L5_KRNLQ_QE_SELF_SEQ_MAX , val); + + val = ((BCM_PAGE_SIZE /sizeof (struct kcqe )) <<16 ) |KCQ_PAGE_CNT ; +cnic_bnx2_ctx_wr (dev, cp->kcq_cid_addr,L5_KRNLQ_PGTBL_NPAGES , val); + + val = (u32) ((u64 ) cp->kcq_info.pgtbl_map >>32 ); +cnic_bnx2_ctx_wr (dev, cp->kcq_cid_addr,L5_KRNLQ_PGTBL_HADDR_HI , val); + + val = (u32 ) cp->kcq_info.pgtbl_map; +cnic_bnx2_ctx_wr (dev, cp->kcq_cid_addr,L5_KRNLQ_PGTBL_HADDR_LO , val); + +if (ethdev->drv_state &CNIC_DRV_STATE_USING_MSIX ) { +u32 sb_id = cp->status_blk_num; +u32 sb =KRNLQ_STATUSB_NUM_CNIC_MSIX (sb_id); + +cnic_bnx2_ctx_wr (dev, cp->kwq_cid_addr,L5_KRNLQ_HOST_QIDX , sb); +cnic_bnx2_ctx_wr (dev, cp->kcq_cid_addr,L5_KRNLQ_HOST_QIDX , sb); + } + +/* Enable Commnad Scheduler notification when we write to the +* host producer index of the kernel contexts. */ +CNIC_WR (dev,BNX2_MQ_KNL_CMD_MASK1 ,2 ); + +/* Enable Command Scheduler notification when we write to either +* the Send Queue or Receive Queue producer indexes of the kernel +* bypass contexts. */ +CNIC_WR (dev,BNX2_MQ_KNL_BYP_CMD_MASK1 ,7 ); +CNIC_WR (dev,BNX2_MQ_KNL_BYP_WRITE_MASK1 ,7 ); + +/* Notify COM when the driver post an application buffer. */ +CNIC_WR (dev,BNX2_MQ_KNL_RX_V2P_MASK2 ,0x2000 ); + +/* Set the CP and COM doorbells. These two processors polls the +* doorbell for a non zero value before running. This must be done +* after setting up the kernel queue contexts. */ +cnic_bnx2_reg_wr_ind (dev,BNX2_CP_SCRATCH +0x20 ,1 ); +cnic_bnx2_reg_wr_ind (dev,BNX2_COM_SCRATCH +0x20 ,1 ); + + err =cnic_init_bnx2_irq (dev); +if (err) { + printk(KERN_ERR PFX "%s: cnic_init_irq failed\n", + dev->netdev->name); +cnic_bnx2_reg_wr_ind (dev,BNX2_CP_SCRATCH +0x20 ,0 ); +cnic_bnx2_reg_wr_ind (dev,BNX2_COM_SCRATCH +0x20 ,0 ); +return err; + } + +return 0 ; +} + +static int cnic_start_hw (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; +int err; + +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) +return -EALREADY ; + + err = ethdev->drv_register_cnic (dev->netdev, cp->cnic_ops, dev); +if (err) { + printk(KERN_ERR PFX "%s: register_cnic failed\n", + dev->netdev->name); +return err; + } + + dev->regview = ethdev->io_base; + cp->chip_id = ethdev->chip_id; +pci_dev_get (dev->pcidev); + cp->func =PCI_FUNC (dev->pcidev->devfn); + cp->status_blk = ethdev->irq_arr[0 ].status_blk; + cp->status_blk_num = ethdev->irq_arr[0 ].status_blk_num; + + err = cp->alloc_resc (dev); +if (err) { + printk(KERN_ERR PFX "%s: allocate resource failure\n", + dev->netdev->name); + goto err1; + } + + err = cp->start_hw (dev); +if (err) + goto err1; + + err =cnic_cm_open (dev); +if (err) + goto err1; + +set_bit (CNIC_F_CNIC_UP , &dev->flags); + + cp->enable_int (dev); + +return 0 ; + +err1: + ethdev->drv_unregister_cnic (dev->netdev); + cp->free_resc (dev); +pci_dev_put (dev->pcidev); +return err; +} + +static void cnic_stop_bnx2_hw (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; + +cnic_disable_bnx2_int_sync (dev); + +cnic_bnx2_reg_wr_ind (dev,BNX2_CP_SCRATCH +0x20 ,0 ); +cnic_bnx2_reg_wr_ind (dev,BNX2_COM_SCRATCH +0x20 ,0 ); + +cnic_init_context (dev,KWQ_CID ); +cnic_init_context (dev,KCQ_CID ); + +cnic_setup_5709_context (dev,0 ); +cnic_free_irq (dev); + + ethdev->drv_unregister_cnic (dev->netdev); +
drivers/net/cnic.c line 2137
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+cnic_free_resc (dev); +} + +static void cnic_stop_hw (struct cnic_dev *dev) +{ +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) { +struct cnic_local *cp = dev->cnic_priv; + +clear_bit (CNIC_F_CNIC_UP , &dev->flags); +rcu_assign_pointer (cp->ulp_ops[CNIC_ULP_L4 ],NULL );
Given that the cnic_lock does not appear to be held, what prevents other CPUs from manipulating cp->ulp_ops[CNIC_ULP_L4] concurrently with this function?
Quoted 1,392 lines
drivers/net/cnic.c new file +302
-0+synchronize_rcu (); +cnic_cm_shutdown (dev); + cp->stop_hw (dev); +pci_dev_put (dev->pcidev); + } +} + +static struct cnic_dev *alloc_cnic (struct net_device *dev) +{ +struct cnic_dev *cdev; +struct cnic_local *cp; +int alloc_size; + + alloc_size =sizeof (struct cnic_dev ) +sizeof (struct cnic_local ); + + cdev =kmalloc (alloc_size ,GFP_KERNEL ); +if (cdev ==NULL ) { + printk(KERN_ERR PFX "%s: allocate dev struct failure\n", + dev->name); +return NULL ; + } +memset (cdev,0 , alloc_size); + + cdev->netdev = dev; + cdev->cnic_priv = (char *)cdev +sizeof (struct cnic_dev ); + cdev->register_device = cnic_register_device; + cdev->unregister_device = cnic_unregister_device; + cp = cdev->cnic_priv; + cp->dev = cdev; + +spin_lock_init (&cp->cnic_ulp_lock); + printk(KERN_INFO PFX "Added CNIC device: %s\n", dev->name); + +return cdev; +} + +static struct cnic_dev *init_bnx2_cnic (struct net_device *dev) +{ +struct pci_dev *pdev; +struct cnic_dev *cdev; +struct cnic_local *cp; +struct cnic_eth_dev *ethdev; + + ethdev =bnx2_cnic_probe (dev); +if (!ethdev) +return NULL ; + + pdev = ethdev->pdev; +if (!pdev) +return NULL ; + +dev_hold (dev); +pci_dev_get (pdev); +if (pdev->device ==PCI_DEVICE_ID_NX2_5709 || + pdev->device ==PCI_DEVICE_ID_NX2_5709S ) { +u8 rev; + +pci_read_config_byte (pdev,PCI_REVISION_ID , &rev); +if (rev <0x10 ) { +pci_dev_put (pdev); +dev_put (dev); +return NULL ; + } + } +pci_dev_put (pdev); + + cdev =alloc_cnic (dev); +if (cdev ==NULL ) { +dev_put (dev); +return NULL ; + } + +set_bit (CNIC_F_BNX2_CLASS , &cdev->flags); + cdev->submit_kwqes = cnic_submit_bnx2_kwqes; + + cp = cdev->cnic_priv; + cp->ethdev = ethdev; + cdev->pcidev = pdev; + + cp->cnic_ops = &cnic_bnx2_ops; + cp->start_hw = cnic_start_bnx2_hw; + cp->stop_hw = cnic_stop_bnx2_hw; + cp->setup_pgtbl = cnic_setup_page_tbl; + cp->alloc_resc = cnic_alloc_bnx2_resc; + cp->free_resc = cnic_free_resc; + cp->start_cm = cnic_cm_init_bnx2_hw; + cp->stop_cm = cnic_cm_stop_bnx2_hw; + cp->enable_int = cnic_enable_bnx2_int; + cp->disable_int_sync = cnic_disable_bnx2_int_sync; +return cdev; +} + +static struct cnic_dev *is_cnic_dev (struct net_device *dev) +{ +struct ethtool_drvinfo drvinfo; +struct cnic_dev *cdev =NULL ; + +if (dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) { +memset (&drvinfo,0 ,sizeof (drvinfo)); + dev->ethtool_ops->get_drvinfo (dev, &drvinfo); + +if (!strcmp (drvinfo.driver,"bnx2" )) + cdev =init_bnx2_cnic (dev); +if (cdev) { +write_lock (&cnic_dev_lock); +list_add (&cdev->list, &cnic_dev_list); +write_unlock (&cnic_dev_lock); + } + } +return cdev; +} + +/** +* IP event handler +*/ +static int cnic_ip_event (struct notifier_block *this,unsigned long event, +void *ptr) +{ +struct in_ifaddr *ifa = (struct in_ifaddr *) ptr; +struct net_device *netdev = (struct net_device *) ifa->ifa_dev->dev; +struct cnic_dev *dev; +int if_type; +u32 my_dev =0 ; + +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +if (netdev == dev->netdev) { + my_dev =1 ; +cnic_hold (dev); +break ; + } + } +read_unlock (&cnic_dev_lock); + +if (my_dev) { +struct cnic_local *cp = dev->cnic_priv; + +rcu_read_lock (); +for (if_type =0 ; if_type <MAX_CNIC_ULP_TYPE ; if_type++) { +struct cnic_ulp_ops *ulp_ops; + + ulp_ops =rcu_dereference (cp->ulp_ops[if_type]); +if (ulp_ops) { +void *ctx = cp->ulp_handle[if_type]; + + ulp_ops->indicate_inetevent (ctx, event); + } + } +rcu_read_unlock (); + +cnic_put (dev); + } + +return NOTIFY_DONE ; +} + +/** +* netdev event handler +*/ +static int cnic_netdev_event (struct notifier_block *this,unsigned long event, +void *ptr) +{ +struct net_device *netdev = ptr; +struct cnic_dev *dev; +int if_type; +u32 my_dev =0 ; + +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +if (netdev == dev->netdev) { + my_dev =1 ; +cnic_hold (dev); +break ; + } + } +read_unlock (&cnic_dev_lock); + +if (!my_dev && event ==NETDEV_REGISTER ) { +/* Check for the hot-plug device */ + dev =is_cnic_dev (netdev); +if (dev) { + my_dev =1 ; +cnic_hold (dev); + } + } +if (my_dev) { +struct cnic_local *cp = dev->cnic_priv; + +if (event ==NETDEV_REGISTER ) +cnic_ulp_init (dev); +else if (event ==NETDEV_UNREGISTER ) +cnic_ulp_exit (dev); +else if (event ==NETDEV_UP ) { +mutex_lock (&cnic_lock); +set_bit (CNIC_F_IF_UP , &dev->flags); +if (dev->use_count) { +if (!cnic_start_hw (dev)) +cnic_ulp_start (dev); + } +mutex_unlock (&cnic_lock); + } + +rcu_read_lock (); +for (if_type =0 ; if_type <MAX_CNIC_ULP_TYPE ; if_type++) { +struct cnic_ulp_ops *ulp_ops; +void *ctx; + + ulp_ops =rcu_dereference (cp->ulp_ops[if_type]); +if (!ulp_ops) +continue ; + + ctx = cp->ulp_handle[if_type]; + + ulp_ops->indicate_netevent (ctx, event); + } +rcu_read_unlock (); + +if (event ==NETDEV_GOING_DOWN ) { +mutex_lock (&cnic_lock); +clear_bit (CNIC_F_IF_UP , &dev->flags); +set_bit (CNIC_F_IF_GOING_DOWN , &dev->flags); +cnic_ulp_stop (dev); +cnic_stop_hw (dev); +mutex_unlock (&cnic_lock); + }else if (event ==NETDEV_DOWN ) { +mutex_lock (&cnic_lock); +clear_bit (CNIC_F_IF_GOING_DOWN , &dev->flags); +mutex_unlock (&cnic_lock); + }else if (event ==NETDEV_UNREGISTER ) { +write_lock (&cnic_dev_lock); +list_del_init (&dev->list); +write_unlock (&cnic_dev_lock); + +cnic_put (dev); +cnic_free_dev (dev); + goto done; + } +cnic_put (dev); + } +done: +return NOTIFY_DONE ; +} + +static struct notifier_block cnic_ip_notifier = { + cnic_ip_event, +0 +}; + +static struct notifier_block cnic_netdev_notifier = { + cnic_netdev_event, +0 +}; + +static void cnic_release (void ) +{ +struct cnic_dev *dev; + +while (!list_empty (&cnic_dev_list)) { + dev = list_entry(cnic_dev_list.next, struct cnic_dev, list); +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) +cnic_stop_hw (dev); + +list_del_init (&dev->list); +cnic_free_dev (dev); + } +} + +static int __init cnic_init (void ) +{ +int rc =0 ; +struct net_device *dev; + +printk (KERN_INFO "%s" , version); + +rtnl_lock (); +/* Find Teton devices */ +for_each_netdev (&init_net, dev) +is_cnic_dev (dev); + +rtnl_unlock (); + + rc =register_inetaddr_notifier (&cnic_ip_notifier); +if (rc) +cnic_release (); + rc =register_netdevice_notifier (&cnic_netdev_notifier); +if (rc) { +unregister_inetaddr_notifier (&cnic_ip_notifier); +cnic_release (); + } +return rc; +} + +static void __exit cnic_exit(void) +{ +unregister_inetaddr_notifier (&cnic_ip_notifier); +unregister_netdevice_notifier (&cnic_netdev_notifier); +cnic_release (); +return ; +} + +module_init (cnic_init); +module_exit (cnic_exit);drivers/net/cnic.h new file +221
-0@@ -0,0 +1,221 @@ +/* cnic.h: Broadcom CNIC core network driver. +* +* Copyright (c) 2006 Broadcom Corporation +* +* 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: John(Zongxi) Chen ([email protected]) +*/ + + +#ifndef CNIC_H +#define CNIC_H + +#if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN) +#error "Missing either LITTLE_ENDIAN or BIG_ENDIAN definition." +#endif + +#define KWQ_PAGE_CNT 4 +#define KCQ_PAGE_CNT 16 + +#define KWQ_CID 24 +#define KCQ_CID 25 + +/* +* krnlq_context definition +*/ +#define L5_KRNLQ_FLAGS 0x00000000 +#define L5_KRNLQ_SIZE 0x00000000 +#define L5_KRNLQ_TYPE 0x00000000 +#define KRNLQ_FLAGS_PG_SZ (0xf<<0) +#define KRNLQ_FLAGS_PG_SZ_256 (0<<0) +#define KRNLQ_FLAGS_PG_SZ_512 (1<<0) +#define KRNLQ_FLAGS_PG_SZ_1K (2<<0) +#define KRNLQ_FLAGS_PG_SZ_2K (3<<0) +#define KRNLQ_FLAGS_PG_SZ_4K (4<<0) +#define KRNLQ_FLAGS_PG_SZ_8K (5<<0) +#define KRNLQ_FLAGS_PG_SZ_16K (6<<0) +#define KRNLQ_FLAGS_PG_SZ_32K (7<<0) +#define KRNLQ_FLAGS_PG_SZ_64K (8<<0) +#define KRNLQ_FLAGS_PG_SZ_128K (9<<0) +#define KRNLQ_FLAGS_PG_SZ_256K (10<<0) +#define KRNLQ_FLAGS_PG_SZ_512K (11<<0) +#define KRNLQ_FLAGS_PG_SZ_1M (12<<0) +#define KRNLQ_FLAGS_PG_SZ_2M (13<<0) +#define KRNLQ_FLAGS_QE_SELF_SEQ (1<<15) +#define KRNLQ_SIZE_TYPE_SIZE ((((0x28 + 0x1f) & ~0x1f) / 0x20) << 16) +#define KRNLQ_TYPE_TYPE (0xf<<28) +#define KRNLQ_TYPE_TYPE_EMPTY (0<<28) +#define KRNLQ_TYPE_TYPE_KRNLQ (6<<28) + +#define L5_KRNLQ_HOST_QIDX 0x00000004 +#define KRNLQ_STATUSB_NUM_SHIFT 16 +#define KRNLQ_STATUSB_NUM_CNIC_MSIX (sb_id) (((sb_id) + 7) << \ + KRNLQ_STATUSB_NUM_SHIFT) +#define L5_KRNLQ_HOST_FW_QIDX 0x00000008 +#define L5_KRNLQ_NX_QE_SELF_SEQ 0x0000000c +#define L5_KRNLQ_QE_SELF_SEQ_MAX 0x0000000c +#define L5_KRNLQ_NX_QE_HADDR_HI 0x00000010 +#define L5_KRNLQ_NX_QE_HADDR_LO 0x00000014 +#define L5_KRNLQ_PGTBL_PGIDX 0x00000018 +#define L5_KRNLQ_NX_PG_QIDX 0x00000018 +#define L5_KRNLQ_PGTBL_NPAGES 0x0000001c +#define L5_KRNLQ_QIDX_INCR 0x0000001c +#define L5_KRNLQ_PGTBL_HADDR_HI 0x00000020 +#define L5_KRNLQ_PGTBL_HADDR_LO 0x00000024 + +#define BNX2_PG_CTX_MAP 0x1a0034 +#define BNX2_ISCSI_CTX_MAP 0x1a0074 + +struct cnic_redirect_entry { +struct dst_entry *old_dst; +struct dst_entry *new_dst; +}; + +struct cnic_work_node { +u32 work_type; +#define WORK_TYPE_KCQE 1 +#define WORK_TYPE_NEIGH_UPDATE 2 +#define WORK_TYPE_REDIRECT 3 +union { +struct kcqe kcqe; +struct neighbour *neigh; +struct cnic_redirect_entry cnic_redir; + } work_data; +}; + +#define WORK_RING_SIZE 128 +#define WORK_RING_SIZE_MASK 127 +#define MAX_CM_SK_TBL_SZ 128 +#define MAX_COMPLETED_KCQE 64 + +#define KWQE_CNT (BCM_PAGE_SIZE / sizeof(struct kwqe)) +#define KCQE_CNT (BCM_PAGE_SIZE / sizeof(struct kcqe)) +#define MAX_KWQE_CNT (KWQE_CNT - 1) +#define MAX_KCQE_CNT (KCQE_CNT - 1) + +#define MAX_KWQ_IDX ((KWQ_PAGE_CNT * KWQE_CNT) - 1) +#define MAX_KCQ_IDX ((KCQ_PAGE_CNT * KCQE_CNT) - 1) + +#define KWQ_PG (x) (((x) & ~MAX_KWQE_CNT) >> (BCM_PAGE_BITS - 5)) +#define KWQ_IDX (x) ((x) & MAX_KWQE_CNT) + +#define KCQ_PG (x) (((x) & ~MAX_KCQE_CNT) >> (BCM_PAGE_BITS - 5)) +#define KCQ_IDX (x) ((x) & MAX_KCQE_CNT) + +#define DEF_IPID_COUNT 0xc001 + +#define DEF_KA_TIMEOUT 10000 +#define DEF_KA_INTERVAL 300000 +#define DEF_KA_MAX_PROBE_COUNT 3 +#define DEF_TOS 0 +#define DEF_TTL 0xfe +#define DEF_SND_SEQ_SCALE 0 +#define DEF_RCV_BUF 0xffff +#define DEF_SND_BUF 0xffff +#define DEF_SEED 0 + +struct cnic_ctx { +u32 cid; +void *ctx; +dma_addr_t mapping; +}; + +#define BNX2_MAX_CID 0x2000 + +struct cnic_dma { +int num_pages; +void **pg_arr; +dma_addr_t *pg_map_arr; +int pgtbl_size; +u32 *pgtbl; +dma_addr_t pgtbl_map; +}; + +struct cnic_local { + +spinlock_t cnic_ulp_lock; +void *ulp_handle[MAX_CNIC_ULP_TYPE ]; +unsigned long ulp_flags[MAX_CNIC_ULP_TYPE ]; +#define ULP_F_INIT 0 +#define ULP_F_START 1 +struct cnic_ulp_ops *ulp_ops[MAX_CNIC_ULP_TYPE ]; + +/* protected by ulp_lock */ +u32 cnic_local_flags; +#define CNIC_LCL_FL_KWQ_INIT 0x00000001 + +struct cnic_dev *dev; + +struct cnic_eth_dev *ethdev; + +u32 kwq_cid_addr; +u32 kcq_cid_addr; + +struct cnic_dma kwq_info; +struct kwqe **kwq; + +u16 max_kwq_idx; + +u16 kwq_prod_idx; +u32 kwq_io_addr; + +u16 kwq_con_idx; + +struct cnic_dma kcq_info; +struct kcqe **kcq; + +u16 kcq_prod_idx; +u32 kcq_io_addr; + +void *status_blk; +struct status_block_msix *bnx2_status_blk; + +u32 status_blk_num; +u32 last_status_idx; +struct tasklet_struct cnic_irq_task; + +struct kcqe *completed_kcq[MAX_COMPLETED_KCQE ]; + +struct cnic_sock *csk_tbl; + +struct notifier_block cm_nb; + +struct cnic_work_node cnic_work_ring[WORK_RING_SIZE ]; +int cnic_wr_cons; +int cnic_wr_prod; +spinlock_t wr_lock; + +struct tasklet_struct cnic_task; + +struct cnic_ctx *ctx_arr; +int ctx_blks; +int ctx_blk_size; +int cids_per_blk; + +u32 chip_id; +int func; + +struct cnic_ops *cnic_ops; +int (*start_hw)(struct cnic_dev *); +void (*stop_hw)(struct cnic_dev *); +void (*setup_pgtbl)(struct cnic_dev *, +struct cnic_dma *); +int (*alloc_resc)(struct cnic_dev *); +void (*free_resc)(struct cnic_dev *); +int (*start_cm)(struct cnic_dev *); +void (*stop_cm)(struct cnic_dev *); +void (*enable_int)(struct cnic_dev *); +void (*disable_int_sync)(struct cnic_dev *); +void (*ack_int)(struct cnic_dev *); +}; + +struct bnx2x_bd_chain_next { +u32 addr_lo; +u32 addr_hi; +u8 reserved[8 ]; +}; + +#endif drivers/net/cnic_defs.h new file +553
-0@@ -0,0 +1,553 @@ +#ifndef __57XX_L5CM_HSI_LINUX_LE__ +#define __57XX_L5CM_HSI_LINUX_LE__ + +/* KWQ (kernel work queue) request op codes */ +#define L4_KWQE_OPCODE_VALUE_CONNECT1 (50) +#define L4_KWQE_OPCODE_VALUE_CONNECT2 (51) +#define L4_KWQE_OPCODE_VALUE_CONNECT3 (52) +#define L4_KWQE_OPCODE_VALUE_RESET (53) +#define L4_KWQE_OPCODE_VALUE_CLOSE (54) +#define L4_KWQE_OPCODE_VALUE_UPDATE_SECRET (60) +#define L4_KWQE_OPCODE_VALUE_INIT_ULP (61) + +#define L4_KWQE_OPCODE_VALUE_OFFLOAD_PG (1) +#define L4_KWQE_OPCODE_VALUE_UPDATE_PG (9) +#define L4_KWQE_OPCODE_VALUE_UPLOAD_PG (14) + +/* KCQ (kernel completion queue) response op codes */ +#define L4_KCQE_OPCODE_VALUE_CLOSE_COMP (53) +#define L4_KCQE_OPCODE_VALUE_RESET_COMP (54) +#define L4_KCQE_OPCODE_VALUE_FW_TCP_UPDATE (55) +#define L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE (56) +#define L4_KCQE_OPCODE_VALUE_RESET_RECEIVED (57) +#define L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED (58) +#define L4_KCQE_OPCODE_VALUE_INIT_ULP (61) + +#define L4_KCQE_OPCODE_VALUE_OFFLOAD_PG (1) +#define L4_KCQE_OPCODE_VALUE_UPDATE_PG (9) +#define L4_KCQE_OPCODE_VALUE_UPLOAD_PG (14) + +/* KCQ (kernel completion queue) completion status */ +#define L4_KCQE_COMPLETION_STATUS_SUCCESS (0) +#define L4_KCQE_COMPLETION_STATUS_TIMEOUT (0x93) + +#define L4_LAYER_CODE (4) + +/* + * L4 KCQ CQE + */ +struct l4_kcq { + u32 cid; + u32 pg_cid; + u32 conn_id; + u32 pg_host_opaque; +#if defined(__BIG_ENDIAN) + u16 status; + u16 reserved1; +#elif defined(__LITTLE_ENDIAN) + u16 reserved1; + u16 status; +#endif + u32 reserved2[2]; +#if defined(__BIG_ENDIAN) + u8 flags; +#define L4_KCQ_RESERVED3 (0xF<<0) +#define L4_KCQ_RESERVED3_SHIFT 0 +#define L4_KCQ_LAYER_CODE (0x7<<4) +#define L4_KCQ_LAYER_CODE_SHIFT 4 +#define L4_KCQ_RESERVED4 (0x1<<7) +#define L4_KCQ_RESERVED4_SHIFT 7 + u8 op_code; + u16 qe_self_seq; +#elif defined(__LITTLE_ENDIAN) + u16 qe_self_seq; + u8 op_code; + u8 flags; +#define L4_KCQ_RESERVED3 (0xF<<0) +#define L4_KCQ_RESERVED3_SHIFT 0 +#define L4_KCQ_LAYER_CODE (0x7<<4) +#define L4_KCQ_LAYER_CODE_SHIFT 4 +#define L4_KCQ_RESERVED4 (0x1<<7) +#define L4_KCQ_RESERVED4_SHIFT 7 +#endif +}; + + +/* + * L4 KCQ CQE PG upload + */ +struct l4_kcq_upload_pg { + u32 pg_cid; +#if defined(__BIG_ENDIAN) + u16 pg_status; + u16 pg_ipid_count; +#elif defined(__LITTLE_ENDIAN) + u16 pg_ipid_count; + u16 pg_status; +#endif + u32 reserved1[5]; +#if defined(__BIG_ENDIAN) + u8 flags; +#define L4_KCQ_UPLOAD_PG_RESERVED3 (0xF<<0) +#define L4_KCQ_UPLOAD_PG_RESERVED3_SHIFT 0 +#define L4_KCQ_UPLOAD_PG_LAYER_CODE (0x7<<4) +#define L4_KCQ_UPLOAD_PG_LAYER_CODE_SHIFT 4 +#define L4_KCQ_UPLOAD_PG_RESERVED4 (0x1<<7) +#define L4_KCQ_UPLOAD_PG_RESERVED4_SHIFT 7 + u8 op_code; + u16 qe_self_seq; +#elif defined(__LITTLE_ENDIAN) + u16 qe_self_seq; + u8 op_code; + u8 flags; +#define L4_KCQ_UPLOAD_PG_RESERVED3 (0xF<<0) +#define L4_KCQ_UPLOAD_PG_RESERVED3_SHIFT 0 +#define L4_KCQ_UPLOAD_PG_LAYER_CODE (0x7<<4) +#define L4_KCQ_UPLOAD_PG_LAYER_CODE_SHIFT 4 +#define L4_KCQ_UPLOAD_PG_RESERVED4 (0x1<<7) +#define L4_KCQ_UPLOAD_PG_RESERVED4_SHIFT 7 +#endif +}; + + +/* + * Gracefully close the connection request + */ +struct l4_kwq_close_req { +#if defined(__BIG_ENDIAN) + u8 flags; +#define L4_KWQ_CLOSE_REQ_RESERVED1 (0xF<<0) +#define L4_KWQ_CLOSE_REQ_RESERVED1_SHIFT 0 +#define L4_KWQ_CLOSE_REQ_LAYER_CODE (0x7<<4) +#define L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CLOSE_REQ_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CLOSE_REQ_LINKED_WITH_NEXT_SHIFT 7 + u8 op_code; + u16 reserved0; +#elif defined(__LITTLE_ENDIAN) + u16 reserved0; + u8 op_code; + u8 flags; +#define L4_KWQ_CLOSE_REQ_RESERVED1 (0xF<<0) +#define L4_KWQ_CLOSE_REQ_RESERVED1_SHIFT 0 +#define L4_KWQ_CLOSE_REQ_LAYER_CODE (0x7<<4) +#define L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CLOSE_REQ_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CLOSE_REQ_LINKED_WITH_NEXT_SHIFT 7 +#endif + u32 cid; + u32 reserved2[6]; +}; + + +/* + * The first request to be passed in order to establish connection + */ +struct l4_kwq_connect_req1 { +#if defined(__BIG_ENDIAN) + u8 flags; +#define L4_KWQ_CONNECT_REQ1_RESERVED1 (0xF<<0) +#define L4_KWQ_CONNECT_REQ1_RESERVED1_SHIFT 0 +#define L4_KWQ_CONNECT_REQ1_LAYER_CODE (0x7<<4) +#define L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CONNECT_REQ1_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CONNECT_REQ1_LINKED_WITH_NEXT_SHIFT 7 + u8 op_code; + u8 reserved0; + u8 conn_flags; +#define L4_KWQ_CONNECT_REQ1_IS_PG_HOST_OPAQUE (0x1<<0) +#define L4_KWQ_CONNECT_REQ1_IS_PG_HOST_OPAQUE_SHIFT 0 +#define L4_KWQ_CONNECT_REQ1_IP_V6 (0x1<<1) +#define L4_KWQ_CONNECT_REQ1_IP_V6_SHIFT 1 +#define L4_KWQ_CONNECT_REQ1_PASSIVE_FLAG (0x1<<2) +#define L4_KWQ_CONNECT_REQ1_PASSIVE_FLAG_SHIFT 2 +#define L4_KWQ_CONNECT_REQ1_RSRV (0x1F<<3) +#define L4_KWQ_CONNECT_REQ1_RSRV_SHIFT 3 +#elif defined(__LITTLE_ENDIAN) + u8 conn_flags; +#define L4_KWQ_CONNECT_REQ1_IS_PG_HOST_OPAQUE (0x1<<0) +#define L4_KWQ_CONNECT_REQ1_IS_PG_HOST_OPAQUE_SHIFT 0 +#define L4_KWQ_CONNECT_REQ1_IP_V6 (0x1<<1) +#define L4_KWQ_CONNECT_REQ1_IP_V6_SHIFT 1 +#define L4_KWQ_CONNECT_REQ1_PASSIVE_FLAG (0x1<<2) +#define L4_KWQ_CONNECT_REQ1_PASSIVE_FLAG_SHIFT 2 +#define L4_KWQ_CONNECT_REQ1_RSRV (0x1F<<3) +#define L4_KWQ_CONNECT_REQ1_RSRV_SHIFT 3 + u8 reserved0; + u8 op_code; + u8 flags; +#define L4_KWQ_CONNECT_REQ1_RESERVED1 (0xF<<0) +#define L4_KWQ_CONNECT_REQ1_RESERVED1_SHIFT 0 +#define L4_KWQ_CONNECT_REQ1_LAYER_CODE (0x7<<4) +#define L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CONNECT_REQ1_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CONNECT_REQ1_LINKED_WITH_NEXT_SHIFT 7 +#endif + u32 cid; + u32 pg_cid; + u32 src_ip; + u32 dst_ip; +#if defined(__BIG_ENDIAN) + u16 dst_port; + u16 src_port; +#elif defined(__LITTLE_ENDIAN) + u16 src_port; + u16 dst_port; +#endif +#if defined(__BIG_ENDIAN) + u8 rsrv1[3]; + u8 tcp_flags; +#define L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK (0x1<<0) +#define L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK_SHIFT 0 +#define L4_KWQ_CONNECT_REQ1_KEEP_ALIVE (0x1<<1) +#define L4_KWQ_CONNECT_REQ1_KEEP_ALIVE_SHIFT 1 +#define L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE (0x1<<2) +#define L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE_SHIFT 2 +#define L4_KWQ_CONNECT_REQ1_TIME_STAMP (0x1<<3) +#define L4_KWQ_CONNECT_REQ1_TIME_STAMP_SHIFT 3 +#define L4_KWQ_CONNECT_REQ1_SACK (0x1<<4) +#define L4_KWQ_CONNECT_REQ1_SACK_SHIFT 4 +#define L4_KWQ_CONNECT_REQ1_SEG_SCALING (0x1<<5) +#define L4_KWQ_CONNECT_REQ1_SEG_SCALING_SHIFT 5 +#define L4_KWQ_CONNECT_REQ1_RESERVED2 (0x3<<6) +#define L4_KWQ_CONNECT_REQ1_RESERVED2_SHIFT 6 +#elif defined(__LITTLE_ENDIAN) + u8 tcp_flags; +#define L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK (0x1<<0) +#define L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK_SHIFT 0 +#define L4_KWQ_CONNECT_REQ1_KEEP_ALIVE (0x1<<1) +#define L4_KWQ_CONNECT_REQ1_KEEP_ALIVE_SHIFT 1 +#define L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE (0x1<<2) +#define L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE_SHIFT 2 +#define L4_KWQ_CONNECT_REQ1_TIME_STAMP (0x1<<3) +#define L4_KWQ_CONNECT_REQ1_TIME_STAMP_SHIFT 3 +#define L4_KWQ_CONNECT_REQ1_SACK (0x1<<4) +#define L4_KWQ_CONNECT_REQ1_SACK_SHIFT 4 +#define L4_KWQ_CONNECT_REQ1_SEG_SCALING (0x1<<5) +#define L4_KWQ_CONNECT_REQ1_SEG_SCALING_SHIFT 5 +#define L4_KWQ_CONNECT_REQ1_RESERVED2 (0x3<<6) +#define L4_KWQ_CONNECT_REQ1_RESERVED2_SHIFT 6 + u8 rsrv1[3]; +#endif + u32 rsrv2; +}; + + +/* + * The second ( optional )request to be passed in order to establish connection - for IPv6 only + */ +struct l4_kwq_connect_req2 { +#if defined(__BIG_ENDIAN) + u8 flags; +#define L4_KWQ_CONNECT_REQ2_RESERVED1 (0xF<<0) +#define L4_KWQ_CONNECT_REQ2_RESERVED1_SHIFT 0 +#define L4_KWQ_CONNECT_REQ2_LAYER_CODE (0x7<<4) +#define L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT_SHIFT 7 + u8 op_code; + u8 reserved0; + u8 rsrv; +#elif defined(__LITTLE_ENDIAN) + u8 rsrv; + u8 reserved0; + u8 op_code; + u8 flags; +#define L4_KWQ_CONNECT_REQ2_RESERVED1 (0xF<<0) +#define L4_KWQ_CONNECT_REQ2_RESERVED1_SHIFT 0 +#define L4_KWQ_CONNECT_REQ2_LAYER_CODE (0x7<<4) +#define L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT_SHIFT 7 +#endif + u32 reserved2; + u32 src_ip_v6_2; + u32 src_ip_v6_3; + u32 src_ip_v6_4; + u32 dst_ip_v6_2; + u32 dst_ip_v6_3; + u32 dst_ip_v6_4; +}; + + +/* + * The third ( and last )request to be passed in order to establish connection + */ +struct l4_kwq_connect_req3 { +#if defined(__BIG_ENDIAN) + u8 flags; +#define L4_KWQ_CONNECT_REQ3_RESERVED1 (0xF<<0) +#define L4_KWQ_CONNECT_REQ3_RESERVED1_SHIFT 0 +#define L4_KWQ_CONNECT_REQ3_LAYER_CODE (0x7<<4) +#define L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT_SHIFT 7 + u8 op_code; + u16 reserved0; +#elif defined(__LITTLE_ENDIAN) + u16 reserved0; + u8 op_code; + u8 flags; +#define L4_KWQ_CONNECT_REQ3_RESERVED1 (0xF<<0) +#define L4_KWQ_CONNECT_REQ3_RESERVED1_SHIFT 0 +#define L4_KWQ_CONNECT_REQ3_LAYER_CODE (0x7<<4) +#define L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT 4 +#define L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT (0x1<<7) +#define L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT_SHIFT 7 +#endif + u32 ka_timeout; + u32 ka_interval ; +#if defined(__BIG_ENDIAN) + u8 snd_seq_scale; + u8 ttl; + u8 tos; + u8 ka_max_probe_count; +#elif defined(__LITTLE_ENDIAN) + u8 ka_max_probe_count; + u8 tos; + u8 ttl; + u8 snd_seq_scale; +#endif +#if defined(__BIG_ENDIAN) + u16 pmtu; + u16 mss; +#elif defined(__LITTLE_ENDIAN) + u16 mss; + u16 pmtu; +#endifLines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 8 lines
1.5.5.GIT -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Part of the diff is not shown here. View the raw message.
Re: [PATCH 2/3] cnic: Add CNIC driver.
Quoted 62 lines · Paul E. McKenney
Quoted 17 lines
drivers/net/cnic.c new file +17
-0+ +int cnic_register_driver (int ulp_type,struct cnic_ulp_ops *ulp_ops) +{ +struct cnic_dev *dev; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_register_driver: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (cnic_ulp_tbl[ulp_type]) { + printk(KERN_ERR PFX "cnic_register_driver: Type %d has already " + "been registered\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EBUSY ; + }drivers/net/cnic.c line 192
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+ +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +clear_bit (ULP_F_INIT , &cp->ulp_flags[ulp_type]); + } +read_unlock (&cnic_dev_lock); + +rcu_assign_pointer (cnic_ulp_tbl[ulp_type], ulp_ops);OK, protected by
cnic_lock.Quoted 32 lines
drivers/net/cnic.c new file +32
-0+mutex_unlock (&cnic_lock); + +/* Prevent race conditions with netdev_event */ +rtnl_lock (); +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +if (!test_and_set_bit (ULP_F_INIT , &cp->ulp_flags[ulp_type])) + ulp_ops->cnic_init (dev); + } +read_unlock (&cnic_dev_lock); +rtnl_unlock (); + +return 0 ; +} + +int cnic_unregister_driver (int ulp_type) +{ +struct cnic_dev *dev; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_unregister_driver: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (!cnic_ulp_tbl[ulp_type]) { + printk(KERN_ERR PFX "cnic_unregister_driver: Type %d has not " + "been registered\n", ulp_type); + goto out_unlock; + }
Quoted 8 lines
drivers/net/cnic.c line 229
Quoted 5 lines
drivers/net/cnic.c new file +5
-0+read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +if (rcu_dereference (cp->ulp_ops[ulp_type])) {The
rcu_dereference()is redundant because we holdcnic_lock. (Which is OK, just wanting to make sure I understand the code.)
Yes, I wanted to access these RCU protected pointers in a uniform way.
Quoted 24 lines
drivers/net/cnic.c line 238
Quoted 10 lines
drivers/net/cnic.c new file +9
-0+ printk(KERN_ERR PFX "cnic_unregister_driver: Type %d " + "still has devices registered\n", ulp_type); +read_unlock (&cnic_dev_lock); + goto out_unlock; + } + } +read_unlock (&cnic_dev_lock); + +rcu_assign_pointer (cnic_ulp_tbl[ulp_type],NULL );OK, protected by
cnic_lock.drivers/net/cnic.c line 241
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+ +mutex_unlock (&cnic_lock); +synchronize_rcu ();The caller is responsible for freeing up cnic_ulp_tbl[ulp_type]? If so, the caller had better have kept a pointer to it...
But the caller would need to snapshot the pointer before the
cnic_lockwas acquired, which means that some other pointer might in fact be in place by the time this function returns.
Quoted 6 lines
So, is this data element statically allocated? Or is there some other trick being used?
Or is the whole point of this code simply to ensure that any calls to the old cnic_ulp_tbl[ulp_type] functions have completed before this function returns? If so, please add a comment to this effect.
Yes, once again to ensure that any calls have completed before continuing. I will document the use of RCU more in the next version.
Quoted 115 lines
Quoted 23 lines
drivers/net/cnic.c new file +22
-0+return 0 ; + +out_unlock: +mutex_unlock (&cnic_lock); +return -EINVAL ; +} + +EXPORT_SYMBOL (cnic_register_driver); +EXPORT_SYMBOL (cnic_unregister_driver); + +static int cnic_start_hw (struct cnic_dev *); +static void cnic_stop_hw (struct cnic_dev *); + +static int cnic_register_device (struct cnic_dev *dev,int ulp_type, +void *ulp_ctx) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_ulp_ops *ulp_ops; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_register_device: Bad type %d\n", + ulp_type);drivers/net/cnic.c line 273
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (cnic_ulp_tbl[ulp_type] ==NULL ) { + printk(KERN_ERR PFX "cnic_register_device: Driver with type %d " + "has not been registered\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EAGAIN ; + } +if (rcu_dereference (cp->ulp_ops[ulp_type])) {Again, the
rcu_dereference()is redundant due to thecnic_lockbeing held, and again, this is OK, just checking to make sure I understand it.Quoted 4 lines
drivers/net/cnic.c new file +4
-0+ printk(KERN_ERR PFX "cnic_register_device: Type %d has already " + "been registered to this device\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EBUSY ;drivers/net/cnic.c line 287
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+ } +if (!try_module_get (cnic_ulp_tbl[ulp_type]->owner)) { +mutex_unlock (&cnic_lock); +return -EBUSY ; + } + +clear_bit (ULP_F_START , &cp->ulp_flags[ulp_type]); + cp->ulp_handle[ulp_type] = ulp_ctx; + ulp_ops = cnic_ulp_tbl[ulp_type]; +rcu_assign_pointer (cp->ulp_ops[ulp_type], ulp_ops);Good, protected by
cnic_lock.Quoted 25 lines
drivers/net/cnic.c new file +25
-0+cnic_hold (dev); +if (!dev->use_count) { +if (!test_bit (CNIC_F_IF_GOING_DOWN , &dev->flags)) { +if (dev->netdev->flags &IFF_UP ) +set_bit (CNIC_F_IF_UP , &dev->flags); + } + } + dev->use_count++; + +if (dev->use_count ==1 ) { +if (test_bit (CNIC_F_IF_UP , &dev->flags)) +cnic_start_hw (dev); + } + +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) +if (!test_and_set_bit (ULP_F_START , &cp->ulp_flags[ulp_type])) + ulp_ops->cnic_start (cp->ulp_handle[ulp_type]); + +mutex_unlock (&cnic_lock); + +return 0 ; + +} + +static int cnic_unregister_device (struct cnic_dev *dev,int ulp_type)drivers/net/cnic.c line 322
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+{ +struct cnic_local *cp = dev->cnic_priv; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_unregister_device: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (rcu_dereference (cp->ulp_ops[ulp_type])) {Ditto...
drivers/net/cnic.c line 325
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+ dev->use_count--; +module_put (cp->ulp_ops[ulp_type]->owner); +rcu_assign_pointer (cp->ulp_ops[ulp_type],NULL );OK,
cnic_lockheld...drivers/net/cnic.c line 337
Quoted 12 lines
drivers/net/cnic.c new file +12
-0+if (dev->use_count ==0 ) +cnic_stop_hw (dev); +cnic_put (dev); + }else { + printk(KERN_ERR PFX "cnic_unregister_device: device not " + "registered to this ulp type %d\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EINVAL ; + } +mutex_unlock (&cnic_lock); + +synchronize_rcu ();Caller is again responsible for freeing up cp->ulp_ops[ulp_type]? If so, the caller had better have obtained a reference to it beforehand. But it might have changed in the meantime. So, how is this freed?
Quoted 4 lines
Or is this statically allocated with the only purpose of the
synchronize_rcu()being to ensure that calls though the old ops vector have completed before this function returns? If so, please add a comment to this effect.
Yes same as above.
Quoted 27 lines
Quoted 27 lines
drivers/net/cnic.c new file +27
-0+ +static int cnic_cm_open (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int err; + + err =cnic_cm_alloc_mem (dev); +if (err) +return err; + + err = cp->start_cm (dev); + +if (err) + goto err_out; + +spin_lock_init (&cp->wr_lock); + +tasklet_init (&cp->cnic_task, &cnic_task, (unsigned long ) cp); + + cp->cm_nb.notifier_call = cnic_net_callback; +register_netevent_notifier (&cp->cm_nb); + + dev->cm_create = cnic_cm_create; + dev->cm_destroy = cnic_cm_destroy; + dev->cm_connect = cnic_cm_connect; + dev->cm_abort = cnic_cm_abort; + dev->cm_close = cnic_cm_close;
Quoted 8 lines
drivers/net/cnic.c line 1763
Quoted 4 lines
drivers/net/cnic.c new file +4
-0+ dev->cm_select_dev = cnic_cm_select_dev; + + cp->ulp_handle[CNIC_ULP_L4 ] = dev; +rcu_assign_pointer (cp->ulp_ops[CNIC_ULP_L4 ], &cm_ulp_ops);The
cnic_lockis not held due to this being initialization time, and that no one else can be messing with this until initialization is complete?
Yes, this is actually the CNIC driver registering with itself. Only the CNIC driver will be using the CNIC_ULP_L4 ID.
Quoted 33 lines
Quoted 33 lines
drivers/net/cnic.c new file +31
-0+return 0 ; + +err_out: +cnic_cm_free_mem (dev); +return err; +} + +static void cnic_stop_bnx2_hw (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; + +cnic_disable_bnx2_int_sync (dev); + +cnic_bnx2_reg_wr_ind (dev,BNX2_CP_SCRATCH +0x20 ,0 ); +cnic_bnx2_reg_wr_ind (dev,BNX2_COM_SCRATCH +0x20 ,0 ); + +cnic_init_context (dev,KWQ_CID ); +cnic_init_context (dev,KCQ_CID ); + +cnic_setup_5709_context (dev,0 ); +cnic_free_irq (dev); + + ethdev->drv_unregister_cnic (dev->netdev); + +cnic_free_resc (dev); +} + +static void cnic_stop_hw (struct cnic_dev *dev) +{ +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) {
Quoted 9 lines
drivers/net/cnic.c line 2137
Quoted 4 lines
drivers/net/cnic.c new file +4
-0+struct cnic_local *cp = dev->cnic_priv; + +clear_bit (CNIC_F_CNIC_UP , &dev->flags); +rcu_assign_pointer (cp->ulp_ops[CNIC_ULP_L4 ],NULL );Given that the
cnic_lockdoes not appear to be held, what prevents other CPUs from manipulating cp->ulp_ops[CNIC_ULP_L4] concurrently with this function?
This is again the CNIC driver unregistering with itself. Only the CNIC driver will be using the CNIC_ULP_L4 ID.
Quoted 7 lines
Quoted 7 lines
drivers/net/cnic.c new file +7
-0+synchronize_rcu (); +cnic_cm_shutdown (dev); + cp->stop_hw (dev); +pci_dev_put (dev->pcidev); + } +} +
Re: [PATCH 2/3] cnic: Add CNIC driver.
Quoted 73 lines · Michael Chan
Quoted 62 lines · Paul E. McKenney
Quoted 17 lines
drivers/net/cnic.c new file +17
-0+ +int cnic_register_driver (int ulp_type,struct cnic_ulp_ops *ulp_ops) +{ +struct cnic_dev *dev; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_register_driver: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (cnic_ulp_tbl[ulp_type]) { + printk(KERN_ERR PFX "cnic_register_driver: Type %d has already " + "been registered\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EBUSY ; + }drivers/net/cnic.c line 192
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+ +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +clear_bit (ULP_F_INIT , &cp->ulp_flags[ulp_type]); + } +read_unlock (&cnic_dev_lock); + +rcu_assign_pointer (cnic_ulp_tbl[ulp_type], ulp_ops);OK, protected by
cnic_lock.Quoted 32 lines
drivers/net/cnic.c new file +32
-0+mutex_unlock (&cnic_lock); + +/* Prevent race conditions with netdev_event */ +rtnl_lock (); +read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +if (!test_and_set_bit (ULP_F_INIT , &cp->ulp_flags[ulp_type])) + ulp_ops->cnic_init (dev); + } +read_unlock (&cnic_dev_lock); +rtnl_unlock (); + +return 0 ; +} + +int cnic_unregister_driver (int ulp_type) +{ +struct cnic_dev *dev; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_unregister_driver: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (!cnic_ulp_tbl[ulp_type]) { + printk(KERN_ERR PFX "cnic_unregister_driver: Type %d has not " + "been registered\n", ulp_type); + goto out_unlock; + }Quoted 8 lines
drivers/net/cnic.c line 229
Quoted 5 lines
drivers/net/cnic.c new file +5
-0+read_lock (&cnic_dev_lock); +list_for_each_entry (dev, &cnic_dev_list, list) { +struct cnic_local *cp = dev->cnic_priv; + +if (rcu_dereference (cp->ulp_ops[ulp_type])) {The
rcu_dereference()is redundant because we holdcnic_lock. (Which is OK, just wanting to make sure I understand the code.)
Quoted 1 line
Yes, I wanted to access these RCU protected pointers in a uniform way.
Very good.
Quoted 27 lines
Quoted 27 lines
drivers/net/cnic.c line 238
Quoted 10 lines
drivers/net/cnic.c new file +9
-0+ printk(KERN_ERR PFX "cnic_unregister_driver: Type %d " + "still has devices registered\n", ulp_type); +read_unlock (&cnic_dev_lock); + goto out_unlock; + } + } +read_unlock (&cnic_dev_lock); + +rcu_assign_pointer (cnic_ulp_tbl[ulp_type],NULL );OK, protected by
cnic_lock.drivers/net/cnic.c line 241
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+ +mutex_unlock (&cnic_lock); +synchronize_rcu ();The caller is responsible for freeing up cnic_ulp_tbl[ulp_type]? If so, the caller had better have kept a pointer to it...
But the caller would need to snapshot the pointer before the
cnic_lockwas acquired, which means that some other pointer might in fact be in place by the time this function returns.So, is this data element statically allocated? Or is there some other trick being used?
Quoted 6 lines
Quoted 3 lines
Or is the whole point of this code simply to ensure that any calls to the old cnic_ulp_tbl[ulp_type] functions have completed before this function returns? If so, please add a comment to this effect.
Yes, once again to ensure that any calls have completed before continuing. I will document the use of RCU more in the next version.
Very good!
Quoted 114 lines
Quoted 114 lines
Quoted 22 lines
drivers/net/cnic.c new file +22
-0+return 0 ; + +out_unlock: +mutex_unlock (&cnic_lock); +return -EINVAL ; +} + +EXPORT_SYMBOL (cnic_register_driver); +EXPORT_SYMBOL (cnic_unregister_driver); + +static int cnic_start_hw (struct cnic_dev *); +static void cnic_stop_hw (struct cnic_dev *); + +static int cnic_register_device (struct cnic_dev *dev,int ulp_type, +void *ulp_ctx) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_ulp_ops *ulp_ops; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_register_device: Bad type %d\n", + ulp_type);drivers/net/cnic.c line 273
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (cnic_ulp_tbl[ulp_type] ==NULL ) { + printk(KERN_ERR PFX "cnic_register_device: Driver with type %d " + "has not been registered\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EAGAIN ; + } +if (rcu_dereference (cp->ulp_ops[ulp_type])) {Again, the
rcu_dereference()is redundant due to thecnic_lockbeing held, and again, this is OK, just checking to make sure I understand it.Quoted 4 lines
drivers/net/cnic.c new file +4
-0+ printk(KERN_ERR PFX "cnic_register_device: Type %d has already " + "been registered to this device\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EBUSY ;drivers/net/cnic.c line 287
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+ } +if (!try_module_get (cnic_ulp_tbl[ulp_type]->owner)) { +mutex_unlock (&cnic_lock); +return -EBUSY ; + } + +clear_bit (ULP_F_START , &cp->ulp_flags[ulp_type]); + cp->ulp_handle[ulp_type] = ulp_ctx; + ulp_ops = cnic_ulp_tbl[ulp_type]; +rcu_assign_pointer (cp->ulp_ops[ulp_type], ulp_ops);Good, protected by
cnic_lock.Quoted 25 lines
drivers/net/cnic.c new file +25
-0+cnic_hold (dev); +if (!dev->use_count) { +if (!test_bit (CNIC_F_IF_GOING_DOWN , &dev->flags)) { +if (dev->netdev->flags &IFF_UP ) +set_bit (CNIC_F_IF_UP , &dev->flags); + } + } + dev->use_count++; + +if (dev->use_count ==1 ) { +if (test_bit (CNIC_F_IF_UP , &dev->flags)) +cnic_start_hw (dev); + } + +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) +if (!test_and_set_bit (ULP_F_START , &cp->ulp_flags[ulp_type])) + ulp_ops->cnic_start (cp->ulp_handle[ulp_type]); + +mutex_unlock (&cnic_lock); + +return 0 ; + +} + +static int cnic_unregister_device (struct cnic_dev *dev,int ulp_type)drivers/net/cnic.c line 322
Quoted 10 lines
drivers/net/cnic.c new file +10
-0+{ +struct cnic_local *cp = dev->cnic_priv; + +if (ulp_type >=MAX_CNIC_ULP_TYPE ) { + printk(KERN_ERR PFX "cnic_unregister_device: Bad type %d\n", + ulp_type); +return -EINVAL ; + } +mutex_lock (&cnic_lock); +if (rcu_dereference (cp->ulp_ops[ulp_type])) {Ditto...
drivers/net/cnic.c line 325
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+ dev->use_count--; +module_put (cp->ulp_ops[ulp_type]->owner); +rcu_assign_pointer (cp->ulp_ops[ulp_type],NULL );OK,
cnic_lockheld...drivers/net/cnic.c line 337
Quoted 12 lines
drivers/net/cnic.c new file +12
-0+if (dev->use_count ==0 ) +cnic_stop_hw (dev); +cnic_put (dev); + }else { + printk(KERN_ERR PFX "cnic_unregister_device: device not " + "registered to this ulp type %d\n", ulp_type); +mutex_unlock (&cnic_lock); +return -EINVAL ; + } +mutex_unlock (&cnic_lock); + +synchronize_rcu ();Caller is again responsible for freeing up cp->ulp_ops[ulp_type]? If so, the caller had better have obtained a reference to it beforehand. But it might have changed in the meantime. So, how is this freed?
Quoted 6 lines
Quoted 4 lines
Or is this statically allocated with the only purpose of the
synchronize_rcu()being to ensure that calls though the old ops vector have completed before this function returns? If so, please add a comment to this effect.Yes same as above.
Good!
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
drivers/net/cnic.c new file +27
-0+ +static int cnic_cm_open (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +int err; + + err =cnic_cm_alloc_mem (dev); +if (err) +return err; + + err = cp->start_cm (dev); + +if (err) + goto err_out; + +spin_lock_init (&cp->wr_lock); + +tasklet_init (&cp->cnic_task, &cnic_task, (unsigned long ) cp); + + cp->cm_nb.notifier_call = cnic_net_callback; +register_netevent_notifier (&cp->cm_nb); + + dev->cm_create = cnic_cm_create; + dev->cm_destroy = cnic_cm_destroy; + dev->cm_connect = cnic_cm_connect; + dev->cm_abort = cnic_cm_abort; + dev->cm_close = cnic_cm_close;Quoted 8 lines
drivers/net/cnic.c line 1763
Quoted 4 lines
drivers/net/cnic.c new file +4
-0+ dev->cm_select_dev = cnic_cm_select_dev; + + cp->ulp_handle[CNIC_ULP_L4 ] = dev; +rcu_assign_pointer (cp->ulp_ops[CNIC_ULP_L4 ], &cm_ulp_ops);The
cnic_lockis not held due to this being initialization time, and that no one else can be messing with this until initialization is complete?
Quoted 2 lines
Yes, this is actually the CNIC driver registering with itself. Only the CNIC driver will be using the
CNIC_ULP_L4ID.
Very good! I will leave it to you as to whether you should add a comment to this effect.
Quoted 43 lines
Quoted 33 lines
Quoted 33 lines
drivers/net/cnic.c new file +31
-0+return 0 ; + +err_out: +cnic_cm_free_mem (dev); +return err; +} + +static void cnic_stop_bnx2_hw (struct cnic_dev *dev) +{ +struct cnic_local *cp = dev->cnic_priv; +struct cnic_eth_dev *ethdev = cp->ethdev; + +cnic_disable_bnx2_int_sync (dev); + +cnic_bnx2_reg_wr_ind (dev,BNX2_CP_SCRATCH +0x20 ,0 ); +cnic_bnx2_reg_wr_ind (dev,BNX2_COM_SCRATCH +0x20 ,0 ); + +cnic_init_context (dev,KWQ_CID ); +cnic_init_context (dev,KCQ_CID ); + +cnic_setup_5709_context (dev,0 ); +cnic_free_irq (dev); + + ethdev->drv_unregister_cnic (dev->netdev); + +cnic_free_resc (dev); +} + +static void cnic_stop_hw (struct cnic_dev *dev) +{ +if (test_bit (CNIC_F_CNIC_UP , &dev->flags)) {Quoted 9 lines
drivers/net/cnic.c line 2137
Quoted 4 lines
drivers/net/cnic.c new file +4
-0+struct cnic_local *cp = dev->cnic_priv; + +clear_bit (CNIC_F_CNIC_UP , &dev->flags); +rcu_assign_pointer (cp->ulp_ops[CNIC_ULP_L4 ],NULL );Given that the
cnic_lockdoes not appear to be held, what prevents other CPUs from manipulating cp->ulp_ops[CNIC_ULP_L4] concurrently with this function?
Quoted 2 lines
This is again the CNIC driver unregistering with itself. Only the CNIC driver will be using the
CNIC_ULP_L4ID.
Very good -- could you please add a comment to this effect?
Thanx, Paul
Quoted 14 lines
Quoted 7 lines
drivers/net/cnic.c line 2144
Quoted 7 lines
drivers/net/cnic.c new file +7
-0+synchronize_rcu (); +cnic_cm_shutdown (dev); + cp->stop_hw (dev); +pci_dev_put (dev->pcidev); + } +} +--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] cnic: Add CNIC driver.
In reply to Michael Chandrivers/net/Kconfig config BNX2 · line 2250
Quoted 3 lines
drivers/net/Kconfig +3
-0+config CNIC + tristate "Broadcom CNIC support" + depends on BNX2
I suspect you'll need a "depends on INET" somewhere (probably here, but maybe only for the iSCSI part).
- R.
Re: [PATCH 2/3] cnic: Add CNIC driver.
In reply to Michael Chandrivers/net/cnic.c line 654
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+/* Tell compiler that status_blk fields can change. */ +barrier (); +if (status_idx != sblk->status_idx) {
Is a compiler barrier sufficient here? It seems an out-of-order CPU could still mess things up, so an rmb() or smp_rmb() would be required.
Re: [PATCH 2/3] cnic: Add CNIC driver.
Quoted 7 lines · Roland Dreier
drivers/net/cnic.c line 654
Quoted 3 lines
drivers/net/cnic.c new file +3
-0+/* Tell compiler that status_blk fields can change. */ +barrier (); +if (status_idx != sblk->status_idx) {Is a compiler barrier sufficient here? It seems an out-of-order CPU could still mess things up, so an
rmb()orsmp_rmb()would be required.
The purpose of this compiler barrier is to make sure that the compiled code will get the sblk->status_idx from memory which may change if the chip DMAs a new status_idx.
This code is inside a while loop, so it is possible that the compiler can optimize it to not load status_idx from memory.
Thanks.
A message that is not in the archive (sent off-list or not yet received): 1211418386-18203-1-git-send-email-mchan-dY08KVG/lbpWk0Htik3J/[email protected]
PATCH 1/3 bnx2: Add support for CNIC driver.
Add interface for a separate CNIC driver to drive additional rings and other resources for iSCSI.
A probe function is exported so that the CNIC driver can get information about bnx2 devices. After calling the probe function, the CNIC driver can then register with the BNX2 driver before initializing the hardware for iSCSI.
--- drivers/net/bnx2.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++-- drivers/net/bnx2.h | 21 ++++++ 2 files changed, 218 insertions(+), 5 deletions(-)
drivers/net/bnx2.c +197 -5
@@ -48,6 +48,11 @@#include <linux/cache.h> #include <linux/zlib.h> +#if defined(CONFIG_CNIC ) || defined(CONFIG_CNIC_MODULE ) +#define BCM_CNIC 1 +#include "cnic_drv.h" +#endif +#include "bnx2.h" #include "bnx2_fw.h" #include "bnx2_fw2.h"
@@ -302,6 +307,170 @@ bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)spin_unlock_bh (&bp->indirect_lock); } +#ifdef BCM_CNIC +static int +bnx2_drv_ctl (struct net_device *dev,struct drv_ctl_info *info) +{ +struct bnx2 *bp =netdev_priv (dev); +struct drv_ctl_io *io = &info->data.io; + +switch (info->cmd) { +case DRV_CTL_IO_WR_CMD : +bnx2_reg_wr_ind (bp, io->offset, io->data); +break ; +case DRV_CTL_IO_RD_CMD : + io->data =bnx2_reg_rd_ind (bp, io->offset); +break ; +case DRV_CTL_CTX_WR_CMD : +bnx2_ctx_wr (bp, io->cid_addr, io->offset, io->data); +break ; +default : +return -EINVAL ; + } +return 0 ; +} + +static void bnx2_setup_cnic_irq_info (struct bnx2 *bp) +{ +struct cnic_ops *c_ops; +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; +int sb_id; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (!c_ops) + goto done; + +if (bp->flags &BNX2_FLAG_USING_MSIX ) { + cp->drv_state |=CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_present =0 ; + sb_id =BNX2_CNIC_VEC ; + cp->irq_arr[0 ].irq_flags |=CNIC_IRQ_FL_MSIX ; + }else { + cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_tag = bnapi->last_status_idx; + bnapi->cnic_present =1 ; + sb_id =0 ; + cp->irq_arr[0 ].irq_flags &= !CNIC_IRQ_FL_MSIX ; + } + + cp->irq_arr[0 ].vector = bp->irq_tbl[sb_id].vector; + cp->irq_arr[0 ].status_blk = (void *) ((unsigned long ) bp->status_blk + + (BNX2_SBLK_MSIX_ALIGN_SIZE * sb_id)); + cp->irq_arr[0 ].status_blk_num = sb_id; + cp->num_irq =1 ; + +done: +rcu_read_unlock (); +} + +static int bnx2_register_cnic (struct net_device *dev,struct cnic_ops *ops, +void *data) +{ +struct bnx2 *bp =netdev_priv (dev); +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + +if (ops ==NULL ) +return -EINVAL ; + +if (!try_module_get (ops->cnic_owner)) +return -EBUSY ; + + bp->cnic_data = data; +rcu_assign_pointer (bp->cnic_ops, ops); + + cp->num_irq =0 ; + cp->drv_state =CNIC_DRV_STATE_REGD ; + +bnx2_setup_cnic_irq_info (bp); + +return 0 ; +} + +static int bnx2_unregister_cnic (struct net_device *dev) +{ +struct bnx2 *bp =netdev_priv (dev); +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + + cp->drv_state =0 ; +module_put (bp->cnic_ops->cnic_owner); + bnapi->cnic_present =0 ; +rcu_assign_pointer (bp->cnic_ops,NULL ); +synchronize_rcu (); +return 0 ; +} + +struct cnic_eth_dev *bnx2_cnic_probe (struct net_device *dev) +{ +struct bnx2 *bp =netdev_priv (dev); +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + + cp->chip_id = bp->chip_id; + cp->pdev = bp->pdev; + cp->io_base = bp->regview; + cp->drv_ctl = bnx2_drv_ctl; + cp->drv_register_cnic = bnx2_register_cnic; + cp->drv_unregister_cnic = bnx2_unregister_cnic; + +return cp; +} +EXPORT_SYMBOL (bnx2_cnic_probe); + +static void +bnx2_cnic_stop (struct bnx2 *bp) +{ +struct cnic_ops *c_ops; +struct cnic_ctl_info info; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (c_ops) { + info.cmd =CNIC_CTL_STOP_CMD ; + c_ops->cnic_ctl (bp->cnic_data, &info); + } +rcu_read_unlock (); +} + +static void +bnx2_cnic_start (struct bnx2 *bp) +{ +struct cnic_ops *c_ops; +struct cnic_ctl_info info; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (c_ops) { +if (!(bp->flags &BNX2_FLAG_USING_MSIX )) { +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; + + bnapi->cnic_tag = bnapi->last_status_idx; + } + info.cmd =CNIC_CTL_START_CMD ; + c_ops->cnic_ctl (bp->cnic_data, &info); + } +rcu_read_unlock (); +} + +#else + +static void bnx2_setup_cnic_irq_info (struct bnx2 *bp) +{ +} + +static void +bnx2_cnic_stop (struct bnx2 *bp) +{ +} + +static void +bnx2_cnic_start (struct bnx2 *bp) +{ +} + +#endif +static int bnx2_read_phy (struct bnx2 *bp,u32 reg,u32 *val) {
@@ -475,6 +644,7 @@ bnx2_napi_enable(struct bnx2 *bp)static void bnx2_netif_stop (struct bnx2 *bp) { +bnx2_cnic_stop (bp);bnx2_disable_int_sync (bp);if (netif_running (bp->dev)) {bnx2_napi_disable (bp);
@@ -491,6 +661,7 @@ bnx2_netif_start(struct bnx2 *bp)netif_wake_queue (bp->dev);bnx2_napi_enable (bp);bnx2_enable_int (bp); +bnx2_cnic_start (bp); } } }
@@ -3007,6 +3178,9 @@ bnx2_has_work(struct bnx2_napi *bnapi) (sblk->status_attn_bits_ack & STATUS_ATTN_EVENTS))return 1 ; +if (bnapi->cnic_present && (bnapi->cnic_tag != sblk->status_idx)) +return 1 ; +return 0 ; }
@@ -3059,6 +3233,20 @@ static int bnx2_poll_work(struct bnx2 *bp, struct bnx2_napi *bnapi,if (bnx2_get_hw_rx_cons (bnapi) != bnapi->rx_cons) work_done +=bnx2_rx_int (bp, bnapi, budget - work_done); +#ifdef BCM_CNIC +if (bnapi->cnic_present) { +struct cnic_ops *c_ops; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (c_ops) + bnapi->cnic_tag = + c_ops->cnic_handler (bp->cnic_data, + bnapi->status_blk); +rcu_read_unlock (); + } +#endif +return work_done; }
@@ -3100,7 +3288,6 @@ static int bnx2_poll(struct napi_struct *napi, int budget)break ; } } -return work_done; }
@@ -5517,19 +5704,19 @@ static void bnx2_enable_msix(struct bnx2 *bp) {int i, rc; -struct msix_entry msix_ent[BNX2_MAX_MSIX_VEC ]; +struct msix_entry msix_ent[BNX2_MAX_MSIX_CNIC_VEC ];bnx2_setup_msix_tbl (bp);REG_WR (bp,BNX2_PCI_MSIX_CONTROL ,BNX2_MAX_MSIX_HW_VEC -1 );REG_WR (bp,BNX2_PCI_MSIX_TBL_OFF_BIR ,BNX2_PCI_GRC_WINDOW2_BASE );REG_WR (bp,BNX2_PCI_MSIX_PBA_OFF_BIT ,BNX2_PCI_GRC_WINDOW3_BASE ); -for (i =0 ; i <BNX2_MAX_MSIX_VEC ; i++) { +for (i =0 ; i <BNX2_MAX_MSIX_CNIC_VEC ; i++) { msix_ent[i].entry = i; msix_ent[i].vector =0 ; } - rc =pci_enable_msix (bp->pdev, msix_ent,BNX2_MAX_MSIX_VEC ); + rc =pci_enable_msix (bp->pdev, msix_ent,BNX2_MAX_MSIX_CNIC_VEC );if (rc !=0 )return ;
@@ -5540,10 +5727,14 @@ bnx2_enable_msix(struct bnx2 *bp)strcat (bp->irq_tbl[BNX2_BASE_VEC ].name,"-base" );strcpy (bp->irq_tbl[BNX2_TX_VEC ].name, bp->dev->name);strcat (bp->irq_tbl[BNX2_TX_VEC ].name,"-tx" ); +#ifdef BCM_CNIC +strcpy (bp->irq_tbl[BNX2_CNIC_VEC ].name, bp->dev->name); +strcat (bp->irq_tbl[BNX2_CNIC_VEC ].name,"-cnic" ); +#endif bp->irq_nvecs =BNX2_MAX_MSIX_VEC ; bp->flags |=BNX2_FLAG_USING_MSIX |BNX2_FLAG_ONE_SHOT_MSI ; -for (i =0 ; i <BNX2_MAX_MSIX_VEC ; i++) +for (i =0 ; i <BNX2_MAX_MSIX_CNIC_VEC ; i++) bp->irq_tbl[i].vector = msix_ent[i].vector; }
@@ -5571,6 +5762,7 @@ bnx2_setup_int_mode(struct bnx2 *bp, int dis_msi) bp->irq_tbl[0 ].vector = bp->pdev->irq; } } +bnx2_setup_cnic_irq_info (bp); }/* Called with rtnl_lock */
drivers/net/bnx2.h +21 -0
@@ -6562,6 +6562,15 @@ struct flash_spec {#define BNX2_TX_VEC 1#define BNX2_TX_INT_NUM (BNX2_TX_VEC << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT) +#ifdef BCM_CNIC +#define BNX2_MAX_MSIX_CNIC_VEC (BNX2_MAX_MSIX_VEC + 1) +#define BNX2_CNIC_VEC 2 +#define BNX2_CNIC_INT_NUM \ + (BNX2_CNIC_VEC << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT) +#else +#define BNX2_MAX_MSIX_CNIC_VEC BNX2_MAX_MSIX_VEC +#endif +struct bnx2_irq {irq_handler_t handler;u16 vector;
@@ -6577,6 +6586,9 @@ struct bnx2_napi {u32 last_status_idx;u32 int_num; +u32 cnic_tag; +int cnic_present; +u16 tx_cons;u16 hw_tx_cons;
@@ -6648,6 +6660,11 @@ struct bnx2 {int tx_ring_size;u32 tx_wake_thresh; +#ifdef BCM_CNIC +struct cnic_ops *cnic_ops; +void *cnic_data; +#endif +/* End of fields used in the performance code paths. */ char *name;
@@ -6813,6 +6830,10 @@ struct bnx2 {struct bnx2_irq irq_tbl[BNX2_MAX_MSIX_VEC ];int irq_nvecs; + +#ifdef BCM_CNIC +struct cnic_eth_dev cnic_eth_dev; +#endif };#define REG_RD (bp, offset) \
Signature · 1 line
1.5.5.GIT
Re: [PATCH 1/3] bnx2: Add support for CNIC driver.
Quoted 7 lines · Michael Chan
Add interface for a separate CNIC driver to drive additional rings and other resources for iSCSI.
A probe function is exported so that the CNIC driver can get information about bnx2 devices. After calling the probe function, the CNIC driver can then register with the BNX2 driver before initializing the hardware for iSCSI.
Some RCU-related questions interspersed below, for example, how are updates protected?
Thanx, Paul
Quoted 50 lines
Signed-off-by Michael Chan <[email protected]>--- drivers/net/bnx2.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++-- drivers/net/bnx2.h | 21 ++++++ 2 files changed, 218 insertions(+), 5 deletions(-)drivers/net/bnx2.c +29
-0@@ -48,6 +48,11 @@#include <linux/cache.h> #include <linux/zlib.h> +#if defined(CONFIG_CNIC ) || defined(CONFIG_CNIC_MODULE ) +#define BCM_CNIC 1 +#include "cnic_drv.h" +#endif +#include "bnx2.h" #include "bnx2_fw.h" #include "bnx2_fw2.h" @@ -302,6 +307,170 @@ bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)spin_unlock_bh (&bp->indirect_lock); } +#ifdef BCM_CNIC +static int +bnx2_drv_ctl (struct net_device *dev,struct drv_ctl_info *info) +{ +struct bnx2 *bp =netdev_priv (dev); +struct drv_ctl_io *io = &info->data.io; + +switch (info->cmd) { +case DRV_CTL_IO_WR_CMD : +bnx2_reg_wr_ind (bp, io->offset, io->data); +break ; +case DRV_CTL_IO_RD_CMD : + io->data =bnx2_reg_rd_ind (bp, io->offset); +break ; +case DRV_CTL_CTX_WR_CMD : +bnx2_ctx_wr (bp, io->cid_addr, io->offset, io->data); +break ; +default : +return -EINVAL ; + } +return 0 ; +} + +static void bnx2_setup_cnic_irq_info (struct bnx2 *bp)
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 343
Quoted 10 lines
drivers/net/bnx2.c +10
-0+{ +struct cnic_ops *c_ops; +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; +int sb_id; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (!c_ops) + goto done;
Given that c_ops is unused below, what is happening here? What prevents bp->cnic_ops from becoming NULL immediately after we test it? And if it is OK for bp->cnic_ops to become NULL immediately after we test it, why are we bothering to test it?
Quoted 28 lines
drivers/net/bnx2.c +28
-0+ +if (bp->flags &BNX2_FLAG_USING_MSIX ) { + cp->drv_state |=CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_present =0 ; + sb_id =BNX2_CNIC_VEC ; + cp->irq_arr[0 ].irq_flags |=CNIC_IRQ_FL_MSIX ; + }else { + cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_tag = bnapi->last_status_idx; + bnapi->cnic_present =1 ; + sb_id =0 ; + cp->irq_arr[0 ].irq_flags &= !CNIC_IRQ_FL_MSIX ; + } + + cp->irq_arr[0 ].vector = bp->irq_tbl[sb_id].vector; + cp->irq_arr[0 ].status_blk = (void *) ((unsigned long ) bp->status_blk + + (BNX2_SBLK_MSIX_ALIGN_SIZE * sb_id)); + cp->irq_arr[0 ].status_blk_num = sb_id; + cp->num_irq =1 ; + +done: +rcu_read_unlock (); +} + +static int bnx2_register_cnic (struct net_device *dev,struct cnic_ops *ops, +void *data) +{ +struct bnx2 *bp =netdev_priv (dev);
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 381
Quoted 10 lines
drivers/net/bnx2.c +10
-0+struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + +if (ops ==NULL ) +return -EINVAL ; + +if (!try_module_get (ops->cnic_owner)) +return -EBUSY ; + + bp->cnic_data = data; +rcu_assign_pointer (bp->cnic_ops, ops);
What prevents multiple tasks from doing this assignment concurrently?
Quoted 9 lines
drivers/net/bnx2.c +9
-0+ + cp->num_irq =0 ; + cp->drv_state =CNIC_DRV_STATE_REGD ; + +bnx2_setup_cnic_irq_info (bp); + +return 0 ; +} +
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 400
Quoted 10 lines
drivers/net/bnx2.c +10
-0+static int bnx2_unregister_cnic (struct net_device *dev) +{ +struct bnx2 *bp =netdev_priv (dev); +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + + cp->drv_state =0 ; +module_put (bp->cnic_ops->cnic_owner); + bnapi->cnic_present =0 ; +rcu_assign_pointer (bp->cnic_ops,NULL );
What prevents this from running concurrently with bnx2_register_cnic()?
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 401
Quoted 1 line
drivers/net/bnx2.c +1
-0+synchronize_rcu ();
The caller is responsible for freeing up the old bp->cnic_ops structure? Or is this structure statically allocated?
If so, is the idea to delay return until all prior calls through the old ops structure have completed?
Quoted 239 lines
drivers/net/bnx2.c +100
-5+return 0 ; +} + +struct cnic_eth_dev *bnx2_cnic_probe (struct net_device *dev) +{ +struct bnx2 *bp =netdev_priv (dev); +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + + cp->chip_id = bp->chip_id; + cp->pdev = bp->pdev; + cp->io_base = bp->regview; + cp->drv_ctl = bnx2_drv_ctl; + cp->drv_register_cnic = bnx2_register_cnic; + cp->drv_unregister_cnic = bnx2_unregister_cnic; + +return cp; +} +EXPORT_SYMBOL (bnx2_cnic_probe); + +static void +bnx2_cnic_stop (struct bnx2 *bp) +{ +struct cnic_ops *c_ops; +struct cnic_ctl_info info; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (c_ops) { + info.cmd =CNIC_CTL_STOP_CMD ; + c_ops->cnic_ctl (bp->cnic_data, &info); + } +rcu_read_unlock (); +} + +static void +bnx2_cnic_start (struct bnx2 *bp) +{ +struct cnic_ops *c_ops; +struct cnic_ctl_info info; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (c_ops) { +if (!(bp->flags &BNX2_FLAG_USING_MSIX )) { +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; + + bnapi->cnic_tag = bnapi->last_status_idx; + } + info.cmd =CNIC_CTL_START_CMD ; + c_ops->cnic_ctl (bp->cnic_data, &info); + } +rcu_read_unlock (); +} + +#else + +static void bnx2_setup_cnic_irq_info (struct bnx2 *bp) +{ +} + +static void +bnx2_cnic_stop (struct bnx2 *bp) +{ +} + +static void +bnx2_cnic_start (struct bnx2 *bp) +{ +} + +#endif +static int bnx2_read_phy (struct bnx2 *bp,u32 reg,u32 *val) {@@ -475,6 +644,7 @@ bnx2_napi_enable(struct bnx2 *bp)static void bnx2_netif_stop (struct bnx2 *bp) { +bnx2_cnic_stop (bp);bnx2_disable_int_sync (bp);if (netif_running (bp->dev)) {bnx2_napi_disable (bp);@@ -491,6 +661,7 @@ bnx2_netif_start(struct bnx2 *bp)netif_wake_queue (bp->dev);bnx2_napi_enable (bp);bnx2_enable_int (bp); +bnx2_cnic_start (bp); } } }@@ -3007,6 +3178,9 @@ bnx2_has_work(struct bnx2_napi *bnapi) (sblk->status_attn_bits_ack & STATUS_ATTN_EVENTS))return 1 ; +if (bnapi->cnic_present && (bnapi->cnic_tag != sblk->status_idx)) +return 1 ; +return 0 ; }@@ -3059,6 +3233,20 @@ static int bnx2_poll_work(struct bnx2 *bp, struct bnx2_napi *bnapi,if (bnx2_get_hw_rx_cons (bnapi) != bnapi->rx_cons) work_done +=bnx2_rx_int (bp, bnapi, budget - work_done); +#ifdef BCM_CNIC +if (bnapi->cnic_present) { +struct cnic_ops *c_ops; + +rcu_read_lock (); + c_ops =rcu_dereference (bp->cnic_ops); +if (c_ops) + bnapi->cnic_tag = + c_ops->cnic_handler (bp->cnic_data, + bnapi->status_blk); +rcu_read_unlock (); + } +#endif +return work_done; }@@ -3100,7 +3288,6 @@ static int bnx2_poll(struct napi_struct *napi, int budget)break ; } } -return work_done; }@@ -5517,19 +5704,19 @@ static void bnx2_enable_msix(struct bnx2 *bp) {int i, rc; -struct msix_entry msix_ent[BNX2_MAX_MSIX_VEC ]; +struct msix_entry msix_ent[BNX2_MAX_MSIX_CNIC_VEC ];bnx2_setup_msix_tbl (bp);REG_WR (bp,BNX2_PCI_MSIX_CONTROL ,BNX2_MAX_MSIX_HW_VEC -1 );REG_WR (bp,BNX2_PCI_MSIX_TBL_OFF_BIR ,BNX2_PCI_GRC_WINDOW2_BASE );REG_WR (bp,BNX2_PCI_MSIX_PBA_OFF_BIT ,BNX2_PCI_GRC_WINDOW3_BASE ); -for (i =0 ; i <BNX2_MAX_MSIX_VEC ; i++) { +for (i =0 ; i <BNX2_MAX_MSIX_CNIC_VEC ; i++) { msix_ent[i].entry = i; msix_ent[i].vector =0 ; } - rc =pci_enable_msix (bp->pdev, msix_ent,BNX2_MAX_MSIX_VEC ); + rc =pci_enable_msix (bp->pdev, msix_ent,BNX2_MAX_MSIX_CNIC_VEC );if (rc !=0 )return ;@@ -5540,10 +5727,14 @@ bnx2_enable_msix(struct bnx2 *bp)strcat (bp->irq_tbl[BNX2_BASE_VEC ].name,"-base" );strcpy (bp->irq_tbl[BNX2_TX_VEC ].name, bp->dev->name);strcat (bp->irq_tbl[BNX2_TX_VEC ].name,"-tx" ); +#ifdef BCM_CNIC +strcpy (bp->irq_tbl[BNX2_CNIC_VEC ].name, bp->dev->name); +strcat (bp->irq_tbl[BNX2_CNIC_VEC ].name,"-cnic" ); +#endif bp->irq_nvecs =BNX2_MAX_MSIX_VEC ; bp->flags |=BNX2_FLAG_USING_MSIX |BNX2_FLAG_ONE_SHOT_MSI ; -for (i =0 ; i <BNX2_MAX_MSIX_VEC ; i++) +for (i =0 ; i <BNX2_MAX_MSIX_CNIC_VEC ; i++) bp->irq_tbl[i].vector = msix_ent[i].vector; }@@ -5571,6 +5762,7 @@ bnx2_setup_int_mode(struct bnx2 *bp, int dis_msi) bp->irq_tbl[0 ].vector = bp->pdev->irq; } } +bnx2_setup_cnic_irq_info (bp); }/* Called with rtnl_lock */ drivers/net/bnx2.h +21
-0@@ -6562,6 +6562,15 @@ struct flash_spec {#define BNX2_TX_VEC 1#define BNX2_TX_INT_NUM (BNX2_TX_VEC << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT) +#ifdef BCM_CNIC +#define BNX2_MAX_MSIX_CNIC_VEC (BNX2_MAX_MSIX_VEC + 1) +#define BNX2_CNIC_VEC 2 +#define BNX2_CNIC_INT_NUM \ + (BNX2_CNIC_VEC << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT) +#else +#define BNX2_MAX_MSIX_CNIC_VEC BNX2_MAX_MSIX_VEC +#endif +struct bnx2_irq {irq_handler_t handler;u16 vector;@@ -6577,6 +6586,9 @@ struct bnx2_napi {u32 last_status_idx;u32 int_num; +u32 cnic_tag; +int cnic_present; +u16 tx_cons;u16 hw_tx_cons;@@ -6648,6 +6660,11 @@ struct bnx2 {int tx_ring_size;u32 tx_wake_thresh; +#ifdef BCM_CNIC +struct cnic_ops *cnic_ops; +void *cnic_data; +#endif +/* End of fields used in the performance code paths. */ char *name;@@ -6813,6 +6830,10 @@ struct bnx2 {struct bnx2_irq irq_tbl[BNX2_MAX_MSIX_VEC ];int irq_nvecs; + +#ifdef BCM_CNIC +struct cnic_eth_dev cnic_eth_dev; +#endif };#define REG_RD (bp, offset) \Signature · 8 lines
1.5.5.GIT -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20080522064541.GA11933-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [PATCH 1/3] bnx2: Add support for CNIC driver.
Quoted 2 lines · Paul E. McKenney
Some RCU-related questions interspersed below, for example, how are updates protected?
Only one CNIC driver will ever register with the BNX2 driver. The main purpose of using RCU is so that the fast path can avoid locking when handling interrupt events from the hardware.
Quoted 9 lines
Quoted 9 lines
drivers/net/bnx2.c +9
-0+ +static void bnx2_setup_cnic_irq_info (struct bnx2 *bp) +{ +struct cnic_ops *c_ops; +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; +int sb_id; + +rcu_read_lock ();
Quoted 8 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 343
Quoted 3 lines
drivers/net/bnx2.c +3
-0+ c_ops =rcu_dereference (bp->cnic_ops); +if (!c_ops) + goto done;Given that
c_opsis unused below, what is happening here? What preventsbp->cnic_opsfrom becoming NULL immediately after we test it? And if it is OK forbp->cnic_opsto become NULL immediately after we test it, why are we bothering to test it?
You are right. We should just unconditionally set up the IRQ information without checking for c_ops. The data structures we set up below are owned by us.
Quoted 33 lines
Quoted 33 lines
drivers/net/bnx2.c +32
-0+ +if (bp->flags &BNX2_FLAG_USING_MSIX ) { + cp->drv_state |=CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_present =0 ; + sb_id =BNX2_CNIC_VEC ; + cp->irq_arr[0 ].irq_flags |=CNIC_IRQ_FL_MSIX ; + }else { + cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_tag = bnapi->last_status_idx; + bnapi->cnic_present =1 ; + sb_id =0 ; + cp->irq_arr[0 ].irq_flags &= !CNIC_IRQ_FL_MSIX ; + } + + cp->irq_arr[0 ].vector = bp->irq_tbl[sb_id].vector; + cp->irq_arr[0 ].status_blk = (void *) ((unsigned long ) bp->status_blk + + (BNX2_SBLK_MSIX_ALIGN_SIZE * sb_id)); + cp->irq_arr[0 ].status_blk_num = sb_id; + cp->num_irq =1 ; + +done: +rcu_read_unlock (); +} + +static int bnx2_register_cnic (struct net_device *dev,struct cnic_ops *ops, +void *data) +{ +struct bnx2 *bp =netdev_priv (dev); +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + +if (ops ==NULL ) +return -EINVAL ;
Quoted 8 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 381
Quoted 6 lines
drivers/net/bnx2.c +6
-0+ +if (!try_module_get (ops->cnic_owner)) +return -EBUSY ; + + bp->cnic_data = data; +rcu_assign_pointer (bp->cnic_ops, ops);What prevents multiple tasks from doing this assignment concurrently?
As I said above, only one CNIC driver will ever register.
Quoted 14 lines
Quoted 14 lines
drivers/net/bnx2.c +13
-0+ + cp->num_irq =0 ; + cp->drv_state =CNIC_DRV_STATE_REGD ; + +bnx2_setup_cnic_irq_info (bp); + +return 0 ; +} + +static int bnx2_unregister_cnic (struct net_device *dev) +{ +struct bnx2 *bp =netdev_priv (dev); +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ];
Quoted 8 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 400
Quoted 6 lines
drivers/net/bnx2.c +6
-0+struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + + cp->drv_state =0 ; +module_put (bp->cnic_ops->cnic_owner); + bnapi->cnic_present =0 ; +rcu_assign_pointer (bp->cnic_ops,NULL );What prevents this from running concurrently with
bnx2_register_cnic()?
We expect the CNIC driver to be well behaved and will only unregister after successfully registered.
Quoted 8 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 401
Quoted 2 lines
drivers/net/bnx2.c +1
-0+synchronize_rcu ();The caller is responsible for freeing up the old
bp->cnic_opsstructure? Or is this structure statically allocated?If so, is the idea to delay return until all prior calls through the old ops structure have completed?
The cnic_ops contain call back function pointers to the CNIC driver. We want to make sure that those calls have completed (in the fast path) before continuing.
Quoted 4 lines
Quoted 4 lines
drivers/net/bnx2.c +3
-0+return 0 ; +} +
Re: [PATCH 1/3] bnx2: Add support for CNIC driver.
Quoted 8 lines · Michael Chan
Quoted 2 lines · Paul E. McKenney
Some RCU-related questions interspersed below, for example, how are updates protected?
Only one CNIC driver will ever register with the BNX2 driver. The main purpose of using RCU is so that the fast path can avoid locking when handling interrupt events from the hardware.
So if a second CNIC driver attempts to register, it gets -EBUSY or something, right?
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/bnx2.c +9
-0+ +static void bnx2_setup_cnic_irq_info (struct bnx2 *bp) +{ +struct cnic_ops *c_ops; +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ]; +int sb_id; + +rcu_read_lock ();Quoted 8 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 343
Quoted 3 lines
drivers/net/bnx2.c +3
-0+ c_ops =rcu_dereference (bp->cnic_ops); +if (!c_ops) + goto done;Given that
c_opsis unused below, what is happening here? What preventsbp->cnic_opsfrom becoming NULL immediately after we test it? And if it is OK forbp->cnic_opsto become NULL immediately after we test it, why are we bothering to test it?
Quoted 3 lines
You are right. We should just unconditionally set up the IRQ information without checking for
c_ops. The data structures we set up below are owned by us.
OK. Hmmm.... You cannot even get away with sarcasm these days! ;-)
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
drivers/net/bnx2.c +32
-0+ +if (bp->flags &BNX2_FLAG_USING_MSIX ) { + cp->drv_state |=CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_present =0 ; + sb_id =BNX2_CNIC_VEC ; + cp->irq_arr[0 ].irq_flags |=CNIC_IRQ_FL_MSIX ; + }else { + cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX ; + bnapi->cnic_tag = bnapi->last_status_idx; + bnapi->cnic_present =1 ; + sb_id =0 ; + cp->irq_arr[0 ].irq_flags &= !CNIC_IRQ_FL_MSIX ; + } + + cp->irq_arr[0 ].vector = bp->irq_tbl[sb_id].vector; + cp->irq_arr[0 ].status_blk = (void *) ((unsigned long ) bp->status_blk + + (BNX2_SBLK_MSIX_ALIGN_SIZE * sb_id)); + cp->irq_arr[0 ].status_blk_num = sb_id; + cp->num_irq =1 ; + +done: +rcu_read_unlock (); +} + +static int bnx2_register_cnic (struct net_device *dev,struct cnic_ops *ops, +void *data) +{ +struct bnx2 *bp =netdev_priv (dev); +struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + +if (ops ==NULL ) +return -EINVAL ;Quoted 8 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 381
Quoted 6 lines
drivers/net/bnx2.c +6
-0+ +if (!try_module_get (ops->cnic_owner)) +return -EBUSY ; + + bp->cnic_data = data; +rcu_assign_pointer (bp->cnic_ops, ops);What prevents multiple tasks from doing this assignment concurrently?
Quoted 1 line
As I said above, only one CNIC driver will ever register.
OK.
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/net/bnx2.c +13
-0+ + cp->num_irq =0 ; + cp->drv_state =CNIC_DRV_STATE_REGD ; + +bnx2_setup_cnic_irq_info (bp); + +return 0 ; +} + +static int bnx2_unregister_cnic (struct net_device *dev) +{ +struct bnx2 *bp =netdev_priv (dev); +struct bnx2_napi *bnapi = &bp->bnx2_napi[0 ];Quoted 8 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 400
Quoted 6 lines
drivers/net/bnx2.c +6
-0+struct cnic_eth_dev *cp = &bp->cnic_eth_dev; + + cp->drv_state =0 ; +module_put (bp->cnic_ops->cnic_owner); + bnapi->cnic_present =0 ; +rcu_assign_pointer (bp->cnic_ops,NULL );What prevents this from running concurrently with
bnx2_register_cnic()?
Quoted 2 lines
We expect the CNIC driver to be well behaved and will only unregister after successfully registered.
Trusting, but fair enough. ;-)
Quoted 11 lines
Quoted 7 lines
drivers/net/bnx2.c bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) · line 401
Quoted 1 line
drivers/net/bnx2.c +1
-0+synchronize_rcu ();The caller is responsible for freeing up the old
bp->cnic_opsstructure? Or is this structure statically allocated?If so, is the idea to delay return until all prior calls through the old ops structure have completed?
The
cnic_opscontain call back function pointers to the CNIC driver. We want to make sure that those calls have completed (in the fast path) before continuing.
Very good. Could you please add a comment to that effect? Otherwise people search for what data structure is being freed up.
Thanx, Paul
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/bnx2.c +3
-0+return 0 ; +} +
A message that is not in the archive (sent off-list or not yet received): 20080523034522.GA8612-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [PATCH 1/3] bnx2: Add support for CNIC driver.
Quoted 2 lines · Paul E. McKenney
So if a second CNIC driver attempts to register, it gets
-EBUSYor something, right?
There is only one CNIC driver and it will only register once per BNX2 netdevice.
Quoted 6 lines
Quoted 2 lines
You are right. We should just unconditionally set up the IRQ information without checking for
c_ops. The datastructures we set up
Quoted 1 line
below are owned by us.
OK. Hmmm.... You cannot even get away with sarcasm these days! ;-)
Hmm, not sure what's the sarcasm. The code here is trying to set up the IRQ information so that CNIC driver can see it. Even if the CNIC driver is deregistering or was never registered, it doesn't hurt to set up that information.
Anyway, I'll add some comments to the code to explain this better when I respin.
Quoted 3 lines
Very good. Could you please add a comment to that effect? Otherwise people search for what data structure is being freed up.
Will do. Thanks.
Re: [PATCH 1/3] bnx2: Add support for CNIC driver.
Quoted 7 lines · Michael Chan
Quoted 2 lines · Paul E. McKenney
So if a second CNIC driver attempts to register, it gets
-EBUSYor something, right?There is only one CNIC driver and it will only register once per BNX2 netdevice.
I would nevertheless recommend keeping an error check...
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
You are right. We should just unconditionally set up the IRQ information without checking for
c_ops. The datastructures we set up
Quoted 1 line
below are owned by us.
OK. Hmmm.... You cannot even get away with sarcasm these days! ;-)
Hmm, not sure what's the sarcasm. The code here is trying to set up the IRQ information so that CNIC driver can see it. Even if the CNIC driver is deregistering or was never registered, it doesn't hurt to set up that information.
The sarcasm was that I really didn't expect you to simply be able to remove the check. ;-)
Quoted 8 lines
Anyway, I'll add some comments to the code to explain this better when I respin.
Quoted 3 lines
Very good. Could you please add a comment to that effect? Otherwise people search for what data structure is being freed up.
Will do. Thanks.
Sounds good!
Thanx, Paul
A message that is not in the archive (sent off-list or not yet received): 1211418386-18203-2-git-send-email-mchan-dY08KVG/lbpWk0Htik3J/[email protected]
Re: [PATCH 1/3] bnx2: Add support for CNIC driver.
Review
Quoted 3 lines
(quoted diff) +2
-0+static void +bnx2_cnic_stop(struct bnx2 *bp)
The preceding functions follow this format:
static void <fnc name>(<args)
While this and some below follow the
static void
<fnc name>(<args>)
You probably want to follow one style.
PATCH 3/3 bnx2i: Add bnx2i iSCSI driver.
In reply to a message not in the archiveNew iSCSI driver for BNX2 devices. The driver interfaces with the CNIC driver to access the hardware.
--- drivers/scsi/Kconfig | 2 + drivers/scsi/Makefile | 1 + drivers/scsi/bnx2i/57xx_iscsi_constants.h | 151 ++ drivers/scsi/bnx2i/57xx_iscsi_hsi.h | 1492 ++++++++++++++++++++ drivers/scsi/bnx2i/Kconfig | 7 + drivers/scsi/bnx2i/Makefile | 3 + drivers/scsi/bnx2i/bnx2i.h | 745 ++++++++++ drivers/scsi/bnx2i/bnx2i_hwi.c | 2112 +++++++++++++++++++++++++++++ drivers/scsi/bnx2i/bnx2i_init.c | 452 ++++++ drivers/scsi/bnx2i/bnx2i_iscsi.c | 2086 ++++++++++++++++++++++++++++ drivers/scsi/bnx2i/bnx2i_sysfs.c | 168 +++ 11 files changed, 7219 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/bnx2i/57xx_iscsi_constants.h create mode 100644 drivers/scsi/bnx2i/57xx_iscsi_hsi.h create mode 100644 drivers/scsi/bnx2i/Kconfig create mode 100644 drivers/scsi/bnx2i/Makefile create mode 100644 drivers/scsi/bnx2i/bnx2i.h create mode 100644 drivers/scsi/bnx2i/bnx2i_hwi.c create mode 100644 drivers/scsi/bnx2i/bnx2i_init.c create mode 100644 drivers/scsi/bnx2i/bnx2i_iscsi.c create mode 100644 drivers/scsi/bnx2i/bnx2i_sysfs.c
drivers/scsi/Kconfig +2 -0
@@ -1757,6 +1757,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/bnx2i/Kconfig" + config SCSI_SRP tristate "SCSI RDMA Protocol helper library" depends on SCSI && PCI
drivers/scsi/Makefile +1 -0
@@ -122,6 +122,7 @@ obj-$(CONFIG_SCSI_HPTIOP) += hptiop.o obj-$(CONFIG_SCSI_STEX) += stex.o obj-$(CONFIG_SCSI_MVSAS) += mvsas.o obj-$(CONFIG_PS3_ROM) += ps3rom.o +obj-$(CONFIG_SCSI_BNX2_ISCSI) += bnx2i/ obj-$(CONFIG_ARM) += arm/
drivers/scsi/bnx2i/57xx_iscsi_constants.h new file +151 -0
151 lines not on this page · raw message
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +1492 -0
1,492 lines not on this page · raw message
drivers/scsi/bnx2i/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config SCSI_BNX2_ISCSI + tristate "Broadcom NetXtreme II iSCSI support" + select CNIC + select SCSI_ISCSI_ATTRS + ---help--- + This driver supports iSCSI offload for the Broadcom NetXtreme II + devices.
drivers/scsi/bnx2i/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +bnx2i-y := bnx2i_init.o bnx2i_hwi.o bnx2i_iscsi.o bnx2i_sysfs.o + +obj-$(CONFIG_SCSI_BNX2_ISCSI) += bnx2i.o
drivers/scsi/bnx2i/bnx2i.h new file +745 -0
745 lines not on this page · raw message
drivers/scsi/bnx2i/bnx2i_hwi.c new file +2112 -0
587 lines not on this page · raw message
drivers/scsi/bnx2i/bnx2i_init.c new file +452 -0
452 lines not on this page · raw message
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +2086 -0
2,086 lines not on this page · raw message
drivers/scsi/bnx2i/bnx2i_sysfs.c new file +168 -0
168 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.5.5.GIT
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): 1211418386-18203-4-git-send-email-mchan-dY08KVG/lbpWk0Htik3J/[email protected]
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
A cursory glance..
.. snip..
Quoted 16 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +16
-0+struct bnx2i_cleanup_request { +#if defined(__BIG_ENDIAN) +u8 op_code; +u8 reserved1; +u16 reserved0; +#elif defined(__LITTLE_ENDIAN) +u16 reserved0; +u8 reserved1; +u8 op_code; +#endif +u32 reserved2[3 ]; +#if defined(__BIG_ENDIAN) +u16 reserved3; +u16 itt; +#define ISCSI_CLEANUP_REQUEST_INDEX (0x3FFF<<0) +#define ISCSI_CLEANUP_REQUEST_INDEX_SHIFT 0
drivers/scsi/bnx2i/57xx_iscsi_hsi.h line 130
Quoted 10 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +10
-0+#define ISCSI_CLEANUP_REQUEST_TYPE (0x3<<14) +#define ISCSI_CLEANUP_REQUEST_TYPE_SHIFT 14 +#elif defined(__LITTLE_ENDIAN) +u16 itt; +#define ISCSI_CLEANUP_REQUEST_INDEX (0x3FFF<<0) +#define ISCSI_CLEANUP_REQUEST_INDEX_SHIFT 0 +#define ISCSI_CLEANUP_REQUEST_TYPE (0x3<<14) +#define ISCSI_CLEANUP_REQUEST_TYPE_SHIFT 14 +u16 reserved3; +#endif
Why the duplication of the #define values? They look the same.
.. snip ..
Quoted 2 lines
+/*
+ * mnc - lookup Jeff Garzack's rule about defining this
Has this TODO been completed?
Quoted 3 lines
+ * type of junk. Base on enum and make it less error prone.
+ * Anil - these are bit masks, won't enum be little ugly?
+ */
.. snip ..
Quoted 1 line
+ *
bnx2i_iscsi_license_error- displays iscsi license related error message
Doesn't look very license related. Just says 'not supported'.
Quoted 5 lines
+ * @hba: adapter instance pointer
+ * @error_code: error classification
+ *
+ * Puts out an error log when driver is unable to offload iscsi connection
+ * due to license restrictions
Maybe adding in some extra information to the error, such as: "Due to GPL restrictions, etc.." .. What does 'LOM' stand for?
drivers/scsi/bnx2i/bnx2i_hwi.c line 49
Quoted 10 lines
+ */
drivers/scsi/bnx2i/bnx2i_hwi.c new file +9
-0+static void bnx2i_iscsi_license_error (struct bnx2i_hba *hba,u32 error_code) +{ +if (error_code ==ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED ) +/* iSCSI offload not supported on this device */ +printk (KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n" , + hba->netdev->name); +if (error_code ==ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED ) +/* iSCSI offload not supported on this LOM device */ + printk(KERN_ERR "bnx2i: LOM is not enable to "
^^^^-enabled.
Quoted 21 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +21
-0+"offload iSCSI connections, dev=%s\n" , + hba->netdev->name); +set_bit (ADAPTER_STATE_INIT_FAILED , &hba->adapter_state); +} + +#ifdef _EVENT_COALESCE_ +#define CNIC_ARM_CQE 1 +#define CNIC_DISARM_CQE 0 +extern unsigned int event_coal_div; + +/** +* bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification +* @ep: endpoint (transport indentifier) structure +* @action: action, ARM or DISARM. For now only ARM_CQE is used +* +* Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt +* the driver. EQ event is generated CQ index is hit or at least 1 CQ is +* outstanding and on chip timer expires +*/ +static void bnx2i_arm_cq_event_coalescing (struct bnx2i_endpoint *ep,u8 action) +{
drivers/scsi/bnx2i/bnx2i_hwi.c line 80
Quoted 10 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +10
-0+u16 cq_index; +if ((action ==CNIC_ARM_CQE ) && ep->sess) { + cq_index = ep->qp.cqe_exp_seq_sn + + ep->sess->num_active_cmds / event_coal_div; + cq_index %= (ep->qp.cqe_size *2 +1 ); +if (!cq_index) + cq_index =1 ; +writew (cq_index, ep->qp.ctx_base +CNIC_EVENT_COAL_INDEX ); + } +writeb (action, ep->qp.ctx_base +CNIC_EVENT_CQ_ARM );
This code looks to be outside the function. Did you try to compile with the _EVENT_COALESCE_ define?
.. snip ..
Quoted 2 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +2
-0+int bnx2i_send_iscsi_tmf (struct bnx2i_conn *bnx2i_conn, +struct iscsi_task *mtask)
.. snip
drivers/scsi/bnx2i/bnx2i_hwi.c line 278
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+ tmfabort_wqe->op_attr =0 ; + tmfabort_wqe->op_attr = +ISCSI_TMF_REQUEST_ALWAYS_ONE |ISCSI_TM_FUNC_ABORT_TASK ;
Is the first assigment neccessary?
.. snip ..
Quoted 1 line
+static int
bnx2i_power_of2(u32 val)
There are no macros for this?
.. snip ..
Quoted 18 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +18
-0+static void bnx2i_process_async_mesg (struct iscsi_session *session, +struct bnx2i_conn *bnx2i_conn, +struct cqe *cqe) +{ +struct bnx2i_async_msg *async_cqe; +struct iscsi_async *resp_hdr; +u8 async_event; + +bnx2i_unsol_pdu_adjust_rq (bnx2i_conn); + + async_cqe = (struct bnx2i_async_msg *)cqe; + async_event = async_cqe->async_event; + +if (async_event ==ISCSI_ASYNC_MSG_SCSI_EVENT ) { +/* TODO mnc - can't we just copy the scsi sense buffer +* to the conn->data buffer +* Anil - currently there is no interface to push this +* up to SCSI layer. So far we have not seen any
drivers/scsi/bnx2i/bnx2i_hwi.c line 1327
Quoted 10 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +10
-0+* target generating one. So could be one those +* fancy unused feature +* +* For iser/tcp we pass this to libiscsi which does +* iscsi_recv_pdu to send it to userspace. +* +* This event is used by Cisco to signal that a lun +* has been added or removed. It is also used by +* EMC celerra or centerra boxes, and EMC will ping +* you one day :), so we have to do something.
Yes. This would be really nice if it was passed to the userspace. Especially since the iscsi daemon re-scans the SCSI blk device when this is triggered.
drivers/scsi/bnx2i/bnx2i_hwi.c line 1330
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+*/ +iscsi_conn_printk (KERN_ALERT , bnx2i_conn->cls_conn->dd_data, +"async: scsi events not supported\n" );
You might want to include the SCSI sense buffer as well in the printk.
.. snip ..
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+static void bnx2i_process_iscsi_error (struct bnx2i_hba *hba, +struct iscsi_kcqe *iscsi_err) +{
.. snip ..
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_hwi.c new file +1
-0+char additional_notice[64 ];
.. snip ..
drivers/scsi/bnx2i/bnx2i_hwi.c line 1631
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+switch (iscsi_err->completion_status) { +case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR : +strcpy (additional_notice,"hdr digest err" );
You don't want to memset the 'additional_notice' so that you are guaranteed to have the \0 at the end?
.. snip ..
drivers/scsi/bnx2i/bnx2i_init.c line 40
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_init.c new file +4
-0+ +unsigned int event_coal_div =1 ; +module_param (event_coal_div, int,0664 ); +MODULE_PARM_DESC (event_coal_div,"Event Coalescing Divide Factor" );
Should that have an #ifdef around it? You are not using it except in the code that has the #ifdef _EVENT_COALESCE_
.. snip..
Quoted 2 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +2
-0+static struct iscsi_endpoint *bnx2i_alloc_ep (struct bnx2i_hba *hba) +{
.. snip ..
drivers/scsi/bnx2i/bnx2i_iscsi.c line 521
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +3
-0+ tcp_port =bnx2i_alloc_tcp_port (); +if (!tcp_port) { +printk (KERN_ERR "bnx2i: run 'bnx2id' to alloc tcp ports\n" );
Is that correct? Or will this be handled by iscsid?
.. snip ..
Quoted 5 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +5
-0+static void bnx2i_cleanup_task (struct iscsi_conn *conn, +struct iscsi_task *task) +{ +struct bnx2i_conn *bnx2i_conn = conn->dd_data; +struct bnx2i_hba *hba = bnx2i_conn->hba;
drivers/scsi/bnx2i/bnx2i_iscsi.c line 1216
Quoted 10 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +10
-0+ +/* +* mgmt task or cmd completed while tmf in progress. +*/ +if (!task->sc) +return ; +/* +* ANIL +* do we have to do this for other tmfs? +*/
Not finished TODO?
.. snip ..
drivers/scsi/bnx2i/bnx2i_iscsi.c line 2020
Quoted 13 lines
+ */
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +12
-0+static struct scsi_host_template bnx2i_host_template = { + .module =THIS_MODULE , + .name ="Broadcom Offload iSCSI Initiator" , + .proc_name ="bnx2i" , + .queuecommand = iscsi_queuecommand, + .slave_alloc = iscsi_slave_alloc, + .eh_abort_handler = iscsi_eh_abort, +/* +* Anil +* uncomment this when we know if we need to do a +* ISCSI_OPCODE_CLEANUP_REQUEST on tasks that are affected by +* the lu reset.
What is the verdict?
drivers/scsi/bnx2i/bnx2i_iscsi.c line 2024
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +4
-0+.eh_device_reset_handler = iscsi_eh_device_reset, +*/ + .eh_target_reset_handler = iscsi_eh_target_reset, +/* TODO - just make this the max sessions * max_cmds_per_session */
And is 1024 the right value?
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 3 lines · Konrad Rzeszutek
Quoted 1 line
+ *
bnx2i_iscsi_license_error- displays iscsi license related error messageDoesn't look very license related. Just says 'not supported'.
Could be that some hardware strap pin is being used as a dongle. This doesn't seem entirely in the spirit of GPL, and would be rather easy to remove...
Quoted 8 lines
Quoted 5 lines
+ * @hba: adapter instance pointer
+ * @error_code: error classification
+ *
+ * Puts out an error log when driver is unable to offload iscsi connection
+ * due to license restrictionsMaybe adding in some extra information to the error, such as: "Due to GPL restrictions, etc.." .. What does 'LOM' stand for?
LOM is a common abbreviation for "LAN on motherboard" as opposed to an expansion card.
Ben.
Signature · 2 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
In reply to Konrad RzeszutekQuoted 24 lines · Konrad Rzeszutek
A cursory glance..
.. snip..
Quoted 21 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +21
-0+struct bnx2i_cleanup_request { +#if defined(__BIG_ENDIAN) +u8 op_code; +u8 reserved1; +u16 reserved0; +#elif defined(__LITTLE_ENDIAN) +u16 reserved0; +u8 reserved1; +u8 op_code; +#endif +u32 reserved2[3 ]; +#if defined(__BIG_ENDIAN) +u16 reserved3; +u16 itt; +#define ISCSI_CLEANUP_REQUEST_INDEX (0x3FFF<<0) +#define ISCSI_CLEANUP_REQUEST_INDEX_SHIFT 0 +#define ISCSI_CLEANUP_REQUEST_TYPE (0x3<<14) +#define ISCSI_CLEANUP_REQUEST_TYPE_SHIFT 14 +#elif defined(__LITTLE_ENDIAN) +u16 itt; +#define ISCSI_CLEANUP_REQUEST_INDEX (0x3FFF<<0)
Quoted 9 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h line 130
Quoted 5 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +5
-0+#define ISCSI_CLEANUP_REQUEST_INDEX_SHIFT 0 +#define ISCSI_CLEANUP_REQUEST_TYPE (0x3<<14) +#define ISCSI_CLEANUP_REQUEST_TYPE_SHIFT 14 +u16 reserved3; +#endif Why the duplication of the #define values? They look the same.
Sure we can take care of that by moving macros outside of #ifdef
Quoted 16 lines
.. snip ..
Quoted 2 lines
+/*
+ * mnc - lookup Jeff Garzack's rule about defining thisHas this TODO been completed?
Quoted 3 lines
+ * type of junk. Base on enum and make it less error prone.
+ * Anil - these are bit masks, won't enum be little ugly?
+ */.. snip ..
Quoted 1 line
+ *
bnx2i_iscsi_license_error- displays iscsi license related error messageDoesn't look very license related. Just says 'not supported'.
Quoted 8 lines
Quoted 5 lines
+ * @hba: adapter instance pointer
+ * @error_code: error classification
+ *
+ * Puts out an error log when driver is unable to offload iscsi connection
+ * due to license restrictionsMaybe adding in some extra information to the error, such as: "Due to GPL restrictions, etc.." .. What does 'LOM' stand for?
This has nothing to do with code licensing but related to whether iSCSI functionality is enabled on the device or not. iSCSI feature can be controlled through NVRAM configuration and some OEM's do not enable iscsi
Quoted 38 lines
drivers/scsi/bnx2i/bnx2i_hwi.c line 49
Quoted 11 lines
+ */
drivers/scsi/bnx2i/bnx2i_hwi.c new file +9
-0+static void bnx2i_iscsi_license_error (struct bnx2i_hba *hba,u32 error_code) +{ +if (error_code ==ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED ) +/* iSCSI offload not supported on this device */ +printk (KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n" , + hba->netdev->name); +if (error_code ==ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED ) +/* iSCSI offload not supported on this LOM device */ + printk(KERN_ERR "bnx2i: LOM is not enable to "^^^^-enabled.Quoted 26 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +26
-0+"offload iSCSI connections, dev=%s\n" , + hba->netdev->name); +set_bit (ADAPTER_STATE_INIT_FAILED , &hba->adapter_state); +} + +#ifdef _EVENT_COALESCE_ +#define CNIC_ARM_CQE 1 +#define CNIC_DISARM_CQE 0 +extern unsigned int event_coal_div; + +/** +* bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification +* @ep: endpoint (transport indentifier) structure +* @action: action, ARM or DISARM. For now only ARM_CQE is used +* +* Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt +* the driver. EQ event is generated CQ index is hit or at least 1 CQ is +* outstanding and on chip timer expires +*/ +static void bnx2i_arm_cq_event_coalescing (struct bnx2i_endpoint *ep,u8 action) +{ +u16 cq_index; +if ((action ==CNIC_ARM_CQE ) && ep->sess) { + cq_index = ep->qp.cqe_exp_seq_sn + + ep->sess->num_active_cmds / event_coal_div; + cq_index %= (ep->qp.cqe_size *2 +1 );
Quoted 8 lines
drivers/scsi/bnx2i/bnx2i_hwi.c line 80
Quoted 5 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +5
-0+if (!cq_index) + cq_index =1 ; +writew (cq_index, ep->qp.ctx_base +CNIC_EVENT_COAL_INDEX ); + } +writeb (action, ep->qp.ctx_base +CNIC_EVENT_CQ_ARM );This code looks to be outside the function. Did you try to compile with the _EVENT_COALESCE_ define?
function construction is ok, may be an additional blank line after writeb() the reason for confusion
Quoted 11 lines
.. snip ..
Quoted 2 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +2
-0+int bnx2i_send_iscsi_tmf (struct bnx2i_conn *bnx2i_conn, +struct iscsi_task *mtask).. snip
drivers/scsi/bnx2i/bnx2i_hwi.c line 278
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+ tmfabort_wqe->op_attr =0 ; + tmfabort_wqe->op_attr = +ISCSI_TMF_REQUEST_ALWAYS_ONE |ISCSI_TM_FUNC_ABORT_TASK ;Is the first assigment neccessary?
Quoted 4 lines
.. snip ..
Quoted 1 line
+static int
bnx2i_power_of2(u32 val)There are no macros for this?
Did not find one. But there is is_power_of_2() to check if the given integer is an exact power of 2
Quoted 26 lines
.. snip ..
Quoted 24 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +24
-0+static void bnx2i_process_async_mesg (struct iscsi_session *session, +struct bnx2i_conn *bnx2i_conn, +struct cqe *cqe) +{ +struct bnx2i_async_msg *async_cqe; +struct iscsi_async *resp_hdr; +u8 async_event; + +bnx2i_unsol_pdu_adjust_rq (bnx2i_conn); + + async_cqe = (struct bnx2i_async_msg *)cqe; + async_event = async_cqe->async_event; + +if (async_event ==ISCSI_ASYNC_MSG_SCSI_EVENT ) { +/* TODO mnc - can't we just copy the scsi sense buffer +* to the conn->data buffer +* Anil - currently there is no interface to push this +* up to SCSI layer. So far we have not seen any +* target generating one. So could be one those +* fancy unused feature +* +* For iser/tcp we pass this to libiscsi which does +* iscsi_recv_pdu to send it to userspace. +*
Quoted 8 lines
drivers/scsi/bnx2i/bnx2i_hwi.c line 1327
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +4
-0+* This event is used by Cisco to signal that a lun +* has been added or removed. It is also used by +* EMC celerra or centerra boxes, and EMC will ping +* you one day :), so we have to do something. Yes. This would be really nice if it was passed to the userspace. Especially since the iscsi daemon re-scans the SCSI blk device when this is triggered.
yes, we will include this in later revision
Quoted 23 lines
drivers/scsi/bnx2i/bnx2i_hwi.c line 1330
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+*/ +iscsi_conn_printk (KERN_ALERT , bnx2i_conn->cls_conn->dd_data, +"async: scsi events not supported\n" );You might want to include the SCSI sense buffer as well in the printk.
.. snip ..
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+static void bnx2i_process_iscsi_error (struct bnx2i_hba *hba, +struct iscsi_kcqe *iscsi_err) +{.. snip ..
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_hwi.c new file +1
-0+char additional_notice[64 ];.. snip ..
drivers/scsi/bnx2i/bnx2i_hwi.c line 1631
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_hwi.c new file +3
-0+switch (iscsi_err->completion_status) { +case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR : +strcpy (additional_notice,"hdr digest err" );You don't want to memset the '
additional_notice' so that you are guaranteed to have the \0 at the end?
.. snip ..
Quoted 8 lines
drivers/scsi/bnx2i/bnx2i_init.c line 40
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_init.c new file +4
-0+ +unsigned int event_coal_div =1 ; +module_param (event_coal_div, int,0664 ); +MODULE_PARM_DESC (event_coal_div,"Event Coalescing Divide Factor" );Should that have an #ifdef around it? You are not using it except in the code that has the #ifdef _EVENT_COALESCE_
.. snip..
Thanks. Will make this change in the next revision
Quoted 9 lines
Quoted 2 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +2
-0+static struct iscsi_endpoint *bnx2i_alloc_ep (struct bnx2i_hba *hba) +{.. snip ..
drivers/scsi/bnx2i/bnx2i_iscsi.c line 521
Quoted 3 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +3
-0+ tcp_port =bnx2i_alloc_tcp_port (); +if (!tcp_port) { +printk (KERN_ERR "bnx2i: run 'bnx2id' to alloc tcp ports\n" );Is that correct? Or will this be handled by iscsid?
This will be handled by a separate user daemon, bnx2id
Quoted 11 lines
.. snip ..
Quoted 10 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +10
-0+static void bnx2i_cleanup_task (struct iscsi_conn *conn, +struct iscsi_task *task) +{ +struct bnx2i_conn *bnx2i_conn = conn->dd_data; +struct bnx2i_hba *hba = bnx2i_conn->hba; + +/* +* mgmt task or cmd completed while tmf in progress. +*/ +if (!task->sc)
Quoted 8 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c line 1216
Quoted 5 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +5
-0+return ; +/* +* ANIL +* do we have to do this for other tmfs? +*/ Not finished TODO?
.. snip ..
We just forgot to remove the comments
Quoted 16 lines
Quoted 4 lines
+ */
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +2
-0+static struct scsi_host_template bnx2i_host_template = { + .module =THIS_MODULE ,drivers/scsi/bnx2i/bnx2i_iscsi.c line 2020
Quoted 10 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +10
-0+ .name = "Broadcom Offload iSCSI Initiator", + .proc_name = "bnx2i", + .queuecommand = iscsi_queuecommand, + .slave_alloc = iscsi_slave_alloc, + .eh_abort_handler = iscsi_eh_abort, +/* +* Anil +* uncomment this when we know if we need to do a +* ISCSI_OPCODE_CLEANUP_REQUEST on tasks that are affected by +* the lu reset. What is the verdict?
Will remove these old notes between Mike & myself. This has to do with reclaiming task resources which got affected by lun reset and it correctly handled by the driver set
Quoted 7 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c line 2024
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +4
-0+.eh_device_reset_handler = iscsi_eh_device_reset, +*/ + .eh_target_reset_handler = iscsi_eh_target_reset, +/* TODO - just make this the max sessions * max_cmds_per_session */ And is 1024 the right value?
Because the same driver handles multiple devices with different hardware capabilities, we recently changed the driver to assign 'can_queue' value based on the device type. This change got missed out in this revision as Mike Christie merged this change a couple of days back.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
In reply to Michael ChanQuoted 4 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +4
-0+struct bnx2i_async_msg { +#if defined(__BIG_ENDIAN) +u8 op_code; +u8 reserved1;
drivers/scsi/bnx2i/57xx_iscsi_hsi.h line 30
Quoted 10 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +10
-0+u16 reserved0; +#elif defined(__LITTLE_ENDIAN) +u16 reserved0; +u8 reserved1; +u8 op_code; +#endif +u32 reserved2; +u32 exp_cmd_sn; +u32 max_cmd_sn; +u32 reserved3[2 ];
Please don't do the ifdef big endian mess. Just read the whole 32bit word and do mask and shift operations to extract the actual value.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 9 lines · Christoph Hellwig
Quoted 9 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +9
-0+struct bnx2i_async_msg { +#if defined(__BIG_ENDIAN) +u8 op_code; +u8 reserved1; +u16 reserved0; +#elif defined(__LITTLE_ENDIAN) +u16 reserved0; +u8 reserved1; +u8 op_code;
Quoted 10 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h line 30
Quoted 5 lines
drivers/scsi/bnx2i/57xx_iscsi_hsi.h new file +5
-0+#endif +u32 reserved2; +u32 exp_cmd_sn; +u32 max_cmd_sn; +u32 reserved3[2 ];Please don't do the ifdef big endian mess. Just read the whole 32bit word and do mask and shift operations to extract the actual value.
I agree with you that u32 is cleaner in some cases. We can just change it to u32 op_code and we just need a OP_CODE_MASK of 0xff.
We'll go through this .h file and remove some of this big endian stuff and also the duplicate constants pointed out earlier.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
In reply to Michael ChanHi Michael, I was reading over the driver to try and figure out how you handle allocating source ports for the offloaded TCP connections you make so that they don't collide with the main network stack. It looks like you have:
drivers/scsi/bnx2i/bnx2i_iscsi.c line 66
Quoted 6 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +6
-0+/** +* bnx2i_alloc_tcp_port - allocates a tcp port from the free list +* +* Assumes this function is called with 'bnx2i_resc_lock' held. +*/ +static u16 bnx2i_alloc_tcp_port (void )
that has some failure code:
drivers/scsi/bnx2i/bnx2i_iscsi.c line 521
Quoted 2 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +2
-0+if (!tcp_port) { +printk (KERN_ERR "bnx2i: run 'bnx2id' to alloc tcp ports\n" );
but I don't know what bnx2id is?
and I didn't see anywhere that bnx2i_get_tcp_port_requirements() is actually called, and it's not exported?
Quoted 8 lines
drivers/scsi/bnx2i/bnx2i_init.c new file +8
-0+/** +* bnx2i_get_tcp_port_requirements - returns num tcp ports to alloc/bind +* +* driver returns the number of TCP ports to be allocated/bound by 'bnx2id' +* daemon. Return value of '0' means driver has everything to support +* max iscsi connections on enumerated NX2 devices +*/ +int bnx2i_get_tcp_port_requirements (void )
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 14 lines · Roland Dreier
Hi Michael, I was reading over the driver to try and figure out how you handle allocating source ports for the offloaded TCP connections you make so that they don't collide with the main network stack. It looks like you have:
drivers/scsi/bnx2i/bnx2i_iscsi.c line 66
Quoted 6 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +6
-0+/** +* bnx2i_alloc_tcp_port - allocates a tcp port from the free list +* +* Assumes this function is called with 'bnx2i_resc_lock' held. +*/ +static u16 bnx2i_alloc_tcp_port (void )that has some failure code:
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c line 521
Quoted 2 lines
drivers/scsi/bnx2i/bnx2i_iscsi.c new file +2
-0+if (!tcp_port) { +printk (KERN_ERR "bnx2i: run 'bnx2id' to alloc tcp ports\n" );but I don't know what bnx2id is?
'bnx2id' is the user component in this solution. bnx2id daemon uses socket calls to bind tcp ports in high range and hands them over to driver. This is how iscsi driver tries to solve tcp port collision issue. User daemon communicates with the driver using sysfs and tcp port related functions are bnx2i_read_tcp_portd_*/bnx2i_write_tcp_portd_* (reference: bnx2i_sysfs.c)
Quoted 4 lines
and I didn't see anywhere that
bnx2i_get_tcp_port_requirements()is actually called, and it's not exported?
Quoted 9 lines
drivers/scsi/bnx2i/bnx2i_init.c line 82
Quoted 8 lines
drivers/scsi/bnx2i/bnx2i_init.c new file +8
-0+/** +* bnx2i_get_tcp_port_requirements - returns num tcp ports to alloc/bind +* +* driver returns the number of TCP ports to be allocated/bound by 'bnx2id' +* daemon. Return value of '0' means driver has everything to support +* max iscsi connections on enumerated NX2 devices +*/ +int bnx2i_get_tcp_port_requirements (void )
Actually this logic was simplified by adding a new member, 'num_required' to 'tcp_port_mgmt' structure. This call is no more required, will remove bnx2i_get_tcp_port_requirements() in the next driver revision
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 6 lines
'bnx2id' is the user component in this solution. bnx2id daemon uses socket calls to bind tcp ports in high range and hands them over to driver. This is how iscsi driver tries to solve tcp port collision issue. User daemon communicates with the driver using sysfs and tcp port related functions are bnx2i_read_tcp_portd_*/bnx2i_write_tcp_portd_* (reference:
bnx2i_sysfs.c)
So you are creating sockets just to reserve TCP ports to avoid host stack clashes with your offload engine? Wasn't this approach strongly rejected (in the context of iWARP) in the past?
- R.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 11 lines · Roland Dreier
Quoted 6 lines
'bnx2id' is the user component in this solution. bnx2id daemon uses socket calls to bind tcp ports in high range and hands them over to driver. This is how iscsi driver tries to solve tcp port collision issue. User daemon communicates with the driver using sysfs and tcp port related functions are bnx2i_read_tcp_portd_*/bnx2i_write_tcp_portd_* (reference:
bnx2i_sysfs.c)So you are creating sockets just to reserve TCP ports to avoid host stack clashes with your offload engine? Wasn't this approach strongly rejected (in the context of iWARP) in the past?
We're doing it in userspace, so I don't if that makes it any better or any worse.
Roland, what do you suggest? We can do it like cma_alloc_any_port() in cma.c.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 2 lines
We're doing it in userspace, so I don't if that makes it any better or any worse.
How do you do it in userspace? With a bind()? That is a little wasteful in that you are reserving a local addr/port when all you really need to reserve is the actual local/remote 4-tuple that you are going to use for the connection, but that's not horrible.
Quoted 2 lines
Roland, what do you suggest? We can do it like
cma_alloc_any_port()incma.c.
Actually cma.c still has the problem of host/offload port space collisions.
The whole port sharing thing is a mess -- I was hoping you had come up with a good solution that cma.c could steal to be honest, so I don't have any better ideas at the moment.
- R.
David Miller
maintainerRe: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
In reply to Roland DreierFrom: Roland Dreier <[email protected]>
Date: Tue, 27 May 2008 07:38:19 -0700
Quoted 3 lines
So you are creating sockets just to reserve TCP ports to avoid host stack clashes with your offload engine? Wasn't this approach strongly rejected (in the context of iWARP) in the past?
Yes, it was, and likewise similar hacks in other areas will be rejected similarly.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 10 lines · David Miller
From: Roland Dreier <[email protected]>
Date: Tue, 27 May 2008 07:38:19 -0700Quoted 3 lines
So you are creating sockets just to reserve TCP ports to avoid host stack clashes with your offload engine? Wasn't this approach strongly rejected (in the context of iWARP) in the past?
Yes, it was, and likewise similar hacks in other areas will be rejected similarly.
If we change the implementation to use a separate IP address and separate MAC address for iSCSI, will it be acceptable? The iSCSI IP/MAC addresses will be unknown to the Linux TCP stack and so no sharing of the 4-tuple space will be needed.
The patches will be very similar, except that all inet calls and notifiers will be removed.
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Quoted 7 lines · Michael Chan
If we change the implementation to use a separate IP address and separate MAC address for iSCSI, will it be acceptable? The iSCSI IP/MAC addresses will be unknown to the Linux TCP stack and so no sharing of the 4-tuple space will be needed.
The patches will be very similar, except that all inet calls and notifiers will be removed.
IMO a totally separate MAC and IP would definitely be preferred...
Jeff
Re: [PATCH 3/3] bnx2i: Add bnx2i iSCSI driver.
Hi all,
Quoted 6 lines · Jeff Garzik
Quoted 5 lines · Michael Chan
If we change the implementation to use a separate IP address and separate MAC address for iSCSI, will it be acceptable? The iSCSI IP/MAC addresses will be unknown to the Linux TCP stack and so no sharing of the 4-tuple space will be needed.
Quoted 6 lines
Quoted 2 lines
The patches will be very similar, except that all inet calls and notifiers will be removed.
IMO a totally separate MAC and IP would definitely be preferred...
And as it happens, the machines I have here claim to use a different MAC address for iSCSI anyway. So we should be using them.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Markus Rex, HRB 16746 (AG Nürnberg)