Initial commit. Based on v3.18 master origin/HEAD origin/master
authorVladimir Sokolovsky <vlad@mellanox.com>
Mon, 8 Dec 2014 15:07:59 +0000 (17:07 +0200)
committerVladimir Sokolovsky <vlad@mellanox.com>
Mon, 8 Dec 2014 15:07:59 +0000 (17:07 +0200)
Signed-off-by: Vladimir Sokolovsky <vlad@mellanox.com>
589 files changed:
.gitignore [new file with mode: 0644]
drivers/infiniband/Kconfig [new file with mode: 0644]
drivers/infiniband/Makefile [new file with mode: 0644]
drivers/infiniband/core/Makefile [new file with mode: 0644]
drivers/infiniband/core/addr.c [new file with mode: 0644]
drivers/infiniband/core/agent.c [new file with mode: 0644]
drivers/infiniband/core/agent.h [new file with mode: 0644]
drivers/infiniband/core/cache.c [new file with mode: 0644]
drivers/infiniband/core/cm.c [new file with mode: 0644]
drivers/infiniband/core/cm_msgs.h [new file with mode: 0644]
drivers/infiniband/core/cma.c [new file with mode: 0644]
drivers/infiniband/core/core_priv.h [new file with mode: 0644]
drivers/infiniband/core/device.c [new file with mode: 0644]
drivers/infiniband/core/fmr_pool.c [new file with mode: 0644]
drivers/infiniband/core/iwcm.c [new file with mode: 0644]
drivers/infiniband/core/iwcm.h [new file with mode: 0644]
drivers/infiniband/core/iwpm_msg.c [new file with mode: 0644]
drivers/infiniband/core/iwpm_util.c [new file with mode: 0644]
drivers/infiniband/core/iwpm_util.h [new file with mode: 0644]
drivers/infiniband/core/mad.c [new file with mode: 0644]
drivers/infiniband/core/mad_priv.h [new file with mode: 0644]
drivers/infiniband/core/mad_rmpp.c [new file with mode: 0644]
drivers/infiniband/core/mad_rmpp.h [new file with mode: 0644]
drivers/infiniband/core/multicast.c [new file with mode: 0644]
drivers/infiniband/core/netlink.c [new file with mode: 0644]
drivers/infiniband/core/packer.c [new file with mode: 0644]
drivers/infiniband/core/sa.h [new file with mode: 0644]
drivers/infiniband/core/sa_query.c [new file with mode: 0644]
drivers/infiniband/core/smi.c [new file with mode: 0644]
drivers/infiniband/core/smi.h [new file with mode: 0644]
drivers/infiniband/core/sysfs.c [new file with mode: 0644]
drivers/infiniband/core/ucm.c [new file with mode: 0644]
drivers/infiniband/core/ucma.c [new file with mode: 0644]
drivers/infiniband/core/ud_header.c [new file with mode: 0644]
drivers/infiniband/core/umem.c [new file with mode: 0644]
drivers/infiniband/core/user_mad.c [new file with mode: 0644]
drivers/infiniband/core/uverbs.h [new file with mode: 0644]
drivers/infiniband/core/uverbs_cmd.c [new file with mode: 0644]
drivers/infiniband/core/uverbs_main.c [new file with mode: 0644]
drivers/infiniband/core/uverbs_marshall.c [new file with mode: 0644]
drivers/infiniband/core/verbs.c [new file with mode: 0644]
drivers/infiniband/hw/Makefile [new file with mode: 0644]
drivers/infiniband/hw/amso1100/Kbuild [new file with mode: 0644]
drivers/infiniband/hw/amso1100/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2.h [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_ae.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_ae.h [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_alloc.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_cm.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_cq.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_intr.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_mm.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_mq.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_mq.h [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_pd.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_provider.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_provider.h [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_qp.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_rnic.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_status.h [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_user.h [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_vq.c [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_vq.h [new file with mode: 0644]
drivers/infiniband/hw/amso1100/c2_wr.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/Makefile [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/cxio_dbg.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/cxio_hal.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/cxio_hal.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/cxio_resource.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/cxio_resource.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/cxio_wr.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_cm.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_cm.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_cq.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_ev.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_mem.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_provider.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_provider.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_qp.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/iwch_user.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb3/tcb.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/Makefile [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/cm.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/cq.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/device.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/ev.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/id_table.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/iw_cxgb4.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/mem.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/provider.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/qp.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/resource.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/t4.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/user.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/ehca/Makefile [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_av.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_classes.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_classes_pSeries.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_cq.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_eq.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_hca.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_irq.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_irq.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_iverbs.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_main.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_mcast.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_mrmw.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_mrmw.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_pd.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_qes.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_qp.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_reqs.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_sqp.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_tools.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ehca_uverbs.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/hcp_if.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/hcp_if.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/hcp_phyp.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/hcp_phyp.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/hipz_fns.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/hipz_fns_core.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/hipz_hw.h [new file with mode: 0644]
drivers/infiniband/hw/ehca/ipz_pt_fn.c [new file with mode: 0644]
drivers/infiniband/hw/ehca/ipz_pt_fn.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/ipath/Makefile [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_common.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_cq.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_debug.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_diag.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_dma.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_driver.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_eeprom.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_file_ops.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_fs.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_iba6110.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_init_chip.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_intr.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_kernel.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_keys.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_mad.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_mmap.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_mr.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_qp.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_rc.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_registers.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_ruc.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_sdma.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_srq.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_stats.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_sysfs.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_uc.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_ud.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_user_pages.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_user_sdma.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_user_sdma.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_verbs.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_verbs.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_verbs_mcast.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_wc_ppc64.c [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_wc_x86_64.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/mlx4/Makefile [new file with mode: 0644]
drivers/infiniband/hw/mlx4/ah.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/alias_GUID.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/cm.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/cq.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/doorbell.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/mad.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/main.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/mcg.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/mlx4_ib.h [new file with mode: 0644]
drivers/infiniband/hw/mlx4/mr.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/qp.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/srq.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/sysfs.c [new file with mode: 0644]
drivers/infiniband/hw/mlx4/user.h [new file with mode: 0644]
drivers/infiniband/hw/mlx5/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/mlx5/Makefile [new file with mode: 0644]
drivers/infiniband/hw/mlx5/ah.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/cq.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/doorbell.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/mad.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/main.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/mem.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/mlx5_ib.h [new file with mode: 0644]
drivers/infiniband/hw/mlx5/mr.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/qp.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/srq.c [new file with mode: 0644]
drivers/infiniband/hw/mlx5/user.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/mthca/Makefile [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_allocator.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_av.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_catas.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_cmd.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_cmd.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_config_reg.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_cq.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_dev.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_doorbell.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_eq.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_mad.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_main.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_mcg.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_memfree.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_memfree.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_mr.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_pd.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_profile.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_profile.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_provider.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_provider.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_qp.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_reset.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_srq.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_uar.c [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_user.h [new file with mode: 0644]
drivers/infiniband/hw/mthca/mthca_wqe.h [new file with mode: 0644]
drivers/infiniband/hw/nes/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/nes/Makefile [new file with mode: 0644]
drivers/infiniband/hw/nes/nes.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_cm.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_cm.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_context.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_hw.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_hw.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_mgt.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_mgt.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_nic.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_user.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_utils.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_verbs.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_verbs.h [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/Makefile [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma.h [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_abi.h [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_ah.c [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_ah.h [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_hw.c [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_hw.h [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_main.c [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_sli.h [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_stats.c [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_stats.h [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c [new file with mode: 0644]
drivers/infiniband/hw/ocrdma/ocrdma_verbs.h [new file with mode: 0644]
drivers/infiniband/hw/qib/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/qib/Makefile [new file with mode: 0644]
drivers/infiniband/hw/qib/qib.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_6120_regs.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_7220.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_7220_regs.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_7322_regs.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_common.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_cq.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_debugfs.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_debugfs.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_diag.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_dma.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_driver.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_eeprom.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_file_ops.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_fs.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_iba6120.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_iba7220.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_iba7322.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_init.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_intr.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_keys.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_mad.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_mad.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_mmap.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_mr.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_pcie.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_pio_copy.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_qp.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_qsfp.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_qsfp.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_rc.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_ruc.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_sd7220.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_sdma.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_srq.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_sysfs.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_twsi.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_tx.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_uc.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_ud.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_user_pages.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_user_sdma.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_user_sdma.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_verbs.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_verbs.h [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_verbs_mcast.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_wc_ppc64.c [new file with mode: 0644]
drivers/infiniband/hw/qib/qib_wc_x86_64.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/usnic/Makefile [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_abi.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_common_pkt_hdr.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_common_util.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_debugfs.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_debugfs.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_fwd.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_fwd.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib_main.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib_qp_grp.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib_sysfs.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib_sysfs.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib_verbs.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_ib_verbs.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_log.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_transport.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_transport.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_uiom.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_uiom.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_uiom_interval_tree.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_uiom_interval_tree.h [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_vnic.c [new file with mode: 0644]
drivers/infiniband/hw/usnic/usnic_vnic.h [new file with mode: 0644]
drivers/infiniband/ulp/Makefile [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/Kconfig [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/Makefile [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib.h [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_cm.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_ethtool.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_fs.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_ib.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_main.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_multicast.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_netlink.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_verbs.c [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_vlan.c [new file with mode: 0644]
drivers/infiniband/ulp/iser/Kconfig [new file with mode: 0644]
drivers/infiniband/ulp/iser/Makefile [new file with mode: 0644]
drivers/infiniband/ulp/iser/iscsi_iser.c [new file with mode: 0644]
drivers/infiniband/ulp/iser/iscsi_iser.h [new file with mode: 0644]
drivers/infiniband/ulp/iser/iser_initiator.c [new file with mode: 0644]
drivers/infiniband/ulp/iser/iser_memory.c [new file with mode: 0644]
drivers/infiniband/ulp/iser/iser_verbs.c [new file with mode: 0644]
drivers/infiniband/ulp/isert/Kconfig [new file with mode: 0644]
drivers/infiniband/ulp/isert/Makefile [new file with mode: 0644]
drivers/infiniband/ulp/isert/ib_isert.c [new file with mode: 0644]
drivers/infiniband/ulp/isert/ib_isert.h [new file with mode: 0644]
drivers/infiniband/ulp/isert/isert_proto.h [new file with mode: 0644]
drivers/infiniband/ulp/srp/Kbuild [new file with mode: 0644]
drivers/infiniband/ulp/srp/Kconfig [new file with mode: 0644]
drivers/infiniband/ulp/srp/ib_srp.c [new file with mode: 0644]
drivers/infiniband/ulp/srp/ib_srp.h [new file with mode: 0644]
drivers/infiniband/ulp/srpt/Kconfig [new file with mode: 0644]
drivers/infiniband/ulp/srpt/Makefile [new file with mode: 0644]
drivers/infiniband/ulp/srpt/ib_dm_mad.h [new file with mode: 0644]
drivers/infiniband/ulp/srpt/ib_srpt.c [new file with mode: 0644]
drivers/infiniband/ulp/srpt/ib_srpt.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/Makefile [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/adapter.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/ael1002.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/aq100x.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/common.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/cxgb3_ctl_defs.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/cxgb3_defs.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/cxgb3_ioctl.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/firmware_exports.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/l2t.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/l2t.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/mc5.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/regs.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/sge.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/sge_defs.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/t3_cpl.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/t3_hw.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/t3cdev.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/version.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/vsc8211.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb3/xgmac.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/Makefile [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/l2t.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/l2t.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/sge.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/t4_hw.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/t4_msg.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/t4_regs.h [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/Kconfig [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/Makefile [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be.h [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be_cmds.c [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be_cmds.h [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be_ethtool.c [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be_hw.h [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be_main.c [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be_roce.c [new file with mode: 0644]
drivers/net/ethernet/emulex/benet/be_roce.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/Kconfig [new file with mode: 0644]
drivers/net/ethernet/mellanox/Makefile [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/Kconfig [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/Makefile [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/alloc.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/catas.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/cmd.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/cq.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_clock.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_cq.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_main.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_netdev.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_port.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_port.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_resources.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_rx.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_selftest.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/en_tx.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/eq.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/fw.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/fw.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/icm.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/icm.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/intf.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/main.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/mcg.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/mlx4.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/mr.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/pd.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/port.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/profile.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/qp.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/reset.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/resource_tracker.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/sense.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx4/srq.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/Kconfig [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/Makefile [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/alloc.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/cmd.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/cq.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/debugfs.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/eq.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/fw.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/health.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/mad.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/main.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/mcg.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/mr.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/pd.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/port.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/qp.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/srq.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/uar.c [new file with mode: 0644]
drivers/scsi/Makefile [new file with mode: 0644]
drivers/scsi/cxgbi/Kconfig [new file with mode: 0644]
drivers/scsi/cxgbi/Makefile [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb3i/Kbuild [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb3i/Kconfig [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb3i/cxgb3i.c [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb3i/cxgb3i.h [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb4i/Kbuild [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb4i/Kconfig [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb4i/cxgb4i.c [new file with mode: 0644]
drivers/scsi/cxgbi/cxgb4i/cxgb4i.h [new file with mode: 0644]
drivers/scsi/cxgbi/libcxgbi.c [new file with mode: 0644]
drivers/scsi/cxgbi/libcxgbi.h [new file with mode: 0644]
drivers/scsi/scsi_priv.h [new file with mode: 0644]
drivers/scsi/scsi_transport_srp.c [new file with mode: 0644]
include/linux/mlx4/cmd.h [new file with mode: 0644]
include/linux/mlx4/cq.h [new file with mode: 0644]
include/linux/mlx4/device.h [new file with mode: 0644]
include/linux/mlx4/doorbell.h [new file with mode: 0644]
include/linux/mlx4/driver.h [new file with mode: 0644]
include/linux/mlx4/qp.h [new file with mode: 0644]
include/linux/mlx4/srq.h [new file with mode: 0644]
include/linux/mlx5/cmd.h [new file with mode: 0644]
include/linux/mlx5/cq.h [new file with mode: 0644]
include/linux/mlx5/device.h [new file with mode: 0644]
include/linux/mlx5/doorbell.h [new file with mode: 0644]
include/linux/mlx5/driver.h [new file with mode: 0644]
include/linux/mlx5/mlx5_ifc.h [new file with mode: 0644]
include/linux/mlx5/qp.h [new file with mode: 0644]
include/linux/mlx5/srq.h [new file with mode: 0644]
include/rdma/ib.h [new file with mode: 0644]
include/rdma/ib_addr.h [new file with mode: 0644]
include/rdma/ib_cache.h [new file with mode: 0644]
include/rdma/ib_cm.h [new file with mode: 0644]
include/rdma/ib_fmr_pool.h [new file with mode: 0644]
include/rdma/ib_mad.h [new file with mode: 0644]
include/rdma/ib_marshall.h [new file with mode: 0644]
include/rdma/ib_pack.h [new file with mode: 0644]
include/rdma/ib_pma.h [new file with mode: 0644]
include/rdma/ib_sa.h [new file with mode: 0644]
include/rdma/ib_smi.h [new file with mode: 0644]
include/rdma/ib_umem.h [new file with mode: 0644]
include/rdma/ib_verbs.h [new file with mode: 0644]
include/rdma/iw_cm.h [new file with mode: 0644]
include/rdma/iw_portmap.h [new file with mode: 0644]
include/rdma/rdma_cm.h [new file with mode: 0644]
include/rdma/rdma_cm_ib.h [new file with mode: 0644]
include/rdma/rdma_netlink.h [new file with mode: 0644]
include/scsi/scsi_transport_srp.h [new file with mode: 0644]
include/scsi/srp.h [new file with mode: 0644]
include/uapi/linux/rds.h [new file with mode: 0644]
include/uapi/rdma/Kbuild [new file with mode: 0644]
include/uapi/rdma/ib_user_cm.h [new file with mode: 0644]
include/uapi/rdma/ib_user_mad.h [new file with mode: 0644]
include/uapi/rdma/ib_user_sa.h [new file with mode: 0644]
include/uapi/rdma/ib_user_verbs.h [new file with mode: 0644]
include/uapi/rdma/rdma_netlink.h [new file with mode: 0644]
include/uapi/rdma/rdma_user_cm.h [new file with mode: 0644]
net/rds/Kconfig [new file with mode: 0644]
net/rds/Makefile [new file with mode: 0644]
net/rds/af_rds.c [new file with mode: 0644]
net/rds/bind.c [new file with mode: 0644]
net/rds/cong.c [new file with mode: 0644]
net/rds/connection.c [new file with mode: 0644]
net/rds/ib.c [new file with mode: 0644]
net/rds/ib.h [new file with mode: 0644]
net/rds/ib_cm.c [new file with mode: 0644]
net/rds/ib_rdma.c [new file with mode: 0644]
net/rds/ib_recv.c [new file with mode: 0644]
net/rds/ib_ring.c [new file with mode: 0644]
net/rds/ib_send.c [new file with mode: 0644]
net/rds/ib_stats.c [new file with mode: 0644]
net/rds/ib_sysctl.c [new file with mode: 0644]
net/rds/info.c [new file with mode: 0644]
net/rds/info.h [new file with mode: 0644]
net/rds/iw.c [new file with mode: 0644]
net/rds/iw.h [new file with mode: 0644]
net/rds/iw_cm.c [new file with mode: 0644]
net/rds/iw_rdma.c [new file with mode: 0644]
net/rds/iw_recv.c [new file with mode: 0644]
net/rds/iw_ring.c [new file with mode: 0644]
net/rds/iw_send.c [new file with mode: 0644]
net/rds/iw_stats.c [new file with mode: 0644]
net/rds/iw_sysctl.c [new file with mode: 0644]
net/rds/loop.c [new file with mode: 0644]
net/rds/loop.h [new file with mode: 0644]
net/rds/message.c [new file with mode: 0644]
net/rds/page.c [new file with mode: 0644]
net/rds/rdma.c [new file with mode: 0644]
net/rds/rdma_transport.c [new file with mode: 0644]
net/rds/rdma_transport.h [new file with mode: 0644]
net/rds/rds.h [new file with mode: 0644]
net/rds/recv.c [new file with mode: 0644]
net/rds/send.c [new file with mode: 0644]
net/rds/stats.c [new file with mode: 0644]
net/rds/sysctl.c [new file with mode: 0644]
net/rds/tcp.c [new file with mode: 0644]
net/rds/tcp.h [new file with mode: 0644]
net/rds/tcp_connect.c [new file with mode: 0644]
net/rds/tcp_listen.c [new file with mode: 0644]
net/rds/tcp_recv.c [new file with mode: 0644]
net/rds/tcp_send.c [new file with mode: 0644]
net/rds/tcp_stats.c [new file with mode: 0644]
net/rds/threads.c [new file with mode: 0644]
net/rds/transport.c [new file with mode: 0644]
net/sunrpc/xprtrdma/Makefile [new file with mode: 0644]
net/sunrpc/xprtrdma/rpc_rdma.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_marshal.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_sendto.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_transport.c [new file with mode: 0644]
net/sunrpc/xprtrdma/transport.c [new file with mode: 0644]
net/sunrpc/xprtrdma/verbs.c [new file with mode: 0644]
net/sunrpc/xprtrdma/xprt_rdma.h [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e213b27
--- /dev/null
@@ -0,0 +1,98 @@
+#
+# NOTE! Don't add files that are generated in specific
+# subdirectories here. Add them in the ".gitignore" file
+# in that subdirectory instead.
+#
+# NOTE! Please use 'git ls-files -i --exclude-standard'
+# command after changing this file, to see if there are
+# any tracked files which get ignored after the change.
+#
+# Normal rules
+#
+.*
+*.o
+*.o.*
+*.a
+*.s
+*.ko
+*.so
+*.so.dbg
+*.mod.c
+*.i
+*.lst
+*.symtypes
+*.order
+*.elf
+*.bin
+*.gz
+*.bz2
+*.lzma
+*.xz
+*.lz4
+*.lzo
+*.patch
+*.gcno
+modules.builtin
+Module.symvers
+*.dwo
+
+#
+# Top-level generic files
+#
+/tags
+/TAGS
+/linux
+/vmlinux
+/vmlinuz
+/System.map
+/Module.markers
+
+#
+# Debian directory (make deb-pkg)
+#
+/debian/
+
+#
+# git files that we don't want to ignore even it they are dot-files
+#
+!.gitignore
+!.mailmap
+
+#
+# Generated include files
+#
+include/config
+include/generated
+arch/*/include/generated
+
+# stgit generated dirs
+patches-*
+
+# quilt's files
+patches
+series
+
+# cscope files
+cscope.*
+ncscope.*
+
+# gnu global files
+GPATH
+GRTAGS
+GSYMS
+GTAGS
+
+*.orig
+*~
+\#*#
+
+#
+# Leavings from module signing
+#
+extra_certificates
+signing_key.priv
+signing_key.x509
+x509.genkey
+
+# Kconfig presets
+all.config
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
new file mode 100644 (file)
index 0000000..7708939
--- /dev/null
@@ -0,0 +1,67 @@
+menuconfig INFINIBAND
+       tristate "InfiniBand support"
+       depends on PCI || BROKEN
+       depends on HAS_IOMEM
+       depends on NET
+       depends on INET
+       depends on m || IPV6 != m
+       ---help---
+         Core support for InfiniBand (IB).  Make sure to also select
+         any protocols you wish to use as well as drivers for your
+         InfiniBand hardware.
+
+if INFINIBAND
+
+config INFINIBAND_USER_MAD
+       tristate "InfiniBand userspace MAD support"
+       depends on INFINIBAND
+       ---help---
+         Userspace InfiniBand Management Datagram (MAD) support.  This
+         is the kernel side of the userspace MAD support, which allows
+         userspace processes to send and receive MADs. You will also
+         need libibumad from <http://www.openfabrics.org/downloads/management/>.
+
+config INFINIBAND_USER_ACCESS
+       tristate "InfiniBand userspace access (verbs and CM)"
+       select ANON_INODES
+       ---help---
+         Userspace InfiniBand access support.  This enables the
+         kernel side of userspace verbs and the userspace
+         communication manager (CM).  This allows userspace processes
+         to set up connections and directly access InfiniBand
+         hardware for fast-path operations.  You will also need
+         libibverbs, libibcm and a hardware driver library from
+         <http://www.openfabrics.org/git/>.
+
+config INFINIBAND_USER_MEM
+       bool
+       depends on INFINIBAND_USER_ACCESS != n
+       default y
+
+config INFINIBAND_ADDR_TRANS
+       bool
+       depends on INFINIBAND
+       default y
+
+source "drivers/infiniband/hw/mthca/Kconfig"
+source "drivers/infiniband/hw/ipath/Kconfig"
+source "drivers/infiniband/hw/qib/Kconfig"
+source "drivers/infiniband/hw/ehca/Kconfig"
+source "drivers/infiniband/hw/amso1100/Kconfig"
+source "drivers/infiniband/hw/cxgb3/Kconfig"
+source "drivers/infiniband/hw/cxgb4/Kconfig"
+source "drivers/infiniband/hw/mlx4/Kconfig"
+source "drivers/infiniband/hw/mlx5/Kconfig"
+source "drivers/infiniband/hw/nes/Kconfig"
+source "drivers/infiniband/hw/ocrdma/Kconfig"
+source "drivers/infiniband/hw/usnic/Kconfig"
+
+source "drivers/infiniband/ulp/ipoib/Kconfig"
+
+source "drivers/infiniband/ulp/srp/Kconfig"
+source "drivers/infiniband/ulp/srpt/Kconfig"
+
+source "drivers/infiniband/ulp/iser/Kconfig"
+source "drivers/infiniband/ulp/isert/Kconfig"
+
+endif # INFINIBAND
diff --git a/drivers/infiniband/Makefile b/drivers/infiniband/Makefile
new file mode 100644 (file)
index 0000000..dc21836
--- /dev/null
@@ -0,0 +1,3 @@
+obj-$(CONFIG_INFINIBAND)               += core/
+obj-$(CONFIG_INFINIBAND)               += hw/
+obj-$(CONFIG_INFINIBAND)               += ulp/
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
new file mode 100644 (file)
index 0000000..ffd0af6
--- /dev/null
@@ -0,0 +1,33 @@
+infiniband-$(CONFIG_INFINIBAND_ADDR_TRANS)     := rdma_cm.o
+user_access-$(CONFIG_INFINIBAND_ADDR_TRANS)    := rdma_ucm.o
+
+obj-$(CONFIG_INFINIBAND) +=            ib_core.o ib_mad.o ib_sa.o \
+                                       ib_cm.o iw_cm.o ib_addr.o \
+                                       $(infiniband-y)
+obj-$(CONFIG_INFINIBAND_USER_MAD) +=   ib_umad.o
+obj-$(CONFIG_INFINIBAND_USER_ACCESS) +=        ib_uverbs.o ib_ucm.o \
+                                       $(user_access-y)
+
+ib_core-y :=                   packer.o ud_header.o verbs.o sysfs.o \
+                               device.o fmr_pool.o cache.o netlink.o
+ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o
+
+ib_mad-y :=                    mad.o smi.o agent.o mad_rmpp.o
+
+ib_sa-y :=                     sa_query.o multicast.o
+
+ib_cm-y :=                     cm.o
+
+iw_cm-y :=                     iwcm.o iwpm_util.o iwpm_msg.o
+
+rdma_cm-y :=                   cma.o
+
+rdma_ucm-y :=                  ucma.o
+
+ib_addr-y :=                   addr.o
+
+ib_umad-y :=                   user_mad.o
+
+ib_ucm-y :=                    ucm.o
+
+ib_uverbs-y :=                 uverbs_main.o uverbs_cmd.o uverbs_marshall.o
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
new file mode 100644 (file)
index 0000000..8172d37
--- /dev/null
@@ -0,0 +1,565 @@
+/*
+ * Copyright (c) 2005 Voltaire Inc.  All rights reserved.
+ * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
+ * Copyright (c) 1999-2005, Mellanox Technologies, Inc. All rights reserved.
+ * Copyright (c) 2005 Intel Corporation.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/mutex.h>
+#include <linux/inetdevice.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <linux/module.h>
+#include <net/arp.h>
+#include <net/neighbour.h>
+#include <net/route.h>
+#include <net/netevent.h>
+#include <net/addrconf.h>
+#include <net/ip6_route.h>
+#include <rdma/ib_addr.h>
+#include <rdma/ib.h>
+
+MODULE_AUTHOR("Sean Hefty");
+MODULE_DESCRIPTION("IB Address Translation");
+MODULE_LICENSE("Dual BSD/GPL");
+
+struct addr_req {
+       struct list_head list;
+       struct sockaddr_storage src_addr;
+       struct sockaddr_storage dst_addr;
+       struct rdma_dev_addr *addr;
+       struct rdma_addr_client *client;
+       void *context;
+       void (*callback)(int status, struct sockaddr *src_addr,
+                        struct rdma_dev_addr *addr, void *context);
+       unsigned long timeout;
+       int status;
+};
+
+static void process_req(struct work_struct *work);
+
+static DEFINE_MUTEX(lock);
+static LIST_HEAD(req_list);
+static DECLARE_DELAYED_WORK(work, process_req);
+static struct workqueue_struct *addr_wq;
+
+int rdma_addr_size(struct sockaddr *addr)
+{
+       switch (addr->sa_family) {
+       case AF_INET:
+               return sizeof(struct sockaddr_in);
+       case AF_INET6:
+               return sizeof(struct sockaddr_in6);
+       case AF_IB:
+               return sizeof(struct sockaddr_ib);
+       default:
+               return 0;
+       }
+}
+EXPORT_SYMBOL(rdma_addr_size);
+
+static struct rdma_addr_client self;
+
+void rdma_addr_register_client(struct rdma_addr_client *client)
+{
+       atomic_set(&client->refcount, 1);
+       init_completion(&client->comp);
+}
+EXPORT_SYMBOL(rdma_addr_register_client);
+
+static inline void put_client(struct rdma_addr_client *client)
+{
+       if (atomic_dec_and_test(&client->refcount))
+               complete(&client->comp);
+}
+
+void rdma_addr_unregister_client(struct rdma_addr_client *client)
+{
+       put_client(client);
+       wait_for_completion(&client->comp);
+}
+EXPORT_SYMBOL(rdma_addr_unregister_client);
+
+int rdma_copy_addr(struct rdma_dev_addr *dev_addr, struct net_device *dev,
+                    const unsigned char *dst_dev_addr)
+{
+       dev_addr->dev_type = dev->type;
+       memcpy(dev_addr->src_dev_addr, dev->dev_addr, MAX_ADDR_LEN);
+       memcpy(dev_addr->broadcast, dev->broadcast, MAX_ADDR_LEN);
+       if (dst_dev_addr)
+               memcpy(dev_addr->dst_dev_addr, dst_dev_addr, MAX_ADDR_LEN);
+       dev_addr->bound_dev_if = dev->ifindex;
+       return 0;
+}
+EXPORT_SYMBOL(rdma_copy_addr);
+
+int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr,
+                     u16 *vlan_id)
+{
+       struct net_device *dev;
+       int ret = -EADDRNOTAVAIL;
+
+       if (dev_addr->bound_dev_if) {
+               dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if);
+               if (!dev)
+                       return -ENODEV;
+               ret = rdma_copy_addr(dev_addr, dev, NULL);
+               dev_put(dev);
+               return ret;
+       }
+
+       switch (addr->sa_family) {
+       case AF_INET:
+               dev = ip_dev_find(&init_net,
+                       ((struct sockaddr_in *) addr)->sin_addr.s_addr);
+
+               if (!dev)
+                       return ret;
+
+               ret = rdma_copy_addr(dev_addr, dev, NULL);
+               if (vlan_id)
+                       *vlan_id = rdma_vlan_dev_vlan_id(dev);
+               dev_put(dev);
+               break;
+
+#if IS_ENABLED(CONFIG_IPV6)
+       case AF_INET6:
+               rcu_read_lock();
+               for_each_netdev_rcu(&init_net, dev) {
+                       if (ipv6_chk_addr(&init_net,
+                                         &((struct sockaddr_in6 *) addr)->sin6_addr,
+                                         dev, 1)) {
+                               ret = rdma_copy_addr(dev_addr, dev, NULL);
+                               if (vlan_id)
+                                       *vlan_id = rdma_vlan_dev_vlan_id(dev);
+                               break;
+                       }
+               }
+               rcu_read_unlock();
+               break;
+#endif
+       }
+       return ret;
+}
+EXPORT_SYMBOL(rdma_translate_ip);
+
+static void set_timeout(unsigned long time)
+{
+       unsigned long delay;
+
+       delay = time - jiffies;
+       if ((long)delay <= 0)
+               delay = 1;
+
+       mod_delayed_work(addr_wq, &work, delay);
+}
+
+static void queue_req(struct addr_req *req)
+{
+       struct addr_req *temp_req;
+
+       mutex_lock(&lock);
+       list_for_each_entry_reverse(temp_req, &req_list, list) {
+               if (time_after_eq(req->timeout, temp_req->timeout))
+                       break;
+       }
+
+       list_add(&req->list, &temp_req->list);
+
+       if (req_list.next == &req->list)
+               set_timeout(req->timeout);
+       mutex_unlock(&lock);
+}
+
+static int dst_fetch_ha(struct dst_entry *dst, struct rdma_dev_addr *dev_addr, void *daddr)
+{
+       struct neighbour *n;
+       int ret;
+
+       n = dst_neigh_lookup(dst, daddr);
+
+       rcu_read_lock();
+       if (!n || !(n->nud_state & NUD_VALID)) {
+               if (n)
+                       neigh_event_send(n, NULL);
+               ret = -ENODATA;
+       } else {
+               ret = rdma_copy_addr(dev_addr, dst->dev, n->ha);
+       }
+       rcu_read_unlock();
+
+       if (n)
+               neigh_release(n);
+
+       return ret;
+}
+
+static int addr4_resolve(struct sockaddr_in *src_in,
+                        struct sockaddr_in *dst_in,
+                        struct rdma_dev_addr *addr)
+{
+       __be32 src_ip = src_in->sin_addr.s_addr;
+       __be32 dst_ip = dst_in->sin_addr.s_addr;
+       struct rtable *rt;
+       struct flowi4 fl4;
+       int ret;
+
+       memset(&fl4, 0, sizeof(fl4));
+       fl4.daddr = dst_ip;
+       fl4.saddr = src_ip;
+       fl4.flowi4_oif = addr->bound_dev_if;
+       rt = ip_route_output_key(&init_net, &fl4);
+       if (IS_ERR(rt)) {
+               ret = PTR_ERR(rt);
+               goto out;
+       }
+       src_in->sin_family = AF_INET;
+       src_in->sin_addr.s_addr = fl4.saddr;
+
+       if (rt->dst.dev->flags & IFF_LOOPBACK) {
+               ret = rdma_translate_ip((struct sockaddr *)dst_in, addr, NULL);
+               if (!ret)
+                       memcpy(addr->dst_dev_addr, addr->src_dev_addr, MAX_ADDR_LEN);
+               goto put;
+       }
+
+       /* If the device does ARP internally, return 'done' */
+       if (rt->dst.dev->flags & IFF_NOARP) {
+               ret = rdma_copy_addr(addr, rt->dst.dev, NULL);
+               goto put;
+       }
+
+       ret = dst_fetch_ha(&rt->dst, addr, &fl4.daddr);
+put:
+       ip_rt_put(rt);
+out:
+       return ret;
+}
+
+#if IS_ENABLED(CONFIG_IPV6)
+static int addr6_resolve(struct sockaddr_in6 *src_in,
+                        struct sockaddr_in6 *dst_in,
+                        struct rdma_dev_addr *addr)
+{
+       struct flowi6 fl6;
+       struct dst_entry *dst;
+       int ret;
+
+       memset(&fl6, 0, sizeof fl6);
+       fl6.daddr = dst_in->sin6_addr;
+       fl6.saddr = src_in->sin6_addr;
+       fl6.flowi6_oif = addr->bound_dev_if;
+
+       dst = ip6_route_output(&init_net, NULL, &fl6);
+       if ((ret = dst->error))
+               goto put;
+
+       if (ipv6_addr_any(&fl6.saddr)) {
+               ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
+                                        &fl6.daddr, 0, &fl6.saddr);
+               if (ret)
+                       goto put;
+
+               src_in->sin6_family = AF_INET6;
+               src_in->sin6_addr = fl6.saddr;
+       }
+
+       if (dst->dev->flags & IFF_LOOPBACK) {
+               ret = rdma_translate_ip((struct sockaddr *)dst_in, addr, NULL);
+               if (!ret)
+                       memcpy(addr->dst_dev_addr, addr->src_dev_addr, MAX_ADDR_LEN);
+               goto put;
+       }
+
+       /* If the device does ARP internally, return 'done' */
+       if (dst->dev->flags & IFF_NOARP) {
+               ret = rdma_copy_addr(addr, dst->dev, NULL);
+               goto put;
+       }
+
+       ret = dst_fetch_ha(dst, addr, &fl6.daddr);
+put:
+       dst_release(dst);
+       return ret;
+}
+#else
+static int addr6_resolve(struct sockaddr_in6 *src_in,
+                        struct sockaddr_in6 *dst_in,
+                        struct rdma_dev_addr *addr)
+{
+       return -EADDRNOTAVAIL;
+}
+#endif
+
+static int addr_resolve(struct sockaddr *src_in,
+                       struct sockaddr *dst_in,
+                       struct rdma_dev_addr *addr)
+{
+       if (src_in->sa_family == AF_INET) {
+               return addr4_resolve((struct sockaddr_in *) src_in,
+                       (struct sockaddr_in *) dst_in, addr);
+       } else
+               return addr6_resolve((struct sockaddr_in6 *) src_in,
+                       (struct sockaddr_in6 *) dst_in, addr);
+}
+
+static void process_req(struct work_struct *work)
+{
+       struct addr_req *req, *temp_req;
+       struct sockaddr *src_in, *dst_in;
+       struct list_head done_list;
+
+       INIT_LIST_HEAD(&done_list);
+
+       mutex_lock(&lock);
+       list_for_each_entry_safe(req, temp_req, &req_list, list) {
+               if (req->status == -ENODATA) {
+                       src_in = (struct sockaddr *) &req->src_addr;
+                       dst_in = (struct sockaddr *) &req->dst_addr;
+                       req->status = addr_resolve(src_in, dst_in, req->addr);
+                       if (req->status && time_after_eq(jiffies, req->timeout))
+                               req->status = -ETIMEDOUT;
+                       else if (req->status == -ENODATA)
+                               continue;
+               }
+               list_move_tail(&req->list, &done_list);
+       }
+
+       if (!list_empty(&req_list)) {
+               req = list_entry(req_list.next, struct addr_req, list);
+               set_timeout(req->timeout);
+       }
+       mutex_unlock(&lock);
+
+       list_for_each_entry_safe(req, temp_req, &done_list, list) {
+               list_del(&req->list);
+               req->callback(req->status, (struct sockaddr *) &req->src_addr,
+                       req->addr, req->context);
+               put_client(req->client);
+               kfree(req);
+       }
+}
+
+int rdma_resolve_ip(struct rdma_addr_client *client,
+                   struct sockaddr *src_addr, struct sockaddr *dst_addr,
+                   struct rdma_dev_addr *addr, int timeout_ms,
+                   void (*callback)(int status, struct sockaddr *src_addr,
+                                    struct rdma_dev_addr *addr, void *context),
+                   void *context)
+{
+       struct sockaddr *src_in, *dst_in;
+       struct addr_req *req;
+       int ret = 0;
+
+       req = kzalloc(sizeof *req, GFP_KERNEL);
+       if (!req)
+               return -ENOMEM;
+
+       src_in = (struct sockaddr *) &req->src_addr;
+       dst_in = (struct sockaddr *) &req->dst_addr;
+
+       if (src_addr) {
+               if (src_addr->sa_family != dst_addr->sa_family) {
+                       ret = -EINVAL;
+                       goto err;
+               }
+
+               memcpy(src_in, src_addr, rdma_addr_size(src_addr));
+       } else {
+               src_in->sa_family = dst_addr->sa_family;
+       }
+
+       memcpy(dst_in, dst_addr, rdma_addr_size(dst_addr));
+       req->addr = addr;
+       req->callback = callback;
+       req->context = context;
+       req->client = client;
+       atomic_inc(&client->refcount);
+
+       req->status = addr_resolve(src_in, dst_in, addr);
+       switch (req->status) {
+       case 0:
+               req->timeout = jiffies;
+               queue_req(req);
+               break;
+       case -ENODATA:
+               req->timeout = msecs_to_jiffies(timeout_ms) + jiffies;
+               queue_req(req);
+               break;
+       default:
+               ret = req->status;
+               atomic_dec(&client->refcount);
+               goto err;
+       }
+       return ret;
+err:
+       kfree(req);
+       return ret;
+}
+EXPORT_SYMBOL(rdma_resolve_ip);
+
+void rdma_addr_cancel(struct rdma_dev_addr *addr)
+{
+       struct addr_req *req, *temp_req;
+
+       mutex_lock(&lock);
+       list_for_each_entry_safe(req, temp_req, &req_list, list) {
+               if (req->addr == addr) {
+                       req->status = -ECANCELED;
+                       req->timeout = jiffies;
+                       list_move(&req->list, &req_list);
+                       set_timeout(req->timeout);
+                       break;
+               }
+       }
+       mutex_unlock(&lock);
+}
+EXPORT_SYMBOL(rdma_addr_cancel);
+
+struct resolve_cb_context {
+       struct rdma_dev_addr *addr;
+       struct completion comp;
+};
+
+static void resolve_cb(int status, struct sockaddr *src_addr,
+            struct rdma_dev_addr *addr, void *context)
+{
+       memcpy(((struct resolve_cb_context *)context)->addr, addr, sizeof(struct
+                               rdma_dev_addr));
+       complete(&((struct resolve_cb_context *)context)->comp);
+}
+
+int rdma_addr_find_dmac_by_grh(union ib_gid *sgid, union ib_gid *dgid, u8 *dmac,
+                              u16 *vlan_id)
+{
+       int ret = 0;
+       struct rdma_dev_addr dev_addr;
+       struct resolve_cb_context ctx;
+       struct net_device *dev;
+
+       union {
+               struct sockaddr     _sockaddr;
+               struct sockaddr_in  _sockaddr_in;
+               struct sockaddr_in6 _sockaddr_in6;
+       } sgid_addr, dgid_addr;
+
+
+       ret = rdma_gid2ip(&sgid_addr._sockaddr, sgid);
+       if (ret)
+               return ret;
+
+       ret = rdma_gid2ip(&dgid_addr._sockaddr, dgid);
+       if (ret)
+               return ret;
+
+       memset(&dev_addr, 0, sizeof(dev_addr));
+
+       ctx.addr = &dev_addr;
+       init_completion(&ctx.comp);
+       ret = rdma_resolve_ip(&self, &sgid_addr._sockaddr, &dgid_addr._sockaddr,
+                       &dev_addr, 1000, resolve_cb, &ctx);
+       if (ret)
+               return ret;
+
+       wait_for_completion(&ctx.comp);
+
+       memcpy(dmac, dev_addr.dst_dev_addr, ETH_ALEN);
+       dev = dev_get_by_index(&init_net, dev_addr.bound_dev_if);
+       if (!dev)
+               return -ENODEV;
+       if (vlan_id)
+               *vlan_id = rdma_vlan_dev_vlan_id(dev);
+       dev_put(dev);
+       return ret;
+}
+EXPORT_SYMBOL(rdma_addr_find_dmac_by_grh);
+
+int rdma_addr_find_smac_by_sgid(union ib_gid *sgid, u8 *smac, u16 *vlan_id)
+{
+       int ret = 0;
+       struct rdma_dev_addr dev_addr;
+       union {
+               struct sockaddr     _sockaddr;
+               struct sockaddr_in  _sockaddr_in;
+               struct sockaddr_in6 _sockaddr_in6;
+       } gid_addr;
+
+       ret = rdma_gid2ip(&gid_addr._sockaddr, sgid);
+
+       if (ret)
+               return ret;
+       memset(&dev_addr, 0, sizeof(dev_addr));
+       ret = rdma_translate_ip(&gid_addr._sockaddr, &dev_addr, vlan_id);
+       if (ret)
+               return ret;
+
+       memcpy(smac, dev_addr.src_dev_addr, ETH_ALEN);
+       return ret;
+}
+EXPORT_SYMBOL(rdma_addr_find_smac_by_sgid);
+
+static int netevent_callback(struct notifier_block *self, unsigned long event,
+       void *ctx)
+{
+       if (event == NETEVENT_NEIGH_UPDATE) {
+               struct neighbour *neigh = ctx;
+
+               if (neigh->nud_state & NUD_VALID) {
+                       set_timeout(jiffies);
+               }
+       }
+       return 0;
+}
+
+static struct notifier_block nb = {
+       .notifier_call = netevent_callback
+};
+
+static int __init addr_init(void)
+{
+       addr_wq = create_singlethread_workqueue("ib_addr");
+       if (!addr_wq)
+               return -ENOMEM;
+
+       register_netevent_notifier(&nb);
+       rdma_addr_register_client(&self);
+       return 0;
+}
+
+static void __exit addr_cleanup(void)
+{
+       rdma_addr_unregister_client(&self);
+       unregister_netevent_notifier(&nb);
+       destroy_workqueue(addr_wq);
+}
+
+module_init(addr_init);
+module_exit(addr_cleanup);
diff --git a/drivers/infiniband/core/agent.c b/drivers/infiniband/core/agent.c
new file mode 100644 (file)
index 0000000..f6d2961
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2004, 2005 Mellanox Technologies Ltd.  All rights reserved.
+ * Copyright (c) 2004, 2005 Infinicon Corporation.  All rights reserved.
+ * Copyright (c) 2004, 2005 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2004, 2005 Topspin Corporation.  All rights reserved.
+ * Copyright (c) 2004-2007 Voltaire Corporation.  All rights reserved.
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "agent.h"
+#include "smi.h"
+#include "mad_priv.h"
+
+#define SPFX "ib_agent: "
+
+struct ib_agent_port_private {
+       struct list_head port_list;
+       struct ib_mad_agent *agent[2];
+};
+
+static DEFINE_SPINLOCK(ib_agent_port_list_lock);
+static LIST_HEAD(ib_agent_port_list);
+
+static struct ib_agent_port_private *
+__ib_get_agent_port(struct ib_device *device, int port_num)
+{
+       struct ib_agent_port_private *entry;
+
+       list_for_each_entry(entry, &ib_agent_port_list, port_list) {
+               if (entry->agent[1]->device == device &&
+                   entry->agent[1]->port_num == port_num)
+                       return entry;
+       }
+       return NULL;
+}
+
+static struct ib_agent_port_private *
+ib_get_agent_port(struct ib_device *device, int port_num)
+{
+       struct ib_agent_port_private *entry;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       entry = __ib_get_agent_port(device, port_num);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
+       return entry;
+}
+
+void agent_send_response(struct ib_mad *mad, struct ib_grh *grh,
+                        struct ib_wc *wc, struct ib_device *device,
+                        int port_num, int qpn)
+{
+       struct ib_agent_port_private *port_priv;
+       struct ib_mad_agent *agent;
+       struct ib_mad_send_buf *send_buf;
+       struct ib_ah *ah;
+       struct ib_mad_send_wr_private *mad_send_wr;
+
+       if (device->node_type == RDMA_NODE_IB_SWITCH)
+               port_priv = ib_get_agent_port(device, 0);
+       else
+               port_priv = ib_get_agent_port(device, port_num);
+
+       if (!port_priv) {
+               dev_err(&device->dev, "Unable to find port agent\n");
+               return;
+       }
+
+       agent = port_priv->agent[qpn];
+       ah = ib_create_ah_from_wc(agent->qp->pd, wc, grh, port_num);
+       if (IS_ERR(ah)) {
+               dev_err(&device->dev, "ib_create_ah_from_wc error %ld\n",
+                       PTR_ERR(ah));
+               return;
+       }
+
+       send_buf = ib_create_send_mad(agent, wc->src_qp, wc->pkey_index, 0,
+                                     IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
+                                     GFP_KERNEL);
+       if (IS_ERR(send_buf)) {
+               dev_err(&device->dev, "ib_create_send_mad error\n");
+               goto err1;
+       }
+
+       memcpy(send_buf->mad, mad, sizeof *mad);
+       send_buf->ah = ah;
+
+       if (device->node_type == RDMA_NODE_IB_SWITCH) {
+               mad_send_wr = container_of(send_buf,
+                                          struct ib_mad_send_wr_private,
+                                          send_buf);
+               mad_send_wr->send_wr.wr.ud.port_num = port_num;
+       }
+
+       if (ib_post_send_mad(send_buf, NULL)) {
+               dev_err(&device->dev, "ib_post_send_mad error\n");
+               goto err2;
+       }
+       return;
+err2:
+       ib_free_send_mad(send_buf);
+err1:
+       ib_destroy_ah(ah);
+}
+
+static void agent_send_handler(struct ib_mad_agent *mad_agent,
+                              struct ib_mad_send_wc *mad_send_wc)
+{
+       ib_destroy_ah(mad_send_wc->send_buf->ah);
+       ib_free_send_mad(mad_send_wc->send_buf);
+}
+
+int ib_agent_port_open(struct ib_device *device, int port_num)
+{
+       struct ib_agent_port_private *port_priv;
+       unsigned long flags;
+       int ret;
+
+       /* Create new device info */
+       port_priv = kzalloc(sizeof *port_priv, GFP_KERNEL);
+       if (!port_priv) {
+               dev_err(&device->dev, "No memory for ib_agent_port_private\n");
+               ret = -ENOMEM;
+               goto error1;
+       }
+
+       if (rdma_port_get_link_layer(device, port_num) == IB_LINK_LAYER_INFINIBAND) {
+               /* Obtain send only MAD agent for SMI QP */
+               port_priv->agent[0] = ib_register_mad_agent(device, port_num,
+                                                           IB_QPT_SMI, NULL, 0,
+                                                           &agent_send_handler,
+                                                           NULL, NULL, 0);
+               if (IS_ERR(port_priv->agent[0])) {
+                       ret = PTR_ERR(port_priv->agent[0]);
+                       goto error2;
+               }
+       }
+
+       /* Obtain send only MAD agent for GSI QP */
+       port_priv->agent[1] = ib_register_mad_agent(device, port_num,
+                                                   IB_QPT_GSI, NULL, 0,
+                                                   &agent_send_handler,
+                                                   NULL, NULL, 0);
+       if (IS_ERR(port_priv->agent[1])) {
+               ret = PTR_ERR(port_priv->agent[1]);
+               goto error3;
+       }
+
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       list_add_tail(&port_priv->port_list, &ib_agent_port_list);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
+
+       return 0;
+
+error3:
+       if (port_priv->agent[0])
+               ib_unregister_mad_agent(port_priv->agent[0]);
+error2:
+       kfree(port_priv);
+error1:
+       return ret;
+}
+
+int ib_agent_port_close(struct ib_device *device, int port_num)
+{
+       struct ib_agent_port_private *port_priv;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       port_priv = __ib_get_agent_port(device, port_num);
+       if (port_priv == NULL) {
+               spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
+               dev_err(&device->dev, "Port %d not found\n", port_num);
+               return -ENODEV;
+       }
+       list_del(&port_priv->port_list);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
+
+       ib_unregister_mad_agent(port_priv->agent[1]);
+       if (port_priv->agent[0])
+               ib_unregister_mad_agent(port_priv->agent[0]);
+
+       kfree(port_priv);
+       return 0;
+}
diff --git a/drivers/infiniband/core/agent.h b/drivers/infiniband/core/agent.h
new file mode 100644 (file)
index 0000000..6669287
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
+ * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
+ * Copyright (c) 2004 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
+ * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __AGENT_H_
+#define __AGENT_H_
+
+#include <linux/err.h>
+#include <rdma/ib_mad.h>
+
+extern int ib_agent_port_open(struct ib_device *device, int port_num);
+
+extern int ib_agent_port_close(struct ib_device *device, int port_num);
+
+extern void agent_send_response(struct ib_mad *mad, struct ib_grh *grh,
+                               struct ib_wc *wc, struct ib_device *device,
+                               int port_num, int qpn);
+
+#endif /* __AGENT_H_ */
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
new file mode 100644 (file)
index 0000000..80f6cf2
--- /dev/null
@@ -0,0 +1,439 @@
+/*
+ * Copyright (c) 2004 Topspin Communications.  All rights reserved.
+ * Copyright (c) 2005 Intel Corporation. All rights reserved.
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#include <rdma/ib_cache.h>
+
+#include "core_priv.h"
+
+struct ib_pkey_cache {
+       int             table_len;
+       u16             table[0];
+};
+
+struct ib_gid_cache {
+       int             table_len;
+       union ib_gid    table[0];
+};
+
+struct ib_update_work {
+       struct work_struct work;
+       struct ib_device  *device;
+       u8                 port_num;
+};
+
+static inline int start_port(struct ib_device *device)
+{
+       return (device->node_type == RDMA_NODE_IB_SWITCH) ? 0 : 1;
+}
+
+static inline int end_port(struct ib_device *device)
+{
+       return (device->node_type == RDMA_NODE_IB_SWITCH) ?
+               0 : device->phys_port_cnt;
+}
+
+int ib_get_cached_gid(struct ib_device *device,
+                     u8                port_num,
+                     int               index,
+                     union ib_gid     *gid)
+{
+       struct ib_gid_cache *cache;
+       unsigned long flags;
+       int ret = 0;
+
+       if (port_num < start_port(device) || port_num > end_port(device))
+               return -EINVAL;
+
+       read_lock_irqsave(&device->cache.lock, flags);
+
+       cache = device->cache.gid_cache[port_num - start_port(device)];
+
+       if (index < 0 || index >= cache->table_len)
+               ret = -EINVAL;
+       else
+               *gid = cache->table[index];
+
+       read_unlock_irqrestore(&device->cache.lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_get_cached_gid);
+
+int ib_find_cached_gid(struct ib_device *device,
+                      union ib_gid     *gid,
+                      u8               *port_num,
+                      u16              *index)
+{
+       struct ib_gid_cache *cache;
+       unsigned long flags;
+       int p, i;
+       int ret = -ENOENT;
+
+       *port_num = -1;
+       if (index)
+               *index = -1;
+
+       read_lock_irqsave(&device->cache.lock, flags);
+
+       for (p = 0; p <= end_port(device) - start_port(device); ++p) {
+               cache = device->cache.gid_cache[p];
+               for (i = 0; i < cache->table_len; ++i) {
+                       if (!memcmp(gid, &cache->table[i], sizeof *gid)) {
+                               *port_num = p + start_port(device);
+                               if (index)
+                                       *index = i;
+                               ret = 0;
+                               goto found;
+                       }
+               }
+       }
+found:
+       read_unlock_irqrestore(&device->cache.lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_find_cached_gid);
+
+int ib_get_cached_pkey(struct ib_device *device,
+                      u8                port_num,
+                      int               index,
+                      u16              *pkey)
+{
+       struct ib_pkey_cache *cache;
+       unsigned long flags;
+       int ret = 0;
+
+       if (port_num < start_port(device) || port_num > end_port(device))
+               return -EINVAL;
+
+       read_lock_irqsave(&device->cache.lock, flags);
+
+       cache = device->cache.pkey_cache[port_num - start_port(device)];
+
+       if (index < 0 || index >= cache->table_len)
+               ret = -EINVAL;
+       else
+               *pkey = cache->table[index];
+
+       read_unlock_irqrestore(&device->cache.lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_get_cached_pkey);
+
+int ib_find_cached_pkey(struct ib_device *device,
+                       u8                port_num,
+                       u16               pkey,
+                       u16              *index)
+{
+       struct ib_pkey_cache *cache;
+       unsigned long flags;
+       int i;
+       int ret = -ENOENT;
+       int partial_ix = -1;
+
+       if (port_num < start_port(device) || port_num > end_port(device))
+               return -EINVAL;
+
+       read_lock_irqsave(&device->cache.lock, flags);
+
+       cache = device->cache.pkey_cache[port_num - start_port(device)];
+
+       *index = -1;
+
+       for (i = 0; i < cache->table_len; ++i)
+               if ((cache->table[i] & 0x7fff) == (pkey & 0x7fff)) {
+                       if (cache->table[i] & 0x8000) {
+                               *index = i;
+                               ret = 0;
+                               break;
+                       } else
+                               partial_ix = i;
+               }
+
+       if (ret && partial_ix >= 0) {
+               *index = partial_ix;
+               ret = 0;
+       }
+
+       read_unlock_irqrestore(&device->cache.lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_find_cached_pkey);
+
+int ib_find_exact_cached_pkey(struct ib_device *device,
+                             u8                port_num,
+                             u16               pkey,
+                             u16              *index)
+{
+       struct ib_pkey_cache *cache;
+       unsigned long flags;
+       int i;
+       int ret = -ENOENT;
+
+       if (port_num < start_port(device) || port_num > end_port(device))
+               return -EINVAL;
+
+       read_lock_irqsave(&device->cache.lock, flags);
+
+       cache = device->cache.pkey_cache[port_num - start_port(device)];
+
+       *index = -1;
+
+       for (i = 0; i < cache->table_len; ++i)
+               if (cache->table[i] == pkey) {
+                       *index = i;
+                       ret = 0;
+                       break;
+               }
+
+       read_unlock_irqrestore(&device->cache.lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_find_exact_cached_pkey);
+
+int ib_get_cached_lmc(struct ib_device *device,
+                     u8                port_num,
+                     u8                *lmc)
+{
+       unsigned long flags;
+       int ret = 0;
+
+       if (port_num < start_port(device) || port_num > end_port(device))
+               return -EINVAL;
+
+       read_lock_irqsave(&device->cache.lock, flags);
+       *lmc = device->cache.lmc_cache[port_num - start_port(device)];
+       read_unlock_irqrestore(&device->cache.lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_get_cached_lmc);
+
+static void ib_cache_update(struct ib_device *device,
+                           u8                port)
+{
+       struct ib_port_attr       *tprops = NULL;
+       struct ib_pkey_cache      *pkey_cache = NULL, *old_pkey_cache;
+       struct ib_gid_cache       *gid_cache = NULL, *old_gid_cache;
+       int                        i;
+       int                        ret;
+
+       tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
+       if (!tprops)
+               return;
+
+       ret = ib_query_port(device, port, tprops);
+       if (ret) {
+               printk(KERN_WARNING "ib_query_port failed (%d) for %s\n",
+                      ret, device->name);
+               goto err;
+       }
+
+       pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
+                            sizeof *pkey_cache->table, GFP_KERNEL);
+       if (!pkey_cache)
+               goto err;
+
+       pkey_cache->table_len = tprops->pkey_tbl_len;
+
+       gid_cache = kmalloc(sizeof *gid_cache + tprops->gid_tbl_len *
+                           sizeof *gid_cache->table, GFP_KERNEL);
+       if (!gid_cache)
+               goto err;
+
+       gid_cache->table_len = tprops->gid_tbl_len;
+
+       for (i = 0; i < pkey_cache->table_len; ++i) {
+               ret = ib_query_pkey(device, port, i, pkey_cache->table + i);
+               if (ret) {
+                       printk(KERN_WARNING "ib_query_pkey failed (%d) for %s (index %d)\n",
+                              ret, device->name, i);
+                       goto err;
+               }
+       }
+
+       for (i = 0; i < gid_cache->table_len; ++i) {
+               ret = ib_query_gid(device, port, i, gid_cache->table + i);
+               if (ret) {
+                       printk(KERN_WARNING "ib_query_gid failed (%d) for %s (index %d)\n",
+                              ret, device->name, i);
+                       goto err;
+               }
+       }
+
+       write_lock_irq(&device->cache.lock);
+
+       old_pkey_cache = device->cache.pkey_cache[port - start_port(device)];
+       old_gid_cache  = device->cache.gid_cache [port - start_port(device)];
+
+       device->cache.pkey_cache[port - start_port(device)] = pkey_cache;
+       device->cache.gid_cache [port - start_port(device)] = gid_cache;
+
+       device->cache.lmc_cache[port - start_port(device)] = tprops->lmc;
+
+       write_unlock_irq(&device->cache.lock);
+
+       kfree(old_pkey_cache);
+       kfree(old_gid_cache);
+       kfree(tprops);
+       return;
+
+err:
+       kfree(pkey_cache);
+       kfree(gid_cache);
+       kfree(tprops);
+}
+
+static void ib_cache_task(struct work_struct *_work)
+{
+       struct ib_update_work *work =
+               container_of(_work, struct ib_update_work, work);
+
+       ib_cache_update(work->device, work->port_num);
+       kfree(work);
+}
+
+static void ib_cache_event(struct ib_event_handler *handler,
+                          struct ib_event *event)
+{
+       struct ib_update_work *work;
+
+       if (event->event == IB_EVENT_PORT_ERR    ||
+           event->event == IB_EVENT_PORT_ACTIVE ||
+           event->event == IB_EVENT_LID_CHANGE  ||
+           event->event == IB_EVENT_PKEY_CHANGE ||
+           event->event == IB_EVENT_SM_CHANGE   ||
+           event->event == IB_EVENT_CLIENT_REREGISTER ||
+           event->event == IB_EVENT_GID_CHANGE) {
+               work = kmalloc(sizeof *work, GFP_ATOMIC);
+               if (work) {
+                       INIT_WORK(&work->work, ib_cache_task);
+                       work->device   = event->device;
+                       work->port_num = event->element.port_num;
+                       queue_work(ib_wq, &work->work);
+               }
+       }
+}
+
+static void ib_cache_setup_one(struct ib_device *device)
+{
+       int p;
+
+       rwlock_init(&device->cache.lock);
+
+       device->cache.pkey_cache =
+               kmalloc(sizeof *device->cache.pkey_cache *
+                       (end_port(device) - start_port(device) + 1), GFP_KERNEL);
+       device->cache.gid_cache =
+               kmalloc(sizeof *device->cache.gid_cache *
+                       (end_port(device) - start_port(device) + 1), GFP_KERNEL);
+
+       device->cache.lmc_cache = kmalloc(sizeof *device->cache.lmc_cache *
+                                         (end_port(device) -
+                                          start_port(device) + 1),
+                                         GFP_KERNEL);
+
+       if (!device->cache.pkey_cache || !device->cache.gid_cache ||
+           !device->cache.lmc_cache) {
+               printk(KERN_WARNING "Couldn't allocate cache "
+                      "for %s\n", device->name);
+               goto err;
+       }
+
+       for (p = 0; p <= end_port(device) - start_port(device); ++p) {
+               device->cache.pkey_cache[p] = NULL;
+               device->cache.gid_cache [p] = NULL;
+               ib_cache_update(device, p + start_port(device));
+       }
+
+       INIT_IB_EVENT_HANDLER(&device->cache.event_handler,
+                             device, ib_cache_event);
+       if (ib_register_event_handler(&device->cache.event_handler))
+               goto err_cache;
+
+       return;
+
+err_cache:
+       for (p = 0; p <= end_port(device) - start_port(device); ++p) {
+               kfree(device->cache.pkey_cache[p]);
+               kfree(device->cache.gid_cache[p]);
+       }
+
+err:
+       kfree(device->cache.pkey_cache);
+       kfree(device->cache.gid_cache);
+       kfree(device->cache.lmc_cache);
+}
+
+static void ib_cache_cleanup_one(struct ib_device *device)
+{
+       int p;
+
+       ib_unregister_event_handler(&device->cache.event_handler);
+       flush_workqueue(ib_wq);
+
+       for (p = 0; p <= end_port(device) - start_port(device); ++p) {
+               kfree(device->cache.pkey_cache[p]);
+               kfree(device->cache.gid_cache[p]);
+       }
+
+       kfree(device->cache.pkey_cache);
+       kfree(device->cache.gid_cache);
+       kfree(device->cache.lmc_cache);
+}
+
+static struct ib_client cache_client = {
+       .name   = "cache",
+       .add    = ib_cache_setup_one,
+       .remove = ib_cache_cleanup_one
+};
+
+int __init ib_cache_setup(void)
+{
+       return ib_register_client(&cache_client);
+}
+
+void __exit ib_cache_cleanup(void)
+{
+       ib_unregister_client(&cache_client);
+}
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
new file mode 100644 (file)
index 0000000..e28a494
--- /dev/null
@@ -0,0 +1,3932 @@
+/*
+ * Copyright (c) 2004-2007 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
+ * Copyright (c) 2004, 2005 Voltaire Corporation.  All rights reserved.
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/completion.h>
+#include <linux/dma-mapping.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/idr.h>
+#include <linux/interrupt.h>
+#include <linux/random.h>
+#include <linux/rbtree.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
+#include <linux/workqueue.h>
+#include <linux/kdev_t.h>
+#include <linux/etherdevice.h>
+
+#include <rdma/ib_cache.h>
+#include <rdma/ib_cm.h>
+#include "cm_msgs.h"
+
+MODULE_AUTHOR("Sean Hefty");
+MODULE_DESCRIPTION("InfiniBand CM");
+MODULE_LICENSE("Dual BSD/GPL");
+
+static void cm_add_one(struct ib_device *device);
+static void cm_remove_one(struct ib_device *device);
+
+static struct ib_client cm_client = {
+       .name   = "cm",
+       .add    = cm_add_one,
+       .remove = cm_remove_one
+};
+
+static struct ib_cm {
+       spinlock_t lock;
+       struct list_head device_list;
+       rwlock_t device_lock;
+       struct rb_root listen_service_table;
+       u64 listen_service_id;
+       /* struct rb_root peer_service_table; todo: fix peer to peer */
+       struct rb_root remote_qp_table;
+       struct rb_root remote_id_table;
+       struct rb_root remote_sidr_table;
+       struct idr local_id_table;
+       __be32 random_id_operand;
+       struct list_head timewait_list;
+       struct workqueue_struct *wq;
+} cm;
+
+/* Counter indexes ordered by attribute ID */
+enum {
+       CM_REQ_COUNTER,
+       CM_MRA_COUNTER,
+       CM_REJ_COUNTER,
+       CM_REP_COUNTER,
+       CM_RTU_COUNTER,
+       CM_DREQ_COUNTER,
+       CM_DREP_COUNTER,
+       CM_SIDR_REQ_COUNTER,
+       CM_SIDR_REP_COUNTER,
+       CM_LAP_COUNTER,
+       CM_APR_COUNTER,
+       CM_ATTR_COUNT,
+       CM_ATTR_ID_OFFSET = 0x0010,
+};
+
+enum {
+       CM_XMIT,
+       CM_XMIT_RETRIES,
+       CM_RECV,
+       CM_RECV_DUPLICATES,
+       CM_COUNTER_GROUPS
+};
+
+static char const counter_group_names[CM_COUNTER_GROUPS]
+                                    [sizeof("cm_rx_duplicates")] = {
+       "cm_tx_msgs", "cm_tx_retries",
+       "cm_rx_msgs", "cm_rx_duplicates"
+};
+
+struct cm_counter_group {
+       struct kobject obj;
+       atomic_long_t counter[CM_ATTR_COUNT];
+};
+
+struct cm_counter_attribute {
+       struct attribute attr;
+       int index;
+};
+
+#define CM_COUNTER_ATTR(_name, _index) \
+struct cm_counter_attribute cm_##_name##_counter_attr = { \
+       .attr = { .name = __stringify(_name), .mode = 0444 }, \
+       .index = _index \
+}
+
+static CM_COUNTER_ATTR(req, CM_REQ_COUNTER);
+static CM_COUNTER_ATTR(mra, CM_MRA_COUNTER);
+static CM_COUNTER_ATTR(rej, CM_REJ_COUNTER);
+static CM_COUNTER_ATTR(rep, CM_REP_COUNTER);
+static CM_COUNTER_ATTR(rtu, CM_RTU_COUNTER);
+static CM_COUNTER_ATTR(dreq, CM_DREQ_COUNTER);
+static CM_COUNTER_ATTR(drep, CM_DREP_COUNTER);
+static CM_COUNTER_ATTR(sidr_req, CM_SIDR_REQ_COUNTER);
+static CM_COUNTER_ATTR(sidr_rep, CM_SIDR_REP_COUNTER);
+static CM_COUNTER_ATTR(lap, CM_LAP_COUNTER);
+static CM_COUNTER_ATTR(apr, CM_APR_COUNTER);
+
+static struct attribute *cm_counter_default_attrs[] = {
+       &cm_req_counter_attr.attr,
+       &cm_mra_counter_attr.attr,
+       &cm_rej_counter_attr.attr,
+       &cm_rep_counter_attr.attr,
+       &cm_rtu_counter_attr.attr,
+       &cm_dreq_counter_attr.attr,
+       &cm_drep_counter_attr.attr,
+       &cm_sidr_req_counter_attr.attr,
+       &cm_sidr_rep_counter_attr.attr,
+       &cm_lap_counter_attr.attr,
+       &cm_apr_counter_attr.attr,
+       NULL
+};
+
+struct cm_port {
+       struct cm_device *cm_dev;
+       struct ib_mad_agent *mad_agent;
+       struct kobject port_obj;
+       u8 port_num;
+       struct cm_counter_group counter_group[CM_COUNTER_GROUPS];
+};
+
+struct cm_device {
+       struct list_head list;
+       struct ib_device *ib_device;
+       struct device *device;
+       u8 ack_delay;
+       struct cm_port *port[0];
+};
+
+struct cm_av {
+       struct cm_port *port;
+       union ib_gid dgid;
+       struct ib_ah_attr ah_attr;
+       u16 pkey_index;
+       u8 timeout;
+       u8  valid;
+       u8  smac[ETH_ALEN];
+};
+
+struct cm_work {
+       struct delayed_work work;
+       struct list_head list;
+       struct cm_port *port;
+       struct ib_mad_recv_wc *mad_recv_wc;     /* Received MADs */
+       __be32 local_id;                        /* Established / timewait */
+       __be32 remote_id;
+       struct ib_cm_event cm_event;
+       struct ib_sa_path_rec path[0];
+};
+
+struct cm_timewait_info {
+       struct cm_work work;                    /* Must be first. */
+       struct list_head list;
+       struct rb_node remote_qp_node;
+       struct rb_node remote_id_node;
+       __be64 remote_ca_guid;
+       __be32 remote_qpn;
+       u8 inserted_remote_qp;
+       u8 inserted_remote_id;
+};
+
+struct cm_id_private {
+       struct ib_cm_id id;
+
+       struct rb_node service_node;
+       struct rb_node sidr_id_node;
+       spinlock_t lock;        /* Do not acquire inside cm.lock */
+       struct completion comp;
+       atomic_t refcount;
+
+       struct ib_mad_send_buf *msg;
+       struct cm_timewait_info *timewait_info;
+       /* todo: use alternate port on send failure */
+       struct cm_av av;
+       struct cm_av alt_av;
+       struct ib_cm_compare_data *compare_data;
+
+       void *private_data;
+       __be64 tid;
+       __be32 local_qpn;
+       __be32 remote_qpn;
+       enum ib_qp_type qp_type;
+       __be32 sq_psn;
+       __be32 rq_psn;
+       int timeout_ms;
+       enum ib_mtu path_mtu;
+       __be16 pkey;
+       u8 private_data_len;
+       u8 max_cm_retries;
+       u8 peer_to_peer;
+       u8 responder_resources;
+       u8 initiator_depth;
+       u8 retry_count;
+       u8 rnr_retry_count;
+       u8 service_timeout;
+       u8 target_ack_delay;
+
+       struct list_head work_list;
+       atomic_t work_count;
+};
+
+static void cm_work_handler(struct work_struct *work);
+
+static inline void cm_deref_id(struct cm_id_private *cm_id_priv)
+{
+       if (atomic_dec_and_test(&cm_id_priv->refcount))
+               complete(&cm_id_priv->comp);
+}
+
+static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
+                       struct ib_mad_send_buf **msg)
+{
+       struct ib_mad_agent *mad_agent;
+       struct ib_mad_send_buf *m;
+       struct ib_ah *ah;
+
+       mad_agent = cm_id_priv->av.port->mad_agent;
+       ah = ib_create_ah(mad_agent->qp->pd, &cm_id_priv->av.ah_attr);
+       if (IS_ERR(ah))
+               return PTR_ERR(ah);
+
+       m = ib_create_send_mad(mad_agent, cm_id_priv->id.remote_cm_qpn,
+                              cm_id_priv->av.pkey_index,
+                              0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
+                              GFP_ATOMIC);
+       if (IS_ERR(m)) {
+               ib_destroy_ah(ah);
+               return PTR_ERR(m);
+       }
+
+       /* Timeout set by caller if response is expected. */
+       m->ah = ah;
+       m->retries = cm_id_priv->max_cm_retries;
+
+       atomic_inc(&cm_id_priv->refcount);
+       m->context[0] = cm_id_priv;
+       *msg = m;
+       return 0;
+}
+
+static int cm_alloc_response_msg(struct cm_port *port,
+                                struct ib_mad_recv_wc *mad_recv_wc,
+                                struct ib_mad_send_buf **msg)
+{
+       struct ib_mad_send_buf *m;
+       struct ib_ah *ah;
+
+       ah = ib_create_ah_from_wc(port->mad_agent->qp->pd, mad_recv_wc->wc,
+                                 mad_recv_wc->recv_buf.grh, port->port_num);
+       if (IS_ERR(ah))
+               return PTR_ERR(ah);
+
+       m = ib_create_send_mad(port->mad_agent, 1, mad_recv_wc->wc->pkey_index,
+                              0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
+                              GFP_ATOMIC);
+       if (IS_ERR(m)) {
+               ib_destroy_ah(ah);
+               return PTR_ERR(m);
+       }
+       m->ah = ah;
+       *msg = m;
+       return 0;
+}
+
+static void cm_free_msg(struct ib_mad_send_buf *msg)
+{
+       ib_destroy_ah(msg->ah);
+       if (msg->context[0])
+               cm_deref_id(msg->context[0]);
+       ib_free_send_mad(msg);
+}
+
+static void * cm_copy_private_data(const void *private_data,
+                                  u8 private_data_len)
+{
+       void *data;
+
+       if (!private_data || !private_data_len)
+               return NULL;
+
+       data = kmemdup(private_data, private_data_len, GFP_KERNEL);
+       if (!data)
+               return ERR_PTR(-ENOMEM);
+
+       return data;
+}
+
+static void cm_set_private_data(struct cm_id_private *cm_id_priv,
+                                void *private_data, u8 private_data_len)
+{
+       if (cm_id_priv->private_data && cm_id_priv->private_data_len)
+               kfree(cm_id_priv->private_data);
+
+       cm_id_priv->private_data = private_data;
+       cm_id_priv->private_data_len = private_data_len;
+}
+
+static void cm_init_av_for_response(struct cm_port *port, struct ib_wc *wc,
+                                   struct ib_grh *grh, struct cm_av *av)
+{
+       av->port = port;
+       av->pkey_index = wc->pkey_index;
+       ib_init_ah_from_wc(port->cm_dev->ib_device, port->port_num, wc,
+                          grh, &av->ah_attr);
+}
+
+static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av)
+{
+       struct cm_device *cm_dev;
+       struct cm_port *port = NULL;
+       unsigned long flags;
+       int ret;
+       u8 p;
+
+       read_lock_irqsave(&cm.device_lock, flags);
+       list_for_each_entry(cm_dev, &cm.device_list, list) {
+               if (!ib_find_cached_gid(cm_dev->ib_device, &path->sgid,
+                                       &p, NULL)) {
+                       port = cm_dev->port[p-1];
+                       break;
+               }
+       }
+       read_unlock_irqrestore(&cm.device_lock, flags);
+
+       if (!port)
+               return -EINVAL;
+
+       ret = ib_find_cached_pkey(cm_dev->ib_device, port->port_num,
+                                 be16_to_cpu(path->pkey), &av->pkey_index);
+       if (ret)
+               return ret;
+
+       av->port = port;
+       ib_init_ah_from_path(cm_dev->ib_device, port->port_num, path,
+                            &av->ah_attr);
+       av->timeout = path->packet_life_time + 1;
+       memcpy(av->smac, path->smac, sizeof(av->smac));
+
+       av->valid = 1;
+       return 0;
+}
+
+static int cm_alloc_id(struct cm_id_private *cm_id_priv)
+{
+       unsigned long flags;
+       int id;
+
+       idr_preload(GFP_KERNEL);
+       spin_lock_irqsave(&cm.lock, flags);
+
+       id = idr_alloc_cyclic(&cm.local_id_table, cm_id_priv, 0, 0, GFP_NOWAIT);
+
+       spin_unlock_irqrestore(&cm.lock, flags);
+       idr_preload_end();
+
+       cm_id_priv->id.local_id = (__force __be32)id ^ cm.random_id_operand;
+       return id < 0 ? id : 0;
+}
+
+static void cm_free_id(__be32 local_id)
+{
+       spin_lock_irq(&cm.lock);
+       idr_remove(&cm.local_id_table,
+                  (__force int) (local_id ^ cm.random_id_operand));
+       spin_unlock_irq(&cm.lock);
+}
+
+static struct cm_id_private * cm_get_id(__be32 local_id, __be32 remote_id)
+{
+       struct cm_id_private *cm_id_priv;
+
+       cm_id_priv = idr_find(&cm.local_id_table,
+                             (__force int) (local_id ^ cm.random_id_operand));
+       if (cm_id_priv) {
+               if (cm_id_priv->id.remote_id == remote_id)
+                       atomic_inc(&cm_id_priv->refcount);
+               else
+                       cm_id_priv = NULL;
+       }
+
+       return cm_id_priv;
+}
+
+static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id)
+{
+       struct cm_id_private *cm_id_priv;
+
+       spin_lock_irq(&cm.lock);
+       cm_id_priv = cm_get_id(local_id, remote_id);
+       spin_unlock_irq(&cm.lock);
+
+       return cm_id_priv;
+}
+
+static void cm_mask_copy(u8 *dst, u8 *src, u8 *mask)
+{
+       int i;
+
+       for (i = 0; i < IB_CM_COMPARE_SIZE / sizeof(unsigned long); i++)
+               ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] &
+                                            ((unsigned long *) mask)[i];
+}
+
+static int cm_compare_data(struct ib_cm_compare_data *src_data,
+                          struct ib_cm_compare_data *dst_data)
+{
+       u8 src[IB_CM_COMPARE_SIZE];
+       u8 dst[IB_CM_COMPARE_SIZE];
+
+       if (!src_data || !dst_data)
+               return 0;
+
+       cm_mask_copy(src, src_data->data, dst_data->mask);
+       cm_mask_copy(dst, dst_data->data, src_data->mask);
+       return memcmp(src, dst, IB_CM_COMPARE_SIZE);
+}
+
+static int cm_compare_private_data(u8 *private_data,
+                                  struct ib_cm_compare_data *dst_data)
+{
+       u8 src[IB_CM_COMPARE_SIZE];
+
+       if (!dst_data)
+               return 0;
+
+       cm_mask_copy(src, private_data, dst_data->mask);
+       return memcmp(src, dst_data->data, IB_CM_COMPARE_SIZE);
+}
+
+/*
+ * Trivial helpers to strip endian annotation and compare; the
+ * endianness doesn't actually matter since we just need a stable
+ * order for the RB tree.
+ */
+static int be32_lt(__be32 a, __be32 b)
+{
+       return (__force u32) a < (__force u32) b;
+}
+
+static int be32_gt(__be32 a, __be32 b)
+{
+       return (__force u32) a > (__force u32) b;
+}
+
+static int be64_lt(__be64 a, __be64 b)
+{
+       return (__force u64) a < (__force u64) b;
+}
+
+static int be64_gt(__be64 a, __be64 b)
+{
+       return (__force u64) a > (__force u64) b;
+}
+
+static struct cm_id_private * cm_insert_listen(struct cm_id_private *cm_id_priv)
+{
+       struct rb_node **link = &cm.listen_service_table.rb_node;
+       struct rb_node *parent = NULL;
+       struct cm_id_private *cur_cm_id_priv;
+       __be64 service_id = cm_id_priv->id.service_id;
+       __be64 service_mask = cm_id_priv->id.service_mask;
+       int data_cmp;
+
+       while (*link) {
+               parent = *link;
+               cur_cm_id_priv = rb_entry(parent, struct cm_id_private,
+                                         service_node);
+               data_cmp = cm_compare_data(cm_id_priv->compare_data,
+                                          cur_cm_id_priv->compare_data);
+               if ((cur_cm_id_priv->id.service_mask & service_id) ==
+                   (service_mask & cur_cm_id_priv->id.service_id) &&
+                   (cm_id_priv->id.device == cur_cm_id_priv->id.device) &&
+                   !data_cmp)
+                       return cur_cm_id_priv;
+
+               if (cm_id_priv->id.device < cur_cm_id_priv->id.device)
+                       link = &(*link)->rb_left;
+               else if (cm_id_priv->id.device > cur_cm_id_priv->id.device)
+                       link = &(*link)->rb_right;
+               else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
+                       link = &(*link)->rb_left;
+               else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
+                       link = &(*link)->rb_right;
+               else if (data_cmp < 0)
+                       link = &(*link)->rb_left;
+               else
+                       link = &(*link)->rb_right;
+       }
+       rb_link_node(&cm_id_priv->service_node, parent, link);
+       rb_insert_color(&cm_id_priv->service_node, &cm.listen_service_table);
+       return NULL;
+}
+
+static struct cm_id_private * cm_find_listen(struct ib_device *device,
+                                            __be64 service_id,
+                                            u8 *private_data)
+{
+       struct rb_node *node = cm.listen_service_table.rb_node;
+       struct cm_id_private *cm_id_priv;
+       int data_cmp;
+
+       while (node) {
+               cm_id_priv = rb_entry(node, struct cm_id_private, service_node);
+               data_cmp = cm_compare_private_data(private_data,
+                                                  cm_id_priv->compare_data);
+               if ((cm_id_priv->id.service_mask & service_id) ==
+                    cm_id_priv->id.service_id &&
+                   (cm_id_priv->id.device == device) && !data_cmp)
+                       return cm_id_priv;
+
+               if (device < cm_id_priv->id.device)
+                       node = node->rb_left;
+               else if (device > cm_id_priv->id.device)
+                       node = node->rb_right;
+               else if (be64_lt(service_id, cm_id_priv->id.service_id))
+                       node = node->rb_left;
+               else if (be64_gt(service_id, cm_id_priv->id.service_id))
+                       node = node->rb_right;
+               else if (data_cmp < 0)
+                       node = node->rb_left;
+               else
+                       node = node->rb_right;
+       }
+       return NULL;
+}
+
+static struct cm_timewait_info * cm_insert_remote_id(struct cm_timewait_info
+                                                    *timewait_info)
+{
+       struct rb_node **link = &cm.remote_id_table.rb_node;
+       struct rb_node *parent = NULL;
+       struct cm_timewait_info *cur_timewait_info;
+       __be64 remote_ca_guid = timewait_info->remote_ca_guid;
+       __be32 remote_id = timewait_info->work.remote_id;
+
+       while (*link) {
+               parent = *link;
+               cur_timewait_info = rb_entry(parent, struct cm_timewait_info,
+                                            remote_id_node);
+               if (be32_lt(remote_id, cur_timewait_info->work.remote_id))
+                       link = &(*link)->rb_left;
+               else if (be32_gt(remote_id, cur_timewait_info->work.remote_id))
+                       link = &(*link)->rb_right;
+               else if (be64_lt(remote_ca_guid, cur_timewait_info->remote_ca_guid))
+                       link = &(*link)->rb_left;
+               else if (be64_gt(remote_ca_guid, cur_timewait_info->remote_ca_guid))
+                       link = &(*link)->rb_right;
+               else
+                       return cur_timewait_info;
+       }
+       timewait_info->inserted_remote_id = 1;
+       rb_link_node(&timewait_info->remote_id_node, parent, link);
+       rb_insert_color(&timewait_info->remote_id_node, &cm.remote_id_table);
+       return NULL;
+}
+
+static struct cm_timewait_info * cm_find_remote_id(__be64 remote_ca_guid,
+                                                  __be32 remote_id)
+{
+       struct rb_node *node = cm.remote_id_table.rb_node;
+       struct cm_timewait_info *timewait_info;
+
+       while (node) {
+               timewait_info = rb_entry(node, struct cm_timewait_info,
+                                        remote_id_node);
+               if (be32_lt(remote_id, timewait_info->work.remote_id))
+                       node = node->rb_left;
+               else if (be32_gt(remote_id, timewait_info->work.remote_id))
+                       node = node->rb_right;
+               else if (be64_lt(remote_ca_guid, timewait_info->remote_ca_guid))
+                       node = node->rb_left;
+               else if (be64_gt(remote_ca_guid, timewait_info->remote_ca_guid))
+                       node = node->rb_right;
+               else
+                       return timewait_info;
+       }
+       return NULL;
+}
+
+static struct cm_timewait_info * cm_insert_remote_qpn(struct cm_timewait_info
+                                                     *timewait_info)
+{
+       struct rb_node **link = &cm.remote_qp_table.rb_node;
+       struct rb_node *parent = NULL;
+       struct cm_timewait_info *cur_timewait_info;
+       __be64 remote_ca_guid = timewait_info->remote_ca_guid;
+       __be32 remote_qpn = timewait_info->remote_qpn;
+
+       while (*link) {
+               parent = *link;
+               cur_timewait_info = rb_entry(parent, struct cm_timewait_info,
+                                            remote_qp_node);
+               if (be32_lt(remote_qpn, cur_timewait_info->remote_qpn))
+                       link = &(*link)->rb_left;
+               else if (be32_gt(remote_qpn, cur_timewait_info->remote_qpn))
+                       link = &(*link)->rb_right;
+               else if (be64_lt(remote_ca_guid, cur_timewait_info->remote_ca_guid))
+                       link = &(*link)->rb_left;
+               else if (be64_gt(remote_ca_guid, cur_timewait_info->remote_ca_guid))
+                       link = &(*link)->rb_right;
+               else
+                       return cur_timewait_info;
+       }
+       timewait_info->inserted_remote_qp = 1;
+       rb_link_node(&timewait_info->remote_qp_node, parent, link);
+       rb_insert_color(&timewait_info->remote_qp_node, &cm.remote_qp_table);
+       return NULL;
+}
+
+static struct cm_id_private * cm_insert_remote_sidr(struct cm_id_private
+                                                   *cm_id_priv)
+{
+       struct rb_node **link = &cm.remote_sidr_table.rb_node;
+       struct rb_node *parent = NULL;
+       struct cm_id_private *cur_cm_id_priv;
+       union ib_gid *port_gid = &cm_id_priv->av.dgid;
+       __be32 remote_id = cm_id_priv->id.remote_id;
+
+       while (*link) {
+               parent = *link;
+               cur_cm_id_priv = rb_entry(parent, struct cm_id_private,
+                                         sidr_id_node);
+               if (be32_lt(remote_id, cur_cm_id_priv->id.remote_id))
+                       link = &(*link)->rb_left;
+               else if (be32_gt(remote_id, cur_cm_id_priv->id.remote_id))
+                       link = &(*link)->rb_right;
+               else {
+                       int cmp;
+                       cmp = memcmp(port_gid, &cur_cm_id_priv->av.dgid,
+                                    sizeof *port_gid);
+                       if (cmp < 0)
+                               link = &(*link)->rb_left;
+                       else if (cmp > 0)
+                               link = &(*link)->rb_right;
+                       else
+                               return cur_cm_id_priv;
+               }
+       }
+       rb_link_node(&cm_id_priv->sidr_id_node, parent, link);
+       rb_insert_color(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table);
+       return NULL;
+}
+
+static void cm_reject_sidr_req(struct cm_id_private *cm_id_priv,
+                              enum ib_cm_sidr_status status)
+{
+       struct ib_cm_sidr_rep_param param;
+
+       memset(&param, 0, sizeof param);
+       param.status = status;
+       ib_send_cm_sidr_rep(&cm_id_priv->id, &param);
+}
+
+struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
+                                ib_cm_handler cm_handler,
+                                void *context)
+{
+       struct cm_id_private *cm_id_priv;
+       int ret;
+
+       cm_id_priv = kzalloc(sizeof *cm_id_priv, GFP_KERNEL);
+       if (!cm_id_priv)
+               return ERR_PTR(-ENOMEM);
+
+       cm_id_priv->id.state = IB_CM_IDLE;
+       cm_id_priv->id.device = device;
+       cm_id_priv->id.cm_handler = cm_handler;
+       cm_id_priv->id.context = context;
+       cm_id_priv->id.remote_cm_qpn = 1;
+       ret = cm_alloc_id(cm_id_priv);
+       if (ret)
+               goto error;
+
+       spin_lock_init(&cm_id_priv->lock);
+       init_completion(&cm_id_priv->comp);
+       INIT_LIST_HEAD(&cm_id_priv->work_list);
+       atomic_set(&cm_id_priv->work_count, -1);
+       atomic_set(&cm_id_priv->refcount, 1);
+       return &cm_id_priv->id;
+
+error:
+       kfree(cm_id_priv);
+       return ERR_PTR(-ENOMEM);
+}
+EXPORT_SYMBOL(ib_create_cm_id);
+
+static struct cm_work * cm_dequeue_work(struct cm_id_private *cm_id_priv)
+{
+       struct cm_work *work;
+
+       if (list_empty(&cm_id_priv->work_list))
+               return NULL;
+
+       work = list_entry(cm_id_priv->work_list.next, struct cm_work, list);
+       list_del(&work->list);
+       return work;
+}
+
+static void cm_free_work(struct cm_work *work)
+{
+       if (work->mad_recv_wc)
+               ib_free_recv_mad(work->mad_recv_wc);
+       kfree(work);
+}
+
+static inline int cm_convert_to_ms(int iba_time)
+{
+       /* approximate conversion to ms from 4.096us x 2^iba_time */
+       return 1 << max(iba_time - 8, 0);
+}
+
+/*
+ * calculate: 4.096x2^ack_timeout = 4.096x2^ack_delay + 2x4.096x2^life_time
+ * Because of how ack_timeout is stored, adding one doubles the timeout.
+ * To avoid large timeouts, select the max(ack_delay, life_time + 1), and
+ * increment it (round up) only if the other is within 50%.
+ */
+static u8 cm_ack_timeout(u8 ca_ack_delay, u8 packet_life_time)
+{
+       int ack_timeout = packet_life_time + 1;
+
+       if (ack_timeout >= ca_ack_delay)
+               ack_timeout += (ca_ack_delay >= (ack_timeout - 1));
+       else
+               ack_timeout = ca_ack_delay +
+                             (ack_timeout >= (ca_ack_delay - 1));
+
+       return min(31, ack_timeout);
+}
+
+static void cm_cleanup_timewait(struct cm_timewait_info *timewait_info)
+{
+       if (timewait_info->inserted_remote_id) {
+               rb_erase(&timewait_info->remote_id_node, &cm.remote_id_table);
+               timewait_info->inserted_remote_id = 0;
+       }
+
+       if (timewait_info->inserted_remote_qp) {
+               rb_erase(&timewait_info->remote_qp_node, &cm.remote_qp_table);
+               timewait_info->inserted_remote_qp = 0;
+       }
+}
+
+static struct cm_timewait_info * cm_create_timewait_info(__be32 local_id)
+{
+       struct cm_timewait_info *timewait_info;
+
+       timewait_info = kzalloc(sizeof *timewait_info, GFP_KERNEL);
+       if (!timewait_info)
+               return ERR_PTR(-ENOMEM);
+
+       timewait_info->work.local_id = local_id;
+       INIT_DELAYED_WORK(&timewait_info->work.work, cm_work_handler);
+       timewait_info->work.cm_event.event = IB_CM_TIMEWAIT_EXIT;
+       return timewait_info;
+}
+
+static void cm_enter_timewait(struct cm_id_private *cm_id_priv)
+{
+       int wait_time;
+       unsigned long flags;
+
+       spin_lock_irqsave(&cm.lock, flags);
+       cm_cleanup_timewait(cm_id_priv->timewait_info);
+       list_add_tail(&cm_id_priv->timewait_info->list, &cm.timewait_list);
+       spin_unlock_irqrestore(&cm.lock, flags);
+
+       /*
+        * The cm_id could be destroyed by the user before we exit timewait.
+        * To protect against this, we search for the cm_id after exiting
+        * timewait before notifying the user that we've exited timewait.
+        */
+       cm_id_priv->id.state = IB_CM_TIMEWAIT;
+       wait_time = cm_convert_to_ms(cm_id_priv->av.timeout);
+       queue_delayed_work(cm.wq, &cm_id_priv->timewait_info->work.work,
+                          msecs_to_jiffies(wait_time));
+       cm_id_priv->timewait_info = NULL;
+}
+
+static void cm_reset_to_idle(struct cm_id_private *cm_id_priv)
+{
+       unsigned long flags;
+
+       cm_id_priv->id.state = IB_CM_IDLE;
+       if (cm_id_priv->timewait_info) {
+               spin_lock_irqsave(&cm.lock, flags);
+               cm_cleanup_timewait(cm_id_priv->timewait_info);
+               spin_unlock_irqrestore(&cm.lock, flags);
+               kfree(cm_id_priv->timewait_info);
+               cm_id_priv->timewait_info = NULL;
+       }
+}
+
+static void cm_destroy_id(struct ib_cm_id *cm_id, int err)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_work *work;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+retest:
+       spin_lock_irq(&cm_id_priv->lock);
+       switch (cm_id->state) {
+       case IB_CM_LISTEN:
+               cm_id->state = IB_CM_IDLE;
+               spin_unlock_irq(&cm_id_priv->lock);
+               spin_lock_irq(&cm.lock);
+               rb_erase(&cm_id_priv->service_node, &cm.listen_service_table);
+               spin_unlock_irq(&cm.lock);
+               break;
+       case IB_CM_SIDR_REQ_SENT:
+               cm_id->state = IB_CM_IDLE;
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               spin_unlock_irq(&cm_id_priv->lock);
+               break;
+       case IB_CM_SIDR_REQ_RCVD:
+               spin_unlock_irq(&cm_id_priv->lock);
+               cm_reject_sidr_req(cm_id_priv, IB_SIDR_REJECT);
+               break;
+       case IB_CM_REQ_SENT:
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               spin_unlock_irq(&cm_id_priv->lock);
+               ib_send_cm_rej(cm_id, IB_CM_REJ_TIMEOUT,
+                              &cm_id_priv->id.device->node_guid,
+                              sizeof cm_id_priv->id.device->node_guid,
+                              NULL, 0);
+               break;
+       case IB_CM_REQ_RCVD:
+               if (err == -ENOMEM) {
+                       /* Do not reject to allow future retries. */
+                       cm_reset_to_idle(cm_id_priv);
+                       spin_unlock_irq(&cm_id_priv->lock);
+               } else {
+                       spin_unlock_irq(&cm_id_priv->lock);
+                       ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED,
+                                      NULL, 0, NULL, 0);
+               }
+               break;
+       case IB_CM_MRA_REQ_RCVD:
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               /* Fall through */
+       case IB_CM_MRA_REQ_SENT:
+       case IB_CM_REP_RCVD:
+       case IB_CM_MRA_REP_SENT:
+               spin_unlock_irq(&cm_id_priv->lock);
+               ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED,
+                              NULL, 0, NULL, 0);
+               break;
+       case IB_CM_ESTABLISHED:
+               spin_unlock_irq(&cm_id_priv->lock);
+               if (cm_id_priv->qp_type == IB_QPT_XRC_TGT)
+                       break;
+               ib_send_cm_dreq(cm_id, NULL, 0);
+               goto retest;
+       case IB_CM_DREQ_SENT:
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               cm_enter_timewait(cm_id_priv);
+               spin_unlock_irq(&cm_id_priv->lock);
+               break;
+       case IB_CM_DREQ_RCVD:
+               spin_unlock_irq(&cm_id_priv->lock);
+               ib_send_cm_drep(cm_id, NULL, 0);
+               break;
+       default:
+               spin_unlock_irq(&cm_id_priv->lock);
+               break;
+       }
+
+       cm_free_id(cm_id->local_id);
+       cm_deref_id(cm_id_priv);
+       wait_for_completion(&cm_id_priv->comp);
+       while ((work = cm_dequeue_work(cm_id_priv)) != NULL)
+               cm_free_work(work);
+       kfree(cm_id_priv->compare_data);
+       kfree(cm_id_priv->private_data);
+       kfree(cm_id_priv);
+}
+
+void ib_destroy_cm_id(struct ib_cm_id *cm_id)
+{
+       cm_destroy_id(cm_id, 0);
+}
+EXPORT_SYMBOL(ib_destroy_cm_id);
+
+int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,
+                struct ib_cm_compare_data *compare_data)
+{
+       struct cm_id_private *cm_id_priv, *cur_cm_id_priv;
+       unsigned long flags;
+       int ret = 0;
+
+       service_mask = service_mask ? service_mask : ~cpu_to_be64(0);
+       service_id &= service_mask;
+       if ((service_id & IB_SERVICE_ID_AGN_MASK) == IB_CM_ASSIGN_SERVICE_ID &&
+           (service_id != IB_CM_ASSIGN_SERVICE_ID))
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       if (cm_id->state != IB_CM_IDLE)
+               return -EINVAL;
+
+       if (compare_data) {
+               cm_id_priv->compare_data = kzalloc(sizeof *compare_data,
+                                                  GFP_KERNEL);
+               if (!cm_id_priv->compare_data)
+                       return -ENOMEM;
+               cm_mask_copy(cm_id_priv->compare_data->data,
+                            compare_data->data, compare_data->mask);
+               memcpy(cm_id_priv->compare_data->mask, compare_data->mask,
+                      IB_CM_COMPARE_SIZE);
+       }
+
+       cm_id->state = IB_CM_LISTEN;
+
+       spin_lock_irqsave(&cm.lock, flags);
+       if (service_id == IB_CM_ASSIGN_SERVICE_ID) {
+               cm_id->service_id = cpu_to_be64(cm.listen_service_id++);
+               cm_id->service_mask = ~cpu_to_be64(0);
+       } else {
+               cm_id->service_id = service_id;
+               cm_id->service_mask = service_mask;
+       }
+       cur_cm_id_priv = cm_insert_listen(cm_id_priv);
+       spin_unlock_irqrestore(&cm.lock, flags);
+
+       if (cur_cm_id_priv) {
+               cm_id->state = IB_CM_IDLE;
+               kfree(cm_id_priv->compare_data);
+               cm_id_priv->compare_data = NULL;
+               ret = -EBUSY;
+       }
+       return ret;
+}
+EXPORT_SYMBOL(ib_cm_listen);
+
+static __be64 cm_form_tid(struct cm_id_private *cm_id_priv,
+                         enum cm_msg_sequence msg_seq)
+{
+       u64 hi_tid, low_tid;
+
+       hi_tid   = ((u64) cm_id_priv->av.port->mad_agent->hi_tid) << 32;
+       low_tid  = (u64) ((__force u32)cm_id_priv->id.local_id |
+                         (msg_seq << 30));
+       return cpu_to_be64(hi_tid | low_tid);
+}
+
+static void cm_format_mad_hdr(struct ib_mad_hdr *hdr,
+                             __be16 attr_id, __be64 tid)
+{
+       hdr->base_version  = IB_MGMT_BASE_VERSION;
+       hdr->mgmt_class    = IB_MGMT_CLASS_CM;
+       hdr->class_version = IB_CM_CLASS_VERSION;
+       hdr->method        = IB_MGMT_METHOD_SEND;
+       hdr->attr_id       = attr_id;
+       hdr->tid           = tid;
+}
+
+static void cm_format_req(struct cm_req_msg *req_msg,
+                         struct cm_id_private *cm_id_priv,
+                         struct ib_cm_req_param *param)
+{
+       struct ib_sa_path_rec *pri_path = param->primary_path;
+       struct ib_sa_path_rec *alt_path = param->alternate_path;
+
+       cm_format_mad_hdr(&req_msg->hdr, CM_REQ_ATTR_ID,
+                         cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_REQ));
+
+       req_msg->local_comm_id = cm_id_priv->id.local_id;
+       req_msg->service_id = param->service_id;
+       req_msg->local_ca_guid = cm_id_priv->id.device->node_guid;
+       cm_req_set_local_qpn(req_msg, cpu_to_be32(param->qp_num));
+       cm_req_set_init_depth(req_msg, param->initiator_depth);
+       cm_req_set_remote_resp_timeout(req_msg,
+                                      param->remote_cm_response_timeout);
+       cm_req_set_qp_type(req_msg, param->qp_type);
+       cm_req_set_flow_ctrl(req_msg, param->flow_control);
+       cm_req_set_starting_psn(req_msg, cpu_to_be32(param->starting_psn));
+       cm_req_set_local_resp_timeout(req_msg,
+                                     param->local_cm_response_timeout);
+       req_msg->pkey = param->primary_path->pkey;
+       cm_req_set_path_mtu(req_msg, param->primary_path->mtu);
+       cm_req_set_max_cm_retries(req_msg, param->max_cm_retries);
+
+       if (param->qp_type != IB_QPT_XRC_INI) {
+               cm_req_set_resp_res(req_msg, param->responder_resources);
+               cm_req_set_retry_count(req_msg, param->retry_count);
+               cm_req_set_rnr_retry_count(req_msg, param->rnr_retry_count);
+               cm_req_set_srq(req_msg, param->srq);
+       }
+
+       if (pri_path->hop_limit <= 1) {
+               req_msg->primary_local_lid = pri_path->slid;
+               req_msg->primary_remote_lid = pri_path->dlid;
+       } else {
+               /* Work-around until there's a way to obtain remote LID info */
+               req_msg->primary_local_lid = IB_LID_PERMISSIVE;
+               req_msg->primary_remote_lid = IB_LID_PERMISSIVE;
+       }
+       req_msg->primary_local_gid = pri_path->sgid;
+       req_msg->primary_remote_gid = pri_path->dgid;
+       cm_req_set_primary_flow_label(req_msg, pri_path->flow_label);
+       cm_req_set_primary_packet_rate(req_msg, pri_path->rate);
+       req_msg->primary_traffic_class = pri_path->traffic_class;
+       req_msg->primary_hop_limit = pri_path->hop_limit;
+       cm_req_set_primary_sl(req_msg, pri_path->sl);
+       cm_req_set_primary_subnet_local(req_msg, (pri_path->hop_limit <= 1));
+       cm_req_set_primary_local_ack_timeout(req_msg,
+               cm_ack_timeout(cm_id_priv->av.port->cm_dev->ack_delay,
+                              pri_path->packet_life_time));
+
+       if (alt_path) {
+               if (alt_path->hop_limit <= 1) {
+                       req_msg->alt_local_lid = alt_path->slid;
+                       req_msg->alt_remote_lid = alt_path->dlid;
+               } else {
+                       req_msg->alt_local_lid = IB_LID_PERMISSIVE;
+                       req_msg->alt_remote_lid = IB_LID_PERMISSIVE;
+               }
+               req_msg->alt_local_gid = alt_path->sgid;
+               req_msg->alt_remote_gid = alt_path->dgid;
+               cm_req_set_alt_flow_label(req_msg,
+                                         alt_path->flow_label);
+               cm_req_set_alt_packet_rate(req_msg, alt_path->rate);
+               req_msg->alt_traffic_class = alt_path->traffic_class;
+               req_msg->alt_hop_limit = alt_path->hop_limit;
+               cm_req_set_alt_sl(req_msg, alt_path->sl);
+               cm_req_set_alt_subnet_local(req_msg, (alt_path->hop_limit <= 1));
+               cm_req_set_alt_local_ack_timeout(req_msg,
+                       cm_ack_timeout(cm_id_priv->av.port->cm_dev->ack_delay,
+                                      alt_path->packet_life_time));
+       }
+
+       if (param->private_data && param->private_data_len)
+               memcpy(req_msg->private_data, param->private_data,
+                      param->private_data_len);
+}
+
+static int cm_validate_req_param(struct ib_cm_req_param *param)
+{
+       /* peer-to-peer not supported */
+       if (param->peer_to_peer)
+               return -EINVAL;
+
+       if (!param->primary_path)
+               return -EINVAL;
+
+       if (param->qp_type != IB_QPT_RC && param->qp_type != IB_QPT_UC &&
+           param->qp_type != IB_QPT_XRC_INI)
+               return -EINVAL;
+
+       if (param->private_data &&
+           param->private_data_len > IB_CM_REQ_PRIVATE_DATA_SIZE)
+               return -EINVAL;
+
+       if (param->alternate_path &&
+           (param->alternate_path->pkey != param->primary_path->pkey ||
+            param->alternate_path->mtu != param->primary_path->mtu))
+               return -EINVAL;
+
+       return 0;
+}
+
+int ib_send_cm_req(struct ib_cm_id *cm_id,
+                  struct ib_cm_req_param *param)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_req_msg *req_msg;
+       unsigned long flags;
+       int ret;
+
+       ret = cm_validate_req_param(param);
+       if (ret)
+               return ret;
+
+       /* Verify that we're not in timewait. */
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_IDLE) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               ret = -EINVAL;
+               goto out;
+       }
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+       cm_id_priv->timewait_info = cm_create_timewait_info(cm_id_priv->
+                                                           id.local_id);
+       if (IS_ERR(cm_id_priv->timewait_info)) {
+               ret = PTR_ERR(cm_id_priv->timewait_info);
+               goto out;
+       }
+
+       ret = cm_init_av_by_path(param->primary_path, &cm_id_priv->av);
+       if (ret)
+               goto error1;
+       if (param->alternate_path) {
+               ret = cm_init_av_by_path(param->alternate_path,
+                                        &cm_id_priv->alt_av);
+               if (ret)
+                       goto error1;
+       }
+       cm_id->service_id = param->service_id;
+       cm_id->service_mask = ~cpu_to_be64(0);
+       cm_id_priv->timeout_ms = cm_convert_to_ms(
+                                   param->primary_path->packet_life_time) * 2 +
+                                cm_convert_to_ms(
+                                   param->remote_cm_response_timeout);
+       cm_id_priv->max_cm_retries = param->max_cm_retries;
+       cm_id_priv->initiator_depth = param->initiator_depth;
+       cm_id_priv->responder_resources = param->responder_resources;
+       cm_id_priv->retry_count = param->retry_count;
+       cm_id_priv->path_mtu = param->primary_path->mtu;
+       cm_id_priv->pkey = param->primary_path->pkey;
+       cm_id_priv->qp_type = param->qp_type;
+
+       ret = cm_alloc_msg(cm_id_priv, &cm_id_priv->msg);
+       if (ret)
+               goto error1;
+
+       req_msg = (struct cm_req_msg *) cm_id_priv->msg->mad;
+       cm_format_req(req_msg, cm_id_priv, param);
+       cm_id_priv->tid = req_msg->hdr.tid;
+       cm_id_priv->msg->timeout_ms = cm_id_priv->timeout_ms;
+       cm_id_priv->msg->context[1] = (void *) (unsigned long) IB_CM_REQ_SENT;
+
+       cm_id_priv->local_qpn = cm_req_get_local_qpn(req_msg);
+       cm_id_priv->rq_psn = cm_req_get_starting_psn(req_msg);
+
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       ret = ib_post_send_mad(cm_id_priv->msg, NULL);
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               goto error2;
+       }
+       BUG_ON(cm_id->state != IB_CM_IDLE);
+       cm_id->state = IB_CM_REQ_SENT;
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return 0;
+
+error2:        cm_free_msg(cm_id_priv->msg);
+error1:        kfree(cm_id_priv->timewait_info);
+out:   return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_req);
+
+static int cm_issue_rej(struct cm_port *port,
+                       struct ib_mad_recv_wc *mad_recv_wc,
+                       enum ib_cm_rej_reason reason,
+                       enum cm_msg_response msg_rejected,
+                       void *ari, u8 ari_length)
+{
+       struct ib_mad_send_buf *msg = NULL;
+       struct cm_rej_msg *rej_msg, *rcv_msg;
+       int ret;
+
+       ret = cm_alloc_response_msg(port, mad_recv_wc, &msg);
+       if (ret)
+               return ret;
+
+       /* We just need common CM header information.  Cast to any message. */
+       rcv_msg = (struct cm_rej_msg *) mad_recv_wc->recv_buf.mad;
+       rej_msg = (struct cm_rej_msg *) msg->mad;
+
+       cm_format_mad_hdr(&rej_msg->hdr, CM_REJ_ATTR_ID, rcv_msg->hdr.tid);
+       rej_msg->remote_comm_id = rcv_msg->local_comm_id;
+       rej_msg->local_comm_id = rcv_msg->remote_comm_id;
+       cm_rej_set_msg_rejected(rej_msg, msg_rejected);
+       rej_msg->reason = cpu_to_be16(reason);
+
+       if (ari && ari_length) {
+               cm_rej_set_reject_info_len(rej_msg, ari_length);
+               memcpy(rej_msg->ari, ari, ari_length);
+       }
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret)
+               cm_free_msg(msg);
+
+       return ret;
+}
+
+static inline int cm_is_active_peer(__be64 local_ca_guid, __be64 remote_ca_guid,
+                                   __be32 local_qpn, __be32 remote_qpn)
+{
+       return (be64_to_cpu(local_ca_guid) > be64_to_cpu(remote_ca_guid) ||
+               ((local_ca_guid == remote_ca_guid) &&
+                (be32_to_cpu(local_qpn) > be32_to_cpu(remote_qpn))));
+}
+
+static void cm_format_paths_from_req(struct cm_req_msg *req_msg,
+                                           struct ib_sa_path_rec *primary_path,
+                                           struct ib_sa_path_rec *alt_path)
+{
+       memset(primary_path, 0, sizeof *primary_path);
+       primary_path->dgid = req_msg->primary_local_gid;
+       primary_path->sgid = req_msg->primary_remote_gid;
+       primary_path->dlid = req_msg->primary_local_lid;
+       primary_path->slid = req_msg->primary_remote_lid;
+       primary_path->flow_label = cm_req_get_primary_flow_label(req_msg);
+       primary_path->hop_limit = req_msg->primary_hop_limit;
+       primary_path->traffic_class = req_msg->primary_traffic_class;
+       primary_path->reversible = 1;
+       primary_path->pkey = req_msg->pkey;
+       primary_path->sl = cm_req_get_primary_sl(req_msg);
+       primary_path->mtu_selector = IB_SA_EQ;
+       primary_path->mtu = cm_req_get_path_mtu(req_msg);
+       primary_path->rate_selector = IB_SA_EQ;
+       primary_path->rate = cm_req_get_primary_packet_rate(req_msg);
+       primary_path->packet_life_time_selector = IB_SA_EQ;
+       primary_path->packet_life_time =
+               cm_req_get_primary_local_ack_timeout(req_msg);
+       primary_path->packet_life_time -= (primary_path->packet_life_time > 0);
+
+       if (req_msg->alt_local_lid) {
+               memset(alt_path, 0, sizeof *alt_path);
+               alt_path->dgid = req_msg->alt_local_gid;
+               alt_path->sgid = req_msg->alt_remote_gid;
+               alt_path->dlid = req_msg->alt_local_lid;
+               alt_path->slid = req_msg->alt_remote_lid;
+               alt_path->flow_label = cm_req_get_alt_flow_label(req_msg);
+               alt_path->hop_limit = req_msg->alt_hop_limit;
+               alt_path->traffic_class = req_msg->alt_traffic_class;
+               alt_path->reversible = 1;
+               alt_path->pkey = req_msg->pkey;
+               alt_path->sl = cm_req_get_alt_sl(req_msg);
+               alt_path->mtu_selector = IB_SA_EQ;
+               alt_path->mtu = cm_req_get_path_mtu(req_msg);
+               alt_path->rate_selector = IB_SA_EQ;
+               alt_path->rate = cm_req_get_alt_packet_rate(req_msg);
+               alt_path->packet_life_time_selector = IB_SA_EQ;
+               alt_path->packet_life_time =
+                       cm_req_get_alt_local_ack_timeout(req_msg);
+               alt_path->packet_life_time -= (alt_path->packet_life_time > 0);
+       }
+}
+
+static void cm_format_req_event(struct cm_work *work,
+                               struct cm_id_private *cm_id_priv,
+                               struct ib_cm_id *listen_id)
+{
+       struct cm_req_msg *req_msg;
+       struct ib_cm_req_event_param *param;
+
+       req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
+       param = &work->cm_event.param.req_rcvd;
+       param->listen_id = listen_id;
+       param->port = cm_id_priv->av.port->port_num;
+       param->primary_path = &work->path[0];
+       if (req_msg->alt_local_lid)
+               param->alternate_path = &work->path[1];
+       else
+               param->alternate_path = NULL;
+       param->remote_ca_guid = req_msg->local_ca_guid;
+       param->remote_qkey = be32_to_cpu(req_msg->local_qkey);
+       param->remote_qpn = be32_to_cpu(cm_req_get_local_qpn(req_msg));
+       param->qp_type = cm_req_get_qp_type(req_msg);
+       param->starting_psn = be32_to_cpu(cm_req_get_starting_psn(req_msg));
+       param->responder_resources = cm_req_get_init_depth(req_msg);
+       param->initiator_depth = cm_req_get_resp_res(req_msg);
+       param->local_cm_response_timeout =
+                                       cm_req_get_remote_resp_timeout(req_msg);
+       param->flow_control = cm_req_get_flow_ctrl(req_msg);
+       param->remote_cm_response_timeout =
+                                       cm_req_get_local_resp_timeout(req_msg);
+       param->retry_count = cm_req_get_retry_count(req_msg);
+       param->rnr_retry_count = cm_req_get_rnr_retry_count(req_msg);
+       param->srq = cm_req_get_srq(req_msg);
+       work->cm_event.private_data = &req_msg->private_data;
+}
+
+static void cm_process_work(struct cm_id_private *cm_id_priv,
+                           struct cm_work *work)
+{
+       int ret;
+
+       /* We will typically only have the current event to report. */
+       ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &work->cm_event);
+       cm_free_work(work);
+
+       while (!ret && !atomic_add_negative(-1, &cm_id_priv->work_count)) {
+               spin_lock_irq(&cm_id_priv->lock);
+               work = cm_dequeue_work(cm_id_priv);
+               spin_unlock_irq(&cm_id_priv->lock);
+               BUG_ON(!work);
+               ret = cm_id_priv->id.cm_handler(&cm_id_priv->id,
+                                               &work->cm_event);
+               cm_free_work(work);
+       }
+       cm_deref_id(cm_id_priv);
+       if (ret)
+               cm_destroy_id(&cm_id_priv->id, ret);
+}
+
+static void cm_format_mra(struct cm_mra_msg *mra_msg,
+                         struct cm_id_private *cm_id_priv,
+                         enum cm_msg_response msg_mraed, u8 service_timeout,
+                         const void *private_data, u8 private_data_len)
+{
+       cm_format_mad_hdr(&mra_msg->hdr, CM_MRA_ATTR_ID, cm_id_priv->tid);
+       cm_mra_set_msg_mraed(mra_msg, msg_mraed);
+       mra_msg->local_comm_id = cm_id_priv->id.local_id;
+       mra_msg->remote_comm_id = cm_id_priv->id.remote_id;
+       cm_mra_set_service_timeout(mra_msg, service_timeout);
+
+       if (private_data && private_data_len)
+               memcpy(mra_msg->private_data, private_data, private_data_len);
+}
+
+static void cm_format_rej(struct cm_rej_msg *rej_msg,
+                         struct cm_id_private *cm_id_priv,
+                         enum ib_cm_rej_reason reason,
+                         void *ari,
+                         u8 ari_length,
+                         const void *private_data,
+                         u8 private_data_len)
+{
+       cm_format_mad_hdr(&rej_msg->hdr, CM_REJ_ATTR_ID, cm_id_priv->tid);
+       rej_msg->remote_comm_id = cm_id_priv->id.remote_id;
+
+       switch(cm_id_priv->id.state) {
+       case IB_CM_REQ_RCVD:
+               rej_msg->local_comm_id = 0;
+               cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_REQ);
+               break;
+       case IB_CM_MRA_REQ_SENT:
+               rej_msg->local_comm_id = cm_id_priv->id.local_id;
+               cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_REQ);
+               break;
+       case IB_CM_REP_RCVD:
+       case IB_CM_MRA_REP_SENT:
+               rej_msg->local_comm_id = cm_id_priv->id.local_id;
+               cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_REP);
+               break;
+       default:
+               rej_msg->local_comm_id = cm_id_priv->id.local_id;
+               cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_OTHER);
+               break;
+       }
+
+       rej_msg->reason = cpu_to_be16(reason);
+       if (ari && ari_length) {
+               cm_rej_set_reject_info_len(rej_msg, ari_length);
+               memcpy(rej_msg->ari, ari, ari_length);
+       }
+
+       if (private_data && private_data_len)
+               memcpy(rej_msg->private_data, private_data, private_data_len);
+}
+
+static void cm_dup_req_handler(struct cm_work *work,
+                              struct cm_id_private *cm_id_priv)
+{
+       struct ib_mad_send_buf *msg = NULL;
+       int ret;
+
+       atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                       counter[CM_REQ_COUNTER]);
+
+       /* Quick state check to discard duplicate REQs. */
+       if (cm_id_priv->id.state == IB_CM_REQ_RCVD)
+               return;
+
+       ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
+       if (ret)
+               return;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       switch (cm_id_priv->id.state) {
+       case IB_CM_MRA_REQ_SENT:
+               cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
+                             CM_MSG_RESPONSE_REQ, cm_id_priv->service_timeout,
+                             cm_id_priv->private_data,
+                             cm_id_priv->private_data_len);
+               break;
+       case IB_CM_TIMEWAIT:
+               cm_format_rej((struct cm_rej_msg *) msg->mad, cm_id_priv,
+                             IB_CM_REJ_STALE_CONN, NULL, 0, NULL, 0);
+               break;
+       default:
+               goto unlock;
+       }
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret)
+               goto free;
+       return;
+
+unlock:        spin_unlock_irq(&cm_id_priv->lock);
+free:  cm_free_msg(msg);
+}
+
+static struct cm_id_private * cm_match_req(struct cm_work *work,
+                                          struct cm_id_private *cm_id_priv)
+{
+       struct cm_id_private *listen_cm_id_priv, *cur_cm_id_priv;
+       struct cm_timewait_info *timewait_info;
+       struct cm_req_msg *req_msg;
+
+       req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
+
+       /* Check for possible duplicate REQ. */
+       spin_lock_irq(&cm.lock);
+       timewait_info = cm_insert_remote_id(cm_id_priv->timewait_info);
+       if (timewait_info) {
+               cur_cm_id_priv = cm_get_id(timewait_info->work.local_id,
+                                          timewait_info->work.remote_id);
+               spin_unlock_irq(&cm.lock);
+               if (cur_cm_id_priv) {
+                       cm_dup_req_handler(work, cur_cm_id_priv);
+                       cm_deref_id(cur_cm_id_priv);
+               }
+               return NULL;
+       }
+
+       /* Check for stale connections. */
+       timewait_info = cm_insert_remote_qpn(cm_id_priv->timewait_info);
+       if (timewait_info) {
+               cm_cleanup_timewait(cm_id_priv->timewait_info);
+               spin_unlock_irq(&cm.lock);
+               cm_issue_rej(work->port, work->mad_recv_wc,
+                            IB_CM_REJ_STALE_CONN, CM_MSG_RESPONSE_REQ,
+                            NULL, 0);
+               return NULL;
+       }
+
+       /* Find matching listen request. */
+       listen_cm_id_priv = cm_find_listen(cm_id_priv->id.device,
+                                          req_msg->service_id,
+                                          req_msg->private_data);
+       if (!listen_cm_id_priv) {
+               cm_cleanup_timewait(cm_id_priv->timewait_info);
+               spin_unlock_irq(&cm.lock);
+               cm_issue_rej(work->port, work->mad_recv_wc,
+                            IB_CM_REJ_INVALID_SERVICE_ID, CM_MSG_RESPONSE_REQ,
+                            NULL, 0);
+               goto out;
+       }
+       atomic_inc(&listen_cm_id_priv->refcount);
+       atomic_inc(&cm_id_priv->refcount);
+       cm_id_priv->id.state = IB_CM_REQ_RCVD;
+       atomic_inc(&cm_id_priv->work_count);
+       spin_unlock_irq(&cm.lock);
+out:
+       return listen_cm_id_priv;
+}
+
+/*
+ * Work-around for inter-subnet connections.  If the LIDs are permissive,
+ * we need to override the LID/SL data in the REQ with the LID information
+ * in the work completion.
+ */
+static void cm_process_routed_req(struct cm_req_msg *req_msg, struct ib_wc *wc)
+{
+       if (!cm_req_get_primary_subnet_local(req_msg)) {
+               if (req_msg->primary_local_lid == IB_LID_PERMISSIVE) {
+                       req_msg->primary_local_lid = cpu_to_be16(wc->slid);
+                       cm_req_set_primary_sl(req_msg, wc->sl);
+               }
+
+               if (req_msg->primary_remote_lid == IB_LID_PERMISSIVE)
+                       req_msg->primary_remote_lid = cpu_to_be16(wc->dlid_path_bits);
+       }
+
+       if (!cm_req_get_alt_subnet_local(req_msg)) {
+               if (req_msg->alt_local_lid == IB_LID_PERMISSIVE) {
+                       req_msg->alt_local_lid = cpu_to_be16(wc->slid);
+                       cm_req_set_alt_sl(req_msg, wc->sl);
+               }
+
+               if (req_msg->alt_remote_lid == IB_LID_PERMISSIVE)
+                       req_msg->alt_remote_lid = cpu_to_be16(wc->dlid_path_bits);
+       }
+}
+
+static int cm_req_handler(struct cm_work *work)
+{
+       struct ib_cm_id *cm_id;
+       struct cm_id_private *cm_id_priv, *listen_cm_id_priv;
+       struct cm_req_msg *req_msg;
+       int ret;
+
+       req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
+
+       cm_id = ib_create_cm_id(work->port->cm_dev->ib_device, NULL, NULL);
+       if (IS_ERR(cm_id))
+               return PTR_ERR(cm_id);
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       cm_id_priv->id.remote_id = req_msg->local_comm_id;
+       cm_init_av_for_response(work->port, work->mad_recv_wc->wc,
+                               work->mad_recv_wc->recv_buf.grh,
+                               &cm_id_priv->av);
+       cm_id_priv->timewait_info = cm_create_timewait_info(cm_id_priv->
+                                                           id.local_id);
+       if (IS_ERR(cm_id_priv->timewait_info)) {
+               ret = PTR_ERR(cm_id_priv->timewait_info);
+               goto destroy;
+       }
+       cm_id_priv->timewait_info->work.remote_id = req_msg->local_comm_id;
+       cm_id_priv->timewait_info->remote_ca_guid = req_msg->local_ca_guid;
+       cm_id_priv->timewait_info->remote_qpn = cm_req_get_local_qpn(req_msg);
+
+       listen_cm_id_priv = cm_match_req(work, cm_id_priv);
+       if (!listen_cm_id_priv) {
+               ret = -EINVAL;
+               kfree(cm_id_priv->timewait_info);
+               goto destroy;
+       }
+
+       cm_id_priv->id.cm_handler = listen_cm_id_priv->id.cm_handler;
+       cm_id_priv->id.context = listen_cm_id_priv->id.context;
+       cm_id_priv->id.service_id = req_msg->service_id;
+       cm_id_priv->id.service_mask = ~cpu_to_be64(0);
+
+       cm_process_routed_req(req_msg, work->mad_recv_wc->wc);
+       cm_format_paths_from_req(req_msg, &work->path[0], &work->path[1]);
+
+       memcpy(work->path[0].dmac, cm_id_priv->av.ah_attr.dmac, ETH_ALEN);
+       work->path[0].vlan_id = cm_id_priv->av.ah_attr.vlan_id;
+       ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av);
+       if (ret) {
+               ib_get_cached_gid(work->port->cm_dev->ib_device,
+                                 work->port->port_num, 0, &work->path[0].sgid);
+               ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_GID,
+                              &work->path[0].sgid, sizeof work->path[0].sgid,
+                              NULL, 0);
+               goto rejected;
+       }
+       if (req_msg->alt_local_lid) {
+               ret = cm_init_av_by_path(&work->path[1], &cm_id_priv->alt_av);
+               if (ret) {
+                       ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_ALT_GID,
+                                      &work->path[0].sgid,
+                                      sizeof work->path[0].sgid, NULL, 0);
+                       goto rejected;
+               }
+       }
+       cm_id_priv->tid = req_msg->hdr.tid;
+       cm_id_priv->timeout_ms = cm_convert_to_ms(
+                                       cm_req_get_local_resp_timeout(req_msg));
+       cm_id_priv->max_cm_retries = cm_req_get_max_cm_retries(req_msg);
+       cm_id_priv->remote_qpn = cm_req_get_local_qpn(req_msg);
+       cm_id_priv->initiator_depth = cm_req_get_resp_res(req_msg);
+       cm_id_priv->responder_resources = cm_req_get_init_depth(req_msg);
+       cm_id_priv->path_mtu = cm_req_get_path_mtu(req_msg);
+       cm_id_priv->pkey = req_msg->pkey;
+       cm_id_priv->sq_psn = cm_req_get_starting_psn(req_msg);
+       cm_id_priv->retry_count = cm_req_get_retry_count(req_msg);
+       cm_id_priv->rnr_retry_count = cm_req_get_rnr_retry_count(req_msg);
+       cm_id_priv->qp_type = cm_req_get_qp_type(req_msg);
+
+       cm_format_req_event(work, cm_id_priv, &listen_cm_id_priv->id);
+       cm_process_work(cm_id_priv, work);
+       cm_deref_id(listen_cm_id_priv);
+       return 0;
+
+rejected:
+       atomic_dec(&cm_id_priv->refcount);
+       cm_deref_id(listen_cm_id_priv);
+destroy:
+       ib_destroy_cm_id(cm_id);
+       return ret;
+}
+
+static void cm_format_rep(struct cm_rep_msg *rep_msg,
+                         struct cm_id_private *cm_id_priv,
+                         struct ib_cm_rep_param *param)
+{
+       cm_format_mad_hdr(&rep_msg->hdr, CM_REP_ATTR_ID, cm_id_priv->tid);
+       rep_msg->local_comm_id = cm_id_priv->id.local_id;
+       rep_msg->remote_comm_id = cm_id_priv->id.remote_id;
+       cm_rep_set_starting_psn(rep_msg, cpu_to_be32(param->starting_psn));
+       rep_msg->resp_resources = param->responder_resources;
+       cm_rep_set_target_ack_delay(rep_msg,
+                                   cm_id_priv->av.port->cm_dev->ack_delay);
+       cm_rep_set_failover(rep_msg, param->failover_accepted);
+       cm_rep_set_rnr_retry_count(rep_msg, param->rnr_retry_count);
+       rep_msg->local_ca_guid = cm_id_priv->id.device->node_guid;
+
+       if (cm_id_priv->qp_type != IB_QPT_XRC_TGT) {
+               rep_msg->initiator_depth = param->initiator_depth;
+               cm_rep_set_flow_ctrl(rep_msg, param->flow_control);
+               cm_rep_set_srq(rep_msg, param->srq);
+               cm_rep_set_local_qpn(rep_msg, cpu_to_be32(param->qp_num));
+       } else {
+               cm_rep_set_srq(rep_msg, 1);
+               cm_rep_set_local_eecn(rep_msg, cpu_to_be32(param->qp_num));
+       }
+
+       if (param->private_data && param->private_data_len)
+               memcpy(rep_msg->private_data, param->private_data,
+                      param->private_data_len);
+}
+
+int ib_send_cm_rep(struct ib_cm_id *cm_id,
+                  struct ib_cm_rep_param *param)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       struct cm_rep_msg *rep_msg;
+       unsigned long flags;
+       int ret;
+
+       if (param->private_data &&
+           param->private_data_len > IB_CM_REP_PRIVATE_DATA_SIZE)
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_REQ_RCVD &&
+           cm_id->state != IB_CM_MRA_REQ_SENT) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret)
+               goto out;
+
+       rep_msg = (struct cm_rep_msg *) msg->mad;
+       cm_format_rep(rep_msg, cm_id_priv, param);
+       msg->timeout_ms = cm_id_priv->timeout_ms;
+       msg->context[1] = (void *) (unsigned long) IB_CM_REP_SENT;
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               return ret;
+       }
+
+       cm_id->state = IB_CM_REP_SENT;
+       cm_id_priv->msg = msg;
+       cm_id_priv->initiator_depth = param->initiator_depth;
+       cm_id_priv->responder_resources = param->responder_resources;
+       cm_id_priv->rq_psn = cm_rep_get_starting_psn(rep_msg);
+       cm_id_priv->local_qpn = cpu_to_be32(param->qp_num & 0xFFFFFF);
+
+out:   spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_rep);
+
+static void cm_format_rtu(struct cm_rtu_msg *rtu_msg,
+                         struct cm_id_private *cm_id_priv,
+                         const void *private_data,
+                         u8 private_data_len)
+{
+       cm_format_mad_hdr(&rtu_msg->hdr, CM_RTU_ATTR_ID, cm_id_priv->tid);
+       rtu_msg->local_comm_id = cm_id_priv->id.local_id;
+       rtu_msg->remote_comm_id = cm_id_priv->id.remote_id;
+
+       if (private_data && private_data_len)
+               memcpy(rtu_msg->private_data, private_data, private_data_len);
+}
+
+int ib_send_cm_rtu(struct ib_cm_id *cm_id,
+                  const void *private_data,
+                  u8 private_data_len)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       void *data;
+       int ret;
+
+       if (private_data && private_data_len > IB_CM_RTU_PRIVATE_DATA_SIZE)
+               return -EINVAL;
+
+       data = cm_copy_private_data(private_data, private_data_len);
+       if (IS_ERR(data))
+               return PTR_ERR(data);
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_REP_RCVD &&
+           cm_id->state != IB_CM_MRA_REP_SENT) {
+               ret = -EINVAL;
+               goto error;
+       }
+
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret)
+               goto error;
+
+       cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv,
+                     private_data, private_data_len);
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               kfree(data);
+               return ret;
+       }
+
+       cm_id->state = IB_CM_ESTABLISHED;
+       cm_set_private_data(cm_id_priv, data, private_data_len);
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return 0;
+
+error: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       kfree(data);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_rtu);
+
+static void cm_format_rep_event(struct cm_work *work, enum ib_qp_type qp_type)
+{
+       struct cm_rep_msg *rep_msg;
+       struct ib_cm_rep_event_param *param;
+
+       rep_msg = (struct cm_rep_msg *)work->mad_recv_wc->recv_buf.mad;
+       param = &work->cm_event.param.rep_rcvd;
+       param->remote_ca_guid = rep_msg->local_ca_guid;
+       param->remote_qkey = be32_to_cpu(rep_msg->local_qkey);
+       param->remote_qpn = be32_to_cpu(cm_rep_get_qpn(rep_msg, qp_type));
+       param->starting_psn = be32_to_cpu(cm_rep_get_starting_psn(rep_msg));
+       param->responder_resources = rep_msg->initiator_depth;
+       param->initiator_depth = rep_msg->resp_resources;
+       param->target_ack_delay = cm_rep_get_target_ack_delay(rep_msg);
+       param->failover_accepted = cm_rep_get_failover(rep_msg);
+       param->flow_control = cm_rep_get_flow_ctrl(rep_msg);
+       param->rnr_retry_count = cm_rep_get_rnr_retry_count(rep_msg);
+       param->srq = cm_rep_get_srq(rep_msg);
+       work->cm_event.private_data = &rep_msg->private_data;
+}
+
+static void cm_dup_rep_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_rep_msg *rep_msg;
+       struct ib_mad_send_buf *msg = NULL;
+       int ret;
+
+       rep_msg = (struct cm_rep_msg *) work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(rep_msg->remote_comm_id,
+                                  rep_msg->local_comm_id);
+       if (!cm_id_priv)
+               return;
+
+       atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                       counter[CM_REP_COUNTER]);
+       ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
+       if (ret)
+               goto deref;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state == IB_CM_ESTABLISHED)
+               cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv,
+                             cm_id_priv->private_data,
+                             cm_id_priv->private_data_len);
+       else if (cm_id_priv->id.state == IB_CM_MRA_REP_SENT)
+               cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
+                             CM_MSG_RESPONSE_REP, cm_id_priv->service_timeout,
+                             cm_id_priv->private_data,
+                             cm_id_priv->private_data_len);
+       else
+               goto unlock;
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret)
+               goto free;
+       goto deref;
+
+unlock:        spin_unlock_irq(&cm_id_priv->lock);
+free:  cm_free_msg(msg);
+deref: cm_deref_id(cm_id_priv);
+}
+
+static int cm_rep_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_rep_msg *rep_msg;
+       int ret;
+
+       rep_msg = (struct cm_rep_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(rep_msg->remote_comm_id, 0);
+       if (!cm_id_priv) {
+               cm_dup_rep_handler(work);
+               return -EINVAL;
+       }
+
+       cm_format_rep_event(work, cm_id_priv->qp_type);
+
+       spin_lock_irq(&cm_id_priv->lock);
+       switch (cm_id_priv->id.state) {
+       case IB_CM_REQ_SENT:
+       case IB_CM_MRA_REQ_RCVD:
+               break;
+       default:
+               spin_unlock_irq(&cm_id_priv->lock);
+               ret = -EINVAL;
+               goto error;
+       }
+
+       cm_id_priv->timewait_info->work.remote_id = rep_msg->local_comm_id;
+       cm_id_priv->timewait_info->remote_ca_guid = rep_msg->local_ca_guid;
+       cm_id_priv->timewait_info->remote_qpn = cm_rep_get_qpn(rep_msg, cm_id_priv->qp_type);
+
+       spin_lock(&cm.lock);
+       /* Check for duplicate REP. */
+       if (cm_insert_remote_id(cm_id_priv->timewait_info)) {
+               spin_unlock(&cm.lock);
+               spin_unlock_irq(&cm_id_priv->lock);
+               ret = -EINVAL;
+               goto error;
+       }
+       /* Check for a stale connection. */
+       if (cm_insert_remote_qpn(cm_id_priv->timewait_info)) {
+               rb_erase(&cm_id_priv->timewait_info->remote_id_node,
+                        &cm.remote_id_table);
+               cm_id_priv->timewait_info->inserted_remote_id = 0;
+               spin_unlock(&cm.lock);
+               spin_unlock_irq(&cm_id_priv->lock);
+               cm_issue_rej(work->port, work->mad_recv_wc,
+                            IB_CM_REJ_STALE_CONN, CM_MSG_RESPONSE_REP,
+                            NULL, 0);
+               ret = -EINVAL;
+               goto error;
+       }
+       spin_unlock(&cm.lock);
+
+       cm_id_priv->id.state = IB_CM_REP_RCVD;
+       cm_id_priv->id.remote_id = rep_msg->local_comm_id;
+       cm_id_priv->remote_qpn = cm_rep_get_qpn(rep_msg, cm_id_priv->qp_type);
+       cm_id_priv->initiator_depth = rep_msg->resp_resources;
+       cm_id_priv->responder_resources = rep_msg->initiator_depth;
+       cm_id_priv->sq_psn = cm_rep_get_starting_psn(rep_msg);
+       cm_id_priv->rnr_retry_count = cm_rep_get_rnr_retry_count(rep_msg);
+       cm_id_priv->target_ack_delay = cm_rep_get_target_ack_delay(rep_msg);
+       cm_id_priv->av.timeout =
+                       cm_ack_timeout(cm_id_priv->target_ack_delay,
+                                      cm_id_priv->av.timeout - 1);
+       cm_id_priv->alt_av.timeout =
+                       cm_ack_timeout(cm_id_priv->target_ack_delay,
+                                      cm_id_priv->alt_av.timeout - 1);
+
+       /* todo: handle peer_to_peer */
+
+       ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+
+error:
+       cm_deref_id(cm_id_priv);
+       return ret;
+}
+
+static int cm_establish_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       int ret;
+
+       /* See comment in cm_establish about lookup. */
+       cm_id_priv = cm_acquire_id(work->local_id, work->remote_id);
+       if (!cm_id_priv)
+               return -EINVAL;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state != IB_CM_ESTABLISHED) {
+               spin_unlock_irq(&cm_id_priv->lock);
+               goto out;
+       }
+
+       ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+out:
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static int cm_rtu_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_rtu_msg *rtu_msg;
+       int ret;
+
+       rtu_msg = (struct cm_rtu_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(rtu_msg->remote_comm_id,
+                                  rtu_msg->local_comm_id);
+       if (!cm_id_priv)
+               return -EINVAL;
+
+       work->cm_event.private_data = &rtu_msg->private_data;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state != IB_CM_REP_SENT &&
+           cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
+               spin_unlock_irq(&cm_id_priv->lock);
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_RTU_COUNTER]);
+               goto out;
+       }
+       cm_id_priv->id.state = IB_CM_ESTABLISHED;
+
+       ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+out:
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static void cm_format_dreq(struct cm_dreq_msg *dreq_msg,
+                         struct cm_id_private *cm_id_priv,
+                         const void *private_data,
+                         u8 private_data_len)
+{
+       cm_format_mad_hdr(&dreq_msg->hdr, CM_DREQ_ATTR_ID,
+                         cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_DREQ));
+       dreq_msg->local_comm_id = cm_id_priv->id.local_id;
+       dreq_msg->remote_comm_id = cm_id_priv->id.remote_id;
+       cm_dreq_set_remote_qpn(dreq_msg, cm_id_priv->remote_qpn);
+
+       if (private_data && private_data_len)
+               memcpy(dreq_msg->private_data, private_data, private_data_len);
+}
+
+int ib_send_cm_dreq(struct ib_cm_id *cm_id,
+                   const void *private_data,
+                   u8 private_data_len)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       int ret;
+
+       if (private_data && private_data_len > IB_CM_DREQ_PRIVATE_DATA_SIZE)
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_ESTABLISHED) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (cm_id->lap_state == IB_CM_LAP_SENT ||
+           cm_id->lap_state == IB_CM_MRA_LAP_RCVD)
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret) {
+               cm_enter_timewait(cm_id_priv);
+               goto out;
+       }
+
+       cm_format_dreq((struct cm_dreq_msg *) msg->mad, cm_id_priv,
+                      private_data, private_data_len);
+       msg->timeout_ms = cm_id_priv->timeout_ms;
+       msg->context[1] = (void *) (unsigned long) IB_CM_DREQ_SENT;
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret) {
+               cm_enter_timewait(cm_id_priv);
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               return ret;
+       }
+
+       cm_id->state = IB_CM_DREQ_SENT;
+       cm_id_priv->msg = msg;
+out:   spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_dreq);
+
+static void cm_format_drep(struct cm_drep_msg *drep_msg,
+                         struct cm_id_private *cm_id_priv,
+                         const void *private_data,
+                         u8 private_data_len)
+{
+       cm_format_mad_hdr(&drep_msg->hdr, CM_DREP_ATTR_ID, cm_id_priv->tid);
+       drep_msg->local_comm_id = cm_id_priv->id.local_id;
+       drep_msg->remote_comm_id = cm_id_priv->id.remote_id;
+
+       if (private_data && private_data_len)
+               memcpy(drep_msg->private_data, private_data, private_data_len);
+}
+
+int ib_send_cm_drep(struct ib_cm_id *cm_id,
+                   const void *private_data,
+                   u8 private_data_len)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       void *data;
+       int ret;
+
+       if (private_data && private_data_len > IB_CM_DREP_PRIVATE_DATA_SIZE)
+               return -EINVAL;
+
+       data = cm_copy_private_data(private_data, private_data_len);
+       if (IS_ERR(data))
+               return PTR_ERR(data);
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_DREQ_RCVD) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               kfree(data);
+               return -EINVAL;
+       }
+
+       cm_set_private_data(cm_id_priv, data, private_data_len);
+       cm_enter_timewait(cm_id_priv);
+
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret)
+               goto out;
+
+       cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv,
+                      private_data, private_data_len);
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               return ret;
+       }
+
+out:   spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_drep);
+
+static int cm_issue_drep(struct cm_port *port,
+                        struct ib_mad_recv_wc *mad_recv_wc)
+{
+       struct ib_mad_send_buf *msg = NULL;
+       struct cm_dreq_msg *dreq_msg;
+       struct cm_drep_msg *drep_msg;
+       int ret;
+
+       ret = cm_alloc_response_msg(port, mad_recv_wc, &msg);
+       if (ret)
+               return ret;
+
+       dreq_msg = (struct cm_dreq_msg *) mad_recv_wc->recv_buf.mad;
+       drep_msg = (struct cm_drep_msg *) msg->mad;
+
+       cm_format_mad_hdr(&drep_msg->hdr, CM_DREP_ATTR_ID, dreq_msg->hdr.tid);
+       drep_msg->remote_comm_id = dreq_msg->local_comm_id;
+       drep_msg->local_comm_id = dreq_msg->remote_comm_id;
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret)
+               cm_free_msg(msg);
+
+       return ret;
+}
+
+static int cm_dreq_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_dreq_msg *dreq_msg;
+       struct ib_mad_send_buf *msg = NULL;
+       int ret;
+
+       dreq_msg = (struct cm_dreq_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
+                                  dreq_msg->local_comm_id);
+       if (!cm_id_priv) {
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_DREQ_COUNTER]);
+               cm_issue_drep(work->port, work->mad_recv_wc);
+               return -EINVAL;
+       }
+
+       work->cm_event.private_data = &dreq_msg->private_data;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->local_qpn != cm_dreq_get_remote_qpn(dreq_msg))
+               goto unlock;
+
+       switch (cm_id_priv->id.state) {
+       case IB_CM_REP_SENT:
+       case IB_CM_DREQ_SENT:
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               break;
+       case IB_CM_ESTABLISHED:
+               if (cm_id_priv->id.lap_state == IB_CM_LAP_SENT ||
+                   cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
+                       ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               break;
+       case IB_CM_MRA_REP_RCVD:
+               break;
+       case IB_CM_TIMEWAIT:
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_DREQ_COUNTER]);
+               if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
+                       goto unlock;
+
+               cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv,
+                              cm_id_priv->private_data,
+                              cm_id_priv->private_data_len);
+               spin_unlock_irq(&cm_id_priv->lock);
+
+               if (ib_post_send_mad(msg, NULL))
+                       cm_free_msg(msg);
+               goto deref;
+       case IB_CM_DREQ_RCVD:
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_DREQ_COUNTER]);
+               goto unlock;
+       default:
+               goto unlock;
+       }
+       cm_id_priv->id.state = IB_CM_DREQ_RCVD;
+       cm_id_priv->tid = dreq_msg->hdr.tid;
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+
+unlock:        spin_unlock_irq(&cm_id_priv->lock);
+deref: cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static int cm_drep_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_drep_msg *drep_msg;
+       int ret;
+
+       drep_msg = (struct cm_drep_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(drep_msg->remote_comm_id,
+                                  drep_msg->local_comm_id);
+       if (!cm_id_priv)
+               return -EINVAL;
+
+       work->cm_event.private_data = &drep_msg->private_data;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state != IB_CM_DREQ_SENT &&
+           cm_id_priv->id.state != IB_CM_DREQ_RCVD) {
+               spin_unlock_irq(&cm_id_priv->lock);
+               goto out;
+       }
+       cm_enter_timewait(cm_id_priv);
+
+       ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+out:
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+int ib_send_cm_rej(struct ib_cm_id *cm_id,
+                  enum ib_cm_rej_reason reason,
+                  void *ari,
+                  u8 ari_length,
+                  const void *private_data,
+                  u8 private_data_len)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       int ret;
+
+       if ((private_data && private_data_len > IB_CM_REJ_PRIVATE_DATA_SIZE) ||
+           (ari && ari_length > IB_CM_REJ_ARI_LENGTH))
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       switch (cm_id->state) {
+       case IB_CM_REQ_SENT:
+       case IB_CM_MRA_REQ_RCVD:
+       case IB_CM_REQ_RCVD:
+       case IB_CM_MRA_REQ_SENT:
+       case IB_CM_REP_RCVD:
+       case IB_CM_MRA_REP_SENT:
+               ret = cm_alloc_msg(cm_id_priv, &msg);
+               if (!ret)
+                       cm_format_rej((struct cm_rej_msg *) msg->mad,
+                                     cm_id_priv, reason, ari, ari_length,
+                                     private_data, private_data_len);
+
+               cm_reset_to_idle(cm_id_priv);
+               break;
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+               ret = cm_alloc_msg(cm_id_priv, &msg);
+               if (!ret)
+                       cm_format_rej((struct cm_rej_msg *) msg->mad,
+                                     cm_id_priv, reason, ari, ari_length,
+                                     private_data, private_data_len);
+
+               cm_enter_timewait(cm_id_priv);
+               break;
+       default:
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (ret)
+               goto out;
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret)
+               cm_free_msg(msg);
+
+out:   spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_rej);
+
+static void cm_format_rej_event(struct cm_work *work)
+{
+       struct cm_rej_msg *rej_msg;
+       struct ib_cm_rej_event_param *param;
+
+       rej_msg = (struct cm_rej_msg *)work->mad_recv_wc->recv_buf.mad;
+       param = &work->cm_event.param.rej_rcvd;
+       param->ari = rej_msg->ari;
+       param->ari_length = cm_rej_get_reject_info_len(rej_msg);
+       param->reason = __be16_to_cpu(rej_msg->reason);
+       work->cm_event.private_data = &rej_msg->private_data;
+}
+
+static struct cm_id_private * cm_acquire_rejected_id(struct cm_rej_msg *rej_msg)
+{
+       struct cm_timewait_info *timewait_info;
+       struct cm_id_private *cm_id_priv;
+       __be32 remote_id;
+
+       remote_id = rej_msg->local_comm_id;
+
+       if (__be16_to_cpu(rej_msg->reason) == IB_CM_REJ_TIMEOUT) {
+               spin_lock_irq(&cm.lock);
+               timewait_info = cm_find_remote_id( *((__be64 *) rej_msg->ari),
+                                                 remote_id);
+               if (!timewait_info) {
+                       spin_unlock_irq(&cm.lock);
+                       return NULL;
+               }
+               cm_id_priv = idr_find(&cm.local_id_table, (__force int)
+                                     (timewait_info->work.local_id ^
+                                      cm.random_id_operand));
+               if (cm_id_priv) {
+                       if (cm_id_priv->id.remote_id == remote_id)
+                               atomic_inc(&cm_id_priv->refcount);
+                       else
+                               cm_id_priv = NULL;
+               }
+               spin_unlock_irq(&cm.lock);
+       } else if (cm_rej_get_msg_rejected(rej_msg) == CM_MSG_RESPONSE_REQ)
+               cm_id_priv = cm_acquire_id(rej_msg->remote_comm_id, 0);
+       else
+               cm_id_priv = cm_acquire_id(rej_msg->remote_comm_id, remote_id);
+
+       return cm_id_priv;
+}
+
+static int cm_rej_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_rej_msg *rej_msg;
+       int ret;
+
+       rej_msg = (struct cm_rej_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_rejected_id(rej_msg);
+       if (!cm_id_priv)
+               return -EINVAL;
+
+       cm_format_rej_event(work);
+
+       spin_lock_irq(&cm_id_priv->lock);
+       switch (cm_id_priv->id.state) {
+       case IB_CM_REQ_SENT:
+       case IB_CM_MRA_REQ_RCVD:
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               /* fall through */
+       case IB_CM_REQ_RCVD:
+       case IB_CM_MRA_REQ_SENT:
+               if (__be16_to_cpu(rej_msg->reason) == IB_CM_REJ_STALE_CONN)
+                       cm_enter_timewait(cm_id_priv);
+               else
+                       cm_reset_to_idle(cm_id_priv);
+               break;
+       case IB_CM_DREQ_SENT:
+               ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+               /* fall through */
+       case IB_CM_REP_RCVD:
+       case IB_CM_MRA_REP_SENT:
+               cm_enter_timewait(cm_id_priv);
+               break;
+       case IB_CM_ESTABLISHED:
+               if (cm_id_priv->id.lap_state == IB_CM_LAP_UNINIT ||
+                   cm_id_priv->id.lap_state == IB_CM_LAP_SENT) {
+                       if (cm_id_priv->id.lap_state == IB_CM_LAP_SENT)
+                               ib_cancel_mad(cm_id_priv->av.port->mad_agent,
+                                             cm_id_priv->msg);
+                       cm_enter_timewait(cm_id_priv);
+                       break;
+               }
+               /* fall through */
+       default:
+               spin_unlock_irq(&cm_id_priv->lock);
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+out:
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+int ib_send_cm_mra(struct ib_cm_id *cm_id,
+                  u8 service_timeout,
+                  const void *private_data,
+                  u8 private_data_len)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       enum ib_cm_state cm_state;
+       enum ib_cm_lap_state lap_state;
+       enum cm_msg_response msg_response;
+       void *data;
+       unsigned long flags;
+       int ret;
+
+       if (private_data && private_data_len > IB_CM_MRA_PRIVATE_DATA_SIZE)
+               return -EINVAL;
+
+       data = cm_copy_private_data(private_data, private_data_len);
+       if (IS_ERR(data))
+               return PTR_ERR(data);
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       switch(cm_id_priv->id.state) {
+       case IB_CM_REQ_RCVD:
+               cm_state = IB_CM_MRA_REQ_SENT;
+               lap_state = cm_id->lap_state;
+               msg_response = CM_MSG_RESPONSE_REQ;
+               break;
+       case IB_CM_REP_RCVD:
+               cm_state = IB_CM_MRA_REP_SENT;
+               lap_state = cm_id->lap_state;
+               msg_response = CM_MSG_RESPONSE_REP;
+               break;
+       case IB_CM_ESTABLISHED:
+               if (cm_id->lap_state == IB_CM_LAP_RCVD) {
+                       cm_state = cm_id->state;
+                       lap_state = IB_CM_MRA_LAP_SENT;
+                       msg_response = CM_MSG_RESPONSE_OTHER;
+                       break;
+               }
+       default:
+               ret = -EINVAL;
+               goto error1;
+       }
+
+       if (!(service_timeout & IB_CM_MRA_FLAG_DELAY)) {
+               ret = cm_alloc_msg(cm_id_priv, &msg);
+               if (ret)
+                       goto error1;
+
+               cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
+                             msg_response, service_timeout,
+                             private_data, private_data_len);
+               ret = ib_post_send_mad(msg, NULL);
+               if (ret)
+                       goto error2;
+       }
+
+       cm_id->state = cm_state;
+       cm_id->lap_state = lap_state;
+       cm_id_priv->service_timeout = service_timeout;
+       cm_set_private_data(cm_id_priv, data, private_data_len);
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return 0;
+
+error1:        spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       kfree(data);
+       return ret;
+
+error2:        spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       kfree(data);
+       cm_free_msg(msg);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_mra);
+
+static struct cm_id_private * cm_acquire_mraed_id(struct cm_mra_msg *mra_msg)
+{
+       switch (cm_mra_get_msg_mraed(mra_msg)) {
+       case CM_MSG_RESPONSE_REQ:
+               return cm_acquire_id(mra_msg->remote_comm_id, 0);
+       case CM_MSG_RESPONSE_REP:
+       case CM_MSG_RESPONSE_OTHER:
+               return cm_acquire_id(mra_msg->remote_comm_id,
+                                    mra_msg->local_comm_id);
+       default:
+               return NULL;
+       }
+}
+
+static int cm_mra_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_mra_msg *mra_msg;
+       int timeout, ret;
+
+       mra_msg = (struct cm_mra_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_mraed_id(mra_msg);
+       if (!cm_id_priv)
+               return -EINVAL;
+
+       work->cm_event.private_data = &mra_msg->private_data;
+       work->cm_event.param.mra_rcvd.service_timeout =
+                                       cm_mra_get_service_timeout(mra_msg);
+       timeout = cm_convert_to_ms(cm_mra_get_service_timeout(mra_msg)) +
+                 cm_convert_to_ms(cm_id_priv->av.timeout);
+
+       spin_lock_irq(&cm_id_priv->lock);
+       switch (cm_id_priv->id.state) {
+       case IB_CM_REQ_SENT:
+               if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REQ ||
+                   ib_modify_mad(cm_id_priv->av.port->mad_agent,
+                                 cm_id_priv->msg, timeout))
+                       goto out;
+               cm_id_priv->id.state = IB_CM_MRA_REQ_RCVD;
+               break;
+       case IB_CM_REP_SENT:
+               if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REP ||
+                   ib_modify_mad(cm_id_priv->av.port->mad_agent,
+                                 cm_id_priv->msg, timeout))
+                       goto out;
+               cm_id_priv->id.state = IB_CM_MRA_REP_RCVD;
+               break;
+       case IB_CM_ESTABLISHED:
+               if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_OTHER ||
+                   cm_id_priv->id.lap_state != IB_CM_LAP_SENT ||
+                   ib_modify_mad(cm_id_priv->av.port->mad_agent,
+                                 cm_id_priv->msg, timeout)) {
+                       if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
+                               atomic_long_inc(&work->port->
+                                               counter_group[CM_RECV_DUPLICATES].
+                                               counter[CM_MRA_COUNTER]);
+                       goto out;
+               }
+               cm_id_priv->id.lap_state = IB_CM_MRA_LAP_RCVD;
+               break;
+       case IB_CM_MRA_REQ_RCVD:
+       case IB_CM_MRA_REP_RCVD:
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_MRA_COUNTER]);
+               /* fall through */
+       default:
+               goto out;
+       }
+
+       cm_id_priv->msg->context[1] = (void *) (unsigned long)
+                                     cm_id_priv->id.state;
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+out:
+       spin_unlock_irq(&cm_id_priv->lock);
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static void cm_format_lap(struct cm_lap_msg *lap_msg,
+                         struct cm_id_private *cm_id_priv,
+                         struct ib_sa_path_rec *alternate_path,
+                         const void *private_data,
+                         u8 private_data_len)
+{
+       cm_format_mad_hdr(&lap_msg->hdr, CM_LAP_ATTR_ID,
+                         cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_LAP));
+       lap_msg->local_comm_id = cm_id_priv->id.local_id;
+       lap_msg->remote_comm_id = cm_id_priv->id.remote_id;
+       cm_lap_set_remote_qpn(lap_msg, cm_id_priv->remote_qpn);
+       /* todo: need remote CM response timeout */
+       cm_lap_set_remote_resp_timeout(lap_msg, 0x1F);
+       lap_msg->alt_local_lid = alternate_path->slid;
+       lap_msg->alt_remote_lid = alternate_path->dlid;
+       lap_msg->alt_local_gid = alternate_path->sgid;
+       lap_msg->alt_remote_gid = alternate_path->dgid;
+       cm_lap_set_flow_label(lap_msg, alternate_path->flow_label);
+       cm_lap_set_traffic_class(lap_msg, alternate_path->traffic_class);
+       lap_msg->alt_hop_limit = alternate_path->hop_limit;
+       cm_lap_set_packet_rate(lap_msg, alternate_path->rate);
+       cm_lap_set_sl(lap_msg, alternate_path->sl);
+       cm_lap_set_subnet_local(lap_msg, 1); /* local only... */
+       cm_lap_set_local_ack_timeout(lap_msg,
+               cm_ack_timeout(cm_id_priv->av.port->cm_dev->ack_delay,
+                              alternate_path->packet_life_time));
+
+       if (private_data && private_data_len)
+               memcpy(lap_msg->private_data, private_data, private_data_len);
+}
+
+int ib_send_cm_lap(struct ib_cm_id *cm_id,
+                  struct ib_sa_path_rec *alternate_path,
+                  const void *private_data,
+                  u8 private_data_len)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       int ret;
+
+       if (private_data && private_data_len > IB_CM_LAP_PRIVATE_DATA_SIZE)
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_ESTABLISHED ||
+           (cm_id->lap_state != IB_CM_LAP_UNINIT &&
+            cm_id->lap_state != IB_CM_LAP_IDLE)) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = cm_init_av_by_path(alternate_path, &cm_id_priv->alt_av);
+       if (ret)
+               goto out;
+       cm_id_priv->alt_av.timeout =
+                       cm_ack_timeout(cm_id_priv->target_ack_delay,
+                                      cm_id_priv->alt_av.timeout - 1);
+
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret)
+               goto out;
+
+       cm_format_lap((struct cm_lap_msg *) msg->mad, cm_id_priv,
+                     alternate_path, private_data, private_data_len);
+       msg->timeout_ms = cm_id_priv->timeout_ms;
+       msg->context[1] = (void *) (unsigned long) IB_CM_ESTABLISHED;
+
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               return ret;
+       }
+
+       cm_id->lap_state = IB_CM_LAP_SENT;
+       cm_id_priv->msg = msg;
+
+out:   spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_lap);
+
+static void cm_format_path_from_lap(struct cm_id_private *cm_id_priv,
+                                   struct ib_sa_path_rec *path,
+                                   struct cm_lap_msg *lap_msg)
+{
+       memset(path, 0, sizeof *path);
+       path->dgid = lap_msg->alt_local_gid;
+       path->sgid = lap_msg->alt_remote_gid;
+       path->dlid = lap_msg->alt_local_lid;
+       path->slid = lap_msg->alt_remote_lid;
+       path->flow_label = cm_lap_get_flow_label(lap_msg);
+       path->hop_limit = lap_msg->alt_hop_limit;
+       path->traffic_class = cm_lap_get_traffic_class(lap_msg);
+       path->reversible = 1;
+       path->pkey = cm_id_priv->pkey;
+       path->sl = cm_lap_get_sl(lap_msg);
+       path->mtu_selector = IB_SA_EQ;
+       path->mtu = cm_id_priv->path_mtu;
+       path->rate_selector = IB_SA_EQ;
+       path->rate = cm_lap_get_packet_rate(lap_msg);
+       path->packet_life_time_selector = IB_SA_EQ;
+       path->packet_life_time = cm_lap_get_local_ack_timeout(lap_msg);
+       path->packet_life_time -= (path->packet_life_time > 0);
+}
+
+static int cm_lap_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_lap_msg *lap_msg;
+       struct ib_cm_lap_event_param *param;
+       struct ib_mad_send_buf *msg = NULL;
+       int ret;
+
+       /* todo: verify LAP request and send reject APR if invalid. */
+       lap_msg = (struct cm_lap_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(lap_msg->remote_comm_id,
+                                  lap_msg->local_comm_id);
+       if (!cm_id_priv)
+               return -EINVAL;
+
+       param = &work->cm_event.param.lap_rcvd;
+       param->alternate_path = &work->path[0];
+       cm_format_path_from_lap(cm_id_priv, param->alternate_path, lap_msg);
+       work->cm_event.private_data = &lap_msg->private_data;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state != IB_CM_ESTABLISHED)
+               goto unlock;
+
+       switch (cm_id_priv->id.lap_state) {
+       case IB_CM_LAP_UNINIT:
+       case IB_CM_LAP_IDLE:
+               break;
+       case IB_CM_MRA_LAP_SENT:
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_LAP_COUNTER]);
+               if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
+                       goto unlock;
+
+               cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
+                             CM_MSG_RESPONSE_OTHER,
+                             cm_id_priv->service_timeout,
+                             cm_id_priv->private_data,
+                             cm_id_priv->private_data_len);
+               spin_unlock_irq(&cm_id_priv->lock);
+
+               if (ib_post_send_mad(msg, NULL))
+                       cm_free_msg(msg);
+               goto deref;
+       case IB_CM_LAP_RCVD:
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_LAP_COUNTER]);
+               goto unlock;
+       default:
+               goto unlock;
+       }
+
+       cm_id_priv->id.lap_state = IB_CM_LAP_RCVD;
+       cm_id_priv->tid = lap_msg->hdr.tid;
+       cm_init_av_for_response(work->port, work->mad_recv_wc->wc,
+                               work->mad_recv_wc->recv_buf.grh,
+                               &cm_id_priv->av);
+       cm_init_av_by_path(param->alternate_path, &cm_id_priv->alt_av);
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+
+unlock:        spin_unlock_irq(&cm_id_priv->lock);
+deref: cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static void cm_format_apr(struct cm_apr_msg *apr_msg,
+                         struct cm_id_private *cm_id_priv,
+                         enum ib_cm_apr_status status,
+                         void *info,
+                         u8 info_length,
+                         const void *private_data,
+                         u8 private_data_len)
+{
+       cm_format_mad_hdr(&apr_msg->hdr, CM_APR_ATTR_ID, cm_id_priv->tid);
+       apr_msg->local_comm_id = cm_id_priv->id.local_id;
+       apr_msg->remote_comm_id = cm_id_priv->id.remote_id;
+       apr_msg->ap_status = (u8) status;
+
+       if (info && info_length) {
+               apr_msg->info_length = info_length;
+               memcpy(apr_msg->info, info, info_length);
+       }
+
+       if (private_data && private_data_len)
+               memcpy(apr_msg->private_data, private_data, private_data_len);
+}
+
+int ib_send_cm_apr(struct ib_cm_id *cm_id,
+                  enum ib_cm_apr_status status,
+                  void *info,
+                  u8 info_length,
+                  const void *private_data,
+                  u8 private_data_len)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       int ret;
+
+       if ((private_data && private_data_len > IB_CM_APR_PRIVATE_DATA_SIZE) ||
+           (info && info_length > IB_CM_APR_INFO_LENGTH))
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_ESTABLISHED ||
+           (cm_id->lap_state != IB_CM_LAP_RCVD &&
+            cm_id->lap_state != IB_CM_MRA_LAP_SENT)) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret)
+               goto out;
+
+       cm_format_apr((struct cm_apr_msg *) msg->mad, cm_id_priv, status,
+                     info, info_length, private_data, private_data_len);
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               return ret;
+       }
+
+       cm_id->lap_state = IB_CM_LAP_IDLE;
+out:   spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_apr);
+
+static int cm_apr_handler(struct cm_work *work)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_apr_msg *apr_msg;
+       int ret;
+
+       apr_msg = (struct cm_apr_msg *)work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(apr_msg->remote_comm_id,
+                                  apr_msg->local_comm_id);
+       if (!cm_id_priv)
+               return -EINVAL; /* Unmatched reply. */
+
+       work->cm_event.param.apr_rcvd.ap_status = apr_msg->ap_status;
+       work->cm_event.param.apr_rcvd.apr_info = &apr_msg->info;
+       work->cm_event.param.apr_rcvd.info_len = apr_msg->info_length;
+       work->cm_event.private_data = &apr_msg->private_data;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state != IB_CM_ESTABLISHED ||
+           (cm_id_priv->id.lap_state != IB_CM_LAP_SENT &&
+            cm_id_priv->id.lap_state != IB_CM_MRA_LAP_RCVD)) {
+               spin_unlock_irq(&cm_id_priv->lock);
+               goto out;
+       }
+       cm_id_priv->id.lap_state = IB_CM_LAP_IDLE;
+       ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+       cm_id_priv->msg = NULL;
+
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+out:
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static int cm_timewait_handler(struct cm_work *work)
+{
+       struct cm_timewait_info *timewait_info;
+       struct cm_id_private *cm_id_priv;
+       int ret;
+
+       timewait_info = (struct cm_timewait_info *)work;
+       spin_lock_irq(&cm.lock);
+       list_del(&timewait_info->list);
+       spin_unlock_irq(&cm.lock);
+
+       cm_id_priv = cm_acquire_id(timewait_info->work.local_id,
+                                  timewait_info->work.remote_id);
+       if (!cm_id_priv)
+               return -EINVAL;
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state != IB_CM_TIMEWAIT ||
+           cm_id_priv->remote_qpn != timewait_info->remote_qpn) {
+               spin_unlock_irq(&cm_id_priv->lock);
+               goto out;
+       }
+       cm_id_priv->id.state = IB_CM_IDLE;
+       ret = atomic_inc_and_test(&cm_id_priv->work_count);
+       if (!ret)
+               list_add_tail(&work->list, &cm_id_priv->work_list);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       if (ret)
+               cm_process_work(cm_id_priv, work);
+       else
+               cm_deref_id(cm_id_priv);
+       return 0;
+out:
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static void cm_format_sidr_req(struct cm_sidr_req_msg *sidr_req_msg,
+                              struct cm_id_private *cm_id_priv,
+                              struct ib_cm_sidr_req_param *param)
+{
+       cm_format_mad_hdr(&sidr_req_msg->hdr, CM_SIDR_REQ_ATTR_ID,
+                         cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_SIDR));
+       sidr_req_msg->request_id = cm_id_priv->id.local_id;
+       sidr_req_msg->pkey = param->path->pkey;
+       sidr_req_msg->service_id = param->service_id;
+
+       if (param->private_data && param->private_data_len)
+               memcpy(sidr_req_msg->private_data, param->private_data,
+                      param->private_data_len);
+}
+
+int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
+                       struct ib_cm_sidr_req_param *param)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       int ret;
+
+       if (!param->path || (param->private_data &&
+            param->private_data_len > IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE))
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       ret = cm_init_av_by_path(param->path, &cm_id_priv->av);
+       if (ret)
+               goto out;
+
+       cm_id->service_id = param->service_id;
+       cm_id->service_mask = ~cpu_to_be64(0);
+       cm_id_priv->timeout_ms = param->timeout_ms;
+       cm_id_priv->max_cm_retries = param->max_cm_retries;
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret)
+               goto out;
+
+       cm_format_sidr_req((struct cm_sidr_req_msg *) msg->mad, cm_id_priv,
+                          param);
+       msg->timeout_ms = cm_id_priv->timeout_ms;
+       msg->context[1] = (void *) (unsigned long) IB_CM_SIDR_REQ_SENT;
+
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state == IB_CM_IDLE)
+               ret = ib_post_send_mad(msg, NULL);
+       else
+               ret = -EINVAL;
+
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               goto out;
+       }
+       cm_id->state = IB_CM_SIDR_REQ_SENT;
+       cm_id_priv->msg = msg;
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+out:
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_sidr_req);
+
+static void cm_format_sidr_req_event(struct cm_work *work,
+                                    struct ib_cm_id *listen_id)
+{
+       struct cm_sidr_req_msg *sidr_req_msg;
+       struct ib_cm_sidr_req_event_param *param;
+
+       sidr_req_msg = (struct cm_sidr_req_msg *)
+                               work->mad_recv_wc->recv_buf.mad;
+       param = &work->cm_event.param.sidr_req_rcvd;
+       param->pkey = __be16_to_cpu(sidr_req_msg->pkey);
+       param->listen_id = listen_id;
+       param->port = work->port->port_num;
+       work->cm_event.private_data = &sidr_req_msg->private_data;
+}
+
+static int cm_sidr_req_handler(struct cm_work *work)
+{
+       struct ib_cm_id *cm_id;
+       struct cm_id_private *cm_id_priv, *cur_cm_id_priv;
+       struct cm_sidr_req_msg *sidr_req_msg;
+       struct ib_wc *wc;
+
+       cm_id = ib_create_cm_id(work->port->cm_dev->ib_device, NULL, NULL);
+       if (IS_ERR(cm_id))
+               return PTR_ERR(cm_id);
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+
+       /* Record SGID/SLID and request ID for lookup. */
+       sidr_req_msg = (struct cm_sidr_req_msg *)
+                               work->mad_recv_wc->recv_buf.mad;
+       wc = work->mad_recv_wc->wc;
+       cm_id_priv->av.dgid.global.subnet_prefix = cpu_to_be64(wc->slid);
+       cm_id_priv->av.dgid.global.interface_id = 0;
+       cm_init_av_for_response(work->port, work->mad_recv_wc->wc,
+                               work->mad_recv_wc->recv_buf.grh,
+                               &cm_id_priv->av);
+       cm_id_priv->id.remote_id = sidr_req_msg->request_id;
+       cm_id_priv->tid = sidr_req_msg->hdr.tid;
+       atomic_inc(&cm_id_priv->work_count);
+
+       spin_lock_irq(&cm.lock);
+       cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
+       if (cur_cm_id_priv) {
+               spin_unlock_irq(&cm.lock);
+               atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+                               counter[CM_SIDR_REQ_COUNTER]);
+               goto out; /* Duplicate message. */
+       }
+       cm_id_priv->id.state = IB_CM_SIDR_REQ_RCVD;
+       cur_cm_id_priv = cm_find_listen(cm_id->device,
+                                       sidr_req_msg->service_id,
+                                       sidr_req_msg->private_data);
+       if (!cur_cm_id_priv) {
+               spin_unlock_irq(&cm.lock);
+               cm_reject_sidr_req(cm_id_priv, IB_SIDR_UNSUPPORTED);
+               goto out; /* No match. */
+       }
+       atomic_inc(&cur_cm_id_priv->refcount);
+       atomic_inc(&cm_id_priv->refcount);
+       spin_unlock_irq(&cm.lock);
+
+       cm_id_priv->id.cm_handler = cur_cm_id_priv->id.cm_handler;
+       cm_id_priv->id.context = cur_cm_id_priv->id.context;
+       cm_id_priv->id.service_id = sidr_req_msg->service_id;
+       cm_id_priv->id.service_mask = ~cpu_to_be64(0);
+
+       cm_format_sidr_req_event(work, &cur_cm_id_priv->id);
+       cm_process_work(cm_id_priv, work);
+       cm_deref_id(cur_cm_id_priv);
+       return 0;
+out:
+       ib_destroy_cm_id(&cm_id_priv->id);
+       return -EINVAL;
+}
+
+static void cm_format_sidr_rep(struct cm_sidr_rep_msg *sidr_rep_msg,
+                              struct cm_id_private *cm_id_priv,
+                              struct ib_cm_sidr_rep_param *param)
+{
+       cm_format_mad_hdr(&sidr_rep_msg->hdr, CM_SIDR_REP_ATTR_ID,
+                         cm_id_priv->tid);
+       sidr_rep_msg->request_id = cm_id_priv->id.remote_id;
+       sidr_rep_msg->status = param->status;
+       cm_sidr_rep_set_qpn(sidr_rep_msg, cpu_to_be32(param->qp_num));
+       sidr_rep_msg->service_id = cm_id_priv->id.service_id;
+       sidr_rep_msg->qkey = cpu_to_be32(param->qkey);
+
+       if (param->info && param->info_length)
+               memcpy(sidr_rep_msg->info, param->info, param->info_length);
+
+       if (param->private_data && param->private_data_len)
+               memcpy(sidr_rep_msg->private_data, param->private_data,
+                      param->private_data_len);
+}
+
+int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
+                       struct ib_cm_sidr_rep_param *param)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_mad_send_buf *msg;
+       unsigned long flags;
+       int ret;
+
+       if ((param->info && param->info_length > IB_CM_SIDR_REP_INFO_LENGTH) ||
+           (param->private_data &&
+            param->private_data_len > IB_CM_SIDR_REP_PRIVATE_DATA_SIZE))
+               return -EINVAL;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state != IB_CM_SIDR_REQ_RCVD) {
+               ret = -EINVAL;
+               goto error;
+       }
+
+       ret = cm_alloc_msg(cm_id_priv, &msg);
+       if (ret)
+               goto error;
+
+       cm_format_sidr_rep((struct cm_sidr_rep_msg *) msg->mad, cm_id_priv,
+                          param);
+       ret = ib_post_send_mad(msg, NULL);
+       if (ret) {
+               spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+               cm_free_msg(msg);
+               return ret;
+       }
+       cm_id->state = IB_CM_IDLE;
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+       spin_lock_irqsave(&cm.lock, flags);
+       rb_erase(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table);
+       spin_unlock_irqrestore(&cm.lock, flags);
+       return 0;
+
+error: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(ib_send_cm_sidr_rep);
+
+static void cm_format_sidr_rep_event(struct cm_work *work)
+{
+       struct cm_sidr_rep_msg *sidr_rep_msg;
+       struct ib_cm_sidr_rep_event_param *param;
+
+       sidr_rep_msg = (struct cm_sidr_rep_msg *)
+                               work->mad_recv_wc->recv_buf.mad;
+       param = &work->cm_event.param.sidr_rep_rcvd;
+       param->status = sidr_rep_msg->status;
+       param->qkey = be32_to_cpu(sidr_rep_msg->qkey);
+       param->qpn = be32_to_cpu(cm_sidr_rep_get_qpn(sidr_rep_msg));
+       param->info = &sidr_rep_msg->info;
+       param->info_len = sidr_rep_msg->info_length;
+       work->cm_event.private_data = &sidr_rep_msg->private_data;
+}
+
+static int cm_sidr_rep_handler(struct cm_work *work)
+{
+       struct cm_sidr_rep_msg *sidr_rep_msg;
+       struct cm_id_private *cm_id_priv;
+
+       sidr_rep_msg = (struct cm_sidr_rep_msg *)
+                               work->mad_recv_wc->recv_buf.mad;
+       cm_id_priv = cm_acquire_id(sidr_rep_msg->request_id, 0);
+       if (!cm_id_priv)
+               return -EINVAL; /* Unmatched reply. */
+
+       spin_lock_irq(&cm_id_priv->lock);
+       if (cm_id_priv->id.state != IB_CM_SIDR_REQ_SENT) {
+               spin_unlock_irq(&cm_id_priv->lock);
+               goto out;
+       }
+       cm_id_priv->id.state = IB_CM_IDLE;
+       ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
+       spin_unlock_irq(&cm_id_priv->lock);
+
+       cm_format_sidr_rep_event(work);
+       cm_process_work(cm_id_priv, work);
+       return 0;
+out:
+       cm_deref_id(cm_id_priv);
+       return -EINVAL;
+}
+
+static void cm_process_send_error(struct ib_mad_send_buf *msg,
+                                 enum ib_wc_status wc_status)
+{
+       struct cm_id_private *cm_id_priv;
+       struct ib_cm_event cm_event;
+       enum ib_cm_state state;
+       int ret;
+
+       memset(&cm_event, 0, sizeof cm_event);
+       cm_id_priv = msg->context[0];
+
+       /* Discard old sends or ones without a response. */
+       spin_lock_irq(&cm_id_priv->lock);
+       state = (enum ib_cm_state) (unsigned long) msg->context[1];
+       if (msg != cm_id_priv->msg || state != cm_id_priv->id.state)
+               goto discard;
+
+       switch (state) {
+       case IB_CM_REQ_SENT:
+       case IB_CM_MRA_REQ_RCVD:
+               cm_reset_to_idle(cm_id_priv);
+               cm_event.event = IB_CM_REQ_ERROR;
+               break;
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+               cm_reset_to_idle(cm_id_priv);
+               cm_event.event = IB_CM_REP_ERROR;
+               break;
+       case IB_CM_DREQ_SENT:
+               cm_enter_timewait(cm_id_priv);
+               cm_event.event = IB_CM_DREQ_ERROR;
+               break;
+       case IB_CM_SIDR_REQ_SENT:
+               cm_id_priv->id.state = IB_CM_IDLE;
+               cm_event.event = IB_CM_SIDR_REQ_ERROR;
+               break;
+       default:
+               goto discard;
+       }
+       spin_unlock_irq(&cm_id_priv->lock);
+       cm_event.param.send_status = wc_status;
+
+       /* No other events can occur on the cm_id at this point. */
+       ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &cm_event);
+       cm_free_msg(msg);
+       if (ret)
+               ib_destroy_cm_id(&cm_id_priv->id);
+       return;
+discard:
+       spin_unlock_irq(&cm_id_priv->lock);
+       cm_free_msg(msg);
+}
+
+static void cm_send_handler(struct ib_mad_agent *mad_agent,
+                           struct ib_mad_send_wc *mad_send_wc)
+{
+       struct ib_mad_send_buf *msg = mad_send_wc->send_buf;
+       struct cm_port *port;
+       u16 attr_index;
+
+       port = mad_agent->context;
+       attr_index = be16_to_cpu(((struct ib_mad_hdr *)
+                                 msg->mad)->attr_id) - CM_ATTR_ID_OFFSET;
+
+       /*
+        * If the send was in response to a received message (context[0] is not
+        * set to a cm_id), and is not a REJ, then it is a send that was
+        * manually retried.
+        */
+       if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
+               msg->retries = 1;
+
+       atomic_long_add(1 + msg->retries,
+                       &port->counter_group[CM_XMIT].counter[attr_index]);
+       if (msg->retries)
+               atomic_long_add(msg->retries,
+                               &port->counter_group[CM_XMIT_RETRIES].
+                               counter[attr_index]);
+
+       switch (mad_send_wc->status) {
+       case IB_WC_SUCCESS:
+       case IB_WC_WR_FLUSH_ERR:
+               cm_free_msg(msg);
+               break;
+       default:
+               if (msg->context[0] && msg->context[1])
+                       cm_process_send_error(msg, mad_send_wc->status);
+               else
+                       cm_free_msg(msg);
+               break;
+       }
+}
+
+static void cm_work_handler(struct work_struct *_work)
+{
+       struct cm_work *work = container_of(_work, struct cm_work, work.work);
+       int ret;
+
+       switch (work->cm_event.event) {
+       case IB_CM_REQ_RECEIVED:
+               ret = cm_req_handler(work);
+               break;
+       case IB_CM_MRA_RECEIVED:
+               ret = cm_mra_handler(work);
+               break;
+       case IB_CM_REJ_RECEIVED:
+               ret = cm_rej_handler(work);
+               break;
+       case IB_CM_REP_RECEIVED:
+               ret = cm_rep_handler(work);
+               break;
+       case IB_CM_RTU_RECEIVED:
+               ret = cm_rtu_handler(work);
+               break;
+       case IB_CM_USER_ESTABLISHED:
+               ret = cm_establish_handler(work);
+               break;
+       case IB_CM_DREQ_RECEIVED:
+               ret = cm_dreq_handler(work);
+               break;
+       case IB_CM_DREP_RECEIVED:
+               ret = cm_drep_handler(work);
+               break;
+       case IB_CM_SIDR_REQ_RECEIVED:
+               ret = cm_sidr_req_handler(work);
+               break;
+       case IB_CM_SIDR_REP_RECEIVED:
+               ret = cm_sidr_rep_handler(work);
+               break;
+       case IB_CM_LAP_RECEIVED:
+               ret = cm_lap_handler(work);
+               break;
+       case IB_CM_APR_RECEIVED:
+               ret = cm_apr_handler(work);
+               break;
+       case IB_CM_TIMEWAIT_EXIT:
+               ret = cm_timewait_handler(work);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       if (ret)
+               cm_free_work(work);
+}
+
+static int cm_establish(struct ib_cm_id *cm_id)
+{
+       struct cm_id_private *cm_id_priv;
+       struct cm_work *work;
+       unsigned long flags;
+       int ret = 0;
+
+       work = kmalloc(sizeof *work, GFP_ATOMIC);
+       if (!work)
+               return -ENOMEM;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       switch (cm_id->state)
+       {
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+               cm_id->state = IB_CM_ESTABLISHED;
+               break;
+       case IB_CM_ESTABLISHED:
+               ret = -EISCONN;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+       if (ret) {
+               kfree(work);
+               goto out;
+       }
+
+       /*
+        * The CM worker thread may try to destroy the cm_id before it
+        * can execute this work item.  To prevent potential deadlock,
+        * we need to find the cm_id once we're in the context of the
+        * worker thread, rather than holding a reference on it.
+        */
+       INIT_DELAYED_WORK(&work->work, cm_work_handler);
+       work->local_id = cm_id->local_id;
+       work->remote_id = cm_id->remote_id;
+       work->mad_recv_wc = NULL;
+       work->cm_event.event = IB_CM_USER_ESTABLISHED;
+       queue_delayed_work(cm.wq, &work->work, 0);
+out:
+       return ret;
+}
+
+static int cm_migrate(struct ib_cm_id *cm_id)
+{
+       struct cm_id_private *cm_id_priv;
+       unsigned long flags;
+       int ret = 0;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       if (cm_id->state == IB_CM_ESTABLISHED &&
+           (cm_id->lap_state == IB_CM_LAP_UNINIT ||
+            cm_id->lap_state == IB_CM_LAP_IDLE)) {
+               cm_id->lap_state = IB_CM_LAP_IDLE;
+               cm_id_priv->av = cm_id_priv->alt_av;
+       } else
+               ret = -EINVAL;
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+       return ret;
+}
+
+int ib_cm_notify(struct ib_cm_id *cm_id, enum ib_event_type event)
+{
+       int ret;
+
+       switch (event) {
+       case IB_EVENT_COMM_EST:
+               ret = cm_establish(cm_id);
+               break;
+       case IB_EVENT_PATH_MIG:
+               ret = cm_migrate(cm_id);
+               break;
+       default:
+               ret = -EINVAL;
+       }
+       return ret;
+}
+EXPORT_SYMBOL(ib_cm_notify);
+
+static void cm_recv_handler(struct ib_mad_agent *mad_agent,
+                           struct ib_mad_recv_wc *mad_recv_wc)
+{
+       struct cm_port *port = mad_agent->context;
+       struct cm_work *work;
+       enum ib_cm_event_type event;
+       u16 attr_id;
+       int paths = 0;
+
+       switch (mad_recv_wc->recv_buf.mad->mad_hdr.attr_id) {
+       case CM_REQ_ATTR_ID:
+               paths = 1 + (((struct cm_req_msg *) mad_recv_wc->recv_buf.mad)->
+                                                   alt_local_lid != 0);
+               event = IB_CM_REQ_RECEIVED;
+               break;
+       case CM_MRA_ATTR_ID:
+               event = IB_CM_MRA_RECEIVED;
+               break;
+       case CM_REJ_ATTR_ID:
+               event = IB_CM_REJ_RECEIVED;
+               break;
+       case CM_REP_ATTR_ID:
+               event = IB_CM_REP_RECEIVED;
+               break;
+       case CM_RTU_ATTR_ID:
+               event = IB_CM_RTU_RECEIVED;
+               break;
+       case CM_DREQ_ATTR_ID:
+               event = IB_CM_DREQ_RECEIVED;
+               break;
+       case CM_DREP_ATTR_ID:
+               event = IB_CM_DREP_RECEIVED;
+               break;
+       case CM_SIDR_REQ_ATTR_ID:
+               event = IB_CM_SIDR_REQ_RECEIVED;
+               break;
+       case CM_SIDR_REP_ATTR_ID:
+               event = IB_CM_SIDR_REP_RECEIVED;
+               break;
+       case CM_LAP_ATTR_ID:
+               paths = 1;
+               event = IB_CM_LAP_RECEIVED;
+               break;
+       case CM_APR_ATTR_ID:
+               event = IB_CM_APR_RECEIVED;
+               break;
+       default:
+               ib_free_recv_mad(mad_recv_wc);
+               return;
+       }
+
+       attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
+       atomic_long_inc(&port->counter_group[CM_RECV].
+                       counter[attr_id - CM_ATTR_ID_OFFSET]);
+
+       work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
+                      GFP_KERNEL);
+       if (!work) {
+               ib_free_recv_mad(mad_recv_wc);
+               return;
+       }
+
+       INIT_DELAYED_WORK(&work->work, cm_work_handler);
+       work->cm_event.event = event;
+       work->mad_recv_wc = mad_recv_wc;
+       work->port = port;
+       queue_delayed_work(cm.wq, &work->work, 0);
+}
+
+static int cm_init_qp_init_attr(struct cm_id_private *cm_id_priv,
+                               struct ib_qp_attr *qp_attr,
+                               int *qp_attr_mask)
+{
+       unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       switch (cm_id_priv->id.state) {
+       case IB_CM_REQ_SENT:
+       case IB_CM_MRA_REQ_RCVD:
+       case IB_CM_REQ_RCVD:
+       case IB_CM_MRA_REQ_SENT:
+       case IB_CM_REP_RCVD:
+       case IB_CM_MRA_REP_SENT:
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+       case IB_CM_ESTABLISHED:
+               *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS |
+                               IB_QP_PKEY_INDEX | IB_QP_PORT;
+               qp_attr->qp_access_flags = IB_ACCESS_REMOTE_WRITE;
+               if (cm_id_priv->responder_resources)
+                       qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_READ |
+                                                   IB_ACCESS_REMOTE_ATOMIC;
+               qp_attr->pkey_index = cm_id_priv->av.pkey_index;
+               qp_attr->port_num = cm_id_priv->av.port->port_num;
+               ret = 0;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+
+static int cm_init_qp_rtr_attr(struct cm_id_private *cm_id_priv,
+                              struct ib_qp_attr *qp_attr,
+                              int *qp_attr_mask)
+{
+       unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       switch (cm_id_priv->id.state) {
+       case IB_CM_REQ_RCVD:
+       case IB_CM_MRA_REQ_SENT:
+       case IB_CM_REP_RCVD:
+       case IB_CM_MRA_REP_SENT:
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+       case IB_CM_ESTABLISHED:
+               *qp_attr_mask = IB_QP_STATE | IB_QP_AV | IB_QP_PATH_MTU |
+                               IB_QP_DEST_QPN | IB_QP_RQ_PSN;
+               qp_attr->ah_attr = cm_id_priv->av.ah_attr;
+               if (!cm_id_priv->av.valid) {
+                       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+                       return -EINVAL;
+               }
+               if (cm_id_priv->av.ah_attr.vlan_id != 0xffff) {
+                       qp_attr->vlan_id = cm_id_priv->av.ah_attr.vlan_id;
+                       *qp_attr_mask |= IB_QP_VID;
+               }
+               if (!is_zero_ether_addr(cm_id_priv->av.smac)) {
+                       memcpy(qp_attr->smac, cm_id_priv->av.smac,
+                              sizeof(qp_attr->smac));
+                       *qp_attr_mask |= IB_QP_SMAC;
+               }
+               if (cm_id_priv->alt_av.valid) {
+                       if (cm_id_priv->alt_av.ah_attr.vlan_id != 0xffff) {
+                               qp_attr->alt_vlan_id =
+                                       cm_id_priv->alt_av.ah_attr.vlan_id;
+                               *qp_attr_mask |= IB_QP_ALT_VID;
+                       }
+                       if (!is_zero_ether_addr(cm_id_priv->alt_av.smac)) {
+                               memcpy(qp_attr->alt_smac,
+                                      cm_id_priv->alt_av.smac,
+                                      sizeof(qp_attr->alt_smac));
+                               *qp_attr_mask |= IB_QP_ALT_SMAC;
+                       }
+               }
+               qp_attr->path_mtu = cm_id_priv->path_mtu;
+               qp_attr->dest_qp_num = be32_to_cpu(cm_id_priv->remote_qpn);
+               qp_attr->rq_psn = be32_to_cpu(cm_id_priv->rq_psn);
+               if (cm_id_priv->qp_type == IB_QPT_RC ||
+                   cm_id_priv->qp_type == IB_QPT_XRC_TGT) {
+                       *qp_attr_mask |= IB_QP_MAX_DEST_RD_ATOMIC |
+                                        IB_QP_MIN_RNR_TIMER;
+                       qp_attr->max_dest_rd_atomic =
+                                       cm_id_priv->responder_resources;
+                       qp_attr->min_rnr_timer = 0;
+               }
+               if (cm_id_priv->alt_av.ah_attr.dlid) {
+                       *qp_attr_mask |= IB_QP_ALT_PATH;
+                       qp_attr->alt_port_num = cm_id_priv->alt_av.port->port_num;
+                       qp_attr->alt_pkey_index = cm_id_priv->alt_av.pkey_index;
+                       qp_attr->alt_timeout = cm_id_priv->alt_av.timeout;
+                       qp_attr->alt_ah_attr = cm_id_priv->alt_av.ah_attr;
+               }
+               ret = 0;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+
+static int cm_init_qp_rts_attr(struct cm_id_private *cm_id_priv,
+                              struct ib_qp_attr *qp_attr,
+                              int *qp_attr_mask)
+{
+       unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&cm_id_priv->lock, flags);
+       switch (cm_id_priv->id.state) {
+       /* Allow transition to RTS before sending REP */
+       case IB_CM_REQ_RCVD:
+       case IB_CM_MRA_REQ_SENT:
+
+       case IB_CM_REP_RCVD:
+       case IB_CM_MRA_REP_SENT:
+       case IB_CM_REP_SENT:
+       case IB_CM_MRA_REP_RCVD:
+       case IB_CM_ESTABLISHED:
+               if (cm_id_priv->id.lap_state == IB_CM_LAP_UNINIT) {
+                       *qp_attr_mask = IB_QP_STATE | IB_QP_SQ_PSN;
+                       qp_attr->sq_psn = be32_to_cpu(cm_id_priv->sq_psn);
+                       switch (cm_id_priv->qp_type) {
+                       case IB_QPT_RC:
+                       case IB_QPT_XRC_INI:
+                               *qp_attr_mask |= IB_QP_RETRY_CNT | IB_QP_RNR_RETRY |
+                                                IB_QP_MAX_QP_RD_ATOMIC;
+                               qp_attr->retry_cnt = cm_id_priv->retry_count;
+                               qp_attr->rnr_retry = cm_id_priv->rnr_retry_count;
+                               qp_attr->max_rd_atomic = cm_id_priv->initiator_depth;
+                               /* fall through */
+                       case IB_QPT_XRC_TGT:
+                               *qp_attr_mask |= IB_QP_TIMEOUT;
+                               qp_attr->timeout = cm_id_priv->av.timeout;
+                               break;
+                       default:
+                               break;
+                       }
+                       if (cm_id_priv->alt_av.ah_attr.dlid) {
+                               *qp_attr_mask |= IB_QP_PATH_MIG_STATE;
+                               qp_attr->path_mig_state = IB_MIG_REARM;
+                       }
+               } else {
+                       *qp_attr_mask = IB_QP_ALT_PATH | IB_QP_PATH_MIG_STATE;
+                       qp_attr->alt_port_num = cm_id_priv->alt_av.port->port_num;
+                       qp_attr->alt_pkey_index = cm_id_priv->alt_av.pkey_index;
+                       qp_attr->alt_timeout = cm_id_priv->alt_av.timeout;
+                       qp_attr->alt_ah_attr = cm_id_priv->alt_av.ah_attr;
+                       qp_attr->path_mig_state = IB_MIG_REARM;
+               }
+               ret = 0;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+       return ret;
+}
+
+int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
+                      struct ib_qp_attr *qp_attr,
+                      int *qp_attr_mask)
+{
+       struct cm_id_private *cm_id_priv;
+       int ret;
+
+       cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+       switch (qp_attr->qp_state) {
+       case IB_QPS_INIT:
+               ret = cm_init_qp_init_attr(cm_id_priv, qp_attr, qp_attr_mask);
+               break;
+       case IB_QPS_RTR:
+               ret = cm_init_qp_rtr_attr(cm_id_priv, qp_attr, qp_attr_mask);
+               break;
+       case IB_QPS_RTS:
+               ret = cm_init_qp_rts_attr(cm_id_priv, qp_attr, qp_attr_mask);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       return ret;
+}
+EXPORT_SYMBOL(ib_cm_init_qp_attr);
+
+static void cm_get_ack_delay(struct cm_device *cm_dev)
+{
+       struct ib_device_attr attr;
+
+       if (ib_query_device(cm_dev->ib_device, &attr))
+               cm_dev->ack_delay = 0; /* acks will rely on packet life time */
+       else
+               cm_dev->ack_delay = attr.local_ca_ack_delay;
+}
+
+static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
+                              char *buf)
+{
+       struct cm_counter_group *group;
+       struct cm_counter_attribute *cm_attr;
+
+       group = container_of(obj, struct cm_counter_group, obj);
+       cm_attr = container_of(attr, struct cm_counter_attribute, attr);
+
+       return sprintf(buf, "%ld\n",
+                      atomic_long_read(&group->counter[cm_attr->index]));
+}
+
+static const struct sysfs_ops cm_counter_ops = {
+       .show = cm_show_counter
+};
+
+static struct kobj_type cm_counter_obj_type = {
+       .sysfs_ops = &cm_counter_ops,
+       .default_attrs = cm_counter_default_attrs
+};
+
+static void cm_release_port_obj(struct kobject *obj)
+{
+       struct cm_port *cm_port;
+
+       cm_port = container_of(obj, struct cm_port, port_obj);
+       kfree(cm_port);
+}
+
+static struct kobj_type cm_port_obj_type = {
+       .release = cm_release_port_obj
+};
+
+static char *cm_devnode(struct device *dev, umode_t *mode)
+{
+       if (mode)
+               *mode = 0666;
+       return kasprintf(GFP_KERNEL, "infiniband/%s", dev_name(dev));
+}
+
+struct class cm_class = {
+       .owner   = THIS_MODULE,
+       .name    = "infiniband_cm",
+       .devnode = cm_devnode,
+};
+EXPORT_SYMBOL(cm_class);
+
+static int cm_create_port_fs(struct cm_port *port)
+{
+       int i, ret;
+
+       ret = kobject_init_and_add(&port->port_obj, &cm_port_obj_type,
+                                  &port->cm_dev->device->kobj,
+                                  "%d", port->port_num);
+       if (ret) {
+               kfree(port);
+               return ret;
+       }
+
+       for (i = 0; i < CM_COUNTER_GROUPS; i++) {
+               ret = kobject_init_and_add(&port->counter_group[i].obj,
+                                          &cm_counter_obj_type,
+                                          &port->port_obj,
+                                          "%s", counter_group_names[i]);
+               if (ret)
+                       goto error;
+       }
+
+       return 0;
+
+error:
+       while (i--)
+               kobject_put(&port->counter_group[i].obj);
+       kobject_put(&port->port_obj);
+       return ret;
+
+}
+
+static void cm_remove_port_fs(struct cm_port *port)
+{
+       int i;
+
+       for (i = 0; i < CM_COUNTER_GROUPS; i++)
+               kobject_put(&port->counter_group[i].obj);
+
+       kobject_put(&port->port_obj);
+}
+
+static void cm_add_one(struct ib_device *ib_device)
+{
+       struct cm_device *cm_dev;
+       struct cm_port *port;
+       struct ib_mad_reg_req reg_req = {
+               .mgmt_class = IB_MGMT_CLASS_CM,
+               .mgmt_class_version = IB_CM_CLASS_VERSION,
+       };
+       struct ib_port_modify port_modify = {
+               .set_port_cap_mask = IB_PORT_CM_SUP
+       };
+       unsigned long flags;
+       int ret;
+       u8 i;
+
+       if (rdma_node_get_transport(ib_device->node_type) != RDMA_TRANSPORT_IB)
+               return;
+
+       cm_dev = kzalloc(sizeof(*cm_dev) + sizeof(*port) *
+                        ib_device->phys_port_cnt, GFP_KERNEL);
+       if (!cm_dev)
+               return;
+
+       cm_dev->ib_device = ib_device;
+       cm_get_ack_delay(cm_dev);
+
+       cm_dev->device = device_create(&cm_class, &ib_device->dev,
+                                      MKDEV(0, 0), NULL,
+                                      "%s", ib_device->name);
+       if (IS_ERR(cm_dev->device)) {
+               kfree(cm_dev);
+               return;
+       }
+
+       set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask);
+       for (i = 1; i <= ib_device->phys_port_cnt; i++) {
+               port = kzalloc(sizeof *port, GFP_KERNEL);
+               if (!port)
+                       goto error1;
+
+               cm_dev->port[i-1] = port;
+               port->cm_dev = cm_dev;
+               port->port_num = i;
+
+               ret = cm_create_port_fs(port);
+               if (ret)
+                       goto error1;
+
+               port->mad_agent = ib_register_mad_agent(ib_device, i,
+                                                       IB_QPT_GSI,
+                                                       &reg_req,
+                                                       0,
+                                                       cm_send_handler,
+                                                       cm_recv_handler,
+                                                       port,
+                                                       0);
+               if (IS_ERR(port->mad_agent))
+                       goto error2;
+
+               ret = ib_modify_port(ib_device, i, 0, &port_modify);
+               if (ret)
+                       goto error3;
+       }
+       ib_set_client_data(ib_device, &cm_client, cm_dev);
+
+       write_lock_irqsave(&cm.device_lock, flags);
+       list_add_tail(&cm_dev->list, &cm.device_list);
+       write_unlock_irqrestore(&cm.device_lock, flags);
+       return;
+
+error3:
+       ib_unregister_mad_agent(port->mad_agent);
+error2:
+       cm_remove_port_fs(port);
+error1:
+       port_modify.set_port_cap_mask = 0;
+       port_modify.clr_port_cap_mask = IB_PORT_CM_SUP;
+       while (--i) {
+               port = cm_dev->port[i-1];
+               ib_modify_port(ib_device, port->port_num, 0, &port_modify);
+               ib_unregister_mad_agent(port->mad_agent);
+               cm_remove_port_fs(port);
+       }
+       device_unregister(cm_dev->device);
+       kfree(cm_dev);
+}
+
+static void cm_remove_one(struct ib_device *ib_device)
+{
+       struct cm_device *cm_dev;
+       struct cm_port *port;
+       struct ib_port_modify port_modify = {
+               .clr_port_cap_mask = IB_PORT_CM_SUP
+       };
+       unsigned long flags;
+       int i;
+
+       cm_dev = ib_get_client_data(ib_device, &cm_client);
+       if (!cm_dev)
+               return;
+
+       write_lock_irqsave(&cm.device_lock, flags);
+       list_del(&cm_dev->list);
+       write_unlock_irqrestore(&cm.device_lock, flags);
+
+       for (i = 1; i <= ib_device->phys_port_cnt; i++) {
+               port = cm_dev->port[i-1];
+               ib_modify_port(ib_device, port->port_num, 0, &port_modify);
+               ib_unregister_mad_agent(port->mad_agent);
+               flush_workqueue(cm.wq);
+               cm_remove_port_fs(port);
+       }
+       device_unregister(cm_dev->device);
+       kfree(cm_dev);
+}
+
+static int __init ib_cm_init(void)
+{
+       int ret;
+
+       memset(&cm, 0, sizeof cm);
+       INIT_LIST_HEAD(&cm.device_list);
+       rwlock_init(&cm.device_lock);
+       spin_lock_init(&cm.lock);
+       cm.listen_service_table = RB_ROOT;
+       cm.listen_service_id = be64_to_cpu(IB_CM_ASSIGN_SERVICE_ID);
+       cm.remote_id_table = RB_ROOT;
+       cm.remote_qp_table = RB_ROOT;
+       cm.remote_sidr_table = RB_ROOT;
+       idr_init(&cm.local_id_table);
+       get_random_bytes(&cm.random_id_operand, sizeof cm.random_id_operand);
+       INIT_LIST_HEAD(&cm.timewait_list);
+
+       ret = class_register(&cm_class);
+       if (ret) {
+               ret = -ENOMEM;
+               goto error1;
+       }
+
+       cm.wq = create_workqueue("ib_cm");
+       if (!cm.wq) {
+               ret = -ENOMEM;
+               goto error2;
+       }
+
+       ret = ib_register_client(&cm_client);
+       if (ret)
+               goto error3;
+
+       return 0;
+error3:
+       destroy_workqueue(cm.wq);
+error2:
+       class_unregister(&cm_class);
+error1:
+       idr_destroy(&cm.local_id_table);
+       return ret;
+}
+
+static void __exit ib_cm_cleanup(void)
+{
+       struct cm_timewait_info *timewait_info, *tmp;
+
+       spin_lock_irq(&cm.lock);
+       list_for_each_entry(timewait_info, &cm.timewait_list, list)
+               cancel_delayed_work(&timewait_info->work.work);
+       spin_unlock_irq(&cm.lock);
+
+       ib_unregister_client(&cm_client);
+       destroy_workqueue(cm.wq);
+
+       list_for_each_entry_safe(timewait_info, tmp, &cm.timewait_list, list) {
+               list_del(&timewait_info->list);
+               kfree(timewait_info);
+       }
+
+       class_unregister(&cm_class);
+       idr_destroy(&cm.local_id_table);
+}
+
+module_init(ib_cm_init);
+module_exit(ib_cm_cleanup);
+
diff --git a/drivers/infiniband/core/cm_msgs.h b/drivers/infiniband/core/cm_msgs.h
new file mode 100644 (file)
index 0000000..be068f4
--- /dev/null
@@ -0,0 +1,836 @@
+/*
+ * Copyright (c) 2004, 2011 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
+ * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING the madirectory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use source and binary forms, with or
+ *     withmodification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retathe above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHWARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS THE
+ * SOFTWARE.
+ */
+#if !defined(CM_MSGS_H)
+#define CM_MSGS_H
+
+#include <rdma/ib_mad.h>
+#include <rdma/ib_cm.h>
+
+/*
+ * Parameters to routines below should be in network-byte order, and values
+ * are returned in network-byte order.
+ */
+
+#define IB_CM_CLASS_VERSION    2 /* IB specification 1.2 */
+
+enum cm_msg_sequence {
+       CM_MSG_SEQUENCE_REQ,
+       CM_MSG_SEQUENCE_LAP,
+       CM_MSG_SEQUENCE_DREQ,
+       CM_MSG_SEQUENCE_SIDR
+};
+
+struct cm_req_msg {
+       struct ib_mad_hdr hdr;
+
+       __be32 local_comm_id;
+       __be32 rsvd4;
+       __be64 service_id;
+       __be64 local_ca_guid;
+       __be32 rsvd24;
+       __be32 local_qkey;
+       /* local QPN:24, responder resources:8 */
+       __be32 offset32;
+       /* local EECN:24, initiator depth:8 */
+       __be32 offset36;
+       /*
+        * remote EECN:24, remote CM response timeout:5,
+        * transport service type:2, end-to-end flow control:1
+        */
+       __be32 offset40;
+       /* starting PSN:24, local CM response timeout:5, retry count:3 */
+       __be32 offset44;
+       __be16 pkey;
+       /* path MTU:4, RDC exists:1, RNR retry count:3. */
+       u8 offset50;
+       /* max CM Retries:4, SRQ:1, extended transport type:3 */
+       u8 offset51;
+
+       __be16 primary_local_lid;
+       __be16 primary_remote_lid;
+       union ib_gid primary_local_gid;
+       union ib_gid primary_remote_gid;
+       /* flow label:20, rsvd:6, packet rate:6 */
+       __be32 primary_offset88;
+       u8 primary_traffic_class;
+       u8 primary_hop_limit;
+       /* SL:4, subnet local:1, rsvd:3 */
+       u8 primary_offset94;
+       /* local ACK timeout:5, rsvd:3 */
+       u8 primary_offset95;
+
+       __be16 alt_local_lid;
+       __be16 alt_remote_lid;
+       union ib_gid alt_local_gid;
+       union ib_gid alt_remote_gid;
+       /* flow label:20, rsvd:6, packet rate:6 */
+       __be32 alt_offset132;
+       u8 alt_traffic_class;
+       u8 alt_hop_limit;
+       /* SL:4, subnet local:1, rsvd:3 */
+       u8 alt_offset138;
+       /* local ACK timeout:5, rsvd:3 */
+       u8 alt_offset139;
+
+       u8 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE];
+
+} __attribute__ ((packed));
+
+static inline __be32 cm_req_get_local_qpn(struct cm_req_msg *req_msg)
+{
+       return cpu_to_be32(be32_to_cpu(req_msg->offset32) >> 8);
+}
+
+static inline void cm_req_set_local_qpn(struct cm_req_msg *req_msg, __be32 qpn)
+{
+       req_msg->offset32 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
+                                        (be32_to_cpu(req_msg->offset32) &
+