aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-03-22 18:48:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-22 18:48:44 -0400
commitb8ba4526832fcccba7f46e55ce9a8b79902bdcec (patch)
tree5f2fc306e9909c9936efc017bf2c8fde49d8c9bb
parent01cde1538e1dff4254e340f606177a870131a01f (diff)
parent520a07bff6fbb23cac905007d74c67058b189acb (diff)
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma
Pull more rdma updates from Doug Ledford: "Round two of 4.6 merge window patches. This is a monster pull request. I held off on the hfi1 driver updates (the hfi1 driver is intimately tied to the qib driver and the new rdmavt software library that was created to help both of them) in my first pull request. The hfi1/qib/rdmavt update is probably 90% of this pull request. The hfi1 driver is being left in staging so that it can be fixed up in regards to the API that Al and yourself didn't like. Intel has agreed to do the work, but in the meantime, this clears out 300+ patches in the backlog queue and brings my tree and their tree closer to sync. This also includes about 10 patches to the core and a few to mlx5 to create an infrastructure for configuring SRIOV ports on IB devices. That series includes one patch to the net core that we sent to netdev@ and Dave Miller with each of the three revisions to the series. We didn't get any response to the patch, so we took that as implicit approval. Finally, this series includes Intel's new iWARP driver for their x722 cards. It's not nearly the beast as the hfi1 driver. It also has a linux-next merge issue, but that has been resolved and it now passes just fine. Summary: - A few minor core fixups needed for the next patch series - The IB SRIOV series. This has bounced around for several versions. Of note is the fact that the first patch in this series effects the net core. It was directed to netdev and DaveM for each iteration of the series (three versions total). Dave did not object, but did not respond either. I've taken this as permission to move forward with the series. - The new Intel X722 iWARP driver - A huge set of updates to the Intel hfi1 driver. Of particular interest here is that we have left the driver in staging since it still has an API that people object to. Intel is working on a fix, but getting these patches in now helps keep me sane as the upstream and Intel's trees were over 300 patches apart" * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma: (362 commits) IB/ipoib: Allow mcast packets from other VFs IB/mlx5: Implement callbacks for manipulating VFs net/mlx5_core: Implement modify HCA vport command net/mlx5_core: Add VF param when querying vport counter IB/ipoib: Add ndo operations for configuring VFs IB/core: Add interfaces to control VF attributes IB/core: Support accessing SA in virtualized environment IB/core: Add subnet prefix to port info IB/mlx5: Fix decision on using MAD_IFC net/core: Add support for configuring VF GUIDs IB/{core, ulp} Support above 32 possible device capability flags IB/core: Replace setting the zero values in ib_uverbs_ex_query_device net/mlx5_core: Introduce offload arithmetic hardware capabilities net/mlx5_core: Refactor device capability function net/mlx5_core: Fix caching ATOMIC endian mode capability ib_srpt: fix a WARN_ON() message i40iw: Replace the obsolete crypto hash interface with shash IB/hfi1: Add SDMA cache eviction algorithm IB/hfi1: Switch to using the pin query function IB/hfi1: Specify mm when releasing pages ...
-rw-r--r--Documentation/infiniband/sysfs.txt3
-rw-r--r--MAINTAINERS16
-rw-r--r--drivers/infiniband/Kconfig3
-rw-r--r--drivers/infiniband/Makefile1
-rw-r--r--drivers/infiniband/core/device.c15
-rw-r--r--drivers/infiniband/core/sa_query.c5
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c17
-rw-r--r--drivers/infiniband/core/verbs.c40
-rw-r--r--drivers/infiniband/hw/Makefile1
-rw-r--r--drivers/infiniband/hw/i40iw/Kconfig7
-rw-r--r--drivers/infiniband/hw/i40iw/Makefile9
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw.h570
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_cm.c4141
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_cm.h456
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_ctrl.c4743
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_d.h1713
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_hmc.c821
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_hmc.h241
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_hw.c730
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_main.c1910
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_osdep.h215
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_p.h106
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_pble.c618
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_pble.h131
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_puda.c1436
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_puda.h183
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_register.h1030
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_status.h100
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_type.h1312
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_ucontext.h107
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_uk.c1204
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_user.h442
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_utils.c1270
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_verbs.c2437
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_verbs.h173
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_vf.c85
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_vf.h62
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_virtchnl.c748
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_virtchnl.h124
-rw-r--r--drivers/infiniband/hw/mlx5/Makefile2
-rw-r--r--drivers/infiniband/hw/mlx5/ib_virt.c194
-rw-r--r--drivers/infiniband/hw/mlx5/mad.c2
-rw-r--r--drivers/infiniband/hw/mlx5/main.c12
-rw-r--r--drivers/infiniband/hw/mlx5/mlx5_ib.h8
-rw-r--r--drivers/infiniband/hw/qib/Kconfig2
-rw-r--r--drivers/infiniband/hw/qib/Makefile10
-rw-r--r--drivers/infiniband/hw/qib/qib.h33
-rw-r--r--drivers/infiniband/hw/qib/qib_common.h3
-rw-r--r--drivers/infiniband/hw/qib/qib_cq.c545
-rw-r--r--drivers/infiniband/hw/qib/qib_driver.c71
-rw-r--r--drivers/infiniband/hw/qib/qib_iba6120.c8
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7322.c6
-rw-r--r--drivers/infiniband/hw/qib/qib_init.c25
-rw-r--r--drivers/infiniband/hw/qib/qib_intr.c2
-rw-r--r--drivers/infiniband/hw/qib/qib_keys.c186
-rw-r--r--drivers/infiniband/hw/qib/qib_mad.c338
-rw-r--r--drivers/infiniband/hw/qib/qib_mmap.c174
-rw-r--r--drivers/infiniband/hw/qib/qib_mr.c490
-rw-r--r--drivers/infiniband/hw/qib/qib_qp.c1178
-rw-r--r--drivers/infiniband/hw/qib/qib_rc.c409
-rw-r--r--drivers/infiniband/hw/qib/qib_ruc.c191
-rw-r--r--drivers/infiniband/hw/qib/qib_sdma.c41
-rw-r--r--drivers/infiniband/hw/qib/qib_srq.c380
-rw-r--r--drivers/infiniband/hw/qib/qib_sysfs.c85
-rw-r--r--drivers/infiniband/hw/qib/qib_uc.c79
-rw-r--r--drivers/infiniband/hw/qib/qib_ud.c142
-rw-r--r--drivers/infiniband/hw/qib/qib_verbs.c1223
-rw-r--r--drivers/infiniband/hw/qib/qib_verbs.h812
-rw-r--r--drivers/infiniband/hw/qib/qib_verbs_mcast.c363
-rw-r--r--drivers/infiniband/sw/Makefile1
-rw-r--r--drivers/infiniband/sw/rdmavt/Kconfig6
-rw-r--r--drivers/infiniband/sw/rdmavt/Makefile13
-rw-r--r--drivers/infiniband/sw/rdmavt/ah.c196
-rw-r--r--drivers/infiniband/sw/rdmavt/ah.h59
-rw-r--r--drivers/infiniband/sw/rdmavt/cq.c (renamed from drivers/staging/rdma/hfi1/cq.c)325
-rw-r--r--drivers/infiniband/sw/rdmavt/cq.h64
-rw-r--r--drivers/infiniband/sw/rdmavt/dma.c184
-rw-r--r--drivers/infiniband/sw/rdmavt/dma.h53
-rw-r--r--drivers/infiniband/sw/rdmavt/mad.c171
-rw-r--r--drivers/infiniband/sw/rdmavt/mad.h60
-rw-r--r--drivers/infiniband/sw/rdmavt/mcast.c (renamed from drivers/staging/rdma/hfi1/verbs_mcast.c)262
-rw-r--r--drivers/infiniband/sw/rdmavt/mcast.h58
-rw-r--r--drivers/infiniband/sw/rdmavt/mmap.c (renamed from drivers/staging/rdma/hfi1/mmap.c)142
-rw-r--r--drivers/infiniband/sw/rdmavt/mmap.h63
-rw-r--r--drivers/infiniband/sw/rdmavt/mr.c830
-rw-r--r--drivers/infiniband/sw/rdmavt/mr.h92
-rw-r--r--drivers/infiniband/sw/rdmavt/pd.c119
-rw-r--r--drivers/infiniband/sw/rdmavt/pd.h58
-rw-r--r--drivers/infiniband/sw/rdmavt/qp.c1696
-rw-r--r--drivers/infiniband/sw/rdmavt/qp.h69
-rw-r--r--drivers/infiniband/sw/rdmavt/srq.c (renamed from drivers/staging/rdma/hfi1/srq.c)204
-rw-r--r--drivers/infiniband/sw/rdmavt/srq.h62
-rw-r--r--drivers/infiniband/sw/rdmavt/trace.c49
-rw-r--r--drivers/infiniband/sw/rdmavt/trace.h187
-rw-r--r--drivers/infiniband/sw/rdmavt/vt.c873
-rw-r--r--drivers/infiniband/sw/rdmavt/vt.h104
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h2
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c27
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c65
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c2
-rw-r--r--drivers/net/ethernet/intel/i40e/Makefile1
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e.h22
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_client.c1012
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_client.h232
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_main.c115
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_type.h3
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_virtchnl.h34
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c247
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/cmd.c6
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fw.c57
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c24
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/vport.c72
-rw-r--r--drivers/staging/rdma/hfi1/Kconfig13
-rw-r--r--drivers/staging/rdma/hfi1/Makefile10
-rw-r--r--drivers/staging/rdma/hfi1/affinity.c430
-rw-r--r--drivers/staging/rdma/hfi1/affinity.h91
-rw-r--r--drivers/staging/rdma/hfi1/aspm.h309
-rw-r--r--drivers/staging/rdma/hfi1/chip.c2456
-rw-r--r--drivers/staging/rdma/hfi1/chip.h151
-rw-r--r--drivers/staging/rdma/hfi1/chip_registers.h9
-rw-r--r--drivers/staging/rdma/hfi1/common.h12
-rw-r--r--drivers/staging/rdma/hfi1/debugfs.c332
-rw-r--r--drivers/staging/rdma/hfi1/debugfs.h5
-rw-r--r--drivers/staging/rdma/hfi1/device.c5
-rw-r--r--drivers/staging/rdma/hfi1/device.h5
-rw-r--r--drivers/staging/rdma/hfi1/diag.c103
-rw-r--r--drivers/staging/rdma/hfi1/dma.c17
-rw-r--r--drivers/staging/rdma/hfi1/driver.c344
-rw-r--r--drivers/staging/rdma/hfi1/efivar.c5
-rw-r--r--drivers/staging/rdma/hfi1/efivar.h5
-rw-r--r--drivers/staging/rdma/hfi1/eprom.c117
-rw-r--r--drivers/staging/rdma/hfi1/eprom.h7
-rw-r--r--drivers/staging/rdma/hfi1/file_ops.c552
-rw-r--r--drivers/staging/rdma/hfi1/firmware.c587
-rw-r--r--drivers/staging/rdma/hfi1/hfi.h251
-rw-r--r--drivers/staging/rdma/hfi1/init.c183
-rw-r--r--drivers/staging/rdma/hfi1/intr.c29
-rw-r--r--drivers/staging/rdma/hfi1/iowait.h126
-rw-r--r--drivers/staging/rdma/hfi1/keys.c356
-rw-r--r--drivers/staging/rdma/hfi1/mad.c1005
-rw-r--r--drivers/staging/rdma/hfi1/mad.h14
-rw-r--r--drivers/staging/rdma/hfi1/mmu_rb.c292
-rw-r--r--drivers/staging/rdma/hfi1/mmu_rb.h73
-rw-r--r--drivers/staging/rdma/hfi1/mr.c473
-rw-r--r--drivers/staging/rdma/hfi1/opa_compat.h20
-rw-r--r--drivers/staging/rdma/hfi1/pcie.c192
-rw-r--r--drivers/staging/rdma/hfi1/pio.c365
-rw-r--r--drivers/staging/rdma/hfi1/pio.h118
-rw-r--r--drivers/staging/rdma/hfi1/pio_copy.c67
-rw-r--r--drivers/staging/rdma/hfi1/platform.c893
-rw-r--r--drivers/staging/rdma/hfi1/platform.h (renamed from drivers/staging/rdma/hfi1/platform_config.h)58
-rw-r--r--drivers/staging/rdma/hfi1/qp.c1642
-rw-r--r--drivers/staging/rdma/hfi1/qp.h198
-rw-r--r--drivers/staging/rdma/hfi1/qsfp.c270
-rw-r--r--drivers/staging/rdma/hfi1/qsfp.h57
-rw-r--r--drivers/staging/rdma/hfi1/rc.c765
-rw-r--r--drivers/staging/rdma/hfi1/ruc.c373
-rw-r--r--drivers/staging/rdma/hfi1/sdma.c365
-rw-r--r--drivers/staging/rdma/hfi1/sdma.h116
-rw-r--r--drivers/staging/rdma/hfi1/sdma_txreq.h135
-rw-r--r--drivers/staging/rdma/hfi1/sysfs.c136
-rw-r--r--drivers/staging/rdma/hfi1/trace.c53
-rw-r--r--drivers/staging/rdma/hfi1/trace.h1477
-rw-r--r--drivers/staging/rdma/hfi1/twsi.c205
-rw-r--r--drivers/staging/rdma/hfi1/twsi.h9
-rw-r--r--drivers/staging/rdma/hfi1/uc.c164
-rw-r--r--drivers/staging/rdma/hfi1/ud.c248
-rw-r--r--drivers/staging/rdma/hfi1/user_exp_rcv.c1044
-rw-r--r--drivers/staging/rdma/hfi1/user_exp_rcv.h13
-rw-r--r--drivers/staging/rdma/hfi1/user_pages.c74
-rw-r--r--drivers/staging/rdma/hfi1/user_sdma.c621
-rw-r--r--drivers/staging/rdma/hfi1/user_sdma.h11
-rw-r--r--drivers/staging/rdma/hfi1/verbs.c1663
-rw-r--r--drivers/staging/rdma/hfi1/verbs.h824
-rw-r--r--drivers/staging/rdma/hfi1/verbs_txreq.c149
-rw-r--r--drivers/staging/rdma/hfi1/verbs_txreq.h116
-rw-r--r--include/linux/mlx5/device.h6
-rw-r--r--include/linux/mlx5/driver.h8
-rw-r--r--include/linux/mlx5/mlx5_ifc.h37
-rw-r--r--include/linux/mlx5/vport.h7
-rw-r--r--include/linux/netdevice.h3
-rw-r--r--include/rdma/ib_verbs.h29
-rw-r--r--include/rdma/opa_port_info.h2
-rw-r--r--include/rdma/rdma_vt.h481
-rw-r--r--include/rdma/rdmavt_cq.h99
-rw-r--r--include/rdma/rdmavt_mr.h139
-rw-r--r--include/rdma/rdmavt_qp.h446
-rw-r--r--include/uapi/linux/if_link.h7
-rw-r--r--include/uapi/rdma/hfi/hfi1_user.h14
-rw-r--r--include/uapi/rdma/rdma_netlink.h1
-rw-r--r--net/core/rtnetlink.c36
192 files changed, 49074 insertions, 15213 deletions
diff --git a/Documentation/infiniband/sysfs.txt b/Documentation/infiniband/sysfs.txt
index 9028b025501a..3ecf0c3a133f 100644
--- a/Documentation/infiniband/sysfs.txt
+++ b/Documentation/infiniband/sysfs.txt
@@ -78,9 +78,10 @@ HFI1
78 chip_reset - diagnostic (root only) 78 chip_reset - diagnostic (root only)
79 boardversion - board version 79 boardversion - board version
80 ports/1/ 80 ports/1/
81 CMgtA/ 81 CCMgtA/
82 cc_settings_bin - CCA tables used by PSM2 82 cc_settings_bin - CCA tables used by PSM2
83 cc_table_bin 83 cc_table_bin
84 cc_prescan - enable prescaning for faster BECN response
84 sc2v/ - 32 files (0 - 31) used to translate sl->vl 85 sc2v/ - 32 files (0 - 31) used to translate sl->vl
85 sl2sc/ - 32 files (0 - 31) used to translate sl->sc 86 sl2sc/ - 32 files (0 - 31) used to translate sl->sc
86 vl2mtu/ - 16 (0 - 15) files used to determine MTU for vl 87 vl2mtu/ - 16 (0 - 15) files used to determine MTU for vl
diff --git a/MAINTAINERS b/MAINTAINERS
index 0f3063cce44c..32bafda47c2f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5770,6 +5770,16 @@ F: Documentation/networking/i40evf.txt
5770F: drivers/net/ethernet/intel/ 5770F: drivers/net/ethernet/intel/
5771F: drivers/net/ethernet/intel/*/ 5771F: drivers/net/ethernet/intel/*/
5772 5772
5773INTEL RDMA RNIC DRIVER
5774M: Faisal Latif <faisal.latif@intel.com>
5775R: Chien Tin Tung <chien.tin.tung@intel.com>
5776R: Mustafa Ismail <mustafa.ismail@intel.com>
5777R: Shiraz Saleem <shiraz.saleem@intel.com>
5778R: Tatyana Nikolova <tatyana.e.nikolova@intel.com>
5779L: linux-rdma@vger.kernel.org
5780S: Supported
5781F: drivers/infiniband/hw/i40iw/
5782
5773INTEL-MID GPIO DRIVER 5783INTEL-MID GPIO DRIVER
5774M: David Cohen <david.a.cohen@linux.intel.com> 5784M: David Cohen <david.a.cohen@linux.intel.com>
5775L: linux-gpio@vger.kernel.org 5785L: linux-gpio@vger.kernel.org
@@ -9224,6 +9234,12 @@ S: Supported
9224F: net/rds/ 9234F: net/rds/
9225F: Documentation/networking/rds.txt 9235F: Documentation/networking/rds.txt
9226 9236
9237RDMAVT - RDMA verbs software
9238M: Dennis Dalessandro <dennis.dalessandro@intel.com>
9239L: linux-rdma@vger.kernel.org
9240S: Supported
9241F: drivers/infiniband/sw/rdmavt
9242
9227READ-COPY UPDATE (RCU) 9243READ-COPY UPDATE (RCU)
9228M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> 9244M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
9229M: Josh Triplett <josh@joshtriplett.org> 9245M: Josh Triplett <josh@joshtriplett.org>
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index 8a8440c0eed1..6425c0e5d18a 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -68,6 +68,7 @@ source "drivers/infiniband/hw/mthca/Kconfig"
68source "drivers/infiniband/hw/qib/Kconfig" 68source "drivers/infiniband/hw/qib/Kconfig"
69source "drivers/infiniband/hw/cxgb3/Kconfig" 69source "drivers/infiniband/hw/cxgb3/Kconfig"
70source "drivers/infiniband/hw/cxgb4/Kconfig" 70source "drivers/infiniband/hw/cxgb4/Kconfig"
71source "drivers/infiniband/hw/i40iw/Kconfig"
71source "drivers/infiniband/hw/mlx4/Kconfig" 72source "drivers/infiniband/hw/mlx4/Kconfig"
72source "drivers/infiniband/hw/mlx5/Kconfig" 73source "drivers/infiniband/hw/mlx5/Kconfig"
73source "drivers/infiniband/hw/nes/Kconfig" 74source "drivers/infiniband/hw/nes/Kconfig"
@@ -82,4 +83,6 @@ source "drivers/infiniband/ulp/srpt/Kconfig"
82source "drivers/infiniband/ulp/iser/Kconfig" 83source "drivers/infiniband/ulp/iser/Kconfig"
83source "drivers/infiniband/ulp/isert/Kconfig" 84source "drivers/infiniband/ulp/isert/Kconfig"
84 85
86source "drivers/infiniband/sw/rdmavt/Kconfig"
87
85endif # INFINIBAND 88endif # INFINIBAND
diff --git a/drivers/infiniband/Makefile b/drivers/infiniband/Makefile
index dc21836b5a8d..fad0b44c356f 100644
--- a/drivers/infiniband/Makefile
+++ b/drivers/infiniband/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_INFINIBAND) += core/ 1obj-$(CONFIG_INFINIBAND) += core/
2obj-$(CONFIG_INFINIBAND) += hw/ 2obj-$(CONFIG_INFINIBAND) += hw/
3obj-$(CONFIG_INFINIBAND) += ulp/ 3obj-$(CONFIG_INFINIBAND) += ulp/
4obj-$(CONFIG_INFINIBAND) += sw/
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 270c7ff6cba7..10979844026a 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -650,10 +650,23 @@ int ib_query_port(struct ib_device *device,
650 u8 port_num, 650 u8 port_num,
651 struct ib_port_attr *port_attr) 651 struct ib_port_attr *port_attr)
652{ 652{
653 union ib_gid gid;
654 int err;
655
653 if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) 656 if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
654 return -EINVAL; 657 return -EINVAL;
655 658
656 return device->query_port(device, port_num, port_attr); 659 memset(port_attr, 0, sizeof(*port_attr));
660 err = device->query_port(device, port_num, port_attr);
661 if (err || port_attr->subnet_prefix)
662 return err;
663
664 err = ib_query_gid(device, port_num, 0, &gid, NULL);
665 if (err)
666 return err;
667
668 port_attr->subnet_prefix = be64_to_cpu(gid.global.subnet_prefix);
669 return 0;
657} 670}
658EXPORT_SYMBOL(ib_query_port); 671EXPORT_SYMBOL(ib_query_port);
659 672
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index b5656a2298ee..8a09c0fb268d 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -885,6 +885,11 @@ static void update_sm_ah(struct work_struct *work)
885 ah_attr.dlid = port_attr.sm_lid; 885 ah_attr.dlid = port_attr.sm_lid;
886 ah_attr.sl = port_attr.sm_sl; 886 ah_attr.sl = port_attr.sm_sl;
887 ah_attr.port_num = port->port_num; 887 ah_attr.port_num = port->port_num;
888 if (port_attr.grh_required) {
889 ah_attr.ah_flags = IB_AH_GRH;
890 ah_attr.grh.dgid.global.subnet_prefix = cpu_to_be64(port_attr.subnet_prefix);
891 ah_attr.grh.dgid.global.interface_id = cpu_to_be64(IB_SA_WELL_KNOWN_GUID);
892 }
888 893
889 new_ah->ah = ib_create_ah(port->agent->qp->pd, &ah_attr); 894 new_ah->ah = ib_create_ah(port->agent->qp->pd, &ah_attr);
890 if (IS_ERR(new_ah->ah)) { 895 if (IS_ERR(new_ah->ah)) {
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 3638c787cb7c..6fdc7ecdaca0 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -402,7 +402,7 @@ static void copy_query_dev_fields(struct ib_uverbs_file *file,
402 resp->hw_ver = attr->hw_ver; 402 resp->hw_ver = attr->hw_ver;
403 resp->max_qp = attr->max_qp; 403 resp->max_qp = attr->max_qp;
404 resp->max_qp_wr = attr->max_qp_wr; 404 resp->max_qp_wr = attr->max_qp_wr;
405 resp->device_cap_flags = attr->device_cap_flags; 405 resp->device_cap_flags = lower_32_bits(attr->device_cap_flags);
406 resp->max_sge = attr->max_sge; 406 resp->max_sge = attr->max_sge;
407 resp->max_sge_rd = attr->max_sge_rd; 407 resp->max_sge_rd = attr->max_sge_rd;
408 resp->max_cq = attr->max_cq; 408 resp->max_cq = attr->max_cq;
@@ -3600,9 +3600,9 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file *file,
3600 struct ib_udata *ucore, 3600 struct ib_udata *ucore,
3601 struct ib_udata *uhw) 3601 struct ib_udata *uhw)
3602{ 3602{
3603 struct ib_uverbs_ex_query_device_resp resp; 3603 struct ib_uverbs_ex_query_device_resp resp = { {0} };
3604 struct ib_uverbs_ex_query_device cmd; 3604 struct ib_uverbs_ex_query_device cmd;
3605 struct ib_device_attr attr; 3605 struct ib_device_attr attr = {0};
3606 int err; 3606 int err;
3607 3607
3608 if (ucore->inlen < sizeof(cmd)) 3608 if (ucore->inlen < sizeof(cmd))
@@ -3623,14 +3623,11 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file *file,
3623 if (ucore->outlen < resp.response_length) 3623 if (ucore->outlen < resp.response_length)
3624 return -ENOSPC; 3624 return -ENOSPC;
3625 3625
3626 memset(&attr, 0, sizeof(attr));
3627
3628 err = ib_dev->query_device(ib_dev, &attr, uhw); 3626 err = ib_dev->query_device(ib_dev, &attr, uhw);
3629 if (err) 3627 if (err)
3630 return err; 3628 return err;
3631 3629
3632 copy_query_dev_fields(file, ib_dev, &resp.base, &attr); 3630 copy_query_dev_fields(file, ib_dev, &resp.base, &attr);
3633 resp.comp_mask = 0;
3634 3631
3635 if (ucore->outlen < resp.response_length + sizeof(resp.odp_caps)) 3632 if (ucore->outlen < resp.response_length + sizeof(resp.odp_caps))
3636 goto end; 3633 goto end;
@@ -3643,9 +3640,6 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file *file,
3643 attr.odp_caps.per_transport_caps.uc_odp_caps; 3640 attr.odp_caps.per_transport_caps.uc_odp_caps;
3644 resp.odp_caps.per_transport_caps.ud_odp_caps = 3641 resp.odp_caps.per_transport_caps.ud_odp_caps =
3645 attr.odp_caps.per_transport_caps.ud_odp_caps; 3642 attr.odp_caps.per_transport_caps.ud_odp_caps;
3646 resp.odp_caps.reserved = 0;
3647#else
3648 memset(&resp.odp_caps, 0, sizeof(resp.odp_caps));
3649#endif 3643#endif
3650 resp.response_length += sizeof(resp.odp_caps); 3644 resp.response_length += sizeof(resp.odp_caps);
3651 3645
@@ -3663,8 +3657,5 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file *file,
3663 3657
3664end: 3658end:
3665 err = ib_copy_to_udata(ucore, &resp, resp.response_length); 3659 err = ib_copy_to_udata(ucore, &resp, resp.response_length);
3666 if (err) 3660 return err;
3667 return err;
3668
3669 return 0;
3670} 3661}
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 5cd1e3987f2b..15b8adbf39c0 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -1551,6 +1551,46 @@ int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
1551} 1551}
1552EXPORT_SYMBOL(ib_check_mr_status); 1552EXPORT_SYMBOL(ib_check_mr_status);
1553 1553
1554int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
1555 int state)
1556{
1557 if (!device->set_vf_link_state)
1558 return -ENOSYS;
1559
1560 return device->set_vf_link_state(device, vf, port, state);
1561}
1562EXPORT_SYMBOL(ib_set_vf_link_state);
1563
1564int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
1565 struct ifla_vf_info *info)
1566{
1567 if (!device->get_vf_config)
1568 return -ENOSYS;
1569
1570 return device->get_vf_config(device, vf, port, info);
1571}
1572EXPORT_SYMBOL(ib_get_vf_config);
1573
1574int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
1575 struct ifla_vf_stats *stats)
1576{
1577 if (!device->get_vf_stats)
1578 return -ENOSYS;
1579
1580 return device->get_vf_stats(device, vf, port, stats);
1581}
1582EXPORT_SYMBOL(ib_get_vf_stats);
1583
1584int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
1585 int type)
1586{
1587 if (!device->set_vf_guid)
1588 return -ENOSYS;
1589
1590 return device->set_vf_guid(device, vf, port, guid, type);
1591}
1592EXPORT_SYMBOL(ib_set_vf_guid);
1593
1554/** 1594/**
1555 * ib_map_mr_sg() - Map the largest prefix of a dma mapped SG list 1595 * ib_map_mr_sg() - Map the largest prefix of a dma mapped SG list
1556 * and set it the memory region. 1596 * and set it the memory region.
diff --git a/drivers/infiniband/hw/Makefile b/drivers/infiniband/hw/Makefile
index aded2a5cc2d5..c7ad0a4c8b15 100644
--- a/drivers/infiniband/hw/Makefile
+++ b/drivers/infiniband/hw/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_INFINIBAND_MTHCA) += mthca/
2obj-$(CONFIG_INFINIBAND_QIB) += qib/ 2obj-$(CONFIG_INFINIBAND_QIB) += qib/
3obj-$(CONFIG_INFINIBAND_CXGB3) += cxgb3/ 3obj-$(CONFIG_INFINIBAND_CXGB3) += cxgb3/
4obj-$(CONFIG_INFINIBAND_CXGB4) += cxgb4/ 4obj-$(CONFIG_INFINIBAND_CXGB4) += cxgb4/
5obj-$(CONFIG_INFINIBAND_I40IW) += i40iw/
5obj-$(CONFIG_MLX4_INFINIBAND) += mlx4/ 6obj-$(CONFIG_MLX4_INFINIBAND) += mlx4/
6obj-$(CONFIG_MLX5_INFINIBAND) += mlx5/ 7obj-$(CONFIG_MLX5_INFINIBAND) += mlx5/
7obj-$(CONFIG_INFINIBAND_NES) += nes/ 8obj-$(CONFIG_INFINIBAND_NES) += nes/
diff --git a/drivers/infiniband/hw/i40iw/Kconfig b/drivers/infiniband/hw/i40iw/Kconfig
new file mode 100644
index 000000000000..6e7d27a14061
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/Kconfig
@@ -0,0 +1,7 @@
1config INFINIBAND_I40IW
2 tristate "Intel(R) Ethernet X722 iWARP Driver"
3 depends on INET && I40E
4 select GENERIC_ALLOCATOR
5 ---help---
6 Intel(R) Ethernet X722 iWARP Driver
7 INET && I40IW && INFINIBAND && I40E
diff --git a/drivers/infiniband/hw/i40iw/Makefile b/drivers/infiniband/hw/i40iw/Makefile
new file mode 100644
index 000000000000..90068c03d217
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/Makefile
@@ -0,0 +1,9 @@
1ccflags-y := -Idrivers/net/ethernet/intel/i40e
2
3obj-$(CONFIG_INFINIBAND_I40IW) += i40iw.o
4
5i40iw-objs :=\
6 i40iw_cm.o i40iw_ctrl.o \
7 i40iw_hmc.o i40iw_hw.o i40iw_main.o \
8 i40iw_pble.o i40iw_puda.o i40iw_uk.o i40iw_utils.o \
9 i40iw_verbs.o i40iw_virtchnl.o i40iw_vf.o
diff --git a/drivers/infiniband/hw/i40iw/i40iw.h b/drivers/infiniband/hw/i40iw/i40iw.h
new file mode 100644
index 000000000000..819767681445
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw.h
@@ -0,0 +1,570 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_IW_H
36#define I40IW_IW_H
37#include <linux/netdevice.h>
38#include <linux/inetdevice.h>
39#include <linux/spinlock.h>
40#include <linux/kernel.h>
41#include <linux/delay.h>
42#include <linux/pci.h>
43#include <linux/dma-mapping.h>
44#include <linux/workqueue.h>
45#include <linux/slab.h>
46#include <linux/io.h>
47#include <linux/crc32c.h>
48#include <rdma/ib_smi.h>
49#include <rdma/ib_verbs.h>
50#include <rdma/ib_pack.h>
51#include <rdma/rdma_cm.h>
52#include <rdma/iw_cm.h>
53#include <rdma/iw_portmap.h>
54#include <rdma/rdma_netlink.h>
55#include <crypto/hash.h>
56
57#include "i40iw_status.h"
58#include "i40iw_osdep.h"
59#include "i40iw_d.h"
60#include "i40iw_hmc.h"
61
62#include <i40e_client.h>
63#include "i40iw_type.h"
64#include "i40iw_p.h"
65#include "i40iw_ucontext.h"
66#include "i40iw_pble.h"
67#include "i40iw_verbs.h"
68#include "i40iw_cm.h"
69#include "i40iw_user.h"
70#include "i40iw_puda.h"
71
72#define I40IW_FW_VERSION 2
73#define I40IW_HW_VERSION 2
74
75#define I40IW_ARP_ADD 1
76#define I40IW_ARP_DELETE 2
77#define I40IW_ARP_RESOLVE 3
78
79#define I40IW_MACIP_ADD 1
80#define I40IW_MACIP_DELETE 2
81
82#define IW_CCQ_SIZE (I40IW_CQP_SW_SQSIZE_2048 + 1)
83#define IW_CEQ_SIZE 2048
84#define IW_AEQ_SIZE 2048
85
86#define RX_BUF_SIZE (1536 + 8)
87#define IW_REG0_SIZE (4 * 1024)
88#define IW_TX_TIMEOUT (6 * HZ)
89#define IW_FIRST_QPN 1
90#define IW_SW_CONTEXT_ALIGN 1024
91
92#define MAX_DPC_ITERATIONS 128
93
94#define I40IW_EVENT_TIMEOUT 100000
95#define I40IW_VCHNL_EVENT_TIMEOUT 100000
96
97#define I40IW_NO_VLAN 0xffff
98#define I40IW_NO_QSET 0xffff
99
100/* access to mcast filter list */
101#define IW_ADD_MCAST false
102#define IW_DEL_MCAST true
103
104#define I40IW_DRV_OPT_ENABLE_MPA_VER_0 0x00000001
105#define I40IW_DRV_OPT_DISABLE_MPA_CRC 0x00000002
106#define I40IW_DRV_OPT_DISABLE_FIRST_WRITE 0x00000004
107#define I40IW_DRV_OPT_DISABLE_INTF 0x00000008
108#define I40IW_DRV_OPT_ENABLE_MSI 0x00000010
109#define I40IW_DRV_OPT_DUAL_LOGICAL_PORT 0x00000020
110#define I40IW_DRV_OPT_NO_INLINE_DATA 0x00000080
111#define I40IW_DRV_OPT_DISABLE_INT_MOD 0x00000100
112#define I40IW_DRV_OPT_DISABLE_VIRT_WQ 0x00000200
113#define I40IW_DRV_OPT_ENABLE_PAU 0x00000400
114#define I40IW_DRV_OPT_MCAST_LOGPORT_MAP 0x00000800
115
116#define IW_HMC_OBJ_TYPE_NUM ARRAY_SIZE(iw_hmc_obj_types)
117#define IW_CFG_FPM_QP_COUNT 32768
118
119#define I40IW_MTU_TO_MSS 40
120#define I40IW_DEFAULT_MSS 1460
121
122struct i40iw_cqp_compl_info {
123 u32 op_ret_val;
124 u16 maj_err_code;
125 u16 min_err_code;
126 bool error;
127 u8 op_code;
128};
129
130#define i40iw_pr_err(fmt, args ...) pr_err("%s: "fmt, __func__, ## args)
131
132#define i40iw_pr_info(fmt, args ...) pr_info("%s: " fmt, __func__, ## args)
133
134#define i40iw_pr_warn(fmt, args ...) pr_warn("%s: " fmt, __func__, ## args)
135
136struct i40iw_cqp_request {
137 struct cqp_commands_info info;
138 wait_queue_head_t waitq;
139 struct list_head list;
140 atomic_t refcount;
141 void (*callback_fcn)(struct i40iw_cqp_request*, u32);
142 void *param;
143 struct i40iw_cqp_compl_info compl_info;
144 bool waiting;
145 bool request_done;
146 bool dynamic;
147};
148
149struct i40iw_cqp {
150 struct i40iw_sc_cqp sc_cqp;
151 spinlock_t req_lock; /*cqp request list */
152 wait_queue_head_t waitq;
153 struct i40iw_dma_mem sq;
154 struct i40iw_dma_mem host_ctx;
155 u64 *scratch_array;
156 struct i40iw_cqp_request *cqp_requests;
157 struct list_head cqp_avail_reqs;
158 struct list_head cqp_pending_reqs;
159};
160
161struct i40iw_device;
162
163struct i40iw_ccq {
164 struct i40iw_sc_cq sc_cq;
165 spinlock_t lock; /* ccq control */
166 wait_queue_head_t waitq;
167 struct i40iw_dma_mem mem_cq;
168 struct i40iw_dma_mem shadow_area;
169};
170
171struct i40iw_ceq {
172 struct i40iw_sc_ceq sc_ceq;
173 struct i40iw_dma_mem mem;
174 u32 irq;
175 u32 msix_idx;
176 struct i40iw_device *iwdev;
177 struct tasklet_struct dpc_tasklet;
178};
179
180struct i40iw_aeq {
181 struct i40iw_sc_aeq sc_aeq;
182 struct i40iw_dma_mem mem;
183};
184
185struct i40iw_arp_entry {
186 u32 ip_addr[4];
187 u8 mac_addr[ETH_ALEN];
188};
189
190enum init_completion_state {
191 INVALID_STATE = 0,
192 INITIAL_STATE,
193 CQP_CREATED,
194 HMC_OBJS_CREATED,
195 PBLE_CHUNK_MEM,
196 CCQ_CREATED,
197 AEQ_CREATED,
198 CEQ_CREATED,
199 ILQ_CREATED,
200 IEQ_CREATED,
201 INET_NOTIFIER,
202 IP_ADDR_REGISTERED,
203 RDMA_DEV_REGISTERED
204};
205
206struct i40iw_msix_vector {
207 u32 idx;
208 u32 irq;
209 u32 cpu_affinity;
210 u32 ceq_id;
211};
212
213#define I40IW_MSIX_TABLE_SIZE 65
214
215struct virtchnl_work {
216 struct work_struct work;
217 union {
218 struct i40iw_cqp_request *cqp_request;
219 struct i40iw_virtchnl_work_info work_info;
220 };
221};
222
223struct i40e_qvlist_info;
224
225struct i40iw_device {
226 struct i40iw_ib_device *iwibdev;
227 struct net_device *netdev;
228 wait_queue_head_t vchnl_waitq;
229 struct i40iw_sc_dev sc_dev;
230 struct i40iw_handler *hdl;
231 struct i40e_info *ldev;
232 struct i40e_client *client;
233 struct i40iw_hw hw;
234 struct i40iw_cm_core cm_core;
235 unsigned long *mem_resources;
236 unsigned long *allocated_qps;
237 unsigned long *allocated_cqs;
238 unsigned long *allocated_mrs;
239 unsigned long *allocated_pds;
240 unsigned long *allocated_arps;
241 struct i40iw_qp **qp_table;
242 bool msix_shared;
243 u32 msix_count;
244 struct i40iw_msix_vector *iw_msixtbl;
245 struct i40e_qvlist_info *iw_qvlist;
246
247 struct i40iw_hmc_pble_rsrc *pble_rsrc;
248 struct i40iw_arp_entry *arp_table;
249 struct i40iw_cqp cqp;
250 struct i40iw_ccq ccq;
251 u32 ceqs_count;
252 struct i40iw_ceq *ceqlist;
253 struct i40iw_aeq aeq;
254 u32 arp_table_size;
255 u32 next_arp_index;
256 spinlock_t resource_lock; /* hw resource access */
257 u32 vendor_id;
258 u32 vendor_part_id;
259 u32 of_device_registered;
260
261 u32 device_cap_flags;
262 unsigned long db_start;
263 u8 resource_profile;
264 u8 max_rdma_vfs;
265 u8 max_enabled_vfs;
266 u8 max_sge;
267 u8 iw_status;
268 u8 send_term_ok;
269 bool push_mode; /* Initialized from parameter passed to driver */
270
271 /* x710 specific */
272 struct mutex pbl_mutex;
273 struct tasklet_struct dpc_tasklet;
274 struct workqueue_struct *virtchnl_wq;
275 struct virtchnl_work virtchnl_w[I40IW_MAX_PE_ENABLED_VF_COUNT];
276 struct i40iw_dma_mem obj_mem;
277 struct i40iw_dma_mem obj_next;
278 u8 *hmc_info_mem;
279 u32 sd_type;
280 struct workqueue_struct *param_wq;
281 atomic_t params_busy;
282 u32 mss;
283 enum init_completion_state init_state;
284 u16 mac_ip_table_idx;
285 atomic_t vchnl_msgs;
286 u32 max_mr;
287 u32 max_qp;
288 u32 max_cq;
289 u32 max_pd;
290 u32 next_qp;
291 u32 next_cq;
292 u32 next_pd;
293 u32 max_mr_size;
294 u32 max_qp_wr;
295 u32 max_cqe;
296 u32 mr_stagmask;
297 u32 mpa_version;
298 bool dcb;
299};
300
301struct i40iw_ib_device {
302 struct ib_device ibdev;
303 struct i40iw_device *iwdev;
304};
305
306struct i40iw_handler {
307 struct list_head list;
308 struct i40e_client *client;
309 struct i40iw_device device;
310 struct i40e_info ldev;
311};
312
313/**
314 * to_iwdev - get device
315 * @ibdev: ib device
316 **/
317static inline struct i40iw_device *to_iwdev(struct ib_device *ibdev)
318{
319 return container_of(ibdev, struct i40iw_ib_device, ibdev)->iwdev;
320}
321
322/**
323 * to_ucontext - get user context
324 * @ibucontext: ib user context
325 **/
326static inline struct i40iw_ucontext *to_ucontext(struct ib_ucontext *ibucontext)
327{
328 return container_of(ibucontext, struct i40iw_ucontext, ibucontext);
329}
330
331/**
332 * to_iwpd - get protection domain
333 * @ibpd: ib pd
334 **/
335static inline struct i40iw_pd *to_iwpd(struct ib_pd *ibpd)
336{
337 return container_of(ibpd, struct i40iw_pd, ibpd);
338}
339
340/**
341 * to_iwmr - get device memory region
342 * @ibdev: ib memory region
343 **/
344static inline struct i40iw_mr *to_iwmr(struct ib_mr *ibmr)
345{
346 return container_of(ibmr, struct i40iw_mr, ibmr);
347}
348
349/**
350 * to_iwmr_from_ibfmr - get device memory region
351 * @ibfmr: ib fmr
352 **/
353static inline struct i40iw_mr *to_iwmr_from_ibfmr(struct ib_fmr *ibfmr)
354{
355 return container_of(ibfmr, struct i40iw_mr, ibfmr);
356}
357
358/**
359 * to_iwmw - get device memory window
360 * @ibmw: ib memory window
361 **/
362static inline struct i40iw_mr *to_iwmw(struct ib_mw *ibmw)
363{
364 return container_of(ibmw, struct i40iw_mr, ibmw);
365}
366
367/**
368 * to_iwcq - get completion queue
369 * @ibcq: ib cqdevice
370 **/
371static inline struct i40iw_cq *to_iwcq(struct ib_cq *ibcq)
372{
373 return container_of(ibcq, struct i40iw_cq, ibcq);
374}
375
376/**
377 * to_iwqp - get device qp
378 * @ibqp: ib qp
379 **/
380static inline struct i40iw_qp *to_iwqp(struct ib_qp *ibqp)
381{
382 return container_of(ibqp, struct i40iw_qp, ibqp);
383}
384
385/* i40iw.c */
386void i40iw_add_ref(struct ib_qp *);
387void i40iw_rem_ref(struct ib_qp *);
388struct ib_qp *i40iw_get_qp(struct ib_device *, int);
389
390void i40iw_flush_wqes(struct i40iw_device *iwdev,
391 struct i40iw_qp *qp);
392
393void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
394 unsigned char *mac_addr,
395 __be32 *ip_addr,
396 bool ipv4,
397 u32 action);
398
399int i40iw_manage_apbvt(struct i40iw_device *iwdev,
400 u16 accel_local_port,
401 bool add_port);
402
403struct i40iw_cqp_request *i40iw_get_cqp_request(struct i40iw_cqp *cqp, bool wait);
404void i40iw_free_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
405void i40iw_put_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
406
407/**
408 * i40iw_alloc_resource - allocate a resource
409 * @iwdev: device pointer
410 * @resource_array: resource bit array:
411 * @max_resources: maximum resource number
412 * @req_resources_num: Allocated resource number
413 * @next: next free id
414 **/
415static inline int i40iw_alloc_resource(struct i40iw_device *iwdev,
416 unsigned long *resource_array,
417 u32 max_resources,
418 u32 *req_resource_num,
419 u32 *next)
420{
421 u32 resource_num;
422 unsigned long flags;
423
424 spin_lock_irqsave(&iwdev->resource_lock, flags);
425 resource_num = find_next_zero_bit(resource_array, max_resources, *next);
426 if (resource_num >= max_resources) {
427 resource_num = find_first_zero_bit(resource_array, max_resources);
428 if (resource_num >= max_resources) {
429 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
430 return -EOVERFLOW;
431 }
432 }
433 set_bit(resource_num, resource_array);
434 *next = resource_num + 1;
435 if (*next == max_resources)
436 *next = 0;
437 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
438 *req_resource_num = resource_num;
439
440 return 0;
441}
442
443/**
444 * i40iw_is_resource_allocated - detrmine if resource is
445 * allocated
446 * @iwdev: device pointer
447 * @resource_array: resource array for the resource_num
448 * @resource_num: resource number to check
449 **/
450static inline bool i40iw_is_resource_allocated(struct i40iw_device *iwdev,
451 unsigned long *resource_array,
452 u32 resource_num)
453{
454 bool bit_is_set;
455 unsigned long flags;
456
457 spin_lock_irqsave(&iwdev->resource_lock, flags);
458
459 bit_is_set = test_bit(resource_num, resource_array);
460 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
461
462 return bit_is_set;
463}
464
465/**
466 * i40iw_free_resource - free a resource
467 * @iwdev: device pointer
468 * @resource_array: resource array for the resource_num
469 * @resource_num: resource number to free
470 **/
471static inline void i40iw_free_resource(struct i40iw_device *iwdev,
472 unsigned long *resource_array,
473 u32 resource_num)
474{
475 unsigned long flags;
476
477 spin_lock_irqsave(&iwdev->resource_lock, flags);
478 clear_bit(resource_num, resource_array);
479 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
480}
481
482/**
483 * to_iwhdl - Get the handler from the device pointer
484 * @iwdev: device pointer
485 **/
486static inline struct i40iw_handler *to_iwhdl(struct i40iw_device *iw_dev)
487{
488 return container_of(iw_dev, struct i40iw_handler, device);
489}
490
491struct i40iw_handler *i40iw_find_netdev(struct net_device *netdev);
492
493/**
494 * iw_init_resources -
495 */
496u32 i40iw_initialize_hw_resources(struct i40iw_device *iwdev);
497
498int i40iw_register_rdma_device(struct i40iw_device *iwdev);
499void i40iw_port_ibevent(struct i40iw_device *iwdev);
500int i40iw_cm_disconn(struct i40iw_qp *);
501void i40iw_cm_disconn_worker(void *);
502int mini_cm_recv_pkt(struct i40iw_cm_core *, struct i40iw_device *,
503 struct sk_buff *);
504
505enum i40iw_status_code i40iw_handle_cqp_op(struct i40iw_device *iwdev,
506 struct i40iw_cqp_request *cqp_request);
507enum i40iw_status_code i40iw_add_mac_addr(struct i40iw_device *iwdev,
508 u8 *mac_addr, u8 *mac_index);
509int i40iw_modify_qp(struct ib_qp *, struct ib_qp_attr *, int, struct ib_udata *);
510
511void i40iw_rem_pdusecount(struct i40iw_pd *iwpd, struct i40iw_device *iwdev);
512void i40iw_add_pdusecount(struct i40iw_pd *iwpd);
513void i40iw_hw_modify_qp(struct i40iw_device *iwdev, struct i40iw_qp *iwqp,
514 struct i40iw_modify_qp_info *info, bool wait);
515
516enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
517 struct i40iw_cm_info *cminfo,
518 enum i40iw_quad_entry_type etype,
519 enum i40iw_quad_hash_manage_type mtype,
520 void *cmnode,
521 bool wait);
522void i40iw_receive_ilq(struct i40iw_sc_dev *dev, struct i40iw_puda_buf *rbuf);
523void i40iw_free_sqbuf(struct i40iw_sc_dev *dev, void *bufp);
524void i40iw_free_qp_resources(struct i40iw_device *iwdev,
525 struct i40iw_qp *iwqp,
526 u32 qp_num);
527enum i40iw_status_code i40iw_obj_aligned_mem(struct i40iw_device *iwdev,
528 struct i40iw_dma_mem *memptr,
529 u32 size, u32 mask);
530
531void i40iw_request_reset(struct i40iw_device *iwdev);
532void i40iw_destroy_rdma_device(struct i40iw_ib_device *iwibdev);
533void i40iw_setup_cm_core(struct i40iw_device *iwdev);
534void i40iw_cleanup_cm_core(struct i40iw_cm_core *cm_core);
535void i40iw_process_ceq(struct i40iw_device *, struct i40iw_ceq *iwceq);
536void i40iw_process_aeq(struct i40iw_device *);
537void i40iw_next_iw_state(struct i40iw_qp *iwqp,
538 u8 state, u8 del_hash,
539 u8 term, u8 term_len);
540int i40iw_send_syn(struct i40iw_cm_node *cm_node, u32 sendack);
541struct i40iw_cm_node *i40iw_find_node(struct i40iw_cm_core *cm_core,
542 u16 rem_port,
543 u32 *rem_addr,
544 u16 loc_port,
545 u32 *loc_addr,
546 bool add_refcnt);
547
548enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
549 struct i40iw_sc_qp *qp,
550 struct i40iw_qp_flush_info *info,
551 bool wait);
552
553void i40iw_copy_ip_ntohl(u32 *dst, u32 *src);
554struct ib_mr *i40iw_reg_phys_mr(struct ib_pd *ib_pd,
555 u64 addr,
556 u64 size,
557 int acc,
558 u64 *iova_start);
559
560int i40iw_inetaddr_event(struct notifier_block *notifier,
561 unsigned long event,
562 void *ptr);
563int i40iw_inet6addr_event(struct notifier_block *notifier,
564 unsigned long event,
565 void *ptr);
566int i40iw_net_event(struct notifier_block *notifier,
567 unsigned long event,
568 void *ptr);
569
570#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c b/drivers/infiniband/hw/i40iw/i40iw_cm.c
new file mode 100644
index 000000000000..92745d755272
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c
@@ -0,0 +1,4141 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include <linux/atomic.h>
36#include <linux/ip.h>
37#include <linux/tcp.h>
38#include <linux/init.h>
39#include <linux/if_arp.h>
40#include <linux/if_vlan.h>
41#include <linux/notifier.h>
42#include <linux/net.h>
43#include <linux/types.h>
44#include <linux/timer.h>
45#include <linux/time.h>
46#include <linux/delay.h>
47#include <linux/etherdevice.h>
48#include <linux/netdevice.h>
49#include <linux/random.h>
50#include <linux/list.h>
51#include <linux/threads.h>
52#include <linux/highmem.h>
53#include <net/arp.h>
54#include <net/ndisc.h>
55#include <net/neighbour.h>
56#include <net/route.h>
57#include <net/addrconf.h>
58#include <net/ip6_route.h>
59#include <net/ip_fib.h>
60#include <net/tcp.h>
61#include <asm/checksum.h>
62
63#include "i40iw.h"
64
65static void i40iw_rem_ref_cm_node(struct i40iw_cm_node *);
66static void i40iw_cm_post_event(struct i40iw_cm_event *event);
67static void i40iw_disconnect_worker(struct work_struct *work);
68
69/**
70 * i40iw_free_sqbuf - put back puda buffer if refcount = 0
71 * @dev: FPK device
72 * @buf: puda buffer to free
73 */
74void i40iw_free_sqbuf(struct i40iw_sc_dev *dev, void *bufp)
75{
76 struct i40iw_puda_buf *buf = (struct i40iw_puda_buf *)bufp;
77 struct i40iw_puda_rsrc *ilq = dev->ilq;
78
79 if (!atomic_dec_return(&buf->refcount))
80 i40iw_puda_ret_bufpool(ilq, buf);
81}
82
83/**
84 * i40iw_derive_hw_ird_setting - Calculate IRD
85 *
86 * @cm_ird: IRD of connection's node
87 *
88 * The ird from the connection is rounded to a supported HW
89 * setting (2,8,32,64) and then encoded for ird_size field of
90 * qp_ctx
91 */
92static u8 i40iw_derive_hw_ird_setting(u16 cm_ird)
93{
94 u8 encoded_ird_size;
95 u8 pof2_cm_ird = 1;
96
97 /* round-off to next powerof2 */
98 while (pof2_cm_ird < cm_ird)
99 pof2_cm_ird *= 2;
100
101 /* ird_size field is encoded in qp_ctx */
102 switch (pof2_cm_ird) {
103 case I40IW_HW_IRD_SETTING_64:
104 encoded_ird_size = 3;
105 break;
106 case I40IW_HW_IRD_SETTING_32:
107 case I40IW_HW_IRD_SETTING_16:
108 encoded_ird_size = 2;
109 break;
110 case I40IW_HW_IRD_SETTING_8:
111 case I40IW_HW_IRD_SETTING_4:
112 encoded_ird_size = 1;
113 break;
114 case I40IW_HW_IRD_SETTING_2:
115 default:
116 encoded_ird_size = 0;
117 break;
118 }
119 return encoded_ird_size;
120}
121
122/**
123 * i40iw_record_ird_ord - Record IRD/ORD passed in
124 * @cm_node: connection's node
125 * @conn_ird: connection IRD
126 * @conn_ord: connection ORD
127 */
128static void i40iw_record_ird_ord(struct i40iw_cm_node *cm_node, u16 conn_ird, u16 conn_ord)
129{
130 if (conn_ird > I40IW_MAX_IRD_SIZE)
131 conn_ird = I40IW_MAX_IRD_SIZE;
132
133 if (conn_ord > I40IW_MAX_ORD_SIZE)
134 conn_ord = I40IW_MAX_ORD_SIZE;
135
136 cm_node->ird_size = conn_ird;
137 cm_node->ord_size = conn_ord;
138}
139
140/**
141 * i40iw_copy_ip_ntohl - change network to host ip
142 * @dst: host ip
143 * @src: big endian
144 */
145void i40iw_copy_ip_ntohl(u32 *dst, __be32 *src)
146{
147 *dst++ = ntohl(*src++);
148 *dst++ = ntohl(*src++);
149 *dst++ = ntohl(*src++);
150 *dst = ntohl(*src);
151}
152
153/**
154 * i40iw_copy_ip_htonl - change host addr to network ip
155 * @dst: host ip
156 * @src: little endian
157 */
158static inline void i40iw_copy_ip_htonl(__be32 *dst, u32 *src)
159{
160 *dst++ = htonl(*src++);
161 *dst++ = htonl(*src++);
162 *dst++ = htonl(*src++);
163 *dst = htonl(*src);
164}
165
166/**
167 * i40iw_fill_sockaddr4 - get addr info for passive connection
168 * @cm_node: connection's node
169 * @event: upper layer's cm event
170 */
171static inline void i40iw_fill_sockaddr4(struct i40iw_cm_node *cm_node,
172 struct iw_cm_event *event)
173{
174 struct sockaddr_in *laddr = (struct sockaddr_in *)&event->local_addr;
175 struct sockaddr_in *raddr = (struct sockaddr_in *)&event->remote_addr;
176
177 laddr->sin_family = AF_INET;
178 raddr->sin_family = AF_INET;
179
180 laddr->sin_port = htons(cm_node->loc_port);
181 raddr->sin_port = htons(cm_node->rem_port);
182
183 laddr->sin_addr.s_addr = htonl(cm_node->loc_addr[0]);
184 raddr->sin_addr.s_addr = htonl(cm_node->rem_addr[0]);
185}
186
187/**
188 * i40iw_fill_sockaddr6 - get ipv6 addr info for passive side
189 * @cm_node: connection's node
190 * @event: upper layer's cm event
191 */
192static inline void i40iw_fill_sockaddr6(struct i40iw_cm_node *cm_node,
193 struct iw_cm_event *event)
194{
195 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&event->local_addr;
196 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)&event->remote_addr;
197
198 laddr6->sin6_family = AF_INET6;
199 raddr6->sin6_family = AF_INET6;
200
201 laddr6->sin6_port = htons(cm_node->loc_port);
202 raddr6->sin6_port = htons(cm_node->rem_port);
203
204 i40iw_copy_ip_htonl(laddr6->sin6_addr.in6_u.u6_addr32,
205 cm_node->loc_addr);
206 i40iw_copy_ip_htonl(raddr6->sin6_addr.in6_u.u6_addr32,
207 cm_node->rem_addr);
208}
209
210/**
211 * i40iw_get_addr_info
212 * @cm_node: contains ip/tcp info
213 * @cm_info: to get a copy of the cm_node ip/tcp info
214*/
215static void i40iw_get_addr_info(struct i40iw_cm_node *cm_node,
216 struct i40iw_cm_info *cm_info)
217{
218 cm_info->ipv4 = cm_node->ipv4;
219 cm_info->vlan_id = cm_node->vlan_id;
220 memcpy(cm_info->loc_addr, cm_node->loc_addr, sizeof(cm_info->loc_addr));
221 memcpy(cm_info->rem_addr, cm_node->rem_addr, sizeof(cm_info->rem_addr));
222 cm_info->loc_port = cm_node->loc_port;
223 cm_info->rem_port = cm_node->rem_port;
224}
225
226/**
227 * i40iw_get_cmevent_info - for cm event upcall
228 * @cm_node: connection's node
229 * @cm_id: upper layers cm struct for the event
230 * @event: upper layer's cm event
231 */
232static inline void i40iw_get_cmevent_info(struct i40iw_cm_node *cm_node,
233 struct iw_cm_id *cm_id,
234 struct iw_cm_event *event)
235{
236 memcpy(&event->local_addr, &cm_id->m_local_addr,
237 sizeof(event->local_addr));
238 memcpy(&event->remote_addr, &cm_id->m_remote_addr,
239 sizeof(event->remote_addr));
240 if (cm_node) {
241 event->private_data = (void *)cm_node->pdata_buf;
242 event->private_data_len = (u8)cm_node->pdata.size;
243 event->ird = cm_node->ird_size;
244 event->ord = cm_node->ord_size;
245 }
246}
247
248/**
249 * i40iw_send_cm_event - upcall cm's event handler
250 * @cm_node: connection's node
251 * @cm_id: upper layer's cm info struct
252 * @type: Event type to indicate
253 * @status: status for the event type
254 */
255static int i40iw_send_cm_event(struct i40iw_cm_node *cm_node,
256 struct iw_cm_id *cm_id,
257 enum iw_cm_event_type type,
258 int status)
259{
260 struct iw_cm_event event;
261
262 memset(&event, 0, sizeof(event));
263 event.event = type;
264 event.status = status;
265 switch (type) {
266 case IW_CM_EVENT_CONNECT_REQUEST:
267 if (cm_node->ipv4)
268 i40iw_fill_sockaddr4(cm_node, &event);
269 else
270 i40iw_fill_sockaddr6(cm_node, &event);
271 event.provider_data = (void *)cm_node;
272 event.private_data = (void *)cm_node->pdata_buf;
273 event.private_data_len = (u8)cm_node->pdata.size;
274 break;
275 case IW_CM_EVENT_CONNECT_REPLY:
276 i40iw_get_cmevent_info(cm_node, cm_id, &event);
277 break;
278 case IW_CM_EVENT_ESTABLISHED:
279 event.ird = cm_node->ird_size;
280 event.ord = cm_node->ord_size;
281 break;
282 case IW_CM_EVENT_DISCONNECT:
283 break;
284 case IW_CM_EVENT_CLOSE:
285 break;
286 default:
287 i40iw_pr_err("event type received type = %d\n", type);
288 return -1;
289 }
290 return cm_id->event_handler(cm_id, &event);
291}
292
293/**
294 * i40iw_create_event - create cm event
295 * @cm_node: connection's node
296 * @type: Event type to generate
297 */
298static struct i40iw_cm_event *i40iw_create_event(struct i40iw_cm_node *cm_node,
299 enum i40iw_cm_event_type type)
300{
301 struct i40iw_cm_event *event;
302
303 if (!cm_node->cm_id)
304 return NULL;
305
306 event = kzalloc(sizeof(*event), GFP_ATOMIC);
307
308 if (!event)
309 return NULL;
310
311 event->type = type;
312 event->cm_node = cm_node;
313 memcpy(event->cm_info.rem_addr, cm_node->rem_addr, sizeof(event->cm_info.rem_addr));
314 memcpy(event->cm_info.loc_addr, cm_node->loc_addr, sizeof(event->cm_info.loc_addr));
315 event->cm_info.rem_port = cm_node->rem_port;
316 event->cm_info.loc_port = cm_node->loc_port;
317 event->cm_info.cm_id = cm_node->cm_id;
318
319 i40iw_debug(cm_node->dev,
320 I40IW_DEBUG_CM,
321 "node=%p event=%p type=%u dst=%pI4 src=%pI4\n",
322 cm_node,
323 event,
324 type,
325 event->cm_info.loc_addr,
326 event->cm_info.rem_addr);
327
328 i40iw_cm_post_event(event);
329 return event;
330}
331
332/**
333 * i40iw_free_retrans_entry - free send entry
334 * @cm_node: connection's node
335 */
336static void i40iw_free_retrans_entry(struct i40iw_cm_node *cm_node)
337{
338 struct i40iw_sc_dev *dev = cm_node->dev;
339 struct i40iw_timer_entry *send_entry;
340
341 send_entry = cm_node->send_entry;
342 if (send_entry) {
343 cm_node->send_entry = NULL;
344 i40iw_free_sqbuf(dev, (void *)send_entry->sqbuf);
345 kfree(send_entry);
346 atomic_dec(&cm_node->ref_count);
347 }
348}
349
350/**
351 * i40iw_cleanup_retrans_entry - free send entry with lock
352 * @cm_node: connection's node
353 */
354static void i40iw_cleanup_retrans_entry(struct i40iw_cm_node *cm_node)
355{
356 unsigned long flags;
357
358 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
359 i40iw_free_retrans_entry(cm_node);
360 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
361}
362
363static bool is_remote_ne020_or_chelsio(struct i40iw_cm_node *cm_node)
364{
365 if ((cm_node->rem_mac[0] == 0x0) &&
366 (((cm_node->rem_mac[1] == 0x12) && (cm_node->rem_mac[2] == 0x55)) ||
367 ((cm_node->rem_mac[1] == 0x07 && (cm_node->rem_mac[2] == 0x43)))))
368 return true;
369 return false;
370}
371
372/**
373 * i40iw_form_cm_frame - get a free packet and build frame
374 * @cm_node: connection's node ionfo to use in frame
375 * @options: pointer to options info
376 * @hdr: pointer mpa header
377 * @pdata: pointer to private data
378 * @flags: indicates FIN or ACK
379 */
380static struct i40iw_puda_buf *i40iw_form_cm_frame(struct i40iw_cm_node *cm_node,
381 struct i40iw_kmem_info *options,
382 struct i40iw_kmem_info *hdr,
383 struct i40iw_kmem_info *pdata,
384 u8 flags)
385{
386 struct i40iw_puda_buf *sqbuf;
387 struct i40iw_sc_dev *dev = cm_node->dev;
388 u8 *buf;
389
390 struct tcphdr *tcph;
391 struct iphdr *iph;
392 struct ipv6hdr *ip6h;
393 struct ethhdr *ethh;
394 u16 packetsize;
395 u16 eth_hlen = ETH_HLEN;
396 u32 opts_len = 0;
397 u32 pd_len = 0;
398 u32 hdr_len = 0;
399
400 sqbuf = i40iw_puda_get_bufpool(dev->ilq);
401 if (!sqbuf)
402 return NULL;
403 buf = sqbuf->mem.va;
404
405 if (options)
406 opts_len = (u32)options->size;
407
408 if (hdr)
409 hdr_len = hdr->size;
410
411 if (pdata) {
412 pd_len = pdata->size;
413 if (!is_remote_ne020_or_chelsio(cm_node))
414 pd_len += MPA_ZERO_PAD_LEN;
415 }
416
417 if (cm_node->vlan_id < VLAN_TAG_PRESENT)
418 eth_hlen += 4;
419
420 if (cm_node->ipv4)
421 packetsize = sizeof(*iph) + sizeof(*tcph);
422 else
423 packetsize = sizeof(*ip6h) + sizeof(*tcph);
424 packetsize += opts_len + hdr_len + pd_len;
425
426 memset(buf, 0x00, eth_hlen + packetsize);
427
428 sqbuf->totallen = packetsize + eth_hlen;
429 sqbuf->maclen = eth_hlen;
430 sqbuf->tcphlen = sizeof(*tcph) + opts_len;
431 sqbuf->scratch = (void *)cm_node;
432
433 ethh = (struct ethhdr *)buf;
434 buf += eth_hlen;
435
436 if (cm_node->ipv4) {
437 sqbuf->ipv4 = true;
438
439 iph = (struct iphdr *)buf;
440 buf += sizeof(*iph);
441 tcph = (struct tcphdr *)buf;
442 buf += sizeof(*tcph);
443
444 ether_addr_copy(ethh->h_dest, cm_node->rem_mac);
445 ether_addr_copy(ethh->h_source, cm_node->loc_mac);
446 if (cm_node->vlan_id < VLAN_TAG_PRESENT) {
447 ((struct vlan_ethhdr *)ethh)->h_vlan_proto = htons(ETH_P_8021Q);
448 ((struct vlan_ethhdr *)ethh)->h_vlan_TCI = htons(cm_node->vlan_id);
449
450 ((struct vlan_ethhdr *)ethh)->h_vlan_encapsulated_proto = htons(ETH_P_IP);
451 } else {
452 ethh->h_proto = htons(ETH_P_IP);
453 }
454
455 iph->version = IPVERSION;
456 iph->ihl = 5; /* 5 * 4Byte words, IP headr len */
457 iph->tos = 0;
458 iph->tot_len = htons(packetsize);
459 iph->id = htons(++cm_node->tcp_cntxt.loc_id);
460
461 iph->frag_off = htons(0x4000);
462 iph->ttl = 0x40;
463 iph->protocol = IPPROTO_TCP;
464 iph->saddr = htonl(cm_node->loc_addr[0]);
465 iph->daddr = htonl(cm_node->rem_addr[0]);
466 } else {
467 sqbuf->ipv4 = false;
468 ip6h = (struct ipv6hdr *)buf;
469 buf += sizeof(*ip6h);
470 tcph = (struct tcphdr *)buf;
471 buf += sizeof(*tcph);
472
473 ether_addr_copy(ethh->h_dest, cm_node->rem_mac);
474 ether_addr_copy(ethh->h_source, cm_node->loc_mac);
475 if (cm_node->vlan_id < VLAN_TAG_PRESENT) {
476 ((struct vlan_ethhdr *)ethh)->h_vlan_proto = htons(ETH_P_8021Q);
477 ((struct vlan_ethhdr *)ethh)->h_vlan_TCI = htons(cm_node->vlan_id);
478 ((struct vlan_ethhdr *)ethh)->h_vlan_encapsulated_proto = htons(ETH_P_IPV6);
479 } else {
480 ethh->h_proto = htons(ETH_P_IPV6);
481 }
482 ip6h->version = 6;
483 ip6h->flow_lbl[0] = 0;
484 ip6h->flow_lbl[1] = 0;
485 ip6h->flow_lbl[2] = 0;
486 ip6h->payload_len = htons(packetsize - sizeof(*ip6h));
487 ip6h->nexthdr = 6;
488 ip6h->hop_limit = 128;
489 i40iw_copy_ip_htonl(ip6h->saddr.in6_u.u6_addr32,
490 cm_node->loc_addr);
491 i40iw_copy_ip_htonl(ip6h->daddr.in6_u.u6_addr32,
492 cm_node->rem_addr);
493 }
494
495 tcph->source = htons(cm_node->loc_port);
496 tcph->dest = htons(cm_node->rem_port);
497
498 tcph->seq = htonl(cm_node->tcp_cntxt.loc_seq_num);
499
500 if (flags & SET_ACK) {
501 cm_node->tcp_cntxt.loc_ack_num = cm_node->tcp_cntxt.rcv_nxt;
502 tcph->ack_seq = htonl(cm_node->tcp_cntxt.loc_ack_num);
503 tcph->ack = 1;
504 } else {
505 tcph->ack_seq = 0;
506 }
507
508 if (flags & SET_SYN) {
509 cm_node->tcp_cntxt.loc_seq_num++;
510 tcph->syn = 1;
511 } else {
512 cm_node->tcp_cntxt.loc_seq_num += hdr_len + pd_len;
513 }
514
515 if (flags & SET_FIN) {
516 cm_node->tcp_cntxt.loc_seq_num++;
517 tcph->fin = 1;
518 }
519
520 if (flags & SET_RST)
521 tcph->rst = 1;
522
523 tcph->doff = (u16)((sizeof(*tcph) + opts_len + 3) >> 2);
524 sqbuf->tcphlen = tcph->doff << 2;
525 tcph->window = htons(cm_node->tcp_cntxt.rcv_wnd);
526 tcph->urg_ptr = 0;
527
528 if (opts_len) {
529 memcpy(buf, options->addr, opts_len);
530 buf += opts_len;
531 }
532
533 if (hdr_len) {
534 memcpy(buf, hdr->addr, hdr_len);
535 buf += hdr_len;
536 }
537
538 if (pd_len)
539 memcpy(buf, pdata->addr, pd_len);
540
541 atomic_set(&sqbuf->refcount, 1);
542
543 return sqbuf;
544}
545
546/**
547 * i40iw_send_reset - Send RST packet
548 * @cm_node: connection's node
549 */
550static int i40iw_send_reset(struct i40iw_cm_node *cm_node)
551{
552 struct i40iw_puda_buf *sqbuf;
553 int flags = SET_RST | SET_ACK;
554
555 sqbuf = i40iw_form_cm_frame(cm_node, NULL, NULL, NULL, flags);
556 if (!sqbuf) {
557 i40iw_pr_err("no sqbuf\n");
558 return -1;
559 }
560
561 return i40iw_schedule_cm_timer(cm_node, sqbuf, I40IW_TIMER_TYPE_SEND, 0, 1);
562}
563
564/**
565 * i40iw_active_open_err - send event for active side cm error
566 * @cm_node: connection's node
567 * @reset: Flag to send reset or not
568 */
569static void i40iw_active_open_err(struct i40iw_cm_node *cm_node, bool reset)
570{
571 i40iw_cleanup_retrans_entry(cm_node);
572 cm_node->cm_core->stats_connect_errs++;
573 if (reset) {
574 i40iw_debug(cm_node->dev,
575 I40IW_DEBUG_CM,
576 "%s cm_node=%p state=%d\n",
577 __func__,
578 cm_node,
579 cm_node->state);
580 atomic_inc(&cm_node->ref_count);
581 i40iw_send_reset(cm_node);
582 }
583
584 cm_node->state = I40IW_CM_STATE_CLOSED;
585 i40iw_create_event(cm_node, I40IW_CM_EVENT_ABORTED);
586}
587
588/**
589 * i40iw_passive_open_err - handle passive side cm error
590 * @cm_node: connection's node
591 * @reset: send reset or just free cm_node
592 */
593static void i40iw_passive_open_err(struct i40iw_cm_node *cm_node, bool reset)
594{
595 i40iw_cleanup_retrans_entry(cm_node);
596 cm_node->cm_core->stats_passive_errs++;
597 cm_node->state = I40IW_CM_STATE_CLOSED;
598 i40iw_debug(cm_node->dev,
599 I40IW_DEBUG_CM,
600 "%s cm_node=%p state =%d\n",
601 __func__,
602 cm_node,
603 cm_node->state);
604 if (reset)
605 i40iw_send_reset(cm_node);
606 else
607 i40iw_rem_ref_cm_node(cm_node);
608}
609
610/**
611 * i40iw_event_connect_error - to create connect error event
612 * @event: cm information for connect event
613 */
614static void i40iw_event_connect_error(struct i40iw_cm_event *event)
615{
616 struct i40iw_qp *iwqp;
617 struct iw_cm_id *cm_id;
618
619 cm_id = event->cm_node->cm_id;
620 if (!cm_id)
621 return;
622
623 iwqp = cm_id->provider_data;
624
625 if (!iwqp || !iwqp->iwdev)
626 return;
627
628 iwqp->cm_id = NULL;
629 cm_id->provider_data = NULL;
630 i40iw_send_cm_event(event->cm_node, cm_id,
631 IW_CM_EVENT_CONNECT_REPLY,
632 -ECONNRESET);
633 cm_id->rem_ref(cm_id);
634 i40iw_rem_ref_cm_node(event->cm_node);
635}
636
637/**
638 * i40iw_process_options
639 * @cm_node: connection's node
640 * @optionsloc: point to start of options
641 * @optionsize: size of all options
642 * @syn_packet: flag if syn packet
643 */
644static int i40iw_process_options(struct i40iw_cm_node *cm_node,
645 u8 *optionsloc,
646 u32 optionsize,
647 u32 syn_packet)
648{
649 u32 tmp;
650 u32 offset = 0;
651 union all_known_options *all_options;
652 char got_mss_option = 0;
653
654 while (offset < optionsize) {
655 all_options = (union all_known_options *)(optionsloc + offset);
656 switch (all_options->as_base.optionnum) {
657 case OPTION_NUMBER_END:
658 offset = optionsize;
659 break;
660 case OPTION_NUMBER_NONE:
661 offset += 1;
662 continue;
663 case OPTION_NUMBER_MSS:
664 i40iw_debug(cm_node->dev,
665 I40IW_DEBUG_CM,
666 "%s: MSS Length: %d Offset: %d Size: %d\n",
667 __func__,
668 all_options->as_mss.length,
669 offset,
670 optionsize);
671 got_mss_option = 1;
672 if (all_options->as_mss.length != 4)
673 return -1;
674 tmp = ntohs(all_options->as_mss.mss);
675 if (tmp > 0 && tmp < cm_node->tcp_cntxt.mss)
676 cm_node->tcp_cntxt.mss = tmp;
677 break;
678 case OPTION_NUMBER_WINDOW_SCALE:
679 cm_node->tcp_cntxt.snd_wscale =
680 all_options->as_windowscale.shiftcount;
681 break;
682 default:
683 i40iw_debug(cm_node->dev,
684 I40IW_DEBUG_CM,
685 "TCP Option not understood: %x\n",
686 all_options->as_base.optionnum);
687 break;
688 }
689 offset += all_options->as_base.length;
690 }
691 if (!got_mss_option && syn_packet)
692 cm_node->tcp_cntxt.mss = I40IW_CM_DEFAULT_MSS;
693 return 0;
694}
695
696/**
697 * i40iw_handle_tcp_options -
698 * @cm_node: connection's node
699 * @tcph: pointer tcp header
700 * @optionsize: size of options rcvd
701 * @passive: active or passive flag
702 */
703static int i40iw_handle_tcp_options(struct i40iw_cm_node *cm_node,
704 struct tcphdr *tcph,
705 int optionsize,
706 int passive)
707{
708 u8 *optionsloc = (u8 *)&tcph[1];
709
710 if (optionsize) {
711 if (i40iw_process_options(cm_node,
712 optionsloc,
713 optionsize,
714 (u32)tcph->syn)) {
715 i40iw_debug(cm_node->dev,
716 I40IW_DEBUG_CM,
717 "%s: Node %p, Sending RESET\n",
718 __func__,
719 cm_node);
720 if (passive)
721 i40iw_passive_open_err(cm_node, true);
722 else
723 i40iw_active_open_err(cm_node, true);
724 return -1;
725 }
726 }
727
728 cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window) <<
729 cm_node->tcp_cntxt.snd_wscale;
730
731 if (cm_node->tcp_cntxt.snd_wnd > cm_node->tcp_cntxt.max_snd_wnd)
732 cm_node->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.snd_wnd;
733 return 0;
734}
735
736/**
737 * i40iw_build_mpa_v1 - build a MPA V1 frame
738 * @cm_node: connection's node
739 * @mpa_key: to do read0 or write0
740 */
741static void i40iw_build_mpa_v1(struct i40iw_cm_node *cm_node,
742 void *start_addr,
743 u8 mpa_key)
744{
745 struct ietf_mpa_v1 *mpa_frame = (struct ietf_mpa_v1 *)start_addr;
746
747 switch (mpa_key) {
748 case MPA_KEY_REQUEST:
749 memcpy(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE);
750 break;
751 case MPA_KEY_REPLY:
752 memcpy(mpa_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
753 break;
754 default:
755 break;
756 }
757 mpa_frame->flags = IETF_MPA_FLAGS_CRC;
758 mpa_frame->rev = cm_node->mpa_frame_rev;
759 mpa_frame->priv_data_len = htons(cm_node->pdata.size);
760}
761
762/**
763 * i40iw_build_mpa_v2 - build a MPA V2 frame
764 * @cm_node: connection's node
765 * @start_addr: buffer start address
766 * @mpa_key: to do read0 or write0
767 */
768static void i40iw_build_mpa_v2(struct i40iw_cm_node *cm_node,
769 void *start_addr,
770 u8 mpa_key)
771{
772 struct ietf_mpa_v2 *mpa_frame = (struct ietf_mpa_v2 *)start_addr;
773 struct ietf_rtr_msg *rtr_msg = &mpa_frame->rtr_msg;
774
775 /* initialize the upper 5 bytes of the frame */
776 i40iw_build_mpa_v1(cm_node, start_addr, mpa_key);
777 mpa_frame->flags |= IETF_MPA_V2_FLAG;
778 mpa_frame->priv_data_len += htons(IETF_RTR_MSG_SIZE);
779
780 /* initialize RTR msg */
781 if (cm_node->mpav2_ird_ord == IETF_NO_IRD_ORD) {
782 rtr_msg->ctrl_ird = IETF_NO_IRD_ORD;
783 rtr_msg->ctrl_ord = IETF_NO_IRD_ORD;
784 } else {
785 rtr_msg->ctrl_ird = (cm_node->ird_size > IETF_NO_IRD_ORD) ?
786 IETF_NO_IRD_ORD : cm_node->ird_size;
787 rtr_msg->ctrl_ord = (cm_node->ord_size > IETF_NO_IRD_ORD) ?
788 IETF_NO_IRD_ORD : cm_node->ord_size;
789 }
790
791 rtr_msg->ctrl_ird |= IETF_PEER_TO_PEER;
792 rtr_msg->ctrl_ird |= IETF_FLPDU_ZERO_LEN;
793
794 switch (mpa_key) {
795 case MPA_KEY_REQUEST:
796 rtr_msg->ctrl_ord |= IETF_RDMA0_WRITE;
797 rtr_msg->ctrl_ord |= IETF_RDMA0_READ;
798 break;
799 case MPA_KEY_REPLY:
800 switch (cm_node->send_rdma0_op) {
801 case SEND_RDMA_WRITE_ZERO:
802 rtr_msg->ctrl_ord |= IETF_RDMA0_WRITE;
803 break;
804 case SEND_RDMA_READ_ZERO:
805 rtr_msg->ctrl_ord |= IETF_RDMA0_READ;
806 break;
807 }
808 break;
809 default:
810 break;
811 }
812 rtr_msg->ctrl_ird = htons(rtr_msg->ctrl_ird);
813 rtr_msg->ctrl_ord = htons(rtr_msg->ctrl_ord);
814}
815
816/**
817 * i40iw_cm_build_mpa_frame - build mpa frame for mpa version 1 or version 2
818 * @cm_node: connection's node
819 * @mpa: mpa: data buffer
820 * @mpa_key: to do read0 or write0
821 */
822static int i40iw_cm_build_mpa_frame(struct i40iw_cm_node *cm_node,
823 struct i40iw_kmem_info *mpa,
824 u8 mpa_key)
825{
826 int hdr_len = 0;
827
828 switch (cm_node->mpa_frame_rev) {
829 case IETF_MPA_V1:
830 hdr_len = sizeof(struct ietf_mpa_v1);
831 i40iw_build_mpa_v1(cm_node, mpa->addr, mpa_key);
832 break;
833 case IETF_MPA_V2:
834 hdr_len = sizeof(struct ietf_mpa_v2);
835 i40iw_build_mpa_v2(cm_node, mpa->addr, mpa_key);
836 break;
837 default:
838 break;
839 }
840
841 return hdr_len;
842}
843
844/**
845 * i40iw_send_mpa_request - active node send mpa request to passive node
846 * @cm_node: connection's node
847 */
848static int i40iw_send_mpa_request(struct i40iw_cm_node *cm_node)
849{
850 struct i40iw_puda_buf *sqbuf;
851
852 if (!cm_node) {
853 i40iw_pr_err("cm_node == NULL\n");
854 return -1;
855 }
856
857 cm_node->mpa_hdr.addr = &cm_node->mpa_frame;
858 cm_node->mpa_hdr.size = i40iw_cm_build_mpa_frame(cm_node,
859 &cm_node->mpa_hdr,
860 MPA_KEY_REQUEST);
861 if (!cm_node->mpa_hdr.size) {
862 i40iw_pr_err("mpa size = %d\n", cm_node->mpa_hdr.size);
863 return -1;
864 }
865
866 sqbuf = i40iw_form_cm_frame(cm_node,
867 NULL,
868 &cm_node->mpa_hdr,
869 &cm_node->pdata,
870 SET_ACK);
871 if (!sqbuf) {
872 i40iw_pr_err("sq_buf == NULL\n");
873 return -1;
874 }
875 return i40iw_schedule_cm_timer(cm_node, sqbuf, I40IW_TIMER_TYPE_SEND, 1, 0);
876}
877
878/**
879 * i40iw_send_mpa_reject -
880 * @cm_node: connection's node
881 * @pdata: reject data for connection
882 * @plen: length of reject data
883 */
884static int i40iw_send_mpa_reject(struct i40iw_cm_node *cm_node,
885 const void *pdata,
886 u8 plen)
887{
888 struct i40iw_puda_buf *sqbuf;
889 struct i40iw_kmem_info priv_info;
890
891 cm_node->mpa_hdr.addr = &cm_node->mpa_frame;
892 cm_node->mpa_hdr.size = i40iw_cm_build_mpa_frame(cm_node,
893 &cm_node->mpa_hdr,
894 MPA_KEY_REPLY);
895
896 cm_node->mpa_frame.flags |= IETF_MPA_FLAGS_REJECT;
897 priv_info.addr = (void *)pdata;
898 priv_info.size = plen;
899
900 sqbuf = i40iw_form_cm_frame(cm_node,
901 NULL,
902 &cm_node->mpa_hdr,
903 &priv_info,
904 SET_ACK | SET_FIN);
905 if (!sqbuf) {
906 i40iw_pr_err("no sqbuf\n");
907 return -ENOMEM;
908 }
909 cm_node->state = I40IW_CM_STATE_FIN_WAIT1;
910 return i40iw_schedule_cm_timer(cm_node, sqbuf, I40IW_TIMER_TYPE_SEND, 1, 0);
911}
912
913/**
914 * recv_mpa - process an IETF MPA frame
915 * @cm_node: connection's node
916 * @buffer: Data pointer
917 * @type: to return accept or reject
918 * @len: Len of mpa buffer
919 */
920static int i40iw_parse_mpa(struct i40iw_cm_node *cm_node, u8 *buffer, u32 *type, u32 len)
921{
922 struct ietf_mpa_v1 *mpa_frame;
923 struct ietf_mpa_v2 *mpa_v2_frame;
924 struct ietf_rtr_msg *rtr_msg;
925 int mpa_hdr_len;
926 int priv_data_len;
927
928 *type = I40IW_MPA_REQUEST_ACCEPT;
929
930 if (len < sizeof(struct ietf_mpa_v1)) {
931 i40iw_pr_err("ietf buffer small (%x)\n", len);
932 return -1;
933 }
934
935 mpa_frame = (struct ietf_mpa_v1 *)buffer;
936 mpa_hdr_len = sizeof(struct ietf_mpa_v1);
937 priv_data_len = ntohs(mpa_frame->priv_data_len);
938
939 if (priv_data_len > IETF_MAX_PRIV_DATA_LEN) {
940 i40iw_pr_err("large pri_data %d\n", priv_data_len);
941 return -1;
942 }
943 if (mpa_frame->rev != IETF_MPA_V1 && mpa_frame->rev != IETF_MPA_V2) {
944 i40iw_pr_err("unsupported mpa rev = %d\n", mpa_frame->rev);
945 return -1;
946 }
947 if (mpa_frame->rev > cm_node->mpa_frame_rev) {
948 i40iw_pr_err("rev %d\n", mpa_frame->rev);
949 return -1;
950 }
951 cm_node->mpa_frame_rev = mpa_frame->rev;
952
953 if (cm_node->state != I40IW_CM_STATE_MPAREQ_SENT) {
954 if (memcmp(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE)) {
955 i40iw_pr_err("Unexpected MPA Key received\n");
956 return -1;
957 }
958 } else {
959 if (memcmp(mpa_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE)) {
960 i40iw_pr_err("Unexpected MPA Key received\n");
961 return -1;
962 }
963 }
964
965 if (priv_data_len + mpa_hdr_len > len) {
966 i40iw_pr_err("ietf buffer len(%x + %x != %x)\n",
967 priv_data_len, mpa_hdr_len, len);
968 return -1;
969 }
970 if (len > MAX_CM_BUFFER) {
971 i40iw_pr_err("ietf buffer large len = %d\n", len);
972 return -1;
973 }
974
975 switch (mpa_frame->rev) {
976 case IETF_MPA_V2:{
977 u16 ird_size;
978 u16 ord_size;
979 u16 ctrl_ord;
980 u16 ctrl_ird;
981
982 mpa_v2_frame = (struct ietf_mpa_v2 *)buffer;
983 mpa_hdr_len += IETF_RTR_MSG_SIZE;
984 rtr_msg = &mpa_v2_frame->rtr_msg;
985
986 /* parse rtr message */
987 ctrl_ord = ntohs(rtr_msg->ctrl_ord);
988 ctrl_ird = ntohs(rtr_msg->ctrl_ird);
989 ird_size = ctrl_ird & IETF_NO_IRD_ORD;
990 ord_size = ctrl_ord & IETF_NO_IRD_ORD;
991
992 if (!(ctrl_ird & IETF_PEER_TO_PEER))
993 return -1;
994
995 if (ird_size == IETF_NO_IRD_ORD || ord_size == IETF_NO_IRD_ORD) {
996 cm_node->mpav2_ird_ord = IETF_NO_IRD_ORD;
997 goto negotiate_done;
998 }
999
1000 if (cm_node->state != I40IW_CM_STATE_MPAREQ_SENT) {
1001 /* responder */
1002 if (!ord_size && (ctrl_ord & IETF_RDMA0_READ))
1003 cm_node->ird_size = 1;
1004 if (cm_node->ord_size > ird_size)
1005 cm_node->ord_size = ird_size;
1006 } else {
1007 /* initiator */
1008 if (!ird_size && (ctrl_ord & IETF_RDMA0_READ))
1009 return -1;
1010 if (cm_node->ord_size > ird_size)
1011 cm_node->ord_size = ird_size;
1012
1013 if (cm_node->ird_size < ord_size)
1014 /* no resources available */
1015 return -1;
1016 }
1017
1018negotiate_done:
1019 if (ctrl_ord & IETF_RDMA0_READ)
1020 cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
1021 else if (ctrl_ord & IETF_RDMA0_WRITE)
1022 cm_node->send_rdma0_op = SEND_RDMA_WRITE_ZERO;
1023 else /* Not supported RDMA0 operation */
1024 return -1;
1025 i40iw_debug(cm_node->dev, I40IW_DEBUG_CM,
1026 "MPAV2: Negotiated ORD: %d, IRD: %d\n",
1027 cm_node->ord_size, cm_node->ird_size);
1028 break;
1029 }
1030 break;
1031 case IETF_MPA_V1:
1032 default:
1033 break;
1034 }
1035
1036 memcpy(cm_node->pdata_buf, buffer + mpa_hdr_len, priv_data_len);
1037 cm_node->pdata.size = priv_data_len;
1038
1039 if (mpa_frame->flags & IETF_MPA_FLAGS_REJECT)
1040 *type = I40IW_MPA_REQUEST_REJECT;
1041
1042 if (mpa_frame->flags & IETF_MPA_FLAGS_MARKERS)
1043 cm_node->snd_mark_en = true;
1044
1045 return 0;
1046}
1047
1048/**
1049 * i40iw_schedule_cm_timer
1050 * @@cm_node: connection's node
1051 * @sqbuf: buffer to send
1052 * @type: if it es send ot close
1053 * @send_retrans: if rexmits to be done
1054 * @close_when_complete: is cm_node to be removed
1055 *
1056 * note - cm_node needs to be protected before calling this. Encase in:
1057 * i40iw_rem_ref_cm_node(cm_core, cm_node);
1058 * i40iw_schedule_cm_timer(...)
1059 * atomic_inc(&cm_node->ref_count);
1060 */
1061int i40iw_schedule_cm_timer(struct i40iw_cm_node *cm_node,
1062 struct i40iw_puda_buf *sqbuf,
1063 enum i40iw_timer_type type,
1064 int send_retrans,
1065 int close_when_complete)
1066{
1067 struct i40iw_sc_dev *dev = cm_node->dev;
1068 struct i40iw_cm_core *cm_core = cm_node->cm_core;
1069 struct i40iw_timer_entry *new_send;
1070 int ret = 0;
1071 u32 was_timer_set;
1072 unsigned long flags;
1073
1074 new_send = kzalloc(sizeof(*new_send), GFP_ATOMIC);
1075 if (!new_send) {
1076 i40iw_free_sqbuf(cm_node->dev, (void *)sqbuf);
1077 return -ENOMEM;
1078 }
1079 new_send->retrycount = I40IW_DEFAULT_RETRYS;
1080 new_send->retranscount = I40IW_DEFAULT_RETRANS;
1081 new_send->sqbuf = sqbuf;
1082 new_send->timetosend = jiffies;
1083 new_send->type = type;
1084 new_send->send_retrans = send_retrans;
1085 new_send->close_when_complete = close_when_complete;
1086
1087 if (type == I40IW_TIMER_TYPE_CLOSE) {
1088 new_send->timetosend += (HZ / 10);
1089 if (cm_node->close_entry) {
1090 kfree(new_send);
1091 i40iw_free_sqbuf(cm_node->dev, (void *)sqbuf);
1092 i40iw_pr_err("already close entry\n");
1093 return -EINVAL;
1094 }
1095 cm_node->close_entry = new_send;
1096 }
1097
1098 if (type == I40IW_TIMER_TYPE_SEND) {
1099 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
1100 cm_node->send_entry = new_send;
1101 atomic_inc(&cm_node->ref_count);
1102 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
1103 new_send->timetosend = jiffies + I40IW_RETRY_TIMEOUT;
1104
1105 atomic_inc(&sqbuf->refcount);
1106 i40iw_puda_send_buf(dev->ilq, sqbuf);
1107 if (!send_retrans) {
1108 i40iw_cleanup_retrans_entry(cm_node);
1109 if (close_when_complete)
1110 i40iw_rem_ref_cm_node(cm_node);
1111 return ret;
1112 }
1113 }
1114
1115 spin_lock_irqsave(&cm_core->ht_lock, flags);
1116 was_timer_set = timer_pending(&cm_core->tcp_timer);
1117
1118 if (!was_timer_set) {
1119 cm_core->tcp_timer.expires = new_send->timetosend;
1120 add_timer(&cm_core->tcp_timer);
1121 }
1122 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
1123
1124 return ret;
1125}
1126
1127/**
1128 * i40iw_retrans_expired - Could not rexmit the packet
1129 * @cm_node: connection's node
1130 */
1131static void i40iw_retrans_expired(struct i40iw_cm_node *cm_node)
1132{
1133 struct iw_cm_id *cm_id = cm_node->cm_id;
1134 enum i40iw_cm_node_state state = cm_node->state;
1135
1136 cm_node->state = I40IW_CM_STATE_CLOSED;
1137 switch (state) {
1138 case I40IW_CM_STATE_SYN_RCVD:
1139 case I40IW_CM_STATE_CLOSING:
1140 i40iw_rem_ref_cm_node(cm_node);
1141 break;
1142 case I40IW_CM_STATE_FIN_WAIT1:
1143 case I40IW_CM_STATE_LAST_ACK:
1144 if (cm_node->cm_id)
1145 cm_id->rem_ref(cm_id);
1146 i40iw_send_reset(cm_node);
1147 break;
1148 default:
1149 atomic_inc(&cm_node->ref_count);
1150 i40iw_send_reset(cm_node);
1151 i40iw_create_event(cm_node, I40IW_CM_EVENT_ABORTED);
1152 break;
1153 }
1154}
1155
1156/**
1157 * i40iw_handle_close_entry - for handling retry/timeouts
1158 * @cm_node: connection's node
1159 * @rem_node: flag for remove cm_node
1160 */
1161static void i40iw_handle_close_entry(struct i40iw_cm_node *cm_node, u32 rem_node)
1162{
1163 struct i40iw_timer_entry *close_entry = cm_node->close_entry;
1164 struct iw_cm_id *cm_id = cm_node->cm_id;
1165 struct i40iw_qp *iwqp;
1166 unsigned long flags;
1167
1168 if (!close_entry)
1169 return;
1170 iwqp = (struct i40iw_qp *)close_entry->sqbuf;
1171 if (iwqp) {
1172 spin_lock_irqsave(&iwqp->lock, flags);
1173 if (iwqp->cm_id) {
1174 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSED;
1175 iwqp->hw_iwarp_state = I40IW_QP_STATE_ERROR;
1176 iwqp->last_aeq = I40IW_AE_RESET_SENT;
1177 iwqp->ibqp_state = IB_QPS_ERR;
1178 spin_unlock_irqrestore(&iwqp->lock, flags);
1179 i40iw_cm_disconn(iwqp);
1180 } else {
1181 spin_unlock_irqrestore(&iwqp->lock, flags);
1182 }
1183 } else if (rem_node) {
1184 /* TIME_WAIT state */
1185 i40iw_rem_ref_cm_node(cm_node);
1186 }
1187 if (cm_id)
1188 cm_id->rem_ref(cm_id);
1189 kfree(close_entry);
1190 cm_node->close_entry = NULL;
1191}
1192
1193/**
1194 * i40iw_cm_timer_tick - system's timer expired callback
1195 * @pass: Pointing to cm_core
1196 */
1197static void i40iw_cm_timer_tick(unsigned long pass)
1198{
1199 unsigned long nexttimeout = jiffies + I40IW_LONG_TIME;
1200 struct i40iw_cm_node *cm_node;
1201 struct i40iw_timer_entry *send_entry, *close_entry;
1202 struct list_head *list_core_temp;
1203 struct list_head *list_node;
1204 struct i40iw_cm_core *cm_core = (struct i40iw_cm_core *)pass;
1205 u32 settimer = 0;
1206 unsigned long timetosend;
1207 struct i40iw_sc_dev *dev;
1208 unsigned long flags;
1209
1210 struct list_head timer_list;
1211
1212 INIT_LIST_HEAD(&timer_list);
1213 spin_lock_irqsave(&cm_core->ht_lock, flags);
1214
1215 list_for_each_safe(list_node, list_core_temp, &cm_core->connected_nodes) {
1216 cm_node = container_of(list_node, struct i40iw_cm_node, list);
1217 if (cm_node->close_entry || cm_node->send_entry) {
1218 atomic_inc(&cm_node->ref_count);
1219 list_add(&cm_node->timer_entry, &timer_list);
1220 }
1221 }
1222 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
1223
1224 list_for_each_safe(list_node, list_core_temp, &timer_list) {
1225 cm_node = container_of(list_node,
1226 struct i40iw_cm_node,
1227 timer_entry);
1228 close_entry = cm_node->close_entry;
1229
1230 if (close_entry) {
1231 if (time_after(close_entry->timetosend, jiffies)) {
1232 if (nexttimeout > close_entry->timetosend ||
1233 !settimer) {
1234 nexttimeout = close_entry->timetosend;
1235 settimer = 1;
1236 }
1237 } else {
1238 i40iw_handle_close_entry(cm_node, 1);
1239 }
1240 }
1241
1242 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
1243
1244 send_entry = cm_node->send_entry;
1245 if (!send_entry)
1246 goto done;
1247 if (time_after(send_entry->timetosend, jiffies)) {
1248 if (cm_node->state != I40IW_CM_STATE_OFFLOADED) {
1249 if ((nexttimeout > send_entry->timetosend) ||
1250 !settimer) {
1251 nexttimeout = send_entry->timetosend;
1252 settimer = 1;
1253 }
1254 } else {
1255 i40iw_free_retrans_entry(cm_node);
1256 }
1257 goto done;
1258 }
1259
1260 if ((cm_node->state == I40IW_CM_STATE_OFFLOADED) ||
1261 (cm_node->state == I40IW_CM_STATE_CLOSED)) {
1262 i40iw_free_retrans_entry(cm_node);
1263 goto done;
1264 }
1265
1266 if (!send_entry->retranscount || !send_entry->retrycount) {
1267 i40iw_free_retrans_entry(cm_node);
1268
1269 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
1270 i40iw_retrans_expired(cm_node);
1271 cm_node->state = I40IW_CM_STATE_CLOSED;
1272 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
1273 goto done;
1274 }
1275 cm_node->cm_core->stats_pkt_retrans++;
1276 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
1277
1278 dev = cm_node->dev;
1279 atomic_inc(&send_entry->sqbuf->refcount);
1280 i40iw_puda_send_buf(dev->ilq, send_entry->sqbuf);
1281 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
1282 if (send_entry->send_retrans) {
1283 send_entry->retranscount--;
1284 timetosend = (I40IW_RETRY_TIMEOUT <<
1285 (I40IW_DEFAULT_RETRANS -
1286 send_entry->retranscount));
1287
1288 send_entry->timetosend = jiffies +
1289 min(timetosend, I40IW_MAX_TIMEOUT);
1290 if (nexttimeout > send_entry->timetosend || !settimer) {
1291 nexttimeout = send_entry->timetosend;
1292 settimer = 1;
1293 }
1294 } else {
1295 int close_when_complete;
1296
1297 close_when_complete = send_entry->close_when_complete;
1298 i40iw_debug(cm_node->dev,
1299 I40IW_DEBUG_CM,
1300 "cm_node=%p state=%d\n",
1301 cm_node,
1302 cm_node->state);
1303 i40iw_free_retrans_entry(cm_node);
1304 if (close_when_complete)
1305 i40iw_rem_ref_cm_node(cm_node);
1306 }
1307done:
1308 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
1309 i40iw_rem_ref_cm_node(cm_node);
1310 }
1311
1312 if (settimer) {
1313 spin_lock_irqsave(&cm_core->ht_lock, flags);
1314 if (!timer_pending(&cm_core->tcp_timer)) {
1315 cm_core->tcp_timer.expires = nexttimeout;
1316 add_timer(&cm_core->tcp_timer);
1317 }
1318 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
1319 }
1320}
1321
1322/**
1323 * i40iw_send_syn - send SYN packet
1324 * @cm_node: connection's node
1325 * @sendack: flag to set ACK bit or not
1326 */
1327int i40iw_send_syn(struct i40iw_cm_node *cm_node, u32 sendack)
1328{
1329 struct i40iw_puda_buf *sqbuf;
1330 int flags = SET_SYN;
1331 char optionsbuffer[sizeof(struct option_mss) +
1332 sizeof(struct option_windowscale) +
1333 sizeof(struct option_base) + TCP_OPTIONS_PADDING];
1334 struct i40iw_kmem_info opts;
1335
1336 int optionssize = 0;
1337 /* Sending MSS option */
1338 union all_known_options *options;
1339
1340 opts.addr = optionsbuffer;
1341 if (!cm_node) {
1342 i40iw_pr_err("no cm_node\n");
1343 return -EINVAL;
1344 }
1345
1346 options = (union all_known_options *)&optionsbuffer[optionssize];
1347 options->as_mss.optionnum = OPTION_NUMBER_MSS;
1348 options->as_mss.length = sizeof(struct option_mss);
1349 options->as_mss.mss = htons(cm_node->tcp_cntxt.mss);
1350 optionssize += sizeof(struct option_mss);
1351
1352 options = (union all_known_options *)&optionsbuffer[optionssize];
1353 options->as_windowscale.optionnum = OPTION_NUMBER_WINDOW_SCALE;
1354 options->as_windowscale.length = sizeof(struct option_windowscale);
1355 options->as_windowscale.shiftcount = cm_node->tcp_cntxt.rcv_wscale;
1356 optionssize += sizeof(struct option_windowscale);
1357 options = (union all_known_options *)&optionsbuffer[optionssize];
1358 options->as_end = OPTION_NUMBER_END;
1359 optionssize += 1;
1360
1361 if (sendack)
1362 flags |= SET_ACK;
1363
1364 opts.size = optionssize;
1365
1366 sqbuf = i40iw_form_cm_frame(cm_node, &opts, NULL, NULL, flags);
1367 if (!sqbuf) {
1368 i40iw_pr_err("no sqbuf\n");
1369 return -1;
1370 }
1371 return i40iw_schedule_cm_timer(cm_node, sqbuf, I40IW_TIMER_TYPE_SEND, 1, 0);
1372}
1373
1374/**
1375 * i40iw_send_ack - Send ACK packet
1376 * @cm_node: connection's node
1377 */
1378static void i40iw_send_ack(struct i40iw_cm_node *cm_node)
1379{
1380 struct i40iw_puda_buf *sqbuf;
1381
1382 sqbuf = i40iw_form_cm_frame(cm_node, NULL, NULL, NULL, SET_ACK);
1383 if (sqbuf)
1384 i40iw_puda_send_buf(cm_node->dev->ilq, sqbuf);
1385 else
1386 i40iw_pr_err("no sqbuf\n");
1387}
1388
1389/**
1390 * i40iw_send_fin - Send FIN pkt
1391 * @cm_node: connection's node
1392 */
1393static int i40iw_send_fin(struct i40iw_cm_node *cm_node)
1394{
1395 struct i40iw_puda_buf *sqbuf;
1396
1397 sqbuf = i40iw_form_cm_frame(cm_node, NULL, NULL, NULL, SET_ACK | SET_FIN);
1398 if (!sqbuf) {
1399 i40iw_pr_err("no sqbuf\n");
1400 return -1;
1401 }
1402 return i40iw_schedule_cm_timer(cm_node, sqbuf, I40IW_TIMER_TYPE_SEND, 1, 0);
1403}
1404
1405/**
1406 * i40iw_find_node - find a cm node that matches the reference cm node
1407 * @cm_core: cm's core
1408 * @rem_port: remote tcp port num
1409 * @rem_addr: remote ip addr
1410 * @loc_port: local tcp port num
1411 * @loc_addr: loc ip addr
1412 * @add_refcnt: flag to increment refcount of cm_node
1413 */
1414struct i40iw_cm_node *i40iw_find_node(struct i40iw_cm_core *cm_core,
1415 u16 rem_port,
1416 u32 *rem_addr,
1417 u16 loc_port,
1418 u32 *loc_addr,
1419 bool add_refcnt)
1420{
1421 struct list_head *hte;
1422 struct i40iw_cm_node *cm_node;
1423 unsigned long flags;
1424
1425 hte = &cm_core->connected_nodes;
1426
1427 /* walk list and find cm_node associated with this session ID */
1428 spin_lock_irqsave(&cm_core->ht_lock, flags);
1429 list_for_each_entry(cm_node, hte, list) {
1430 if (!memcmp(cm_node->loc_addr, loc_addr, sizeof(cm_node->loc_addr)) &&
1431 (cm_node->loc_port == loc_port) &&
1432 !memcmp(cm_node->rem_addr, rem_addr, sizeof(cm_node->rem_addr)) &&
1433 (cm_node->rem_port == rem_port)) {
1434 if (add_refcnt)
1435 atomic_inc(&cm_node->ref_count);
1436 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
1437 return cm_node;
1438 }
1439 }
1440 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
1441
1442 /* no owner node */
1443 return NULL;
1444}
1445
1446/**
1447 * i40iw_find_listener - find a cm node listening on this addr-port pair
1448 * @cm_core: cm's core
1449 * @dst_port: listener tcp port num
1450 * @dst_addr: listener ip addr
1451 * @listener_state: state to match with listen node's
1452 */
1453static struct i40iw_cm_listener *i40iw_find_listener(
1454 struct i40iw_cm_core *cm_core,
1455 u32 *dst_addr,
1456 u16 dst_port,
1457 u16 vlan_id,
1458 enum i40iw_cm_listener_state
1459 listener_state)
1460{
1461 struct i40iw_cm_listener *listen_node;
1462 static const u32 ip_zero[4] = { 0, 0, 0, 0 };
1463 u32 listen_addr[4];
1464 u16 listen_port;
1465 unsigned long flags;
1466
1467 /* walk list and find cm_node associated with this session ID */
1468 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
1469 list_for_each_entry(listen_node, &cm_core->listen_nodes, list) {
1470 memcpy(listen_addr, listen_node->loc_addr, sizeof(listen_addr));
1471 listen_port = listen_node->loc_port;
1472 /* compare node pair, return node handle if a match */
1473 if ((!memcmp(listen_addr, dst_addr, sizeof(listen_addr)) ||
1474 !memcmp(listen_addr, ip_zero, sizeof(listen_addr))) &&
1475 (listen_port == dst_port) &&
1476 (listener_state & listen_node->listener_state)) {
1477 atomic_inc(&listen_node->ref_count);
1478 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1479 return listen_node;
1480 }
1481 }
1482 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1483 return NULL;
1484}
1485
1486/**
1487 * i40iw_add_hte_node - add a cm node to the hash table
1488 * @cm_core: cm's core
1489 * @cm_node: connection's node
1490 */
1491static void i40iw_add_hte_node(struct i40iw_cm_core *cm_core,
1492 struct i40iw_cm_node *cm_node)
1493{
1494 struct list_head *hte;
1495 unsigned long flags;
1496
1497 if (!cm_node || !cm_core) {
1498 i40iw_pr_err("cm_node or cm_core == NULL\n");
1499 return;
1500 }
1501 spin_lock_irqsave(&cm_core->ht_lock, flags);
1502
1503 /* get a handle on the hash table element (list head for this slot) */
1504 hte = &cm_core->connected_nodes;
1505 list_add_tail(&cm_node->list, hte);
1506 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
1507}
1508
1509/**
1510 * listen_port_in_use - determine if port is in use
1511 * @port: Listen port number
1512 */
1513static bool i40iw_listen_port_in_use(struct i40iw_cm_core *cm_core, u16 port)
1514{
1515 struct i40iw_cm_listener *listen_node;
1516 unsigned long flags;
1517 bool ret = false;
1518
1519 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
1520 list_for_each_entry(listen_node, &cm_core->listen_nodes, list) {
1521 if (listen_node->loc_port == port) {
1522 ret = true;
1523 break;
1524 }
1525 }
1526 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1527 return ret;
1528}
1529
1530/**
1531 * i40iw_del_multiple_qhash - Remove qhash and child listens
1532 * @iwdev: iWarp device
1533 * @cm_info: CM info for parent listen node
1534 * @cm_parent_listen_node: The parent listen node
1535 */
1536static enum i40iw_status_code i40iw_del_multiple_qhash(
1537 struct i40iw_device *iwdev,
1538 struct i40iw_cm_info *cm_info,
1539 struct i40iw_cm_listener *cm_parent_listen_node)
1540{
1541 struct i40iw_cm_listener *child_listen_node;
1542 enum i40iw_status_code ret = I40IW_ERR_CONFIG;
1543 struct list_head *pos, *tpos;
1544 unsigned long flags;
1545
1546 spin_lock_irqsave(&iwdev->cm_core.listen_list_lock, flags);
1547 list_for_each_safe(pos, tpos, &cm_parent_listen_node->child_listen_list) {
1548 child_listen_node = list_entry(pos, struct i40iw_cm_listener, child_listen_list);
1549 if (child_listen_node->ipv4)
1550 i40iw_debug(&iwdev->sc_dev,
1551 I40IW_DEBUG_CM,
1552 "removing child listen for IP=%pI4, port=%d, vlan=%d\n",
1553 child_listen_node->loc_addr,
1554 child_listen_node->loc_port,
1555 child_listen_node->vlan_id);
1556 else
1557 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_CM,
1558 "removing child listen for IP=%pI6, port=%d, vlan=%d\n",
1559 child_listen_node->loc_addr,
1560 child_listen_node->loc_port,
1561 child_listen_node->vlan_id);
1562 list_del(pos);
1563 memcpy(cm_info->loc_addr, child_listen_node->loc_addr,
1564 sizeof(cm_info->loc_addr));
1565 cm_info->vlan_id = child_listen_node->vlan_id;
1566 ret = i40iw_manage_qhash(iwdev, cm_info,
1567 I40IW_QHASH_TYPE_TCP_SYN,
1568 I40IW_QHASH_MANAGE_TYPE_DELETE, NULL, false);
1569 kfree(child_listen_node);
1570 cm_parent_listen_node->cm_core->stats_listen_nodes_destroyed++;
1571 i40iw_debug(&iwdev->sc_dev,
1572 I40IW_DEBUG_CM,
1573 "freed pointer = %p\n",
1574 child_listen_node);
1575 }
1576 spin_unlock_irqrestore(&iwdev->cm_core.listen_list_lock, flags);
1577
1578 return ret;
1579}
1580
1581/**
1582 * i40iw_netdev_vlan_ipv6 - Gets the netdev and mac
1583 * @addr: local IPv6 address
1584 * @vlan_id: vlan id for the given IPv6 address
1585 * @mac: mac address for the given IPv6 address
1586 *
1587 * Returns the net_device of the IPv6 address and also sets the
1588 * vlan id and mac for that address.
1589 */
1590static struct net_device *i40iw_netdev_vlan_ipv6(u32 *addr, u16 *vlan_id, u8 *mac)
1591{
1592 struct net_device *ip_dev = NULL;
1593#if IS_ENABLED(CONFIG_IPV6)
1594 struct in6_addr laddr6;
1595
1596 i40iw_copy_ip_htonl(laddr6.in6_u.u6_addr32, addr);
1597 if (vlan_id)
1598 *vlan_id = I40IW_NO_VLAN;
1599 if (mac)
1600 eth_zero_addr(mac);
1601 rcu_read_lock();
1602 for_each_netdev_rcu(&init_net, ip_dev) {
1603 if (ipv6_chk_addr(&init_net, &laddr6, ip_dev, 1)) {
1604 if (vlan_id)
1605 *vlan_id = rdma_vlan_dev_vlan_id(ip_dev);
1606 if (ip_dev->dev_addr && mac)
1607 ether_addr_copy(mac, ip_dev->dev_addr);
1608 break;
1609 }
1610 }
1611 rcu_read_unlock();
1612#endif
1613 return ip_dev;
1614}
1615
1616/**
1617 * i40iw_get_vlan_ipv4 - Returns the vlan_id for IPv4 address
1618 * @addr: local IPv4 address
1619 */
1620static u16 i40iw_get_vlan_ipv4(u32 *addr)
1621{
1622 struct net_device *netdev;
1623 u16 vlan_id = I40IW_NO_VLAN;
1624
1625 netdev = ip_dev_find(&init_net, htonl(addr[0]));
1626 if (netdev) {
1627 vlan_id = rdma_vlan_dev_vlan_id(netdev);
1628 dev_put(netdev);
1629 }
1630 return vlan_id;
1631}
1632
1633/**
1634 * i40iw_add_mqh_6 - Adds multiple qhashes for IPv6
1635 * @iwdev: iWarp device
1636 * @cm_info: CM info for parent listen node
1637 * @cm_parent_listen_node: The parent listen node
1638 *
1639 * Adds a qhash and a child listen node for every IPv6 address
1640 * on the adapter and adds the associated qhash filter
1641 */
1642static enum i40iw_status_code i40iw_add_mqh_6(struct i40iw_device *iwdev,
1643 struct i40iw_cm_info *cm_info,
1644 struct i40iw_cm_listener *cm_parent_listen_node)
1645{
1646 struct net_device *ip_dev;
1647 struct inet6_dev *idev;
1648 struct inet6_ifaddr *ifp;
1649 enum i40iw_status_code ret = 0;
1650 struct i40iw_cm_listener *child_listen_node;
1651 unsigned long flags;
1652
1653 rtnl_lock();
1654 for_each_netdev_rcu(&init_net, ip_dev) {
1655 if ((((rdma_vlan_dev_vlan_id(ip_dev) < I40IW_NO_VLAN) &&
1656 (rdma_vlan_dev_real_dev(ip_dev) == iwdev->netdev)) ||
1657 (ip_dev == iwdev->netdev)) && (ip_dev->flags & IFF_UP)) {
1658 idev = __in6_dev_get(ip_dev);
1659 if (!idev) {
1660 i40iw_pr_err("idev == NULL\n");
1661 break;
1662 }
1663 list_for_each_entry(ifp, &idev->addr_list, if_list) {
1664 i40iw_debug(&iwdev->sc_dev,
1665 I40IW_DEBUG_CM,
1666 "IP=%pI6, vlan_id=%d, MAC=%pM\n",
1667 &ifp->addr,
1668 rdma_vlan_dev_vlan_id(ip_dev),
1669 ip_dev->dev_addr);
1670 child_listen_node =
1671 kzalloc(sizeof(*child_listen_node), GFP_ATOMIC);
1672 i40iw_debug(&iwdev->sc_dev,
1673 I40IW_DEBUG_CM,
1674 "Allocating child listener %p\n",
1675 child_listen_node);
1676 if (!child_listen_node) {
1677 i40iw_pr_err("listener memory allocation\n");
1678 ret = I40IW_ERR_NO_MEMORY;
1679 goto exit;
1680 }
1681 cm_info->vlan_id = rdma_vlan_dev_vlan_id(ip_dev);
1682 cm_parent_listen_node->vlan_id = cm_info->vlan_id;
1683
1684 memcpy(child_listen_node, cm_parent_listen_node,
1685 sizeof(*child_listen_node));
1686
1687 i40iw_copy_ip_ntohl(child_listen_node->loc_addr,
1688 ifp->addr.in6_u.u6_addr32);
1689 memcpy(cm_info->loc_addr, child_listen_node->loc_addr,
1690 sizeof(cm_info->loc_addr));
1691
1692 ret = i40iw_manage_qhash(iwdev, cm_info,
1693 I40IW_QHASH_TYPE_TCP_SYN,
1694 I40IW_QHASH_MANAGE_TYPE_ADD,
1695 NULL, true);
1696 if (!ret) {
1697 spin_lock_irqsave(&iwdev->cm_core.listen_list_lock, flags);
1698 list_add(&child_listen_node->child_listen_list,
1699 &cm_parent_listen_node->child_listen_list);
1700 spin_unlock_irqrestore(&iwdev->cm_core.listen_list_lock, flags);
1701 cm_parent_listen_node->cm_core->stats_listen_nodes_created++;
1702 } else {
1703 kfree(child_listen_node);
1704 }
1705 }
1706 }
1707 }
1708exit:
1709 rtnl_unlock();
1710 return ret;
1711}
1712
1713/**
1714 * i40iw_add_mqh_4 - Adds multiple qhashes for IPv4
1715 * @iwdev: iWarp device
1716 * @cm_info: CM info for parent listen node
1717 * @cm_parent_listen_node: The parent listen node
1718 *
1719 * Adds a qhash and a child listen node for every IPv4 address
1720 * on the adapter and adds the associated qhash filter
1721 */
1722static enum i40iw_status_code i40iw_add_mqh_4(
1723 struct i40iw_device *iwdev,
1724 struct i40iw_cm_info *cm_info,
1725 struct i40iw_cm_listener *cm_parent_listen_node)
1726{
1727 struct net_device *dev;
1728 struct in_device *idev;
1729 struct i40iw_cm_listener *child_listen_node;
1730 enum i40iw_status_code ret = 0;
1731 unsigned long flags;
1732
1733 rtnl_lock();
1734 for_each_netdev(&init_net, dev) {
1735 if ((((rdma_vlan_dev_vlan_id(dev) < I40IW_NO_VLAN) &&
1736 (rdma_vlan_dev_real_dev(dev) == iwdev->netdev)) ||
1737 (dev == iwdev->netdev)) && (dev->flags & IFF_UP)) {
1738 idev = in_dev_get(dev);
1739 for_ifa(idev) {
1740 i40iw_debug(&iwdev->sc_dev,
1741 I40IW_DEBUG_CM,
1742 "Allocating child CM Listener forIP=%pI4, vlan_id=%d, MAC=%pM\n",
1743 &ifa->ifa_address,
1744 rdma_vlan_dev_vlan_id(dev),
1745 dev->dev_addr);
1746 child_listen_node = kzalloc(sizeof(*child_listen_node), GFP_ATOMIC);
1747 cm_parent_listen_node->cm_core->stats_listen_nodes_created++;
1748 i40iw_debug(&iwdev->sc_dev,
1749 I40IW_DEBUG_CM,
1750 "Allocating child listener %p\n",
1751 child_listen_node);
1752 if (!child_listen_node) {
1753 i40iw_pr_err("listener memory allocation\n");
1754 in_dev_put(idev);
1755 ret = I40IW_ERR_NO_MEMORY;
1756 goto exit;
1757 }
1758 cm_info->vlan_id = rdma_vlan_dev_vlan_id(dev);
1759 cm_parent_listen_node->vlan_id = cm_info->vlan_id;
1760 memcpy(child_listen_node,
1761 cm_parent_listen_node,
1762 sizeof(*child_listen_node));
1763
1764 child_listen_node->loc_addr[0] = ntohl(ifa->ifa_address);
1765 memcpy(cm_info->loc_addr, child_listen_node->loc_addr,
1766 sizeof(cm_info->loc_addr));
1767
1768 ret = i40iw_manage_qhash(iwdev,
1769 cm_info,
1770 I40IW_QHASH_TYPE_TCP_SYN,
1771 I40IW_QHASH_MANAGE_TYPE_ADD,
1772 NULL,
1773 true);
1774 if (!ret) {
1775 spin_lock_irqsave(&iwdev->cm_core.listen_list_lock, flags);
1776 list_add(&child_listen_node->child_listen_list,
1777 &cm_parent_listen_node->child_listen_list);
1778 spin_unlock_irqrestore(&iwdev->cm_core.listen_list_lock, flags);
1779 } else {
1780 kfree(child_listen_node);
1781 cm_parent_listen_node->cm_core->stats_listen_nodes_created--;
1782 }
1783 }
1784 endfor_ifa(idev);
1785 in_dev_put(idev);
1786 }
1787 }
1788exit:
1789 rtnl_unlock();
1790 return ret;
1791}
1792
1793/**
1794 * i40iw_dec_refcnt_listen - delete listener and associated cm nodes
1795 * @cm_core: cm's core
1796 * @free_hanging_nodes: to free associated cm_nodes
1797 * @apbvt_del: flag to delete the apbvt
1798 */
1799static int i40iw_dec_refcnt_listen(struct i40iw_cm_core *cm_core,
1800 struct i40iw_cm_listener *listener,
1801 int free_hanging_nodes, bool apbvt_del)
1802{
1803 int ret = -EINVAL;
1804 int err = 0;
1805 struct list_head *list_pos;
1806 struct list_head *list_temp;
1807 struct i40iw_cm_node *cm_node;
1808 struct list_head reset_list;
1809 struct i40iw_cm_info nfo;
1810 struct i40iw_cm_node *loopback;
1811 enum i40iw_cm_node_state old_state;
1812 unsigned long flags;
1813
1814 /* free non-accelerated child nodes for this listener */
1815 INIT_LIST_HEAD(&reset_list);
1816 if (free_hanging_nodes) {
1817 spin_lock_irqsave(&cm_core->ht_lock, flags);
1818 list_for_each_safe(list_pos, list_temp, &cm_core->connected_nodes) {
1819 cm_node = container_of(list_pos, struct i40iw_cm_node, list);
1820 if ((cm_node->listener == listener) && !cm_node->accelerated) {
1821 atomic_inc(&cm_node->ref_count);
1822 list_add(&cm_node->reset_entry, &reset_list);
1823 }
1824 }
1825 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
1826 }
1827
1828 list_for_each_safe(list_pos, list_temp, &reset_list) {
1829 cm_node = container_of(list_pos, struct i40iw_cm_node, reset_entry);
1830 loopback = cm_node->loopbackpartner;
1831 if (cm_node->state >= I40IW_CM_STATE_FIN_WAIT1) {
1832 i40iw_rem_ref_cm_node(cm_node);
1833 } else {
1834 if (!loopback) {
1835 i40iw_cleanup_retrans_entry(cm_node);
1836 err = i40iw_send_reset(cm_node);
1837 if (err) {
1838 cm_node->state = I40IW_CM_STATE_CLOSED;
1839 i40iw_pr_err("send reset\n");
1840 } else {
1841 old_state = cm_node->state;
1842 cm_node->state = I40IW_CM_STATE_LISTENER_DESTROYED;
1843 if (old_state != I40IW_CM_STATE_MPAREQ_RCVD)
1844 i40iw_rem_ref_cm_node(cm_node);
1845 }
1846 } else {
1847 struct i40iw_cm_event event;
1848
1849 event.cm_node = loopback;
1850 memcpy(event.cm_info.rem_addr,
1851 loopback->rem_addr, sizeof(event.cm_info.rem_addr));
1852 memcpy(event.cm_info.loc_addr,
1853 loopback->loc_addr, sizeof(event.cm_info.loc_addr));
1854 event.cm_info.rem_port = loopback->rem_port;
1855 event.cm_info.loc_port = loopback->loc_port;
1856 event.cm_info.cm_id = loopback->cm_id;
1857 event.cm_info.ipv4 = loopback->ipv4;
1858 atomic_inc(&loopback->ref_count);
1859 loopback->state = I40IW_CM_STATE_CLOSED;
1860 i40iw_event_connect_error(&event);
1861 cm_node->state = I40IW_CM_STATE_LISTENER_DESTROYED;
1862 i40iw_rem_ref_cm_node(cm_node);
1863 }
1864 }
1865 }
1866
1867 if (!atomic_dec_return(&listener->ref_count)) {
1868 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
1869 list_del(&listener->list);
1870 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1871
1872 if (listener->iwdev) {
1873 if (apbvt_del && !i40iw_listen_port_in_use(cm_core, listener->loc_port))
1874 i40iw_manage_apbvt(listener->iwdev,
1875 listener->loc_port,
1876 I40IW_MANAGE_APBVT_DEL);
1877
1878 memcpy(nfo.loc_addr, listener->loc_addr, sizeof(nfo.loc_addr));
1879 nfo.loc_port = listener->loc_port;
1880 nfo.ipv4 = listener->ipv4;
1881 nfo.vlan_id = listener->vlan_id;
1882
1883 if (!list_empty(&listener->child_listen_list)) {
1884 i40iw_del_multiple_qhash(listener->iwdev, &nfo, listener);
1885 } else {
1886 if (listener->qhash_set)
1887 i40iw_manage_qhash(listener->iwdev,
1888 &nfo,
1889 I40IW_QHASH_TYPE_TCP_SYN,
1890 I40IW_QHASH_MANAGE_TYPE_DELETE,
1891 NULL,
1892 false);
1893 }
1894 }
1895
1896 cm_core->stats_listen_destroyed++;
1897 kfree(listener);
1898 cm_core->stats_listen_nodes_destroyed++;
1899 listener = NULL;
1900 ret = 0;
1901 }
1902
1903 if (listener) {
1904 if (atomic_read(&listener->pend_accepts_cnt) > 0)
1905 i40iw_debug(cm_core->dev,
1906 I40IW_DEBUG_CM,
1907 "%s: listener (%p) pending accepts=%u\n",
1908 __func__,
1909 listener,
1910 atomic_read(&listener->pend_accepts_cnt));
1911 }
1912
1913 return ret;
1914}
1915
1916/**
1917 * i40iw_cm_del_listen - delete a linstener
1918 * @cm_core: cm's core
1919 * @listener: passive connection's listener
1920 * @apbvt_del: flag to delete apbvt
1921 */
1922static int i40iw_cm_del_listen(struct i40iw_cm_core *cm_core,
1923 struct i40iw_cm_listener *listener,
1924 bool apbvt_del)
1925{
1926 listener->listener_state = I40IW_CM_LISTENER_PASSIVE_STATE;
1927 listener->cm_id = NULL; /* going to be destroyed pretty soon */
1928 return i40iw_dec_refcnt_listen(cm_core, listener, 1, apbvt_del);
1929}
1930
1931/**
1932 * i40iw_addr_resolve_neigh - resolve neighbor address
1933 * @iwdev: iwarp device structure
1934 * @src_ip: local ip address
1935 * @dst_ip: remote ip address
1936 * @arpindex: if there is an arp entry
1937 */
1938static int i40iw_addr_resolve_neigh(struct i40iw_device *iwdev,
1939 u32 src_ip,
1940 u32 dst_ip,
1941 int arpindex)
1942{
1943 struct rtable *rt;
1944 struct neighbour *neigh;
1945 int rc = arpindex;
1946 struct net_device *netdev = iwdev->netdev;
1947 __be32 dst_ipaddr = htonl(dst_ip);
1948 __be32 src_ipaddr = htonl(src_ip);
1949
1950 rt = ip_route_output(&init_net, dst_ipaddr, src_ipaddr, 0, 0);
1951 if (IS_ERR(rt)) {
1952 i40iw_pr_err("ip_route_output\n");
1953 return rc;
1954 }
1955
1956 if (netif_is_bond_slave(netdev))
1957 netdev = netdev_master_upper_dev_get(netdev);
1958
1959 neigh = dst_neigh_lookup(&rt->dst, &dst_ipaddr);
1960
1961 rcu_read_lock();
1962 if (neigh) {
1963 if (neigh->nud_state & NUD_VALID) {
1964 if (arpindex >= 0) {
1965 if (ether_addr_equal(iwdev->arp_table[arpindex].mac_addr,
1966 neigh->ha))
1967 /* Mac address same as arp table */
1968 goto resolve_neigh_exit;
1969 i40iw_manage_arp_cache(iwdev,
1970 iwdev->arp_table[arpindex].mac_addr,
1971 &dst_ip,
1972 true,
1973 I40IW_ARP_DELETE);
1974 }
1975
1976 i40iw_manage_arp_cache(iwdev, neigh->ha, &dst_ip, true, I40IW_ARP_ADD);
1977 rc = i40iw_arp_table(iwdev, &dst_ip, true, NULL, I40IW_ARP_RESOLVE);
1978 } else {
1979 neigh_event_send(neigh, NULL);
1980 }
1981 }
1982 resolve_neigh_exit:
1983
1984 rcu_read_unlock();
1985 if (neigh)
1986 neigh_release(neigh);
1987
1988 ip_rt_put(rt);
1989 return rc;
1990}
1991
1992/**
1993 * i40iw_get_dst_ipv6
1994 */
1995#if IS_ENABLED(CONFIG_IPV6)
1996static struct dst_entry *i40iw_get_dst_ipv6(struct sockaddr_in6 *src_addr,
1997 struct sockaddr_in6 *dst_addr)
1998{
1999 struct dst_entry *dst;
2000 struct flowi6 fl6;
2001
2002 memset(&fl6, 0, sizeof(fl6));
2003 fl6.daddr = dst_addr->sin6_addr;
2004 fl6.saddr = src_addr->sin6_addr;
2005 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
2006 fl6.flowi6_oif = dst_addr->sin6_scope_id;
2007
2008 dst = ip6_route_output(&init_net, NULL, &fl6);
2009 return dst;
2010}
2011#endif
2012
2013/**
2014 * i40iw_addr_resolve_neigh_ipv6 - resolve neighbor ipv6 address
2015 * @iwdev: iwarp device structure
2016 * @dst_ip: remote ip address
2017 * @arpindex: if there is an arp entry
2018 */
2019#if IS_ENABLED(CONFIG_IPV6)
2020static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device *iwdev,
2021 u32 *src,
2022 u32 *dest,
2023 int arpindex)
2024{
2025 struct neighbour *neigh;
2026 int rc = arpindex;
2027 struct net_device *netdev = iwdev->netdev;
2028 struct dst_entry *dst;
2029 struct sockaddr_in6 dst_addr;
2030 struct sockaddr_in6 src_addr;
2031
2032 memset(&dst_addr, 0, sizeof(dst_addr));
2033 dst_addr.sin6_family = AF_INET6;
2034 i40iw_copy_ip_htonl(dst_addr.sin6_addr.in6_u.u6_addr32, dest);
2035 memset(&src_addr, 0, sizeof(src_addr));
2036 src_addr.sin6_family = AF_INET6;
2037 i40iw_copy_ip_htonl(src_addr.sin6_addr.in6_u.u6_addr32, src);
2038 dst = i40iw_get_dst_ipv6(&src_addr, &dst_addr);
2039 if (!dst || dst->error) {
2040 if (dst) {
2041 dst_release(dst);
2042 i40iw_pr_err("ip6_route_output returned dst->error = %d\n",
2043 dst->error);
2044 }
2045 return rc;
2046 }
2047
2048 if (netif_is_bond_slave(netdev))
2049 netdev = netdev_master_upper_dev_get(netdev);
2050
2051 neigh = dst_neigh_lookup(dst, &dst_addr);
2052
2053 rcu_read_lock();
2054 if (neigh) {
2055 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_CM, "dst_neigh_lookup MAC=%pM\n", neigh->ha);
2056 if (neigh->nud_state & NUD_VALID) {
2057 if (arpindex >= 0) {
2058 if (ether_addr_equal
2059 (iwdev->arp_table[arpindex].mac_addr,
2060 neigh->ha)) {
2061 /* Mac address same as in arp table */
2062 goto resolve_neigh_exit6;
2063 }
2064 i40iw_manage_arp_cache(iwdev,
2065 iwdev->arp_table[arpindex].mac_addr,
2066 dest,
2067 false,
2068 I40IW_ARP_DELETE);
2069 }
2070 i40iw_manage_arp_cache(iwdev,
2071 neigh->ha,
2072 dest,
2073 false,
2074 I40IW_ARP_ADD);
2075 rc = i40iw_arp_table(iwdev,
2076 dest,
2077 false,
2078 NULL,
2079 I40IW_ARP_RESOLVE);
2080 } else {
2081 neigh_event_send(neigh, NULL);
2082 }
2083 }
2084
2085 resolve_neigh_exit6:
2086 rcu_read_unlock();
2087 if (neigh)
2088 neigh_release(neigh);
2089 dst_release(dst);
2090 return rc;
2091}
2092#endif
2093
2094/**
2095 * i40iw_ipv4_is_loopback - check if loopback
2096 * @loc_addr: local addr to compare
2097 * @rem_addr: remote address
2098 */
2099static bool i40iw_ipv4_is_loopback(u32 loc_addr, u32 rem_addr)
2100{
2101 return ipv4_is_loopback(htonl(rem_addr)) || (loc_addr == rem_addr);
2102}
2103
2104/**
2105 * i40iw_ipv6_is_loopback - check if loopback
2106 * @loc_addr: local addr to compare
2107 * @rem_addr: remote address
2108 */
2109static bool i40iw_ipv6_is_loopback(u32 *loc_addr, u32 *rem_addr)
2110{
2111 struct in6_addr raddr6;
2112
2113 i40iw_copy_ip_htonl(raddr6.in6_u.u6_addr32, rem_addr);
2114 return (!memcmp(loc_addr, rem_addr, 16) || ipv6_addr_loopback(&raddr6));
2115}
2116
2117/**
2118 * i40iw_make_cm_node - create a new instance of a cm node
2119 * @cm_core: cm's core
2120 * @iwdev: iwarp device structure
2121 * @cm_info: quad info for connection
2122 * @listener: passive connection's listener
2123 */
2124static struct i40iw_cm_node *i40iw_make_cm_node(
2125 struct i40iw_cm_core *cm_core,
2126 struct i40iw_device *iwdev,
2127 struct i40iw_cm_info *cm_info,
2128 struct i40iw_cm_listener *listener)
2129{
2130 struct i40iw_cm_node *cm_node;
2131 struct timespec ts;
2132 int oldarpindex;
2133 int arpindex;
2134 struct net_device *netdev = iwdev->netdev;
2135
2136 /* create an hte and cm_node for this instance */
2137 cm_node = kzalloc(sizeof(*cm_node), GFP_ATOMIC);
2138 if (!cm_node)
2139 return NULL;
2140
2141 /* set our node specific transport info */
2142 cm_node->ipv4 = cm_info->ipv4;
2143 cm_node->vlan_id = cm_info->vlan_id;
2144 memcpy(cm_node->loc_addr, cm_info->loc_addr, sizeof(cm_node->loc_addr));
2145 memcpy(cm_node->rem_addr, cm_info->rem_addr, sizeof(cm_node->rem_addr));
2146 cm_node->loc_port = cm_info->loc_port;
2147 cm_node->rem_port = cm_info->rem_port;
2148
2149 cm_node->mpa_frame_rev = iwdev->mpa_version;
2150 cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
2151 cm_node->ird_size = I40IW_MAX_IRD_SIZE;
2152 cm_node->ord_size = I40IW_MAX_ORD_SIZE;
2153
2154 cm_node->listener = listener;
2155 cm_node->cm_id = cm_info->cm_id;
2156 ether_addr_copy(cm_node->loc_mac, netdev->dev_addr);
2157 spin_lock_init(&cm_node->retrans_list_lock);
2158
2159 atomic_set(&cm_node->ref_count, 1);
2160 /* associate our parent CM core */
2161 cm_node->cm_core = cm_core;
2162 cm_node->tcp_cntxt.loc_id = I40IW_CM_DEF_LOCAL_ID;
2163 cm_node->tcp_cntxt.rcv_wscale = I40IW_CM_DEFAULT_RCV_WND_SCALE;
2164 cm_node->tcp_cntxt.rcv_wnd =
2165 I40IW_CM_DEFAULT_RCV_WND_SCALED >> I40IW_CM_DEFAULT_RCV_WND_SCALE;
2166 ts = current_kernel_time();
2167 cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec);
2168 cm_node->tcp_cntxt.mss = iwdev->mss;
2169
2170 cm_node->iwdev = iwdev;
2171 cm_node->dev = &iwdev->sc_dev;
2172
2173 if ((cm_node->ipv4 &&
2174 i40iw_ipv4_is_loopback(cm_node->loc_addr[0], cm_node->rem_addr[0])) ||
2175 (!cm_node->ipv4 && i40iw_ipv6_is_loopback(cm_node->loc_addr,
2176 cm_node->rem_addr))) {
2177 arpindex = i40iw_arp_table(iwdev,
2178 cm_node->rem_addr,
2179 false,
2180 NULL,
2181 I40IW_ARP_RESOLVE);
2182 } else {
2183 oldarpindex = i40iw_arp_table(iwdev,
2184 cm_node->rem_addr,
2185 false,
2186 NULL,
2187 I40IW_ARP_RESOLVE);
2188 if (cm_node->ipv4)
2189 arpindex = i40iw_addr_resolve_neigh(iwdev,
2190 cm_info->loc_addr[0],
2191 cm_info->rem_addr[0],
2192 oldarpindex);
2193#if IS_ENABLED(CONFIG_IPV6)
2194 else
2195 arpindex = i40iw_addr_resolve_neigh_ipv6(iwdev,
2196 cm_info->loc_addr,
2197 cm_info->rem_addr,
2198 oldarpindex);
2199#endif
2200 }
2201 if (arpindex < 0) {
2202 i40iw_pr_err("cm_node arpindex\n");
2203 kfree(cm_node);
2204 return NULL;
2205 }
2206 ether_addr_copy(cm_node->rem_mac, iwdev->arp_table[arpindex].mac_addr);
2207 i40iw_add_hte_node(cm_core, cm_node);
2208 cm_core->stats_nodes_created++;
2209 return cm_node;
2210}
2211
2212/**
2213 * i40iw_rem_ref_cm_node - destroy an instance of a cm node
2214 * @cm_node: connection's node
2215 */
2216static void i40iw_rem_ref_cm_node(struct i40iw_cm_node *cm_node)
2217{
2218 struct i40iw_cm_core *cm_core = cm_node->cm_core;
2219 struct i40iw_qp *iwqp;
2220 struct i40iw_cm_info nfo;
2221 unsigned long flags;
2222
2223 spin_lock_irqsave(&cm_node->cm_core->ht_lock, flags);
2224 if (atomic_dec_return(&cm_node->ref_count)) {
2225 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
2226 return;
2227 }
2228 list_del(&cm_node->list);
2229 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
2230
2231 /* if the node is destroyed before connection was accelerated */
2232 if (!cm_node->accelerated && cm_node->accept_pend) {
2233 pr_err("node destroyed before established\n");
2234 atomic_dec(&cm_node->listener->pend_accepts_cnt);
2235 }
2236 if (cm_node->close_entry)
2237 i40iw_handle_close_entry(cm_node, 0);
2238 if (cm_node->listener) {
2239 i40iw_dec_refcnt_listen(cm_core, cm_node->listener, 0, true);
2240 } else {
2241 if (!i40iw_listen_port_in_use(cm_core, htons(cm_node->loc_port)) &&
2242 cm_node->apbvt_set && cm_node->iwdev) {
2243 i40iw_manage_apbvt(cm_node->iwdev,
2244 cm_node->loc_port,
2245 I40IW_MANAGE_APBVT_DEL);
2246 i40iw_get_addr_info(cm_node, &nfo);
2247 if (cm_node->qhash_set) {
2248 i40iw_manage_qhash(cm_node->iwdev,
2249 &nfo,
2250 I40IW_QHASH_TYPE_TCP_ESTABLISHED,
2251 I40IW_QHASH_MANAGE_TYPE_DELETE,
2252 NULL,
2253 false);
2254 cm_node->qhash_set = 0;
2255 }
2256 }
2257 }
2258
2259 iwqp = cm_node->iwqp;
2260 if (iwqp) {
2261 iwqp->cm_node = NULL;
2262 i40iw_rem_ref(&iwqp->ibqp);
2263 cm_node->iwqp = NULL;
2264 } else if (cm_node->qhash_set) {
2265 i40iw_get_addr_info(cm_node, &nfo);
2266 i40iw_manage_qhash(cm_node->iwdev,
2267 &nfo,
2268 I40IW_QHASH_TYPE_TCP_ESTABLISHED,
2269 I40IW_QHASH_MANAGE_TYPE_DELETE,
2270 NULL,
2271 false);
2272 cm_node->qhash_set = 0;
2273 }
2274
2275 cm_node->cm_core->stats_nodes_destroyed++;
2276 kfree(cm_node);
2277}
2278
2279/**
2280 * i40iw_handle_fin_pkt - FIN packet received
2281 * @cm_node: connection's node
2282 */
2283static void i40iw_handle_fin_pkt(struct i40iw_cm_node *cm_node)
2284{
2285 u32 ret;
2286
2287 switch (cm_node->state) {
2288 case I40IW_CM_STATE_SYN_RCVD:
2289 case I40IW_CM_STATE_SYN_SENT:
2290 case I40IW_CM_STATE_ESTABLISHED:
2291 case I40IW_CM_STATE_MPAREJ_RCVD:
2292 cm_node->tcp_cntxt.rcv_nxt++;
2293 i40iw_cleanup_retrans_entry(cm_node);
2294 cm_node->state = I40IW_CM_STATE_LAST_ACK;
2295 i40iw_send_fin(cm_node);
2296 break;
2297 case I40IW_CM_STATE_MPAREQ_SENT:
2298 i40iw_create_event(cm_node, I40IW_CM_EVENT_ABORTED);
2299 cm_node->tcp_cntxt.rcv_nxt++;
2300 i40iw_cleanup_retrans_entry(cm_node);
2301 cm_node->state = I40IW_CM_STATE_CLOSED;
2302 atomic_inc(&cm_node->ref_count);
2303 i40iw_send_reset(cm_node);
2304 break;
2305 case I40IW_CM_STATE_FIN_WAIT1:
2306 cm_node->tcp_cntxt.rcv_nxt++;
2307 i40iw_cleanup_retrans_entry(cm_node);
2308 cm_node->state = I40IW_CM_STATE_CLOSING;
2309 i40iw_send_ack(cm_node);
2310 /*
2311 * Wait for ACK as this is simultaneous close.
2312 * After we receive ACK, do not send anything.
2313 * Just rm the node.
2314 */
2315 break;
2316 case I40IW_CM_STATE_FIN_WAIT2:
2317 cm_node->tcp_cntxt.rcv_nxt++;
2318 i40iw_cleanup_retrans_entry(cm_node);
2319 cm_node->state = I40IW_CM_STATE_TIME_WAIT;
2320 i40iw_send_ack(cm_node);
2321 ret =
2322 i40iw_schedule_cm_timer(cm_node, NULL, I40IW_TIMER_TYPE_CLOSE, 1, 0);
2323 if (ret)
2324 i40iw_pr_err("node %p state = %d\n", cm_node, cm_node->state);
2325 break;
2326 case I40IW_CM_STATE_TIME_WAIT:
2327 cm_node->tcp_cntxt.rcv_nxt++;
2328 i40iw_cleanup_retrans_entry(cm_node);
2329 cm_node->state = I40IW_CM_STATE_CLOSED;
2330 i40iw_rem_ref_cm_node(cm_node);
2331 break;
2332 case I40IW_CM_STATE_OFFLOADED:
2333 default:
2334 i40iw_pr_err("bad state node %p state = %d\n", cm_node, cm_node->state);
2335 break;
2336 }
2337}
2338
2339/**
2340 * i40iw_handle_rst_pkt - process received RST packet
2341 * @cm_node: connection's node
2342 * @rbuf: receive buffer
2343 */
2344static void i40iw_handle_rst_pkt(struct i40iw_cm_node *cm_node,
2345 struct i40iw_puda_buf *rbuf)
2346{
2347 i40iw_cleanup_retrans_entry(cm_node);
2348 switch (cm_node->state) {
2349 case I40IW_CM_STATE_SYN_SENT:
2350 case I40IW_CM_STATE_MPAREQ_SENT:
2351 switch (cm_node->mpa_frame_rev) {
2352 case IETF_MPA_V2:
2353 cm_node->mpa_frame_rev = IETF_MPA_V1;
2354 /* send a syn and goto syn sent state */
2355 cm_node->state = I40IW_CM_STATE_SYN_SENT;
2356 if (i40iw_send_syn(cm_node, 0))
2357 i40iw_active_open_err(cm_node, false);
2358 break;
2359 case IETF_MPA_V1:
2360 default:
2361 i40iw_active_open_err(cm_node, false);
2362 break;
2363 }
2364 break;
2365 case I40IW_CM_STATE_MPAREQ_RCVD:
2366 atomic_add_return(1, &cm_node->passive_state);
2367 break;
2368 case I40IW_CM_STATE_ESTABLISHED:
2369 case I40IW_CM_STATE_SYN_RCVD:
2370 case I40IW_CM_STATE_LISTENING:
2371 i40iw_pr_err("Bad state state = %d\n", cm_node->state);
2372 i40iw_passive_open_err(cm_node, false);
2373 break;
2374 case I40IW_CM_STATE_OFFLOADED:
2375 i40iw_active_open_err(cm_node, false);
2376 break;
2377 case I40IW_CM_STATE_CLOSED:
2378 break;
2379 case I40IW_CM_STATE_FIN_WAIT2:
2380 case I40IW_CM_STATE_FIN_WAIT1:
2381 case I40IW_CM_STATE_LAST_ACK:
2382 cm_node->cm_id->rem_ref(cm_node->cm_id);
2383 case I40IW_CM_STATE_TIME_WAIT:
2384 cm_node->state = I40IW_CM_STATE_CLOSED;
2385 i40iw_rem_ref_cm_node(cm_node);
2386 break;
2387 default:
2388 break;
2389 }
2390}
2391
2392/**
2393 * i40iw_handle_rcv_mpa - Process a recv'd mpa buffer
2394 * @cm_node: connection's node
2395 * @rbuf: receive buffer
2396 */
2397static void i40iw_handle_rcv_mpa(struct i40iw_cm_node *cm_node,
2398 struct i40iw_puda_buf *rbuf)
2399{
2400 int ret;
2401 int datasize = rbuf->datalen;
2402 u8 *dataloc = rbuf->data;
2403
2404 enum i40iw_cm_event_type type = I40IW_CM_EVENT_UNKNOWN;
2405 u32 res_type;
2406
2407 ret = i40iw_parse_mpa(cm_node, dataloc, &res_type, datasize);
2408 if (ret) {
2409 if (cm_node->state == I40IW_CM_STATE_MPAREQ_SENT)
2410 i40iw_active_open_err(cm_node, true);
2411 else
2412 i40iw_passive_open_err(cm_node, true);
2413 return;
2414 }
2415
2416 switch (cm_node->state) {
2417 case I40IW_CM_STATE_ESTABLISHED:
2418 if (res_type == I40IW_MPA_REQUEST_REJECT)
2419 i40iw_pr_err("state for reject\n");
2420 cm_node->state = I40IW_CM_STATE_MPAREQ_RCVD;
2421 type = I40IW_CM_EVENT_MPA_REQ;
2422 i40iw_send_ack(cm_node); /* ACK received MPA request */
2423 atomic_set(&cm_node->passive_state,
2424 I40IW_PASSIVE_STATE_INDICATED);
2425 break;
2426 case I40IW_CM_STATE_MPAREQ_SENT:
2427 i40iw_cleanup_retrans_entry(cm_node);
2428 if (res_type == I40IW_MPA_REQUEST_REJECT) {
2429 type = I40IW_CM_EVENT_MPA_REJECT;
2430 cm_node->state = I40IW_CM_STATE_MPAREJ_RCVD;
2431 } else {
2432 type = I40IW_CM_EVENT_CONNECTED;
2433 cm_node->state = I40IW_CM_STATE_OFFLOADED;
2434 i40iw_send_ack(cm_node);
2435 }
2436 break;
2437 default:
2438 pr_err("%s wrong cm_node state =%d\n", __func__, cm_node->state);
2439 break;
2440 }
2441 i40iw_create_event(cm_node, type);
2442}
2443
2444/**
2445 * i40iw_indicate_pkt_err - Send up err event to cm
2446 * @cm_node: connection's node
2447 */
2448static void i40iw_indicate_pkt_err(struct i40iw_cm_node *cm_node)
2449{
2450 switch (cm_node->state) {
2451 case I40IW_CM_STATE_SYN_SENT:
2452 case I40IW_CM_STATE_MPAREQ_SENT:
2453 i40iw_active_open_err(cm_node, true);
2454 break;
2455 case I40IW_CM_STATE_ESTABLISHED:
2456 case I40IW_CM_STATE_SYN_RCVD:
2457 i40iw_passive_open_err(cm_node, true);
2458 break;
2459 case I40IW_CM_STATE_OFFLOADED:
2460 default:
2461 break;
2462 }
2463}
2464
2465/**
2466 * i40iw_check_syn - Check for error on received syn ack
2467 * @cm_node: connection's node
2468 * @tcph: pointer tcp header
2469 */
2470static int i40iw_check_syn(struct i40iw_cm_node *cm_node, struct tcphdr *tcph)
2471{
2472 int err = 0;
2473
2474 if (ntohl(tcph->ack_seq) != cm_node->tcp_cntxt.loc_seq_num) {
2475 err = 1;
2476 i40iw_active_open_err(cm_node, true);
2477 }
2478 return err;
2479}
2480
2481/**
2482 * i40iw_check_seq - check seq numbers if OK
2483 * @cm_node: connection's node
2484 * @tcph: pointer tcp header
2485 */
2486static int i40iw_check_seq(struct i40iw_cm_node *cm_node, struct tcphdr *tcph)
2487{
2488 int err = 0;
2489 u32 seq;
2490 u32 ack_seq;
2491 u32 loc_seq_num = cm_node->tcp_cntxt.loc_seq_num;
2492 u32 rcv_nxt = cm_node->tcp_cntxt.rcv_nxt;
2493 u32 rcv_wnd;
2494
2495 seq = ntohl(tcph->seq);
2496 ack_seq = ntohl(tcph->ack_seq);
2497 rcv_wnd = cm_node->tcp_cntxt.rcv_wnd;
2498 if (ack_seq != loc_seq_num)
2499 err = -1;
2500 else if (!between(seq, rcv_nxt, (rcv_nxt + rcv_wnd)))
2501 err = -1;
2502 if (err) {
2503 i40iw_pr_err("seq number\n");
2504 i40iw_indicate_pkt_err(cm_node);
2505 }
2506 return err;
2507}
2508
2509/**
2510 * i40iw_handle_syn_pkt - is for Passive node
2511 * @cm_node: connection's node
2512 * @rbuf: receive buffer
2513 */
2514static void i40iw_handle_syn_pkt(struct i40iw_cm_node *cm_node,
2515 struct i40iw_puda_buf *rbuf)
2516{
2517 struct tcphdr *tcph = (struct tcphdr *)rbuf->tcph;
2518 int ret;
2519 u32 inc_sequence;
2520 int optionsize;
2521 struct i40iw_cm_info nfo;
2522
2523 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
2524 inc_sequence = ntohl(tcph->seq);
2525
2526 switch (cm_node->state) {
2527 case I40IW_CM_STATE_SYN_SENT:
2528 case I40IW_CM_STATE_MPAREQ_SENT:
2529 /* Rcvd syn on active open connection */
2530 i40iw_active_open_err(cm_node, 1);
2531 break;
2532 case I40IW_CM_STATE_LISTENING:
2533 /* Passive OPEN */
2534 if (atomic_read(&cm_node->listener->pend_accepts_cnt) >
2535 cm_node->listener->backlog) {
2536 cm_node->cm_core->stats_backlog_drops++;
2537 i40iw_passive_open_err(cm_node, false);
2538 break;
2539 }
2540 ret = i40iw_handle_tcp_options(cm_node, tcph, optionsize, 1);
2541 if (ret) {
2542 i40iw_passive_open_err(cm_node, false);
2543 /* drop pkt */
2544 break;
2545 }
2546 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
2547 cm_node->accept_pend = 1;
2548 atomic_inc(&cm_node->listener->pend_accepts_cnt);
2549
2550 cm_node->state = I40IW_CM_STATE_SYN_RCVD;
2551 i40iw_get_addr_info(cm_node, &nfo);
2552 ret = i40iw_manage_qhash(cm_node->iwdev,
2553 &nfo,
2554 I40IW_QHASH_TYPE_TCP_ESTABLISHED,
2555 I40IW_QHASH_MANAGE_TYPE_ADD,
2556 (void *)cm_node,
2557 false);
2558 cm_node->qhash_set = true;
2559 break;
2560 case I40IW_CM_STATE_CLOSED:
2561 i40iw_cleanup_retrans_entry(cm_node);
2562 atomic_inc(&cm_node->ref_count);
2563 i40iw_send_reset(cm_node);
2564 break;
2565 case I40IW_CM_STATE_OFFLOADED:
2566 case I40IW_CM_STATE_ESTABLISHED:
2567 case I40IW_CM_STATE_FIN_WAIT1:
2568 case I40IW_CM_STATE_FIN_WAIT2:
2569 case I40IW_CM_STATE_MPAREQ_RCVD:
2570 case I40IW_CM_STATE_LAST_ACK:
2571 case I40IW_CM_STATE_CLOSING:
2572 case I40IW_CM_STATE_UNKNOWN:
2573 default:
2574 break;
2575 }
2576}
2577
2578/**
2579 * i40iw_handle_synack_pkt - Process SYN+ACK packet (active side)
2580 * @cm_node: connection's node
2581 * @rbuf: receive buffer
2582 */
2583static void i40iw_handle_synack_pkt(struct i40iw_cm_node *cm_node,
2584 struct i40iw_puda_buf *rbuf)
2585{
2586 struct tcphdr *tcph = (struct tcphdr *)rbuf->tcph;
2587 int ret;
2588 u32 inc_sequence;
2589 int optionsize;
2590
2591 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
2592 inc_sequence = ntohl(tcph->seq);
2593 switch (cm_node->state) {
2594 case I40IW_CM_STATE_SYN_SENT:
2595 i40iw_cleanup_retrans_entry(cm_node);
2596 /* active open */
2597 if (i40iw_check_syn(cm_node, tcph)) {
2598 i40iw_pr_err("check syn fail\n");
2599 return;
2600 }
2601 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
2602 /* setup options */
2603 ret = i40iw_handle_tcp_options(cm_node, tcph, optionsize, 0);
2604 if (ret) {
2605 i40iw_debug(cm_node->dev,
2606 I40IW_DEBUG_CM,
2607 "cm_node=%p tcp_options failed\n",
2608 cm_node);
2609 break;
2610 }
2611 i40iw_cleanup_retrans_entry(cm_node);
2612 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
2613 i40iw_send_ack(cm_node); /* ACK for the syn_ack */
2614 ret = i40iw_send_mpa_request(cm_node);
2615 if (ret) {
2616 i40iw_debug(cm_node->dev,
2617 I40IW_DEBUG_CM,
2618 "cm_node=%p i40iw_send_mpa_request failed\n",
2619 cm_node);
2620 break;
2621 }
2622 cm_node->state = I40IW_CM_STATE_MPAREQ_SENT;
2623 break;
2624 case I40IW_CM_STATE_MPAREQ_RCVD:
2625 i40iw_passive_open_err(cm_node, true);
2626 break;
2627 case I40IW_CM_STATE_LISTENING:
2628 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
2629 i40iw_cleanup_retrans_entry(cm_node);
2630 cm_node->state = I40IW_CM_STATE_CLOSED;
2631 i40iw_send_reset(cm_node);
2632 break;
2633 case I40IW_CM_STATE_CLOSED:
2634 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
2635 i40iw_cleanup_retrans_entry(cm_node);
2636 atomic_inc(&cm_node->ref_count);
2637 i40iw_send_reset(cm_node);
2638 break;
2639 case I40IW_CM_STATE_ESTABLISHED:
2640 case I40IW_CM_STATE_FIN_WAIT1:
2641 case I40IW_CM_STATE_FIN_WAIT2:
2642 case I40IW_CM_STATE_LAST_ACK:
2643 case I40IW_CM_STATE_OFFLOADED:
2644 case I40IW_CM_STATE_CLOSING:
2645 case I40IW_CM_STATE_UNKNOWN:
2646 case I40IW_CM_STATE_MPAREQ_SENT:
2647 default:
2648 break;
2649 }
2650}
2651
2652/**
2653 * i40iw_handle_ack_pkt - process packet with ACK
2654 * @cm_node: connection's node
2655 * @rbuf: receive buffer
2656 */
2657static int i40iw_handle_ack_pkt(struct i40iw_cm_node *cm_node,
2658 struct i40iw_puda_buf *rbuf)
2659{
2660 struct tcphdr *tcph = (struct tcphdr *)rbuf->tcph;
2661 u32 inc_sequence;
2662 int ret = 0;
2663 int optionsize;
2664 u32 datasize = rbuf->datalen;
2665
2666 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
2667
2668 if (i40iw_check_seq(cm_node, tcph))
2669 return -EINVAL;
2670
2671 inc_sequence = ntohl(tcph->seq);
2672 switch (cm_node->state) {
2673 case I40IW_CM_STATE_SYN_RCVD:
2674 i40iw_cleanup_retrans_entry(cm_node);
2675 ret = i40iw_handle_tcp_options(cm_node, tcph, optionsize, 1);
2676 if (ret)
2677 break;
2678 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
2679 cm_node->state = I40IW_CM_STATE_ESTABLISHED;
2680 if (datasize) {
2681 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2682 i40iw_handle_rcv_mpa(cm_node, rbuf);
2683 }
2684 break;
2685 case I40IW_CM_STATE_ESTABLISHED:
2686 i40iw_cleanup_retrans_entry(cm_node);
2687 if (datasize) {
2688 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2689 i40iw_handle_rcv_mpa(cm_node, rbuf);
2690 }
2691 break;
2692 case I40IW_CM_STATE_MPAREQ_SENT:
2693 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
2694 if (datasize) {
2695 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2696 i40iw_handle_rcv_mpa(cm_node, rbuf);
2697 }
2698 break;
2699 case I40IW_CM_STATE_LISTENING:
2700 i40iw_cleanup_retrans_entry(cm_node);
2701 cm_node->state = I40IW_CM_STATE_CLOSED;
2702 i40iw_send_reset(cm_node);
2703 break;
2704 case I40IW_CM_STATE_CLOSED:
2705 i40iw_cleanup_retrans_entry(cm_node);
2706 atomic_inc(&cm_node->ref_count);
2707 i40iw_send_reset(cm_node);
2708 break;
2709 case I40IW_CM_STATE_LAST_ACK:
2710 case I40IW_CM_STATE_CLOSING:
2711 i40iw_cleanup_retrans_entry(cm_node);
2712 cm_node->state = I40IW_CM_STATE_CLOSED;
2713 if (!cm_node->accept_pend)
2714 cm_node->cm_id->rem_ref(cm_node->cm_id);
2715 i40iw_rem_ref_cm_node(cm_node);
2716 break;
2717 case I40IW_CM_STATE_FIN_WAIT1:
2718 i40iw_cleanup_retrans_entry(cm_node);
2719 cm_node->state = I40IW_CM_STATE_FIN_WAIT2;
2720 break;
2721 case I40IW_CM_STATE_SYN_SENT:
2722 case I40IW_CM_STATE_FIN_WAIT2:
2723 case I40IW_CM_STATE_OFFLOADED:
2724 case I40IW_CM_STATE_MPAREQ_RCVD:
2725 case I40IW_CM_STATE_UNKNOWN:
2726 default:
2727 i40iw_cleanup_retrans_entry(cm_node);
2728 break;
2729 }
2730 return ret;
2731}
2732
2733/**
2734 * i40iw_process_packet - process cm packet
2735 * @cm_node: connection's node
2736 * @rbuf: receive buffer
2737 */
2738static void i40iw_process_packet(struct i40iw_cm_node *cm_node,
2739 struct i40iw_puda_buf *rbuf)
2740{
2741 enum i40iw_tcpip_pkt_type pkt_type = I40IW_PKT_TYPE_UNKNOWN;
2742 struct tcphdr *tcph = (struct tcphdr *)rbuf->tcph;
2743 u32 fin_set = 0;
2744 int ret;
2745
2746 if (tcph->rst) {
2747 pkt_type = I40IW_PKT_TYPE_RST;
2748 } else if (tcph->syn) {
2749 pkt_type = I40IW_PKT_TYPE_SYN;
2750 if (tcph->ack)
2751 pkt_type = I40IW_PKT_TYPE_SYNACK;
2752 } else if (tcph->ack) {
2753 pkt_type = I40IW_PKT_TYPE_ACK;
2754 }
2755 if (tcph->fin)
2756 fin_set = 1;
2757
2758 switch (pkt_type) {
2759 case I40IW_PKT_TYPE_SYN:
2760 i40iw_handle_syn_pkt(cm_node, rbuf);
2761 break;
2762 case I40IW_PKT_TYPE_SYNACK:
2763 i40iw_handle_synack_pkt(cm_node, rbuf);
2764 break;
2765 case I40IW_PKT_TYPE_ACK:
2766 ret = i40iw_handle_ack_pkt(cm_node, rbuf);
2767 if (fin_set && !ret)
2768 i40iw_handle_fin_pkt(cm_node);
2769 break;
2770 case I40IW_PKT_TYPE_RST:
2771 i40iw_handle_rst_pkt(cm_node, rbuf);
2772 break;
2773 default:
2774 if (fin_set &&
2775 (!i40iw_check_seq(cm_node, (struct tcphdr *)rbuf->tcph)))
2776 i40iw_handle_fin_pkt(cm_node);
2777 break;
2778 }
2779}
2780
2781/**
2782 * i40iw_make_listen_node - create a listen node with params
2783 * @cm_core: cm's core
2784 * @iwdev: iwarp device structure
2785 * @cm_info: quad info for connection
2786 */
2787static struct i40iw_cm_listener *i40iw_make_listen_node(
2788 struct i40iw_cm_core *cm_core,
2789 struct i40iw_device *iwdev,
2790 struct i40iw_cm_info *cm_info)
2791{
2792 struct i40iw_cm_listener *listener;
2793 unsigned long flags;
2794
2795 /* cannot have multiple matching listeners */
2796 listener = i40iw_find_listener(cm_core, cm_info->loc_addr,
2797 cm_info->loc_port,
2798 cm_info->vlan_id,
2799 I40IW_CM_LISTENER_EITHER_STATE);
2800 if (listener &&
2801 (listener->listener_state == I40IW_CM_LISTENER_ACTIVE_STATE)) {
2802 atomic_dec(&listener->ref_count);
2803 i40iw_debug(cm_core->dev,
2804 I40IW_DEBUG_CM,
2805 "Not creating listener since it already exists\n");
2806 return NULL;
2807 }
2808
2809 if (!listener) {
2810 /* create a CM listen node (1/2 node to compare incoming traffic to) */
2811 listener = kzalloc(sizeof(*listener), GFP_ATOMIC);
2812 if (!listener)
2813 return NULL;
2814 cm_core->stats_listen_nodes_created++;
2815 memcpy(listener->loc_addr, cm_info->loc_addr, sizeof(listener->loc_addr));
2816 listener->loc_port = cm_info->loc_port;
2817
2818 INIT_LIST_HEAD(&listener->child_listen_list);
2819
2820 atomic_set(&listener->ref_count, 1);
2821 } else {
2822 listener->reused_node = 1;
2823 }
2824
2825 listener->cm_id = cm_info->cm_id;
2826 listener->ipv4 = cm_info->ipv4;
2827 listener->vlan_id = cm_info->vlan_id;
2828 atomic_set(&listener->pend_accepts_cnt, 0);
2829 listener->cm_core = cm_core;
2830 listener->iwdev = iwdev;
2831
2832 listener->backlog = cm_info->backlog;
2833 listener->listener_state = I40IW_CM_LISTENER_ACTIVE_STATE;
2834
2835 if (!listener->reused_node) {
2836 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
2837 list_add(&listener->list, &cm_core->listen_nodes);
2838 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
2839 }
2840
2841 return listener;
2842}
2843
2844/**
2845 * i40iw_create_cm_node - make a connection node with params
2846 * @cm_core: cm's core
2847 * @iwdev: iwarp device structure
2848 * @private_data_len: len to provate data for mpa request
2849 * @private_data: pointer to private data for connection
2850 * @cm_info: quad info for connection
2851 */
2852static struct i40iw_cm_node *i40iw_create_cm_node(
2853 struct i40iw_cm_core *cm_core,
2854 struct i40iw_device *iwdev,
2855 u16 private_data_len,
2856 void *private_data,
2857 struct i40iw_cm_info *cm_info)
2858{
2859 int ret;
2860 struct i40iw_cm_node *cm_node;
2861 struct i40iw_cm_listener *loopback_remotelistener;
2862 struct i40iw_cm_node *loopback_remotenode;
2863 struct i40iw_cm_info loopback_cm_info;
2864
2865 /* create a CM connection node */
2866 cm_node = i40iw_make_cm_node(cm_core, iwdev, cm_info, NULL);
2867 if (!cm_node)
2868 return NULL;
2869 /* set our node side to client (active) side */
2870 cm_node->tcp_cntxt.client = 1;
2871 cm_node->tcp_cntxt.rcv_wscale = I40IW_CM_DEFAULT_RCV_WND_SCALE;
2872
2873 if (!memcmp(cm_info->loc_addr, cm_info->rem_addr, sizeof(cm_info->loc_addr))) {
2874 loopback_remotelistener = i40iw_find_listener(
2875 cm_core,
2876 cm_info->rem_addr,
2877 cm_node->rem_port,
2878 cm_node->vlan_id,
2879 I40IW_CM_LISTENER_ACTIVE_STATE);
2880 if (!loopback_remotelistener) {
2881 i40iw_create_event(cm_node, I40IW_CM_EVENT_ABORTED);
2882 } else {
2883 loopback_cm_info = *cm_info;
2884 loopback_cm_info.loc_port = cm_info->rem_port;
2885 loopback_cm_info.rem_port = cm_info->loc_port;
2886 loopback_cm_info.cm_id = loopback_remotelistener->cm_id;
2887 loopback_cm_info.ipv4 = cm_info->ipv4;
2888 loopback_remotenode = i40iw_make_cm_node(cm_core,
2889 iwdev,
2890 &loopback_cm_info,
2891 loopback_remotelistener);
2892 if (!loopback_remotenode) {
2893 i40iw_rem_ref_cm_node(cm_node);
2894 return NULL;
2895 }
2896 cm_core->stats_loopbacks++;
2897 loopback_remotenode->loopbackpartner = cm_node;
2898 loopback_remotenode->tcp_cntxt.rcv_wscale =
2899 I40IW_CM_DEFAULT_RCV_WND_SCALE;
2900 cm_node->loopbackpartner = loopback_remotenode;
2901 memcpy(loopback_remotenode->pdata_buf, private_data,
2902 private_data_len);
2903 loopback_remotenode->pdata.size = private_data_len;
2904
2905 cm_node->state = I40IW_CM_STATE_OFFLOADED;
2906 cm_node->tcp_cntxt.rcv_nxt =
2907 loopback_remotenode->tcp_cntxt.loc_seq_num;
2908 loopback_remotenode->tcp_cntxt.rcv_nxt =
2909 cm_node->tcp_cntxt.loc_seq_num;
2910 cm_node->tcp_cntxt.max_snd_wnd =
2911 loopback_remotenode->tcp_cntxt.rcv_wnd;
2912 loopback_remotenode->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.rcv_wnd;
2913 cm_node->tcp_cntxt.snd_wnd = loopback_remotenode->tcp_cntxt.rcv_wnd;
2914 loopback_remotenode->tcp_cntxt.snd_wnd = cm_node->tcp_cntxt.rcv_wnd;
2915 cm_node->tcp_cntxt.snd_wscale = loopback_remotenode->tcp_cntxt.rcv_wscale;
2916 loopback_remotenode->tcp_cntxt.snd_wscale = cm_node->tcp_cntxt.rcv_wscale;
2917 loopback_remotenode->state = I40IW_CM_STATE_MPAREQ_RCVD;
2918 i40iw_create_event(loopback_remotenode, I40IW_CM_EVENT_MPA_REQ);
2919 }
2920 return cm_node;
2921 }
2922
2923 cm_node->pdata.size = private_data_len;
2924 cm_node->pdata.addr = cm_node->pdata_buf;
2925
2926 memcpy(cm_node->pdata_buf, private_data, private_data_len);
2927
2928 cm_node->state = I40IW_CM_STATE_SYN_SENT;
2929 ret = i40iw_send_syn(cm_node, 0);
2930
2931 if (ret) {
2932 if (cm_node->ipv4)
2933 i40iw_debug(cm_node->dev,
2934 I40IW_DEBUG_CM,
2935 "Api - connect() FAILED: dest addr=%pI4",
2936 cm_node->rem_addr);
2937 else
2938 i40iw_debug(cm_node->dev, I40IW_DEBUG_CM,
2939 "Api - connect() FAILED: dest addr=%pI6",
2940 cm_node->rem_addr);
2941 i40iw_rem_ref_cm_node(cm_node);
2942 cm_node = NULL;
2943 }
2944
2945 if (cm_node)
2946 i40iw_debug(cm_node->dev,
2947 I40IW_DEBUG_CM,
2948 "Api - connect(): port=0x%04x, cm_node=%p, cm_id = %p.\n",
2949 cm_node->rem_port,
2950 cm_node,
2951 cm_node->cm_id);
2952
2953 return cm_node;
2954}
2955
2956/**
2957 * i40iw_cm_reject - reject and teardown a connection
2958 * @cm_node: connection's node
2959 * @pdate: ptr to private data for reject
2960 * @plen: size of private data
2961 */
2962static int i40iw_cm_reject(struct i40iw_cm_node *cm_node, const void *pdata, u8 plen)
2963{
2964 int ret = 0;
2965 int err;
2966 int passive_state;
2967 struct iw_cm_id *cm_id = cm_node->cm_id;
2968 struct i40iw_cm_node *loopback = cm_node->loopbackpartner;
2969
2970 if (cm_node->tcp_cntxt.client)
2971 return ret;
2972 i40iw_cleanup_retrans_entry(cm_node);
2973
2974 if (!loopback) {
2975 passive_state = atomic_add_return(1, &cm_node->passive_state);
2976 if (passive_state == I40IW_SEND_RESET_EVENT) {
2977 cm_node->state = I40IW_CM_STATE_CLOSED;
2978 i40iw_rem_ref_cm_node(cm_node);
2979 } else {
2980 if (cm_node->state == I40IW_CM_STATE_LISTENER_DESTROYED) {
2981 i40iw_rem_ref_cm_node(cm_node);
2982 } else {
2983 ret = i40iw_send_mpa_reject(cm_node, pdata, plen);
2984 if (ret) {
2985 cm_node->state = I40IW_CM_STATE_CLOSED;
2986 err = i40iw_send_reset(cm_node);
2987 if (err)
2988 i40iw_pr_err("send reset failed\n");
2989 } else {
2990 cm_id->add_ref(cm_id);
2991 }
2992 }
2993 }
2994 } else {
2995 cm_node->cm_id = NULL;
2996 if (cm_node->state == I40IW_CM_STATE_LISTENER_DESTROYED) {
2997 i40iw_rem_ref_cm_node(cm_node);
2998 i40iw_rem_ref_cm_node(loopback);
2999 } else {
3000 ret = i40iw_send_cm_event(loopback,
3001 loopback->cm_id,
3002 IW_CM_EVENT_CONNECT_REPLY,
3003 -ECONNREFUSED);
3004 i40iw_rem_ref_cm_node(cm_node);
3005 loopback->state = I40IW_CM_STATE_CLOSING;
3006
3007 cm_id = loopback->cm_id;
3008 i40iw_rem_ref_cm_node(loopback);
3009 cm_id->rem_ref(cm_id);
3010 }
3011 }
3012
3013 return ret;
3014}
3015
3016/**
3017 * i40iw_cm_close - close of cm connection
3018 * @cm_node: connection's node
3019 */
3020static int i40iw_cm_close(struct i40iw_cm_node *cm_node)
3021{
3022 int ret = 0;
3023
3024 if (!cm_node)
3025 return -EINVAL;
3026
3027 switch (cm_node->state) {
3028 case I40IW_CM_STATE_SYN_RCVD:
3029 case I40IW_CM_STATE_SYN_SENT:
3030 case I40IW_CM_STATE_ONE_SIDE_ESTABLISHED:
3031 case I40IW_CM_STATE_ESTABLISHED:
3032 case I40IW_CM_STATE_ACCEPTING:
3033 case I40IW_CM_STATE_MPAREQ_SENT:
3034 case I40IW_CM_STATE_MPAREQ_RCVD:
3035 i40iw_cleanup_retrans_entry(cm_node);
3036 i40iw_send_reset(cm_node);
3037 break;
3038 case I40IW_CM_STATE_CLOSE_WAIT:
3039 cm_node->state = I40IW_CM_STATE_LAST_ACK;
3040 i40iw_send_fin(cm_node);
3041 break;
3042 case I40IW_CM_STATE_FIN_WAIT1:
3043 case I40IW_CM_STATE_FIN_WAIT2:
3044 case I40IW_CM_STATE_LAST_ACK:
3045 case I40IW_CM_STATE_TIME_WAIT:
3046 case I40IW_CM_STATE_CLOSING:
3047 ret = -1;
3048 break;
3049 case I40IW_CM_STATE_LISTENING:
3050 i40iw_cleanup_retrans_entry(cm_node);
3051 i40iw_send_reset(cm_node);
3052 break;
3053 case I40IW_CM_STATE_MPAREJ_RCVD:
3054 case I40IW_CM_STATE_UNKNOWN:
3055 case I40IW_CM_STATE_INITED:
3056 case I40IW_CM_STATE_CLOSED:
3057 case I40IW_CM_STATE_LISTENER_DESTROYED:
3058 i40iw_rem_ref_cm_node(cm_node);
3059 break;
3060 case I40IW_CM_STATE_OFFLOADED:
3061 if (cm_node->send_entry)
3062 i40iw_pr_err("send_entry\n");
3063 i40iw_rem_ref_cm_node(cm_node);
3064 break;
3065 }
3066 return ret;
3067}
3068
3069/**
3070 * i40iw_receive_ilq - recv an ETHERNET packet, and process it
3071 * through CM
3072 * @dev: FPK dev struct
3073 * @rbuf: receive buffer
3074 */
3075void i40iw_receive_ilq(struct i40iw_sc_dev *dev, struct i40iw_puda_buf *rbuf)
3076{
3077 struct i40iw_cm_node *cm_node;
3078 struct i40iw_cm_listener *listener;
3079 struct iphdr *iph;
3080 struct ipv6hdr *ip6h;
3081 struct tcphdr *tcph;
3082 struct i40iw_cm_info cm_info;
3083 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
3084 struct i40iw_cm_core *cm_core = &iwdev->cm_core;
3085 struct vlan_ethhdr *ethh;
3086
3087 /* if vlan, then maclen = 18 else 14 */
3088 iph = (struct iphdr *)rbuf->iph;
3089 memset(&cm_info, 0, sizeof(cm_info));
3090
3091 i40iw_debug_buf(dev,
3092 I40IW_DEBUG_ILQ,
3093 "RECEIVE ILQ BUFFER",
3094 rbuf->mem.va,
3095 rbuf->totallen);
3096 ethh = (struct vlan_ethhdr *)rbuf->mem.va;
3097
3098 if (ethh->h_vlan_proto == htons(ETH_P_8021Q)) {
3099 cm_info.vlan_id = ntohs(ethh->h_vlan_TCI) & VLAN_VID_MASK;
3100 i40iw_debug(cm_core->dev,
3101 I40IW_DEBUG_CM,
3102 "%s vlan_id=%d\n",
3103 __func__,
3104 cm_info.vlan_id);
3105 } else {
3106 cm_info.vlan_id = I40IW_NO_VLAN;
3107 }
3108 tcph = (struct tcphdr *)rbuf->tcph;
3109
3110 if (rbuf->ipv4) {
3111 cm_info.loc_addr[0] = ntohl(iph->daddr);
3112 cm_info.rem_addr[0] = ntohl(iph->saddr);
3113 cm_info.ipv4 = true;
3114 } else {
3115 ip6h = (struct ipv6hdr *)rbuf->iph;
3116 i40iw_copy_ip_ntohl(cm_info.loc_addr,
3117 ip6h->daddr.in6_u.u6_addr32);
3118 i40iw_copy_ip_ntohl(cm_info.rem_addr,
3119 ip6h->saddr.in6_u.u6_addr32);
3120 cm_info.ipv4 = false;
3121 }
3122 cm_info.loc_port = ntohs(tcph->dest);
3123 cm_info.rem_port = ntohs(tcph->source);
3124 cm_node = i40iw_find_node(cm_core,
3125 cm_info.rem_port,
3126 cm_info.rem_addr,
3127 cm_info.loc_port,
3128 cm_info.loc_addr,
3129 true);
3130
3131 if (!cm_node) {
3132 /* Only type of packet accepted are for */
3133 /* the PASSIVE open (syn only) */
3134 if (!tcph->syn || tcph->ack)
3135 return;
3136 listener =
3137 i40iw_find_listener(cm_core,
3138 cm_info.loc_addr,
3139 cm_info.loc_port,
3140 cm_info.vlan_id,
3141 I40IW_CM_LISTENER_ACTIVE_STATE);
3142 if (!listener) {
3143 cm_info.cm_id = NULL;
3144 i40iw_debug(cm_core->dev,
3145 I40IW_DEBUG_CM,
3146 "%s no listener found\n",
3147 __func__);
3148 return;
3149 }
3150 cm_info.cm_id = listener->cm_id;
3151 cm_node = i40iw_make_cm_node(cm_core, iwdev, &cm_info, listener);
3152 if (!cm_node) {
3153 i40iw_debug(cm_core->dev,
3154 I40IW_DEBUG_CM,
3155 "%s allocate node failed\n",
3156 __func__);
3157 atomic_dec(&listener->ref_count);
3158 return;
3159 }
3160 if (!tcph->rst && !tcph->fin) {
3161 cm_node->state = I40IW_CM_STATE_LISTENING;
3162 } else {
3163 i40iw_rem_ref_cm_node(cm_node);
3164 return;
3165 }
3166 atomic_inc(&cm_node->ref_count);
3167 } else if (cm_node->state == I40IW_CM_STATE_OFFLOADED) {
3168 i40iw_rem_ref_cm_node(cm_node);
3169 return;
3170 }
3171 i40iw_process_packet(cm_node, rbuf);
3172 i40iw_rem_ref_cm_node(cm_node);
3173}
3174
3175/**
3176 * i40iw_setup_cm_core - allocate a top level instance of a cm
3177 * core
3178 * @iwdev: iwarp device structure
3179 */
3180void i40iw_setup_cm_core(struct i40iw_device *iwdev)
3181{
3182 struct i40iw_cm_core *cm_core = &iwdev->cm_core;
3183
3184 cm_core->iwdev = iwdev;
3185 cm_core->dev = &iwdev->sc_dev;
3186
3187 INIT_LIST_HEAD(&cm_core->connected_nodes);
3188 INIT_LIST_HEAD(&cm_core->listen_nodes);
3189
3190 init_timer(&cm_core->tcp_timer);
3191 cm_core->tcp_timer.function = i40iw_cm_timer_tick;
3192 cm_core->tcp_timer.data = (unsigned long)cm_core;
3193
3194 spin_lock_init(&cm_core->ht_lock);
3195 spin_lock_init(&cm_core->listen_list_lock);
3196
3197 cm_core->event_wq = create_singlethread_workqueue("iwewq");
3198 cm_core->disconn_wq = create_singlethread_workqueue("iwdwq");
3199}
3200
3201/**
3202 * i40iw_cleanup_cm_core - deallocate a top level instance of a
3203 * cm core
3204 * @cm_core: cm's core
3205 */
3206void i40iw_cleanup_cm_core(struct i40iw_cm_core *cm_core)
3207{
3208 unsigned long flags;
3209
3210 if (!cm_core)
3211 return;
3212
3213 spin_lock_irqsave(&cm_core->ht_lock, flags);
3214 if (timer_pending(&cm_core->tcp_timer))
3215 del_timer_sync(&cm_core->tcp_timer);
3216 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
3217
3218 destroy_workqueue(cm_core->event_wq);
3219 destroy_workqueue(cm_core->disconn_wq);
3220}
3221
3222/**
3223 * i40iw_init_tcp_ctx - setup qp context
3224 * @cm_node: connection's node
3225 * @tcp_info: offload info for tcp
3226 * @iwqp: associate qp for the connection
3227 */
3228static void i40iw_init_tcp_ctx(struct i40iw_cm_node *cm_node,
3229 struct i40iw_tcp_offload_info *tcp_info,
3230 struct i40iw_qp *iwqp)
3231{
3232 tcp_info->ipv4 = cm_node->ipv4;
3233 tcp_info->drop_ooo_seg = true;
3234 tcp_info->wscale = true;
3235 tcp_info->ignore_tcp_opt = true;
3236 tcp_info->ignore_tcp_uns_opt = true;
3237 tcp_info->no_nagle = false;
3238
3239 tcp_info->ttl = I40IW_DEFAULT_TTL;
3240 tcp_info->rtt_var = cpu_to_le32(I40IW_DEFAULT_RTT_VAR);
3241 tcp_info->ss_thresh = cpu_to_le32(I40IW_DEFAULT_SS_THRESH);
3242 tcp_info->rexmit_thresh = I40IW_DEFAULT_REXMIT_THRESH;
3243
3244 tcp_info->tcp_state = I40IW_TCP_STATE_ESTABLISHED;
3245 tcp_info->snd_wscale = cm_node->tcp_cntxt.snd_wscale;
3246 tcp_info->rcv_wscale = cm_node->tcp_cntxt.rcv_wscale;
3247
3248 tcp_info->snd_nxt = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
3249 tcp_info->snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.snd_wnd);
3250 tcp_info->rcv_nxt = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
3251 tcp_info->snd_max = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
3252
3253 tcp_info->snd_una = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
3254 tcp_info->cwnd = cpu_to_le32(2 * cm_node->tcp_cntxt.mss);
3255 tcp_info->snd_wl1 = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
3256 tcp_info->snd_wl2 = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
3257 tcp_info->max_snd_window = cpu_to_le32(cm_node->tcp_cntxt.max_snd_wnd);
3258 tcp_info->rcv_wnd = cpu_to_le32(cm_node->tcp_cntxt.rcv_wnd <<
3259 cm_node->tcp_cntxt.rcv_wscale);
3260
3261 tcp_info->flow_label = 0;
3262 tcp_info->snd_mss = cpu_to_le32(((u32)cm_node->tcp_cntxt.mss));
3263 if (cm_node->vlan_id < VLAN_TAG_PRESENT) {
3264 tcp_info->insert_vlan_tag = true;
3265 tcp_info->vlan_tag = cpu_to_le16(cm_node->vlan_id);
3266 }
3267 if (cm_node->ipv4) {
3268 tcp_info->src_port = cpu_to_le16(cm_node->loc_port);
3269 tcp_info->dst_port = cpu_to_le16(cm_node->rem_port);
3270
3271 tcp_info->dest_ip_addr3 = cpu_to_le32(cm_node->rem_addr[0]);
3272 tcp_info->local_ipaddr3 = cpu_to_le32(cm_node->loc_addr[0]);
3273 tcp_info->arp_idx = cpu_to_le32(i40iw_arp_table(iwqp->iwdev,
3274 &tcp_info->dest_ip_addr3,
3275 true,
3276 NULL,
3277 I40IW_ARP_RESOLVE));
3278 } else {
3279 tcp_info->src_port = cpu_to_le16(cm_node->loc_port);
3280 tcp_info->dst_port = cpu_to_le16(cm_node->rem_port);
3281 tcp_info->dest_ip_addr0 = cpu_to_le32(cm_node->rem_addr[0]);
3282 tcp_info->dest_ip_addr1 = cpu_to_le32(cm_node->rem_addr[1]);
3283 tcp_info->dest_ip_addr2 = cpu_to_le32(cm_node->rem_addr[2]);
3284 tcp_info->dest_ip_addr3 = cpu_to_le32(cm_node->rem_addr[3]);
3285 tcp_info->local_ipaddr0 = cpu_to_le32(cm_node->loc_addr[0]);
3286 tcp_info->local_ipaddr1 = cpu_to_le32(cm_node->loc_addr[1]);
3287 tcp_info->local_ipaddr2 = cpu_to_le32(cm_node->loc_addr[2]);
3288 tcp_info->local_ipaddr3 = cpu_to_le32(cm_node->loc_addr[3]);
3289 tcp_info->arp_idx = cpu_to_le32(i40iw_arp_table(
3290 iwqp->iwdev,
3291 &tcp_info->dest_ip_addr0,
3292 false,
3293 NULL,
3294 I40IW_ARP_RESOLVE));
3295 }
3296}
3297
3298/**
3299 * i40iw_cm_init_tsa_conn - setup qp for RTS
3300 * @iwqp: associate qp for the connection
3301 * @cm_node: connection's node
3302 */
3303static void i40iw_cm_init_tsa_conn(struct i40iw_qp *iwqp,
3304 struct i40iw_cm_node *cm_node)
3305{
3306 struct i40iw_tcp_offload_info tcp_info;
3307 struct i40iwarp_offload_info *iwarp_info;
3308 struct i40iw_qp_host_ctx_info *ctx_info;
3309 struct i40iw_device *iwdev = iwqp->iwdev;
3310 struct i40iw_sc_dev *dev = &iwqp->iwdev->sc_dev;
3311
3312 memset(&tcp_info, 0x00, sizeof(struct i40iw_tcp_offload_info));
3313 iwarp_info = &iwqp->iwarp_info;
3314 ctx_info = &iwqp->ctx_info;
3315
3316 ctx_info->tcp_info = &tcp_info;
3317 ctx_info->send_cq_num = iwqp->iwscq->sc_cq.cq_uk.cq_id;
3318 ctx_info->rcv_cq_num = iwqp->iwrcq->sc_cq.cq_uk.cq_id;
3319
3320 iwarp_info->ord_size = cm_node->ord_size;
3321 iwarp_info->ird_size = i40iw_derive_hw_ird_setting(cm_node->ird_size);
3322
3323 if (iwarp_info->ord_size == 1)
3324 iwarp_info->ord_size = 2;
3325
3326 iwarp_info->rd_enable = true;
3327 iwarp_info->rdmap_ver = 1;
3328 iwarp_info->ddp_ver = 1;
3329
3330 iwarp_info->pd_id = iwqp->iwpd->sc_pd.pd_id;
3331
3332 ctx_info->tcp_info_valid = true;
3333 ctx_info->iwarp_info_valid = true;
3334
3335 i40iw_init_tcp_ctx(cm_node, &tcp_info, iwqp);
3336 if (cm_node->snd_mark_en) {
3337 iwarp_info->snd_mark_en = true;
3338 iwarp_info->snd_mark_offset = (tcp_info.snd_nxt &
3339 SNDMARKER_SEQNMASK) + cm_node->lsmm_size;
3340 }
3341
3342 cm_node->state = I40IW_CM_STATE_OFFLOADED;
3343 tcp_info.tcp_state = I40IW_TCP_STATE_ESTABLISHED;
3344 tcp_info.src_mac_addr_idx = iwdev->mac_ip_table_idx;
3345
3346 dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp, (u64 *)(iwqp->host_ctx.va), ctx_info);
3347
3348 /* once tcp_info is set, no need to do it again */
3349 ctx_info->tcp_info_valid = false;
3350 ctx_info->iwarp_info_valid = false;
3351}
3352
3353/**
3354 * i40iw_cm_disconn - when a connection is being closed
3355 * @iwqp: associate qp for the connection
3356 */
3357int i40iw_cm_disconn(struct i40iw_qp *iwqp)
3358{
3359 struct disconn_work *work;
3360 struct i40iw_device *iwdev = iwqp->iwdev;
3361 struct i40iw_cm_core *cm_core = &iwdev->cm_core;
3362
3363 work = kzalloc(sizeof(*work), GFP_ATOMIC);
3364 if (!work)
3365 return -ENOMEM; /* Timer will clean up */
3366
3367 i40iw_add_ref(&iwqp->ibqp);
3368 work->iwqp = iwqp;
3369 INIT_WORK(&work->work, i40iw_disconnect_worker);
3370 queue_work(cm_core->disconn_wq, &work->work);
3371 return 0;
3372}
3373
3374/**
3375 * i40iw_loopback_nop - Send a nop
3376 * @qp: associated hw qp
3377 */
3378static void i40iw_loopback_nop(struct i40iw_sc_qp *qp)
3379{
3380 u64 *wqe;
3381 u64 header;
3382
3383 wqe = qp->qp_uk.sq_base->elem;
3384 set_64bit_val(wqe, 0, 0);
3385 set_64bit_val(wqe, 8, 0);
3386 set_64bit_val(wqe, 16, 0);
3387
3388 header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
3389 LS_64(0, I40IWQPSQ_SIGCOMPL) |
3390 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3391 set_64bit_val(wqe, 24, header);
3392}
3393
3394/**
3395 * i40iw_qp_disconnect - free qp and close cm
3396 * @iwqp: associate qp for the connection
3397 */
3398static void i40iw_qp_disconnect(struct i40iw_qp *iwqp)
3399{
3400 struct i40iw_device *iwdev;
3401 struct i40iw_ib_device *iwibdev;
3402
3403 iwdev = to_iwdev(iwqp->ibqp.device);
3404 if (!iwdev) {
3405 i40iw_pr_err("iwdev == NULL\n");
3406 return;
3407 }
3408
3409 iwibdev = iwdev->iwibdev;
3410
3411 if (iwqp->active_conn) {
3412 /* indicate this connection is NOT active */
3413 iwqp->active_conn = 0;
3414 } else {
3415 /* Need to free the Last Streaming Mode Message */
3416 if (iwqp->ietf_mem.va) {
3417 if (iwqp->lsmm_mr)
3418 iwibdev->ibdev.dereg_mr(iwqp->lsmm_mr);
3419 i40iw_free_dma_mem(iwdev->sc_dev.hw, &iwqp->ietf_mem);
3420 }
3421 }
3422
3423 /* close the CM node down if it is still active */
3424 if (iwqp->cm_node) {
3425 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_CM, "%s Call close API\n", __func__);
3426 i40iw_cm_close(iwqp->cm_node);
3427 }
3428}
3429
3430/**
3431 * i40iw_cm_disconn_true - called by worker thread to disconnect qp
3432 * @iwqp: associate qp for the connection
3433 */
3434static void i40iw_cm_disconn_true(struct i40iw_qp *iwqp)
3435{
3436 struct iw_cm_id *cm_id;
3437 struct i40iw_device *iwdev;
3438 struct i40iw_sc_qp *qp = &iwqp->sc_qp;
3439 u16 last_ae;
3440 u8 original_hw_tcp_state;
3441 u8 original_ibqp_state;
3442 int disconn_status = 0;
3443 int issue_disconn = 0;
3444 int issue_close = 0;
3445 int issue_flush = 0;
3446 struct ib_event ibevent;
3447 unsigned long flags;
3448 int ret;
3449
3450 if (!iwqp) {
3451 i40iw_pr_err("iwqp == NULL\n");
3452 return;
3453 }
3454
3455 spin_lock_irqsave(&iwqp->lock, flags);
3456 cm_id = iwqp->cm_id;
3457 /* make sure we havent already closed this connection */
3458 if (!cm_id) {
3459 spin_unlock_irqrestore(&iwqp->lock, flags);
3460 return;
3461 }
3462
3463 iwdev = to_iwdev(iwqp->ibqp.device);
3464
3465 original_hw_tcp_state = iwqp->hw_tcp_state;
3466 original_ibqp_state = iwqp->ibqp_state;
3467 last_ae = iwqp->last_aeq;
3468
3469 if (qp->term_flags) {
3470 issue_disconn = 1;
3471 issue_close = 1;
3472 iwqp->cm_id = NULL;
3473 /*When term timer expires after cm_timer, don't want
3474 *terminate-handler to issue cm_disconn which can re-free
3475 *a QP even after its refcnt=0.
3476 */
3477 del_timer(&iwqp->terminate_timer);
3478 if (!iwqp->flush_issued) {
3479 iwqp->flush_issued = 1;
3480 issue_flush = 1;
3481 }
3482 } else if ((original_hw_tcp_state == I40IW_TCP_STATE_CLOSE_WAIT) ||
3483 ((original_ibqp_state == IB_QPS_RTS) &&
3484 (last_ae == I40IW_AE_LLP_CONNECTION_RESET))) {
3485 issue_disconn = 1;
3486 if (last_ae == I40IW_AE_LLP_CONNECTION_RESET)
3487 disconn_status = -ECONNRESET;
3488 }
3489
3490 if (((original_hw_tcp_state == I40IW_TCP_STATE_CLOSED) ||
3491 (original_hw_tcp_state == I40IW_TCP_STATE_TIME_WAIT) ||
3492 (last_ae == I40IW_AE_RDMAP_ROE_BAD_LLP_CLOSE) ||
3493 (last_ae == I40IW_AE_LLP_CONNECTION_RESET))) {
3494 issue_close = 1;
3495 iwqp->cm_id = NULL;
3496 if (!iwqp->flush_issued) {
3497 iwqp->flush_issued = 1;
3498 issue_flush = 1;
3499 }
3500 }
3501
3502 spin_unlock_irqrestore(&iwqp->lock, flags);
3503 if (issue_flush && !iwqp->destroyed) {
3504 /* Flush the queues */
3505 i40iw_flush_wqes(iwdev, iwqp);
3506
3507 if (qp->term_flags) {
3508 ibevent.device = iwqp->ibqp.device;
3509 ibevent.event = (qp->eventtype == TERM_EVENT_QP_FATAL) ?
3510 IB_EVENT_QP_FATAL : IB_EVENT_QP_ACCESS_ERR;
3511 ibevent.element.qp = &iwqp->ibqp;
3512 iwqp->ibqp.event_handler(&ibevent, iwqp->ibqp.qp_context);
3513 }
3514 }
3515
3516 if (cm_id && cm_id->event_handler) {
3517 if (issue_disconn) {
3518 ret = i40iw_send_cm_event(NULL,
3519 cm_id,
3520 IW_CM_EVENT_DISCONNECT,
3521 disconn_status);
3522
3523 if (ret)
3524 i40iw_debug(&iwdev->sc_dev,
3525 I40IW_DEBUG_CM,
3526 "disconnect event failed %s: - cm_id = %p\n",
3527 __func__, cm_id);
3528 }
3529 if (issue_close) {
3530 i40iw_qp_disconnect(iwqp);
3531 cm_id->provider_data = iwqp;
3532 ret = i40iw_send_cm_event(NULL, cm_id, IW_CM_EVENT_CLOSE, 0);
3533 if (ret)
3534 i40iw_debug(&iwdev->sc_dev,
3535 I40IW_DEBUG_CM,
3536 "close event failed %s: - cm_id = %p\n",
3537 __func__, cm_id);
3538 cm_id->rem_ref(cm_id);
3539 }
3540 }
3541}
3542
3543/**
3544 * i40iw_disconnect_worker - worker for connection close
3545 * @work: points or disconn structure
3546 */
3547static void i40iw_disconnect_worker(struct work_struct *work)
3548{
3549 struct disconn_work *dwork = container_of(work, struct disconn_work, work);
3550 struct i40iw_qp *iwqp = dwork->iwqp;
3551
3552 kfree(dwork);
3553 i40iw_cm_disconn_true(iwqp);
3554 i40iw_rem_ref(&iwqp->ibqp);
3555}
3556
3557/**
3558 * i40iw_accept - registered call for connection to be accepted
3559 * @cm_id: cm information for passive connection
3560 * @conn_param: accpet parameters
3561 */
3562int i40iw_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3563{
3564 struct ib_qp *ibqp;
3565 struct i40iw_qp *iwqp;
3566 struct i40iw_device *iwdev;
3567 struct i40iw_sc_dev *dev;
3568 struct i40iw_cm_node *cm_node;
3569 struct ib_qp_attr attr;
3570 int passive_state;
3571 struct i40iw_ib_device *iwibdev;
3572 struct ib_mr *ibmr;
3573 struct i40iw_pd *iwpd;
3574 u16 buf_len = 0;
3575 struct i40iw_kmem_info accept;
3576 enum i40iw_status_code status;
3577 u64 tagged_offset;
3578
3579 memset(&attr, 0, sizeof(attr));
3580 ibqp = i40iw_get_qp(cm_id->device, conn_param->qpn);
3581 if (!ibqp)
3582 return -EINVAL;
3583
3584 iwqp = to_iwqp(ibqp);
3585 iwdev = iwqp->iwdev;
3586 dev = &iwdev->sc_dev;
3587 cm_node = (struct i40iw_cm_node *)cm_id->provider_data;
3588
3589 if (((struct sockaddr_in *)&cm_id->local_addr)->sin_family == AF_INET) {
3590 cm_node->ipv4 = true;
3591 cm_node->vlan_id = i40iw_get_vlan_ipv4(cm_node->loc_addr);
3592 } else {
3593 cm_node->ipv4 = false;
3594 i40iw_netdev_vlan_ipv6(cm_node->loc_addr, &cm_node->vlan_id, NULL);
3595 }
3596 i40iw_debug(cm_node->dev,
3597 I40IW_DEBUG_CM,
3598 "Accept vlan_id=%d\n",
3599 cm_node->vlan_id);
3600 if (cm_node->state == I40IW_CM_STATE_LISTENER_DESTROYED) {
3601 if (cm_node->loopbackpartner)
3602 i40iw_rem_ref_cm_node(cm_node->loopbackpartner);
3603 i40iw_rem_ref_cm_node(cm_node);
3604 return -EINVAL;
3605 }
3606
3607 passive_state = atomic_add_return(1, &cm_node->passive_state);
3608 if (passive_state == I40IW_SEND_RESET_EVENT) {
3609 i40iw_rem_ref_cm_node(cm_node);
3610 return -ECONNRESET;
3611 }
3612
3613 cm_node->cm_core->stats_accepts++;
3614 iwqp->cm_node = (void *)cm_node;
3615 cm_node->iwqp = iwqp;
3616
3617 buf_len = conn_param->private_data_len + I40IW_MAX_IETF_SIZE + MPA_ZERO_PAD_LEN;
3618
3619 status = i40iw_allocate_dma_mem(dev->hw, &iwqp->ietf_mem, buf_len, 1);
3620
3621 if (status)
3622 return -ENOMEM;
3623 cm_node->pdata.size = conn_param->private_data_len;
3624 accept.addr = iwqp->ietf_mem.va;
3625 accept.size = i40iw_cm_build_mpa_frame(cm_node, &accept, MPA_KEY_REPLY);
3626 memcpy(accept.addr + accept.size, conn_param->private_data,
3627 conn_param->private_data_len);
3628
3629 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
3630 if ((cm_node->ipv4 &&
3631 !i40iw_ipv4_is_loopback(cm_node->loc_addr[0], cm_node->rem_addr[0])) ||
3632 (!cm_node->ipv4 &&
3633 !i40iw_ipv6_is_loopback(cm_node->loc_addr, cm_node->rem_addr))) {
3634 iwibdev = iwdev->iwibdev;
3635 iwpd = iwqp->iwpd;
3636 tagged_offset = (uintptr_t)iwqp->ietf_mem.va;
3637 ibmr = i40iw_reg_phys_mr(&iwpd->ibpd,
3638 iwqp->ietf_mem.pa,
3639 buf_len,
3640 IB_ACCESS_LOCAL_WRITE,
3641 &tagged_offset);
3642 if (IS_ERR(ibmr)) {
3643 i40iw_free_dma_mem(dev->hw, &iwqp->ietf_mem);
3644 return -ENOMEM;
3645 }
3646
3647 ibmr->pd = &iwpd->ibpd;
3648 ibmr->device = iwpd->ibpd.device;
3649 iwqp->lsmm_mr = ibmr;
3650 if (iwqp->page)
3651 iwqp->sc_qp.qp_uk.sq_base = kmap(iwqp->page);
3652 if (is_remote_ne020_or_chelsio(cm_node))
3653 dev->iw_priv_qp_ops->qp_send_lsmm(
3654 &iwqp->sc_qp,
3655 iwqp->ietf_mem.va,
3656 (accept.size + conn_param->private_data_len),
3657 ibmr->lkey);
3658 else
3659 dev->iw_priv_qp_ops->qp_send_lsmm(
3660 &iwqp->sc_qp,
3661 iwqp->ietf_mem.va,
3662 (accept.size + conn_param->private_data_len + MPA_ZERO_PAD_LEN),
3663 ibmr->lkey);
3664
3665 } else {
3666 if (iwqp->page)
3667 iwqp->sc_qp.qp_uk.sq_base = kmap(iwqp->page);
3668 i40iw_loopback_nop(&iwqp->sc_qp);
3669 }
3670
3671 if (iwqp->page)
3672 kunmap(iwqp->page);
3673
3674 iwqp->cm_id = cm_id;
3675 cm_node->cm_id = cm_id;
3676
3677 cm_id->provider_data = (void *)iwqp;
3678 iwqp->active_conn = 0;
3679
3680 cm_node->lsmm_size = accept.size + conn_param->private_data_len;
3681 i40iw_cm_init_tsa_conn(iwqp, cm_node);
3682 cm_id->add_ref(cm_id);
3683 i40iw_add_ref(&iwqp->ibqp);
3684
3685 i40iw_send_cm_event(cm_node, cm_id, IW_CM_EVENT_ESTABLISHED, 0);
3686
3687 attr.qp_state = IB_QPS_RTS;
3688 cm_node->qhash_set = false;
3689 i40iw_modify_qp(&iwqp->ibqp, &attr, IB_QP_STATE, NULL);
3690 if (cm_node->loopbackpartner) {
3691 cm_node->loopbackpartner->pdata.size = conn_param->private_data_len;
3692
3693 /* copy entire MPA frame to our cm_node's frame */
3694 memcpy(cm_node->loopbackpartner->pdata_buf,
3695 conn_param->private_data,
3696 conn_param->private_data_len);
3697 i40iw_create_event(cm_node->loopbackpartner, I40IW_CM_EVENT_CONNECTED);
3698 }
3699
3700 cm_node->accelerated = 1;
3701 if (cm_node->accept_pend) {
3702 if (!cm_node->listener)
3703 i40iw_pr_err("cm_node->listener NULL for passive node\n");
3704 atomic_dec(&cm_node->listener->pend_accepts_cnt);
3705 cm_node->accept_pend = 0;
3706 }
3707 return 0;
3708}
3709
3710/**
3711 * i40iw_reject - registered call for connection to be rejected
3712 * @cm_id: cm information for passive connection
3713 * @pdata: private data to be sent
3714 * @pdata_len: private data length
3715 */
3716int i40iw_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3717{
3718 struct i40iw_device *iwdev;
3719 struct i40iw_cm_node *cm_node;
3720 struct i40iw_cm_node *loopback;
3721
3722 cm_node = (struct i40iw_cm_node *)cm_id->provider_data;
3723 loopback = cm_node->loopbackpartner;
3724 cm_node->cm_id = cm_id;
3725 cm_node->pdata.size = pdata_len;
3726
3727 iwdev = to_iwdev(cm_id->device);
3728 if (!iwdev)
3729 return -EINVAL;
3730 cm_node->cm_core->stats_rejects++;
3731
3732 if (pdata_len + sizeof(struct ietf_mpa_v2) > MAX_CM_BUFFER)
3733 return -EINVAL;
3734
3735 if (loopback) {
3736 memcpy(&loopback->pdata_buf, pdata, pdata_len);
3737 loopback->pdata.size = pdata_len;
3738 }
3739
3740 return i40iw_cm_reject(cm_node, pdata, pdata_len);
3741}
3742
3743/**
3744 * i40iw_connect - registered call for connection to be established
3745 * @cm_id: cm information for passive connection
3746 * @conn_param: Information about the connection
3747 */
3748int i40iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3749{
3750 struct ib_qp *ibqp;
3751 struct i40iw_qp *iwqp;
3752 struct i40iw_device *iwdev;
3753 struct i40iw_cm_node *cm_node;
3754 struct i40iw_cm_info cm_info;
3755 struct sockaddr_in *laddr;
3756 struct sockaddr_in *raddr;
3757 struct sockaddr_in6 *laddr6;
3758 struct sockaddr_in6 *raddr6;
3759 int apbvt_set = 0;
3760 enum i40iw_status_code status;
3761
3762 ibqp = i40iw_get_qp(cm_id->device, conn_param->qpn);
3763 if (!ibqp)
3764 return -EINVAL;
3765 iwqp = to_iwqp(ibqp);
3766 if (!iwqp)
3767 return -EINVAL;
3768 iwdev = to_iwdev(iwqp->ibqp.device);
3769 if (!iwdev)
3770 return -EINVAL;
3771
3772 laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3773 raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
3774 laddr6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3775 raddr6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
3776
3777 if (!(laddr->sin_port) || !(raddr->sin_port))
3778 return -EINVAL;
3779
3780 iwqp->active_conn = 1;
3781 iwqp->cm_id = NULL;
3782 cm_id->provider_data = iwqp;
3783
3784 /* set up the connection params for the node */
3785 if (cm_id->remote_addr.ss_family == AF_INET) {
3786 cm_info.ipv4 = true;
3787 memset(cm_info.loc_addr, 0, sizeof(cm_info.loc_addr));
3788 memset(cm_info.rem_addr, 0, sizeof(cm_info.rem_addr));
3789 cm_info.loc_addr[0] = ntohl(laddr->sin_addr.s_addr);
3790 cm_info.rem_addr[0] = ntohl(raddr->sin_addr.s_addr);
3791 cm_info.loc_port = ntohs(laddr->sin_port);
3792 cm_info.rem_port = ntohs(raddr->sin_port);
3793 cm_info.vlan_id = i40iw_get_vlan_ipv4(cm_info.loc_addr);
3794 } else {
3795 cm_info.ipv4 = false;
3796 i40iw_copy_ip_ntohl(cm_info.loc_addr,
3797 laddr6->sin6_addr.in6_u.u6_addr32);
3798 i40iw_copy_ip_ntohl(cm_info.rem_addr,
3799 raddr6->sin6_addr.in6_u.u6_addr32);
3800 cm_info.loc_port = ntohs(laddr6->sin6_port);
3801 cm_info.rem_port = ntohs(raddr6->sin6_port);
3802 i40iw_netdev_vlan_ipv6(cm_info.loc_addr, &cm_info.vlan_id, NULL);
3803 }
3804 cm_info.cm_id = cm_id;
3805 if ((cm_info.ipv4 && (laddr->sin_addr.s_addr != raddr->sin_addr.s_addr)) ||
3806 (!cm_info.ipv4 && memcmp(laddr6->sin6_addr.in6_u.u6_addr32,
3807 raddr6->sin6_addr.in6_u.u6_addr32,
3808 sizeof(laddr6->sin6_addr.in6_u.u6_addr32)))) {
3809 status = i40iw_manage_qhash(iwdev,
3810 &cm_info,
3811 I40IW_QHASH_TYPE_TCP_ESTABLISHED,
3812 I40IW_QHASH_MANAGE_TYPE_ADD,
3813 NULL,
3814 true);
3815 if (status)
3816 return -EINVAL;
3817 }
3818 status = i40iw_manage_apbvt(iwdev, cm_info.loc_port, I40IW_MANAGE_APBVT_ADD);
3819 if (status) {
3820 i40iw_manage_qhash(iwdev,
3821 &cm_info,
3822 I40IW_QHASH_TYPE_TCP_ESTABLISHED,
3823 I40IW_QHASH_MANAGE_TYPE_DELETE,
3824 NULL,
3825 false);
3826 return -EINVAL;
3827 }
3828
3829 apbvt_set = 1;
3830 cm_id->add_ref(cm_id);
3831 cm_node = i40iw_create_cm_node(&iwdev->cm_core, iwdev,
3832 conn_param->private_data_len,
3833 (void *)conn_param->private_data,
3834 &cm_info);
3835 if (!cm_node) {
3836 i40iw_manage_qhash(iwdev,
3837 &cm_info,
3838 I40IW_QHASH_TYPE_TCP_ESTABLISHED,
3839 I40IW_QHASH_MANAGE_TYPE_DELETE,
3840 NULL,
3841 false);
3842
3843 if (apbvt_set && !i40iw_listen_port_in_use(&iwdev->cm_core,
3844 cm_info.loc_port))
3845 i40iw_manage_apbvt(iwdev,
3846 cm_info.loc_port,
3847 I40IW_MANAGE_APBVT_DEL);
3848 cm_id->rem_ref(cm_id);
3849 iwdev->cm_core.stats_connect_errs++;
3850 return -ENOMEM;
3851 }
3852
3853 i40iw_record_ird_ord(cm_node, (u16)conn_param->ird, (u16)conn_param->ord);
3854 if (cm_node->send_rdma0_op == SEND_RDMA_READ_ZERO &&
3855 !cm_node->ord_size)
3856 cm_node->ord_size = 1;
3857
3858 cm_node->apbvt_set = apbvt_set;
3859 cm_node->qhash_set = true;
3860 iwqp->cm_node = cm_node;
3861 cm_node->iwqp = iwqp;
3862 iwqp->cm_id = cm_id;
3863 i40iw_add_ref(&iwqp->ibqp);
3864 return 0;
3865}
3866
3867/**
3868 * i40iw_create_listen - registered call creating listener
3869 * @cm_id: cm information for passive connection
3870 * @backlog: to max accept pending count
3871 */
3872int i40iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3873{
3874 struct i40iw_device *iwdev;
3875 struct i40iw_cm_listener *cm_listen_node;
3876 struct i40iw_cm_info cm_info;
3877 enum i40iw_status_code ret;
3878 struct sockaddr_in *laddr;
3879 struct sockaddr_in6 *laddr6;
3880 bool wildcard = false;
3881
3882 iwdev = to_iwdev(cm_id->device);
3883 if (!iwdev)
3884 return -EINVAL;
3885
3886 laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3887 laddr6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3888 memset(&cm_info, 0, sizeof(cm_info));
3889 if (laddr->sin_family == AF_INET) {
3890 cm_info.ipv4 = true;
3891 cm_info.loc_addr[0] = ntohl(laddr->sin_addr.s_addr);
3892 cm_info.loc_port = ntohs(laddr->sin_port);
3893
3894 if (laddr->sin_addr.s_addr != INADDR_ANY)
3895 cm_info.vlan_id = i40iw_get_vlan_ipv4(cm_info.loc_addr);
3896 else
3897 wildcard = true;
3898
3899 } else {
3900 cm_info.ipv4 = false;
3901 i40iw_copy_ip_ntohl(cm_info.loc_addr,
3902 laddr6->sin6_addr.in6_u.u6_addr32);
3903 cm_info.loc_port = ntohs(laddr6->sin6_port);
3904 if (ipv6_addr_type(&laddr6->sin6_addr) != IPV6_ADDR_ANY)
3905 i40iw_netdev_vlan_ipv6(cm_info.loc_addr,
3906 &cm_info.vlan_id,
3907 NULL);
3908 else
3909 wildcard = true;
3910 }
3911 cm_info.backlog = backlog;
3912 cm_info.cm_id = cm_id;
3913
3914 cm_listen_node = i40iw_make_listen_node(&iwdev->cm_core, iwdev, &cm_info);
3915 if (!cm_listen_node) {
3916 i40iw_pr_err("cm_listen_node == NULL\n");
3917 return -ENOMEM;
3918 }
3919
3920 cm_id->provider_data = cm_listen_node;
3921
3922 if (!cm_listen_node->reused_node) {
3923 if (wildcard) {
3924 if (cm_info.ipv4)
3925 ret = i40iw_add_mqh_4(iwdev,
3926 &cm_info,
3927 cm_listen_node);
3928 else
3929 ret = i40iw_add_mqh_6(iwdev,
3930 &cm_info,
3931 cm_listen_node);
3932 if (ret)
3933 goto error;
3934
3935 ret = i40iw_manage_apbvt(iwdev,
3936 cm_info.loc_port,
3937 I40IW_MANAGE_APBVT_ADD);
3938
3939 if (ret)
3940 goto error;
3941 } else {
3942 ret = i40iw_manage_qhash(iwdev,
3943 &cm_info,
3944 I40IW_QHASH_TYPE_TCP_SYN,
3945 I40IW_QHASH_MANAGE_TYPE_ADD,
3946 NULL,
3947 true);
3948 if (ret)
3949 goto error;
3950 cm_listen_node->qhash_set = true;
3951 ret = i40iw_manage_apbvt(iwdev,
3952 cm_info.loc_port,
3953 I40IW_MANAGE_APBVT_ADD);
3954 if (ret)
3955 goto error;
3956 }
3957 }
3958 cm_id->add_ref(cm_id);
3959 cm_listen_node->cm_core->stats_listen_created++;
3960 return 0;
3961 error:
3962 i40iw_cm_del_listen(&iwdev->cm_core, (void *)cm_listen_node, false);
3963 return -EINVAL;
3964}
3965
3966/**
3967 * i40iw_destroy_listen - registered call to destroy listener
3968 * @cm_id: cm information for passive connection
3969 */
3970int i40iw_destroy_listen(struct iw_cm_id *cm_id)
3971{
3972 struct i40iw_device *iwdev;
3973
3974 iwdev = to_iwdev(cm_id->device);
3975 if (cm_id->provider_data)
3976 i40iw_cm_del_listen(&iwdev->cm_core, cm_id->provider_data, true);
3977 else
3978 i40iw_pr_err("cm_id->provider_data was NULL\n");
3979
3980 cm_id->rem_ref(cm_id);
3981
3982 return 0;
3983}
3984
3985/**
3986 * i40iw_cm_event_connected - handle connected active node
3987 * @event: the info for cm_node of connection
3988 */
3989static void i40iw_cm_event_connected(struct i40iw_cm_event *event)
3990{
3991 struct i40iw_qp *iwqp;
3992 struct i40iw_device *iwdev;
3993 struct i40iw_cm_node *cm_node;
3994 struct i40iw_sc_dev *dev;
3995 struct ib_qp_attr attr;
3996 struct iw_cm_id *cm_id;
3997 int status;
3998 bool read0;
3999
4000 cm_node = event->cm_node;
4001 cm_id = cm_node->cm_id;
4002 iwqp = (struct i40iw_qp *)cm_id->provider_data;
4003 iwdev = to_iwdev(iwqp->ibqp.device);
4004 dev = &iwdev->sc_dev;
4005
4006 if (iwqp->destroyed) {
4007 status = -ETIMEDOUT;
4008 goto error;
4009 }
4010 i40iw_cm_init_tsa_conn(iwqp, cm_node);
4011 read0 = (cm_node->send_rdma0_op == SEND_RDMA_READ_ZERO);
4012 if (iwqp->page)
4013 iwqp->sc_qp.qp_uk.sq_base = kmap(iwqp->page);
4014 dev->iw_priv_qp_ops->qp_send_rtt(&iwqp->sc_qp, read0);
4015 if (iwqp->page)
4016 kunmap(iwqp->page);
4017 status = i40iw_send_cm_event(cm_node, cm_id, IW_CM_EVENT_CONNECT_REPLY, 0);
4018 if (status)
4019 i40iw_pr_err("send cm event\n");
4020
4021 memset(&attr, 0, sizeof(attr));
4022 attr.qp_state = IB_QPS_RTS;
4023 cm_node->qhash_set = false;
4024 i40iw_modify_qp(&iwqp->ibqp, &attr, IB_QP_STATE, NULL);
4025
4026 cm_node->accelerated = 1;
4027 if (cm_node->accept_pend) {
4028 if (!cm_node->listener)
4029 i40iw_pr_err("listener is null for passive node\n");
4030 atomic_dec(&cm_node->listener->pend_accepts_cnt);
4031 cm_node->accept_pend = 0;
4032 }
4033 return;
4034
4035error:
4036 iwqp->cm_id = NULL;
4037 cm_id->provider_data = NULL;
4038 i40iw_send_cm_event(event->cm_node,
4039 cm_id,
4040 IW_CM_EVENT_CONNECT_REPLY,
4041 status);
4042 cm_id->rem_ref(cm_id);
4043 i40iw_rem_ref_cm_node(event->cm_node);
4044}
4045
4046/**
4047 * i40iw_cm_event_reset - handle reset
4048 * @event: the info for cm_node of connection
4049 */
4050static void i40iw_cm_event_reset(struct i40iw_cm_event *event)
4051{
4052 struct i40iw_cm_node *cm_node = event->cm_node;
4053 struct iw_cm_id *cm_id = cm_node->cm_id;
4054 struct i40iw_qp *iwqp;
4055
4056 if (!cm_id)
4057 return;
4058
4059 iwqp = cm_id->provider_data;
4060 if (!iwqp)
4061 return;
4062
4063 i40iw_debug(cm_node->dev,
4064 I40IW_DEBUG_CM,
4065 "reset event %p - cm_id = %p\n",
4066 event->cm_node, cm_id);
4067 iwqp->cm_id = NULL;
4068
4069 i40iw_send_cm_event(cm_node, cm_node->cm_id, IW_CM_EVENT_DISCONNECT, -ECONNRESET);
4070 i40iw_send_cm_event(cm_node, cm_node->cm_id, IW_CM_EVENT_CLOSE, 0);
4071}
4072
4073/**
4074 * i40iw_cm_event_handler - worker thread callback to send event to cm upper layer
4075 * @work: pointer of cm event info.
4076 */
4077static void i40iw_cm_event_handler(struct work_struct *work)
4078{
4079 struct i40iw_cm_event *event = container_of(work,
4080 struct i40iw_cm_event,
4081 event_work);
4082 struct i40iw_cm_node *cm_node;
4083
4084 if (!event || !event->cm_node || !event->cm_node->cm_core)
4085 return;
4086
4087 cm_node = event->cm_node;
4088
4089 switch (event->type) {
4090 case I40IW_CM_EVENT_MPA_REQ:
4091 i40iw_send_cm_event(cm_node,
4092 cm_node->cm_id,
4093 IW_CM_EVENT_CONNECT_REQUEST,
4094 0);
4095 break;
4096 case I40IW_CM_EVENT_RESET:
4097 i40iw_cm_event_reset(event);
4098 break;
4099 case I40IW_CM_EVENT_CONNECTED:
4100 if (!event->cm_node->cm_id ||
4101 (event->cm_node->state != I40IW_CM_STATE_OFFLOADED))
4102 break;
4103 i40iw_cm_event_connected(event);
4104 break;
4105 case I40IW_CM_EVENT_MPA_REJECT:
4106 if (!event->cm_node->cm_id ||
4107 (cm_node->state == I40IW_CM_STATE_OFFLOADED))
4108 break;
4109 i40iw_send_cm_event(cm_node,
4110 cm_node->cm_id,
4111 IW_CM_EVENT_CONNECT_REPLY,
4112 -ECONNREFUSED);
4113 break;
4114 case I40IW_CM_EVENT_ABORTED:
4115 if (!event->cm_node->cm_id ||
4116 (event->cm_node->state == I40IW_CM_STATE_OFFLOADED))
4117 break;
4118 i40iw_event_connect_error(event);
4119 break;
4120 default:
4121 i40iw_pr_err("event type = %d\n", event->type);
4122 break;
4123 }
4124
4125 event->cm_info.cm_id->rem_ref(event->cm_info.cm_id);
4126 i40iw_rem_ref_cm_node(event->cm_node);
4127 kfree(event);
4128}
4129
4130/**
4131 * i40iw_cm_post_event - queue event request for worker thread
4132 * @event: cm node's info for up event call
4133 */
4134static void i40iw_cm_post_event(struct i40iw_cm_event *event)
4135{
4136 atomic_inc(&event->cm_node->ref_count);
4137 event->cm_info.cm_id->add_ref(event->cm_info.cm_id);
4138 INIT_WORK(&event->event_work, i40iw_cm_event_handler);
4139
4140 queue_work(event->cm_node->cm_core->event_wq, &event->event_work);
4141}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.h b/drivers/infiniband/hw/i40iw/i40iw_cm.h
new file mode 100644
index 000000000000..5f8ceb4a8e84
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.h
@@ -0,0 +1,456 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_CM_H
36#define I40IW_CM_H
37
38#define QUEUE_EVENTS
39
40#define I40IW_MANAGE_APBVT_DEL 0
41#define I40IW_MANAGE_APBVT_ADD 1
42
43#define I40IW_MPA_REQUEST_ACCEPT 1
44#define I40IW_MPA_REQUEST_REJECT 2
45
46/* IETF MPA -- defines, enums, structs */
47#define IEFT_MPA_KEY_REQ "MPA ID Req Frame"
48#define IEFT_MPA_KEY_REP "MPA ID Rep Frame"
49#define IETF_MPA_KEY_SIZE 16
50#define IETF_MPA_VERSION 1
51#define IETF_MAX_PRIV_DATA_LEN 512
52#define IETF_MPA_FRAME_SIZE 20
53#define IETF_RTR_MSG_SIZE 4
54#define IETF_MPA_V2_FLAG 0x10
55#define SNDMARKER_SEQNMASK 0x000001FF
56
57#define I40IW_MAX_IETF_SIZE 32
58
59#define MPA_ZERO_PAD_LEN 4
60
61/* IETF RTR MSG Fields */
62#define IETF_PEER_TO_PEER 0x8000
63#define IETF_FLPDU_ZERO_LEN 0x4000
64#define IETF_RDMA0_WRITE 0x8000
65#define IETF_RDMA0_READ 0x4000
66#define IETF_NO_IRD_ORD 0x3FFF
67
68/* HW-supported IRD sizes*/
69#define I40IW_HW_IRD_SETTING_2 2
70#define I40IW_HW_IRD_SETTING_4 4
71#define I40IW_HW_IRD_SETTING_8 8
72#define I40IW_HW_IRD_SETTING_16 16
73#define I40IW_HW_IRD_SETTING_32 32
74#define I40IW_HW_IRD_SETTING_64 64
75
76enum ietf_mpa_flags {
77 IETF_MPA_FLAGS_MARKERS = 0x80, /* receive Markers */
78 IETF_MPA_FLAGS_CRC = 0x40, /* receive Markers */
79 IETF_MPA_FLAGS_REJECT = 0x20, /* Reject */
80};
81
82struct ietf_mpa_v1 {
83 u8 key[IETF_MPA_KEY_SIZE];
84 u8 flags;
85 u8 rev;
86 __be16 priv_data_len;
87 u8 priv_data[0];
88};
89
90#define ietf_mpa_req_resp_frame ietf_mpa_frame
91
92struct ietf_rtr_msg {
93 __be16 ctrl_ird;
94 __be16 ctrl_ord;
95};
96
97struct ietf_mpa_v2 {
98 u8 key[IETF_MPA_KEY_SIZE];
99 u8 flags;
100 u8 rev;
101 __be16 priv_data_len;
102 struct ietf_rtr_msg rtr_msg;
103 u8 priv_data[0];
104};
105
106struct i40iw_cm_node;
107enum i40iw_timer_type {
108 I40IW_TIMER_TYPE_SEND,
109 I40IW_TIMER_TYPE_RECV,
110 I40IW_TIMER_NODE_CLEANUP,
111 I40IW_TIMER_TYPE_CLOSE,
112};
113
114#define I40IW_PASSIVE_STATE_INDICATED 0
115#define I40IW_DO_NOT_SEND_RESET_EVENT 1
116#define I40IW_SEND_RESET_EVENT 2
117
118#define MAX_I40IW_IFS 4
119
120#define SET_ACK 0x1
121#define SET_SYN 0x2
122#define SET_FIN 0x4
123#define SET_RST 0x8
124
125#define TCP_OPTIONS_PADDING 3
126
127struct option_base {
128 u8 optionnum;
129 u8 length;
130};
131
132enum option_numbers {
133 OPTION_NUMBER_END,
134 OPTION_NUMBER_NONE,
135 OPTION_NUMBER_MSS,
136 OPTION_NUMBER_WINDOW_SCALE,
137 OPTION_NUMBER_SACK_PERM,
138 OPTION_NUMBER_SACK,
139 OPTION_NUMBER_WRITE0 = 0xbc
140};
141
142struct option_mss {
143 u8 optionnum;
144 u8 length;
145 __be16 mss;
146};
147
148struct option_windowscale {
149 u8 optionnum;
150 u8 length;
151 u8 shiftcount;
152};
153
154union all_known_options {
155 char as_end;
156 struct option_base as_base;
157 struct option_mss as_mss;
158 struct option_windowscale as_windowscale;
159};
160
161struct i40iw_timer_entry {
162 struct list_head list;
163 unsigned long timetosend; /* jiffies */
164 struct i40iw_puda_buf *sqbuf;
165 u32 type;
166 u32 retrycount;
167 u32 retranscount;
168 u32 context;
169 u32 send_retrans;
170 int close_when_complete;
171};
172
173#define I40IW_DEFAULT_RETRYS 64
174#define I40IW_DEFAULT_RETRANS 8
175#define I40IW_DEFAULT_TTL 0x40
176#define I40IW_DEFAULT_RTT_VAR 0x6
177#define I40IW_DEFAULT_SS_THRESH 0x3FFFFFFF
178#define I40IW_DEFAULT_REXMIT_THRESH 8
179
180#define I40IW_RETRY_TIMEOUT HZ
181#define I40IW_SHORT_TIME 10
182#define I40IW_LONG_TIME (2 * HZ)
183#define I40IW_MAX_TIMEOUT ((unsigned long)(12 * HZ))
184
185#define I40IW_CM_HASHTABLE_SIZE 1024
186#define I40IW_CM_TCP_TIMER_INTERVAL 3000
187#define I40IW_CM_DEFAULT_MTU 1540
188#define I40IW_CM_DEFAULT_FRAME_CNT 10
189#define I40IW_CM_THREAD_STACK_SIZE 256
190#define I40IW_CM_DEFAULT_RCV_WND 64240
191#define I40IW_CM_DEFAULT_RCV_WND_SCALED 0x3fffc
192#define I40IW_CM_DEFAULT_RCV_WND_SCALE 2
193#define I40IW_CM_DEFAULT_FREE_PKTS 0x000A
194#define I40IW_CM_FREE_PKT_LO_WATERMARK 2
195
196#define I40IW_CM_DEFAULT_MSS 536
197
198#define I40IW_CM_DEF_SEQ 0x159bf75f
199#define I40IW_CM_DEF_LOCAL_ID 0x3b47
200
201#define I40IW_CM_DEF_SEQ2 0x18ed5740
202#define I40IW_CM_DEF_LOCAL_ID2 0xb807
203#define MAX_CM_BUFFER (I40IW_MAX_IETF_SIZE + IETF_MAX_PRIV_DATA_LEN)
204
205typedef u32 i40iw_addr_t;
206
207#define i40iw_cm_tsa_context i40iw_qp_context
208
209struct i40iw_qp;
210
211/* cm node transition states */
212enum i40iw_cm_node_state {
213 I40IW_CM_STATE_UNKNOWN,
214 I40IW_CM_STATE_INITED,
215 I40IW_CM_STATE_LISTENING,
216 I40IW_CM_STATE_SYN_RCVD,
217 I40IW_CM_STATE_SYN_SENT,
218 I40IW_CM_STATE_ONE_SIDE_ESTABLISHED,
219 I40IW_CM_STATE_ESTABLISHED,
220 I40IW_CM_STATE_ACCEPTING,
221 I40IW_CM_STATE_MPAREQ_SENT,
222 I40IW_CM_STATE_MPAREQ_RCVD,
223 I40IW_CM_STATE_MPAREJ_RCVD,
224 I40IW_CM_STATE_OFFLOADED,
225 I40IW_CM_STATE_FIN_WAIT1,
226 I40IW_CM_STATE_FIN_WAIT2,
227 I40IW_CM_STATE_CLOSE_WAIT,
228 I40IW_CM_STATE_TIME_WAIT,
229 I40IW_CM_STATE_LAST_ACK,
230 I40IW_CM_STATE_CLOSING,
231 I40IW_CM_STATE_LISTENER_DESTROYED,
232 I40IW_CM_STATE_CLOSED
233};
234
235enum mpa_frame_version {
236 IETF_MPA_V1 = 1,
237 IETF_MPA_V2 = 2
238};
239
240enum mpa_frame_key {
241 MPA_KEY_REQUEST,
242 MPA_KEY_REPLY
243};
244
245enum send_rdma0 {
246 SEND_RDMA_READ_ZERO = 1,
247 SEND_RDMA_WRITE_ZERO = 2
248};
249
250enum i40iw_tcpip_pkt_type {
251 I40IW_PKT_TYPE_UNKNOWN,
252 I40IW_PKT_TYPE_SYN,
253 I40IW_PKT_TYPE_SYNACK,
254 I40IW_PKT_TYPE_ACK,
255 I40IW_PKT_TYPE_FIN,
256 I40IW_PKT_TYPE_RST
257};
258
259/* CM context params */
260struct i40iw_cm_tcp_context {
261 u8 client;
262
263 u32 loc_seq_num;
264 u32 loc_ack_num;
265 u32 rem_ack_num;
266 u32 rcv_nxt;
267
268 u32 loc_id;
269 u32 rem_id;
270
271 u32 snd_wnd;
272 u32 max_snd_wnd;
273
274 u32 rcv_wnd;
275 u32 mss;
276 u8 snd_wscale;
277 u8 rcv_wscale;
278
279 struct timeval sent_ts;
280};
281
282enum i40iw_cm_listener_state {
283 I40IW_CM_LISTENER_PASSIVE_STATE = 1,
284 I40IW_CM_LISTENER_ACTIVE_STATE = 2,
285 I40IW_CM_LISTENER_EITHER_STATE = 3
286};
287
288struct i40iw_cm_listener {
289 struct list_head list;
290 struct i40iw_cm_core *cm_core;
291 u8 loc_mac[ETH_ALEN];
292 u32 loc_addr[4];
293 u16 loc_port;
294 u32 map_loc_addr[4];
295 u16 map_loc_port;
296 struct iw_cm_id *cm_id;
297 atomic_t ref_count;
298 struct i40iw_device *iwdev;
299 atomic_t pend_accepts_cnt;
300 int backlog;
301 enum i40iw_cm_listener_state listener_state;
302 u32 reused_node;
303 u8 user_pri;
304 u16 vlan_id;
305 bool qhash_set;
306 bool ipv4;
307 struct list_head child_listen_list;
308
309};
310
311struct i40iw_kmem_info {
312 void *addr;
313 u32 size;
314};
315
316/* per connection node and node state information */
317struct i40iw_cm_node {
318 u32 loc_addr[4], rem_addr[4];
319 u16 loc_port, rem_port;
320 u32 map_loc_addr[4], map_rem_addr[4];
321 u16 map_loc_port, map_rem_port;
322 u16 vlan_id;
323 enum i40iw_cm_node_state state;
324 u8 loc_mac[ETH_ALEN];
325 u8 rem_mac[ETH_ALEN];
326 atomic_t ref_count;
327 struct i40iw_qp *iwqp;
328 struct i40iw_device *iwdev;
329 struct i40iw_sc_dev *dev;
330 struct i40iw_cm_tcp_context tcp_cntxt;
331 struct i40iw_cm_core *cm_core;
332 struct i40iw_cm_node *loopbackpartner;
333 struct i40iw_timer_entry *send_entry;
334 struct i40iw_timer_entry *close_entry;
335 spinlock_t retrans_list_lock; /* cm transmit packet */
336 enum send_rdma0 send_rdma0_op;
337 u16 ird_size;
338 u16 ord_size;
339 u16 mpav2_ird_ord;
340 struct iw_cm_id *cm_id;
341 struct list_head list;
342 int accelerated;
343 struct i40iw_cm_listener *listener;
344 int apbvt_set;
345 int accept_pend;
346 struct list_head timer_entry;
347 struct list_head reset_entry;
348 atomic_t passive_state;
349 bool qhash_set;
350 u8 user_pri;
351 bool ipv4;
352 bool snd_mark_en;
353 u16 lsmm_size;
354 enum mpa_frame_version mpa_frame_rev;
355 struct i40iw_kmem_info pdata;
356 union {
357 struct ietf_mpa_v1 mpa_frame;
358 struct ietf_mpa_v2 mpa_v2_frame;
359 };
360
361 u8 pdata_buf[IETF_MAX_PRIV_DATA_LEN];
362 struct i40iw_kmem_info mpa_hdr;
363};
364
365/* structure for client or CM to fill when making CM api calls. */
366/* - only need to set relevant data, based on op. */
367struct i40iw_cm_info {
368 struct iw_cm_id *cm_id;
369 u16 loc_port;
370 u16 rem_port;
371 u32 loc_addr[4];
372 u32 rem_addr[4];
373 u16 map_loc_port;
374 u16 map_rem_port;
375 u32 map_loc_addr[4];
376 u32 map_rem_addr[4];
377 u16 vlan_id;
378 int backlog;
379 u16 user_pri;
380 bool ipv4;
381};
382
383/* CM event codes */
384enum i40iw_cm_event_type {
385 I40IW_CM_EVENT_UNKNOWN,
386 I40IW_CM_EVENT_ESTABLISHED,
387 I40IW_CM_EVENT_MPA_REQ,
388 I40IW_CM_EVENT_MPA_CONNECT,
389 I40IW_CM_EVENT_MPA_ACCEPT,
390 I40IW_CM_EVENT_MPA_REJECT,
391 I40IW_CM_EVENT_MPA_ESTABLISHED,
392 I40IW_CM_EVENT_CONNECTED,
393 I40IW_CM_EVENT_RESET,
394 I40IW_CM_EVENT_ABORTED
395};
396
397/* event to post to CM event handler */
398struct i40iw_cm_event {
399 enum i40iw_cm_event_type type;
400 struct i40iw_cm_info cm_info;
401 struct work_struct event_work;
402 struct i40iw_cm_node *cm_node;
403};
404
405struct i40iw_cm_core {
406 struct i40iw_device *iwdev;
407 struct i40iw_sc_dev *dev;
408
409 struct list_head listen_nodes;
410 struct list_head connected_nodes;
411
412 struct timer_list tcp_timer;
413
414 struct workqueue_struct *event_wq;
415 struct workqueue_struct *disconn_wq;
416
417 spinlock_t ht_lock; /* manage hash table */
418 spinlock_t listen_list_lock; /* listen list */
419
420 u64 stats_nodes_created;
421 u64 stats_nodes_destroyed;
422 u64 stats_listen_created;
423 u64 stats_listen_destroyed;
424 u64 stats_listen_nodes_created;
425 u64 stats_listen_nodes_destroyed;
426 u64 stats_loopbacks;
427 u64 stats_accepts;
428 u64 stats_rejects;
429 u64 stats_connect_errs;
430 u64 stats_passive_errs;
431 u64 stats_pkt_retrans;
432 u64 stats_backlog_drops;
433};
434
435int i40iw_schedule_cm_timer(struct i40iw_cm_node *cm_node,
436 struct i40iw_puda_buf *sqbuf,
437 enum i40iw_timer_type type,
438 int send_retrans,
439 int close_when_complete);
440
441int i40iw_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
442int i40iw_reject(struct iw_cm_id *, const void *, u8);
443int i40iw_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
444int i40iw_create_listen(struct iw_cm_id *, int);
445int i40iw_destroy_listen(struct iw_cm_id *);
446
447int i40iw_cm_start(struct i40iw_device *);
448int i40iw_cm_stop(struct i40iw_device *);
449
450int i40iw_arp_table(struct i40iw_device *iwdev,
451 u32 *ip_addr,
452 bool ipv4,
453 u8 *mac_addr,
454 u32 action);
455
456#endif /* I40IW_CM_H */
diff --git a/drivers/infiniband/hw/i40iw/i40iw_ctrl.c b/drivers/infiniband/hw/i40iw/i40iw_ctrl.c
new file mode 100644
index 000000000000..f05802bf6ca0
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_ctrl.c
@@ -0,0 +1,4743 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_osdep.h"
36#include "i40iw_register.h"
37#include "i40iw_status.h"
38#include "i40iw_hmc.h"
39
40#include "i40iw_d.h"
41#include "i40iw_type.h"
42#include "i40iw_p.h"
43#include "i40iw_vf.h"
44#include "i40iw_virtchnl.h"
45
46/**
47 * i40iw_insert_wqe_hdr - write wqe header
48 * @wqe: cqp wqe for header
49 * @header: header for the cqp wqe
50 */
51static inline void i40iw_insert_wqe_hdr(u64 *wqe, u64 header)
52{
53 wmb(); /* make sure WQE is populated before polarity is set */
54 set_64bit_val(wqe, 24, header);
55}
56
57/**
58 * i40iw_get_cqp_reg_info - get head and tail for cqp using registers
59 * @cqp: struct for cqp hw
60 * @val: cqp tail register value
61 * @tail:wqtail register value
62 * @error: cqp processing err
63 */
64static inline void i40iw_get_cqp_reg_info(struct i40iw_sc_cqp *cqp,
65 u32 *val,
66 u32 *tail,
67 u32 *error)
68{
69 if (cqp->dev->is_pf) {
70 *val = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPTAIL);
71 *tail = RS_32(*val, I40E_PFPE_CQPTAIL_WQTAIL);
72 *error = RS_32(*val, I40E_PFPE_CQPTAIL_CQP_OP_ERR);
73 } else {
74 *val = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPTAIL1);
75 *tail = RS_32(*val, I40E_VFPE_CQPTAIL_WQTAIL);
76 *error = RS_32(*val, I40E_VFPE_CQPTAIL_CQP_OP_ERR);
77 }
78}
79
80/**
81 * i40iw_cqp_poll_registers - poll cqp registers
82 * @cqp: struct for cqp hw
83 * @tail:wqtail register value
84 * @count: how many times to try for completion
85 */
86static enum i40iw_status_code i40iw_cqp_poll_registers(
87 struct i40iw_sc_cqp *cqp,
88 u32 tail,
89 u32 count)
90{
91 u32 i = 0;
92 u32 newtail, error, val;
93
94 while (i < count) {
95 i++;
96 i40iw_get_cqp_reg_info(cqp, &val, &newtail, &error);
97 if (error) {
98 error = (cqp->dev->is_pf) ?
99 i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPERRCODES) :
100 i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPERRCODES1);
101 return I40IW_ERR_CQP_COMPL_ERROR;
102 }
103 if (newtail != tail) {
104 /* SUCCESS */
105 I40IW_RING_MOVE_TAIL(cqp->sq_ring);
106 return 0;
107 }
108 udelay(I40IW_SLEEP_COUNT);
109 }
110 return I40IW_ERR_TIMEOUT;
111}
112
113/**
114 * i40iw_sc_parse_fpm_commit_buf - parse fpm commit buffer
115 * @buf: ptr to fpm commit buffer
116 * @info: ptr to i40iw_hmc_obj_info struct
117 *
118 * parses fpm commit info and copy base value
119 * of hmc objects in hmc_info
120 */
121static enum i40iw_status_code i40iw_sc_parse_fpm_commit_buf(
122 u64 *buf,
123 struct i40iw_hmc_obj_info *info)
124{
125 u64 temp;
126 u32 i, j;
127 u32 low;
128
129 /* copy base values in obj_info */
130 for (i = I40IW_HMC_IW_QP, j = 0;
131 i <= I40IW_HMC_IW_PBLE; i++, j += 8) {
132 get_64bit_val(buf, j, &temp);
133 info[i].base = RS_64_1(temp, 32) * 512;
134 low = (u32)(temp);
135 if (low)
136 info[i].cnt = low;
137 }
138 return 0;
139}
140
141/**
142 * i40iw_sc_parse_fpm_query_buf() - parses fpm query buffer
143 * @buf: ptr to fpm query buffer
144 * @info: ptr to i40iw_hmc_obj_info struct
145 * @hmc_fpm_misc: ptr to fpm data
146 *
147 * parses fpm query buffer and copy max_cnt and
148 * size value of hmc objects in hmc_info
149 */
150static enum i40iw_status_code i40iw_sc_parse_fpm_query_buf(
151 u64 *buf,
152 struct i40iw_hmc_info *hmc_info,
153 struct i40iw_hmc_fpm_misc *hmc_fpm_misc)
154{
155 u64 temp;
156 struct i40iw_hmc_obj_info *obj_info;
157 u32 i, j, size;
158 u16 max_pe_sds;
159
160 obj_info = hmc_info->hmc_obj;
161
162 get_64bit_val(buf, 0, &temp);
163 hmc_info->first_sd_index = (u16)RS_64(temp, I40IW_QUERY_FPM_FIRST_PE_SD_INDEX);
164 max_pe_sds = (u16)RS_64(temp, I40IW_QUERY_FPM_MAX_PE_SDS);
165
166 /* Reduce SD count for VFs by 1 to account for PBLE backing page rounding */
167 if (hmc_info->hmc_fn_id >= I40IW_FIRST_VF_FPM_ID)
168 max_pe_sds--;
169 hmc_fpm_misc->max_sds = max_pe_sds;
170 hmc_info->sd_table.sd_cnt = max_pe_sds + hmc_info->first_sd_index;
171
172 for (i = I40IW_HMC_IW_QP, j = 8;
173 i <= I40IW_HMC_IW_ARP; i++, j += 8) {
174 get_64bit_val(buf, j, &temp);
175 if (i == I40IW_HMC_IW_QP)
176 obj_info[i].max_cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_QPS);
177 else if (i == I40IW_HMC_IW_CQ)
178 obj_info[i].max_cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_CQS);
179 else
180 obj_info[i].max_cnt = (u32)temp;
181
182 size = (u32)RS_64_1(temp, 32);
183 obj_info[i].size = ((u64)1 << size);
184 }
185 for (i = I40IW_HMC_IW_MR, j = 48;
186 i <= I40IW_HMC_IW_PBLE; i++, j += 8) {
187 get_64bit_val(buf, j, &temp);
188 obj_info[i].max_cnt = (u32)temp;
189 size = (u32)RS_64_1(temp, 32);
190 obj_info[i].size = LS_64_1(1, size);
191 }
192
193 get_64bit_val(buf, 120, &temp);
194 hmc_fpm_misc->max_ceqs = (u8)RS_64(temp, I40IW_QUERY_FPM_MAX_CEQS);
195 get_64bit_val(buf, 120, &temp);
196 hmc_fpm_misc->ht_multiplier = RS_64(temp, I40IW_QUERY_FPM_HTMULTIPLIER);
197 get_64bit_val(buf, 120, &temp);
198 hmc_fpm_misc->timer_bucket = RS_64(temp, I40IW_QUERY_FPM_TIMERBUCKET);
199 get_64bit_val(buf, 64, &temp);
200 hmc_fpm_misc->xf_block_size = RS_64(temp, I40IW_QUERY_FPM_XFBLOCKSIZE);
201 if (!hmc_fpm_misc->xf_block_size)
202 return I40IW_ERR_INVALID_SIZE;
203 get_64bit_val(buf, 80, &temp);
204 hmc_fpm_misc->q1_block_size = RS_64(temp, I40IW_QUERY_FPM_Q1BLOCKSIZE);
205 if (!hmc_fpm_misc->q1_block_size)
206 return I40IW_ERR_INVALID_SIZE;
207 return 0;
208}
209
210/**
211 * i40iw_sc_pd_init - initialize sc pd struct
212 * @dev: sc device struct
213 * @pd: sc pd ptr
214 * @pd_id: pd_id for allocated pd
215 */
216static void i40iw_sc_pd_init(struct i40iw_sc_dev *dev,
217 struct i40iw_sc_pd *pd,
218 u16 pd_id)
219{
220 pd->size = sizeof(*pd);
221 pd->pd_id = pd_id;
222 pd->dev = dev;
223}
224
225/**
226 * i40iw_get_encoded_wqe_size - given wq size, returns hardware encoded size
227 * @wqsize: size of the wq (sq, rq, srq) to encoded_size
228 * @cqpsq: encoded size for sq for cqp as its encoded size is 1+ other wq's
229 */
230u8 i40iw_get_encoded_wqe_size(u32 wqsize, bool cqpsq)
231{
232 u8 encoded_size = 0;
233
234 /* cqp sq's hw coded value starts from 1 for size of 4
235 * while it starts from 0 for qp' wq's.
236 */
237 if (cqpsq)
238 encoded_size = 1;
239 wqsize >>= 2;
240 while (wqsize >>= 1)
241 encoded_size++;
242 return encoded_size;
243}
244
245/**
246 * i40iw_sc_cqp_init - Initialize buffers for a control Queue Pair
247 * @cqp: IWARP control queue pair pointer
248 * @info: IWARP control queue pair init info pointer
249 *
250 * Initializes the object and context buffers for a control Queue Pair.
251 */
252static enum i40iw_status_code i40iw_sc_cqp_init(struct i40iw_sc_cqp *cqp,
253 struct i40iw_cqp_init_info *info)
254{
255 u8 hw_sq_size;
256
257 if ((info->sq_size > I40IW_CQP_SW_SQSIZE_2048) ||
258 (info->sq_size < I40IW_CQP_SW_SQSIZE_4) ||
259 ((info->sq_size & (info->sq_size - 1))))
260 return I40IW_ERR_INVALID_SIZE;
261
262 hw_sq_size = i40iw_get_encoded_wqe_size(info->sq_size, true);
263 cqp->size = sizeof(*cqp);
264 cqp->sq_size = info->sq_size;
265 cqp->hw_sq_size = hw_sq_size;
266 cqp->sq_base = info->sq;
267 cqp->host_ctx = info->host_ctx;
268 cqp->sq_pa = info->sq_pa;
269 cqp->host_ctx_pa = info->host_ctx_pa;
270 cqp->dev = info->dev;
271 cqp->struct_ver = info->struct_ver;
272 cqp->scratch_array = info->scratch_array;
273 cqp->polarity = 0;
274 cqp->en_datacenter_tcp = info->en_datacenter_tcp;
275 cqp->enabled_vf_count = info->enabled_vf_count;
276 cqp->hmc_profile = info->hmc_profile;
277 info->dev->cqp = cqp;
278
279 I40IW_RING_INIT(cqp->sq_ring, cqp->sq_size);
280 i40iw_debug(cqp->dev, I40IW_DEBUG_WQE,
281 "%s: sq_size[%04d] hw_sq_size[%04d] sq_base[%p] sq_pa[%llxh] cqp[%p] polarity[x%04X]\n",
282 __func__, cqp->sq_size, cqp->hw_sq_size,
283 cqp->sq_base, cqp->sq_pa, cqp, cqp->polarity);
284 return 0;
285}
286
287/**
288 * i40iw_sc_cqp_create - create cqp during bringup
289 * @cqp: struct for cqp hw
290 * @disable_pfpdus: if pfpdu to be disabled
291 * @maj_err: If error, major err number
292 * @min_err: If error, minor err number
293 */
294static enum i40iw_status_code i40iw_sc_cqp_create(struct i40iw_sc_cqp *cqp,
295 bool disable_pfpdus,
296 u16 *maj_err,
297 u16 *min_err)
298{
299 u64 temp;
300 u32 cnt = 0, p1, p2, val = 0, err_code;
301 enum i40iw_status_code ret_code;
302
303 ret_code = i40iw_allocate_dma_mem(cqp->dev->hw,
304 &cqp->sdbuf,
305 128,
306 I40IW_SD_BUF_ALIGNMENT);
307
308 if (ret_code)
309 goto exit;
310
311 temp = LS_64(cqp->hw_sq_size, I40IW_CQPHC_SQSIZE) |
312 LS_64(cqp->struct_ver, I40IW_CQPHC_SVER);
313
314 if (disable_pfpdus)
315 temp |= LS_64(1, I40IW_CQPHC_DISABLE_PFPDUS);
316
317 set_64bit_val(cqp->host_ctx, 0, temp);
318 set_64bit_val(cqp->host_ctx, 8, cqp->sq_pa);
319 temp = LS_64(cqp->enabled_vf_count, I40IW_CQPHC_ENABLED_VFS) |
320 LS_64(cqp->hmc_profile, I40IW_CQPHC_HMC_PROFILE);
321 set_64bit_val(cqp->host_ctx, 16, temp);
322 set_64bit_val(cqp->host_ctx, 24, (uintptr_t)cqp);
323 set_64bit_val(cqp->host_ctx, 32, 0);
324 set_64bit_val(cqp->host_ctx, 40, 0);
325 set_64bit_val(cqp->host_ctx, 48, 0);
326 set_64bit_val(cqp->host_ctx, 56, 0);
327
328 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQP_HOST_CTX",
329 cqp->host_ctx, I40IW_CQP_CTX_SIZE * 8);
330
331 p1 = RS_32_1(cqp->host_ctx_pa, 32);
332 p2 = (u32)cqp->host_ctx_pa;
333
334 if (cqp->dev->is_pf) {
335 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPHIGH, p1);
336 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPLOW, p2);
337 } else {
338 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPHIGH1, p1);
339 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPLOW1, p2);
340 }
341 do {
342 if (cnt++ > I40IW_DONE_COUNT) {
343 i40iw_free_dma_mem(cqp->dev->hw, &cqp->sdbuf);
344 ret_code = I40IW_ERR_TIMEOUT;
345 /*
346 * read PFPE_CQPERRORCODES register to get the minor
347 * and major error code
348 */
349 if (cqp->dev->is_pf)
350 err_code = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPERRCODES);
351 else
352 err_code = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPERRCODES1);
353 *min_err = RS_32(err_code, I40E_PFPE_CQPERRCODES_CQP_MINOR_CODE);
354 *maj_err = RS_32(err_code, I40E_PFPE_CQPERRCODES_CQP_MAJOR_CODE);
355 goto exit;
356 }
357 udelay(I40IW_SLEEP_COUNT);
358 if (cqp->dev->is_pf)
359 val = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CCQPSTATUS);
360 else
361 val = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CCQPSTATUS1);
362 } while (!val);
363
364exit:
365 if (!ret_code)
366 cqp->process_cqp_sds = i40iw_update_sds_noccq;
367 return ret_code;
368}
369
370/**
371 * i40iw_sc_cqp_post_sq - post of cqp's sq
372 * @cqp: struct for cqp hw
373 */
374void i40iw_sc_cqp_post_sq(struct i40iw_sc_cqp *cqp)
375{
376 if (cqp->dev->is_pf)
377 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CQPDB, I40IW_RING_GETCURRENT_HEAD(cqp->sq_ring));
378 else
379 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CQPDB1, I40IW_RING_GETCURRENT_HEAD(cqp->sq_ring));
380
381 i40iw_debug(cqp->dev,
382 I40IW_DEBUG_WQE,
383 "%s: HEAD_TAIL[%04d,%04d,%04d]\n",
384 __func__,
385 cqp->sq_ring.head,
386 cqp->sq_ring.tail,
387 cqp->sq_ring.size);
388}
389
390/**
391 * i40iw_sc_cqp_get_next_send_wqe - get next wqe on cqp sq
392 * @cqp: struct for cqp hw
393 * @wqe_idx: we index of cqp ring
394 */
395u64 *i40iw_sc_cqp_get_next_send_wqe(struct i40iw_sc_cqp *cqp, u64 scratch)
396{
397 u64 *wqe = NULL;
398 u32 wqe_idx;
399 enum i40iw_status_code ret_code;
400
401 if (I40IW_RING_FULL_ERR(cqp->sq_ring)) {
402 i40iw_debug(cqp->dev,
403 I40IW_DEBUG_WQE,
404 "%s: ring is full head %x tail %x size %x\n",
405 __func__,
406 cqp->sq_ring.head,
407 cqp->sq_ring.tail,
408 cqp->sq_ring.size);
409 return NULL;
410 }
411 I40IW_ATOMIC_RING_MOVE_HEAD(cqp->sq_ring, wqe_idx, ret_code);
412 if (ret_code)
413 return NULL;
414 if (!wqe_idx)
415 cqp->polarity = !cqp->polarity;
416
417 wqe = cqp->sq_base[wqe_idx].elem;
418 cqp->scratch_array[wqe_idx] = scratch;
419 I40IW_CQP_INIT_WQE(wqe);
420
421 return wqe;
422}
423
424/**
425 * i40iw_sc_cqp_destroy - destroy cqp during close
426 * @cqp: struct for cqp hw
427 */
428static enum i40iw_status_code i40iw_sc_cqp_destroy(struct i40iw_sc_cqp *cqp)
429{
430 u32 cnt = 0, val = 1;
431 enum i40iw_status_code ret_code = 0;
432 u32 cqpstat_addr;
433
434 if (cqp->dev->is_pf) {
435 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPHIGH, 0);
436 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPLOW, 0);
437 cqpstat_addr = I40E_PFPE_CCQPSTATUS;
438 } else {
439 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPHIGH1, 0);
440 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPLOW1, 0);
441 cqpstat_addr = I40E_VFPE_CCQPSTATUS1;
442 }
443 do {
444 if (cnt++ > I40IW_DONE_COUNT) {
445 ret_code = I40IW_ERR_TIMEOUT;
446 break;
447 }
448 udelay(I40IW_SLEEP_COUNT);
449 val = i40iw_rd32(cqp->dev->hw, cqpstat_addr);
450 } while (val);
451
452 i40iw_free_dma_mem(cqp->dev->hw, &cqp->sdbuf);
453 return ret_code;
454}
455
456/**
457 * i40iw_sc_ccq_arm - enable intr for control cq
458 * @ccq: ccq sc struct
459 */
460static void i40iw_sc_ccq_arm(struct i40iw_sc_cq *ccq)
461{
462 u64 temp_val;
463 u16 sw_cq_sel;
464 u8 arm_next_se;
465 u8 arm_seq_num;
466
467 /* write to cq doorbell shadow area */
468 /* arm next se should always be zero */
469 get_64bit_val(ccq->cq_uk.shadow_area, 32, &temp_val);
470
471 sw_cq_sel = (u16)RS_64(temp_val, I40IW_CQ_DBSA_SW_CQ_SELECT);
472 arm_next_se = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_NEXT_SE);
473
474 arm_seq_num = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_SEQ_NUM);
475 arm_seq_num++;
476
477 temp_val = LS_64(arm_seq_num, I40IW_CQ_DBSA_ARM_SEQ_NUM) |
478 LS_64(sw_cq_sel, I40IW_CQ_DBSA_SW_CQ_SELECT) |
479 LS_64(arm_next_se, I40IW_CQ_DBSA_ARM_NEXT_SE) |
480 LS_64(1, I40IW_CQ_DBSA_ARM_NEXT);
481
482 set_64bit_val(ccq->cq_uk.shadow_area, 32, temp_val);
483
484 wmb(); /* make sure shadow area is updated before arming */
485
486 if (ccq->dev->is_pf)
487 i40iw_wr32(ccq->dev->hw, I40E_PFPE_CQARM, ccq->cq_uk.cq_id);
488 else
489 i40iw_wr32(ccq->dev->hw, I40E_VFPE_CQARM1, ccq->cq_uk.cq_id);
490}
491
492/**
493 * i40iw_sc_ccq_get_cqe_info - get ccq's cq entry
494 * @ccq: ccq sc struct
495 * @info: completion q entry to return
496 */
497static enum i40iw_status_code i40iw_sc_ccq_get_cqe_info(
498 struct i40iw_sc_cq *ccq,
499 struct i40iw_ccq_cqe_info *info)
500{
501 u64 qp_ctx, temp, temp1;
502 u64 *cqe;
503 struct i40iw_sc_cqp *cqp;
504 u32 wqe_idx;
505 u8 polarity;
506 enum i40iw_status_code ret_code = 0;
507
508 if (ccq->cq_uk.avoid_mem_cflct)
509 cqe = (u64 *)I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(&ccq->cq_uk);
510 else
511 cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(&ccq->cq_uk);
512
513 get_64bit_val(cqe, 24, &temp);
514 polarity = (u8)RS_64(temp, I40IW_CQ_VALID);
515 if (polarity != ccq->cq_uk.polarity)
516 return I40IW_ERR_QUEUE_EMPTY;
517
518 get_64bit_val(cqe, 8, &qp_ctx);
519 cqp = (struct i40iw_sc_cqp *)(unsigned long)qp_ctx;
520 info->error = (bool)RS_64(temp, I40IW_CQ_ERROR);
521 info->min_err_code = (u16)RS_64(temp, I40IW_CQ_MINERR);
522 if (info->error) {
523 info->maj_err_code = (u16)RS_64(temp, I40IW_CQ_MAJERR);
524 info->min_err_code = (u16)RS_64(temp, I40IW_CQ_MINERR);
525 }
526 wqe_idx = (u32)RS_64(temp, I40IW_CQ_WQEIDX);
527 info->scratch = cqp->scratch_array[wqe_idx];
528
529 get_64bit_val(cqe, 16, &temp1);
530 info->op_ret_val = (u32)RS_64(temp1, I40IW_CCQ_OPRETVAL);
531 get_64bit_val(cqp->sq_base[wqe_idx].elem, 24, &temp1);
532 info->op_code = (u8)RS_64(temp1, I40IW_CQPSQ_OPCODE);
533 info->cqp = cqp;
534
535 /* move the head for cq */
536 I40IW_RING_MOVE_HEAD(ccq->cq_uk.cq_ring, ret_code);
537 if (I40IW_RING_GETCURRENT_HEAD(ccq->cq_uk.cq_ring) == 0)
538 ccq->cq_uk.polarity ^= 1;
539
540 /* update cq tail in cq shadow memory also */
541 I40IW_RING_MOVE_TAIL(ccq->cq_uk.cq_ring);
542 set_64bit_val(ccq->cq_uk.shadow_area,
543 0,
544 I40IW_RING_GETCURRENT_HEAD(ccq->cq_uk.cq_ring));
545 wmb(); /* write shadow area before tail */
546 I40IW_RING_MOVE_TAIL(cqp->sq_ring);
547 return ret_code;
548}
549
550/**
551 * i40iw_sc_poll_for_cqp_op_done - Waits for last write to complete in CQP SQ
552 * @cqp: struct for cqp hw
553 * @op_code: cqp opcode for completion
554 * @info: completion q entry to return
555 */
556static enum i40iw_status_code i40iw_sc_poll_for_cqp_op_done(
557 struct i40iw_sc_cqp *cqp,
558 u8 op_code,
559 struct i40iw_ccq_cqe_info *compl_info)
560{
561 struct i40iw_ccq_cqe_info info;
562 struct i40iw_sc_cq *ccq;
563 enum i40iw_status_code ret_code = 0;
564 u32 cnt = 0;
565
566 memset(&info, 0, sizeof(info));
567 ccq = cqp->dev->ccq;
568 while (1) {
569 if (cnt++ > I40IW_DONE_COUNT)
570 return I40IW_ERR_TIMEOUT;
571
572 if (i40iw_sc_ccq_get_cqe_info(ccq, &info)) {
573 udelay(I40IW_SLEEP_COUNT);
574 continue;
575 }
576
577 if (info.error) {
578 ret_code = I40IW_ERR_CQP_COMPL_ERROR;
579 break;
580 }
581 /* check if opcode is cq create */
582 if (op_code != info.op_code) {
583 i40iw_debug(cqp->dev, I40IW_DEBUG_WQE,
584 "%s: opcode mismatch for my op code 0x%x, returned opcode %x\n",
585 __func__, op_code, info.op_code);
586 }
587 /* success, exit out of the loop */
588 if (op_code == info.op_code)
589 break;
590 }
591
592 if (compl_info)
593 memcpy(compl_info, &info, sizeof(*compl_info));
594
595 return ret_code;
596}
597
598/**
599 * i40iw_sc_manage_push_page - Handle push page
600 * @cqp: struct for cqp hw
601 * @info: push page info
602 * @scratch: u64 saved to be used during cqp completion
603 * @post_sq: flag for cqp db to ring
604 */
605static enum i40iw_status_code i40iw_sc_manage_push_page(
606 struct i40iw_sc_cqp *cqp,
607 struct i40iw_cqp_manage_push_page_info *info,
608 u64 scratch,
609 bool post_sq)
610{
611 u64 *wqe;
612 u64 header;
613
614 if (info->push_idx >= I40IW_MAX_PUSH_PAGE_COUNT)
615 return I40IW_ERR_INVALID_PUSH_PAGE_INDEX;
616
617 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
618 if (!wqe)
619 return I40IW_ERR_RING_FULL;
620
621 set_64bit_val(wqe, 16, info->qs_handle);
622
623 header = LS_64(info->push_idx, I40IW_CQPSQ_MPP_PPIDX) |
624 LS_64(I40IW_CQP_OP_MANAGE_PUSH_PAGES, I40IW_CQPSQ_OPCODE) |
625 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
626 LS_64(info->free_page, I40IW_CQPSQ_MPP_FREE_PAGE);
627
628 i40iw_insert_wqe_hdr(wqe, header);
629
630 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_PUSH_PAGES WQE",
631 wqe, I40IW_CQP_WQE_SIZE * 8);
632
633 if (post_sq)
634 i40iw_sc_cqp_post_sq(cqp);
635 return 0;
636}
637
638/**
639 * i40iw_sc_manage_hmc_pm_func_table - manage of function table
640 * @cqp: struct for cqp hw
641 * @scratch: u64 saved to be used during cqp completion
642 * @vf_index: vf index for cqp
643 * @free_pm_fcn: function number
644 * @post_sq: flag for cqp db to ring
645 */
646static enum i40iw_status_code i40iw_sc_manage_hmc_pm_func_table(
647 struct i40iw_sc_cqp *cqp,
648 u64 scratch,
649 u8 vf_index,
650 bool free_pm_fcn,
651 bool post_sq)
652{
653 u64 *wqe;
654 u64 header;
655
656 if (vf_index >= I40IW_MAX_VF_PER_PF)
657 return I40IW_ERR_INVALID_VF_ID;
658 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
659 if (!wqe)
660 return I40IW_ERR_RING_FULL;
661
662 header = LS_64(vf_index, I40IW_CQPSQ_MHMC_VFIDX) |
663 LS_64(I40IW_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE, I40IW_CQPSQ_OPCODE) |
664 LS_64(free_pm_fcn, I40IW_CQPSQ_MHMC_FREEPMFN) |
665 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
666
667 i40iw_insert_wqe_hdr(wqe, header);
668 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_HMC_PM_FUNC_TABLE WQE",
669 wqe, I40IW_CQP_WQE_SIZE * 8);
670 if (post_sq)
671 i40iw_sc_cqp_post_sq(cqp);
672 return 0;
673}
674
675/**
676 * i40iw_sc_set_hmc_resource_profile - cqp wqe for hmc profile
677 * @cqp: struct for cqp hw
678 * @scratch: u64 saved to be used during cqp completion
679 * @hmc_profile_type: type of profile to set
680 * @vf_num: vf number for profile
681 * @post_sq: flag for cqp db to ring
682 * @poll_registers: flag to poll register for cqp completion
683 */
684static enum i40iw_status_code i40iw_sc_set_hmc_resource_profile(
685 struct i40iw_sc_cqp *cqp,
686 u64 scratch,
687 u8 hmc_profile_type,
688 u8 vf_num, bool post_sq,
689 bool poll_registers)
690{
691 u64 *wqe;
692 u64 header;
693 u32 val, tail, error;
694 enum i40iw_status_code ret_code = 0;
695
696 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
697 if (!wqe)
698 return I40IW_ERR_RING_FULL;
699
700 set_64bit_val(wqe, 16,
701 (LS_64(hmc_profile_type, I40IW_CQPSQ_SHMCRP_HMC_PROFILE) |
702 LS_64(vf_num, I40IW_CQPSQ_SHMCRP_VFNUM)));
703
704 header = LS_64(I40IW_CQP_OP_SET_HMC_RESOURCE_PROFILE, I40IW_CQPSQ_OPCODE) |
705 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
706
707 i40iw_insert_wqe_hdr(wqe, header);
708
709 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_HMC_PM_FUNC_TABLE WQE",
710 wqe, I40IW_CQP_WQE_SIZE * 8);
711
712 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
713 if (error)
714 return I40IW_ERR_CQP_COMPL_ERROR;
715
716 if (post_sq) {
717 i40iw_sc_cqp_post_sq(cqp);
718 if (poll_registers)
719 ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000000);
720 else
721 ret_code = i40iw_sc_poll_for_cqp_op_done(cqp,
722 I40IW_CQP_OP_SHMC_PAGES_ALLOCATED,
723 NULL);
724 }
725
726 return ret_code;
727}
728
729/**
730 * i40iw_sc_manage_hmc_pm_func_table_done - wait for cqp wqe completion for function table
731 * @cqp: struct for cqp hw
732 */
733static enum i40iw_status_code i40iw_sc_manage_hmc_pm_func_table_done(struct i40iw_sc_cqp *cqp)
734{
735 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE, NULL);
736}
737
738/**
739 * i40iw_sc_commit_fpm_values_done - wait for cqp eqe completion for fpm commit
740 * @cqp: struct for cqp hw
741 */
742static enum i40iw_status_code i40iw_sc_commit_fpm_values_done(struct i40iw_sc_cqp *cqp)
743{
744 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_COMMIT_FPM_VALUES, NULL);
745}
746
747/**
748 * i40iw_sc_commit_fpm_values - cqp wqe for commit fpm values
749 * @cqp: struct for cqp hw
750 * @scratch: u64 saved to be used during cqp completion
751 * @hmc_fn_id: hmc function id
752 * @commit_fpm_mem; Memory for fpm values
753 * @post_sq: flag for cqp db to ring
754 * @wait_type: poll ccq or cqp registers for cqp completion
755 */
756static enum i40iw_status_code i40iw_sc_commit_fpm_values(
757 struct i40iw_sc_cqp *cqp,
758 u64 scratch,
759 u8 hmc_fn_id,
760 struct i40iw_dma_mem *commit_fpm_mem,
761 bool post_sq,
762 u8 wait_type)
763{
764 u64 *wqe;
765 u64 header;
766 u32 tail, val, error;
767 enum i40iw_status_code ret_code = 0;
768
769 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
770 if (!wqe)
771 return I40IW_ERR_RING_FULL;
772
773 set_64bit_val(wqe, 16, hmc_fn_id);
774 set_64bit_val(wqe, 32, commit_fpm_mem->pa);
775
776 header = LS_64(I40IW_CQP_OP_COMMIT_FPM_VALUES, I40IW_CQPSQ_OPCODE) |
777 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
778
779 i40iw_insert_wqe_hdr(wqe, header);
780
781 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "COMMIT_FPM_VALUES WQE",
782 wqe, I40IW_CQP_WQE_SIZE * 8);
783
784 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
785 if (error)
786 return I40IW_ERR_CQP_COMPL_ERROR;
787
788 if (post_sq) {
789 i40iw_sc_cqp_post_sq(cqp);
790
791 if (wait_type == I40IW_CQP_WAIT_POLL_REGS)
792 ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
793 else if (wait_type == I40IW_CQP_WAIT_POLL_CQ)
794 ret_code = i40iw_sc_commit_fpm_values_done(cqp);
795 }
796
797 return ret_code;
798}
799
800/**
801 * i40iw_sc_query_fpm_values_done - poll for cqp wqe completion for query fpm
802 * @cqp: struct for cqp hw
803 */
804static enum i40iw_status_code i40iw_sc_query_fpm_values_done(struct i40iw_sc_cqp *cqp)
805{
806 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_QUERY_FPM_VALUES, NULL);
807}
808
809/**
810 * i40iw_sc_query_fpm_values - cqp wqe query fpm values
811 * @cqp: struct for cqp hw
812 * @scratch: u64 saved to be used during cqp completion
813 * @hmc_fn_id: hmc function id
814 * @query_fpm_mem: memory for return fpm values
815 * @post_sq: flag for cqp db to ring
816 * @wait_type: poll ccq or cqp registers for cqp completion
817 */
818static enum i40iw_status_code i40iw_sc_query_fpm_values(
819 struct i40iw_sc_cqp *cqp,
820 u64 scratch,
821 u8 hmc_fn_id,
822 struct i40iw_dma_mem *query_fpm_mem,
823 bool post_sq,
824 u8 wait_type)
825{
826 u64 *wqe;
827 u64 header;
828 u32 tail, val, error;
829 enum i40iw_status_code ret_code = 0;
830
831 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
832 if (!wqe)
833 return I40IW_ERR_RING_FULL;
834
835 set_64bit_val(wqe, 16, hmc_fn_id);
836 set_64bit_val(wqe, 32, query_fpm_mem->pa);
837
838 header = LS_64(I40IW_CQP_OP_QUERY_FPM_VALUES, I40IW_CQPSQ_OPCODE) |
839 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
840
841 i40iw_insert_wqe_hdr(wqe, header);
842
843 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QUERY_FPM WQE",
844 wqe, I40IW_CQP_WQE_SIZE * 8);
845
846 /* read the tail from CQP_TAIL register */
847 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
848
849 if (error)
850 return I40IW_ERR_CQP_COMPL_ERROR;
851
852 if (post_sq) {
853 i40iw_sc_cqp_post_sq(cqp);
854 if (wait_type == I40IW_CQP_WAIT_POLL_REGS)
855 ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
856 else if (wait_type == I40IW_CQP_WAIT_POLL_CQ)
857 ret_code = i40iw_sc_query_fpm_values_done(cqp);
858 }
859
860 return ret_code;
861}
862
863/**
864 * i40iw_sc_add_arp_cache_entry - cqp wqe add arp cache entry
865 * @cqp: struct for cqp hw
866 * @info: arp entry information
867 * @scratch: u64 saved to be used during cqp completion
868 * @post_sq: flag for cqp db to ring
869 */
870static enum i40iw_status_code i40iw_sc_add_arp_cache_entry(
871 struct i40iw_sc_cqp *cqp,
872 struct i40iw_add_arp_cache_entry_info *info,
873 u64 scratch,
874 bool post_sq)
875{
876 u64 *wqe;
877 u64 temp, header;
878
879 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
880 if (!wqe)
881 return I40IW_ERR_RING_FULL;
882 set_64bit_val(wqe, 8, info->reach_max);
883
884 temp = info->mac_addr[5] |
885 LS_64_1(info->mac_addr[4], 8) |
886 LS_64_1(info->mac_addr[3], 16) |
887 LS_64_1(info->mac_addr[2], 24) |
888 LS_64_1(info->mac_addr[1], 32) |
889 LS_64_1(info->mac_addr[0], 40);
890
891 set_64bit_val(wqe, 16, temp);
892
893 header = info->arp_index |
894 LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
895 LS_64((info->permanent ? 1 : 0), I40IW_CQPSQ_MAT_PERMANENT) |
896 LS_64(1, I40IW_CQPSQ_MAT_ENTRYVALID) |
897 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
898
899 i40iw_insert_wqe_hdr(wqe, header);
900
901 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ARP_CACHE_ENTRY WQE",
902 wqe, I40IW_CQP_WQE_SIZE * 8);
903
904 if (post_sq)
905 i40iw_sc_cqp_post_sq(cqp);
906 return 0;
907}
908
909/**
910 * i40iw_sc_del_arp_cache_entry - dele arp cache entry
911 * @cqp: struct for cqp hw
912 * @scratch: u64 saved to be used during cqp completion
913 * @arp_index: arp index to delete arp entry
914 * @post_sq: flag for cqp db to ring
915 */
916static enum i40iw_status_code i40iw_sc_del_arp_cache_entry(
917 struct i40iw_sc_cqp *cqp,
918 u64 scratch,
919 u16 arp_index,
920 bool post_sq)
921{
922 u64 *wqe;
923 u64 header;
924
925 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
926 if (!wqe)
927 return I40IW_ERR_RING_FULL;
928
929 header = arp_index |
930 LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
931 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
932 i40iw_insert_wqe_hdr(wqe, header);
933
934 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ARP_CACHE_DEL_ENTRY WQE",
935 wqe, I40IW_CQP_WQE_SIZE * 8);
936
937 if (post_sq)
938 i40iw_sc_cqp_post_sq(cqp);
939 return 0;
940}
941
942/**
943 * i40iw_sc_query_arp_cache_entry - cqp wqe to query arp and arp index
944 * @cqp: struct for cqp hw
945 * @scratch: u64 saved to be used during cqp completion
946 * @arp_index: arp index to delete arp entry
947 * @post_sq: flag for cqp db to ring
948 */
949static enum i40iw_status_code i40iw_sc_query_arp_cache_entry(
950 struct i40iw_sc_cqp *cqp,
951 u64 scratch,
952 u16 arp_index,
953 bool post_sq)
954{
955 u64 *wqe;
956 u64 header;
957
958 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
959 if (!wqe)
960 return I40IW_ERR_RING_FULL;
961
962 header = arp_index |
963 LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
964 LS_64(1, I40IW_CQPSQ_MAT_QUERY) |
965 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
966
967 i40iw_insert_wqe_hdr(wqe, header);
968
969 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QUERY_ARP_CACHE_ENTRY WQE",
970 wqe, I40IW_CQP_WQE_SIZE * 8);
971
972 if (post_sq)
973 i40iw_sc_cqp_post_sq(cqp);
974 return 0;
975}
976
977/**
978 * i40iw_sc_manage_apbvt_entry - for adding and deleting apbvt entries
979 * @cqp: struct for cqp hw
980 * @info: info for apbvt entry to add or delete
981 * @scratch: u64 saved to be used during cqp completion
982 * @post_sq: flag for cqp db to ring
983 */
984static enum i40iw_status_code i40iw_sc_manage_apbvt_entry(
985 struct i40iw_sc_cqp *cqp,
986 struct i40iw_apbvt_info *info,
987 u64 scratch,
988 bool post_sq)
989{
990 u64 *wqe;
991 u64 header;
992
993 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
994 if (!wqe)
995 return I40IW_ERR_RING_FULL;
996
997 set_64bit_val(wqe, 16, info->port);
998
999 header = LS_64(I40IW_CQP_OP_MANAGE_APBVT, I40IW_CQPSQ_OPCODE) |
1000 LS_64(info->add, I40IW_CQPSQ_MAPT_ADDPORT) |
1001 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1002
1003 i40iw_insert_wqe_hdr(wqe, header);
1004
1005 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_APBVT WQE",
1006 wqe, I40IW_CQP_WQE_SIZE * 8);
1007
1008 if (post_sq)
1009 i40iw_sc_cqp_post_sq(cqp);
1010 return 0;
1011}
1012
1013/**
1014 * i40iw_sc_manage_qhash_table_entry - manage quad hash entries
1015 * @cqp: struct for cqp hw
1016 * @info: info for quad hash to manage
1017 * @scratch: u64 saved to be used during cqp completion
1018 * @post_sq: flag for cqp db to ring
1019 *
1020 * This is called before connection establishment is started. For passive connections, when
1021 * listener is created, it will call with entry type of I40IW_QHASH_TYPE_TCP_SYN with local
1022 * ip address and tcp port. When SYN is received (passive connections) or
1023 * sent (active connections), this routine is called with entry type of
1024 * I40IW_QHASH_TYPE_TCP_ESTABLISHED and quad is passed in info.
1025 *
1026 * When iwarp connection is done and its state moves to RTS, the quad hash entry in
1027 * the hardware will point to iwarp's qp number and requires no calls from the driver.
1028 */
1029static enum i40iw_status_code i40iw_sc_manage_qhash_table_entry(
1030 struct i40iw_sc_cqp *cqp,
1031 struct i40iw_qhash_table_info *info,
1032 u64 scratch,
1033 bool post_sq)
1034{
1035 u64 *wqe;
1036 u64 qw1 = 0;
1037 u64 qw2 = 0;
1038 u64 temp;
1039
1040 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1041 if (!wqe)
1042 return I40IW_ERR_RING_FULL;
1043
1044 temp = info->mac_addr[5] |
1045 LS_64_1(info->mac_addr[4], 8) |
1046 LS_64_1(info->mac_addr[3], 16) |
1047 LS_64_1(info->mac_addr[2], 24) |
1048 LS_64_1(info->mac_addr[1], 32) |
1049 LS_64_1(info->mac_addr[0], 40);
1050
1051 set_64bit_val(wqe, 0, temp);
1052
1053 qw1 = LS_64(info->qp_num, I40IW_CQPSQ_QHASH_QPN) |
1054 LS_64(info->dest_port, I40IW_CQPSQ_QHASH_DEST_PORT);
1055 if (info->ipv4_valid) {
1056 set_64bit_val(wqe,
1057 48,
1058 LS_64(info->dest_ip[0], I40IW_CQPSQ_QHASH_ADDR3));
1059 } else {
1060 set_64bit_val(wqe,
1061 56,
1062 LS_64(info->dest_ip[0], I40IW_CQPSQ_QHASH_ADDR0) |
1063 LS_64(info->dest_ip[1], I40IW_CQPSQ_QHASH_ADDR1));
1064
1065 set_64bit_val(wqe,
1066 48,
1067 LS_64(info->dest_ip[2], I40IW_CQPSQ_QHASH_ADDR2) |
1068 LS_64(info->dest_ip[3], I40IW_CQPSQ_QHASH_ADDR3));
1069 }
1070 qw2 = LS_64(cqp->dev->qs_handle, I40IW_CQPSQ_QHASH_QS_HANDLE);
1071 if (info->vlan_valid)
1072 qw2 |= LS_64(info->vlan_id, I40IW_CQPSQ_QHASH_VLANID);
1073 set_64bit_val(wqe, 16, qw2);
1074 if (info->entry_type == I40IW_QHASH_TYPE_TCP_ESTABLISHED) {
1075 qw1 |= LS_64(info->src_port, I40IW_CQPSQ_QHASH_SRC_PORT);
1076 if (!info->ipv4_valid) {
1077 set_64bit_val(wqe,
1078 40,
1079 LS_64(info->src_ip[0], I40IW_CQPSQ_QHASH_ADDR0) |
1080 LS_64(info->src_ip[1], I40IW_CQPSQ_QHASH_ADDR1));
1081 set_64bit_val(wqe,
1082 32,
1083 LS_64(info->src_ip[2], I40IW_CQPSQ_QHASH_ADDR2) |
1084 LS_64(info->src_ip[3], I40IW_CQPSQ_QHASH_ADDR3));
1085 } else {
1086 set_64bit_val(wqe,
1087 32,
1088 LS_64(info->src_ip[0], I40IW_CQPSQ_QHASH_ADDR3));
1089 }
1090 }
1091
1092 set_64bit_val(wqe, 8, qw1);
1093 temp = LS_64(cqp->polarity, I40IW_CQPSQ_QHASH_WQEVALID) |
1094 LS_64(I40IW_CQP_OP_MANAGE_QUAD_HASH_TABLE_ENTRY, I40IW_CQPSQ_QHASH_OPCODE) |
1095 LS_64(info->manage, I40IW_CQPSQ_QHASH_MANAGE) |
1096 LS_64(info->ipv4_valid, I40IW_CQPSQ_QHASH_IPV4VALID) |
1097 LS_64(info->vlan_valid, I40IW_CQPSQ_QHASH_VLANVALID) |
1098 LS_64(info->entry_type, I40IW_CQPSQ_QHASH_ENTRYTYPE);
1099
1100 i40iw_insert_wqe_hdr(wqe, temp);
1101
1102 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_QHASH WQE",
1103 wqe, I40IW_CQP_WQE_SIZE * 8);
1104
1105 if (post_sq)
1106 i40iw_sc_cqp_post_sq(cqp);
1107 return 0;
1108}
1109
1110/**
1111 * i40iw_sc_alloc_local_mac_ipaddr_entry - cqp wqe for loc mac entry
1112 * @cqp: struct for cqp hw
1113 * @scratch: u64 saved to be used during cqp completion
1114 * @post_sq: flag for cqp db to ring
1115 */
1116static enum i40iw_status_code i40iw_sc_alloc_local_mac_ipaddr_entry(
1117 struct i40iw_sc_cqp *cqp,
1118 u64 scratch,
1119 bool post_sq)
1120{
1121 u64 *wqe;
1122 u64 header;
1123
1124 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1125 if (!wqe)
1126 return I40IW_ERR_RING_FULL;
1127 header = LS_64(I40IW_CQP_OP_ALLOCATE_LOC_MAC_IP_TABLE_ENTRY, I40IW_CQPSQ_OPCODE) |
1128 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1129
1130 i40iw_insert_wqe_hdr(wqe, header);
1131 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ALLOCATE_LOCAL_MAC_IPADDR WQE",
1132 wqe, I40IW_CQP_WQE_SIZE * 8);
1133 if (post_sq)
1134 i40iw_sc_cqp_post_sq(cqp);
1135 return 0;
1136}
1137
1138/**
1139 * i40iw_sc_add_local_mac_ipaddr_entry - add mac enry
1140 * @cqp: struct for cqp hw
1141 * @info:mac addr info
1142 * @scratch: u64 saved to be used during cqp completion
1143 * @post_sq: flag for cqp db to ring
1144 */
1145static enum i40iw_status_code i40iw_sc_add_local_mac_ipaddr_entry(
1146 struct i40iw_sc_cqp *cqp,
1147 struct i40iw_local_mac_ipaddr_entry_info *info,
1148 u64 scratch,
1149 bool post_sq)
1150{
1151 u64 *wqe;
1152 u64 temp, header;
1153
1154 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1155 if (!wqe)
1156 return I40IW_ERR_RING_FULL;
1157 temp = info->mac_addr[5] |
1158 LS_64_1(info->mac_addr[4], 8) |
1159 LS_64_1(info->mac_addr[3], 16) |
1160 LS_64_1(info->mac_addr[2], 24) |
1161 LS_64_1(info->mac_addr[1], 32) |
1162 LS_64_1(info->mac_addr[0], 40);
1163
1164 set_64bit_val(wqe, 32, temp);
1165
1166 header = LS_64(info->entry_idx, I40IW_CQPSQ_MLIPA_IPTABLEIDX) |
1167 LS_64(I40IW_CQP_OP_MANAGE_LOC_MAC_IP_TABLE, I40IW_CQPSQ_OPCODE) |
1168 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1169
1170 i40iw_insert_wqe_hdr(wqe, header);
1171
1172 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ADD_LOCAL_MAC_IPADDR WQE",
1173 wqe, I40IW_CQP_WQE_SIZE * 8);
1174
1175 if (post_sq)
1176 i40iw_sc_cqp_post_sq(cqp);
1177 return 0;
1178}
1179
1180/**
1181 * i40iw_sc_del_local_mac_ipaddr_entry - cqp wqe to dele local mac
1182 * @cqp: struct for cqp hw
1183 * @scratch: u64 saved to be used during cqp completion
1184 * @entry_idx: index of mac entry
1185 * @ ignore_ref_count: to force mac adde delete
1186 * @post_sq: flag for cqp db to ring
1187 */
1188static enum i40iw_status_code i40iw_sc_del_local_mac_ipaddr_entry(
1189 struct i40iw_sc_cqp *cqp,
1190 u64 scratch,
1191 u8 entry_idx,
1192 u8 ignore_ref_count,
1193 bool post_sq)
1194{
1195 u64 *wqe;
1196 u64 header;
1197
1198 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1199 if (!wqe)
1200 return I40IW_ERR_RING_FULL;
1201 header = LS_64(entry_idx, I40IW_CQPSQ_MLIPA_IPTABLEIDX) |
1202 LS_64(I40IW_CQP_OP_MANAGE_LOC_MAC_IP_TABLE, I40IW_CQPSQ_OPCODE) |
1203 LS_64(1, I40IW_CQPSQ_MLIPA_FREEENTRY) |
1204 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
1205 LS_64(ignore_ref_count, I40IW_CQPSQ_MLIPA_IGNORE_REF_CNT);
1206
1207 i40iw_insert_wqe_hdr(wqe, header);
1208
1209 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "DEL_LOCAL_MAC_IPADDR WQE",
1210 wqe, I40IW_CQP_WQE_SIZE * 8);
1211
1212 if (post_sq)
1213 i40iw_sc_cqp_post_sq(cqp);
1214 return 0;
1215}
1216
1217/**
1218 * i40iw_sc_cqp_nop - send a nop wqe
1219 * @cqp: struct for cqp hw
1220 * @scratch: u64 saved to be used during cqp completion
1221 * @post_sq: flag for cqp db to ring
1222 */
1223static enum i40iw_status_code i40iw_sc_cqp_nop(struct i40iw_sc_cqp *cqp,
1224 u64 scratch,
1225 bool post_sq)
1226{
1227 u64 *wqe;
1228 u64 header;
1229
1230 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1231 if (!wqe)
1232 return I40IW_ERR_RING_FULL;
1233 header = LS_64(I40IW_CQP_OP_NOP, I40IW_CQPSQ_OPCODE) |
1234 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1235 i40iw_insert_wqe_hdr(wqe, header);
1236 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "NOP WQE",
1237 wqe, I40IW_CQP_WQE_SIZE * 8);
1238
1239 if (post_sq)
1240 i40iw_sc_cqp_post_sq(cqp);
1241 return 0;
1242}
1243
1244/**
1245 * i40iw_sc_ceq_init - initialize ceq
1246 * @ceq: ceq sc structure
1247 * @info: ceq initialization info
1248 */
1249static enum i40iw_status_code i40iw_sc_ceq_init(struct i40iw_sc_ceq *ceq,
1250 struct i40iw_ceq_init_info *info)
1251{
1252 u32 pble_obj_cnt;
1253
1254 if ((info->elem_cnt < I40IW_MIN_CEQ_ENTRIES) ||
1255 (info->elem_cnt > I40IW_MAX_CEQ_ENTRIES))
1256 return I40IW_ERR_INVALID_SIZE;
1257
1258 if (info->ceq_id >= I40IW_MAX_CEQID)
1259 return I40IW_ERR_INVALID_CEQ_ID;
1260
1261 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
1262
1263 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
1264 return I40IW_ERR_INVALID_PBLE_INDEX;
1265
1266 ceq->size = sizeof(*ceq);
1267 ceq->ceqe_base = (struct i40iw_ceqe *)info->ceqe_base;
1268 ceq->ceq_id = info->ceq_id;
1269 ceq->dev = info->dev;
1270 ceq->elem_cnt = info->elem_cnt;
1271 ceq->ceq_elem_pa = info->ceqe_pa;
1272 ceq->virtual_map = info->virtual_map;
1273
1274 ceq->pbl_chunk_size = (ceq->virtual_map ? info->pbl_chunk_size : 0);
1275 ceq->first_pm_pbl_idx = (ceq->virtual_map ? info->first_pm_pbl_idx : 0);
1276 ceq->pbl_list = (ceq->virtual_map ? info->pbl_list : NULL);
1277
1278 ceq->tph_en = info->tph_en;
1279 ceq->tph_val = info->tph_val;
1280 ceq->polarity = 1;
1281 I40IW_RING_INIT(ceq->ceq_ring, ceq->elem_cnt);
1282 ceq->dev->ceq[info->ceq_id] = ceq;
1283
1284 return 0;
1285}
1286
1287/**
1288 * i40iw_sc_ceq_create - create ceq wqe
1289 * @ceq: ceq sc structure
1290 * @scratch: u64 saved to be used during cqp completion
1291 * @post_sq: flag for cqp db to ring
1292 */
1293static enum i40iw_status_code i40iw_sc_ceq_create(struct i40iw_sc_ceq *ceq,
1294 u64 scratch,
1295 bool post_sq)
1296{
1297 struct i40iw_sc_cqp *cqp;
1298 u64 *wqe;
1299 u64 header;
1300
1301 cqp = ceq->dev->cqp;
1302 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1303 if (!wqe)
1304 return I40IW_ERR_RING_FULL;
1305 set_64bit_val(wqe, 16, ceq->elem_cnt);
1306 set_64bit_val(wqe, 32, (ceq->virtual_map ? 0 : ceq->ceq_elem_pa));
1307 set_64bit_val(wqe, 48, (ceq->virtual_map ? ceq->first_pm_pbl_idx : 0));
1308 set_64bit_val(wqe, 56, LS_64(ceq->tph_val, I40IW_CQPSQ_TPHVAL));
1309
1310 header = ceq->ceq_id |
1311 LS_64(I40IW_CQP_OP_CREATE_CEQ, I40IW_CQPSQ_OPCODE) |
1312 LS_64(ceq->pbl_chunk_size, I40IW_CQPSQ_CEQ_LPBLSIZE) |
1313 LS_64(ceq->virtual_map, I40IW_CQPSQ_CEQ_VMAP) |
1314 LS_64(ceq->tph_en, I40IW_CQPSQ_TPHEN) |
1315 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1316
1317 i40iw_insert_wqe_hdr(wqe, header);
1318
1319 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CEQ_CREATE WQE",
1320 wqe, I40IW_CQP_WQE_SIZE * 8);
1321
1322 if (post_sq)
1323 i40iw_sc_cqp_post_sq(cqp);
1324 return 0;
1325}
1326
1327/**
1328 * i40iw_sc_cceq_create_done - poll for control ceq wqe to complete
1329 * @ceq: ceq sc structure
1330 */
1331static enum i40iw_status_code i40iw_sc_cceq_create_done(struct i40iw_sc_ceq *ceq)
1332{
1333 struct i40iw_sc_cqp *cqp;
1334
1335 cqp = ceq->dev->cqp;
1336 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_CEQ, NULL);
1337}
1338
1339/**
1340 * i40iw_sc_cceq_destroy_done - poll for destroy cceq to complete
1341 * @ceq: ceq sc structure
1342 */
1343static enum i40iw_status_code i40iw_sc_cceq_destroy_done(struct i40iw_sc_ceq *ceq)
1344{
1345 struct i40iw_sc_cqp *cqp;
1346
1347 cqp = ceq->dev->cqp;
1348 cqp->process_cqp_sds = i40iw_update_sds_noccq;
1349 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_DESTROY_CEQ, NULL);
1350}
1351
1352/**
1353 * i40iw_sc_cceq_create - create cceq
1354 * @ceq: ceq sc structure
1355 * @scratch: u64 saved to be used during cqp completion
1356 */
1357static enum i40iw_status_code i40iw_sc_cceq_create(struct i40iw_sc_ceq *ceq, u64 scratch)
1358{
1359 enum i40iw_status_code ret_code;
1360
1361 ret_code = i40iw_sc_ceq_create(ceq, scratch, true);
1362 if (!ret_code)
1363 ret_code = i40iw_sc_cceq_create_done(ceq);
1364 return ret_code;
1365}
1366
1367/**
1368 * i40iw_sc_ceq_destroy - destroy ceq
1369 * @ceq: ceq sc structure
1370 * @scratch: u64 saved to be used during cqp completion
1371 * @post_sq: flag for cqp db to ring
1372 */
1373static enum i40iw_status_code i40iw_sc_ceq_destroy(struct i40iw_sc_ceq *ceq,
1374 u64 scratch,
1375 bool post_sq)
1376{
1377 struct i40iw_sc_cqp *cqp;
1378 u64 *wqe;
1379 u64 header;
1380
1381 cqp = ceq->dev->cqp;
1382 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1383 if (!wqe)
1384 return I40IW_ERR_RING_FULL;
1385 set_64bit_val(wqe, 16, ceq->elem_cnt);
1386 set_64bit_val(wqe, 48, ceq->first_pm_pbl_idx);
1387 header = ceq->ceq_id |
1388 LS_64(I40IW_CQP_OP_DESTROY_CEQ, I40IW_CQPSQ_OPCODE) |
1389 LS_64(ceq->pbl_chunk_size, I40IW_CQPSQ_CEQ_LPBLSIZE) |
1390 LS_64(ceq->virtual_map, I40IW_CQPSQ_CEQ_VMAP) |
1391 LS_64(ceq->tph_en, I40IW_CQPSQ_TPHEN) |
1392 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1393 i40iw_insert_wqe_hdr(wqe, header);
1394 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CEQ_DESTROY WQE",
1395 wqe, I40IW_CQP_WQE_SIZE * 8);
1396
1397 if (post_sq)
1398 i40iw_sc_cqp_post_sq(cqp);
1399 return 0;
1400}
1401
1402/**
1403 * i40iw_sc_process_ceq - process ceq
1404 * @dev: sc device struct
1405 * @ceq: ceq sc structure
1406 */
1407static void *i40iw_sc_process_ceq(struct i40iw_sc_dev *dev, struct i40iw_sc_ceq *ceq)
1408{
1409 u64 temp;
1410 u64 *ceqe;
1411 struct i40iw_sc_cq *cq = NULL;
1412 u8 polarity;
1413
1414 ceqe = (u64 *)I40IW_GET_CURRENT_CEQ_ELEMENT(ceq);
1415 get_64bit_val(ceqe, 0, &temp);
1416 polarity = (u8)RS_64(temp, I40IW_CEQE_VALID);
1417 if (polarity != ceq->polarity)
1418 return cq;
1419
1420 cq = (struct i40iw_sc_cq *)(unsigned long)LS_64_1(temp, 1);
1421
1422 I40IW_RING_MOVE_TAIL(ceq->ceq_ring);
1423 if (I40IW_RING_GETCURRENT_TAIL(ceq->ceq_ring) == 0)
1424 ceq->polarity ^= 1;
1425
1426 if (dev->is_pf)
1427 i40iw_wr32(dev->hw, I40E_PFPE_CQACK, cq->cq_uk.cq_id);
1428 else
1429 i40iw_wr32(dev->hw, I40E_VFPE_CQACK1, cq->cq_uk.cq_id);
1430
1431 return cq;
1432}
1433
1434/**
1435 * i40iw_sc_aeq_init - initialize aeq
1436 * @aeq: aeq structure ptr
1437 * @info: aeq initialization info
1438 */
1439static enum i40iw_status_code i40iw_sc_aeq_init(struct i40iw_sc_aeq *aeq,
1440 struct i40iw_aeq_init_info *info)
1441{
1442 u32 pble_obj_cnt;
1443
1444 if ((info->elem_cnt < I40IW_MIN_AEQ_ENTRIES) ||
1445 (info->elem_cnt > I40IW_MAX_AEQ_ENTRIES))
1446 return I40IW_ERR_INVALID_SIZE;
1447 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
1448
1449 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
1450 return I40IW_ERR_INVALID_PBLE_INDEX;
1451
1452 aeq->size = sizeof(*aeq);
1453 aeq->polarity = 1;
1454 aeq->aeqe_base = (struct i40iw_sc_aeqe *)info->aeqe_base;
1455 aeq->dev = info->dev;
1456 aeq->elem_cnt = info->elem_cnt;
1457
1458 aeq->aeq_elem_pa = info->aeq_elem_pa;
1459 I40IW_RING_INIT(aeq->aeq_ring, aeq->elem_cnt);
1460 info->dev->aeq = aeq;
1461
1462 aeq->virtual_map = info->virtual_map;
1463 aeq->pbl_list = (aeq->virtual_map ? info->pbl_list : NULL);
1464 aeq->pbl_chunk_size = (aeq->virtual_map ? info->pbl_chunk_size : 0);
1465 aeq->first_pm_pbl_idx = (aeq->virtual_map ? info->first_pm_pbl_idx : 0);
1466 info->dev->aeq = aeq;
1467 return 0;
1468}
1469
1470/**
1471 * i40iw_sc_aeq_create - create aeq
1472 * @aeq: aeq structure ptr
1473 * @scratch: u64 saved to be used during cqp completion
1474 * @post_sq: flag for cqp db to ring
1475 */
1476static enum i40iw_status_code i40iw_sc_aeq_create(struct i40iw_sc_aeq *aeq,
1477 u64 scratch,
1478 bool post_sq)
1479{
1480 u64 *wqe;
1481 struct i40iw_sc_cqp *cqp;
1482 u64 header;
1483
1484 cqp = aeq->dev->cqp;
1485 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1486 if (!wqe)
1487 return I40IW_ERR_RING_FULL;
1488 set_64bit_val(wqe, 16, aeq->elem_cnt);
1489 set_64bit_val(wqe, 32,
1490 (aeq->virtual_map ? 0 : aeq->aeq_elem_pa));
1491 set_64bit_val(wqe, 48,
1492 (aeq->virtual_map ? aeq->first_pm_pbl_idx : 0));
1493
1494 header = LS_64(I40IW_CQP_OP_CREATE_AEQ, I40IW_CQPSQ_OPCODE) |
1495 LS_64(aeq->pbl_chunk_size, I40IW_CQPSQ_AEQ_LPBLSIZE) |
1496 LS_64(aeq->virtual_map, I40IW_CQPSQ_AEQ_VMAP) |
1497 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1498
1499 i40iw_insert_wqe_hdr(wqe, header);
1500 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "AEQ_CREATE WQE",
1501 wqe, I40IW_CQP_WQE_SIZE * 8);
1502 if (post_sq)
1503 i40iw_sc_cqp_post_sq(cqp);
1504 return 0;
1505}
1506
1507/**
1508 * i40iw_sc_aeq_destroy - destroy aeq during close
1509 * @aeq: aeq structure ptr
1510 * @scratch: u64 saved to be used during cqp completion
1511 * @post_sq: flag for cqp db to ring
1512 */
1513static enum i40iw_status_code i40iw_sc_aeq_destroy(struct i40iw_sc_aeq *aeq,
1514 u64 scratch,
1515 bool post_sq)
1516{
1517 u64 *wqe;
1518 struct i40iw_sc_cqp *cqp;
1519 u64 header;
1520
1521 cqp = aeq->dev->cqp;
1522 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1523 if (!wqe)
1524 return I40IW_ERR_RING_FULL;
1525 set_64bit_val(wqe, 16, aeq->elem_cnt);
1526 set_64bit_val(wqe, 48, aeq->first_pm_pbl_idx);
1527 header = LS_64(I40IW_CQP_OP_DESTROY_AEQ, I40IW_CQPSQ_OPCODE) |
1528 LS_64(aeq->pbl_chunk_size, I40IW_CQPSQ_AEQ_LPBLSIZE) |
1529 LS_64(aeq->virtual_map, I40IW_CQPSQ_AEQ_VMAP) |
1530 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1531 i40iw_insert_wqe_hdr(wqe, header);
1532
1533 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "AEQ_DESTROY WQE",
1534 wqe, I40IW_CQP_WQE_SIZE * 8);
1535 if (post_sq)
1536 i40iw_sc_cqp_post_sq(cqp);
1537 return 0;
1538}
1539
1540/**
1541 * i40iw_sc_get_next_aeqe - get next aeq entry
1542 * @aeq: aeq structure ptr
1543 * @info: aeqe info to be returned
1544 */
1545static enum i40iw_status_code i40iw_sc_get_next_aeqe(struct i40iw_sc_aeq *aeq,
1546 struct i40iw_aeqe_info *info)
1547{
1548 u64 temp, compl_ctx;
1549 u64 *aeqe;
1550 u16 wqe_idx;
1551 u8 ae_src;
1552 u8 polarity;
1553
1554 aeqe = (u64 *)I40IW_GET_CURRENT_AEQ_ELEMENT(aeq);
1555 get_64bit_val(aeqe, 0, &compl_ctx);
1556 get_64bit_val(aeqe, 8, &temp);
1557 polarity = (u8)RS_64(temp, I40IW_AEQE_VALID);
1558
1559 if (aeq->polarity != polarity)
1560 return I40IW_ERR_QUEUE_EMPTY;
1561
1562 i40iw_debug_buf(aeq->dev, I40IW_DEBUG_WQE, "AEQ_ENTRY", aeqe, 16);
1563
1564 ae_src = (u8)RS_64(temp, I40IW_AEQE_AESRC);
1565 wqe_idx = (u16)RS_64(temp, I40IW_AEQE_WQDESCIDX);
1566 info->qp_cq_id = (u32)RS_64(temp, I40IW_AEQE_QPCQID);
1567 info->ae_id = (u16)RS_64(temp, I40IW_AEQE_AECODE);
1568 info->tcp_state = (u8)RS_64(temp, I40IW_AEQE_TCPSTATE);
1569 info->iwarp_state = (u8)RS_64(temp, I40IW_AEQE_IWSTATE);
1570 info->q2_data_written = (u8)RS_64(temp, I40IW_AEQE_Q2DATA);
1571 info->aeqe_overflow = (bool)RS_64(temp, I40IW_AEQE_OVERFLOW);
1572 switch (ae_src) {
1573 case I40IW_AE_SOURCE_RQ:
1574 case I40IW_AE_SOURCE_RQ_0011:
1575 info->qp = true;
1576 info->wqe_idx = wqe_idx;
1577 info->compl_ctx = compl_ctx;
1578 break;
1579 case I40IW_AE_SOURCE_CQ:
1580 case I40IW_AE_SOURCE_CQ_0110:
1581 case I40IW_AE_SOURCE_CQ_1010:
1582 case I40IW_AE_SOURCE_CQ_1110:
1583 info->cq = true;
1584 info->compl_ctx = LS_64_1(compl_ctx, 1);
1585 break;
1586 case I40IW_AE_SOURCE_SQ:
1587 case I40IW_AE_SOURCE_SQ_0111:
1588 info->qp = true;
1589 info->sq = true;
1590 info->wqe_idx = wqe_idx;
1591 info->compl_ctx = compl_ctx;
1592 break;
1593 case I40IW_AE_SOURCE_IN_RR_WR:
1594 case I40IW_AE_SOURCE_IN_RR_WR_1011:
1595 info->qp = true;
1596 info->compl_ctx = compl_ctx;
1597 info->in_rdrsp_wr = true;
1598 break;
1599 case I40IW_AE_SOURCE_OUT_RR:
1600 case I40IW_AE_SOURCE_OUT_RR_1111:
1601 info->qp = true;
1602 info->compl_ctx = compl_ctx;
1603 info->out_rdrsp = true;
1604 break;
1605 default:
1606 break;
1607 }
1608 I40IW_RING_MOVE_TAIL(aeq->aeq_ring);
1609 if (I40IW_RING_GETCURRENT_TAIL(aeq->aeq_ring) == 0)
1610 aeq->polarity ^= 1;
1611 return 0;
1612}
1613
1614/**
1615 * i40iw_sc_repost_aeq_entries - repost completed aeq entries
1616 * @dev: sc device struct
1617 * @count: allocate count
1618 */
1619static enum i40iw_status_code i40iw_sc_repost_aeq_entries(struct i40iw_sc_dev *dev,
1620 u32 count)
1621{
1622 if (count > I40IW_MAX_AEQ_ALLOCATE_COUNT)
1623 return I40IW_ERR_INVALID_SIZE;
1624
1625 if (dev->is_pf)
1626 i40iw_wr32(dev->hw, I40E_PFPE_AEQALLOC, count);
1627 else
1628 i40iw_wr32(dev->hw, I40E_VFPE_AEQALLOC1, count);
1629
1630 return 0;
1631}
1632
1633/**
1634 * i40iw_sc_aeq_create_done - create aeq
1635 * @aeq: aeq structure ptr
1636 */
1637static enum i40iw_status_code i40iw_sc_aeq_create_done(struct i40iw_sc_aeq *aeq)
1638{
1639 struct i40iw_sc_cqp *cqp;
1640
1641 cqp = aeq->dev->cqp;
1642 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_AEQ, NULL);
1643}
1644
1645/**
1646 * i40iw_sc_aeq_destroy_done - destroy of aeq during close
1647 * @aeq: aeq structure ptr
1648 */
1649static enum i40iw_status_code i40iw_sc_aeq_destroy_done(struct i40iw_sc_aeq *aeq)
1650{
1651 struct i40iw_sc_cqp *cqp;
1652
1653 cqp = aeq->dev->cqp;
1654 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_DESTROY_AEQ, NULL);
1655}
1656
1657/**
1658 * i40iw_sc_ccq_init - initialize control cq
1659 * @cq: sc's cq ctruct
1660 * @info: info for control cq initialization
1661 */
1662static enum i40iw_status_code i40iw_sc_ccq_init(struct i40iw_sc_cq *cq,
1663 struct i40iw_ccq_init_info *info)
1664{
1665 u32 pble_obj_cnt;
1666
1667 if (info->num_elem < I40IW_MIN_CQ_SIZE || info->num_elem > I40IW_MAX_CQ_SIZE)
1668 return I40IW_ERR_INVALID_SIZE;
1669
1670 if (info->ceq_id > I40IW_MAX_CEQID)
1671 return I40IW_ERR_INVALID_CEQ_ID;
1672
1673 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
1674
1675 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
1676 return I40IW_ERR_INVALID_PBLE_INDEX;
1677
1678 cq->cq_pa = info->cq_pa;
1679 cq->cq_uk.cq_base = info->cq_base;
1680 cq->shadow_area_pa = info->shadow_area_pa;
1681 cq->cq_uk.shadow_area = info->shadow_area;
1682 cq->shadow_read_threshold = info->shadow_read_threshold;
1683 cq->dev = info->dev;
1684 cq->ceq_id = info->ceq_id;
1685 cq->cq_uk.cq_size = info->num_elem;
1686 cq->cq_type = I40IW_CQ_TYPE_CQP;
1687 cq->ceqe_mask = info->ceqe_mask;
1688 I40IW_RING_INIT(cq->cq_uk.cq_ring, info->num_elem);
1689
1690 cq->cq_uk.cq_id = 0; /* control cq is id 0 always */
1691 cq->ceq_id_valid = info->ceq_id_valid;
1692 cq->tph_en = info->tph_en;
1693 cq->tph_val = info->tph_val;
1694 cq->cq_uk.avoid_mem_cflct = info->avoid_mem_cflct;
1695
1696 cq->pbl_list = info->pbl_list;
1697 cq->virtual_map = info->virtual_map;
1698 cq->pbl_chunk_size = info->pbl_chunk_size;
1699 cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
1700 cq->cq_uk.polarity = true;
1701
1702 /* following are only for iw cqs so initialize them to zero */
1703 cq->cq_uk.cqe_alloc_reg = NULL;
1704 info->dev->ccq = cq;
1705 return 0;
1706}
1707
1708/**
1709 * i40iw_sc_ccq_create_done - poll cqp for ccq create
1710 * @ccq: ccq sc struct
1711 */
1712static enum i40iw_status_code i40iw_sc_ccq_create_done(struct i40iw_sc_cq *ccq)
1713{
1714 struct i40iw_sc_cqp *cqp;
1715
1716 cqp = ccq->dev->cqp;
1717 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_CQ, NULL);
1718}
1719
1720/**
1721 * i40iw_sc_ccq_create - create control cq
1722 * @ccq: ccq sc struct
1723 * @scratch: u64 saved to be used during cqp completion
1724 * @check_overflow: overlow flag for ccq
1725 * @post_sq: flag for cqp db to ring
1726 */
1727static enum i40iw_status_code i40iw_sc_ccq_create(struct i40iw_sc_cq *ccq,
1728 u64 scratch,
1729 bool check_overflow,
1730 bool post_sq)
1731{
1732 u64 *wqe;
1733 struct i40iw_sc_cqp *cqp;
1734 u64 header;
1735 enum i40iw_status_code ret_code;
1736
1737 cqp = ccq->dev->cqp;
1738 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1739 if (!wqe)
1740 return I40IW_ERR_RING_FULL;
1741 set_64bit_val(wqe, 0, ccq->cq_uk.cq_size);
1742 set_64bit_val(wqe, 8, RS_64_1(ccq, 1));
1743 set_64bit_val(wqe, 16,
1744 LS_64(ccq->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
1745 set_64bit_val(wqe, 32, (ccq->virtual_map ? 0 : ccq->cq_pa));
1746 set_64bit_val(wqe, 40, ccq->shadow_area_pa);
1747 set_64bit_val(wqe, 48,
1748 (ccq->virtual_map ? ccq->first_pm_pbl_idx : 0));
1749 set_64bit_val(wqe, 56,
1750 LS_64(ccq->tph_val, I40IW_CQPSQ_TPHVAL));
1751
1752 header = ccq->cq_uk.cq_id |
1753 LS_64((ccq->ceq_id_valid ? ccq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
1754 LS_64(I40IW_CQP_OP_CREATE_CQ, I40IW_CQPSQ_OPCODE) |
1755 LS_64(ccq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
1756 LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
1757 LS_64(ccq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
1758 LS_64(ccq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
1759 LS_64(ccq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
1760 LS_64(ccq->tph_en, I40IW_CQPSQ_TPHEN) |
1761 LS_64(ccq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
1762 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1763
1764 i40iw_insert_wqe_hdr(wqe, header);
1765
1766 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CCQ_CREATE WQE",
1767 wqe, I40IW_CQP_WQE_SIZE * 8);
1768
1769 if (post_sq) {
1770 i40iw_sc_cqp_post_sq(cqp);
1771 ret_code = i40iw_sc_ccq_create_done(ccq);
1772 if (ret_code)
1773 return ret_code;
1774 }
1775 cqp->process_cqp_sds = i40iw_cqp_sds_cmd;
1776
1777 return 0;
1778}
1779
1780/**
1781 * i40iw_sc_ccq_destroy - destroy ccq during close
1782 * @ccq: ccq sc struct
1783 * @scratch: u64 saved to be used during cqp completion
1784 * @post_sq: flag for cqp db to ring
1785 */
1786static enum i40iw_status_code i40iw_sc_ccq_destroy(struct i40iw_sc_cq *ccq,
1787 u64 scratch,
1788 bool post_sq)
1789{
1790 struct i40iw_sc_cqp *cqp;
1791 u64 *wqe;
1792 u64 header;
1793 enum i40iw_status_code ret_code = 0;
1794 u32 tail, val, error;
1795
1796 cqp = ccq->dev->cqp;
1797 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1798 if (!wqe)
1799 return I40IW_ERR_RING_FULL;
1800 set_64bit_val(wqe, 0, ccq->cq_uk.cq_size);
1801 set_64bit_val(wqe, 8, RS_64_1(ccq, 1));
1802 set_64bit_val(wqe, 40, ccq->shadow_area_pa);
1803
1804 header = ccq->cq_uk.cq_id |
1805 LS_64((ccq->ceq_id_valid ? ccq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
1806 LS_64(I40IW_CQP_OP_DESTROY_CQ, I40IW_CQPSQ_OPCODE) |
1807 LS_64(ccq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
1808 LS_64(ccq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
1809 LS_64(ccq->tph_en, I40IW_CQPSQ_TPHEN) |
1810 LS_64(ccq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
1811 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1812
1813 i40iw_insert_wqe_hdr(wqe, header);
1814
1815 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CCQ_DESTROY WQE",
1816 wqe, I40IW_CQP_WQE_SIZE * 8);
1817
1818 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
1819 if (error)
1820 return I40IW_ERR_CQP_COMPL_ERROR;
1821
1822 if (post_sq) {
1823 i40iw_sc_cqp_post_sq(cqp);
1824 ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000);
1825 }
1826
1827 return ret_code;
1828}
1829
1830/**
1831 * i40iw_sc_cq_init - initialize completion q
1832 * @cq: cq struct
1833 * @info: cq initialization info
1834 */
1835static enum i40iw_status_code i40iw_sc_cq_init(struct i40iw_sc_cq *cq,
1836 struct i40iw_cq_init_info *info)
1837{
1838 u32 __iomem *cqe_alloc_reg = NULL;
1839 enum i40iw_status_code ret_code;
1840 u32 pble_obj_cnt;
1841 u32 arm_offset;
1842
1843 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
1844
1845 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
1846 return I40IW_ERR_INVALID_PBLE_INDEX;
1847
1848 cq->cq_pa = info->cq_base_pa;
1849 cq->dev = info->dev;
1850 cq->ceq_id = info->ceq_id;
1851 arm_offset = (info->dev->is_pf) ? I40E_PFPE_CQARM : I40E_VFPE_CQARM1;
1852 if (i40iw_get_hw_addr(cq->dev))
1853 cqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(cq->dev) +
1854 arm_offset);
1855 info->cq_uk_init_info.cqe_alloc_reg = cqe_alloc_reg;
1856 ret_code = i40iw_cq_uk_init(&cq->cq_uk, &info->cq_uk_init_info);
1857 if (ret_code)
1858 return ret_code;
1859 cq->virtual_map = info->virtual_map;
1860 cq->pbl_chunk_size = info->pbl_chunk_size;
1861 cq->ceqe_mask = info->ceqe_mask;
1862 cq->cq_type = (info->type) ? info->type : I40IW_CQ_TYPE_IWARP;
1863
1864 cq->shadow_area_pa = info->shadow_area_pa;
1865 cq->shadow_read_threshold = info->shadow_read_threshold;
1866
1867 cq->ceq_id_valid = info->ceq_id_valid;
1868 cq->tph_en = info->tph_en;
1869 cq->tph_val = info->tph_val;
1870
1871 cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
1872
1873 return 0;
1874}
1875
1876/**
1877 * i40iw_sc_cq_create - create completion q
1878 * @cq: cq struct
1879 * @scratch: u64 saved to be used during cqp completion
1880 * @check_overflow: flag for overflow check
1881 * @post_sq: flag for cqp db to ring
1882 */
1883static enum i40iw_status_code i40iw_sc_cq_create(struct i40iw_sc_cq *cq,
1884 u64 scratch,
1885 bool check_overflow,
1886 bool post_sq)
1887{
1888 u64 *wqe;
1889 struct i40iw_sc_cqp *cqp;
1890 u64 header;
1891
1892 if (cq->cq_uk.cq_id > I40IW_MAX_CQID)
1893 return I40IW_ERR_INVALID_CQ_ID;
1894
1895 if (cq->ceq_id > I40IW_MAX_CEQID)
1896 return I40IW_ERR_INVALID_CEQ_ID;
1897
1898 cqp = cq->dev->cqp;
1899 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1900 if (!wqe)
1901 return I40IW_ERR_RING_FULL;
1902
1903 set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
1904 set_64bit_val(wqe, 8, RS_64_1(cq, 1));
1905 set_64bit_val(wqe,
1906 16,
1907 LS_64(cq->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
1908
1909 set_64bit_val(wqe, 32, (cq->virtual_map ? 0 : cq->cq_pa));
1910
1911 set_64bit_val(wqe, 40, cq->shadow_area_pa);
1912 set_64bit_val(wqe, 48, (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
1913 set_64bit_val(wqe, 56, LS_64(cq->tph_val, I40IW_CQPSQ_TPHVAL));
1914
1915 header = cq->cq_uk.cq_id |
1916 LS_64((cq->ceq_id_valid ? cq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
1917 LS_64(I40IW_CQP_OP_CREATE_CQ, I40IW_CQPSQ_OPCODE) |
1918 LS_64(cq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
1919 LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
1920 LS_64(cq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
1921 LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
1922 LS_64(cq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
1923 LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
1924 LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
1925 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1926
1927 i40iw_insert_wqe_hdr(wqe, header);
1928
1929 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_CREATE WQE",
1930 wqe, I40IW_CQP_WQE_SIZE * 8);
1931
1932 if (post_sq)
1933 i40iw_sc_cqp_post_sq(cqp);
1934 return 0;
1935}
1936
1937/**
1938 * i40iw_sc_cq_destroy - destroy completion q
1939 * @cq: cq struct
1940 * @scratch: u64 saved to be used during cqp completion
1941 * @post_sq: flag for cqp db to ring
1942 */
1943static enum i40iw_status_code i40iw_sc_cq_destroy(struct i40iw_sc_cq *cq,
1944 u64 scratch,
1945 bool post_sq)
1946{
1947 struct i40iw_sc_cqp *cqp;
1948 u64 *wqe;
1949 u64 header;
1950
1951 cqp = cq->dev->cqp;
1952 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1953 if (!wqe)
1954 return I40IW_ERR_RING_FULL;
1955 set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
1956 set_64bit_val(wqe, 8, RS_64_1(cq, 1));
1957 set_64bit_val(wqe, 40, cq->shadow_area_pa);
1958 set_64bit_val(wqe, 48, (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
1959
1960 header = cq->cq_uk.cq_id |
1961 LS_64((cq->ceq_id_valid ? cq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
1962 LS_64(I40IW_CQP_OP_DESTROY_CQ, I40IW_CQPSQ_OPCODE) |
1963 LS_64(cq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
1964 LS_64(cq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
1965 LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
1966 LS_64(cq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
1967 LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
1968 LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
1969 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1970
1971 i40iw_insert_wqe_hdr(wqe, header);
1972
1973 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_DESTROY WQE",
1974 wqe, I40IW_CQP_WQE_SIZE * 8);
1975
1976 if (post_sq)
1977 i40iw_sc_cqp_post_sq(cqp);
1978 return 0;
1979}
1980
1981/**
1982 * i40iw_sc_cq_modify - modify a Completion Queue
1983 * @cq: cq struct
1984 * @info: modification info struct
1985 * @scratch:
1986 * @post_sq: flag to post to sq
1987 */
1988static enum i40iw_status_code i40iw_sc_cq_modify(struct i40iw_sc_cq *cq,
1989 struct i40iw_modify_cq_info *info,
1990 u64 scratch,
1991 bool post_sq)
1992{
1993 struct i40iw_sc_cqp *cqp;
1994 u64 *wqe;
1995 u64 header;
1996 u32 cq_size, ceq_id, first_pm_pbl_idx;
1997 u8 pbl_chunk_size;
1998 bool virtual_map, ceq_id_valid, check_overflow;
1999 u32 pble_obj_cnt;
2000
2001 if (info->ceq_valid && (info->ceq_id > I40IW_MAX_CEQID))
2002 return I40IW_ERR_INVALID_CEQ_ID;
2003
2004 pble_obj_cnt = cq->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
2005
2006 if (info->cq_resize && info->virtual_map &&
2007 (info->first_pm_pbl_idx >= pble_obj_cnt))
2008 return I40IW_ERR_INVALID_PBLE_INDEX;
2009
2010 cqp = cq->dev->cqp;
2011 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2012 if (!wqe)
2013 return I40IW_ERR_RING_FULL;
2014
2015 cq->pbl_list = info->pbl_list;
2016 cq->cq_pa = info->cq_pa;
2017 cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
2018
2019 cq_size = info->cq_resize ? info->cq_size : cq->cq_uk.cq_size;
2020 if (info->ceq_change) {
2021 ceq_id_valid = true;
2022 ceq_id = info->ceq_id;
2023 } else {
2024 ceq_id_valid = cq->ceq_id_valid;
2025 ceq_id = ceq_id_valid ? cq->ceq_id : 0;
2026 }
2027 virtual_map = info->cq_resize ? info->virtual_map : cq->virtual_map;
2028 first_pm_pbl_idx = (info->cq_resize ?
2029 (info->virtual_map ? info->first_pm_pbl_idx : 0) :
2030 (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
2031 pbl_chunk_size = (info->cq_resize ?
2032 (info->virtual_map ? info->pbl_chunk_size : 0) :
2033 (cq->virtual_map ? cq->pbl_chunk_size : 0));
2034 check_overflow = info->check_overflow_change ? info->check_overflow :
2035 cq->check_overflow;
2036 cq->cq_uk.cq_size = cq_size;
2037 cq->ceq_id_valid = ceq_id_valid;
2038 cq->ceq_id = ceq_id;
2039 cq->virtual_map = virtual_map;
2040 cq->first_pm_pbl_idx = first_pm_pbl_idx;
2041 cq->pbl_chunk_size = pbl_chunk_size;
2042 cq->check_overflow = check_overflow;
2043
2044 set_64bit_val(wqe, 0, cq_size);
2045 set_64bit_val(wqe, 8, RS_64_1(cq, 1));
2046 set_64bit_val(wqe, 16,
2047 LS_64(info->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
2048 set_64bit_val(wqe, 32, (cq->virtual_map ? 0 : cq->cq_pa));
2049 set_64bit_val(wqe, 40, cq->shadow_area_pa);
2050 set_64bit_val(wqe, 48, (cq->virtual_map ? first_pm_pbl_idx : 0));
2051 set_64bit_val(wqe, 56, LS_64(cq->tph_val, I40IW_CQPSQ_TPHVAL));
2052
2053 header = cq->cq_uk.cq_id |
2054 LS_64(ceq_id, I40IW_CQPSQ_CQ_CEQID) |
2055 LS_64(I40IW_CQP_OP_MODIFY_CQ, I40IW_CQPSQ_OPCODE) |
2056 LS_64(info->cq_resize, I40IW_CQPSQ_CQ_CQRESIZE) |
2057 LS_64(pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
2058 LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
2059 LS_64(virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
2060 LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
2061 LS_64(ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
2062 LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
2063 LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
2064 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2065
2066 i40iw_insert_wqe_hdr(wqe, header);
2067
2068 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_MODIFY WQE",
2069 wqe, I40IW_CQP_WQE_SIZE * 8);
2070
2071 if (post_sq)
2072 i40iw_sc_cqp_post_sq(cqp);
2073 return 0;
2074}
2075
2076/**
2077 * i40iw_sc_qp_init - initialize qp
2078 * @qp: sc qp
2079 * @info: initialization qp info
2080 */
2081static enum i40iw_status_code i40iw_sc_qp_init(struct i40iw_sc_qp *qp,
2082 struct i40iw_qp_init_info *info)
2083{
2084 u32 __iomem *wqe_alloc_reg = NULL;
2085 enum i40iw_status_code ret_code;
2086 u32 pble_obj_cnt;
2087 u8 wqe_size;
2088 u32 offset;
2089
2090 qp->dev = info->pd->dev;
2091 qp->sq_pa = info->sq_pa;
2092 qp->rq_pa = info->rq_pa;
2093 qp->hw_host_ctx_pa = info->host_ctx_pa;
2094 qp->q2_pa = info->q2_pa;
2095 qp->shadow_area_pa = info->shadow_area_pa;
2096
2097 qp->q2_buf = info->q2;
2098 qp->pd = info->pd;
2099 qp->hw_host_ctx = info->host_ctx;
2100 offset = (qp->pd->dev->is_pf) ? I40E_PFPE_WQEALLOC : I40E_VFPE_WQEALLOC1;
2101 if (i40iw_get_hw_addr(qp->pd->dev))
2102 wqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(qp->pd->dev) +
2103 offset);
2104
2105 info->qp_uk_init_info.wqe_alloc_reg = wqe_alloc_reg;
2106 ret_code = i40iw_qp_uk_init(&qp->qp_uk, &info->qp_uk_init_info);
2107 if (ret_code)
2108 return ret_code;
2109 qp->virtual_map = info->virtual_map;
2110
2111 pble_obj_cnt = info->pd->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
2112
2113 if ((info->virtual_map && (info->sq_pa >= pble_obj_cnt)) ||
2114 (info->virtual_map && (info->rq_pa >= pble_obj_cnt)))
2115 return I40IW_ERR_INVALID_PBLE_INDEX;
2116
2117 qp->llp_stream_handle = (void *)(-1);
2118 qp->qp_type = (info->type) ? info->type : I40IW_QP_TYPE_IWARP;
2119
2120 qp->hw_sq_size = i40iw_get_encoded_wqe_size(qp->qp_uk.sq_ring.size,
2121 false);
2122 i40iw_debug(qp->dev, I40IW_DEBUG_WQE, "%s: hw_sq_size[%04d] sq_ring.size[%04d]\n",
2123 __func__, qp->hw_sq_size, qp->qp_uk.sq_ring.size);
2124 ret_code = i40iw_fragcnt_to_wqesize_rq(qp->qp_uk.max_rq_frag_cnt,
2125 &wqe_size);
2126 if (ret_code)
2127 return ret_code;
2128 qp->hw_rq_size = i40iw_get_encoded_wqe_size(qp->qp_uk.rq_size *
2129 (wqe_size / I40IW_QP_WQE_MIN_SIZE), false);
2130 i40iw_debug(qp->dev, I40IW_DEBUG_WQE,
2131 "%s: hw_rq_size[%04d] qp_uk.rq_size[%04d] wqe_size[%04d]\n",
2132 __func__, qp->hw_rq_size, qp->qp_uk.rq_size, wqe_size);
2133 qp->sq_tph_val = info->sq_tph_val;
2134 qp->rq_tph_val = info->rq_tph_val;
2135 qp->sq_tph_en = info->sq_tph_en;
2136 qp->rq_tph_en = info->rq_tph_en;
2137 qp->rcv_tph_en = info->rcv_tph_en;
2138 qp->xmit_tph_en = info->xmit_tph_en;
2139 qp->qs_handle = qp->pd->dev->qs_handle;
2140 qp->exception_lan_queue = qp->pd->dev->exception_lan_queue;
2141
2142 return 0;
2143}
2144
2145/**
2146 * i40iw_sc_qp_create - create qp
2147 * @qp: sc qp
2148 * @info: qp create info
2149 * @scratch: u64 saved to be used during cqp completion
2150 * @post_sq: flag for cqp db to ring
2151 */
2152static enum i40iw_status_code i40iw_sc_qp_create(
2153 struct i40iw_sc_qp *qp,
2154 struct i40iw_create_qp_info *info,
2155 u64 scratch,
2156 bool post_sq)
2157{
2158 struct i40iw_sc_cqp *cqp;
2159 u64 *wqe;
2160 u64 header;
2161
2162 if ((qp->qp_uk.qp_id < I40IW_MIN_IW_QP_ID) ||
2163 (qp->qp_uk.qp_id > I40IW_MAX_IW_QP_ID))
2164 return I40IW_ERR_INVALID_QP_ID;
2165
2166 cqp = qp->pd->dev->cqp;
2167 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2168 if (!wqe)
2169 return I40IW_ERR_RING_FULL;
2170
2171 set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
2172
2173 set_64bit_val(wqe, 40, qp->shadow_area_pa);
2174
2175 header = qp->qp_uk.qp_id |
2176 LS_64(I40IW_CQP_OP_CREATE_QP, I40IW_CQPSQ_OPCODE) |
2177 LS_64((info->ord_valid ? 1 : 0), I40IW_CQPSQ_QP_ORDVALID) |
2178 LS_64(info->tcp_ctx_valid, I40IW_CQPSQ_QP_TOECTXVALID) |
2179 LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
2180 LS_64(qp->virtual_map, I40IW_CQPSQ_QP_VQ) |
2181 LS_64(info->cq_num_valid, I40IW_CQPSQ_QP_CQNUMVALID) |
2182 LS_64(info->static_rsrc, I40IW_CQPSQ_QP_STATRSRC) |
2183 LS_64(info->arp_cache_idx_valid, I40IW_CQPSQ_QP_ARPTABIDXVALID) |
2184 LS_64(info->next_iwarp_state, I40IW_CQPSQ_QP_NEXTIWSTATE) |
2185 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2186
2187 i40iw_insert_wqe_hdr(wqe, header);
2188 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_CREATE WQE",
2189 wqe, I40IW_CQP_WQE_SIZE * 8);
2190
2191 if (post_sq)
2192 i40iw_sc_cqp_post_sq(cqp);
2193 return 0;
2194}
2195
2196/**
2197 * i40iw_sc_qp_modify - modify qp cqp wqe
2198 * @qp: sc qp
2199 * @info: modify qp info
2200 * @scratch: u64 saved to be used during cqp completion
2201 * @post_sq: flag for cqp db to ring
2202 */
2203static enum i40iw_status_code i40iw_sc_qp_modify(
2204 struct i40iw_sc_qp *qp,
2205 struct i40iw_modify_qp_info *info,
2206 u64 scratch,
2207 bool post_sq)
2208{
2209 u64 *wqe;
2210 struct i40iw_sc_cqp *cqp;
2211 u64 header;
2212 u8 term_actions = 0;
2213 u8 term_len = 0;
2214
2215 cqp = qp->pd->dev->cqp;
2216 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2217 if (!wqe)
2218 return I40IW_ERR_RING_FULL;
2219 if (info->next_iwarp_state == I40IW_QP_STATE_TERMINATE) {
2220 if (info->dont_send_fin)
2221 term_actions += I40IWQP_TERM_SEND_TERM_ONLY;
2222 if (info->dont_send_term)
2223 term_actions += I40IWQP_TERM_SEND_FIN_ONLY;
2224 if ((term_actions == I40IWQP_TERM_SEND_TERM_AND_FIN) ||
2225 (term_actions == I40IWQP_TERM_SEND_TERM_ONLY))
2226 term_len = info->termlen;
2227 }
2228
2229 set_64bit_val(wqe,
2230 8,
2231 LS_64(info->new_mss, I40IW_CQPSQ_QP_NEWMSS) |
2232 LS_64(term_len, I40IW_CQPSQ_QP_TERMLEN));
2233
2234 set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
2235 set_64bit_val(wqe, 40, qp->shadow_area_pa);
2236
2237 header = qp->qp_uk.qp_id |
2238 LS_64(I40IW_CQP_OP_MODIFY_QP, I40IW_CQPSQ_OPCODE) |
2239 LS_64(info->ord_valid, I40IW_CQPSQ_QP_ORDVALID) |
2240 LS_64(info->tcp_ctx_valid, I40IW_CQPSQ_QP_TOECTXVALID) |
2241 LS_64(info->cached_var_valid, I40IW_CQPSQ_QP_CACHEDVARVALID) |
2242 LS_64(qp->virtual_map, I40IW_CQPSQ_QP_VQ) |
2243 LS_64(info->cq_num_valid, I40IW_CQPSQ_QP_CQNUMVALID) |
2244 LS_64(info->force_loopback, I40IW_CQPSQ_QP_FORCELOOPBACK) |
2245 LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
2246 LS_64(info->mss_change, I40IW_CQPSQ_QP_MSSCHANGE) |
2247 LS_64(info->static_rsrc, I40IW_CQPSQ_QP_STATRSRC) |
2248 LS_64(info->remove_hash_idx, I40IW_CQPSQ_QP_REMOVEHASHENTRY) |
2249 LS_64(term_actions, I40IW_CQPSQ_QP_TERMACT) |
2250 LS_64(info->reset_tcp_conn, I40IW_CQPSQ_QP_RESETCON) |
2251 LS_64(info->arp_cache_idx_valid, I40IW_CQPSQ_QP_ARPTABIDXVALID) |
2252 LS_64(info->next_iwarp_state, I40IW_CQPSQ_QP_NEXTIWSTATE) |
2253 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2254
2255 i40iw_insert_wqe_hdr(wqe, header);
2256
2257 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_MODIFY WQE",
2258 wqe, I40IW_CQP_WQE_SIZE * 8);
2259
2260 if (post_sq)
2261 i40iw_sc_cqp_post_sq(cqp);
2262 return 0;
2263}
2264
2265/**
2266 * i40iw_sc_qp_destroy - cqp destroy qp
2267 * @qp: sc qp
2268 * @scratch: u64 saved to be used during cqp completion
2269 * @remove_hash_idx: flag if to remove hash idx
2270 * @ignore_mw_bnd: memory window bind flag
2271 * @post_sq: flag for cqp db to ring
2272 */
2273static enum i40iw_status_code i40iw_sc_qp_destroy(
2274 struct i40iw_sc_qp *qp,
2275 u64 scratch,
2276 bool remove_hash_idx,
2277 bool ignore_mw_bnd,
2278 bool post_sq)
2279{
2280 u64 *wqe;
2281 struct i40iw_sc_cqp *cqp;
2282 u64 header;
2283
2284 cqp = qp->pd->dev->cqp;
2285 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2286 if (!wqe)
2287 return I40IW_ERR_RING_FULL;
2288 set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
2289 set_64bit_val(wqe, 40, qp->shadow_area_pa);
2290
2291 header = qp->qp_uk.qp_id |
2292 LS_64(I40IW_CQP_OP_DESTROY_QP, I40IW_CQPSQ_OPCODE) |
2293 LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
2294 LS_64(ignore_mw_bnd, I40IW_CQPSQ_QP_IGNOREMWBOUND) |
2295 LS_64(remove_hash_idx, I40IW_CQPSQ_QP_REMOVEHASHENTRY) |
2296 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2297
2298 i40iw_insert_wqe_hdr(wqe, header);
2299 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_DESTROY WQE",
2300 wqe, I40IW_CQP_WQE_SIZE * 8);
2301
2302 if (post_sq)
2303 i40iw_sc_cqp_post_sq(cqp);
2304 return 0;
2305}
2306
2307/**
2308 * i40iw_sc_qp_flush_wqes - flush qp's wqe
2309 * @qp: sc qp
2310 * @info: dlush information
2311 * @scratch: u64 saved to be used during cqp completion
2312 * @post_sq: flag for cqp db to ring
2313 */
2314static enum i40iw_status_code i40iw_sc_qp_flush_wqes(
2315 struct i40iw_sc_qp *qp,
2316 struct i40iw_qp_flush_info *info,
2317 u64 scratch,
2318 bool post_sq)
2319{
2320 u64 temp = 0;
2321 u64 *wqe;
2322 struct i40iw_sc_cqp *cqp;
2323 u64 header;
2324 bool flush_sq = false, flush_rq = false;
2325
2326 if (info->rq && !qp->flush_rq)
2327 flush_rq = true;
2328
2329 if (info->sq && !qp->flush_sq)
2330 flush_sq = true;
2331
2332 qp->flush_sq |= flush_sq;
2333 qp->flush_rq |= flush_rq;
2334 if (!flush_sq && !flush_rq) {
2335 if (info->ae_code != I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR)
2336 return 0;
2337 }
2338
2339 cqp = qp->pd->dev->cqp;
2340 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2341 if (!wqe)
2342 return I40IW_ERR_RING_FULL;
2343 if (info->userflushcode) {
2344 if (flush_rq) {
2345 temp |= LS_64(info->rq_minor_code, I40IW_CQPSQ_FWQE_RQMNERR) |
2346 LS_64(info->rq_major_code, I40IW_CQPSQ_FWQE_RQMJERR);
2347 }
2348 if (flush_sq) {
2349 temp |= LS_64(info->sq_minor_code, I40IW_CQPSQ_FWQE_SQMNERR) |
2350 LS_64(info->sq_major_code, I40IW_CQPSQ_FWQE_SQMJERR);
2351 }
2352 }
2353 set_64bit_val(wqe, 16, temp);
2354
2355 temp = (info->generate_ae) ?
2356 info->ae_code | LS_64(info->ae_source, I40IW_CQPSQ_FWQE_AESOURCE) : 0;
2357
2358 set_64bit_val(wqe, 8, temp);
2359
2360 header = qp->qp_uk.qp_id |
2361 LS_64(I40IW_CQP_OP_FLUSH_WQES, I40IW_CQPSQ_OPCODE) |
2362 LS_64(info->generate_ae, I40IW_CQPSQ_FWQE_GENERATE_AE) |
2363 LS_64(info->userflushcode, I40IW_CQPSQ_FWQE_USERFLCODE) |
2364 LS_64(flush_sq, I40IW_CQPSQ_FWQE_FLUSHSQ) |
2365 LS_64(flush_rq, I40IW_CQPSQ_FWQE_FLUSHRQ) |
2366 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2367
2368 i40iw_insert_wqe_hdr(wqe, header);
2369
2370 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_FLUSH WQE",
2371 wqe, I40IW_CQP_WQE_SIZE * 8);
2372
2373 if (post_sq)
2374 i40iw_sc_cqp_post_sq(cqp);
2375 return 0;
2376}
2377
2378/**
2379 * i40iw_sc_qp_upload_context - upload qp's context
2380 * @dev: sc device struct
2381 * @info: upload context info ptr for return
2382 * @scratch: u64 saved to be used during cqp completion
2383 * @post_sq: flag for cqp db to ring
2384 */
2385static enum i40iw_status_code i40iw_sc_qp_upload_context(
2386 struct i40iw_sc_dev *dev,
2387 struct i40iw_upload_context_info *info,
2388 u64 scratch,
2389 bool post_sq)
2390{
2391 u64 *wqe;
2392 struct i40iw_sc_cqp *cqp;
2393 u64 header;
2394
2395 cqp = dev->cqp;
2396 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2397 if (!wqe)
2398 return I40IW_ERR_RING_FULL;
2399 set_64bit_val(wqe, 16, info->buf_pa);
2400
2401 header = LS_64(info->qp_id, I40IW_CQPSQ_UCTX_QPID) |
2402 LS_64(I40IW_CQP_OP_UPLOAD_CONTEXT, I40IW_CQPSQ_OPCODE) |
2403 LS_64(info->qp_type, I40IW_CQPSQ_UCTX_QPTYPE) |
2404 LS_64(info->raw_format, I40IW_CQPSQ_UCTX_RAWFORMAT) |
2405 LS_64(info->freeze_qp, I40IW_CQPSQ_UCTX_FREEZEQP) |
2406 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2407
2408 i40iw_insert_wqe_hdr(wqe, header);
2409
2410 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "QP_UPLOAD_CTX WQE",
2411 wqe, I40IW_CQP_WQE_SIZE * 8);
2412
2413 if (post_sq)
2414 i40iw_sc_cqp_post_sq(cqp);
2415 return 0;
2416}
2417
2418/**
2419 * i40iw_sc_qp_setctx - set qp's context
2420 * @qp: sc qp
2421 * @qp_ctx: context ptr
2422 * @info: ctx info
2423 */
2424static enum i40iw_status_code i40iw_sc_qp_setctx(
2425 struct i40iw_sc_qp *qp,
2426 u64 *qp_ctx,
2427 struct i40iw_qp_host_ctx_info *info)
2428{
2429 struct i40iwarp_offload_info *iw;
2430 struct i40iw_tcp_offload_info *tcp;
2431 u64 qw0, qw3, qw7 = 0;
2432
2433 iw = info->iwarp_info;
2434 tcp = info->tcp_info;
2435 qw0 = LS_64(qp->qp_uk.rq_wqe_size, I40IWQPC_RQWQESIZE) |
2436 LS_64(info->err_rq_idx_valid, I40IWQPC_ERR_RQ_IDX_VALID) |
2437 LS_64(qp->rcv_tph_en, I40IWQPC_RCVTPHEN) |
2438 LS_64(qp->xmit_tph_en, I40IWQPC_XMITTPHEN) |
2439 LS_64(qp->rq_tph_en, I40IWQPC_RQTPHEN) |
2440 LS_64(qp->sq_tph_en, I40IWQPC_SQTPHEN) |
2441 LS_64(info->push_idx, I40IWQPC_PPIDX) |
2442 LS_64(info->push_mode_en, I40IWQPC_PMENA);
2443
2444 set_64bit_val(qp_ctx, 8, qp->sq_pa);
2445 set_64bit_val(qp_ctx, 16, qp->rq_pa);
2446
2447 qw3 = LS_64(qp->src_mac_addr_idx, I40IWQPC_SRCMACADDRIDX) |
2448 LS_64(qp->hw_rq_size, I40IWQPC_RQSIZE) |
2449 LS_64(qp->hw_sq_size, I40IWQPC_SQSIZE);
2450
2451 set_64bit_val(qp_ctx,
2452 128,
2453 LS_64(info->err_rq_idx, I40IWQPC_ERR_RQ_IDX));
2454
2455 set_64bit_val(qp_ctx,
2456 136,
2457 LS_64(info->send_cq_num, I40IWQPC_TXCQNUM) |
2458 LS_64(info->rcv_cq_num, I40IWQPC_RXCQNUM));
2459
2460 set_64bit_val(qp_ctx,
2461 168,
2462 LS_64(info->qp_compl_ctx, I40IWQPC_QPCOMPCTX));
2463 set_64bit_val(qp_ctx,
2464 176,
2465 LS_64(qp->sq_tph_val, I40IWQPC_SQTPHVAL) |
2466 LS_64(qp->rq_tph_val, I40IWQPC_RQTPHVAL) |
2467 LS_64(qp->qs_handle, I40IWQPC_QSHANDLE) |
2468 LS_64(qp->exception_lan_queue, I40IWQPC_EXCEPTION_LAN_QUEUE));
2469
2470 if (info->iwarp_info_valid) {
2471 qw0 |= LS_64(iw->ddp_ver, I40IWQPC_DDP_VER) |
2472 LS_64(iw->rdmap_ver, I40IWQPC_RDMAP_VER);
2473
2474 qw7 |= LS_64(iw->pd_id, I40IWQPC_PDIDX);
2475 set_64bit_val(qp_ctx, 144, qp->q2_pa);
2476 set_64bit_val(qp_ctx,
2477 152,
2478 LS_64(iw->last_byte_sent, I40IWQPC_LASTBYTESENT));
2479
2480 /*
2481 * Hard-code IRD_SIZE to hw-limit, 128, in qpctx, i.e matching an
2482 *advertisable IRD of 64
2483 */
2484 iw->ird_size = I40IW_QPCTX_ENCD_MAXIRD;
2485 set_64bit_val(qp_ctx,
2486 160,
2487 LS_64(iw->ord_size, I40IWQPC_ORDSIZE) |
2488 LS_64(iw->ird_size, I40IWQPC_IRDSIZE) |
2489 LS_64(iw->wr_rdresp_en, I40IWQPC_WRRDRSPOK) |
2490 LS_64(iw->rd_enable, I40IWQPC_RDOK) |
2491 LS_64(iw->snd_mark_en, I40IWQPC_SNDMARKERS) |
2492 LS_64(iw->bind_en, I40IWQPC_BINDEN) |
2493 LS_64(iw->fast_reg_en, I40IWQPC_FASTREGEN) |
2494 LS_64(iw->priv_mode_en, I40IWQPC_PRIVEN) |
2495 LS_64(1, I40IWQPC_IWARPMODE) |
2496 LS_64(iw->rcv_mark_en, I40IWQPC_RCVMARKERS) |
2497 LS_64(iw->align_hdrs, I40IWQPC_ALIGNHDRS) |
2498 LS_64(iw->rcv_no_mpa_crc, I40IWQPC_RCVNOMPACRC) |
2499 LS_64(iw->rcv_mark_offset, I40IWQPC_RCVMARKOFFSET) |
2500 LS_64(iw->snd_mark_offset, I40IWQPC_SNDMARKOFFSET));
2501 }
2502 if (info->tcp_info_valid) {
2503 qw0 |= LS_64(tcp->ipv4, I40IWQPC_IPV4) |
2504 LS_64(tcp->no_nagle, I40IWQPC_NONAGLE) |
2505 LS_64(tcp->insert_vlan_tag, I40IWQPC_INSERTVLANTAG) |
2506 LS_64(tcp->time_stamp, I40IWQPC_TIMESTAMP) |
2507 LS_64(tcp->cwnd_inc_limit, I40IWQPC_LIMIT) |
2508 LS_64(tcp->drop_ooo_seg, I40IWQPC_DROPOOOSEG) |
2509 LS_64(tcp->dup_ack_thresh, I40IWQPC_DUPACK_THRESH);
2510
2511 qw3 |= LS_64(tcp->ttl, I40IWQPC_TTL) |
2512 LS_64(tcp->src_mac_addr_idx, I40IWQPC_SRCMACADDRIDX) |
2513 LS_64(tcp->avoid_stretch_ack, I40IWQPC_AVOIDSTRETCHACK) |
2514 LS_64(tcp->tos, I40IWQPC_TOS) |
2515 LS_64(tcp->src_port, I40IWQPC_SRCPORTNUM) |
2516 LS_64(tcp->dst_port, I40IWQPC_DESTPORTNUM);
2517
2518 qp->src_mac_addr_idx = tcp->src_mac_addr_idx;
2519 set_64bit_val(qp_ctx,
2520 32,
2521 LS_64(tcp->dest_ip_addr2, I40IWQPC_DESTIPADDR2) |
2522 LS_64(tcp->dest_ip_addr3, I40IWQPC_DESTIPADDR3));
2523
2524 set_64bit_val(qp_ctx,
2525 40,
2526 LS_64(tcp->dest_ip_addr0, I40IWQPC_DESTIPADDR0) |
2527 LS_64(tcp->dest_ip_addr1, I40IWQPC_DESTIPADDR1));
2528
2529 set_64bit_val(qp_ctx,
2530 48,
2531 LS_64(tcp->snd_mss, I40IWQPC_SNDMSS) |
2532 LS_64(tcp->vlan_tag, I40IWQPC_VLANTAG) |
2533 LS_64(tcp->arp_idx, I40IWQPC_ARPIDX));
2534
2535 qw7 |= LS_64(tcp->flow_label, I40IWQPC_FLOWLABEL) |
2536 LS_64(tcp->wscale, I40IWQPC_WSCALE) |
2537 LS_64(tcp->ignore_tcp_opt, I40IWQPC_IGNORE_TCP_OPT) |
2538 LS_64(tcp->ignore_tcp_uns_opt, I40IWQPC_IGNORE_TCP_UNS_OPT) |
2539 LS_64(tcp->tcp_state, I40IWQPC_TCPSTATE) |
2540 LS_64(tcp->rcv_wscale, I40IWQPC_RCVSCALE) |
2541 LS_64(tcp->snd_wscale, I40IWQPC_SNDSCALE);
2542
2543 set_64bit_val(qp_ctx,
2544 72,
2545 LS_64(tcp->time_stamp_recent, I40IWQPC_TIMESTAMP_RECENT) |
2546 LS_64(tcp->time_stamp_age, I40IWQPC_TIMESTAMP_AGE));
2547 set_64bit_val(qp_ctx,
2548 80,
2549 LS_64(tcp->snd_nxt, I40IWQPC_SNDNXT) |
2550 LS_64(tcp->snd_wnd, I40IWQPC_SNDWND));
2551
2552 set_64bit_val(qp_ctx,
2553 88,
2554 LS_64(tcp->rcv_nxt, I40IWQPC_RCVNXT) |
2555 LS_64(tcp->rcv_wnd, I40IWQPC_RCVWND));
2556 set_64bit_val(qp_ctx,
2557 96,
2558 LS_64(tcp->snd_max, I40IWQPC_SNDMAX) |
2559 LS_64(tcp->snd_una, I40IWQPC_SNDUNA));
2560 set_64bit_val(qp_ctx,
2561 104,
2562 LS_64(tcp->srtt, I40IWQPC_SRTT) |
2563 LS_64(tcp->rtt_var, I40IWQPC_RTTVAR));
2564 set_64bit_val(qp_ctx,
2565 112,
2566 LS_64(tcp->ss_thresh, I40IWQPC_SSTHRESH) |
2567 LS_64(tcp->cwnd, I40IWQPC_CWND));
2568 set_64bit_val(qp_ctx,
2569 120,
2570 LS_64(tcp->snd_wl1, I40IWQPC_SNDWL1) |
2571 LS_64(tcp->snd_wl2, I40IWQPC_SNDWL2));
2572 set_64bit_val(qp_ctx,
2573 128,
2574 LS_64(tcp->max_snd_window, I40IWQPC_MAXSNDWND) |
2575 LS_64(tcp->rexmit_thresh, I40IWQPC_REXMIT_THRESH));
2576 set_64bit_val(qp_ctx,
2577 184,
2578 LS_64(tcp->local_ipaddr3, I40IWQPC_LOCAL_IPADDR3) |
2579 LS_64(tcp->local_ipaddr2, I40IWQPC_LOCAL_IPADDR2));
2580 set_64bit_val(qp_ctx,
2581 192,
2582 LS_64(tcp->local_ipaddr1, I40IWQPC_LOCAL_IPADDR1) |
2583 LS_64(tcp->local_ipaddr0, I40IWQPC_LOCAL_IPADDR0));
2584 }
2585
2586 set_64bit_val(qp_ctx, 0, qw0);
2587 set_64bit_val(qp_ctx, 24, qw3);
2588 set_64bit_val(qp_ctx, 56, qw7);
2589
2590 i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "QP_HOST)CTX WQE",
2591 qp_ctx, I40IW_QP_CTX_SIZE);
2592 return 0;
2593}
2594
2595/**
2596 * i40iw_sc_alloc_stag - mr stag alloc
2597 * @dev: sc device struct
2598 * @info: stag info
2599 * @scratch: u64 saved to be used during cqp completion
2600 * @post_sq: flag for cqp db to ring
2601 */
2602static enum i40iw_status_code i40iw_sc_alloc_stag(
2603 struct i40iw_sc_dev *dev,
2604 struct i40iw_allocate_stag_info *info,
2605 u64 scratch,
2606 bool post_sq)
2607{
2608 u64 *wqe;
2609 struct i40iw_sc_cqp *cqp;
2610 u64 header;
2611
2612 cqp = dev->cqp;
2613 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2614 if (!wqe)
2615 return I40IW_ERR_RING_FULL;
2616 set_64bit_val(wqe,
2617 8,
2618 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID) |
2619 LS_64(info->total_len, I40IW_CQPSQ_STAG_STAGLEN));
2620 set_64bit_val(wqe,
2621 16,
2622 LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
2623 set_64bit_val(wqe,
2624 40,
2625 LS_64(info->hmc_fcn_index, I40IW_CQPSQ_STAG_HMCFNIDX));
2626
2627 header = LS_64(I40IW_CQP_OP_ALLOC_STAG, I40IW_CQPSQ_OPCODE) |
2628 LS_64(1, I40IW_CQPSQ_STAG_MR) |
2629 LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
2630 LS_64(info->chunk_size, I40IW_CQPSQ_STAG_LPBLSIZE) |
2631 LS_64(info->page_size, I40IW_CQPSQ_STAG_HPAGESIZE) |
2632 LS_64(info->remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
2633 LS_64(info->use_hmc_fcn_index, I40IW_CQPSQ_STAG_USEHMCFNIDX) |
2634 LS_64(info->use_pf_rid, I40IW_CQPSQ_STAG_USEPFRID) |
2635 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2636
2637 i40iw_insert_wqe_hdr(wqe, header);
2638
2639 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "ALLOC_STAG WQE",
2640 wqe, I40IW_CQP_WQE_SIZE * 8);
2641
2642 if (post_sq)
2643 i40iw_sc_cqp_post_sq(cqp);
2644 return 0;
2645}
2646
2647/**
2648 * i40iw_sc_mr_reg_non_shared - non-shared mr registration
2649 * @dev: sc device struct
2650 * @info: mr info
2651 * @scratch: u64 saved to be used during cqp completion
2652 * @post_sq: flag for cqp db to ring
2653 */
2654static enum i40iw_status_code i40iw_sc_mr_reg_non_shared(
2655 struct i40iw_sc_dev *dev,
2656 struct i40iw_reg_ns_stag_info *info,
2657 u64 scratch,
2658 bool post_sq)
2659{
2660 u64 *wqe;
2661 u64 temp;
2662 struct i40iw_sc_cqp *cqp;
2663 u64 header;
2664 u32 pble_obj_cnt;
2665 bool remote_access;
2666 u8 addr_type;
2667
2668 if (info->access_rights & (I40IW_ACCESS_FLAGS_REMOTEREAD_ONLY |
2669 I40IW_ACCESS_FLAGS_REMOTEWRITE_ONLY))
2670 remote_access = true;
2671 else
2672 remote_access = false;
2673
2674 pble_obj_cnt = dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
2675
2676 if (info->chunk_size && (info->first_pm_pbl_index >= pble_obj_cnt))
2677 return I40IW_ERR_INVALID_PBLE_INDEX;
2678
2679 cqp = dev->cqp;
2680 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2681 if (!wqe)
2682 return I40IW_ERR_RING_FULL;
2683
2684 temp = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? (uintptr_t)info->va : info->fbo;
2685 set_64bit_val(wqe, 0, temp);
2686
2687 set_64bit_val(wqe,
2688 8,
2689 LS_64(info->total_len, I40IW_CQPSQ_STAG_STAGLEN) |
2690 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
2691
2692 set_64bit_val(wqe,
2693 16,
2694 LS_64(info->stag_key, I40IW_CQPSQ_STAG_KEY) |
2695 LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
2696 if (!info->chunk_size) {
2697 set_64bit_val(wqe, 32, info->reg_addr_pa);
2698 set_64bit_val(wqe, 48, 0);
2699 } else {
2700 set_64bit_val(wqe, 32, 0);
2701 set_64bit_val(wqe, 48, info->first_pm_pbl_index);
2702 }
2703 set_64bit_val(wqe, 40, info->hmc_fcn_index);
2704 set_64bit_val(wqe, 56, 0);
2705
2706 addr_type = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? 1 : 0;
2707 header = LS_64(I40IW_CQP_OP_REG_MR, I40IW_CQPSQ_OPCODE) |
2708 LS_64(1, I40IW_CQPSQ_STAG_MR) |
2709 LS_64(info->chunk_size, I40IW_CQPSQ_STAG_LPBLSIZE) |
2710 LS_64(info->page_size, I40IW_CQPSQ_STAG_HPAGESIZE) |
2711 LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
2712 LS_64(remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
2713 LS_64(addr_type, I40IW_CQPSQ_STAG_VABASEDTO) |
2714 LS_64(info->use_hmc_fcn_index, I40IW_CQPSQ_STAG_USEHMCFNIDX) |
2715 LS_64(info->use_pf_rid, I40IW_CQPSQ_STAG_USEPFRID) |
2716 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2717
2718 i40iw_insert_wqe_hdr(wqe, header);
2719
2720 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MR_REG_NS WQE",
2721 wqe, I40IW_CQP_WQE_SIZE * 8);
2722
2723 if (post_sq)
2724 i40iw_sc_cqp_post_sq(cqp);
2725 return 0;
2726}
2727
2728/**
2729 * i40iw_sc_mr_reg_shared - registered shared memory region
2730 * @dev: sc device struct
2731 * @info: info for shared memory registeration
2732 * @scratch: u64 saved to be used during cqp completion
2733 * @post_sq: flag for cqp db to ring
2734 */
2735static enum i40iw_status_code i40iw_sc_mr_reg_shared(
2736 struct i40iw_sc_dev *dev,
2737 struct i40iw_register_shared_stag *info,
2738 u64 scratch,
2739 bool post_sq)
2740{
2741 u64 *wqe;
2742 struct i40iw_sc_cqp *cqp;
2743 u64 temp, va64, fbo, header;
2744 u32 va32;
2745 bool remote_access;
2746 u8 addr_type;
2747
2748 if (info->access_rights & (I40IW_ACCESS_FLAGS_REMOTEREAD_ONLY |
2749 I40IW_ACCESS_FLAGS_REMOTEWRITE_ONLY))
2750 remote_access = true;
2751 else
2752 remote_access = false;
2753 cqp = dev->cqp;
2754 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2755 if (!wqe)
2756 return I40IW_ERR_RING_FULL;
2757 va64 = (uintptr_t)(info->va);
2758 va32 = (u32)(va64 & 0x00000000FFFFFFFF);
2759 fbo = (u64)(va32 & (4096 - 1));
2760
2761 set_64bit_val(wqe,
2762 0,
2763 (info->addr_type == I40IW_ADDR_TYPE_VA_BASED ? (uintptr_t)info->va : fbo));
2764
2765 set_64bit_val(wqe,
2766 8,
2767 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
2768 temp = LS_64(info->new_stag_key, I40IW_CQPSQ_STAG_KEY) |
2769 LS_64(info->new_stag_idx, I40IW_CQPSQ_STAG_IDX) |
2770 LS_64(info->parent_stag_idx, I40IW_CQPSQ_STAG_PARENTSTAGIDX);
2771 set_64bit_val(wqe, 16, temp);
2772
2773 addr_type = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? 1 : 0;
2774 header = LS_64(I40IW_CQP_OP_REG_SMR, I40IW_CQPSQ_OPCODE) |
2775 LS_64(1, I40IW_CQPSQ_STAG_MR) |
2776 LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
2777 LS_64(remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
2778 LS_64(addr_type, I40IW_CQPSQ_STAG_VABASEDTO) |
2779 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2780
2781 i40iw_insert_wqe_hdr(wqe, header);
2782
2783 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MR_REG_SHARED WQE",
2784 wqe, I40IW_CQP_WQE_SIZE * 8);
2785
2786 if (post_sq)
2787 i40iw_sc_cqp_post_sq(cqp);
2788 return 0;
2789}
2790
2791/**
2792 * i40iw_sc_dealloc_stag - deallocate stag
2793 * @dev: sc device struct
2794 * @info: dealloc stag info
2795 * @scratch: u64 saved to be used during cqp completion
2796 * @post_sq: flag for cqp db to ring
2797 */
2798static enum i40iw_status_code i40iw_sc_dealloc_stag(
2799 struct i40iw_sc_dev *dev,
2800 struct i40iw_dealloc_stag_info *info,
2801 u64 scratch,
2802 bool post_sq)
2803{
2804 u64 header;
2805 u64 *wqe;
2806 struct i40iw_sc_cqp *cqp;
2807
2808 cqp = dev->cqp;
2809 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2810 if (!wqe)
2811 return I40IW_ERR_RING_FULL;
2812 set_64bit_val(wqe,
2813 8,
2814 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
2815 set_64bit_val(wqe,
2816 16,
2817 LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
2818
2819 header = LS_64(I40IW_CQP_OP_DEALLOC_STAG, I40IW_CQPSQ_OPCODE) |
2820 LS_64(info->mr, I40IW_CQPSQ_STAG_MR) |
2821 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2822
2823 i40iw_insert_wqe_hdr(wqe, header);
2824
2825 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "DEALLOC_STAG WQE",
2826 wqe, I40IW_CQP_WQE_SIZE * 8);
2827
2828 if (post_sq)
2829 i40iw_sc_cqp_post_sq(cqp);
2830 return 0;
2831}
2832
2833/**
2834 * i40iw_sc_query_stag - query hardware for stag
2835 * @dev: sc device struct
2836 * @scratch: u64 saved to be used during cqp completion
2837 * @stag_index: stag index for query
2838 * @post_sq: flag for cqp db to ring
2839 */
2840static enum i40iw_status_code i40iw_sc_query_stag(struct i40iw_sc_dev *dev,
2841 u64 scratch,
2842 u32 stag_index,
2843 bool post_sq)
2844{
2845 u64 header;
2846 u64 *wqe;
2847 struct i40iw_sc_cqp *cqp;
2848
2849 cqp = dev->cqp;
2850 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2851 if (!wqe)
2852 return I40IW_ERR_RING_FULL;
2853 set_64bit_val(wqe,
2854 16,
2855 LS_64(stag_index, I40IW_CQPSQ_QUERYSTAG_IDX));
2856
2857 header = LS_64(I40IW_CQP_OP_QUERY_STAG, I40IW_CQPSQ_OPCODE) |
2858 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2859
2860 i40iw_insert_wqe_hdr(wqe, header);
2861
2862 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "QUERY_STAG WQE",
2863 wqe, I40IW_CQP_WQE_SIZE * 8);
2864
2865 if (post_sq)
2866 i40iw_sc_cqp_post_sq(cqp);
2867 return 0;
2868}
2869
2870/**
2871 * i40iw_sc_mw_alloc - mw allocate
2872 * @dev: sc device struct
2873 * @scratch: u64 saved to be used during cqp completion
2874 * @mw_stag_index:stag index
2875 * @pd_id: pd is for this mw
2876 * @post_sq: flag for cqp db to ring
2877 */
2878static enum i40iw_status_code i40iw_sc_mw_alloc(
2879 struct i40iw_sc_dev *dev,
2880 u64 scratch,
2881 u32 mw_stag_index,
2882 u16 pd_id,
2883 bool post_sq)
2884{
2885 u64 header;
2886 struct i40iw_sc_cqp *cqp;
2887 u64 *wqe;
2888
2889 cqp = dev->cqp;
2890 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2891 if (!wqe)
2892 return I40IW_ERR_RING_FULL;
2893 set_64bit_val(wqe, 8, LS_64(pd_id, I40IW_CQPSQ_STAG_PDID));
2894 set_64bit_val(wqe,
2895 16,
2896 LS_64(mw_stag_index, I40IW_CQPSQ_STAG_IDX));
2897
2898 header = LS_64(I40IW_CQP_OP_ALLOC_STAG, I40IW_CQPSQ_OPCODE) |
2899 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2900
2901 i40iw_insert_wqe_hdr(wqe, header);
2902
2903 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MW_ALLOC WQE",
2904 wqe, I40IW_CQP_WQE_SIZE * 8);
2905
2906 if (post_sq)
2907 i40iw_sc_cqp_post_sq(cqp);
2908 return 0;
2909}
2910
2911/**
2912 * i40iw_sc_send_lsmm - send last streaming mode message
2913 * @qp: sc qp struct
2914 * @lsmm_buf: buffer with lsmm message
2915 * @size: size of lsmm buffer
2916 * @stag: stag of lsmm buffer
2917 */
2918static void i40iw_sc_send_lsmm(struct i40iw_sc_qp *qp,
2919 void *lsmm_buf,
2920 u32 size,
2921 i40iw_stag stag)
2922{
2923 u64 *wqe;
2924 u64 header;
2925 struct i40iw_qp_uk *qp_uk;
2926
2927 qp_uk = &qp->qp_uk;
2928 wqe = qp_uk->sq_base->elem;
2929
2930 set_64bit_val(wqe, 0, (uintptr_t)lsmm_buf);
2931
2932 set_64bit_val(wqe, 8, (size | LS_64(stag, I40IWQPSQ_FRAG_STAG)));
2933
2934 set_64bit_val(wqe, 16, 0);
2935
2936 header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
2937 LS_64(1, I40IWQPSQ_STREAMMODE) |
2938 LS_64(1, I40IWQPSQ_WAITFORRCVPDU) |
2939 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
2940
2941 i40iw_insert_wqe_hdr(wqe, header);
2942
2943 i40iw_debug_buf(qp->dev, I40IW_DEBUG_QP, "SEND_LSMM WQE",
2944 wqe, I40IW_QP_WQE_MIN_SIZE);
2945}
2946
2947/**
2948 * i40iw_sc_send_lsmm_nostag - for privilege qp
2949 * @qp: sc qp struct
2950 * @lsmm_buf: buffer with lsmm message
2951 * @size: size of lsmm buffer
2952 */
2953static void i40iw_sc_send_lsmm_nostag(struct i40iw_sc_qp *qp,
2954 void *lsmm_buf,
2955 u32 size)
2956{
2957 u64 *wqe;
2958 u64 header;
2959 struct i40iw_qp_uk *qp_uk;
2960
2961 qp_uk = &qp->qp_uk;
2962 wqe = qp_uk->sq_base->elem;
2963
2964 set_64bit_val(wqe, 0, (uintptr_t)lsmm_buf);
2965
2966 set_64bit_val(wqe, 8, size);
2967
2968 set_64bit_val(wqe, 16, 0);
2969
2970 header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
2971 LS_64(1, I40IWQPSQ_STREAMMODE) |
2972 LS_64(1, I40IWQPSQ_WAITFORRCVPDU) |
2973 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
2974
2975 i40iw_insert_wqe_hdr(wqe, header);
2976
2977 i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "SEND_LSMM_NOSTAG WQE",
2978 wqe, I40IW_QP_WQE_MIN_SIZE);
2979}
2980
2981/**
2982 * i40iw_sc_send_rtt - send last read0 or write0
2983 * @qp: sc qp struct
2984 * @read: Do read0 or write0
2985 */
2986static void i40iw_sc_send_rtt(struct i40iw_sc_qp *qp, bool read)
2987{
2988 u64 *wqe;
2989 u64 header;
2990 struct i40iw_qp_uk *qp_uk;
2991
2992 qp_uk = &qp->qp_uk;
2993 wqe = qp_uk->sq_base->elem;
2994
2995 set_64bit_val(wqe, 0, 0);
2996 set_64bit_val(wqe, 8, 0);
2997 set_64bit_val(wqe, 16, 0);
2998 if (read) {
2999 header = LS_64(0x1234, I40IWQPSQ_REMSTAG) |
3000 LS_64(I40IWQP_OP_RDMA_READ, I40IWQPSQ_OPCODE) |
3001 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3002 set_64bit_val(wqe, 8, ((u64)0xabcd << 32));
3003 } else {
3004 header = LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
3005 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3006 }
3007
3008 i40iw_insert_wqe_hdr(wqe, header);
3009
3010 i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "RTR WQE",
3011 wqe, I40IW_QP_WQE_MIN_SIZE);
3012}
3013
3014/**
3015 * i40iw_sc_post_wqe0 - send wqe with opcode
3016 * @qp: sc qp struct
3017 * @opcode: opcode to use for wqe0
3018 */
3019static enum i40iw_status_code i40iw_sc_post_wqe0(struct i40iw_sc_qp *qp, u8 opcode)
3020{
3021 u64 *wqe;
3022 u64 header;
3023 struct i40iw_qp_uk *qp_uk;
3024
3025 qp_uk = &qp->qp_uk;
3026 wqe = qp_uk->sq_base->elem;
3027
3028 if (!wqe)
3029 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
3030 switch (opcode) {
3031 case I40IWQP_OP_NOP:
3032 set_64bit_val(wqe, 0, 0);
3033 set_64bit_val(wqe, 8, 0);
3034 set_64bit_val(wqe, 16, 0);
3035 header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
3036 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3037
3038 i40iw_insert_wqe_hdr(wqe, header);
3039 break;
3040 case I40IWQP_OP_RDMA_SEND:
3041 set_64bit_val(wqe, 0, 0);
3042 set_64bit_val(wqe, 8, 0);
3043 set_64bit_val(wqe, 16, 0);
3044 header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
3045 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID) |
3046 LS_64(1, I40IWQPSQ_STREAMMODE) |
3047 LS_64(1, I40IWQPSQ_WAITFORRCVPDU);
3048
3049 i40iw_insert_wqe_hdr(wqe, header);
3050 break;
3051 default:
3052 i40iw_debug(qp->dev, I40IW_DEBUG_QP, "%s: Invalid WQE zero opcode\n",
3053 __func__);
3054 break;
3055 }
3056 return 0;
3057}
3058
3059/**
3060 * i40iw_sc_init_iw_hmc() - queries fpm values using cqp and populates hmc_info
3061 * @dev : ptr to i40iw_dev struct
3062 * @hmc_fn_id: hmc function id
3063 */
3064enum i40iw_status_code i40iw_sc_init_iw_hmc(struct i40iw_sc_dev *dev, u8 hmc_fn_id)
3065{
3066 struct i40iw_hmc_info *hmc_info;
3067 struct i40iw_dma_mem query_fpm_mem;
3068 struct i40iw_virt_mem virt_mem;
3069 struct i40iw_vfdev *vf_dev = NULL;
3070 u32 mem_size;
3071 enum i40iw_status_code ret_code = 0;
3072 bool poll_registers = true;
3073 u16 iw_vf_idx;
3074 u8 wait_type;
3075
3076 if (hmc_fn_id >= I40IW_MAX_VF_FPM_ID ||
3077 (dev->hmc_fn_id != hmc_fn_id && hmc_fn_id < I40IW_FIRST_VF_FPM_ID))
3078 return I40IW_ERR_INVALID_HMCFN_ID;
3079
3080 i40iw_debug(dev, I40IW_DEBUG_HMC, "hmc_fn_id %u, dev->hmc_fn_id %u\n", hmc_fn_id,
3081 dev->hmc_fn_id);
3082 if (hmc_fn_id == dev->hmc_fn_id) {
3083 hmc_info = dev->hmc_info;
3084 query_fpm_mem.pa = dev->fpm_query_buf_pa;
3085 query_fpm_mem.va = dev->fpm_query_buf;
3086 } else {
3087 vf_dev = i40iw_vfdev_from_fpm(dev, hmc_fn_id);
3088 if (!vf_dev)
3089 return I40IW_ERR_INVALID_VF_ID;
3090
3091 hmc_info = &vf_dev->hmc_info;
3092 iw_vf_idx = vf_dev->iw_vf_idx;
3093 i40iw_debug(dev, I40IW_DEBUG_HMC, "vf_dev %p, hmc_info %p, hmc_obj %p\n", vf_dev,
3094 hmc_info, hmc_info->hmc_obj);
3095 if (!vf_dev->fpm_query_buf) {
3096 if (!dev->vf_fpm_query_buf[iw_vf_idx].va) {
3097 ret_code = i40iw_alloc_query_fpm_buf(dev,
3098 &dev->vf_fpm_query_buf[iw_vf_idx]);
3099 if (ret_code)
3100 return ret_code;
3101 }
3102 vf_dev->fpm_query_buf = dev->vf_fpm_query_buf[iw_vf_idx].va;
3103 vf_dev->fpm_query_buf_pa = dev->vf_fpm_query_buf[iw_vf_idx].pa;
3104 }
3105 query_fpm_mem.pa = vf_dev->fpm_query_buf_pa;
3106 query_fpm_mem.va = vf_dev->fpm_query_buf;
3107 /**
3108 * It is HARDWARE specific:
3109 * this call is done by PF for VF and
3110 * i40iw_sc_query_fpm_values needs ccq poll
3111 * because PF ccq is already created.
3112 */
3113 poll_registers = false;
3114 }
3115
3116 hmc_info->hmc_fn_id = hmc_fn_id;
3117
3118 if (hmc_fn_id != dev->hmc_fn_id) {
3119 ret_code =
3120 i40iw_cqp_query_fpm_values_cmd(dev, &query_fpm_mem, hmc_fn_id);
3121 } else {
3122 wait_type = poll_registers ? (u8)I40IW_CQP_WAIT_POLL_REGS :
3123 (u8)I40IW_CQP_WAIT_POLL_CQ;
3124
3125 ret_code = i40iw_sc_query_fpm_values(
3126 dev->cqp,
3127 0,
3128 hmc_info->hmc_fn_id,
3129 &query_fpm_mem,
3130 true,
3131 wait_type);
3132 }
3133 if (ret_code)
3134 return ret_code;
3135
3136 /* parse the fpm_query_buf and fill hmc obj info */
3137 ret_code =
3138 i40iw_sc_parse_fpm_query_buf((u64 *)query_fpm_mem.va,
3139 hmc_info,
3140 &dev->hmc_fpm_misc);
3141 if (ret_code)
3142 return ret_code;
3143 i40iw_debug_buf(dev, I40IW_DEBUG_HMC, "QUERY FPM BUFFER",
3144 query_fpm_mem.va, I40IW_QUERY_FPM_BUF_SIZE);
3145
3146 if (hmc_fn_id != dev->hmc_fn_id) {
3147 i40iw_cqp_commit_fpm_values_cmd(dev, &query_fpm_mem, hmc_fn_id);
3148
3149 /* parse the fpm_commit_buf and fill hmc obj info */
3150 i40iw_sc_parse_fpm_commit_buf((u64 *)query_fpm_mem.va, hmc_info->hmc_obj);
3151 mem_size = sizeof(struct i40iw_hmc_sd_entry) *
3152 (hmc_info->sd_table.sd_cnt + hmc_info->first_sd_index);
3153 ret_code = i40iw_allocate_virt_mem(dev->hw, &virt_mem, mem_size);
3154 if (ret_code)
3155 return ret_code;
3156 hmc_info->sd_table.sd_entry = virt_mem.va;
3157 }
3158
3159 /* fill size of objects which are fixed */
3160 hmc_info->hmc_obj[I40IW_HMC_IW_XFFL].size = 4;
3161 hmc_info->hmc_obj[I40IW_HMC_IW_Q1FL].size = 4;
3162 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].size = 8;
3163 hmc_info->hmc_obj[I40IW_HMC_IW_APBVT_ENTRY].size = 8192;
3164 hmc_info->hmc_obj[I40IW_HMC_IW_APBVT_ENTRY].max_cnt = 1;
3165
3166 return ret_code;
3167}
3168
3169/**
3170 * i40iw_sc_configure_iw_fpm() - commits hmc obj cnt values using cqp command and
3171 * populates fpm base address in hmc_info
3172 * @dev : ptr to i40iw_dev struct
3173 * @hmc_fn_id: hmc function id
3174 */
3175static enum i40iw_status_code i40iw_sc_configure_iw_fpm(struct i40iw_sc_dev *dev,
3176 u8 hmc_fn_id)
3177{
3178 struct i40iw_hmc_info *hmc_info;
3179 struct i40iw_hmc_obj_info *obj_info;
3180 u64 *buf;
3181 struct i40iw_dma_mem commit_fpm_mem;
3182 u32 i, j;
3183 enum i40iw_status_code ret_code = 0;
3184 bool poll_registers = true;
3185 u8 wait_type;
3186
3187 if (hmc_fn_id >= I40IW_MAX_VF_FPM_ID ||
3188 (dev->hmc_fn_id != hmc_fn_id && hmc_fn_id < I40IW_FIRST_VF_FPM_ID))
3189 return I40IW_ERR_INVALID_HMCFN_ID;
3190
3191 if (hmc_fn_id == dev->hmc_fn_id) {
3192 hmc_info = dev->hmc_info;
3193 } else {
3194 hmc_info = i40iw_vf_hmcinfo_from_fpm(dev, hmc_fn_id);
3195 poll_registers = false;
3196 }
3197 if (!hmc_info)
3198 return I40IW_ERR_BAD_PTR;
3199
3200 obj_info = hmc_info->hmc_obj;
3201 buf = dev->fpm_commit_buf;
3202
3203 /* copy cnt values in commit buf */
3204 for (i = I40IW_HMC_IW_QP, j = 0; i <= I40IW_HMC_IW_PBLE;
3205 i++, j += 8)
3206 set_64bit_val(buf, j, (u64)obj_info[i].cnt);
3207
3208 set_64bit_val(buf, 40, 0); /* APBVT rsvd */
3209
3210 commit_fpm_mem.pa = dev->fpm_commit_buf_pa;
3211 commit_fpm_mem.va = dev->fpm_commit_buf;
3212 wait_type = poll_registers ? (u8)I40IW_CQP_WAIT_POLL_REGS :
3213 (u8)I40IW_CQP_WAIT_POLL_CQ;
3214 ret_code = i40iw_sc_commit_fpm_values(
3215 dev->cqp,
3216 0,
3217 hmc_info->hmc_fn_id,
3218 &commit_fpm_mem,
3219 true,
3220 wait_type);
3221
3222 /* parse the fpm_commit_buf and fill hmc obj info */
3223 if (!ret_code)
3224 ret_code = i40iw_sc_parse_fpm_commit_buf(dev->fpm_commit_buf, hmc_info->hmc_obj);
3225
3226 i40iw_debug_buf(dev, I40IW_DEBUG_HMC, "COMMIT FPM BUFFER",
3227 commit_fpm_mem.va, I40IW_COMMIT_FPM_BUF_SIZE);
3228
3229 return ret_code;
3230}
3231
3232/**
3233 * cqp_sds_wqe_fill - fill cqp wqe doe sd
3234 * @cqp: struct for cqp hw
3235 * @info; sd info for wqe
3236 * @scratch: u64 saved to be used during cqp completion
3237 */
3238static enum i40iw_status_code cqp_sds_wqe_fill(struct i40iw_sc_cqp *cqp,
3239 struct i40iw_update_sds_info *info,
3240 u64 scratch)
3241{
3242 u64 data;
3243 u64 header;
3244 u64 *wqe;
3245 int mem_entries, wqe_entries;
3246 struct i40iw_dma_mem *sdbuf = &cqp->sdbuf;
3247
3248 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3249 if (!wqe)
3250 return I40IW_ERR_RING_FULL;
3251
3252 I40IW_CQP_INIT_WQE(wqe);
3253 wqe_entries = (info->cnt > 3) ? 3 : info->cnt;
3254 mem_entries = info->cnt - wqe_entries;
3255
3256 header = LS_64(I40IW_CQP_OP_UPDATE_PE_SDS, I40IW_CQPSQ_OPCODE) |
3257 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
3258 LS_64(mem_entries, I40IW_CQPSQ_UPESD_ENTRY_COUNT);
3259
3260 if (mem_entries) {
3261 memcpy(sdbuf->va, &info->entry[3], (mem_entries << 4));
3262 data = sdbuf->pa;
3263 } else {
3264 data = 0;
3265 }
3266 data |= LS_64(info->hmc_fn_id, I40IW_CQPSQ_UPESD_HMCFNID);
3267
3268 set_64bit_val(wqe, 16, data);
3269
3270 switch (wqe_entries) {
3271 case 3:
3272 set_64bit_val(wqe, 48,
3273 (LS_64(info->entry[2].cmd, I40IW_CQPSQ_UPESD_SDCMD) |
3274 LS_64(1, I40IW_CQPSQ_UPESD_ENTRY_VALID)));
3275
3276 set_64bit_val(wqe, 56, info->entry[2].data);
3277 /* fallthrough */
3278 case 2:
3279 set_64bit_val(wqe, 32,
3280 (LS_64(info->entry[1].cmd, I40IW_CQPSQ_UPESD_SDCMD) |
3281 LS_64(1, I40IW_CQPSQ_UPESD_ENTRY_VALID)));
3282
3283 set_64bit_val(wqe, 40, info->entry[1].data);
3284 /* fallthrough */
3285 case 1:
3286 set_64bit_val(wqe, 0,
3287 LS_64(info->entry[0].cmd, I40IW_CQPSQ_UPESD_SDCMD));
3288
3289 set_64bit_val(wqe, 8, info->entry[0].data);
3290 break;
3291 default:
3292 break;
3293 }
3294
3295 i40iw_insert_wqe_hdr(wqe, header);
3296
3297 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "UPDATE_PE_SDS WQE",
3298 wqe, I40IW_CQP_WQE_SIZE * 8);
3299 return 0;
3300}
3301
3302/**
3303 * i40iw_update_pe_sds - cqp wqe for sd
3304 * @dev: ptr to i40iw_dev struct
3305 * @info: sd info for sd's
3306 * @scratch: u64 saved to be used during cqp completion
3307 */
3308static enum i40iw_status_code i40iw_update_pe_sds(struct i40iw_sc_dev *dev,
3309 struct i40iw_update_sds_info *info,
3310 u64 scratch)
3311{
3312 struct i40iw_sc_cqp *cqp = dev->cqp;
3313 enum i40iw_status_code ret_code;
3314
3315 ret_code = cqp_sds_wqe_fill(cqp, info, scratch);
3316 if (!ret_code)
3317 i40iw_sc_cqp_post_sq(cqp);
3318
3319 return ret_code;
3320}
3321
3322/**
3323 * i40iw_update_sds_noccq - update sd before ccq created
3324 * @dev: sc device struct
3325 * @info: sd info for sd's
3326 */
3327enum i40iw_status_code i40iw_update_sds_noccq(struct i40iw_sc_dev *dev,
3328 struct i40iw_update_sds_info *info)
3329{
3330 u32 error, val, tail;
3331 struct i40iw_sc_cqp *cqp = dev->cqp;
3332 enum i40iw_status_code ret_code;
3333
3334 ret_code = cqp_sds_wqe_fill(cqp, info, 0);
3335 if (ret_code)
3336 return ret_code;
3337 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
3338 if (error)
3339 return I40IW_ERR_CQP_COMPL_ERROR;
3340
3341 i40iw_sc_cqp_post_sq(cqp);
3342 ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
3343
3344 return ret_code;
3345}
3346
3347/**
3348 * i40iw_sc_suspend_qp - suspend qp for param change
3349 * @cqp: struct for cqp hw
3350 * @qp: sc qp struct
3351 * @scratch: u64 saved to be used during cqp completion
3352 */
3353enum i40iw_status_code i40iw_sc_suspend_qp(struct i40iw_sc_cqp *cqp,
3354 struct i40iw_sc_qp *qp,
3355 u64 scratch)
3356{
3357 u64 header;
3358 u64 *wqe;
3359
3360 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3361 if (!wqe)
3362 return I40IW_ERR_RING_FULL;
3363 header = LS_64(qp->qp_uk.qp_id, I40IW_CQPSQ_SUSPENDQP_QPID) |
3364 LS_64(I40IW_CQP_OP_SUSPEND_QP, I40IW_CQPSQ_OPCODE) |
3365 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3366
3367 i40iw_insert_wqe_hdr(wqe, header);
3368
3369 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "SUSPEND_QP WQE",
3370 wqe, I40IW_CQP_WQE_SIZE * 8);
3371
3372 i40iw_sc_cqp_post_sq(cqp);
3373 return 0;
3374}
3375
3376/**
3377 * i40iw_sc_resume_qp - resume qp after suspend
3378 * @cqp: struct for cqp hw
3379 * @qp: sc qp struct
3380 * @scratch: u64 saved to be used during cqp completion
3381 */
3382enum i40iw_status_code i40iw_sc_resume_qp(struct i40iw_sc_cqp *cqp,
3383 struct i40iw_sc_qp *qp,
3384 u64 scratch)
3385{
3386 u64 header;
3387 u64 *wqe;
3388
3389 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3390 if (!wqe)
3391 return I40IW_ERR_RING_FULL;
3392 set_64bit_val(wqe,
3393 16,
3394 LS_64(qp->qs_handle, I40IW_CQPSQ_RESUMEQP_QSHANDLE));
3395
3396 header = LS_64(qp->qp_uk.qp_id, I40IW_CQPSQ_RESUMEQP_QPID) |
3397 LS_64(I40IW_CQP_OP_RESUME_QP, I40IW_CQPSQ_OPCODE) |
3398 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3399
3400 i40iw_insert_wqe_hdr(wqe, header);
3401
3402 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "RESUME_QP WQE",
3403 wqe, I40IW_CQP_WQE_SIZE * 8);
3404
3405 i40iw_sc_cqp_post_sq(cqp);
3406 return 0;
3407}
3408
3409/**
3410 * i40iw_sc_static_hmc_pages_allocated - cqp wqe to allocate hmc pages
3411 * @cqp: struct for cqp hw
3412 * @scratch: u64 saved to be used during cqp completion
3413 * @hmc_fn_id: hmc function id
3414 * @post_sq: flag for cqp db to ring
3415 * @poll_registers: flag to poll register for cqp completion
3416 */
3417enum i40iw_status_code i40iw_sc_static_hmc_pages_allocated(
3418 struct i40iw_sc_cqp *cqp,
3419 u64 scratch,
3420 u8 hmc_fn_id,
3421 bool post_sq,
3422 bool poll_registers)
3423{
3424 u64 header;
3425 u64 *wqe;
3426 u32 tail, val, error;
3427 enum i40iw_status_code ret_code = 0;
3428
3429 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3430 if (!wqe)
3431 return I40IW_ERR_RING_FULL;
3432 set_64bit_val(wqe,
3433 16,
3434 LS_64(hmc_fn_id, I40IW_SHMC_PAGE_ALLOCATED_HMC_FN_ID));
3435
3436 header = LS_64(I40IW_CQP_OP_SHMC_PAGES_ALLOCATED, I40IW_CQPSQ_OPCODE) |
3437 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3438
3439 i40iw_insert_wqe_hdr(wqe, header);
3440
3441 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "SHMC_PAGES_ALLOCATED WQE",
3442 wqe, I40IW_CQP_WQE_SIZE * 8);
3443 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
3444 if (error) {
3445 ret_code = I40IW_ERR_CQP_COMPL_ERROR;
3446 return ret_code;
3447 }
3448 if (post_sq) {
3449 i40iw_sc_cqp_post_sq(cqp);
3450 if (poll_registers)
3451 /* check for cqp sq tail update */
3452 ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000);
3453 else
3454 ret_code = i40iw_sc_poll_for_cqp_op_done(cqp,
3455 I40IW_CQP_OP_SHMC_PAGES_ALLOCATED,
3456 NULL);
3457 }
3458
3459 return ret_code;
3460}
3461
3462/**
3463 * i40iw_ring_full - check if cqp ring is full
3464 * @cqp: struct for cqp hw
3465 */
3466static bool i40iw_ring_full(struct i40iw_sc_cqp *cqp)
3467{
3468 return I40IW_RING_FULL_ERR(cqp->sq_ring);
3469}
3470
3471/**
3472 * i40iw_config_fpm_values - configure HMC objects
3473 * @dev: sc device struct
3474 * @qp_count: desired qp count
3475 */
3476enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_count)
3477{
3478 struct i40iw_virt_mem virt_mem;
3479 u32 i, mem_size;
3480 u32 qpwantedoriginal, qpwanted, mrwanted, pblewanted;
3481 u32 powerof2;
3482 u64 sd_needed, bytes_needed;
3483 u32 loop_count = 0;
3484
3485 struct i40iw_hmc_info *hmc_info;
3486 struct i40iw_hmc_fpm_misc *hmc_fpm_misc;
3487 enum i40iw_status_code ret_code = 0;
3488
3489 hmc_info = dev->hmc_info;
3490 hmc_fpm_misc = &dev->hmc_fpm_misc;
3491
3492 ret_code = i40iw_sc_init_iw_hmc(dev, dev->hmc_fn_id);
3493 if (ret_code) {
3494 i40iw_debug(dev, I40IW_DEBUG_HMC,
3495 "i40iw_sc_init_iw_hmc returned error_code = %d\n",
3496 ret_code);
3497 return ret_code;
3498 }
3499
3500 bytes_needed = 0;
3501 for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_MAX; i++) {
3502 hmc_info->hmc_obj[i].cnt = hmc_info->hmc_obj[i].max_cnt;
3503 bytes_needed +=
3504 (hmc_info->hmc_obj[i].max_cnt) * (hmc_info->hmc_obj[i].size);
3505 i40iw_debug(dev, I40IW_DEBUG_HMC,
3506 "%s i[%04d] max_cnt[0x%04X] size[0x%04llx]\n",
3507 __func__, i, hmc_info->hmc_obj[i].max_cnt,
3508 hmc_info->hmc_obj[i].size);
3509 }
3510 sd_needed = (bytes_needed / I40IW_HMC_DIRECT_BP_SIZE) + 1; /* round up */
3511 i40iw_debug(dev, I40IW_DEBUG_HMC,
3512 "%s: FW initial max sd_count[%08lld] first_sd_index[%04d]\n",
3513 __func__, sd_needed, hmc_info->first_sd_index);
3514 i40iw_debug(dev, I40IW_DEBUG_HMC,
3515 "%s: bytes_needed=0x%llx sd count %d where max sd is %d\n",
3516 __func__, bytes_needed, hmc_info->sd_table.sd_cnt,
3517 hmc_fpm_misc->max_sds);
3518
3519 qpwanted = min(qp_count, hmc_info->hmc_obj[I40IW_HMC_IW_QP].max_cnt);
3520 qpwantedoriginal = qpwanted;
3521 mrwanted = hmc_info->hmc_obj[I40IW_HMC_IW_MR].max_cnt;
3522 pblewanted = hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].max_cnt;
3523
3524 i40iw_debug(dev, I40IW_DEBUG_HMC,
3525 "req_qp=%d max_sd=%d, max_qp = %d, max_cq=%d, max_mr=%d, max_pble=%d\n",
3526 qp_count, hmc_fpm_misc->max_sds,
3527 hmc_info->hmc_obj[I40IW_HMC_IW_QP].max_cnt,
3528 hmc_info->hmc_obj[I40IW_HMC_IW_CQ].max_cnt,
3529 hmc_info->hmc_obj[I40IW_HMC_IW_MR].max_cnt,
3530 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].max_cnt);
3531
3532 do {
3533 ++loop_count;
3534 hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt = qpwanted;
3535 hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt =
3536 min(2 * qpwanted, hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt);
3537 hmc_info->hmc_obj[I40IW_HMC_IW_SRQ].cnt = 0x00; /* Reserved */
3538 hmc_info->hmc_obj[I40IW_HMC_IW_HTE].cnt =
3539 qpwanted * hmc_fpm_misc->ht_multiplier;
3540 hmc_info->hmc_obj[I40IW_HMC_IW_ARP].cnt =
3541 hmc_info->hmc_obj[I40IW_HMC_IW_ARP].max_cnt;
3542 hmc_info->hmc_obj[I40IW_HMC_IW_APBVT_ENTRY].cnt = 1;
3543 hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt = mrwanted;
3544
3545 hmc_info->hmc_obj[I40IW_HMC_IW_XF].cnt = I40IW_MAX_WQ_ENTRIES * qpwanted;
3546 hmc_info->hmc_obj[I40IW_HMC_IW_Q1].cnt = 4 * I40IW_MAX_IRD_SIZE * qpwanted;
3547 hmc_info->hmc_obj[I40IW_HMC_IW_XFFL].cnt =
3548 hmc_info->hmc_obj[I40IW_HMC_IW_XF].cnt / hmc_fpm_misc->xf_block_size;
3549 hmc_info->hmc_obj[I40IW_HMC_IW_Q1FL].cnt =
3550 hmc_info->hmc_obj[I40IW_HMC_IW_Q1].cnt / hmc_fpm_misc->q1_block_size;
3551 hmc_info->hmc_obj[I40IW_HMC_IW_TIMER].cnt =
3552 ((qpwanted) / 512 + 1) * hmc_fpm_misc->timer_bucket;
3553 hmc_info->hmc_obj[I40IW_HMC_IW_FSIMC].cnt = 0x00;
3554 hmc_info->hmc_obj[I40IW_HMC_IW_FSIAV].cnt = 0x00;
3555 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt = pblewanted;
3556
3557 /* How much memory is needed for all the objects. */
3558 bytes_needed = 0;
3559 for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_MAX; i++)
3560 bytes_needed +=
3561 (hmc_info->hmc_obj[i].cnt) * (hmc_info->hmc_obj[i].size);
3562 sd_needed = (bytes_needed / I40IW_HMC_DIRECT_BP_SIZE) + 1;
3563 if ((loop_count > 1000) ||
3564 ((!(loop_count % 10)) &&
3565 (qpwanted > qpwantedoriginal * 2 / 3))) {
3566 if (qpwanted > FPM_MULTIPLIER) {
3567 qpwanted -= FPM_MULTIPLIER;
3568 powerof2 = 1;
3569 while (powerof2 < qpwanted)
3570 powerof2 *= 2;
3571 powerof2 /= 2;
3572 qpwanted = powerof2;
3573 } else {
3574 qpwanted /= 2;
3575 }
3576 }
3577 if (mrwanted > FPM_MULTIPLIER * 10)
3578 mrwanted -= FPM_MULTIPLIER * 10;
3579 if (pblewanted > FPM_MULTIPLIER * 1000)
3580 pblewanted -= FPM_MULTIPLIER * 1000;
3581 } while (sd_needed > hmc_fpm_misc->max_sds && loop_count < 2000);
3582
3583 bytes_needed = 0;
3584 for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_MAX; i++) {
3585 bytes_needed += (hmc_info->hmc_obj[i].cnt) * (hmc_info->hmc_obj[i].size);
3586 i40iw_debug(dev, I40IW_DEBUG_HMC,
3587 "%s i[%04d] cnt[0x%04x] size[0x%04llx]\n",
3588 __func__, i, hmc_info->hmc_obj[i].cnt,
3589 hmc_info->hmc_obj[i].size);
3590 }
3591 sd_needed = (bytes_needed / I40IW_HMC_DIRECT_BP_SIZE) + 1; /* round up not truncate. */
3592
3593 i40iw_debug(dev, I40IW_DEBUG_HMC,
3594 "loop_cnt=%d, sd_needed=%lld, qpcnt = %d, cqcnt=%d, mrcnt=%d, pblecnt=%d\n",
3595 loop_count, sd_needed,
3596 hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt,
3597 hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt,
3598 hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt,
3599 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt);
3600
3601 ret_code = i40iw_sc_configure_iw_fpm(dev, dev->hmc_fn_id);
3602 if (ret_code) {
3603 i40iw_debug(dev, I40IW_DEBUG_HMC,
3604 "configure_iw_fpm returned error_code[x%08X]\n",
3605 i40iw_rd32(dev->hw, dev->is_pf ? I40E_PFPE_CQPERRCODES : I40E_VFPE_CQPERRCODES1));
3606 return ret_code;
3607 }
3608
3609 hmc_info->sd_table.sd_cnt = (u32)sd_needed;
3610
3611 mem_size = sizeof(struct i40iw_hmc_sd_entry) *
3612 (hmc_info->sd_table.sd_cnt + hmc_info->first_sd_index + 1);
3613 ret_code = i40iw_allocate_virt_mem(dev->hw, &virt_mem, mem_size);
3614 if (ret_code) {
3615 i40iw_debug(dev, I40IW_DEBUG_HMC,
3616 "%s: failed to allocate memory for sd_entry buffer\n",
3617 __func__);
3618 return ret_code;
3619 }
3620 hmc_info->sd_table.sd_entry = virt_mem.va;
3621
3622 return ret_code;
3623}
3624
3625/**
3626 * i40iw_exec_cqp_cmd - execute cqp cmd when wqe are available
3627 * @dev: rdma device
3628 * @pcmdinfo: cqp command info
3629 */
3630static enum i40iw_status_code i40iw_exec_cqp_cmd(struct i40iw_sc_dev *dev,
3631 struct cqp_commands_info *pcmdinfo)
3632{
3633 enum i40iw_status_code status;
3634 struct i40iw_dma_mem values_mem;
3635
3636 dev->cqp_cmd_stats[pcmdinfo->cqp_cmd]++;
3637 switch (pcmdinfo->cqp_cmd) {
3638 case OP_DELETE_LOCAL_MAC_IPADDR_ENTRY:
3639 status = i40iw_sc_del_local_mac_ipaddr_entry(
3640 pcmdinfo->in.u.del_local_mac_ipaddr_entry.cqp,
3641 pcmdinfo->in.u.del_local_mac_ipaddr_entry.scratch,
3642 pcmdinfo->in.u.del_local_mac_ipaddr_entry.entry_idx,
3643 pcmdinfo->in.u.del_local_mac_ipaddr_entry.ignore_ref_count,
3644 pcmdinfo->post_sq);
3645 break;
3646 case OP_CEQ_DESTROY:
3647 status = i40iw_sc_ceq_destroy(pcmdinfo->in.u.ceq_destroy.ceq,
3648 pcmdinfo->in.u.ceq_destroy.scratch,
3649 pcmdinfo->post_sq);
3650 break;
3651 case OP_AEQ_DESTROY:
3652 status = i40iw_sc_aeq_destroy(pcmdinfo->in.u.aeq_destroy.aeq,
3653 pcmdinfo->in.u.aeq_destroy.scratch,
3654 pcmdinfo->post_sq);
3655
3656 break;
3657 case OP_DELETE_ARP_CACHE_ENTRY:
3658 status = i40iw_sc_del_arp_cache_entry(
3659 pcmdinfo->in.u.del_arp_cache_entry.cqp,
3660 pcmdinfo->in.u.del_arp_cache_entry.scratch,
3661 pcmdinfo->in.u.del_arp_cache_entry.arp_index,
3662 pcmdinfo->post_sq);
3663 break;
3664 case OP_MANAGE_APBVT_ENTRY:
3665 status = i40iw_sc_manage_apbvt_entry(
3666 pcmdinfo->in.u.manage_apbvt_entry.cqp,
3667 &pcmdinfo->in.u.manage_apbvt_entry.info,
3668 pcmdinfo->in.u.manage_apbvt_entry.scratch,
3669 pcmdinfo->post_sq);
3670 break;
3671 case OP_CEQ_CREATE:
3672 status = i40iw_sc_ceq_create(pcmdinfo->in.u.ceq_create.ceq,
3673 pcmdinfo->in.u.ceq_create.scratch,
3674 pcmdinfo->post_sq);
3675 break;
3676 case OP_AEQ_CREATE:
3677 status = i40iw_sc_aeq_create(pcmdinfo->in.u.aeq_create.aeq,
3678 pcmdinfo->in.u.aeq_create.scratch,
3679 pcmdinfo->post_sq);
3680 break;
3681 case OP_ALLOC_LOCAL_MAC_IPADDR_ENTRY:
3682 status = i40iw_sc_alloc_local_mac_ipaddr_entry(
3683 pcmdinfo->in.u.alloc_local_mac_ipaddr_entry.cqp,
3684 pcmdinfo->in.u.alloc_local_mac_ipaddr_entry.scratch,
3685 pcmdinfo->post_sq);
3686 break;
3687 case OP_ADD_LOCAL_MAC_IPADDR_ENTRY:
3688 status = i40iw_sc_add_local_mac_ipaddr_entry(
3689 pcmdinfo->in.u.add_local_mac_ipaddr_entry.cqp,
3690 &pcmdinfo->in.u.add_local_mac_ipaddr_entry.info,
3691 pcmdinfo->in.u.add_local_mac_ipaddr_entry.scratch,
3692 pcmdinfo->post_sq);
3693 break;
3694 case OP_MANAGE_QHASH_TABLE_ENTRY:
3695 status = i40iw_sc_manage_qhash_table_entry(
3696 pcmdinfo->in.u.manage_qhash_table_entry.cqp,
3697 &pcmdinfo->in.u.manage_qhash_table_entry.info,
3698 pcmdinfo->in.u.manage_qhash_table_entry.scratch,
3699 pcmdinfo->post_sq);
3700
3701 break;
3702 case OP_QP_MODIFY:
3703 status = i40iw_sc_qp_modify(
3704 pcmdinfo->in.u.qp_modify.qp,
3705 &pcmdinfo->in.u.qp_modify.info,
3706 pcmdinfo->in.u.qp_modify.scratch,
3707 pcmdinfo->post_sq);
3708
3709 break;
3710 case OP_QP_UPLOAD_CONTEXT:
3711 status = i40iw_sc_qp_upload_context(
3712 pcmdinfo->in.u.qp_upload_context.dev,
3713 &pcmdinfo->in.u.qp_upload_context.info,
3714 pcmdinfo->in.u.qp_upload_context.scratch,
3715 pcmdinfo->post_sq);
3716
3717 break;
3718 case OP_CQ_CREATE:
3719 status = i40iw_sc_cq_create(
3720 pcmdinfo->in.u.cq_create.cq,
3721 pcmdinfo->in.u.cq_create.scratch,
3722 pcmdinfo->in.u.cq_create.check_overflow,
3723 pcmdinfo->post_sq);
3724 break;
3725 case OP_CQ_DESTROY:
3726 status = i40iw_sc_cq_destroy(
3727 pcmdinfo->in.u.cq_destroy.cq,
3728 pcmdinfo->in.u.cq_destroy.scratch,
3729 pcmdinfo->post_sq);
3730
3731 break;
3732 case OP_QP_CREATE:
3733 status = i40iw_sc_qp_create(
3734 pcmdinfo->in.u.qp_create.qp,
3735 &pcmdinfo->in.u.qp_create.info,
3736 pcmdinfo->in.u.qp_create.scratch,
3737 pcmdinfo->post_sq);
3738 break;
3739 case OP_QP_DESTROY:
3740 status = i40iw_sc_qp_destroy(
3741 pcmdinfo->in.u.qp_destroy.qp,
3742 pcmdinfo->in.u.qp_destroy.scratch,
3743 pcmdinfo->in.u.qp_destroy.remove_hash_idx,
3744 pcmdinfo->in.u.qp_destroy.
3745 ignore_mw_bnd,
3746 pcmdinfo->post_sq);
3747
3748 break;
3749 case OP_ALLOC_STAG:
3750 status = i40iw_sc_alloc_stag(
3751 pcmdinfo->in.u.alloc_stag.dev,
3752 &pcmdinfo->in.u.alloc_stag.info,
3753 pcmdinfo->in.u.alloc_stag.scratch,
3754 pcmdinfo->post_sq);
3755 break;
3756 case OP_MR_REG_NON_SHARED:
3757 status = i40iw_sc_mr_reg_non_shared(
3758 pcmdinfo->in.u.mr_reg_non_shared.dev,
3759 &pcmdinfo->in.u.mr_reg_non_shared.info,
3760 pcmdinfo->in.u.mr_reg_non_shared.scratch,
3761 pcmdinfo->post_sq);
3762
3763 break;
3764 case OP_DEALLOC_STAG:
3765 status = i40iw_sc_dealloc_stag(
3766 pcmdinfo->in.u.dealloc_stag.dev,
3767 &pcmdinfo->in.u.dealloc_stag.info,
3768 pcmdinfo->in.u.dealloc_stag.scratch,
3769 pcmdinfo->post_sq);
3770
3771 break;
3772 case OP_MW_ALLOC:
3773 status = i40iw_sc_mw_alloc(
3774 pcmdinfo->in.u.mw_alloc.dev,
3775 pcmdinfo->in.u.mw_alloc.scratch,
3776 pcmdinfo->in.u.mw_alloc.mw_stag_index,
3777 pcmdinfo->in.u.mw_alloc.pd_id,
3778 pcmdinfo->post_sq);
3779
3780 break;
3781 case OP_QP_FLUSH_WQES:
3782 status = i40iw_sc_qp_flush_wqes(
3783 pcmdinfo->in.u.qp_flush_wqes.qp,
3784 &pcmdinfo->in.u.qp_flush_wqes.info,
3785 pcmdinfo->in.u.qp_flush_wqes.
3786 scratch, pcmdinfo->post_sq);
3787 break;
3788 case OP_ADD_ARP_CACHE_ENTRY:
3789 status = i40iw_sc_add_arp_cache_entry(
3790 pcmdinfo->in.u.add_arp_cache_entry.cqp,
3791 &pcmdinfo->in.u.add_arp_cache_entry.info,
3792 pcmdinfo->in.u.add_arp_cache_entry.scratch,
3793 pcmdinfo->post_sq);
3794 break;
3795 case OP_MANAGE_PUSH_PAGE:
3796 status = i40iw_sc_manage_push_page(
3797 pcmdinfo->in.u.manage_push_page.cqp,
3798 &pcmdinfo->in.u.manage_push_page.info,
3799 pcmdinfo->in.u.manage_push_page.scratch,
3800 pcmdinfo->post_sq);
3801 break;
3802 case OP_UPDATE_PE_SDS:
3803 /* case I40IW_CQP_OP_UPDATE_PE_SDS */
3804 status = i40iw_update_pe_sds(
3805 pcmdinfo->in.u.update_pe_sds.dev,
3806 &pcmdinfo->in.u.update_pe_sds.info,
3807 pcmdinfo->in.u.update_pe_sds.
3808 scratch);
3809
3810 break;
3811 case OP_MANAGE_HMC_PM_FUNC_TABLE:
3812 status = i40iw_sc_manage_hmc_pm_func_table(
3813 pcmdinfo->in.u.manage_hmc_pm.dev->cqp,
3814 pcmdinfo->in.u.manage_hmc_pm.scratch,
3815 (u8)pcmdinfo->in.u.manage_hmc_pm.info.vf_id,
3816 pcmdinfo->in.u.manage_hmc_pm.info.free_fcn,
3817 true);
3818 break;
3819 case OP_SUSPEND:
3820 status = i40iw_sc_suspend_qp(
3821 pcmdinfo->in.u.suspend_resume.cqp,
3822 pcmdinfo->in.u.suspend_resume.qp,
3823 pcmdinfo->in.u.suspend_resume.scratch);
3824 break;
3825 case OP_RESUME:
3826 status = i40iw_sc_resume_qp(
3827 pcmdinfo->in.u.suspend_resume.cqp,
3828 pcmdinfo->in.u.suspend_resume.qp,
3829 pcmdinfo->in.u.suspend_resume.scratch);
3830 break;
3831 case OP_MANAGE_VF_PBLE_BP:
3832 status = i40iw_manage_vf_pble_bp(
3833 pcmdinfo->in.u.manage_vf_pble_bp.cqp,
3834 &pcmdinfo->in.u.manage_vf_pble_bp.info,
3835 pcmdinfo->in.u.manage_vf_pble_bp.scratch, true);
3836 break;
3837 case OP_QUERY_FPM_VALUES:
3838 values_mem.pa = pcmdinfo->in.u.query_fpm_values.fpm_values_pa;
3839 values_mem.va = pcmdinfo->in.u.query_fpm_values.fpm_values_va;
3840 status = i40iw_sc_query_fpm_values(
3841 pcmdinfo->in.u.query_fpm_values.cqp,
3842 pcmdinfo->in.u.query_fpm_values.scratch,
3843 pcmdinfo->in.u.query_fpm_values.hmc_fn_id,
3844 &values_mem, true, I40IW_CQP_WAIT_EVENT);
3845 break;
3846 case OP_COMMIT_FPM_VALUES:
3847 values_mem.pa = pcmdinfo->in.u.commit_fpm_values.fpm_values_pa;
3848 values_mem.va = pcmdinfo->in.u.commit_fpm_values.fpm_values_va;
3849 status = i40iw_sc_commit_fpm_values(
3850 pcmdinfo->in.u.commit_fpm_values.cqp,
3851 pcmdinfo->in.u.commit_fpm_values.scratch,
3852 pcmdinfo->in.u.commit_fpm_values.hmc_fn_id,
3853 &values_mem,
3854 true,
3855 I40IW_CQP_WAIT_EVENT);
3856 break;
3857 default:
3858 status = I40IW_NOT_SUPPORTED;
3859 break;
3860 }
3861
3862 return status;
3863}
3864
3865/**
3866 * i40iw_process_cqp_cmd - process all cqp commands
3867 * @dev: sc device struct
3868 * @pcmdinfo: cqp command info
3869 */
3870enum i40iw_status_code i40iw_process_cqp_cmd(struct i40iw_sc_dev *dev,
3871 struct cqp_commands_info *pcmdinfo)
3872{
3873 enum i40iw_status_code status = 0;
3874 unsigned long flags;
3875
3876 spin_lock_irqsave(&dev->cqp_lock, flags);
3877 if (list_empty(&dev->cqp_cmd_head) && !i40iw_ring_full(dev->cqp))
3878 status = i40iw_exec_cqp_cmd(dev, pcmdinfo);
3879 else
3880 list_add_tail(&pcmdinfo->cqp_cmd_entry, &dev->cqp_cmd_head);
3881 spin_unlock_irqrestore(&dev->cqp_lock, flags);
3882 return status;
3883}
3884
3885/**
3886 * i40iw_process_bh - called from tasklet for cqp list
3887 * @dev: sc device struct
3888 */
3889enum i40iw_status_code i40iw_process_bh(struct i40iw_sc_dev *dev)
3890{
3891 enum i40iw_status_code status = 0;
3892 struct cqp_commands_info *pcmdinfo;
3893 unsigned long flags;
3894
3895 spin_lock_irqsave(&dev->cqp_lock, flags);
3896 while (!list_empty(&dev->cqp_cmd_head) && !i40iw_ring_full(dev->cqp)) {
3897 pcmdinfo = (struct cqp_commands_info *)i40iw_remove_head(&dev->cqp_cmd_head);
3898
3899 status = i40iw_exec_cqp_cmd(dev, pcmdinfo);
3900 if (status)
3901 break;
3902 }
3903 spin_unlock_irqrestore(&dev->cqp_lock, flags);
3904 return status;
3905}
3906
3907/**
3908 * i40iw_iwarp_opcode - determine if incoming is rdma layer
3909 * @info: aeq info for the packet
3910 * @pkt: packet for error
3911 */
3912static u32 i40iw_iwarp_opcode(struct i40iw_aeqe_info *info, u8 *pkt)
3913{
3914 u16 *mpa;
3915 u32 opcode = 0xffffffff;
3916
3917 if (info->q2_data_written) {
3918 mpa = (u16 *)pkt;
3919 opcode = ntohs(mpa[1]) & 0xf;
3920 }
3921 return opcode;
3922}
3923
3924/**
3925 * i40iw_locate_mpa - return pointer to mpa in the pkt
3926 * @pkt: packet with data
3927 */
3928static u8 *i40iw_locate_mpa(u8 *pkt)
3929{
3930 /* skip over ethernet header */
3931 pkt += I40IW_MAC_HLEN;
3932
3933 /* Skip over IP and TCP headers */
3934 pkt += 4 * (pkt[0] & 0x0f);
3935 pkt += 4 * ((pkt[12] >> 4) & 0x0f);
3936 return pkt;
3937}
3938
3939/**
3940 * i40iw_setup_termhdr - termhdr for terminate pkt
3941 * @qp: sc qp ptr for pkt
3942 * @hdr: term hdr
3943 * @opcode: flush opcode for termhdr
3944 * @layer_etype: error layer + error type
3945 * @err: error cod ein the header
3946 */
3947static void i40iw_setup_termhdr(struct i40iw_sc_qp *qp,
3948 struct i40iw_terminate_hdr *hdr,
3949 enum i40iw_flush_opcode opcode,
3950 u8 layer_etype,
3951 u8 err)
3952{
3953 qp->flush_code = opcode;
3954 hdr->layer_etype = layer_etype;
3955 hdr->error_code = err;
3956}
3957
3958/**
3959 * i40iw_bld_terminate_hdr - build terminate message header
3960 * @qp: qp associated with received terminate AE
3961 * @info: the struct contiaing AE information
3962 */
3963static int i40iw_bld_terminate_hdr(struct i40iw_sc_qp *qp,
3964 struct i40iw_aeqe_info *info)
3965{
3966 u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
3967 u16 ddp_seg_len;
3968 int copy_len = 0;
3969 u8 is_tagged = 0;
3970 enum i40iw_flush_opcode flush_code = FLUSH_INVALID;
3971 u32 opcode;
3972 struct i40iw_terminate_hdr *termhdr;
3973
3974 termhdr = (struct i40iw_terminate_hdr *)qp->q2_buf;
3975 memset(termhdr, 0, Q2_BAD_FRAME_OFFSET);
3976
3977 if (info->q2_data_written) {
3978 /* Use data from offending packet to fill in ddp & rdma hdrs */
3979 pkt = i40iw_locate_mpa(pkt);
3980 ddp_seg_len = ntohs(*(u16 *)pkt);
3981 if (ddp_seg_len) {
3982 copy_len = 2;
3983 termhdr->hdrct = DDP_LEN_FLAG;
3984 if (pkt[2] & 0x80) {
3985 is_tagged = 1;
3986 if (ddp_seg_len >= TERM_DDP_LEN_TAGGED) {
3987 copy_len += TERM_DDP_LEN_TAGGED;
3988 termhdr->hdrct |= DDP_HDR_FLAG;
3989 }
3990 } else {
3991 if (ddp_seg_len >= TERM_DDP_LEN_UNTAGGED) {
3992 copy_len += TERM_DDP_LEN_UNTAGGED;
3993 termhdr->hdrct |= DDP_HDR_FLAG;
3994 }
3995
3996 if (ddp_seg_len >= (TERM_DDP_LEN_UNTAGGED + TERM_RDMA_LEN)) {
3997 if ((pkt[3] & RDMA_OPCODE_MASK) == RDMA_READ_REQ_OPCODE) {
3998 copy_len += TERM_RDMA_LEN;
3999 termhdr->hdrct |= RDMA_HDR_FLAG;
4000 }
4001 }
4002 }
4003 }
4004 }
4005
4006 opcode = i40iw_iwarp_opcode(info, pkt);
4007
4008 switch (info->ae_id) {
4009 case I40IW_AE_AMP_UNALLOCATED_STAG:
4010 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4011 if (opcode == I40IW_OP_TYPE_RDMA_WRITE)
4012 i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
4013 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_INV_STAG);
4014 else
4015 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4016 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_STAG);
4017 break;
4018 case I40IW_AE_AMP_BOUNDS_VIOLATION:
4019 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4020 if (info->q2_data_written)
4021 i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
4022 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_BOUNDS);
4023 else
4024 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4025 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_BOUNDS);
4026 break;
4027 case I40IW_AE_AMP_BAD_PD:
4028 switch (opcode) {
4029 case I40IW_OP_TYPE_RDMA_WRITE:
4030 i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
4031 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_UNASSOC_STAG);
4032 break;
4033 case I40IW_OP_TYPE_SEND_INV:
4034 case I40IW_OP_TYPE_SEND_SOL_INV:
4035 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4036 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_CANT_INV_STAG);
4037 break;
4038 default:
4039 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4040 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_UNASSOC_STAG);
4041 }
4042 break;
4043 case I40IW_AE_AMP_INVALID_STAG:
4044 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4045 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4046 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_STAG);
4047 break;
4048 case I40IW_AE_AMP_BAD_QP:
4049 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_QP_OP_ERR,
4050 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_QN);
4051 break;
4052 case I40IW_AE_AMP_BAD_STAG_KEY:
4053 case I40IW_AE_AMP_BAD_STAG_INDEX:
4054 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4055 switch (opcode) {
4056 case I40IW_OP_TYPE_SEND_INV:
4057 case I40IW_OP_TYPE_SEND_SOL_INV:
4058 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_OP_ERR,
4059 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_CANT_INV_STAG);
4060 break;
4061 default:
4062 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4063 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_INV_STAG);
4064 }
4065 break;
4066 case I40IW_AE_AMP_RIGHTS_VIOLATION:
4067 case I40IW_AE_AMP_INVALIDATE_NO_REMOTE_ACCESS_RIGHTS:
4068 case I40IW_AE_PRIV_OPERATION_DENIED:
4069 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4070 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4071 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_ACCESS);
4072 break;
4073 case I40IW_AE_AMP_TO_WRAP:
4074 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4075 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4076 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_TO_WRAP);
4077 break;
4078 case I40IW_AE_LLP_RECEIVED_MARKER_AND_LENGTH_FIELDS_DONT_MATCH:
4079 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
4080 (LAYER_MPA << 4) | DDP_LLP, MPA_MARKER);
4081 break;
4082 case I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR:
4083 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4084 (LAYER_MPA << 4) | DDP_LLP, MPA_CRC);
4085 break;
4086 case I40IW_AE_LLP_SEGMENT_TOO_LARGE:
4087 case I40IW_AE_LLP_SEGMENT_TOO_SMALL:
4088 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
4089 (LAYER_DDP << 4) | DDP_CATASTROPHIC, DDP_CATASTROPHIC_LOCAL);
4090 break;
4091 case I40IW_AE_LCE_QP_CATASTROPHIC:
4092 case I40IW_AE_DDP_NO_L_BIT:
4093 i40iw_setup_termhdr(qp, termhdr, FLUSH_FATAL_ERR,
4094 (LAYER_DDP << 4) | DDP_CATASTROPHIC, DDP_CATASTROPHIC_LOCAL);
4095 break;
4096 case I40IW_AE_DDP_INVALID_MSN_GAP_IN_MSN:
4097 case I40IW_AE_DDP_INVALID_MSN_RANGE_IS_NOT_VALID:
4098 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4099 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MSN_RANGE);
4100 break;
4101 case I40IW_AE_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
4102 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4103 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
4104 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_TOO_LONG);
4105 break;
4106 case I40IW_AE_DDP_UBE_INVALID_DDP_VERSION:
4107 if (is_tagged)
4108 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4109 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_INV_DDP_VER);
4110 else
4111 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4112 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_DDP_VER);
4113 break;
4114 case I40IW_AE_DDP_UBE_INVALID_MO:
4115 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4116 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MO);
4117 break;
4118 case I40IW_AE_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
4119 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_OP_ERR,
4120 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MSN_NO_BUF);
4121 break;
4122 case I40IW_AE_DDP_UBE_INVALID_QN:
4123 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4124 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_QN);
4125 break;
4126 case I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
4127 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4128 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_INV_RDMAP_VER);
4129 break;
4130 case I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
4131 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_QP_OP_ERR,
4132 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_UNEXPECTED_OP);
4133 break;
4134 default:
4135 i40iw_setup_termhdr(qp, termhdr, FLUSH_FATAL_ERR,
4136 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_UNSPECIFIED);
4137 break;
4138 }
4139
4140 if (copy_len)
4141 memcpy(termhdr + 1, pkt, copy_len);
4142
4143 if (flush_code && !info->in_rdrsp_wr)
4144 qp->sq_flush = (info->sq) ? true : false;
4145
4146 return sizeof(struct i40iw_terminate_hdr) + copy_len;
4147}
4148
4149/**
4150 * i40iw_terminate_send_fin() - Send fin for terminate message
4151 * @qp: qp associated with received terminate AE
4152 */
4153void i40iw_terminate_send_fin(struct i40iw_sc_qp *qp)
4154{
4155 /* Send the fin only */
4156 i40iw_term_modify_qp(qp,
4157 I40IW_QP_STATE_TERMINATE,
4158 I40IWQP_TERM_SEND_FIN_ONLY,
4159 0);
4160}
4161
4162/**
4163 * i40iw_terminate_connection() - Bad AE and send terminate to remote QP
4164 * @qp: qp associated with received terminate AE
4165 * @info: the struct contiaing AE information
4166 */
4167void i40iw_terminate_connection(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info)
4168{
4169 u8 termlen = 0;
4170
4171 if (qp->term_flags & I40IW_TERM_SENT)
4172 return; /* Sanity check */
4173
4174 /* Eventtype can change from bld_terminate_hdr */
4175 qp->eventtype = TERM_EVENT_QP_FATAL;
4176 termlen = i40iw_bld_terminate_hdr(qp, info);
4177 i40iw_terminate_start_timer(qp);
4178 qp->term_flags |= I40IW_TERM_SENT;
4179 i40iw_term_modify_qp(qp, I40IW_QP_STATE_TERMINATE,
4180 I40IWQP_TERM_SEND_TERM_ONLY, termlen);
4181}
4182
4183/**
4184 * i40iw_terminate_received - handle terminate received AE
4185 * @qp: qp associated with received terminate AE
4186 * @info: the struct contiaing AE information
4187 */
4188void i40iw_terminate_received(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info)
4189{
4190 u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
4191 u32 *mpa;
4192 u8 ddp_ctl;
4193 u8 rdma_ctl;
4194 u16 aeq_id = 0;
4195 struct i40iw_terminate_hdr *termhdr;
4196
4197 mpa = (u32 *)i40iw_locate_mpa(pkt);
4198 if (info->q2_data_written) {
4199 /* did not validate the frame - do it now */
4200 ddp_ctl = (ntohl(mpa[0]) >> 8) & 0xff;
4201 rdma_ctl = ntohl(mpa[0]) & 0xff;
4202 if ((ddp_ctl & 0xc0) != 0x40)
4203 aeq_id = I40IW_AE_LCE_QP_CATASTROPHIC;
4204 else if ((ddp_ctl & 0x03) != 1)
4205 aeq_id = I40IW_AE_DDP_UBE_INVALID_DDP_VERSION;
4206 else if (ntohl(mpa[2]) != 2)
4207 aeq_id = I40IW_AE_DDP_UBE_INVALID_QN;
4208 else if (ntohl(mpa[3]) != 1)
4209 aeq_id = I40IW_AE_DDP_INVALID_MSN_GAP_IN_MSN;
4210 else if (ntohl(mpa[4]) != 0)
4211 aeq_id = I40IW_AE_DDP_UBE_INVALID_MO;
4212 else if ((rdma_ctl & 0xc0) != 0x40)
4213 aeq_id = I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION;
4214
4215 info->ae_id = aeq_id;
4216 if (info->ae_id) {
4217 /* Bad terminate recvd - send back a terminate */
4218 i40iw_terminate_connection(qp, info);
4219 return;
4220 }
4221 }
4222
4223 qp->term_flags |= I40IW_TERM_RCVD;
4224 qp->eventtype = TERM_EVENT_QP_FATAL;
4225 termhdr = (struct i40iw_terminate_hdr *)&mpa[5];
4226 if (termhdr->layer_etype == RDMAP_REMOTE_PROT ||
4227 termhdr->layer_etype == RDMAP_REMOTE_OP) {
4228 i40iw_terminate_done(qp, 0);
4229 } else {
4230 i40iw_terminate_start_timer(qp);
4231 i40iw_terminate_send_fin(qp);
4232 }
4233}
4234
4235/**
4236 * i40iw_hw_stat_init - Initiliaze HW stats table
4237 * @devstat: pestat struct
4238 * @fcn_idx: PCI fn id
4239 * @hw: PF i40iw_hw structure.
4240 * @is_pf: Is it a PF?
4241 *
4242 * Populate the HW stat table with register offset addr for each
4243 * stat. And start the perioidic stats timer.
4244 */
4245static void i40iw_hw_stat_init(struct i40iw_dev_pestat *devstat,
4246 u8 fcn_idx,
4247 struct i40iw_hw *hw, bool is_pf)
4248{
4249 u32 stat_reg_offset;
4250 u32 stat_index;
4251 struct i40iw_dev_hw_stat_offsets *stat_table =
4252 &devstat->hw_stat_offsets;
4253 struct i40iw_dev_hw_stats *last_rd_stats = &devstat->last_read_hw_stats;
4254
4255 devstat->hw = hw;
4256
4257 if (is_pf) {
4258 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] =
4259 I40E_GLPES_PFIP4RXDISCARD(fcn_idx);
4260 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] =
4261 I40E_GLPES_PFIP4RXTRUNC(fcn_idx);
4262 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] =
4263 I40E_GLPES_PFIP4TXNOROUTE(fcn_idx);
4264 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD] =
4265 I40E_GLPES_PFIP6RXDISCARD(fcn_idx);
4266 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC] =
4267 I40E_GLPES_PFIP6RXTRUNC(fcn_idx);
4268 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE] =
4269 I40E_GLPES_PFIP6TXNOROUTE(fcn_idx);
4270 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRTXSEG] =
4271 I40E_GLPES_PFTCPRTXSEG(fcn_idx);
4272 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXOPTERR] =
4273 I40E_GLPES_PFTCPRXOPTERR(fcn_idx);
4274 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXPROTOERR] =
4275 I40E_GLPES_PFTCPRXPROTOERR(fcn_idx);
4276
4277 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXOCTS] =
4278 I40E_GLPES_PFIP4RXOCTSLO(fcn_idx);
4279 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] =
4280 I40E_GLPES_PFIP4RXPKTSLO(fcn_idx);
4281 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] =
4282 I40E_GLPES_PFIP4RXFRAGSLO(fcn_idx);
4283 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] =
4284 I40E_GLPES_PFIP4RXMCPKTSLO(fcn_idx);
4285 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXOCTS] =
4286 I40E_GLPES_PFIP4TXOCTSLO(fcn_idx);
4287 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXPKTS] =
4288 I40E_GLPES_PFIP4TXPKTSLO(fcn_idx);
4289 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] =
4290 I40E_GLPES_PFIP4TXFRAGSLO(fcn_idx);
4291 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] =
4292 I40E_GLPES_PFIP4TXMCPKTSLO(fcn_idx);
4293 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXOCTS] =
4294 I40E_GLPES_PFIP6RXOCTSLO(fcn_idx);
4295 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXPKTS] =
4296 I40E_GLPES_PFIP6RXPKTSLO(fcn_idx);
4297 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS] =
4298 I40E_GLPES_PFIP6RXFRAGSLO(fcn_idx);
4299 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS] =
4300 I40E_GLPES_PFIP6RXMCPKTSLO(fcn_idx);
4301 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXOCTS] =
4302 I40E_GLPES_PFIP6TXOCTSLO(fcn_idx);
4303 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
4304 I40E_GLPES_PFIP6TXPKTSLO(fcn_idx);
4305 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
4306 I40E_GLPES_PFIP6TXPKTSLO(fcn_idx);
4307 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS] =
4308 I40E_GLPES_PFIP6TXFRAGSLO(fcn_idx);
4309 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPRXSEGS] =
4310 I40E_GLPES_PFTCPRXSEGSLO(fcn_idx);
4311 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPTXSEG] =
4312 I40E_GLPES_PFTCPTXSEGLO(fcn_idx);
4313 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXRDS] =
4314 I40E_GLPES_PFRDMARXRDSLO(fcn_idx);
4315 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXSNDS] =
4316 I40E_GLPES_PFRDMARXSNDSLO(fcn_idx);
4317 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXWRS] =
4318 I40E_GLPES_PFRDMARXWRSLO(fcn_idx);
4319 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXRDS] =
4320 I40E_GLPES_PFRDMATXRDSLO(fcn_idx);
4321 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXSNDS] =
4322 I40E_GLPES_PFRDMATXSNDSLO(fcn_idx);
4323 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXWRS] =
4324 I40E_GLPES_PFRDMATXWRSLO(fcn_idx);
4325 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVBND] =
4326 I40E_GLPES_PFRDMAVBNDLO(fcn_idx);
4327 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVINV] =
4328 I40E_GLPES_PFRDMAVINVLO(fcn_idx);
4329 } else {
4330 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] =
4331 I40E_GLPES_VFIP4RXDISCARD(fcn_idx);
4332 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] =
4333 I40E_GLPES_VFIP4RXTRUNC(fcn_idx);
4334 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] =
4335 I40E_GLPES_VFIP4TXNOROUTE(fcn_idx);
4336 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD] =
4337 I40E_GLPES_VFIP6RXDISCARD(fcn_idx);
4338 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC] =
4339 I40E_GLPES_VFIP6RXTRUNC(fcn_idx);
4340 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE] =
4341 I40E_GLPES_VFIP6TXNOROUTE(fcn_idx);
4342 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRTXSEG] =
4343 I40E_GLPES_VFTCPRTXSEG(fcn_idx);
4344 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXOPTERR] =
4345 I40E_GLPES_VFTCPRXOPTERR(fcn_idx);
4346 stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXPROTOERR] =
4347 I40E_GLPES_VFTCPRXPROTOERR(fcn_idx);
4348
4349 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXOCTS] =
4350 I40E_GLPES_VFIP4RXOCTSLO(fcn_idx);
4351 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] =
4352 I40E_GLPES_VFIP4RXPKTSLO(fcn_idx);
4353 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] =
4354 I40E_GLPES_VFIP4RXFRAGSLO(fcn_idx);
4355 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] =
4356 I40E_GLPES_VFIP4RXMCPKTSLO(fcn_idx);
4357 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXOCTS] =
4358 I40E_GLPES_VFIP4TXOCTSLO(fcn_idx);
4359 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXPKTS] =
4360 I40E_GLPES_VFIP4TXPKTSLO(fcn_idx);
4361 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] =
4362 I40E_GLPES_VFIP4TXFRAGSLO(fcn_idx);
4363 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] =
4364 I40E_GLPES_VFIP4TXMCPKTSLO(fcn_idx);
4365 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXOCTS] =
4366 I40E_GLPES_VFIP6RXOCTSLO(fcn_idx);
4367 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXPKTS] =
4368 I40E_GLPES_VFIP6RXPKTSLO(fcn_idx);
4369 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS] =
4370 I40E_GLPES_VFIP6RXFRAGSLO(fcn_idx);
4371 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS] =
4372 I40E_GLPES_VFIP6RXMCPKTSLO(fcn_idx);
4373 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXOCTS] =
4374 I40E_GLPES_VFIP6TXOCTSLO(fcn_idx);
4375 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
4376 I40E_GLPES_VFIP6TXPKTSLO(fcn_idx);
4377 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
4378 I40E_GLPES_VFIP6TXPKTSLO(fcn_idx);
4379 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS] =
4380 I40E_GLPES_VFIP6TXFRAGSLO(fcn_idx);
4381 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPRXSEGS] =
4382 I40E_GLPES_VFTCPRXSEGSLO(fcn_idx);
4383 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPTXSEG] =
4384 I40E_GLPES_VFTCPTXSEGLO(fcn_idx);
4385 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXRDS] =
4386 I40E_GLPES_VFRDMARXRDSLO(fcn_idx);
4387 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXSNDS] =
4388 I40E_GLPES_VFRDMARXSNDSLO(fcn_idx);
4389 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXWRS] =
4390 I40E_GLPES_VFRDMARXWRSLO(fcn_idx);
4391 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXRDS] =
4392 I40E_GLPES_VFRDMATXRDSLO(fcn_idx);
4393 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXSNDS] =
4394 I40E_GLPES_VFRDMATXSNDSLO(fcn_idx);
4395 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXWRS] =
4396 I40E_GLPES_VFRDMATXWRSLO(fcn_idx);
4397 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVBND] =
4398 I40E_GLPES_VFRDMAVBNDLO(fcn_idx);
4399 stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVINV] =
4400 I40E_GLPES_VFRDMAVINVLO(fcn_idx);
4401 }
4402
4403 for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_64;
4404 stat_index++) {
4405 stat_reg_offset = stat_table->stat_offset_64[stat_index];
4406 last_rd_stats->stat_value_64[stat_index] =
4407 readq(devstat->hw->hw_addr + stat_reg_offset);
4408 }
4409
4410 for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_32;
4411 stat_index++) {
4412 stat_reg_offset = stat_table->stat_offset_32[stat_index];
4413 last_rd_stats->stat_value_32[stat_index] =
4414 i40iw_rd32(devstat->hw, stat_reg_offset);
4415 }
4416}
4417
4418/**
4419 * i40iw_hw_stat_read_32 - Read 32-bit HW stat counters and accommodates for roll-overs.
4420 * @devstat: pestat struct
4421 * @index: index in HW stat table which contains offset reg-addr
4422 * @value: hw stat value
4423 */
4424static void i40iw_hw_stat_read_32(struct i40iw_dev_pestat *devstat,
4425 enum i40iw_hw_stat_index_32b index,
4426 u64 *value)
4427{
4428 struct i40iw_dev_hw_stat_offsets *stat_table =
4429 &devstat->hw_stat_offsets;
4430 struct i40iw_dev_hw_stats *last_rd_stats = &devstat->last_read_hw_stats;
4431 struct i40iw_dev_hw_stats *hw_stats = &devstat->hw_stats;
4432 u64 new_stat_value = 0;
4433 u32 stat_reg_offset = stat_table->stat_offset_32[index];
4434
4435 new_stat_value = i40iw_rd32(devstat->hw, stat_reg_offset);
4436 /*roll-over case */
4437 if (new_stat_value < last_rd_stats->stat_value_32[index])
4438 hw_stats->stat_value_32[index] += new_stat_value;
4439 else
4440 hw_stats->stat_value_32[index] +=
4441 new_stat_value - last_rd_stats->stat_value_32[index];
4442 last_rd_stats->stat_value_32[index] = new_stat_value;
4443 *value = hw_stats->stat_value_32[index];
4444}
4445
4446/**
4447 * i40iw_hw_stat_read_64 - Read HW stat counters (greater than 32-bit) and accommodates for roll-overs.
4448 * @devstat: pestat struct
4449 * @index: index in HW stat table which contains offset reg-addr
4450 * @value: hw stat value
4451 */
4452static void i40iw_hw_stat_read_64(struct i40iw_dev_pestat *devstat,
4453 enum i40iw_hw_stat_index_64b index,
4454 u64 *value)
4455{
4456 struct i40iw_dev_hw_stat_offsets *stat_table =
4457 &devstat->hw_stat_offsets;
4458 struct i40iw_dev_hw_stats *last_rd_stats = &devstat->last_read_hw_stats;
4459 struct i40iw_dev_hw_stats *hw_stats = &devstat->hw_stats;
4460 u64 new_stat_value = 0;
4461 u32 stat_reg_offset = stat_table->stat_offset_64[index];
4462
4463 new_stat_value = readq(devstat->hw->hw_addr + stat_reg_offset);
4464 /*roll-over case */
4465 if (new_stat_value < last_rd_stats->stat_value_64[index])
4466 hw_stats->stat_value_64[index] += new_stat_value;
4467 else
4468 hw_stats->stat_value_64[index] +=
4469 new_stat_value - last_rd_stats->stat_value_64[index];
4470 last_rd_stats->stat_value_64[index] = new_stat_value;
4471 *value = hw_stats->stat_value_64[index];
4472}
4473
4474/**
4475 * i40iw_hw_stat_read_all - read all HW stat counters
4476 * @devstat: pestat struct
4477 * @stat_values: hw stats structure
4478 *
4479 * Read all the HW stat counters and populates hw_stats structure
4480 * of passed-in dev's pestat as well as copy created in stat_values.
4481 */
4482static void i40iw_hw_stat_read_all(struct i40iw_dev_pestat *devstat,
4483 struct i40iw_dev_hw_stats *stat_values)
4484{
4485 u32 stat_index;
4486
4487 for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_32;
4488 stat_index++)
4489 i40iw_hw_stat_read_32(devstat, stat_index,
4490 &stat_values->stat_value_32[stat_index]);
4491 for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_64;
4492 stat_index++)
4493 i40iw_hw_stat_read_64(devstat, stat_index,
4494 &stat_values->stat_value_64[stat_index]);
4495}
4496
4497/**
4498 * i40iw_hw_stat_refresh_all - Update all HW stat structs
4499 * @devstat: pestat struct
4500 * @stat_values: hw stats structure
4501 *
4502 * Read all the HW stat counters to refresh values in hw_stats structure
4503 * of passed-in dev's pestat
4504 */
4505static void i40iw_hw_stat_refresh_all(struct i40iw_dev_pestat *devstat)
4506{
4507 u64 stat_value;
4508 u32 stat_index;
4509
4510 for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_32;
4511 stat_index++)
4512 i40iw_hw_stat_read_32(devstat, stat_index, &stat_value);
4513 for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_64;
4514 stat_index++)
4515 i40iw_hw_stat_read_64(devstat, stat_index, &stat_value);
4516}
4517
4518static struct i40iw_cqp_ops iw_cqp_ops = {
4519 i40iw_sc_cqp_init,
4520 i40iw_sc_cqp_create,
4521 i40iw_sc_cqp_post_sq,
4522 i40iw_sc_cqp_get_next_send_wqe,
4523 i40iw_sc_cqp_destroy,
4524 i40iw_sc_poll_for_cqp_op_done
4525};
4526
4527static struct i40iw_ccq_ops iw_ccq_ops = {
4528 i40iw_sc_ccq_init,
4529 i40iw_sc_ccq_create,
4530 i40iw_sc_ccq_destroy,
4531 i40iw_sc_ccq_create_done,
4532 i40iw_sc_ccq_get_cqe_info,
4533 i40iw_sc_ccq_arm
4534};
4535
4536static struct i40iw_ceq_ops iw_ceq_ops = {
4537 i40iw_sc_ceq_init,
4538 i40iw_sc_ceq_create,
4539 i40iw_sc_cceq_create_done,
4540 i40iw_sc_cceq_destroy_done,
4541 i40iw_sc_cceq_create,
4542 i40iw_sc_ceq_destroy,
4543 i40iw_sc_process_ceq
4544};
4545
4546static struct i40iw_aeq_ops iw_aeq_ops = {
4547 i40iw_sc_aeq_init,
4548 i40iw_sc_aeq_create,
4549 i40iw_sc_aeq_destroy,
4550 i40iw_sc_get_next_aeqe,
4551 i40iw_sc_repost_aeq_entries,
4552 i40iw_sc_aeq_create_done,
4553 i40iw_sc_aeq_destroy_done
4554};
4555
4556/* iwarp pd ops */
4557static struct i40iw_pd_ops iw_pd_ops = {
4558 i40iw_sc_pd_init,
4559};
4560
4561static struct i40iw_priv_qp_ops iw_priv_qp_ops = {
4562 i40iw_sc_qp_init,
4563 i40iw_sc_qp_create,
4564 i40iw_sc_qp_modify,
4565 i40iw_sc_qp_destroy,
4566 i40iw_sc_qp_flush_wqes,
4567 i40iw_sc_qp_upload_context,
4568 i40iw_sc_qp_setctx,
4569 i40iw_sc_send_lsmm,
4570 i40iw_sc_send_lsmm_nostag,
4571 i40iw_sc_send_rtt,
4572 i40iw_sc_post_wqe0,
4573};
4574
4575static struct i40iw_priv_cq_ops iw_priv_cq_ops = {
4576 i40iw_sc_cq_init,
4577 i40iw_sc_cq_create,
4578 i40iw_sc_cq_destroy,
4579 i40iw_sc_cq_modify,
4580};
4581
4582static struct i40iw_mr_ops iw_mr_ops = {
4583 i40iw_sc_alloc_stag,
4584 i40iw_sc_mr_reg_non_shared,
4585 i40iw_sc_mr_reg_shared,
4586 i40iw_sc_dealloc_stag,
4587 i40iw_sc_query_stag,
4588 i40iw_sc_mw_alloc
4589};
4590
4591static struct i40iw_cqp_misc_ops iw_cqp_misc_ops = {
4592 i40iw_sc_manage_push_page,
4593 i40iw_sc_manage_hmc_pm_func_table,
4594 i40iw_sc_set_hmc_resource_profile,
4595 i40iw_sc_commit_fpm_values,
4596 i40iw_sc_query_fpm_values,
4597 i40iw_sc_static_hmc_pages_allocated,
4598 i40iw_sc_add_arp_cache_entry,
4599 i40iw_sc_del_arp_cache_entry,
4600 i40iw_sc_query_arp_cache_entry,
4601 i40iw_sc_manage_apbvt_entry,
4602 i40iw_sc_manage_qhash_table_entry,
4603 i40iw_sc_alloc_local_mac_ipaddr_entry,
4604 i40iw_sc_add_local_mac_ipaddr_entry,
4605 i40iw_sc_del_local_mac_ipaddr_entry,
4606 i40iw_sc_cqp_nop,
4607 i40iw_sc_commit_fpm_values_done,
4608 i40iw_sc_query_fpm_values_done,
4609 i40iw_sc_manage_hmc_pm_func_table_done,
4610 i40iw_sc_suspend_qp,
4611 i40iw_sc_resume_qp
4612};
4613
4614static struct i40iw_hmc_ops iw_hmc_ops = {
4615 i40iw_sc_init_iw_hmc,
4616 i40iw_sc_parse_fpm_query_buf,
4617 i40iw_sc_configure_iw_fpm,
4618 i40iw_sc_parse_fpm_commit_buf,
4619 i40iw_sc_create_hmc_obj,
4620 i40iw_sc_del_hmc_obj,
4621 NULL,
4622 NULL
4623};
4624
4625static const struct i40iw_device_pestat_ops iw_device_pestat_ops = {
4626 i40iw_hw_stat_init,
4627 i40iw_hw_stat_read_32,
4628 i40iw_hw_stat_read_64,
4629 i40iw_hw_stat_read_all,
4630 i40iw_hw_stat_refresh_all
4631};
4632
4633/**
4634 * i40iw_device_init_pestat - Initialize the pestat structure
4635 * @dev: pestat struct
4636 */
4637enum i40iw_status_code i40iw_device_init_pestat(struct i40iw_dev_pestat *devstat)
4638{
4639 devstat->ops = iw_device_pestat_ops;
4640 return 0;
4641}
4642
4643/**
4644 * i40iw_device_init - Initialize IWARP device
4645 * @dev: IWARP device pointer
4646 * @info: IWARP init info
4647 */
4648enum i40iw_status_code i40iw_device_init(struct i40iw_sc_dev *dev,
4649 struct i40iw_device_init_info *info)
4650{
4651 u32 val;
4652 u32 vchnl_ver = 0;
4653 u16 hmc_fcn = 0;
4654 enum i40iw_status_code ret_code = 0;
4655 u8 db_size;
4656
4657 spin_lock_init(&dev->cqp_lock);
4658 INIT_LIST_HEAD(&dev->cqp_cmd_head); /* for the cqp commands backlog. */
4659
4660 i40iw_device_init_uk(&dev->dev_uk);
4661
4662 dev->debug_mask = info->debug_mask;
4663
4664 ret_code = i40iw_device_init_pestat(&dev->dev_pestat);
4665 if (ret_code) {
4666 i40iw_debug(dev, I40IW_DEBUG_DEV,
4667 "%s: i40iw_device_init_pestat failed\n", __func__);
4668 return ret_code;
4669 }
4670 dev->hmc_fn_id = info->hmc_fn_id;
4671 dev->qs_handle = info->qs_handle;
4672 dev->exception_lan_queue = info->exception_lan_queue;
4673 dev->is_pf = info->is_pf;
4674
4675 dev->fpm_query_buf_pa = info->fpm_query_buf_pa;
4676 dev->fpm_query_buf = info->fpm_query_buf;
4677
4678 dev->fpm_commit_buf_pa = info->fpm_commit_buf_pa;
4679 dev->fpm_commit_buf = info->fpm_commit_buf;
4680
4681 dev->hw = info->hw;
4682 dev->hw->hw_addr = info->bar0;
4683
4684 val = i40iw_rd32(dev->hw, I40E_GLPCI_DREVID);
4685 dev->hw_rev = (u8)RS_32(val, I40E_GLPCI_DREVID_DEFAULT_REVID);
4686
4687 if (dev->is_pf) {
4688 dev->dev_pestat.ops.iw_hw_stat_init(&dev->dev_pestat,
4689 dev->hmc_fn_id, dev->hw, true);
4690 spin_lock_init(&dev->dev_pestat.stats_lock);
4691 /*start the periodic stats_timer */
4692 i40iw_hw_stats_start_timer(dev);
4693 val = i40iw_rd32(dev->hw, I40E_GLPCI_LBARCTRL);
4694 db_size = (u8)RS_32(val, I40E_GLPCI_LBARCTRL_PE_DB_SIZE);
4695 if ((db_size != I40IW_PE_DB_SIZE_4M) &&
4696 (db_size != I40IW_PE_DB_SIZE_8M)) {
4697 i40iw_debug(dev, I40IW_DEBUG_DEV,
4698 "%s: PE doorbell is not enabled in CSR val 0x%x\n",
4699 __func__, val);
4700 ret_code = I40IW_ERR_PE_DOORBELL_NOT_ENABLED;
4701 return ret_code;
4702 }
4703 dev->db_addr = dev->hw->hw_addr + I40IW_DB_ADDR_OFFSET;
4704 dev->vchnl_if.vchnl_recv = i40iw_vchnl_recv_pf;
4705 } else {
4706 dev->db_addr = dev->hw->hw_addr + I40IW_VF_DB_ADDR_OFFSET;
4707 }
4708
4709 dev->cqp_ops = &iw_cqp_ops;
4710 dev->ccq_ops = &iw_ccq_ops;
4711 dev->ceq_ops = &iw_ceq_ops;
4712 dev->aeq_ops = &iw_aeq_ops;
4713 dev->cqp_misc_ops = &iw_cqp_misc_ops;
4714 dev->iw_pd_ops = &iw_pd_ops;
4715 dev->iw_priv_qp_ops = &iw_priv_qp_ops;
4716 dev->iw_priv_cq_ops = &iw_priv_cq_ops;
4717 dev->mr_ops = &iw_mr_ops;
4718 dev->hmc_ops = &iw_hmc_ops;
4719 dev->vchnl_if.vchnl_send = info->vchnl_send;
4720 if (dev->vchnl_if.vchnl_send)
4721 dev->vchnl_up = true;
4722 else
4723 dev->vchnl_up = false;
4724 if (!dev->is_pf) {
4725 dev->vchnl_if.vchnl_recv = i40iw_vchnl_recv_vf;
4726 ret_code = i40iw_vchnl_vf_get_ver(dev, &vchnl_ver);
4727 if (!ret_code) {
4728 i40iw_debug(dev, I40IW_DEBUG_DEV,
4729 "%s: Get Channel version rc = 0x%0x, version is %u\n",
4730 __func__, ret_code, vchnl_ver);
4731 ret_code = i40iw_vchnl_vf_get_hmc_fcn(dev, &hmc_fcn);
4732 if (!ret_code) {
4733 i40iw_debug(dev, I40IW_DEBUG_DEV,
4734 "%s Get HMC function rc = 0x%0x, hmc fcn is %u\n",
4735 __func__, ret_code, hmc_fcn);
4736 dev->hmc_fn_id = (u8)hmc_fcn;
4737 }
4738 }
4739 }
4740 dev->iw_vf_cqp_ops = &iw_vf_cqp_ops;
4741
4742 return ret_code;
4743}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_d.h b/drivers/infiniband/hw/i40iw/i40iw_d.h
new file mode 100644
index 000000000000..aab88d65f805
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_d.h
@@ -0,0 +1,1713 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_D_H
36#define I40IW_D_H
37
38#define I40IW_DB_ADDR_OFFSET (4 * 1024 * 1024 - 64 * 1024)
39#define I40IW_VF_DB_ADDR_OFFSET (64 * 1024)
40
41#define I40IW_PUSH_OFFSET (4 * 1024 * 1024)
42#define I40IW_PF_FIRST_PUSH_PAGE_INDEX 16
43#define I40IW_VF_PUSH_OFFSET ((8 + 64) * 1024)
44#define I40IW_VF_FIRST_PUSH_PAGE_INDEX 2
45
46#define I40IW_PE_DB_SIZE_4M 1
47#define I40IW_PE_DB_SIZE_8M 2
48
49#define I40IW_DDP_VER 1
50#define I40IW_RDMAP_VER 1
51
52#define I40IW_RDMA_MODE_RDMAC 0
53#define I40IW_RDMA_MODE_IETF 1
54
55#define I40IW_QP_STATE_INVALID 0
56#define I40IW_QP_STATE_IDLE 1
57#define I40IW_QP_STATE_RTS 2
58#define I40IW_QP_STATE_CLOSING 3
59#define I40IW_QP_STATE_RESERVED 4
60#define I40IW_QP_STATE_TERMINATE 5
61#define I40IW_QP_STATE_ERROR 6
62
63#define I40IW_STAG_STATE_INVALID 0
64#define I40IW_STAG_STATE_VALID 1
65
66#define I40IW_STAG_TYPE_SHARED 0
67#define I40IW_STAG_TYPE_NONSHARED 1
68
69#define I40IW_MAX_USER_PRIORITY 8
70
71#define LS_64_1(val, bits) ((u64)(uintptr_t)val << bits)
72#define RS_64_1(val, bits) ((u64)(uintptr_t)val >> bits)
73#define LS_32_1(val, bits) (u32)(val << bits)
74#define RS_32_1(val, bits) (u32)(val >> bits)
75#define I40E_HI_DWORD(x) ((u32)((((x) >> 16) >> 16) & 0xFFFFFFFF))
76
77#define LS_64(val, field) (((u64)val << field ## _SHIFT) & (field ## _MASK))
78
79#define RS_64(val, field) ((u64)(val & field ## _MASK) >> field ## _SHIFT)
80#define LS_32(val, field) ((val << field ## _SHIFT) & (field ## _MASK))
81#define RS_32(val, field) ((val & field ## _MASK) >> field ## _SHIFT)
82
83#define TERM_DDP_LEN_TAGGED 14
84#define TERM_DDP_LEN_UNTAGGED 18
85#define TERM_RDMA_LEN 28
86#define RDMA_OPCODE_MASK 0x0f
87#define RDMA_READ_REQ_OPCODE 1
88#define Q2_BAD_FRAME_OFFSET 72
89#define CQE_MAJOR_DRV 0x8000
90
91#define I40IW_TERM_SENT 0x01
92#define I40IW_TERM_RCVD 0x02
93#define I40IW_TERM_DONE 0x04
94#define I40IW_MAC_HLEN 14
95
96#define I40IW_INVALID_WQE_INDEX 0xffffffff
97
98#define I40IW_CQP_WAIT_POLL_REGS 1
99#define I40IW_CQP_WAIT_POLL_CQ 2
100#define I40IW_CQP_WAIT_EVENT 3
101
102#define I40IW_CQP_INIT_WQE(wqe) memset(wqe, 0, 64)
103
104#define I40IW_GET_CURRENT_CQ_ELEMENT(_cq) \
105 ( \
106 &((_cq)->cq_base[I40IW_RING_GETCURRENT_HEAD((_cq)->cq_ring)]) \
107 )
108#define I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(_cq) \
109 ( \
110 &(((struct i40iw_extended_cqe *) \
111 ((_cq)->cq_base))[I40IW_RING_GETCURRENT_HEAD((_cq)->cq_ring)]) \
112 )
113
114#define I40IW_GET_CURRENT_AEQ_ELEMENT(_aeq) \
115 ( \
116 &_aeq->aeqe_base[I40IW_RING_GETCURRENT_TAIL(_aeq->aeq_ring)] \
117 )
118
119#define I40IW_GET_CURRENT_CEQ_ELEMENT(_ceq) \
120 ( \
121 &_ceq->ceqe_base[I40IW_RING_GETCURRENT_TAIL(_ceq->ceq_ring)] \
122 )
123
124#define I40IW_AE_SOURCE_RQ 0x1
125#define I40IW_AE_SOURCE_RQ_0011 0x3
126
127#define I40IW_AE_SOURCE_CQ 0x2
128#define I40IW_AE_SOURCE_CQ_0110 0x6
129#define I40IW_AE_SOURCE_CQ_1010 0xA
130#define I40IW_AE_SOURCE_CQ_1110 0xE
131
132#define I40IW_AE_SOURCE_SQ 0x5
133#define I40IW_AE_SOURCE_SQ_0111 0x7
134
135#define I40IW_AE_SOURCE_IN_RR_WR 0x9
136#define I40IW_AE_SOURCE_IN_RR_WR_1011 0xB
137#define I40IW_AE_SOURCE_OUT_RR 0xD
138#define I40IW_AE_SOURCE_OUT_RR_1111 0xF
139
140#define I40IW_TCP_STATE_NON_EXISTENT 0
141#define I40IW_TCP_STATE_CLOSED 1
142#define I40IW_TCP_STATE_LISTEN 2
143#define I40IW_STATE_SYN_SEND 3
144#define I40IW_TCP_STATE_SYN_RECEIVED 4
145#define I40IW_TCP_STATE_ESTABLISHED 5
146#define I40IW_TCP_STATE_CLOSE_WAIT 6
147#define I40IW_TCP_STATE_FIN_WAIT_1 7
148#define I40IW_TCP_STATE_CLOSING 8
149#define I40IW_TCP_STATE_LAST_ACK 9
150#define I40IW_TCP_STATE_FIN_WAIT_2 10
151#define I40IW_TCP_STATE_TIME_WAIT 11
152#define I40IW_TCP_STATE_RESERVED_1 12
153#define I40IW_TCP_STATE_RESERVED_2 13
154#define I40IW_TCP_STATE_RESERVED_3 14
155#define I40IW_TCP_STATE_RESERVED_4 15
156
157/* ILQ CQP hash table fields */
158#define I40IW_CQPSQ_QHASH_VLANID_SHIFT 32
159#define I40IW_CQPSQ_QHASH_VLANID_MASK \
160 ((u64)0xfff << I40IW_CQPSQ_QHASH_VLANID_SHIFT)
161
162#define I40IW_CQPSQ_QHASH_QPN_SHIFT 32
163#define I40IW_CQPSQ_QHASH_QPN_MASK \
164 ((u64)0x3ffff << I40IW_CQPSQ_QHASH_QPN_SHIFT)
165
166#define I40IW_CQPSQ_QHASH_QS_HANDLE_SHIFT 0
167#define I40IW_CQPSQ_QHASH_QS_HANDLE_MASK ((u64)0x3ff << I40IW_CQPSQ_QHASH_QS_HANDLE_SHIFT)
168
169#define I40IW_CQPSQ_QHASH_SRC_PORT_SHIFT 16
170#define I40IW_CQPSQ_QHASH_SRC_PORT_MASK \
171 ((u64)0xffff << I40IW_CQPSQ_QHASH_SRC_PORT_SHIFT)
172
173#define I40IW_CQPSQ_QHASH_DEST_PORT_SHIFT 0
174#define I40IW_CQPSQ_QHASH_DEST_PORT_MASK \
175 ((u64)0xffff << I40IW_CQPSQ_QHASH_DEST_PORT_SHIFT)
176
177#define I40IW_CQPSQ_QHASH_ADDR0_SHIFT 32
178#define I40IW_CQPSQ_QHASH_ADDR0_MASK \
179 ((u64)0xffffffff << I40IW_CQPSQ_QHASH_ADDR0_SHIFT)
180
181#define I40IW_CQPSQ_QHASH_ADDR1_SHIFT 0
182#define I40IW_CQPSQ_QHASH_ADDR1_MASK \
183 ((u64)0xffffffff << I40IW_CQPSQ_QHASH_ADDR1_SHIFT)
184
185#define I40IW_CQPSQ_QHASH_ADDR2_SHIFT 32
186#define I40IW_CQPSQ_QHASH_ADDR2_MASK \
187 ((u64)0xffffffff << I40IW_CQPSQ_QHASH_ADDR2_SHIFT)
188
189#define I40IW_CQPSQ_QHASH_ADDR3_SHIFT 0
190#define I40IW_CQPSQ_QHASH_ADDR3_MASK \
191 ((u64)0xffffffff << I40IW_CQPSQ_QHASH_ADDR3_SHIFT)
192
193#define I40IW_CQPSQ_QHASH_WQEVALID_SHIFT 63
194#define I40IW_CQPSQ_QHASH_WQEVALID_MASK \
195 ((u64)0x1 << I40IW_CQPSQ_QHASH_WQEVALID_SHIFT)
196#define I40IW_CQPSQ_QHASH_OPCODE_SHIFT 32
197#define I40IW_CQPSQ_QHASH_OPCODE_MASK \
198 ((u64)0x3f << I40IW_CQPSQ_QHASH_OPCODE_SHIFT)
199
200#define I40IW_CQPSQ_QHASH_MANAGE_SHIFT 61
201#define I40IW_CQPSQ_QHASH_MANAGE_MASK \
202 ((u64)0x3 << I40IW_CQPSQ_QHASH_MANAGE_SHIFT)
203
204#define I40IW_CQPSQ_QHASH_IPV4VALID_SHIFT 60
205#define I40IW_CQPSQ_QHASH_IPV4VALID_MASK \
206 ((u64)0x1 << I40IW_CQPSQ_QHASH_IPV4VALID_SHIFT)
207
208#define I40IW_CQPSQ_QHASH_VLANVALID_SHIFT 59
209#define I40IW_CQPSQ_QHASH_VLANVALID_MASK \
210 ((u64)0x1 << I40IW_CQPSQ_QHASH_VLANVALID_SHIFT)
211
212#define I40IW_CQPSQ_QHASH_ENTRYTYPE_SHIFT 42
213#define I40IW_CQPSQ_QHASH_ENTRYTYPE_MASK \
214 ((u64)0x7 << I40IW_CQPSQ_QHASH_ENTRYTYPE_SHIFT)
215/* CQP Host Context */
216#define I40IW_CQPHC_EN_DC_TCP_SHIFT 0
217#define I40IW_CQPHC_EN_DC_TCP_MASK (1UL << I40IW_CQPHC_EN_DC_TCP_SHIFT)
218
219#define I40IW_CQPHC_SQSIZE_SHIFT 8
220#define I40IW_CQPHC_SQSIZE_MASK (0xfUL << I40IW_CQPHC_SQSIZE_SHIFT)
221
222#define I40IW_CQPHC_DISABLE_PFPDUS_SHIFT 1
223#define I40IW_CQPHC_DISABLE_PFPDUS_MASK (0x1UL << I40IW_CQPHC_DISABLE_PFPDUS_SHIFT)
224
225#define I40IW_CQPHC_ENABLED_VFS_SHIFT 32
226#define I40IW_CQPHC_ENABLED_VFS_MASK (0x3fULL << I40IW_CQPHC_ENABLED_VFS_SHIFT)
227
228#define I40IW_CQPHC_HMC_PROFILE_SHIFT 0
229#define I40IW_CQPHC_HMC_PROFILE_MASK (0x7ULL << I40IW_CQPHC_HMC_PROFILE_SHIFT)
230
231#define I40IW_CQPHC_SVER_SHIFT 24
232#define I40IW_CQPHC_SVER_MASK (0xffUL << I40IW_CQPHC_SVER_SHIFT)
233
234#define I40IW_CQPHC_SQBASE_SHIFT 9
235#define I40IW_CQPHC_SQBASE_MASK \
236 (0xfffffffffffffeULL << I40IW_CQPHC_SQBASE_SHIFT)
237
238#define I40IW_CQPHC_QPCTX_SHIFT 0
239#define I40IW_CQPHC_QPCTX_MASK \
240 (0xffffffffffffffffULL << I40IW_CQPHC_QPCTX_SHIFT)
241#define I40IW_CQPHC_SVER 1
242
243#define I40IW_CQP_SW_SQSIZE_4 4
244#define I40IW_CQP_SW_SQSIZE_2048 2048
245
246/* iWARP QP Doorbell shadow area */
247#define I40IW_QP_DBSA_HW_SQ_TAIL_SHIFT 0
248#define I40IW_QP_DBSA_HW_SQ_TAIL_MASK \
249 (0x3fffUL << I40IW_QP_DBSA_HW_SQ_TAIL_SHIFT)
250
251/* Completion Queue Doorbell shadow area */
252#define I40IW_CQ_DBSA_CQEIDX_SHIFT 0
253#define I40IW_CQ_DBSA_CQEIDX_MASK (0xfffffUL << I40IW_CQ_DBSA_CQEIDX_SHIFT)
254
255#define I40IW_CQ_DBSA_SW_CQ_SELECT_SHIFT 0
256#define I40IW_CQ_DBSA_SW_CQ_SELECT_MASK \
257 (0x3fffUL << I40IW_CQ_DBSA_SW_CQ_SELECT_SHIFT)
258
259#define I40IW_CQ_DBSA_ARM_NEXT_SHIFT 14
260#define I40IW_CQ_DBSA_ARM_NEXT_MASK (1UL << I40IW_CQ_DBSA_ARM_NEXT_SHIFT)
261
262#define I40IW_CQ_DBSA_ARM_NEXT_SE_SHIFT 15
263#define I40IW_CQ_DBSA_ARM_NEXT_SE_MASK (1UL << I40IW_CQ_DBSA_ARM_NEXT_SE_SHIFT)
264
265#define I40IW_CQ_DBSA_ARM_SEQ_NUM_SHIFT 16
266#define I40IW_CQ_DBSA_ARM_SEQ_NUM_MASK \
267 (0x3UL << I40IW_CQ_DBSA_ARM_SEQ_NUM_SHIFT)
268
269/* CQP and iWARP Completion Queue */
270#define I40IW_CQ_QPCTX_SHIFT I40IW_CQPHC_QPCTX_SHIFT
271#define I40IW_CQ_QPCTX_MASK I40IW_CQPHC_QPCTX_MASK
272
273#define I40IW_CCQ_OPRETVAL_SHIFT 0
274#define I40IW_CCQ_OPRETVAL_MASK (0xffffffffUL << I40IW_CCQ_OPRETVAL_SHIFT)
275
276#define I40IW_CQ_MINERR_SHIFT 0
277#define I40IW_CQ_MINERR_MASK (0xffffUL << I40IW_CQ_MINERR_SHIFT)
278
279#define I40IW_CQ_MAJERR_SHIFT 16
280#define I40IW_CQ_MAJERR_MASK (0xffffUL << I40IW_CQ_MAJERR_SHIFT)
281
282#define I40IW_CQ_WQEIDX_SHIFT 32
283#define I40IW_CQ_WQEIDX_MASK (0x3fffULL << I40IW_CQ_WQEIDX_SHIFT)
284
285#define I40IW_CQ_ERROR_SHIFT 55
286#define I40IW_CQ_ERROR_MASK (1ULL << I40IW_CQ_ERROR_SHIFT)
287
288#define I40IW_CQ_SQ_SHIFT 62
289#define I40IW_CQ_SQ_MASK (1ULL << I40IW_CQ_SQ_SHIFT)
290
291#define I40IW_CQ_VALID_SHIFT 63
292#define I40IW_CQ_VALID_MASK (1ULL << I40IW_CQ_VALID_SHIFT)
293
294#define I40IWCQ_PAYLDLEN_SHIFT 0
295#define I40IWCQ_PAYLDLEN_MASK (0xffffffffUL << I40IWCQ_PAYLDLEN_SHIFT)
296
297#define I40IWCQ_TCPSEQNUM_SHIFT 32
298#define I40IWCQ_TCPSEQNUM_MASK (0xffffffffULL << I40IWCQ_TCPSEQNUM_SHIFT)
299
300#define I40IWCQ_INVSTAG_SHIFT 0
301#define I40IWCQ_INVSTAG_MASK (0xffffffffUL << I40IWCQ_INVSTAG_SHIFT)
302
303#define I40IWCQ_QPID_SHIFT 32
304#define I40IWCQ_QPID_MASK (0x3ffffULL << I40IWCQ_QPID_SHIFT)
305
306#define I40IWCQ_PSHDROP_SHIFT 51
307#define I40IWCQ_PSHDROP_MASK (1ULL << I40IWCQ_PSHDROP_SHIFT)
308
309#define I40IWCQ_SRQ_SHIFT 52
310#define I40IWCQ_SRQ_MASK (1ULL << I40IWCQ_SRQ_SHIFT)
311
312#define I40IWCQ_STAG_SHIFT 53
313#define I40IWCQ_STAG_MASK (1ULL << I40IWCQ_STAG_SHIFT)
314
315#define I40IWCQ_SOEVENT_SHIFT 54
316#define I40IWCQ_SOEVENT_MASK (1ULL << I40IWCQ_SOEVENT_SHIFT)
317
318#define I40IWCQ_OP_SHIFT 56
319#define I40IWCQ_OP_MASK (0x3fULL << I40IWCQ_OP_SHIFT)
320
321/* CEQE format */
322#define I40IW_CEQE_CQCTX_SHIFT 0
323#define I40IW_CEQE_CQCTX_MASK \
324 (0x7fffffffffffffffULL << I40IW_CEQE_CQCTX_SHIFT)
325
326#define I40IW_CEQE_VALID_SHIFT 63
327#define I40IW_CEQE_VALID_MASK (1ULL << I40IW_CEQE_VALID_SHIFT)
328
329/* AEQE format */
330#define I40IW_AEQE_COMPCTX_SHIFT I40IW_CQPHC_QPCTX_SHIFT
331#define I40IW_AEQE_COMPCTX_MASK I40IW_CQPHC_QPCTX_MASK
332
333#define I40IW_AEQE_QPCQID_SHIFT 0
334#define I40IW_AEQE_QPCQID_MASK (0x3ffffUL << I40IW_AEQE_QPCQID_SHIFT)
335
336#define I40IW_AEQE_WQDESCIDX_SHIFT 18
337#define I40IW_AEQE_WQDESCIDX_MASK (0x3fffULL << I40IW_AEQE_WQDESCIDX_SHIFT)
338
339#define I40IW_AEQE_OVERFLOW_SHIFT 33
340#define I40IW_AEQE_OVERFLOW_MASK (1ULL << I40IW_AEQE_OVERFLOW_SHIFT)
341
342#define I40IW_AEQE_AECODE_SHIFT 34
343#define I40IW_AEQE_AECODE_MASK (0xffffULL << I40IW_AEQE_AECODE_SHIFT)
344
345#define I40IW_AEQE_AESRC_SHIFT 50
346#define I40IW_AEQE_AESRC_MASK (0xfULL << I40IW_AEQE_AESRC_SHIFT)
347
348#define I40IW_AEQE_IWSTATE_SHIFT 54
349#define I40IW_AEQE_IWSTATE_MASK (0x7ULL << I40IW_AEQE_IWSTATE_SHIFT)
350
351#define I40IW_AEQE_TCPSTATE_SHIFT 57
352#define I40IW_AEQE_TCPSTATE_MASK (0xfULL << I40IW_AEQE_TCPSTATE_SHIFT)
353
354#define I40IW_AEQE_Q2DATA_SHIFT 61
355#define I40IW_AEQE_Q2DATA_MASK (0x3ULL << I40IW_AEQE_Q2DATA_SHIFT)
356
357#define I40IW_AEQE_VALID_SHIFT 63
358#define I40IW_AEQE_VALID_MASK (1ULL << I40IW_AEQE_VALID_SHIFT)
359
360/* CQP SQ WQES */
361#define I40IW_QP_TYPE_IWARP 1
362#define I40IW_QP_TYPE_UDA 2
363#define I40IW_QP_TYPE_CQP 4
364
365#define I40IW_CQ_TYPE_IWARP 1
366#define I40IW_CQ_TYPE_ILQ 2
367#define I40IW_CQ_TYPE_IEQ 3
368#define I40IW_CQ_TYPE_CQP 4
369
370#define I40IWQP_TERM_SEND_TERM_AND_FIN 0
371#define I40IWQP_TERM_SEND_TERM_ONLY 1
372#define I40IWQP_TERM_SEND_FIN_ONLY 2
373#define I40IWQP_TERM_DONOT_SEND_TERM_OR_FIN 3
374
375#define I40IW_CQP_OP_CREATE_QP 0
376#define I40IW_CQP_OP_MODIFY_QP 0x1
377#define I40IW_CQP_OP_DESTROY_QP 0x02
378#define I40IW_CQP_OP_CREATE_CQ 0x03
379#define I40IW_CQP_OP_MODIFY_CQ 0x04
380#define I40IW_CQP_OP_DESTROY_CQ 0x05
381#define I40IW_CQP_OP_CREATE_SRQ 0x06
382#define I40IW_CQP_OP_MODIFY_SRQ 0x07
383#define I40IW_CQP_OP_DESTROY_SRQ 0x08
384#define I40IW_CQP_OP_ALLOC_STAG 0x09
385#define I40IW_CQP_OP_REG_MR 0x0a
386#define I40IW_CQP_OP_QUERY_STAG 0x0b
387#define I40IW_CQP_OP_REG_SMR 0x0c
388#define I40IW_CQP_OP_DEALLOC_STAG 0x0d
389#define I40IW_CQP_OP_MANAGE_LOC_MAC_IP_TABLE 0x0e
390#define I40IW_CQP_OP_MANAGE_ARP 0x0f
391#define I40IW_CQP_OP_MANAGE_VF_PBLE_BP 0x10
392#define I40IW_CQP_OP_MANAGE_PUSH_PAGES 0x11
393#define I40IW_CQP_OP_MANAGE_PE_TEAM 0x12
394#define I40IW_CQP_OP_UPLOAD_CONTEXT 0x13
395#define I40IW_CQP_OP_ALLOCATE_LOC_MAC_IP_TABLE_ENTRY 0x14
396#define I40IW_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE 0x15
397#define I40IW_CQP_OP_CREATE_CEQ 0x16
398#define I40IW_CQP_OP_DESTROY_CEQ 0x18
399#define I40IW_CQP_OP_CREATE_AEQ 0x19
400#define I40IW_CQP_OP_DESTROY_AEQ 0x1b
401#define I40IW_CQP_OP_CREATE_ADDR_VECT 0x1c
402#define I40IW_CQP_OP_MODIFY_ADDR_VECT 0x1d
403#define I40IW_CQP_OP_DESTROY_ADDR_VECT 0x1e
404#define I40IW_CQP_OP_UPDATE_PE_SDS 0x1f
405#define I40IW_CQP_OP_QUERY_FPM_VALUES 0x20
406#define I40IW_CQP_OP_COMMIT_FPM_VALUES 0x21
407#define I40IW_CQP_OP_FLUSH_WQES 0x22
408#define I40IW_CQP_OP_MANAGE_APBVT 0x23
409#define I40IW_CQP_OP_NOP 0x24
410#define I40IW_CQP_OP_MANAGE_QUAD_HASH_TABLE_ENTRY 0x25
411#define I40IW_CQP_OP_CREATE_UDA_MCAST_GROUP 0x26
412#define I40IW_CQP_OP_MODIFY_UDA_MCAST_GROUP 0x27
413#define I40IW_CQP_OP_DESTROY_UDA_MCAST_GROUP 0x28
414#define I40IW_CQP_OP_SUSPEND_QP 0x29
415#define I40IW_CQP_OP_RESUME_QP 0x2a
416#define I40IW_CQP_OP_SHMC_PAGES_ALLOCATED 0x2b
417#define I40IW_CQP_OP_SET_HMC_RESOURCE_PROFILE 0x2d
418
419#define I40IW_UDA_QPSQ_NEXT_HEADER_SHIFT 16
420#define I40IW_UDA_QPSQ_NEXT_HEADER_MASK ((u64)0xff << I40IW_UDA_QPSQ_NEXT_HEADER_SHIFT)
421
422#define I40IW_UDA_QPSQ_OPCODE_SHIFT 32
423#define I40IW_UDA_QPSQ_OPCODE_MASK ((u64)0x3f << I40IW_UDA_QPSQ_OPCODE_SHIFT)
424
425#define I40IW_UDA_QPSQ_MACLEN_SHIFT 56
426#define I40IW_UDA_QPSQ_MACLEN_MASK \
427 ((u64)0x7f << I40IW_UDA_QPSQ_MACLEN_SHIFT)
428
429#define I40IW_UDA_QPSQ_IPLEN_SHIFT 48
430#define I40IW_UDA_QPSQ_IPLEN_MASK \
431 ((u64)0x7f << I40IW_UDA_QPSQ_IPLEN_SHIFT)
432
433#define I40IW_UDA_QPSQ_L4T_SHIFT 30
434#define I40IW_UDA_QPSQ_L4T_MASK \
435 ((u64)0x3 << I40IW_UDA_QPSQ_L4T_SHIFT)
436
437#define I40IW_UDA_QPSQ_IIPT_SHIFT 28
438#define I40IW_UDA_QPSQ_IIPT_MASK \
439 ((u64)0x3 << I40IW_UDA_QPSQ_IIPT_SHIFT)
440
441#define I40IW_UDA_QPSQ_L4LEN_SHIFT 24
442#define I40IW_UDA_QPSQ_L4LEN_MASK ((u64)0xf << I40IW_UDA_QPSQ_L4LEN_SHIFT)
443
444#define I40IW_UDA_QPSQ_AVIDX_SHIFT 0
445#define I40IW_UDA_QPSQ_AVIDX_MASK ((u64)0xffff << I40IW_UDA_QPSQ_AVIDX_SHIFT)
446
447#define I40IW_UDA_QPSQ_VALID_SHIFT 63
448#define I40IW_UDA_QPSQ_VALID_MASK \
449 ((u64)0x1 << I40IW_UDA_QPSQ_VALID_SHIFT)
450
451#define I40IW_UDA_QPSQ_SIGCOMPL_SHIFT 62
452#define I40IW_UDA_QPSQ_SIGCOMPL_MASK ((u64)0x1 << I40IW_UDA_QPSQ_SIGCOMPL_SHIFT)
453
454#define I40IW_UDA_PAYLOADLEN_SHIFT 0
455#define I40IW_UDA_PAYLOADLEN_MASK ((u64)0x3fff << I40IW_UDA_PAYLOADLEN_SHIFT)
456
457#define I40IW_UDA_HDRLEN_SHIFT 16
458#define I40IW_UDA_HDRLEN_MASK ((u64)0x1ff << I40IW_UDA_HDRLEN_SHIFT)
459
460#define I40IW_VLAN_TAG_VALID_SHIFT 50
461#define I40IW_VLAN_TAG_VALID_MASK ((u64)0x1 << I40IW_VLAN_TAG_VALID_SHIFT)
462
463#define I40IW_UDA_L3PROTO_SHIFT 0
464#define I40IW_UDA_L3PROTO_MASK ((u64)0x3 << I40IW_UDA_L3PROTO_SHIFT)
465
466#define I40IW_UDA_L4PROTO_SHIFT 16
467#define I40IW_UDA_L4PROTO_MASK ((u64)0x3 << I40IW_UDA_L4PROTO_SHIFT)
468
469#define I40IW_UDA_QPSQ_DOLOOPBACK_SHIFT 44
470#define I40IW_UDA_QPSQ_DOLOOPBACK_MASK \
471 ((u64)0x1 << I40IW_UDA_QPSQ_DOLOOPBACK_SHIFT)
472
473/* CQP SQ WQE common fields */
474#define I40IW_CQPSQ_OPCODE_SHIFT 32
475#define I40IW_CQPSQ_OPCODE_MASK (0x3fULL << I40IW_CQPSQ_OPCODE_SHIFT)
476
477#define I40IW_CQPSQ_WQEVALID_SHIFT 63
478#define I40IW_CQPSQ_WQEVALID_MASK (1ULL << I40IW_CQPSQ_WQEVALID_SHIFT)
479
480#define I40IW_CQPSQ_TPHVAL_SHIFT 0
481#define I40IW_CQPSQ_TPHVAL_MASK (0xffUL << I40IW_CQPSQ_TPHVAL_SHIFT)
482
483#define I40IW_CQPSQ_TPHEN_SHIFT 60
484#define I40IW_CQPSQ_TPHEN_MASK (1ULL << I40IW_CQPSQ_TPHEN_SHIFT)
485
486#define I40IW_CQPSQ_PBUFADDR_SHIFT I40IW_CQPHC_QPCTX_SHIFT
487#define I40IW_CQPSQ_PBUFADDR_MASK I40IW_CQPHC_QPCTX_MASK
488
489/* Create/Modify/Destroy QP */
490
491#define I40IW_CQPSQ_QP_NEWMSS_SHIFT 32
492#define I40IW_CQPSQ_QP_NEWMSS_MASK (0x3fffULL << I40IW_CQPSQ_QP_NEWMSS_SHIFT)
493
494#define I40IW_CQPSQ_QP_TERMLEN_SHIFT 48
495#define I40IW_CQPSQ_QP_TERMLEN_MASK (0xfULL << I40IW_CQPSQ_QP_TERMLEN_SHIFT)
496
497#define I40IW_CQPSQ_QP_QPCTX_SHIFT I40IW_CQPHC_QPCTX_SHIFT
498#define I40IW_CQPSQ_QP_QPCTX_MASK I40IW_CQPHC_QPCTX_MASK
499
500#define I40IW_CQPSQ_QP_QPID_SHIFT 0
501#define I40IW_CQPSQ_QP_QPID_MASK (0x3FFFFUL)
502/* I40IWCQ_QPID_MASK */
503
504#define I40IW_CQPSQ_QP_OP_SHIFT 32
505#define I40IW_CQPSQ_QP_OP_MASK I40IWCQ_OP_MASK
506
507#define I40IW_CQPSQ_QP_ORDVALID_SHIFT 42
508#define I40IW_CQPSQ_QP_ORDVALID_MASK (1ULL << I40IW_CQPSQ_QP_ORDVALID_SHIFT)
509
510#define I40IW_CQPSQ_QP_TOECTXVALID_SHIFT 43
511#define I40IW_CQPSQ_QP_TOECTXVALID_MASK \
512 (1ULL << I40IW_CQPSQ_QP_TOECTXVALID_SHIFT)
513
514#define I40IW_CQPSQ_QP_CACHEDVARVALID_SHIFT 44
515#define I40IW_CQPSQ_QP_CACHEDVARVALID_MASK \
516 (1ULL << I40IW_CQPSQ_QP_CACHEDVARVALID_SHIFT)
517
518#define I40IW_CQPSQ_QP_VQ_SHIFT 45
519#define I40IW_CQPSQ_QP_VQ_MASK (1ULL << I40IW_CQPSQ_QP_VQ_SHIFT)
520
521#define I40IW_CQPSQ_QP_FORCELOOPBACK_SHIFT 46
522#define I40IW_CQPSQ_QP_FORCELOOPBACK_MASK \
523 (1ULL << I40IW_CQPSQ_QP_FORCELOOPBACK_SHIFT)
524
525#define I40IW_CQPSQ_QP_CQNUMVALID_SHIFT 47
526#define I40IW_CQPSQ_QP_CQNUMVALID_MASK \
527 (1ULL << I40IW_CQPSQ_QP_CQNUMVALID_SHIFT)
528
529#define I40IW_CQPSQ_QP_QPTYPE_SHIFT 48
530#define I40IW_CQPSQ_QP_QPTYPE_MASK (0x3ULL << I40IW_CQPSQ_QP_QPTYPE_SHIFT)
531
532#define I40IW_CQPSQ_QP_MSSCHANGE_SHIFT 52
533#define I40IW_CQPSQ_QP_MSSCHANGE_MASK (1ULL << I40IW_CQPSQ_QP_MSSCHANGE_SHIFT)
534
535#define I40IW_CQPSQ_QP_STATRSRC_SHIFT 53
536#define I40IW_CQPSQ_QP_STATRSRC_MASK (1ULL << I40IW_CQPSQ_QP_STATRSRC_SHIFT)
537
538#define I40IW_CQPSQ_QP_IGNOREMWBOUND_SHIFT 54
539#define I40IW_CQPSQ_QP_IGNOREMWBOUND_MASK \
540 (1ULL << I40IW_CQPSQ_QP_IGNOREMWBOUND_SHIFT)
541
542#define I40IW_CQPSQ_QP_REMOVEHASHENTRY_SHIFT 55
543#define I40IW_CQPSQ_QP_REMOVEHASHENTRY_MASK \
544 (1ULL << I40IW_CQPSQ_QP_REMOVEHASHENTRY_SHIFT)
545
546#define I40IW_CQPSQ_QP_TERMACT_SHIFT 56
547#define I40IW_CQPSQ_QP_TERMACT_MASK (0x3ULL << I40IW_CQPSQ_QP_TERMACT_SHIFT)
548
549#define I40IW_CQPSQ_QP_RESETCON_SHIFT 58
550#define I40IW_CQPSQ_QP_RESETCON_MASK (1ULL << I40IW_CQPSQ_QP_RESETCON_SHIFT)
551
552#define I40IW_CQPSQ_QP_ARPTABIDXVALID_SHIFT 59
553#define I40IW_CQPSQ_QP_ARPTABIDXVALID_MASK \
554 (1ULL << I40IW_CQPSQ_QP_ARPTABIDXVALID_SHIFT)
555
556#define I40IW_CQPSQ_QP_NEXTIWSTATE_SHIFT 60
557#define I40IW_CQPSQ_QP_NEXTIWSTATE_MASK \
558 (0x7ULL << I40IW_CQPSQ_QP_NEXTIWSTATE_SHIFT)
559
560#define I40IW_CQPSQ_QP_DBSHADOWADDR_SHIFT I40IW_CQPHC_QPCTX_SHIFT
561#define I40IW_CQPSQ_QP_DBSHADOWADDR_MASK I40IW_CQPHC_QPCTX_MASK
562
563/* Create/Modify/Destroy CQ */
564#define I40IW_CQPSQ_CQ_CQSIZE_SHIFT 0
565#define I40IW_CQPSQ_CQ_CQSIZE_MASK (0x3ffffUL << I40IW_CQPSQ_CQ_CQSIZE_SHIFT)
566
567#define I40IW_CQPSQ_CQ_CQCTX_SHIFT 0
568#define I40IW_CQPSQ_CQ_CQCTX_MASK \
569 (0x7fffffffffffffffULL << I40IW_CQPSQ_CQ_CQCTX_SHIFT)
570
571#define I40IW_CQPSQ_CQ_CQCTX_SHIFT 0
572#define I40IW_CQPSQ_CQ_CQCTX_MASK \
573 (0x7fffffffffffffffULL << I40IW_CQPSQ_CQ_CQCTX_SHIFT)
574
575#define I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD_SHIFT 0
576#define I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD_MASK \
577 (0x3ffff << I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD_SHIFT)
578
579#define I40IW_CQPSQ_CQ_CEQID_SHIFT 24
580#define I40IW_CQPSQ_CQ_CEQID_MASK (0x7fUL << I40IW_CQPSQ_CQ_CEQID_SHIFT)
581
582#define I40IW_CQPSQ_CQ_OP_SHIFT 32
583#define I40IW_CQPSQ_CQ_OP_MASK (0x3fULL << I40IW_CQPSQ_CQ_OP_SHIFT)
584
585#define I40IW_CQPSQ_CQ_CQRESIZE_SHIFT 43
586#define I40IW_CQPSQ_CQ_CQRESIZE_MASK (1ULL << I40IW_CQPSQ_CQ_CQRESIZE_SHIFT)
587
588#define I40IW_CQPSQ_CQ_LPBLSIZE_SHIFT 44
589#define I40IW_CQPSQ_CQ_LPBLSIZE_MASK (3ULL << I40IW_CQPSQ_CQ_LPBLSIZE_SHIFT)
590
591#define I40IW_CQPSQ_CQ_CHKOVERFLOW_SHIFT 46
592#define I40IW_CQPSQ_CQ_CHKOVERFLOW_MASK \
593 (1ULL << I40IW_CQPSQ_CQ_CHKOVERFLOW_SHIFT)
594
595#define I40IW_CQPSQ_CQ_VIRTMAP_SHIFT 47
596#define I40IW_CQPSQ_CQ_VIRTMAP_MASK (1ULL << I40IW_CQPSQ_CQ_VIRTMAP_SHIFT)
597
598#define I40IW_CQPSQ_CQ_ENCEQEMASK_SHIFT 48
599#define I40IW_CQPSQ_CQ_ENCEQEMASK_MASK \
600 (1ULL << I40IW_CQPSQ_CQ_ENCEQEMASK_SHIFT)
601
602#define I40IW_CQPSQ_CQ_CEQIDVALID_SHIFT 49
603#define I40IW_CQPSQ_CQ_CEQIDVALID_MASK \
604 (1ULL << I40IW_CQPSQ_CQ_CEQIDVALID_SHIFT)
605
606#define I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT_SHIFT 61
607#define I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT_MASK \
608 (1ULL << I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT_SHIFT)
609
610/* Create/Modify/Destroy Shared Receive Queue */
611
612#define I40IW_CQPSQ_SRQ_RQSIZE_SHIFT 0
613#define I40IW_CQPSQ_SRQ_RQSIZE_MASK (0xfUL << I40IW_CQPSQ_SRQ_RQSIZE_SHIFT)
614
615#define I40IW_CQPSQ_SRQ_RQWQESIZE_SHIFT 4
616#define I40IW_CQPSQ_SRQ_RQWQESIZE_MASK \
617 (0x7UL << I40IW_CQPSQ_SRQ_RQWQESIZE_SHIFT)
618
619#define I40IW_CQPSQ_SRQ_SRQLIMIT_SHIFT 32
620#define I40IW_CQPSQ_SRQ_SRQLIMIT_MASK \
621 (0xfffULL << I40IW_CQPSQ_SRQ_SRQLIMIT_SHIFT)
622
623#define I40IW_CQPSQ_SRQ_SRQCTX_SHIFT I40IW_CQPHC_QPCTX_SHIFT
624#define I40IW_CQPSQ_SRQ_SRQCTX_MASK I40IW_CQPHC_QPCTX_MASK
625
626#define I40IW_CQPSQ_SRQ_PDID_SHIFT 16
627#define I40IW_CQPSQ_SRQ_PDID_MASK \
628 (0x7fffULL << I40IW_CQPSQ_SRQ_PDID_SHIFT)
629
630#define I40IW_CQPSQ_SRQ_SRQID_SHIFT 0
631#define I40IW_CQPSQ_SRQ_SRQID_MASK (0x7fffUL << I40IW_CQPSQ_SRQ_SRQID_SHIFT)
632
633#define I40IW_CQPSQ_SRQ_LPBLSIZE_SHIFT I40IW_CQPSQ_CQ_LPBLSIZE_SHIFT
634#define I40IW_CQPSQ_SRQ_LPBLSIZE_MASK I40IW_CQPSQ_CQ_LPBLSIZE_MASK
635
636#define I40IW_CQPSQ_SRQ_VIRTMAP_SHIFT I40IW_CQPSQ_CQ_VIRTMAP_SHIFT
637#define I40IW_CQPSQ_SRQ_VIRTMAP_MASK I40IW_CQPSQ_CQ_VIRTMAP_MASK
638
639#define I40IW_CQPSQ_SRQ_TPHEN_SHIFT I40IW_CQPSQ_TPHEN_SHIFT
640#define I40IW_CQPSQ_SRQ_TPHEN_MASK I40IW_CQPSQ_TPHEN_MASK
641
642#define I40IW_CQPSQ_SRQ_ARMLIMITEVENT_SHIFT 61
643#define I40IW_CQPSQ_SRQ_ARMLIMITEVENT_MASK \
644 (1ULL << I40IW_CQPSQ_SRQ_ARMLIMITEVENT_SHIFT)
645
646#define I40IW_CQPSQ_SRQ_DBSHADOWAREA_SHIFT 6
647#define I40IW_CQPSQ_SRQ_DBSHADOWAREA_MASK \
648 (0x3ffffffffffffffULL << I40IW_CQPSQ_SRQ_DBSHADOWAREA_SHIFT)
649
650#define I40IW_CQPSQ_SRQ_FIRSTPMPBLIDX_SHIFT 0
651#define I40IW_CQPSQ_SRQ_FIRSTPMPBLIDX_MASK \
652 (0xfffffffUL << I40IW_CQPSQ_SRQ_FIRSTPMPBLIDX_SHIFT)
653
654/* Allocate/Register/Register Shared/Deallocate Stag */
655#define I40IW_CQPSQ_STAG_VA_FBO_SHIFT I40IW_CQPHC_QPCTX_SHIFT
656#define I40IW_CQPSQ_STAG_VA_FBO_MASK I40IW_CQPHC_QPCTX_MASK
657
658#define I40IW_CQPSQ_STAG_STAGLEN_SHIFT 0
659#define I40IW_CQPSQ_STAG_STAGLEN_MASK \
660 (0x3fffffffffffULL << I40IW_CQPSQ_STAG_STAGLEN_SHIFT)
661
662#define I40IW_CQPSQ_STAG_PDID_SHIFT 48
663#define I40IW_CQPSQ_STAG_PDID_MASK (0x7fffULL << I40IW_CQPSQ_STAG_PDID_SHIFT)
664
665#define I40IW_CQPSQ_STAG_KEY_SHIFT 0
666#define I40IW_CQPSQ_STAG_KEY_MASK (0xffUL << I40IW_CQPSQ_STAG_KEY_SHIFT)
667
668#define I40IW_CQPSQ_STAG_IDX_SHIFT 8
669#define I40IW_CQPSQ_STAG_IDX_MASK (0xffffffUL << I40IW_CQPSQ_STAG_IDX_SHIFT)
670
671#define I40IW_CQPSQ_STAG_PARENTSTAGIDX_SHIFT 32
672#define I40IW_CQPSQ_STAG_PARENTSTAGIDX_MASK \
673 (0xffffffULL << I40IW_CQPSQ_STAG_PARENTSTAGIDX_SHIFT)
674
675#define I40IW_CQPSQ_STAG_MR_SHIFT 43
676#define I40IW_CQPSQ_STAG_MR_MASK (1ULL << I40IW_CQPSQ_STAG_MR_SHIFT)
677
678#define I40IW_CQPSQ_STAG_LPBLSIZE_SHIFT I40IW_CQPSQ_CQ_LPBLSIZE_SHIFT
679#define I40IW_CQPSQ_STAG_LPBLSIZE_MASK I40IW_CQPSQ_CQ_LPBLSIZE_MASK
680
681#define I40IW_CQPSQ_STAG_HPAGESIZE_SHIFT 46
682#define I40IW_CQPSQ_STAG_HPAGESIZE_MASK \
683 (1ULL << I40IW_CQPSQ_STAG_HPAGESIZE_SHIFT)
684
685#define I40IW_CQPSQ_STAG_ARIGHTS_SHIFT 48
686#define I40IW_CQPSQ_STAG_ARIGHTS_MASK \
687 (0x1fULL << I40IW_CQPSQ_STAG_ARIGHTS_SHIFT)
688
689#define I40IW_CQPSQ_STAG_REMACCENABLED_SHIFT 53
690#define I40IW_CQPSQ_STAG_REMACCENABLED_MASK \
691 (1ULL << I40IW_CQPSQ_STAG_REMACCENABLED_SHIFT)
692
693#define I40IW_CQPSQ_STAG_VABASEDTO_SHIFT 59
694#define I40IW_CQPSQ_STAG_VABASEDTO_MASK \
695 (1ULL << I40IW_CQPSQ_STAG_VABASEDTO_SHIFT)
696
697#define I40IW_CQPSQ_STAG_USEHMCFNIDX_SHIFT 60
698#define I40IW_CQPSQ_STAG_USEHMCFNIDX_MASK \
699 (1ULL << I40IW_CQPSQ_STAG_USEHMCFNIDX_SHIFT)
700
701#define I40IW_CQPSQ_STAG_USEPFRID_SHIFT 61
702#define I40IW_CQPSQ_STAG_USEPFRID_MASK \
703 (1ULL << I40IW_CQPSQ_STAG_USEPFRID_SHIFT)
704
705#define I40IW_CQPSQ_STAG_PBA_SHIFT I40IW_CQPHC_QPCTX_SHIFT
706#define I40IW_CQPSQ_STAG_PBA_MASK I40IW_CQPHC_QPCTX_MASK
707
708#define I40IW_CQPSQ_STAG_HMCFNIDX_SHIFT 0
709#define I40IW_CQPSQ_STAG_HMCFNIDX_MASK \
710 (0x3fUL << I40IW_CQPSQ_STAG_HMCFNIDX_SHIFT)
711
712#define I40IW_CQPSQ_STAG_FIRSTPMPBLIDX_SHIFT 0
713#define I40IW_CQPSQ_STAG_FIRSTPMPBLIDX_MASK \
714 (0xfffffffUL << I40IW_CQPSQ_STAG_FIRSTPMPBLIDX_SHIFT)
715
716/* Query stag */
717#define I40IW_CQPSQ_QUERYSTAG_IDX_SHIFT I40IW_CQPSQ_STAG_IDX_SHIFT
718#define I40IW_CQPSQ_QUERYSTAG_IDX_MASK I40IW_CQPSQ_STAG_IDX_MASK
719
720/* Allocate Local IP Address Entry */
721
722/* Manage Local IP Address Table - MLIPA */
723#define I40IW_CQPSQ_MLIPA_IPV6LO_SHIFT I40IW_CQPHC_QPCTX_SHIFT
724#define I40IW_CQPSQ_MLIPA_IPV6LO_MASK I40IW_CQPHC_QPCTX_MASK
725
726#define I40IW_CQPSQ_MLIPA_IPV6HI_SHIFT I40IW_CQPHC_QPCTX_SHIFT
727#define I40IW_CQPSQ_MLIPA_IPV6HI_MASK I40IW_CQPHC_QPCTX_MASK
728
729#define I40IW_CQPSQ_MLIPA_IPV4_SHIFT 0
730#define I40IW_CQPSQ_MLIPA_IPV4_MASK \
731 (0xffffffffUL << I40IW_CQPSQ_MLIPA_IPV4_SHIFT)
732
733#define I40IW_CQPSQ_MLIPA_IPTABLEIDX_SHIFT 0
734#define I40IW_CQPSQ_MLIPA_IPTABLEIDX_MASK \
735 (0x3fUL << I40IW_CQPSQ_MLIPA_IPTABLEIDX_SHIFT)
736
737#define I40IW_CQPSQ_MLIPA_IPV4VALID_SHIFT 42
738#define I40IW_CQPSQ_MLIPA_IPV4VALID_MASK \
739 (1ULL << I40IW_CQPSQ_MLIPA_IPV4VALID_SHIFT)
740
741#define I40IW_CQPSQ_MLIPA_IPV6VALID_SHIFT 43
742#define I40IW_CQPSQ_MLIPA_IPV6VALID_MASK \
743 (1ULL << I40IW_CQPSQ_MLIPA_IPV6VALID_SHIFT)
744
745#define I40IW_CQPSQ_MLIPA_FREEENTRY_SHIFT 62
746#define I40IW_CQPSQ_MLIPA_FREEENTRY_MASK \
747 (1ULL << I40IW_CQPSQ_MLIPA_FREEENTRY_SHIFT)
748
749#define I40IW_CQPSQ_MLIPA_IGNORE_REF_CNT_SHIFT 61
750#define I40IW_CQPSQ_MLIPA_IGNORE_REF_CNT_MASK \
751 (1ULL << I40IW_CQPSQ_MLIPA_IGNORE_REF_CNT_SHIFT)
752
753#define I40IW_CQPSQ_MLIPA_MAC0_SHIFT 0
754#define I40IW_CQPSQ_MLIPA_MAC0_MASK (0xffUL << I40IW_CQPSQ_MLIPA_MAC0_SHIFT)
755
756#define I40IW_CQPSQ_MLIPA_MAC1_SHIFT 8
757#define I40IW_CQPSQ_MLIPA_MAC1_MASK (0xffUL << I40IW_CQPSQ_MLIPA_MAC1_SHIFT)
758
759#define I40IW_CQPSQ_MLIPA_MAC2_SHIFT 16
760#define I40IW_CQPSQ_MLIPA_MAC2_MASK (0xffUL << I40IW_CQPSQ_MLIPA_MAC2_SHIFT)
761
762#define I40IW_CQPSQ_MLIPA_MAC3_SHIFT 24
763#define I40IW_CQPSQ_MLIPA_MAC3_MASK (0xffUL << I40IW_CQPSQ_MLIPA_MAC3_SHIFT)
764
765#define I40IW_CQPSQ_MLIPA_MAC4_SHIFT 32
766#define I40IW_CQPSQ_MLIPA_MAC4_MASK (0xffULL << I40IW_CQPSQ_MLIPA_MAC4_SHIFT)
767
768#define I40IW_CQPSQ_MLIPA_MAC5_SHIFT 40
769#define I40IW_CQPSQ_MLIPA_MAC5_MASK (0xffULL << I40IW_CQPSQ_MLIPA_MAC5_SHIFT)
770
771/* Manage ARP Table - MAT */
772#define I40IW_CQPSQ_MAT_REACHMAX_SHIFT 0
773#define I40IW_CQPSQ_MAT_REACHMAX_MASK \
774 (0xffffffffUL << I40IW_CQPSQ_MAT_REACHMAX_SHIFT)
775
776#define I40IW_CQPSQ_MAT_MACADDR_SHIFT 0
777#define I40IW_CQPSQ_MAT_MACADDR_MASK \
778 (0xffffffffffffULL << I40IW_CQPSQ_MAT_MACADDR_SHIFT)
779
780#define I40IW_CQPSQ_MAT_ARPENTRYIDX_SHIFT 0
781#define I40IW_CQPSQ_MAT_ARPENTRYIDX_MASK \
782 (0xfffUL << I40IW_CQPSQ_MAT_ARPENTRYIDX_SHIFT)
783
784#define I40IW_CQPSQ_MAT_ENTRYVALID_SHIFT 42
785#define I40IW_CQPSQ_MAT_ENTRYVALID_MASK \
786 (1ULL << I40IW_CQPSQ_MAT_ENTRYVALID_SHIFT)
787
788#define I40IW_CQPSQ_MAT_PERMANENT_SHIFT 43
789#define I40IW_CQPSQ_MAT_PERMANENT_MASK \
790 (1ULL << I40IW_CQPSQ_MAT_PERMANENT_SHIFT)
791
792#define I40IW_CQPSQ_MAT_QUERY_SHIFT 44
793#define I40IW_CQPSQ_MAT_QUERY_MASK (1ULL << I40IW_CQPSQ_MAT_QUERY_SHIFT)
794
795/* Manage VF PBLE Backing Pages - MVPBP*/
796#define I40IW_CQPSQ_MVPBP_PD_ENTRY_CNT_SHIFT 0
797#define I40IW_CQPSQ_MVPBP_PD_ENTRY_CNT_MASK \
798 (0x3ffULL << I40IW_CQPSQ_MVPBP_PD_ENTRY_CNT_SHIFT)
799
800#define I40IW_CQPSQ_MVPBP_FIRST_PD_INX_SHIFT 16
801#define I40IW_CQPSQ_MVPBP_FIRST_PD_INX_MASK \
802 (0x1ffULL << I40IW_CQPSQ_MVPBP_FIRST_PD_INX_SHIFT)
803
804#define I40IW_CQPSQ_MVPBP_SD_INX_SHIFT 32
805#define I40IW_CQPSQ_MVPBP_SD_INX_MASK \
806 (0xfffULL << I40IW_CQPSQ_MVPBP_SD_INX_SHIFT)
807
808#define I40IW_CQPSQ_MVPBP_INV_PD_ENT_SHIFT 62
809#define I40IW_CQPSQ_MVPBP_INV_PD_ENT_MASK \
810 (0x1ULL << I40IW_CQPSQ_MVPBP_INV_PD_ENT_SHIFT)
811
812#define I40IW_CQPSQ_MVPBP_PD_PLPBA_SHIFT 3
813#define I40IW_CQPSQ_MVPBP_PD_PLPBA_MASK \
814 (0x1fffffffffffffffULL << I40IW_CQPSQ_MVPBP_PD_PLPBA_SHIFT)
815
816/* Manage Push Page - MPP */
817#define I40IW_INVALID_PUSH_PAGE_INDEX 0xffff
818
819#define I40IW_CQPSQ_MPP_QS_HANDLE_SHIFT 0
820#define I40IW_CQPSQ_MPP_QS_HANDLE_MASK (0xffffUL << \
821 I40IW_CQPSQ_MPP_QS_HANDLE_SHIFT)
822
823#define I40IW_CQPSQ_MPP_PPIDX_SHIFT 0
824#define I40IW_CQPSQ_MPP_PPIDX_MASK (0x3ffUL << I40IW_CQPSQ_MPP_PPIDX_SHIFT)
825
826#define I40IW_CQPSQ_MPP_FREE_PAGE_SHIFT 62
827#define I40IW_CQPSQ_MPP_FREE_PAGE_MASK (1ULL << I40IW_CQPSQ_MPP_FREE_PAGE_SHIFT)
828
829/* Upload Context - UCTX */
830#define I40IW_CQPSQ_UCTX_QPCTXADDR_SHIFT I40IW_CQPHC_QPCTX_SHIFT
831#define I40IW_CQPSQ_UCTX_QPCTXADDR_MASK I40IW_CQPHC_QPCTX_MASK
832
833#define I40IW_CQPSQ_UCTX_QPID_SHIFT 0
834#define I40IW_CQPSQ_UCTX_QPID_MASK (0x3ffffUL << I40IW_CQPSQ_UCTX_QPID_SHIFT)
835
836#define I40IW_CQPSQ_UCTX_QPTYPE_SHIFT 48
837#define I40IW_CQPSQ_UCTX_QPTYPE_MASK (0xfULL << I40IW_CQPSQ_UCTX_QPTYPE_SHIFT)
838
839#define I40IW_CQPSQ_UCTX_RAWFORMAT_SHIFT 61
840#define I40IW_CQPSQ_UCTX_RAWFORMAT_MASK \
841 (1ULL << I40IW_CQPSQ_UCTX_RAWFORMAT_SHIFT)
842
843#define I40IW_CQPSQ_UCTX_FREEZEQP_SHIFT 62
844#define I40IW_CQPSQ_UCTX_FREEZEQP_MASK \
845 (1ULL << I40IW_CQPSQ_UCTX_FREEZEQP_SHIFT)
846
847/* Manage HMC PM Function Table - MHMC */
848#define I40IW_CQPSQ_MHMC_VFIDX_SHIFT 0
849#define I40IW_CQPSQ_MHMC_VFIDX_MASK (0x7fUL << I40IW_CQPSQ_MHMC_VFIDX_SHIFT)
850
851#define I40IW_CQPSQ_MHMC_FREEPMFN_SHIFT 62
852#define I40IW_CQPSQ_MHMC_FREEPMFN_MASK \
853 (1ULL << I40IW_CQPSQ_MHMC_FREEPMFN_SHIFT)
854
855/* Set HMC Resource Profile - SHMCRP */
856#define I40IW_CQPSQ_SHMCRP_HMC_PROFILE_SHIFT 0
857#define I40IW_CQPSQ_SHMCRP_HMC_PROFILE_MASK \
858 (0x7ULL << I40IW_CQPSQ_SHMCRP_HMC_PROFILE_SHIFT)
859#define I40IW_CQPSQ_SHMCRP_VFNUM_SHIFT 32
860#define I40IW_CQPSQ_SHMCRP_VFNUM_MASK (0x3fULL << I40IW_CQPSQ_SHMCRP_VFNUM_SHIFT)
861
862/* Create/Destroy CEQ */
863#define I40IW_CQPSQ_CEQ_CEQSIZE_SHIFT 0
864#define I40IW_CQPSQ_CEQ_CEQSIZE_MASK \
865 (0x1ffffUL << I40IW_CQPSQ_CEQ_CEQSIZE_SHIFT)
866
867#define I40IW_CQPSQ_CEQ_CEQID_SHIFT 0
868#define I40IW_CQPSQ_CEQ_CEQID_MASK (0x7fUL << I40IW_CQPSQ_CEQ_CEQID_SHIFT)
869
870#define I40IW_CQPSQ_CEQ_LPBLSIZE_SHIFT I40IW_CQPSQ_CQ_LPBLSIZE_SHIFT
871#define I40IW_CQPSQ_CEQ_LPBLSIZE_MASK I40IW_CQPSQ_CQ_LPBLSIZE_MASK
872
873#define I40IW_CQPSQ_CEQ_VMAP_SHIFT 47
874#define I40IW_CQPSQ_CEQ_VMAP_MASK (1ULL << I40IW_CQPSQ_CEQ_VMAP_SHIFT)
875
876#define I40IW_CQPSQ_CEQ_FIRSTPMPBLIDX_SHIFT 0
877#define I40IW_CQPSQ_CEQ_FIRSTPMPBLIDX_MASK \
878 (0xfffffffUL << I40IW_CQPSQ_CEQ_FIRSTPMPBLIDX_SHIFT)
879
880/* Create/Destroy AEQ */
881#define I40IW_CQPSQ_AEQ_AEQECNT_SHIFT 0
882#define I40IW_CQPSQ_AEQ_AEQECNT_MASK \
883 (0x7ffffUL << I40IW_CQPSQ_AEQ_AEQECNT_SHIFT)
884
885#define I40IW_CQPSQ_AEQ_LPBLSIZE_SHIFT I40IW_CQPSQ_CQ_LPBLSIZE_SHIFT
886#define I40IW_CQPSQ_AEQ_LPBLSIZE_MASK I40IW_CQPSQ_CQ_LPBLSIZE_MASK
887
888#define I40IW_CQPSQ_AEQ_VMAP_SHIFT 47
889#define I40IW_CQPSQ_AEQ_VMAP_MASK (1ULL << I40IW_CQPSQ_AEQ_VMAP_SHIFT)
890
891#define I40IW_CQPSQ_AEQ_FIRSTPMPBLIDX_SHIFT 0
892#define I40IW_CQPSQ_AEQ_FIRSTPMPBLIDX_MASK \
893 (0xfffffffUL << I40IW_CQPSQ_AEQ_FIRSTPMPBLIDX_SHIFT)
894
895/* Commit FPM Values - CFPM */
896#define I40IW_CQPSQ_CFPM_HMCFNID_SHIFT 0
897#define I40IW_CQPSQ_CFPM_HMCFNID_MASK (0x3fUL << I40IW_CQPSQ_CFPM_HMCFNID_SHIFT)
898
899/* Flush WQEs - FWQE */
900#define I40IW_CQPSQ_FWQE_AECODE_SHIFT 0
901#define I40IW_CQPSQ_FWQE_AECODE_MASK (0xffffUL << I40IW_CQPSQ_FWQE_AECODE_SHIFT)
902
903#define I40IW_CQPSQ_FWQE_AESOURCE_SHIFT 16
904#define I40IW_CQPSQ_FWQE_AESOURCE_MASK \
905 (0xfUL << I40IW_CQPSQ_FWQE_AESOURCE_SHIFT)
906
907#define I40IW_CQPSQ_FWQE_RQMNERR_SHIFT 0
908#define I40IW_CQPSQ_FWQE_RQMNERR_MASK \
909 (0xffffUL << I40IW_CQPSQ_FWQE_RQMNERR_SHIFT)
910
911#define I40IW_CQPSQ_FWQE_RQMJERR_SHIFT 16
912#define I40IW_CQPSQ_FWQE_RQMJERR_MASK \
913 (0xffffUL << I40IW_CQPSQ_FWQE_RQMJERR_SHIFT)
914
915#define I40IW_CQPSQ_FWQE_SQMNERR_SHIFT 32
916#define I40IW_CQPSQ_FWQE_SQMNERR_MASK \
917 (0xffffULL << I40IW_CQPSQ_FWQE_SQMNERR_SHIFT)
918
919#define I40IW_CQPSQ_FWQE_SQMJERR_SHIFT 48
920#define I40IW_CQPSQ_FWQE_SQMJERR_MASK \
921 (0xffffULL << I40IW_CQPSQ_FWQE_SQMJERR_SHIFT)
922
923#define I40IW_CQPSQ_FWQE_QPID_SHIFT 0
924#define I40IW_CQPSQ_FWQE_QPID_MASK (0x3ffffULL << I40IW_CQPSQ_FWQE_QPID_SHIFT)
925
926#define I40IW_CQPSQ_FWQE_GENERATE_AE_SHIFT 59
927#define I40IW_CQPSQ_FWQE_GENERATE_AE_MASK (1ULL << \
928 I40IW_CQPSQ_FWQE_GENERATE_AE_SHIFT)
929
930#define I40IW_CQPSQ_FWQE_USERFLCODE_SHIFT 60
931#define I40IW_CQPSQ_FWQE_USERFLCODE_MASK \
932 (1ULL << I40IW_CQPSQ_FWQE_USERFLCODE_SHIFT)
933
934#define I40IW_CQPSQ_FWQE_FLUSHSQ_SHIFT 61
935#define I40IW_CQPSQ_FWQE_FLUSHSQ_MASK (1ULL << I40IW_CQPSQ_FWQE_FLUSHSQ_SHIFT)
936
937#define I40IW_CQPSQ_FWQE_FLUSHRQ_SHIFT 62
938#define I40IW_CQPSQ_FWQE_FLUSHRQ_MASK (1ULL << I40IW_CQPSQ_FWQE_FLUSHRQ_SHIFT)
939
940/* Manage Accelerated Port Table - MAPT */
941#define I40IW_CQPSQ_MAPT_PORT_SHIFT 0
942#define I40IW_CQPSQ_MAPT_PORT_MASK (0xffffUL << I40IW_CQPSQ_MAPT_PORT_SHIFT)
943
944#define I40IW_CQPSQ_MAPT_ADDPORT_SHIFT 62
945#define I40IW_CQPSQ_MAPT_ADDPORT_MASK (1ULL << I40IW_CQPSQ_MAPT_ADDPORT_SHIFT)
946
947/* Update Protocol Engine SDs */
948#define I40IW_CQPSQ_UPESD_SDCMD_SHIFT 0
949#define I40IW_CQPSQ_UPESD_SDCMD_MASK (0xffffffffUL << I40IW_CQPSQ_UPESD_SDCMD_SHIFT)
950
951#define I40IW_CQPSQ_UPESD_SDDATALOW_SHIFT 0
952#define I40IW_CQPSQ_UPESD_SDDATALOW_MASK \
953 (0xffffffffUL << I40IW_CQPSQ_UPESD_SDDATALOW_SHIFT)
954
955#define I40IW_CQPSQ_UPESD_SDDATAHI_SHIFT 32
956#define I40IW_CQPSQ_UPESD_SDDATAHI_MASK \
957 (0xffffffffULL << I40IW_CQPSQ_UPESD_SDDATAHI_SHIFT)
958#define I40IW_CQPSQ_UPESD_HMCFNID_SHIFT 0
959#define I40IW_CQPSQ_UPESD_HMCFNID_MASK \
960 (0x3fUL << I40IW_CQPSQ_UPESD_HMCFNID_SHIFT)
961
962#define I40IW_CQPSQ_UPESD_ENTRY_VALID_SHIFT 63
963#define I40IW_CQPSQ_UPESD_ENTRY_VALID_MASK \
964 ((u64)1 << I40IW_CQPSQ_UPESD_ENTRY_VALID_SHIFT)
965
966#define I40IW_CQPSQ_UPESD_ENTRY_COUNT_SHIFT 0
967#define I40IW_CQPSQ_UPESD_ENTRY_COUNT_MASK \
968 (0xfUL << I40IW_CQPSQ_UPESD_ENTRY_COUNT_SHIFT)
969
970#define I40IW_CQPSQ_UPESD_SKIP_ENTRY_SHIFT 7
971#define I40IW_CQPSQ_UPESD_SKIP_ENTRY_MASK \
972 (0x1UL << I40IW_CQPSQ_UPESD_SKIP_ENTRY_SHIFT)
973
974/* Suspend QP */
975#define I40IW_CQPSQ_SUSPENDQP_QPID_SHIFT 0
976#define I40IW_CQPSQ_SUSPENDQP_QPID_MASK (0x3FFFFUL)
977/* I40IWCQ_QPID_MASK */
978
979/* Resume QP */
980#define I40IW_CQPSQ_RESUMEQP_QSHANDLE_SHIFT 0
981#define I40IW_CQPSQ_RESUMEQP_QSHANDLE_MASK \
982 (0xffffffffUL << I40IW_CQPSQ_RESUMEQP_QSHANDLE_SHIFT)
983
984#define I40IW_CQPSQ_RESUMEQP_QPID_SHIFT 0
985#define I40IW_CQPSQ_RESUMEQP_QPID_MASK (0x3FFFFUL)
986/* I40IWCQ_QPID_MASK */
987
988/* IW QP Context */
989#define I40IWQPC_DDP_VER_SHIFT 0
990#define I40IWQPC_DDP_VER_MASK (3UL << I40IWQPC_DDP_VER_SHIFT)
991
992#define I40IWQPC_SNAP_SHIFT 2
993#define I40IWQPC_SNAP_MASK (1UL << I40IWQPC_SNAP_SHIFT)
994
995#define I40IWQPC_IPV4_SHIFT 3
996#define I40IWQPC_IPV4_MASK (1UL << I40IWQPC_IPV4_SHIFT)
997
998#define I40IWQPC_NONAGLE_SHIFT 4
999#define I40IWQPC_NONAGLE_MASK (1UL << I40IWQPC_NONAGLE_SHIFT)
1000
1001#define I40IWQPC_INSERTVLANTAG_SHIFT 5
1002#define I40IWQPC_INSERTVLANTAG_MASK (1 << I40IWQPC_INSERTVLANTAG_SHIFT)
1003
1004#define I40IWQPC_USESRQ_SHIFT 6
1005#define I40IWQPC_USESRQ_MASK (1UL << I40IWQPC_USESRQ_SHIFT)
1006
1007#define I40IWQPC_TIMESTAMP_SHIFT 7
1008#define I40IWQPC_TIMESTAMP_MASK (1UL << I40IWQPC_TIMESTAMP_SHIFT)
1009
1010#define I40IWQPC_RQWQESIZE_SHIFT 8
1011#define I40IWQPC_RQWQESIZE_MASK (3UL << I40IWQPC_RQWQESIZE_SHIFT)
1012
1013#define I40IWQPC_INSERTL2TAG2_SHIFT 11
1014#define I40IWQPC_INSERTL2TAG2_MASK (1UL << I40IWQPC_INSERTL2TAG2_SHIFT)
1015
1016#define I40IWQPC_LIMIT_SHIFT 12
1017#define I40IWQPC_LIMIT_MASK (3UL << I40IWQPC_LIMIT_SHIFT)
1018
1019#define I40IWQPC_DROPOOOSEG_SHIFT 15
1020#define I40IWQPC_DROPOOOSEG_MASK (1UL << I40IWQPC_DROPOOOSEG_SHIFT)
1021
1022#define I40IWQPC_DUPACK_THRESH_SHIFT 16
1023#define I40IWQPC_DUPACK_THRESH_MASK (7UL << I40IWQPC_DUPACK_THRESH_SHIFT)
1024
1025#define I40IWQPC_ERR_RQ_IDX_VALID_SHIFT 19
1026#define I40IWQPC_ERR_RQ_IDX_VALID_MASK (1UL << I40IWQPC_ERR_RQ_IDX_VALID_SHIFT)
1027
1028#define I40IWQPC_DIS_VLAN_CHECKS_SHIFT 19
1029#define I40IWQPC_DIS_VLAN_CHECKS_MASK (7UL << I40IWQPC_DIS_VLAN_CHECKS_SHIFT)
1030
1031#define I40IWQPC_RCVTPHEN_SHIFT 28
1032#define I40IWQPC_RCVTPHEN_MASK (1UL << I40IWQPC_RCVTPHEN_SHIFT)
1033
1034#define I40IWQPC_XMITTPHEN_SHIFT 29
1035#define I40IWQPC_XMITTPHEN_MASK (1ULL << I40IWQPC_XMITTPHEN_SHIFT)
1036
1037#define I40IWQPC_RQTPHEN_SHIFT 30
1038#define I40IWQPC_RQTPHEN_MASK (1UL << I40IWQPC_RQTPHEN_SHIFT)
1039
1040#define I40IWQPC_SQTPHEN_SHIFT 31
1041#define I40IWQPC_SQTPHEN_MASK (1ULL << I40IWQPC_SQTPHEN_SHIFT)
1042
1043#define I40IWQPC_PPIDX_SHIFT 32
1044#define I40IWQPC_PPIDX_MASK (0x3ffULL << I40IWQPC_PPIDX_SHIFT)
1045
1046#define I40IWQPC_PMENA_SHIFT 47
1047#define I40IWQPC_PMENA_MASK (1ULL << I40IWQPC_PMENA_SHIFT)
1048
1049#define I40IWQPC_RDMAP_VER_SHIFT 62
1050#define I40IWQPC_RDMAP_VER_MASK (3ULL << I40IWQPC_RDMAP_VER_SHIFT)
1051
1052#define I40IWQPC_SQADDR_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1053#define I40IWQPC_SQADDR_MASK I40IW_CQPHC_QPCTX_MASK
1054
1055#define I40IWQPC_RQADDR_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1056#define I40IWQPC_RQADDR_MASK I40IW_CQPHC_QPCTX_MASK
1057
1058#define I40IWQPC_TTL_SHIFT 0
1059#define I40IWQPC_TTL_MASK (0xffUL << I40IWQPC_TTL_SHIFT)
1060
1061#define I40IWQPC_RQSIZE_SHIFT 8
1062#define I40IWQPC_RQSIZE_MASK (0xfUL << I40IWQPC_RQSIZE_SHIFT)
1063
1064#define I40IWQPC_SQSIZE_SHIFT 12
1065#define I40IWQPC_SQSIZE_MASK (0xfUL << I40IWQPC_SQSIZE_SHIFT)
1066
1067#define I40IWQPC_SRCMACADDRIDX_SHIFT 16
1068#define I40IWQPC_SRCMACADDRIDX_MASK (0x3fUL << I40IWQPC_SRCMACADDRIDX_SHIFT)
1069
1070#define I40IWQPC_AVOIDSTRETCHACK_SHIFT 23
1071#define I40IWQPC_AVOIDSTRETCHACK_MASK (1UL << I40IWQPC_AVOIDSTRETCHACK_SHIFT)
1072
1073#define I40IWQPC_TOS_SHIFT 24
1074#define I40IWQPC_TOS_MASK (0xffUL << I40IWQPC_TOS_SHIFT)
1075
1076#define I40IWQPC_SRCPORTNUM_SHIFT 32
1077#define I40IWQPC_SRCPORTNUM_MASK (0xffffULL << I40IWQPC_SRCPORTNUM_SHIFT)
1078
1079#define I40IWQPC_DESTPORTNUM_SHIFT 48
1080#define I40IWQPC_DESTPORTNUM_MASK (0xffffULL << I40IWQPC_DESTPORTNUM_SHIFT)
1081
1082#define I40IWQPC_DESTIPADDR0_SHIFT 32
1083#define I40IWQPC_DESTIPADDR0_MASK \
1084 (0xffffffffULL << I40IWQPC_DESTIPADDR0_SHIFT)
1085
1086#define I40IWQPC_DESTIPADDR1_SHIFT 0
1087#define I40IWQPC_DESTIPADDR1_MASK \
1088 (0xffffffffULL << I40IWQPC_DESTIPADDR1_SHIFT)
1089
1090#define I40IWQPC_DESTIPADDR2_SHIFT 32
1091#define I40IWQPC_DESTIPADDR2_MASK \
1092 (0xffffffffULL << I40IWQPC_DESTIPADDR2_SHIFT)
1093
1094#define I40IWQPC_DESTIPADDR3_SHIFT 0
1095#define I40IWQPC_DESTIPADDR3_MASK \
1096 (0xffffffffULL << I40IWQPC_DESTIPADDR3_SHIFT)
1097
1098#define I40IWQPC_SNDMSS_SHIFT 16
1099#define I40IWQPC_SNDMSS_MASK (0x3fffUL << I40IWQPC_SNDMSS_SHIFT)
1100
1101#define I40IWQPC_VLANTAG_SHIFT 32
1102#define I40IWQPC_VLANTAG_MASK (0xffffULL << I40IWQPC_VLANTAG_SHIFT)
1103
1104#define I40IWQPC_ARPIDX_SHIFT 48
1105#define I40IWQPC_ARPIDX_MASK (0xfffULL << I40IWQPC_ARPIDX_SHIFT)
1106
1107#define I40IWQPC_FLOWLABEL_SHIFT 0
1108#define I40IWQPC_FLOWLABEL_MASK (0xfffffUL << I40IWQPC_FLOWLABEL_SHIFT)
1109
1110#define I40IWQPC_WSCALE_SHIFT 20
1111#define I40IWQPC_WSCALE_MASK (1UL << I40IWQPC_WSCALE_SHIFT)
1112
1113#define I40IWQPC_KEEPALIVE_SHIFT 21
1114#define I40IWQPC_KEEPALIVE_MASK (1UL << I40IWQPC_KEEPALIVE_SHIFT)
1115
1116#define I40IWQPC_IGNORE_TCP_OPT_SHIFT 22
1117#define I40IWQPC_IGNORE_TCP_OPT_MASK (1UL << I40IWQPC_IGNORE_TCP_OPT_SHIFT)
1118
1119#define I40IWQPC_IGNORE_TCP_UNS_OPT_SHIFT 23
1120#define I40IWQPC_IGNORE_TCP_UNS_OPT_MASK \
1121 (1UL << I40IWQPC_IGNORE_TCP_UNS_OPT_SHIFT)
1122
1123#define I40IWQPC_TCPSTATE_SHIFT 28
1124#define I40IWQPC_TCPSTATE_MASK (0xfUL << I40IWQPC_TCPSTATE_SHIFT)
1125
1126#define I40IWQPC_RCVSCALE_SHIFT 32
1127#define I40IWQPC_RCVSCALE_MASK (0xfULL << I40IWQPC_RCVSCALE_SHIFT)
1128
1129#define I40IWQPC_SNDSCALE_SHIFT 40
1130#define I40IWQPC_SNDSCALE_MASK (0xfULL << I40IWQPC_SNDSCALE_SHIFT)
1131
1132#define I40IWQPC_PDIDX_SHIFT 48
1133#define I40IWQPC_PDIDX_MASK (0x7fffULL << I40IWQPC_PDIDX_SHIFT)
1134
1135#define I40IWQPC_KALIVE_TIMER_MAX_PROBES_SHIFT 16
1136#define I40IWQPC_KALIVE_TIMER_MAX_PROBES_MASK \
1137 (0xffUL << I40IWQPC_KALIVE_TIMER_MAX_PROBES_SHIFT)
1138
1139#define I40IWQPC_KEEPALIVE_INTERVAL_SHIFT 24
1140#define I40IWQPC_KEEPALIVE_INTERVAL_MASK \
1141 (0xffUL << I40IWQPC_KEEPALIVE_INTERVAL_SHIFT)
1142
1143#define I40IWQPC_TIMESTAMP_RECENT_SHIFT 0
1144#define I40IWQPC_TIMESTAMP_RECENT_MASK \
1145 (0xffffffffUL << I40IWQPC_TIMESTAMP_RECENT_SHIFT)
1146
1147#define I40IWQPC_TIMESTAMP_AGE_SHIFT 32
1148#define I40IWQPC_TIMESTAMP_AGE_MASK \
1149 (0xffffffffULL << I40IWQPC_TIMESTAMP_AGE_SHIFT)
1150
1151#define I40IWQPC_SNDNXT_SHIFT 0
1152#define I40IWQPC_SNDNXT_MASK (0xffffffffUL << I40IWQPC_SNDNXT_SHIFT)
1153
1154#define I40IWQPC_SNDWND_SHIFT 32
1155#define I40IWQPC_SNDWND_MASK (0xffffffffULL << I40IWQPC_SNDWND_SHIFT)
1156
1157#define I40IWQPC_RCVNXT_SHIFT 0
1158#define I40IWQPC_RCVNXT_MASK (0xffffffffUL << I40IWQPC_RCVNXT_SHIFT)
1159
1160#define I40IWQPC_RCVWND_SHIFT 32
1161#define I40IWQPC_RCVWND_MASK (0xffffffffULL << I40IWQPC_RCVWND_SHIFT)
1162
1163#define I40IWQPC_SNDMAX_SHIFT 0
1164#define I40IWQPC_SNDMAX_MASK (0xffffffffUL << I40IWQPC_SNDMAX_SHIFT)
1165
1166#define I40IWQPC_SNDUNA_SHIFT 32
1167#define I40IWQPC_SNDUNA_MASK (0xffffffffULL << I40IWQPC_SNDUNA_SHIFT)
1168
1169#define I40IWQPC_SRTT_SHIFT 0
1170#define I40IWQPC_SRTT_MASK (0xffffffffUL << I40IWQPC_SRTT_SHIFT)
1171
1172#define I40IWQPC_RTTVAR_SHIFT 32
1173#define I40IWQPC_RTTVAR_MASK (0xffffffffULL << I40IWQPC_RTTVAR_SHIFT)
1174
1175#define I40IWQPC_SSTHRESH_SHIFT 0
1176#define I40IWQPC_SSTHRESH_MASK (0xffffffffUL << I40IWQPC_SSTHRESH_SHIFT)
1177
1178#define I40IWQPC_CWND_SHIFT 32
1179#define I40IWQPC_CWND_MASK (0xffffffffULL << I40IWQPC_CWND_SHIFT)
1180
1181#define I40IWQPC_SNDWL1_SHIFT 0
1182#define I40IWQPC_SNDWL1_MASK (0xffffffffUL << I40IWQPC_SNDWL1_SHIFT)
1183
1184#define I40IWQPC_SNDWL2_SHIFT 32
1185#define I40IWQPC_SNDWL2_MASK (0xffffffffULL << I40IWQPC_SNDWL2_SHIFT)
1186
1187#define I40IWQPC_ERR_RQ_IDX_SHIFT 32
1188#define I40IWQPC_ERR_RQ_IDX_MASK (0x3fffULL << I40IWQPC_ERR_RQ_IDX_SHIFT)
1189
1190#define I40IWQPC_MAXSNDWND_SHIFT 0
1191#define I40IWQPC_MAXSNDWND_MASK (0xffffffffUL << I40IWQPC_MAXSNDWND_SHIFT)
1192
1193#define I40IWQPC_REXMIT_THRESH_SHIFT 48
1194#define I40IWQPC_REXMIT_THRESH_MASK (0x3fULL << I40IWQPC_REXMIT_THRESH_SHIFT)
1195
1196#define I40IWQPC_TXCQNUM_SHIFT 0
1197#define I40IWQPC_TXCQNUM_MASK (0x1ffffUL << I40IWQPC_TXCQNUM_SHIFT)
1198
1199#define I40IWQPC_RXCQNUM_SHIFT 32
1200#define I40IWQPC_RXCQNUM_MASK (0x1ffffULL << I40IWQPC_RXCQNUM_SHIFT)
1201
1202#define I40IWQPC_Q2ADDR_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1203#define I40IWQPC_Q2ADDR_MASK I40IW_CQPHC_QPCTX_MASK
1204
1205#define I40IWQPC_LASTBYTESENT_SHIFT 0
1206#define I40IWQPC_LASTBYTESENT_MASK (0xffUL << I40IWQPC_LASTBYTESENT_SHIFT)
1207
1208#define I40IWQPC_SRQID_SHIFT 32
1209#define I40IWQPC_SRQID_MASK (0xffULL << I40IWQPC_SRQID_SHIFT)
1210
1211#define I40IWQPC_ORDSIZE_SHIFT 0
1212#define I40IWQPC_ORDSIZE_MASK (0x7fUL << I40IWQPC_ORDSIZE_SHIFT)
1213
1214#define I40IWQPC_IRDSIZE_SHIFT 16
1215#define I40IWQPC_IRDSIZE_MASK (0x3UL << I40IWQPC_IRDSIZE_SHIFT)
1216
1217#define I40IWQPC_WRRDRSPOK_SHIFT 20
1218#define I40IWQPC_WRRDRSPOK_MASK (1UL << I40IWQPC_WRRDRSPOK_SHIFT)
1219
1220#define I40IWQPC_RDOK_SHIFT 21
1221#define I40IWQPC_RDOK_MASK (1UL << I40IWQPC_RDOK_SHIFT)
1222
1223#define I40IWQPC_SNDMARKERS_SHIFT 22
1224#define I40IWQPC_SNDMARKERS_MASK (1UL << I40IWQPC_SNDMARKERS_SHIFT)
1225
1226#define I40IWQPC_BINDEN_SHIFT 23
1227#define I40IWQPC_BINDEN_MASK (1UL << I40IWQPC_BINDEN_SHIFT)
1228
1229#define I40IWQPC_FASTREGEN_SHIFT 24
1230#define I40IWQPC_FASTREGEN_MASK (1UL << I40IWQPC_FASTREGEN_SHIFT)
1231
1232#define I40IWQPC_PRIVEN_SHIFT 25
1233#define I40IWQPC_PRIVEN_MASK (1UL << I40IWQPC_PRIVEN_SHIFT)
1234
1235#define I40IWQPC_LSMMPRESENT_SHIFT 26
1236#define I40IWQPC_LSMMPRESENT_MASK (1UL << I40IWQPC_LSMMPRESENT_SHIFT)
1237
1238#define I40IWQPC_ADJUSTFORLSMM_SHIFT 27
1239#define I40IWQPC_ADJUSTFORLSMM_MASK (1UL << I40IWQPC_ADJUSTFORLSMM_SHIFT)
1240
1241#define I40IWQPC_IWARPMODE_SHIFT 28
1242#define I40IWQPC_IWARPMODE_MASK (1UL << I40IWQPC_IWARPMODE_SHIFT)
1243
1244#define I40IWQPC_RCVMARKERS_SHIFT 29
1245#define I40IWQPC_RCVMARKERS_MASK (1UL << I40IWQPC_RCVMARKERS_SHIFT)
1246
1247#define I40IWQPC_ALIGNHDRS_SHIFT 30
1248#define I40IWQPC_ALIGNHDRS_MASK (1UL << I40IWQPC_ALIGNHDRS_SHIFT)
1249
1250#define I40IWQPC_RCVNOMPACRC_SHIFT 31
1251#define I40IWQPC_RCVNOMPACRC_MASK (1UL << I40IWQPC_RCVNOMPACRC_SHIFT)
1252
1253#define I40IWQPC_RCVMARKOFFSET_SHIFT 33
1254#define I40IWQPC_RCVMARKOFFSET_MASK (0x1ffULL << I40IWQPC_RCVMARKOFFSET_SHIFT)
1255
1256#define I40IWQPC_SNDMARKOFFSET_SHIFT 48
1257#define I40IWQPC_SNDMARKOFFSET_MASK (0x1ffULL << I40IWQPC_SNDMARKOFFSET_SHIFT)
1258
1259#define I40IWQPC_QPCOMPCTX_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1260#define I40IWQPC_QPCOMPCTX_MASK I40IW_CQPHC_QPCTX_MASK
1261
1262#define I40IWQPC_SQTPHVAL_SHIFT 0
1263#define I40IWQPC_SQTPHVAL_MASK (0xffUL << I40IWQPC_SQTPHVAL_SHIFT)
1264
1265#define I40IWQPC_RQTPHVAL_SHIFT 8
1266#define I40IWQPC_RQTPHVAL_MASK (0xffUL << I40IWQPC_RQTPHVAL_SHIFT)
1267
1268#define I40IWQPC_QSHANDLE_SHIFT 16
1269#define I40IWQPC_QSHANDLE_MASK (0x3ffUL << I40IWQPC_QSHANDLE_SHIFT)
1270
1271#define I40IWQPC_EXCEPTION_LAN_QUEUE_SHIFT 32
1272#define I40IWQPC_EXCEPTION_LAN_QUEUE_MASK (0xfffULL << \
1273 I40IWQPC_EXCEPTION_LAN_QUEUE_SHIFT)
1274
1275#define I40IWQPC_LOCAL_IPADDR3_SHIFT 0
1276#define I40IWQPC_LOCAL_IPADDR3_MASK \
1277 (0xffffffffUL << I40IWQPC_LOCAL_IPADDR3_SHIFT)
1278
1279#define I40IWQPC_LOCAL_IPADDR2_SHIFT 32
1280#define I40IWQPC_LOCAL_IPADDR2_MASK \
1281 (0xffffffffULL << I40IWQPC_LOCAL_IPADDR2_SHIFT)
1282
1283#define I40IWQPC_LOCAL_IPADDR1_SHIFT 0
1284#define I40IWQPC_LOCAL_IPADDR1_MASK \
1285 (0xffffffffUL << I40IWQPC_LOCAL_IPADDR1_SHIFT)
1286
1287#define I40IWQPC_LOCAL_IPADDR0_SHIFT 32
1288#define I40IWQPC_LOCAL_IPADDR0_MASK \
1289 (0xffffffffULL << I40IWQPC_LOCAL_IPADDR0_SHIFT)
1290
1291/* wqe size considering 32 bytes per wqe*/
1292#define I40IWQP_SW_MIN_WQSIZE 4 /* 128 bytes */
1293#define I40IWQP_SW_MAX_WQSIZE 16384 /* 524288 bytes */
1294
1295#define I40IWQP_OP_RDMA_WRITE 0
1296#define I40IWQP_OP_RDMA_READ 1
1297#define I40IWQP_OP_RDMA_SEND 3
1298#define I40IWQP_OP_RDMA_SEND_INV 4
1299#define I40IWQP_OP_RDMA_SEND_SOL_EVENT 5
1300#define I40IWQP_OP_RDMA_SEND_SOL_EVENT_INV 6
1301#define I40IWQP_OP_BIND_MW 8
1302#define I40IWQP_OP_FAST_REGISTER 9
1303#define I40IWQP_OP_LOCAL_INVALIDATE 10
1304#define I40IWQP_OP_RDMA_READ_LOC_INV 11
1305#define I40IWQP_OP_NOP 12
1306
1307#define I40IW_RSVD_SHIFT 41
1308#define I40IW_RSVD_MASK (0x7fffULL << I40IW_RSVD_SHIFT)
1309
1310/* iwarp QP SQ WQE common fields */
1311#define I40IWQPSQ_OPCODE_SHIFT 32
1312#define I40IWQPSQ_OPCODE_MASK (0x3fULL << I40IWQPSQ_OPCODE_SHIFT)
1313
1314#define I40IWQPSQ_ADDFRAGCNT_SHIFT 38
1315#define I40IWQPSQ_ADDFRAGCNT_MASK (0x7ULL << I40IWQPSQ_ADDFRAGCNT_SHIFT)
1316
1317#define I40IWQPSQ_PUSHWQE_SHIFT 56
1318#define I40IWQPSQ_PUSHWQE_MASK (1ULL << I40IWQPSQ_PUSHWQE_SHIFT)
1319
1320#define I40IWQPSQ_STREAMMODE_SHIFT 58
1321#define I40IWQPSQ_STREAMMODE_MASK (1ULL << I40IWQPSQ_STREAMMODE_SHIFT)
1322
1323#define I40IWQPSQ_WAITFORRCVPDU_SHIFT 59
1324#define I40IWQPSQ_WAITFORRCVPDU_MASK (1ULL << I40IWQPSQ_WAITFORRCVPDU_SHIFT)
1325
1326#define I40IWQPSQ_READFENCE_SHIFT 60
1327#define I40IWQPSQ_READFENCE_MASK (1ULL << I40IWQPSQ_READFENCE_SHIFT)
1328
1329#define I40IWQPSQ_LOCALFENCE_SHIFT 61
1330#define I40IWQPSQ_LOCALFENCE_MASK (1ULL << I40IWQPSQ_LOCALFENCE_SHIFT)
1331
1332#define I40IWQPSQ_SIGCOMPL_SHIFT 62
1333#define I40IWQPSQ_SIGCOMPL_MASK (1ULL << I40IWQPSQ_SIGCOMPL_SHIFT)
1334
1335#define I40IWQPSQ_VALID_SHIFT 63
1336#define I40IWQPSQ_VALID_MASK (1ULL << I40IWQPSQ_VALID_SHIFT)
1337
1338#define I40IWQPSQ_FRAG_TO_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1339#define I40IWQPSQ_FRAG_TO_MASK I40IW_CQPHC_QPCTX_MASK
1340
1341#define I40IWQPSQ_FRAG_LEN_SHIFT 0
1342#define I40IWQPSQ_FRAG_LEN_MASK (0xffffffffUL << I40IWQPSQ_FRAG_LEN_SHIFT)
1343
1344#define I40IWQPSQ_FRAG_STAG_SHIFT 32
1345#define I40IWQPSQ_FRAG_STAG_MASK (0xffffffffULL << I40IWQPSQ_FRAG_STAG_SHIFT)
1346
1347#define I40IWQPSQ_REMSTAGINV_SHIFT 0
1348#define I40IWQPSQ_REMSTAGINV_MASK (0xffffffffUL << I40IWQPSQ_REMSTAGINV_SHIFT)
1349
1350#define I40IWQPSQ_INLINEDATAFLAG_SHIFT 57
1351#define I40IWQPSQ_INLINEDATAFLAG_MASK (1ULL << I40IWQPSQ_INLINEDATAFLAG_SHIFT)
1352
1353#define I40IWQPSQ_INLINEDATALEN_SHIFT 48
1354#define I40IWQPSQ_INLINEDATALEN_MASK \
1355 (0x7fULL << I40IWQPSQ_INLINEDATALEN_SHIFT)
1356
1357/* iwarp send with push mode */
1358#define I40IWQPSQ_WQDESCIDX_SHIFT 0
1359#define I40IWQPSQ_WQDESCIDX_MASK (0x3fffUL << I40IWQPSQ_WQDESCIDX_SHIFT)
1360
1361/* rdma write */
1362#define I40IWQPSQ_REMSTAG_SHIFT 0
1363#define I40IWQPSQ_REMSTAG_MASK (0xffffffffUL << I40IWQPSQ_REMSTAG_SHIFT)
1364
1365#define I40IWQPSQ_REMTO_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1366#define I40IWQPSQ_REMTO_MASK I40IW_CQPHC_QPCTX_MASK
1367
1368/* memory window */
1369#define I40IWQPSQ_STAGRIGHTS_SHIFT 48
1370#define I40IWQPSQ_STAGRIGHTS_MASK (0x1fULL << I40IWQPSQ_STAGRIGHTS_SHIFT)
1371
1372#define I40IWQPSQ_VABASEDTO_SHIFT 53
1373#define I40IWQPSQ_VABASEDTO_MASK (1ULL << I40IWQPSQ_VABASEDTO_SHIFT)
1374
1375#define I40IWQPSQ_MWLEN_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1376#define I40IWQPSQ_MWLEN_MASK I40IW_CQPHC_QPCTX_MASK
1377
1378#define I40IWQPSQ_PARENTMRSTAG_SHIFT 0
1379#define I40IWQPSQ_PARENTMRSTAG_MASK \
1380 (0xffffffffUL << I40IWQPSQ_PARENTMRSTAG_SHIFT)
1381
1382#define I40IWQPSQ_MWSTAG_SHIFT 32
1383#define I40IWQPSQ_MWSTAG_MASK (0xffffffffULL << I40IWQPSQ_MWSTAG_SHIFT)
1384
1385#define I40IWQPSQ_BASEVA_TO_FBO_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1386#define I40IWQPSQ_BASEVA_TO_FBO_MASK I40IW_CQPHC_QPCTX_MASK
1387
1388/* Local Invalidate */
1389#define I40IWQPSQ_LOCSTAG_SHIFT 32
1390#define I40IWQPSQ_LOCSTAG_MASK (0xffffffffULL << I40IWQPSQ_LOCSTAG_SHIFT)
1391
1392/* Fast Register */
1393#define I40IWQPSQ_STAGKEY_SHIFT 0
1394#define I40IWQPSQ_STAGKEY_MASK (0xffUL << I40IWQPSQ_STAGKEY_SHIFT)
1395
1396#define I40IWQPSQ_STAGINDEX_SHIFT 8
1397#define I40IWQPSQ_STAGINDEX_MASK (0xffffffUL << I40IWQPSQ_STAGINDEX_SHIFT)
1398
1399#define I40IWQPSQ_COPYHOSTPBLS_SHIFT 43
1400#define I40IWQPSQ_COPYHOSTPBLS_MASK (1ULL << I40IWQPSQ_COPYHOSTPBLS_SHIFT)
1401
1402#define I40IWQPSQ_LPBLSIZE_SHIFT 44
1403#define I40IWQPSQ_LPBLSIZE_MASK (3ULL << I40IWQPSQ_LPBLSIZE_SHIFT)
1404
1405#define I40IWQPSQ_HPAGESIZE_SHIFT 46
1406#define I40IWQPSQ_HPAGESIZE_MASK (3ULL << I40IWQPSQ_HPAGESIZE_SHIFT)
1407
1408#define I40IWQPSQ_STAGLEN_SHIFT 0
1409#define I40IWQPSQ_STAGLEN_MASK (0x1ffffffffffULL << I40IWQPSQ_STAGLEN_SHIFT)
1410
1411#define I40IWQPSQ_FIRSTPMPBLIDXLO_SHIFT 48
1412#define I40IWQPSQ_FIRSTPMPBLIDXLO_MASK \
1413 (0xffffULL << I40IWQPSQ_FIRSTPMPBLIDXLO_SHIFT)
1414
1415#define I40IWQPSQ_FIRSTPMPBLIDXHI_SHIFT 0
1416#define I40IWQPSQ_FIRSTPMPBLIDXHI_MASK \
1417 (0xfffUL << I40IWQPSQ_FIRSTPMPBLIDXHI_SHIFT)
1418
1419#define I40IWQPSQ_PBLADDR_SHIFT 12
1420#define I40IWQPSQ_PBLADDR_MASK (0xfffffffffffffULL << I40IWQPSQ_PBLADDR_SHIFT)
1421
1422/* iwarp QP RQ WQE common fields */
1423#define I40IWQPRQ_ADDFRAGCNT_SHIFT I40IWQPSQ_ADDFRAGCNT_SHIFT
1424#define I40IWQPRQ_ADDFRAGCNT_MASK I40IWQPSQ_ADDFRAGCNT_MASK
1425
1426#define I40IWQPRQ_VALID_SHIFT I40IWQPSQ_VALID_SHIFT
1427#define I40IWQPRQ_VALID_MASK I40IWQPSQ_VALID_MASK
1428
1429#define I40IWQPRQ_COMPLCTX_SHIFT I40IW_CQPHC_QPCTX_SHIFT
1430#define I40IWQPRQ_COMPLCTX_MASK I40IW_CQPHC_QPCTX_MASK
1431
1432#define I40IWQPRQ_FRAG_LEN_SHIFT I40IWQPSQ_FRAG_LEN_SHIFT
1433#define I40IWQPRQ_FRAG_LEN_MASK I40IWQPSQ_FRAG_LEN_MASK
1434
1435#define I40IWQPRQ_STAG_SHIFT I40IWQPSQ_FRAG_STAG_SHIFT
1436#define I40IWQPRQ_STAG_MASK I40IWQPSQ_FRAG_STAG_MASK
1437
1438#define I40IWQPRQ_TO_SHIFT I40IWQPSQ_FRAG_TO_SHIFT
1439#define I40IWQPRQ_TO_MASK I40IWQPSQ_FRAG_TO_MASK
1440
1441/* Query FPM CQP buf */
1442#define I40IW_QUERY_FPM_MAX_QPS_SHIFT 0
1443#define I40IW_QUERY_FPM_MAX_QPS_MASK \
1444 (0x7ffffUL << I40IW_QUERY_FPM_MAX_QPS_SHIFT)
1445
1446#define I40IW_QUERY_FPM_MAX_CQS_SHIFT 0
1447#define I40IW_QUERY_FPM_MAX_CQS_MASK \
1448 (0x3ffffUL << I40IW_QUERY_FPM_MAX_CQS_SHIFT)
1449
1450#define I40IW_QUERY_FPM_FIRST_PE_SD_INDEX_SHIFT 0
1451#define I40IW_QUERY_FPM_FIRST_PE_SD_INDEX_MASK \
1452 (0x3fffUL << I40IW_QUERY_FPM_FIRST_PE_SD_INDEX_SHIFT)
1453
1454#define I40IW_QUERY_FPM_MAX_PE_SDS_SHIFT 32
1455#define I40IW_QUERY_FPM_MAX_PE_SDS_MASK \
1456 (0x3fffULL << I40IW_QUERY_FPM_MAX_PE_SDS_SHIFT)
1457
1458#define I40IW_QUERY_FPM_MAX_QPS_SHIFT 0
1459#define I40IW_QUERY_FPM_MAX_QPS_MASK \
1460 (0x7ffffUL << I40IW_QUERY_FPM_MAX_QPS_SHIFT)
1461
1462#define I40IW_QUERY_FPM_MAX_CQS_SHIFT 0
1463#define I40IW_QUERY_FPM_MAX_CQS_MASK \
1464 (0x3ffffUL << I40IW_QUERY_FPM_MAX_CQS_SHIFT)
1465
1466#define I40IW_QUERY_FPM_MAX_CEQS_SHIFT 0
1467#define I40IW_QUERY_FPM_MAX_CEQS_MASK \
1468 (0xffUL << I40IW_QUERY_FPM_MAX_CEQS_SHIFT)
1469
1470#define I40IW_QUERY_FPM_XFBLOCKSIZE_SHIFT 32
1471#define I40IW_QUERY_FPM_XFBLOCKSIZE_MASK \
1472 (0xffffffffULL << I40IW_QUERY_FPM_XFBLOCKSIZE_SHIFT)
1473
1474#define I40IW_QUERY_FPM_Q1BLOCKSIZE_SHIFT 32
1475#define I40IW_QUERY_FPM_Q1BLOCKSIZE_MASK \
1476 (0xffffffffULL << I40IW_QUERY_FPM_Q1BLOCKSIZE_SHIFT)
1477
1478#define I40IW_QUERY_FPM_HTMULTIPLIER_SHIFT 16
1479#define I40IW_QUERY_FPM_HTMULTIPLIER_MASK \
1480 (0xfUL << I40IW_QUERY_FPM_HTMULTIPLIER_SHIFT)
1481
1482#define I40IW_QUERY_FPM_TIMERBUCKET_SHIFT 32
1483#define I40IW_QUERY_FPM_TIMERBUCKET_MASK \
1484 (0xffFFULL << I40IW_QUERY_FPM_TIMERBUCKET_SHIFT)
1485
1486/* Static HMC pages allocated buf */
1487#define I40IW_SHMC_PAGE_ALLOCATED_HMC_FN_ID_SHIFT 0
1488#define I40IW_SHMC_PAGE_ALLOCATED_HMC_FN_ID_MASK \
1489 (0x3fUL << I40IW_SHMC_PAGE_ALLOCATED_HMC_FN_ID_SHIFT)
1490
1491#define I40IW_HW_PAGE_SIZE 4096
1492#define I40IW_DONE_COUNT 1000
1493#define I40IW_SLEEP_COUNT 10
1494
1495enum {
1496 I40IW_QUEUES_ALIGNMENT_MASK = (128 - 1),
1497 I40IW_AEQ_ALIGNMENT_MASK = (256 - 1),
1498 I40IW_Q2_ALIGNMENT_MASK = (256 - 1),
1499 I40IW_CEQ_ALIGNMENT_MASK = (256 - 1),
1500 I40IW_CQ0_ALIGNMENT_MASK = (256 - 1),
1501 I40IW_HOST_CTX_ALIGNMENT_MASK = (4 - 1),
1502 I40IW_SHADOWAREA_MASK = (128 - 1),
1503 I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK = 0,
1504 I40IW_FPM_COMMIT_BUF_ALIGNMENT_MASK = 0
1505};
1506
1507enum i40iw_alignment {
1508 I40IW_CQP_ALIGNMENT = 0x200,
1509 I40IW_AEQ_ALIGNMENT = 0x100,
1510 I40IW_CEQ_ALIGNMENT = 0x100,
1511 I40IW_CQ0_ALIGNMENT = 0x100,
1512 I40IW_SD_BUF_ALIGNMENT = 0x100
1513};
1514
1515#define I40IW_QP_WQE_MIN_SIZE 32
1516#define I40IW_QP_WQE_MAX_SIZE 128
1517
1518#define I40IW_CQE_QTYPE_RQ 0
1519#define I40IW_CQE_QTYPE_SQ 1
1520
1521#define I40IW_RING_INIT(_ring, _size) \
1522 { \
1523 (_ring).head = 0; \
1524 (_ring).tail = 0; \
1525 (_ring).size = (_size); \
1526 }
1527#define I40IW_RING_GETSIZE(_ring) ((_ring).size)
1528#define I40IW_RING_GETCURRENT_HEAD(_ring) ((_ring).head)
1529#define I40IW_RING_GETCURRENT_TAIL(_ring) ((_ring).tail)
1530
1531#define I40IW_RING_MOVE_HEAD(_ring, _retcode) \
1532 { \
1533 register u32 size; \
1534 size = (_ring).size; \
1535 if (!I40IW_RING_FULL_ERR(_ring)) { \
1536 (_ring).head = ((_ring).head + 1) % size; \
1537 (_retcode) = 0; \
1538 } else { \
1539 (_retcode) = I40IW_ERR_RING_FULL; \
1540 } \
1541 }
1542
1543#define I40IW_RING_MOVE_HEAD_BY_COUNT(_ring, _count, _retcode) \
1544 { \
1545 register u32 size; \
1546 size = (_ring).size; \
1547 if ((I40IW_RING_WORK_AVAILABLE(_ring) + (_count)) < size) { \
1548 (_ring).head = ((_ring).head + (_count)) % size; \
1549 (_retcode) = 0; \
1550 } else { \
1551 (_retcode) = I40IW_ERR_RING_FULL; \
1552 } \
1553 }
1554
1555#define I40IW_RING_MOVE_TAIL(_ring) \
1556 (_ring).tail = ((_ring).tail + 1) % (_ring).size
1557
1558#define I40IW_RING_MOVE_TAIL_BY_COUNT(_ring, _count) \
1559 (_ring).tail = ((_ring).tail + (_count)) % (_ring).size
1560
1561#define I40IW_RING_SET_TAIL(_ring, _pos) \
1562 (_ring).tail = (_pos) % (_ring).size
1563
1564#define I40IW_RING_FULL_ERR(_ring) \
1565 ( \
1566 (I40IW_RING_WORK_AVAILABLE(_ring) == ((_ring).size - 1)) \
1567 )
1568
1569#define I40IW_ERR_RING_FULL2(_ring) \
1570 ( \
1571 (I40IW_RING_WORK_AVAILABLE(_ring) == ((_ring).size - 2)) \
1572 )
1573
1574#define I40IW_ERR_RING_FULL3(_ring) \
1575 ( \
1576 (I40IW_RING_WORK_AVAILABLE(_ring) == ((_ring).size - 3)) \
1577 )
1578
1579#define I40IW_RING_MORE_WORK(_ring) \
1580 ( \
1581 (I40IW_RING_WORK_AVAILABLE(_ring) != 0) \
1582 )
1583
1584#define I40IW_RING_WORK_AVAILABLE(_ring) \
1585 ( \
1586 (((_ring).head + (_ring).size - (_ring).tail) % (_ring).size) \
1587 )
1588
1589#define I40IW_RING_GET_WQES_AVAILABLE(_ring) \
1590 ( \
1591 ((_ring).size - I40IW_RING_WORK_AVAILABLE(_ring) - 1) \
1592 )
1593
1594#define I40IW_ATOMIC_RING_MOVE_HEAD(_ring, index, _retcode) \
1595 { \
1596 index = I40IW_RING_GETCURRENT_HEAD(_ring); \
1597 I40IW_RING_MOVE_HEAD(_ring, _retcode); \
1598 }
1599
1600/* Async Events codes */
1601#define I40IW_AE_AMP_UNALLOCATED_STAG 0x0102
1602#define I40IW_AE_AMP_INVALID_STAG 0x0103
1603#define I40IW_AE_AMP_BAD_QP 0x0104
1604#define I40IW_AE_AMP_BAD_PD 0x0105
1605#define I40IW_AE_AMP_BAD_STAG_KEY 0x0106
1606#define I40IW_AE_AMP_BAD_STAG_INDEX 0x0107
1607#define I40IW_AE_AMP_BOUNDS_VIOLATION 0x0108
1608#define I40IW_AE_AMP_RIGHTS_VIOLATION 0x0109
1609#define I40IW_AE_AMP_TO_WRAP 0x010a
1610#define I40IW_AE_AMP_FASTREG_SHARED 0x010b
1611#define I40IW_AE_AMP_FASTREG_VALID_STAG 0x010c
1612#define I40IW_AE_AMP_FASTREG_MW_STAG 0x010d
1613#define I40IW_AE_AMP_FASTREG_INVALID_RIGHTS 0x010e
1614#define I40IW_AE_AMP_FASTREG_PBL_TABLE_OVERFLOW 0x010f
1615#define I40IW_AE_AMP_FASTREG_INVALID_LENGTH 0x0110
1616#define I40IW_AE_AMP_INVALIDATE_SHARED 0x0111
1617#define I40IW_AE_AMP_INVALIDATE_NO_REMOTE_ACCESS_RIGHTS 0x0112
1618#define I40IW_AE_AMP_INVALIDATE_MR_WITH_BOUND_WINDOWS 0x0113
1619#define I40IW_AE_AMP_MWBIND_VALID_STAG 0x0114
1620#define I40IW_AE_AMP_MWBIND_OF_MR_STAG 0x0115
1621#define I40IW_AE_AMP_MWBIND_TO_ZERO_BASED_STAG 0x0116
1622#define I40IW_AE_AMP_MWBIND_TO_MW_STAG 0x0117
1623#define I40IW_AE_AMP_MWBIND_INVALID_RIGHTS 0x0118
1624#define I40IW_AE_AMP_MWBIND_INVALID_BOUNDS 0x0119
1625#define I40IW_AE_AMP_MWBIND_TO_INVALID_PARENT 0x011a
1626#define I40IW_AE_AMP_MWBIND_BIND_DISABLED 0x011b
1627#define I40IW_AE_AMP_WQE_INVALID_PARAMETER 0x0130
1628#define I40IW_AE_BAD_CLOSE 0x0201
1629#define I40IW_AE_RDMAP_ROE_BAD_LLP_CLOSE 0x0202
1630#define I40IW_AE_CQ_OPERATION_ERROR 0x0203
1631#define I40IW_AE_PRIV_OPERATION_DENIED 0x011c
1632#define I40IW_AE_RDMA_READ_WHILE_ORD_ZERO 0x0205
1633#define I40IW_AE_STAG_ZERO_INVALID 0x0206
1634#define I40IW_AE_IB_RREQ_AND_Q1_FULL 0x0207
1635#define I40IW_AE_SRQ_LIMIT 0x0209
1636#define I40IW_AE_WQE_UNEXPECTED_OPCODE 0x020a
1637#define I40IW_AE_WQE_INVALID_PARAMETER 0x020b
1638#define I40IW_AE_WQE_LSMM_TOO_LONG 0x0220
1639#define I40IW_AE_DDP_INVALID_MSN_GAP_IN_MSN 0x0301
1640#define I40IW_AE_DDP_INVALID_MSN_RANGE_IS_NOT_VALID 0x0302
1641#define I40IW_AE_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER 0x0303
1642#define I40IW_AE_DDP_UBE_INVALID_DDP_VERSION 0x0304
1643#define I40IW_AE_DDP_UBE_INVALID_MO 0x0305
1644#define I40IW_AE_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE 0x0306
1645#define I40IW_AE_DDP_UBE_INVALID_QN 0x0307
1646#define I40IW_AE_DDP_NO_L_BIT 0x0308
1647#define I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION 0x0311
1648#define I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE 0x0312
1649#define I40IW_AE_ROE_INVALID_RDMA_READ_REQUEST 0x0313
1650#define I40IW_AE_ROE_INVALID_RDMA_WRITE_OR_READ_RESP 0x0314
1651#define I40IW_AE_INVALID_ARP_ENTRY 0x0401
1652#define I40IW_AE_INVALID_TCP_OPTION_RCVD 0x0402
1653#define I40IW_AE_STALE_ARP_ENTRY 0x0403
1654#define I40IW_AE_INVALID_WQE_LENGTH 0x0404
1655#define I40IW_AE_INVALID_MAC_ENTRY 0x0405
1656#define I40IW_AE_LLP_CLOSE_COMPLETE 0x0501
1657#define I40IW_AE_LLP_CONNECTION_RESET 0x0502
1658#define I40IW_AE_LLP_FIN_RECEIVED 0x0503
1659#define I40IW_AE_LLP_RECEIVED_MARKER_AND_LENGTH_FIELDS_DONT_MATCH 0x0504
1660#define I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR 0x0505
1661#define I40IW_AE_LLP_SEGMENT_TOO_LARGE 0x0506
1662#define I40IW_AE_LLP_SEGMENT_TOO_SMALL 0x0507
1663#define I40IW_AE_LLP_SYN_RECEIVED 0x0508
1664#define I40IW_AE_LLP_TERMINATE_RECEIVED 0x0509
1665#define I40IW_AE_LLP_TOO_MANY_RETRIES 0x050a
1666#define I40IW_AE_LLP_TOO_MANY_KEEPALIVE_RETRIES 0x050b
1667#define I40IW_AE_LLP_DOUBT_REACHABILITY 0x050c
1668#define I40IW_AE_LLP_RX_VLAN_MISMATCH 0x050d
1669#define I40IW_AE_RESOURCE_EXHAUSTION 0x0520
1670#define I40IW_AE_RESET_SENT 0x0601
1671#define I40IW_AE_TERMINATE_SENT 0x0602
1672#define I40IW_AE_RESET_NOT_SENT 0x0603
1673#define I40IW_AE_LCE_QP_CATASTROPHIC 0x0700
1674#define I40IW_AE_LCE_FUNCTION_CATASTROPHIC 0x0701
1675#define I40IW_AE_LCE_CQ_CATASTROPHIC 0x0702
1676#define I40IW_AE_UDA_XMIT_FRAG_SEQ 0x0800
1677#define I40IW_AE_UDA_XMIT_DGRAM_TOO_LONG 0x0801
1678#define I40IW_AE_UDA_XMIT_IPADDR_MISMATCH 0x0802
1679#define I40IW_AE_QP_SUSPEND_COMPLETE 0x0900
1680
1681#define OP_DELETE_LOCAL_MAC_IPADDR_ENTRY 1
1682#define OP_CEQ_DESTROY 2
1683#define OP_AEQ_DESTROY 3
1684#define OP_DELETE_ARP_CACHE_ENTRY 4
1685#define OP_MANAGE_APBVT_ENTRY 5
1686#define OP_CEQ_CREATE 6
1687#define OP_AEQ_CREATE 7
1688#define OP_ALLOC_LOCAL_MAC_IPADDR_ENTRY 8
1689#define OP_ADD_LOCAL_MAC_IPADDR_ENTRY 9
1690#define OP_MANAGE_QHASH_TABLE_ENTRY 10
1691#define OP_QP_MODIFY 11
1692#define OP_QP_UPLOAD_CONTEXT 12
1693#define OP_CQ_CREATE 13
1694#define OP_CQ_DESTROY 14
1695#define OP_QP_CREATE 15
1696#define OP_QP_DESTROY 16
1697#define OP_ALLOC_STAG 17
1698#define OP_MR_REG_NON_SHARED 18
1699#define OP_DEALLOC_STAG 19
1700#define OP_MW_ALLOC 20
1701#define OP_QP_FLUSH_WQES 21
1702#define OP_ADD_ARP_CACHE_ENTRY 22
1703#define OP_MANAGE_PUSH_PAGE 23
1704#define OP_UPDATE_PE_SDS 24
1705#define OP_MANAGE_HMC_PM_FUNC_TABLE 25
1706#define OP_SUSPEND 26
1707#define OP_RESUME 27
1708#define OP_MANAGE_VF_PBLE_BP 28
1709#define OP_QUERY_FPM_VALUES 29
1710#define OP_COMMIT_FPM_VALUES 30
1711#define OP_SIZE_CQP_STAT_ARRAY 31
1712
1713#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_hmc.c b/drivers/infiniband/hw/i40iw/i40iw_hmc.c
new file mode 100644
index 000000000000..5484cbf55f0f
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_hmc.c
@@ -0,0 +1,821 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_osdep.h"
36#include "i40iw_register.h"
37#include "i40iw_status.h"
38#include "i40iw_hmc.h"
39#include "i40iw_d.h"
40#include "i40iw_type.h"
41#include "i40iw_p.h"
42#include "i40iw_vf.h"
43#include "i40iw_virtchnl.h"
44
45/**
46 * i40iw_find_sd_index_limit - finds segment descriptor index limit
47 * @hmc_info: pointer to the HMC configuration information structure
48 * @type: type of HMC resources we're searching
49 * @index: starting index for the object
50 * @cnt: number of objects we're trying to create
51 * @sd_idx: pointer to return index of the segment descriptor in question
52 * @sd_limit: pointer to return the maximum number of segment descriptors
53 *
54 * This function calculates the segment descriptor index and index limit
55 * for the resource defined by i40iw_hmc_rsrc_type.
56 */
57
58static inline void i40iw_find_sd_index_limit(struct i40iw_hmc_info *hmc_info,
59 u32 type,
60 u32 idx,
61 u32 cnt,
62 u32 *sd_idx,
63 u32 *sd_limit)
64{
65 u64 fpm_addr, fpm_limit;
66
67 fpm_addr = hmc_info->hmc_obj[(type)].base +
68 hmc_info->hmc_obj[type].size * idx;
69 fpm_limit = fpm_addr + hmc_info->hmc_obj[type].size * cnt;
70 *sd_idx = (u32)(fpm_addr / I40IW_HMC_DIRECT_BP_SIZE);
71 *sd_limit = (u32)((fpm_limit - 1) / I40IW_HMC_DIRECT_BP_SIZE);
72 *sd_limit += 1;
73}
74
75/**
76 * i40iw_find_pd_index_limit - finds page descriptor index limit
77 * @hmc_info: pointer to the HMC configuration information struct
78 * @type: HMC resource type we're examining
79 * @idx: starting index for the object
80 * @cnt: number of objects we're trying to create
81 * @pd_index: pointer to return page descriptor index
82 * @pd_limit: pointer to return page descriptor index limit
83 *
84 * Calculates the page descriptor index and index limit for the resource
85 * defined by i40iw_hmc_rsrc_type.
86 */
87
88static inline void i40iw_find_pd_index_limit(struct i40iw_hmc_info *hmc_info,
89 u32 type,
90 u32 idx,
91 u32 cnt,
92 u32 *pd_idx,
93 u32 *pd_limit)
94{
95 u64 fpm_adr, fpm_limit;
96
97 fpm_adr = hmc_info->hmc_obj[type].base +
98 hmc_info->hmc_obj[type].size * idx;
99 fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt);
100 *(pd_idx) = (u32)(fpm_adr / I40IW_HMC_PAGED_BP_SIZE);
101 *(pd_limit) = (u32)((fpm_limit - 1) / I40IW_HMC_PAGED_BP_SIZE);
102 *(pd_limit) += 1;
103}
104
105/**
106 * i40iw_set_sd_entry - setup entry for sd programming
107 * @pa: physical addr
108 * @idx: sd index
109 * @type: paged or direct sd
110 * @entry: sd entry ptr
111 */
112static inline void i40iw_set_sd_entry(u64 pa,
113 u32 idx,
114 enum i40iw_sd_entry_type type,
115 struct update_sd_entry *entry)
116{
117 entry->data = pa | (I40IW_HMC_MAX_BP_COUNT << I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) |
118 (((type == I40IW_SD_TYPE_PAGED) ? 0 : 1) <<
119 I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) |
120 (1 << I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT);
121 entry->cmd = (idx | (1 << I40E_PFHMC_SDCMD_PMSDWR_SHIFT) | (1 << 15));
122}
123
124/**
125 * i40iw_clr_sd_entry - setup entry for sd clear
126 * @idx: sd index
127 * @type: paged or direct sd
128 * @entry: sd entry ptr
129 */
130static inline void i40iw_clr_sd_entry(u32 idx, enum i40iw_sd_entry_type type,
131 struct update_sd_entry *entry)
132{
133 entry->data = (I40IW_HMC_MAX_BP_COUNT <<
134 I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) |
135 (((type == I40IW_SD_TYPE_PAGED) ? 0 : 1) <<
136 I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT);
137 entry->cmd = (idx | (1 << I40E_PFHMC_SDCMD_PMSDWR_SHIFT) | (1 << 15));
138}
139
140/**
141 * i40iw_hmc_sd_one - setup 1 sd entry for cqp
142 * @dev: pointer to the device structure
143 * @hmc_fn_id: hmc's function id
144 * @pa: physical addr
145 * @sd_idx: sd index
146 * @type: paged or direct sd
147 * @setsd: flag to set or clear sd
148 */
149enum i40iw_status_code i40iw_hmc_sd_one(struct i40iw_sc_dev *dev,
150 u8 hmc_fn_id,
151 u64 pa, u32 sd_idx,
152 enum i40iw_sd_entry_type type,
153 bool setsd)
154{
155 struct i40iw_update_sds_info sdinfo;
156
157 sdinfo.cnt = 1;
158 sdinfo.hmc_fn_id = hmc_fn_id;
159 if (setsd)
160 i40iw_set_sd_entry(pa, sd_idx, type, sdinfo.entry);
161 else
162 i40iw_clr_sd_entry(sd_idx, type, sdinfo.entry);
163
164 return dev->cqp->process_cqp_sds(dev, &sdinfo);
165}
166
167/**
168 * i40iw_hmc_sd_grp - setup group od sd entries for cqp
169 * @dev: pointer to the device structure
170 * @hmc_info: pointer to the HMC configuration information struct
171 * @sd_index: sd index
172 * @sd_cnt: number of sd entries
173 * @setsd: flag to set or clear sd
174 */
175static enum i40iw_status_code i40iw_hmc_sd_grp(struct i40iw_sc_dev *dev,
176 struct i40iw_hmc_info *hmc_info,
177 u32 sd_index,
178 u32 sd_cnt,
179 bool setsd)
180{
181 struct i40iw_hmc_sd_entry *sd_entry;
182 struct i40iw_update_sds_info sdinfo;
183 u64 pa;
184 u32 i;
185 enum i40iw_status_code ret_code = 0;
186
187 memset(&sdinfo, 0, sizeof(sdinfo));
188 sdinfo.hmc_fn_id = hmc_info->hmc_fn_id;
189 for (i = sd_index; i < sd_index + sd_cnt; i++) {
190 sd_entry = &hmc_info->sd_table.sd_entry[i];
191 if (!sd_entry ||
192 (!sd_entry->valid && setsd) ||
193 (sd_entry->valid && !setsd))
194 continue;
195 if (setsd) {
196 pa = (sd_entry->entry_type == I40IW_SD_TYPE_PAGED) ?
197 sd_entry->u.pd_table.pd_page_addr.pa :
198 sd_entry->u.bp.addr.pa;
199 i40iw_set_sd_entry(pa, i, sd_entry->entry_type,
200 &sdinfo.entry[sdinfo.cnt]);
201 } else {
202 i40iw_clr_sd_entry(i, sd_entry->entry_type,
203 &sdinfo.entry[sdinfo.cnt]);
204 }
205 sdinfo.cnt++;
206 if (sdinfo.cnt == I40IW_MAX_SD_ENTRIES) {
207 ret_code = dev->cqp->process_cqp_sds(dev, &sdinfo);
208 if (ret_code) {
209 i40iw_debug(dev, I40IW_DEBUG_HMC,
210 "i40iw_hmc_sd_grp: sd_programming failed err=%d\n",
211 ret_code);
212 return ret_code;
213 }
214 sdinfo.cnt = 0;
215 }
216 }
217 if (sdinfo.cnt)
218 ret_code = dev->cqp->process_cqp_sds(dev, &sdinfo);
219
220 return ret_code;
221}
222
223/**
224 * i40iw_vfdev_from_fpm - return vf dev ptr for hmc function id
225 * @dev: pointer to the device structure
226 * @hmc_fn_id: hmc's function id
227 */
228struct i40iw_vfdev *i40iw_vfdev_from_fpm(struct i40iw_sc_dev *dev, u8 hmc_fn_id)
229{
230 struct i40iw_vfdev *vf_dev = NULL;
231 u16 idx;
232
233 for (idx = 0; idx < I40IW_MAX_PE_ENABLED_VF_COUNT; idx++) {
234 if (dev->vf_dev[idx] &&
235 ((u8)dev->vf_dev[idx]->pmf_index == hmc_fn_id)) {
236 vf_dev = dev->vf_dev[idx];
237 break;
238 }
239 }
240 return vf_dev;
241}
242
243/**
244 * i40iw_vf_hmcinfo_from_fpm - get ptr to hmc for func_id
245 * @dev: pointer to the device structure
246 * @hmc_fn_id: hmc's function id
247 */
248struct i40iw_hmc_info *i40iw_vf_hmcinfo_from_fpm(struct i40iw_sc_dev *dev,
249 u8 hmc_fn_id)
250{
251 struct i40iw_hmc_info *hmc_info = NULL;
252 u16 idx;
253
254 for (idx = 0; idx < I40IW_MAX_PE_ENABLED_VF_COUNT; idx++) {
255 if (dev->vf_dev[idx] &&
256 ((u8)dev->vf_dev[idx]->pmf_index == hmc_fn_id)) {
257 hmc_info = &dev->vf_dev[idx]->hmc_info;
258 break;
259 }
260 }
261 return hmc_info;
262}
263
264/**
265 * i40iw_hmc_finish_add_sd_reg - program sd entries for objects
266 * @dev: pointer to the device structure
267 * @info: create obj info
268 */
269static enum i40iw_status_code i40iw_hmc_finish_add_sd_reg(struct i40iw_sc_dev *dev,
270 struct i40iw_hmc_create_obj_info *info)
271{
272 if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt)
273 return I40IW_ERR_INVALID_HMC_OBJ_INDEX;
274
275 if ((info->start_idx + info->count) >
276 info->hmc_info->hmc_obj[info->rsrc_type].cnt)
277 return I40IW_ERR_INVALID_HMC_OBJ_COUNT;
278
279 if (!info->add_sd_cnt)
280 return 0;
281
282 return i40iw_hmc_sd_grp(dev, info->hmc_info,
283 info->hmc_info->sd_indexes[0],
284 info->add_sd_cnt, true);
285}
286
287/**
288 * i40iw_create_iw_hmc_obj - allocate backing store for hmc objects
289 * @dev: pointer to the device structure
290 * @info: pointer to i40iw_hmc_iw_create_obj_info struct
291 *
292 * This will allocate memory for PDs and backing pages and populate
293 * the sd and pd entries.
294 */
295enum i40iw_status_code i40iw_sc_create_hmc_obj(struct i40iw_sc_dev *dev,
296 struct i40iw_hmc_create_obj_info *info)
297{
298 struct i40iw_hmc_sd_entry *sd_entry;
299 u32 sd_idx, sd_lmt;
300 u32 pd_idx = 0, pd_lmt = 0;
301 u32 pd_idx1 = 0, pd_lmt1 = 0;
302 u32 i, j;
303 bool pd_error = false;
304 enum i40iw_status_code ret_code = 0;
305
306 if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt)
307 return I40IW_ERR_INVALID_HMC_OBJ_INDEX;
308
309 if ((info->start_idx + info->count) >
310 info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
311 i40iw_debug(dev, I40IW_DEBUG_HMC,
312 "%s: error type %u, start = %u, req cnt %u, cnt = %u\n",
313 __func__, info->rsrc_type, info->start_idx, info->count,
314 info->hmc_info->hmc_obj[info->rsrc_type].cnt);
315 return I40IW_ERR_INVALID_HMC_OBJ_COUNT;
316 }
317
318 if (!dev->is_pf)
319 return i40iw_vchnl_vf_add_hmc_objs(dev, info->rsrc_type, 0, info->count);
320
321 i40iw_find_sd_index_limit(info->hmc_info, info->rsrc_type,
322 info->start_idx, info->count,
323 &sd_idx, &sd_lmt);
324 if (sd_idx >= info->hmc_info->sd_table.sd_cnt ||
325 sd_lmt > info->hmc_info->sd_table.sd_cnt) {
326 return I40IW_ERR_INVALID_SD_INDEX;
327 }
328 i40iw_find_pd_index_limit(info->hmc_info, info->rsrc_type,
329 info->start_idx, info->count, &pd_idx, &pd_lmt);
330
331 for (j = sd_idx; j < sd_lmt; j++) {
332 ret_code = i40iw_add_sd_table_entry(dev->hw, info->hmc_info,
333 j,
334 info->entry_type,
335 I40IW_HMC_DIRECT_BP_SIZE);
336 if (ret_code)
337 goto exit_sd_error;
338 sd_entry = &info->hmc_info->sd_table.sd_entry[j];
339
340 if ((sd_entry->entry_type == I40IW_SD_TYPE_PAGED) &&
341 ((dev->hmc_info == info->hmc_info) &&
342 (info->rsrc_type != I40IW_HMC_IW_PBLE))) {
343 pd_idx1 = max(pd_idx, (j * I40IW_HMC_MAX_BP_COUNT));
344 pd_lmt1 = min(pd_lmt,
345 (j + 1) * I40IW_HMC_MAX_BP_COUNT);
346 for (i = pd_idx1; i < pd_lmt1; i++) {
347 /* update the pd table entry */
348 ret_code = i40iw_add_pd_table_entry(dev->hw, info->hmc_info,
349 i, NULL);
350 if (ret_code) {
351 pd_error = true;
352 break;
353 }
354 }
355 if (pd_error) {
356 while (i && (i > pd_idx1)) {
357 i40iw_remove_pd_bp(dev->hw, info->hmc_info, (i - 1),
358 info->is_pf);
359 i--;
360 }
361 }
362 }
363 if (sd_entry->valid)
364 continue;
365
366 info->hmc_info->sd_indexes[info->add_sd_cnt] = (u16)j;
367 info->add_sd_cnt++;
368 sd_entry->valid = true;
369 }
370 return i40iw_hmc_finish_add_sd_reg(dev, info);
371
372exit_sd_error:
373 while (j && (j > sd_idx)) {
374 sd_entry = &info->hmc_info->sd_table.sd_entry[j - 1];
375 switch (sd_entry->entry_type) {
376 case I40IW_SD_TYPE_PAGED:
377 pd_idx1 = max(pd_idx,
378 (j - 1) * I40IW_HMC_MAX_BP_COUNT);
379 pd_lmt1 = min(pd_lmt, (j * I40IW_HMC_MAX_BP_COUNT));
380 for (i = pd_idx1; i < pd_lmt1; i++)
381 i40iw_prep_remove_pd_page(info->hmc_info, i);
382 break;
383 case I40IW_SD_TYPE_DIRECT:
384 i40iw_prep_remove_pd_page(info->hmc_info, (j - 1));
385 break;
386 default:
387 ret_code = I40IW_ERR_INVALID_SD_TYPE;
388 break;
389 }
390 j--;
391 }
392
393 return ret_code;
394}
395
396/**
397 * i40iw_finish_del_sd_reg - delete sd entries for objects
398 * @dev: pointer to the device structure
399 * @info: dele obj info
400 * @reset: true if called before reset
401 */
402static enum i40iw_status_code i40iw_finish_del_sd_reg(struct i40iw_sc_dev *dev,
403 struct i40iw_hmc_del_obj_info *info,
404 bool reset)
405{
406 struct i40iw_hmc_sd_entry *sd_entry;
407 enum i40iw_status_code ret_code = 0;
408 u32 i, sd_idx;
409 struct i40iw_dma_mem *mem;
410
411 if (dev->is_pf && !reset)
412 ret_code = i40iw_hmc_sd_grp(dev, info->hmc_info,
413 info->hmc_info->sd_indexes[0],
414 info->del_sd_cnt, false);
415
416 if (ret_code)
417 i40iw_debug(dev, I40IW_DEBUG_HMC, "%s: error cqp sd sd_grp\n", __func__);
418
419 for (i = 0; i < info->del_sd_cnt; i++) {
420 sd_idx = info->hmc_info->sd_indexes[i];
421 sd_entry = &info->hmc_info->sd_table.sd_entry[sd_idx];
422 if (!sd_entry)
423 continue;
424 mem = (sd_entry->entry_type == I40IW_SD_TYPE_PAGED) ?
425 &sd_entry->u.pd_table.pd_page_addr :
426 &sd_entry->u.bp.addr;
427
428 if (!mem || !mem->va)
429 i40iw_debug(dev, I40IW_DEBUG_HMC, "%s: error cqp sd mem\n", __func__);
430 else
431 i40iw_free_dma_mem(dev->hw, mem);
432 }
433 return ret_code;
434}
435
436/**
437 * i40iw_del_iw_hmc_obj - remove pe hmc objects
438 * @dev: pointer to the device structure
439 * @info: pointer to i40iw_hmc_del_obj_info struct
440 * @reset: true if called before reset
441 *
442 * This will de-populate the SDs and PDs. It frees
443 * the memory for PDS and backing storage. After this function is returned,
444 * caller should deallocate memory allocated previously for
445 * book-keeping information about PDs and backing storage.
446 */
447enum i40iw_status_code i40iw_sc_del_hmc_obj(struct i40iw_sc_dev *dev,
448 struct i40iw_hmc_del_obj_info *info,
449 bool reset)
450{
451 struct i40iw_hmc_pd_table *pd_table;
452 u32 sd_idx, sd_lmt;
453 u32 pd_idx, pd_lmt, rel_pd_idx;
454 u32 i, j;
455 enum i40iw_status_code ret_code = 0;
456
457 if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
458 i40iw_debug(dev, I40IW_DEBUG_HMC,
459 "%s: error start_idx[%04d] >= [type %04d].cnt[%04d]\n",
460 __func__, info->start_idx, info->rsrc_type,
461 info->hmc_info->hmc_obj[info->rsrc_type].cnt);
462 return I40IW_ERR_INVALID_HMC_OBJ_INDEX;
463 }
464
465 if ((info->start_idx + info->count) >
466 info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
467 i40iw_debug(dev, I40IW_DEBUG_HMC,
468 "%s: error start_idx[%04d] + count %04d >= [type %04d].cnt[%04d]\n",
469 __func__, info->start_idx, info->count,
470 info->rsrc_type,
471 info->hmc_info->hmc_obj[info->rsrc_type].cnt);
472 return I40IW_ERR_INVALID_HMC_OBJ_COUNT;
473 }
474 if (!dev->is_pf) {
475 ret_code = i40iw_vchnl_vf_del_hmc_obj(dev, info->rsrc_type, 0,
476 info->count);
477 if (info->rsrc_type != I40IW_HMC_IW_PBLE)
478 return ret_code;
479 }
480
481 i40iw_find_pd_index_limit(info->hmc_info, info->rsrc_type,
482 info->start_idx, info->count, &pd_idx, &pd_lmt);
483
484 for (j = pd_idx; j < pd_lmt; j++) {
485 sd_idx = j / I40IW_HMC_PD_CNT_IN_SD;
486
487 if (info->hmc_info->sd_table.sd_entry[sd_idx].entry_type !=
488 I40IW_SD_TYPE_PAGED)
489 continue;
490
491 rel_pd_idx = j % I40IW_HMC_PD_CNT_IN_SD;
492 pd_table = &info->hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
493 if (pd_table->pd_entry[rel_pd_idx].valid) {
494 ret_code = i40iw_remove_pd_bp(dev->hw, info->hmc_info, j,
495 info->is_pf);
496 if (ret_code) {
497 i40iw_debug(dev, I40IW_DEBUG_HMC, "%s: error\n", __func__);
498 return ret_code;
499 }
500 }
501 }
502
503 i40iw_find_sd_index_limit(info->hmc_info, info->rsrc_type,
504 info->start_idx, info->count, &sd_idx, &sd_lmt);
505 if (sd_idx >= info->hmc_info->sd_table.sd_cnt ||
506 sd_lmt > info->hmc_info->sd_table.sd_cnt) {
507 i40iw_debug(dev, I40IW_DEBUG_HMC, "%s: error invalid sd_idx\n", __func__);
508 return I40IW_ERR_INVALID_SD_INDEX;
509 }
510
511 for (i = sd_idx; i < sd_lmt; i++) {
512 if (!info->hmc_info->sd_table.sd_entry[i].valid)
513 continue;
514 switch (info->hmc_info->sd_table.sd_entry[i].entry_type) {
515 case I40IW_SD_TYPE_DIRECT:
516 ret_code = i40iw_prep_remove_sd_bp(info->hmc_info, i);
517 if (!ret_code) {
518 info->hmc_info->sd_indexes[info->del_sd_cnt] = (u16)i;
519 info->del_sd_cnt++;
520 }
521 break;
522 case I40IW_SD_TYPE_PAGED:
523 ret_code = i40iw_prep_remove_pd_page(info->hmc_info, i);
524 if (!ret_code) {
525 info->hmc_info->sd_indexes[info->del_sd_cnt] = (u16)i;
526 info->del_sd_cnt++;
527 }
528 break;
529 default:
530 break;
531 }
532 }
533 return i40iw_finish_del_sd_reg(dev, info, reset);
534}
535
536/**
537 * i40iw_add_sd_table_entry - Adds a segment descriptor to the table
538 * @hw: pointer to our hw struct
539 * @hmc_info: pointer to the HMC configuration information struct
540 * @sd_index: segment descriptor index to manipulate
541 * @type: what type of segment descriptor we're manipulating
542 * @direct_mode_sz: size to alloc in direct mode
543 */
544enum i40iw_status_code i40iw_add_sd_table_entry(struct i40iw_hw *hw,
545 struct i40iw_hmc_info *hmc_info,
546 u32 sd_index,
547 enum i40iw_sd_entry_type type,
548 u64 direct_mode_sz)
549{
550 enum i40iw_status_code ret_code = 0;
551 struct i40iw_hmc_sd_entry *sd_entry;
552 bool dma_mem_alloc_done = false;
553 struct i40iw_dma_mem mem;
554 u64 alloc_len;
555
556 sd_entry = &hmc_info->sd_table.sd_entry[sd_index];
557 if (!sd_entry->valid) {
558 if (type == I40IW_SD_TYPE_PAGED)
559 alloc_len = I40IW_HMC_PAGED_BP_SIZE;
560 else
561 alloc_len = direct_mode_sz;
562
563 /* allocate a 4K pd page or 2M backing page */
564 ret_code = i40iw_allocate_dma_mem(hw, &mem, alloc_len,
565 I40IW_HMC_PD_BP_BUF_ALIGNMENT);
566 if (ret_code)
567 goto exit;
568 dma_mem_alloc_done = true;
569 if (type == I40IW_SD_TYPE_PAGED) {
570 ret_code = i40iw_allocate_virt_mem(hw,
571 &sd_entry->u.pd_table.pd_entry_virt_mem,
572 sizeof(struct i40iw_hmc_pd_entry) * 512);
573 if (ret_code)
574 goto exit;
575 sd_entry->u.pd_table.pd_entry = (struct i40iw_hmc_pd_entry *)
576 sd_entry->u.pd_table.pd_entry_virt_mem.va;
577
578 memcpy(&sd_entry->u.pd_table.pd_page_addr, &mem, sizeof(struct i40iw_dma_mem));
579 } else {
580 memcpy(&sd_entry->u.bp.addr, &mem, sizeof(struct i40iw_dma_mem));
581 sd_entry->u.bp.sd_pd_index = sd_index;
582 }
583
584 hmc_info->sd_table.sd_entry[sd_index].entry_type = type;
585
586 I40IW_INC_SD_REFCNT(&hmc_info->sd_table);
587 }
588 if (sd_entry->entry_type == I40IW_SD_TYPE_DIRECT)
589 I40IW_INC_BP_REFCNT(&sd_entry->u.bp);
590exit:
591 if (ret_code)
592 if (dma_mem_alloc_done)
593 i40iw_free_dma_mem(hw, &mem);
594
595 return ret_code;
596}
597
598/**
599 * i40iw_add_pd_table_entry - Adds page descriptor to the specified table
600 * @hw: pointer to our HW structure
601 * @hmc_info: pointer to the HMC configuration information structure
602 * @pd_index: which page descriptor index to manipulate
603 * @rsrc_pg: if not NULL, use preallocated page instead of allocating new one.
604 *
605 * This function:
606 * 1. Initializes the pd entry
607 * 2. Adds pd_entry in the pd_table
608 * 3. Mark the entry valid in i40iw_hmc_pd_entry structure
609 * 4. Initializes the pd_entry's ref count to 1
610 * assumptions:
611 * 1. The memory for pd should be pinned down, physically contiguous and
612 * aligned on 4K boundary and zeroed memory.
613 * 2. It should be 4K in size.
614 */
615enum i40iw_status_code i40iw_add_pd_table_entry(struct i40iw_hw *hw,
616 struct i40iw_hmc_info *hmc_info,
617 u32 pd_index,
618 struct i40iw_dma_mem *rsrc_pg)
619{
620 enum i40iw_status_code ret_code = 0;
621 struct i40iw_hmc_pd_table *pd_table;
622 struct i40iw_hmc_pd_entry *pd_entry;
623 struct i40iw_dma_mem mem;
624 struct i40iw_dma_mem *page = &mem;
625 u32 sd_idx, rel_pd_idx;
626 u64 *pd_addr;
627 u64 page_desc;
628
629 if (pd_index / I40IW_HMC_PD_CNT_IN_SD >= hmc_info->sd_table.sd_cnt)
630 return I40IW_ERR_INVALID_PAGE_DESC_INDEX;
631
632 sd_idx = (pd_index / I40IW_HMC_PD_CNT_IN_SD);
633 if (hmc_info->sd_table.sd_entry[sd_idx].entry_type != I40IW_SD_TYPE_PAGED)
634 return 0;
635
636 rel_pd_idx = (pd_index % I40IW_HMC_PD_CNT_IN_SD);
637 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
638 pd_entry = &pd_table->pd_entry[rel_pd_idx];
639 if (!pd_entry->valid) {
640 if (rsrc_pg) {
641 pd_entry->rsrc_pg = true;
642 page = rsrc_pg;
643 } else {
644 ret_code = i40iw_allocate_dma_mem(hw, page,
645 I40IW_HMC_PAGED_BP_SIZE,
646 I40IW_HMC_PD_BP_BUF_ALIGNMENT);
647 if (ret_code)
648 return ret_code;
649 pd_entry->rsrc_pg = false;
650 }
651
652 memcpy(&pd_entry->bp.addr, page, sizeof(struct i40iw_dma_mem));
653 pd_entry->bp.sd_pd_index = pd_index;
654 pd_entry->bp.entry_type = I40IW_SD_TYPE_PAGED;
655 page_desc = page->pa | 0x1;
656
657 pd_addr = (u64 *)pd_table->pd_page_addr.va;
658 pd_addr += rel_pd_idx;
659
660 memcpy(pd_addr, &page_desc, sizeof(*pd_addr));
661
662 pd_entry->sd_index = sd_idx;
663 pd_entry->valid = true;
664 I40IW_INC_PD_REFCNT(pd_table);
665 if (hmc_info->hmc_fn_id < I40IW_FIRST_VF_FPM_ID)
666 I40IW_INVALIDATE_PF_HMC_PD(hw, sd_idx, rel_pd_idx);
667 else if (hw->hmc.hmc_fn_id != hmc_info->hmc_fn_id)
668 I40IW_INVALIDATE_VF_HMC_PD(hw, sd_idx, rel_pd_idx,
669 hmc_info->hmc_fn_id);
670 }
671 I40IW_INC_BP_REFCNT(&pd_entry->bp);
672
673 return 0;
674}
675
676/**
677 * i40iw_remove_pd_bp - remove a backing page from a page descriptor
678 * @hw: pointer to our HW structure
679 * @hmc_info: pointer to the HMC configuration information structure
680 * @idx: the page index
681 * @is_pf: distinguishes a VF from a PF
682 *
683 * This function:
684 * 1. Marks the entry in pd table (for paged address mode) or in sd table
685 * (for direct address mode) invalid.
686 * 2. Write to register PMPDINV to invalidate the backing page in FV cache
687 * 3. Decrement the ref count for the pd _entry
688 * assumptions:
689 * 1. Caller can deallocate the memory used by backing storage after this
690 * function returns.
691 */
692enum i40iw_status_code i40iw_remove_pd_bp(struct i40iw_hw *hw,
693 struct i40iw_hmc_info *hmc_info,
694 u32 idx,
695 bool is_pf)
696{
697 struct i40iw_hmc_pd_entry *pd_entry;
698 struct i40iw_hmc_pd_table *pd_table;
699 struct i40iw_hmc_sd_entry *sd_entry;
700 u32 sd_idx, rel_pd_idx;
701 struct i40iw_dma_mem *mem;
702 u64 *pd_addr;
703
704 sd_idx = idx / I40IW_HMC_PD_CNT_IN_SD;
705 rel_pd_idx = idx % I40IW_HMC_PD_CNT_IN_SD;
706 if (sd_idx >= hmc_info->sd_table.sd_cnt)
707 return I40IW_ERR_INVALID_PAGE_DESC_INDEX;
708
709 sd_entry = &hmc_info->sd_table.sd_entry[sd_idx];
710 if (sd_entry->entry_type != I40IW_SD_TYPE_PAGED)
711 return I40IW_ERR_INVALID_SD_TYPE;
712
713 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
714 pd_entry = &pd_table->pd_entry[rel_pd_idx];
715 I40IW_DEC_BP_REFCNT(&pd_entry->bp);
716 if (pd_entry->bp.ref_cnt)
717 return 0;
718
719 pd_entry->valid = false;
720 I40IW_DEC_PD_REFCNT(pd_table);
721 pd_addr = (u64 *)pd_table->pd_page_addr.va;
722 pd_addr += rel_pd_idx;
723 memset(pd_addr, 0, sizeof(u64));
724 if (is_pf)
725 I40IW_INVALIDATE_PF_HMC_PD(hw, sd_idx, idx);
726 else
727 I40IW_INVALIDATE_VF_HMC_PD(hw, sd_idx, idx,
728 hmc_info->hmc_fn_id);
729
730 if (!pd_entry->rsrc_pg) {
731 mem = &pd_entry->bp.addr;
732 if (!mem || !mem->va)
733 return I40IW_ERR_PARAM;
734 i40iw_free_dma_mem(hw, mem);
735 }
736 if (!pd_table->ref_cnt)
737 i40iw_free_virt_mem(hw, &pd_table->pd_entry_virt_mem);
738
739 return 0;
740}
741
742/**
743 * i40iw_prep_remove_sd_bp - Prepares to remove a backing page from a sd entry
744 * @hmc_info: pointer to the HMC configuration information structure
745 * @idx: the page index
746 */
747enum i40iw_status_code i40iw_prep_remove_sd_bp(struct i40iw_hmc_info *hmc_info, u32 idx)
748{
749 struct i40iw_hmc_sd_entry *sd_entry;
750
751 sd_entry = &hmc_info->sd_table.sd_entry[idx];
752 I40IW_DEC_BP_REFCNT(&sd_entry->u.bp);
753 if (sd_entry->u.bp.ref_cnt)
754 return I40IW_ERR_NOT_READY;
755
756 I40IW_DEC_SD_REFCNT(&hmc_info->sd_table);
757 sd_entry->valid = false;
758
759 return 0;
760}
761
762/**
763 * i40iw_prep_remove_pd_page - Prepares to remove a PD page from sd entry.
764 * @hmc_info: pointer to the HMC configuration information structure
765 * @idx: segment descriptor index to find the relevant page descriptor
766 */
767enum i40iw_status_code i40iw_prep_remove_pd_page(struct i40iw_hmc_info *hmc_info,
768 u32 idx)
769{
770 struct i40iw_hmc_sd_entry *sd_entry;
771
772 sd_entry = &hmc_info->sd_table.sd_entry[idx];
773
774 if (sd_entry->u.pd_table.ref_cnt)
775 return I40IW_ERR_NOT_READY;
776
777 sd_entry->valid = false;
778 I40IW_DEC_SD_REFCNT(&hmc_info->sd_table);
779
780 return 0;
781}
782
783/**
784 * i40iw_pf_init_vfhmc -
785 * @vf_cnt_array: array of cnt values of iwarp hmc objects
786 * @vf_hmc_fn_id: hmc function id ofr vf driver
787 * @dev: pointer to i40iw_dev struct
788 *
789 * Called by pf driver to initialize hmc_info for vf driver instance.
790 */
791enum i40iw_status_code i40iw_pf_init_vfhmc(struct i40iw_sc_dev *dev,
792 u8 vf_hmc_fn_id,
793 u32 *vf_cnt_array)
794{
795 struct i40iw_hmc_info *hmc_info;
796 enum i40iw_status_code ret_code = 0;
797 u32 i;
798
799 if ((vf_hmc_fn_id < I40IW_FIRST_VF_FPM_ID) ||
800 (vf_hmc_fn_id >= I40IW_FIRST_VF_FPM_ID +
801 I40IW_MAX_PE_ENABLED_VF_COUNT)) {
802 i40iw_debug(dev, I40IW_DEBUG_HMC, "%s: invalid vf_hmc_fn_id 0x%x\n",
803 __func__, vf_hmc_fn_id);
804 return I40IW_ERR_INVALID_HMCFN_ID;
805 }
806
807 ret_code = i40iw_sc_init_iw_hmc(dev, vf_hmc_fn_id);
808 if (ret_code)
809 return ret_code;
810
811 hmc_info = i40iw_vf_hmcinfo_from_fpm(dev, vf_hmc_fn_id);
812
813 for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_MAX; i++)
814 if (vf_cnt_array)
815 hmc_info->hmc_obj[i].cnt =
816 vf_cnt_array[i - I40IW_HMC_IW_QP];
817 else
818 hmc_info->hmc_obj[i].cnt = hmc_info->hmc_obj[i].max_cnt;
819
820 return 0;
821}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_hmc.h b/drivers/infiniband/hw/i40iw/i40iw_hmc.h
new file mode 100644
index 000000000000..4c3fdd875621
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_hmc.h
@@ -0,0 +1,241 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_HMC_H
36#define I40IW_HMC_H
37
38#include "i40iw_d.h"
39
40struct i40iw_hw;
41enum i40iw_status_code;
42
43#define I40IW_HMC_MAX_BP_COUNT 512
44#define I40IW_MAX_SD_ENTRIES 11
45#define I40IW_HW_DBG_HMC_INVALID_BP_MARK 0xCA
46
47#define I40IW_HMC_INFO_SIGNATURE 0x484D5347
48#define I40IW_HMC_PD_CNT_IN_SD 512
49#define I40IW_HMC_DIRECT_BP_SIZE 0x200000
50#define I40IW_HMC_MAX_SD_COUNT 4096
51#define I40IW_HMC_PAGED_BP_SIZE 4096
52#define I40IW_HMC_PD_BP_BUF_ALIGNMENT 4096
53#define I40IW_FIRST_VF_FPM_ID 16
54#define FPM_MULTIPLIER 1024
55
56#define I40IW_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++)
57#define I40IW_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++)
58#define I40IW_INC_BP_REFCNT(bp) ((bp)->ref_cnt++)
59
60#define I40IW_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--)
61#define I40IW_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--)
62#define I40IW_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--)
63
64/**
65 * I40IW_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware
66 * @hw: pointer to our hw struct
67 * @sd_idx: segment descriptor index
68 * @pd_idx: page descriptor index
69 */
70#define I40IW_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \
71 i40iw_wr32((hw), I40E_PFHMC_PDINV, \
72 (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \
73 (0x1 << I40E_PFHMC_PDINV_PMSDPARTSEL_SHIFT) | \
74 ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)))
75
76/**
77 * I40IW_INVALIDATE_VF_HMC_PD - Invalidates the pd cache in the hardware
78 * @hw: pointer to our hw struct
79 * @sd_idx: segment descriptor index
80 * @pd_idx: page descriptor index
81 * @hmc_fn_id: VF's function id
82 */
83#define I40IW_INVALIDATE_VF_HMC_PD(hw, sd_idx, pd_idx, hmc_fn_id) \
84 i40iw_wr32(hw, I40E_GLHMC_VFPDINV(hmc_fn_id - I40IW_FIRST_VF_FPM_ID), \
85 ((sd_idx << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \
86 (pd_idx << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)))
87
88struct i40iw_hmc_obj_info {
89 u64 base;
90 u32 max_cnt;
91 u32 cnt;
92 u64 size;
93};
94
95enum i40iw_sd_entry_type {
96 I40IW_SD_TYPE_INVALID = 0,
97 I40IW_SD_TYPE_PAGED = 1,
98 I40IW_SD_TYPE_DIRECT = 2
99};
100
101struct i40iw_hmc_bp {
102 enum i40iw_sd_entry_type entry_type;
103 struct i40iw_dma_mem addr;
104 u32 sd_pd_index;
105 u32 ref_cnt;
106};
107
108struct i40iw_hmc_pd_entry {
109 struct i40iw_hmc_bp bp;
110 u32 sd_index;
111 bool rsrc_pg;
112 bool valid;
113};
114
115struct i40iw_hmc_pd_table {
116 struct i40iw_dma_mem pd_page_addr;
117 struct i40iw_hmc_pd_entry *pd_entry;
118 struct i40iw_virt_mem pd_entry_virt_mem;
119 u32 ref_cnt;
120 u32 sd_index;
121};
122
123struct i40iw_hmc_sd_entry {
124 enum i40iw_sd_entry_type entry_type;
125 bool valid;
126
127 union {
128 struct i40iw_hmc_pd_table pd_table;
129 struct i40iw_hmc_bp bp;
130 } u;
131};
132
133struct i40iw_hmc_sd_table {
134 struct i40iw_virt_mem addr;
135 u32 sd_cnt;
136 u32 ref_cnt;
137 struct i40iw_hmc_sd_entry *sd_entry;
138};
139
140struct i40iw_hmc_info {
141 u32 signature;
142 u8 hmc_fn_id;
143 u16 first_sd_index;
144
145 struct i40iw_hmc_obj_info *hmc_obj;
146 struct i40iw_virt_mem hmc_obj_virt_mem;
147 struct i40iw_hmc_sd_table sd_table;
148 u16 sd_indexes[I40IW_HMC_MAX_SD_COUNT];
149};
150
151struct update_sd_entry {
152 u64 cmd;
153 u64 data;
154};
155
156struct i40iw_update_sds_info {
157 u32 cnt;
158 u8 hmc_fn_id;
159 struct update_sd_entry entry[I40IW_MAX_SD_ENTRIES];
160};
161
162struct i40iw_ccq_cqe_info;
163struct i40iw_hmc_fcn_info {
164 void (*callback_fcn)(struct i40iw_sc_dev *, void *,
165 struct i40iw_ccq_cqe_info *);
166 void *cqp_callback_param;
167 u32 vf_id;
168 u16 iw_vf_idx;
169 bool free_fcn;
170};
171
172enum i40iw_hmc_rsrc_type {
173 I40IW_HMC_IW_QP = 0,
174 I40IW_HMC_IW_CQ = 1,
175 I40IW_HMC_IW_SRQ = 2,
176 I40IW_HMC_IW_HTE = 3,
177 I40IW_HMC_IW_ARP = 4,
178 I40IW_HMC_IW_APBVT_ENTRY = 5,
179 I40IW_HMC_IW_MR = 6,
180 I40IW_HMC_IW_XF = 7,
181 I40IW_HMC_IW_XFFL = 8,
182 I40IW_HMC_IW_Q1 = 9,
183 I40IW_HMC_IW_Q1FL = 10,
184 I40IW_HMC_IW_TIMER = 11,
185 I40IW_HMC_IW_FSIMC = 12,
186 I40IW_HMC_IW_FSIAV = 13,
187 I40IW_HMC_IW_PBLE = 14,
188 I40IW_HMC_IW_MAX = 15,
189};
190
191struct i40iw_hmc_create_obj_info {
192 struct i40iw_hmc_info *hmc_info;
193 struct i40iw_virt_mem add_sd_virt_mem;
194 u32 rsrc_type;
195 u32 start_idx;
196 u32 count;
197 u32 add_sd_cnt;
198 enum i40iw_sd_entry_type entry_type;
199 bool is_pf;
200};
201
202struct i40iw_hmc_del_obj_info {
203 struct i40iw_hmc_info *hmc_info;
204 struct i40iw_virt_mem del_sd_virt_mem;
205 u32 rsrc_type;
206 u32 start_idx;
207 u32 count;
208 u32 del_sd_cnt;
209 bool is_pf;
210};
211
212enum i40iw_status_code i40iw_copy_dma_mem(struct i40iw_hw *hw, void *dest_buf,
213 struct i40iw_dma_mem *src_mem, u64 src_offset, u64 size);
214enum i40iw_status_code i40iw_sc_create_hmc_obj(struct i40iw_sc_dev *dev,
215 struct i40iw_hmc_create_obj_info *info);
216enum i40iw_status_code i40iw_sc_del_hmc_obj(struct i40iw_sc_dev *dev,
217 struct i40iw_hmc_del_obj_info *info,
218 bool reset);
219enum i40iw_status_code i40iw_hmc_sd_one(struct i40iw_sc_dev *dev, u8 hmc_fn_id,
220 u64 pa, u32 sd_idx, enum i40iw_sd_entry_type type,
221 bool setsd);
222enum i40iw_status_code i40iw_update_sds_noccq(struct i40iw_sc_dev *dev,
223 struct i40iw_update_sds_info *info);
224struct i40iw_vfdev *i40iw_vfdev_from_fpm(struct i40iw_sc_dev *dev, u8 hmc_fn_id);
225struct i40iw_hmc_info *i40iw_vf_hmcinfo_from_fpm(struct i40iw_sc_dev *dev,
226 u8 hmc_fn_id);
227enum i40iw_status_code i40iw_add_sd_table_entry(struct i40iw_hw *hw,
228 struct i40iw_hmc_info *hmc_info, u32 sd_index,
229 enum i40iw_sd_entry_type type, u64 direct_mode_sz);
230enum i40iw_status_code i40iw_add_pd_table_entry(struct i40iw_hw *hw,
231 struct i40iw_hmc_info *hmc_info, u32 pd_index,
232 struct i40iw_dma_mem *rsrc_pg);
233enum i40iw_status_code i40iw_remove_pd_bp(struct i40iw_hw *hw,
234 struct i40iw_hmc_info *hmc_info, u32 idx, bool is_pf);
235enum i40iw_status_code i40iw_prep_remove_sd_bp(struct i40iw_hmc_info *hmc_info, u32 idx);
236enum i40iw_status_code i40iw_prep_remove_pd_page(struct i40iw_hmc_info *hmc_info, u32 idx);
237
238#define ENTER_SHARED_FUNCTION()
239#define EXIT_SHARED_FUNCTION()
240
241#endif /* I40IW_HMC_H */
diff --git a/drivers/infiniband/hw/i40iw/i40iw_hw.c b/drivers/infiniband/hw/i40iw/i40iw_hw.c
new file mode 100644
index 000000000000..9fd302425563
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_hw.c
@@ -0,0 +1,730 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
41#include <linux/if_vlan.h>
42
43#include "i40iw.h"
44
45/**
46 * i40iw_initialize_hw_resources - initialize hw resource during open
47 * @iwdev: iwarp device
48 */
49u32 i40iw_initialize_hw_resources(struct i40iw_device *iwdev)
50{
51 unsigned long num_pds;
52 u32 resources_size;
53 u32 max_mr;
54 u32 max_qp;
55 u32 max_cq;
56 u32 arp_table_size;
57 u32 mrdrvbits;
58 void *resource_ptr;
59
60 max_qp = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt;
61 max_cq = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
62 max_mr = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt;
63 arp_table_size = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_ARP].cnt;
64 iwdev->max_cqe = 0xFFFFF;
65 num_pds = max_qp * 4;
66 resources_size = sizeof(struct i40iw_arp_entry) * arp_table_size;
67 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(max_qp);
68 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(max_mr);
69 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(max_cq);
70 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(num_pds);
71 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size);
72 resources_size += sizeof(struct i40iw_qp **) * max_qp;
73 iwdev->mem_resources = kzalloc(resources_size, GFP_KERNEL);
74
75 if (!iwdev->mem_resources)
76 return -ENOMEM;
77
78 iwdev->max_qp = max_qp;
79 iwdev->max_mr = max_mr;
80 iwdev->max_cq = max_cq;
81 iwdev->max_pd = num_pds;
82 iwdev->arp_table_size = arp_table_size;
83 iwdev->arp_table = (struct i40iw_arp_entry *)iwdev->mem_resources;
84 resource_ptr = iwdev->mem_resources + (sizeof(struct i40iw_arp_entry) * arp_table_size);
85
86 iwdev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY |
87 IB_DEVICE_MEM_WINDOW | IB_DEVICE_MEM_MGT_EXTENSIONS;
88
89 iwdev->allocated_qps = resource_ptr;
90 iwdev->allocated_cqs = &iwdev->allocated_qps[BITS_TO_LONGS(max_qp)];
91 iwdev->allocated_mrs = &iwdev->allocated_cqs[BITS_TO_LONGS(max_cq)];
92 iwdev->allocated_pds = &iwdev->allocated_mrs[BITS_TO_LONGS(max_mr)];
93 iwdev->allocated_arps = &iwdev->allocated_pds[BITS_TO_LONGS(num_pds)];
94 iwdev->qp_table = (struct i40iw_qp **)(&iwdev->allocated_arps[BITS_TO_LONGS(arp_table_size)]);
95 set_bit(0, iwdev->allocated_mrs);
96 set_bit(0, iwdev->allocated_qps);
97 set_bit(0, iwdev->allocated_cqs);
98 set_bit(0, iwdev->allocated_pds);
99 set_bit(0, iwdev->allocated_arps);
100
101 /* Following for ILQ/IEQ */
102 set_bit(1, iwdev->allocated_qps);
103 set_bit(1, iwdev->allocated_cqs);
104 set_bit(1, iwdev->allocated_pds);
105 set_bit(2, iwdev->allocated_cqs);
106 set_bit(2, iwdev->allocated_pds);
107
108 spin_lock_init(&iwdev->resource_lock);
109 mrdrvbits = 24 - get_count_order(iwdev->max_mr);
110 iwdev->mr_stagmask = ~(((1 << mrdrvbits) - 1) << (32 - mrdrvbits));
111 return 0;
112}
113
114/**
115 * i40iw_cqp_ce_handler - handle cqp completions
116 * @iwdev: iwarp device
117 * @arm: flag to arm after completions
118 * @cq: cq for cqp completions
119 */
120static void i40iw_cqp_ce_handler(struct i40iw_device *iwdev, struct i40iw_sc_cq *cq, bool arm)
121{
122 struct i40iw_cqp_request *cqp_request;
123 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
124 u32 cqe_count = 0;
125 struct i40iw_ccq_cqe_info info;
126 int ret;
127
128 do {
129 memset(&info, 0, sizeof(info));
130 ret = dev->ccq_ops->ccq_get_cqe_info(cq, &info);
131 if (ret)
132 break;
133 cqp_request = (struct i40iw_cqp_request *)(unsigned long)info.scratch;
134 if (info.error)
135 i40iw_pr_err("opcode = 0x%x maj_err_code = 0x%x min_err_code = 0x%x\n",
136 info.op_code, info.maj_err_code, info.min_err_code);
137 if (cqp_request) {
138 cqp_request->compl_info.maj_err_code = info.maj_err_code;
139 cqp_request->compl_info.min_err_code = info.min_err_code;
140 cqp_request->compl_info.op_ret_val = info.op_ret_val;
141 cqp_request->compl_info.error = info.error;
142
143 if (cqp_request->waiting) {
144 cqp_request->request_done = true;
145 wake_up(&cqp_request->waitq);
146 i40iw_put_cqp_request(&iwdev->cqp, cqp_request);
147 } else {
148 if (cqp_request->callback_fcn)
149 cqp_request->callback_fcn(cqp_request, 1);
150 i40iw_put_cqp_request(&iwdev->cqp, cqp_request);
151 }
152 }
153
154 cqe_count++;
155 } while (1);
156
157 if (arm && cqe_count) {
158 i40iw_process_bh(dev);
159 dev->ccq_ops->ccq_arm(cq);
160 }
161}
162
163/**
164 * i40iw_iwarp_ce_handler - handle iwarp completions
165 * @iwdev: iwarp device
166 * @iwcp: iwarp cq receiving event
167 */
168static void i40iw_iwarp_ce_handler(struct i40iw_device *iwdev,
169 struct i40iw_sc_cq *iwcq)
170{
171 struct i40iw_cq *i40iwcq = iwcq->back_cq;
172
173 if (i40iwcq->ibcq.comp_handler)
174 i40iwcq->ibcq.comp_handler(&i40iwcq->ibcq,
175 i40iwcq->ibcq.cq_context);
176}
177
178/**
179 * i40iw_puda_ce_handler - handle puda completion events
180 * @iwdev: iwarp device
181 * @cq: puda completion q for event
182 */
183static void i40iw_puda_ce_handler(struct i40iw_device *iwdev,
184 struct i40iw_sc_cq *cq)
185{
186 struct i40iw_sc_dev *dev = (struct i40iw_sc_dev *)&iwdev->sc_dev;
187 enum i40iw_status_code status;
188 u32 compl_error;
189
190 do {
191 status = i40iw_puda_poll_completion(dev, cq, &compl_error);
192 if (status == I40IW_ERR_QUEUE_EMPTY)
193 break;
194 if (status) {
195 i40iw_pr_err("puda status = %d\n", status);
196 break;
197 }
198 if (compl_error) {
199 i40iw_pr_err("puda compl_err =0x%x\n", compl_error);
200 break;
201 }
202 } while (1);
203
204 dev->ccq_ops->ccq_arm(cq);
205}
206
207/**
208 * i40iw_process_ceq - handle ceq for completions
209 * @iwdev: iwarp device
210 * @ceq: ceq having cq for completion
211 */
212void i40iw_process_ceq(struct i40iw_device *iwdev, struct i40iw_ceq *ceq)
213{
214 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
215 struct i40iw_sc_ceq *sc_ceq;
216 struct i40iw_sc_cq *cq;
217 bool arm = true;
218
219 sc_ceq = &ceq->sc_ceq;
220 do {
221 cq = dev->ceq_ops->process_ceq(dev, sc_ceq);
222 if (!cq)
223 break;
224
225 if (cq->cq_type == I40IW_CQ_TYPE_CQP)
226 i40iw_cqp_ce_handler(iwdev, cq, arm);
227 else if (cq->cq_type == I40IW_CQ_TYPE_IWARP)
228 i40iw_iwarp_ce_handler(iwdev, cq);
229 else if ((cq->cq_type == I40IW_CQ_TYPE_ILQ) ||
230 (cq->cq_type == I40IW_CQ_TYPE_IEQ))
231 i40iw_puda_ce_handler(iwdev, cq);
232 } while (1);
233}
234
235/**
236 * i40iw_next_iw_state - modify qp state
237 * @iwqp: iwarp qp to modify
238 * @state: next state for qp
239 * @del_hash: del hash
240 * @term: term message
241 * @termlen: length of term message
242 */
243void i40iw_next_iw_state(struct i40iw_qp *iwqp,
244 u8 state,
245 u8 del_hash,
246 u8 term,
247 u8 termlen)
248{
249 struct i40iw_modify_qp_info info;
250
251 memset(&info, 0, sizeof(info));
252 info.next_iwarp_state = state;
253 info.remove_hash_idx = del_hash;
254 info.cq_num_valid = true;
255 info.arp_cache_idx_valid = true;
256 info.dont_send_term = true;
257 info.dont_send_fin = true;
258 info.termlen = termlen;
259
260 if (term & I40IWQP_TERM_SEND_TERM_ONLY)
261 info.dont_send_term = false;
262 if (term & I40IWQP_TERM_SEND_FIN_ONLY)
263 info.dont_send_fin = false;
264 if (iwqp->sc_qp.term_flags && (state == I40IW_QP_STATE_ERROR))
265 info.reset_tcp_conn = true;
266 i40iw_hw_modify_qp(iwqp->iwdev, iwqp, &info, 0);
267}
268
269/**
270 * i40iw_process_aeq - handle aeq events
271 * @iwdev: iwarp device
272 */
273void i40iw_process_aeq(struct i40iw_device *iwdev)
274{
275 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
276 struct i40iw_aeq *aeq = &iwdev->aeq;
277 struct i40iw_sc_aeq *sc_aeq = &aeq->sc_aeq;
278 struct i40iw_aeqe_info aeinfo;
279 struct i40iw_aeqe_info *info = &aeinfo;
280 int ret;
281 struct i40iw_qp *iwqp = NULL;
282 struct i40iw_sc_cq *cq = NULL;
283 struct i40iw_cq *iwcq = NULL;
284 struct i40iw_sc_qp *qp = NULL;
285 struct i40iw_qp_host_ctx_info *ctx_info = NULL;
286 unsigned long flags;
287
288 u32 aeqcnt = 0;
289
290 if (!sc_aeq->size)
291 return;
292
293 do {
294 memset(info, 0, sizeof(*info));
295 ret = dev->aeq_ops->get_next_aeqe(sc_aeq, info);
296 if (ret)
297 break;
298
299 aeqcnt++;
300 i40iw_debug(dev, I40IW_DEBUG_AEQ,
301 "%s ae_id = 0x%x bool qp=%d qp_id = %d\n",
302 __func__, info->ae_id, info->qp, info->qp_cq_id);
303 if (info->qp) {
304 iwqp = iwdev->qp_table[info->qp_cq_id];
305 if (!iwqp) {
306 i40iw_pr_err("qp_id %d is already freed\n", info->qp_cq_id);
307 continue;
308 }
309 qp = &iwqp->sc_qp;
310 spin_lock_irqsave(&iwqp->lock, flags);
311 iwqp->hw_tcp_state = info->tcp_state;
312 iwqp->hw_iwarp_state = info->iwarp_state;
313 iwqp->last_aeq = info->ae_id;
314 spin_unlock_irqrestore(&iwqp->lock, flags);
315 ctx_info = &iwqp->ctx_info;
316 ctx_info->err_rq_idx_valid = true;
317 } else {
318 if (info->ae_id != I40IW_AE_CQ_OPERATION_ERROR)
319 continue;
320 }
321
322 switch (info->ae_id) {
323 case I40IW_AE_LLP_FIN_RECEIVED:
324 if (qp->term_flags)
325 continue;
326 if (atomic_inc_return(&iwqp->close_timer_started) == 1) {
327 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSE_WAIT;
328 if ((iwqp->hw_tcp_state == I40IW_TCP_STATE_CLOSE_WAIT) &&
329 (iwqp->ibqp_state == IB_QPS_RTS)) {
330 i40iw_next_iw_state(iwqp,
331 I40IW_QP_STATE_CLOSING, 0, 0, 0);
332 i40iw_cm_disconn(iwqp);
333 }
334 iwqp->cm_id->add_ref(iwqp->cm_id);
335 i40iw_schedule_cm_timer(iwqp->cm_node,
336 (struct i40iw_puda_buf *)iwqp,
337 I40IW_TIMER_TYPE_CLOSE, 1, 0);
338 }
339 break;
340 case I40IW_AE_LLP_CLOSE_COMPLETE:
341 if (qp->term_flags)
342 i40iw_terminate_done(qp, 0);
343 else
344 i40iw_cm_disconn(iwqp);
345 break;
346 case I40IW_AE_RESET_SENT:
347 i40iw_next_iw_state(iwqp, I40IW_QP_STATE_ERROR, 1, 0, 0);
348 i40iw_cm_disconn(iwqp);
349 break;
350 case I40IW_AE_LLP_CONNECTION_RESET:
351 if (atomic_read(&iwqp->close_timer_started))
352 continue;
353 i40iw_cm_disconn(iwqp);
354 break;
355 case I40IW_AE_TERMINATE_SENT:
356 i40iw_terminate_send_fin(qp);
357 break;
358 case I40IW_AE_LLP_TERMINATE_RECEIVED:
359 i40iw_terminate_received(qp, info);
360 break;
361 case I40IW_AE_CQ_OPERATION_ERROR:
362 i40iw_pr_err("Processing an iWARP related AE for CQ misc = 0x%04X\n",
363 info->ae_id);
364 cq = (struct i40iw_sc_cq *)(unsigned long)info->compl_ctx;
365 iwcq = (struct i40iw_cq *)cq->back_cq;
366
367 if (iwcq->ibcq.event_handler) {
368 struct ib_event ibevent;
369
370 ibevent.device = iwcq->ibcq.device;
371 ibevent.event = IB_EVENT_CQ_ERR;
372 ibevent.element.cq = &iwcq->ibcq;
373 iwcq->ibcq.event_handler(&ibevent, iwcq->ibcq.cq_context);
374 }
375 break;
376 case I40IW_AE_PRIV_OPERATION_DENIED:
377 case I40IW_AE_STAG_ZERO_INVALID:
378 case I40IW_AE_IB_RREQ_AND_Q1_FULL:
379 case I40IW_AE_DDP_UBE_INVALID_DDP_VERSION:
380 case I40IW_AE_DDP_UBE_INVALID_MO:
381 case I40IW_AE_DDP_UBE_INVALID_QN:
382 case I40IW_AE_DDP_NO_L_BIT:
383 case I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
384 case I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
385 case I40IW_AE_ROE_INVALID_RDMA_READ_REQUEST:
386 case I40IW_AE_ROE_INVALID_RDMA_WRITE_OR_READ_RESP:
387 case I40IW_AE_INVALID_ARP_ENTRY:
388 case I40IW_AE_INVALID_TCP_OPTION_RCVD:
389 case I40IW_AE_STALE_ARP_ENTRY:
390 case I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR:
391 case I40IW_AE_LLP_SEGMENT_TOO_SMALL:
392 case I40IW_AE_LLP_SYN_RECEIVED:
393 case I40IW_AE_LLP_TOO_MANY_RETRIES:
394 case I40IW_AE_LLP_DOUBT_REACHABILITY:
395 case I40IW_AE_LCE_QP_CATASTROPHIC:
396 case I40IW_AE_LCE_FUNCTION_CATASTROPHIC:
397 case I40IW_AE_LCE_CQ_CATASTROPHIC:
398 case I40IW_AE_UDA_XMIT_DGRAM_TOO_LONG:
399 case I40IW_AE_UDA_XMIT_IPADDR_MISMATCH:
400 case I40IW_AE_QP_SUSPEND_COMPLETE:
401 ctx_info->err_rq_idx_valid = false;
402 default:
403 if (!info->sq && ctx_info->err_rq_idx_valid) {
404 ctx_info->err_rq_idx = info->wqe_idx;
405 ctx_info->tcp_info_valid = false;
406 ctx_info->iwarp_info_valid = false;
407 ret = dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp,
408 iwqp->host_ctx.va,
409 ctx_info);
410 }
411 i40iw_terminate_connection(qp, info);
412 break;
413 }
414 } while (1);
415
416 if (aeqcnt)
417 dev->aeq_ops->repost_aeq_entries(dev, aeqcnt);
418}
419
420/**
421 * i40iw_manage_apbvt - add or delete tcp port
422 * @iwdev: iwarp device
423 * @accel_local_port: port for apbvt
424 * @add_port: add or delete port
425 */
426int i40iw_manage_apbvt(struct i40iw_device *iwdev, u16 accel_local_port, bool add_port)
427{
428 struct i40iw_apbvt_info *info;
429 enum i40iw_status_code status;
430 struct i40iw_cqp_request *cqp_request;
431 struct cqp_commands_info *cqp_info;
432
433 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, add_port);
434 if (!cqp_request)
435 return -ENOMEM;
436
437 cqp_info = &cqp_request->info;
438 info = &cqp_info->in.u.manage_apbvt_entry.info;
439
440 memset(info, 0, sizeof(*info));
441 info->add = add_port;
442 info->port = cpu_to_le16(accel_local_port);
443
444 cqp_info->cqp_cmd = OP_MANAGE_APBVT_ENTRY;
445 cqp_info->post_sq = 1;
446 cqp_info->in.u.manage_apbvt_entry.cqp = &iwdev->cqp.sc_cqp;
447 cqp_info->in.u.manage_apbvt_entry.scratch = (uintptr_t)cqp_request;
448 status = i40iw_handle_cqp_op(iwdev, cqp_request);
449 if (status)
450 i40iw_pr_err("CQP-OP Manage APBVT entry fail");
451 return status;
452}
453
454/**
455 * i40iw_manage_arp_cache - manage hw arp cache
456 * @iwdev: iwarp device
457 * @mac_addr: mac address ptr
458 * @ip_addr: ip addr for arp cache
459 * @action: add, delete or modify
460 */
461void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
462 unsigned char *mac_addr,
463 __be32 *ip_addr,
464 bool ipv4,
465 u32 action)
466{
467 struct i40iw_add_arp_cache_entry_info *info;
468 struct i40iw_cqp_request *cqp_request;
469 struct cqp_commands_info *cqp_info;
470 int arp_index;
471
472 arp_index = i40iw_arp_table(iwdev, ip_addr, ipv4, mac_addr, action);
473 if (arp_index == -1)
474 return;
475 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
476 if (!cqp_request)
477 return;
478
479 cqp_info = &cqp_request->info;
480 if (action == I40IW_ARP_ADD) {
481 cqp_info->cqp_cmd = OP_ADD_ARP_CACHE_ENTRY;
482 info = &cqp_info->in.u.add_arp_cache_entry.info;
483 memset(info, 0, sizeof(*info));
484 info->arp_index = cpu_to_le32(arp_index);
485 info->permanent = true;
486 ether_addr_copy(info->mac_addr, mac_addr);
487 cqp_info->in.u.add_arp_cache_entry.scratch = (uintptr_t)cqp_request;
488 cqp_info->in.u.add_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
489 } else {
490 cqp_info->cqp_cmd = OP_DELETE_ARP_CACHE_ENTRY;
491 cqp_info->in.u.del_arp_cache_entry.scratch = (uintptr_t)cqp_request;
492 cqp_info->in.u.del_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
493 cqp_info->in.u.del_arp_cache_entry.arp_index = arp_index;
494 }
495
496 cqp_info->in.u.add_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
497 cqp_info->in.u.add_arp_cache_entry.scratch = (uintptr_t)cqp_request;
498 cqp_info->post_sq = 1;
499 if (i40iw_handle_cqp_op(iwdev, cqp_request))
500 i40iw_pr_err("CQP-OP Add/Del Arp Cache entry fail");
501}
502
503/**
504 * i40iw_send_syn_cqp_callback - do syn/ack after qhash
505 * @cqp_request: qhash cqp completion
506 * @send_ack: flag send ack
507 */
508static void i40iw_send_syn_cqp_callback(struct i40iw_cqp_request *cqp_request, u32 send_ack)
509{
510 i40iw_send_syn(cqp_request->param, send_ack);
511}
512
513/**
514 * i40iw_manage_qhash - add or modify qhash
515 * @iwdev: iwarp device
516 * @cminfo: cm info for qhash
517 * @etype: type (syn or quad)
518 * @mtype: type of qhash
519 * @cmnode: cmnode associated with connection
520 * @wait: wait for completion
521 * @user_pri:user pri of the connection
522 */
523enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
524 struct i40iw_cm_info *cminfo,
525 enum i40iw_quad_entry_type etype,
526 enum i40iw_quad_hash_manage_type mtype,
527 void *cmnode,
528 bool wait)
529{
530 struct i40iw_qhash_table_info *info;
531 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
532 enum i40iw_status_code status;
533 struct i40iw_cqp *iwcqp = &iwdev->cqp;
534 struct i40iw_cqp_request *cqp_request;
535 struct cqp_commands_info *cqp_info;
536
537 cqp_request = i40iw_get_cqp_request(iwcqp, wait);
538 if (!cqp_request)
539 return I40IW_ERR_NO_MEMORY;
540 cqp_info = &cqp_request->info;
541 info = &cqp_info->in.u.manage_qhash_table_entry.info;
542 memset(info, 0, sizeof(*info));
543
544 info->manage = mtype;
545 info->entry_type = etype;
546 if (cminfo->vlan_id != 0xFFFF) {
547 info->vlan_valid = true;
548 info->vlan_id = cpu_to_le16(cminfo->vlan_id);
549 } else {
550 info->vlan_valid = false;
551 }
552
553 info->ipv4_valid = cminfo->ipv4;
554 ether_addr_copy(info->mac_addr, iwdev->netdev->dev_addr);
555 info->qp_num = cpu_to_le32(dev->ilq->qp_id);
556 info->dest_port = cpu_to_le16(cminfo->loc_port);
557 info->dest_ip[0] = cpu_to_le32(cminfo->loc_addr[0]);
558 info->dest_ip[1] = cpu_to_le32(cminfo->loc_addr[1]);
559 info->dest_ip[2] = cpu_to_le32(cminfo->loc_addr[2]);
560 info->dest_ip[3] = cpu_to_le32(cminfo->loc_addr[3]);
561 if (etype == I40IW_QHASH_TYPE_TCP_ESTABLISHED) {
562 info->src_port = cpu_to_le16(cminfo->rem_port);
563 info->src_ip[0] = cpu_to_le32(cminfo->rem_addr[0]);
564 info->src_ip[1] = cpu_to_le32(cminfo->rem_addr[1]);
565 info->src_ip[2] = cpu_to_le32(cminfo->rem_addr[2]);
566 info->src_ip[3] = cpu_to_le32(cminfo->rem_addr[3]);
567 }
568 if (cmnode) {
569 cqp_request->callback_fcn = i40iw_send_syn_cqp_callback;
570 cqp_request->param = (void *)cmnode;
571 }
572
573 if (info->ipv4_valid)
574 i40iw_debug(dev, I40IW_DEBUG_CM,
575 "%s:%s IP=%pI4, port=%d, mac=%pM, vlan_id=%d\n",
576 __func__, (!mtype) ? "DELETE" : "ADD",
577 info->dest_ip,
578 info->dest_port, info->mac_addr, cminfo->vlan_id);
579 else
580 i40iw_debug(dev, I40IW_DEBUG_CM,
581 "%s:%s IP=%pI6, port=%d, mac=%pM, vlan_id=%d\n",
582 __func__, (!mtype) ? "DELETE" : "ADD",
583 info->dest_ip,
584 info->dest_port, info->mac_addr, cminfo->vlan_id);
585 cqp_info->in.u.manage_qhash_table_entry.cqp = &iwdev->cqp.sc_cqp;
586 cqp_info->in.u.manage_qhash_table_entry.scratch = (uintptr_t)cqp_request;
587 cqp_info->cqp_cmd = OP_MANAGE_QHASH_TABLE_ENTRY;
588 cqp_info->post_sq = 1;
589 status = i40iw_handle_cqp_op(iwdev, cqp_request);
590 if (status)
591 i40iw_pr_err("CQP-OP Manage Qhash Entry fail");
592 return status;
593}
594
595/**
596 * i40iw_hw_flush_wqes - flush qp's wqe
597 * @iwdev: iwarp device
598 * @qp: hardware control qp
599 * @info: info for flush
600 * @wait: flag wait for completion
601 */
602enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
603 struct i40iw_sc_qp *qp,
604 struct i40iw_qp_flush_info *info,
605 bool wait)
606{
607 enum i40iw_status_code status;
608 struct i40iw_qp_flush_info *hw_info;
609 struct i40iw_cqp_request *cqp_request;
610 struct cqp_commands_info *cqp_info;
611
612 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
613 if (!cqp_request)
614 return I40IW_ERR_NO_MEMORY;
615
616 cqp_info = &cqp_request->info;
617 hw_info = &cqp_request->info.in.u.qp_flush_wqes.info;
618 memcpy(hw_info, info, sizeof(*hw_info));
619
620 cqp_info->cqp_cmd = OP_QP_FLUSH_WQES;
621 cqp_info->post_sq = 1;
622 cqp_info->in.u.qp_flush_wqes.qp = qp;
623 cqp_info->in.u.qp_flush_wqes.scratch = (uintptr_t)cqp_request;
624 status = i40iw_handle_cqp_op(iwdev, cqp_request);
625 if (status)
626 i40iw_pr_err("CQP-OP Flush WQE's fail");
627 return status;
628}
629
630/**
631 * i40iw_hw_manage_vf_pble_bp - manage vf pbles
632 * @iwdev: iwarp device
633 * @info: info for managing pble
634 * @wait: flag wait for completion
635 */
636enum i40iw_status_code i40iw_hw_manage_vf_pble_bp(struct i40iw_device *iwdev,
637 struct i40iw_manage_vf_pble_info *info,
638 bool wait)
639{
640 enum i40iw_status_code status;
641 struct i40iw_manage_vf_pble_info *hw_info;
642 struct i40iw_cqp_request *cqp_request;
643 struct cqp_commands_info *cqp_info;
644
645 if ((iwdev->init_state < CCQ_CREATED) && wait)
646 wait = false;
647
648 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
649 if (!cqp_request)
650 return I40IW_ERR_NO_MEMORY;
651
652 cqp_info = &cqp_request->info;
653 hw_info = &cqp_request->info.in.u.manage_vf_pble_bp.info;
654 memcpy(hw_info, info, sizeof(*hw_info));
655
656 cqp_info->cqp_cmd = OP_MANAGE_VF_PBLE_BP;
657 cqp_info->post_sq = 1;
658 cqp_info->in.u.manage_vf_pble_bp.cqp = &iwdev->cqp.sc_cqp;
659 cqp_info->in.u.manage_vf_pble_bp.scratch = (uintptr_t)cqp_request;
660 status = i40iw_handle_cqp_op(iwdev, cqp_request);
661 if (status)
662 i40iw_pr_err("CQP-OP Manage VF pble_bp fail");
663 return status;
664}
665
666/**
667 * i40iw_get_ib_wc - return change flush code to IB's
668 * @opcode: iwarp flush code
669 */
670static enum ib_wc_status i40iw_get_ib_wc(enum i40iw_flush_opcode opcode)
671{
672 switch (opcode) {
673 case FLUSH_PROT_ERR:
674 return IB_WC_LOC_PROT_ERR;
675 case FLUSH_REM_ACCESS_ERR:
676 return IB_WC_REM_ACCESS_ERR;
677 case FLUSH_LOC_QP_OP_ERR:
678 return IB_WC_LOC_QP_OP_ERR;
679 case FLUSH_REM_OP_ERR:
680 return IB_WC_REM_OP_ERR;
681 case FLUSH_LOC_LEN_ERR:
682 return IB_WC_LOC_LEN_ERR;
683 case FLUSH_GENERAL_ERR:
684 return IB_WC_GENERAL_ERR;
685 case FLUSH_FATAL_ERR:
686 default:
687 return IB_WC_FATAL_ERR;
688 }
689}
690
691/**
692 * i40iw_set_flush_info - set flush info
693 * @pinfo: set flush info
694 * @min: minor err
695 * @maj: major err
696 * @opcode: flush error code
697 */
698static void i40iw_set_flush_info(struct i40iw_qp_flush_info *pinfo,
699 u16 *min,
700 u16 *maj,
701 enum i40iw_flush_opcode opcode)
702{
703 *min = (u16)i40iw_get_ib_wc(opcode);
704 *maj = CQE_MAJOR_DRV;
705 pinfo->userflushcode = true;
706}
707
708/**
709 * i40iw_flush_wqes - flush wqe for qp
710 * @iwdev: iwarp device
711 * @iwqp: qp to flush wqes
712 */
713void i40iw_flush_wqes(struct i40iw_device *iwdev, struct i40iw_qp *iwqp)
714{
715 struct i40iw_qp_flush_info info;
716 struct i40iw_qp_flush_info *pinfo = &info;
717
718 struct i40iw_sc_qp *qp = &iwqp->sc_qp;
719
720 memset(pinfo, 0, sizeof(*pinfo));
721 info.sq = true;
722 info.rq = true;
723 if (qp->term_flags) {
724 i40iw_set_flush_info(pinfo, &pinfo->sq_minor_code,
725 &pinfo->sq_major_code, qp->flush_code);
726 i40iw_set_flush_info(pinfo, &pinfo->rq_minor_code,
727 &pinfo->rq_major_code, qp->flush_code);
728 }
729 (void)i40iw_hw_flush_wqes(iwdev, &iwqp->sc_qp, &info, true);
730}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_main.c b/drivers/infiniband/hw/i40iw/i40iw_main.c
new file mode 100644
index 000000000000..90e5af21737e
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_main.c
@@ -0,0 +1,1910 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
41#include <linux/if_vlan.h>
42#include <net/addrconf.h>
43
44#include "i40iw.h"
45#include "i40iw_register.h"
46#include <net/netevent.h>
47#define CLIENT_IW_INTERFACE_VERSION_MAJOR 0
48#define CLIENT_IW_INTERFACE_VERSION_MINOR 01
49#define CLIENT_IW_INTERFACE_VERSION_BUILD 00
50
51#define DRV_VERSION_MAJOR 0
52#define DRV_VERSION_MINOR 5
53#define DRV_VERSION_BUILD 123
54#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
55 __stringify(DRV_VERSION_MINOR) "." __stringify(DRV_VERSION_BUILD)
56
57static int push_mode;
58module_param(push_mode, int, 0644);
59MODULE_PARM_DESC(push_mode, "Low latency mode: 0=disabled (default), 1=enabled)");
60
61static int debug;
62module_param(debug, int, 0644);
63MODULE_PARM_DESC(debug, "debug flags: 0=disabled (default), 0x7fffffff=all");
64
65static int resource_profile;
66module_param(resource_profile, int, 0644);
67MODULE_PARM_DESC(resource_profile,
68 "Resource Profile: 0=no VF RDMA support (default), 1=Weighted VF, 2=Even Distribution");
69
70static int max_rdma_vfs = 32;
71module_param(max_rdma_vfs, int, 0644);
72MODULE_PARM_DESC(max_rdma_vfs, "Maximum VF count: 0-32 32=default");
73static int mpa_version = 2;
74module_param(mpa_version, int, 0644);
75MODULE_PARM_DESC(mpa_version, "MPA version to be used in MPA Req/Resp 1 or 2");
76
77MODULE_AUTHOR("Intel Corporation, <e1000-rdma@lists.sourceforge.net>");
78MODULE_DESCRIPTION("Intel(R) Ethernet Connection X722 iWARP RDMA Driver");
79MODULE_LICENSE("Dual BSD/GPL");
80MODULE_VERSION(DRV_VERSION);
81
82static struct i40e_client i40iw_client;
83static char i40iw_client_name[I40E_CLIENT_STR_LENGTH] = "i40iw";
84
85static LIST_HEAD(i40iw_handlers);
86static spinlock_t i40iw_handler_lock;
87
88static enum i40iw_status_code i40iw_virtchnl_send(struct i40iw_sc_dev *dev,
89 u32 vf_id, u8 *msg, u16 len);
90
91static struct notifier_block i40iw_inetaddr_notifier = {
92 .notifier_call = i40iw_inetaddr_event
93};
94
95static struct notifier_block i40iw_inetaddr6_notifier = {
96 .notifier_call = i40iw_inet6addr_event
97};
98
99static struct notifier_block i40iw_net_notifier = {
100 .notifier_call = i40iw_net_event
101};
102
103static int i40iw_notifiers_registered;
104
105/**
106 * i40iw_find_i40e_handler - find a handler given a client info
107 * @ldev: pointer to a client info
108 */
109static struct i40iw_handler *i40iw_find_i40e_handler(struct i40e_info *ldev)
110{
111 struct i40iw_handler *hdl;
112 unsigned long flags;
113
114 spin_lock_irqsave(&i40iw_handler_lock, flags);
115 list_for_each_entry(hdl, &i40iw_handlers, list) {
116 if (hdl->ldev.netdev == ldev->netdev) {
117 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
118 return hdl;
119 }
120 }
121 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
122 return NULL;
123}
124
125/**
126 * i40iw_find_netdev - find a handler given a netdev
127 * @netdev: pointer to net_device
128 */
129struct i40iw_handler *i40iw_find_netdev(struct net_device *netdev)
130{
131 struct i40iw_handler *hdl;
132 unsigned long flags;
133
134 spin_lock_irqsave(&i40iw_handler_lock, flags);
135 list_for_each_entry(hdl, &i40iw_handlers, list) {
136 if (hdl->ldev.netdev == netdev) {
137 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
138 return hdl;
139 }
140 }
141 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
142 return NULL;
143}
144
145/**
146 * i40iw_add_handler - add a handler to the list
147 * @hdl: handler to be added to the handler list
148 */
149static void i40iw_add_handler(struct i40iw_handler *hdl)
150{
151 unsigned long flags;
152
153 spin_lock_irqsave(&i40iw_handler_lock, flags);
154 list_add(&hdl->list, &i40iw_handlers);
155 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
156}
157
158/**
159 * i40iw_del_handler - delete a handler from the list
160 * @hdl: handler to be deleted from the handler list
161 */
162static int i40iw_del_handler(struct i40iw_handler *hdl)
163{
164 unsigned long flags;
165
166 spin_lock_irqsave(&i40iw_handler_lock, flags);
167 list_del(&hdl->list);
168 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
169 return 0;
170}
171
172/**
173 * i40iw_enable_intr - set up device interrupts
174 * @dev: hardware control device structure
175 * @msix_id: id of the interrupt to be enabled
176 */
177static void i40iw_enable_intr(struct i40iw_sc_dev *dev, u32 msix_id)
178{
179 u32 val;
180
181 val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
182 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
183 (3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
184 if (dev->is_pf)
185 i40iw_wr32(dev->hw, I40E_PFINT_DYN_CTLN(msix_id - 1), val);
186 else
187 i40iw_wr32(dev->hw, I40E_VFINT_DYN_CTLN1(msix_id - 1), val);
188}
189
190/**
191 * i40iw_dpc - tasklet for aeq and ceq 0
192 * @data: iwarp device
193 */
194static void i40iw_dpc(unsigned long data)
195{
196 struct i40iw_device *iwdev = (struct i40iw_device *)data;
197
198 if (iwdev->msix_shared)
199 i40iw_process_ceq(iwdev, iwdev->ceqlist);
200 i40iw_process_aeq(iwdev);
201 i40iw_enable_intr(&iwdev->sc_dev, iwdev->iw_msixtbl[0].idx);
202}
203
204/**
205 * i40iw_ceq_dpc - dpc handler for CEQ
206 * @data: data points to CEQ
207 */
208static void i40iw_ceq_dpc(unsigned long data)
209{
210 struct i40iw_ceq *iwceq = (struct i40iw_ceq *)data;
211 struct i40iw_device *iwdev = iwceq->iwdev;
212
213 i40iw_process_ceq(iwdev, iwceq);
214 i40iw_enable_intr(&iwdev->sc_dev, iwceq->msix_idx);
215}
216
217/**
218 * i40iw_irq_handler - interrupt handler for aeq and ceq0
219 * @irq: Interrupt request number
220 * @data: iwarp device
221 */
222static irqreturn_t i40iw_irq_handler(int irq, void *data)
223{
224 struct i40iw_device *iwdev = (struct i40iw_device *)data;
225
226 tasklet_schedule(&iwdev->dpc_tasklet);
227 return IRQ_HANDLED;
228}
229
230/**
231 * i40iw_destroy_cqp - destroy control qp
232 * @iwdev: iwarp device
233 * @create_done: 1 if cqp create poll was success
234 *
235 * Issue destroy cqp request and
236 * free the resources associated with the cqp
237 */
238static void i40iw_destroy_cqp(struct i40iw_device *iwdev, bool free_hwcqp)
239{
240 enum i40iw_status_code status = 0;
241 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
242 struct i40iw_cqp *cqp = &iwdev->cqp;
243
244 if (free_hwcqp && dev->cqp_ops->cqp_destroy)
245 status = dev->cqp_ops->cqp_destroy(dev->cqp);
246 if (status)
247 i40iw_pr_err("destroy cqp failed");
248
249 i40iw_free_dma_mem(dev->hw, &cqp->sq);
250 kfree(cqp->scratch_array);
251 iwdev->cqp.scratch_array = NULL;
252
253 kfree(cqp->cqp_requests);
254 cqp->cqp_requests = NULL;
255}
256
257/**
258 * i40iw_disable_irqs - disable device interrupts
259 * @dev: hardware control device structure
260 * @msic_vec: msix vector to disable irq
261 * @dev_id: parameter to pass to free_irq (used during irq setup)
262 *
263 * The function is called when destroying aeq/ceq
264 */
265static void i40iw_disable_irq(struct i40iw_sc_dev *dev,
266 struct i40iw_msix_vector *msix_vec,
267 void *dev_id)
268{
269 if (dev->is_pf)
270 i40iw_wr32(dev->hw, I40E_PFINT_DYN_CTLN(msix_vec->idx - 1), 0);
271 else
272 i40iw_wr32(dev->hw, I40E_VFINT_DYN_CTLN1(msix_vec->idx - 1), 0);
273 synchronize_irq(msix_vec->irq);
274 free_irq(msix_vec->irq, dev_id);
275}
276
277/**
278 * i40iw_destroy_aeq - destroy aeq
279 * @iwdev: iwarp device
280 * @reset: true if called before reset
281 *
282 * Issue a destroy aeq request and
283 * free the resources associated with the aeq
284 * The function is called during driver unload
285 */
286static void i40iw_destroy_aeq(struct i40iw_device *iwdev, bool reset)
287{
288 enum i40iw_status_code status = I40IW_ERR_NOT_READY;
289 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
290 struct i40iw_aeq *aeq = &iwdev->aeq;
291
292 if (!iwdev->msix_shared)
293 i40iw_disable_irq(dev, iwdev->iw_msixtbl, (void *)iwdev);
294 if (reset)
295 goto exit;
296
297 if (!dev->aeq_ops->aeq_destroy(&aeq->sc_aeq, 0, 1))
298 status = dev->aeq_ops->aeq_destroy_done(&aeq->sc_aeq);
299 if (status)
300 i40iw_pr_err("destroy aeq failed %d\n", status);
301
302exit:
303 i40iw_free_dma_mem(dev->hw, &aeq->mem);
304}
305
306/**
307 * i40iw_destroy_ceq - destroy ceq
308 * @iwdev: iwarp device
309 * @iwceq: ceq to be destroyed
310 * @reset: true if called before reset
311 *
312 * Issue a destroy ceq request and
313 * free the resources associated with the ceq
314 */
315static void i40iw_destroy_ceq(struct i40iw_device *iwdev,
316 struct i40iw_ceq *iwceq,
317 bool reset)
318{
319 enum i40iw_status_code status;
320 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
321
322 if (reset)
323 goto exit;
324
325 status = dev->ceq_ops->ceq_destroy(&iwceq->sc_ceq, 0, 1);
326 if (status) {
327 i40iw_pr_err("ceq destroy command failed %d\n", status);
328 goto exit;
329 }
330
331 status = dev->ceq_ops->cceq_destroy_done(&iwceq->sc_ceq);
332 if (status)
333 i40iw_pr_err("ceq destroy completion failed %d\n", status);
334exit:
335 i40iw_free_dma_mem(dev->hw, &iwceq->mem);
336}
337
338/**
339 * i40iw_dele_ceqs - destroy all ceq's
340 * @iwdev: iwarp device
341 * @reset: true if called before reset
342 *
343 * Go through all of the device ceq's and for each ceq
344 * disable the ceq interrupt and destroy the ceq
345 */
346static void i40iw_dele_ceqs(struct i40iw_device *iwdev, bool reset)
347{
348 u32 i = 0;
349 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
350 struct i40iw_ceq *iwceq = iwdev->ceqlist;
351 struct i40iw_msix_vector *msix_vec = iwdev->iw_msixtbl;
352
353 if (iwdev->msix_shared) {
354 i40iw_disable_irq(dev, msix_vec, (void *)iwdev);
355 i40iw_destroy_ceq(iwdev, iwceq, reset);
356 iwceq++;
357 i++;
358 }
359
360 for (msix_vec++; i < iwdev->ceqs_count; i++, msix_vec++, iwceq++) {
361 i40iw_disable_irq(dev, msix_vec, (void *)iwceq);
362 i40iw_destroy_ceq(iwdev, iwceq, reset);
363 }
364}
365
366/**
367 * i40iw_destroy_ccq - destroy control cq
368 * @iwdev: iwarp device
369 * @reset: true if called before reset
370 *
371 * Issue destroy ccq request and
372 * free the resources associated with the ccq
373 */
374static void i40iw_destroy_ccq(struct i40iw_device *iwdev, bool reset)
375{
376 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
377 struct i40iw_ccq *ccq = &iwdev->ccq;
378 enum i40iw_status_code status = 0;
379
380 if (!reset)
381 status = dev->ccq_ops->ccq_destroy(dev->ccq, 0, true);
382 if (status)
383 i40iw_pr_err("ccq destroy failed %d\n", status);
384 i40iw_free_dma_mem(dev->hw, &ccq->mem_cq);
385}
386
387/* types of hmc objects */
388static enum i40iw_hmc_rsrc_type iw_hmc_obj_types[] = {
389 I40IW_HMC_IW_QP,
390 I40IW_HMC_IW_CQ,
391 I40IW_HMC_IW_HTE,
392 I40IW_HMC_IW_ARP,
393 I40IW_HMC_IW_APBVT_ENTRY,
394 I40IW_HMC_IW_MR,
395 I40IW_HMC_IW_XF,
396 I40IW_HMC_IW_XFFL,
397 I40IW_HMC_IW_Q1,
398 I40IW_HMC_IW_Q1FL,
399 I40IW_HMC_IW_TIMER,
400};
401
402/**
403 * i40iw_close_hmc_objects_type - delete hmc objects of a given type
404 * @iwdev: iwarp device
405 * @obj_type: the hmc object type to be deleted
406 * @is_pf: true if the function is PF otherwise false
407 * @reset: true if called before reset
408 */
409static void i40iw_close_hmc_objects_type(struct i40iw_sc_dev *dev,
410 enum i40iw_hmc_rsrc_type obj_type,
411 struct i40iw_hmc_info *hmc_info,
412 bool is_pf,
413 bool reset)
414{
415 struct i40iw_hmc_del_obj_info info;
416
417 memset(&info, 0, sizeof(info));
418 info.hmc_info = hmc_info;
419 info.rsrc_type = obj_type;
420 info.count = hmc_info->hmc_obj[obj_type].cnt;
421 info.is_pf = is_pf;
422 if (dev->hmc_ops->del_hmc_object(dev, &info, reset))
423 i40iw_pr_err("del obj of type %d failed\n", obj_type);
424}
425
426/**
427 * i40iw_del_hmc_objects - remove all device hmc objects
428 * @dev: iwarp device
429 * @hmc_info: hmc_info to free
430 * @is_pf: true if hmc_info belongs to PF, not vf nor allocated
431 * by PF on behalf of VF
432 * @reset: true if called before reset
433 */
434static void i40iw_del_hmc_objects(struct i40iw_sc_dev *dev,
435 struct i40iw_hmc_info *hmc_info,
436 bool is_pf,
437 bool reset)
438{
439 unsigned int i;
440
441 for (i = 0; i < IW_HMC_OBJ_TYPE_NUM; i++)
442 i40iw_close_hmc_objects_type(dev, iw_hmc_obj_types[i], hmc_info, is_pf, reset);
443}
444
445/**
446 * i40iw_ceq_handler - interrupt handler for ceq
447 * @data: ceq pointer
448 */
449static irqreturn_t i40iw_ceq_handler(int irq, void *data)
450{
451 struct i40iw_ceq *iwceq = (struct i40iw_ceq *)data;
452
453 if (iwceq->irq != irq)
454 i40iw_pr_err("expected irq = %d received irq = %d\n", iwceq->irq, irq);
455 tasklet_schedule(&iwceq->dpc_tasklet);
456 return IRQ_HANDLED;
457}
458
459/**
460 * i40iw_create_hmc_obj_type - create hmc object of a given type
461 * @dev: hardware control device structure
462 * @info: information for the hmc object to create
463 */
464static enum i40iw_status_code i40iw_create_hmc_obj_type(struct i40iw_sc_dev *dev,
465 struct i40iw_hmc_create_obj_info *info)
466{
467 return dev->hmc_ops->create_hmc_object(dev, info);
468}
469
470/**
471 * i40iw_create_hmc_objs - create all hmc objects for the device
472 * @iwdev: iwarp device
473 * @is_pf: true if the function is PF otherwise false
474 *
475 * Create the device hmc objects and allocate hmc pages
476 * Return 0 if successful, otherwise clean up and return error
477 */
478static enum i40iw_status_code i40iw_create_hmc_objs(struct i40iw_device *iwdev,
479 bool is_pf)
480{
481 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
482 struct i40iw_hmc_create_obj_info info;
483 enum i40iw_status_code status;
484 int i;
485
486 memset(&info, 0, sizeof(info));
487 info.hmc_info = dev->hmc_info;
488 info.is_pf = is_pf;
489 info.entry_type = iwdev->sd_type;
490 for (i = 0; i < IW_HMC_OBJ_TYPE_NUM; i++) {
491 info.rsrc_type = iw_hmc_obj_types[i];
492 info.count = dev->hmc_info->hmc_obj[info.rsrc_type].cnt;
493 status = i40iw_create_hmc_obj_type(dev, &info);
494 if (status) {
495 i40iw_pr_err("create obj type %d status = %d\n",
496 iw_hmc_obj_types[i], status);
497 break;
498 }
499 }
500 if (!status)
501 return (dev->cqp_misc_ops->static_hmc_pages_allocated(dev->cqp, 0,
502 dev->hmc_fn_id,
503 true, true));
504
505 while (i) {
506 i--;
507 /* destroy the hmc objects of a given type */
508 i40iw_close_hmc_objects_type(dev,
509 iw_hmc_obj_types[i],
510 dev->hmc_info,
511 is_pf,
512 false);
513 }
514 return status;
515}
516
517/**
518 * i40iw_obj_aligned_mem - get aligned memory from device allocated memory
519 * @iwdev: iwarp device
520 * @memptr: points to the memory addresses
521 * @size: size of memory needed
522 * @mask: mask for the aligned memory
523 *
524 * Get aligned memory of the requested size and
525 * update the memptr to point to the new aligned memory
526 * Return 0 if successful, otherwise return no memory error
527 */
528enum i40iw_status_code i40iw_obj_aligned_mem(struct i40iw_device *iwdev,
529 struct i40iw_dma_mem *memptr,
530 u32 size,
531 u32 mask)
532{
533 unsigned long va, newva;
534 unsigned long extra;
535
536 va = (unsigned long)iwdev->obj_next.va;
537 newva = va;
538 if (mask)
539 newva = ALIGN(va, (mask + 1));
540 extra = newva - va;
541 memptr->va = (u8 *)va + extra;
542 memptr->pa = iwdev->obj_next.pa + extra;
543 memptr->size = size;
544 if ((memptr->va + size) > (iwdev->obj_mem.va + iwdev->obj_mem.size))
545 return I40IW_ERR_NO_MEMORY;
546
547 iwdev->obj_next.va = memptr->va + size;
548 iwdev->obj_next.pa = memptr->pa + size;
549 return 0;
550}
551
552/**
553 * i40iw_create_cqp - create control qp
554 * @iwdev: iwarp device
555 *
556 * Return 0, if the cqp and all the resources associated with it
557 * are successfully created, otherwise return error
558 */
559static enum i40iw_status_code i40iw_create_cqp(struct i40iw_device *iwdev)
560{
561 enum i40iw_status_code status;
562 u32 sqsize = I40IW_CQP_SW_SQSIZE_2048;
563 struct i40iw_dma_mem mem;
564 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
565 struct i40iw_cqp_init_info cqp_init_info;
566 struct i40iw_cqp *cqp = &iwdev->cqp;
567 u16 maj_err, min_err;
568 int i;
569
570 cqp->cqp_requests = kcalloc(sqsize, sizeof(*cqp->cqp_requests), GFP_KERNEL);
571 if (!cqp->cqp_requests)
572 return I40IW_ERR_NO_MEMORY;
573 cqp->scratch_array = kcalloc(sqsize, sizeof(*cqp->scratch_array), GFP_KERNEL);
574 if (!cqp->scratch_array) {
575 kfree(cqp->cqp_requests);
576 return I40IW_ERR_NO_MEMORY;
577 }
578 dev->cqp = &cqp->sc_cqp;
579 dev->cqp->dev = dev;
580 memset(&cqp_init_info, 0, sizeof(cqp_init_info));
581 status = i40iw_allocate_dma_mem(dev->hw, &cqp->sq,
582 (sizeof(struct i40iw_cqp_sq_wqe) * sqsize),
583 I40IW_CQP_ALIGNMENT);
584 if (status)
585 goto exit;
586 status = i40iw_obj_aligned_mem(iwdev, &mem, sizeof(struct i40iw_cqp_ctx),
587 I40IW_HOST_CTX_ALIGNMENT_MASK);
588 if (status)
589 goto exit;
590 dev->cqp->host_ctx_pa = mem.pa;
591 dev->cqp->host_ctx = mem.va;
592 /* populate the cqp init info */
593 cqp_init_info.dev = dev;
594 cqp_init_info.sq_size = sqsize;
595 cqp_init_info.sq = cqp->sq.va;
596 cqp_init_info.sq_pa = cqp->sq.pa;
597 cqp_init_info.host_ctx_pa = mem.pa;
598 cqp_init_info.host_ctx = mem.va;
599 cqp_init_info.hmc_profile = iwdev->resource_profile;
600 cqp_init_info.enabled_vf_count = iwdev->max_rdma_vfs;
601 cqp_init_info.scratch_array = cqp->scratch_array;
602 status = dev->cqp_ops->cqp_init(dev->cqp, &cqp_init_info);
603 if (status) {
604 i40iw_pr_err("cqp init status %d maj_err %d min_err %d\n",
605 status, maj_err, min_err);
606 goto exit;
607 }
608 status = dev->cqp_ops->cqp_create(dev->cqp, true, &maj_err, &min_err);
609 if (status) {
610 i40iw_pr_err("cqp create status %d maj_err %d min_err %d\n",
611 status, maj_err, min_err);
612 goto exit;
613 }
614 spin_lock_init(&cqp->req_lock);
615 INIT_LIST_HEAD(&cqp->cqp_avail_reqs);
616 INIT_LIST_HEAD(&cqp->cqp_pending_reqs);
617 /* init the waitq of the cqp_requests and add them to the list */
618 for (i = 0; i < I40IW_CQP_SW_SQSIZE_2048; i++) {
619 init_waitqueue_head(&cqp->cqp_requests[i].waitq);
620 list_add_tail(&cqp->cqp_requests[i].list, &cqp->cqp_avail_reqs);
621 }
622 return 0;
623exit:
624 /* clean up the created resources */
625 i40iw_destroy_cqp(iwdev, false);
626 return status;
627}
628
629/**
630 * i40iw_create_ccq - create control cq
631 * @iwdev: iwarp device
632 *
633 * Return 0, if the ccq and the resources associated with it
634 * are successfully created, otherwise return error
635 */
636static enum i40iw_status_code i40iw_create_ccq(struct i40iw_device *iwdev)
637{
638 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
639 struct i40iw_dma_mem mem;
640 enum i40iw_status_code status;
641 struct i40iw_ccq_init_info info;
642 struct i40iw_ccq *ccq = &iwdev->ccq;
643
644 memset(&info, 0, sizeof(info));
645 dev->ccq = &ccq->sc_cq;
646 dev->ccq->dev = dev;
647 info.dev = dev;
648 ccq->shadow_area.size = sizeof(struct i40iw_cq_shadow_area);
649 ccq->mem_cq.size = sizeof(struct i40iw_cqe) * IW_CCQ_SIZE;
650 status = i40iw_allocate_dma_mem(dev->hw, &ccq->mem_cq,
651 ccq->mem_cq.size, I40IW_CQ0_ALIGNMENT);
652 if (status)
653 goto exit;
654 status = i40iw_obj_aligned_mem(iwdev, &mem, ccq->shadow_area.size,
655 I40IW_SHADOWAREA_MASK);
656 if (status)
657 goto exit;
658 ccq->sc_cq.back_cq = (void *)ccq;
659 /* populate the ccq init info */
660 info.cq_base = ccq->mem_cq.va;
661 info.cq_pa = ccq->mem_cq.pa;
662 info.num_elem = IW_CCQ_SIZE;
663 info.shadow_area = mem.va;
664 info.shadow_area_pa = mem.pa;
665 info.ceqe_mask = false;
666 info.ceq_id_valid = true;
667 info.shadow_read_threshold = 16;
668 status = dev->ccq_ops->ccq_init(dev->ccq, &info);
669 if (!status)
670 status = dev->ccq_ops->ccq_create(dev->ccq, 0, true, true);
671exit:
672 if (status)
673 i40iw_free_dma_mem(dev->hw, &ccq->mem_cq);
674 return status;
675}
676
677/**
678 * i40iw_configure_ceq_vector - set up the msix interrupt vector for ceq
679 * @iwdev: iwarp device
680 * @msix_vec: interrupt vector information
681 * @iwceq: ceq associated with the vector
682 * @ceq_id: the id number of the iwceq
683 *
684 * Allocate interrupt resources and enable irq handling
685 * Return 0 if successful, otherwise return error
686 */
687static enum i40iw_status_code i40iw_configure_ceq_vector(struct i40iw_device *iwdev,
688 struct i40iw_ceq *iwceq,
689 u32 ceq_id,
690 struct i40iw_msix_vector *msix_vec)
691{
692 enum i40iw_status_code status;
693
694 if (iwdev->msix_shared && !ceq_id) {
695 tasklet_init(&iwdev->dpc_tasklet, i40iw_dpc, (unsigned long)iwdev);
696 status = request_irq(msix_vec->irq, i40iw_irq_handler, 0, "AEQCEQ", iwdev);
697 } else {
698 tasklet_init(&iwceq->dpc_tasklet, i40iw_ceq_dpc, (unsigned long)iwceq);
699 status = request_irq(msix_vec->irq, i40iw_ceq_handler, 0, "CEQ", iwceq);
700 }
701
702 if (status) {
703 i40iw_pr_err("ceq irq config fail\n");
704 return I40IW_ERR_CONFIG;
705 }
706 msix_vec->ceq_id = ceq_id;
707 msix_vec->cpu_affinity = 0;
708
709 return 0;
710}
711
712/**
713 * i40iw_create_ceq - create completion event queue
714 * @iwdev: iwarp device
715 * @iwceq: pointer to the ceq resources to be created
716 * @ceq_id: the id number of the iwceq
717 *
718 * Return 0, if the ceq and the resources associated with it
719 * are successfully created, otherwise return error
720 */
721static enum i40iw_status_code i40iw_create_ceq(struct i40iw_device *iwdev,
722 struct i40iw_ceq *iwceq,
723 u32 ceq_id)
724{
725 enum i40iw_status_code status;
726 struct i40iw_ceq_init_info info;
727 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
728 u64 scratch;
729
730 memset(&info, 0, sizeof(info));
731 info.ceq_id = ceq_id;
732 iwceq->iwdev = iwdev;
733 iwceq->mem.size = sizeof(struct i40iw_ceqe) *
734 iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
735 status = i40iw_allocate_dma_mem(dev->hw, &iwceq->mem, iwceq->mem.size,
736 I40IW_CEQ_ALIGNMENT);
737 if (status)
738 goto exit;
739 info.ceq_id = ceq_id;
740 info.ceqe_base = iwceq->mem.va;
741 info.ceqe_pa = iwceq->mem.pa;
742
743 info.elem_cnt = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
744 iwceq->sc_ceq.ceq_id = ceq_id;
745 info.dev = dev;
746 scratch = (uintptr_t)&iwdev->cqp.sc_cqp;
747 status = dev->ceq_ops->ceq_init(&iwceq->sc_ceq, &info);
748 if (!status)
749 status = dev->ceq_ops->cceq_create(&iwceq->sc_ceq, scratch);
750
751exit:
752 if (status)
753 i40iw_free_dma_mem(dev->hw, &iwceq->mem);
754 return status;
755}
756
757void i40iw_request_reset(struct i40iw_device *iwdev)
758{
759 struct i40e_info *ldev = iwdev->ldev;
760
761 ldev->ops->request_reset(ldev, iwdev->client, 1);
762}
763
764/**
765 * i40iw_setup_ceqs - manage the device ceq's and their interrupt resources
766 * @iwdev: iwarp device
767 * @ldev: i40e lan device
768 *
769 * Allocate a list for all device completion event queues
770 * Create the ceq's and configure their msix interrupt vectors
771 * Return 0, if at least one ceq is successfully set up, otherwise return error
772 */
773static enum i40iw_status_code i40iw_setup_ceqs(struct i40iw_device *iwdev,
774 struct i40e_info *ldev)
775{
776 u32 i;
777 u32 ceq_id;
778 struct i40iw_ceq *iwceq;
779 struct i40iw_msix_vector *msix_vec;
780 enum i40iw_status_code status = 0;
781 u32 num_ceqs;
782
783 if (ldev && ldev->ops && ldev->ops->setup_qvlist) {
784 status = ldev->ops->setup_qvlist(ldev, &i40iw_client,
785 iwdev->iw_qvlist);
786 if (status)
787 goto exit;
788 } else {
789 status = I40IW_ERR_BAD_PTR;
790 goto exit;
791 }
792
793 num_ceqs = min(iwdev->msix_count, iwdev->sc_dev.hmc_fpm_misc.max_ceqs);
794 iwdev->ceqlist = kcalloc(num_ceqs, sizeof(*iwdev->ceqlist), GFP_KERNEL);
795 if (!iwdev->ceqlist) {
796 status = I40IW_ERR_NO_MEMORY;
797 goto exit;
798 }
799 i = (iwdev->msix_shared) ? 0 : 1;
800 for (ceq_id = 0; i < num_ceqs; i++, ceq_id++) {
801 iwceq = &iwdev->ceqlist[ceq_id];
802 status = i40iw_create_ceq(iwdev, iwceq, ceq_id);
803 if (status) {
804 i40iw_pr_err("create ceq status = %d\n", status);
805 break;
806 }
807
808 msix_vec = &iwdev->iw_msixtbl[i];
809 iwceq->irq = msix_vec->irq;
810 iwceq->msix_idx = msix_vec->idx;
811 status = i40iw_configure_ceq_vector(iwdev, iwceq, ceq_id, msix_vec);
812 if (status) {
813 i40iw_destroy_ceq(iwdev, iwceq, false);
814 break;
815 }
816 i40iw_enable_intr(&iwdev->sc_dev, msix_vec->idx);
817 iwdev->ceqs_count++;
818 }
819
820exit:
821 if (status) {
822 if (!iwdev->ceqs_count) {
823 kfree(iwdev->ceqlist);
824 iwdev->ceqlist = NULL;
825 } else {
826 status = 0;
827 }
828 }
829 return status;
830}
831
832/**
833 * i40iw_configure_aeq_vector - set up the msix vector for aeq
834 * @iwdev: iwarp device
835 *
836 * Allocate interrupt resources and enable irq handling
837 * Return 0 if successful, otherwise return error
838 */
839static enum i40iw_status_code i40iw_configure_aeq_vector(struct i40iw_device *iwdev)
840{
841 struct i40iw_msix_vector *msix_vec = iwdev->iw_msixtbl;
842 u32 ret = 0;
843
844 if (!iwdev->msix_shared) {
845 tasklet_init(&iwdev->dpc_tasklet, i40iw_dpc, (unsigned long)iwdev);
846 ret = request_irq(msix_vec->irq, i40iw_irq_handler, 0, "i40iw", iwdev);
847 }
848 if (ret) {
849 i40iw_pr_err("aeq irq config fail\n");
850 return I40IW_ERR_CONFIG;
851 }
852
853 return 0;
854}
855
856/**
857 * i40iw_create_aeq - create async event queue
858 * @iwdev: iwarp device
859 *
860 * Return 0, if the aeq and the resources associated with it
861 * are successfully created, otherwise return error
862 */
863static enum i40iw_status_code i40iw_create_aeq(struct i40iw_device *iwdev)
864{
865 enum i40iw_status_code status;
866 struct i40iw_aeq_init_info info;
867 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
868 struct i40iw_aeq *aeq = &iwdev->aeq;
869 u64 scratch = 0;
870 u32 aeq_size;
871
872 aeq_size = 2 * iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt +
873 iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
874 memset(&info, 0, sizeof(info));
875 aeq->mem.size = sizeof(struct i40iw_sc_aeqe) * aeq_size;
876 status = i40iw_allocate_dma_mem(dev->hw, &aeq->mem, aeq->mem.size,
877 I40IW_AEQ_ALIGNMENT);
878 if (status)
879 goto exit;
880
881 info.aeqe_base = aeq->mem.va;
882 info.aeq_elem_pa = aeq->mem.pa;
883 info.elem_cnt = aeq_size;
884 info.dev = dev;
885 status = dev->aeq_ops->aeq_init(&aeq->sc_aeq, &info);
886 if (status)
887 goto exit;
888 status = dev->aeq_ops->aeq_create(&aeq->sc_aeq, scratch, 1);
889 if (!status)
890 status = dev->aeq_ops->aeq_create_done(&aeq->sc_aeq);
891exit:
892 if (status)
893 i40iw_free_dma_mem(dev->hw, &aeq->mem);
894 return status;
895}
896
897/**
898 * i40iw_setup_aeq - set up the device aeq
899 * @iwdev: iwarp device
900 *
901 * Create the aeq and configure its msix interrupt vector
902 * Return 0 if successful, otherwise return error
903 */
904static enum i40iw_status_code i40iw_setup_aeq(struct i40iw_device *iwdev)
905{
906 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
907 enum i40iw_status_code status;
908
909 status = i40iw_create_aeq(iwdev);
910 if (status)
911 return status;
912
913 status = i40iw_configure_aeq_vector(iwdev);
914 if (status) {
915 i40iw_destroy_aeq(iwdev, false);
916 return status;
917 }
918
919 if (!iwdev->msix_shared)
920 i40iw_enable_intr(dev, iwdev->iw_msixtbl[0].idx);
921 return 0;
922}
923
924/**
925 * i40iw_initialize_ilq - create iwarp local queue for cm
926 * @iwdev: iwarp device
927 *
928 * Return 0 if successful, otherwise return error
929 */
930static enum i40iw_status_code i40iw_initialize_ilq(struct i40iw_device *iwdev)
931{
932 struct i40iw_puda_rsrc_info info;
933 enum i40iw_status_code status;
934
935 info.type = I40IW_PUDA_RSRC_TYPE_ILQ;
936 info.cq_id = 1;
937 info.qp_id = 0;
938 info.count = 1;
939 info.pd_id = 1;
940 info.sq_size = 8192;
941 info.rq_size = 8192;
942 info.buf_size = 1024;
943 info.tx_buf_cnt = 16384;
944 info.mss = iwdev->mss;
945 info.receive = i40iw_receive_ilq;
946 info.xmit_complete = i40iw_free_sqbuf;
947 status = i40iw_puda_create_rsrc(&iwdev->sc_dev, &info);
948 if (status)
949 i40iw_pr_err("ilq create fail\n");
950 return status;
951}
952
953/**
954 * i40iw_initialize_ieq - create iwarp exception queue
955 * @iwdev: iwarp device
956 *
957 * Return 0 if successful, otherwise return error
958 */
959static enum i40iw_status_code i40iw_initialize_ieq(struct i40iw_device *iwdev)
960{
961 struct i40iw_puda_rsrc_info info;
962 enum i40iw_status_code status;
963
964 info.type = I40IW_PUDA_RSRC_TYPE_IEQ;
965 info.cq_id = 2;
966 info.qp_id = iwdev->sc_dev.exception_lan_queue;
967 info.count = 1;
968 info.pd_id = 2;
969 info.sq_size = 8192;
970 info.rq_size = 8192;
971 info.buf_size = 2048;
972 info.mss = iwdev->mss;
973 info.tx_buf_cnt = 16384;
974 status = i40iw_puda_create_rsrc(&iwdev->sc_dev, &info);
975 if (status)
976 i40iw_pr_err("ieq create fail\n");
977 return status;
978}
979
980/**
981 * i40iw_hmc_setup - create hmc objects for the device
982 * @iwdev: iwarp device
983 *
984 * Set up the device private memory space for the number and size of
985 * the hmc objects and create the objects
986 * Return 0 if successful, otherwise return error
987 */
988static enum i40iw_status_code i40iw_hmc_setup(struct i40iw_device *iwdev)
989{
990 enum i40iw_status_code status;
991
992 iwdev->sd_type = I40IW_SD_TYPE_DIRECT;
993 status = i40iw_config_fpm_values(&iwdev->sc_dev, IW_CFG_FPM_QP_COUNT);
994 if (status)
995 goto exit;
996 status = i40iw_create_hmc_objs(iwdev, true);
997 if (status)
998 goto exit;
999 iwdev->init_state = HMC_OBJS_CREATED;
1000exit:
1001 return status;
1002}
1003
1004/**
1005 * i40iw_del_init_mem - deallocate memory resources
1006 * @iwdev: iwarp device
1007 */
1008static void i40iw_del_init_mem(struct i40iw_device *iwdev)
1009{
1010 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1011
1012 i40iw_free_dma_mem(&iwdev->hw, &iwdev->obj_mem);
1013 kfree(dev->hmc_info->sd_table.sd_entry);
1014 dev->hmc_info->sd_table.sd_entry = NULL;
1015 kfree(iwdev->mem_resources);
1016 iwdev->mem_resources = NULL;
1017 kfree(iwdev->ceqlist);
1018 iwdev->ceqlist = NULL;
1019 kfree(iwdev->iw_msixtbl);
1020 iwdev->iw_msixtbl = NULL;
1021 kfree(iwdev->hmc_info_mem);
1022 iwdev->hmc_info_mem = NULL;
1023}
1024
1025/**
1026 * i40iw_del_macip_entry - remove a mac ip address entry from the hw table
1027 * @iwdev: iwarp device
1028 * @idx: the index of the mac ip address to delete
1029 */
1030static void i40iw_del_macip_entry(struct i40iw_device *iwdev, u8 idx)
1031{
1032 struct i40iw_cqp *iwcqp = &iwdev->cqp;
1033 struct i40iw_cqp_request *cqp_request;
1034 struct cqp_commands_info *cqp_info;
1035 enum i40iw_status_code status = 0;
1036
1037 cqp_request = i40iw_get_cqp_request(iwcqp, true);
1038 if (!cqp_request) {
1039 i40iw_pr_err("cqp_request memory failed\n");
1040 return;
1041 }
1042 cqp_info = &cqp_request->info;
1043 cqp_info->cqp_cmd = OP_DELETE_LOCAL_MAC_IPADDR_ENTRY;
1044 cqp_info->post_sq = 1;
1045 cqp_info->in.u.del_local_mac_ipaddr_entry.cqp = &iwcqp->sc_cqp;
1046 cqp_info->in.u.del_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1047 cqp_info->in.u.del_local_mac_ipaddr_entry.entry_idx = idx;
1048 cqp_info->in.u.del_local_mac_ipaddr_entry.ignore_ref_count = 0;
1049 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1050 if (status)
1051 i40iw_pr_err("CQP-OP Del MAC Ip entry fail");
1052}
1053
1054/**
1055 * i40iw_add_mac_ipaddr_entry - add a mac ip address entry to the hw table
1056 * @iwdev: iwarp device
1057 * @mac_addr: pointer to mac address
1058 * @idx: the index of the mac ip address to add
1059 */
1060static enum i40iw_status_code i40iw_add_mac_ipaddr_entry(struct i40iw_device *iwdev,
1061 u8 *mac_addr,
1062 u8 idx)
1063{
1064 struct i40iw_local_mac_ipaddr_entry_info *info;
1065 struct i40iw_cqp *iwcqp = &iwdev->cqp;
1066 struct i40iw_cqp_request *cqp_request;
1067 struct cqp_commands_info *cqp_info;
1068 enum i40iw_status_code status = 0;
1069
1070 cqp_request = i40iw_get_cqp_request(iwcqp, true);
1071 if (!cqp_request) {
1072 i40iw_pr_err("cqp_request memory failed\n");
1073 return I40IW_ERR_NO_MEMORY;
1074 }
1075
1076 cqp_info = &cqp_request->info;
1077
1078 cqp_info->post_sq = 1;
1079 info = &cqp_info->in.u.add_local_mac_ipaddr_entry.info;
1080 ether_addr_copy(info->mac_addr, mac_addr);
1081 info->entry_idx = idx;
1082 cqp_info->in.u.add_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1083 cqp_info->cqp_cmd = OP_ADD_LOCAL_MAC_IPADDR_ENTRY;
1084 cqp_info->in.u.add_local_mac_ipaddr_entry.cqp = &iwcqp->sc_cqp;
1085 cqp_info->in.u.add_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1086 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1087 if (status)
1088 i40iw_pr_err("CQP-OP Add MAC Ip entry fail");
1089 return status;
1090}
1091
1092/**
1093 * i40iw_alloc_local_mac_ipaddr_entry - allocate a mac ip address entry
1094 * @iwdev: iwarp device
1095 * @mac_ip_tbl_idx: the index of the new mac ip address
1096 *
1097 * Allocate a mac ip address entry and update the mac_ip_tbl_idx
1098 * to hold the index of the newly created mac ip address
1099 * Return 0 if successful, otherwise return error
1100 */
1101static enum i40iw_status_code i40iw_alloc_local_mac_ipaddr_entry(struct i40iw_device *iwdev,
1102 u16 *mac_ip_tbl_idx)
1103{
1104 struct i40iw_cqp *iwcqp = &iwdev->cqp;
1105 struct i40iw_cqp_request *cqp_request;
1106 struct cqp_commands_info *cqp_info;
1107 enum i40iw_status_code status = 0;
1108
1109 cqp_request = i40iw_get_cqp_request(iwcqp, true);
1110 if (!cqp_request) {
1111 i40iw_pr_err("cqp_request memory failed\n");
1112 return I40IW_ERR_NO_MEMORY;
1113 }
1114
1115 /* increment refcount, because we need the cqp request ret value */
1116 atomic_inc(&cqp_request->refcount);
1117
1118 cqp_info = &cqp_request->info;
1119 cqp_info->cqp_cmd = OP_ALLOC_LOCAL_MAC_IPADDR_ENTRY;
1120 cqp_info->post_sq = 1;
1121 cqp_info->in.u.alloc_local_mac_ipaddr_entry.cqp = &iwcqp->sc_cqp;
1122 cqp_info->in.u.alloc_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1123 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1124 if (!status)
1125 *mac_ip_tbl_idx = cqp_request->compl_info.op_ret_val;
1126 else
1127 i40iw_pr_err("CQP-OP Alloc MAC Ip entry fail");
1128 /* decrement refcount and free the cqp request, if no longer used */
1129 i40iw_put_cqp_request(iwcqp, cqp_request);
1130 return status;
1131}
1132
1133/**
1134 * i40iw_alloc_set_mac_ipaddr - set up a mac ip address table entry
1135 * @iwdev: iwarp device
1136 * @macaddr: pointer to mac address
1137 *
1138 * Allocate a mac ip address entry and add it to the hw table
1139 * Return 0 if successful, otherwise return error
1140 */
1141static enum i40iw_status_code i40iw_alloc_set_mac_ipaddr(struct i40iw_device *iwdev,
1142 u8 *macaddr)
1143{
1144 enum i40iw_status_code status;
1145
1146 status = i40iw_alloc_local_mac_ipaddr_entry(iwdev, &iwdev->mac_ip_table_idx);
1147 if (!status) {
1148 status = i40iw_add_mac_ipaddr_entry(iwdev, macaddr,
1149 (u8)iwdev->mac_ip_table_idx);
1150 if (!status)
1151 status = i40iw_add_mac_ipaddr_entry(iwdev, macaddr,
1152 (u8)iwdev->mac_ip_table_idx);
1153 else
1154 i40iw_del_macip_entry(iwdev, (u8)iwdev->mac_ip_table_idx);
1155 }
1156 return status;
1157}
1158
1159/**
1160 * i40iw_add_ipv6_addr - add ipv6 address to the hw arp table
1161 * @iwdev: iwarp device
1162 */
1163static void i40iw_add_ipv6_addr(struct i40iw_device *iwdev)
1164{
1165 struct net_device *ip_dev;
1166 struct inet6_dev *idev;
1167 struct inet6_ifaddr *ifp;
1168 __be32 local_ipaddr6[4];
1169
1170 rcu_read_lock();
1171 for_each_netdev_rcu(&init_net, ip_dev) {
1172 if ((((rdma_vlan_dev_vlan_id(ip_dev) < 0xFFFF) &&
1173 (rdma_vlan_dev_real_dev(ip_dev) == iwdev->netdev)) ||
1174 (ip_dev == iwdev->netdev)) && (ip_dev->flags & IFF_UP)) {
1175 idev = __in6_dev_get(ip_dev);
1176 if (!idev) {
1177 i40iw_pr_err("ipv6 inet device not found\n");
1178 break;
1179 }
1180 list_for_each_entry(ifp, &idev->addr_list, if_list) {
1181 i40iw_pr_info("IP=%pI6, vlan_id=%d, MAC=%pM\n", &ifp->addr,
1182 rdma_vlan_dev_vlan_id(ip_dev), ip_dev->dev_addr);
1183 i40iw_copy_ip_ntohl(local_ipaddr6,
1184 ifp->addr.in6_u.u6_addr32);
1185 i40iw_manage_arp_cache(iwdev,
1186 ip_dev->dev_addr,
1187 local_ipaddr6,
1188 false,
1189 I40IW_ARP_ADD);
1190 }
1191 }
1192 }
1193 rcu_read_unlock();
1194}
1195
1196/**
1197 * i40iw_add_ipv4_addr - add ipv4 address to the hw arp table
1198 * @iwdev: iwarp device
1199 */
1200static void i40iw_add_ipv4_addr(struct i40iw_device *iwdev)
1201{
1202 struct net_device *dev;
1203 struct in_device *idev;
1204 bool got_lock = true;
1205 u32 ip_addr;
1206
1207 if (!rtnl_trylock())
1208 got_lock = false;
1209
1210 for_each_netdev(&init_net, dev) {
1211 if ((((rdma_vlan_dev_vlan_id(dev) < 0xFFFF) &&
1212 (rdma_vlan_dev_real_dev(dev) == iwdev->netdev)) ||
1213 (dev == iwdev->netdev)) && (dev->flags & IFF_UP)) {
1214 idev = in_dev_get(dev);
1215 for_ifa(idev) {
1216 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_CM,
1217 "IP=%pI4, vlan_id=%d, MAC=%pM\n", &ifa->ifa_address,
1218 rdma_vlan_dev_vlan_id(dev), dev->dev_addr);
1219
1220 ip_addr = ntohl(ifa->ifa_address);
1221 i40iw_manage_arp_cache(iwdev,
1222 dev->dev_addr,
1223 &ip_addr,
1224 true,
1225 I40IW_ARP_ADD);
1226 }
1227 endfor_ifa(idev);
1228 in_dev_put(idev);
1229 }
1230 }
1231 if (got_lock)
1232 rtnl_unlock();
1233}
1234
1235/**
1236 * i40iw_add_mac_ip - add mac and ip addresses
1237 * @iwdev: iwarp device
1238 *
1239 * Create and add a mac ip address entry to the hw table and
1240 * ipv4/ipv6 addresses to the arp cache
1241 * Return 0 if successful, otherwise return error
1242 */
1243static enum i40iw_status_code i40iw_add_mac_ip(struct i40iw_device *iwdev)
1244{
1245 struct net_device *netdev = iwdev->netdev;
1246 enum i40iw_status_code status;
1247
1248 status = i40iw_alloc_set_mac_ipaddr(iwdev, (u8 *)netdev->dev_addr);
1249 if (status)
1250 return status;
1251 i40iw_add_ipv4_addr(iwdev);
1252 i40iw_add_ipv6_addr(iwdev);
1253 return 0;
1254}
1255
1256/**
1257 * i40iw_wait_pe_ready - Check if firmware is ready
1258 * @hw: provides access to registers
1259 */
1260static void i40iw_wait_pe_ready(struct i40iw_hw *hw)
1261{
1262 u32 statusfw;
1263 u32 statuscpu0;
1264 u32 statuscpu1;
1265 u32 statuscpu2;
1266 u32 retrycount = 0;
1267
1268 do {
1269 statusfw = i40iw_rd32(hw, I40E_GLPE_FWLDSTATUS);
1270 i40iw_pr_info("[%04d] fm load status[x%04X]\n", __LINE__, statusfw);
1271 statuscpu0 = i40iw_rd32(hw, I40E_GLPE_CPUSTATUS0);
1272 i40iw_pr_info("[%04d] CSR_CQP status[x%04X]\n", __LINE__, statuscpu0);
1273 statuscpu1 = i40iw_rd32(hw, I40E_GLPE_CPUSTATUS1);
1274 i40iw_pr_info("[%04d] I40E_GLPE_CPUSTATUS1 status[x%04X]\n",
1275 __LINE__, statuscpu1);
1276 statuscpu2 = i40iw_rd32(hw, I40E_GLPE_CPUSTATUS2);
1277 i40iw_pr_info("[%04d] I40E_GLPE_CPUSTATUS2 status[x%04X]\n",
1278 __LINE__, statuscpu2);
1279 if ((statuscpu0 == 0x80) && (statuscpu1 == 0x80) && (statuscpu2 == 0x80))
1280 break; /* SUCCESS */
1281 mdelay(1000);
1282 retrycount++;
1283 } while (retrycount < 14);
1284 i40iw_wr32(hw, 0xb4040, 0x4C104C5);
1285}
1286
1287/**
1288 * i40iw_initialize_dev - initialize device
1289 * @iwdev: iwarp device
1290 * @ldev: lan device information
1291 *
1292 * Allocate memory for the hmc objects and initialize iwdev
1293 * Return 0 if successful, otherwise clean up the resources
1294 * and return error
1295 */
1296static enum i40iw_status_code i40iw_initialize_dev(struct i40iw_device *iwdev,
1297 struct i40e_info *ldev)
1298{
1299 enum i40iw_status_code status;
1300 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1301 struct i40iw_device_init_info info;
1302 struct i40iw_dma_mem mem;
1303 u32 size;
1304
1305 memset(&info, 0, sizeof(info));
1306 size = sizeof(struct i40iw_hmc_pble_rsrc) + sizeof(struct i40iw_hmc_info) +
1307 (sizeof(struct i40iw_hmc_obj_info) * I40IW_HMC_IW_MAX);
1308 iwdev->hmc_info_mem = kzalloc(size, GFP_KERNEL);
1309 if (!iwdev->hmc_info_mem) {
1310 i40iw_pr_err("memory alloc fail\n");
1311 return I40IW_ERR_NO_MEMORY;
1312 }
1313 iwdev->pble_rsrc = (struct i40iw_hmc_pble_rsrc *)iwdev->hmc_info_mem;
1314 dev->hmc_info = &iwdev->hw.hmc;
1315 dev->hmc_info->hmc_obj = (struct i40iw_hmc_obj_info *)(iwdev->pble_rsrc + 1);
1316 status = i40iw_obj_aligned_mem(iwdev, &mem, I40IW_QUERY_FPM_BUF_SIZE,
1317 I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK);
1318 if (status)
1319 goto exit;
1320 info.fpm_query_buf_pa = mem.pa;
1321 info.fpm_query_buf = mem.va;
1322 status = i40iw_obj_aligned_mem(iwdev, &mem, I40IW_COMMIT_FPM_BUF_SIZE,
1323 I40IW_FPM_COMMIT_BUF_ALIGNMENT_MASK);
1324 if (status)
1325 goto exit;
1326 info.fpm_commit_buf_pa = mem.pa;
1327 info.fpm_commit_buf = mem.va;
1328 info.hmc_fn_id = ldev->fid;
1329 info.is_pf = (ldev->ftype) ? false : true;
1330 info.bar0 = ldev->hw_addr;
1331 info.hw = &iwdev->hw;
1332 info.debug_mask = debug;
1333 info.qs_handle = ldev->params.qos.prio_qos[0].qs_handle;
1334 info.exception_lan_queue = 1;
1335 info.vchnl_send = i40iw_virtchnl_send;
1336 status = i40iw_device_init(&iwdev->sc_dev, &info);
1337exit:
1338 if (status) {
1339 kfree(iwdev->hmc_info_mem);
1340 iwdev->hmc_info_mem = NULL;
1341 }
1342 return status;
1343}
1344
1345/**
1346 * i40iw_register_notifiers - register tcp ip notifiers
1347 */
1348static void i40iw_register_notifiers(void)
1349{
1350 if (!i40iw_notifiers_registered) {
1351 register_inetaddr_notifier(&i40iw_inetaddr_notifier);
1352 register_inet6addr_notifier(&i40iw_inetaddr6_notifier);
1353 register_netevent_notifier(&i40iw_net_notifier);
1354 }
1355 i40iw_notifiers_registered++;
1356}
1357
1358/**
1359 * i40iw_save_msix_info - copy msix vector information to iwarp device
1360 * @iwdev: iwarp device
1361 * @ldev: lan device information
1362 *
1363 * Allocate iwdev msix table and copy the ldev msix info to the table
1364 * Return 0 if successful, otherwise return error
1365 */
1366static enum i40iw_status_code i40iw_save_msix_info(struct i40iw_device *iwdev,
1367 struct i40e_info *ldev)
1368{
1369 struct i40e_qvlist_info *iw_qvlist;
1370 struct i40e_qv_info *iw_qvinfo;
1371 u32 ceq_idx;
1372 u32 i;
1373 u32 size;
1374
1375 iwdev->msix_count = ldev->msix_count;
1376
1377 size = sizeof(struct i40iw_msix_vector) * iwdev->msix_count;
1378 size += sizeof(struct i40e_qvlist_info);
1379 size += sizeof(struct i40e_qv_info) * iwdev->msix_count - 1;
1380 iwdev->iw_msixtbl = kzalloc(size, GFP_KERNEL);
1381
1382 if (!iwdev->iw_msixtbl)
1383 return I40IW_ERR_NO_MEMORY;
1384 iwdev->iw_qvlist = (struct i40e_qvlist_info *)(&iwdev->iw_msixtbl[iwdev->msix_count]);
1385 iw_qvlist = iwdev->iw_qvlist;
1386 iw_qvinfo = iw_qvlist->qv_info;
1387 iw_qvlist->num_vectors = iwdev->msix_count;
1388 if (iwdev->msix_count <= num_online_cpus())
1389 iwdev->msix_shared = true;
1390 for (i = 0, ceq_idx = 0; i < iwdev->msix_count; i++, iw_qvinfo++) {
1391 iwdev->iw_msixtbl[i].idx = ldev->msix_entries[i].entry;
1392 iwdev->iw_msixtbl[i].irq = ldev->msix_entries[i].vector;
1393 if (i == 0) {
1394 iw_qvinfo->aeq_idx = 0;
1395 if (iwdev->msix_shared)
1396 iw_qvinfo->ceq_idx = ceq_idx++;
1397 else
1398 iw_qvinfo->ceq_idx = I40E_QUEUE_INVALID_IDX;
1399 } else {
1400 iw_qvinfo->aeq_idx = I40E_QUEUE_INVALID_IDX;
1401 iw_qvinfo->ceq_idx = ceq_idx++;
1402 }
1403 iw_qvinfo->itr_idx = 3;
1404 iw_qvinfo->v_idx = iwdev->iw_msixtbl[i].idx;
1405 }
1406 return 0;
1407}
1408
1409/**
1410 * i40iw_deinit_device - clean up the device resources
1411 * @iwdev: iwarp device
1412 * @reset: true if called before reset
1413 * @del_hdl: true if delete hdl entry
1414 *
1415 * Destroy the ib device interface, remove the mac ip entry and ipv4/ipv6 addresses,
1416 * destroy the device queues and free the pble and the hmc objects
1417 */
1418static void i40iw_deinit_device(struct i40iw_device *iwdev, bool reset, bool del_hdl)
1419{
1420 struct i40e_info *ldev = iwdev->ldev;
1421
1422 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1423
1424 i40iw_pr_info("state = %d\n", iwdev->init_state);
1425
1426 switch (iwdev->init_state) {
1427 case RDMA_DEV_REGISTERED:
1428 iwdev->iw_status = 0;
1429 i40iw_port_ibevent(iwdev);
1430 i40iw_destroy_rdma_device(iwdev->iwibdev);
1431 /* fallthrough */
1432 case IP_ADDR_REGISTERED:
1433 if (!reset)
1434 i40iw_del_macip_entry(iwdev, (u8)iwdev->mac_ip_table_idx);
1435 /* fallthrough */
1436 case INET_NOTIFIER:
1437 if (i40iw_notifiers_registered > 0) {
1438 i40iw_notifiers_registered--;
1439 unregister_netevent_notifier(&i40iw_net_notifier);
1440 unregister_inetaddr_notifier(&i40iw_inetaddr_notifier);
1441 unregister_inet6addr_notifier(&i40iw_inetaddr6_notifier);
1442 }
1443 /* fallthrough */
1444 case CEQ_CREATED:
1445 i40iw_dele_ceqs(iwdev, reset);
1446 /* fallthrough */
1447 case AEQ_CREATED:
1448 i40iw_destroy_aeq(iwdev, reset);
1449 /* fallthrough */
1450 case IEQ_CREATED:
1451 i40iw_puda_dele_resources(dev, I40IW_PUDA_RSRC_TYPE_IEQ, reset);
1452 /* fallthrough */
1453 case ILQ_CREATED:
1454 i40iw_puda_dele_resources(dev, I40IW_PUDA_RSRC_TYPE_ILQ, reset);
1455 /* fallthrough */
1456 case CCQ_CREATED:
1457 i40iw_destroy_ccq(iwdev, reset);
1458 /* fallthrough */
1459 case PBLE_CHUNK_MEM:
1460 i40iw_destroy_pble_pool(dev, iwdev->pble_rsrc);
1461 /* fallthrough */
1462 case HMC_OBJS_CREATED:
1463 i40iw_del_hmc_objects(dev, dev->hmc_info, true, reset);
1464 /* fallthrough */
1465 case CQP_CREATED:
1466 i40iw_destroy_cqp(iwdev, !reset);
1467 /* fallthrough */
1468 case INITIAL_STATE:
1469 i40iw_cleanup_cm_core(&iwdev->cm_core);
1470 if (dev->is_pf)
1471 i40iw_hw_stats_del_timer(dev);
1472
1473 i40iw_del_init_mem(iwdev);
1474 break;
1475 case INVALID_STATE:
1476 /* fallthrough */
1477 default:
1478 i40iw_pr_err("bad init_state = %d\n", iwdev->init_state);
1479 break;
1480 }
1481
1482 if (del_hdl)
1483 i40iw_del_handler(i40iw_find_i40e_handler(ldev));
1484 kfree(iwdev->hdl);
1485}
1486
1487/**
1488 * i40iw_setup_init_state - set up the initial device struct
1489 * @hdl: handler for iwarp device - one per instance
1490 * @ldev: lan device information
1491 * @client: iwarp client information, provided during registration
1492 *
1493 * Initialize the iwarp device and its hdl information
1494 * using the ldev and client information
1495 * Return 0 if successful, otherwise return error
1496 */
1497static enum i40iw_status_code i40iw_setup_init_state(struct i40iw_handler *hdl,
1498 struct i40e_info *ldev,
1499 struct i40e_client *client)
1500{
1501 struct i40iw_device *iwdev = &hdl->device;
1502 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1503 enum i40iw_status_code status;
1504
1505 memcpy(&hdl->ldev, ldev, sizeof(*ldev));
1506 if (resource_profile == 1)
1507 resource_profile = 2;
1508
1509 iwdev->mpa_version = mpa_version;
1510 iwdev->resource_profile = (resource_profile < I40IW_HMC_PROFILE_EQUAL) ?
1511 (u8)resource_profile + I40IW_HMC_PROFILE_DEFAULT :
1512 I40IW_HMC_PROFILE_DEFAULT;
1513 iwdev->max_rdma_vfs =
1514 (iwdev->resource_profile != I40IW_HMC_PROFILE_DEFAULT) ? max_rdma_vfs : 0;
1515 iwdev->netdev = ldev->netdev;
1516 hdl->client = client;
1517 iwdev->mss = (!ldev->params.mtu) ? I40IW_DEFAULT_MSS : ldev->params.mtu - I40IW_MTU_TO_MSS;
1518 if (!ldev->ftype)
1519 iwdev->db_start = pci_resource_start(ldev->pcidev, 0) + I40IW_DB_ADDR_OFFSET;
1520 else
1521 iwdev->db_start = pci_resource_start(ldev->pcidev, 0) + I40IW_VF_DB_ADDR_OFFSET;
1522
1523 status = i40iw_save_msix_info(iwdev, ldev);
1524 if (status)
1525 goto exit;
1526 iwdev->hw.dev_context = (void *)ldev->pcidev;
1527 iwdev->hw.hw_addr = ldev->hw_addr;
1528 status = i40iw_allocate_dma_mem(&iwdev->hw,
1529 &iwdev->obj_mem, 8192, 4096);
1530 if (status)
1531 goto exit;
1532 iwdev->obj_next = iwdev->obj_mem;
1533 iwdev->push_mode = push_mode;
1534 init_waitqueue_head(&iwdev->vchnl_waitq);
1535 status = i40iw_initialize_dev(iwdev, ldev);
1536exit:
1537 if (status) {
1538 kfree(iwdev->iw_msixtbl);
1539 i40iw_free_dma_mem(dev->hw, &iwdev->obj_mem);
1540 iwdev->iw_msixtbl = NULL;
1541 }
1542 return status;
1543}
1544
1545/**
1546 * i40iw_open - client interface operation open for iwarp/uda device
1547 * @ldev: lan device information
1548 * @client: iwarp client information, provided during registration
1549 *
1550 * Called by the lan driver during the processing of client register
1551 * Create device resources, set up queues, pble and hmc objects and
1552 * register the device with the ib verbs interface
1553 * Return 0 if successful, otherwise return error
1554 */
1555static int i40iw_open(struct i40e_info *ldev, struct i40e_client *client)
1556{
1557 struct i40iw_device *iwdev;
1558 struct i40iw_sc_dev *dev;
1559 enum i40iw_status_code status;
1560 struct i40iw_handler *hdl;
1561
1562 hdl = kzalloc(sizeof(*hdl), GFP_KERNEL);
1563 if (!hdl)
1564 return -ENOMEM;
1565 iwdev = &hdl->device;
1566 iwdev->hdl = hdl;
1567 dev = &iwdev->sc_dev;
1568 i40iw_setup_cm_core(iwdev);
1569
1570 dev->back_dev = (void *)iwdev;
1571 iwdev->ldev = &hdl->ldev;
1572 iwdev->client = client;
1573 mutex_init(&iwdev->pbl_mutex);
1574 i40iw_add_handler(hdl);
1575
1576 do {
1577 status = i40iw_setup_init_state(hdl, ldev, client);
1578 if (status)
1579 break;
1580 iwdev->init_state = INITIAL_STATE;
1581 if (dev->is_pf)
1582 i40iw_wait_pe_ready(dev->hw);
1583 status = i40iw_create_cqp(iwdev);
1584 if (status)
1585 break;
1586 iwdev->init_state = CQP_CREATED;
1587 status = i40iw_hmc_setup(iwdev);
1588 if (status)
1589 break;
1590 status = i40iw_create_ccq(iwdev);
1591 if (status)
1592 break;
1593 iwdev->init_state = CCQ_CREATED;
1594 status = i40iw_initialize_ilq(iwdev);
1595 if (status)
1596 break;
1597 iwdev->init_state = ILQ_CREATED;
1598 status = i40iw_initialize_ieq(iwdev);
1599 if (status)
1600 break;
1601 iwdev->init_state = IEQ_CREATED;
1602 status = i40iw_setup_aeq(iwdev);
1603 if (status)
1604 break;
1605 iwdev->init_state = AEQ_CREATED;
1606 status = i40iw_setup_ceqs(iwdev, ldev);
1607 if (status)
1608 break;
1609 iwdev->init_state = CEQ_CREATED;
1610 status = i40iw_initialize_hw_resources(iwdev);
1611 if (status)
1612 break;
1613 dev->ccq_ops->ccq_arm(dev->ccq);
1614 status = i40iw_hmc_init_pble(&iwdev->sc_dev, iwdev->pble_rsrc);
1615 if (status)
1616 break;
1617 iwdev->virtchnl_wq = create_singlethread_workqueue("iwvch");
1618 i40iw_register_notifiers();
1619 iwdev->init_state = INET_NOTIFIER;
1620 status = i40iw_add_mac_ip(iwdev);
1621 if (status)
1622 break;
1623 iwdev->init_state = IP_ADDR_REGISTERED;
1624 if (i40iw_register_rdma_device(iwdev)) {
1625 i40iw_pr_err("register rdma device fail\n");
1626 break;
1627 };
1628
1629 iwdev->init_state = RDMA_DEV_REGISTERED;
1630 iwdev->iw_status = 1;
1631 i40iw_port_ibevent(iwdev);
1632 i40iw_pr_info("i40iw_open completed\n");
1633 return 0;
1634 } while (0);
1635
1636 i40iw_pr_err("status = %d last completion = %d\n", status, iwdev->init_state);
1637 i40iw_deinit_device(iwdev, false, false);
1638 return -ERESTART;
1639}
1640
1641/**
1642 * i40iw_l2param_change : handle qs handles for qos and mss change
1643 * @ldev: lan device information
1644 * @client: client for paramater change
1645 * @params: new parameters from L2
1646 */
1647static void i40iw_l2param_change(struct i40e_info *ldev,
1648 struct i40e_client *client,
1649 struct i40e_params *params)
1650{
1651 struct i40iw_handler *hdl;
1652 struct i40iw_device *iwdev;
1653
1654 hdl = i40iw_find_i40e_handler(ldev);
1655 if (!hdl)
1656 return;
1657
1658 iwdev = &hdl->device;
1659 if (params->mtu)
1660 iwdev->mss = params->mtu - I40IW_MTU_TO_MSS;
1661}
1662
1663/**
1664 * i40iw_close - client interface operation close for iwarp/uda device
1665 * @ldev: lan device information
1666 * @client: client to close
1667 *
1668 * Called by the lan driver during the processing of client unregister
1669 * Destroy and clean up the driver resources
1670 */
1671static void i40iw_close(struct i40e_info *ldev, struct i40e_client *client, bool reset)
1672{
1673 struct i40iw_device *iwdev;
1674 struct i40iw_handler *hdl;
1675
1676 hdl = i40iw_find_i40e_handler(ldev);
1677 if (!hdl)
1678 return;
1679
1680 iwdev = &hdl->device;
1681 destroy_workqueue(iwdev->virtchnl_wq);
1682 i40iw_deinit_device(iwdev, reset, true);
1683}
1684
1685/**
1686 * i40iw_vf_reset - process VF reset
1687 * @ldev: lan device information
1688 * @client: client interface instance
1689 * @vf_id: virtual function id
1690 *
1691 * Called when a VF is reset by the PF
1692 * Destroy and clean up the VF resources
1693 */
1694static void i40iw_vf_reset(struct i40e_info *ldev, struct i40e_client *client, u32 vf_id)
1695{
1696 struct i40iw_handler *hdl;
1697 struct i40iw_sc_dev *dev;
1698 struct i40iw_hmc_fcn_info hmc_fcn_info;
1699 struct i40iw_virt_mem vf_dev_mem;
1700 struct i40iw_vfdev *tmp_vfdev;
1701 unsigned int i;
1702 unsigned long flags;
1703
1704 hdl = i40iw_find_i40e_handler(ldev);
1705 if (!hdl)
1706 return;
1707
1708 dev = &hdl->device.sc_dev;
1709
1710 for (i = 0; i < I40IW_MAX_PE_ENABLED_VF_COUNT; i++) {
1711 if (!dev->vf_dev[i] || (dev->vf_dev[i]->vf_id != vf_id))
1712 continue;
1713
1714 /* free all resources allocated on behalf of vf */
1715 tmp_vfdev = dev->vf_dev[i];
1716 spin_lock_irqsave(&dev->dev_pestat.stats_lock, flags);
1717 dev->vf_dev[i] = NULL;
1718 spin_unlock_irqrestore(&dev->dev_pestat.stats_lock, flags);
1719 i40iw_del_hmc_objects(dev, &tmp_vfdev->hmc_info, false, false);
1720 /* remove vf hmc function */
1721 memset(&hmc_fcn_info, 0, sizeof(hmc_fcn_info));
1722 hmc_fcn_info.vf_id = vf_id;
1723 hmc_fcn_info.iw_vf_idx = tmp_vfdev->iw_vf_idx;
1724 hmc_fcn_info.free_fcn = true;
1725 i40iw_cqp_manage_hmc_fcn_cmd(dev, &hmc_fcn_info);
1726 /* free vf_dev */
1727 vf_dev_mem.va = tmp_vfdev;
1728 vf_dev_mem.size = sizeof(struct i40iw_vfdev) +
1729 sizeof(struct i40iw_hmc_obj_info) * I40IW_HMC_IW_MAX;
1730 i40iw_free_virt_mem(dev->hw, &vf_dev_mem);
1731 break;
1732 }
1733}
1734
1735/**
1736 * i40iw_vf_enable - enable a number of VFs
1737 * @ldev: lan device information
1738 * @client: client interface instance
1739 * @num_vfs: number of VFs for the PF
1740 *
1741 * Called when the number of VFs changes
1742 */
1743static void i40iw_vf_enable(struct i40e_info *ldev,
1744 struct i40e_client *client,
1745 u32 num_vfs)
1746{
1747 struct i40iw_handler *hdl;
1748
1749 hdl = i40iw_find_i40e_handler(ldev);
1750 if (!hdl)
1751 return;
1752
1753 if (num_vfs > I40IW_MAX_PE_ENABLED_VF_COUNT)
1754 hdl->device.max_enabled_vfs = I40IW_MAX_PE_ENABLED_VF_COUNT;
1755 else
1756 hdl->device.max_enabled_vfs = num_vfs;
1757}
1758
1759/**
1760 * i40iw_vf_capable - check if VF capable
1761 * @ldev: lan device information
1762 * @client: client interface instance
1763 * @vf_id: virtual function id
1764 *
1765 * Return 1 if a VF slot is available or if VF is already RDMA enabled
1766 * Return 0 otherwise
1767 */
1768static int i40iw_vf_capable(struct i40e_info *ldev,
1769 struct i40e_client *client,
1770 u32 vf_id)
1771{
1772 struct i40iw_handler *hdl;
1773 struct i40iw_sc_dev *dev;
1774 unsigned int i;
1775
1776 hdl = i40iw_find_i40e_handler(ldev);
1777 if (!hdl)
1778 return 0;
1779
1780 dev = &hdl->device.sc_dev;
1781
1782 for (i = 0; i < hdl->device.max_enabled_vfs; i++) {
1783 if (!dev->vf_dev[i] || (dev->vf_dev[i]->vf_id == vf_id))
1784 return 1;
1785 }
1786
1787 return 0;
1788}
1789
1790/**
1791 * i40iw_virtchnl_receive - receive a message through the virtual channel
1792 * @ldev: lan device information
1793 * @client: client interface instance
1794 * @vf_id: virtual function id associated with the message
1795 * @msg: message buffer pointer
1796 * @len: length of the message
1797 *
1798 * Invoke virtual channel receive operation for the given msg
1799 * Return 0 if successful, otherwise return error
1800 */
1801static int i40iw_virtchnl_receive(struct i40e_info *ldev,
1802 struct i40e_client *client,
1803 u32 vf_id,
1804 u8 *msg,
1805 u16 len)
1806{
1807 struct i40iw_handler *hdl;
1808 struct i40iw_sc_dev *dev;
1809 struct i40iw_device *iwdev;
1810 int ret_code = I40IW_NOT_SUPPORTED;
1811
1812 if (!len || !msg)
1813 return I40IW_ERR_PARAM;
1814
1815 hdl = i40iw_find_i40e_handler(ldev);
1816 if (!hdl)
1817 return I40IW_ERR_PARAM;
1818
1819 dev = &hdl->device.sc_dev;
1820 iwdev = dev->back_dev;
1821
1822 i40iw_debug(dev, I40IW_DEBUG_VIRT, "msg %p, message length %u\n", msg, len);
1823
1824 if (dev->vchnl_if.vchnl_recv) {
1825 ret_code = dev->vchnl_if.vchnl_recv(dev, vf_id, msg, len);
1826 if (!dev->is_pf) {
1827 atomic_dec(&iwdev->vchnl_msgs);
1828 wake_up(&iwdev->vchnl_waitq);
1829 }
1830 }
1831 return ret_code;
1832}
1833
1834/**
1835 * i40iw_virtchnl_send - send a message through the virtual channel
1836 * @dev: iwarp device
1837 * @vf_id: virtual function id associated with the message
1838 * @msg: virtual channel message buffer pointer
1839 * @len: length of the message
1840 *
1841 * Invoke virtual channel send operation for the given msg
1842 * Return 0 if successful, otherwise return error
1843 */
1844static enum i40iw_status_code i40iw_virtchnl_send(struct i40iw_sc_dev *dev,
1845 u32 vf_id,
1846 u8 *msg,
1847 u16 len)
1848{
1849 struct i40iw_device *iwdev;
1850 struct i40e_info *ldev;
1851 enum i40iw_status_code ret_code = I40IW_ERR_BAD_PTR;
1852
1853 if (!dev || !dev->back_dev)
1854 return ret_code;
1855
1856 iwdev = dev->back_dev;
1857 ldev = iwdev->ldev;
1858
1859 if (ldev && ldev->ops && ldev->ops->virtchnl_send)
1860 ret_code = ldev->ops->virtchnl_send(ldev, &i40iw_client, vf_id, msg, len);
1861
1862 return ret_code;
1863}
1864
1865/* client interface functions */
1866static struct i40e_client_ops i40e_ops = {
1867 .open = i40iw_open,
1868 .close = i40iw_close,
1869 .l2_param_change = i40iw_l2param_change,
1870 .virtchnl_receive = i40iw_virtchnl_receive,
1871 .vf_reset = i40iw_vf_reset,
1872 .vf_enable = i40iw_vf_enable,
1873 .vf_capable = i40iw_vf_capable
1874};
1875
1876/**
1877 * i40iw_init_module - driver initialization function
1878 *
1879 * First function to call when the driver is loaded
1880 * Register the driver as i40e client and port mapper client
1881 */
1882static int __init i40iw_init_module(void)
1883{
1884 int ret;
1885
1886 memset(&i40iw_client, 0, sizeof(i40iw_client));
1887 i40iw_client.version.major = CLIENT_IW_INTERFACE_VERSION_MAJOR;
1888 i40iw_client.version.minor = CLIENT_IW_INTERFACE_VERSION_MINOR;
1889 i40iw_client.version.build = CLIENT_IW_INTERFACE_VERSION_BUILD;
1890 i40iw_client.ops = &i40e_ops;
1891 memcpy(i40iw_client.name, i40iw_client_name, I40E_CLIENT_STR_LENGTH);
1892 i40iw_client.type = I40E_CLIENT_IWARP;
1893 spin_lock_init(&i40iw_handler_lock);
1894 ret = i40e_register_client(&i40iw_client);
1895 return ret;
1896}
1897
1898/**
1899 * i40iw_exit_module - driver exit clean up function
1900 *
1901 * The function is called just before the driver is unloaded
1902 * Unregister the driver as i40e client and port mapper client
1903 */
1904static void __exit i40iw_exit_module(void)
1905{
1906 i40e_unregister_client(&i40iw_client);
1907}
1908
1909module_init(i40iw_init_module);
1910module_exit(i40iw_exit_module);
diff --git a/drivers/infiniband/hw/i40iw/i40iw_osdep.h b/drivers/infiniband/hw/i40iw/i40iw_osdep.h
new file mode 100644
index 000000000000..7e20493510e8
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_osdep.h
@@ -0,0 +1,215 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_OSDEP_H
36#define I40IW_OSDEP_H
37
38#include <linux/kernel.h>
39#include <linux/string.h>
40#include <linux/bitops.h>
41#include <net/tcp.h>
42#include <crypto/hash.h>
43/* get readq/writeq support for 32 bit kernels, use the low-first version */
44#include <linux/io-64-nonatomic-lo-hi.h>
45
46#define STATS_TIMER_DELAY 1000
47
48static inline void set_64bit_val(u64 *wqe_words, u32 byte_index, u64 value)
49{
50 wqe_words[byte_index >> 3] = value;
51}
52
53/**
54 * set_32bit_val - set 32 value to hw wqe
55 * @wqe_words: wqe addr to write
56 * @byte_index: index in wqe
57 * @value: value to write
58 **/
59static inline void set_32bit_val(u32 *wqe_words, u32 byte_index, u32 value)
60{
61 wqe_words[byte_index >> 2] = value;
62}
63
64/**
65 * get_64bit_val - read 64 bit value from wqe
66 * @wqe_words: wqe addr
67 * @byte_index: index to read from
68 * @value: read value
69 **/
70static inline void get_64bit_val(u64 *wqe_words, u32 byte_index, u64 *value)
71{
72 *value = wqe_words[byte_index >> 3];
73}
74
75/**
76 * get_32bit_val - read 32 bit value from wqe
77 * @wqe_words: wqe addr
78 * @byte_index: index to reaad from
79 * @value: return 32 bit value
80 **/
81static inline void get_32bit_val(u32 *wqe_words, u32 byte_index, u32 *value)
82{
83 *value = wqe_words[byte_index >> 2];
84}
85
86struct i40iw_dma_mem {
87 void *va;
88 dma_addr_t pa;
89 u32 size;
90} __packed;
91
92struct i40iw_virt_mem {
93 void *va;
94 u32 size;
95} __packed;
96
97#define i40iw_debug(h, m, s, ...) \
98do { \
99 if (((m) & (h)->debug_mask)) \
100 pr_info("i40iw " s, ##__VA_ARGS__); \
101} while (0)
102
103#define i40iw_flush(a) readl((a)->hw_addr + I40E_GLGEN_STAT)
104
105#define I40E_GLHMC_VFSDCMD(_i) (0x000C8000 + ((_i) * 4)) \
106 /* _i=0...31 */
107#define I40E_GLHMC_VFSDCMD_MAX_INDEX 31
108#define I40E_GLHMC_VFSDCMD_PMSDIDX_SHIFT 0
109#define I40E_GLHMC_VFSDCMD_PMSDIDX_MASK (0xFFF \
110 << I40E_GLHMC_VFSDCMD_PMSDIDX_SHIFT)
111#define I40E_GLHMC_VFSDCMD_PF_SHIFT 16
112#define I40E_GLHMC_VFSDCMD_PF_MASK (0xF << I40E_GLHMC_VFSDCMD_PF_SHIFT)
113#define I40E_GLHMC_VFSDCMD_VF_SHIFT 20
114#define I40E_GLHMC_VFSDCMD_VF_MASK (0x1FF << I40E_GLHMC_VFSDCMD_VF_SHIFT)
115#define I40E_GLHMC_VFSDCMD_PMF_TYPE_SHIFT 29
116#define I40E_GLHMC_VFSDCMD_PMF_TYPE_MASK (0x3 \
117 << I40E_GLHMC_VFSDCMD_PMF_TYPE_SHIFT)
118#define I40E_GLHMC_VFSDCMD_PMSDWR_SHIFT 31
119#define I40E_GLHMC_VFSDCMD_PMSDWR_MASK (0x1 << I40E_GLHMC_VFSDCMD_PMSDWR_SHIFT)
120
121#define I40E_GLHMC_VFSDDATAHIGH(_i) (0x000C8200 + ((_i) * 4)) \
122 /* _i=0...31 */
123#define I40E_GLHMC_VFSDDATAHIGH_MAX_INDEX 31
124#define I40E_GLHMC_VFSDDATAHIGH_PMSDDATAHIGH_SHIFT 0
125#define I40E_GLHMC_VFSDDATAHIGH_PMSDDATAHIGH_MASK (0xFFFFFFFF \
126 << I40E_GLHMC_VFSDDATAHIGH_PMSDDATAHIGH_SHIFT)
127
128#define I40E_GLHMC_VFSDDATALOW(_i) (0x000C8100 + ((_i) * 4)) \
129 /* _i=0...31 */
130#define I40E_GLHMC_VFSDDATALOW_MAX_INDEX 31
131#define I40E_GLHMC_VFSDDATALOW_PMSDVALID_SHIFT 0
132#define I40E_GLHMC_VFSDDATALOW_PMSDVALID_MASK (0x1 \
133 << I40E_GLHMC_VFSDDATALOW_PMSDVALID_SHIFT)
134#define I40E_GLHMC_VFSDDATALOW_PMSDTYPE_SHIFT 1
135#define I40E_GLHMC_VFSDDATALOW_PMSDTYPE_MASK (0x1 \
136 << I40E_GLHMC_VFSDDATALOW_PMSDTYPE_SHIFT)
137#define I40E_GLHMC_VFSDDATALOW_PMSDBPCOUNT_SHIFT 2
138#define I40E_GLHMC_VFSDDATALOW_PMSDBPCOUNT_MASK (0x3FF \
139 << I40E_GLHMC_VFSDDATALOW_PMSDBPCOUNT_SHIFT)
140#define I40E_GLHMC_VFSDDATALOW_PMSDDATALOW_SHIFT 12
141#define I40E_GLHMC_VFSDDATALOW_PMSDDATALOW_MASK (0xFFFFF \
142 << I40E_GLHMC_VFSDDATALOW_PMSDDATALOW_SHIFT)
143
144#define I40E_GLPE_FWLDSTATUS 0x0000D200
145#define I40E_GLPE_FWLDSTATUS_LOAD_REQUESTED_SHIFT 0
146#define I40E_GLPE_FWLDSTATUS_LOAD_REQUESTED_MASK (0x1 \
147 << I40E_GLPE_FWLDSTATUS_LOAD_REQUESTED_SHIFT)
148#define I40E_GLPE_FWLDSTATUS_DONE_SHIFT 1
149#define I40E_GLPE_FWLDSTATUS_DONE_MASK (0x1 << I40E_GLPE_FWLDSTATUS_DONE_SHIFT)
150#define I40E_GLPE_FWLDSTATUS_CQP_FAIL_SHIFT 2
151#define I40E_GLPE_FWLDSTATUS_CQP_FAIL_MASK (0x1 \
152 << I40E_GLPE_FWLDSTATUS_CQP_FAIL_SHIFT)
153#define I40E_GLPE_FWLDSTATUS_TEP_FAIL_SHIFT 3
154#define I40E_GLPE_FWLDSTATUS_TEP_FAIL_MASK (0x1 \
155 << I40E_GLPE_FWLDSTATUS_TEP_FAIL_SHIFT)
156#define I40E_GLPE_FWLDSTATUS_OOP_FAIL_SHIFT 4
157#define I40E_GLPE_FWLDSTATUS_OOP_FAIL_MASK (0x1 \
158 << I40E_GLPE_FWLDSTATUS_OOP_FAIL_SHIFT)
159
160struct i40iw_sc_dev;
161struct i40iw_sc_qp;
162struct i40iw_puda_buf;
163struct i40iw_puda_completion_info;
164struct i40iw_update_sds_info;
165struct i40iw_hmc_fcn_info;
166struct i40iw_virtchnl_work_info;
167struct i40iw_manage_vf_pble_info;
168struct i40iw_device;
169struct i40iw_hmc_info;
170struct i40iw_hw;
171
172u8 __iomem *i40iw_get_hw_addr(void *dev);
173void i40iw_ieq_mpa_crc_ae(struct i40iw_sc_dev *dev, struct i40iw_sc_qp *qp);
174enum i40iw_status_code i40iw_vf_wait_vchnl_resp(struct i40iw_sc_dev *dev);
175enum i40iw_status_code i40iw_ieq_check_mpacrc(struct shash_desc *desc, void *addr,
176 u32 length, u32 value);
177struct i40iw_sc_qp *i40iw_ieq_get_qp(struct i40iw_sc_dev *dev, struct i40iw_puda_buf *buf);
178void i40iw_ieq_update_tcpip_info(struct i40iw_puda_buf *buf, u16 length, u32 seqnum);
179void i40iw_free_hash_desc(struct shash_desc *);
180enum i40iw_status_code i40iw_init_hash_desc(struct shash_desc **);
181enum i40iw_status_code i40iw_puda_get_tcpip_info(struct i40iw_puda_completion_info *info,
182 struct i40iw_puda_buf *buf);
183enum i40iw_status_code i40iw_cqp_sds_cmd(struct i40iw_sc_dev *dev,
184 struct i40iw_update_sds_info *info);
185enum i40iw_status_code i40iw_cqp_manage_hmc_fcn_cmd(struct i40iw_sc_dev *dev,
186 struct i40iw_hmc_fcn_info *hmcfcninfo);
187enum i40iw_status_code i40iw_cqp_query_fpm_values_cmd(struct i40iw_sc_dev *dev,
188 struct i40iw_dma_mem *values_mem,
189 u8 hmc_fn_id);
190enum i40iw_status_code i40iw_cqp_commit_fpm_values_cmd(struct i40iw_sc_dev *dev,
191 struct i40iw_dma_mem *values_mem,
192 u8 hmc_fn_id);
193enum i40iw_status_code i40iw_alloc_query_fpm_buf(struct i40iw_sc_dev *dev,
194 struct i40iw_dma_mem *mem);
195enum i40iw_status_code i40iw_cqp_manage_vf_pble_bp(struct i40iw_sc_dev *dev,
196 struct i40iw_manage_vf_pble_info *info);
197void i40iw_cqp_spawn_worker(struct i40iw_sc_dev *dev,
198 struct i40iw_virtchnl_work_info *work_info, u32 iw_vf_idx);
199void *i40iw_remove_head(struct list_head *list);
200
201void i40iw_term_modify_qp(struct i40iw_sc_qp *qp, u8 next_state, u8 term, u8 term_len);
202void i40iw_terminate_done(struct i40iw_sc_qp *qp, int timeout_occurred);
203void i40iw_terminate_start_timer(struct i40iw_sc_qp *qp);
204void i40iw_terminate_del_timer(struct i40iw_sc_qp *qp);
205
206enum i40iw_status_code i40iw_hw_manage_vf_pble_bp(struct i40iw_device *iwdev,
207 struct i40iw_manage_vf_pble_info *info,
208 bool wait);
209struct i40iw_dev_pestat;
210void i40iw_hw_stats_start_timer(struct i40iw_sc_dev *);
211void i40iw_hw_stats_del_timer(struct i40iw_sc_dev *);
212#define i40iw_mmiowb() mmiowb()
213void i40iw_wr32(struct i40iw_hw *hw, u32 reg, u32 value);
214u32 i40iw_rd32(struct i40iw_hw *hw, u32 reg);
215#endif /* _I40IW_OSDEP_H_ */
diff --git a/drivers/infiniband/hw/i40iw/i40iw_p.h b/drivers/infiniband/hw/i40iw/i40iw_p.h
new file mode 100644
index 000000000000..a0b8ca10d67e
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_p.h
@@ -0,0 +1,106 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_P_H
36#define I40IW_P_H
37
38#define PAUSE_TIMER_VALUE 0xFFFF
39#define REFRESH_THRESHOLD 0x7FFF
40#define HIGH_THRESHOLD 0x800
41#define LOW_THRESHOLD 0x200
42#define ALL_TC2PFC 0xFF
43
44void i40iw_debug_buf(struct i40iw_sc_dev *dev, enum i40iw_debug_flag mask,
45 char *desc, u64 *buf, u32 size);
46/* init operations */
47enum i40iw_status_code i40iw_device_init(struct i40iw_sc_dev *dev,
48 struct i40iw_device_init_info *info);
49
50enum i40iw_status_code i40iw_device_init_pestat(struct i40iw_dev_pestat *);
51
52void i40iw_sc_cqp_post_sq(struct i40iw_sc_cqp *cqp);
53
54u64 *i40iw_sc_cqp_get_next_send_wqe(struct i40iw_sc_cqp *cqp, u64 scratch);
55
56enum i40iw_status_code i40iw_sc_mr_fast_register(struct i40iw_sc_qp *qp,
57 struct i40iw_fast_reg_stag_info *info,
58 bool post_sq);
59
60/* HMC/FPM functions */
61enum i40iw_status_code i40iw_sc_init_iw_hmc(struct i40iw_sc_dev *dev,
62 u8 hmc_fn_id);
63
64enum i40iw_status_code i40iw_pf_init_vfhmc(struct i40iw_sc_dev *dev, u8 vf_hmc_fn_id,
65 u32 *vf_cnt_array);
66
67/* cqp misc functions */
68
69void i40iw_terminate_send_fin(struct i40iw_sc_qp *qp);
70
71void i40iw_terminate_connection(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info);
72
73void i40iw_terminate_received(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info);
74
75enum i40iw_status_code i40iw_sc_suspend_qp(struct i40iw_sc_cqp *cqp,
76 struct i40iw_sc_qp *qp, u64 scratch);
77
78enum i40iw_status_code i40iw_sc_resume_qp(struct i40iw_sc_cqp *cqp,
79 struct i40iw_sc_qp *qp, u64 scratch);
80
81enum i40iw_status_code i40iw_sc_static_hmc_pages_allocated(struct i40iw_sc_cqp *cqp,
82 u64 scratch, u8 hmc_fn_id,
83 bool post_sq,
84 bool poll_registers);
85
86enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_count);
87
88void free_sd_mem(struct i40iw_sc_dev *dev);
89
90enum i40iw_status_code i40iw_process_cqp_cmd(struct i40iw_sc_dev *dev,
91 struct cqp_commands_info *pcmdinfo);
92
93enum i40iw_status_code i40iw_process_bh(struct i40iw_sc_dev *dev);
94
95/* prototype for functions used for dynamic memory allocation */
96enum i40iw_status_code i40iw_allocate_dma_mem(struct i40iw_hw *hw,
97 struct i40iw_dma_mem *mem, u64 size,
98 u32 alignment);
99void i40iw_free_dma_mem(struct i40iw_hw *hw, struct i40iw_dma_mem *mem);
100enum i40iw_status_code i40iw_allocate_virt_mem(struct i40iw_hw *hw,
101 struct i40iw_virt_mem *mem, u32 size);
102enum i40iw_status_code i40iw_free_virt_mem(struct i40iw_hw *hw,
103 struct i40iw_virt_mem *mem);
104u8 i40iw_get_encoded_wqe_size(u32 wqsize, bool cqpsq);
105
106#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_pble.c b/drivers/infiniband/hw/i40iw/i40iw_pble.c
new file mode 100644
index 000000000000..ded853d2fad8
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_pble.c
@@ -0,0 +1,618 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_status.h"
36#include "i40iw_osdep.h"
37#include "i40iw_register.h"
38#include "i40iw_hmc.h"
39
40#include "i40iw_d.h"
41#include "i40iw_type.h"
42#include "i40iw_p.h"
43
44#include <linux/pci.h>
45#include <linux/genalloc.h>
46#include <linux/vmalloc.h>
47#include "i40iw_pble.h"
48#include "i40iw.h"
49
50struct i40iw_device;
51static enum i40iw_status_code add_pble_pool(struct i40iw_sc_dev *dev,
52 struct i40iw_hmc_pble_rsrc *pble_rsrc);
53static void i40iw_free_vmalloc_mem(struct i40iw_hw *hw, struct i40iw_chunk *chunk);
54
55/**
56 * i40iw_destroy_pble_pool - destroy pool during module unload
57 * @pble_rsrc: pble resources
58 */
59void i40iw_destroy_pble_pool(struct i40iw_sc_dev *dev, struct i40iw_hmc_pble_rsrc *pble_rsrc)
60{
61 struct list_head *clist;
62 struct list_head *tlist;
63 struct i40iw_chunk *chunk;
64 struct i40iw_pble_pool *pinfo = &pble_rsrc->pinfo;
65
66 if (pinfo->pool) {
67 list_for_each_safe(clist, tlist, &pinfo->clist) {
68 chunk = list_entry(clist, struct i40iw_chunk, list);
69 if (chunk->type == I40IW_VMALLOC)
70 i40iw_free_vmalloc_mem(dev->hw, chunk);
71 kfree(chunk);
72 }
73 gen_pool_destroy(pinfo->pool);
74 }
75}
76
77/**
78 * i40iw_hmc_init_pble - Initialize pble resources during module load
79 * @dev: i40iw_sc_dev struct
80 * @pble_rsrc: pble resources
81 */
82enum i40iw_status_code i40iw_hmc_init_pble(struct i40iw_sc_dev *dev,
83 struct i40iw_hmc_pble_rsrc *pble_rsrc)
84{
85 struct i40iw_hmc_info *hmc_info;
86 u32 fpm_idx = 0;
87
88 hmc_info = dev->hmc_info;
89 pble_rsrc->fpm_base_addr = hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].base;
90 /* Now start the pble' on 4k boundary */
91 if (pble_rsrc->fpm_base_addr & 0xfff)
92 fpm_idx = (PAGE_SIZE - (pble_rsrc->fpm_base_addr & 0xfff)) >> 3;
93
94 pble_rsrc->unallocated_pble =
95 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt - fpm_idx;
96 pble_rsrc->next_fpm_addr = pble_rsrc->fpm_base_addr + (fpm_idx << 3);
97
98 pble_rsrc->pinfo.pool_shift = POOL_SHIFT;
99 pble_rsrc->pinfo.pool = gen_pool_create(pble_rsrc->pinfo.pool_shift, -1);
100 INIT_LIST_HEAD(&pble_rsrc->pinfo.clist);
101 if (!pble_rsrc->pinfo.pool)
102 goto error;
103
104 if (add_pble_pool(dev, pble_rsrc))
105 goto error;
106
107 return 0;
108
109 error:i40iw_destroy_pble_pool(dev, pble_rsrc);
110 return I40IW_ERR_NO_MEMORY;
111}
112
113/**
114 * get_sd_pd_idx - Returns sd index, pd index and rel_pd_idx from fpm address
115 * @ pble_rsrc: structure containing fpm address
116 * @ idx: where to return indexes
117 */
118static inline void get_sd_pd_idx(struct i40iw_hmc_pble_rsrc *pble_rsrc,
119 struct sd_pd_idx *idx)
120{
121 idx->sd_idx = (u32)(pble_rsrc->next_fpm_addr) / I40IW_HMC_DIRECT_BP_SIZE;
122 idx->pd_idx = (u32)(pble_rsrc->next_fpm_addr) / I40IW_HMC_PAGED_BP_SIZE;
123 idx->rel_pd_idx = (idx->pd_idx % I40IW_HMC_PD_CNT_IN_SD);
124}
125
126/**
127 * add_sd_direct - add sd direct for pble
128 * @dev: hardware control device structure
129 * @pble_rsrc: pble resource ptr
130 * @info: page info for sd
131 */
132static enum i40iw_status_code add_sd_direct(struct i40iw_sc_dev *dev,
133 struct i40iw_hmc_pble_rsrc *pble_rsrc,
134 struct i40iw_add_page_info *info)
135{
136 enum i40iw_status_code ret_code = 0;
137 struct sd_pd_idx *idx = &info->idx;
138 struct i40iw_chunk *chunk = info->chunk;
139 struct i40iw_hmc_info *hmc_info = info->hmc_info;
140 struct i40iw_hmc_sd_entry *sd_entry = info->sd_entry;
141 u32 offset = 0;
142
143 if (!sd_entry->valid) {
144 if (dev->is_pf) {
145 ret_code = i40iw_add_sd_table_entry(dev->hw, hmc_info,
146 info->idx.sd_idx,
147 I40IW_SD_TYPE_DIRECT,
148 I40IW_HMC_DIRECT_BP_SIZE);
149 if (ret_code)
150 return ret_code;
151 chunk->type = I40IW_DMA_COHERENT;
152 }
153 }
154 offset = idx->rel_pd_idx << I40IW_HMC_PAGED_BP_SHIFT;
155 chunk->size = info->pages << I40IW_HMC_PAGED_BP_SHIFT;
156 chunk->vaddr = ((u8 *)sd_entry->u.bp.addr.va + offset);
157 chunk->fpm_addr = pble_rsrc->next_fpm_addr;
158 i40iw_debug(dev, I40IW_DEBUG_PBLE, "chunk_size[%d] = 0x%x vaddr=%p fpm_addr = %llx\n",
159 chunk->size, chunk->size, chunk->vaddr, chunk->fpm_addr);
160 return 0;
161}
162
163/**
164 * i40iw_free_vmalloc_mem - free vmalloc during close
165 * @hw: hw struct
166 * @chunk: chunk information for vmalloc
167 */
168static void i40iw_free_vmalloc_mem(struct i40iw_hw *hw, struct i40iw_chunk *chunk)
169{
170 struct pci_dev *pcidev = (struct pci_dev *)hw->dev_context;
171 int i;
172
173 if (!chunk->pg_cnt)
174 goto done;
175 for (i = 0; i < chunk->pg_cnt; i++)
176 dma_unmap_page(&pcidev->dev, chunk->dmaaddrs[i], PAGE_SIZE, DMA_BIDIRECTIONAL);
177
178 done:
179 kfree(chunk->dmaaddrs);
180 chunk->dmaaddrs = NULL;
181 vfree(chunk->vaddr);
182 chunk->vaddr = NULL;
183 chunk->type = 0;
184}
185
186/**
187 * i40iw_get_vmalloc_mem - get 2M page for sd
188 * @hw: hardware address
189 * @chunk: chunk to adf
190 * @pg_cnt: #of 4 K pages
191 */
192static enum i40iw_status_code i40iw_get_vmalloc_mem(struct i40iw_hw *hw,
193 struct i40iw_chunk *chunk,
194 int pg_cnt)
195{
196 struct pci_dev *pcidev = (struct pci_dev *)hw->dev_context;
197 struct page *page;
198 u8 *addr;
199 u32 size;
200 int i;
201
202 chunk->dmaaddrs = kzalloc(pg_cnt << 3, GFP_KERNEL);
203 if (!chunk->dmaaddrs)
204 return I40IW_ERR_NO_MEMORY;
205 size = PAGE_SIZE * pg_cnt;
206 chunk->vaddr = vmalloc(size);
207 if (!chunk->vaddr) {
208 kfree(chunk->dmaaddrs);
209 chunk->dmaaddrs = NULL;
210 return I40IW_ERR_NO_MEMORY;
211 }
212 chunk->size = size;
213 addr = (u8 *)chunk->vaddr;
214 for (i = 0; i < pg_cnt; i++) {
215 page = vmalloc_to_page((void *)addr);
216 if (!page)
217 break;
218 chunk->dmaaddrs[i] = dma_map_page(&pcidev->dev, page, 0,
219 PAGE_SIZE, DMA_BIDIRECTIONAL);
220 if (dma_mapping_error(&pcidev->dev, chunk->dmaaddrs[i]))
221 break;
222 addr += PAGE_SIZE;
223 }
224
225 chunk->pg_cnt = i;
226 chunk->type = I40IW_VMALLOC;
227 if (i == pg_cnt)
228 return 0;
229
230 i40iw_free_vmalloc_mem(hw, chunk);
231 return I40IW_ERR_NO_MEMORY;
232}
233
234/**
235 * fpm_to_idx - given fpm address, get pble index
236 * @pble_rsrc: pble resource management
237 * @addr: fpm address for index
238 */
239static inline u32 fpm_to_idx(struct i40iw_hmc_pble_rsrc *pble_rsrc, u64 addr)
240{
241 return (addr - (pble_rsrc->fpm_base_addr)) >> 3;
242}
243
244/**
245 * add_bp_pages - add backing pages for sd
246 * @dev: hardware control device structure
247 * @pble_rsrc: pble resource management
248 * @info: page info for sd
249 */
250static enum i40iw_status_code add_bp_pages(struct i40iw_sc_dev *dev,
251 struct i40iw_hmc_pble_rsrc *pble_rsrc,
252 struct i40iw_add_page_info *info)
253{
254 u8 *addr;
255 struct i40iw_dma_mem mem;
256 struct i40iw_hmc_pd_entry *pd_entry;
257 struct i40iw_hmc_sd_entry *sd_entry = info->sd_entry;
258 struct i40iw_hmc_info *hmc_info = info->hmc_info;
259 struct i40iw_chunk *chunk = info->chunk;
260 struct i40iw_manage_vf_pble_info vf_pble_info;
261 enum i40iw_status_code status = 0;
262 u32 rel_pd_idx = info->idx.rel_pd_idx;
263 u32 pd_idx = info->idx.pd_idx;
264 u32 i;
265
266 status = i40iw_get_vmalloc_mem(dev->hw, chunk, info->pages);
267 if (status)
268 return I40IW_ERR_NO_MEMORY;
269 status = i40iw_add_sd_table_entry(dev->hw, hmc_info,
270 info->idx.sd_idx, I40IW_SD_TYPE_PAGED,
271 I40IW_HMC_DIRECT_BP_SIZE);
272 if (status) {
273 i40iw_free_vmalloc_mem(dev->hw, chunk);
274 return status;
275 }
276 if (!dev->is_pf) {
277 status = i40iw_vchnl_vf_add_hmc_objs(dev, I40IW_HMC_IW_PBLE,
278 fpm_to_idx(pble_rsrc,
279 pble_rsrc->next_fpm_addr),
280 (info->pages << PBLE_512_SHIFT));
281 if (status) {
282 i40iw_pr_err("allocate PBLEs in the PF. Error %i\n", status);
283 i40iw_free_vmalloc_mem(dev->hw, chunk);
284 return status;
285 }
286 }
287 addr = chunk->vaddr;
288 for (i = 0; i < info->pages; i++) {
289 mem.pa = chunk->dmaaddrs[i];
290 mem.size = PAGE_SIZE;
291 mem.va = (void *)(addr);
292 pd_entry = &sd_entry->u.pd_table.pd_entry[rel_pd_idx++];
293 if (!pd_entry->valid) {
294 status = i40iw_add_pd_table_entry(dev->hw, hmc_info, pd_idx++, &mem);
295 if (status)
296 goto error;
297 addr += PAGE_SIZE;
298 } else {
299 i40iw_pr_err("pd entry is valid expecting to be invalid\n");
300 }
301 }
302 if (!dev->is_pf) {
303 vf_pble_info.first_pd_index = info->idx.rel_pd_idx;
304 vf_pble_info.inv_pd_ent = false;
305 vf_pble_info.pd_entry_cnt = PBLE_PER_PAGE;
306 vf_pble_info.pd_pl_pba = sd_entry->u.pd_table.pd_page_addr.pa;
307 vf_pble_info.sd_index = info->idx.sd_idx;
308 status = i40iw_hw_manage_vf_pble_bp(dev->back_dev,
309 &vf_pble_info, true);
310 if (status) {
311 i40iw_pr_err("CQP manage VF PBLE BP failed. %i\n", status);
312 goto error;
313 }
314 }
315 chunk->fpm_addr = pble_rsrc->next_fpm_addr;
316 return 0;
317error:
318 i40iw_free_vmalloc_mem(dev->hw, chunk);
319 return status;
320}
321
322/**
323 * add_pble_pool - add a sd entry for pble resoure
324 * @dev: hardware control device structure
325 * @pble_rsrc: pble resource management
326 */
327static enum i40iw_status_code add_pble_pool(struct i40iw_sc_dev *dev,
328 struct i40iw_hmc_pble_rsrc *pble_rsrc)
329{
330 struct i40iw_hmc_sd_entry *sd_entry;
331 struct i40iw_hmc_info *hmc_info;
332 struct i40iw_chunk *chunk;
333 struct i40iw_add_page_info info;
334 struct sd_pd_idx *idx = &info.idx;
335 enum i40iw_status_code ret_code = 0;
336 enum i40iw_sd_entry_type sd_entry_type;
337 u64 sd_reg_val = 0;
338 u32 pages;
339
340 if (pble_rsrc->unallocated_pble < PBLE_PER_PAGE)
341 return I40IW_ERR_NO_MEMORY;
342 if (pble_rsrc->next_fpm_addr & 0xfff) {
343 i40iw_pr_err("next fpm_addr %llx\n", pble_rsrc->next_fpm_addr);
344 return I40IW_ERR_INVALID_PAGE_DESC_INDEX;
345 }
346 chunk = kzalloc(sizeof(*chunk), GFP_KERNEL);
347 if (!chunk)
348 return I40IW_ERR_NO_MEMORY;
349 hmc_info = dev->hmc_info;
350 chunk->fpm_addr = pble_rsrc->next_fpm_addr;
351 get_sd_pd_idx(pble_rsrc, idx);
352 sd_entry = &hmc_info->sd_table.sd_entry[idx->sd_idx];
353 pages = (idx->rel_pd_idx) ? (I40IW_HMC_PD_CNT_IN_SD -
354 idx->rel_pd_idx) : I40IW_HMC_PD_CNT_IN_SD;
355 pages = min(pages, pble_rsrc->unallocated_pble >> PBLE_512_SHIFT);
356 if (!pages) {
357 ret_code = I40IW_ERR_NO_PBLCHUNKS_AVAILABLE;
358 goto error;
359 }
360 info.chunk = chunk;
361 info.hmc_info = hmc_info;
362 info.pages = pages;
363 info.sd_entry = sd_entry;
364 if (!sd_entry->valid) {
365 sd_entry_type = (!idx->rel_pd_idx &&
366 (pages == I40IW_HMC_PD_CNT_IN_SD) &&
367 dev->is_pf) ? I40IW_SD_TYPE_DIRECT : I40IW_SD_TYPE_PAGED;
368 } else {
369 sd_entry_type = sd_entry->entry_type;
370 }
371 i40iw_debug(dev, I40IW_DEBUG_PBLE,
372 "pages = %d, unallocated_pble[%u] current_fpm_addr = %llx\n",
373 pages, pble_rsrc->unallocated_pble, pble_rsrc->next_fpm_addr);
374 i40iw_debug(dev, I40IW_DEBUG_PBLE, "sd_entry_type = %d sd_entry valid = %d\n",
375 sd_entry_type, sd_entry->valid);
376
377 if (sd_entry_type == I40IW_SD_TYPE_DIRECT)
378 ret_code = add_sd_direct(dev, pble_rsrc, &info);
379 if (ret_code)
380 sd_entry_type = I40IW_SD_TYPE_PAGED;
381 else
382 pble_rsrc->stats_direct_sds++;
383
384 if (sd_entry_type == I40IW_SD_TYPE_PAGED) {
385 ret_code = add_bp_pages(dev, pble_rsrc, &info);
386 if (ret_code)
387 goto error;
388 else
389 pble_rsrc->stats_paged_sds++;
390 }
391
392 if (gen_pool_add_virt(pble_rsrc->pinfo.pool, (unsigned long)chunk->vaddr,
393 (phys_addr_t)chunk->fpm_addr, chunk->size, -1)) {
394 i40iw_pr_err("could not allocate memory by gen_pool_addr_virt()\n");
395 ret_code = I40IW_ERR_NO_MEMORY;
396 goto error;
397 }
398 pble_rsrc->next_fpm_addr += chunk->size;
399 i40iw_debug(dev, I40IW_DEBUG_PBLE, "next_fpm_addr = %llx chunk_size[%u] = 0x%x\n",
400 pble_rsrc->next_fpm_addr, chunk->size, chunk->size);
401 pble_rsrc->unallocated_pble -= (chunk->size >> 3);
402 list_add(&chunk->list, &pble_rsrc->pinfo.clist);
403 sd_reg_val = (sd_entry_type == I40IW_SD_TYPE_PAGED) ?
404 sd_entry->u.pd_table.pd_page_addr.pa : sd_entry->u.bp.addr.pa;
405 if (sd_entry->valid)
406 return 0;
407 if (dev->is_pf)
408 ret_code = i40iw_hmc_sd_one(dev, hmc_info->hmc_fn_id,
409 sd_reg_val, idx->sd_idx,
410 sd_entry->entry_type, true);
411 if (ret_code) {
412 i40iw_pr_err("cqp cmd failed for sd (pbles)\n");
413 goto error;
414 }
415
416 sd_entry->valid = true;
417 return 0;
418 error:
419 kfree(chunk);
420 return ret_code;
421}
422
423/**
424 * free_lvl2 - fee level 2 pble
425 * @pble_rsrc: pble resource management
426 * @palloc: level 2 pble allocation
427 */
428static void free_lvl2(struct i40iw_hmc_pble_rsrc *pble_rsrc,
429 struct i40iw_pble_alloc *palloc)
430{
431 u32 i;
432 struct gen_pool *pool;
433 struct i40iw_pble_level2 *lvl2 = &palloc->level2;
434 struct i40iw_pble_info *root = &lvl2->root;
435 struct i40iw_pble_info *leaf = lvl2->leaf;
436
437 pool = pble_rsrc->pinfo.pool;
438
439 for (i = 0; i < lvl2->leaf_cnt; i++, leaf++) {
440 if (leaf->addr)
441 gen_pool_free(pool, leaf->addr, (leaf->cnt << 3));
442 else
443 break;
444 }
445
446 if (root->addr)
447 gen_pool_free(pool, root->addr, (root->cnt << 3));
448
449 kfree(lvl2->leaf);
450 lvl2->leaf = NULL;
451}
452
453/**
454 * get_lvl2_pble - get level 2 pble resource
455 * @pble_rsrc: pble resource management
456 * @palloc: level 2 pble allocation
457 * @pool: pool pointer
458 */
459static enum i40iw_status_code get_lvl2_pble(struct i40iw_hmc_pble_rsrc *pble_rsrc,
460 struct i40iw_pble_alloc *palloc,
461 struct gen_pool *pool)
462{
463 u32 lf4k, lflast, total, i;
464 u32 pblcnt = PBLE_PER_PAGE;
465 u64 *addr;
466 struct i40iw_pble_level2 *lvl2 = &palloc->level2;
467 struct i40iw_pble_info *root = &lvl2->root;
468 struct i40iw_pble_info *leaf;
469
470 /* number of full 512 (4K) leafs) */
471 lf4k = palloc->total_cnt >> 9;
472 lflast = palloc->total_cnt % PBLE_PER_PAGE;
473 total = (lflast == 0) ? lf4k : lf4k + 1;
474 lvl2->leaf_cnt = total;
475
476 leaf = kzalloc((sizeof(*leaf) * total), GFP_ATOMIC);
477 if (!leaf)
478 return I40IW_ERR_NO_MEMORY;
479 lvl2->leaf = leaf;
480 /* allocate pbles for the root */
481 root->addr = gen_pool_alloc(pool, (total << 3));
482 if (!root->addr) {
483 kfree(lvl2->leaf);
484 lvl2->leaf = NULL;
485 return I40IW_ERR_NO_MEMORY;
486 }
487 root->idx = fpm_to_idx(pble_rsrc,
488 (u64)gen_pool_virt_to_phys(pool, root->addr));
489 root->cnt = total;
490 addr = (u64 *)root->addr;
491 for (i = 0; i < total; i++, leaf++) {
492 pblcnt = (lflast && ((i + 1) == total)) ? lflast : PBLE_PER_PAGE;
493 leaf->addr = gen_pool_alloc(pool, (pblcnt << 3));
494 if (!leaf->addr)
495 goto error;
496 leaf->idx = fpm_to_idx(pble_rsrc, (u64)gen_pool_virt_to_phys(pool, leaf->addr));
497
498 leaf->cnt = pblcnt;
499 *addr = (u64)leaf->idx;
500 addr++;
501 }
502 palloc->level = I40IW_LEVEL_2;
503 pble_rsrc->stats_lvl2++;
504 return 0;
505 error:
506 free_lvl2(pble_rsrc, palloc);
507 return I40IW_ERR_NO_MEMORY;
508}
509
510/**
511 * get_lvl1_pble - get level 1 pble resource
512 * @dev: hardware control device structure
513 * @pble_rsrc: pble resource management
514 * @palloc: level 1 pble allocation
515 */
516static enum i40iw_status_code get_lvl1_pble(struct i40iw_sc_dev *dev,
517 struct i40iw_hmc_pble_rsrc *pble_rsrc,
518 struct i40iw_pble_alloc *palloc)
519{
520 u64 *addr;
521 struct gen_pool *pool;
522 struct i40iw_pble_info *lvl1 = &palloc->level1;
523
524 pool = pble_rsrc->pinfo.pool;
525 addr = (u64 *)gen_pool_alloc(pool, (palloc->total_cnt << 3));
526
527 if (!addr)
528 return I40IW_ERR_NO_MEMORY;
529
530 palloc->level = I40IW_LEVEL_1;
531 lvl1->addr = (unsigned long)addr;
532 lvl1->idx = fpm_to_idx(pble_rsrc, (u64)gen_pool_virt_to_phys(pool,
533 (unsigned long)addr));
534 lvl1->cnt = palloc->total_cnt;
535 pble_rsrc->stats_lvl1++;
536 return 0;
537}
538
539/**
540 * get_lvl1_lvl2_pble - calls get_lvl1 and get_lvl2 pble routine
541 * @dev: i40iw_sc_dev struct
542 * @pble_rsrc: pble resources
543 * @palloc: contains all inforamtion regarding pble (idx + pble addr)
544 * @pool: pointer to general purpose special memory pool descriptor
545 */
546static inline enum i40iw_status_code get_lvl1_lvl2_pble(struct i40iw_sc_dev *dev,
547 struct i40iw_hmc_pble_rsrc *pble_rsrc,
548 struct i40iw_pble_alloc *palloc,
549 struct gen_pool *pool)
550{
551 enum i40iw_status_code status = 0;
552
553 status = get_lvl1_pble(dev, pble_rsrc, palloc);
554 if (status && (palloc->total_cnt > PBLE_PER_PAGE))
555 status = get_lvl2_pble(pble_rsrc, palloc, pool);
556 return status;
557}
558
559/**
560 * i40iw_get_pble - allocate pbles from the pool
561 * @dev: i40iw_sc_dev struct
562 * @pble_rsrc: pble resources
563 * @palloc: contains all inforamtion regarding pble (idx + pble addr)
564 * @pble_cnt: #of pbles requested
565 */
566enum i40iw_status_code i40iw_get_pble(struct i40iw_sc_dev *dev,
567 struct i40iw_hmc_pble_rsrc *pble_rsrc,
568 struct i40iw_pble_alloc *palloc,
569 u32 pble_cnt)
570{
571 struct gen_pool *pool;
572 enum i40iw_status_code status = 0;
573 u32 max_sds = 0;
574 int i;
575
576 pool = pble_rsrc->pinfo.pool;
577 palloc->total_cnt = pble_cnt;
578 palloc->level = I40IW_LEVEL_0;
579 /*check first to see if we can get pble's without acquiring additional sd's */
580 status = get_lvl1_lvl2_pble(dev, pble_rsrc, palloc, pool);
581 if (!status)
582 goto exit;
583 max_sds = (palloc->total_cnt >> 18) + 1;
584 for (i = 0; i < max_sds; i++) {
585 status = add_pble_pool(dev, pble_rsrc);
586 if (status)
587 break;
588 status = get_lvl1_lvl2_pble(dev, pble_rsrc, palloc, pool);
589 if (!status)
590 break;
591 }
592exit:
593 if (!status)
594 pble_rsrc->stats_alloc_ok++;
595 else
596 pble_rsrc->stats_alloc_fail++;
597
598 return status;
599}
600
601/**
602 * i40iw_free_pble - put pbles back into pool
603 * @pble_rsrc: pble resources
604 * @palloc: contains all inforamtion regarding pble resource being freed
605 */
606void i40iw_free_pble(struct i40iw_hmc_pble_rsrc *pble_rsrc,
607 struct i40iw_pble_alloc *palloc)
608{
609 struct gen_pool *pool;
610
611 pool = pble_rsrc->pinfo.pool;
612 if (palloc->level == I40IW_LEVEL_2)
613 free_lvl2(pble_rsrc, palloc);
614 else
615 gen_pool_free(pool, palloc->level1.addr,
616 (palloc->level1.cnt << 3));
617 pble_rsrc->stats_alloc_freed++;
618}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_pble.h b/drivers/infiniband/hw/i40iw/i40iw_pble.h
new file mode 100644
index 000000000000..7b1851d21cc0
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_pble.h
@@ -0,0 +1,131 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_PBLE_H
36#define I40IW_PBLE_H
37
38#define POOL_SHIFT 6
39#define PBLE_PER_PAGE 512
40#define I40IW_HMC_PAGED_BP_SHIFT 12
41#define PBLE_512_SHIFT 9
42
43enum i40iw_pble_level {
44 I40IW_LEVEL_0 = 0,
45 I40IW_LEVEL_1 = 1,
46 I40IW_LEVEL_2 = 2
47};
48
49enum i40iw_alloc_type {
50 I40IW_NO_ALLOC = 0,
51 I40IW_DMA_COHERENT = 1,
52 I40IW_VMALLOC = 2
53};
54
55struct i40iw_pble_info {
56 unsigned long addr;
57 u32 idx;
58 u32 cnt;
59};
60
61struct i40iw_pble_level2 {
62 struct i40iw_pble_info root;
63 struct i40iw_pble_info *leaf;
64 u32 leaf_cnt;
65};
66
67struct i40iw_pble_alloc {
68 u32 total_cnt;
69 enum i40iw_pble_level level;
70 union {
71 struct i40iw_pble_info level1;
72 struct i40iw_pble_level2 level2;
73 };
74};
75
76struct sd_pd_idx {
77 u32 sd_idx;
78 u32 pd_idx;
79 u32 rel_pd_idx;
80};
81
82struct i40iw_add_page_info {
83 struct i40iw_chunk *chunk;
84 struct i40iw_hmc_sd_entry *sd_entry;
85 struct i40iw_hmc_info *hmc_info;
86 struct sd_pd_idx idx;
87 u32 pages;
88};
89
90struct i40iw_chunk {
91 struct list_head list;
92 u32 size;
93 void *vaddr;
94 u64 fpm_addr;
95 u32 pg_cnt;
96 dma_addr_t *dmaaddrs;
97 enum i40iw_alloc_type type;
98};
99
100struct i40iw_pble_pool {
101 struct gen_pool *pool;
102 struct list_head clist;
103 u32 total_pble_alloc;
104 u32 free_pble_cnt;
105 u32 pool_shift;
106};
107
108struct i40iw_hmc_pble_rsrc {
109 u32 unallocated_pble;
110 u64 fpm_base_addr;
111 u64 next_fpm_addr;
112 struct i40iw_pble_pool pinfo;
113
114 u32 stats_direct_sds;
115 u32 stats_paged_sds;
116 u64 stats_alloc_ok;
117 u64 stats_alloc_fail;
118 u64 stats_alloc_freed;
119 u64 stats_lvl1;
120 u64 stats_lvl2;
121};
122
123void i40iw_destroy_pble_pool(struct i40iw_sc_dev *dev, struct i40iw_hmc_pble_rsrc *pble_rsrc);
124enum i40iw_status_code i40iw_hmc_init_pble(struct i40iw_sc_dev *dev,
125 struct i40iw_hmc_pble_rsrc *pble_rsrc);
126void i40iw_free_pble(struct i40iw_hmc_pble_rsrc *pble_rsrc, struct i40iw_pble_alloc *palloc);
127enum i40iw_status_code i40iw_get_pble(struct i40iw_sc_dev *dev,
128 struct i40iw_hmc_pble_rsrc *pble_rsrc,
129 struct i40iw_pble_alloc *palloc,
130 u32 pble_cnt);
131#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_puda.c b/drivers/infiniband/hw/i40iw/i40iw_puda.c
new file mode 100644
index 000000000000..8eb400d8a7a0
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_puda.c
@@ -0,0 +1,1436 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_osdep.h"
36#include "i40iw_register.h"
37#include "i40iw_status.h"
38#include "i40iw_hmc.h"
39
40#include "i40iw_d.h"
41#include "i40iw_type.h"
42#include "i40iw_p.h"
43#include "i40iw_puda.h"
44
45static void i40iw_ieq_receive(struct i40iw_sc_dev *dev,
46 struct i40iw_puda_buf *buf);
47static void i40iw_ieq_tx_compl(struct i40iw_sc_dev *dev, void *sqwrid);
48static void i40iw_ilq_putback_rcvbuf(struct i40iw_sc_qp *qp, u32 wqe_idx);
49static enum i40iw_status_code i40iw_puda_replenish_rq(struct i40iw_puda_rsrc
50 *rsrc, bool initial);
51/**
52 * i40iw_puda_get_listbuf - get buffer from puda list
53 * @list: list to use for buffers (ILQ or IEQ)
54 */
55static struct i40iw_puda_buf *i40iw_puda_get_listbuf(struct list_head *list)
56{
57 struct i40iw_puda_buf *buf = NULL;
58
59 if (!list_empty(list)) {
60 buf = (struct i40iw_puda_buf *)list->next;
61 list_del((struct list_head *)&buf->list);
62 }
63 return buf;
64}
65
66/**
67 * i40iw_puda_get_bufpool - return buffer from resource
68 * @rsrc: resource to use for buffer
69 */
70struct i40iw_puda_buf *i40iw_puda_get_bufpool(struct i40iw_puda_rsrc *rsrc)
71{
72 struct i40iw_puda_buf *buf = NULL;
73 struct list_head *list = &rsrc->bufpool;
74 unsigned long flags;
75
76 spin_lock_irqsave(&rsrc->bufpool_lock, flags);
77 buf = i40iw_puda_get_listbuf(list);
78 if (buf)
79 rsrc->avail_buf_count--;
80 else
81 rsrc->stats_buf_alloc_fail++;
82 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags);
83 return buf;
84}
85
86/**
87 * i40iw_puda_ret_bufpool - return buffer to rsrc list
88 * @rsrc: resource to use for buffer
89 * @buf: buffe to return to resouce
90 */
91void i40iw_puda_ret_bufpool(struct i40iw_puda_rsrc *rsrc,
92 struct i40iw_puda_buf *buf)
93{
94 unsigned long flags;
95
96 spin_lock_irqsave(&rsrc->bufpool_lock, flags);
97 list_add(&buf->list, &rsrc->bufpool);
98 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags);
99 rsrc->avail_buf_count++;
100}
101
102/**
103 * i40iw_puda_post_recvbuf - set wqe for rcv buffer
104 * @rsrc: resource ptr
105 * @wqe_idx: wqe index to use
106 * @buf: puda buffer for rcv q
107 * @initial: flag if during init time
108 */
109static void i40iw_puda_post_recvbuf(struct i40iw_puda_rsrc *rsrc, u32 wqe_idx,
110 struct i40iw_puda_buf *buf, bool initial)
111{
112 u64 *wqe;
113 struct i40iw_sc_qp *qp = &rsrc->qp;
114 u64 offset24 = 0;
115
116 qp->qp_uk.rq_wrid_array[wqe_idx] = (uintptr_t)buf;
117 wqe = qp->qp_uk.rq_base[wqe_idx].elem;
118 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA,
119 "%s: wqe_idx= %d buf = %p wqe = %p\n", __func__,
120 wqe_idx, buf, wqe);
121 if (!initial)
122 get_64bit_val(wqe, 24, &offset24);
123
124 offset24 = (offset24) ? 0 : LS_64(1, I40IWQPSQ_VALID);
125 set_64bit_val(wqe, 24, offset24);
126
127 set_64bit_val(wqe, 0, buf->mem.pa);
128 set_64bit_val(wqe, 8,
129 LS_64(buf->mem.size, I40IWQPSQ_FRAG_LEN));
130 set_64bit_val(wqe, 24, offset24);
131}
132
133/**
134 * i40iw_puda_replenish_rq - post rcv buffers
135 * @rsrc: resource to use for buffer
136 * @initial: flag if during init time
137 */
138static enum i40iw_status_code i40iw_puda_replenish_rq(struct i40iw_puda_rsrc *rsrc,
139 bool initial)
140{
141 u32 i;
142 u32 invalid_cnt = rsrc->rxq_invalid_cnt;
143 struct i40iw_puda_buf *buf = NULL;
144
145 for (i = 0; i < invalid_cnt; i++) {
146 buf = i40iw_puda_get_bufpool(rsrc);
147 if (!buf)
148 return I40IW_ERR_list_empty;
149 i40iw_puda_post_recvbuf(rsrc, rsrc->rx_wqe_idx, buf,
150 initial);
151 rsrc->rx_wqe_idx =
152 ((rsrc->rx_wqe_idx + 1) % rsrc->rq_size);
153 rsrc->rxq_invalid_cnt--;
154 }
155 return 0;
156}
157
158/**
159 * i40iw_puda_alloc_buf - allocate mem for buffer
160 * @dev: iwarp device
161 * @length: length of buffer
162 */
163static struct i40iw_puda_buf *i40iw_puda_alloc_buf(struct i40iw_sc_dev *dev,
164 u32 length)
165{
166 struct i40iw_puda_buf *buf = NULL;
167 struct i40iw_virt_mem buf_mem;
168 enum i40iw_status_code ret;
169
170 ret = i40iw_allocate_virt_mem(dev->hw, &buf_mem,
171 sizeof(struct i40iw_puda_buf));
172 if (ret) {
173 i40iw_debug(dev, I40IW_DEBUG_PUDA,
174 "%s: error mem for buf\n", __func__);
175 return NULL;
176 }
177 buf = (struct i40iw_puda_buf *)buf_mem.va;
178 ret = i40iw_allocate_dma_mem(dev->hw, &buf->mem, length, 1);
179 if (ret) {
180 i40iw_debug(dev, I40IW_DEBUG_PUDA,
181 "%s: error dma mem for buf\n", __func__);
182 i40iw_free_virt_mem(dev->hw, &buf_mem);
183 return NULL;
184 }
185 buf->buf_mem.va = buf_mem.va;
186 buf->buf_mem.size = buf_mem.size;
187 return buf;
188}
189
190/**
191 * i40iw_puda_dele_buf - delete buffer back to system
192 * @dev: iwarp device
193 * @buf: buffer to free
194 */
195static void i40iw_puda_dele_buf(struct i40iw_sc_dev *dev,
196 struct i40iw_puda_buf *buf)
197{
198 i40iw_free_dma_mem(dev->hw, &buf->mem);
199 i40iw_free_virt_mem(dev->hw, &buf->buf_mem);
200}
201
202/**
203 * i40iw_puda_get_next_send_wqe - return next wqe for processing
204 * @qp: puda qp for wqe
205 * @wqe_idx: wqe index for caller
206 */
207static u64 *i40iw_puda_get_next_send_wqe(struct i40iw_qp_uk *qp, u32 *wqe_idx)
208{
209 u64 *wqe = NULL;
210 enum i40iw_status_code ret_code = 0;
211
212 *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
213 if (!*wqe_idx)
214 qp->swqe_polarity = !qp->swqe_polarity;
215 I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
216 if (ret_code)
217 return wqe;
218 wqe = qp->sq_base[*wqe_idx].elem;
219
220 return wqe;
221}
222
223/**
224 * i40iw_puda_poll_info - poll cq for completion
225 * @cq: cq for poll
226 * @info: info return for successful completion
227 */
228static enum i40iw_status_code i40iw_puda_poll_info(struct i40iw_sc_cq *cq,
229 struct i40iw_puda_completion_info *info)
230{
231 u64 qword0, qword2, qword3;
232 u64 *cqe;
233 u64 comp_ctx;
234 bool valid_bit;
235 u32 major_err, minor_err;
236 bool error;
237
238 cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(&cq->cq_uk);
239 get_64bit_val(cqe, 24, &qword3);
240 valid_bit = (bool)RS_64(qword3, I40IW_CQ_VALID);
241
242 if (valid_bit != cq->cq_uk.polarity)
243 return I40IW_ERR_QUEUE_EMPTY;
244
245 i40iw_debug_buf(cq->dev, I40IW_DEBUG_PUDA, "PUDA CQE", cqe, 32);
246 error = (bool)RS_64(qword3, I40IW_CQ_ERROR);
247 if (error) {
248 i40iw_debug(cq->dev, I40IW_DEBUG_PUDA, "%s receive error\n", __func__);
249 major_err = (u32)(RS_64(qword3, I40IW_CQ_MAJERR));
250 minor_err = (u32)(RS_64(qword3, I40IW_CQ_MINERR));
251 info->compl_error = major_err << 16 | minor_err;
252 return I40IW_ERR_CQ_COMPL_ERROR;
253 }
254
255 get_64bit_val(cqe, 0, &qword0);
256 get_64bit_val(cqe, 16, &qword2);
257
258 info->q_type = (u8)RS_64(qword3, I40IW_CQ_SQ);
259 info->qp_id = (u32)RS_64(qword2, I40IWCQ_QPID);
260
261 get_64bit_val(cqe, 8, &comp_ctx);
262 info->qp = (struct i40iw_qp_uk *)(unsigned long)comp_ctx;
263 info->wqe_idx = (u32)RS_64(qword3, I40IW_CQ_WQEIDX);
264
265 if (info->q_type == I40IW_CQE_QTYPE_RQ) {
266 info->vlan_valid = (bool)RS_64(qword3, I40IW_VLAN_TAG_VALID);
267 info->l4proto = (u8)RS_64(qword2, I40IW_UDA_L4PROTO);
268 info->l3proto = (u8)RS_64(qword2, I40IW_UDA_L3PROTO);
269 info->payload_len = (u16)RS_64(qword0, I40IW_UDA_PAYLOADLEN);
270 }
271
272 return 0;
273}
274
275/**
276 * i40iw_puda_poll_completion - processes completion for cq
277 * @dev: iwarp device
278 * @cq: cq getting interrupt
279 * @compl_err: return any completion err
280 */
281enum i40iw_status_code i40iw_puda_poll_completion(struct i40iw_sc_dev *dev,
282 struct i40iw_sc_cq *cq, u32 *compl_err)
283{
284 struct i40iw_qp_uk *qp;
285 struct i40iw_cq_uk *cq_uk = &cq->cq_uk;
286 struct i40iw_puda_completion_info info;
287 enum i40iw_status_code ret = 0;
288 struct i40iw_puda_buf *buf;
289 struct i40iw_puda_rsrc *rsrc;
290 void *sqwrid;
291 u8 cq_type = cq->cq_type;
292 unsigned long flags;
293
294 if ((cq_type == I40IW_CQ_TYPE_ILQ) || (cq_type == I40IW_CQ_TYPE_IEQ)) {
295 rsrc = (cq_type == I40IW_CQ_TYPE_ILQ) ? dev->ilq : dev->ieq;
296 } else {
297 i40iw_debug(dev, I40IW_DEBUG_PUDA, "%s qp_type error\n", __func__);
298 return I40IW_ERR_BAD_PTR;
299 }
300 memset(&info, 0, sizeof(info));
301 ret = i40iw_puda_poll_info(cq, &info);
302 *compl_err = info.compl_error;
303 if (ret == I40IW_ERR_QUEUE_EMPTY)
304 return ret;
305 if (ret)
306 goto done;
307
308 qp = info.qp;
309 if (!qp || !rsrc) {
310 ret = I40IW_ERR_BAD_PTR;
311 goto done;
312 }
313
314 if (qp->qp_id != rsrc->qp_id) {
315 ret = I40IW_ERR_BAD_PTR;
316 goto done;
317 }
318
319 if (info.q_type == I40IW_CQE_QTYPE_RQ) {
320 buf = (struct i40iw_puda_buf *)(uintptr_t)qp->rq_wrid_array[info.wqe_idx];
321 /* Get all the tcpip information in the buf header */
322 ret = i40iw_puda_get_tcpip_info(&info, buf);
323 if (ret) {
324 rsrc->stats_rcvd_pkt_err++;
325 if (cq_type == I40IW_CQ_TYPE_ILQ) {
326 i40iw_ilq_putback_rcvbuf(&rsrc->qp,
327 info.wqe_idx);
328 } else {
329 i40iw_puda_ret_bufpool(rsrc, buf);
330 i40iw_puda_replenish_rq(rsrc, false);
331 }
332 goto done;
333 }
334
335 rsrc->stats_pkt_rcvd++;
336 rsrc->compl_rxwqe_idx = info.wqe_idx;
337 i40iw_debug(dev, I40IW_DEBUG_PUDA, "%s RQ completion\n", __func__);
338 rsrc->receive(rsrc->dev, buf);
339 if (cq_type == I40IW_CQ_TYPE_ILQ)
340 i40iw_ilq_putback_rcvbuf(&rsrc->qp, info.wqe_idx);
341 else
342 i40iw_puda_replenish_rq(rsrc, false);
343
344 } else {
345 i40iw_debug(dev, I40IW_DEBUG_PUDA, "%s SQ completion\n", __func__);
346 sqwrid = (void *)(uintptr_t)qp->sq_wrtrk_array[info.wqe_idx].wrid;
347 I40IW_RING_SET_TAIL(qp->sq_ring, info.wqe_idx);
348 rsrc->xmit_complete(rsrc->dev, sqwrid);
349 spin_lock_irqsave(&rsrc->bufpool_lock, flags);
350 rsrc->tx_wqe_avail_cnt++;
351 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags);
352 if (!list_empty(&dev->ilq->txpend))
353 i40iw_puda_send_buf(dev->ilq, NULL);
354 }
355
356done:
357 I40IW_RING_MOVE_HEAD(cq_uk->cq_ring, ret);
358 if (I40IW_RING_GETCURRENT_HEAD(cq_uk->cq_ring) == 0)
359 cq_uk->polarity = !cq_uk->polarity;
360 /* update cq tail in cq shadow memory also */
361 I40IW_RING_MOVE_TAIL(cq_uk->cq_ring);
362 set_64bit_val(cq_uk->shadow_area, 0,
363 I40IW_RING_GETCURRENT_HEAD(cq_uk->cq_ring));
364 return 0;
365}
366
367/**
368 * i40iw_puda_send - complete send wqe for transmit
369 * @qp: puda qp for send
370 * @info: buffer information for transmit
371 */
372enum i40iw_status_code i40iw_puda_send(struct i40iw_sc_qp *qp,
373 struct i40iw_puda_send_info *info)
374{
375 u64 *wqe;
376 u32 iplen, l4len;
377 u64 header[2];
378 u32 wqe_idx;
379 u8 iipt;
380
381 /* number of 32 bits DWORDS in header */
382 l4len = info->tcplen >> 2;
383 if (info->ipv4) {
384 iipt = 3;
385 iplen = 5;
386 } else {
387 iipt = 1;
388 iplen = 10;
389 }
390
391 wqe = i40iw_puda_get_next_send_wqe(&qp->qp_uk, &wqe_idx);
392 if (!wqe)
393 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
394 qp->qp_uk.sq_wrtrk_array[wqe_idx].wrid = (uintptr_t)info->scratch;
395 /* Third line of WQE descriptor */
396 /* maclen is in words */
397 header[0] = LS_64((info->maclen >> 1), I40IW_UDA_QPSQ_MACLEN) |
398 LS_64(iplen, I40IW_UDA_QPSQ_IPLEN) | LS_64(1, I40IW_UDA_QPSQ_L4T) |
399 LS_64(iipt, I40IW_UDA_QPSQ_IIPT) |
400 LS_64(l4len, I40IW_UDA_QPSQ_L4LEN);
401 /* Forth line of WQE descriptor */
402 header[1] = LS_64(I40IW_OP_TYPE_SEND, I40IW_UDA_QPSQ_OPCODE) |
403 LS_64(1, I40IW_UDA_QPSQ_SIGCOMPL) |
404 LS_64(info->doloopback, I40IW_UDA_QPSQ_DOLOOPBACK) |
405 LS_64(qp->qp_uk.swqe_polarity, I40IW_UDA_QPSQ_VALID);
406
407 set_64bit_val(wqe, 0, info->paddr);
408 set_64bit_val(wqe, 8, LS_64(info->len, I40IWQPSQ_FRAG_LEN));
409 set_64bit_val(wqe, 16, header[0]);
410 set_64bit_val(wqe, 24, header[1]);
411
412 i40iw_debug_buf(qp->dev, I40IW_DEBUG_PUDA, "PUDA SEND WQE", wqe, 32);
413 i40iw_qp_post_wr(&qp->qp_uk);
414 return 0;
415}
416
417/**
418 * i40iw_puda_send_buf - transmit puda buffer
419 * @rsrc: resource to use for buffer
420 * @buf: puda buffer to transmit
421 */
422void i40iw_puda_send_buf(struct i40iw_puda_rsrc *rsrc, struct i40iw_puda_buf *buf)
423{
424 struct i40iw_puda_send_info info;
425 enum i40iw_status_code ret = 0;
426 unsigned long flags;
427
428 spin_lock_irqsave(&rsrc->bufpool_lock, flags);
429 /* if no wqe available or not from a completion and we have
430 * pending buffers, we must queue new buffer
431 */
432 if (!rsrc->tx_wqe_avail_cnt || (buf && !list_empty(&rsrc->txpend))) {
433 list_add_tail(&buf->list, &rsrc->txpend);
434 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags);
435 rsrc->stats_sent_pkt_q++;
436 if (rsrc->type == I40IW_PUDA_RSRC_TYPE_ILQ)
437 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA,
438 "%s: adding to txpend\n", __func__);
439 return;
440 }
441 rsrc->tx_wqe_avail_cnt--;
442 /* if we are coming from a completion and have pending buffers
443 * then Get one from pending list
444 */
445 if (!buf) {
446 buf = i40iw_puda_get_listbuf(&rsrc->txpend);
447 if (!buf)
448 goto done;
449 }
450
451 info.scratch = (void *)buf;
452 info.paddr = buf->mem.pa;
453 info.len = buf->totallen;
454 info.tcplen = buf->tcphlen;
455 info.maclen = buf->maclen;
456 info.ipv4 = buf->ipv4;
457 info.doloopback = (rsrc->type == I40IW_PUDA_RSRC_TYPE_IEQ);
458
459 ret = i40iw_puda_send(&rsrc->qp, &info);
460 if (ret) {
461 rsrc->tx_wqe_avail_cnt++;
462 rsrc->stats_sent_pkt_q++;
463 list_add(&buf->list, &rsrc->txpend);
464 if (rsrc->type == I40IW_PUDA_RSRC_TYPE_ILQ)
465 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA,
466 "%s: adding to puda_send\n", __func__);
467 } else {
468 rsrc->stats_pkt_sent++;
469 }
470done:
471 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags);
472}
473
474/**
475 * i40iw_puda_qp_setctx - during init, set qp's context
476 * @rsrc: qp's resource
477 */
478static void i40iw_puda_qp_setctx(struct i40iw_puda_rsrc *rsrc)
479{
480 struct i40iw_sc_qp *qp = &rsrc->qp;
481 u64 *qp_ctx = qp->hw_host_ctx;
482
483 set_64bit_val(qp_ctx, 8, qp->sq_pa);
484 set_64bit_val(qp_ctx, 16, qp->rq_pa);
485
486 set_64bit_val(qp_ctx, 24,
487 LS_64(qp->hw_rq_size, I40IWQPC_RQSIZE) |
488 LS_64(qp->hw_sq_size, I40IWQPC_SQSIZE));
489
490 set_64bit_val(qp_ctx, 48, LS_64(1514, I40IWQPC_SNDMSS));
491 set_64bit_val(qp_ctx, 56, 0);
492 set_64bit_val(qp_ctx, 64, 1);
493
494 set_64bit_val(qp_ctx, 136,
495 LS_64(rsrc->cq_id, I40IWQPC_TXCQNUM) |
496 LS_64(rsrc->cq_id, I40IWQPC_RXCQNUM));
497
498 set_64bit_val(qp_ctx, 160, LS_64(1, I40IWQPC_PRIVEN));
499
500 set_64bit_val(qp_ctx, 168,
501 LS_64((uintptr_t)qp, I40IWQPC_QPCOMPCTX));
502
503 set_64bit_val(qp_ctx, 176,
504 LS_64(qp->sq_tph_val, I40IWQPC_SQTPHVAL) |
505 LS_64(qp->rq_tph_val, I40IWQPC_RQTPHVAL) |
506 LS_64(qp->qs_handle, I40IWQPC_QSHANDLE));
507
508 i40iw_debug_buf(rsrc->dev, I40IW_DEBUG_PUDA, "PUDA QP CONTEXT",
509 qp_ctx, I40IW_QP_CTX_SIZE);
510}
511
512/**
513 * i40iw_puda_qp_wqe - setup wqe for qp create
514 * @rsrc: resource for qp
515 */
516static enum i40iw_status_code i40iw_puda_qp_wqe(struct i40iw_puda_rsrc *rsrc)
517{
518 struct i40iw_sc_qp *qp = &rsrc->qp;
519 struct i40iw_sc_dev *dev = rsrc->dev;
520 struct i40iw_sc_cqp *cqp;
521 u64 *wqe;
522 u64 header;
523 struct i40iw_ccq_cqe_info compl_info;
524 enum i40iw_status_code status = 0;
525
526 cqp = dev->cqp;
527 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, 0);
528 if (!wqe)
529 return I40IW_ERR_RING_FULL;
530
531 set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
532 set_64bit_val(wqe, 40, qp->shadow_area_pa);
533 header = qp->qp_uk.qp_id |
534 LS_64(I40IW_CQP_OP_CREATE_QP, I40IW_CQPSQ_OPCODE) |
535 LS_64(I40IW_QP_TYPE_UDA, I40IW_CQPSQ_QP_QPTYPE) |
536 LS_64(1, I40IW_CQPSQ_QP_CQNUMVALID) |
537 LS_64(2, I40IW_CQPSQ_QP_NEXTIWSTATE) |
538 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
539
540 set_64bit_val(wqe, 24, header);
541
542 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_PUDA, "PUDA CQE", wqe, 32);
543 i40iw_sc_cqp_post_sq(cqp);
544 status = dev->cqp_ops->poll_for_cqp_op_done(dev->cqp,
545 I40IW_CQP_OP_CREATE_QP,
546 &compl_info);
547 return status;
548}
549
550/**
551 * i40iw_puda_qp_create - create qp for resource
552 * @rsrc: resource to use for buffer
553 */
554static enum i40iw_status_code i40iw_puda_qp_create(struct i40iw_puda_rsrc *rsrc)
555{
556 struct i40iw_sc_qp *qp = &rsrc->qp;
557 struct i40iw_qp_uk *ukqp = &qp->qp_uk;
558 enum i40iw_status_code ret = 0;
559 u32 sq_size, rq_size, t_size;
560 struct i40iw_dma_mem *mem;
561
562 sq_size = rsrc->sq_size * I40IW_QP_WQE_MIN_SIZE;
563 rq_size = rsrc->rq_size * I40IW_QP_WQE_MIN_SIZE;
564 t_size = (sq_size + rq_size + (I40IW_SHADOW_AREA_SIZE << 3) +
565 I40IW_QP_CTX_SIZE);
566 /* Get page aligned memory */
567 ret =
568 i40iw_allocate_dma_mem(rsrc->dev->hw, &rsrc->qpmem, t_size,
569 I40IW_HW_PAGE_SIZE);
570 if (ret) {
571 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA, "%s: error dma mem\n", __func__);
572 return ret;
573 }
574
575 mem = &rsrc->qpmem;
576 memset(mem->va, 0, t_size);
577 qp->hw_sq_size = i40iw_get_encoded_wqe_size(rsrc->sq_size, false);
578 qp->hw_rq_size = i40iw_get_encoded_wqe_size(rsrc->rq_size, false);
579 qp->pd = &rsrc->sc_pd;
580 qp->qp_type = I40IW_QP_TYPE_UDA;
581 qp->dev = rsrc->dev;
582 qp->back_qp = (void *)rsrc;
583 qp->sq_pa = mem->pa;
584 qp->rq_pa = qp->sq_pa + sq_size;
585 ukqp->sq_base = mem->va;
586 ukqp->rq_base = &ukqp->sq_base[rsrc->sq_size];
587 ukqp->shadow_area = ukqp->rq_base[rsrc->rq_size].elem;
588 qp->shadow_area_pa = qp->rq_pa + rq_size;
589 qp->hw_host_ctx = ukqp->shadow_area + I40IW_SHADOW_AREA_SIZE;
590 qp->hw_host_ctx_pa =
591 qp->shadow_area_pa + (I40IW_SHADOW_AREA_SIZE << 3);
592 ukqp->qp_id = rsrc->qp_id;
593 ukqp->sq_wrtrk_array = rsrc->sq_wrtrk_array;
594 ukqp->rq_wrid_array = rsrc->rq_wrid_array;
595
596 ukqp->qp_id = rsrc->qp_id;
597 ukqp->sq_size = rsrc->sq_size;
598 ukqp->rq_size = rsrc->rq_size;
599
600 I40IW_RING_INIT(ukqp->sq_ring, ukqp->sq_size);
601 I40IW_RING_INIT(ukqp->initial_ring, ukqp->sq_size);
602 I40IW_RING_INIT(ukqp->rq_ring, ukqp->rq_size);
603
604 if (qp->pd->dev->is_pf)
605 ukqp->wqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(qp->pd->dev) +
606 I40E_PFPE_WQEALLOC);
607 else
608 ukqp->wqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(qp->pd->dev) +
609 I40E_VFPE_WQEALLOC1);
610
611 qp->qs_handle = qp->dev->qs_handle;
612 i40iw_puda_qp_setctx(rsrc);
613 ret = i40iw_puda_qp_wqe(rsrc);
614 if (ret)
615 i40iw_free_dma_mem(rsrc->dev->hw, &rsrc->qpmem);
616 return ret;
617}
618
619/**
620 * i40iw_puda_cq_create - create cq for resource
621 * @rsrc: resource for which cq to create
622 */
623static enum i40iw_status_code i40iw_puda_cq_create(struct i40iw_puda_rsrc *rsrc)
624{
625 struct i40iw_sc_dev *dev = rsrc->dev;
626 struct i40iw_sc_cq *cq = &rsrc->cq;
627 u64 *wqe;
628 struct i40iw_sc_cqp *cqp;
629 u64 header;
630 enum i40iw_status_code ret = 0;
631 u32 tsize, cqsize;
632 u32 shadow_read_threshold = 128;
633 struct i40iw_dma_mem *mem;
634 struct i40iw_ccq_cqe_info compl_info;
635 struct i40iw_cq_init_info info;
636 struct i40iw_cq_uk_init_info *init_info = &info.cq_uk_init_info;
637
638 cq->back_cq = (void *)rsrc;
639 cqsize = rsrc->cq_size * (sizeof(struct i40iw_cqe));
640 tsize = cqsize + sizeof(struct i40iw_cq_shadow_area);
641 ret = i40iw_allocate_dma_mem(dev->hw, &rsrc->cqmem, tsize,
642 I40IW_CQ0_ALIGNMENT_MASK);
643 if (ret)
644 return ret;
645
646 mem = &rsrc->cqmem;
647 memset(&info, 0, sizeof(info));
648 info.dev = dev;
649 info.type = (rsrc->type == I40IW_PUDA_RSRC_TYPE_ILQ) ?
650 I40IW_CQ_TYPE_ILQ : I40IW_CQ_TYPE_IEQ;
651 info.shadow_read_threshold = rsrc->cq_size >> 2;
652 info.ceq_id_valid = true;
653 info.cq_base_pa = mem->pa;
654 info.shadow_area_pa = mem->pa + cqsize;
655 init_info->cq_base = mem->va;
656 init_info->shadow_area = (u64 *)((u8 *)mem->va + cqsize);
657 init_info->cq_size = rsrc->cq_size;
658 init_info->cq_id = rsrc->cq_id;
659 ret = dev->iw_priv_cq_ops->cq_init(cq, &info);
660 if (ret)
661 goto error;
662 cqp = dev->cqp;
663 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, 0);
664 if (!wqe) {
665 ret = I40IW_ERR_RING_FULL;
666 goto error;
667 }
668
669 set_64bit_val(wqe, 0, rsrc->cq_size);
670 set_64bit_val(wqe, 8, RS_64_1(cq, 1));
671 set_64bit_val(wqe, 16, LS_64(shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
672 set_64bit_val(wqe, 32, cq->cq_pa);
673
674 set_64bit_val(wqe, 40, cq->shadow_area_pa);
675
676 header = rsrc->cq_id |
677 LS_64(I40IW_CQP_OP_CREATE_CQ, I40IW_CQPSQ_OPCODE) |
678 LS_64(1, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
679 LS_64(1, I40IW_CQPSQ_CQ_ENCEQEMASK) |
680 LS_64(1, I40IW_CQPSQ_CQ_CEQIDVALID) |
681 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
682 set_64bit_val(wqe, 24, header);
683
684 i40iw_debug_buf(dev, I40IW_DEBUG_PUDA, "PUDA CQE",
685 wqe, I40IW_CQP_WQE_SIZE * 8);
686
687 i40iw_sc_cqp_post_sq(dev->cqp);
688 ret = dev->cqp_ops->poll_for_cqp_op_done(dev->cqp,
689 I40IW_CQP_OP_CREATE_CQ,
690 &compl_info);
691
692error:
693 if (ret)
694 i40iw_free_dma_mem(dev->hw, &rsrc->cqmem);
695 return ret;
696}
697
698/**
699 * i40iw_puda_dele_resources - delete all resources during close
700 * @dev: iwarp device
701 * @type: type of resource to dele
702 * @reset: true if reset chip
703 */
704void i40iw_puda_dele_resources(struct i40iw_sc_dev *dev,
705 enum puda_resource_type type,
706 bool reset)
707{
708 struct i40iw_ccq_cqe_info compl_info;
709 struct i40iw_puda_rsrc *rsrc;
710 struct i40iw_puda_buf *buf = NULL;
711 struct i40iw_puda_buf *nextbuf = NULL;
712 struct i40iw_virt_mem *vmem;
713 enum i40iw_status_code ret;
714
715 switch (type) {
716 case I40IW_PUDA_RSRC_TYPE_ILQ:
717 rsrc = dev->ilq;
718 vmem = &dev->ilq_mem;
719 break;
720 case I40IW_PUDA_RSRC_TYPE_IEQ:
721 rsrc = dev->ieq;
722 vmem = &dev->ieq_mem;
723 break;
724 default:
725 i40iw_debug(dev, I40IW_DEBUG_PUDA, "%s: error resource type = 0x%x\n",
726 __func__, type);
727 return;
728 }
729
730 switch (rsrc->completion) {
731 case PUDA_HASH_CRC_COMPLETE:
732 i40iw_free_hash_desc(rsrc->hash_desc);
733 case PUDA_QP_CREATED:
734 do {
735 if (reset)
736 break;
737 ret = dev->iw_priv_qp_ops->qp_destroy(&rsrc->qp,
738 0, false, true, true);
739 if (ret)
740 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA,
741 "%s error ieq qp destroy\n",
742 __func__);
743
744 ret = dev->cqp_ops->poll_for_cqp_op_done(dev->cqp,
745 I40IW_CQP_OP_DESTROY_QP,
746 &compl_info);
747 if (ret)
748 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA,
749 "%s error ieq qp destroy done\n",
750 __func__);
751 } while (0);
752
753 i40iw_free_dma_mem(dev->hw, &rsrc->qpmem);
754 /* fallthrough */
755 case PUDA_CQ_CREATED:
756 do {
757 if (reset)
758 break;
759 ret = dev->iw_priv_cq_ops->cq_destroy(&rsrc->cq, 0, true);
760 if (ret)
761 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA,
762 "%s error ieq cq destroy\n",
763 __func__);
764
765 ret = dev->cqp_ops->poll_for_cqp_op_done(dev->cqp,
766 I40IW_CQP_OP_DESTROY_CQ,
767 &compl_info);
768 if (ret)
769 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA,
770 "%s error ieq qp destroy done\n",
771 __func__);
772 } while (0);
773
774 i40iw_free_dma_mem(dev->hw, &rsrc->cqmem);
775 break;
776 default:
777 i40iw_debug(rsrc->dev, I40IW_DEBUG_PUDA, "%s error no resources\n", __func__);
778 break;
779 }
780 /* Free all allocated puda buffers for both tx and rx */
781 buf = rsrc->alloclist;
782 while (buf) {
783 nextbuf = buf->next;
784 i40iw_puda_dele_buf(dev, buf);
785 buf = nextbuf;
786 rsrc->alloc_buf_count--;
787 }
788 i40iw_free_virt_mem(dev->hw, vmem);
789}
790
791/**
792 * i40iw_puda_allocbufs - allocate buffers for resource
793 * @rsrc: resource for buffer allocation
794 * @count: number of buffers to create
795 */
796static enum i40iw_status_code i40iw_puda_allocbufs(struct i40iw_puda_rsrc *rsrc,
797 u32 count)
798{
799 u32 i;
800 struct i40iw_puda_buf *buf;
801 struct i40iw_puda_buf *nextbuf;
802
803 for (i = 0; i < count; i++) {
804 buf = i40iw_puda_alloc_buf(rsrc->dev, rsrc->buf_size);
805 if (!buf) {
806 rsrc->stats_buf_alloc_fail++;
807 return I40IW_ERR_NO_MEMORY;
808 }
809 i40iw_puda_ret_bufpool(rsrc, buf);
810 rsrc->alloc_buf_count++;
811 if (!rsrc->alloclist) {
812 rsrc->alloclist = buf;
813 } else {
814 nextbuf = rsrc->alloclist;
815 rsrc->alloclist = buf;
816 buf->next = nextbuf;
817 }
818 }
819 rsrc->avail_buf_count = rsrc->alloc_buf_count;
820 return 0;
821}
822
823/**
824 * i40iw_puda_create_rsrc - create resouce (ilq or ieq)
825 * @dev: iwarp device
826 * @info: resource information
827 */
828enum i40iw_status_code i40iw_puda_create_rsrc(struct i40iw_sc_dev *dev,
829 struct i40iw_puda_rsrc_info *info)
830{
831 enum i40iw_status_code ret = 0;
832 struct i40iw_puda_rsrc *rsrc;
833 u32 pudasize;
834 u32 sqwridsize, rqwridsize;
835 struct i40iw_virt_mem *vmem;
836
837 info->count = 1;
838 pudasize = sizeof(struct i40iw_puda_rsrc);
839 sqwridsize = info->sq_size * sizeof(struct i40iw_sq_uk_wr_trk_info);
840 rqwridsize = info->rq_size * 8;
841 switch (info->type) {
842 case I40IW_PUDA_RSRC_TYPE_ILQ:
843 vmem = &dev->ilq_mem;
844 break;
845 case I40IW_PUDA_RSRC_TYPE_IEQ:
846 vmem = &dev->ieq_mem;
847 break;
848 default:
849 return I40IW_NOT_SUPPORTED;
850 }
851 ret =
852 i40iw_allocate_virt_mem(dev->hw, vmem,
853 pudasize + sqwridsize + rqwridsize);
854 if (ret)
855 return ret;
856 rsrc = (struct i40iw_puda_rsrc *)vmem->va;
857 spin_lock_init(&rsrc->bufpool_lock);
858 if (info->type == I40IW_PUDA_RSRC_TYPE_ILQ) {
859 dev->ilq = (struct i40iw_puda_rsrc *)vmem->va;
860 dev->ilq_count = info->count;
861 rsrc->receive = info->receive;
862 rsrc->xmit_complete = info->xmit_complete;
863 } else {
864 vmem = &dev->ieq_mem;
865 dev->ieq_count = info->count;
866 dev->ieq = (struct i40iw_puda_rsrc *)vmem->va;
867 rsrc->receive = i40iw_ieq_receive;
868 rsrc->xmit_complete = i40iw_ieq_tx_compl;
869 }
870
871 rsrc->type = info->type;
872 rsrc->sq_wrtrk_array = (struct i40iw_sq_uk_wr_trk_info *)((u8 *)vmem->va + pudasize);
873 rsrc->rq_wrid_array = (u64 *)((u8 *)vmem->va + pudasize + sqwridsize);
874 rsrc->mss = info->mss;
875 /* Initialize all ieq lists */
876 INIT_LIST_HEAD(&rsrc->bufpool);
877 INIT_LIST_HEAD(&rsrc->txpend);
878
879 rsrc->tx_wqe_avail_cnt = info->sq_size - 1;
880 dev->iw_pd_ops->pd_init(dev, &rsrc->sc_pd, info->pd_id);
881 rsrc->qp_id = info->qp_id;
882 rsrc->cq_id = info->cq_id;
883 rsrc->sq_size = info->sq_size;
884 rsrc->rq_size = info->rq_size;
885 rsrc->cq_size = info->rq_size + info->sq_size;
886 rsrc->buf_size = info->buf_size;
887 rsrc->dev = dev;
888
889 ret = i40iw_puda_cq_create(rsrc);
890 if (!ret) {
891 rsrc->completion = PUDA_CQ_CREATED;
892 ret = i40iw_puda_qp_create(rsrc);
893 }
894 if (ret) {
895 i40iw_debug(dev, I40IW_DEBUG_PUDA, "[%s] error qp_create\n", __func__);
896 goto error;
897 }
898 rsrc->completion = PUDA_QP_CREATED;
899
900 ret = i40iw_puda_allocbufs(rsrc, info->tx_buf_cnt + info->rq_size);
901 if (ret) {
902 i40iw_debug(dev, I40IW_DEBUG_PUDA, "[%s] error allloc_buf\n", __func__);
903 goto error;
904 }
905
906 rsrc->rxq_invalid_cnt = info->rq_size;
907 ret = i40iw_puda_replenish_rq(rsrc, true);
908 if (ret)
909 goto error;
910
911 if (info->type == I40IW_PUDA_RSRC_TYPE_IEQ) {
912 if (!i40iw_init_hash_desc(&rsrc->hash_desc)) {
913 rsrc->check_crc = true;
914 rsrc->completion = PUDA_HASH_CRC_COMPLETE;
915 ret = 0;
916 }
917 }
918
919 dev->ccq_ops->ccq_arm(&rsrc->cq);
920 return ret;
921 error:
922 i40iw_puda_dele_resources(dev, info->type, false);
923
924 return ret;
925}
926
927/**
928 * i40iw_ilq_putback_rcvbuf - ilq buffer to put back on rq
929 * @qp: ilq's qp resource
930 * @wqe_idx: wqe index of completed rcvbuf
931 */
932static void i40iw_ilq_putback_rcvbuf(struct i40iw_sc_qp *qp, u32 wqe_idx)
933{
934 u64 *wqe;
935 u64 offset24;
936
937 wqe = qp->qp_uk.rq_base[wqe_idx].elem;
938 get_64bit_val(wqe, 24, &offset24);
939 offset24 = (offset24) ? 0 : LS_64(1, I40IWQPSQ_VALID);
940 set_64bit_val(wqe, 24, offset24);
941}
942
943/**
944 * i40iw_ieq_get_fpdu - given length return fpdu length
945 * @length: length if fpdu
946 */
947static u16 i40iw_ieq_get_fpdu_length(u16 length)
948{
949 u16 fpdu_len;
950
951 fpdu_len = length + I40IW_IEQ_MPA_FRAMING;
952 fpdu_len = (fpdu_len + 3) & 0xfffffffc;
953 return fpdu_len;
954}
955
956/**
957 * i40iw_ieq_copy_to_txbuf - copydata from rcv buf to tx buf
958 * @buf: rcv buffer with partial
959 * @txbuf: tx buffer for sendign back
960 * @buf_offset: rcv buffer offset to copy from
961 * @txbuf_offset: at offset in tx buf to copy
962 * @length: length of data to copy
963 */
964static void i40iw_ieq_copy_to_txbuf(struct i40iw_puda_buf *buf,
965 struct i40iw_puda_buf *txbuf,
966 u16 buf_offset, u32 txbuf_offset,
967 u32 length)
968{
969 void *mem1 = (u8 *)buf->mem.va + buf_offset;
970 void *mem2 = (u8 *)txbuf->mem.va + txbuf_offset;
971
972 memcpy(mem2, mem1, length);
973}
974
975/**
976 * i40iw_ieq_setup_tx_buf - setup tx buffer for partial handling
977 * @buf: reeive buffer with partial
978 * @txbuf: buffer to prepare
979 */
980static void i40iw_ieq_setup_tx_buf(struct i40iw_puda_buf *buf,
981 struct i40iw_puda_buf *txbuf)
982{
983 txbuf->maclen = buf->maclen;
984 txbuf->tcphlen = buf->tcphlen;
985 txbuf->ipv4 = buf->ipv4;
986 txbuf->hdrlen = buf->hdrlen;
987 i40iw_ieq_copy_to_txbuf(buf, txbuf, 0, 0, buf->hdrlen);
988}
989
990/**
991 * i40iw_ieq_check_first_buf - check if rcv buffer's seq is in range
992 * @buf: receive exception buffer
993 * @fps: first partial sequence number
994 */
995static void i40iw_ieq_check_first_buf(struct i40iw_puda_buf *buf, u32 fps)
996{
997 u32 offset;
998
999 if (buf->seqnum < fps) {
1000 offset = fps - buf->seqnum;
1001 if (offset > buf->datalen)
1002 return;
1003 buf->data += offset;
1004 buf->datalen -= (u16)offset;
1005 buf->seqnum = fps;
1006 }
1007}
1008
1009/**
1010 * i40iw_ieq_compl_pfpdu - write txbuf with full fpdu
1011 * @ieq: ieq resource
1012 * @rxlist: ieq's received buffer list
1013 * @pbufl: temporary list for buffers for fpddu
1014 * @txbuf: tx buffer for fpdu
1015 * @fpdu_len: total length of fpdu
1016 */
1017static void i40iw_ieq_compl_pfpdu(struct i40iw_puda_rsrc *ieq,
1018 struct list_head *rxlist,
1019 struct list_head *pbufl,
1020 struct i40iw_puda_buf *txbuf,
1021 u16 fpdu_len)
1022{
1023 struct i40iw_puda_buf *buf;
1024 u32 nextseqnum;
1025 u16 txoffset, bufoffset;
1026
1027 buf = i40iw_puda_get_listbuf(pbufl);
1028 nextseqnum = buf->seqnum + fpdu_len;
1029 txbuf->totallen = buf->hdrlen + fpdu_len;
1030 txbuf->data = (u8 *)txbuf->mem.va + buf->hdrlen;
1031 i40iw_ieq_setup_tx_buf(buf, txbuf);
1032
1033 txoffset = buf->hdrlen;
1034 bufoffset = (u16)(buf->data - (u8 *)buf->mem.va);
1035
1036 do {
1037 if (buf->datalen >= fpdu_len) {
1038 /* copied full fpdu */
1039 i40iw_ieq_copy_to_txbuf(buf, txbuf, bufoffset, txoffset, fpdu_len);
1040 buf->datalen -= fpdu_len;
1041 buf->data += fpdu_len;
1042 buf->seqnum = nextseqnum;
1043 break;
1044 }
1045 /* copy partial fpdu */
1046 i40iw_ieq_copy_to_txbuf(buf, txbuf, bufoffset, txoffset, buf->datalen);
1047 txoffset += buf->datalen;
1048 fpdu_len -= buf->datalen;
1049 i40iw_puda_ret_bufpool(ieq, buf);
1050 buf = i40iw_puda_get_listbuf(pbufl);
1051 bufoffset = (u16)(buf->data - (u8 *)buf->mem.va);
1052 } while (1);
1053
1054 /* last buffer on the list*/
1055 if (buf->datalen)
1056 list_add(&buf->list, rxlist);
1057 else
1058 i40iw_puda_ret_bufpool(ieq, buf);
1059}
1060
1061/**
1062 * i40iw_ieq_create_pbufl - create buffer list for single fpdu
1063 * @rxlist: resource list for receive ieq buffes
1064 * @pbufl: temp. list for buffers for fpddu
1065 * @buf: first receive buffer
1066 * @fpdu_len: total length of fpdu
1067 */
1068static enum i40iw_status_code i40iw_ieq_create_pbufl(
1069 struct i40iw_pfpdu *pfpdu,
1070 struct list_head *rxlist,
1071 struct list_head *pbufl,
1072 struct i40iw_puda_buf *buf,
1073 u16 fpdu_len)
1074{
1075 enum i40iw_status_code status = 0;
1076 struct i40iw_puda_buf *nextbuf;
1077 u32 nextseqnum;
1078 u16 plen = fpdu_len - buf->datalen;
1079 bool done = false;
1080
1081 nextseqnum = buf->seqnum + buf->datalen;
1082 do {
1083 nextbuf = i40iw_puda_get_listbuf(rxlist);
1084 if (!nextbuf) {
1085 status = I40IW_ERR_list_empty;
1086 break;
1087 }
1088 list_add_tail(&nextbuf->list, pbufl);
1089 if (nextbuf->seqnum != nextseqnum) {
1090 pfpdu->bad_seq_num++;
1091 status = I40IW_ERR_SEQ_NUM;
1092 break;
1093 }
1094 if (nextbuf->datalen >= plen) {
1095 done = true;
1096 } else {
1097 plen -= nextbuf->datalen;
1098 nextseqnum = nextbuf->seqnum + nextbuf->datalen;
1099 }
1100
1101 } while (!done);
1102
1103 return status;
1104}
1105
1106/**
1107 * i40iw_ieq_handle_partial - process partial fpdu buffer
1108 * @ieq: ieq resource
1109 * @pfpdu: partial management per user qp
1110 * @buf: receive buffer
1111 * @fpdu_len: fpdu len in the buffer
1112 */
1113static enum i40iw_status_code i40iw_ieq_handle_partial(struct i40iw_puda_rsrc *ieq,
1114 struct i40iw_pfpdu *pfpdu,
1115 struct i40iw_puda_buf *buf,
1116 u16 fpdu_len)
1117{
1118 enum i40iw_status_code status = 0;
1119 u8 *crcptr;
1120 u32 mpacrc;
1121 u32 seqnum = buf->seqnum;
1122 struct list_head pbufl; /* partial buffer list */
1123 struct i40iw_puda_buf *txbuf = NULL;
1124 struct list_head *rxlist = &pfpdu->rxlist;
1125
1126 INIT_LIST_HEAD(&pbufl);
1127 list_add(&buf->list, &pbufl);
1128
1129 status = i40iw_ieq_create_pbufl(pfpdu, rxlist, &pbufl, buf, fpdu_len);
1130 if (!status)
1131 goto error;
1132
1133 txbuf = i40iw_puda_get_bufpool(ieq);
1134 if (!txbuf) {
1135 pfpdu->no_tx_bufs++;
1136 status = I40IW_ERR_NO_TXBUFS;
1137 goto error;
1138 }
1139
1140 i40iw_ieq_compl_pfpdu(ieq, rxlist, &pbufl, txbuf, fpdu_len);
1141 i40iw_ieq_update_tcpip_info(txbuf, fpdu_len, seqnum);
1142 crcptr = txbuf->data + fpdu_len - 4;
1143 mpacrc = *(u32 *)crcptr;
1144 if (ieq->check_crc) {
1145 status = i40iw_ieq_check_mpacrc(ieq->hash_desc, txbuf->data,
1146 (fpdu_len - 4), mpacrc);
1147 if (status) {
1148 i40iw_debug(ieq->dev, I40IW_DEBUG_IEQ,
1149 "%s: error bad crc\n", __func__);
1150 goto error;
1151 }
1152 }
1153
1154 i40iw_debug_buf(ieq->dev, I40IW_DEBUG_IEQ, "IEQ TX BUFFER",
1155 txbuf->mem.va, txbuf->totallen);
1156 i40iw_puda_send_buf(ieq, txbuf);
1157 pfpdu->rcv_nxt = seqnum + fpdu_len;
1158 return status;
1159 error:
1160 while (!list_empty(&pbufl)) {
1161 buf = (struct i40iw_puda_buf *)(pbufl.prev);
1162 list_del(&buf->list);
1163 list_add(&buf->list, rxlist);
1164 }
1165 if (txbuf)
1166 i40iw_puda_ret_bufpool(ieq, txbuf);
1167 return status;
1168}
1169
1170/**
1171 * i40iw_ieq_process_buf - process buffer rcvd for ieq
1172 * @ieq: ieq resource
1173 * @pfpdu: partial management per user qp
1174 * @buf: receive buffer
1175 */
1176static enum i40iw_status_code i40iw_ieq_process_buf(struct i40iw_puda_rsrc *ieq,
1177 struct i40iw_pfpdu *pfpdu,
1178 struct i40iw_puda_buf *buf)
1179{
1180 u16 fpdu_len = 0;
1181 u16 datalen = buf->datalen;
1182 u8 *datap = buf->data;
1183 u8 *crcptr;
1184 u16 ioffset = 0;
1185 u32 mpacrc;
1186 u32 seqnum = buf->seqnum;
1187 u16 length = 0;
1188 u16 full = 0;
1189 bool partial = false;
1190 struct i40iw_puda_buf *txbuf;
1191 struct list_head *rxlist = &pfpdu->rxlist;
1192 enum i40iw_status_code ret = 0;
1193 enum i40iw_status_code status = 0;
1194
1195 ioffset = (u16)(buf->data - (u8 *)buf->mem.va);
1196 while (datalen) {
1197 fpdu_len = i40iw_ieq_get_fpdu_length(ntohs(*(u16 *)datap));
1198 if (fpdu_len > pfpdu->max_fpdu_data) {
1199 i40iw_debug(ieq->dev, I40IW_DEBUG_IEQ,
1200 "%s: error bad fpdu_len\n", __func__);
1201 status = I40IW_ERR_MPA_CRC;
1202 list_add(&buf->list, rxlist);
1203 return status;
1204 }
1205
1206 if (datalen < fpdu_len) {
1207 partial = true;
1208 break;
1209 }
1210 crcptr = datap + fpdu_len - 4;
1211 mpacrc = *(u32 *)crcptr;
1212 if (ieq->check_crc)
1213 ret = i40iw_ieq_check_mpacrc(ieq->hash_desc,
1214 datap, fpdu_len - 4, mpacrc);
1215 if (ret) {
1216 status = I40IW_ERR_MPA_CRC;
1217 list_add(&buf->list, rxlist);
1218 return status;
1219 }
1220 full++;
1221 pfpdu->fpdu_processed++;
1222 datap += fpdu_len;
1223 length += fpdu_len;
1224 datalen -= fpdu_len;
1225 }
1226 if (full) {
1227 /* copy full pdu's in the txbuf and send them out */
1228 txbuf = i40iw_puda_get_bufpool(ieq);
1229 if (!txbuf) {
1230 pfpdu->no_tx_bufs++;
1231 status = I40IW_ERR_NO_TXBUFS;
1232 list_add(&buf->list, rxlist);
1233 return status;
1234 }
1235 /* modify txbuf's buffer header */
1236 i40iw_ieq_setup_tx_buf(buf, txbuf);
1237 /* copy full fpdu's to new buffer */
1238 i40iw_ieq_copy_to_txbuf(buf, txbuf, ioffset, buf->hdrlen,
1239 length);
1240 txbuf->totallen = buf->hdrlen + length;
1241
1242 i40iw_ieq_update_tcpip_info(txbuf, length, buf->seqnum);
1243 i40iw_puda_send_buf(ieq, txbuf);
1244
1245 if (!datalen) {
1246 pfpdu->rcv_nxt = buf->seqnum + length;
1247 i40iw_puda_ret_bufpool(ieq, buf);
1248 return status;
1249 }
1250 buf->data = datap;
1251 buf->seqnum = seqnum + length;
1252 buf->datalen = datalen;
1253 pfpdu->rcv_nxt = buf->seqnum;
1254 }
1255 if (partial)
1256 status = i40iw_ieq_handle_partial(ieq, pfpdu, buf, fpdu_len);
1257
1258 return status;
1259}
1260
1261/**
1262 * i40iw_ieq_process_fpdus - process fpdu's buffers on its list
1263 * @qp: qp for which partial fpdus
1264 * @ieq: ieq resource
1265 */
1266static void i40iw_ieq_process_fpdus(struct i40iw_sc_qp *qp,
1267 struct i40iw_puda_rsrc *ieq)
1268{
1269 struct i40iw_pfpdu *pfpdu = &qp->pfpdu;
1270 struct list_head *rxlist = &pfpdu->rxlist;
1271 struct i40iw_puda_buf *buf;
1272 enum i40iw_status_code status;
1273
1274 do {
1275 if (list_empty(rxlist))
1276 break;
1277 buf = i40iw_puda_get_listbuf(rxlist);
1278 if (!buf) {
1279 i40iw_debug(ieq->dev, I40IW_DEBUG_IEQ,
1280 "%s: error no buf\n", __func__);
1281 break;
1282 }
1283 if (buf->seqnum != pfpdu->rcv_nxt) {
1284 /* This could be out of order or missing packet */
1285 pfpdu->out_of_order++;
1286 list_add(&buf->list, rxlist);
1287 break;
1288 }
1289 /* keep processing buffers from the head of the list */
1290 status = i40iw_ieq_process_buf(ieq, pfpdu, buf);
1291 if (status == I40IW_ERR_MPA_CRC) {
1292 pfpdu->mpa_crc_err = true;
1293 while (!list_empty(rxlist)) {
1294 buf = i40iw_puda_get_listbuf(rxlist);
1295 i40iw_puda_ret_bufpool(ieq, buf);
1296 pfpdu->crc_err++;
1297 }
1298 /* create CQP for AE */
1299 i40iw_ieq_mpa_crc_ae(ieq->dev, qp);
1300 }
1301 } while (!status);
1302}
1303
1304/**
1305 * i40iw_ieq_handle_exception - handle qp's exception
1306 * @ieq: ieq resource
1307 * @qp: qp receiving excpetion
1308 * @buf: receive buffer
1309 */
1310static void i40iw_ieq_handle_exception(struct i40iw_puda_rsrc *ieq,
1311 struct i40iw_sc_qp *qp,
1312 struct i40iw_puda_buf *buf)
1313{
1314 struct i40iw_puda_buf *tmpbuf = NULL;
1315 struct i40iw_pfpdu *pfpdu = &qp->pfpdu;
1316 u32 *hw_host_ctx = (u32 *)qp->hw_host_ctx;
1317 u32 rcv_wnd = hw_host_ctx[23];
1318 /* first partial seq # in q2 */
1319 u32 fps = qp->q2_buf[16];
1320 struct list_head *rxlist = &pfpdu->rxlist;
1321 struct list_head *plist;
1322
1323 pfpdu->total_ieq_bufs++;
1324
1325 if (pfpdu->mpa_crc_err) {
1326 pfpdu->crc_err++;
1327 goto error;
1328 }
1329 if (pfpdu->mode && (fps != pfpdu->fps)) {
1330 /* clean up qp as it is new partial sequence */
1331 i40iw_ieq_cleanup_qp(ieq->dev, qp);
1332 i40iw_debug(ieq->dev, I40IW_DEBUG_IEQ,
1333 "%s: restarting new partial\n", __func__);
1334 pfpdu->mode = false;
1335 }
1336
1337 if (!pfpdu->mode) {
1338 i40iw_debug_buf(ieq->dev, I40IW_DEBUG_IEQ, "Q2 BUFFER", (u64 *)qp->q2_buf, 128);
1339 /* First_Partial_Sequence_Number check */
1340 pfpdu->rcv_nxt = fps;
1341 pfpdu->fps = fps;
1342 pfpdu->mode = true;
1343 pfpdu->max_fpdu_data = ieq->mss;
1344 pfpdu->pmode_count++;
1345 INIT_LIST_HEAD(rxlist);
1346 i40iw_ieq_check_first_buf(buf, fps);
1347 }
1348
1349 if (!(rcv_wnd >= (buf->seqnum - pfpdu->rcv_nxt))) {
1350 pfpdu->bad_seq_num++;
1351 goto error;
1352 }
1353
1354 if (!list_empty(rxlist)) {
1355 tmpbuf = (struct i40iw_puda_buf *)rxlist->next;
1356 plist = &tmpbuf->list;
1357 while ((struct list_head *)tmpbuf != rxlist) {
1358 if ((int)(buf->seqnum - tmpbuf->seqnum) < 0)
1359 break;
1360 tmpbuf = (struct i40iw_puda_buf *)plist->next;
1361 }
1362 /* Insert buf before tmpbuf */
1363 list_add_tail(&buf->list, &tmpbuf->list);
1364 } else {
1365 list_add_tail(&buf->list, rxlist);
1366 }
1367 i40iw_ieq_process_fpdus(qp, ieq);
1368 return;
1369 error:
1370 i40iw_puda_ret_bufpool(ieq, buf);
1371}
1372
1373/**
1374 * i40iw_ieq_receive - received exception buffer
1375 * @dev: iwarp device
1376 * @buf: exception buffer received
1377 */
1378static void i40iw_ieq_receive(struct i40iw_sc_dev *dev,
1379 struct i40iw_puda_buf *buf)
1380{
1381 struct i40iw_puda_rsrc *ieq = dev->ieq;
1382 struct i40iw_sc_qp *qp = NULL;
1383 u32 wqe_idx = ieq->compl_rxwqe_idx;
1384
1385 qp = i40iw_ieq_get_qp(dev, buf);
1386 if (!qp) {
1387 ieq->stats_bad_qp_id++;
1388 i40iw_puda_ret_bufpool(ieq, buf);
1389 } else {
1390 i40iw_ieq_handle_exception(ieq, qp, buf);
1391 }
1392 /*
1393 * ieq->rx_wqe_idx is used by i40iw_puda_replenish_rq()
1394 * on which wqe_idx to start replenish rq
1395 */
1396 if (!ieq->rxq_invalid_cnt)
1397 ieq->rx_wqe_idx = wqe_idx;
1398 ieq->rxq_invalid_cnt++;
1399}
1400
1401/**
1402 * i40iw_ieq_tx_compl - put back after sending completed exception buffer
1403 * @dev: iwarp device
1404 * @sqwrid: pointer to puda buffer
1405 */
1406static void i40iw_ieq_tx_compl(struct i40iw_sc_dev *dev, void *sqwrid)
1407{
1408 struct i40iw_puda_rsrc *ieq = dev->ieq;
1409 struct i40iw_puda_buf *buf = (struct i40iw_puda_buf *)sqwrid;
1410
1411 i40iw_puda_ret_bufpool(ieq, buf);
1412 if (!list_empty(&ieq->txpend)) {
1413 buf = i40iw_puda_get_listbuf(&ieq->txpend);
1414 i40iw_puda_send_buf(ieq, buf);
1415 }
1416}
1417
1418/**
1419 * i40iw_ieq_cleanup_qp - qp is being destroyed
1420 * @dev: iwarp device
1421 * @qp: all pending fpdu buffers
1422 */
1423void i40iw_ieq_cleanup_qp(struct i40iw_sc_dev *dev, struct i40iw_sc_qp *qp)
1424{
1425 struct i40iw_puda_buf *buf;
1426 struct i40iw_pfpdu *pfpdu = &qp->pfpdu;
1427 struct list_head *rxlist = &pfpdu->rxlist;
1428 struct i40iw_puda_rsrc *ieq = dev->ieq;
1429
1430 if (!pfpdu->mode)
1431 return;
1432 while (!list_empty(rxlist)) {
1433 buf = i40iw_puda_get_listbuf(rxlist);
1434 i40iw_puda_ret_bufpool(ieq, buf);
1435 }
1436}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_puda.h b/drivers/infiniband/hw/i40iw/i40iw_puda.h
new file mode 100644
index 000000000000..52bf7826ce4e
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_puda.h
@@ -0,0 +1,183 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_PUDA_H
36#define I40IW_PUDA_H
37
38#define I40IW_IEQ_MPA_FRAMING 6
39
40struct i40iw_sc_dev;
41struct i40iw_sc_qp;
42struct i40iw_sc_cq;
43
44enum puda_resource_type {
45 I40IW_PUDA_RSRC_TYPE_ILQ = 1,
46 I40IW_PUDA_RSRC_TYPE_IEQ
47};
48
49enum puda_rsrc_complete {
50 PUDA_CQ_CREATED = 1,
51 PUDA_QP_CREATED,
52 PUDA_TX_COMPLETE,
53 PUDA_RX_COMPLETE,
54 PUDA_HASH_CRC_COMPLETE
55};
56
57struct i40iw_puda_completion_info {
58 struct i40iw_qp_uk *qp;
59 u8 q_type;
60 u8 vlan_valid;
61 u8 l3proto;
62 u8 l4proto;
63 u16 payload_len;
64 u32 compl_error; /* No_err=0, else major and minor err code */
65 u32 qp_id;
66 u32 wqe_idx;
67};
68
69struct i40iw_puda_send_info {
70 u64 paddr; /* Physical address */
71 u32 len;
72 u8 tcplen;
73 u8 maclen;
74 bool ipv4;
75 bool doloopback;
76 void *scratch;
77};
78
79struct i40iw_puda_buf {
80 struct list_head list; /* MUST be first entry */
81 struct i40iw_dma_mem mem; /* DMA memory for the buffer */
82 struct i40iw_puda_buf *next; /* for alloclist in rsrc struct */
83 struct i40iw_virt_mem buf_mem; /* Buffer memory for this buffer */
84 void *scratch;
85 u8 *iph;
86 u8 *tcph;
87 u8 *data;
88 u16 datalen;
89 u16 vlan_id;
90 u8 tcphlen; /* tcp length in bytes */
91 u8 maclen; /* mac length in bytes */
92 u32 totallen; /* machlen+iphlen+tcphlen+datalen */
93 atomic_t refcount;
94 u8 hdrlen;
95 bool ipv4;
96 u32 seqnum;
97};
98
99struct i40iw_puda_rsrc_info {
100 enum puda_resource_type type; /* ILQ or IEQ */
101 u32 count;
102 u16 pd_id;
103 u32 cq_id;
104 u32 qp_id;
105 u32 sq_size;
106 u32 rq_size;
107 u16 buf_size;
108 u16 mss;
109 u32 tx_buf_cnt; /* total bufs allocated will be rq_size + tx_buf_cnt */
110 void (*receive)(struct i40iw_sc_dev *, struct i40iw_puda_buf *);
111 void (*xmit_complete)(struct i40iw_sc_dev *, void *);
112};
113
114struct i40iw_puda_rsrc {
115 struct i40iw_sc_cq cq;
116 struct i40iw_sc_qp qp;
117 struct i40iw_sc_pd sc_pd;
118 struct i40iw_sc_dev *dev;
119 struct i40iw_dma_mem cqmem;
120 struct i40iw_dma_mem qpmem;
121 struct i40iw_virt_mem ilq_mem;
122 enum puda_rsrc_complete completion;
123 enum puda_resource_type type;
124 u16 buf_size; /*buffer must be max datalen + tcpip hdr + mac */
125 u16 mss;
126 u32 cq_id;
127 u32 qp_id;
128 u32 sq_size;
129 u32 rq_size;
130 u32 cq_size;
131 struct i40iw_sq_uk_wr_trk_info *sq_wrtrk_array;
132 u64 *rq_wrid_array;
133 u32 compl_rxwqe_idx;
134 u32 rx_wqe_idx;
135 u32 rxq_invalid_cnt;
136 u32 tx_wqe_avail_cnt;
137 bool check_crc;
138 struct shash_desc *hash_desc;
139 struct list_head txpend;
140 struct list_head bufpool; /* free buffers pool list for recv and xmit */
141 u32 alloc_buf_count;
142 u32 avail_buf_count; /* snapshot of currently available buffers */
143 spinlock_t bufpool_lock;
144 struct i40iw_puda_buf *alloclist;
145 void (*receive)(struct i40iw_sc_dev *, struct i40iw_puda_buf *);
146 void (*xmit_complete)(struct i40iw_sc_dev *, void *);
147 /* puda stats */
148 u64 stats_buf_alloc_fail;
149 u64 stats_pkt_rcvd;
150 u64 stats_pkt_sent;
151 u64 stats_rcvd_pkt_err;
152 u64 stats_sent_pkt_q;
153 u64 stats_bad_qp_id;
154};
155
156struct i40iw_puda_buf *i40iw_puda_get_bufpool(struct i40iw_puda_rsrc *rsrc);
157void i40iw_puda_ret_bufpool(struct i40iw_puda_rsrc *rsrc,
158 struct i40iw_puda_buf *buf);
159void i40iw_puda_send_buf(struct i40iw_puda_rsrc *rsrc,
160 struct i40iw_puda_buf *buf);
161enum i40iw_status_code i40iw_puda_send(struct i40iw_sc_qp *qp,
162 struct i40iw_puda_send_info *info);
163enum i40iw_status_code i40iw_puda_create_rsrc(struct i40iw_sc_dev *dev,
164 struct i40iw_puda_rsrc_info *info);
165void i40iw_puda_dele_resources(struct i40iw_sc_dev *dev,
166 enum puda_resource_type type,
167 bool reset);
168enum i40iw_status_code i40iw_puda_poll_completion(struct i40iw_sc_dev *dev,
169 struct i40iw_sc_cq *cq, u32 *compl_err);
170void i40iw_ieq_cleanup_qp(struct i40iw_sc_dev *dev, struct i40iw_sc_qp *qp);
171
172struct i40iw_sc_qp *i40iw_ieq_get_qp(struct i40iw_sc_dev *dev,
173 struct i40iw_puda_buf *buf);
174enum i40iw_status_code i40iw_puda_get_tcpip_info(struct i40iw_puda_completion_info *info,
175 struct i40iw_puda_buf *buf);
176enum i40iw_status_code i40iw_ieq_check_mpacrc(struct shash_desc *desc,
177 void *addr, u32 length, u32 value);
178enum i40iw_status_code i40iw_init_hash_desc(struct shash_desc **desc);
179void i40iw_ieq_mpa_crc_ae(struct i40iw_sc_dev *dev, struct i40iw_sc_qp *qp);
180void i40iw_free_hash_desc(struct shash_desc *desc);
181void i40iw_ieq_update_tcpip_info(struct i40iw_puda_buf *buf, u16 length,
182 u32 seqnum);
183#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_register.h b/drivers/infiniband/hw/i40iw/i40iw_register.h
new file mode 100644
index 000000000000..57768184e251
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_register.h
@@ -0,0 +1,1030 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_REGISTER_H
36#define I40IW_REGISTER_H
37
38#define I40E_GLGEN_STAT 0x000B612C /* Reset: POR */
39
40#define I40E_PFHMC_PDINV 0x000C0300 /* Reset: PFR */
41#define I40E_PFHMC_PDINV_PMSDIDX_SHIFT 0
42#define I40E_PFHMC_PDINV_PMSDIDX_MASK (0xFFF << I40E_PFHMC_PDINV_PMSDIDX_SHIFT)
43#define I40E_PFHMC_PDINV_PMPDIDX_SHIFT 16
44#define I40E_PFHMC_PDINV_PMPDIDX_MASK (0x1FF << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)
45#define I40E_PFHMC_SDCMD_PMSDWR_SHIFT 31
46#define I40E_PFHMC_SDCMD_PMSDWR_MASK (0x1 << I40E_PFHMC_SDCMD_PMSDWR_SHIFT)
47#define I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT 0
48#define I40E_PFHMC_SDDATALOW_PMSDVALID_MASK (0x1 << I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT)
49#define I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT 1
50#define I40E_PFHMC_SDDATALOW_PMSDTYPE_MASK (0x1 << I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT)
51#define I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT 2
52#define I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_MASK (0x3FF << I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT)
53
54#define I40E_PFINT_DYN_CTLN(_INTPF) (0x00034800 + ((_INTPF) * 4)) /* _i=0...511 */ /* Reset: PFR */
55#define I40E_PFINT_DYN_CTLN_INTENA_SHIFT 0
56#define I40E_PFINT_DYN_CTLN_INTENA_MASK (0x1 << I40E_PFINT_DYN_CTLN_INTENA_SHIFT)
57#define I40E_PFINT_DYN_CTLN_CLEARPBA_SHIFT 1
58#define I40E_PFINT_DYN_CTLN_CLEARPBA_MASK (0x1 << I40E_PFINT_DYN_CTLN_CLEARPBA_SHIFT)
59#define I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT 3
60#define I40E_PFINT_DYN_CTLN_ITR_INDX_MASK (0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT)
61
62#define I40E_VFINT_DYN_CTLN1(_INTVF) (0x00003800 + ((_INTVF) * 4)) /* _i=0...15 */ /* Reset: VFR */
63#define I40E_GLHMC_VFPDINV(_i) (0x000C8300 + ((_i) * 4)) /* _i=0...31 */ /* Reset: CORER */
64
65#define I40E_PFHMC_PDINV_PMSDPARTSEL_SHIFT 15
66#define I40E_PFHMC_PDINV_PMSDPARTSEL_MASK (0x1 << I40E_PFHMC_PDINV_PMSDPARTSEL_SHIFT)
67#define I40E_GLPCI_LBARCTRL 0x000BE484 /* Reset: POR */
68#define I40E_GLPCI_LBARCTRL_PE_DB_SIZE_SHIFT 4
69#define I40E_GLPCI_LBARCTRL_PE_DB_SIZE_MASK (0x3 << I40E_GLPCI_LBARCTRL_PE_DB_SIZE_SHIFT)
70#define I40E_GLPCI_DREVID 0x0009C480 /* Reset: PCIR */
71#define I40E_GLPCI_DREVID_DEFAULT_REVID_SHIFT 0
72#define I40E_GLPCI_DREVID_DEFAULT_REVID_MASK 0xFF
73
74#define I40E_PFPE_AEQALLOC 0x00131180 /* Reset: PFR */
75#define I40E_PFPE_AEQALLOC_AECOUNT_SHIFT 0
76#define I40E_PFPE_AEQALLOC_AECOUNT_MASK (0xFFFFFFFF << I40E_PFPE_AEQALLOC_AECOUNT_SHIFT)
77#define I40E_PFPE_CCQPHIGH 0x00008200 /* Reset: PFR */
78#define I40E_PFPE_CCQPHIGH_PECCQPHIGH_SHIFT 0
79#define I40E_PFPE_CCQPHIGH_PECCQPHIGH_MASK (0xFFFFFFFF << I40E_PFPE_CCQPHIGH_PECCQPHIGH_SHIFT)
80#define I40E_PFPE_CCQPLOW 0x00008180 /* Reset: PFR */
81#define I40E_PFPE_CCQPLOW_PECCQPLOW_SHIFT 0
82#define I40E_PFPE_CCQPLOW_PECCQPLOW_MASK (0xFFFFFFFF << I40E_PFPE_CCQPLOW_PECCQPLOW_SHIFT)
83#define I40E_PFPE_CCQPSTATUS 0x00008100 /* Reset: PFR */
84#define I40E_PFPE_CCQPSTATUS_CCQP_DONE_SHIFT 0
85#define I40E_PFPE_CCQPSTATUS_CCQP_DONE_MASK (0x1 << I40E_PFPE_CCQPSTATUS_CCQP_DONE_SHIFT)
86#define I40E_PFPE_CCQPSTATUS_HMC_PROFILE_SHIFT 4
87#define I40E_PFPE_CCQPSTATUS_HMC_PROFILE_MASK (0x7 << I40E_PFPE_CCQPSTATUS_HMC_PROFILE_SHIFT)
88#define I40E_PFPE_CCQPSTATUS_RDMA_EN_VFS_SHIFT 16
89#define I40E_PFPE_CCQPSTATUS_RDMA_EN_VFS_MASK (0x3F << I40E_PFPE_CCQPSTATUS_RDMA_EN_VFS_SHIFT)
90#define I40E_PFPE_CCQPSTATUS_CCQP_ERR_SHIFT 31
91#define I40E_PFPE_CCQPSTATUS_CCQP_ERR_MASK (0x1 << I40E_PFPE_CCQPSTATUS_CCQP_ERR_SHIFT)
92#define I40E_PFPE_CQACK 0x00131100 /* Reset: PFR */
93#define I40E_PFPE_CQACK_PECQID_SHIFT 0
94#define I40E_PFPE_CQACK_PECQID_MASK (0x1FFFF << I40E_PFPE_CQACK_PECQID_SHIFT)
95#define I40E_PFPE_CQARM 0x00131080 /* Reset: PFR */
96#define I40E_PFPE_CQARM_PECQID_SHIFT 0
97#define I40E_PFPE_CQARM_PECQID_MASK (0x1FFFF << I40E_PFPE_CQARM_PECQID_SHIFT)
98#define I40E_PFPE_CQPDB 0x00008000 /* Reset: PFR */
99#define I40E_PFPE_CQPDB_WQHEAD_SHIFT 0
100#define I40E_PFPE_CQPDB_WQHEAD_MASK (0x7FF << I40E_PFPE_CQPDB_WQHEAD_SHIFT)
101#define I40E_PFPE_CQPERRCODES 0x00008880 /* Reset: PFR */
102#define I40E_PFPE_CQPERRCODES_CQP_MINOR_CODE_SHIFT 0
103#define I40E_PFPE_CQPERRCODES_CQP_MINOR_CODE_MASK (0xFFFF << I40E_PFPE_CQPERRCODES_CQP_MINOR_CODE_SHIFT)
104#define I40E_PFPE_CQPERRCODES_CQP_MAJOR_CODE_SHIFT 16
105#define I40E_PFPE_CQPERRCODES_CQP_MAJOR_CODE_MASK (0xFFFF << I40E_PFPE_CQPERRCODES_CQP_MAJOR_CODE_SHIFT)
106#define I40E_PFPE_CQPTAIL 0x00008080 /* Reset: PFR */
107#define I40E_PFPE_CQPTAIL_WQTAIL_SHIFT 0
108#define I40E_PFPE_CQPTAIL_WQTAIL_MASK (0x7FF << I40E_PFPE_CQPTAIL_WQTAIL_SHIFT)
109#define I40E_PFPE_CQPTAIL_CQP_OP_ERR_SHIFT 31
110#define I40E_PFPE_CQPTAIL_CQP_OP_ERR_MASK (0x1 << I40E_PFPE_CQPTAIL_CQP_OP_ERR_SHIFT)
111#define I40E_PFPE_FLMQ1ALLOCERR 0x00008980 /* Reset: PFR */
112#define I40E_PFPE_FLMQ1ALLOCERR_ERROR_COUNT_SHIFT 0
113#define I40E_PFPE_FLMQ1ALLOCERR_ERROR_COUNT_MASK (0xFFFF << I40E_PFPE_FLMQ1ALLOCERR_ERROR_COUNT_SHIFT)
114#define I40E_PFPE_FLMXMITALLOCERR 0x00008900 /* Reset: PFR */
115#define I40E_PFPE_FLMXMITALLOCERR_ERROR_COUNT_SHIFT 0
116#define I40E_PFPE_FLMXMITALLOCERR_ERROR_COUNT_MASK (0xFFFF << I40E_PFPE_FLMXMITALLOCERR_ERROR_COUNT_SHIFT)
117#define I40E_PFPE_IPCONFIG0 0x00008280 /* Reset: PFR */
118#define I40E_PFPE_IPCONFIG0_PEIPID_SHIFT 0
119#define I40E_PFPE_IPCONFIG0_PEIPID_MASK (0xFFFF << I40E_PFPE_IPCONFIG0_PEIPID_SHIFT)
120#define I40E_PFPE_IPCONFIG0_USEENTIREIDRANGE_SHIFT 16
121#define I40E_PFPE_IPCONFIG0_USEENTIREIDRANGE_MASK (0x1 << I40E_PFPE_IPCONFIG0_USEENTIREIDRANGE_SHIFT)
122#define I40E_PFPE_MRTEIDXMASK 0x00008600 /* Reset: PFR */
123#define I40E_PFPE_MRTEIDXMASK_MRTEIDXMASKBITS_SHIFT 0
124#define I40E_PFPE_MRTEIDXMASK_MRTEIDXMASKBITS_MASK (0x1F << I40E_PFPE_MRTEIDXMASK_MRTEIDXMASKBITS_SHIFT)
125#define I40E_PFPE_RCVUNEXPECTEDERROR 0x00008680 /* Reset: PFR */
126#define I40E_PFPE_RCVUNEXPECTEDERROR_TCP_RX_UNEXP_ERR_SHIFT 0
127#define I40E_PFPE_RCVUNEXPECTEDERROR_TCP_RX_UNEXP_ERR_MASK (0xFFFFFF << I40E_PFPE_RCVUNEXPECTEDERROR_TCP_RX_UNEXP_ERR_SHIFT)
128#define I40E_PFPE_TCPNOWTIMER 0x00008580 /* Reset: PFR */
129#define I40E_PFPE_TCPNOWTIMER_TCP_NOW_SHIFT 0
130#define I40E_PFPE_TCPNOWTIMER_TCP_NOW_MASK (0xFFFFFFFF << I40E_PFPE_TCPNOWTIMER_TCP_NOW_SHIFT)
131
132#define I40E_PFPE_WQEALLOC 0x00138C00 /* Reset: PFR */
133#define I40E_PFPE_WQEALLOC_PEQPID_SHIFT 0
134#define I40E_PFPE_WQEALLOC_PEQPID_MASK (0x3FFFF << I40E_PFPE_WQEALLOC_PEQPID_SHIFT)
135#define I40E_PFPE_WQEALLOC_WQE_DESC_INDEX_SHIFT 20
136#define I40E_PFPE_WQEALLOC_WQE_DESC_INDEX_MASK (0xFFF << I40E_PFPE_WQEALLOC_WQE_DESC_INDEX_SHIFT)
137
138#define I40E_VFPE_AEQALLOC(_VF) (0x00130C00 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
139#define I40E_VFPE_AEQALLOC_MAX_INDEX 127
140#define I40E_VFPE_AEQALLOC_AECOUNT_SHIFT 0
141#define I40E_VFPE_AEQALLOC_AECOUNT_MASK (0xFFFFFFFF << I40E_VFPE_AEQALLOC_AECOUNT_SHIFT)
142#define I40E_VFPE_CCQPHIGH(_VF) (0x00001000 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
143#define I40E_VFPE_CCQPHIGH_MAX_INDEX 127
144#define I40E_VFPE_CCQPHIGH_PECCQPHIGH_SHIFT 0
145#define I40E_VFPE_CCQPHIGH_PECCQPHIGH_MASK (0xFFFFFFFF << I40E_VFPE_CCQPHIGH_PECCQPHIGH_SHIFT)
146#define I40E_VFPE_CCQPLOW(_VF) (0x00000C00 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
147#define I40E_VFPE_CCQPLOW_MAX_INDEX 127
148#define I40E_VFPE_CCQPLOW_PECCQPLOW_SHIFT 0
149#define I40E_VFPE_CCQPLOW_PECCQPLOW_MASK (0xFFFFFFFF << I40E_VFPE_CCQPLOW_PECCQPLOW_SHIFT)
150#define I40E_VFPE_CCQPSTATUS(_VF) (0x00000800 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
151#define I40E_VFPE_CCQPSTATUS_MAX_INDEX 127
152#define I40E_VFPE_CCQPSTATUS_CCQP_DONE_SHIFT 0
153#define I40E_VFPE_CCQPSTATUS_CCQP_DONE_MASK (0x1 << I40E_VFPE_CCQPSTATUS_CCQP_DONE_SHIFT)
154#define I40E_VFPE_CCQPSTATUS_HMC_PROFILE_SHIFT 4
155#define I40E_VFPE_CCQPSTATUS_HMC_PROFILE_MASK (0x7 << I40E_VFPE_CCQPSTATUS_HMC_PROFILE_SHIFT)
156#define I40E_VFPE_CCQPSTATUS_RDMA_EN_VFS_SHIFT 16
157#define I40E_VFPE_CCQPSTATUS_RDMA_EN_VFS_MASK (0x3F << I40E_VFPE_CCQPSTATUS_RDMA_EN_VFS_SHIFT)
158#define I40E_VFPE_CCQPSTATUS_CCQP_ERR_SHIFT 31
159#define I40E_VFPE_CCQPSTATUS_CCQP_ERR_MASK (0x1 << I40E_VFPE_CCQPSTATUS_CCQP_ERR_SHIFT)
160#define I40E_VFPE_CQACK(_VF) (0x00130800 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
161#define I40E_VFPE_CQACK_MAX_INDEX 127
162#define I40E_VFPE_CQACK_PECQID_SHIFT 0
163#define I40E_VFPE_CQACK_PECQID_MASK (0x1FFFF << I40E_VFPE_CQACK_PECQID_SHIFT)
164#define I40E_VFPE_CQARM(_VF) (0x00130400 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
165#define I40E_VFPE_CQARM_MAX_INDEX 127
166#define I40E_VFPE_CQARM_PECQID_SHIFT 0
167#define I40E_VFPE_CQARM_PECQID_MASK (0x1FFFF << I40E_VFPE_CQARM_PECQID_SHIFT)
168#define I40E_VFPE_CQPDB(_VF) (0x00000000 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
169#define I40E_VFPE_CQPDB_MAX_INDEX 127
170#define I40E_VFPE_CQPDB_WQHEAD_SHIFT 0
171#define I40E_VFPE_CQPDB_WQHEAD_MASK (0x7FF << I40E_VFPE_CQPDB_WQHEAD_SHIFT)
172#define I40E_VFPE_CQPERRCODES(_VF) (0x00001800 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
173#define I40E_VFPE_CQPERRCODES_MAX_INDEX 127
174#define I40E_VFPE_CQPERRCODES_CQP_MINOR_CODE_SHIFT 0
175#define I40E_VFPE_CQPERRCODES_CQP_MINOR_CODE_MASK (0xFFFF << I40E_VFPE_CQPERRCODES_CQP_MINOR_CODE_SHIFT)
176#define I40E_VFPE_CQPERRCODES_CQP_MAJOR_CODE_SHIFT 16
177#define I40E_VFPE_CQPERRCODES_CQP_MAJOR_CODE_MASK (0xFFFF << I40E_VFPE_CQPERRCODES_CQP_MAJOR_CODE_SHIFT)
178#define I40E_VFPE_CQPTAIL(_VF) (0x00000400 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
179#define I40E_VFPE_CQPTAIL_MAX_INDEX 127
180#define I40E_VFPE_CQPTAIL_WQTAIL_SHIFT 0
181#define I40E_VFPE_CQPTAIL_WQTAIL_MASK (0x7FF << I40E_VFPE_CQPTAIL_WQTAIL_SHIFT)
182#define I40E_VFPE_CQPTAIL_CQP_OP_ERR_SHIFT 31
183#define I40E_VFPE_CQPTAIL_CQP_OP_ERR_MASK (0x1 << I40E_VFPE_CQPTAIL_CQP_OP_ERR_SHIFT)
184#define I40E_VFPE_IPCONFIG0(_VF) (0x00001400 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
185#define I40E_VFPE_IPCONFIG0_MAX_INDEX 127
186#define I40E_VFPE_IPCONFIG0_PEIPID_SHIFT 0
187#define I40E_VFPE_IPCONFIG0_PEIPID_MASK (0xFFFF << I40E_VFPE_IPCONFIG0_PEIPID_SHIFT)
188#define I40E_VFPE_IPCONFIG0_USEENTIREIDRANGE_SHIFT 16
189#define I40E_VFPE_IPCONFIG0_USEENTIREIDRANGE_MASK (0x1 << I40E_VFPE_IPCONFIG0_USEENTIREIDRANGE_SHIFT)
190#define I40E_VFPE_MRTEIDXMASK(_VF) (0x00003000 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
191#define I40E_VFPE_MRTEIDXMASK_MAX_INDEX 127
192#define I40E_VFPE_MRTEIDXMASK_MRTEIDXMASKBITS_SHIFT 0
193#define I40E_VFPE_MRTEIDXMASK_MRTEIDXMASKBITS_MASK (0x1F << I40E_VFPE_MRTEIDXMASK_MRTEIDXMASKBITS_SHIFT)
194#define I40E_VFPE_RCVUNEXPECTEDERROR(_VF) (0x00003400 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
195#define I40E_VFPE_RCVUNEXPECTEDERROR_MAX_INDEX 127
196#define I40E_VFPE_RCVUNEXPECTEDERROR_TCP_RX_UNEXP_ERR_SHIFT 0
197#define I40E_VFPE_RCVUNEXPECTEDERROR_TCP_RX_UNEXP_ERR_MASK (0xFFFFFF << I40E_VFPE_RCVUNEXPECTEDERROR_TCP_RX_UNEXP_ERR_SHIFT)
198#define I40E_VFPE_TCPNOWTIMER(_VF) (0x00002C00 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
199#define I40E_VFPE_TCPNOWTIMER_MAX_INDEX 127
200#define I40E_VFPE_TCPNOWTIMER_TCP_NOW_SHIFT 0
201#define I40E_VFPE_TCPNOWTIMER_TCP_NOW_MASK (0xFFFFFFFF << I40E_VFPE_TCPNOWTIMER_TCP_NOW_SHIFT)
202#define I40E_VFPE_WQEALLOC(_VF) (0x00138000 + ((_VF) * 4)) /* _i=0...127 */ /* Reset: VFR */
203#define I40E_VFPE_WQEALLOC_MAX_INDEX 127
204#define I40E_VFPE_WQEALLOC_PEQPID_SHIFT 0
205#define I40E_VFPE_WQEALLOC_PEQPID_MASK (0x3FFFF << I40E_VFPE_WQEALLOC_PEQPID_SHIFT)
206#define I40E_VFPE_WQEALLOC_WQE_DESC_INDEX_SHIFT 20
207#define I40E_VFPE_WQEALLOC_WQE_DESC_INDEX_MASK (0xFFF << I40E_VFPE_WQEALLOC_WQE_DESC_INDEX_SHIFT)
208
209#define I40E_GLPE_CPUSTATUS0 0x0000D040 /* Reset: PE_CORER */
210#define I40E_GLPE_CPUSTATUS0_PECPUSTATUS0_SHIFT 0
211#define I40E_GLPE_CPUSTATUS0_PECPUSTATUS0_MASK (0xFFFFFFFF << I40E_GLPE_CPUSTATUS0_PECPUSTATUS0_SHIFT)
212#define I40E_GLPE_CPUSTATUS1 0x0000D044 /* Reset: PE_CORER */
213#define I40E_GLPE_CPUSTATUS1_PECPUSTATUS1_SHIFT 0
214#define I40E_GLPE_CPUSTATUS1_PECPUSTATUS1_MASK (0xFFFFFFFF << I40E_GLPE_CPUSTATUS1_PECPUSTATUS1_SHIFT)
215#define I40E_GLPE_CPUSTATUS2 0x0000D048 /* Reset: PE_CORER */
216#define I40E_GLPE_CPUSTATUS2_PECPUSTATUS2_SHIFT 0
217#define I40E_GLPE_CPUSTATUS2_PECPUSTATUS2_MASK (0xFFFFFFFF << I40E_GLPE_CPUSTATUS2_PECPUSTATUS2_SHIFT)
218#define I40E_GLPE_CPUTRIG0 0x0000D060 /* Reset: PE_CORER */
219#define I40E_GLPE_CPUTRIG0_PECPUTRIG0_SHIFT 0
220#define I40E_GLPE_CPUTRIG0_PECPUTRIG0_MASK (0xFFFF << I40E_GLPE_CPUTRIG0_PECPUTRIG0_SHIFT)
221#define I40E_GLPE_CPUTRIG0_TEPREQUEST0_SHIFT 17
222#define I40E_GLPE_CPUTRIG0_TEPREQUEST0_MASK (0x1 << I40E_GLPE_CPUTRIG0_TEPREQUEST0_SHIFT)
223#define I40E_GLPE_CPUTRIG0_OOPREQUEST0_SHIFT 18
224#define I40E_GLPE_CPUTRIG0_OOPREQUEST0_MASK (0x1 << I40E_GLPE_CPUTRIG0_OOPREQUEST0_SHIFT)
225#define I40E_GLPE_DUAL40_RUPM 0x0000DA04 /* Reset: PE_CORER */
226#define I40E_GLPE_DUAL40_RUPM_DUAL_40G_MODE_SHIFT 0
227#define I40E_GLPE_DUAL40_RUPM_DUAL_40G_MODE_MASK (0x1 << I40E_GLPE_DUAL40_RUPM_DUAL_40G_MODE_SHIFT)
228#define I40E_GLPE_PFAEQEDROPCNT(_i) (0x00131440 + ((_i) * 4)) /* _i=0...15 */ /* Reset: CORER */
229#define I40E_GLPE_PFAEQEDROPCNT_MAX_INDEX 15
230#define I40E_GLPE_PFAEQEDROPCNT_AEQEDROPCNT_SHIFT 0
231#define I40E_GLPE_PFAEQEDROPCNT_AEQEDROPCNT_MASK (0xFFFF << I40E_GLPE_PFAEQEDROPCNT_AEQEDROPCNT_SHIFT)
232#define I40E_GLPE_PFCEQEDROPCNT(_i) (0x001313C0 + ((_i) * 4)) /* _i=0...15 */ /* Reset: CORER */
233#define I40E_GLPE_PFCEQEDROPCNT_MAX_INDEX 15
234#define I40E_GLPE_PFCEQEDROPCNT_CEQEDROPCNT_SHIFT 0
235#define I40E_GLPE_PFCEQEDROPCNT_CEQEDROPCNT_MASK (0xFFFF << I40E_GLPE_PFCEQEDROPCNT_CEQEDROPCNT_SHIFT)
236#define I40E_GLPE_PFCQEDROPCNT(_i) (0x00131340 + ((_i) * 4)) /* _i=0...15 */ /* Reset: CORER */
237#define I40E_GLPE_PFCQEDROPCNT_MAX_INDEX 15
238#define I40E_GLPE_PFCQEDROPCNT_CQEDROPCNT_SHIFT 0
239#define I40E_GLPE_PFCQEDROPCNT_CQEDROPCNT_MASK (0xFFFF << I40E_GLPE_PFCQEDROPCNT_CQEDROPCNT_SHIFT)
240#define I40E_GLPE_RUPM_CQPPOOL 0x0000DACC /* Reset: PE_CORER */
241#define I40E_GLPE_RUPM_CQPPOOL_CQPSPADS_SHIFT 0
242#define I40E_GLPE_RUPM_CQPPOOL_CQPSPADS_MASK (0xFF << I40E_GLPE_RUPM_CQPPOOL_CQPSPADS_SHIFT)
243#define I40E_GLPE_RUPM_FLRPOOL 0x0000DAC4 /* Reset: PE_CORER */
244#define I40E_GLPE_RUPM_FLRPOOL_FLRSPADS_SHIFT 0
245#define I40E_GLPE_RUPM_FLRPOOL_FLRSPADS_MASK (0xFF << I40E_GLPE_RUPM_FLRPOOL_FLRSPADS_SHIFT)
246#define I40E_GLPE_RUPM_GCTL 0x0000DA00 /* Reset: PE_CORER */
247#define I40E_GLPE_RUPM_GCTL_ALLOFFTH_SHIFT 0
248#define I40E_GLPE_RUPM_GCTL_ALLOFFTH_MASK (0xFF << I40E_GLPE_RUPM_GCTL_ALLOFFTH_SHIFT)
249#define I40E_GLPE_RUPM_GCTL_RUPM_P0_DIS_SHIFT 26
250#define I40E_GLPE_RUPM_GCTL_RUPM_P0_DIS_MASK (0x1 << I40E_GLPE_RUPM_GCTL_RUPM_P0_DIS_SHIFT)
251#define I40E_GLPE_RUPM_GCTL_RUPM_P1_DIS_SHIFT 27
252#define I40E_GLPE_RUPM_GCTL_RUPM_P1_DIS_MASK (0x1 << I40E_GLPE_RUPM_GCTL_RUPM_P1_DIS_SHIFT)
253#define I40E_GLPE_RUPM_GCTL_RUPM_P2_DIS_SHIFT 28
254#define I40E_GLPE_RUPM_GCTL_RUPM_P2_DIS_MASK (0x1 << I40E_GLPE_RUPM_GCTL_RUPM_P2_DIS_SHIFT)
255#define I40E_GLPE_RUPM_GCTL_RUPM_P3_DIS_SHIFT 29
256#define I40E_GLPE_RUPM_GCTL_RUPM_P3_DIS_MASK (0x1 << I40E_GLPE_RUPM_GCTL_RUPM_P3_DIS_SHIFT)
257#define I40E_GLPE_RUPM_GCTL_RUPM_DIS_SHIFT 30
258#define I40E_GLPE_RUPM_GCTL_RUPM_DIS_MASK (0x1 << I40E_GLPE_RUPM_GCTL_RUPM_DIS_SHIFT)
259#define I40E_GLPE_RUPM_GCTL_SWLB_MODE_SHIFT 31
260#define I40E_GLPE_RUPM_GCTL_SWLB_MODE_MASK (0x1 << I40E_GLPE_RUPM_GCTL_SWLB_MODE_SHIFT)
261#define I40E_GLPE_RUPM_PTXPOOL 0x0000DAC8 /* Reset: PE_CORER */
262#define I40E_GLPE_RUPM_PTXPOOL_PTXSPADS_SHIFT 0
263#define I40E_GLPE_RUPM_PTXPOOL_PTXSPADS_MASK (0xFF << I40E_GLPE_RUPM_PTXPOOL_PTXSPADS_SHIFT)
264#define I40E_GLPE_RUPM_PUSHPOOL 0x0000DAC0 /* Reset: PE_CORER */
265#define I40E_GLPE_RUPM_PUSHPOOL_PUSHSPADS_SHIFT 0
266#define I40E_GLPE_RUPM_PUSHPOOL_PUSHSPADS_MASK (0xFF << I40E_GLPE_RUPM_PUSHPOOL_PUSHSPADS_SHIFT)
267#define I40E_GLPE_RUPM_TXHOST_EN 0x0000DA08 /* Reset: PE_CORER */
268#define I40E_GLPE_RUPM_TXHOST_EN_TXHOST_EN_SHIFT 0
269#define I40E_GLPE_RUPM_TXHOST_EN_TXHOST_EN_MASK (0x1 << I40E_GLPE_RUPM_TXHOST_EN_TXHOST_EN_SHIFT)
270#define I40E_GLPE_VFAEQEDROPCNT(_i) (0x00132540 + ((_i) * 4)) /* _i=0...31 */ /* Reset: CORER */
271#define I40E_GLPE_VFAEQEDROPCNT_MAX_INDEX 31
272#define I40E_GLPE_VFAEQEDROPCNT_AEQEDROPCNT_SHIFT 0
273#define I40E_GLPE_VFAEQEDROPCNT_AEQEDROPCNT_MASK (0xFFFF << I40E_GLPE_VFAEQEDROPCNT_AEQEDROPCNT_SHIFT)
274#define I40E_GLPE_VFCEQEDROPCNT(_i) (0x00132440 + ((_i) * 4)) /* _i=0...31 */ /* Reset: CORER */
275#define I40E_GLPE_VFCEQEDROPCNT_MAX_INDEX 31
276#define I40E_GLPE_VFCEQEDROPCNT_CEQEDROPCNT_SHIFT 0
277#define I40E_GLPE_VFCEQEDROPCNT_CEQEDROPCNT_MASK (0xFFFF << I40E_GLPE_VFCEQEDROPCNT_CEQEDROPCNT_SHIFT)
278#define I40E_GLPE_VFCQEDROPCNT(_i) (0x00132340 + ((_i) * 4)) /* _i=0...31 */ /* Reset: CORER */
279#define I40E_GLPE_VFCQEDROPCNT_MAX_INDEX 31
280#define I40E_GLPE_VFCQEDROPCNT_CQEDROPCNT_SHIFT 0
281#define I40E_GLPE_VFCQEDROPCNT_CQEDROPCNT_MASK (0xFFFF << I40E_GLPE_VFCQEDROPCNT_CQEDROPCNT_SHIFT)
282#define I40E_GLPE_VFFLMOBJCTRL(_i) (0x0000D400 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
283#define I40E_GLPE_VFFLMOBJCTRL_MAX_INDEX 31
284#define I40E_GLPE_VFFLMOBJCTRL_XMIT_BLOCKSIZE_SHIFT 0
285#define I40E_GLPE_VFFLMOBJCTRL_XMIT_BLOCKSIZE_MASK (0x7 << I40E_GLPE_VFFLMOBJCTRL_XMIT_BLOCKSIZE_SHIFT)
286#define I40E_GLPE_VFFLMOBJCTRL_Q1_BLOCKSIZE_SHIFT 8
287#define I40E_GLPE_VFFLMOBJCTRL_Q1_BLOCKSIZE_MASK (0x7 << I40E_GLPE_VFFLMOBJCTRL_Q1_BLOCKSIZE_SHIFT)
288#define I40E_GLPE_VFFLMQ1ALLOCERR(_i) (0x0000C700 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
289#define I40E_GLPE_VFFLMQ1ALLOCERR_MAX_INDEX 31
290#define I40E_GLPE_VFFLMQ1ALLOCERR_ERROR_COUNT_SHIFT 0
291#define I40E_GLPE_VFFLMQ1ALLOCERR_ERROR_COUNT_MASK (0xFFFF << I40E_GLPE_VFFLMQ1ALLOCERR_ERROR_COUNT_SHIFT)
292#define I40E_GLPE_VFFLMXMITALLOCERR(_i) (0x0000C600 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
293#define I40E_GLPE_VFFLMXMITALLOCERR_MAX_INDEX 31
294#define I40E_GLPE_VFFLMXMITALLOCERR_ERROR_COUNT_SHIFT 0
295#define I40E_GLPE_VFFLMXMITALLOCERR_ERROR_COUNT_MASK (0xFFFF << I40E_GLPE_VFFLMXMITALLOCERR_ERROR_COUNT_SHIFT)
296#define I40E_GLPE_VFUDACTRL(_i) (0x0000C000 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
297#define I40E_GLPE_VFUDACTRL_MAX_INDEX 31
298#define I40E_GLPE_VFUDACTRL_IPV4MCFRAGRESBP_SHIFT 0
299#define I40E_GLPE_VFUDACTRL_IPV4MCFRAGRESBP_MASK (0x1 << I40E_GLPE_VFUDACTRL_IPV4MCFRAGRESBP_SHIFT)
300#define I40E_GLPE_VFUDACTRL_IPV4UCFRAGRESBP_SHIFT 1
301#define I40E_GLPE_VFUDACTRL_IPV4UCFRAGRESBP_MASK (0x1 << I40E_GLPE_VFUDACTRL_IPV4UCFRAGRESBP_SHIFT)
302#define I40E_GLPE_VFUDACTRL_IPV6MCFRAGRESBP_SHIFT 2
303#define I40E_GLPE_VFUDACTRL_IPV6MCFRAGRESBP_MASK (0x1 << I40E_GLPE_VFUDACTRL_IPV6MCFRAGRESBP_SHIFT)
304#define I40E_GLPE_VFUDACTRL_IPV6UCFRAGRESBP_SHIFT 3
305#define I40E_GLPE_VFUDACTRL_IPV6UCFRAGRESBP_MASK (0x1 << I40E_GLPE_VFUDACTRL_IPV6UCFRAGRESBP_SHIFT)
306#define I40E_GLPE_VFUDACTRL_UDPMCFRAGRESFAIL_SHIFT 4
307#define I40E_GLPE_VFUDACTRL_UDPMCFRAGRESFAIL_MASK (0x1 << I40E_GLPE_VFUDACTRL_UDPMCFRAGRESFAIL_SHIFT)
308#define I40E_GLPE_VFUDAUCFBQPN(_i) (0x0000C100 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
309#define I40E_GLPE_VFUDAUCFBQPN_MAX_INDEX 31
310#define I40E_GLPE_VFUDAUCFBQPN_QPN_SHIFT 0
311#define I40E_GLPE_VFUDAUCFBQPN_QPN_MASK (0x3FFFF << I40E_GLPE_VFUDAUCFBQPN_QPN_SHIFT)
312#define I40E_GLPE_VFUDAUCFBQPN_VALID_SHIFT 31
313#define I40E_GLPE_VFUDAUCFBQPN_VALID_MASK (0x1 << I40E_GLPE_VFUDAUCFBQPN_VALID_SHIFT)
314
315#define I40E_GLPES_PFIP4RXDISCARD(_i) (0x00010600 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
316#define I40E_GLPES_PFIP4RXDISCARD_MAX_INDEX 15
317#define I40E_GLPES_PFIP4RXDISCARD_IP4RXDISCARD_SHIFT 0
318#define I40E_GLPES_PFIP4RXDISCARD_IP4RXDISCARD_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4RXDISCARD_IP4RXDISCARD_SHIFT)
319#define I40E_GLPES_PFIP4RXFRAGSHI(_i) (0x00010804 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
320#define I40E_GLPES_PFIP4RXFRAGSHI_MAX_INDEX 15
321#define I40E_GLPES_PFIP4RXFRAGSHI_IP4RXFRAGSHI_SHIFT 0
322#define I40E_GLPES_PFIP4RXFRAGSHI_IP4RXFRAGSHI_MASK (0xFFFF << I40E_GLPES_PFIP4RXFRAGSHI_IP4RXFRAGSHI_SHIFT)
323#define I40E_GLPES_PFIP4RXFRAGSLO(_i) (0x00010800 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
324#define I40E_GLPES_PFIP4RXFRAGSLO_MAX_INDEX 15
325#define I40E_GLPES_PFIP4RXFRAGSLO_IP4RXFRAGSLO_SHIFT 0
326#define I40E_GLPES_PFIP4RXFRAGSLO_IP4RXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4RXFRAGSLO_IP4RXFRAGSLO_SHIFT)
327#define I40E_GLPES_PFIP4RXMCOCTSHI(_i) (0x00010A04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
328#define I40E_GLPES_PFIP4RXMCOCTSHI_MAX_INDEX 15
329#define I40E_GLPES_PFIP4RXMCOCTSHI_IP4RXMCOCTSHI_SHIFT 0
330#define I40E_GLPES_PFIP4RXMCOCTSHI_IP4RXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4RXMCOCTSHI_IP4RXMCOCTSHI_SHIFT)
331#define I40E_GLPES_PFIP4RXMCOCTSLO(_i) (0x00010A00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
332#define I40E_GLPES_PFIP4RXMCOCTSLO_MAX_INDEX 15
333#define I40E_GLPES_PFIP4RXMCOCTSLO_IP4RXMCOCTSLO_SHIFT 0
334#define I40E_GLPES_PFIP4RXMCOCTSLO_IP4RXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4RXMCOCTSLO_IP4RXMCOCTSLO_SHIFT)
335#define I40E_GLPES_PFIP4RXMCPKTSHI(_i) (0x00010C04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
336#define I40E_GLPES_PFIP4RXMCPKTSHI_MAX_INDEX 15
337#define I40E_GLPES_PFIP4RXMCPKTSHI_IP4RXMCPKTSHI_SHIFT 0
338#define I40E_GLPES_PFIP4RXMCPKTSHI_IP4RXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4RXMCPKTSHI_IP4RXMCPKTSHI_SHIFT)
339#define I40E_GLPES_PFIP4RXMCPKTSLO(_i) (0x00010C00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
340#define I40E_GLPES_PFIP4RXMCPKTSLO_MAX_INDEX 15
341#define I40E_GLPES_PFIP4RXMCPKTSLO_IP4RXMCPKTSLO_SHIFT 0
342#define I40E_GLPES_PFIP4RXMCPKTSLO_IP4RXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4RXMCPKTSLO_IP4RXMCPKTSLO_SHIFT)
343#define I40E_GLPES_PFIP4RXOCTSHI(_i) (0x00010204 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
344#define I40E_GLPES_PFIP4RXOCTSHI_MAX_INDEX 15
345#define I40E_GLPES_PFIP4RXOCTSHI_IP4RXOCTSHI_SHIFT 0
346#define I40E_GLPES_PFIP4RXOCTSHI_IP4RXOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4RXOCTSHI_IP4RXOCTSHI_SHIFT)
347#define I40E_GLPES_PFIP4RXOCTSLO(_i) (0x00010200 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
348#define I40E_GLPES_PFIP4RXOCTSLO_MAX_INDEX 15
349#define I40E_GLPES_PFIP4RXOCTSLO_IP4RXOCTSLO_SHIFT 0
350#define I40E_GLPES_PFIP4RXOCTSLO_IP4RXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4RXOCTSLO_IP4RXOCTSLO_SHIFT)
351#define I40E_GLPES_PFIP4RXPKTSHI(_i) (0x00010404 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
352#define I40E_GLPES_PFIP4RXPKTSHI_MAX_INDEX 15
353#define I40E_GLPES_PFIP4RXPKTSHI_IP4RXPKTSHI_SHIFT 0
354#define I40E_GLPES_PFIP4RXPKTSHI_IP4RXPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4RXPKTSHI_IP4RXPKTSHI_SHIFT)
355#define I40E_GLPES_PFIP4RXPKTSLO(_i) (0x00010400 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
356#define I40E_GLPES_PFIP4RXPKTSLO_MAX_INDEX 15
357#define I40E_GLPES_PFIP4RXPKTSLO_IP4RXPKTSLO_SHIFT 0
358#define I40E_GLPES_PFIP4RXPKTSLO_IP4RXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4RXPKTSLO_IP4RXPKTSLO_SHIFT)
359#define I40E_GLPES_PFIP4RXTRUNC(_i) (0x00010700 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
360#define I40E_GLPES_PFIP4RXTRUNC_MAX_INDEX 15
361#define I40E_GLPES_PFIP4RXTRUNC_IP4RXTRUNC_SHIFT 0
362#define I40E_GLPES_PFIP4RXTRUNC_IP4RXTRUNC_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4RXTRUNC_IP4RXTRUNC_SHIFT)
363#define I40E_GLPES_PFIP4TXFRAGSHI(_i) (0x00011E04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
364#define I40E_GLPES_PFIP4TXFRAGSHI_MAX_INDEX 15
365#define I40E_GLPES_PFIP4TXFRAGSHI_IP4TXFRAGSHI_SHIFT 0
366#define I40E_GLPES_PFIP4TXFRAGSHI_IP4TXFRAGSHI_MASK (0xFFFF << I40E_GLPES_PFIP4TXFRAGSHI_IP4TXFRAGSHI_SHIFT)
367#define I40E_GLPES_PFIP4TXFRAGSLO(_i) (0x00011E00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
368#define I40E_GLPES_PFIP4TXFRAGSLO_MAX_INDEX 15
369#define I40E_GLPES_PFIP4TXFRAGSLO_IP4TXFRAGSLO_SHIFT 0
370#define I40E_GLPES_PFIP4TXFRAGSLO_IP4TXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4TXFRAGSLO_IP4TXFRAGSLO_SHIFT)
371#define I40E_GLPES_PFIP4TXMCOCTSHI(_i) (0x00012004 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
372#define I40E_GLPES_PFIP4TXMCOCTSHI_MAX_INDEX 15
373#define I40E_GLPES_PFIP4TXMCOCTSHI_IP4TXMCOCTSHI_SHIFT 0
374#define I40E_GLPES_PFIP4TXMCOCTSHI_IP4TXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4TXMCOCTSHI_IP4TXMCOCTSHI_SHIFT)
375#define I40E_GLPES_PFIP4TXMCOCTSLO(_i) (0x00012000 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
376#define I40E_GLPES_PFIP4TXMCOCTSLO_MAX_INDEX 15
377#define I40E_GLPES_PFIP4TXMCOCTSLO_IP4TXMCOCTSLO_SHIFT 0
378#define I40E_GLPES_PFIP4TXMCOCTSLO_IP4TXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4TXMCOCTSLO_IP4TXMCOCTSLO_SHIFT)
379#define I40E_GLPES_PFIP4TXMCPKTSHI(_i) (0x00012204 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
380#define I40E_GLPES_PFIP4TXMCPKTSHI_MAX_INDEX 15
381#define I40E_GLPES_PFIP4TXMCPKTSHI_IP4TXMCPKTSHI_SHIFT 0
382#define I40E_GLPES_PFIP4TXMCPKTSHI_IP4TXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4TXMCPKTSHI_IP4TXMCPKTSHI_SHIFT)
383#define I40E_GLPES_PFIP4TXMCPKTSLO(_i) (0x00012200 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
384#define I40E_GLPES_PFIP4TXMCPKTSLO_MAX_INDEX 15
385#define I40E_GLPES_PFIP4TXMCPKTSLO_IP4TXMCPKTSLO_SHIFT 0
386#define I40E_GLPES_PFIP4TXMCPKTSLO_IP4TXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4TXMCPKTSLO_IP4TXMCPKTSLO_SHIFT)
387#define I40E_GLPES_PFIP4TXNOROUTE(_i) (0x00012E00 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
388#define I40E_GLPES_PFIP4TXNOROUTE_MAX_INDEX 15
389#define I40E_GLPES_PFIP4TXNOROUTE_IP4TXNOROUTE_SHIFT 0
390#define I40E_GLPES_PFIP4TXNOROUTE_IP4TXNOROUTE_MASK (0xFFFFFF << I40E_GLPES_PFIP4TXNOROUTE_IP4TXNOROUTE_SHIFT)
391#define I40E_GLPES_PFIP4TXOCTSHI(_i) (0x00011A04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
392#define I40E_GLPES_PFIP4TXOCTSHI_MAX_INDEX 15
393#define I40E_GLPES_PFIP4TXOCTSHI_IP4TXOCTSHI_SHIFT 0
394#define I40E_GLPES_PFIP4TXOCTSHI_IP4TXOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4TXOCTSHI_IP4TXOCTSHI_SHIFT)
395#define I40E_GLPES_PFIP4TXOCTSLO(_i) (0x00011A00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
396#define I40E_GLPES_PFIP4TXOCTSLO_MAX_INDEX 15
397#define I40E_GLPES_PFIP4TXOCTSLO_IP4TXOCTSLO_SHIFT 0
398#define I40E_GLPES_PFIP4TXOCTSLO_IP4TXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4TXOCTSLO_IP4TXOCTSLO_SHIFT)
399#define I40E_GLPES_PFIP4TXPKTSHI(_i) (0x00011C04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
400#define I40E_GLPES_PFIP4TXPKTSHI_MAX_INDEX 15
401#define I40E_GLPES_PFIP4TXPKTSHI_IP4TXPKTSHI_SHIFT 0
402#define I40E_GLPES_PFIP4TXPKTSHI_IP4TXPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP4TXPKTSHI_IP4TXPKTSHI_SHIFT)
403#define I40E_GLPES_PFIP4TXPKTSLO(_i) (0x00011C00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
404#define I40E_GLPES_PFIP4TXPKTSLO_MAX_INDEX 15
405#define I40E_GLPES_PFIP4TXPKTSLO_IP4TXPKTSLO_SHIFT 0
406#define I40E_GLPES_PFIP4TXPKTSLO_IP4TXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP4TXPKTSLO_IP4TXPKTSLO_SHIFT)
407#define I40E_GLPES_PFIP6RXDISCARD(_i) (0x00011200 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
408#define I40E_GLPES_PFIP6RXDISCARD_MAX_INDEX 15
409#define I40E_GLPES_PFIP6RXDISCARD_IP6RXDISCARD_SHIFT 0
410#define I40E_GLPES_PFIP6RXDISCARD_IP6RXDISCARD_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6RXDISCARD_IP6RXDISCARD_SHIFT)
411#define I40E_GLPES_PFIP6RXFRAGSHI(_i) (0x00011404 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
412#define I40E_GLPES_PFIP6RXFRAGSHI_MAX_INDEX 15
413#define I40E_GLPES_PFIP6RXFRAGSHI_IP6RXFRAGSHI_SHIFT 0
414#define I40E_GLPES_PFIP6RXFRAGSHI_IP6RXFRAGSHI_MASK (0xFFFF << I40E_GLPES_PFIP6RXFRAGSHI_IP6RXFRAGSHI_SHIFT)
415#define I40E_GLPES_PFIP6RXFRAGSLO(_i) (0x00011400 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
416#define I40E_GLPES_PFIP6RXFRAGSLO_MAX_INDEX 15
417#define I40E_GLPES_PFIP6RXFRAGSLO_IP6RXFRAGSLO_SHIFT 0
418#define I40E_GLPES_PFIP6RXFRAGSLO_IP6RXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6RXFRAGSLO_IP6RXFRAGSLO_SHIFT)
419#define I40E_GLPES_PFIP6RXMCOCTSHI(_i) (0x00011604 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
420#define I40E_GLPES_PFIP6RXMCOCTSHI_MAX_INDEX 15
421#define I40E_GLPES_PFIP6RXMCOCTSHI_IP6RXMCOCTSHI_SHIFT 0
422#define I40E_GLPES_PFIP6RXMCOCTSHI_IP6RXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6RXMCOCTSHI_IP6RXMCOCTSHI_SHIFT)
423#define I40E_GLPES_PFIP6RXMCOCTSLO(_i) (0x00011600 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
424#define I40E_GLPES_PFIP6RXMCOCTSLO_MAX_INDEX 15
425#define I40E_GLPES_PFIP6RXMCOCTSLO_IP6RXMCOCTSLO_SHIFT 0
426#define I40E_GLPES_PFIP6RXMCOCTSLO_IP6RXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6RXMCOCTSLO_IP6RXMCOCTSLO_SHIFT)
427#define I40E_GLPES_PFIP6RXMCPKTSHI(_i) (0x00011804 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
428#define I40E_GLPES_PFIP6RXMCPKTSHI_MAX_INDEX 15
429#define I40E_GLPES_PFIP6RXMCPKTSHI_IP6RXMCPKTSHI_SHIFT 0
430#define I40E_GLPES_PFIP6RXMCPKTSHI_IP6RXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6RXMCPKTSHI_IP6RXMCPKTSHI_SHIFT)
431#define I40E_GLPES_PFIP6RXMCPKTSLO(_i) (0x00011800 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
432#define I40E_GLPES_PFIP6RXMCPKTSLO_MAX_INDEX 15
433#define I40E_GLPES_PFIP6RXMCPKTSLO_IP6RXMCPKTSLO_SHIFT 0
434#define I40E_GLPES_PFIP6RXMCPKTSLO_IP6RXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6RXMCPKTSLO_IP6RXMCPKTSLO_SHIFT)
435#define I40E_GLPES_PFIP6RXOCTSHI(_i) (0x00010E04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
436#define I40E_GLPES_PFIP6RXOCTSHI_MAX_INDEX 15
437#define I40E_GLPES_PFIP6RXOCTSHI_IP6RXOCTSHI_SHIFT 0
438#define I40E_GLPES_PFIP6RXOCTSHI_IP6RXOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6RXOCTSHI_IP6RXOCTSHI_SHIFT)
439#define I40E_GLPES_PFIP6RXOCTSLO(_i) (0x00010E00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
440#define I40E_GLPES_PFIP6RXOCTSLO_MAX_INDEX 15
441#define I40E_GLPES_PFIP6RXOCTSLO_IP6RXOCTSLO_SHIFT 0
442#define I40E_GLPES_PFIP6RXOCTSLO_IP6RXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6RXOCTSLO_IP6RXOCTSLO_SHIFT)
443#define I40E_GLPES_PFIP6RXPKTSHI(_i) (0x00011004 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
444#define I40E_GLPES_PFIP6RXPKTSHI_MAX_INDEX 15
445#define I40E_GLPES_PFIP6RXPKTSHI_IP6RXPKTSHI_SHIFT 0
446#define I40E_GLPES_PFIP6RXPKTSHI_IP6RXPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6RXPKTSHI_IP6RXPKTSHI_SHIFT)
447#define I40E_GLPES_PFIP6RXPKTSLO(_i) (0x00011000 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
448#define I40E_GLPES_PFIP6RXPKTSLO_MAX_INDEX 15
449#define I40E_GLPES_PFIP6RXPKTSLO_IP6RXPKTSLO_SHIFT 0
450#define I40E_GLPES_PFIP6RXPKTSLO_IP6RXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6RXPKTSLO_IP6RXPKTSLO_SHIFT)
451#define I40E_GLPES_PFIP6RXTRUNC(_i) (0x00011300 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
452#define I40E_GLPES_PFIP6RXTRUNC_MAX_INDEX 15
453#define I40E_GLPES_PFIP6RXTRUNC_IP6RXTRUNC_SHIFT 0
454#define I40E_GLPES_PFIP6RXTRUNC_IP6RXTRUNC_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6RXTRUNC_IP6RXTRUNC_SHIFT)
455#define I40E_GLPES_PFIP6TXFRAGSHI(_i) (0x00012804 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
456#define I40E_GLPES_PFIP6TXFRAGSHI_MAX_INDEX 15
457#define I40E_GLPES_PFIP6TXFRAGSHI_IP6TXFRAGSHI_SHIFT 0
458#define I40E_GLPES_PFIP6TXFRAGSHI_IP6TXFRAGSHI_MASK (0xFFFF << I40E_GLPES_PFIP6TXFRAGSHI_IP6TXFRAGSHI_SHIFT)
459#define I40E_GLPES_PFIP6TXFRAGSLO(_i) (0x00012800 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
460#define I40E_GLPES_PFIP6TXFRAGSLO_MAX_INDEX 15
461#define I40E_GLPES_PFIP6TXFRAGSLO_IP6TXFRAGSLO_SHIFT 0
462#define I40E_GLPES_PFIP6TXFRAGSLO_IP6TXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6TXFRAGSLO_IP6TXFRAGSLO_SHIFT)
463#define I40E_GLPES_PFIP6TXMCOCTSHI(_i) (0x00012A04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
464#define I40E_GLPES_PFIP6TXMCOCTSHI_MAX_INDEX 15
465#define I40E_GLPES_PFIP6TXMCOCTSHI_IP6TXMCOCTSHI_SHIFT 0
466#define I40E_GLPES_PFIP6TXMCOCTSHI_IP6TXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6TXMCOCTSHI_IP6TXMCOCTSHI_SHIFT)
467#define I40E_GLPES_PFIP6TXMCOCTSLO(_i) (0x00012A00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
468#define I40E_GLPES_PFIP6TXMCOCTSLO_MAX_INDEX 15
469#define I40E_GLPES_PFIP6TXMCOCTSLO_IP6TXMCOCTSLO_SHIFT 0
470#define I40E_GLPES_PFIP6TXMCOCTSLO_IP6TXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6TXMCOCTSLO_IP6TXMCOCTSLO_SHIFT)
471#define I40E_GLPES_PFIP6TXMCPKTSHI(_i) (0x00012C04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
472#define I40E_GLPES_PFIP6TXMCPKTSHI_MAX_INDEX 15
473#define I40E_GLPES_PFIP6TXMCPKTSHI_IP6TXMCPKTSHI_SHIFT 0
474#define I40E_GLPES_PFIP6TXMCPKTSHI_IP6TXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6TXMCPKTSHI_IP6TXMCPKTSHI_SHIFT)
475#define I40E_GLPES_PFIP6TXMCPKTSLO(_i) (0x00012C00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
476#define I40E_GLPES_PFIP6TXMCPKTSLO_MAX_INDEX 15
477#define I40E_GLPES_PFIP6TXMCPKTSLO_IP6TXMCPKTSLO_SHIFT 0
478#define I40E_GLPES_PFIP6TXMCPKTSLO_IP6TXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6TXMCPKTSLO_IP6TXMCPKTSLO_SHIFT)
479#define I40E_GLPES_PFIP6TXNOROUTE(_i) (0x00012F00 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
480#define I40E_GLPES_PFIP6TXNOROUTE_MAX_INDEX 15
481#define I40E_GLPES_PFIP6TXNOROUTE_IP6TXNOROUTE_SHIFT 0
482#define I40E_GLPES_PFIP6TXNOROUTE_IP6TXNOROUTE_MASK (0xFFFFFF << I40E_GLPES_PFIP6TXNOROUTE_IP6TXNOROUTE_SHIFT)
483#define I40E_GLPES_PFIP6TXOCTSHI(_i) (0x00012404 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
484#define I40E_GLPES_PFIP6TXOCTSHI_MAX_INDEX 15
485#define I40E_GLPES_PFIP6TXOCTSHI_IP6TXOCTSHI_SHIFT 0
486#define I40E_GLPES_PFIP6TXOCTSHI_IP6TXOCTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6TXOCTSHI_IP6TXOCTSHI_SHIFT)
487#define I40E_GLPES_PFIP6TXOCTSLO(_i) (0x00012400 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
488#define I40E_GLPES_PFIP6TXOCTSLO_MAX_INDEX 15
489#define I40E_GLPES_PFIP6TXOCTSLO_IP6TXOCTSLO_SHIFT 0
490#define I40E_GLPES_PFIP6TXOCTSLO_IP6TXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6TXOCTSLO_IP6TXOCTSLO_SHIFT)
491#define I40E_GLPES_PFIP6TXPKTSHI(_i) (0x00012604 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
492#define I40E_GLPES_PFIP6TXPKTSHI_MAX_INDEX 15
493#define I40E_GLPES_PFIP6TXPKTSHI_IP6TXPKTSHI_SHIFT 0
494#define I40E_GLPES_PFIP6TXPKTSHI_IP6TXPKTSHI_MASK (0xFFFF << I40E_GLPES_PFIP6TXPKTSHI_IP6TXPKTSHI_SHIFT)
495#define I40E_GLPES_PFIP6TXPKTSLO(_i) (0x00012600 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
496#define I40E_GLPES_PFIP6TXPKTSLO_MAX_INDEX 15
497#define I40E_GLPES_PFIP6TXPKTSLO_IP6TXPKTSLO_SHIFT 0
498#define I40E_GLPES_PFIP6TXPKTSLO_IP6TXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFIP6TXPKTSLO_IP6TXPKTSLO_SHIFT)
499#define I40E_GLPES_PFRDMARXRDSHI(_i) (0x00013E04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
500#define I40E_GLPES_PFRDMARXRDSHI_MAX_INDEX 15
501#define I40E_GLPES_PFRDMARXRDSHI_RDMARXRDSHI_SHIFT 0
502#define I40E_GLPES_PFRDMARXRDSHI_RDMARXRDSHI_MASK (0xFFFF << I40E_GLPES_PFRDMARXRDSHI_RDMARXRDSHI_SHIFT)
503#define I40E_GLPES_PFRDMARXRDSLO(_i) (0x00013E00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
504#define I40E_GLPES_PFRDMARXRDSLO_MAX_INDEX 15
505#define I40E_GLPES_PFRDMARXRDSLO_RDMARXRDSLO_SHIFT 0
506#define I40E_GLPES_PFRDMARXRDSLO_RDMARXRDSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMARXRDSLO_RDMARXRDSLO_SHIFT)
507#define I40E_GLPES_PFRDMARXSNDSHI(_i) (0x00014004 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
508#define I40E_GLPES_PFRDMARXSNDSHI_MAX_INDEX 15
509#define I40E_GLPES_PFRDMARXSNDSHI_RDMARXSNDSHI_SHIFT 0
510#define I40E_GLPES_PFRDMARXSNDSHI_RDMARXSNDSHI_MASK (0xFFFF << I40E_GLPES_PFRDMARXSNDSHI_RDMARXSNDSHI_SHIFT)
511#define I40E_GLPES_PFRDMARXSNDSLO(_i) (0x00014000 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
512#define I40E_GLPES_PFRDMARXSNDSLO_MAX_INDEX 15
513#define I40E_GLPES_PFRDMARXSNDSLO_RDMARXSNDSLO_SHIFT 0
514#define I40E_GLPES_PFRDMARXSNDSLO_RDMARXSNDSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMARXSNDSLO_RDMARXSNDSLO_SHIFT)
515#define I40E_GLPES_PFRDMARXWRSHI(_i) (0x00013C04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
516#define I40E_GLPES_PFRDMARXWRSHI_MAX_INDEX 15
517#define I40E_GLPES_PFRDMARXWRSHI_RDMARXWRSHI_SHIFT 0
518#define I40E_GLPES_PFRDMARXWRSHI_RDMARXWRSHI_MASK (0xFFFF << I40E_GLPES_PFRDMARXWRSHI_RDMARXWRSHI_SHIFT)
519#define I40E_GLPES_PFRDMARXWRSLO(_i) (0x00013C00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
520#define I40E_GLPES_PFRDMARXWRSLO_MAX_INDEX 15
521#define I40E_GLPES_PFRDMARXWRSLO_RDMARXWRSLO_SHIFT 0
522#define I40E_GLPES_PFRDMARXWRSLO_RDMARXWRSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMARXWRSLO_RDMARXWRSLO_SHIFT)
523#define I40E_GLPES_PFRDMATXRDSHI(_i) (0x00014404 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
524#define I40E_GLPES_PFRDMATXRDSHI_MAX_INDEX 15
525#define I40E_GLPES_PFRDMATXRDSHI_RDMARXRDSHI_SHIFT 0
526#define I40E_GLPES_PFRDMATXRDSHI_RDMARXRDSHI_MASK (0xFFFF << I40E_GLPES_PFRDMATXRDSHI_RDMARXRDSHI_SHIFT)
527#define I40E_GLPES_PFRDMATXRDSLO(_i) (0x00014400 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
528#define I40E_GLPES_PFRDMATXRDSLO_MAX_INDEX 15
529#define I40E_GLPES_PFRDMATXRDSLO_RDMARXRDSLO_SHIFT 0
530#define I40E_GLPES_PFRDMATXRDSLO_RDMARXRDSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMATXRDSLO_RDMARXRDSLO_SHIFT)
531#define I40E_GLPES_PFRDMATXSNDSHI(_i) (0x00014604 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
532#define I40E_GLPES_PFRDMATXSNDSHI_MAX_INDEX 15
533#define I40E_GLPES_PFRDMATXSNDSHI_RDMARXSNDSHI_SHIFT 0
534#define I40E_GLPES_PFRDMATXSNDSHI_RDMARXSNDSHI_MASK (0xFFFF << I40E_GLPES_PFRDMATXSNDSHI_RDMARXSNDSHI_SHIFT)
535#define I40E_GLPES_PFRDMATXSNDSLO(_i) (0x00014600 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
536#define I40E_GLPES_PFRDMATXSNDSLO_MAX_INDEX 15
537#define I40E_GLPES_PFRDMATXSNDSLO_RDMARXSNDSLO_SHIFT 0
538#define I40E_GLPES_PFRDMATXSNDSLO_RDMARXSNDSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMATXSNDSLO_RDMARXSNDSLO_SHIFT)
539#define I40E_GLPES_PFRDMATXWRSHI(_i) (0x00014204 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
540#define I40E_GLPES_PFRDMATXWRSHI_MAX_INDEX 15
541#define I40E_GLPES_PFRDMATXWRSHI_RDMARXWRSHI_SHIFT 0
542#define I40E_GLPES_PFRDMATXWRSHI_RDMARXWRSHI_MASK (0xFFFF << I40E_GLPES_PFRDMATXWRSHI_RDMARXWRSHI_SHIFT)
543#define I40E_GLPES_PFRDMATXWRSLO(_i) (0x00014200 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
544#define I40E_GLPES_PFRDMATXWRSLO_MAX_INDEX 15
545#define I40E_GLPES_PFRDMATXWRSLO_RDMARXWRSLO_SHIFT 0
546#define I40E_GLPES_PFRDMATXWRSLO_RDMARXWRSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMATXWRSLO_RDMARXWRSLO_SHIFT)
547#define I40E_GLPES_PFRDMAVBNDHI(_i) (0x00014804 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
548#define I40E_GLPES_PFRDMAVBNDHI_MAX_INDEX 15
549#define I40E_GLPES_PFRDMAVBNDHI_RDMAVBNDHI_SHIFT 0
550#define I40E_GLPES_PFRDMAVBNDHI_RDMAVBNDHI_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMAVBNDHI_RDMAVBNDHI_SHIFT)
551#define I40E_GLPES_PFRDMAVBNDLO(_i) (0x00014800 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
552#define I40E_GLPES_PFRDMAVBNDLO_MAX_INDEX 15
553#define I40E_GLPES_PFRDMAVBNDLO_RDMAVBNDLO_SHIFT 0
554#define I40E_GLPES_PFRDMAVBNDLO_RDMAVBNDLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMAVBNDLO_RDMAVBNDLO_SHIFT)
555#define I40E_GLPES_PFRDMAVINVHI(_i) (0x00014A04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
556#define I40E_GLPES_PFRDMAVINVHI_MAX_INDEX 15
557#define I40E_GLPES_PFRDMAVINVHI_RDMAVINVHI_SHIFT 0
558#define I40E_GLPES_PFRDMAVINVHI_RDMAVINVHI_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMAVINVHI_RDMAVINVHI_SHIFT)
559#define I40E_GLPES_PFRDMAVINVLO(_i) (0x00014A00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
560#define I40E_GLPES_PFRDMAVINVLO_MAX_INDEX 15
561#define I40E_GLPES_PFRDMAVINVLO_RDMAVINVLO_SHIFT 0
562#define I40E_GLPES_PFRDMAVINVLO_RDMAVINVLO_MASK (0xFFFFFFFF << I40E_GLPES_PFRDMAVINVLO_RDMAVINVLO_SHIFT)
563#define I40E_GLPES_PFRXVLANERR(_i) (0x00010000 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
564#define I40E_GLPES_PFRXVLANERR_MAX_INDEX 15
565#define I40E_GLPES_PFRXVLANERR_RXVLANERR_SHIFT 0
566#define I40E_GLPES_PFRXVLANERR_RXVLANERR_MASK (0xFFFFFF << I40E_GLPES_PFRXVLANERR_RXVLANERR_SHIFT)
567#define I40E_GLPES_PFTCPRTXSEG(_i) (0x00013600 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
568#define I40E_GLPES_PFTCPRTXSEG_MAX_INDEX 15
569#define I40E_GLPES_PFTCPRTXSEG_TCPRTXSEG_SHIFT 0
570#define I40E_GLPES_PFTCPRTXSEG_TCPRTXSEG_MASK (0xFFFFFFFF << I40E_GLPES_PFTCPRTXSEG_TCPRTXSEG_SHIFT)
571#define I40E_GLPES_PFTCPRXOPTERR(_i) (0x00013200 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
572#define I40E_GLPES_PFTCPRXOPTERR_MAX_INDEX 15
573#define I40E_GLPES_PFTCPRXOPTERR_TCPRXOPTERR_SHIFT 0
574#define I40E_GLPES_PFTCPRXOPTERR_TCPRXOPTERR_MASK (0xFFFFFF << I40E_GLPES_PFTCPRXOPTERR_TCPRXOPTERR_SHIFT)
575#define I40E_GLPES_PFTCPRXPROTOERR(_i) (0x00013300 + ((_i) * 4)) /* _i=0...15 */ /* Reset: PE_CORER */
576#define I40E_GLPES_PFTCPRXPROTOERR_MAX_INDEX 15
577#define I40E_GLPES_PFTCPRXPROTOERR_TCPRXPROTOERR_SHIFT 0
578#define I40E_GLPES_PFTCPRXPROTOERR_TCPRXPROTOERR_MASK (0xFFFFFF << I40E_GLPES_PFTCPRXPROTOERR_TCPRXPROTOERR_SHIFT)
579#define I40E_GLPES_PFTCPRXSEGSHI(_i) (0x00013004 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
580#define I40E_GLPES_PFTCPRXSEGSHI_MAX_INDEX 15
581#define I40E_GLPES_PFTCPRXSEGSHI_TCPRXSEGSHI_SHIFT 0
582#define I40E_GLPES_PFTCPRXSEGSHI_TCPRXSEGSHI_MASK (0xFFFF << I40E_GLPES_PFTCPRXSEGSHI_TCPRXSEGSHI_SHIFT)
583#define I40E_GLPES_PFTCPRXSEGSLO(_i) (0x00013000 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
584#define I40E_GLPES_PFTCPRXSEGSLO_MAX_INDEX 15
585#define I40E_GLPES_PFTCPRXSEGSLO_TCPRXSEGSLO_SHIFT 0
586#define I40E_GLPES_PFTCPRXSEGSLO_TCPRXSEGSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFTCPRXSEGSLO_TCPRXSEGSLO_SHIFT)
587#define I40E_GLPES_PFTCPTXSEGHI(_i) (0x00013404 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
588#define I40E_GLPES_PFTCPTXSEGHI_MAX_INDEX 15
589#define I40E_GLPES_PFTCPTXSEGHI_TCPTXSEGHI_SHIFT 0
590#define I40E_GLPES_PFTCPTXSEGHI_TCPTXSEGHI_MASK (0xFFFF << I40E_GLPES_PFTCPTXSEGHI_TCPTXSEGHI_SHIFT)
591#define I40E_GLPES_PFTCPTXSEGLO(_i) (0x00013400 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
592#define I40E_GLPES_PFTCPTXSEGLO_MAX_INDEX 15
593#define I40E_GLPES_PFTCPTXSEGLO_TCPTXSEGLO_SHIFT 0
594#define I40E_GLPES_PFTCPTXSEGLO_TCPTXSEGLO_MASK (0xFFFFFFFF << I40E_GLPES_PFTCPTXSEGLO_TCPTXSEGLO_SHIFT)
595#define I40E_GLPES_PFUDPRXPKTSHI(_i) (0x00013804 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
596#define I40E_GLPES_PFUDPRXPKTSHI_MAX_INDEX 15
597#define I40E_GLPES_PFUDPRXPKTSHI_UDPRXPKTSHI_SHIFT 0
598#define I40E_GLPES_PFUDPRXPKTSHI_UDPRXPKTSHI_MASK (0xFFFF << I40E_GLPES_PFUDPRXPKTSHI_UDPRXPKTSHI_SHIFT)
599#define I40E_GLPES_PFUDPRXPKTSLO(_i) (0x00013800 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
600#define I40E_GLPES_PFUDPRXPKTSLO_MAX_INDEX 15
601#define I40E_GLPES_PFUDPRXPKTSLO_UDPRXPKTSLO_SHIFT 0
602#define I40E_GLPES_PFUDPRXPKTSLO_UDPRXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFUDPRXPKTSLO_UDPRXPKTSLO_SHIFT)
603#define I40E_GLPES_PFUDPTXPKTSHI(_i) (0x00013A04 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
604#define I40E_GLPES_PFUDPTXPKTSHI_MAX_INDEX 15
605#define I40E_GLPES_PFUDPTXPKTSHI_UDPTXPKTSHI_SHIFT 0
606#define I40E_GLPES_PFUDPTXPKTSHI_UDPTXPKTSHI_MASK (0xFFFF << I40E_GLPES_PFUDPTXPKTSHI_UDPTXPKTSHI_SHIFT)
607#define I40E_GLPES_PFUDPTXPKTSLO(_i) (0x00013A00 + ((_i) * 8)) /* _i=0...15 */ /* Reset: PE_CORER */
608#define I40E_GLPES_PFUDPTXPKTSLO_MAX_INDEX 15
609#define I40E_GLPES_PFUDPTXPKTSLO_UDPTXPKTSLO_SHIFT 0
610#define I40E_GLPES_PFUDPTXPKTSLO_UDPTXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_PFUDPTXPKTSLO_UDPTXPKTSLO_SHIFT)
611#define I40E_GLPES_RDMARXMULTFPDUSHI 0x0001E014 /* Reset: PE_CORER */
612#define I40E_GLPES_RDMARXMULTFPDUSHI_RDMARXMULTFPDUSHI_SHIFT 0
613#define I40E_GLPES_RDMARXMULTFPDUSHI_RDMARXMULTFPDUSHI_MASK (0xFFFFFF << I40E_GLPES_RDMARXMULTFPDUSHI_RDMARXMULTFPDUSHI_SHIFT)
614#define I40E_GLPES_RDMARXMULTFPDUSLO 0x0001E010 /* Reset: PE_CORER */
615#define I40E_GLPES_RDMARXMULTFPDUSLO_RDMARXMULTFPDUSLO_SHIFT 0
616#define I40E_GLPES_RDMARXMULTFPDUSLO_RDMARXMULTFPDUSLO_MASK (0xFFFFFFFF << I40E_GLPES_RDMARXMULTFPDUSLO_RDMARXMULTFPDUSLO_SHIFT)
617#define I40E_GLPES_RDMARXOOODDPHI 0x0001E01C /* Reset: PE_CORER */
618#define I40E_GLPES_RDMARXOOODDPHI_RDMARXOOODDPHI_SHIFT 0
619#define I40E_GLPES_RDMARXOOODDPHI_RDMARXOOODDPHI_MASK (0xFFFFFF << I40E_GLPES_RDMARXOOODDPHI_RDMARXOOODDPHI_SHIFT)
620#define I40E_GLPES_RDMARXOOODDPLO 0x0001E018 /* Reset: PE_CORER */
621#define I40E_GLPES_RDMARXOOODDPLO_RDMARXOOODDPLO_SHIFT 0
622#define I40E_GLPES_RDMARXOOODDPLO_RDMARXOOODDPLO_MASK (0xFFFFFFFF << I40E_GLPES_RDMARXOOODDPLO_RDMARXOOODDPLO_SHIFT)
623#define I40E_GLPES_RDMARXOOONOMARK 0x0001E004 /* Reset: PE_CORER */
624#define I40E_GLPES_RDMARXOOONOMARK_RDMAOOONOMARK_SHIFT 0
625#define I40E_GLPES_RDMARXOOONOMARK_RDMAOOONOMARK_MASK (0xFFFFFFFF << I40E_GLPES_RDMARXOOONOMARK_RDMAOOONOMARK_SHIFT)
626#define I40E_GLPES_RDMARXUNALIGN 0x0001E000 /* Reset: PE_CORER */
627#define I40E_GLPES_RDMARXUNALIGN_RDMRXAUNALIGN_SHIFT 0
628#define I40E_GLPES_RDMARXUNALIGN_RDMRXAUNALIGN_MASK (0xFFFFFFFF << I40E_GLPES_RDMARXUNALIGN_RDMRXAUNALIGN_SHIFT)
629#define I40E_GLPES_TCPRXFOURHOLEHI 0x0001E044 /* Reset: PE_CORER */
630#define I40E_GLPES_TCPRXFOURHOLEHI_TCPRXFOURHOLEHI_SHIFT 0
631#define I40E_GLPES_TCPRXFOURHOLEHI_TCPRXFOURHOLEHI_MASK (0xFFFFFF << I40E_GLPES_TCPRXFOURHOLEHI_TCPRXFOURHOLEHI_SHIFT)
632#define I40E_GLPES_TCPRXFOURHOLELO 0x0001E040 /* Reset: PE_CORER */
633#define I40E_GLPES_TCPRXFOURHOLELO_TCPRXFOURHOLELO_SHIFT 0
634#define I40E_GLPES_TCPRXFOURHOLELO_TCPRXFOURHOLELO_MASK (0xFFFFFFFF << I40E_GLPES_TCPRXFOURHOLELO_TCPRXFOURHOLELO_SHIFT)
635#define I40E_GLPES_TCPRXONEHOLEHI 0x0001E02C /* Reset: PE_CORER */
636#define I40E_GLPES_TCPRXONEHOLEHI_TCPRXONEHOLEHI_SHIFT 0
637#define I40E_GLPES_TCPRXONEHOLEHI_TCPRXONEHOLEHI_MASK (0xFFFFFF << I40E_GLPES_TCPRXONEHOLEHI_TCPRXONEHOLEHI_SHIFT)
638#define I40E_GLPES_TCPRXONEHOLELO 0x0001E028 /* Reset: PE_CORER */
639#define I40E_GLPES_TCPRXONEHOLELO_TCPRXONEHOLELO_SHIFT 0
640#define I40E_GLPES_TCPRXONEHOLELO_TCPRXONEHOLELO_MASK (0xFFFFFFFF << I40E_GLPES_TCPRXONEHOLELO_TCPRXONEHOLELO_SHIFT)
641#define I40E_GLPES_TCPRXPUREACKHI 0x0001E024 /* Reset: PE_CORER */
642#define I40E_GLPES_TCPRXPUREACKHI_TCPRXPUREACKSHI_SHIFT 0
643#define I40E_GLPES_TCPRXPUREACKHI_TCPRXPUREACKSHI_MASK (0xFFFFFF << I40E_GLPES_TCPRXPUREACKHI_TCPRXPUREACKSHI_SHIFT)
644#define I40E_GLPES_TCPRXPUREACKSLO 0x0001E020 /* Reset: PE_CORER */
645#define I40E_GLPES_TCPRXPUREACKSLO_TCPRXPUREACKLO_SHIFT 0
646#define I40E_GLPES_TCPRXPUREACKSLO_TCPRXPUREACKLO_MASK (0xFFFFFFFF << I40E_GLPES_TCPRXPUREACKSLO_TCPRXPUREACKLO_SHIFT)
647#define I40E_GLPES_TCPRXTHREEHOLEHI 0x0001E03C /* Reset: PE_CORER */
648#define I40E_GLPES_TCPRXTHREEHOLEHI_TCPRXTHREEHOLEHI_SHIFT 0
649#define I40E_GLPES_TCPRXTHREEHOLEHI_TCPRXTHREEHOLEHI_MASK (0xFFFFFF << I40E_GLPES_TCPRXTHREEHOLEHI_TCPRXTHREEHOLEHI_SHIFT)
650#define I40E_GLPES_TCPRXTHREEHOLELO 0x0001E038 /* Reset: PE_CORER */
651#define I40E_GLPES_TCPRXTHREEHOLELO_TCPRXTHREEHOLELO_SHIFT 0
652#define I40E_GLPES_TCPRXTHREEHOLELO_TCPRXTHREEHOLELO_MASK (0xFFFFFFFF << I40E_GLPES_TCPRXTHREEHOLELO_TCPRXTHREEHOLELO_SHIFT)
653#define I40E_GLPES_TCPRXTWOHOLEHI 0x0001E034 /* Reset: PE_CORER */
654#define I40E_GLPES_TCPRXTWOHOLEHI_TCPRXTWOHOLEHI_SHIFT 0
655#define I40E_GLPES_TCPRXTWOHOLEHI_TCPRXTWOHOLEHI_MASK (0xFFFFFF << I40E_GLPES_TCPRXTWOHOLEHI_TCPRXTWOHOLEHI_SHIFT)
656#define I40E_GLPES_TCPRXTWOHOLELO 0x0001E030 /* Reset: PE_CORER */
657#define I40E_GLPES_TCPRXTWOHOLELO_TCPRXTWOHOLELO_SHIFT 0
658#define I40E_GLPES_TCPRXTWOHOLELO_TCPRXTWOHOLELO_MASK (0xFFFFFFFF << I40E_GLPES_TCPRXTWOHOLELO_TCPRXTWOHOLELO_SHIFT)
659#define I40E_GLPES_TCPTXRETRANSFASTHI 0x0001E04C /* Reset: PE_CORER */
660#define I40E_GLPES_TCPTXRETRANSFASTHI_TCPTXRETRANSFASTHI_SHIFT 0
661#define I40E_GLPES_TCPTXRETRANSFASTHI_TCPTXRETRANSFASTHI_MASK (0xFFFFFF << I40E_GLPES_TCPTXRETRANSFASTHI_TCPTXRETRANSFASTHI_SHIFT)
662#define I40E_GLPES_TCPTXRETRANSFASTLO 0x0001E048 /* Reset: PE_CORER */
663#define I40E_GLPES_TCPTXRETRANSFASTLO_TCPTXRETRANSFASTLO_SHIFT 0
664#define I40E_GLPES_TCPTXRETRANSFASTLO_TCPTXRETRANSFASTLO_MASK (0xFFFFFFFF << I40E_GLPES_TCPTXRETRANSFASTLO_TCPTXRETRANSFASTLO_SHIFT)
665#define I40E_GLPES_TCPTXTOUTSFASTHI 0x0001E054 /* Reset: PE_CORER */
666#define I40E_GLPES_TCPTXTOUTSFASTHI_TCPTXTOUTSFASTHI_SHIFT 0
667#define I40E_GLPES_TCPTXTOUTSFASTHI_TCPTXTOUTSFASTHI_MASK (0xFFFFFF << I40E_GLPES_TCPTXTOUTSFASTHI_TCPTXTOUTSFASTHI_SHIFT)
668#define I40E_GLPES_TCPTXTOUTSFASTLO 0x0001E050 /* Reset: PE_CORER */
669#define I40E_GLPES_TCPTXTOUTSFASTLO_TCPTXTOUTSFASTLO_SHIFT 0
670#define I40E_GLPES_TCPTXTOUTSFASTLO_TCPTXTOUTSFASTLO_MASK (0xFFFFFFFF << I40E_GLPES_TCPTXTOUTSFASTLO_TCPTXTOUTSFASTLO_SHIFT)
671#define I40E_GLPES_TCPTXTOUTSHI 0x0001E05C /* Reset: PE_CORER */
672#define I40E_GLPES_TCPTXTOUTSHI_TCPTXTOUTSHI_SHIFT 0
673#define I40E_GLPES_TCPTXTOUTSHI_TCPTXTOUTSHI_MASK (0xFFFFFF << I40E_GLPES_TCPTXTOUTSHI_TCPTXTOUTSHI_SHIFT)
674#define I40E_GLPES_TCPTXTOUTSLO 0x0001E058 /* Reset: PE_CORER */
675#define I40E_GLPES_TCPTXTOUTSLO_TCPTXTOUTSLO_SHIFT 0
676#define I40E_GLPES_TCPTXTOUTSLO_TCPTXTOUTSLO_MASK (0xFFFFFFFF << I40E_GLPES_TCPTXTOUTSLO_TCPTXTOUTSLO_SHIFT)
677#define I40E_GLPES_VFIP4RXDISCARD(_i) (0x00018600 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
678#define I40E_GLPES_VFIP4RXDISCARD_MAX_INDEX 31
679#define I40E_GLPES_VFIP4RXDISCARD_IP4RXDISCARD_SHIFT 0
680#define I40E_GLPES_VFIP4RXDISCARD_IP4RXDISCARD_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4RXDISCARD_IP4RXDISCARD_SHIFT)
681#define I40E_GLPES_VFIP4RXFRAGSHI(_i) (0x00018804 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
682#define I40E_GLPES_VFIP4RXFRAGSHI_MAX_INDEX 31
683#define I40E_GLPES_VFIP4RXFRAGSHI_IP4RXFRAGSHI_SHIFT 0
684#define I40E_GLPES_VFIP4RXFRAGSHI_IP4RXFRAGSHI_MASK (0xFFFF << I40E_GLPES_VFIP4RXFRAGSHI_IP4RXFRAGSHI_SHIFT)
685#define I40E_GLPES_VFIP4RXFRAGSLO(_i) (0x00018800 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
686#define I40E_GLPES_VFIP4RXFRAGSLO_MAX_INDEX 31
687#define I40E_GLPES_VFIP4RXFRAGSLO_IP4RXFRAGSLO_SHIFT 0
688#define I40E_GLPES_VFIP4RXFRAGSLO_IP4RXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4RXFRAGSLO_IP4RXFRAGSLO_SHIFT)
689#define I40E_GLPES_VFIP4RXMCOCTSHI(_i) (0x00018A04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
690#define I40E_GLPES_VFIP4RXMCOCTSHI_MAX_INDEX 31
691#define I40E_GLPES_VFIP4RXMCOCTSHI_IP4RXMCOCTSHI_SHIFT 0
692#define I40E_GLPES_VFIP4RXMCOCTSHI_IP4RXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4RXMCOCTSHI_IP4RXMCOCTSHI_SHIFT)
693#define I40E_GLPES_VFIP4RXMCOCTSLO(_i) (0x00018A00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
694#define I40E_GLPES_VFIP4RXMCOCTSLO_MAX_INDEX 31
695#define I40E_GLPES_VFIP4RXMCOCTSLO_IP4RXMCOCTSLO_SHIFT 0
696#define I40E_GLPES_VFIP4RXMCOCTSLO_IP4RXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4RXMCOCTSLO_IP4RXMCOCTSLO_SHIFT)
697#define I40E_GLPES_VFIP4RXMCPKTSHI(_i) (0x00018C04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
698#define I40E_GLPES_VFIP4RXMCPKTSHI_MAX_INDEX 31
699#define I40E_GLPES_VFIP4RXMCPKTSHI_IP4RXMCPKTSHI_SHIFT 0
700#define I40E_GLPES_VFIP4RXMCPKTSHI_IP4RXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4RXMCPKTSHI_IP4RXMCPKTSHI_SHIFT)
701#define I40E_GLPES_VFIP4RXMCPKTSLO(_i) (0x00018C00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
702#define I40E_GLPES_VFIP4RXMCPKTSLO_MAX_INDEX 31
703#define I40E_GLPES_VFIP4RXMCPKTSLO_IP4RXMCPKTSLO_SHIFT 0
704#define I40E_GLPES_VFIP4RXMCPKTSLO_IP4RXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4RXMCPKTSLO_IP4RXMCPKTSLO_SHIFT)
705#define I40E_GLPES_VFIP4RXOCTSHI(_i) (0x00018204 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
706#define I40E_GLPES_VFIP4RXOCTSHI_MAX_INDEX 31
707#define I40E_GLPES_VFIP4RXOCTSHI_IP4RXOCTSHI_SHIFT 0
708#define I40E_GLPES_VFIP4RXOCTSHI_IP4RXOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4RXOCTSHI_IP4RXOCTSHI_SHIFT)
709#define I40E_GLPES_VFIP4RXOCTSLO(_i) (0x00018200 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
710#define I40E_GLPES_VFIP4RXOCTSLO_MAX_INDEX 31
711#define I40E_GLPES_VFIP4RXOCTSLO_IP4RXOCTSLO_SHIFT 0
712#define I40E_GLPES_VFIP4RXOCTSLO_IP4RXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4RXOCTSLO_IP4RXOCTSLO_SHIFT)
713#define I40E_GLPES_VFIP4RXPKTSHI(_i) (0x00018404 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
714#define I40E_GLPES_VFIP4RXPKTSHI_MAX_INDEX 31
715#define I40E_GLPES_VFIP4RXPKTSHI_IP4RXPKTSHI_SHIFT 0
716#define I40E_GLPES_VFIP4RXPKTSHI_IP4RXPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4RXPKTSHI_IP4RXPKTSHI_SHIFT)
717#define I40E_GLPES_VFIP4RXPKTSLO(_i) (0x00018400 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
718#define I40E_GLPES_VFIP4RXPKTSLO_MAX_INDEX 31
719#define I40E_GLPES_VFIP4RXPKTSLO_IP4RXPKTSLO_SHIFT 0
720#define I40E_GLPES_VFIP4RXPKTSLO_IP4RXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4RXPKTSLO_IP4RXPKTSLO_SHIFT)
721#define I40E_GLPES_VFIP4RXTRUNC(_i) (0x00018700 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
722#define I40E_GLPES_VFIP4RXTRUNC_MAX_INDEX 31
723#define I40E_GLPES_VFIP4RXTRUNC_IP4RXTRUNC_SHIFT 0
724#define I40E_GLPES_VFIP4RXTRUNC_IP4RXTRUNC_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4RXTRUNC_IP4RXTRUNC_SHIFT)
725#define I40E_GLPES_VFIP4TXFRAGSHI(_i) (0x00019E04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
726#define I40E_GLPES_VFIP4TXFRAGSHI_MAX_INDEX 31
727#define I40E_GLPES_VFIP4TXFRAGSHI_IP4TXFRAGSHI_SHIFT 0
728#define I40E_GLPES_VFIP4TXFRAGSHI_IP4TXFRAGSHI_MASK (0xFFFF << I40E_GLPES_VFIP4TXFRAGSHI_IP4TXFRAGSHI_SHIFT)
729#define I40E_GLPES_VFIP4TXFRAGSLO(_i) (0x00019E00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
730#define I40E_GLPES_VFIP4TXFRAGSLO_MAX_INDEX 31
731#define I40E_GLPES_VFIP4TXFRAGSLO_IP4TXFRAGSLO_SHIFT 0
732#define I40E_GLPES_VFIP4TXFRAGSLO_IP4TXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4TXFRAGSLO_IP4TXFRAGSLO_SHIFT)
733#define I40E_GLPES_VFIP4TXMCOCTSHI(_i) (0x0001A004 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
734#define I40E_GLPES_VFIP4TXMCOCTSHI_MAX_INDEX 31
735#define I40E_GLPES_VFIP4TXMCOCTSHI_IP4TXMCOCTSHI_SHIFT 0
736#define I40E_GLPES_VFIP4TXMCOCTSHI_IP4TXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4TXMCOCTSHI_IP4TXMCOCTSHI_SHIFT)
737#define I40E_GLPES_VFIP4TXMCOCTSLO(_i) (0x0001A000 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
738#define I40E_GLPES_VFIP4TXMCOCTSLO_MAX_INDEX 31
739#define I40E_GLPES_VFIP4TXMCOCTSLO_IP4TXMCOCTSLO_SHIFT 0
740#define I40E_GLPES_VFIP4TXMCOCTSLO_IP4TXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4TXMCOCTSLO_IP4TXMCOCTSLO_SHIFT)
741#define I40E_GLPES_VFIP4TXMCPKTSHI(_i) (0x0001A204 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
742#define I40E_GLPES_VFIP4TXMCPKTSHI_MAX_INDEX 31
743#define I40E_GLPES_VFIP4TXMCPKTSHI_IP4TXMCPKTSHI_SHIFT 0
744#define I40E_GLPES_VFIP4TXMCPKTSHI_IP4TXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4TXMCPKTSHI_IP4TXMCPKTSHI_SHIFT)
745#define I40E_GLPES_VFIP4TXMCPKTSLO(_i) (0x0001A200 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
746#define I40E_GLPES_VFIP4TXMCPKTSLO_MAX_INDEX 31
747#define I40E_GLPES_VFIP4TXMCPKTSLO_IP4TXMCPKTSLO_SHIFT 0
748#define I40E_GLPES_VFIP4TXMCPKTSLO_IP4TXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4TXMCPKTSLO_IP4TXMCPKTSLO_SHIFT)
749#define I40E_GLPES_VFIP4TXNOROUTE(_i) (0x0001AE00 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
750#define I40E_GLPES_VFIP4TXNOROUTE_MAX_INDEX 31
751#define I40E_GLPES_VFIP4TXNOROUTE_IP4TXNOROUTE_SHIFT 0
752#define I40E_GLPES_VFIP4TXNOROUTE_IP4TXNOROUTE_MASK (0xFFFFFF << I40E_GLPES_VFIP4TXNOROUTE_IP4TXNOROUTE_SHIFT)
753#define I40E_GLPES_VFIP4TXOCTSHI(_i) (0x00019A04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
754#define I40E_GLPES_VFIP4TXOCTSHI_MAX_INDEX 31
755#define I40E_GLPES_VFIP4TXOCTSHI_IP4TXOCTSHI_SHIFT 0
756#define I40E_GLPES_VFIP4TXOCTSHI_IP4TXOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4TXOCTSHI_IP4TXOCTSHI_SHIFT)
757#define I40E_GLPES_VFIP4TXOCTSLO(_i) (0x00019A00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
758#define I40E_GLPES_VFIP4TXOCTSLO_MAX_INDEX 31
759#define I40E_GLPES_VFIP4TXOCTSLO_IP4TXOCTSLO_SHIFT 0
760#define I40E_GLPES_VFIP4TXOCTSLO_IP4TXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4TXOCTSLO_IP4TXOCTSLO_SHIFT)
761#define I40E_GLPES_VFIP4TXPKTSHI(_i) (0x00019C04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
762#define I40E_GLPES_VFIP4TXPKTSHI_MAX_INDEX 31
763#define I40E_GLPES_VFIP4TXPKTSHI_IP4TXPKTSHI_SHIFT 0
764#define I40E_GLPES_VFIP4TXPKTSHI_IP4TXPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP4TXPKTSHI_IP4TXPKTSHI_SHIFT)
765#define I40E_GLPES_VFIP4TXPKTSLO(_i) (0x00019C00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
766#define I40E_GLPES_VFIP4TXPKTSLO_MAX_INDEX 31
767#define I40E_GLPES_VFIP4TXPKTSLO_IP4TXPKTSLO_SHIFT 0
768#define I40E_GLPES_VFIP4TXPKTSLO_IP4TXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP4TXPKTSLO_IP4TXPKTSLO_SHIFT)
769#define I40E_GLPES_VFIP6RXDISCARD(_i) (0x00019200 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
770#define I40E_GLPES_VFIP6RXDISCARD_MAX_INDEX 31
771#define I40E_GLPES_VFIP6RXDISCARD_IP6RXDISCARD_SHIFT 0
772#define I40E_GLPES_VFIP6RXDISCARD_IP6RXDISCARD_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6RXDISCARD_IP6RXDISCARD_SHIFT)
773#define I40E_GLPES_VFIP6RXFRAGSHI(_i) (0x00019404 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
774#define I40E_GLPES_VFIP6RXFRAGSHI_MAX_INDEX 31
775#define I40E_GLPES_VFIP6RXFRAGSHI_IP6RXFRAGSHI_SHIFT 0
776#define I40E_GLPES_VFIP6RXFRAGSHI_IP6RXFRAGSHI_MASK (0xFFFF << I40E_GLPES_VFIP6RXFRAGSHI_IP6RXFRAGSHI_SHIFT)
777#define I40E_GLPES_VFIP6RXFRAGSLO(_i) (0x00019400 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
778#define I40E_GLPES_VFIP6RXFRAGSLO_MAX_INDEX 31
779#define I40E_GLPES_VFIP6RXFRAGSLO_IP6RXFRAGSLO_SHIFT 0
780#define I40E_GLPES_VFIP6RXFRAGSLO_IP6RXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6RXFRAGSLO_IP6RXFRAGSLO_SHIFT)
781#define I40E_GLPES_VFIP6RXMCOCTSHI(_i) (0x00019604 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
782#define I40E_GLPES_VFIP6RXMCOCTSHI_MAX_INDEX 31
783#define I40E_GLPES_VFIP6RXMCOCTSHI_IP6RXMCOCTSHI_SHIFT 0
784#define I40E_GLPES_VFIP6RXMCOCTSHI_IP6RXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6RXMCOCTSHI_IP6RXMCOCTSHI_SHIFT)
785#define I40E_GLPES_VFIP6RXMCOCTSLO(_i) (0x00019600 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
786#define I40E_GLPES_VFIP6RXMCOCTSLO_MAX_INDEX 31
787#define I40E_GLPES_VFIP6RXMCOCTSLO_IP6RXMCOCTSLO_SHIFT 0
788#define I40E_GLPES_VFIP6RXMCOCTSLO_IP6RXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6RXMCOCTSLO_IP6RXMCOCTSLO_SHIFT)
789#define I40E_GLPES_VFIP6RXMCPKTSHI(_i) (0x00019804 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
790#define I40E_GLPES_VFIP6RXMCPKTSHI_MAX_INDEX 31
791#define I40E_GLPES_VFIP6RXMCPKTSHI_IP6RXMCPKTSHI_SHIFT 0
792#define I40E_GLPES_VFIP6RXMCPKTSHI_IP6RXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6RXMCPKTSHI_IP6RXMCPKTSHI_SHIFT)
793#define I40E_GLPES_VFIP6RXMCPKTSLO(_i) (0x00019800 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
794#define I40E_GLPES_VFIP6RXMCPKTSLO_MAX_INDEX 31
795#define I40E_GLPES_VFIP6RXMCPKTSLO_IP6RXMCPKTSLO_SHIFT 0
796#define I40E_GLPES_VFIP6RXMCPKTSLO_IP6RXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6RXMCPKTSLO_IP6RXMCPKTSLO_SHIFT)
797#define I40E_GLPES_VFIP6RXOCTSHI(_i) (0x00018E04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
798#define I40E_GLPES_VFIP6RXOCTSHI_MAX_INDEX 31
799#define I40E_GLPES_VFIP6RXOCTSHI_IP6RXOCTSHI_SHIFT 0
800#define I40E_GLPES_VFIP6RXOCTSHI_IP6RXOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6RXOCTSHI_IP6RXOCTSHI_SHIFT)
801#define I40E_GLPES_VFIP6RXOCTSLO(_i) (0x00018E00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
802#define I40E_GLPES_VFIP6RXOCTSLO_MAX_INDEX 31
803#define I40E_GLPES_VFIP6RXOCTSLO_IP6RXOCTSLO_SHIFT 0
804#define I40E_GLPES_VFIP6RXOCTSLO_IP6RXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6RXOCTSLO_IP6RXOCTSLO_SHIFT)
805#define I40E_GLPES_VFIP6RXPKTSHI(_i) (0x00019004 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
806#define I40E_GLPES_VFIP6RXPKTSHI_MAX_INDEX 31
807#define I40E_GLPES_VFIP6RXPKTSHI_IP6RXPKTSHI_SHIFT 0
808#define I40E_GLPES_VFIP6RXPKTSHI_IP6RXPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6RXPKTSHI_IP6RXPKTSHI_SHIFT)
809#define I40E_GLPES_VFIP6RXPKTSLO(_i) (0x00019000 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
810#define I40E_GLPES_VFIP6RXPKTSLO_MAX_INDEX 31
811#define I40E_GLPES_VFIP6RXPKTSLO_IP6RXPKTSLO_SHIFT 0
812#define I40E_GLPES_VFIP6RXPKTSLO_IP6RXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6RXPKTSLO_IP6RXPKTSLO_SHIFT)
813#define I40E_GLPES_VFIP6RXTRUNC(_i) (0x00019300 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
814#define I40E_GLPES_VFIP6RXTRUNC_MAX_INDEX 31
815#define I40E_GLPES_VFIP6RXTRUNC_IP6RXTRUNC_SHIFT 0
816#define I40E_GLPES_VFIP6RXTRUNC_IP6RXTRUNC_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6RXTRUNC_IP6RXTRUNC_SHIFT)
817#define I40E_GLPES_VFIP6TXFRAGSHI(_i) (0x0001A804 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
818#define I40E_GLPES_VFIP6TXFRAGSHI_MAX_INDEX 31
819#define I40E_GLPES_VFIP6TXFRAGSHI_IP6TXFRAGSHI_SHIFT 0
820#define I40E_GLPES_VFIP6TXFRAGSHI_IP6TXFRAGSHI_MASK (0xFFFF << I40E_GLPES_VFIP6TXFRAGSHI_IP6TXFRAGSHI_SHIFT)
821#define I40E_GLPES_VFIP6TXFRAGSLO(_i) (0x0001A800 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
822#define I40E_GLPES_VFIP6TXFRAGSLO_MAX_INDEX 31
823#define I40E_GLPES_VFIP6TXFRAGSLO_IP6TXFRAGSLO_SHIFT 0
824#define I40E_GLPES_VFIP6TXFRAGSLO_IP6TXFRAGSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6TXFRAGSLO_IP6TXFRAGSLO_SHIFT)
825#define I40E_GLPES_VFIP6TXMCOCTSHI(_i) (0x0001AA04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
826#define I40E_GLPES_VFIP6TXMCOCTSHI_MAX_INDEX 31
827#define I40E_GLPES_VFIP6TXMCOCTSHI_IP6TXMCOCTSHI_SHIFT 0
828#define I40E_GLPES_VFIP6TXMCOCTSHI_IP6TXMCOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6TXMCOCTSHI_IP6TXMCOCTSHI_SHIFT)
829#define I40E_GLPES_VFIP6TXMCOCTSLO(_i) (0x0001AA00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
830#define I40E_GLPES_VFIP6TXMCOCTSLO_MAX_INDEX 31
831#define I40E_GLPES_VFIP6TXMCOCTSLO_IP6TXMCOCTSLO_SHIFT 0
832#define I40E_GLPES_VFIP6TXMCOCTSLO_IP6TXMCOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6TXMCOCTSLO_IP6TXMCOCTSLO_SHIFT)
833#define I40E_GLPES_VFIP6TXMCPKTSHI(_i) (0x0001AC04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
834#define I40E_GLPES_VFIP6TXMCPKTSHI_MAX_INDEX 31
835#define I40E_GLPES_VFIP6TXMCPKTSHI_IP6TXMCPKTSHI_SHIFT 0
836#define I40E_GLPES_VFIP6TXMCPKTSHI_IP6TXMCPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6TXMCPKTSHI_IP6TXMCPKTSHI_SHIFT)
837#define I40E_GLPES_VFIP6TXMCPKTSLO(_i) (0x0001AC00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
838#define I40E_GLPES_VFIP6TXMCPKTSLO_MAX_INDEX 31
839#define I40E_GLPES_VFIP6TXMCPKTSLO_IP6TXMCPKTSLO_SHIFT 0
840#define I40E_GLPES_VFIP6TXMCPKTSLO_IP6TXMCPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6TXMCPKTSLO_IP6TXMCPKTSLO_SHIFT)
841#define I40E_GLPES_VFIP6TXNOROUTE(_i) (0x0001AF00 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
842#define I40E_GLPES_VFIP6TXNOROUTE_MAX_INDEX 31
843#define I40E_GLPES_VFIP6TXNOROUTE_IP6TXNOROUTE_SHIFT 0
844#define I40E_GLPES_VFIP6TXNOROUTE_IP6TXNOROUTE_MASK (0xFFFFFF << I40E_GLPES_VFIP6TXNOROUTE_IP6TXNOROUTE_SHIFT)
845#define I40E_GLPES_VFIP6TXOCTSHI(_i) (0x0001A404 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
846#define I40E_GLPES_VFIP6TXOCTSHI_MAX_INDEX 31
847#define I40E_GLPES_VFIP6TXOCTSHI_IP6TXOCTSHI_SHIFT 0
848#define I40E_GLPES_VFIP6TXOCTSHI_IP6TXOCTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6TXOCTSHI_IP6TXOCTSHI_SHIFT)
849#define I40E_GLPES_VFIP6TXOCTSLO(_i) (0x0001A400 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
850#define I40E_GLPES_VFIP6TXOCTSLO_MAX_INDEX 31
851#define I40E_GLPES_VFIP6TXOCTSLO_IP6TXOCTSLO_SHIFT 0
852#define I40E_GLPES_VFIP6TXOCTSLO_IP6TXOCTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6TXOCTSLO_IP6TXOCTSLO_SHIFT)
853#define I40E_GLPES_VFIP6TXPKTSHI(_i) (0x0001A604 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
854#define I40E_GLPES_VFIP6TXPKTSHI_MAX_INDEX 31
855#define I40E_GLPES_VFIP6TXPKTSHI_IP6TXPKTSHI_SHIFT 0
856#define I40E_GLPES_VFIP6TXPKTSHI_IP6TXPKTSHI_MASK (0xFFFF << I40E_GLPES_VFIP6TXPKTSHI_IP6TXPKTSHI_SHIFT)
857#define I40E_GLPES_VFIP6TXPKTSLO(_i) (0x0001A600 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
858#define I40E_GLPES_VFIP6TXPKTSLO_MAX_INDEX 31
859#define I40E_GLPES_VFIP6TXPKTSLO_IP6TXPKTSLO_SHIFT 0
860#define I40E_GLPES_VFIP6TXPKTSLO_IP6TXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFIP6TXPKTSLO_IP6TXPKTSLO_SHIFT)
861#define I40E_GLPES_VFRDMARXRDSHI(_i) (0x0001BE04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
862#define I40E_GLPES_VFRDMARXRDSHI_MAX_INDEX 31
863#define I40E_GLPES_VFRDMARXRDSHI_RDMARXRDSHI_SHIFT 0
864#define I40E_GLPES_VFRDMARXRDSHI_RDMARXRDSHI_MASK (0xFFFF << I40E_GLPES_VFRDMARXRDSHI_RDMARXRDSHI_SHIFT)
865#define I40E_GLPES_VFRDMARXRDSLO(_i) (0x0001BE00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
866#define I40E_GLPES_VFRDMARXRDSLO_MAX_INDEX 31
867#define I40E_GLPES_VFRDMARXRDSLO_RDMARXRDSLO_SHIFT 0
868#define I40E_GLPES_VFRDMARXRDSLO_RDMARXRDSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMARXRDSLO_RDMARXRDSLO_SHIFT)
869#define I40E_GLPES_VFRDMARXSNDSHI(_i) (0x0001C004 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
870#define I40E_GLPES_VFRDMARXSNDSHI_MAX_INDEX 31
871#define I40E_GLPES_VFRDMARXSNDSHI_RDMARXSNDSHI_SHIFT 0
872#define I40E_GLPES_VFRDMARXSNDSHI_RDMARXSNDSHI_MASK (0xFFFF << I40E_GLPES_VFRDMARXSNDSHI_RDMARXSNDSHI_SHIFT)
873#define I40E_GLPES_VFRDMARXSNDSLO(_i) (0x0001C000 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
874#define I40E_GLPES_VFRDMARXSNDSLO_MAX_INDEX 31
875#define I40E_GLPES_VFRDMARXSNDSLO_RDMARXSNDSLO_SHIFT 0
876#define I40E_GLPES_VFRDMARXSNDSLO_RDMARXSNDSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMARXSNDSLO_RDMARXSNDSLO_SHIFT)
877#define I40E_GLPES_VFRDMARXWRSHI(_i) (0x0001BC04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
878#define I40E_GLPES_VFRDMARXWRSHI_MAX_INDEX 31
879#define I40E_GLPES_VFRDMARXWRSHI_RDMARXWRSHI_SHIFT 0
880#define I40E_GLPES_VFRDMARXWRSHI_RDMARXWRSHI_MASK (0xFFFF << I40E_GLPES_VFRDMARXWRSHI_RDMARXWRSHI_SHIFT)
881#define I40E_GLPES_VFRDMARXWRSLO(_i) (0x0001BC00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
882#define I40E_GLPES_VFRDMARXWRSLO_MAX_INDEX 31
883#define I40E_GLPES_VFRDMARXWRSLO_RDMARXWRSLO_SHIFT 0
884#define I40E_GLPES_VFRDMARXWRSLO_RDMARXWRSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMARXWRSLO_RDMARXWRSLO_SHIFT)
885#define I40E_GLPES_VFRDMATXRDSHI(_i) (0x0001C404 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
886#define I40E_GLPES_VFRDMATXRDSHI_MAX_INDEX 31
887#define I40E_GLPES_VFRDMATXRDSHI_RDMARXRDSHI_SHIFT 0
888#define I40E_GLPES_VFRDMATXRDSHI_RDMARXRDSHI_MASK (0xFFFF << I40E_GLPES_VFRDMATXRDSHI_RDMARXRDSHI_SHIFT)
889#define I40E_GLPES_VFRDMATXRDSLO(_i) (0x0001C400 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
890#define I40E_GLPES_VFRDMATXRDSLO_MAX_INDEX 31
891#define I40E_GLPES_VFRDMATXRDSLO_RDMARXRDSLO_SHIFT 0
892#define I40E_GLPES_VFRDMATXRDSLO_RDMARXRDSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMATXRDSLO_RDMARXRDSLO_SHIFT)
893#define I40E_GLPES_VFRDMATXSNDSHI(_i) (0x0001C604 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
894#define I40E_GLPES_VFRDMATXSNDSHI_MAX_INDEX 31
895#define I40E_GLPES_VFRDMATXSNDSHI_RDMARXSNDSHI_SHIFT 0
896#define I40E_GLPES_VFRDMATXSNDSHI_RDMARXSNDSHI_MASK (0xFFFF << I40E_GLPES_VFRDMATXSNDSHI_RDMARXSNDSHI_SHIFT)
897#define I40E_GLPES_VFRDMATXSNDSLO(_i) (0x0001C600 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
898#define I40E_GLPES_VFRDMATXSNDSLO_MAX_INDEX 31
899#define I40E_GLPES_VFRDMATXSNDSLO_RDMARXSNDSLO_SHIFT 0
900#define I40E_GLPES_VFRDMATXSNDSLO_RDMARXSNDSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMATXSNDSLO_RDMARXSNDSLO_SHIFT)
901#define I40E_GLPES_VFRDMATXWRSHI(_i) (0x0001C204 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
902#define I40E_GLPES_VFRDMATXWRSHI_MAX_INDEX 31
903#define I40E_GLPES_VFRDMATXWRSHI_RDMARXWRSHI_SHIFT 0
904#define I40E_GLPES_VFRDMATXWRSHI_RDMARXWRSHI_MASK (0xFFFF << I40E_GLPES_VFRDMATXWRSHI_RDMARXWRSHI_SHIFT)
905#define I40E_GLPES_VFRDMATXWRSLO(_i) (0x0001C200 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
906#define I40E_GLPES_VFRDMATXWRSLO_MAX_INDEX 31
907#define I40E_GLPES_VFRDMATXWRSLO_RDMARXWRSLO_SHIFT 0
908#define I40E_GLPES_VFRDMATXWRSLO_RDMARXWRSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMATXWRSLO_RDMARXWRSLO_SHIFT)
909#define I40E_GLPES_VFRDMAVBNDHI(_i) (0x0001C804 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
910#define I40E_GLPES_VFRDMAVBNDHI_MAX_INDEX 31
911#define I40E_GLPES_VFRDMAVBNDHI_RDMAVBNDHI_SHIFT 0
912#define I40E_GLPES_VFRDMAVBNDHI_RDMAVBNDHI_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMAVBNDHI_RDMAVBNDHI_SHIFT)
913#define I40E_GLPES_VFRDMAVBNDLO(_i) (0x0001C800 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
914#define I40E_GLPES_VFRDMAVBNDLO_MAX_INDEX 31
915#define I40E_GLPES_VFRDMAVBNDLO_RDMAVBNDLO_SHIFT 0
916#define I40E_GLPES_VFRDMAVBNDLO_RDMAVBNDLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMAVBNDLO_RDMAVBNDLO_SHIFT)
917#define I40E_GLPES_VFRDMAVINVHI(_i) (0x0001CA04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
918#define I40E_GLPES_VFRDMAVINVHI_MAX_INDEX 31
919#define I40E_GLPES_VFRDMAVINVHI_RDMAVINVHI_SHIFT 0
920#define I40E_GLPES_VFRDMAVINVHI_RDMAVINVHI_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMAVINVHI_RDMAVINVHI_SHIFT)
921#define I40E_GLPES_VFRDMAVINVLO(_i) (0x0001CA00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
922#define I40E_GLPES_VFRDMAVINVLO_MAX_INDEX 31
923#define I40E_GLPES_VFRDMAVINVLO_RDMAVINVLO_SHIFT 0
924#define I40E_GLPES_VFRDMAVINVLO_RDMAVINVLO_MASK (0xFFFFFFFF << I40E_GLPES_VFRDMAVINVLO_RDMAVINVLO_SHIFT)
925#define I40E_GLPES_VFRXVLANERR(_i) (0x00018000 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
926#define I40E_GLPES_VFRXVLANERR_MAX_INDEX 31
927#define I40E_GLPES_VFRXVLANERR_RXVLANERR_SHIFT 0
928#define I40E_GLPES_VFRXVLANERR_RXVLANERR_MASK (0xFFFFFF << I40E_GLPES_VFRXVLANERR_RXVLANERR_SHIFT)
929#define I40E_GLPES_VFTCPRTXSEG(_i) (0x0001B600 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
930#define I40E_GLPES_VFTCPRTXSEG_MAX_INDEX 31
931#define I40E_GLPES_VFTCPRTXSEG_TCPRTXSEG_SHIFT 0
932#define I40E_GLPES_VFTCPRTXSEG_TCPRTXSEG_MASK (0xFFFFFFFF << I40E_GLPES_VFTCPRTXSEG_TCPRTXSEG_SHIFT)
933#define I40E_GLPES_VFTCPRXOPTERR(_i) (0x0001B200 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
934#define I40E_GLPES_VFTCPRXOPTERR_MAX_INDEX 31
935#define I40E_GLPES_VFTCPRXOPTERR_TCPRXOPTERR_SHIFT 0
936#define I40E_GLPES_VFTCPRXOPTERR_TCPRXOPTERR_MASK (0xFFFFFF << I40E_GLPES_VFTCPRXOPTERR_TCPRXOPTERR_SHIFT)
937#define I40E_GLPES_VFTCPRXPROTOERR(_i) (0x0001B300 + ((_i) * 4)) /* _i=0...31 */ /* Reset: PE_CORER */
938#define I40E_GLPES_VFTCPRXPROTOERR_MAX_INDEX 31
939#define I40E_GLPES_VFTCPRXPROTOERR_TCPRXPROTOERR_SHIFT 0
940#define I40E_GLPES_VFTCPRXPROTOERR_TCPRXPROTOERR_MASK (0xFFFFFF << I40E_GLPES_VFTCPRXPROTOERR_TCPRXPROTOERR_SHIFT)
941#define I40E_GLPES_VFTCPRXSEGSHI(_i) (0x0001B004 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
942#define I40E_GLPES_VFTCPRXSEGSHI_MAX_INDEX 31
943#define I40E_GLPES_VFTCPRXSEGSHI_TCPRXSEGSHI_SHIFT 0
944#define I40E_GLPES_VFTCPRXSEGSHI_TCPRXSEGSHI_MASK (0xFFFF << I40E_GLPES_VFTCPRXSEGSHI_TCPRXSEGSHI_SHIFT)
945#define I40E_GLPES_VFTCPRXSEGSLO(_i) (0x0001B000 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
946#define I40E_GLPES_VFTCPRXSEGSLO_MAX_INDEX 31
947#define I40E_GLPES_VFTCPRXSEGSLO_TCPRXSEGSLO_SHIFT 0
948#define I40E_GLPES_VFTCPRXSEGSLO_TCPRXSEGSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFTCPRXSEGSLO_TCPRXSEGSLO_SHIFT)
949#define I40E_GLPES_VFTCPTXSEGHI(_i) (0x0001B404 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
950#define I40E_GLPES_VFTCPTXSEGHI_MAX_INDEX 31
951#define I40E_GLPES_VFTCPTXSEGHI_TCPTXSEGHI_SHIFT 0
952#define I40E_GLPES_VFTCPTXSEGHI_TCPTXSEGHI_MASK (0xFFFF << I40E_GLPES_VFTCPTXSEGHI_TCPTXSEGHI_SHIFT)
953#define I40E_GLPES_VFTCPTXSEGLO(_i) (0x0001B400 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
954#define I40E_GLPES_VFTCPTXSEGLO_MAX_INDEX 31
955#define I40E_GLPES_VFTCPTXSEGLO_TCPTXSEGLO_SHIFT 0
956#define I40E_GLPES_VFTCPTXSEGLO_TCPTXSEGLO_MASK (0xFFFFFFFF << I40E_GLPES_VFTCPTXSEGLO_TCPTXSEGLO_SHIFT)
957#define I40E_GLPES_VFUDPRXPKTSHI(_i) (0x0001B804 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
958#define I40E_GLPES_VFUDPRXPKTSHI_MAX_INDEX 31
959#define I40E_GLPES_VFUDPRXPKTSHI_UDPRXPKTSHI_SHIFT 0
960#define I40E_GLPES_VFUDPRXPKTSHI_UDPRXPKTSHI_MASK (0xFFFF << I40E_GLPES_VFUDPRXPKTSHI_UDPRXPKTSHI_SHIFT)
961#define I40E_GLPES_VFUDPRXPKTSLO(_i) (0x0001B800 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
962#define I40E_GLPES_VFUDPRXPKTSLO_MAX_INDEX 31
963#define I40E_GLPES_VFUDPRXPKTSLO_UDPRXPKTSLO_SHIFT 0
964#define I40E_GLPES_VFUDPRXPKTSLO_UDPRXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFUDPRXPKTSLO_UDPRXPKTSLO_SHIFT)
965#define I40E_GLPES_VFUDPTXPKTSHI(_i) (0x0001BA04 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
966#define I40E_GLPES_VFUDPTXPKTSHI_MAX_INDEX 31
967#define I40E_GLPES_VFUDPTXPKTSHI_UDPTXPKTSHI_SHIFT 0
968#define I40E_GLPES_VFUDPTXPKTSHI_UDPTXPKTSHI_MASK (0xFFFF << I40E_GLPES_VFUDPTXPKTSHI_UDPTXPKTSHI_SHIFT)
969#define I40E_GLPES_VFUDPTXPKTSLO(_i) (0x0001BA00 + ((_i) * 8)) /* _i=0...31 */ /* Reset: PE_CORER */
970#define I40E_GLPES_VFUDPTXPKTSLO_MAX_INDEX 31
971#define I40E_GLPES_VFUDPTXPKTSLO_UDPTXPKTSLO_SHIFT 0
972#define I40E_GLPES_VFUDPTXPKTSLO_UDPTXPKTSLO_MASK (0xFFFFFFFF << I40E_GLPES_VFUDPTXPKTSLO_UDPTXPKTSLO_SHIFT)
973
974#define I40E_VFPE_AEQALLOC1 0x0000A400 /* Reset: VFR */
975#define I40E_VFPE_AEQALLOC1_AECOUNT_SHIFT 0
976#define I40E_VFPE_AEQALLOC1_AECOUNT_MASK (0xFFFFFFFF << I40E_VFPE_AEQALLOC1_AECOUNT_SHIFT)
977#define I40E_VFPE_CCQPHIGH1 0x00009800 /* Reset: VFR */
978#define I40E_VFPE_CCQPHIGH1_PECCQPHIGH_SHIFT 0
979#define I40E_VFPE_CCQPHIGH1_PECCQPHIGH_MASK (0xFFFFFFFF << I40E_VFPE_CCQPHIGH1_PECCQPHIGH_SHIFT)
980#define I40E_VFPE_CCQPLOW1 0x0000AC00 /* Reset: VFR */
981#define I40E_VFPE_CCQPLOW1_PECCQPLOW_SHIFT 0
982#define I40E_VFPE_CCQPLOW1_PECCQPLOW_MASK (0xFFFFFFFF << I40E_VFPE_CCQPLOW1_PECCQPLOW_SHIFT)
983#define I40E_VFPE_CCQPSTATUS1 0x0000B800 /* Reset: VFR */
984#define I40E_VFPE_CCQPSTATUS1_CCQP_DONE_SHIFT 0
985#define I40E_VFPE_CCQPSTATUS1_CCQP_DONE_MASK (0x1 << I40E_VFPE_CCQPSTATUS1_CCQP_DONE_SHIFT)
986#define I40E_VFPE_CCQPSTATUS1_HMC_PROFILE_SHIFT 4
987#define I40E_VFPE_CCQPSTATUS1_HMC_PROFILE_MASK (0x7 << I40E_VFPE_CCQPSTATUS1_HMC_PROFILE_SHIFT)
988#define I40E_VFPE_CCQPSTATUS1_RDMA_EN_VFS_SHIFT 16
989#define I40E_VFPE_CCQPSTATUS1_RDMA_EN_VFS_MASK (0x3F << I40E_VFPE_CCQPSTATUS1_RDMA_EN_VFS_SHIFT)
990#define I40E_VFPE_CCQPSTATUS1_CCQP_ERR_SHIFT 31
991#define I40E_VFPE_CCQPSTATUS1_CCQP_ERR_MASK (0x1 << I40E_VFPE_CCQPSTATUS1_CCQP_ERR_SHIFT)
992#define I40E_VFPE_CQACK1 0x0000B000 /* Reset: VFR */
993#define I40E_VFPE_CQACK1_PECQID_SHIFT 0
994#define I40E_VFPE_CQACK1_PECQID_MASK (0x1FFFF << I40E_VFPE_CQACK1_PECQID_SHIFT)
995#define I40E_VFPE_CQARM1 0x0000B400 /* Reset: VFR */
996#define I40E_VFPE_CQARM1_PECQID_SHIFT 0
997#define I40E_VFPE_CQARM1_PECQID_MASK (0x1FFFF << I40E_VFPE_CQARM1_PECQID_SHIFT)
998#define I40E_VFPE_CQPDB1 0x0000BC00 /* Reset: VFR */
999#define I40E_VFPE_CQPDB1_WQHEAD_SHIFT 0
1000#define I40E_VFPE_CQPDB1_WQHEAD_MASK (0x7FF << I40E_VFPE_CQPDB1_WQHEAD_SHIFT)
1001#define I40E_VFPE_CQPERRCODES1 0x00009C00 /* Reset: VFR */
1002#define I40E_VFPE_CQPERRCODES1_CQP_MINOR_CODE_SHIFT 0
1003#define I40E_VFPE_CQPERRCODES1_CQP_MINOR_CODE_MASK (0xFFFF << I40E_VFPE_CQPERRCODES1_CQP_MINOR_CODE_SHIFT)
1004#define I40E_VFPE_CQPERRCODES1_CQP_MAJOR_CODE_SHIFT 16
1005#define I40E_VFPE_CQPERRCODES1_CQP_MAJOR_CODE_MASK (0xFFFF << I40E_VFPE_CQPERRCODES1_CQP_MAJOR_CODE_SHIFT)
1006#define I40E_VFPE_CQPTAIL1 0x0000A000 /* Reset: VFR */
1007#define I40E_VFPE_CQPTAIL1_WQTAIL_SHIFT 0
1008#define I40E_VFPE_CQPTAIL1_WQTAIL_MASK (0x7FF << I40E_VFPE_CQPTAIL1_WQTAIL_SHIFT)
1009#define I40E_VFPE_CQPTAIL1_CQP_OP_ERR_SHIFT 31
1010#define I40E_VFPE_CQPTAIL1_CQP_OP_ERR_MASK (0x1 << I40E_VFPE_CQPTAIL1_CQP_OP_ERR_SHIFT)
1011#define I40E_VFPE_IPCONFIG01 0x00008C00 /* Reset: VFR */
1012#define I40E_VFPE_IPCONFIG01_PEIPID_SHIFT 0
1013#define I40E_VFPE_IPCONFIG01_PEIPID_MASK (0xFFFF << I40E_VFPE_IPCONFIG01_PEIPID_SHIFT)
1014#define I40E_VFPE_IPCONFIG01_USEENTIREIDRANGE_SHIFT 16
1015#define I40E_VFPE_IPCONFIG01_USEENTIREIDRANGE_MASK (0x1 << I40E_VFPE_IPCONFIG01_USEENTIREIDRANGE_SHIFT)
1016#define I40E_VFPE_MRTEIDXMASK1 0x00009000 /* Reset: VFR */
1017#define I40E_VFPE_MRTEIDXMASK1_MRTEIDXMASKBITS_SHIFT 0
1018#define I40E_VFPE_MRTEIDXMASK1_MRTEIDXMASKBITS_MASK (0x1F << I40E_VFPE_MRTEIDXMASK1_MRTEIDXMASKBITS_SHIFT)
1019#define I40E_VFPE_RCVUNEXPECTEDERROR1 0x00009400 /* Reset: VFR */
1020#define I40E_VFPE_RCVUNEXPECTEDERROR1_TCP_RX_UNEXP_ERR_SHIFT 0
1021#define I40E_VFPE_RCVUNEXPECTEDERROR1_TCP_RX_UNEXP_ERR_MASK (0xFFFFFF << I40E_VFPE_RCVUNEXPECTEDERROR1_TCP_RX_UNEXP_ERR_SHIFT)
1022#define I40E_VFPE_TCPNOWTIMER1 0x0000A800 /* Reset: VFR */
1023#define I40E_VFPE_TCPNOWTIMER1_TCP_NOW_SHIFT 0
1024#define I40E_VFPE_TCPNOWTIMER1_TCP_NOW_MASK (0xFFFFFFFF << I40E_VFPE_TCPNOWTIMER1_TCP_NOW_SHIFT)
1025#define I40E_VFPE_WQEALLOC1 0x0000C000 /* Reset: VFR */
1026#define I40E_VFPE_WQEALLOC1_PEQPID_SHIFT 0
1027#define I40E_VFPE_WQEALLOC1_PEQPID_MASK (0x3FFFF << I40E_VFPE_WQEALLOC1_PEQPID_SHIFT)
1028#define I40E_VFPE_WQEALLOC1_WQE_DESC_INDEX_SHIFT 20
1029#define I40E_VFPE_WQEALLOC1_WQE_DESC_INDEX_MASK (0xFFF << I40E_VFPE_WQEALLOC1_WQE_DESC_INDEX_SHIFT)
1030#endif /* I40IW_REGISTER_H */
diff --git a/drivers/infiniband/hw/i40iw/i40iw_status.h b/drivers/infiniband/hw/i40iw/i40iw_status.h
new file mode 100644
index 000000000000..b0110c15e044
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_status.h
@@ -0,0 +1,100 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_STATUS_H
36#define I40IW_STATUS_H
37
38/* Error Codes */
39enum i40iw_status_code {
40 I40IW_SUCCESS = 0,
41 I40IW_ERR_NVM = -1,
42 I40IW_ERR_NVM_CHECKSUM = -2,
43 I40IW_ERR_CONFIG = -4,
44 I40IW_ERR_PARAM = -5,
45 I40IW_ERR_DEVICE_NOT_SUPPORTED = -6,
46 I40IW_ERR_RESET_FAILED = -7,
47 I40IW_ERR_SWFW_SYNC = -8,
48 I40IW_ERR_NO_MEMORY = -9,
49 I40IW_ERR_BAD_PTR = -10,
50 I40IW_ERR_INVALID_PD_ID = -11,
51 I40IW_ERR_INVALID_QP_ID = -12,
52 I40IW_ERR_INVALID_CQ_ID = -13,
53 I40IW_ERR_INVALID_CEQ_ID = -14,
54 I40IW_ERR_INVALID_AEQ_ID = -15,
55 I40IW_ERR_INVALID_SIZE = -16,
56 I40IW_ERR_INVALID_ARP_INDEX = -17,
57 I40IW_ERR_INVALID_FPM_FUNC_ID = -18,
58 I40IW_ERR_QP_INVALID_MSG_SIZE = -19,
59 I40IW_ERR_QP_TOOMANY_WRS_POSTED = -20,
60 I40IW_ERR_INVALID_FRAG_COUNT = -21,
61 I40IW_ERR_QUEUE_EMPTY = -22,
62 I40IW_ERR_INVALID_ALIGNMENT = -23,
63 I40IW_ERR_FLUSHED_QUEUE = -24,
64 I40IW_ERR_INVALID_PUSH_PAGE_INDEX = -25,
65 I40IW_ERR_INVALID_IMM_DATA_SIZE = -26,
66 I40IW_ERR_TIMEOUT = -27,
67 I40IW_ERR_OPCODE_MISMATCH = -28,
68 I40IW_ERR_CQP_COMPL_ERROR = -29,
69 I40IW_ERR_INVALID_VF_ID = -30,
70 I40IW_ERR_INVALID_HMCFN_ID = -31,
71 I40IW_ERR_BACKING_PAGE_ERROR = -32,
72 I40IW_ERR_NO_PBLCHUNKS_AVAILABLE = -33,
73 I40IW_ERR_INVALID_PBLE_INDEX = -34,
74 I40IW_ERR_INVALID_SD_INDEX = -35,
75 I40IW_ERR_INVALID_PAGE_DESC_INDEX = -36,
76 I40IW_ERR_INVALID_SD_TYPE = -37,
77 I40IW_ERR_MEMCPY_FAILED = -38,
78 I40IW_ERR_INVALID_HMC_OBJ_INDEX = -39,
79 I40IW_ERR_INVALID_HMC_OBJ_COUNT = -40,
80 I40IW_ERR_INVALID_SRQ_ARM_LIMIT = -41,
81 I40IW_ERR_SRQ_ENABLED = -42,
82 I40IW_ERR_BUF_TOO_SHORT = -43,
83 I40IW_ERR_BAD_IWARP_CQE = -44,
84 I40IW_ERR_NVM_BLANK_MODE = -45,
85 I40IW_ERR_NOT_IMPLEMENTED = -46,
86 I40IW_ERR_PE_DOORBELL_NOT_ENABLED = -47,
87 I40IW_ERR_NOT_READY = -48,
88 I40IW_NOT_SUPPORTED = -49,
89 I40IW_ERR_FIRMWARE_API_VERSION = -50,
90 I40IW_ERR_RING_FULL = -51,
91 I40IW_ERR_MPA_CRC = -61,
92 I40IW_ERR_NO_TXBUFS = -62,
93 I40IW_ERR_SEQ_NUM = -63,
94 I40IW_ERR_list_empty = -64,
95 I40IW_ERR_INVALID_MAC_ADDR = -65,
96 I40IW_ERR_BAD_STAG = -66,
97 I40IW_ERR_CQ_COMPL_ERROR = -67,
98
99};
100#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_type.h b/drivers/infiniband/hw/i40iw/i40iw_type.h
new file mode 100644
index 000000000000..edb3a8c8267a
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_type.h
@@ -0,0 +1,1312 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_TYPE_H
36#define I40IW_TYPE_H
37#include "i40iw_user.h"
38#include "i40iw_hmc.h"
39#include "i40iw_vf.h"
40#include "i40iw_virtchnl.h"
41
42struct i40iw_cqp_sq_wqe {
43 u64 buf[I40IW_CQP_WQE_SIZE];
44};
45
46struct i40iw_sc_aeqe {
47 u64 buf[I40IW_AEQE_SIZE];
48};
49
50struct i40iw_ceqe {
51 u64 buf[I40IW_CEQE_SIZE];
52};
53
54struct i40iw_cqp_ctx {
55 u64 buf[I40IW_CQP_CTX_SIZE];
56};
57
58struct i40iw_cq_shadow_area {
59 u64 buf[I40IW_SHADOW_AREA_SIZE];
60};
61
62struct i40iw_sc_dev;
63struct i40iw_hmc_info;
64struct i40iw_dev_pestat;
65
66struct i40iw_cqp_ops;
67struct i40iw_ccq_ops;
68struct i40iw_ceq_ops;
69struct i40iw_aeq_ops;
70struct i40iw_mr_ops;
71struct i40iw_cqp_misc_ops;
72struct i40iw_pd_ops;
73struct i40iw_priv_qp_ops;
74struct i40iw_priv_cq_ops;
75struct i40iw_hmc_ops;
76
77enum i40iw_resource_indicator_type {
78 I40IW_RSRC_INDICATOR_TYPE_ADAPTER = 0,
79 I40IW_RSRC_INDICATOR_TYPE_CQ,
80 I40IW_RSRC_INDICATOR_TYPE_QP,
81 I40IW_RSRC_INDICATOR_TYPE_SRQ
82};
83
84enum i40iw_hdrct_flags {
85 DDP_LEN_FLAG = 0x80,
86 DDP_HDR_FLAG = 0x40,
87 RDMA_HDR_FLAG = 0x20
88};
89
90enum i40iw_term_layers {
91 LAYER_RDMA = 0,
92 LAYER_DDP = 1,
93 LAYER_MPA = 2
94};
95
96enum i40iw_term_error_types {
97 RDMAP_REMOTE_PROT = 1,
98 RDMAP_REMOTE_OP = 2,
99 DDP_CATASTROPHIC = 0,
100 DDP_TAGGED_BUFFER = 1,
101 DDP_UNTAGGED_BUFFER = 2,
102 DDP_LLP = 3
103};
104
105enum i40iw_term_rdma_errors {
106 RDMAP_INV_STAG = 0x00,
107 RDMAP_INV_BOUNDS = 0x01,
108 RDMAP_ACCESS = 0x02,
109 RDMAP_UNASSOC_STAG = 0x03,
110 RDMAP_TO_WRAP = 0x04,
111 RDMAP_INV_RDMAP_VER = 0x05,
112 RDMAP_UNEXPECTED_OP = 0x06,
113 RDMAP_CATASTROPHIC_LOCAL = 0x07,
114 RDMAP_CATASTROPHIC_GLOBAL = 0x08,
115 RDMAP_CANT_INV_STAG = 0x09,
116 RDMAP_UNSPECIFIED = 0xff
117};
118
119enum i40iw_term_ddp_errors {
120 DDP_CATASTROPHIC_LOCAL = 0x00,
121 DDP_TAGGED_INV_STAG = 0x00,
122 DDP_TAGGED_BOUNDS = 0x01,
123 DDP_TAGGED_UNASSOC_STAG = 0x02,
124 DDP_TAGGED_TO_WRAP = 0x03,
125 DDP_TAGGED_INV_DDP_VER = 0x04,
126 DDP_UNTAGGED_INV_QN = 0x01,
127 DDP_UNTAGGED_INV_MSN_NO_BUF = 0x02,
128 DDP_UNTAGGED_INV_MSN_RANGE = 0x03,
129 DDP_UNTAGGED_INV_MO = 0x04,
130 DDP_UNTAGGED_INV_TOO_LONG = 0x05,
131 DDP_UNTAGGED_INV_DDP_VER = 0x06
132};
133
134enum i40iw_term_mpa_errors {
135 MPA_CLOSED = 0x01,
136 MPA_CRC = 0x02,
137 MPA_MARKER = 0x03,
138 MPA_REQ_RSP = 0x04,
139};
140
141enum i40iw_flush_opcode {
142 FLUSH_INVALID = 0,
143 FLUSH_PROT_ERR,
144 FLUSH_REM_ACCESS_ERR,
145 FLUSH_LOC_QP_OP_ERR,
146 FLUSH_REM_OP_ERR,
147 FLUSH_LOC_LEN_ERR,
148 FLUSH_GENERAL_ERR,
149 FLUSH_FATAL_ERR
150};
151
152enum i40iw_term_eventtypes {
153 TERM_EVENT_QP_FATAL,
154 TERM_EVENT_QP_ACCESS_ERR
155};
156
157struct i40iw_terminate_hdr {
158 u8 layer_etype;
159 u8 error_code;
160 u8 hdrct;
161 u8 rsvd;
162};
163
164enum i40iw_debug_flag {
165 I40IW_DEBUG_NONE = 0x00000000,
166 I40IW_DEBUG_ERR = 0x00000001,
167 I40IW_DEBUG_INIT = 0x00000002,
168 I40IW_DEBUG_DEV = 0x00000004,
169 I40IW_DEBUG_CM = 0x00000008,
170 I40IW_DEBUG_VERBS = 0x00000010,
171 I40IW_DEBUG_PUDA = 0x00000020,
172 I40IW_DEBUG_ILQ = 0x00000040,
173 I40IW_DEBUG_IEQ = 0x00000080,
174 I40IW_DEBUG_QP = 0x00000100,
175 I40IW_DEBUG_CQ = 0x00000200,
176 I40IW_DEBUG_MR = 0x00000400,
177 I40IW_DEBUG_PBLE = 0x00000800,
178 I40IW_DEBUG_WQE = 0x00001000,
179 I40IW_DEBUG_AEQ = 0x00002000,
180 I40IW_DEBUG_CQP = 0x00004000,
181 I40IW_DEBUG_HMC = 0x00008000,
182 I40IW_DEBUG_USER = 0x00010000,
183 I40IW_DEBUG_VIRT = 0x00020000,
184 I40IW_DEBUG_DCB = 0x00040000,
185 I40IW_DEBUG_CQE = 0x00800000,
186 I40IW_DEBUG_ALL = 0xFFFFFFFF
187};
188
189enum i40iw_hw_stat_index_32b {
190 I40IW_HW_STAT_INDEX_IP4RXDISCARD = 0,
191 I40IW_HW_STAT_INDEX_IP4RXTRUNC,
192 I40IW_HW_STAT_INDEX_IP4TXNOROUTE,
193 I40IW_HW_STAT_INDEX_IP6RXDISCARD,
194 I40IW_HW_STAT_INDEX_IP6RXTRUNC,
195 I40IW_HW_STAT_INDEX_IP6TXNOROUTE,
196 I40IW_HW_STAT_INDEX_TCPRTXSEG,
197 I40IW_HW_STAT_INDEX_TCPRXOPTERR,
198 I40IW_HW_STAT_INDEX_TCPRXPROTOERR,
199 I40IW_HW_STAT_INDEX_MAX_32
200};
201
202enum i40iw_hw_stat_index_64b {
203 I40IW_HW_STAT_INDEX_IP4RXOCTS = 0,
204 I40IW_HW_STAT_INDEX_IP4RXPKTS,
205 I40IW_HW_STAT_INDEX_IP4RXFRAGS,
206 I40IW_HW_STAT_INDEX_IP4RXMCPKTS,
207 I40IW_HW_STAT_INDEX_IP4TXOCTS,
208 I40IW_HW_STAT_INDEX_IP4TXPKTS,
209 I40IW_HW_STAT_INDEX_IP4TXFRAGS,
210 I40IW_HW_STAT_INDEX_IP4TXMCPKTS,
211 I40IW_HW_STAT_INDEX_IP6RXOCTS,
212 I40IW_HW_STAT_INDEX_IP6RXPKTS,
213 I40IW_HW_STAT_INDEX_IP6RXFRAGS,
214 I40IW_HW_STAT_INDEX_IP6RXMCPKTS,
215 I40IW_HW_STAT_INDEX_IP6TXOCTS,
216 I40IW_HW_STAT_INDEX_IP6TXPKTS,
217 I40IW_HW_STAT_INDEX_IP6TXFRAGS,
218 I40IW_HW_STAT_INDEX_IP6TXMCPKTS,
219 I40IW_HW_STAT_INDEX_TCPRXSEGS,
220 I40IW_HW_STAT_INDEX_TCPTXSEG,
221 I40IW_HW_STAT_INDEX_RDMARXRDS,
222 I40IW_HW_STAT_INDEX_RDMARXSNDS,
223 I40IW_HW_STAT_INDEX_RDMARXWRS,
224 I40IW_HW_STAT_INDEX_RDMATXRDS,
225 I40IW_HW_STAT_INDEX_RDMATXSNDS,
226 I40IW_HW_STAT_INDEX_RDMATXWRS,
227 I40IW_HW_STAT_INDEX_RDMAVBND,
228 I40IW_HW_STAT_INDEX_RDMAVINV,
229 I40IW_HW_STAT_INDEX_MAX_64
230};
231
232struct i40iw_dev_hw_stat_offsets {
233 u32 stat_offset_32[I40IW_HW_STAT_INDEX_MAX_32];
234 u32 stat_offset_64[I40IW_HW_STAT_INDEX_MAX_64];
235};
236
237struct i40iw_dev_hw_stats {
238 u64 stat_value_32[I40IW_HW_STAT_INDEX_MAX_32];
239 u64 stat_value_64[I40IW_HW_STAT_INDEX_MAX_64];
240};
241
242struct i40iw_device_pestat_ops {
243 void (*iw_hw_stat_init)(struct i40iw_dev_pestat *, u8, struct i40iw_hw *, bool);
244 void (*iw_hw_stat_read_32)(struct i40iw_dev_pestat *, enum i40iw_hw_stat_index_32b, u64 *);
245 void (*iw_hw_stat_read_64)(struct i40iw_dev_pestat *, enum i40iw_hw_stat_index_64b, u64 *);
246 void (*iw_hw_stat_read_all)(struct i40iw_dev_pestat *, struct i40iw_dev_hw_stats *);
247 void (*iw_hw_stat_refresh_all)(struct i40iw_dev_pestat *);
248};
249
250struct i40iw_dev_pestat {
251 struct i40iw_hw *hw;
252 struct i40iw_device_pestat_ops ops;
253 struct i40iw_dev_hw_stats hw_stats;
254 struct i40iw_dev_hw_stats last_read_hw_stats;
255 struct i40iw_dev_hw_stat_offsets hw_stat_offsets;
256 struct timer_list stats_timer;
257 spinlock_t stats_lock; /* rdma stats lock */
258};
259
260struct i40iw_hw {
261 u8 __iomem *hw_addr;
262 void *dev_context;
263 struct i40iw_hmc_info hmc;
264};
265
266struct i40iw_pfpdu {
267 struct list_head rxlist;
268 u32 rcv_nxt;
269 u32 fps;
270 u32 max_fpdu_data;
271 bool mode;
272 bool mpa_crc_err;
273 u64 total_ieq_bufs;
274 u64 fpdu_processed;
275 u64 bad_seq_num;
276 u64 crc_err;
277 u64 no_tx_bufs;
278 u64 tx_err;
279 u64 out_of_order;
280 u64 pmode_count;
281};
282
283struct i40iw_sc_pd {
284 u32 size;
285 struct i40iw_sc_dev *dev;
286 u16 pd_id;
287};
288
289struct i40iw_cqp_quanta {
290 u64 elem[I40IW_CQP_WQE_SIZE];
291};
292
293struct i40iw_sc_cqp {
294 u32 size;
295 u64 sq_pa;
296 u64 host_ctx_pa;
297 void *back_cqp;
298 struct i40iw_sc_dev *dev;
299 enum i40iw_status_code (*process_cqp_sds)(struct i40iw_sc_dev *,
300 struct i40iw_update_sds_info *);
301 struct i40iw_dma_mem sdbuf;
302 struct i40iw_ring sq_ring;
303 struct i40iw_cqp_quanta *sq_base;
304 u64 *host_ctx;
305 u64 *scratch_array;
306 u32 cqp_id;
307 u32 sq_size;
308 u32 hw_sq_size;
309 u8 struct_ver;
310 u8 polarity;
311 bool en_datacenter_tcp;
312 u8 hmc_profile;
313 u8 enabled_vf_count;
314 u8 timeout_count;
315};
316
317struct i40iw_sc_aeq {
318 u32 size;
319 u64 aeq_elem_pa;
320 struct i40iw_sc_dev *dev;
321 struct i40iw_sc_aeqe *aeqe_base;
322 void *pbl_list;
323 u32 elem_cnt;
324 struct i40iw_ring aeq_ring;
325 bool virtual_map;
326 u8 pbl_chunk_size;
327 u32 first_pm_pbl_idx;
328 u8 polarity;
329};
330
331struct i40iw_sc_ceq {
332 u32 size;
333 u64 ceq_elem_pa;
334 struct i40iw_sc_dev *dev;
335 struct i40iw_ceqe *ceqe_base;
336 void *pbl_list;
337 u32 ceq_id;
338 u32 elem_cnt;
339 struct i40iw_ring ceq_ring;
340 bool virtual_map;
341 u8 pbl_chunk_size;
342 bool tph_en;
343 u8 tph_val;
344 u32 first_pm_pbl_idx;
345 u8 polarity;
346};
347
348struct i40iw_sc_cq {
349 struct i40iw_cq_uk cq_uk;
350 u64 cq_pa;
351 u64 shadow_area_pa;
352 struct i40iw_sc_dev *dev;
353 void *pbl_list;
354 void *back_cq;
355 u32 ceq_id;
356 u32 shadow_read_threshold;
357 bool ceqe_mask;
358 bool virtual_map;
359 u8 pbl_chunk_size;
360 u8 cq_type;
361 bool ceq_id_valid;
362 bool tph_en;
363 u8 tph_val;
364 u32 first_pm_pbl_idx;
365 bool check_overflow;
366};
367
368struct i40iw_sc_qp {
369 struct i40iw_qp_uk qp_uk;
370 u64 sq_pa;
371 u64 rq_pa;
372 u64 hw_host_ctx_pa;
373 u64 shadow_area_pa;
374 u64 q2_pa;
375 struct i40iw_sc_dev *dev;
376 struct i40iw_sc_pd *pd;
377 u64 *hw_host_ctx;
378 void *llp_stream_handle;
379 void *back_qp;
380 struct i40iw_pfpdu pfpdu;
381 u8 *q2_buf;
382 u64 qp_compl_ctx;
383 u16 qs_handle;
384 u16 exception_lan_queue;
385 u16 push_idx;
386 u8 sq_tph_val;
387 u8 rq_tph_val;
388 u8 qp_state;
389 u8 qp_type;
390 u8 hw_sq_size;
391 u8 hw_rq_size;
392 u8 src_mac_addr_idx;
393 bool sq_tph_en;
394 bool rq_tph_en;
395 bool rcv_tph_en;
396 bool xmit_tph_en;
397 bool virtual_map;
398 bool flush_sq;
399 bool flush_rq;
400 bool sq_flush;
401 enum i40iw_flush_opcode flush_code;
402 enum i40iw_term_eventtypes eventtype;
403 u8 term_flags;
404};
405
406struct i40iw_hmc_fpm_misc {
407 u32 max_ceqs;
408 u32 max_sds;
409 u32 xf_block_size;
410 u32 q1_block_size;
411 u32 ht_multiplier;
412 u32 timer_bucket;
413};
414
415struct i40iw_vchnl_if {
416 enum i40iw_status_code (*vchnl_recv)(struct i40iw_sc_dev *, u32, u8 *, u16);
417 enum i40iw_status_code (*vchnl_send)(struct i40iw_sc_dev *dev, u32, u8 *, u16);
418};
419
420#define I40IW_VCHNL_MAX_VF_MSG_SIZE 512
421
422struct i40iw_vchnl_vf_msg_buffer {
423 struct i40iw_virtchnl_op_buf vchnl_msg;
424 char parm_buffer[I40IW_VCHNL_MAX_VF_MSG_SIZE - 1];
425};
426
427struct i40iw_vfdev {
428 struct i40iw_sc_dev *pf_dev;
429 u8 *hmc_info_mem;
430 struct i40iw_dev_pestat dev_pestat;
431 struct i40iw_hmc_pble_info *pble_info;
432 struct i40iw_hmc_info hmc_info;
433 struct i40iw_vchnl_vf_msg_buffer vf_msg_buffer;
434 u64 fpm_query_buf_pa;
435 u64 *fpm_query_buf;
436 u32 vf_id;
437 u32 msg_count;
438 bool pf_hmc_initialized;
439 u16 pmf_index;
440 u16 iw_vf_idx; /* VF Device table index */
441 bool stats_initialized;
442};
443
444struct i40iw_sc_dev {
445 struct list_head cqp_cmd_head; /* head of the CQP command list */
446 spinlock_t cqp_lock; /* cqp list sync */
447 struct i40iw_dev_uk dev_uk;
448 struct i40iw_dev_pestat dev_pestat;
449 struct i40iw_dma_mem vf_fpm_query_buf[I40IW_MAX_PE_ENABLED_VF_COUNT];
450 u64 fpm_query_buf_pa;
451 u64 fpm_commit_buf_pa;
452 u64 *fpm_query_buf;
453 u64 *fpm_commit_buf;
454 void *back_dev;
455 struct i40iw_hw *hw;
456 u8 __iomem *db_addr;
457 struct i40iw_hmc_info *hmc_info;
458 struct i40iw_hmc_pble_info *pble_info;
459 struct i40iw_vfdev *vf_dev[I40IW_MAX_PE_ENABLED_VF_COUNT];
460 struct i40iw_sc_cqp *cqp;
461 struct i40iw_sc_aeq *aeq;
462 struct i40iw_sc_ceq *ceq[I40IW_CEQ_MAX_COUNT];
463 struct i40iw_sc_cq *ccq;
464 struct i40iw_cqp_ops *cqp_ops;
465 struct i40iw_ccq_ops *ccq_ops;
466 struct i40iw_ceq_ops *ceq_ops;
467 struct i40iw_aeq_ops *aeq_ops;
468 struct i40iw_pd_ops *iw_pd_ops;
469 struct i40iw_priv_qp_ops *iw_priv_qp_ops;
470 struct i40iw_priv_cq_ops *iw_priv_cq_ops;
471 struct i40iw_mr_ops *mr_ops;
472 struct i40iw_cqp_misc_ops *cqp_misc_ops;
473 struct i40iw_hmc_ops *hmc_ops;
474 struct i40iw_vchnl_if vchnl_if;
475 u32 ilq_count;
476 struct i40iw_virt_mem ilq_mem;
477 struct i40iw_puda_rsrc *ilq;
478 u32 ieq_count;
479 struct i40iw_virt_mem ieq_mem;
480 struct i40iw_puda_rsrc *ieq;
481
482 struct i40iw_vf_cqp_ops *iw_vf_cqp_ops;
483
484 struct i40iw_hmc_fpm_misc hmc_fpm_misc;
485 u16 qs_handle;
486 u32 debug_mask;
487 u16 exception_lan_queue;
488 u8 hmc_fn_id;
489 bool is_pf;
490 bool vchnl_up;
491 u8 vf_id;
492 u64 cqp_cmd_stats[OP_SIZE_CQP_STAT_ARRAY];
493 struct i40iw_vchnl_vf_msg_buffer vchnl_vf_msg_buf;
494 u8 hw_rev;
495};
496
497struct i40iw_modify_cq_info {
498 u64 cq_pa;
499 struct i40iw_cqe *cq_base;
500 void *pbl_list;
501 u32 ceq_id;
502 u32 cq_size;
503 u32 shadow_read_threshold;
504 bool virtual_map;
505 u8 pbl_chunk_size;
506 bool check_overflow;
507 bool cq_resize;
508 bool ceq_change;
509 bool check_overflow_change;
510 u32 first_pm_pbl_idx;
511 bool ceq_valid;
512};
513
514struct i40iw_create_qp_info {
515 u8 next_iwarp_state;
516 bool ord_valid;
517 bool tcp_ctx_valid;
518 bool cq_num_valid;
519 bool static_rsrc;
520 bool arp_cache_idx_valid;
521};
522
523struct i40iw_modify_qp_info {
524 u64 rx_win0;
525 u64 rx_win1;
526 u16 new_mss;
527 u8 next_iwarp_state;
528 u8 termlen;
529 bool ord_valid;
530 bool tcp_ctx_valid;
531 bool cq_num_valid;
532 bool static_rsrc;
533 bool arp_cache_idx_valid;
534 bool reset_tcp_conn;
535 bool remove_hash_idx;
536 bool dont_send_term;
537 bool dont_send_fin;
538 bool cached_var_valid;
539 bool mss_change;
540 bool force_loopback;
541};
542
543struct i40iw_ccq_cqe_info {
544 struct i40iw_sc_cqp *cqp;
545 u64 scratch;
546 u32 op_ret_val;
547 u16 maj_err_code;
548 u16 min_err_code;
549 u8 op_code;
550 bool error;
551};
552
553struct i40iw_l2params {
554 u16 qs_handle_list[I40IW_MAX_USER_PRIORITY];
555 u16 mss;
556};
557
558struct i40iw_device_init_info {
559 u64 fpm_query_buf_pa;
560 u64 fpm_commit_buf_pa;
561 u64 *fpm_query_buf;
562 u64 *fpm_commit_buf;
563 struct i40iw_hw *hw;
564 void __iomem *bar0;
565 enum i40iw_status_code (*vchnl_send)(struct i40iw_sc_dev *, u32, u8 *, u16);
566 u16 qs_handle;
567 u16 exception_lan_queue;
568 u8 hmc_fn_id;
569 bool is_pf;
570 u32 debug_mask;
571};
572
573enum i40iw_cqp_hmc_profile {
574 I40IW_HMC_PROFILE_DEFAULT = 1,
575 I40IW_HMC_PROFILE_FAVOR_VF = 2,
576 I40IW_HMC_PROFILE_EQUAL = 3,
577};
578
579struct i40iw_cqp_init_info {
580 u64 cqp_compl_ctx;
581 u64 host_ctx_pa;
582 u64 sq_pa;
583 struct i40iw_sc_dev *dev;
584 struct i40iw_cqp_quanta *sq;
585 u64 *host_ctx;
586 u64 *scratch_array;
587 u32 sq_size;
588 u8 struct_ver;
589 bool en_datacenter_tcp;
590 u8 hmc_profile;
591 u8 enabled_vf_count;
592};
593
594struct i40iw_ceq_init_info {
595 u64 ceqe_pa;
596 struct i40iw_sc_dev *dev;
597 u64 *ceqe_base;
598 void *pbl_list;
599 u32 elem_cnt;
600 u32 ceq_id;
601 bool virtual_map;
602 u8 pbl_chunk_size;
603 bool tph_en;
604 u8 tph_val;
605 u32 first_pm_pbl_idx;
606};
607
608struct i40iw_aeq_init_info {
609 u64 aeq_elem_pa;
610 struct i40iw_sc_dev *dev;
611 u32 *aeqe_base;
612 void *pbl_list;
613 u32 elem_cnt;
614 bool virtual_map;
615 u8 pbl_chunk_size;
616 u32 first_pm_pbl_idx;
617};
618
619struct i40iw_ccq_init_info {
620 u64 cq_pa;
621 u64 shadow_area_pa;
622 struct i40iw_sc_dev *dev;
623 struct i40iw_cqe *cq_base;
624 u64 *shadow_area;
625 void *pbl_list;
626 u32 num_elem;
627 u32 ceq_id;
628 u32 shadow_read_threshold;
629 bool ceqe_mask;
630 bool ceq_id_valid;
631 bool tph_en;
632 u8 tph_val;
633 bool avoid_mem_cflct;
634 bool virtual_map;
635 u8 pbl_chunk_size;
636 u32 first_pm_pbl_idx;
637};
638
639struct i40iwarp_offload_info {
640 u16 rcv_mark_offset;
641 u16 snd_mark_offset;
642 u16 pd_id;
643 u8 ddp_ver;
644 u8 rdmap_ver;
645 u8 ord_size;
646 u8 ird_size;
647 bool wr_rdresp_en;
648 bool rd_enable;
649 bool snd_mark_en;
650 bool rcv_mark_en;
651 bool bind_en;
652 bool fast_reg_en;
653 bool priv_mode_en;
654 bool lsmm_present;
655 u8 iwarp_mode;
656 bool align_hdrs;
657 bool rcv_no_mpa_crc;
658
659 u8 last_byte_sent;
660};
661
662struct i40iw_tcp_offload_info {
663 bool ipv4;
664 bool no_nagle;
665 bool insert_vlan_tag;
666 bool time_stamp;
667 u8 cwnd_inc_limit;
668 bool drop_ooo_seg;
669 bool dup_ack_thresh;
670 u8 ttl;
671 u8 src_mac_addr_idx;
672 bool avoid_stretch_ack;
673 u8 tos;
674 u16 src_port;
675 u16 dst_port;
676 u32 dest_ip_addr0;
677 u32 dest_ip_addr1;
678 u32 dest_ip_addr2;
679 u32 dest_ip_addr3;
680 u32 snd_mss;
681 u16 vlan_tag;
682 u16 arp_idx;
683 u32 flow_label;
684 bool wscale;
685 u8 tcp_state;
686 u8 snd_wscale;
687 u8 rcv_wscale;
688 u32 time_stamp_recent;
689 u32 time_stamp_age;
690 u32 snd_nxt;
691 u32 snd_wnd;
692 u32 rcv_nxt;
693 u32 rcv_wnd;
694 u32 snd_max;
695 u32 snd_una;
696 u32 srtt;
697 u32 rtt_var;
698 u32 ss_thresh;
699 u32 cwnd;
700 u32 snd_wl1;
701 u32 snd_wl2;
702 u32 max_snd_window;
703 u8 rexmit_thresh;
704 u32 local_ipaddr0;
705 u32 local_ipaddr1;
706 u32 local_ipaddr2;
707 u32 local_ipaddr3;
708 bool ignore_tcp_opt;
709 bool ignore_tcp_uns_opt;
710};
711
712struct i40iw_qp_host_ctx_info {
713 u64 qp_compl_ctx;
714 struct i40iw_tcp_offload_info *tcp_info;
715 struct i40iwarp_offload_info *iwarp_info;
716 u32 send_cq_num;
717 u32 rcv_cq_num;
718 u16 push_idx;
719 bool push_mode_en;
720 bool tcp_info_valid;
721 bool iwarp_info_valid;
722 bool err_rq_idx_valid;
723 u16 err_rq_idx;
724};
725
726struct i40iw_aeqe_info {
727 u64 compl_ctx;
728 u32 qp_cq_id;
729 u16 ae_id;
730 u16 wqe_idx;
731 u8 tcp_state;
732 u8 iwarp_state;
733 bool qp;
734 bool cq;
735 bool sq;
736 bool in_rdrsp_wr;
737 bool out_rdrsp;
738 u8 q2_data_written;
739 bool aeqe_overflow;
740};
741
742struct i40iw_allocate_stag_info {
743 u64 total_len;
744 u32 chunk_size;
745 u32 stag_idx;
746 u32 page_size;
747 u16 pd_id;
748 u16 access_rights;
749 bool remote_access;
750 bool use_hmc_fcn_index;
751 u8 hmc_fcn_index;
752 bool use_pf_rid;
753};
754
755struct i40iw_reg_ns_stag_info {
756 u64 reg_addr_pa;
757 u64 fbo;
758 void *va;
759 u64 total_len;
760 u32 page_size;
761 u32 chunk_size;
762 u32 first_pm_pbl_index;
763 enum i40iw_addressing_type addr_type;
764 i40iw_stag_index stag_idx;
765 u16 access_rights;
766 u16 pd_id;
767 i40iw_stag_key stag_key;
768 bool use_hmc_fcn_index;
769 u8 hmc_fcn_index;
770 bool use_pf_rid;
771};
772
773struct i40iw_fast_reg_stag_info {
774 u64 wr_id;
775 u64 reg_addr_pa;
776 u64 fbo;
777 void *va;
778 u64 total_len;
779 u32 page_size;
780 u32 chunk_size;
781 u32 first_pm_pbl_index;
782 enum i40iw_addressing_type addr_type;
783 i40iw_stag_index stag_idx;
784 u16 access_rights;
785 u16 pd_id;
786 i40iw_stag_key stag_key;
787 bool local_fence;
788 bool read_fence;
789 bool signaled;
790 bool use_hmc_fcn_index;
791 u8 hmc_fcn_index;
792 bool use_pf_rid;
793 bool defer_flag;
794};
795
796struct i40iw_dealloc_stag_info {
797 u32 stag_idx;
798 u16 pd_id;
799 bool mr;
800 bool dealloc_pbl;
801};
802
803struct i40iw_register_shared_stag {
804 void *va;
805 enum i40iw_addressing_type addr_type;
806 i40iw_stag_index new_stag_idx;
807 i40iw_stag_index parent_stag_idx;
808 u32 access_rights;
809 u16 pd_id;
810 i40iw_stag_key new_stag_key;
811};
812
813struct i40iw_qp_init_info {
814 struct i40iw_qp_uk_init_info qp_uk_init_info;
815 struct i40iw_sc_pd *pd;
816 u64 *host_ctx;
817 u8 *q2;
818 u64 sq_pa;
819 u64 rq_pa;
820 u64 host_ctx_pa;
821 u64 q2_pa;
822 u64 shadow_area_pa;
823 u8 sq_tph_val;
824 u8 rq_tph_val;
825 u8 type;
826 bool sq_tph_en;
827 bool rq_tph_en;
828 bool rcv_tph_en;
829 bool xmit_tph_en;
830 bool virtual_map;
831};
832
833struct i40iw_cq_init_info {
834 struct i40iw_sc_dev *dev;
835 u64 cq_base_pa;
836 u64 shadow_area_pa;
837 u32 ceq_id;
838 u32 shadow_read_threshold;
839 bool virtual_map;
840 bool ceqe_mask;
841 u8 pbl_chunk_size;
842 u32 first_pm_pbl_idx;
843 bool ceq_id_valid;
844 bool tph_en;
845 u8 tph_val;
846 u8 type;
847 struct i40iw_cq_uk_init_info cq_uk_init_info;
848};
849
850struct i40iw_upload_context_info {
851 u64 buf_pa;
852 bool freeze_qp;
853 bool raw_format;
854 u32 qp_id;
855 u8 qp_type;
856};
857
858struct i40iw_add_arp_cache_entry_info {
859 u8 mac_addr[6];
860 u32 reach_max;
861 u16 arp_index;
862 bool permanent;
863};
864
865struct i40iw_apbvt_info {
866 u16 port;
867 bool add;
868};
869
870enum i40iw_quad_entry_type {
871 I40IW_QHASH_TYPE_TCP_ESTABLISHED = 1,
872 I40IW_QHASH_TYPE_TCP_SYN,
873};
874
875enum i40iw_quad_hash_manage_type {
876 I40IW_QHASH_MANAGE_TYPE_DELETE = 0,
877 I40IW_QHASH_MANAGE_TYPE_ADD,
878 I40IW_QHASH_MANAGE_TYPE_MODIFY
879};
880
881struct i40iw_qhash_table_info {
882 enum i40iw_quad_hash_manage_type manage;
883 enum i40iw_quad_entry_type entry_type;
884 bool vlan_valid;
885 bool ipv4_valid;
886 u8 mac_addr[6];
887 u16 vlan_id;
888 u16 qs_handle;
889 u32 qp_num;
890 u32 dest_ip[4];
891 u32 src_ip[4];
892 u32 dest_port;
893 u32 src_port;
894};
895
896struct i40iw_local_mac_ipaddr_entry_info {
897 u8 mac_addr[6];
898 u8 entry_idx;
899};
900
901struct i40iw_cqp_manage_push_page_info {
902 u32 push_idx;
903 u16 qs_handle;
904 u8 free_page;
905};
906
907struct i40iw_qp_flush_info {
908 u16 sq_minor_code;
909 u16 sq_major_code;
910 u16 rq_minor_code;
911 u16 rq_major_code;
912 u16 ae_code;
913 u8 ae_source;
914 bool sq;
915 bool rq;
916 bool userflushcode;
917 bool generate_ae;
918};
919
920struct i40iw_cqp_commit_fpm_values {
921 u64 qp_base;
922 u64 cq_base;
923 u32 hte_base;
924 u32 arp_base;
925 u32 apbvt_inuse_base;
926 u32 mr_base;
927 u32 xf_base;
928 u32 xffl_base;
929 u32 q1_base;
930 u32 q1fl_base;
931 u32 fsimc_base;
932 u32 fsiav_base;
933 u32 pbl_base;
934
935 u32 qp_cnt;
936 u32 cq_cnt;
937 u32 hte_cnt;
938 u32 arp_cnt;
939 u32 mr_cnt;
940 u32 xf_cnt;
941 u32 xffl_cnt;
942 u32 q1_cnt;
943 u32 q1fl_cnt;
944 u32 fsimc_cnt;
945 u32 fsiav_cnt;
946 u32 pbl_cnt;
947};
948
949struct i40iw_cqp_query_fpm_values {
950 u16 first_pe_sd_index;
951 u32 qp_objsize;
952 u32 cq_objsize;
953 u32 hte_objsize;
954 u32 arp_objsize;
955 u32 mr_objsize;
956 u32 xf_objsize;
957 u32 q1_objsize;
958 u32 fsimc_objsize;
959 u32 fsiav_objsize;
960
961 u32 qp_max;
962 u32 cq_max;
963 u32 hte_max;
964 u32 arp_max;
965 u32 mr_max;
966 u32 xf_max;
967 u32 xffl_max;
968 u32 q1_max;
969 u32 q1fl_max;
970 u32 fsimc_max;
971 u32 fsiav_max;
972 u32 pbl_max;
973};
974
975struct i40iw_cqp_ops {
976 enum i40iw_status_code (*cqp_init)(struct i40iw_sc_cqp *,
977 struct i40iw_cqp_init_info *);
978 enum i40iw_status_code (*cqp_create)(struct i40iw_sc_cqp *, bool, u16 *, u16 *);
979 void (*cqp_post_sq)(struct i40iw_sc_cqp *);
980 u64 *(*cqp_get_next_send_wqe)(struct i40iw_sc_cqp *, u64 scratch);
981 enum i40iw_status_code (*cqp_destroy)(struct i40iw_sc_cqp *);
982 enum i40iw_status_code (*poll_for_cqp_op_done)(struct i40iw_sc_cqp *, u8,
983 struct i40iw_ccq_cqe_info *);
984};
985
986struct i40iw_ccq_ops {
987 enum i40iw_status_code (*ccq_init)(struct i40iw_sc_cq *,
988 struct i40iw_ccq_init_info *);
989 enum i40iw_status_code (*ccq_create)(struct i40iw_sc_cq *, u64, bool, bool);
990 enum i40iw_status_code (*ccq_destroy)(struct i40iw_sc_cq *, u64, bool);
991 enum i40iw_status_code (*ccq_create_done)(struct i40iw_sc_cq *);
992 enum i40iw_status_code (*ccq_get_cqe_info)(struct i40iw_sc_cq *,
993 struct i40iw_ccq_cqe_info *);
994 void (*ccq_arm)(struct i40iw_sc_cq *);
995};
996
997struct i40iw_ceq_ops {
998 enum i40iw_status_code (*ceq_init)(struct i40iw_sc_ceq *,
999 struct i40iw_ceq_init_info *);
1000 enum i40iw_status_code (*ceq_create)(struct i40iw_sc_ceq *, u64, bool);
1001 enum i40iw_status_code (*cceq_create_done)(struct i40iw_sc_ceq *);
1002 enum i40iw_status_code (*cceq_destroy_done)(struct i40iw_sc_ceq *);
1003 enum i40iw_status_code (*cceq_create)(struct i40iw_sc_ceq *, u64);
1004 enum i40iw_status_code (*ceq_destroy)(struct i40iw_sc_ceq *, u64, bool);
1005 void *(*process_ceq)(struct i40iw_sc_dev *, struct i40iw_sc_ceq *);
1006};
1007
1008struct i40iw_aeq_ops {
1009 enum i40iw_status_code (*aeq_init)(struct i40iw_sc_aeq *,
1010 struct i40iw_aeq_init_info *);
1011 enum i40iw_status_code (*aeq_create)(struct i40iw_sc_aeq *, u64, bool);
1012 enum i40iw_status_code (*aeq_destroy)(struct i40iw_sc_aeq *, u64, bool);
1013 enum i40iw_status_code (*get_next_aeqe)(struct i40iw_sc_aeq *,
1014 struct i40iw_aeqe_info *);
1015 enum i40iw_status_code (*repost_aeq_entries)(struct i40iw_sc_dev *, u32);
1016 enum i40iw_status_code (*aeq_create_done)(struct i40iw_sc_aeq *);
1017 enum i40iw_status_code (*aeq_destroy_done)(struct i40iw_sc_aeq *);
1018};
1019
1020struct i40iw_pd_ops {
1021 void (*pd_init)(struct i40iw_sc_dev *, struct i40iw_sc_pd *, u16);
1022};
1023
1024struct i40iw_priv_qp_ops {
1025 enum i40iw_status_code (*qp_init)(struct i40iw_sc_qp *, struct i40iw_qp_init_info *);
1026 enum i40iw_status_code (*qp_create)(struct i40iw_sc_qp *,
1027 struct i40iw_create_qp_info *, u64, bool);
1028 enum i40iw_status_code (*qp_modify)(struct i40iw_sc_qp *,
1029 struct i40iw_modify_qp_info *, u64, bool);
1030 enum i40iw_status_code (*qp_destroy)(struct i40iw_sc_qp *, u64, bool, bool, bool);
1031 enum i40iw_status_code (*qp_flush_wqes)(struct i40iw_sc_qp *,
1032 struct i40iw_qp_flush_info *, u64, bool);
1033 enum i40iw_status_code (*qp_upload_context)(struct i40iw_sc_dev *,
1034 struct i40iw_upload_context_info *,
1035 u64, bool);
1036 enum i40iw_status_code (*qp_setctx)(struct i40iw_sc_qp *, u64 *,
1037 struct i40iw_qp_host_ctx_info *);
1038
1039 void (*qp_send_lsmm)(struct i40iw_sc_qp *, void *, u32, i40iw_stag);
1040 void (*qp_send_lsmm_nostag)(struct i40iw_sc_qp *, void *, u32);
1041 void (*qp_send_rtt)(struct i40iw_sc_qp *, bool);
1042 enum i40iw_status_code (*qp_post_wqe0)(struct i40iw_sc_qp *, u8);
1043};
1044
1045struct i40iw_priv_cq_ops {
1046 enum i40iw_status_code (*cq_init)(struct i40iw_sc_cq *, struct i40iw_cq_init_info *);
1047 enum i40iw_status_code (*cq_create)(struct i40iw_sc_cq *, u64, bool, bool);
1048 enum i40iw_status_code (*cq_destroy)(struct i40iw_sc_cq *, u64, bool);
1049 enum i40iw_status_code (*cq_modify)(struct i40iw_sc_cq *,
1050 struct i40iw_modify_cq_info *, u64, bool);
1051};
1052
1053struct i40iw_mr_ops {
1054 enum i40iw_status_code (*alloc_stag)(struct i40iw_sc_dev *,
1055 struct i40iw_allocate_stag_info *, u64, bool);
1056 enum i40iw_status_code (*mr_reg_non_shared)(struct i40iw_sc_dev *,
1057 struct i40iw_reg_ns_stag_info *,
1058 u64, bool);
1059 enum i40iw_status_code (*mr_reg_shared)(struct i40iw_sc_dev *,
1060 struct i40iw_register_shared_stag *,
1061 u64, bool);
1062 enum i40iw_status_code (*dealloc_stag)(struct i40iw_sc_dev *,
1063 struct i40iw_dealloc_stag_info *,
1064 u64, bool);
1065 enum i40iw_status_code (*query_stag)(struct i40iw_sc_dev *, u64, u32, bool);
1066 enum i40iw_status_code (*mw_alloc)(struct i40iw_sc_dev *, u64, u32, u16, bool);
1067};
1068
1069struct i40iw_cqp_misc_ops {
1070 enum i40iw_status_code (*manage_push_page)(struct i40iw_sc_cqp *,
1071 struct i40iw_cqp_manage_push_page_info *,
1072 u64, bool);
1073 enum i40iw_status_code (*manage_hmc_pm_func_table)(struct i40iw_sc_cqp *,
1074 u64, u8, bool, bool);
1075 enum i40iw_status_code (*set_hmc_resource_profile)(struct i40iw_sc_cqp *,
1076 u64, u8, u8, bool, bool);
1077 enum i40iw_status_code (*commit_fpm_values)(struct i40iw_sc_cqp *, u64, u8,
1078 struct i40iw_dma_mem *, bool, u8);
1079 enum i40iw_status_code (*query_fpm_values)(struct i40iw_sc_cqp *, u64, u8,
1080 struct i40iw_dma_mem *, bool, u8);
1081 enum i40iw_status_code (*static_hmc_pages_allocated)(struct i40iw_sc_cqp *,
1082 u64, u8, bool, bool);
1083 enum i40iw_status_code (*add_arp_cache_entry)(struct i40iw_sc_cqp *,
1084 struct i40iw_add_arp_cache_entry_info *,
1085 u64, bool);
1086 enum i40iw_status_code (*del_arp_cache_entry)(struct i40iw_sc_cqp *, u64, u16, bool);
1087 enum i40iw_status_code (*query_arp_cache_entry)(struct i40iw_sc_cqp *, u64, u16, bool);
1088 enum i40iw_status_code (*manage_apbvt_entry)(struct i40iw_sc_cqp *,
1089 struct i40iw_apbvt_info *, u64, bool);
1090 enum i40iw_status_code (*manage_qhash_table_entry)(struct i40iw_sc_cqp *,
1091 struct i40iw_qhash_table_info *, u64, bool);
1092 enum i40iw_status_code (*alloc_local_mac_ipaddr_table_entry)(struct i40iw_sc_cqp *, u64, bool);
1093 enum i40iw_status_code (*add_local_mac_ipaddr_entry)(struct i40iw_sc_cqp *,
1094 struct i40iw_local_mac_ipaddr_entry_info *,
1095 u64, bool);
1096 enum i40iw_status_code (*del_local_mac_ipaddr_entry)(struct i40iw_sc_cqp *, u64, u8, u8, bool);
1097 enum i40iw_status_code (*cqp_nop)(struct i40iw_sc_cqp *, u64, bool);
1098 enum i40iw_status_code (*commit_fpm_values_done)(struct i40iw_sc_cqp
1099 *);
1100 enum i40iw_status_code (*query_fpm_values_done)(struct i40iw_sc_cqp *);
1101 enum i40iw_status_code (*manage_hmc_pm_func_table_done)(struct i40iw_sc_cqp *);
1102 enum i40iw_status_code (*update_suspend_qp)(struct i40iw_sc_cqp *, struct i40iw_sc_qp *, u64);
1103 enum i40iw_status_code (*update_resume_qp)(struct i40iw_sc_cqp *, struct i40iw_sc_qp *, u64);
1104};
1105
1106struct i40iw_hmc_ops {
1107 enum i40iw_status_code (*init_iw_hmc)(struct i40iw_sc_dev *, u8);
1108 enum i40iw_status_code (*parse_fpm_query_buf)(u64 *, struct i40iw_hmc_info *,
1109 struct i40iw_hmc_fpm_misc *);
1110 enum i40iw_status_code (*configure_iw_fpm)(struct i40iw_sc_dev *, u8);
1111 enum i40iw_status_code (*parse_fpm_commit_buf)(u64 *, struct i40iw_hmc_obj_info *);
1112 enum i40iw_status_code (*create_hmc_object)(struct i40iw_sc_dev *dev,
1113 struct i40iw_hmc_create_obj_info *);
1114 enum i40iw_status_code (*del_hmc_object)(struct i40iw_sc_dev *dev,
1115 struct i40iw_hmc_del_obj_info *,
1116 bool reset);
1117 enum i40iw_status_code (*pf_init_vfhmc)(struct i40iw_sc_dev *, u8, u32 *);
1118 enum i40iw_status_code (*vf_configure_vffpm)(struct i40iw_sc_dev *, u32 *);
1119};
1120
1121struct cqp_info {
1122 union {
1123 struct {
1124 struct i40iw_sc_qp *qp;
1125 struct i40iw_create_qp_info info;
1126 u64 scratch;
1127 } qp_create;
1128
1129 struct {
1130 struct i40iw_sc_qp *qp;
1131 struct i40iw_modify_qp_info info;
1132 u64 scratch;
1133 } qp_modify;
1134
1135 struct {
1136 struct i40iw_sc_qp *qp;
1137 u64 scratch;
1138 bool remove_hash_idx;
1139 bool ignore_mw_bnd;
1140 } qp_destroy;
1141
1142 struct {
1143 struct i40iw_sc_cq *cq;
1144 u64 scratch;
1145 bool check_overflow;
1146 } cq_create;
1147
1148 struct {
1149 struct i40iw_sc_cq *cq;
1150 u64 scratch;
1151 } cq_destroy;
1152
1153 struct {
1154 struct i40iw_sc_dev *dev;
1155 struct i40iw_allocate_stag_info info;
1156 u64 scratch;
1157 } alloc_stag;
1158
1159 struct {
1160 struct i40iw_sc_dev *dev;
1161 u64 scratch;
1162 u32 mw_stag_index;
1163 u16 pd_id;
1164 } mw_alloc;
1165
1166 struct {
1167 struct i40iw_sc_dev *dev;
1168 struct i40iw_reg_ns_stag_info info;
1169 u64 scratch;
1170 } mr_reg_non_shared;
1171
1172 struct {
1173 struct i40iw_sc_dev *dev;
1174 struct i40iw_dealloc_stag_info info;
1175 u64 scratch;
1176 } dealloc_stag;
1177
1178 struct {
1179 struct i40iw_sc_cqp *cqp;
1180 struct i40iw_local_mac_ipaddr_entry_info info;
1181 u64 scratch;
1182 } add_local_mac_ipaddr_entry;
1183
1184 struct {
1185 struct i40iw_sc_cqp *cqp;
1186 struct i40iw_add_arp_cache_entry_info info;
1187 u64 scratch;
1188 } add_arp_cache_entry;
1189
1190 struct {
1191 struct i40iw_sc_cqp *cqp;
1192 u64 scratch;
1193 u8 entry_idx;
1194 u8 ignore_ref_count;
1195 } del_local_mac_ipaddr_entry;
1196
1197 struct {
1198 struct i40iw_sc_cqp *cqp;
1199 u64 scratch;
1200 u16 arp_index;
1201 } del_arp_cache_entry;
1202
1203 struct {
1204 struct i40iw_sc_cqp *cqp;
1205 struct i40iw_manage_vf_pble_info info;
1206 u64 scratch;
1207 } manage_vf_pble_bp;
1208
1209 struct {
1210 struct i40iw_sc_cqp *cqp;
1211 struct i40iw_cqp_manage_push_page_info info;
1212 u64 scratch;
1213 } manage_push_page;
1214
1215 struct {
1216 struct i40iw_sc_dev *dev;
1217 struct i40iw_upload_context_info info;
1218 u64 scratch;
1219 } qp_upload_context;
1220
1221 struct {
1222 struct i40iw_sc_cqp *cqp;
1223 u64 scratch;
1224 } alloc_local_mac_ipaddr_entry;
1225
1226 struct {
1227 struct i40iw_sc_dev *dev;
1228 struct i40iw_hmc_fcn_info info;
1229 u64 scratch;
1230 } manage_hmc_pm;
1231
1232 struct {
1233 struct i40iw_sc_ceq *ceq;
1234 u64 scratch;
1235 } ceq_create;
1236
1237 struct {
1238 struct i40iw_sc_ceq *ceq;
1239 u64 scratch;
1240 } ceq_destroy;
1241
1242 struct {
1243 struct i40iw_sc_aeq *aeq;
1244 u64 scratch;
1245 } aeq_create;
1246
1247 struct {
1248 struct i40iw_sc_aeq *aeq;
1249 u64 scratch;
1250 } aeq_destroy;
1251
1252 struct {
1253 struct i40iw_sc_qp *qp;
1254 struct i40iw_qp_flush_info info;
1255 u64 scratch;
1256 } qp_flush_wqes;
1257
1258 struct {
1259 struct i40iw_sc_cqp *cqp;
1260 void *fpm_values_va;
1261 u64 fpm_values_pa;
1262 u8 hmc_fn_id;
1263 u64 scratch;
1264 } query_fpm_values;
1265
1266 struct {
1267 struct i40iw_sc_cqp *cqp;
1268 void *fpm_values_va;
1269 u64 fpm_values_pa;
1270 u8 hmc_fn_id;
1271 u64 scratch;
1272 } commit_fpm_values;
1273
1274 struct {
1275 struct i40iw_sc_cqp *cqp;
1276 struct i40iw_apbvt_info info;
1277 u64 scratch;
1278 } manage_apbvt_entry;
1279
1280 struct {
1281 struct i40iw_sc_cqp *cqp;
1282 struct i40iw_qhash_table_info info;
1283 u64 scratch;
1284 } manage_qhash_table_entry;
1285
1286 struct {
1287 struct i40iw_sc_dev *dev;
1288 struct i40iw_update_sds_info info;
1289 u64 scratch;
1290 } update_pe_sds;
1291
1292 struct {
1293 struct i40iw_sc_cqp *cqp;
1294 struct i40iw_sc_qp *qp;
1295 u64 scratch;
1296 } suspend_resume;
1297 } u;
1298};
1299
1300struct cqp_commands_info {
1301 struct list_head cqp_cmd_entry;
1302 u8 cqp_cmd;
1303 u8 post_sq;
1304 struct cqp_info in;
1305};
1306
1307struct i40iw_virtchnl_work_info {
1308 void (*callback_fcn)(void *vf_dev);
1309 void *worker_vf_dev;
1310};
1311
1312#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_ucontext.h b/drivers/infiniband/hw/i40iw/i40iw_ucontext.h
new file mode 100644
index 000000000000..12acd688def4
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_ucontext.h
@@ -0,0 +1,107 @@
1/*
2 * Copyright (c) 2006 - 2016 Intel Corporation. All rights reserved.
3 * Copyright (c) 2005 Topspin Communications. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved.
5 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 *
35 */
36
37#ifndef I40IW_USER_CONTEXT_H
38#define I40IW_USER_CONTEXT_H
39
40#include <linux/types.h>
41
42#define I40IW_ABI_USERSPACE_VER 4
43#define I40IW_ABI_KERNEL_VER 4
44struct i40iw_alloc_ucontext_req {
45 __u32 reserved32;
46 __u8 userspace_ver;
47 __u8 reserved8[3];
48};
49
50struct i40iw_alloc_ucontext_resp {
51 __u32 max_pds; /* maximum pds allowed for this user process */
52 __u32 max_qps; /* maximum qps allowed for this user process */
53 __u32 wq_size; /* size of the WQs (sq+rq) allocated to the mmaped area */
54 __u8 kernel_ver;
55 __u8 reserved[3];
56};
57
58struct i40iw_alloc_pd_resp {
59 __u32 pd_id;
60 __u8 reserved[4];
61};
62
63struct i40iw_create_cq_req {
64 __u64 user_cq_buffer;
65 __u64 user_shadow_area;
66};
67
68struct i40iw_create_qp_req {
69 __u64 user_wqe_buffers;
70 __u64 user_compl_ctx;
71
72 /* UDA QP PHB */
73 __u64 user_sq_phb; /* place for VA of the sq phb buff */
74 __u64 user_rq_phb; /* place for VA of the rq phb buff */
75};
76
77enum i40iw_memreg_type {
78 IW_MEMREG_TYPE_MEM = 0x0000,
79 IW_MEMREG_TYPE_QP = 0x0001,
80 IW_MEMREG_TYPE_CQ = 0x0002,
81};
82
83struct i40iw_mem_reg_req {
84 __u16 reg_type; /* Memory, QP or CQ */
85 __u16 cq_pages;
86 __u16 rq_pages;
87 __u16 sq_pages;
88};
89
90struct i40iw_create_cq_resp {
91 __u32 cq_id;
92 __u32 cq_size;
93 __u32 mmap_db_index;
94 __u32 reserved;
95};
96
97struct i40iw_create_qp_resp {
98 __u32 qp_id;
99 __u32 actual_sq_size;
100 __u32 actual_rq_size;
101 __u32 i40iw_drv_opt;
102 __u16 push_idx;
103 __u8 lsmm;
104 __u8 rsvd2;
105};
106
107#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_uk.c b/drivers/infiniband/hw/i40iw/i40iw_uk.c
new file mode 100644
index 000000000000..f78c3dc8bdb2
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_uk.c
@@ -0,0 +1,1204 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_osdep.h"
36#include "i40iw_status.h"
37#include "i40iw_d.h"
38#include "i40iw_user.h"
39#include "i40iw_register.h"
40
41static u32 nop_signature = 0x55550000;
42
43/**
44 * i40iw_nop_1 - insert a nop wqe and move head. no post work
45 * @qp: hw qp ptr
46 */
47static enum i40iw_status_code i40iw_nop_1(struct i40iw_qp_uk *qp)
48{
49 u64 header, *wqe;
50 u64 *wqe_0 = NULL;
51 u32 wqe_idx, peek_head;
52 bool signaled = false;
53
54 if (!qp->sq_ring.head)
55 return I40IW_ERR_PARAM;
56
57 wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
58 wqe = qp->sq_base[wqe_idx].elem;
59 peek_head = (qp->sq_ring.head + 1) % qp->sq_ring.size;
60 wqe_0 = qp->sq_base[peek_head].elem;
61 if (peek_head)
62 wqe_0[3] = LS_64(!qp->swqe_polarity, I40IWQPSQ_VALID);
63 else
64 wqe_0[3] = LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
65
66 set_64bit_val(wqe, 0, 0);
67 set_64bit_val(wqe, 8, 0);
68 set_64bit_val(wqe, 16, 0);
69
70 header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
71 LS_64(signaled, I40IWQPSQ_SIGCOMPL) |
72 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID) | nop_signature++;
73
74 wmb(); /* Memory barrier to ensure data is written before valid bit is set */
75
76 set_64bit_val(wqe, 24, header);
77 return 0;
78}
79
80/**
81 * i40iw_qp_post_wr - post wr to hrdware
82 * @qp: hw qp ptr
83 */
84void i40iw_qp_post_wr(struct i40iw_qp_uk *qp)
85{
86 u64 temp;
87 u32 hw_sq_tail;
88 u32 sw_sq_head;
89
90 mb(); /* valid bit is written and loads completed before reading shadow */
91
92 /* read the doorbell shadow area */
93 get_64bit_val(qp->shadow_area, 0, &temp);
94
95 hw_sq_tail = (u32)RS_64(temp, I40IW_QP_DBSA_HW_SQ_TAIL);
96 sw_sq_head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
97 if (sw_sq_head != hw_sq_tail) {
98 if (sw_sq_head > qp->initial_ring.head) {
99 if ((hw_sq_tail >= qp->initial_ring.head) &&
100 (hw_sq_tail < sw_sq_head)) {
101 writel(qp->qp_id, qp->wqe_alloc_reg);
102 }
103 } else if (sw_sq_head != qp->initial_ring.head) {
104 if ((hw_sq_tail >= qp->initial_ring.head) ||
105 (hw_sq_tail < sw_sq_head)) {
106 writel(qp->qp_id, qp->wqe_alloc_reg);
107 }
108 }
109 }
110
111 qp->initial_ring.head = qp->sq_ring.head;
112}
113
114/**
115 * i40iw_qp_ring_push_db - ring qp doorbell
116 * @qp: hw qp ptr
117 * @wqe_idx: wqe index
118 */
119static void i40iw_qp_ring_push_db(struct i40iw_qp_uk *qp, u32 wqe_idx)
120{
121 set_32bit_val(qp->push_db, 0, LS_32((wqe_idx >> 2), I40E_PFPE_WQEALLOC_WQE_DESC_INDEX) | qp->qp_id);
122 qp->initial_ring.head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
123}
124
125/**
126 * i40iw_qp_get_next_send_wqe - return next wqe ptr
127 * @qp: hw qp ptr
128 * @wqe_idx: return wqe index
129 * @wqe_size: size of sq wqe
130 */
131u64 *i40iw_qp_get_next_send_wqe(struct i40iw_qp_uk *qp,
132 u32 *wqe_idx,
133 u8 wqe_size)
134{
135 u64 *wqe = NULL;
136 u64 wqe_ptr;
137 u32 peek_head = 0;
138 u16 offset;
139 enum i40iw_status_code ret_code = 0;
140 u8 nop_wqe_cnt = 0, i;
141 u64 *wqe_0 = NULL;
142
143 *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
144
145 if (!*wqe_idx)
146 qp->swqe_polarity = !qp->swqe_polarity;
147 wqe_ptr = (uintptr_t)qp->sq_base[*wqe_idx].elem;
148 offset = (u16)(wqe_ptr) & 0x7F;
149 if ((offset + wqe_size) > I40IW_QP_WQE_MAX_SIZE) {
150 nop_wqe_cnt = (u8)(I40IW_QP_WQE_MAX_SIZE - offset) / I40IW_QP_WQE_MIN_SIZE;
151 for (i = 0; i < nop_wqe_cnt; i++) {
152 i40iw_nop_1(qp);
153 I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
154 if (ret_code)
155 return NULL;
156 }
157
158 *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
159 if (!*wqe_idx)
160 qp->swqe_polarity = !qp->swqe_polarity;
161 }
162 for (i = 0; i < wqe_size / I40IW_QP_WQE_MIN_SIZE; i++) {
163 I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
164 if (ret_code)
165 return NULL;
166 }
167
168 wqe = qp->sq_base[*wqe_idx].elem;
169
170 peek_head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
171 wqe_0 = qp->sq_base[peek_head].elem;
172 if (peek_head & 0x3)
173 wqe_0[3] = LS_64(!qp->swqe_polarity, I40IWQPSQ_VALID);
174 return wqe;
175}
176
177/**
178 * i40iw_set_fragment - set fragment in wqe
179 * @wqe: wqe for setting fragment
180 * @offset: offset value
181 * @sge: sge length and stag
182 */
183static void i40iw_set_fragment(u64 *wqe, u32 offset, struct i40iw_sge *sge)
184{
185 if (sge) {
186 set_64bit_val(wqe, offset, LS_64(sge->tag_off, I40IWQPSQ_FRAG_TO));
187 set_64bit_val(wqe, (offset + 8),
188 (LS_64(sge->len, I40IWQPSQ_FRAG_LEN) |
189 LS_64(sge->stag, I40IWQPSQ_FRAG_STAG)));
190 }
191}
192
193/**
194 * i40iw_qp_get_next_recv_wqe - get next qp's rcv wqe
195 * @qp: hw qp ptr
196 * @wqe_idx: return wqe index
197 */
198u64 *i40iw_qp_get_next_recv_wqe(struct i40iw_qp_uk *qp, u32 *wqe_idx)
199{
200 u64 *wqe = NULL;
201 enum i40iw_status_code ret_code;
202
203 if (I40IW_RING_FULL_ERR(qp->rq_ring))
204 return NULL;
205
206 I40IW_ATOMIC_RING_MOVE_HEAD(qp->rq_ring, *wqe_idx, ret_code);
207 if (ret_code)
208 return NULL;
209 if (!*wqe_idx)
210 qp->rwqe_polarity = !qp->rwqe_polarity;
211 /* rq_wqe_size_multiplier is no of qwords in one rq wqe */
212 wqe = qp->rq_base[*wqe_idx * (qp->rq_wqe_size_multiplier >> 2)].elem;
213
214 return wqe;
215}
216
217/**
218 * i40iw_rdma_write - rdma write operation
219 * @qp: hw qp ptr
220 * @info: post sq information
221 * @post_sq: flag to post sq
222 */
223static enum i40iw_status_code i40iw_rdma_write(struct i40iw_qp_uk *qp,
224 struct i40iw_post_sq_info *info,
225 bool post_sq)
226{
227 u64 header;
228 u64 *wqe;
229 struct i40iw_rdma_write *op_info;
230 u32 i, wqe_idx;
231 u32 total_size = 0, byte_off;
232 enum i40iw_status_code ret_code;
233 bool read_fence = false;
234 u8 wqe_size;
235
236 op_info = &info->op.rdma_write;
237 if (op_info->num_lo_sges > qp->max_sq_frag_cnt)
238 return I40IW_ERR_INVALID_FRAG_COUNT;
239
240 for (i = 0; i < op_info->num_lo_sges; i++)
241 total_size += op_info->lo_sg_list[i].len;
242
243 if (total_size > I40IW_MAX_OUTBOUND_MESSAGE_SIZE)
244 return I40IW_ERR_QP_INVALID_MSG_SIZE;
245
246 read_fence |= info->read_fence;
247
248 ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_lo_sges, &wqe_size);
249 if (ret_code)
250 return ret_code;
251
252 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
253 if (!wqe)
254 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
255
256 qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
257 qp->sq_wrtrk_array[wqe_idx].wr_len = total_size;
258 set_64bit_val(wqe, 16,
259 LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
260 if (!op_info->rem_addr.stag)
261 return I40IW_ERR_BAD_STAG;
262
263 header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
264 LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
265 LS_64((op_info->num_lo_sges > 1 ? (op_info->num_lo_sges - 1) : 0), I40IWQPSQ_ADDFRAGCNT) |
266 LS_64(read_fence, I40IWQPSQ_READFENCE) |
267 LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
268 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
269 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
270
271 i40iw_set_fragment(wqe, 0, op_info->lo_sg_list);
272
273 for (i = 1; i < op_info->num_lo_sges; i++) {
274 byte_off = 32 + (i - 1) * 16;
275 i40iw_set_fragment(wqe, byte_off, &op_info->lo_sg_list[i]);
276 }
277
278 wmb(); /* make sure WQE is populated before valid bit is set */
279
280 set_64bit_val(wqe, 24, header);
281
282 if (post_sq)
283 i40iw_qp_post_wr(qp);
284
285 return 0;
286}
287
288/**
289 * i40iw_rdma_read - rdma read command
290 * @qp: hw qp ptr
291 * @info: post sq information
292 * @inv_stag: flag for inv_stag
293 * @post_sq: flag to post sq
294 */
295static enum i40iw_status_code i40iw_rdma_read(struct i40iw_qp_uk *qp,
296 struct i40iw_post_sq_info *info,
297 bool inv_stag,
298 bool post_sq)
299{
300 u64 *wqe;
301 struct i40iw_rdma_read *op_info;
302 u64 header;
303 u32 wqe_idx;
304 enum i40iw_status_code ret_code;
305 u8 wqe_size;
306 bool local_fence = false;
307
308 op_info = &info->op.rdma_read;
309 ret_code = i40iw_fragcnt_to_wqesize_sq(1, &wqe_size);
310 if (ret_code)
311 return ret_code;
312 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
313 if (!wqe)
314 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
315
316 qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
317 qp->sq_wrtrk_array[wqe_idx].wr_len = op_info->lo_addr.len;
318 local_fence |= info->local_fence;
319
320 set_64bit_val(wqe, 16, LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
321 header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
322 LS_64((inv_stag ? I40IWQP_OP_RDMA_READ_LOC_INV : I40IWQP_OP_RDMA_READ), I40IWQPSQ_OPCODE) |
323 LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
324 LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
325 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
326 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
327
328 i40iw_set_fragment(wqe, 0, &op_info->lo_addr);
329
330 wmb(); /* make sure WQE is populated before valid bit is set */
331
332 set_64bit_val(wqe, 24, header);
333 if (post_sq)
334 i40iw_qp_post_wr(qp);
335
336 return 0;
337}
338
339/**
340 * i40iw_send - rdma send command
341 * @qp: hw qp ptr
342 * @info: post sq information
343 * @stag_to_inv: stag_to_inv value
344 * @post_sq: flag to post sq
345 */
346static enum i40iw_status_code i40iw_send(struct i40iw_qp_uk *qp,
347 struct i40iw_post_sq_info *info,
348 u32 stag_to_inv,
349 bool post_sq)
350{
351 u64 *wqe;
352 struct i40iw_post_send *op_info;
353 u64 header;
354 u32 i, wqe_idx, total_size = 0, byte_off;
355 enum i40iw_status_code ret_code;
356 bool read_fence = false;
357 u8 wqe_size;
358
359 op_info = &info->op.send;
360 if (qp->max_sq_frag_cnt < op_info->num_sges)
361 return I40IW_ERR_INVALID_FRAG_COUNT;
362
363 for (i = 0; i < op_info->num_sges; i++)
364 total_size += op_info->sg_list[i].len;
365 ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_sges, &wqe_size);
366 if (ret_code)
367 return ret_code;
368
369 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
370 if (!wqe)
371 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
372
373 read_fence |= info->read_fence;
374 qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
375 qp->sq_wrtrk_array[wqe_idx].wr_len = total_size;
376 set_64bit_val(wqe, 16, 0);
377 header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
378 LS_64(info->op_type, I40IWQPSQ_OPCODE) |
379 LS_64((op_info->num_sges > 1 ? (op_info->num_sges - 1) : 0),
380 I40IWQPSQ_ADDFRAGCNT) |
381 LS_64(read_fence, I40IWQPSQ_READFENCE) |
382 LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
383 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
384 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
385
386 i40iw_set_fragment(wqe, 0, op_info->sg_list);
387
388 for (i = 1; i < op_info->num_sges; i++) {
389 byte_off = 32 + (i - 1) * 16;
390 i40iw_set_fragment(wqe, byte_off, &op_info->sg_list[i]);
391 }
392
393 wmb(); /* make sure WQE is populated before valid bit is set */
394
395 set_64bit_val(wqe, 24, header);
396 if (post_sq)
397 i40iw_qp_post_wr(qp);
398
399 return 0;
400}
401
402/**
403 * i40iw_inline_rdma_write - inline rdma write operation
404 * @qp: hw qp ptr
405 * @info: post sq information
406 * @post_sq: flag to post sq
407 */
408static enum i40iw_status_code i40iw_inline_rdma_write(struct i40iw_qp_uk *qp,
409 struct i40iw_post_sq_info *info,
410 bool post_sq)
411{
412 u64 *wqe;
413 u8 *dest, *src;
414 struct i40iw_inline_rdma_write *op_info;
415 u64 *push;
416 u64 header = 0;
417 u32 i, wqe_idx;
418 enum i40iw_status_code ret_code;
419 bool read_fence = false;
420 u8 wqe_size;
421
422 op_info = &info->op.inline_rdma_write;
423 if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
424 return I40IW_ERR_INVALID_IMM_DATA_SIZE;
425
426 ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
427 if (ret_code)
428 return ret_code;
429
430 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
431 if (!wqe)
432 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
433
434 read_fence |= info->read_fence;
435 qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
436 qp->sq_wrtrk_array[wqe_idx].wr_len = op_info->len;
437 set_64bit_val(wqe, 16,
438 LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
439
440 header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
441 LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
442 LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
443 LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
444 LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
445 LS_64(read_fence, I40IWQPSQ_READFENCE) |
446 LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
447 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
448 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
449
450 dest = (u8 *)wqe;
451 src = (u8 *)(op_info->data);
452
453 if (op_info->len <= 16) {
454 for (i = 0; i < op_info->len; i++, src++, dest++)
455 *dest = *src;
456 } else {
457 for (i = 0; i < 16; i++, src++, dest++)
458 *dest = *src;
459 dest = (u8 *)wqe + 32;
460 for (; i < op_info->len; i++, src++, dest++)
461 *dest = *src;
462 }
463
464 wmb(); /* make sure WQE is populated before valid bit is set */
465
466 set_64bit_val(wqe, 24, header);
467
468 if (qp->push_db) {
469 push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
470 memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
471 i40iw_qp_ring_push_db(qp, wqe_idx);
472 } else {
473 if (post_sq)
474 i40iw_qp_post_wr(qp);
475 }
476
477 return 0;
478}
479
480/**
481 * i40iw_inline_send - inline send operation
482 * @qp: hw qp ptr
483 * @info: post sq information
484 * @stag_to_inv: remote stag
485 * @post_sq: flag to post sq
486 */
487static enum i40iw_status_code i40iw_inline_send(struct i40iw_qp_uk *qp,
488 struct i40iw_post_sq_info *info,
489 u32 stag_to_inv,
490 bool post_sq)
491{
492 u64 *wqe;
493 u8 *dest, *src;
494 struct i40iw_post_inline_send *op_info;
495 u64 header;
496 u32 wqe_idx, i;
497 enum i40iw_status_code ret_code;
498 bool read_fence = false;
499 u8 wqe_size;
500 u64 *push;
501
502 op_info = &info->op.inline_send;
503 if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
504 return I40IW_ERR_INVALID_IMM_DATA_SIZE;
505
506 ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
507 if (ret_code)
508 return ret_code;
509
510 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
511 if (!wqe)
512 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
513
514 read_fence |= info->read_fence;
515
516 qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
517 qp->sq_wrtrk_array[wqe_idx].wr_len = op_info->len;
518 header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
519 LS_64(info->op_type, I40IWQPSQ_OPCODE) |
520 LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
521 LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
522 LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
523 LS_64(read_fence, I40IWQPSQ_READFENCE) |
524 LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
525 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
526 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
527
528 dest = (u8 *)wqe;
529 src = (u8 *)(op_info->data);
530
531 if (op_info->len <= 16) {
532 for (i = 0; i < op_info->len; i++, src++, dest++)
533 *dest = *src;
534 } else {
535 for (i = 0; i < 16; i++, src++, dest++)
536 *dest = *src;
537 dest = (u8 *)wqe + 32;
538 for (; i < op_info->len; i++, src++, dest++)
539 *dest = *src;
540 }
541
542 wmb(); /* make sure WQE is populated before valid bit is set */
543
544 set_64bit_val(wqe, 24, header);
545
546 if (qp->push_db) {
547 push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
548 memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
549 i40iw_qp_ring_push_db(qp, wqe_idx);
550 } else {
551 if (post_sq)
552 i40iw_qp_post_wr(qp);
553 }
554
555 return 0;
556}
557
558/**
559 * i40iw_stag_local_invalidate - stag invalidate operation
560 * @qp: hw qp ptr
561 * @info: post sq information
562 * @post_sq: flag to post sq
563 */
564static enum i40iw_status_code i40iw_stag_local_invalidate(struct i40iw_qp_uk *qp,
565 struct i40iw_post_sq_info *info,
566 bool post_sq)
567{
568 u64 *wqe;
569 struct i40iw_inv_local_stag *op_info;
570 u64 header;
571 u32 wqe_idx;
572 bool local_fence = false;
573
574 op_info = &info->op.inv_local_stag;
575 local_fence = info->local_fence;
576
577 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE);
578 if (!wqe)
579 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
580
581 qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
582 qp->sq_wrtrk_array[wqe_idx].wr_len = 0;
583 set_64bit_val(wqe, 0, 0);
584 set_64bit_val(wqe, 8,
585 LS_64(op_info->target_stag, I40IWQPSQ_LOCSTAG));
586 set_64bit_val(wqe, 16, 0);
587 header = LS_64(I40IW_OP_TYPE_INV_STAG, I40IWQPSQ_OPCODE) |
588 LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
589 LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
590 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
591 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
592
593 wmb(); /* make sure WQE is populated before valid bit is set */
594
595 set_64bit_val(wqe, 24, header);
596
597 if (post_sq)
598 i40iw_qp_post_wr(qp);
599
600 return 0;
601}
602
603/**
604 * i40iw_mw_bind - Memory Window bind operation
605 * @qp: hw qp ptr
606 * @info: post sq information
607 * @post_sq: flag to post sq
608 */
609static enum i40iw_status_code i40iw_mw_bind(struct i40iw_qp_uk *qp,
610 struct i40iw_post_sq_info *info,
611 bool post_sq)
612{
613 u64 *wqe;
614 struct i40iw_bind_window *op_info;
615 u64 header;
616 u32 wqe_idx;
617 bool local_fence = false;
618
619 op_info = &info->op.bind_window;
620
621 local_fence |= info->local_fence;
622 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE);
623 if (!wqe)
624 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
625
626 qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
627 qp->sq_wrtrk_array[wqe_idx].wr_len = 0;
628 set_64bit_val(wqe, 0, (uintptr_t)op_info->va);
629 set_64bit_val(wqe, 8,
630 LS_64(op_info->mr_stag, I40IWQPSQ_PARENTMRSTAG) |
631 LS_64(op_info->mw_stag, I40IWQPSQ_MWSTAG));
632 set_64bit_val(wqe, 16, op_info->bind_length);
633 header = LS_64(I40IW_OP_TYPE_BIND_MW, I40IWQPSQ_OPCODE) |
634 LS_64(((op_info->enable_reads << 2) |
635 (op_info->enable_writes << 3)),
636 I40IWQPSQ_STAGRIGHTS) |
637 LS_64((op_info->addressing_type == I40IW_ADDR_TYPE_VA_BASED ? 1 : 0),
638 I40IWQPSQ_VABASEDTO) |
639 LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
640 LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
641 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
642 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
643
644 wmb(); /* make sure WQE is populated before valid bit is set */
645
646 set_64bit_val(wqe, 24, header);
647
648 if (post_sq)
649 i40iw_qp_post_wr(qp);
650
651 return 0;
652}
653
654/**
655 * i40iw_post_receive - post receive wqe
656 * @qp: hw qp ptr
657 * @info: post rq information
658 */
659static enum i40iw_status_code i40iw_post_receive(struct i40iw_qp_uk *qp,
660 struct i40iw_post_rq_info *info)
661{
662 u64 *wqe;
663 u64 header;
664 u32 total_size = 0, wqe_idx, i, byte_off;
665
666 if (qp->max_rq_frag_cnt < info->num_sges)
667 return I40IW_ERR_INVALID_FRAG_COUNT;
668 for (i = 0; i < info->num_sges; i++)
669 total_size += info->sg_list[i].len;
670 wqe = i40iw_qp_get_next_recv_wqe(qp, &wqe_idx);
671 if (!wqe)
672 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
673
674 qp->rq_wrid_array[wqe_idx] = info->wr_id;
675 set_64bit_val(wqe, 16, 0);
676
677 header = LS_64((info->num_sges > 1 ? (info->num_sges - 1) : 0),
678 I40IWQPSQ_ADDFRAGCNT) |
679 LS_64(qp->rwqe_polarity, I40IWQPSQ_VALID);
680
681 i40iw_set_fragment(wqe, 0, info->sg_list);
682
683 for (i = 1; i < info->num_sges; i++) {
684 byte_off = 32 + (i - 1) * 16;
685 i40iw_set_fragment(wqe, byte_off, &info->sg_list[i]);
686 }
687
688 wmb(); /* make sure WQE is populated before valid bit is set */
689
690 set_64bit_val(wqe, 24, header);
691
692 return 0;
693}
694
695/**
696 * i40iw_cq_request_notification - cq notification request (door bell)
697 * @cq: hw cq
698 * @cq_notify: notification type
699 */
700static void i40iw_cq_request_notification(struct i40iw_cq_uk *cq,
701 enum i40iw_completion_notify cq_notify)
702{
703 u64 temp_val;
704 u16 sw_cq_sel;
705 u8 arm_next_se = 0;
706 u8 arm_next = 0;
707 u8 arm_seq_num;
708
709 get_64bit_val(cq->shadow_area, 32, &temp_val);
710 arm_seq_num = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_SEQ_NUM);
711 arm_seq_num++;
712
713 sw_cq_sel = (u16)RS_64(temp_val, I40IW_CQ_DBSA_SW_CQ_SELECT);
714 arm_next_se = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_NEXT_SE);
715 arm_next_se |= 1;
716 if (cq_notify == IW_CQ_COMPL_EVENT)
717 arm_next = 1;
718 temp_val = LS_64(arm_seq_num, I40IW_CQ_DBSA_ARM_SEQ_NUM) |
719 LS_64(sw_cq_sel, I40IW_CQ_DBSA_SW_CQ_SELECT) |
720 LS_64(arm_next_se, I40IW_CQ_DBSA_ARM_NEXT_SE) |
721 LS_64(arm_next, I40IW_CQ_DBSA_ARM_NEXT);
722
723 set_64bit_val(cq->shadow_area, 32, temp_val);
724
725 wmb(); /* make sure WQE is populated before valid bit is set */
726
727 writel(cq->cq_id, cq->cqe_alloc_reg);
728}
729
730/**
731 * i40iw_cq_post_entries - update tail in shadow memory
732 * @cq: hw cq
733 * @count: # of entries processed
734 */
735static enum i40iw_status_code i40iw_cq_post_entries(struct i40iw_cq_uk *cq,
736 u8 count)
737{
738 I40IW_RING_MOVE_TAIL_BY_COUNT(cq->cq_ring, count);
739 set_64bit_val(cq->shadow_area, 0,
740 I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
741 return 0;
742}
743
744/**
745 * i40iw_cq_poll_completion - get cq completion info
746 * @cq: hw cq
747 * @info: cq poll information returned
748 * @post_cq: update cq tail
749 */
750static enum i40iw_status_code i40iw_cq_poll_completion(struct i40iw_cq_uk *cq,
751 struct i40iw_cq_poll_info *info,
752 bool post_cq)
753{
754 u64 comp_ctx, qword0, qword2, qword3, wqe_qword;
755 u64 *cqe, *sw_wqe;
756 struct i40iw_qp_uk *qp;
757 struct i40iw_ring *pring = NULL;
758 u32 wqe_idx, q_type, array_idx = 0;
759 enum i40iw_status_code ret_code = 0;
760 enum i40iw_status_code ret_code2 = 0;
761 bool move_cq_head = true;
762 u8 polarity;
763 u8 addl_frag_cnt, addl_wqes = 0;
764
765 if (cq->avoid_mem_cflct)
766 cqe = (u64 *)I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(cq);
767 else
768 cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(cq);
769
770 get_64bit_val(cqe, 24, &qword3);
771 polarity = (u8)RS_64(qword3, I40IW_CQ_VALID);
772
773 if (polarity != cq->polarity)
774 return I40IW_ERR_QUEUE_EMPTY;
775
776 q_type = (u8)RS_64(qword3, I40IW_CQ_SQ);
777 info->error = (bool)RS_64(qword3, I40IW_CQ_ERROR);
778 info->push_dropped = (bool)RS_64(qword3, I40IWCQ_PSHDROP);
779 if (info->error) {
780 info->comp_status = I40IW_COMPL_STATUS_FLUSHED;
781 info->major_err = (bool)RS_64(qword3, I40IW_CQ_MAJERR);
782 info->minor_err = (bool)RS_64(qword3, I40IW_CQ_MINERR);
783 } else {
784 info->comp_status = I40IW_COMPL_STATUS_SUCCESS;
785 }
786
787 get_64bit_val(cqe, 0, &qword0);
788 get_64bit_val(cqe, 16, &qword2);
789
790 info->tcp_seq_num = (u8)RS_64(qword0, I40IWCQ_TCPSEQNUM);
791
792 info->qp_id = (u32)RS_64(qword2, I40IWCQ_QPID);
793
794 get_64bit_val(cqe, 8, &comp_ctx);
795
796 info->solicited_event = (bool)RS_64(qword3, I40IWCQ_SOEVENT);
797 info->is_srq = (bool)RS_64(qword3, I40IWCQ_SRQ);
798
799 qp = (struct i40iw_qp_uk *)(unsigned long)comp_ctx;
800 wqe_idx = (u32)RS_64(qword3, I40IW_CQ_WQEIDX);
801 info->qp_handle = (i40iw_qp_handle)(unsigned long)qp;
802
803 if (q_type == I40IW_CQE_QTYPE_RQ) {
804 array_idx = (wqe_idx * 4) / qp->rq_wqe_size_multiplier;
805 if (info->comp_status == I40IW_COMPL_STATUS_FLUSHED) {
806 info->wr_id = qp->rq_wrid_array[qp->rq_ring.tail];
807 array_idx = qp->rq_ring.tail;
808 } else {
809 info->wr_id = qp->rq_wrid_array[array_idx];
810 }
811
812 info->op_type = I40IW_OP_TYPE_REC;
813 if (qword3 & I40IWCQ_STAG_MASK) {
814 info->stag_invalid_set = true;
815 info->inv_stag = (u32)RS_64(qword2, I40IWCQ_INVSTAG);
816 } else {
817 info->stag_invalid_set = false;
818 }
819 info->bytes_xfered = (u32)RS_64(qword0, I40IWCQ_PAYLDLEN);
820 I40IW_RING_SET_TAIL(qp->rq_ring, array_idx + 1);
821 pring = &qp->rq_ring;
822 } else {
823 if (info->comp_status != I40IW_COMPL_STATUS_FLUSHED) {
824 info->wr_id = qp->sq_wrtrk_array[wqe_idx].wrid;
825 info->bytes_xfered = qp->sq_wrtrk_array[wqe_idx].wr_len;
826
827 info->op_type = (u8)RS_64(qword3, I40IWCQ_OP);
828 sw_wqe = qp->sq_base[wqe_idx].elem;
829 get_64bit_val(sw_wqe, 24, &wqe_qword);
830 addl_frag_cnt =
831 (u8)RS_64(wqe_qword, I40IWQPSQ_ADDFRAGCNT);
832 i40iw_fragcnt_to_wqesize_sq(addl_frag_cnt + 1, &addl_wqes);
833
834 addl_wqes = (addl_wqes / I40IW_QP_WQE_MIN_SIZE);
835 I40IW_RING_SET_TAIL(qp->sq_ring, (wqe_idx + addl_wqes));
836 } else {
837 do {
838 u8 op_type;
839 u32 tail;
840
841 tail = qp->sq_ring.tail;
842 sw_wqe = qp->sq_base[tail].elem;
843 get_64bit_val(sw_wqe, 24, &wqe_qword);
844 op_type = (u8)RS_64(wqe_qword, I40IWQPSQ_OPCODE);
845 info->op_type = op_type;
846 addl_frag_cnt = (u8)RS_64(wqe_qword, I40IWQPSQ_ADDFRAGCNT);
847 i40iw_fragcnt_to_wqesize_sq(addl_frag_cnt + 1, &addl_wqes);
848 addl_wqes = (addl_wqes / I40IW_QP_WQE_MIN_SIZE);
849 I40IW_RING_SET_TAIL(qp->sq_ring, (tail + addl_wqes));
850 if (op_type != I40IWQP_OP_NOP) {
851 info->wr_id = qp->sq_wrtrk_array[tail].wrid;
852 info->bytes_xfered = qp->sq_wrtrk_array[tail].wr_len;
853 break;
854 }
855 } while (1);
856 }
857 pring = &qp->sq_ring;
858 }
859
860 ret_code = 0;
861
862 if (!ret_code &&
863 (info->comp_status == I40IW_COMPL_STATUS_FLUSHED))
864 if (pring && (I40IW_RING_MORE_WORK(*pring)))
865 move_cq_head = false;
866
867 if (move_cq_head) {
868 I40IW_RING_MOVE_HEAD(cq->cq_ring, ret_code2);
869
870 if (ret_code2 && !ret_code)
871 ret_code = ret_code2;
872
873 if (I40IW_RING_GETCURRENT_HEAD(cq->cq_ring) == 0)
874 cq->polarity ^= 1;
875
876 if (post_cq) {
877 I40IW_RING_MOVE_TAIL(cq->cq_ring);
878 set_64bit_val(cq->shadow_area, 0,
879 I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
880 }
881 } else {
882 if (info->is_srq)
883 return ret_code;
884 qword3 &= ~I40IW_CQ_WQEIDX_MASK;
885 qword3 |= LS_64(pring->tail, I40IW_CQ_WQEIDX);
886 set_64bit_val(cqe, 24, qword3);
887 }
888
889 return ret_code;
890}
891
892/**
893 * i40iw_get_wqe_shift - get shift count for maximum wqe size
894 * @wqdepth: depth of wq required.
895 * @sge: Maximum Scatter Gather Elements wqe
896 * @shift: Returns the shift needed based on sge
897 *
898 * Shift can be used to left shift the wqe size based on sge.
899 * If sge, == 1, shift =0 (wqe_size of 32 bytes), for sge=2 and 3, shift =1
900 * (64 bytes wqes) and 2 otherwise (128 bytes wqe).
901 */
902enum i40iw_status_code i40iw_get_wqe_shift(u32 wqdepth, u8 sge, u8 *shift)
903{
904 u32 size;
905
906 *shift = 0;
907 if (sge > 1)
908 *shift = (sge < 4) ? 1 : 2;
909
910 /* check if wqdepth is multiple of 2 or not */
911
912 if ((wqdepth < I40IWQP_SW_MIN_WQSIZE) || (wqdepth & (wqdepth - 1)))
913 return I40IW_ERR_INVALID_SIZE;
914
915 size = wqdepth << *shift; /* multiple of 32 bytes count */
916 if (size > I40IWQP_SW_MAX_WQSIZE)
917 return I40IW_ERR_INVALID_SIZE;
918 return 0;
919}
920
921static struct i40iw_qp_uk_ops iw_qp_uk_ops = {
922 i40iw_qp_post_wr,
923 i40iw_qp_ring_push_db,
924 i40iw_rdma_write,
925 i40iw_rdma_read,
926 i40iw_send,
927 i40iw_inline_rdma_write,
928 i40iw_inline_send,
929 i40iw_stag_local_invalidate,
930 i40iw_mw_bind,
931 i40iw_post_receive,
932 i40iw_nop
933};
934
935static struct i40iw_cq_ops iw_cq_ops = {
936 i40iw_cq_request_notification,
937 i40iw_cq_poll_completion,
938 i40iw_cq_post_entries,
939 i40iw_clean_cq
940};
941
942static struct i40iw_device_uk_ops iw_device_uk_ops = {
943 i40iw_cq_uk_init,
944 i40iw_qp_uk_init,
945};
946
947/**
948 * i40iw_qp_uk_init - initialize shared qp
949 * @qp: hw qp (user and kernel)
950 * @info: qp initialization info
951 *
952 * initializes the vars used in both user and kernel mode.
953 * size of the wqe depends on numbers of max. fragements
954 * allowed. Then size of wqe * the number of wqes should be the
955 * amount of memory allocated for sq and rq. If srq is used,
956 * then rq_base will point to one rq wqe only (not the whole
957 * array of wqes)
958 */
959enum i40iw_status_code i40iw_qp_uk_init(struct i40iw_qp_uk *qp,
960 struct i40iw_qp_uk_init_info *info)
961{
962 enum i40iw_status_code ret_code = 0;
963 u32 sq_ring_size;
964 u8 sqshift, rqshift;
965
966 if (info->max_sq_frag_cnt > I40IW_MAX_WQ_FRAGMENT_COUNT)
967 return I40IW_ERR_INVALID_FRAG_COUNT;
968
969 if (info->max_rq_frag_cnt > I40IW_MAX_WQ_FRAGMENT_COUNT)
970 return I40IW_ERR_INVALID_FRAG_COUNT;
971 ret_code = i40iw_get_wqe_shift(info->sq_size, info->max_sq_frag_cnt, &sqshift);
972 if (ret_code)
973 return ret_code;
974
975 ret_code = i40iw_get_wqe_shift(info->rq_size, info->max_rq_frag_cnt, &rqshift);
976 if (ret_code)
977 return ret_code;
978
979 qp->sq_base = info->sq;
980 qp->rq_base = info->rq;
981 qp->shadow_area = info->shadow_area;
982 qp->sq_wrtrk_array = info->sq_wrtrk_array;
983 qp->rq_wrid_array = info->rq_wrid_array;
984
985 qp->wqe_alloc_reg = info->wqe_alloc_reg;
986 qp->qp_id = info->qp_id;
987
988 qp->sq_size = info->sq_size;
989 qp->push_db = info->push_db;
990 qp->push_wqe = info->push_wqe;
991
992 qp->max_sq_frag_cnt = info->max_sq_frag_cnt;
993 sq_ring_size = qp->sq_size << sqshift;
994
995 I40IW_RING_INIT(qp->sq_ring, sq_ring_size);
996 I40IW_RING_INIT(qp->initial_ring, sq_ring_size);
997 I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
998 I40IW_RING_MOVE_TAIL(qp->sq_ring);
999 I40IW_RING_MOVE_HEAD(qp->initial_ring, ret_code);
1000 qp->swqe_polarity = 1;
1001 qp->swqe_polarity_deferred = 1;
1002 qp->rwqe_polarity = 0;
1003
1004 if (!qp->use_srq) {
1005 qp->rq_size = info->rq_size;
1006 qp->max_rq_frag_cnt = info->max_rq_frag_cnt;
1007 qp->rq_wqe_size = rqshift;
1008 I40IW_RING_INIT(qp->rq_ring, qp->rq_size);
1009 qp->rq_wqe_size_multiplier = 4 << rqshift;
1010 }
1011 qp->ops = iw_qp_uk_ops;
1012
1013 return ret_code;
1014}
1015
1016/**
1017 * i40iw_cq_uk_init - initialize shared cq (user and kernel)
1018 * @cq: hw cq
1019 * @info: hw cq initialization info
1020 */
1021enum i40iw_status_code i40iw_cq_uk_init(struct i40iw_cq_uk *cq,
1022 struct i40iw_cq_uk_init_info *info)
1023{
1024 if ((info->cq_size < I40IW_MIN_CQ_SIZE) ||
1025 (info->cq_size > I40IW_MAX_CQ_SIZE))
1026 return I40IW_ERR_INVALID_SIZE;
1027 cq->cq_base = (struct i40iw_cqe *)info->cq_base;
1028 cq->cq_id = info->cq_id;
1029 cq->cq_size = info->cq_size;
1030 cq->cqe_alloc_reg = info->cqe_alloc_reg;
1031 cq->shadow_area = info->shadow_area;
1032 cq->avoid_mem_cflct = info->avoid_mem_cflct;
1033
1034 I40IW_RING_INIT(cq->cq_ring, cq->cq_size);
1035 cq->polarity = 1;
1036 cq->ops = iw_cq_ops;
1037
1038 return 0;
1039}
1040
1041/**
1042 * i40iw_device_init_uk - setup routines for iwarp shared device
1043 * @dev: iwarp shared (user and kernel)
1044 */
1045void i40iw_device_init_uk(struct i40iw_dev_uk *dev)
1046{
1047 dev->ops_uk = iw_device_uk_ops;
1048}
1049
1050/**
1051 * i40iw_clean_cq - clean cq entries
1052 * @ queue completion context
1053 * @cq: cq to clean
1054 */
1055void i40iw_clean_cq(void *queue, struct i40iw_cq_uk *cq)
1056{
1057 u64 *cqe;
1058 u64 qword3, comp_ctx;
1059 u32 cq_head;
1060 u8 polarity, temp;
1061
1062 cq_head = cq->cq_ring.head;
1063 temp = cq->polarity;
1064 do {
1065 if (cq->avoid_mem_cflct)
1066 cqe = (u64 *)&(((struct i40iw_extended_cqe *)cq->cq_base)[cq_head]);
1067 else
1068 cqe = (u64 *)&cq->cq_base[cq_head];
1069 get_64bit_val(cqe, 24, &qword3);
1070 polarity = (u8)RS_64(qword3, I40IW_CQ_VALID);
1071
1072 if (polarity != temp)
1073 break;
1074
1075 get_64bit_val(cqe, 8, &comp_ctx);
1076 if ((void *)(unsigned long)comp_ctx == queue)
1077 set_64bit_val(cqe, 8, 0);
1078
1079 cq_head = (cq_head + 1) % cq->cq_ring.size;
1080 if (!cq_head)
1081 temp ^= 1;
1082 } while (true);
1083}
1084
1085/**
1086 * i40iw_nop - send a nop
1087 * @qp: hw qp ptr
1088 * @wr_id: work request id
1089 * @signaled: flag if signaled for completion
1090 * @post_sq: flag to post sq
1091 */
1092enum i40iw_status_code i40iw_nop(struct i40iw_qp_uk *qp,
1093 u64 wr_id,
1094 bool signaled,
1095 bool post_sq)
1096{
1097 u64 header, *wqe;
1098 u32 wqe_idx;
1099
1100 wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE);
1101 if (!wqe)
1102 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
1103
1104 qp->sq_wrtrk_array[wqe_idx].wrid = wr_id;
1105 qp->sq_wrtrk_array[wqe_idx].wr_len = 0;
1106 set_64bit_val(wqe, 0, 0);
1107 set_64bit_val(wqe, 8, 0);
1108 set_64bit_val(wqe, 16, 0);
1109
1110 header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
1111 LS_64(signaled, I40IWQPSQ_SIGCOMPL) |
1112 LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
1113
1114 wmb(); /* make sure WQE is populated before valid bit is set */
1115
1116 set_64bit_val(wqe, 24, header);
1117 if (post_sq)
1118 i40iw_qp_post_wr(qp);
1119
1120 return 0;
1121}
1122
1123/**
1124 * i40iw_fragcnt_to_wqesize_sq - calculate wqe size based on fragment count for SQ
1125 * @frag_cnt: number of fragments
1126 * @wqe_size: size of sq wqe returned
1127 */
1128enum i40iw_status_code i40iw_fragcnt_to_wqesize_sq(u8 frag_cnt, u8 *wqe_size)
1129{
1130 switch (frag_cnt) {
1131 case 0:
1132 case 1:
1133 *wqe_size = I40IW_QP_WQE_MIN_SIZE;
1134 break;
1135 case 2:
1136 case 3:
1137 *wqe_size = 64;
1138 break;
1139 case 4:
1140 case 5:
1141 *wqe_size = 96;
1142 break;
1143 case 6:
1144 case 7:
1145 *wqe_size = 128;
1146 break;
1147 default:
1148 return I40IW_ERR_INVALID_FRAG_COUNT;
1149 }
1150
1151 return 0;
1152}
1153
1154/**
1155 * i40iw_fragcnt_to_wqesize_rq - calculate wqe size based on fragment count for RQ
1156 * @frag_cnt: number of fragments
1157 * @wqe_size: size of rq wqe returned
1158 */
1159enum i40iw_status_code i40iw_fragcnt_to_wqesize_rq(u8 frag_cnt, u8 *wqe_size)
1160{
1161 switch (frag_cnt) {
1162 case 0:
1163 case 1:
1164 *wqe_size = 32;
1165 break;
1166 case 2:
1167 case 3:
1168 *wqe_size = 64;
1169 break;
1170 case 4:
1171 case 5:
1172 case 6:
1173 case 7:
1174 *wqe_size = 128;
1175 break;
1176 default:
1177 return I40IW_ERR_INVALID_FRAG_COUNT;
1178 }
1179
1180 return 0;
1181}
1182
1183/**
1184 * i40iw_inline_data_size_to_wqesize - based on inline data, wqe size
1185 * @data_size: data size for inline
1186 * @wqe_size: size of sq wqe returned
1187 */
1188enum i40iw_status_code i40iw_inline_data_size_to_wqesize(u32 data_size,
1189 u8 *wqe_size)
1190{
1191 if (data_size > I40IW_MAX_INLINE_DATA_SIZE)
1192 return I40IW_ERR_INVALID_IMM_DATA_SIZE;
1193
1194 if (data_size <= 16)
1195 *wqe_size = I40IW_QP_WQE_MIN_SIZE;
1196 else if (data_size <= 48)
1197 *wqe_size = 64;
1198 else if (data_size <= 80)
1199 *wqe_size = 96;
1200 else
1201 *wqe_size = 128;
1202
1203 return 0;
1204}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_user.h b/drivers/infiniband/hw/i40iw/i40iw_user.h
new file mode 100644
index 000000000000..5cd971bb8cc7
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_user.h
@@ -0,0 +1,442 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_USER_H
36#define I40IW_USER_H
37
38enum i40iw_device_capabilities_const {
39 I40IW_WQE_SIZE = 4,
40 I40IW_CQP_WQE_SIZE = 8,
41 I40IW_CQE_SIZE = 4,
42 I40IW_EXTENDED_CQE_SIZE = 8,
43 I40IW_AEQE_SIZE = 2,
44 I40IW_CEQE_SIZE = 1,
45 I40IW_CQP_CTX_SIZE = 8,
46 I40IW_SHADOW_AREA_SIZE = 8,
47 I40IW_CEQ_MAX_COUNT = 256,
48 I40IW_QUERY_FPM_BUF_SIZE = 128,
49 I40IW_COMMIT_FPM_BUF_SIZE = 128,
50 I40IW_MIN_IW_QP_ID = 1,
51 I40IW_MAX_IW_QP_ID = 262143,
52 I40IW_MIN_CEQID = 0,
53 I40IW_MAX_CEQID = 256,
54 I40IW_MIN_CQID = 0,
55 I40IW_MAX_CQID = 131071,
56 I40IW_MIN_AEQ_ENTRIES = 1,
57 I40IW_MAX_AEQ_ENTRIES = 524287,
58 I40IW_MIN_CEQ_ENTRIES = 1,
59 I40IW_MAX_CEQ_ENTRIES = 131071,
60 I40IW_MIN_CQ_SIZE = 1,
61 I40IW_MAX_CQ_SIZE = 1048575,
62 I40IW_MAX_AEQ_ALLOCATE_COUNT = 255,
63 I40IW_DB_ID_ZERO = 0,
64 I40IW_MAX_WQ_FRAGMENT_COUNT = 6,
65 I40IW_MAX_SGE_RD = 1,
66 I40IW_MAX_OUTBOUND_MESSAGE_SIZE = 2147483647,
67 I40IW_MAX_INBOUND_MESSAGE_SIZE = 2147483647,
68 I40IW_MAX_PUSH_PAGE_COUNT = 4096,
69 I40IW_MAX_PE_ENABLED_VF_COUNT = 32,
70 I40IW_MAX_VF_FPM_ID = 47,
71 I40IW_MAX_VF_PER_PF = 127,
72 I40IW_MAX_SQ_PAYLOAD_SIZE = 2145386496,
73 I40IW_MAX_INLINE_DATA_SIZE = 112,
74 I40IW_MAX_PUSHMODE_INLINE_DATA_SIZE = 112,
75 I40IW_MAX_IRD_SIZE = 32,
76 I40IW_QPCTX_ENCD_MAXIRD = 3,
77 I40IW_MAX_WQ_ENTRIES = 2048,
78 I40IW_MAX_ORD_SIZE = 32,
79 I40IW_Q2_BUFFER_SIZE = (248 + 100),
80 I40IW_QP_CTX_SIZE = 248
81};
82
83#define i40iw_handle void *
84#define i40iw_adapter_handle i40iw_handle
85#define i40iw_qp_handle i40iw_handle
86#define i40iw_cq_handle i40iw_handle
87#define i40iw_srq_handle i40iw_handle
88#define i40iw_pd_id i40iw_handle
89#define i40iw_stag_handle i40iw_handle
90#define i40iw_stag_index u32
91#define i40iw_stag u32
92#define i40iw_stag_key u8
93
94#define i40iw_tagged_offset u64
95#define i40iw_access_privileges u32
96#define i40iw_physical_fragment u64
97#define i40iw_address_list u64 *
98
99#define I40IW_CREATE_STAG(index, key) (((index) << 8) + (key))
100
101#define I40IW_STAG_KEY_FROM_STAG(stag) ((stag) && 0x000000FF)
102
103#define I40IW_STAG_INDEX_FROM_STAG(stag) (((stag) && 0xFFFFFF00) >> 8)
104
105struct i40iw_qp_uk;
106struct i40iw_cq_uk;
107struct i40iw_srq_uk;
108struct i40iw_qp_uk_init_info;
109struct i40iw_cq_uk_init_info;
110struct i40iw_srq_uk_init_info;
111
112struct i40iw_sge {
113 i40iw_tagged_offset tag_off;
114 u32 len;
115 i40iw_stag stag;
116};
117
118#define i40iw_sgl struct i40iw_sge *
119
120struct i40iw_ring {
121 u32 head;
122 u32 tail;
123 u32 size;
124};
125
126struct i40iw_cqe {
127 u64 buf[I40IW_CQE_SIZE];
128};
129
130struct i40iw_extended_cqe {
131 u64 buf[I40IW_EXTENDED_CQE_SIZE];
132};
133
134struct i40iw_wqe {
135 u64 buf[I40IW_WQE_SIZE];
136};
137
138struct i40iw_qp_uk_ops;
139
140enum i40iw_addressing_type {
141 I40IW_ADDR_TYPE_ZERO_BASED = 0,
142 I40IW_ADDR_TYPE_VA_BASED = 1,
143};
144
145#define I40IW_ACCESS_FLAGS_LOCALREAD 0x01
146#define I40IW_ACCESS_FLAGS_LOCALWRITE 0x02
147#define I40IW_ACCESS_FLAGS_REMOTEREAD_ONLY 0x04
148#define I40IW_ACCESS_FLAGS_REMOTEREAD 0x05
149#define I40IW_ACCESS_FLAGS_REMOTEWRITE_ONLY 0x08
150#define I40IW_ACCESS_FLAGS_REMOTEWRITE 0x0a
151#define I40IW_ACCESS_FLAGS_BIND_WINDOW 0x10
152#define I40IW_ACCESS_FLAGS_ALL 0x1F
153
154#define I40IW_OP_TYPE_RDMA_WRITE 0
155#define I40IW_OP_TYPE_RDMA_READ 1
156#define I40IW_OP_TYPE_SEND 3
157#define I40IW_OP_TYPE_SEND_INV 4
158#define I40IW_OP_TYPE_SEND_SOL 5
159#define I40IW_OP_TYPE_SEND_SOL_INV 6
160#define I40IW_OP_TYPE_REC 7
161#define I40IW_OP_TYPE_BIND_MW 8
162#define I40IW_OP_TYPE_FAST_REG_NSMR 9
163#define I40IW_OP_TYPE_INV_STAG 10
164#define I40IW_OP_TYPE_RDMA_READ_INV_STAG 11
165#define I40IW_OP_TYPE_NOP 12
166
167enum i40iw_completion_status {
168 I40IW_COMPL_STATUS_SUCCESS = 0,
169 I40IW_COMPL_STATUS_FLUSHED,
170 I40IW_COMPL_STATUS_INVALID_WQE,
171 I40IW_COMPL_STATUS_QP_CATASTROPHIC,
172 I40IW_COMPL_STATUS_REMOTE_TERMINATION,
173 I40IW_COMPL_STATUS_INVALID_STAG,
174 I40IW_COMPL_STATUS_BASE_BOUND_VIOLATION,
175 I40IW_COMPL_STATUS_ACCESS_VIOLATION,
176 I40IW_COMPL_STATUS_INVALID_PD_ID,
177 I40IW_COMPL_STATUS_WRAP_ERROR,
178 I40IW_COMPL_STATUS_STAG_INVALID_PDID,
179 I40IW_COMPL_STATUS_RDMA_READ_ZERO_ORD,
180 I40IW_COMPL_STATUS_QP_NOT_PRIVLEDGED,
181 I40IW_COMPL_STATUS_STAG_NOT_INVALID,
182 I40IW_COMPL_STATUS_INVALID_PHYS_BUFFER_SIZE,
183 I40IW_COMPL_STATUS_INVALID_PHYS_BUFFER_ENTRY,
184 I40IW_COMPL_STATUS_INVALID_FBO,
185 I40IW_COMPL_STATUS_INVALID_LENGTH,
186 I40IW_COMPL_STATUS_INVALID_ACCESS,
187 I40IW_COMPL_STATUS_PHYS_BUFFER_LIST_TOO_LONG,
188 I40IW_COMPL_STATUS_INVALID_VIRT_ADDRESS,
189 I40IW_COMPL_STATUS_INVALID_REGION,
190 I40IW_COMPL_STATUS_INVALID_WINDOW,
191 I40IW_COMPL_STATUS_INVALID_TOTAL_LENGTH
192};
193
194enum i40iw_completion_notify {
195 IW_CQ_COMPL_EVENT = 0,
196 IW_CQ_COMPL_SOLICITED = 1
197};
198
199struct i40iw_post_send {
200 i40iw_sgl sg_list;
201 u8 num_sges;
202};
203
204struct i40iw_post_inline_send {
205 void *data;
206 u32 len;
207};
208
209struct i40iw_post_send_w_inv {
210 i40iw_sgl sg_list;
211 u32 num_sges;
212 i40iw_stag remote_stag_to_inv;
213};
214
215struct i40iw_post_inline_send_w_inv {
216 void *data;
217 u32 len;
218 i40iw_stag remote_stag_to_inv;
219};
220
221struct i40iw_rdma_write {
222 i40iw_sgl lo_sg_list;
223 u8 num_lo_sges;
224 struct i40iw_sge rem_addr;
225};
226
227struct i40iw_inline_rdma_write {
228 void *data;
229 u32 len;
230 struct i40iw_sge rem_addr;
231};
232
233struct i40iw_rdma_read {
234 struct i40iw_sge lo_addr;
235 struct i40iw_sge rem_addr;
236};
237
238struct i40iw_bind_window {
239 i40iw_stag mr_stag;
240 u64 bind_length;
241 void *va;
242 enum i40iw_addressing_type addressing_type;
243 bool enable_reads;
244 bool enable_writes;
245 i40iw_stag mw_stag;
246};
247
248struct i40iw_inv_local_stag {
249 i40iw_stag target_stag;
250};
251
252struct i40iw_post_sq_info {
253 u64 wr_id;
254 u8 op_type;
255 bool signaled;
256 bool read_fence;
257 bool local_fence;
258 bool inline_data;
259 bool defer_flag;
260 union {
261 struct i40iw_post_send send;
262 struct i40iw_post_send send_w_sol;
263 struct i40iw_post_send_w_inv send_w_inv;
264 struct i40iw_post_send_w_inv send_w_sol_inv;
265 struct i40iw_rdma_write rdma_write;
266 struct i40iw_rdma_read rdma_read;
267 struct i40iw_rdma_read rdma_read_inv;
268 struct i40iw_bind_window bind_window;
269 struct i40iw_inv_local_stag inv_local_stag;
270 struct i40iw_inline_rdma_write inline_rdma_write;
271 struct i40iw_post_inline_send inline_send;
272 struct i40iw_post_inline_send inline_send_w_sol;
273 struct i40iw_post_inline_send_w_inv inline_send_w_inv;
274 struct i40iw_post_inline_send_w_inv inline_send_w_sol_inv;
275 } op;
276};
277
278struct i40iw_post_rq_info {
279 u64 wr_id;
280 i40iw_sgl sg_list;
281 u32 num_sges;
282};
283
284struct i40iw_cq_poll_info {
285 u64 wr_id;
286 i40iw_qp_handle qp_handle;
287 u32 bytes_xfered;
288 u32 tcp_seq_num;
289 u32 qp_id;
290 i40iw_stag inv_stag;
291 enum i40iw_completion_status comp_status;
292 u16 major_err;
293 u16 minor_err;
294 u8 op_type;
295 bool stag_invalid_set;
296 bool push_dropped;
297 bool error;
298 bool is_srq;
299 bool solicited_event;
300};
301
302struct i40iw_qp_uk_ops {
303 void (*iw_qp_post_wr)(struct i40iw_qp_uk *);
304 void (*iw_qp_ring_push_db)(struct i40iw_qp_uk *, u32);
305 enum i40iw_status_code (*iw_rdma_write)(struct i40iw_qp_uk *,
306 struct i40iw_post_sq_info *, bool);
307 enum i40iw_status_code (*iw_rdma_read)(struct i40iw_qp_uk *,
308 struct i40iw_post_sq_info *, bool, bool);
309 enum i40iw_status_code (*iw_send)(struct i40iw_qp_uk *,
310 struct i40iw_post_sq_info *, u32, bool);
311 enum i40iw_status_code (*iw_inline_rdma_write)(struct i40iw_qp_uk *,
312 struct i40iw_post_sq_info *, bool);
313 enum i40iw_status_code (*iw_inline_send)(struct i40iw_qp_uk *,
314 struct i40iw_post_sq_info *, u32, bool);
315 enum i40iw_status_code (*iw_stag_local_invalidate)(struct i40iw_qp_uk *,
316 struct i40iw_post_sq_info *, bool);
317 enum i40iw_status_code (*iw_mw_bind)(struct i40iw_qp_uk *,
318 struct i40iw_post_sq_info *, bool);
319 enum i40iw_status_code (*iw_post_receive)(struct i40iw_qp_uk *,
320 struct i40iw_post_rq_info *);
321 enum i40iw_status_code (*iw_post_nop)(struct i40iw_qp_uk *, u64, bool, bool);
322};
323
324struct i40iw_cq_ops {
325 void (*iw_cq_request_notification)(struct i40iw_cq_uk *,
326 enum i40iw_completion_notify);
327 enum i40iw_status_code (*iw_cq_poll_completion)(struct i40iw_cq_uk *,
328 struct i40iw_cq_poll_info *, bool);
329 enum i40iw_status_code (*iw_cq_post_entries)(struct i40iw_cq_uk *, u8 count);
330 void (*iw_cq_clean)(void *, struct i40iw_cq_uk *);
331};
332
333struct i40iw_dev_uk;
334
335struct i40iw_device_uk_ops {
336 enum i40iw_status_code (*iwarp_cq_uk_init)(struct i40iw_cq_uk *,
337 struct i40iw_cq_uk_init_info *);
338 enum i40iw_status_code (*iwarp_qp_uk_init)(struct i40iw_qp_uk *,
339 struct i40iw_qp_uk_init_info *);
340};
341
342struct i40iw_dev_uk {
343 struct i40iw_device_uk_ops ops_uk;
344};
345
346struct i40iw_sq_uk_wr_trk_info {
347 u64 wrid;
348 u64 wr_len;
349};
350
351struct i40iw_qp_quanta {
352 u64 elem[I40IW_WQE_SIZE];
353};
354
355struct i40iw_qp_uk {
356 struct i40iw_qp_quanta *sq_base;
357 struct i40iw_qp_quanta *rq_base;
358 u32 __iomem *wqe_alloc_reg;
359 struct i40iw_sq_uk_wr_trk_info *sq_wrtrk_array;
360 u64 *rq_wrid_array;
361 u64 *shadow_area;
362 u32 *push_db;
363 u64 *push_wqe;
364 struct i40iw_ring sq_ring;
365 struct i40iw_ring rq_ring;
366 struct i40iw_ring initial_ring;
367 u32 qp_id;
368 u32 sq_size;
369 u32 rq_size;
370 struct i40iw_qp_uk_ops ops;
371 bool use_srq;
372 u8 swqe_polarity;
373 u8 swqe_polarity_deferred;
374 u8 rwqe_polarity;
375 u8 rq_wqe_size;
376 u8 rq_wqe_size_multiplier;
377 u8 max_sq_frag_cnt;
378 u8 max_rq_frag_cnt;
379 bool deferred_flag;
380};
381
382struct i40iw_cq_uk {
383 struct i40iw_cqe *cq_base;
384 u32 __iomem *cqe_alloc_reg;
385 u64 *shadow_area;
386 u32 cq_id;
387 u32 cq_size;
388 struct i40iw_ring cq_ring;
389 u8 polarity;
390 bool avoid_mem_cflct;
391
392 struct i40iw_cq_ops ops;
393};
394
395struct i40iw_qp_uk_init_info {
396 struct i40iw_qp_quanta *sq;
397 struct i40iw_qp_quanta *rq;
398 u32 __iomem *wqe_alloc_reg;
399 u64 *shadow_area;
400 struct i40iw_sq_uk_wr_trk_info *sq_wrtrk_array;
401 u64 *rq_wrid_array;
402 u32 *push_db;
403 u64 *push_wqe;
404 u32 qp_id;
405 u32 sq_size;
406 u32 rq_size;
407 u8 max_sq_frag_cnt;
408 u8 max_rq_frag_cnt;
409
410};
411
412struct i40iw_cq_uk_init_info {
413 u32 __iomem *cqe_alloc_reg;
414 struct i40iw_cqe *cq_base;
415 u64 *shadow_area;
416 u32 cq_size;
417 u32 cq_id;
418 bool avoid_mem_cflct;
419};
420
421void i40iw_device_init_uk(struct i40iw_dev_uk *dev);
422
423void i40iw_qp_post_wr(struct i40iw_qp_uk *qp);
424u64 *i40iw_qp_get_next_send_wqe(struct i40iw_qp_uk *qp, u32 *wqe_idx,
425 u8 wqe_size);
426u64 *i40iw_qp_get_next_recv_wqe(struct i40iw_qp_uk *qp, u32 *wqe_idx);
427u64 *i40iw_qp_get_next_srq_wqe(struct i40iw_srq_uk *srq, u32 *wqe_idx);
428
429enum i40iw_status_code i40iw_cq_uk_init(struct i40iw_cq_uk *cq,
430 struct i40iw_cq_uk_init_info *info);
431enum i40iw_status_code i40iw_qp_uk_init(struct i40iw_qp_uk *qp,
432 struct i40iw_qp_uk_init_info *info);
433
434void i40iw_clean_cq(void *queue, struct i40iw_cq_uk *cq);
435enum i40iw_status_code i40iw_nop(struct i40iw_qp_uk *qp, u64 wr_id,
436 bool signaled, bool post_sq);
437enum i40iw_status_code i40iw_fragcnt_to_wqesize_sq(u8 frag_cnt, u8 *wqe_size);
438enum i40iw_status_code i40iw_fragcnt_to_wqesize_rq(u8 frag_cnt, u8 *wqe_size);
439enum i40iw_status_code i40iw_inline_data_size_to_wqesize(u32 data_size,
440 u8 *wqe_size);
441enum i40iw_status_code i40iw_get_wqe_shift(u32 wqdepth, u8 sge, u8 *shift);
442#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_utils.c b/drivers/infiniband/hw/i40iw/i40iw_utils.c
new file mode 100644
index 000000000000..1ceec81bd8eb
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_utils.c
@@ -0,0 +1,1270 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/ethtool.h>
40#include <linux/mii.h>
41#include <linux/if_vlan.h>
42#include <linux/crc32.h>
43#include <linux/in.h>
44#include <linux/ip.h>
45#include <linux/tcp.h>
46#include <linux/init.h>
47#include <linux/io.h>
48#include <asm/irq.h>
49#include <asm/byteorder.h>
50#include <net/netevent.h>
51#include <net/neighbour.h>
52#include "i40iw.h"
53
54/**
55 * i40iw_arp_table - manage arp table
56 * @iwdev: iwarp device
57 * @ip_addr: ip address for device
58 * @mac_addr: mac address ptr
59 * @action: modify, delete or add
60 */
61int i40iw_arp_table(struct i40iw_device *iwdev,
62 __be32 *ip_addr,
63 bool ipv4,
64 u8 *mac_addr,
65 u32 action)
66{
67 int arp_index;
68 int err;
69 u32 ip[4];
70
71 if (ipv4) {
72 memset(ip, 0, sizeof(ip));
73 ip[0] = *ip_addr;
74 } else {
75 memcpy(ip, ip_addr, sizeof(ip));
76 }
77
78 for (arp_index = 0; (u32)arp_index < iwdev->arp_table_size; arp_index++)
79 if (memcmp(iwdev->arp_table[arp_index].ip_addr, ip, sizeof(ip)) == 0)
80 break;
81 switch (action) {
82 case I40IW_ARP_ADD:
83 if (arp_index != iwdev->arp_table_size)
84 return -1;
85
86 arp_index = 0;
87 err = i40iw_alloc_resource(iwdev, iwdev->allocated_arps,
88 iwdev->arp_table_size,
89 (u32 *)&arp_index,
90 &iwdev->next_arp_index);
91
92 if (err)
93 return err;
94
95 memcpy(iwdev->arp_table[arp_index].ip_addr, ip, sizeof(ip));
96 ether_addr_copy(iwdev->arp_table[arp_index].mac_addr, mac_addr);
97 break;
98 case I40IW_ARP_RESOLVE:
99 if (arp_index == iwdev->arp_table_size)
100 return -1;
101 break;
102 case I40IW_ARP_DELETE:
103 if (arp_index == iwdev->arp_table_size)
104 return -1;
105 memset(iwdev->arp_table[arp_index].ip_addr, 0,
106 sizeof(iwdev->arp_table[arp_index].ip_addr));
107 eth_zero_addr(iwdev->arp_table[arp_index].mac_addr);
108 i40iw_free_resource(iwdev, iwdev->allocated_arps, arp_index);
109 break;
110 default:
111 return -1;
112 }
113 return arp_index;
114}
115
116/**
117 * i40iw_wr32 - write 32 bits to hw register
118 * @hw: hardware information including registers
119 * @reg: register offset
120 * @value: vvalue to write to register
121 */
122inline void i40iw_wr32(struct i40iw_hw *hw, u32 reg, u32 value)
123{
124 writel(value, hw->hw_addr + reg);
125}
126
127/**
128 * i40iw_rd32 - read a 32 bit hw register
129 * @hw: hardware information including registers
130 * @reg: register offset
131 *
132 * Return value of register content
133 */
134inline u32 i40iw_rd32(struct i40iw_hw *hw, u32 reg)
135{
136 return readl(hw->hw_addr + reg);
137}
138
139/**
140 * i40iw_inetaddr_event - system notifier for netdev events
141 * @notfier: not used
142 * @event: event for notifier
143 * @ptr: if address
144 */
145int i40iw_inetaddr_event(struct notifier_block *notifier,
146 unsigned long event,
147 void *ptr)
148{
149 struct in_ifaddr *ifa = ptr;
150 struct net_device *event_netdev = ifa->ifa_dev->dev;
151 struct net_device *netdev;
152 struct net_device *upper_dev;
153 struct i40iw_device *iwdev;
154 struct i40iw_handler *hdl;
155 __be32 local_ipaddr;
156
157 hdl = i40iw_find_netdev(event_netdev);
158 if (!hdl)
159 return NOTIFY_DONE;
160
161 iwdev = &hdl->device;
162 netdev = iwdev->ldev->netdev;
163 upper_dev = netdev_master_upper_dev_get(netdev);
164 if (netdev != event_netdev)
165 return NOTIFY_DONE;
166
167 switch (event) {
168 case NETDEV_DOWN:
169 if (upper_dev)
170 local_ipaddr =
171 ((struct in_device *)upper_dev->ip_ptr)->ifa_list->ifa_address;
172 else
173 local_ipaddr = ifa->ifa_address;
174 local_ipaddr = ntohl(local_ipaddr);
175 i40iw_manage_arp_cache(iwdev,
176 netdev->dev_addr,
177 &local_ipaddr,
178 true,
179 I40IW_ARP_DELETE);
180 return NOTIFY_OK;
181 case NETDEV_UP:
182 if (upper_dev)
183 local_ipaddr =
184 ((struct in_device *)upper_dev->ip_ptr)->ifa_list->ifa_address;
185 else
186 local_ipaddr = ifa->ifa_address;
187 local_ipaddr = ntohl(local_ipaddr);
188 i40iw_manage_arp_cache(iwdev,
189 netdev->dev_addr,
190 &local_ipaddr,
191 true,
192 I40IW_ARP_ADD);
193 break;
194 case NETDEV_CHANGEADDR:
195 /* Add the address to the IP table */
196 if (upper_dev)
197 local_ipaddr =
198 ((struct in_device *)upper_dev->ip_ptr)->ifa_list->ifa_address;
199 else
200 local_ipaddr = ifa->ifa_address;
201
202 local_ipaddr = ntohl(local_ipaddr);
203 i40iw_manage_arp_cache(iwdev,
204 netdev->dev_addr,
205 &local_ipaddr,
206 true,
207 I40IW_ARP_ADD);
208 break;
209 default:
210 break;
211 }
212 return NOTIFY_DONE;
213}
214
215/**
216 * i40iw_inet6addr_event - system notifier for ipv6 netdev events
217 * @notfier: not used
218 * @event: event for notifier
219 * @ptr: if address
220 */
221int i40iw_inet6addr_event(struct notifier_block *notifier,
222 unsigned long event,
223 void *ptr)
224{
225 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
226 struct net_device *event_netdev = ifa->idev->dev;
227 struct net_device *netdev;
228 struct i40iw_device *iwdev;
229 struct i40iw_handler *hdl;
230 __be32 local_ipaddr6[4];
231
232 hdl = i40iw_find_netdev(event_netdev);
233 if (!hdl)
234 return NOTIFY_DONE;
235
236 iwdev = &hdl->device;
237 netdev = iwdev->ldev->netdev;
238 if (netdev != event_netdev)
239 return NOTIFY_DONE;
240
241 switch (event) {
242 case NETDEV_DOWN:
243 i40iw_copy_ip_ntohl(local_ipaddr6, ifa->addr.in6_u.u6_addr32);
244 i40iw_manage_arp_cache(iwdev,
245 netdev->dev_addr,
246 local_ipaddr6,
247 false,
248 I40IW_ARP_DELETE);
249 return NOTIFY_OK;
250 case NETDEV_UP:
251 /* Fall through */
252 case NETDEV_CHANGEADDR:
253 i40iw_copy_ip_ntohl(local_ipaddr6, ifa->addr.in6_u.u6_addr32);
254 i40iw_manage_arp_cache(iwdev,
255 netdev->dev_addr,
256 local_ipaddr6,
257 false,
258 I40IW_ARP_ADD);
259 break;
260 default:
261 break;
262 }
263 return NOTIFY_DONE;
264}
265
266/**
267 * i40iw_net_event - system notifier for net events
268 * @notfier: not used
269 * @event: event for notifier
270 * @ptr: neighbor
271 */
272int i40iw_net_event(struct notifier_block *notifier, unsigned long event, void *ptr)
273{
274 struct neighbour *neigh = ptr;
275 struct i40iw_device *iwdev;
276 struct i40iw_handler *iwhdl;
277 __be32 *p;
278 u32 local_ipaddr[4];
279
280 switch (event) {
281 case NETEVENT_NEIGH_UPDATE:
282 iwhdl = i40iw_find_netdev((struct net_device *)neigh->dev);
283 if (!iwhdl)
284 return NOTIFY_DONE;
285 iwdev = &iwhdl->device;
286 p = (__be32 *)neigh->primary_key;
287 i40iw_copy_ip_ntohl(local_ipaddr, p);
288 if (neigh->nud_state & NUD_VALID) {
289 i40iw_manage_arp_cache(iwdev,
290 neigh->ha,
291 local_ipaddr,
292 false,
293 I40IW_ARP_ADD);
294
295 } else {
296 i40iw_manage_arp_cache(iwdev,
297 neigh->ha,
298 local_ipaddr,
299 false,
300 I40IW_ARP_DELETE);
301 }
302 break;
303 default:
304 break;
305 }
306 return NOTIFY_DONE;
307}
308
309/**
310 * i40iw_get_cqp_request - get cqp struct
311 * @cqp: device cqp ptr
312 * @wait: cqp to be used in wait mode
313 */
314struct i40iw_cqp_request *i40iw_get_cqp_request(struct i40iw_cqp *cqp, bool wait)
315{
316 struct i40iw_cqp_request *cqp_request = NULL;
317 unsigned long flags;
318
319 spin_lock_irqsave(&cqp->req_lock, flags);
320 if (!list_empty(&cqp->cqp_avail_reqs)) {
321 cqp_request = list_entry(cqp->cqp_avail_reqs.next,
322 struct i40iw_cqp_request, list);
323 list_del_init(&cqp_request->list);
324 }
325 spin_unlock_irqrestore(&cqp->req_lock, flags);
326 if (!cqp_request) {
327 cqp_request = kzalloc(sizeof(*cqp_request), GFP_ATOMIC);
328 if (cqp_request) {
329 cqp_request->dynamic = true;
330 INIT_LIST_HEAD(&cqp_request->list);
331 init_waitqueue_head(&cqp_request->waitq);
332 }
333 }
334 if (!cqp_request) {
335 i40iw_pr_err("CQP Request Fail: No Memory");
336 return NULL;
337 }
338
339 if (wait) {
340 atomic_set(&cqp_request->refcount, 2);
341 cqp_request->waiting = true;
342 } else {
343 atomic_set(&cqp_request->refcount, 1);
344 }
345 return cqp_request;
346}
347
348/**
349 * i40iw_free_cqp_request - free cqp request
350 * @cqp: cqp ptr
351 * @cqp_request: to be put back in cqp list
352 */
353void i40iw_free_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request)
354{
355 unsigned long flags;
356
357 if (cqp_request->dynamic) {
358 kfree(cqp_request);
359 } else {
360 cqp_request->request_done = false;
361 cqp_request->callback_fcn = NULL;
362 cqp_request->waiting = false;
363
364 spin_lock_irqsave(&cqp->req_lock, flags);
365 list_add_tail(&cqp_request->list, &cqp->cqp_avail_reqs);
366 spin_unlock_irqrestore(&cqp->req_lock, flags);
367 }
368}
369
370/**
371 * i40iw_put_cqp_request - dec ref count and free if 0
372 * @cqp: cqp ptr
373 * @cqp_request: to be put back in cqp list
374 */
375void i40iw_put_cqp_request(struct i40iw_cqp *cqp,
376 struct i40iw_cqp_request *cqp_request)
377{
378 if (atomic_dec_and_test(&cqp_request->refcount))
379 i40iw_free_cqp_request(cqp, cqp_request);
380}
381
382/**
383 * i40iw_free_qp - callback after destroy cqp completes
384 * @cqp_request: cqp request for destroy qp
385 * @num: not used
386 */
387static void i40iw_free_qp(struct i40iw_cqp_request *cqp_request, u32 num)
388{
389 struct i40iw_sc_qp *qp = (struct i40iw_sc_qp *)cqp_request->param;
390 struct i40iw_qp *iwqp = (struct i40iw_qp *)qp->back_qp;
391 struct i40iw_device *iwdev;
392 u32 qp_num = iwqp->ibqp.qp_num;
393
394 iwdev = iwqp->iwdev;
395
396 i40iw_rem_pdusecount(iwqp->iwpd, iwdev);
397 i40iw_free_qp_resources(iwdev, iwqp, qp_num);
398}
399
400/**
401 * i40iw_wait_event - wait for completion
402 * @iwdev: iwarp device
403 * @cqp_request: cqp request to wait
404 */
405static int i40iw_wait_event(struct i40iw_device *iwdev,
406 struct i40iw_cqp_request *cqp_request)
407{
408 struct cqp_commands_info *info = &cqp_request->info;
409 struct i40iw_cqp *iwcqp = &iwdev->cqp;
410 bool cqp_error = false;
411 int err_code = 0;
412 int timeout_ret = 0;
413
414 timeout_ret = wait_event_timeout(cqp_request->waitq,
415 cqp_request->request_done,
416 I40IW_EVENT_TIMEOUT);
417 if (!timeout_ret) {
418 i40iw_pr_err("error cqp command 0x%x timed out ret = %d\n",
419 info->cqp_cmd, timeout_ret);
420 err_code = -ETIME;
421 i40iw_request_reset(iwdev);
422 goto done;
423 }
424 cqp_error = cqp_request->compl_info.error;
425 if (cqp_error) {
426 i40iw_pr_err("error cqp command 0x%x completion maj = 0x%x min=0x%x\n",
427 info->cqp_cmd, cqp_request->compl_info.maj_err_code,
428 cqp_request->compl_info.min_err_code);
429 err_code = -EPROTO;
430 goto done;
431 }
432done:
433 i40iw_put_cqp_request(iwcqp, cqp_request);
434 return err_code;
435}
436
437/**
438 * i40iw_handle_cqp_op - process cqp command
439 * @iwdev: iwarp device
440 * @cqp_request: cqp request to process
441 */
442enum i40iw_status_code i40iw_handle_cqp_op(struct i40iw_device *iwdev,
443 struct i40iw_cqp_request
444 *cqp_request)
445{
446 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
447 enum i40iw_status_code status;
448 struct cqp_commands_info *info = &cqp_request->info;
449 int err_code = 0;
450
451 status = i40iw_process_cqp_cmd(dev, info);
452 if (status) {
453 i40iw_pr_err("error cqp command 0x%x failed\n", info->cqp_cmd);
454 i40iw_free_cqp_request(&iwdev->cqp, cqp_request);
455 return status;
456 }
457 if (cqp_request->waiting)
458 err_code = i40iw_wait_event(iwdev, cqp_request);
459 if (err_code)
460 status = I40IW_ERR_CQP_COMPL_ERROR;
461 return status;
462}
463
464/**
465 * i40iw_add_pdusecount - add pd refcount
466 * @iwpd: pd for refcount
467 */
468void i40iw_add_pdusecount(struct i40iw_pd *iwpd)
469{
470 atomic_inc(&iwpd->usecount);
471}
472
473/**
474 * i40iw_rem_pdusecount - decrement refcount for pd and free if 0
475 * @iwpd: pd for refcount
476 * @iwdev: iwarp device
477 */
478void i40iw_rem_pdusecount(struct i40iw_pd *iwpd, struct i40iw_device *iwdev)
479{
480 if (!atomic_dec_and_test(&iwpd->usecount))
481 return;
482 i40iw_free_resource(iwdev, iwdev->allocated_pds, iwpd->sc_pd.pd_id);
483 kfree(iwpd);
484}
485
486/**
487 * i40iw_add_ref - add refcount for qp
488 * @ibqp: iqarp qp
489 */
490void i40iw_add_ref(struct ib_qp *ibqp)
491{
492 struct i40iw_qp *iwqp = (struct i40iw_qp *)ibqp;
493
494 atomic_inc(&iwqp->refcount);
495}
496
497/**
498 * i40iw_rem_ref - rem refcount for qp and free if 0
499 * @ibqp: iqarp qp
500 */
501void i40iw_rem_ref(struct ib_qp *ibqp)
502{
503 struct i40iw_qp *iwqp;
504 enum i40iw_status_code status;
505 struct i40iw_cqp_request *cqp_request;
506 struct cqp_commands_info *cqp_info;
507 struct i40iw_device *iwdev;
508 u32 qp_num;
509
510 iwqp = to_iwqp(ibqp);
511 if (!atomic_dec_and_test(&iwqp->refcount))
512 return;
513
514 iwdev = iwqp->iwdev;
515 qp_num = iwqp->ibqp.qp_num;
516 iwdev->qp_table[qp_num] = NULL;
517 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
518 if (!cqp_request)
519 return;
520
521 cqp_request->callback_fcn = i40iw_free_qp;
522 cqp_request->param = (void *)&iwqp->sc_qp;
523 cqp_info = &cqp_request->info;
524 cqp_info->cqp_cmd = OP_QP_DESTROY;
525 cqp_info->post_sq = 1;
526 cqp_info->in.u.qp_destroy.qp = &iwqp->sc_qp;
527 cqp_info->in.u.qp_destroy.scratch = (uintptr_t)cqp_request;
528 cqp_info->in.u.qp_destroy.remove_hash_idx = true;
529 status = i40iw_handle_cqp_op(iwdev, cqp_request);
530 if (status)
531 i40iw_pr_err("CQP-OP Destroy QP fail");
532}
533
534/**
535 * i40iw_get_qp - get qp address
536 * @device: iwarp device
537 * @qpn: qp number
538 */
539struct ib_qp *i40iw_get_qp(struct ib_device *device, int qpn)
540{
541 struct i40iw_device *iwdev = to_iwdev(device);
542
543 if ((qpn < IW_FIRST_QPN) || (qpn >= iwdev->max_qp))
544 return NULL;
545
546 return &iwdev->qp_table[qpn]->ibqp;
547}
548
549/**
550 * i40iw_debug_buf - print debug msg and buffer is mask set
551 * @dev: hardware control device structure
552 * @mask: mask to compare if to print debug buffer
553 * @buf: points buffer addr
554 * @size: saize of buffer to print
555 */
556void i40iw_debug_buf(struct i40iw_sc_dev *dev,
557 enum i40iw_debug_flag mask,
558 char *desc,
559 u64 *buf,
560 u32 size)
561{
562 u32 i;
563
564 if (!(dev->debug_mask & mask))
565 return;
566 i40iw_debug(dev, mask, "%s\n", desc);
567 i40iw_debug(dev, mask, "starting address virt=%p phy=%llxh\n", buf,
568 (unsigned long long)virt_to_phys(buf));
569
570 for (i = 0; i < size; i += 8)
571 i40iw_debug(dev, mask, "index %03d val: %016llx\n", i, buf[i / 8]);
572}
573
574/**
575 * i40iw_get_hw_addr - return hw addr
576 * @par: points to shared dev
577 */
578u8 __iomem *i40iw_get_hw_addr(void *par)
579{
580 struct i40iw_sc_dev *dev = (struct i40iw_sc_dev *)par;
581
582 return dev->hw->hw_addr;
583}
584
585/**
586 * i40iw_remove_head - return head entry and remove from list
587 * @list: list for entry
588 */
589void *i40iw_remove_head(struct list_head *list)
590{
591 struct list_head *entry;
592
593 if (list_empty(list))
594 return NULL;
595
596 entry = (void *)list->next;
597 list_del(entry);
598 return (void *)entry;
599}
600
601/**
602 * i40iw_allocate_dma_mem - Memory alloc helper fn
603 * @hw: pointer to the HW structure
604 * @mem: ptr to mem struct to fill out
605 * @size: size of memory requested
606 * @alignment: what to align the allocation to
607 */
608enum i40iw_status_code i40iw_allocate_dma_mem(struct i40iw_hw *hw,
609 struct i40iw_dma_mem *mem,
610 u64 size,
611 u32 alignment)
612{
613 struct pci_dev *pcidev = (struct pci_dev *)hw->dev_context;
614
615 if (!mem)
616 return I40IW_ERR_PARAM;
617 mem->size = ALIGN(size, alignment);
618 mem->va = dma_zalloc_coherent(&pcidev->dev, mem->size,
619 (dma_addr_t *)&mem->pa, GFP_KERNEL);
620 if (!mem->va)
621 return I40IW_ERR_NO_MEMORY;
622 return 0;
623}
624
625/**
626 * i40iw_free_dma_mem - Memory free helper fn
627 * @hw: pointer to the HW structure
628 * @mem: ptr to mem struct to free
629 */
630void i40iw_free_dma_mem(struct i40iw_hw *hw, struct i40iw_dma_mem *mem)
631{
632 struct pci_dev *pcidev = (struct pci_dev *)hw->dev_context;
633
634 if (!mem || !mem->va)
635 return;
636
637 dma_free_coherent(&pcidev->dev, mem->size,
638 mem->va, (dma_addr_t)mem->pa);
639 mem->va = NULL;
640}
641
642/**
643 * i40iw_allocate_virt_mem - virtual memory alloc helper fn
644 * @hw: pointer to the HW structure
645 * @mem: ptr to mem struct to fill out
646 * @size: size of memory requested
647 */
648enum i40iw_status_code i40iw_allocate_virt_mem(struct i40iw_hw *hw,
649 struct i40iw_virt_mem *mem,
650 u32 size)
651{
652 if (!mem)
653 return I40IW_ERR_PARAM;
654
655 mem->size = size;
656 mem->va = kzalloc(size, GFP_KERNEL);
657
658 if (mem->va)
659 return 0;
660 else
661 return I40IW_ERR_NO_MEMORY;
662}
663
664/**
665 * i40iw_free_virt_mem - virtual memory free helper fn
666 * @hw: pointer to the HW structure
667 * @mem: ptr to mem struct to free
668 */
669enum i40iw_status_code i40iw_free_virt_mem(struct i40iw_hw *hw,
670 struct i40iw_virt_mem *mem)
671{
672 if (!mem)
673 return I40IW_ERR_PARAM;
674 kfree(mem->va);
675 mem->va = NULL;
676 return 0;
677}
678
679/**
680 * i40iw_cqp_sds_cmd - create cqp command for sd
681 * @dev: hardware control device structure
682 * @sd_info: information for sd cqp
683 *
684 */
685enum i40iw_status_code i40iw_cqp_sds_cmd(struct i40iw_sc_dev *dev,
686 struct i40iw_update_sds_info *sdinfo)
687{
688 enum i40iw_status_code status;
689 struct i40iw_cqp_request *cqp_request;
690 struct cqp_commands_info *cqp_info;
691 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
692
693 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
694 if (!cqp_request)
695 return I40IW_ERR_NO_MEMORY;
696 cqp_info = &cqp_request->info;
697 memcpy(&cqp_info->in.u.update_pe_sds.info, sdinfo,
698 sizeof(cqp_info->in.u.update_pe_sds.info));
699 cqp_info->cqp_cmd = OP_UPDATE_PE_SDS;
700 cqp_info->post_sq = 1;
701 cqp_info->in.u.update_pe_sds.dev = dev;
702 cqp_info->in.u.update_pe_sds.scratch = (uintptr_t)cqp_request;
703 status = i40iw_handle_cqp_op(iwdev, cqp_request);
704 if (status)
705 i40iw_pr_err("CQP-OP Update SD's fail");
706 return status;
707}
708
709/**
710 * i40iw_term_modify_qp - modify qp for term message
711 * @qp: hardware control qp
712 * @next_state: qp's next state
713 * @term: terminate code
714 * @term_len: length
715 */
716void i40iw_term_modify_qp(struct i40iw_sc_qp *qp, u8 next_state, u8 term, u8 term_len)
717{
718 struct i40iw_qp *iwqp;
719
720 iwqp = (struct i40iw_qp *)qp->back_qp;
721 i40iw_next_iw_state(iwqp, next_state, 0, term, term_len);
722};
723
724/**
725 * i40iw_terminate_done - after terminate is completed
726 * @qp: hardware control qp
727 * @timeout_occurred: indicates if terminate timer expired
728 */
729void i40iw_terminate_done(struct i40iw_sc_qp *qp, int timeout_occurred)
730{
731 struct i40iw_qp *iwqp;
732 u32 next_iwarp_state = I40IW_QP_STATE_ERROR;
733 u8 hte = 0;
734 bool first_time;
735 unsigned long flags;
736
737 iwqp = (struct i40iw_qp *)qp->back_qp;
738 spin_lock_irqsave(&iwqp->lock, flags);
739 if (iwqp->hte_added) {
740 iwqp->hte_added = 0;
741 hte = 1;
742 }
743 first_time = !(qp->term_flags & I40IW_TERM_DONE);
744 qp->term_flags |= I40IW_TERM_DONE;
745 spin_unlock_irqrestore(&iwqp->lock, flags);
746 if (first_time) {
747 if (!timeout_occurred)
748 i40iw_terminate_del_timer(qp);
749 else
750 next_iwarp_state = I40IW_QP_STATE_CLOSING;
751
752 i40iw_next_iw_state(iwqp, next_iwarp_state, hte, 0, 0);
753 i40iw_cm_disconn(iwqp);
754 }
755}
756
757/**
758 * i40iw_terminate_imeout - timeout happened
759 * @context: points to iwarp qp
760 */
761static void i40iw_terminate_timeout(unsigned long context)
762{
763 struct i40iw_qp *iwqp = (struct i40iw_qp *)context;
764 struct i40iw_sc_qp *qp = (struct i40iw_sc_qp *)&iwqp->sc_qp;
765
766 i40iw_terminate_done(qp, 1);
767}
768
769/**
770 * i40iw_terminate_start_timer - start terminate timeout
771 * @qp: hardware control qp
772 */
773void i40iw_terminate_start_timer(struct i40iw_sc_qp *qp)
774{
775 struct i40iw_qp *iwqp;
776
777 iwqp = (struct i40iw_qp *)qp->back_qp;
778 init_timer(&iwqp->terminate_timer);
779 iwqp->terminate_timer.function = i40iw_terminate_timeout;
780 iwqp->terminate_timer.expires = jiffies + HZ;
781 iwqp->terminate_timer.data = (unsigned long)iwqp;
782 add_timer(&iwqp->terminate_timer);
783}
784
785/**
786 * i40iw_terminate_del_timer - delete terminate timeout
787 * @qp: hardware control qp
788 */
789void i40iw_terminate_del_timer(struct i40iw_sc_qp *qp)
790{
791 struct i40iw_qp *iwqp;
792
793 iwqp = (struct i40iw_qp *)qp->back_qp;
794 del_timer(&iwqp->terminate_timer);
795}
796
797/**
798 * i40iw_cqp_generic_worker - generic worker for cqp
799 * @work: work pointer
800 */
801static void i40iw_cqp_generic_worker(struct work_struct *work)
802{
803 struct i40iw_virtchnl_work_info *work_info =
804 &((struct virtchnl_work *)work)->work_info;
805
806 if (work_info->worker_vf_dev)
807 work_info->callback_fcn(work_info->worker_vf_dev);
808}
809
810/**
811 * i40iw_cqp_spawn_worker - spawn worket thread
812 * @iwdev: device struct pointer
813 * @work_info: work request info
814 * @iw_vf_idx: virtual function index
815 */
816void i40iw_cqp_spawn_worker(struct i40iw_sc_dev *dev,
817 struct i40iw_virtchnl_work_info *work_info,
818 u32 iw_vf_idx)
819{
820 struct virtchnl_work *work;
821 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
822
823 work = &iwdev->virtchnl_w[iw_vf_idx];
824 memcpy(&work->work_info, work_info, sizeof(*work_info));
825 INIT_WORK(&work->work, i40iw_cqp_generic_worker);
826 queue_work(iwdev->virtchnl_wq, &work->work);
827}
828
829/**
830 * i40iw_cqp_manage_hmc_fcn_worker -
831 * @work: work pointer for hmc info
832 */
833static void i40iw_cqp_manage_hmc_fcn_worker(struct work_struct *work)
834{
835 struct i40iw_cqp_request *cqp_request =
836 ((struct virtchnl_work *)work)->cqp_request;
837 struct i40iw_ccq_cqe_info ccq_cqe_info;
838 struct i40iw_hmc_fcn_info *hmcfcninfo =
839 &cqp_request->info.in.u.manage_hmc_pm.info;
840 struct i40iw_device *iwdev =
841 (struct i40iw_device *)cqp_request->info.in.u.manage_hmc_pm.dev->back_dev;
842
843 ccq_cqe_info.cqp = NULL;
844 ccq_cqe_info.maj_err_code = cqp_request->compl_info.maj_err_code;
845 ccq_cqe_info.min_err_code = cqp_request->compl_info.min_err_code;
846 ccq_cqe_info.op_code = cqp_request->compl_info.op_code;
847 ccq_cqe_info.op_ret_val = cqp_request->compl_info.op_ret_val;
848 ccq_cqe_info.scratch = 0;
849 ccq_cqe_info.error = cqp_request->compl_info.error;
850 hmcfcninfo->callback_fcn(cqp_request->info.in.u.manage_hmc_pm.dev,
851 hmcfcninfo->cqp_callback_param, &ccq_cqe_info);
852 i40iw_put_cqp_request(&iwdev->cqp, cqp_request);
853}
854
855/**
856 * i40iw_cqp_manage_hmc_fcn_callback - called function after cqp completion
857 * @cqp_request: cqp request info struct for hmc fun
858 * @unused: unused param of callback
859 */
860static void i40iw_cqp_manage_hmc_fcn_callback(struct i40iw_cqp_request *cqp_request,
861 u32 unused)
862{
863 struct virtchnl_work *work;
864 struct i40iw_hmc_fcn_info *hmcfcninfo =
865 &cqp_request->info.in.u.manage_hmc_pm.info;
866 struct i40iw_device *iwdev =
867 (struct i40iw_device *)cqp_request->info.in.u.manage_hmc_pm.dev->
868 back_dev;
869
870 if (hmcfcninfo && hmcfcninfo->callback_fcn) {
871 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s1\n", __func__);
872 atomic_inc(&cqp_request->refcount);
873 work = &iwdev->virtchnl_w[hmcfcninfo->iw_vf_idx];
874 work->cqp_request = cqp_request;
875 INIT_WORK(&work->work, i40iw_cqp_manage_hmc_fcn_worker);
876 queue_work(iwdev->virtchnl_wq, &work->work);
877 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s2\n", __func__);
878 } else {
879 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s: Something wrong\n", __func__);
880 }
881}
882
883/**
884 * i40iw_cqp_manage_hmc_fcn_cmd - issue cqp command to manage hmc
885 * @dev: hardware control device structure
886 * @hmcfcninfo: info for hmc
887 */
888enum i40iw_status_code i40iw_cqp_manage_hmc_fcn_cmd(struct i40iw_sc_dev *dev,
889 struct i40iw_hmc_fcn_info *hmcfcninfo)
890{
891 enum i40iw_status_code status;
892 struct i40iw_cqp_request *cqp_request;
893 struct cqp_commands_info *cqp_info;
894 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
895
896 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_HMC, "%s\n", __func__);
897 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
898 if (!cqp_request)
899 return I40IW_ERR_NO_MEMORY;
900 cqp_info = &cqp_request->info;
901 cqp_request->callback_fcn = i40iw_cqp_manage_hmc_fcn_callback;
902 cqp_request->param = hmcfcninfo;
903 memcpy(&cqp_info->in.u.manage_hmc_pm.info, hmcfcninfo,
904 sizeof(*hmcfcninfo));
905 cqp_info->in.u.manage_hmc_pm.dev = dev;
906 cqp_info->cqp_cmd = OP_MANAGE_HMC_PM_FUNC_TABLE;
907 cqp_info->post_sq = 1;
908 cqp_info->in.u.manage_hmc_pm.scratch = (uintptr_t)cqp_request;
909 status = i40iw_handle_cqp_op(iwdev, cqp_request);
910 if (status)
911 i40iw_pr_err("CQP-OP Manage HMC fail");
912 return status;
913}
914
915/**
916 * i40iw_cqp_query_fpm_values_cmd - send cqp command for fpm
917 * @iwdev: function device struct
918 * @values_mem: buffer for fpm
919 * @hmc_fn_id: function id for fpm
920 */
921enum i40iw_status_code i40iw_cqp_query_fpm_values_cmd(struct i40iw_sc_dev *dev,
922 struct i40iw_dma_mem *values_mem,
923 u8 hmc_fn_id)
924{
925 enum i40iw_status_code status;
926 struct i40iw_cqp_request *cqp_request;
927 struct cqp_commands_info *cqp_info;
928 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
929
930 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
931 if (!cqp_request)
932 return I40IW_ERR_NO_MEMORY;
933 cqp_info = &cqp_request->info;
934 cqp_request->param = NULL;
935 cqp_info->in.u.query_fpm_values.cqp = dev->cqp;
936 cqp_info->in.u.query_fpm_values.fpm_values_pa = values_mem->pa;
937 cqp_info->in.u.query_fpm_values.fpm_values_va = values_mem->va;
938 cqp_info->in.u.query_fpm_values.hmc_fn_id = hmc_fn_id;
939 cqp_info->cqp_cmd = OP_QUERY_FPM_VALUES;
940 cqp_info->post_sq = 1;
941 cqp_info->in.u.query_fpm_values.scratch = (uintptr_t)cqp_request;
942 status = i40iw_handle_cqp_op(iwdev, cqp_request);
943 if (status)
944 i40iw_pr_err("CQP-OP Query FPM fail");
945 return status;
946}
947
948/**
949 * i40iw_cqp_commit_fpm_values_cmd - commit fpm values in hw
950 * @dev: hardware control device structure
951 * @values_mem: buffer with fpm values
952 * @hmc_fn_id: function id for fpm
953 */
954enum i40iw_status_code i40iw_cqp_commit_fpm_values_cmd(struct i40iw_sc_dev *dev,
955 struct i40iw_dma_mem *values_mem,
956 u8 hmc_fn_id)
957{
958 enum i40iw_status_code status;
959 struct i40iw_cqp_request *cqp_request;
960 struct cqp_commands_info *cqp_info;
961 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
962
963 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
964 if (!cqp_request)
965 return I40IW_ERR_NO_MEMORY;
966 cqp_info = &cqp_request->info;
967 cqp_request->param = NULL;
968 cqp_info->in.u.commit_fpm_values.cqp = dev->cqp;
969 cqp_info->in.u.commit_fpm_values.fpm_values_pa = values_mem->pa;
970 cqp_info->in.u.commit_fpm_values.fpm_values_va = values_mem->va;
971 cqp_info->in.u.commit_fpm_values.hmc_fn_id = hmc_fn_id;
972 cqp_info->cqp_cmd = OP_COMMIT_FPM_VALUES;
973 cqp_info->post_sq = 1;
974 cqp_info->in.u.commit_fpm_values.scratch = (uintptr_t)cqp_request;
975 status = i40iw_handle_cqp_op(iwdev, cqp_request);
976 if (status)
977 i40iw_pr_err("CQP-OP Commit FPM fail");
978 return status;
979}
980
981/**
982 * i40iw_vf_wait_vchnl_resp - wait for channel msg
983 * @iwdev: function's device struct
984 */
985enum i40iw_status_code i40iw_vf_wait_vchnl_resp(struct i40iw_sc_dev *dev)
986{
987 struct i40iw_device *iwdev = dev->back_dev;
988 enum i40iw_status_code err_code = 0;
989 int timeout_ret;
990
991 i40iw_debug(dev, I40IW_DEBUG_VIRT, "%s[%u] dev %p, iwdev %p\n",
992 __func__, __LINE__, dev, iwdev);
993 atomic_add(2, &iwdev->vchnl_msgs);
994 timeout_ret = wait_event_timeout(iwdev->vchnl_waitq,
995 (atomic_read(&iwdev->vchnl_msgs) == 1),
996 I40IW_VCHNL_EVENT_TIMEOUT);
997 atomic_dec(&iwdev->vchnl_msgs);
998 if (!timeout_ret) {
999 i40iw_pr_err("virt channel completion timeout = 0x%x\n", timeout_ret);
1000 err_code = I40IW_ERR_TIMEOUT;
1001 }
1002 return err_code;
1003}
1004
1005/**
1006 * i40iw_ieq_mpa_crc_ae - generate AE for crc error
1007 * @dev: hardware control device structure
1008 * @qp: hardware control qp
1009 */
1010void i40iw_ieq_mpa_crc_ae(struct i40iw_sc_dev *dev, struct i40iw_sc_qp *qp)
1011{
1012 struct i40iw_qp_flush_info info;
1013 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
1014
1015 i40iw_debug(dev, I40IW_DEBUG_AEQ, "%s entered\n", __func__);
1016 memset(&info, 0, sizeof(info));
1017 info.ae_code = I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR;
1018 info.generate_ae = true;
1019 info.ae_source = 0x3;
1020 (void)i40iw_hw_flush_wqes(iwdev, qp, &info, false);
1021}
1022
1023/**
1024 * i40iw_init_hash_desc - initialize hash for crc calculation
1025 * @desc: cryption type
1026 */
1027enum i40iw_status_code i40iw_init_hash_desc(struct shash_desc **desc)
1028{
1029 struct crypto_shash *tfm;
1030 struct shash_desc *tdesc;
1031
1032 tfm = crypto_alloc_shash("crc32c", 0, 0);
1033 if (IS_ERR(tfm))
1034 return I40IW_ERR_MPA_CRC;
1035
1036 tdesc = kzalloc(sizeof(*tdesc) + crypto_shash_descsize(tfm),
1037 GFP_KERNEL);
1038 if (!tdesc) {
1039 crypto_free_shash(tfm);
1040 return I40IW_ERR_MPA_CRC;
1041 }
1042 tdesc->tfm = tfm;
1043 *desc = tdesc;
1044
1045 return 0;
1046}
1047
1048/**
1049 * i40iw_free_hash_desc - free hash desc
1050 * @desc: to be freed
1051 */
1052void i40iw_free_hash_desc(struct shash_desc *desc)
1053{
1054 if (desc) {
1055 crypto_free_shash(desc->tfm);
1056 kfree(desc);
1057 }
1058}
1059
1060/**
1061 * i40iw_alloc_query_fpm_buf - allocate buffer for fpm
1062 * @dev: hardware control device structure
1063 * @mem: buffer ptr for fpm to be allocated
1064 * @return: memory allocation status
1065 */
1066enum i40iw_status_code i40iw_alloc_query_fpm_buf(struct i40iw_sc_dev *dev,
1067 struct i40iw_dma_mem *mem)
1068{
1069 enum i40iw_status_code status;
1070 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
1071
1072 status = i40iw_obj_aligned_mem(iwdev, mem, I40IW_QUERY_FPM_BUF_SIZE,
1073 I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK);
1074 return status;
1075}
1076
1077/**
1078 * i40iw_ieq_check_mpacrc - check if mpa crc is OK
1079 * @desc: desc for hash
1080 * @addr: address of buffer for crc
1081 * @length: length of buffer
1082 * @value: value to be compared
1083 */
1084enum i40iw_status_code i40iw_ieq_check_mpacrc(struct shash_desc *desc,
1085 void *addr,
1086 u32 length,
1087 u32 value)
1088{
1089 u32 crc = 0;
1090 int ret;
1091 enum i40iw_status_code ret_code = 0;
1092
1093 crypto_shash_init(desc);
1094 ret = crypto_shash_update(desc, addr, length);
1095 if (!ret)
1096 crypto_shash_final(desc, (u8 *)&crc);
1097 if (crc != value) {
1098 i40iw_pr_err("mpa crc check fail\n");
1099 ret_code = I40IW_ERR_MPA_CRC;
1100 }
1101 return ret_code;
1102}
1103
1104/**
1105 * i40iw_ieq_get_qp - get qp based on quad in puda buffer
1106 * @dev: hardware control device structure
1107 * @buf: receive puda buffer on exception q
1108 */
1109struct i40iw_sc_qp *i40iw_ieq_get_qp(struct i40iw_sc_dev *dev,
1110 struct i40iw_puda_buf *buf)
1111{
1112 struct i40iw_device *iwdev = (struct i40iw_device *)dev->back_dev;
1113 struct i40iw_qp *iwqp;
1114 struct i40iw_cm_node *cm_node;
1115 u32 loc_addr[4], rem_addr[4];
1116 u16 loc_port, rem_port;
1117 struct ipv6hdr *ip6h;
1118 struct iphdr *iph = (struct iphdr *)buf->iph;
1119 struct tcphdr *tcph = (struct tcphdr *)buf->tcph;
1120
1121 if (iph->version == 4) {
1122 memset(loc_addr, 0, sizeof(loc_addr));
1123 loc_addr[0] = ntohl(iph->daddr);
1124 memset(rem_addr, 0, sizeof(rem_addr));
1125 rem_addr[0] = ntohl(iph->saddr);
1126 } else {
1127 ip6h = (struct ipv6hdr *)buf->iph;
1128 i40iw_copy_ip_ntohl(loc_addr, ip6h->daddr.in6_u.u6_addr32);
1129 i40iw_copy_ip_ntohl(rem_addr, ip6h->saddr.in6_u.u6_addr32);
1130 }
1131 loc_port = ntohs(tcph->dest);
1132 rem_port = ntohs(tcph->source);
1133
1134 cm_node = i40iw_find_node(&iwdev->cm_core, rem_port, rem_addr, loc_port,
1135 loc_addr, false);
1136 if (!cm_node)
1137 return NULL;
1138 iwqp = cm_node->iwqp;
1139 return &iwqp->sc_qp;
1140}
1141
1142/**
1143 * i40iw_ieq_update_tcpip_info - update tcpip in the buffer
1144 * @buf: puda to update
1145 * @length: length of buffer
1146 * @seqnum: seq number for tcp
1147 */
1148void i40iw_ieq_update_tcpip_info(struct i40iw_puda_buf *buf, u16 length, u32 seqnum)
1149{
1150 struct tcphdr *tcph;
1151 struct iphdr *iph;
1152 u16 iphlen;
1153 u16 packetsize;
1154 u8 *addr = (u8 *)buf->mem.va;
1155
1156 iphlen = (buf->ipv4) ? 20 : 40;
1157 iph = (struct iphdr *)(addr + buf->maclen);
1158 tcph = (struct tcphdr *)(addr + buf->maclen + iphlen);
1159 packetsize = length + buf->tcphlen + iphlen;
1160
1161 iph->tot_len = htons(packetsize);
1162 tcph->seq = htonl(seqnum);
1163}
1164
1165/**
1166 * i40iw_puda_get_tcpip_info - get tcpip info from puda buffer
1167 * @info: to get information
1168 * @buf: puda buffer
1169 */
1170enum i40iw_status_code i40iw_puda_get_tcpip_info(struct i40iw_puda_completion_info *info,
1171 struct i40iw_puda_buf *buf)
1172{
1173 struct iphdr *iph;
1174 struct ipv6hdr *ip6h;
1175 struct tcphdr *tcph;
1176 u16 iphlen;
1177 u16 pkt_len;
1178 u8 *mem = (u8 *)buf->mem.va;
1179 struct ethhdr *ethh = (struct ethhdr *)buf->mem.va;
1180
1181 if (ethh->h_proto == htons(0x8100)) {
1182 info->vlan_valid = true;
1183 buf->vlan_id = ntohs(((struct vlan_ethhdr *)ethh)->h_vlan_TCI) & VLAN_VID_MASK;
1184 }
1185 buf->maclen = (info->vlan_valid) ? 18 : 14;
1186 iphlen = (info->l3proto) ? 40 : 20;
1187 buf->ipv4 = (info->l3proto) ? false : true;
1188 buf->iph = mem + buf->maclen;
1189 iph = (struct iphdr *)buf->iph;
1190
1191 buf->tcph = buf->iph + iphlen;
1192 tcph = (struct tcphdr *)buf->tcph;
1193
1194 if (buf->ipv4) {
1195 pkt_len = ntohs(iph->tot_len);
1196 } else {
1197 ip6h = (struct ipv6hdr *)buf->iph;
1198 pkt_len = ntohs(ip6h->payload_len) + iphlen;
1199 }
1200
1201 buf->totallen = pkt_len + buf->maclen;
1202
1203 if (info->payload_len < buf->totallen - 4) {
1204 i40iw_pr_err("payload_len = 0x%x totallen expected0x%x\n",
1205 info->payload_len, buf->totallen);
1206 return I40IW_ERR_INVALID_SIZE;
1207 }
1208
1209 buf->tcphlen = (tcph->doff) << 2;
1210 buf->datalen = pkt_len - iphlen - buf->tcphlen;
1211 buf->data = (buf->datalen) ? buf->tcph + buf->tcphlen : NULL;
1212 buf->hdrlen = buf->maclen + iphlen + buf->tcphlen;
1213 buf->seqnum = ntohl(tcph->seq);
1214 return 0;
1215}
1216
1217/**
1218 * i40iw_hw_stats_timeout - Stats timer-handler which updates all HW stats
1219 * @dev: hardware control device structure
1220 */
1221static void i40iw_hw_stats_timeout(unsigned long dev)
1222{
1223 struct i40iw_sc_dev *pf_dev = (struct i40iw_sc_dev *)dev;
1224 struct i40iw_dev_pestat *pf_devstat = &pf_dev->dev_pestat;
1225 struct i40iw_dev_pestat *vf_devstat = NULL;
1226 u16 iw_vf_idx;
1227 unsigned long flags;
1228
1229 /*PF*/
1230 pf_devstat->ops.iw_hw_stat_read_all(pf_devstat, &pf_devstat->hw_stats);
1231 for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT; iw_vf_idx++) {
1232 spin_lock_irqsave(&pf_devstat->stats_lock, flags);
1233 if (pf_dev->vf_dev[iw_vf_idx]) {
1234 if (pf_dev->vf_dev[iw_vf_idx]->stats_initialized) {
1235 vf_devstat = &pf_dev->vf_dev[iw_vf_idx]->dev_pestat;
1236 vf_devstat->ops.iw_hw_stat_read_all(vf_devstat, &vf_devstat->hw_stats);
1237 }
1238 }
1239 spin_unlock_irqrestore(&pf_devstat->stats_lock, flags);
1240 }
1241
1242 mod_timer(&pf_devstat->stats_timer,
1243 jiffies + msecs_to_jiffies(STATS_TIMER_DELAY));
1244}
1245
1246/**
1247 * i40iw_hw_stats_start_timer - Start periodic stats timer
1248 * @dev: hardware control device structure
1249 */
1250void i40iw_hw_stats_start_timer(struct i40iw_sc_dev *dev)
1251{
1252 struct i40iw_dev_pestat *devstat = &dev->dev_pestat;
1253
1254 init_timer(&devstat->stats_timer);
1255 devstat->stats_timer.function = i40iw_hw_stats_timeout;
1256 devstat->stats_timer.data = (unsigned long)dev;
1257 mod_timer(&devstat->stats_timer,
1258 jiffies + msecs_to_jiffies(STATS_TIMER_DELAY));
1259}
1260
1261/**
1262 * i40iw_hw_stats_del_timer - Delete periodic stats timer
1263 * @dev: hardware control device structure
1264 */
1265void i40iw_hw_stats_del_timer(struct i40iw_sc_dev *dev)
1266{
1267 struct i40iw_dev_pestat *devstat = &dev->dev_pestat;
1268
1269 del_timer_sync(&devstat->stats_timer);
1270}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
new file mode 100644
index 000000000000..1fe3b84a06e4
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
@@ -0,0 +1,2437 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/random.h>
38#include <linux/highmem.h>
39#include <linux/time.h>
40#include <asm/byteorder.h>
41#include <net/ip.h>
42#include <rdma/ib_verbs.h>
43#include <rdma/iw_cm.h>
44#include <rdma/ib_user_verbs.h>
45#include <rdma/ib_umem.h>
46#include "i40iw.h"
47
48/**
49 * i40iw_query_device - get device attributes
50 * @ibdev: device pointer from stack
51 * @props: returning device attributes
52 * @udata: user data
53 */
54static int i40iw_query_device(struct ib_device *ibdev,
55 struct ib_device_attr *props,
56 struct ib_udata *udata)
57{
58 struct i40iw_device *iwdev = to_iwdev(ibdev);
59
60 if (udata->inlen || udata->outlen)
61 return -EINVAL;
62 memset(props, 0, sizeof(*props));
63 ether_addr_copy((u8 *)&props->sys_image_guid, iwdev->netdev->dev_addr);
64 props->fw_ver = I40IW_FW_VERSION;
65 props->device_cap_flags = iwdev->device_cap_flags;
66 props->vendor_id = iwdev->vendor_id;
67 props->vendor_part_id = iwdev->vendor_part_id;
68 props->hw_ver = (u32)iwdev->sc_dev.hw_rev;
69 props->max_mr_size = I40IW_MAX_OUTBOUND_MESSAGE_SIZE;
70 props->max_qp = iwdev->max_qp;
71 props->max_qp_wr = (I40IW_MAX_WQ_ENTRIES >> 2) - 1;
72 props->max_sge = I40IW_MAX_WQ_FRAGMENT_COUNT;
73 props->max_cq = iwdev->max_cq;
74 props->max_cqe = iwdev->max_cqe;
75 props->max_mr = iwdev->max_mr;
76 props->max_pd = iwdev->max_pd;
77 props->max_sge_rd = 1;
78 props->max_qp_rd_atom = I40IW_MAX_IRD_SIZE;
79 props->max_qp_init_rd_atom = props->max_qp_rd_atom;
80 props->atomic_cap = IB_ATOMIC_NONE;
81 props->max_map_per_fmr = 1;
82 return 0;
83}
84
85/**
86 * i40iw_query_port - get port attrubutes
87 * @ibdev: device pointer from stack
88 * @port: port number for query
89 * @props: returning device attributes
90 */
91static int i40iw_query_port(struct ib_device *ibdev,
92 u8 port,
93 struct ib_port_attr *props)
94{
95 struct i40iw_device *iwdev = to_iwdev(ibdev);
96 struct net_device *netdev = iwdev->netdev;
97
98 memset(props, 0, sizeof(*props));
99
100 props->max_mtu = IB_MTU_4096;
101 if (netdev->mtu >= 4096)
102 props->active_mtu = IB_MTU_4096;
103 else if (netdev->mtu >= 2048)
104 props->active_mtu = IB_MTU_2048;
105 else if (netdev->mtu >= 1024)
106 props->active_mtu = IB_MTU_1024;
107 else if (netdev->mtu >= 512)
108 props->active_mtu = IB_MTU_512;
109 else
110 props->active_mtu = IB_MTU_256;
111
112 props->lid = 1;
113 if (netif_carrier_ok(iwdev->netdev))
114 props->state = IB_PORT_ACTIVE;
115 else
116 props->state = IB_PORT_DOWN;
117 props->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_REINIT_SUP |
118 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
119 props->gid_tbl_len = 1;
120 props->pkey_tbl_len = 1;
121 props->active_width = IB_WIDTH_4X;
122 props->active_speed = 1;
123 props->max_msg_sz = 0x80000000;
124 return 0;
125}
126
127/**
128 * i40iw_alloc_ucontext - Allocate the user context data structure
129 * @ibdev: device pointer from stack
130 * @udata: user data
131 *
132 * This keeps track of all objects associated with a particular
133 * user-mode client.
134 */
135static struct ib_ucontext *i40iw_alloc_ucontext(struct ib_device *ibdev,
136 struct ib_udata *udata)
137{
138 struct i40iw_device *iwdev = to_iwdev(ibdev);
139 struct i40iw_alloc_ucontext_req req;
140 struct i40iw_alloc_ucontext_resp uresp;
141 struct i40iw_ucontext *ucontext;
142
143 if (ib_copy_from_udata(&req, udata, sizeof(req)))
144 return ERR_PTR(-EINVAL);
145
146 if (req.userspace_ver != I40IW_ABI_USERSPACE_VER) {
147 i40iw_pr_err("Invalid userspace driver version detected. Detected version %d, should be %d\n",
148 req.userspace_ver, I40IW_ABI_USERSPACE_VER);
149 return ERR_PTR(-EINVAL);
150 }
151
152 memset(&uresp, 0, sizeof(uresp));
153 uresp.max_qps = iwdev->max_qp;
154 uresp.max_pds = iwdev->max_pd;
155 uresp.wq_size = iwdev->max_qp_wr * 2;
156 uresp.kernel_ver = I40IW_ABI_KERNEL_VER;
157
158 ucontext = kzalloc(sizeof(*ucontext), GFP_KERNEL);
159 if (!ucontext)
160 return ERR_PTR(-ENOMEM);
161
162 ucontext->iwdev = iwdev;
163
164 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
165 kfree(ucontext);
166 return ERR_PTR(-EFAULT);
167 }
168
169 INIT_LIST_HEAD(&ucontext->cq_reg_mem_list);
170 spin_lock_init(&ucontext->cq_reg_mem_list_lock);
171 INIT_LIST_HEAD(&ucontext->qp_reg_mem_list);
172 spin_lock_init(&ucontext->qp_reg_mem_list_lock);
173
174 return &ucontext->ibucontext;
175}
176
177/**
178 * i40iw_dealloc_ucontext - deallocate the user context data structure
179 * @context: user context created during alloc
180 */
181static int i40iw_dealloc_ucontext(struct ib_ucontext *context)
182{
183 struct i40iw_ucontext *ucontext = to_ucontext(context);
184 unsigned long flags;
185
186 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
187 if (!list_empty(&ucontext->cq_reg_mem_list)) {
188 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
189 return -EBUSY;
190 }
191 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
192 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
193 if (!list_empty(&ucontext->qp_reg_mem_list)) {
194 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
195 return -EBUSY;
196 }
197 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
198
199 kfree(ucontext);
200 return 0;
201}
202
203/**
204 * i40iw_mmap - user memory map
205 * @context: context created during alloc
206 * @vma: kernel info for user memory map
207 */
208static int i40iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
209{
210 struct i40iw_ucontext *ucontext;
211 u64 db_addr_offset;
212 u64 push_offset;
213
214 ucontext = to_ucontext(context);
215 if (ucontext->iwdev->sc_dev.is_pf) {
216 db_addr_offset = I40IW_DB_ADDR_OFFSET;
217 push_offset = I40IW_PUSH_OFFSET;
218 if (vma->vm_pgoff)
219 vma->vm_pgoff += I40IW_PF_FIRST_PUSH_PAGE_INDEX - 1;
220 } else {
221 db_addr_offset = I40IW_VF_DB_ADDR_OFFSET;
222 push_offset = I40IW_VF_PUSH_OFFSET;
223 if (vma->vm_pgoff)
224 vma->vm_pgoff += I40IW_VF_FIRST_PUSH_PAGE_INDEX - 1;
225 }
226
227 vma->vm_pgoff += db_addr_offset >> PAGE_SHIFT;
228
229 if (vma->vm_pgoff == (db_addr_offset >> PAGE_SHIFT)) {
230 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
231 vma->vm_private_data = ucontext;
232 } else {
233 if ((vma->vm_pgoff - (push_offset >> PAGE_SHIFT)) % 2)
234 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
235 else
236 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
237 }
238
239 if (io_remap_pfn_range(vma, vma->vm_start,
240 vma->vm_pgoff + (pci_resource_start(ucontext->iwdev->ldev->pcidev, 0) >> PAGE_SHIFT),
241 PAGE_SIZE, vma->vm_page_prot))
242 return -EAGAIN;
243
244 return 0;
245}
246
247/**
248 * i40iw_alloc_push_page - allocate a push page for qp
249 * @iwdev: iwarp device
250 * @qp: hardware control qp
251 */
252static void i40iw_alloc_push_page(struct i40iw_device *iwdev, struct i40iw_sc_qp *qp)
253{
254 struct i40iw_cqp_request *cqp_request;
255 struct cqp_commands_info *cqp_info;
256 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
257 enum i40iw_status_code status;
258
259 if (qp->push_idx != I40IW_INVALID_PUSH_PAGE_INDEX)
260 return;
261
262 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
263 if (!cqp_request)
264 return;
265
266 atomic_inc(&cqp_request->refcount);
267
268 cqp_info = &cqp_request->info;
269 cqp_info->cqp_cmd = OP_MANAGE_PUSH_PAGE;
270 cqp_info->post_sq = 1;
271
272 cqp_info->in.u.manage_push_page.info.qs_handle = dev->qs_handle;
273 cqp_info->in.u.manage_push_page.info.free_page = 0;
274 cqp_info->in.u.manage_push_page.cqp = &iwdev->cqp.sc_cqp;
275 cqp_info->in.u.manage_push_page.scratch = (uintptr_t)cqp_request;
276
277 status = i40iw_handle_cqp_op(iwdev, cqp_request);
278 if (!status)
279 qp->push_idx = cqp_request->compl_info.op_ret_val;
280 else
281 i40iw_pr_err("CQP-OP Push page fail");
282 i40iw_put_cqp_request(&iwdev->cqp, cqp_request);
283}
284
285/**
286 * i40iw_dealloc_push_page - free a push page for qp
287 * @iwdev: iwarp device
288 * @qp: hardware control qp
289 */
290static void i40iw_dealloc_push_page(struct i40iw_device *iwdev, struct i40iw_sc_qp *qp)
291{
292 struct i40iw_cqp_request *cqp_request;
293 struct cqp_commands_info *cqp_info;
294 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
295 enum i40iw_status_code status;
296
297 if (qp->push_idx == I40IW_INVALID_PUSH_PAGE_INDEX)
298 return;
299
300 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
301 if (!cqp_request)
302 return;
303
304 cqp_info = &cqp_request->info;
305 cqp_info->cqp_cmd = OP_MANAGE_PUSH_PAGE;
306 cqp_info->post_sq = 1;
307
308 cqp_info->in.u.manage_push_page.info.push_idx = qp->push_idx;
309 cqp_info->in.u.manage_push_page.info.qs_handle = dev->qs_handle;
310 cqp_info->in.u.manage_push_page.info.free_page = 1;
311 cqp_info->in.u.manage_push_page.cqp = &iwdev->cqp.sc_cqp;
312 cqp_info->in.u.manage_push_page.scratch = (uintptr_t)cqp_request;
313
314 status = i40iw_handle_cqp_op(iwdev, cqp_request);
315 if (!status)
316 qp->push_idx = I40IW_INVALID_PUSH_PAGE_INDEX;
317 else
318 i40iw_pr_err("CQP-OP Push page fail");
319}
320
321/**
322 * i40iw_alloc_pd - allocate protection domain
323 * @ibdev: device pointer from stack
324 * @context: user context created during alloc
325 * @udata: user data
326 */
327static struct ib_pd *i40iw_alloc_pd(struct ib_device *ibdev,
328 struct ib_ucontext *context,
329 struct ib_udata *udata)
330{
331 struct i40iw_pd *iwpd;
332 struct i40iw_device *iwdev = to_iwdev(ibdev);
333 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
334 struct i40iw_alloc_pd_resp uresp;
335 struct i40iw_sc_pd *sc_pd;
336 u32 pd_id = 0;
337 int err;
338
339 err = i40iw_alloc_resource(iwdev, iwdev->allocated_pds,
340 iwdev->max_pd, &pd_id, &iwdev->next_pd);
341 if (err) {
342 i40iw_pr_err("alloc resource failed\n");
343 return ERR_PTR(err);
344 }
345
346 iwpd = kzalloc(sizeof(*iwpd), GFP_KERNEL);
347 if (!iwpd) {
348 err = -ENOMEM;
349 goto free_res;
350 }
351
352 sc_pd = &iwpd->sc_pd;
353 dev->iw_pd_ops->pd_init(dev, sc_pd, pd_id);
354
355 if (context) {
356 memset(&uresp, 0, sizeof(uresp));
357 uresp.pd_id = pd_id;
358 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
359 err = -EFAULT;
360 goto error;
361 }
362 }
363
364 i40iw_add_pdusecount(iwpd);
365 return &iwpd->ibpd;
366error:
367 kfree(iwpd);
368free_res:
369 i40iw_free_resource(iwdev, iwdev->allocated_pds, pd_id);
370 return ERR_PTR(err);
371}
372
373/**
374 * i40iw_dealloc_pd - deallocate pd
375 * @ibpd: ptr of pd to be deallocated
376 */
377static int i40iw_dealloc_pd(struct ib_pd *ibpd)
378{
379 struct i40iw_pd *iwpd = to_iwpd(ibpd);
380 struct i40iw_device *iwdev = to_iwdev(ibpd->device);
381
382 i40iw_rem_pdusecount(iwpd, iwdev);
383 return 0;
384}
385
386/**
387 * i40iw_qp_roundup - return round up qp ring size
388 * @wr_ring_size: ring size to round up
389 */
390static int i40iw_qp_roundup(u32 wr_ring_size)
391{
392 int scount = 1;
393
394 if (wr_ring_size < I40IWQP_SW_MIN_WQSIZE)
395 wr_ring_size = I40IWQP_SW_MIN_WQSIZE;
396
397 for (wr_ring_size--; scount <= 16; scount *= 2)
398 wr_ring_size |= wr_ring_size >> scount;
399 return ++wr_ring_size;
400}
401
402/**
403 * i40iw_get_pbl - Retrieve pbl from a list given a virtual
404 * address
405 * @va: user virtual address
406 * @pbl_list: pbl list to search in (QP's or CQ's)
407 */
408static struct i40iw_pbl *i40iw_get_pbl(unsigned long va,
409 struct list_head *pbl_list)
410{
411 struct i40iw_pbl *iwpbl;
412
413 list_for_each_entry(iwpbl, pbl_list, list) {
414 if (iwpbl->user_base == va) {
415 list_del(&iwpbl->list);
416 return iwpbl;
417 }
418 }
419 return NULL;
420}
421
422/**
423 * i40iw_free_qp_resources - free up memory resources for qp
424 * @iwdev: iwarp device
425 * @iwqp: qp ptr (user or kernel)
426 * @qp_num: qp number assigned
427 */
428void i40iw_free_qp_resources(struct i40iw_device *iwdev,
429 struct i40iw_qp *iwqp,
430 u32 qp_num)
431{
432 i40iw_dealloc_push_page(iwdev, &iwqp->sc_qp);
433 if (qp_num)
434 i40iw_free_resource(iwdev, iwdev->allocated_qps, qp_num);
435 i40iw_free_dma_mem(iwdev->sc_dev.hw, &iwqp->q2_ctx_mem);
436 i40iw_free_dma_mem(iwdev->sc_dev.hw, &iwqp->kqp.dma_mem);
437 kfree(iwqp->kqp.wrid_mem);
438 iwqp->kqp.wrid_mem = NULL;
439 kfree(iwqp->allocated_buffer);
440 iwqp->allocated_buffer = NULL;
441}
442
443/**
444 * i40iw_clean_cqes - clean cq entries for qp
445 * @iwqp: qp ptr (user or kernel)
446 * @iwcq: cq ptr
447 */
448static void i40iw_clean_cqes(struct i40iw_qp *iwqp, struct i40iw_cq *iwcq)
449{
450 struct i40iw_cq_uk *ukcq = &iwcq->sc_cq.cq_uk;
451
452 ukcq->ops.iw_cq_clean(&iwqp->sc_qp.qp_uk, ukcq);
453}
454
455/**
456 * i40iw_destroy_qp - destroy qp
457 * @ibqp: qp's ib pointer also to get to device's qp address
458 */
459static int i40iw_destroy_qp(struct ib_qp *ibqp)
460{
461 struct i40iw_qp *iwqp = to_iwqp(ibqp);
462
463 iwqp->destroyed = 1;
464
465 if (iwqp->ibqp_state >= IB_QPS_INIT && iwqp->ibqp_state < IB_QPS_RTS)
466 i40iw_next_iw_state(iwqp, I40IW_QP_STATE_ERROR, 0, 0, 0);
467
468 if (!iwqp->user_mode) {
469 if (iwqp->iwscq) {
470 i40iw_clean_cqes(iwqp, iwqp->iwscq);
471 if (iwqp->iwrcq != iwqp->iwscq)
472 i40iw_clean_cqes(iwqp, iwqp->iwrcq);
473 }
474 }
475
476 i40iw_rem_ref(&iwqp->ibqp);
477 return 0;
478}
479
480/**
481 * i40iw_setup_virt_qp - setup for allocation of virtual qp
482 * @dev: iwarp device
483 * @qp: qp ptr
484 * @init_info: initialize info to return
485 */
486static int i40iw_setup_virt_qp(struct i40iw_device *iwdev,
487 struct i40iw_qp *iwqp,
488 struct i40iw_qp_init_info *init_info)
489{
490 struct i40iw_pbl *iwpbl = iwqp->iwpbl;
491 struct i40iw_qp_mr *qpmr = &iwpbl->qp_mr;
492
493 iwqp->page = qpmr->sq_page;
494 init_info->shadow_area_pa = cpu_to_le64(qpmr->shadow);
495 if (iwpbl->pbl_allocated) {
496 init_info->virtual_map = true;
497 init_info->sq_pa = qpmr->sq_pbl.idx;
498 init_info->rq_pa = qpmr->rq_pbl.idx;
499 } else {
500 init_info->sq_pa = qpmr->sq_pbl.addr;
501 init_info->rq_pa = qpmr->rq_pbl.addr;
502 }
503 return 0;
504}
505
506/**
507 * i40iw_setup_kmode_qp - setup initialization for kernel mode qp
508 * @iwdev: iwarp device
509 * @iwqp: qp ptr (user or kernel)
510 * @info: initialize info to return
511 */
512static int i40iw_setup_kmode_qp(struct i40iw_device *iwdev,
513 struct i40iw_qp *iwqp,
514 struct i40iw_qp_init_info *info)
515{
516 struct i40iw_dma_mem *mem = &iwqp->kqp.dma_mem;
517 u32 sqdepth, rqdepth;
518 u32 sq_size, rq_size;
519 u8 sqshift, rqshift;
520 u32 size;
521 enum i40iw_status_code status;
522 struct i40iw_qp_uk_init_info *ukinfo = &info->qp_uk_init_info;
523
524 ukinfo->max_sq_frag_cnt = I40IW_MAX_WQ_FRAGMENT_COUNT;
525
526 sq_size = i40iw_qp_roundup(ukinfo->sq_size + 1);
527 rq_size = i40iw_qp_roundup(ukinfo->rq_size + 1);
528
529 status = i40iw_get_wqe_shift(sq_size, ukinfo->max_sq_frag_cnt, &sqshift);
530 if (!status)
531 status = i40iw_get_wqe_shift(rq_size, ukinfo->max_rq_frag_cnt, &rqshift);
532
533 if (status)
534 return -ENOSYS;
535
536 sqdepth = sq_size << sqshift;
537 rqdepth = rq_size << rqshift;
538
539 size = sqdepth * sizeof(struct i40iw_sq_uk_wr_trk_info) + (rqdepth << 3);
540 iwqp->kqp.wrid_mem = kzalloc(size, GFP_KERNEL);
541
542 ukinfo->sq_wrtrk_array = (struct i40iw_sq_uk_wr_trk_info *)iwqp->kqp.wrid_mem;
543 if (!ukinfo->sq_wrtrk_array)
544 return -ENOMEM;
545
546 ukinfo->rq_wrid_array = (u64 *)&ukinfo->sq_wrtrk_array[sqdepth];
547
548 size = (sqdepth + rqdepth) * I40IW_QP_WQE_MIN_SIZE;
549 size += (I40IW_SHADOW_AREA_SIZE << 3);
550
551 status = i40iw_allocate_dma_mem(iwdev->sc_dev.hw, mem, size, 256);
552 if (status) {
553 kfree(ukinfo->sq_wrtrk_array);
554 ukinfo->sq_wrtrk_array = NULL;
555 return -ENOMEM;
556 }
557
558 ukinfo->sq = mem->va;
559 info->sq_pa = mem->pa;
560
561 ukinfo->rq = &ukinfo->sq[sqdepth];
562 info->rq_pa = info->sq_pa + (sqdepth * I40IW_QP_WQE_MIN_SIZE);
563
564 ukinfo->shadow_area = ukinfo->rq[rqdepth].elem;
565 info->shadow_area_pa = info->rq_pa + (rqdepth * I40IW_QP_WQE_MIN_SIZE);
566
567 ukinfo->sq_size = sq_size;
568 ukinfo->rq_size = rq_size;
569 ukinfo->qp_id = iwqp->ibqp.qp_num;
570 return 0;
571}
572
573/**
574 * i40iw_create_qp - create qp
575 * @ibpd: ptr of pd
576 * @init_attr: attributes for qp
577 * @udata: user data for create qp
578 */
579static struct ib_qp *i40iw_create_qp(struct ib_pd *ibpd,
580 struct ib_qp_init_attr *init_attr,
581 struct ib_udata *udata)
582{
583 struct i40iw_pd *iwpd = to_iwpd(ibpd);
584 struct i40iw_device *iwdev = to_iwdev(ibpd->device);
585 struct i40iw_cqp *iwcqp = &iwdev->cqp;
586 struct i40iw_qp *iwqp;
587 struct i40iw_ucontext *ucontext;
588 struct i40iw_create_qp_req req;
589 struct i40iw_create_qp_resp uresp;
590 u32 qp_num = 0;
591 void *mem;
592 enum i40iw_status_code ret;
593 int err_code;
594 int sq_size;
595 int rq_size;
596 struct i40iw_sc_qp *qp;
597 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
598 struct i40iw_qp_init_info init_info;
599 struct i40iw_create_qp_info *qp_info;
600 struct i40iw_cqp_request *cqp_request;
601 struct cqp_commands_info *cqp_info;
602
603 struct i40iw_qp_host_ctx_info *ctx_info;
604 struct i40iwarp_offload_info *iwarp_info;
605 unsigned long flags;
606
607 if (init_attr->create_flags)
608 return ERR_PTR(-EINVAL);
609 if (init_attr->cap.max_inline_data > I40IW_MAX_INLINE_DATA_SIZE)
610 init_attr->cap.max_inline_data = I40IW_MAX_INLINE_DATA_SIZE;
611
612 memset(&init_info, 0, sizeof(init_info));
613
614 sq_size = init_attr->cap.max_send_wr;
615 rq_size = init_attr->cap.max_recv_wr;
616
617 init_info.qp_uk_init_info.sq_size = sq_size;
618 init_info.qp_uk_init_info.rq_size = rq_size;
619 init_info.qp_uk_init_info.max_sq_frag_cnt = init_attr->cap.max_send_sge;
620 init_info.qp_uk_init_info.max_rq_frag_cnt = init_attr->cap.max_recv_sge;
621
622 mem = kzalloc(sizeof(*iwqp), GFP_KERNEL);
623 if (!mem)
624 return ERR_PTR(-ENOMEM);
625
626 iwqp = (struct i40iw_qp *)mem;
627 qp = &iwqp->sc_qp;
628 qp->back_qp = (void *)iwqp;
629 qp->push_idx = I40IW_INVALID_PUSH_PAGE_INDEX;
630
631 iwqp->ctx_info.iwarp_info = &iwqp->iwarp_info;
632
633 if (i40iw_allocate_dma_mem(dev->hw,
634 &iwqp->q2_ctx_mem,
635 I40IW_Q2_BUFFER_SIZE + I40IW_QP_CTX_SIZE,
636 256)) {
637 i40iw_pr_err("dma_mem failed\n");
638 err_code = -ENOMEM;
639 goto error;
640 }
641
642 init_info.q2 = iwqp->q2_ctx_mem.va;
643 init_info.q2_pa = iwqp->q2_ctx_mem.pa;
644
645 init_info.host_ctx = (void *)init_info.q2 + I40IW_Q2_BUFFER_SIZE;
646 init_info.host_ctx_pa = init_info.q2_pa + I40IW_Q2_BUFFER_SIZE;
647
648 err_code = i40iw_alloc_resource(iwdev, iwdev->allocated_qps, iwdev->max_qp,
649 &qp_num, &iwdev->next_qp);
650 if (err_code) {
651 i40iw_pr_err("qp resource\n");
652 goto error;
653 }
654
655 iwqp->allocated_buffer = mem;
656 iwqp->iwdev = iwdev;
657 iwqp->iwpd = iwpd;
658 iwqp->ibqp.qp_num = qp_num;
659 qp = &iwqp->sc_qp;
660 iwqp->iwscq = to_iwcq(init_attr->send_cq);
661 iwqp->iwrcq = to_iwcq(init_attr->recv_cq);
662
663 iwqp->host_ctx.va = init_info.host_ctx;
664 iwqp->host_ctx.pa = init_info.host_ctx_pa;
665 iwqp->host_ctx.size = I40IW_QP_CTX_SIZE;
666
667 init_info.pd = &iwpd->sc_pd;
668 init_info.qp_uk_init_info.qp_id = iwqp->ibqp.qp_num;
669 iwqp->ctx_info.qp_compl_ctx = (uintptr_t)qp;
670
671 if (init_attr->qp_type != IB_QPT_RC) {
672 err_code = -ENOSYS;
673 goto error;
674 }
675 if (iwdev->push_mode)
676 i40iw_alloc_push_page(iwdev, qp);
677 if (udata) {
678 err_code = ib_copy_from_udata(&req, udata, sizeof(req));
679 if (err_code) {
680 i40iw_pr_err("ib_copy_from_data\n");
681 goto error;
682 }
683 iwqp->ctx_info.qp_compl_ctx = req.user_compl_ctx;
684 if (ibpd->uobject && ibpd->uobject->context) {
685 iwqp->user_mode = 1;
686 ucontext = to_ucontext(ibpd->uobject->context);
687
688 if (req.user_wqe_buffers) {
689 spin_lock_irqsave(
690 &ucontext->qp_reg_mem_list_lock, flags);
691 iwqp->iwpbl = i40iw_get_pbl(
692 (unsigned long)req.user_wqe_buffers,
693 &ucontext->qp_reg_mem_list);
694 spin_unlock_irqrestore(
695 &ucontext->qp_reg_mem_list_lock, flags);
696
697 if (!iwqp->iwpbl) {
698 err_code = -ENODATA;
699 i40iw_pr_err("no pbl info\n");
700 goto error;
701 }
702 }
703 }
704 err_code = i40iw_setup_virt_qp(iwdev, iwqp, &init_info);
705 } else {
706 err_code = i40iw_setup_kmode_qp(iwdev, iwqp, &init_info);
707 }
708
709 if (err_code) {
710 i40iw_pr_err("setup qp failed\n");
711 goto error;
712 }
713
714 init_info.type = I40IW_QP_TYPE_IWARP;
715 ret = dev->iw_priv_qp_ops->qp_init(qp, &init_info);
716 if (ret) {
717 err_code = -EPROTO;
718 i40iw_pr_err("qp_init fail\n");
719 goto error;
720 }
721 ctx_info = &iwqp->ctx_info;
722 iwarp_info = &iwqp->iwarp_info;
723 iwarp_info->rd_enable = true;
724 iwarp_info->wr_rdresp_en = true;
725 if (!iwqp->user_mode)
726 iwarp_info->priv_mode_en = true;
727 iwarp_info->ddp_ver = 1;
728 iwarp_info->rdmap_ver = 1;
729
730 ctx_info->iwarp_info_valid = true;
731 ctx_info->send_cq_num = iwqp->iwscq->sc_cq.cq_uk.cq_id;
732 ctx_info->rcv_cq_num = iwqp->iwrcq->sc_cq.cq_uk.cq_id;
733 if (qp->push_idx == I40IW_INVALID_PUSH_PAGE_INDEX) {
734 ctx_info->push_mode_en = false;
735 } else {
736 ctx_info->push_mode_en = true;
737 ctx_info->push_idx = qp->push_idx;
738 }
739
740 ret = dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp,
741 (u64 *)iwqp->host_ctx.va,
742 ctx_info);
743 ctx_info->iwarp_info_valid = false;
744 cqp_request = i40iw_get_cqp_request(iwcqp, true);
745 if (!cqp_request) {
746 err_code = -ENOMEM;
747 goto error;
748 }
749 cqp_info = &cqp_request->info;
750 qp_info = &cqp_request->info.in.u.qp_create.info;
751
752 memset(qp_info, 0, sizeof(*qp_info));
753
754 qp_info->cq_num_valid = true;
755 qp_info->next_iwarp_state = I40IW_QP_STATE_IDLE;
756
757 cqp_info->cqp_cmd = OP_QP_CREATE;
758 cqp_info->post_sq = 1;
759 cqp_info->in.u.qp_create.qp = qp;
760 cqp_info->in.u.qp_create.scratch = (uintptr_t)cqp_request;
761 ret = i40iw_handle_cqp_op(iwdev, cqp_request);
762 if (ret) {
763 i40iw_pr_err("CQP-OP QP create fail");
764 err_code = -EACCES;
765 goto error;
766 }
767
768 i40iw_add_ref(&iwqp->ibqp);
769 spin_lock_init(&iwqp->lock);
770 iwqp->sig_all = (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) ? 1 : 0;
771 iwdev->qp_table[qp_num] = iwqp;
772 i40iw_add_pdusecount(iwqp->iwpd);
773 if (ibpd->uobject && udata) {
774 memset(&uresp, 0, sizeof(uresp));
775 uresp.actual_sq_size = sq_size;
776 uresp.actual_rq_size = rq_size;
777 uresp.qp_id = qp_num;
778 uresp.push_idx = qp->push_idx;
779 err_code = ib_copy_to_udata(udata, &uresp, sizeof(uresp));
780 if (err_code) {
781 i40iw_pr_err("copy_to_udata failed\n");
782 i40iw_destroy_qp(&iwqp->ibqp);
783 /* let the completion of the qp destroy free the qp */
784 return ERR_PTR(err_code);
785 }
786 }
787
788 return &iwqp->ibqp;
789error:
790 i40iw_free_qp_resources(iwdev, iwqp, qp_num);
791 kfree(mem);
792 return ERR_PTR(err_code);
793}
794
795/**
796 * i40iw_query - query qp attributes
797 * @ibqp: qp pointer
798 * @attr: attributes pointer
799 * @attr_mask: Not used
800 * @init_attr: qp attributes to return
801 */
802static int i40iw_query_qp(struct ib_qp *ibqp,
803 struct ib_qp_attr *attr,
804 int attr_mask,
805 struct ib_qp_init_attr *init_attr)
806{
807 struct i40iw_qp *iwqp = to_iwqp(ibqp);
808 struct i40iw_sc_qp *qp = &iwqp->sc_qp;
809
810 attr->qp_access_flags = 0;
811 attr->cap.max_send_wr = qp->qp_uk.sq_size;
812 attr->cap.max_recv_wr = qp->qp_uk.rq_size;
813 attr->cap.max_recv_sge = 1;
814 attr->cap.max_inline_data = I40IW_MAX_INLINE_DATA_SIZE;
815 init_attr->event_handler = iwqp->ibqp.event_handler;
816 init_attr->qp_context = iwqp->ibqp.qp_context;
817 init_attr->send_cq = iwqp->ibqp.send_cq;
818 init_attr->recv_cq = iwqp->ibqp.recv_cq;
819 init_attr->srq = iwqp->ibqp.srq;
820 init_attr->cap = attr->cap;
821 return 0;
822}
823
824/**
825 * i40iw_hw_modify_qp - setup cqp for modify qp
826 * @iwdev: iwarp device
827 * @iwqp: qp ptr (user or kernel)
828 * @info: info for modify qp
829 * @wait: flag to wait or not for modify qp completion
830 */
831void i40iw_hw_modify_qp(struct i40iw_device *iwdev, struct i40iw_qp *iwqp,
832 struct i40iw_modify_qp_info *info, bool wait)
833{
834 enum i40iw_status_code status;
835 struct i40iw_cqp_request *cqp_request;
836 struct cqp_commands_info *cqp_info;
837 struct i40iw_modify_qp_info *m_info;
838
839 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
840 if (!cqp_request)
841 return;
842
843 cqp_info = &cqp_request->info;
844 m_info = &cqp_info->in.u.qp_modify.info;
845 memcpy(m_info, info, sizeof(*m_info));
846 cqp_info->cqp_cmd = OP_QP_MODIFY;
847 cqp_info->post_sq = 1;
848 cqp_info->in.u.qp_modify.qp = &iwqp->sc_qp;
849 cqp_info->in.u.qp_modify.scratch = (uintptr_t)cqp_request;
850 status = i40iw_handle_cqp_op(iwdev, cqp_request);
851 if (status)
852 i40iw_pr_err("CQP-OP Modify QP fail");
853}
854
855/**
856 * i40iw_modify_qp - modify qp request
857 * @ibqp: qp's pointer for modify
858 * @attr: access attributes
859 * @attr_mask: state mask
860 * @udata: user data
861 */
862int i40iw_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
863 int attr_mask, struct ib_udata *udata)
864{
865 struct i40iw_qp *iwqp = to_iwqp(ibqp);
866 struct i40iw_device *iwdev = iwqp->iwdev;
867 struct i40iw_qp_host_ctx_info *ctx_info;
868 struct i40iwarp_offload_info *iwarp_info;
869 struct i40iw_modify_qp_info info;
870 u8 issue_modify_qp = 0;
871 u8 dont_wait = 0;
872 u32 err;
873 unsigned long flags;
874
875 memset(&info, 0, sizeof(info));
876 ctx_info = &iwqp->ctx_info;
877 iwarp_info = &iwqp->iwarp_info;
878
879 spin_lock_irqsave(&iwqp->lock, flags);
880
881 if (attr_mask & IB_QP_STATE) {
882 switch (attr->qp_state) {
883 case IB_QPS_INIT:
884 case IB_QPS_RTR:
885 if (iwqp->iwarp_state > (u32)I40IW_QP_STATE_IDLE) {
886 err = -EINVAL;
887 goto exit;
888 }
889 if (iwqp->iwarp_state == I40IW_QP_STATE_INVALID) {
890 info.next_iwarp_state = I40IW_QP_STATE_IDLE;
891 issue_modify_qp = 1;
892 }
893 break;
894 case IB_QPS_RTS:
895 if ((iwqp->iwarp_state > (u32)I40IW_QP_STATE_RTS) ||
896 (!iwqp->cm_id)) {
897 err = -EINVAL;
898 goto exit;
899 }
900
901 issue_modify_qp = 1;
902 iwqp->hw_tcp_state = I40IW_TCP_STATE_ESTABLISHED;
903 iwqp->hte_added = 1;
904 info.next_iwarp_state = I40IW_QP_STATE_RTS;
905 info.tcp_ctx_valid = true;
906 info.ord_valid = true;
907 info.arp_cache_idx_valid = true;
908 info.cq_num_valid = true;
909 break;
910 case IB_QPS_SQD:
911 if (iwqp->hw_iwarp_state > (u32)I40IW_QP_STATE_RTS) {
912 err = 0;
913 goto exit;
914 }
915 if ((iwqp->iwarp_state == (u32)I40IW_QP_STATE_CLOSING) ||
916 (iwqp->iwarp_state < (u32)I40IW_QP_STATE_RTS)) {
917 err = 0;
918 goto exit;
919 }
920 if (iwqp->iwarp_state > (u32)I40IW_QP_STATE_CLOSING) {
921 err = -EINVAL;
922 goto exit;
923 }
924 info.next_iwarp_state = I40IW_QP_STATE_CLOSING;
925 issue_modify_qp = 1;
926 break;
927 case IB_QPS_SQE:
928 if (iwqp->iwarp_state >= (u32)I40IW_QP_STATE_TERMINATE) {
929 err = -EINVAL;
930 goto exit;
931 }
932 info.next_iwarp_state = I40IW_QP_STATE_TERMINATE;
933 issue_modify_qp = 1;
934 break;
935 case IB_QPS_ERR:
936 case IB_QPS_RESET:
937 if (iwqp->iwarp_state == (u32)I40IW_QP_STATE_ERROR) {
938 err = -EINVAL;
939 goto exit;
940 }
941 if (iwqp->sc_qp.term_flags)
942 del_timer(&iwqp->terminate_timer);
943 info.next_iwarp_state = I40IW_QP_STATE_ERROR;
944 if ((iwqp->hw_tcp_state > I40IW_TCP_STATE_CLOSED) &&
945 iwdev->iw_status &&
946 (iwqp->hw_tcp_state != I40IW_TCP_STATE_TIME_WAIT))
947 info.reset_tcp_conn = true;
948 else
949 dont_wait = 1;
950 issue_modify_qp = 1;
951 info.next_iwarp_state = I40IW_QP_STATE_ERROR;
952 break;
953 default:
954 err = -EINVAL;
955 goto exit;
956 }
957
958 iwqp->ibqp_state = attr->qp_state;
959
960 if (issue_modify_qp)
961 iwqp->iwarp_state = info.next_iwarp_state;
962 else
963 info.next_iwarp_state = iwqp->iwarp_state;
964 }
965 if (attr_mask & IB_QP_ACCESS_FLAGS) {
966 ctx_info->iwarp_info_valid = true;
967 if (attr->qp_access_flags & IB_ACCESS_LOCAL_WRITE)
968 iwarp_info->wr_rdresp_en = true;
969 if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE)
970 iwarp_info->wr_rdresp_en = true;
971 if (attr->qp_access_flags & IB_ACCESS_REMOTE_READ)
972 iwarp_info->rd_enable = true;
973 if (attr->qp_access_flags & IB_ACCESS_MW_BIND)
974 iwarp_info->bind_en = true;
975
976 if (iwqp->user_mode) {
977 iwarp_info->rd_enable = true;
978 iwarp_info->wr_rdresp_en = true;
979 iwarp_info->priv_mode_en = false;
980 }
981 }
982
983 if (ctx_info->iwarp_info_valid) {
984 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
985 int ret;
986
987 ctx_info->send_cq_num = iwqp->iwscq->sc_cq.cq_uk.cq_id;
988 ctx_info->rcv_cq_num = iwqp->iwrcq->sc_cq.cq_uk.cq_id;
989 ret = dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp,
990 (u64 *)iwqp->host_ctx.va,
991 ctx_info);
992 if (ret) {
993 i40iw_pr_err("setting QP context\n");
994 err = -EINVAL;
995 goto exit;
996 }
997 }
998
999 spin_unlock_irqrestore(&iwqp->lock, flags);
1000
1001 if (issue_modify_qp)
1002 i40iw_hw_modify_qp(iwdev, iwqp, &info, true);
1003
1004 if (issue_modify_qp && (iwqp->ibqp_state > IB_QPS_RTS)) {
1005 if (dont_wait) {
1006 if (iwqp->cm_id && iwqp->hw_tcp_state) {
1007 spin_lock_irqsave(&iwqp->lock, flags);
1008 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSED;
1009 iwqp->last_aeq = I40IW_AE_RESET_SENT;
1010 spin_unlock_irqrestore(&iwqp->lock, flags);
1011 }
1012 }
1013 }
1014 return 0;
1015exit:
1016 spin_unlock_irqrestore(&iwqp->lock, flags);
1017 return err;
1018}
1019
1020/**
1021 * cq_free_resources - free up recources for cq
1022 * @iwdev: iwarp device
1023 * @iwcq: cq ptr
1024 */
1025static void cq_free_resources(struct i40iw_device *iwdev, struct i40iw_cq *iwcq)
1026{
1027 struct i40iw_sc_cq *cq = &iwcq->sc_cq;
1028
1029 if (!iwcq->user_mode)
1030 i40iw_free_dma_mem(iwdev->sc_dev.hw, &iwcq->kmem);
1031 i40iw_free_resource(iwdev, iwdev->allocated_cqs, cq->cq_uk.cq_id);
1032}
1033
1034/**
1035 * cq_wq_destroy - send cq destroy cqp
1036 * @iwdev: iwarp device
1037 * @cq: hardware control cq
1038 */
1039static void cq_wq_destroy(struct i40iw_device *iwdev, struct i40iw_sc_cq *cq)
1040{
1041 enum i40iw_status_code status;
1042 struct i40iw_cqp_request *cqp_request;
1043 struct cqp_commands_info *cqp_info;
1044
1045 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1046 if (!cqp_request)
1047 return;
1048
1049 cqp_info = &cqp_request->info;
1050
1051 cqp_info->cqp_cmd = OP_CQ_DESTROY;
1052 cqp_info->post_sq = 1;
1053 cqp_info->in.u.cq_destroy.cq = cq;
1054 cqp_info->in.u.cq_destroy.scratch = (uintptr_t)cqp_request;
1055 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1056 if (status)
1057 i40iw_pr_err("CQP-OP Destroy QP fail");
1058}
1059
1060/**
1061 * i40iw_destroy_cq - destroy cq
1062 * @ib_cq: cq pointer
1063 */
1064static int i40iw_destroy_cq(struct ib_cq *ib_cq)
1065{
1066 struct i40iw_cq *iwcq;
1067 struct i40iw_device *iwdev;
1068 struct i40iw_sc_cq *cq;
1069
1070 if (!ib_cq) {
1071 i40iw_pr_err("ib_cq == NULL\n");
1072 return 0;
1073 }
1074
1075 iwcq = to_iwcq(ib_cq);
1076 iwdev = to_iwdev(ib_cq->device);
1077 cq = &iwcq->sc_cq;
1078 cq_wq_destroy(iwdev, cq);
1079 cq_free_resources(iwdev, iwcq);
1080 kfree(iwcq);
1081 return 0;
1082}
1083
1084/**
1085 * i40iw_create_cq - create cq
1086 * @ibdev: device pointer from stack
1087 * @attr: attributes for cq
1088 * @context: user context created during alloc
1089 * @udata: user data
1090 */
1091static struct ib_cq *i40iw_create_cq(struct ib_device *ibdev,
1092 const struct ib_cq_init_attr *attr,
1093 struct ib_ucontext *context,
1094 struct ib_udata *udata)
1095{
1096 struct i40iw_device *iwdev = to_iwdev(ibdev);
1097 struct i40iw_cq *iwcq;
1098 struct i40iw_pbl *iwpbl;
1099 u32 cq_num = 0;
1100 struct i40iw_sc_cq *cq;
1101 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1102 struct i40iw_cq_init_info info;
1103 enum i40iw_status_code status;
1104 struct i40iw_cqp_request *cqp_request;
1105 struct cqp_commands_info *cqp_info;
1106 struct i40iw_cq_uk_init_info *ukinfo = &info.cq_uk_init_info;
1107 unsigned long flags;
1108 int err_code;
1109 int entries = attr->cqe;
1110
1111 if (entries > iwdev->max_cqe)
1112 return ERR_PTR(-EINVAL);
1113
1114 iwcq = kzalloc(sizeof(*iwcq), GFP_KERNEL);
1115 if (!iwcq)
1116 return ERR_PTR(-ENOMEM);
1117
1118 memset(&info, 0, sizeof(info));
1119
1120 err_code = i40iw_alloc_resource(iwdev, iwdev->allocated_cqs,
1121 iwdev->max_cq, &cq_num,
1122 &iwdev->next_cq);
1123 if (err_code)
1124 goto error;
1125
1126 cq = &iwcq->sc_cq;
1127 cq->back_cq = (void *)iwcq;
1128 spin_lock_init(&iwcq->lock);
1129
1130 info.dev = dev;
1131 ukinfo->cq_size = max(entries, 4);
1132 ukinfo->cq_id = cq_num;
1133 iwcq->ibcq.cqe = info.cq_uk_init_info.cq_size;
1134 info.ceqe_mask = 0;
1135 info.ceq_id = 0;
1136 info.ceq_id_valid = true;
1137 info.ceqe_mask = 1;
1138 info.type = I40IW_CQ_TYPE_IWARP;
1139 if (context) {
1140 struct i40iw_ucontext *ucontext;
1141 struct i40iw_create_cq_req req;
1142 struct i40iw_cq_mr *cqmr;
1143
1144 memset(&req, 0, sizeof(req));
1145 iwcq->user_mode = true;
1146 ucontext = to_ucontext(context);
1147 if (ib_copy_from_udata(&req, udata, sizeof(struct i40iw_create_cq_req)))
1148 goto cq_free_resources;
1149
1150 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
1151 iwpbl = i40iw_get_pbl((unsigned long)req.user_cq_buffer,
1152 &ucontext->cq_reg_mem_list);
1153 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
1154 if (!iwpbl) {
1155 err_code = -EPROTO;
1156 goto cq_free_resources;
1157 }
1158
1159 iwcq->iwpbl = iwpbl;
1160 iwcq->cq_mem_size = 0;
1161 cqmr = &iwpbl->cq_mr;
1162 info.shadow_area_pa = cpu_to_le64(cqmr->shadow);
1163 if (iwpbl->pbl_allocated) {
1164 info.virtual_map = true;
1165 info.pbl_chunk_size = 1;
1166 info.first_pm_pbl_idx = cqmr->cq_pbl.idx;
1167 } else {
1168 info.cq_base_pa = cqmr->cq_pbl.addr;
1169 }
1170 } else {
1171 /* Kmode allocations */
1172 int rsize;
1173 int shadow;
1174
1175 rsize = info.cq_uk_init_info.cq_size * sizeof(struct i40iw_cqe);
1176 rsize = round_up(rsize, 256);
1177 shadow = I40IW_SHADOW_AREA_SIZE << 3;
1178 status = i40iw_allocate_dma_mem(dev->hw, &iwcq->kmem,
1179 rsize + shadow, 256);
1180 if (status) {
1181 err_code = -ENOMEM;
1182 goto cq_free_resources;
1183 }
1184 ukinfo->cq_base = iwcq->kmem.va;
1185 info.cq_base_pa = iwcq->kmem.pa;
1186 info.shadow_area_pa = info.cq_base_pa + rsize;
1187 ukinfo->shadow_area = iwcq->kmem.va + rsize;
1188 }
1189
1190 if (dev->iw_priv_cq_ops->cq_init(cq, &info)) {
1191 i40iw_pr_err("init cq fail\n");
1192 err_code = -EPROTO;
1193 goto cq_free_resources;
1194 }
1195
1196 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1197 if (!cqp_request) {
1198 err_code = -ENOMEM;
1199 goto cq_free_resources;
1200 }
1201
1202 cqp_info = &cqp_request->info;
1203 cqp_info->cqp_cmd = OP_CQ_CREATE;
1204 cqp_info->post_sq = 1;
1205 cqp_info->in.u.cq_create.cq = cq;
1206 cqp_info->in.u.cq_create.scratch = (uintptr_t)cqp_request;
1207 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1208 if (status) {
1209 i40iw_pr_err("CQP-OP Create QP fail");
1210 err_code = -EPROTO;
1211 goto cq_free_resources;
1212 }
1213
1214 if (context) {
1215 struct i40iw_create_cq_resp resp;
1216
1217 memset(&resp, 0, sizeof(resp));
1218 resp.cq_id = info.cq_uk_init_info.cq_id;
1219 resp.cq_size = info.cq_uk_init_info.cq_size;
1220 if (ib_copy_to_udata(udata, &resp, sizeof(resp))) {
1221 i40iw_pr_err("copy to user data\n");
1222 err_code = -EPROTO;
1223 goto cq_destroy;
1224 }
1225 }
1226
1227 return (struct ib_cq *)iwcq;
1228
1229cq_destroy:
1230 cq_wq_destroy(iwdev, cq);
1231cq_free_resources:
1232 cq_free_resources(iwdev, iwcq);
1233error:
1234 kfree(iwcq);
1235 return ERR_PTR(err_code);
1236}
1237
1238/**
1239 * i40iw_get_user_access - get hw access from IB access
1240 * @acc: IB access to return hw access
1241 */
1242static inline u16 i40iw_get_user_access(int acc)
1243{
1244 u16 access = 0;
1245
1246 access |= (acc & IB_ACCESS_LOCAL_WRITE) ? I40IW_ACCESS_FLAGS_LOCALWRITE : 0;
1247 access |= (acc & IB_ACCESS_REMOTE_WRITE) ? I40IW_ACCESS_FLAGS_REMOTEWRITE : 0;
1248 access |= (acc & IB_ACCESS_REMOTE_READ) ? I40IW_ACCESS_FLAGS_REMOTEREAD : 0;
1249 access |= (acc & IB_ACCESS_MW_BIND) ? I40IW_ACCESS_FLAGS_BIND_WINDOW : 0;
1250 return access;
1251}
1252
1253/**
1254 * i40iw_free_stag - free stag resource
1255 * @iwdev: iwarp device
1256 * @stag: stag to free
1257 */
1258static void i40iw_free_stag(struct i40iw_device *iwdev, u32 stag)
1259{
1260 u32 stag_idx;
1261
1262 stag_idx = (stag & iwdev->mr_stagmask) >> I40IW_CQPSQ_STAG_IDX_SHIFT;
1263 i40iw_free_resource(iwdev, iwdev->allocated_mrs, stag_idx);
1264}
1265
1266/**
1267 * i40iw_create_stag - create random stag
1268 * @iwdev: iwarp device
1269 */
1270static u32 i40iw_create_stag(struct i40iw_device *iwdev)
1271{
1272 u32 stag = 0;
1273 u32 stag_index = 0;
1274 u32 next_stag_index;
1275 u32 driver_key;
1276 u32 random;
1277 u8 consumer_key;
1278 int ret;
1279
1280 get_random_bytes(&random, sizeof(random));
1281 consumer_key = (u8)random;
1282
1283 driver_key = random & ~iwdev->mr_stagmask;
1284 next_stag_index = (random & iwdev->mr_stagmask) >> 8;
1285 next_stag_index %= iwdev->max_mr;
1286
1287 ret = i40iw_alloc_resource(iwdev,
1288 iwdev->allocated_mrs, iwdev->max_mr,
1289 &stag_index, &next_stag_index);
1290 if (!ret) {
1291 stag = stag_index << I40IW_CQPSQ_STAG_IDX_SHIFT;
1292 stag |= driver_key;
1293 stag += (u32)consumer_key;
1294 }
1295 return stag;
1296}
1297
1298/**
1299 * i40iw_next_pbl_addr - Get next pbl address
1300 * @palloc: Poiner to allocated pbles
1301 * @pbl: pointer to a pble
1302 * @pinfo: info pointer
1303 * @idx: index
1304 */
1305static inline u64 *i40iw_next_pbl_addr(struct i40iw_pble_alloc *palloc,
1306 u64 *pbl,
1307 struct i40iw_pble_info **pinfo,
1308 u32 *idx)
1309{
1310 *idx += 1;
1311 if ((!(*pinfo)) || (*idx != (*pinfo)->cnt))
1312 return ++pbl;
1313 *idx = 0;
1314 (*pinfo)++;
1315 return (u64 *)(*pinfo)->addr;
1316}
1317
1318/**
1319 * i40iw_copy_user_pgaddrs - copy user page address to pble's os locally
1320 * @iwmr: iwmr for IB's user page addresses
1321 * @pbl: ple pointer to save 1 level or 0 level pble
1322 * @level: indicated level 0, 1 or 2
1323 */
1324static void i40iw_copy_user_pgaddrs(struct i40iw_mr *iwmr,
1325 u64 *pbl,
1326 enum i40iw_pble_level level)
1327{
1328 struct ib_umem *region = iwmr->region;
1329 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1330 int chunk_pages, entry, pg_shift, i;
1331 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1332 struct i40iw_pble_info *pinfo;
1333 struct scatterlist *sg;
1334 u32 idx = 0;
1335
1336 pinfo = (level == I40IW_LEVEL_1) ? NULL : palloc->level2.leaf;
1337 pg_shift = ffs(region->page_size) - 1;
1338 for_each_sg(region->sg_head.sgl, sg, region->nmap, entry) {
1339 chunk_pages = sg_dma_len(sg) >> pg_shift;
1340 if ((iwmr->type == IW_MEMREG_TYPE_QP) &&
1341 !iwpbl->qp_mr.sq_page)
1342 iwpbl->qp_mr.sq_page = sg_page(sg);
1343 for (i = 0; i < chunk_pages; i++) {
1344 *pbl = cpu_to_le64(sg_dma_address(sg) + region->page_size * i);
1345 pbl = i40iw_next_pbl_addr(palloc, pbl, &pinfo, &idx);
1346 }
1347 }
1348}
1349
1350/**
1351 * i40iw_setup_pbles - copy user pg address to pble's
1352 * @iwdev: iwarp device
1353 * @iwmr: mr pointer for this memory registration
1354 * @use_pbles: flag if to use pble's or memory (level 0)
1355 */
1356static int i40iw_setup_pbles(struct i40iw_device *iwdev,
1357 struct i40iw_mr *iwmr,
1358 bool use_pbles)
1359{
1360 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1361 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1362 struct i40iw_pble_info *pinfo;
1363 u64 *pbl;
1364 enum i40iw_status_code status;
1365 enum i40iw_pble_level level = I40IW_LEVEL_1;
1366
1367 if (!use_pbles && (iwmr->page_cnt > MAX_SAVE_PAGE_ADDRS))
1368 return -ENOMEM;
1369
1370 if (use_pbles) {
1371 mutex_lock(&iwdev->pbl_mutex);
1372 status = i40iw_get_pble(&iwdev->sc_dev, iwdev->pble_rsrc, palloc, iwmr->page_cnt);
1373 mutex_unlock(&iwdev->pbl_mutex);
1374 if (status)
1375 return -ENOMEM;
1376
1377 iwpbl->pbl_allocated = true;
1378 level = palloc->level;
1379 pinfo = (level == I40IW_LEVEL_1) ? &palloc->level1 : palloc->level2.leaf;
1380 pbl = (u64 *)pinfo->addr;
1381 } else {
1382 pbl = iwmr->pgaddrmem;
1383 }
1384
1385 i40iw_copy_user_pgaddrs(iwmr, pbl, level);
1386 return 0;
1387}
1388
1389/**
1390 * i40iw_handle_q_mem - handle memory for qp and cq
1391 * @iwdev: iwarp device
1392 * @req: information for q memory management
1393 * @iwpbl: pble struct
1394 * @use_pbles: flag to use pble
1395 */
1396static int i40iw_handle_q_mem(struct i40iw_device *iwdev,
1397 struct i40iw_mem_reg_req *req,
1398 struct i40iw_pbl *iwpbl,
1399 bool use_pbles)
1400{
1401 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1402 struct i40iw_mr *iwmr = iwpbl->iwmr;
1403 struct i40iw_qp_mr *qpmr = &iwpbl->qp_mr;
1404 struct i40iw_cq_mr *cqmr = &iwpbl->cq_mr;
1405 struct i40iw_hmc_pble *hmc_p;
1406 u64 *arr = iwmr->pgaddrmem;
1407 int err;
1408 int total;
1409
1410 total = req->sq_pages + req->rq_pages + req->cq_pages;
1411
1412 err = i40iw_setup_pbles(iwdev, iwmr, use_pbles);
1413 if (err)
1414 return err;
1415 if (use_pbles && (palloc->level != I40IW_LEVEL_1)) {
1416 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1417 iwpbl->pbl_allocated = false;
1418 return -ENOMEM;
1419 }
1420
1421 if (use_pbles)
1422 arr = (u64 *)palloc->level1.addr;
1423 if (req->reg_type == IW_MEMREG_TYPE_QP) {
1424 hmc_p = &qpmr->sq_pbl;
1425 qpmr->shadow = (dma_addr_t)arr[total];
1426 if (use_pbles) {
1427 hmc_p->idx = palloc->level1.idx;
1428 hmc_p = &qpmr->rq_pbl;
1429 hmc_p->idx = palloc->level1.idx + req->sq_pages;
1430 } else {
1431 hmc_p->addr = arr[0];
1432 hmc_p = &qpmr->rq_pbl;
1433 hmc_p->addr = arr[1];
1434 }
1435 } else { /* CQ */
1436 hmc_p = &cqmr->cq_pbl;
1437 cqmr->shadow = (dma_addr_t)arr[total];
1438 if (use_pbles)
1439 hmc_p->idx = palloc->level1.idx;
1440 else
1441 hmc_p->addr = arr[0];
1442 }
1443 return err;
1444}
1445
1446/**
1447 * i40iw_hwreg_mr - send cqp command for memory registration
1448 * @iwdev: iwarp device
1449 * @iwmr: iwarp mr pointer
1450 * @access: access for MR
1451 */
1452static int i40iw_hwreg_mr(struct i40iw_device *iwdev,
1453 struct i40iw_mr *iwmr,
1454 u16 access)
1455{
1456 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1457 struct i40iw_reg_ns_stag_info *stag_info;
1458 struct i40iw_pd *iwpd = to_iwpd(iwmr->ibmr.pd);
1459 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1460 enum i40iw_status_code status;
1461 int err = 0;
1462 struct i40iw_cqp_request *cqp_request;
1463 struct cqp_commands_info *cqp_info;
1464
1465 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1466 if (!cqp_request)
1467 return -ENOMEM;
1468
1469 cqp_info = &cqp_request->info;
1470 stag_info = &cqp_info->in.u.mr_reg_non_shared.info;
1471 memset(stag_info, 0, sizeof(*stag_info));
1472 stag_info->va = (void *)(unsigned long)iwpbl->user_base;
1473 stag_info->stag_idx = iwmr->stag >> I40IW_CQPSQ_STAG_IDX_SHIFT;
1474 stag_info->stag_key = (u8)iwmr->stag;
1475 stag_info->total_len = iwmr->length;
1476 stag_info->access_rights = access;
1477 stag_info->pd_id = iwpd->sc_pd.pd_id;
1478 stag_info->addr_type = I40IW_ADDR_TYPE_VA_BASED;
1479
1480 if (iwmr->page_cnt > 1) {
1481 if (palloc->level == I40IW_LEVEL_1) {
1482 stag_info->first_pm_pbl_index = palloc->level1.idx;
1483 stag_info->chunk_size = 1;
1484 } else {
1485 stag_info->first_pm_pbl_index = palloc->level2.root.idx;
1486 stag_info->chunk_size = 3;
1487 }
1488 } else {
1489 stag_info->reg_addr_pa = iwmr->pgaddrmem[0];
1490 }
1491
1492 cqp_info->cqp_cmd = OP_MR_REG_NON_SHARED;
1493 cqp_info->post_sq = 1;
1494 cqp_info->in.u.mr_reg_non_shared.dev = &iwdev->sc_dev;
1495 cqp_info->in.u.mr_reg_non_shared.scratch = (uintptr_t)cqp_request;
1496
1497 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1498 if (status) {
1499 err = -ENOMEM;
1500 i40iw_pr_err("CQP-OP MR Reg fail");
1501 }
1502 return err;
1503}
1504
1505/**
1506 * i40iw_reg_user_mr - Register a user memory region
1507 * @pd: ptr of pd
1508 * @start: virtual start address
1509 * @length: length of mr
1510 * @virt: virtual address
1511 * @acc: access of mr
1512 * @udata: user data
1513 */
1514static struct ib_mr *i40iw_reg_user_mr(struct ib_pd *pd,
1515 u64 start,
1516 u64 length,
1517 u64 virt,
1518 int acc,
1519 struct ib_udata *udata)
1520{
1521 struct i40iw_pd *iwpd = to_iwpd(pd);
1522 struct i40iw_device *iwdev = to_iwdev(pd->device);
1523 struct i40iw_ucontext *ucontext;
1524 struct i40iw_pble_alloc *palloc;
1525 struct i40iw_pbl *iwpbl;
1526 struct i40iw_mr *iwmr;
1527 struct ib_umem *region;
1528 struct i40iw_mem_reg_req req;
1529 u32 pbl_depth = 0;
1530 u32 stag = 0;
1531 u16 access;
1532 u32 region_length;
1533 bool use_pbles = false;
1534 unsigned long flags;
1535 int err = -ENOSYS;
1536
1537 region = ib_umem_get(pd->uobject->context, start, length, acc, 0);
1538 if (IS_ERR(region))
1539 return (struct ib_mr *)region;
1540
1541 if (ib_copy_from_udata(&req, udata, sizeof(req))) {
1542 ib_umem_release(region);
1543 return ERR_PTR(-EFAULT);
1544 }
1545
1546 iwmr = kzalloc(sizeof(*iwmr), GFP_KERNEL);
1547 if (!iwmr) {
1548 ib_umem_release(region);
1549 return ERR_PTR(-ENOMEM);
1550 }
1551
1552 iwpbl = &iwmr->iwpbl;
1553 iwpbl->iwmr = iwmr;
1554 iwmr->region = region;
1555 iwmr->ibmr.pd = pd;
1556 iwmr->ibmr.device = pd->device;
1557 ucontext = to_ucontext(pd->uobject->context);
1558 region_length = region->length + (start & 0xfff);
1559 pbl_depth = region_length >> 12;
1560 pbl_depth += (region_length & (4096 - 1)) ? 1 : 0;
1561 iwmr->length = region->length;
1562
1563 iwpbl->user_base = virt;
1564 palloc = &iwpbl->pble_alloc;
1565
1566 iwmr->type = req.reg_type;
1567 iwmr->page_cnt = pbl_depth;
1568
1569 switch (req.reg_type) {
1570 case IW_MEMREG_TYPE_QP:
1571 use_pbles = ((req.sq_pages + req.rq_pages) > 2);
1572 err = i40iw_handle_q_mem(iwdev, &req, iwpbl, use_pbles);
1573 if (err)
1574 goto error;
1575 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
1576 list_add_tail(&iwpbl->list, &ucontext->qp_reg_mem_list);
1577 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
1578 break;
1579 case IW_MEMREG_TYPE_CQ:
1580 use_pbles = (req.cq_pages > 1);
1581 err = i40iw_handle_q_mem(iwdev, &req, iwpbl, use_pbles);
1582 if (err)
1583 goto error;
1584
1585 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
1586 list_add_tail(&iwpbl->list, &ucontext->cq_reg_mem_list);
1587 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
1588 break;
1589 case IW_MEMREG_TYPE_MEM:
1590 access = I40IW_ACCESS_FLAGS_LOCALREAD;
1591
1592 use_pbles = (iwmr->page_cnt != 1);
1593 err = i40iw_setup_pbles(iwdev, iwmr, use_pbles);
1594 if (err)
1595 goto error;
1596
1597 access |= i40iw_get_user_access(acc);
1598 stag = i40iw_create_stag(iwdev);
1599 if (!stag) {
1600 err = -ENOMEM;
1601 goto error;
1602 }
1603
1604 iwmr->stag = stag;
1605 iwmr->ibmr.rkey = stag;
1606 iwmr->ibmr.lkey = stag;
1607
1608 err = i40iw_hwreg_mr(iwdev, iwmr, access);
1609 if (err) {
1610 i40iw_free_stag(iwdev, stag);
1611 goto error;
1612 }
1613 break;
1614 default:
1615 goto error;
1616 }
1617
1618 iwmr->type = req.reg_type;
1619 if (req.reg_type == IW_MEMREG_TYPE_MEM)
1620 i40iw_add_pdusecount(iwpd);
1621 return &iwmr->ibmr;
1622
1623error:
1624 if (palloc->level != I40IW_LEVEL_0)
1625 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1626 ib_umem_release(region);
1627 kfree(iwmr);
1628 return ERR_PTR(err);
1629}
1630
1631/**
1632 * i40iw_reg_phys_mr - register kernel physical memory
1633 * @pd: ibpd pointer
1634 * @addr: physical address of memory to register
1635 * @size: size of memory to register
1636 * @acc: Access rights
1637 * @iova_start: start of virtual address for physical buffers
1638 */
1639struct ib_mr *i40iw_reg_phys_mr(struct ib_pd *pd,
1640 u64 addr,
1641 u64 size,
1642 int acc,
1643 u64 *iova_start)
1644{
1645 struct i40iw_pd *iwpd = to_iwpd(pd);
1646 struct i40iw_device *iwdev = to_iwdev(pd->device);
1647 struct i40iw_pbl *iwpbl;
1648 struct i40iw_mr *iwmr;
1649 enum i40iw_status_code status;
1650 u32 stag;
1651 u16 access = I40IW_ACCESS_FLAGS_LOCALREAD;
1652 int ret;
1653
1654 iwmr = kzalloc(sizeof(*iwmr), GFP_KERNEL);
1655 if (!iwmr)
1656 return ERR_PTR(-ENOMEM);
1657 iwmr->ibmr.pd = pd;
1658 iwmr->ibmr.device = pd->device;
1659 iwpbl = &iwmr->iwpbl;
1660 iwpbl->iwmr = iwmr;
1661 iwmr->type = IW_MEMREG_TYPE_MEM;
1662 iwpbl->user_base = *iova_start;
1663 stag = i40iw_create_stag(iwdev);
1664 if (!stag) {
1665 ret = -EOVERFLOW;
1666 goto err;
1667 }
1668 access |= i40iw_get_user_access(acc);
1669 iwmr->stag = stag;
1670 iwmr->ibmr.rkey = stag;
1671 iwmr->ibmr.lkey = stag;
1672 iwmr->page_cnt = 1;
1673 iwmr->pgaddrmem[0] = addr;
1674 status = i40iw_hwreg_mr(iwdev, iwmr, access);
1675 if (status) {
1676 i40iw_free_stag(iwdev, stag);
1677 ret = -ENOMEM;
1678 goto err;
1679 }
1680
1681 i40iw_add_pdusecount(iwpd);
1682 return &iwmr->ibmr;
1683 err:
1684 kfree(iwmr);
1685 return ERR_PTR(ret);
1686}
1687
1688/**
1689 * i40iw_get_dma_mr - register physical mem
1690 * @pd: ptr of pd
1691 * @acc: access for memory
1692 */
1693static struct ib_mr *i40iw_get_dma_mr(struct ib_pd *pd, int acc)
1694{
1695 u64 kva = 0;
1696
1697 return i40iw_reg_phys_mr(pd, 0, 0xffffffffffULL, acc, &kva);
1698}
1699
1700/**
1701 * i40iw_del_mem_list - Deleting pbl list entries for CQ/QP
1702 * @iwmr: iwmr for IB's user page addresses
1703 * @ucontext: ptr to user context
1704 */
1705static void i40iw_del_memlist(struct i40iw_mr *iwmr,
1706 struct i40iw_ucontext *ucontext)
1707{
1708 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1709 unsigned long flags;
1710
1711 switch (iwmr->type) {
1712 case IW_MEMREG_TYPE_CQ:
1713 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
1714 if (!list_empty(&ucontext->cq_reg_mem_list))
1715 list_del(&iwpbl->list);
1716 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
1717 break;
1718 case IW_MEMREG_TYPE_QP:
1719 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
1720 if (!list_empty(&ucontext->qp_reg_mem_list))
1721 list_del(&iwpbl->list);
1722 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
1723 break;
1724 default:
1725 break;
1726 }
1727}
1728
1729/**
1730 * i40iw_dereg_mr - deregister mr
1731 * @ib_mr: mr ptr for dereg
1732 */
1733static int i40iw_dereg_mr(struct ib_mr *ib_mr)
1734{
1735 struct ib_pd *ibpd = ib_mr->pd;
1736 struct i40iw_pd *iwpd = to_iwpd(ibpd);
1737 struct i40iw_mr *iwmr = to_iwmr(ib_mr);
1738 struct i40iw_device *iwdev = to_iwdev(ib_mr->device);
1739 enum i40iw_status_code status;
1740 struct i40iw_dealloc_stag_info *info;
1741 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1742 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1743 struct i40iw_cqp_request *cqp_request;
1744 struct cqp_commands_info *cqp_info;
1745 u32 stag_idx;
1746
1747 if (iwmr->region)
1748 ib_umem_release(iwmr->region);
1749
1750 if (iwmr->type != IW_MEMREG_TYPE_MEM) {
1751 if (ibpd->uobject) {
1752 struct i40iw_ucontext *ucontext;
1753
1754 ucontext = to_ucontext(ibpd->uobject->context);
1755 i40iw_del_memlist(iwmr, ucontext);
1756 }
1757 if (iwpbl->pbl_allocated)
1758 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1759 kfree(iwpbl->iwmr);
1760 iwpbl->iwmr = NULL;
1761 return 0;
1762 }
1763
1764 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1765 if (!cqp_request)
1766 return -ENOMEM;
1767
1768 cqp_info = &cqp_request->info;
1769 info = &cqp_info->in.u.dealloc_stag.info;
1770 memset(info, 0, sizeof(*info));
1771
1772 info->pd_id = cpu_to_le32(iwpd->sc_pd.pd_id & 0x00007fff);
1773 info->stag_idx = RS_64_1(ib_mr->rkey, I40IW_CQPSQ_STAG_IDX_SHIFT);
1774 stag_idx = info->stag_idx;
1775 info->mr = true;
1776 if (iwpbl->pbl_allocated)
1777 info->dealloc_pbl = true;
1778
1779 cqp_info->cqp_cmd = OP_DEALLOC_STAG;
1780 cqp_info->post_sq = 1;
1781 cqp_info->in.u.dealloc_stag.dev = &iwdev->sc_dev;
1782 cqp_info->in.u.dealloc_stag.scratch = (uintptr_t)cqp_request;
1783 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1784 if (status)
1785 i40iw_pr_err("CQP-OP dealloc failed for stag_idx = 0x%x\n", stag_idx);
1786 i40iw_rem_pdusecount(iwpd, iwdev);
1787 i40iw_free_stag(iwdev, iwmr->stag);
1788 if (iwpbl->pbl_allocated)
1789 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1790 kfree(iwmr);
1791 return 0;
1792}
1793
1794/**
1795 * i40iw_show_rev
1796 */
1797static ssize_t i40iw_show_rev(struct device *dev,
1798 struct device_attribute *attr, char *buf)
1799{
1800 struct i40iw_ib_device *iwibdev = container_of(dev,
1801 struct i40iw_ib_device,
1802 ibdev.dev);
1803 u32 hw_rev = iwibdev->iwdev->sc_dev.hw_rev;
1804
1805 return sprintf(buf, "%x\n", hw_rev);
1806}
1807
1808/**
1809 * i40iw_show_fw_ver
1810 */
1811static ssize_t i40iw_show_fw_ver(struct device *dev,
1812 struct device_attribute *attr, char *buf)
1813{
1814 u32 firmware_version = I40IW_FW_VERSION;
1815
1816 return sprintf(buf, "%u.%u\n", firmware_version,
1817 (firmware_version & 0x000000ff));
1818}
1819
1820/**
1821 * i40iw_show_hca
1822 */
1823static ssize_t i40iw_show_hca(struct device *dev,
1824 struct device_attribute *attr, char *buf)
1825{
1826 return sprintf(buf, "I40IW\n");
1827}
1828
1829/**
1830 * i40iw_show_board
1831 */
1832static ssize_t i40iw_show_board(struct device *dev,
1833 struct device_attribute *attr,
1834 char *buf)
1835{
1836 return sprintf(buf, "%.*s\n", 32, "I40IW Board ID");
1837}
1838
1839static DEVICE_ATTR(hw_rev, S_IRUGO, i40iw_show_rev, NULL);
1840static DEVICE_ATTR(fw_ver, S_IRUGO, i40iw_show_fw_ver, NULL);
1841static DEVICE_ATTR(hca_type, S_IRUGO, i40iw_show_hca, NULL);
1842static DEVICE_ATTR(board_id, S_IRUGO, i40iw_show_board, NULL);
1843
1844static struct device_attribute *i40iw_dev_attributes[] = {
1845 &dev_attr_hw_rev,
1846 &dev_attr_fw_ver,
1847 &dev_attr_hca_type,
1848 &dev_attr_board_id
1849};
1850
1851/**
1852 * i40iw_copy_sg_list - copy sg list for qp
1853 * @sg_list: copied into sg_list
1854 * @sgl: copy from sgl
1855 * @num_sges: count of sg entries
1856 */
1857static void i40iw_copy_sg_list(struct i40iw_sge *sg_list, struct ib_sge *sgl, int num_sges)
1858{
1859 unsigned int i;
1860
1861 for (i = 0; (i < num_sges) && (i < I40IW_MAX_WQ_FRAGMENT_COUNT); i++) {
1862 sg_list[i].tag_off = sgl[i].addr;
1863 sg_list[i].len = sgl[i].length;
1864 sg_list[i].stag = sgl[i].lkey;
1865 }
1866}
1867
1868/**
1869 * i40iw_post_send - kernel application wr
1870 * @ibqp: qp ptr for wr
1871 * @ib_wr: work request ptr
1872 * @bad_wr: return of bad wr if err
1873 */
1874static int i40iw_post_send(struct ib_qp *ibqp,
1875 struct ib_send_wr *ib_wr,
1876 struct ib_send_wr **bad_wr)
1877{
1878 struct i40iw_qp *iwqp;
1879 struct i40iw_qp_uk *ukqp;
1880 struct i40iw_post_sq_info info;
1881 enum i40iw_status_code ret;
1882 int err = 0;
1883 unsigned long flags;
1884
1885 iwqp = (struct i40iw_qp *)ibqp;
1886 ukqp = &iwqp->sc_qp.qp_uk;
1887
1888 spin_lock_irqsave(&iwqp->lock, flags);
1889 while (ib_wr) {
1890 memset(&info, 0, sizeof(info));
1891 info.wr_id = (u64)(ib_wr->wr_id);
1892 if ((ib_wr->send_flags & IB_SEND_SIGNALED) || iwqp->sig_all)
1893 info.signaled = true;
1894 if (ib_wr->send_flags & IB_SEND_FENCE)
1895 info.read_fence = true;
1896
1897 switch (ib_wr->opcode) {
1898 case IB_WR_SEND:
1899 if (ib_wr->send_flags & IB_SEND_SOLICITED)
1900 info.op_type = I40IW_OP_TYPE_SEND_SOL;
1901 else
1902 info.op_type = I40IW_OP_TYPE_SEND;
1903
1904 if (ib_wr->send_flags & IB_SEND_INLINE) {
1905 info.op.inline_send.data = (void *)(unsigned long)ib_wr->sg_list[0].addr;
1906 info.op.inline_send.len = ib_wr->sg_list[0].length;
1907 ret = ukqp->ops.iw_inline_send(ukqp, &info, rdma_wr(ib_wr)->rkey, false);
1908 } else {
1909 info.op.send.num_sges = ib_wr->num_sge;
1910 info.op.send.sg_list = (struct i40iw_sge *)ib_wr->sg_list;
1911 ret = ukqp->ops.iw_send(ukqp, &info, rdma_wr(ib_wr)->rkey, false);
1912 }
1913
1914 if (ret)
1915 err = -EIO;
1916 break;
1917 case IB_WR_RDMA_WRITE:
1918 info.op_type = I40IW_OP_TYPE_RDMA_WRITE;
1919
1920 if (ib_wr->send_flags & IB_SEND_INLINE) {
1921 info.op.inline_rdma_write.data = (void *)(unsigned long)ib_wr->sg_list[0].addr;
1922 info.op.inline_rdma_write.len = ib_wr->sg_list[0].length;
1923 info.op.inline_rdma_write.rem_addr.tag_off = rdma_wr(ib_wr)->remote_addr;
1924 info.op.inline_rdma_write.rem_addr.stag = rdma_wr(ib_wr)->rkey;
1925 info.op.inline_rdma_write.rem_addr.len = ib_wr->sg_list->length;
1926 ret = ukqp->ops.iw_inline_rdma_write(ukqp, &info, false);
1927 } else {
1928 info.op.rdma_write.lo_sg_list = (void *)ib_wr->sg_list;
1929 info.op.rdma_write.num_lo_sges = ib_wr->num_sge;
1930 info.op.rdma_write.rem_addr.tag_off = rdma_wr(ib_wr)->remote_addr;
1931 info.op.rdma_write.rem_addr.stag = rdma_wr(ib_wr)->rkey;
1932 info.op.rdma_write.rem_addr.len = ib_wr->sg_list->length;
1933 ret = ukqp->ops.iw_rdma_write(ukqp, &info, false);
1934 }
1935
1936 if (ret)
1937 err = -EIO;
1938 break;
1939 case IB_WR_RDMA_READ:
1940 info.op_type = I40IW_OP_TYPE_RDMA_READ;
1941 info.op.rdma_read.rem_addr.tag_off = rdma_wr(ib_wr)->remote_addr;
1942 info.op.rdma_read.rem_addr.stag = rdma_wr(ib_wr)->rkey;
1943 info.op.rdma_read.rem_addr.len = ib_wr->sg_list->length;
1944 info.op.rdma_read.lo_addr.tag_off = ib_wr->sg_list->addr;
1945 info.op.rdma_read.lo_addr.stag = ib_wr->sg_list->lkey;
1946 info.op.rdma_read.lo_addr.len = ib_wr->sg_list->length;
1947 ret = ukqp->ops.iw_rdma_read(ukqp, &info, false, false);
1948 if (ret)
1949 err = -EIO;
1950 break;
1951 default:
1952 err = -EINVAL;
1953 i40iw_pr_err(" upost_send bad opcode = 0x%x\n",
1954 ib_wr->opcode);
1955 break;
1956 }
1957
1958 if (err)
1959 break;
1960 ib_wr = ib_wr->next;
1961 }
1962
1963 if (err)
1964 *bad_wr = ib_wr;
1965 else
1966 ukqp->ops.iw_qp_post_wr(ukqp);
1967 spin_unlock_irqrestore(&iwqp->lock, flags);
1968
1969 return err;
1970}
1971
1972/**
1973 * i40iw_post_recv - post receive wr for kernel application
1974 * @ibqp: ib qp pointer
1975 * @ib_wr: work request for receive
1976 * @bad_wr: bad wr caused an error
1977 */
1978static int i40iw_post_recv(struct ib_qp *ibqp,
1979 struct ib_recv_wr *ib_wr,
1980 struct ib_recv_wr **bad_wr)
1981{
1982 struct i40iw_qp *iwqp;
1983 struct i40iw_qp_uk *ukqp;
1984 struct i40iw_post_rq_info post_recv;
1985 struct i40iw_sge sg_list[I40IW_MAX_WQ_FRAGMENT_COUNT];
1986 enum i40iw_status_code ret = 0;
1987 unsigned long flags;
1988
1989 iwqp = (struct i40iw_qp *)ibqp;
1990 ukqp = &iwqp->sc_qp.qp_uk;
1991
1992 memset(&post_recv, 0, sizeof(post_recv));
1993 spin_lock_irqsave(&iwqp->lock, flags);
1994 while (ib_wr) {
1995 post_recv.num_sges = ib_wr->num_sge;
1996 post_recv.wr_id = ib_wr->wr_id;
1997 i40iw_copy_sg_list(sg_list, ib_wr->sg_list, ib_wr->num_sge);
1998 post_recv.sg_list = sg_list;
1999 ret = ukqp->ops.iw_post_receive(ukqp, &post_recv);
2000 if (ret) {
2001 i40iw_pr_err(" post_recv err %d\n", ret);
2002 *bad_wr = ib_wr;
2003 goto out;
2004 }
2005 ib_wr = ib_wr->next;
2006 }
2007 out:
2008 spin_unlock_irqrestore(&iwqp->lock, flags);
2009 if (ret)
2010 return -ENOSYS;
2011 return 0;
2012}
2013
2014/**
2015 * i40iw_poll_cq - poll cq for completion (kernel apps)
2016 * @ibcq: cq to poll
2017 * @num_entries: number of entries to poll
2018 * @entry: wr of entry completed
2019 */
2020static int i40iw_poll_cq(struct ib_cq *ibcq,
2021 int num_entries,
2022 struct ib_wc *entry)
2023{
2024 struct i40iw_cq *iwcq;
2025 int cqe_count = 0;
2026 struct i40iw_cq_poll_info cq_poll_info;
2027 enum i40iw_status_code ret;
2028 struct i40iw_cq_uk *ukcq;
2029 struct i40iw_sc_qp *qp;
2030 unsigned long flags;
2031
2032 iwcq = (struct i40iw_cq *)ibcq;
2033 ukcq = &iwcq->sc_cq.cq_uk;
2034
2035 spin_lock_irqsave(&iwcq->lock, flags);
2036 while (cqe_count < num_entries) {
2037 ret = ukcq->ops.iw_cq_poll_completion(ukcq, &cq_poll_info, true);
2038 if (ret == I40IW_ERR_QUEUE_EMPTY) {
2039 break;
2040 } else if (ret) {
2041 if (!cqe_count)
2042 cqe_count = -1;
2043 break;
2044 }
2045 entry->wc_flags = 0;
2046 entry->wr_id = cq_poll_info.wr_id;
2047 if (!cq_poll_info.error)
2048 entry->status = IB_WC_SUCCESS;
2049 else
2050 entry->status = IB_WC_WR_FLUSH_ERR;
2051
2052 switch (cq_poll_info.op_type) {
2053 case I40IW_OP_TYPE_RDMA_WRITE:
2054 entry->opcode = IB_WC_RDMA_WRITE;
2055 break;
2056 case I40IW_OP_TYPE_RDMA_READ_INV_STAG:
2057 case I40IW_OP_TYPE_RDMA_READ:
2058 entry->opcode = IB_WC_RDMA_READ;
2059 break;
2060 case I40IW_OP_TYPE_SEND_SOL:
2061 case I40IW_OP_TYPE_SEND_SOL_INV:
2062 case I40IW_OP_TYPE_SEND_INV:
2063 case I40IW_OP_TYPE_SEND:
2064 entry->opcode = IB_WC_SEND;
2065 break;
2066 case I40IW_OP_TYPE_REC:
2067 entry->opcode = IB_WC_RECV;
2068 break;
2069 default:
2070 entry->opcode = IB_WC_RECV;
2071 break;
2072 }
2073
2074 entry->vendor_err =
2075 cq_poll_info.major_err << 16 | cq_poll_info.minor_err;
2076 entry->ex.imm_data = 0;
2077 qp = (struct i40iw_sc_qp *)cq_poll_info.qp_handle;
2078 entry->qp = (struct ib_qp *)qp->back_qp;
2079 entry->src_qp = cq_poll_info.qp_id;
2080 entry->byte_len = cq_poll_info.bytes_xfered;
2081 entry++;
2082 cqe_count++;
2083 }
2084 spin_unlock_irqrestore(&iwcq->lock, flags);
2085 return cqe_count;
2086}
2087
2088/**
2089 * i40iw_req_notify_cq - arm cq kernel application
2090 * @ibcq: cq to arm
2091 * @notify_flags: notofication flags
2092 */
2093static int i40iw_req_notify_cq(struct ib_cq *ibcq,
2094 enum ib_cq_notify_flags notify_flags)
2095{
2096 struct i40iw_cq *iwcq;
2097 struct i40iw_cq_uk *ukcq;
2098 enum i40iw_completion_notify cq_notify = IW_CQ_COMPL_SOLICITED;
2099
2100 iwcq = (struct i40iw_cq *)ibcq;
2101 ukcq = &iwcq->sc_cq.cq_uk;
2102 if (notify_flags == IB_CQ_NEXT_COMP)
2103 cq_notify = IW_CQ_COMPL_EVENT;
2104 ukcq->ops.iw_cq_request_notification(ukcq, cq_notify);
2105 return 0;
2106}
2107
2108/**
2109 * i40iw_port_immutable - return port's immutable data
2110 * @ibdev: ib dev struct
2111 * @port_num: port number
2112 * @immutable: immutable data for the port return
2113 */
2114static int i40iw_port_immutable(struct ib_device *ibdev, u8 port_num,
2115 struct ib_port_immutable *immutable)
2116{
2117 struct ib_port_attr attr;
2118 int err;
2119
2120 err = i40iw_query_port(ibdev, port_num, &attr);
2121
2122 if (err)
2123 return err;
2124
2125 immutable->pkey_tbl_len = attr.pkey_tbl_len;
2126 immutable->gid_tbl_len = attr.gid_tbl_len;
2127 immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
2128
2129 return 0;
2130}
2131
2132/**
2133 * i40iw_get_protocol_stats - Populates the rdma_stats structure
2134 * @ibdev: ib dev struct
2135 * @stats: iw protocol stats struct
2136 */
2137static int i40iw_get_protocol_stats(struct ib_device *ibdev,
2138 union rdma_protocol_stats *stats)
2139{
2140 struct i40iw_device *iwdev = to_iwdev(ibdev);
2141 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
2142 struct i40iw_dev_pestat *devstat = &dev->dev_pestat;
2143 struct i40iw_dev_hw_stats *hw_stats = &devstat->hw_stats;
2144 struct timespec curr_time;
2145 static struct timespec last_rd_time = {0, 0};
2146 enum i40iw_status_code status = 0;
2147 unsigned long flags;
2148
2149 curr_time = current_kernel_time();
2150 memset(stats, 0, sizeof(*stats));
2151
2152 if (dev->is_pf) {
2153 spin_lock_irqsave(&devstat->stats_lock, flags);
2154 devstat->ops.iw_hw_stat_read_all(devstat,
2155 &devstat->hw_stats);
2156 spin_unlock_irqrestore(&devstat->stats_lock, flags);
2157 } else {
2158 if (((u64)curr_time.tv_sec - (u64)last_rd_time.tv_sec) > 1)
2159 status = i40iw_vchnl_vf_get_pe_stats(dev,
2160 &devstat->hw_stats);
2161
2162 if (status)
2163 return -ENOSYS;
2164 }
2165
2166 stats->iw.ipInReceives = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] +
2167 hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6RXPKTS];
2168 stats->iw.ipInTruncatedPkts = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] +
2169 hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC];
2170 stats->iw.ipInDiscards = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] +
2171 hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD];
2172 stats->iw.ipOutNoRoutes = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] +
2173 hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE];
2174 stats->iw.ipReasmReqds = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] +
2175 hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS];
2176 stats->iw.ipFragCreates = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] +
2177 hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS];
2178 stats->iw.ipInMcastPkts = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] +
2179 hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS];
2180 stats->iw.ipOutMcastPkts = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] +
2181 hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6TXMCPKTS];
2182 stats->iw.tcpOutSegs = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_TCPTXSEG];
2183 stats->iw.tcpInSegs = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_TCPRXSEGS];
2184 stats->iw.tcpRetransSegs = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_TCPRTXSEG];
2185
2186 last_rd_time = curr_time;
2187 return 0;
2188}
2189
2190/**
2191 * i40iw_query_gid - Query port GID
2192 * @ibdev: device pointer from stack
2193 * @port: port number
2194 * @index: Entry index
2195 * @gid: Global ID
2196 */
2197static int i40iw_query_gid(struct ib_device *ibdev,
2198 u8 port,
2199 int index,
2200 union ib_gid *gid)
2201{
2202 struct i40iw_device *iwdev = to_iwdev(ibdev);
2203
2204 memset(gid->raw, 0, sizeof(gid->raw));
2205 ether_addr_copy(gid->raw, iwdev->netdev->dev_addr);
2206 return 0;
2207}
2208
2209/**
2210 * i40iw_modify_port Modify port properties
2211 * @ibdev: device pointer from stack
2212 * @port: port number
2213 * @port_modify_mask: mask for port modifications
2214 * @props: port properties
2215 */
2216static int i40iw_modify_port(struct ib_device *ibdev,
2217 u8 port,
2218 int port_modify_mask,
2219 struct ib_port_modify *props)
2220{
2221 return 0;
2222}
2223
2224/**
2225 * i40iw_query_pkey - Query partition key
2226 * @ibdev: device pointer from stack
2227 * @port: port number
2228 * @index: index of pkey
2229 * @pkey: pointer to store the pkey
2230 */
2231static int i40iw_query_pkey(struct ib_device *ibdev,
2232 u8 port,
2233 u16 index,
2234 u16 *pkey)
2235{
2236 *pkey = 0;
2237 return 0;
2238}
2239
2240/**
2241 * i40iw_create_ah - create address handle
2242 * @ibpd: ptr of pd
2243 * @ah_attr: address handle attributes
2244 */
2245static struct ib_ah *i40iw_create_ah(struct ib_pd *ibpd,
2246 struct ib_ah_attr *attr)
2247{
2248 return ERR_PTR(-ENOSYS);
2249}
2250
2251/**
2252 * i40iw_destroy_ah - Destroy address handle
2253 * @ah: pointer to address handle
2254 */
2255static int i40iw_destroy_ah(struct ib_ah *ah)
2256{
2257 return -ENOSYS;
2258}
2259
2260/**
2261 * i40iw_init_rdma_device - initialization of iwarp device
2262 * @iwdev: iwarp device
2263 */
2264static struct i40iw_ib_device *i40iw_init_rdma_device(struct i40iw_device *iwdev)
2265{
2266 struct i40iw_ib_device *iwibdev;
2267 struct net_device *netdev = iwdev->netdev;
2268 struct pci_dev *pcidev = (struct pci_dev *)iwdev->hw.dev_context;
2269
2270 iwibdev = (struct i40iw_ib_device *)ib_alloc_device(sizeof(*iwibdev));
2271 if (!iwibdev) {
2272 i40iw_pr_err("iwdev == NULL\n");
2273 return NULL;
2274 }
2275 strlcpy(iwibdev->ibdev.name, "i40iw%d", IB_DEVICE_NAME_MAX);
2276 iwibdev->ibdev.owner = THIS_MODULE;
2277 iwdev->iwibdev = iwibdev;
2278 iwibdev->iwdev = iwdev;
2279
2280 iwibdev->ibdev.node_type = RDMA_NODE_RNIC;
2281 ether_addr_copy((u8 *)&iwibdev->ibdev.node_guid, netdev->dev_addr);
2282
2283 iwibdev->ibdev.uverbs_cmd_mask =
2284 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
2285 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
2286 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
2287 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
2288 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
2289 (1ull << IB_USER_VERBS_CMD_REG_MR) |
2290 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
2291 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
2292 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
2293 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
2294 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
2295 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
2296 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
2297 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
2298 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
2299 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
2300 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
2301 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
2302 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
2303 (1ull << IB_USER_VERBS_CMD_POST_SEND);
2304 iwibdev->ibdev.phys_port_cnt = 1;
2305 iwibdev->ibdev.num_comp_vectors = 1;
2306 iwibdev->ibdev.dma_device = &pcidev->dev;
2307 iwibdev->ibdev.dev.parent = &pcidev->dev;
2308 iwibdev->ibdev.query_port = i40iw_query_port;
2309 iwibdev->ibdev.modify_port = i40iw_modify_port;
2310 iwibdev->ibdev.query_pkey = i40iw_query_pkey;
2311 iwibdev->ibdev.query_gid = i40iw_query_gid;
2312 iwibdev->ibdev.alloc_ucontext = i40iw_alloc_ucontext;
2313 iwibdev->ibdev.dealloc_ucontext = i40iw_dealloc_ucontext;
2314 iwibdev->ibdev.mmap = i40iw_mmap;
2315 iwibdev->ibdev.alloc_pd = i40iw_alloc_pd;
2316 iwibdev->ibdev.dealloc_pd = i40iw_dealloc_pd;
2317 iwibdev->ibdev.create_qp = i40iw_create_qp;
2318 iwibdev->ibdev.modify_qp = i40iw_modify_qp;
2319 iwibdev->ibdev.query_qp = i40iw_query_qp;
2320 iwibdev->ibdev.destroy_qp = i40iw_destroy_qp;
2321 iwibdev->ibdev.create_cq = i40iw_create_cq;
2322 iwibdev->ibdev.destroy_cq = i40iw_destroy_cq;
2323 iwibdev->ibdev.get_dma_mr = i40iw_get_dma_mr;
2324 iwibdev->ibdev.reg_user_mr = i40iw_reg_user_mr;
2325 iwibdev->ibdev.dereg_mr = i40iw_dereg_mr;
2326 iwibdev->ibdev.get_protocol_stats = i40iw_get_protocol_stats;
2327 iwibdev->ibdev.query_device = i40iw_query_device;
2328 iwibdev->ibdev.create_ah = i40iw_create_ah;
2329 iwibdev->ibdev.destroy_ah = i40iw_destroy_ah;
2330 iwibdev->ibdev.iwcm = kzalloc(sizeof(*iwibdev->ibdev.iwcm), GFP_KERNEL);
2331 if (!iwibdev->ibdev.iwcm) {
2332 ib_dealloc_device(&iwibdev->ibdev);
2333 i40iw_pr_err("iwcm == NULL\n");
2334 return NULL;
2335 }
2336
2337 iwibdev->ibdev.iwcm->add_ref = i40iw_add_ref;
2338 iwibdev->ibdev.iwcm->rem_ref = i40iw_rem_ref;
2339 iwibdev->ibdev.iwcm->get_qp = i40iw_get_qp;
2340 iwibdev->ibdev.iwcm->connect = i40iw_connect;
2341 iwibdev->ibdev.iwcm->accept = i40iw_accept;
2342 iwibdev->ibdev.iwcm->reject = i40iw_reject;
2343 iwibdev->ibdev.iwcm->create_listen = i40iw_create_listen;
2344 iwibdev->ibdev.iwcm->destroy_listen = i40iw_destroy_listen;
2345 memcpy(iwibdev->ibdev.iwcm->ifname, netdev->name,
2346 sizeof(iwibdev->ibdev.iwcm->ifname));
2347 iwibdev->ibdev.get_port_immutable = i40iw_port_immutable;
2348 iwibdev->ibdev.poll_cq = i40iw_poll_cq;
2349 iwibdev->ibdev.req_notify_cq = i40iw_req_notify_cq;
2350 iwibdev->ibdev.post_send = i40iw_post_send;
2351 iwibdev->ibdev.post_recv = i40iw_post_recv;
2352
2353 return iwibdev;
2354}
2355
2356/**
2357 * i40iw_port_ibevent - indicate port event
2358 * @iwdev: iwarp device
2359 */
2360void i40iw_port_ibevent(struct i40iw_device *iwdev)
2361{
2362 struct i40iw_ib_device *iwibdev = iwdev->iwibdev;
2363 struct ib_event event;
2364
2365 event.device = &iwibdev->ibdev;
2366 event.element.port_num = 1;
2367 event.event = iwdev->iw_status ? IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
2368 ib_dispatch_event(&event);
2369}
2370
2371/**
2372 * i40iw_unregister_rdma_device - unregister of iwarp from IB
2373 * @iwibdev: rdma device ptr
2374 */
2375static void i40iw_unregister_rdma_device(struct i40iw_ib_device *iwibdev)
2376{
2377 int i;
2378
2379 for (i = 0; i < ARRAY_SIZE(i40iw_dev_attributes); ++i)
2380 device_remove_file(&iwibdev->ibdev.dev,
2381 i40iw_dev_attributes[i]);
2382 ib_unregister_device(&iwibdev->ibdev);
2383}
2384
2385/**
2386 * i40iw_destroy_rdma_device - destroy rdma device and free resources
2387 * @iwibdev: IB device ptr
2388 */
2389void i40iw_destroy_rdma_device(struct i40iw_ib_device *iwibdev)
2390{
2391 if (!iwibdev)
2392 return;
2393
2394 i40iw_unregister_rdma_device(iwibdev);
2395 kfree(iwibdev->ibdev.iwcm);
2396 iwibdev->ibdev.iwcm = NULL;
2397 ib_dealloc_device(&iwibdev->ibdev);
2398}
2399
2400/**
2401 * i40iw_register_rdma_device - register iwarp device to IB
2402 * @iwdev: iwarp device
2403 */
2404int i40iw_register_rdma_device(struct i40iw_device *iwdev)
2405{
2406 int i, ret;
2407 struct i40iw_ib_device *iwibdev;
2408
2409 iwdev->iwibdev = i40iw_init_rdma_device(iwdev);
2410 if (!iwdev->iwibdev)
2411 return -ENOSYS;
2412 iwibdev = iwdev->iwibdev;
2413
2414 ret = ib_register_device(&iwibdev->ibdev, NULL);
2415 if (ret)
2416 goto error;
2417
2418 for (i = 0; i < ARRAY_SIZE(i40iw_dev_attributes); ++i) {
2419 ret =
2420 device_create_file(&iwibdev->ibdev.dev,
2421 i40iw_dev_attributes[i]);
2422 if (ret) {
2423 while (i > 0) {
2424 i--;
2425 device_remove_file(&iwibdev->ibdev.dev, i40iw_dev_attributes[i]);
2426 }
2427 ib_unregister_device(&iwibdev->ibdev);
2428 goto error;
2429 }
2430 }
2431 return 0;
2432error:
2433 kfree(iwdev->iwibdev->ibdev.iwcm);
2434 iwdev->iwibdev->ibdev.iwcm = NULL;
2435 ib_dealloc_device(&iwdev->iwibdev->ibdev);
2436 return -ENOSYS;
2437}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.h b/drivers/infiniband/hw/i40iw/i40iw_verbs.h
new file mode 100644
index 000000000000..1101f77080e6
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.h
@@ -0,0 +1,173 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_VERBS_H
36#define I40IW_VERBS_H
37
38struct i40iw_ucontext {
39 struct ib_ucontext ibucontext;
40 struct i40iw_device *iwdev;
41 struct list_head cq_reg_mem_list;
42 spinlock_t cq_reg_mem_list_lock; /* memory list for cq's */
43 struct list_head qp_reg_mem_list;
44 spinlock_t qp_reg_mem_list_lock; /* memory list for qp's */
45};
46
47struct i40iw_pd {
48 struct ib_pd ibpd;
49 struct i40iw_sc_pd sc_pd;
50 atomic_t usecount;
51};
52
53struct i40iw_hmc_pble {
54 union {
55 u32 idx;
56 dma_addr_t addr;
57 };
58};
59
60struct i40iw_cq_mr {
61 struct i40iw_hmc_pble cq_pbl;
62 dma_addr_t shadow;
63};
64
65struct i40iw_qp_mr {
66 struct i40iw_hmc_pble sq_pbl;
67 struct i40iw_hmc_pble rq_pbl;
68 dma_addr_t shadow;
69 struct page *sq_page;
70};
71
72struct i40iw_pbl {
73 struct list_head list;
74 union {
75 struct i40iw_qp_mr qp_mr;
76 struct i40iw_cq_mr cq_mr;
77 };
78
79 bool pbl_allocated;
80 u64 user_base;
81 struct i40iw_pble_alloc pble_alloc;
82 struct i40iw_mr *iwmr;
83};
84
85#define MAX_SAVE_PAGE_ADDRS 4
86struct i40iw_mr {
87 union {
88 struct ib_mr ibmr;
89 struct ib_mw ibmw;
90 struct ib_fmr ibfmr;
91 };
92 struct ib_umem *region;
93 u16 type;
94 u32 page_cnt;
95 u32 stag;
96 u64 length;
97 u64 pgaddrmem[MAX_SAVE_PAGE_ADDRS];
98 struct i40iw_pbl iwpbl;
99};
100
101struct i40iw_cq {
102 struct ib_cq ibcq;
103 struct i40iw_sc_cq sc_cq;
104 u16 cq_head;
105 u16 cq_size;
106 u16 cq_number;
107 bool user_mode;
108 u32 polled_completions;
109 u32 cq_mem_size;
110 struct i40iw_dma_mem kmem;
111 spinlock_t lock; /* for poll cq */
112 struct i40iw_pbl *iwpbl;
113};
114
115struct disconn_work {
116 struct work_struct work;
117 struct i40iw_qp *iwqp;
118};
119
120struct iw_cm_id;
121struct ietf_mpa_frame;
122struct i40iw_ud_file;
123
124struct i40iw_qp_kmode {
125 struct i40iw_dma_mem dma_mem;
126 u64 *wrid_mem;
127};
128
129struct i40iw_qp {
130 struct ib_qp ibqp;
131 struct i40iw_sc_qp sc_qp;
132 struct i40iw_device *iwdev;
133 struct i40iw_cq *iwscq;
134 struct i40iw_cq *iwrcq;
135 struct i40iw_pd *iwpd;
136 struct i40iw_qp_host_ctx_info ctx_info;
137 struct i40iwarp_offload_info iwarp_info;
138 void *allocated_buffer;
139 atomic_t refcount;
140 struct iw_cm_id *cm_id;
141 void *cm_node;
142 struct ib_mr *lsmm_mr;
143 struct work_struct work;
144 enum ib_qp_state ibqp_state;
145 u32 iwarp_state;
146 u32 qp_mem_size;
147 u32 last_aeq;
148 atomic_t close_timer_started;
149 spinlock_t lock; /* for post work requests */
150 struct i40iw_qp_context *iwqp_context;
151 void *pbl_vbase;
152 dma_addr_t pbl_pbase;
153 struct page *page;
154 u8 active_conn:1;
155 u8 user_mode:1;
156 u8 hte_added:1;
157 u8 flush_issued:1;
158 u8 destroyed:1;
159 u8 sig_all:1;
160 u8 pau_mode:1;
161 u8 rsvd:1;
162 u16 term_sq_flush_code;
163 u16 term_rq_flush_code;
164 u8 hw_iwarp_state;
165 u8 hw_tcp_state;
166 struct i40iw_qp_kmode kqp;
167 struct i40iw_dma_mem host_ctx;
168 struct timer_list terminate_timer;
169 struct i40iw_pbl *iwpbl;
170 struct i40iw_dma_mem q2_ctx_mem;
171 struct i40iw_dma_mem ietf_mem;
172};
173#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_vf.c b/drivers/infiniband/hw/i40iw/i40iw_vf.c
new file mode 100644
index 000000000000..cb0f18340e14
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_vf.c
@@ -0,0 +1,85 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_osdep.h"
36#include "i40iw_register.h"
37#include "i40iw_status.h"
38#include "i40iw_hmc.h"
39#include "i40iw_d.h"
40#include "i40iw_type.h"
41#include "i40iw_p.h"
42#include "i40iw_vf.h"
43
44/**
45 * i40iw_manage_vf_pble_bp - manage vf pble
46 * @cqp: cqp for cqp' sq wqe
47 * @info: pble info
48 * @scratch: pointer for completion
49 * @post_sq: to post and ring
50 */
51enum i40iw_status_code i40iw_manage_vf_pble_bp(struct i40iw_sc_cqp *cqp,
52 struct i40iw_manage_vf_pble_info *info,
53 u64 scratch,
54 bool post_sq)
55{
56 u64 *wqe;
57 u64 temp, header, pd_pl_pba = 0;
58
59 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
60 if (!wqe)
61 return I40IW_ERR_RING_FULL;
62
63 temp = LS_64(info->pd_entry_cnt, I40IW_CQPSQ_MVPBP_PD_ENTRY_CNT) |
64 LS_64(info->first_pd_index, I40IW_CQPSQ_MVPBP_FIRST_PD_INX) |
65 LS_64(info->sd_index, I40IW_CQPSQ_MVPBP_SD_INX);
66 set_64bit_val(wqe, 16, temp);
67
68 header = LS_64((info->inv_pd_ent ? 1 : 0), I40IW_CQPSQ_MVPBP_INV_PD_ENT) |
69 LS_64(I40IW_CQP_OP_MANAGE_VF_PBLE_BP, I40IW_CQPSQ_OPCODE) |
70 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
71 set_64bit_val(wqe, 24, header);
72
73 pd_pl_pba = LS_64(info->pd_pl_pba >> 3, I40IW_CQPSQ_MVPBP_PD_PLPBA);
74 set_64bit_val(wqe, 32, pd_pl_pba);
75
76 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE VF_PBLE_BP WQE", wqe, I40IW_CQP_WQE_SIZE * 8);
77
78 if (post_sq)
79 i40iw_sc_cqp_post_sq(cqp);
80 return 0;
81}
82
83struct i40iw_vf_cqp_ops iw_vf_cqp_ops = {
84 i40iw_manage_vf_pble_bp
85};
diff --git a/drivers/infiniband/hw/i40iw/i40iw_vf.h b/drivers/infiniband/hw/i40iw/i40iw_vf.h
new file mode 100644
index 000000000000..f649f3a62e13
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_vf.h
@@ -0,0 +1,62 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_VF_H
36#define I40IW_VF_H
37
38struct i40iw_sc_cqp;
39
40struct i40iw_manage_vf_pble_info {
41 u32 sd_index;
42 u16 first_pd_index;
43 u16 pd_entry_cnt;
44 u8 inv_pd_ent;
45 u64 pd_pl_pba;
46};
47
48struct i40iw_vf_cqp_ops {
49 enum i40iw_status_code (*manage_vf_pble_bp)(struct i40iw_sc_cqp *,
50 struct i40iw_manage_vf_pble_info *,
51 u64,
52 bool);
53};
54
55enum i40iw_status_code i40iw_manage_vf_pble_bp(struct i40iw_sc_cqp *cqp,
56 struct i40iw_manage_vf_pble_info *info,
57 u64 scratch,
58 bool post_sq);
59
60extern struct i40iw_vf_cqp_ops iw_vf_cqp_ops;
61
62#endif
diff --git a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
new file mode 100644
index 000000000000..6b68f7890b76
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
@@ -0,0 +1,748 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_osdep.h"
36#include "i40iw_register.h"
37#include "i40iw_status.h"
38#include "i40iw_hmc.h"
39#include "i40iw_d.h"
40#include "i40iw_type.h"
41#include "i40iw_p.h"
42#include "i40iw_virtchnl.h"
43
44/**
45 * vchnl_vf_send_get_ver_req - Request Channel version
46 * @dev: IWARP device pointer
47 * @vchnl_req: Virtual channel message request pointer
48 */
49static enum i40iw_status_code vchnl_vf_send_get_ver_req(struct i40iw_sc_dev *dev,
50 struct i40iw_virtchnl_req *vchnl_req)
51{
52 enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
53 struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
54
55 if (!dev->vchnl_up)
56 return ret_code;
57
58 memset(vchnl_msg, 0, sizeof(*vchnl_msg));
59 vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
60 vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg);
61 vchnl_msg->iw_op_code = I40IW_VCHNL_OP_GET_VER;
62 vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_GET_VER_V0;
63 ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
64 if (ret_code)
65 i40iw_debug(dev, I40IW_DEBUG_VIRT,
66 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
67 return ret_code;
68}
69
70/**
71 * vchnl_vf_send_get_hmc_fcn_req - Request HMC Function from VF
72 * @dev: IWARP device pointer
73 * @vchnl_req: Virtual channel message request pointer
74 */
75static enum i40iw_status_code vchnl_vf_send_get_hmc_fcn_req(struct i40iw_sc_dev *dev,
76 struct i40iw_virtchnl_req *vchnl_req)
77{
78 enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
79 struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
80
81 if (!dev->vchnl_up)
82 return ret_code;
83
84 memset(vchnl_msg, 0, sizeof(*vchnl_msg));
85 vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
86 vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg);
87 vchnl_msg->iw_op_code = I40IW_VCHNL_OP_GET_HMC_FCN;
88 vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_GET_HMC_FCN_V0;
89 ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
90 if (ret_code)
91 i40iw_debug(dev, I40IW_DEBUG_VIRT,
92 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
93 return ret_code;
94}
95
96/**
97 * vchnl_vf_send_get_pe_stats_req - Request PE stats from VF
98 * @dev: IWARP device pointer
99 * @vchnl_req: Virtual channel message request pointer
100 */
101static enum i40iw_status_code vchnl_vf_send_get_pe_stats_req(struct i40iw_sc_dev *dev,
102 struct i40iw_virtchnl_req *vchnl_req)
103{
104 enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
105 struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
106
107 if (!dev->vchnl_up)
108 return ret_code;
109
110 memset(vchnl_msg, 0, sizeof(*vchnl_msg));
111 vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
112 vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg) + sizeof(struct i40iw_dev_hw_stats) - 1;
113 vchnl_msg->iw_op_code = I40IW_VCHNL_OP_GET_STATS;
114 vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_GET_STATS_V0;
115 ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
116 if (ret_code)
117 i40iw_debug(dev, I40IW_DEBUG_VIRT,
118 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
119 return ret_code;
120}
121
122/**
123 * vchnl_vf_send_add_hmc_objs_req - Add HMC objects
124 * @dev: IWARP device pointer
125 * @vchnl_req: Virtual channel message request pointer
126 */
127static enum i40iw_status_code vchnl_vf_send_add_hmc_objs_req(struct i40iw_sc_dev *dev,
128 struct i40iw_virtchnl_req *vchnl_req,
129 enum i40iw_hmc_rsrc_type rsrc_type,
130 u32 start_index,
131 u32 rsrc_count)
132{
133 enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
134 struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
135 struct i40iw_virtchnl_hmc_obj_range *add_hmc_obj;
136
137 if (!dev->vchnl_up)
138 return ret_code;
139
140 add_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
141 memset(vchnl_msg, 0, sizeof(*vchnl_msg));
142 memset(add_hmc_obj, 0, sizeof(*add_hmc_obj));
143 vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
144 vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg) + sizeof(struct i40iw_virtchnl_hmc_obj_range) - 1;
145 vchnl_msg->iw_op_code = I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE;
146 vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE_V0;
147 add_hmc_obj->obj_type = (u16)rsrc_type;
148 add_hmc_obj->start_index = start_index;
149 add_hmc_obj->obj_count = rsrc_count;
150 ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
151 if (ret_code)
152 i40iw_debug(dev, I40IW_DEBUG_VIRT,
153 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
154 return ret_code;
155}
156
157/**
158 * vchnl_vf_send_del_hmc_objs_req - del HMC objects
159 * @dev: IWARP device pointer
160 * @vchnl_req: Virtual channel message request pointer
161 * @ rsrc_type - resource type to delete
162 * @ start_index - starting index for resource
163 * @ rsrc_count - number of resource type to delete
164 */
165static enum i40iw_status_code vchnl_vf_send_del_hmc_objs_req(struct i40iw_sc_dev *dev,
166 struct i40iw_virtchnl_req *vchnl_req,
167 enum i40iw_hmc_rsrc_type rsrc_type,
168 u32 start_index,
169 u32 rsrc_count)
170{
171 enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
172 struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
173 struct i40iw_virtchnl_hmc_obj_range *add_hmc_obj;
174
175 if (!dev->vchnl_up)
176 return ret_code;
177
178 add_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
179 memset(vchnl_msg, 0, sizeof(*vchnl_msg));
180 memset(add_hmc_obj, 0, sizeof(*add_hmc_obj));
181 vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
182 vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg) + sizeof(struct i40iw_virtchnl_hmc_obj_range) - 1;
183 vchnl_msg->iw_op_code = I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE;
184 vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE_V0;
185 add_hmc_obj->obj_type = (u16)rsrc_type;
186 add_hmc_obj->start_index = start_index;
187 add_hmc_obj->obj_count = rsrc_count;
188 ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
189 if (ret_code)
190 i40iw_debug(dev, I40IW_DEBUG_VIRT,
191 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
192 return ret_code;
193}
194
195/**
196 * vchnl_pf_send_get_ver_resp - Send channel version to VF
197 * @dev: IWARP device pointer
198 * @vf_id: Virtual function ID associated with the message
199 * @vchnl_msg: Virtual channel message buffer pointer
200 */
201static void vchnl_pf_send_get_ver_resp(struct i40iw_sc_dev *dev,
202 u32 vf_id,
203 struct i40iw_virtchnl_op_buf *vchnl_msg)
204{
205 enum i40iw_status_code ret_code;
206 u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf) + sizeof(u32) - 1];
207 struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
208
209 memset(resp_buffer, 0, sizeof(*resp_buffer));
210 vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
211 vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
212 vchnl_msg_resp->iw_op_ret_code = I40IW_SUCCESS;
213 *((u32 *)vchnl_msg_resp->iw_chnl_buf) = I40IW_VCHNL_CHNL_VER_V0;
214 ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
215 if (ret_code)
216 i40iw_debug(dev, I40IW_DEBUG_VIRT,
217 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
218}
219
220/**
221 * vchnl_pf_send_get_hmc_fcn_resp - Send HMC Function to VF
222 * @dev: IWARP device pointer
223 * @vf_id: Virtual function ID associated with the message
224 * @vchnl_msg: Virtual channel message buffer pointer
225 */
226static void vchnl_pf_send_get_hmc_fcn_resp(struct i40iw_sc_dev *dev,
227 u32 vf_id,
228 struct i40iw_virtchnl_op_buf *vchnl_msg,
229 u16 hmc_fcn)
230{
231 enum i40iw_status_code ret_code;
232 u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf) + sizeof(u16) - 1];
233 struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
234
235 memset(resp_buffer, 0, sizeof(*resp_buffer));
236 vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
237 vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
238 vchnl_msg_resp->iw_op_ret_code = I40IW_SUCCESS;
239 *((u16 *)vchnl_msg_resp->iw_chnl_buf) = hmc_fcn;
240 ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
241 if (ret_code)
242 i40iw_debug(dev, I40IW_DEBUG_VIRT,
243 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
244}
245
246/**
247 * vchnl_pf_send_get_pe_stats_resp - Send PE Stats to VF
248 * @dev: IWARP device pointer
249 * @vf_id: Virtual function ID associated with the message
250 * @vchnl_msg: Virtual channel message buffer pointer
251 * @hw_stats: HW Stats struct
252 */
253
254static void vchnl_pf_send_get_pe_stats_resp(struct i40iw_sc_dev *dev,
255 u32 vf_id,
256 struct i40iw_virtchnl_op_buf *vchnl_msg,
257 struct i40iw_dev_hw_stats hw_stats)
258{
259 enum i40iw_status_code ret_code;
260 u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf) + sizeof(struct i40iw_dev_hw_stats) - 1];
261 struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
262
263 memset(resp_buffer, 0, sizeof(*resp_buffer));
264 vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
265 vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
266 vchnl_msg_resp->iw_op_ret_code = I40IW_SUCCESS;
267 *((struct i40iw_dev_hw_stats *)vchnl_msg_resp->iw_chnl_buf) = hw_stats;
268 ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
269 if (ret_code)
270 i40iw_debug(dev, I40IW_DEBUG_VIRT,
271 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
272}
273
274/**
275 * vchnl_pf_send_error_resp - Send an error response to VF
276 * @dev: IWARP device pointer
277 * @vf_id: Virtual function ID associated with the message
278 * @vchnl_msg: Virtual channel message buffer pointer
279 */
280static void vchnl_pf_send_error_resp(struct i40iw_sc_dev *dev, u32 vf_id,
281 struct i40iw_virtchnl_op_buf *vchnl_msg,
282 u16 op_ret_code)
283{
284 enum i40iw_status_code ret_code;
285 u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf)];
286 struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
287
288 memset(resp_buffer, 0, sizeof(resp_buffer));
289 vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
290 vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
291 vchnl_msg_resp->iw_op_ret_code = (u16)op_ret_code;
292 ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
293 if (ret_code)
294 i40iw_debug(dev, I40IW_DEBUG_VIRT,
295 "%s: virt channel send failed 0x%x\n", __func__, ret_code);
296}
297
298/**
299 * pf_cqp_get_hmc_fcn_callback - Callback for Get HMC Fcn
300 * @cqp_req_param: CQP Request param value
301 * @not_used: unused CQP callback parameter
302 */
303static void pf_cqp_get_hmc_fcn_callback(struct i40iw_sc_dev *dev, void *callback_param,
304 struct i40iw_ccq_cqe_info *cqe_info)
305{
306 struct i40iw_vfdev *vf_dev = callback_param;
307 struct i40iw_virt_mem vf_dev_mem;
308
309 if (cqe_info->error) {
310 i40iw_debug(dev, I40IW_DEBUG_VIRT,
311 "CQP Completion Error on Get HMC Function. Maj = 0x%04x, Minor = 0x%04x\n",
312 cqe_info->maj_err_code, cqe_info->min_err_code);
313 dev->vf_dev[vf_dev->iw_vf_idx] = NULL;
314 vchnl_pf_send_error_resp(dev, vf_dev->vf_id, &vf_dev->vf_msg_buffer.vchnl_msg,
315 (u16)I40IW_ERR_CQP_COMPL_ERROR);
316 vf_dev_mem.va = vf_dev;
317 vf_dev_mem.size = sizeof(*vf_dev);
318 i40iw_free_virt_mem(dev->hw, &vf_dev_mem);
319 } else {
320 i40iw_debug(dev, I40IW_DEBUG_VIRT,
321 "CQP Completion Operation Return information = 0x%08x\n",
322 cqe_info->op_ret_val);
323 vf_dev->pmf_index = (u16)cqe_info->op_ret_val;
324 vf_dev->msg_count--;
325 vchnl_pf_send_get_hmc_fcn_resp(dev,
326 vf_dev->vf_id,
327 &vf_dev->vf_msg_buffer.vchnl_msg,
328 vf_dev->pmf_index);
329 }
330}
331
332/**
333 * pf_add_hmc_obj - Callback for Add HMC Object
334 * @vf_dev: pointer to the VF Device
335 */
336static void pf_add_hmc_obj_callback(void *work_vf_dev)
337{
338 struct i40iw_vfdev *vf_dev = (struct i40iw_vfdev *)work_vf_dev;
339 struct i40iw_hmc_info *hmc_info = &vf_dev->hmc_info;
340 struct i40iw_virtchnl_op_buf *vchnl_msg = &vf_dev->vf_msg_buffer.vchnl_msg;
341 struct i40iw_hmc_create_obj_info info;
342 struct i40iw_virtchnl_hmc_obj_range *add_hmc_obj;
343 enum i40iw_status_code ret_code;
344
345 if (!vf_dev->pf_hmc_initialized) {
346 ret_code = i40iw_pf_init_vfhmc(vf_dev->pf_dev, (u8)vf_dev->pmf_index, NULL);
347 if (ret_code)
348 goto add_out;
349 vf_dev->pf_hmc_initialized = true;
350 }
351
352 add_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
353
354 memset(&info, 0, sizeof(info));
355 info.hmc_info = hmc_info;
356 info.is_pf = false;
357 info.rsrc_type = (u32)add_hmc_obj->obj_type;
358 info.entry_type = (info.rsrc_type == I40IW_HMC_IW_PBLE) ? I40IW_SD_TYPE_PAGED : I40IW_SD_TYPE_DIRECT;
359 info.start_idx = add_hmc_obj->start_index;
360 info.count = add_hmc_obj->obj_count;
361 i40iw_debug(vf_dev->pf_dev, I40IW_DEBUG_VIRT,
362 "I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE. Add %u type %u objects\n",
363 info.count, info.rsrc_type);
364 ret_code = i40iw_sc_create_hmc_obj(vf_dev->pf_dev, &info);
365 if (!ret_code)
366 vf_dev->hmc_info.hmc_obj[add_hmc_obj->obj_type].cnt = add_hmc_obj->obj_count;
367add_out:
368 vf_dev->msg_count--;
369 vchnl_pf_send_error_resp(vf_dev->pf_dev, vf_dev->vf_id, vchnl_msg, (u16)ret_code);
370}
371
372/**
373 * pf_del_hmc_obj_callback - Callback for delete HMC Object
374 * @work_vf_dev: pointer to the VF Device
375 */
376static void pf_del_hmc_obj_callback(void *work_vf_dev)
377{
378 struct i40iw_vfdev *vf_dev = (struct i40iw_vfdev *)work_vf_dev;
379 struct i40iw_hmc_info *hmc_info = &vf_dev->hmc_info;
380 struct i40iw_virtchnl_op_buf *vchnl_msg = &vf_dev->vf_msg_buffer.vchnl_msg;
381 struct i40iw_hmc_del_obj_info info;
382 struct i40iw_virtchnl_hmc_obj_range *del_hmc_obj;
383 enum i40iw_status_code ret_code = I40IW_SUCCESS;
384
385 if (!vf_dev->pf_hmc_initialized)
386 goto del_out;
387
388 del_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
389
390 memset(&info, 0, sizeof(info));
391 info.hmc_info = hmc_info;
392 info.is_pf = false;
393 info.rsrc_type = (u32)del_hmc_obj->obj_type;
394 info.start_idx = del_hmc_obj->start_index;
395 info.count = del_hmc_obj->obj_count;
396 i40iw_debug(vf_dev->pf_dev, I40IW_DEBUG_VIRT,
397 "I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE. Delete %u type %u objects\n",
398 info.count, info.rsrc_type);
399 ret_code = i40iw_sc_del_hmc_obj(vf_dev->pf_dev, &info, false);
400del_out:
401 vf_dev->msg_count--;
402 vchnl_pf_send_error_resp(vf_dev->pf_dev, vf_dev->vf_id, vchnl_msg, (u16)ret_code);
403}
404
405/**
406 * i40iw_vchnl_recv_pf - Receive PF virtual channel messages
407 * @dev: IWARP device pointer
408 * @vf_id: Virtual function ID associated with the message
409 * @msg: Virtual channel message buffer pointer
410 * @len: Length of the virtual channels message
411 */
412enum i40iw_status_code i40iw_vchnl_recv_pf(struct i40iw_sc_dev *dev,
413 u32 vf_id,
414 u8 *msg,
415 u16 len)
416{
417 struct i40iw_virtchnl_op_buf *vchnl_msg = (struct i40iw_virtchnl_op_buf *)msg;
418 struct i40iw_vfdev *vf_dev = NULL;
419 struct i40iw_hmc_fcn_info hmc_fcn_info;
420 u16 iw_vf_idx;
421 u16 first_avail_iw_vf = I40IW_MAX_PE_ENABLED_VF_COUNT;
422 struct i40iw_virt_mem vf_dev_mem;
423 struct i40iw_virtchnl_work_info work_info;
424 struct i40iw_dev_pestat *devstat;
425 enum i40iw_status_code ret_code;
426 unsigned long flags;
427
428 if (!dev || !msg || !len)
429 return I40IW_ERR_PARAM;
430
431 if (!dev->vchnl_up)
432 return I40IW_ERR_NOT_READY;
433 if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
434 if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
435 vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
436 else
437 vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
438 return I40IW_SUCCESS;
439 }
440 for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT;
441 iw_vf_idx++) {
442 if (!dev->vf_dev[iw_vf_idx]) {
443 if (first_avail_iw_vf ==
444 I40IW_MAX_PE_ENABLED_VF_COUNT)
445 first_avail_iw_vf = iw_vf_idx;
446 continue;
447 }
448 if (dev->vf_dev[iw_vf_idx]->vf_id == vf_id) {
449 vf_dev = dev->vf_dev[iw_vf_idx];
450 break;
451 }
452 }
453 if (vf_dev) {
454 if (!vf_dev->msg_count) {
455 vf_dev->msg_count++;
456 } else {
457 i40iw_debug(dev, I40IW_DEBUG_VIRT,
458 "VF%u already has a channel message in progress.\n",
459 vf_id);
460 return I40IW_SUCCESS;
461 }
462 }
463 switch (vchnl_msg->iw_op_code) {
464 case I40IW_VCHNL_OP_GET_HMC_FCN:
465 if (!vf_dev &&
466 (first_avail_iw_vf != I40IW_MAX_PE_ENABLED_VF_COUNT)) {
467 ret_code = i40iw_allocate_virt_mem(dev->hw, &vf_dev_mem, sizeof(struct i40iw_vfdev) +
468 (sizeof(struct i40iw_hmc_obj_info) * I40IW_HMC_IW_MAX));
469 if (!ret_code) {
470 vf_dev = vf_dev_mem.va;
471 vf_dev->stats_initialized = false;
472 vf_dev->pf_dev = dev;
473 vf_dev->msg_count = 1;
474 vf_dev->vf_id = vf_id;
475 vf_dev->iw_vf_idx = first_avail_iw_vf;
476 vf_dev->pf_hmc_initialized = false;
477 vf_dev->hmc_info.hmc_obj = (struct i40iw_hmc_obj_info *)(&vf_dev[1]);
478 i40iw_debug(dev, I40IW_DEBUG_VIRT,
479 "vf_dev %p, hmc_info %p, hmc_obj %p\n",
480 vf_dev, &vf_dev->hmc_info, vf_dev->hmc_info.hmc_obj);
481 dev->vf_dev[first_avail_iw_vf] = vf_dev;
482 iw_vf_idx = first_avail_iw_vf;
483 } else {
484 i40iw_debug(dev, I40IW_DEBUG_VIRT,
485 "VF%u Unable to allocate a VF device structure.\n",
486 vf_id);
487 vchnl_pf_send_error_resp(dev, vf_id, vchnl_msg, (u16)I40IW_ERR_NO_MEMORY);
488 return I40IW_SUCCESS;
489 }
490 memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
491 hmc_fcn_info.callback_fcn = pf_cqp_get_hmc_fcn_callback;
492 hmc_fcn_info.vf_id = vf_id;
493 hmc_fcn_info.iw_vf_idx = vf_dev->iw_vf_idx;
494 hmc_fcn_info.cqp_callback_param = vf_dev;
495 hmc_fcn_info.free_fcn = false;
496 ret_code = i40iw_cqp_manage_hmc_fcn_cmd(dev, &hmc_fcn_info);
497 if (ret_code)
498 i40iw_debug(dev, I40IW_DEBUG_VIRT,
499 "VF%u error CQP HMC Function operation.\n",
500 vf_id);
501 ret_code = i40iw_device_init_pestat(&vf_dev->dev_pestat);
502 if (ret_code)
503 i40iw_debug(dev, I40IW_DEBUG_VIRT,
504 "VF%u - i40iw_device_init_pestat failed\n",
505 vf_id);
506 vf_dev->dev_pestat.ops.iw_hw_stat_init(&vf_dev->dev_pestat,
507 (u8)vf_dev->pmf_index,
508 dev->hw, false);
509 vf_dev->stats_initialized = true;
510 } else {
511 if (vf_dev) {
512 vf_dev->msg_count--;
513 vchnl_pf_send_get_hmc_fcn_resp(dev, vf_id, vchnl_msg, vf_dev->pmf_index);
514 } else {
515 vchnl_pf_send_error_resp(dev, vf_id, vchnl_msg,
516 (u16)I40IW_ERR_NO_MEMORY);
517 }
518 }
519 break;
520 case I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE:
521 if (!vf_dev)
522 return I40IW_ERR_BAD_PTR;
523 work_info.worker_vf_dev = vf_dev;
524 work_info.callback_fcn = pf_add_hmc_obj_callback;
525 memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
526 i40iw_cqp_spawn_worker(dev, &work_info, vf_dev->iw_vf_idx);
527 break;
528 case I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE:
529 if (!vf_dev)
530 return I40IW_ERR_BAD_PTR;
531 work_info.worker_vf_dev = vf_dev;
532 work_info.callback_fcn = pf_del_hmc_obj_callback;
533 memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
534 i40iw_cqp_spawn_worker(dev, &work_info, vf_dev->iw_vf_idx);
535 break;
536 case I40IW_VCHNL_OP_GET_STATS:
537 if (!vf_dev)
538 return I40IW_ERR_BAD_PTR;
539 devstat = &vf_dev->dev_pestat;
540 spin_lock_irqsave(&dev->dev_pestat.stats_lock, flags);
541 devstat->ops.iw_hw_stat_read_all(devstat, &devstat->hw_stats);
542 spin_unlock_irqrestore(&dev->dev_pestat.stats_lock, flags);
543 vf_dev->msg_count--;
544 vchnl_pf_send_get_pe_stats_resp(dev, vf_id, vchnl_msg, devstat->hw_stats);
545 break;
546 default:
547 i40iw_debug(dev, I40IW_DEBUG_VIRT,
548 "40iw_vchnl_recv_pf: Invalid OpCode 0x%x\n",
549 vchnl_msg->iw_op_code);
550 vchnl_pf_send_error_resp(dev, vf_id,
551 vchnl_msg, (u16)I40IW_ERR_NOT_IMPLEMENTED);
552 }
553 return I40IW_SUCCESS;
554}
555
556/**
557 * i40iw_vchnl_recv_vf - Receive VF virtual channel messages
558 * @dev: IWARP device pointer
559 * @vf_id: Virtual function ID associated with the message
560 * @msg: Virtual channel message buffer pointer
561 * @len: Length of the virtual channels message
562 */
563enum i40iw_status_code i40iw_vchnl_recv_vf(struct i40iw_sc_dev *dev,
564 u32 vf_id,
565 u8 *msg,
566 u16 len)
567{
568 struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)msg;
569 struct i40iw_virtchnl_req *vchnl_req;
570
571 vchnl_req = (struct i40iw_virtchnl_req *)(uintptr_t)vchnl_msg_resp->iw_chnl_op_ctx;
572 vchnl_req->ret_code = (enum i40iw_status_code)vchnl_msg_resp->iw_op_ret_code;
573 if (len == (sizeof(*vchnl_msg_resp) + vchnl_req->parm_len - 1)) {
574 if (vchnl_req->parm_len && vchnl_req->parm)
575 memcpy(vchnl_req->parm, vchnl_msg_resp->iw_chnl_buf, vchnl_req->parm_len);
576 i40iw_debug(dev, I40IW_DEBUG_VIRT,
577 "%s: Got response, data size %u\n", __func__,
578 vchnl_req->parm_len);
579 } else {
580 i40iw_debug(dev, I40IW_DEBUG_VIRT,
581 "%s: error length on response, Got %u, expected %u\n", __func__,
582 len, (u32)(sizeof(*vchnl_msg_resp) + vchnl_req->parm_len - 1));
583 }
584
585 return I40IW_SUCCESS;
586}
587
588/**
589 * i40iw_vchnl_vf_get_ver - Request Channel version
590 * @dev: IWARP device pointer
591 * @vchnl_ver: Virtual channel message version pointer
592 */
593enum i40iw_status_code i40iw_vchnl_vf_get_ver(struct i40iw_sc_dev *dev,
594 u32 *vchnl_ver)
595{
596 struct i40iw_virtchnl_req vchnl_req;
597 enum i40iw_status_code ret_code;
598
599 memset(&vchnl_req, 0, sizeof(vchnl_req));
600 vchnl_req.dev = dev;
601 vchnl_req.parm = vchnl_ver;
602 vchnl_req.parm_len = sizeof(*vchnl_ver);
603 vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
604 ret_code = vchnl_vf_send_get_ver_req(dev, &vchnl_req);
605 if (!ret_code) {
606 ret_code = i40iw_vf_wait_vchnl_resp(dev);
607 if (!ret_code)
608 ret_code = vchnl_req.ret_code;
609 else
610 dev->vchnl_up = false;
611 } else {
612 i40iw_debug(dev, I40IW_DEBUG_VIRT,
613 "%s Send message failed 0x%0x\n", __func__, ret_code);
614 }
615 return ret_code;
616}
617
618/**
619 * i40iw_vchnl_vf_get_hmc_fcn - Request HMC Function
620 * @dev: IWARP device pointer
621 * @hmc_fcn: HMC function index pointer
622 */
623enum i40iw_status_code i40iw_vchnl_vf_get_hmc_fcn(struct i40iw_sc_dev *dev,
624 u16 *hmc_fcn)
625{
626 struct i40iw_virtchnl_req vchnl_req;
627 enum i40iw_status_code ret_code;
628
629 memset(&vchnl_req, 0, sizeof(vchnl_req));
630 vchnl_req.dev = dev;
631 vchnl_req.parm = hmc_fcn;
632 vchnl_req.parm_len = sizeof(*hmc_fcn);
633 vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
634 ret_code = vchnl_vf_send_get_hmc_fcn_req(dev, &vchnl_req);
635 if (!ret_code) {
636 ret_code = i40iw_vf_wait_vchnl_resp(dev);
637 if (!ret_code)
638 ret_code = vchnl_req.ret_code;
639 else
640 dev->vchnl_up = false;
641 } else {
642 i40iw_debug(dev, I40IW_DEBUG_VIRT,
643 "%s Send message failed 0x%0x\n", __func__, ret_code);
644 }
645 return ret_code;
646}
647
648/**
649 * i40iw_vchnl_vf_add_hmc_objs - Add HMC Object
650 * @dev: IWARP device pointer
651 * @rsrc_type: HMC Resource type
652 * @start_index: Starting index of the objects to be added
653 * @rsrc_count: Number of resources to be added
654 */
655enum i40iw_status_code i40iw_vchnl_vf_add_hmc_objs(struct i40iw_sc_dev *dev,
656 enum i40iw_hmc_rsrc_type rsrc_type,
657 u32 start_index,
658 u32 rsrc_count)
659{
660 struct i40iw_virtchnl_req vchnl_req;
661 enum i40iw_status_code ret_code;
662
663 memset(&vchnl_req, 0, sizeof(vchnl_req));
664 vchnl_req.dev = dev;
665 vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
666 ret_code = vchnl_vf_send_add_hmc_objs_req(dev,
667 &vchnl_req,
668 rsrc_type,
669 start_index,
670 rsrc_count);
671 if (!ret_code) {
672 ret_code = i40iw_vf_wait_vchnl_resp(dev);
673 if (!ret_code)
674 ret_code = vchnl_req.ret_code;
675 else
676 dev->vchnl_up = false;
677 } else {
678 i40iw_debug(dev, I40IW_DEBUG_VIRT,
679 "%s Send message failed 0x%0x\n", __func__, ret_code);
680 }
681 return ret_code;
682}
683
684/**
685 * i40iw_vchnl_vf_del_hmc_obj - del HMC obj
686 * @dev: IWARP device pointer
687 * @rsrc_type: HMC Resource type
688 * @start_index: Starting index of the object to delete
689 * @rsrc_count: Number of resources to be delete
690 */
691enum i40iw_status_code i40iw_vchnl_vf_del_hmc_obj(struct i40iw_sc_dev *dev,
692 enum i40iw_hmc_rsrc_type rsrc_type,
693 u32 start_index,
694 u32 rsrc_count)
695{
696 struct i40iw_virtchnl_req vchnl_req;
697 enum i40iw_status_code ret_code;
698
699 memset(&vchnl_req, 0, sizeof(vchnl_req));
700 vchnl_req.dev = dev;
701 vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
702 ret_code = vchnl_vf_send_del_hmc_objs_req(dev,
703 &vchnl_req,
704 rsrc_type,
705 start_index,
706 rsrc_count);
707 if (!ret_code) {
708 ret_code = i40iw_vf_wait_vchnl_resp(dev);
709 if (!ret_code)
710 ret_code = vchnl_req.ret_code;
711 else
712 dev->vchnl_up = false;
713 } else {
714 i40iw_debug(dev, I40IW_DEBUG_VIRT,
715 "%s Send message failed 0x%0x\n", __func__, ret_code);
716 }
717 return ret_code;
718}
719
720/**
721 * i40iw_vchnl_vf_get_pe_stats - Get PE stats
722 * @dev: IWARP device pointer
723 * @hw_stats: HW stats struct
724 */
725enum i40iw_status_code i40iw_vchnl_vf_get_pe_stats(struct i40iw_sc_dev *dev,
726 struct i40iw_dev_hw_stats *hw_stats)
727{
728 struct i40iw_virtchnl_req vchnl_req;
729 enum i40iw_status_code ret_code;
730
731 memset(&vchnl_req, 0, sizeof(vchnl_req));
732 vchnl_req.dev = dev;
733 vchnl_req.parm = hw_stats;
734 vchnl_req.parm_len = sizeof(*hw_stats);
735 vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
736 ret_code = vchnl_vf_send_get_pe_stats_req(dev, &vchnl_req);
737 if (!ret_code) {
738 ret_code = i40iw_vf_wait_vchnl_resp(dev);
739 if (!ret_code)
740 ret_code = vchnl_req.ret_code;
741 else
742 dev->vchnl_up = false;
743 } else {
744 i40iw_debug(dev, I40IW_DEBUG_VIRT,
745 "%s Send message failed 0x%0x\n", __func__, ret_code);
746 }
747 return ret_code;
748}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.h b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.h
new file mode 100644
index 000000000000..24886ef08293
--- /dev/null
+++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.h
@@ -0,0 +1,124 @@
1/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#ifndef I40IW_VIRTCHNL_H
36#define I40IW_VIRTCHNL_H
37
38#include "i40iw_hmc.h"
39
40#pragma pack(push, 1)
41
42struct i40iw_virtchnl_op_buf {
43 u16 iw_op_code;
44 u16 iw_op_ver;
45 u16 iw_chnl_buf_len;
46 u16 rsvd;
47 u64 iw_chnl_op_ctx;
48 /* Member alignment MUST be maintained above this location */
49 u8 iw_chnl_buf[1];
50};
51
52struct i40iw_virtchnl_resp_buf {
53 u64 iw_chnl_op_ctx;
54 u16 iw_chnl_buf_len;
55 s16 iw_op_ret_code;
56 /* Member alignment MUST be maintained above this location */
57 u16 rsvd[2];
58 u8 iw_chnl_buf[1];
59};
60
61enum i40iw_virtchnl_ops {
62 I40IW_VCHNL_OP_GET_VER = 0,
63 I40IW_VCHNL_OP_GET_HMC_FCN,
64 I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE,
65 I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE,
66 I40IW_VCHNL_OP_GET_STATS
67};
68
69#define I40IW_VCHNL_OP_GET_VER_V0 0
70#define I40IW_VCHNL_OP_GET_HMC_FCN_V0 0
71#define I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE_V0 0
72#define I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE_V0 0
73#define I40IW_VCHNL_OP_GET_STATS_V0 0
74#define I40IW_VCHNL_CHNL_VER_V0 0
75
76struct i40iw_dev_hw_stats;
77
78struct i40iw_virtchnl_hmc_obj_range {
79 u16 obj_type;
80 u16 rsvd;
81 u32 start_index;
82 u32 obj_count;
83};
84
85enum i40iw_status_code i40iw_vchnl_recv_pf(struct i40iw_sc_dev *dev,
86 u32 vf_id,
87 u8 *msg,
88 u16 len);
89
90enum i40iw_status_code i40iw_vchnl_recv_vf(struct i40iw_sc_dev *dev,
91 u32 vf_id,
92 u8 *msg,
93 u16 len);
94
95struct i40iw_virtchnl_req {
96 struct i40iw_sc_dev *dev;
97 struct i40iw_virtchnl_op_buf *vchnl_msg;
98 void *parm;
99 u32 vf_id;
100 u16 parm_len;
101 s16 ret_code;
102};
103
104#pragma pack(pop)
105
106enum i40iw_status_code i40iw_vchnl_vf_get_ver(struct i40iw_sc_dev *dev,
107 u32 *vchnl_ver);
108
109enum i40iw_status_code i40iw_vchnl_vf_get_hmc_fcn(struct i40iw_sc_dev *dev,
110 u16 *hmc_fcn);
111
112enum i40iw_status_code i40iw_vchnl_vf_add_hmc_objs(struct i40iw_sc_dev *dev,
113 enum i40iw_hmc_rsrc_type rsrc_type,
114 u32 start_index,
115 u32 rsrc_count);
116
117enum i40iw_status_code i40iw_vchnl_vf_del_hmc_obj(struct i40iw_sc_dev *dev,
118 enum i40iw_hmc_rsrc_type rsrc_type,
119 u32 start_index,
120 u32 rsrc_count);
121
122enum i40iw_status_code i40iw_vchnl_vf_get_pe_stats(struct i40iw_sc_dev *dev,
123 struct i40iw_dev_hw_stats *hw_stats);
124#endif
diff --git a/drivers/infiniband/hw/mlx5/Makefile b/drivers/infiniband/hw/mlx5/Makefile
index 4e851889355a..7493a83acd28 100644
--- a/drivers/infiniband/hw/mlx5/Makefile
+++ b/drivers/infiniband/hw/mlx5/Makefile
@@ -1,4 +1,4 @@
1obj-$(CONFIG_MLX5_INFINIBAND) += mlx5_ib.o 1obj-$(CONFIG_MLX5_INFINIBAND) += mlx5_ib.o
2 2
3mlx5_ib-y := main.o cq.o doorbell.o qp.o mem.o srq.o mr.o ah.o mad.o gsi.o 3mlx5_ib-y := main.o cq.o doorbell.o qp.o mem.o srq.o mr.o ah.o mad.o gsi.o ib_virt.o
4mlx5_ib-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += odp.o 4mlx5_ib-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += odp.o
diff --git a/drivers/infiniband/hw/mlx5/ib_virt.c b/drivers/infiniband/hw/mlx5/ib_virt.c
new file mode 100644
index 000000000000..c1b9de800fe5
--- /dev/null
+++ b/drivers/infiniband/hw/mlx5/ib_virt.c
@@ -0,0 +1,194 @@
1/*
2 * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/module.h>
34#include <linux/mlx5/vport.h>
35#include "mlx5_ib.h"
36
37static inline u32 mlx_to_net_policy(enum port_state_policy mlx_policy)
38{
39 switch (mlx_policy) {
40 case MLX5_POLICY_DOWN:
41 return IFLA_VF_LINK_STATE_DISABLE;
42 case MLX5_POLICY_UP:
43 return IFLA_VF_LINK_STATE_ENABLE;
44 case MLX5_POLICY_FOLLOW:
45 return IFLA_VF_LINK_STATE_AUTO;
46 default:
47 return __IFLA_VF_LINK_STATE_MAX;
48 }
49}
50
51int mlx5_ib_get_vf_config(struct ib_device *device, int vf, u8 port,
52 struct ifla_vf_info *info)
53{
54 struct mlx5_ib_dev *dev = to_mdev(device);
55 struct mlx5_core_dev *mdev = dev->mdev;
56 struct mlx5_hca_vport_context *rep;
57 int err;
58
59 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
60 if (!rep)
61 return -ENOMEM;
62
63 err = mlx5_query_hca_vport_context(mdev, 1, 1, vf + 1, rep);
64 if (err) {
65 mlx5_ib_warn(dev, "failed to query port policy for vf %d (%d)\n",
66 vf, err);
67 goto free;
68 }
69 memset(info, 0, sizeof(*info));
70 info->linkstate = mlx_to_net_policy(rep->policy);
71 if (info->linkstate == __IFLA_VF_LINK_STATE_MAX)
72 err = -EINVAL;
73
74free:
75 kfree(rep);
76 return err;
77}
78
79static inline enum port_state_policy net_to_mlx_policy(int policy)
80{
81 switch (policy) {
82 case IFLA_VF_LINK_STATE_DISABLE:
83 return MLX5_POLICY_DOWN;
84 case IFLA_VF_LINK_STATE_ENABLE:
85 return MLX5_POLICY_UP;
86 case IFLA_VF_LINK_STATE_AUTO:
87 return MLX5_POLICY_FOLLOW;
88 default:
89 return MLX5_POLICY_INVALID;
90 }
91}
92
93int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
94 u8 port, int state)
95{
96 struct mlx5_ib_dev *dev = to_mdev(device);
97 struct mlx5_core_dev *mdev = dev->mdev;
98 struct mlx5_hca_vport_context *in;
99 int err;
100
101 in = kzalloc(sizeof(*in), GFP_KERNEL);
102 if (!in)
103 return -ENOMEM;
104
105 in->policy = net_to_mlx_policy(state);
106 if (in->policy == MLX5_POLICY_INVALID) {
107 err = -EINVAL;
108 goto out;
109 }
110 in->field_select = MLX5_HCA_VPORT_SEL_STATE_POLICY;
111 err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
112
113out:
114 kfree(in);
115 return err;
116}
117
118int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
119 u8 port, struct ifla_vf_stats *stats)
120{
121 int out_sz = MLX5_ST_SZ_BYTES(query_vport_counter_out);
122 struct mlx5_core_dev *mdev;
123 struct mlx5_ib_dev *dev;
124 void *out;
125 int err;
126
127 dev = to_mdev(device);
128 mdev = dev->mdev;
129
130 out = kzalloc(out_sz, GFP_KERNEL);
131 if (!out)
132 return -ENOMEM;
133
134 err = mlx5_core_query_vport_counter(mdev, true, vf, port, out, out_sz);
135 if (err)
136 goto ex;
137
138 stats->rx_packets = MLX5_GET64_PR(query_vport_counter_out, out, received_ib_unicast.packets);
139 stats->tx_packets = MLX5_GET64_PR(query_vport_counter_out, out, transmitted_ib_unicast.packets);
140 stats->rx_bytes = MLX5_GET64_PR(query_vport_counter_out, out, received_ib_unicast.octets);
141 stats->tx_bytes = MLX5_GET64_PR(query_vport_counter_out, out, transmitted_ib_unicast.octets);
142 stats->multicast = MLX5_GET64_PR(query_vport_counter_out, out, received_ib_multicast.packets);
143
144ex:
145 kfree(out);
146 return err;
147}
148
149static int set_vf_node_guid(struct ib_device *device, int vf, u8 port, u64 guid)
150{
151 struct mlx5_ib_dev *dev = to_mdev(device);
152 struct mlx5_core_dev *mdev = dev->mdev;
153 struct mlx5_hca_vport_context *in;
154 int err;
155
156 in = kzalloc(sizeof(*in), GFP_KERNEL);
157 if (!in)
158 return -ENOMEM;
159
160 in->field_select = MLX5_HCA_VPORT_SEL_NODE_GUID;
161 in->node_guid = guid;
162 err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
163 kfree(in);
164 return err;
165}
166
167static int set_vf_port_guid(struct ib_device *device, int vf, u8 port, u64 guid)
168{
169 struct mlx5_ib_dev *dev = to_mdev(device);
170 struct mlx5_core_dev *mdev = dev->mdev;
171 struct mlx5_hca_vport_context *in;
172 int err;
173
174 in = kzalloc(sizeof(*in), GFP_KERNEL);
175 if (!in)
176 return -ENOMEM;
177
178 in->field_select = MLX5_HCA_VPORT_SEL_PORT_GUID;
179 in->port_guid = guid;
180 err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
181 kfree(in);
182 return err;
183}
184
185int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
186 u64 guid, int type)
187{
188 if (type == IFLA_VF_IB_NODE_GUID)
189 return set_vf_node_guid(device, vf, port, guid);
190 else if (type == IFLA_VF_IB_PORT_GUID)
191 return set_vf_port_guid(device, vf, port, guid);
192
193 return -EINVAL;
194}
diff --git a/drivers/infiniband/hw/mlx5/mad.c b/drivers/infiniband/hw/mlx5/mad.c
index 41d8a0036465..1534af113058 100644
--- a/drivers/infiniband/hw/mlx5/mad.c
+++ b/drivers/infiniband/hw/mlx5/mad.c
@@ -208,7 +208,7 @@ static int process_pma_cmd(struct ib_device *ibdev, u8 port_num,
208 if (!out_cnt) 208 if (!out_cnt)
209 return IB_MAD_RESULT_FAILURE; 209 return IB_MAD_RESULT_FAILURE;
210 210
211 err = mlx5_core_query_vport_counter(dev->mdev, 0, 211 err = mlx5_core_query_vport_counter(dev->mdev, 0, 0,
212 port_num, out_cnt, sz); 212 port_num, out_cnt, sz);
213 if (!err) 213 if (!err)
214 pma_cnt_ext_assign(pma_cnt_ext, out_cnt); 214 pma_cnt_ext_assign(pma_cnt_ext, out_cnt);
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index edd8b8741846..5acf346e048e 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -284,7 +284,7 @@ __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
284 284
285static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) 285static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev)
286{ 286{
287 return !dev->mdev->issi; 287 return !MLX5_CAP_GEN(dev->mdev, ib_virt);
288} 288}
289 289
290enum { 290enum {
@@ -563,6 +563,9 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
563 if (MLX5_CAP_GEN(mdev, cd)) 563 if (MLX5_CAP_GEN(mdev, cd))
564 props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; 564 props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL;
565 565
566 if (!mlx5_core_is_pf(mdev))
567 props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION;
568
566 return 0; 569 return 0;
567} 570}
568 571
@@ -700,6 +703,7 @@ static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port,
700 props->qkey_viol_cntr = rep->qkey_violation_counter; 703 props->qkey_viol_cntr = rep->qkey_violation_counter;
701 props->subnet_timeout = rep->subnet_timeout; 704 props->subnet_timeout = rep->subnet_timeout;
702 props->init_type_reply = rep->init_type_reply; 705 props->init_type_reply = rep->init_type_reply;
706 props->grh_required = rep->grh_required;
703 707
704 err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); 708 err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port);
705 if (err) 709 if (err)
@@ -2350,6 +2354,12 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
2350 dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg; 2354 dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg;
2351 dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; 2355 dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status;
2352 dev->ib_dev.get_port_immutable = mlx5_port_immutable; 2356 dev->ib_dev.get_port_immutable = mlx5_port_immutable;
2357 if (mlx5_core_is_pf(mdev)) {
2358 dev->ib_dev.get_vf_config = mlx5_ib_get_vf_config;
2359 dev->ib_dev.set_vf_link_state = mlx5_ib_set_vf_link_state;
2360 dev->ib_dev.get_vf_stats = mlx5_ib_get_vf_stats;
2361 dev->ib_dev.set_vf_guid = mlx5_ib_set_vf_guid;
2362 }
2353 2363
2354 mlx5_ib_internal_fill_odp_caps(dev); 2364 mlx5_ib_internal_fill_odp_caps(dev);
2355 2365
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index 76b2b42e0535..f16c818ad2e6 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -776,6 +776,14 @@ void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
776void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp); 776void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
777void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, 777void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
778 unsigned long end); 778 unsigned long end);
779int mlx5_ib_get_vf_config(struct ib_device *device, int vf,
780 u8 port, struct ifla_vf_info *info);
781int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
782 u8 port, int state);
783int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
784 u8 port, struct ifla_vf_stats *stats);
785int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
786 u64 guid, int type);
779 787
780#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */ 788#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
781static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev) 789static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
diff --git a/drivers/infiniband/hw/qib/Kconfig b/drivers/infiniband/hw/qib/Kconfig
index 495be09781b1..e0fdb9201423 100644
--- a/drivers/infiniband/hw/qib/Kconfig
+++ b/drivers/infiniband/hw/qib/Kconfig
@@ -1,6 +1,6 @@
1config INFINIBAND_QIB 1config INFINIBAND_QIB
2 tristate "Intel PCIe HCA support" 2 tristate "Intel PCIe HCA support"
3 depends on 64BIT 3 depends on 64BIT && INFINIBAND_RDMAVT
4 ---help--- 4 ---help---
5 This is a low-level driver for Intel PCIe QLE InfiniBand host 5 This is a low-level driver for Intel PCIe QLE InfiniBand host
6 channel adapters. This driver does not support the Intel 6 channel adapters. This driver does not support the Intel
diff --git a/drivers/infiniband/hw/qib/Makefile b/drivers/infiniband/hw/qib/Makefile
index 57f8103e51f8..79ebd79e8405 100644
--- a/drivers/infiniband/hw/qib/Makefile
+++ b/drivers/infiniband/hw/qib/Makefile
@@ -1,11 +1,11 @@
1obj-$(CONFIG_INFINIBAND_QIB) += ib_qib.o 1obj-$(CONFIG_INFINIBAND_QIB) += ib_qib.o
2 2
3ib_qib-y := qib_cq.o qib_diag.o qib_dma.o qib_driver.o qib_eeprom.o \ 3ib_qib-y := qib_diag.o qib_driver.o qib_eeprom.o \
4 qib_file_ops.o qib_fs.o qib_init.o qib_intr.o qib_keys.o \ 4 qib_file_ops.o qib_fs.o qib_init.o qib_intr.o \
5 qib_mad.o qib_mmap.o qib_mr.o qib_pcie.o qib_pio_copy.o \ 5 qib_mad.o qib_pcie.o qib_pio_copy.o \
6 qib_qp.o qib_qsfp.o qib_rc.o qib_ruc.o qib_sdma.o qib_srq.o \ 6 qib_qp.o qib_qsfp.o qib_rc.o qib_ruc.o qib_sdma.o \
7 qib_sysfs.o qib_twsi.o qib_tx.o qib_uc.o qib_ud.o \ 7 qib_sysfs.o qib_twsi.o qib_tx.o qib_uc.o qib_ud.o \
8 qib_user_pages.o qib_user_sdma.o qib_verbs_mcast.o qib_iba7220.o \ 8 qib_user_pages.o qib_user_sdma.o qib_iba7220.o \
9 qib_sd7220.o qib_iba7322.o qib_verbs.o 9 qib_sd7220.o qib_iba7322.o qib_verbs.o
10 10
11# 6120 has no fallback if no MSI interrupts, others can do INTx 11# 6120 has no fallback if no MSI interrupts, others can do INTx
diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
index 7df16f74bb45..bbf0a163aeab 100644
--- a/drivers/infiniband/hw/qib/qib.h
+++ b/drivers/infiniband/hw/qib/qib.h
@@ -52,6 +52,7 @@
52#include <linux/kref.h> 52#include <linux/kref.h>
53#include <linux/sched.h> 53#include <linux/sched.h>
54#include <linux/kthread.h> 54#include <linux/kthread.h>
55#include <rdma/rdma_vt.h>
55 56
56#include "qib_common.h" 57#include "qib_common.h"
57#include "qib_verbs.h" 58#include "qib_verbs.h"
@@ -229,9 +230,6 @@ struct qib_ctxtdata {
229 u8 redirect_seq_cnt; 230 u8 redirect_seq_cnt;
230 /* ctxt rcvhdrq head offset */ 231 /* ctxt rcvhdrq head offset */
231 u32 head; 232 u32 head;
232 /* lookaside fields */
233 struct qib_qp *lookaside_qp;
234 u32 lookaside_qpn;
235 /* QPs waiting for context processing */ 233 /* QPs waiting for context processing */
236 struct list_head qp_wait_list; 234 struct list_head qp_wait_list;
237#ifdef CONFIG_DEBUG_FS 235#ifdef CONFIG_DEBUG_FS
@@ -240,7 +238,7 @@ struct qib_ctxtdata {
240#endif 238#endif
241}; 239};
242 240
243struct qib_sge_state; 241struct rvt_sge_state;
244 242
245struct qib_sdma_txreq { 243struct qib_sdma_txreq {
246 int flags; 244 int flags;
@@ -258,14 +256,14 @@ struct qib_sdma_desc {
258 256
259struct qib_verbs_txreq { 257struct qib_verbs_txreq {
260 struct qib_sdma_txreq txreq; 258 struct qib_sdma_txreq txreq;
261 struct qib_qp *qp; 259 struct rvt_qp *qp;
262 struct qib_swqe *wqe; 260 struct rvt_swqe *wqe;
263 u32 dwords; 261 u32 dwords;
264 u16 hdr_dwords; 262 u16 hdr_dwords;
265 u16 hdr_inx; 263 u16 hdr_inx;
266 struct qib_pio_header *align_buf; 264 struct qib_pio_header *align_buf;
267 struct qib_mregion *mr; 265 struct rvt_mregion *mr;
268 struct qib_sge_state *ss; 266 struct rvt_sge_state *ss;
269}; 267};
270 268
271#define QIB_SDMA_TXREQ_F_USELARGEBUF 0x1 269#define QIB_SDMA_TXREQ_F_USELARGEBUF 0x1
@@ -1096,8 +1094,6 @@ struct qib_devdata {
1096 u16 psxmitwait_check_rate; 1094 u16 psxmitwait_check_rate;
1097 /* high volume overflow errors defered to tasklet */ 1095 /* high volume overflow errors defered to tasklet */
1098 struct tasklet_struct error_tasklet; 1096 struct tasklet_struct error_tasklet;
1099 /* per device cq worker */
1100 struct kthread_worker *worker;
1101 1097
1102 int assigned_node_id; /* NUMA node closest to HCA */ 1098 int assigned_node_id; /* NUMA node closest to HCA */
1103}; 1099};
@@ -1135,8 +1131,9 @@ extern spinlock_t qib_devs_lock;
1135extern struct qib_devdata *qib_lookup(int unit); 1131extern struct qib_devdata *qib_lookup(int unit);
1136extern u32 qib_cpulist_count; 1132extern u32 qib_cpulist_count;
1137extern unsigned long *qib_cpulist; 1133extern unsigned long *qib_cpulist;
1138 1134extern u16 qpt_mask;
1139extern unsigned qib_cc_table_size; 1135extern unsigned qib_cc_table_size;
1136
1140int qib_init(struct qib_devdata *, int); 1137int qib_init(struct qib_devdata *, int);
1141int init_chip_wc_pat(struct qib_devdata *dd, u32); 1138int init_chip_wc_pat(struct qib_devdata *dd, u32);
1142int qib_enable_wc(struct qib_devdata *dd); 1139int qib_enable_wc(struct qib_devdata *dd);
@@ -1323,7 +1320,7 @@ void __qib_sdma_intr(struct qib_pportdata *);
1323void qib_sdma_intr(struct qib_pportdata *); 1320void qib_sdma_intr(struct qib_pportdata *);
1324void qib_user_sdma_send_desc(struct qib_pportdata *dd, 1321void qib_user_sdma_send_desc(struct qib_pportdata *dd,
1325 struct list_head *pktlist); 1322 struct list_head *pktlist);
1326int qib_sdma_verbs_send(struct qib_pportdata *, struct qib_sge_state *, 1323int qib_sdma_verbs_send(struct qib_pportdata *, struct rvt_sge_state *,
1327 u32, struct qib_verbs_txreq *); 1324 u32, struct qib_verbs_txreq *);
1328/* ppd->sdma_lock should be locked before calling this. */ 1325/* ppd->sdma_lock should be locked before calling this. */
1329int qib_sdma_make_progress(struct qib_pportdata *dd); 1326int qib_sdma_make_progress(struct qib_pportdata *dd);
@@ -1454,6 +1451,8 @@ u64 qib_sps_ints(void);
1454dma_addr_t qib_map_page(struct pci_dev *, struct page *, unsigned long, 1451dma_addr_t qib_map_page(struct pci_dev *, struct page *, unsigned long,
1455 size_t, int); 1452 size_t, int);
1456const char *qib_get_unit_name(int unit); 1453const char *qib_get_unit_name(int unit);
1454const char *qib_get_card_name(struct rvt_dev_info *rdi);
1455struct pci_dev *qib_get_pci_dev(struct rvt_dev_info *rdi);
1457 1456
1458/* 1457/*
1459 * Flush write combining store buffers (if present) and perform a write 1458 * Flush write combining store buffers (if present) and perform a write
@@ -1540,4 +1539,14 @@ struct qib_hwerror_msgs {
1540void qib_format_hwerrors(u64 hwerrs, 1539void qib_format_hwerrors(u64 hwerrs,
1541 const struct qib_hwerror_msgs *hwerrmsgs, 1540 const struct qib_hwerror_msgs *hwerrmsgs,
1542 size_t nhwerrmsgs, char *msg, size_t lmsg); 1541 size_t nhwerrmsgs, char *msg, size_t lmsg);
1542
1543void qib_stop_send_queue(struct rvt_qp *qp);
1544void qib_quiesce_qp(struct rvt_qp *qp);
1545void qib_flush_qp_waiters(struct rvt_qp *qp);
1546int qib_mtu_to_path_mtu(u32 mtu);
1547u32 qib_mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu);
1548void qib_notify_error_qp(struct rvt_qp *qp);
1549int qib_get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
1550 struct ib_qp_attr *attr);
1551
1543#endif /* _QIB_KERNEL_H */ 1552#endif /* _QIB_KERNEL_H */
diff --git a/drivers/infiniband/hw/qib/qib_common.h b/drivers/infiniband/hw/qib/qib_common.h
index 4fb78abd8ba1..1d6e63eb1146 100644
--- a/drivers/infiniband/hw/qib/qib_common.h
+++ b/drivers/infiniband/hw/qib/qib_common.h
@@ -742,14 +742,11 @@ struct qib_tid_session_member {
742#define SIZE_OF_CRC 1 742#define SIZE_OF_CRC 1
743 743
744#define QIB_DEFAULT_P_KEY 0xFFFF 744#define QIB_DEFAULT_P_KEY 0xFFFF
745#define QIB_PERMISSIVE_LID 0xFFFF
746#define QIB_AETH_CREDIT_SHIFT 24 745#define QIB_AETH_CREDIT_SHIFT 24
747#define QIB_AETH_CREDIT_MASK 0x1F 746#define QIB_AETH_CREDIT_MASK 0x1F
748#define QIB_AETH_CREDIT_INVAL 0x1F 747#define QIB_AETH_CREDIT_INVAL 0x1F
749#define QIB_PSN_MASK 0xFFFFFF 748#define QIB_PSN_MASK 0xFFFFFF
750#define QIB_MSN_MASK 0xFFFFFF 749#define QIB_MSN_MASK 0xFFFFFF
751#define QIB_QPN_MASK 0xFFFFFF
752#define QIB_MULTICAST_LID_BASE 0xC000
753#define QIB_EAGER_TID_ID QLOGIC_IB_I_TID_MASK 750#define QIB_EAGER_TID_ID QLOGIC_IB_I_TID_MASK
754#define QIB_MULTICAST_QPN 0xFFFFFF 751#define QIB_MULTICAST_QPN 0xFFFFFF
755 752
diff --git a/drivers/infiniband/hw/qib/qib_cq.c b/drivers/infiniband/hw/qib/qib_cq.c
deleted file mode 100644
index 2b45d0b02300..000000000000
--- a/drivers/infiniband/hw/qib/qib_cq.c
+++ /dev/null
@@ -1,545 +0,0 @@
1/*
2 * Copyright (c) 2013 Intel Corporation. All rights reserved.
3 * Copyright (c) 2006, 2007, 2008, 2010 QLogic Corporation. All rights reserved.
4 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <linux/err.h>
36#include <linux/slab.h>
37#include <linux/vmalloc.h>
38#include <linux/kthread.h>
39
40#include "qib_verbs.h"
41#include "qib.h"
42
43/**
44 * qib_cq_enter - add a new entry to the completion queue
45 * @cq: completion queue
46 * @entry: work completion entry to add
47 * @sig: true if @entry is a solicitated entry
48 *
49 * This may be called with qp->s_lock held.
50 */
51void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int solicited)
52{
53 struct qib_cq_wc *wc;
54 unsigned long flags;
55 u32 head;
56 u32 next;
57
58 spin_lock_irqsave(&cq->lock, flags);
59
60 /*
61 * Note that the head pointer might be writable by user processes.
62 * Take care to verify it is a sane value.
63 */
64 wc = cq->queue;
65 head = wc->head;
66 if (head >= (unsigned) cq->ibcq.cqe) {
67 head = cq->ibcq.cqe;
68 next = 0;
69 } else
70 next = head + 1;
71 if (unlikely(next == wc->tail)) {
72 spin_unlock_irqrestore(&cq->lock, flags);
73 if (cq->ibcq.event_handler) {
74 struct ib_event ev;
75
76 ev.device = cq->ibcq.device;
77 ev.element.cq = &cq->ibcq;
78 ev.event = IB_EVENT_CQ_ERR;
79 cq->ibcq.event_handler(&ev, cq->ibcq.cq_context);
80 }
81 return;
82 }
83 if (cq->ip) {
84 wc->uqueue[head].wr_id = entry->wr_id;
85 wc->uqueue[head].status = entry->status;
86 wc->uqueue[head].opcode = entry->opcode;
87 wc->uqueue[head].vendor_err = entry->vendor_err;
88 wc->uqueue[head].byte_len = entry->byte_len;
89 wc->uqueue[head].ex.imm_data =
90 (__u32 __force)entry->ex.imm_data;
91 wc->uqueue[head].qp_num = entry->qp->qp_num;
92 wc->uqueue[head].src_qp = entry->src_qp;
93 wc->uqueue[head].wc_flags = entry->wc_flags;
94 wc->uqueue[head].pkey_index = entry->pkey_index;
95 wc->uqueue[head].slid = entry->slid;
96 wc->uqueue[head].sl = entry->sl;
97 wc->uqueue[head].dlid_path_bits = entry->dlid_path_bits;
98 wc->uqueue[head].port_num = entry->port_num;
99 /* Make sure entry is written before the head index. */
100 smp_wmb();
101 } else
102 wc->kqueue[head] = *entry;
103 wc->head = next;
104
105 if (cq->notify == IB_CQ_NEXT_COMP ||
106 (cq->notify == IB_CQ_SOLICITED &&
107 (solicited || entry->status != IB_WC_SUCCESS))) {
108 struct kthread_worker *worker;
109 /*
110 * This will cause send_complete() to be called in
111 * another thread.
112 */
113 smp_rmb();
114 worker = cq->dd->worker;
115 if (likely(worker)) {
116 cq->notify = IB_CQ_NONE;
117 cq->triggered++;
118 queue_kthread_work(worker, &cq->comptask);
119 }
120 }
121
122 spin_unlock_irqrestore(&cq->lock, flags);
123}
124
125/**
126 * qib_poll_cq - poll for work completion entries
127 * @ibcq: the completion queue to poll
128 * @num_entries: the maximum number of entries to return
129 * @entry: pointer to array where work completions are placed
130 *
131 * Returns the number of completion entries polled.
132 *
133 * This may be called from interrupt context. Also called by ib_poll_cq()
134 * in the generic verbs code.
135 */
136int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
137{
138 struct qib_cq *cq = to_icq(ibcq);
139 struct qib_cq_wc *wc;
140 unsigned long flags;
141 int npolled;
142 u32 tail;
143
144 /* The kernel can only poll a kernel completion queue */
145 if (cq->ip) {
146 npolled = -EINVAL;
147 goto bail;
148 }
149
150 spin_lock_irqsave(&cq->lock, flags);
151
152 wc = cq->queue;
153 tail = wc->tail;
154 if (tail > (u32) cq->ibcq.cqe)
155 tail = (u32) cq->ibcq.cqe;
156 for (npolled = 0; npolled < num_entries; ++npolled, ++entry) {
157 if (tail == wc->head)
158 break;
159 /* The kernel doesn't need a RMB since it has the lock. */
160 *entry = wc->kqueue[tail];
161 if (tail >= cq->ibcq.cqe)
162 tail = 0;
163 else
164 tail++;
165 }
166 wc->tail = tail;
167
168 spin_unlock_irqrestore(&cq->lock, flags);
169
170bail:
171 return npolled;
172}
173
174static void send_complete(struct kthread_work *work)
175{
176 struct qib_cq *cq = container_of(work, struct qib_cq, comptask);
177
178 /*
179 * The completion handler will most likely rearm the notification
180 * and poll for all pending entries. If a new completion entry
181 * is added while we are in this routine, queue_work()
182 * won't call us again until we return so we check triggered to
183 * see if we need to call the handler again.
184 */
185 for (;;) {
186 u8 triggered = cq->triggered;
187
188 /*
189 * IPoIB connected mode assumes the callback is from a
190 * soft IRQ. We simulate this by blocking "bottom halves".
191 * See the implementation for ipoib_cm_handle_tx_wc(),
192 * netif_tx_lock_bh() and netif_tx_lock().
193 */
194 local_bh_disable();
195 cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);
196 local_bh_enable();
197
198 if (cq->triggered == triggered)
199 return;
200 }
201}
202
203/**
204 * qib_create_cq - create a completion queue
205 * @ibdev: the device this completion queue is attached to
206 * @attr: creation attributes
207 * @context: unused by the QLogic_IB driver
208 * @udata: user data for libibverbs.so
209 *
210 * Returns a pointer to the completion queue or negative errno values
211 * for failure.
212 *
213 * Called by ib_create_cq() in the generic verbs code.
214 */
215struct ib_cq *qib_create_cq(struct ib_device *ibdev,
216 const struct ib_cq_init_attr *attr,
217 struct ib_ucontext *context,
218 struct ib_udata *udata)
219{
220 int entries = attr->cqe;
221 struct qib_ibdev *dev = to_idev(ibdev);
222 struct qib_cq *cq;
223 struct qib_cq_wc *wc;
224 struct ib_cq *ret;
225 u32 sz;
226
227 if (attr->flags)
228 return ERR_PTR(-EINVAL);
229
230 if (entries < 1 || entries > ib_qib_max_cqes) {
231 ret = ERR_PTR(-EINVAL);
232 goto done;
233 }
234
235 /* Allocate the completion queue structure. */
236 cq = kmalloc(sizeof(*cq), GFP_KERNEL);
237 if (!cq) {
238 ret = ERR_PTR(-ENOMEM);
239 goto done;
240 }
241
242 /*
243 * Allocate the completion queue entries and head/tail pointers.
244 * This is allocated separately so that it can be resized and
245 * also mapped into user space.
246 * We need to use vmalloc() in order to support mmap and large
247 * numbers of entries.
248 */
249 sz = sizeof(*wc);
250 if (udata && udata->outlen >= sizeof(__u64))
251 sz += sizeof(struct ib_uverbs_wc) * (entries + 1);
252 else
253 sz += sizeof(struct ib_wc) * (entries + 1);
254 wc = vmalloc_user(sz);
255 if (!wc) {
256 ret = ERR_PTR(-ENOMEM);
257 goto bail_cq;
258 }
259
260 /*
261 * Return the address of the WC as the offset to mmap.
262 * See qib_mmap() for details.
263 */
264 if (udata && udata->outlen >= sizeof(__u64)) {
265 int err;
266
267 cq->ip = qib_create_mmap_info(dev, sz, context, wc);
268 if (!cq->ip) {
269 ret = ERR_PTR(-ENOMEM);
270 goto bail_wc;
271 }
272
273 err = ib_copy_to_udata(udata, &cq->ip->offset,
274 sizeof(cq->ip->offset));
275 if (err) {
276 ret = ERR_PTR(err);
277 goto bail_ip;
278 }
279 } else
280 cq->ip = NULL;
281
282 spin_lock(&dev->n_cqs_lock);
283 if (dev->n_cqs_allocated == ib_qib_max_cqs) {
284 spin_unlock(&dev->n_cqs_lock);
285 ret = ERR_PTR(-ENOMEM);
286 goto bail_ip;
287 }
288
289 dev->n_cqs_allocated++;
290 spin_unlock(&dev->n_cqs_lock);
291
292 if (cq->ip) {
293 spin_lock_irq(&dev->pending_lock);
294 list_add(&cq->ip->pending_mmaps, &dev->pending_mmaps);
295 spin_unlock_irq(&dev->pending_lock);
296 }
297
298 /*
299 * ib_create_cq() will initialize cq->ibcq except for cq->ibcq.cqe.
300 * The number of entries should be >= the number requested or return
301 * an error.
302 */
303 cq->dd = dd_from_dev(dev);
304 cq->ibcq.cqe = entries;
305 cq->notify = IB_CQ_NONE;
306 cq->triggered = 0;
307 spin_lock_init(&cq->lock);
308 init_kthread_work(&cq->comptask, send_complete);
309 wc->head = 0;
310 wc->tail = 0;
311 cq->queue = wc;
312
313 ret = &cq->ibcq;
314
315 goto done;
316
317bail_ip:
318 kfree(cq->ip);
319bail_wc:
320 vfree(wc);
321bail_cq:
322 kfree(cq);
323done:
324 return ret;
325}
326
327/**
328 * qib_destroy_cq - destroy a completion queue
329 * @ibcq: the completion queue to destroy.
330 *
331 * Returns 0 for success.
332 *
333 * Called by ib_destroy_cq() in the generic verbs code.
334 */
335int qib_destroy_cq(struct ib_cq *ibcq)
336{
337 struct qib_ibdev *dev = to_idev(ibcq->device);
338 struct qib_cq *cq = to_icq(ibcq);
339
340 flush_kthread_work(&cq->comptask);
341 spin_lock(&dev->n_cqs_lock);
342 dev->n_cqs_allocated--;
343 spin_unlock(&dev->n_cqs_lock);
344 if (cq->ip)
345 kref_put(&cq->ip->ref, qib_release_mmap_info);
346 else
347 vfree(cq->queue);
348 kfree(cq);
349
350 return 0;
351}
352
353/**
354 * qib_req_notify_cq - change the notification type for a completion queue
355 * @ibcq: the completion queue
356 * @notify_flags: the type of notification to request
357 *
358 * Returns 0 for success.
359 *
360 * This may be called from interrupt context. Also called by
361 * ib_req_notify_cq() in the generic verbs code.
362 */
363int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags)
364{
365 struct qib_cq *cq = to_icq(ibcq);
366 unsigned long flags;
367 int ret = 0;
368
369 spin_lock_irqsave(&cq->lock, flags);
370 /*
371 * Don't change IB_CQ_NEXT_COMP to IB_CQ_SOLICITED but allow
372 * any other transitions (see C11-31 and C11-32 in ch. 11.4.2.2).
373 */
374 if (cq->notify != IB_CQ_NEXT_COMP)
375 cq->notify = notify_flags & IB_CQ_SOLICITED_MASK;
376
377 if ((notify_flags & IB_CQ_REPORT_MISSED_EVENTS) &&
378 cq->queue->head != cq->queue->tail)
379 ret = 1;
380
381 spin_unlock_irqrestore(&cq->lock, flags);
382
383 return ret;
384}
385
386/**
387 * qib_resize_cq - change the size of the CQ
388 * @ibcq: the completion queue
389 *
390 * Returns 0 for success.
391 */
392int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
393{
394 struct qib_cq *cq = to_icq(ibcq);
395 struct qib_cq_wc *old_wc;
396 struct qib_cq_wc *wc;
397 u32 head, tail, n;
398 int ret;
399 u32 sz;
400
401 if (cqe < 1 || cqe > ib_qib_max_cqes) {
402 ret = -EINVAL;
403 goto bail;
404 }
405
406 /*
407 * Need to use vmalloc() if we want to support large #s of entries.
408 */
409 sz = sizeof(*wc);
410 if (udata && udata->outlen >= sizeof(__u64))
411 sz += sizeof(struct ib_uverbs_wc) * (cqe + 1);
412 else
413 sz += sizeof(struct ib_wc) * (cqe + 1);
414 wc = vmalloc_user(sz);
415 if (!wc) {
416 ret = -ENOMEM;
417 goto bail;
418 }
419
420 /* Check that we can write the offset to mmap. */
421 if (udata && udata->outlen >= sizeof(__u64)) {
422 __u64 offset = 0;
423
424 ret = ib_copy_to_udata(udata, &offset, sizeof(offset));
425 if (ret)
426 goto bail_free;
427 }
428
429 spin_lock_irq(&cq->lock);
430 /*
431 * Make sure head and tail are sane since they
432 * might be user writable.
433 */
434 old_wc = cq->queue;
435 head = old_wc->head;
436 if (head > (u32) cq->ibcq.cqe)
437 head = (u32) cq->ibcq.cqe;
438 tail = old_wc->tail;
439 if (tail > (u32) cq->ibcq.cqe)
440 tail = (u32) cq->ibcq.cqe;
441 if (head < tail)
442 n = cq->ibcq.cqe + 1 + head - tail;
443 else
444 n = head - tail;
445 if (unlikely((u32)cqe < n)) {
446 ret = -EINVAL;
447 goto bail_unlock;
448 }
449 for (n = 0; tail != head; n++) {
450 if (cq->ip)
451 wc->uqueue[n] = old_wc->uqueue[tail];
452 else
453 wc->kqueue[n] = old_wc->kqueue[tail];
454 if (tail == (u32) cq->ibcq.cqe)
455 tail = 0;
456 else
457 tail++;
458 }
459 cq->ibcq.cqe = cqe;
460 wc->head = n;
461 wc->tail = 0;
462 cq->queue = wc;
463 spin_unlock_irq(&cq->lock);
464
465 vfree(old_wc);
466
467 if (cq->ip) {
468 struct qib_ibdev *dev = to_idev(ibcq->device);
469 struct qib_mmap_info *ip = cq->ip;
470
471 qib_update_mmap_info(dev, ip, sz, wc);
472
473 /*
474 * Return the offset to mmap.
475 * See qib_mmap() for details.
476 */
477 if (udata && udata->outlen >= sizeof(__u64)) {
478 ret = ib_copy_to_udata(udata, &ip->offset,
479 sizeof(ip->offset));
480 if (ret)
481 goto bail;
482 }
483
484 spin_lock_irq(&dev->pending_lock);
485 if (list_empty(&ip->pending_mmaps))
486 list_add(&ip->pending_mmaps, &dev->pending_mmaps);
487 spin_unlock_irq(&dev->pending_lock);
488 }
489
490 ret = 0;
491 goto bail;
492
493bail_unlock:
494 spin_unlock_irq(&cq->lock);
495bail_free:
496 vfree(wc);
497bail:
498 return ret;
499}
500
501int qib_cq_init(struct qib_devdata *dd)
502{
503 int ret = 0;
504 int cpu;
505 struct task_struct *task;
506
507 if (dd->worker)
508 return 0;
509 dd->worker = kzalloc(sizeof(*dd->worker), GFP_KERNEL);
510 if (!dd->worker)
511 return -ENOMEM;
512 init_kthread_worker(dd->worker);
513 task = kthread_create_on_node(
514 kthread_worker_fn,
515 dd->worker,
516 dd->assigned_node_id,
517 "qib_cq%d", dd->unit);
518 if (IS_ERR(task))
519 goto task_fail;
520 cpu = cpumask_first(cpumask_of_node(dd->assigned_node_id));
521 kthread_bind(task, cpu);
522 wake_up_process(task);
523out:
524 return ret;
525task_fail:
526 ret = PTR_ERR(task);
527 kfree(dd->worker);
528 dd->worker = NULL;
529 goto out;
530}
531
532void qib_cq_exit(struct qib_devdata *dd)
533{
534 struct kthread_worker *worker;
535
536 worker = dd->worker;
537 if (!worker)
538 return;
539 /* blocks future queuing from send_complete() */
540 dd->worker = NULL;
541 smp_wmb();
542 flush_kthread_worker(worker);
543 kthread_stop(worker->task);
544 kfree(worker);
545}
diff --git a/drivers/infiniband/hw/qib/qib_driver.c b/drivers/infiniband/hw/qib/qib_driver.c
index f58fdc3d25a2..67ee6438cf59 100644
--- a/drivers/infiniband/hw/qib/qib_driver.c
+++ b/drivers/infiniband/hw/qib/qib_driver.c
@@ -90,6 +90,22 @@ const char *qib_get_unit_name(int unit)
90 return iname; 90 return iname;
91} 91}
92 92
93const char *qib_get_card_name(struct rvt_dev_info *rdi)
94{
95 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
96 struct qib_devdata *dd = container_of(ibdev,
97 struct qib_devdata, verbs_dev);
98 return qib_get_unit_name(dd->unit);
99}
100
101struct pci_dev *qib_get_pci_dev(struct rvt_dev_info *rdi)
102{
103 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
104 struct qib_devdata *dd = container_of(ibdev,
105 struct qib_devdata, verbs_dev);
106 return dd->pcidev;
107}
108
93/* 109/*
94 * Return count of units with at least one port ACTIVE. 110 * Return count of units with at least one port ACTIVE.
95 */ 111 */
@@ -306,7 +322,9 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
306 struct qib_ib_header *hdr = (struct qib_ib_header *) rhdr; 322 struct qib_ib_header *hdr = (struct qib_ib_header *) rhdr;
307 struct qib_other_headers *ohdr = NULL; 323 struct qib_other_headers *ohdr = NULL;
308 struct qib_ibport *ibp = &ppd->ibport_data; 324 struct qib_ibport *ibp = &ppd->ibport_data;
309 struct qib_qp *qp = NULL; 325 struct qib_devdata *dd = ppd->dd;
326 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
327 struct rvt_qp *qp = NULL;
310 u32 tlen = qib_hdrget_length_in_bytes(rhf_addr); 328 u32 tlen = qib_hdrget_length_in_bytes(rhf_addr);
311 u16 lid = be16_to_cpu(hdr->lrh[1]); 329 u16 lid = be16_to_cpu(hdr->lrh[1]);
312 int lnh = be16_to_cpu(hdr->lrh[0]) & 3; 330 int lnh = be16_to_cpu(hdr->lrh[0]) & 3;
@@ -319,7 +337,7 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
319 if (tlen < 24) 337 if (tlen < 24)
320 goto drop; 338 goto drop;
321 339
322 if (lid < QIB_MULTICAST_LID_BASE) { 340 if (lid < be16_to_cpu(IB_MULTICAST_LID_BASE)) {
323 lid &= ~((1 << ppd->lmc) - 1); 341 lid &= ~((1 << ppd->lmc) - 1);
324 if (unlikely(lid != ppd->lid)) 342 if (unlikely(lid != ppd->lid))
325 goto drop; 343 goto drop;
@@ -346,13 +364,16 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
346 psn = be32_to_cpu(ohdr->bth[2]); 364 psn = be32_to_cpu(ohdr->bth[2]);
347 365
348 /* Get the destination QP number. */ 366 /* Get the destination QP number. */
349 qp_num = be32_to_cpu(ohdr->bth[1]) & QIB_QPN_MASK; 367 qp_num = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
350 if (qp_num != QIB_MULTICAST_QPN) { 368 if (qp_num != QIB_MULTICAST_QPN) {
351 int ruc_res; 369 int ruc_res;
352 370
353 qp = qib_lookup_qpn(ibp, qp_num); 371 rcu_read_lock();
354 if (!qp) 372 qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
373 if (!qp) {
374 rcu_read_unlock();
355 goto drop; 375 goto drop;
376 }
356 377
357 /* 378 /*
358 * Handle only RC QPs - for other QP types drop error 379 * Handle only RC QPs - for other QP types drop error
@@ -361,9 +382,9 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
361 spin_lock(&qp->r_lock); 382 spin_lock(&qp->r_lock);
362 383
363 /* Check for valid receive state. */ 384 /* Check for valid receive state. */
364 if (!(ib_qib_state_ops[qp->state] & 385 if (!(ib_rvt_state_ops[qp->state] &
365 QIB_PROCESS_RECV_OK)) { 386 RVT_PROCESS_RECV_OK)) {
366 ibp->n_pkt_drops++; 387 ibp->rvp.n_pkt_drops++;
367 goto unlock; 388 goto unlock;
368 } 389 }
369 390
@@ -383,7 +404,7 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
383 IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) { 404 IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) {
384 diff = qib_cmp24(psn, qp->r_psn); 405 diff = qib_cmp24(psn, qp->r_psn);
385 if (!qp->r_nak_state && diff >= 0) { 406 if (!qp->r_nak_state && diff >= 0) {
386 ibp->n_rc_seqnak++; 407 ibp->rvp.n_rc_seqnak++;
387 qp->r_nak_state = 408 qp->r_nak_state =
388 IB_NAK_PSN_ERROR; 409 IB_NAK_PSN_ERROR;
389 /* Use the expected PSN. */ 410 /* Use the expected PSN. */
@@ -398,7 +419,7 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
398 */ 419 */
399 if (list_empty(&qp->rspwait)) { 420 if (list_empty(&qp->rspwait)) {
400 qp->r_flags |= 421 qp->r_flags |=
401 QIB_R_RSP_NAK; 422 RVT_R_RSP_NAK;
402 atomic_inc( 423 atomic_inc(
403 &qp->refcount); 424 &qp->refcount);
404 list_add_tail( 425 list_add_tail(
@@ -419,12 +440,7 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
419 440
420unlock: 441unlock:
421 spin_unlock(&qp->r_lock); 442 spin_unlock(&qp->r_lock);
422 /* 443 rcu_read_unlock();
423 * Notify qib_destroy_qp() if it is waiting
424 * for us to finish.
425 */
426 if (atomic_dec_and_test(&qp->refcount))
427 wake_up(&qp->wait);
428 } /* Unicast QP */ 444 } /* Unicast QP */
429 } /* Valid packet with TIDErr */ 445 } /* Valid packet with TIDErr */
430 446
@@ -456,7 +472,7 @@ u32 qib_kreceive(struct qib_ctxtdata *rcd, u32 *llic, u32 *npkts)
456 u32 eflags, etype, tlen, i = 0, updegr = 0, crcs = 0; 472 u32 eflags, etype, tlen, i = 0, updegr = 0, crcs = 0;
457 int last; 473 int last;
458 u64 lval; 474 u64 lval;
459 struct qib_qp *qp, *nqp; 475 struct rvt_qp *qp, *nqp;
460 476
461 l = rcd->head; 477 l = rcd->head;
462 rhf_addr = (__le32 *) rcd->rcvhdrq + l + dd->rhf_offset; 478 rhf_addr = (__le32 *) rcd->rcvhdrq + l + dd->rhf_offset;
@@ -549,15 +565,6 @@ move_along:
549 updegr = 0; 565 updegr = 0;
550 } 566 }
551 } 567 }
552 /*
553 * Notify qib_destroy_qp() if it is waiting
554 * for lookaside_qp to finish.
555 */
556 if (rcd->lookaside_qp) {
557 if (atomic_dec_and_test(&rcd->lookaside_qp->refcount))
558 wake_up(&rcd->lookaside_qp->wait);
559 rcd->lookaside_qp = NULL;
560 }
561 568
562 rcd->head = l; 569 rcd->head = l;
563 570
@@ -567,17 +574,17 @@ move_along:
567 */ 574 */
568 list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) { 575 list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) {
569 list_del_init(&qp->rspwait); 576 list_del_init(&qp->rspwait);
570 if (qp->r_flags & QIB_R_RSP_NAK) { 577 if (qp->r_flags & RVT_R_RSP_NAK) {
571 qp->r_flags &= ~QIB_R_RSP_NAK; 578 qp->r_flags &= ~RVT_R_RSP_NAK;
572 qib_send_rc_ack(qp); 579 qib_send_rc_ack(qp);
573 } 580 }
574 if (qp->r_flags & QIB_R_RSP_SEND) { 581 if (qp->r_flags & RVT_R_RSP_SEND) {
575 unsigned long flags; 582 unsigned long flags;
576 583
577 qp->r_flags &= ~QIB_R_RSP_SEND; 584 qp->r_flags &= ~RVT_R_RSP_SEND;
578 spin_lock_irqsave(&qp->s_lock, flags); 585 spin_lock_irqsave(&qp->s_lock, flags);
579 if (ib_qib_state_ops[qp->state] & 586 if (ib_rvt_state_ops[qp->state] &
580 QIB_PROCESS_OR_FLUSH_SEND) 587 RVT_PROCESS_OR_FLUSH_SEND)
581 qib_schedule_send(qp); 588 qib_schedule_send(qp);
582 spin_unlock_irqrestore(&qp->s_lock, flags); 589 spin_unlock_irqrestore(&qp->s_lock, flags);
583 } 590 }
diff --git a/drivers/infiniband/hw/qib/qib_iba6120.c b/drivers/infiniband/hw/qib/qib_iba6120.c
index 4b927809d1a1..a3733f25280f 100644
--- a/drivers/infiniband/hw/qib/qib_iba6120.c
+++ b/drivers/infiniband/hw/qib/qib_iba6120.c
@@ -2956,13 +2956,13 @@ static void pma_6120_timer(unsigned long data)
2956 struct qib_ibport *ibp = &ppd->ibport_data; 2956 struct qib_ibport *ibp = &ppd->ibport_data;
2957 unsigned long flags; 2957 unsigned long flags;
2958 2958
2959 spin_lock_irqsave(&ibp->lock, flags); 2959 spin_lock_irqsave(&ibp->rvp.lock, flags);
2960 if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED) { 2960 if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED) {
2961 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING; 2961 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
2962 qib_snapshot_counters(ppd, &cs->sword, &cs->rword, 2962 qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
2963 &cs->spkts, &cs->rpkts, &cs->xmit_wait); 2963 &cs->spkts, &cs->rpkts, &cs->xmit_wait);
2964 mod_timer(&cs->pma_timer, 2964 mod_timer(&cs->pma_timer,
2965 jiffies + usecs_to_jiffies(ibp->pma_sample_interval)); 2965 jiffies + usecs_to_jiffies(ibp->rvp.pma_sample_interval));
2966 } else if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) { 2966 } else if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
2967 u64 ta, tb, tc, td, te; 2967 u64 ta, tb, tc, td, te;
2968 2968
@@ -2975,11 +2975,11 @@ static void pma_6120_timer(unsigned long data)
2975 cs->rpkts = td - cs->rpkts; 2975 cs->rpkts = td - cs->rpkts;
2976 cs->xmit_wait = te - cs->xmit_wait; 2976 cs->xmit_wait = te - cs->xmit_wait;
2977 } 2977 }
2978 spin_unlock_irqrestore(&ibp->lock, flags); 2978 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
2979} 2979}
2980 2980
2981/* 2981/*
2982 * Note that the caller has the ibp->lock held. 2982 * Note that the caller has the ibp->rvp.lock held.
2983 */ 2983 */
2984static void qib_set_cntr_6120_sample(struct qib_pportdata *ppd, u32 intv, 2984static void qib_set_cntr_6120_sample(struct qib_pportdata *ppd, u32 intv,
2985 u32 start) 2985 u32 start)
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c
index 6c8ff10101c0..82d7c4bf5970 100644
--- a/drivers/infiniband/hw/qib/qib_iba7322.c
+++ b/drivers/infiniband/hw/qib/qib_iba7322.c
@@ -2910,8 +2910,6 @@ static void qib_setup_7322_cleanup(struct qib_devdata *dd)
2910 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags); 2910 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2911 qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data); 2911 qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data);
2912 } 2912 }
2913 if (dd->pport[i].ibport_data.smi_ah)
2914 ib_destroy_ah(&dd->pport[i].ibport_data.smi_ah->ibah);
2915 } 2913 }
2916} 2914}
2917 2915
@@ -5497,7 +5495,7 @@ static void try_7322_ipg(struct qib_pportdata *ppd)
5497 unsigned delay; 5495 unsigned delay;
5498 int ret; 5496 int ret;
5499 5497
5500 agent = ibp->send_agent; 5498 agent = ibp->rvp.send_agent;
5501 if (!agent) 5499 if (!agent)
5502 goto retry; 5500 goto retry;
5503 5501
@@ -5515,7 +5513,7 @@ static void try_7322_ipg(struct qib_pportdata *ppd)
5515 ret = PTR_ERR(ah); 5513 ret = PTR_ERR(ah);
5516 else { 5514 else {
5517 send_buf->ah = ah; 5515 send_buf->ah = ah;
5518 ibp->smi_ah = to_iah(ah); 5516 ibp->smi_ah = ibah_to_rvtah(ah);
5519 ret = 0; 5517 ret = 0;
5520 } 5518 }
5521 } else { 5519 } else {
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c
index 4ff340fe904f..3f062f0dd9d8 100644
--- a/drivers/infiniband/hw/qib/qib_init.c
+++ b/drivers/infiniband/hw/qib/qib_init.c
@@ -42,6 +42,7 @@
42#ifdef CONFIG_INFINIBAND_QIB_DCA 42#ifdef CONFIG_INFINIBAND_QIB_DCA
43#include <linux/dca.h> 43#include <linux/dca.h>
44#endif 44#endif
45#include <rdma/rdma_vt.h>
45 46
46#include "qib.h" 47#include "qib.h"
47#include "qib_common.h" 48#include "qib_common.h"
@@ -244,6 +245,13 @@ int qib_init_pportdata(struct qib_pportdata *ppd, struct qib_devdata *dd,
244 alloc_percpu(struct qib_pma_counters); 245 alloc_percpu(struct qib_pma_counters);
245 if (!ppd->ibport_data.pmastats) 246 if (!ppd->ibport_data.pmastats)
246 return -ENOMEM; 247 return -ENOMEM;
248 ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
249 ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
250 ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
251 if (!(ppd->ibport_data.rvp.rc_acks) ||
252 !(ppd->ibport_data.rvp.rc_qacks) ||
253 !(ppd->ibport_data.rvp.rc_delayed_comp))
254 return -ENOMEM;
247 255
248 if (qib_cc_table_size < IB_CCT_MIN_ENTRIES) 256 if (qib_cc_table_size < IB_CCT_MIN_ENTRIES)
249 goto bail; 257 goto bail;
@@ -449,8 +457,6 @@ static int loadtime_init(struct qib_devdata *dd)
449 init_timer(&dd->intrchk_timer); 457 init_timer(&dd->intrchk_timer);
450 dd->intrchk_timer.function = verify_interrupt; 458 dd->intrchk_timer.function = verify_interrupt;
451 dd->intrchk_timer.data = (unsigned long) dd; 459 dd->intrchk_timer.data = (unsigned long) dd;
452
453 ret = qib_cq_init(dd);
454done: 460done:
455 return ret; 461 return ret;
456} 462}
@@ -631,6 +637,9 @@ wq_error:
631static void qib_free_pportdata(struct qib_pportdata *ppd) 637static void qib_free_pportdata(struct qib_pportdata *ppd)
632{ 638{
633 free_percpu(ppd->ibport_data.pmastats); 639 free_percpu(ppd->ibport_data.pmastats);
640 free_percpu(ppd->ibport_data.rvp.rc_acks);
641 free_percpu(ppd->ibport_data.rvp.rc_qacks);
642 free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
634 ppd->ibport_data.pmastats = NULL; 643 ppd->ibport_data.pmastats = NULL;
635} 644}
636 645
@@ -1081,7 +1090,7 @@ void qib_free_devdata(struct qib_devdata *dd)
1081 qib_dbg_ibdev_exit(&dd->verbs_dev); 1090 qib_dbg_ibdev_exit(&dd->verbs_dev);
1082#endif 1091#endif
1083 free_percpu(dd->int_counter); 1092 free_percpu(dd->int_counter);
1084 ib_dealloc_device(&dd->verbs_dev.ibdev); 1093 ib_dealloc_device(&dd->verbs_dev.rdi.ibdev);
1085} 1094}
1086 1095
1087u64 qib_int_counter(struct qib_devdata *dd) 1096u64 qib_int_counter(struct qib_devdata *dd)
@@ -1120,9 +1129,12 @@ struct qib_devdata *qib_alloc_devdata(struct pci_dev *pdev, size_t extra)
1120{ 1129{
1121 unsigned long flags; 1130 unsigned long flags;
1122 struct qib_devdata *dd; 1131 struct qib_devdata *dd;
1123 int ret; 1132 int ret, nports;
1124 1133
1125 dd = (struct qib_devdata *) ib_alloc_device(sizeof(*dd) + extra); 1134 /* extra is * number of ports */
1135 nports = extra / sizeof(struct qib_pportdata);
1136 dd = (struct qib_devdata *)rvt_alloc_device(sizeof(*dd) + extra,
1137 nports);
1126 if (!dd) 1138 if (!dd)
1127 return ERR_PTR(-ENOMEM); 1139 return ERR_PTR(-ENOMEM);
1128 1140
@@ -1171,7 +1183,7 @@ struct qib_devdata *qib_alloc_devdata(struct pci_dev *pdev, size_t extra)
1171bail: 1183bail:
1172 if (!list_empty(&dd->list)) 1184 if (!list_empty(&dd->list))
1173 list_del_init(&dd->list); 1185 list_del_init(&dd->list);
1174 ib_dealloc_device(&dd->verbs_dev.ibdev); 1186 ib_dealloc_device(&dd->verbs_dev.rdi.ibdev);
1175 return ERR_PTR(ret); 1187 return ERR_PTR(ret);
1176} 1188}
1177 1189
@@ -1421,7 +1433,6 @@ static void cleanup_device_data(struct qib_devdata *dd)
1421 } 1433 }
1422 kfree(tmp); 1434 kfree(tmp);
1423 kfree(dd->boardname); 1435 kfree(dd->boardname);
1424 qib_cq_exit(dd);
1425} 1436}
1426 1437
1427/* 1438/*
diff --git a/drivers/infiniband/hw/qib/qib_intr.c b/drivers/infiniband/hw/qib/qib_intr.c
index 086616d071b9..a014fd4cd076 100644
--- a/drivers/infiniband/hw/qib/qib_intr.c
+++ b/drivers/infiniband/hw/qib/qib_intr.c
@@ -74,7 +74,7 @@ static void signal_ib_event(struct qib_pportdata *ppd, enum ib_event_type ev)
74 struct ib_event event; 74 struct ib_event event;
75 struct qib_devdata *dd = ppd->dd; 75 struct qib_devdata *dd = ppd->dd;
76 76
77 event.device = &dd->verbs_dev.ibdev; 77 event.device = &dd->verbs_dev.rdi.ibdev;
78 event.element.port_num = ppd->port; 78 event.element.port_num = ppd->port;
79 event.event = ev; 79 event.event = ev;
80 ib_dispatch_event(&event); 80 ib_dispatch_event(&event);
diff --git a/drivers/infiniband/hw/qib/qib_keys.c b/drivers/infiniband/hw/qib/qib_keys.c
index d725c565518d..2c3c93572c17 100644
--- a/drivers/infiniband/hw/qib/qib_keys.c
+++ b/drivers/infiniband/hw/qib/qib_keys.c
@@ -46,20 +46,20 @@
46 * 46 *
47 */ 47 */
48 48
49int qib_alloc_lkey(struct qib_mregion *mr, int dma_region) 49int qib_alloc_lkey(struct rvt_mregion *mr, int dma_region)
50{ 50{
51 unsigned long flags; 51 unsigned long flags;
52 u32 r; 52 u32 r;
53 u32 n; 53 u32 n;
54 int ret = 0; 54 int ret = 0;
55 struct qib_ibdev *dev = to_idev(mr->pd->device); 55 struct qib_ibdev *dev = to_idev(mr->pd->device);
56 struct qib_lkey_table *rkt = &dev->lk_table; 56 struct rvt_lkey_table *rkt = &dev->lk_table;
57 57
58 spin_lock_irqsave(&rkt->lock, flags); 58 spin_lock_irqsave(&rkt->lock, flags);
59 59
60 /* special case for dma_mr lkey == 0 */ 60 /* special case for dma_mr lkey == 0 */
61 if (dma_region) { 61 if (dma_region) {
62 struct qib_mregion *tmr; 62 struct rvt_mregion *tmr;
63 63
64 tmr = rcu_access_pointer(dev->dma_mr); 64 tmr = rcu_access_pointer(dev->dma_mr);
65 if (!tmr) { 65 if (!tmr) {
@@ -90,8 +90,8 @@ int qib_alloc_lkey(struct qib_mregion *mr, int dma_region)
90 * bits are capped in qib_verbs.c to insure enough bits 90 * bits are capped in qib_verbs.c to insure enough bits
91 * for generation number 91 * for generation number
92 */ 92 */
93 mr->lkey = (r << (32 - ib_qib_lkey_table_size)) | 93 mr->lkey = (r << (32 - ib_rvt_lkey_table_size)) |
94 ((((1 << (24 - ib_qib_lkey_table_size)) - 1) & rkt->gen) 94 ((((1 << (24 - ib_rvt_lkey_table_size)) - 1) & rkt->gen)
95 << 8); 95 << 8);
96 if (mr->lkey == 0) { 96 if (mr->lkey == 0) {
97 mr->lkey |= 1 << 8; 97 mr->lkey |= 1 << 8;
@@ -114,13 +114,13 @@ bail:
114 * qib_free_lkey - free an lkey 114 * qib_free_lkey - free an lkey
115 * @mr: mr to free from tables 115 * @mr: mr to free from tables
116 */ 116 */
117void qib_free_lkey(struct qib_mregion *mr) 117void qib_free_lkey(struct rvt_mregion *mr)
118{ 118{
119 unsigned long flags; 119 unsigned long flags;
120 u32 lkey = mr->lkey; 120 u32 lkey = mr->lkey;
121 u32 r; 121 u32 r;
122 struct qib_ibdev *dev = to_idev(mr->pd->device); 122 struct qib_ibdev *dev = to_idev(mr->pd->device);
123 struct qib_lkey_table *rkt = &dev->lk_table; 123 struct rvt_lkey_table *rkt = &dev->lk_table;
124 124
125 spin_lock_irqsave(&rkt->lock, flags); 125 spin_lock_irqsave(&rkt->lock, flags);
126 if (!mr->lkey_published) 126 if (!mr->lkey_published)
@@ -128,7 +128,7 @@ void qib_free_lkey(struct qib_mregion *mr)
128 if (lkey == 0) 128 if (lkey == 0)
129 RCU_INIT_POINTER(dev->dma_mr, NULL); 129 RCU_INIT_POINTER(dev->dma_mr, NULL);
130 else { 130 else {
131 r = lkey >> (32 - ib_qib_lkey_table_size); 131 r = lkey >> (32 - ib_rvt_lkey_table_size);
132 RCU_INIT_POINTER(rkt->table[r], NULL); 132 RCU_INIT_POINTER(rkt->table[r], NULL);
133 } 133 }
134 qib_put_mr(mr); 134 qib_put_mr(mr);
@@ -138,105 +138,6 @@ out:
138} 138}
139 139
140/** 140/**
141 * qib_lkey_ok - check IB SGE for validity and initialize
142 * @rkt: table containing lkey to check SGE against
143 * @pd: protection domain
144 * @isge: outgoing internal SGE
145 * @sge: SGE to check
146 * @acc: access flags
147 *
148 * Return 1 if valid and successful, otherwise returns 0.
149 *
150 * increments the reference count upon success
151 *
152 * Check the IB SGE for validity and initialize our internal version
153 * of it.
154 */
155int qib_lkey_ok(struct qib_lkey_table *rkt, struct qib_pd *pd,
156 struct qib_sge *isge, struct ib_sge *sge, int acc)
157{
158 struct qib_mregion *mr;
159 unsigned n, m;
160 size_t off;
161
162 /*
163 * We use LKEY == zero for kernel virtual addresses
164 * (see qib_get_dma_mr and qib_dma.c).
165 */
166 rcu_read_lock();
167 if (sge->lkey == 0) {
168 struct qib_ibdev *dev = to_idev(pd->ibpd.device);
169
170 if (pd->user)
171 goto bail;
172 mr = rcu_dereference(dev->dma_mr);
173 if (!mr)
174 goto bail;
175 if (unlikely(!atomic_inc_not_zero(&mr->refcount)))
176 goto bail;
177 rcu_read_unlock();
178
179 isge->mr = mr;
180 isge->vaddr = (void *) sge->addr;
181 isge->length = sge->length;
182 isge->sge_length = sge->length;
183 isge->m = 0;
184 isge->n = 0;
185 goto ok;
186 }
187 mr = rcu_dereference(
188 rkt->table[(sge->lkey >> (32 - ib_qib_lkey_table_size))]);
189 if (unlikely(!mr || mr->lkey != sge->lkey || mr->pd != &pd->ibpd))
190 goto bail;
191
192 off = sge->addr - mr->user_base;
193 if (unlikely(sge->addr < mr->user_base ||
194 off + sge->length > mr->length ||
195 (mr->access_flags & acc) != acc))
196 goto bail;
197 if (unlikely(!atomic_inc_not_zero(&mr->refcount)))
198 goto bail;
199 rcu_read_unlock();
200
201 off += mr->offset;
202 if (mr->page_shift) {
203 /*
204 page sizes are uniform power of 2 so no loop is necessary
205 entries_spanned_by_off is the number of times the loop below
206 would have executed.
207 */
208 size_t entries_spanned_by_off;
209
210 entries_spanned_by_off = off >> mr->page_shift;
211 off -= (entries_spanned_by_off << mr->page_shift);
212 m = entries_spanned_by_off/QIB_SEGSZ;
213 n = entries_spanned_by_off%QIB_SEGSZ;
214 } else {
215 m = 0;
216 n = 0;
217 while (off >= mr->map[m]->segs[n].length) {
218 off -= mr->map[m]->segs[n].length;
219 n++;
220 if (n >= QIB_SEGSZ) {
221 m++;
222 n = 0;
223 }
224 }
225 }
226 isge->mr = mr;
227 isge->vaddr = mr->map[m]->segs[n].vaddr + off;
228 isge->length = mr->map[m]->segs[n].length - off;
229 isge->sge_length = sge->length;
230 isge->m = m;
231 isge->n = n;
232ok:
233 return 1;
234bail:
235 rcu_read_unlock();
236 return 0;
237}
238
239/**
240 * qib_rkey_ok - check the IB virtual address, length, and RKEY 141 * qib_rkey_ok - check the IB virtual address, length, and RKEY
241 * @qp: qp for validation 142 * @qp: qp for validation
242 * @sge: SGE state 143 * @sge: SGE state
@@ -249,11 +150,11 @@ bail:
249 * 150 *
250 * increments the reference count upon success 151 * increments the reference count upon success
251 */ 152 */
252int qib_rkey_ok(struct qib_qp *qp, struct qib_sge *sge, 153int qib_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
253 u32 len, u64 vaddr, u32 rkey, int acc) 154 u32 len, u64 vaddr, u32 rkey, int acc)
254{ 155{
255 struct qib_lkey_table *rkt = &to_idev(qp->ibqp.device)->lk_table; 156 struct rvt_lkey_table *rkt = &to_idev(qp->ibqp.device)->lk_table;
256 struct qib_mregion *mr; 157 struct rvt_mregion *mr;
257 unsigned n, m; 158 unsigned n, m;
258 size_t off; 159 size_t off;
259 160
@@ -263,7 +164,7 @@ int qib_rkey_ok(struct qib_qp *qp, struct qib_sge *sge,
263 */ 164 */
264 rcu_read_lock(); 165 rcu_read_lock();
265 if (rkey == 0) { 166 if (rkey == 0) {
266 struct qib_pd *pd = to_ipd(qp->ibqp.pd); 167 struct rvt_pd *pd = ibpd_to_rvtpd(qp->ibqp.pd);
267 struct qib_ibdev *dev = to_idev(pd->ibpd.device); 168 struct qib_ibdev *dev = to_idev(pd->ibpd.device);
268 169
269 if (pd->user) 170 if (pd->user)
@@ -285,7 +186,7 @@ int qib_rkey_ok(struct qib_qp *qp, struct qib_sge *sge,
285 } 186 }
286 187
287 mr = rcu_dereference( 188 mr = rcu_dereference(
288 rkt->table[(rkey >> (32 - ib_qib_lkey_table_size))]); 189 rkt->table[(rkey >> (32 - ib_rvt_lkey_table_size))]);
289 if (unlikely(!mr || mr->lkey != rkey || qp->ibqp.pd != mr->pd)) 190 if (unlikely(!mr || mr->lkey != rkey || qp->ibqp.pd != mr->pd))
290 goto bail; 191 goto bail;
291 192
@@ -308,15 +209,15 @@ int qib_rkey_ok(struct qib_qp *qp, struct qib_sge *sge,
308 209
309 entries_spanned_by_off = off >> mr->page_shift; 210 entries_spanned_by_off = off >> mr->page_shift;
310 off -= (entries_spanned_by_off << mr->page_shift); 211 off -= (entries_spanned_by_off << mr->page_shift);
311 m = entries_spanned_by_off/QIB_SEGSZ; 212 m = entries_spanned_by_off / RVT_SEGSZ;
312 n = entries_spanned_by_off%QIB_SEGSZ; 213 n = entries_spanned_by_off % RVT_SEGSZ;
313 } else { 214 } else {
314 m = 0; 215 m = 0;
315 n = 0; 216 n = 0;
316 while (off >= mr->map[m]->segs[n].length) { 217 while (off >= mr->map[m]->segs[n].length) {
317 off -= mr->map[m]->segs[n].length; 218 off -= mr->map[m]->segs[n].length;
318 n++; 219 n++;
319 if (n >= QIB_SEGSZ) { 220 if (n >= RVT_SEGSZ) {
320 m++; 221 m++;
321 n = 0; 222 n = 0;
322 } 223 }
@@ -335,58 +236,3 @@ bail:
335 return 0; 236 return 0;
336} 237}
337 238
338/*
339 * Initialize the memory region specified by the work request.
340 */
341int qib_reg_mr(struct qib_qp *qp, struct ib_reg_wr *wr)
342{
343 struct qib_lkey_table *rkt = &to_idev(qp->ibqp.device)->lk_table;
344 struct qib_pd *pd = to_ipd(qp->ibqp.pd);
345 struct qib_mr *mr = to_imr(wr->mr);
346 struct qib_mregion *mrg;
347 u32 key = wr->key;
348 unsigned i, n, m;
349 int ret = -EINVAL;
350 unsigned long flags;
351 u64 *page_list;
352 size_t ps;
353
354 spin_lock_irqsave(&rkt->lock, flags);
355 if (pd->user || key == 0)
356 goto bail;
357
358 mrg = rcu_dereference_protected(
359 rkt->table[(key >> (32 - ib_qib_lkey_table_size))],
360 lockdep_is_held(&rkt->lock));
361 if (unlikely(mrg == NULL || qp->ibqp.pd != mrg->pd))
362 goto bail;
363
364 if (mr->npages > mrg->max_segs)
365 goto bail;
366
367 ps = mr->ibmr.page_size;
368 if (mr->ibmr.length > ps * mr->npages)
369 goto bail;
370
371 mrg->user_base = mr->ibmr.iova;
372 mrg->iova = mr->ibmr.iova;
373 mrg->lkey = key;
374 mrg->length = mr->ibmr.length;
375 mrg->access_flags = wr->access;
376 page_list = mr->pages;
377 m = 0;
378 n = 0;
379 for (i = 0; i < mr->npages; i++) {
380 mrg->map[m]->segs[n].vaddr = (void *) page_list[i];
381 mrg->map[m]->segs[n].length = ps;
382 if (++n == QIB_SEGSZ) {
383 m++;
384 n = 0;
385 }
386 }
387
388 ret = 0;
389bail:
390 spin_unlock_irqrestore(&rkt->lock, flags);
391 return ret;
392}
diff --git a/drivers/infiniband/hw/qib/qib_mad.c b/drivers/infiniband/hw/qib/qib_mad.c
index 9625e7c438e5..0bd18375d7df 100644
--- a/drivers/infiniband/hw/qib/qib_mad.c
+++ b/drivers/infiniband/hw/qib/qib_mad.c
@@ -70,7 +70,7 @@ static void qib_send_trap(struct qib_ibport *ibp, void *data, unsigned len)
70 unsigned long flags; 70 unsigned long flags;
71 unsigned long timeout; 71 unsigned long timeout;
72 72
73 agent = ibp->send_agent; 73 agent = ibp->rvp.send_agent;
74 if (!agent) 74 if (!agent)
75 return; 75 return;
76 76
@@ -79,7 +79,8 @@ static void qib_send_trap(struct qib_ibport *ibp, void *data, unsigned len)
79 return; 79 return;
80 80
81 /* o14-2 */ 81 /* o14-2 */
82 if (ibp->trap_timeout && time_before(jiffies, ibp->trap_timeout)) 82 if (ibp->rvp.trap_timeout &&
83 time_before(jiffies, ibp->rvp.trap_timeout))
83 return; 84 return;
84 85
85 send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR, 86 send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
@@ -93,42 +94,42 @@ static void qib_send_trap(struct qib_ibport *ibp, void *data, unsigned len)
93 smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; 94 smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
94 smp->class_version = 1; 95 smp->class_version = 1;
95 smp->method = IB_MGMT_METHOD_TRAP; 96 smp->method = IB_MGMT_METHOD_TRAP;
96 ibp->tid++; 97 ibp->rvp.tid++;
97 smp->tid = cpu_to_be64(ibp->tid); 98 smp->tid = cpu_to_be64(ibp->rvp.tid);
98 smp->attr_id = IB_SMP_ATTR_NOTICE; 99 smp->attr_id = IB_SMP_ATTR_NOTICE;
99 /* o14-1: smp->mkey = 0; */ 100 /* o14-1: smp->mkey = 0; */
100 memcpy(smp->data, data, len); 101 memcpy(smp->data, data, len);
101 102
102 spin_lock_irqsave(&ibp->lock, flags); 103 spin_lock_irqsave(&ibp->rvp.lock, flags);
103 if (!ibp->sm_ah) { 104 if (!ibp->rvp.sm_ah) {
104 if (ibp->sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) { 105 if (ibp->rvp.sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
105 struct ib_ah *ah; 106 struct ib_ah *ah;
106 107
107 ah = qib_create_qp0_ah(ibp, ibp->sm_lid); 108 ah = qib_create_qp0_ah(ibp, ibp->rvp.sm_lid);
108 if (IS_ERR(ah)) 109 if (IS_ERR(ah))
109 ret = PTR_ERR(ah); 110 ret = PTR_ERR(ah);
110 else { 111 else {
111 send_buf->ah = ah; 112 send_buf->ah = ah;
112 ibp->sm_ah = to_iah(ah); 113 ibp->rvp.sm_ah = ibah_to_rvtah(ah);
113 ret = 0; 114 ret = 0;
114 } 115 }
115 } else 116 } else
116 ret = -EINVAL; 117 ret = -EINVAL;
117 } else { 118 } else {
118 send_buf->ah = &ibp->sm_ah->ibah; 119 send_buf->ah = &ibp->rvp.sm_ah->ibah;
119 ret = 0; 120 ret = 0;
120 } 121 }
121 spin_unlock_irqrestore(&ibp->lock, flags); 122 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
122 123
123 if (!ret) 124 if (!ret)
124 ret = ib_post_send_mad(send_buf, NULL); 125 ret = ib_post_send_mad(send_buf, NULL);
125 if (!ret) { 126 if (!ret) {
126 /* 4.096 usec. */ 127 /* 4.096 usec. */
127 timeout = (4096 * (1UL << ibp->subnet_timeout)) / 1000; 128 timeout = (4096 * (1UL << ibp->rvp.subnet_timeout)) / 1000;
128 ibp->trap_timeout = jiffies + usecs_to_jiffies(timeout); 129 ibp->rvp.trap_timeout = jiffies + usecs_to_jiffies(timeout);
129 } else { 130 } else {
130 ib_free_send_mad(send_buf); 131 ib_free_send_mad(send_buf);
131 ibp->trap_timeout = 0; 132 ibp->rvp.trap_timeout = 0;
132 } 133 }
133} 134}
134 135
@@ -141,10 +142,10 @@ void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
141 struct ib_mad_notice_attr data; 142 struct ib_mad_notice_attr data;
142 143
143 if (trap_num == IB_NOTICE_TRAP_BAD_PKEY) 144 if (trap_num == IB_NOTICE_TRAP_BAD_PKEY)
144 ibp->pkey_violations++; 145 ibp->rvp.pkey_violations++;
145 else 146 else
146 ibp->qkey_violations++; 147 ibp->rvp.qkey_violations++;
147 ibp->n_pkt_drops++; 148 ibp->rvp.n_pkt_drops++;
148 149
149 /* Send violation trap */ 150 /* Send violation trap */
150 data.generic_type = IB_NOTICE_TYPE_SECURITY; 151 data.generic_type = IB_NOTICE_TYPE_SECURITY;
@@ -205,8 +206,11 @@ static void qib_bad_mkey(struct qib_ibport *ibp, struct ib_smp *smp)
205/* 206/*
206 * Send a Port Capability Mask Changed trap (ch. 14.3.11). 207 * Send a Port Capability Mask Changed trap (ch. 14.3.11).
207 */ 208 */
208void qib_cap_mask_chg(struct qib_ibport *ibp) 209void qib_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num)
209{ 210{
211 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
212 struct qib_devdata *dd = dd_from_dev(ibdev);
213 struct qib_ibport *ibp = &dd->pport[port_num - 1].ibport_data;
210 struct ib_mad_notice_attr data; 214 struct ib_mad_notice_attr data;
211 215
212 data.generic_type = IB_NOTICE_TYPE_INFO; 216 data.generic_type = IB_NOTICE_TYPE_INFO;
@@ -217,8 +221,8 @@ void qib_cap_mask_chg(struct qib_ibport *ibp)
217 data.toggle_count = 0; 221 data.toggle_count = 0;
218 memset(&data.details, 0, sizeof(data.details)); 222 memset(&data.details, 0, sizeof(data.details));
219 data.details.ntc_144.lid = data.issuer_lid; 223 data.details.ntc_144.lid = data.issuer_lid;
220 data.details.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags); 224 data.details.ntc_144.new_cap_mask =
221 225 cpu_to_be32(ibp->rvp.port_cap_flags);
222 qib_send_trap(ibp, &data, sizeof(data)); 226 qib_send_trap(ibp, &data, sizeof(data));
223} 227}
224 228
@@ -409,37 +413,38 @@ static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags)
409 int ret = 0; 413 int ret = 0;
410 414
411 /* Is the mkey in the process of expiring? */ 415 /* Is the mkey in the process of expiring? */
412 if (ibp->mkey_lease_timeout && 416 if (ibp->rvp.mkey_lease_timeout &&
413 time_after_eq(jiffies, ibp->mkey_lease_timeout)) { 417 time_after_eq(jiffies, ibp->rvp.mkey_lease_timeout)) {
414 /* Clear timeout and mkey protection field. */ 418 /* Clear timeout and mkey protection field. */
415 ibp->mkey_lease_timeout = 0; 419 ibp->rvp.mkey_lease_timeout = 0;
416 ibp->mkeyprot = 0; 420 ibp->rvp.mkeyprot = 0;
417 } 421 }
418 422
419 if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->mkey == 0 || 423 if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->rvp.mkey == 0 ||
420 ibp->mkey == smp->mkey) 424 ibp->rvp.mkey == smp->mkey)
421 valid_mkey = 1; 425 valid_mkey = 1;
422 426
423 /* Unset lease timeout on any valid Get/Set/TrapRepress */ 427 /* Unset lease timeout on any valid Get/Set/TrapRepress */
424 if (valid_mkey && ibp->mkey_lease_timeout && 428 if (valid_mkey && ibp->rvp.mkey_lease_timeout &&
425 (smp->method == IB_MGMT_METHOD_GET || 429 (smp->method == IB_MGMT_METHOD_GET ||
426 smp->method == IB_MGMT_METHOD_SET || 430 smp->method == IB_MGMT_METHOD_SET ||
427 smp->method == IB_MGMT_METHOD_TRAP_REPRESS)) 431 smp->method == IB_MGMT_METHOD_TRAP_REPRESS))
428 ibp->mkey_lease_timeout = 0; 432 ibp->rvp.mkey_lease_timeout = 0;
429 433
430 if (!valid_mkey) { 434 if (!valid_mkey) {
431 switch (smp->method) { 435 switch (smp->method) {
432 case IB_MGMT_METHOD_GET: 436 case IB_MGMT_METHOD_GET:
433 /* Bad mkey not a violation below level 2 */ 437 /* Bad mkey not a violation below level 2 */
434 if (ibp->mkeyprot < 2) 438 if (ibp->rvp.mkeyprot < 2)
435 break; 439 break;
436 case IB_MGMT_METHOD_SET: 440 case IB_MGMT_METHOD_SET:
437 case IB_MGMT_METHOD_TRAP_REPRESS: 441 case IB_MGMT_METHOD_TRAP_REPRESS:
438 if (ibp->mkey_violations != 0xFFFF) 442 if (ibp->rvp.mkey_violations != 0xFFFF)
439 ++ibp->mkey_violations; 443 ++ibp->rvp.mkey_violations;
440 if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period) 444 if (!ibp->rvp.mkey_lease_timeout &&
441 ibp->mkey_lease_timeout = jiffies + 445 ibp->rvp.mkey_lease_period)
442 ibp->mkey_lease_period * HZ; 446 ibp->rvp.mkey_lease_timeout = jiffies +
447 ibp->rvp.mkey_lease_period * HZ;
443 /* Generate a trap notice. */ 448 /* Generate a trap notice. */
444 qib_bad_mkey(ibp, smp); 449 qib_bad_mkey(ibp, smp);
445 ret = 1; 450 ret = 1;
@@ -489,15 +494,15 @@ static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
489 494
490 /* Only return the mkey if the protection field allows it. */ 495 /* Only return the mkey if the protection field allows it. */
491 if (!(smp->method == IB_MGMT_METHOD_GET && 496 if (!(smp->method == IB_MGMT_METHOD_GET &&
492 ibp->mkey != smp->mkey && 497 ibp->rvp.mkey != smp->mkey &&
493 ibp->mkeyprot == 1)) 498 ibp->rvp.mkeyprot == 1))
494 pip->mkey = ibp->mkey; 499 pip->mkey = ibp->rvp.mkey;
495 pip->gid_prefix = ibp->gid_prefix; 500 pip->gid_prefix = ibp->rvp.gid_prefix;
496 pip->lid = cpu_to_be16(ppd->lid); 501 pip->lid = cpu_to_be16(ppd->lid);
497 pip->sm_lid = cpu_to_be16(ibp->sm_lid); 502 pip->sm_lid = cpu_to_be16(ibp->rvp.sm_lid);
498 pip->cap_mask = cpu_to_be32(ibp->port_cap_flags); 503 pip->cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
499 /* pip->diag_code; */ 504 /* pip->diag_code; */
500 pip->mkey_lease_period = cpu_to_be16(ibp->mkey_lease_period); 505 pip->mkey_lease_period = cpu_to_be16(ibp->rvp.mkey_lease_period);
501 pip->local_port_num = port; 506 pip->local_port_num = port;
502 pip->link_width_enabled = ppd->link_width_enabled; 507 pip->link_width_enabled = ppd->link_width_enabled;
503 pip->link_width_supported = ppd->link_width_supported; 508 pip->link_width_supported = ppd->link_width_supported;
@@ -508,7 +513,7 @@ static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
508 pip->portphysstate_linkdown = 513 pip->portphysstate_linkdown =
509 (dd->f_ibphys_portstate(ppd->lastibcstat) << 4) | 514 (dd->f_ibphys_portstate(ppd->lastibcstat) << 4) |
510 (get_linkdowndefaultstate(ppd) ? 1 : 2); 515 (get_linkdowndefaultstate(ppd) ? 1 : 2);
511 pip->mkeyprot_resv_lmc = (ibp->mkeyprot << 6) | ppd->lmc; 516 pip->mkeyprot_resv_lmc = (ibp->rvp.mkeyprot << 6) | ppd->lmc;
512 pip->linkspeedactive_enabled = (ppd->link_speed_active << 4) | 517 pip->linkspeedactive_enabled = (ppd->link_speed_active << 4) |
513 ppd->link_speed_enabled; 518 ppd->link_speed_enabled;
514 switch (ppd->ibmtu) { 519 switch (ppd->ibmtu) {
@@ -529,9 +534,9 @@ static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
529 mtu = IB_MTU_256; 534 mtu = IB_MTU_256;
530 break; 535 break;
531 } 536 }
532 pip->neighbormtu_mastersmsl = (mtu << 4) | ibp->sm_sl; 537 pip->neighbormtu_mastersmsl = (mtu << 4) | ibp->rvp.sm_sl;
533 pip->vlcap_inittype = ppd->vls_supported << 4; /* InitType = 0 */ 538 pip->vlcap_inittype = ppd->vls_supported << 4; /* InitType = 0 */
534 pip->vl_high_limit = ibp->vl_high_limit; 539 pip->vl_high_limit = ibp->rvp.vl_high_limit;
535 pip->vl_arb_high_cap = 540 pip->vl_arb_high_cap =
536 dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_CAP); 541 dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_CAP);
537 pip->vl_arb_low_cap = 542 pip->vl_arb_low_cap =
@@ -542,20 +547,20 @@ static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
542 /* pip->vlstallcnt_hoqlife; */ 547 /* pip->vlstallcnt_hoqlife; */
543 pip->operationalvl_pei_peo_fpi_fpo = 548 pip->operationalvl_pei_peo_fpi_fpo =
544 dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OP_VLS) << 4; 549 dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OP_VLS) << 4;
545 pip->mkey_violations = cpu_to_be16(ibp->mkey_violations); 550 pip->mkey_violations = cpu_to_be16(ibp->rvp.mkey_violations);
546 /* P_KeyViolations are counted by hardware. */ 551 /* P_KeyViolations are counted by hardware. */
547 pip->pkey_violations = cpu_to_be16(ibp->pkey_violations); 552 pip->pkey_violations = cpu_to_be16(ibp->rvp.pkey_violations);
548 pip->qkey_violations = cpu_to_be16(ibp->qkey_violations); 553 pip->qkey_violations = cpu_to_be16(ibp->rvp.qkey_violations);
549 /* Only the hardware GUID is supported for now */ 554 /* Only the hardware GUID is supported for now */
550 pip->guid_cap = QIB_GUIDS_PER_PORT; 555 pip->guid_cap = QIB_GUIDS_PER_PORT;
551 pip->clientrereg_resv_subnetto = ibp->subnet_timeout; 556 pip->clientrereg_resv_subnetto = ibp->rvp.subnet_timeout;
552 /* 32.768 usec. response time (guessing) */ 557 /* 32.768 usec. response time (guessing) */
553 pip->resv_resptimevalue = 3; 558 pip->resv_resptimevalue = 3;
554 pip->localphyerrors_overrunerrors = 559 pip->localphyerrors_overrunerrors =
555 (get_phyerrthreshold(ppd) << 4) | 560 (get_phyerrthreshold(ppd) << 4) |
556 get_overrunthreshold(ppd); 561 get_overrunthreshold(ppd);
557 /* pip->max_credit_hint; */ 562 /* pip->max_credit_hint; */
558 if (ibp->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) { 563 if (ibp->rvp.port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
559 u32 v; 564 u32 v;
560 565
561 v = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKLATENCY); 566 v = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKLATENCY);
@@ -685,13 +690,13 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
685 event.device = ibdev; 690 event.device = ibdev;
686 event.element.port_num = port; 691 event.element.port_num = port;
687 692
688 ibp->mkey = pip->mkey; 693 ibp->rvp.mkey = pip->mkey;
689 ibp->gid_prefix = pip->gid_prefix; 694 ibp->rvp.gid_prefix = pip->gid_prefix;
690 ibp->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period); 695 ibp->rvp.mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
691 696
692 lid = be16_to_cpu(pip->lid); 697 lid = be16_to_cpu(pip->lid);
693 /* Must be a valid unicast LID address. */ 698 /* Must be a valid unicast LID address. */
694 if (lid == 0 || lid >= QIB_MULTICAST_LID_BASE) 699 if (lid == 0 || lid >= be16_to_cpu(IB_MULTICAST_LID_BASE))
695 smp->status |= IB_SMP_INVALID_FIELD; 700 smp->status |= IB_SMP_INVALID_FIELD;
696 else if (ppd->lid != lid || ppd->lmc != (pip->mkeyprot_resv_lmc & 7)) { 701 else if (ppd->lid != lid || ppd->lmc != (pip->mkeyprot_resv_lmc & 7)) {
697 if (ppd->lid != lid) 702 if (ppd->lid != lid)
@@ -706,21 +711,21 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
706 smlid = be16_to_cpu(pip->sm_lid); 711 smlid = be16_to_cpu(pip->sm_lid);
707 msl = pip->neighbormtu_mastersmsl & 0xF; 712 msl = pip->neighbormtu_mastersmsl & 0xF;
708 /* Must be a valid unicast LID address. */ 713 /* Must be a valid unicast LID address. */
709 if (smlid == 0 || smlid >= QIB_MULTICAST_LID_BASE) 714 if (smlid == 0 || smlid >= be16_to_cpu(IB_MULTICAST_LID_BASE))
710 smp->status |= IB_SMP_INVALID_FIELD; 715 smp->status |= IB_SMP_INVALID_FIELD;
711 else if (smlid != ibp->sm_lid || msl != ibp->sm_sl) { 716 else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) {
712 spin_lock_irqsave(&ibp->lock, flags); 717 spin_lock_irqsave(&ibp->rvp.lock, flags);
713 if (ibp->sm_ah) { 718 if (ibp->rvp.sm_ah) {
714 if (smlid != ibp->sm_lid) 719 if (smlid != ibp->rvp.sm_lid)
715 ibp->sm_ah->attr.dlid = smlid; 720 ibp->rvp.sm_ah->attr.dlid = smlid;
716 if (msl != ibp->sm_sl) 721 if (msl != ibp->rvp.sm_sl)
717 ibp->sm_ah->attr.sl = msl; 722 ibp->rvp.sm_ah->attr.sl = msl;
718 } 723 }
719 spin_unlock_irqrestore(&ibp->lock, flags); 724 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
720 if (smlid != ibp->sm_lid) 725 if (smlid != ibp->rvp.sm_lid)
721 ibp->sm_lid = smlid; 726 ibp->rvp.sm_lid = smlid;
722 if (msl != ibp->sm_sl) 727 if (msl != ibp->rvp.sm_sl)
723 ibp->sm_sl = msl; 728 ibp->rvp.sm_sl = msl;
724 event.event = IB_EVENT_SM_CHANGE; 729 event.event = IB_EVENT_SM_CHANGE;
725 ib_dispatch_event(&event); 730 ib_dispatch_event(&event);
726 } 731 }
@@ -768,10 +773,10 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
768 smp->status |= IB_SMP_INVALID_FIELD; 773 smp->status |= IB_SMP_INVALID_FIELD;
769 } 774 }
770 775
771 ibp->mkeyprot = pip->mkeyprot_resv_lmc >> 6; 776 ibp->rvp.mkeyprot = pip->mkeyprot_resv_lmc >> 6;
772 ibp->vl_high_limit = pip->vl_high_limit; 777 ibp->rvp.vl_high_limit = pip->vl_high_limit;
773 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_LIMIT, 778 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_LIMIT,
774 ibp->vl_high_limit); 779 ibp->rvp.vl_high_limit);
775 780
776 mtu = ib_mtu_enum_to_int((pip->neighbormtu_mastersmsl >> 4) & 0xF); 781 mtu = ib_mtu_enum_to_int((pip->neighbormtu_mastersmsl >> 4) & 0xF);
777 if (mtu == -1) 782 if (mtu == -1)
@@ -789,13 +794,13 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
789 } 794 }
790 795
791 if (pip->mkey_violations == 0) 796 if (pip->mkey_violations == 0)
792 ibp->mkey_violations = 0; 797 ibp->rvp.mkey_violations = 0;
793 798
794 if (pip->pkey_violations == 0) 799 if (pip->pkey_violations == 0)
795 ibp->pkey_violations = 0; 800 ibp->rvp.pkey_violations = 0;
796 801
797 if (pip->qkey_violations == 0) 802 if (pip->qkey_violations == 0)
798 ibp->qkey_violations = 0; 803 ibp->rvp.qkey_violations = 0;
799 804
800 ore = pip->localphyerrors_overrunerrors; 805 ore = pip->localphyerrors_overrunerrors;
801 if (set_phyerrthreshold(ppd, (ore >> 4) & 0xF)) 806 if (set_phyerrthreshold(ppd, (ore >> 4) & 0xF))
@@ -804,7 +809,7 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
804 if (set_overrunthreshold(ppd, (ore & 0xF))) 809 if (set_overrunthreshold(ppd, (ore & 0xF)))
805 smp->status |= IB_SMP_INVALID_FIELD; 810 smp->status |= IB_SMP_INVALID_FIELD;
806 811
807 ibp->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F; 812 ibp->rvp.subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
808 813
809 /* 814 /*
810 * Do the port state change now that the other link parameters 815 * Do the port state change now that the other link parameters
@@ -1028,7 +1033,7 @@ static int set_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys)
1028 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0); 1033 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0);
1029 1034
1030 event.event = IB_EVENT_PKEY_CHANGE; 1035 event.event = IB_EVENT_PKEY_CHANGE;
1031 event.device = &dd->verbs_dev.ibdev; 1036 event.device = &dd->verbs_dev.rdi.ibdev;
1032 event.element.port_num = port; 1037 event.element.port_num = port;
1033 ib_dispatch_event(&event); 1038 ib_dispatch_event(&event);
1034 } 1039 }
@@ -1062,7 +1067,7 @@ static int subn_get_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
1062 1067
1063 memset(smp->data, 0, sizeof(smp->data)); 1068 memset(smp->data, 0, sizeof(smp->data));
1064 1069
1065 if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP)) 1070 if (!(ibp->rvp.port_cap_flags & IB_PORT_SL_MAP_SUP))
1066 smp->status |= IB_SMP_UNSUP_METHOD; 1071 smp->status |= IB_SMP_UNSUP_METHOD;
1067 else 1072 else
1068 for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2) 1073 for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2)
@@ -1078,7 +1083,7 @@ static int subn_set_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
1078 u8 *p = (u8 *) smp->data; 1083 u8 *p = (u8 *) smp->data;
1079 unsigned i; 1084 unsigned i;
1080 1085
1081 if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP)) { 1086 if (!(ibp->rvp.port_cap_flags & IB_PORT_SL_MAP_SUP)) {
1082 smp->status |= IB_SMP_UNSUP_METHOD; 1087 smp->status |= IB_SMP_UNSUP_METHOD;
1083 return reply(smp); 1088 return reply(smp);
1084 } 1089 }
@@ -1195,20 +1200,20 @@ static int pma_get_portsamplescontrol(struct ib_pma_mad *pmp,
1195 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; 1200 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
1196 goto bail; 1201 goto bail;
1197 } 1202 }
1198 spin_lock_irqsave(&ibp->lock, flags); 1203 spin_lock_irqsave(&ibp->rvp.lock, flags);
1199 p->tick = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PMA_TICKS); 1204 p->tick = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PMA_TICKS);
1200 p->sample_status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT); 1205 p->sample_status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
1201 p->counter_width = 4; /* 32 bit counters */ 1206 p->counter_width = 4; /* 32 bit counters */
1202 p->counter_mask0_9 = COUNTER_MASK0_9; 1207 p->counter_mask0_9 = COUNTER_MASK0_9;
1203 p->sample_start = cpu_to_be32(ibp->pma_sample_start); 1208 p->sample_start = cpu_to_be32(ibp->rvp.pma_sample_start);
1204 p->sample_interval = cpu_to_be32(ibp->pma_sample_interval); 1209 p->sample_interval = cpu_to_be32(ibp->rvp.pma_sample_interval);
1205 p->tag = cpu_to_be16(ibp->pma_tag); 1210 p->tag = cpu_to_be16(ibp->rvp.pma_tag);
1206 p->counter_select[0] = ibp->pma_counter_select[0]; 1211 p->counter_select[0] = ibp->rvp.pma_counter_select[0];
1207 p->counter_select[1] = ibp->pma_counter_select[1]; 1212 p->counter_select[1] = ibp->rvp.pma_counter_select[1];
1208 p->counter_select[2] = ibp->pma_counter_select[2]; 1213 p->counter_select[2] = ibp->rvp.pma_counter_select[2];
1209 p->counter_select[3] = ibp->pma_counter_select[3]; 1214 p->counter_select[3] = ibp->rvp.pma_counter_select[3];
1210 p->counter_select[4] = ibp->pma_counter_select[4]; 1215 p->counter_select[4] = ibp->rvp.pma_counter_select[4];
1211 spin_unlock_irqrestore(&ibp->lock, flags); 1216 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
1212 1217
1213bail: 1218bail:
1214 return reply((struct ib_smp *) pmp); 1219 return reply((struct ib_smp *) pmp);
@@ -1233,7 +1238,7 @@ static int pma_set_portsamplescontrol(struct ib_pma_mad *pmp,
1233 goto bail; 1238 goto bail;
1234 } 1239 }
1235 1240
1236 spin_lock_irqsave(&ibp->lock, flags); 1241 spin_lock_irqsave(&ibp->rvp.lock, flags);
1237 1242
1238 /* Port Sampling code owns the PS* HW counters */ 1243 /* Port Sampling code owns the PS* HW counters */
1239 xmit_flags = ppd->cong_stats.flags; 1244 xmit_flags = ppd->cong_stats.flags;
@@ -1242,18 +1247,18 @@ static int pma_set_portsamplescontrol(struct ib_pma_mad *pmp,
1242 if (status == IB_PMA_SAMPLE_STATUS_DONE || 1247 if (status == IB_PMA_SAMPLE_STATUS_DONE ||
1243 (status == IB_PMA_SAMPLE_STATUS_RUNNING && 1248 (status == IB_PMA_SAMPLE_STATUS_RUNNING &&
1244 xmit_flags == IB_PMA_CONG_HW_CONTROL_TIMER)) { 1249 xmit_flags == IB_PMA_CONG_HW_CONTROL_TIMER)) {
1245 ibp->pma_sample_start = be32_to_cpu(p->sample_start); 1250 ibp->rvp.pma_sample_start = be32_to_cpu(p->sample_start);
1246 ibp->pma_sample_interval = be32_to_cpu(p->sample_interval); 1251 ibp->rvp.pma_sample_interval = be32_to_cpu(p->sample_interval);
1247 ibp->pma_tag = be16_to_cpu(p->tag); 1252 ibp->rvp.pma_tag = be16_to_cpu(p->tag);
1248 ibp->pma_counter_select[0] = p->counter_select[0]; 1253 ibp->rvp.pma_counter_select[0] = p->counter_select[0];
1249 ibp->pma_counter_select[1] = p->counter_select[1]; 1254 ibp->rvp.pma_counter_select[1] = p->counter_select[1];
1250 ibp->pma_counter_select[2] = p->counter_select[2]; 1255 ibp->rvp.pma_counter_select[2] = p->counter_select[2];
1251 ibp->pma_counter_select[3] = p->counter_select[3]; 1256 ibp->rvp.pma_counter_select[3] = p->counter_select[3];
1252 ibp->pma_counter_select[4] = p->counter_select[4]; 1257 ibp->rvp.pma_counter_select[4] = p->counter_select[4];
1253 dd->f_set_cntr_sample(ppd, ibp->pma_sample_interval, 1258 dd->f_set_cntr_sample(ppd, ibp->rvp.pma_sample_interval,
1254 ibp->pma_sample_start); 1259 ibp->rvp.pma_sample_start);
1255 } 1260 }
1256 spin_unlock_irqrestore(&ibp->lock, flags); 1261 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
1257 1262
1258 ret = pma_get_portsamplescontrol(pmp, ibdev, port); 1263 ret = pma_get_portsamplescontrol(pmp, ibdev, port);
1259 1264
@@ -1357,8 +1362,8 @@ static int pma_get_portsamplesresult(struct ib_pma_mad *pmp,
1357 int i; 1362 int i;
1358 1363
1359 memset(pmp->data, 0, sizeof(pmp->data)); 1364 memset(pmp->data, 0, sizeof(pmp->data));
1360 spin_lock_irqsave(&ibp->lock, flags); 1365 spin_lock_irqsave(&ibp->rvp.lock, flags);
1361 p->tag = cpu_to_be16(ibp->pma_tag); 1366 p->tag = cpu_to_be16(ibp->rvp.pma_tag);
1362 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER) 1367 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
1363 p->sample_status = IB_PMA_SAMPLE_STATUS_DONE; 1368 p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
1364 else { 1369 else {
@@ -1373,11 +1378,11 @@ static int pma_get_portsamplesresult(struct ib_pma_mad *pmp,
1373 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER; 1378 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
1374 } 1379 }
1375 } 1380 }
1376 for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++) 1381 for (i = 0; i < ARRAY_SIZE(ibp->rvp.pma_counter_select); i++)
1377 p->counter[i] = cpu_to_be32( 1382 p->counter[i] = cpu_to_be32(
1378 get_cache_hw_sample_counters( 1383 get_cache_hw_sample_counters(
1379 ppd, ibp->pma_counter_select[i])); 1384 ppd, ibp->rvp.pma_counter_select[i]));
1380 spin_unlock_irqrestore(&ibp->lock, flags); 1385 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
1381 1386
1382 return reply((struct ib_smp *) pmp); 1387 return reply((struct ib_smp *) pmp);
1383} 1388}
@@ -1397,8 +1402,8 @@ static int pma_get_portsamplesresult_ext(struct ib_pma_mad *pmp,
1397 1402
1398 /* Port Sampling code owns the PS* HW counters */ 1403 /* Port Sampling code owns the PS* HW counters */
1399 memset(pmp->data, 0, sizeof(pmp->data)); 1404 memset(pmp->data, 0, sizeof(pmp->data));
1400 spin_lock_irqsave(&ibp->lock, flags); 1405 spin_lock_irqsave(&ibp->rvp.lock, flags);
1401 p->tag = cpu_to_be16(ibp->pma_tag); 1406 p->tag = cpu_to_be16(ibp->rvp.pma_tag);
1402 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER) 1407 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
1403 p->sample_status = IB_PMA_SAMPLE_STATUS_DONE; 1408 p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
1404 else { 1409 else {
@@ -1415,11 +1420,11 @@ static int pma_get_portsamplesresult_ext(struct ib_pma_mad *pmp,
1415 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER; 1420 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
1416 } 1421 }
1417 } 1422 }
1418 for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++) 1423 for (i = 0; i < ARRAY_SIZE(ibp->rvp.pma_counter_select); i++)
1419 p->counter[i] = cpu_to_be64( 1424 p->counter[i] = cpu_to_be64(
1420 get_cache_hw_sample_counters( 1425 get_cache_hw_sample_counters(
1421 ppd, ibp->pma_counter_select[i])); 1426 ppd, ibp->rvp.pma_counter_select[i]));
1422 spin_unlock_irqrestore(&ibp->lock, flags); 1427 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
1423 1428
1424 return reply((struct ib_smp *) pmp); 1429 return reply((struct ib_smp *) pmp);
1425} 1430}
@@ -1453,7 +1458,7 @@ static int pma_get_portcounters(struct ib_pma_mad *pmp,
1453 cntrs.excessive_buffer_overrun_errors -= 1458 cntrs.excessive_buffer_overrun_errors -=
1454 ibp->z_excessive_buffer_overrun_errors; 1459 ibp->z_excessive_buffer_overrun_errors;
1455 cntrs.vl15_dropped -= ibp->z_vl15_dropped; 1460 cntrs.vl15_dropped -= ibp->z_vl15_dropped;
1456 cntrs.vl15_dropped += ibp->n_vl15_dropped; 1461 cntrs.vl15_dropped += ibp->rvp.n_vl15_dropped;
1457 1462
1458 memset(pmp->data, 0, sizeof(pmp->data)); 1463 memset(pmp->data, 0, sizeof(pmp->data));
1459 1464
@@ -1546,9 +1551,9 @@ static int pma_get_portcounters_cong(struct ib_pma_mad *pmp,
1546 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; 1551 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
1547 1552
1548 qib_get_counters(ppd, &cntrs); 1553 qib_get_counters(ppd, &cntrs);
1549 spin_lock_irqsave(&ppd->ibport_data.lock, flags); 1554 spin_lock_irqsave(&ppd->ibport_data.rvp.lock, flags);
1550 xmit_wait_counter = xmit_wait_get_value_delta(ppd); 1555 xmit_wait_counter = xmit_wait_get_value_delta(ppd);
1551 spin_unlock_irqrestore(&ppd->ibport_data.lock, flags); 1556 spin_unlock_irqrestore(&ppd->ibport_data.rvp.lock, flags);
1552 1557
1553 /* Adjust counters for any resets done. */ 1558 /* Adjust counters for any resets done. */
1554 cntrs.symbol_error_counter -= ibp->z_symbol_error_counter; 1559 cntrs.symbol_error_counter -= ibp->z_symbol_error_counter;
@@ -1564,7 +1569,7 @@ static int pma_get_portcounters_cong(struct ib_pma_mad *pmp,
1564 cntrs.excessive_buffer_overrun_errors -= 1569 cntrs.excessive_buffer_overrun_errors -=
1565 ibp->z_excessive_buffer_overrun_errors; 1570 ibp->z_excessive_buffer_overrun_errors;
1566 cntrs.vl15_dropped -= ibp->z_vl15_dropped; 1571 cntrs.vl15_dropped -= ibp->z_vl15_dropped;
1567 cntrs.vl15_dropped += ibp->n_vl15_dropped; 1572 cntrs.vl15_dropped += ibp->rvp.n_vl15_dropped;
1568 cntrs.port_xmit_data -= ibp->z_port_xmit_data; 1573 cntrs.port_xmit_data -= ibp->z_port_xmit_data;
1569 cntrs.port_rcv_data -= ibp->z_port_rcv_data; 1574 cntrs.port_rcv_data -= ibp->z_port_rcv_data;
1570 cntrs.port_xmit_packets -= ibp->z_port_xmit_packets; 1575 cntrs.port_xmit_packets -= ibp->z_port_xmit_packets;
@@ -1743,7 +1748,7 @@ static int pma_set_portcounters(struct ib_pma_mad *pmp,
1743 cntrs.excessive_buffer_overrun_errors; 1748 cntrs.excessive_buffer_overrun_errors;
1744 1749
1745 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) { 1750 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
1746 ibp->n_vl15_dropped = 0; 1751 ibp->rvp.n_vl15_dropped = 0;
1747 ibp->z_vl15_dropped = cntrs.vl15_dropped; 1752 ibp->z_vl15_dropped = cntrs.vl15_dropped;
1748 } 1753 }
1749 1754
@@ -1778,11 +1783,11 @@ static int pma_set_portcounters_cong(struct ib_pma_mad *pmp,
1778 ret = pma_get_portcounters_cong(pmp, ibdev, port); 1783 ret = pma_get_portcounters_cong(pmp, ibdev, port);
1779 1784
1780 if (counter_select & IB_PMA_SEL_CONG_XMIT) { 1785 if (counter_select & IB_PMA_SEL_CONG_XMIT) {
1781 spin_lock_irqsave(&ppd->ibport_data.lock, flags); 1786 spin_lock_irqsave(&ppd->ibport_data.rvp.lock, flags);
1782 ppd->cong_stats.counter = 0; 1787 ppd->cong_stats.counter = 0;
1783 dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, 1788 dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL,
1784 0x0); 1789 0x0);
1785 spin_unlock_irqrestore(&ppd->ibport_data.lock, flags); 1790 spin_unlock_irqrestore(&ppd->ibport_data.rvp.lock, flags);
1786 } 1791 }
1787 if (counter_select & IB_PMA_SEL_CONG_PORT_DATA) { 1792 if (counter_select & IB_PMA_SEL_CONG_PORT_DATA) {
1788 ibp->z_port_xmit_data = cntrs.port_xmit_data; 1793 ibp->z_port_xmit_data = cntrs.port_xmit_data;
@@ -1806,7 +1811,7 @@ static int pma_set_portcounters_cong(struct ib_pma_mad *pmp,
1806 cntrs.local_link_integrity_errors; 1811 cntrs.local_link_integrity_errors;
1807 ibp->z_excessive_buffer_overrun_errors = 1812 ibp->z_excessive_buffer_overrun_errors =
1808 cntrs.excessive_buffer_overrun_errors; 1813 cntrs.excessive_buffer_overrun_errors;
1809 ibp->n_vl15_dropped = 0; 1814 ibp->rvp.n_vl15_dropped = 0;
1810 ibp->z_vl15_dropped = cntrs.vl15_dropped; 1815 ibp->z_vl15_dropped = cntrs.vl15_dropped;
1811 } 1816 }
1812 1817
@@ -1916,12 +1921,12 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
1916 ret = subn_get_vl_arb(smp, ibdev, port); 1921 ret = subn_get_vl_arb(smp, ibdev, port);
1917 goto bail; 1922 goto bail;
1918 case IB_SMP_ATTR_SM_INFO: 1923 case IB_SMP_ATTR_SM_INFO:
1919 if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) { 1924 if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) {
1920 ret = IB_MAD_RESULT_SUCCESS | 1925 ret = IB_MAD_RESULT_SUCCESS |
1921 IB_MAD_RESULT_CONSUMED; 1926 IB_MAD_RESULT_CONSUMED;
1922 goto bail; 1927 goto bail;
1923 } 1928 }
1924 if (ibp->port_cap_flags & IB_PORT_SM) { 1929 if (ibp->rvp.port_cap_flags & IB_PORT_SM) {
1925 ret = IB_MAD_RESULT_SUCCESS; 1930 ret = IB_MAD_RESULT_SUCCESS;
1926 goto bail; 1931 goto bail;
1927 } 1932 }
@@ -1950,12 +1955,12 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
1950 ret = subn_set_vl_arb(smp, ibdev, port); 1955 ret = subn_set_vl_arb(smp, ibdev, port);
1951 goto bail; 1956 goto bail;
1952 case IB_SMP_ATTR_SM_INFO: 1957 case IB_SMP_ATTR_SM_INFO:
1953 if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) { 1958 if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) {
1954 ret = IB_MAD_RESULT_SUCCESS | 1959 ret = IB_MAD_RESULT_SUCCESS |
1955 IB_MAD_RESULT_CONSUMED; 1960 IB_MAD_RESULT_CONSUMED;
1956 goto bail; 1961 goto bail;
1957 } 1962 }
1958 if (ibp->port_cap_flags & IB_PORT_SM) { 1963 if (ibp->rvp.port_cap_flags & IB_PORT_SM) {
1959 ret = IB_MAD_RESULT_SUCCESS; 1964 ret = IB_MAD_RESULT_SUCCESS;
1960 goto bail; 1965 goto bail;
1961 } 1966 }
@@ -2443,12 +2448,6 @@ bail:
2443 return ret; 2448 return ret;
2444} 2449}
2445 2450
2446static void send_handler(struct ib_mad_agent *agent,
2447 struct ib_mad_send_wc *mad_send_wc)
2448{
2449 ib_free_send_mad(mad_send_wc->send_buf);
2450}
2451
2452static void xmit_wait_timer_func(unsigned long opaque) 2451static void xmit_wait_timer_func(unsigned long opaque)
2453{ 2452{
2454 struct qib_pportdata *ppd = (struct qib_pportdata *)opaque; 2453 struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
@@ -2456,7 +2455,7 @@ static void xmit_wait_timer_func(unsigned long opaque)
2456 unsigned long flags; 2455 unsigned long flags;
2457 u8 status; 2456 u8 status;
2458 2457
2459 spin_lock_irqsave(&ppd->ibport_data.lock, flags); 2458 spin_lock_irqsave(&ppd->ibport_data.rvp.lock, flags);
2460 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_SAMPLE) { 2459 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_SAMPLE) {
2461 status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT); 2460 status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
2462 if (status == IB_PMA_SAMPLE_STATUS_DONE) { 2461 if (status == IB_PMA_SAMPLE_STATUS_DONE) {
@@ -2469,74 +2468,35 @@ static void xmit_wait_timer_func(unsigned long opaque)
2469 ppd->cong_stats.counter = xmit_wait_get_value_delta(ppd); 2468 ppd->cong_stats.counter = xmit_wait_get_value_delta(ppd);
2470 dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, 0x0); 2469 dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, 0x0);
2471done: 2470done:
2472 spin_unlock_irqrestore(&ppd->ibport_data.lock, flags); 2471 spin_unlock_irqrestore(&ppd->ibport_data.rvp.lock, flags);
2473 mod_timer(&ppd->cong_stats.timer, jiffies + HZ); 2472 mod_timer(&ppd->cong_stats.timer, jiffies + HZ);
2474} 2473}
2475 2474
2476int qib_create_agents(struct qib_ibdev *dev) 2475void qib_notify_create_mad_agent(struct rvt_dev_info *rdi, int port_idx)
2477{ 2476{
2478 struct qib_devdata *dd = dd_from_dev(dev); 2477 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
2479 struct ib_mad_agent *agent; 2478 struct qib_devdata *dd = container_of(ibdev,
2480 struct qib_ibport *ibp; 2479 struct qib_devdata, verbs_dev);
2481 int p;
2482 int ret;
2483 2480
2484 for (p = 0; p < dd->num_pports; p++) { 2481 /* Initialize xmit_wait structure */
2485 ibp = &dd->pport[p].ibport_data; 2482 dd->pport[port_idx].cong_stats.counter = 0;
2486 agent = ib_register_mad_agent(&dev->ibdev, p + 1, IB_QPT_SMI, 2483 init_timer(&dd->pport[port_idx].cong_stats.timer);
2487 NULL, 0, send_handler, 2484 dd->pport[port_idx].cong_stats.timer.function = xmit_wait_timer_func;
2488 NULL, NULL, 0); 2485 dd->pport[port_idx].cong_stats.timer.data =
2489 if (IS_ERR(agent)) { 2486 (unsigned long)(&dd->pport[port_idx]);
2490 ret = PTR_ERR(agent); 2487 dd->pport[port_idx].cong_stats.timer.expires = 0;
2491 goto err; 2488 add_timer(&dd->pport[port_idx].cong_stats.timer);
2492 }
2493
2494 /* Initialize xmit_wait structure */
2495 dd->pport[p].cong_stats.counter = 0;
2496 init_timer(&dd->pport[p].cong_stats.timer);
2497 dd->pport[p].cong_stats.timer.function = xmit_wait_timer_func;
2498 dd->pport[p].cong_stats.timer.data =
2499 (unsigned long)(&dd->pport[p]);
2500 dd->pport[p].cong_stats.timer.expires = 0;
2501 add_timer(&dd->pport[p].cong_stats.timer);
2502
2503 ibp->send_agent = agent;
2504 }
2505
2506 return 0;
2507
2508err:
2509 for (p = 0; p < dd->num_pports; p++) {
2510 ibp = &dd->pport[p].ibport_data;
2511 if (ibp->send_agent) {
2512 agent = ibp->send_agent;
2513 ibp->send_agent = NULL;
2514 ib_unregister_mad_agent(agent);
2515 }
2516 }
2517
2518 return ret;
2519} 2489}
2520 2490
2521void qib_free_agents(struct qib_ibdev *dev) 2491void qib_notify_free_mad_agent(struct rvt_dev_info *rdi, int port_idx)
2522{ 2492{
2523 struct qib_devdata *dd = dd_from_dev(dev); 2493 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
2524 struct ib_mad_agent *agent; 2494 struct qib_devdata *dd = container_of(ibdev,
2525 struct qib_ibport *ibp; 2495 struct qib_devdata, verbs_dev);
2526 int p; 2496
2527 2497 if (dd->pport[port_idx].cong_stats.timer.data)
2528 for (p = 0; p < dd->num_pports; p++) { 2498 del_timer_sync(&dd->pport[port_idx].cong_stats.timer);
2529 ibp = &dd->pport[p].ibport_data; 2499
2530 if (ibp->send_agent) { 2500 if (dd->pport[port_idx].ibport_data.smi_ah)
2531 agent = ibp->send_agent; 2501 ib_destroy_ah(&dd->pport[port_idx].ibport_data.smi_ah->ibah);
2532 ibp->send_agent = NULL;
2533 ib_unregister_mad_agent(agent);
2534 }
2535 if (ibp->sm_ah) {
2536 ib_destroy_ah(&ibp->sm_ah->ibah);
2537 ibp->sm_ah = NULL;
2538 }
2539 if (dd->pport[p].cong_stats.timer.data)
2540 del_timer_sync(&dd->pport[p].cong_stats.timer);
2541 }
2542} 2502}
diff --git a/drivers/infiniband/hw/qib/qib_mmap.c b/drivers/infiniband/hw/qib/qib_mmap.c
deleted file mode 100644
index 34927b700b0e..000000000000
--- a/drivers/infiniband/hw/qib/qib_mmap.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/*
2 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/module.h>
34#include <linux/slab.h>
35#include <linux/vmalloc.h>
36#include <linux/mm.h>
37#include <linux/errno.h>
38#include <asm/pgtable.h>
39
40#include "qib_verbs.h"
41
42/**
43 * qib_release_mmap_info - free mmap info structure
44 * @ref: a pointer to the kref within struct qib_mmap_info
45 */
46void qib_release_mmap_info(struct kref *ref)
47{
48 struct qib_mmap_info *ip =
49 container_of(ref, struct qib_mmap_info, ref);
50 struct qib_ibdev *dev = to_idev(ip->context->device);
51
52 spin_lock_irq(&dev->pending_lock);
53 list_del(&ip->pending_mmaps);
54 spin_unlock_irq(&dev->pending_lock);
55
56 vfree(ip->obj);
57 kfree(ip);
58}
59
60/*
61 * open and close keep track of how many times the CQ is mapped,
62 * to avoid releasing it.
63 */
64static void qib_vma_open(struct vm_area_struct *vma)
65{
66 struct qib_mmap_info *ip = vma->vm_private_data;
67
68 kref_get(&ip->ref);
69}
70
71static void qib_vma_close(struct vm_area_struct *vma)
72{
73 struct qib_mmap_info *ip = vma->vm_private_data;
74
75 kref_put(&ip->ref, qib_release_mmap_info);
76}
77
78static const struct vm_operations_struct qib_vm_ops = {
79 .open = qib_vma_open,
80 .close = qib_vma_close,
81};
82
83/**
84 * qib_mmap - create a new mmap region
85 * @context: the IB user context of the process making the mmap() call
86 * @vma: the VMA to be initialized
87 * Return zero if the mmap is OK. Otherwise, return an errno.
88 */
89int qib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
90{
91 struct qib_ibdev *dev = to_idev(context->device);
92 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
93 unsigned long size = vma->vm_end - vma->vm_start;
94 struct qib_mmap_info *ip, *pp;
95 int ret = -EINVAL;
96
97 /*
98 * Search the device's list of objects waiting for a mmap call.
99 * Normally, this list is very short since a call to create a
100 * CQ, QP, or SRQ is soon followed by a call to mmap().
101 */
102 spin_lock_irq(&dev->pending_lock);
103 list_for_each_entry_safe(ip, pp, &dev->pending_mmaps,
104 pending_mmaps) {
105 /* Only the creator is allowed to mmap the object */
106 if (context != ip->context || (__u64) offset != ip->offset)
107 continue;
108 /* Don't allow a mmap larger than the object. */
109 if (size > ip->size)
110 break;
111
112 list_del_init(&ip->pending_mmaps);
113 spin_unlock_irq(&dev->pending_lock);
114
115 ret = remap_vmalloc_range(vma, ip->obj, 0);
116 if (ret)
117 goto done;
118 vma->vm_ops = &qib_vm_ops;
119 vma->vm_private_data = ip;
120 qib_vma_open(vma);
121 goto done;
122 }
123 spin_unlock_irq(&dev->pending_lock);
124done:
125 return ret;
126}
127
128/*
129 * Allocate information for qib_mmap
130 */
131struct qib_mmap_info *qib_create_mmap_info(struct qib_ibdev *dev,
132 u32 size,
133 struct ib_ucontext *context,
134 void *obj) {
135 struct qib_mmap_info *ip;
136
137 ip = kmalloc(sizeof(*ip), GFP_KERNEL);
138 if (!ip)
139 goto bail;
140
141 size = PAGE_ALIGN(size);
142
143 spin_lock_irq(&dev->mmap_offset_lock);
144 if (dev->mmap_offset == 0)
145 dev->mmap_offset = PAGE_SIZE;
146 ip->offset = dev->mmap_offset;
147 dev->mmap_offset += size;
148 spin_unlock_irq(&dev->mmap_offset_lock);
149
150 INIT_LIST_HEAD(&ip->pending_mmaps);
151 ip->size = size;
152 ip->context = context;
153 ip->obj = obj;
154 kref_init(&ip->ref);
155
156bail:
157 return ip;
158}
159
160void qib_update_mmap_info(struct qib_ibdev *dev, struct qib_mmap_info *ip,
161 u32 size, void *obj)
162{
163 size = PAGE_ALIGN(size);
164
165 spin_lock_irq(&dev->mmap_offset_lock);
166 if (dev->mmap_offset == 0)
167 dev->mmap_offset = PAGE_SIZE;
168 ip->offset = dev->mmap_offset;
169 dev->mmap_offset += size;
170 spin_unlock_irq(&dev->mmap_offset_lock);
171
172 ip->size = size;
173 ip->obj = obj;
174}
diff --git a/drivers/infiniband/hw/qib/qib_mr.c b/drivers/infiniband/hw/qib/qib_mr.c
deleted file mode 100644
index 5f53304e8a9b..000000000000
--- a/drivers/infiniband/hw/qib/qib_mr.c
+++ /dev/null
@@ -1,490 +0,0 @@
1/*
2 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <rdma/ib_umem.h>
35#include <rdma/ib_smi.h>
36
37#include "qib.h"
38
39/* Fast memory region */
40struct qib_fmr {
41 struct ib_fmr ibfmr;
42 struct qib_mregion mr; /* must be last */
43};
44
45static inline struct qib_fmr *to_ifmr(struct ib_fmr *ibfmr)
46{
47 return container_of(ibfmr, struct qib_fmr, ibfmr);
48}
49
50static int init_qib_mregion(struct qib_mregion *mr, struct ib_pd *pd,
51 int count)
52{
53 int m, i = 0;
54 int rval = 0;
55
56 m = (count + QIB_SEGSZ - 1) / QIB_SEGSZ;
57 for (; i < m; i++) {
58 mr->map[i] = kzalloc(sizeof(*mr->map[0]), GFP_KERNEL);
59 if (!mr->map[i])
60 goto bail;
61 }
62 mr->mapsz = m;
63 init_completion(&mr->comp);
64 /* count returning the ptr to user */
65 atomic_set(&mr->refcount, 1);
66 mr->pd = pd;
67 mr->max_segs = count;
68out:
69 return rval;
70bail:
71 while (i)
72 kfree(mr->map[--i]);
73 rval = -ENOMEM;
74 goto out;
75}
76
77static void deinit_qib_mregion(struct qib_mregion *mr)
78{
79 int i = mr->mapsz;
80
81 mr->mapsz = 0;
82 while (i)
83 kfree(mr->map[--i]);
84}
85
86
87/**
88 * qib_get_dma_mr - get a DMA memory region
89 * @pd: protection domain for this memory region
90 * @acc: access flags
91 *
92 * Returns the memory region on success, otherwise returns an errno.
93 * Note that all DMA addresses should be created via the
94 * struct ib_dma_mapping_ops functions (see qib_dma.c).
95 */
96struct ib_mr *qib_get_dma_mr(struct ib_pd *pd, int acc)
97{
98 struct qib_mr *mr = NULL;
99 struct ib_mr *ret;
100 int rval;
101
102 if (to_ipd(pd)->user) {
103 ret = ERR_PTR(-EPERM);
104 goto bail;
105 }
106
107 mr = kzalloc(sizeof(*mr), GFP_KERNEL);
108 if (!mr) {
109 ret = ERR_PTR(-ENOMEM);
110 goto bail;
111 }
112
113 rval = init_qib_mregion(&mr->mr, pd, 0);
114 if (rval) {
115 ret = ERR_PTR(rval);
116 goto bail;
117 }
118
119
120 rval = qib_alloc_lkey(&mr->mr, 1);
121 if (rval) {
122 ret = ERR_PTR(rval);
123 goto bail_mregion;
124 }
125
126 mr->mr.access_flags = acc;
127 ret = &mr->ibmr;
128done:
129 return ret;
130
131bail_mregion:
132 deinit_qib_mregion(&mr->mr);
133bail:
134 kfree(mr);
135 goto done;
136}
137
138static struct qib_mr *alloc_mr(int count, struct ib_pd *pd)
139{
140 struct qib_mr *mr;
141 int rval = -ENOMEM;
142 int m;
143
144 /* Allocate struct plus pointers to first level page tables. */
145 m = (count + QIB_SEGSZ - 1) / QIB_SEGSZ;
146 mr = kzalloc(sizeof(*mr) + m * sizeof(mr->mr.map[0]), GFP_KERNEL);
147 if (!mr)
148 goto bail;
149
150 rval = init_qib_mregion(&mr->mr, pd, count);
151 if (rval)
152 goto bail;
153
154 rval = qib_alloc_lkey(&mr->mr, 0);
155 if (rval)
156 goto bail_mregion;
157 mr->ibmr.lkey = mr->mr.lkey;
158 mr->ibmr.rkey = mr->mr.lkey;
159done:
160 return mr;
161
162bail_mregion:
163 deinit_qib_mregion(&mr->mr);
164bail:
165 kfree(mr);
166 mr = ERR_PTR(rval);
167 goto done;
168}
169
170/**
171 * qib_reg_user_mr - register a userspace memory region
172 * @pd: protection domain for this memory region
173 * @start: starting userspace address
174 * @length: length of region to register
175 * @mr_access_flags: access flags for this memory region
176 * @udata: unused by the QLogic_IB driver
177 *
178 * Returns the memory region on success, otherwise returns an errno.
179 */
180struct ib_mr *qib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
181 u64 virt_addr, int mr_access_flags,
182 struct ib_udata *udata)
183{
184 struct qib_mr *mr;
185 struct ib_umem *umem;
186 struct scatterlist *sg;
187 int n, m, entry;
188 struct ib_mr *ret;
189
190 if (length == 0) {
191 ret = ERR_PTR(-EINVAL);
192 goto bail;
193 }
194
195 umem = ib_umem_get(pd->uobject->context, start, length,
196 mr_access_flags, 0);
197 if (IS_ERR(umem))
198 return (void *) umem;
199
200 n = umem->nmap;
201
202 mr = alloc_mr(n, pd);
203 if (IS_ERR(mr)) {
204 ret = (struct ib_mr *)mr;
205 ib_umem_release(umem);
206 goto bail;
207 }
208
209 mr->mr.user_base = start;
210 mr->mr.iova = virt_addr;
211 mr->mr.length = length;
212 mr->mr.offset = ib_umem_offset(umem);
213 mr->mr.access_flags = mr_access_flags;
214 mr->umem = umem;
215
216 if (is_power_of_2(umem->page_size))
217 mr->mr.page_shift = ilog2(umem->page_size);
218 m = 0;
219 n = 0;
220 for_each_sg(umem->sg_head.sgl, sg, umem->nmap, entry) {
221 void *vaddr;
222
223 vaddr = page_address(sg_page(sg));
224 if (!vaddr) {
225 ret = ERR_PTR(-EINVAL);
226 goto bail;
227 }
228 mr->mr.map[m]->segs[n].vaddr = vaddr;
229 mr->mr.map[m]->segs[n].length = umem->page_size;
230 n++;
231 if (n == QIB_SEGSZ) {
232 m++;
233 n = 0;
234 }
235 }
236 ret = &mr->ibmr;
237
238bail:
239 return ret;
240}
241
242/**
243 * qib_dereg_mr - unregister and free a memory region
244 * @ibmr: the memory region to free
245 *
246 * Returns 0 on success.
247 *
248 * Note that this is called to free MRs created by qib_get_dma_mr()
249 * or qib_reg_user_mr().
250 */
251int qib_dereg_mr(struct ib_mr *ibmr)
252{
253 struct qib_mr *mr = to_imr(ibmr);
254 int ret = 0;
255 unsigned long timeout;
256
257 kfree(mr->pages);
258 qib_free_lkey(&mr->mr);
259
260 qib_put_mr(&mr->mr); /* will set completion if last */
261 timeout = wait_for_completion_timeout(&mr->mr.comp,
262 5 * HZ);
263 if (!timeout) {
264 qib_get_mr(&mr->mr);
265 ret = -EBUSY;
266 goto out;
267 }
268 deinit_qib_mregion(&mr->mr);
269 if (mr->umem)
270 ib_umem_release(mr->umem);
271 kfree(mr);
272out:
273 return ret;
274}
275
276/*
277 * Allocate a memory region usable with the
278 * IB_WR_REG_MR send work request.
279 *
280 * Return the memory region on success, otherwise return an errno.
281 */
282struct ib_mr *qib_alloc_mr(struct ib_pd *pd,
283 enum ib_mr_type mr_type,
284 u32 max_num_sg)
285{
286 struct qib_mr *mr;
287
288 if (mr_type != IB_MR_TYPE_MEM_REG)
289 return ERR_PTR(-EINVAL);
290
291 mr = alloc_mr(max_num_sg, pd);
292 if (IS_ERR(mr))
293 return (struct ib_mr *)mr;
294
295 mr->pages = kcalloc(max_num_sg, sizeof(u64), GFP_KERNEL);
296 if (!mr->pages)
297 goto err;
298
299 return &mr->ibmr;
300
301err:
302 qib_dereg_mr(&mr->ibmr);
303 return ERR_PTR(-ENOMEM);
304}
305
306static int qib_set_page(struct ib_mr *ibmr, u64 addr)
307{
308 struct qib_mr *mr = to_imr(ibmr);
309
310 if (unlikely(mr->npages == mr->mr.max_segs))
311 return -ENOMEM;
312
313 mr->pages[mr->npages++] = addr;
314
315 return 0;
316}
317
318int qib_map_mr_sg(struct ib_mr *ibmr,
319 struct scatterlist *sg,
320 int sg_nents)
321{
322 struct qib_mr *mr = to_imr(ibmr);
323
324 mr->npages = 0;
325
326 return ib_sg_to_pages(ibmr, sg, sg_nents, qib_set_page);
327}
328
329/**
330 * qib_alloc_fmr - allocate a fast memory region
331 * @pd: the protection domain for this memory region
332 * @mr_access_flags: access flags for this memory region
333 * @fmr_attr: fast memory region attributes
334 *
335 * Returns the memory region on success, otherwise returns an errno.
336 */
337struct ib_fmr *qib_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
338 struct ib_fmr_attr *fmr_attr)
339{
340 struct qib_fmr *fmr;
341 int m;
342 struct ib_fmr *ret;
343 int rval = -ENOMEM;
344
345 /* Allocate struct plus pointers to first level page tables. */
346 m = (fmr_attr->max_pages + QIB_SEGSZ - 1) / QIB_SEGSZ;
347 fmr = kzalloc(sizeof(*fmr) + m * sizeof(fmr->mr.map[0]), GFP_KERNEL);
348 if (!fmr)
349 goto bail;
350
351 rval = init_qib_mregion(&fmr->mr, pd, fmr_attr->max_pages);
352 if (rval)
353 goto bail;
354
355 /*
356 * ib_alloc_fmr() will initialize fmr->ibfmr except for lkey &
357 * rkey.
358 */
359 rval = qib_alloc_lkey(&fmr->mr, 0);
360 if (rval)
361 goto bail_mregion;
362 fmr->ibfmr.rkey = fmr->mr.lkey;
363 fmr->ibfmr.lkey = fmr->mr.lkey;
364 /*
365 * Resources are allocated but no valid mapping (RKEY can't be
366 * used).
367 */
368 fmr->mr.access_flags = mr_access_flags;
369 fmr->mr.max_segs = fmr_attr->max_pages;
370 fmr->mr.page_shift = fmr_attr->page_shift;
371
372 ret = &fmr->ibfmr;
373done:
374 return ret;
375
376bail_mregion:
377 deinit_qib_mregion(&fmr->mr);
378bail:
379 kfree(fmr);
380 ret = ERR_PTR(rval);
381 goto done;
382}
383
384/**
385 * qib_map_phys_fmr - set up a fast memory region
386 * @ibmfr: the fast memory region to set up
387 * @page_list: the list of pages to associate with the fast memory region
388 * @list_len: the number of pages to associate with the fast memory region
389 * @iova: the virtual address of the start of the fast memory region
390 *
391 * This may be called from interrupt context.
392 */
393
394int qib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
395 int list_len, u64 iova)
396{
397 struct qib_fmr *fmr = to_ifmr(ibfmr);
398 struct qib_lkey_table *rkt;
399 unsigned long flags;
400 int m, n, i;
401 u32 ps;
402 int ret;
403
404 i = atomic_read(&fmr->mr.refcount);
405 if (i > 2)
406 return -EBUSY;
407
408 if (list_len > fmr->mr.max_segs) {
409 ret = -EINVAL;
410 goto bail;
411 }
412 rkt = &to_idev(ibfmr->device)->lk_table;
413 spin_lock_irqsave(&rkt->lock, flags);
414 fmr->mr.user_base = iova;
415 fmr->mr.iova = iova;
416 ps = 1 << fmr->mr.page_shift;
417 fmr->mr.length = list_len * ps;
418 m = 0;
419 n = 0;
420 for (i = 0; i < list_len; i++) {
421 fmr->mr.map[m]->segs[n].vaddr = (void *) page_list[i];
422 fmr->mr.map[m]->segs[n].length = ps;
423 if (++n == QIB_SEGSZ) {
424 m++;
425 n = 0;
426 }
427 }
428 spin_unlock_irqrestore(&rkt->lock, flags);
429 ret = 0;
430
431bail:
432 return ret;
433}
434
435/**
436 * qib_unmap_fmr - unmap fast memory regions
437 * @fmr_list: the list of fast memory regions to unmap
438 *
439 * Returns 0 on success.
440 */
441int qib_unmap_fmr(struct list_head *fmr_list)
442{
443 struct qib_fmr *fmr;
444 struct qib_lkey_table *rkt;
445 unsigned long flags;
446
447 list_for_each_entry(fmr, fmr_list, ibfmr.list) {
448 rkt = &to_idev(fmr->ibfmr.device)->lk_table;
449 spin_lock_irqsave(&rkt->lock, flags);
450 fmr->mr.user_base = 0;
451 fmr->mr.iova = 0;
452 fmr->mr.length = 0;
453 spin_unlock_irqrestore(&rkt->lock, flags);
454 }
455 return 0;
456}
457
458/**
459 * qib_dealloc_fmr - deallocate a fast memory region
460 * @ibfmr: the fast memory region to deallocate
461 *
462 * Returns 0 on success.
463 */
464int qib_dealloc_fmr(struct ib_fmr *ibfmr)
465{
466 struct qib_fmr *fmr = to_ifmr(ibfmr);
467 int ret = 0;
468 unsigned long timeout;
469
470 qib_free_lkey(&fmr->mr);
471 qib_put_mr(&fmr->mr); /* will set completion if last */
472 timeout = wait_for_completion_timeout(&fmr->mr.comp,
473 5 * HZ);
474 if (!timeout) {
475 qib_get_mr(&fmr->mr);
476 ret = -EBUSY;
477 goto out;
478 }
479 deinit_qib_mregion(&fmr->mr);
480 kfree(fmr);
481out:
482 return ret;
483}
484
485void mr_rcu_callback(struct rcu_head *list)
486{
487 struct qib_mregion *mr = container_of(list, struct qib_mregion, list);
488
489 complete(&mr->comp);
490}
diff --git a/drivers/infiniband/hw/qib/qib_qp.c b/drivers/infiniband/hw/qib/qib_qp.c
index 3eff35c2d453..575b737d9ef3 100644
--- a/drivers/infiniband/hw/qib/qib_qp.c
+++ b/drivers/infiniband/hw/qib/qib_qp.c
@@ -34,32 +34,38 @@
34 34
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/jhash.h> 37#include <rdma/rdma_vt.h>
38#ifdef CONFIG_DEBUG_FS 38#ifdef CONFIG_DEBUG_FS
39#include <linux/seq_file.h> 39#include <linux/seq_file.h>
40#endif 40#endif
41 41
42#include "qib.h" 42#include "qib.h"
43 43
44#define BITS_PER_PAGE (PAGE_SIZE*BITS_PER_BYTE) 44/*
45#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1) 45 * mask field which was present in now deleted qib_qpn_table
46 * is not present in rvt_qpn_table. Defining the same field
47 * as qpt_mask here instead of adding the mask field to
48 * rvt_qpn_table.
49 */
50u16 qpt_mask;
46 51
47static inline unsigned mk_qpn(struct qib_qpn_table *qpt, 52static inline unsigned mk_qpn(struct rvt_qpn_table *qpt,
48 struct qpn_map *map, unsigned off) 53 struct rvt_qpn_map *map, unsigned off)
49{ 54{
50 return (map - qpt->map) * BITS_PER_PAGE + off; 55 return (map - qpt->map) * RVT_BITS_PER_PAGE + off;
51} 56}
52 57
53static inline unsigned find_next_offset(struct qib_qpn_table *qpt, 58static inline unsigned find_next_offset(struct rvt_qpn_table *qpt,
54 struct qpn_map *map, unsigned off, 59 struct rvt_qpn_map *map, unsigned off,
55 unsigned n) 60 unsigned n)
56{ 61{
57 if (qpt->mask) { 62 if (qpt_mask) {
58 off++; 63 off++;
59 if (((off & qpt->mask) >> 1) >= n) 64 if (((off & qpt_mask) >> 1) >= n)
60 off = (off | qpt->mask) + 2; 65 off = (off | qpt_mask) + 2;
61 } else 66 } else {
62 off = find_next_zero_bit(map->page, BITS_PER_PAGE, off); 67 off = find_next_zero_bit(map->page, RVT_BITS_PER_PAGE, off);
68 }
63 return off; 69 return off;
64} 70}
65 71
@@ -100,7 +106,7 @@ static u32 credit_table[31] = {
100 32768 /* 1E */ 106 32768 /* 1E */
101}; 107};
102 108
103static void get_map_page(struct qib_qpn_table *qpt, struct qpn_map *map, 109static void get_map_page(struct rvt_qpn_table *qpt, struct rvt_qpn_map *map,
104 gfp_t gfp) 110 gfp_t gfp)
105{ 111{
106 unsigned long page = get_zeroed_page(gfp); 112 unsigned long page = get_zeroed_page(gfp);
@@ -121,12 +127,15 @@ static void get_map_page(struct qib_qpn_table *qpt, struct qpn_map *map,
121 * Allocate the next available QPN or 127 * Allocate the next available QPN or
122 * zero/one for QP type IB_QPT_SMI/IB_QPT_GSI. 128 * zero/one for QP type IB_QPT_SMI/IB_QPT_GSI.
123 */ 129 */
124static int alloc_qpn(struct qib_devdata *dd, struct qib_qpn_table *qpt, 130int qib_alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
125 enum ib_qp_type type, u8 port, gfp_t gfp) 131 enum ib_qp_type type, u8 port, gfp_t gfp)
126{ 132{
127 u32 i, offset, max_scan, qpn; 133 u32 i, offset, max_scan, qpn;
128 struct qpn_map *map; 134 struct rvt_qpn_map *map;
129 u32 ret; 135 u32 ret;
136 struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi);
137 struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata,
138 verbs_dev);
130 139
131 if (type == IB_QPT_SMI || type == IB_QPT_GSI) { 140 if (type == IB_QPT_SMI || type == IB_QPT_GSI) {
132 unsigned n; 141 unsigned n;
@@ -143,12 +152,12 @@ static int alloc_qpn(struct qib_devdata *dd, struct qib_qpn_table *qpt,
143 } 152 }
144 153
145 qpn = qpt->last + 2; 154 qpn = qpt->last + 2;
146 if (qpn >= QPN_MAX) 155 if (qpn >= RVT_QPN_MAX)
147 qpn = 2; 156 qpn = 2;
148 if (qpt->mask && ((qpn & qpt->mask) >> 1) >= dd->n_krcv_queues) 157 if (qpt_mask && ((qpn & qpt_mask) >> 1) >= dd->n_krcv_queues)
149 qpn = (qpn | qpt->mask) + 2; 158 qpn = (qpn | qpt_mask) + 2;
150 offset = qpn & BITS_PER_PAGE_MASK; 159 offset = qpn & RVT_BITS_PER_PAGE_MASK;
151 map = &qpt->map[qpn / BITS_PER_PAGE]; 160 map = &qpt->map[qpn / RVT_BITS_PER_PAGE];
152 max_scan = qpt->nmaps - !offset; 161 max_scan = qpt->nmaps - !offset;
153 for (i = 0;;) { 162 for (i = 0;;) {
154 if (unlikely(!map->page)) { 163 if (unlikely(!map->page)) {
@@ -173,14 +182,14 @@ static int alloc_qpn(struct qib_devdata *dd, struct qib_qpn_table *qpt,
173 * We just need to be sure we don't loop 182 * We just need to be sure we don't loop
174 * forever. 183 * forever.
175 */ 184 */
176 } while (offset < BITS_PER_PAGE && qpn < QPN_MAX); 185 } while (offset < RVT_BITS_PER_PAGE && qpn < RVT_QPN_MAX);
177 /* 186 /*
178 * In order to keep the number of pages allocated to a 187 * In order to keep the number of pages allocated to a
179 * minimum, we scan the all existing pages before increasing 188 * minimum, we scan the all existing pages before increasing
180 * the size of the bitmap table. 189 * the size of the bitmap table.
181 */ 190 */
182 if (++i > max_scan) { 191 if (++i > max_scan) {
183 if (qpt->nmaps == QPNMAP_ENTRIES) 192 if (qpt->nmaps == RVT_QPNMAP_ENTRIES)
184 break; 193 break;
185 map = &qpt->map[qpt->nmaps++]; 194 map = &qpt->map[qpt->nmaps++];
186 offset = 0; 195 offset = 0;
@@ -200,706 +209,113 @@ bail:
200 return ret; 209 return ret;
201} 210}
202 211
203static void free_qpn(struct qib_qpn_table *qpt, u32 qpn)
204{
205 struct qpn_map *map;
206
207 map = qpt->map + qpn / BITS_PER_PAGE;
208 if (map->page)
209 clear_bit(qpn & BITS_PER_PAGE_MASK, map->page);
210}
211
212static inline unsigned qpn_hash(struct qib_ibdev *dev, u32 qpn)
213{
214 return jhash_1word(qpn, dev->qp_rnd) &
215 (dev->qp_table_size - 1);
216}
217
218
219/*
220 * Put the QP into the hash table.
221 * The hash table holds a reference to the QP.
222 */
223static void insert_qp(struct qib_ibdev *dev, struct qib_qp *qp)
224{
225 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
226 unsigned long flags;
227 unsigned n = qpn_hash(dev, qp->ibqp.qp_num);
228
229 atomic_inc(&qp->refcount);
230 spin_lock_irqsave(&dev->qpt_lock, flags);
231
232 if (qp->ibqp.qp_num == 0)
233 rcu_assign_pointer(ibp->qp0, qp);
234 else if (qp->ibqp.qp_num == 1)
235 rcu_assign_pointer(ibp->qp1, qp);
236 else {
237 qp->next = dev->qp_table[n];
238 rcu_assign_pointer(dev->qp_table[n], qp);
239 }
240
241 spin_unlock_irqrestore(&dev->qpt_lock, flags);
242}
243
244/*
245 * Remove the QP from the table so it can't be found asynchronously by
246 * the receive interrupt routine.
247 */
248static void remove_qp(struct qib_ibdev *dev, struct qib_qp *qp)
249{
250 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
251 unsigned n = qpn_hash(dev, qp->ibqp.qp_num);
252 unsigned long flags;
253 int removed = 1;
254
255 spin_lock_irqsave(&dev->qpt_lock, flags);
256
257 if (rcu_dereference_protected(ibp->qp0,
258 lockdep_is_held(&dev->qpt_lock)) == qp) {
259 RCU_INIT_POINTER(ibp->qp0, NULL);
260 } else if (rcu_dereference_protected(ibp->qp1,
261 lockdep_is_held(&dev->qpt_lock)) == qp) {
262 RCU_INIT_POINTER(ibp->qp1, NULL);
263 } else {
264 struct qib_qp *q;
265 struct qib_qp __rcu **qpp;
266
267 removed = 0;
268 qpp = &dev->qp_table[n];
269 for (; (q = rcu_dereference_protected(*qpp,
270 lockdep_is_held(&dev->qpt_lock))) != NULL;
271 qpp = &q->next)
272 if (q == qp) {
273 RCU_INIT_POINTER(*qpp,
274 rcu_dereference_protected(qp->next,
275 lockdep_is_held(&dev->qpt_lock)));
276 removed = 1;
277 break;
278 }
279 }
280
281 spin_unlock_irqrestore(&dev->qpt_lock, flags);
282 if (removed) {
283 synchronize_rcu();
284 atomic_dec(&qp->refcount);
285 }
286}
287
288/** 212/**
289 * qib_free_all_qps - check for QPs still in use 213 * qib_free_all_qps - check for QPs still in use
290 * @qpt: the QP table to empty
291 *
292 * There should not be any QPs still in use.
293 * Free memory for table.
294 */ 214 */
295unsigned qib_free_all_qps(struct qib_devdata *dd) 215unsigned qib_free_all_qps(struct rvt_dev_info *rdi)
296{ 216{
297 struct qib_ibdev *dev = &dd->verbs_dev; 217 struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi);
298 unsigned long flags; 218 struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata,
299 struct qib_qp *qp; 219 verbs_dev);
300 unsigned n, qp_inuse = 0; 220 unsigned n, qp_inuse = 0;
301 221
302 for (n = 0; n < dd->num_pports; n++) { 222 for (n = 0; n < dd->num_pports; n++) {
303 struct qib_ibport *ibp = &dd->pport[n].ibport_data; 223 struct qib_ibport *ibp = &dd->pport[n].ibport_data;
304 224
305 if (!qib_mcast_tree_empty(ibp))
306 qp_inuse++;
307 rcu_read_lock(); 225 rcu_read_lock();
308 if (rcu_dereference(ibp->qp0)) 226 if (rcu_dereference(ibp->rvp.qp[0]))
309 qp_inuse++; 227 qp_inuse++;
310 if (rcu_dereference(ibp->qp1)) 228 if (rcu_dereference(ibp->rvp.qp[1]))
311 qp_inuse++; 229 qp_inuse++;
312 rcu_read_unlock(); 230 rcu_read_unlock();
313 } 231 }
314
315 spin_lock_irqsave(&dev->qpt_lock, flags);
316 for (n = 0; n < dev->qp_table_size; n++) {
317 qp = rcu_dereference_protected(dev->qp_table[n],
318 lockdep_is_held(&dev->qpt_lock));
319 RCU_INIT_POINTER(dev->qp_table[n], NULL);
320
321 for (; qp; qp = rcu_dereference_protected(qp->next,
322 lockdep_is_held(&dev->qpt_lock)))
323 qp_inuse++;
324 }
325 spin_unlock_irqrestore(&dev->qpt_lock, flags);
326 synchronize_rcu();
327
328 return qp_inuse; 232 return qp_inuse;
329} 233}
330 234
331/** 235void qib_notify_qp_reset(struct rvt_qp *qp)
332 * qib_lookup_qpn - return the QP with the given QPN
333 * @qpt: the QP table
334 * @qpn: the QP number to look up
335 *
336 * The caller is responsible for decrementing the QP reference count
337 * when done.
338 */
339struct qib_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn)
340{ 236{
341 struct qib_qp *qp = NULL; 237 struct qib_qp_priv *priv = qp->priv;
342
343 rcu_read_lock();
344 if (unlikely(qpn <= 1)) {
345 if (qpn == 0)
346 qp = rcu_dereference(ibp->qp0);
347 else
348 qp = rcu_dereference(ibp->qp1);
349 if (qp)
350 atomic_inc(&qp->refcount);
351 } else {
352 struct qib_ibdev *dev = &ppd_from_ibp(ibp)->dd->verbs_dev;
353 unsigned n = qpn_hash(dev, qpn);
354
355 for (qp = rcu_dereference(dev->qp_table[n]); qp;
356 qp = rcu_dereference(qp->next))
357 if (qp->ibqp.qp_num == qpn) {
358 atomic_inc(&qp->refcount);
359 break;
360 }
361 }
362 rcu_read_unlock();
363 return qp;
364}
365
366/**
367 * qib_reset_qp - initialize the QP state to the reset state
368 * @qp: the QP to reset
369 * @type: the QP type
370 */
371static void qib_reset_qp(struct qib_qp *qp, enum ib_qp_type type)
372{
373 qp->remote_qpn = 0;
374 qp->qkey = 0;
375 qp->qp_access_flags = 0;
376 atomic_set(&qp->s_dma_busy, 0);
377 qp->s_flags &= QIB_S_SIGNAL_REQ_WR;
378 qp->s_hdrwords = 0;
379 qp->s_wqe = NULL;
380 qp->s_draining = 0;
381 qp->s_next_psn = 0;
382 qp->s_last_psn = 0;
383 qp->s_sending_psn = 0;
384 qp->s_sending_hpsn = 0;
385 qp->s_psn = 0;
386 qp->r_psn = 0;
387 qp->r_msn = 0;
388 if (type == IB_QPT_RC) {
389 qp->s_state = IB_OPCODE_RC_SEND_LAST;
390 qp->r_state = IB_OPCODE_RC_SEND_LAST;
391 } else {
392 qp->s_state = IB_OPCODE_UC_SEND_LAST;
393 qp->r_state = IB_OPCODE_UC_SEND_LAST;
394 }
395 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
396 qp->r_nak_state = 0;
397 qp->r_aflags = 0;
398 qp->r_flags = 0;
399 qp->s_head = 0;
400 qp->s_tail = 0;
401 qp->s_cur = 0;
402 qp->s_acked = 0;
403 qp->s_last = 0;
404 qp->s_ssn = 1;
405 qp->s_lsn = 0;
406 qp->s_mig_state = IB_MIG_MIGRATED;
407 memset(qp->s_ack_queue, 0, sizeof(qp->s_ack_queue));
408 qp->r_head_ack_queue = 0;
409 qp->s_tail_ack_queue = 0;
410 qp->s_num_rd_atomic = 0;
411 if (qp->r_rq.wq) {
412 qp->r_rq.wq->head = 0;
413 qp->r_rq.wq->tail = 0;
414 }
415 qp->r_sge.num_sge = 0;
416}
417
418static void clear_mr_refs(struct qib_qp *qp, int clr_sends)
419{
420 unsigned n;
421
422 if (test_and_clear_bit(QIB_R_REWIND_SGE, &qp->r_aflags))
423 qib_put_ss(&qp->s_rdma_read_sge);
424
425 qib_put_ss(&qp->r_sge);
426
427 if (clr_sends) {
428 while (qp->s_last != qp->s_head) {
429 struct qib_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
430 unsigned i;
431
432 for (i = 0; i < wqe->wr.num_sge; i++) {
433 struct qib_sge *sge = &wqe->sg_list[i];
434
435 qib_put_mr(sge->mr);
436 }
437 if (qp->ibqp.qp_type == IB_QPT_UD ||
438 qp->ibqp.qp_type == IB_QPT_SMI ||
439 qp->ibqp.qp_type == IB_QPT_GSI)
440 atomic_dec(&to_iah(wqe->ud_wr.ah)->refcount);
441 if (++qp->s_last >= qp->s_size)
442 qp->s_last = 0;
443 }
444 if (qp->s_rdma_mr) {
445 qib_put_mr(qp->s_rdma_mr);
446 qp->s_rdma_mr = NULL;
447 }
448 }
449
450 if (qp->ibqp.qp_type != IB_QPT_RC)
451 return;
452 238
453 for (n = 0; n < ARRAY_SIZE(qp->s_ack_queue); n++) { 239 atomic_set(&priv->s_dma_busy, 0);
454 struct qib_ack_entry *e = &qp->s_ack_queue[n];
455
456 if (e->opcode == IB_OPCODE_RC_RDMA_READ_REQUEST &&
457 e->rdma_sge.mr) {
458 qib_put_mr(e->rdma_sge.mr);
459 e->rdma_sge.mr = NULL;
460 }
461 }
462} 240}
463 241
464/** 242void qib_notify_error_qp(struct rvt_qp *qp)
465 * qib_error_qp - put a QP into the error state
466 * @qp: the QP to put into the error state
467 * @err: the receive completion error to signal if a RWQE is active
468 *
469 * Flushes both send and receive work queues.
470 * Returns true if last WQE event should be generated.
471 * The QP r_lock and s_lock should be held and interrupts disabled.
472 * If we are already in error state, just return.
473 */
474int qib_error_qp(struct qib_qp *qp, enum ib_wc_status err)
475{ 243{
244 struct qib_qp_priv *priv = qp->priv;
476 struct qib_ibdev *dev = to_idev(qp->ibqp.device); 245 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
477 struct ib_wc wc;
478 int ret = 0;
479
480 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET)
481 goto bail;
482
483 qp->state = IB_QPS_ERR;
484
485 if (qp->s_flags & (QIB_S_TIMER | QIB_S_WAIT_RNR)) {
486 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_WAIT_RNR);
487 del_timer(&qp->s_timer);
488 }
489
490 if (qp->s_flags & QIB_S_ANY_WAIT_SEND)
491 qp->s_flags &= ~QIB_S_ANY_WAIT_SEND;
492 246
493 spin_lock(&dev->pending_lock); 247 spin_lock(&dev->rdi.pending_lock);
494 if (!list_empty(&qp->iowait) && !(qp->s_flags & QIB_S_BUSY)) { 248 if (!list_empty(&priv->iowait) && !(qp->s_flags & RVT_S_BUSY)) {
495 qp->s_flags &= ~QIB_S_ANY_WAIT_IO; 249 qp->s_flags &= ~RVT_S_ANY_WAIT_IO;
496 list_del_init(&qp->iowait); 250 list_del_init(&priv->iowait);
497 } 251 }
498 spin_unlock(&dev->pending_lock); 252 spin_unlock(&dev->rdi.pending_lock);
499 253
500 if (!(qp->s_flags & QIB_S_BUSY)) { 254 if (!(qp->s_flags & RVT_S_BUSY)) {
501 qp->s_hdrwords = 0; 255 qp->s_hdrwords = 0;
502 if (qp->s_rdma_mr) { 256 if (qp->s_rdma_mr) {
503 qib_put_mr(qp->s_rdma_mr); 257 rvt_put_mr(qp->s_rdma_mr);
504 qp->s_rdma_mr = NULL; 258 qp->s_rdma_mr = NULL;
505 } 259 }
506 if (qp->s_tx) { 260 if (priv->s_tx) {
507 qib_put_txreq(qp->s_tx); 261 qib_put_txreq(priv->s_tx);
508 qp->s_tx = NULL; 262 priv->s_tx = NULL;
509 } 263 }
510 } 264 }
511
512 /* Schedule the sending tasklet to drain the send work queue. */
513 if (qp->s_last != qp->s_head)
514 qib_schedule_send(qp);
515
516 clear_mr_refs(qp, 0);
517
518 memset(&wc, 0, sizeof(wc));
519 wc.qp = &qp->ibqp;
520 wc.opcode = IB_WC_RECV;
521
522 if (test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) {
523 wc.wr_id = qp->r_wr_id;
524 wc.status = err;
525 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
526 }
527 wc.status = IB_WC_WR_FLUSH_ERR;
528
529 if (qp->r_rq.wq) {
530 struct qib_rwq *wq;
531 u32 head;
532 u32 tail;
533
534 spin_lock(&qp->r_rq.lock);
535
536 /* sanity check pointers before trusting them */
537 wq = qp->r_rq.wq;
538 head = wq->head;
539 if (head >= qp->r_rq.size)
540 head = 0;
541 tail = wq->tail;
542 if (tail >= qp->r_rq.size)
543 tail = 0;
544 while (tail != head) {
545 wc.wr_id = get_rwqe_ptr(&qp->r_rq, tail)->wr_id;
546 if (++tail >= qp->r_rq.size)
547 tail = 0;
548 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
549 }
550 wq->tail = tail;
551
552 spin_unlock(&qp->r_rq.lock);
553 } else if (qp->ibqp.event_handler)
554 ret = 1;
555
556bail:
557 return ret;
558} 265}
559 266
560/** 267static int mtu_to_enum(u32 mtu)
561 * qib_modify_qp - modify the attributes of a queue pair
562 * @ibqp: the queue pair who's attributes we're modifying
563 * @attr: the new attributes
564 * @attr_mask: the mask of attributes to modify
565 * @udata: user data for libibverbs.so
566 *
567 * Returns 0 on success, otherwise returns an errno.
568 */
569int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
570 int attr_mask, struct ib_udata *udata)
571{ 268{
572 struct qib_ibdev *dev = to_idev(ibqp->device); 269 int enum_mtu;
573 struct qib_qp *qp = to_iqp(ibqp);
574 enum ib_qp_state cur_state, new_state;
575 struct ib_event ev;
576 int lastwqe = 0;
577 int mig = 0;
578 int ret;
579 u32 pmtu = 0; /* for gcc warning only */
580
581 spin_lock_irq(&qp->r_lock);
582 spin_lock(&qp->s_lock);
583
584 cur_state = attr_mask & IB_QP_CUR_STATE ?
585 attr->cur_qp_state : qp->state;
586 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
587
588 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
589 attr_mask, IB_LINK_LAYER_UNSPECIFIED))
590 goto inval;
591
592 if (attr_mask & IB_QP_AV) {
593 if (attr->ah_attr.dlid >= QIB_MULTICAST_LID_BASE)
594 goto inval;
595 if (qib_check_ah(qp->ibqp.device, &attr->ah_attr))
596 goto inval;
597 }
598
599 if (attr_mask & IB_QP_ALT_PATH) {
600 if (attr->alt_ah_attr.dlid >= QIB_MULTICAST_LID_BASE)
601 goto inval;
602 if (qib_check_ah(qp->ibqp.device, &attr->alt_ah_attr))
603 goto inval;
604 if (attr->alt_pkey_index >= qib_get_npkeys(dd_from_dev(dev)))
605 goto inval;
606 }
607
608 if (attr_mask & IB_QP_PKEY_INDEX)
609 if (attr->pkey_index >= qib_get_npkeys(dd_from_dev(dev)))
610 goto inval;
611
612 if (attr_mask & IB_QP_MIN_RNR_TIMER)
613 if (attr->min_rnr_timer > 31)
614 goto inval;
615
616 if (attr_mask & IB_QP_PORT)
617 if (qp->ibqp.qp_type == IB_QPT_SMI ||
618 qp->ibqp.qp_type == IB_QPT_GSI ||
619 attr->port_num == 0 ||
620 attr->port_num > ibqp->device->phys_port_cnt)
621 goto inval;
622
623 if (attr_mask & IB_QP_DEST_QPN)
624 if (attr->dest_qp_num > QIB_QPN_MASK)
625 goto inval;
626
627 if (attr_mask & IB_QP_RETRY_CNT)
628 if (attr->retry_cnt > 7)
629 goto inval;
630
631 if (attr_mask & IB_QP_RNR_RETRY)
632 if (attr->rnr_retry > 7)
633 goto inval;
634
635 /*
636 * Don't allow invalid path_mtu values. OK to set greater
637 * than the active mtu (or even the max_cap, if we have tuned
638 * that to a small mtu. We'll set qp->path_mtu
639 * to the lesser of requested attribute mtu and active,
640 * for packetizing messages.
641 * Note that the QP port has to be set in INIT and MTU in RTR.
642 */
643 if (attr_mask & IB_QP_PATH_MTU) {
644 struct qib_devdata *dd = dd_from_dev(dev);
645 int mtu, pidx = qp->port_num - 1;
646
647 mtu = ib_mtu_enum_to_int(attr->path_mtu);
648 if (mtu == -1)
649 goto inval;
650 if (mtu > dd->pport[pidx].ibmtu) {
651 switch (dd->pport[pidx].ibmtu) {
652 case 4096:
653 pmtu = IB_MTU_4096;
654 break;
655 case 2048:
656 pmtu = IB_MTU_2048;
657 break;
658 case 1024:
659 pmtu = IB_MTU_1024;
660 break;
661 case 512:
662 pmtu = IB_MTU_512;
663 break;
664 case 256:
665 pmtu = IB_MTU_256;
666 break;
667 default:
668 pmtu = IB_MTU_2048;
669 }
670 } else
671 pmtu = attr->path_mtu;
672 }
673
674 if (attr_mask & IB_QP_PATH_MIG_STATE) {
675 if (attr->path_mig_state == IB_MIG_REARM) {
676 if (qp->s_mig_state == IB_MIG_ARMED)
677 goto inval;
678 if (new_state != IB_QPS_RTS)
679 goto inval;
680 } else if (attr->path_mig_state == IB_MIG_MIGRATED) {
681 if (qp->s_mig_state == IB_MIG_REARM)
682 goto inval;
683 if (new_state != IB_QPS_RTS && new_state != IB_QPS_SQD)
684 goto inval;
685 if (qp->s_mig_state == IB_MIG_ARMED)
686 mig = 1;
687 } else
688 goto inval;
689 }
690
691 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
692 if (attr->max_dest_rd_atomic > QIB_MAX_RDMA_ATOMIC)
693 goto inval;
694 270
695 switch (new_state) { 271 switch (mtu) {
696 case IB_QPS_RESET: 272 case 4096:
697 if (qp->state != IB_QPS_RESET) { 273 enum_mtu = IB_MTU_4096;
698 qp->state = IB_QPS_RESET;
699 spin_lock(&dev->pending_lock);
700 if (!list_empty(&qp->iowait))
701 list_del_init(&qp->iowait);
702 spin_unlock(&dev->pending_lock);
703 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_ANY_WAIT);
704 spin_unlock(&qp->s_lock);
705 spin_unlock_irq(&qp->r_lock);
706 /* Stop the sending work queue and retry timer */
707 cancel_work_sync(&qp->s_work);
708 del_timer_sync(&qp->s_timer);
709 wait_event(qp->wait_dma, !atomic_read(&qp->s_dma_busy));
710 if (qp->s_tx) {
711 qib_put_txreq(qp->s_tx);
712 qp->s_tx = NULL;
713 }
714 remove_qp(dev, qp);
715 wait_event(qp->wait, !atomic_read(&qp->refcount));
716 spin_lock_irq(&qp->r_lock);
717 spin_lock(&qp->s_lock);
718 clear_mr_refs(qp, 1);
719 qib_reset_qp(qp, ibqp->qp_type);
720 }
721 break; 274 break;
722 275 case 2048:
723 case IB_QPS_RTR: 276 enum_mtu = IB_MTU_2048;
724 /* Allow event to retrigger if QP set to RTR more than once */
725 qp->r_flags &= ~QIB_R_COMM_EST;
726 qp->state = new_state;
727 break; 277 break;
728 278 case 1024:
729 case IB_QPS_SQD: 279 enum_mtu = IB_MTU_1024;
730 qp->s_draining = qp->s_last != qp->s_cur;
731 qp->state = new_state;
732 break; 280 break;
733 281 case 512:
734 case IB_QPS_SQE: 282 enum_mtu = IB_MTU_512;
735 if (qp->ibqp.qp_type == IB_QPT_RC)
736 goto inval;
737 qp->state = new_state;
738 break; 283 break;
739 284 case 256:
740 case IB_QPS_ERR: 285 enum_mtu = IB_MTU_256;
741 lastwqe = qib_error_qp(qp, IB_WC_WR_FLUSH_ERR);
742 break; 286 break;
743
744 default: 287 default:
745 qp->state = new_state; 288 enum_mtu = IB_MTU_2048;
746 break;
747 }
748
749 if (attr_mask & IB_QP_PKEY_INDEX)
750 qp->s_pkey_index = attr->pkey_index;
751
752 if (attr_mask & IB_QP_PORT)
753 qp->port_num = attr->port_num;
754
755 if (attr_mask & IB_QP_DEST_QPN)
756 qp->remote_qpn = attr->dest_qp_num;
757
758 if (attr_mask & IB_QP_SQ_PSN) {
759 qp->s_next_psn = attr->sq_psn & QIB_PSN_MASK;
760 qp->s_psn = qp->s_next_psn;
761 qp->s_sending_psn = qp->s_next_psn;
762 qp->s_last_psn = qp->s_next_psn - 1;
763 qp->s_sending_hpsn = qp->s_last_psn;
764 }
765
766 if (attr_mask & IB_QP_RQ_PSN)
767 qp->r_psn = attr->rq_psn & QIB_PSN_MASK;
768
769 if (attr_mask & IB_QP_ACCESS_FLAGS)
770 qp->qp_access_flags = attr->qp_access_flags;
771
772 if (attr_mask & IB_QP_AV) {
773 qp->remote_ah_attr = attr->ah_attr;
774 qp->s_srate = attr->ah_attr.static_rate;
775 }
776
777 if (attr_mask & IB_QP_ALT_PATH) {
778 qp->alt_ah_attr = attr->alt_ah_attr;
779 qp->s_alt_pkey_index = attr->alt_pkey_index;
780 }
781
782 if (attr_mask & IB_QP_PATH_MIG_STATE) {
783 qp->s_mig_state = attr->path_mig_state;
784 if (mig) {
785 qp->remote_ah_attr = qp->alt_ah_attr;
786 qp->port_num = qp->alt_ah_attr.port_num;
787 qp->s_pkey_index = qp->s_alt_pkey_index;
788 }
789 }
790
791 if (attr_mask & IB_QP_PATH_MTU) {
792 qp->path_mtu = pmtu;
793 qp->pmtu = ib_mtu_enum_to_int(pmtu);
794 }
795
796 if (attr_mask & IB_QP_RETRY_CNT) {
797 qp->s_retry_cnt = attr->retry_cnt;
798 qp->s_retry = attr->retry_cnt;
799 }
800
801 if (attr_mask & IB_QP_RNR_RETRY) {
802 qp->s_rnr_retry_cnt = attr->rnr_retry;
803 qp->s_rnr_retry = attr->rnr_retry;
804 } 289 }
805 290 return enum_mtu;
806 if (attr_mask & IB_QP_MIN_RNR_TIMER)
807 qp->r_min_rnr_timer = attr->min_rnr_timer;
808
809 if (attr_mask & IB_QP_TIMEOUT) {
810 qp->timeout = attr->timeout;
811 qp->timeout_jiffies =
812 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
813 1000UL);
814 }
815
816 if (attr_mask & IB_QP_QKEY)
817 qp->qkey = attr->qkey;
818
819 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
820 qp->r_max_rd_atomic = attr->max_dest_rd_atomic;
821
822 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
823 qp->s_max_rd_atomic = attr->max_rd_atomic;
824
825 spin_unlock(&qp->s_lock);
826 spin_unlock_irq(&qp->r_lock);
827
828 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
829 insert_qp(dev, qp);
830
831 if (lastwqe) {
832 ev.device = qp->ibqp.device;
833 ev.element.qp = &qp->ibqp;
834 ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
835 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
836 }
837 if (mig) {
838 ev.device = qp->ibqp.device;
839 ev.element.qp = &qp->ibqp;
840 ev.event = IB_EVENT_PATH_MIG;
841 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
842 }
843 ret = 0;
844 goto bail;
845
846inval:
847 spin_unlock(&qp->s_lock);
848 spin_unlock_irq(&qp->r_lock);
849 ret = -EINVAL;
850
851bail:
852 return ret;
853} 291}
854 292
855int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 293int qib_get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
856 int attr_mask, struct ib_qp_init_attr *init_attr) 294 struct ib_qp_attr *attr)
857{ 295{
858 struct qib_qp *qp = to_iqp(ibqp); 296 int mtu, pmtu, pidx = qp->port_num - 1;
297 struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi);
298 struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata,
299 verbs_dev);
300 mtu = ib_mtu_enum_to_int(attr->path_mtu);
301 if (mtu == -1)
302 return -EINVAL;
303
304 if (mtu > dd->pport[pidx].ibmtu)
305 pmtu = mtu_to_enum(dd->pport[pidx].ibmtu);
306 else
307 pmtu = attr->path_mtu;
308 return pmtu;
309}
859 310
860 attr->qp_state = qp->state; 311int qib_mtu_to_path_mtu(u32 mtu)
861 attr->cur_qp_state = attr->qp_state; 312{
862 attr->path_mtu = qp->path_mtu; 313 return mtu_to_enum(mtu);
863 attr->path_mig_state = qp->s_mig_state; 314}
864 attr->qkey = qp->qkey;
865 attr->rq_psn = qp->r_psn & QIB_PSN_MASK;
866 attr->sq_psn = qp->s_next_psn & QIB_PSN_MASK;
867 attr->dest_qp_num = qp->remote_qpn;
868 attr->qp_access_flags = qp->qp_access_flags;
869 attr->cap.max_send_wr = qp->s_size - 1;
870 attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1;
871 attr->cap.max_send_sge = qp->s_max_sge;
872 attr->cap.max_recv_sge = qp->r_rq.max_sge;
873 attr->cap.max_inline_data = 0;
874 attr->ah_attr = qp->remote_ah_attr;
875 attr->alt_ah_attr = qp->alt_ah_attr;
876 attr->pkey_index = qp->s_pkey_index;
877 attr->alt_pkey_index = qp->s_alt_pkey_index;
878 attr->en_sqd_async_notify = 0;
879 attr->sq_draining = qp->s_draining;
880 attr->max_rd_atomic = qp->s_max_rd_atomic;
881 attr->max_dest_rd_atomic = qp->r_max_rd_atomic;
882 attr->min_rnr_timer = qp->r_min_rnr_timer;
883 attr->port_num = qp->port_num;
884 attr->timeout = qp->timeout;
885 attr->retry_cnt = qp->s_retry_cnt;
886 attr->rnr_retry = qp->s_rnr_retry_cnt;
887 attr->alt_port_num = qp->alt_ah_attr.port_num;
888 attr->alt_timeout = qp->alt_timeout;
889 315
890 init_attr->event_handler = qp->ibqp.event_handler; 316u32 qib_mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu)
891 init_attr->qp_context = qp->ibqp.qp_context; 317{
892 init_attr->send_cq = qp->ibqp.send_cq; 318 return ib_mtu_enum_to_int(pmtu);
893 init_attr->recv_cq = qp->ibqp.recv_cq;
894 init_attr->srq = qp->ibqp.srq;
895 init_attr->cap = attr->cap;
896 if (qp->s_flags & QIB_S_SIGNAL_REQ_WR)
897 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR;
898 else
899 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR;
900 init_attr->qp_type = qp->ibqp.qp_type;
901 init_attr->port_num = qp->port_num;
902 return 0;
903} 319}
904 320
905/** 321/**
@@ -908,7 +324,7 @@ int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
908 * 324 *
909 * Returns the AETH. 325 * Returns the AETH.
910 */ 326 */
911__be32 qib_compute_aeth(struct qib_qp *qp) 327__be32 qib_compute_aeth(struct rvt_qp *qp)
912{ 328{
913 u32 aeth = qp->r_msn & QIB_MSN_MASK; 329 u32 aeth = qp->r_msn & QIB_MSN_MASK;
914 330
@@ -921,7 +337,7 @@ __be32 qib_compute_aeth(struct qib_qp *qp)
921 } else { 337 } else {
922 u32 min, max, x; 338 u32 min, max, x;
923 u32 credits; 339 u32 credits;
924 struct qib_rwq *wq = qp->r_rq.wq; 340 struct rvt_rwq *wq = qp->r_rq.wq;
925 u32 head; 341 u32 head;
926 u32 tail; 342 u32 tail;
927 343
@@ -962,315 +378,63 @@ __be32 qib_compute_aeth(struct qib_qp *qp)
962 return cpu_to_be32(aeth); 378 return cpu_to_be32(aeth);
963} 379}
964 380
965/** 381void *qib_qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp, gfp_t gfp)
966 * qib_create_qp - create a queue pair for a device
967 * @ibpd: the protection domain who's device we create the queue pair for
968 * @init_attr: the attributes of the queue pair
969 * @udata: user data for libibverbs.so
970 *
971 * Returns the queue pair on success, otherwise returns an errno.
972 *
973 * Called by the ib_create_qp() core verbs function.
974 */
975struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
976 struct ib_qp_init_attr *init_attr,
977 struct ib_udata *udata)
978{ 382{
979 struct qib_qp *qp; 383 struct qib_qp_priv *priv;
980 int err;
981 struct qib_swqe *swq = NULL;
982 struct qib_ibdev *dev;
983 struct qib_devdata *dd;
984 size_t sz;
985 size_t sg_list_sz;
986 struct ib_qp *ret;
987 gfp_t gfp;
988 384
385 priv = kzalloc(sizeof(*priv), gfp);
386 if (!priv)
387 return ERR_PTR(-ENOMEM);
388 priv->owner = qp;
989 389
990 if (init_attr->cap.max_send_sge > ib_qib_max_sges || 390 priv->s_hdr = kzalloc(sizeof(*priv->s_hdr), gfp);
991 init_attr->cap.max_send_wr > ib_qib_max_qp_wrs || 391 if (!priv->s_hdr) {
992 init_attr->create_flags & ~(IB_QP_CREATE_USE_GFP_NOIO)) 392 kfree(priv);
993 return ERR_PTR(-EINVAL); 393 return ERR_PTR(-ENOMEM);
994
995 /* GFP_NOIO is applicable in RC QPs only */
996 if (init_attr->create_flags & IB_QP_CREATE_USE_GFP_NOIO &&
997 init_attr->qp_type != IB_QPT_RC)
998 return ERR_PTR(-EINVAL);
999
1000 gfp = init_attr->create_flags & IB_QP_CREATE_USE_GFP_NOIO ?
1001 GFP_NOIO : GFP_KERNEL;
1002
1003 /* Check receive queue parameters if no SRQ is specified. */
1004 if (!init_attr->srq) {
1005 if (init_attr->cap.max_recv_sge > ib_qib_max_sges ||
1006 init_attr->cap.max_recv_wr > ib_qib_max_qp_wrs) {
1007 ret = ERR_PTR(-EINVAL);
1008 goto bail;
1009 }
1010 if (init_attr->cap.max_send_sge +
1011 init_attr->cap.max_send_wr +
1012 init_attr->cap.max_recv_sge +
1013 init_attr->cap.max_recv_wr == 0) {
1014 ret = ERR_PTR(-EINVAL);
1015 goto bail;
1016 }
1017 } 394 }
395 init_waitqueue_head(&priv->wait_dma);
396 INIT_WORK(&priv->s_work, _qib_do_send);
397 INIT_LIST_HEAD(&priv->iowait);
1018 398
1019 switch (init_attr->qp_type) { 399 return priv;
1020 case IB_QPT_SMI:
1021 case IB_QPT_GSI:
1022 if (init_attr->port_num == 0 ||
1023 init_attr->port_num > ibpd->device->phys_port_cnt) {
1024 ret = ERR_PTR(-EINVAL);
1025 goto bail;
1026 }
1027 case IB_QPT_UC:
1028 case IB_QPT_RC:
1029 case IB_QPT_UD:
1030 sz = sizeof(struct qib_sge) *
1031 init_attr->cap.max_send_sge +
1032 sizeof(struct qib_swqe);
1033 swq = __vmalloc((init_attr->cap.max_send_wr + 1) * sz,
1034 gfp, PAGE_KERNEL);
1035 if (swq == NULL) {
1036 ret = ERR_PTR(-ENOMEM);
1037 goto bail;
1038 }
1039 sz = sizeof(*qp);
1040 sg_list_sz = 0;
1041 if (init_attr->srq) {
1042 struct qib_srq *srq = to_isrq(init_attr->srq);
1043
1044 if (srq->rq.max_sge > 1)
1045 sg_list_sz = sizeof(*qp->r_sg_list) *
1046 (srq->rq.max_sge - 1);
1047 } else if (init_attr->cap.max_recv_sge > 1)
1048 sg_list_sz = sizeof(*qp->r_sg_list) *
1049 (init_attr->cap.max_recv_sge - 1);
1050 qp = kzalloc(sz + sg_list_sz, gfp);
1051 if (!qp) {
1052 ret = ERR_PTR(-ENOMEM);
1053 goto bail_swq;
1054 }
1055 RCU_INIT_POINTER(qp->next, NULL);
1056 qp->s_hdr = kzalloc(sizeof(*qp->s_hdr), gfp);
1057 if (!qp->s_hdr) {
1058 ret = ERR_PTR(-ENOMEM);
1059 goto bail_qp;
1060 }
1061 qp->timeout_jiffies =
1062 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
1063 1000UL);
1064 if (init_attr->srq)
1065 sz = 0;
1066 else {
1067 qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
1068 qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
1069 sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) +
1070 sizeof(struct qib_rwqe);
1071 if (gfp != GFP_NOIO)
1072 qp->r_rq.wq = vmalloc_user(
1073 sizeof(struct qib_rwq) +
1074 qp->r_rq.size * sz);
1075 else
1076 qp->r_rq.wq = __vmalloc(
1077 sizeof(struct qib_rwq) +
1078 qp->r_rq.size * sz,
1079 gfp, PAGE_KERNEL);
1080
1081 if (!qp->r_rq.wq) {
1082 ret = ERR_PTR(-ENOMEM);
1083 goto bail_qp;
1084 }
1085 }
1086
1087 /*
1088 * ib_create_qp() will initialize qp->ibqp
1089 * except for qp->ibqp.qp_num.
1090 */
1091 spin_lock_init(&qp->r_lock);
1092 spin_lock_init(&qp->s_lock);
1093 spin_lock_init(&qp->r_rq.lock);
1094 atomic_set(&qp->refcount, 0);
1095 init_waitqueue_head(&qp->wait);
1096 init_waitqueue_head(&qp->wait_dma);
1097 init_timer(&qp->s_timer);
1098 qp->s_timer.data = (unsigned long)qp;
1099 INIT_WORK(&qp->s_work, qib_do_send);
1100 INIT_LIST_HEAD(&qp->iowait);
1101 INIT_LIST_HEAD(&qp->rspwait);
1102 qp->state = IB_QPS_RESET;
1103 qp->s_wq = swq;
1104 qp->s_size = init_attr->cap.max_send_wr + 1;
1105 qp->s_max_sge = init_attr->cap.max_send_sge;
1106 if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR)
1107 qp->s_flags = QIB_S_SIGNAL_REQ_WR;
1108 dev = to_idev(ibpd->device);
1109 dd = dd_from_dev(dev);
1110 err = alloc_qpn(dd, &dev->qpn_table, init_attr->qp_type,
1111 init_attr->port_num, gfp);
1112 if (err < 0) {
1113 ret = ERR_PTR(err);
1114 vfree(qp->r_rq.wq);
1115 goto bail_qp;
1116 }
1117 qp->ibqp.qp_num = err;
1118 qp->port_num = init_attr->port_num;
1119 qib_reset_qp(qp, init_attr->qp_type);
1120 break;
1121
1122 default:
1123 /* Don't support raw QPs */
1124 ret = ERR_PTR(-ENOSYS);
1125 goto bail;
1126 }
1127
1128 init_attr->cap.max_inline_data = 0;
1129
1130 /*
1131 * Return the address of the RWQ as the offset to mmap.
1132 * See qib_mmap() for details.
1133 */
1134 if (udata && udata->outlen >= sizeof(__u64)) {
1135 if (!qp->r_rq.wq) {
1136 __u64 offset = 0;
1137
1138 err = ib_copy_to_udata(udata, &offset,
1139 sizeof(offset));
1140 if (err) {
1141 ret = ERR_PTR(err);
1142 goto bail_ip;
1143 }
1144 } else {
1145 u32 s = sizeof(struct qib_rwq) + qp->r_rq.size * sz;
1146
1147 qp->ip = qib_create_mmap_info(dev, s,
1148 ibpd->uobject->context,
1149 qp->r_rq.wq);
1150 if (!qp->ip) {
1151 ret = ERR_PTR(-ENOMEM);
1152 goto bail_ip;
1153 }
1154
1155 err = ib_copy_to_udata(udata, &(qp->ip->offset),
1156 sizeof(qp->ip->offset));
1157 if (err) {
1158 ret = ERR_PTR(err);
1159 goto bail_ip;
1160 }
1161 }
1162 }
1163
1164 spin_lock(&dev->n_qps_lock);
1165 if (dev->n_qps_allocated == ib_qib_max_qps) {
1166 spin_unlock(&dev->n_qps_lock);
1167 ret = ERR_PTR(-ENOMEM);
1168 goto bail_ip;
1169 }
1170
1171 dev->n_qps_allocated++;
1172 spin_unlock(&dev->n_qps_lock);
1173
1174 if (qp->ip) {
1175 spin_lock_irq(&dev->pending_lock);
1176 list_add(&qp->ip->pending_mmaps, &dev->pending_mmaps);
1177 spin_unlock_irq(&dev->pending_lock);
1178 }
1179
1180 ret = &qp->ibqp;
1181 goto bail;
1182
1183bail_ip:
1184 if (qp->ip)
1185 kref_put(&qp->ip->ref, qib_release_mmap_info);
1186 else
1187 vfree(qp->r_rq.wq);
1188 free_qpn(&dev->qpn_table, qp->ibqp.qp_num);
1189bail_qp:
1190 kfree(qp->s_hdr);
1191 kfree(qp);
1192bail_swq:
1193 vfree(swq);
1194bail:
1195 return ret;
1196} 400}
1197 401
1198/** 402void qib_qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp)
1199 * qib_destroy_qp - destroy a queue pair
1200 * @ibqp: the queue pair to destroy
1201 *
1202 * Returns 0 on success.
1203 *
1204 * Note that this can be called while the QP is actively sending or
1205 * receiving!
1206 */
1207int qib_destroy_qp(struct ib_qp *ibqp)
1208{ 403{
1209 struct qib_qp *qp = to_iqp(ibqp); 404 struct qib_qp_priv *priv = qp->priv;
1210 struct qib_ibdev *dev = to_idev(ibqp->device);
1211 405
1212 /* Make sure HW and driver activity is stopped. */ 406 kfree(priv->s_hdr);
1213 spin_lock_irq(&qp->s_lock); 407 kfree(priv);
1214 if (qp->state != IB_QPS_RESET) { 408}
1215 qp->state = IB_QPS_RESET;
1216 spin_lock(&dev->pending_lock);
1217 if (!list_empty(&qp->iowait))
1218 list_del_init(&qp->iowait);
1219 spin_unlock(&dev->pending_lock);
1220 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_ANY_WAIT);
1221 spin_unlock_irq(&qp->s_lock);
1222 cancel_work_sync(&qp->s_work);
1223 del_timer_sync(&qp->s_timer);
1224 wait_event(qp->wait_dma, !atomic_read(&qp->s_dma_busy));
1225 if (qp->s_tx) {
1226 qib_put_txreq(qp->s_tx);
1227 qp->s_tx = NULL;
1228 }
1229 remove_qp(dev, qp);
1230 wait_event(qp->wait, !atomic_read(&qp->refcount));
1231 clear_mr_refs(qp, 1);
1232 } else
1233 spin_unlock_irq(&qp->s_lock);
1234 409
1235 /* all user's cleaned up, mark it available */ 410void qib_stop_send_queue(struct rvt_qp *qp)
1236 free_qpn(&dev->qpn_table, qp->ibqp.qp_num); 411{
1237 spin_lock(&dev->n_qps_lock); 412 struct qib_qp_priv *priv = qp->priv;
1238 dev->n_qps_allocated--;
1239 spin_unlock(&dev->n_qps_lock);
1240 413
1241 if (qp->ip) 414 cancel_work_sync(&priv->s_work);
1242 kref_put(&qp->ip->ref, qib_release_mmap_info); 415 del_timer_sync(&qp->s_timer);
1243 else
1244 vfree(qp->r_rq.wq);
1245 vfree(qp->s_wq);
1246 kfree(qp->s_hdr);
1247 kfree(qp);
1248 return 0;
1249} 416}
1250 417
1251/** 418void qib_quiesce_qp(struct rvt_qp *qp)
1252 * qib_init_qpn_table - initialize the QP number table for a device
1253 * @qpt: the QPN table
1254 */
1255void qib_init_qpn_table(struct qib_devdata *dd, struct qib_qpn_table *qpt)
1256{ 419{
1257 spin_lock_init(&qpt->lock); 420 struct qib_qp_priv *priv = qp->priv;
1258 qpt->last = 1; /* start with QPN 2 */ 421
1259 qpt->nmaps = 1; 422 wait_event(priv->wait_dma, !atomic_read(&priv->s_dma_busy));
1260 qpt->mask = dd->qpn_mask; 423 if (priv->s_tx) {
424 qib_put_txreq(priv->s_tx);
425 priv->s_tx = NULL;
426 }
1261} 427}
1262 428
1263/** 429void qib_flush_qp_waiters(struct rvt_qp *qp)
1264 * qib_free_qpn_table - free the QP number table for a device
1265 * @qpt: the QPN table
1266 */
1267void qib_free_qpn_table(struct qib_qpn_table *qpt)
1268{ 430{
1269 int i; 431 struct qib_qp_priv *priv = qp->priv;
432 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
1270 433
1271 for (i = 0; i < ARRAY_SIZE(qpt->map); i++) 434 spin_lock(&dev->rdi.pending_lock);
1272 if (qpt->map[i].page) 435 if (!list_empty(&priv->iowait))
1273 free_page((unsigned long) qpt->map[i].page); 436 list_del_init(&priv->iowait);
437 spin_unlock(&dev->rdi.pending_lock);
1274} 438}
1275 439
1276/** 440/**
@@ -1280,7 +444,7 @@ void qib_free_qpn_table(struct qib_qpn_table *qpt)
1280 * 444 *
1281 * The QP s_lock should be held. 445 * The QP s_lock should be held.
1282 */ 446 */
1283void qib_get_credit(struct qib_qp *qp, u32 aeth) 447void qib_get_credit(struct rvt_qp *qp, u32 aeth)
1284{ 448{
1285 u32 credit = (aeth >> QIB_AETH_CREDIT_SHIFT) & QIB_AETH_CREDIT_MASK; 449 u32 credit = (aeth >> QIB_AETH_CREDIT_SHIFT) & QIB_AETH_CREDIT_MASK;
1286 450
@@ -1290,31 +454,70 @@ void qib_get_credit(struct qib_qp *qp, u32 aeth)
1290 * honor the credit field. 454 * honor the credit field.
1291 */ 455 */
1292 if (credit == QIB_AETH_CREDIT_INVAL) { 456 if (credit == QIB_AETH_CREDIT_INVAL) {
1293 if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT)) { 457 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) {
1294 qp->s_flags |= QIB_S_UNLIMITED_CREDIT; 458 qp->s_flags |= RVT_S_UNLIMITED_CREDIT;
1295 if (qp->s_flags & QIB_S_WAIT_SSN_CREDIT) { 459 if (qp->s_flags & RVT_S_WAIT_SSN_CREDIT) {
1296 qp->s_flags &= ~QIB_S_WAIT_SSN_CREDIT; 460 qp->s_flags &= ~RVT_S_WAIT_SSN_CREDIT;
1297 qib_schedule_send(qp); 461 qib_schedule_send(qp);
1298 } 462 }
1299 } 463 }
1300 } else if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT)) { 464 } else if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) {
1301 /* Compute new LSN (i.e., MSN + credit) */ 465 /* Compute new LSN (i.e., MSN + credit) */
1302 credit = (aeth + credit_table[credit]) & QIB_MSN_MASK; 466 credit = (aeth + credit_table[credit]) & QIB_MSN_MASK;
1303 if (qib_cmp24(credit, qp->s_lsn) > 0) { 467 if (qib_cmp24(credit, qp->s_lsn) > 0) {
1304 qp->s_lsn = credit; 468 qp->s_lsn = credit;
1305 if (qp->s_flags & QIB_S_WAIT_SSN_CREDIT) { 469 if (qp->s_flags & RVT_S_WAIT_SSN_CREDIT) {
1306 qp->s_flags &= ~QIB_S_WAIT_SSN_CREDIT; 470 qp->s_flags &= ~RVT_S_WAIT_SSN_CREDIT;
1307 qib_schedule_send(qp); 471 qib_schedule_send(qp);
1308 } 472 }
1309 } 473 }
1310 } 474 }
1311} 475}
1312 476
477/**
478 * qib_check_send_wqe - validate wr/wqe
479 * @qp - The qp
480 * @wqe - The built wqe
481 *
482 * validate wr/wqe. This is called
483 * prior to inserting the wqe into
484 * the ring but after the wqe has been
485 * setup.
486 *
487 * Returns 1 to force direct progress, 0 otherwise, -EINVAL on failure
488 */
489int qib_check_send_wqe(struct rvt_qp *qp,
490 struct rvt_swqe *wqe)
491{
492 struct rvt_ah *ah;
493 int ret = 0;
494
495 switch (qp->ibqp.qp_type) {
496 case IB_QPT_RC:
497 case IB_QPT_UC:
498 if (wqe->length > 0x80000000U)
499 return -EINVAL;
500 break;
501 case IB_QPT_SMI:
502 case IB_QPT_GSI:
503 case IB_QPT_UD:
504 ah = ibah_to_rvtah(wqe->ud_wr.ah);
505 if (wqe->length > (1 << ah->log_pmtu))
506 return -EINVAL;
507 /* progress hint */
508 ret = 1;
509 break;
510 default:
511 break;
512 }
513 return ret;
514}
515
1313#ifdef CONFIG_DEBUG_FS 516#ifdef CONFIG_DEBUG_FS
1314 517
1315struct qib_qp_iter { 518struct qib_qp_iter {
1316 struct qib_ibdev *dev; 519 struct qib_ibdev *dev;
1317 struct qib_qp *qp; 520 struct rvt_qp *qp;
1318 int n; 521 int n;
1319}; 522};
1320 523
@@ -1340,14 +543,14 @@ int qib_qp_iter_next(struct qib_qp_iter *iter)
1340 struct qib_ibdev *dev = iter->dev; 543 struct qib_ibdev *dev = iter->dev;
1341 int n = iter->n; 544 int n = iter->n;
1342 int ret = 1; 545 int ret = 1;
1343 struct qib_qp *pqp = iter->qp; 546 struct rvt_qp *pqp = iter->qp;
1344 struct qib_qp *qp; 547 struct rvt_qp *qp;
1345 548
1346 for (; n < dev->qp_table_size; n++) { 549 for (; n < dev->rdi.qp_dev->qp_table_size; n++) {
1347 if (pqp) 550 if (pqp)
1348 qp = rcu_dereference(pqp->next); 551 qp = rcu_dereference(pqp->next);
1349 else 552 else
1350 qp = rcu_dereference(dev->qp_table[n]); 553 qp = rcu_dereference(dev->rdi.qp_dev->qp_table[n]);
1351 pqp = qp; 554 pqp = qp;
1352 if (qp) { 555 if (qp) {
1353 iter->qp = qp; 556 iter->qp = qp;
@@ -1364,10 +567,11 @@ static const char * const qp_type_str[] = {
1364 567
1365void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter) 568void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter)
1366{ 569{
1367 struct qib_swqe *wqe; 570 struct rvt_swqe *wqe;
1368 struct qib_qp *qp = iter->qp; 571 struct rvt_qp *qp = iter->qp;
572 struct qib_qp_priv *priv = qp->priv;
1369 573
1370 wqe = get_swqe_ptr(qp, qp->s_last); 574 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
1371 seq_printf(s, 575 seq_printf(s,
1372 "N %d QP%u %s %u %u %u f=%x %u %u %u %u %u PSN %x %x %x %x %x (%u %u %u %u %u %u) QP%u LID %x\n", 576 "N %d QP%u %s %u %u %u f=%x %u %u %u %u %u PSN %x %x %x %x %x (%u %u %u %u %u %u) QP%u LID %x\n",
1373 iter->n, 577 iter->n,
@@ -1377,8 +581,8 @@ void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter)
1377 wqe->wr.opcode, 581 wqe->wr.opcode,
1378 qp->s_hdrwords, 582 qp->s_hdrwords,
1379 qp->s_flags, 583 qp->s_flags,
1380 atomic_read(&qp->s_dma_busy), 584 atomic_read(&priv->s_dma_busy),
1381 !list_empty(&qp->iowait), 585 !list_empty(&priv->iowait),
1382 qp->timeout, 586 qp->timeout,
1383 wqe->ssn, 587 wqe->ssn,
1384 qp->s_lsn, 588 qp->s_lsn,
diff --git a/drivers/infiniband/hw/qib/qib_rc.c b/drivers/infiniband/hw/qib/qib_rc.c
index e6b7556d5221..9088e26d3ac8 100644
--- a/drivers/infiniband/hw/qib/qib_rc.c
+++ b/drivers/infiniband/hw/qib/qib_rc.c
@@ -40,7 +40,7 @@
40 40
41static void rc_timeout(unsigned long arg); 41static void rc_timeout(unsigned long arg);
42 42
43static u32 restart_sge(struct qib_sge_state *ss, struct qib_swqe *wqe, 43static u32 restart_sge(struct rvt_sge_state *ss, struct rvt_swqe *wqe,
44 u32 psn, u32 pmtu) 44 u32 psn, u32 pmtu)
45{ 45{
46 u32 len; 46 u32 len;
@@ -54,9 +54,9 @@ static u32 restart_sge(struct qib_sge_state *ss, struct qib_swqe *wqe,
54 return wqe->length - len; 54 return wqe->length - len;
55} 55}
56 56
57static void start_timer(struct qib_qp *qp) 57static void start_timer(struct rvt_qp *qp)
58{ 58{
59 qp->s_flags |= QIB_S_TIMER; 59 qp->s_flags |= RVT_S_TIMER;
60 qp->s_timer.function = rc_timeout; 60 qp->s_timer.function = rc_timeout;
61 /* 4.096 usec. * (1 << qp->timeout) */ 61 /* 4.096 usec. * (1 << qp->timeout) */
62 qp->s_timer.expires = jiffies + qp->timeout_jiffies; 62 qp->s_timer.expires = jiffies + qp->timeout_jiffies;
@@ -74,17 +74,17 @@ static void start_timer(struct qib_qp *qp)
74 * Note that we are in the responder's side of the QP context. 74 * Note that we are in the responder's side of the QP context.
75 * Note the QP s_lock must be held. 75 * Note the QP s_lock must be held.
76 */ 76 */
77static int qib_make_rc_ack(struct qib_ibdev *dev, struct qib_qp *qp, 77static int qib_make_rc_ack(struct qib_ibdev *dev, struct rvt_qp *qp,
78 struct qib_other_headers *ohdr, u32 pmtu) 78 struct qib_other_headers *ohdr, u32 pmtu)
79{ 79{
80 struct qib_ack_entry *e; 80 struct rvt_ack_entry *e;
81 u32 hwords; 81 u32 hwords;
82 u32 len; 82 u32 len;
83 u32 bth0; 83 u32 bth0;
84 u32 bth2; 84 u32 bth2;
85 85
86 /* Don't send an ACK if we aren't supposed to. */ 86 /* Don't send an ACK if we aren't supposed to. */
87 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) 87 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
88 goto bail; 88 goto bail;
89 89
90 /* header size in 32-bit words LRH+BTH = (8+12)/4. */ 90 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
@@ -95,7 +95,7 @@ static int qib_make_rc_ack(struct qib_ibdev *dev, struct qib_qp *qp,
95 case OP(RDMA_READ_RESPONSE_ONLY): 95 case OP(RDMA_READ_RESPONSE_ONLY):
96 e = &qp->s_ack_queue[qp->s_tail_ack_queue]; 96 e = &qp->s_ack_queue[qp->s_tail_ack_queue];
97 if (e->rdma_sge.mr) { 97 if (e->rdma_sge.mr) {
98 qib_put_mr(e->rdma_sge.mr); 98 rvt_put_mr(e->rdma_sge.mr);
99 e->rdma_sge.mr = NULL; 99 e->rdma_sge.mr = NULL;
100 } 100 }
101 /* FALLTHROUGH */ 101 /* FALLTHROUGH */
@@ -112,7 +112,7 @@ static int qib_make_rc_ack(struct qib_ibdev *dev, struct qib_qp *qp,
112 case OP(ACKNOWLEDGE): 112 case OP(ACKNOWLEDGE):
113 /* Check for no next entry in the queue. */ 113 /* Check for no next entry in the queue. */
114 if (qp->r_head_ack_queue == qp->s_tail_ack_queue) { 114 if (qp->r_head_ack_queue == qp->s_tail_ack_queue) {
115 if (qp->s_flags & QIB_S_ACK_PENDING) 115 if (qp->s_flags & RVT_S_ACK_PENDING)
116 goto normal; 116 goto normal;
117 goto bail; 117 goto bail;
118 } 118 }
@@ -133,7 +133,7 @@ static int qib_make_rc_ack(struct qib_ibdev *dev, struct qib_qp *qp,
133 /* Copy SGE state in case we need to resend */ 133 /* Copy SGE state in case we need to resend */
134 qp->s_rdma_mr = e->rdma_sge.mr; 134 qp->s_rdma_mr = e->rdma_sge.mr;
135 if (qp->s_rdma_mr) 135 if (qp->s_rdma_mr)
136 qib_get_mr(qp->s_rdma_mr); 136 rvt_get_mr(qp->s_rdma_mr);
137 qp->s_ack_rdma_sge.sge = e->rdma_sge; 137 qp->s_ack_rdma_sge.sge = e->rdma_sge;
138 qp->s_ack_rdma_sge.num_sge = 1; 138 qp->s_ack_rdma_sge.num_sge = 1;
139 qp->s_cur_sge = &qp->s_ack_rdma_sge; 139 qp->s_cur_sge = &qp->s_ack_rdma_sge;
@@ -172,7 +172,7 @@ static int qib_make_rc_ack(struct qib_ibdev *dev, struct qib_qp *qp,
172 qp->s_cur_sge = &qp->s_ack_rdma_sge; 172 qp->s_cur_sge = &qp->s_ack_rdma_sge;
173 qp->s_rdma_mr = qp->s_ack_rdma_sge.sge.mr; 173 qp->s_rdma_mr = qp->s_ack_rdma_sge.sge.mr;
174 if (qp->s_rdma_mr) 174 if (qp->s_rdma_mr)
175 qib_get_mr(qp->s_rdma_mr); 175 rvt_get_mr(qp->s_rdma_mr);
176 len = qp->s_ack_rdma_sge.sge.sge_length; 176 len = qp->s_ack_rdma_sge.sge.sge_length;
177 if (len > pmtu) 177 if (len > pmtu)
178 len = pmtu; 178 len = pmtu;
@@ -196,7 +196,7 @@ normal:
196 * (see above). 196 * (see above).
197 */ 197 */
198 qp->s_ack_state = OP(SEND_ONLY); 198 qp->s_ack_state = OP(SEND_ONLY);
199 qp->s_flags &= ~QIB_S_ACK_PENDING; 199 qp->s_flags &= ~RVT_S_ACK_PENDING;
200 qp->s_cur_sge = NULL; 200 qp->s_cur_sge = NULL;
201 if (qp->s_nak_state) 201 if (qp->s_nak_state)
202 ohdr->u.aeth = 202 ohdr->u.aeth =
@@ -218,7 +218,7 @@ normal:
218 218
219bail: 219bail:
220 qp->s_ack_state = OP(ACKNOWLEDGE); 220 qp->s_ack_state = OP(ACKNOWLEDGE);
221 qp->s_flags &= ~(QIB_S_RESP_PENDING | QIB_S_ACK_PENDING); 221 qp->s_flags &= ~(RVT_S_RESP_PENDING | RVT_S_ACK_PENDING);
222 return 0; 222 return 0;
223} 223}
224 224
@@ -226,63 +226,60 @@ bail:
226 * qib_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC) 226 * qib_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC)
227 * @qp: a pointer to the QP 227 * @qp: a pointer to the QP
228 * 228 *
229 * Assumes the s_lock is held.
230 *
229 * Return 1 if constructed; otherwise, return 0. 231 * Return 1 if constructed; otherwise, return 0.
230 */ 232 */
231int qib_make_rc_req(struct qib_qp *qp) 233int qib_make_rc_req(struct rvt_qp *qp)
232{ 234{
235 struct qib_qp_priv *priv = qp->priv;
233 struct qib_ibdev *dev = to_idev(qp->ibqp.device); 236 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
234 struct qib_other_headers *ohdr; 237 struct qib_other_headers *ohdr;
235 struct qib_sge_state *ss; 238 struct rvt_sge_state *ss;
236 struct qib_swqe *wqe; 239 struct rvt_swqe *wqe;
237 u32 hwords; 240 u32 hwords;
238 u32 len; 241 u32 len;
239 u32 bth0; 242 u32 bth0;
240 u32 bth2; 243 u32 bth2;
241 u32 pmtu = qp->pmtu; 244 u32 pmtu = qp->pmtu;
242 char newreq; 245 char newreq;
243 unsigned long flags;
244 int ret = 0; 246 int ret = 0;
245 int delta; 247 int delta;
246 248
247 ohdr = &qp->s_hdr->u.oth; 249 ohdr = &priv->s_hdr->u.oth;
248 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH) 250 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
249 ohdr = &qp->s_hdr->u.l.oth; 251 ohdr = &priv->s_hdr->u.l.oth;
250
251 /*
252 * The lock is needed to synchronize between the sending tasklet,
253 * the receive interrupt handler, and timeout resends.
254 */
255 spin_lock_irqsave(&qp->s_lock, flags);
256 252
257 /* Sending responses has higher priority over sending requests. */ 253 /* Sending responses has higher priority over sending requests. */
258 if ((qp->s_flags & QIB_S_RESP_PENDING) && 254 if ((qp->s_flags & RVT_S_RESP_PENDING) &&
259 qib_make_rc_ack(dev, qp, ohdr, pmtu)) 255 qib_make_rc_ack(dev, qp, ohdr, pmtu))
260 goto done; 256 goto done;
261 257
262 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_SEND_OK)) { 258 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) {
263 if (!(ib_qib_state_ops[qp->state] & QIB_FLUSH_SEND)) 259 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
264 goto bail; 260 goto bail;
265 /* We are in the error state, flush the work request. */ 261 /* We are in the error state, flush the work request. */
266 if (qp->s_last == qp->s_head) 262 smp_read_barrier_depends(); /* see post_one_send() */
263 if (qp->s_last == ACCESS_ONCE(qp->s_head))
267 goto bail; 264 goto bail;
268 /* If DMAs are in progress, we can't flush immediately. */ 265 /* If DMAs are in progress, we can't flush immediately. */
269 if (atomic_read(&qp->s_dma_busy)) { 266 if (atomic_read(&priv->s_dma_busy)) {
270 qp->s_flags |= QIB_S_WAIT_DMA; 267 qp->s_flags |= RVT_S_WAIT_DMA;
271 goto bail; 268 goto bail;
272 } 269 }
273 wqe = get_swqe_ptr(qp, qp->s_last); 270 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
274 qib_send_complete(qp, wqe, qp->s_last != qp->s_acked ? 271 qib_send_complete(qp, wqe, qp->s_last != qp->s_acked ?
275 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR); 272 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR);
276 /* will get called again */ 273 /* will get called again */
277 goto done; 274 goto done;
278 } 275 }
279 276
280 if (qp->s_flags & (QIB_S_WAIT_RNR | QIB_S_WAIT_ACK)) 277 if (qp->s_flags & (RVT_S_WAIT_RNR | RVT_S_WAIT_ACK))
281 goto bail; 278 goto bail;
282 279
283 if (qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) { 280 if (qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) {
284 if (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) { 281 if (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) {
285 qp->s_flags |= QIB_S_WAIT_PSN; 282 qp->s_flags |= RVT_S_WAIT_PSN;
286 goto bail; 283 goto bail;
287 } 284 }
288 qp->s_sending_psn = qp->s_psn; 285 qp->s_sending_psn = qp->s_psn;
@@ -294,10 +291,10 @@ int qib_make_rc_req(struct qib_qp *qp)
294 bth0 = 0; 291 bth0 = 0;
295 292
296 /* Send a request. */ 293 /* Send a request. */
297 wqe = get_swqe_ptr(qp, qp->s_cur); 294 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
298 switch (qp->s_state) { 295 switch (qp->s_state) {
299 default: 296 default:
300 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_NEXT_SEND_OK)) 297 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK))
301 goto bail; 298 goto bail;
302 /* 299 /*
303 * Resend an old request or start a new one. 300 * Resend an old request or start a new one.
@@ -317,11 +314,11 @@ int qib_make_rc_req(struct qib_qp *qp)
317 */ 314 */
318 if ((wqe->wr.send_flags & IB_SEND_FENCE) && 315 if ((wqe->wr.send_flags & IB_SEND_FENCE) &&
319 qp->s_num_rd_atomic) { 316 qp->s_num_rd_atomic) {
320 qp->s_flags |= QIB_S_WAIT_FENCE; 317 qp->s_flags |= RVT_S_WAIT_FENCE;
321 goto bail; 318 goto bail;
322 } 319 }
323 wqe->psn = qp->s_next_psn;
324 newreq = 1; 320 newreq = 1;
321 qp->s_psn = wqe->psn;
325 } 322 }
326 /* 323 /*
327 * Note that we have to be careful not to modify the 324 * Note that we have to be careful not to modify the
@@ -335,14 +332,12 @@ int qib_make_rc_req(struct qib_qp *qp)
335 case IB_WR_SEND: 332 case IB_WR_SEND:
336 case IB_WR_SEND_WITH_IMM: 333 case IB_WR_SEND_WITH_IMM:
337 /* If no credit, return. */ 334 /* If no credit, return. */
338 if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT) && 335 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
339 qib_cmp24(wqe->ssn, qp->s_lsn + 1) > 0) { 336 qib_cmp24(wqe->ssn, qp->s_lsn + 1) > 0) {
340 qp->s_flags |= QIB_S_WAIT_SSN_CREDIT; 337 qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
341 goto bail; 338 goto bail;
342 } 339 }
343 wqe->lpsn = wqe->psn;
344 if (len > pmtu) { 340 if (len > pmtu) {
345 wqe->lpsn += (len - 1) / pmtu;
346 qp->s_state = OP(SEND_FIRST); 341 qp->s_state = OP(SEND_FIRST);
347 len = pmtu; 342 len = pmtu;
348 break; 343 break;
@@ -363,14 +358,14 @@ int qib_make_rc_req(struct qib_qp *qp)
363 break; 358 break;
364 359
365 case IB_WR_RDMA_WRITE: 360 case IB_WR_RDMA_WRITE:
366 if (newreq && !(qp->s_flags & QIB_S_UNLIMITED_CREDIT)) 361 if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
367 qp->s_lsn++; 362 qp->s_lsn++;
368 /* FALLTHROUGH */ 363 /* FALLTHROUGH */
369 case IB_WR_RDMA_WRITE_WITH_IMM: 364 case IB_WR_RDMA_WRITE_WITH_IMM:
370 /* If no credit, return. */ 365 /* If no credit, return. */
371 if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT) && 366 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
372 qib_cmp24(wqe->ssn, qp->s_lsn + 1) > 0) { 367 qib_cmp24(wqe->ssn, qp->s_lsn + 1) > 0) {
373 qp->s_flags |= QIB_S_WAIT_SSN_CREDIT; 368 qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
374 goto bail; 369 goto bail;
375 } 370 }
376 371
@@ -380,9 +375,7 @@ int qib_make_rc_req(struct qib_qp *qp)
380 cpu_to_be32(wqe->rdma_wr.rkey); 375 cpu_to_be32(wqe->rdma_wr.rkey);
381 ohdr->u.rc.reth.length = cpu_to_be32(len); 376 ohdr->u.rc.reth.length = cpu_to_be32(len);
382 hwords += sizeof(struct ib_reth) / sizeof(u32); 377 hwords += sizeof(struct ib_reth) / sizeof(u32);
383 wqe->lpsn = wqe->psn;
384 if (len > pmtu) { 378 if (len > pmtu) {
385 wqe->lpsn += (len - 1) / pmtu;
386 qp->s_state = OP(RDMA_WRITE_FIRST); 379 qp->s_state = OP(RDMA_WRITE_FIRST);
387 len = pmtu; 380 len = pmtu;
388 break; 381 break;
@@ -411,19 +404,12 @@ int qib_make_rc_req(struct qib_qp *qp)
411 if (newreq) { 404 if (newreq) {
412 if (qp->s_num_rd_atomic >= 405 if (qp->s_num_rd_atomic >=
413 qp->s_max_rd_atomic) { 406 qp->s_max_rd_atomic) {
414 qp->s_flags |= QIB_S_WAIT_RDMAR; 407 qp->s_flags |= RVT_S_WAIT_RDMAR;
415 goto bail; 408 goto bail;
416 } 409 }
417 qp->s_num_rd_atomic++; 410 qp->s_num_rd_atomic++;
418 if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT)) 411 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
419 qp->s_lsn++; 412 qp->s_lsn++;
420 /*
421 * Adjust s_next_psn to count the
422 * expected number of responses.
423 */
424 if (len > pmtu)
425 qp->s_next_psn += (len - 1) / pmtu;
426 wqe->lpsn = qp->s_next_psn++;
427 } 413 }
428 414
429 ohdr->u.rc.reth.vaddr = 415 ohdr->u.rc.reth.vaddr =
@@ -449,13 +435,12 @@ int qib_make_rc_req(struct qib_qp *qp)
449 if (newreq) { 435 if (newreq) {
450 if (qp->s_num_rd_atomic >= 436 if (qp->s_num_rd_atomic >=
451 qp->s_max_rd_atomic) { 437 qp->s_max_rd_atomic) {
452 qp->s_flags |= QIB_S_WAIT_RDMAR; 438 qp->s_flags |= RVT_S_WAIT_RDMAR;
453 goto bail; 439 goto bail;
454 } 440 }
455 qp->s_num_rd_atomic++; 441 qp->s_num_rd_atomic++;
456 if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT)) 442 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
457 qp->s_lsn++; 443 qp->s_lsn++;
458 wqe->lpsn = wqe->psn;
459 } 444 }
460 if (wqe->atomic_wr.wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP) { 445 if (wqe->atomic_wr.wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
461 qp->s_state = OP(COMPARE_SWAP); 446 qp->s_state = OP(COMPARE_SWAP);
@@ -498,11 +483,8 @@ int qib_make_rc_req(struct qib_qp *qp)
498 } 483 }
499 if (wqe->wr.opcode == IB_WR_RDMA_READ) 484 if (wqe->wr.opcode == IB_WR_RDMA_READ)
500 qp->s_psn = wqe->lpsn + 1; 485 qp->s_psn = wqe->lpsn + 1;
501 else { 486 else
502 qp->s_psn++; 487 qp->s_psn++;
503 if (qib_cmp24(qp->s_psn, qp->s_next_psn) > 0)
504 qp->s_next_psn = qp->s_psn;
505 }
506 break; 488 break;
507 489
508 case OP(RDMA_READ_RESPONSE_FIRST): 490 case OP(RDMA_READ_RESPONSE_FIRST):
@@ -522,8 +504,6 @@ int qib_make_rc_req(struct qib_qp *qp)
522 /* FALLTHROUGH */ 504 /* FALLTHROUGH */
523 case OP(SEND_MIDDLE): 505 case OP(SEND_MIDDLE):
524 bth2 = qp->s_psn++ & QIB_PSN_MASK; 506 bth2 = qp->s_psn++ & QIB_PSN_MASK;
525 if (qib_cmp24(qp->s_psn, qp->s_next_psn) > 0)
526 qp->s_next_psn = qp->s_psn;
527 ss = &qp->s_sge; 507 ss = &qp->s_sge;
528 len = qp->s_len; 508 len = qp->s_len;
529 if (len > pmtu) { 509 if (len > pmtu) {
@@ -563,8 +543,6 @@ int qib_make_rc_req(struct qib_qp *qp)
563 /* FALLTHROUGH */ 543 /* FALLTHROUGH */
564 case OP(RDMA_WRITE_MIDDLE): 544 case OP(RDMA_WRITE_MIDDLE):
565 bth2 = qp->s_psn++ & QIB_PSN_MASK; 545 bth2 = qp->s_psn++ & QIB_PSN_MASK;
566 if (qib_cmp24(qp->s_psn, qp->s_next_psn) > 0)
567 qp->s_next_psn = qp->s_psn;
568 ss = &qp->s_sge; 546 ss = &qp->s_sge;
569 len = qp->s_len; 547 len = qp->s_len;
570 if (len > pmtu) { 548 if (len > pmtu) {
@@ -618,9 +596,9 @@ int qib_make_rc_req(struct qib_qp *qp)
618 delta = (((int) bth2 - (int) wqe->psn) << 8) >> 8; 596 delta = (((int) bth2 - (int) wqe->psn) << 8) >> 8;
619 if (delta && delta % QIB_PSN_CREDIT == 0) 597 if (delta && delta % QIB_PSN_CREDIT == 0)
620 bth2 |= IB_BTH_REQ_ACK; 598 bth2 |= IB_BTH_REQ_ACK;
621 if (qp->s_flags & QIB_S_SEND_ONE) { 599 if (qp->s_flags & RVT_S_SEND_ONE) {
622 qp->s_flags &= ~QIB_S_SEND_ONE; 600 qp->s_flags &= ~RVT_S_SEND_ONE;
623 qp->s_flags |= QIB_S_WAIT_ACK; 601 qp->s_flags |= RVT_S_WAIT_ACK;
624 bth2 |= IB_BTH_REQ_ACK; 602 bth2 |= IB_BTH_REQ_ACK;
625 } 603 }
626 qp->s_len -= len; 604 qp->s_len -= len;
@@ -629,13 +607,9 @@ int qib_make_rc_req(struct qib_qp *qp)
629 qp->s_cur_size = len; 607 qp->s_cur_size = len;
630 qib_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24), bth2); 608 qib_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24), bth2);
631done: 609done:
632 ret = 1; 610 return 1;
633 goto unlock;
634
635bail: 611bail:
636 qp->s_flags &= ~QIB_S_BUSY; 612 qp->s_flags &= ~RVT_S_BUSY;
637unlock:
638 spin_unlock_irqrestore(&qp->s_lock, flags);
639 return ret; 613 return ret;
640} 614}
641 615
@@ -647,7 +621,7 @@ unlock:
647 * Note that RDMA reads and atomics are handled in the 621 * Note that RDMA reads and atomics are handled in the
648 * send side QP state and tasklet. 622 * send side QP state and tasklet.
649 */ 623 */
650void qib_send_rc_ack(struct qib_qp *qp) 624void qib_send_rc_ack(struct rvt_qp *qp)
651{ 625{
652 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device); 626 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
653 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 627 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
@@ -665,11 +639,11 @@ void qib_send_rc_ack(struct qib_qp *qp)
665 639
666 spin_lock_irqsave(&qp->s_lock, flags); 640 spin_lock_irqsave(&qp->s_lock, flags);
667 641
668 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) 642 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
669 goto unlock; 643 goto unlock;
670 644
671 /* Don't send ACK or NAK if a RDMA read or atomic is pending. */ 645 /* Don't send ACK or NAK if a RDMA read or atomic is pending. */
672 if ((qp->s_flags & QIB_S_RESP_PENDING) || qp->s_rdma_ack_cnt) 646 if ((qp->s_flags & RVT_S_RESP_PENDING) || qp->s_rdma_ack_cnt)
673 goto queue_ack; 647 goto queue_ack;
674 648
675 /* Construct the header with s_lock held so APM doesn't change it. */ 649 /* Construct the header with s_lock held so APM doesn't change it. */
@@ -758,9 +732,9 @@ void qib_send_rc_ack(struct qib_qp *qp)
758 goto done; 732 goto done;
759 733
760queue_ack: 734queue_ack:
761 if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) { 735 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
762 ibp->n_rc_qacks++; 736 this_cpu_inc(*ibp->rvp.rc_qacks);
763 qp->s_flags |= QIB_S_ACK_PENDING | QIB_S_RESP_PENDING; 737 qp->s_flags |= RVT_S_ACK_PENDING | RVT_S_RESP_PENDING;
764 qp->s_nak_state = qp->r_nak_state; 738 qp->s_nak_state = qp->r_nak_state;
765 qp->s_ack_psn = qp->r_ack_psn; 739 qp->s_ack_psn = qp->r_ack_psn;
766 740
@@ -782,10 +756,10 @@ done:
782 * for the given QP. 756 * for the given QP.
783 * Called at interrupt level with the QP s_lock held. 757 * Called at interrupt level with the QP s_lock held.
784 */ 758 */
785static void reset_psn(struct qib_qp *qp, u32 psn) 759static void reset_psn(struct rvt_qp *qp, u32 psn)
786{ 760{
787 u32 n = qp->s_acked; 761 u32 n = qp->s_acked;
788 struct qib_swqe *wqe = get_swqe_ptr(qp, n); 762 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, n);
789 u32 opcode; 763 u32 opcode;
790 764
791 qp->s_cur = n; 765 qp->s_cur = n;
@@ -808,7 +782,7 @@ static void reset_psn(struct qib_qp *qp, u32 psn)
808 n = 0; 782 n = 0;
809 if (n == qp->s_tail) 783 if (n == qp->s_tail)
810 break; 784 break;
811 wqe = get_swqe_ptr(qp, n); 785 wqe = rvt_get_swqe_ptr(qp, n);
812 diff = qib_cmp24(psn, wqe->psn); 786 diff = qib_cmp24(psn, wqe->psn);
813 if (diff < 0) 787 if (diff < 0)
814 break; 788 break;
@@ -854,22 +828,22 @@ static void reset_psn(struct qib_qp *qp, u32 psn)
854done: 828done:
855 qp->s_psn = psn; 829 qp->s_psn = psn;
856 /* 830 /*
857 * Set QIB_S_WAIT_PSN as qib_rc_complete() may start the timer 831 * Set RVT_S_WAIT_PSN as qib_rc_complete() may start the timer
858 * asynchronously before the send tasklet can get scheduled. 832 * asynchronously before the send tasklet can get scheduled.
859 * Doing it in qib_make_rc_req() is too late. 833 * Doing it in qib_make_rc_req() is too late.
860 */ 834 */
861 if ((qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) && 835 if ((qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) &&
862 (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)) 836 (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0))
863 qp->s_flags |= QIB_S_WAIT_PSN; 837 qp->s_flags |= RVT_S_WAIT_PSN;
864} 838}
865 839
866/* 840/*
867 * Back up requester to resend the last un-ACKed request. 841 * Back up requester to resend the last un-ACKed request.
868 * The QP r_lock and s_lock should be held and interrupts disabled. 842 * The QP r_lock and s_lock should be held and interrupts disabled.
869 */ 843 */
870static void qib_restart_rc(struct qib_qp *qp, u32 psn, int wait) 844static void qib_restart_rc(struct rvt_qp *qp, u32 psn, int wait)
871{ 845{
872 struct qib_swqe *wqe = get_swqe_ptr(qp, qp->s_acked); 846 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
873 struct qib_ibport *ibp; 847 struct qib_ibport *ibp;
874 848
875 if (qp->s_retry == 0) { 849 if (qp->s_retry == 0) {
@@ -878,7 +852,7 @@ static void qib_restart_rc(struct qib_qp *qp, u32 psn, int wait)
878 qp->s_retry = qp->s_retry_cnt; 852 qp->s_retry = qp->s_retry_cnt;
879 } else if (qp->s_last == qp->s_acked) { 853 } else if (qp->s_last == qp->s_acked) {
880 qib_send_complete(qp, wqe, IB_WC_RETRY_EXC_ERR); 854 qib_send_complete(qp, wqe, IB_WC_RETRY_EXC_ERR);
881 qib_error_qp(qp, IB_WC_WR_FLUSH_ERR); 855 rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
882 return; 856 return;
883 } else /* XXX need to handle delayed completion */ 857 } else /* XXX need to handle delayed completion */
884 return; 858 return;
@@ -887,15 +861,15 @@ static void qib_restart_rc(struct qib_qp *qp, u32 psn, int wait)
887 861
888 ibp = to_iport(qp->ibqp.device, qp->port_num); 862 ibp = to_iport(qp->ibqp.device, qp->port_num);
889 if (wqe->wr.opcode == IB_WR_RDMA_READ) 863 if (wqe->wr.opcode == IB_WR_RDMA_READ)
890 ibp->n_rc_resends++; 864 ibp->rvp.n_rc_resends++;
891 else 865 else
892 ibp->n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK; 866 ibp->rvp.n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK;
893 867
894 qp->s_flags &= ~(QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | 868 qp->s_flags &= ~(RVT_S_WAIT_FENCE | RVT_S_WAIT_RDMAR |
895 QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_PSN | 869 RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_PSN |
896 QIB_S_WAIT_ACK); 870 RVT_S_WAIT_ACK);
897 if (wait) 871 if (wait)
898 qp->s_flags |= QIB_S_SEND_ONE; 872 qp->s_flags |= RVT_S_SEND_ONE;
899 reset_psn(qp, psn); 873 reset_psn(qp, psn);
900} 874}
901 875
@@ -904,16 +878,16 @@ static void qib_restart_rc(struct qib_qp *qp, u32 psn, int wait)
904 */ 878 */
905static void rc_timeout(unsigned long arg) 879static void rc_timeout(unsigned long arg)
906{ 880{
907 struct qib_qp *qp = (struct qib_qp *)arg; 881 struct rvt_qp *qp = (struct rvt_qp *)arg;
908 struct qib_ibport *ibp; 882 struct qib_ibport *ibp;
909 unsigned long flags; 883 unsigned long flags;
910 884
911 spin_lock_irqsave(&qp->r_lock, flags); 885 spin_lock_irqsave(&qp->r_lock, flags);
912 spin_lock(&qp->s_lock); 886 spin_lock(&qp->s_lock);
913 if (qp->s_flags & QIB_S_TIMER) { 887 if (qp->s_flags & RVT_S_TIMER) {
914 ibp = to_iport(qp->ibqp.device, qp->port_num); 888 ibp = to_iport(qp->ibqp.device, qp->port_num);
915 ibp->n_rc_timeouts++; 889 ibp->rvp.n_rc_timeouts++;
916 qp->s_flags &= ~QIB_S_TIMER; 890 qp->s_flags &= ~RVT_S_TIMER;
917 del_timer(&qp->s_timer); 891 del_timer(&qp->s_timer);
918 qib_restart_rc(qp, qp->s_last_psn + 1, 1); 892 qib_restart_rc(qp, qp->s_last_psn + 1, 1);
919 qib_schedule_send(qp); 893 qib_schedule_send(qp);
@@ -927,12 +901,12 @@ static void rc_timeout(unsigned long arg)
927 */ 901 */
928void qib_rc_rnr_retry(unsigned long arg) 902void qib_rc_rnr_retry(unsigned long arg)
929{ 903{
930 struct qib_qp *qp = (struct qib_qp *)arg; 904 struct rvt_qp *qp = (struct rvt_qp *)arg;
931 unsigned long flags; 905 unsigned long flags;
932 906
933 spin_lock_irqsave(&qp->s_lock, flags); 907 spin_lock_irqsave(&qp->s_lock, flags);
934 if (qp->s_flags & QIB_S_WAIT_RNR) { 908 if (qp->s_flags & RVT_S_WAIT_RNR) {
935 qp->s_flags &= ~QIB_S_WAIT_RNR; 909 qp->s_flags &= ~RVT_S_WAIT_RNR;
936 del_timer(&qp->s_timer); 910 del_timer(&qp->s_timer);
937 qib_schedule_send(qp); 911 qib_schedule_send(qp);
938 } 912 }
@@ -943,14 +917,14 @@ void qib_rc_rnr_retry(unsigned long arg)
943 * Set qp->s_sending_psn to the next PSN after the given one. 917 * Set qp->s_sending_psn to the next PSN after the given one.
944 * This would be psn+1 except when RDMA reads are present. 918 * This would be psn+1 except when RDMA reads are present.
945 */ 919 */
946static void reset_sending_psn(struct qib_qp *qp, u32 psn) 920static void reset_sending_psn(struct rvt_qp *qp, u32 psn)
947{ 921{
948 struct qib_swqe *wqe; 922 struct rvt_swqe *wqe;
949 u32 n = qp->s_last; 923 u32 n = qp->s_last;
950 924
951 /* Find the work request corresponding to the given PSN. */ 925 /* Find the work request corresponding to the given PSN. */
952 for (;;) { 926 for (;;) {
953 wqe = get_swqe_ptr(qp, n); 927 wqe = rvt_get_swqe_ptr(qp, n);
954 if (qib_cmp24(psn, wqe->lpsn) <= 0) { 928 if (qib_cmp24(psn, wqe->lpsn) <= 0) {
955 if (wqe->wr.opcode == IB_WR_RDMA_READ) 929 if (wqe->wr.opcode == IB_WR_RDMA_READ)
956 qp->s_sending_psn = wqe->lpsn + 1; 930 qp->s_sending_psn = wqe->lpsn + 1;
@@ -968,16 +942,16 @@ static void reset_sending_psn(struct qib_qp *qp, u32 psn)
968/* 942/*
969 * This should be called with the QP s_lock held and interrupts disabled. 943 * This should be called with the QP s_lock held and interrupts disabled.
970 */ 944 */
971void qib_rc_send_complete(struct qib_qp *qp, struct qib_ib_header *hdr) 945void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr)
972{ 946{
973 struct qib_other_headers *ohdr; 947 struct qib_other_headers *ohdr;
974 struct qib_swqe *wqe; 948 struct rvt_swqe *wqe;
975 struct ib_wc wc; 949 struct ib_wc wc;
976 unsigned i; 950 unsigned i;
977 u32 opcode; 951 u32 opcode;
978 u32 psn; 952 u32 psn;
979 953
980 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_OR_FLUSH_SEND)) 954 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND))
981 return; 955 return;
982 956
983 /* Find out where the BTH is */ 957 /* Find out where the BTH is */
@@ -1002,22 +976,30 @@ void qib_rc_send_complete(struct qib_qp *qp, struct qib_ib_header *hdr)
1002 * there are still requests that haven't been acked. 976 * there are still requests that haven't been acked.
1003 */ 977 */
1004 if ((psn & IB_BTH_REQ_ACK) && qp->s_acked != qp->s_tail && 978 if ((psn & IB_BTH_REQ_ACK) && qp->s_acked != qp->s_tail &&
1005 !(qp->s_flags & (QIB_S_TIMER | QIB_S_WAIT_RNR | QIB_S_WAIT_PSN)) && 979 !(qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR | RVT_S_WAIT_PSN)) &&
1006 (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) 980 (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
1007 start_timer(qp); 981 start_timer(qp);
1008 982
1009 while (qp->s_last != qp->s_acked) { 983 while (qp->s_last != qp->s_acked) {
1010 wqe = get_swqe_ptr(qp, qp->s_last); 984 u32 s_last;
985
986 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
1011 if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) >= 0 && 987 if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) >= 0 &&
1012 qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) 988 qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)
1013 break; 989 break;
990 s_last = qp->s_last;
991 if (++s_last >= qp->s_size)
992 s_last = 0;
993 qp->s_last = s_last;
994 /* see post_send() */
995 barrier();
1014 for (i = 0; i < wqe->wr.num_sge; i++) { 996 for (i = 0; i < wqe->wr.num_sge; i++) {
1015 struct qib_sge *sge = &wqe->sg_list[i]; 997 struct rvt_sge *sge = &wqe->sg_list[i];
1016 998
1017 qib_put_mr(sge->mr); 999 rvt_put_mr(sge->mr);
1018 } 1000 }
1019 /* Post a send completion queue entry if requested. */ 1001 /* Post a send completion queue entry if requested. */
1020 if (!(qp->s_flags & QIB_S_SIGNAL_REQ_WR) || 1002 if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) ||
1021 (wqe->wr.send_flags & IB_SEND_SIGNALED)) { 1003 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
1022 memset(&wc, 0, sizeof(wc)); 1004 memset(&wc, 0, sizeof(wc));
1023 wc.wr_id = wqe->wr.wr_id; 1005 wc.wr_id = wqe->wr.wr_id;
@@ -1025,25 +1007,23 @@ void qib_rc_send_complete(struct qib_qp *qp, struct qib_ib_header *hdr)
1025 wc.opcode = ib_qib_wc_opcode[wqe->wr.opcode]; 1007 wc.opcode = ib_qib_wc_opcode[wqe->wr.opcode];
1026 wc.byte_len = wqe->length; 1008 wc.byte_len = wqe->length;
1027 wc.qp = &qp->ibqp; 1009 wc.qp = &qp->ibqp;
1028 qib_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0); 1010 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc, 0);
1029 } 1011 }
1030 if (++qp->s_last >= qp->s_size)
1031 qp->s_last = 0;
1032 } 1012 }
1033 /* 1013 /*
1034 * If we were waiting for sends to complete before resending, 1014 * If we were waiting for sends to complete before resending,
1035 * and they are now complete, restart sending. 1015 * and they are now complete, restart sending.
1036 */ 1016 */
1037 if (qp->s_flags & QIB_S_WAIT_PSN && 1017 if (qp->s_flags & RVT_S_WAIT_PSN &&
1038 qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) { 1018 qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
1039 qp->s_flags &= ~QIB_S_WAIT_PSN; 1019 qp->s_flags &= ~RVT_S_WAIT_PSN;
1040 qp->s_sending_psn = qp->s_psn; 1020 qp->s_sending_psn = qp->s_psn;
1041 qp->s_sending_hpsn = qp->s_psn - 1; 1021 qp->s_sending_hpsn = qp->s_psn - 1;
1042 qib_schedule_send(qp); 1022 qib_schedule_send(qp);
1043 } 1023 }
1044} 1024}
1045 1025
1046static inline void update_last_psn(struct qib_qp *qp, u32 psn) 1026static inline void update_last_psn(struct rvt_qp *qp, u32 psn)
1047{ 1027{
1048 qp->s_last_psn = psn; 1028 qp->s_last_psn = psn;
1049} 1029}
@@ -1053,8 +1033,8 @@ static inline void update_last_psn(struct qib_qp *qp, u32 psn)
1053 * This is similar to qib_send_complete but has to check to be sure 1033 * This is similar to qib_send_complete but has to check to be sure
1054 * that the SGEs are not being referenced if the SWQE is being resent. 1034 * that the SGEs are not being referenced if the SWQE is being resent.
1055 */ 1035 */
1056static struct qib_swqe *do_rc_completion(struct qib_qp *qp, 1036static struct rvt_swqe *do_rc_completion(struct rvt_qp *qp,
1057 struct qib_swqe *wqe, 1037 struct rvt_swqe *wqe,
1058 struct qib_ibport *ibp) 1038 struct qib_ibport *ibp)
1059{ 1039{
1060 struct ib_wc wc; 1040 struct ib_wc wc;
@@ -1067,13 +1047,21 @@ static struct qib_swqe *do_rc_completion(struct qib_qp *qp,
1067 */ 1047 */
1068 if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) < 0 || 1048 if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) < 0 ||
1069 qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) { 1049 qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
1050 u32 s_last;
1051
1070 for (i = 0; i < wqe->wr.num_sge; i++) { 1052 for (i = 0; i < wqe->wr.num_sge; i++) {
1071 struct qib_sge *sge = &wqe->sg_list[i]; 1053 struct rvt_sge *sge = &wqe->sg_list[i];
1072 1054
1073 qib_put_mr(sge->mr); 1055 rvt_put_mr(sge->mr);
1074 } 1056 }
1057 s_last = qp->s_last;
1058 if (++s_last >= qp->s_size)
1059 s_last = 0;
1060 qp->s_last = s_last;
1061 /* see post_send() */
1062 barrier();
1075 /* Post a send completion queue entry if requested. */ 1063 /* Post a send completion queue entry if requested. */
1076 if (!(qp->s_flags & QIB_S_SIGNAL_REQ_WR) || 1064 if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) ||
1077 (wqe->wr.send_flags & IB_SEND_SIGNALED)) { 1065 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
1078 memset(&wc, 0, sizeof(wc)); 1066 memset(&wc, 0, sizeof(wc));
1079 wc.wr_id = wqe->wr.wr_id; 1067 wc.wr_id = wqe->wr.wr_id;
@@ -1081,12 +1069,10 @@ static struct qib_swqe *do_rc_completion(struct qib_qp *qp,
1081 wc.opcode = ib_qib_wc_opcode[wqe->wr.opcode]; 1069 wc.opcode = ib_qib_wc_opcode[wqe->wr.opcode];
1082 wc.byte_len = wqe->length; 1070 wc.byte_len = wqe->length;
1083 wc.qp = &qp->ibqp; 1071 wc.qp = &qp->ibqp;
1084 qib_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0); 1072 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc, 0);
1085 } 1073 }
1086 if (++qp->s_last >= qp->s_size)
1087 qp->s_last = 0;
1088 } else 1074 } else
1089 ibp->n_rc_delayed_comp++; 1075 this_cpu_inc(*ibp->rvp.rc_delayed_comp);
1090 1076
1091 qp->s_retry = qp->s_retry_cnt; 1077 qp->s_retry = qp->s_retry_cnt;
1092 update_last_psn(qp, wqe->lpsn); 1078 update_last_psn(qp, wqe->lpsn);
@@ -1100,7 +1086,7 @@ static struct qib_swqe *do_rc_completion(struct qib_qp *qp,
1100 if (++qp->s_cur >= qp->s_size) 1086 if (++qp->s_cur >= qp->s_size)
1101 qp->s_cur = 0; 1087 qp->s_cur = 0;
1102 qp->s_acked = qp->s_cur; 1088 qp->s_acked = qp->s_cur;
1103 wqe = get_swqe_ptr(qp, qp->s_cur); 1089 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
1104 if (qp->s_acked != qp->s_tail) { 1090 if (qp->s_acked != qp->s_tail) {
1105 qp->s_state = OP(SEND_LAST); 1091 qp->s_state = OP(SEND_LAST);
1106 qp->s_psn = wqe->psn; 1092 qp->s_psn = wqe->psn;
@@ -1110,7 +1096,7 @@ static struct qib_swqe *do_rc_completion(struct qib_qp *qp,
1110 qp->s_acked = 0; 1096 qp->s_acked = 0;
1111 if (qp->state == IB_QPS_SQD && qp->s_acked == qp->s_cur) 1097 if (qp->state == IB_QPS_SQD && qp->s_acked == qp->s_cur)
1112 qp->s_draining = 0; 1098 qp->s_draining = 0;
1113 wqe = get_swqe_ptr(qp, qp->s_acked); 1099 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1114 } 1100 }
1115 return wqe; 1101 return wqe;
1116} 1102}
@@ -1126,19 +1112,19 @@ static struct qib_swqe *do_rc_completion(struct qib_qp *qp,
1126 * Called at interrupt level with the QP s_lock held. 1112 * Called at interrupt level with the QP s_lock held.
1127 * Returns 1 if OK, 0 if current operation should be aborted (NAK). 1113 * Returns 1 if OK, 0 if current operation should be aborted (NAK).
1128 */ 1114 */
1129static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode, 1115static int do_rc_ack(struct rvt_qp *qp, u32 aeth, u32 psn, int opcode,
1130 u64 val, struct qib_ctxtdata *rcd) 1116 u64 val, struct qib_ctxtdata *rcd)
1131{ 1117{
1132 struct qib_ibport *ibp; 1118 struct qib_ibport *ibp;
1133 enum ib_wc_status status; 1119 enum ib_wc_status status;
1134 struct qib_swqe *wqe; 1120 struct rvt_swqe *wqe;
1135 int ret = 0; 1121 int ret = 0;
1136 u32 ack_psn; 1122 u32 ack_psn;
1137 int diff; 1123 int diff;
1138 1124
1139 /* Remove QP from retry timer */ 1125 /* Remove QP from retry timer */
1140 if (qp->s_flags & (QIB_S_TIMER | QIB_S_WAIT_RNR)) { 1126 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) {
1141 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_WAIT_RNR); 1127 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR);
1142 del_timer(&qp->s_timer); 1128 del_timer(&qp->s_timer);
1143 } 1129 }
1144 1130
@@ -1151,7 +1137,7 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1151 ack_psn = psn; 1137 ack_psn = psn;
1152 if (aeth >> 29) 1138 if (aeth >> 29)
1153 ack_psn--; 1139 ack_psn--;
1154 wqe = get_swqe_ptr(qp, qp->s_acked); 1140 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1155 ibp = to_iport(qp->ibqp.device, qp->port_num); 1141 ibp = to_iport(qp->ibqp.device, qp->port_num);
1156 1142
1157 /* 1143 /*
@@ -1186,11 +1172,11 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1186 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) && 1172 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) &&
1187 (opcode != OP(ATOMIC_ACKNOWLEDGE) || diff != 0))) { 1173 (opcode != OP(ATOMIC_ACKNOWLEDGE) || diff != 0))) {
1188 /* Retry this request. */ 1174 /* Retry this request. */
1189 if (!(qp->r_flags & QIB_R_RDMAR_SEQ)) { 1175 if (!(qp->r_flags & RVT_R_RDMAR_SEQ)) {
1190 qp->r_flags |= QIB_R_RDMAR_SEQ; 1176 qp->r_flags |= RVT_R_RDMAR_SEQ;
1191 qib_restart_rc(qp, qp->s_last_psn + 1, 0); 1177 qib_restart_rc(qp, qp->s_last_psn + 1, 0);
1192 if (list_empty(&qp->rspwait)) { 1178 if (list_empty(&qp->rspwait)) {
1193 qp->r_flags |= QIB_R_RSP_SEND; 1179 qp->r_flags |= RVT_R_RSP_SEND;
1194 atomic_inc(&qp->refcount); 1180 atomic_inc(&qp->refcount);
1195 list_add_tail(&qp->rspwait, 1181 list_add_tail(&qp->rspwait,
1196 &rcd->qp_wait_list); 1182 &rcd->qp_wait_list);
@@ -1213,14 +1199,14 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1213 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)) { 1199 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)) {
1214 qp->s_num_rd_atomic--; 1200 qp->s_num_rd_atomic--;
1215 /* Restart sending task if fence is complete */ 1201 /* Restart sending task if fence is complete */
1216 if ((qp->s_flags & QIB_S_WAIT_FENCE) && 1202 if ((qp->s_flags & RVT_S_WAIT_FENCE) &&
1217 !qp->s_num_rd_atomic) { 1203 !qp->s_num_rd_atomic) {
1218 qp->s_flags &= ~(QIB_S_WAIT_FENCE | 1204 qp->s_flags &= ~(RVT_S_WAIT_FENCE |
1219 QIB_S_WAIT_ACK); 1205 RVT_S_WAIT_ACK);
1220 qib_schedule_send(qp); 1206 qib_schedule_send(qp);
1221 } else if (qp->s_flags & QIB_S_WAIT_RDMAR) { 1207 } else if (qp->s_flags & RVT_S_WAIT_RDMAR) {
1222 qp->s_flags &= ~(QIB_S_WAIT_RDMAR | 1208 qp->s_flags &= ~(RVT_S_WAIT_RDMAR |
1223 QIB_S_WAIT_ACK); 1209 RVT_S_WAIT_ACK);
1224 qib_schedule_send(qp); 1210 qib_schedule_send(qp);
1225 } 1211 }
1226 } 1212 }
@@ -1231,7 +1217,7 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1231 1217
1232 switch (aeth >> 29) { 1218 switch (aeth >> 29) {
1233 case 0: /* ACK */ 1219 case 0: /* ACK */
1234 ibp->n_rc_acks++; 1220 this_cpu_inc(*ibp->rvp.rc_acks);
1235 if (qp->s_acked != qp->s_tail) { 1221 if (qp->s_acked != qp->s_tail) {
1236 /* 1222 /*
1237 * We are expecting more ACKs so 1223 * We are expecting more ACKs so
@@ -1248,8 +1234,8 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1248 qp->s_state = OP(SEND_LAST); 1234 qp->s_state = OP(SEND_LAST);
1249 qp->s_psn = psn + 1; 1235 qp->s_psn = psn + 1;
1250 } 1236 }
1251 if (qp->s_flags & QIB_S_WAIT_ACK) { 1237 if (qp->s_flags & RVT_S_WAIT_ACK) {
1252 qp->s_flags &= ~QIB_S_WAIT_ACK; 1238 qp->s_flags &= ~RVT_S_WAIT_ACK;
1253 qib_schedule_send(qp); 1239 qib_schedule_send(qp);
1254 } 1240 }
1255 qib_get_credit(qp, aeth); 1241 qib_get_credit(qp, aeth);
@@ -1260,10 +1246,10 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1260 goto bail; 1246 goto bail;
1261 1247
1262 case 1: /* RNR NAK */ 1248 case 1: /* RNR NAK */
1263 ibp->n_rnr_naks++; 1249 ibp->rvp.n_rnr_naks++;
1264 if (qp->s_acked == qp->s_tail) 1250 if (qp->s_acked == qp->s_tail)
1265 goto bail; 1251 goto bail;
1266 if (qp->s_flags & QIB_S_WAIT_RNR) 1252 if (qp->s_flags & RVT_S_WAIT_RNR)
1267 goto bail; 1253 goto bail;
1268 if (qp->s_rnr_retry == 0) { 1254 if (qp->s_rnr_retry == 0) {
1269 status = IB_WC_RNR_RETRY_EXC_ERR; 1255 status = IB_WC_RNR_RETRY_EXC_ERR;
@@ -1275,12 +1261,12 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1275 /* The last valid PSN is the previous PSN. */ 1261 /* The last valid PSN is the previous PSN. */
1276 update_last_psn(qp, psn - 1); 1262 update_last_psn(qp, psn - 1);
1277 1263
1278 ibp->n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK; 1264 ibp->rvp.n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK;
1279 1265
1280 reset_psn(qp, psn); 1266 reset_psn(qp, psn);
1281 1267
1282 qp->s_flags &= ~(QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_ACK); 1268 qp->s_flags &= ~(RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_ACK);
1283 qp->s_flags |= QIB_S_WAIT_RNR; 1269 qp->s_flags |= RVT_S_WAIT_RNR;
1284 qp->s_timer.function = qib_rc_rnr_retry; 1270 qp->s_timer.function = qib_rc_rnr_retry;
1285 qp->s_timer.expires = jiffies + usecs_to_jiffies( 1271 qp->s_timer.expires = jiffies + usecs_to_jiffies(
1286 ib_qib_rnr_table[(aeth >> QIB_AETH_CREDIT_SHIFT) & 1272 ib_qib_rnr_table[(aeth >> QIB_AETH_CREDIT_SHIFT) &
@@ -1296,7 +1282,7 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1296 switch ((aeth >> QIB_AETH_CREDIT_SHIFT) & 1282 switch ((aeth >> QIB_AETH_CREDIT_SHIFT) &
1297 QIB_AETH_CREDIT_MASK) { 1283 QIB_AETH_CREDIT_MASK) {
1298 case 0: /* PSN sequence error */ 1284 case 0: /* PSN sequence error */
1299 ibp->n_seq_naks++; 1285 ibp->rvp.n_seq_naks++;
1300 /* 1286 /*
1301 * Back up to the responder's expected PSN. 1287 * Back up to the responder's expected PSN.
1302 * Note that we might get a NAK in the middle of an 1288 * Note that we might get a NAK in the middle of an
@@ -1309,21 +1295,21 @@ static int do_rc_ack(struct qib_qp *qp, u32 aeth, u32 psn, int opcode,
1309 1295
1310 case 1: /* Invalid Request */ 1296 case 1: /* Invalid Request */
1311 status = IB_WC_REM_INV_REQ_ERR; 1297 status = IB_WC_REM_INV_REQ_ERR;
1312 ibp->n_other_naks++; 1298 ibp->rvp.n_other_naks++;
1313 goto class_b; 1299 goto class_b;
1314 1300
1315 case 2: /* Remote Access Error */ 1301 case 2: /* Remote Access Error */
1316 status = IB_WC_REM_ACCESS_ERR; 1302 status = IB_WC_REM_ACCESS_ERR;
1317 ibp->n_other_naks++; 1303 ibp->rvp.n_other_naks++;
1318 goto class_b; 1304 goto class_b;
1319 1305
1320 case 3: /* Remote Operation Error */ 1306 case 3: /* Remote Operation Error */
1321 status = IB_WC_REM_OP_ERR; 1307 status = IB_WC_REM_OP_ERR;
1322 ibp->n_other_naks++; 1308 ibp->rvp.n_other_naks++;
1323class_b: 1309class_b:
1324 if (qp->s_last == qp->s_acked) { 1310 if (qp->s_last == qp->s_acked) {
1325 qib_send_complete(qp, wqe, status); 1311 qib_send_complete(qp, wqe, status);
1326 qib_error_qp(qp, IB_WC_WR_FLUSH_ERR); 1312 rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
1327 } 1313 }
1328 break; 1314 break;
1329 1315
@@ -1349,18 +1335,18 @@ bail:
1349 * We have seen an out of sequence RDMA read middle or last packet. 1335 * We have seen an out of sequence RDMA read middle or last packet.
1350 * This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE. 1336 * This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE.
1351 */ 1337 */
1352static void rdma_seq_err(struct qib_qp *qp, struct qib_ibport *ibp, u32 psn, 1338static void rdma_seq_err(struct rvt_qp *qp, struct qib_ibport *ibp, u32 psn,
1353 struct qib_ctxtdata *rcd) 1339 struct qib_ctxtdata *rcd)
1354{ 1340{
1355 struct qib_swqe *wqe; 1341 struct rvt_swqe *wqe;
1356 1342
1357 /* Remove QP from retry timer */ 1343 /* Remove QP from retry timer */
1358 if (qp->s_flags & (QIB_S_TIMER | QIB_S_WAIT_RNR)) { 1344 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) {
1359 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_WAIT_RNR); 1345 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR);
1360 del_timer(&qp->s_timer); 1346 del_timer(&qp->s_timer);
1361 } 1347 }
1362 1348
1363 wqe = get_swqe_ptr(qp, qp->s_acked); 1349 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1364 1350
1365 while (qib_cmp24(psn, wqe->lpsn) > 0) { 1351 while (qib_cmp24(psn, wqe->lpsn) > 0) {
1366 if (wqe->wr.opcode == IB_WR_RDMA_READ || 1352 if (wqe->wr.opcode == IB_WR_RDMA_READ ||
@@ -1370,11 +1356,11 @@ static void rdma_seq_err(struct qib_qp *qp, struct qib_ibport *ibp, u32 psn,
1370 wqe = do_rc_completion(qp, wqe, ibp); 1356 wqe = do_rc_completion(qp, wqe, ibp);
1371 } 1357 }
1372 1358
1373 ibp->n_rdma_seq++; 1359 ibp->rvp.n_rdma_seq++;
1374 qp->r_flags |= QIB_R_RDMAR_SEQ; 1360 qp->r_flags |= RVT_R_RDMAR_SEQ;
1375 qib_restart_rc(qp, qp->s_last_psn + 1, 0); 1361 qib_restart_rc(qp, qp->s_last_psn + 1, 0);
1376 if (list_empty(&qp->rspwait)) { 1362 if (list_empty(&qp->rspwait)) {
1377 qp->r_flags |= QIB_R_RSP_SEND; 1363 qp->r_flags |= RVT_R_RSP_SEND;
1378 atomic_inc(&qp->refcount); 1364 atomic_inc(&qp->refcount);
1379 list_add_tail(&qp->rspwait, &rcd->qp_wait_list); 1365 list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
1380 } 1366 }
@@ -1399,12 +1385,12 @@ static void rdma_seq_err(struct qib_qp *qp, struct qib_ibport *ibp, u32 psn,
1399static void qib_rc_rcv_resp(struct qib_ibport *ibp, 1385static void qib_rc_rcv_resp(struct qib_ibport *ibp,
1400 struct qib_other_headers *ohdr, 1386 struct qib_other_headers *ohdr,
1401 void *data, u32 tlen, 1387 void *data, u32 tlen,
1402 struct qib_qp *qp, 1388 struct rvt_qp *qp,
1403 u32 opcode, 1389 u32 opcode,
1404 u32 psn, u32 hdrsize, u32 pmtu, 1390 u32 psn, u32 hdrsize, u32 pmtu,
1405 struct qib_ctxtdata *rcd) 1391 struct qib_ctxtdata *rcd)
1406{ 1392{
1407 struct qib_swqe *wqe; 1393 struct rvt_swqe *wqe;
1408 struct qib_pportdata *ppd = ppd_from_ibp(ibp); 1394 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1409 enum ib_wc_status status; 1395 enum ib_wc_status status;
1410 unsigned long flags; 1396 unsigned long flags;
@@ -1425,7 +1411,7 @@ static void qib_rc_rcv_resp(struct qib_ibport *ibp,
1425 * If send tasklet not running attempt to progress 1411 * If send tasklet not running attempt to progress
1426 * SDMA queue. 1412 * SDMA queue.
1427 */ 1413 */
1428 if (!(qp->s_flags & QIB_S_BUSY)) { 1414 if (!(qp->s_flags & RVT_S_BUSY)) {
1429 /* Acquire SDMA Lock */ 1415 /* Acquire SDMA Lock */
1430 spin_lock_irqsave(&ppd->sdma_lock, flags); 1416 spin_lock_irqsave(&ppd->sdma_lock, flags);
1431 /* Invoke sdma make progress */ 1417 /* Invoke sdma make progress */
@@ -1437,11 +1423,12 @@ static void qib_rc_rcv_resp(struct qib_ibport *ibp,
1437 } 1423 }
1438 1424
1439 spin_lock_irqsave(&qp->s_lock, flags); 1425 spin_lock_irqsave(&qp->s_lock, flags);
1440 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) 1426 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
1441 goto ack_done; 1427 goto ack_done;
1442 1428
1443 /* Ignore invalid responses. */ 1429 /* Ignore invalid responses. */
1444 if (qib_cmp24(psn, qp->s_next_psn) >= 0) 1430 smp_read_barrier_depends(); /* see post_one_send */
1431 if (qib_cmp24(psn, ACCESS_ONCE(qp->s_next_psn)) >= 0)
1445 goto ack_done; 1432 goto ack_done;
1446 1433
1447 /* Ignore duplicate responses. */ 1434 /* Ignore duplicate responses. */
@@ -1460,15 +1447,15 @@ static void qib_rc_rcv_resp(struct qib_ibport *ibp,
1460 * Skip everything other than the PSN we expect, if we are waiting 1447 * Skip everything other than the PSN we expect, if we are waiting
1461 * for a reply to a restarted RDMA read or atomic op. 1448 * for a reply to a restarted RDMA read or atomic op.
1462 */ 1449 */
1463 if (qp->r_flags & QIB_R_RDMAR_SEQ) { 1450 if (qp->r_flags & RVT_R_RDMAR_SEQ) {
1464 if (qib_cmp24(psn, qp->s_last_psn + 1) != 0) 1451 if (qib_cmp24(psn, qp->s_last_psn + 1) != 0)
1465 goto ack_done; 1452 goto ack_done;
1466 qp->r_flags &= ~QIB_R_RDMAR_SEQ; 1453 qp->r_flags &= ~RVT_R_RDMAR_SEQ;
1467 } 1454 }
1468 1455
1469 if (unlikely(qp->s_acked == qp->s_tail)) 1456 if (unlikely(qp->s_acked == qp->s_tail))
1470 goto ack_done; 1457 goto ack_done;
1471 wqe = get_swqe_ptr(qp, qp->s_acked); 1458 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1472 status = IB_WC_SUCCESS; 1459 status = IB_WC_SUCCESS;
1473 1460
1474 switch (opcode) { 1461 switch (opcode) {
@@ -1487,7 +1474,7 @@ static void qib_rc_rcv_resp(struct qib_ibport *ibp,
1487 opcode != OP(RDMA_READ_RESPONSE_FIRST)) 1474 opcode != OP(RDMA_READ_RESPONSE_FIRST))
1488 goto ack_done; 1475 goto ack_done;
1489 hdrsize += 4; 1476 hdrsize += 4;
1490 wqe = get_swqe_ptr(qp, qp->s_acked); 1477 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1491 if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ)) 1478 if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
1492 goto ack_op_err; 1479 goto ack_op_err;
1493 /* 1480 /*
@@ -1515,10 +1502,10 @@ read_middle:
1515 * We got a response so update the timeout. 1502 * We got a response so update the timeout.
1516 * 4.096 usec. * (1 << qp->timeout) 1503 * 4.096 usec. * (1 << qp->timeout)
1517 */ 1504 */
1518 qp->s_flags |= QIB_S_TIMER; 1505 qp->s_flags |= RVT_S_TIMER;
1519 mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies); 1506 mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies);
1520 if (qp->s_flags & QIB_S_WAIT_ACK) { 1507 if (qp->s_flags & RVT_S_WAIT_ACK) {
1521 qp->s_flags &= ~QIB_S_WAIT_ACK; 1508 qp->s_flags &= ~RVT_S_WAIT_ACK;
1522 qib_schedule_send(qp); 1509 qib_schedule_send(qp);
1523 } 1510 }
1524 1511
@@ -1553,7 +1540,7 @@ read_middle:
1553 * have to be careful to copy the data to the right 1540 * have to be careful to copy the data to the right
1554 * location. 1541 * location.
1555 */ 1542 */
1556 wqe = get_swqe_ptr(qp, qp->s_acked); 1543 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1557 qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge, 1544 qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge,
1558 wqe, psn, pmtu); 1545 wqe, psn, pmtu);
1559 goto read_last; 1546 goto read_last;
@@ -1598,7 +1585,7 @@ ack_len_err:
1598ack_err: 1585ack_err:
1599 if (qp->s_last == qp->s_acked) { 1586 if (qp->s_last == qp->s_acked) {
1600 qib_send_complete(qp, wqe, status); 1587 qib_send_complete(qp, wqe, status);
1601 qib_error_qp(qp, IB_WC_WR_FLUSH_ERR); 1588 rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
1602 } 1589 }
1603ack_done: 1590ack_done:
1604 spin_unlock_irqrestore(&qp->s_lock, flags); 1591 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -1623,14 +1610,14 @@ bail:
1623 */ 1610 */
1624static int qib_rc_rcv_error(struct qib_other_headers *ohdr, 1611static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1625 void *data, 1612 void *data,
1626 struct qib_qp *qp, 1613 struct rvt_qp *qp,
1627 u32 opcode, 1614 u32 opcode,
1628 u32 psn, 1615 u32 psn,
1629 int diff, 1616 int diff,
1630 struct qib_ctxtdata *rcd) 1617 struct qib_ctxtdata *rcd)
1631{ 1618{
1632 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 1619 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
1633 struct qib_ack_entry *e; 1620 struct rvt_ack_entry *e;
1634 unsigned long flags; 1621 unsigned long flags;
1635 u8 i, prev; 1622 u8 i, prev;
1636 int old_req; 1623 int old_req;
@@ -1642,7 +1629,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1642 * Don't queue the NAK if we already sent one. 1629 * Don't queue the NAK if we already sent one.
1643 */ 1630 */
1644 if (!qp->r_nak_state) { 1631 if (!qp->r_nak_state) {
1645 ibp->n_rc_seqnak++; 1632 ibp->rvp.n_rc_seqnak++;
1646 qp->r_nak_state = IB_NAK_PSN_ERROR; 1633 qp->r_nak_state = IB_NAK_PSN_ERROR;
1647 /* Use the expected PSN. */ 1634 /* Use the expected PSN. */
1648 qp->r_ack_psn = qp->r_psn; 1635 qp->r_ack_psn = qp->r_psn;
@@ -1652,7 +1639,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1652 * Otherwise, we end up propagating congestion. 1639 * Otherwise, we end up propagating congestion.
1653 */ 1640 */
1654 if (list_empty(&qp->rspwait)) { 1641 if (list_empty(&qp->rspwait)) {
1655 qp->r_flags |= QIB_R_RSP_NAK; 1642 qp->r_flags |= RVT_R_RSP_NAK;
1656 atomic_inc(&qp->refcount); 1643 atomic_inc(&qp->refcount);
1657 list_add_tail(&qp->rspwait, &rcd->qp_wait_list); 1644 list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
1658 } 1645 }
@@ -1678,7 +1665,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1678 */ 1665 */
1679 e = NULL; 1666 e = NULL;
1680 old_req = 1; 1667 old_req = 1;
1681 ibp->n_rc_dupreq++; 1668 ibp->rvp.n_rc_dupreq++;
1682 1669
1683 spin_lock_irqsave(&qp->s_lock, flags); 1670 spin_lock_irqsave(&qp->s_lock, flags);
1684 1671
@@ -1732,7 +1719,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1732 if (unlikely(offset + len != e->rdma_sge.sge_length)) 1719 if (unlikely(offset + len != e->rdma_sge.sge_length))
1733 goto unlock_done; 1720 goto unlock_done;
1734 if (e->rdma_sge.mr) { 1721 if (e->rdma_sge.mr) {
1735 qib_put_mr(e->rdma_sge.mr); 1722 rvt_put_mr(e->rdma_sge.mr);
1736 e->rdma_sge.mr = NULL; 1723 e->rdma_sge.mr = NULL;
1737 } 1724 }
1738 if (len != 0) { 1725 if (len != 0) {
@@ -1740,7 +1727,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1740 u64 vaddr = be64_to_cpu(reth->vaddr); 1727 u64 vaddr = be64_to_cpu(reth->vaddr);
1741 int ok; 1728 int ok;
1742 1729
1743 ok = qib_rkey_ok(qp, &e->rdma_sge, len, vaddr, rkey, 1730 ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr, rkey,
1744 IB_ACCESS_REMOTE_READ); 1731 IB_ACCESS_REMOTE_READ);
1745 if (unlikely(!ok)) 1732 if (unlikely(!ok))
1746 goto unlock_done; 1733 goto unlock_done;
@@ -1791,7 +1778,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1791 * which doesn't accept a RDMA read response or atomic 1778 * which doesn't accept a RDMA read response or atomic
1792 * response as an ACK for earlier SENDs or RDMA writes. 1779 * response as an ACK for earlier SENDs or RDMA writes.
1793 */ 1780 */
1794 if (!(qp->s_flags & QIB_S_RESP_PENDING)) { 1781 if (!(qp->s_flags & RVT_S_RESP_PENDING)) {
1795 spin_unlock_irqrestore(&qp->s_lock, flags); 1782 spin_unlock_irqrestore(&qp->s_lock, flags);
1796 qp->r_nak_state = 0; 1783 qp->r_nak_state = 0;
1797 qp->r_ack_psn = qp->s_ack_queue[i].psn - 1; 1784 qp->r_ack_psn = qp->s_ack_queue[i].psn - 1;
@@ -1805,7 +1792,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
1805 break; 1792 break;
1806 } 1793 }
1807 qp->s_ack_state = OP(ACKNOWLEDGE); 1794 qp->s_ack_state = OP(ACKNOWLEDGE);
1808 qp->s_flags |= QIB_S_RESP_PENDING; 1795 qp->s_flags |= RVT_S_RESP_PENDING;
1809 qp->r_nak_state = 0; 1796 qp->r_nak_state = 0;
1810 qib_schedule_send(qp); 1797 qib_schedule_send(qp);
1811 1798
@@ -1818,13 +1805,13 @@ send_ack:
1818 return 0; 1805 return 0;
1819} 1806}
1820 1807
1821void qib_rc_error(struct qib_qp *qp, enum ib_wc_status err) 1808void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err)
1822{ 1809{
1823 unsigned long flags; 1810 unsigned long flags;
1824 int lastwqe; 1811 int lastwqe;
1825 1812
1826 spin_lock_irqsave(&qp->s_lock, flags); 1813 spin_lock_irqsave(&qp->s_lock, flags);
1827 lastwqe = qib_error_qp(qp, err); 1814 lastwqe = rvt_error_qp(qp, err);
1828 spin_unlock_irqrestore(&qp->s_lock, flags); 1815 spin_unlock_irqrestore(&qp->s_lock, flags);
1829 1816
1830 if (lastwqe) { 1817 if (lastwqe) {
@@ -1837,7 +1824,7 @@ void qib_rc_error(struct qib_qp *qp, enum ib_wc_status err)
1837 } 1824 }
1838} 1825}
1839 1826
1840static inline void qib_update_ack_queue(struct qib_qp *qp, unsigned n) 1827static inline void qib_update_ack_queue(struct rvt_qp *qp, unsigned n)
1841{ 1828{
1842 unsigned next; 1829 unsigned next;
1843 1830
@@ -1862,7 +1849,7 @@ static inline void qib_update_ack_queue(struct qib_qp *qp, unsigned n)
1862 * Called at interrupt level. 1849 * Called at interrupt level.
1863 */ 1850 */
1864void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr, 1851void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
1865 int has_grh, void *data, u32 tlen, struct qib_qp *qp) 1852 int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
1866{ 1853{
1867 struct qib_ibport *ibp = &rcd->ppd->ibport_data; 1854 struct qib_ibport *ibp = &rcd->ppd->ibport_data;
1868 struct qib_other_headers *ohdr; 1855 struct qib_other_headers *ohdr;
@@ -1948,8 +1935,8 @@ void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
1948 break; 1935 break;
1949 } 1936 }
1950 1937
1951 if (qp->state == IB_QPS_RTR && !(qp->r_flags & QIB_R_COMM_EST)) { 1938 if (qp->state == IB_QPS_RTR && !(qp->r_flags & RVT_R_COMM_EST)) {
1952 qp->r_flags |= QIB_R_COMM_EST; 1939 qp->r_flags |= RVT_R_COMM_EST;
1953 if (qp->ibqp.event_handler) { 1940 if (qp->ibqp.event_handler) {
1954 struct ib_event ev; 1941 struct ib_event ev;
1955 1942
@@ -2026,9 +2013,9 @@ send_last:
2026 if (unlikely(wc.byte_len > qp->r_len)) 2013 if (unlikely(wc.byte_len > qp->r_len))
2027 goto nack_inv; 2014 goto nack_inv;
2028 qib_copy_sge(&qp->r_sge, data, tlen, 1); 2015 qib_copy_sge(&qp->r_sge, data, tlen, 1);
2029 qib_put_ss(&qp->r_sge); 2016 rvt_put_ss(&qp->r_sge);
2030 qp->r_msn++; 2017 qp->r_msn++;
2031 if (!test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) 2018 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
2032 break; 2019 break;
2033 wc.wr_id = qp->r_wr_id; 2020 wc.wr_id = qp->r_wr_id;
2034 wc.status = IB_WC_SUCCESS; 2021 wc.status = IB_WC_SUCCESS;
@@ -2047,7 +2034,7 @@ send_last:
2047 wc.dlid_path_bits = 0; 2034 wc.dlid_path_bits = 0;
2048 wc.port_num = 0; 2035 wc.port_num = 0;
2049 /* Signal completion event if the solicited bit is set. */ 2036 /* Signal completion event if the solicited bit is set. */
2050 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 2037 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
2051 (ohdr->bth[0] & 2038 (ohdr->bth[0] &
2052 cpu_to_be32(IB_BTH_SOLICITED)) != 0); 2039 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
2053 break; 2040 break;
@@ -2069,7 +2056,7 @@ send_last:
2069 int ok; 2056 int ok;
2070 2057
2071 /* Check rkey & NAK */ 2058 /* Check rkey & NAK */
2072 ok = qib_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, vaddr, 2059 ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, vaddr,
2073 rkey, IB_ACCESS_REMOTE_WRITE); 2060 rkey, IB_ACCESS_REMOTE_WRITE);
2074 if (unlikely(!ok)) 2061 if (unlikely(!ok))
2075 goto nack_acc; 2062 goto nack_acc;
@@ -2096,7 +2083,7 @@ send_last:
2096 goto send_last; 2083 goto send_last;
2097 2084
2098 case OP(RDMA_READ_REQUEST): { 2085 case OP(RDMA_READ_REQUEST): {
2099 struct qib_ack_entry *e; 2086 struct rvt_ack_entry *e;
2100 u32 len; 2087 u32 len;
2101 u8 next; 2088 u8 next;
2102 2089
@@ -2114,7 +2101,7 @@ send_last:
2114 } 2101 }
2115 e = &qp->s_ack_queue[qp->r_head_ack_queue]; 2102 e = &qp->s_ack_queue[qp->r_head_ack_queue];
2116 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) { 2103 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
2117 qib_put_mr(e->rdma_sge.mr); 2104 rvt_put_mr(e->rdma_sge.mr);
2118 e->rdma_sge.mr = NULL; 2105 e->rdma_sge.mr = NULL;
2119 } 2106 }
2120 reth = &ohdr->u.rc.reth; 2107 reth = &ohdr->u.rc.reth;
@@ -2125,7 +2112,7 @@ send_last:
2125 int ok; 2112 int ok;
2126 2113
2127 /* Check rkey & NAK */ 2114 /* Check rkey & NAK */
2128 ok = qib_rkey_ok(qp, &e->rdma_sge, len, vaddr, 2115 ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr,
2129 rkey, IB_ACCESS_REMOTE_READ); 2116 rkey, IB_ACCESS_REMOTE_READ);
2130 if (unlikely(!ok)) 2117 if (unlikely(!ok))
2131 goto nack_acc_unlck; 2118 goto nack_acc_unlck;
@@ -2157,7 +2144,7 @@ send_last:
2157 qp->r_head_ack_queue = next; 2144 qp->r_head_ack_queue = next;
2158 2145
2159 /* Schedule the send tasklet. */ 2146 /* Schedule the send tasklet. */
2160 qp->s_flags |= QIB_S_RESP_PENDING; 2147 qp->s_flags |= RVT_S_RESP_PENDING;
2161 qib_schedule_send(qp); 2148 qib_schedule_send(qp);
2162 2149
2163 goto sunlock; 2150 goto sunlock;
@@ -2166,7 +2153,7 @@ send_last:
2166 case OP(COMPARE_SWAP): 2153 case OP(COMPARE_SWAP):
2167 case OP(FETCH_ADD): { 2154 case OP(FETCH_ADD): {
2168 struct ib_atomic_eth *ateth; 2155 struct ib_atomic_eth *ateth;
2169 struct qib_ack_entry *e; 2156 struct rvt_ack_entry *e;
2170 u64 vaddr; 2157 u64 vaddr;
2171 atomic64_t *maddr; 2158 atomic64_t *maddr;
2172 u64 sdata; 2159 u64 sdata;
@@ -2186,7 +2173,7 @@ send_last:
2186 } 2173 }
2187 e = &qp->s_ack_queue[qp->r_head_ack_queue]; 2174 e = &qp->s_ack_queue[qp->r_head_ack_queue];
2188 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) { 2175 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
2189 qib_put_mr(e->rdma_sge.mr); 2176 rvt_put_mr(e->rdma_sge.mr);
2190 e->rdma_sge.mr = NULL; 2177 e->rdma_sge.mr = NULL;
2191 } 2178 }
2192 ateth = &ohdr->u.atomic_eth; 2179 ateth = &ohdr->u.atomic_eth;
@@ -2196,7 +2183,7 @@ send_last:
2196 goto nack_inv_unlck; 2183 goto nack_inv_unlck;
2197 rkey = be32_to_cpu(ateth->rkey); 2184 rkey = be32_to_cpu(ateth->rkey);
2198 /* Check rkey & NAK */ 2185 /* Check rkey & NAK */
2199 if (unlikely(!qib_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), 2186 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
2200 vaddr, rkey, 2187 vaddr, rkey,
2201 IB_ACCESS_REMOTE_ATOMIC))) 2188 IB_ACCESS_REMOTE_ATOMIC)))
2202 goto nack_acc_unlck; 2189 goto nack_acc_unlck;
@@ -2208,7 +2195,7 @@ send_last:
2208 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr, 2195 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
2209 be64_to_cpu(ateth->compare_data), 2196 be64_to_cpu(ateth->compare_data),
2210 sdata); 2197 sdata);
2211 qib_put_mr(qp->r_sge.sge.mr); 2198 rvt_put_mr(qp->r_sge.sge.mr);
2212 qp->r_sge.num_sge = 0; 2199 qp->r_sge.num_sge = 0;
2213 e->opcode = opcode; 2200 e->opcode = opcode;
2214 e->sent = 0; 2201 e->sent = 0;
@@ -2221,7 +2208,7 @@ send_last:
2221 qp->r_head_ack_queue = next; 2208 qp->r_head_ack_queue = next;
2222 2209
2223 /* Schedule the send tasklet. */ 2210 /* Schedule the send tasklet. */
2224 qp->s_flags |= QIB_S_RESP_PENDING; 2211 qp->s_flags |= RVT_S_RESP_PENDING;
2225 qib_schedule_send(qp); 2212 qib_schedule_send(qp);
2226 2213
2227 goto sunlock; 2214 goto sunlock;
@@ -2245,7 +2232,7 @@ rnr_nak:
2245 qp->r_ack_psn = qp->r_psn; 2232 qp->r_ack_psn = qp->r_psn;
2246 /* Queue RNR NAK for later */ 2233 /* Queue RNR NAK for later */
2247 if (list_empty(&qp->rspwait)) { 2234 if (list_empty(&qp->rspwait)) {
2248 qp->r_flags |= QIB_R_RSP_NAK; 2235 qp->r_flags |= RVT_R_RSP_NAK;
2249 atomic_inc(&qp->refcount); 2236 atomic_inc(&qp->refcount);
2250 list_add_tail(&qp->rspwait, &rcd->qp_wait_list); 2237 list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
2251 } 2238 }
@@ -2257,7 +2244,7 @@ nack_op_err:
2257 qp->r_ack_psn = qp->r_psn; 2244 qp->r_ack_psn = qp->r_psn;
2258 /* Queue NAK for later */ 2245 /* Queue NAK for later */
2259 if (list_empty(&qp->rspwait)) { 2246 if (list_empty(&qp->rspwait)) {
2260 qp->r_flags |= QIB_R_RSP_NAK; 2247 qp->r_flags |= RVT_R_RSP_NAK;
2261 atomic_inc(&qp->refcount); 2248 atomic_inc(&qp->refcount);
2262 list_add_tail(&qp->rspwait, &rcd->qp_wait_list); 2249 list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
2263 } 2250 }
@@ -2271,7 +2258,7 @@ nack_inv:
2271 qp->r_ack_psn = qp->r_psn; 2258 qp->r_ack_psn = qp->r_psn;
2272 /* Queue NAK for later */ 2259 /* Queue NAK for later */
2273 if (list_empty(&qp->rspwait)) { 2260 if (list_empty(&qp->rspwait)) {
2274 qp->r_flags |= QIB_R_RSP_NAK; 2261 qp->r_flags |= RVT_R_RSP_NAK;
2275 atomic_inc(&qp->refcount); 2262 atomic_inc(&qp->refcount);
2276 list_add_tail(&qp->rspwait, &rcd->qp_wait_list); 2263 list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
2277 } 2264 }
diff --git a/drivers/infiniband/hw/qib/qib_ruc.c b/drivers/infiniband/hw/qib/qib_ruc.c
index b1aa21bdd484..a5f07a64b228 100644
--- a/drivers/infiniband/hw/qib/qib_ruc.c
+++ b/drivers/infiniband/hw/qib/qib_ruc.c
@@ -79,16 +79,16 @@ const u32 ib_qib_rnr_table[32] = {
79 * Validate a RWQE and fill in the SGE state. 79 * Validate a RWQE and fill in the SGE state.
80 * Return 1 if OK. 80 * Return 1 if OK.
81 */ 81 */
82static int qib_init_sge(struct qib_qp *qp, struct qib_rwqe *wqe) 82static int qib_init_sge(struct rvt_qp *qp, struct rvt_rwqe *wqe)
83{ 83{
84 int i, j, ret; 84 int i, j, ret;
85 struct ib_wc wc; 85 struct ib_wc wc;
86 struct qib_lkey_table *rkt; 86 struct rvt_lkey_table *rkt;
87 struct qib_pd *pd; 87 struct rvt_pd *pd;
88 struct qib_sge_state *ss; 88 struct rvt_sge_state *ss;
89 89
90 rkt = &to_idev(qp->ibqp.device)->lk_table; 90 rkt = &to_idev(qp->ibqp.device)->rdi.lkey_table;
91 pd = to_ipd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd); 91 pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd);
92 ss = &qp->r_sge; 92 ss = &qp->r_sge;
93 ss->sg_list = qp->r_sg_list; 93 ss->sg_list = qp->r_sg_list;
94 qp->r_len = 0; 94 qp->r_len = 0;
@@ -96,7 +96,7 @@ static int qib_init_sge(struct qib_qp *qp, struct qib_rwqe *wqe)
96 if (wqe->sg_list[i].length == 0) 96 if (wqe->sg_list[i].length == 0)
97 continue; 97 continue;
98 /* Check LKEY */ 98 /* Check LKEY */
99 if (!qib_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge, 99 if (!rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge,
100 &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE)) 100 &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE))
101 goto bad_lkey; 101 goto bad_lkey;
102 qp->r_len += wqe->sg_list[i].length; 102 qp->r_len += wqe->sg_list[i].length;
@@ -109,9 +109,9 @@ static int qib_init_sge(struct qib_qp *qp, struct qib_rwqe *wqe)
109 109
110bad_lkey: 110bad_lkey:
111 while (j) { 111 while (j) {
112 struct qib_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge; 112 struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge;
113 113
114 qib_put_mr(sge->mr); 114 rvt_put_mr(sge->mr);
115 } 115 }
116 ss->num_sge = 0; 116 ss->num_sge = 0;
117 memset(&wc, 0, sizeof(wc)); 117 memset(&wc, 0, sizeof(wc));
@@ -120,7 +120,7 @@ bad_lkey:
120 wc.opcode = IB_WC_RECV; 120 wc.opcode = IB_WC_RECV;
121 wc.qp = &qp->ibqp; 121 wc.qp = &qp->ibqp;
122 /* Signal solicited completion event. */ 122 /* Signal solicited completion event. */
123 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1); 123 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
124 ret = 0; 124 ret = 0;
125bail: 125bail:
126 return ret; 126 return ret;
@@ -136,19 +136,19 @@ bail:
136 * 136 *
137 * Can be called from interrupt level. 137 * Can be called from interrupt level.
138 */ 138 */
139int qib_get_rwqe(struct qib_qp *qp, int wr_id_only) 139int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only)
140{ 140{
141 unsigned long flags; 141 unsigned long flags;
142 struct qib_rq *rq; 142 struct rvt_rq *rq;
143 struct qib_rwq *wq; 143 struct rvt_rwq *wq;
144 struct qib_srq *srq; 144 struct rvt_srq *srq;
145 struct qib_rwqe *wqe; 145 struct rvt_rwqe *wqe;
146 void (*handler)(struct ib_event *, void *); 146 void (*handler)(struct ib_event *, void *);
147 u32 tail; 147 u32 tail;
148 int ret; 148 int ret;
149 149
150 if (qp->ibqp.srq) { 150 if (qp->ibqp.srq) {
151 srq = to_isrq(qp->ibqp.srq); 151 srq = ibsrq_to_rvtsrq(qp->ibqp.srq);
152 handler = srq->ibsrq.event_handler; 152 handler = srq->ibsrq.event_handler;
153 rq = &srq->rq; 153 rq = &srq->rq;
154 } else { 154 } else {
@@ -158,7 +158,7 @@ int qib_get_rwqe(struct qib_qp *qp, int wr_id_only)
158 } 158 }
159 159
160 spin_lock_irqsave(&rq->lock, flags); 160 spin_lock_irqsave(&rq->lock, flags);
161 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) { 161 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
162 ret = 0; 162 ret = 0;
163 goto unlock; 163 goto unlock;
164 } 164 }
@@ -174,7 +174,7 @@ int qib_get_rwqe(struct qib_qp *qp, int wr_id_only)
174 } 174 }
175 /* Make sure entry is read after head index is read. */ 175 /* Make sure entry is read after head index is read. */
176 smp_rmb(); 176 smp_rmb();
177 wqe = get_rwqe_ptr(rq, tail); 177 wqe = rvt_get_rwqe_ptr(rq, tail);
178 /* 178 /*
179 * Even though we update the tail index in memory, the verbs 179 * Even though we update the tail index in memory, the verbs
180 * consumer is not supposed to post more entries until a 180 * consumer is not supposed to post more entries until a
@@ -190,7 +190,7 @@ int qib_get_rwqe(struct qib_qp *qp, int wr_id_only)
190 qp->r_wr_id = wqe->wr_id; 190 qp->r_wr_id = wqe->wr_id;
191 191
192 ret = 1; 192 ret = 1;
193 set_bit(QIB_R_WRID_VALID, &qp->r_aflags); 193 set_bit(RVT_R_WRID_VALID, &qp->r_aflags);
194 if (handler) { 194 if (handler) {
195 u32 n; 195 u32 n;
196 196
@@ -227,7 +227,7 @@ bail:
227 * Switch to alternate path. 227 * Switch to alternate path.
228 * The QP s_lock should be held and interrupts disabled. 228 * The QP s_lock should be held and interrupts disabled.
229 */ 229 */
230void qib_migrate_qp(struct qib_qp *qp) 230void qib_migrate_qp(struct rvt_qp *qp)
231{ 231{
232 struct ib_event ev; 232 struct ib_event ev;
233 233
@@ -266,7 +266,7 @@ static int gid_ok(union ib_gid *gid, __be64 gid_prefix, __be64 id)
266 * The s_lock will be acquired around the qib_migrate_qp() call. 266 * The s_lock will be acquired around the qib_migrate_qp() call.
267 */ 267 */
268int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr, 268int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
269 int has_grh, struct qib_qp *qp, u32 bth0) 269 int has_grh, struct rvt_qp *qp, u32 bth0)
270{ 270{
271 __be64 guid; 271 __be64 guid;
272 unsigned long flags; 272 unsigned long flags;
@@ -279,7 +279,8 @@ int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
279 if (!(qp->alt_ah_attr.ah_flags & IB_AH_GRH)) 279 if (!(qp->alt_ah_attr.ah_flags & IB_AH_GRH))
280 goto err; 280 goto err;
281 guid = get_sguid(ibp, qp->alt_ah_attr.grh.sgid_index); 281 guid = get_sguid(ibp, qp->alt_ah_attr.grh.sgid_index);
282 if (!gid_ok(&hdr->u.l.grh.dgid, ibp->gid_prefix, guid)) 282 if (!gid_ok(&hdr->u.l.grh.dgid,
283 ibp->rvp.gid_prefix, guid))
283 goto err; 284 goto err;
284 if (!gid_ok(&hdr->u.l.grh.sgid, 285 if (!gid_ok(&hdr->u.l.grh.sgid,
285 qp->alt_ah_attr.grh.dgid.global.subnet_prefix, 286 qp->alt_ah_attr.grh.dgid.global.subnet_prefix,
@@ -311,7 +312,8 @@ int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
311 goto err; 312 goto err;
312 guid = get_sguid(ibp, 313 guid = get_sguid(ibp,
313 qp->remote_ah_attr.grh.sgid_index); 314 qp->remote_ah_attr.grh.sgid_index);
314 if (!gid_ok(&hdr->u.l.grh.dgid, ibp->gid_prefix, guid)) 315 if (!gid_ok(&hdr->u.l.grh.dgid,
316 ibp->rvp.gid_prefix, guid))
315 goto err; 317 goto err;
316 if (!gid_ok(&hdr->u.l.grh.sgid, 318 if (!gid_ok(&hdr->u.l.grh.sgid,
317 qp->remote_ah_attr.grh.dgid.global.subnet_prefix, 319 qp->remote_ah_attr.grh.dgid.global.subnet_prefix,
@@ -353,12 +355,15 @@ err:
353 * receive interrupts since this is a connected protocol and all packets 355 * receive interrupts since this is a connected protocol and all packets
354 * will pass through here. 356 * will pass through here.
355 */ 357 */
356static void qib_ruc_loopback(struct qib_qp *sqp) 358static void qib_ruc_loopback(struct rvt_qp *sqp)
357{ 359{
358 struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num); 360 struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
359 struct qib_qp *qp; 361 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
360 struct qib_swqe *wqe; 362 struct qib_devdata *dd = ppd->dd;
361 struct qib_sge *sge; 363 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
364 struct rvt_qp *qp;
365 struct rvt_swqe *wqe;
366 struct rvt_sge *sge;
362 unsigned long flags; 367 unsigned long flags;
363 struct ib_wc wc; 368 struct ib_wc wc;
364 u64 sdata; 369 u64 sdata;
@@ -367,29 +372,33 @@ static void qib_ruc_loopback(struct qib_qp *sqp)
367 int release; 372 int release;
368 int ret; 373 int ret;
369 374
375 rcu_read_lock();
370 /* 376 /*
371 * Note that we check the responder QP state after 377 * Note that we check the responder QP state after
372 * checking the requester's state. 378 * checking the requester's state.
373 */ 379 */
374 qp = qib_lookup_qpn(ibp, sqp->remote_qpn); 380 qp = rvt_lookup_qpn(rdi, &ibp->rvp, sqp->remote_qpn);
381 if (!qp)
382 goto done;
375 383
376 spin_lock_irqsave(&sqp->s_lock, flags); 384 spin_lock_irqsave(&sqp->s_lock, flags);
377 385
378 /* Return if we are already busy processing a work request. */ 386 /* Return if we are already busy processing a work request. */
379 if ((sqp->s_flags & (QIB_S_BUSY | QIB_S_ANY_WAIT)) || 387 if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) ||
380 !(ib_qib_state_ops[sqp->state] & QIB_PROCESS_OR_FLUSH_SEND)) 388 !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND))
381 goto unlock; 389 goto unlock;
382 390
383 sqp->s_flags |= QIB_S_BUSY; 391 sqp->s_flags |= RVT_S_BUSY;
384 392
385again: 393again:
386 if (sqp->s_last == sqp->s_head) 394 smp_read_barrier_depends(); /* see post_one_send() */
395 if (sqp->s_last == ACCESS_ONCE(sqp->s_head))
387 goto clr_busy; 396 goto clr_busy;
388 wqe = get_swqe_ptr(sqp, sqp->s_last); 397 wqe = rvt_get_swqe_ptr(sqp, sqp->s_last);
389 398
390 /* Return if it is not OK to start a new work reqeust. */ 399 /* Return if it is not OK to start a new work reqeust. */
391 if (!(ib_qib_state_ops[sqp->state] & QIB_PROCESS_NEXT_SEND_OK)) { 400 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
392 if (!(ib_qib_state_ops[sqp->state] & QIB_FLUSH_SEND)) 401 if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND))
393 goto clr_busy; 402 goto clr_busy;
394 /* We are in the error state, flush the work request. */ 403 /* We are in the error state, flush the work request. */
395 send_status = IB_WC_WR_FLUSH_ERR; 404 send_status = IB_WC_WR_FLUSH_ERR;
@@ -407,9 +416,9 @@ again:
407 } 416 }
408 spin_unlock_irqrestore(&sqp->s_lock, flags); 417 spin_unlock_irqrestore(&sqp->s_lock, flags);
409 418
410 if (!qp || !(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) || 419 if (!qp || !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) ||
411 qp->ibqp.qp_type != sqp->ibqp.qp_type) { 420 qp->ibqp.qp_type != sqp->ibqp.qp_type) {
412 ibp->n_pkt_drops++; 421 ibp->rvp.n_pkt_drops++;
413 /* 422 /*
414 * For RC, the requester would timeout and retry so 423 * For RC, the requester would timeout and retry so
415 * shortcut the timeouts and just signal too many retries. 424 * shortcut the timeouts and just signal too many retries.
@@ -458,7 +467,7 @@ again:
458 goto inv_err; 467 goto inv_err;
459 if (wqe->length == 0) 468 if (wqe->length == 0)
460 break; 469 break;
461 if (unlikely(!qib_rkey_ok(qp, &qp->r_sge.sge, wqe->length, 470 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length,
462 wqe->rdma_wr.remote_addr, 471 wqe->rdma_wr.remote_addr,
463 wqe->rdma_wr.rkey, 472 wqe->rdma_wr.rkey,
464 IB_ACCESS_REMOTE_WRITE))) 473 IB_ACCESS_REMOTE_WRITE)))
@@ -471,7 +480,7 @@ again:
471 case IB_WR_RDMA_READ: 480 case IB_WR_RDMA_READ:
472 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) 481 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ)))
473 goto inv_err; 482 goto inv_err;
474 if (unlikely(!qib_rkey_ok(qp, &sqp->s_sge.sge, wqe->length, 483 if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length,
475 wqe->rdma_wr.remote_addr, 484 wqe->rdma_wr.remote_addr,
476 wqe->rdma_wr.rkey, 485 wqe->rdma_wr.rkey,
477 IB_ACCESS_REMOTE_READ))) 486 IB_ACCESS_REMOTE_READ)))
@@ -489,7 +498,7 @@ again:
489 case IB_WR_ATOMIC_FETCH_AND_ADD: 498 case IB_WR_ATOMIC_FETCH_AND_ADD:
490 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) 499 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))
491 goto inv_err; 500 goto inv_err;
492 if (unlikely(!qib_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), 501 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
493 wqe->atomic_wr.remote_addr, 502 wqe->atomic_wr.remote_addr,
494 wqe->atomic_wr.rkey, 503 wqe->atomic_wr.rkey,
495 IB_ACCESS_REMOTE_ATOMIC))) 504 IB_ACCESS_REMOTE_ATOMIC)))
@@ -502,7 +511,7 @@ again:
502 (u64) atomic64_add_return(sdata, maddr) - sdata : 511 (u64) atomic64_add_return(sdata, maddr) - sdata :
503 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr, 512 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
504 sdata, wqe->atomic_wr.swap); 513 sdata, wqe->atomic_wr.swap);
505 qib_put_mr(qp->r_sge.sge.mr); 514 rvt_put_mr(qp->r_sge.sge.mr);
506 qp->r_sge.num_sge = 0; 515 qp->r_sge.num_sge = 0;
507 goto send_comp; 516 goto send_comp;
508 517
@@ -526,11 +535,11 @@ again:
526 sge->sge_length -= len; 535 sge->sge_length -= len;
527 if (sge->sge_length == 0) { 536 if (sge->sge_length == 0) {
528 if (!release) 537 if (!release)
529 qib_put_mr(sge->mr); 538 rvt_put_mr(sge->mr);
530 if (--sqp->s_sge.num_sge) 539 if (--sqp->s_sge.num_sge)
531 *sge = *sqp->s_sge.sg_list++; 540 *sge = *sqp->s_sge.sg_list++;
532 } else if (sge->length == 0 && sge->mr->lkey) { 541 } else if (sge->length == 0 && sge->mr->lkey) {
533 if (++sge->n >= QIB_SEGSZ) { 542 if (++sge->n >= RVT_SEGSZ) {
534 if (++sge->m >= sge->mr->mapsz) 543 if (++sge->m >= sge->mr->mapsz)
535 break; 544 break;
536 sge->n = 0; 545 sge->n = 0;
@@ -543,9 +552,9 @@ again:
543 sqp->s_len -= len; 552 sqp->s_len -= len;
544 } 553 }
545 if (release) 554 if (release)
546 qib_put_ss(&qp->r_sge); 555 rvt_put_ss(&qp->r_sge);
547 556
548 if (!test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) 557 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
549 goto send_comp; 558 goto send_comp;
550 559
551 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM) 560 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM)
@@ -561,12 +570,12 @@ again:
561 wc.sl = qp->remote_ah_attr.sl; 570 wc.sl = qp->remote_ah_attr.sl;
562 wc.port_num = 1; 571 wc.port_num = 1;
563 /* Signal completion event if the solicited bit is set. */ 572 /* Signal completion event if the solicited bit is set. */
564 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 573 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
565 wqe->wr.send_flags & IB_SEND_SOLICITED); 574 wqe->wr.send_flags & IB_SEND_SOLICITED);
566 575
567send_comp: 576send_comp:
568 spin_lock_irqsave(&sqp->s_lock, flags); 577 spin_lock_irqsave(&sqp->s_lock, flags);
569 ibp->n_loop_pkts++; 578 ibp->rvp.n_loop_pkts++;
570flush_send: 579flush_send:
571 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; 580 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt;
572 qib_send_complete(sqp, wqe, send_status); 581 qib_send_complete(sqp, wqe, send_status);
@@ -576,7 +585,7 @@ rnr_nak:
576 /* Handle RNR NAK */ 585 /* Handle RNR NAK */
577 if (qp->ibqp.qp_type == IB_QPT_UC) 586 if (qp->ibqp.qp_type == IB_QPT_UC)
578 goto send_comp; 587 goto send_comp;
579 ibp->n_rnr_naks++; 588 ibp->rvp.n_rnr_naks++;
580 /* 589 /*
581 * Note: we don't need the s_lock held since the BUSY flag 590 * Note: we don't need the s_lock held since the BUSY flag
582 * makes this single threaded. 591 * makes this single threaded.
@@ -588,9 +597,9 @@ rnr_nak:
588 if (sqp->s_rnr_retry_cnt < 7) 597 if (sqp->s_rnr_retry_cnt < 7)
589 sqp->s_rnr_retry--; 598 sqp->s_rnr_retry--;
590 spin_lock_irqsave(&sqp->s_lock, flags); 599 spin_lock_irqsave(&sqp->s_lock, flags);
591 if (!(ib_qib_state_ops[sqp->state] & QIB_PROCESS_RECV_OK)) 600 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK))
592 goto clr_busy; 601 goto clr_busy;
593 sqp->s_flags |= QIB_S_WAIT_RNR; 602 sqp->s_flags |= RVT_S_WAIT_RNR;
594 sqp->s_timer.function = qib_rc_rnr_retry; 603 sqp->s_timer.function = qib_rc_rnr_retry;
595 sqp->s_timer.expires = jiffies + 604 sqp->s_timer.expires = jiffies +
596 usecs_to_jiffies(ib_qib_rnr_table[qp->r_min_rnr_timer]); 605 usecs_to_jiffies(ib_qib_rnr_table[qp->r_min_rnr_timer]);
@@ -618,9 +627,9 @@ serr:
618 spin_lock_irqsave(&sqp->s_lock, flags); 627 spin_lock_irqsave(&sqp->s_lock, flags);
619 qib_send_complete(sqp, wqe, send_status); 628 qib_send_complete(sqp, wqe, send_status);
620 if (sqp->ibqp.qp_type == IB_QPT_RC) { 629 if (sqp->ibqp.qp_type == IB_QPT_RC) {
621 int lastwqe = qib_error_qp(sqp, IB_WC_WR_FLUSH_ERR); 630 int lastwqe = rvt_error_qp(sqp, IB_WC_WR_FLUSH_ERR);
622 631
623 sqp->s_flags &= ~QIB_S_BUSY; 632 sqp->s_flags &= ~RVT_S_BUSY;
624 spin_unlock_irqrestore(&sqp->s_lock, flags); 633 spin_unlock_irqrestore(&sqp->s_lock, flags);
625 if (lastwqe) { 634 if (lastwqe) {
626 struct ib_event ev; 635 struct ib_event ev;
@@ -633,12 +642,11 @@ serr:
633 goto done; 642 goto done;
634 } 643 }
635clr_busy: 644clr_busy:
636 sqp->s_flags &= ~QIB_S_BUSY; 645 sqp->s_flags &= ~RVT_S_BUSY;
637unlock: 646unlock:
638 spin_unlock_irqrestore(&sqp->s_lock, flags); 647 spin_unlock_irqrestore(&sqp->s_lock, flags);
639done: 648done:
640 if (qp && atomic_dec_and_test(&qp->refcount)) 649 rcu_read_unlock();
641 wake_up(&qp->wait);
642} 650}
643 651
644/** 652/**
@@ -663,7 +671,7 @@ u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
663 hdr->next_hdr = IB_GRH_NEXT_HDR; 671 hdr->next_hdr = IB_GRH_NEXT_HDR;
664 hdr->hop_limit = grh->hop_limit; 672 hdr->hop_limit = grh->hop_limit;
665 /* The SGID is 32-bit aligned. */ 673 /* The SGID is 32-bit aligned. */
666 hdr->sgid.global.subnet_prefix = ibp->gid_prefix; 674 hdr->sgid.global.subnet_prefix = ibp->rvp.gid_prefix;
667 hdr->sgid.global.interface_id = grh->sgid_index ? 675 hdr->sgid.global.interface_id = grh->sgid_index ?
668 ibp->guids[grh->sgid_index - 1] : ppd_from_ibp(ibp)->guid; 676 ibp->guids[grh->sgid_index - 1] : ppd_from_ibp(ibp)->guid;
669 hdr->dgid = grh->dgid; 677 hdr->dgid = grh->dgid;
@@ -672,9 +680,10 @@ u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
672 return sizeof(struct ib_grh) / sizeof(u32); 680 return sizeof(struct ib_grh) / sizeof(u32);
673} 681}
674 682
675void qib_make_ruc_header(struct qib_qp *qp, struct qib_other_headers *ohdr, 683void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
676 u32 bth0, u32 bth2) 684 u32 bth0, u32 bth2)
677{ 685{
686 struct qib_qp_priv *priv = qp->priv;
678 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 687 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
679 u16 lrh0; 688 u16 lrh0;
680 u32 nwords; 689 u32 nwords;
@@ -685,17 +694,18 @@ void qib_make_ruc_header(struct qib_qp *qp, struct qib_other_headers *ohdr,
685 nwords = (qp->s_cur_size + extra_bytes) >> 2; 694 nwords = (qp->s_cur_size + extra_bytes) >> 2;
686 lrh0 = QIB_LRH_BTH; 695 lrh0 = QIB_LRH_BTH;
687 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) { 696 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
688 qp->s_hdrwords += qib_make_grh(ibp, &qp->s_hdr->u.l.grh, 697 qp->s_hdrwords += qib_make_grh(ibp, &priv->s_hdr->u.l.grh,
689 &qp->remote_ah_attr.grh, 698 &qp->remote_ah_attr.grh,
690 qp->s_hdrwords, nwords); 699 qp->s_hdrwords, nwords);
691 lrh0 = QIB_LRH_GRH; 700 lrh0 = QIB_LRH_GRH;
692 } 701 }
693 lrh0 |= ibp->sl_to_vl[qp->remote_ah_attr.sl] << 12 | 702 lrh0 |= ibp->sl_to_vl[qp->remote_ah_attr.sl] << 12 |
694 qp->remote_ah_attr.sl << 4; 703 qp->remote_ah_attr.sl << 4;
695 qp->s_hdr->lrh[0] = cpu_to_be16(lrh0); 704 priv->s_hdr->lrh[0] = cpu_to_be16(lrh0);
696 qp->s_hdr->lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid); 705 priv->s_hdr->lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
697 qp->s_hdr->lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); 706 priv->s_hdr->lrh[2] =
698 qp->s_hdr->lrh[3] = cpu_to_be16(ppd_from_ibp(ibp)->lid | 707 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
708 priv->s_hdr->lrh[3] = cpu_to_be16(ppd_from_ibp(ibp)->lid |
699 qp->remote_ah_attr.src_path_bits); 709 qp->remote_ah_attr.src_path_bits);
700 bth0 |= qib_get_pkey(ibp, qp->s_pkey_index); 710 bth0 |= qib_get_pkey(ibp, qp->s_pkey_index);
701 bth0 |= extra_bytes << 20; 711 bth0 |= extra_bytes << 20;
@@ -707,20 +717,29 @@ void qib_make_ruc_header(struct qib_qp *qp, struct qib_other_headers *ohdr,
707 this_cpu_inc(ibp->pmastats->n_unicast_xmit); 717 this_cpu_inc(ibp->pmastats->n_unicast_xmit);
708} 718}
709 719
720void _qib_do_send(struct work_struct *work)
721{
722 struct qib_qp_priv *priv = container_of(work, struct qib_qp_priv,
723 s_work);
724 struct rvt_qp *qp = priv->owner;
725
726 qib_do_send(qp);
727}
728
710/** 729/**
711 * qib_do_send - perform a send on a QP 730 * qib_do_send - perform a send on a QP
712 * @work: contains a pointer to the QP 731 * @qp: pointer to the QP
713 * 732 *
714 * Process entries in the send work queue until credit or queue is 733 * Process entries in the send work queue until credit or queue is
715 * exhausted. Only allow one CPU to send a packet per QP (tasklet). 734 * exhausted. Only allow one CPU to send a packet per QP (tasklet).
716 * Otherwise, two threads could send packets out of order. 735 * Otherwise, two threads could send packets out of order.
717 */ 736 */
718void qib_do_send(struct work_struct *work) 737void qib_do_send(struct rvt_qp *qp)
719{ 738{
720 struct qib_qp *qp = container_of(work, struct qib_qp, s_work); 739 struct qib_qp_priv *priv = qp->priv;
721 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 740 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
722 struct qib_pportdata *ppd = ppd_from_ibp(ibp); 741 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
723 int (*make_req)(struct qib_qp *qp); 742 int (*make_req)(struct rvt_qp *qp);
724 unsigned long flags; 743 unsigned long flags;
725 744
726 if ((qp->ibqp.qp_type == IB_QPT_RC || 745 if ((qp->ibqp.qp_type == IB_QPT_RC ||
@@ -745,50 +764,59 @@ void qib_do_send(struct work_struct *work)
745 return; 764 return;
746 } 765 }
747 766
748 qp->s_flags |= QIB_S_BUSY; 767 qp->s_flags |= RVT_S_BUSY;
749
750 spin_unlock_irqrestore(&qp->s_lock, flags);
751 768
752 do { 769 do {
753 /* Check for a constructed packet to be sent. */ 770 /* Check for a constructed packet to be sent. */
754 if (qp->s_hdrwords != 0) { 771 if (qp->s_hdrwords != 0) {
772 spin_unlock_irqrestore(&qp->s_lock, flags);
755 /* 773 /*
756 * If the packet cannot be sent now, return and 774 * If the packet cannot be sent now, return and
757 * the send tasklet will be woken up later. 775 * the send tasklet will be woken up later.
758 */ 776 */
759 if (qib_verbs_send(qp, qp->s_hdr, qp->s_hdrwords, 777 if (qib_verbs_send(qp, priv->s_hdr, qp->s_hdrwords,
760 qp->s_cur_sge, qp->s_cur_size)) 778 qp->s_cur_sge, qp->s_cur_size))
761 break; 779 return;
762 /* Record that s_hdr is empty. */ 780 /* Record that s_hdr is empty. */
763 qp->s_hdrwords = 0; 781 qp->s_hdrwords = 0;
782 spin_lock_irqsave(&qp->s_lock, flags);
764 } 783 }
765 } while (make_req(qp)); 784 } while (make_req(qp));
785
786 spin_unlock_irqrestore(&qp->s_lock, flags);
766} 787}
767 788
768/* 789/*
769 * This should be called with s_lock held. 790 * This should be called with s_lock held.
770 */ 791 */
771void qib_send_complete(struct qib_qp *qp, struct qib_swqe *wqe, 792void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
772 enum ib_wc_status status) 793 enum ib_wc_status status)
773{ 794{
774 u32 old_last, last; 795 u32 old_last, last;
775 unsigned i; 796 unsigned i;
776 797
777 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_OR_FLUSH_SEND)) 798 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND))
778 return; 799 return;
779 800
801 last = qp->s_last;
802 old_last = last;
803 if (++last >= qp->s_size)
804 last = 0;
805 qp->s_last = last;
806 /* See post_send() */
807 barrier();
780 for (i = 0; i < wqe->wr.num_sge; i++) { 808 for (i = 0; i < wqe->wr.num_sge; i++) {
781 struct qib_sge *sge = &wqe->sg_list[i]; 809 struct rvt_sge *sge = &wqe->sg_list[i];
782 810
783 qib_put_mr(sge->mr); 811 rvt_put_mr(sge->mr);
784 } 812 }
785 if (qp->ibqp.qp_type == IB_QPT_UD || 813 if (qp->ibqp.qp_type == IB_QPT_UD ||
786 qp->ibqp.qp_type == IB_QPT_SMI || 814 qp->ibqp.qp_type == IB_QPT_SMI ||
787 qp->ibqp.qp_type == IB_QPT_GSI) 815 qp->ibqp.qp_type == IB_QPT_GSI)
788 atomic_dec(&to_iah(wqe->ud_wr.ah)->refcount); 816 atomic_dec(&ibah_to_rvtah(wqe->ud_wr.ah)->refcount);
789 817
790 /* See ch. 11.2.4.1 and 10.7.3.1 */ 818 /* See ch. 11.2.4.1 and 10.7.3.1 */
791 if (!(qp->s_flags & QIB_S_SIGNAL_REQ_WR) || 819 if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) ||
792 (wqe->wr.send_flags & IB_SEND_SIGNALED) || 820 (wqe->wr.send_flags & IB_SEND_SIGNALED) ||
793 status != IB_WC_SUCCESS) { 821 status != IB_WC_SUCCESS) {
794 struct ib_wc wc; 822 struct ib_wc wc;
@@ -800,15 +828,10 @@ void qib_send_complete(struct qib_qp *qp, struct qib_swqe *wqe,
800 wc.qp = &qp->ibqp; 828 wc.qp = &qp->ibqp;
801 if (status == IB_WC_SUCCESS) 829 if (status == IB_WC_SUCCESS)
802 wc.byte_len = wqe->length; 830 wc.byte_len = wqe->length;
803 qib_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 831 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc,
804 status != IB_WC_SUCCESS); 832 status != IB_WC_SUCCESS);
805 } 833 }
806 834
807 last = qp->s_last;
808 old_last = last;
809 if (++last >= qp->s_size)
810 last = 0;
811 qp->s_last = last;
812 if (qp->s_acked == old_last) 835 if (qp->s_acked == old_last)
813 qp->s_acked = last; 836 qp->s_acked = last;
814 if (qp->s_cur == old_last) 837 if (qp->s_cur == old_last)
diff --git a/drivers/infiniband/hw/qib/qib_sdma.c b/drivers/infiniband/hw/qib/qib_sdma.c
index c6d6a54d2e19..891873b38a1e 100644
--- a/drivers/infiniband/hw/qib/qib_sdma.c
+++ b/drivers/infiniband/hw/qib/qib_sdma.c
@@ -513,7 +513,9 @@ int qib_sdma_running(struct qib_pportdata *ppd)
513static void complete_sdma_err_req(struct qib_pportdata *ppd, 513static void complete_sdma_err_req(struct qib_pportdata *ppd,
514 struct qib_verbs_txreq *tx) 514 struct qib_verbs_txreq *tx)
515{ 515{
516 atomic_inc(&tx->qp->s_dma_busy); 516 struct qib_qp_priv *priv = tx->qp->priv;
517
518 atomic_inc(&priv->s_dma_busy);
517 /* no sdma descriptors, so no unmap_desc */ 519 /* no sdma descriptors, so no unmap_desc */
518 tx->txreq.start_idx = 0; 520 tx->txreq.start_idx = 0;
519 tx->txreq.next_descq_idx = 0; 521 tx->txreq.next_descq_idx = 0;
@@ -531,18 +533,19 @@ static void complete_sdma_err_req(struct qib_pportdata *ppd,
531 * 3) The SGE addresses are suitable for passing to dma_map_single(). 533 * 3) The SGE addresses are suitable for passing to dma_map_single().
532 */ 534 */
533int qib_sdma_verbs_send(struct qib_pportdata *ppd, 535int qib_sdma_verbs_send(struct qib_pportdata *ppd,
534 struct qib_sge_state *ss, u32 dwords, 536 struct rvt_sge_state *ss, u32 dwords,
535 struct qib_verbs_txreq *tx) 537 struct qib_verbs_txreq *tx)
536{ 538{
537 unsigned long flags; 539 unsigned long flags;
538 struct qib_sge *sge; 540 struct rvt_sge *sge;
539 struct qib_qp *qp; 541 struct rvt_qp *qp;
540 int ret = 0; 542 int ret = 0;
541 u16 tail; 543 u16 tail;
542 __le64 *descqp; 544 __le64 *descqp;
543 u64 sdmadesc[2]; 545 u64 sdmadesc[2];
544 u32 dwoffset; 546 u32 dwoffset;
545 dma_addr_t addr; 547 dma_addr_t addr;
548 struct qib_qp_priv *priv;
546 549
547 spin_lock_irqsave(&ppd->sdma_lock, flags); 550 spin_lock_irqsave(&ppd->sdma_lock, flags);
548 551
@@ -621,7 +624,7 @@ retry:
621 if (--ss->num_sge) 624 if (--ss->num_sge)
622 *sge = *ss->sg_list++; 625 *sge = *ss->sg_list++;
623 } else if (sge->length == 0 && sge->mr->lkey) { 626 } else if (sge->length == 0 && sge->mr->lkey) {
624 if (++sge->n >= QIB_SEGSZ) { 627 if (++sge->n >= RVT_SEGSZ) {
625 if (++sge->m >= sge->mr->mapsz) 628 if (++sge->m >= sge->mr->mapsz)
626 break; 629 break;
627 sge->n = 0; 630 sge->n = 0;
@@ -644,8 +647,8 @@ retry:
644 descqp[0] |= cpu_to_le64(SDMA_DESC_DMA_HEAD); 647 descqp[0] |= cpu_to_le64(SDMA_DESC_DMA_HEAD);
645 if (tx->txreq.flags & QIB_SDMA_TXREQ_F_INTREQ) 648 if (tx->txreq.flags & QIB_SDMA_TXREQ_F_INTREQ)
646 descqp[0] |= cpu_to_le64(SDMA_DESC_INTR); 649 descqp[0] |= cpu_to_le64(SDMA_DESC_INTR);
647 650 priv = tx->qp->priv;
648 atomic_inc(&tx->qp->s_dma_busy); 651 atomic_inc(&priv->s_dma_busy);
649 tx->txreq.next_descq_idx = tail; 652 tx->txreq.next_descq_idx = tail;
650 ppd->dd->f_sdma_update_tail(ppd, tail); 653 ppd->dd->f_sdma_update_tail(ppd, tail);
651 ppd->sdma_descq_added += tx->txreq.sg_count; 654 ppd->sdma_descq_added += tx->txreq.sg_count;
@@ -663,13 +666,14 @@ unmap:
663 unmap_desc(ppd, tail); 666 unmap_desc(ppd, tail);
664 } 667 }
665 qp = tx->qp; 668 qp = tx->qp;
669 priv = qp->priv;
666 qib_put_txreq(tx); 670 qib_put_txreq(tx);
667 spin_lock(&qp->r_lock); 671 spin_lock(&qp->r_lock);
668 spin_lock(&qp->s_lock); 672 spin_lock(&qp->s_lock);
669 if (qp->ibqp.qp_type == IB_QPT_RC) { 673 if (qp->ibqp.qp_type == IB_QPT_RC) {
670 /* XXX what about error sending RDMA read responses? */ 674 /* XXX what about error sending RDMA read responses? */
671 if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) 675 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)
672 qib_error_qp(qp, IB_WC_GENERAL_ERR); 676 rvt_error_qp(qp, IB_WC_GENERAL_ERR);
673 } else if (qp->s_wqe) 677 } else if (qp->s_wqe)
674 qib_send_complete(qp, qp->s_wqe, IB_WC_GENERAL_ERR); 678 qib_send_complete(qp, qp->s_wqe, IB_WC_GENERAL_ERR);
675 spin_unlock(&qp->s_lock); 679 spin_unlock(&qp->s_lock);
@@ -679,8 +683,9 @@ unmap:
679 683
680busy: 684busy:
681 qp = tx->qp; 685 qp = tx->qp;
686 priv = qp->priv;
682 spin_lock(&qp->s_lock); 687 spin_lock(&qp->s_lock);
683 if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) { 688 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
684 struct qib_ibdev *dev; 689 struct qib_ibdev *dev;
685 690
686 /* 691 /*
@@ -690,19 +695,19 @@ busy:
690 */ 695 */
691 tx->ss = ss; 696 tx->ss = ss;
692 tx->dwords = dwords; 697 tx->dwords = dwords;
693 qp->s_tx = tx; 698 priv->s_tx = tx;
694 dev = &ppd->dd->verbs_dev; 699 dev = &ppd->dd->verbs_dev;
695 spin_lock(&dev->pending_lock); 700 spin_lock(&dev->rdi.pending_lock);
696 if (list_empty(&qp->iowait)) { 701 if (list_empty(&priv->iowait)) {
697 struct qib_ibport *ibp; 702 struct qib_ibport *ibp;
698 703
699 ibp = &ppd->ibport_data; 704 ibp = &ppd->ibport_data;
700 ibp->n_dmawait++; 705 ibp->rvp.n_dmawait++;
701 qp->s_flags |= QIB_S_WAIT_DMA_DESC; 706 qp->s_flags |= RVT_S_WAIT_DMA_DESC;
702 list_add_tail(&qp->iowait, &dev->dmawait); 707 list_add_tail(&priv->iowait, &dev->dmawait);
703 } 708 }
704 spin_unlock(&dev->pending_lock); 709 spin_unlock(&dev->rdi.pending_lock);
705 qp->s_flags &= ~QIB_S_BUSY; 710 qp->s_flags &= ~RVT_S_BUSY;
706 spin_unlock(&qp->s_lock); 711 spin_unlock(&qp->s_lock);
707 ret = -EBUSY; 712 ret = -EBUSY;
708 } else { 713 } else {
diff --git a/drivers/infiniband/hw/qib/qib_srq.c b/drivers/infiniband/hw/qib/qib_srq.c
deleted file mode 100644
index d6235931a1ba..000000000000
--- a/drivers/infiniband/hw/qib/qib_srq.c
+++ /dev/null
@@ -1,380 +0,0 @@
1/*
2 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <linux/err.h>
35#include <linux/slab.h>
36#include <linux/vmalloc.h>
37
38#include "qib_verbs.h"
39
40/**
41 * qib_post_srq_receive - post a receive on a shared receive queue
42 * @ibsrq: the SRQ to post the receive on
43 * @wr: the list of work requests to post
44 * @bad_wr: A pointer to the first WR to cause a problem is put here
45 *
46 * This may be called from interrupt context.
47 */
48int qib_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
49 struct ib_recv_wr **bad_wr)
50{
51 struct qib_srq *srq = to_isrq(ibsrq);
52 struct qib_rwq *wq;
53 unsigned long flags;
54 int ret;
55
56 for (; wr; wr = wr->next) {
57 struct qib_rwqe *wqe;
58 u32 next;
59 int i;
60
61 if ((unsigned) wr->num_sge > srq->rq.max_sge) {
62 *bad_wr = wr;
63 ret = -EINVAL;
64 goto bail;
65 }
66
67 spin_lock_irqsave(&srq->rq.lock, flags);
68 wq = srq->rq.wq;
69 next = wq->head + 1;
70 if (next >= srq->rq.size)
71 next = 0;
72 if (next == wq->tail) {
73 spin_unlock_irqrestore(&srq->rq.lock, flags);
74 *bad_wr = wr;
75 ret = -ENOMEM;
76 goto bail;
77 }
78
79 wqe = get_rwqe_ptr(&srq->rq, wq->head);
80 wqe->wr_id = wr->wr_id;
81 wqe->num_sge = wr->num_sge;
82 for (i = 0; i < wr->num_sge; i++)
83 wqe->sg_list[i] = wr->sg_list[i];
84 /* Make sure queue entry is written before the head index. */
85 smp_wmb();
86 wq->head = next;
87 spin_unlock_irqrestore(&srq->rq.lock, flags);
88 }
89 ret = 0;
90
91bail:
92 return ret;
93}
94
95/**
96 * qib_create_srq - create a shared receive queue
97 * @ibpd: the protection domain of the SRQ to create
98 * @srq_init_attr: the attributes of the SRQ
99 * @udata: data from libibverbs when creating a user SRQ
100 */
101struct ib_srq *qib_create_srq(struct ib_pd *ibpd,
102 struct ib_srq_init_attr *srq_init_attr,
103 struct ib_udata *udata)
104{
105 struct qib_ibdev *dev = to_idev(ibpd->device);
106 struct qib_srq *srq;
107 u32 sz;
108 struct ib_srq *ret;
109
110 if (srq_init_attr->srq_type != IB_SRQT_BASIC) {
111 ret = ERR_PTR(-ENOSYS);
112 goto done;
113 }
114
115 if (srq_init_attr->attr.max_sge == 0 ||
116 srq_init_attr->attr.max_sge > ib_qib_max_srq_sges ||
117 srq_init_attr->attr.max_wr == 0 ||
118 srq_init_attr->attr.max_wr > ib_qib_max_srq_wrs) {
119 ret = ERR_PTR(-EINVAL);
120 goto done;
121 }
122
123 srq = kmalloc(sizeof(*srq), GFP_KERNEL);
124 if (!srq) {
125 ret = ERR_PTR(-ENOMEM);
126 goto done;
127 }
128
129 /*
130 * Need to use vmalloc() if we want to support large #s of entries.
131 */
132 srq->rq.size = srq_init_attr->attr.max_wr + 1;
133 srq->rq.max_sge = srq_init_attr->attr.max_sge;
134 sz = sizeof(struct ib_sge) * srq->rq.max_sge +
135 sizeof(struct qib_rwqe);
136 srq->rq.wq = vmalloc_user(sizeof(struct qib_rwq) + srq->rq.size * sz);
137 if (!srq->rq.wq) {
138 ret = ERR_PTR(-ENOMEM);
139 goto bail_srq;
140 }
141
142 /*
143 * Return the address of the RWQ as the offset to mmap.
144 * See qib_mmap() for details.
145 */
146 if (udata && udata->outlen >= sizeof(__u64)) {
147 int err;
148 u32 s = sizeof(struct qib_rwq) + srq->rq.size * sz;
149
150 srq->ip =
151 qib_create_mmap_info(dev, s, ibpd->uobject->context,
152 srq->rq.wq);
153 if (!srq->ip) {
154 ret = ERR_PTR(-ENOMEM);
155 goto bail_wq;
156 }
157
158 err = ib_copy_to_udata(udata, &srq->ip->offset,
159 sizeof(srq->ip->offset));
160 if (err) {
161 ret = ERR_PTR(err);
162 goto bail_ip;
163 }
164 } else
165 srq->ip = NULL;
166
167 /*
168 * ib_create_srq() will initialize srq->ibsrq.
169 */
170 spin_lock_init(&srq->rq.lock);
171 srq->rq.wq->head = 0;
172 srq->rq.wq->tail = 0;
173 srq->limit = srq_init_attr->attr.srq_limit;
174
175 spin_lock(&dev->n_srqs_lock);
176 if (dev->n_srqs_allocated == ib_qib_max_srqs) {
177 spin_unlock(&dev->n_srqs_lock);
178 ret = ERR_PTR(-ENOMEM);
179 goto bail_ip;
180 }
181
182 dev->n_srqs_allocated++;
183 spin_unlock(&dev->n_srqs_lock);
184
185 if (srq->ip) {
186 spin_lock_irq(&dev->pending_lock);
187 list_add(&srq->ip->pending_mmaps, &dev->pending_mmaps);
188 spin_unlock_irq(&dev->pending_lock);
189 }
190
191 ret = &srq->ibsrq;
192 goto done;
193
194bail_ip:
195 kfree(srq->ip);
196bail_wq:
197 vfree(srq->rq.wq);
198bail_srq:
199 kfree(srq);
200done:
201 return ret;
202}
203
204/**
205 * qib_modify_srq - modify a shared receive queue
206 * @ibsrq: the SRQ to modify
207 * @attr: the new attributes of the SRQ
208 * @attr_mask: indicates which attributes to modify
209 * @udata: user data for libibverbs.so
210 */
211int qib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
212 enum ib_srq_attr_mask attr_mask,
213 struct ib_udata *udata)
214{
215 struct qib_srq *srq = to_isrq(ibsrq);
216 struct qib_rwq *wq;
217 int ret = 0;
218
219 if (attr_mask & IB_SRQ_MAX_WR) {
220 struct qib_rwq *owq;
221 struct qib_rwqe *p;
222 u32 sz, size, n, head, tail;
223
224 /* Check that the requested sizes are below the limits. */
225 if ((attr->max_wr > ib_qib_max_srq_wrs) ||
226 ((attr_mask & IB_SRQ_LIMIT) ?
227 attr->srq_limit : srq->limit) > attr->max_wr) {
228 ret = -EINVAL;
229 goto bail;
230 }
231
232 sz = sizeof(struct qib_rwqe) +
233 srq->rq.max_sge * sizeof(struct ib_sge);
234 size = attr->max_wr + 1;
235 wq = vmalloc_user(sizeof(struct qib_rwq) + size * sz);
236 if (!wq) {
237 ret = -ENOMEM;
238 goto bail;
239 }
240
241 /* Check that we can write the offset to mmap. */
242 if (udata && udata->inlen >= sizeof(__u64)) {
243 __u64 offset_addr;
244 __u64 offset = 0;
245
246 ret = ib_copy_from_udata(&offset_addr, udata,
247 sizeof(offset_addr));
248 if (ret)
249 goto bail_free;
250 udata->outbuf =
251 (void __user *) (unsigned long) offset_addr;
252 ret = ib_copy_to_udata(udata, &offset,
253 sizeof(offset));
254 if (ret)
255 goto bail_free;
256 }
257
258 spin_lock_irq(&srq->rq.lock);
259 /*
260 * validate head and tail pointer values and compute
261 * the number of remaining WQEs.
262 */
263 owq = srq->rq.wq;
264 head = owq->head;
265 tail = owq->tail;
266 if (head >= srq->rq.size || tail >= srq->rq.size) {
267 ret = -EINVAL;
268 goto bail_unlock;
269 }
270 n = head;
271 if (n < tail)
272 n += srq->rq.size - tail;
273 else
274 n -= tail;
275 if (size <= n) {
276 ret = -EINVAL;
277 goto bail_unlock;
278 }
279 n = 0;
280 p = wq->wq;
281 while (tail != head) {
282 struct qib_rwqe *wqe;
283 int i;
284
285 wqe = get_rwqe_ptr(&srq->rq, tail);
286 p->wr_id = wqe->wr_id;
287 p->num_sge = wqe->num_sge;
288 for (i = 0; i < wqe->num_sge; i++)
289 p->sg_list[i] = wqe->sg_list[i];
290 n++;
291 p = (struct qib_rwqe *)((char *) p + sz);
292 if (++tail >= srq->rq.size)
293 tail = 0;
294 }
295 srq->rq.wq = wq;
296 srq->rq.size = size;
297 wq->head = n;
298 wq->tail = 0;
299 if (attr_mask & IB_SRQ_LIMIT)
300 srq->limit = attr->srq_limit;
301 spin_unlock_irq(&srq->rq.lock);
302
303 vfree(owq);
304
305 if (srq->ip) {
306 struct qib_mmap_info *ip = srq->ip;
307 struct qib_ibdev *dev = to_idev(srq->ibsrq.device);
308 u32 s = sizeof(struct qib_rwq) + size * sz;
309
310 qib_update_mmap_info(dev, ip, s, wq);
311
312 /*
313 * Return the offset to mmap.
314 * See qib_mmap() for details.
315 */
316 if (udata && udata->inlen >= sizeof(__u64)) {
317 ret = ib_copy_to_udata(udata, &ip->offset,
318 sizeof(ip->offset));
319 if (ret)
320 goto bail;
321 }
322
323 /*
324 * Put user mapping info onto the pending list
325 * unless it already is on the list.
326 */
327 spin_lock_irq(&dev->pending_lock);
328 if (list_empty(&ip->pending_mmaps))
329 list_add(&ip->pending_mmaps,
330 &dev->pending_mmaps);
331 spin_unlock_irq(&dev->pending_lock);
332 }
333 } else if (attr_mask & IB_SRQ_LIMIT) {
334 spin_lock_irq(&srq->rq.lock);
335 if (attr->srq_limit >= srq->rq.size)
336 ret = -EINVAL;
337 else
338 srq->limit = attr->srq_limit;
339 spin_unlock_irq(&srq->rq.lock);
340 }
341 goto bail;
342
343bail_unlock:
344 spin_unlock_irq(&srq->rq.lock);
345bail_free:
346 vfree(wq);
347bail:
348 return ret;
349}
350
351int qib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr)
352{
353 struct qib_srq *srq = to_isrq(ibsrq);
354
355 attr->max_wr = srq->rq.size - 1;
356 attr->max_sge = srq->rq.max_sge;
357 attr->srq_limit = srq->limit;
358 return 0;
359}
360
361/**
362 * qib_destroy_srq - destroy a shared receive queue
363 * @ibsrq: the SRQ to destroy
364 */
365int qib_destroy_srq(struct ib_srq *ibsrq)
366{
367 struct qib_srq *srq = to_isrq(ibsrq);
368 struct qib_ibdev *dev = to_idev(ibsrq->device);
369
370 spin_lock(&dev->n_srqs_lock);
371 dev->n_srqs_allocated--;
372 spin_unlock(&dev->n_srqs_lock);
373 if (srq->ip)
374 kref_put(&srq->ip->ref, qib_release_mmap_info);
375 else
376 vfree(srq->rq.wq);
377 kfree(srq);
378
379 return 0;
380}
diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
index 81f56cdff2bc..fe4cf5e4acec 100644
--- a/drivers/infiniband/hw/qib/qib_sysfs.c
+++ b/drivers/infiniband/hw/qib/qib_sysfs.c
@@ -406,7 +406,13 @@ static struct kobj_type qib_sl2vl_ktype = {
406#define QIB_DIAGC_ATTR(N) \ 406#define QIB_DIAGC_ATTR(N) \
407 static struct qib_diagc_attr qib_diagc_attr_##N = { \ 407 static struct qib_diagc_attr qib_diagc_attr_##N = { \
408 .attr = { .name = __stringify(N), .mode = 0664 }, \ 408 .attr = { .name = __stringify(N), .mode = 0664 }, \
409 .counter = offsetof(struct qib_ibport, n_##N) \ 409 .counter = offsetof(struct qib_ibport, rvp.n_##N) \
410 }
411
412#define QIB_DIAGC_ATTR_PER_CPU(N) \
413 static struct qib_diagc_attr qib_diagc_attr_##N = { \
414 .attr = { .name = __stringify(N), .mode = 0664 }, \
415 .counter = offsetof(struct qib_ibport, rvp.z_##N) \
410 } 416 }
411 417
412struct qib_diagc_attr { 418struct qib_diagc_attr {
@@ -414,10 +420,11 @@ struct qib_diagc_attr {
414 size_t counter; 420 size_t counter;
415}; 421};
416 422
423QIB_DIAGC_ATTR_PER_CPU(rc_acks);
424QIB_DIAGC_ATTR_PER_CPU(rc_qacks);
425QIB_DIAGC_ATTR_PER_CPU(rc_delayed_comp);
426
417QIB_DIAGC_ATTR(rc_resends); 427QIB_DIAGC_ATTR(rc_resends);
418QIB_DIAGC_ATTR(rc_acks);
419QIB_DIAGC_ATTR(rc_qacks);
420QIB_DIAGC_ATTR(rc_delayed_comp);
421QIB_DIAGC_ATTR(seq_naks); 428QIB_DIAGC_ATTR(seq_naks);
422QIB_DIAGC_ATTR(rdma_seq); 429QIB_DIAGC_ATTR(rdma_seq);
423QIB_DIAGC_ATTR(rnr_naks); 430QIB_DIAGC_ATTR(rnr_naks);
@@ -449,6 +456,35 @@ static struct attribute *diagc_default_attributes[] = {
449 NULL 456 NULL
450}; 457};
451 458
459static u64 get_all_cpu_total(u64 __percpu *cntr)
460{
461 int cpu;
462 u64 counter = 0;
463
464 for_each_possible_cpu(cpu)
465 counter += *per_cpu_ptr(cntr, cpu);
466 return counter;
467}
468
469#define def_write_per_cpu(cntr) \
470static void write_per_cpu_##cntr(struct qib_pportdata *ppd, u32 data) \
471{ \
472 struct qib_devdata *dd = ppd->dd; \
473 struct qib_ibport *qibp = &ppd->ibport_data; \
474 /* A write can only zero the counter */ \
475 if (data == 0) \
476 qibp->rvp.z_##cntr = get_all_cpu_total(qibp->rvp.cntr); \
477 else \
478 qib_dev_err(dd, "Per CPU cntrs can only be zeroed"); \
479}
480
481def_write_per_cpu(rc_acks)
482def_write_per_cpu(rc_qacks)
483def_write_per_cpu(rc_delayed_comp)
484
485#define READ_PER_CPU_CNTR(cntr) (get_all_cpu_total(qibp->rvp.cntr) - \
486 qibp->rvp.z_##cntr)
487
452static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, 488static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
453 char *buf) 489 char *buf)
454{ 490{
@@ -458,7 +494,16 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
458 container_of(kobj, struct qib_pportdata, diagc_kobj); 494 container_of(kobj, struct qib_pportdata, diagc_kobj);
459 struct qib_ibport *qibp = &ppd->ibport_data; 495 struct qib_ibport *qibp = &ppd->ibport_data;
460 496
461 return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter)); 497 if (!strncmp(dattr->attr.name, "rc_acks", 7))
498 return sprintf(buf, "%llu\n", READ_PER_CPU_CNTR(rc_acks));
499 else if (!strncmp(dattr->attr.name, "rc_qacks", 8))
500 return sprintf(buf, "%llu\n", READ_PER_CPU_CNTR(rc_qacks));
501 else if (!strncmp(dattr->attr.name, "rc_delayed_comp", 15))
502 return sprintf(buf, "%llu\n",
503 READ_PER_CPU_CNTR(rc_delayed_comp));
504 else
505 return sprintf(buf, "%u\n",
506 *(u32 *)((char *)qibp + dattr->counter));
462} 507}
463 508
464static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr, 509static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
@@ -475,7 +520,15 @@ static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
475 ret = kstrtou32(buf, 0, &val); 520 ret = kstrtou32(buf, 0, &val);
476 if (ret) 521 if (ret)
477 return ret; 522 return ret;
478 *(u32 *)((char *) qibp + dattr->counter) = val; 523
524 if (!strncmp(dattr->attr.name, "rc_acks", 7))
525 write_per_cpu_rc_acks(ppd, val);
526 else if (!strncmp(dattr->attr.name, "rc_qacks", 8))
527 write_per_cpu_rc_qacks(ppd, val);
528 else if (!strncmp(dattr->attr.name, "rc_delayed_comp", 15))
529 write_per_cpu_rc_delayed_comp(ppd, val);
530 else
531 *(u32 *)((char *)qibp + dattr->counter) = val;
479 return size; 532 return size;
480} 533}
481 534
@@ -502,7 +555,7 @@ static ssize_t show_rev(struct device *device, struct device_attribute *attr,
502 char *buf) 555 char *buf)
503{ 556{
504 struct qib_ibdev *dev = 557 struct qib_ibdev *dev =
505 container_of(device, struct qib_ibdev, ibdev.dev); 558 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
506 559
507 return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev); 560 return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
508} 561}
@@ -511,7 +564,7 @@ static ssize_t show_hca(struct device *device, struct device_attribute *attr,
511 char *buf) 564 char *buf)
512{ 565{
513 struct qib_ibdev *dev = 566 struct qib_ibdev *dev =
514 container_of(device, struct qib_ibdev, ibdev.dev); 567 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
515 struct qib_devdata *dd = dd_from_dev(dev); 568 struct qib_devdata *dd = dd_from_dev(dev);
516 int ret; 569 int ret;
517 570
@@ -533,7 +586,7 @@ static ssize_t show_boardversion(struct device *device,
533 struct device_attribute *attr, char *buf) 586 struct device_attribute *attr, char *buf)
534{ 587{
535 struct qib_ibdev *dev = 588 struct qib_ibdev *dev =
536 container_of(device, struct qib_ibdev, ibdev.dev); 589 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
537 struct qib_devdata *dd = dd_from_dev(dev); 590 struct qib_devdata *dd = dd_from_dev(dev);
538 591
539 /* The string printed here is already newline-terminated. */ 592 /* The string printed here is already newline-terminated. */
@@ -545,7 +598,7 @@ static ssize_t show_localbus_info(struct device *device,
545 struct device_attribute *attr, char *buf) 598 struct device_attribute *attr, char *buf)
546{ 599{
547 struct qib_ibdev *dev = 600 struct qib_ibdev *dev =
548 container_of(device, struct qib_ibdev, ibdev.dev); 601 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
549 struct qib_devdata *dd = dd_from_dev(dev); 602 struct qib_devdata *dd = dd_from_dev(dev);
550 603
551 /* The string printed here is already newline-terminated. */ 604 /* The string printed here is already newline-terminated. */
@@ -557,7 +610,7 @@ static ssize_t show_nctxts(struct device *device,
557 struct device_attribute *attr, char *buf) 610 struct device_attribute *attr, char *buf)
558{ 611{
559 struct qib_ibdev *dev = 612 struct qib_ibdev *dev =
560 container_of(device, struct qib_ibdev, ibdev.dev); 613 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
561 struct qib_devdata *dd = dd_from_dev(dev); 614 struct qib_devdata *dd = dd_from_dev(dev);
562 615
563 /* Return the number of user ports (contexts) available. */ 616 /* Return the number of user ports (contexts) available. */
@@ -572,7 +625,7 @@ static ssize_t show_nfreectxts(struct device *device,
572 struct device_attribute *attr, char *buf) 625 struct device_attribute *attr, char *buf)
573{ 626{
574 struct qib_ibdev *dev = 627 struct qib_ibdev *dev =
575 container_of(device, struct qib_ibdev, ibdev.dev); 628 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
576 struct qib_devdata *dd = dd_from_dev(dev); 629 struct qib_devdata *dd = dd_from_dev(dev);
577 630
578 /* Return the number of free user ports (contexts) available. */ 631 /* Return the number of free user ports (contexts) available. */
@@ -583,7 +636,7 @@ static ssize_t show_serial(struct device *device,
583 struct device_attribute *attr, char *buf) 636 struct device_attribute *attr, char *buf)
584{ 637{
585 struct qib_ibdev *dev = 638 struct qib_ibdev *dev =
586 container_of(device, struct qib_ibdev, ibdev.dev); 639 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
587 struct qib_devdata *dd = dd_from_dev(dev); 640 struct qib_devdata *dd = dd_from_dev(dev);
588 641
589 buf[sizeof(dd->serial)] = '\0'; 642 buf[sizeof(dd->serial)] = '\0';
@@ -597,7 +650,7 @@ static ssize_t store_chip_reset(struct device *device,
597 size_t count) 650 size_t count)
598{ 651{
599 struct qib_ibdev *dev = 652 struct qib_ibdev *dev =
600 container_of(device, struct qib_ibdev, ibdev.dev); 653 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
601 struct qib_devdata *dd = dd_from_dev(dev); 654 struct qib_devdata *dd = dd_from_dev(dev);
602 int ret; 655 int ret;
603 656
@@ -618,7 +671,7 @@ static ssize_t show_tempsense(struct device *device,
618 struct device_attribute *attr, char *buf) 671 struct device_attribute *attr, char *buf)
619{ 672{
620 struct qib_ibdev *dev = 673 struct qib_ibdev *dev =
621 container_of(device, struct qib_ibdev, ibdev.dev); 674 container_of(device, struct qib_ibdev, rdi.ibdev.dev);
622 struct qib_devdata *dd = dd_from_dev(dev); 675 struct qib_devdata *dd = dd_from_dev(dev);
623 int ret; 676 int ret;
624 int idx; 677 int idx;
@@ -778,7 +831,7 @@ bail:
778 */ 831 */
779int qib_verbs_register_sysfs(struct qib_devdata *dd) 832int qib_verbs_register_sysfs(struct qib_devdata *dd)
780{ 833{
781 struct ib_device *dev = &dd->verbs_dev.ibdev; 834 struct ib_device *dev = &dd->verbs_dev.rdi.ibdev;
782 int i, ret; 835 int i, ret;
783 836
784 for (i = 0; i < ARRAY_SIZE(qib_attributes); ++i) { 837 for (i = 0; i < ARRAY_SIZE(qib_attributes); ++i) {
diff --git a/drivers/infiniband/hw/qib/qib_uc.c b/drivers/infiniband/hw/qib/qib_uc.c
index 06a564589c35..7bdbc79ceaa3 100644
--- a/drivers/infiniband/hw/qib/qib_uc.c
+++ b/drivers/infiniband/hw/qib/qib_uc.c
@@ -41,61 +41,62 @@
41 * qib_make_uc_req - construct a request packet (SEND, RDMA write) 41 * qib_make_uc_req - construct a request packet (SEND, RDMA write)
42 * @qp: a pointer to the QP 42 * @qp: a pointer to the QP
43 * 43 *
44 * Assumes the s_lock is held.
45 *
44 * Return 1 if constructed; otherwise, return 0. 46 * Return 1 if constructed; otherwise, return 0.
45 */ 47 */
46int qib_make_uc_req(struct qib_qp *qp) 48int qib_make_uc_req(struct rvt_qp *qp)
47{ 49{
50 struct qib_qp_priv *priv = qp->priv;
48 struct qib_other_headers *ohdr; 51 struct qib_other_headers *ohdr;
49 struct qib_swqe *wqe; 52 struct rvt_swqe *wqe;
50 unsigned long flags;
51 u32 hwords; 53 u32 hwords;
52 u32 bth0; 54 u32 bth0;
53 u32 len; 55 u32 len;
54 u32 pmtu = qp->pmtu; 56 u32 pmtu = qp->pmtu;
55 int ret = 0; 57 int ret = 0;
56 58
57 spin_lock_irqsave(&qp->s_lock, flags); 59 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) {
58 60 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
59 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_SEND_OK)) {
60 if (!(ib_qib_state_ops[qp->state] & QIB_FLUSH_SEND))
61 goto bail; 61 goto bail;
62 /* We are in the error state, flush the work request. */ 62 /* We are in the error state, flush the work request. */
63 if (qp->s_last == qp->s_head) 63 smp_read_barrier_depends(); /* see post_one_send() */
64 if (qp->s_last == ACCESS_ONCE(qp->s_head))
64 goto bail; 65 goto bail;
65 /* If DMAs are in progress, we can't flush immediately. */ 66 /* If DMAs are in progress, we can't flush immediately. */
66 if (atomic_read(&qp->s_dma_busy)) { 67 if (atomic_read(&priv->s_dma_busy)) {
67 qp->s_flags |= QIB_S_WAIT_DMA; 68 qp->s_flags |= RVT_S_WAIT_DMA;
68 goto bail; 69 goto bail;
69 } 70 }
70 wqe = get_swqe_ptr(qp, qp->s_last); 71 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
71 qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR); 72 qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
72 goto done; 73 goto done;
73 } 74 }
74 75
75 ohdr = &qp->s_hdr->u.oth; 76 ohdr = &priv->s_hdr->u.oth;
76 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH) 77 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
77 ohdr = &qp->s_hdr->u.l.oth; 78 ohdr = &priv->s_hdr->u.l.oth;
78 79
79 /* header size in 32-bit words LRH+BTH = (8+12)/4. */ 80 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
80 hwords = 5; 81 hwords = 5;
81 bth0 = 0; 82 bth0 = 0;
82 83
83 /* Get the next send request. */ 84 /* Get the next send request. */
84 wqe = get_swqe_ptr(qp, qp->s_cur); 85 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
85 qp->s_wqe = NULL; 86 qp->s_wqe = NULL;
86 switch (qp->s_state) { 87 switch (qp->s_state) {
87 default: 88 default:
88 if (!(ib_qib_state_ops[qp->state] & 89 if (!(ib_rvt_state_ops[qp->state] &
89 QIB_PROCESS_NEXT_SEND_OK)) 90 RVT_PROCESS_NEXT_SEND_OK))
90 goto bail; 91 goto bail;
91 /* Check if send work queue is empty. */ 92 /* Check if send work queue is empty. */
92 if (qp->s_cur == qp->s_head) 93 smp_read_barrier_depends(); /* see post_one_send() */
94 if (qp->s_cur == ACCESS_ONCE(qp->s_head))
93 goto bail; 95 goto bail;
94 /* 96 /*
95 * Start a new request. 97 * Start a new request.
96 */ 98 */
97 wqe->psn = qp->s_next_psn; 99 qp->s_psn = wqe->psn;
98 qp->s_psn = qp->s_next_psn;
99 qp->s_sge.sge = wqe->sg_list[0]; 100 qp->s_sge.sge = wqe->sg_list[0];
100 qp->s_sge.sg_list = wqe->sg_list + 1; 101 qp->s_sge.sg_list = wqe->sg_list + 1;
101 qp->s_sge.num_sge = wqe->wr.num_sge; 102 qp->s_sge.num_sge = wqe->wr.num_sge;
@@ -214,15 +215,11 @@ int qib_make_uc_req(struct qib_qp *qp)
214 qp->s_cur_sge = &qp->s_sge; 215 qp->s_cur_sge = &qp->s_sge;
215 qp->s_cur_size = len; 216 qp->s_cur_size = len;
216 qib_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24), 217 qib_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24),
217 qp->s_next_psn++ & QIB_PSN_MASK); 218 qp->s_psn++ & QIB_PSN_MASK);
218done: 219done:
219 ret = 1; 220 return 1;
220 goto unlock;
221
222bail: 221bail:
223 qp->s_flags &= ~QIB_S_BUSY; 222 qp->s_flags &= ~RVT_S_BUSY;
224unlock:
225 spin_unlock_irqrestore(&qp->s_lock, flags);
226 return ret; 223 return ret;
227} 224}
228 225
@@ -240,7 +237,7 @@ unlock:
240 * Called at interrupt level. 237 * Called at interrupt level.
241 */ 238 */
242void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr, 239void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
243 int has_grh, void *data, u32 tlen, struct qib_qp *qp) 240 int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
244{ 241{
245 struct qib_other_headers *ohdr; 242 struct qib_other_headers *ohdr;
246 u32 opcode; 243 u32 opcode;
@@ -278,10 +275,10 @@ void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
278inv: 275inv:
279 if (qp->r_state == OP(SEND_FIRST) || 276 if (qp->r_state == OP(SEND_FIRST) ||
280 qp->r_state == OP(SEND_MIDDLE)) { 277 qp->r_state == OP(SEND_MIDDLE)) {
281 set_bit(QIB_R_REWIND_SGE, &qp->r_aflags); 278 set_bit(RVT_R_REWIND_SGE, &qp->r_aflags);
282 qp->r_sge.num_sge = 0; 279 qp->r_sge.num_sge = 0;
283 } else 280 } else
284 qib_put_ss(&qp->r_sge); 281 rvt_put_ss(&qp->r_sge);
285 qp->r_state = OP(SEND_LAST); 282 qp->r_state = OP(SEND_LAST);
286 switch (opcode) { 283 switch (opcode) {
287 case OP(SEND_FIRST): 284 case OP(SEND_FIRST):
@@ -328,8 +325,8 @@ inv:
328 goto inv; 325 goto inv;
329 } 326 }
330 327
331 if (qp->state == IB_QPS_RTR && !(qp->r_flags & QIB_R_COMM_EST)) { 328 if (qp->state == IB_QPS_RTR && !(qp->r_flags & RVT_R_COMM_EST)) {
332 qp->r_flags |= QIB_R_COMM_EST; 329 qp->r_flags |= RVT_R_COMM_EST;
333 if (qp->ibqp.event_handler) { 330 if (qp->ibqp.event_handler) {
334 struct ib_event ev; 331 struct ib_event ev;
335 332
@@ -346,7 +343,7 @@ inv:
346 case OP(SEND_ONLY): 343 case OP(SEND_ONLY):
347 case OP(SEND_ONLY_WITH_IMMEDIATE): 344 case OP(SEND_ONLY_WITH_IMMEDIATE):
348send_first: 345send_first:
349 if (test_and_clear_bit(QIB_R_REWIND_SGE, &qp->r_aflags)) 346 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags))
350 qp->r_sge = qp->s_rdma_read_sge; 347 qp->r_sge = qp->s_rdma_read_sge;
351 else { 348 else {
352 ret = qib_get_rwqe(qp, 0); 349 ret = qib_get_rwqe(qp, 0);
@@ -400,7 +397,7 @@ send_last:
400 goto rewind; 397 goto rewind;
401 wc.opcode = IB_WC_RECV; 398 wc.opcode = IB_WC_RECV;
402 qib_copy_sge(&qp->r_sge, data, tlen, 0); 399 qib_copy_sge(&qp->r_sge, data, tlen, 0);
403 qib_put_ss(&qp->s_rdma_read_sge); 400 rvt_put_ss(&qp->s_rdma_read_sge);
404last_imm: 401last_imm:
405 wc.wr_id = qp->r_wr_id; 402 wc.wr_id = qp->r_wr_id;
406 wc.status = IB_WC_SUCCESS; 403 wc.status = IB_WC_SUCCESS;
@@ -414,7 +411,7 @@ last_imm:
414 wc.dlid_path_bits = 0; 411 wc.dlid_path_bits = 0;
415 wc.port_num = 0; 412 wc.port_num = 0;
416 /* Signal completion event if the solicited bit is set. */ 413 /* Signal completion event if the solicited bit is set. */
417 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 414 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
418 (ohdr->bth[0] & 415 (ohdr->bth[0] &
419 cpu_to_be32(IB_BTH_SOLICITED)) != 0); 416 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
420 break; 417 break;
@@ -438,7 +435,7 @@ rdma_first:
438 int ok; 435 int ok;
439 436
440 /* Check rkey */ 437 /* Check rkey */
441 ok = qib_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, 438 ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len,
442 vaddr, rkey, IB_ACCESS_REMOTE_WRITE); 439 vaddr, rkey, IB_ACCESS_REMOTE_WRITE);
443 if (unlikely(!ok)) 440 if (unlikely(!ok))
444 goto drop; 441 goto drop;
@@ -483,8 +480,8 @@ rdma_last_imm:
483 tlen -= (hdrsize + pad + 4); 480 tlen -= (hdrsize + pad + 4);
484 if (unlikely(tlen + qp->r_rcv_len != qp->r_len)) 481 if (unlikely(tlen + qp->r_rcv_len != qp->r_len))
485 goto drop; 482 goto drop;
486 if (test_and_clear_bit(QIB_R_REWIND_SGE, &qp->r_aflags)) 483 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags))
487 qib_put_ss(&qp->s_rdma_read_sge); 484 rvt_put_ss(&qp->s_rdma_read_sge);
488 else { 485 else {
489 ret = qib_get_rwqe(qp, 1); 486 ret = qib_get_rwqe(qp, 1);
490 if (ret < 0) 487 if (ret < 0)
@@ -495,7 +492,7 @@ rdma_last_imm:
495 wc.byte_len = qp->r_len; 492 wc.byte_len = qp->r_len;
496 wc.opcode = IB_WC_RECV_RDMA_WITH_IMM; 493 wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;
497 qib_copy_sge(&qp->r_sge, data, tlen, 1); 494 qib_copy_sge(&qp->r_sge, data, tlen, 1);
498 qib_put_ss(&qp->r_sge); 495 rvt_put_ss(&qp->r_sge);
499 goto last_imm; 496 goto last_imm;
500 497
501 case OP(RDMA_WRITE_LAST): 498 case OP(RDMA_WRITE_LAST):
@@ -511,7 +508,7 @@ rdma_last:
511 if (unlikely(tlen + qp->r_rcv_len != qp->r_len)) 508 if (unlikely(tlen + qp->r_rcv_len != qp->r_len))
512 goto drop; 509 goto drop;
513 qib_copy_sge(&qp->r_sge, data, tlen, 1); 510 qib_copy_sge(&qp->r_sge, data, tlen, 1);
514 qib_put_ss(&qp->r_sge); 511 rvt_put_ss(&qp->r_sge);
515 break; 512 break;
516 513
517 default: 514 default:
@@ -523,10 +520,10 @@ rdma_last:
523 return; 520 return;
524 521
525rewind: 522rewind:
526 set_bit(QIB_R_REWIND_SGE, &qp->r_aflags); 523 set_bit(RVT_R_REWIND_SGE, &qp->r_aflags);
527 qp->r_sge.num_sge = 0; 524 qp->r_sge.num_sge = 0;
528drop: 525drop:
529 ibp->n_pkt_drops++; 526 ibp->rvp.n_pkt_drops++;
530 return; 527 return;
531 528
532op_err: 529op_err:
diff --git a/drivers/infiniband/hw/qib/qib_ud.c b/drivers/infiniband/hw/qib/qib_ud.c
index 59193f67ea78..d9502137de62 100644
--- a/drivers/infiniband/hw/qib/qib_ud.c
+++ b/drivers/infiniband/hw/qib/qib_ud.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <rdma/ib_smi.h> 34#include <rdma/ib_smi.h>
35#include <rdma/ib_verbs.h>
35 36
36#include "qib.h" 37#include "qib.h"
37#include "qib_mad.h" 38#include "qib_mad.h"
@@ -46,22 +47,26 @@
46 * Note that the receive interrupt handler may be calling qib_ud_rcv() 47 * Note that the receive interrupt handler may be calling qib_ud_rcv()
47 * while this is being called. 48 * while this is being called.
48 */ 49 */
49static void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe) 50static void qib_ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
50{ 51{
51 struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num); 52 struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
52 struct qib_pportdata *ppd; 53 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
53 struct qib_qp *qp; 54 struct qib_devdata *dd = ppd->dd;
55 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
56 struct rvt_qp *qp;
54 struct ib_ah_attr *ah_attr; 57 struct ib_ah_attr *ah_attr;
55 unsigned long flags; 58 unsigned long flags;
56 struct qib_sge_state ssge; 59 struct rvt_sge_state ssge;
57 struct qib_sge *sge; 60 struct rvt_sge *sge;
58 struct ib_wc wc; 61 struct ib_wc wc;
59 u32 length; 62 u32 length;
60 enum ib_qp_type sqptype, dqptype; 63 enum ib_qp_type sqptype, dqptype;
61 64
62 qp = qib_lookup_qpn(ibp, swqe->ud_wr.remote_qpn); 65 rcu_read_lock();
66 qp = rvt_lookup_qpn(rdi, &ibp->rvp, swqe->ud_wr.remote_qpn);
63 if (!qp) { 67 if (!qp) {
64 ibp->n_pkt_drops++; 68 ibp->rvp.n_pkt_drops++;
69 rcu_read_unlock();
65 return; 70 return;
66 } 71 }
67 72
@@ -71,12 +76,12 @@ static void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe)
71 IB_QPT_UD : qp->ibqp.qp_type; 76 IB_QPT_UD : qp->ibqp.qp_type;
72 77
73 if (dqptype != sqptype || 78 if (dqptype != sqptype ||
74 !(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) { 79 !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
75 ibp->n_pkt_drops++; 80 ibp->rvp.n_pkt_drops++;
76 goto drop; 81 goto drop;
77 } 82 }
78 83
79 ah_attr = &to_iah(swqe->ud_wr.ah)->attr; 84 ah_attr = &ibah_to_rvtah(swqe->ud_wr.ah)->attr;
80 ppd = ppd_from_ibp(ibp); 85 ppd = ppd_from_ibp(ibp);
81 86
82 if (qp->ibqp.qp_num > 1) { 87 if (qp->ibqp.qp_num > 1) {
@@ -140,8 +145,8 @@ static void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe)
140 /* 145 /*
141 * Get the next work request entry to find where to put the data. 146 * Get the next work request entry to find where to put the data.
142 */ 147 */
143 if (qp->r_flags & QIB_R_REUSE_SGE) 148 if (qp->r_flags & RVT_R_REUSE_SGE)
144 qp->r_flags &= ~QIB_R_REUSE_SGE; 149 qp->r_flags &= ~RVT_R_REUSE_SGE;
145 else { 150 else {
146 int ret; 151 int ret;
147 152
@@ -152,14 +157,14 @@ static void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe)
152 } 157 }
153 if (!ret) { 158 if (!ret) {
154 if (qp->ibqp.qp_num == 0) 159 if (qp->ibqp.qp_num == 0)
155 ibp->n_vl15_dropped++; 160 ibp->rvp.n_vl15_dropped++;
156 goto bail_unlock; 161 goto bail_unlock;
157 } 162 }
158 } 163 }
159 /* Silently drop packets which are too big. */ 164 /* Silently drop packets which are too big. */
160 if (unlikely(wc.byte_len > qp->r_len)) { 165 if (unlikely(wc.byte_len > qp->r_len)) {
161 qp->r_flags |= QIB_R_REUSE_SGE; 166 qp->r_flags |= RVT_R_REUSE_SGE;
162 ibp->n_pkt_drops++; 167 ibp->rvp.n_pkt_drops++;
163 goto bail_unlock; 168 goto bail_unlock;
164 } 169 }
165 170
@@ -189,7 +194,7 @@ static void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe)
189 if (--ssge.num_sge) 194 if (--ssge.num_sge)
190 *sge = *ssge.sg_list++; 195 *sge = *ssge.sg_list++;
191 } else if (sge->length == 0 && sge->mr->lkey) { 196 } else if (sge->length == 0 && sge->mr->lkey) {
192 if (++sge->n >= QIB_SEGSZ) { 197 if (++sge->n >= RVT_SEGSZ) {
193 if (++sge->m >= sge->mr->mapsz) 198 if (++sge->m >= sge->mr->mapsz)
194 break; 199 break;
195 sge->n = 0; 200 sge->n = 0;
@@ -201,8 +206,8 @@ static void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe)
201 } 206 }
202 length -= len; 207 length -= len;
203 } 208 }
204 qib_put_ss(&qp->r_sge); 209 rvt_put_ss(&qp->r_sge);
205 if (!test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) 210 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
206 goto bail_unlock; 211 goto bail_unlock;
207 wc.wr_id = qp->r_wr_id; 212 wc.wr_id = qp->r_wr_id;
208 wc.status = IB_WC_SUCCESS; 213 wc.status = IB_WC_SUCCESS;
@@ -216,30 +221,31 @@ static void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe)
216 wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1); 221 wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1);
217 wc.port_num = qp->port_num; 222 wc.port_num = qp->port_num;
218 /* Signal completion event if the solicited bit is set. */ 223 /* Signal completion event if the solicited bit is set. */
219 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 224 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
220 swqe->wr.send_flags & IB_SEND_SOLICITED); 225 swqe->wr.send_flags & IB_SEND_SOLICITED);
221 ibp->n_loop_pkts++; 226 ibp->rvp.n_loop_pkts++;
222bail_unlock: 227bail_unlock:
223 spin_unlock_irqrestore(&qp->r_lock, flags); 228 spin_unlock_irqrestore(&qp->r_lock, flags);
224drop: 229drop:
225 if (atomic_dec_and_test(&qp->refcount)) 230 rcu_read_unlock();
226 wake_up(&qp->wait);
227} 231}
228 232
229/** 233/**
230 * qib_make_ud_req - construct a UD request packet 234 * qib_make_ud_req - construct a UD request packet
231 * @qp: the QP 235 * @qp: the QP
232 * 236 *
237 * Assumes the s_lock is held.
238 *
233 * Return 1 if constructed; otherwise, return 0. 239 * Return 1 if constructed; otherwise, return 0.
234 */ 240 */
235int qib_make_ud_req(struct qib_qp *qp) 241int qib_make_ud_req(struct rvt_qp *qp)
236{ 242{
243 struct qib_qp_priv *priv = qp->priv;
237 struct qib_other_headers *ohdr; 244 struct qib_other_headers *ohdr;
238 struct ib_ah_attr *ah_attr; 245 struct ib_ah_attr *ah_attr;
239 struct qib_pportdata *ppd; 246 struct qib_pportdata *ppd;
240 struct qib_ibport *ibp; 247 struct qib_ibport *ibp;
241 struct qib_swqe *wqe; 248 struct rvt_swqe *wqe;
242 unsigned long flags;
243 u32 nwords; 249 u32 nwords;
244 u32 extra_bytes; 250 u32 extra_bytes;
245 u32 bth0; 251 u32 bth0;
@@ -248,28 +254,29 @@ int qib_make_ud_req(struct qib_qp *qp)
248 int ret = 0; 254 int ret = 0;
249 int next_cur; 255 int next_cur;
250 256
251 spin_lock_irqsave(&qp->s_lock, flags); 257 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
252 258 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
253 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_NEXT_SEND_OK)) {
254 if (!(ib_qib_state_ops[qp->state] & QIB_FLUSH_SEND))
255 goto bail; 259 goto bail;
256 /* We are in the error state, flush the work request. */ 260 /* We are in the error state, flush the work request. */
257 if (qp->s_last == qp->s_head) 261 smp_read_barrier_depends(); /* see post_one_send */
262 if (qp->s_last == ACCESS_ONCE(qp->s_head))
258 goto bail; 263 goto bail;
259 /* If DMAs are in progress, we can't flush immediately. */ 264 /* If DMAs are in progress, we can't flush immediately. */
260 if (atomic_read(&qp->s_dma_busy)) { 265 if (atomic_read(&priv->s_dma_busy)) {
261 qp->s_flags |= QIB_S_WAIT_DMA; 266 qp->s_flags |= RVT_S_WAIT_DMA;
262 goto bail; 267 goto bail;
263 } 268 }
264 wqe = get_swqe_ptr(qp, qp->s_last); 269 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
265 qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR); 270 qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
266 goto done; 271 goto done;
267 } 272 }
268 273
269 if (qp->s_cur == qp->s_head) 274 /* see post_one_send() */
275 smp_read_barrier_depends();
276 if (qp->s_cur == ACCESS_ONCE(qp->s_head))
270 goto bail; 277 goto bail;
271 278
272 wqe = get_swqe_ptr(qp, qp->s_cur); 279 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
273 next_cur = qp->s_cur + 1; 280 next_cur = qp->s_cur + 1;
274 if (next_cur >= qp->s_size) 281 if (next_cur >= qp->s_size)
275 next_cur = 0; 282 next_cur = 0;
@@ -277,9 +284,9 @@ int qib_make_ud_req(struct qib_qp *qp)
277 /* Construct the header. */ 284 /* Construct the header. */
278 ibp = to_iport(qp->ibqp.device, qp->port_num); 285 ibp = to_iport(qp->ibqp.device, qp->port_num);
279 ppd = ppd_from_ibp(ibp); 286 ppd = ppd_from_ibp(ibp);
280 ah_attr = &to_iah(wqe->ud_wr.ah)->attr; 287 ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
281 if (ah_attr->dlid >= QIB_MULTICAST_LID_BASE) { 288 if (ah_attr->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
282 if (ah_attr->dlid != QIB_PERMISSIVE_LID) 289 if (ah_attr->dlid != be16_to_cpu(IB_LID_PERMISSIVE))
283 this_cpu_inc(ibp->pmastats->n_multicast_xmit); 290 this_cpu_inc(ibp->pmastats->n_multicast_xmit);
284 else 291 else
285 this_cpu_inc(ibp->pmastats->n_unicast_xmit); 292 this_cpu_inc(ibp->pmastats->n_unicast_xmit);
@@ -287,6 +294,7 @@ int qib_make_ud_req(struct qib_qp *qp)
287 this_cpu_inc(ibp->pmastats->n_unicast_xmit); 294 this_cpu_inc(ibp->pmastats->n_unicast_xmit);
288 lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1); 295 lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1);
289 if (unlikely(lid == ppd->lid)) { 296 if (unlikely(lid == ppd->lid)) {
297 unsigned long flags;
290 /* 298 /*
291 * If DMAs are in progress, we can't generate 299 * If DMAs are in progress, we can't generate
292 * a completion for the loopback packet since 300 * a completion for the loopback packet since
@@ -294,11 +302,12 @@ int qib_make_ud_req(struct qib_qp *qp)
294 * XXX Instead of waiting, we could queue a 302 * XXX Instead of waiting, we could queue a
295 * zero length descriptor so we get a callback. 303 * zero length descriptor so we get a callback.
296 */ 304 */
297 if (atomic_read(&qp->s_dma_busy)) { 305 if (atomic_read(&priv->s_dma_busy)) {
298 qp->s_flags |= QIB_S_WAIT_DMA; 306 qp->s_flags |= RVT_S_WAIT_DMA;
299 goto bail; 307 goto bail;
300 } 308 }
301 qp->s_cur = next_cur; 309 qp->s_cur = next_cur;
310 local_irq_save(flags);
302 spin_unlock_irqrestore(&qp->s_lock, flags); 311 spin_unlock_irqrestore(&qp->s_lock, flags);
303 qib_ud_loopback(qp, wqe); 312 qib_ud_loopback(qp, wqe);
304 spin_lock_irqsave(&qp->s_lock, flags); 313 spin_lock_irqsave(&qp->s_lock, flags);
@@ -324,11 +333,11 @@ int qib_make_ud_req(struct qib_qp *qp)
324 333
325 if (ah_attr->ah_flags & IB_AH_GRH) { 334 if (ah_attr->ah_flags & IB_AH_GRH) {
326 /* Header size in 32-bit words. */ 335 /* Header size in 32-bit words. */
327 qp->s_hdrwords += qib_make_grh(ibp, &qp->s_hdr->u.l.grh, 336 qp->s_hdrwords += qib_make_grh(ibp, &priv->s_hdr->u.l.grh,
328 &ah_attr->grh, 337 &ah_attr->grh,
329 qp->s_hdrwords, nwords); 338 qp->s_hdrwords, nwords);
330 lrh0 = QIB_LRH_GRH; 339 lrh0 = QIB_LRH_GRH;
331 ohdr = &qp->s_hdr->u.l.oth; 340 ohdr = &priv->s_hdr->u.l.oth;
332 /* 341 /*
333 * Don't worry about sending to locally attached multicast 342 * Don't worry about sending to locally attached multicast
334 * QPs. It is unspecified by the spec. what happens. 343 * QPs. It is unspecified by the spec. what happens.
@@ -336,7 +345,7 @@ int qib_make_ud_req(struct qib_qp *qp)
336 } else { 345 } else {
337 /* Header size in 32-bit words. */ 346 /* Header size in 32-bit words. */
338 lrh0 = QIB_LRH_BTH; 347 lrh0 = QIB_LRH_BTH;
339 ohdr = &qp->s_hdr->u.oth; 348 ohdr = &priv->s_hdr->u.oth;
340 } 349 }
341 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) { 350 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
342 qp->s_hdrwords++; 351 qp->s_hdrwords++;
@@ -349,15 +358,16 @@ int qib_make_ud_req(struct qib_qp *qp)
349 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */ 358 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
350 else 359 else
351 lrh0 |= ibp->sl_to_vl[ah_attr->sl] << 12; 360 lrh0 |= ibp->sl_to_vl[ah_attr->sl] << 12;
352 qp->s_hdr->lrh[0] = cpu_to_be16(lrh0); 361 priv->s_hdr->lrh[0] = cpu_to_be16(lrh0);
353 qp->s_hdr->lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */ 362 priv->s_hdr->lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */
354 qp->s_hdr->lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); 363 priv->s_hdr->lrh[2] =
364 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
355 lid = ppd->lid; 365 lid = ppd->lid;
356 if (lid) { 366 if (lid) {
357 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1); 367 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1);
358 qp->s_hdr->lrh[3] = cpu_to_be16(lid); 368 priv->s_hdr->lrh[3] = cpu_to_be16(lid);
359 } else 369 } else
360 qp->s_hdr->lrh[3] = IB_LID_PERMISSIVE; 370 priv->s_hdr->lrh[3] = IB_LID_PERMISSIVE;
361 if (wqe->wr.send_flags & IB_SEND_SOLICITED) 371 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
362 bth0 |= IB_BTH_SOLICITED; 372 bth0 |= IB_BTH_SOLICITED;
363 bth0 |= extra_bytes << 20; 373 bth0 |= extra_bytes << 20;
@@ -368,11 +378,11 @@ int qib_make_ud_req(struct qib_qp *qp)
368 /* 378 /*
369 * Use the multicast QP if the destination LID is a multicast LID. 379 * Use the multicast QP if the destination LID is a multicast LID.
370 */ 380 */
371 ohdr->bth[1] = ah_attr->dlid >= QIB_MULTICAST_LID_BASE && 381 ohdr->bth[1] = ah_attr->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) &&
372 ah_attr->dlid != QIB_PERMISSIVE_LID ? 382 ah_attr->dlid != be16_to_cpu(IB_LID_PERMISSIVE) ?
373 cpu_to_be32(QIB_MULTICAST_QPN) : 383 cpu_to_be32(QIB_MULTICAST_QPN) :
374 cpu_to_be32(wqe->ud_wr.remote_qpn); 384 cpu_to_be32(wqe->ud_wr.remote_qpn);
375 ohdr->bth[2] = cpu_to_be32(qp->s_next_psn++ & QIB_PSN_MASK); 385 ohdr->bth[2] = cpu_to_be32(wqe->psn & QIB_PSN_MASK);
376 /* 386 /*
377 * Qkeys with the high order bit set mean use the 387 * Qkeys with the high order bit set mean use the
378 * qkey from the QP context instead of the WR (see 10.2.5). 388 * qkey from the QP context instead of the WR (see 10.2.5).
@@ -382,13 +392,9 @@ int qib_make_ud_req(struct qib_qp *qp)
382 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num); 392 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
383 393
384done: 394done:
385 ret = 1; 395 return 1;
386 goto unlock;
387
388bail: 396bail:
389 qp->s_flags &= ~QIB_S_BUSY; 397 qp->s_flags &= ~RVT_S_BUSY;
390unlock:
391 spin_unlock_irqrestore(&qp->s_lock, flags);
392 return ret; 398 return ret;
393} 399}
394 400
@@ -426,7 +432,7 @@ static unsigned qib_lookup_pkey(struct qib_ibport *ibp, u16 pkey)
426 * Called at interrupt level. 432 * Called at interrupt level.
427 */ 433 */
428void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr, 434void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
429 int has_grh, void *data, u32 tlen, struct qib_qp *qp) 435 int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
430{ 436{
431 struct qib_other_headers *ohdr; 437 struct qib_other_headers *ohdr;
432 int opcode; 438 int opcode;
@@ -446,7 +452,7 @@ void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
446 hdrsize = 8 + 40 + 12 + 8; /* LRH + GRH + BTH + DETH */ 452 hdrsize = 8 + 40 + 12 + 8; /* LRH + GRH + BTH + DETH */
447 } 453 }
448 qkey = be32_to_cpu(ohdr->u.ud.deth[0]); 454 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
449 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & QIB_QPN_MASK; 455 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
450 456
451 /* 457 /*
452 * Get the number of bytes the message was padded by 458 * Get the number of bytes the message was padded by
@@ -531,8 +537,8 @@ void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
531 /* 537 /*
532 * Get the next work request entry to find where to put the data. 538 * Get the next work request entry to find where to put the data.
533 */ 539 */
534 if (qp->r_flags & QIB_R_REUSE_SGE) 540 if (qp->r_flags & RVT_R_REUSE_SGE)
535 qp->r_flags &= ~QIB_R_REUSE_SGE; 541 qp->r_flags &= ~RVT_R_REUSE_SGE;
536 else { 542 else {
537 int ret; 543 int ret;
538 544
@@ -543,13 +549,13 @@ void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
543 } 549 }
544 if (!ret) { 550 if (!ret) {
545 if (qp->ibqp.qp_num == 0) 551 if (qp->ibqp.qp_num == 0)
546 ibp->n_vl15_dropped++; 552 ibp->rvp.n_vl15_dropped++;
547 return; 553 return;
548 } 554 }
549 } 555 }
550 /* Silently drop packets which are too big. */ 556 /* Silently drop packets which are too big. */
551 if (unlikely(wc.byte_len > qp->r_len)) { 557 if (unlikely(wc.byte_len > qp->r_len)) {
552 qp->r_flags |= QIB_R_REUSE_SGE; 558 qp->r_flags |= RVT_R_REUSE_SGE;
553 goto drop; 559 goto drop;
554 } 560 }
555 if (has_grh) { 561 if (has_grh) {
@@ -559,8 +565,8 @@ void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
559 } else 565 } else
560 qib_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1); 566 qib_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
561 qib_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh), 1); 567 qib_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh), 1);
562 qib_put_ss(&qp->r_sge); 568 rvt_put_ss(&qp->r_sge);
563 if (!test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) 569 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
564 return; 570 return;
565 wc.wr_id = qp->r_wr_id; 571 wc.wr_id = qp->r_wr_id;
566 wc.status = IB_WC_SUCCESS; 572 wc.status = IB_WC_SUCCESS;
@@ -576,15 +582,15 @@ void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
576 /* 582 /*
577 * Save the LMC lower bits if the destination LID is a unicast LID. 583 * Save the LMC lower bits if the destination LID is a unicast LID.
578 */ 584 */
579 wc.dlid_path_bits = dlid >= QIB_MULTICAST_LID_BASE ? 0 : 585 wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 :
580 dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1); 586 dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
581 wc.port_num = qp->port_num; 587 wc.port_num = qp->port_num;
582 /* Signal completion event if the solicited bit is set. */ 588 /* Signal completion event if the solicited bit is set. */
583 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 589 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
584 (ohdr->bth[0] & 590 (ohdr->bth[0] &
585 cpu_to_be32(IB_BTH_SOLICITED)) != 0); 591 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
586 return; 592 return;
587 593
588drop: 594drop:
589 ibp->n_pkt_drops++; 595 ibp->rvp.n_pkt_drops++;
590} 596}
diff --git a/drivers/infiniband/hw/qib/qib_verbs.c b/drivers/infiniband/hw/qib/qib_verbs.c
index baf1e42b6896..cbf6200e6afc 100644
--- a/drivers/infiniband/hw/qib/qib_verbs.c
+++ b/drivers/infiniband/hw/qib/qib_verbs.c
@@ -41,6 +41,7 @@
41#include <linux/mm.h> 41#include <linux/mm.h>
42#include <linux/random.h> 42#include <linux/random.h>
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <rdma/rdma_vt.h>
44 45
45#include "qib.h" 46#include "qib.h"
46#include "qib_common.h" 47#include "qib_common.h"
@@ -49,8 +50,8 @@ static unsigned int ib_qib_qp_table_size = 256;
49module_param_named(qp_table_size, ib_qib_qp_table_size, uint, S_IRUGO); 50module_param_named(qp_table_size, ib_qib_qp_table_size, uint, S_IRUGO);
50MODULE_PARM_DESC(qp_table_size, "QP table size"); 51MODULE_PARM_DESC(qp_table_size, "QP table size");
51 52
52unsigned int ib_qib_lkey_table_size = 16; 53static unsigned int qib_lkey_table_size = 16;
53module_param_named(lkey_table_size, ib_qib_lkey_table_size, uint, 54module_param_named(lkey_table_size, qib_lkey_table_size, uint,
54 S_IRUGO); 55 S_IRUGO);
55MODULE_PARM_DESC(lkey_table_size, 56MODULE_PARM_DESC(lkey_table_size,
56 "LKEY table size in bits (2^n, 1 <= n <= 23)"); 57 "LKEY table size in bits (2^n, 1 <= n <= 23)");
@@ -113,36 +114,6 @@ module_param_named(disable_sma, ib_qib_disable_sma, uint, S_IWUSR | S_IRUGO);
113MODULE_PARM_DESC(disable_sma, "Disable the SMA"); 114MODULE_PARM_DESC(disable_sma, "Disable the SMA");
114 115
115/* 116/*
116 * Note that it is OK to post send work requests in the SQE and ERR
117 * states; qib_do_send() will process them and generate error
118 * completions as per IB 1.2 C10-96.
119 */
120const int ib_qib_state_ops[IB_QPS_ERR + 1] = {
121 [IB_QPS_RESET] = 0,
122 [IB_QPS_INIT] = QIB_POST_RECV_OK,
123 [IB_QPS_RTR] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK,
124 [IB_QPS_RTS] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK |
125 QIB_POST_SEND_OK | QIB_PROCESS_SEND_OK |
126 QIB_PROCESS_NEXT_SEND_OK,
127 [IB_QPS_SQD] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK |
128 QIB_POST_SEND_OK | QIB_PROCESS_SEND_OK,
129 [IB_QPS_SQE] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK |
130 QIB_POST_SEND_OK | QIB_FLUSH_SEND,
131 [IB_QPS_ERR] = QIB_POST_RECV_OK | QIB_FLUSH_RECV |
132 QIB_POST_SEND_OK | QIB_FLUSH_SEND,
133};
134
135struct qib_ucontext {
136 struct ib_ucontext ibucontext;
137};
138
139static inline struct qib_ucontext *to_iucontext(struct ib_ucontext
140 *ibucontext)
141{
142 return container_of(ibucontext, struct qib_ucontext, ibucontext);
143}
144
145/*
146 * Translate ib_wr_opcode into ib_wc_opcode. 117 * Translate ib_wr_opcode into ib_wc_opcode.
147 */ 118 */
148const enum ib_wc_opcode ib_qib_wc_opcode[] = { 119const enum ib_wc_opcode ib_qib_wc_opcode[] = {
@@ -166,9 +137,9 @@ __be64 ib_qib_sys_image_guid;
166 * @data: the data to copy 137 * @data: the data to copy
167 * @length: the length of the data 138 * @length: the length of the data
168 */ 139 */
169void qib_copy_sge(struct qib_sge_state *ss, void *data, u32 length, int release) 140void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length, int release)
170{ 141{
171 struct qib_sge *sge = &ss->sge; 142 struct rvt_sge *sge = &ss->sge;
172 143
173 while (length) { 144 while (length) {
174 u32 len = sge->length; 145 u32 len = sge->length;
@@ -184,11 +155,11 @@ void qib_copy_sge(struct qib_sge_state *ss, void *data, u32 length, int release)
184 sge->sge_length -= len; 155 sge->sge_length -= len;
185 if (sge->sge_length == 0) { 156 if (sge->sge_length == 0) {
186 if (release) 157 if (release)
187 qib_put_mr(sge->mr); 158 rvt_put_mr(sge->mr);
188 if (--ss->num_sge) 159 if (--ss->num_sge)
189 *sge = *ss->sg_list++; 160 *sge = *ss->sg_list++;
190 } else if (sge->length == 0 && sge->mr->lkey) { 161 } else if (sge->length == 0 && sge->mr->lkey) {
191 if (++sge->n >= QIB_SEGSZ) { 162 if (++sge->n >= RVT_SEGSZ) {
192 if (++sge->m >= sge->mr->mapsz) 163 if (++sge->m >= sge->mr->mapsz)
193 break; 164 break;
194 sge->n = 0; 165 sge->n = 0;
@@ -208,9 +179,9 @@ void qib_copy_sge(struct qib_sge_state *ss, void *data, u32 length, int release)
208 * @ss: the SGE state 179 * @ss: the SGE state
209 * @length: the number of bytes to skip 180 * @length: the number of bytes to skip
210 */ 181 */
211void qib_skip_sge(struct qib_sge_state *ss, u32 length, int release) 182void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release)
212{ 183{
213 struct qib_sge *sge = &ss->sge; 184 struct rvt_sge *sge = &ss->sge;
214 185
215 while (length) { 186 while (length) {
216 u32 len = sge->length; 187 u32 len = sge->length;
@@ -225,11 +196,11 @@ void qib_skip_sge(struct qib_sge_state *ss, u32 length, int release)
225 sge->sge_length -= len; 196 sge->sge_length -= len;
226 if (sge->sge_length == 0) { 197 if (sge->sge_length == 0) {
227 if (release) 198 if (release)
228 qib_put_mr(sge->mr); 199 rvt_put_mr(sge->mr);
229 if (--ss->num_sge) 200 if (--ss->num_sge)
230 *sge = *ss->sg_list++; 201 *sge = *ss->sg_list++;
231 } else if (sge->length == 0 && sge->mr->lkey) { 202 } else if (sge->length == 0 && sge->mr->lkey) {
232 if (++sge->n >= QIB_SEGSZ) { 203 if (++sge->n >= RVT_SEGSZ) {
233 if (++sge->m >= sge->mr->mapsz) 204 if (++sge->m >= sge->mr->mapsz)
234 break; 205 break;
235 sge->n = 0; 206 sge->n = 0;
@@ -248,10 +219,10 @@ void qib_skip_sge(struct qib_sge_state *ss, u32 length, int release)
248 * Don't modify the qib_sge_state to get the count. 219 * Don't modify the qib_sge_state to get the count.
249 * Return zero if any of the segments is not aligned. 220 * Return zero if any of the segments is not aligned.
250 */ 221 */
251static u32 qib_count_sge(struct qib_sge_state *ss, u32 length) 222static u32 qib_count_sge(struct rvt_sge_state *ss, u32 length)
252{ 223{
253 struct qib_sge *sg_list = ss->sg_list; 224 struct rvt_sge *sg_list = ss->sg_list;
254 struct qib_sge sge = ss->sge; 225 struct rvt_sge sge = ss->sge;
255 u8 num_sge = ss->num_sge; 226 u8 num_sge = ss->num_sge;
256 u32 ndesc = 1; /* count the header */ 227 u32 ndesc = 1; /* count the header */
257 228
@@ -276,7 +247,7 @@ static u32 qib_count_sge(struct qib_sge_state *ss, u32 length)
276 if (--num_sge) 247 if (--num_sge)
277 sge = *sg_list++; 248 sge = *sg_list++;
278 } else if (sge.length == 0 && sge.mr->lkey) { 249 } else if (sge.length == 0 && sge.mr->lkey) {
279 if (++sge.n >= QIB_SEGSZ) { 250 if (++sge.n >= RVT_SEGSZ) {
280 if (++sge.m >= sge.mr->mapsz) 251 if (++sge.m >= sge.mr->mapsz)
281 break; 252 break;
282 sge.n = 0; 253 sge.n = 0;
@@ -294,9 +265,9 @@ static u32 qib_count_sge(struct qib_sge_state *ss, u32 length)
294/* 265/*
295 * Copy from the SGEs to the data buffer. 266 * Copy from the SGEs to the data buffer.
296 */ 267 */
297static void qib_copy_from_sge(void *data, struct qib_sge_state *ss, u32 length) 268static void qib_copy_from_sge(void *data, struct rvt_sge_state *ss, u32 length)
298{ 269{
299 struct qib_sge *sge = &ss->sge; 270 struct rvt_sge *sge = &ss->sge;
300 271
301 while (length) { 272 while (length) {
302 u32 len = sge->length; 273 u32 len = sge->length;
@@ -314,7 +285,7 @@ static void qib_copy_from_sge(void *data, struct qib_sge_state *ss, u32 length)
314 if (--ss->num_sge) 285 if (--ss->num_sge)
315 *sge = *ss->sg_list++; 286 *sge = *ss->sg_list++;
316 } else if (sge->length == 0 && sge->mr->lkey) { 287 } else if (sge->length == 0 && sge->mr->lkey) {
317 if (++sge->n >= QIB_SEGSZ) { 288 if (++sge->n >= RVT_SEGSZ) {
318 if (++sge->m >= sge->mr->mapsz) 289 if (++sge->m >= sge->mr->mapsz)
319 break; 290 break;
320 sge->n = 0; 291 sge->n = 0;
@@ -330,242 +301,6 @@ static void qib_copy_from_sge(void *data, struct qib_sge_state *ss, u32 length)
330} 301}
331 302
332/** 303/**
333 * qib_post_one_send - post one RC, UC, or UD send work request
334 * @qp: the QP to post on
335 * @wr: the work request to send
336 */
337static int qib_post_one_send(struct qib_qp *qp, struct ib_send_wr *wr,
338 int *scheduled)
339{
340 struct qib_swqe *wqe;
341 u32 next;
342 int i;
343 int j;
344 int acc;
345 int ret;
346 unsigned long flags;
347 struct qib_lkey_table *rkt;
348 struct qib_pd *pd;
349 int avoid_schedule = 0;
350
351 spin_lock_irqsave(&qp->s_lock, flags);
352
353 /* Check that state is OK to post send. */
354 if (unlikely(!(ib_qib_state_ops[qp->state] & QIB_POST_SEND_OK)))
355 goto bail_inval;
356
357 /* IB spec says that num_sge == 0 is OK. */
358 if (wr->num_sge > qp->s_max_sge)
359 goto bail_inval;
360
361 /*
362 * Don't allow RDMA reads or atomic operations on UC or
363 * undefined operations.
364 * Make sure buffer is large enough to hold the result for atomics.
365 */
366 if (wr->opcode == IB_WR_REG_MR) {
367 if (qib_reg_mr(qp, reg_wr(wr)))
368 goto bail_inval;
369 } else if (qp->ibqp.qp_type == IB_QPT_UC) {
370 if ((unsigned) wr->opcode >= IB_WR_RDMA_READ)
371 goto bail_inval;
372 } else if (qp->ibqp.qp_type != IB_QPT_RC) {
373 /* Check IB_QPT_SMI, IB_QPT_GSI, IB_QPT_UD opcode */
374 if (wr->opcode != IB_WR_SEND &&
375 wr->opcode != IB_WR_SEND_WITH_IMM)
376 goto bail_inval;
377 /* Check UD destination address PD */
378 if (qp->ibqp.pd != ud_wr(wr)->ah->pd)
379 goto bail_inval;
380 } else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD)
381 goto bail_inval;
382 else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
383 (wr->num_sge == 0 ||
384 wr->sg_list[0].length < sizeof(u64) ||
385 wr->sg_list[0].addr & (sizeof(u64) - 1)))
386 goto bail_inval;
387 else if (wr->opcode >= IB_WR_RDMA_READ && !qp->s_max_rd_atomic)
388 goto bail_inval;
389
390 next = qp->s_head + 1;
391 if (next >= qp->s_size)
392 next = 0;
393 if (next == qp->s_last) {
394 ret = -ENOMEM;
395 goto bail;
396 }
397
398 rkt = &to_idev(qp->ibqp.device)->lk_table;
399 pd = to_ipd(qp->ibqp.pd);
400 wqe = get_swqe_ptr(qp, qp->s_head);
401
402 if (qp->ibqp.qp_type != IB_QPT_UC &&
403 qp->ibqp.qp_type != IB_QPT_RC)
404 memcpy(&wqe->ud_wr, ud_wr(wr), sizeof(wqe->ud_wr));
405 else if (wr->opcode == IB_WR_REG_MR)
406 memcpy(&wqe->reg_wr, reg_wr(wr),
407 sizeof(wqe->reg_wr));
408 else if (wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
409 wr->opcode == IB_WR_RDMA_WRITE ||
410 wr->opcode == IB_WR_RDMA_READ)
411 memcpy(&wqe->rdma_wr, rdma_wr(wr), sizeof(wqe->rdma_wr));
412 else if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
413 wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD)
414 memcpy(&wqe->atomic_wr, atomic_wr(wr), sizeof(wqe->atomic_wr));
415 else
416 memcpy(&wqe->wr, wr, sizeof(wqe->wr));
417
418 wqe->length = 0;
419 j = 0;
420 if (wr->num_sge) {
421 acc = wr->opcode >= IB_WR_RDMA_READ ?
422 IB_ACCESS_LOCAL_WRITE : 0;
423 for (i = 0; i < wr->num_sge; i++) {
424 u32 length = wr->sg_list[i].length;
425 int ok;
426
427 if (length == 0)
428 continue;
429 ok = qib_lkey_ok(rkt, pd, &wqe->sg_list[j],
430 &wr->sg_list[i], acc);
431 if (!ok)
432 goto bail_inval_free;
433 wqe->length += length;
434 j++;
435 }
436 wqe->wr.num_sge = j;
437 }
438 if (qp->ibqp.qp_type == IB_QPT_UC ||
439 qp->ibqp.qp_type == IB_QPT_RC) {
440 if (wqe->length > 0x80000000U)
441 goto bail_inval_free;
442 if (wqe->length <= qp->pmtu)
443 avoid_schedule = 1;
444 } else if (wqe->length > (dd_from_ibdev(qp->ibqp.device)->pport +
445 qp->port_num - 1)->ibmtu) {
446 goto bail_inval_free;
447 } else {
448 atomic_inc(&to_iah(ud_wr(wr)->ah)->refcount);
449 avoid_schedule = 1;
450 }
451 wqe->ssn = qp->s_ssn++;
452 qp->s_head = next;
453
454 ret = 0;
455 goto bail;
456
457bail_inval_free:
458 while (j) {
459 struct qib_sge *sge = &wqe->sg_list[--j];
460
461 qib_put_mr(sge->mr);
462 }
463bail_inval:
464 ret = -EINVAL;
465bail:
466 if (!ret && !wr->next && !avoid_schedule &&
467 !qib_sdma_empty(
468 dd_from_ibdev(qp->ibqp.device)->pport + qp->port_num - 1)) {
469 qib_schedule_send(qp);
470 *scheduled = 1;
471 }
472 spin_unlock_irqrestore(&qp->s_lock, flags);
473 return ret;
474}
475
476/**
477 * qib_post_send - post a send on a QP
478 * @ibqp: the QP to post the send on
479 * @wr: the list of work requests to post
480 * @bad_wr: the first bad WR is put here
481 *
482 * This may be called from interrupt context.
483 */
484static int qib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
485 struct ib_send_wr **bad_wr)
486{
487 struct qib_qp *qp = to_iqp(ibqp);
488 int err = 0;
489 int scheduled = 0;
490
491 for (; wr; wr = wr->next) {
492 err = qib_post_one_send(qp, wr, &scheduled);
493 if (err) {
494 *bad_wr = wr;
495 goto bail;
496 }
497 }
498
499 /* Try to do the send work in the caller's context. */
500 if (!scheduled)
501 qib_do_send(&qp->s_work);
502
503bail:
504 return err;
505}
506
507/**
508 * qib_post_receive - post a receive on a QP
509 * @ibqp: the QP to post the receive on
510 * @wr: the WR to post
511 * @bad_wr: the first bad WR is put here
512 *
513 * This may be called from interrupt context.
514 */
515static int qib_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
516 struct ib_recv_wr **bad_wr)
517{
518 struct qib_qp *qp = to_iqp(ibqp);
519 struct qib_rwq *wq = qp->r_rq.wq;
520 unsigned long flags;
521 int ret;
522
523 /* Check that state is OK to post receive. */
524 if (!(ib_qib_state_ops[qp->state] & QIB_POST_RECV_OK) || !wq) {
525 *bad_wr = wr;
526 ret = -EINVAL;
527 goto bail;
528 }
529
530 for (; wr; wr = wr->next) {
531 struct qib_rwqe *wqe;
532 u32 next;
533 int i;
534
535 if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
536 *bad_wr = wr;
537 ret = -EINVAL;
538 goto bail;
539 }
540
541 spin_lock_irqsave(&qp->r_rq.lock, flags);
542 next = wq->head + 1;
543 if (next >= qp->r_rq.size)
544 next = 0;
545 if (next == wq->tail) {
546 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
547 *bad_wr = wr;
548 ret = -ENOMEM;
549 goto bail;
550 }
551
552 wqe = get_rwqe_ptr(&qp->r_rq, wq->head);
553 wqe->wr_id = wr->wr_id;
554 wqe->num_sge = wr->num_sge;
555 for (i = 0; i < wr->num_sge; i++)
556 wqe->sg_list[i] = wr->sg_list[i];
557 /* Make sure queue entry is written before the head index. */
558 smp_wmb();
559 wq->head = next;
560 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
561 }
562 ret = 0;
563
564bail:
565 return ret;
566}
567
568/**
569 * qib_qp_rcv - processing an incoming packet on a QP 304 * qib_qp_rcv - processing an incoming packet on a QP
570 * @rcd: the context pointer 305 * @rcd: the context pointer
571 * @hdr: the packet header 306 * @hdr: the packet header
@@ -579,15 +314,15 @@ bail:
579 * Called at interrupt level. 314 * Called at interrupt level.
580 */ 315 */
581static void qib_qp_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr, 316static void qib_qp_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
582 int has_grh, void *data, u32 tlen, struct qib_qp *qp) 317 int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
583{ 318{
584 struct qib_ibport *ibp = &rcd->ppd->ibport_data; 319 struct qib_ibport *ibp = &rcd->ppd->ibport_data;
585 320
586 spin_lock(&qp->r_lock); 321 spin_lock(&qp->r_lock);
587 322
588 /* Check for valid receive state. */ 323 /* Check for valid receive state. */
589 if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) { 324 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
590 ibp->n_pkt_drops++; 325 ibp->rvp.n_pkt_drops++;
591 goto unlock; 326 goto unlock;
592 } 327 }
593 328
@@ -632,8 +367,10 @@ void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen)
632 struct qib_pportdata *ppd = rcd->ppd; 367 struct qib_pportdata *ppd = rcd->ppd;
633 struct qib_ibport *ibp = &ppd->ibport_data; 368 struct qib_ibport *ibp = &ppd->ibport_data;
634 struct qib_ib_header *hdr = rhdr; 369 struct qib_ib_header *hdr = rhdr;
370 struct qib_devdata *dd = ppd->dd;
371 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
635 struct qib_other_headers *ohdr; 372 struct qib_other_headers *ohdr;
636 struct qib_qp *qp; 373 struct rvt_qp *qp;
637 u32 qp_num; 374 u32 qp_num;
638 int lnh; 375 int lnh;
639 u8 opcode; 376 u8 opcode;
@@ -645,7 +382,7 @@ void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen)
645 382
646 /* Check for a valid destination LID (see ch. 7.11.1). */ 383 /* Check for a valid destination LID (see ch. 7.11.1). */
647 lid = be16_to_cpu(hdr->lrh[1]); 384 lid = be16_to_cpu(hdr->lrh[1]);
648 if (lid < QIB_MULTICAST_LID_BASE) { 385 if (lid < be16_to_cpu(IB_MULTICAST_LID_BASE)) {
649 lid &= ~((1 << ppd->lmc) - 1); 386 lid &= ~((1 << ppd->lmc) - 1);
650 if (unlikely(lid != ppd->lid)) 387 if (unlikely(lid != ppd->lid))
651 goto drop; 388 goto drop;
@@ -674,50 +411,40 @@ void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen)
674#endif 411#endif
675 412
676 /* Get the destination QP number. */ 413 /* Get the destination QP number. */
677 qp_num = be32_to_cpu(ohdr->bth[1]) & QIB_QPN_MASK; 414 qp_num = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
678 if (qp_num == QIB_MULTICAST_QPN) { 415 if (qp_num == QIB_MULTICAST_QPN) {
679 struct qib_mcast *mcast; 416 struct rvt_mcast *mcast;
680 struct qib_mcast_qp *p; 417 struct rvt_mcast_qp *p;
681 418
682 if (lnh != QIB_LRH_GRH) 419 if (lnh != QIB_LRH_GRH)
683 goto drop; 420 goto drop;
684 mcast = qib_mcast_find(ibp, &hdr->u.l.grh.dgid); 421 mcast = rvt_mcast_find(&ibp->rvp, &hdr->u.l.grh.dgid);
685 if (mcast == NULL) 422 if (mcast == NULL)
686 goto drop; 423 goto drop;
687 this_cpu_inc(ibp->pmastats->n_multicast_rcv); 424 this_cpu_inc(ibp->pmastats->n_multicast_rcv);
688 list_for_each_entry_rcu(p, &mcast->qp_list, list) 425 list_for_each_entry_rcu(p, &mcast->qp_list, list)
689 qib_qp_rcv(rcd, hdr, 1, data, tlen, p->qp); 426 qib_qp_rcv(rcd, hdr, 1, data, tlen, p->qp);
690 /* 427 /*
691 * Notify qib_multicast_detach() if it is waiting for us 428 * Notify rvt_multicast_detach() if it is waiting for us
692 * to finish. 429 * to finish.
693 */ 430 */
694 if (atomic_dec_return(&mcast->refcount) <= 1) 431 if (atomic_dec_return(&mcast->refcount) <= 1)
695 wake_up(&mcast->wait); 432 wake_up(&mcast->wait);
696 } else { 433 } else {
697 if (rcd->lookaside_qp) { 434 rcu_read_lock();
698 if (rcd->lookaside_qpn != qp_num) { 435 qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
699 if (atomic_dec_and_test( 436 if (!qp) {
700 &rcd->lookaside_qp->refcount)) 437 rcu_read_unlock();
701 wake_up( 438 goto drop;
702 &rcd->lookaside_qp->wait);
703 rcd->lookaside_qp = NULL;
704 }
705 } 439 }
706 if (!rcd->lookaside_qp) {
707 qp = qib_lookup_qpn(ibp, qp_num);
708 if (!qp)
709 goto drop;
710 rcd->lookaside_qp = qp;
711 rcd->lookaside_qpn = qp_num;
712 } else
713 qp = rcd->lookaside_qp;
714 this_cpu_inc(ibp->pmastats->n_unicast_rcv); 440 this_cpu_inc(ibp->pmastats->n_unicast_rcv);
715 qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp); 441 qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp);
442 rcu_read_unlock();
716 } 443 }
717 return; 444 return;
718 445
719drop: 446drop:
720 ibp->n_pkt_drops++; 447 ibp->rvp.n_pkt_drops++;
721} 448}
722 449
723/* 450/*
@@ -728,23 +455,25 @@ static void mem_timer(unsigned long data)
728{ 455{
729 struct qib_ibdev *dev = (struct qib_ibdev *) data; 456 struct qib_ibdev *dev = (struct qib_ibdev *) data;
730 struct list_head *list = &dev->memwait; 457 struct list_head *list = &dev->memwait;
731 struct qib_qp *qp = NULL; 458 struct rvt_qp *qp = NULL;
459 struct qib_qp_priv *priv = NULL;
732 unsigned long flags; 460 unsigned long flags;
733 461
734 spin_lock_irqsave(&dev->pending_lock, flags); 462 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
735 if (!list_empty(list)) { 463 if (!list_empty(list)) {
736 qp = list_entry(list->next, struct qib_qp, iowait); 464 priv = list_entry(list->next, struct qib_qp_priv, iowait);
737 list_del_init(&qp->iowait); 465 qp = priv->owner;
466 list_del_init(&priv->iowait);
738 atomic_inc(&qp->refcount); 467 atomic_inc(&qp->refcount);
739 if (!list_empty(list)) 468 if (!list_empty(list))
740 mod_timer(&dev->mem_timer, jiffies + 1); 469 mod_timer(&dev->mem_timer, jiffies + 1);
741 } 470 }
742 spin_unlock_irqrestore(&dev->pending_lock, flags); 471 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
743 472
744 if (qp) { 473 if (qp) {
745 spin_lock_irqsave(&qp->s_lock, flags); 474 spin_lock_irqsave(&qp->s_lock, flags);
746 if (qp->s_flags & QIB_S_WAIT_KMEM) { 475 if (qp->s_flags & RVT_S_WAIT_KMEM) {
747 qp->s_flags &= ~QIB_S_WAIT_KMEM; 476 qp->s_flags &= ~RVT_S_WAIT_KMEM;
748 qib_schedule_send(qp); 477 qib_schedule_send(qp);
749 } 478 }
750 spin_unlock_irqrestore(&qp->s_lock, flags); 479 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -753,9 +482,9 @@ static void mem_timer(unsigned long data)
753 } 482 }
754} 483}
755 484
756static void update_sge(struct qib_sge_state *ss, u32 length) 485static void update_sge(struct rvt_sge_state *ss, u32 length)
757{ 486{
758 struct qib_sge *sge = &ss->sge; 487 struct rvt_sge *sge = &ss->sge;
759 488
760 sge->vaddr += length; 489 sge->vaddr += length;
761 sge->length -= length; 490 sge->length -= length;
@@ -764,7 +493,7 @@ static void update_sge(struct qib_sge_state *ss, u32 length)
764 if (--ss->num_sge) 493 if (--ss->num_sge)
765 *sge = *ss->sg_list++; 494 *sge = *ss->sg_list++;
766 } else if (sge->length == 0 && sge->mr->lkey) { 495 } else if (sge->length == 0 && sge->mr->lkey) {
767 if (++sge->n >= QIB_SEGSZ) { 496 if (++sge->n >= RVT_SEGSZ) {
768 if (++sge->m >= sge->mr->mapsz) 497 if (++sge->m >= sge->mr->mapsz)
769 return; 498 return;
770 sge->n = 0; 499 sge->n = 0;
@@ -810,7 +539,7 @@ static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
810} 539}
811#endif 540#endif
812 541
813static void copy_io(u32 __iomem *piobuf, struct qib_sge_state *ss, 542static void copy_io(u32 __iomem *piobuf, struct rvt_sge_state *ss,
814 u32 length, unsigned flush_wc) 543 u32 length, unsigned flush_wc)
815{ 544{
816 u32 extra = 0; 545 u32 extra = 0;
@@ -947,30 +676,31 @@ static void copy_io(u32 __iomem *piobuf, struct qib_sge_state *ss,
947} 676}
948 677
949static noinline struct qib_verbs_txreq *__get_txreq(struct qib_ibdev *dev, 678static noinline struct qib_verbs_txreq *__get_txreq(struct qib_ibdev *dev,
950 struct qib_qp *qp) 679 struct rvt_qp *qp)
951{ 680{
681 struct qib_qp_priv *priv = qp->priv;
952 struct qib_verbs_txreq *tx; 682 struct qib_verbs_txreq *tx;
953 unsigned long flags; 683 unsigned long flags;
954 684
955 spin_lock_irqsave(&qp->s_lock, flags); 685 spin_lock_irqsave(&qp->s_lock, flags);
956 spin_lock(&dev->pending_lock); 686 spin_lock(&dev->rdi.pending_lock);
957 687
958 if (!list_empty(&dev->txreq_free)) { 688 if (!list_empty(&dev->txreq_free)) {
959 struct list_head *l = dev->txreq_free.next; 689 struct list_head *l = dev->txreq_free.next;
960 690
961 list_del(l); 691 list_del(l);
962 spin_unlock(&dev->pending_lock); 692 spin_unlock(&dev->rdi.pending_lock);
963 spin_unlock_irqrestore(&qp->s_lock, flags); 693 spin_unlock_irqrestore(&qp->s_lock, flags);
964 tx = list_entry(l, struct qib_verbs_txreq, txreq.list); 694 tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
965 } else { 695 } else {
966 if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK && 696 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK &&
967 list_empty(&qp->iowait)) { 697 list_empty(&priv->iowait)) {
968 dev->n_txwait++; 698 dev->n_txwait++;
969 qp->s_flags |= QIB_S_WAIT_TX; 699 qp->s_flags |= RVT_S_WAIT_TX;
970 list_add_tail(&qp->iowait, &dev->txwait); 700 list_add_tail(&priv->iowait, &dev->txwait);
971 } 701 }
972 qp->s_flags &= ~QIB_S_BUSY; 702 qp->s_flags &= ~RVT_S_BUSY;
973 spin_unlock(&dev->pending_lock); 703 spin_unlock(&dev->rdi.pending_lock);
974 spin_unlock_irqrestore(&qp->s_lock, flags); 704 spin_unlock_irqrestore(&qp->s_lock, flags);
975 tx = ERR_PTR(-EBUSY); 705 tx = ERR_PTR(-EBUSY);
976 } 706 }
@@ -978,22 +708,22 @@ static noinline struct qib_verbs_txreq *__get_txreq(struct qib_ibdev *dev,
978} 708}
979 709
980static inline struct qib_verbs_txreq *get_txreq(struct qib_ibdev *dev, 710static inline struct qib_verbs_txreq *get_txreq(struct qib_ibdev *dev,
981 struct qib_qp *qp) 711 struct rvt_qp *qp)
982{ 712{
983 struct qib_verbs_txreq *tx; 713 struct qib_verbs_txreq *tx;
984 unsigned long flags; 714 unsigned long flags;
985 715
986 spin_lock_irqsave(&dev->pending_lock, flags); 716 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
987 /* assume the list non empty */ 717 /* assume the list non empty */
988 if (likely(!list_empty(&dev->txreq_free))) { 718 if (likely(!list_empty(&dev->txreq_free))) {
989 struct list_head *l = dev->txreq_free.next; 719 struct list_head *l = dev->txreq_free.next;
990 720
991 list_del(l); 721 list_del(l);
992 spin_unlock_irqrestore(&dev->pending_lock, flags); 722 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
993 tx = list_entry(l, struct qib_verbs_txreq, txreq.list); 723 tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
994 } else { 724 } else {
995 /* call slow path to get the extra lock */ 725 /* call slow path to get the extra lock */
996 spin_unlock_irqrestore(&dev->pending_lock, flags); 726 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
997 tx = __get_txreq(dev, qp); 727 tx = __get_txreq(dev, qp);
998 } 728 }
999 return tx; 729 return tx;
@@ -1002,16 +732,15 @@ static inline struct qib_verbs_txreq *get_txreq(struct qib_ibdev *dev,
1002void qib_put_txreq(struct qib_verbs_txreq *tx) 732void qib_put_txreq(struct qib_verbs_txreq *tx)
1003{ 733{
1004 struct qib_ibdev *dev; 734 struct qib_ibdev *dev;
1005 struct qib_qp *qp; 735 struct rvt_qp *qp;
736 struct qib_qp_priv *priv;
1006 unsigned long flags; 737 unsigned long flags;
1007 738
1008 qp = tx->qp; 739 qp = tx->qp;
1009 dev = to_idev(qp->ibqp.device); 740 dev = to_idev(qp->ibqp.device);
1010 741
1011 if (atomic_dec_and_test(&qp->refcount))
1012 wake_up(&qp->wait);
1013 if (tx->mr) { 742 if (tx->mr) {
1014 qib_put_mr(tx->mr); 743 rvt_put_mr(tx->mr);
1015 tx->mr = NULL; 744 tx->mr = NULL;
1016 } 745 }
1017 if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF) { 746 if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF) {
@@ -1022,21 +751,23 @@ void qib_put_txreq(struct qib_verbs_txreq *tx)
1022 kfree(tx->align_buf); 751 kfree(tx->align_buf);
1023 } 752 }
1024 753
1025 spin_lock_irqsave(&dev->pending_lock, flags); 754 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
1026 755
1027 /* Put struct back on free list */ 756 /* Put struct back on free list */
1028 list_add(&tx->txreq.list, &dev->txreq_free); 757 list_add(&tx->txreq.list, &dev->txreq_free);
1029 758
1030 if (!list_empty(&dev->txwait)) { 759 if (!list_empty(&dev->txwait)) {
1031 /* Wake up first QP wanting a free struct */ 760 /* Wake up first QP wanting a free struct */
1032 qp = list_entry(dev->txwait.next, struct qib_qp, iowait); 761 priv = list_entry(dev->txwait.next, struct qib_qp_priv,
1033 list_del_init(&qp->iowait); 762 iowait);
763 qp = priv->owner;
764 list_del_init(&priv->iowait);
1034 atomic_inc(&qp->refcount); 765 atomic_inc(&qp->refcount);
1035 spin_unlock_irqrestore(&dev->pending_lock, flags); 766 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
1036 767
1037 spin_lock_irqsave(&qp->s_lock, flags); 768 spin_lock_irqsave(&qp->s_lock, flags);
1038 if (qp->s_flags & QIB_S_WAIT_TX) { 769 if (qp->s_flags & RVT_S_WAIT_TX) {
1039 qp->s_flags &= ~QIB_S_WAIT_TX; 770 qp->s_flags &= ~RVT_S_WAIT_TX;
1040 qib_schedule_send(qp); 771 qib_schedule_send(qp);
1041 } 772 }
1042 spin_unlock_irqrestore(&qp->s_lock, flags); 773 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -1044,7 +775,7 @@ void qib_put_txreq(struct qib_verbs_txreq *tx)
1044 if (atomic_dec_and_test(&qp->refcount)) 775 if (atomic_dec_and_test(&qp->refcount))
1045 wake_up(&qp->wait); 776 wake_up(&qp->wait);
1046 } else 777 } else
1047 spin_unlock_irqrestore(&dev->pending_lock, flags); 778 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
1048} 779}
1049 780
1050/* 781/*
@@ -1055,36 +786,39 @@ void qib_put_txreq(struct qib_verbs_txreq *tx)
1055 */ 786 */
1056void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail) 787void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail)
1057{ 788{
1058 struct qib_qp *qp, *nqp; 789 struct rvt_qp *qp, *nqp;
1059 struct qib_qp *qps[20]; 790 struct qib_qp_priv *qpp, *nqpp;
791 struct rvt_qp *qps[20];
1060 struct qib_ibdev *dev; 792 struct qib_ibdev *dev;
1061 unsigned i, n; 793 unsigned i, n;
1062 794
1063 n = 0; 795 n = 0;
1064 dev = &ppd->dd->verbs_dev; 796 dev = &ppd->dd->verbs_dev;
1065 spin_lock(&dev->pending_lock); 797 spin_lock(&dev->rdi.pending_lock);
1066 798
1067 /* Search wait list for first QP wanting DMA descriptors. */ 799 /* Search wait list for first QP wanting DMA descriptors. */
1068 list_for_each_entry_safe(qp, nqp, &dev->dmawait, iowait) { 800 list_for_each_entry_safe(qpp, nqpp, &dev->dmawait, iowait) {
801 qp = qpp->owner;
802 nqp = nqpp->owner;
1069 if (qp->port_num != ppd->port) 803 if (qp->port_num != ppd->port)
1070 continue; 804 continue;
1071 if (n == ARRAY_SIZE(qps)) 805 if (n == ARRAY_SIZE(qps))
1072 break; 806 break;
1073 if (qp->s_tx->txreq.sg_count > avail) 807 if (qpp->s_tx->txreq.sg_count > avail)
1074 break; 808 break;
1075 avail -= qp->s_tx->txreq.sg_count; 809 avail -= qpp->s_tx->txreq.sg_count;
1076 list_del_init(&qp->iowait); 810 list_del_init(&qpp->iowait);
1077 atomic_inc(&qp->refcount); 811 atomic_inc(&qp->refcount);
1078 qps[n++] = qp; 812 qps[n++] = qp;
1079 } 813 }
1080 814
1081 spin_unlock(&dev->pending_lock); 815 spin_unlock(&dev->rdi.pending_lock);
1082 816
1083 for (i = 0; i < n; i++) { 817 for (i = 0; i < n; i++) {
1084 qp = qps[i]; 818 qp = qps[i];
1085 spin_lock(&qp->s_lock); 819 spin_lock(&qp->s_lock);
1086 if (qp->s_flags & QIB_S_WAIT_DMA_DESC) { 820 if (qp->s_flags & RVT_S_WAIT_DMA_DESC) {
1087 qp->s_flags &= ~QIB_S_WAIT_DMA_DESC; 821 qp->s_flags &= ~RVT_S_WAIT_DMA_DESC;
1088 qib_schedule_send(qp); 822 qib_schedule_send(qp);
1089 } 823 }
1090 spin_unlock(&qp->s_lock); 824 spin_unlock(&qp->s_lock);
@@ -1100,7 +834,8 @@ static void sdma_complete(struct qib_sdma_txreq *cookie, int status)
1100{ 834{
1101 struct qib_verbs_txreq *tx = 835 struct qib_verbs_txreq *tx =
1102 container_of(cookie, struct qib_verbs_txreq, txreq); 836 container_of(cookie, struct qib_verbs_txreq, txreq);
1103 struct qib_qp *qp = tx->qp; 837 struct rvt_qp *qp = tx->qp;
838 struct qib_qp_priv *priv = qp->priv;
1104 839
1105 spin_lock(&qp->s_lock); 840 spin_lock(&qp->s_lock);
1106 if (tx->wqe) 841 if (tx->wqe)
@@ -1117,11 +852,11 @@ static void sdma_complete(struct qib_sdma_txreq *cookie, int status)
1117 } 852 }
1118 qib_rc_send_complete(qp, hdr); 853 qib_rc_send_complete(qp, hdr);
1119 } 854 }
1120 if (atomic_dec_and_test(&qp->s_dma_busy)) { 855 if (atomic_dec_and_test(&priv->s_dma_busy)) {
1121 if (qp->state == IB_QPS_RESET) 856 if (qp->state == IB_QPS_RESET)
1122 wake_up(&qp->wait_dma); 857 wake_up(&priv->wait_dma);
1123 else if (qp->s_flags & QIB_S_WAIT_DMA) { 858 else if (qp->s_flags & RVT_S_WAIT_DMA) {
1124 qp->s_flags &= ~QIB_S_WAIT_DMA; 859 qp->s_flags &= ~RVT_S_WAIT_DMA;
1125 qib_schedule_send(qp); 860 qib_schedule_send(qp);
1126 } 861 }
1127 } 862 }
@@ -1130,22 +865,23 @@ static void sdma_complete(struct qib_sdma_txreq *cookie, int status)
1130 qib_put_txreq(tx); 865 qib_put_txreq(tx);
1131} 866}
1132 867
1133static int wait_kmem(struct qib_ibdev *dev, struct qib_qp *qp) 868static int wait_kmem(struct qib_ibdev *dev, struct rvt_qp *qp)
1134{ 869{
870 struct qib_qp_priv *priv = qp->priv;
1135 unsigned long flags; 871 unsigned long flags;
1136 int ret = 0; 872 int ret = 0;
1137 873
1138 spin_lock_irqsave(&qp->s_lock, flags); 874 spin_lock_irqsave(&qp->s_lock, flags);
1139 if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) { 875 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
1140 spin_lock(&dev->pending_lock); 876 spin_lock(&dev->rdi.pending_lock);
1141 if (list_empty(&qp->iowait)) { 877 if (list_empty(&priv->iowait)) {
1142 if (list_empty(&dev->memwait)) 878 if (list_empty(&dev->memwait))
1143 mod_timer(&dev->mem_timer, jiffies + 1); 879 mod_timer(&dev->mem_timer, jiffies + 1);
1144 qp->s_flags |= QIB_S_WAIT_KMEM; 880 qp->s_flags |= RVT_S_WAIT_KMEM;
1145 list_add_tail(&qp->iowait, &dev->memwait); 881 list_add_tail(&priv->iowait, &dev->memwait);
1146 } 882 }
1147 spin_unlock(&dev->pending_lock); 883 spin_unlock(&dev->rdi.pending_lock);
1148 qp->s_flags &= ~QIB_S_BUSY; 884 qp->s_flags &= ~RVT_S_BUSY;
1149 ret = -EBUSY; 885 ret = -EBUSY;
1150 } 886 }
1151 spin_unlock_irqrestore(&qp->s_lock, flags); 887 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -1153,10 +889,11 @@ static int wait_kmem(struct qib_ibdev *dev, struct qib_qp *qp)
1153 return ret; 889 return ret;
1154} 890}
1155 891
1156static int qib_verbs_send_dma(struct qib_qp *qp, struct qib_ib_header *hdr, 892static int qib_verbs_send_dma(struct rvt_qp *qp, struct qib_ib_header *hdr,
1157 u32 hdrwords, struct qib_sge_state *ss, u32 len, 893 u32 hdrwords, struct rvt_sge_state *ss, u32 len,
1158 u32 plen, u32 dwords) 894 u32 plen, u32 dwords)
1159{ 895{
896 struct qib_qp_priv *priv = qp->priv;
1160 struct qib_ibdev *dev = to_idev(qp->ibqp.device); 897 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
1161 struct qib_devdata *dd = dd_from_dev(dev); 898 struct qib_devdata *dd = dd_from_dev(dev);
1162 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 899 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
@@ -1167,9 +904,9 @@ static int qib_verbs_send_dma(struct qib_qp *qp, struct qib_ib_header *hdr,
1167 u32 ndesc; 904 u32 ndesc;
1168 int ret; 905 int ret;
1169 906
1170 tx = qp->s_tx; 907 tx = priv->s_tx;
1171 if (tx) { 908 if (tx) {
1172 qp->s_tx = NULL; 909 priv->s_tx = NULL;
1173 /* resend previously constructed packet */ 910 /* resend previously constructed packet */
1174 ret = qib_sdma_verbs_send(ppd, tx->ss, tx->dwords, tx); 911 ret = qib_sdma_verbs_send(ppd, tx->ss, tx->dwords, tx);
1175 goto bail; 912 goto bail;
@@ -1182,7 +919,6 @@ static int qib_verbs_send_dma(struct qib_qp *qp, struct qib_ib_header *hdr,
1182 control = dd->f_setpbc_control(ppd, plen, qp->s_srate, 919 control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
1183 be16_to_cpu(hdr->lrh[0]) >> 12); 920 be16_to_cpu(hdr->lrh[0]) >> 12);
1184 tx->qp = qp; 921 tx->qp = qp;
1185 atomic_inc(&qp->refcount);
1186 tx->wqe = qp->s_wqe; 922 tx->wqe = qp->s_wqe;
1187 tx->mr = qp->s_rdma_mr; 923 tx->mr = qp->s_rdma_mr;
1188 if (qp->s_rdma_mr) 924 if (qp->s_rdma_mr)
@@ -1245,7 +981,7 @@ err_tx:
1245 qib_put_txreq(tx); 981 qib_put_txreq(tx);
1246 ret = wait_kmem(dev, qp); 982 ret = wait_kmem(dev, qp);
1247unaligned: 983unaligned:
1248 ibp->n_unaligned++; 984 ibp->rvp.n_unaligned++;
1249bail: 985bail:
1250 return ret; 986 return ret;
1251bail_tx: 987bail_tx:
@@ -1257,8 +993,9 @@ bail_tx:
1257 * If we are now in the error state, return zero to flush the 993 * If we are now in the error state, return zero to flush the
1258 * send work request. 994 * send work request.
1259 */ 995 */
1260static int no_bufs_available(struct qib_qp *qp) 996static int no_bufs_available(struct rvt_qp *qp)
1261{ 997{
998 struct qib_qp_priv *priv = qp->priv;
1262 struct qib_ibdev *dev = to_idev(qp->ibqp.device); 999 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
1263 struct qib_devdata *dd; 1000 struct qib_devdata *dd;
1264 unsigned long flags; 1001 unsigned long flags;
@@ -1271,25 +1008,25 @@ static int no_bufs_available(struct qib_qp *qp)
1271 * enabling the PIO avail interrupt. 1008 * enabling the PIO avail interrupt.
1272 */ 1009 */
1273 spin_lock_irqsave(&qp->s_lock, flags); 1010 spin_lock_irqsave(&qp->s_lock, flags);
1274 if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) { 1011 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
1275 spin_lock(&dev->pending_lock); 1012 spin_lock(&dev->rdi.pending_lock);
1276 if (list_empty(&qp->iowait)) { 1013 if (list_empty(&priv->iowait)) {
1277 dev->n_piowait++; 1014 dev->n_piowait++;
1278 qp->s_flags |= QIB_S_WAIT_PIO; 1015 qp->s_flags |= RVT_S_WAIT_PIO;
1279 list_add_tail(&qp->iowait, &dev->piowait); 1016 list_add_tail(&priv->iowait, &dev->piowait);
1280 dd = dd_from_dev(dev); 1017 dd = dd_from_dev(dev);
1281 dd->f_wantpiobuf_intr(dd, 1); 1018 dd->f_wantpiobuf_intr(dd, 1);
1282 } 1019 }
1283 spin_unlock(&dev->pending_lock); 1020 spin_unlock(&dev->rdi.pending_lock);
1284 qp->s_flags &= ~QIB_S_BUSY; 1021 qp->s_flags &= ~RVT_S_BUSY;
1285 ret = -EBUSY; 1022 ret = -EBUSY;
1286 } 1023 }
1287 spin_unlock_irqrestore(&qp->s_lock, flags); 1024 spin_unlock_irqrestore(&qp->s_lock, flags);
1288 return ret; 1025 return ret;
1289} 1026}
1290 1027
1291static int qib_verbs_send_pio(struct qib_qp *qp, struct qib_ib_header *ibhdr, 1028static int qib_verbs_send_pio(struct rvt_qp *qp, struct qib_ib_header *ibhdr,
1292 u32 hdrwords, struct qib_sge_state *ss, u32 len, 1029 u32 hdrwords, struct rvt_sge_state *ss, u32 len,
1293 u32 plen, u32 dwords) 1030 u32 plen, u32 dwords)
1294{ 1031{
1295 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device); 1032 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
@@ -1370,7 +1107,7 @@ done:
1370 } 1107 }
1371 qib_sendbuf_done(dd, pbufn); 1108 qib_sendbuf_done(dd, pbufn);
1372 if (qp->s_rdma_mr) { 1109 if (qp->s_rdma_mr) {
1373 qib_put_mr(qp->s_rdma_mr); 1110 rvt_put_mr(qp->s_rdma_mr);
1374 qp->s_rdma_mr = NULL; 1111 qp->s_rdma_mr = NULL;
1375 } 1112 }
1376 if (qp->s_wqe) { 1113 if (qp->s_wqe) {
@@ -1394,10 +1131,10 @@ done:
1394 * @len: the length of the packet in bytes 1131 * @len: the length of the packet in bytes
1395 * 1132 *
1396 * Return zero if packet is sent or queued OK. 1133 * Return zero if packet is sent or queued OK.
1397 * Return non-zero and clear qp->s_flags QIB_S_BUSY otherwise. 1134 * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise.
1398 */ 1135 */
1399int qib_verbs_send(struct qib_qp *qp, struct qib_ib_header *hdr, 1136int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
1400 u32 hdrwords, struct qib_sge_state *ss, u32 len) 1137 u32 hdrwords, struct rvt_sge_state *ss, u32 len)
1401{ 1138{
1402 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device); 1139 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1403 u32 plen; 1140 u32 plen;
@@ -1529,10 +1266,11 @@ void qib_ib_piobufavail(struct qib_devdata *dd)
1529{ 1266{
1530 struct qib_ibdev *dev = &dd->verbs_dev; 1267 struct qib_ibdev *dev = &dd->verbs_dev;
1531 struct list_head *list; 1268 struct list_head *list;
1532 struct qib_qp *qps[5]; 1269 struct rvt_qp *qps[5];
1533 struct qib_qp *qp; 1270 struct rvt_qp *qp;
1534 unsigned long flags; 1271 unsigned long flags;
1535 unsigned i, n; 1272 unsigned i, n;
1273 struct qib_qp_priv *priv;
1536 1274
1537 list = &dev->piowait; 1275 list = &dev->piowait;
1538 n = 0; 1276 n = 0;
@@ -1543,25 +1281,26 @@ void qib_ib_piobufavail(struct qib_devdata *dd)
1543 * could end up with QPs on the wait list with the interrupt 1281 * could end up with QPs on the wait list with the interrupt
1544 * disabled. 1282 * disabled.
1545 */ 1283 */
1546 spin_lock_irqsave(&dev->pending_lock, flags); 1284 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
1547 while (!list_empty(list)) { 1285 while (!list_empty(list)) {
1548 if (n == ARRAY_SIZE(qps)) 1286 if (n == ARRAY_SIZE(qps))
1549 goto full; 1287 goto full;
1550 qp = list_entry(list->next, struct qib_qp, iowait); 1288 priv = list_entry(list->next, struct qib_qp_priv, iowait);
1551 list_del_init(&qp->iowait); 1289 qp = priv->owner;
1290 list_del_init(&priv->iowait);
1552 atomic_inc(&qp->refcount); 1291 atomic_inc(&qp->refcount);
1553 qps[n++] = qp; 1292 qps[n++] = qp;
1554 } 1293 }
1555 dd->f_wantpiobuf_intr(dd, 0); 1294 dd->f_wantpiobuf_intr(dd, 0);
1556full: 1295full:
1557 spin_unlock_irqrestore(&dev->pending_lock, flags); 1296 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
1558 1297
1559 for (i = 0; i < n; i++) { 1298 for (i = 0; i < n; i++) {
1560 qp = qps[i]; 1299 qp = qps[i];
1561 1300
1562 spin_lock_irqsave(&qp->s_lock, flags); 1301 spin_lock_irqsave(&qp->s_lock, flags);
1563 if (qp->s_flags & QIB_S_WAIT_PIO) { 1302 if (qp->s_flags & RVT_S_WAIT_PIO) {
1564 qp->s_flags &= ~QIB_S_WAIT_PIO; 1303 qp->s_flags &= ~RVT_S_WAIT_PIO;
1565 qib_schedule_send(qp); 1304 qib_schedule_send(qp);
1566 } 1305 }
1567 spin_unlock_irqrestore(&qp->s_lock, flags); 1306 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -1572,82 +1311,24 @@ full:
1572 } 1311 }
1573} 1312}
1574 1313
1575static int qib_query_device(struct ib_device *ibdev, struct ib_device_attr *props, 1314static int qib_query_port(struct rvt_dev_info *rdi, u8 port_num,
1576 struct ib_udata *uhw)
1577{
1578 struct qib_devdata *dd = dd_from_ibdev(ibdev);
1579 struct qib_ibdev *dev = to_idev(ibdev);
1580
1581 if (uhw->inlen || uhw->outlen)
1582 return -EINVAL;
1583 memset(props, 0, sizeof(*props));
1584
1585 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1586 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1587 IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
1588 IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE;
1589 props->page_size_cap = PAGE_SIZE;
1590 props->vendor_id =
1591 QIB_SRC_OUI_1 << 16 | QIB_SRC_OUI_2 << 8 | QIB_SRC_OUI_3;
1592 props->vendor_part_id = dd->deviceid;
1593 props->hw_ver = dd->minrev;
1594 props->sys_image_guid = ib_qib_sys_image_guid;
1595 props->max_mr_size = ~0ULL;
1596 props->max_qp = ib_qib_max_qps;
1597 props->max_qp_wr = ib_qib_max_qp_wrs;
1598 props->max_sge = ib_qib_max_sges;
1599 props->max_sge_rd = ib_qib_max_sges;
1600 props->max_cq = ib_qib_max_cqs;
1601 props->max_ah = ib_qib_max_ahs;
1602 props->max_cqe = ib_qib_max_cqes;
1603 props->max_mr = dev->lk_table.max;
1604 props->max_fmr = dev->lk_table.max;
1605 props->max_map_per_fmr = 32767;
1606 props->max_pd = ib_qib_max_pds;
1607 props->max_qp_rd_atom = QIB_MAX_RDMA_ATOMIC;
1608 props->max_qp_init_rd_atom = 255;
1609 /* props->max_res_rd_atom */
1610 props->max_srq = ib_qib_max_srqs;
1611 props->max_srq_wr = ib_qib_max_srq_wrs;
1612 props->max_srq_sge = ib_qib_max_srq_sges;
1613 /* props->local_ca_ack_delay */
1614 props->atomic_cap = IB_ATOMIC_GLOB;
1615 props->max_pkeys = qib_get_npkeys(dd);
1616 props->max_mcast_grp = ib_qib_max_mcast_grps;
1617 props->max_mcast_qp_attach = ib_qib_max_mcast_qp_attached;
1618 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
1619 props->max_mcast_grp;
1620
1621 return 0;
1622}
1623
1624static int qib_query_port(struct ib_device *ibdev, u8 port,
1625 struct ib_port_attr *props) 1315 struct ib_port_attr *props)
1626{ 1316{
1627 struct qib_devdata *dd = dd_from_ibdev(ibdev); 1317 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
1628 struct qib_ibport *ibp = to_iport(ibdev, port); 1318 struct qib_devdata *dd = dd_from_dev(ibdev);
1629 struct qib_pportdata *ppd = ppd_from_ibp(ibp); 1319 struct qib_pportdata *ppd = &dd->pport[port_num - 1];
1630 enum ib_mtu mtu; 1320 enum ib_mtu mtu;
1631 u16 lid = ppd->lid; 1321 u16 lid = ppd->lid;
1632 1322
1633 memset(props, 0, sizeof(*props));
1634 props->lid = lid ? lid : be16_to_cpu(IB_LID_PERMISSIVE); 1323 props->lid = lid ? lid : be16_to_cpu(IB_LID_PERMISSIVE);
1635 props->lmc = ppd->lmc; 1324 props->lmc = ppd->lmc;
1636 props->sm_lid = ibp->sm_lid;
1637 props->sm_sl = ibp->sm_sl;
1638 props->state = dd->f_iblink_state(ppd->lastibcstat); 1325 props->state = dd->f_iblink_state(ppd->lastibcstat);
1639 props->phys_state = dd->f_ibphys_portstate(ppd->lastibcstat); 1326 props->phys_state = dd->f_ibphys_portstate(ppd->lastibcstat);
1640 props->port_cap_flags = ibp->port_cap_flags;
1641 props->gid_tbl_len = QIB_GUIDS_PER_PORT; 1327 props->gid_tbl_len = QIB_GUIDS_PER_PORT;
1642 props->max_msg_sz = 0x80000000;
1643 props->pkey_tbl_len = qib_get_npkeys(dd);
1644 props->bad_pkey_cntr = ibp->pkey_violations;
1645 props->qkey_viol_cntr = ibp->qkey_violations;
1646 props->active_width = ppd->link_width_active; 1328 props->active_width = ppd->link_width_active;
1647 /* See rate_show() */ 1329 /* See rate_show() */
1648 props->active_speed = ppd->link_speed_active; 1330 props->active_speed = ppd->link_speed_active;
1649 props->max_vl_num = qib_num_vls(ppd->vls_supported); 1331 props->max_vl_num = qib_num_vls(ppd->vls_supported);
1650 props->init_type_reply = 0;
1651 1332
1652 props->max_mtu = qib_ibmtu ? qib_ibmtu : IB_MTU_4096; 1333 props->max_mtu = qib_ibmtu ? qib_ibmtu : IB_MTU_4096;
1653 switch (ppd->ibmtu) { 1334 switch (ppd->ibmtu) {
@@ -1670,7 +1351,6 @@ static int qib_query_port(struct ib_device *ibdev, u8 port,
1670 mtu = IB_MTU_2048; 1351 mtu = IB_MTU_2048;
1671 } 1352 }
1672 props->active_mtu = mtu; 1353 props->active_mtu = mtu;
1673 props->subnet_timeout = ibp->subnet_timeout;
1674 1354
1675 return 0; 1355 return 0;
1676} 1356}
@@ -1714,185 +1394,70 @@ bail:
1714 return ret; 1394 return ret;
1715} 1395}
1716 1396
1717static int qib_modify_port(struct ib_device *ibdev, u8 port, 1397static int qib_shut_down_port(struct rvt_dev_info *rdi, u8 port_num)
1718 int port_modify_mask, struct ib_port_modify *props)
1719{ 1398{
1720 struct qib_ibport *ibp = to_iport(ibdev, port); 1399 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
1721 struct qib_pportdata *ppd = ppd_from_ibp(ibp); 1400 struct qib_devdata *dd = dd_from_dev(ibdev);
1722 1401 struct qib_pportdata *ppd = &dd->pport[port_num - 1];
1723 ibp->port_cap_flags |= props->set_port_cap_mask;
1724 ibp->port_cap_flags &= ~props->clr_port_cap_mask;
1725 if (props->set_port_cap_mask || props->clr_port_cap_mask)
1726 qib_cap_mask_chg(ibp);
1727 if (port_modify_mask & IB_PORT_SHUTDOWN)
1728 qib_set_linkstate(ppd, QIB_IB_LINKDOWN);
1729 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
1730 ibp->qkey_violations = 0;
1731 return 0;
1732}
1733
1734static int qib_query_gid(struct ib_device *ibdev, u8 port,
1735 int index, union ib_gid *gid)
1736{
1737 struct qib_devdata *dd = dd_from_ibdev(ibdev);
1738 int ret = 0;
1739
1740 if (!port || port > dd->num_pports)
1741 ret = -EINVAL;
1742 else {
1743 struct qib_ibport *ibp = to_iport(ibdev, port);
1744 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1745
1746 gid->global.subnet_prefix = ibp->gid_prefix;
1747 if (index == 0)
1748 gid->global.interface_id = ppd->guid;
1749 else if (index < QIB_GUIDS_PER_PORT)
1750 gid->global.interface_id = ibp->guids[index - 1];
1751 else
1752 ret = -EINVAL;
1753 }
1754
1755 return ret;
1756}
1757 1402
1758static struct ib_pd *qib_alloc_pd(struct ib_device *ibdev, 1403 qib_set_linkstate(ppd, QIB_IB_LINKDOWN);
1759 struct ib_ucontext *context,
1760 struct ib_udata *udata)
1761{
1762 struct qib_ibdev *dev = to_idev(ibdev);
1763 struct qib_pd *pd;
1764 struct ib_pd *ret;
1765 1404
1766 /* 1405 return 0;
1767 * This is actually totally arbitrary. Some correctness tests
1768 * assume there's a maximum number of PDs that can be allocated.
1769 * We don't actually have this limit, but we fail the test if
1770 * we allow allocations of more than we report for this value.
1771 */
1772
1773 pd = kmalloc(sizeof(*pd), GFP_KERNEL);
1774 if (!pd) {
1775 ret = ERR_PTR(-ENOMEM);
1776 goto bail;
1777 }
1778
1779 spin_lock(&dev->n_pds_lock);
1780 if (dev->n_pds_allocated == ib_qib_max_pds) {
1781 spin_unlock(&dev->n_pds_lock);
1782 kfree(pd);
1783 ret = ERR_PTR(-ENOMEM);
1784 goto bail;
1785 }
1786
1787 dev->n_pds_allocated++;
1788 spin_unlock(&dev->n_pds_lock);
1789
1790 /* ib_alloc_pd() will initialize pd->ibpd. */
1791 pd->user = udata != NULL;
1792
1793 ret = &pd->ibpd;
1794
1795bail:
1796 return ret;
1797} 1406}
1798 1407
1799static int qib_dealloc_pd(struct ib_pd *ibpd) 1408static int qib_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
1409 int guid_index, __be64 *guid)
1800{ 1410{
1801 struct qib_pd *pd = to_ipd(ibpd); 1411 struct qib_ibport *ibp = container_of(rvp, struct qib_ibport, rvp);
1802 struct qib_ibdev *dev = to_idev(ibpd->device); 1412 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1803
1804 spin_lock(&dev->n_pds_lock);
1805 dev->n_pds_allocated--;
1806 spin_unlock(&dev->n_pds_lock);
1807 1413
1808 kfree(pd); 1414 if (guid_index == 0)
1415 *guid = ppd->guid;
1416 else if (guid_index < QIB_GUIDS_PER_PORT)
1417 *guid = ibp->guids[guid_index - 1];
1418 else
1419 return -EINVAL;
1809 1420
1810 return 0; 1421 return 0;
1811} 1422}
1812 1423
1813int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr) 1424int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr)
1814{ 1425{
1815 /* A multicast address requires a GRH (see ch. 8.4.1). */
1816 if (ah_attr->dlid >= QIB_MULTICAST_LID_BASE &&
1817 ah_attr->dlid != QIB_PERMISSIVE_LID &&
1818 !(ah_attr->ah_flags & IB_AH_GRH))
1819 goto bail;
1820 if ((ah_attr->ah_flags & IB_AH_GRH) &&
1821 ah_attr->grh.sgid_index >= QIB_GUIDS_PER_PORT)
1822 goto bail;
1823 if (ah_attr->dlid == 0)
1824 goto bail;
1825 if (ah_attr->port_num < 1 ||
1826 ah_attr->port_num > ibdev->phys_port_cnt)
1827 goto bail;
1828 if (ah_attr->static_rate != IB_RATE_PORT_CURRENT &&
1829 ib_rate_to_mult(ah_attr->static_rate) < 0)
1830 goto bail;
1831 if (ah_attr->sl > 15) 1426 if (ah_attr->sl > 15)
1832 goto bail; 1427 return -EINVAL;
1428
1833 return 0; 1429 return 0;
1834bail:
1835 return -EINVAL;
1836} 1430}
1837 1431
1838/** 1432static void qib_notify_new_ah(struct ib_device *ibdev,
1839 * qib_create_ah - create an address handle 1433 struct ib_ah_attr *ah_attr,
1840 * @pd: the protection domain 1434 struct rvt_ah *ah)
1841 * @ah_attr: the attributes of the AH
1842 *
1843 * This may be called from interrupt context.
1844 */
1845static struct ib_ah *qib_create_ah(struct ib_pd *pd,
1846 struct ib_ah_attr *ah_attr)
1847{ 1435{
1848 struct qib_ah *ah; 1436 struct qib_ibport *ibp;
1849 struct ib_ah *ret; 1437 struct qib_pportdata *ppd;
1850 struct qib_ibdev *dev = to_idev(pd->device);
1851 unsigned long flags;
1852 1438
1853 if (qib_check_ah(pd->device, ah_attr)) { 1439 /*
1854 ret = ERR_PTR(-EINVAL); 1440 * Do not trust reading anything from rvt_ah at this point as it is not
1855 goto bail; 1441 * done being setup. We can however modify things which we need to set.
1856 } 1442 */
1857
1858 ah = kmalloc(sizeof(*ah), GFP_ATOMIC);
1859 if (!ah) {
1860 ret = ERR_PTR(-ENOMEM);
1861 goto bail;
1862 }
1863
1864 spin_lock_irqsave(&dev->n_ahs_lock, flags);
1865 if (dev->n_ahs_allocated == ib_qib_max_ahs) {
1866 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1867 kfree(ah);
1868 ret = ERR_PTR(-ENOMEM);
1869 goto bail;
1870 }
1871
1872 dev->n_ahs_allocated++;
1873 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1874
1875 /* ib_create_ah() will initialize ah->ibah. */
1876 ah->attr = *ah_attr;
1877 atomic_set(&ah->refcount, 0);
1878
1879 ret = &ah->ibah;
1880 1443
1881bail: 1444 ibp = to_iport(ibdev, ah_attr->port_num);
1882 return ret; 1445 ppd = ppd_from_ibp(ibp);
1446 ah->vl = ibp->sl_to_vl[ah->attr.sl];
1447 ah->log_pmtu = ilog2(ppd->ibmtu);
1883} 1448}
1884 1449
1885struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid) 1450struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid)
1886{ 1451{
1887 struct ib_ah_attr attr; 1452 struct ib_ah_attr attr;
1888 struct ib_ah *ah = ERR_PTR(-EINVAL); 1453 struct ib_ah *ah = ERR_PTR(-EINVAL);
1889 struct qib_qp *qp0; 1454 struct rvt_qp *qp0;
1890 1455
1891 memset(&attr, 0, sizeof(attr)); 1456 memset(&attr, 0, sizeof(attr));
1892 attr.dlid = dlid; 1457 attr.dlid = dlid;
1893 attr.port_num = ppd_from_ibp(ibp)->port; 1458 attr.port_num = ppd_from_ibp(ibp)->port;
1894 rcu_read_lock(); 1459 rcu_read_lock();
1895 qp0 = rcu_dereference(ibp->qp0); 1460 qp0 = rcu_dereference(ibp->rvp.qp[0]);
1896 if (qp0) 1461 if (qp0)
1897 ah = ib_create_ah(qp0->ibqp.pd, &attr); 1462 ah = ib_create_ah(qp0->ibqp.pd, &attr);
1898 rcu_read_unlock(); 1463 rcu_read_unlock();
@@ -1900,51 +1465,6 @@ struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid)
1900} 1465}
1901 1466
1902/** 1467/**
1903 * qib_destroy_ah - destroy an address handle
1904 * @ibah: the AH to destroy
1905 *
1906 * This may be called from interrupt context.
1907 */
1908static int qib_destroy_ah(struct ib_ah *ibah)
1909{
1910 struct qib_ibdev *dev = to_idev(ibah->device);
1911 struct qib_ah *ah = to_iah(ibah);
1912 unsigned long flags;
1913
1914 if (atomic_read(&ah->refcount) != 0)
1915 return -EBUSY;
1916
1917 spin_lock_irqsave(&dev->n_ahs_lock, flags);
1918 dev->n_ahs_allocated--;
1919 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1920
1921 kfree(ah);
1922
1923 return 0;
1924}
1925
1926static int qib_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1927{
1928 struct qib_ah *ah = to_iah(ibah);
1929
1930 if (qib_check_ah(ibah->device, ah_attr))
1931 return -EINVAL;
1932
1933 ah->attr = *ah_attr;
1934
1935 return 0;
1936}
1937
1938static int qib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1939{
1940 struct qib_ah *ah = to_iah(ibah);
1941
1942 *ah_attr = ah->attr;
1943
1944 return 0;
1945}
1946
1947/**
1948 * qib_get_npkeys - return the size of the PKEY table for context 0 1468 * qib_get_npkeys - return the size of the PKEY table for context 0
1949 * @dd: the qlogic_ib device 1469 * @dd: the qlogic_ib device
1950 */ 1470 */
@@ -1973,75 +1493,27 @@ unsigned qib_get_pkey(struct qib_ibport *ibp, unsigned index)
1973 return ret; 1493 return ret;
1974} 1494}
1975 1495
1976static int qib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
1977 u16 *pkey)
1978{
1979 struct qib_devdata *dd = dd_from_ibdev(ibdev);
1980 int ret;
1981
1982 if (index >= qib_get_npkeys(dd)) {
1983 ret = -EINVAL;
1984 goto bail;
1985 }
1986
1987 *pkey = qib_get_pkey(to_iport(ibdev, port), index);
1988 ret = 0;
1989
1990bail:
1991 return ret;
1992}
1993
1994/**
1995 * qib_alloc_ucontext - allocate a ucontest
1996 * @ibdev: the infiniband device
1997 * @udata: not used by the QLogic_IB driver
1998 */
1999
2000static struct ib_ucontext *qib_alloc_ucontext(struct ib_device *ibdev,
2001 struct ib_udata *udata)
2002{
2003 struct qib_ucontext *context;
2004 struct ib_ucontext *ret;
2005
2006 context = kmalloc(sizeof(*context), GFP_KERNEL);
2007 if (!context) {
2008 ret = ERR_PTR(-ENOMEM);
2009 goto bail;
2010 }
2011
2012 ret = &context->ibucontext;
2013
2014bail:
2015 return ret;
2016}
2017
2018static int qib_dealloc_ucontext(struct ib_ucontext *context)
2019{
2020 kfree(to_iucontext(context));
2021 return 0;
2022}
2023
2024static void init_ibport(struct qib_pportdata *ppd) 1496static void init_ibport(struct qib_pportdata *ppd)
2025{ 1497{
2026 struct qib_verbs_counters cntrs; 1498 struct qib_verbs_counters cntrs;
2027 struct qib_ibport *ibp = &ppd->ibport_data; 1499 struct qib_ibport *ibp = &ppd->ibport_data;
2028 1500
2029 spin_lock_init(&ibp->lock); 1501 spin_lock_init(&ibp->rvp.lock);
2030 /* Set the prefix to the default value (see ch. 4.1.1) */ 1502 /* Set the prefix to the default value (see ch. 4.1.1) */
2031 ibp->gid_prefix = IB_DEFAULT_GID_PREFIX; 1503 ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX;
2032 ibp->sm_lid = be16_to_cpu(IB_LID_PERMISSIVE); 1504 ibp->rvp.sm_lid = be16_to_cpu(IB_LID_PERMISSIVE);
2033 ibp->port_cap_flags = IB_PORT_SYS_IMAGE_GUID_SUP | 1505 ibp->rvp.port_cap_flags = IB_PORT_SYS_IMAGE_GUID_SUP |
2034 IB_PORT_CLIENT_REG_SUP | IB_PORT_SL_MAP_SUP | 1506 IB_PORT_CLIENT_REG_SUP | IB_PORT_SL_MAP_SUP |
2035 IB_PORT_TRAP_SUP | IB_PORT_AUTO_MIGR_SUP | 1507 IB_PORT_TRAP_SUP | IB_PORT_AUTO_MIGR_SUP |
2036 IB_PORT_DR_NOTICE_SUP | IB_PORT_CAP_MASK_NOTICE_SUP | 1508 IB_PORT_DR_NOTICE_SUP | IB_PORT_CAP_MASK_NOTICE_SUP |
2037 IB_PORT_OTHER_LOCAL_CHANGES_SUP; 1509 IB_PORT_OTHER_LOCAL_CHANGES_SUP;
2038 if (ppd->dd->flags & QIB_HAS_LINK_LATENCY) 1510 if (ppd->dd->flags & QIB_HAS_LINK_LATENCY)
2039 ibp->port_cap_flags |= IB_PORT_LINK_LATENCY_SUP; 1511 ibp->rvp.port_cap_flags |= IB_PORT_LINK_LATENCY_SUP;
2040 ibp->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA; 1512 ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
2041 ibp->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA; 1513 ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
2042 ibp->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS; 1514 ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
2043 ibp->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS; 1515 ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
2044 ibp->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT; 1516 ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
2045 1517
2046 /* Snapshot current HW counters to "clear" them. */ 1518 /* Snapshot current HW counters to "clear" them. */
2047 qib_get_counters(ppd, &cntrs); 1519 qib_get_counters(ppd, &cntrs);
@@ -2061,26 +1533,55 @@ static void init_ibport(struct qib_pportdata *ppd)
2061 ibp->z_excessive_buffer_overrun_errors = 1533 ibp->z_excessive_buffer_overrun_errors =
2062 cntrs.excessive_buffer_overrun_errors; 1534 cntrs.excessive_buffer_overrun_errors;
2063 ibp->z_vl15_dropped = cntrs.vl15_dropped; 1535 ibp->z_vl15_dropped = cntrs.vl15_dropped;
2064 RCU_INIT_POINTER(ibp->qp0, NULL); 1536 RCU_INIT_POINTER(ibp->rvp.qp[0], NULL);
2065 RCU_INIT_POINTER(ibp->qp1, NULL); 1537 RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
2066} 1538}
2067 1539
2068static int qib_port_immutable(struct ib_device *ibdev, u8 port_num, 1540/**
2069 struct ib_port_immutable *immutable) 1541 * qib_fill_device_attr - Fill in rvt dev info device attributes.
1542 * @dd: the device data structure
1543 */
1544static void qib_fill_device_attr(struct qib_devdata *dd)
2070{ 1545{
2071 struct ib_port_attr attr; 1546 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
2072 int err;
2073
2074 err = qib_query_port(ibdev, port_num, &attr);
2075 if (err)
2076 return err;
2077 1547
2078 immutable->pkey_tbl_len = attr.pkey_tbl_len; 1548 memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props));
2079 immutable->gid_tbl_len = attr.gid_tbl_len;
2080 immutable->core_cap_flags = RDMA_CORE_PORT_IBA_IB;
2081 immutable->max_mad_size = IB_MGMT_MAD_SIZE;
2082 1549
2083 return 0; 1550 rdi->dparms.props.max_pd = ib_qib_max_pds;
1551 rdi->dparms.props.max_ah = ib_qib_max_ahs;
1552 rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1553 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1554 IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
1555 IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE;
1556 rdi->dparms.props.page_size_cap = PAGE_SIZE;
1557 rdi->dparms.props.vendor_id =
1558 QIB_SRC_OUI_1 << 16 | QIB_SRC_OUI_2 << 8 | QIB_SRC_OUI_3;
1559 rdi->dparms.props.vendor_part_id = dd->deviceid;
1560 rdi->dparms.props.hw_ver = dd->minrev;
1561 rdi->dparms.props.sys_image_guid = ib_qib_sys_image_guid;
1562 rdi->dparms.props.max_mr_size = ~0ULL;
1563 rdi->dparms.props.max_qp = ib_qib_max_qps;
1564 rdi->dparms.props.max_qp_wr = ib_qib_max_qp_wrs;
1565 rdi->dparms.props.max_sge = ib_qib_max_sges;
1566 rdi->dparms.props.max_sge_rd = ib_qib_max_sges;
1567 rdi->dparms.props.max_cq = ib_qib_max_cqs;
1568 rdi->dparms.props.max_cqe = ib_qib_max_cqes;
1569 rdi->dparms.props.max_ah = ib_qib_max_ahs;
1570 rdi->dparms.props.max_mr = rdi->lkey_table.max;
1571 rdi->dparms.props.max_fmr = rdi->lkey_table.max;
1572 rdi->dparms.props.max_map_per_fmr = 32767;
1573 rdi->dparms.props.max_qp_rd_atom = QIB_MAX_RDMA_ATOMIC;
1574 rdi->dparms.props.max_qp_init_rd_atom = 255;
1575 rdi->dparms.props.max_srq = ib_qib_max_srqs;
1576 rdi->dparms.props.max_srq_wr = ib_qib_max_srq_wrs;
1577 rdi->dparms.props.max_srq_sge = ib_qib_max_srq_sges;
1578 rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB;
1579 rdi->dparms.props.max_pkeys = qib_get_npkeys(dd);
1580 rdi->dparms.props.max_mcast_grp = ib_qib_max_mcast_grps;
1581 rdi->dparms.props.max_mcast_qp_attach = ib_qib_max_mcast_qp_attached;
1582 rdi->dparms.props.max_total_mcast_qp_attach =
1583 rdi->dparms.props.max_mcast_qp_attach *
1584 rdi->dparms.props.max_mcast_grp;
2084} 1585}
2085 1586
2086/** 1587/**
@@ -2091,68 +1592,20 @@ static int qib_port_immutable(struct ib_device *ibdev, u8 port_num,
2091int qib_register_ib_device(struct qib_devdata *dd) 1592int qib_register_ib_device(struct qib_devdata *dd)
2092{ 1593{
2093 struct qib_ibdev *dev = &dd->verbs_dev; 1594 struct qib_ibdev *dev = &dd->verbs_dev;
2094 struct ib_device *ibdev = &dev->ibdev; 1595 struct ib_device *ibdev = &dev->rdi.ibdev;
2095 struct qib_pportdata *ppd = dd->pport; 1596 struct qib_pportdata *ppd = dd->pport;
2096 unsigned i, lk_tab_size; 1597 unsigned i, ctxt;
2097 int ret; 1598 int ret;
2098 1599
2099 dev->qp_table_size = ib_qib_qp_table_size;
2100 get_random_bytes(&dev->qp_rnd, sizeof(dev->qp_rnd)); 1600 get_random_bytes(&dev->qp_rnd, sizeof(dev->qp_rnd));
2101 dev->qp_table = kmalloc_array(
2102 dev->qp_table_size,
2103 sizeof(*dev->qp_table),
2104 GFP_KERNEL);
2105 if (!dev->qp_table) {
2106 ret = -ENOMEM;
2107 goto err_qpt;
2108 }
2109 for (i = 0; i < dev->qp_table_size; i++)
2110 RCU_INIT_POINTER(dev->qp_table[i], NULL);
2111
2112 for (i = 0; i < dd->num_pports; i++) 1601 for (i = 0; i < dd->num_pports; i++)
2113 init_ibport(ppd + i); 1602 init_ibport(ppd + i);
2114 1603
2115 /* Only need to initialize non-zero fields. */ 1604 /* Only need to initialize non-zero fields. */
2116 spin_lock_init(&dev->qpt_lock); 1605 setup_timer(&dev->mem_timer, mem_timer, (unsigned long)dev);
2117 spin_lock_init(&dev->n_pds_lock); 1606
2118 spin_lock_init(&dev->n_ahs_lock); 1607 qpt_mask = dd->qpn_mask;
2119 spin_lock_init(&dev->n_cqs_lock);
2120 spin_lock_init(&dev->n_qps_lock);
2121 spin_lock_init(&dev->n_srqs_lock);
2122 spin_lock_init(&dev->n_mcast_grps_lock);
2123 init_timer(&dev->mem_timer);
2124 dev->mem_timer.function = mem_timer;
2125 dev->mem_timer.data = (unsigned long) dev;
2126
2127 qib_init_qpn_table(dd, &dev->qpn_table);
2128 1608
2129 /*
2130 * The top ib_qib_lkey_table_size bits are used to index the
2131 * table. The lower 8 bits can be owned by the user (copied from
2132 * the LKEY). The remaining bits act as a generation number or tag.
2133 */
2134 spin_lock_init(&dev->lk_table.lock);
2135 /* insure generation is at least 4 bits see keys.c */
2136 if (ib_qib_lkey_table_size > MAX_LKEY_TABLE_BITS) {
2137 qib_dev_warn(dd, "lkey bits %u too large, reduced to %u\n",
2138 ib_qib_lkey_table_size, MAX_LKEY_TABLE_BITS);
2139 ib_qib_lkey_table_size = MAX_LKEY_TABLE_BITS;
2140 }
2141 dev->lk_table.max = 1 << ib_qib_lkey_table_size;
2142 lk_tab_size = dev->lk_table.max * sizeof(*dev->lk_table.table);
2143 dev->lk_table.table = (struct qib_mregion __rcu **)
2144 vmalloc(lk_tab_size);
2145 if (dev->lk_table.table == NULL) {
2146 ret = -ENOMEM;
2147 goto err_lk;
2148 }
2149 RCU_INIT_POINTER(dev->dma_mr, NULL);
2150 for (i = 0; i < dev->lk_table.max; i++)
2151 RCU_INIT_POINTER(dev->lk_table.table[i], NULL);
2152 INIT_LIST_HEAD(&dev->pending_mmaps);
2153 spin_lock_init(&dev->pending_lock);
2154 dev->mmap_offset = PAGE_SIZE;
2155 spin_lock_init(&dev->mmap_offset_lock);
2156 INIT_LIST_HEAD(&dev->piowait); 1609 INIT_LIST_HEAD(&dev->piowait);
2157 INIT_LIST_HEAD(&dev->dmawait); 1610 INIT_LIST_HEAD(&dev->dmawait);
2158 INIT_LIST_HEAD(&dev->txwait); 1611 INIT_LIST_HEAD(&dev->txwait);
@@ -2194,110 +1647,91 @@ int qib_register_ib_device(struct qib_devdata *dd)
2194 strlcpy(ibdev->name, "qib%d", IB_DEVICE_NAME_MAX); 1647 strlcpy(ibdev->name, "qib%d", IB_DEVICE_NAME_MAX);
2195 ibdev->owner = THIS_MODULE; 1648 ibdev->owner = THIS_MODULE;
2196 ibdev->node_guid = ppd->guid; 1649 ibdev->node_guid = ppd->guid;
2197 ibdev->uverbs_abi_ver = QIB_UVERBS_ABI_VERSION;
2198 ibdev->uverbs_cmd_mask =
2199 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
2200 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
2201 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
2202 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
2203 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
2204 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
2205 (1ull << IB_USER_VERBS_CMD_MODIFY_AH) |
2206 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
2207 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
2208 (1ull << IB_USER_VERBS_CMD_REG_MR) |
2209 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
2210 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
2211 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
2212 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
2213 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
2214 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
2215 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
2216 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
2217 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
2218 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
2219 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
2220 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
2221 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
2222 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
2223 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
2224 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
2225 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
2226 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
2227 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
2228 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
2229 ibdev->node_type = RDMA_NODE_IB_CA;
2230 ibdev->phys_port_cnt = dd->num_pports; 1650 ibdev->phys_port_cnt = dd->num_pports;
2231 ibdev->num_comp_vectors = 1;
2232 ibdev->dma_device = &dd->pcidev->dev; 1651 ibdev->dma_device = &dd->pcidev->dev;
2233 ibdev->query_device = qib_query_device;
2234 ibdev->modify_device = qib_modify_device; 1652 ibdev->modify_device = qib_modify_device;
2235 ibdev->query_port = qib_query_port;
2236 ibdev->modify_port = qib_modify_port;
2237 ibdev->query_pkey = qib_query_pkey;
2238 ibdev->query_gid = qib_query_gid;
2239 ibdev->alloc_ucontext = qib_alloc_ucontext;
2240 ibdev->dealloc_ucontext = qib_dealloc_ucontext;
2241 ibdev->alloc_pd = qib_alloc_pd;
2242 ibdev->dealloc_pd = qib_dealloc_pd;
2243 ibdev->create_ah = qib_create_ah;
2244 ibdev->destroy_ah = qib_destroy_ah;
2245 ibdev->modify_ah = qib_modify_ah;
2246 ibdev->query_ah = qib_query_ah;
2247 ibdev->create_srq = qib_create_srq;
2248 ibdev->modify_srq = qib_modify_srq;
2249 ibdev->query_srq = qib_query_srq;
2250 ibdev->destroy_srq = qib_destroy_srq;
2251 ibdev->create_qp = qib_create_qp;
2252 ibdev->modify_qp = qib_modify_qp;
2253 ibdev->query_qp = qib_query_qp;
2254 ibdev->destroy_qp = qib_destroy_qp;
2255 ibdev->post_send = qib_post_send;
2256 ibdev->post_recv = qib_post_receive;
2257 ibdev->post_srq_recv = qib_post_srq_receive;
2258 ibdev->create_cq = qib_create_cq;
2259 ibdev->destroy_cq = qib_destroy_cq;
2260 ibdev->resize_cq = qib_resize_cq;
2261 ibdev->poll_cq = qib_poll_cq;
2262 ibdev->req_notify_cq = qib_req_notify_cq;
2263 ibdev->get_dma_mr = qib_get_dma_mr;
2264 ibdev->reg_user_mr = qib_reg_user_mr;
2265 ibdev->dereg_mr = qib_dereg_mr;
2266 ibdev->alloc_mr = qib_alloc_mr;
2267 ibdev->map_mr_sg = qib_map_mr_sg;
2268 ibdev->alloc_fmr = qib_alloc_fmr;
2269 ibdev->map_phys_fmr = qib_map_phys_fmr;
2270 ibdev->unmap_fmr = qib_unmap_fmr;
2271 ibdev->dealloc_fmr = qib_dealloc_fmr;
2272 ibdev->attach_mcast = qib_multicast_attach;
2273 ibdev->detach_mcast = qib_multicast_detach;
2274 ibdev->process_mad = qib_process_mad; 1653 ibdev->process_mad = qib_process_mad;
2275 ibdev->mmap = qib_mmap;
2276 ibdev->dma_ops = &qib_dma_mapping_ops;
2277 ibdev->get_port_immutable = qib_port_immutable;
2278 1654
2279 snprintf(ibdev->node_desc, sizeof(ibdev->node_desc), 1655 snprintf(ibdev->node_desc, sizeof(ibdev->node_desc),
2280 "Intel Infiniband HCA %s", init_utsname()->nodename); 1656 "Intel Infiniband HCA %s", init_utsname()->nodename);
2281 1657
2282 ret = ib_register_device(ibdev, qib_create_port_files); 1658 /*
2283 if (ret) 1659 * Fill in rvt info object.
2284 goto err_reg; 1660 */
1661 dd->verbs_dev.rdi.driver_f.port_callback = qib_create_port_files;
1662 dd->verbs_dev.rdi.driver_f.get_card_name = qib_get_card_name;
1663 dd->verbs_dev.rdi.driver_f.get_pci_dev = qib_get_pci_dev;
1664 dd->verbs_dev.rdi.driver_f.check_ah = qib_check_ah;
1665 dd->verbs_dev.rdi.driver_f.check_send_wqe = qib_check_send_wqe;
1666 dd->verbs_dev.rdi.driver_f.notify_new_ah = qib_notify_new_ah;
1667 dd->verbs_dev.rdi.driver_f.alloc_qpn = qib_alloc_qpn;
1668 dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qib_qp_priv_alloc;
1669 dd->verbs_dev.rdi.driver_f.qp_priv_free = qib_qp_priv_free;
1670 dd->verbs_dev.rdi.driver_f.free_all_qps = qib_free_all_qps;
1671 dd->verbs_dev.rdi.driver_f.notify_qp_reset = qib_notify_qp_reset;
1672 dd->verbs_dev.rdi.driver_f.do_send = qib_do_send;
1673 dd->verbs_dev.rdi.driver_f.schedule_send = qib_schedule_send;
1674 dd->verbs_dev.rdi.driver_f.quiesce_qp = qib_quiesce_qp;
1675 dd->verbs_dev.rdi.driver_f.stop_send_queue = qib_stop_send_queue;
1676 dd->verbs_dev.rdi.driver_f.flush_qp_waiters = qib_flush_qp_waiters;
1677 dd->verbs_dev.rdi.driver_f.notify_error_qp = qib_notify_error_qp;
1678 dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = qib_mtu_to_path_mtu;
1679 dd->verbs_dev.rdi.driver_f.mtu_from_qp = qib_mtu_from_qp;
1680 dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = qib_get_pmtu_from_attr;
1681 dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _qib_schedule_send;
1682 dd->verbs_dev.rdi.driver_f.query_port_state = qib_query_port;
1683 dd->verbs_dev.rdi.driver_f.shut_down_port = qib_shut_down_port;
1684 dd->verbs_dev.rdi.driver_f.cap_mask_chg = qib_cap_mask_chg;
1685 dd->verbs_dev.rdi.driver_f.notify_create_mad_agent =
1686 qib_notify_create_mad_agent;
1687 dd->verbs_dev.rdi.driver_f.notify_free_mad_agent =
1688 qib_notify_free_mad_agent;
1689
1690 dd->verbs_dev.rdi.dparms.max_rdma_atomic = QIB_MAX_RDMA_ATOMIC;
1691 dd->verbs_dev.rdi.driver_f.get_guid_be = qib_get_guid_be;
1692 dd->verbs_dev.rdi.dparms.lkey_table_size = qib_lkey_table_size;
1693 dd->verbs_dev.rdi.dparms.qp_table_size = ib_qib_qp_table_size;
1694 dd->verbs_dev.rdi.dparms.qpn_start = 1;
1695 dd->verbs_dev.rdi.dparms.qpn_res_start = QIB_KD_QP;
1696 dd->verbs_dev.rdi.dparms.qpn_res_end = QIB_KD_QP; /* Reserve one QP */
1697 dd->verbs_dev.rdi.dparms.qpn_inc = 1;
1698 dd->verbs_dev.rdi.dparms.qos_shift = 1;
1699 dd->verbs_dev.rdi.dparms.psn_mask = QIB_PSN_MASK;
1700 dd->verbs_dev.rdi.dparms.psn_shift = QIB_PSN_SHIFT;
1701 dd->verbs_dev.rdi.dparms.psn_modify_mask = QIB_PSN_MASK;
1702 dd->verbs_dev.rdi.dparms.nports = dd->num_pports;
1703 dd->verbs_dev.rdi.dparms.npkeys = qib_get_npkeys(dd);
1704 dd->verbs_dev.rdi.dparms.node = dd->assigned_node_id;
1705 dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_IBA_IB;
1706 dd->verbs_dev.rdi.dparms.max_mad_size = IB_MGMT_MAD_SIZE;
1707
1708 snprintf(dd->verbs_dev.rdi.dparms.cq_name,
1709 sizeof(dd->verbs_dev.rdi.dparms.cq_name),
1710 "qib_cq%d", dd->unit);
1711
1712 qib_fill_device_attr(dd);
1713
1714 ppd = dd->pport;
1715 for (i = 0; i < dd->num_pports; i++, ppd++) {
1716 ctxt = ppd->hw_pidx;
1717 rvt_init_port(&dd->verbs_dev.rdi,
1718 &ppd->ibport_data.rvp,
1719 i,
1720 dd->rcd[ctxt]->pkeys);
1721 }
2285 1722
2286 ret = qib_create_agents(dev); 1723 ret = rvt_register_device(&dd->verbs_dev.rdi);
2287 if (ret) 1724 if (ret)
2288 goto err_agents; 1725 goto err_tx;
2289 1726
2290 ret = qib_verbs_register_sysfs(dd); 1727 ret = qib_verbs_register_sysfs(dd);
2291 if (ret) 1728 if (ret)
2292 goto err_class; 1729 goto err_class;
2293 1730
2294 goto bail; 1731 return ret;
2295 1732
2296err_class: 1733err_class:
2297 qib_free_agents(dev); 1734 rvt_unregister_device(&dd->verbs_dev.rdi);
2298err_agents:
2299 ib_unregister_device(ibdev);
2300err_reg:
2301err_tx: 1735err_tx:
2302 while (!list_empty(&dev->txreq_free)) { 1736 while (!list_empty(&dev->txreq_free)) {
2303 struct list_head *l = dev->txreq_free.next; 1737 struct list_head *l = dev->txreq_free.next;
@@ -2313,27 +1747,17 @@ err_tx:
2313 sizeof(struct qib_pio_header), 1747 sizeof(struct qib_pio_header),
2314 dev->pio_hdrs, dev->pio_hdrs_phys); 1748 dev->pio_hdrs, dev->pio_hdrs_phys);
2315err_hdrs: 1749err_hdrs:
2316 vfree(dev->lk_table.table);
2317err_lk:
2318 kfree(dev->qp_table);
2319err_qpt:
2320 qib_dev_err(dd, "cannot register verbs: %d!\n", -ret); 1750 qib_dev_err(dd, "cannot register verbs: %d!\n", -ret);
2321bail:
2322 return ret; 1751 return ret;
2323} 1752}
2324 1753
2325void qib_unregister_ib_device(struct qib_devdata *dd) 1754void qib_unregister_ib_device(struct qib_devdata *dd)
2326{ 1755{
2327 struct qib_ibdev *dev = &dd->verbs_dev; 1756 struct qib_ibdev *dev = &dd->verbs_dev;
2328 struct ib_device *ibdev = &dev->ibdev;
2329 u32 qps_inuse;
2330 unsigned lk_tab_size;
2331 1757
2332 qib_verbs_unregister_sysfs(dd); 1758 qib_verbs_unregister_sysfs(dd);
2333 1759
2334 qib_free_agents(dev); 1760 rvt_unregister_device(&dd->verbs_dev.rdi);
2335
2336 ib_unregister_device(ibdev);
2337 1761
2338 if (!list_empty(&dev->piowait)) 1762 if (!list_empty(&dev->piowait))
2339 qib_dev_err(dd, "piowait list not empty!\n"); 1763 qib_dev_err(dd, "piowait list not empty!\n");
@@ -2343,16 +1767,8 @@ void qib_unregister_ib_device(struct qib_devdata *dd)
2343 qib_dev_err(dd, "txwait list not empty!\n"); 1767 qib_dev_err(dd, "txwait list not empty!\n");
2344 if (!list_empty(&dev->memwait)) 1768 if (!list_empty(&dev->memwait))
2345 qib_dev_err(dd, "memwait list not empty!\n"); 1769 qib_dev_err(dd, "memwait list not empty!\n");
2346 if (dev->dma_mr)
2347 qib_dev_err(dd, "DMA MR not NULL!\n");
2348
2349 qps_inuse = qib_free_all_qps(dd);
2350 if (qps_inuse)
2351 qib_dev_err(dd, "QP memory leak! %u still in use\n",
2352 qps_inuse);
2353 1770
2354 del_timer_sync(&dev->mem_timer); 1771 del_timer_sync(&dev->mem_timer);
2355 qib_free_qpn_table(&dev->qpn_table);
2356 while (!list_empty(&dev->txreq_free)) { 1772 while (!list_empty(&dev->txreq_free)) {
2357 struct list_head *l = dev->txreq_free.next; 1773 struct list_head *l = dev->txreq_free.next;
2358 struct qib_verbs_txreq *tx; 1774 struct qib_verbs_txreq *tx;
@@ -2366,21 +1782,36 @@ void qib_unregister_ib_device(struct qib_devdata *dd)
2366 dd->pport->sdma_descq_cnt * 1782 dd->pport->sdma_descq_cnt *
2367 sizeof(struct qib_pio_header), 1783 sizeof(struct qib_pio_header),
2368 dev->pio_hdrs, dev->pio_hdrs_phys); 1784 dev->pio_hdrs, dev->pio_hdrs_phys);
2369 lk_tab_size = dev->lk_table.max * sizeof(*dev->lk_table.table);
2370 vfree(dev->lk_table.table);
2371 kfree(dev->qp_table);
2372} 1785}
2373 1786
2374/* 1787/**
2375 * This must be called with s_lock held. 1788 * _qib_schedule_send - schedule progress
1789 * @qp - the qp
1790 *
1791 * This schedules progress w/o regard to the s_flags.
1792 *
1793 * It is only used in post send, which doesn't hold
1794 * the s_lock.
2376 */ 1795 */
2377void qib_schedule_send(struct qib_qp *qp) 1796void _qib_schedule_send(struct rvt_qp *qp)
2378{ 1797{
2379 if (qib_send_ok(qp)) { 1798 struct qib_ibport *ibp =
2380 struct qib_ibport *ibp = 1799 to_iport(qp->ibqp.device, qp->port_num);
2381 to_iport(qp->ibqp.device, qp->port_num); 1800 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
2382 struct qib_pportdata *ppd = ppd_from_ibp(ibp); 1801 struct qib_qp_priv *priv = qp->priv;
2383 1802
2384 queue_work(ppd->qib_wq, &qp->s_work); 1803 queue_work(ppd->qib_wq, &priv->s_work);
2385 } 1804}
1805
1806/**
1807 * qib_schedule_send - schedule progress
1808 * @qp - the qp
1809 *
1810 * This schedules qp progress. The s_lock
1811 * should be held.
1812 */
1813void qib_schedule_send(struct rvt_qp *qp)
1814{
1815 if (qib_send_ok(qp))
1816 _qib_schedule_send(qp);
2386} 1817}
diff --git a/drivers/infiniband/hw/qib/qib_verbs.h b/drivers/infiniband/hw/qib/qib_verbs.h
index 6c5e77753d85..4b76a8d59337 100644
--- a/drivers/infiniband/hw/qib/qib_verbs.h
+++ b/drivers/infiniband/hw/qib/qib_verbs.h
@@ -45,6 +45,8 @@
45#include <linux/completion.h> 45#include <linux/completion.h>
46#include <rdma/ib_pack.h> 46#include <rdma/ib_pack.h>
47#include <rdma/ib_user_verbs.h> 47#include <rdma/ib_user_verbs.h>
48#include <rdma/rdma_vt.h>
49#include <rdma/rdmavt_cq.h>
48 50
49struct qib_ctxtdata; 51struct qib_ctxtdata;
50struct qib_pportdata; 52struct qib_pportdata;
@@ -53,9 +55,7 @@ struct qib_verbs_txreq;
53 55
54#define QIB_MAX_RDMA_ATOMIC 16 56#define QIB_MAX_RDMA_ATOMIC 16
55#define QIB_GUIDS_PER_PORT 5 57#define QIB_GUIDS_PER_PORT 5
56 58#define QIB_PSN_SHIFT 8
57#define QPN_MAX (1 << 24)
58#define QPNMAP_ENTRIES (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
59 59
60/* 60/*
61 * Increment this value if any changes that break userspace ABI 61 * Increment this value if any changes that break userspace ABI
@@ -63,12 +63,6 @@ struct qib_verbs_txreq;
63 */ 63 */
64#define QIB_UVERBS_ABI_VERSION 2 64#define QIB_UVERBS_ABI_VERSION 2
65 65
66/*
67 * Define an ib_cq_notify value that is not valid so we know when CQ
68 * notifications are armed.
69 */
70#define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1)
71
72#define IB_SEQ_NAK (3 << 29) 66#define IB_SEQ_NAK (3 << 29)
73 67
74/* AETH NAK opcode values */ 68/* AETH NAK opcode values */
@@ -79,17 +73,6 @@ struct qib_verbs_txreq;
79#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63 73#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
80#define IB_NAK_INVALID_RD_REQUEST 0x64 74#define IB_NAK_INVALID_RD_REQUEST 0x64
81 75
82/* Flags for checking QP state (see ib_qib_state_ops[]) */
83#define QIB_POST_SEND_OK 0x01
84#define QIB_POST_RECV_OK 0x02
85#define QIB_PROCESS_RECV_OK 0x04
86#define QIB_PROCESS_SEND_OK 0x08
87#define QIB_PROCESS_NEXT_SEND_OK 0x10
88#define QIB_FLUSH_SEND 0x20
89#define QIB_FLUSH_RECV 0x40
90#define QIB_PROCESS_OR_FLUSH_SEND \
91 (QIB_PROCESS_SEND_OK | QIB_FLUSH_SEND)
92
93/* IB Performance Manager status values */ 76/* IB Performance Manager status values */
94#define IB_PMA_SAMPLE_STATUS_DONE 0x00 77#define IB_PMA_SAMPLE_STATUS_DONE 0x00
95#define IB_PMA_SAMPLE_STATUS_STARTED 0x01 78#define IB_PMA_SAMPLE_STATUS_STARTED 0x01
@@ -203,468 +186,21 @@ struct qib_pio_header {
203} __packed; 186} __packed;
204 187
205/* 188/*
206 * There is one struct qib_mcast for each multicast GID. 189 * qib specific data structure that will be hidden from rvt after the queue pair
207 * All attached QPs are then stored as a list of 190 * is made common.
208 * struct qib_mcast_qp.
209 */ 191 */
210struct qib_mcast_qp { 192struct qib_qp_priv {
211 struct list_head list; 193 struct qib_ib_header *s_hdr; /* next packet header to send */
212 struct qib_qp *qp;
213};
214
215struct qib_mcast {
216 struct rb_node rb_node;
217 union ib_gid mgid;
218 struct list_head qp_list;
219 wait_queue_head_t wait;
220 atomic_t refcount;
221 int n_attached;
222};
223
224/* Protection domain */
225struct qib_pd {
226 struct ib_pd ibpd;
227 int user; /* non-zero if created from user space */
228};
229
230/* Address Handle */
231struct qib_ah {
232 struct ib_ah ibah;
233 struct ib_ah_attr attr;
234 atomic_t refcount;
235};
236
237/*
238 * This structure is used by qib_mmap() to validate an offset
239 * when an mmap() request is made. The vm_area_struct then uses
240 * this as its vm_private_data.
241 */
242struct qib_mmap_info {
243 struct list_head pending_mmaps;
244 struct ib_ucontext *context;
245 void *obj;
246 __u64 offset;
247 struct kref ref;
248 unsigned size;
249};
250
251/*
252 * This structure is used to contain the head pointer, tail pointer,
253 * and completion queue entries as a single memory allocation so
254 * it can be mmap'ed into user space.
255 */
256struct qib_cq_wc {
257 u32 head; /* index of next entry to fill */
258 u32 tail; /* index of next ib_poll_cq() entry */
259 union {
260 /* these are actually size ibcq.cqe + 1 */
261 struct ib_uverbs_wc uqueue[0];
262 struct ib_wc kqueue[0];
263 };
264};
265
266/*
267 * The completion queue structure.
268 */
269struct qib_cq {
270 struct ib_cq ibcq;
271 struct kthread_work comptask;
272 struct qib_devdata *dd;
273 spinlock_t lock; /* protect changes in this struct */
274 u8 notify;
275 u8 triggered;
276 struct qib_cq_wc *queue;
277 struct qib_mmap_info *ip;
278};
279
280/*
281 * A segment is a linear region of low physical memory.
282 * XXX Maybe we should use phys addr here and kmap()/kunmap().
283 * Used by the verbs layer.
284 */
285struct qib_seg {
286 void *vaddr;
287 size_t length;
288};
289
290/* The number of qib_segs that fit in a page. */
291#define QIB_SEGSZ (PAGE_SIZE / sizeof(struct qib_seg))
292
293struct qib_segarray {
294 struct qib_seg segs[QIB_SEGSZ];
295};
296
297struct qib_mregion {
298 struct ib_pd *pd; /* shares refcnt of ibmr.pd */
299 u64 user_base; /* User's address for this region */
300 u64 iova; /* IB start address of this region */
301 size_t length;
302 u32 lkey;
303 u32 offset; /* offset (bytes) to start of region */
304 int access_flags;
305 u32 max_segs; /* number of qib_segs in all the arrays */
306 u32 mapsz; /* size of the map array */
307 u8 page_shift; /* 0 - non unform/non powerof2 sizes */
308 u8 lkey_published; /* in global table */
309 struct completion comp; /* complete when refcount goes to zero */
310 struct rcu_head list;
311 atomic_t refcount;
312 struct qib_segarray *map[0]; /* the segments */
313};
314
315/*
316 * These keep track of the copy progress within a memory region.
317 * Used by the verbs layer.
318 */
319struct qib_sge {
320 struct qib_mregion *mr;
321 void *vaddr; /* kernel virtual address of segment */
322 u32 sge_length; /* length of the SGE */
323 u32 length; /* remaining length of the segment */
324 u16 m; /* current index: mr->map[m] */
325 u16 n; /* current index: mr->map[m]->segs[n] */
326};
327
328/* Memory region */
329struct qib_mr {
330 struct ib_mr ibmr;
331 struct ib_umem *umem;
332 u64 *pages;
333 u32 npages;
334 struct qib_mregion mr; /* must be last */
335};
336
337/*
338 * Send work request queue entry.
339 * The size of the sg_list is determined when the QP is created and stored
340 * in qp->s_max_sge.
341 */
342struct qib_swqe {
343 union {
344 struct ib_send_wr wr; /* don't use wr.sg_list */
345 struct ib_ud_wr ud_wr;
346 struct ib_reg_wr reg_wr;
347 struct ib_rdma_wr rdma_wr;
348 struct ib_atomic_wr atomic_wr;
349 };
350 u32 psn; /* first packet sequence number */
351 u32 lpsn; /* last packet sequence number */
352 u32 ssn; /* send sequence number */
353 u32 length; /* total length of data in sg_list */
354 struct qib_sge sg_list[0];
355};
356
357/*
358 * Receive work request queue entry.
359 * The size of the sg_list is determined when the QP (or SRQ) is created
360 * and stored in qp->r_rq.max_sge (or srq->rq.max_sge).
361 */
362struct qib_rwqe {
363 u64 wr_id;
364 u8 num_sge;
365 struct ib_sge sg_list[0];
366};
367
368/*
369 * This structure is used to contain the head pointer, tail pointer,
370 * and receive work queue entries as a single memory allocation so
371 * it can be mmap'ed into user space.
372 * Note that the wq array elements are variable size so you can't
373 * just index into the array to get the N'th element;
374 * use get_rwqe_ptr() instead.
375 */
376struct qib_rwq {
377 u32 head; /* new work requests posted to the head */
378 u32 tail; /* receives pull requests from here. */
379 struct qib_rwqe wq[0];
380};
381
382struct qib_rq {
383 struct qib_rwq *wq;
384 u32 size; /* size of RWQE array */
385 u8 max_sge;
386 spinlock_t lock /* protect changes in this struct */
387 ____cacheline_aligned_in_smp;
388};
389
390struct qib_srq {
391 struct ib_srq ibsrq;
392 struct qib_rq rq;
393 struct qib_mmap_info *ip;
394 /* send signal when number of RWQEs < limit */
395 u32 limit;
396};
397
398struct qib_sge_state {
399 struct qib_sge *sg_list; /* next SGE to be used if any */
400 struct qib_sge sge; /* progress state for the current SGE */
401 u32 total_len;
402 u8 num_sge;
403};
404
405/*
406 * This structure holds the information that the send tasklet needs
407 * to send a RDMA read response or atomic operation.
408 */
409struct qib_ack_entry {
410 u8 opcode;
411 u8 sent;
412 u32 psn;
413 u32 lpsn;
414 union {
415 struct qib_sge rdma_sge;
416 u64 atomic_data;
417 };
418};
419
420/*
421 * Variables prefixed with s_ are for the requester (sender).
422 * Variables prefixed with r_ are for the responder (receiver).
423 * Variables prefixed with ack_ are for responder replies.
424 *
425 * Common variables are protected by both r_rq.lock and s_lock in that order
426 * which only happens in modify_qp() or changing the QP 'state'.
427 */
428struct qib_qp {
429 struct ib_qp ibqp;
430 /* read mostly fields above and below */
431 struct ib_ah_attr remote_ah_attr;
432 struct ib_ah_attr alt_ah_attr;
433 struct qib_qp __rcu *next; /* link list for QPN hash table */
434 struct qib_swqe *s_wq; /* send work queue */
435 struct qib_mmap_info *ip;
436 struct qib_ib_header *s_hdr; /* next packet header to send */
437 unsigned long timeout_jiffies; /* computed from timeout */
438
439 enum ib_mtu path_mtu;
440 u32 remote_qpn;
441 u32 pmtu; /* decoded from path_mtu */
442 u32 qkey; /* QKEY for this QP (for UD or RD) */
443 u32 s_size; /* send work queue size */
444 u32 s_rnr_timeout; /* number of milliseconds for RNR timeout */
445
446 u8 state; /* QP state */
447 u8 qp_access_flags;
448 u8 alt_timeout; /* Alternate path timeout for this QP */
449 u8 timeout; /* Timeout for this QP */
450 u8 s_srate;
451 u8 s_mig_state;
452 u8 port_num;
453 u8 s_pkey_index; /* PKEY index to use */
454 u8 s_alt_pkey_index; /* Alternate path PKEY index to use */
455 u8 r_max_rd_atomic; /* max number of RDMA read/atomic to receive */
456 u8 s_max_rd_atomic; /* max number of RDMA read/atomic to send */
457 u8 s_retry_cnt; /* number of times to retry */
458 u8 s_rnr_retry_cnt;
459 u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */
460 u8 s_max_sge; /* size of s_wq->sg_list */
461 u8 s_draining;
462
463 /* start of read/write fields */
464
465 atomic_t refcount ____cacheline_aligned_in_smp;
466 wait_queue_head_t wait;
467
468
469 struct qib_ack_entry s_ack_queue[QIB_MAX_RDMA_ATOMIC + 1]
470 ____cacheline_aligned_in_smp;
471 struct qib_sge_state s_rdma_read_sge;
472
473 spinlock_t r_lock ____cacheline_aligned_in_smp; /* used for APM */
474 unsigned long r_aflags;
475 u64 r_wr_id; /* ID for current receive WQE */
476 u32 r_ack_psn; /* PSN for next ACK or atomic ACK */
477 u32 r_len; /* total length of r_sge */
478 u32 r_rcv_len; /* receive data len processed */
479 u32 r_psn; /* expected rcv packet sequence number */
480 u32 r_msn; /* message sequence number */
481
482 u8 r_state; /* opcode of last packet received */
483 u8 r_flags;
484 u8 r_head_ack_queue; /* index into s_ack_queue[] */
485
486 struct list_head rspwait; /* link for waititing to respond */
487
488 struct qib_sge_state r_sge; /* current receive data */
489 struct qib_rq r_rq; /* receive work queue */
490
491 spinlock_t s_lock ____cacheline_aligned_in_smp;
492 struct qib_sge_state *s_cur_sge;
493 u32 s_flags;
494 struct qib_verbs_txreq *s_tx;
495 struct qib_swqe *s_wqe;
496 struct qib_sge_state s_sge; /* current send request data */
497 struct qib_mregion *s_rdma_mr;
498 atomic_t s_dma_busy;
499 u32 s_cur_size; /* size of send packet in bytes */
500 u32 s_len; /* total length of s_sge */
501 u32 s_rdma_read_len; /* total length of s_rdma_read_sge */
502 u32 s_next_psn; /* PSN for next request */
503 u32 s_last_psn; /* last response PSN processed */
504 u32 s_sending_psn; /* lowest PSN that is being sent */
505 u32 s_sending_hpsn; /* highest PSN that is being sent */
506 u32 s_psn; /* current packet sequence number */
507 u32 s_ack_rdma_psn; /* PSN for sending RDMA read responses */
508 u32 s_ack_psn; /* PSN for acking sends and RDMA writes */
509 u32 s_head; /* new entries added here */
510 u32 s_tail; /* next entry to process */
511 u32 s_cur; /* current work queue entry */
512 u32 s_acked; /* last un-ACK'ed entry */
513 u32 s_last; /* last completed entry */
514 u32 s_ssn; /* SSN of tail entry */
515 u32 s_lsn; /* limit sequence number (credit) */
516 u16 s_hdrwords; /* size of s_hdr in 32 bit words */
517 u16 s_rdma_ack_cnt;
518 u8 s_state; /* opcode of last packet sent */
519 u8 s_ack_state; /* opcode of packet to ACK */
520 u8 s_nak_state; /* non-zero if NAK is pending */
521 u8 r_nak_state; /* non-zero if NAK is pending */
522 u8 s_retry; /* requester retry counter */
523 u8 s_rnr_retry; /* requester RNR retry counter */
524 u8 s_num_rd_atomic; /* number of RDMA read/atomic pending */
525 u8 s_tail_ack_queue; /* index into s_ack_queue[] */
526
527 struct qib_sge_state s_ack_rdma_sge;
528 struct timer_list s_timer;
529 struct list_head iowait; /* link for wait PIO buf */ 194 struct list_head iowait; /* link for wait PIO buf */
530 195 atomic_t s_dma_busy;
196 struct qib_verbs_txreq *s_tx;
531 struct work_struct s_work; 197 struct work_struct s_work;
532
533 wait_queue_head_t wait_dma; 198 wait_queue_head_t wait_dma;
534 199 struct rvt_qp *owner;
535 struct qib_sge r_sg_list[0] /* verified SGEs */
536 ____cacheline_aligned_in_smp;
537}; 200};
538 201
539/*
540 * Atomic bit definitions for r_aflags.
541 */
542#define QIB_R_WRID_VALID 0
543#define QIB_R_REWIND_SGE 1
544
545/*
546 * Bit definitions for r_flags.
547 */
548#define QIB_R_REUSE_SGE 0x01
549#define QIB_R_RDMAR_SEQ 0x02
550#define QIB_R_RSP_NAK 0x04
551#define QIB_R_RSP_SEND 0x08
552#define QIB_R_COMM_EST 0x10
553
554/*
555 * Bit definitions for s_flags.
556 *
557 * QIB_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
558 * QIB_S_BUSY - send tasklet is processing the QP
559 * QIB_S_TIMER - the RC retry timer is active
560 * QIB_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
561 * QIB_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
562 * before processing the next SWQE
563 * QIB_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
564 * before processing the next SWQE
565 * QIB_S_WAIT_RNR - waiting for RNR timeout
566 * QIB_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
567 * QIB_S_WAIT_DMA - waiting for send DMA queue to drain before generating
568 * next send completion entry not via send DMA
569 * QIB_S_WAIT_PIO - waiting for a send buffer to be available
570 * QIB_S_WAIT_TX - waiting for a struct qib_verbs_txreq to be available
571 * QIB_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
572 * QIB_S_WAIT_KMEM - waiting for kernel memory to be available
573 * QIB_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
574 * QIB_S_WAIT_ACK - waiting for an ACK packet before sending more requests
575 * QIB_S_SEND_ONE - send one packet, request ACK, then wait for ACK
576 */
577#define QIB_S_SIGNAL_REQ_WR 0x0001
578#define QIB_S_BUSY 0x0002
579#define QIB_S_TIMER 0x0004
580#define QIB_S_RESP_PENDING 0x0008
581#define QIB_S_ACK_PENDING 0x0010
582#define QIB_S_WAIT_FENCE 0x0020
583#define QIB_S_WAIT_RDMAR 0x0040
584#define QIB_S_WAIT_RNR 0x0080
585#define QIB_S_WAIT_SSN_CREDIT 0x0100
586#define QIB_S_WAIT_DMA 0x0200
587#define QIB_S_WAIT_PIO 0x0400
588#define QIB_S_WAIT_TX 0x0800
589#define QIB_S_WAIT_DMA_DESC 0x1000
590#define QIB_S_WAIT_KMEM 0x2000
591#define QIB_S_WAIT_PSN 0x4000
592#define QIB_S_WAIT_ACK 0x8000
593#define QIB_S_SEND_ONE 0x10000
594#define QIB_S_UNLIMITED_CREDIT 0x20000
595
596/*
597 * Wait flags that would prevent any packet type from being sent.
598 */
599#define QIB_S_ANY_WAIT_IO (QIB_S_WAIT_PIO | QIB_S_WAIT_TX | \
600 QIB_S_WAIT_DMA_DESC | QIB_S_WAIT_KMEM)
601
602/*
603 * Wait flags that would prevent send work requests from making progress.
604 */
605#define QIB_S_ANY_WAIT_SEND (QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | \
606 QIB_S_WAIT_RNR | QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_DMA | \
607 QIB_S_WAIT_PSN | QIB_S_WAIT_ACK)
608
609#define QIB_S_ANY_WAIT (QIB_S_ANY_WAIT_IO | QIB_S_ANY_WAIT_SEND)
610
611#define QIB_PSN_CREDIT 16 202#define QIB_PSN_CREDIT 16
612 203
613/*
614 * Since struct qib_swqe is not a fixed size, we can't simply index into
615 * struct qib_qp.s_wq. This function does the array index computation.
616 */
617static inline struct qib_swqe *get_swqe_ptr(struct qib_qp *qp,
618 unsigned n)
619{
620 return (struct qib_swqe *)((char *)qp->s_wq +
621 (sizeof(struct qib_swqe) +
622 qp->s_max_sge *
623 sizeof(struct qib_sge)) * n);
624}
625
626/*
627 * Since struct qib_rwqe is not a fixed size, we can't simply index into
628 * struct qib_rwq.wq. This function does the array index computation.
629 */
630static inline struct qib_rwqe *get_rwqe_ptr(struct qib_rq *rq, unsigned n)
631{
632 return (struct qib_rwqe *)
633 ((char *) rq->wq->wq +
634 (sizeof(struct qib_rwqe) +
635 rq->max_sge * sizeof(struct ib_sge)) * n);
636}
637
638/*
639 * QPN-map pages start out as NULL, they get allocated upon
640 * first use and are never deallocated. This way,
641 * large bitmaps are not allocated unless large numbers of QPs are used.
642 */
643struct qpn_map {
644 void *page;
645};
646
647struct qib_qpn_table {
648 spinlock_t lock; /* protect changes in this struct */
649 unsigned flags; /* flags for QP0/1 allocated for each port */
650 u32 last; /* last QP number allocated */
651 u32 nmaps; /* size of the map table */
652 u16 limit;
653 u16 mask;
654 /* bit map of free QP numbers other than 0/1 */
655 struct qpn_map map[QPNMAP_ENTRIES];
656};
657
658#define MAX_LKEY_TABLE_BITS 23
659
660struct qib_lkey_table {
661 spinlock_t lock; /* protect changes in this struct */
662 u32 next; /* next unused index (speeds search) */
663 u32 gen; /* generation count */
664 u32 max; /* size of the table */
665 struct qib_mregion __rcu **table;
666};
667
668struct qib_opcode_stats { 204struct qib_opcode_stats {
669 u64 n_packets; /* number of packets */ 205 u64 n_packets; /* number of packets */
670 u64 n_bytes; /* total number of bytes */ 206 u64 n_bytes; /* total number of bytes */
@@ -682,21 +218,9 @@ struct qib_pma_counters {
682}; 218};
683 219
684struct qib_ibport { 220struct qib_ibport {
685 struct qib_qp __rcu *qp0; 221 struct rvt_ibport rvp;
686 struct qib_qp __rcu *qp1; 222 struct rvt_ah *smi_ah;
687 struct ib_mad_agent *send_agent; /* agent for SMI (traps) */
688 struct qib_ah *sm_ah;
689 struct qib_ah *smi_ah;
690 struct rb_root mcast_tree;
691 spinlock_t lock; /* protect changes in this struct */
692
693 /* non-zero when timer is set */
694 unsigned long mkey_lease_timeout;
695 unsigned long trap_timeout;
696 __be64 gid_prefix; /* in network order */
697 __be64 mkey;
698 __be64 guids[QIB_GUIDS_PER_PORT - 1]; /* writable GUIDs */ 223 __be64 guids[QIB_GUIDS_PER_PORT - 1]; /* writable GUIDs */
699 u64 tid; /* TID for traps */
700 struct qib_pma_counters __percpu *pmastats; 224 struct qib_pma_counters __percpu *pmastats;
701 u64 z_unicast_xmit; /* starting count for PMA */ 225 u64 z_unicast_xmit; /* starting count for PMA */
702 u64 z_unicast_rcv; /* starting count for PMA */ 226 u64 z_unicast_rcv; /* starting count for PMA */
@@ -715,82 +239,25 @@ struct qib_ibport {
715 u32 z_local_link_integrity_errors; /* starting count for PMA */ 239 u32 z_local_link_integrity_errors; /* starting count for PMA */
716 u32 z_excessive_buffer_overrun_errors; /* starting count for PMA */ 240 u32 z_excessive_buffer_overrun_errors; /* starting count for PMA */
717 u32 z_vl15_dropped; /* starting count for PMA */ 241 u32 z_vl15_dropped; /* starting count for PMA */
718 u32 n_rc_resends;
719 u32 n_rc_acks;
720 u32 n_rc_qacks;
721 u32 n_rc_delayed_comp;
722 u32 n_seq_naks;
723 u32 n_rdma_seq;
724 u32 n_rnr_naks;
725 u32 n_other_naks;
726 u32 n_loop_pkts;
727 u32 n_pkt_drops;
728 u32 n_vl15_dropped;
729 u32 n_rc_timeouts;
730 u32 n_dmawait;
731 u32 n_unaligned;
732 u32 n_rc_dupreq;
733 u32 n_rc_seqnak;
734 u32 port_cap_flags;
735 u32 pma_sample_start;
736 u32 pma_sample_interval;
737 __be16 pma_counter_select[5];
738 u16 pma_tag;
739 u16 pkey_violations;
740 u16 qkey_violations;
741 u16 mkey_violations;
742 u16 mkey_lease_period;
743 u16 sm_lid;
744 u16 repress_traps;
745 u8 sm_sl;
746 u8 mkeyprot;
747 u8 subnet_timeout;
748 u8 vl_high_limit;
749 u8 sl_to_vl[16]; 242 u8 sl_to_vl[16];
750
751}; 243};
752 244
753
754struct qib_ibdev { 245struct qib_ibdev {
755 struct ib_device ibdev; 246 struct rvt_dev_info rdi;
756 struct list_head pending_mmaps; 247
757 spinlock_t mmap_offset_lock; /* protect mmap_offset */
758 u32 mmap_offset;
759 struct qib_mregion __rcu *dma_mr;
760
761 /* QP numbers are shared by all IB ports */
762 struct qib_qpn_table qpn_table;
763 struct qib_lkey_table lk_table;
764 struct list_head piowait; /* list for wait PIO buf */ 248 struct list_head piowait; /* list for wait PIO buf */
765 struct list_head dmawait; /* list for wait DMA */ 249 struct list_head dmawait; /* list for wait DMA */
766 struct list_head txwait; /* list for wait qib_verbs_txreq */ 250 struct list_head txwait; /* list for wait qib_verbs_txreq */
767 struct list_head memwait; /* list for wait kernel memory */ 251 struct list_head memwait; /* list for wait kernel memory */
768 struct list_head txreq_free; 252 struct list_head txreq_free;
769 struct timer_list mem_timer; 253 struct timer_list mem_timer;
770 struct qib_qp __rcu **qp_table;
771 struct qib_pio_header *pio_hdrs; 254 struct qib_pio_header *pio_hdrs;
772 dma_addr_t pio_hdrs_phys; 255 dma_addr_t pio_hdrs_phys;
773 /* list of QPs waiting for RNR timer */
774 spinlock_t pending_lock; /* protect wait lists, PMA counters, etc. */
775 u32 qp_table_size; /* size of the hash table */
776 u32 qp_rnd; /* random bytes for hash */ 256 u32 qp_rnd; /* random bytes for hash */
777 spinlock_t qpt_lock;
778 257
779 u32 n_piowait; 258 u32 n_piowait;
780 u32 n_txwait; 259 u32 n_txwait;
781 260
782 u32 n_pds_allocated; /* number of PDs allocated for device */
783 spinlock_t n_pds_lock;
784 u32 n_ahs_allocated; /* number of AHs allocated for device */
785 spinlock_t n_ahs_lock;
786 u32 n_cqs_allocated; /* number of CQs allocated for device */
787 spinlock_t n_cqs_lock;
788 u32 n_qps_allocated; /* number of QPs allocated for device */
789 spinlock_t n_qps_lock;
790 u32 n_srqs_allocated; /* number of SRQs allocated for device */
791 spinlock_t n_srqs_lock;
792 u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
793 spinlock_t n_mcast_grps_lock;
794#ifdef CONFIG_DEBUG_FS 261#ifdef CONFIG_DEBUG_FS
795 /* per HCA debugfs */ 262 /* per HCA debugfs */
796 struct dentry *qib_ibdev_dbg; 263 struct dentry *qib_ibdev_dbg;
@@ -813,56 +280,27 @@ struct qib_verbs_counters {
813 u32 vl15_dropped; 280 u32 vl15_dropped;
814}; 281};
815 282
816static inline struct qib_mr *to_imr(struct ib_mr *ibmr)
817{
818 return container_of(ibmr, struct qib_mr, ibmr);
819}
820
821static inline struct qib_pd *to_ipd(struct ib_pd *ibpd)
822{
823 return container_of(ibpd, struct qib_pd, ibpd);
824}
825
826static inline struct qib_ah *to_iah(struct ib_ah *ibah)
827{
828 return container_of(ibah, struct qib_ah, ibah);
829}
830
831static inline struct qib_cq *to_icq(struct ib_cq *ibcq)
832{
833 return container_of(ibcq, struct qib_cq, ibcq);
834}
835
836static inline struct qib_srq *to_isrq(struct ib_srq *ibsrq)
837{
838 return container_of(ibsrq, struct qib_srq, ibsrq);
839}
840
841static inline struct qib_qp *to_iqp(struct ib_qp *ibqp)
842{
843 return container_of(ibqp, struct qib_qp, ibqp);
844}
845
846static inline struct qib_ibdev *to_idev(struct ib_device *ibdev) 283static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
847{ 284{
848 return container_of(ibdev, struct qib_ibdev, ibdev); 285 struct rvt_dev_info *rdi;
286
287 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
288 return container_of(rdi, struct qib_ibdev, rdi);
849} 289}
850 290
851/* 291/*
852 * Send if not busy or waiting for I/O and either 292 * Send if not busy or waiting for I/O and either
853 * a RC response is pending or we can process send work requests. 293 * a RC response is pending or we can process send work requests.
854 */ 294 */
855static inline int qib_send_ok(struct qib_qp *qp) 295static inline int qib_send_ok(struct rvt_qp *qp)
856{ 296{
857 return !(qp->s_flags & (QIB_S_BUSY | QIB_S_ANY_WAIT_IO)) && 297 return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) &&
858 (qp->s_hdrwords || (qp->s_flags & QIB_S_RESP_PENDING) || 298 (qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) ||
859 !(qp->s_flags & QIB_S_ANY_WAIT_SEND)); 299 !(qp->s_flags & RVT_S_ANY_WAIT_SEND));
860} 300}
861 301
862/* 302void _qib_schedule_send(struct rvt_qp *qp);
863 * This must be called with s_lock held. 303void qib_schedule_send(struct rvt_qp *qp);
864 */
865void qib_schedule_send(struct qib_qp *qp);
866 304
867static inline int qib_pkey_ok(u16 pkey1, u16 pkey2) 305static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
868{ 306{
@@ -878,7 +316,7 @@ static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
878 316
879void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl, 317void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
880 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2); 318 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
881void qib_cap_mask_chg(struct qib_ibport *ibp); 319void qib_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
882void qib_sys_guid_chg(struct qib_ibport *ibp); 320void qib_sys_guid_chg(struct qib_ibport *ibp);
883void qib_node_desc_chg(struct qib_ibport *ibp); 321void qib_node_desc_chg(struct qib_ibport *ibp);
884int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num, 322int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
@@ -886,8 +324,8 @@ int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
886 const struct ib_mad_hdr *in, size_t in_mad_size, 324 const struct ib_mad_hdr *in, size_t in_mad_size,
887 struct ib_mad_hdr *out, size_t *out_mad_size, 325 struct ib_mad_hdr *out, size_t *out_mad_size,
888 u16 *out_mad_pkey_index); 326 u16 *out_mad_pkey_index);
889int qib_create_agents(struct qib_ibdev *dev); 327void qib_notify_create_mad_agent(struct rvt_dev_info *rdi, int port_idx);
890void qib_free_agents(struct qib_ibdev *dev); 328void qib_notify_free_mad_agent(struct rvt_dev_info *rdi, int port_idx);
891 329
892/* 330/*
893 * Compare the lower 24 bits of the two values. 331 * Compare the lower 24 bits of the two values.
@@ -898,8 +336,6 @@ static inline int qib_cmp24(u32 a, u32 b)
898 return (((int) a) - ((int) b)) << 8; 336 return (((int) a) - ((int) b)) << 8;
899} 337}
900 338
901struct qib_mcast *qib_mcast_find(struct qib_ibport *ibp, union ib_gid *mgid);
902
903int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords, 339int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
904 u64 *rwords, u64 *spkts, u64 *rpkts, 340 u64 *rwords, u64 *spkts, u64 *rpkts,
905 u64 *xmit_wait); 341 u64 *xmit_wait);
@@ -907,35 +343,17 @@ int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
907int qib_get_counters(struct qib_pportdata *ppd, 343int qib_get_counters(struct qib_pportdata *ppd,
908 struct qib_verbs_counters *cntrs); 344 struct qib_verbs_counters *cntrs);
909 345
910int qib_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 346__be32 qib_compute_aeth(struct rvt_qp *qp);
911
912int qib_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
913
914int qib_mcast_tree_empty(struct qib_ibport *ibp);
915
916__be32 qib_compute_aeth(struct qib_qp *qp);
917
918struct qib_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn);
919
920struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
921 struct ib_qp_init_attr *init_attr,
922 struct ib_udata *udata);
923
924int qib_destroy_qp(struct ib_qp *ibqp);
925
926int qib_error_qp(struct qib_qp *qp, enum ib_wc_status err);
927
928int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
929 int attr_mask, struct ib_udata *udata);
930
931int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
932 int attr_mask, struct ib_qp_init_attr *init_attr);
933
934unsigned qib_free_all_qps(struct qib_devdata *dd);
935 347
936void qib_init_qpn_table(struct qib_devdata *dd, struct qib_qpn_table *qpt); 348/*
937 349 * Functions provided by qib driver for rdmavt to use
938void qib_free_qpn_table(struct qib_qpn_table *qpt); 350 */
351unsigned qib_free_all_qps(struct rvt_dev_info *rdi);
352void *qib_qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp, gfp_t gfp);
353void qib_qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp);
354void qib_notify_qp_reset(struct rvt_qp *qp);
355int qib_alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
356 enum ib_qp_type type, u8 port, gfp_t gfp);
939 357
940#ifdef CONFIG_DEBUG_FS 358#ifdef CONFIG_DEBUG_FS
941 359
@@ -949,7 +367,7 @@ void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter);
949 367
950#endif 368#endif
951 369
952void qib_get_credit(struct qib_qp *qp, u32 aeth); 370void qib_get_credit(struct rvt_qp *qp, u32 aeth);
953 371
954unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult); 372unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
955 373
@@ -957,166 +375,66 @@ void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
957 375
958void qib_put_txreq(struct qib_verbs_txreq *tx); 376void qib_put_txreq(struct qib_verbs_txreq *tx);
959 377
960int qib_verbs_send(struct qib_qp *qp, struct qib_ib_header *hdr, 378int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
961 u32 hdrwords, struct qib_sge_state *ss, u32 len); 379 u32 hdrwords, struct rvt_sge_state *ss, u32 len);
962 380
963void qib_copy_sge(struct qib_sge_state *ss, void *data, u32 length, 381void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
964 int release); 382 int release);
965 383
966void qib_skip_sge(struct qib_sge_state *ss, u32 length, int release); 384void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
967 385
968void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr, 386void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
969 int has_grh, void *data, u32 tlen, struct qib_qp *qp); 387 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
970 388
971void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr, 389void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
972 int has_grh, void *data, u32 tlen, struct qib_qp *qp); 390 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
973 391
974int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr); 392int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
975 393
394int qib_check_send_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe);
395
976struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid); 396struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
977 397
978void qib_rc_rnr_retry(unsigned long arg); 398void qib_rc_rnr_retry(unsigned long arg);
979 399
980void qib_rc_send_complete(struct qib_qp *qp, struct qib_ib_header *hdr); 400void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr);
981 401
982void qib_rc_error(struct qib_qp *qp, enum ib_wc_status err); 402void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
983 403
984int qib_post_ud_send(struct qib_qp *qp, struct ib_send_wr *wr); 404int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr);
985 405
986void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr, 406void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
987 int has_grh, void *data, u32 tlen, struct qib_qp *qp); 407 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
988
989int qib_alloc_lkey(struct qib_mregion *mr, int dma_region);
990
991void qib_free_lkey(struct qib_mregion *mr);
992
993int qib_lkey_ok(struct qib_lkey_table *rkt, struct qib_pd *pd,
994 struct qib_sge *isge, struct ib_sge *sge, int acc);
995
996int qib_rkey_ok(struct qib_qp *qp, struct qib_sge *sge,
997 u32 len, u64 vaddr, u32 rkey, int acc);
998
999int qib_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
1000 struct ib_recv_wr **bad_wr);
1001
1002struct ib_srq *qib_create_srq(struct ib_pd *ibpd,
1003 struct ib_srq_init_attr *srq_init_attr,
1004 struct ib_udata *udata);
1005
1006int qib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
1007 enum ib_srq_attr_mask attr_mask,
1008 struct ib_udata *udata);
1009
1010int qib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
1011
1012int qib_destroy_srq(struct ib_srq *ibsrq);
1013
1014int qib_cq_init(struct qib_devdata *dd);
1015
1016void qib_cq_exit(struct qib_devdata *dd);
1017
1018void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int sig);
1019
1020int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
1021
1022struct ib_cq *qib_create_cq(struct ib_device *ibdev,
1023 const struct ib_cq_init_attr *attr,
1024 struct ib_ucontext *context,
1025 struct ib_udata *udata);
1026
1027int qib_destroy_cq(struct ib_cq *ibcq);
1028
1029int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags);
1030
1031int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
1032
1033struct ib_mr *qib_get_dma_mr(struct ib_pd *pd, int acc);
1034
1035struct ib_mr *qib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1036 u64 virt_addr, int mr_access_flags,
1037 struct ib_udata *udata);
1038
1039int qib_dereg_mr(struct ib_mr *ibmr);
1040
1041struct ib_mr *qib_alloc_mr(struct ib_pd *pd,
1042 enum ib_mr_type mr_type,
1043 u32 max_entries);
1044
1045int qib_map_mr_sg(struct ib_mr *ibmr,
1046 struct scatterlist *sg,
1047 int sg_nents);
1048
1049int qib_reg_mr(struct qib_qp *qp, struct ib_reg_wr *wr);
1050
1051struct ib_fmr *qib_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
1052 struct ib_fmr_attr *fmr_attr);
1053
1054int qib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
1055 int list_len, u64 iova);
1056
1057int qib_unmap_fmr(struct list_head *fmr_list);
1058
1059int qib_dealloc_fmr(struct ib_fmr *ibfmr);
1060
1061static inline void qib_get_mr(struct qib_mregion *mr)
1062{
1063 atomic_inc(&mr->refcount);
1064}
1065 408
1066void mr_rcu_callback(struct rcu_head *list); 409void mr_rcu_callback(struct rcu_head *list);
1067 410
1068static inline void qib_put_mr(struct qib_mregion *mr) 411int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only);
1069{
1070 if (unlikely(atomic_dec_and_test(&mr->refcount)))
1071 call_rcu(&mr->list, mr_rcu_callback);
1072}
1073
1074static inline void qib_put_ss(struct qib_sge_state *ss)
1075{
1076 while (ss->num_sge) {
1077 qib_put_mr(ss->sge.mr);
1078 if (--ss->num_sge)
1079 ss->sge = *ss->sg_list++;
1080 }
1081}
1082
1083
1084void qib_release_mmap_info(struct kref *ref);
1085 412
1086struct qib_mmap_info *qib_create_mmap_info(struct qib_ibdev *dev, u32 size, 413void qib_migrate_qp(struct rvt_qp *qp);
1087 struct ib_ucontext *context,
1088 void *obj);
1089
1090void qib_update_mmap_info(struct qib_ibdev *dev, struct qib_mmap_info *ip,
1091 u32 size, void *obj);
1092
1093int qib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
1094
1095int qib_get_rwqe(struct qib_qp *qp, int wr_id_only);
1096
1097void qib_migrate_qp(struct qib_qp *qp);
1098 414
1099int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr, 415int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
1100 int has_grh, struct qib_qp *qp, u32 bth0); 416 int has_grh, struct rvt_qp *qp, u32 bth0);
1101 417
1102u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr, 418u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
1103 struct ib_global_route *grh, u32 hwords, u32 nwords); 419 struct ib_global_route *grh, u32 hwords, u32 nwords);
1104 420
1105void qib_make_ruc_header(struct qib_qp *qp, struct qib_other_headers *ohdr, 421void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
1106 u32 bth0, u32 bth2); 422 u32 bth0, u32 bth2);
1107 423
1108void qib_do_send(struct work_struct *work); 424void _qib_do_send(struct work_struct *work);
425
426void qib_do_send(struct rvt_qp *qp);
1109 427
1110void qib_send_complete(struct qib_qp *qp, struct qib_swqe *wqe, 428void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
1111 enum ib_wc_status status); 429 enum ib_wc_status status);
1112 430
1113void qib_send_rc_ack(struct qib_qp *qp); 431void qib_send_rc_ack(struct rvt_qp *qp);
1114 432
1115int qib_make_rc_req(struct qib_qp *qp); 433int qib_make_rc_req(struct rvt_qp *qp);
1116 434
1117int qib_make_uc_req(struct qib_qp *qp); 435int qib_make_uc_req(struct rvt_qp *qp);
1118 436
1119int qib_make_ud_req(struct qib_qp *qp); 437int qib_make_ud_req(struct rvt_qp *qp);
1120 438
1121int qib_register_ib_device(struct qib_devdata *); 439int qib_register_ib_device(struct qib_devdata *);
1122 440
@@ -1150,11 +468,11 @@ extern const enum ib_wc_opcode ib_qib_wc_opcode[];
1150#define IB_PHYSPORTSTATE_CFG_ENH 0x10 468#define IB_PHYSPORTSTATE_CFG_ENH 0x10
1151#define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13 469#define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
1152 470
1153extern const int ib_qib_state_ops[]; 471extern const int ib_rvt_state_ops[];
1154 472
1155extern __be64 ib_qib_sys_image_guid; /* in network order */ 473extern __be64 ib_qib_sys_image_guid; /* in network order */
1156 474
1157extern unsigned int ib_qib_lkey_table_size; 475extern unsigned int ib_rvt_lkey_table_size;
1158 476
1159extern unsigned int ib_qib_max_cqes; 477extern unsigned int ib_qib_max_cqes;
1160 478
@@ -1178,6 +496,4 @@ extern unsigned int ib_qib_max_srq_wrs;
1178 496
1179extern const u32 ib_qib_rnr_table[]; 497extern const u32 ib_qib_rnr_table[];
1180 498
1181extern struct ib_dma_mapping_ops qib_dma_mapping_ops;
1182
1183#endif /* QIB_VERBS_H */ 499#endif /* QIB_VERBS_H */
diff --git a/drivers/infiniband/hw/qib/qib_verbs_mcast.c b/drivers/infiniband/hw/qib/qib_verbs_mcast.c
deleted file mode 100644
index b2fb5286dbd9..000000000000
--- a/drivers/infiniband/hw/qib/qib_verbs_mcast.c
+++ /dev/null
@@ -1,363 +0,0 @@
1/*
2 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <linux/rculist.h>
35
36#include "qib.h"
37
38/**
39 * qib_mcast_qp_alloc - alloc a struct to link a QP to mcast GID struct
40 * @qp: the QP to link
41 */
42static struct qib_mcast_qp *qib_mcast_qp_alloc(struct qib_qp *qp)
43{
44 struct qib_mcast_qp *mqp;
45
46 mqp = kmalloc(sizeof(*mqp), GFP_KERNEL);
47 if (!mqp)
48 goto bail;
49
50 mqp->qp = qp;
51 atomic_inc(&qp->refcount);
52
53bail:
54 return mqp;
55}
56
57static void qib_mcast_qp_free(struct qib_mcast_qp *mqp)
58{
59 struct qib_qp *qp = mqp->qp;
60
61 /* Notify qib_destroy_qp() if it is waiting. */
62 if (atomic_dec_and_test(&qp->refcount))
63 wake_up(&qp->wait);
64
65 kfree(mqp);
66}
67
68/**
69 * qib_mcast_alloc - allocate the multicast GID structure
70 * @mgid: the multicast GID
71 *
72 * A list of QPs will be attached to this structure.
73 */
74static struct qib_mcast *qib_mcast_alloc(union ib_gid *mgid)
75{
76 struct qib_mcast *mcast;
77
78 mcast = kmalloc(sizeof(*mcast), GFP_KERNEL);
79 if (!mcast)
80 goto bail;
81
82 mcast->mgid = *mgid;
83 INIT_LIST_HEAD(&mcast->qp_list);
84 init_waitqueue_head(&mcast->wait);
85 atomic_set(&mcast->refcount, 0);
86 mcast->n_attached = 0;
87
88bail:
89 return mcast;
90}
91
92static void qib_mcast_free(struct qib_mcast *mcast)
93{
94 struct qib_mcast_qp *p, *tmp;
95
96 list_for_each_entry_safe(p, tmp, &mcast->qp_list, list)
97 qib_mcast_qp_free(p);
98
99 kfree(mcast);
100}
101
102/**
103 * qib_mcast_find - search the global table for the given multicast GID
104 * @ibp: the IB port structure
105 * @mgid: the multicast GID to search for
106 *
107 * Returns NULL if not found.
108 *
109 * The caller is responsible for decrementing the reference count if found.
110 */
111struct qib_mcast *qib_mcast_find(struct qib_ibport *ibp, union ib_gid *mgid)
112{
113 struct rb_node *n;
114 unsigned long flags;
115 struct qib_mcast *mcast;
116
117 spin_lock_irqsave(&ibp->lock, flags);
118 n = ibp->mcast_tree.rb_node;
119 while (n) {
120 int ret;
121
122 mcast = rb_entry(n, struct qib_mcast, rb_node);
123
124 ret = memcmp(mgid->raw, mcast->mgid.raw,
125 sizeof(union ib_gid));
126 if (ret < 0)
127 n = n->rb_left;
128 else if (ret > 0)
129 n = n->rb_right;
130 else {
131 atomic_inc(&mcast->refcount);
132 spin_unlock_irqrestore(&ibp->lock, flags);
133 goto bail;
134 }
135 }
136 spin_unlock_irqrestore(&ibp->lock, flags);
137
138 mcast = NULL;
139
140bail:
141 return mcast;
142}
143
144/**
145 * qib_mcast_add - insert mcast GID into table and attach QP struct
146 * @mcast: the mcast GID table
147 * @mqp: the QP to attach
148 *
149 * Return zero if both were added. Return EEXIST if the GID was already in
150 * the table but the QP was added. Return ESRCH if the QP was already
151 * attached and neither structure was added.
152 */
153static int qib_mcast_add(struct qib_ibdev *dev, struct qib_ibport *ibp,
154 struct qib_mcast *mcast, struct qib_mcast_qp *mqp)
155{
156 struct rb_node **n = &ibp->mcast_tree.rb_node;
157 struct rb_node *pn = NULL;
158 int ret;
159
160 spin_lock_irq(&ibp->lock);
161
162 while (*n) {
163 struct qib_mcast *tmcast;
164 struct qib_mcast_qp *p;
165
166 pn = *n;
167 tmcast = rb_entry(pn, struct qib_mcast, rb_node);
168
169 ret = memcmp(mcast->mgid.raw, tmcast->mgid.raw,
170 sizeof(union ib_gid));
171 if (ret < 0) {
172 n = &pn->rb_left;
173 continue;
174 }
175 if (ret > 0) {
176 n = &pn->rb_right;
177 continue;
178 }
179
180 /* Search the QP list to see if this is already there. */
181 list_for_each_entry_rcu(p, &tmcast->qp_list, list) {
182 if (p->qp == mqp->qp) {
183 ret = ESRCH;
184 goto bail;
185 }
186 }
187 if (tmcast->n_attached == ib_qib_max_mcast_qp_attached) {
188 ret = ENOMEM;
189 goto bail;
190 }
191
192 tmcast->n_attached++;
193
194 list_add_tail_rcu(&mqp->list, &tmcast->qp_list);
195 ret = EEXIST;
196 goto bail;
197 }
198
199 spin_lock(&dev->n_mcast_grps_lock);
200 if (dev->n_mcast_grps_allocated == ib_qib_max_mcast_grps) {
201 spin_unlock(&dev->n_mcast_grps_lock);
202 ret = ENOMEM;
203 goto bail;
204 }
205
206 dev->n_mcast_grps_allocated++;
207 spin_unlock(&dev->n_mcast_grps_lock);
208
209 mcast->n_attached++;
210
211 list_add_tail_rcu(&mqp->list, &mcast->qp_list);
212
213 atomic_inc(&mcast->refcount);
214 rb_link_node(&mcast->rb_node, pn, n);
215 rb_insert_color(&mcast->rb_node, &ibp->mcast_tree);
216
217 ret = 0;
218
219bail:
220 spin_unlock_irq(&ibp->lock);
221
222 return ret;
223}
224
225int qib_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
226{
227 struct qib_qp *qp = to_iqp(ibqp);
228 struct qib_ibdev *dev = to_idev(ibqp->device);
229 struct qib_ibport *ibp;
230 struct qib_mcast *mcast;
231 struct qib_mcast_qp *mqp;
232 int ret;
233
234 if (ibqp->qp_num <= 1 || qp->state == IB_QPS_RESET) {
235 ret = -EINVAL;
236 goto bail;
237 }
238
239 /*
240 * Allocate data structures since its better to do this outside of
241 * spin locks and it will most likely be needed.
242 */
243 mcast = qib_mcast_alloc(gid);
244 if (mcast == NULL) {
245 ret = -ENOMEM;
246 goto bail;
247 }
248 mqp = qib_mcast_qp_alloc(qp);
249 if (mqp == NULL) {
250 qib_mcast_free(mcast);
251 ret = -ENOMEM;
252 goto bail;
253 }
254 ibp = to_iport(ibqp->device, qp->port_num);
255 switch (qib_mcast_add(dev, ibp, mcast, mqp)) {
256 case ESRCH:
257 /* Neither was used: OK to attach the same QP twice. */
258 qib_mcast_qp_free(mqp);
259 qib_mcast_free(mcast);
260 break;
261
262 case EEXIST: /* The mcast wasn't used */
263 qib_mcast_free(mcast);
264 break;
265
266 case ENOMEM:
267 /* Exceeded the maximum number of mcast groups. */
268 qib_mcast_qp_free(mqp);
269 qib_mcast_free(mcast);
270 ret = -ENOMEM;
271 goto bail;
272
273 default:
274 break;
275 }
276
277 ret = 0;
278
279bail:
280 return ret;
281}
282
283int qib_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
284{
285 struct qib_qp *qp = to_iqp(ibqp);
286 struct qib_ibdev *dev = to_idev(ibqp->device);
287 struct qib_ibport *ibp = to_iport(ibqp->device, qp->port_num);
288 struct qib_mcast *mcast = NULL;
289 struct qib_mcast_qp *p, *tmp, *delp = NULL;
290 struct rb_node *n;
291 int last = 0;
292 int ret;
293
294 if (ibqp->qp_num <= 1 || qp->state == IB_QPS_RESET)
295 return -EINVAL;
296
297 spin_lock_irq(&ibp->lock);
298
299 /* Find the GID in the mcast table. */
300 n = ibp->mcast_tree.rb_node;
301 while (1) {
302 if (n == NULL) {
303 spin_unlock_irq(&ibp->lock);
304 return -EINVAL;
305 }
306
307 mcast = rb_entry(n, struct qib_mcast, rb_node);
308 ret = memcmp(gid->raw, mcast->mgid.raw,
309 sizeof(union ib_gid));
310 if (ret < 0)
311 n = n->rb_left;
312 else if (ret > 0)
313 n = n->rb_right;
314 else
315 break;
316 }
317
318 /* Search the QP list. */
319 list_for_each_entry_safe(p, tmp, &mcast->qp_list, list) {
320 if (p->qp != qp)
321 continue;
322 /*
323 * We found it, so remove it, but don't poison the forward
324 * link until we are sure there are no list walkers.
325 */
326 list_del_rcu(&p->list);
327 mcast->n_attached--;
328 delp = p;
329
330 /* If this was the last attached QP, remove the GID too. */
331 if (list_empty(&mcast->qp_list)) {
332 rb_erase(&mcast->rb_node, &ibp->mcast_tree);
333 last = 1;
334 }
335 break;
336 }
337
338 spin_unlock_irq(&ibp->lock);
339 /* QP not attached */
340 if (!delp)
341 return -EINVAL;
342 /*
343 * Wait for any list walkers to finish before freeing the
344 * list element.
345 */
346 wait_event(mcast->wait, atomic_read(&mcast->refcount) <= 1);
347 qib_mcast_qp_free(delp);
348
349 if (last) {
350 atomic_dec(&mcast->refcount);
351 wait_event(mcast->wait, !atomic_read(&mcast->refcount));
352 qib_mcast_free(mcast);
353 spin_lock_irq(&dev->n_mcast_grps_lock);
354 dev->n_mcast_grps_allocated--;
355 spin_unlock_irq(&dev->n_mcast_grps_lock);
356 }
357 return 0;
358}
359
360int qib_mcast_tree_empty(struct qib_ibport *ibp)
361{
362 return ibp->mcast_tree.rb_node == NULL;
363}
diff --git a/drivers/infiniband/sw/Makefile b/drivers/infiniband/sw/Makefile
new file mode 100644
index 000000000000..988b6a0101a4
--- /dev/null
+++ b/drivers/infiniband/sw/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_INFINIBAND_RDMAVT) += rdmavt/
diff --git a/drivers/infiniband/sw/rdmavt/Kconfig b/drivers/infiniband/sw/rdmavt/Kconfig
new file mode 100644
index 000000000000..11aa6a34bd71
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/Kconfig
@@ -0,0 +1,6 @@
1config INFINIBAND_RDMAVT
2 tristate "RDMA verbs transport library"
3 depends on 64BIT
4 default m
5 ---help---
6 This is a common software verbs provider for RDMA networks.
diff --git a/drivers/infiniband/sw/rdmavt/Makefile b/drivers/infiniband/sw/rdmavt/Makefile
new file mode 100644
index 000000000000..ccaa7992ac97
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/Makefile
@@ -0,0 +1,13 @@
1#
2# rdmavt driver
3#
4#
5#
6# Called from the kernel module build system.
7#
8obj-$(CONFIG_INFINIBAND_RDMAVT) += rdmavt.o
9
10rdmavt-y := vt.o ah.o cq.o dma.o mad.o mcast.o mmap.o mr.o pd.o qp.o srq.o \
11 trace.o
12
13CFLAGS_trace.o = -I$(src)
diff --git a/drivers/infiniband/sw/rdmavt/ah.c b/drivers/infiniband/sw/rdmavt/ah.c
new file mode 100644
index 000000000000..16c446142c2a
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/ah.c
@@ -0,0 +1,196 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <linux/slab.h>
49#include "ah.h"
50#include "vt.h" /* for prints */
51
52/**
53 * rvt_check_ah - validate the attributes of AH
54 * @ibdev: the ib device
55 * @ah_attr: the attributes of the AH
56 *
57 * If driver supports a more detailed check_ah function call back to it
58 * otherwise just check the basics.
59 *
60 * Return: 0 on success
61 */
62int rvt_check_ah(struct ib_device *ibdev,
63 struct ib_ah_attr *ah_attr)
64{
65 int err;
66 struct ib_port_attr port_attr;
67 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
68 enum rdma_link_layer link = rdma_port_get_link_layer(ibdev,
69 ah_attr->port_num);
70
71 err = ib_query_port(ibdev, ah_attr->port_num, &port_attr);
72 if (err)
73 return -EINVAL;
74 if (ah_attr->port_num < 1 ||
75 ah_attr->port_num > ibdev->phys_port_cnt)
76 return -EINVAL;
77 if (ah_attr->static_rate != IB_RATE_PORT_CURRENT &&
78 ib_rate_to_mbps(ah_attr->static_rate) < 0)
79 return -EINVAL;
80 if ((ah_attr->ah_flags & IB_AH_GRH) &&
81 ah_attr->grh.sgid_index >= port_attr.gid_tbl_len)
82 return -EINVAL;
83 if (link != IB_LINK_LAYER_ETHERNET) {
84 if (ah_attr->dlid == 0)
85 return -EINVAL;
86 if (ah_attr->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) &&
87 ah_attr->dlid != be16_to_cpu(IB_LID_PERMISSIVE) &&
88 !(ah_attr->ah_flags & IB_AH_GRH))
89 return -EINVAL;
90 }
91 if (rdi->driver_f.check_ah)
92 return rdi->driver_f.check_ah(ibdev, ah_attr);
93 return 0;
94}
95EXPORT_SYMBOL(rvt_check_ah);
96
97/**
98 * rvt_create_ah - create an address handle
99 * @pd: the protection domain
100 * @ah_attr: the attributes of the AH
101 *
102 * This may be called from interrupt context.
103 *
104 * Return: newly allocated ah
105 */
106struct ib_ah *rvt_create_ah(struct ib_pd *pd,
107 struct ib_ah_attr *ah_attr)
108{
109 struct rvt_ah *ah;
110 struct rvt_dev_info *dev = ib_to_rvt(pd->device);
111 unsigned long flags;
112
113 if (rvt_check_ah(pd->device, ah_attr))
114 return ERR_PTR(-EINVAL);
115
116 ah = kmalloc(sizeof(*ah), GFP_ATOMIC);
117 if (!ah)
118 return ERR_PTR(-ENOMEM);
119
120 spin_lock_irqsave(&dev->n_ahs_lock, flags);
121 if (dev->n_ahs_allocated == dev->dparms.props.max_ah) {
122 spin_unlock(&dev->n_ahs_lock);
123 kfree(ah);
124 return ERR_PTR(-ENOMEM);
125 }
126
127 dev->n_ahs_allocated++;
128 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
129
130 ah->attr = *ah_attr;
131 atomic_set(&ah->refcount, 0);
132
133 if (dev->driver_f.notify_new_ah)
134 dev->driver_f.notify_new_ah(pd->device, ah_attr, ah);
135
136 return &ah->ibah;
137}
138
139/**
140 * rvt_destory_ah - Destory an address handle
141 * @ibah: address handle
142 *
143 * Return: 0 on success
144 */
145int rvt_destroy_ah(struct ib_ah *ibah)
146{
147 struct rvt_dev_info *dev = ib_to_rvt(ibah->device);
148 struct rvt_ah *ah = ibah_to_rvtah(ibah);
149 unsigned long flags;
150
151 if (atomic_read(&ah->refcount) != 0)
152 return -EBUSY;
153
154 spin_lock_irqsave(&dev->n_ahs_lock, flags);
155 dev->n_ahs_allocated--;
156 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
157
158 kfree(ah);
159
160 return 0;
161}
162
163/**
164 * rvt_modify_ah - modify an ah with given attrs
165 * @ibah: address handle to modify
166 * @ah_attr: attrs to apply
167 *
168 * Return: 0 on success
169 */
170int rvt_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
171{
172 struct rvt_ah *ah = ibah_to_rvtah(ibah);
173
174 if (rvt_check_ah(ibah->device, ah_attr))
175 return -EINVAL;
176
177 ah->attr = *ah_attr;
178
179 return 0;
180}
181
182/**
183 * rvt_query_ah - return attrs for ah
184 * @ibah: address handle to query
185 * @ah_attr: return info in this
186 *
187 * Return: always 0
188 */
189int rvt_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
190{
191 struct rvt_ah *ah = ibah_to_rvtah(ibah);
192
193 *ah_attr = ah->attr;
194
195 return 0;
196}
diff --git a/drivers/infiniband/sw/rdmavt/ah.h b/drivers/infiniband/sw/rdmavt/ah.h
new file mode 100644
index 000000000000..e9c36be87d79
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/ah.h
@@ -0,0 +1,59 @@
1#ifndef DEF_RVTAH_H
2#define DEF_RVTAH_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52
53struct ib_ah *rvt_create_ah(struct ib_pd *pd,
54 struct ib_ah_attr *ah_attr);
55int rvt_destroy_ah(struct ib_ah *ibah);
56int rvt_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
57int rvt_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
58
59#endif /* DEF_RVTAH_H */
diff --git a/drivers/staging/rdma/hfi1/cq.c b/drivers/infiniband/sw/rdmavt/cq.c
index 4f046ffe7e60..b1ffc8b4a6c0 100644
--- a/drivers/staging/rdma/hfi1/cq.c
+++ b/drivers/infiniband/sw/rdmavt/cq.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -48,25 +45,23 @@
48 * 45 *
49 */ 46 */
50 47
51#include <linux/err.h>
52#include <linux/slab.h> 48#include <linux/slab.h>
53#include <linux/vmalloc.h> 49#include <linux/vmalloc.h>
54#include <linux/kthread.h> 50#include <linux/kthread.h>
55 51#include "cq.h"
56#include "verbs.h" 52#include "vt.h"
57#include "hfi.h"
58 53
59/** 54/**
60 * hfi1_cq_enter - add a new entry to the completion queue 55 * rvt_cq_enter - add a new entry to the completion queue
61 * @cq: completion queue 56 * @cq: completion queue
62 * @entry: work completion entry to add 57 * @entry: work completion entry to add
63 * @sig: true if @entry is a solicited entry 58 * @sig: true if @entry is solicited
64 * 59 *
65 * This may be called with qp->s_lock held. 60 * This may be called with qp->s_lock held.
66 */ 61 */
67void hfi1_cq_enter(struct hfi1_cq *cq, struct ib_wc *entry, int solicited) 62void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited)
68{ 63{
69 struct hfi1_cq_wc *wc; 64 struct rvt_cq_wc *wc;
70 unsigned long flags; 65 unsigned long flags;
71 u32 head; 66 u32 head;
72 u32 next; 67 u32 next;
@@ -79,11 +74,13 @@ void hfi1_cq_enter(struct hfi1_cq *cq, struct ib_wc *entry, int solicited)
79 */ 74 */
80 wc = cq->queue; 75 wc = cq->queue;
81 head = wc->head; 76 head = wc->head;
82 if (head >= (unsigned) cq->ibcq.cqe) { 77 if (head >= (unsigned)cq->ibcq.cqe) {
83 head = cq->ibcq.cqe; 78 head = cq->ibcq.cqe;
84 next = 0; 79 next = 0;
85 } else 80 } else {
86 next = head + 1; 81 next = head + 1;
82 }
83
87 if (unlikely(next == wc->tail)) { 84 if (unlikely(next == wc->tail)) {
88 spin_unlock_irqrestore(&cq->lock, flags); 85 spin_unlock_irqrestore(&cq->lock, flags);
89 if (cq->ibcq.event_handler) { 86 if (cq->ibcq.event_handler) {
@@ -114,8 +111,9 @@ void hfi1_cq_enter(struct hfi1_cq *cq, struct ib_wc *entry, int solicited)
114 wc->uqueue[head].port_num = entry->port_num; 111 wc->uqueue[head].port_num = entry->port_num;
115 /* Make sure entry is written before the head index. */ 112 /* Make sure entry is written before the head index. */
116 smp_wmb(); 113 smp_wmb();
117 } else 114 } else {
118 wc->kqueue[head] = *entry; 115 wc->kqueue[head] = *entry;
116 }
119 wc->head = next; 117 wc->head = next;
120 118
121 if (cq->notify == IB_CQ_NEXT_COMP || 119 if (cq->notify == IB_CQ_NEXT_COMP ||
@@ -126,10 +124,10 @@ void hfi1_cq_enter(struct hfi1_cq *cq, struct ib_wc *entry, int solicited)
126 * This will cause send_complete() to be called in 124 * This will cause send_complete() to be called in
127 * another thread. 125 * another thread.
128 */ 126 */
129 smp_read_barrier_depends(); /* see hfi1_cq_exit */ 127 smp_read_barrier_depends(); /* see rvt_cq_exit */
130 worker = cq->dd->worker; 128 worker = cq->rdi->worker;
131 if (likely(worker)) { 129 if (likely(worker)) {
132 cq->notify = IB_CQ_NONE; 130 cq->notify = RVT_CQ_NONE;
133 cq->triggered++; 131 cq->triggered++;
134 queue_kthread_work(worker, &cq->comptask); 132 queue_kthread_work(worker, &cq->comptask);
135 } 133 }
@@ -137,59 +135,11 @@ void hfi1_cq_enter(struct hfi1_cq *cq, struct ib_wc *entry, int solicited)
137 135
138 spin_unlock_irqrestore(&cq->lock, flags); 136 spin_unlock_irqrestore(&cq->lock, flags);
139} 137}
140 138EXPORT_SYMBOL(rvt_cq_enter);
141/**
142 * hfi1_poll_cq - poll for work completion entries
143 * @ibcq: the completion queue to poll
144 * @num_entries: the maximum number of entries to return
145 * @entry: pointer to array where work completions are placed
146 *
147 * Returns the number of completion entries polled.
148 *
149 * This may be called from interrupt context. Also called by ib_poll_cq()
150 * in the generic verbs code.
151 */
152int hfi1_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
153{
154 struct hfi1_cq *cq = to_icq(ibcq);
155 struct hfi1_cq_wc *wc;
156 unsigned long flags;
157 int npolled;
158 u32 tail;
159
160 /* The kernel can only poll a kernel completion queue */
161 if (cq->ip) {
162 npolled = -EINVAL;
163 goto bail;
164 }
165
166 spin_lock_irqsave(&cq->lock, flags);
167
168 wc = cq->queue;
169 tail = wc->tail;
170 if (tail > (u32) cq->ibcq.cqe)
171 tail = (u32) cq->ibcq.cqe;
172 for (npolled = 0; npolled < num_entries; ++npolled, ++entry) {
173 if (tail == wc->head)
174 break;
175 /* The kernel doesn't need a RMB since it has the lock. */
176 *entry = wc->kqueue[tail];
177 if (tail >= cq->ibcq.cqe)
178 tail = 0;
179 else
180 tail++;
181 }
182 wc->tail = tail;
183
184 spin_unlock_irqrestore(&cq->lock, flags);
185
186bail:
187 return npolled;
188}
189 139
190static void send_complete(struct kthread_work *work) 140static void send_complete(struct kthread_work *work)
191{ 141{
192 struct hfi1_cq *cq = container_of(work, struct hfi1_cq, comptask); 142 struct rvt_cq *cq = container_of(work, struct rvt_cq, comptask);
193 143
194 /* 144 /*
195 * The completion handler will most likely rearm the notification 145 * The completion handler will most likely rearm the notification
@@ -217,26 +167,25 @@ static void send_complete(struct kthread_work *work)
217} 167}
218 168
219/** 169/**
220 * hfi1_create_cq - create a completion queue 170 * rvt_create_cq - create a completion queue
221 * @ibdev: the device this completion queue is attached to 171 * @ibdev: the device this completion queue is attached to
222 * @attr: creation attributes 172 * @attr: creation attributes
223 * @context: unused by the driver 173 * @context: unused by the QLogic_IB driver
224 * @udata: user data for libibverbs.so 174 * @udata: user data for libibverbs.so
225 * 175 *
226 * Returns a pointer to the completion queue or negative errno values
227 * for failure.
228 *
229 * Called by ib_create_cq() in the generic verbs code. 176 * Called by ib_create_cq() in the generic verbs code.
177 *
178 * Return: pointer to the completion queue or negative errno values
179 * for failure.
230 */ 180 */
231struct ib_cq *hfi1_create_cq( 181struct ib_cq *rvt_create_cq(struct ib_device *ibdev,
232 struct ib_device *ibdev, 182 const struct ib_cq_init_attr *attr,
233 const struct ib_cq_init_attr *attr, 183 struct ib_ucontext *context,
234 struct ib_ucontext *context, 184 struct ib_udata *udata)
235 struct ib_udata *udata)
236{ 185{
237 struct hfi1_ibdev *dev = to_idev(ibdev); 186 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
238 struct hfi1_cq *cq; 187 struct rvt_cq *cq;
239 struct hfi1_cq_wc *wc; 188 struct rvt_cq_wc *wc;
240 struct ib_cq *ret; 189 struct ib_cq *ret;
241 u32 sz; 190 u32 sz;
242 unsigned int entries = attr->cqe; 191 unsigned int entries = attr->cqe;
@@ -244,11 +193,11 @@ struct ib_cq *hfi1_create_cq(
244 if (attr->flags) 193 if (attr->flags)
245 return ERR_PTR(-EINVAL); 194 return ERR_PTR(-EINVAL);
246 195
247 if (entries < 1 || entries > hfi1_max_cqes) 196 if (entries < 1 || entries > rdi->dparms.props.max_cqe)
248 return ERR_PTR(-EINVAL); 197 return ERR_PTR(-EINVAL);
249 198
250 /* Allocate the completion queue structure. */ 199 /* Allocate the completion queue structure. */
251 cq = kmalloc(sizeof(*cq), GFP_KERNEL); 200 cq = kzalloc(sizeof(*cq), GFP_KERNEL);
252 if (!cq) 201 if (!cq)
253 return ERR_PTR(-ENOMEM); 202 return ERR_PTR(-ENOMEM);
254 203
@@ -272,12 +221,12 @@ struct ib_cq *hfi1_create_cq(
272 221
273 /* 222 /*
274 * Return the address of the WC as the offset to mmap. 223 * Return the address of the WC as the offset to mmap.
275 * See hfi1_mmap() for details. 224 * See rvt_mmap() for details.
276 */ 225 */
277 if (udata && udata->outlen >= sizeof(__u64)) { 226 if (udata && udata->outlen >= sizeof(__u64)) {
278 int err; 227 int err;
279 228
280 cq->ip = hfi1_create_mmap_info(dev, sz, context, wc); 229 cq->ip = rvt_create_mmap_info(rdi, sz, context, wc);
281 if (!cq->ip) { 230 if (!cq->ip) {
282 ret = ERR_PTR(-ENOMEM); 231 ret = ERR_PTR(-ENOMEM);
283 goto bail_wc; 232 goto bail_wc;
@@ -289,23 +238,22 @@ struct ib_cq *hfi1_create_cq(
289 ret = ERR_PTR(err); 238 ret = ERR_PTR(err);
290 goto bail_ip; 239 goto bail_ip;
291 } 240 }
292 } else 241 }
293 cq->ip = NULL;
294 242
295 spin_lock(&dev->n_cqs_lock); 243 spin_lock(&rdi->n_cqs_lock);
296 if (dev->n_cqs_allocated == hfi1_max_cqs) { 244 if (rdi->n_cqs_allocated == rdi->dparms.props.max_cq) {
297 spin_unlock(&dev->n_cqs_lock); 245 spin_unlock(&rdi->n_cqs_lock);
298 ret = ERR_PTR(-ENOMEM); 246 ret = ERR_PTR(-ENOMEM);
299 goto bail_ip; 247 goto bail_ip;
300 } 248 }
301 249
302 dev->n_cqs_allocated++; 250 rdi->n_cqs_allocated++;
303 spin_unlock(&dev->n_cqs_lock); 251 spin_unlock(&rdi->n_cqs_lock);
304 252
305 if (cq->ip) { 253 if (cq->ip) {
306 spin_lock_irq(&dev->pending_lock); 254 spin_lock_irq(&rdi->pending_lock);
307 list_add(&cq->ip->pending_mmaps, &dev->pending_mmaps); 255 list_add(&cq->ip->pending_mmaps, &rdi->pending_mmaps);
308 spin_unlock_irq(&dev->pending_lock); 256 spin_unlock_irq(&rdi->pending_lock);
309 } 257 }
310 258
311 /* 259 /*
@@ -313,14 +261,11 @@ struct ib_cq *hfi1_create_cq(
313 * The number of entries should be >= the number requested or return 261 * The number of entries should be >= the number requested or return
314 * an error. 262 * an error.
315 */ 263 */
316 cq->dd = dd_from_dev(dev); 264 cq->rdi = rdi;
317 cq->ibcq.cqe = entries; 265 cq->ibcq.cqe = entries;
318 cq->notify = IB_CQ_NONE; 266 cq->notify = RVT_CQ_NONE;
319 cq->triggered = 0;
320 spin_lock_init(&cq->lock); 267 spin_lock_init(&cq->lock);
321 init_kthread_work(&cq->comptask, send_complete); 268 init_kthread_work(&cq->comptask, send_complete);
322 wc->head = 0;
323 wc->tail = 0;
324 cq->queue = wc; 269 cq->queue = wc;
325 270
326 ret = &cq->ibcq; 271 ret = &cq->ibcq;
@@ -338,24 +283,24 @@ done:
338} 283}
339 284
340/** 285/**
341 * hfi1_destroy_cq - destroy a completion queue 286 * rvt_destroy_cq - destroy a completion queue
342 * @ibcq: the completion queue to destroy. 287 * @ibcq: the completion queue to destroy.
343 * 288 *
344 * Returns 0 for success.
345 *
346 * Called by ib_destroy_cq() in the generic verbs code. 289 * Called by ib_destroy_cq() in the generic verbs code.
290 *
291 * Return: always 0
347 */ 292 */
348int hfi1_destroy_cq(struct ib_cq *ibcq) 293int rvt_destroy_cq(struct ib_cq *ibcq)
349{ 294{
350 struct hfi1_ibdev *dev = to_idev(ibcq->device); 295 struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
351 struct hfi1_cq *cq = to_icq(ibcq); 296 struct rvt_dev_info *rdi = cq->rdi;
352 297
353 flush_kthread_work(&cq->comptask); 298 flush_kthread_work(&cq->comptask);
354 spin_lock(&dev->n_cqs_lock); 299 spin_lock(&rdi->n_cqs_lock);
355 dev->n_cqs_allocated--; 300 rdi->n_cqs_allocated--;
356 spin_unlock(&dev->n_cqs_lock); 301 spin_unlock(&rdi->n_cqs_lock);
357 if (cq->ip) 302 if (cq->ip)
358 kref_put(&cq->ip->ref, hfi1_release_mmap_info); 303 kref_put(&cq->ip->ref, rvt_release_mmap_info);
359 else 304 else
360 vfree(cq->queue); 305 vfree(cq->queue);
361 kfree(cq); 306 kfree(cq);
@@ -364,18 +309,18 @@ int hfi1_destroy_cq(struct ib_cq *ibcq)
364} 309}
365 310
366/** 311/**
367 * hfi1_req_notify_cq - change the notification type for a completion queue 312 * rvt_req_notify_cq - change the notification type for a completion queue
368 * @ibcq: the completion queue 313 * @ibcq: the completion queue
369 * @notify_flags: the type of notification to request 314 * @notify_flags: the type of notification to request
370 * 315 *
371 * Returns 0 for success.
372 *
373 * This may be called from interrupt context. Also called by 316 * This may be called from interrupt context. Also called by
374 * ib_req_notify_cq() in the generic verbs code. 317 * ib_req_notify_cq() in the generic verbs code.
318 *
319 * Return: 0 for success.
375 */ 320 */
376int hfi1_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags) 321int rvt_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags)
377{ 322{
378 struct hfi1_cq *cq = to_icq(ibcq); 323 struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
379 unsigned long flags; 324 unsigned long flags;
380 int ret = 0; 325 int ret = 0;
381 326
@@ -397,24 +342,23 @@ int hfi1_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags)
397} 342}
398 343
399/** 344/**
400 * hfi1_resize_cq - change the size of the CQ 345 * rvt_resize_cq - change the size of the CQ
401 * @ibcq: the completion queue 346 * @ibcq: the completion queue
402 * 347 *
403 * Returns 0 for success. 348 * Return: 0 for success.
404 */ 349 */
405int hfi1_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) 350int rvt_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
406{ 351{
407 struct hfi1_cq *cq = to_icq(ibcq); 352 struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
408 struct hfi1_cq_wc *old_wc; 353 struct rvt_cq_wc *old_wc;
409 struct hfi1_cq_wc *wc; 354 struct rvt_cq_wc *wc;
410 u32 head, tail, n; 355 u32 head, tail, n;
411 int ret; 356 int ret;
412 u32 sz; 357 u32 sz;
358 struct rvt_dev_info *rdi = cq->rdi;
413 359
414 if (cqe < 1 || cqe > hfi1_max_cqes) { 360 if (cqe < 1 || cqe > rdi->dparms.props.max_cqe)
415 ret = -EINVAL; 361 return -EINVAL;
416 goto bail;
417 }
418 362
419 /* 363 /*
420 * Need to use vmalloc() if we want to support large #s of entries. 364 * Need to use vmalloc() if we want to support large #s of entries.
@@ -425,10 +369,8 @@ int hfi1_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
425 else 369 else
426 sz += sizeof(struct ib_wc) * (cqe + 1); 370 sz += sizeof(struct ib_wc) * (cqe + 1);
427 wc = vmalloc_user(sz); 371 wc = vmalloc_user(sz);
428 if (!wc) { 372 if (!wc)
429 ret = -ENOMEM; 373 return -ENOMEM;
430 goto bail;
431 }
432 374
433 /* Check that we can write the offset to mmap. */ 375 /* Check that we can write the offset to mmap. */
434 if (udata && udata->outlen >= sizeof(__u64)) { 376 if (udata && udata->outlen >= sizeof(__u64)) {
@@ -446,11 +388,11 @@ int hfi1_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
446 */ 388 */
447 old_wc = cq->queue; 389 old_wc = cq->queue;
448 head = old_wc->head; 390 head = old_wc->head;
449 if (head > (u32) cq->ibcq.cqe) 391 if (head > (u32)cq->ibcq.cqe)
450 head = (u32) cq->ibcq.cqe; 392 head = (u32)cq->ibcq.cqe;
451 tail = old_wc->tail; 393 tail = old_wc->tail;
452 if (tail > (u32) cq->ibcq.cqe) 394 if (tail > (u32)cq->ibcq.cqe)
453 tail = (u32) cq->ibcq.cqe; 395 tail = (u32)cq->ibcq.cqe;
454 if (head < tail) 396 if (head < tail)
455 n = cq->ibcq.cqe + 1 + head - tail; 397 n = cq->ibcq.cqe + 1 + head - tail;
456 else 398 else
@@ -464,7 +406,7 @@ int hfi1_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
464 wc->uqueue[n] = old_wc->uqueue[tail]; 406 wc->uqueue[n] = old_wc->uqueue[tail];
465 else 407 else
466 wc->kqueue[n] = old_wc->kqueue[tail]; 408 wc->kqueue[n] = old_wc->kqueue[tail];
467 if (tail == (u32) cq->ibcq.cqe) 409 if (tail == (u32)cq->ibcq.cqe)
468 tail = 0; 410 tail = 0;
469 else 411 else
470 tail++; 412 tail++;
@@ -478,80 +420,131 @@ int hfi1_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
478 vfree(old_wc); 420 vfree(old_wc);
479 421
480 if (cq->ip) { 422 if (cq->ip) {
481 struct hfi1_ibdev *dev = to_idev(ibcq->device); 423 struct rvt_mmap_info *ip = cq->ip;
482 struct hfi1_mmap_info *ip = cq->ip;
483 424
484 hfi1_update_mmap_info(dev, ip, sz, wc); 425 rvt_update_mmap_info(rdi, ip, sz, wc);
485 426
486 /* 427 /*
487 * Return the offset to mmap. 428 * Return the offset to mmap.
488 * See hfi1_mmap() for details. 429 * See rvt_mmap() for details.
489 */ 430 */
490 if (udata && udata->outlen >= sizeof(__u64)) { 431 if (udata && udata->outlen >= sizeof(__u64)) {
491 ret = ib_copy_to_udata(udata, &ip->offset, 432 ret = ib_copy_to_udata(udata, &ip->offset,
492 sizeof(ip->offset)); 433 sizeof(ip->offset));
493 if (ret) 434 if (ret)
494 goto bail; 435 return ret;
495 } 436 }
496 437
497 spin_lock_irq(&dev->pending_lock); 438 spin_lock_irq(&rdi->pending_lock);
498 if (list_empty(&ip->pending_mmaps)) 439 if (list_empty(&ip->pending_mmaps))
499 list_add(&ip->pending_mmaps, &dev->pending_mmaps); 440 list_add(&ip->pending_mmaps, &rdi->pending_mmaps);
500 spin_unlock_irq(&dev->pending_lock); 441 spin_unlock_irq(&rdi->pending_lock);
501 } 442 }
502 443
503 ret = 0; 444 return 0;
504 goto bail;
505 445
506bail_unlock: 446bail_unlock:
507 spin_unlock_irq(&cq->lock); 447 spin_unlock_irq(&cq->lock);
508bail_free: 448bail_free:
509 vfree(wc); 449 vfree(wc);
510bail:
511 return ret; 450 return ret;
512} 451}
513 452
514int hfi1_cq_init(struct hfi1_devdata *dd) 453/**
454 * rvt_poll_cq - poll for work completion entries
455 * @ibcq: the completion queue to poll
456 * @num_entries: the maximum number of entries to return
457 * @entry: pointer to array where work completions are placed
458 *
459 * This may be called from interrupt context. Also called by ib_poll_cq()
460 * in the generic verbs code.
461 *
462 * Return: the number of completion entries polled.
463 */
464int rvt_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
465{
466 struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
467 struct rvt_cq_wc *wc;
468 unsigned long flags;
469 int npolled;
470 u32 tail;
471
472 /* The kernel can only poll a kernel completion queue */
473 if (cq->ip)
474 return -EINVAL;
475
476 spin_lock_irqsave(&cq->lock, flags);
477
478 wc = cq->queue;
479 tail = wc->tail;
480 if (tail > (u32)cq->ibcq.cqe)
481 tail = (u32)cq->ibcq.cqe;
482 for (npolled = 0; npolled < num_entries; ++npolled, ++entry) {
483 if (tail == wc->head)
484 break;
485 /* The kernel doesn't need a RMB since it has the lock. */
486 *entry = wc->kqueue[tail];
487 if (tail >= cq->ibcq.cqe)
488 tail = 0;
489 else
490 tail++;
491 }
492 wc->tail = tail;
493
494 spin_unlock_irqrestore(&cq->lock, flags);
495
496 return npolled;
497}
498
499/**
500 * rvt_driver_cq_init - Init cq resources on behalf of driver
501 * @rdi: rvt dev structure
502 *
503 * Return: 0 on success
504 */
505int rvt_driver_cq_init(struct rvt_dev_info *rdi)
515{ 506{
516 int ret = 0; 507 int ret = 0;
517 int cpu; 508 int cpu;
518 struct task_struct *task; 509 struct task_struct *task;
519 510
520 if (dd->worker) 511 if (rdi->worker)
521 return 0; 512 return 0;
522 dd->worker = kzalloc(sizeof(*dd->worker), GFP_KERNEL); 513 rdi->worker = kzalloc(sizeof(*rdi->worker), GFP_KERNEL);
523 if (!dd->worker) 514 if (!rdi->worker)
524 return -ENOMEM; 515 return -ENOMEM;
525 init_kthread_worker(dd->worker); 516 init_kthread_worker(rdi->worker);
526 task = kthread_create_on_node( 517 task = kthread_create_on_node(
527 kthread_worker_fn, 518 kthread_worker_fn,
528 dd->worker, 519 rdi->worker,
529 dd->assigned_node_id, 520 rdi->dparms.node,
530 "hfi1_cq%d", dd->unit); 521 "%s", rdi->dparms.cq_name);
531 if (IS_ERR(task)) 522 if (IS_ERR(task)) {
532 goto task_fail; 523 kfree(rdi->worker);
533 cpu = cpumask_first(cpumask_of_node(dd->assigned_node_id)); 524 rdi->worker = NULL;
525 return PTR_ERR(task);
526 }
527
528 cpu = cpumask_first(cpumask_of_node(rdi->dparms.node));
534 kthread_bind(task, cpu); 529 kthread_bind(task, cpu);
535 wake_up_process(task); 530 wake_up_process(task);
536out:
537 return ret; 531 return ret;
538task_fail:
539 ret = PTR_ERR(task);
540 kfree(dd->worker);
541 dd->worker = NULL;
542 goto out;
543} 532}
544 533
545void hfi1_cq_exit(struct hfi1_devdata *dd) 534/**
535 * rvt_cq_exit - tear down cq reources
536 * @rdi: rvt dev structure
537 */
538void rvt_cq_exit(struct rvt_dev_info *rdi)
546{ 539{
547 struct kthread_worker *worker; 540 struct kthread_worker *worker;
548 541
549 worker = dd->worker; 542 worker = rdi->worker;
550 if (!worker) 543 if (!worker)
551 return; 544 return;
552 /* blocks future queuing from send_complete() */ 545 /* blocks future queuing from send_complete() */
553 dd->worker = NULL; 546 rdi->worker = NULL;
554 smp_wmb(); /* See hfi1_cq_enter */ 547 smp_wmb(); /* See rdi_cq_enter */
555 flush_kthread_worker(worker); 548 flush_kthread_worker(worker);
556 kthread_stop(worker->task); 549 kthread_stop(worker->task);
557 kfree(worker); 550 kfree(worker);
diff --git a/drivers/infiniband/sw/rdmavt/cq.h b/drivers/infiniband/sw/rdmavt/cq.h
new file mode 100644
index 000000000000..6182c29eff66
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/cq.h
@@ -0,0 +1,64 @@
1#ifndef DEF_RVTCQ_H
2#define DEF_RVTCQ_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52#include <rdma/rdmavt_cq.h>
53
54struct ib_cq *rvt_create_cq(struct ib_device *ibdev,
55 const struct ib_cq_init_attr *attr,
56 struct ib_ucontext *context,
57 struct ib_udata *udata);
58int rvt_destroy_cq(struct ib_cq *ibcq);
59int rvt_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags);
60int rvt_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
61int rvt_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
62int rvt_driver_cq_init(struct rvt_dev_info *rdi);
63void rvt_cq_exit(struct rvt_dev_info *rdi);
64#endif /* DEF_RVTCQ_H */
diff --git a/drivers/infiniband/sw/rdmavt/dma.c b/drivers/infiniband/sw/rdmavt/dma.c
new file mode 100644
index 000000000000..33076a5eee2f
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/dma.c
@@ -0,0 +1,184 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#include <linux/types.h>
48#include <linux/scatterlist.h>
49#include <rdma/ib_verbs.h>
50
51#include "dma.h"
52
53#define BAD_DMA_ADDRESS ((u64)0)
54
55/*
56 * The following functions implement driver specific replacements
57 * for the ib_dma_*() functions.
58 *
59 * These functions return kernel virtual addresses instead of
60 * device bus addresses since the driver uses the CPU to copy
61 * data instead of using hardware DMA.
62 */
63
64static int rvt_mapping_error(struct ib_device *dev, u64 dma_addr)
65{
66 return dma_addr == BAD_DMA_ADDRESS;
67}
68
69static u64 rvt_dma_map_single(struct ib_device *dev, void *cpu_addr,
70 size_t size, enum dma_data_direction direction)
71{
72 if (WARN_ON(!valid_dma_direction(direction)))
73 return BAD_DMA_ADDRESS;
74
75 return (u64)cpu_addr;
76}
77
78static void rvt_dma_unmap_single(struct ib_device *dev, u64 addr, size_t size,
79 enum dma_data_direction direction)
80{
81 /* This is a stub, nothing to be done here */
82}
83
84static u64 rvt_dma_map_page(struct ib_device *dev, struct page *page,
85 unsigned long offset, size_t size,
86 enum dma_data_direction direction)
87{
88 u64 addr;
89
90 if (WARN_ON(!valid_dma_direction(direction)))
91 return BAD_DMA_ADDRESS;
92
93 if (offset + size > PAGE_SIZE)
94 return BAD_DMA_ADDRESS;
95
96 addr = (u64)page_address(page);
97 if (addr)
98 addr += offset;
99
100 return addr;
101}
102
103static void rvt_dma_unmap_page(struct ib_device *dev, u64 addr, size_t size,
104 enum dma_data_direction direction)
105{
106 /* This is a stub, nothing to be done here */
107}
108
109static int rvt_map_sg(struct ib_device *dev, struct scatterlist *sgl,
110 int nents, enum dma_data_direction direction)
111{
112 struct scatterlist *sg;
113 u64 addr;
114 int i;
115 int ret = nents;
116
117 if (WARN_ON(!valid_dma_direction(direction)))
118 return 0;
119
120 for_each_sg(sgl, sg, nents, i) {
121 addr = (u64)page_address(sg_page(sg));
122 if (!addr) {
123 ret = 0;
124 break;
125 }
126 sg->dma_address = addr + sg->offset;
127#ifdef CONFIG_NEED_SG_DMA_LENGTH
128 sg->dma_length = sg->length;
129#endif
130 }
131 return ret;
132}
133
134static void rvt_unmap_sg(struct ib_device *dev,
135 struct scatterlist *sg, int nents,
136 enum dma_data_direction direction)
137{
138 /* This is a stub, nothing to be done here */
139}
140
141static void rvt_sync_single_for_cpu(struct ib_device *dev, u64 addr,
142 size_t size, enum dma_data_direction dir)
143{
144}
145
146static void rvt_sync_single_for_device(struct ib_device *dev, u64 addr,
147 size_t size,
148 enum dma_data_direction dir)
149{
150}
151
152static void *rvt_dma_alloc_coherent(struct ib_device *dev, size_t size,
153 u64 *dma_handle, gfp_t flag)
154{
155 struct page *p;
156 void *addr = NULL;
157
158 p = alloc_pages(flag, get_order(size));
159 if (p)
160 addr = page_address(p);
161 if (dma_handle)
162 *dma_handle = (u64)addr;
163 return addr;
164}
165
166static void rvt_dma_free_coherent(struct ib_device *dev, size_t size,
167 void *cpu_addr, u64 dma_handle)
168{
169 free_pages((unsigned long)cpu_addr, get_order(size));
170}
171
172struct ib_dma_mapping_ops rvt_default_dma_mapping_ops = {
173 .mapping_error = rvt_mapping_error,
174 .map_single = rvt_dma_map_single,
175 .unmap_single = rvt_dma_unmap_single,
176 .map_page = rvt_dma_map_page,
177 .unmap_page = rvt_dma_unmap_page,
178 .map_sg = rvt_map_sg,
179 .unmap_sg = rvt_unmap_sg,
180 .sync_single_for_cpu = rvt_sync_single_for_cpu,
181 .sync_single_for_device = rvt_sync_single_for_device,
182 .alloc_coherent = rvt_dma_alloc_coherent,
183 .free_coherent = rvt_dma_free_coherent
184};
diff --git a/drivers/infiniband/sw/rdmavt/dma.h b/drivers/infiniband/sw/rdmavt/dma.h
new file mode 100644
index 000000000000..979f07e09195
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/dma.h
@@ -0,0 +1,53 @@
1#ifndef DEF_RDMAVTDMA_H
2#define DEF_RDMAVTDMA_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51extern struct ib_dma_mapping_ops rvt_default_dma_mapping_ops;
52
53#endif /* DEF_RDMAVTDMA_H */
diff --git a/drivers/infiniband/sw/rdmavt/mad.c b/drivers/infiniband/sw/rdmavt/mad.c
new file mode 100644
index 000000000000..f6e99778d7ca
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/mad.c
@@ -0,0 +1,171 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <rdma/ib_mad.h>
49#include "mad.h"
50#include "vt.h"
51
52/**
53 * rvt_process_mad - process an incoming MAD packet
54 * @ibdev: the infiniband device this packet came in on
55 * @mad_flags: MAD flags
56 * @port_num: the port number this packet came in on, 1 based from ib core
57 * @in_wc: the work completion entry for this packet
58 * @in_grh: the global route header for this packet
59 * @in_mad: the incoming MAD
60 * @out_mad: any outgoing MAD reply
61 *
62 * Note that the verbs framework has already done the MAD sanity checks,
63 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
64 * MADs.
65 *
66 * This is called by the ib_mad module.
67 *
68 * Return: IB_MAD_RESULT_SUCCESS or error
69 */
70int rvt_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
71 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
72 const struct ib_mad_hdr *in, size_t in_mad_size,
73 struct ib_mad_hdr *out, size_t *out_mad_size,
74 u16 *out_mad_pkey_index)
75{
76 /*
77 * MAD processing is quite different between hfi1 and qib. Therfore this
78 * is expected to be provided by the driver. Other drivers in the future
79 * may chose to implement this but it should not be made into a
80 * requirement.
81 */
82 if (ibport_num_to_idx(ibdev, port_num) < 0)
83 return -EINVAL;
84
85 return IB_MAD_RESULT_FAILURE;
86}
87
88static void rvt_send_mad_handler(struct ib_mad_agent *agent,
89 struct ib_mad_send_wc *mad_send_wc)
90{
91 ib_free_send_mad(mad_send_wc->send_buf);
92}
93
94/**
95 * rvt_create_mad_agents - create mad agents
96 * @rdi: rvt dev struct
97 *
98 * If driver needs to be notified of mad agent creation then call back
99 *
100 * Return 0 on success
101 */
102int rvt_create_mad_agents(struct rvt_dev_info *rdi)
103{
104 struct ib_mad_agent *agent;
105 struct rvt_ibport *rvp;
106 int p;
107 int ret;
108
109 for (p = 0; p < rdi->dparms.nports; p++) {
110 rvp = rdi->ports[p];
111 agent = ib_register_mad_agent(&rdi->ibdev, p + 1,
112 IB_QPT_SMI,
113 NULL, 0, rvt_send_mad_handler,
114 NULL, NULL, 0);
115 if (IS_ERR(agent)) {
116 ret = PTR_ERR(agent);
117 goto err;
118 }
119
120 rvp->send_agent = agent;
121
122 if (rdi->driver_f.notify_create_mad_agent)
123 rdi->driver_f.notify_create_mad_agent(rdi, p);
124 }
125
126 return 0;
127
128err:
129 for (p = 0; p < rdi->dparms.nports; p++) {
130 rvp = rdi->ports[p];
131 if (rvp->send_agent) {
132 agent = rvp->send_agent;
133 rvp->send_agent = NULL;
134 ib_unregister_mad_agent(agent);
135 if (rdi->driver_f.notify_free_mad_agent)
136 rdi->driver_f.notify_free_mad_agent(rdi, p);
137 }
138 }
139
140 return ret;
141}
142
143/**
144 * rvt_free_mad_agents - free up mad agents
145 * @rdi: rvt dev struct
146 *
147 * If driver needs notification of mad agent removal make the call back
148 */
149void rvt_free_mad_agents(struct rvt_dev_info *rdi)
150{
151 struct ib_mad_agent *agent;
152 struct rvt_ibport *rvp;
153 int p;
154
155 for (p = 0; p < rdi->dparms.nports; p++) {
156 rvp = rdi->ports[p];
157 if (rvp->send_agent) {
158 agent = rvp->send_agent;
159 rvp->send_agent = NULL;
160 ib_unregister_mad_agent(agent);
161 }
162 if (rvp->sm_ah) {
163 ib_destroy_ah(&rvp->sm_ah->ibah);
164 rvp->sm_ah = NULL;
165 }
166
167 if (rdi->driver_f.notify_free_mad_agent)
168 rdi->driver_f.notify_free_mad_agent(rdi, p);
169 }
170}
171
diff --git a/drivers/infiniband/sw/rdmavt/mad.h b/drivers/infiniband/sw/rdmavt/mad.h
new file mode 100644
index 000000000000..a9d6eecc3723
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/mad.h
@@ -0,0 +1,60 @@
1#ifndef DEF_RVTMAD_H
2#define DEF_RVTMAD_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52
53int rvt_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
54 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
55 const struct ib_mad_hdr *in, size_t in_mad_size,
56 struct ib_mad_hdr *out, size_t *out_mad_size,
57 u16 *out_mad_pkey_index);
58int rvt_create_mad_agents(struct rvt_dev_info *rdi);
59void rvt_free_mad_agents(struct rvt_dev_info *rdi);
60#endif /* DEF_RVTMAD_H */
diff --git a/drivers/staging/rdma/hfi1/verbs_mcast.c b/drivers/infiniband/sw/rdmavt/mcast.c
index afc6b4c61a1d..983d319ac976 100644
--- a/drivers/staging/rdma/hfi1/verbs_mcast.c
+++ b/drivers/infiniband/sw/rdmavt/mcast.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -48,17 +45,36 @@
48 * 45 *
49 */ 46 */
50 47
48#include <linux/slab.h>
49#include <linux/sched.h>
51#include <linux/rculist.h> 50#include <linux/rculist.h>
51#include <rdma/rdma_vt.h>
52#include <rdma/rdmavt_qp.h>
52 53
53#include "hfi.h" 54#include "mcast.h"
55
56/**
57 * rvt_driver_mcast - init resources for multicast
58 * @rdi: rvt dev struct
59 *
60 * This is per device that registers with rdmavt
61 */
62void rvt_driver_mcast_init(struct rvt_dev_info *rdi)
63{
64 /*
65 * Anything that needs setup for multicast on a per driver or per rdi
66 * basis should be done in here.
67 */
68 spin_lock_init(&rdi->n_mcast_grps_lock);
69}
54 70
55/** 71/**
56 * mcast_qp_alloc - alloc a struct to link a QP to mcast GID struct 72 * mcast_qp_alloc - alloc a struct to link a QP to mcast GID struct
57 * @qp: the QP to link 73 * @qp: the QP to link
58 */ 74 */
59static struct hfi1_mcast_qp *mcast_qp_alloc(struct hfi1_qp *qp) 75static struct rvt_mcast_qp *rvt_mcast_qp_alloc(struct rvt_qp *qp)
60{ 76{
61 struct hfi1_mcast_qp *mqp; 77 struct rvt_mcast_qp *mqp;
62 78
63 mqp = kmalloc(sizeof(*mqp), GFP_KERNEL); 79 mqp = kmalloc(sizeof(*mqp), GFP_KERNEL);
64 if (!mqp) 80 if (!mqp)
@@ -71,9 +87,9 @@ bail:
71 return mqp; 87 return mqp;
72} 88}
73 89
74static void mcast_qp_free(struct hfi1_mcast_qp *mqp) 90static void rvt_mcast_qp_free(struct rvt_mcast_qp *mqp)
75{ 91{
76 struct hfi1_qp *qp = mqp->qp; 92 struct rvt_qp *qp = mqp->qp;
77 93
78 /* Notify hfi1_destroy_qp() if it is waiting. */ 94 /* Notify hfi1_destroy_qp() if it is waiting. */
79 if (atomic_dec_and_test(&qp->refcount)) 95 if (atomic_dec_and_test(&qp->refcount))
@@ -88,11 +104,11 @@ static void mcast_qp_free(struct hfi1_mcast_qp *mqp)
88 * 104 *
89 * A list of QPs will be attached to this structure. 105 * A list of QPs will be attached to this structure.
90 */ 106 */
91static struct hfi1_mcast *mcast_alloc(union ib_gid *mgid) 107static struct rvt_mcast *rvt_mcast_alloc(union ib_gid *mgid)
92{ 108{
93 struct hfi1_mcast *mcast; 109 struct rvt_mcast *mcast;
94 110
95 mcast = kmalloc(sizeof(*mcast), GFP_KERNEL); 111 mcast = kzalloc(sizeof(*mcast), GFP_KERNEL);
96 if (!mcast) 112 if (!mcast)
97 goto bail; 113 goto bail;
98 114
@@ -100,75 +116,72 @@ static struct hfi1_mcast *mcast_alloc(union ib_gid *mgid)
100 INIT_LIST_HEAD(&mcast->qp_list); 116 INIT_LIST_HEAD(&mcast->qp_list);
101 init_waitqueue_head(&mcast->wait); 117 init_waitqueue_head(&mcast->wait);
102 atomic_set(&mcast->refcount, 0); 118 atomic_set(&mcast->refcount, 0);
103 mcast->n_attached = 0;
104 119
105bail: 120bail:
106 return mcast; 121 return mcast;
107} 122}
108 123
109static void mcast_free(struct hfi1_mcast *mcast) 124static void rvt_mcast_free(struct rvt_mcast *mcast)
110{ 125{
111 struct hfi1_mcast_qp *p, *tmp; 126 struct rvt_mcast_qp *p, *tmp;
112 127
113 list_for_each_entry_safe(p, tmp, &mcast->qp_list, list) 128 list_for_each_entry_safe(p, tmp, &mcast->qp_list, list)
114 mcast_qp_free(p); 129 rvt_mcast_qp_free(p);
115 130
116 kfree(mcast); 131 kfree(mcast);
117} 132}
118 133
119/** 134/**
120 * hfi1_mcast_find - search the global table for the given multicast GID 135 * rvt_mcast_find - search the global table for the given multicast GID
121 * @ibp: the IB port structure 136 * @ibp: the IB port structure
122 * @mgid: the multicast GID to search for 137 * @mgid: the multicast GID to search for
123 * 138 *
124 * Returns NULL if not found.
125 *
126 * The caller is responsible for decrementing the reference count if found. 139 * The caller is responsible for decrementing the reference count if found.
140 *
141 * Return: NULL if not found.
127 */ 142 */
128struct hfi1_mcast *hfi1_mcast_find(struct hfi1_ibport *ibp, union ib_gid *mgid) 143struct rvt_mcast *rvt_mcast_find(struct rvt_ibport *ibp, union ib_gid *mgid)
129{ 144{
130 struct rb_node *n; 145 struct rb_node *n;
131 unsigned long flags; 146 unsigned long flags;
132 struct hfi1_mcast *mcast; 147 struct rvt_mcast *found = NULL;
133 148
134 spin_lock_irqsave(&ibp->lock, flags); 149 spin_lock_irqsave(&ibp->lock, flags);
135 n = ibp->mcast_tree.rb_node; 150 n = ibp->mcast_tree.rb_node;
136 while (n) { 151 while (n) {
137 int ret; 152 int ret;
153 struct rvt_mcast *mcast;
138 154
139 mcast = rb_entry(n, struct hfi1_mcast, rb_node); 155 mcast = rb_entry(n, struct rvt_mcast, rb_node);
140 156
141 ret = memcmp(mgid->raw, mcast->mgid.raw, 157 ret = memcmp(mgid->raw, mcast->mgid.raw,
142 sizeof(union ib_gid)); 158 sizeof(union ib_gid));
143 if (ret < 0) 159 if (ret < 0) {
144 n = n->rb_left; 160 n = n->rb_left;
145 else if (ret > 0) 161 } else if (ret > 0) {
146 n = n->rb_right; 162 n = n->rb_right;
147 else { 163 } else {
148 atomic_inc(&mcast->refcount); 164 atomic_inc(&mcast->refcount);
149 spin_unlock_irqrestore(&ibp->lock, flags); 165 found = mcast;
150 goto bail; 166 break;
151 } 167 }
152 } 168 }
153 spin_unlock_irqrestore(&ibp->lock, flags); 169 spin_unlock_irqrestore(&ibp->lock, flags);
154 170 return found;
155 mcast = NULL;
156
157bail:
158 return mcast;
159} 171}
172EXPORT_SYMBOL(rvt_mcast_find);
160 173
161/** 174/**
162 * mcast_add - insert mcast GID into table and attach QP struct 175 * mcast_add - insert mcast GID into table and attach QP struct
163 * @mcast: the mcast GID table 176 * @mcast: the mcast GID table
164 * @mqp: the QP to attach 177 * @mqp: the QP to attach
165 * 178 *
166 * Return zero if both were added. Return EEXIST if the GID was already in 179 * Return: zero if both were added. Return EEXIST if the GID was already in
167 * the table but the QP was added. Return ESRCH if the QP was already 180 * the table but the QP was added. Return ESRCH if the QP was already
168 * attached and neither structure was added. 181 * attached and neither structure was added.
169 */ 182 */
170static int mcast_add(struct hfi1_ibdev *dev, struct hfi1_ibport *ibp, 183static int rvt_mcast_add(struct rvt_dev_info *rdi, struct rvt_ibport *ibp,
171 struct hfi1_mcast *mcast, struct hfi1_mcast_qp *mqp) 184 struct rvt_mcast *mcast, struct rvt_mcast_qp *mqp)
172{ 185{
173 struct rb_node **n = &ibp->mcast_tree.rb_node; 186 struct rb_node **n = &ibp->mcast_tree.rb_node;
174 struct rb_node *pn = NULL; 187 struct rb_node *pn = NULL;
@@ -177,11 +190,11 @@ static int mcast_add(struct hfi1_ibdev *dev, struct hfi1_ibport *ibp,
177 spin_lock_irq(&ibp->lock); 190 spin_lock_irq(&ibp->lock);
178 191
179 while (*n) { 192 while (*n) {
180 struct hfi1_mcast *tmcast; 193 struct rvt_mcast *tmcast;
181 struct hfi1_mcast_qp *p; 194 struct rvt_mcast_qp *p;
182 195
183 pn = *n; 196 pn = *n;
184 tmcast = rb_entry(pn, struct hfi1_mcast, rb_node); 197 tmcast = rb_entry(pn, struct rvt_mcast, rb_node);
185 198
186 ret = memcmp(mcast->mgid.raw, tmcast->mgid.raw, 199 ret = memcmp(mcast->mgid.raw, tmcast->mgid.raw,
187 sizeof(union ib_gid)); 200 sizeof(union ib_gid));
@@ -201,7 +214,8 @@ static int mcast_add(struct hfi1_ibdev *dev, struct hfi1_ibport *ibp,
201 goto bail; 214 goto bail;
202 } 215 }
203 } 216 }
204 if (tmcast->n_attached == hfi1_max_mcast_qp_attached) { 217 if (tmcast->n_attached ==
218 rdi->dparms.props.max_mcast_qp_attach) {
205 ret = ENOMEM; 219 ret = ENOMEM;
206 goto bail; 220 goto bail;
207 } 221 }
@@ -213,15 +227,15 @@ static int mcast_add(struct hfi1_ibdev *dev, struct hfi1_ibport *ibp,
213 goto bail; 227 goto bail;
214 } 228 }
215 229
216 spin_lock(&dev->n_mcast_grps_lock); 230 spin_lock(&rdi->n_mcast_grps_lock);
217 if (dev->n_mcast_grps_allocated == hfi1_max_mcast_grps) { 231 if (rdi->n_mcast_grps_allocated == rdi->dparms.props.max_mcast_grp) {
218 spin_unlock(&dev->n_mcast_grps_lock); 232 spin_unlock(&rdi->n_mcast_grps_lock);
219 ret = ENOMEM; 233 ret = ENOMEM;
220 goto bail; 234 goto bail;
221 } 235 }
222 236
223 dev->n_mcast_grps_allocated++; 237 rdi->n_mcast_grps_allocated++;
224 spin_unlock(&dev->n_mcast_grps_lock); 238 spin_unlock(&rdi->n_mcast_grps_lock);
225 239
226 mcast->n_attached++; 240 mcast->n_attached++;
227 241
@@ -239,92 +253,98 @@ bail:
239 return ret; 253 return ret;
240} 254}
241 255
242int hfi1_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 256/**
257 * rvt_attach_mcast - attach a qp to a multicast group
258 * @ibqp: Infiniband qp
259 * @igd: multicast guid
260 * @lid: multicast lid
261 *
262 * Return: 0 on success
263 */
264int rvt_attach_mcast(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
243{ 265{
244 struct hfi1_qp *qp = to_iqp(ibqp); 266 struct rvt_qp *qp = ibqp_to_rvtqp(ibqp);
245 struct hfi1_ibdev *dev = to_idev(ibqp->device); 267 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
246 struct hfi1_ibport *ibp; 268 struct rvt_ibport *ibp = rdi->ports[qp->port_num - 1];
247 struct hfi1_mcast *mcast; 269 struct rvt_mcast *mcast;
248 struct hfi1_mcast_qp *mqp; 270 struct rvt_mcast_qp *mqp;
249 int ret; 271 int ret = -ENOMEM;
250 272
251 if (ibqp->qp_num <= 1 || qp->state == IB_QPS_RESET) { 273 if (ibqp->qp_num <= 1 || qp->state == IB_QPS_RESET)
252 ret = -EINVAL; 274 return -EINVAL;
253 goto bail;
254 }
255 275
256 /* 276 /*
257 * Allocate data structures since its better to do this outside of 277 * Allocate data structures since its better to do this outside of
258 * spin locks and it will most likely be needed. 278 * spin locks and it will most likely be needed.
259 */ 279 */
260 mcast = mcast_alloc(gid); 280 mcast = rvt_mcast_alloc(gid);
261 if (mcast == NULL) { 281 if (!mcast)
262 ret = -ENOMEM; 282 return -ENOMEM;
263 goto bail;
264 }
265 mqp = mcast_qp_alloc(qp);
266 if (mqp == NULL) {
267 mcast_free(mcast);
268 ret = -ENOMEM;
269 goto bail;
270 }
271 ibp = to_iport(ibqp->device, qp->port_num);
272 switch (mcast_add(dev, ibp, mcast, mqp)) {
273 case ESRCH:
274 /* Neither was used: OK to attach the same QP twice. */
275 mcast_qp_free(mqp);
276 mcast_free(mcast);
277 break;
278 283
279 case EEXIST: /* The mcast wasn't used */ 284 mqp = rvt_mcast_qp_alloc(qp);
280 mcast_free(mcast); 285 if (!mqp)
281 break; 286 goto bail_mcast;
282 287
288 switch (rvt_mcast_add(rdi, ibp, mcast, mqp)) {
289 case ESRCH:
290 /* Neither was used: OK to attach the same QP twice. */
291 ret = 0;
292 goto bail_mqp;
293 case EEXIST: /* The mcast wasn't used */
294 ret = 0;
295 goto bail_mcast;
283 case ENOMEM: 296 case ENOMEM:
284 /* Exceeded the maximum number of mcast groups. */ 297 /* Exceeded the maximum number of mcast groups. */
285 mcast_qp_free(mqp);
286 mcast_free(mcast);
287 ret = -ENOMEM; 298 ret = -ENOMEM;
288 goto bail; 299 goto bail_mqp;
289
290 default: 300 default:
291 break; 301 break;
292 } 302 }
293 303
294 ret = 0; 304 return 0;
305
306bail_mqp:
307 rvt_mcast_qp_free(mqp);
308
309bail_mcast:
310 rvt_mcast_free(mcast);
295 311
296bail:
297 return ret; 312 return ret;
298} 313}
299 314
300int hfi1_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 315/**
316 * rvt_detach_mcast - remove a qp from a multicast group
317 * @ibqp: Infiniband qp
318 * @igd: multicast guid
319 * @lid: multicast lid
320 *
321 * Return: 0 on success
322 */
323int rvt_detach_mcast(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
301{ 324{
302 struct hfi1_qp *qp = to_iqp(ibqp); 325 struct rvt_qp *qp = ibqp_to_rvtqp(ibqp);
303 struct hfi1_ibdev *dev = to_idev(ibqp->device); 326 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
304 struct hfi1_ibport *ibp = to_iport(ibqp->device, qp->port_num); 327 struct rvt_ibport *ibp = rdi->ports[qp->port_num - 1];
305 struct hfi1_mcast *mcast = NULL; 328 struct rvt_mcast *mcast = NULL;
306 struct hfi1_mcast_qp *p, *tmp; 329 struct rvt_mcast_qp *p, *tmp, *delp = NULL;
307 struct rb_node *n; 330 struct rb_node *n;
308 int last = 0; 331 int last = 0;
309 int ret; 332 int ret = 0;
310 333
311 if (ibqp->qp_num <= 1 || qp->state == IB_QPS_RESET) { 334 if (ibqp->qp_num <= 1 || qp->state == IB_QPS_RESET)
312 ret = -EINVAL; 335 return -EINVAL;
313 goto bail;
314 }
315 336
316 spin_lock_irq(&ibp->lock); 337 spin_lock_irq(&ibp->lock);
317 338
318 /* Find the GID in the mcast table. */ 339 /* Find the GID in the mcast table. */
319 n = ibp->mcast_tree.rb_node; 340 n = ibp->mcast_tree.rb_node;
320 while (1) { 341 while (1) {
321 if (n == NULL) { 342 if (!n) {
322 spin_unlock_irq(&ibp->lock); 343 spin_unlock_irq(&ibp->lock);
323 ret = -EINVAL; 344 return -EINVAL;
324 goto bail;
325 } 345 }
326 346
327 mcast = rb_entry(n, struct hfi1_mcast, rb_node); 347 mcast = rb_entry(n, struct rvt_mcast, rb_node);
328 ret = memcmp(gid->raw, mcast->mgid.raw, 348 ret = memcmp(gid->raw, mcast->mgid.raw,
329 sizeof(union ib_gid)); 349 sizeof(union ib_gid));
330 if (ret < 0) 350 if (ret < 0)
@@ -345,6 +365,7 @@ int hfi1_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
345 */ 365 */
346 list_del_rcu(&p->list); 366 list_del_rcu(&p->list);
347 mcast->n_attached--; 367 mcast->n_attached--;
368 delp = p;
348 369
349 /* If this was the last attached QP, remove the GID too. */ 370 /* If this was the last attached QP, remove the GID too. */
350 if (list_empty(&mcast->qp_list)) { 371 if (list_empty(&mcast->qp_list)) {
@@ -355,31 +376,42 @@ int hfi1_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
355 } 376 }
356 377
357 spin_unlock_irq(&ibp->lock); 378 spin_unlock_irq(&ibp->lock);
379 /* QP not attached */
380 if (!delp)
381 return -EINVAL;
382
383 /*
384 * Wait for any list walkers to finish before freeing the
385 * list element.
386 */
387 wait_event(mcast->wait, atomic_read(&mcast->refcount) <= 1);
388 rvt_mcast_qp_free(delp);
358 389
359 if (p) {
360 /*
361 * Wait for any list walkers to finish before freeing the
362 * list element.
363 */
364 wait_event(mcast->wait, atomic_read(&mcast->refcount) <= 1);
365 mcast_qp_free(p);
366 }
367 if (last) { 390 if (last) {
368 atomic_dec(&mcast->refcount); 391 atomic_dec(&mcast->refcount);
369 wait_event(mcast->wait, !atomic_read(&mcast->refcount)); 392 wait_event(mcast->wait, !atomic_read(&mcast->refcount));
370 mcast_free(mcast); 393 rvt_mcast_free(mcast);
371 spin_lock_irq(&dev->n_mcast_grps_lock); 394 spin_lock_irq(&rdi->n_mcast_grps_lock);
372 dev->n_mcast_grps_allocated--; 395 rdi->n_mcast_grps_allocated--;
373 spin_unlock_irq(&dev->n_mcast_grps_lock); 396 spin_unlock_irq(&rdi->n_mcast_grps_lock);
374 } 397 }
375 398
376 ret = 0; 399 return 0;
377
378bail:
379 return ret;
380} 400}
381 401
382int hfi1_mcast_tree_empty(struct hfi1_ibport *ibp) 402/**
403 *rvt_mast_tree_empty - determine if any qps are attached to any mcast group
404 *@rdi: rvt dev struct
405 *
406 * Return: in use count
407 */
408int rvt_mcast_tree_empty(struct rvt_dev_info *rdi)
383{ 409{
384 return ibp->mcast_tree.rb_node == NULL; 410 int i;
411 int in_use = 0;
412
413 for (i = 0; i < rdi->dparms.nports; i++)
414 if (rdi->ports[i]->mcast_tree.rb_node)
415 in_use++;
416 return in_use;
385} 417}
diff --git a/drivers/infiniband/sw/rdmavt/mcast.h b/drivers/infiniband/sw/rdmavt/mcast.h
new file mode 100644
index 000000000000..29f579267608
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/mcast.h
@@ -0,0 +1,58 @@
1#ifndef DEF_RVTMCAST_H
2#define DEF_RVTMCAST_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52
53void rvt_driver_mcast_init(struct rvt_dev_info *rdi);
54int rvt_attach_mcast(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
55int rvt_detach_mcast(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
56int rvt_mcast_tree_empty(struct rvt_dev_info *rdi);
57
58#endif /* DEF_RVTMCAST_H */
diff --git a/drivers/staging/rdma/hfi1/mmap.c b/drivers/infiniband/sw/rdmavt/mmap.c
index 5173b1c60b3d..e202b8142759 100644
--- a/drivers/staging/rdma/hfi1/mmap.c
+++ b/drivers/infiniband/sw/rdmavt/mmap.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -48,68 +45,74 @@
48 * 45 *
49 */ 46 */
50 47
51#include <linux/module.h>
52#include <linux/slab.h> 48#include <linux/slab.h>
53#include <linux/vmalloc.h> 49#include <linux/vmalloc.h>
54#include <linux/mm.h> 50#include <linux/mm.h>
55#include <linux/errno.h>
56#include <asm/pgtable.h> 51#include <asm/pgtable.h>
52#include "mmap.h"
57 53
58#include "verbs.h" 54/**
55 * rvt_mmap_init - init link list and lock for mem map
56 * @rdi: rvt dev struct
57 */
58void rvt_mmap_init(struct rvt_dev_info *rdi)
59{
60 INIT_LIST_HEAD(&rdi->pending_mmaps);
61 spin_lock_init(&rdi->pending_lock);
62 rdi->mmap_offset = PAGE_SIZE;
63 spin_lock_init(&rdi->mmap_offset_lock);
64}
59 65
60/** 66/**
61 * hfi1_release_mmap_info - free mmap info structure 67 * rvt_release_mmap_info - free mmap info structure
62 * @ref: a pointer to the kref within struct hfi1_mmap_info 68 * @ref: a pointer to the kref within struct rvt_mmap_info
63 */ 69 */
64void hfi1_release_mmap_info(struct kref *ref) 70void rvt_release_mmap_info(struct kref *ref)
65{ 71{
66 struct hfi1_mmap_info *ip = 72 struct rvt_mmap_info *ip =
67 container_of(ref, struct hfi1_mmap_info, ref); 73 container_of(ref, struct rvt_mmap_info, ref);
68 struct hfi1_ibdev *dev = to_idev(ip->context->device); 74 struct rvt_dev_info *rdi = ib_to_rvt(ip->context->device);
69 75
70 spin_lock_irq(&dev->pending_lock); 76 spin_lock_irq(&rdi->pending_lock);
71 list_del(&ip->pending_mmaps); 77 list_del(&ip->pending_mmaps);
72 spin_unlock_irq(&dev->pending_lock); 78 spin_unlock_irq(&rdi->pending_lock);
73 79
74 vfree(ip->obj); 80 vfree(ip->obj);
75 kfree(ip); 81 kfree(ip);
76} 82}
77 83
78/* 84static void rvt_vma_open(struct vm_area_struct *vma)
79 * open and close keep track of how many times the CQ is mapped,
80 * to avoid releasing it.
81 */
82static void hfi1_vma_open(struct vm_area_struct *vma)
83{ 85{
84 struct hfi1_mmap_info *ip = vma->vm_private_data; 86 struct rvt_mmap_info *ip = vma->vm_private_data;
85 87
86 kref_get(&ip->ref); 88 kref_get(&ip->ref);
87} 89}
88 90
89static void hfi1_vma_close(struct vm_area_struct *vma) 91static void rvt_vma_close(struct vm_area_struct *vma)
90{ 92{
91 struct hfi1_mmap_info *ip = vma->vm_private_data; 93 struct rvt_mmap_info *ip = vma->vm_private_data;
92 94
93 kref_put(&ip->ref, hfi1_release_mmap_info); 95 kref_put(&ip->ref, rvt_release_mmap_info);
94} 96}
95 97
96static struct vm_operations_struct hfi1_vm_ops = { 98static const struct vm_operations_struct rvt_vm_ops = {
97 .open = hfi1_vma_open, 99 .open = rvt_vma_open,
98 .close = hfi1_vma_close, 100 .close = rvt_vma_close,
99}; 101};
100 102
101/** 103/**
102 * hfi1_mmap - create a new mmap region 104 * rvt_mmap - create a new mmap region
103 * @context: the IB user context of the process making the mmap() call 105 * @context: the IB user context of the process making the mmap() call
104 * @vma: the VMA to be initialized 106 * @vma: the VMA to be initialized
105 * Return zero if the mmap is OK. Otherwise, return an errno. 107 *
108 * Return: zero if the mmap is OK. Otherwise, return an errno.
106 */ 109 */
107int hfi1_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) 110int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
108{ 111{
109 struct hfi1_ibdev *dev = to_idev(context->device); 112 struct rvt_dev_info *rdi = ib_to_rvt(context->device);
110 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 113 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
111 unsigned long size = vma->vm_end - vma->vm_start; 114 unsigned long size = vma->vm_end - vma->vm_start;
112 struct hfi1_mmap_info *ip, *pp; 115 struct rvt_mmap_info *ip, *pp;
113 int ret = -EINVAL; 116 int ret = -EINVAL;
114 117
115 /* 118 /*
@@ -117,53 +120,60 @@ int hfi1_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
117 * Normally, this list is very short since a call to create a 120 * Normally, this list is very short since a call to create a
118 * CQ, QP, or SRQ is soon followed by a call to mmap(). 121 * CQ, QP, or SRQ is soon followed by a call to mmap().
119 */ 122 */
120 spin_lock_irq(&dev->pending_lock); 123 spin_lock_irq(&rdi->pending_lock);
121 list_for_each_entry_safe(ip, pp, &dev->pending_mmaps, 124 list_for_each_entry_safe(ip, pp, &rdi->pending_mmaps,
122 pending_mmaps) { 125 pending_mmaps) {
123 /* Only the creator is allowed to mmap the object */ 126 /* Only the creator is allowed to mmap the object */
124 if (context != ip->context || (__u64) offset != ip->offset) 127 if (context != ip->context || (__u64)offset != ip->offset)
125 continue; 128 continue;
126 /* Don't allow a mmap larger than the object. */ 129 /* Don't allow a mmap larger than the object. */
127 if (size > ip->size) 130 if (size > ip->size)
128 break; 131 break;
129 132
130 list_del_init(&ip->pending_mmaps); 133 list_del_init(&ip->pending_mmaps);
131 spin_unlock_irq(&dev->pending_lock); 134 spin_unlock_irq(&rdi->pending_lock);
132 135
133 ret = remap_vmalloc_range(vma, ip->obj, 0); 136 ret = remap_vmalloc_range(vma, ip->obj, 0);
134 if (ret) 137 if (ret)
135 goto done; 138 goto done;
136 vma->vm_ops = &hfi1_vm_ops; 139 vma->vm_ops = &rvt_vm_ops;
137 vma->vm_private_data = ip; 140 vma->vm_private_data = ip;
138 hfi1_vma_open(vma); 141 rvt_vma_open(vma);
139 goto done; 142 goto done;
140 } 143 }
141 spin_unlock_irq(&dev->pending_lock); 144 spin_unlock_irq(&rdi->pending_lock);
142done: 145done:
143 return ret; 146 return ret;
144} 147}
145 148
146/* 149/**
147 * Allocate information for hfi1_mmap 150 * rvt_create_mmap_info - allocate information for hfi1_mmap
151 * @rdi: rvt dev struct
152 * @size: size in bytes to map
153 * @context: user context
154 * @obj: opaque pointer to a cq, wq etc
155 *
156 * Return: rvt_mmap struct on success
148 */ 157 */
149struct hfi1_mmap_info *hfi1_create_mmap_info(struct hfi1_ibdev *dev, 158struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi,
150 u32 size, 159 u32 size,
151 struct ib_ucontext *context, 160 struct ib_ucontext *context,
152 void *obj) { 161 void *obj)
153 struct hfi1_mmap_info *ip; 162{
163 struct rvt_mmap_info *ip;
154 164
155 ip = kmalloc(sizeof(*ip), GFP_KERNEL); 165 ip = kmalloc_node(sizeof(*ip), GFP_KERNEL, rdi->dparms.node);
156 if (!ip) 166 if (!ip)
157 goto bail; 167 return ip;
158 168
159 size = PAGE_ALIGN(size); 169 size = PAGE_ALIGN(size);
160 170
161 spin_lock_irq(&dev->mmap_offset_lock); 171 spin_lock_irq(&rdi->mmap_offset_lock);
162 if (dev->mmap_offset == 0) 172 if (rdi->mmap_offset == 0)
163 dev->mmap_offset = PAGE_SIZE; 173 rdi->mmap_offset = PAGE_SIZE;
164 ip->offset = dev->mmap_offset; 174 ip->offset = rdi->mmap_offset;
165 dev->mmap_offset += size; 175 rdi->mmap_offset += size;
166 spin_unlock_irq(&dev->mmap_offset_lock); 176 spin_unlock_irq(&rdi->mmap_offset_lock);
167 177
168 INIT_LIST_HEAD(&ip->pending_mmaps); 178 INIT_LIST_HEAD(&ip->pending_mmaps);
169 ip->size = size; 179 ip->size = size;
@@ -171,21 +181,27 @@ struct hfi1_mmap_info *hfi1_create_mmap_info(struct hfi1_ibdev *dev,
171 ip->obj = obj; 181 ip->obj = obj;
172 kref_init(&ip->ref); 182 kref_init(&ip->ref);
173 183
174bail:
175 return ip; 184 return ip;
176} 185}
177 186
178void hfi1_update_mmap_info(struct hfi1_ibdev *dev, struct hfi1_mmap_info *ip, 187/**
179 u32 size, void *obj) 188 * rvt_update_mmap_info - update a mem map
189 * @rdi: rvt dev struct
190 * @ip: mmap info pointer
191 * @size: size to grow by
192 * @obj: opaque pointer to cq, wq, etc.
193 */
194void rvt_update_mmap_info(struct rvt_dev_info *rdi, struct rvt_mmap_info *ip,
195 u32 size, void *obj)
180{ 196{
181 size = PAGE_ALIGN(size); 197 size = PAGE_ALIGN(size);
182 198
183 spin_lock_irq(&dev->mmap_offset_lock); 199 spin_lock_irq(&rdi->mmap_offset_lock);
184 if (dev->mmap_offset == 0) 200 if (rdi->mmap_offset == 0)
185 dev->mmap_offset = PAGE_SIZE; 201 rdi->mmap_offset = PAGE_SIZE;
186 ip->offset = dev->mmap_offset; 202 ip->offset = rdi->mmap_offset;
187 dev->mmap_offset += size; 203 rdi->mmap_offset += size;
188 spin_unlock_irq(&dev->mmap_offset_lock); 204 spin_unlock_irq(&rdi->mmap_offset_lock);
189 205
190 ip->size = size; 206 ip->size = size;
191 ip->obj = obj; 207 ip->obj = obj;
diff --git a/drivers/infiniband/sw/rdmavt/mmap.h b/drivers/infiniband/sw/rdmavt/mmap.h
new file mode 100644
index 000000000000..fab0e7b1daf9
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/mmap.h
@@ -0,0 +1,63 @@
1#ifndef DEF_RDMAVTMMAP_H
2#define DEF_RDMAVTMMAP_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52
53void rvt_mmap_init(struct rvt_dev_info *rdi);
54void rvt_release_mmap_info(struct kref *ref);
55int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
56struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi,
57 u32 size,
58 struct ib_ucontext *context,
59 void *obj);
60void rvt_update_mmap_info(struct rvt_dev_info *rdi, struct rvt_mmap_info *ip,
61 u32 size, void *obj);
62
63#endif /* DEF_RDMAVTMMAP_H */
diff --git a/drivers/infiniband/sw/rdmavt/mr.c b/drivers/infiniband/sw/rdmavt/mr.c
new file mode 100644
index 000000000000..0ff765bfd619
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/mr.c
@@ -0,0 +1,830 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <linux/slab.h>
49#include <linux/vmalloc.h>
50#include <rdma/ib_umem.h>
51#include <rdma/rdma_vt.h>
52#include "vt.h"
53#include "mr.h"
54
55/**
56 * rvt_driver_mr_init - Init MR resources per driver
57 * @rdi: rvt dev struct
58 *
59 * Do any intilization needed when a driver registers with rdmavt.
60 *
61 * Return: 0 on success or errno on failure
62 */
63int rvt_driver_mr_init(struct rvt_dev_info *rdi)
64{
65 unsigned int lkey_table_size = rdi->dparms.lkey_table_size;
66 unsigned lk_tab_size;
67 int i;
68
69 /*
70 * The top hfi1_lkey_table_size bits are used to index the
71 * table. The lower 8 bits can be owned by the user (copied from
72 * the LKEY). The remaining bits act as a generation number or tag.
73 */
74 if (!lkey_table_size)
75 return -EINVAL;
76
77 spin_lock_init(&rdi->lkey_table.lock);
78
79 /* ensure generation is at least 4 bits */
80 if (lkey_table_size > RVT_MAX_LKEY_TABLE_BITS) {
81 rvt_pr_warn(rdi, "lkey bits %u too large, reduced to %u\n",
82 lkey_table_size, RVT_MAX_LKEY_TABLE_BITS);
83 rdi->dparms.lkey_table_size = RVT_MAX_LKEY_TABLE_BITS;
84 lkey_table_size = rdi->dparms.lkey_table_size;
85 }
86 rdi->lkey_table.max = 1 << lkey_table_size;
87 lk_tab_size = rdi->lkey_table.max * sizeof(*rdi->lkey_table.table);
88 rdi->lkey_table.table = (struct rvt_mregion __rcu **)
89 vmalloc_node(lk_tab_size, rdi->dparms.node);
90 if (!rdi->lkey_table.table)
91 return -ENOMEM;
92
93 RCU_INIT_POINTER(rdi->dma_mr, NULL);
94 for (i = 0; i < rdi->lkey_table.max; i++)
95 RCU_INIT_POINTER(rdi->lkey_table.table[i], NULL);
96
97 return 0;
98}
99
100/**
101 *rvt_mr_exit: clean up MR
102 *@rdi: rvt dev structure
103 *
104 * called when drivers have unregistered or perhaps failed to register with us
105 */
106void rvt_mr_exit(struct rvt_dev_info *rdi)
107{
108 if (rdi->dma_mr)
109 rvt_pr_err(rdi, "DMA MR not null!\n");
110
111 vfree(rdi->lkey_table.table);
112}
113
114static void rvt_deinit_mregion(struct rvt_mregion *mr)
115{
116 int i = mr->mapsz;
117
118 mr->mapsz = 0;
119 while (i)
120 kfree(mr->map[--i]);
121}
122
123static int rvt_init_mregion(struct rvt_mregion *mr, struct ib_pd *pd,
124 int count)
125{
126 int m, i = 0;
127
128 mr->mapsz = 0;
129 m = (count + RVT_SEGSZ - 1) / RVT_SEGSZ;
130 for (; i < m; i++) {
131 mr->map[i] = kzalloc(sizeof(*mr->map[0]), GFP_KERNEL);
132 if (!mr->map[i]) {
133 rvt_deinit_mregion(mr);
134 return -ENOMEM;
135 }
136 mr->mapsz++;
137 }
138 init_completion(&mr->comp);
139 /* count returning the ptr to user */
140 atomic_set(&mr->refcount, 1);
141 mr->pd = pd;
142 mr->max_segs = count;
143 return 0;
144}
145
146/**
147 * rvt_alloc_lkey - allocate an lkey
148 * @mr: memory region that this lkey protects
149 * @dma_region: 0->normal key, 1->restricted DMA key
150 *
151 * Returns 0 if successful, otherwise returns -errno.
152 *
153 * Increments mr reference count as required.
154 *
155 * Sets the lkey field mr for non-dma regions.
156 *
157 */
158static int rvt_alloc_lkey(struct rvt_mregion *mr, int dma_region)
159{
160 unsigned long flags;
161 u32 r;
162 u32 n;
163 int ret = 0;
164 struct rvt_dev_info *dev = ib_to_rvt(mr->pd->device);
165 struct rvt_lkey_table *rkt = &dev->lkey_table;
166
167 rvt_get_mr(mr);
168 spin_lock_irqsave(&rkt->lock, flags);
169
170 /* special case for dma_mr lkey == 0 */
171 if (dma_region) {
172 struct rvt_mregion *tmr;
173
174 tmr = rcu_access_pointer(dev->dma_mr);
175 if (!tmr) {
176 rcu_assign_pointer(dev->dma_mr, mr);
177 mr->lkey_published = 1;
178 } else {
179 rvt_put_mr(mr);
180 }
181 goto success;
182 }
183
184 /* Find the next available LKEY */
185 r = rkt->next;
186 n = r;
187 for (;;) {
188 if (!rcu_access_pointer(rkt->table[r]))
189 break;
190 r = (r + 1) & (rkt->max - 1);
191 if (r == n)
192 goto bail;
193 }
194 rkt->next = (r + 1) & (rkt->max - 1);
195 /*
196 * Make sure lkey is never zero which is reserved to indicate an
197 * unrestricted LKEY.
198 */
199 rkt->gen++;
200 /*
201 * bits are capped to ensure enough bits for generation number
202 */
203 mr->lkey = (r << (32 - dev->dparms.lkey_table_size)) |
204 ((((1 << (24 - dev->dparms.lkey_table_size)) - 1) & rkt->gen)
205 << 8);
206 if (mr->lkey == 0) {
207 mr->lkey |= 1 << 8;
208 rkt->gen++;
209 }
210 rcu_assign_pointer(rkt->table[r], mr);
211 mr->lkey_published = 1;
212success:
213 spin_unlock_irqrestore(&rkt->lock, flags);
214out:
215 return ret;
216bail:
217 rvt_put_mr(mr);
218 spin_unlock_irqrestore(&rkt->lock, flags);
219 ret = -ENOMEM;
220 goto out;
221}
222
223/**
224 * rvt_free_lkey - free an lkey
225 * @mr: mr to free from tables
226 */
227static void rvt_free_lkey(struct rvt_mregion *mr)
228{
229 unsigned long flags;
230 u32 lkey = mr->lkey;
231 u32 r;
232 struct rvt_dev_info *dev = ib_to_rvt(mr->pd->device);
233 struct rvt_lkey_table *rkt = &dev->lkey_table;
234 int freed = 0;
235
236 spin_lock_irqsave(&rkt->lock, flags);
237 if (!mr->lkey_published)
238 goto out;
239 if (lkey == 0) {
240 RCU_INIT_POINTER(dev->dma_mr, NULL);
241 } else {
242 r = lkey >> (32 - dev->dparms.lkey_table_size);
243 RCU_INIT_POINTER(rkt->table[r], NULL);
244 }
245 mr->lkey_published = 0;
246 freed++;
247out:
248 spin_unlock_irqrestore(&rkt->lock, flags);
249 if (freed) {
250 synchronize_rcu();
251 rvt_put_mr(mr);
252 }
253}
254
255static struct rvt_mr *__rvt_alloc_mr(int count, struct ib_pd *pd)
256{
257 struct rvt_mr *mr;
258 int rval = -ENOMEM;
259 int m;
260
261 /* Allocate struct plus pointers to first level page tables. */
262 m = (count + RVT_SEGSZ - 1) / RVT_SEGSZ;
263 mr = kzalloc(sizeof(*mr) + m * sizeof(mr->mr.map[0]), GFP_KERNEL);
264 if (!mr)
265 goto bail;
266
267 rval = rvt_init_mregion(&mr->mr, pd, count);
268 if (rval)
269 goto bail;
270 /*
271 * ib_reg_phys_mr() will initialize mr->ibmr except for
272 * lkey and rkey.
273 */
274 rval = rvt_alloc_lkey(&mr->mr, 0);
275 if (rval)
276 goto bail_mregion;
277 mr->ibmr.lkey = mr->mr.lkey;
278 mr->ibmr.rkey = mr->mr.lkey;
279done:
280 return mr;
281
282bail_mregion:
283 rvt_deinit_mregion(&mr->mr);
284bail:
285 kfree(mr);
286 mr = ERR_PTR(rval);
287 goto done;
288}
289
290static void __rvt_free_mr(struct rvt_mr *mr)
291{
292 rvt_deinit_mregion(&mr->mr);
293 rvt_free_lkey(&mr->mr);
294 vfree(mr);
295}
296
297/**
298 * rvt_get_dma_mr - get a DMA memory region
299 * @pd: protection domain for this memory region
300 * @acc: access flags
301 *
302 * Return: the memory region on success, otherwise returns an errno.
303 * Note that all DMA addresses should be created via the
304 * struct ib_dma_mapping_ops functions (see dma.c).
305 */
306struct ib_mr *rvt_get_dma_mr(struct ib_pd *pd, int acc)
307{
308 struct rvt_mr *mr;
309 struct ib_mr *ret;
310 int rval;
311
312 if (ibpd_to_rvtpd(pd)->user)
313 return ERR_PTR(-EPERM);
314
315 mr = kzalloc(sizeof(*mr), GFP_KERNEL);
316 if (!mr) {
317 ret = ERR_PTR(-ENOMEM);
318 goto bail;
319 }
320
321 rval = rvt_init_mregion(&mr->mr, pd, 0);
322 if (rval) {
323 ret = ERR_PTR(rval);
324 goto bail;
325 }
326
327 rval = rvt_alloc_lkey(&mr->mr, 1);
328 if (rval) {
329 ret = ERR_PTR(rval);
330 goto bail_mregion;
331 }
332
333 mr->mr.access_flags = acc;
334 ret = &mr->ibmr;
335done:
336 return ret;
337
338bail_mregion:
339 rvt_deinit_mregion(&mr->mr);
340bail:
341 kfree(mr);
342 goto done;
343}
344
345/**
346 * rvt_reg_user_mr - register a userspace memory region
347 * @pd: protection domain for this memory region
348 * @start: starting userspace address
349 * @length: length of region to register
350 * @mr_access_flags: access flags for this memory region
351 * @udata: unused by the driver
352 *
353 * Return: the memory region on success, otherwise returns an errno.
354 */
355struct ib_mr *rvt_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
356 u64 virt_addr, int mr_access_flags,
357 struct ib_udata *udata)
358{
359 struct rvt_mr *mr;
360 struct ib_umem *umem;
361 struct scatterlist *sg;
362 int n, m, entry;
363 struct ib_mr *ret;
364
365 if (length == 0)
366 return ERR_PTR(-EINVAL);
367
368 umem = ib_umem_get(pd->uobject->context, start, length,
369 mr_access_flags, 0);
370 if (IS_ERR(umem))
371 return (void *)umem;
372
373 n = umem->nmap;
374
375 mr = __rvt_alloc_mr(n, pd);
376 if (IS_ERR(mr)) {
377 ret = (struct ib_mr *)mr;
378 goto bail_umem;
379 }
380
381 mr->mr.user_base = start;
382 mr->mr.iova = virt_addr;
383 mr->mr.length = length;
384 mr->mr.offset = ib_umem_offset(umem);
385 mr->mr.access_flags = mr_access_flags;
386 mr->umem = umem;
387
388 if (is_power_of_2(umem->page_size))
389 mr->mr.page_shift = ilog2(umem->page_size);
390 m = 0;
391 n = 0;
392 for_each_sg(umem->sg_head.sgl, sg, umem->nmap, entry) {
393 void *vaddr;
394
395 vaddr = page_address(sg_page(sg));
396 if (!vaddr) {
397 ret = ERR_PTR(-EINVAL);
398 goto bail_inval;
399 }
400 mr->mr.map[m]->segs[n].vaddr = vaddr;
401 mr->mr.map[m]->segs[n].length = umem->page_size;
402 n++;
403 if (n == RVT_SEGSZ) {
404 m++;
405 n = 0;
406 }
407 }
408 return &mr->ibmr;
409
410bail_inval:
411 __rvt_free_mr(mr);
412
413bail_umem:
414 ib_umem_release(umem);
415
416 return ret;
417}
418
419/**
420 * rvt_dereg_mr - unregister and free a memory region
421 * @ibmr: the memory region to free
422 *
423 *
424 * Note that this is called to free MRs created by rvt_get_dma_mr()
425 * or rvt_reg_user_mr().
426 *
427 * Returns 0 on success.
428 */
429int rvt_dereg_mr(struct ib_mr *ibmr)
430{
431 struct rvt_mr *mr = to_imr(ibmr);
432 struct rvt_dev_info *rdi = ib_to_rvt(ibmr->pd->device);
433 int ret = 0;
434 unsigned long timeout;
435
436 rvt_free_lkey(&mr->mr);
437
438 rvt_put_mr(&mr->mr); /* will set completion if last */
439 timeout = wait_for_completion_timeout(&mr->mr.comp, 5 * HZ);
440 if (!timeout) {
441 rvt_pr_err(rdi,
442 "rvt_dereg_mr timeout mr %p pd %p refcount %u\n",
443 mr, mr->mr.pd, atomic_read(&mr->mr.refcount));
444 rvt_get_mr(&mr->mr);
445 ret = -EBUSY;
446 goto out;
447 }
448 rvt_deinit_mregion(&mr->mr);
449 if (mr->umem)
450 ib_umem_release(mr->umem);
451 kfree(mr);
452out:
453 return ret;
454}
455
456/**
457 * rvt_alloc_mr - Allocate a memory region usable with the
458 * @pd: protection domain for this memory region
459 * @mr_type: mem region type
460 * @max_num_sg: Max number of segments allowed
461 *
462 * Return: the memory region on success, otherwise return an errno.
463 */
464struct ib_mr *rvt_alloc_mr(struct ib_pd *pd,
465 enum ib_mr_type mr_type,
466 u32 max_num_sg)
467{
468 struct rvt_mr *mr;
469
470 if (mr_type != IB_MR_TYPE_MEM_REG)
471 return ERR_PTR(-EINVAL);
472
473 mr = __rvt_alloc_mr(max_num_sg, pd);
474 if (IS_ERR(mr))
475 return (struct ib_mr *)mr;
476
477 return &mr->ibmr;
478}
479
480/**
481 * rvt_alloc_fmr - allocate a fast memory region
482 * @pd: the protection domain for this memory region
483 * @mr_access_flags: access flags for this memory region
484 * @fmr_attr: fast memory region attributes
485 *
486 * Return: the memory region on success, otherwise returns an errno.
487 */
488struct ib_fmr *rvt_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
489 struct ib_fmr_attr *fmr_attr)
490{
491 struct rvt_fmr *fmr;
492 int m;
493 struct ib_fmr *ret;
494 int rval = -ENOMEM;
495
496 /* Allocate struct plus pointers to first level page tables. */
497 m = (fmr_attr->max_pages + RVT_SEGSZ - 1) / RVT_SEGSZ;
498 fmr = kzalloc(sizeof(*fmr) + m * sizeof(fmr->mr.map[0]), GFP_KERNEL);
499 if (!fmr)
500 goto bail;
501
502 rval = rvt_init_mregion(&fmr->mr, pd, fmr_attr->max_pages);
503 if (rval)
504 goto bail;
505
506 /*
507 * ib_alloc_fmr() will initialize fmr->ibfmr except for lkey &
508 * rkey.
509 */
510 rval = rvt_alloc_lkey(&fmr->mr, 0);
511 if (rval)
512 goto bail_mregion;
513 fmr->ibfmr.rkey = fmr->mr.lkey;
514 fmr->ibfmr.lkey = fmr->mr.lkey;
515 /*
516 * Resources are allocated but no valid mapping (RKEY can't be
517 * used).
518 */
519 fmr->mr.access_flags = mr_access_flags;
520 fmr->mr.max_segs = fmr_attr->max_pages;
521 fmr->mr.page_shift = fmr_attr->page_shift;
522
523 ret = &fmr->ibfmr;
524done:
525 return ret;
526
527bail_mregion:
528 rvt_deinit_mregion(&fmr->mr);
529bail:
530 kfree(fmr);
531 ret = ERR_PTR(rval);
532 goto done;
533}
534
535/**
536 * rvt_map_phys_fmr - set up a fast memory region
537 * @ibmfr: the fast memory region to set up
538 * @page_list: the list of pages to associate with the fast memory region
539 * @list_len: the number of pages to associate with the fast memory region
540 * @iova: the virtual address of the start of the fast memory region
541 *
542 * This may be called from interrupt context.
543 *
544 * Return: 0 on success
545 */
546
547int rvt_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
548 int list_len, u64 iova)
549{
550 struct rvt_fmr *fmr = to_ifmr(ibfmr);
551 struct rvt_lkey_table *rkt;
552 unsigned long flags;
553 int m, n, i;
554 u32 ps;
555 struct rvt_dev_info *rdi = ib_to_rvt(ibfmr->device);
556
557 i = atomic_read(&fmr->mr.refcount);
558 if (i > 2)
559 return -EBUSY;
560
561 if (list_len > fmr->mr.max_segs)
562 return -EINVAL;
563
564 rkt = &rdi->lkey_table;
565 spin_lock_irqsave(&rkt->lock, flags);
566 fmr->mr.user_base = iova;
567 fmr->mr.iova = iova;
568 ps = 1 << fmr->mr.page_shift;
569 fmr->mr.length = list_len * ps;
570 m = 0;
571 n = 0;
572 for (i = 0; i < list_len; i++) {
573 fmr->mr.map[m]->segs[n].vaddr = (void *)page_list[i];
574 fmr->mr.map[m]->segs[n].length = ps;
575 if (++n == RVT_SEGSZ) {
576 m++;
577 n = 0;
578 }
579 }
580 spin_unlock_irqrestore(&rkt->lock, flags);
581 return 0;
582}
583
584/**
585 * rvt_unmap_fmr - unmap fast memory regions
586 * @fmr_list: the list of fast memory regions to unmap
587 *
588 * Return: 0 on success.
589 */
590int rvt_unmap_fmr(struct list_head *fmr_list)
591{
592 struct rvt_fmr *fmr;
593 struct rvt_lkey_table *rkt;
594 unsigned long flags;
595 struct rvt_dev_info *rdi;
596
597 list_for_each_entry(fmr, fmr_list, ibfmr.list) {
598 rdi = ib_to_rvt(fmr->ibfmr.device);
599 rkt = &rdi->lkey_table;
600 spin_lock_irqsave(&rkt->lock, flags);
601 fmr->mr.user_base = 0;
602 fmr->mr.iova = 0;
603 fmr->mr.length = 0;
604 spin_unlock_irqrestore(&rkt->lock, flags);
605 }
606 return 0;
607}
608
609/**
610 * rvt_dealloc_fmr - deallocate a fast memory region
611 * @ibfmr: the fast memory region to deallocate
612 *
613 * Return: 0 on success.
614 */
615int rvt_dealloc_fmr(struct ib_fmr *ibfmr)
616{
617 struct rvt_fmr *fmr = to_ifmr(ibfmr);
618 int ret = 0;
619 unsigned long timeout;
620
621 rvt_free_lkey(&fmr->mr);
622 rvt_put_mr(&fmr->mr); /* will set completion if last */
623 timeout = wait_for_completion_timeout(&fmr->mr.comp, 5 * HZ);
624 if (!timeout) {
625 rvt_get_mr(&fmr->mr);
626 ret = -EBUSY;
627 goto out;
628 }
629 rvt_deinit_mregion(&fmr->mr);
630 kfree(fmr);
631out:
632 return ret;
633}
634
635/**
636 * rvt_lkey_ok - check IB SGE for validity and initialize
637 * @rkt: table containing lkey to check SGE against
638 * @pd: protection domain
639 * @isge: outgoing internal SGE
640 * @sge: SGE to check
641 * @acc: access flags
642 *
643 * Check the IB SGE for validity and initialize our internal version
644 * of it.
645 *
646 * Return: 1 if valid and successful, otherwise returns 0.
647 *
648 * increments the reference count upon success
649 *
650 */
651int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd,
652 struct rvt_sge *isge, struct ib_sge *sge, int acc)
653{
654 struct rvt_mregion *mr;
655 unsigned n, m;
656 size_t off;
657 struct rvt_dev_info *dev = ib_to_rvt(pd->ibpd.device);
658
659 /*
660 * We use LKEY == zero for kernel virtual addresses
661 * (see rvt_get_dma_mr and dma.c).
662 */
663 rcu_read_lock();
664 if (sge->lkey == 0) {
665 if (pd->user)
666 goto bail;
667 mr = rcu_dereference(dev->dma_mr);
668 if (!mr)
669 goto bail;
670 atomic_inc(&mr->refcount);
671 rcu_read_unlock();
672
673 isge->mr = mr;
674 isge->vaddr = (void *)sge->addr;
675 isge->length = sge->length;
676 isge->sge_length = sge->length;
677 isge->m = 0;
678 isge->n = 0;
679 goto ok;
680 }
681 mr = rcu_dereference(
682 rkt->table[(sge->lkey >> (32 - dev->dparms.lkey_table_size))]);
683 if (unlikely(!mr || mr->lkey != sge->lkey || mr->pd != &pd->ibpd))
684 goto bail;
685
686 off = sge->addr - mr->user_base;
687 if (unlikely(sge->addr < mr->user_base ||
688 off + sge->length > mr->length ||
689 (mr->access_flags & acc) != acc))
690 goto bail;
691 atomic_inc(&mr->refcount);
692 rcu_read_unlock();
693
694 off += mr->offset;
695 if (mr->page_shift) {
696 /*
697 * page sizes are uniform power of 2 so no loop is necessary
698 * entries_spanned_by_off is the number of times the loop below
699 * would have executed.
700 */
701 size_t entries_spanned_by_off;
702
703 entries_spanned_by_off = off >> mr->page_shift;
704 off -= (entries_spanned_by_off << mr->page_shift);
705 m = entries_spanned_by_off / RVT_SEGSZ;
706 n = entries_spanned_by_off % RVT_SEGSZ;
707 } else {
708 m = 0;
709 n = 0;
710 while (off >= mr->map[m]->segs[n].length) {
711 off -= mr->map[m]->segs[n].length;
712 n++;
713 if (n >= RVT_SEGSZ) {
714 m++;
715 n = 0;
716 }
717 }
718 }
719 isge->mr = mr;
720 isge->vaddr = mr->map[m]->segs[n].vaddr + off;
721 isge->length = mr->map[m]->segs[n].length - off;
722 isge->sge_length = sge->length;
723 isge->m = m;
724 isge->n = n;
725ok:
726 return 1;
727bail:
728 rcu_read_unlock();
729 return 0;
730}
731EXPORT_SYMBOL(rvt_lkey_ok);
732
733/**
734 * rvt_rkey_ok - check the IB virtual address, length, and RKEY
735 * @qp: qp for validation
736 * @sge: SGE state
737 * @len: length of data
738 * @vaddr: virtual address to place data
739 * @rkey: rkey to check
740 * @acc: access flags
741 *
742 * Return: 1 if successful, otherwise 0.
743 *
744 * increments the reference count upon success
745 */
746int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
747 u32 len, u64 vaddr, u32 rkey, int acc)
748{
749 struct rvt_dev_info *dev = ib_to_rvt(qp->ibqp.device);
750 struct rvt_lkey_table *rkt = &dev->lkey_table;
751 struct rvt_mregion *mr;
752 unsigned n, m;
753 size_t off;
754
755 /*
756 * We use RKEY == zero for kernel virtual addresses
757 * (see rvt_get_dma_mr and dma.c).
758 */
759 rcu_read_lock();
760 if (rkey == 0) {
761 struct rvt_pd *pd = ibpd_to_rvtpd(qp->ibqp.pd);
762 struct rvt_dev_info *rdi = ib_to_rvt(pd->ibpd.device);
763
764 if (pd->user)
765 goto bail;
766 mr = rcu_dereference(rdi->dma_mr);
767 if (!mr)
768 goto bail;
769 atomic_inc(&mr->refcount);
770 rcu_read_unlock();
771
772 sge->mr = mr;
773 sge->vaddr = (void *)vaddr;
774 sge->length = len;
775 sge->sge_length = len;
776 sge->m = 0;
777 sge->n = 0;
778 goto ok;
779 }
780
781 mr = rcu_dereference(
782 rkt->table[(rkey >> (32 - dev->dparms.lkey_table_size))]);
783 if (unlikely(!mr || mr->lkey != rkey || qp->ibqp.pd != mr->pd))
784 goto bail;
785
786 off = vaddr - mr->iova;
787 if (unlikely(vaddr < mr->iova || off + len > mr->length ||
788 (mr->access_flags & acc) == 0))
789 goto bail;
790 atomic_inc(&mr->refcount);
791 rcu_read_unlock();
792
793 off += mr->offset;
794 if (mr->page_shift) {
795 /*
796 * page sizes are uniform power of 2 so no loop is necessary
797 * entries_spanned_by_off is the number of times the loop below
798 * would have executed.
799 */
800 size_t entries_spanned_by_off;
801
802 entries_spanned_by_off = off >> mr->page_shift;
803 off -= (entries_spanned_by_off << mr->page_shift);
804 m = entries_spanned_by_off / RVT_SEGSZ;
805 n = entries_spanned_by_off % RVT_SEGSZ;
806 } else {
807 m = 0;
808 n = 0;
809 while (off >= mr->map[m]->segs[n].length) {
810 off -= mr->map[m]->segs[n].length;
811 n++;
812 if (n >= RVT_SEGSZ) {
813 m++;
814 n = 0;
815 }
816 }
817 }
818 sge->mr = mr;
819 sge->vaddr = mr->map[m]->segs[n].vaddr + off;
820 sge->length = mr->map[m]->segs[n].length - off;
821 sge->sge_length = len;
822 sge->m = m;
823 sge->n = n;
824ok:
825 return 1;
826bail:
827 rcu_read_unlock();
828 return 0;
829}
830EXPORT_SYMBOL(rvt_rkey_ok);
diff --git a/drivers/infiniband/sw/rdmavt/mr.h b/drivers/infiniband/sw/rdmavt/mr.h
new file mode 100644
index 000000000000..69380512c6d1
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/mr.h
@@ -0,0 +1,92 @@
1#ifndef DEF_RVTMR_H
2#define DEF_RVTMR_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52struct rvt_fmr {
53 struct ib_fmr ibfmr;
54 struct rvt_mregion mr; /* must be last */
55};
56
57struct rvt_mr {
58 struct ib_mr ibmr;
59 struct ib_umem *umem;
60 struct rvt_mregion mr; /* must be last */
61};
62
63static inline struct rvt_fmr *to_ifmr(struct ib_fmr *ibfmr)
64{
65 return container_of(ibfmr, struct rvt_fmr, ibfmr);
66}
67
68static inline struct rvt_mr *to_imr(struct ib_mr *ibmr)
69{
70 return container_of(ibmr, struct rvt_mr, ibmr);
71}
72
73int rvt_driver_mr_init(struct rvt_dev_info *rdi);
74void rvt_mr_exit(struct rvt_dev_info *rdi);
75
76/* Mem Regions */
77struct ib_mr *rvt_get_dma_mr(struct ib_pd *pd, int acc);
78struct ib_mr *rvt_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
79 u64 virt_addr, int mr_access_flags,
80 struct ib_udata *udata);
81int rvt_dereg_mr(struct ib_mr *ibmr);
82struct ib_mr *rvt_alloc_mr(struct ib_pd *pd,
83 enum ib_mr_type mr_type,
84 u32 max_num_sg);
85struct ib_fmr *rvt_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
86 struct ib_fmr_attr *fmr_attr);
87int rvt_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
88 int list_len, u64 iova);
89int rvt_unmap_fmr(struct list_head *fmr_list);
90int rvt_dealloc_fmr(struct ib_fmr *ibfmr);
91
92#endif /* DEF_RVTMR_H */
diff --git a/drivers/infiniband/sw/rdmavt/pd.c b/drivers/infiniband/sw/rdmavt/pd.c
new file mode 100644
index 000000000000..d1292f324c67
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/pd.c
@@ -0,0 +1,119 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <linux/slab.h>
49#include "pd.h"
50
51/**
52 * rvt_alloc_pd - allocate a protection domain
53 * @ibdev: ib device
54 * @context: optional user context
55 * @udata: optional user data
56 *
57 * Allocate and keep track of a PD.
58 *
59 * Return: 0 on success
60 */
61struct ib_pd *rvt_alloc_pd(struct ib_device *ibdev,
62 struct ib_ucontext *context,
63 struct ib_udata *udata)
64{
65 struct rvt_dev_info *dev = ib_to_rvt(ibdev);
66 struct rvt_pd *pd;
67 struct ib_pd *ret;
68
69 pd = kmalloc(sizeof(*pd), GFP_KERNEL);
70 if (!pd) {
71 ret = ERR_PTR(-ENOMEM);
72 goto bail;
73 }
74 /*
75 * While we could continue allocating protecetion domains, being
76 * constrained only by system resources. The IBTA spec defines that
77 * there is a max_pd limit that can be set and we need to check for
78 * that.
79 */
80
81 spin_lock(&dev->n_pds_lock);
82 if (dev->n_pds_allocated == dev->dparms.props.max_pd) {
83 spin_unlock(&dev->n_pds_lock);
84 kfree(pd);
85 ret = ERR_PTR(-ENOMEM);
86 goto bail;
87 }
88
89 dev->n_pds_allocated++;
90 spin_unlock(&dev->n_pds_lock);
91
92 /* ib_alloc_pd() will initialize pd->ibpd. */
93 pd->user = udata ? 1 : 0;
94
95 ret = &pd->ibpd;
96
97bail:
98 return ret;
99}
100
101/**
102 * rvt_dealloc_pd - Free PD
103 * @ibpd: Free up PD
104 *
105 * Return: always 0
106 */
107int rvt_dealloc_pd(struct ib_pd *ibpd)
108{
109 struct rvt_pd *pd = ibpd_to_rvtpd(ibpd);
110 struct rvt_dev_info *dev = ib_to_rvt(ibpd->device);
111
112 spin_lock(&dev->n_pds_lock);
113 dev->n_pds_allocated--;
114 spin_unlock(&dev->n_pds_lock);
115
116 kfree(pd);
117
118 return 0;
119}
diff --git a/drivers/infiniband/sw/rdmavt/pd.h b/drivers/infiniband/sw/rdmavt/pd.h
new file mode 100644
index 000000000000..1892ca4a9746
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/pd.h
@@ -0,0 +1,58 @@
1#ifndef DEF_RDMAVTPD_H
2#define DEF_RDMAVTPD_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52
53struct ib_pd *rvt_alloc_pd(struct ib_device *ibdev,
54 struct ib_ucontext *context,
55 struct ib_udata *udata);
56int rvt_dealloc_pd(struct ib_pd *ibpd);
57
58#endif /* DEF_RDMAVTPD_H */
diff --git a/drivers/infiniband/sw/rdmavt/qp.c b/drivers/infiniband/sw/rdmavt/qp.c
new file mode 100644
index 000000000000..bd82a6948dc8
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/qp.c
@@ -0,0 +1,1696 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <linux/hash.h>
49#include <linux/bitops.h>
50#include <linux/lockdep.h>
51#include <linux/vmalloc.h>
52#include <linux/slab.h>
53#include <rdma/ib_verbs.h>
54#include "qp.h"
55#include "vt.h"
56#include "trace.h"
57
58/*
59 * Note that it is OK to post send work requests in the SQE and ERR
60 * states; rvt_do_send() will process them and generate error
61 * completions as per IB 1.2 C10-96.
62 */
63const int ib_rvt_state_ops[IB_QPS_ERR + 1] = {
64 [IB_QPS_RESET] = 0,
65 [IB_QPS_INIT] = RVT_POST_RECV_OK,
66 [IB_QPS_RTR] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK,
67 [IB_QPS_RTS] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK |
68 RVT_POST_SEND_OK | RVT_PROCESS_SEND_OK |
69 RVT_PROCESS_NEXT_SEND_OK,
70 [IB_QPS_SQD] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK |
71 RVT_POST_SEND_OK | RVT_PROCESS_SEND_OK,
72 [IB_QPS_SQE] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK |
73 RVT_POST_SEND_OK | RVT_FLUSH_SEND,
74 [IB_QPS_ERR] = RVT_POST_RECV_OK | RVT_FLUSH_RECV |
75 RVT_POST_SEND_OK | RVT_FLUSH_SEND,
76};
77EXPORT_SYMBOL(ib_rvt_state_ops);
78
79static void get_map_page(struct rvt_qpn_table *qpt,
80 struct rvt_qpn_map *map,
81 gfp_t gfp)
82{
83 unsigned long page = get_zeroed_page(gfp);
84
85 /*
86 * Free the page if someone raced with us installing it.
87 */
88
89 spin_lock(&qpt->lock);
90 if (map->page)
91 free_page(page);
92 else
93 map->page = (void *)page;
94 spin_unlock(&qpt->lock);
95}
96
97/**
98 * init_qpn_table - initialize the QP number table for a device
99 * @qpt: the QPN table
100 */
101static int init_qpn_table(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt)
102{
103 u32 offset, i;
104 struct rvt_qpn_map *map;
105 int ret = 0;
106
107 if (!(rdi->dparms.qpn_res_end >= rdi->dparms.qpn_res_start))
108 return -EINVAL;
109
110 spin_lock_init(&qpt->lock);
111
112 qpt->last = rdi->dparms.qpn_start;
113 qpt->incr = rdi->dparms.qpn_inc << rdi->dparms.qos_shift;
114
115 /*
116 * Drivers may want some QPs beyond what we need for verbs let them use
117 * our qpn table. No need for two. Lets go ahead and mark the bitmaps
118 * for those. The reserved range must be *after* the range which verbs
119 * will pick from.
120 */
121
122 /* Figure out number of bit maps needed before reserved range */
123 qpt->nmaps = rdi->dparms.qpn_res_start / RVT_BITS_PER_PAGE;
124
125 /* This should always be zero */
126 offset = rdi->dparms.qpn_res_start & RVT_BITS_PER_PAGE_MASK;
127
128 /* Starting with the first reserved bit map */
129 map = &qpt->map[qpt->nmaps];
130
131 rvt_pr_info(rdi, "Reserving QPNs from 0x%x to 0x%x for non-verbs use\n",
132 rdi->dparms.qpn_res_start, rdi->dparms.qpn_res_end);
133 for (i = rdi->dparms.qpn_res_start; i <= rdi->dparms.qpn_res_end; i++) {
134 if (!map->page) {
135 get_map_page(qpt, map, GFP_KERNEL);
136 if (!map->page) {
137 ret = -ENOMEM;
138 break;
139 }
140 }
141 set_bit(offset, map->page);
142 offset++;
143 if (offset == RVT_BITS_PER_PAGE) {
144 /* next page */
145 qpt->nmaps++;
146 map++;
147 offset = 0;
148 }
149 }
150 return ret;
151}
152
153/**
154 * free_qpn_table - free the QP number table for a device
155 * @qpt: the QPN table
156 */
157static void free_qpn_table(struct rvt_qpn_table *qpt)
158{
159 int i;
160
161 for (i = 0; i < ARRAY_SIZE(qpt->map); i++)
162 free_page((unsigned long)qpt->map[i].page);
163}
164
165/**
166 * rvt_driver_qp_init - Init driver qp resources
167 * @rdi: rvt dev strucutre
168 *
169 * Return: 0 on success
170 */
171int rvt_driver_qp_init(struct rvt_dev_info *rdi)
172{
173 int i;
174 int ret = -ENOMEM;
175
176 if (!rdi->dparms.qp_table_size)
177 return -EINVAL;
178
179 /*
180 * If driver is not doing any QP allocation then make sure it is
181 * providing the necessary QP functions.
182 */
183 if (!rdi->driver_f.free_all_qps ||
184 !rdi->driver_f.qp_priv_alloc ||
185 !rdi->driver_f.qp_priv_free ||
186 !rdi->driver_f.notify_qp_reset)
187 return -EINVAL;
188
189 /* allocate parent object */
190 rdi->qp_dev = kzalloc_node(sizeof(*rdi->qp_dev), GFP_KERNEL,
191 rdi->dparms.node);
192 if (!rdi->qp_dev)
193 return -ENOMEM;
194
195 /* allocate hash table */
196 rdi->qp_dev->qp_table_size = rdi->dparms.qp_table_size;
197 rdi->qp_dev->qp_table_bits = ilog2(rdi->dparms.qp_table_size);
198 rdi->qp_dev->qp_table =
199 kmalloc_node(rdi->qp_dev->qp_table_size *
200 sizeof(*rdi->qp_dev->qp_table),
201 GFP_KERNEL, rdi->dparms.node);
202 if (!rdi->qp_dev->qp_table)
203 goto no_qp_table;
204
205 for (i = 0; i < rdi->qp_dev->qp_table_size; i++)
206 RCU_INIT_POINTER(rdi->qp_dev->qp_table[i], NULL);
207
208 spin_lock_init(&rdi->qp_dev->qpt_lock);
209
210 /* initialize qpn map */
211 if (init_qpn_table(rdi, &rdi->qp_dev->qpn_table))
212 goto fail_table;
213
214 spin_lock_init(&rdi->n_qps_lock);
215
216 return 0;
217
218fail_table:
219 kfree(rdi->qp_dev->qp_table);
220 free_qpn_table(&rdi->qp_dev->qpn_table);
221
222no_qp_table:
223 kfree(rdi->qp_dev);
224
225 return ret;
226}
227
228/**
229 * free_all_qps - check for QPs still in use
230 * @qpt: the QP table to empty
231 *
232 * There should not be any QPs still in use.
233 * Free memory for table.
234 */
235static unsigned rvt_free_all_qps(struct rvt_dev_info *rdi)
236{
237 unsigned long flags;
238 struct rvt_qp *qp;
239 unsigned n, qp_inuse = 0;
240 spinlock_t *ql; /* work around too long line below */
241
242 if (rdi->driver_f.free_all_qps)
243 qp_inuse = rdi->driver_f.free_all_qps(rdi);
244
245 qp_inuse += rvt_mcast_tree_empty(rdi);
246
247 if (!rdi->qp_dev)
248 return qp_inuse;
249
250 ql = &rdi->qp_dev->qpt_lock;
251 spin_lock_irqsave(ql, flags);
252 for (n = 0; n < rdi->qp_dev->qp_table_size; n++) {
253 qp = rcu_dereference_protected(rdi->qp_dev->qp_table[n],
254 lockdep_is_held(ql));
255 RCU_INIT_POINTER(rdi->qp_dev->qp_table[n], NULL);
256
257 for (; qp; qp = rcu_dereference_protected(qp->next,
258 lockdep_is_held(ql)))
259 qp_inuse++;
260 }
261 spin_unlock_irqrestore(ql, flags);
262 synchronize_rcu();
263 return qp_inuse;
264}
265
266/**
267 * rvt_qp_exit - clean up qps on device exit
268 * @rdi: rvt dev structure
269 *
270 * Check for qp leaks and free resources.
271 */
272void rvt_qp_exit(struct rvt_dev_info *rdi)
273{
274 u32 qps_inuse = rvt_free_all_qps(rdi);
275
276 if (qps_inuse)
277 rvt_pr_err(rdi, "QP memory leak! %u still in use\n",
278 qps_inuse);
279 if (!rdi->qp_dev)
280 return;
281
282 kfree(rdi->qp_dev->qp_table);
283 free_qpn_table(&rdi->qp_dev->qpn_table);
284 kfree(rdi->qp_dev);
285}
286
287static inline unsigned mk_qpn(struct rvt_qpn_table *qpt,
288 struct rvt_qpn_map *map, unsigned off)
289{
290 return (map - qpt->map) * RVT_BITS_PER_PAGE + off;
291}
292
293/**
294 * alloc_qpn - Allocate the next available qpn or zero/one for QP type
295 * IB_QPT_SMI/IB_QPT_GSI
296 *@rdi: rvt device info structure
297 *@qpt: queue pair number table pointer
298 *@port_num: IB port number, 1 based, comes from core
299 *
300 * Return: The queue pair number
301 */
302static int alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
303 enum ib_qp_type type, u8 port_num, gfp_t gfp)
304{
305 u32 i, offset, max_scan, qpn;
306 struct rvt_qpn_map *map;
307 u32 ret;
308
309 if (rdi->driver_f.alloc_qpn)
310 return rdi->driver_f.alloc_qpn(rdi, qpt, type, port_num, gfp);
311
312 if (type == IB_QPT_SMI || type == IB_QPT_GSI) {
313 unsigned n;
314
315 ret = type == IB_QPT_GSI;
316 n = 1 << (ret + 2 * (port_num - 1));
317 spin_lock(&qpt->lock);
318 if (qpt->flags & n)
319 ret = -EINVAL;
320 else
321 qpt->flags |= n;
322 spin_unlock(&qpt->lock);
323 goto bail;
324 }
325
326 qpn = qpt->last + qpt->incr;
327 if (qpn >= RVT_QPN_MAX)
328 qpn = qpt->incr | ((qpt->last & 1) ^ 1);
329 /* offset carries bit 0 */
330 offset = qpn & RVT_BITS_PER_PAGE_MASK;
331 map = &qpt->map[qpn / RVT_BITS_PER_PAGE];
332 max_scan = qpt->nmaps - !offset;
333 for (i = 0;;) {
334 if (unlikely(!map->page)) {
335 get_map_page(qpt, map, gfp);
336 if (unlikely(!map->page))
337 break;
338 }
339 do {
340 if (!test_and_set_bit(offset, map->page)) {
341 qpt->last = qpn;
342 ret = qpn;
343 goto bail;
344 }
345 offset += qpt->incr;
346 /*
347 * This qpn might be bogus if offset >= BITS_PER_PAGE.
348 * That is OK. It gets re-assigned below
349 */
350 qpn = mk_qpn(qpt, map, offset);
351 } while (offset < RVT_BITS_PER_PAGE && qpn < RVT_QPN_MAX);
352 /*
353 * In order to keep the number of pages allocated to a
354 * minimum, we scan the all existing pages before increasing
355 * the size of the bitmap table.
356 */
357 if (++i > max_scan) {
358 if (qpt->nmaps == RVT_QPNMAP_ENTRIES)
359 break;
360 map = &qpt->map[qpt->nmaps++];
361 /* start at incr with current bit 0 */
362 offset = qpt->incr | (offset & 1);
363 } else if (map < &qpt->map[qpt->nmaps]) {
364 ++map;
365 /* start at incr with current bit 0 */
366 offset = qpt->incr | (offset & 1);
367 } else {
368 map = &qpt->map[0];
369 /* wrap to first map page, invert bit 0 */
370 offset = qpt->incr | ((offset & 1) ^ 1);
371 }
372 /* there can be no bits at shift and below */
373 WARN_ON(offset & (rdi->dparms.qos_shift - 1));
374 qpn = mk_qpn(qpt, map, offset);
375 }
376
377 ret = -ENOMEM;
378
379bail:
380 return ret;
381}
382
383static void free_qpn(struct rvt_qpn_table *qpt, u32 qpn)
384{
385 struct rvt_qpn_map *map;
386
387 map = qpt->map + qpn / RVT_BITS_PER_PAGE;
388 if (map->page)
389 clear_bit(qpn & RVT_BITS_PER_PAGE_MASK, map->page);
390}
391
392/**
393 * rvt_clear_mr_refs - Drop help mr refs
394 * @qp: rvt qp data structure
395 * @clr_sends: If shoudl clear send side or not
396 */
397static void rvt_clear_mr_refs(struct rvt_qp *qp, int clr_sends)
398{
399 unsigned n;
400
401 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags))
402 rvt_put_ss(&qp->s_rdma_read_sge);
403
404 rvt_put_ss(&qp->r_sge);
405
406 if (clr_sends) {
407 while (qp->s_last != qp->s_head) {
408 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_last);
409 unsigned i;
410
411 for (i = 0; i < wqe->wr.num_sge; i++) {
412 struct rvt_sge *sge = &wqe->sg_list[i];
413
414 rvt_put_mr(sge->mr);
415 }
416 if (qp->ibqp.qp_type == IB_QPT_UD ||
417 qp->ibqp.qp_type == IB_QPT_SMI ||
418 qp->ibqp.qp_type == IB_QPT_GSI)
419 atomic_dec(&ibah_to_rvtah(
420 wqe->ud_wr.ah)->refcount);
421 if (++qp->s_last >= qp->s_size)
422 qp->s_last = 0;
423 smp_wmb(); /* see qp_set_savail */
424 }
425 if (qp->s_rdma_mr) {
426 rvt_put_mr(qp->s_rdma_mr);
427 qp->s_rdma_mr = NULL;
428 }
429 }
430
431 if (qp->ibqp.qp_type != IB_QPT_RC)
432 return;
433
434 for (n = 0; n < ARRAY_SIZE(qp->s_ack_queue); n++) {
435 struct rvt_ack_entry *e = &qp->s_ack_queue[n];
436
437 if (e->opcode == IB_OPCODE_RC_RDMA_READ_REQUEST &&
438 e->rdma_sge.mr) {
439 rvt_put_mr(e->rdma_sge.mr);
440 e->rdma_sge.mr = NULL;
441 }
442 }
443}
444
445/**
446 * rvt_remove_qp - remove qp form table
447 * @rdi: rvt dev struct
448 * @qp: qp to remove
449 *
450 * Remove the QP from the table so it can't be found asynchronously by
451 * the receive routine.
452 */
453static void rvt_remove_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp)
454{
455 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1];
456 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits);
457 unsigned long flags;
458 int removed = 1;
459
460 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags);
461
462 if (rcu_dereference_protected(rvp->qp[0],
463 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) {
464 RCU_INIT_POINTER(rvp->qp[0], NULL);
465 } else if (rcu_dereference_protected(rvp->qp[1],
466 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) {
467 RCU_INIT_POINTER(rvp->qp[1], NULL);
468 } else {
469 struct rvt_qp *q;
470 struct rvt_qp __rcu **qpp;
471
472 removed = 0;
473 qpp = &rdi->qp_dev->qp_table[n];
474 for (; (q = rcu_dereference_protected(*qpp,
475 lockdep_is_held(&rdi->qp_dev->qpt_lock))) != NULL;
476 qpp = &q->next) {
477 if (q == qp) {
478 RCU_INIT_POINTER(*qpp,
479 rcu_dereference_protected(qp->next,
480 lockdep_is_held(&rdi->qp_dev->qpt_lock)));
481 removed = 1;
482 trace_rvt_qpremove(qp, n);
483 break;
484 }
485 }
486 }
487
488 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags);
489 if (removed) {
490 synchronize_rcu();
491 if (atomic_dec_and_test(&qp->refcount))
492 wake_up(&qp->wait);
493 }
494}
495
496/**
497 * reset_qp - initialize the QP state to the reset state
498 * @qp: the QP to reset
499 * @type: the QP type
500 * r and s lock are required to be held by the caller
501 */
502static void rvt_reset_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp,
503 enum ib_qp_type type)
504{
505 if (qp->state != IB_QPS_RESET) {
506 qp->state = IB_QPS_RESET;
507
508 /* Let drivers flush their waitlist */
509 rdi->driver_f.flush_qp_waiters(qp);
510 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_ANY_WAIT);
511 spin_unlock(&qp->s_lock);
512 spin_unlock(&qp->s_hlock);
513 spin_unlock_irq(&qp->r_lock);
514
515 /* Stop the send queue and the retry timer */
516 rdi->driver_f.stop_send_queue(qp);
517
518 /* Wait for things to stop */
519 rdi->driver_f.quiesce_qp(qp);
520
521 /* take qp out the hash and wait for it to be unused */
522 rvt_remove_qp(rdi, qp);
523 wait_event(qp->wait, !atomic_read(&qp->refcount));
524
525 /* grab the lock b/c it was locked at call time */
526 spin_lock_irq(&qp->r_lock);
527 spin_lock(&qp->s_hlock);
528 spin_lock(&qp->s_lock);
529
530 rvt_clear_mr_refs(qp, 1);
531 }
532
533 /*
534 * Let the driver do any tear down it needs to for a qp
535 * that has been reset
536 */
537 rdi->driver_f.notify_qp_reset(qp);
538
539 qp->remote_qpn = 0;
540 qp->qkey = 0;
541 qp->qp_access_flags = 0;
542 qp->s_flags &= RVT_S_SIGNAL_REQ_WR;
543 qp->s_hdrwords = 0;
544 qp->s_wqe = NULL;
545 qp->s_draining = 0;
546 qp->s_next_psn = 0;
547 qp->s_last_psn = 0;
548 qp->s_sending_psn = 0;
549 qp->s_sending_hpsn = 0;
550 qp->s_psn = 0;
551 qp->r_psn = 0;
552 qp->r_msn = 0;
553 if (type == IB_QPT_RC) {
554 qp->s_state = IB_OPCODE_RC_SEND_LAST;
555 qp->r_state = IB_OPCODE_RC_SEND_LAST;
556 } else {
557 qp->s_state = IB_OPCODE_UC_SEND_LAST;
558 qp->r_state = IB_OPCODE_UC_SEND_LAST;
559 }
560 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
561 qp->r_nak_state = 0;
562 qp->r_aflags = 0;
563 qp->r_flags = 0;
564 qp->s_head = 0;
565 qp->s_tail = 0;
566 qp->s_cur = 0;
567 qp->s_acked = 0;
568 qp->s_last = 0;
569 qp->s_ssn = 1;
570 qp->s_lsn = 0;
571 qp->s_mig_state = IB_MIG_MIGRATED;
572 memset(qp->s_ack_queue, 0, sizeof(qp->s_ack_queue));
573 qp->r_head_ack_queue = 0;
574 qp->s_tail_ack_queue = 0;
575 qp->s_num_rd_atomic = 0;
576 if (qp->r_rq.wq) {
577 qp->r_rq.wq->head = 0;
578 qp->r_rq.wq->tail = 0;
579 }
580 qp->r_sge.num_sge = 0;
581}
582
583/**
584 * rvt_create_qp - create a queue pair for a device
585 * @ibpd: the protection domain who's device we create the queue pair for
586 * @init_attr: the attributes of the queue pair
587 * @udata: user data for libibverbs.so
588 *
589 * Queue pair creation is mostly an rvt issue. However, drivers have their own
590 * unique idea of what queue pair numbers mean. For instance there is a reserved
591 * range for PSM.
592 *
593 * Return: the queue pair on success, otherwise returns an errno.
594 *
595 * Called by the ib_create_qp() core verbs function.
596 */
597struct ib_qp *rvt_create_qp(struct ib_pd *ibpd,
598 struct ib_qp_init_attr *init_attr,
599 struct ib_udata *udata)
600{
601 struct rvt_qp *qp;
602 int err;
603 struct rvt_swqe *swq = NULL;
604 size_t sz;
605 size_t sg_list_sz;
606 struct ib_qp *ret = ERR_PTR(-ENOMEM);
607 struct rvt_dev_info *rdi = ib_to_rvt(ibpd->device);
608 void *priv = NULL;
609 gfp_t gfp;
610
611 if (!rdi)
612 return ERR_PTR(-EINVAL);
613
614 if (init_attr->cap.max_send_sge > rdi->dparms.props.max_sge ||
615 init_attr->cap.max_send_wr > rdi->dparms.props.max_qp_wr ||
616 init_attr->create_flags & ~(IB_QP_CREATE_USE_GFP_NOIO))
617 return ERR_PTR(-EINVAL);
618
619 /* GFP_NOIO is applicable to RC QP's only */
620
621 if (init_attr->create_flags & IB_QP_CREATE_USE_GFP_NOIO &&
622 init_attr->qp_type != IB_QPT_RC)
623 return ERR_PTR(-EINVAL);
624
625 gfp = init_attr->create_flags & IB_QP_CREATE_USE_GFP_NOIO ?
626 GFP_NOIO : GFP_KERNEL;
627
628 /* Check receive queue parameters if no SRQ is specified. */
629 if (!init_attr->srq) {
630 if (init_attr->cap.max_recv_sge > rdi->dparms.props.max_sge ||
631 init_attr->cap.max_recv_wr > rdi->dparms.props.max_qp_wr)
632 return ERR_PTR(-EINVAL);
633
634 if (init_attr->cap.max_send_sge +
635 init_attr->cap.max_send_wr +
636 init_attr->cap.max_recv_sge +
637 init_attr->cap.max_recv_wr == 0)
638 return ERR_PTR(-EINVAL);
639 }
640
641 switch (init_attr->qp_type) {
642 case IB_QPT_SMI:
643 case IB_QPT_GSI:
644 if (init_attr->port_num == 0 ||
645 init_attr->port_num > ibpd->device->phys_port_cnt)
646 return ERR_PTR(-EINVAL);
647 case IB_QPT_UC:
648 case IB_QPT_RC:
649 case IB_QPT_UD:
650 sz = sizeof(struct rvt_sge) *
651 init_attr->cap.max_send_sge +
652 sizeof(struct rvt_swqe);
653 if (gfp == GFP_NOIO)
654 swq = __vmalloc(
655 (init_attr->cap.max_send_wr + 1) * sz,
656 gfp, PAGE_KERNEL);
657 else
658 swq = vmalloc_node(
659 (init_attr->cap.max_send_wr + 1) * sz,
660 rdi->dparms.node);
661 if (!swq)
662 return ERR_PTR(-ENOMEM);
663
664 sz = sizeof(*qp);
665 sg_list_sz = 0;
666 if (init_attr->srq) {
667 struct rvt_srq *srq = ibsrq_to_rvtsrq(init_attr->srq);
668
669 if (srq->rq.max_sge > 1)
670 sg_list_sz = sizeof(*qp->r_sg_list) *
671 (srq->rq.max_sge - 1);
672 } else if (init_attr->cap.max_recv_sge > 1)
673 sg_list_sz = sizeof(*qp->r_sg_list) *
674 (init_attr->cap.max_recv_sge - 1);
675 qp = kzalloc_node(sz + sg_list_sz, gfp, rdi->dparms.node);
676 if (!qp)
677 goto bail_swq;
678
679 RCU_INIT_POINTER(qp->next, NULL);
680
681 /*
682 * Driver needs to set up it's private QP structure and do any
683 * initialization that is needed.
684 */
685 priv = rdi->driver_f.qp_priv_alloc(rdi, qp, gfp);
686 if (!priv)
687 goto bail_qp;
688 qp->priv = priv;
689 qp->timeout_jiffies =
690 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
691 1000UL);
692 if (init_attr->srq) {
693 sz = 0;
694 } else {
695 qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
696 qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
697 sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) +
698 sizeof(struct rvt_rwqe);
699 if (udata)
700 qp->r_rq.wq = vmalloc_user(
701 sizeof(struct rvt_rwq) +
702 qp->r_rq.size * sz);
703 else if (gfp == GFP_NOIO)
704 qp->r_rq.wq = __vmalloc(
705 sizeof(struct rvt_rwq) +
706 qp->r_rq.size * sz,
707 gfp, PAGE_KERNEL);
708 else
709 qp->r_rq.wq = vmalloc_node(
710 sizeof(struct rvt_rwq) +
711 qp->r_rq.size * sz,
712 rdi->dparms.node);
713 if (!qp->r_rq.wq)
714 goto bail_driver_priv;
715 }
716
717 /*
718 * ib_create_qp() will initialize qp->ibqp
719 * except for qp->ibqp.qp_num.
720 */
721 spin_lock_init(&qp->r_lock);
722 spin_lock_init(&qp->s_hlock);
723 spin_lock_init(&qp->s_lock);
724 spin_lock_init(&qp->r_rq.lock);
725 atomic_set(&qp->refcount, 0);
726 init_waitqueue_head(&qp->wait);
727 init_timer(&qp->s_timer);
728 qp->s_timer.data = (unsigned long)qp;
729 INIT_LIST_HEAD(&qp->rspwait);
730 qp->state = IB_QPS_RESET;
731 qp->s_wq = swq;
732 qp->s_size = init_attr->cap.max_send_wr + 1;
733 qp->s_avail = init_attr->cap.max_send_wr;
734 qp->s_max_sge = init_attr->cap.max_send_sge;
735 if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR)
736 qp->s_flags = RVT_S_SIGNAL_REQ_WR;
737
738 err = alloc_qpn(rdi, &rdi->qp_dev->qpn_table,
739 init_attr->qp_type,
740 init_attr->port_num, gfp);
741 if (err < 0) {
742 ret = ERR_PTR(err);
743 goto bail_rq_wq;
744 }
745 qp->ibqp.qp_num = err;
746 qp->port_num = init_attr->port_num;
747 rvt_reset_qp(rdi, qp, init_attr->qp_type);
748 break;
749
750 default:
751 /* Don't support raw QPs */
752 return ERR_PTR(-EINVAL);
753 }
754
755 init_attr->cap.max_inline_data = 0;
756
757 /*
758 * Return the address of the RWQ as the offset to mmap.
759 * See rvt_mmap() for details.
760 */
761 if (udata && udata->outlen >= sizeof(__u64)) {
762 if (!qp->r_rq.wq) {
763 __u64 offset = 0;
764
765 err = ib_copy_to_udata(udata, &offset,
766 sizeof(offset));
767 if (err) {
768 ret = ERR_PTR(err);
769 goto bail_qpn;
770 }
771 } else {
772 u32 s = sizeof(struct rvt_rwq) + qp->r_rq.size * sz;
773
774 qp->ip = rvt_create_mmap_info(rdi, s,
775 ibpd->uobject->context,
776 qp->r_rq.wq);
777 if (!qp->ip) {
778 ret = ERR_PTR(-ENOMEM);
779 goto bail_qpn;
780 }
781
782 err = ib_copy_to_udata(udata, &qp->ip->offset,
783 sizeof(qp->ip->offset));
784 if (err) {
785 ret = ERR_PTR(err);
786 goto bail_ip;
787 }
788 }
789 qp->pid = current->pid;
790 }
791
792 spin_lock(&rdi->n_qps_lock);
793 if (rdi->n_qps_allocated == rdi->dparms.props.max_qp) {
794 spin_unlock(&rdi->n_qps_lock);
795 ret = ERR_PTR(-ENOMEM);
796 goto bail_ip;
797 }
798
799 rdi->n_qps_allocated++;
800 /*
801 * Maintain a busy_jiffies variable that will be added to the timeout
802 * period in mod_retry_timer and add_retry_timer. This busy jiffies
803 * is scaled by the number of rc qps created for the device to reduce
804 * the number of timeouts occurring when there is a large number of
805 * qps. busy_jiffies is incremented every rc qp scaling interval.
806 * The scaling interval is selected based on extensive performance
807 * evaluation of targeted workloads.
808 */
809 if (init_attr->qp_type == IB_QPT_RC) {
810 rdi->n_rc_qps++;
811 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL;
812 }
813 spin_unlock(&rdi->n_qps_lock);
814
815 if (qp->ip) {
816 spin_lock_irq(&rdi->pending_lock);
817 list_add(&qp->ip->pending_mmaps, &rdi->pending_mmaps);
818 spin_unlock_irq(&rdi->pending_lock);
819 }
820
821 ret = &qp->ibqp;
822
823 /*
824 * We have our QP and its good, now keep track of what types of opcodes
825 * can be processed on this QP. We do this by keeping track of what the
826 * 3 high order bits of the opcode are.
827 */
828 switch (init_attr->qp_type) {
829 case IB_QPT_SMI:
830 case IB_QPT_GSI:
831 case IB_QPT_UD:
832 qp->allowed_ops = IB_OPCODE_UD_SEND_ONLY & RVT_OPCODE_QP_MASK;
833 break;
834 case IB_QPT_RC:
835 qp->allowed_ops = IB_OPCODE_RC_SEND_ONLY & RVT_OPCODE_QP_MASK;
836 break;
837 case IB_QPT_UC:
838 qp->allowed_ops = IB_OPCODE_UC_SEND_ONLY & RVT_OPCODE_QP_MASK;
839 break;
840 default:
841 ret = ERR_PTR(-EINVAL);
842 goto bail_ip;
843 }
844
845 return ret;
846
847bail_ip:
848 kref_put(&qp->ip->ref, rvt_release_mmap_info);
849
850bail_qpn:
851 free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num);
852
853bail_rq_wq:
854 vfree(qp->r_rq.wq);
855
856bail_driver_priv:
857 rdi->driver_f.qp_priv_free(rdi, qp);
858
859bail_qp:
860 kfree(qp);
861
862bail_swq:
863 vfree(swq);
864
865 return ret;
866}
867
868/**
869 * rvt_error_qp - put a QP into the error state
870 * @qp: the QP to put into the error state
871 * @err: the receive completion error to signal if a RWQE is active
872 *
873 * Flushes both send and receive work queues.
874 *
875 * Return: true if last WQE event should be generated.
876 * The QP r_lock and s_lock should be held and interrupts disabled.
877 * If we are already in error state, just return.
878 */
879int rvt_error_qp(struct rvt_qp *qp, enum ib_wc_status err)
880{
881 struct ib_wc wc;
882 int ret = 0;
883 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
884
885 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET)
886 goto bail;
887
888 qp->state = IB_QPS_ERR;
889
890 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) {
891 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR);
892 del_timer(&qp->s_timer);
893 }
894
895 if (qp->s_flags & RVT_S_ANY_WAIT_SEND)
896 qp->s_flags &= ~RVT_S_ANY_WAIT_SEND;
897
898 rdi->driver_f.notify_error_qp(qp);
899
900 /* Schedule the sending tasklet to drain the send work queue. */
901 if (ACCESS_ONCE(qp->s_last) != qp->s_head)
902 rdi->driver_f.schedule_send(qp);
903
904 rvt_clear_mr_refs(qp, 0);
905
906 memset(&wc, 0, sizeof(wc));
907 wc.qp = &qp->ibqp;
908 wc.opcode = IB_WC_RECV;
909
910 if (test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) {
911 wc.wr_id = qp->r_wr_id;
912 wc.status = err;
913 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
914 }
915 wc.status = IB_WC_WR_FLUSH_ERR;
916
917 if (qp->r_rq.wq) {
918 struct rvt_rwq *wq;
919 u32 head;
920 u32 tail;
921
922 spin_lock(&qp->r_rq.lock);
923
924 /* sanity check pointers before trusting them */
925 wq = qp->r_rq.wq;
926 head = wq->head;
927 if (head >= qp->r_rq.size)
928 head = 0;
929 tail = wq->tail;
930 if (tail >= qp->r_rq.size)
931 tail = 0;
932 while (tail != head) {
933 wc.wr_id = rvt_get_rwqe_ptr(&qp->r_rq, tail)->wr_id;
934 if (++tail >= qp->r_rq.size)
935 tail = 0;
936 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
937 }
938 wq->tail = tail;
939
940 spin_unlock(&qp->r_rq.lock);
941 } else if (qp->ibqp.event_handler) {
942 ret = 1;
943 }
944
945bail:
946 return ret;
947}
948EXPORT_SYMBOL(rvt_error_qp);
949
950/*
951 * Put the QP into the hash table.
952 * The hash table holds a reference to the QP.
953 */
954static void rvt_insert_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp)
955{
956 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1];
957 unsigned long flags;
958
959 atomic_inc(&qp->refcount);
960 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags);
961
962 if (qp->ibqp.qp_num <= 1) {
963 rcu_assign_pointer(rvp->qp[qp->ibqp.qp_num], qp);
964 } else {
965 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits);
966
967 qp->next = rdi->qp_dev->qp_table[n];
968 rcu_assign_pointer(rdi->qp_dev->qp_table[n], qp);
969 trace_rvt_qpinsert(qp, n);
970 }
971
972 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags);
973}
974
975/**
976 * qib_modify_qp - modify the attributes of a queue pair
977 * @ibqp: the queue pair who's attributes we're modifying
978 * @attr: the new attributes
979 * @attr_mask: the mask of attributes to modify
980 * @udata: user data for libibverbs.so
981 *
982 * Return: 0 on success, otherwise returns an errno.
983 */
984int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
985 int attr_mask, struct ib_udata *udata)
986{
987 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
988 struct rvt_qp *qp = ibqp_to_rvtqp(ibqp);
989 enum ib_qp_state cur_state, new_state;
990 struct ib_event ev;
991 int lastwqe = 0;
992 int mig = 0;
993 int pmtu = 0; /* for gcc warning only */
994 enum rdma_link_layer link;
995
996 link = rdma_port_get_link_layer(ibqp->device, qp->port_num);
997
998 spin_lock_irq(&qp->r_lock);
999 spin_lock(&qp->s_hlock);
1000 spin_lock(&qp->s_lock);
1001
1002 cur_state = attr_mask & IB_QP_CUR_STATE ?
1003 attr->cur_qp_state : qp->state;
1004 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
1005
1006 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
1007 attr_mask, link))
1008 goto inval;
1009
1010 if (rdi->driver_f.check_modify_qp &&
1011 rdi->driver_f.check_modify_qp(qp, attr, attr_mask, udata))
1012 goto inval;
1013
1014 if (attr_mask & IB_QP_AV) {
1015 if (attr->ah_attr.dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE))
1016 goto inval;
1017 if (rvt_check_ah(qp->ibqp.device, &attr->ah_attr))
1018 goto inval;
1019 }
1020
1021 if (attr_mask & IB_QP_ALT_PATH) {
1022 if (attr->alt_ah_attr.dlid >=
1023 be16_to_cpu(IB_MULTICAST_LID_BASE))
1024 goto inval;
1025 if (rvt_check_ah(qp->ibqp.device, &attr->alt_ah_attr))
1026 goto inval;
1027 if (attr->alt_pkey_index >= rvt_get_npkeys(rdi))
1028 goto inval;
1029 }
1030
1031 if (attr_mask & IB_QP_PKEY_INDEX)
1032 if (attr->pkey_index >= rvt_get_npkeys(rdi))
1033 goto inval;
1034
1035 if (attr_mask & IB_QP_MIN_RNR_TIMER)
1036 if (attr->min_rnr_timer > 31)
1037 goto inval;
1038
1039 if (attr_mask & IB_QP_PORT)
1040 if (qp->ibqp.qp_type == IB_QPT_SMI ||
1041 qp->ibqp.qp_type == IB_QPT_GSI ||
1042 attr->port_num == 0 ||
1043 attr->port_num > ibqp->device->phys_port_cnt)
1044 goto inval;
1045
1046 if (attr_mask & IB_QP_DEST_QPN)
1047 if (attr->dest_qp_num > RVT_QPN_MASK)
1048 goto inval;
1049
1050 if (attr_mask & IB_QP_RETRY_CNT)
1051 if (attr->retry_cnt > 7)
1052 goto inval;
1053
1054 if (attr_mask & IB_QP_RNR_RETRY)
1055 if (attr->rnr_retry > 7)
1056 goto inval;
1057
1058 /*
1059 * Don't allow invalid path_mtu values. OK to set greater
1060 * than the active mtu (or even the max_cap, if we have tuned
1061 * that to a small mtu. We'll set qp->path_mtu
1062 * to the lesser of requested attribute mtu and active,
1063 * for packetizing messages.
1064 * Note that the QP port has to be set in INIT and MTU in RTR.
1065 */
1066 if (attr_mask & IB_QP_PATH_MTU) {
1067 pmtu = rdi->driver_f.get_pmtu_from_attr(rdi, qp, attr);
1068 if (pmtu < 0)
1069 goto inval;
1070 }
1071
1072 if (attr_mask & IB_QP_PATH_MIG_STATE) {
1073 if (attr->path_mig_state == IB_MIG_REARM) {
1074 if (qp->s_mig_state == IB_MIG_ARMED)
1075 goto inval;
1076 if (new_state != IB_QPS_RTS)
1077 goto inval;
1078 } else if (attr->path_mig_state == IB_MIG_MIGRATED) {
1079 if (qp->s_mig_state == IB_MIG_REARM)
1080 goto inval;
1081 if (new_state != IB_QPS_RTS && new_state != IB_QPS_SQD)
1082 goto inval;
1083 if (qp->s_mig_state == IB_MIG_ARMED)
1084 mig = 1;
1085 } else {
1086 goto inval;
1087 }
1088 }
1089
1090 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1091 if (attr->max_dest_rd_atomic > rdi->dparms.max_rdma_atomic)
1092 goto inval;
1093
1094 switch (new_state) {
1095 case IB_QPS_RESET:
1096 if (qp->state != IB_QPS_RESET)
1097 rvt_reset_qp(rdi, qp, ibqp->qp_type);
1098 break;
1099
1100 case IB_QPS_RTR:
1101 /* Allow event to re-trigger if QP set to RTR more than once */
1102 qp->r_flags &= ~RVT_R_COMM_EST;
1103 qp->state = new_state;
1104 break;
1105
1106 case IB_QPS_SQD:
1107 qp->s_draining = qp->s_last != qp->s_cur;
1108 qp->state = new_state;
1109 break;
1110
1111 case IB_QPS_SQE:
1112 if (qp->ibqp.qp_type == IB_QPT_RC)
1113 goto inval;
1114 qp->state = new_state;
1115 break;
1116
1117 case IB_QPS_ERR:
1118 lastwqe = rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
1119 break;
1120
1121 default:
1122 qp->state = new_state;
1123 break;
1124 }
1125
1126 if (attr_mask & IB_QP_PKEY_INDEX)
1127 qp->s_pkey_index = attr->pkey_index;
1128
1129 if (attr_mask & IB_QP_PORT)
1130 qp->port_num = attr->port_num;
1131
1132 if (attr_mask & IB_QP_DEST_QPN)
1133 qp->remote_qpn = attr->dest_qp_num;
1134
1135 if (attr_mask & IB_QP_SQ_PSN) {
1136 qp->s_next_psn = attr->sq_psn & rdi->dparms.psn_modify_mask;
1137 qp->s_psn = qp->s_next_psn;
1138 qp->s_sending_psn = qp->s_next_psn;
1139 qp->s_last_psn = qp->s_next_psn - 1;
1140 qp->s_sending_hpsn = qp->s_last_psn;
1141 }
1142
1143 if (attr_mask & IB_QP_RQ_PSN)
1144 qp->r_psn = attr->rq_psn & rdi->dparms.psn_modify_mask;
1145
1146 if (attr_mask & IB_QP_ACCESS_FLAGS)
1147 qp->qp_access_flags = attr->qp_access_flags;
1148
1149 if (attr_mask & IB_QP_AV) {
1150 qp->remote_ah_attr = attr->ah_attr;
1151 qp->s_srate = attr->ah_attr.static_rate;
1152 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate);
1153 }
1154
1155 if (attr_mask & IB_QP_ALT_PATH) {
1156 qp->alt_ah_attr = attr->alt_ah_attr;
1157 qp->s_alt_pkey_index = attr->alt_pkey_index;
1158 }
1159
1160 if (attr_mask & IB_QP_PATH_MIG_STATE) {
1161 qp->s_mig_state = attr->path_mig_state;
1162 if (mig) {
1163 qp->remote_ah_attr = qp->alt_ah_attr;
1164 qp->port_num = qp->alt_ah_attr.port_num;
1165 qp->s_pkey_index = qp->s_alt_pkey_index;
1166 }
1167 }
1168
1169 if (attr_mask & IB_QP_PATH_MTU) {
1170 qp->pmtu = rdi->driver_f.mtu_from_qp(rdi, qp, pmtu);
1171 qp->path_mtu = rdi->driver_f.mtu_to_path_mtu(qp->pmtu);
1172 qp->log_pmtu = ilog2(qp->pmtu);
1173 }
1174
1175 if (attr_mask & IB_QP_RETRY_CNT) {
1176 qp->s_retry_cnt = attr->retry_cnt;
1177 qp->s_retry = attr->retry_cnt;
1178 }
1179
1180 if (attr_mask & IB_QP_RNR_RETRY) {
1181 qp->s_rnr_retry_cnt = attr->rnr_retry;
1182 qp->s_rnr_retry = attr->rnr_retry;
1183 }
1184
1185 if (attr_mask & IB_QP_MIN_RNR_TIMER)
1186 qp->r_min_rnr_timer = attr->min_rnr_timer;
1187
1188 if (attr_mask & IB_QP_TIMEOUT) {
1189 qp->timeout = attr->timeout;
1190 qp->timeout_jiffies =
1191 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
1192 1000UL);
1193 }
1194
1195 if (attr_mask & IB_QP_QKEY)
1196 qp->qkey = attr->qkey;
1197
1198 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1199 qp->r_max_rd_atomic = attr->max_dest_rd_atomic;
1200
1201 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
1202 qp->s_max_rd_atomic = attr->max_rd_atomic;
1203
1204 if (rdi->driver_f.modify_qp)
1205 rdi->driver_f.modify_qp(qp, attr, attr_mask, udata);
1206
1207 spin_unlock(&qp->s_lock);
1208 spin_unlock(&qp->s_hlock);
1209 spin_unlock_irq(&qp->r_lock);
1210
1211 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
1212 rvt_insert_qp(rdi, qp);
1213
1214 if (lastwqe) {
1215 ev.device = qp->ibqp.device;
1216 ev.element.qp = &qp->ibqp;
1217 ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
1218 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
1219 }
1220 if (mig) {
1221 ev.device = qp->ibqp.device;
1222 ev.element.qp = &qp->ibqp;
1223 ev.event = IB_EVENT_PATH_MIG;
1224 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
1225 }
1226 return 0;
1227
1228inval:
1229 spin_unlock(&qp->s_lock);
1230 spin_unlock(&qp->s_hlock);
1231 spin_unlock_irq(&qp->r_lock);
1232 return -EINVAL;
1233}
1234
1235/** rvt_free_qpn - Free a qpn from the bit map
1236 * @qpt: QP table
1237 * @qpn: queue pair number to free
1238 */
1239static void rvt_free_qpn(struct rvt_qpn_table *qpt, u32 qpn)
1240{
1241 struct rvt_qpn_map *map;
1242
1243 map = qpt->map + qpn / RVT_BITS_PER_PAGE;
1244 if (map->page)
1245 clear_bit(qpn & RVT_BITS_PER_PAGE_MASK, map->page);
1246}
1247
1248/**
1249 * rvt_destroy_qp - destroy a queue pair
1250 * @ibqp: the queue pair to destroy
1251 *
1252 * Note that this can be called while the QP is actively sending or
1253 * receiving!
1254 *
1255 * Return: 0 on success.
1256 */
1257int rvt_destroy_qp(struct ib_qp *ibqp)
1258{
1259 struct rvt_qp *qp = ibqp_to_rvtqp(ibqp);
1260 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
1261
1262 spin_lock_irq(&qp->r_lock);
1263 spin_lock(&qp->s_hlock);
1264 spin_lock(&qp->s_lock);
1265 rvt_reset_qp(rdi, qp, ibqp->qp_type);
1266 spin_unlock(&qp->s_lock);
1267 spin_unlock(&qp->s_hlock);
1268 spin_unlock_irq(&qp->r_lock);
1269
1270 /* qpn is now available for use again */
1271 rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num);
1272
1273 spin_lock(&rdi->n_qps_lock);
1274 rdi->n_qps_allocated--;
1275 if (qp->ibqp.qp_type == IB_QPT_RC) {
1276 rdi->n_rc_qps--;
1277 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL;
1278 }
1279 spin_unlock(&rdi->n_qps_lock);
1280
1281 if (qp->ip)
1282 kref_put(&qp->ip->ref, rvt_release_mmap_info);
1283 else
1284 vfree(qp->r_rq.wq);
1285 vfree(qp->s_wq);
1286 rdi->driver_f.qp_priv_free(rdi, qp);
1287 kfree(qp);
1288 return 0;
1289}
1290
1291/**
1292 * rvt_query_qp - query an ipbq
1293 * @ibqp: IB qp to query
1294 * @attr: attr struct to fill in
1295 * @attr_mask: attr mask ignored
1296 * @init_attr: struct to fill in
1297 *
1298 * Return: always 0
1299 */
1300int rvt_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
1301 int attr_mask, struct ib_qp_init_attr *init_attr)
1302{
1303 struct rvt_qp *qp = ibqp_to_rvtqp(ibqp);
1304 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
1305
1306 attr->qp_state = qp->state;
1307 attr->cur_qp_state = attr->qp_state;
1308 attr->path_mtu = qp->path_mtu;
1309 attr->path_mig_state = qp->s_mig_state;
1310 attr->qkey = qp->qkey;
1311 attr->rq_psn = qp->r_psn & rdi->dparms.psn_mask;
1312 attr->sq_psn = qp->s_next_psn & rdi->dparms.psn_mask;
1313 attr->dest_qp_num = qp->remote_qpn;
1314 attr->qp_access_flags = qp->qp_access_flags;
1315 attr->cap.max_send_wr = qp->s_size - 1;
1316 attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1;
1317 attr->cap.max_send_sge = qp->s_max_sge;
1318 attr->cap.max_recv_sge = qp->r_rq.max_sge;
1319 attr->cap.max_inline_data = 0;
1320 attr->ah_attr = qp->remote_ah_attr;
1321 attr->alt_ah_attr = qp->alt_ah_attr;
1322 attr->pkey_index = qp->s_pkey_index;
1323 attr->alt_pkey_index = qp->s_alt_pkey_index;
1324 attr->en_sqd_async_notify = 0;
1325 attr->sq_draining = qp->s_draining;
1326 attr->max_rd_atomic = qp->s_max_rd_atomic;
1327 attr->max_dest_rd_atomic = qp->r_max_rd_atomic;
1328 attr->min_rnr_timer = qp->r_min_rnr_timer;
1329 attr->port_num = qp->port_num;
1330 attr->timeout = qp->timeout;
1331 attr->retry_cnt = qp->s_retry_cnt;
1332 attr->rnr_retry = qp->s_rnr_retry_cnt;
1333 attr->alt_port_num = qp->alt_ah_attr.port_num;
1334 attr->alt_timeout = qp->alt_timeout;
1335
1336 init_attr->event_handler = qp->ibqp.event_handler;
1337 init_attr->qp_context = qp->ibqp.qp_context;
1338 init_attr->send_cq = qp->ibqp.send_cq;
1339 init_attr->recv_cq = qp->ibqp.recv_cq;
1340 init_attr->srq = qp->ibqp.srq;
1341 init_attr->cap = attr->cap;
1342 if (qp->s_flags & RVT_S_SIGNAL_REQ_WR)
1343 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR;
1344 else
1345 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR;
1346 init_attr->qp_type = qp->ibqp.qp_type;
1347 init_attr->port_num = qp->port_num;
1348 return 0;
1349}
1350
1351/**
1352 * rvt_post_receive - post a receive on a QP
1353 * @ibqp: the QP to post the receive on
1354 * @wr: the WR to post
1355 * @bad_wr: the first bad WR is put here
1356 *
1357 * This may be called from interrupt context.
1358 *
1359 * Return: 0 on success otherwise errno
1360 */
1361int rvt_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
1362 struct ib_recv_wr **bad_wr)
1363{
1364 struct rvt_qp *qp = ibqp_to_rvtqp(ibqp);
1365 struct rvt_rwq *wq = qp->r_rq.wq;
1366 unsigned long flags;
1367 int qp_err_flush = (ib_rvt_state_ops[qp->state] & RVT_FLUSH_RECV) &&
1368 !qp->ibqp.srq;
1369
1370 /* Check that state is OK to post receive. */
1371 if (!(ib_rvt_state_ops[qp->state] & RVT_POST_RECV_OK) || !wq) {
1372 *bad_wr = wr;
1373 return -EINVAL;
1374 }
1375
1376 for (; wr; wr = wr->next) {
1377 struct rvt_rwqe *wqe;
1378 u32 next;
1379 int i;
1380
1381 if ((unsigned)wr->num_sge > qp->r_rq.max_sge) {
1382 *bad_wr = wr;
1383 return -EINVAL;
1384 }
1385
1386 spin_lock_irqsave(&qp->r_rq.lock, flags);
1387 next = wq->head + 1;
1388 if (next >= qp->r_rq.size)
1389 next = 0;
1390 if (next == wq->tail) {
1391 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
1392 *bad_wr = wr;
1393 return -ENOMEM;
1394 }
1395 if (unlikely(qp_err_flush)) {
1396 struct ib_wc wc;
1397
1398 memset(&wc, 0, sizeof(wc));
1399 wc.qp = &qp->ibqp;
1400 wc.opcode = IB_WC_RECV;
1401 wc.wr_id = wr->wr_id;
1402 wc.status = IB_WC_WR_FLUSH_ERR;
1403 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
1404 } else {
1405 wqe = rvt_get_rwqe_ptr(&qp->r_rq, wq->head);
1406 wqe->wr_id = wr->wr_id;
1407 wqe->num_sge = wr->num_sge;
1408 for (i = 0; i < wr->num_sge; i++)
1409 wqe->sg_list[i] = wr->sg_list[i];
1410 /*
1411 * Make sure queue entry is written
1412 * before the head index.
1413 */
1414 smp_wmb();
1415 wq->head = next;
1416 }
1417 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
1418 }
1419 return 0;
1420}
1421
1422/**
1423 * qp_get_savail - return number of avail send entries
1424 *
1425 * @qp - the qp
1426 *
1427 * This assumes the s_hlock is held but the s_last
1428 * qp variable is uncontrolled.
1429 */
1430static inline u32 qp_get_savail(struct rvt_qp *qp)
1431{
1432 u32 slast;
1433 u32 ret;
1434
1435 smp_read_barrier_depends(); /* see rc.c */
1436 slast = ACCESS_ONCE(qp->s_last);
1437 if (qp->s_head >= slast)
1438 ret = qp->s_size - (qp->s_head - slast);
1439 else
1440 ret = slast - qp->s_head;
1441 return ret - 1;
1442}
1443
1444/**
1445 * rvt_post_one_wr - post one RC, UC, or UD send work request
1446 * @qp: the QP to post on
1447 * @wr: the work request to send
1448 */
1449static int rvt_post_one_wr(struct rvt_qp *qp,
1450 struct ib_send_wr *wr,
1451 int *call_send)
1452{
1453 struct rvt_swqe *wqe;
1454 u32 next;
1455 int i;
1456 int j;
1457 int acc;
1458 struct rvt_lkey_table *rkt;
1459 struct rvt_pd *pd;
1460 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
1461 u8 log_pmtu;
1462 int ret;
1463
1464 /* IB spec says that num_sge == 0 is OK. */
1465 if (unlikely(wr->num_sge > qp->s_max_sge))
1466 return -EINVAL;
1467
1468 /*
1469 * Don't allow RDMA reads or atomic operations on UC or
1470 * undefined operations.
1471 * Make sure buffer is large enough to hold the result for atomics.
1472 */
1473 if (qp->ibqp.qp_type == IB_QPT_UC) {
1474 if ((unsigned)wr->opcode >= IB_WR_RDMA_READ)
1475 return -EINVAL;
1476 } else if (qp->ibqp.qp_type != IB_QPT_RC) {
1477 /* Check IB_QPT_SMI, IB_QPT_GSI, IB_QPT_UD opcode */
1478 if (wr->opcode != IB_WR_SEND &&
1479 wr->opcode != IB_WR_SEND_WITH_IMM)
1480 return -EINVAL;
1481 /* Check UD destination address PD */
1482 if (qp->ibqp.pd != ud_wr(wr)->ah->pd)
1483 return -EINVAL;
1484 } else if ((unsigned)wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD) {
1485 return -EINVAL;
1486 } else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
1487 (wr->num_sge == 0 ||
1488 wr->sg_list[0].length < sizeof(u64) ||
1489 wr->sg_list[0].addr & (sizeof(u64) - 1))) {
1490 return -EINVAL;
1491 } else if (wr->opcode >= IB_WR_RDMA_READ && !qp->s_max_rd_atomic) {
1492 return -EINVAL;
1493 }
1494 /* check for avail */
1495 if (unlikely(!qp->s_avail)) {
1496 qp->s_avail = qp_get_savail(qp);
1497 if (WARN_ON(qp->s_avail > (qp->s_size - 1)))
1498 rvt_pr_err(rdi,
1499 "More avail entries than QP RB size.\nQP: %u, size: %u, avail: %u\nhead: %u, tail: %u, cur: %u, acked: %u, last: %u",
1500 qp->ibqp.qp_num, qp->s_size, qp->s_avail,
1501 qp->s_head, qp->s_tail, qp->s_cur,
1502 qp->s_acked, qp->s_last);
1503 if (!qp->s_avail)
1504 return -ENOMEM;
1505 }
1506 next = qp->s_head + 1;
1507 if (next >= qp->s_size)
1508 next = 0;
1509
1510 rkt = &rdi->lkey_table;
1511 pd = ibpd_to_rvtpd(qp->ibqp.pd);
1512 wqe = rvt_get_swqe_ptr(qp, qp->s_head);
1513
1514 if (qp->ibqp.qp_type != IB_QPT_UC &&
1515 qp->ibqp.qp_type != IB_QPT_RC)
1516 memcpy(&wqe->ud_wr, ud_wr(wr), sizeof(wqe->ud_wr));
1517 else if (wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
1518 wr->opcode == IB_WR_RDMA_WRITE ||
1519 wr->opcode == IB_WR_RDMA_READ)
1520 memcpy(&wqe->rdma_wr, rdma_wr(wr), sizeof(wqe->rdma_wr));
1521 else if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
1522 wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD)
1523 memcpy(&wqe->atomic_wr, atomic_wr(wr), sizeof(wqe->atomic_wr));
1524 else
1525 memcpy(&wqe->wr, wr, sizeof(wqe->wr));
1526
1527 wqe->length = 0;
1528 j = 0;
1529 if (wr->num_sge) {
1530 acc = wr->opcode >= IB_WR_RDMA_READ ?
1531 IB_ACCESS_LOCAL_WRITE : 0;
1532 for (i = 0; i < wr->num_sge; i++) {
1533 u32 length = wr->sg_list[i].length;
1534 int ok;
1535
1536 if (length == 0)
1537 continue;
1538 ok = rvt_lkey_ok(rkt, pd, &wqe->sg_list[j],
1539 &wr->sg_list[i], acc);
1540 if (!ok) {
1541 ret = -EINVAL;
1542 goto bail_inval_free;
1543 }
1544 wqe->length += length;
1545 j++;
1546 }
1547 wqe->wr.num_sge = j;
1548 }
1549
1550 /* general part of wqe valid - allow for driver checks */
1551 if (rdi->driver_f.check_send_wqe) {
1552 ret = rdi->driver_f.check_send_wqe(qp, wqe);
1553 if (ret < 0)
1554 goto bail_inval_free;
1555 if (ret)
1556 *call_send = ret;
1557 }
1558
1559 log_pmtu = qp->log_pmtu;
1560 if (qp->ibqp.qp_type != IB_QPT_UC &&
1561 qp->ibqp.qp_type != IB_QPT_RC) {
1562 struct rvt_ah *ah = ibah_to_rvtah(wqe->ud_wr.ah);
1563
1564 log_pmtu = ah->log_pmtu;
1565 atomic_inc(&ibah_to_rvtah(ud_wr(wr)->ah)->refcount);
1566 }
1567
1568 wqe->ssn = qp->s_ssn++;
1569 wqe->psn = qp->s_next_psn;
1570 wqe->lpsn = wqe->psn +
1571 (wqe->length ? ((wqe->length - 1) >> log_pmtu) : 0);
1572 qp->s_next_psn = wqe->lpsn + 1;
1573 trace_rvt_post_one_wr(qp, wqe);
1574 smp_wmb(); /* see request builders */
1575 qp->s_avail--;
1576 qp->s_head = next;
1577
1578 return 0;
1579
1580bail_inval_free:
1581 /* release mr holds */
1582 while (j) {
1583 struct rvt_sge *sge = &wqe->sg_list[--j];
1584
1585 rvt_put_mr(sge->mr);
1586 }
1587 return ret;
1588}
1589
1590/**
1591 * rvt_post_send - post a send on a QP
1592 * @ibqp: the QP to post the send on
1593 * @wr: the list of work requests to post
1594 * @bad_wr: the first bad WR is put here
1595 *
1596 * This may be called from interrupt context.
1597 *
1598 * Return: 0 on success else errno
1599 */
1600int rvt_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1601 struct ib_send_wr **bad_wr)
1602{
1603 struct rvt_qp *qp = ibqp_to_rvtqp(ibqp);
1604 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
1605 unsigned long flags = 0;
1606 int call_send;
1607 unsigned nreq = 0;
1608 int err = 0;
1609
1610 spin_lock_irqsave(&qp->s_hlock, flags);
1611
1612 /*
1613 * Ensure QP state is such that we can send. If not bail out early,
1614 * there is no need to do this every time we post a send.
1615 */
1616 if (unlikely(!(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))) {
1617 spin_unlock_irqrestore(&qp->s_hlock, flags);
1618 return -EINVAL;
1619 }
1620
1621 /*
1622 * If the send queue is empty, and we only have a single WR then just go
1623 * ahead and kick the send engine into gear. Otherwise we will always
1624 * just schedule the send to happen later.
1625 */
1626 call_send = qp->s_head == ACCESS_ONCE(qp->s_last) && !wr->next;
1627
1628 for (; wr; wr = wr->next) {
1629 err = rvt_post_one_wr(qp, wr, &call_send);
1630 if (unlikely(err)) {
1631 *bad_wr = wr;
1632 goto bail;
1633 }
1634 nreq++;
1635 }
1636bail:
1637 spin_unlock_irqrestore(&qp->s_hlock, flags);
1638 if (nreq) {
1639 if (call_send)
1640 rdi->driver_f.schedule_send_no_lock(qp);
1641 else
1642 rdi->driver_f.do_send(qp);
1643 }
1644 return err;
1645}
1646
1647/**
1648 * rvt_post_srq_receive - post a receive on a shared receive queue
1649 * @ibsrq: the SRQ to post the receive on
1650 * @wr: the list of work requests to post
1651 * @bad_wr: A pointer to the first WR to cause a problem is put here
1652 *
1653 * This may be called from interrupt context.
1654 *
1655 * Return: 0 on success else errno
1656 */
1657int rvt_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
1658 struct ib_recv_wr **bad_wr)
1659{
1660 struct rvt_srq *srq = ibsrq_to_rvtsrq(ibsrq);
1661 struct rvt_rwq *wq;
1662 unsigned long flags;
1663
1664 for (; wr; wr = wr->next) {
1665 struct rvt_rwqe *wqe;
1666 u32 next;
1667 int i;
1668
1669 if ((unsigned)wr->num_sge > srq->rq.max_sge) {
1670 *bad_wr = wr;
1671 return -EINVAL;
1672 }
1673
1674 spin_lock_irqsave(&srq->rq.lock, flags);
1675 wq = srq->rq.wq;
1676 next = wq->head + 1;
1677 if (next >= srq->rq.size)
1678 next = 0;
1679 if (next == wq->tail) {
1680 spin_unlock_irqrestore(&srq->rq.lock, flags);
1681 *bad_wr = wr;
1682 return -ENOMEM;
1683 }
1684
1685 wqe = rvt_get_rwqe_ptr(&srq->rq, wq->head);
1686 wqe->wr_id = wr->wr_id;
1687 wqe->num_sge = wr->num_sge;
1688 for (i = 0; i < wr->num_sge; i++)
1689 wqe->sg_list[i] = wr->sg_list[i];
1690 /* Make sure queue entry is written before the head index. */
1691 smp_wmb();
1692 wq->head = next;
1693 spin_unlock_irqrestore(&srq->rq.lock, flags);
1694 }
1695 return 0;
1696}
diff --git a/drivers/infiniband/sw/rdmavt/qp.h b/drivers/infiniband/sw/rdmavt/qp.h
new file mode 100644
index 000000000000..8409f80d5f25
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/qp.h
@@ -0,0 +1,69 @@
1#ifndef DEF_RVTQP_H
2#define DEF_RVTQP_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52
53int rvt_driver_qp_init(struct rvt_dev_info *rdi);
54void rvt_qp_exit(struct rvt_dev_info *rdi);
55struct ib_qp *rvt_create_qp(struct ib_pd *ibpd,
56 struct ib_qp_init_attr *init_attr,
57 struct ib_udata *udata);
58int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
59 int attr_mask, struct ib_udata *udata);
60int rvt_destroy_qp(struct ib_qp *ibqp);
61int rvt_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
62 int attr_mask, struct ib_qp_init_attr *init_attr);
63int rvt_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
64 struct ib_recv_wr **bad_wr);
65int rvt_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
66 struct ib_send_wr **bad_wr);
67int rvt_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
68 struct ib_recv_wr **bad_wr);
69#endif /* DEF_RVTQP_H */
diff --git a/drivers/staging/rdma/hfi1/srq.c b/drivers/infiniband/sw/rdmavt/srq.c
index 67786d417493..f7c48e9023de 100644
--- a/drivers/staging/rdma/hfi1/srq.c
+++ b/drivers/infiniband/sw/rdmavt/srq.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -52,96 +49,50 @@
52#include <linux/slab.h> 49#include <linux/slab.h>
53#include <linux/vmalloc.h> 50#include <linux/vmalloc.h>
54 51
55#include "verbs.h" 52#include "srq.h"
53#include "vt.h"
56 54
57/** 55/**
58 * hfi1_post_srq_receive - post a receive on a shared receive queue 56 * rvt_driver_srq_init - init srq resources on a per driver basis
59 * @ibsrq: the SRQ to post the receive on 57 * @rdi: rvt dev structure
60 * @wr: the list of work requests to post
61 * @bad_wr: A pointer to the first WR to cause a problem is put here
62 * 58 *
63 * This may be called from interrupt context. 59 * Do any initialization needed when a driver registers with rdmavt.
64 */ 60 */
65int hfi1_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr, 61void rvt_driver_srq_init(struct rvt_dev_info *rdi)
66 struct ib_recv_wr **bad_wr)
67{ 62{
68 struct hfi1_srq *srq = to_isrq(ibsrq); 63 spin_lock_init(&rdi->n_srqs_lock);
69 struct hfi1_rwq *wq; 64 rdi->n_srqs_allocated = 0;
70 unsigned long flags;
71 int ret;
72
73 for (; wr; wr = wr->next) {
74 struct hfi1_rwqe *wqe;
75 u32 next;
76 int i;
77
78 if ((unsigned) wr->num_sge > srq->rq.max_sge) {
79 *bad_wr = wr;
80 ret = -EINVAL;
81 goto bail;
82 }
83
84 spin_lock_irqsave(&srq->rq.lock, flags);
85 wq = srq->rq.wq;
86 next = wq->head + 1;
87 if (next >= srq->rq.size)
88 next = 0;
89 if (next == wq->tail) {
90 spin_unlock_irqrestore(&srq->rq.lock, flags);
91 *bad_wr = wr;
92 ret = -ENOMEM;
93 goto bail;
94 }
95
96 wqe = get_rwqe_ptr(&srq->rq, wq->head);
97 wqe->wr_id = wr->wr_id;
98 wqe->num_sge = wr->num_sge;
99 for (i = 0; i < wr->num_sge; i++)
100 wqe->sg_list[i] = wr->sg_list[i];
101 /* Make sure queue entry is written before the head index. */
102 smp_wmb();
103 wq->head = next;
104 spin_unlock_irqrestore(&srq->rq.lock, flags);
105 }
106 ret = 0;
107
108bail:
109 return ret;
110} 65}
111 66
112/** 67/**
113 * hfi1_create_srq - create a shared receive queue 68 * rvt_create_srq - create a shared receive queue
114 * @ibpd: the protection domain of the SRQ to create 69 * @ibpd: the protection domain of the SRQ to create
115 * @srq_init_attr: the attributes of the SRQ 70 * @srq_init_attr: the attributes of the SRQ
116 * @udata: data from libibverbs when creating a user SRQ 71 * @udata: data from libibverbs when creating a user SRQ
72 *
73 * Return: Allocated srq object
117 */ 74 */
118struct ib_srq *hfi1_create_srq(struct ib_pd *ibpd, 75struct ib_srq *rvt_create_srq(struct ib_pd *ibpd,
119 struct ib_srq_init_attr *srq_init_attr, 76 struct ib_srq_init_attr *srq_init_attr,
120 struct ib_udata *udata) 77 struct ib_udata *udata)
121{ 78{
122 struct hfi1_ibdev *dev = to_idev(ibpd->device); 79 struct rvt_dev_info *dev = ib_to_rvt(ibpd->device);
123 struct hfi1_srq *srq; 80 struct rvt_srq *srq;
124 u32 sz; 81 u32 sz;
125 struct ib_srq *ret; 82 struct ib_srq *ret;
126 83
127 if (srq_init_attr->srq_type != IB_SRQT_BASIC) { 84 if (srq_init_attr->srq_type != IB_SRQT_BASIC)
128 ret = ERR_PTR(-ENOSYS); 85 return ERR_PTR(-ENOSYS);
129 goto done;
130 }
131 86
132 if (srq_init_attr->attr.max_sge == 0 || 87 if (srq_init_attr->attr.max_sge == 0 ||
133 srq_init_attr->attr.max_sge > hfi1_max_srq_sges || 88 srq_init_attr->attr.max_sge > dev->dparms.props.max_srq_sge ||
134 srq_init_attr->attr.max_wr == 0 || 89 srq_init_attr->attr.max_wr == 0 ||
135 srq_init_attr->attr.max_wr > hfi1_max_srq_wrs) { 90 srq_init_attr->attr.max_wr > dev->dparms.props.max_srq_wr)
136 ret = ERR_PTR(-EINVAL); 91 return ERR_PTR(-EINVAL);
137 goto done;
138 }
139 92
140 srq = kmalloc(sizeof(*srq), GFP_KERNEL); 93 srq = kmalloc(sizeof(*srq), GFP_KERNEL);
141 if (!srq) { 94 if (!srq)
142 ret = ERR_PTR(-ENOMEM); 95 return ERR_PTR(-ENOMEM);
143 goto done;
144 }
145 96
146 /* 97 /*
147 * Need to use vmalloc() if we want to support large #s of entries. 98 * Need to use vmalloc() if we want to support large #s of entries.
@@ -149,8 +100,8 @@ struct ib_srq *hfi1_create_srq(struct ib_pd *ibpd,
149 srq->rq.size = srq_init_attr->attr.max_wr + 1; 100 srq->rq.size = srq_init_attr->attr.max_wr + 1;
150 srq->rq.max_sge = srq_init_attr->attr.max_sge; 101 srq->rq.max_sge = srq_init_attr->attr.max_sge;
151 sz = sizeof(struct ib_sge) * srq->rq.max_sge + 102 sz = sizeof(struct ib_sge) * srq->rq.max_sge +
152 sizeof(struct hfi1_rwqe); 103 sizeof(struct rvt_rwqe);
153 srq->rq.wq = vmalloc_user(sizeof(struct hfi1_rwq) + srq->rq.size * sz); 104 srq->rq.wq = vmalloc_user(sizeof(struct rvt_rwq) + srq->rq.size * sz);
154 if (!srq->rq.wq) { 105 if (!srq->rq.wq) {
155 ret = ERR_PTR(-ENOMEM); 106 ret = ERR_PTR(-ENOMEM);
156 goto bail_srq; 107 goto bail_srq;
@@ -158,15 +109,15 @@ struct ib_srq *hfi1_create_srq(struct ib_pd *ibpd,
158 109
159 /* 110 /*
160 * Return the address of the RWQ as the offset to mmap. 111 * Return the address of the RWQ as the offset to mmap.
161 * See hfi1_mmap() for details. 112 * See rvt_mmap() for details.
162 */ 113 */
163 if (udata && udata->outlen >= sizeof(__u64)) { 114 if (udata && udata->outlen >= sizeof(__u64)) {
164 int err; 115 int err;
165 u32 s = sizeof(struct hfi1_rwq) + srq->rq.size * sz; 116 u32 s = sizeof(struct rvt_rwq) + srq->rq.size * sz;
166 117
167 srq->ip = 118 srq->ip =
168 hfi1_create_mmap_info(dev, s, ibpd->uobject->context, 119 rvt_create_mmap_info(dev, s, ibpd->uobject->context,
169 srq->rq.wq); 120 srq->rq.wq);
170 if (!srq->ip) { 121 if (!srq->ip) {
171 ret = ERR_PTR(-ENOMEM); 122 ret = ERR_PTR(-ENOMEM);
172 goto bail_wq; 123 goto bail_wq;
@@ -178,8 +129,9 @@ struct ib_srq *hfi1_create_srq(struct ib_pd *ibpd,
178 ret = ERR_PTR(err); 129 ret = ERR_PTR(err);
179 goto bail_ip; 130 goto bail_ip;
180 } 131 }
181 } else 132 } else {
182 srq->ip = NULL; 133 srq->ip = NULL;
134 }
183 135
184 /* 136 /*
185 * ib_create_srq() will initialize srq->ibsrq. 137 * ib_create_srq() will initialize srq->ibsrq.
@@ -190,7 +142,7 @@ struct ib_srq *hfi1_create_srq(struct ib_pd *ibpd,
190 srq->limit = srq_init_attr->attr.srq_limit; 142 srq->limit = srq_init_attr->attr.srq_limit;
191 143
192 spin_lock(&dev->n_srqs_lock); 144 spin_lock(&dev->n_srqs_lock);
193 if (dev->n_srqs_allocated == hfi1_max_srqs) { 145 if (dev->n_srqs_allocated == dev->dparms.props.max_srq) {
194 spin_unlock(&dev->n_srqs_lock); 146 spin_unlock(&dev->n_srqs_lock);
195 ret = ERR_PTR(-ENOMEM); 147 ret = ERR_PTR(-ENOMEM);
196 goto bail_ip; 148 goto bail_ip;
@@ -205,8 +157,7 @@ struct ib_srq *hfi1_create_srq(struct ib_pd *ibpd,
205 spin_unlock_irq(&dev->pending_lock); 157 spin_unlock_irq(&dev->pending_lock);
206 } 158 }
207 159
208 ret = &srq->ibsrq; 160 return &srq->ibsrq;
209 goto done;
210 161
211bail_ip: 162bail_ip:
212 kfree(srq->ip); 163 kfree(srq->ip);
@@ -214,46 +165,44 @@ bail_wq:
214 vfree(srq->rq.wq); 165 vfree(srq->rq.wq);
215bail_srq: 166bail_srq:
216 kfree(srq); 167 kfree(srq);
217done:
218 return ret; 168 return ret;
219} 169}
220 170
221/** 171/**
222 * hfi1_modify_srq - modify a shared receive queue 172 * rvt_modify_srq - modify a shared receive queue
223 * @ibsrq: the SRQ to modify 173 * @ibsrq: the SRQ to modify
224 * @attr: the new attributes of the SRQ 174 * @attr: the new attributes of the SRQ
225 * @attr_mask: indicates which attributes to modify 175 * @attr_mask: indicates which attributes to modify
226 * @udata: user data for libibverbs.so 176 * @udata: user data for libibverbs.so
177 *
178 * Return: 0 on success
227 */ 179 */
228int hfi1_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 180int rvt_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
229 enum ib_srq_attr_mask attr_mask, 181 enum ib_srq_attr_mask attr_mask,
230 struct ib_udata *udata) 182 struct ib_udata *udata)
231{ 183{
232 struct hfi1_srq *srq = to_isrq(ibsrq); 184 struct rvt_srq *srq = ibsrq_to_rvtsrq(ibsrq);
233 struct hfi1_rwq *wq; 185 struct rvt_dev_info *dev = ib_to_rvt(ibsrq->device);
186 struct rvt_rwq *wq;
234 int ret = 0; 187 int ret = 0;
235 188
236 if (attr_mask & IB_SRQ_MAX_WR) { 189 if (attr_mask & IB_SRQ_MAX_WR) {
237 struct hfi1_rwq *owq; 190 struct rvt_rwq *owq;
238 struct hfi1_rwqe *p; 191 struct rvt_rwqe *p;
239 u32 sz, size, n, head, tail; 192 u32 sz, size, n, head, tail;
240 193
241 /* Check that the requested sizes are below the limits. */ 194 /* Check that the requested sizes are below the limits. */
242 if ((attr->max_wr > hfi1_max_srq_wrs) || 195 if ((attr->max_wr > dev->dparms.props.max_srq_wr) ||
243 ((attr_mask & IB_SRQ_LIMIT) ? 196 ((attr_mask & IB_SRQ_LIMIT) ?
244 attr->srq_limit : srq->limit) > attr->max_wr) { 197 attr->srq_limit : srq->limit) > attr->max_wr)
245 ret = -EINVAL; 198 return -EINVAL;
246 goto bail;
247 }
248 199
249 sz = sizeof(struct hfi1_rwqe) + 200 sz = sizeof(struct rvt_rwqe) +
250 srq->rq.max_sge * sizeof(struct ib_sge); 201 srq->rq.max_sge * sizeof(struct ib_sge);
251 size = attr->max_wr + 1; 202 size = attr->max_wr + 1;
252 wq = vmalloc_user(sizeof(struct hfi1_rwq) + size * sz); 203 wq = vmalloc_user(sizeof(struct rvt_rwq) + size * sz);
253 if (!wq) { 204 if (!wq)
254 ret = -ENOMEM; 205 return -ENOMEM;
255 goto bail;
256 }
257 206
258 /* Check that we can write the offset to mmap. */ 207 /* Check that we can write the offset to mmap. */
259 if (udata && udata->inlen >= sizeof(__u64)) { 208 if (udata && udata->inlen >= sizeof(__u64)) {
@@ -264,8 +213,8 @@ int hfi1_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
264 sizeof(offset_addr)); 213 sizeof(offset_addr));
265 if (ret) 214 if (ret)
266 goto bail_free; 215 goto bail_free;
267 udata->outbuf = 216 udata->outbuf = (void __user *)
268 (void __user *) (unsigned long) offset_addr; 217 (unsigned long)offset_addr;
269 ret = ib_copy_to_udata(udata, &offset, 218 ret = ib_copy_to_udata(udata, &offset,
270 sizeof(offset)); 219 sizeof(offset));
271 if (ret) 220 if (ret)
@@ -296,16 +245,16 @@ int hfi1_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
296 n = 0; 245 n = 0;
297 p = wq->wq; 246 p = wq->wq;
298 while (tail != head) { 247 while (tail != head) {
299 struct hfi1_rwqe *wqe; 248 struct rvt_rwqe *wqe;
300 int i; 249 int i;
301 250
302 wqe = get_rwqe_ptr(&srq->rq, tail); 251 wqe = rvt_get_rwqe_ptr(&srq->rq, tail);
303 p->wr_id = wqe->wr_id; 252 p->wr_id = wqe->wr_id;
304 p->num_sge = wqe->num_sge; 253 p->num_sge = wqe->num_sge;
305 for (i = 0; i < wqe->num_sge; i++) 254 for (i = 0; i < wqe->num_sge; i++)
306 p->sg_list[i] = wqe->sg_list[i]; 255 p->sg_list[i] = wqe->sg_list[i];
307 n++; 256 n++;
308 p = (struct hfi1_rwqe *)((char *)p + sz); 257 p = (struct rvt_rwqe *)((char *)p + sz);
309 if (++tail >= srq->rq.size) 258 if (++tail >= srq->rq.size)
310 tail = 0; 259 tail = 0;
311 } 260 }
@@ -320,21 +269,21 @@ int hfi1_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
320 vfree(owq); 269 vfree(owq);
321 270
322 if (srq->ip) { 271 if (srq->ip) {
323 struct hfi1_mmap_info *ip = srq->ip; 272 struct rvt_mmap_info *ip = srq->ip;
324 struct hfi1_ibdev *dev = to_idev(srq->ibsrq.device); 273 struct rvt_dev_info *dev = ib_to_rvt(srq->ibsrq.device);
325 u32 s = sizeof(struct hfi1_rwq) + size * sz; 274 u32 s = sizeof(struct rvt_rwq) + size * sz;
326 275
327 hfi1_update_mmap_info(dev, ip, s, wq); 276 rvt_update_mmap_info(dev, ip, s, wq);
328 277
329 /* 278 /*
330 * Return the offset to mmap. 279 * Return the offset to mmap.
331 * See hfi1_mmap() for details. 280 * See rvt_mmap() for details.
332 */ 281 */
333 if (udata && udata->inlen >= sizeof(__u64)) { 282 if (udata && udata->inlen >= sizeof(__u64)) {
334 ret = ib_copy_to_udata(udata, &ip->offset, 283 ret = ib_copy_to_udata(udata, &ip->offset,
335 sizeof(ip->offset)); 284 sizeof(ip->offset));
336 if (ret) 285 if (ret)
337 goto bail; 286 return ret;
338 } 287 }
339 288
340 /* 289 /*
@@ -355,19 +304,24 @@ int hfi1_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
355 srq->limit = attr->srq_limit; 304 srq->limit = attr->srq_limit;
356 spin_unlock_irq(&srq->rq.lock); 305 spin_unlock_irq(&srq->rq.lock);
357 } 306 }
358 goto bail; 307 return ret;
359 308
360bail_unlock: 309bail_unlock:
361 spin_unlock_irq(&srq->rq.lock); 310 spin_unlock_irq(&srq->rq.lock);
362bail_free: 311bail_free:
363 vfree(wq); 312 vfree(wq);
364bail:
365 return ret; 313 return ret;
366} 314}
367 315
368int hfi1_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr) 316/** rvt_query_srq - query srq data
317 * @ibsrq: srq to query
318 * @attr: return info in attr
319 *
320 * Return: always 0
321 */
322int rvt_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr)
369{ 323{
370 struct hfi1_srq *srq = to_isrq(ibsrq); 324 struct rvt_srq *srq = ibsrq_to_rvtsrq(ibsrq);
371 325
372 attr->max_wr = srq->rq.size - 1; 326 attr->max_wr = srq->rq.size - 1;
373 attr->max_sge = srq->rq.max_sge; 327 attr->max_sge = srq->rq.max_sge;
@@ -376,19 +330,21 @@ int hfi1_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr)
376} 330}
377 331
378/** 332/**
379 * hfi1_destroy_srq - destroy a shared receive queue 333 * rvt_destroy_srq - destory an srq
380 * @ibsrq: the SRQ to destroy 334 * @ibsrq: srq object to destroy
335 *
336 * Return always 0
381 */ 337 */
382int hfi1_destroy_srq(struct ib_srq *ibsrq) 338int rvt_destroy_srq(struct ib_srq *ibsrq)
383{ 339{
384 struct hfi1_srq *srq = to_isrq(ibsrq); 340 struct rvt_srq *srq = ibsrq_to_rvtsrq(ibsrq);
385 struct hfi1_ibdev *dev = to_idev(ibsrq->device); 341 struct rvt_dev_info *dev = ib_to_rvt(ibsrq->device);
386 342
387 spin_lock(&dev->n_srqs_lock); 343 spin_lock(&dev->n_srqs_lock);
388 dev->n_srqs_allocated--; 344 dev->n_srqs_allocated--;
389 spin_unlock(&dev->n_srqs_lock); 345 spin_unlock(&dev->n_srqs_lock);
390 if (srq->ip) 346 if (srq->ip)
391 kref_put(&srq->ip->ref, hfi1_release_mmap_info); 347 kref_put(&srq->ip->ref, rvt_release_mmap_info);
392 else 348 else
393 vfree(srq->rq.wq); 349 vfree(srq->rq.wq);
394 kfree(srq); 350 kfree(srq);
diff --git a/drivers/infiniband/sw/rdmavt/srq.h b/drivers/infiniband/sw/rdmavt/srq.h
new file mode 100644
index 000000000000..bf0eaaf56465
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/srq.h
@@ -0,0 +1,62 @@
1#ifndef DEF_RVTSRQ_H
2#define DEF_RVTSRQ_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52void rvt_driver_srq_init(struct rvt_dev_info *rdi);
53struct ib_srq *rvt_create_srq(struct ib_pd *ibpd,
54 struct ib_srq_init_attr *srq_init_attr,
55 struct ib_udata *udata);
56int rvt_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
57 enum ib_srq_attr_mask attr_mask,
58 struct ib_udata *udata);
59int rvt_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
60int rvt_destroy_srq(struct ib_srq *ibsrq);
61
62#endif /* DEF_RVTSRQ_H */
diff --git a/drivers/infiniband/sw/rdmavt/trace.c b/drivers/infiniband/sw/rdmavt/trace.c
new file mode 100644
index 000000000000..d593285a349c
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/trace.c
@@ -0,0 +1,49 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#define CREATE_TRACE_POINTS
49#include "trace.h"
diff --git a/drivers/infiniband/sw/rdmavt/trace.h b/drivers/infiniband/sw/rdmavt/trace.h
new file mode 100644
index 000000000000..6c0457db5499
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/trace.h
@@ -0,0 +1,187 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#undef TRACE_SYSTEM_VAR
49#define TRACE_SYSTEM_VAR rdmavt
50
51#if !defined(__RDMAVT_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
52#define __RDMAVT_TRACE_H
53
54#include <linux/tracepoint.h>
55#include <linux/trace_seq.h>
56
57#include <rdma/ib_verbs.h>
58#include <rdma/rdma_vt.h>
59
60#define RDI_DEV_ENTRY(rdi) __string(dev, rdi->driver_f.get_card_name(rdi))
61#define RDI_DEV_ASSIGN(rdi) __assign_str(dev, rdi->driver_f.get_card_name(rdi))
62
63#undef TRACE_SYSTEM
64#define TRACE_SYSTEM rdmavt
65
66TRACE_EVENT(rvt_dbg,
67 TP_PROTO(struct rvt_dev_info *rdi,
68 const char *msg),
69 TP_ARGS(rdi, msg),
70 TP_STRUCT__entry(
71 RDI_DEV_ENTRY(rdi)
72 __string(msg, msg)
73 ),
74 TP_fast_assign(
75 RDI_DEV_ASSIGN(rdi);
76 __assign_str(msg, msg);
77 ),
78 TP_printk("[%s]: %s", __get_str(dev), __get_str(msg))
79);
80
81#undef TRACE_SYSTEM
82#define TRACE_SYSTEM rvt_qphash
83DECLARE_EVENT_CLASS(rvt_qphash_template,
84 TP_PROTO(struct rvt_qp *qp, u32 bucket),
85 TP_ARGS(qp, bucket),
86 TP_STRUCT__entry(
87 RDI_DEV_ENTRY(ib_to_rvt(qp->ibqp.device))
88 __field(u32, qpn)
89 __field(u32, bucket)
90 ),
91 TP_fast_assign(
92 RDI_DEV_ASSIGN(ib_to_rvt(qp->ibqp.device))
93 __entry->qpn = qp->ibqp.qp_num;
94 __entry->bucket = bucket;
95 ),
96 TP_printk(
97 "[%s] qpn 0x%x bucket %u",
98 __get_str(dev),
99 __entry->qpn,
100 __entry->bucket
101 )
102);
103
104DEFINE_EVENT(rvt_qphash_template, rvt_qpinsert,
105 TP_PROTO(struct rvt_qp *qp, u32 bucket),
106 TP_ARGS(qp, bucket));
107
108DEFINE_EVENT(rvt_qphash_template, rvt_qpremove,
109 TP_PROTO(struct rvt_qp *qp, u32 bucket),
110 TP_ARGS(qp, bucket));
111
112#undef TRACE_SYSTEM
113#define TRACE_SYSTEM rvt_tx
114
115#define wr_opcode_name(opcode) { IB_WR_##opcode, #opcode }
116#define show_wr_opcode(opcode) \
117__print_symbolic(opcode, \
118 wr_opcode_name(RDMA_WRITE), \
119 wr_opcode_name(RDMA_WRITE_WITH_IMM), \
120 wr_opcode_name(SEND), \
121 wr_opcode_name(SEND_WITH_IMM), \
122 wr_opcode_name(RDMA_READ), \
123 wr_opcode_name(ATOMIC_CMP_AND_SWP), \
124 wr_opcode_name(ATOMIC_FETCH_AND_ADD), \
125 wr_opcode_name(LSO), \
126 wr_opcode_name(SEND_WITH_INV), \
127 wr_opcode_name(RDMA_READ_WITH_INV), \
128 wr_opcode_name(LOCAL_INV), \
129 wr_opcode_name(MASKED_ATOMIC_CMP_AND_SWP), \
130 wr_opcode_name(MASKED_ATOMIC_FETCH_AND_ADD))
131
132#define POS_PRN \
133"[%s] wr_id %llx qpn %x psn 0x%x lpsn 0x%x length %u opcode 0x%.2x,%s size %u avail %u head %u last %u"
134
135TRACE_EVENT(
136 rvt_post_one_wr,
137 TP_PROTO(struct rvt_qp *qp, struct rvt_swqe *wqe),
138 TP_ARGS(qp, wqe),
139 TP_STRUCT__entry(
140 RDI_DEV_ENTRY(ib_to_rvt(qp->ibqp.device))
141 __field(u64, wr_id)
142 __field(u32, qpn)
143 __field(u32, psn)
144 __field(u32, lpsn)
145 __field(u32, length)
146 __field(u32, opcode)
147 __field(u32, size)
148 __field(u32, avail)
149 __field(u32, head)
150 __field(u32, last)
151 ),
152 TP_fast_assign(
153 RDI_DEV_ASSIGN(ib_to_rvt(qp->ibqp.device))
154 __entry->wr_id = wqe->wr.wr_id;
155 __entry->qpn = qp->ibqp.qp_num;
156 __entry->psn = wqe->psn;
157 __entry->lpsn = wqe->lpsn;
158 __entry->length = wqe->length;
159 __entry->opcode = wqe->wr.opcode;
160 __entry->size = qp->s_size;
161 __entry->avail = qp->s_avail;
162 __entry->head = qp->s_head;
163 __entry->last = qp->s_last;
164 ),
165 TP_printk(
166 POS_PRN,
167 __get_str(dev),
168 __entry->wr_id,
169 __entry->qpn,
170 __entry->psn,
171 __entry->lpsn,
172 __entry->length,
173 __entry->opcode, show_wr_opcode(__entry->opcode),
174 __entry->size,
175 __entry->avail,
176 __entry->head,
177 __entry->last
178 )
179);
180
181#endif /* __RDMAVT_TRACE_H */
182
183#undef TRACE_INCLUDE_PATH
184#undef TRACE_INCLUDE_FILE
185#define TRACE_INCLUDE_PATH .
186#define TRACE_INCLUDE_FILE trace
187#include <trace/define_trace.h>
diff --git a/drivers/infiniband/sw/rdmavt/vt.c b/drivers/infiniband/sw/rdmavt/vt.c
new file mode 100644
index 000000000000..6caf5272ba1f
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/vt.c
@@ -0,0 +1,873 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <linux/module.h>
49#include <linux/kernel.h>
50#include "vt.h"
51#include "trace.h"
52
53#define RVT_UVERBS_ABI_VERSION 2
54
55MODULE_LICENSE("Dual BSD/GPL");
56MODULE_DESCRIPTION("RDMA Verbs Transport Library");
57
58static int rvt_init(void)
59{
60 /*
61 * rdmavt does not need to do anything special when it starts up. All it
62 * needs to do is sit and wait until a driver attempts registration.
63 */
64 return 0;
65}
66module_init(rvt_init);
67
68static void rvt_cleanup(void)
69{
70 /*
71 * Nothing to do at exit time either. The module won't be able to be
72 * removed until all drivers are gone which means all the dev structs
73 * are gone so there is really nothing to do.
74 */
75}
76module_exit(rvt_cleanup);
77
78/**
79 * rvt_alloc_device - allocate rdi
80 * @size: how big of a structure to allocate
81 * @nports: number of ports to allocate array slots for
82 *
83 * Use IB core device alloc to allocate space for the rdi which is assumed to be
84 * inside of the ib_device. Any extra space that drivers require should be
85 * included in size.
86 *
87 * We also allocate a port array based on the number of ports.
88 *
89 * Return: pointer to allocated rdi
90 */
91struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
92{
93 struct rvt_dev_info *rdi = ERR_PTR(-ENOMEM);
94
95 rdi = (struct rvt_dev_info *)ib_alloc_device(size);
96 if (!rdi)
97 return rdi;
98
99 rdi->ports = kcalloc(nports,
100 sizeof(struct rvt_ibport **),
101 GFP_KERNEL);
102 if (!rdi->ports)
103 ib_dealloc_device(&rdi->ibdev);
104
105 return rdi;
106}
107EXPORT_SYMBOL(rvt_alloc_device);
108
109static int rvt_query_device(struct ib_device *ibdev,
110 struct ib_device_attr *props,
111 struct ib_udata *uhw)
112{
113 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
114
115 if (uhw->inlen || uhw->outlen)
116 return -EINVAL;
117 /*
118 * Return rvt_dev_info.dparms.props contents
119 */
120 *props = rdi->dparms.props;
121 return 0;
122}
123
124static int rvt_modify_device(struct ib_device *device,
125 int device_modify_mask,
126 struct ib_device_modify *device_modify)
127{
128 /*
129 * There is currently no need to supply this based on qib and hfi1.
130 * Future drivers may need to implement this though.
131 */
132
133 return -EOPNOTSUPP;
134}
135
136/**
137 * rvt_query_port: Passes the query port call to the driver
138 * @ibdev: Verbs IB dev
139 * @port_num: port number, 1 based from ib core
140 * @props: structure to hold returned properties
141 *
142 * Return: 0 on success
143 */
144static int rvt_query_port(struct ib_device *ibdev, u8 port_num,
145 struct ib_port_attr *props)
146{
147 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
148 struct rvt_ibport *rvp;
149 int port_index = ibport_num_to_idx(ibdev, port_num);
150
151 if (port_index < 0)
152 return -EINVAL;
153
154 rvp = rdi->ports[port_index];
155 memset(props, 0, sizeof(*props));
156 props->sm_lid = rvp->sm_lid;
157 props->sm_sl = rvp->sm_sl;
158 props->port_cap_flags = rvp->port_cap_flags;
159 props->max_msg_sz = 0x80000000;
160 props->pkey_tbl_len = rvt_get_npkeys(rdi);
161 props->bad_pkey_cntr = rvp->pkey_violations;
162 props->qkey_viol_cntr = rvp->qkey_violations;
163 props->subnet_timeout = rvp->subnet_timeout;
164 props->init_type_reply = 0;
165
166 /* Populate the remaining ib_port_attr elements */
167 return rdi->driver_f.query_port_state(rdi, port_num, props);
168}
169
170/**
171 * rvt_modify_port
172 * @ibdev: Verbs IB dev
173 * @port_num: Port number, 1 based from ib core
174 * @port_modify_mask: How to change the port
175 * @props: Structure to fill in
176 *
177 * Return: 0 on success
178 */
179static int rvt_modify_port(struct ib_device *ibdev, u8 port_num,
180 int port_modify_mask, struct ib_port_modify *props)
181{
182 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
183 struct rvt_ibport *rvp;
184 int ret = 0;
185 int port_index = ibport_num_to_idx(ibdev, port_num);
186
187 if (port_index < 0)
188 return -EINVAL;
189
190 rvp = rdi->ports[port_index];
191 rvp->port_cap_flags |= props->set_port_cap_mask;
192 rvp->port_cap_flags &= ~props->clr_port_cap_mask;
193
194 if (props->set_port_cap_mask || props->clr_port_cap_mask)
195 rdi->driver_f.cap_mask_chg(rdi, port_num);
196 if (port_modify_mask & IB_PORT_SHUTDOWN)
197 ret = rdi->driver_f.shut_down_port(rdi, port_num);
198 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
199 rvp->qkey_violations = 0;
200
201 return ret;
202}
203
204/**
205 * rvt_query_pkey - Return a pkey from the table at a given index
206 * @ibdev: Verbs IB dev
207 * @port_num: Port number, 1 based from ib core
208 * @intex: Index into pkey table
209 *
210 * Return: 0 on failure pkey otherwise
211 */
212static int rvt_query_pkey(struct ib_device *ibdev, u8 port_num, u16 index,
213 u16 *pkey)
214{
215 /*
216 * Driver will be responsible for keeping rvt_dev_info.pkey_table up to
217 * date. This function will just return that value. There is no need to
218 * lock, if a stale value is read and sent to the user so be it there is
219 * no way to protect against that anyway.
220 */
221 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
222 int port_index;
223
224 port_index = ibport_num_to_idx(ibdev, port_num);
225 if (port_index < 0)
226 return -EINVAL;
227
228 if (index >= rvt_get_npkeys(rdi))
229 return -EINVAL;
230
231 *pkey = rvt_get_pkey(rdi, port_index, index);
232 return 0;
233}
234
235/**
236 * rvt_query_gid - Return a gid from the table
237 * @ibdev: Verbs IB dev
238 * @port_num: Port number, 1 based from ib core
239 * @index: = Index in table
240 * @gid: Gid to return
241 *
242 * Return: 0 on success
243 */
244static int rvt_query_gid(struct ib_device *ibdev, u8 port_num,
245 int guid_index, union ib_gid *gid)
246{
247 struct rvt_dev_info *rdi;
248 struct rvt_ibport *rvp;
249 int port_index;
250
251 /*
252 * Driver is responsible for updating the guid table. Which will be used
253 * to craft the return value. This will work similar to how query_pkey()
254 * is being done.
255 */
256 port_index = ibport_num_to_idx(ibdev, port_num);
257 if (port_index < 0)
258 return -EINVAL;
259
260 rdi = ib_to_rvt(ibdev);
261 rvp = rdi->ports[port_index];
262
263 gid->global.subnet_prefix = rvp->gid_prefix;
264
265 return rdi->driver_f.get_guid_be(rdi, rvp, guid_index,
266 &gid->global.interface_id);
267}
268
269struct rvt_ucontext {
270 struct ib_ucontext ibucontext;
271};
272
273static inline struct rvt_ucontext *to_iucontext(struct ib_ucontext
274 *ibucontext)
275{
276 return container_of(ibucontext, struct rvt_ucontext, ibucontext);
277}
278
279/**
280 * rvt_alloc_ucontext - Allocate a user context
281 * @ibdev: Vers IB dev
282 * @data: User data allocated
283 */
284static struct ib_ucontext *rvt_alloc_ucontext(struct ib_device *ibdev,
285 struct ib_udata *udata)
286{
287 struct rvt_ucontext *context;
288
289 context = kmalloc(sizeof(*context), GFP_KERNEL);
290 if (!context)
291 return ERR_PTR(-ENOMEM);
292 return &context->ibucontext;
293}
294
295/**
296 *rvt_dealloc_ucontext - Free a user context
297 *@context - Free this
298 */
299static int rvt_dealloc_ucontext(struct ib_ucontext *context)
300{
301 kfree(to_iucontext(context));
302 return 0;
303}
304
305static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num,
306 struct ib_port_immutable *immutable)
307{
308 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
309 struct ib_port_attr attr;
310 int err, port_index;
311
312 port_index = ibport_num_to_idx(ibdev, port_num);
313 if (port_index < 0)
314 return -EINVAL;
315
316 err = rvt_query_port(ibdev, port_num, &attr);
317 if (err)
318 return err;
319
320 immutable->pkey_tbl_len = attr.pkey_tbl_len;
321 immutable->gid_tbl_len = attr.gid_tbl_len;
322 immutable->core_cap_flags = rdi->dparms.core_cap_flags;
323 immutable->max_mad_size = rdi->dparms.max_mad_size;
324
325 return 0;
326}
327
328enum {
329 MISC,
330 QUERY_DEVICE,
331 MODIFY_DEVICE,
332 QUERY_PORT,
333 MODIFY_PORT,
334 QUERY_PKEY,
335 QUERY_GID,
336 ALLOC_UCONTEXT,
337 DEALLOC_UCONTEXT,
338 GET_PORT_IMMUTABLE,
339 CREATE_QP,
340 MODIFY_QP,
341 DESTROY_QP,
342 QUERY_QP,
343 POST_SEND,
344 POST_RECV,
345 POST_SRQ_RECV,
346 CREATE_AH,
347 DESTROY_AH,
348 MODIFY_AH,
349 QUERY_AH,
350 CREATE_SRQ,
351 MODIFY_SRQ,
352 DESTROY_SRQ,
353 QUERY_SRQ,
354 ATTACH_MCAST,
355 DETACH_MCAST,
356 GET_DMA_MR,
357 REG_USER_MR,
358 DEREG_MR,
359 ALLOC_MR,
360 ALLOC_FMR,
361 MAP_PHYS_FMR,
362 UNMAP_FMR,
363 DEALLOC_FMR,
364 MMAP,
365 CREATE_CQ,
366 DESTROY_CQ,
367 POLL_CQ,
368 REQ_NOTFIY_CQ,
369 RESIZE_CQ,
370 ALLOC_PD,
371 DEALLOC_PD,
372 _VERB_IDX_MAX /* Must always be last! */
373};
374
375static inline int check_driver_override(struct rvt_dev_info *rdi,
376 size_t offset, void *func)
377{
378 if (!*(void **)((void *)&rdi->ibdev + offset)) {
379 *(void **)((void *)&rdi->ibdev + offset) = func;
380 return 0;
381 }
382
383 return 1;
384}
385
386static noinline int check_support(struct rvt_dev_info *rdi, int verb)
387{
388 switch (verb) {
389 case MISC:
390 /*
391 * These functions are not part of verbs specifically but are
392 * required for rdmavt to function.
393 */
394 if ((!rdi->driver_f.port_callback) ||
395 (!rdi->driver_f.get_card_name) ||
396 (!rdi->driver_f.get_pci_dev))
397 return -EINVAL;
398 break;
399
400 case QUERY_DEVICE:
401 check_driver_override(rdi, offsetof(struct ib_device,
402 query_device),
403 rvt_query_device);
404 break;
405
406 case MODIFY_DEVICE:
407 /*
408 * rdmavt does not support modify device currently drivers must
409 * provide.
410 */
411 if (!check_driver_override(rdi, offsetof(struct ib_device,
412 modify_device),
413 rvt_modify_device))
414 return -EOPNOTSUPP;
415 break;
416
417 case QUERY_PORT:
418 if (!check_driver_override(rdi, offsetof(struct ib_device,
419 query_port),
420 rvt_query_port))
421 if (!rdi->driver_f.query_port_state)
422 return -EINVAL;
423 break;
424
425 case MODIFY_PORT:
426 if (!check_driver_override(rdi, offsetof(struct ib_device,
427 modify_port),
428 rvt_modify_port))
429 if (!rdi->driver_f.cap_mask_chg ||
430 !rdi->driver_f.shut_down_port)
431 return -EINVAL;
432 break;
433
434 case QUERY_PKEY:
435 check_driver_override(rdi, offsetof(struct ib_device,
436 query_pkey),
437 rvt_query_pkey);
438 break;
439
440 case QUERY_GID:
441 if (!check_driver_override(rdi, offsetof(struct ib_device,
442 query_gid),
443 rvt_query_gid))
444 if (!rdi->driver_f.get_guid_be)
445 return -EINVAL;
446 break;
447
448 case ALLOC_UCONTEXT:
449 check_driver_override(rdi, offsetof(struct ib_device,
450 alloc_ucontext),
451 rvt_alloc_ucontext);
452 break;
453
454 case DEALLOC_UCONTEXT:
455 check_driver_override(rdi, offsetof(struct ib_device,
456 dealloc_ucontext),
457 rvt_dealloc_ucontext);
458 break;
459
460 case GET_PORT_IMMUTABLE:
461 check_driver_override(rdi, offsetof(struct ib_device,
462 get_port_immutable),
463 rvt_get_port_immutable);
464 break;
465
466 case CREATE_QP:
467 if (!check_driver_override(rdi, offsetof(struct ib_device,
468 create_qp),
469 rvt_create_qp))
470 if (!rdi->driver_f.qp_priv_alloc ||
471 !rdi->driver_f.qp_priv_free ||
472 !rdi->driver_f.notify_qp_reset ||
473 !rdi->driver_f.flush_qp_waiters ||
474 !rdi->driver_f.stop_send_queue ||
475 !rdi->driver_f.quiesce_qp)
476 return -EINVAL;
477 break;
478
479 case MODIFY_QP:
480 if (!check_driver_override(rdi, offsetof(struct ib_device,
481 modify_qp),
482 rvt_modify_qp))
483 if (!rdi->driver_f.notify_qp_reset ||
484 !rdi->driver_f.schedule_send ||
485 !rdi->driver_f.get_pmtu_from_attr ||
486 !rdi->driver_f.flush_qp_waiters ||
487 !rdi->driver_f.stop_send_queue ||
488 !rdi->driver_f.quiesce_qp ||
489 !rdi->driver_f.notify_error_qp ||
490 !rdi->driver_f.mtu_from_qp ||
491 !rdi->driver_f.mtu_to_path_mtu ||
492 !rdi->driver_f.shut_down_port ||
493 !rdi->driver_f.cap_mask_chg)
494 return -EINVAL;
495 break;
496
497 case DESTROY_QP:
498 if (!check_driver_override(rdi, offsetof(struct ib_device,
499 destroy_qp),
500 rvt_destroy_qp))
501 if (!rdi->driver_f.qp_priv_free ||
502 !rdi->driver_f.notify_qp_reset ||
503 !rdi->driver_f.flush_qp_waiters ||
504 !rdi->driver_f.stop_send_queue ||
505 !rdi->driver_f.quiesce_qp)
506 return -EINVAL;
507 break;
508
509 case QUERY_QP:
510 check_driver_override(rdi, offsetof(struct ib_device,
511 query_qp),
512 rvt_query_qp);
513 break;
514
515 case POST_SEND:
516 if (!check_driver_override(rdi, offsetof(struct ib_device,
517 post_send),
518 rvt_post_send))
519 if (!rdi->driver_f.schedule_send ||
520 !rdi->driver_f.do_send)
521 return -EINVAL;
522 break;
523
524 case POST_RECV:
525 check_driver_override(rdi, offsetof(struct ib_device,
526 post_recv),
527 rvt_post_recv);
528 break;
529 case POST_SRQ_RECV:
530 check_driver_override(rdi, offsetof(struct ib_device,
531 post_srq_recv),
532 rvt_post_srq_recv);
533 break;
534
535 case CREATE_AH:
536 check_driver_override(rdi, offsetof(struct ib_device,
537 create_ah),
538 rvt_create_ah);
539 break;
540
541 case DESTROY_AH:
542 check_driver_override(rdi, offsetof(struct ib_device,
543 destroy_ah),
544 rvt_destroy_ah);
545 break;
546
547 case MODIFY_AH:
548 check_driver_override(rdi, offsetof(struct ib_device,
549 modify_ah),
550 rvt_modify_ah);
551 break;
552
553 case QUERY_AH:
554 check_driver_override(rdi, offsetof(struct ib_device,
555 query_ah),
556 rvt_query_ah);
557 break;
558
559 case CREATE_SRQ:
560 check_driver_override(rdi, offsetof(struct ib_device,
561 create_srq),
562 rvt_create_srq);
563 break;
564
565 case MODIFY_SRQ:
566 check_driver_override(rdi, offsetof(struct ib_device,
567 modify_srq),
568 rvt_modify_srq);
569 break;
570
571 case DESTROY_SRQ:
572 check_driver_override(rdi, offsetof(struct ib_device,
573 destroy_srq),
574 rvt_destroy_srq);
575 break;
576
577 case QUERY_SRQ:
578 check_driver_override(rdi, offsetof(struct ib_device,
579 query_srq),
580 rvt_query_srq);
581 break;
582
583 case ATTACH_MCAST:
584 check_driver_override(rdi, offsetof(struct ib_device,
585 attach_mcast),
586 rvt_attach_mcast);
587 break;
588
589 case DETACH_MCAST:
590 check_driver_override(rdi, offsetof(struct ib_device,
591 detach_mcast),
592 rvt_detach_mcast);
593 break;
594
595 case GET_DMA_MR:
596 check_driver_override(rdi, offsetof(struct ib_device,
597 get_dma_mr),
598 rvt_get_dma_mr);
599 break;
600
601 case REG_USER_MR:
602 check_driver_override(rdi, offsetof(struct ib_device,
603 reg_user_mr),
604 rvt_reg_user_mr);
605 break;
606
607 case DEREG_MR:
608 check_driver_override(rdi, offsetof(struct ib_device,
609 dereg_mr),
610 rvt_dereg_mr);
611 break;
612
613 case ALLOC_FMR:
614 check_driver_override(rdi, offsetof(struct ib_device,
615 alloc_fmr),
616 rvt_alloc_fmr);
617 break;
618
619 case ALLOC_MR:
620 check_driver_override(rdi, offsetof(struct ib_device,
621 alloc_mr),
622 rvt_alloc_mr);
623 break;
624
625 case MAP_PHYS_FMR:
626 check_driver_override(rdi, offsetof(struct ib_device,
627 map_phys_fmr),
628 rvt_map_phys_fmr);
629 break;
630
631 case UNMAP_FMR:
632 check_driver_override(rdi, offsetof(struct ib_device,
633 unmap_fmr),
634 rvt_unmap_fmr);
635 break;
636
637 case DEALLOC_FMR:
638 check_driver_override(rdi, offsetof(struct ib_device,
639 dealloc_fmr),
640 rvt_dealloc_fmr);
641 break;
642
643 case MMAP:
644 check_driver_override(rdi, offsetof(struct ib_device,
645 mmap),
646 rvt_mmap);
647 break;
648
649 case CREATE_CQ:
650 check_driver_override(rdi, offsetof(struct ib_device,
651 create_cq),
652 rvt_create_cq);
653 break;
654
655 case DESTROY_CQ:
656 check_driver_override(rdi, offsetof(struct ib_device,
657 destroy_cq),
658 rvt_destroy_cq);
659 break;
660
661 case POLL_CQ:
662 check_driver_override(rdi, offsetof(struct ib_device,
663 poll_cq),
664 rvt_poll_cq);
665 break;
666
667 case REQ_NOTFIY_CQ:
668 check_driver_override(rdi, offsetof(struct ib_device,
669 req_notify_cq),
670 rvt_req_notify_cq);
671 break;
672
673 case RESIZE_CQ:
674 check_driver_override(rdi, offsetof(struct ib_device,
675 resize_cq),
676 rvt_resize_cq);
677 break;
678
679 case ALLOC_PD:
680 check_driver_override(rdi, offsetof(struct ib_device,
681 alloc_pd),
682 rvt_alloc_pd);
683 break;
684
685 case DEALLOC_PD:
686 check_driver_override(rdi, offsetof(struct ib_device,
687 dealloc_pd),
688 rvt_dealloc_pd);
689 break;
690
691 default:
692 return -EINVAL;
693 }
694
695 return 0;
696}
697
698/**
699 * rvt_register_device - register a driver
700 * @rdi: main dev structure for all of rdmavt operations
701 *
702 * It is up to drivers to allocate the rdi and fill in the appropriate
703 * information.
704 *
705 * Return: 0 on success otherwise an errno.
706 */
707int rvt_register_device(struct rvt_dev_info *rdi)
708{
709 int ret = 0, i;
710
711 if (!rdi)
712 return -EINVAL;
713
714 /*
715 * Check to ensure drivers have setup the required helpers for the verbs
716 * they want rdmavt to handle
717 */
718 for (i = 0; i < _VERB_IDX_MAX; i++)
719 if (check_support(rdi, i)) {
720 pr_err("Driver support req not met at %d\n", i);
721 return -EINVAL;
722 }
723
724
725 /* Once we get past here we can use rvt_pr macros and tracepoints */
726 trace_rvt_dbg(rdi, "Driver attempting registration");
727 rvt_mmap_init(rdi);
728
729 /* Queue Pairs */
730 ret = rvt_driver_qp_init(rdi);
731 if (ret) {
732 pr_err("Error in driver QP init.\n");
733 return -EINVAL;
734 }
735
736 /* Address Handle */
737 spin_lock_init(&rdi->n_ahs_lock);
738 rdi->n_ahs_allocated = 0;
739
740 /* Shared Receive Queue */
741 rvt_driver_srq_init(rdi);
742
743 /* Multicast */
744 rvt_driver_mcast_init(rdi);
745
746 /* Mem Region */
747 ret = rvt_driver_mr_init(rdi);
748 if (ret) {
749 pr_err("Error in driver MR init.\n");
750 goto bail_no_mr;
751 }
752
753 /* Completion queues */
754 ret = rvt_driver_cq_init(rdi);
755 if (ret) {
756 pr_err("Error in driver CQ init.\n");
757 goto bail_mr;
758 }
759
760 /* DMA Operations */
761 rdi->ibdev.dma_ops =
762 rdi->ibdev.dma_ops ? : &rvt_default_dma_mapping_ops;
763
764 /* Protection Domain */
765 spin_lock_init(&rdi->n_pds_lock);
766 rdi->n_pds_allocated = 0;
767
768 /*
769 * There are some things which could be set by underlying drivers but
770 * really should be up to rdmavt to set. For instance drivers can't know
771 * exactly which functions rdmavt supports, nor do they know the ABI
772 * version, so we do all of this sort of stuff here.
773 */
774 rdi->ibdev.uverbs_abi_ver = RVT_UVERBS_ABI_VERSION;
775 rdi->ibdev.uverbs_cmd_mask =
776 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
777 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
778 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
779 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
780 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
781 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
782 (1ull << IB_USER_VERBS_CMD_MODIFY_AH) |
783 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
784 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
785 (1ull << IB_USER_VERBS_CMD_REG_MR) |
786 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
787 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
788 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
789 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
790 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
791 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
792 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
793 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
794 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
795 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
796 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
797 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
798 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
799 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
800 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
801 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
802 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
803 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
804 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
805 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
806 rdi->ibdev.node_type = RDMA_NODE_IB_CA;
807 rdi->ibdev.num_comp_vectors = 1;
808
809 /* We are now good to announce we exist */
810 ret = ib_register_device(&rdi->ibdev, rdi->driver_f.port_callback);
811 if (ret) {
812 rvt_pr_err(rdi, "Failed to register driver with ib core.\n");
813 goto bail_cq;
814 }
815
816 rvt_create_mad_agents(rdi);
817
818 rvt_pr_info(rdi, "Registration with rdmavt done.\n");
819 return ret;
820
821bail_cq:
822 rvt_cq_exit(rdi);
823
824bail_mr:
825 rvt_mr_exit(rdi);
826
827bail_no_mr:
828 rvt_qp_exit(rdi);
829
830 return ret;
831}
832EXPORT_SYMBOL(rvt_register_device);
833
834/**
835 * rvt_unregister_device - remove a driver
836 * @rdi: rvt dev struct
837 */
838void rvt_unregister_device(struct rvt_dev_info *rdi)
839{
840 trace_rvt_dbg(rdi, "Driver is unregistering.");
841 if (!rdi)
842 return;
843
844 rvt_free_mad_agents(rdi);
845
846 ib_unregister_device(&rdi->ibdev);
847 rvt_cq_exit(rdi);
848 rvt_mr_exit(rdi);
849 rvt_qp_exit(rdi);
850}
851EXPORT_SYMBOL(rvt_unregister_device);
852
853/**
854 * rvt_init_port - init internal data for driver port
855 * @rdi: rvt dev strut
856 * @port: rvt port
857 * @port_index: 0 based index of ports, different from IB core port num
858 *
859 * Keep track of a list of ports. No need to have a detach port.
860 * They persist until the driver goes away.
861 *
862 * Return: always 0
863 */
864int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
865 int port_index, u16 *pkey_table)
866{
867
868 rdi->ports[port_index] = port;
869 rdi->ports[port_index]->pkey_table = pkey_table;
870
871 return 0;
872}
873EXPORT_SYMBOL(rvt_init_port);
diff --git a/drivers/infiniband/sw/rdmavt/vt.h b/drivers/infiniband/sw/rdmavt/vt.h
new file mode 100644
index 000000000000..6b01eaa4461b
--- /dev/null
+++ b/drivers/infiniband/sw/rdmavt/vt.h
@@ -0,0 +1,104 @@
1#ifndef DEF_RDMAVT_H
2#define DEF_RDMAVT_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52#include <linux/pci.h>
53#include "dma.h"
54#include "pd.h"
55#include "qp.h"
56#include "ah.h"
57#include "mr.h"
58#include "srq.h"
59#include "mcast.h"
60#include "mmap.h"
61#include "cq.h"
62#include "mad.h"
63#include "mmap.h"
64
65#define rvt_pr_info(rdi, fmt, ...) \
66 __rvt_pr_info(rdi->driver_f.get_pci_dev(rdi), \
67 rdi->driver_f.get_card_name(rdi), \
68 fmt, \
69 ##__VA_ARGS__)
70
71#define rvt_pr_warn(rdi, fmt, ...) \
72 __rvt_pr_warn(rdi->driver_f.get_pci_dev(rdi), \
73 rdi->driver_f.get_card_name(rdi), \
74 fmt, \
75 ##__VA_ARGS__)
76
77#define rvt_pr_err(rdi, fmt, ...) \
78 __rvt_pr_err(rdi->driver_f.get_pci_dev(rdi), \
79 rdi->driver_f.get_card_name(rdi), \
80 fmt, \
81 ##__VA_ARGS__)
82
83#define __rvt_pr_info(pdev, name, fmt, ...) \
84 dev_info(&pdev->dev, "%s: " fmt, name, ##__VA_ARGS__)
85
86#define __rvt_pr_warn(pdev, name, fmt, ...) \
87 dev_warn(&pdev->dev, "%s: " fmt, name, ##__VA_ARGS__)
88
89#define __rvt_pr_err(pdev, name, fmt, ...) \
90 dev_err(&pdev->dev, "%s: " fmt, name, ##__VA_ARGS__)
91
92static inline int ibport_num_to_idx(struct ib_device *ibdev, u8 port_num)
93{
94 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
95 int port_index;
96
97 port_index = port_num - 1; /* IB ports start at 1 our arrays at 0 */
98 if ((port_index < 0) || (port_index >= rdi->dparms.nports))
99 return -EINVAL;
100
101 return port_index;
102}
103
104#endif /* DEF_RDMAVT_H */
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 85be0de3ab26..caec8e9c4666 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -388,7 +388,7 @@ struct ipoib_dev_priv {
388 struct dentry *mcg_dentry; 388 struct dentry *mcg_dentry;
389 struct dentry *path_dentry; 389 struct dentry *path_dentry;
390#endif 390#endif
391 int hca_caps; 391 u64 hca_caps;
392 struct ipoib_ethtool_st ethtool; 392 struct ipoib_ethtool_st ethtool;
393 struct timer_list poll_timer; 393 struct timer_list poll_timer;
394 unsigned max_send_sge; 394 unsigned max_send_sge;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 899e6b7fb8a5..f0e55e47eb54 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -180,6 +180,7 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
180 struct sk_buff *skb; 180 struct sk_buff *skb;
181 u64 mapping[IPOIB_UD_RX_SG]; 181 u64 mapping[IPOIB_UD_RX_SG];
182 union ib_gid *dgid; 182 union ib_gid *dgid;
183 union ib_gid *sgid;
183 184
184 ipoib_dbg_data(priv, "recv completion: id %d, status: %d\n", 185 ipoib_dbg_data(priv, "recv completion: id %d, status: %d\n",
185 wr_id, wc->status); 186 wr_id, wc->status);
@@ -203,13 +204,6 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
203 return; 204 return;
204 } 205 }
205 206
206 /*
207 * Drop packets that this interface sent, ie multicast packets
208 * that the HCA has replicated.
209 */
210 if (wc->slid == priv->local_lid && wc->src_qp == priv->qp->qp_num)
211 goto repost;
212
213 memcpy(mapping, priv->rx_ring[wr_id].mapping, 207 memcpy(mapping, priv->rx_ring[wr_id].mapping,
214 IPOIB_UD_RX_SG * sizeof *mapping); 208 IPOIB_UD_RX_SG * sizeof *mapping);
215 209
@@ -239,6 +233,25 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
239 else 233 else
240 skb->pkt_type = PACKET_MULTICAST; 234 skb->pkt_type = PACKET_MULTICAST;
241 235
236 sgid = &((struct ib_grh *)skb->data)->sgid;
237
238 /*
239 * Drop packets that this interface sent, ie multicast packets
240 * that the HCA has replicated.
241 */
242 if (wc->slid == priv->local_lid && wc->src_qp == priv->qp->qp_num) {
243 int need_repost = 1;
244
245 if ((wc->wc_flags & IB_WC_GRH) &&
246 sgid->global.interface_id != priv->local_gid.global.interface_id)
247 need_repost = 0;
248
249 if (need_repost) {
250 dev_kfree_skb_any(skb);
251 goto repost;
252 }
253 }
254
242 skb_pull(skb, IB_GRH_BYTES); 255 skb_pull(skb, IB_GRH_BYTES);
243 256
244 skb->protocol = ((struct ipoib_header *) skb->data)->proto; 257 skb->protocol = ((struct ipoib_header *) skb->data)->proto;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 25509bbd4a05..80807d6e5c4c 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -51,6 +51,7 @@
51#include <net/addrconf.h> 51#include <net/addrconf.h>
52#include <linux/inetdevice.h> 52#include <linux/inetdevice.h>
53#include <rdma/ib_cache.h> 53#include <rdma/ib_cache.h>
54#include <linux/pci.h>
54 55
55#define DRV_VERSION "1.0.0" 56#define DRV_VERSION "1.0.0"
56 57
@@ -1590,11 +1591,67 @@ void ipoib_dev_cleanup(struct net_device *dev)
1590 priv->tx_ring = NULL; 1591 priv->tx_ring = NULL;
1591} 1592}
1592 1593
1594static int ipoib_set_vf_link_state(struct net_device *dev, int vf, int link_state)
1595{
1596 struct ipoib_dev_priv *priv = netdev_priv(dev);
1597
1598 return ib_set_vf_link_state(priv->ca, vf, priv->port, link_state);
1599}
1600
1601static int ipoib_get_vf_config(struct net_device *dev, int vf,
1602 struct ifla_vf_info *ivf)
1603{
1604 struct ipoib_dev_priv *priv = netdev_priv(dev);
1605 int err;
1606
1607 err = ib_get_vf_config(priv->ca, vf, priv->port, ivf);
1608 if (err)
1609 return err;
1610
1611 ivf->vf = vf;
1612
1613 return 0;
1614}
1615
1616static int ipoib_set_vf_guid(struct net_device *dev, int vf, u64 guid, int type)
1617{
1618 struct ipoib_dev_priv *priv = netdev_priv(dev);
1619
1620 if (type != IFLA_VF_IB_NODE_GUID && type != IFLA_VF_IB_PORT_GUID)
1621 return -EINVAL;
1622
1623 return ib_set_vf_guid(priv->ca, vf, priv->port, guid, type);
1624}
1625
1626static int ipoib_get_vf_stats(struct net_device *dev, int vf,
1627 struct ifla_vf_stats *vf_stats)
1628{
1629 struct ipoib_dev_priv *priv = netdev_priv(dev);
1630
1631 return ib_get_vf_stats(priv->ca, vf, priv->port, vf_stats);
1632}
1633
1593static const struct header_ops ipoib_header_ops = { 1634static const struct header_ops ipoib_header_ops = {
1594 .create = ipoib_hard_header, 1635 .create = ipoib_hard_header,
1595}; 1636};
1596 1637
1597static const struct net_device_ops ipoib_netdev_ops = { 1638static const struct net_device_ops ipoib_netdev_ops_pf = {
1639 .ndo_uninit = ipoib_uninit,
1640 .ndo_open = ipoib_open,
1641 .ndo_stop = ipoib_stop,
1642 .ndo_change_mtu = ipoib_change_mtu,
1643 .ndo_fix_features = ipoib_fix_features,
1644 .ndo_start_xmit = ipoib_start_xmit,
1645 .ndo_tx_timeout = ipoib_timeout,
1646 .ndo_set_rx_mode = ipoib_set_mcast_list,
1647 .ndo_get_iflink = ipoib_get_iflink,
1648 .ndo_set_vf_link_state = ipoib_set_vf_link_state,
1649 .ndo_get_vf_config = ipoib_get_vf_config,
1650 .ndo_get_vf_stats = ipoib_get_vf_stats,
1651 .ndo_set_vf_guid = ipoib_set_vf_guid,
1652};
1653
1654static const struct net_device_ops ipoib_netdev_ops_vf = {
1598 .ndo_uninit = ipoib_uninit, 1655 .ndo_uninit = ipoib_uninit,
1599 .ndo_open = ipoib_open, 1656 .ndo_open = ipoib_open,
1600 .ndo_stop = ipoib_stop, 1657 .ndo_stop = ipoib_stop,
@@ -1610,7 +1667,11 @@ void ipoib_setup(struct net_device *dev)
1610{ 1667{
1611 struct ipoib_dev_priv *priv = netdev_priv(dev); 1668 struct ipoib_dev_priv *priv = netdev_priv(dev);
1612 1669
1613 dev->netdev_ops = &ipoib_netdev_ops; 1670 if (priv->hca_caps & IB_DEVICE_VIRTUAL_FUNCTION)
1671 dev->netdev_ops = &ipoib_netdev_ops_vf;
1672 else
1673 dev->netdev_ops = &ipoib_netdev_ops_pf;
1674
1614 dev->header_ops = &ipoib_header_ops; 1675 dev->header_ops = &ipoib_header_ops;
1615 1676
1616 ipoib_set_ethtool_ops(dev); 1677 ipoib_set_ethtool_ops(dev);
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 1d1309091aba..0bd3cb2f3c67 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -839,7 +839,7 @@ static void srpt_zerolength_write_done(struct ib_cq *cq, struct ib_wc *wc)
839 if (srpt_set_ch_state(ch, CH_DISCONNECTED)) 839 if (srpt_set_ch_state(ch, CH_DISCONNECTED))
840 schedule_work(&ch->release_work); 840 schedule_work(&ch->release_work);
841 else 841 else
842 WARN_ONCE("%s-%d\n", ch->sess_name, ch->qp->qp_num); 842 WARN_ONCE(1, "%s-%d\n", ch->sess_name, ch->qp->qp_num);
843 } 843 }
844} 844}
845 845
diff --git a/drivers/net/ethernet/intel/i40e/Makefile b/drivers/net/ethernet/intel/i40e/Makefile
index b4729ba57c9c..3b3c63e54ed6 100644
--- a/drivers/net/ethernet/intel/i40e/Makefile
+++ b/drivers/net/ethernet/intel/i40e/Makefile
@@ -41,6 +41,7 @@ i40e-objs := i40e_main.o \
41 i40e_diag.o \ 41 i40e_diag.o \
42 i40e_txrx.o \ 42 i40e_txrx.o \
43 i40e_ptp.o \ 43 i40e_ptp.o \
44 i40e_client.o \
44 i40e_virtchnl_pf.o 45 i40e_virtchnl_pf.o
45 46
46i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o 47i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o
diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
index 2f6210ae8ba0..1ce6e9c0427d 100644
--- a/drivers/net/ethernet/intel/i40e/i40e.h
+++ b/drivers/net/ethernet/intel/i40e/i40e.h
@@ -58,6 +58,7 @@
58#ifdef I40E_FCOE 58#ifdef I40E_FCOE
59#include "i40e_fcoe.h" 59#include "i40e_fcoe.h"
60#endif 60#endif
61#include "i40e_client.h"
61#include "i40e_virtchnl.h" 62#include "i40e_virtchnl.h"
62#include "i40e_virtchnl_pf.h" 63#include "i40e_virtchnl_pf.h"
63#include "i40e_txrx.h" 64#include "i40e_txrx.h"
@@ -190,6 +191,7 @@ struct i40e_lump_tracking {
190 u16 search_hint; 191 u16 search_hint;
191 u16 list[0]; 192 u16 list[0];
192#define I40E_PILE_VALID_BIT 0x8000 193#define I40E_PILE_VALID_BIT 0x8000
194#define I40E_IWARP_IRQ_PILE_ID (I40E_PILE_VALID_BIT - 2)
193}; 195};
194 196
195#define I40E_DEFAULT_ATR_SAMPLE_RATE 20 197#define I40E_DEFAULT_ATR_SAMPLE_RATE 20
@@ -282,6 +284,8 @@ struct i40e_pf {
282#endif /* I40E_FCOE */ 284#endif /* I40E_FCOE */
283 u16 num_lan_qps; /* num lan queues this PF has set up */ 285 u16 num_lan_qps; /* num lan queues this PF has set up */
284 u16 num_lan_msix; /* num queue vectors for the base PF vsi */ 286 u16 num_lan_msix; /* num queue vectors for the base PF vsi */
287 u16 num_iwarp_msix; /* num of iwarp vectors for this PF */
288 int iwarp_base_vector;
285 int queues_left; /* queues left unclaimed */ 289 int queues_left; /* queues left unclaimed */
286 u16 alloc_rss_size; /* allocated RSS queues */ 290 u16 alloc_rss_size; /* allocated RSS queues */
287 u16 rss_size_max; /* HW defined max RSS queues */ 291 u16 rss_size_max; /* HW defined max RSS queues */
@@ -329,6 +333,7 @@ struct i40e_pf {
329#define I40E_FLAG_16BYTE_RX_DESC_ENABLED BIT_ULL(13) 333#define I40E_FLAG_16BYTE_RX_DESC_ENABLED BIT_ULL(13)
330#define I40E_FLAG_CLEAN_ADMINQ BIT_ULL(14) 334#define I40E_FLAG_CLEAN_ADMINQ BIT_ULL(14)
331#define I40E_FLAG_FILTER_SYNC BIT_ULL(15) 335#define I40E_FLAG_FILTER_SYNC BIT_ULL(15)
336#define I40E_FLAG_SERVICE_CLIENT_REQUESTED BIT_ULL(16)
332#define I40E_FLAG_PROCESS_MDD_EVENT BIT_ULL(17) 337#define I40E_FLAG_PROCESS_MDD_EVENT BIT_ULL(17)
333#define I40E_FLAG_PROCESS_VFLR_EVENT BIT_ULL(18) 338#define I40E_FLAG_PROCESS_VFLR_EVENT BIT_ULL(18)
334#define I40E_FLAG_SRIOV_ENABLED BIT_ULL(19) 339#define I40E_FLAG_SRIOV_ENABLED BIT_ULL(19)
@@ -571,6 +576,8 @@ struct i40e_vsi {
571 struct kobject *kobj; /* sysfs object */ 576 struct kobject *kobj; /* sysfs object */
572 bool current_isup; /* Sync 'link up' logging */ 577 bool current_isup; /* Sync 'link up' logging */
573 578
579 void *priv; /* client driver data reference. */
580
574 /* VSI specific handlers */ 581 /* VSI specific handlers */
575 irqreturn_t (*irq_handler)(int irq, void *data); 582 irqreturn_t (*irq_handler)(int irq, void *data);
576 583
@@ -728,6 +735,10 @@ void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
728 struct i40e_vsi_context *ctxt, 735 struct i40e_vsi_context *ctxt,
729 u8 enabled_tc, bool is_add); 736 u8 enabled_tc, bool is_add);
730#endif 737#endif
738void i40e_service_event_schedule(struct i40e_pf *pf);
739void i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id,
740 u8 *msg, u16 len);
741
731int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool enable); 742int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool enable);
732int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count); 743int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count);
733struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, u16 uplink_seid, 744struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, u16 uplink_seid,
@@ -750,6 +761,17 @@ static inline void i40e_dbg_pf_exit(struct i40e_pf *pf) {}
750static inline void i40e_dbg_init(void) {} 761static inline void i40e_dbg_init(void) {}
751static inline void i40e_dbg_exit(void) {} 762static inline void i40e_dbg_exit(void) {}
752#endif /* CONFIG_DEBUG_FS*/ 763#endif /* CONFIG_DEBUG_FS*/
764/* needed by client drivers */
765int i40e_lan_add_device(struct i40e_pf *pf);
766int i40e_lan_del_device(struct i40e_pf *pf);
767void i40e_client_subtask(struct i40e_pf *pf);
768void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi);
769void i40e_notify_client_of_netdev_open(struct i40e_vsi *vsi);
770void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset);
771void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs);
772void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id);
773int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id,
774 enum i40e_client_type type);
753/** 775/**
754 * i40e_irq_dynamic_enable - Enable default interrupt generation settings 776 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
755 * @vsi: pointer to a vsi 777 * @vsi: pointer to a vsi
diff --git a/drivers/net/ethernet/intel/i40e/i40e_client.c b/drivers/net/ethernet/intel/i40e/i40e_client.c
new file mode 100644
index 000000000000..0e6ac841321c
--- /dev/null
+++ b/drivers/net/ethernet/intel/i40e/i40e_client.c
@@ -0,0 +1,1012 @@
1/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include <linux/list.h>
28#include <linux/errno.h>
29
30#include "i40e.h"
31#include "i40e_prototype.h"
32#include "i40e_client.h"
33
34static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR;
35
36static LIST_HEAD(i40e_devices);
37static DEFINE_MUTEX(i40e_device_mutex);
38
39static LIST_HEAD(i40e_clients);
40static DEFINE_MUTEX(i40e_client_mutex);
41
42static LIST_HEAD(i40e_client_instances);
43static DEFINE_MUTEX(i40e_client_instance_mutex);
44
45static int i40e_client_virtchnl_send(struct i40e_info *ldev,
46 struct i40e_client *client,
47 u32 vf_id, u8 *msg, u16 len);
48
49static int i40e_client_setup_qvlist(struct i40e_info *ldev,
50 struct i40e_client *client,
51 struct i40e_qvlist_info *qvlist_info);
52
53static void i40e_client_request_reset(struct i40e_info *ldev,
54 struct i40e_client *client,
55 u32 reset_level);
56
57static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
58 struct i40e_client *client,
59 bool is_vf, u32 vf_id,
60 u32 flag, u32 valid_flag);
61
62static struct i40e_ops i40e_lan_ops = {
63 .virtchnl_send = i40e_client_virtchnl_send,
64 .setup_qvlist = i40e_client_setup_qvlist,
65 .request_reset = i40e_client_request_reset,
66 .update_vsi_ctxt = i40e_client_update_vsi_ctxt,
67};
68
69/**
70 * i40e_client_type_to_vsi_type - convert client type to vsi type
71 * @client_type: the i40e_client type
72 *
73 * returns the related vsi type value
74 **/
75static
76enum i40e_vsi_type i40e_client_type_to_vsi_type(enum i40e_client_type type)
77{
78 switch (type) {
79 case I40E_CLIENT_IWARP:
80 return I40E_VSI_IWARP;
81
82 case I40E_CLIENT_VMDQ2:
83 return I40E_VSI_VMDQ2;
84
85 default:
86 pr_err("i40e: Client type unknown\n");
87 return I40E_VSI_TYPE_UNKNOWN;
88 }
89}
90
91/**
92 * i40e_client_get_params - Get the params that can change at runtime
93 * @vsi: the VSI with the message
94 * @param: clinet param struct
95 *
96 **/
97static
98int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params)
99{
100 struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config;
101 int i = 0;
102
103 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
104 u8 tc = dcb_cfg->etscfg.prioritytable[i];
105 u16 qs_handle;
106
107 /* If TC is not enabled for VSI use TC0 for UP */
108 if (!(vsi->tc_config.enabled_tc & BIT(tc)))
109 tc = 0;
110
111 qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]);
112 params->qos.prio_qos[i].tc = tc;
113 params->qos.prio_qos[i].qs_handle = qs_handle;
114 if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) {
115 dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n",
116 tc, vsi->id);
117 return -EINVAL;
118 }
119 }
120
121 params->mtu = vsi->netdev->mtu;
122 return 0;
123}
124
125/**
126 * i40e_notify_client_of_vf_msg - call the client vf message callback
127 * @vsi: the VSI with the message
128 * @vf_id: the absolute VF id that sent the message
129 * @msg: message buffer
130 * @len: length of the message
131 *
132 * If there is a client to this VSI, call the client
133 **/
134void
135i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
136{
137 struct i40e_client_instance *cdev;
138
139 if (!vsi)
140 return;
141 mutex_lock(&i40e_client_instance_mutex);
142 list_for_each_entry(cdev, &i40e_client_instances, list) {
143 if (cdev->lan_info.pf == vsi->back) {
144 if (!cdev->client ||
145 !cdev->client->ops ||
146 !cdev->client->ops->virtchnl_receive) {
147 dev_dbg(&vsi->back->pdev->dev,
148 "Cannot locate client instance virtual channel receive routine\n");
149 continue;
150 }
151 cdev->client->ops->virtchnl_receive(&cdev->lan_info,
152 cdev->client,
153 vf_id, msg, len);
154 }
155 }
156 mutex_unlock(&i40e_client_instance_mutex);
157}
158
159/**
160 * i40e_notify_client_of_l2_param_changes - call the client notify callback
161 * @vsi: the VSI with l2 param changes
162 *
163 * If there is a client to this VSI, call the client
164 **/
165void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi)
166{
167 struct i40e_client_instance *cdev;
168 struct i40e_params params;
169
170 if (!vsi)
171 return;
172 memset(&params, 0, sizeof(params));
173 i40e_client_get_params(vsi, &params);
174 mutex_lock(&i40e_client_instance_mutex);
175 list_for_each_entry(cdev, &i40e_client_instances, list) {
176 if (cdev->lan_info.pf == vsi->back) {
177 if (!cdev->client ||
178 !cdev->client->ops ||
179 !cdev->client->ops->l2_param_change) {
180 dev_dbg(&vsi->back->pdev->dev,
181 "Cannot locate client instance l2_param_change routine\n");
182 continue;
183 }
184 cdev->lan_info.params = params;
185 cdev->client->ops->l2_param_change(&cdev->lan_info,
186 cdev->client,
187 &params);
188 }
189 }
190 mutex_unlock(&i40e_client_instance_mutex);
191}
192
193/**
194 * i40e_notify_client_of_netdev_open - call the client open callback
195 * @vsi: the VSI with netdev opened
196 *
197 * If there is a client to this netdev, call the client with open
198 **/
199void i40e_notify_client_of_netdev_open(struct i40e_vsi *vsi)
200{
201 struct i40e_client_instance *cdev;
202
203 if (!vsi)
204 return;
205 mutex_lock(&i40e_client_instance_mutex);
206 list_for_each_entry(cdev, &i40e_client_instances, list) {
207 if (cdev->lan_info.netdev == vsi->netdev) {
208 if (!cdev->client ||
209 !cdev->client->ops || !cdev->client->ops->open) {
210 dev_dbg(&vsi->back->pdev->dev,
211 "Cannot locate client instance open routine\n");
212 continue;
213 }
214 cdev->client->ops->open(&cdev->lan_info, cdev->client);
215 }
216 }
217 mutex_unlock(&i40e_client_instance_mutex);
218}
219
220/**
221 * i40e_client_release_qvlist
222 * @ldev: pointer to L2 context.
223 *
224 **/
225static void i40e_client_release_qvlist(struct i40e_info *ldev)
226{
227 struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
228 u32 i;
229
230 if (!ldev->qvlist_info)
231 return;
232
233 for (i = 0; i < qvlist_info->num_vectors; i++) {
234 struct i40e_pf *pf = ldev->pf;
235 struct i40e_qv_info *qv_info;
236 u32 reg_idx;
237
238 qv_info = &qvlist_info->qv_info[i];
239 if (!qv_info)
240 continue;
241 reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
242 wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
243 }
244 kfree(ldev->qvlist_info);
245 ldev->qvlist_info = NULL;
246}
247
248/**
249 * i40e_notify_client_of_netdev_close - call the client close callback
250 * @vsi: the VSI with netdev closed
251 * @reset: true when close called due to a reset pending
252 *
253 * If there is a client to this netdev, call the client with close
254 **/
255void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
256{
257 struct i40e_client_instance *cdev;
258
259 if (!vsi)
260 return;
261 mutex_lock(&i40e_client_instance_mutex);
262 list_for_each_entry(cdev, &i40e_client_instances, list) {
263 if (cdev->lan_info.netdev == vsi->netdev) {
264 if (!cdev->client ||
265 !cdev->client->ops || !cdev->client->ops->close) {
266 dev_dbg(&vsi->back->pdev->dev,
267 "Cannot locate client instance close routine\n");
268 continue;
269 }
270 cdev->client->ops->close(&cdev->lan_info, cdev->client,
271 reset);
272 i40e_client_release_qvlist(&cdev->lan_info);
273 }
274 }
275 mutex_unlock(&i40e_client_instance_mutex);
276}
277
278/**
279 * i40e_notify_client_of_vf_reset - call the client vf reset callback
280 * @pf: PF device pointer
281 * @vf_id: asolute id of VF being reset
282 *
283 * If there is a client attached to this PF, notify when a VF is reset
284 **/
285void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
286{
287 struct i40e_client_instance *cdev;
288
289 if (!pf)
290 return;
291 mutex_lock(&i40e_client_instance_mutex);
292 list_for_each_entry(cdev, &i40e_client_instances, list) {
293 if (cdev->lan_info.pf == pf) {
294 if (!cdev->client ||
295 !cdev->client->ops ||
296 !cdev->client->ops->vf_reset) {
297 dev_dbg(&pf->pdev->dev,
298 "Cannot locate client instance VF reset routine\n");
299 continue;
300 }
301 cdev->client->ops->vf_reset(&cdev->lan_info,
302 cdev->client, vf_id);
303 }
304 }
305 mutex_unlock(&i40e_client_instance_mutex);
306}
307
308/**
309 * i40e_notify_client_of_vf_enable - call the client vf notification callback
310 * @pf: PF device pointer
311 * @num_vfs: the number of VFs currently enabled, 0 for disable
312 *
313 * If there is a client attached to this PF, call its VF notification routine
314 **/
315void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
316{
317 struct i40e_client_instance *cdev;
318
319 if (!pf)
320 return;
321 mutex_lock(&i40e_client_instance_mutex);
322 list_for_each_entry(cdev, &i40e_client_instances, list) {
323 if (cdev->lan_info.pf == pf) {
324 if (!cdev->client ||
325 !cdev->client->ops ||
326 !cdev->client->ops->vf_enable) {
327 dev_dbg(&pf->pdev->dev,
328 "Cannot locate client instance VF enable routine\n");
329 continue;
330 }
331 cdev->client->ops->vf_enable(&cdev->lan_info,
332 cdev->client, num_vfs);
333 }
334 }
335 mutex_unlock(&i40e_client_instance_mutex);
336}
337
338/**
339 * i40e_vf_client_capable - ask the client if it likes the specified VF
340 * @pf: PF device pointer
341 * @vf_id: the VF in question
342 *
343 * If there is a client of the specified type attached to this PF, call
344 * its vf_capable routine
345 **/
346int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id,
347 enum i40e_client_type type)
348{
349 struct i40e_client_instance *cdev;
350 int capable = false;
351
352 if (!pf)
353 return false;
354 mutex_lock(&i40e_client_instance_mutex);
355 list_for_each_entry(cdev, &i40e_client_instances, list) {
356 if (cdev->lan_info.pf == pf) {
357 if (!cdev->client ||
358 !cdev->client->ops ||
359 !cdev->client->ops->vf_capable ||
360 !(cdev->client->type == type)) {
361 dev_dbg(&pf->pdev->dev,
362 "Cannot locate client instance VF capability routine\n");
363 continue;
364 }
365 capable = cdev->client->ops->vf_capable(&cdev->lan_info,
366 cdev->client,
367 vf_id);
368 break;
369 }
370 }
371 mutex_unlock(&i40e_client_instance_mutex);
372 return capable;
373}
374
375/**
376 * i40e_vsi_lookup - finds a matching VSI from the PF list starting at start_vsi
377 * @pf: board private structure
378 * @type: vsi type
379 * @start_vsi: a VSI pointer from where to start the search
380 *
381 * Returns non NULL on success or NULL for failure
382 **/
383struct i40e_vsi *i40e_vsi_lookup(struct i40e_pf *pf,
384 enum i40e_vsi_type type,
385 struct i40e_vsi *start_vsi)
386{
387 struct i40e_vsi *vsi;
388 int i = 0;
389
390 if (start_vsi) {
391 for (i = 0; i < pf->num_alloc_vsi; i++) {
392 vsi = pf->vsi[i];
393 if (vsi == start_vsi)
394 break;
395 }
396 }
397 for (; i < pf->num_alloc_vsi; i++) {
398 vsi = pf->vsi[i];
399 if (vsi && vsi->type == type)
400 return vsi;
401 }
402
403 return NULL;
404}
405
406/**
407 * i40e_client_add_instance - add a client instance struct to the instance list
408 * @pf: pointer to the board struct
409 * @client: pointer to a client struct in the client list.
410 *
411 * Returns cdev ptr on success, NULL on failure
412 **/
413static
414struct i40e_client_instance *i40e_client_add_instance(struct i40e_pf *pf,
415 struct i40e_client *client)
416{
417 struct i40e_client_instance *cdev;
418 struct netdev_hw_addr *mac = NULL;
419 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
420
421 mutex_lock(&i40e_client_instance_mutex);
422 list_for_each_entry(cdev, &i40e_client_instances, list) {
423 if ((cdev->lan_info.pf == pf) && (cdev->client == client)) {
424 cdev = NULL;
425 goto out;
426 }
427 }
428 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
429 if (!cdev)
430 goto out;
431
432 cdev->lan_info.pf = (void *)pf;
433 cdev->lan_info.netdev = vsi->netdev;
434 cdev->lan_info.pcidev = pf->pdev;
435 cdev->lan_info.fid = pf->hw.pf_id;
436 cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
437 cdev->lan_info.hw_addr = pf->hw.hw_addr;
438 cdev->lan_info.ops = &i40e_lan_ops;
439 cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
440 cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
441 cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
442 cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
443 cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
444 cdev->lan_info.fw_build = pf->hw.aq.fw_build;
445 set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
446
447 if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
448 kfree(cdev);
449 cdev = NULL;
450 goto out;
451 }
452
453 cdev->lan_info.msix_count = pf->num_iwarp_msix;
454 cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
455
456 mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
457 struct netdev_hw_addr, list);
458 if (mac)
459 ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
460 else
461 dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
462
463 cdev->client = client;
464 INIT_LIST_HEAD(&cdev->list);
465 list_add(&cdev->list, &i40e_client_instances);
466out:
467 mutex_unlock(&i40e_client_instance_mutex);
468 return cdev;
469}
470
471/**
472 * i40e_client_del_instance - removes a client instance from the list
473 * @pf: pointer to the board struct
474 *
475 * Returns 0 on success or non-0 on error
476 **/
477static
478int i40e_client_del_instance(struct i40e_pf *pf, struct i40e_client *client)
479{
480 struct i40e_client_instance *cdev, *tmp;
481 int ret = -ENODEV;
482
483 mutex_lock(&i40e_client_instance_mutex);
484 list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
485 if ((cdev->lan_info.pf != pf) || (cdev->client != client))
486 continue;
487
488 dev_info(&pf->pdev->dev, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
489 client->name, pf->hw.pf_id,
490 pf->hw.bus.device, pf->hw.bus.func);
491 list_del(&cdev->list);
492 kfree(cdev);
493 ret = 0;
494 break;
495 }
496 mutex_unlock(&i40e_client_instance_mutex);
497 return ret;
498}
499
500/**
501 * i40e_client_subtask - client maintenance work
502 * @pf: board private structure
503 **/
504void i40e_client_subtask(struct i40e_pf *pf)
505{
506 struct i40e_client_instance *cdev;
507 struct i40e_client *client;
508 int ret = 0;
509
510 if (!(pf->flags & I40E_FLAG_SERVICE_CLIENT_REQUESTED))
511 return;
512 pf->flags &= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED;
513
514 /* If we're down or resetting, just bail */
515 if (test_bit(__I40E_DOWN, &pf->state) ||
516 test_bit(__I40E_CONFIG_BUSY, &pf->state))
517 return;
518
519 /* Check client state and instantiate client if client registered */
520 mutex_lock(&i40e_client_mutex);
521 list_for_each_entry(client, &i40e_clients, list) {
522 /* first check client is registered */
523 if (!test_bit(__I40E_CLIENT_REGISTERED, &client->state))
524 continue;
525
526 /* Do we also need the LAN VSI to be up, to create instance */
527 if (!(client->flags & I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE)) {
528 /* check if L2 VSI is up, if not we are not ready */
529 if (test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
530 continue;
531 }
532
533 /* Add the client instance to the instance list */
534 cdev = i40e_client_add_instance(pf, client);
535 if (!cdev)
536 continue;
537
538 /* Also up the ref_cnt of no. of instances of this client */
539 atomic_inc(&client->ref_cnt);
540 dev_info(&pf->pdev->dev, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
541 client->name, pf->hw.pf_id,
542 pf->hw.bus.device, pf->hw.bus.func);
543
544 /* Send an Open request to the client */
545 atomic_inc(&cdev->ref_cnt);
546 if (client->ops && client->ops->open)
547 ret = client->ops->open(&cdev->lan_info, client);
548 atomic_dec(&cdev->ref_cnt);
549 if (!ret) {
550 set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
551 } else {
552 /* remove client instance */
553 i40e_client_del_instance(pf, client);
554 atomic_dec(&client->ref_cnt);
555 continue;
556 }
557 }
558 mutex_unlock(&i40e_client_mutex);
559}
560
561/**
562 * i40e_lan_add_device - add a lan device struct to the list of lan devices
563 * @pf: pointer to the board struct
564 *
565 * Returns 0 on success or none 0 on error
566 **/
567int i40e_lan_add_device(struct i40e_pf *pf)
568{
569 struct i40e_device *ldev;
570 int ret = 0;
571
572 mutex_lock(&i40e_device_mutex);
573 list_for_each_entry(ldev, &i40e_devices, list) {
574 if (ldev->pf == pf) {
575 ret = -EEXIST;
576 goto out;
577 }
578 }
579 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
580 if (!ldev) {
581 ret = -ENOMEM;
582 goto out;
583 }
584 ldev->pf = pf;
585 INIT_LIST_HEAD(&ldev->list);
586 list_add(&ldev->list, &i40e_devices);
587 dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
588 pf->hw.pf_id, pf->hw.bus.device, pf->hw.bus.func);
589
590 /* Since in some cases register may have happened before a device gets
591 * added, we can schedule a subtask to go initiate the clients.
592 */
593 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
594 i40e_service_event_schedule(pf);
595
596out:
597 mutex_unlock(&i40e_device_mutex);
598 return ret;
599}
600
601/**
602 * i40e_lan_del_device - removes a lan device from the device list
603 * @pf: pointer to the board struct
604 *
605 * Returns 0 on success or non-0 on error
606 **/
607int i40e_lan_del_device(struct i40e_pf *pf)
608{
609 struct i40e_device *ldev, *tmp;
610 int ret = -ENODEV;
611
612 mutex_lock(&i40e_device_mutex);
613 list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
614 if (ldev->pf == pf) {
615 dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
616 pf->hw.pf_id, pf->hw.bus.device,
617 pf->hw.bus.func);
618 list_del(&ldev->list);
619 kfree(ldev);
620 ret = 0;
621 break;
622 }
623 }
624
625 mutex_unlock(&i40e_device_mutex);
626 return ret;
627}
628
629/**
630 * i40e_client_release - release client specific resources
631 * @client: pointer to the registered client
632 *
633 * Return 0 on success or < 0 on error
634 **/
635static int i40e_client_release(struct i40e_client *client)
636{
637 struct i40e_client_instance *cdev, *tmp;
638 struct i40e_pf *pf = NULL;
639 int ret = 0;
640
641 LIST_HEAD(cdevs_tmp);
642
643 mutex_lock(&i40e_client_instance_mutex);
644 list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
645 if (strncmp(cdev->client->name, client->name,
646 I40E_CLIENT_STR_LENGTH))
647 continue;
648 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
649 if (atomic_read(&cdev->ref_cnt) > 0) {
650 ret = I40E_ERR_NOT_READY;
651 goto out;
652 }
653 pf = (struct i40e_pf *)cdev->lan_info.pf;
654 if (client->ops && client->ops->close)
655 client->ops->close(&cdev->lan_info, client,
656 false);
657 i40e_client_release_qvlist(&cdev->lan_info);
658 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
659
660 dev_warn(&pf->pdev->dev,
661 "Client %s instance for PF id %d closed\n",
662 client->name, pf->hw.pf_id);
663 }
664 /* delete the client instance from the list */
665 list_del(&cdev->list);
666 list_add(&cdev->list, &cdevs_tmp);
667 atomic_dec(&client->ref_cnt);
668 dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
669 client->name);
670 }
671out:
672 mutex_unlock(&i40e_client_instance_mutex);
673
674 /* free the client device and release its vsi */
675 list_for_each_entry_safe(cdev, tmp, &cdevs_tmp, list) {
676 kfree(cdev);
677 }
678 return ret;
679}
680
681/**
682 * i40e_client_prepare - prepare client specific resources
683 * @client: pointer to the registered client
684 *
685 * Return 0 on success or < 0 on error
686 **/
687static int i40e_client_prepare(struct i40e_client *client)
688{
689 struct i40e_device *ldev;
690 struct i40e_pf *pf;
691 int ret = 0;
692
693 mutex_lock(&i40e_device_mutex);
694 list_for_each_entry(ldev, &i40e_devices, list) {
695 pf = ldev->pf;
696 /* Start the client subtask */
697 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
698 i40e_service_event_schedule(pf);
699 }
700 mutex_unlock(&i40e_device_mutex);
701 return ret;
702}
703
704/**
705 * i40e_client_virtchnl_send - TBD
706 * @ldev: pointer to L2 context
707 * @client: Client pointer
708 * @vf_id: absolute VF identifier
709 * @msg: message buffer
710 * @len: length of message buffer
711 *
712 * Return 0 on success or < 0 on error
713 **/
714static int i40e_client_virtchnl_send(struct i40e_info *ldev,
715 struct i40e_client *client,
716 u32 vf_id, u8 *msg, u16 len)
717{
718 struct i40e_pf *pf = ldev->pf;
719 struct i40e_hw *hw = &pf->hw;
720 i40e_status err;
721
722 err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
723 0, msg, len, NULL);
724 if (err)
725 dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
726 err, hw->aq.asq_last_status);
727
728 return err;
729}
730
731/**
732 * i40e_client_setup_qvlist
733 * @ldev: pointer to L2 context.
734 * @client: Client pointer.
735 * @qv_info: queue and vector list
736 *
737 * Return 0 on success or < 0 on error
738 **/
739static int i40e_client_setup_qvlist(struct i40e_info *ldev,
740 struct i40e_client *client,
741 struct i40e_qvlist_info *qvlist_info)
742{
743 struct i40e_pf *pf = ldev->pf;
744 struct i40e_hw *hw = &pf->hw;
745 struct i40e_qv_info *qv_info;
746 u32 v_idx, i, reg_idx, reg;
747 u32 size;
748
749 size = sizeof(struct i40e_qvlist_info) +
750 (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
751 ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
752 ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
753
754 for (i = 0; i < qvlist_info->num_vectors; i++) {
755 qv_info = &qvlist_info->qv_info[i];
756 if (!qv_info)
757 continue;
758 v_idx = qv_info->v_idx;
759
760 /* Validate vector id belongs to this client */
761 if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
762 (v_idx < pf->iwarp_base_vector))
763 goto err;
764
765 ldev->qvlist_info->qv_info[i] = *qv_info;
766 reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
767
768 if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
769 /* Special case - No CEQ mapped on this vector */
770 wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
771 } else {
772 reg = (qv_info->ceq_idx &
773 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
774 (I40E_QUEUE_TYPE_PE_CEQ <<
775 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
776 wr32(hw, reg_idx, reg);
777
778 reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
779 (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
780 (qv_info->itr_idx <<
781 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
782 (I40E_QUEUE_END_OF_LIST <<
783 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
784 wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
785 }
786 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
787 reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
788 (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
789 (qv_info->itr_idx <<
790 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
791
792 wr32(hw, I40E_PFINT_AEQCTL, reg);
793 }
794 }
795
796 return 0;
797err:
798 kfree(ldev->qvlist_info);
799 ldev->qvlist_info = NULL;
800 return -EINVAL;
801}
802
803/**
804 * i40e_client_request_reset
805 * @ldev: pointer to L2 context.
806 * @client: Client pointer.
807 * @level: reset level
808 **/
809static void i40e_client_request_reset(struct i40e_info *ldev,
810 struct i40e_client *client,
811 u32 reset_level)
812{
813 struct i40e_pf *pf = ldev->pf;
814
815 switch (reset_level) {
816 case I40E_CLIENT_RESET_LEVEL_PF:
817 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
818 break;
819 case I40E_CLIENT_RESET_LEVEL_CORE:
820 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
821 break;
822 default:
823 dev_warn(&pf->pdev->dev,
824 "Client %s instance for PF id %d request an unsupported reset: %d.\n",
825 client->name, pf->hw.pf_id, reset_level);
826 break;
827 }
828
829 i40e_service_event_schedule(pf);
830}
831
832/**
833 * i40e_client_update_vsi_ctxt
834 * @ldev: pointer to L2 context.
835 * @client: Client pointer.
836 * @is_vf: if this for the VF
837 * @vf_id: if is_vf true this carries the vf_id
838 * @flag: Any device level setting that needs to be done for PE
839 * @valid_flag: Bits in this match up and enable changing of flag bits
840 *
841 * Return 0 on success or < 0 on error
842 **/
843static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
844 struct i40e_client *client,
845 bool is_vf, u32 vf_id,
846 u32 flag, u32 valid_flag)
847{
848 struct i40e_pf *pf = ldev->pf;
849 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
850 struct i40e_vsi_context ctxt;
851 bool update = true;
852 i40e_status err;
853
854 /* TODO: for now do not allow setting VF's VSI setting */
855 if (is_vf)
856 return -EINVAL;
857
858 ctxt.seid = pf->main_vsi_seid;
859 ctxt.pf_num = pf->hw.pf_id;
860 err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
861 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
862 if (err) {
863 dev_info(&pf->pdev->dev,
864 "couldn't get PF vsi config, err %s aq_err %s\n",
865 i40e_stat_str(&pf->hw, err),
866 i40e_aq_str(&pf->hw,
867 pf->hw.aq.asq_last_status));
868 return -ENOENT;
869 }
870
871 if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
872 (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
873 ctxt.info.valid_sections =
874 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
875 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
876 } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
877 !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
878 ctxt.info.valid_sections =
879 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
880 ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
881 } else {
882 update = false;
883 dev_warn(&pf->pdev->dev,
884 "Client %s instance for PF id %d request an unsupported Config: %x.\n",
885 client->name, pf->hw.pf_id, flag);
886 }
887
888 if (update) {
889 err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
890 if (err) {
891 dev_info(&pf->pdev->dev,
892 "update VSI ctxt for PE failed, err %s aq_err %s\n",
893 i40e_stat_str(&pf->hw, err),
894 i40e_aq_str(&pf->hw,
895 pf->hw.aq.asq_last_status));
896 }
897 }
898 return err;
899}
900
901/**
902 * i40e_register_client - Register a i40e client driver with the L2 driver
903 * @client: pointer to the i40e_client struct
904 *
905 * Returns 0 on success or non-0 on error
906 **/
907int i40e_register_client(struct i40e_client *client)
908{
909 int ret = 0;
910 enum i40e_vsi_type vsi_type;
911
912 if (!client) {
913 ret = -EIO;
914 goto out;
915 }
916
917 if (strlen(client->name) == 0) {
918 pr_info("i40e: Failed to register client with no name\n");
919 ret = -EIO;
920 goto out;
921 }
922
923 mutex_lock(&i40e_client_mutex);
924 if (i40e_client_is_registered(client)) {
925 pr_info("i40e: Client %s has already been registered!\n",
926 client->name);
927 mutex_unlock(&i40e_client_mutex);
928 ret = -EEXIST;
929 goto out;
930 }
931
932 if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
933 (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
934 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
935 client->name);
936 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
937 client->version.major, client->version.minor,
938 client->version.build,
939 i40e_client_interface_version_str);
940 mutex_unlock(&i40e_client_mutex);
941 ret = -EIO;
942 goto out;
943 }
944
945 vsi_type = i40e_client_type_to_vsi_type(client->type);
946 if (vsi_type == I40E_VSI_TYPE_UNKNOWN) {
947 pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
948 client->name, client->type);
949 mutex_unlock(&i40e_client_mutex);
950 ret = -EIO;
951 goto out;
952 }
953 list_add(&client->list, &i40e_clients);
954 set_bit(__I40E_CLIENT_REGISTERED, &client->state);
955 mutex_unlock(&i40e_client_mutex);
956
957 if (i40e_client_prepare(client)) {
958 ret = -EIO;
959 goto out;
960 }
961
962 pr_info("i40e: Registered client %s with return code %d\n",
963 client->name, ret);
964out:
965 return ret;
966}
967EXPORT_SYMBOL(i40e_register_client);
968
969/**
970 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
971 * @client: pointer to the i40e_client struct
972 *
973 * Returns 0 on success or non-0 on error
974 **/
975int i40e_unregister_client(struct i40e_client *client)
976{
977 int ret = 0;
978
979 /* When a unregister request comes through we would have to send
980 * a close for each of the client instances that were opened.
981 * client_release function is called to handle this.
982 */
983 if (!client || i40e_client_release(client)) {
984 ret = -EIO;
985 goto out;
986 }
987
988 /* TODO: check if device is in reset, or if that matters? */
989 mutex_lock(&i40e_client_mutex);
990 if (!i40e_client_is_registered(client)) {
991 pr_info("i40e: Client %s has not been registered\n",
992 client->name);
993 mutex_unlock(&i40e_client_mutex);
994 ret = -ENODEV;
995 goto out;
996 }
997 if (atomic_read(&client->ref_cnt) == 0) {
998 clear_bit(__I40E_CLIENT_REGISTERED, &client->state);
999 list_del(&client->list);
1000 pr_info("i40e: Unregistered client %s with return code %d\n",
1001 client->name, ret);
1002 } else {
1003 ret = I40E_ERR_NOT_READY;
1004 pr_err("i40e: Client %s failed unregister - client has open instances\n",
1005 client->name);
1006 }
1007
1008 mutex_unlock(&i40e_client_mutex);
1009out:
1010 return ret;
1011}
1012EXPORT_SYMBOL(i40e_unregister_client);
diff --git a/drivers/net/ethernet/intel/i40e/i40e_client.h b/drivers/net/ethernet/intel/i40e/i40e_client.h
new file mode 100644
index 000000000000..bf6b453d93a1
--- /dev/null
+++ b/drivers/net/ethernet/intel/i40e/i40e_client.h
@@ -0,0 +1,232 @@
1/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#ifndef _I40E_CLIENT_H_
28#define _I40E_CLIENT_H_
29
30#define I40E_CLIENT_STR_LENGTH 10
31
32/* Client interface version should be updated anytime there is a change in the
33 * existing APIs or data structures.
34 */
35#define I40E_CLIENT_VERSION_MAJOR 0
36#define I40E_CLIENT_VERSION_MINOR 01
37#define I40E_CLIENT_VERSION_BUILD 00
38#define I40E_CLIENT_VERSION_STR \
39 XSTRINGIFY(I40E_CLIENT_VERSION_MAJOR) "." \
40 XSTRINGIFY(I40E_CLIENT_VERSION_MINOR) "." \
41 XSTRINGIFY(I40E_CLIENT_VERSION_BUILD)
42
43struct i40e_client_version {
44 u8 major;
45 u8 minor;
46 u8 build;
47 u8 rsvd;
48};
49
50enum i40e_client_state {
51 __I40E_CLIENT_NULL,
52 __I40E_CLIENT_REGISTERED
53};
54
55enum i40e_client_instance_state {
56 __I40E_CLIENT_INSTANCE_NONE,
57 __I40E_CLIENT_INSTANCE_OPENED,
58};
59
60enum i40e_client_type {
61 I40E_CLIENT_IWARP,
62 I40E_CLIENT_VMDQ2
63};
64
65struct i40e_ops;
66struct i40e_client;
67
68/* HW does not define a type value for AEQ; only for RX/TX and CEQ.
69 * In order for us to keep the interface simple, SW will define a
70 * unique type value for AEQ.
71 */
72#define I40E_QUEUE_TYPE_PE_AEQ 0x80
73#define I40E_QUEUE_INVALID_IDX 0xFFFF
74
75struct i40e_qv_info {
76 u32 v_idx; /* msix_vector */
77 u16 ceq_idx;
78 u16 aeq_idx;
79 u8 itr_idx;
80};
81
82struct i40e_qvlist_info {
83 u32 num_vectors;
84 struct i40e_qv_info qv_info[1];
85};
86
87#define I40E_CLIENT_MSIX_ALL 0xFFFFFFFF
88
89/* set of LAN parameters useful for clients managed by LAN */
90
91/* Struct to hold per priority info */
92struct i40e_prio_qos_params {
93 u16 qs_handle; /* qs handle for prio */
94 u8 tc; /* TC mapped to prio */
95 u8 reserved;
96};
97
98#define I40E_CLIENT_MAX_USER_PRIORITY 8
99/* Struct to hold Client QoS */
100struct i40e_qos_params {
101 struct i40e_prio_qos_params prio_qos[I40E_CLIENT_MAX_USER_PRIORITY];
102};
103
104struct i40e_params {
105 struct i40e_qos_params qos;
106 u16 mtu;
107};
108
109/* Structure to hold Lan device info for a client device */
110struct i40e_info {
111 struct i40e_client_version version;
112 u8 lanmac[6];
113 struct net_device *netdev;
114 struct pci_dev *pcidev;
115 u8 __iomem *hw_addr;
116 u8 fid; /* function id, PF id or VF id */
117#define I40E_CLIENT_FTYPE_PF 0
118#define I40E_CLIENT_FTYPE_VF 1
119 u8 ftype; /* function type, PF or VF */
120 void *pf;
121
122 /* All L2 params that could change during the life span of the PF
123 * and needs to be communicated to the client when they change
124 */
125 struct i40e_qvlist_info *qvlist_info;
126 struct i40e_params params;
127 struct i40e_ops *ops;
128
129 u16 msix_count; /* number of msix vectors*/
130 /* Array down below will be dynamically allocated based on msix_count */
131 struct msix_entry *msix_entries;
132 u16 itr_index; /* Which ITR index the PE driver is suppose to use */
133 u16 fw_maj_ver; /* firmware major version */
134 u16 fw_min_ver; /* firmware minor version */
135 u32 fw_build; /* firmware build number */
136};
137
138#define I40E_CLIENT_RESET_LEVEL_PF 1
139#define I40E_CLIENT_RESET_LEVEL_CORE 2
140#define I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE BIT(1)
141
142struct i40e_ops {
143 /* setup_q_vector_list enables queues with a particular vector */
144 int (*setup_qvlist)(struct i40e_info *ldev, struct i40e_client *client,
145 struct i40e_qvlist_info *qv_info);
146
147 int (*virtchnl_send)(struct i40e_info *ldev, struct i40e_client *client,
148 u32 vf_id, u8 *msg, u16 len);
149
150 /* If the PE Engine is unresponsive, RDMA driver can request a reset.
151 * The level helps determine the level of reset being requested.
152 */
153 void (*request_reset)(struct i40e_info *ldev,
154 struct i40e_client *client, u32 level);
155
156 /* API for the RDMA driver to set certain VSI flags that control
157 * PE Engine.
158 */
159 int (*update_vsi_ctxt)(struct i40e_info *ldev,
160 struct i40e_client *client,
161 bool is_vf, u32 vf_id,
162 u32 flag, u32 valid_flag);
163};
164
165struct i40e_client_ops {
166 /* Should be called from register_client() or whenever PF is ready
167 * to create a specific client instance.
168 */
169 int (*open)(struct i40e_info *ldev, struct i40e_client *client);
170
171 /* Should be called when netdev is unavailable or when unregister
172 * call comes in. If the close is happenening due to a reset being
173 * triggered set the reset bit to true.
174 */
175 void (*close)(struct i40e_info *ldev, struct i40e_client *client,
176 bool reset);
177
178 /* called when some l2 managed parameters changes - mtu */
179 void (*l2_param_change)(struct i40e_info *ldev,
180 struct i40e_client *client,
181 struct i40e_params *params);
182
183 int (*virtchnl_receive)(struct i40e_info *ldev,
184 struct i40e_client *client, u32 vf_id,
185 u8 *msg, u16 len);
186
187 /* called when a VF is reset by the PF */
188 void (*vf_reset)(struct i40e_info *ldev,
189 struct i40e_client *client, u32 vf_id);
190
191 /* called when the number of VFs changes */
192 void (*vf_enable)(struct i40e_info *ldev,
193 struct i40e_client *client, u32 num_vfs);
194
195 /* returns true if VF is capable of specified offload */
196 int (*vf_capable)(struct i40e_info *ldev,
197 struct i40e_client *client, u32 vf_id);
198};
199
200/* Client device */
201struct i40e_client_instance {
202 struct list_head list;
203 struct i40e_info lan_info;
204 struct i40e_client *client;
205 unsigned long state;
206 /* A count of all the in-progress calls to the client */
207 atomic_t ref_cnt;
208};
209
210struct i40e_client {
211 struct list_head list; /* list of registered clients */
212 char name[I40E_CLIENT_STR_LENGTH];
213 struct i40e_client_version version;
214 unsigned long state; /* client state */
215 atomic_t ref_cnt; /* Count of all the client devices of this kind */
216 u32 flags;
217#define I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE BIT(0)
218#define I40E_TX_FLAGS_NOTIFY_OTHER_EVENTS BIT(2)
219 enum i40e_client_type type;
220 struct i40e_client_ops *ops; /* client ops provided by the client */
221};
222
223static inline bool i40e_client_is_registered(struct i40e_client *client)
224{
225 return test_bit(__I40E_CLIENT_REGISTERED, &client->state);
226}
227
228/* used by clients */
229int i40e_register_client(struct i40e_client *client);
230int i40e_unregister_client(struct i40e_client *client);
231
232#endif /* _I40E_CLIENT_H_ */
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 70d9605a0d9e..67006431726a 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -289,7 +289,7 @@ struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
289 * 289 *
290 * If not already scheduled, this puts the task into the work queue 290 * If not already scheduled, this puts the task into the work queue
291 **/ 291 **/
292static void i40e_service_event_schedule(struct i40e_pf *pf) 292void i40e_service_event_schedule(struct i40e_pf *pf)
293{ 293{
294 if (!test_bit(__I40E_DOWN, &pf->state) && 294 if (!test_bit(__I40E_DOWN, &pf->state) &&
295 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && 295 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
@@ -2230,7 +2230,7 @@ static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2230 netdev->mtu = new_mtu; 2230 netdev->mtu = new_mtu;
2231 if (netif_running(netdev)) 2231 if (netif_running(netdev))
2232 i40e_vsi_reinit_locked(vsi); 2232 i40e_vsi_reinit_locked(vsi);
2233 2233 i40e_notify_client_of_l2_param_changes(vsi);
2234 return 0; 2234 return 0;
2235} 2235}
2236 2236
@@ -4169,6 +4169,9 @@ static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4169 free_irq(pf->msix_entries[0].vector, pf); 4169 free_irq(pf->msix_entries[0].vector, pf);
4170 } 4170 }
4171 4171
4172 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4173 I40E_IWARP_IRQ_PILE_ID);
4174
4172 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); 4175 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
4173 for (i = 0; i < pf->num_alloc_vsi; i++) 4176 for (i = 0; i < pf->num_alloc_vsi; i++)
4174 if (pf->vsi[i]) 4177 if (pf->vsi[i])
@@ -4212,12 +4215,17 @@ static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4212 **/ 4215 **/
4213static void i40e_vsi_close(struct i40e_vsi *vsi) 4216static void i40e_vsi_close(struct i40e_vsi *vsi)
4214{ 4217{
4218 bool reset = false;
4219
4215 if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) 4220 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
4216 i40e_down(vsi); 4221 i40e_down(vsi);
4217 i40e_vsi_free_irq(vsi); 4222 i40e_vsi_free_irq(vsi);
4218 i40e_vsi_free_tx_resources(vsi); 4223 i40e_vsi_free_tx_resources(vsi);
4219 i40e_vsi_free_rx_resources(vsi); 4224 i40e_vsi_free_rx_resources(vsi);
4220 vsi->current_netdev_flags = 0; 4225 vsi->current_netdev_flags = 0;
4226 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4227 reset = true;
4228 i40e_notify_client_of_netdev_close(vsi, reset);
4221} 4229}
4222 4230
4223/** 4231/**
@@ -4850,6 +4858,12 @@ static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4850 ctxt.info = vsi->info; 4858 ctxt.info = vsi->info;
4851 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); 4859 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4852 4860
4861 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
4862 ctxt.info.valid_sections |=
4863 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
4864 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
4865 }
4866
4853 /* Update the VSI after updating the VSI queue-mapping information */ 4867 /* Update the VSI after updating the VSI queue-mapping information */
4854 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); 4868 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4855 if (ret) { 4869 if (ret) {
@@ -4993,6 +5007,7 @@ static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4993 if (pf->vsi[v]->netdev) 5007 if (pf->vsi[v]->netdev)
4994 i40e_dcbnl_set_all(pf->vsi[v]); 5008 i40e_dcbnl_set_all(pf->vsi[v]);
4995 } 5009 }
5010 i40e_notify_client_of_l2_param_changes(pf->vsi[v]);
4996 } 5011 }
4997} 5012}
4998 5013
@@ -5191,6 +5206,11 @@ static int i40e_up_complete(struct i40e_vsi *vsi)
5191 } 5206 }
5192 i40e_fdir_filter_restore(vsi); 5207 i40e_fdir_filter_restore(vsi);
5193 } 5208 }
5209
5210 /* On the next run of the service_task, notify any clients of the new
5211 * opened netdev
5212 */
5213 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
5194 i40e_service_event_schedule(pf); 5214 i40e_service_event_schedule(pf);
5195 5215
5196 return 0; 5216 return 0;
@@ -5379,6 +5399,8 @@ int i40e_open(struct net_device *netdev)
5379 geneve_get_rx_port(netdev); 5399 geneve_get_rx_port(netdev);
5380#endif 5400#endif
5381 5401
5402 i40e_notify_client_of_netdev_open(vsi);
5403
5382 return 0; 5404 return 0;
5383} 5405}
5384 5406
@@ -6043,6 +6065,7 @@ static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
6043 case I40E_VSI_SRIOV: 6065 case I40E_VSI_SRIOV:
6044 case I40E_VSI_VMDQ2: 6066 case I40E_VSI_VMDQ2:
6045 case I40E_VSI_CTRL: 6067 case I40E_VSI_CTRL:
6068 case I40E_VSI_IWARP:
6046 case I40E_VSI_MIRROR: 6069 case I40E_VSI_MIRROR:
6047 default: 6070 default:
6048 /* there is no notification for other VSIs */ 6071 /* there is no notification for other VSIs */
@@ -7148,6 +7171,7 @@ static void i40e_service_task(struct work_struct *work)
7148 i40e_vc_process_vflr_event(pf); 7171 i40e_vc_process_vflr_event(pf);
7149 i40e_watchdog_subtask(pf); 7172 i40e_watchdog_subtask(pf);
7150 i40e_fdir_reinit_subtask(pf); 7173 i40e_fdir_reinit_subtask(pf);
7174 i40e_client_subtask(pf);
7151 i40e_sync_filters_subtask(pf); 7175 i40e_sync_filters_subtask(pf);
7152 i40e_sync_udp_filters_subtask(pf); 7176 i40e_sync_udp_filters_subtask(pf);
7153 i40e_clean_adminq_subtask(pf); 7177 i40e_clean_adminq_subtask(pf);
@@ -7550,6 +7574,7 @@ static int i40e_init_msix(struct i40e_pf *pf)
7550 int vectors_left; 7574 int vectors_left;
7551 int v_budget, i; 7575 int v_budget, i;
7552 int v_actual; 7576 int v_actual;
7577 int iwarp_requested = 0;
7553 7578
7554 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) 7579 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7555 return -ENODEV; 7580 return -ENODEV;
@@ -7563,6 +7588,7 @@ static int i40e_init_msix(struct i40e_pf *pf)
7563 * is governed by number of cpus in the system. 7588 * is governed by number of cpus in the system.
7564 * - assumes symmetric Tx/Rx pairing 7589 * - assumes symmetric Tx/Rx pairing
7565 * - The number of VMDq pairs 7590 * - The number of VMDq pairs
7591 * - The CPU count within the NUMA node if iWARP is enabled
7566#ifdef I40E_FCOE 7592#ifdef I40E_FCOE
7567 * - The number of FCOE qps. 7593 * - The number of FCOE qps.
7568#endif 7594#endif
@@ -7609,6 +7635,16 @@ static int i40e_init_msix(struct i40e_pf *pf)
7609 } 7635 }
7610 7636
7611#endif 7637#endif
7638 /* can we reserve enough for iWARP? */
7639 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7640 if (!vectors_left)
7641 pf->num_iwarp_msix = 0;
7642 else if (vectors_left < pf->num_iwarp_msix)
7643 pf->num_iwarp_msix = 1;
7644 v_budget += pf->num_iwarp_msix;
7645 vectors_left -= pf->num_iwarp_msix;
7646 }
7647
7612 /* any vectors left over go for VMDq support */ 7648 /* any vectors left over go for VMDq support */
7613 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { 7649 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
7614 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; 7650 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
@@ -7643,6 +7679,8 @@ static int i40e_init_msix(struct i40e_pf *pf)
7643 * of these features based on the policy and at the end disable 7679 * of these features based on the policy and at the end disable
7644 * the features that did not get any vectors. 7680 * the features that did not get any vectors.
7645 */ 7681 */
7682 iwarp_requested = pf->num_iwarp_msix;
7683 pf->num_iwarp_msix = 0;
7646#ifdef I40E_FCOE 7684#ifdef I40E_FCOE
7647 pf->num_fcoe_qps = 0; 7685 pf->num_fcoe_qps = 0;
7648 pf->num_fcoe_msix = 0; 7686 pf->num_fcoe_msix = 0;
@@ -7681,17 +7719,33 @@ static int i40e_init_msix(struct i40e_pf *pf)
7681 pf->num_lan_msix = 1; 7719 pf->num_lan_msix = 1;
7682 break; 7720 break;
7683 case 3: 7721 case 3:
7722 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7723 pf->num_lan_msix = 1;
7724 pf->num_iwarp_msix = 1;
7725 } else {
7726 pf->num_lan_msix = 2;
7727 }
7684#ifdef I40E_FCOE 7728#ifdef I40E_FCOE
7685 /* give one vector to FCoE */ 7729 /* give one vector to FCoE */
7686 if (pf->flags & I40E_FLAG_FCOE_ENABLED) { 7730 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7687 pf->num_lan_msix = 1; 7731 pf->num_lan_msix = 1;
7688 pf->num_fcoe_msix = 1; 7732 pf->num_fcoe_msix = 1;
7689 } 7733 }
7690#else
7691 pf->num_lan_msix = 2;
7692#endif 7734#endif
7693 break; 7735 break;
7694 default: 7736 default:
7737 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7738 pf->num_iwarp_msix = min_t(int, (vec / 3),
7739 iwarp_requested);
7740 pf->num_vmdq_vsis = min_t(int, (vec / 3),
7741 I40E_DEFAULT_NUM_VMDQ_VSI);
7742 } else {
7743 pf->num_vmdq_vsis = min_t(int, (vec / 2),
7744 I40E_DEFAULT_NUM_VMDQ_VSI);
7745 }
7746 pf->num_lan_msix = min_t(int,
7747 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
7748 pf->num_lan_msix);
7695#ifdef I40E_FCOE 7749#ifdef I40E_FCOE
7696 /* give one vector to FCoE */ 7750 /* give one vector to FCoE */
7697 if (pf->flags & I40E_FLAG_FCOE_ENABLED) { 7751 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
@@ -7699,8 +7753,6 @@ static int i40e_init_msix(struct i40e_pf *pf)
7699 vec--; 7753 vec--;
7700 } 7754 }
7701#endif 7755#endif
7702 /* give the rest to the PF */
7703 pf->num_lan_msix = min_t(int, vec, pf->num_lan_qps);
7704 break; 7756 break;
7705 } 7757 }
7706 } 7758 }
@@ -7710,6 +7762,12 @@ static int i40e_init_msix(struct i40e_pf *pf)
7710 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); 7762 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
7711 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; 7763 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
7712 } 7764 }
7765
7766 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
7767 (pf->num_iwarp_msix == 0)) {
7768 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
7769 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
7770 }
7713#ifdef I40E_FCOE 7771#ifdef I40E_FCOE
7714 7772
7715 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { 7773 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
@@ -7801,6 +7859,7 @@ static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
7801 vectors = i40e_init_msix(pf); 7859 vectors = i40e_init_msix(pf);
7802 if (vectors < 0) { 7860 if (vectors < 0) {
7803 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | 7861 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
7862 I40E_FLAG_IWARP_ENABLED |
7804#ifdef I40E_FCOE 7863#ifdef I40E_FCOE
7805 I40E_FLAG_FCOE_ENABLED | 7864 I40E_FLAG_FCOE_ENABLED |
7806#endif 7865#endif
@@ -8474,6 +8533,12 @@ static int i40e_sw_init(struct i40e_pf *pf)
8474 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); 8533 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
8475 } 8534 }
8476 8535
8536 if (pf->hw.func_caps.iwarp) {
8537 pf->flags |= I40E_FLAG_IWARP_ENABLED;
8538 /* IWARP needs one extra vector for CQP just like MISC.*/
8539 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
8540 }
8541
8477#ifdef I40E_FCOE 8542#ifdef I40E_FCOE
8478 i40e_init_pf_fcoe(pf); 8543 i40e_init_pf_fcoe(pf);
8479 8544
@@ -9328,6 +9393,13 @@ static int i40e_add_vsi(struct i40e_vsi *vsi)
9328 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); 9393 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9329 } 9394 }
9330 9395
9396 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
9397 ctxt.info.valid_sections |=
9398 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
9399 ctxt.info.queueing_opt_flags |=
9400 I40E_AQ_VSI_QUE_OPT_TCP_ENA;
9401 }
9402
9331 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); 9403 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9332 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; 9404 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
9333 if (pf->vf[vsi->vf_id].spoofchk) { 9405 if (pf->vf[vsi->vf_id].spoofchk) {
@@ -9351,6 +9423,10 @@ static int i40e_add_vsi(struct i40e_vsi *vsi)
9351 break; 9423 break;
9352 9424
9353#endif /* I40E_FCOE */ 9425#endif /* I40E_FCOE */
9426 case I40E_VSI_IWARP:
9427 /* send down message to iWARP */
9428 break;
9429
9354 default: 9430 default:
9355 return -ENODEV; 9431 return -ENODEV;
9356 } 9432 }
@@ -10467,6 +10543,7 @@ static void i40e_determine_queue_usage(struct i40e_pf *pf)
10467 10543
10468 /* make sure all the fancies are disabled */ 10544 /* make sure all the fancies are disabled */
10469 pf->flags &= ~(I40E_FLAG_RSS_ENABLED | 10545 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
10546 I40E_FLAG_IWARP_ENABLED |
10470#ifdef I40E_FCOE 10547#ifdef I40E_FCOE
10471 I40E_FLAG_FCOE_ENABLED | 10548 I40E_FLAG_FCOE_ENABLED |
10472#endif 10549#endif
@@ -10484,6 +10561,7 @@ static void i40e_determine_queue_usage(struct i40e_pf *pf)
10484 queues_left -= pf->num_lan_qps; 10561 queues_left -= pf->num_lan_qps;
10485 10562
10486 pf->flags &= ~(I40E_FLAG_RSS_ENABLED | 10563 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
10564 I40E_FLAG_IWARP_ENABLED |
10487#ifdef I40E_FCOE 10565#ifdef I40E_FCOE
10488 I40E_FLAG_FCOE_ENABLED | 10566 I40E_FLAG_FCOE_ENABLED |
10489#endif 10567#endif
@@ -11059,7 +11137,17 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11059 } 11137 }
11060#endif /* CONFIG_PCI_IOV */ 11138#endif /* CONFIG_PCI_IOV */
11061 11139
11062 pfs_found++; 11140 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11141 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
11142 pf->num_iwarp_msix,
11143 I40E_IWARP_IRQ_PILE_ID);
11144 if (pf->iwarp_base_vector < 0) {
11145 dev_info(&pdev->dev,
11146 "failed to get tracking for %d vectors for IWARP err=%d\n",
11147 pf->num_iwarp_msix, pf->iwarp_base_vector);
11148 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11149 }
11150 }
11063 11151
11064 i40e_dbg_pf_init(pf); 11152 i40e_dbg_pf_init(pf);
11065 11153
@@ -11070,6 +11158,12 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11070 mod_timer(&pf->service_timer, 11158 mod_timer(&pf->service_timer,
11071 round_jiffies(jiffies + pf->service_timer_period)); 11159 round_jiffies(jiffies + pf->service_timer_period));
11072 11160
11161 /* add this PF to client device list and launch a client service task */
11162 err = i40e_lan_add_device(pf);
11163 if (err)
11164 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
11165 err);
11166
11073#ifdef I40E_FCOE 11167#ifdef I40E_FCOE
11074 /* create FCoE interface */ 11168 /* create FCoE interface */
11075 i40e_fcoe_vsi_setup(pf); 11169 i40e_fcoe_vsi_setup(pf);
@@ -11245,6 +11339,13 @@ static void i40e_remove(struct pci_dev *pdev)
11245 if (pf->vsi[pf->lan_vsi]) 11339 if (pf->vsi[pf->lan_vsi])
11246 i40e_vsi_release(pf->vsi[pf->lan_vsi]); 11340 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11247 11341
11342 /* remove attached clients */
11343 ret_code = i40e_lan_del_device(pf);
11344 if (ret_code) {
11345 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
11346 ret_code);
11347 }
11348
11248 /* shutdown and destroy the HMC */ 11349 /* shutdown and destroy the HMC */
11249 if (hw->hmc.hmc_obj) { 11350 if (hw->hmc.hmc_obj) {
11250 ret_code = i40e_shutdown_lan_hmc(hw); 11351 ret_code = i40e_shutdown_lan_hmc(hw);
diff --git a/drivers/net/ethernet/intel/i40e/i40e_type.h b/drivers/net/ethernet/intel/i40e/i40e_type.h
index 0a0baf71041b..3335f9d13374 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_type.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_type.h
@@ -78,7 +78,7 @@ enum i40e_debug_mask {
78 I40E_DEBUG_DCB = 0x00000400, 78 I40E_DEBUG_DCB = 0x00000400,
79 I40E_DEBUG_DIAG = 0x00000800, 79 I40E_DEBUG_DIAG = 0x00000800,
80 I40E_DEBUG_FD = 0x00001000, 80 I40E_DEBUG_FD = 0x00001000,
81 81 I40E_DEBUG_IWARP = 0x00F00000,
82 I40E_DEBUG_AQ_MESSAGE = 0x01000000, 82 I40E_DEBUG_AQ_MESSAGE = 0x01000000,
83 I40E_DEBUG_AQ_DESCRIPTOR = 0x02000000, 83 I40E_DEBUG_AQ_DESCRIPTOR = 0x02000000,
84 I40E_DEBUG_AQ_DESC_BUFFER = 0x04000000, 84 I40E_DEBUG_AQ_DESC_BUFFER = 0x04000000,
@@ -160,6 +160,7 @@ enum i40e_vsi_type {
160 I40E_VSI_MIRROR = 5, 160 I40E_VSI_MIRROR = 5,
161 I40E_VSI_SRIOV = 6, 161 I40E_VSI_SRIOV = 6,
162 I40E_VSI_FDIR = 7, 162 I40E_VSI_FDIR = 7,
163 I40E_VSI_IWARP = 8,
163 I40E_VSI_TYPE_UNKNOWN 164 I40E_VSI_TYPE_UNKNOWN
164}; 165};
165 166
diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl.h b/drivers/net/ethernet/intel/i40e/i40e_virtchnl.h
index 3226946bf3d4..ab866cf3dc18 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl.h
@@ -81,6 +81,9 @@ enum i40e_virtchnl_ops {
81 I40E_VIRTCHNL_OP_GET_STATS = 15, 81 I40E_VIRTCHNL_OP_GET_STATS = 15,
82 I40E_VIRTCHNL_OP_FCOE = 16, 82 I40E_VIRTCHNL_OP_FCOE = 16,
83 I40E_VIRTCHNL_OP_EVENT = 17, 83 I40E_VIRTCHNL_OP_EVENT = 17,
84 I40E_VIRTCHNL_OP_IWARP = 20,
85 I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21,
86 I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22,
84}; 87};
85 88
86/* Virtual channel message descriptor. This overlays the admin queue 89/* Virtual channel message descriptor. This overlays the admin queue
@@ -348,6 +351,37 @@ struct i40e_virtchnl_pf_event {
348 int severity; 351 int severity;
349}; 352};
350 353
354/* I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
355 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
356 * The request for this originates from the VF IWARP driver through
357 * a client interface between VF LAN and VF IWARP driver.
358 * A vector could have an AEQ and CEQ attached to it although
359 * there is a single AEQ per VF IWARP instance in which case
360 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
361 * There will never be a case where there will be multiple CEQs attached
362 * to a single vector.
363 * PF configures interrupt mapping and returns status.
364 */
365
366/* HW does not define a type value for AEQ; only for RX/TX and CEQ.
367 * In order for us to keep the interface simple, SW will define a
368 * unique type value for AEQ.
369*/
370#define I40E_QUEUE_TYPE_PE_AEQ 0x80
371#define I40E_QUEUE_INVALID_IDX 0xFFFF
372
373struct i40e_virtchnl_iwarp_qv_info {
374 u32 v_idx; /* msix_vector */
375 u16 ceq_idx;
376 u16 aeq_idx;
377 u8 itr_idx;
378};
379
380struct i40e_virtchnl_iwarp_qvlist_info {
381 u32 num_vectors;
382 struct i40e_virtchnl_iwarp_qv_info qv_info[1];
383};
384
351/* VF reset states - these are written into the RSTAT register: 385/* VF reset states - these are written into the RSTAT register:
352 * I40E_VFGEN_RSTAT1 on the PF 386 * I40E_VFGEN_RSTAT1 on the PF
353 * I40E_VFGEN_RSTAT on the VF 387 * I40E_VFGEN_RSTAT on the VF
diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
index acd2693a4e97..816c6bbf7093 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
@@ -352,6 +352,136 @@ irq_list_done:
352} 352}
353 353
354/** 354/**
355 * i40e_release_iwarp_qvlist
356 * @vf: pointer to the VF.
357 *
358 **/
359static void i40e_release_iwarp_qvlist(struct i40e_vf *vf)
360{
361 struct i40e_pf *pf = vf->pf;
362 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info = vf->qvlist_info;
363 u32 msix_vf;
364 u32 i;
365
366 if (!vf->qvlist_info)
367 return;
368
369 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
370 for (i = 0; i < qvlist_info->num_vectors; i++) {
371 struct i40e_virtchnl_iwarp_qv_info *qv_info;
372 u32 next_q_index, next_q_type;
373 struct i40e_hw *hw = &pf->hw;
374 u32 v_idx, reg_idx, reg;
375
376 qv_info = &qvlist_info->qv_info[i];
377 if (!qv_info)
378 continue;
379 v_idx = qv_info->v_idx;
380 if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
381 /* Figure out the queue after CEQ and make that the
382 * first queue.
383 */
384 reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
385 reg = rd32(hw, I40E_VPINT_CEQCTL(reg_idx));
386 next_q_index = (reg & I40E_VPINT_CEQCTL_NEXTQ_INDX_MASK)
387 >> I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT;
388 next_q_type = (reg & I40E_VPINT_CEQCTL_NEXTQ_TYPE_MASK)
389 >> I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT;
390
391 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
392 reg = (next_q_index &
393 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
394 (next_q_type <<
395 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
396
397 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
398 }
399 }
400 kfree(vf->qvlist_info);
401 vf->qvlist_info = NULL;
402}
403
404/**
405 * i40e_config_iwarp_qvlist
406 * @vf: pointer to the VF info
407 * @qvlist_info: queue and vector list
408 *
409 * Return 0 on success or < 0 on error
410 **/
411static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,
412 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info)
413{
414 struct i40e_pf *pf = vf->pf;
415 struct i40e_hw *hw = &pf->hw;
416 struct i40e_virtchnl_iwarp_qv_info *qv_info;
417 u32 v_idx, i, reg_idx, reg;
418 u32 next_q_idx, next_q_type;
419 u32 msix_vf, size;
420
421 size = sizeof(struct i40e_virtchnl_iwarp_qvlist_info) +
422 (sizeof(struct i40e_virtchnl_iwarp_qv_info) *
423 (qvlist_info->num_vectors - 1));
424 vf->qvlist_info = kzalloc(size, GFP_KERNEL);
425 vf->qvlist_info->num_vectors = qvlist_info->num_vectors;
426
427 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
428 for (i = 0; i < qvlist_info->num_vectors; i++) {
429 qv_info = &qvlist_info->qv_info[i];
430 if (!qv_info)
431 continue;
432 v_idx = qv_info->v_idx;
433
434 /* Validate vector id belongs to this vf */
435 if (!i40e_vc_isvalid_vector_id(vf, v_idx))
436 goto err;
437
438 vf->qvlist_info->qv_info[i] = *qv_info;
439
440 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
441 /* We might be sharing the interrupt, so get the first queue
442 * index and type, push it down the list by adding the new
443 * queue on top. Also link it with the new queue in CEQCTL.
444 */
445 reg = rd32(hw, I40E_VPINT_LNKLSTN(reg_idx));
446 next_q_idx = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) >>
447 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT);
448 next_q_type = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK) >>
449 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
450
451 if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
452 reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
453 reg = (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK |
454 (v_idx << I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT) |
455 (qv_info->itr_idx << I40E_VPINT_CEQCTL_ITR_INDX_SHIFT) |
456 (next_q_type << I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT) |
457 (next_q_idx << I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT));
458 wr32(hw, I40E_VPINT_CEQCTL(reg_idx), reg);
459
460 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
461 reg = (qv_info->ceq_idx &
462 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
463 (I40E_QUEUE_TYPE_PE_CEQ <<
464 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
465 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
466 }
467
468 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
469 reg = (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK |
470 (v_idx << I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT) |
471 (qv_info->itr_idx << I40E_VPINT_AEQCTL_ITR_INDX_SHIFT));
472
473 wr32(hw, I40E_VPINT_AEQCTL(vf->vf_id), reg);
474 }
475 }
476
477 return 0;
478err:
479 kfree(vf->qvlist_info);
480 vf->qvlist_info = NULL;
481 return -EINVAL;
482}
483
484/**
355 * i40e_config_vsi_tx_queue 485 * i40e_config_vsi_tx_queue
356 * @vf: pointer to the VF info 486 * @vf: pointer to the VF info
357 * @vsi_id: id of VSI as provided by the FW 487 * @vsi_id: id of VSI as provided by the FW
@@ -850,9 +980,11 @@ complete_reset:
850 /* reallocate VF resources to reset the VSI state */ 980 /* reallocate VF resources to reset the VSI state */
851 i40e_free_vf_res(vf); 981 i40e_free_vf_res(vf);
852 if (!i40e_alloc_vf_res(vf)) { 982 if (!i40e_alloc_vf_res(vf)) {
983 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
853 i40e_enable_vf_mappings(vf); 984 i40e_enable_vf_mappings(vf);
854 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); 985 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
855 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); 986 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
987 i40e_notify_client_of_vf_reset(pf, abs_vf_id);
856 } 988 }
857 /* tell the VF the reset is done */ 989 /* tell the VF the reset is done */
858 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE); 990 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
@@ -877,11 +1009,7 @@ void i40e_free_vfs(struct i40e_pf *pf)
877 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state)) 1009 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
878 usleep_range(1000, 2000); 1010 usleep_range(1000, 2000);
879 1011
880 for (i = 0; i < pf->num_alloc_vfs; i++) 1012 i40e_notify_client_of_vf_enable(pf, 0);
881 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
882 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
883 false);
884
885 for (i = 0; i < pf->num_alloc_vfs; i++) 1013 for (i = 0; i < pf->num_alloc_vfs; i++)
886 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) 1014 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
887 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx], 1015 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
@@ -953,6 +1081,7 @@ int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
953 goto err_iov; 1081 goto err_iov;
954 } 1082 }
955 } 1083 }
1084 i40e_notify_client_of_vf_enable(pf, num_alloc_vfs);
956 /* allocate memory */ 1085 /* allocate memory */
957 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL); 1086 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
958 if (!vfs) { 1087 if (!vfs) {
@@ -1206,6 +1335,13 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
1206 vsi = pf->vsi[vf->lan_vsi_idx]; 1335 vsi = pf->vsi[vf->lan_vsi_idx];
1207 if (!vsi->info.pvid) 1336 if (!vsi->info.pvid)
1208 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN; 1337 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1338
1339 if (i40e_vf_client_capable(pf, vf->vf_id, I40E_CLIENT_IWARP) &&
1340 (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_IWARP)) {
1341 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_IWARP;
1342 set_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states);
1343 }
1344
1209 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) { 1345 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
1210 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ) 1346 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
1211 vfres->vf_offload_flags |= 1347 vfres->vf_offload_flags |=
@@ -1827,6 +1963,72 @@ error_param:
1827} 1963}
1828 1964
1829/** 1965/**
1966 * i40e_vc_iwarp_msg
1967 * @vf: pointer to the VF info
1968 * @msg: pointer to the msg buffer
1969 * @msglen: msg length
1970 *
1971 * called from the VF for the iwarp msgs
1972 **/
1973static int i40e_vc_iwarp_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1974{
1975 struct i40e_pf *pf = vf->pf;
1976 int abs_vf_id = vf->vf_id + pf->hw.func_caps.vf_base_id;
1977 i40e_status aq_ret = 0;
1978
1979 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1980 !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
1981 aq_ret = I40E_ERR_PARAM;
1982 goto error_param;
1983 }
1984
1985 i40e_notify_client_of_vf_msg(pf->vsi[pf->lan_vsi], abs_vf_id,
1986 msg, msglen);
1987
1988error_param:
1989 /* send the response to the VF */
1990 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_IWARP,
1991 aq_ret);
1992}
1993
1994/**
1995 * i40e_vc_iwarp_qvmap_msg
1996 * @vf: pointer to the VF info
1997 * @msg: pointer to the msg buffer
1998 * @msglen: msg length
1999 * @config: config qvmap or release it
2000 *
2001 * called from the VF for the iwarp msgs
2002 **/
2003static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
2004 bool config)
2005{
2006 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info =
2007 (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
2008 i40e_status aq_ret = 0;
2009
2010 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2011 !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
2012 aq_ret = I40E_ERR_PARAM;
2013 goto error_param;
2014 }
2015
2016 if (config) {
2017 if (i40e_config_iwarp_qvlist(vf, qvlist_info))
2018 aq_ret = I40E_ERR_PARAM;
2019 } else {
2020 i40e_release_iwarp_qvlist(vf);
2021 }
2022
2023error_param:
2024 /* send the response to the VF */
2025 return i40e_vc_send_resp_to_vf(vf,
2026 config ? I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP :
2027 I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP,
2028 aq_ret);
2029}
2030
2031/**
1830 * i40e_vc_validate_vf_msg 2032 * i40e_vc_validate_vf_msg
1831 * @vf: pointer to the VF info 2033 * @vf: pointer to the VF info
1832 * @msg: pointer to the msg buffer 2034 * @msg: pointer to the msg buffer
@@ -1921,6 +2123,32 @@ static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1921 case I40E_VIRTCHNL_OP_GET_STATS: 2123 case I40E_VIRTCHNL_OP_GET_STATS:
1922 valid_len = sizeof(struct i40e_virtchnl_queue_select); 2124 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1923 break; 2125 break;
2126 case I40E_VIRTCHNL_OP_IWARP:
2127 /* These messages are opaque to us and will be validated in
2128 * the RDMA client code. We just need to check for nonzero
2129 * length. The firmware will enforce max length restrictions.
2130 */
2131 if (msglen)
2132 valid_len = msglen;
2133 else
2134 err_msg_format = true;
2135 break;
2136 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
2137 valid_len = 0;
2138 break;
2139 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2140 valid_len = sizeof(struct i40e_virtchnl_iwarp_qvlist_info);
2141 if (msglen >= valid_len) {
2142 struct i40e_virtchnl_iwarp_qvlist_info *qv =
2143 (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
2144 if (qv->num_vectors == 0) {
2145 err_msg_format = true;
2146 break;
2147 }
2148 valid_len += ((qv->num_vectors - 1) *
2149 sizeof(struct i40e_virtchnl_iwarp_qv_info));
2150 }
2151 break;
1924 /* These are always errors coming from the VF. */ 2152 /* These are always errors coming from the VF. */
1925 case I40E_VIRTCHNL_OP_EVENT: 2153 case I40E_VIRTCHNL_OP_EVENT:
1926 case I40E_VIRTCHNL_OP_UNKNOWN: 2154 case I40E_VIRTCHNL_OP_UNKNOWN:
@@ -2010,6 +2238,15 @@ int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
2010 case I40E_VIRTCHNL_OP_GET_STATS: 2238 case I40E_VIRTCHNL_OP_GET_STATS:
2011 ret = i40e_vc_get_stats_msg(vf, msg, msglen); 2239 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
2012 break; 2240 break;
2241 case I40E_VIRTCHNL_OP_IWARP:
2242 ret = i40e_vc_iwarp_msg(vf, msg, msglen);
2243 break;
2244 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2245 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
2246 break;
2247 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
2248 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
2249 break;
2013 case I40E_VIRTCHNL_OP_UNKNOWN: 2250 case I40E_VIRTCHNL_OP_UNKNOWN:
2014 default: 2251 default:
2015 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n", 2252 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h
index e74642a0c42e..e7b2fba0309e 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h
@@ -58,6 +58,7 @@ enum i40e_queue_ctrl {
58enum i40e_vf_states { 58enum i40e_vf_states {
59 I40E_VF_STAT_INIT = 0, 59 I40E_VF_STAT_INIT = 0,
60 I40E_VF_STAT_ACTIVE, 60 I40E_VF_STAT_ACTIVE,
61 I40E_VF_STAT_IWARPENA,
61 I40E_VF_STAT_FCOEENA, 62 I40E_VF_STAT_FCOEENA,
62 I40E_VF_STAT_DISABLED, 63 I40E_VF_STAT_DISABLED,
63}; 64};
@@ -66,6 +67,7 @@ enum i40e_vf_states {
66enum i40e_vf_capabilities { 67enum i40e_vf_capabilities {
67 I40E_VIRTCHNL_VF_CAP_PRIVILEGE = 0, 68 I40E_VIRTCHNL_VF_CAP_PRIVILEGE = 0,
68 I40E_VIRTCHNL_VF_CAP_L2, 69 I40E_VIRTCHNL_VF_CAP_L2,
70 I40E_VIRTCHNL_VF_CAP_IWARP,
69}; 71};
70 72
71/* VF information structure */ 73/* VF information structure */
@@ -106,6 +108,8 @@ struct i40e_vf {
106 bool link_forced; 108 bool link_forced;
107 bool link_up; /* only valid if VF link is forced */ 109 bool link_up; /* only valid if VF link is forced */
108 bool spoofchk; 110 bool spoofchk;
111 /* RDMA Client */
112 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info;
109}; 113};
110 114
111void i40e_free_vfs(struct i40e_pf *pf); 115void i40e_free_vfs(struct i40e_pf *pf);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 97f5114fc113..eb926e1ee71c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -407,6 +407,12 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
407const char *mlx5_command_str(int command) 407const char *mlx5_command_str(int command)
408{ 408{
409 switch (command) { 409 switch (command) {
410 case MLX5_CMD_OP_QUERY_HCA_VPORT_CONTEXT:
411 return "QUERY_HCA_VPORT_CONTEXT";
412
413 case MLX5_CMD_OP_MODIFY_HCA_VPORT_CONTEXT:
414 return "MODIFY_HCA_VPORT_CONTEXT";
415
410 case MLX5_CMD_OP_QUERY_HCA_CAP: 416 case MLX5_CMD_OP_QUERY_HCA_CAP:
411 return "QUERY_HCA_CAP"; 417 return "QUERY_HCA_CAP";
412 418
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fw.c b/drivers/net/ethernet/mellanox/mlx5/core/fw.c
index aa1ab4702385..75c7ae6a5cc4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fw.c
@@ -98,88 +98,55 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev)
98{ 98{
99 int err; 99 int err;
100 100
101 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_CUR); 101 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL);
102 if (err)
103 return err;
104
105 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_MAX);
106 if (err) 102 if (err)
107 return err; 103 return err;
108 104
109 if (MLX5_CAP_GEN(dev, eth_net_offloads)) { 105 if (MLX5_CAP_GEN(dev, eth_net_offloads)) {
110 err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS, 106 err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS);
111 HCA_CAP_OPMOD_GET_CUR);
112 if (err)
113 return err;
114 err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS,
115 HCA_CAP_OPMOD_GET_MAX);
116 if (err) 107 if (err)
117 return err; 108 return err;
118 } 109 }
119 110
120 if (MLX5_CAP_GEN(dev, pg)) { 111 if (MLX5_CAP_GEN(dev, pg)) {
121 err = mlx5_core_get_caps(dev, MLX5_CAP_ODP, 112 err = mlx5_core_get_caps(dev, MLX5_CAP_ODP);
122 HCA_CAP_OPMOD_GET_CUR);
123 if (err)
124 return err;
125 err = mlx5_core_get_caps(dev, MLX5_CAP_ODP,
126 HCA_CAP_OPMOD_GET_MAX);
127 if (err) 113 if (err)
128 return err; 114 return err;
129 } 115 }
130 116
131 if (MLX5_CAP_GEN(dev, atomic)) { 117 if (MLX5_CAP_GEN(dev, atomic)) {
132 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC, 118 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC);
133 HCA_CAP_OPMOD_GET_CUR);
134 if (err)
135 return err;
136 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC,
137 HCA_CAP_OPMOD_GET_MAX);
138 if (err) 119 if (err)
139 return err; 120 return err;
140 } 121 }
141 122
142 if (MLX5_CAP_GEN(dev, roce)) { 123 if (MLX5_CAP_GEN(dev, roce)) {
143 err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE, 124 err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE);
144 HCA_CAP_OPMOD_GET_CUR);
145 if (err)
146 return err;
147 err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE,
148 HCA_CAP_OPMOD_GET_MAX);
149 if (err) 125 if (err)
150 return err; 126 return err;
151 } 127 }
152 128
153 if (MLX5_CAP_GEN(dev, nic_flow_table)) { 129 if (MLX5_CAP_GEN(dev, nic_flow_table)) {
154 err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE, 130 err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE);
155 HCA_CAP_OPMOD_GET_CUR);
156 if (err)
157 return err;
158 err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE,
159 HCA_CAP_OPMOD_GET_MAX);
160 if (err) 131 if (err)
161 return err; 132 return err;
162 } 133 }
163 134
164 if (MLX5_CAP_GEN(dev, vport_group_manager) && 135 if (MLX5_CAP_GEN(dev, vport_group_manager) &&
165 MLX5_CAP_GEN(dev, eswitch_flow_table)) { 136 MLX5_CAP_GEN(dev, eswitch_flow_table)) {
166 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE, 137 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE);
167 HCA_CAP_OPMOD_GET_CUR);
168 if (err)
169 return err;
170 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE,
171 HCA_CAP_OPMOD_GET_MAX);
172 if (err) 138 if (err)
173 return err; 139 return err;
174 } 140 }
175 141
176 if (MLX5_CAP_GEN(dev, eswitch_flow_table)) { 142 if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
177 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH, 143 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH);
178 HCA_CAP_OPMOD_GET_CUR);
179 if (err) 144 if (err)
180 return err; 145 return err;
181 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH, 146 }
182 HCA_CAP_OPMOD_GET_MAX); 147
148 if (MLX5_CAP_GEN(dev, vector_calc)) {
149 err = mlx5_core_get_caps(dev, MLX5_CAP_VECTOR_CALC);
183 if (err) 150 if (err)
184 return err; 151 return err;
185 } 152 }
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 72a94e72ee25..3f3b2fae4991 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -341,8 +341,9 @@ static u16 to_fw_pkey_sz(u32 size)
341 } 341 }
342} 342}
343 343
344int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type, 344static int mlx5_core_get_caps_mode(struct mlx5_core_dev *dev,
345 enum mlx5_cap_mode cap_mode) 345 enum mlx5_cap_type cap_type,
346 enum mlx5_cap_mode cap_mode)
346{ 347{
347 u8 in[MLX5_ST_SZ_BYTES(query_hca_cap_in)]; 348 u8 in[MLX5_ST_SZ_BYTES(query_hca_cap_in)];
348 int out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out); 349 int out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
@@ -392,6 +393,16 @@ query_ex:
392 return err; 393 return err;
393} 394}
394 395
396int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type)
397{
398 int ret;
399
400 ret = mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_CUR);
401 if (ret)
402 return ret;
403 return mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_MAX);
404}
405
395static int set_caps(struct mlx5_core_dev *dev, void *in, int in_sz, int opmod) 406static int set_caps(struct mlx5_core_dev *dev, void *in, int in_sz, int opmod)
396{ 407{
397 u32 out[MLX5_ST_SZ_DW(set_hca_cap_out)]; 408 u32 out[MLX5_ST_SZ_DW(set_hca_cap_out)];
@@ -419,8 +430,7 @@ static int handle_hca_cap_atomic(struct mlx5_core_dev *dev)
419 int err; 430 int err;
420 431
421 if (MLX5_CAP_GEN(dev, atomic)) { 432 if (MLX5_CAP_GEN(dev, atomic)) {
422 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC, 433 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC);
423 HCA_CAP_OPMOD_GET_CUR);
424 if (err) 434 if (err)
425 return err; 435 return err;
426 } else { 436 } else {
@@ -462,11 +472,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
462 if (!set_ctx) 472 if (!set_ctx)
463 goto query_ex; 473 goto query_ex;
464 474
465 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_MAX); 475 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL);
466 if (err)
467 goto query_ex;
468
469 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_CUR);
470 if (err) 476 if (err)
471 goto query_ex; 477 goto query_ex;
472 478
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/vport.c b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
index 90ab09e375b8..bd518405859e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/vport.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
@@ -852,7 +852,8 @@ int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev)
852EXPORT_SYMBOL_GPL(mlx5_nic_vport_disable_roce); 852EXPORT_SYMBOL_GPL(mlx5_nic_vport_disable_roce);
853 853
854int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport, 854int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
855 u8 port_num, void *out, size_t out_sz) 855 int vf, u8 port_num, void *out,
856 size_t out_sz)
856{ 857{
857 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in); 858 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in);
858 int is_group_manager; 859 int is_group_manager;
@@ -871,7 +872,7 @@ int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
871 if (other_vport) { 872 if (other_vport) {
872 if (is_group_manager) { 873 if (is_group_manager) {
873 MLX5_SET(query_vport_counter_in, in, other_vport, 1); 874 MLX5_SET(query_vport_counter_in, in, other_vport, 1);
874 MLX5_SET(query_vport_counter_in, in, vport_number, 0); 875 MLX5_SET(query_vport_counter_in, in, vport_number, vf + 1);
875 } else { 876 } else {
876 err = -EPERM; 877 err = -EPERM;
877 goto free; 878 goto free;
@@ -890,3 +891,70 @@ free:
890 return err; 891 return err;
891} 892}
892EXPORT_SYMBOL_GPL(mlx5_core_query_vport_counter); 893EXPORT_SYMBOL_GPL(mlx5_core_query_vport_counter);
894
895int mlx5_core_modify_hca_vport_context(struct mlx5_core_dev *dev,
896 u8 other_vport, u8 port_num,
897 int vf,
898 struct mlx5_hca_vport_context *req)
899{
900 int in_sz = MLX5_ST_SZ_BYTES(modify_hca_vport_context_in);
901 u8 out[MLX5_ST_SZ_BYTES(modify_hca_vport_context_out)];
902 int is_group_manager;
903 void *in;
904 int err;
905 void *ctx;
906
907 mlx5_core_dbg(dev, "vf %d\n", vf);
908 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
909 in = kzalloc(in_sz, GFP_KERNEL);
910 if (!in)
911 return -ENOMEM;
912
913 memset(out, 0, sizeof(out));
914 MLX5_SET(modify_hca_vport_context_in, in, opcode, MLX5_CMD_OP_MODIFY_HCA_VPORT_CONTEXT);
915 if (other_vport) {
916 if (is_group_manager) {
917 MLX5_SET(modify_hca_vport_context_in, in, other_vport, 1);
918 MLX5_SET(modify_hca_vport_context_in, in, vport_number, vf);
919 } else {
920 err = -EPERM;
921 goto ex;
922 }
923 }
924
925 if (MLX5_CAP_GEN(dev, num_ports) > 1)
926 MLX5_SET(modify_hca_vport_context_in, in, port_num, port_num);
927
928 ctx = MLX5_ADDR_OF(modify_hca_vport_context_in, in, hca_vport_context);
929 MLX5_SET(hca_vport_context, ctx, field_select, req->field_select);
930 MLX5_SET(hca_vport_context, ctx, sm_virt_aware, req->sm_virt_aware);
931 MLX5_SET(hca_vport_context, ctx, has_smi, req->has_smi);
932 MLX5_SET(hca_vport_context, ctx, has_raw, req->has_raw);
933 MLX5_SET(hca_vport_context, ctx, vport_state_policy, req->policy);
934 MLX5_SET(hca_vport_context, ctx, port_physical_state, req->phys_state);
935 MLX5_SET(hca_vport_context, ctx, vport_state, req->vport_state);
936 MLX5_SET64(hca_vport_context, ctx, port_guid, req->port_guid);
937 MLX5_SET64(hca_vport_context, ctx, node_guid, req->node_guid);
938 MLX5_SET(hca_vport_context, ctx, cap_mask1, req->cap_mask1);
939 MLX5_SET(hca_vport_context, ctx, cap_mask1_field_select, req->cap_mask1_perm);
940 MLX5_SET(hca_vport_context, ctx, cap_mask2, req->cap_mask2);
941 MLX5_SET(hca_vport_context, ctx, cap_mask2_field_select, req->cap_mask2_perm);
942 MLX5_SET(hca_vport_context, ctx, lid, req->lid);
943 MLX5_SET(hca_vport_context, ctx, init_type_reply, req->init_type_reply);
944 MLX5_SET(hca_vport_context, ctx, lmc, req->lmc);
945 MLX5_SET(hca_vport_context, ctx, subnet_timeout, req->subnet_timeout);
946 MLX5_SET(hca_vport_context, ctx, sm_lid, req->sm_lid);
947 MLX5_SET(hca_vport_context, ctx, sm_sl, req->sm_sl);
948 MLX5_SET(hca_vport_context, ctx, qkey_violation_counter, req->qkey_violation_counter);
949 MLX5_SET(hca_vport_context, ctx, pkey_violation_counter, req->pkey_violation_counter);
950 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
951 if (err)
952 goto ex;
953
954 err = mlx5_cmd_status_to_err_v2(out);
955
956ex:
957 kfree(in);
958 return err;
959}
960EXPORT_SYMBOL_GPL(mlx5_core_modify_hca_vport_context);
diff --git a/drivers/staging/rdma/hfi1/Kconfig b/drivers/staging/rdma/hfi1/Kconfig
index fd25078ee923..3e668d852f03 100644
--- a/drivers/staging/rdma/hfi1/Kconfig
+++ b/drivers/staging/rdma/hfi1/Kconfig
@@ -1,6 +1,7 @@
1config INFINIBAND_HFI1 1config INFINIBAND_HFI1
2 tristate "Intel OPA Gen1 support" 2 tristate "Intel OPA Gen1 support"
3 depends on X86_64 3 depends on X86_64 && INFINIBAND_RDMAVT
4 select MMU_NOTIFIER
4 default m 5 default m
5 ---help--- 6 ---help---
6 This is a low-level driver for Intel OPA Gen1 adapter. 7 This is a low-level driver for Intel OPA Gen1 adapter.
@@ -25,13 +26,3 @@ config SDMA_VERBOSITY
25 ---help--- 26 ---help---
26 This is a configuration flag to enable verbose 27 This is a configuration flag to enable verbose
27 SDMA debug 28 SDMA debug
28config PRESCAN_RXQ
29 bool "Enable prescanning of the RX queue for ECNs"
30 depends on INFINIBAND_HFI1
31 default n
32 ---help---
33 This option toggles the prescanning of the receive queue for
34 Explicit Congestion Notifications. If an ECN is detected, it
35 is processed as quickly as possible, the ECN is toggled off.
36 After the prescanning step, the receive queue is processed as
37 usual.
diff --git a/drivers/staging/rdma/hfi1/Makefile b/drivers/staging/rdma/hfi1/Makefile
index 68c5a315e557..8dc59382ee96 100644
--- a/drivers/staging/rdma/hfi1/Makefile
+++ b/drivers/staging/rdma/hfi1/Makefile
@@ -7,10 +7,12 @@
7# 7#
8obj-$(CONFIG_INFINIBAND_HFI1) += hfi1.o 8obj-$(CONFIG_INFINIBAND_HFI1) += hfi1.o
9 9
10hfi1-y := chip.o cq.o device.o diag.o dma.o driver.o efivar.o eprom.o file_ops.o firmware.o \ 10hfi1-y := affinity.o chip.o device.o diag.o driver.o efivar.o \
11 init.o intr.o keys.o mad.o mmap.o mr.o pcie.o pio.o pio_copy.o \ 11 eprom.o file_ops.o firmware.o \
12 qp.o qsfp.o rc.o ruc.o sdma.o srq.o sysfs.o trace.o twsi.o \ 12 init.o intr.o mad.o mmu_rb.o pcie.o pio.o pio_copy.o platform.o \
13 uc.o ud.o user_pages.o user_sdma.o verbs_mcast.o verbs.o 13 qp.o qsfp.o rc.o ruc.o sdma.o sysfs.o trace.o twsi.o \
14 uc.o ud.o user_exp_rcv.o user_pages.o user_sdma.o verbs.o \
15 verbs_txreq.o
14hfi1-$(CONFIG_DEBUG_FS) += debugfs.o 16hfi1-$(CONFIG_DEBUG_FS) += debugfs.o
15 17
16CFLAGS_trace.o = -I$(src) 18CFLAGS_trace.o = -I$(src)
diff --git a/drivers/staging/rdma/hfi1/affinity.c b/drivers/staging/rdma/hfi1/affinity.c
new file mode 100644
index 000000000000..2cb8ca77f876
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/affinity.c
@@ -0,0 +1,430 @@
1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#include <linux/topology.h>
48#include <linux/cpumask.h>
49#include <linux/module.h>
50
51#include "hfi.h"
52#include "affinity.h"
53#include "sdma.h"
54#include "trace.h"
55
56struct cpu_mask_set {
57 struct cpumask mask;
58 struct cpumask used;
59 uint gen;
60};
61
62struct hfi1_affinity {
63 struct cpu_mask_set def_intr;
64 struct cpu_mask_set rcv_intr;
65 struct cpu_mask_set proc;
66 /* spin lock to protect affinity struct */
67 spinlock_t lock;
68};
69
70/* Name of IRQ types, indexed by enum irq_type */
71static const char * const irq_type_names[] = {
72 "SDMA",
73 "RCVCTXT",
74 "GENERAL",
75 "OTHER",
76};
77
78static inline void init_cpu_mask_set(struct cpu_mask_set *set)
79{
80 cpumask_clear(&set->mask);
81 cpumask_clear(&set->used);
82 set->gen = 0;
83}
84
85/*
86 * Interrupt affinity.
87 *
88 * non-rcv avail gets a default mask that
89 * starts as possible cpus with threads reset
90 * and each rcv avail reset.
91 *
92 * rcv avail gets node relative 1 wrapping back
93 * to the node relative 1 as necessary.
94 *
95 */
96int hfi1_dev_affinity_init(struct hfi1_devdata *dd)
97{
98 int node = pcibus_to_node(dd->pcidev->bus);
99 struct hfi1_affinity *info;
100 const struct cpumask *local_mask;
101 int curr_cpu, possible, i, ht;
102
103 if (node < 0)
104 node = numa_node_id();
105 dd->node = node;
106
107 info = kzalloc(sizeof(*info), GFP_KERNEL);
108 if (!info)
109 return -ENOMEM;
110 spin_lock_init(&info->lock);
111
112 init_cpu_mask_set(&info->def_intr);
113 init_cpu_mask_set(&info->rcv_intr);
114 init_cpu_mask_set(&info->proc);
115
116 local_mask = cpumask_of_node(dd->node);
117 if (cpumask_first(local_mask) >= nr_cpu_ids)
118 local_mask = topology_core_cpumask(0);
119 /* use local mask as default */
120 cpumask_copy(&info->def_intr.mask, local_mask);
121 /*
122 * Remove HT cores from the default mask. Do this in two steps below.
123 */
124 possible = cpumask_weight(&info->def_intr.mask);
125 ht = cpumask_weight(topology_sibling_cpumask(
126 cpumask_first(&info->def_intr.mask)));
127 /*
128 * Step 1. Skip over the first N HT siblings and use them as the
129 * "real" cores. Assumes that HT cores are not enumerated in
130 * succession (except in the single core case).
131 */
132 curr_cpu = cpumask_first(&info->def_intr.mask);
133 for (i = 0; i < possible / ht; i++)
134 curr_cpu = cpumask_next(curr_cpu, &info->def_intr.mask);
135 /*
136 * Step 2. Remove the remaining HT siblings. Use cpumask_next() to
137 * skip any gaps.
138 */
139 for (; i < possible; i++) {
140 cpumask_clear_cpu(curr_cpu, &info->def_intr.mask);
141 curr_cpu = cpumask_next(curr_cpu, &info->def_intr.mask);
142 }
143
144 /* fill in the receive list */
145 possible = cpumask_weight(&info->def_intr.mask);
146 curr_cpu = cpumask_first(&info->def_intr.mask);
147 if (possible == 1) {
148 /* only one CPU, everyone will use it */
149 cpumask_set_cpu(curr_cpu, &info->rcv_intr.mask);
150 } else {
151 /*
152 * Retain the first CPU in the default list for the control
153 * context.
154 */
155 curr_cpu = cpumask_next(curr_cpu, &info->def_intr.mask);
156 /*
157 * Remove the remaining kernel receive queues from
158 * the default list and add them to the receive list.
159 */
160 for (i = 0; i < dd->n_krcv_queues - 1; i++) {
161 cpumask_clear_cpu(curr_cpu, &info->def_intr.mask);
162 cpumask_set_cpu(curr_cpu, &info->rcv_intr.mask);
163 curr_cpu = cpumask_next(curr_cpu, &info->def_intr.mask);
164 if (curr_cpu >= nr_cpu_ids)
165 break;
166 }
167 }
168
169 cpumask_copy(&info->proc.mask, cpu_online_mask);
170 dd->affinity = info;
171 return 0;
172}
173
174void hfi1_dev_affinity_free(struct hfi1_devdata *dd)
175{
176 kfree(dd->affinity);
177}
178
179int hfi1_get_irq_affinity(struct hfi1_devdata *dd, struct hfi1_msix_entry *msix)
180{
181 int ret;
182 cpumask_var_t diff;
183 struct cpu_mask_set *set;
184 struct sdma_engine *sde = NULL;
185 struct hfi1_ctxtdata *rcd = NULL;
186 char extra[64];
187 int cpu = -1;
188
189 extra[0] = '\0';
190 cpumask_clear(&msix->mask);
191
192 ret = zalloc_cpumask_var(&diff, GFP_KERNEL);
193 if (!ret)
194 return -ENOMEM;
195
196 switch (msix->type) {
197 case IRQ_SDMA:
198 sde = (struct sdma_engine *)msix->arg;
199 scnprintf(extra, 64, "engine %u", sde->this_idx);
200 /* fall through */
201 case IRQ_GENERAL:
202 set = &dd->affinity->def_intr;
203 break;
204 case IRQ_RCVCTXT:
205 rcd = (struct hfi1_ctxtdata *)msix->arg;
206 if (rcd->ctxt == HFI1_CTRL_CTXT) {
207 set = &dd->affinity->def_intr;
208 cpu = cpumask_first(&set->mask);
209 } else {
210 set = &dd->affinity->rcv_intr;
211 }
212 scnprintf(extra, 64, "ctxt %u", rcd->ctxt);
213 break;
214 default:
215 dd_dev_err(dd, "Invalid IRQ type %d\n", msix->type);
216 return -EINVAL;
217 }
218
219 /*
220 * The control receive context is placed on a particular CPU, which
221 * is set above. Skip accounting for it. Everything else finds its
222 * CPU here.
223 */
224 if (cpu == -1) {
225 spin_lock(&dd->affinity->lock);
226 if (cpumask_equal(&set->mask, &set->used)) {
227 /*
228 * We've used up all the CPUs, bump up the generation
229 * and reset the 'used' map
230 */
231 set->gen++;
232 cpumask_clear(&set->used);
233 }
234 cpumask_andnot(diff, &set->mask, &set->used);
235 cpu = cpumask_first(diff);
236 cpumask_set_cpu(cpu, &set->used);
237 spin_unlock(&dd->affinity->lock);
238 }
239
240 switch (msix->type) {
241 case IRQ_SDMA:
242 sde->cpu = cpu;
243 break;
244 case IRQ_GENERAL:
245 case IRQ_RCVCTXT:
246 case IRQ_OTHER:
247 break;
248 }
249
250 cpumask_set_cpu(cpu, &msix->mask);
251 dd_dev_info(dd, "IRQ vector: %u, type %s %s -> cpu: %d\n",
252 msix->msix.vector, irq_type_names[msix->type],
253 extra, cpu);
254 irq_set_affinity_hint(msix->msix.vector, &msix->mask);
255
256 free_cpumask_var(diff);
257 return 0;
258}
259
260void hfi1_put_irq_affinity(struct hfi1_devdata *dd,
261 struct hfi1_msix_entry *msix)
262{
263 struct cpu_mask_set *set = NULL;
264 struct hfi1_ctxtdata *rcd;
265
266 switch (msix->type) {
267 case IRQ_SDMA:
268 case IRQ_GENERAL:
269 set = &dd->affinity->def_intr;
270 break;
271 case IRQ_RCVCTXT:
272 rcd = (struct hfi1_ctxtdata *)msix->arg;
273 /* only do accounting for non control contexts */
274 if (rcd->ctxt != HFI1_CTRL_CTXT)
275 set = &dd->affinity->rcv_intr;
276 break;
277 default:
278 return;
279 }
280
281 if (set) {
282 spin_lock(&dd->affinity->lock);
283 cpumask_andnot(&set->used, &set->used, &msix->mask);
284 if (cpumask_empty(&set->used) && set->gen) {
285 set->gen--;
286 cpumask_copy(&set->used, &set->mask);
287 }
288 spin_unlock(&dd->affinity->lock);
289 }
290
291 irq_set_affinity_hint(msix->msix.vector, NULL);
292 cpumask_clear(&msix->mask);
293}
294
295int hfi1_get_proc_affinity(struct hfi1_devdata *dd, int node)
296{
297 int cpu = -1, ret;
298 cpumask_var_t diff, mask, intrs;
299 const struct cpumask *node_mask,
300 *proc_mask = tsk_cpus_allowed(current);
301 struct cpu_mask_set *set = &dd->affinity->proc;
302 char buf[1024];
303
304 /*
305 * check whether process/context affinity has already
306 * been set
307 */
308 if (cpumask_weight(proc_mask) == 1) {
309 scnprintf(buf, 1024, "%*pbl", cpumask_pr_args(proc_mask));
310 hfi1_cdbg(PROC, "PID %u %s affinity set to CPU %s",
311 current->pid, current->comm, buf);
312 /*
313 * Mark the pre-set CPU as used. This is atomic so we don't
314 * need the lock
315 */
316 cpu = cpumask_first(proc_mask);
317 cpumask_set_cpu(cpu, &set->used);
318 goto done;
319 } else if (cpumask_weight(proc_mask) < cpumask_weight(&set->mask)) {
320 scnprintf(buf, 1024, "%*pbl", cpumask_pr_args(proc_mask));
321 hfi1_cdbg(PROC, "PID %u %s affinity set to CPU set(s) %s",
322 current->pid, current->comm, buf);
323 goto done;
324 }
325
326 /*
327 * The process does not have a preset CPU affinity so find one to
328 * recommend. We prefer CPUs on the same NUMA as the device.
329 */
330
331 ret = zalloc_cpumask_var(&diff, GFP_KERNEL);
332 if (!ret)
333 goto done;
334 ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
335 if (!ret)
336 goto free_diff;
337 ret = zalloc_cpumask_var(&intrs, GFP_KERNEL);
338 if (!ret)
339 goto free_mask;
340
341 spin_lock(&dd->affinity->lock);
342 /*
343 * If we've used all available CPUs, clear the mask and start
344 * overloading.
345 */
346 if (cpumask_equal(&set->mask, &set->used)) {
347 set->gen++;
348 cpumask_clear(&set->used);
349 }
350
351 /* CPUs used by interrupt handlers */
352 cpumask_copy(intrs, (dd->affinity->def_intr.gen ?
353 &dd->affinity->def_intr.mask :
354 &dd->affinity->def_intr.used));
355 cpumask_or(intrs, intrs, (dd->affinity->rcv_intr.gen ?
356 &dd->affinity->rcv_intr.mask :
357 &dd->affinity->rcv_intr.used));
358 scnprintf(buf, 1024, "%*pbl", cpumask_pr_args(intrs));
359 hfi1_cdbg(PROC, "CPUs used by interrupts: %s", buf);
360
361 /*
362 * If we don't have a NUMA node requested, preference is towards
363 * device NUMA node
364 */
365 if (node == -1)
366 node = dd->node;
367 node_mask = cpumask_of_node(node);
368 scnprintf(buf, 1024, "%*pbl", cpumask_pr_args(node_mask));
369 hfi1_cdbg(PROC, "device on NUMA %u, CPUs %s", node, buf);
370
371 /* diff will hold all unused cpus */
372 cpumask_andnot(diff, &set->mask, &set->used);
373 scnprintf(buf, 1024, "%*pbl", cpumask_pr_args(diff));
374 hfi1_cdbg(PROC, "unused CPUs (all) %s", buf);
375
376 /* get cpumask of available CPUs on preferred NUMA */
377 cpumask_and(mask, diff, node_mask);
378 scnprintf(buf, 1024, "%*pbl", cpumask_pr_args(mask));
379 hfi1_cdbg(PROC, "available cpus on NUMA %s", buf);
380
381 /*
382 * At first, we don't want to place processes on the same
383 * CPUs as interrupt handlers.
384 */
385 cpumask_andnot(diff, mask, intrs);
386 if (!cpumask_empty(diff))
387 cpumask_copy(mask, diff);
388
389 /*
390 * if we don't have a cpu on the preferred NUMA, get
391 * the list of the remaining available CPUs
392 */
393 if (cpumask_empty(mask)) {
394 cpumask_andnot(diff, &set->mask, &set->used);
395 cpumask_andnot(mask, diff, node_mask);
396 }
397 scnprintf(buf, 1024, "%*pbl", cpumask_pr_args(mask));
398 hfi1_cdbg(PROC, "possible CPUs for process %s", buf);
399
400 cpu = cpumask_first(mask);
401 if (cpu >= nr_cpu_ids) /* empty */
402 cpu = -1;
403 else
404 cpumask_set_cpu(cpu, &set->used);
405 spin_unlock(&dd->affinity->lock);
406
407 free_cpumask_var(intrs);
408free_mask:
409 free_cpumask_var(mask);
410free_diff:
411 free_cpumask_var(diff);
412done:
413 return cpu;
414}
415
416void hfi1_put_proc_affinity(struct hfi1_devdata *dd, int cpu)
417{
418 struct cpu_mask_set *set = &dd->affinity->proc;
419
420 if (cpu < 0)
421 return;
422 spin_lock(&dd->affinity->lock);
423 cpumask_clear_cpu(cpu, &set->used);
424 if (cpumask_empty(&set->used) && set->gen) {
425 set->gen--;
426 cpumask_copy(&set->used, &set->mask);
427 }
428 spin_unlock(&dd->affinity->lock);
429}
430
diff --git a/drivers/staging/rdma/hfi1/affinity.h b/drivers/staging/rdma/hfi1/affinity.h
new file mode 100644
index 000000000000..b287e4963024
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/affinity.h
@@ -0,0 +1,91 @@
1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#ifndef _HFI1_AFFINITY_H
48#define _HFI1_AFFINITY_H
49
50#include "hfi.h"
51
52enum irq_type {
53 IRQ_SDMA,
54 IRQ_RCVCTXT,
55 IRQ_GENERAL,
56 IRQ_OTHER
57};
58
59/* Can be used for both memory and cpu */
60enum affinity_flags {
61 AFF_AUTO,
62 AFF_NUMA_LOCAL,
63 AFF_DEV_LOCAL,
64 AFF_IRQ_LOCAL
65};
66
67struct hfi1_msix_entry;
68
69/* Initialize driver affinity data */
70int hfi1_dev_affinity_init(struct hfi1_devdata *);
71/* Free driver affinity data */
72void hfi1_dev_affinity_free(struct hfi1_devdata *);
73/*
74 * Set IRQ affinity to a CPU. The function will determine the
75 * CPU and set the affinity to it.
76 */
77int hfi1_get_irq_affinity(struct hfi1_devdata *, struct hfi1_msix_entry *);
78/*
79 * Remove the IRQ's CPU affinity. This function also updates
80 * any internal CPU tracking data
81 */
82void hfi1_put_irq_affinity(struct hfi1_devdata *, struct hfi1_msix_entry *);
83/*
84 * Determine a CPU affinity for a user process, if the process does not
85 * have an affinity set yet.
86 */
87int hfi1_get_proc_affinity(struct hfi1_devdata *, int);
88/* Release a CPU used by a user process. */
89void hfi1_put_proc_affinity(struct hfi1_devdata *, int);
90
91#endif /* _HFI1_AFFINITY_H */
diff --git a/drivers/staging/rdma/hfi1/aspm.h b/drivers/staging/rdma/hfi1/aspm.h
new file mode 100644
index 000000000000..0d58fe3b49b5
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/aspm.h
@@ -0,0 +1,309 @@
1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#ifndef _ASPM_H
48#define _ASPM_H
49
50#include "hfi.h"
51
52extern uint aspm_mode;
53
54enum aspm_mode {
55 ASPM_MODE_DISABLED = 0, /* ASPM always disabled, performance mode */
56 ASPM_MODE_ENABLED = 1, /* ASPM always enabled, power saving mode */
57 ASPM_MODE_DYNAMIC = 2, /* ASPM enabled/disabled dynamically */
58};
59
60/* Time after which the timer interrupt will re-enable ASPM */
61#define ASPM_TIMER_MS 1000
62/* Time for which interrupts are ignored after a timer has been scheduled */
63#define ASPM_RESCHED_TIMER_MS (ASPM_TIMER_MS / 2)
64/* Two interrupts within this time trigger ASPM disable */
65#define ASPM_TRIGGER_MS 1
66#define ASPM_TRIGGER_NS (ASPM_TRIGGER_MS * 1000 * 1000ull)
67#define ASPM_L1_SUPPORTED(reg) \
68 (((reg & PCI_EXP_LNKCAP_ASPMS) >> 10) & 0x2)
69
70static inline bool aspm_hw_l1_supported(struct hfi1_devdata *dd)
71{
72 struct pci_dev *parent = dd->pcidev->bus->self;
73 u32 up, dn;
74
75 /*
76 * If the driver does not have access to the upstream component,
77 * it cannot support ASPM L1 at all.
78 */
79 if (!parent)
80 return false;
81
82 pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &dn);
83 dn = ASPM_L1_SUPPORTED(dn);
84
85 pcie_capability_read_dword(parent, PCI_EXP_LNKCAP, &up);
86 up = ASPM_L1_SUPPORTED(up);
87
88 /* ASPM works on A-step but is reported as not supported */
89 return (!!dn || is_ax(dd)) && !!up;
90}
91
92/* Set L1 entrance latency for slower entry to L1 */
93static inline void aspm_hw_set_l1_ent_latency(struct hfi1_devdata *dd)
94{
95 u32 l1_ent_lat = 0x4u;
96 u32 reg32;
97
98 pci_read_config_dword(dd->pcidev, PCIE_CFG_REG_PL3, &reg32);
99 reg32 &= ~PCIE_CFG_REG_PL3_L1_ENT_LATENCY_SMASK;
100 reg32 |= l1_ent_lat << PCIE_CFG_REG_PL3_L1_ENT_LATENCY_SHIFT;
101 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL3, reg32);
102}
103
104static inline void aspm_hw_enable_l1(struct hfi1_devdata *dd)
105{
106 struct pci_dev *parent = dd->pcidev->bus->self;
107
108 /*
109 * If the driver does not have access to the upstream component,
110 * it cannot support ASPM L1 at all.
111 */
112 if (!parent)
113 return;
114
115 /* Enable ASPM L1 first in upstream component and then downstream */
116 pcie_capability_clear_and_set_word(parent, PCI_EXP_LNKCTL,
117 PCI_EXP_LNKCTL_ASPMC,
118 PCI_EXP_LNKCTL_ASPM_L1);
119 pcie_capability_clear_and_set_word(dd->pcidev, PCI_EXP_LNKCTL,
120 PCI_EXP_LNKCTL_ASPMC,
121 PCI_EXP_LNKCTL_ASPM_L1);
122}
123
124static inline void aspm_hw_disable_l1(struct hfi1_devdata *dd)
125{
126 struct pci_dev *parent = dd->pcidev->bus->self;
127
128 /* Disable ASPM L1 first in downstream component and then upstream */
129 pcie_capability_clear_and_set_word(dd->pcidev, PCI_EXP_LNKCTL,
130 PCI_EXP_LNKCTL_ASPMC, 0x0);
131 if (parent)
132 pcie_capability_clear_and_set_word(parent, PCI_EXP_LNKCTL,
133 PCI_EXP_LNKCTL_ASPMC, 0x0);
134}
135
136static inline void aspm_enable(struct hfi1_devdata *dd)
137{
138 if (dd->aspm_enabled || aspm_mode == ASPM_MODE_DISABLED ||
139 !dd->aspm_supported)
140 return;
141
142 aspm_hw_enable_l1(dd);
143 dd->aspm_enabled = true;
144}
145
146static inline void aspm_disable(struct hfi1_devdata *dd)
147{
148 if (!dd->aspm_enabled || aspm_mode == ASPM_MODE_ENABLED)
149 return;
150
151 aspm_hw_disable_l1(dd);
152 dd->aspm_enabled = false;
153}
154
155static inline void aspm_disable_inc(struct hfi1_devdata *dd)
156{
157 unsigned long flags;
158
159 spin_lock_irqsave(&dd->aspm_lock, flags);
160 aspm_disable(dd);
161 atomic_inc(&dd->aspm_disabled_cnt);
162 spin_unlock_irqrestore(&dd->aspm_lock, flags);
163}
164
165static inline void aspm_enable_dec(struct hfi1_devdata *dd)
166{
167 unsigned long flags;
168
169 spin_lock_irqsave(&dd->aspm_lock, flags);
170 if (atomic_dec_and_test(&dd->aspm_disabled_cnt))
171 aspm_enable(dd);
172 spin_unlock_irqrestore(&dd->aspm_lock, flags);
173}
174
175/* ASPM processing for each receive context interrupt */
176static inline void aspm_ctx_disable(struct hfi1_ctxtdata *rcd)
177{
178 bool restart_timer;
179 bool close_interrupts;
180 unsigned long flags;
181 ktime_t now, prev;
182
183 /* Quickest exit for minimum impact */
184 if (!rcd->aspm_intr_supported)
185 return;
186
187 spin_lock_irqsave(&rcd->aspm_lock, flags);
188 /* PSM contexts are open */
189 if (!rcd->aspm_intr_enable)
190 goto unlock;
191
192 prev = rcd->aspm_ts_last_intr;
193 now = ktime_get();
194 rcd->aspm_ts_last_intr = now;
195
196 /* An interrupt pair close together in time */
197 close_interrupts = ktime_to_ns(ktime_sub(now, prev)) < ASPM_TRIGGER_NS;
198
199 /* Don't push out our timer till this much time has elapsed */
200 restart_timer = ktime_to_ns(ktime_sub(now, rcd->aspm_ts_timer_sched)) >
201 ASPM_RESCHED_TIMER_MS * NSEC_PER_MSEC;
202 restart_timer = restart_timer && close_interrupts;
203
204 /* Disable ASPM and schedule timer */
205 if (rcd->aspm_enabled && close_interrupts) {
206 aspm_disable_inc(rcd->dd);
207 rcd->aspm_enabled = false;
208 restart_timer = true;
209 }
210
211 if (restart_timer) {
212 mod_timer(&rcd->aspm_timer,
213 jiffies + msecs_to_jiffies(ASPM_TIMER_MS));
214 rcd->aspm_ts_timer_sched = now;
215 }
216unlock:
217 spin_unlock_irqrestore(&rcd->aspm_lock, flags);
218}
219
220/* Timer function for re-enabling ASPM in the absence of interrupt activity */
221static inline void aspm_ctx_timer_function(unsigned long data)
222{
223 struct hfi1_ctxtdata *rcd = (struct hfi1_ctxtdata *)data;
224 unsigned long flags;
225
226 spin_lock_irqsave(&rcd->aspm_lock, flags);
227 aspm_enable_dec(rcd->dd);
228 rcd->aspm_enabled = true;
229 spin_unlock_irqrestore(&rcd->aspm_lock, flags);
230}
231
232/* Disable interrupt processing for verbs contexts when PSM contexts are open */
233static inline void aspm_disable_all(struct hfi1_devdata *dd)
234{
235 struct hfi1_ctxtdata *rcd;
236 unsigned long flags;
237 unsigned i;
238
239 for (i = 0; i < dd->first_user_ctxt; i++) {
240 rcd = dd->rcd[i];
241 del_timer_sync(&rcd->aspm_timer);
242 spin_lock_irqsave(&rcd->aspm_lock, flags);
243 rcd->aspm_intr_enable = false;
244 spin_unlock_irqrestore(&rcd->aspm_lock, flags);
245 }
246
247 aspm_disable(dd);
248 atomic_set(&dd->aspm_disabled_cnt, 0);
249}
250
251/* Re-enable interrupt processing for verbs contexts */
252static inline void aspm_enable_all(struct hfi1_devdata *dd)
253{
254 struct hfi1_ctxtdata *rcd;
255 unsigned long flags;
256 unsigned i;
257
258 aspm_enable(dd);
259
260 if (aspm_mode != ASPM_MODE_DYNAMIC)
261 return;
262
263 for (i = 0; i < dd->first_user_ctxt; i++) {
264 rcd = dd->rcd[i];
265 spin_lock_irqsave(&rcd->aspm_lock, flags);
266 rcd->aspm_intr_enable = true;
267 rcd->aspm_enabled = true;
268 spin_unlock_irqrestore(&rcd->aspm_lock, flags);
269 }
270}
271
272static inline void aspm_ctx_init(struct hfi1_ctxtdata *rcd)
273{
274 spin_lock_init(&rcd->aspm_lock);
275 setup_timer(&rcd->aspm_timer, aspm_ctx_timer_function,
276 (unsigned long)rcd);
277 rcd->aspm_intr_supported = rcd->dd->aspm_supported &&
278 aspm_mode == ASPM_MODE_DYNAMIC &&
279 rcd->ctxt < rcd->dd->first_user_ctxt;
280}
281
282static inline void aspm_init(struct hfi1_devdata *dd)
283{
284 unsigned i;
285
286 spin_lock_init(&dd->aspm_lock);
287 dd->aspm_supported = aspm_hw_l1_supported(dd);
288
289 for (i = 0; i < dd->first_user_ctxt; i++)
290 aspm_ctx_init(dd->rcd[i]);
291
292 /* Start with ASPM disabled */
293 aspm_hw_set_l1_ent_latency(dd);
294 dd->aspm_enabled = false;
295 aspm_hw_disable_l1(dd);
296
297 /* Now turn on ASPM if configured */
298 aspm_enable_all(dd);
299}
300
301static inline void aspm_exit(struct hfi1_devdata *dd)
302{
303 aspm_disable_all(dd);
304
305 /* Turn on ASPM on exit to conserve power */
306 aspm_enable(dd);
307}
308
309#endif /* _ASPM_H */
diff --git a/drivers/staging/rdma/hfi1/chip.c b/drivers/staging/rdma/hfi1/chip.c
index 46a1830b509b..16eb653903e0 100644
--- a/drivers/staging/rdma/hfi1/chip.c
+++ b/drivers/staging/rdma/hfi1/chip.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -64,6 +61,8 @@
64#include "sdma.h" 61#include "sdma.h"
65#include "eprom.h" 62#include "eprom.h"
66#include "efivar.h" 63#include "efivar.h"
64#include "platform.h"
65#include "aspm.h"
67 66
68#define NUM_IB_PORTS 1 67#define NUM_IB_PORTS 1
69 68
@@ -420,10 +419,10 @@ static struct flag_table pio_err_status_flags[] = {
420 SEC_SPC_FREEZE, 419 SEC_SPC_FREEZE,
421 SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK), 420 SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
422/*23*/ FLAG_ENTRY("PioWriteQwValidParity", 421/*23*/ FLAG_ENTRY("PioWriteQwValidParity",
423 SEC_WRITE_DROPPED|SEC_SPC_FREEZE, 422 SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
424 SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK), 423 SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
425/*24*/ FLAG_ENTRY("PioBlockQwCountParity", 424/*24*/ FLAG_ENTRY("PioBlockQwCountParity",
426 SEC_WRITE_DROPPED|SEC_SPC_FREEZE, 425 SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
427 SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK), 426 SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
428/*25*/ FLAG_ENTRY("PioVlfVlLenParity", 427/*25*/ FLAG_ENTRY("PioVlfVlLenParity",
429 SEC_SPC_FREEZE, 428 SEC_SPC_FREEZE,
@@ -509,6 +508,12 @@ static struct flag_table sdma_err_status_flags[] = {
509 | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \ 508 | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
510 | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK) 509 | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
511 510
511/* SendEgressErrInfo bits that correspond to a PortXmitDiscard counter */
512#define PORT_DISCARD_EGRESS_ERRS \
513 (SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK \
514 | SEND_EGRESS_ERR_INFO_VL_MAPPING_ERR_SMASK \
515 | SEND_EGRESS_ERR_INFO_VL_ERR_SMASK)
516
512/* 517/*
513 * TXE Egress Error flags 518 * TXE Egress Error flags
514 */ 519 */
@@ -936,7 +941,7 @@ static struct flag_table dc8051_err_flags[] = {
936 FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)), 941 FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
937 FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)), 942 FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
938 FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES", 943 FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
939 D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)), 944 D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
940 FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)), 945 FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
941}; 946};
942 947
@@ -950,7 +955,7 @@ static struct flag_table dc8051_info_err_flags[] = {
950 FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME), 955 FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
951 FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET), 956 FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
952 FLAG_ENTRY0("Serdes internal loopback failure", 957 FLAG_ENTRY0("Serdes internal loopback failure",
953 FAILED_SERDES_INTERNAL_LOOPBACK), 958 FAILED_SERDES_INTERNAL_LOOPBACK),
954 FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT), 959 FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
955 FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING), 960 FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
956 FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE), 961 FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
@@ -958,7 +963,8 @@ static struct flag_table dc8051_info_err_flags[] = {
958 FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ), 963 FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
959 FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1), 964 FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
960 FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2), 965 FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
961 FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT) 966 FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT),
967 FLAG_ENTRY0("Host Handshake Timeout", HOST_HANDSHAKE_TIMEOUT)
962}; 968};
963 969
964/* 970/*
@@ -978,7 +984,6 @@ static struct flag_table dc8051_info_host_msg_flags[] = {
978 FLAG_ENTRY0("Link going down", 0x0100), 984 FLAG_ENTRY0("Link going down", 0x0100),
979}; 985};
980 986
981
982static u32 encoded_size(u32 size); 987static u32 encoded_size(u32 size);
983static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate); 988static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
984static int set_physical_link_state(struct hfi1_devdata *dd, u64 state); 989static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
@@ -1140,11 +1145,8 @@ struct cntr_entry {
1140 /* 1145 /*
1141 * accessor for stat element, context either dd or ppd 1146 * accessor for stat element, context either dd or ppd
1142 */ 1147 */
1143 u64 (*rw_cntr)(const struct cntr_entry *, 1148 u64 (*rw_cntr)(const struct cntr_entry *, void *context, int vl,
1144 void *context, 1149 int mode, u64 data);
1145 int vl,
1146 int mode,
1147 u64 data);
1148}; 1150};
1149 1151
1150#define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0 1152#define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
@@ -1188,7 +1190,7 @@ CNTR_ELEM(#name, \
1188#define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx 1190#define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
1189#define OVR_ELM(ctx) \ 1191#define OVR_ELM(ctx) \
1190CNTR_ELEM("RcvHdrOvr" #ctx, \ 1192CNTR_ELEM("RcvHdrOvr" #ctx, \
1191 (RCV_HDR_OVFL_CNT + ctx*0x100), \ 1193 (RCV_HDR_OVFL_CNT + ctx * 0x100), \
1192 0, CNTR_NORMAL, port_access_u64_csr) 1194 0, CNTR_NORMAL, port_access_u64_csr)
1193 1195
1194/* 32bit TXE */ 1196/* 32bit TXE */
@@ -1274,7 +1276,6 @@ static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
1274{ 1276{
1275 u64 ret; 1277 u64 ret;
1276 1278
1277
1278 if (mode == CNTR_MODE_R) { 1279 if (mode == CNTR_MODE_R) {
1279 ret = read_csr(dd, csr); 1280 ret = read_csr(dd, csr);
1280 } else if (mode == CNTR_MODE_W) { 1281 } else if (mode == CNTR_MODE_W) {
@@ -1291,17 +1292,65 @@ static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
1291 1292
1292/* Dev Access */ 1293/* Dev Access */
1293static u64 dev_access_u32_csr(const struct cntr_entry *entry, 1294static u64 dev_access_u32_csr(const struct cntr_entry *entry,
1294 void *context, int vl, int mode, u64 data) 1295 void *context, int vl, int mode, u64 data)
1295{ 1296{
1296 struct hfi1_devdata *dd = context; 1297 struct hfi1_devdata *dd = context;
1298 u64 csr = entry->csr;
1297 1299
1298 if (vl != CNTR_INVALID_VL) 1300 if (entry->flags & CNTR_SDMA) {
1299 return 0; 1301 if (vl == CNTR_INVALID_VL)
1300 return read_write_csr(dd, entry->csr, mode, data); 1302 return 0;
1303 csr += 0x100 * vl;
1304 } else {
1305 if (vl != CNTR_INVALID_VL)
1306 return 0;
1307 }
1308 return read_write_csr(dd, csr, mode, data);
1309}
1310
1311static u64 access_sde_err_cnt(const struct cntr_entry *entry,
1312 void *context, int idx, int mode, u64 data)
1313{
1314 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1315
1316 if (dd->per_sdma && idx < dd->num_sdma)
1317 return dd->per_sdma[idx].err_cnt;
1318 return 0;
1319}
1320
1321static u64 access_sde_int_cnt(const struct cntr_entry *entry,
1322 void *context, int idx, int mode, u64 data)
1323{
1324 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1325
1326 if (dd->per_sdma && idx < dd->num_sdma)
1327 return dd->per_sdma[idx].sdma_int_cnt;
1328 return 0;
1329}
1330
1331static u64 access_sde_idle_int_cnt(const struct cntr_entry *entry,
1332 void *context, int idx, int mode, u64 data)
1333{
1334 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1335
1336 if (dd->per_sdma && idx < dd->num_sdma)
1337 return dd->per_sdma[idx].idle_int_cnt;
1338 return 0;
1339}
1340
1341static u64 access_sde_progress_int_cnt(const struct cntr_entry *entry,
1342 void *context, int idx, int mode,
1343 u64 data)
1344{
1345 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1346
1347 if (dd->per_sdma && idx < dd->num_sdma)
1348 return dd->per_sdma[idx].progress_int_cnt;
1349 return 0;
1301} 1350}
1302 1351
1303static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context, 1352static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
1304 int vl, int mode, u64 data) 1353 int vl, int mode, u64 data)
1305{ 1354{
1306 struct hfi1_devdata *dd = context; 1355 struct hfi1_devdata *dd = context;
1307 1356
@@ -1322,7 +1371,7 @@ static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
1322} 1371}
1323 1372
1324static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context, 1373static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
1325 int vl, int mode, u64 data) 1374 int vl, int mode, u64 data)
1326{ 1375{
1327 struct hfi1_devdata *dd = context; 1376 struct hfi1_devdata *dd = context;
1328 u32 csr = entry->csr; 1377 u32 csr = entry->csr;
@@ -1346,7 +1395,7 @@ static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
1346 1395
1347/* Port Access */ 1396/* Port Access */
1348static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context, 1397static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
1349 int vl, int mode, u64 data) 1398 int vl, int mode, u64 data)
1350{ 1399{
1351 struct hfi1_pportdata *ppd = context; 1400 struct hfi1_pportdata *ppd = context;
1352 1401
@@ -1356,7 +1405,7 @@ static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
1356} 1405}
1357 1406
1358static u64 port_access_u64_csr(const struct cntr_entry *entry, 1407static u64 port_access_u64_csr(const struct cntr_entry *entry,
1359 void *context, int vl, int mode, u64 data) 1408 void *context, int vl, int mode, u64 data)
1360{ 1409{
1361 struct hfi1_pportdata *ppd = context; 1410 struct hfi1_pportdata *ppd = context;
1362 u64 val; 1411 u64 val;
@@ -1396,7 +1445,7 @@ static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
1396} 1445}
1397 1446
1398static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context, 1447static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
1399 int vl, int mode, u64 data) 1448 int vl, int mode, u64 data)
1400{ 1449{
1401 struct hfi1_pportdata *ppd = context; 1450 struct hfi1_pportdata *ppd = context;
1402 1451
@@ -1406,7 +1455,7 @@ static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
1406} 1455}
1407 1456
1408static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context, 1457static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
1409 int vl, int mode, u64 data) 1458 int vl, int mode, u64 data)
1410{ 1459{
1411 struct hfi1_pportdata *ppd = context; 1460 struct hfi1_pportdata *ppd = context;
1412 1461
@@ -1427,18 +1476,25 @@ static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry,
1427} 1476}
1428 1477
1429static u64 access_sw_xmit_discards(const struct cntr_entry *entry, 1478static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
1430 void *context, int vl, int mode, u64 data) 1479 void *context, int vl, int mode, u64 data)
1431{ 1480{
1432 struct hfi1_pportdata *ppd = context; 1481 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
1482 u64 zero = 0;
1483 u64 *counter;
1433 1484
1434 if (vl != CNTR_INVALID_VL) 1485 if (vl == CNTR_INVALID_VL)
1435 return 0; 1486 counter = &ppd->port_xmit_discards;
1487 else if (vl >= 0 && vl < C_VL_COUNT)
1488 counter = &ppd->port_xmit_discards_vl[vl];
1489 else
1490 counter = &zero;
1436 1491
1437 return read_write_sw(ppd->dd, &ppd->port_xmit_discards, mode, data); 1492 return read_write_sw(ppd->dd, counter, mode, data);
1438} 1493}
1439 1494
1440static u64 access_xmit_constraint_errs(const struct cntr_entry *entry, 1495static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
1441 void *context, int vl, int mode, u64 data) 1496 void *context, int vl, int mode,
1497 u64 data)
1442{ 1498{
1443 struct hfi1_pportdata *ppd = context; 1499 struct hfi1_pportdata *ppd = context;
1444 1500
@@ -1450,7 +1506,7 @@ static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
1450} 1506}
1451 1507
1452static u64 access_rcv_constraint_errs(const struct cntr_entry *entry, 1508static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
1453 void *context, int vl, int mode, u64 data) 1509 void *context, int vl, int mode, u64 data)
1454{ 1510{
1455 struct hfi1_pportdata *ppd = context; 1511 struct hfi1_pportdata *ppd = context;
1456 1512
@@ -1475,7 +1531,6 @@ static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
1475 u64 __percpu *cntr, 1531 u64 __percpu *cntr,
1476 int vl, int mode, u64 data) 1532 int vl, int mode, u64 data)
1477{ 1533{
1478
1479 u64 ret = 0; 1534 u64 ret = 0;
1480 1535
1481 if (vl != CNTR_INVALID_VL) 1536 if (vl != CNTR_INVALID_VL)
@@ -1507,7 +1562,7 @@ static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
1507} 1562}
1508 1563
1509static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry, 1564static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
1510 void *context, int vl, int mode, u64 data) 1565 void *context, int vl, int mode, u64 data)
1511{ 1566{
1512 struct hfi1_devdata *dd = context; 1567 struct hfi1_devdata *dd = context;
1513 1568
@@ -1523,6 +1578,14 @@ static u64 access_sw_pio_wait(const struct cntr_entry *entry,
1523 return dd->verbs_dev.n_piowait; 1578 return dd->verbs_dev.n_piowait;
1524} 1579}
1525 1580
1581static u64 access_sw_pio_drain(const struct cntr_entry *entry,
1582 void *context, int vl, int mode, u64 data)
1583{
1584 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1585
1586 return dd->verbs_dev.n_piodrain;
1587}
1588
1526static u64 access_sw_vtx_wait(const struct cntr_entry *entry, 1589static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
1527 void *context, int vl, int mode, u64 data) 1590 void *context, int vl, int mode, u64 data)
1528{ 1591{
@@ -1540,11 +1603,12 @@ static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
1540} 1603}
1541 1604
1542static u64 access_sw_send_schedule(const struct cntr_entry *entry, 1605static u64 access_sw_send_schedule(const struct cntr_entry *entry,
1543 void *context, int vl, int mode, u64 data) 1606 void *context, int vl, int mode, u64 data)
1544{ 1607{
1545 struct hfi1_devdata *dd = (struct hfi1_devdata *)context; 1608 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1546 1609
1547 return dd->verbs_dev.n_send_schedule; 1610 return read_write_cpu(dd, &dd->z_send_schedule, dd->send_schedule, vl,
1611 mode, data);
1548} 1612}
1549 1613
1550/* Software counters for the error status bits within MISC_ERR_STATUS */ 1614/* Software counters for the error status bits within MISC_ERR_STATUS */
@@ -3882,8 +3946,8 @@ static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
3882 void *context, int vl, int mode, u64 data) \ 3946 void *context, int vl, int mode, u64 data) \
3883{ \ 3947{ \
3884 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \ 3948 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
3885 return read_write_cpu(ppd->dd, &ppd->ibport_data.z_ ##cntr, \ 3949 return read_write_cpu(ppd->dd, &ppd->ibport_data.rvp.z_ ##cntr, \
3886 ppd->ibport_data.cntr, vl, \ 3950 ppd->ibport_data.rvp.cntr, vl, \
3887 mode, data); \ 3951 mode, data); \
3888} 3952}
3889 3953
@@ -3900,7 +3964,7 @@ static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
3900 if (vl != CNTR_INVALID_VL) \ 3964 if (vl != CNTR_INVALID_VL) \
3901 return 0; \ 3965 return 0; \
3902 \ 3966 \
3903 return read_write_sw(ppd->dd, &ppd->ibport_data.n_ ##cntr, \ 3967 return read_write_sw(ppd->dd, &ppd->ibport_data.rvp.n_ ##cntr, \
3904 mode, data); \ 3968 mode, data); \
3905} 3969}
3906 3970
@@ -4063,10 +4127,28 @@ static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
4063 access_sw_vtx_wait), 4127 access_sw_vtx_wait),
4064[C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL, 4128[C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
4065 access_sw_pio_wait), 4129 access_sw_pio_wait),
4130[C_SW_PIO_DRAIN] = CNTR_ELEM("PioDrain", 0, 0, CNTR_NORMAL,
4131 access_sw_pio_drain),
4066[C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL, 4132[C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
4067 access_sw_kmem_wait), 4133 access_sw_kmem_wait),
4068[C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL, 4134[C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
4069 access_sw_send_schedule), 4135 access_sw_send_schedule),
4136[C_SDMA_DESC_FETCHED_CNT] = CNTR_ELEM("SDEDscFdCn",
4137 SEND_DMA_DESC_FETCHED_CNT, 0,
4138 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4139 dev_access_u32_csr),
4140[C_SDMA_INT_CNT] = CNTR_ELEM("SDMAInt", 0, 0,
4141 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4142 access_sde_int_cnt),
4143[C_SDMA_ERR_CNT] = CNTR_ELEM("SDMAErrCt", 0, 0,
4144 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4145 access_sde_err_cnt),
4146[C_SDMA_IDLE_INT_CNT] = CNTR_ELEM("SDMAIdInt", 0, 0,
4147 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4148 access_sde_idle_int_cnt),
4149[C_SDMA_PROGRESS_INT_CNT] = CNTR_ELEM("SDMAPrIntCn", 0, 0,
4150 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4151 access_sde_progress_int_cnt),
4070/* MISC_ERR_STATUS */ 4152/* MISC_ERR_STATUS */
4071[C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0, 4153[C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0,
4072 CNTR_NORMAL, 4154 CNTR_NORMAL,
@@ -4876,28 +4958,28 @@ static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
4876[C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL), 4958[C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
4877[C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH), 4959[C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
4878[C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT, 4960[C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
4879 CNTR_SYNTH | CNTR_VL), 4961 CNTR_SYNTH | CNTR_VL),
4880[C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT, 4962[C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
4881 CNTR_SYNTH | CNTR_VL), 4963 CNTR_SYNTH | CNTR_VL),
4882[C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT, 4964[C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
4883 CNTR_SYNTH | CNTR_VL), 4965 CNTR_SYNTH | CNTR_VL),
4884[C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL), 4966[C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
4885[C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL), 4967[C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
4886[C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT, 4968[C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
4887 access_sw_link_dn_cnt), 4969 access_sw_link_dn_cnt),
4888[C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT, 4970[C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
4889 access_sw_link_up_cnt), 4971 access_sw_link_up_cnt),
4890[C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL, 4972[C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL,
4891 access_sw_unknown_frame_cnt), 4973 access_sw_unknown_frame_cnt),
4892[C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT, 4974[C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
4893 access_sw_xmit_discards), 4975 access_sw_xmit_discards),
4894[C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0, 4976[C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
4895 CNTR_SYNTH | CNTR_32BIT | CNTR_VL, 4977 CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
4896 access_sw_xmit_discards), 4978 access_sw_xmit_discards),
4897[C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH, 4979[C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
4898 access_xmit_constraint_errs), 4980 access_xmit_constraint_errs),
4899[C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH, 4981[C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
4900 access_rcv_constraint_errs), 4982 access_rcv_constraint_errs),
4901[C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts), 4983[C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
4902[C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends), 4984[C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
4903[C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks), 4985[C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
@@ -4913,9 +4995,9 @@ static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
4913[C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL, 4995[C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
4914 access_sw_cpu_rc_acks), 4996 access_sw_cpu_rc_acks),
4915[C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL, 4997[C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
4916 access_sw_cpu_rc_qacks), 4998 access_sw_cpu_rc_qacks),
4917[C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL, 4999[C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
4918 access_sw_cpu_rc_delayed_comp), 5000 access_sw_cpu_rc_delayed_comp),
4919[OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1), 5001[OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
4920[OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3), 5002[OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
4921[OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5), 5003[OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
@@ -5064,7 +5146,7 @@ done:
5064 * the buffer. End in '*' if the buffer is too short. 5146 * the buffer. End in '*' if the buffer is too short.
5065 */ 5147 */
5066static char *flag_string(char *buf, int buf_len, u64 flags, 5148static char *flag_string(char *buf, int buf_len, u64 flags,
5067 struct flag_table *table, int table_size) 5149 struct flag_table *table, int table_size)
5068{ 5150{
5069 char extra[32]; 5151 char extra[32];
5070 char *p = buf; 5152 char *p = buf;
@@ -5125,10 +5207,8 @@ static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
5125 if (source < ARRAY_SIZE(cce_misc_names)) 5207 if (source < ARRAY_SIZE(cce_misc_names))
5126 strncpy(buf, cce_misc_names[source], bsize); 5208 strncpy(buf, cce_misc_names[source], bsize);
5127 else 5209 else
5128 snprintf(buf, 5210 snprintf(buf, bsize, "Reserved%u",
5129 bsize, 5211 source + IS_GENERAL_ERR_START);
5130 "Reserved%u",
5131 source + IS_GENERAL_ERR_START);
5132 5212
5133 return buf; 5213 return buf;
5134} 5214}
@@ -5167,7 +5247,7 @@ static char *is_various_name(char *buf, size_t bsize, unsigned int source)
5167 if (source < ARRAY_SIZE(various_names)) 5247 if (source < ARRAY_SIZE(various_names))
5168 strncpy(buf, various_names[source], bsize); 5248 strncpy(buf, various_names[source], bsize);
5169 else 5249 else
5170 snprintf(buf, bsize, "Reserved%u", source+IS_VARIOUS_START); 5250 snprintf(buf, bsize, "Reserved%u", source + IS_VARIOUS_START);
5171 return buf; 5251 return buf;
5172} 5252}
5173 5253
@@ -5252,51 +5332,56 @@ static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
5252static char *cce_err_status_string(char *buf, int buf_len, u64 flags) 5332static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
5253{ 5333{
5254 return flag_string(buf, buf_len, flags, 5334 return flag_string(buf, buf_len, flags,
5255 cce_err_status_flags, ARRAY_SIZE(cce_err_status_flags)); 5335 cce_err_status_flags,
5336 ARRAY_SIZE(cce_err_status_flags));
5256} 5337}
5257 5338
5258static char *rxe_err_status_string(char *buf, int buf_len, u64 flags) 5339static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
5259{ 5340{
5260 return flag_string(buf, buf_len, flags, 5341 return flag_string(buf, buf_len, flags,
5261 rxe_err_status_flags, ARRAY_SIZE(rxe_err_status_flags)); 5342 rxe_err_status_flags,
5343 ARRAY_SIZE(rxe_err_status_flags));
5262} 5344}
5263 5345
5264static char *misc_err_status_string(char *buf, int buf_len, u64 flags) 5346static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
5265{ 5347{
5266 return flag_string(buf, buf_len, flags, misc_err_status_flags, 5348 return flag_string(buf, buf_len, flags, misc_err_status_flags,
5267 ARRAY_SIZE(misc_err_status_flags)); 5349 ARRAY_SIZE(misc_err_status_flags));
5268} 5350}
5269 5351
5270static char *pio_err_status_string(char *buf, int buf_len, u64 flags) 5352static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
5271{ 5353{
5272 return flag_string(buf, buf_len, flags, 5354 return flag_string(buf, buf_len, flags,
5273 pio_err_status_flags, ARRAY_SIZE(pio_err_status_flags)); 5355 pio_err_status_flags,
5356 ARRAY_SIZE(pio_err_status_flags));
5274} 5357}
5275 5358
5276static char *sdma_err_status_string(char *buf, int buf_len, u64 flags) 5359static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
5277{ 5360{
5278 return flag_string(buf, buf_len, flags, 5361 return flag_string(buf, buf_len, flags,
5279 sdma_err_status_flags, 5362 sdma_err_status_flags,
5280 ARRAY_SIZE(sdma_err_status_flags)); 5363 ARRAY_SIZE(sdma_err_status_flags));
5281} 5364}
5282 5365
5283static char *egress_err_status_string(char *buf, int buf_len, u64 flags) 5366static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
5284{ 5367{
5285 return flag_string(buf, buf_len, flags, 5368 return flag_string(buf, buf_len, flags,
5286 egress_err_status_flags, ARRAY_SIZE(egress_err_status_flags)); 5369 egress_err_status_flags,
5370 ARRAY_SIZE(egress_err_status_flags));
5287} 5371}
5288 5372
5289static char *egress_err_info_string(char *buf, int buf_len, u64 flags) 5373static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
5290{ 5374{
5291 return flag_string(buf, buf_len, flags, 5375 return flag_string(buf, buf_len, flags,
5292 egress_err_info_flags, ARRAY_SIZE(egress_err_info_flags)); 5376 egress_err_info_flags,
5377 ARRAY_SIZE(egress_err_info_flags));
5293} 5378}
5294 5379
5295static char *send_err_status_string(char *buf, int buf_len, u64 flags) 5380static char *send_err_status_string(char *buf, int buf_len, u64 flags)
5296{ 5381{
5297 return flag_string(buf, buf_len, flags, 5382 return flag_string(buf, buf_len, flags,
5298 send_err_status_flags, 5383 send_err_status_flags,
5299 ARRAY_SIZE(send_err_status_flags)); 5384 ARRAY_SIZE(send_err_status_flags));
5300} 5385}
5301 5386
5302static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg) 5387static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
@@ -5309,7 +5394,7 @@ static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5309 * report or record it. 5394 * report or record it.
5310 */ 5395 */
5311 dd_dev_info(dd, "CCE Error: %s\n", 5396 dd_dev_info(dd, "CCE Error: %s\n",
5312 cce_err_status_string(buf, sizeof(buf), reg)); 5397 cce_err_status_string(buf, sizeof(buf), reg));
5313 5398
5314 if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) && 5399 if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
5315 is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) { 5400 is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
@@ -5339,14 +5424,14 @@ static void update_rcverr_timer(unsigned long opaque)
5339 u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL); 5424 u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
5340 5425
5341 if (dd->rcv_ovfl_cnt < cur_ovfl_cnt && 5426 if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
5342 ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) { 5427 ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
5343 dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__); 5428 dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
5344 set_link_down_reason(ppd, 5429 set_link_down_reason(
5345 OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0, 5430 ppd, OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
5346 OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN); 5431 OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
5347 queue_work(ppd->hfi1_wq, &ppd->link_bounce_work); 5432 queue_work(ppd->hfi1_wq, &ppd->link_bounce_work);
5348 } 5433 }
5349 dd->rcv_ovfl_cnt = (u32) cur_ovfl_cnt; 5434 dd->rcv_ovfl_cnt = (u32)cur_ovfl_cnt;
5350 5435
5351 mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME); 5436 mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
5352} 5437}
@@ -5372,7 +5457,7 @@ static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5372 int i = 0; 5457 int i = 0;
5373 5458
5374 dd_dev_info(dd, "Receive Error: %s\n", 5459 dd_dev_info(dd, "Receive Error: %s\n",
5375 rxe_err_status_string(buf, sizeof(buf), reg)); 5460 rxe_err_status_string(buf, sizeof(buf), reg));
5376 5461
5377 if (reg & ALL_RXE_FREEZE_ERR) { 5462 if (reg & ALL_RXE_FREEZE_ERR) {
5378 int flags = 0; 5463 int flags = 0;
@@ -5399,7 +5484,7 @@ static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5399 int i = 0; 5484 int i = 0;
5400 5485
5401 dd_dev_info(dd, "Misc Error: %s", 5486 dd_dev_info(dd, "Misc Error: %s",
5402 misc_err_status_string(buf, sizeof(buf), reg)); 5487 misc_err_status_string(buf, sizeof(buf), reg));
5403 for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) { 5488 for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) {
5404 if (reg & (1ull << i)) 5489 if (reg & (1ull << i))
5405 incr_cntr64(&dd->misc_err_status_cnt[i]); 5490 incr_cntr64(&dd->misc_err_status_cnt[i]);
@@ -5412,7 +5497,7 @@ static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5412 int i = 0; 5497 int i = 0;
5413 5498
5414 dd_dev_info(dd, "PIO Error: %s\n", 5499 dd_dev_info(dd, "PIO Error: %s\n",
5415 pio_err_status_string(buf, sizeof(buf), reg)); 5500 pio_err_status_string(buf, sizeof(buf), reg));
5416 5501
5417 if (reg & ALL_PIO_FREEZE_ERR) 5502 if (reg & ALL_PIO_FREEZE_ERR)
5418 start_freeze_handling(dd->pport, 0); 5503 start_freeze_handling(dd->pport, 0);
@@ -5429,7 +5514,7 @@ static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5429 int i = 0; 5514 int i = 0;
5430 5515
5431 dd_dev_info(dd, "SDMA Error: %s\n", 5516 dd_dev_info(dd, "SDMA Error: %s\n",
5432 sdma_err_status_string(buf, sizeof(buf), reg)); 5517 sdma_err_status_string(buf, sizeof(buf), reg));
5433 5518
5434 if (reg & ALL_SDMA_FREEZE_ERR) 5519 if (reg & ALL_SDMA_FREEZE_ERR)
5435 start_freeze_handling(dd->pport, 0); 5520 start_freeze_handling(dd->pport, 0);
@@ -5440,12 +5525,14 @@ static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5440 } 5525 }
5441} 5526}
5442 5527
5443static void count_port_inactive(struct hfi1_devdata *dd) 5528static inline void __count_port_discards(struct hfi1_pportdata *ppd)
5444{ 5529{
5445 struct hfi1_pportdata *ppd = dd->pport; 5530 incr_cntr64(&ppd->port_xmit_discards);
5531}
5446 5532
5447 if (ppd->port_xmit_discards < ~(u64)0) 5533static void count_port_inactive(struct hfi1_devdata *dd)
5448 ppd->port_xmit_discards++; 5534{
5535 __count_port_discards(dd->pport);
5449} 5536}
5450 5537
5451/* 5538/*
@@ -5457,7 +5544,8 @@ static void count_port_inactive(struct hfi1_devdata *dd)
5457 * egress error if more than one packet fails the same integrity check 5544 * egress error if more than one packet fails the same integrity check
5458 * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO. 5545 * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
5459 */ 5546 */
5460static void handle_send_egress_err_info(struct hfi1_devdata *dd) 5547static void handle_send_egress_err_info(struct hfi1_devdata *dd,
5548 int vl)
5461{ 5549{
5462 struct hfi1_pportdata *ppd = dd->pport; 5550 struct hfi1_pportdata *ppd = dd->pport;
5463 u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */ 5551 u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
@@ -5468,14 +5556,44 @@ static void handle_send_egress_err_info(struct hfi1_devdata *dd)
5468 write_csr(dd, SEND_EGRESS_ERR_INFO, info); 5556 write_csr(dd, SEND_EGRESS_ERR_INFO, info);
5469 5557
5470 dd_dev_info(dd, 5558 dd_dev_info(dd,
5471 "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n", 5559 "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
5472 info, egress_err_info_string(buf, sizeof(buf), info), src); 5560 info, egress_err_info_string(buf, sizeof(buf), info), src);
5473 5561
5474 /* Eventually add other counters for each bit */ 5562 /* Eventually add other counters for each bit */
5563 if (info & PORT_DISCARD_EGRESS_ERRS) {
5564 int weight, i;
5475 5565
5476 if (info & SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK) { 5566 /*
5477 if (ppd->port_xmit_discards < ~(u64)0) 5567 * Count all applicable bits as individual errors and
5478 ppd->port_xmit_discards++; 5568 * attribute them to the packet that triggered this handler.
5569 * This may not be completely accurate due to limitations
5570 * on the available hardware error information. There is
5571 * a single information register and any number of error
5572 * packets may have occurred and contributed to it before
5573 * this routine is called. This means that:
5574 * a) If multiple packets with the same error occur before
5575 * this routine is called, earlier packets are missed.
5576 * There is only a single bit for each error type.
5577 * b) Errors may not be attributed to the correct VL.
5578 * The driver is attributing all bits in the info register
5579 * to the packet that triggered this call, but bits
5580 * could be an accumulation of different packets with
5581 * different VLs.
5582 * c) A single error packet may have multiple counts attached
5583 * to it. There is no way for the driver to know if
5584 * multiple bits set in the info register are due to a
5585 * single packet or multiple packets. The driver assumes
5586 * multiple packets.
5587 */
5588 weight = hweight64(info & PORT_DISCARD_EGRESS_ERRS);
5589 for (i = 0; i < weight; i++) {
5590 __count_port_discards(ppd);
5591 if (vl >= 0 && vl < TXE_NUM_DATA_VL)
5592 incr_cntr64(&ppd->port_xmit_discards_vl[vl]);
5593 else if (vl == 15)
5594 incr_cntr64(&ppd->port_xmit_discards_vl
5595 [C_VL_15]);
5596 }
5479 } 5597 }
5480} 5598}
5481 5599
@@ -5493,12 +5611,71 @@ static inline int port_inactive_err(u64 posn)
5493 * Input value is a bit position within the SEND_EGRESS_ERR_STATUS 5611 * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
5494 * register. Does it represent a 'disallowed packet' error? 5612 * register. Does it represent a 'disallowed packet' error?
5495 */ 5613 */
5496static inline int disallowed_pkt_err(u64 posn) 5614static inline int disallowed_pkt_err(int posn)
5497{ 5615{
5498 return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) && 5616 return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
5499 posn <= SEES(TX_SDMA15_DISALLOWED_PACKET)); 5617 posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
5500} 5618}
5501 5619
5620/*
5621 * Input value is a bit position of one of the SDMA engine disallowed
5622 * packet errors. Return which engine. Use of this must be guarded by
5623 * disallowed_pkt_err().
5624 */
5625static inline int disallowed_pkt_engine(int posn)
5626{
5627 return posn - SEES(TX_SDMA0_DISALLOWED_PACKET);
5628}
5629
5630/*
5631 * Translate an SDMA engine to a VL. Return -1 if the tranlation cannot
5632 * be done.
5633 */
5634static int engine_to_vl(struct hfi1_devdata *dd, int engine)
5635{
5636 struct sdma_vl_map *m;
5637 int vl;
5638
5639 /* range check */
5640 if (engine < 0 || engine >= TXE_NUM_SDMA_ENGINES)
5641 return -1;
5642
5643 rcu_read_lock();
5644 m = rcu_dereference(dd->sdma_map);
5645 vl = m->engine_to_vl[engine];
5646 rcu_read_unlock();
5647
5648 return vl;
5649}
5650
5651/*
5652 * Translate the send context (sofware index) into a VL. Return -1 if the
5653 * translation cannot be done.
5654 */
5655static int sc_to_vl(struct hfi1_devdata *dd, int sw_index)
5656{
5657 struct send_context_info *sci;
5658 struct send_context *sc;
5659 int i;
5660
5661 sci = &dd->send_contexts[sw_index];
5662
5663 /* there is no information for user (PSM) and ack contexts */
5664 if (sci->type != SC_KERNEL)
5665 return -1;
5666
5667 sc = sci->sc;
5668 if (!sc)
5669 return -1;
5670 if (dd->vld[15].sc == sc)
5671 return 15;
5672 for (i = 0; i < num_vls; i++)
5673 if (dd->vld[i].sc == sc)
5674 return i;
5675
5676 return -1;
5677}
5678
5502static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg) 5679static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5503{ 5680{
5504 u64 reg_copy = reg, handled = 0; 5681 u64 reg_copy = reg, handled = 0;
@@ -5507,34 +5684,34 @@ static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5507 5684
5508 if (reg & ALL_TXE_EGRESS_FREEZE_ERR) 5685 if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
5509 start_freeze_handling(dd->pport, 0); 5686 start_freeze_handling(dd->pport, 0);
5510 if (is_ax(dd) && (reg & 5687 else if (is_ax(dd) &&
5511 SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) 5688 (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) &&
5512 && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) 5689 (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
5513 start_freeze_handling(dd->pport, 0); 5690 start_freeze_handling(dd->pport, 0);
5514 5691
5515 while (reg_copy) { 5692 while (reg_copy) {
5516 int posn = fls64(reg_copy); 5693 int posn = fls64(reg_copy);
5517 /* 5694 /* fls64() returns a 1-based offset, we want it zero based */
5518 * fls64() returns a 1-based offset, but we generally
5519 * want 0-based offsets.
5520 */
5521 int shift = posn - 1; 5695 int shift = posn - 1;
5696 u64 mask = 1ULL << shift;
5522 5697
5523 if (port_inactive_err(shift)) { 5698 if (port_inactive_err(shift)) {
5524 count_port_inactive(dd); 5699 count_port_inactive(dd);
5525 handled |= (1ULL << shift); 5700 handled |= mask;
5526 } else if (disallowed_pkt_err(shift)) { 5701 } else if (disallowed_pkt_err(shift)) {
5527 handle_send_egress_err_info(dd); 5702 int vl = engine_to_vl(dd, disallowed_pkt_engine(shift));
5528 handled |= (1ULL << shift); 5703
5704 handle_send_egress_err_info(dd, vl);
5705 handled |= mask;
5529 } 5706 }
5530 clear_bit(shift, (unsigned long *)&reg_copy); 5707 reg_copy &= ~mask;
5531 } 5708 }
5532 5709
5533 reg &= ~handled; 5710 reg &= ~handled;
5534 5711
5535 if (reg) 5712 if (reg)
5536 dd_dev_info(dd, "Egress Error: %s\n", 5713 dd_dev_info(dd, "Egress Error: %s\n",
5537 egress_err_status_string(buf, sizeof(buf), reg)); 5714 egress_err_status_string(buf, sizeof(buf), reg));
5538 5715
5539 for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) { 5716 for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) {
5540 if (reg & (1ull << i)) 5717 if (reg & (1ull << i))
@@ -5548,7 +5725,7 @@ static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5548 int i = 0; 5725 int i = 0;
5549 5726
5550 dd_dev_info(dd, "Send Error: %s\n", 5727 dd_dev_info(dd, "Send Error: %s\n",
5551 send_err_status_string(buf, sizeof(buf), reg)); 5728 send_err_status_string(buf, sizeof(buf), reg));
5552 5729
5553 for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) { 5730 for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) {
5554 if (reg & (1ull << i)) 5731 if (reg & (1ull << i))
@@ -5594,7 +5771,7 @@ static void interrupt_clear_down(struct hfi1_devdata *dd,
5594 u64 mask; 5771 u64 mask;
5595 5772
5596 dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n", 5773 dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
5597 eri->desc, reg); 5774 eri->desc, reg);
5598 /* 5775 /*
5599 * Read-modify-write so any other masked bits 5776 * Read-modify-write so any other masked bits
5600 * remain masked. 5777 * remain masked.
@@ -5618,14 +5795,15 @@ static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
5618 interrupt_clear_down(dd, 0, eri); 5795 interrupt_clear_down(dd, 0, eri);
5619 } else { 5796 } else {
5620 dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n", 5797 dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
5621 source); 5798 source);
5622 } 5799 }
5623} 5800}
5624 5801
5625static char *send_context_err_status_string(char *buf, int buf_len, u64 flags) 5802static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
5626{ 5803{
5627 return flag_string(buf, buf_len, flags, 5804 return flag_string(buf, buf_len, flags,
5628 sc_err_status_flags, ARRAY_SIZE(sc_err_status_flags)); 5805 sc_err_status_flags,
5806 ARRAY_SIZE(sc_err_status_flags));
5629} 5807}
5630 5808
5631/* 5809/*
@@ -5650,15 +5828,15 @@ static void is_sendctxt_err_int(struct hfi1_devdata *dd,
5650 sw_index = dd->hw_to_sw[hw_context]; 5828 sw_index = dd->hw_to_sw[hw_context];
5651 if (sw_index >= dd->num_send_contexts) { 5829 if (sw_index >= dd->num_send_contexts) {
5652 dd_dev_err(dd, 5830 dd_dev_err(dd,
5653 "out of range sw index %u for send context %u\n", 5831 "out of range sw index %u for send context %u\n",
5654 sw_index, hw_context); 5832 sw_index, hw_context);
5655 return; 5833 return;
5656 } 5834 }
5657 sci = &dd->send_contexts[sw_index]; 5835 sci = &dd->send_contexts[sw_index];
5658 sc = sci->sc; 5836 sc = sci->sc;
5659 if (!sc) { 5837 if (!sc) {
5660 dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__, 5838 dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
5661 sw_index, hw_context); 5839 sw_index, hw_context);
5662 return; 5840 return;
5663 } 5841 }
5664 5842
@@ -5668,10 +5846,11 @@ static void is_sendctxt_err_int(struct hfi1_devdata *dd,
5668 status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS); 5846 status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
5669 5847
5670 dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context, 5848 dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
5671 send_context_err_status_string(flags, sizeof(flags), status)); 5849 send_context_err_status_string(flags, sizeof(flags),
5850 status));
5672 5851
5673 if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK) 5852 if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
5674 handle_send_egress_err_info(dd); 5853 handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
5675 5854
5676 /* 5855 /*
5677 * Automatically restart halted kernel contexts out of interrupt 5856 * Automatically restart halted kernel contexts out of interrupt
@@ -5704,6 +5883,7 @@ static void handle_sdma_eng_err(struct hfi1_devdata *dd,
5704 dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n", 5883 dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
5705 sde->this_idx, source, (unsigned long long)status); 5884 sde->this_idx, source, (unsigned long long)status);
5706#endif 5885#endif
5886 sde->err_cnt++;
5707 sdma_engine_error(sde, status); 5887 sdma_engine_error(sde, status);
5708 5888
5709 /* 5889 /*
@@ -5752,23 +5932,22 @@ static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
5752 interrupt_clear_down(dd, 0, eri); 5932 interrupt_clear_down(dd, 0, eri);
5753 else 5933 else
5754 dd_dev_info(dd, 5934 dd_dev_info(dd,
5755 "%s: Unimplemented/reserved interrupt %d\n", 5935 "%s: Unimplemented/reserved interrupt %d\n",
5756 __func__, source); 5936 __func__, source);
5757} 5937}
5758 5938
5759static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg) 5939static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
5760{ 5940{
5761 /* source is always zero */ 5941 /* src_ctx is always zero */
5762 struct hfi1_pportdata *ppd = dd->pport; 5942 struct hfi1_pportdata *ppd = dd->pport;
5763 unsigned long flags; 5943 unsigned long flags;
5764 u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N); 5944 u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
5765 5945
5766 if (reg & QSFP_HFI0_MODPRST_N) { 5946 if (reg & QSFP_HFI0_MODPRST_N) {
5767
5768 dd_dev_info(dd, "%s: ModPresent triggered QSFP interrupt\n",
5769 __func__);
5770
5771 if (!qsfp_mod_present(ppd)) { 5947 if (!qsfp_mod_present(ppd)) {
5948 dd_dev_info(dd, "%s: QSFP module removed\n",
5949 __func__);
5950
5772 ppd->driver_link_ready = 0; 5951 ppd->driver_link_ready = 0;
5773 /* 5952 /*
5774 * Cable removed, reset all our information about the 5953 * Cable removed, reset all our information about the
@@ -5781,14 +5960,23 @@ static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
5781 * an interrupt when a cable is inserted 5960 * an interrupt when a cable is inserted
5782 */ 5961 */
5783 ppd->qsfp_info.cache_valid = 0; 5962 ppd->qsfp_info.cache_valid = 0;
5784 ppd->qsfp_info.qsfp_interrupt_functional = 0; 5963 ppd->qsfp_info.reset_needed = 0;
5964 ppd->qsfp_info.limiting_active = 0;
5785 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, 5965 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
5786 flags); 5966 flags);
5787 write_csr(dd, 5967 /* Invert the ModPresent pin now to detect plug-in */
5788 dd->hfi1_id ? 5968 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
5789 ASIC_QSFP2_INVERT : 5969 ASIC_QSFP1_INVERT, qsfp_int_mgmt);
5790 ASIC_QSFP1_INVERT, 5970
5791 qsfp_int_mgmt); 5971 if ((ppd->offline_disabled_reason >
5972 HFI1_ODR_MASK(
5973 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
5974 (ppd->offline_disabled_reason ==
5975 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
5976 ppd->offline_disabled_reason =
5977 HFI1_ODR_MASK(
5978 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
5979
5792 if (ppd->host_link_state == HLS_DN_POLL) { 5980 if (ppd->host_link_state == HLS_DN_POLL) {
5793 /* 5981 /*
5794 * The link is still in POLL. This means 5982 * The link is still in POLL. This means
@@ -5799,28 +5987,33 @@ static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
5799 queue_work(ppd->hfi1_wq, &ppd->link_down_work); 5987 queue_work(ppd->hfi1_wq, &ppd->link_down_work);
5800 } 5988 }
5801 } else { 5989 } else {
5990 dd_dev_info(dd, "%s: QSFP module inserted\n",
5991 __func__);
5992
5802 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags); 5993 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
5803 ppd->qsfp_info.cache_valid = 0; 5994 ppd->qsfp_info.cache_valid = 0;
5804 ppd->qsfp_info.cache_refresh_required = 1; 5995 ppd->qsfp_info.cache_refresh_required = 1;
5805 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, 5996 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
5806 flags); 5997 flags);
5807 5998
5999 /*
6000 * Stop inversion of ModPresent pin to detect
6001 * removal of the cable
6002 */
5808 qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N; 6003 qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
5809 write_csr(dd, 6004 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
5810 dd->hfi1_id ? 6005 ASIC_QSFP1_INVERT, qsfp_int_mgmt);
5811 ASIC_QSFP2_INVERT : 6006
5812 ASIC_QSFP1_INVERT, 6007 ppd->offline_disabled_reason =
5813 qsfp_int_mgmt); 6008 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
5814 } 6009 }
5815 } 6010 }
5816 6011
5817 if (reg & QSFP_HFI0_INT_N) { 6012 if (reg & QSFP_HFI0_INT_N) {
5818 6013 dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
5819 dd_dev_info(dd, "%s: IntN triggered QSFP interrupt\n", 6014 __func__);
5820 __func__);
5821 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags); 6015 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
5822 ppd->qsfp_info.check_interrupt_flags = 1; 6016 ppd->qsfp_info.check_interrupt_flags = 1;
5823 ppd->qsfp_info.qsfp_interrupt_functional = 1;
5824 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags); 6017 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
5825 } 6018 }
5826 6019
@@ -5834,11 +6027,11 @@ static int request_host_lcb_access(struct hfi1_devdata *dd)
5834 int ret; 6027 int ret;
5835 6028
5836 ret = do_8051_command(dd, HCMD_MISC, 6029 ret = do_8051_command(dd, HCMD_MISC,
5837 (u64)HCMD_MISC_REQUEST_LCB_ACCESS << LOAD_DATA_FIELD_ID_SHIFT, 6030 (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
5838 NULL); 6031 LOAD_DATA_FIELD_ID_SHIFT, NULL);
5839 if (ret != HCMD_SUCCESS) { 6032 if (ret != HCMD_SUCCESS) {
5840 dd_dev_err(dd, "%s: command failed with error %d\n", 6033 dd_dev_err(dd, "%s: command failed with error %d\n",
5841 __func__, ret); 6034 __func__, ret);
5842 } 6035 }
5843 return ret == HCMD_SUCCESS ? 0 : -EBUSY; 6036 return ret == HCMD_SUCCESS ? 0 : -EBUSY;
5844} 6037}
@@ -5848,11 +6041,11 @@ static int request_8051_lcb_access(struct hfi1_devdata *dd)
5848 int ret; 6041 int ret;
5849 6042
5850 ret = do_8051_command(dd, HCMD_MISC, 6043 ret = do_8051_command(dd, HCMD_MISC,
5851 (u64)HCMD_MISC_GRANT_LCB_ACCESS << LOAD_DATA_FIELD_ID_SHIFT, 6044 (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
5852 NULL); 6045 LOAD_DATA_FIELD_ID_SHIFT, NULL);
5853 if (ret != HCMD_SUCCESS) { 6046 if (ret != HCMD_SUCCESS) {
5854 dd_dev_err(dd, "%s: command failed with error %d\n", 6047 dd_dev_err(dd, "%s: command failed with error %d\n",
5855 __func__, ret); 6048 __func__, ret);
5856 } 6049 }
5857 return ret == HCMD_SUCCESS ? 0 : -EBUSY; 6050 return ret == HCMD_SUCCESS ? 0 : -EBUSY;
5858} 6051}
@@ -5864,8 +6057,8 @@ static int request_8051_lcb_access(struct hfi1_devdata *dd)
5864static inline void set_host_lcb_access(struct hfi1_devdata *dd) 6057static inline void set_host_lcb_access(struct hfi1_devdata *dd)
5865{ 6058{
5866 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL, 6059 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
5867 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK 6060 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
5868 | DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK); 6061 DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
5869} 6062}
5870 6063
5871/* 6064/*
@@ -5875,7 +6068,7 @@ static inline void set_host_lcb_access(struct hfi1_devdata *dd)
5875static inline void set_8051_lcb_access(struct hfi1_devdata *dd) 6068static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
5876{ 6069{
5877 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL, 6070 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
5878 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK); 6071 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
5879} 6072}
5880 6073
5881/* 6074/*
@@ -5909,7 +6102,7 @@ int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
5909 /* this access is valid only when the link is up */ 6102 /* this access is valid only when the link is up */
5910 if ((ppd->host_link_state & HLS_UP) == 0) { 6103 if ((ppd->host_link_state & HLS_UP) == 0) {
5911 dd_dev_info(dd, "%s: link state %s not up\n", 6104 dd_dev_info(dd, "%s: link state %s not up\n",
5912 __func__, link_state_name(ppd->host_link_state)); 6105 __func__, link_state_name(ppd->host_link_state));
5913 ret = -EBUSY; 6106 ret = -EBUSY;
5914 goto done; 6107 goto done;
5915 } 6108 }
@@ -5918,8 +6111,8 @@ int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
5918 ret = request_host_lcb_access(dd); 6111 ret = request_host_lcb_access(dd);
5919 if (ret) { 6112 if (ret) {
5920 dd_dev_err(dd, 6113 dd_dev_err(dd,
5921 "%s: unable to acquire LCB access, err %d\n", 6114 "%s: unable to acquire LCB access, err %d\n",
5922 __func__, ret); 6115 __func__, ret);
5923 goto done; 6116 goto done;
5924 } 6117 }
5925 set_host_lcb_access(dd); 6118 set_host_lcb_access(dd);
@@ -5956,7 +6149,7 @@ int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
5956 6149
5957 if (dd->lcb_access_count == 0) { 6150 if (dd->lcb_access_count == 0) {
5958 dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n", 6151 dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
5959 __func__); 6152 __func__);
5960 goto done; 6153 goto done;
5961 } 6154 }
5962 6155
@@ -5965,8 +6158,8 @@ int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
5965 ret = request_8051_lcb_access(dd); 6158 ret = request_8051_lcb_access(dd);
5966 if (ret) { 6159 if (ret) {
5967 dd_dev_err(dd, 6160 dd_dev_err(dd,
5968 "%s: unable to release LCB access, err %d\n", 6161 "%s: unable to release LCB access, err %d\n",
5969 __func__, ret); 6162 __func__, ret);
5970 /* restore host access if the grant didn't work */ 6163 /* restore host access if the grant didn't work */
5971 set_host_lcb_access(dd); 6164 set_host_lcb_access(dd);
5972 goto done; 6165 goto done;
@@ -5998,19 +6191,26 @@ static void init_lcb_access(struct hfi1_devdata *dd)
5998static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data) 6191static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
5999{ 6192{
6000 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 6193 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
6001 DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK 6194 DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
6002 | (u64)return_code << DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT 6195 (u64)return_code <<
6003 | (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT); 6196 DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
6197 (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
6004} 6198}
6005 6199
6006/* 6200/*
6007 * Handle requests from the 8051. 6201 * Handle host requests from the 8051.
6202 *
6203 * This is a work-queue function outside of the interrupt.
6008 */ 6204 */
6009static void handle_8051_request(struct hfi1_devdata *dd) 6205void handle_8051_request(struct work_struct *work)
6010{ 6206{
6207 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
6208 dc_host_req_work);
6209 struct hfi1_devdata *dd = ppd->dd;
6011 u64 reg; 6210 u64 reg;
6012 u16 data; 6211 u16 data = 0;
6013 u8 type; 6212 u8 type, i, lanes, *cache = ppd->qsfp_info.cache;
6213 u8 cdr_ctrl_byte = cache[QSFP_CDR_CTRL_BYTE_OFFS];
6014 6214
6015 reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1); 6215 reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
6016 if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0) 6216 if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
@@ -6031,12 +6231,46 @@ static void handle_8051_request(struct hfi1_devdata *dd)
6031 case HREQ_READ_CONFIG: 6231 case HREQ_READ_CONFIG:
6032 case HREQ_SET_TX_EQ_ABS: 6232 case HREQ_SET_TX_EQ_ABS:
6033 case HREQ_SET_TX_EQ_REL: 6233 case HREQ_SET_TX_EQ_REL:
6034 case HREQ_ENABLE:
6035 dd_dev_info(dd, "8051 request: request 0x%x not supported\n", 6234 dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
6036 type); 6235 type);
6037 hreq_response(dd, HREQ_NOT_SUPPORTED, 0); 6236 hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
6038 break; 6237 break;
6039 6238
6239 case HREQ_ENABLE:
6240 lanes = data & 0xF;
6241 for (i = 0; lanes; lanes >>= 1, i++) {
6242 if (!(lanes & 1))
6243 continue;
6244 if (data & 0x200) {
6245 /* enable TX CDR */
6246 if (cache[QSFP_MOD_PWR_OFFS] & 0x8 &&
6247 cache[QSFP_CDR_INFO_OFFS] & 0x80)
6248 cdr_ctrl_byte |= (1 << (i + 4));
6249 } else {
6250 /* disable TX CDR */
6251 if (cache[QSFP_MOD_PWR_OFFS] & 0x8 &&
6252 cache[QSFP_CDR_INFO_OFFS] & 0x80)
6253 cdr_ctrl_byte &= ~(1 << (i + 4));
6254 }
6255
6256 if (data & 0x800) {
6257 /* enable RX CDR */
6258 if (cache[QSFP_MOD_PWR_OFFS] & 0x4 &&
6259 cache[QSFP_CDR_INFO_OFFS] & 0x40)
6260 cdr_ctrl_byte |= (1 << i);
6261 } else {
6262 /* disable RX CDR */
6263 if (cache[QSFP_MOD_PWR_OFFS] & 0x4 &&
6264 cache[QSFP_CDR_INFO_OFFS] & 0x40)
6265 cdr_ctrl_byte &= ~(1 << i);
6266 }
6267 }
6268 one_qsfp_write(ppd, dd->hfi1_id, QSFP_CDR_CTRL_BYTE_OFFS,
6269 &cdr_ctrl_byte, 1);
6270 hreq_response(dd, HREQ_SUCCESS, data);
6271 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
6272 break;
6273
6040 case HREQ_CONFIG_DONE: 6274 case HREQ_CONFIG_DONE:
6041 hreq_response(dd, HREQ_SUCCESS, 0); 6275 hreq_response(dd, HREQ_SUCCESS, 0);
6042 break; 6276 break;
@@ -6056,11 +6290,11 @@ static void write_global_credit(struct hfi1_devdata *dd,
6056 u8 vau, u16 total, u16 shared) 6290 u8 vau, u16 total, u16 shared)
6057{ 6291{
6058 write_csr(dd, SEND_CM_GLOBAL_CREDIT, 6292 write_csr(dd, SEND_CM_GLOBAL_CREDIT,
6059 ((u64)total 6293 ((u64)total <<
6060 << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT) 6294 SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT) |
6061 | ((u64)shared 6295 ((u64)shared <<
6062 << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT) 6296 SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT) |
6063 | ((u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT)); 6297 ((u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT));
6064} 6298}
6065 6299
6066/* 6300/*
@@ -6097,7 +6331,7 @@ void reset_link_credits(struct hfi1_devdata *dd)
6097 6331
6098 /* remove all previous VL credit limits */ 6332 /* remove all previous VL credit limits */
6099 for (i = 0; i < TXE_NUM_DATA_VL; i++) 6333 for (i = 0; i < TXE_NUM_DATA_VL; i++)
6100 write_csr(dd, SEND_CM_CREDIT_VL + (8*i), 0); 6334 write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
6101 write_csr(dd, SEND_CM_CREDIT_VL15, 0); 6335 write_csr(dd, SEND_CM_CREDIT_VL15, 0);
6102 write_global_credit(dd, 0, 0, 0); 6336 write_global_credit(dd, 0, 0, 0);
6103 /* reset the CM block */ 6337 /* reset the CM block */
@@ -6139,15 +6373,14 @@ static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
6139 write_csr(dd, DC_LCB_CFG_RUN, 0); 6373 write_csr(dd, DC_LCB_CFG_RUN, 0);
6140 /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */ 6374 /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
6141 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 6375 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
6142 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT); 6376 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
6143 /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */ 6377 /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
6144 dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN); 6378 dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
6145 reg = read_csr(dd, DCC_CFG_RESET); 6379 reg = read_csr(dd, DCC_CFG_RESET);
6146 write_csr(dd, DCC_CFG_RESET, 6380 write_csr(dd, DCC_CFG_RESET, reg |
6147 reg 6381 (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT) |
6148 | (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT) 6382 (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT));
6149 | (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT)); 6383 (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
6150 (void) read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
6151 if (!abort) { 6384 if (!abort) {
6152 udelay(1); /* must hold for the longer of 16cclks or 20ns */ 6385 udelay(1); /* must hold for the longer of 16cclks or 20ns */
6153 write_csr(dd, DCC_CFG_RESET, reg); 6386 write_csr(dd, DCC_CFG_RESET, reg);
@@ -6176,14 +6409,18 @@ static void dc_shutdown(struct hfi1_devdata *dd)
6176 spin_unlock_irqrestore(&dd->dc8051_lock, flags); 6409 spin_unlock_irqrestore(&dd->dc8051_lock, flags);
6177 /* Shutdown the LCB */ 6410 /* Shutdown the LCB */
6178 lcb_shutdown(dd, 1); 6411 lcb_shutdown(dd, 1);
6179 /* Going to OFFLINE would have causes the 8051 to put the 6412 /*
6413 * Going to OFFLINE would have causes the 8051 to put the
6180 * SerDes into reset already. Just need to shut down the 8051, 6414 * SerDes into reset already. Just need to shut down the 8051,
6181 * itself. */ 6415 * itself.
6416 */
6182 write_csr(dd, DC_DC8051_CFG_RST, 0x1); 6417 write_csr(dd, DC_DC8051_CFG_RST, 0x1);
6183} 6418}
6184 6419
6185/* Calling this after the DC has been brought out of reset should not 6420/*
6186 * do any damage. */ 6421 * Calling this after the DC has been brought out of reset should not
6422 * do any damage.
6423 */
6187static void dc_start(struct hfi1_devdata *dd) 6424static void dc_start(struct hfi1_devdata *dd)
6188{ 6425{
6189 unsigned long flags; 6426 unsigned long flags;
@@ -6199,7 +6436,7 @@ static void dc_start(struct hfi1_devdata *dd)
6199 ret = wait_fm_ready(dd, TIMEOUT_8051_START); 6436 ret = wait_fm_ready(dd, TIMEOUT_8051_START);
6200 if (ret) { 6437 if (ret) {
6201 dd_dev_err(dd, "%s: timeout starting 8051 firmware\n", 6438 dd_dev_err(dd, "%s: timeout starting 8051 firmware\n",
6202 __func__); 6439 __func__);
6203 } 6440 }
6204 /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */ 6441 /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
6205 write_csr(dd, DCC_CFG_RESET, 0x10); 6442 write_csr(dd, DCC_CFG_RESET, 0x10);
@@ -6292,7 +6529,7 @@ static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
6292 write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr); 6529 write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
6293 /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */ 6530 /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
6294 write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK, 6531 write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
6295 DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK); 6532 DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
6296 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr); 6533 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
6297} 6534}
6298 6535
@@ -6309,8 +6546,10 @@ void handle_sma_message(struct work_struct *work)
6309 u64 msg; 6546 u64 msg;
6310 int ret; 6547 int ret;
6311 6548
6312 /* msg is bytes 1-4 of the 40-bit idle message - the command code 6549 /*
6313 is stripped off */ 6550 * msg is bytes 1-4 of the 40-bit idle message - the command code
6551 * is stripped off
6552 */
6314 ret = read_idle_sma(dd, &msg); 6553 ret = read_idle_sma(dd, &msg);
6315 if (ret) 6554 if (ret)
6316 return; 6555 return;
@@ -6336,8 +6575,8 @@ void handle_sma_message(struct work_struct *work)
6336 * 6575 *
6337 * Can activate the node. Discard otherwise. 6576 * Can activate the node. Discard otherwise.
6338 */ 6577 */
6339 if (ppd->host_link_state == HLS_UP_ARMED 6578 if (ppd->host_link_state == HLS_UP_ARMED &&
6340 && ppd->is_active_optimize_enabled) { 6579 ppd->is_active_optimize_enabled) {
6341 ppd->neighbor_normal = 1; 6580 ppd->neighbor_normal = 1;
6342 ret = set_link_state(ppd, HLS_UP_ACTIVE); 6581 ret = set_link_state(ppd, HLS_UP_ACTIVE);
6343 if (ret) 6582 if (ret)
@@ -6349,8 +6588,8 @@ void handle_sma_message(struct work_struct *work)
6349 break; 6588 break;
6350 default: 6589 default:
6351 dd_dev_err(dd, 6590 dd_dev_err(dd,
6352 "%s: received unexpected SMA idle message 0x%llx\n", 6591 "%s: received unexpected SMA idle message 0x%llx\n",
6353 __func__, msg); 6592 __func__, msg);
6354 break; 6593 break;
6355 } 6594 }
6356} 6595}
@@ -6442,10 +6681,9 @@ static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
6442 6681
6443 if (time_after(jiffies, timeout)) { 6682 if (time_after(jiffies, timeout)) {
6444 dd_dev_err(dd, 6683 dd_dev_err(dd,
6445 "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing", 6684 "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
6446 freeze ? "" : "un", 6685 freeze ? "" : "un", reg & ALL_FROZE,
6447 reg & ALL_FROZE, 6686 freeze ? ALL_FROZE : 0ull);
6448 freeze ? ALL_FROZE : 0ull);
6449 return; 6687 return;
6450 } 6688 }
6451 usleep_range(80, 120); 6689 usleep_range(80, 120);
@@ -6475,11 +6713,17 @@ static void rxe_freeze(struct hfi1_devdata *dd)
6475 */ 6713 */
6476static void rxe_kernel_unfreeze(struct hfi1_devdata *dd) 6714static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
6477{ 6715{
6716 u32 rcvmask;
6478 int i; 6717 int i;
6479 6718
6480 /* enable all kernel contexts */ 6719 /* enable all kernel contexts */
6481 for (i = 0; i < dd->n_krcv_queues; i++) 6720 for (i = 0; i < dd->n_krcv_queues; i++) {
6482 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_ENB, i); 6721 rcvmask = HFI1_RCVCTRL_CTXT_ENB;
6722 /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
6723 rcvmask |= HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, DMA_RTAIL) ?
6724 HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
6725 hfi1_rcvctrl(dd, rcvmask, i);
6726 }
6483 6727
6484 /* enable port */ 6728 /* enable port */
6485 add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK); 6729 add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
@@ -6564,7 +6808,7 @@ void handle_freeze(struct work_struct *work)
6564void handle_link_up(struct work_struct *work) 6808void handle_link_up(struct work_struct *work)
6565{ 6809{
6566 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata, 6810 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
6567 link_up_work); 6811 link_up_work);
6568 set_link_state(ppd, HLS_UP_INIT); 6812 set_link_state(ppd, HLS_UP_INIT);
6569 6813
6570 /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */ 6814 /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
@@ -6583,17 +6827,20 @@ void handle_link_up(struct work_struct *work)
6583 if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) { 6827 if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
6584 /* oops - current speed is not enabled, bounce */ 6828 /* oops - current speed is not enabled, bounce */
6585 dd_dev_err(ppd->dd, 6829 dd_dev_err(ppd->dd,
6586 "Link speed active 0x%x is outside enabled 0x%x, downing link\n", 6830 "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
6587 ppd->link_speed_active, ppd->link_speed_enabled); 6831 ppd->link_speed_active, ppd->link_speed_enabled);
6588 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0, 6832 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
6589 OPA_LINKDOWN_REASON_SPEED_POLICY); 6833 OPA_LINKDOWN_REASON_SPEED_POLICY);
6590 set_link_state(ppd, HLS_DN_OFFLINE); 6834 set_link_state(ppd, HLS_DN_OFFLINE);
6835 tune_serdes(ppd);
6591 start_link(ppd); 6836 start_link(ppd);
6592 } 6837 }
6593} 6838}
6594 6839
6595/* Several pieces of LNI information were cached for SMA in ppd. 6840/*
6596 * Reset these on link down */ 6841 * Several pieces of LNI information were cached for SMA in ppd.
6842 * Reset these on link down
6843 */
6597static void reset_neighbor_info(struct hfi1_pportdata *ppd) 6844static void reset_neighbor_info(struct hfi1_pportdata *ppd)
6598{ 6845{
6599 ppd->neighbor_guid = 0; 6846 ppd->neighbor_guid = 0;
@@ -6613,7 +6860,13 @@ void handle_link_down(struct work_struct *work)
6613 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata, 6860 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
6614 link_down_work); 6861 link_down_work);
6615 6862
6616 /* go offline first, then deal with reasons */ 6863 if ((ppd->host_link_state &
6864 (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
6865 ppd->port_type == PORT_TYPE_FIXED)
6866 ppd->offline_disabled_reason =
6867 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
6868
6869 /* Go offline first, then deal with reading/writing through 8051 */
6617 set_link_state(ppd, HLS_DN_OFFLINE); 6870 set_link_state(ppd, HLS_DN_OFFLINE);
6618 6871
6619 lcl_reason = 0; 6872 lcl_reason = 0;
@@ -6633,12 +6886,16 @@ void handle_link_down(struct work_struct *work)
6633 /* disable the port */ 6886 /* disable the port */
6634 clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK); 6887 clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
6635 6888
6636 /* If there is no cable attached, turn the DC off. Otherwise, 6889 /*
6637 * start the link bring up. */ 6890 * If there is no cable attached, turn the DC off. Otherwise,
6638 if (!qsfp_mod_present(ppd)) 6891 * start the link bring up.
6892 */
6893 if (!qsfp_mod_present(ppd)) {
6639 dc_shutdown(ppd->dd); 6894 dc_shutdown(ppd->dd);
6640 else 6895 } else {
6896 tune_serdes(ppd);
6641 start_link(ppd); 6897 start_link(ppd);
6898 }
6642} 6899}
6643 6900
6644void handle_link_bounce(struct work_struct *work) 6901void handle_link_bounce(struct work_struct *work)
@@ -6651,10 +6908,11 @@ void handle_link_bounce(struct work_struct *work)
6651 */ 6908 */
6652 if (ppd->host_link_state & HLS_UP) { 6909 if (ppd->host_link_state & HLS_UP) {
6653 set_link_state(ppd, HLS_DN_OFFLINE); 6910 set_link_state(ppd, HLS_DN_OFFLINE);
6911 tune_serdes(ppd);
6654 start_link(ppd); 6912 start_link(ppd);
6655 } else { 6913 } else {
6656 dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n", 6914 dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
6657 __func__, link_state_name(ppd->host_link_state)); 6915 __func__, link_state_name(ppd->host_link_state));
6658 } 6916 }
6659} 6917}
6660 6918
@@ -6751,7 +7009,7 @@ static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
6751 case 3: return OPA_LINK_WIDTH_3X; 7009 case 3: return OPA_LINK_WIDTH_3X;
6752 default: 7010 default:
6753 dd_dev_info(dd, "%s: invalid width %d, using 4\n", 7011 dd_dev_info(dd, "%s: invalid width %d, using 4\n",
6754 __func__, width); 7012 __func__, width);
6755 /* fall through */ 7013 /* fall through */
6756 case 4: return OPA_LINK_WIDTH_4X; 7014 case 4: return OPA_LINK_WIDTH_4X;
6757 } 7015 }
@@ -6763,6 +7021,7 @@ static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
6763static const u8 bit_counts[16] = { 7021static const u8 bit_counts[16] = {
6764 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 7022 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
6765}; 7023};
7024
6766static inline u8 nibble_to_count(u8 nibble) 7025static inline u8 nibble_to_count(u8 nibble)
6767{ 7026{
6768 return bit_counts[nibble & 0xf]; 7027 return bit_counts[nibble & 0xf];
@@ -6788,7 +7047,7 @@ static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
6788 7047
6789 /* read the active lanes */ 7048 /* read the active lanes */
6790 read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion, 7049 read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
6791 &rx_polarity_inversion, &max_rate); 7050 &rx_polarity_inversion, &max_rate);
6792 read_local_lni(dd, &enable_lane_rx); 7051 read_local_lni(dd, &enable_lane_rx);
6793 7052
6794 /* convert to counts */ 7053 /* convert to counts */
@@ -6800,8 +7059,8 @@ static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
6800 * handle_verify_cap(). The ASIC 8051 firmware does not correctly 7059 * handle_verify_cap(). The ASIC 8051 firmware does not correctly
6801 * set the max_rate field in handle_verify_cap until v0.19. 7060 * set the max_rate field in handle_verify_cap until v0.19.
6802 */ 7061 */
6803 if ((dd->icode == ICODE_RTL_SILICON) 7062 if ((dd->icode == ICODE_RTL_SILICON) &&
6804 && (dd->dc8051_ver < dc8051_ver(0, 19))) { 7063 (dd->dc8051_ver < dc8051_ver(0, 19))) {
6805 /* max_rate: 0 = 12.5G, 1 = 25G */ 7064 /* max_rate: 0 = 12.5G, 1 = 25G */
6806 switch (max_rate) { 7065 switch (max_rate) {
6807 case 0: 7066 case 0:
@@ -6809,8 +7068,8 @@ static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
6809 break; 7068 break;
6810 default: 7069 default:
6811 dd_dev_err(dd, 7070 dd_dev_err(dd,
6812 "%s: unexpected max rate %d, using 25Gb\n", 7071 "%s: unexpected max rate %d, using 25Gb\n",
6813 __func__, (int)max_rate); 7072 __func__, (int)max_rate);
6814 /* fall through */ 7073 /* fall through */
6815 case 1: 7074 case 1:
6816 dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G; 7075 dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
@@ -6819,8 +7078,8 @@ static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
6819 } 7078 }
6820 7079
6821 dd_dev_info(dd, 7080 dd_dev_info(dd,
6822 "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n", 7081 "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
6823 enable_lane_tx, tx, enable_lane_rx, rx); 7082 enable_lane_tx, tx, enable_lane_rx, rx);
6824 *tx_width = link_width_to_bits(dd, tx); 7083 *tx_width = link_width_to_bits(dd, tx);
6825 *rx_width = link_width_to_bits(dd, rx); 7084 *rx_width = link_width_to_bits(dd, rx);
6826} 7085}
@@ -6923,13 +7182,8 @@ void handle_verify_cap(struct work_struct *work)
6923 */ 7182 */
6924 7183
6925 read_vc_remote_phy(dd, &power_management, &continious); 7184 read_vc_remote_phy(dd, &power_management, &continious);
6926 read_vc_remote_fabric( 7185 read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
6927 dd, 7186 &partner_supported_crc);
6928 &vau,
6929 &z,
6930 &vcu,
6931 &vl15buf,
6932 &partner_supported_crc);
6933 read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths); 7187 read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
6934 read_remote_device_id(dd, &device_id, &device_rev); 7188 read_remote_device_id(dd, &device_id, &device_rev);
6935 /* 7189 /*
@@ -6940,19 +7194,16 @@ void handle_verify_cap(struct work_struct *work)
6940 /* print the active widths */ 7194 /* print the active widths */
6941 get_link_widths(dd, &active_tx, &active_rx); 7195 get_link_widths(dd, &active_tx, &active_rx);
6942 dd_dev_info(dd, 7196 dd_dev_info(dd,
6943 "Peer PHY: power management 0x%x, continuous updates 0x%x\n", 7197 "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
6944 (int)power_management, (int)continious); 7198 (int)power_management, (int)continious);
6945 dd_dev_info(dd, 7199 dd_dev_info(dd,
6946 "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n", 7200 "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
6947 (int)vau, 7201 (int)vau, (int)z, (int)vcu, (int)vl15buf,
6948 (int)z, 7202 (int)partner_supported_crc);
6949 (int)vcu,
6950 (int)vl15buf,
6951 (int)partner_supported_crc);
6952 dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n", 7203 dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
6953 (u32)remote_tx_rate, (u32)link_widths); 7204 (u32)remote_tx_rate, (u32)link_widths);
6954 dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n", 7205 dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
6955 (u32)device_id, (u32)device_rev); 7206 (u32)device_id, (u32)device_rev);
6956 /* 7207 /*
6957 * The peer vAU value just read is the peer receiver value. HFI does 7208 * The peer vAU value just read is the peer receiver value. HFI does
6958 * not support a transmit vAU of 0 (AU == 8). We advertised that 7209 * not support a transmit vAU of 0 (AU == 8). We advertised that
@@ -6987,10 +7238,10 @@ void handle_verify_cap(struct work_struct *work)
6987 reg = read_csr(dd, SEND_CM_CTRL); 7238 reg = read_csr(dd, SEND_CM_CTRL);
6988 if (crc_val == LCB_CRC_14B && crc_14b_sideband) { 7239 if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
6989 write_csr(dd, SEND_CM_CTRL, 7240 write_csr(dd, SEND_CM_CTRL,
6990 reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK); 7241 reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
6991 } else { 7242 } else {
6992 write_csr(dd, SEND_CM_CTRL, 7243 write_csr(dd, SEND_CM_CTRL,
6993 reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK); 7244 reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
6994 } 7245 }
6995 7246
6996 ppd->link_speed_active = 0; /* invalid value */ 7247 ppd->link_speed_active = 0; /* invalid value */
@@ -7015,7 +7266,7 @@ void handle_verify_cap(struct work_struct *work)
7015 } 7266 }
7016 if (ppd->link_speed_active == 0) { 7267 if (ppd->link_speed_active == 0) {
7017 dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n", 7268 dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
7018 __func__, (int)remote_tx_rate); 7269 __func__, (int)remote_tx_rate);
7019 ppd->link_speed_active = OPA_LINK_SPEED_25G; 7270 ppd->link_speed_active = OPA_LINK_SPEED_25G;
7020 } 7271 }
7021 7272
@@ -7071,9 +7322,9 @@ void handle_verify_cap(struct work_struct *work)
7071 read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) & 7322 read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) &
7072 DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK; 7323 DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK;
7073 dd_dev_info(dd, 7324 dd_dev_info(dd,
7074 "Neighbor Guid: %llx Neighbor type %d MgmtAllowed %d FM security bypass %d\n", 7325 "Neighbor Guid: %llx Neighbor type %d MgmtAllowed %d FM security bypass %d\n",
7075 ppd->neighbor_guid, ppd->neighbor_type, 7326 ppd->neighbor_guid, ppd->neighbor_type,
7076 ppd->mgmt_allowed, ppd->neighbor_fm_security); 7327 ppd->mgmt_allowed, ppd->neighbor_fm_security);
7077 if (ppd->mgmt_allowed) 7328 if (ppd->mgmt_allowed)
7078 add_full_mgmt_pkey(ppd); 7329 add_full_mgmt_pkey(ppd);
7079 7330
@@ -7127,28 +7378,27 @@ retry:
7127 7378
7128 /* bounce if not at starting active width */ 7379 /* bounce if not at starting active width */
7129 if ((ppd->link_width_active != 7380 if ((ppd->link_width_active !=
7130 ppd->link_width_downgrade_tx_active) 7381 ppd->link_width_downgrade_tx_active) ||
7131 || (ppd->link_width_active != 7382 (ppd->link_width_active !=
7132 ppd->link_width_downgrade_rx_active)) { 7383 ppd->link_width_downgrade_rx_active)) {
7133 dd_dev_err(ppd->dd, 7384 dd_dev_err(ppd->dd,
7134 "Link downgrade is disabled and link has downgraded, downing link\n"); 7385 "Link downgrade is disabled and link has downgraded, downing link\n");
7135 dd_dev_err(ppd->dd, 7386 dd_dev_err(ppd->dd,
7136 " original 0x%x, tx active 0x%x, rx active 0x%x\n", 7387 " original 0x%x, tx active 0x%x, rx active 0x%x\n",
7137 ppd->link_width_active, 7388 ppd->link_width_active,
7138 ppd->link_width_downgrade_tx_active, 7389 ppd->link_width_downgrade_tx_active,
7139 ppd->link_width_downgrade_rx_active); 7390 ppd->link_width_downgrade_rx_active);
7140 do_bounce = 1; 7391 do_bounce = 1;
7141 } 7392 }
7142 } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 7393 } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
7143 || (lwde & ppd->link_width_downgrade_rx_active) == 0) { 7394 (lwde & ppd->link_width_downgrade_rx_active) == 0) {
7144 /* Tx or Rx is outside the enabled policy */ 7395 /* Tx or Rx is outside the enabled policy */
7145 dd_dev_err(ppd->dd, 7396 dd_dev_err(ppd->dd,
7146 "Link is outside of downgrade allowed, downing link\n"); 7397 "Link is outside of downgrade allowed, downing link\n");
7147 dd_dev_err(ppd->dd, 7398 dd_dev_err(ppd->dd,
7148 " enabled 0x%x, tx active 0x%x, rx active 0x%x\n", 7399 " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
7149 lwde, 7400 lwde, ppd->link_width_downgrade_tx_active,
7150 ppd->link_width_downgrade_tx_active, 7401 ppd->link_width_downgrade_rx_active);
7151 ppd->link_width_downgrade_rx_active);
7152 do_bounce = 1; 7402 do_bounce = 1;
7153 } 7403 }
7154 7404
@@ -7157,8 +7407,9 @@ done:
7157 7407
7158 if (do_bounce) { 7408 if (do_bounce) {
7159 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0, 7409 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
7160 OPA_LINKDOWN_REASON_WIDTH_POLICY); 7410 OPA_LINKDOWN_REASON_WIDTH_POLICY);
7161 set_link_state(ppd, HLS_DN_OFFLINE); 7411 set_link_state(ppd, HLS_DN_OFFLINE);
7412 tune_serdes(ppd);
7162 start_link(ppd); 7413 start_link(ppd);
7163 } 7414 }
7164} 7415}
@@ -7239,9 +7490,10 @@ static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
7239 & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) { 7490 & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
7240 queue_link_down = 1; 7491 queue_link_down = 1;
7241 dd_dev_info(dd, "Link error: %s\n", 7492 dd_dev_info(dd, "Link error: %s\n",
7242 dc8051_info_err_string(buf, 7493 dc8051_info_err_string(buf,
7243 sizeof(buf), 7494 sizeof(buf),
7244 err & FAILED_LNI)); 7495 err &
7496 FAILED_LNI));
7245 } 7497 }
7246 err &= ~(u64)FAILED_LNI; 7498 err &= ~(u64)FAILED_LNI;
7247 } 7499 }
@@ -7253,7 +7505,8 @@ static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
7253 if (err) { 7505 if (err) {
7254 /* report remaining errors, but do not do anything */ 7506 /* report remaining errors, but do not do anything */
7255 dd_dev_err(dd, "8051 info error: %s\n", 7507 dd_dev_err(dd, "8051 info error: %s\n",
7256 dc8051_info_err_string(buf, sizeof(buf), err)); 7508 dc8051_info_err_string(buf, sizeof(buf),
7509 err));
7257 } 7510 }
7258 7511
7259 /* 7512 /*
@@ -7281,7 +7534,7 @@ static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
7281 host_msg &= ~(u64)LINKUP_ACHIEVED; 7534 host_msg &= ~(u64)LINKUP_ACHIEVED;
7282 } 7535 }
7283 if (host_msg & EXT_DEVICE_CFG_REQ) { 7536 if (host_msg & EXT_DEVICE_CFG_REQ) {
7284 handle_8051_request(dd); 7537 queue_work(ppd->hfi1_wq, &ppd->dc_host_req_work);
7285 host_msg &= ~(u64)EXT_DEVICE_CFG_REQ; 7538 host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
7286 } 7539 }
7287 if (host_msg & VERIFY_CAP_FRAME) { 7540 if (host_msg & VERIFY_CAP_FRAME) {
@@ -7306,8 +7559,9 @@ static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
7306 if (host_msg) { 7559 if (host_msg) {
7307 /* report remaining messages, but do not do anything */ 7560 /* report remaining messages, but do not do anything */
7308 dd_dev_info(dd, "8051 info host message: %s\n", 7561 dd_dev_info(dd, "8051 info host message: %s\n",
7309 dc8051_info_host_msg_string(buf, sizeof(buf), 7562 dc8051_info_host_msg_string(buf,
7310 host_msg)); 7563 sizeof(buf),
7564 host_msg));
7311 } 7565 }
7312 7566
7313 reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK; 7567 reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
@@ -7320,25 +7574,27 @@ static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
7320 */ 7574 */
7321 dd_dev_err(dd, "Lost 8051 heartbeat\n"); 7575 dd_dev_err(dd, "Lost 8051 heartbeat\n");
7322 write_csr(dd, DC_DC8051_ERR_EN, 7576 write_csr(dd, DC_DC8051_ERR_EN,
7323 read_csr(dd, DC_DC8051_ERR_EN) 7577 read_csr(dd, DC_DC8051_ERR_EN) &
7324 & ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK); 7578 ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
7325 7579
7326 reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK; 7580 reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
7327 } 7581 }
7328 if (reg) { 7582 if (reg) {
7329 /* report the error, but do not do anything */ 7583 /* report the error, but do not do anything */
7330 dd_dev_err(dd, "8051 error: %s\n", 7584 dd_dev_err(dd, "8051 error: %s\n",
7331 dc8051_err_string(buf, sizeof(buf), reg)); 7585 dc8051_err_string(buf, sizeof(buf), reg));
7332 } 7586 }
7333 7587
7334 if (queue_link_down) { 7588 if (queue_link_down) {
7335 /* if the link is already going down or disabled, do not 7589 /*
7336 * queue another */ 7590 * if the link is already going down or disabled, do not
7337 if ((ppd->host_link_state 7591 * queue another
7338 & (HLS_GOING_OFFLINE|HLS_LINK_COOLDOWN)) 7592 */
7339 || ppd->link_enabled == 0) { 7593 if ((ppd->host_link_state &
7594 (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
7595 ppd->link_enabled == 0) {
7340 dd_dev_info(dd, "%s: not queuing link down\n", 7596 dd_dev_info(dd, "%s: not queuing link down\n",
7341 __func__); 7597 __func__);
7342 } else { 7598 } else {
7343 queue_work(ppd->hfi1_wq, &ppd->link_down_work); 7599 queue_work(ppd->hfi1_wq, &ppd->link_down_work);
7344 } 7600 }
@@ -7480,8 +7736,10 @@ static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
7480 /* set status bit */ 7736 /* set status bit */
7481 dd->err_info_rcvport.status_and_code |= 7737 dd->err_info_rcvport.status_and_code |=
7482 OPA_EI_STATUS_SMASK; 7738 OPA_EI_STATUS_SMASK;
7483 /* save first 2 flits in the packet that caused 7739 /*
7484 * the error */ 7740 * save first 2 flits in the packet that caused
7741 * the error
7742 */
7485 dd->err_info_rcvport.packet_flit1 = hdr0; 7743 dd->err_info_rcvport.packet_flit1 = hdr0;
7486 dd->err_info_rcvport.packet_flit2 = hdr1; 7744 dd->err_info_rcvport.packet_flit2 = hdr1;
7487 } 7745 }
@@ -7514,7 +7772,7 @@ static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
7514 /* just report this */ 7772 /* just report this */
7515 dd_dev_info(dd, "DCC Error: PortRcv error: %s\n", extra); 7773 dd_dev_info(dd, "DCC Error: PortRcv error: %s\n", extra);
7516 dd_dev_info(dd, " hdr0 0x%llx, hdr1 0x%llx\n", 7774 dd_dev_info(dd, " hdr0 0x%llx, hdr1 0x%llx\n",
7517 hdr0, hdr1); 7775 hdr0, hdr1);
7518 7776
7519 reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK; 7777 reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
7520 } 7778 }
@@ -7533,7 +7791,7 @@ static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
7533 /* report any remaining errors */ 7791 /* report any remaining errors */
7534 if (reg) 7792 if (reg)
7535 dd_dev_info(dd, "DCC Error: %s\n", 7793 dd_dev_info(dd, "DCC Error: %s\n",
7536 dcc_err_string(buf, sizeof(buf), reg)); 7794 dcc_err_string(buf, sizeof(buf), reg));
7537 7795
7538 if (lcl_reason == 0) 7796 if (lcl_reason == 0)
7539 lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN; 7797 lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
@@ -7550,7 +7808,7 @@ static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
7550 char buf[96]; 7808 char buf[96];
7551 7809
7552 dd_dev_info(dd, "LCB Error: %s\n", 7810 dd_dev_info(dd, "LCB Error: %s\n",
7553 lcb_err_string(buf, sizeof(buf), reg)); 7811 lcb_err_string(buf, sizeof(buf), reg));
7554} 7812}
7555 7813
7556/* 7814/*
@@ -7640,7 +7898,7 @@ static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
7640 err_detail = "out of range"; 7898 err_detail = "out of range";
7641 } 7899 }
7642 dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n", 7900 dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
7643 err_detail, source); 7901 err_detail, source);
7644} 7902}
7645 7903
7646/* 7904/*
@@ -7666,7 +7924,7 @@ static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
7666 err_detail = "out of range"; 7924 err_detail = "out of range";
7667 } 7925 }
7668 dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n", 7926 dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
7669 err_detail, source); 7927 err_detail, source);
7670} 7928}
7671 7929
7672/* 7930/*
@@ -7677,12 +7935,14 @@ static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
7677 char name[64]; 7935 char name[64];
7678 7936
7679 dd_dev_err(dd, "unexpected %s interrupt\n", 7937 dd_dev_err(dd, "unexpected %s interrupt\n",
7680 is_reserved_name(name, sizeof(name), source)); 7938 is_reserved_name(name, sizeof(name), source));
7681} 7939}
7682 7940
7683static const struct is_table is_table[] = { 7941static const struct is_table is_table[] = {
7684/* start end 7942/*
7685 name func interrupt func */ 7943 * start end
7944 * name func interrupt func
7945 */
7686{ IS_GENERAL_ERR_START, IS_GENERAL_ERR_END, 7946{ IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
7687 is_misc_err_name, is_misc_err_int }, 7947 is_misc_err_name, is_misc_err_int },
7688{ IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END, 7948{ IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
@@ -7753,7 +8013,7 @@ static irqreturn_t general_interrupt(int irq, void *data)
7753 8013
7754 /* phase 2: call the appropriate handler */ 8014 /* phase 2: call the appropriate handler */
7755 for_each_set_bit(bit, (unsigned long *)&regs[0], 8015 for_each_set_bit(bit, (unsigned long *)&regs[0],
7756 CCE_NUM_INT_CSRS*64) { 8016 CCE_NUM_INT_CSRS * 64) {
7757 is_interrupt(dd, bit); 8017 is_interrupt(dd, bit);
7758 } 8018 }
7759 8019
@@ -7776,27 +8036,27 @@ static irqreturn_t sdma_interrupt(int irq, void *data)
7776 8036
7777 /* This read_csr is really bad in the hot path */ 8037 /* This read_csr is really bad in the hot path */
7778 status = read_csr(dd, 8038 status = read_csr(dd,
7779 CCE_INT_STATUS + (8*(IS_SDMA_START/64))) 8039 CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
7780 & sde->imask; 8040 & sde->imask;
7781 if (likely(status)) { 8041 if (likely(status)) {
7782 /* clear the interrupt(s) */ 8042 /* clear the interrupt(s) */
7783 write_csr(dd, 8043 write_csr(dd,
7784 CCE_INT_CLEAR + (8*(IS_SDMA_START/64)), 8044 CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
7785 status); 8045 status);
7786 8046
7787 /* handle the interrupt(s) */ 8047 /* handle the interrupt(s) */
7788 sdma_engine_interrupt(sde, status); 8048 sdma_engine_interrupt(sde, status);
7789 } else 8049 } else
7790 dd_dev_err(dd, "SDMA engine %u interrupt, but no status bits set\n", 8050 dd_dev_err(dd, "SDMA engine %u interrupt, but no status bits set\n",
7791 sde->this_idx); 8051 sde->this_idx);
7792 8052
7793 return IRQ_HANDLED; 8053 return IRQ_HANDLED;
7794} 8054}
7795 8055
7796/* 8056/*
7797 * Clear the receive interrupt, forcing the write and making sure 8057 * Clear the receive interrupt. Use a read of the interrupt clear CSR
7798 * we have data from the chip, pushing everything in front of it 8058 * to insure that the write completed. This does NOT guarantee that
7799 * back to the host. 8059 * queued DMA writes to memory from the chip are pushed.
7800 */ 8060 */
7801static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd) 8061static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
7802{ 8062{
@@ -7810,27 +8070,45 @@ static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
7810} 8070}
7811 8071
7812/* force the receive interrupt */ 8072/* force the receive interrupt */
7813static inline void force_recv_intr(struct hfi1_ctxtdata *rcd) 8073void force_recv_intr(struct hfi1_ctxtdata *rcd)
7814{ 8074{
7815 write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask); 8075 write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
7816} 8076}
7817 8077
7818/* return non-zero if a packet is present */ 8078/*
8079 * Return non-zero if a packet is present.
8080 *
8081 * This routine is called when rechecking for packets after the RcvAvail
8082 * interrupt has been cleared down. First, do a quick check of memory for
8083 * a packet present. If not found, use an expensive CSR read of the context
8084 * tail to determine the actual tail. The CSR read is necessary because there
8085 * is no method to push pending DMAs to memory other than an interrupt and we
8086 * are trying to determine if we need to force an interrupt.
8087 */
7819static inline int check_packet_present(struct hfi1_ctxtdata *rcd) 8088static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
7820{ 8089{
8090 u32 tail;
8091 int present;
8092
7821 if (!HFI1_CAP_IS_KSET(DMA_RTAIL)) 8093 if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
7822 return (rcd->seq_cnt == 8094 present = (rcd->seq_cnt ==
7823 rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd)))); 8095 rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
8096 else /* is RDMA rtail */
8097 present = (rcd->head != get_rcvhdrtail(rcd));
8098
8099 if (present)
8100 return 1;
7824 8101
7825 /* else is RDMA rtail */ 8102 /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
7826 return (rcd->head != get_rcvhdrtail(rcd)); 8103 tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
8104 return rcd->head != tail;
7827} 8105}
7828 8106
7829/* 8107/*
7830 * Receive packet IRQ handler. This routine expects to be on its own IRQ. 8108 * Receive packet IRQ handler. This routine expects to be on its own IRQ.
7831 * This routine will try to handle packets immediately (latency), but if 8109 * This routine will try to handle packets immediately (latency), but if
7832 * it finds too many, it will invoke the thread handler (bandwitdh). The 8110 * it finds too many, it will invoke the thread handler (bandwitdh). The
7833 * chip receive interupt is *not* cleared down until this or the thread (if 8111 * chip receive interrupt is *not* cleared down until this or the thread (if
7834 * invoked) is finished. The intent is to avoid extra interrupts while we 8112 * invoked) is finished. The intent is to avoid extra interrupts while we
7835 * are processing packets anyway. 8113 * are processing packets anyway.
7836 */ 8114 */
@@ -7843,6 +8121,7 @@ static irqreturn_t receive_context_interrupt(int irq, void *data)
7843 8121
7844 trace_hfi1_receive_interrupt(dd, rcd->ctxt); 8122 trace_hfi1_receive_interrupt(dd, rcd->ctxt);
7845 this_cpu_inc(*dd->int_counter); 8123 this_cpu_inc(*dd->int_counter);
8124 aspm_ctx_disable(rcd);
7846 8125
7847 /* receive interrupt remains blocked while processing packets */ 8126 /* receive interrupt remains blocked while processing packets */
7848 disposition = rcd->do_interrupt(rcd, 0); 8127 disposition = rcd->do_interrupt(rcd, 0);
@@ -7909,7 +8188,7 @@ u32 read_physical_state(struct hfi1_devdata *dd)
7909 & DC_DC8051_STS_CUR_STATE_PORT_MASK; 8188 & DC_DC8051_STS_CUR_STATE_PORT_MASK;
7910} 8189}
7911 8190
7912static u32 read_logical_state(struct hfi1_devdata *dd) 8191u32 read_logical_state(struct hfi1_devdata *dd)
7913{ 8192{
7914 u64 reg; 8193 u64 reg;
7915 8194
@@ -8157,8 +8436,8 @@ static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
8157 return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL); 8436 return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
8158} 8437}
8159 8438
8160static int load_8051_config(struct hfi1_devdata *dd, u8 field_id, 8439int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
8161 u8 lane_id, u32 config_data) 8440 u8 lane_id, u32 config_data)
8162{ 8441{
8163 u64 data; 8442 u64 data;
8164 int ret; 8443 int ret;
@@ -8169,8 +8448,8 @@ static int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
8169 ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL); 8448 ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
8170 if (ret != HCMD_SUCCESS) { 8449 if (ret != HCMD_SUCCESS) {
8171 dd_dev_err(dd, 8450 dd_dev_err(dd,
8172 "load 8051 config: field id %d, lane %d, err %d\n", 8451 "load 8051 config: field id %d, lane %d, err %d\n",
8173 (int)field_id, (int)lane_id, ret); 8452 (int)field_id, (int)lane_id, ret);
8174 } 8453 }
8175 return ret; 8454 return ret;
8176} 8455}
@@ -8180,8 +8459,8 @@ static int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
8180 * set the result, even on error. 8459 * set the result, even on error.
8181 * Return 0 on success, -errno on failure 8460 * Return 0 on success, -errno on failure
8182 */ 8461 */
8183static int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id, 8462int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
8184 u32 *result) 8463 u32 *result)
8185{ 8464{
8186 u64 big_data; 8465 u64 big_data;
8187 u32 addr; 8466 u32 addr;
@@ -8207,7 +8486,7 @@ static int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
8207 } else { 8486 } else {
8208 *result = 0; 8487 *result = 0;
8209 dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n", 8488 dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
8210 __func__, lane_id, field_id); 8489 __func__, lane_id, field_id);
8211 } 8490 }
8212 8491
8213 return ret; 8492 return ret;
@@ -8244,7 +8523,7 @@ static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
8244 u32 frame; 8523 u32 frame;
8245 8524
8246 read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG, 8525 read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
8247 &frame); 8526 &frame);
8248 *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK; 8527 *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
8249 *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK; 8528 *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
8250 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK; 8529 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
@@ -8326,7 +8605,7 @@ static void read_vc_remote_link_width(struct hfi1_devdata *dd,
8326 u32 frame; 8605 u32 frame;
8327 8606
8328 read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG, 8607 read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
8329 &frame); 8608 &frame);
8330 *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT) 8609 *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
8331 & REMOTE_TX_RATE_MASK; 8610 & REMOTE_TX_RATE_MASK;
8332 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK; 8611 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
@@ -8366,7 +8645,7 @@ void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
8366 *link_quality = 0; 8645 *link_quality = 0;
8367 if (dd->pport->host_link_state & HLS_UP) { 8646 if (dd->pport->host_link_state & HLS_UP) {
8368 ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, 8647 ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
8369 &frame); 8648 &frame);
8370 if (ret == 0) 8649 if (ret == 0)
8371 *link_quality = (frame >> LINK_QUALITY_SHIFT) 8650 *link_quality = (frame >> LINK_QUALITY_SHIFT)
8372 & LINK_QUALITY_MASK; 8651 & LINK_QUALITY_MASK;
@@ -8426,10 +8705,9 @@ static void check_fabric_firmware_versions(struct hfi1_devdata *dd)
8426 for (lane = 0; lane < 4; lane++) { 8705 for (lane = 0; lane < 4; lane++) {
8427 ret = read_8051_config(dd, SPICO_FW_VERSION, lane, &frame); 8706 ret = read_8051_config(dd, SPICO_FW_VERSION, lane, &frame);
8428 if (ret) { 8707 if (ret) {
8429 dd_dev_err( 8708 dd_dev_err(dd,
8430 dd, 8709 "Unable to read lane %d firmware details\n",
8431 "Unable to read lane %d firmware details\n", 8710 lane);
8432 lane);
8433 continue; 8711 continue;
8434 } 8712 }
8435 version = (frame >> SPICO_ROM_VERSION_SHIFT) 8713 version = (frame >> SPICO_ROM_VERSION_SHIFT)
@@ -8437,8 +8715,8 @@ static void check_fabric_firmware_versions(struct hfi1_devdata *dd)
8437 prod_id = (frame >> SPICO_ROM_PROD_ID_SHIFT) 8715 prod_id = (frame >> SPICO_ROM_PROD_ID_SHIFT)
8438 & SPICO_ROM_PROD_ID_MASK; 8716 & SPICO_ROM_PROD_ID_MASK;
8439 dd_dev_info(dd, 8717 dd_dev_info(dd,
8440 "Lane %d firmware: version 0x%04x, prod_id 0x%04x\n", 8718 "Lane %d firmware: version 0x%04x, prod_id 0x%04x\n",
8441 lane, version, prod_id); 8719 lane, version, prod_id);
8442 } 8720 }
8443} 8721}
8444 8722
@@ -8451,11 +8729,10 @@ static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
8451{ 8729{
8452 int ret; 8730 int ret;
8453 8731
8454 ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, 8732 ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
8455 type, data_out);
8456 if (ret != HCMD_SUCCESS) { 8733 if (ret != HCMD_SUCCESS) {
8457 dd_dev_err(dd, "read idle message: type %d, err %d\n", 8734 dd_dev_err(dd, "read idle message: type %d, err %d\n",
8458 (u32)type, ret); 8735 (u32)type, ret);
8459 return -EINVAL; 8736 return -EINVAL;
8460 } 8737 }
8461 dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out); 8738 dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
@@ -8472,8 +8749,8 @@ static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
8472 */ 8749 */
8473static int read_idle_sma(struct hfi1_devdata *dd, u64 *data) 8750static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
8474{ 8751{
8475 return read_idle_message(dd, 8752 return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
8476 (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT, data); 8753 data);
8477} 8754}
8478 8755
8479/* 8756/*
@@ -8489,7 +8766,7 @@ static int send_idle_message(struct hfi1_devdata *dd, u64 data)
8489 ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL); 8766 ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
8490 if (ret != HCMD_SUCCESS) { 8767 if (ret != HCMD_SUCCESS) {
8491 dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n", 8768 dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
8492 data, ret); 8769 data, ret);
8493 return -EINVAL; 8770 return -EINVAL;
8494 } 8771 }
8495 return 0; 8772 return 0;
@@ -8504,8 +8781,8 @@ int send_idle_sma(struct hfi1_devdata *dd, u64 message)
8504{ 8781{
8505 u64 data; 8782 u64 data;
8506 8783
8507 data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) 8784 data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
8508 | ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT); 8785 ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
8509 return send_idle_message(dd, data); 8786 return send_idle_message(dd, data);
8510} 8787}
8511 8788
@@ -8527,7 +8804,7 @@ static int do_quick_linkup(struct hfi1_devdata *dd)
8527 /* LCB_CFG_LOOPBACK.VAL = 2 */ 8804 /* LCB_CFG_LOOPBACK.VAL = 2 */
8528 /* LCB_CFG_LANE_WIDTH.VAL = 0 */ 8805 /* LCB_CFG_LANE_WIDTH.VAL = 0 */
8529 write_csr(dd, DC_LCB_CFG_LOOPBACK, 8806 write_csr(dd, DC_LCB_CFG_LOOPBACK,
8530 IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT); 8807 IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
8531 write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0); 8808 write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
8532 } 8809 }
8533 8810
@@ -8539,25 +8816,24 @@ static int do_quick_linkup(struct hfi1_devdata *dd)
8539 if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) { 8816 if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
8540 /* LCB_CFG_RUN.EN = 1 */ 8817 /* LCB_CFG_RUN.EN = 1 */
8541 write_csr(dd, DC_LCB_CFG_RUN, 8818 write_csr(dd, DC_LCB_CFG_RUN,
8542 1ull << DC_LCB_CFG_RUN_EN_SHIFT); 8819 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
8543 8820
8544 /* watch LCB_STS_LINK_TRANSFER_ACTIVE */ 8821 /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
8545 timeout = jiffies + msecs_to_jiffies(10); 8822 timeout = jiffies + msecs_to_jiffies(10);
8546 while (1) { 8823 while (1) {
8547 reg = read_csr(dd, 8824 reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
8548 DC_LCB_STS_LINK_TRANSFER_ACTIVE);
8549 if (reg) 8825 if (reg)
8550 break; 8826 break;
8551 if (time_after(jiffies, timeout)) { 8827 if (time_after(jiffies, timeout)) {
8552 dd_dev_err(dd, 8828 dd_dev_err(dd,
8553 "timeout waiting for LINK_TRANSFER_ACTIVE\n"); 8829 "timeout waiting for LINK_TRANSFER_ACTIVE\n");
8554 return -ETIMEDOUT; 8830 return -ETIMEDOUT;
8555 } 8831 }
8556 udelay(2); 8832 udelay(2);
8557 } 8833 }
8558 8834
8559 write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 8835 write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
8560 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT); 8836 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
8561 } 8837 }
8562 8838
8563 if (!loopback) { 8839 if (!loopback) {
@@ -8569,10 +8845,9 @@ static int do_quick_linkup(struct hfi1_devdata *dd)
8569 * done with LCB set up before resuming. 8845 * done with LCB set up before resuming.
8570 */ 8846 */
8571 dd_dev_err(dd, 8847 dd_dev_err(dd,
8572 "Pausing for peer to be finished with LCB set up\n"); 8848 "Pausing for peer to be finished with LCB set up\n");
8573 msleep(5000); 8849 msleep(5000);
8574 dd_dev_err(dd, 8850 dd_dev_err(dd, "Continuing with quick linkup\n");
8575 "Continuing with quick linkup\n");
8576 } 8851 }
8577 8852
8578 write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */ 8853 write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
@@ -8586,8 +8861,8 @@ static int do_quick_linkup(struct hfi1_devdata *dd)
8586 ret = set_physical_link_state(dd, PLS_QUICK_LINKUP); 8861 ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
8587 if (ret != HCMD_SUCCESS) { 8862 if (ret != HCMD_SUCCESS) {
8588 dd_dev_err(dd, 8863 dd_dev_err(dd,
8589 "%s: set physical link state to quick LinkUp failed with return %d\n", 8864 "%s: set physical link state to quick LinkUp failed with return %d\n",
8590 __func__, ret); 8865 __func__, ret);
8591 8866
8592 set_host_lcb_access(dd); 8867 set_host_lcb_access(dd);
8593 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */ 8868 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
@@ -8612,8 +8887,8 @@ static int set_serdes_loopback_mode(struct hfi1_devdata *dd)
8612 if (ret == HCMD_SUCCESS) 8887 if (ret == HCMD_SUCCESS)
8613 return 0; 8888 return 0;
8614 dd_dev_err(dd, 8889 dd_dev_err(dd,
8615 "Set physical link state to SerDes Loopback failed with return %d\n", 8890 "Set physical link state to SerDes Loopback failed with return %d\n",
8616 ret); 8891 ret);
8617 if (ret >= 0) 8892 if (ret >= 0)
8618 ret = -EINVAL; 8893 ret = -EINVAL;
8619 return ret; 8894 return ret;
@@ -8628,7 +8903,7 @@ static int init_loopback(struct hfi1_devdata *dd)
8628 8903
8629 /* all loopbacks should disable self GUID check */ 8904 /* all loopbacks should disable self GUID check */
8630 write_csr(dd, DC_DC8051_CFG_MODE, 8905 write_csr(dd, DC_DC8051_CFG_MODE,
8631 (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK)); 8906 (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
8632 8907
8633 /* 8908 /*
8634 * The simulator has only one loopback option - LCB. Switch 8909 * The simulator has only one loopback option - LCB. Switch
@@ -8636,10 +8911,9 @@ static int init_loopback(struct hfi1_devdata *dd)
8636 * 8911 *
8637 * Accept all valid loopback values. 8912 * Accept all valid loopback values.
8638 */ 8913 */
8639 if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) 8914 if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
8640 && (loopback == LOOPBACK_SERDES 8915 (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
8641 || loopback == LOOPBACK_LCB 8916 loopback == LOOPBACK_CABLE)) {
8642 || loopback == LOOPBACK_CABLE)) {
8643 loopback = LOOPBACK_LCB; 8917 loopback = LOOPBACK_LCB;
8644 quick_linkup = 1; 8918 quick_linkup = 1;
8645 return 0; 8919 return 0;
@@ -8660,7 +8934,7 @@ static int init_loopback(struct hfi1_devdata *dd)
8660 /* not supported in emulation due to emulation RTL changes */ 8934 /* not supported in emulation due to emulation RTL changes */
8661 if (dd->icode == ICODE_FPGA_EMULATION) { 8935 if (dd->icode == ICODE_FPGA_EMULATION) {
8662 dd_dev_err(dd, 8936 dd_dev_err(dd,
8663 "LCB loopback not supported in emulation\n"); 8937 "LCB loopback not supported in emulation\n");
8664 return -EINVAL; 8938 return -EINVAL;
8665 } 8939 }
8666 return 0; 8940 return 0;
@@ -8687,10 +8961,10 @@ static u16 opa_to_vc_link_widths(u16 opa_widths)
8687 u16 from; 8961 u16 from;
8688 u16 to; 8962 u16 to;
8689 } opa_link_xlate[] = { 8963 } opa_link_xlate[] = {
8690 { OPA_LINK_WIDTH_1X, 1 << (1-1) }, 8964 { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
8691 { OPA_LINK_WIDTH_2X, 1 << (2-1) }, 8965 { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
8692 { OPA_LINK_WIDTH_3X, 1 << (3-1) }, 8966 { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
8693 { OPA_LINK_WIDTH_4X, 1 << (4-1) }, 8967 { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
8694 }; 8968 };
8695 8969
8696 for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) { 8970 for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
@@ -8716,7 +8990,7 @@ static int set_local_link_attributes(struct hfi1_pportdata *ppd)
8716 8990
8717 /* set the local tx rate - need to read-modify-write */ 8991 /* set the local tx rate - need to read-modify-write */
8718 ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion, 8992 ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
8719 &rx_polarity_inversion, &ppd->local_tx_rate); 8993 &rx_polarity_inversion, &ppd->local_tx_rate);
8720 if (ret) 8994 if (ret)
8721 goto set_local_link_attributes_fail; 8995 goto set_local_link_attributes_fail;
8722 8996
@@ -8737,15 +9011,16 @@ static int set_local_link_attributes(struct hfi1_pportdata *ppd)
8737 9011
8738 enable_lane_tx = 0xF; /* enable all four lanes */ 9012 enable_lane_tx = 0xF; /* enable all four lanes */
8739 ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion, 9013 ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
8740 rx_polarity_inversion, ppd->local_tx_rate); 9014 rx_polarity_inversion, ppd->local_tx_rate);
8741 if (ret != HCMD_SUCCESS) 9015 if (ret != HCMD_SUCCESS)
8742 goto set_local_link_attributes_fail; 9016 goto set_local_link_attributes_fail;
8743 9017
8744 /* 9018 /*
8745 * DC supports continuous updates. 9019 * DC supports continuous updates.
8746 */ 9020 */
8747 ret = write_vc_local_phy(dd, 0 /* no power management */, 9021 ret = write_vc_local_phy(dd,
8748 1 /* continuous updates */); 9022 0 /* no power management */,
9023 1 /* continuous updates */);
8749 if (ret != HCMD_SUCCESS) 9024 if (ret != HCMD_SUCCESS)
8750 goto set_local_link_attributes_fail; 9025 goto set_local_link_attributes_fail;
8751 9026
@@ -8756,7 +9031,8 @@ static int set_local_link_attributes(struct hfi1_pportdata *ppd)
8756 goto set_local_link_attributes_fail; 9031 goto set_local_link_attributes_fail;
8757 9032
8758 ret = write_vc_local_link_width(dd, 0, 0, 9033 ret = write_vc_local_link_width(dd, 0, 0,
8759 opa_to_vc_link_widths(ppd->link_width_enabled)); 9034 opa_to_vc_link_widths(
9035 ppd->link_width_enabled));
8760 if (ret != HCMD_SUCCESS) 9036 if (ret != HCMD_SUCCESS)
8761 goto set_local_link_attributes_fail; 9037 goto set_local_link_attributes_fail;
8762 9038
@@ -8767,8 +9043,8 @@ static int set_local_link_attributes(struct hfi1_pportdata *ppd)
8767 9043
8768set_local_link_attributes_fail: 9044set_local_link_attributes_fail:
8769 dd_dev_err(dd, 9045 dd_dev_err(dd,
8770 "Failed to set local link attributes, return 0x%x\n", 9046 "Failed to set local link attributes, return 0x%x\n",
8771 ret); 9047 ret);
8772 return ret; 9048 return ret;
8773} 9049}
8774 9050
@@ -8781,54 +9057,101 @@ int start_link(struct hfi1_pportdata *ppd)
8781{ 9057{
8782 if (!ppd->link_enabled) { 9058 if (!ppd->link_enabled) {
8783 dd_dev_info(ppd->dd, 9059 dd_dev_info(ppd->dd,
8784 "%s: stopping link start because link is disabled\n", 9060 "%s: stopping link start because link is disabled\n",
8785 __func__); 9061 __func__);
8786 return 0; 9062 return 0;
8787 } 9063 }
8788 if (!ppd->driver_link_ready) { 9064 if (!ppd->driver_link_ready) {
8789 dd_dev_info(ppd->dd, 9065 dd_dev_info(ppd->dd,
8790 "%s: stopping link start because driver is not ready\n", 9066 "%s: stopping link start because driver is not ready\n",
8791 __func__); 9067 __func__);
8792 return 0; 9068 return 0;
8793 } 9069 }
8794 9070
8795 if (qsfp_mod_present(ppd) || loopback == LOOPBACK_SERDES || 9071 if (qsfp_mod_present(ppd) || loopback == LOOPBACK_SERDES ||
8796 loopback == LOOPBACK_LCB || 9072 loopback == LOOPBACK_LCB ||
8797 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) 9073 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
8798 return set_link_state(ppd, HLS_DN_POLL); 9074 return set_link_state(ppd, HLS_DN_POLL);
8799 9075
8800 dd_dev_info(ppd->dd, 9076 dd_dev_info(ppd->dd,
8801 "%s: stopping link start because no cable is present\n", 9077 "%s: stopping link start because no cable is present\n",
8802 __func__); 9078 __func__);
8803 return -EAGAIN; 9079 return -EAGAIN;
8804} 9080}
8805 9081
8806static void reset_qsfp(struct hfi1_pportdata *ppd) 9082static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
9083{
9084 struct hfi1_devdata *dd = ppd->dd;
9085 u64 mask;
9086 unsigned long timeout;
9087
9088 /*
9089 * Check for QSFP interrupt for t_init (SFF 8679)
9090 */
9091 timeout = jiffies + msecs_to_jiffies(2000);
9092 while (1) {
9093 mask = read_csr(dd, dd->hfi1_id ?
9094 ASIC_QSFP2_IN : ASIC_QSFP1_IN);
9095 if (!(mask & QSFP_HFI0_INT_N)) {
9096 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR :
9097 ASIC_QSFP1_CLEAR, QSFP_HFI0_INT_N);
9098 break;
9099 }
9100 if (time_after(jiffies, timeout)) {
9101 dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
9102 __func__);
9103 break;
9104 }
9105 udelay(2);
9106 }
9107}
9108
9109static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
9110{
9111 struct hfi1_devdata *dd = ppd->dd;
9112 u64 mask;
9113
9114 mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
9115 if (enable)
9116 mask |= (u64)QSFP_HFI0_INT_N;
9117 else
9118 mask &= ~(u64)QSFP_HFI0_INT_N;
9119 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
9120}
9121
9122void reset_qsfp(struct hfi1_pportdata *ppd)
8807{ 9123{
8808 struct hfi1_devdata *dd = ppd->dd; 9124 struct hfi1_devdata *dd = ppd->dd;
8809 u64 mask, qsfp_mask; 9125 u64 mask, qsfp_mask;
8810 9126
9127 /* Disable INT_N from triggering QSFP interrupts */
9128 set_qsfp_int_n(ppd, 0);
9129
9130 /* Reset the QSFP */
8811 mask = (u64)QSFP_HFI0_RESET_N; 9131 mask = (u64)QSFP_HFI0_RESET_N;
8812 qsfp_mask = read_csr(dd, 9132 qsfp_mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE);
8813 dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE);
8814 qsfp_mask |= mask; 9133 qsfp_mask |= mask;
8815 write_csr(dd, 9134 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE, qsfp_mask);
8816 dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE,
8817 qsfp_mask);
8818 9135
8819 qsfp_mask = read_csr(dd, 9136 qsfp_mask = read_csr(dd,
8820 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT); 9137 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
8821 qsfp_mask &= ~mask; 9138 qsfp_mask &= ~mask;
8822 write_csr(dd, 9139 write_csr(dd,
8823 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, 9140 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
8824 qsfp_mask);
8825 9141
8826 udelay(10); 9142 udelay(10);
8827 9143
8828 qsfp_mask |= mask; 9144 qsfp_mask |= mask;
8829 write_csr(dd, 9145 write_csr(dd,
8830 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, 9146 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
8831 qsfp_mask); 9147
9148 wait_for_qsfp_init(ppd);
9149
9150 /*
9151 * Allow INT_N to trigger the QSFP interrupt to watch
9152 * for alarms and warnings
9153 */
9154 set_qsfp_int_n(ppd, 1);
8832} 9155}
8833 9156
8834static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd, 9157static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
@@ -8837,102 +9160,86 @@ static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
8837 struct hfi1_devdata *dd = ppd->dd; 9160 struct hfi1_devdata *dd = ppd->dd;
8838 9161
8839 if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) || 9162 if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
8840 (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING)) 9163 (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
8841 dd_dev_info(dd, 9164 dd_dev_info(dd, "%s: QSFP cable on fire\n",
8842 "%s: QSFP cable on fire\n", 9165 __func__);
8843 __func__);
8844 9166
8845 if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) || 9167 if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
8846 (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING)) 9168 (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
8847 dd_dev_info(dd, 9169 dd_dev_info(dd, "%s: QSFP cable temperature too low\n",
8848 "%s: QSFP cable temperature too low\n", 9170 __func__);
8849 __func__);
8850 9171
8851 if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) || 9172 if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
8852 (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING)) 9173 (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
8853 dd_dev_info(dd, 9174 dd_dev_info(dd, "%s: QSFP supply voltage too high\n",
8854 "%s: QSFP supply voltage too high\n", 9175 __func__);
8855 __func__);
8856 9176
8857 if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) || 9177 if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
8858 (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING)) 9178 (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
8859 dd_dev_info(dd, 9179 dd_dev_info(dd, "%s: QSFP supply voltage too low\n",
8860 "%s: QSFP supply voltage too low\n", 9180 __func__);
8861 __func__);
8862 9181
8863 /* Byte 2 is vendor specific */ 9182 /* Byte 2 is vendor specific */
8864 9183
8865 if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) || 9184 if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
8866 (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING)) 9185 (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
8867 dd_dev_info(dd, 9186 dd_dev_info(dd, "%s: Cable RX channel 1/2 power too high\n",
8868 "%s: Cable RX channel 1/2 power too high\n", 9187 __func__);
8869 __func__);
8870 9188
8871 if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) || 9189 if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
8872 (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING)) 9190 (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
8873 dd_dev_info(dd, 9191 dd_dev_info(dd, "%s: Cable RX channel 1/2 power too low\n",
8874 "%s: Cable RX channel 1/2 power too low\n", 9192 __func__);
8875 __func__);
8876 9193
8877 if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) || 9194 if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
8878 (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING)) 9195 (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
8879 dd_dev_info(dd, 9196 dd_dev_info(dd, "%s: Cable RX channel 3/4 power too high\n",
8880 "%s: Cable RX channel 3/4 power too high\n", 9197 __func__);
8881 __func__);
8882 9198
8883 if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) || 9199 if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
8884 (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING)) 9200 (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
8885 dd_dev_info(dd, 9201 dd_dev_info(dd, "%s: Cable RX channel 3/4 power too low\n",
8886 "%s: Cable RX channel 3/4 power too low\n", 9202 __func__);
8887 __func__);
8888 9203
8889 if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) || 9204 if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
8890 (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING)) 9205 (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
8891 dd_dev_info(dd, 9206 dd_dev_info(dd, "%s: Cable TX channel 1/2 bias too high\n",
8892 "%s: Cable TX channel 1/2 bias too high\n", 9207 __func__);
8893 __func__);
8894 9208
8895 if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) || 9209 if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
8896 (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING)) 9210 (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
8897 dd_dev_info(dd, 9211 dd_dev_info(dd, "%s: Cable TX channel 1/2 bias too low\n",
8898 "%s: Cable TX channel 1/2 bias too low\n", 9212 __func__);
8899 __func__);
8900 9213
8901 if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) || 9214 if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
8902 (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING)) 9215 (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
8903 dd_dev_info(dd, 9216 dd_dev_info(dd, "%s: Cable TX channel 3/4 bias too high\n",
8904 "%s: Cable TX channel 3/4 bias too high\n", 9217 __func__);
8905 __func__);
8906 9218
8907 if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) || 9219 if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
8908 (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING)) 9220 (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
8909 dd_dev_info(dd, 9221 dd_dev_info(dd, "%s: Cable TX channel 3/4 bias too low\n",
8910 "%s: Cable TX channel 3/4 bias too low\n", 9222 __func__);
8911 __func__);
8912 9223
8913 if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) || 9224 if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
8914 (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING)) 9225 (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
8915 dd_dev_info(dd, 9226 dd_dev_info(dd, "%s: Cable TX channel 1/2 power too high\n",
8916 "%s: Cable TX channel 1/2 power too high\n", 9227 __func__);
8917 __func__);
8918 9228
8919 if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) || 9229 if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
8920 (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING)) 9230 (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
8921 dd_dev_info(dd, 9231 dd_dev_info(dd, "%s: Cable TX channel 1/2 power too low\n",
8922 "%s: Cable TX channel 1/2 power too low\n", 9232 __func__);
8923 __func__);
8924 9233
8925 if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) || 9234 if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
8926 (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING)) 9235 (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
8927 dd_dev_info(dd, 9236 dd_dev_info(dd, "%s: Cable TX channel 3/4 power too high\n",
8928 "%s: Cable TX channel 3/4 power too high\n", 9237 __func__);
8929 __func__);
8930 9238
8931 if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) || 9239 if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
8932 (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING)) 9240 (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
8933 dd_dev_info(dd, 9241 dd_dev_info(dd, "%s: Cable TX channel 3/4 power too low\n",
8934 "%s: Cable TX channel 3/4 power too low\n", 9242 __func__);
8935 __func__);
8936 9243
8937 /* Bytes 9-10 and 11-12 are reserved */ 9244 /* Bytes 9-10 and 11-12 are reserved */
8938 /* Bytes 13-15 are vendor specific */ 9245 /* Bytes 13-15 are vendor specific */
@@ -8940,35 +9247,8 @@ static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
8940 return 0; 9247 return 0;
8941} 9248}
8942 9249
8943static int do_pre_lni_host_behaviors(struct hfi1_pportdata *ppd)
8944{
8945 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
8946
8947 return 0;
8948}
8949
8950static int do_qsfp_intr_fallback(struct hfi1_pportdata *ppd)
8951{
8952 struct hfi1_devdata *dd = ppd->dd;
8953 u8 qsfp_interrupt_status = 0;
8954
8955 if (qsfp_read(ppd, dd->hfi1_id, 2, &qsfp_interrupt_status, 1)
8956 != 1) {
8957 dd_dev_info(dd,
8958 "%s: Failed to read status of QSFP module\n",
8959 __func__);
8960 return -EIO;
8961 }
8962
8963 /* We don't care about alarms & warnings with a non-functional INT_N */
8964 if (!(qsfp_interrupt_status & QSFP_DATA_NOT_READY))
8965 do_pre_lni_host_behaviors(ppd);
8966
8967 return 0;
8968}
8969
8970/* This routine will only be scheduled if the QSFP module is present */ 9250/* This routine will only be scheduled if the QSFP module is present */
8971static void qsfp_event(struct work_struct *work) 9251void qsfp_event(struct work_struct *work)
8972{ 9252{
8973 struct qsfp_data *qd; 9253 struct qsfp_data *qd;
8974 struct hfi1_pportdata *ppd; 9254 struct hfi1_pportdata *ppd;
@@ -8990,76 +9270,75 @@ static void qsfp_event(struct work_struct *work)
8990 dc_start(dd); 9270 dc_start(dd);
8991 9271
8992 if (qd->cache_refresh_required) { 9272 if (qd->cache_refresh_required) {
8993 msleep(3000); 9273 set_qsfp_int_n(ppd, 0);
8994 reset_qsfp(ppd);
8995 9274
8996 /* Check for QSFP interrupt after t_init (SFF 8679) 9275 wait_for_qsfp_init(ppd);
8997 * + extra 9276
9277 /*
9278 * Allow INT_N to trigger the QSFP interrupt to watch
9279 * for alarms and warnings
8998 */ 9280 */
8999 msleep(3000); 9281 set_qsfp_int_n(ppd, 1);
9000 if (!qd->qsfp_interrupt_functional) { 9282
9001 if (do_qsfp_intr_fallback(ppd) < 0) 9283 tune_serdes(ppd);
9002 dd_dev_info(dd, "%s: QSFP fallback failed\n", 9284
9003 __func__); 9285 start_link(ppd);
9004 ppd->driver_link_ready = 1;
9005 start_link(ppd);
9006 }
9007 } 9286 }
9008 9287
9009 if (qd->check_interrupt_flags) { 9288 if (qd->check_interrupt_flags) {
9010 u8 qsfp_interrupt_status[16] = {0,}; 9289 u8 qsfp_interrupt_status[16] = {0,};
9011 9290
9012 if (qsfp_read(ppd, dd->hfi1_id, 6, 9291 if (one_qsfp_read(ppd, dd->hfi1_id, 6,
9013 &qsfp_interrupt_status[0], 16) != 16) { 9292 &qsfp_interrupt_status[0], 16) != 16) {
9014 dd_dev_info(dd, 9293 dd_dev_info(dd,
9015 "%s: Failed to read status of QSFP module\n", 9294 "%s: Failed to read status of QSFP module\n",
9016 __func__); 9295 __func__);
9017 } else { 9296 } else {
9018 unsigned long flags; 9297 unsigned long flags;
9019 u8 data_status;
9020 9298
9299 handle_qsfp_error_conditions(
9300 ppd, qsfp_interrupt_status);
9021 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags); 9301 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
9022 ppd->qsfp_info.check_interrupt_flags = 0; 9302 ppd->qsfp_info.check_interrupt_flags = 0;
9023 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, 9303 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
9024 flags); 9304 flags);
9025
9026 if (qsfp_read(ppd, dd->hfi1_id, 2, &data_status, 1)
9027 != 1) {
9028 dd_dev_info(dd,
9029 "%s: Failed to read status of QSFP module\n",
9030 __func__);
9031 }
9032 if (!(data_status & QSFP_DATA_NOT_READY)) {
9033 do_pre_lni_host_behaviors(ppd);
9034 start_link(ppd);
9035 } else
9036 handle_qsfp_error_conditions(ppd,
9037 qsfp_interrupt_status);
9038 } 9305 }
9039 } 9306 }
9040} 9307}
9041 9308
9042void init_qsfp(struct hfi1_pportdata *ppd) 9309static void init_qsfp_int(struct hfi1_devdata *dd)
9043{ 9310{
9044 struct hfi1_devdata *dd = ppd->dd; 9311 struct hfi1_pportdata *ppd = dd->pport;
9045 u64 qsfp_mask; 9312 u64 qsfp_mask, cce_int_mask;
9313 const int qsfp1_int_smask = QSFP1_INT % 64;
9314 const int qsfp2_int_smask = QSFP2_INT % 64;
9046 9315
9047 if (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB || 9316 /*
9048 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) { 9317 * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
9049 ppd->driver_link_ready = 1; 9318 * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
9050 return; 9319 * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
9320 * the index of the appropriate CSR in the CCEIntMask CSR array
9321 */
9322 cce_int_mask = read_csr(dd, CCE_INT_MASK +
9323 (8 * (QSFP1_INT / 64)));
9324 if (dd->hfi1_id) {
9325 cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
9326 write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
9327 cce_int_mask);
9328 } else {
9329 cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
9330 write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
9331 cce_int_mask);
9051 } 9332 }
9052 9333
9053 ppd->qsfp_info.ppd = ppd;
9054 INIT_WORK(&ppd->qsfp_info.qsfp_work, qsfp_event);
9055
9056 qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N); 9334 qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
9057 /* Clear current status to avoid spurious interrupts */ 9335 /* Clear current status to avoid spurious interrupts */
9058 write_csr(dd, 9336 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
9059 dd->hfi1_id ? 9337 qsfp_mask);
9060 ASIC_QSFP2_CLEAR : 9338 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
9061 ASIC_QSFP1_CLEAR, 9339 qsfp_mask);
9062 qsfp_mask); 9340
9341 set_qsfp_int_n(ppd, 0);
9063 9342
9064 /* Handle active low nature of INT_N and MODPRST_N pins */ 9343 /* Handle active low nature of INT_N and MODPRST_N pins */
9065 if (qsfp_mod_present(ppd)) 9344 if (qsfp_mod_present(ppd))
@@ -9067,29 +9346,6 @@ void init_qsfp(struct hfi1_pportdata *ppd)
9067 write_csr(dd, 9346 write_csr(dd,
9068 dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT, 9347 dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
9069 qsfp_mask); 9348 qsfp_mask);
9070
9071 /* Allow only INT_N and MODPRST_N to trigger QSFP interrupts */
9072 qsfp_mask |= (u64)QSFP_HFI0_MODPRST_N;
9073 write_csr(dd,
9074 dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
9075 qsfp_mask);
9076
9077 if (qsfp_mod_present(ppd)) {
9078 msleep(3000);
9079 reset_qsfp(ppd);
9080
9081 /* Check for QSFP interrupt after t_init (SFF 8679)
9082 * + extra
9083 */
9084 msleep(3000);
9085 if (!ppd->qsfp_info.qsfp_interrupt_functional) {
9086 if (do_qsfp_intr_fallback(ppd) < 0)
9087 dd_dev_info(dd,
9088 "%s: QSFP fallback failed\n",
9089 __func__);
9090 ppd->driver_link_ready = 1;
9091 }
9092 }
9093} 9349}
9094 9350
9095/* 9351/*
@@ -9097,6 +9353,10 @@ void init_qsfp(struct hfi1_pportdata *ppd)
9097 */ 9353 */
9098static void init_lcb(struct hfi1_devdata *dd) 9354static void init_lcb(struct hfi1_devdata *dd)
9099{ 9355{
9356 /* simulator does not correctly handle LCB cclk loopback, skip */
9357 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
9358 return;
9359
9100 /* the DC has been reset earlier in the driver load */ 9360 /* the DC has been reset earlier in the driver load */
9101 9361
9102 /* set LCB for cclk loopback on the port */ 9362 /* set LCB for cclk loopback on the port */
@@ -9125,8 +9385,6 @@ int bringup_serdes(struct hfi1_pportdata *ppd)
9125 ppd->guid = guid; 9385 ppd->guid = guid;
9126 } 9386 }
9127 9387
9128 /* the link defaults to enabled */
9129 ppd->link_enabled = 1;
9130 /* Set linkinit_reason on power up per OPA spec */ 9388 /* Set linkinit_reason on power up per OPA spec */
9131 ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP; 9389 ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
9132 9390
@@ -9139,6 +9397,12 @@ int bringup_serdes(struct hfi1_pportdata *ppd)
9139 return ret; 9397 return ret;
9140 } 9398 }
9141 9399
9400 /* tune the SERDES to a ballpark setting for
9401 * optimal signal and bit error rate
9402 * Needs to be done before starting the link
9403 */
9404 tune_serdes(ppd);
9405
9142 return start_link(ppd); 9406 return start_link(ppd);
9143} 9407}
9144 9408
@@ -9156,8 +9420,10 @@ void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
9156 ppd->driver_link_ready = 0; 9420 ppd->driver_link_ready = 0;
9157 ppd->link_enabled = 0; 9421 ppd->link_enabled = 0;
9158 9422
9423 ppd->offline_disabled_reason =
9424 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
9159 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SMA_DISABLED, 0, 9425 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SMA_DISABLED, 0,
9160 OPA_LINKDOWN_REASON_SMA_DISABLED); 9426 OPA_LINKDOWN_REASON_SMA_DISABLED);
9161 set_link_state(ppd, HLS_DN_OFFLINE); 9427 set_link_state(ppd, HLS_DN_OFFLINE);
9162 9428
9163 /* disable the port */ 9429 /* disable the port */
@@ -9171,14 +9437,14 @@ static inline int init_cpu_counters(struct hfi1_devdata *dd)
9171 9437
9172 ppd = (struct hfi1_pportdata *)(dd + 1); 9438 ppd = (struct hfi1_pportdata *)(dd + 1);
9173 for (i = 0; i < dd->num_pports; i++, ppd++) { 9439 for (i = 0; i < dd->num_pports; i++, ppd++) {
9174 ppd->ibport_data.rc_acks = NULL; 9440 ppd->ibport_data.rvp.rc_acks = NULL;
9175 ppd->ibport_data.rc_qacks = NULL; 9441 ppd->ibport_data.rvp.rc_qacks = NULL;
9176 ppd->ibport_data.rc_acks = alloc_percpu(u64); 9442 ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
9177 ppd->ibport_data.rc_qacks = alloc_percpu(u64); 9443 ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
9178 ppd->ibport_data.rc_delayed_comp = alloc_percpu(u64); 9444 ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
9179 if ((ppd->ibport_data.rc_acks == NULL) || 9445 if (!ppd->ibport_data.rvp.rc_acks ||
9180 (ppd->ibport_data.rc_delayed_comp == NULL) || 9446 !ppd->ibport_data.rvp.rc_delayed_comp ||
9181 (ppd->ibport_data.rc_qacks == NULL)) 9447 !ppd->ibport_data.rvp.rc_qacks)
9182 return -ENOMEM; 9448 return -ENOMEM;
9183 } 9449 }
9184 9450
@@ -9213,8 +9479,8 @@ void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
9213 pa = 0; 9479 pa = 0;
9214 } else if (type > PT_INVALID) { 9480 } else if (type > PT_INVALID) {
9215 dd_dev_err(dd, 9481 dd_dev_err(dd,
9216 "unexpected receive array type %u for index %u, not handled\n", 9482 "unexpected receive array type %u for index %u, not handled\n",
9217 type, index); 9483 type, index);
9218 goto done; 9484 goto done;
9219 } 9485 }
9220 9486
@@ -9429,12 +9695,15 @@ static void set_send_length(struct hfi1_pportdata *ppd)
9429 /* all kernel receive contexts have the same hdrqentsize */ 9695 /* all kernel receive contexts have the same hdrqentsize */
9430 for (i = 0; i < ppd->vls_supported; i++) { 9696 for (i = 0; i < ppd->vls_supported; i++) {
9431 sc_set_cr_threshold(dd->vld[i].sc, 9697 sc_set_cr_threshold(dd->vld[i].sc,
9432 sc_mtu_to_threshold(dd->vld[i].sc, dd->vld[i].mtu, 9698 sc_mtu_to_threshold(dd->vld[i].sc,
9433 dd->rcd[0]->rcvhdrqentsize)); 9699 dd->vld[i].mtu,
9700 dd->rcd[0]->
9701 rcvhdrqentsize));
9434 } 9702 }
9435 sc_set_cr_threshold(dd->vld[15].sc, 9703 sc_set_cr_threshold(dd->vld[15].sc,
9436 sc_mtu_to_threshold(dd->vld[15].sc, dd->vld[15].mtu, 9704 sc_mtu_to_threshold(dd->vld[15].sc,
9437 dd->rcd[0]->rcvhdrqentsize)); 9705 dd->vld[15].mtu,
9706 dd->rcd[0]->rcvhdrqentsize));
9438 9707
9439 /* Adjust maximum MTU for the port in DC */ 9708 /* Adjust maximum MTU for the port in DC */
9440 dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 : 9709 dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
@@ -9460,7 +9729,7 @@ static void set_lidlmc(struct hfi1_pportdata *ppd)
9460 c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK 9729 c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
9461 | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK); 9730 | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
9462 c1 |= ((ppd->lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK) 9731 c1 |= ((ppd->lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
9463 << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT)| 9732 << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
9464 ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK) 9733 ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
9465 << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT); 9734 << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
9466 write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1); 9735 write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
@@ -9495,8 +9764,8 @@ static int wait_phy_linkstate(struct hfi1_devdata *dd, u32 state, u32 msecs)
9495 break; 9764 break;
9496 if (time_after(jiffies, timeout)) { 9765 if (time_after(jiffies, timeout)) {
9497 dd_dev_err(dd, 9766 dd_dev_err(dd,
9498 "timeout waiting for phy link state 0x%x, current state is 0x%x\n", 9767 "timeout waiting for phy link state 0x%x, current state is 0x%x\n",
9499 state, curr_state); 9768 state, curr_state);
9500 return -ETIMEDOUT; 9769 return -ETIMEDOUT;
9501 } 9770 }
9502 usleep_range(1950, 2050); /* sleep 2ms-ish */ 9771 usleep_range(1950, 2050); /* sleep 2ms-ish */
@@ -9539,17 +9808,18 @@ static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
9539 9808
9540 if (do_transition) { 9809 if (do_transition) {
9541 ret = set_physical_link_state(dd, 9810 ret = set_physical_link_state(dd,
9542 PLS_OFFLINE | (rem_reason << 8)); 9811 (rem_reason << 8) | PLS_OFFLINE);
9543 9812
9544 if (ret != HCMD_SUCCESS) { 9813 if (ret != HCMD_SUCCESS) {
9545 dd_dev_err(dd, 9814 dd_dev_err(dd,
9546 "Failed to transition to Offline link state, return %d\n", 9815 "Failed to transition to Offline link state, return %d\n",
9547 ret); 9816 ret);
9548 return -EINVAL; 9817 return -EINVAL;
9549 } 9818 }
9550 if (ppd->offline_disabled_reason == OPA_LINKDOWN_REASON_NONE) 9819 if (ppd->offline_disabled_reason ==
9820 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
9551 ppd->offline_disabled_reason = 9821 ppd->offline_disabled_reason =
9552 OPA_LINKDOWN_REASON_TRANSIENT; 9822 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
9553 } 9823 }
9554 9824
9555 if (do_wait) { 9825 if (do_wait) {
@@ -9570,6 +9840,22 @@ static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
9570 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */ 9840 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
9571 ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */ 9841 ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
9572 9842
9843 if (ppd->port_type == PORT_TYPE_QSFP &&
9844 ppd->qsfp_info.limiting_active &&
9845 qsfp_mod_present(ppd)) {
9846 int ret;
9847
9848 ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
9849 if (ret == 0) {
9850 set_qsfp_tx(ppd, 0);
9851 release_chip_resource(dd, qsfp_resource(dd));
9852 } else {
9853 /* not fatal, but should warn */
9854 dd_dev_err(dd,
9855 "Unable to acquire lock to turn off QSFP TX\n");
9856 }
9857 }
9858
9573 /* 9859 /*
9574 * The LNI has a mandatory wait time after the physical state 9860 * The LNI has a mandatory wait time after the physical state
9575 * moves to Offline.Quiet. The wait time may be different 9861 * moves to Offline.Quiet. The wait time may be different
@@ -9582,7 +9868,7 @@ static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
9582 ret = wait_fm_ready(dd, 7000); 9868 ret = wait_fm_ready(dd, 7000);
9583 if (ret) { 9869 if (ret) {
9584 dd_dev_err(dd, 9870 dd_dev_err(dd,
9585 "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n"); 9871 "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
9586 /* state is really offline, so make it so */ 9872 /* state is really offline, so make it so */
9587 ppd->host_link_state = HLS_DN_OFFLINE; 9873 ppd->host_link_state = HLS_DN_OFFLINE;
9588 return ret; 9874 return ret;
@@ -9605,8 +9891,8 @@ static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
9605 read_last_local_state(dd, &last_local_state); 9891 read_last_local_state(dd, &last_local_state);
9606 read_last_remote_state(dd, &last_remote_state); 9892 read_last_remote_state(dd, &last_remote_state);
9607 dd_dev_err(dd, 9893 dd_dev_err(dd,
9608 "LNI failure last states: local 0x%08x, remote 0x%08x\n", 9894 "LNI failure last states: local 0x%08x, remote 0x%08x\n",
9609 last_local_state, last_remote_state); 9895 last_local_state, last_remote_state);
9610 } 9896 }
9611 9897
9612 /* the active link width (downgrade) is 0 on link down */ 9898 /* the active link width (downgrade) is 0 on link down */
@@ -9754,14 +10040,14 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9754 state = dd->link_default; 10040 state = dd->link_default;
9755 10041
9756 /* interpret poll -> poll as a link bounce */ 10042 /* interpret poll -> poll as a link bounce */
9757 poll_bounce = ppd->host_link_state == HLS_DN_POLL 10043 poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
9758 && state == HLS_DN_POLL; 10044 state == HLS_DN_POLL;
9759 10045
9760 dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__, 10046 dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
9761 link_state_name(ppd->host_link_state), 10047 link_state_name(ppd->host_link_state),
9762 link_state_name(orig_new_state), 10048 link_state_name(orig_new_state),
9763 poll_bounce ? "(bounce) " : "", 10049 poll_bounce ? "(bounce) " : "",
9764 link_state_reason_name(ppd, state)); 10050 link_state_reason_name(ppd, state));
9765 10051
9766 was_up = !!(ppd->host_link_state & HLS_UP); 10052 was_up = !!(ppd->host_link_state & HLS_UP);
9767 10053
@@ -9782,8 +10068,8 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9782 10068
9783 switch (state) { 10069 switch (state) {
9784 case HLS_UP_INIT: 10070 case HLS_UP_INIT:
9785 if (ppd->host_link_state == HLS_DN_POLL && (quick_linkup 10071 if (ppd->host_link_state == HLS_DN_POLL &&
9786 || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) { 10072 (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
9787 /* 10073 /*
9788 * Quick link up jumps from polling to here. 10074 * Quick link up jumps from polling to here.
9789 * 10075 *
@@ -9791,7 +10077,7 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9791 * simulator jumps from polling to link up. 10077 * simulator jumps from polling to link up.
9792 * Accept that here. 10078 * Accept that here.
9793 */ 10079 */
9794 /* OK */; 10080 /* OK */
9795 } else if (ppd->host_link_state != HLS_GOING_UP) { 10081 } else if (ppd->host_link_state != HLS_GOING_UP) {
9796 goto unexpected; 10082 goto unexpected;
9797 } 10083 }
@@ -9802,8 +10088,8 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9802 /* logical state didn't change, stay at going_up */ 10088 /* logical state didn't change, stay at going_up */
9803 ppd->host_link_state = HLS_GOING_UP; 10089 ppd->host_link_state = HLS_GOING_UP;
9804 dd_dev_err(dd, 10090 dd_dev_err(dd,
9805 "%s: logical state did not change to INIT\n", 10091 "%s: logical state did not change to INIT\n",
9806 __func__); 10092 __func__);
9807 } else { 10093 } else {
9808 /* clear old transient LINKINIT_REASON code */ 10094 /* clear old transient LINKINIT_REASON code */
9809 if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR) 10095 if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
@@ -9827,8 +10113,8 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9827 /* logical state didn't change, stay at init */ 10113 /* logical state didn't change, stay at init */
9828 ppd->host_link_state = HLS_UP_INIT; 10114 ppd->host_link_state = HLS_UP_INIT;
9829 dd_dev_err(dd, 10115 dd_dev_err(dd,
9830 "%s: logical state did not change to ARMED\n", 10116 "%s: logical state did not change to ARMED\n",
9831 __func__); 10117 __func__);
9832 } 10118 }
9833 /* 10119 /*
9834 * The simulator does not currently implement SMA messages, 10120 * The simulator does not currently implement SMA messages,
@@ -9849,15 +10135,14 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9849 /* logical state didn't change, stay at armed */ 10135 /* logical state didn't change, stay at armed */
9850 ppd->host_link_state = HLS_UP_ARMED; 10136 ppd->host_link_state = HLS_UP_ARMED;
9851 dd_dev_err(dd, 10137 dd_dev_err(dd,
9852 "%s: logical state did not change to ACTIVE\n", 10138 "%s: logical state did not change to ACTIVE\n",
9853 __func__); 10139 __func__);
9854 } else { 10140 } else {
9855
9856 /* tell all engines to go running */ 10141 /* tell all engines to go running */
9857 sdma_all_running(dd); 10142 sdma_all_running(dd);
9858 10143
9859 /* Signal the IB layer that the port has went active */ 10144 /* Signal the IB layer that the port has went active */
9860 event.device = &dd->verbs_dev.ibdev; 10145 event.device = &dd->verbs_dev.rdi.ibdev;
9861 event.element.port_num = ppd->port; 10146 event.element.port_num = ppd->port;
9862 event.event = IB_EVENT_PORT_ACTIVE; 10147 event.event = IB_EVENT_PORT_ACTIVE;
9863 } 10148 }
@@ -9884,6 +10169,7 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9884 ppd->link_enabled = 1; 10169 ppd->link_enabled = 1;
9885 } 10170 }
9886 10171
10172 set_all_slowpath(ppd->dd);
9887 ret = set_local_link_attributes(ppd); 10173 ret = set_local_link_attributes(ppd);
9888 if (ret) 10174 if (ret)
9889 break; 10175 break;
@@ -9898,12 +10184,13 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9898 ret1 = set_physical_link_state(dd, PLS_POLLING); 10184 ret1 = set_physical_link_state(dd, PLS_POLLING);
9899 if (ret1 != HCMD_SUCCESS) { 10185 if (ret1 != HCMD_SUCCESS) {
9900 dd_dev_err(dd, 10186 dd_dev_err(dd,
9901 "Failed to transition to Polling link state, return 0x%x\n", 10187 "Failed to transition to Polling link state, return 0x%x\n",
9902 ret1); 10188 ret1);
9903 ret = -EINVAL; 10189 ret = -EINVAL;
9904 } 10190 }
9905 } 10191 }
9906 ppd->offline_disabled_reason = OPA_LINKDOWN_REASON_NONE; 10192 ppd->offline_disabled_reason =
10193 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
9907 /* 10194 /*
9908 * If an error occurred above, go back to offline. The 10195 * If an error occurred above, go back to offline. The
9909 * caller may reschedule another attempt. 10196 * caller may reschedule another attempt.
@@ -9928,8 +10215,8 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9928 ret1 = set_physical_link_state(dd, PLS_DISABLED); 10215 ret1 = set_physical_link_state(dd, PLS_DISABLED);
9929 if (ret1 != HCMD_SUCCESS) { 10216 if (ret1 != HCMD_SUCCESS) {
9930 dd_dev_err(dd, 10217 dd_dev_err(dd,
9931 "Failed to transition to Disabled link state, return 0x%x\n", 10218 "Failed to transition to Disabled link state, return 0x%x\n",
9932 ret1); 10219 ret1);
9933 ret = -EINVAL; 10220 ret = -EINVAL;
9934 break; 10221 break;
9935 } 10222 }
@@ -9957,8 +10244,8 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9957 ret1 = set_physical_link_state(dd, PLS_LINKUP); 10244 ret1 = set_physical_link_state(dd, PLS_LINKUP);
9958 if (ret1 != HCMD_SUCCESS) { 10245 if (ret1 != HCMD_SUCCESS) {
9959 dd_dev_err(dd, 10246 dd_dev_err(dd,
9960 "Failed to transition to link up state, return 0x%x\n", 10247 "Failed to transition to link up state, return 0x%x\n",
9961 ret1); 10248 ret1);
9962 ret = -EINVAL; 10249 ret = -EINVAL;
9963 break; 10250 break;
9964 } 10251 }
@@ -9969,7 +10256,7 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9969 case HLS_LINK_COOLDOWN: /* transient within goto_offline() */ 10256 case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
9970 default: 10257 default:
9971 dd_dev_info(dd, "%s: state 0x%x: not supported\n", 10258 dd_dev_info(dd, "%s: state 0x%x: not supported\n",
9972 __func__, state); 10259 __func__, state);
9973 ret = -EINVAL; 10260 ret = -EINVAL;
9974 break; 10261 break;
9975 } 10262 }
@@ -9989,8 +10276,8 @@ int set_link_state(struct hfi1_pportdata *ppd, u32 state)
9989 10276
9990unexpected: 10277unexpected:
9991 dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n", 10278 dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
9992 __func__, link_state_name(ppd->host_link_state), 10279 __func__, link_state_name(ppd->host_link_state),
9993 link_state_name(state)); 10280 link_state_name(state));
9994 ret = -EINVAL; 10281 ret = -EINVAL;
9995 10282
9996done: 10283done:
@@ -10016,7 +10303,7 @@ int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
10016 * The VL Arbitrator high limit is sent in units of 4k 10303 * The VL Arbitrator high limit is sent in units of 4k
10017 * bytes, while HFI stores it in units of 64 bytes. 10304 * bytes, while HFI stores it in units of 64 bytes.
10018 */ 10305 */
10019 val *= 4096/64; 10306 val *= 4096 / 64;
10020 reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK) 10307 reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
10021 << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT; 10308 << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
10022 write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg); 10309 write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
@@ -10031,12 +10318,6 @@ int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
10031 ppd->vls_operational = val; 10318 ppd->vls_operational = val;
10032 if (!ppd->port) 10319 if (!ppd->port)
10033 ret = -EINVAL; 10320 ret = -EINVAL;
10034 else
10035 ret = sdma_map_init(
10036 ppd->dd,
10037 ppd->port - 1,
10038 val,
10039 NULL);
10040 } 10321 }
10041 break; 10322 break;
10042 /* 10323 /*
@@ -10084,8 +10365,8 @@ int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
10084 default: 10365 default:
10085 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL)) 10366 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
10086 dd_dev_info(ppd->dd, 10367 dd_dev_info(ppd->dd,
10087 "%s: which %s, val 0x%x: not implemented\n", 10368 "%s: which %s, val 0x%x: not implemented\n",
10088 __func__, ib_cfg_name(which), val); 10369 __func__, ib_cfg_name(which), val);
10089 break; 10370 break;
10090 } 10371 }
10091 return ret; 10372 return ret;
@@ -10152,6 +10433,7 @@ static int vl_arb_match_cache(struct vl_arb_cache *cache,
10152{ 10433{
10153 return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl)); 10434 return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
10154} 10435}
10436
10155/* end functions related to vl arbitration table caching */ 10437/* end functions related to vl arbitration table caching */
10156 10438
10157static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target, 10439static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
@@ -10239,7 +10521,7 @@ static int get_buffer_control(struct hfi1_devdata *dd,
10239 10521
10240 /* OPA and HFI have a 1-1 mapping */ 10522 /* OPA and HFI have a 1-1 mapping */
10241 for (i = 0; i < TXE_NUM_DATA_VL; i++) 10523 for (i = 0; i < TXE_NUM_DATA_VL; i++)
10242 read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8*i), &bc->vl[i]); 10524 read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
10243 10525
10244 /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */ 10526 /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
10245 read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]); 10527 read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
@@ -10293,41 +10575,41 @@ static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
10293static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp) 10575static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
10294{ 10576{
10295 write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, 10577 write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
10296 DC_SC_VL_VAL(15_0, 10578 DC_SC_VL_VAL(15_0,
10297 0, dp->vlnt[0] & 0xf, 10579 0, dp->vlnt[0] & 0xf,
10298 1, dp->vlnt[1] & 0xf, 10580 1, dp->vlnt[1] & 0xf,
10299 2, dp->vlnt[2] & 0xf, 10581 2, dp->vlnt[2] & 0xf,
10300 3, dp->vlnt[3] & 0xf, 10582 3, dp->vlnt[3] & 0xf,
10301 4, dp->vlnt[4] & 0xf, 10583 4, dp->vlnt[4] & 0xf,
10302 5, dp->vlnt[5] & 0xf, 10584 5, dp->vlnt[5] & 0xf,
10303 6, dp->vlnt[6] & 0xf, 10585 6, dp->vlnt[6] & 0xf,
10304 7, dp->vlnt[7] & 0xf, 10586 7, dp->vlnt[7] & 0xf,
10305 8, dp->vlnt[8] & 0xf, 10587 8, dp->vlnt[8] & 0xf,
10306 9, dp->vlnt[9] & 0xf, 10588 9, dp->vlnt[9] & 0xf,
10307 10, dp->vlnt[10] & 0xf, 10589 10, dp->vlnt[10] & 0xf,
10308 11, dp->vlnt[11] & 0xf, 10590 11, dp->vlnt[11] & 0xf,
10309 12, dp->vlnt[12] & 0xf, 10591 12, dp->vlnt[12] & 0xf,
10310 13, dp->vlnt[13] & 0xf, 10592 13, dp->vlnt[13] & 0xf,
10311 14, dp->vlnt[14] & 0xf, 10593 14, dp->vlnt[14] & 0xf,
10312 15, dp->vlnt[15] & 0xf)); 10594 15, dp->vlnt[15] & 0xf));
10313 write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, 10595 write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
10314 DC_SC_VL_VAL(31_16, 10596 DC_SC_VL_VAL(31_16,
10315 16, dp->vlnt[16] & 0xf, 10597 16, dp->vlnt[16] & 0xf,
10316 17, dp->vlnt[17] & 0xf, 10598 17, dp->vlnt[17] & 0xf,
10317 18, dp->vlnt[18] & 0xf, 10599 18, dp->vlnt[18] & 0xf,
10318 19, dp->vlnt[19] & 0xf, 10600 19, dp->vlnt[19] & 0xf,
10319 20, dp->vlnt[20] & 0xf, 10601 20, dp->vlnt[20] & 0xf,
10320 21, dp->vlnt[21] & 0xf, 10602 21, dp->vlnt[21] & 0xf,
10321 22, dp->vlnt[22] & 0xf, 10603 22, dp->vlnt[22] & 0xf,
10322 23, dp->vlnt[23] & 0xf, 10604 23, dp->vlnt[23] & 0xf,
10323 24, dp->vlnt[24] & 0xf, 10605 24, dp->vlnt[24] & 0xf,
10324 25, dp->vlnt[25] & 0xf, 10606 25, dp->vlnt[25] & 0xf,
10325 26, dp->vlnt[26] & 0xf, 10607 26, dp->vlnt[26] & 0xf,
10326 27, dp->vlnt[27] & 0xf, 10608 27, dp->vlnt[27] & 0xf,
10327 28, dp->vlnt[28] & 0xf, 10609 28, dp->vlnt[28] & 0xf,
10328 29, dp->vlnt[29] & 0xf, 10610 29, dp->vlnt[29] & 0xf,
10329 30, dp->vlnt[30] & 0xf, 10611 30, dp->vlnt[30] & 0xf,
10330 31, dp->vlnt[31] & 0xf)); 10612 31, dp->vlnt[31] & 0xf));
10331} 10613}
10332 10614
10333static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what, 10615static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
@@ -10335,7 +10617,7 @@ static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
10335{ 10617{
10336 if (limit != 0) 10618 if (limit != 0)
10337 dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n", 10619 dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
10338 what, (int)limit, idx); 10620 what, (int)limit, idx);
10339} 10621}
10340 10622
10341/* change only the shared limit portion of SendCmGLobalCredit */ 10623/* change only the shared limit portion of SendCmGLobalCredit */
@@ -10413,14 +10695,14 @@ static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
10413 } 10695 }
10414 10696
10415 dd_dev_err(dd, 10697 dd_dev_err(dd,
10416 "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n", 10698 "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
10417 which, VL_STATUS_CLEAR_TIMEOUT, mask, reg); 10699 which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
10418 /* 10700 /*
10419 * If this occurs, it is likely there was a credit loss on the link. 10701 * If this occurs, it is likely there was a credit loss on the link.
10420 * The only recovery from that is a link bounce. 10702 * The only recovery from that is a link bounce.
10421 */ 10703 */
10422 dd_dev_err(dd, 10704 dd_dev_err(dd,
10423 "Continuing anyway. A credit loss may occur. Suggest a link bounce\n"); 10705 "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
10424} 10706}
10425 10707
10426/* 10708/*
@@ -10447,13 +10729,15 @@ static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
10447 * raise = if the new limit is higher than the current value (may be changed 10729 * raise = if the new limit is higher than the current value (may be changed
10448 * earlier in the algorithm), set the new limit to the new value 10730 * earlier in the algorithm), set the new limit to the new value
10449 */ 10731 */
10450static int set_buffer_control(struct hfi1_devdata *dd, 10732int set_buffer_control(struct hfi1_pportdata *ppd,
10451 struct buffer_control *new_bc) 10733 struct buffer_control *new_bc)
10452{ 10734{
10735 struct hfi1_devdata *dd = ppd->dd;
10453 u64 changing_mask, ld_mask, stat_mask; 10736 u64 changing_mask, ld_mask, stat_mask;
10454 int change_count; 10737 int change_count;
10455 int i, use_all_mask; 10738 int i, use_all_mask;
10456 int this_shared_changing; 10739 int this_shared_changing;
10740 int vl_count = 0, ret;
10457 /* 10741 /*
10458 * A0: add the variable any_shared_limit_changing below and in the 10742 * A0: add the variable any_shared_limit_changing below and in the
10459 * algorithm above. If removing A0 support, it can be removed. 10743 * algorithm above. If removing A0 support, it can be removed.
@@ -10478,7 +10762,6 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10478#define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15) 10762#define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
10479#define NUM_USABLE_VLS 16 /* look at VL15 and less */ 10763#define NUM_USABLE_VLS 16 /* look at VL15 and less */
10480 10764
10481
10482 /* find the new total credits, do sanity check on unused VLs */ 10765 /* find the new total credits, do sanity check on unused VLs */
10483 for (i = 0; i < OPA_MAX_VLS; i++) { 10766 for (i = 0; i < OPA_MAX_VLS; i++) {
10484 if (valid_vl(i)) { 10767 if (valid_vl(i)) {
@@ -10486,9 +10769,9 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10486 continue; 10769 continue;
10487 } 10770 }
10488 nonzero_msg(dd, i, "dedicated", 10771 nonzero_msg(dd, i, "dedicated",
10489 be16_to_cpu(new_bc->vl[i].dedicated)); 10772 be16_to_cpu(new_bc->vl[i].dedicated));
10490 nonzero_msg(dd, i, "shared", 10773 nonzero_msg(dd, i, "shared",
10491 be16_to_cpu(new_bc->vl[i].shared)); 10774 be16_to_cpu(new_bc->vl[i].shared));
10492 new_bc->vl[i].dedicated = 0; 10775 new_bc->vl[i].dedicated = 0;
10493 new_bc->vl[i].shared = 0; 10776 new_bc->vl[i].shared = 0;
10494 } 10777 }
@@ -10502,8 +10785,10 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10502 */ 10785 */
10503 memset(changing, 0, sizeof(changing)); 10786 memset(changing, 0, sizeof(changing));
10504 memset(lowering_dedicated, 0, sizeof(lowering_dedicated)); 10787 memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
10505 /* NOTE: Assumes that the individual VL bits are adjacent and in 10788 /*
10506 increasing order */ 10789 * NOTE: Assumes that the individual VL bits are adjacent and in
10790 * increasing order
10791 */
10507 stat_mask = 10792 stat_mask =
10508 SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK; 10793 SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
10509 changing_mask = 0; 10794 changing_mask = 0;
@@ -10517,8 +10802,8 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10517 != cur_bc.vl[i].shared; 10802 != cur_bc.vl[i].shared;
10518 if (this_shared_changing) 10803 if (this_shared_changing)
10519 any_shared_limit_changing = 1; 10804 any_shared_limit_changing = 1;
10520 if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated 10805 if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
10521 || this_shared_changing) { 10806 this_shared_changing) {
10522 changing[i] = 1; 10807 changing[i] = 1;
10523 changing_mask |= stat_mask; 10808 changing_mask |= stat_mask;
10524 change_count++; 10809 change_count++;
@@ -10557,7 +10842,7 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10557 } 10842 }
10558 10843
10559 wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask, 10844 wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
10560 "shared"); 10845 "shared");
10561 10846
10562 if (change_count > 0) { 10847 if (change_count > 0) {
10563 for (i = 0; i < NUM_USABLE_VLS; i++) { 10848 for (i = 0; i < NUM_USABLE_VLS; i++) {
@@ -10566,7 +10851,8 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10566 10851
10567 if (lowering_dedicated[i]) { 10852 if (lowering_dedicated[i]) {
10568 set_vl_dedicated(dd, i, 10853 set_vl_dedicated(dd, i,
10569 be16_to_cpu(new_bc->vl[i].dedicated)); 10854 be16_to_cpu(new_bc->
10855 vl[i].dedicated));
10570 cur_bc.vl[i].dedicated = 10856 cur_bc.vl[i].dedicated =
10571 new_bc->vl[i].dedicated; 10857 new_bc->vl[i].dedicated;
10572 } 10858 }
@@ -10582,7 +10868,8 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10582 if (be16_to_cpu(new_bc->vl[i].dedicated) > 10868 if (be16_to_cpu(new_bc->vl[i].dedicated) >
10583 be16_to_cpu(cur_bc.vl[i].dedicated)) 10869 be16_to_cpu(cur_bc.vl[i].dedicated))
10584 set_vl_dedicated(dd, i, 10870 set_vl_dedicated(dd, i,
10585 be16_to_cpu(new_bc->vl[i].dedicated)); 10871 be16_to_cpu(new_bc->
10872 vl[i].dedicated));
10586 } 10873 }
10587 } 10874 }
10588 10875
@@ -10598,13 +10885,35 @@ static int set_buffer_control(struct hfi1_devdata *dd,
10598 10885
10599 /* finally raise the global shared */ 10886 /* finally raise the global shared */
10600 if (be16_to_cpu(new_bc->overall_shared_limit) > 10887 if (be16_to_cpu(new_bc->overall_shared_limit) >
10601 be16_to_cpu(cur_bc.overall_shared_limit)) 10888 be16_to_cpu(cur_bc.overall_shared_limit))
10602 set_global_shared(dd, 10889 set_global_shared(dd,
10603 be16_to_cpu(new_bc->overall_shared_limit)); 10890 be16_to_cpu(new_bc->overall_shared_limit));
10604 10891
10605 /* bracket the credit change with a total adjustment */ 10892 /* bracket the credit change with a total adjustment */
10606 if (new_total < cur_total) 10893 if (new_total < cur_total)
10607 set_global_limit(dd, new_total); 10894 set_global_limit(dd, new_total);
10895
10896 /*
10897 * Determine the actual number of operational VLS using the number of
10898 * dedicated and shared credits for each VL.
10899 */
10900 if (change_count > 0) {
10901 for (i = 0; i < TXE_NUM_DATA_VL; i++)
10902 if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
10903 be16_to_cpu(new_bc->vl[i].shared) > 0)
10904 vl_count++;
10905 ppd->actual_vls_operational = vl_count;
10906 ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
10907 ppd->actual_vls_operational :
10908 ppd->vls_operational,
10909 NULL);
10910 if (ret == 0)
10911 ret = pio_map_init(dd, ppd->port - 1, vl_count ?
10912 ppd->actual_vls_operational :
10913 ppd->vls_operational, NULL);
10914 if (ret)
10915 return ret;
10916 }
10608 return 0; 10917 return 0;
10609} 10918}
10610 10919
@@ -10696,7 +11005,7 @@ int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
10696 VL_ARB_LOW_PRIO_TABLE_SIZE, t); 11005 VL_ARB_LOW_PRIO_TABLE_SIZE, t);
10697 break; 11006 break;
10698 case FM_TBL_BUFFER_CONTROL: 11007 case FM_TBL_BUFFER_CONTROL:
10699 ret = set_buffer_control(ppd->dd, t); 11008 ret = set_buffer_control(ppd, t);
10700 break; 11009 break;
10701 case FM_TBL_SC2VLNT: 11010 case FM_TBL_SC2VLNT:
10702 set_sc2vlnt(ppd->dd, t); 11011 set_sc2vlnt(ppd->dd, t);
@@ -10846,10 +11155,13 @@ static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
10846 } 11155 }
10847 11156
10848 rcd->rcvavail_timeout = timeout; 11157 rcd->rcvavail_timeout = timeout;
10849 /* timeout cannot be larger than rcv_intr_timeout_csr which has already 11158 /*
10850 been verified to be in range */ 11159 * timeout cannot be larger than rcv_intr_timeout_csr which has already
11160 * been verified to be in range
11161 */
10851 write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT, 11162 write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
10852 (u64)timeout << RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT); 11163 (u64)timeout <<
11164 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
10853} 11165}
10854 11166
10855void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd, 11167void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
@@ -10915,16 +11227,16 @@ u32 hdrqempty(struct hfi1_ctxtdata *rcd)
10915static u32 encoded_size(u32 size) 11227static u32 encoded_size(u32 size)
10916{ 11228{
10917 switch (size) { 11229 switch (size) {
10918 case 4*1024: return 0x1; 11230 case 4 * 1024: return 0x1;
10919 case 8*1024: return 0x2; 11231 case 8 * 1024: return 0x2;
10920 case 16*1024: return 0x3; 11232 case 16 * 1024: return 0x3;
10921 case 32*1024: return 0x4; 11233 case 32 * 1024: return 0x4;
10922 case 64*1024: return 0x5; 11234 case 64 * 1024: return 0x5;
10923 case 128*1024: return 0x6; 11235 case 128 * 1024: return 0x6;
10924 case 256*1024: return 0x7; 11236 case 256 * 1024: return 0x7;
10925 case 512*1024: return 0x8; 11237 case 512 * 1024: return 0x8;
10926 case 1*1024*1024: return 0x9; 11238 case 1 * 1024 * 1024: return 0x9;
10927 case 2*1024*1024: return 0xa; 11239 case 2 * 1024 * 1024: return 0xa;
10928 } 11240 }
10929 return 0x1; /* if invalid, go with the minimum size */ 11241 return 0x1; /* if invalid, go with the minimum size */
10930} 11242}
@@ -10943,8 +11255,8 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
10943 11255
10944 rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL); 11256 rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
10945 /* if the context already enabled, don't do the extra steps */ 11257 /* if the context already enabled, don't do the extra steps */
10946 if ((op & HFI1_RCVCTRL_CTXT_ENB) 11258 if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
10947 && !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) { 11259 !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
10948 /* reset the tail and hdr addresses, and sequence count */ 11260 /* reset the tail and hdr addresses, and sequence count */
10949 write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR, 11261 write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
10950 rcd->rcvhdrq_phys); 11262 rcd->rcvhdrq_phys);
@@ -11018,6 +11330,7 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
11018 if (dd->rcvhdrtail_dummy_physaddr) { 11330 if (dd->rcvhdrtail_dummy_physaddr) {
11019 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR, 11331 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
11020 dd->rcvhdrtail_dummy_physaddr); 11332 dd->rcvhdrtail_dummy_physaddr);
11333 /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
11021 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK; 11334 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
11022 } 11335 }
11023 11336
@@ -11029,15 +11342,20 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
11029 rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK; 11342 rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
11030 if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_phys) 11343 if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_phys)
11031 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK; 11344 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
11032 if (op & HFI1_RCVCTRL_TAILUPD_DIS) 11345 if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
11033 rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK; 11346 /* See comment on RcvCtxtCtrl.TailUpd above */
11347 if (!(op & HFI1_RCVCTRL_CTXT_DIS))
11348 rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
11349 }
11034 if (op & HFI1_RCVCTRL_TIDFLOW_ENB) 11350 if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
11035 rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK; 11351 rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
11036 if (op & HFI1_RCVCTRL_TIDFLOW_DIS) 11352 if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
11037 rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK; 11353 rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
11038 if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) { 11354 if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
11039 /* In one-packet-per-eager mode, the size comes from 11355 /*
11040 the RcvArray entry. */ 11356 * In one-packet-per-eager mode, the size comes from
11357 * the RcvArray entry.
11358 */
11041 rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK; 11359 rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
11042 rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK; 11360 rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
11043 } 11361 }
@@ -11056,19 +11374,19 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
11056 write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl); 11374 write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
11057 11375
11058 /* work around sticky RcvCtxtStatus.BlockedRHQFull */ 11376 /* work around sticky RcvCtxtStatus.BlockedRHQFull */
11059 if (did_enable 11377 if (did_enable &&
11060 && (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) { 11378 (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
11061 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS); 11379 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
11062 if (reg != 0) { 11380 if (reg != 0) {
11063 dd_dev_info(dd, "ctxt %d status %lld (blocked)\n", 11381 dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
11064 ctxt, reg); 11382 ctxt, reg);
11065 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD); 11383 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
11066 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10); 11384 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
11067 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00); 11385 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
11068 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD); 11386 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
11069 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS); 11387 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
11070 dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n", 11388 dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
11071 ctxt, reg, reg == 0 ? "not" : "still"); 11389 ctxt, reg, reg == 0 ? "not" : "still");
11072 } 11390 }
11073 } 11391 }
11074 11392
@@ -11079,7 +11397,7 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
11079 */ 11397 */
11080 /* set interrupt timeout */ 11398 /* set interrupt timeout */
11081 write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT, 11399 write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
11082 (u64)rcd->rcvavail_timeout << 11400 (u64)rcd->rcvavail_timeout <<
11083 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT); 11401 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
11084 11402
11085 /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */ 11403 /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
@@ -11097,28 +11415,19 @@ void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
11097 dd->rcvhdrtail_dummy_physaddr); 11415 dd->rcvhdrtail_dummy_physaddr);
11098} 11416}
11099 11417
11100u32 hfi1_read_cntrs(struct hfi1_devdata *dd, loff_t pos, char **namep, 11418u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
11101 u64 **cntrp)
11102{ 11419{
11103 int ret; 11420 int ret;
11104 u64 val = 0; 11421 u64 val = 0;
11105 11422
11106 if (namep) { 11423 if (namep) {
11107 ret = dd->cntrnameslen; 11424 ret = dd->cntrnameslen;
11108 if (pos != 0) {
11109 dd_dev_err(dd, "read_cntrs does not support indexing");
11110 return 0;
11111 }
11112 *namep = dd->cntrnames; 11425 *namep = dd->cntrnames;
11113 } else { 11426 } else {
11114 const struct cntr_entry *entry; 11427 const struct cntr_entry *entry;
11115 int i, j; 11428 int i, j;
11116 11429
11117 ret = (dd->ndevcntrs) * sizeof(u64); 11430 ret = (dd->ndevcntrs) * sizeof(u64);
11118 if (pos != 0) {
11119 dd_dev_err(dd, "read_cntrs does not support indexing");
11120 return 0;
11121 }
11122 11431
11123 /* Get the start of the block of counters */ 11432 /* Get the start of the block of counters */
11124 *cntrp = dd->cntrs; 11433 *cntrp = dd->cntrs;
@@ -11147,6 +11456,20 @@ u32 hfi1_read_cntrs(struct hfi1_devdata *dd, loff_t pos, char **namep,
11147 dd->cntrs[entry->offset + j] = 11456 dd->cntrs[entry->offset + j] =
11148 val; 11457 val;
11149 } 11458 }
11459 } else if (entry->flags & CNTR_SDMA) {
11460 hfi1_cdbg(CNTR,
11461 "\t Per SDMA Engine\n");
11462 for (j = 0; j < dd->chip_sdma_engines;
11463 j++) {
11464 val =
11465 entry->rw_cntr(entry, dd, j,
11466 CNTR_MODE_R, 0);
11467 hfi1_cdbg(CNTR,
11468 "\t\tRead 0x%llx for %d\n",
11469 val, j);
11470 dd->cntrs[entry->offset + j] =
11471 val;
11472 }
11150 } else { 11473 } else {
11151 val = entry->rw_cntr(entry, dd, 11474 val = entry->rw_cntr(entry, dd,
11152 CNTR_INVALID_VL, 11475 CNTR_INVALID_VL,
@@ -11163,30 +11486,19 @@ u32 hfi1_read_cntrs(struct hfi1_devdata *dd, loff_t pos, char **namep,
11163/* 11486/*
11164 * Used by sysfs to create files for hfi stats to read 11487 * Used by sysfs to create files for hfi stats to read
11165 */ 11488 */
11166u32 hfi1_read_portcntrs(struct hfi1_devdata *dd, loff_t pos, u32 port, 11489u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
11167 char **namep, u64 **cntrp)
11168{ 11490{
11169 int ret; 11491 int ret;
11170 u64 val = 0; 11492 u64 val = 0;
11171 11493
11172 if (namep) { 11494 if (namep) {
11173 ret = dd->portcntrnameslen; 11495 ret = ppd->dd->portcntrnameslen;
11174 if (pos != 0) { 11496 *namep = ppd->dd->portcntrnames;
11175 dd_dev_err(dd, "index not supported");
11176 return 0;
11177 }
11178 *namep = dd->portcntrnames;
11179 } else { 11497 } else {
11180 const struct cntr_entry *entry; 11498 const struct cntr_entry *entry;
11181 struct hfi1_pportdata *ppd;
11182 int i, j; 11499 int i, j;
11183 11500
11184 ret = (dd->nportcntrs) * sizeof(u64); 11501 ret = ppd->dd->nportcntrs * sizeof(u64);
11185 if (pos != 0) {
11186 dd_dev_err(dd, "indexing not supported");
11187 return 0;
11188 }
11189 ppd = (struct hfi1_pportdata *)(dd + 1 + port);
11190 *cntrp = ppd->cntrs; 11502 *cntrp = ppd->cntrs;
11191 11503
11192 for (i = 0; i < PORT_CNTR_LAST; i++) { 11504 for (i = 0; i < PORT_CNTR_LAST; i++) {
@@ -11235,14 +11547,14 @@ static void free_cntrs(struct hfi1_devdata *dd)
11235 for (i = 0; i < dd->num_pports; i++, ppd++) { 11547 for (i = 0; i < dd->num_pports; i++, ppd++) {
11236 kfree(ppd->cntrs); 11548 kfree(ppd->cntrs);
11237 kfree(ppd->scntrs); 11549 kfree(ppd->scntrs);
11238 free_percpu(ppd->ibport_data.rc_acks); 11550 free_percpu(ppd->ibport_data.rvp.rc_acks);
11239 free_percpu(ppd->ibport_data.rc_qacks); 11551 free_percpu(ppd->ibport_data.rvp.rc_qacks);
11240 free_percpu(ppd->ibport_data.rc_delayed_comp); 11552 free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
11241 ppd->cntrs = NULL; 11553 ppd->cntrs = NULL;
11242 ppd->scntrs = NULL; 11554 ppd->scntrs = NULL;
11243 ppd->ibport_data.rc_acks = NULL; 11555 ppd->ibport_data.rvp.rc_acks = NULL;
11244 ppd->ibport_data.rc_qacks = NULL; 11556 ppd->ibport_data.rvp.rc_qacks = NULL;
11245 ppd->ibport_data.rc_delayed_comp = NULL; 11557 ppd->ibport_data.rvp.rc_delayed_comp = NULL;
11246 } 11558 }
11247 kfree(dd->portcntrnames); 11559 kfree(dd->portcntrnames);
11248 dd->portcntrnames = NULL; 11560 dd->portcntrnames = NULL;
@@ -11510,11 +11822,13 @@ mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
11510#define C_MAX_NAME 13 /* 12 chars + one for /0 */ 11822#define C_MAX_NAME 13 /* 12 chars + one for /0 */
11511static int init_cntrs(struct hfi1_devdata *dd) 11823static int init_cntrs(struct hfi1_devdata *dd)
11512{ 11824{
11513 int i, rcv_ctxts, index, j; 11825 int i, rcv_ctxts, j;
11514 size_t sz; 11826 size_t sz;
11515 char *p; 11827 char *p;
11516 char name[C_MAX_NAME]; 11828 char name[C_MAX_NAME];
11517 struct hfi1_pportdata *ppd; 11829 struct hfi1_pportdata *ppd;
11830 const char *bit_type_32 = ",32";
11831 const int bit_type_32_sz = strlen(bit_type_32);
11518 11832
11519 /* set up the stats timer; the add_timer is done at the end */ 11833 /* set up the stats timer; the add_timer is done at the end */
11520 setup_timer(&dd->synth_stats_timer, update_synth_timer, 11834 setup_timer(&dd->synth_stats_timer, update_synth_timer,
@@ -11527,49 +11841,57 @@ static int init_cntrs(struct hfi1_devdata *dd)
11527 /* size names and determine how many we have*/ 11841 /* size names and determine how many we have*/
11528 dd->ndevcntrs = 0; 11842 dd->ndevcntrs = 0;
11529 sz = 0; 11843 sz = 0;
11530 index = 0;
11531 11844
11532 for (i = 0; i < DEV_CNTR_LAST; i++) { 11845 for (i = 0; i < DEV_CNTR_LAST; i++) {
11533 hfi1_dbg_early("Init cntr %s\n", dev_cntrs[i].name);
11534 if (dev_cntrs[i].flags & CNTR_DISABLED) { 11846 if (dev_cntrs[i].flags & CNTR_DISABLED) {
11535 hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name); 11847 hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
11536 continue; 11848 continue;
11537 } 11849 }
11538 11850
11539 if (dev_cntrs[i].flags & CNTR_VL) { 11851 if (dev_cntrs[i].flags & CNTR_VL) {
11540 hfi1_dbg_early("\tProcessing VL cntr\n"); 11852 dev_cntrs[i].offset = dd->ndevcntrs;
11541 dev_cntrs[i].offset = index;
11542 for (j = 0; j < C_VL_COUNT; j++) { 11853 for (j = 0; j < C_VL_COUNT; j++) {
11543 memset(name, '\0', C_MAX_NAME);
11544 snprintf(name, C_MAX_NAME, "%s%d", 11854 snprintf(name, C_MAX_NAME, "%s%d",
11545 dev_cntrs[i].name, 11855 dev_cntrs[i].name, vl_from_idx(j));
11546 vl_from_idx(j)); 11856 sz += strlen(name);
11857 /* Add ",32" for 32-bit counters */
11858 if (dev_cntrs[i].flags & CNTR_32BIT)
11859 sz += bit_type_32_sz;
11860 sz++;
11861 dd->ndevcntrs++;
11862 }
11863 } else if (dev_cntrs[i].flags & CNTR_SDMA) {
11864 dev_cntrs[i].offset = dd->ndevcntrs;
11865 for (j = 0; j < dd->chip_sdma_engines; j++) {
11866 snprintf(name, C_MAX_NAME, "%s%d",
11867 dev_cntrs[i].name, j);
11547 sz += strlen(name); 11868 sz += strlen(name);
11869 /* Add ",32" for 32-bit counters */
11870 if (dev_cntrs[i].flags & CNTR_32BIT)
11871 sz += bit_type_32_sz;
11548 sz++; 11872 sz++;
11549 hfi1_dbg_early("\t\t%s\n", name);
11550 dd->ndevcntrs++; 11873 dd->ndevcntrs++;
11551 index++;
11552 } 11874 }
11553 } else { 11875 } else {
11554 /* +1 for newline */ 11876 /* +1 for newline. */
11555 sz += strlen(dev_cntrs[i].name) + 1; 11877 sz += strlen(dev_cntrs[i].name) + 1;
11878 /* Add ",32" for 32-bit counters */
11879 if (dev_cntrs[i].flags & CNTR_32BIT)
11880 sz += bit_type_32_sz;
11881 dev_cntrs[i].offset = dd->ndevcntrs;
11556 dd->ndevcntrs++; 11882 dd->ndevcntrs++;
11557 dev_cntrs[i].offset = index;
11558 index++;
11559 hfi1_dbg_early("\tAdding %s\n", dev_cntrs[i].name);
11560 } 11883 }
11561 } 11884 }
11562 11885
11563 /* allocate space for the counter values */ 11886 /* allocate space for the counter values */
11564 dd->cntrs = kcalloc(index, sizeof(u64), GFP_KERNEL); 11887 dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
11565 if (!dd->cntrs) 11888 if (!dd->cntrs)
11566 goto bail; 11889 goto bail;
11567 11890
11568 dd->scntrs = kcalloc(index, sizeof(u64), GFP_KERNEL); 11891 dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
11569 if (!dd->scntrs) 11892 if (!dd->scntrs)
11570 goto bail; 11893 goto bail;
11571 11894
11572
11573 /* allocate space for the counter names */ 11895 /* allocate space for the counter names */
11574 dd->cntrnameslen = sz; 11896 dd->cntrnameslen = sz;
11575 dd->cntrnames = kmalloc(sz, GFP_KERNEL); 11897 dd->cntrnames = kmalloc(sz, GFP_KERNEL);
@@ -11577,27 +11899,51 @@ static int init_cntrs(struct hfi1_devdata *dd)
11577 goto bail; 11899 goto bail;
11578 11900
11579 /* fill in the names */ 11901 /* fill in the names */
11580 for (p = dd->cntrnames, i = 0, index = 0; i < DEV_CNTR_LAST; i++) { 11902 for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
11581 if (dev_cntrs[i].flags & CNTR_DISABLED) { 11903 if (dev_cntrs[i].flags & CNTR_DISABLED) {
11582 /* Nothing */ 11904 /* Nothing */
11583 } else { 11905 } else if (dev_cntrs[i].flags & CNTR_VL) {
11584 if (dev_cntrs[i].flags & CNTR_VL) { 11906 for (j = 0; j < C_VL_COUNT; j++) {
11585 for (j = 0; j < C_VL_COUNT; j++) { 11907 snprintf(name, C_MAX_NAME, "%s%d",
11586 memset(name, '\0', C_MAX_NAME); 11908 dev_cntrs[i].name,
11587 snprintf(name, C_MAX_NAME, "%s%d", 11909 vl_from_idx(j));
11588 dev_cntrs[i].name, 11910 memcpy(p, name, strlen(name));
11589 vl_from_idx(j)); 11911 p += strlen(name);
11590 memcpy(p, name, strlen(name)); 11912
11591 p += strlen(name); 11913 /* Counter is 32 bits */
11592 *p++ = '\n'; 11914 if (dev_cntrs[i].flags & CNTR_32BIT) {
11915 memcpy(p, bit_type_32, bit_type_32_sz);
11916 p += bit_type_32_sz;
11593 } 11917 }
11594 } else { 11918
11595 memcpy(p, dev_cntrs[i].name, 11919 *p++ = '\n';
11596 strlen(dev_cntrs[i].name)); 11920 }
11597 p += strlen(dev_cntrs[i].name); 11921 } else if (dev_cntrs[i].flags & CNTR_SDMA) {
11922 for (j = 0; j < dd->chip_sdma_engines; j++) {
11923 snprintf(name, C_MAX_NAME, "%s%d",
11924 dev_cntrs[i].name, j);
11925 memcpy(p, name, strlen(name));
11926 p += strlen(name);
11927
11928 /* Counter is 32 bits */
11929 if (dev_cntrs[i].flags & CNTR_32BIT) {
11930 memcpy(p, bit_type_32, bit_type_32_sz);
11931 p += bit_type_32_sz;
11932 }
11933
11598 *p++ = '\n'; 11934 *p++ = '\n';
11599 } 11935 }
11600 index++; 11936 } else {
11937 memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
11938 p += strlen(dev_cntrs[i].name);
11939
11940 /* Counter is 32 bits */
11941 if (dev_cntrs[i].flags & CNTR_32BIT) {
11942 memcpy(p, bit_type_32, bit_type_32_sz);
11943 p += bit_type_32_sz;
11944 }
11945
11946 *p++ = '\n';
11601 } 11947 }
11602 } 11948 }
11603 11949
@@ -11620,31 +11966,31 @@ static int init_cntrs(struct hfi1_devdata *dd)
11620 sz = 0; 11966 sz = 0;
11621 dd->nportcntrs = 0; 11967 dd->nportcntrs = 0;
11622 for (i = 0; i < PORT_CNTR_LAST; i++) { 11968 for (i = 0; i < PORT_CNTR_LAST; i++) {
11623 hfi1_dbg_early("Init pcntr %s\n", port_cntrs[i].name);
11624 if (port_cntrs[i].flags & CNTR_DISABLED) { 11969 if (port_cntrs[i].flags & CNTR_DISABLED) {
11625 hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name); 11970 hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
11626 continue; 11971 continue;
11627 } 11972 }
11628 11973
11629 if (port_cntrs[i].flags & CNTR_VL) { 11974 if (port_cntrs[i].flags & CNTR_VL) {
11630 hfi1_dbg_early("\tProcessing VL cntr\n");
11631 port_cntrs[i].offset = dd->nportcntrs; 11975 port_cntrs[i].offset = dd->nportcntrs;
11632 for (j = 0; j < C_VL_COUNT; j++) { 11976 for (j = 0; j < C_VL_COUNT; j++) {
11633 memset(name, '\0', C_MAX_NAME);
11634 snprintf(name, C_MAX_NAME, "%s%d", 11977 snprintf(name, C_MAX_NAME, "%s%d",
11635 port_cntrs[i].name, 11978 port_cntrs[i].name, vl_from_idx(j));
11636 vl_from_idx(j));
11637 sz += strlen(name); 11979 sz += strlen(name);
11980 /* Add ",32" for 32-bit counters */
11981 if (port_cntrs[i].flags & CNTR_32BIT)
11982 sz += bit_type_32_sz;
11638 sz++; 11983 sz++;
11639 hfi1_dbg_early("\t\t%s\n", name);
11640 dd->nportcntrs++; 11984 dd->nportcntrs++;
11641 } 11985 }
11642 } else { 11986 } else {
11643 /* +1 for newline */ 11987 /* +1 for newline */
11644 sz += strlen(port_cntrs[i].name) + 1; 11988 sz += strlen(port_cntrs[i].name) + 1;
11989 /* Add ",32" for 32-bit counters */
11990 if (port_cntrs[i].flags & CNTR_32BIT)
11991 sz += bit_type_32_sz;
11645 port_cntrs[i].offset = dd->nportcntrs; 11992 port_cntrs[i].offset = dd->nportcntrs;
11646 dd->nportcntrs++; 11993 dd->nportcntrs++;
11647 hfi1_dbg_early("\tAdding %s\n", port_cntrs[i].name);
11648 } 11994 }
11649 } 11995 }
11650 11996
@@ -11661,18 +12007,30 @@ static int init_cntrs(struct hfi1_devdata *dd)
11661 12007
11662 if (port_cntrs[i].flags & CNTR_VL) { 12008 if (port_cntrs[i].flags & CNTR_VL) {
11663 for (j = 0; j < C_VL_COUNT; j++) { 12009 for (j = 0; j < C_VL_COUNT; j++) {
11664 memset(name, '\0', C_MAX_NAME);
11665 snprintf(name, C_MAX_NAME, "%s%d", 12010 snprintf(name, C_MAX_NAME, "%s%d",
11666 port_cntrs[i].name, 12011 port_cntrs[i].name, vl_from_idx(j));
11667 vl_from_idx(j));
11668 memcpy(p, name, strlen(name)); 12012 memcpy(p, name, strlen(name));
11669 p += strlen(name); 12013 p += strlen(name);
12014
12015 /* Counter is 32 bits */
12016 if (port_cntrs[i].flags & CNTR_32BIT) {
12017 memcpy(p, bit_type_32, bit_type_32_sz);
12018 p += bit_type_32_sz;
12019 }
12020
11670 *p++ = '\n'; 12021 *p++ = '\n';
11671 } 12022 }
11672 } else { 12023 } else {
11673 memcpy(p, port_cntrs[i].name, 12024 memcpy(p, port_cntrs[i].name,
11674 strlen(port_cntrs[i].name)); 12025 strlen(port_cntrs[i].name));
11675 p += strlen(port_cntrs[i].name); 12026 p += strlen(port_cntrs[i].name);
12027
12028 /* Counter is 32 bits */
12029 if (port_cntrs[i].flags & CNTR_32BIT) {
12030 memcpy(p, bit_type_32, bit_type_32_sz);
12031 p += bit_type_32_sz;
12032 }
12033
11676 *p++ = '\n'; 12034 *p++ = '\n';
11677 } 12035 }
11678 } 12036 }
@@ -11700,14 +12058,13 @@ bail:
11700 return -ENOMEM; 12058 return -ENOMEM;
11701} 12059}
11702 12060
11703
11704static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate) 12061static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
11705{ 12062{
11706 switch (chip_lstate) { 12063 switch (chip_lstate) {
11707 default: 12064 default:
11708 dd_dev_err(dd, 12065 dd_dev_err(dd,
11709 "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n", 12066 "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
11710 chip_lstate); 12067 chip_lstate);
11711 /* fall through */ 12068 /* fall through */
11712 case LSTATE_DOWN: 12069 case LSTATE_DOWN:
11713 return IB_PORT_DOWN; 12070 return IB_PORT_DOWN;
@@ -11726,7 +12083,7 @@ u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
11726 switch (chip_pstate & 0xf0) { 12083 switch (chip_pstate & 0xf0) {
11727 default: 12084 default:
11728 dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n", 12085 dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
11729 chip_pstate); 12086 chip_pstate);
11730 /* fall through */ 12087 /* fall through */
11731 case PLS_DISABLED: 12088 case PLS_DISABLED:
11732 return IB_PORTPHYSSTATE_DISABLED; 12089 return IB_PORTPHYSSTATE_DISABLED;
@@ -11792,7 +12149,7 @@ u32 get_logical_state(struct hfi1_pportdata *ppd)
11792 new_state = chip_to_opa_lstate(ppd->dd, read_logical_state(ppd->dd)); 12149 new_state = chip_to_opa_lstate(ppd->dd, read_logical_state(ppd->dd));
11793 if (new_state != ppd->lstate) { 12150 if (new_state != ppd->lstate) {
11794 dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n", 12151 dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n",
11795 opa_lstate_name(new_state), new_state); 12152 opa_lstate_name(new_state), new_state);
11796 ppd->lstate = new_state; 12153 ppd->lstate = new_state;
11797 } 12154 }
11798 /* 12155 /*
@@ -11851,18 +12208,17 @@ static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
11851 12208
11852u8 hfi1_ibphys_portstate(struct hfi1_pportdata *ppd) 12209u8 hfi1_ibphys_portstate(struct hfi1_pportdata *ppd)
11853{ 12210{
11854 static u32 remembered_state = 0xff;
11855 u32 pstate; 12211 u32 pstate;
11856 u32 ib_pstate; 12212 u32 ib_pstate;
11857 12213
11858 pstate = read_physical_state(ppd->dd); 12214 pstate = read_physical_state(ppd->dd);
11859 ib_pstate = chip_to_opa_pstate(ppd->dd, pstate); 12215 ib_pstate = chip_to_opa_pstate(ppd->dd, pstate);
11860 if (remembered_state != ib_pstate) { 12216 if (ppd->last_pstate != ib_pstate) {
11861 dd_dev_info(ppd->dd, 12217 dd_dev_info(ppd->dd,
11862 "%s: physical state changed to %s (0x%x), phy 0x%x\n", 12218 "%s: physical state changed to %s (0x%x), phy 0x%x\n",
11863 __func__, opa_pstate_name(ib_pstate), ib_pstate, 12219 __func__, opa_pstate_name(ib_pstate), ib_pstate,
11864 pstate); 12220 pstate);
11865 remembered_state = ib_pstate; 12221 ppd->last_pstate = ib_pstate;
11866 } 12222 }
11867 return ib_pstate; 12223 return ib_pstate;
11868} 12224}
@@ -11906,7 +12262,7 @@ u64 hfi1_gpio_mod(struct hfi1_devdata *dd, u32 target, u32 data, u32 dir,
11906 12262
11907int hfi1_init_ctxt(struct send_context *sc) 12263int hfi1_init_ctxt(struct send_context *sc)
11908{ 12264{
11909 if (sc != NULL) { 12265 if (sc) {
11910 struct hfi1_devdata *dd = sc->dd; 12266 struct hfi1_devdata *dd = sc->dd;
11911 u64 reg; 12267 u64 reg;
11912 u8 set = (sc->type == SC_USER ? 12268 u8 set = (sc->type == SC_USER ?
@@ -11963,34 +12319,14 @@ void set_intr_state(struct hfi1_devdata *dd, u32 enable)
11963 * In HFI, the mask needs to be 1 to allow interrupts. 12319 * In HFI, the mask needs to be 1 to allow interrupts.
11964 */ 12320 */
11965 if (enable) { 12321 if (enable) {
11966 u64 cce_int_mask;
11967 const int qsfp1_int_smask = QSFP1_INT % 64;
11968 const int qsfp2_int_smask = QSFP2_INT % 64;
11969
11970 /* enable all interrupts */ 12322 /* enable all interrupts */
11971 for (i = 0; i < CCE_NUM_INT_CSRS; i++) 12323 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
11972 write_csr(dd, CCE_INT_MASK + (8*i), ~(u64)0); 12324 write_csr(dd, CCE_INT_MASK + (8 * i), ~(u64)0);
11973 12325
11974 /* 12326 init_qsfp_int(dd);
11975 * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
11976 * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
11977 * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
11978 * the index of the appropriate CSR in the CCEIntMask CSR array
11979 */
11980 cce_int_mask = read_csr(dd, CCE_INT_MASK +
11981 (8*(QSFP1_INT/64)));
11982 if (dd->hfi1_id) {
11983 cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
11984 write_csr(dd, CCE_INT_MASK + (8*(QSFP1_INT/64)),
11985 cce_int_mask);
11986 } else {
11987 cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
11988 write_csr(dd, CCE_INT_MASK + (8*(QSFP2_INT/64)),
11989 cce_int_mask);
11990 }
11991 } else { 12327 } else {
11992 for (i = 0; i < CCE_NUM_INT_CSRS; i++) 12328 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
11993 write_csr(dd, CCE_INT_MASK + (8*i), 0ull); 12329 write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
11994 } 12330 }
11995} 12331}
11996 12332
@@ -12002,7 +12338,7 @@ static void clear_all_interrupts(struct hfi1_devdata *dd)
12002 int i; 12338 int i;
12003 12339
12004 for (i = 0; i < CCE_NUM_INT_CSRS; i++) 12340 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
12005 write_csr(dd, CCE_INT_CLEAR + (8*i), ~(u64)0); 12341 write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
12006 12342
12007 write_csr(dd, CCE_ERR_CLEAR, ~(u64)0); 12343 write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
12008 write_csr(dd, MISC_ERR_CLEAR, ~(u64)0); 12344 write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
@@ -12037,10 +12373,9 @@ static void clean_up_interrupts(struct hfi1_devdata *dd)
12037 struct hfi1_msix_entry *me = dd->msix_entries; 12373 struct hfi1_msix_entry *me = dd->msix_entries;
12038 12374
12039 for (i = 0; i < dd->num_msix_entries; i++, me++) { 12375 for (i = 0; i < dd->num_msix_entries; i++, me++) {
12040 if (me->arg == NULL) /* => no irq, no affinity */ 12376 if (!me->arg) /* => no irq, no affinity */
12041 break; 12377 continue;
12042 irq_set_affinity_hint(dd->msix_entries[i].msix.vector, 12378 hfi1_put_irq_affinity(dd, &dd->msix_entries[i]);
12043 NULL);
12044 free_irq(me->msix.vector, me->arg); 12379 free_irq(me->msix.vector, me->arg);
12045 } 12380 }
12046 } else { 12381 } else {
@@ -12061,8 +12396,6 @@ static void clean_up_interrupts(struct hfi1_devdata *dd)
12061 } 12396 }
12062 12397
12063 /* clean structures */ 12398 /* clean structures */
12064 for (i = 0; i < dd->num_msix_entries; i++)
12065 free_cpumask_var(dd->msix_entries[i].mask);
12066 kfree(dd->msix_entries); 12399 kfree(dd->msix_entries);
12067 dd->msix_entries = NULL; 12400 dd->msix_entries = NULL;
12068 dd->num_msix_entries = 0; 12401 dd->num_msix_entries = 0;
@@ -12085,10 +12418,10 @@ static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
12085 /* direct the chip source to the given MSI-X interrupt */ 12418 /* direct the chip source to the given MSI-X interrupt */
12086 m = isrc / 8; 12419 m = isrc / 8;
12087 n = isrc % 8; 12420 n = isrc % 8;
12088 reg = read_csr(dd, CCE_INT_MAP + (8*m)); 12421 reg = read_csr(dd, CCE_INT_MAP + (8 * m));
12089 reg &= ~((u64)0xff << (8*n)); 12422 reg &= ~((u64)0xff << (8 * n));
12090 reg |= ((u64)msix_intr & 0xff) << (8*n); 12423 reg |= ((u64)msix_intr & 0xff) << (8 * n);
12091 write_csr(dd, CCE_INT_MAP + (8*m), reg); 12424 write_csr(dd, CCE_INT_MAP + (8 * m), reg);
12092} 12425}
12093 12426
12094static void remap_sdma_interrupts(struct hfi1_devdata *dd, 12427static void remap_sdma_interrupts(struct hfi1_devdata *dd,
@@ -12101,12 +12434,12 @@ static void remap_sdma_interrupts(struct hfi1_devdata *dd,
12101 * SDMAProgress 12434 * SDMAProgress
12102 * SDMAIdle 12435 * SDMAIdle
12103 */ 12436 */
12104 remap_intr(dd, IS_SDMA_START + 0*TXE_NUM_SDMA_ENGINES + engine, 12437 remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
12105 msix_intr); 12438 msix_intr);
12106 remap_intr(dd, IS_SDMA_START + 1*TXE_NUM_SDMA_ENGINES + engine, 12439 remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
12107 msix_intr); 12440 msix_intr);
12108 remap_intr(dd, IS_SDMA_START + 2*TXE_NUM_SDMA_ENGINES + engine, 12441 remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
12109 msix_intr); 12442 msix_intr);
12110} 12443}
12111 12444
12112static int request_intx_irq(struct hfi1_devdata *dd) 12445static int request_intx_irq(struct hfi1_devdata *dd)
@@ -12116,10 +12449,10 @@ static int request_intx_irq(struct hfi1_devdata *dd)
12116 snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME "_%d", 12449 snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME "_%d",
12117 dd->unit); 12450 dd->unit);
12118 ret = request_irq(dd->pcidev->irq, general_interrupt, 12451 ret = request_irq(dd->pcidev->irq, general_interrupt,
12119 IRQF_SHARED, dd->intx_name, dd); 12452 IRQF_SHARED, dd->intx_name, dd);
12120 if (ret) 12453 if (ret)
12121 dd_dev_err(dd, "unable to request INTx interrupt, err %d\n", 12454 dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
12122 ret); 12455 ret);
12123 else 12456 else
12124 dd->requested_intx_irq = 1; 12457 dd->requested_intx_irq = 1;
12125 return ret; 12458 return ret;
@@ -12127,70 +12460,20 @@ static int request_intx_irq(struct hfi1_devdata *dd)
12127 12460
12128static int request_msix_irqs(struct hfi1_devdata *dd) 12461static int request_msix_irqs(struct hfi1_devdata *dd)
12129{ 12462{
12130 const struct cpumask *local_mask;
12131 cpumask_var_t def, rcv;
12132 bool def_ret, rcv_ret;
12133 int first_general, last_general; 12463 int first_general, last_general;
12134 int first_sdma, last_sdma; 12464 int first_sdma, last_sdma;
12135 int first_rx, last_rx; 12465 int first_rx, last_rx;
12136 int first_cpu, curr_cpu; 12466 int i, ret = 0;
12137 int rcv_cpu, sdma_cpu;
12138 int i, ret = 0, possible;
12139 int ht;
12140 12467
12141 /* calculate the ranges we are going to use */ 12468 /* calculate the ranges we are going to use */
12142 first_general = 0; 12469 first_general = 0;
12143 first_sdma = last_general = first_general + 1; 12470 last_general = first_general + 1;
12144 first_rx = last_sdma = first_sdma + dd->num_sdma; 12471 first_sdma = last_general;
12472 last_sdma = first_sdma + dd->num_sdma;
12473 first_rx = last_sdma;
12145 last_rx = first_rx + dd->n_krcv_queues; 12474 last_rx = first_rx + dd->n_krcv_queues;
12146 12475
12147 /* 12476 /*
12148 * Interrupt affinity.
12149 *
12150 * non-rcv avail gets a default mask that
12151 * starts as possible cpus with threads reset
12152 * and each rcv avail reset.
12153 *
12154 * rcv avail gets node relative 1 wrapping back
12155 * to the node relative 1 as necessary.
12156 *
12157 */
12158 local_mask = cpumask_of_pcibus(dd->pcidev->bus);
12159 /* if first cpu is invalid, use NUMA 0 */
12160 if (cpumask_first(local_mask) >= nr_cpu_ids)
12161 local_mask = topology_core_cpumask(0);
12162
12163 def_ret = zalloc_cpumask_var(&def, GFP_KERNEL);
12164 rcv_ret = zalloc_cpumask_var(&rcv, GFP_KERNEL);
12165 if (!def_ret || !rcv_ret)
12166 goto bail;
12167 /* use local mask as default */
12168 cpumask_copy(def, local_mask);
12169 possible = cpumask_weight(def);
12170 /* disarm threads from default */
12171 ht = cpumask_weight(
12172 topology_sibling_cpumask(cpumask_first(local_mask)));
12173 for (i = possible/ht; i < possible; i++)
12174 cpumask_clear_cpu(i, def);
12175 /* def now has full cores on chosen node*/
12176 first_cpu = cpumask_first(def);
12177 if (nr_cpu_ids >= first_cpu)
12178 first_cpu++;
12179 curr_cpu = first_cpu;
12180
12181 /* One context is reserved as control context */
12182 for (i = first_cpu; i < dd->n_krcv_queues + first_cpu - 1; i++) {
12183 cpumask_clear_cpu(curr_cpu, def);
12184 cpumask_set_cpu(curr_cpu, rcv);
12185 curr_cpu = cpumask_next(curr_cpu, def);
12186 if (curr_cpu >= nr_cpu_ids)
12187 break;
12188 }
12189 /* def mask has non-rcv, rcv has recv mask */
12190 rcv_cpu = cpumask_first(rcv);
12191 sdma_cpu = cpumask_first(def);
12192
12193 /*
12194 * Sanity check - the code expects all SDMA chip source 12477 * Sanity check - the code expects all SDMA chip source
12195 * interrupts to be in the same CSR, starting at bit 0. Verify 12478 * interrupts to be in the same CSR, starting at bit 0. Verify
12196 * that this is true by checking the bit location of the start. 12479 * that this is true by checking the bit location of the start.
@@ -12215,6 +12498,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
12215 snprintf(me->name, sizeof(me->name), 12498 snprintf(me->name, sizeof(me->name),
12216 DRIVER_NAME "_%d", dd->unit); 12499 DRIVER_NAME "_%d", dd->unit);
12217 err_info = "general"; 12500 err_info = "general";
12501 me->type = IRQ_GENERAL;
12218 } else if (first_sdma <= i && i < last_sdma) { 12502 } else if (first_sdma <= i && i < last_sdma) {
12219 idx = i - first_sdma; 12503 idx = i - first_sdma;
12220 sde = &dd->per_sdma[idx]; 12504 sde = &dd->per_sdma[idx];
@@ -12224,6 +12508,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
12224 DRIVER_NAME "_%d sdma%d", dd->unit, idx); 12508 DRIVER_NAME "_%d sdma%d", dd->unit, idx);
12225 err_info = "sdma"; 12509 err_info = "sdma";
12226 remap_sdma_interrupts(dd, idx, i); 12510 remap_sdma_interrupts(dd, idx, i);
12511 me->type = IRQ_SDMA;
12227 } else if (first_rx <= i && i < last_rx) { 12512 } else if (first_rx <= i && i < last_rx) {
12228 idx = i - first_rx; 12513 idx = i - first_rx;
12229 rcd = dd->rcd[idx]; 12514 rcd = dd->rcd[idx];
@@ -12234,9 +12519,9 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
12234 * Set the interrupt register and mask for this 12519 * Set the interrupt register and mask for this
12235 * context's interrupt. 12520 * context's interrupt.
12236 */ 12521 */
12237 rcd->ireg = (IS_RCVAVAIL_START+idx) / 64; 12522 rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
12238 rcd->imask = ((u64)1) << 12523 rcd->imask = ((u64)1) <<
12239 ((IS_RCVAVAIL_START+idx) % 64); 12524 ((IS_RCVAVAIL_START + idx) % 64);
12240 handler = receive_context_interrupt; 12525 handler = receive_context_interrupt;
12241 thread = receive_context_thread; 12526 thread = receive_context_thread;
12242 arg = rcd; 12527 arg = rcd;
@@ -12244,25 +12529,27 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
12244 DRIVER_NAME "_%d kctxt%d", dd->unit, idx); 12529 DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
12245 err_info = "receive context"; 12530 err_info = "receive context";
12246 remap_intr(dd, IS_RCVAVAIL_START + idx, i); 12531 remap_intr(dd, IS_RCVAVAIL_START + idx, i);
12532 me->type = IRQ_RCVCTXT;
12247 } else { 12533 } else {
12248 /* not in our expected range - complain, then 12534 /* not in our expected range - complain, then
12249 ignore it */ 12535 * ignore it
12536 */
12250 dd_dev_err(dd, 12537 dd_dev_err(dd,
12251 "Unexpected extra MSI-X interrupt %d\n", i); 12538 "Unexpected extra MSI-X interrupt %d\n", i);
12252 continue; 12539 continue;
12253 } 12540 }
12254 /* no argument, no interrupt */ 12541 /* no argument, no interrupt */
12255 if (arg == NULL) 12542 if (!arg)
12256 continue; 12543 continue;
12257 /* make sure the name is terminated */ 12544 /* make sure the name is terminated */
12258 me->name[sizeof(me->name)-1] = 0; 12545 me->name[sizeof(me->name) - 1] = 0;
12259 12546
12260 ret = request_threaded_irq(me->msix.vector, handler, thread, 0, 12547 ret = request_threaded_irq(me->msix.vector, handler, thread, 0,
12261 me->name, arg); 12548 me->name, arg);
12262 if (ret) { 12549 if (ret) {
12263 dd_dev_err(dd, 12550 dd_dev_err(dd,
12264 "unable to allocate %s interrupt, vector %d, index %d, err %d\n", 12551 "unable to allocate %s interrupt, vector %d, index %d, err %d\n",
12265 err_info, me->msix.vector, idx, ret); 12552 err_info, me->msix.vector, idx, ret);
12266 return ret; 12553 return ret;
12267 } 12554 }
12268 /* 12555 /*
@@ -12271,52 +12558,13 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
12271 */ 12558 */
12272 me->arg = arg; 12559 me->arg = arg;
12273 12560
12274 if (!zalloc_cpumask_var( 12561 ret = hfi1_get_irq_affinity(dd, me);
12275 &dd->msix_entries[i].mask, 12562 if (ret)
12276 GFP_KERNEL)) 12563 dd_dev_err(dd,
12277 goto bail; 12564 "unable to pin IRQ %d\n", ret);
12278 if (handler == sdma_interrupt) {
12279 dd_dev_info(dd, "sdma engine %d cpu %d\n",
12280 sde->this_idx, sdma_cpu);
12281 sde->cpu = sdma_cpu;
12282 cpumask_set_cpu(sdma_cpu, dd->msix_entries[i].mask);
12283 sdma_cpu = cpumask_next(sdma_cpu, def);
12284 if (sdma_cpu >= nr_cpu_ids)
12285 sdma_cpu = cpumask_first(def);
12286 } else if (handler == receive_context_interrupt) {
12287 dd_dev_info(dd, "rcv ctxt %d cpu %d\n", rcd->ctxt,
12288 (rcd->ctxt == HFI1_CTRL_CTXT) ?
12289 cpumask_first(def) : rcv_cpu);
12290 if (rcd->ctxt == HFI1_CTRL_CTXT) {
12291 /* map to first default */
12292 cpumask_set_cpu(cpumask_first(def),
12293 dd->msix_entries[i].mask);
12294 } else {
12295 cpumask_set_cpu(rcv_cpu,
12296 dd->msix_entries[i].mask);
12297 rcv_cpu = cpumask_next(rcv_cpu, rcv);
12298 if (rcv_cpu >= nr_cpu_ids)
12299 rcv_cpu = cpumask_first(rcv);
12300 }
12301 } else {
12302 /* otherwise first def */
12303 dd_dev_info(dd, "%s cpu %d\n",
12304 err_info, cpumask_first(def));
12305 cpumask_set_cpu(
12306 cpumask_first(def), dd->msix_entries[i].mask);
12307 }
12308 irq_set_affinity_hint(
12309 dd->msix_entries[i].msix.vector,
12310 dd->msix_entries[i].mask);
12311 } 12565 }
12312 12566
12313out:
12314 free_cpumask_var(def);
12315 free_cpumask_var(rcv);
12316 return ret; 12567 return ret;
12317bail:
12318 ret = -ENOMEM;
12319 goto out;
12320} 12568}
12321 12569
12322/* 12570/*
@@ -12333,7 +12581,7 @@ static void reset_interrupts(struct hfi1_devdata *dd)
12333 12581
12334 /* all chip interrupts map to MSI-X 0 */ 12582 /* all chip interrupts map to MSI-X 0 */
12335 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++) 12583 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
12336 write_csr(dd, CCE_INT_MAP + (8*i), 0); 12584 write_csr(dd, CCE_INT_MAP + (8 * i), 0);
12337} 12585}
12338 12586
12339static int set_up_interrupts(struct hfi1_devdata *dd) 12587static int set_up_interrupts(struct hfi1_devdata *dd)
@@ -12442,7 +12690,7 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
12442 */ 12690 */
12443 num_kernel_contexts = n_krcvqs + MIN_KERNEL_KCTXTS - 1; 12691 num_kernel_contexts = n_krcvqs + MIN_KERNEL_KCTXTS - 1;
12444 else 12692 else
12445 num_kernel_contexts = num_online_nodes(); 12693 num_kernel_contexts = num_online_nodes() + 1;
12446 num_kernel_contexts = 12694 num_kernel_contexts =
12447 max_t(int, MIN_KERNEL_KCTXTS, num_kernel_contexts); 12695 max_t(int, MIN_KERNEL_KCTXTS, num_kernel_contexts);
12448 /* 12696 /*
@@ -12483,13 +12731,14 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
12483 dd->num_rcv_contexts = total_contexts; 12731 dd->num_rcv_contexts = total_contexts;
12484 dd->n_krcv_queues = num_kernel_contexts; 12732 dd->n_krcv_queues = num_kernel_contexts;
12485 dd->first_user_ctxt = num_kernel_contexts; 12733 dd->first_user_ctxt = num_kernel_contexts;
12734 dd->num_user_contexts = num_user_contexts;
12486 dd->freectxts = num_user_contexts; 12735 dd->freectxts = num_user_contexts;
12487 dd_dev_info(dd, 12736 dd_dev_info(dd,
12488 "rcv contexts: chip %d, used %d (kernel %d, user %d)\n", 12737 "rcv contexts: chip %d, used %d (kernel %d, user %d)\n",
12489 (int)dd->chip_rcv_contexts, 12738 (int)dd->chip_rcv_contexts,
12490 (int)dd->num_rcv_contexts, 12739 (int)dd->num_rcv_contexts,
12491 (int)dd->n_krcv_queues, 12740 (int)dd->n_krcv_queues,
12492 (int)dd->num_rcv_contexts - dd->n_krcv_queues); 12741 (int)dd->num_rcv_contexts - dd->n_krcv_queues);
12493 12742
12494 /* 12743 /*
12495 * Receive array allocation: 12744 * Receive array allocation:
@@ -12515,8 +12764,8 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
12515 dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) / 12764 dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
12516 dd->rcv_entries.group_size; 12765 dd->rcv_entries.group_size;
12517 dd_dev_info(dd, 12766 dd_dev_info(dd,
12518 "RcvArray group count too high, change to %u\n", 12767 "RcvArray group count too high, change to %u\n",
12519 dd->rcv_entries.ngroups); 12768 dd->rcv_entries.ngroups);
12520 dd->rcv_entries.nctxt_extra = 0; 12769 dd->rcv_entries.nctxt_extra = 0;
12521 } 12770 }
12522 /* 12771 /*
@@ -12582,7 +12831,7 @@ static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
12582 12831
12583 /* CceIntMap */ 12832 /* CceIntMap */
12584 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++) 12833 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
12585 write_csr(dd, CCE_INT_MAP+(8*i), 0); 12834 write_csr(dd, CCE_INT_MAP + (8 * i), 0);
12586 12835
12587 /* SendCtxtCreditReturnAddr */ 12836 /* SendCtxtCreditReturnAddr */
12588 for (i = 0; i < dd->chip_send_contexts; i++) 12837 for (i = 0; i < dd->chip_send_contexts; i++)
@@ -12590,8 +12839,10 @@ static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
12590 12839
12591 /* PIO Send buffers */ 12840 /* PIO Send buffers */
12592 /* SDMA Send buffers */ 12841 /* SDMA Send buffers */
12593 /* These are not normally read, and (presently) have no method 12842 /*
12594 to be read, so are not pre-initialized */ 12843 * These are not normally read, and (presently) have no method
12844 * to be read, so are not pre-initialized
12845 */
12595 12846
12596 /* RcvHdrAddr */ 12847 /* RcvHdrAddr */
12597 /* RcvHdrTailAddr */ 12848 /* RcvHdrTailAddr */
@@ -12600,13 +12851,13 @@ static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
12600 write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0); 12851 write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
12601 write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0); 12852 write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
12602 for (j = 0; j < RXE_NUM_TID_FLOWS; j++) 12853 for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
12603 write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE+(8*j), 0); 12854 write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
12604 } 12855 }
12605 12856
12606 /* RcvArray */ 12857 /* RcvArray */
12607 for (i = 0; i < dd->chip_rcv_array_count; i++) 12858 for (i = 0; i < dd->chip_rcv_array_count; i++)
12608 write_csr(dd, RCV_ARRAY + (8*i), 12859 write_csr(dd, RCV_ARRAY + (8 * i),
12609 RCV_ARRAY_RT_WRITE_ENABLE_SMASK); 12860 RCV_ARRAY_RT_WRITE_ENABLE_SMASK);
12610 12861
12611 /* RcvQPMapTable */ 12862 /* RcvQPMapTable */
12612 for (i = 0; i < 32; i++) 12863 for (i = 0; i < 32; i++)
@@ -12638,8 +12889,8 @@ static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
12638 return; 12889 return;
12639 if (time_after(jiffies, timeout)) { 12890 if (time_after(jiffies, timeout)) {
12640 dd_dev_err(dd, 12891 dd_dev_err(dd,
12641 "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n", 12892 "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
12642 status_bits, reg & status_bits); 12893 status_bits, reg & status_bits);
12643 return; 12894 return;
12644 } 12895 }
12645 udelay(1); 12896 udelay(1);
@@ -12671,7 +12922,7 @@ static void reset_cce_csrs(struct hfi1_devdata *dd)
12671 for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) { 12922 for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
12672 write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0); 12923 write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
12673 write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i), 12924 write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
12674 CCE_MSIX_TABLE_UPPER_RESETCSR); 12925 CCE_MSIX_TABLE_UPPER_RESETCSR);
12675 } 12926 }
12676 for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) { 12927 for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
12677 /* CCE_MSIX_PBA read-only */ 12928 /* CCE_MSIX_PBA read-only */
@@ -12691,91 +12942,6 @@ static void reset_cce_csrs(struct hfi1_devdata *dd)
12691 write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0); 12942 write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
12692} 12943}
12693 12944
12694/* set ASIC CSRs to chip reset defaults */
12695static void reset_asic_csrs(struct hfi1_devdata *dd)
12696{
12697 int i;
12698
12699 /*
12700 * If the HFIs are shared between separate nodes or VMs,
12701 * then more will need to be done here. One idea is a module
12702 * parameter that returns early, letting the first power-on or
12703 * a known first load do the reset and blocking all others.
12704 */
12705
12706 if (!(dd->flags & HFI1_DO_INIT_ASIC))
12707 return;
12708
12709 if (dd->icode != ICODE_FPGA_EMULATION) {
12710 /* emulation does not have an SBus - leave these alone */
12711 /*
12712 * All writes to ASIC_CFG_SBUS_REQUEST do something.
12713 * Notes:
12714 * o The reset is not zero if aimed at the core. See the
12715 * SBus documentation for details.
12716 * o If the SBus firmware has been updated (e.g. by the BIOS),
12717 * will the reset revert that?
12718 */
12719 /* ASIC_CFG_SBUS_REQUEST leave alone */
12720 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 0);
12721 }
12722 /* ASIC_SBUS_RESULT read-only */
12723 write_csr(dd, ASIC_STS_SBUS_COUNTERS, 0);
12724 for (i = 0; i < ASIC_NUM_SCRATCH; i++)
12725 write_csr(dd, ASIC_CFG_SCRATCH + (8 * i), 0);
12726 write_csr(dd, ASIC_CFG_MUTEX, 0); /* this will clear it */
12727
12728 /* We might want to retain this state across FLR if we ever use it */
12729 write_csr(dd, ASIC_CFG_DRV_STR, 0);
12730
12731 /* ASIC_CFG_THERM_POLL_EN leave alone */
12732 /* ASIC_STS_THERM read-only */
12733 /* ASIC_CFG_RESET leave alone */
12734
12735 write_csr(dd, ASIC_PCIE_SD_HOST_CMD, 0);
12736 /* ASIC_PCIE_SD_HOST_STATUS read-only */
12737 write_csr(dd, ASIC_PCIE_SD_INTRPT_DATA_CODE, 0);
12738 write_csr(dd, ASIC_PCIE_SD_INTRPT_ENABLE, 0);
12739 /* ASIC_PCIE_SD_INTRPT_PROGRESS read-only */
12740 write_csr(dd, ASIC_PCIE_SD_INTRPT_STATUS, ~0ull); /* clear */
12741 /* ASIC_HFI0_PCIE_SD_INTRPT_RSPD_DATA read-only */
12742 /* ASIC_HFI1_PCIE_SD_INTRPT_RSPD_DATA read-only */
12743 for (i = 0; i < 16; i++)
12744 write_csr(dd, ASIC_PCIE_SD_INTRPT_LIST + (8 * i), 0);
12745
12746 /* ASIC_GPIO_IN read-only */
12747 write_csr(dd, ASIC_GPIO_OE, 0);
12748 write_csr(dd, ASIC_GPIO_INVERT, 0);
12749 write_csr(dd, ASIC_GPIO_OUT, 0);
12750 write_csr(dd, ASIC_GPIO_MASK, 0);
12751 /* ASIC_GPIO_STATUS read-only */
12752 write_csr(dd, ASIC_GPIO_CLEAR, ~0ull);
12753 /* ASIC_GPIO_FORCE leave alone */
12754
12755 /* ASIC_QSFP1_IN read-only */
12756 write_csr(dd, ASIC_QSFP1_OE, 0);
12757 write_csr(dd, ASIC_QSFP1_INVERT, 0);
12758 write_csr(dd, ASIC_QSFP1_OUT, 0);
12759 write_csr(dd, ASIC_QSFP1_MASK, 0);
12760 /* ASIC_QSFP1_STATUS read-only */
12761 write_csr(dd, ASIC_QSFP1_CLEAR, ~0ull);
12762 /* ASIC_QSFP1_FORCE leave alone */
12763
12764 /* ASIC_QSFP2_IN read-only */
12765 write_csr(dd, ASIC_QSFP2_OE, 0);
12766 write_csr(dd, ASIC_QSFP2_INVERT, 0);
12767 write_csr(dd, ASIC_QSFP2_OUT, 0);
12768 write_csr(dd, ASIC_QSFP2_MASK, 0);
12769 /* ASIC_QSFP2_STATUS read-only */
12770 write_csr(dd, ASIC_QSFP2_CLEAR, ~0ull);
12771 /* ASIC_QSFP2_FORCE leave alone */
12772
12773 write_csr(dd, ASIC_EEP_CTL_STAT, ASIC_EEP_CTL_STAT_RESETCSR);
12774 /* this also writes a NOP command, clearing paging mode */
12775 write_csr(dd, ASIC_EEP_ADDR_CMD, 0);
12776 write_csr(dd, ASIC_EEP_DATA, 0);
12777}
12778
12779/* set MISC CSRs to chip reset defaults */ 12945/* set MISC CSRs to chip reset defaults */
12780static void reset_misc_csrs(struct hfi1_devdata *dd) 12946static void reset_misc_csrs(struct hfi1_devdata *dd)
12781{ 12947{
@@ -12786,8 +12952,10 @@ static void reset_misc_csrs(struct hfi1_devdata *dd)
12786 write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0); 12952 write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
12787 write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0); 12953 write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
12788 } 12954 }
12789 /* MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can 12955 /*
12790 only be written 128-byte chunks */ 12956 * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
12957 * only be written 128-byte chunks
12958 */
12791 /* init RSA engine to clear lingering errors */ 12959 /* init RSA engine to clear lingering errors */
12792 write_csr(dd, MISC_CFG_RSA_CMD, 1); 12960 write_csr(dd, MISC_CFG_RSA_CMD, 1);
12793 write_csr(dd, MISC_CFG_RSA_MU, 0); 12961 write_csr(dd, MISC_CFG_RSA_MU, 0);
@@ -12843,18 +13011,17 @@ static void reset_txe_csrs(struct hfi1_devdata *dd)
12843 write_csr(dd, SEND_ERR_CLEAR, ~0ull); 13011 write_csr(dd, SEND_ERR_CLEAR, ~0ull);
12844 /* SEND_ERR_FORCE read-only */ 13012 /* SEND_ERR_FORCE read-only */
12845 for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++) 13013 for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
12846 write_csr(dd, SEND_LOW_PRIORITY_LIST + (8*i), 0); 13014 write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
12847 for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++) 13015 for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
12848 write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8*i), 0); 13016 write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
12849 for (i = 0; i < dd->chip_send_contexts/NUM_CONTEXTS_PER_SET; i++) 13017 for (i = 0; i < dd->chip_send_contexts / NUM_CONTEXTS_PER_SET; i++)
12850 write_csr(dd, SEND_CONTEXT_SET_CTRL + (8*i), 0); 13018 write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
12851 for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++) 13019 for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
12852 write_csr(dd, SEND_COUNTER_ARRAY32 + (8*i), 0); 13020 write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
12853 for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++) 13021 for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
12854 write_csr(dd, SEND_COUNTER_ARRAY64 + (8*i), 0); 13022 write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
12855 write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR); 13023 write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
12856 write_csr(dd, SEND_CM_GLOBAL_CREDIT, 13024 write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
12857 SEND_CM_GLOBAL_CREDIT_RESETCSR);
12858 /* SEND_CM_CREDIT_USED_STATUS read-only */ 13025 /* SEND_CM_CREDIT_USED_STATUS read-only */
12859 write_csr(dd, SEND_CM_TIMER_CTRL, 0); 13026 write_csr(dd, SEND_CM_TIMER_CTRL, 0);
12860 write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0); 13027 write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
@@ -12862,7 +13029,7 @@ static void reset_txe_csrs(struct hfi1_devdata *dd)
12862 write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0); 13029 write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
12863 write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0); 13030 write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
12864 for (i = 0; i < TXE_NUM_DATA_VL; i++) 13031 for (i = 0; i < TXE_NUM_DATA_VL; i++)
12865 write_csr(dd, SEND_CM_CREDIT_VL + (8*i), 0); 13032 write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
12866 write_csr(dd, SEND_CM_CREDIT_VL15, 0); 13033 write_csr(dd, SEND_CM_CREDIT_VL15, 0);
12867 /* SEND_CM_CREDIT_USED_VL read-only */ 13034 /* SEND_CM_CREDIT_USED_VL read-only */
12868 /* SEND_CM_CREDIT_USED_VL15 read-only */ 13035 /* SEND_CM_CREDIT_USED_VL15 read-only */
@@ -12948,8 +13115,8 @@ static void init_rbufs(struct hfi1_devdata *dd)
12948 */ 13115 */
12949 if (count++ > 500) { 13116 if (count++ > 500) {
12950 dd_dev_err(dd, 13117 dd_dev_err(dd,
12951 "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n", 13118 "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
12952 __func__, reg); 13119 __func__, reg);
12953 break; 13120 break;
12954 } 13121 }
12955 udelay(2); /* do not busy-wait the CSR */ 13122 udelay(2); /* do not busy-wait the CSR */
@@ -12978,8 +13145,8 @@ static void init_rbufs(struct hfi1_devdata *dd)
12978 /* give up after 100us - slowest possible at 33MHz is 73us */ 13145 /* give up after 100us - slowest possible at 33MHz is 73us */
12979 if (count++ > 50) { 13146 if (count++ > 50) {
12980 dd_dev_err(dd, 13147 dd_dev_err(dd,
12981 "%s: RcvStatus.RxRbufInit not set, continuing\n", 13148 "%s: RcvStatus.RxRbufInit not set, continuing\n",
12982 __func__); 13149 __func__);
12983 break; 13150 break;
12984 } 13151 }
12985 } 13152 }
@@ -13005,7 +13172,7 @@ static void reset_rxe_csrs(struct hfi1_devdata *dd)
13005 write_csr(dd, RCV_VL15, 0); 13172 write_csr(dd, RCV_VL15, 0);
13006 /* this is a clear-down */ 13173 /* this is a clear-down */
13007 write_csr(dd, RCV_ERR_INFO, 13174 write_csr(dd, RCV_ERR_INFO,
13008 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK); 13175 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
13009 /* RCV_ERR_STATUS read-only */ 13176 /* RCV_ERR_STATUS read-only */
13010 write_csr(dd, RCV_ERR_MASK, 0); 13177 write_csr(dd, RCV_ERR_MASK, 0);
13011 write_csr(dd, RCV_ERR_CLEAR, ~0ull); 13178 write_csr(dd, RCV_ERR_CLEAR, ~0ull);
@@ -13051,8 +13218,8 @@ static void reset_rxe_csrs(struct hfi1_devdata *dd)
13051 write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0); 13218 write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
13052 /* RCV_EGR_OFFSET_TAIL read-only */ 13219 /* RCV_EGR_OFFSET_TAIL read-only */
13053 for (j = 0; j < RXE_NUM_TID_FLOWS; j++) { 13220 for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
13054 write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 13221 write_uctxt_csr(dd, i,
13055 0); 13222 RCV_TID_FLOW_TABLE + (8 * j), 0);
13056 } 13223 }
13057 } 13224 }
13058} 13225}
@@ -13154,7 +13321,7 @@ static void init_chip(struct hfi1_devdata *dd)
13154 write_csr(dd, RCV_CTXT_CTRL, 0); 13321 write_csr(dd, RCV_CTXT_CTRL, 0);
13155 /* mask all interrupt sources */ 13322 /* mask all interrupt sources */
13156 for (i = 0; i < CCE_NUM_INT_CSRS; i++) 13323 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
13157 write_csr(dd, CCE_INT_MASK + (8*i), 0ull); 13324 write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
13158 13325
13159 /* 13326 /*
13160 * DC Reset: do a full DC reset before the register clear. 13327 * DC Reset: do a full DC reset before the register clear.
@@ -13163,7 +13330,7 @@ static void init_chip(struct hfi1_devdata *dd)
13163 * across the clear. 13330 * across the clear.
13164 */ 13331 */
13165 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK); 13332 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
13166 (void) read_csr(dd, CCE_DC_CTRL); 13333 (void)read_csr(dd, CCE_DC_CTRL);
13167 13334
13168 if (use_flr) { 13335 if (use_flr) {
13169 /* 13336 /*
@@ -13184,22 +13351,19 @@ static void init_chip(struct hfi1_devdata *dd)
13184 hfi1_pcie_flr(dd); 13351 hfi1_pcie_flr(dd);
13185 restore_pci_variables(dd); 13352 restore_pci_variables(dd);
13186 } 13353 }
13187
13188 reset_asic_csrs(dd);
13189 } else { 13354 } else {
13190 dd_dev_info(dd, "Resetting CSRs with writes\n"); 13355 dd_dev_info(dd, "Resetting CSRs with writes\n");
13191 reset_cce_csrs(dd); 13356 reset_cce_csrs(dd);
13192 reset_txe_csrs(dd); 13357 reset_txe_csrs(dd);
13193 reset_rxe_csrs(dd); 13358 reset_rxe_csrs(dd);
13194 reset_asic_csrs(dd);
13195 reset_misc_csrs(dd); 13359 reset_misc_csrs(dd);
13196 } 13360 }
13197 /* clear the DC reset */ 13361 /* clear the DC reset */
13198 write_csr(dd, CCE_DC_CTRL, 0); 13362 write_csr(dd, CCE_DC_CTRL, 0);
13199 13363
13200 /* Set the LED off */ 13364 /* Set the LED off */
13201 if (is_ax(dd)) 13365 setextled(dd, 0);
13202 setextled(dd, 0); 13366
13203 /* 13367 /*
13204 * Clear the QSFP reset. 13368 * Clear the QSFP reset.
13205 * An FLR enforces a 0 on all out pins. The driver does not touch 13369 * An FLR enforces a 0 on all out pins. The driver does not touch
@@ -13212,6 +13376,7 @@ static void init_chip(struct hfi1_devdata *dd)
13212 */ 13376 */
13213 write_csr(dd, ASIC_QSFP1_OUT, 0x1f); 13377 write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
13214 write_csr(dd, ASIC_QSFP2_OUT, 0x1f); 13378 write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
13379 init_chip_resources(dd);
13215} 13380}
13216 13381
13217static void init_early_variables(struct hfi1_devdata *dd) 13382static void init_early_variables(struct hfi1_devdata *dd)
@@ -13252,12 +13417,12 @@ static void init_kdeth_qp(struct hfi1_devdata *dd)
13252 kdeth_qp = DEFAULT_KDETH_QP; 13417 kdeth_qp = DEFAULT_KDETH_QP;
13253 13418
13254 write_csr(dd, SEND_BTH_QP, 13419 write_csr(dd, SEND_BTH_QP,
13255 (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) 13420 (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
13256 << SEND_BTH_QP_KDETH_QP_SHIFT); 13421 SEND_BTH_QP_KDETH_QP_SHIFT);
13257 13422
13258 write_csr(dd, RCV_BTH_QP, 13423 write_csr(dd, RCV_BTH_QP,
13259 (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) 13424 (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
13260 << RCV_BTH_QP_KDETH_QP_SHIFT); 13425 RCV_BTH_QP_KDETH_QP_SHIFT);
13261} 13426}
13262 13427
13263/** 13428/**
@@ -13382,22 +13547,21 @@ static void init_qos(struct hfi1_devdata *dd, u32 first_ctxt)
13382 write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rsmmap[i]); 13547 write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rsmmap[i]);
13383 /* add rule0 */ 13548 /* add rule0 */
13384 write_csr(dd, RCV_RSM_CFG /* + (8 * 0) */, 13549 write_csr(dd, RCV_RSM_CFG /* + (8 * 0) */,
13385 RCV_RSM_CFG_ENABLE_OR_CHAIN_RSM0_MASK 13550 RCV_RSM_CFG_ENABLE_OR_CHAIN_RSM0_MASK <<
13386 << RCV_RSM_CFG_ENABLE_OR_CHAIN_RSM0_SHIFT | 13551 RCV_RSM_CFG_ENABLE_OR_CHAIN_RSM0_SHIFT |
13387 2ull << RCV_RSM_CFG_PACKET_TYPE_SHIFT); 13552 2ull << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
13388 write_csr(dd, RCV_RSM_SELECT /* + (8 * 0) */, 13553 write_csr(dd, RCV_RSM_SELECT /* + (8 * 0) */,
13389 LRH_BTH_MATCH_OFFSET 13554 LRH_BTH_MATCH_OFFSET << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
13390 << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT | 13555 LRH_SC_MATCH_OFFSET << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
13391 LRH_SC_MATCH_OFFSET << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT | 13556 LRH_SC_SELECT_OFFSET << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
13392 LRH_SC_SELECT_OFFSET << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT | 13557 ((u64)n) << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
13393 ((u64)n) << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT | 13558 QPN_SELECT_OFFSET << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
13394 QPN_SELECT_OFFSET << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT | 13559 ((u64)m + (u64)n) << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
13395 ((u64)m + (u64)n) << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
13396 write_csr(dd, RCV_RSM_MATCH /* + (8 * 0) */, 13560 write_csr(dd, RCV_RSM_MATCH /* + (8 * 0) */,
13397 LRH_BTH_MASK << RCV_RSM_MATCH_MASK1_SHIFT | 13561 LRH_BTH_MASK << RCV_RSM_MATCH_MASK1_SHIFT |
13398 LRH_BTH_VALUE << RCV_RSM_MATCH_VALUE1_SHIFT | 13562 LRH_BTH_VALUE << RCV_RSM_MATCH_VALUE1_SHIFT |
13399 LRH_SC_MASK << RCV_RSM_MATCH_MASK2_SHIFT | 13563 LRH_SC_MASK << RCV_RSM_MATCH_MASK2_SHIFT |
13400 LRH_SC_VALUE << RCV_RSM_MATCH_VALUE2_SHIFT); 13564 LRH_SC_VALUE << RCV_RSM_MATCH_VALUE2_SHIFT);
13401 /* Enable RSM */ 13565 /* Enable RSM */
13402 add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK); 13566 add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
13403 kfree(rsmmap); 13567 kfree(rsmmap);
@@ -13415,9 +13579,8 @@ static void init_rxe(struct hfi1_devdata *dd)
13415 /* enable all receive errors */ 13579 /* enable all receive errors */
13416 write_csr(dd, RCV_ERR_MASK, ~0ull); 13580 write_csr(dd, RCV_ERR_MASK, ~0ull);
13417 /* setup QPN map table - start where VL15 context leaves off */ 13581 /* setup QPN map table - start where VL15 context leaves off */
13418 init_qos( 13582 init_qos(dd, dd->n_krcv_queues > MIN_KERNEL_KCTXTS ?
13419 dd, 13583 MIN_KERNEL_KCTXTS : 0);
13420 dd->n_krcv_queues > MIN_KERNEL_KCTXTS ? MIN_KERNEL_KCTXTS : 0);
13421 /* 13584 /*
13422 * make sure RcvCtrl.RcvWcb <= PCIe Device Control 13585 * make sure RcvCtrl.RcvWcb <= PCIe Device Control
13423 * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config 13586 * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
@@ -13454,36 +13617,33 @@ static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
13454 u32 csr0to3, u32 csr4to7) 13617 u32 csr0to3, u32 csr4to7)
13455{ 13618{
13456 write_csr(dd, csr0to3, 13619 write_csr(dd, csr0to3,
13457 0ull << 13620 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
13458 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT 13621 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
13459 | 1ull << 13622 2ull * cu <<
13460 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT 13623 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
13461 | 2ull * cu << 13624 4ull * cu <<
13462 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT 13625 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
13463 | 4ull * cu <<
13464 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
13465 write_csr(dd, csr4to7, 13626 write_csr(dd, csr4to7,
13466 8ull * cu << 13627 8ull * cu <<
13467 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT 13628 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
13468 | 16ull * cu << 13629 16ull * cu <<
13469 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT 13630 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
13470 | 32ull * cu << 13631 32ull * cu <<
13471 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT 13632 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
13472 | 64ull * cu << 13633 64ull * cu <<
13473 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT); 13634 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
13474
13475} 13635}
13476 13636
13477static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu) 13637static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
13478{ 13638{
13479 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3, 13639 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
13480 SEND_CM_LOCAL_AU_TABLE4_TO7); 13640 SEND_CM_LOCAL_AU_TABLE4_TO7);
13481} 13641}
13482 13642
13483void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu) 13643void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
13484{ 13644{
13485 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3, 13645 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
13486 SEND_CM_REMOTE_AU_TABLE4_TO7); 13646 SEND_CM_REMOTE_AU_TABLE4_TO7);
13487} 13647}
13488 13648
13489static void init_txe(struct hfi1_devdata *dd) 13649static void init_txe(struct hfi1_devdata *dd)
@@ -13586,9 +13746,9 @@ int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, unsigned ctxt, u16 pkey)
13586 int ret = 0; 13746 int ret = 0;
13587 u64 reg; 13747 u64 reg;
13588 13748
13589 if (ctxt < dd->num_rcv_contexts) 13749 if (ctxt < dd->num_rcv_contexts) {
13590 rcd = dd->rcd[ctxt]; 13750 rcd = dd->rcd[ctxt];
13591 else { 13751 } else {
13592 ret = -EINVAL; 13752 ret = -EINVAL;
13593 goto done; 13753 goto done;
13594 } 13754 }
@@ -13614,9 +13774,9 @@ int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, unsigned ctxt)
13614 int ret = 0; 13774 int ret = 0;
13615 u64 reg; 13775 u64 reg;
13616 13776
13617 if (ctxt < dd->num_rcv_contexts) 13777 if (ctxt < dd->num_rcv_contexts) {
13618 rcd = dd->rcd[ctxt]; 13778 rcd = dd->rcd[ctxt];
13619 else { 13779 } else {
13620 ret = -EINVAL; 13780 ret = -EINVAL;
13621 goto done; 13781 goto done;
13622 } 13782 }
@@ -13639,24 +13799,26 @@ done:
13639 */ 13799 */
13640void hfi1_start_cleanup(struct hfi1_devdata *dd) 13800void hfi1_start_cleanup(struct hfi1_devdata *dd)
13641{ 13801{
13802 aspm_exit(dd);
13642 free_cntrs(dd); 13803 free_cntrs(dd);
13643 free_rcverr(dd); 13804 free_rcverr(dd);
13644 clean_up_interrupts(dd); 13805 clean_up_interrupts(dd);
13806 finish_chip_resources(dd);
13645} 13807}
13646 13808
13647#define HFI_BASE_GUID(dev) \ 13809#define HFI_BASE_GUID(dev) \
13648 ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT)) 13810 ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
13649 13811
13650/* 13812/*
13651 * Certain chip functions need to be initialized only once per asic 13813 * Information can be shared between the two HFIs on the same ASIC
13652 * instead of per-device. This function finds the peer device and 13814 * in the same OS. This function finds the peer device and sets
13653 * checks whether that chip initialization needs to be done by this 13815 * up a shared structure.
13654 * device.
13655 */ 13816 */
13656static void asic_should_init(struct hfi1_devdata *dd) 13817static int init_asic_data(struct hfi1_devdata *dd)
13657{ 13818{
13658 unsigned long flags; 13819 unsigned long flags;
13659 struct hfi1_devdata *tmp, *peer = NULL; 13820 struct hfi1_devdata *tmp, *peer = NULL;
13821 int ret = 0;
13660 13822
13661 spin_lock_irqsave(&hfi1_devs_lock, flags); 13823 spin_lock_irqsave(&hfi1_devs_lock, flags);
13662 /* Find our peer device */ 13824 /* Find our peer device */
@@ -13668,13 +13830,21 @@ static void asic_should_init(struct hfi1_devdata *dd)
13668 } 13830 }
13669 } 13831 }
13670 13832
13671 /* 13833 if (peer) {
13672 * "Claim" the ASIC for initialization if it hasn't been 13834 dd->asic_data = peer->asic_data;
13673 " "claimed" yet. 13835 } else {
13674 */ 13836 dd->asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
13675 if (!peer || !(peer->flags & HFI1_DO_INIT_ASIC)) 13837 if (!dd->asic_data) {
13676 dd->flags |= HFI1_DO_INIT_ASIC; 13838 ret = -ENOMEM;
13839 goto done;
13840 }
13841 mutex_init(&dd->asic_data->asic_resource_mutex);
13842 }
13843 dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
13844
13845done:
13677 spin_unlock_irqrestore(&hfi1_devs_lock, flags); 13846 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
13847 return ret;
13678} 13848}
13679 13849
13680/* 13850/*
@@ -13694,7 +13864,7 @@ static int obtain_boardname(struct hfi1_devdata *dd)
13694 ret = read_hfi1_efi_var(dd, "description", &size, 13864 ret = read_hfi1_efi_var(dd, "description", &size,
13695 (void **)&dd->boardname); 13865 (void **)&dd->boardname);
13696 if (ret) { 13866 if (ret) {
13697 dd_dev_err(dd, "Board description not found\n"); 13867 dd_dev_info(dd, "Board description not found\n");
13698 /* use generic description */ 13868 /* use generic description */
13699 dd->boardname = kstrdup(generic, GFP_KERNEL); 13869 dd->boardname = kstrdup(generic, GFP_KERNEL);
13700 if (!dd->boardname) 13870 if (!dd->boardname)
@@ -13703,6 +13873,50 @@ static int obtain_boardname(struct hfi1_devdata *dd)
13703 return 0; 13873 return 0;
13704} 13874}
13705 13875
13876/*
13877 * Check the interrupt registers to make sure that they are mapped correctly.
13878 * It is intended to help user identify any mismapping by VMM when the driver
13879 * is running in a VM. This function should only be called before interrupt
13880 * is set up properly.
13881 *
13882 * Return 0 on success, -EINVAL on failure.
13883 */
13884static int check_int_registers(struct hfi1_devdata *dd)
13885{
13886 u64 reg;
13887 u64 all_bits = ~(u64)0;
13888 u64 mask;
13889
13890 /* Clear CceIntMask[0] to avoid raising any interrupts */
13891 mask = read_csr(dd, CCE_INT_MASK);
13892 write_csr(dd, CCE_INT_MASK, 0ull);
13893 reg = read_csr(dd, CCE_INT_MASK);
13894 if (reg)
13895 goto err_exit;
13896
13897 /* Clear all interrupt status bits */
13898 write_csr(dd, CCE_INT_CLEAR, all_bits);
13899 reg = read_csr(dd, CCE_INT_STATUS);
13900 if (reg)
13901 goto err_exit;
13902
13903 /* Set all interrupt status bits */
13904 write_csr(dd, CCE_INT_FORCE, all_bits);
13905 reg = read_csr(dd, CCE_INT_STATUS);
13906 if (reg != all_bits)
13907 goto err_exit;
13908
13909 /* Restore the interrupt mask */
13910 write_csr(dd, CCE_INT_CLEAR, all_bits);
13911 write_csr(dd, CCE_INT_MASK, mask);
13912
13913 return 0;
13914err_exit:
13915 write_csr(dd, CCE_INT_MASK, mask);
13916 dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
13917 return -EINVAL;
13918}
13919
13706/** 13920/**
13707 * Allocate and initialize the device structure for the hfi. 13921 * Allocate and initialize the device structure for the hfi.
13708 * @dev: the pci_dev for hfi1_ib device 13922 * @dev: the pci_dev for hfi1_ib device
@@ -13727,9 +13941,10 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13727 "RTL FPGA emulation", 13941 "RTL FPGA emulation",
13728 "Functional simulator" 13942 "Functional simulator"
13729 }; 13943 };
13944 struct pci_dev *parent = pdev->bus->self;
13730 13945
13731 dd = hfi1_alloc_devdata(pdev, 13946 dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
13732 NUM_IB_PORTS * sizeof(struct hfi1_pportdata)); 13947 sizeof(struct hfi1_pportdata));
13733 if (IS_ERR(dd)) 13948 if (IS_ERR(dd))
13734 goto bail; 13949 goto bail;
13735 ppd = dd->pport; 13950 ppd = dd->pport;
@@ -13750,8 +13965,8 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13750 /* link width active is 0 when link is down */ 13965 /* link width active is 0 when link is down */
13751 /* link width downgrade active is 0 when link is down */ 13966 /* link width downgrade active is 0 when link is down */
13752 13967
13753 if (num_vls < HFI1_MIN_VLS_SUPPORTED 13968 if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
13754 || num_vls > HFI1_MAX_VLS_SUPPORTED) { 13969 num_vls > HFI1_MAX_VLS_SUPPORTED) {
13755 hfi1_early_err(&pdev->dev, 13970 hfi1_early_err(&pdev->dev,
13756 "Invalid num_vls %u, using %u VLs\n", 13971 "Invalid num_vls %u, using %u VLs\n",
13757 num_vls, HFI1_MAX_VLS_SUPPORTED); 13972 num_vls, HFI1_MAX_VLS_SUPPORTED);
@@ -13759,6 +13974,7 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13759 } 13974 }
13760 ppd->vls_supported = num_vls; 13975 ppd->vls_supported = num_vls;
13761 ppd->vls_operational = ppd->vls_supported; 13976 ppd->vls_operational = ppd->vls_supported;
13977 ppd->actual_vls_operational = ppd->vls_supported;
13762 /* Set the default MTU. */ 13978 /* Set the default MTU. */
13763 for (vl = 0; vl < num_vls; vl++) 13979 for (vl = 0; vl < num_vls; vl++)
13764 dd->vld[vl].mtu = hfi1_max_mtu; 13980 dd->vld[vl].mtu = hfi1_max_mtu;
@@ -13778,6 +13994,7 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13778 /* start in offline */ 13994 /* start in offline */
13779 ppd->host_link_state = HLS_DN_OFFLINE; 13995 ppd->host_link_state = HLS_DN_OFFLINE;
13780 init_vl_arb_caches(ppd); 13996 init_vl_arb_caches(ppd);
13997 ppd->last_pstate = 0xff; /* invalid value */
13781 } 13998 }
13782 13999
13783 dd->link_default = HLS_DN_POLL; 14000 dd->link_default = HLS_DN_POLL;
@@ -13803,8 +14020,21 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13803 dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT) 14020 dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
13804 & CCE_REVISION_CHIP_REV_MINOR_MASK; 14021 & CCE_REVISION_CHIP_REV_MINOR_MASK;
13805 14022
13806 /* obtain the hardware ID - NOT related to unit, which is a 14023 /*
13807 software enumeration */ 14024 * Check interrupt registers mapping if the driver has no access to
14025 * the upstream component. In this case, it is likely that the driver
14026 * is running in a VM.
14027 */
14028 if (!parent) {
14029 ret = check_int_registers(dd);
14030 if (ret)
14031 goto bail_cleanup;
14032 }
14033
14034 /*
14035 * obtain the hardware ID - NOT related to unit, which is a
14036 * software enumeration
14037 */
13808 reg = read_csr(dd, CCE_REVISION2); 14038 reg = read_csr(dd, CCE_REVISION2);
13809 dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT) 14039 dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
13810 & CCE_REVISION2_HFI_ID_MASK; 14040 & CCE_REVISION2_HFI_ID_MASK;
@@ -13812,8 +14042,8 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13812 dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT; 14042 dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
13813 dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT; 14043 dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
13814 dd_dev_info(dd, "Implementation: %s, revision 0x%x\n", 14044 dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
13815 dd->icode < ARRAY_SIZE(inames) ? inames[dd->icode] : "unknown", 14045 dd->icode < ARRAY_SIZE(inames) ?
13816 (int)dd->irev); 14046 inames[dd->icode] : "unknown", (int)dd->irev);
13817 14047
13818 /* speeds the hardware can support */ 14048 /* speeds the hardware can support */
13819 dd->pport->link_speed_supported = OPA_LINK_SPEED_25G; 14049 dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
@@ -13842,6 +14072,7 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13842 num_vls, dd->chip_sdma_engines); 14072 num_vls, dd->chip_sdma_engines);
13843 num_vls = dd->chip_sdma_engines; 14073 num_vls = dd->chip_sdma_engines;
13844 ppd->vls_supported = dd->chip_sdma_engines; 14074 ppd->vls_supported = dd->chip_sdma_engines;
14075 ppd->vls_operational = ppd->vls_supported;
13845 } 14076 }
13846 14077
13847 /* 14078 /*
@@ -13863,8 +14094,10 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13863 /* needs to be done before we look for the peer device */ 14094 /* needs to be done before we look for the peer device */
13864 read_guid(dd); 14095 read_guid(dd);
13865 14096
13866 /* should this device init the ASIC block? */ 14097 /* set up shared ASIC data with peer device */
13867 asic_should_init(dd); 14098 ret = init_asic_data(dd);
14099 if (ret)
14100 goto bail_cleanup;
13868 14101
13869 /* obtain chip sizes, reset chip CSRs */ 14102 /* obtain chip sizes, reset chip CSRs */
13870 init_chip(dd); 14103 init_chip(dd);
@@ -13874,6 +14107,9 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13874 if (ret) 14107 if (ret)
13875 goto bail_cleanup; 14108 goto bail_cleanup;
13876 14109
14110 /* Needs to be called before hfi1_firmware_init */
14111 get_platform_config(dd);
14112
13877 /* read in firmware */ 14113 /* read in firmware */
13878 ret = hfi1_firmware_init(dd); 14114 ret = hfi1_firmware_init(dd);
13879 if (ret) 14115 if (ret)
@@ -13925,6 +14161,10 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
13925 /* set up KDETH QP prefix in both RX and TX CSRs */ 14161 /* set up KDETH QP prefix in both RX and TX CSRs */
13926 init_kdeth_qp(dd); 14162 init_kdeth_qp(dd);
13927 14163
14164 ret = hfi1_dev_affinity_init(dd);
14165 if (ret)
14166 goto bail_cleanup;
14167
13928 /* send contexts must be set up before receive contexts */ 14168 /* send contexts must be set up before receive contexts */
13929 ret = init_send_contexts(dd); 14169 ret = init_send_contexts(dd);
13930 if (ret) 14170 if (ret)
@@ -14022,7 +14262,6 @@ static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
14022 return (u16)delta_cycles; 14262 return (u16)delta_cycles;
14023} 14263}
14024 14264
14025
14026/** 14265/**
14027 * create_pbc - build a pbc for transmission 14266 * create_pbc - build a pbc for transmission
14028 * @flags: special case flags or-ed in built pbc 14267 * @flags: special case flags or-ed in built pbc
@@ -14078,10 +14317,15 @@ static int thermal_init(struct hfi1_devdata *dd)
14078 int ret = 0; 14317 int ret = 0;
14079 14318
14080 if (dd->icode != ICODE_RTL_SILICON || 14319 if (dd->icode != ICODE_RTL_SILICON ||
14081 !(dd->flags & HFI1_DO_INIT_ASIC)) 14320 check_chip_resource(dd, CR_THERM_INIT, NULL))
14082 return ret; 14321 return ret;
14083 14322
14084 acquire_hw_mutex(dd); 14323 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
14324 if (ret) {
14325 THERM_FAILURE(dd, ret, "Acquire SBus");
14326 return ret;
14327 }
14328
14085 dd_dev_info(dd, "Initializing thermal sensor\n"); 14329 dd_dev_info(dd, "Initializing thermal sensor\n");
14086 /* Disable polling of thermal readings */ 14330 /* Disable polling of thermal readings */
14087 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0); 14331 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
@@ -14128,8 +14372,14 @@ static int thermal_init(struct hfi1_devdata *dd)
14128 14372
14129 /* Enable polling of thermal readings */ 14373 /* Enable polling of thermal readings */
14130 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1); 14374 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
14375
14376 /* Set initialized flag */
14377 ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
14378 if (ret)
14379 THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
14380
14131done: 14381done:
14132 release_hw_mutex(dd); 14382 release_chip_resource(dd, CR_SBUS);
14133 return ret; 14383 return ret;
14134} 14384}
14135 14385
@@ -14144,7 +14394,7 @@ static void handle_temp_err(struct hfi1_devdata *dd)
14144 dd_dev_emerg(dd, 14394 dd_dev_emerg(dd,
14145 "Critical temperature reached! Forcing device into freeze mode!\n"); 14395 "Critical temperature reached! Forcing device into freeze mode!\n");
14146 dd->flags |= HFI1_FORCED_FREEZE; 14396 dd->flags |= HFI1_FORCED_FREEZE;
14147 start_freeze_handling(ppd, FREEZE_SELF|FREEZE_ABORT); 14397 start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
14148 /* 14398 /*
14149 * Shut DC down as much and as quickly as possible. 14399 * Shut DC down as much and as quickly as possible.
14150 * 14400 *
@@ -14158,8 +14408,8 @@ static void handle_temp_err(struct hfi1_devdata *dd)
14158 */ 14408 */
14159 ppd->driver_link_ready = 0; 14409 ppd->driver_link_ready = 0;
14160 ppd->link_enabled = 0; 14410 ppd->link_enabled = 0;
14161 set_physical_link_state(dd, PLS_OFFLINE | 14411 set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
14162 (OPA_LINKDOWN_REASON_SMA_DISABLED << 8)); 14412 PLS_OFFLINE);
14163 /* 14413 /*
14164 * Step 2: Shutdown LCB and 8051 14414 * Step 2: Shutdown LCB and 8051
14165 * After shutdown, do not restore DC_CFG_RESET value. 14415 * After shutdown, do not restore DC_CFG_RESET value.
diff --git a/drivers/staging/rdma/hfi1/chip.h b/drivers/staging/rdma/hfi1/chip.h
index 5b375ddc345d..4f3b878e43eb 100644
--- a/drivers/staging/rdma/hfi1/chip.h
+++ b/drivers/staging/rdma/hfi1/chip.h
@@ -1,14 +1,13 @@
1#ifndef _CHIP_H 1#ifndef _CHIP_H
2#define _CHIP_H 2#define _CHIP_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -79,8 +76,10 @@
79#define PIO_CMASK 0x7ff /* counter mask for free and fill counters */ 76#define PIO_CMASK 0x7ff /* counter mask for free and fill counters */
80#define MAX_EAGER_ENTRIES 2048 /* max receive eager entries */ 77#define MAX_EAGER_ENTRIES 2048 /* max receive eager entries */
81#define MAX_TID_PAIR_ENTRIES 1024 /* max receive expected pairs */ 78#define MAX_TID_PAIR_ENTRIES 1024 /* max receive expected pairs */
82/* Virtual? Allocation Unit, defined as AU = 8*2^vAU, 64 bytes, AU is fixed 79/*
83 at 64 bytes for all generation one devices */ 80 * Virtual? Allocation Unit, defined as AU = 8*2^vAU, 64 bytes, AU is fixed
81 * at 64 bytes for all generation one devices
82 */
84#define CM_VAU 3 83#define CM_VAU 3
85/* HFI link credit count, AKA receive buffer depth (RBUF_DEPTH) */ 84/* HFI link credit count, AKA receive buffer depth (RBUF_DEPTH) */
86#define CM_GLOBAL_CREDITS 0x940 85#define CM_GLOBAL_CREDITS 0x940
@@ -93,15 +92,15 @@
93#define TXE_PIO_SEND (TXE + TXE_PIO_SEND_OFFSET) 92#define TXE_PIO_SEND (TXE + TXE_PIO_SEND_OFFSET)
94 93
95/* PBC flags */ 94/* PBC flags */
96#define PBC_INTR (1ull << 31) 95#define PBC_INTR BIT_ULL(31)
97#define PBC_DC_INFO_SHIFT (30) 96#define PBC_DC_INFO_SHIFT (30)
98#define PBC_DC_INFO (1ull << PBC_DC_INFO_SHIFT) 97#define PBC_DC_INFO BIT_ULL(PBC_DC_INFO_SHIFT)
99#define PBC_TEST_EBP (1ull << 29) 98#define PBC_TEST_EBP BIT_ULL(29)
100#define PBC_PACKET_BYPASS (1ull << 28) 99#define PBC_PACKET_BYPASS BIT_ULL(28)
101#define PBC_CREDIT_RETURN (1ull << 25) 100#define PBC_CREDIT_RETURN BIT_ULL(25)
102#define PBC_INSERT_BYPASS_ICRC (1ull << 24) 101#define PBC_INSERT_BYPASS_ICRC BIT_ULL(24)
103#define PBC_TEST_BAD_ICRC (1ull << 23) 102#define PBC_TEST_BAD_ICRC BIT_ULL(23)
104#define PBC_FECN (1ull << 22) 103#define PBC_FECN BIT_ULL(22)
105 104
106/* PbcInsertHcrc field settings */ 105/* PbcInsertHcrc field settings */
107#define PBC_IHCRC_LKDETH 0x0 /* insert @ local KDETH offset */ 106#define PBC_IHCRC_LKDETH 0x0 /* insert @ local KDETH offset */
@@ -212,7 +211,7 @@
212#define PLS_CONFIGPHY_DEBOUCE 0x40 211#define PLS_CONFIGPHY_DEBOUCE 0x40
213#define PLS_CONFIGPHY_ESTCOMM 0x41 212#define PLS_CONFIGPHY_ESTCOMM 0x41
214#define PLS_CONFIGPHY_ESTCOMM_TXRX_HUNT 0x42 213#define PLS_CONFIGPHY_ESTCOMM_TXRX_HUNT 0x42
215#define PLS_CONFIGPHY_ESTcOMM_LOCAL_COMPLETE 0x43 214#define PLS_CONFIGPHY_ESTCOMM_LOCAL_COMPLETE 0x43
216#define PLS_CONFIGPHY_OPTEQ 0x44 215#define PLS_CONFIGPHY_OPTEQ 0x44
217#define PLS_CONFIGPHY_OPTEQ_OPTIMIZING 0x44 216#define PLS_CONFIGPHY_OPTEQ_OPTIMIZING 0x44
218#define PLS_CONFIGPHY_OPTEQ_LOCAL_COMPLETE 0x45 217#define PLS_CONFIGPHY_OPTEQ_LOCAL_COMPLETE 0x45
@@ -242,36 +241,37 @@
242#define HCMD_SUCCESS 2 241#define HCMD_SUCCESS 2
243 242
244/* DC_DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR - error flags */ 243/* DC_DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR - error flags */
245#define SPICO_ROM_FAILED (1 << 0) 244#define SPICO_ROM_FAILED BIT(0)
246#define UNKNOWN_FRAME (1 << 1) 245#define UNKNOWN_FRAME BIT(1)
247#define TARGET_BER_NOT_MET (1 << 2) 246#define TARGET_BER_NOT_MET BIT(2)
248#define FAILED_SERDES_INTERNAL_LOOPBACK (1 << 3) 247#define FAILED_SERDES_INTERNAL_LOOPBACK BIT(3)
249#define FAILED_SERDES_INIT (1 << 4) 248#define FAILED_SERDES_INIT BIT(4)
250#define FAILED_LNI_POLLING (1 << 5) 249#define FAILED_LNI_POLLING BIT(5)
251#define FAILED_LNI_DEBOUNCE (1 << 6) 250#define FAILED_LNI_DEBOUNCE BIT(6)
252#define FAILED_LNI_ESTBCOMM (1 << 7) 251#define FAILED_LNI_ESTBCOMM BIT(7)
253#define FAILED_LNI_OPTEQ (1 << 8) 252#define FAILED_LNI_OPTEQ BIT(8)
254#define FAILED_LNI_VERIFY_CAP1 (1 << 9) 253#define FAILED_LNI_VERIFY_CAP1 BIT(9)
255#define FAILED_LNI_VERIFY_CAP2 (1 << 10) 254#define FAILED_LNI_VERIFY_CAP2 BIT(10)
256#define FAILED_LNI_CONFIGLT (1 << 11) 255#define FAILED_LNI_CONFIGLT BIT(11)
256#define HOST_HANDSHAKE_TIMEOUT BIT(12)
257 257
258#define FAILED_LNI (FAILED_LNI_POLLING | FAILED_LNI_DEBOUNCE \ 258#define FAILED_LNI (FAILED_LNI_POLLING | FAILED_LNI_DEBOUNCE \
259 | FAILED_LNI_ESTBCOMM | FAILED_LNI_OPTEQ \ 259 | FAILED_LNI_ESTBCOMM | FAILED_LNI_OPTEQ \
260 | FAILED_LNI_VERIFY_CAP1 \ 260 | FAILED_LNI_VERIFY_CAP1 \
261 | FAILED_LNI_VERIFY_CAP2 \ 261 | FAILED_LNI_VERIFY_CAP2 \
262 | FAILED_LNI_CONFIGLT) 262 | FAILED_LNI_CONFIGLT | HOST_HANDSHAKE_TIMEOUT)
263 263
264/* DC_DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG - host message flags */ 264/* DC_DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG - host message flags */
265#define HOST_REQ_DONE (1 << 0) 265#define HOST_REQ_DONE BIT(0)
266#define BC_PWR_MGM_MSG (1 << 1) 266#define BC_PWR_MGM_MSG BIT(1)
267#define BC_SMA_MSG (1 << 2) 267#define BC_SMA_MSG BIT(2)
268#define BC_BCC_UNKOWN_MSG (1 << 3) 268#define BC_BCC_UNKNOWN_MSG BIT(3)
269#define BC_IDLE_UNKNOWN_MSG (1 << 4) 269#define BC_IDLE_UNKNOWN_MSG BIT(4)
270#define EXT_DEVICE_CFG_REQ (1 << 5) 270#define EXT_DEVICE_CFG_REQ BIT(5)
271#define VERIFY_CAP_FRAME (1 << 6) 271#define VERIFY_CAP_FRAME BIT(6)
272#define LINKUP_ACHIEVED (1 << 7) 272#define LINKUP_ACHIEVED BIT(7)
273#define LINK_GOING_DOWN (1 << 8) 273#define LINK_GOING_DOWN BIT(8)
274#define LINK_WIDTH_DOWNGRADED (1 << 9) 274#define LINK_WIDTH_DOWNGRADED BIT(9)
275 275
276/* DC_DC8051_CFG_EXT_DEV_1.REQ_TYPE - 8051 host requests */ 276/* DC_DC8051_CFG_EXT_DEV_1.REQ_TYPE - 8051 host requests */
277#define HREQ_LOAD_CONFIG 0x01 277#define HREQ_LOAD_CONFIG 0x01
@@ -335,14 +335,14 @@
335 * the CSR fields hold multiples of this value. 335 * the CSR fields hold multiples of this value.
336 */ 336 */
337#define RCV_SHIFT 3 337#define RCV_SHIFT 3
338#define RCV_INCREMENT (1 << RCV_SHIFT) 338#define RCV_INCREMENT BIT(RCV_SHIFT)
339 339
340/* 340/*
341 * Receive header queue entry increment - the CSR holds multiples of 341 * Receive header queue entry increment - the CSR holds multiples of
342 * this value. 342 * this value.
343 */ 343 */
344#define HDRQ_SIZE_SHIFT 5 344#define HDRQ_SIZE_SHIFT 5
345#define HDRQ_INCREMENT (1 << HDRQ_SIZE_SHIFT) 345#define HDRQ_INCREMENT BIT(HDRQ_SIZE_SHIFT)
346 346
347/* 347/*
348 * Freeze handling flags 348 * Freeze handling flags
@@ -371,6 +371,9 @@
371#define NUM_LANE_FIELDS 0x8 371#define NUM_LANE_FIELDS 0x8
372 372
373/* 8051 general register Field IDs */ 373/* 8051 general register Field IDs */
374#define LINK_OPTIMIZATION_SETTINGS 0x00
375#define LINK_TUNING_PARAMETERS 0x02
376#define DC_HOST_COMM_SETTINGS 0x03
374#define TX_SETTINGS 0x06 377#define TX_SETTINGS 0x06
375#define VERIFY_CAP_LOCAL_PHY 0x07 378#define VERIFY_CAP_LOCAL_PHY 0x07
376#define VERIFY_CAP_LOCAL_FABRIC 0x08 379#define VERIFY_CAP_LOCAL_FABRIC 0x08
@@ -387,6 +390,10 @@
387#define LINK_QUALITY_INFO 0x14 390#define LINK_QUALITY_INFO 0x14
388#define REMOTE_DEVICE_ID 0x15 391#define REMOTE_DEVICE_ID 0x15
389 392
393/* 8051 lane specific register field IDs */
394#define TX_EQ_SETTINGS 0x00
395#define CHANNEL_LOSS_SETTINGS 0x05
396
390/* Lane ID for general configuration registers */ 397/* Lane ID for general configuration registers */
391#define GENERAL_CONFIG 4 398#define GENERAL_CONFIG 4
392 399
@@ -511,8 +518,10 @@ enum {
511#define LCB_CRC_48B 0x2 /* 48b CRC */ 518#define LCB_CRC_48B 0x2 /* 48b CRC */
512#define LCB_CRC_12B_16B_PER_LANE 0x3 /* 12b-16b per lane CRC */ 519#define LCB_CRC_12B_16B_PER_LANE 0x3 /* 12b-16b per lane CRC */
513 520
514/* the following enum is (almost) a copy/paste of the definition 521/*
515 * in the OPA spec, section 20.2.2.6.8 (PortInfo) */ 522 * the following enum is (almost) a copy/paste of the definition
523 * in the OPA spec, section 20.2.2.6.8 (PortInfo)
524 */
516enum { 525enum {
517 PORT_LTP_CRC_MODE_NONE = 0, 526 PORT_LTP_CRC_MODE_NONE = 0,
518 PORT_LTP_CRC_MODE_14 = 1, /* 14-bit LTP CRC mode (optional) */ 527 PORT_LTP_CRC_MODE_14 = 1, /* 14-bit LTP CRC mode (optional) */
@@ -614,6 +623,8 @@ u64 create_pbc(struct hfi1_pportdata *ppd, u64, int, u32, u32);
614#define NUM_PCIE_SERDES 16 /* number of PCIe serdes on the SBus */ 623#define NUM_PCIE_SERDES 16 /* number of PCIe serdes on the SBus */
615extern const u8 pcie_serdes_broadcast[]; 624extern const u8 pcie_serdes_broadcast[];
616extern const u8 pcie_pcs_addrs[2][NUM_PCIE_SERDES]; 625extern const u8 pcie_pcs_addrs[2][NUM_PCIE_SERDES];
626extern uint platform_config_load;
627
617/* SBus commands */ 628/* SBus commands */
618#define RESET_SBUS_RECEIVER 0x20 629#define RESET_SBUS_RECEIVER 0x20
619#define WRITE_SBUS_RECEIVER 0x21 630#define WRITE_SBUS_RECEIVER 0x21
@@ -629,6 +640,42 @@ int load_firmware(struct hfi1_devdata *dd);
629void dispose_firmware(void); 640void dispose_firmware(void);
630int acquire_hw_mutex(struct hfi1_devdata *dd); 641int acquire_hw_mutex(struct hfi1_devdata *dd);
631void release_hw_mutex(struct hfi1_devdata *dd); 642void release_hw_mutex(struct hfi1_devdata *dd);
643
644/*
645 * Bitmask of dynamic access for ASIC block chip resources. Each HFI has its
646 * own range of bits for the resource so it can clear its own bits on
647 * starting and exiting. If either HFI has the resource bit set, the
648 * resource is in use. The separate bit ranges are:
649 * HFI0 bits 7:0
650 * HFI1 bits 15:8
651 */
652#define CR_SBUS 0x01 /* SBUS, THERM, and PCIE registers */
653#define CR_EPROM 0x02 /* EEP, GPIO registers */
654#define CR_I2C1 0x04 /* QSFP1_OE register */
655#define CR_I2C2 0x08 /* QSFP2_OE register */
656#define CR_DYN_SHIFT 8 /* dynamic flag shift */
657#define CR_DYN_MASK ((1ull << CR_DYN_SHIFT) - 1)
658
659/*
660 * Bitmask of static ASIC states these are outside of the dynamic ASIC
661 * block chip resources above. These are to be set once and never cleared.
662 * Must be holding the SBus dynamic flag when setting.
663 */
664#define CR_THERM_INIT 0x010000
665
666int acquire_chip_resource(struct hfi1_devdata *dd, u32 resource, u32 mswait);
667void release_chip_resource(struct hfi1_devdata *dd, u32 resource);
668bool check_chip_resource(struct hfi1_devdata *dd, u32 resource,
669 const char *func);
670void init_chip_resources(struct hfi1_devdata *dd);
671void finish_chip_resources(struct hfi1_devdata *dd);
672
673/* ms wait time for access to an SBus resoure */
674#define SBUS_TIMEOUT 4000 /* long enough for a FW download and SBR */
675
676/* ms wait time for a qsfp (i2c) chain to become available */
677#define QSFP_WAIT 20000 /* long enough for FW update to the F4 uc */
678
632void fabric_serdes_reset(struct hfi1_devdata *dd); 679void fabric_serdes_reset(struct hfi1_devdata *dd);
633int read_8051_data(struct hfi1_devdata *dd, u32 addr, u32 len, u64 *result); 680int read_8051_data(struct hfi1_devdata *dd, u32 addr, u32 len, u64 *result);
634 681
@@ -644,13 +691,17 @@ void handle_verify_cap(struct work_struct *work);
644void handle_freeze(struct work_struct *work); 691void handle_freeze(struct work_struct *work);
645void handle_link_up(struct work_struct *work); 692void handle_link_up(struct work_struct *work);
646void handle_link_down(struct work_struct *work); 693void handle_link_down(struct work_struct *work);
694void handle_8051_request(struct work_struct *work);
647void handle_link_downgrade(struct work_struct *work); 695void handle_link_downgrade(struct work_struct *work);
648void handle_link_bounce(struct work_struct *work); 696void handle_link_bounce(struct work_struct *work);
649void handle_sma_message(struct work_struct *work); 697void handle_sma_message(struct work_struct *work);
698void reset_qsfp(struct hfi1_pportdata *ppd);
699void qsfp_event(struct work_struct *work);
650void start_freeze_handling(struct hfi1_pportdata *ppd, int flags); 700void start_freeze_handling(struct hfi1_pportdata *ppd, int flags);
651int send_idle_sma(struct hfi1_devdata *dd, u64 message); 701int send_idle_sma(struct hfi1_devdata *dd, u64 message);
702int load_8051_config(struct hfi1_devdata *, u8, u8, u32);
703int read_8051_config(struct hfi1_devdata *, u8, u8, u32 *);
652int start_link(struct hfi1_pportdata *ppd); 704int start_link(struct hfi1_pportdata *ppd);
653void init_qsfp(struct hfi1_pportdata *ppd);
654int bringup_serdes(struct hfi1_pportdata *ppd); 705int bringup_serdes(struct hfi1_pportdata *ppd);
655void set_intr_state(struct hfi1_devdata *dd, u32 enable); 706void set_intr_state(struct hfi1_devdata *dd, u32 enable);
656void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, 707void apply_link_downgrade_policy(struct hfi1_pportdata *ppd,
@@ -690,6 +741,8 @@ u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl);
690u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data); 741u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data);
691u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl); 742u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl);
692u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data); 743u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data);
744u32 read_logical_state(struct hfi1_devdata *dd);
745void force_recv_intr(struct hfi1_ctxtdata *rcd);
693 746
694/* Per VL indexes */ 747/* Per VL indexes */
695enum { 748enum {
@@ -785,8 +838,14 @@ enum {
785 C_SW_CPU_RCV_LIM, 838 C_SW_CPU_RCV_LIM,
786 C_SW_VTX_WAIT, 839 C_SW_VTX_WAIT,
787 C_SW_PIO_WAIT, 840 C_SW_PIO_WAIT,
841 C_SW_PIO_DRAIN,
788 C_SW_KMEM_WAIT, 842 C_SW_KMEM_WAIT,
789 C_SW_SEND_SCHED, 843 C_SW_SEND_SCHED,
844 C_SDMA_DESC_FETCHED_CNT,
845 C_SDMA_INT_CNT,
846 C_SDMA_ERR_CNT,
847 C_SDMA_IDLE_INT_CNT,
848 C_SDMA_PROGRESS_INT_CNT,
790/* MISC_ERR_STATUS */ 849/* MISC_ERR_STATUS */
791 C_MISC_PLL_LOCK_FAIL_ERR, 850 C_MISC_PLL_LOCK_FAIL_ERR,
792 C_MISC_MBIST_FAIL_ERR, 851 C_MISC_MBIST_FAIL_ERR,
@@ -1275,10 +1334,8 @@ void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
1275 u32 type, unsigned long pa, u16 order); 1334 u32 type, unsigned long pa, u16 order);
1276void hfi1_quiet_serdes(struct hfi1_pportdata *ppd); 1335void hfi1_quiet_serdes(struct hfi1_pportdata *ppd);
1277void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt); 1336void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt);
1278u32 hfi1_read_cntrs(struct hfi1_devdata *dd, loff_t pos, char **namep, 1337u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp);
1279 u64 **cntrp); 1338u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp);
1280u32 hfi1_read_portcntrs(struct hfi1_devdata *dd, loff_t pos, u32 port,
1281 char **namep, u64 **cntrp);
1282u8 hfi1_ibphys_portstate(struct hfi1_pportdata *ppd); 1339u8 hfi1_ibphys_portstate(struct hfi1_pportdata *ppd);
1283int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which); 1340int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which);
1284int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val); 1341int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val);
diff --git a/drivers/staging/rdma/hfi1/chip_registers.h b/drivers/staging/rdma/hfi1/chip_registers.h
index 014d7a609ea0..770f05c9b8de 100644
--- a/drivers/staging/rdma/hfi1/chip_registers.h
+++ b/drivers/staging/rdma/hfi1/chip_registers.h
@@ -2,14 +2,13 @@
2#define DEF_CHIP_REG 2#define DEF_CHIP_REG
3 3
4/* 4/*
5 * Copyright(c) 2015, 2016 Intel Corporation.
5 * 6 *
6 * This file is provided under a dual BSD/GPLv2 license. When using or 7 * This file is provided under a dual BSD/GPLv2 license. When using or
7 * redistributing this file, you may do so under either license. 8 * redistributing this file, you may do so under either license.
8 * 9 *
9 * GPL LICENSE SUMMARY 10 * GPL LICENSE SUMMARY
10 * 11 *
11 * Copyright(c) 2015 Intel Corporation.
12 *
13 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as 13 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation. 14 * published by the Free Software Foundation.
@@ -21,8 +20,6 @@
21 * 20 *
22 * BSD LICENSE 21 * BSD LICENSE
23 * 22 *
24 * Copyright(c) 2015 Intel Corporation.
25 *
26 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
28 * are met: 25 * are met:
@@ -1281,6 +1278,9 @@
1281#define SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SHIFT 0 1278#define SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SHIFT 0
1282#define SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SMASK 0xFFFFull 1279#define SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SMASK 0xFFFFull
1283#define PCIE_CFG_REG_PL2 (PCIE + 0x000000000708) 1280#define PCIE_CFG_REG_PL2 (PCIE + 0x000000000708)
1281#define PCIE_CFG_REG_PL3 (PCIE + 0x00000000070C)
1282#define PCIE_CFG_REG_PL3_L1_ENT_LATENCY_SHIFT 27
1283#define PCIE_CFG_REG_PL3_L1_ENT_LATENCY_SMASK 0x38000000
1284#define PCIE_CFG_REG_PL102 (PCIE + 0x000000000898) 1284#define PCIE_CFG_REG_PL102 (PCIE + 0x000000000898)
1285#define PCIE_CFG_REG_PL102_GEN3_EQ_POST_CURSOR_PSET_SHIFT 12 1285#define PCIE_CFG_REG_PL102_GEN3_EQ_POST_CURSOR_PSET_SHIFT 12
1286#define PCIE_CFG_REG_PL102_GEN3_EQ_CURSOR_PSET_SHIFT 6 1286#define PCIE_CFG_REG_PL102_GEN3_EQ_CURSOR_PSET_SHIFT 6
@@ -1301,5 +1301,6 @@
1301#define CCE_INT_BLOCKED (CCE + 0x000000110C00) 1301#define CCE_INT_BLOCKED (CCE + 0x000000110C00)
1302#define SEND_DMA_IDLE_CNT (TXE + 0x000000200040) 1302#define SEND_DMA_IDLE_CNT (TXE + 0x000000200040)
1303#define SEND_DMA_DESC_FETCHED_CNT (TXE + 0x000000200058) 1303#define SEND_DMA_DESC_FETCHED_CNT (TXE + 0x000000200058)
1304#define CCE_MSIX_PBA_OFFSET 0X0110000
1304 1305
1305#endif /* DEF_CHIP_REG */ 1306#endif /* DEF_CHIP_REG */
diff --git a/drivers/staging/rdma/hfi1/common.h b/drivers/staging/rdma/hfi1/common.h
index 5dd92720faae..e9b6bb322025 100644
--- a/drivers/staging/rdma/hfi1/common.h
+++ b/drivers/staging/rdma/hfi1/common.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -341,19 +338,16 @@ struct hfi1_message_header {
341#define FULL_MGMT_P_KEY 0xFFFF 338#define FULL_MGMT_P_KEY 0xFFFF
342 339
343#define DEFAULT_P_KEY LIM_MGMT_P_KEY 340#define DEFAULT_P_KEY LIM_MGMT_P_KEY
344#define HFI1_PERMISSIVE_LID 0xFFFF
345#define HFI1_AETH_CREDIT_SHIFT 24 341#define HFI1_AETH_CREDIT_SHIFT 24
346#define HFI1_AETH_CREDIT_MASK 0x1F 342#define HFI1_AETH_CREDIT_MASK 0x1F
347#define HFI1_AETH_CREDIT_INVAL 0x1F 343#define HFI1_AETH_CREDIT_INVAL 0x1F
348#define HFI1_MSN_MASK 0xFFFFFF 344#define HFI1_MSN_MASK 0xFFFFFF
349#define HFI1_QPN_MASK 0xFFFFFF
350#define HFI1_FECN_SHIFT 31 345#define HFI1_FECN_SHIFT 31
351#define HFI1_FECN_MASK 1 346#define HFI1_FECN_MASK 1
352#define HFI1_FECN_SMASK (1 << HFI1_FECN_SHIFT) 347#define HFI1_FECN_SMASK BIT(HFI1_FECN_SHIFT)
353#define HFI1_BECN_SHIFT 30 348#define HFI1_BECN_SHIFT 30
354#define HFI1_BECN_MASK 1 349#define HFI1_BECN_MASK 1
355#define HFI1_BECN_SMASK (1 << HFI1_BECN_SHIFT) 350#define HFI1_BECN_SMASK BIT(HFI1_BECN_SHIFT)
356#define HFI1_MULTICAST_LID_BASE 0xC000
357 351
358static inline __u64 rhf_to_cpu(const __le32 *rbuf) 352static inline __u64 rhf_to_cpu(const __le32 *rbuf)
359{ 353{
diff --git a/drivers/staging/rdma/hfi1/debugfs.c b/drivers/staging/rdma/hfi1/debugfs.c
index acd2269e9f14..dbab9d9cc288 100644
--- a/drivers/staging/rdma/hfi1/debugfs.c
+++ b/drivers/staging/rdma/hfi1/debugfs.c
@@ -1,13 +1,12 @@
1#ifdef CONFIG_DEBUG_FS 1#ifdef CONFIG_DEBUG_FS
2/* 2/*
3 * Copyright(c) 2015, 2016 Intel Corporation.
3 * 4 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or 5 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license. 6 * redistributing this file, you may do so under either license.
6 * 7 *
7 * GPL LICENSE SUMMARY 8 * GPL LICENSE SUMMARY
8 * 9 *
9 * Copyright(c) 2015 Intel Corporation.
10 *
11 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as 11 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
@@ -19,8 +18,6 @@
19 * 18 *
20 * BSD LICENSE 19 * BSD LICENSE
21 * 20 *
22 * Copyright(c) 2015 Intel Corporation.
23 *
24 * Redistribution and use in source and binary forms, with or without 21 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions 22 * modification, are permitted provided that the following conditions
26 * are met: 23 * are met:
@@ -52,6 +49,7 @@
52#include <linux/seq_file.h> 49#include <linux/seq_file.h>
53#include <linux/kernel.h> 50#include <linux/kernel.h>
54#include <linux/export.h> 51#include <linux/export.h>
52#include <linux/module.h>
55 53
56#include "hfi.h" 54#include "hfi.h"
57#include "debugfs.h" 55#include "debugfs.h"
@@ -71,6 +69,7 @@ static const struct seq_operations _##name##_seq_ops = { \
71 .stop = _##name##_seq_stop, \ 69 .stop = _##name##_seq_stop, \
72 .show = _##name##_seq_show \ 70 .show = _##name##_seq_show \
73} 71}
72
74#define DEBUGFS_SEQ_FILE_OPEN(name) \ 73#define DEBUGFS_SEQ_FILE_OPEN(name) \
75static int _##name##_open(struct inode *inode, struct file *s) \ 74static int _##name##_open(struct inode *inode, struct file *s) \
76{ \ 75{ \
@@ -102,7 +101,6 @@ do { \
102 pr_warn("create of %s failed\n", name); \ 101 pr_warn("create of %s failed\n", name); \
103} while (0) 102} while (0)
104 103
105
106#define DEBUGFS_SEQ_FILE_CREATE(name, parent, data) \ 104#define DEBUGFS_SEQ_FILE_CREATE(name, parent, data) \
107 DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO) 105 DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO)
108 106
@@ -127,7 +125,6 @@ static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
127 return pos; 125 return pos;
128} 126}
129 127
130
131static void _opcode_stats_seq_stop(struct seq_file *s, void *v) 128static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
132__releases(RCU) 129__releases(RCU)
133{ 130{
@@ -151,8 +148,8 @@ static int _opcode_stats_seq_show(struct seq_file *s, void *v)
151 if (!n_packets && !n_bytes) 148 if (!n_packets && !n_bytes)
152 return SEQ_SKIP; 149 return SEQ_SKIP;
153 seq_printf(s, "%02llx %llu/%llu\n", i, 150 seq_printf(s, "%02llx %llu/%llu\n", i,
154 (unsigned long long) n_packets, 151 (unsigned long long)n_packets,
155 (unsigned long long) n_bytes); 152 (unsigned long long)n_bytes);
156 153
157 return 0; 154 return 0;
158} 155}
@@ -247,7 +244,7 @@ __acquires(RCU)
247} 244}
248 245
249static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr, 246static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
250 loff_t *pos) 247 loff_t *pos)
251{ 248{
252 struct qp_iter *iter = iter_ptr; 249 struct qp_iter *iter = iter_ptr;
253 250
@@ -308,7 +305,6 @@ static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
308 return pos; 305 return pos;
309} 306}
310 307
311
312static void _sdes_seq_stop(struct seq_file *s, void *v) 308static void _sdes_seq_stop(struct seq_file *s, void *v)
313__releases(RCU) 309__releases(RCU)
314{ 310{
@@ -341,7 +337,7 @@ static ssize_t dev_counters_read(struct file *file, char __user *buf,
341 337
342 rcu_read_lock(); 338 rcu_read_lock();
343 dd = private2dd(file); 339 dd = private2dd(file);
344 avail = hfi1_read_cntrs(dd, *ppos, NULL, &counters); 340 avail = hfi1_read_cntrs(dd, NULL, &counters);
345 rval = simple_read_from_buffer(buf, count, ppos, counters, avail); 341 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
346 rcu_read_unlock(); 342 rcu_read_unlock();
347 return rval; 343 return rval;
@@ -358,7 +354,7 @@ static ssize_t dev_names_read(struct file *file, char __user *buf,
358 354
359 rcu_read_lock(); 355 rcu_read_lock();
360 dd = private2dd(file); 356 dd = private2dd(file);
361 avail = hfi1_read_cntrs(dd, *ppos, &names, NULL); 357 avail = hfi1_read_cntrs(dd, &names, NULL);
362 rval = simple_read_from_buffer(buf, count, ppos, names, avail); 358 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
363 rcu_read_unlock(); 359 rcu_read_unlock();
364 return rval; 360 return rval;
@@ -385,8 +381,7 @@ static ssize_t portnames_read(struct file *file, char __user *buf,
385 381
386 rcu_read_lock(); 382 rcu_read_lock();
387 dd = private2dd(file); 383 dd = private2dd(file);
388 /* port number n/a here since names are constant */ 384 avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
389 avail = hfi1_read_portcntrs(dd, *ppos, 0, &names, NULL);
390 rval = simple_read_from_buffer(buf, count, ppos, names, avail); 385 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
391 rcu_read_unlock(); 386 rcu_read_unlock();
392 return rval; 387 return rval;
@@ -394,28 +389,150 @@ static ssize_t portnames_read(struct file *file, char __user *buf,
394 389
395/* read the per-port counters */ 390/* read the per-port counters */
396static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf, 391static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
397 size_t count, loff_t *ppos) 392 size_t count, loff_t *ppos)
398{ 393{
399 u64 *counters; 394 u64 *counters;
400 size_t avail; 395 size_t avail;
401 struct hfi1_devdata *dd;
402 struct hfi1_pportdata *ppd; 396 struct hfi1_pportdata *ppd;
403 ssize_t rval; 397 ssize_t rval;
404 398
405 rcu_read_lock(); 399 rcu_read_lock();
406 ppd = private2ppd(file); 400 ppd = private2ppd(file);
407 dd = ppd->dd; 401 avail = hfi1_read_portcntrs(ppd, NULL, &counters);
408 avail = hfi1_read_portcntrs(dd, *ppos, ppd->port - 1, NULL, &counters);
409 rval = simple_read_from_buffer(buf, count, ppos, counters, avail); 402 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
410 rcu_read_unlock(); 403 rcu_read_unlock();
411 return rval; 404 return rval;
412} 405}
413 406
407static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
408 int this_hfi, int hfi, u32 flag, const char *what)
409{
410 u32 mask;
411
412 mask = flag << (hfi ? CR_DYN_SHIFT : 0);
413 if (scratch0 & mask) {
414 *used += scnprintf(p + *used, size - *used,
415 " 0x%08x - HFI%d %s in use, %s device\n",
416 mask, hfi, what,
417 this_hfi == hfi ? "this" : "other");
418 }
419}
420
421static ssize_t asic_flags_read(struct file *file, char __user *buf,
422 size_t count, loff_t *ppos)
423{
424 struct hfi1_pportdata *ppd;
425 struct hfi1_devdata *dd;
426 u64 scratch0;
427 char *tmp;
428 int ret = 0;
429 int size;
430 int used;
431 int i;
432
433 rcu_read_lock();
434 ppd = private2ppd(file);
435 dd = ppd->dd;
436 size = PAGE_SIZE;
437 used = 0;
438 tmp = kmalloc(size, GFP_KERNEL);
439 if (!tmp) {
440 rcu_read_unlock();
441 return -ENOMEM;
442 }
443
444 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
445 used += scnprintf(tmp + used, size - used,
446 "Resource flags: 0x%016llx\n", scratch0);
447
448 /* check permanent flag */
449 if (scratch0 & CR_THERM_INIT) {
450 used += scnprintf(tmp + used, size - used,
451 " 0x%08x - thermal monitoring initialized\n",
452 (u32)CR_THERM_INIT);
453 }
454
455 /* check each dynamic flag on each HFI */
456 for (i = 0; i < 2; i++) {
457 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
458 CR_SBUS, "SBus");
459 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
460 CR_EPROM, "EPROM");
461 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
462 CR_I2C1, "i2c chain 1");
463 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
464 CR_I2C2, "i2c chain 2");
465 }
466 used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
467
468 ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
469 rcu_read_unlock();
470 kfree(tmp);
471 return ret;
472}
473
474static ssize_t asic_flags_write(struct file *file, const char __user *buf,
475 size_t count, loff_t *ppos)
476{
477 struct hfi1_pportdata *ppd;
478 struct hfi1_devdata *dd;
479 char *buff;
480 int ret;
481 unsigned long long value;
482 u64 scratch0;
483 u64 clear;
484
485 rcu_read_lock();
486 ppd = private2ppd(file);
487 dd = ppd->dd;
488
489 buff = kmalloc(count + 1, GFP_KERNEL);
490 if (!buff) {
491 ret = -ENOMEM;
492 goto do_return;
493 }
494
495 ret = copy_from_user(buff, buf, count);
496 if (ret > 0) {
497 ret = -EFAULT;
498 goto do_free;
499 }
500
501 /* zero terminate and read the expected integer */
502 buff[count] = 0;
503 ret = kstrtoull(buff, 0, &value);
504 if (ret)
505 goto do_free;
506 clear = value;
507
508 /* obtain exclusive access */
509 mutex_lock(&dd->asic_data->asic_resource_mutex);
510 acquire_hw_mutex(dd);
511
512 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
513 scratch0 &= ~clear;
514 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
515 /* force write to be visible to other HFI on another OS */
516 (void)read_csr(dd, ASIC_CFG_SCRATCH);
517
518 release_hw_mutex(dd);
519 mutex_unlock(&dd->asic_data->asic_resource_mutex);
520
521 /* return the number of bytes written */
522 ret = count;
523
524 do_free:
525 kfree(buff);
526 do_return:
527 rcu_read_unlock();
528 return ret;
529}
530
414/* 531/*
415 * read the per-port QSFP data for ppd 532 * read the per-port QSFP data for ppd
416 */ 533 */
417static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf, 534static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
418 size_t count, loff_t *ppos) 535 size_t count, loff_t *ppos)
419{ 536{
420 struct hfi1_pportdata *ppd; 537 struct hfi1_pportdata *ppd;
421 char *tmp; 538 char *tmp;
@@ -439,7 +556,7 @@ static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
439 556
440/* Do an i2c write operation on the chain for the given HFI. */ 557/* Do an i2c write operation on the chain for the given HFI. */
441static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf, 558static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
442 size_t count, loff_t *ppos, u32 target) 559 size_t count, loff_t *ppos, u32 target)
443{ 560{
444 struct hfi1_pportdata *ppd; 561 struct hfi1_pportdata *ppd;
445 char *buff; 562 char *buff;
@@ -451,6 +568,16 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
451 rcu_read_lock(); 568 rcu_read_lock();
452 ppd = private2ppd(file); 569 ppd = private2ppd(file);
453 570
571 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
572 i2c_addr = (*ppos >> 16) & 0xffff;
573 offset = *ppos & 0xffff;
574
575 /* explicitly reject invalid address 0 to catch cp and cat */
576 if (i2c_addr == 0) {
577 ret = -EINVAL;
578 goto _return;
579 }
580
454 buff = kmalloc(count, GFP_KERNEL); 581 buff = kmalloc(count, GFP_KERNEL);
455 if (!buff) { 582 if (!buff) {
456 ret = -ENOMEM; 583 ret = -ENOMEM;
@@ -463,9 +590,6 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
463 goto _free; 590 goto _free;
464 } 591 }
465 592
466 i2c_addr = (*ppos >> 16) & 0xff;
467 offset = *ppos & 0xffff;
468
469 total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count); 593 total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
470 if (total_written < 0) { 594 if (total_written < 0) {
471 ret = total_written; 595 ret = total_written;
@@ -485,21 +609,21 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
485 609
486/* Do an i2c write operation on chain for HFI 0. */ 610/* Do an i2c write operation on chain for HFI 0. */
487static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf, 611static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
488 size_t count, loff_t *ppos) 612 size_t count, loff_t *ppos)
489{ 613{
490 return __i2c_debugfs_write(file, buf, count, ppos, 0); 614 return __i2c_debugfs_write(file, buf, count, ppos, 0);
491} 615}
492 616
493/* Do an i2c write operation on chain for HFI 1. */ 617/* Do an i2c write operation on chain for HFI 1. */
494static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf, 618static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
495 size_t count, loff_t *ppos) 619 size_t count, loff_t *ppos)
496{ 620{
497 return __i2c_debugfs_write(file, buf, count, ppos, 1); 621 return __i2c_debugfs_write(file, buf, count, ppos, 1);
498} 622}
499 623
500/* Do an i2c read operation on the chain for the given HFI. */ 624/* Do an i2c read operation on the chain for the given HFI. */
501static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf, 625static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
502 size_t count, loff_t *ppos, u32 target) 626 size_t count, loff_t *ppos, u32 target)
503{ 627{
504 struct hfi1_pportdata *ppd; 628 struct hfi1_pportdata *ppd;
505 char *buff; 629 char *buff;
@@ -511,15 +635,22 @@ static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
511 rcu_read_lock(); 635 rcu_read_lock();
512 ppd = private2ppd(file); 636 ppd = private2ppd(file);
513 637
638 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
639 i2c_addr = (*ppos >> 16) & 0xffff;
640 offset = *ppos & 0xffff;
641
642 /* explicitly reject invalid address 0 to catch cp and cat */
643 if (i2c_addr == 0) {
644 ret = -EINVAL;
645 goto _return;
646 }
647
514 buff = kmalloc(count, GFP_KERNEL); 648 buff = kmalloc(count, GFP_KERNEL);
515 if (!buff) { 649 if (!buff) {
516 ret = -ENOMEM; 650 ret = -ENOMEM;
517 goto _return; 651 goto _return;
518 } 652 }
519 653
520 i2c_addr = (*ppos >> 16) & 0xff;
521 offset = *ppos & 0xffff;
522
523 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count); 654 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
524 if (total_read < 0) { 655 if (total_read < 0) {
525 ret = total_read; 656 ret = total_read;
@@ -545,21 +676,21 @@ static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
545 676
546/* Do an i2c read operation on chain for HFI 0. */ 677/* Do an i2c read operation on chain for HFI 0. */
547static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf, 678static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
548 size_t count, loff_t *ppos) 679 size_t count, loff_t *ppos)
549{ 680{
550 return __i2c_debugfs_read(file, buf, count, ppos, 0); 681 return __i2c_debugfs_read(file, buf, count, ppos, 0);
551} 682}
552 683
553/* Do an i2c read operation on chain for HFI 1. */ 684/* Do an i2c read operation on chain for HFI 1. */
554static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf, 685static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
555 size_t count, loff_t *ppos) 686 size_t count, loff_t *ppos)
556{ 687{
557 return __i2c_debugfs_read(file, buf, count, ppos, 1); 688 return __i2c_debugfs_read(file, buf, count, ppos, 1);
558} 689}
559 690
560/* Do a QSFP write operation on the i2c chain for the given HFI. */ 691/* Do a QSFP write operation on the i2c chain for the given HFI. */
561static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf, 692static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
562 size_t count, loff_t *ppos, u32 target) 693 size_t count, loff_t *ppos, u32 target)
563{ 694{
564 struct hfi1_pportdata *ppd; 695 struct hfi1_pportdata *ppd;
565 char *buff; 696 char *buff;
@@ -605,21 +736,21 @@ static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
605 736
606/* Do a QSFP write operation on i2c chain for HFI 0. */ 737/* Do a QSFP write operation on i2c chain for HFI 0. */
607static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf, 738static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
608 size_t count, loff_t *ppos) 739 size_t count, loff_t *ppos)
609{ 740{
610 return __qsfp_debugfs_write(file, buf, count, ppos, 0); 741 return __qsfp_debugfs_write(file, buf, count, ppos, 0);
611} 742}
612 743
613/* Do a QSFP write operation on i2c chain for HFI 1. */ 744/* Do a QSFP write operation on i2c chain for HFI 1. */
614static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf, 745static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
615 size_t count, loff_t *ppos) 746 size_t count, loff_t *ppos)
616{ 747{
617 return __qsfp_debugfs_write(file, buf, count, ppos, 1); 748 return __qsfp_debugfs_write(file, buf, count, ppos, 1);
618} 749}
619 750
620/* Do a QSFP read operation on the i2c chain for the given HFI. */ 751/* Do a QSFP read operation on the i2c chain for the given HFI. */
621static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf, 752static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
622 size_t count, loff_t *ppos, u32 target) 753 size_t count, loff_t *ppos, u32 target)
623{ 754{
624 struct hfi1_pportdata *ppd; 755 struct hfi1_pportdata *ppd;
625 char *buff; 756 char *buff;
@@ -665,18 +796,116 @@ static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
665 796
666/* Do a QSFP read operation on i2c chain for HFI 0. */ 797/* Do a QSFP read operation on i2c chain for HFI 0. */
667static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf, 798static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
668 size_t count, loff_t *ppos) 799 size_t count, loff_t *ppos)
669{ 800{
670 return __qsfp_debugfs_read(file, buf, count, ppos, 0); 801 return __qsfp_debugfs_read(file, buf, count, ppos, 0);
671} 802}
672 803
673/* Do a QSFP read operation on i2c chain for HFI 1. */ 804/* Do a QSFP read operation on i2c chain for HFI 1. */
674static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf, 805static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
675 size_t count, loff_t *ppos) 806 size_t count, loff_t *ppos)
676{ 807{
677 return __qsfp_debugfs_read(file, buf, count, ppos, 1); 808 return __qsfp_debugfs_read(file, buf, count, ppos, 1);
678} 809}
679 810
811static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
812{
813 struct hfi1_pportdata *ppd;
814 int ret;
815
816 if (!try_module_get(THIS_MODULE))
817 return -ENODEV;
818
819 ppd = private2ppd(fp);
820
821 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
822 if (ret) /* failed - release the module */
823 module_put(THIS_MODULE);
824
825 return ret;
826}
827
828static int i2c1_debugfs_open(struct inode *in, struct file *fp)
829{
830 return __i2c_debugfs_open(in, fp, 0);
831}
832
833static int i2c2_debugfs_open(struct inode *in, struct file *fp)
834{
835 return __i2c_debugfs_open(in, fp, 1);
836}
837
838static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
839{
840 struct hfi1_pportdata *ppd;
841
842 ppd = private2ppd(fp);
843
844 release_chip_resource(ppd->dd, i2c_target(target));
845 module_put(THIS_MODULE);
846
847 return 0;
848}
849
850static int i2c1_debugfs_release(struct inode *in, struct file *fp)
851{
852 return __i2c_debugfs_release(in, fp, 0);
853}
854
855static int i2c2_debugfs_release(struct inode *in, struct file *fp)
856{
857 return __i2c_debugfs_release(in, fp, 1);
858}
859
860static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
861{
862 struct hfi1_pportdata *ppd;
863 int ret;
864
865 if (!try_module_get(THIS_MODULE))
866 return -ENODEV;
867
868 ppd = private2ppd(fp);
869
870 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
871 if (ret) /* failed - release the module */
872 module_put(THIS_MODULE);
873
874 return ret;
875}
876
877static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
878{
879 return __qsfp_debugfs_open(in, fp, 0);
880}
881
882static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
883{
884 return __qsfp_debugfs_open(in, fp, 1);
885}
886
887static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
888{
889 struct hfi1_pportdata *ppd;
890
891 ppd = private2ppd(fp);
892
893 release_chip_resource(ppd->dd, i2c_target(target));
894 module_put(THIS_MODULE);
895
896 return 0;
897}
898
899static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
900{
901 return __qsfp_debugfs_release(in, fp, 0);
902}
903
904static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
905{
906 return __qsfp_debugfs_release(in, fp, 1);
907}
908
680#define DEBUGFS_OPS(nm, readroutine, writeroutine) \ 909#define DEBUGFS_OPS(nm, readroutine, writeroutine) \
681{ \ 910{ \
682 .name = nm, \ 911 .name = nm, \
@@ -687,6 +916,18 @@ static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
687 }, \ 916 }, \
688} 917}
689 918
919#define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
920{ \
921 .name = nm, \
922 .ops = { \
923 .read = readf, \
924 .write = writef, \
925 .llseek = generic_file_llseek, \
926 .open = openf, \
927 .release = releasef \
928 }, \
929}
930
690static const struct counter_info cntr_ops[] = { 931static const struct counter_info cntr_ops[] = {
691 DEBUGFS_OPS("counter_names", dev_names_read, NULL), 932 DEBUGFS_OPS("counter_names", dev_names_read, NULL),
692 DEBUGFS_OPS("counters", dev_counters_read, NULL), 933 DEBUGFS_OPS("counters", dev_counters_read, NULL),
@@ -695,11 +936,16 @@ static const struct counter_info cntr_ops[] = {
695 936
696static const struct counter_info port_cntr_ops[] = { 937static const struct counter_info port_cntr_ops[] = {
697 DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL), 938 DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
698 DEBUGFS_OPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write), 939 DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
699 DEBUGFS_OPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write), 940 i2c1_debugfs_open, i2c1_debugfs_release),
941 DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
942 i2c2_debugfs_open, i2c2_debugfs_release),
700 DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL), 943 DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
701 DEBUGFS_OPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write), 944 DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
702 DEBUGFS_OPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write), 945 qsfp1_debugfs_open, qsfp1_debugfs_release),
946 DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
947 qsfp2_debugfs_open, qsfp2_debugfs_release),
948 DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
703}; 949};
704 950
705void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd) 951void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
@@ -747,8 +993,8 @@ void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
747 ibd->hfi1_ibdev_dbg, 993 ibd->hfi1_ibdev_dbg,
748 ppd, 994 ppd,
749 &port_cntr_ops[i].ops, 995 &port_cntr_ops[i].ops,
750 port_cntr_ops[i].ops.write == NULL ? 996 !port_cntr_ops[i].ops.write ?
751 S_IRUGO : S_IRUGO|S_IWUSR); 997 S_IRUGO : S_IRUGO | S_IWUSR);
752 } 998 }
753} 999}
754 1000
diff --git a/drivers/staging/rdma/hfi1/debugfs.h b/drivers/staging/rdma/hfi1/debugfs.h
index 92d6fe146714..b6fb6814f1b8 100644
--- a/drivers/staging/rdma/hfi1/debugfs.h
+++ b/drivers/staging/rdma/hfi1/debugfs.h
@@ -1,14 +1,13 @@
1#ifndef _HFI1_DEBUGFS_H 1#ifndef _HFI1_DEBUGFS_H
2#define _HFI1_DEBUGFS_H 2#define _HFI1_DEBUGFS_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
diff --git a/drivers/staging/rdma/hfi1/device.c b/drivers/staging/rdma/hfi1/device.c
index 58472e5ac4e5..c05c39da83b1 100644
--- a/drivers/staging/rdma/hfi1/device.c
+++ b/drivers/staging/rdma/hfi1/device.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
diff --git a/drivers/staging/rdma/hfi1/device.h b/drivers/staging/rdma/hfi1/device.h
index 2850ff739d81..5bb3e83cf2da 100644
--- a/drivers/staging/rdma/hfi1/device.h
+++ b/drivers/staging/rdma/hfi1/device.h
@@ -1,14 +1,13 @@
1#ifndef _HFI1_DEVICE_H 1#ifndef _HFI1_DEVICE_H
2#define _HFI1_DEVICE_H 2#define _HFI1_DEVICE_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
diff --git a/drivers/staging/rdma/hfi1/diag.c b/drivers/staging/rdma/hfi1/diag.c
index e41159fe6889..c5b520bf610e 100644
--- a/drivers/staging/rdma/hfi1/diag.c
+++ b/drivers/staging/rdma/hfi1/diag.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -70,6 +67,7 @@
70#include "hfi.h" 67#include "hfi.h"
71#include "device.h" 68#include "device.h"
72#include "common.h" 69#include "common.h"
70#include "verbs_txreq.h"
73#include "trace.h" 71#include "trace.h"
74 72
75#undef pr_fmt 73#undef pr_fmt
@@ -80,15 +78,15 @@
80/* Snoop option mask */ 78/* Snoop option mask */
81#define SNOOP_DROP_SEND BIT(0) 79#define SNOOP_DROP_SEND BIT(0)
82#define SNOOP_USE_METADATA BIT(1) 80#define SNOOP_USE_METADATA BIT(1)
81#define SNOOP_SET_VL0TOVL15 BIT(2)
83 82
84static u8 snoop_flags; 83static u8 snoop_flags;
85 84
86/* 85/*
87 * Extract packet length from LRH header. 86 * Extract packet length from LRH header.
88 * Why & 0x7FF? Because len is only 11 bits in case it wasn't 0'd we throw the 87 * This is in Dwords so multiply by 4 to get size in bytes
89 * bogus bits away. This is in Dwords so multiply by 4 to get size in bytes
90 */ 88 */
91#define HFI1_GET_PKT_LEN(x) (((be16_to_cpu((x)->lrh[2]) & 0x7FF)) << 2) 89#define HFI1_GET_PKT_LEN(x) (((be16_to_cpu((x)->lrh[2]) & 0xFFF)) << 2)
92 90
93enum hfi1_filter_status { 91enum hfi1_filter_status {
94 HFI1_FILTER_HIT, 92 HFI1_FILTER_HIT,
@@ -860,7 +858,7 @@ static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data,
860 vl = sc4; 858 vl = sc4;
861 } else { 859 } else {
862 sl = (byte_two >> 4) & 0xf; 860 sl = (byte_two >> 4) & 0xf;
863 ibp = to_iport(&dd->verbs_dev.ibdev, 1); 861 ibp = to_iport(&dd->verbs_dev.rdi.ibdev, 1);
864 sc5 = ibp->sl_to_sc[sl]; 862 sc5 = ibp->sl_to_sc[sl];
865 vl = sc_to_vlt(dd, sc5); 863 vl = sc_to_vlt(dd, sc5);
866 if (vl != sc4) { 864 if (vl != sc4) {
@@ -966,6 +964,65 @@ static ssize_t hfi1_snoop_read(struct file *fp, char __user *data,
966 return ret; 964 return ret;
967} 965}
968 966
967/**
968 * hfi1_assign_snoop_link_credits -- Set up credits for VL15 and others
969 * @ppd : ptr to hfi1 port data
970 * @value : options from user space
971 *
972 * Assumes the rest of the CM credit registers are zero from a
973 * previous global or credit reset.
974 * Leave shared count at zero for both global and all vls.
975 * In snoop mode ideally we don't use shared credits
976 * Reserve 8.5k for VL15
977 * If total credits less than 8.5kbytes return error.
978 * Divide the rest of the credits across VL0 to VL7 and if
979 * each of these levels has less than 34 credits (at least 2048 + 128 bytes)
980 * return with an error.
981 * The credit registers will be reset to zero on link negotiation or link up
982 * so this function should be activated from user space only if the port has
983 * gone past link negotiation and link up.
984 *
985 * Return -- 0 if successful else error condition
986 *
987 */
988static long hfi1_assign_snoop_link_credits(struct hfi1_pportdata *ppd,
989 int value)
990{
991#define OPA_MIN_PER_VL_CREDITS 34 /* 2048 + 128 bytes */
992 struct buffer_control t;
993 int i;
994 struct hfi1_devdata *dd = ppd->dd;
995 u16 total_credits = (value >> 16) & 0xffff;
996 u16 vl15_credits = dd->vl15_init / 2;
997 u16 per_vl_credits;
998 __be16 be_per_vl_credits;
999
1000 if (!(ppd->host_link_state & HLS_UP))
1001 goto err_exit;
1002 if (total_credits < vl15_credits)
1003 goto err_exit;
1004
1005 per_vl_credits = (total_credits - vl15_credits) / TXE_NUM_DATA_VL;
1006
1007 if (per_vl_credits < OPA_MIN_PER_VL_CREDITS)
1008 goto err_exit;
1009
1010 memset(&t, 0, sizeof(t));
1011 be_per_vl_credits = cpu_to_be16(per_vl_credits);
1012
1013 for (i = 0; i < TXE_NUM_DATA_VL; i++)
1014 t.vl[i].dedicated = be_per_vl_credits;
1015
1016 t.vl[15].dedicated = cpu_to_be16(vl15_credits);
1017 return set_buffer_control(ppd, &t);
1018
1019err_exit:
1020 snoop_dbg("port_state = 0x%x, total_credits = %d, vl15_credits = %d",
1021 ppd->host_link_state, total_credits, vl15_credits);
1022
1023 return -EINVAL;
1024}
1025
969static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) 1026static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
970{ 1027{
971 struct hfi1_devdata *dd; 1028 struct hfi1_devdata *dd;
@@ -1192,6 +1249,10 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
1192 snoop_flags |= SNOOP_DROP_SEND; 1249 snoop_flags |= SNOOP_DROP_SEND;
1193 if (value & SNOOP_USE_METADATA) 1250 if (value & SNOOP_USE_METADATA)
1194 snoop_flags |= SNOOP_USE_METADATA; 1251 snoop_flags |= SNOOP_USE_METADATA;
1252 if (value & (SNOOP_SET_VL0TOVL15)) {
1253 ppd = &dd->pport[0]; /* first port will do */
1254 ret = hfi1_assign_snoop_link_credits(ppd, value);
1255 }
1195 break; 1256 break;
1196 default: 1257 default:
1197 return -ENOTTY; 1258 return -ENOTTY;
@@ -1603,7 +1664,7 @@ int snoop_recv_handler(struct hfi1_packet *packet)
1603/* 1664/*
1604 * Handle snooping and capturing packets when sdma is being used. 1665 * Handle snooping and capturing packets when sdma is being used.
1605 */ 1666 */
1606int snoop_send_dma_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 1667int snoop_send_dma_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1607 u64 pbc) 1668 u64 pbc)
1608{ 1669{
1609 pr_alert("Snooping/Capture of Send DMA Packets Is Not Supported!\n"); 1670 pr_alert("Snooping/Capture of Send DMA Packets Is Not Supported!\n");
@@ -1616,20 +1677,19 @@ int snoop_send_dma_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1616 * bypass packets. The only way to send a bypass packet currently is to use the 1677 * bypass packets. The only way to send a bypass packet currently is to use the
1617 * diagpkt interface. When that interface is enable snoop/capture is not. 1678 * diagpkt interface. When that interface is enable snoop/capture is not.
1618 */ 1679 */
1619int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 1680int snoop_send_pio_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1620 u64 pbc) 1681 u64 pbc)
1621{ 1682{
1622 struct ahg_ib_header *ahdr = qp->s_hdr;
1623 u32 hdrwords = qp->s_hdrwords; 1683 u32 hdrwords = qp->s_hdrwords;
1624 struct hfi1_sge_state *ss = qp->s_cur_sge; 1684 struct rvt_sge_state *ss = qp->s_cur_sge;
1625 u32 len = qp->s_cur_size; 1685 u32 len = qp->s_cur_size;
1626 u32 dwords = (len + 3) >> 2; 1686 u32 dwords = (len + 3) >> 2;
1627 u32 plen = hdrwords + dwords + 2; /* includes pbc */ 1687 u32 plen = hdrwords + dwords + 2; /* includes pbc */
1628 struct hfi1_pportdata *ppd = ps->ppd; 1688 struct hfi1_pportdata *ppd = ps->ppd;
1629 struct snoop_packet *s_packet = NULL; 1689 struct snoop_packet *s_packet = NULL;
1630 u32 *hdr = (u32 *)&ahdr->ibh; 1690 u32 *hdr = (u32 *)&ps->s_txreq->phdr.hdr;
1631 u32 length = 0; 1691 u32 length = 0;
1632 struct hfi1_sge_state temp_ss; 1692 struct rvt_sge_state temp_ss;
1633 void *data = NULL; 1693 void *data = NULL;
1634 void *data_start = NULL; 1694 void *data_start = NULL;
1635 int ret; 1695 int ret;
@@ -1638,7 +1698,7 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1638 struct capture_md md; 1698 struct capture_md md;
1639 u32 vl; 1699 u32 vl;
1640 u32 hdr_len = hdrwords << 2; 1700 u32 hdr_len = hdrwords << 2;
1641 u32 tlen = HFI1_GET_PKT_LEN(&ahdr->ibh); 1701 u32 tlen = HFI1_GET_PKT_LEN(&ps->s_txreq->phdr.hdr);
1642 1702
1643 md.u.pbc = 0; 1703 md.u.pbc = 0;
1644 1704
@@ -1665,7 +1725,7 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1665 md.port = 1; 1725 md.port = 1;
1666 md.dir = PKT_DIR_EGRESS; 1726 md.dir = PKT_DIR_EGRESS;
1667 if (likely(pbc == 0)) { 1727 if (likely(pbc == 0)) {
1668 vl = be16_to_cpu(ahdr->ibh.lrh[0]) >> 12; 1728 vl = be16_to_cpu(ps->s_txreq->phdr.hdr.lrh[0]) >> 12;
1669 md.u.pbc = create_pbc(ppd, 0, qp->s_srate, vl, plen); 1729 md.u.pbc = create_pbc(ppd, 0, qp->s_srate, vl, plen);
1670 } else { 1730 } else {
1671 md.u.pbc = 0; 1731 md.u.pbc = 0;
@@ -1727,7 +1787,7 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1727 ret = HFI1_FILTER_HIT; 1787 ret = HFI1_FILTER_HIT;
1728 } else { 1788 } else {
1729 ret = ppd->dd->hfi1_snoop.filter_callback( 1789 ret = ppd->dd->hfi1_snoop.filter_callback(
1730 &ahdr->ibh, 1790 &ps->s_txreq->phdr.hdr,
1731 NULL, 1791 NULL,
1732 ppd->dd->hfi1_snoop.filter_value); 1792 ppd->dd->hfi1_snoop.filter_value);
1733 } 1793 }
@@ -1759,9 +1819,16 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1759 spin_unlock_irqrestore(&qp->s_lock, flags); 1819 spin_unlock_irqrestore(&qp->s_lock, flags);
1760 } else if (qp->ibqp.qp_type == IB_QPT_RC) { 1820 } else if (qp->ibqp.qp_type == IB_QPT_RC) {
1761 spin_lock_irqsave(&qp->s_lock, flags); 1821 spin_lock_irqsave(&qp->s_lock, flags);
1762 hfi1_rc_send_complete(qp, &ahdr->ibh); 1822 hfi1_rc_send_complete(qp,
1823 &ps->s_txreq->phdr.hdr);
1763 spin_unlock_irqrestore(&qp->s_lock, flags); 1824 spin_unlock_irqrestore(&qp->s_lock, flags);
1764 } 1825 }
1826
1827 /*
1828 * If snoop is dropping the packet we need to put the
1829 * txreq back because no one else will.
1830 */
1831 hfi1_put_txreq(ps->s_txreq);
1765 return 0; 1832 return 0;
1766 } 1833 }
1767 break; 1834 break;
diff --git a/drivers/staging/rdma/hfi1/dma.c b/drivers/staging/rdma/hfi1/dma.c
index e03bd735173c..7e8dab892848 100644
--- a/drivers/staging/rdma/hfi1/dma.c
+++ b/drivers/staging/rdma/hfi1/dma.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -52,7 +49,7 @@
52 49
53#include "verbs.h" 50#include "verbs.h"
54 51
55#define BAD_DMA_ADDRESS ((u64) 0) 52#define BAD_DMA_ADDRESS ((u64)0)
56 53
57/* 54/*
58 * The following functions implement driver specific replacements 55 * The following functions implement driver specific replacements
@@ -74,7 +71,7 @@ static u64 hfi1_dma_map_single(struct ib_device *dev, void *cpu_addr,
74 if (WARN_ON(!valid_dma_direction(direction))) 71 if (WARN_ON(!valid_dma_direction(direction)))
75 return BAD_DMA_ADDRESS; 72 return BAD_DMA_ADDRESS;
76 73
77 return (u64) cpu_addr; 74 return (u64)cpu_addr;
78} 75}
79 76
80static void hfi1_dma_unmap_single(struct ib_device *dev, u64 addr, size_t size, 77static void hfi1_dma_unmap_single(struct ib_device *dev, u64 addr, size_t size,
@@ -95,7 +92,7 @@ static u64 hfi1_dma_map_page(struct ib_device *dev, struct page *page,
95 if (offset + size > PAGE_SIZE) 92 if (offset + size > PAGE_SIZE)
96 return BAD_DMA_ADDRESS; 93 return BAD_DMA_ADDRESS;
97 94
98 addr = (u64) page_address(page); 95 addr = (u64)page_address(page);
99 if (addr) 96 if (addr)
100 addr += offset; 97 addr += offset;
101 98
@@ -120,7 +117,7 @@ static int hfi1_map_sg(struct ib_device *dev, struct scatterlist *sgl,
120 return BAD_DMA_ADDRESS; 117 return BAD_DMA_ADDRESS;
121 118
122 for_each_sg(sgl, sg, nents, i) { 119 for_each_sg(sgl, sg, nents, i) {
123 addr = (u64) page_address(sg_page(sg)); 120 addr = (u64)page_address(sg_page(sg));
124 if (!addr) { 121 if (!addr) {
125 ret = 0; 122 ret = 0;
126 break; 123 break;
@@ -161,14 +158,14 @@ static void *hfi1_dma_alloc_coherent(struct ib_device *dev, size_t size,
161 if (p) 158 if (p)
162 addr = page_address(p); 159 addr = page_address(p);
163 if (dma_handle) 160 if (dma_handle)
164 *dma_handle = (u64) addr; 161 *dma_handle = (u64)addr;
165 return addr; 162 return addr;
166} 163}
167 164
168static void hfi1_dma_free_coherent(struct ib_device *dev, size_t size, 165static void hfi1_dma_free_coherent(struct ib_device *dev, size_t size,
169 void *cpu_addr, u64 dma_handle) 166 void *cpu_addr, u64 dma_handle)
170{ 167{
171 free_pages((unsigned long) cpu_addr, get_order(size)); 168 free_pages((unsigned long)cpu_addr, get_order(size));
172} 169}
173 170
174struct ib_dma_mapping_ops hfi1_dma_mapping_ops = { 171struct ib_dma_mapping_ops hfi1_dma_mapping_ops = {
diff --git a/drivers/staging/rdma/hfi1/driver.c b/drivers/staging/rdma/hfi1/driver.c
index ee50bbf64d39..34511e5df1d5 100644
--- a/drivers/staging/rdma/hfi1/driver.c
+++ b/drivers/staging/rdma/hfi1/driver.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -56,6 +53,7 @@
56#include <linux/vmalloc.h> 53#include <linux/vmalloc.h>
57#include <linux/module.h> 54#include <linux/module.h>
58#include <linux/prefetch.h> 55#include <linux/prefetch.h>
56#include <rdma/ib_verbs.h>
59 57
60#include "hfi.h" 58#include "hfi.h"
61#include "trace.h" 59#include "trace.h"
@@ -162,6 +160,22 @@ const char *get_unit_name(int unit)
162 return iname; 160 return iname;
163} 161}
164 162
163const char *get_card_name(struct rvt_dev_info *rdi)
164{
165 struct hfi1_ibdev *ibdev = container_of(rdi, struct hfi1_ibdev, rdi);
166 struct hfi1_devdata *dd = container_of(ibdev,
167 struct hfi1_devdata, verbs_dev);
168 return get_unit_name(dd->unit);
169}
170
171struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi)
172{
173 struct hfi1_ibdev *ibdev = container_of(rdi, struct hfi1_ibdev, rdi);
174 struct hfi1_devdata *dd = container_of(ibdev,
175 struct hfi1_devdata, verbs_dev);
176 return dd->pcidev;
177}
178
165/* 179/*
166 * Return count of units with at least one port ACTIVE. 180 * Return count of units with at least one port ACTIVE.
167 */ 181 */
@@ -265,6 +279,8 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
265 u32 rte = rhf_rcv_type_err(packet->rhf); 279 u32 rte = rhf_rcv_type_err(packet->rhf);
266 int lnh = be16_to_cpu(rhdr->lrh[0]) & 3; 280 int lnh = be16_to_cpu(rhdr->lrh[0]) & 3;
267 struct hfi1_ibport *ibp = &ppd->ibport_data; 281 struct hfi1_ibport *ibp = &ppd->ibport_data;
282 struct hfi1_devdata *dd = ppd->dd;
283 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
268 284
269 if (packet->rhf & (RHF_VCRC_ERR | RHF_ICRC_ERR)) 285 if (packet->rhf & (RHF_VCRC_ERR | RHF_ICRC_ERR))
270 return; 286 return;
@@ -283,9 +299,9 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
283 goto drop; 299 goto drop;
284 300
285 /* Check for GRH */ 301 /* Check for GRH */
286 if (lnh == HFI1_LRH_BTH) 302 if (lnh == HFI1_LRH_BTH) {
287 ohdr = &hdr->u.oth; 303 ohdr = &hdr->u.oth;
288 else if (lnh == HFI1_LRH_GRH) { 304 } else if (lnh == HFI1_LRH_GRH) {
289 u32 vtf; 305 u32 vtf;
290 306
291 ohdr = &hdr->u.l.oth; 307 ohdr = &hdr->u.l.oth;
@@ -295,17 +311,17 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
295 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION) 311 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
296 goto drop; 312 goto drop;
297 rcv_flags |= HFI1_HAS_GRH; 313 rcv_flags |= HFI1_HAS_GRH;
298 } else 314 } else {
299 goto drop; 315 goto drop;
300 316 }
301 /* Get the destination QP number. */ 317 /* Get the destination QP number. */
302 qp_num = be32_to_cpu(ohdr->bth[1]) & HFI1_QPN_MASK; 318 qp_num = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
303 if (lid < HFI1_MULTICAST_LID_BASE) { 319 if (lid < be16_to_cpu(IB_MULTICAST_LID_BASE)) {
304 struct hfi1_qp *qp; 320 struct rvt_qp *qp;
305 unsigned long flags; 321 unsigned long flags;
306 322
307 rcu_read_lock(); 323 rcu_read_lock();
308 qp = hfi1_lookup_qpn(ibp, qp_num); 324 qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
309 if (!qp) { 325 if (!qp) {
310 rcu_read_unlock(); 326 rcu_read_unlock();
311 goto drop; 327 goto drop;
@@ -318,9 +334,9 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
318 spin_lock_irqsave(&qp->r_lock, flags); 334 spin_lock_irqsave(&qp->r_lock, flags);
319 335
320 /* Check for valid receive state. */ 336 /* Check for valid receive state. */
321 if (!(ib_hfi1_state_ops[qp->state] & 337 if (!(ib_rvt_state_ops[qp->state] &
322 HFI1_PROCESS_RECV_OK)) { 338 RVT_PROCESS_RECV_OK)) {
323 ibp->n_pkt_drops++; 339 ibp->rvp.n_pkt_drops++;
324 } 340 }
325 341
326 switch (qp->ibqp.qp_type) { 342 switch (qp->ibqp.qp_type) {
@@ -352,7 +368,7 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
352 if (rhf_use_egr_bfr(packet->rhf)) 368 if (rhf_use_egr_bfr(packet->rhf))
353 ebuf = packet->ebuf; 369 ebuf = packet->ebuf;
354 370
355 if (ebuf == NULL) 371 if (!ebuf)
356 goto drop; /* this should never happen */ 372 goto drop; /* this should never happen */
357 373
358 if (lnh == HFI1_LRH_BTH) 374 if (lnh == HFI1_LRH_BTH)
@@ -370,7 +386,7 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
370 * Only in pre-B0 h/w is the CNP_OPCODE handled 386 * Only in pre-B0 h/w is the CNP_OPCODE handled
371 * via this code path. 387 * via this code path.
372 */ 388 */
373 struct hfi1_qp *qp = NULL; 389 struct rvt_qp *qp = NULL;
374 u32 lqpn, rqpn; 390 u32 lqpn, rqpn;
375 u16 rlid; 391 u16 rlid;
376 u8 svc_type, sl, sc5; 392 u8 svc_type, sl, sc5;
@@ -380,10 +396,10 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
380 sc5 |= 0x10; 396 sc5 |= 0x10;
381 sl = ibp->sc_to_sl[sc5]; 397 sl = ibp->sc_to_sl[sc5];
382 398
383 lqpn = be32_to_cpu(bth[1]) & HFI1_QPN_MASK; 399 lqpn = be32_to_cpu(bth[1]) & RVT_QPN_MASK;
384 rcu_read_lock(); 400 rcu_read_lock();
385 qp = hfi1_lookup_qpn(ibp, lqpn); 401 qp = rvt_lookup_qpn(rdi, &ibp->rvp, lqpn);
386 if (qp == NULL) { 402 if (!qp) {
387 rcu_read_unlock(); 403 rcu_read_unlock();
388 goto drop; 404 goto drop;
389 } 405 }
@@ -419,9 +435,8 @@ drop:
419} 435}
420 436
421static inline void init_packet(struct hfi1_ctxtdata *rcd, 437static inline void init_packet(struct hfi1_ctxtdata *rcd,
422 struct hfi1_packet *packet) 438 struct hfi1_packet *packet)
423{ 439{
424
425 packet->rsize = rcd->rcvhdrqentsize; /* words */ 440 packet->rsize = rcd->rcvhdrqentsize; /* words */
426 packet->maxcnt = rcd->rcvhdrq_cnt * packet->rsize; /* words */ 441 packet->maxcnt = rcd->rcvhdrq_cnt * packet->rsize; /* words */
427 packet->rcd = rcd; 442 packet->rcd = rcd;
@@ -434,12 +449,7 @@ static inline void init_packet(struct hfi1_ctxtdata *rcd,
434 packet->rcv_flags = 0; 449 packet->rcv_flags = 0;
435} 450}
436 451
437#ifndef CONFIG_PRESCAN_RXQ 452static void process_ecn(struct rvt_qp *qp, struct hfi1_ib_header *hdr,
438static void prescan_rxq(struct hfi1_packet *packet) {}
439#else /* !CONFIG_PRESCAN_RXQ */
440static int prescan_receive_queue;
441
442static void process_ecn(struct hfi1_qp *qp, struct hfi1_ib_header *hdr,
443 struct hfi1_other_headers *ohdr, 453 struct hfi1_other_headers *ohdr,
444 u64 rhf, u32 bth1, struct ib_grh *grh) 454 u64 rhf, u32 bth1, struct ib_grh *grh)
445{ 455{
@@ -453,7 +463,7 @@ static void process_ecn(struct hfi1_qp *qp, struct hfi1_ib_header *hdr,
453 case IB_QPT_GSI: 463 case IB_QPT_GSI:
454 case IB_QPT_UD: 464 case IB_QPT_UD:
455 rlid = be16_to_cpu(hdr->lrh[3]); 465 rlid = be16_to_cpu(hdr->lrh[3]);
456 rqpn = be32_to_cpu(ohdr->u.ud.deth[1]) & HFI1_QPN_MASK; 466 rqpn = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
457 svc_type = IB_CC_SVCTYPE_UD; 467 svc_type = IB_CC_SVCTYPE_UD;
458 break; 468 break;
459 case IB_QPT_UC: 469 case IB_QPT_UC:
@@ -483,7 +493,7 @@ static void process_ecn(struct hfi1_qp *qp, struct hfi1_ib_header *hdr,
483 493
484 if (bth1 & HFI1_BECN_SMASK) { 494 if (bth1 & HFI1_BECN_SMASK) {
485 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 495 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
486 u32 lqpn = bth1 & HFI1_QPN_MASK; 496 u32 lqpn = bth1 & RVT_QPN_MASK;
487 u8 sl = ibp->sc_to_sl[sc5]; 497 u8 sl = ibp->sc_to_sl[sc5];
488 498
489 process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type); 499 process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type);
@@ -562,26 +572,31 @@ static inline void update_ps_mdata(struct ps_mdata *mdata,
562 * containing Excplicit Congestion Notifications (FECNs, or BECNs). 572 * containing Excplicit Congestion Notifications (FECNs, or BECNs).
563 * When an ECN is found, process the Congestion Notification, and toggle 573 * When an ECN is found, process the Congestion Notification, and toggle
564 * it off. 574 * it off.
575 * This is declared as a macro to allow quick checking of the port to avoid
576 * the overhead of a function call if not enabled.
565 */ 577 */
566static void prescan_rxq(struct hfi1_packet *packet) 578#define prescan_rxq(rcd, packet) \
579 do { \
580 if (rcd->ppd->cc_prescan) \
581 __prescan_rxq(packet); \
582 } while (0)
583static void __prescan_rxq(struct hfi1_packet *packet)
567{ 584{
568 struct hfi1_ctxtdata *rcd = packet->rcd; 585 struct hfi1_ctxtdata *rcd = packet->rcd;
569 struct ps_mdata mdata; 586 struct ps_mdata mdata;
570 587
571 if (!prescan_receive_queue)
572 return;
573
574 init_ps_mdata(&mdata, packet); 588 init_ps_mdata(&mdata, packet);
575 589
576 while (1) { 590 while (1) {
577 struct hfi1_devdata *dd = rcd->dd; 591 struct hfi1_devdata *dd = rcd->dd;
578 struct hfi1_ibport *ibp = &rcd->ppd->ibport_data; 592 struct hfi1_ibport *ibp = &rcd->ppd->ibport_data;
579 __le32 *rhf_addr = (__le32 *) rcd->rcvhdrq + mdata.ps_head + 593 __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head +
580 dd->rhf_offset; 594 dd->rhf_offset;
581 struct hfi1_qp *qp; 595 struct rvt_qp *qp;
582 struct hfi1_ib_header *hdr; 596 struct hfi1_ib_header *hdr;
583 struct hfi1_other_headers *ohdr; 597 struct hfi1_other_headers *ohdr;
584 struct ib_grh *grh = NULL; 598 struct ib_grh *grh = NULL;
599 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
585 u64 rhf = rhf_to_cpu(rhf_addr); 600 u64 rhf = rhf_to_cpu(rhf_addr);
586 u32 etype = rhf_rcv_type(rhf), qpn, bth1; 601 u32 etype = rhf_rcv_type(rhf), qpn, bth1;
587 int is_ecn = 0; 602 int is_ecn = 0;
@@ -600,25 +615,25 @@ static void prescan_rxq(struct hfi1_packet *packet)
600 hfi1_get_msgheader(dd, rhf_addr); 615 hfi1_get_msgheader(dd, rhf_addr);
601 lnh = be16_to_cpu(hdr->lrh[0]) & 3; 616 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
602 617
603 if (lnh == HFI1_LRH_BTH) 618 if (lnh == HFI1_LRH_BTH) {
604 ohdr = &hdr->u.oth; 619 ohdr = &hdr->u.oth;
605 else if (lnh == HFI1_LRH_GRH) { 620 } else if (lnh == HFI1_LRH_GRH) {
606 ohdr = &hdr->u.l.oth; 621 ohdr = &hdr->u.l.oth;
607 grh = &hdr->u.l.grh; 622 grh = &hdr->u.l.grh;
608 } else 623 } else {
609 goto next; /* just in case */ 624 goto next; /* just in case */
610 625 }
611 bth1 = be32_to_cpu(ohdr->bth[1]); 626 bth1 = be32_to_cpu(ohdr->bth[1]);
612 is_ecn = !!(bth1 & (HFI1_FECN_SMASK | HFI1_BECN_SMASK)); 627 is_ecn = !!(bth1 & (HFI1_FECN_SMASK | HFI1_BECN_SMASK));
613 628
614 if (!is_ecn) 629 if (!is_ecn)
615 goto next; 630 goto next;
616 631
617 qpn = bth1 & HFI1_QPN_MASK; 632 qpn = bth1 & RVT_QPN_MASK;
618 rcu_read_lock(); 633 rcu_read_lock();
619 qp = hfi1_lookup_qpn(ibp, qpn); 634 qp = rvt_lookup_qpn(rdi, &ibp->rvp, qpn);
620 635
621 if (qp == NULL) { 636 if (!qp) {
622 rcu_read_unlock(); 637 rcu_read_unlock();
623 goto next; 638 goto next;
624 } 639 }
@@ -633,7 +648,6 @@ next:
633 update_ps_mdata(&mdata, rcd); 648 update_ps_mdata(&mdata, rcd);
634 } 649 }
635} 650}
636#endif /* CONFIG_PRESCAN_RXQ */
637 651
638static inline int skip_rcv_packet(struct hfi1_packet *packet, int thread) 652static inline int skip_rcv_packet(struct hfi1_packet *packet, int thread)
639{ 653{
@@ -683,8 +697,9 @@ static inline int process_rcv_packet(struct hfi1_packet *packet, int thread)
683 * The +2 is the size of the RHF. 697 * The +2 is the size of the RHF.
684 */ 698 */
685 prefetch_range(packet->ebuf, 699 prefetch_range(packet->ebuf,
686 packet->tlen - ((packet->rcd->rcvhdrqentsize - 700 packet->tlen - ((packet->rcd->rcvhdrqentsize -
687 (rhf_hdrq_offset(packet->rhf)+2)) * 4)); 701 (rhf_hdrq_offset(packet->rhf)
702 + 2)) * 4));
688 } 703 }
689 704
690 /* 705 /*
@@ -712,7 +727,7 @@ static inline int process_rcv_packet(struct hfi1_packet *packet, int thread)
712 } 727 }
713 } 728 }
714 729
715 packet->rhf_addr = (__le32 *) packet->rcd->rcvhdrq + packet->rhqoff + 730 packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff +
716 packet->rcd->dd->rhf_offset; 731 packet->rcd->dd->rhf_offset;
717 packet->rhf = rhf_to_cpu(packet->rhf_addr); 732 packet->rhf = rhf_to_cpu(packet->rhf_addr);
718 733
@@ -737,7 +752,6 @@ static inline void process_rcv_update(int last, struct hfi1_packet *packet)
737 752
738static inline void finish_packet(struct hfi1_packet *packet) 753static inline void finish_packet(struct hfi1_packet *packet)
739{ 754{
740
741 /* 755 /*
742 * Nothing we need to free for the packet. 756 * Nothing we need to free for the packet.
743 * 757 *
@@ -746,14 +760,12 @@ static inline void finish_packet(struct hfi1_packet *packet)
746 */ 760 */
747 update_usrhead(packet->rcd, packet->rcd->head, packet->updegr, 761 update_usrhead(packet->rcd, packet->rcd->head, packet->updegr,
748 packet->etail, rcv_intr_dynamic, packet->numpkt); 762 packet->etail, rcv_intr_dynamic, packet->numpkt);
749
750} 763}
751 764
752static inline void process_rcv_qp_work(struct hfi1_packet *packet) 765static inline void process_rcv_qp_work(struct hfi1_packet *packet)
753{ 766{
754
755 struct hfi1_ctxtdata *rcd; 767 struct hfi1_ctxtdata *rcd;
756 struct hfi1_qp *qp, *nqp; 768 struct rvt_qp *qp, *nqp;
757 769
758 rcd = packet->rcd; 770 rcd = packet->rcd;
759 rcd->head = packet->rhqoff; 771 rcd->head = packet->rhqoff;
@@ -764,17 +776,17 @@ static inline void process_rcv_qp_work(struct hfi1_packet *packet)
764 */ 776 */
765 list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) { 777 list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) {
766 list_del_init(&qp->rspwait); 778 list_del_init(&qp->rspwait);
767 if (qp->r_flags & HFI1_R_RSP_DEFERED_ACK) { 779 if (qp->r_flags & RVT_R_RSP_NAK) {
768 qp->r_flags &= ~HFI1_R_RSP_DEFERED_ACK; 780 qp->r_flags &= ~RVT_R_RSP_NAK;
769 hfi1_send_rc_ack(rcd, qp, 0); 781 hfi1_send_rc_ack(rcd, qp, 0);
770 } 782 }
771 if (qp->r_flags & HFI1_R_RSP_SEND) { 783 if (qp->r_flags & RVT_R_RSP_SEND) {
772 unsigned long flags; 784 unsigned long flags;
773 785
774 qp->r_flags &= ~HFI1_R_RSP_SEND; 786 qp->r_flags &= ~RVT_R_RSP_SEND;
775 spin_lock_irqsave(&qp->s_lock, flags); 787 spin_lock_irqsave(&qp->s_lock, flags);
776 if (ib_hfi1_state_ops[qp->state] & 788 if (ib_rvt_state_ops[qp->state] &
777 HFI1_PROCESS_OR_FLUSH_SEND) 789 RVT_PROCESS_OR_FLUSH_SEND)
778 hfi1_schedule_send(qp); 790 hfi1_schedule_send(qp);
779 spin_unlock_irqrestore(&qp->s_lock, flags); 791 spin_unlock_irqrestore(&qp->s_lock, flags);
780 } 792 }
@@ -799,7 +811,7 @@ int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread)
799 goto bail; 811 goto bail;
800 } 812 }
801 813
802 prescan_rxq(&packet); 814 prescan_rxq(rcd, &packet);
803 815
804 while (last == RCV_PKT_OK) { 816 while (last == RCV_PKT_OK) {
805 last = process_rcv_packet(&packet, thread); 817 last = process_rcv_packet(&packet, thread);
@@ -830,7 +842,7 @@ int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread)
830 } 842 }
831 smp_rmb(); /* prevent speculative reads of dma'ed hdrq */ 843 smp_rmb(); /* prevent speculative reads of dma'ed hdrq */
832 844
833 prescan_rxq(&packet); 845 prescan_rxq(rcd, &packet);
834 846
835 while (last == RCV_PKT_OK) { 847 while (last == RCV_PKT_OK) {
836 last = process_rcv_packet(&packet, thread); 848 last = process_rcv_packet(&packet, thread);
@@ -862,6 +874,37 @@ static inline void set_all_dma_rtail(struct hfi1_devdata *dd)
862 &handle_receive_interrupt_dma_rtail; 874 &handle_receive_interrupt_dma_rtail;
863} 875}
864 876
877void set_all_slowpath(struct hfi1_devdata *dd)
878{
879 int i;
880
881 /* HFI1_CTRL_CTXT must always use the slow path interrupt handler */
882 for (i = HFI1_CTRL_CTXT + 1; i < dd->first_user_ctxt; i++)
883 dd->rcd[i]->do_interrupt = &handle_receive_interrupt;
884}
885
886static inline int set_armed_to_active(struct hfi1_ctxtdata *rcd,
887 struct hfi1_packet packet,
888 struct hfi1_devdata *dd)
889{
890 struct work_struct *lsaw = &rcd->ppd->linkstate_active_work;
891 struct hfi1_message_header *hdr = hfi1_get_msgheader(packet.rcd->dd,
892 packet.rhf_addr);
893
894 if (hdr2sc(hdr, packet.rhf) != 0xf) {
895 int hwstate = read_logical_state(dd);
896
897 if (hwstate != LSTATE_ACTIVE) {
898 dd_dev_info(dd, "Unexpected link state %d\n", hwstate);
899 return 0;
900 }
901
902 queue_work(rcd->ppd->hfi1_wq, lsaw);
903 return 1;
904 }
905 return 0;
906}
907
865/* 908/*
866 * handle_receive_interrupt - receive a packet 909 * handle_receive_interrupt - receive a packet
867 * @rcd: the context 910 * @rcd: the context
@@ -910,17 +953,17 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
910 } 953 }
911 } 954 }
912 955
913 prescan_rxq(&packet); 956 prescan_rxq(rcd, &packet);
914 957
915 while (last == RCV_PKT_OK) { 958 while (last == RCV_PKT_OK) {
916 959 if (unlikely(dd->do_drop &&
917 if (unlikely(dd->do_drop && atomic_xchg(&dd->drop_packet, 960 atomic_xchg(&dd->drop_packet, DROP_PACKET_OFF) ==
918 DROP_PACKET_OFF) == DROP_PACKET_ON)) { 961 DROP_PACKET_ON)) {
919 dd->do_drop = 0; 962 dd->do_drop = 0;
920 963
921 /* On to the next packet */ 964 /* On to the next packet */
922 packet.rhqoff += packet.rsize; 965 packet.rhqoff += packet.rsize;
923 packet.rhf_addr = (__le32 *) rcd->rcvhdrq + 966 packet.rhf_addr = (__le32 *)rcd->rcvhdrq +
924 packet.rhqoff + 967 packet.rhqoff +
925 dd->rhf_offset; 968 dd->rhf_offset;
926 packet.rhf = rhf_to_cpu(packet.rhf_addr); 969 packet.rhf = rhf_to_cpu(packet.rhf_addr);
@@ -929,6 +972,11 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
929 last = skip_rcv_packet(&packet, thread); 972 last = skip_rcv_packet(&packet, thread);
930 skip_pkt = 0; 973 skip_pkt = 0;
931 } else { 974 } else {
975 /* Auto activate link on non-SC15 packet receive */
976 if (unlikely(rcd->ppd->host_link_state ==
977 HLS_UP_ARMED) &&
978 set_armed_to_active(rcd, packet, dd))
979 goto bail;
932 last = process_rcv_packet(&packet, thread); 980 last = process_rcv_packet(&packet, thread);
933 } 981 }
934 982
@@ -940,8 +988,7 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
940 if (seq != rcd->seq_cnt) 988 if (seq != rcd->seq_cnt)
941 last = RCV_PKT_DONE; 989 last = RCV_PKT_DONE;
942 if (needset) { 990 if (needset) {
943 dd_dev_info(dd, 991 dd_dev_info(dd, "Switching to NO_DMA_RTAIL\n");
944 "Switching to NO_DMA_RTAIL\n");
945 set_all_nodma_rtail(dd); 992 set_all_nodma_rtail(dd);
946 needset = 0; 993 needset = 0;
947 } 994 }
@@ -984,6 +1031,42 @@ bail:
984} 1031}
985 1032
986/* 1033/*
1034 * We may discover in the interrupt that the hardware link state has
1035 * changed from ARMED to ACTIVE (due to the arrival of a non-SC15 packet),
1036 * and we need to update the driver's notion of the link state. We cannot
1037 * run set_link_state from interrupt context, so we queue this function on
1038 * a workqueue.
1039 *
1040 * We delay the regular interrupt processing until after the state changes
1041 * so that the link will be in the correct state by the time any application
1042 * we wake up attempts to send a reply to any message it received.
1043 * (Subsequent receive interrupts may possibly force the wakeup before we
1044 * update the link state.)
1045 *
1046 * The rcd is freed in hfi1_free_ctxtdata after hfi1_postinit_cleanup invokes
1047 * dd->f_cleanup(dd) to disable the interrupt handler and flush workqueues,
1048 * so we're safe from use-after-free of the rcd.
1049 */
1050void receive_interrupt_work(struct work_struct *work)
1051{
1052 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
1053 linkstate_active_work);
1054 struct hfi1_devdata *dd = ppd->dd;
1055 int i;
1056
1057 /* Received non-SC15 packet implies neighbor_normal */
1058 ppd->neighbor_normal = 1;
1059 set_link_state(ppd, HLS_UP_ACTIVE);
1060
1061 /*
1062 * Interrupt all kernel contexts that could have had an
1063 * interrupt during auto activation.
1064 */
1065 for (i = HFI1_CTRL_CTXT; i < dd->first_user_ctxt; i++)
1066 force_recv_intr(dd->rcd[i]);
1067}
1068
1069/*
987 * Convert a given MTU size to the on-wire MAD packet enumeration. 1070 * Convert a given MTU size to the on-wire MAD packet enumeration.
988 * Return -1 if the size is invalid. 1071 * Return -1 if the size is invalid.
989 */ 1072 */
@@ -1037,9 +1120,9 @@ int set_mtu(struct hfi1_pportdata *ppd)
1037 ppd->ibmaxlen = ppd->ibmtu + lrh_max_header_bytes(ppd->dd); 1120 ppd->ibmaxlen = ppd->ibmtu + lrh_max_header_bytes(ppd->dd);
1038 1121
1039 mutex_lock(&ppd->hls_lock); 1122 mutex_lock(&ppd->hls_lock);
1040 if (ppd->host_link_state == HLS_UP_INIT 1123 if (ppd->host_link_state == HLS_UP_INIT ||
1041 || ppd->host_link_state == HLS_UP_ARMED 1124 ppd->host_link_state == HLS_UP_ARMED ||
1042 || ppd->host_link_state == HLS_UP_ACTIVE) 1125 ppd->host_link_state == HLS_UP_ACTIVE)
1043 is_up = 1; 1126 is_up = 1;
1044 1127
1045 drain = !is_ax(dd) && is_up; 1128 drain = !is_ax(dd) && is_up;
@@ -1082,79 +1165,80 @@ int hfi1_set_lid(struct hfi1_pportdata *ppd, u32 lid, u8 lmc)
1082 return 0; 1165 return 0;
1083} 1166}
1084 1167
1085/* 1168void shutdown_led_override(struct hfi1_pportdata *ppd)
1086 * Following deal with the "obviously simple" task of overriding the state 1169{
1087 * of the LEDs, which normally indicate link physical and logical status. 1170 struct hfi1_devdata *dd = ppd->dd;
1088 * The complications arise in dealing with different hardware mappings 1171
1089 * and the board-dependent routine being called from interrupts. 1172 /*
1090 * and then there's the requirement to _flash_ them. 1173 * This pairs with the memory barrier in hfi1_start_led_override to
1091 */ 1174 * ensure that we read the correct state of LED beaconing represented
1092#define LED_OVER_FREQ_SHIFT 8 1175 * by led_override_timer_active
1093#define LED_OVER_FREQ_MASK (0xFF<<LED_OVER_FREQ_SHIFT) 1176 */
1094/* Below is "non-zero" to force override, but both actual LEDs are off */ 1177 smp_rmb();
1095#define LED_OVER_BOTH_OFF (8) 1178 if (atomic_read(&ppd->led_override_timer_active)) {
1179 del_timer_sync(&ppd->led_override_timer);
1180 atomic_set(&ppd->led_override_timer_active, 0);
1181 /* Ensure the atomic_set is visible to all CPUs */
1182 smp_wmb();
1183 }
1184
1185 /* Hand control of the LED to the DC for normal operation */
1186 write_csr(dd, DCC_CFG_LED_CNTRL, 0);
1187}
1096 1188
1097static void run_led_override(unsigned long opaque) 1189static void run_led_override(unsigned long opaque)
1098{ 1190{
1099 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)opaque; 1191 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)opaque;
1100 struct hfi1_devdata *dd = ppd->dd; 1192 struct hfi1_devdata *dd = ppd->dd;
1101 int timeoff; 1193 unsigned long timeout;
1102 int ph_idx; 1194 int phase_idx;
1103 1195
1104 if (!(dd->flags & HFI1_INITTED)) 1196 if (!(dd->flags & HFI1_INITTED))
1105 return; 1197 return;
1106 1198
1107 ph_idx = ppd->led_override_phase++ & 1; 1199 phase_idx = ppd->led_override_phase & 1;
1108 ppd->led_override = ppd->led_override_vals[ph_idx];
1109 timeoff = ppd->led_override_timeoff;
1110 1200
1111 /* 1201 setextled(dd, phase_idx);
1112 * don't re-fire the timer if user asked for it to be off; we let 1202
1113 * it fire one more time after they turn it off to simplify 1203 timeout = ppd->led_override_vals[phase_idx];
1114 */ 1204
1115 if (ppd->led_override_vals[0] || ppd->led_override_vals[1]) 1205 /* Set up for next phase */
1116 mod_timer(&ppd->led_override_timer, jiffies + timeoff); 1206 ppd->led_override_phase = !ppd->led_override_phase;
1207
1208 mod_timer(&ppd->led_override_timer, jiffies + timeout);
1117} 1209}
1118 1210
1119void hfi1_set_led_override(struct hfi1_pportdata *ppd, unsigned int val) 1211/*
1212 * To have the LED blink in a particular pattern, provide timeon and timeoff
1213 * in milliseconds.
1214 * To turn off custom blinking and return to normal operation, use
1215 * shutdown_led_override()
1216 */
1217void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon,
1218 unsigned int timeoff)
1120{ 1219{
1121 struct hfi1_devdata *dd = ppd->dd; 1220 if (!(ppd->dd->flags & HFI1_INITTED))
1122 int timeoff, freq;
1123
1124 if (!(dd->flags & HFI1_INITTED))
1125 return; 1221 return;
1126 1222
1127 /* First check if we are blinking. If not, use 1HZ polling */ 1223 /* Convert to jiffies for direct use in timer */
1128 timeoff = HZ; 1224 ppd->led_override_vals[0] = msecs_to_jiffies(timeoff);
1129 freq = (val & LED_OVER_FREQ_MASK) >> LED_OVER_FREQ_SHIFT; 1225 ppd->led_override_vals[1] = msecs_to_jiffies(timeon);
1130 1226
1131 if (freq) { 1227 /* Arbitrarily start from LED on phase */
1132 /* For blink, set each phase from one nybble of val */ 1228 ppd->led_override_phase = 1;
1133 ppd->led_override_vals[0] = val & 0xF;
1134 ppd->led_override_vals[1] = (val >> 4) & 0xF;
1135 timeoff = (HZ << 4)/freq;
1136 } else {
1137 /* Non-blink set both phases the same. */
1138 ppd->led_override_vals[0] = val & 0xF;
1139 ppd->led_override_vals[1] = val & 0xF;
1140 }
1141 ppd->led_override_timeoff = timeoff;
1142 1229
1143 /* 1230 /*
1144 * If the timer has not already been started, do so. Use a "quick" 1231 * If the timer has not already been started, do so. Use a "quick"
1145 * timeout so the function will be called soon, to look at our request. 1232 * timeout so the handler will be called soon to look at our request.
1146 */ 1233 */
1147 if (atomic_inc_return(&ppd->led_override_timer_active) == 1) { 1234 if (!timer_pending(&ppd->led_override_timer)) {
1148 /* Need to start timer */
1149 setup_timer(&ppd->led_override_timer, run_led_override, 1235 setup_timer(&ppd->led_override_timer, run_led_override,
1150 (unsigned long)ppd); 1236 (unsigned long)ppd);
1151
1152 ppd->led_override_timer.expires = jiffies + 1; 1237 ppd->led_override_timer.expires = jiffies + 1;
1153 add_timer(&ppd->led_override_timer); 1238 add_timer(&ppd->led_override_timer);
1154 } else { 1239 atomic_set(&ppd->led_override_timer_active, 1);
1155 if (ppd->led_override_vals[0] || ppd->led_override_vals[1]) 1240 /* Ensure the atomic_set is visible to all CPUs */
1156 mod_timer(&ppd->led_override_timer, jiffies + 1); 1241 smp_wmb();
1157 atomic_dec(&ppd->led_override_timer_active);
1158 } 1242 }
1159} 1243}
1160 1244
@@ -1184,8 +1268,8 @@ int hfi1_reset_device(int unit)
1184 1268
1185 if (!dd->kregbase || !(dd->flags & HFI1_PRESENT)) { 1269 if (!dd->kregbase || !(dd->flags & HFI1_PRESENT)) {
1186 dd_dev_info(dd, 1270 dd_dev_info(dd,
1187 "Invalid unit number %u or not initialized or not present\n", 1271 "Invalid unit number %u or not initialized or not present\n",
1188 unit); 1272 unit);
1189 ret = -ENXIO; 1273 ret = -ENXIO;
1190 goto bail; 1274 goto bail;
1191 } 1275 }
@@ -1203,14 +1287,8 @@ int hfi1_reset_device(int unit)
1203 1287
1204 for (pidx = 0; pidx < dd->num_pports; ++pidx) { 1288 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
1205 ppd = dd->pport + pidx; 1289 ppd = dd->pport + pidx;
1206 if (atomic_read(&ppd->led_override_timer_active)) {
1207 /* Need to stop LED timer, _then_ shut off LEDs */
1208 del_timer_sync(&ppd->led_override_timer);
1209 atomic_set(&ppd->led_override_timer_active, 0);
1210 }
1211 1290
1212 /* Shut off LEDs after we are sure timer is not running */ 1291 shutdown_led_override(ppd);
1213 ppd->led_override = LED_OVER_BOTH_OFF;
1214 } 1292 }
1215 if (dd->flags & HFI1_HAS_SEND_DMA) 1293 if (dd->flags & HFI1_HAS_SEND_DMA)
1216 sdma_exit(dd); 1294 sdma_exit(dd);
@@ -1221,11 +1299,11 @@ int hfi1_reset_device(int unit)
1221 1299
1222 if (ret) 1300 if (ret)
1223 dd_dev_err(dd, 1301 dd_dev_err(dd,
1224 "Reinitialize unit %u after reset failed with %d\n", 1302 "Reinitialize unit %u after reset failed with %d\n",
1225 unit, ret); 1303 unit, ret);
1226 else 1304 else
1227 dd_dev_info(dd, "Reinitialized unit %u after resetting\n", 1305 dd_dev_info(dd, "Reinitialized unit %u after resetting\n",
1228 unit); 1306 unit);
1229 1307
1230bail: 1308bail:
1231 return ret; 1309 return ret;
@@ -1282,7 +1360,7 @@ int process_receive_bypass(struct hfi1_packet *packet)
1282 handle_eflags(packet); 1360 handle_eflags(packet);
1283 1361
1284 dd_dev_err(packet->rcd->dd, 1362 dd_dev_err(packet->rcd->dd,
1285 "Bypass packets are not supported in normal operation. Dropping\n"); 1363 "Bypass packets are not supported in normal operation. Dropping\n");
1286 return RHF_RCV_CONTINUE; 1364 return RHF_RCV_CONTINUE;
1287} 1365}
1288 1366
@@ -1320,6 +1398,6 @@ int kdeth_process_eager(struct hfi1_packet *packet)
1320int process_receive_invalid(struct hfi1_packet *packet) 1398int process_receive_invalid(struct hfi1_packet *packet)
1321{ 1399{
1322 dd_dev_err(packet->rcd->dd, "Invalid packet type %d. Dropping\n", 1400 dd_dev_err(packet->rcd->dd, "Invalid packet type %d. Dropping\n",
1323 rhf_rcv_type(packet->rhf)); 1401 rhf_rcv_type(packet->rhf));
1324 return RHF_RCV_CONTINUE; 1402 return RHF_RCV_CONTINUE;
1325} 1403}
diff --git a/drivers/staging/rdma/hfi1/efivar.c b/drivers/staging/rdma/hfi1/efivar.c
index 47dfe2584760..106349fc1fb9 100644
--- a/drivers/staging/rdma/hfi1/efivar.c
+++ b/drivers/staging/rdma/hfi1/efivar.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
diff --git a/drivers/staging/rdma/hfi1/efivar.h b/drivers/staging/rdma/hfi1/efivar.h
index 070706225c51..94e9e70de568 100644
--- a/drivers/staging/rdma/hfi1/efivar.h
+++ b/drivers/staging/rdma/hfi1/efivar.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
diff --git a/drivers/staging/rdma/hfi1/eprom.c b/drivers/staging/rdma/hfi1/eprom.c
index fb620c97f592..bd8771570f81 100644
--- a/drivers/staging/rdma/hfi1/eprom.c
+++ b/drivers/staging/rdma/hfi1/eprom.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -99,17 +96,17 @@
99 96
100/* sleep length while waiting for controller */ 97/* sleep length while waiting for controller */
101#define WAIT_SLEEP_US 100 /* must be larger than 5 (see usage) */ 98#define WAIT_SLEEP_US 100 /* must be larger than 5 (see usage) */
102#define COUNT_DELAY_SEC(n) ((n) * (1000000/WAIT_SLEEP_US)) 99#define COUNT_DELAY_SEC(n) ((n) * (1000000 / WAIT_SLEEP_US))
103 100
104/* GPIO pins */ 101/* GPIO pins */
105#define EPROM_WP_N (1ull << 14) /* EPROM write line */ 102#define EPROM_WP_N BIT_ULL(14) /* EPROM write line */
106 103
107/* 104/*
108 * Use the EP mutex to guard against other callers from within the driver. 105 * How long to wait for the EPROM to become available, in ms.
109 * Also covers usage of eprom_available. 106 * The spec 32 Mb EPROM takes around 40s to erase then write.
107 * Double it for safety.
110 */ 108 */
111static DEFINE_MUTEX(eprom_mutex); 109#define EPROM_TIMEOUT 80000 /* ms */
112static int eprom_available; /* default: not available */
113 110
114/* 111/*
115 * Turn on external enable line that allows writing on the flash. 112 * Turn on external enable line that allows writing on the flash.
@@ -117,11 +114,9 @@ static int eprom_available; /* default: not available */
117static void write_enable(struct hfi1_devdata *dd) 114static void write_enable(struct hfi1_devdata *dd)
118{ 115{
119 /* raise signal */ 116 /* raise signal */
120 write_csr(dd, ASIC_GPIO_OUT, 117 write_csr(dd, ASIC_GPIO_OUT, read_csr(dd, ASIC_GPIO_OUT) | EPROM_WP_N);
121 read_csr(dd, ASIC_GPIO_OUT) | EPROM_WP_N);
122 /* raise enable */ 118 /* raise enable */
123 write_csr(dd, ASIC_GPIO_OE, 119 write_csr(dd, ASIC_GPIO_OE, read_csr(dd, ASIC_GPIO_OE) | EPROM_WP_N);
124 read_csr(dd, ASIC_GPIO_OE) | EPROM_WP_N);
125} 120}
126 121
127/* 122/*
@@ -130,11 +125,9 @@ static void write_enable(struct hfi1_devdata *dd)
130static void write_disable(struct hfi1_devdata *dd) 125static void write_disable(struct hfi1_devdata *dd)
131{ 126{
132 /* lower signal */ 127 /* lower signal */
133 write_csr(dd, ASIC_GPIO_OUT, 128 write_csr(dd, ASIC_GPIO_OUT, read_csr(dd, ASIC_GPIO_OUT) & ~EPROM_WP_N);
134 read_csr(dd, ASIC_GPIO_OUT) & ~EPROM_WP_N);
135 /* lower enable */ 129 /* lower enable */
136 write_csr(dd, ASIC_GPIO_OE, 130 write_csr(dd, ASIC_GPIO_OE, read_csr(dd, ASIC_GPIO_OE) & ~EPROM_WP_N);
137 read_csr(dd, ASIC_GPIO_OE) & ~EPROM_WP_N);
138} 131}
139 132
140/* 133/*
@@ -212,8 +205,8 @@ static int erase_range(struct hfi1_devdata *dd, u32 start, u32 len)
212 /* check the end points for the minimum erase */ 205 /* check the end points for the minimum erase */
213 if ((start & MASK_4KB) || (end & MASK_4KB)) { 206 if ((start & MASK_4KB) || (end & MASK_4KB)) {
214 dd_dev_err(dd, 207 dd_dev_err(dd,
215 "%s: non-aligned range (0x%x,0x%x) for a 4KB erase\n", 208 "%s: non-aligned range (0x%x,0x%x) for a 4KB erase\n",
216 __func__, start, end); 209 __func__, start, end);
217 return -EINVAL; 210 return -EINVAL;
218 } 211 }
219 212
@@ -256,7 +249,7 @@ static void read_page(struct hfi1_devdata *dd, u32 offset, u32 *result)
256 int i; 249 int i;
257 250
258 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_READ_DATA(offset)); 251 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_READ_DATA(offset));
259 for (i = 0; i < EP_PAGE_SIZE/sizeof(u32); i++) 252 for (i = 0; i < EP_PAGE_SIZE / sizeof(u32); i++)
260 result[i] = (u32)read_csr(dd, ASIC_EEP_DATA); 253 result[i] = (u32)read_csr(dd, ASIC_EEP_DATA);
261 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_NOP); /* close open page */ 254 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_NOP); /* close open page */
262} 255}
@@ -267,7 +260,7 @@ static void read_page(struct hfi1_devdata *dd, u32 offset, u32 *result)
267static int read_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr) 260static int read_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr)
268{ 261{
269 u32 offset; 262 u32 offset;
270 u32 buffer[EP_PAGE_SIZE/sizeof(u32)]; 263 u32 buffer[EP_PAGE_SIZE / sizeof(u32)];
271 int ret = 0; 264 int ret = 0;
272 265
273 /* reject anything not on an EPROM page boundary */ 266 /* reject anything not on an EPROM page boundary */
@@ -277,7 +270,7 @@ static int read_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr)
277 for (offset = 0; offset < len; offset += EP_PAGE_SIZE) { 270 for (offset = 0; offset < len; offset += EP_PAGE_SIZE) {
278 read_page(dd, start + offset, buffer); 271 read_page(dd, start + offset, buffer);
279 if (copy_to_user((void __user *)(addr + offset), 272 if (copy_to_user((void __user *)(addr + offset),
280 buffer, EP_PAGE_SIZE)) { 273 buffer, EP_PAGE_SIZE)) {
281 ret = -EFAULT; 274 ret = -EFAULT;
282 goto done; 275 goto done;
283 } 276 }
@@ -298,7 +291,7 @@ static int write_page(struct hfi1_devdata *dd, u32 offset, u32 *data)
298 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_WRITE_ENABLE); 291 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_WRITE_ENABLE);
299 write_csr(dd, ASIC_EEP_DATA, data[0]); 292 write_csr(dd, ASIC_EEP_DATA, data[0]);
300 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_PAGE_PROGRAM(offset)); 293 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_PAGE_PROGRAM(offset));
301 for (i = 1; i < EP_PAGE_SIZE/sizeof(u32); i++) 294 for (i = 1; i < EP_PAGE_SIZE / sizeof(u32); i++)
302 write_csr(dd, ASIC_EEP_DATA, data[i]); 295 write_csr(dd, ASIC_EEP_DATA, data[i]);
303 /* will close the open page */ 296 /* will close the open page */
304 return wait_for_not_busy(dd); 297 return wait_for_not_busy(dd);
@@ -310,7 +303,7 @@ static int write_page(struct hfi1_devdata *dd, u32 offset, u32 *data)
310static int write_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr) 303static int write_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr)
311{ 304{
312 u32 offset; 305 u32 offset;
313 u32 buffer[EP_PAGE_SIZE/sizeof(u32)]; 306 u32 buffer[EP_PAGE_SIZE / sizeof(u32)];
314 int ret = 0; 307 int ret = 0;
315 308
316 /* reject anything not on an EPROM page boundary */ 309 /* reject anything not on an EPROM page boundary */
@@ -321,7 +314,7 @@ static int write_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr)
321 314
322 for (offset = 0; offset < len; offset += EP_PAGE_SIZE) { 315 for (offset = 0; offset < len; offset += EP_PAGE_SIZE) {
323 if (copy_from_user(buffer, (void __user *)(addr + offset), 316 if (copy_from_user(buffer, (void __user *)(addr + offset),
324 EP_PAGE_SIZE)) { 317 EP_PAGE_SIZE)) {
325 ret = -EFAULT; 318 ret = -EFAULT;
326 goto done; 319 goto done;
327 } 320 }
@@ -353,44 +346,42 @@ static inline u32 extract_rstart(u32 composite)
353 * 346 *
354 * Return 0 on success, -ERRNO on error 347 * Return 0 on success, -ERRNO on error
355 */ 348 */
356int handle_eprom_command(const struct hfi1_cmd *cmd) 349int handle_eprom_command(struct file *fp, const struct hfi1_cmd *cmd)
357{ 350{
358 struct hfi1_devdata *dd; 351 struct hfi1_devdata *dd;
359 u32 dev_id; 352 u32 dev_id;
360 u32 rlen; /* range length */ 353 u32 rlen; /* range length */
361 u32 rstart; /* range start */ 354 u32 rstart; /* range start */
355 int i_minor;
362 int ret = 0; 356 int ret = 0;
363 357
364 /* 358 /*
365 * The EPROM is per-device, so use unit 0 as that will always 359 * Map the device file to device data using the relative minor.
366 * exist. 360 * The device file minor number is the unit number + 1. 0 is
361 * the generic device file - reject it.
367 */ 362 */
368 dd = hfi1_lookup(0); 363 i_minor = iminor(file_inode(fp)) - HFI1_USER_MINOR_BASE;
364 if (i_minor <= 0)
365 return -EINVAL;
366 dd = hfi1_lookup(i_minor - 1);
369 if (!dd) { 367 if (!dd) {
370 pr_err("%s: cannot find unit 0!\n", __func__); 368 pr_err("%s: cannot find unit %d!\n", __func__, i_minor);
371 return -EINVAL; 369 return -EINVAL;
372 } 370 }
373 371
374 /* lock against other callers touching the ASIC block */ 372 /* some devices do not have an EPROM */
375 mutex_lock(&eprom_mutex); 373 if (!dd->eprom_available)
376 374 return -EOPNOTSUPP;
377 /* some platforms do not have an EPROM */
378 if (!eprom_available) {
379 ret = -ENOSYS;
380 goto done_asic;
381 }
382 375
383 /* lock against the other HFI on another OS */ 376 ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT);
384 ret = acquire_hw_mutex(dd);
385 if (ret) { 377 if (ret) {
386 dd_dev_err(dd, 378 dd_dev_err(dd, "%s: unable to acquire EPROM resource\n",
387 "%s: unable to acquire hw mutex, no EPROM support\n", 379 __func__);
388 __func__);
389 goto done_asic; 380 goto done_asic;
390 } 381 }
391 382
392 dd_dev_info(dd, "%s: cmd: type %d, len 0x%x, addr 0x%016llx\n", 383 dd_dev_info(dd, "%s: cmd: type %d, len 0x%x, addr 0x%016llx\n",
393 __func__, cmd->type, cmd->len, cmd->addr); 384 __func__, cmd->type, cmd->len, cmd->addr);
394 385
395 switch (cmd->type) { 386 switch (cmd->type) {
396 case HFI1_CMD_EP_INFO: 387 case HFI1_CMD_EP_INFO:
@@ -401,7 +392,7 @@ int handle_eprom_command(const struct hfi1_cmd *cmd)
401 dev_id = read_device_id(dd); 392 dev_id = read_device_id(dd);
402 /* addr points to a u32 user buffer */ 393 /* addr points to a u32 user buffer */
403 if (copy_to_user((void __user *)cmd->addr, &dev_id, 394 if (copy_to_user((void __user *)cmd->addr, &dev_id,
404 sizeof(u32))) 395 sizeof(u32)))
405 ret = -EFAULT; 396 ret = -EFAULT;
406 break; 397 break;
407 398
@@ -429,14 +420,13 @@ int handle_eprom_command(const struct hfi1_cmd *cmd)
429 420
430 default: 421 default:
431 dd_dev_err(dd, "%s: unexpected command %d\n", 422 dd_dev_err(dd, "%s: unexpected command %d\n",
432 __func__, cmd->type); 423 __func__, cmd->type);
433 ret = -EINVAL; 424 ret = -EINVAL;
434 break; 425 break;
435 } 426 }
436 427
437 release_hw_mutex(dd); 428 release_chip_resource(dd, CR_EPROM);
438done_asic: 429done_asic:
439 mutex_unlock(&eprom_mutex);
440 return ret; 430 return ret;
441} 431}
442 432
@@ -447,44 +437,35 @@ int eprom_init(struct hfi1_devdata *dd)
447{ 437{
448 int ret = 0; 438 int ret = 0;
449 439
450 /* only the discrete chip has an EPROM, nothing to do */ 440 /* only the discrete chip has an EPROM */
451 if (dd->pcidev->device != PCI_DEVICE_ID_INTEL0) 441 if (dd->pcidev->device != PCI_DEVICE_ID_INTEL0)
452 return 0; 442 return 0;
453 443
454 /* lock against other callers */
455 mutex_lock(&eprom_mutex);
456 if (eprom_available) /* already initialized */
457 goto done_asic;
458
459 /* 444 /*
460 * Lock against the other HFI on another OS - the mutex above 445 * It is OK if both HFIs reset the EPROM as long as they don't
461 * would have caught anything in this driver. It is OK if 446 * do it at the same time.
462 * both OSes reset the EPROM - as long as they don't do it at
463 * the same time.
464 */ 447 */
465 ret = acquire_hw_mutex(dd); 448 ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT);
466 if (ret) { 449 if (ret) {
467 dd_dev_err(dd, 450 dd_dev_err(dd,
468 "%s: unable to acquire hw mutex, no EPROM support\n", 451 "%s: unable to acquire EPROM resource, no EPROM support\n",
469 __func__); 452 __func__);
470 goto done_asic; 453 goto done_asic;
471 } 454 }
472 455
473 /* reset EPROM to be sure it is in a good state */ 456 /* reset EPROM to be sure it is in a good state */
474 457
475 /* set reset */ 458 /* set reset */
476 write_csr(dd, ASIC_EEP_CTL_STAT, 459 write_csr(dd, ASIC_EEP_CTL_STAT, ASIC_EEP_CTL_STAT_EP_RESET_SMASK);
477 ASIC_EEP_CTL_STAT_EP_RESET_SMASK);
478 /* clear reset, set speed */ 460 /* clear reset, set speed */
479 write_csr(dd, ASIC_EEP_CTL_STAT, 461 write_csr(dd, ASIC_EEP_CTL_STAT,
480 EP_SPEED_FULL << ASIC_EEP_CTL_STAT_RATE_SPI_SHIFT); 462 EP_SPEED_FULL << ASIC_EEP_CTL_STAT_RATE_SPI_SHIFT);
481 463
482 /* wake the device with command "release powerdown NoID" */ 464 /* wake the device with command "release powerdown NoID" */
483 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_RELEASE_POWERDOWN_NOID); 465 write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_RELEASE_POWERDOWN_NOID);
484 466
485 eprom_available = 1; 467 dd->eprom_available = true;
486 release_hw_mutex(dd); 468 release_chip_resource(dd, CR_EPROM);
487done_asic: 469done_asic:
488 mutex_unlock(&eprom_mutex);
489 return ret; 470 return ret;
490} 471}
diff --git a/drivers/staging/rdma/hfi1/eprom.h b/drivers/staging/rdma/hfi1/eprom.h
index 64a64276be81..d41f0b1afb15 100644
--- a/drivers/staging/rdma/hfi1/eprom.h
+++ b/drivers/staging/rdma/hfi1/eprom.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -52,4 +49,4 @@ struct hfi1_cmd;
52struct hfi1_devdata; 49struct hfi1_devdata;
53 50
54int eprom_init(struct hfi1_devdata *dd); 51int eprom_init(struct hfi1_devdata *dd);
55int handle_eprom_command(const struct hfi1_cmd *cmd); 52int handle_eprom_command(struct file *fp, const struct hfi1_cmd *cmd);
diff --git a/drivers/staging/rdma/hfi1/file_ops.c b/drivers/staging/rdma/hfi1/file_ops.c
index 8b911e8bf0df..8396dc5fb6c1 100644
--- a/drivers/staging/rdma/hfi1/file_ops.c
+++ b/drivers/staging/rdma/hfi1/file_ops.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -60,6 +57,8 @@
60#include "user_sdma.h" 57#include "user_sdma.h"
61#include "user_exp_rcv.h" 58#include "user_exp_rcv.h"
62#include "eprom.h" 59#include "eprom.h"
60#include "aspm.h"
61#include "mmu_rb.h"
63 62
64#undef pr_fmt 63#undef pr_fmt
65#define pr_fmt(fmt) DRIVER_NAME ": " fmt 64#define pr_fmt(fmt) DRIVER_NAME ": " fmt
@@ -96,9 +95,6 @@ static int user_event_ack(struct hfi1_ctxtdata *, int, unsigned long);
96static int set_ctxt_pkey(struct hfi1_ctxtdata *, unsigned, u16); 95static int set_ctxt_pkey(struct hfi1_ctxtdata *, unsigned, u16);
97static int manage_rcvq(struct hfi1_ctxtdata *, unsigned, int); 96static int manage_rcvq(struct hfi1_ctxtdata *, unsigned, int);
98static int vma_fault(struct vm_area_struct *, struct vm_fault *); 97static int vma_fault(struct vm_area_struct *, struct vm_fault *);
99static int exp_tid_setup(struct file *, struct hfi1_tid_info *);
100static int exp_tid_free(struct file *, struct hfi1_tid_info *);
101static void unlock_exp_tids(struct hfi1_ctxtdata *);
102 98
103static const struct file_operations hfi1_file_ops = { 99static const struct file_operations hfi1_file_ops = {
104 .owner = THIS_MODULE, 100 .owner = THIS_MODULE,
@@ -164,7 +160,6 @@ enum mmap_types {
164#define dbg(fmt, ...) \ 160#define dbg(fmt, ...) \
165 pr_info(fmt, ##__VA_ARGS__) 161 pr_info(fmt, ##__VA_ARGS__)
166 162
167
168static inline int is_valid_mmap(u64 token) 163static inline int is_valid_mmap(u64 token)
169{ 164{
170 return (HFI1_MMAP_TOKEN_GET(MAGIC, token) == HFI1_MMAP_MAGIC); 165 return (HFI1_MMAP_TOKEN_GET(MAGIC, token) == HFI1_MMAP_MAGIC);
@@ -188,6 +183,7 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
188 struct hfi1_cmd cmd; 183 struct hfi1_cmd cmd;
189 struct hfi1_user_info uinfo; 184 struct hfi1_user_info uinfo;
190 struct hfi1_tid_info tinfo; 185 struct hfi1_tid_info tinfo;
186 unsigned long addr;
191 ssize_t consumed = 0, copy = 0, ret = 0; 187 ssize_t consumed = 0, copy = 0, ret = 0;
192 void *dest = NULL; 188 void *dest = NULL;
193 __u64 user_val = 0; 189 __u64 user_val = 0;
@@ -219,6 +215,7 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
219 break; 215 break;
220 case HFI1_CMD_TID_UPDATE: 216 case HFI1_CMD_TID_UPDATE:
221 case HFI1_CMD_TID_FREE: 217 case HFI1_CMD_TID_FREE:
218 case HFI1_CMD_TID_INVAL_READ:
222 copy = sizeof(tinfo); 219 copy = sizeof(tinfo);
223 dest = &tinfo; 220 dest = &tinfo;
224 break; 221 break;
@@ -294,9 +291,8 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
294 sc_return_credits(uctxt->sc); 291 sc_return_credits(uctxt->sc);
295 break; 292 break;
296 case HFI1_CMD_TID_UPDATE: 293 case HFI1_CMD_TID_UPDATE:
297 ret = exp_tid_setup(fp, &tinfo); 294 ret = hfi1_user_exp_rcv_setup(fp, &tinfo);
298 if (!ret) { 295 if (!ret) {
299 unsigned long addr;
300 /* 296 /*
301 * Copy the number of tidlist entries we used 297 * Copy the number of tidlist entries we used
302 * and the length of the buffer we registered. 298 * and the length of the buffer we registered.
@@ -311,8 +307,25 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
311 ret = -EFAULT; 307 ret = -EFAULT;
312 } 308 }
313 break; 309 break;
310 case HFI1_CMD_TID_INVAL_READ:
311 ret = hfi1_user_exp_rcv_invalid(fp, &tinfo);
312 if (ret)
313 break;
314 addr = (unsigned long)cmd.addr +
315 offsetof(struct hfi1_tid_info, tidcnt);
316 if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
317 sizeof(tinfo.tidcnt)))
318 ret = -EFAULT;
319 break;
314 case HFI1_CMD_TID_FREE: 320 case HFI1_CMD_TID_FREE:
315 ret = exp_tid_free(fp, &tinfo); 321 ret = hfi1_user_exp_rcv_clear(fp, &tinfo);
322 if (ret)
323 break;
324 addr = (unsigned long)cmd.addr +
325 offsetof(struct hfi1_tid_info, tidcnt);
326 if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
327 sizeof(tinfo.tidcnt)))
328 ret = -EFAULT;
316 break; 329 break;
317 case HFI1_CMD_RECV_CTRL: 330 case HFI1_CMD_RECV_CTRL:
318 ret = manage_rcvq(uctxt, fd->subctxt, (int)user_val); 331 ret = manage_rcvq(uctxt, fd->subctxt, (int)user_val);
@@ -373,8 +386,10 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
373 break; 386 break;
374 } 387 }
375 if (dd->flags & HFI1_FORCED_FREEZE) { 388 if (dd->flags & HFI1_FORCED_FREEZE) {
376 /* Don't allow context reset if we are into 389 /*
377 * forced freeze */ 390 * Don't allow context reset if we are into
391 * forced freeze
392 */
378 ret = -ENODEV; 393 ret = -ENODEV;
379 break; 394 break;
380 } 395 }
@@ -382,8 +397,9 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
382 ret = sc_enable(sc); 397 ret = sc_enable(sc);
383 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_ENB, 398 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_ENB,
384 uctxt->ctxt); 399 uctxt->ctxt);
385 } else 400 } else {
386 ret = sc_restart(sc); 401 ret = sc_restart(sc);
402 }
387 if (!ret) 403 if (!ret)
388 sc_return_credits(sc); 404 sc_return_credits(sc);
389 break; 405 break;
@@ -393,7 +409,7 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
393 case HFI1_CMD_EP_ERASE_RANGE: 409 case HFI1_CMD_EP_ERASE_RANGE:
394 case HFI1_CMD_EP_READ_RANGE: 410 case HFI1_CMD_EP_READ_RANGE:
395 case HFI1_CMD_EP_WRITE_RANGE: 411 case HFI1_CMD_EP_WRITE_RANGE:
396 ret = handle_eprom_command(&cmd); 412 ret = handle_eprom_command(fp, &cmd);
397 break; 413 break;
398 } 414 }
399 415
@@ -732,6 +748,9 @@ static int hfi1_file_close(struct inode *inode, struct file *fp)
732 /* drain user sdma queue */ 748 /* drain user sdma queue */
733 hfi1_user_sdma_free_queues(fdata); 749 hfi1_user_sdma_free_queues(fdata);
734 750
751 /* release the cpu */
752 hfi1_put_proc_affinity(dd, fdata->rec_cpu_num);
753
735 /* 754 /*
736 * Clear any left over, unhandled events so the next process that 755 * Clear any left over, unhandled events so the next process that
737 * gets this context doesn't get confused. 756 * gets this context doesn't get confused.
@@ -755,6 +774,7 @@ static int hfi1_file_close(struct inode *inode, struct file *fp)
755 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS | 774 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS |
756 HFI1_RCVCTRL_TIDFLOW_DIS | 775 HFI1_RCVCTRL_TIDFLOW_DIS |
757 HFI1_RCVCTRL_INTRAVAIL_DIS | 776 HFI1_RCVCTRL_INTRAVAIL_DIS |
777 HFI1_RCVCTRL_TAILUPD_DIS |
758 HFI1_RCVCTRL_ONE_PKT_EGR_DIS | 778 HFI1_RCVCTRL_ONE_PKT_EGR_DIS |
759 HFI1_RCVCTRL_NO_RHQ_DROP_DIS | 779 HFI1_RCVCTRL_NO_RHQ_DROP_DIS |
760 HFI1_RCVCTRL_NO_EGR_DROP_DIS, uctxt->ctxt); 780 HFI1_RCVCTRL_NO_EGR_DROP_DIS, uctxt->ctxt);
@@ -777,14 +797,12 @@ static int hfi1_file_close(struct inode *inode, struct file *fp)
777 uctxt->pionowait = 0; 797 uctxt->pionowait = 0;
778 uctxt->event_flags = 0; 798 uctxt->event_flags = 0;
779 799
780 hfi1_clear_tids(uctxt); 800 hfi1_user_exp_rcv_free(fdata);
781 hfi1_clear_ctxt_pkey(dd, uctxt->ctxt); 801 hfi1_clear_ctxt_pkey(dd, uctxt->ctxt);
782 802
783 if (uctxt->tid_pg_list)
784 unlock_exp_tids(uctxt);
785
786 hfi1_stats.sps_ctxts--; 803 hfi1_stats.sps_ctxts--;
787 dd->freectxts++; 804 if (++dd->freectxts == dd->num_user_contexts)
805 aspm_enable_all(dd);
788 mutex_unlock(&hfi1_mutex); 806 mutex_unlock(&hfi1_mutex);
789 hfi1_free_ctxtdata(dd, uctxt); 807 hfi1_free_ctxtdata(dd, uctxt);
790done: 808done:
@@ -826,8 +844,16 @@ static int assign_ctxt(struct file *fp, struct hfi1_user_info *uinfo)
826 844
827 mutex_lock(&hfi1_mutex); 845 mutex_lock(&hfi1_mutex);
828 /* First, lets check if we need to setup a shared context? */ 846 /* First, lets check if we need to setup a shared context? */
829 if (uinfo->subctxt_cnt) 847 if (uinfo->subctxt_cnt) {
848 struct hfi1_filedata *fd = fp->private_data;
849
830 ret = find_shared_ctxt(fp, uinfo); 850 ret = find_shared_ctxt(fp, uinfo);
851 if (ret < 0)
852 goto done_unlock;
853 if (ret)
854 fd->rec_cpu_num = hfi1_get_proc_affinity(
855 fd->uctxt->dd, fd->uctxt->numa_id);
856 }
831 857
832 /* 858 /*
833 * We execute the following block if we couldn't find a 859 * We execute the following block if we couldn't find a
@@ -837,6 +863,7 @@ static int assign_ctxt(struct file *fp, struct hfi1_user_info *uinfo)
837 i_minor = iminor(file_inode(fp)) - HFI1_USER_MINOR_BASE; 863 i_minor = iminor(file_inode(fp)) - HFI1_USER_MINOR_BASE;
838 ret = get_user_context(fp, uinfo, i_minor - 1, alg); 864 ret = get_user_context(fp, uinfo, i_minor - 1, alg);
839 } 865 }
866done_unlock:
840 mutex_unlock(&hfi1_mutex); 867 mutex_unlock(&hfi1_mutex);
841done: 868done:
842 return ret; 869 return ret;
@@ -962,7 +989,7 @@ static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd,
962 struct hfi1_filedata *fd = fp->private_data; 989 struct hfi1_filedata *fd = fp->private_data;
963 struct hfi1_ctxtdata *uctxt; 990 struct hfi1_ctxtdata *uctxt;
964 unsigned ctxt; 991 unsigned ctxt;
965 int ret; 992 int ret, numa;
966 993
967 if (dd->flags & HFI1_FROZEN) { 994 if (dd->flags & HFI1_FROZEN) {
968 /* 995 /*
@@ -982,17 +1009,26 @@ static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd,
982 if (ctxt == dd->num_rcv_contexts) 1009 if (ctxt == dd->num_rcv_contexts)
983 return -EBUSY; 1010 return -EBUSY;
984 1011
985 uctxt = hfi1_create_ctxtdata(dd->pport, ctxt); 1012 fd->rec_cpu_num = hfi1_get_proc_affinity(dd, -1);
1013 if (fd->rec_cpu_num != -1)
1014 numa = cpu_to_node(fd->rec_cpu_num);
1015 else
1016 numa = numa_node_id();
1017 uctxt = hfi1_create_ctxtdata(dd->pport, ctxt, numa);
986 if (!uctxt) { 1018 if (!uctxt) {
987 dd_dev_err(dd, 1019 dd_dev_err(dd,
988 "Unable to allocate ctxtdata memory, failing open\n"); 1020 "Unable to allocate ctxtdata memory, failing open\n");
989 return -ENOMEM; 1021 return -ENOMEM;
990 } 1022 }
1023 hfi1_cdbg(PROC, "[%u:%u] pid %u assigned to CPU %d (NUMA %u)",
1024 uctxt->ctxt, fd->subctxt, current->pid, fd->rec_cpu_num,
1025 uctxt->numa_id);
1026
991 /* 1027 /*
992 * Allocate and enable a PIO send context. 1028 * Allocate and enable a PIO send context.
993 */ 1029 */
994 uctxt->sc = sc_alloc(dd, SC_USER, uctxt->rcvhdrqentsize, 1030 uctxt->sc = sc_alloc(dd, SC_USER, uctxt->rcvhdrqentsize,
995 uctxt->numa_id); 1031 uctxt->dd->node);
996 if (!uctxt->sc) 1032 if (!uctxt->sc)
997 return -ENOMEM; 1033 return -ENOMEM;
998 1034
@@ -1026,7 +1062,12 @@ static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd,
1026 INIT_LIST_HEAD(&uctxt->sdma_queues); 1062 INIT_LIST_HEAD(&uctxt->sdma_queues);
1027 spin_lock_init(&uctxt->sdma_qlock); 1063 spin_lock_init(&uctxt->sdma_qlock);
1028 hfi1_stats.sps_ctxts++; 1064 hfi1_stats.sps_ctxts++;
1029 dd->freectxts--; 1065 /*
1066 * Disable ASPM when there are open user/PSM contexts to avoid
1067 * issues with ASPM L1 exit latency
1068 */
1069 if (dd->freectxts-- == dd->num_user_contexts)
1070 aspm_disable_all(dd);
1030 fd->uctxt = uctxt; 1071 fd->uctxt = uctxt;
1031 1072
1032 return 0; 1073 return 0;
@@ -1035,22 +1076,19 @@ static int allocate_ctxt(struct file *fp, struct hfi1_devdata *dd,
1035static int init_subctxts(struct hfi1_ctxtdata *uctxt, 1076static int init_subctxts(struct hfi1_ctxtdata *uctxt,
1036 const struct hfi1_user_info *uinfo) 1077 const struct hfi1_user_info *uinfo)
1037{ 1078{
1038 int ret = 0;
1039 unsigned num_subctxts; 1079 unsigned num_subctxts;
1040 1080
1041 num_subctxts = uinfo->subctxt_cnt; 1081 num_subctxts = uinfo->subctxt_cnt;
1042 if (num_subctxts > HFI1_MAX_SHARED_CTXTS) { 1082 if (num_subctxts > HFI1_MAX_SHARED_CTXTS)
1043 ret = -EINVAL; 1083 return -EINVAL;
1044 goto bail;
1045 }
1046 1084
1047 uctxt->subctxt_cnt = uinfo->subctxt_cnt; 1085 uctxt->subctxt_cnt = uinfo->subctxt_cnt;
1048 uctxt->subctxt_id = uinfo->subctxt_id; 1086 uctxt->subctxt_id = uinfo->subctxt_id;
1049 uctxt->active_slaves = 1; 1087 uctxt->active_slaves = 1;
1050 uctxt->redirect_seq_cnt = 1; 1088 uctxt->redirect_seq_cnt = 1;
1051 set_bit(HFI1_CTXT_MASTER_UNINIT, &uctxt->event_flags); 1089 set_bit(HFI1_CTXT_MASTER_UNINIT, &uctxt->event_flags);
1052bail: 1090
1053 return ret; 1091 return 0;
1054} 1092}
1055 1093
1056static int setup_subctxt(struct hfi1_ctxtdata *uctxt) 1094static int setup_subctxt(struct hfi1_ctxtdata *uctxt)
@@ -1105,10 +1143,10 @@ static int user_init(struct file *fp)
1105 * has done it. 1143 * has done it.
1106 */ 1144 */
1107 if (fd->subctxt) { 1145 if (fd->subctxt) {
1108 ret = wait_event_interruptible(uctxt->wait, 1146 ret = wait_event_interruptible(uctxt->wait, !test_bit(
1109 !test_bit(HFI1_CTXT_MASTER_UNINIT, 1147 HFI1_CTXT_MASTER_UNINIT,
1110 &uctxt->event_flags)); 1148 &uctxt->event_flags));
1111 goto done; 1149 goto expected;
1112 } 1150 }
1113 1151
1114 /* initialize poll variables... */ 1152 /* initialize poll variables... */
@@ -1146,8 +1184,16 @@ static int user_init(struct file *fp)
1146 rcvctrl_ops |= HFI1_RCVCTRL_NO_EGR_DROP_ENB; 1184 rcvctrl_ops |= HFI1_RCVCTRL_NO_EGR_DROP_ENB;
1147 if (HFI1_CAP_KGET_MASK(uctxt->flags, NODROP_RHQ_FULL)) 1185 if (HFI1_CAP_KGET_MASK(uctxt->flags, NODROP_RHQ_FULL))
1148 rcvctrl_ops |= HFI1_RCVCTRL_NO_RHQ_DROP_ENB; 1186 rcvctrl_ops |= HFI1_RCVCTRL_NO_RHQ_DROP_ENB;
1187 /*
1188 * The RcvCtxtCtrl.TailUpd bit has to be explicitly written.
1189 * We can't rely on the correct value to be set from prior
1190 * uses of the chip or ctxt. Therefore, add the rcvctrl op
1191 * for both cases.
1192 */
1149 if (HFI1_CAP_KGET_MASK(uctxt->flags, DMA_RTAIL)) 1193 if (HFI1_CAP_KGET_MASK(uctxt->flags, DMA_RTAIL))
1150 rcvctrl_ops |= HFI1_RCVCTRL_TAILUPD_ENB; 1194 rcvctrl_ops |= HFI1_RCVCTRL_TAILUPD_ENB;
1195 else
1196 rcvctrl_ops |= HFI1_RCVCTRL_TAILUPD_DIS;
1151 hfi1_rcvctrl(uctxt->dd, rcvctrl_ops, uctxt->ctxt); 1197 hfi1_rcvctrl(uctxt->dd, rcvctrl_ops, uctxt->ctxt);
1152 1198
1153 /* Notify any waiting slaves */ 1199 /* Notify any waiting slaves */
@@ -1155,8 +1201,18 @@ static int user_init(struct file *fp)
1155 clear_bit(HFI1_CTXT_MASTER_UNINIT, &uctxt->event_flags); 1201 clear_bit(HFI1_CTXT_MASTER_UNINIT, &uctxt->event_flags);
1156 wake_up(&uctxt->wait); 1202 wake_up(&uctxt->wait);
1157 } 1203 }
1158 ret = 0;
1159 1204
1205expected:
1206 /*
1207 * Expected receive has to be setup for all processes (including
1208 * shared contexts). However, it has to be done after the master
1209 * context has been fully configured as it depends on the
1210 * eager/expected split of the RcvArray entries.
1211 * Setting it up here ensures that the subcontexts will be waiting
1212 * (due to the above wait_event_interruptible() until the master
1213 * is setup.
1214 */
1215 ret = hfi1_user_exp_rcv_init(fp);
1160done: 1216done:
1161 return ret; 1217 return ret;
1162} 1218}
@@ -1226,46 +1282,6 @@ static int setup_ctxt(struct file *fp)
1226 if (ret) 1282 if (ret)
1227 goto done; 1283 goto done;
1228 } 1284 }
1229 /* Setup Expected Rcv memories */
1230 uctxt->tid_pg_list = vzalloc(uctxt->expected_count *
1231 sizeof(struct page **));
1232 if (!uctxt->tid_pg_list) {
1233 ret = -ENOMEM;
1234 goto done;
1235 }
1236 uctxt->physshadow = vzalloc(uctxt->expected_count *
1237 sizeof(*uctxt->physshadow));
1238 if (!uctxt->physshadow) {
1239 ret = -ENOMEM;
1240 goto done;
1241 }
1242 /* allocate expected TID map and initialize the cursor */
1243 atomic_set(&uctxt->tidcursor, 0);
1244 uctxt->numtidgroups = uctxt->expected_count /
1245 dd->rcv_entries.group_size;
1246 uctxt->tidmapcnt = uctxt->numtidgroups / BITS_PER_LONG +
1247 !!(uctxt->numtidgroups % BITS_PER_LONG);
1248 uctxt->tidusemap = kzalloc_node(uctxt->tidmapcnt *
1249 sizeof(*uctxt->tidusemap),
1250 GFP_KERNEL, uctxt->numa_id);
1251 if (!uctxt->tidusemap) {
1252 ret = -ENOMEM;
1253 goto done;
1254 }
1255 /*
1256 * In case that the number of groups is not a multiple of
1257 * 64 (the number of groups in a tidusemap element), mark
1258 * the extra ones as used. This will effectively make them
1259 * permanently used and should never be assigned. Otherwise,
1260 * the code which checks how many free groups we have will
1261 * get completely confused about the state of the bits.
1262 */
1263 if (uctxt->numtidgroups % BITS_PER_LONG)
1264 uctxt->tidusemap[uctxt->tidmapcnt - 1] =
1265 ~((1ULL << (uctxt->numtidgroups %
1266 BITS_PER_LONG)) - 1);
1267 trace_hfi1_exp_tid_map(uctxt->ctxt, fd->subctxt, 0,
1268 uctxt->tidusemap, uctxt->tidmapcnt);
1269 } 1285 }
1270 ret = hfi1_user_sdma_alloc_queues(uctxt, fp); 1286 ret = hfi1_user_sdma_alloc_queues(uctxt, fp);
1271 if (ret) 1287 if (ret)
@@ -1391,8 +1407,9 @@ static unsigned int poll_next(struct file *fp,
1391 set_bit(HFI1_CTXT_WAITING_RCV, &uctxt->event_flags); 1407 set_bit(HFI1_CTXT_WAITING_RCV, &uctxt->event_flags);
1392 hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_ENB, uctxt->ctxt); 1408 hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_ENB, uctxt->ctxt);
1393 pollflag = 0; 1409 pollflag = 0;
1394 } else 1410 } else {
1395 pollflag = POLLIN | POLLRDNORM; 1411 pollflag = POLLIN | POLLRDNORM;
1412 }
1396 spin_unlock_irq(&dd->uctxt_lock); 1413 spin_unlock_irq(&dd->uctxt_lock);
1397 1414
1398 return pollflag; 1415 return pollflag;
@@ -1470,8 +1487,9 @@ static int manage_rcvq(struct hfi1_ctxtdata *uctxt, unsigned subctxt,
1470 if (uctxt->rcvhdrtail_kvaddr) 1487 if (uctxt->rcvhdrtail_kvaddr)
1471 clear_rcvhdrtail(uctxt); 1488 clear_rcvhdrtail(uctxt);
1472 rcvctrl_op = HFI1_RCVCTRL_CTXT_ENB; 1489 rcvctrl_op = HFI1_RCVCTRL_CTXT_ENB;
1473 } else 1490 } else {
1474 rcvctrl_op = HFI1_RCVCTRL_CTXT_DIS; 1491 rcvctrl_op = HFI1_RCVCTRL_CTXT_DIS;
1492 }
1475 hfi1_rcvctrl(dd, rcvctrl_op, uctxt->ctxt); 1493 hfi1_rcvctrl(dd, rcvctrl_op, uctxt->ctxt);
1476 /* always; new head should be equal to new tail; see above */ 1494 /* always; new head should be equal to new tail; see above */
1477bail: 1495bail:
@@ -1504,367 +1522,6 @@ static int user_event_ack(struct hfi1_ctxtdata *uctxt, int subctxt,
1504 return 0; 1522 return 0;
1505} 1523}
1506 1524
1507#define num_user_pages(vaddr, len) \
1508 (1 + (((((unsigned long)(vaddr) + \
1509 (unsigned long)(len) - 1) & PAGE_MASK) - \
1510 ((unsigned long)vaddr & PAGE_MASK)) >> PAGE_SHIFT))
1511
1512/**
1513 * tzcnt - count the number of trailing zeros in a 64bit value
1514 * @value: the value to be examined
1515 *
1516 * Returns the number of trailing least significant zeros in the
1517 * the input value. If the value is zero, return the number of
1518 * bits of the value.
1519 */
1520static inline u8 tzcnt(u64 value)
1521{
1522 return value ? __builtin_ctzl(value) : sizeof(value) * 8;
1523}
1524
1525static inline unsigned num_free_groups(unsigned long map, u16 *start)
1526{
1527 unsigned free;
1528 u16 bitidx = *start;
1529
1530 if (bitidx >= BITS_PER_LONG)
1531 return 0;
1532 /* "Turn off" any bits set before our bit index */
1533 map &= ~((1ULL << bitidx) - 1);
1534 free = tzcnt(map) - bitidx;
1535 while (!free && bitidx < BITS_PER_LONG) {
1536 /* Zero out the last set bit so we look at the rest */
1537 map &= ~(1ULL << bitidx);
1538 /*
1539 * Account for the previously checked bits and advance
1540 * the bit index. We don't have to check for bitidx
1541 * getting bigger than BITS_PER_LONG here as it would
1542 * mean extra instructions that we don't need. If it
1543 * did happen, it would push free to a negative value
1544 * which will break the loop.
1545 */
1546 free = tzcnt(map) - ++bitidx;
1547 }
1548 *start = bitidx;
1549 return free;
1550}
1551
1552static int exp_tid_setup(struct file *fp, struct hfi1_tid_info *tinfo)
1553{
1554 int ret = 0;
1555 struct hfi1_filedata *fd = fp->private_data;
1556 struct hfi1_ctxtdata *uctxt = fd->uctxt;
1557 struct hfi1_devdata *dd = uctxt->dd;
1558 unsigned tid, mapped = 0, npages, ngroups, exp_groups,
1559 tidpairs = uctxt->expected_count / 2;
1560 struct page **pages;
1561 unsigned long vaddr, tidmap[uctxt->tidmapcnt];
1562 dma_addr_t *phys;
1563 u32 tidlist[tidpairs], pairidx = 0, tidcursor;
1564 u16 useidx, idx, bitidx, tidcnt = 0;
1565
1566 vaddr = tinfo->vaddr;
1567
1568 if (offset_in_page(vaddr)) {
1569 ret = -EINVAL;
1570 goto bail;
1571 }
1572
1573 npages = num_user_pages(vaddr, tinfo->length);
1574 if (!npages) {
1575 ret = -EINVAL;
1576 goto bail;
1577 }
1578 if (!access_ok(VERIFY_WRITE, (void __user *)vaddr,
1579 npages * PAGE_SIZE)) {
1580 dd_dev_err(dd, "Fail vaddr %p, %u pages, !access_ok\n",
1581 (void *)vaddr, npages);
1582 ret = -EFAULT;
1583 goto bail;
1584 }
1585
1586 memset(tidmap, 0, sizeof(tidmap[0]) * uctxt->tidmapcnt);
1587 memset(tidlist, 0, sizeof(tidlist[0]) * tidpairs);
1588
1589 exp_groups = uctxt->expected_count / dd->rcv_entries.group_size;
1590 /* which group set do we look at first? */
1591 tidcursor = atomic_read(&uctxt->tidcursor);
1592 useidx = (tidcursor >> 16) & 0xffff;
1593 bitidx = tidcursor & 0xffff;
1594
1595 /*
1596 * Keep going until we've mapped all pages or we've exhausted all
1597 * RcvArray entries.
1598 * This iterates over the number of tidmaps + 1
1599 * (idx <= uctxt->tidmapcnt) so we check the bitmap which we
1600 * started from one more time for any free bits before the
1601 * starting point bit.
1602 */
1603 for (mapped = 0, idx = 0;
1604 mapped < npages && idx <= uctxt->tidmapcnt;) {
1605 u64 i, offset = 0;
1606 unsigned free, pinned, pmapped = 0, bits_used;
1607 u16 grp;
1608
1609 /*
1610 * "Reserve" the needed group bits under lock so other
1611 * processes can't step in the middle of it. Once
1612 * reserved, we don't need the lock anymore since we
1613 * are guaranteed the groups.
1614 */
1615 spin_lock(&uctxt->exp_lock);
1616 if (uctxt->tidusemap[useidx] == -1ULL ||
1617 bitidx >= BITS_PER_LONG) {
1618 /* no free groups in the set, use the next */
1619 useidx = (useidx + 1) % uctxt->tidmapcnt;
1620 idx++;
1621 bitidx = 0;
1622 spin_unlock(&uctxt->exp_lock);
1623 continue;
1624 }
1625 ngroups = ((npages - mapped) / dd->rcv_entries.group_size) +
1626 !!((npages - mapped) % dd->rcv_entries.group_size);
1627
1628 /*
1629 * If we've gotten here, the current set of groups does have
1630 * one or more free groups.
1631 */
1632 free = num_free_groups(uctxt->tidusemap[useidx], &bitidx);
1633 if (!free) {
1634 /*
1635 * Despite the check above, free could still come back
1636 * as 0 because we don't check the entire bitmap but
1637 * we start from bitidx.
1638 */
1639 spin_unlock(&uctxt->exp_lock);
1640 continue;
1641 }
1642 bits_used = min(free, ngroups);
1643 tidmap[useidx] |= ((1ULL << bits_used) - 1) << bitidx;
1644 uctxt->tidusemap[useidx] |= tidmap[useidx];
1645 spin_unlock(&uctxt->exp_lock);
1646
1647 /*
1648 * At this point, we know where in the map we have free bits.
1649 * properly offset into the various "shadow" arrays and compute
1650 * the RcvArray entry index.
1651 */
1652 offset = ((useidx * BITS_PER_LONG) + bitidx) *
1653 dd->rcv_entries.group_size;
1654 pages = uctxt->tid_pg_list + offset;
1655 phys = uctxt->physshadow + offset;
1656 tid = uctxt->expected_base + offset;
1657
1658 /* Calculate how many pages we can pin based on free bits */
1659 pinned = min((bits_used * dd->rcv_entries.group_size),
1660 (npages - mapped));
1661 /*
1662 * Now that we know how many free RcvArray entries we have,
1663 * we can pin that many user pages.
1664 */
1665 ret = hfi1_acquire_user_pages(vaddr + (mapped * PAGE_SIZE),
1666 pinned, true, pages);
1667 if (ret) {
1668 /*
1669 * We can't continue because the pages array won't be
1670 * initialized. This should never happen,
1671 * unless perhaps the user has mpin'ed the pages
1672 * themselves.
1673 */
1674 dd_dev_info(dd,
1675 "Failed to lock addr %p, %u pages: errno %d\n",
1676 (void *) vaddr, pinned, -ret);
1677 /*
1678 * Let go of the bits that we reserved since we are not
1679 * going to use them.
1680 */
1681 spin_lock(&uctxt->exp_lock);
1682 uctxt->tidusemap[useidx] &=
1683 ~(((1ULL << bits_used) - 1) << bitidx);
1684 spin_unlock(&uctxt->exp_lock);
1685 goto done;
1686 }
1687 /*
1688 * How many groups do we need based on how many pages we have
1689 * pinned?
1690 */
1691 ngroups = (pinned / dd->rcv_entries.group_size) +
1692 !!(pinned % dd->rcv_entries.group_size);
1693 /*
1694 * Keep programming RcvArray entries for all the <ngroups> free
1695 * groups.
1696 */
1697 for (i = 0, grp = 0; grp < ngroups; i++, grp++) {
1698 unsigned j;
1699 u32 pair_size = 0, tidsize;
1700 /*
1701 * This inner loop will program an entire group or the
1702 * array of pinned pages (which ever limit is hit
1703 * first).
1704 */
1705 for (j = 0; j < dd->rcv_entries.group_size &&
1706 pmapped < pinned; j++, pmapped++, tid++) {
1707 tidsize = PAGE_SIZE;
1708 phys[pmapped] = hfi1_map_page(dd->pcidev,
1709 pages[pmapped], 0,
1710 tidsize, PCI_DMA_FROMDEVICE);
1711 trace_hfi1_exp_rcv_set(uctxt->ctxt,
1712 fd->subctxt,
1713 tid, vaddr,
1714 phys[pmapped],
1715 pages[pmapped]);
1716 /*
1717 * Each RcvArray entry is programmed with one
1718 * page * worth of memory. This will handle
1719 * the 8K MTU as well as anything smaller
1720 * due to the fact that both entries in the
1721 * RcvTidPair are programmed with a page.
1722 * PSM currently does not handle anything
1723 * bigger than 8K MTU, so should we even worry
1724 * about 10K here?
1725 */
1726 hfi1_put_tid(dd, tid, PT_EXPECTED,
1727 phys[pmapped],
1728 ilog2(tidsize >> PAGE_SHIFT) + 1);
1729 pair_size += tidsize >> PAGE_SHIFT;
1730 EXP_TID_RESET(tidlist[pairidx], LEN, pair_size);
1731 if (!(tid % 2)) {
1732 tidlist[pairidx] |=
1733 EXP_TID_SET(IDX,
1734 (tid - uctxt->expected_base)
1735 / 2);
1736 tidlist[pairidx] |=
1737 EXP_TID_SET(CTRL, 1);
1738 tidcnt++;
1739 } else {
1740 tidlist[pairidx] |=
1741 EXP_TID_SET(CTRL, 2);
1742 pair_size = 0;
1743 pairidx++;
1744 }
1745 }
1746 /*
1747 * We've programmed the entire group (or as much of the
1748 * group as we'll use. Now, it's time to push it out...
1749 */
1750 flush_wc();
1751 }
1752 mapped += pinned;
1753 atomic_set(&uctxt->tidcursor,
1754 (((useidx & 0xffffff) << 16) |
1755 ((bitidx + bits_used) & 0xffffff)));
1756 }
1757 trace_hfi1_exp_tid_map(uctxt->ctxt, fd->subctxt, 0, uctxt->tidusemap,
1758 uctxt->tidmapcnt);
1759
1760done:
1761 /* If we've mapped anything, copy relevant info to user */
1762 if (mapped) {
1763 if (copy_to_user((void __user *)(unsigned long)tinfo->tidlist,
1764 tidlist, sizeof(tidlist[0]) * tidcnt)) {
1765 ret = -EFAULT;
1766 goto done;
1767 }
1768 /* copy TID info to user */
1769 if (copy_to_user((void __user *)(unsigned long)tinfo->tidmap,
1770 tidmap, sizeof(tidmap[0]) * uctxt->tidmapcnt))
1771 ret = -EFAULT;
1772 }
1773bail:
1774 /*
1775 * Calculate mapped length. New Exp TID protocol does not "unwind" and
1776 * report an error if it can't map the entire buffer. It just reports
1777 * the length that was mapped.
1778 */
1779 tinfo->length = mapped * PAGE_SIZE;
1780 tinfo->tidcnt = tidcnt;
1781 return ret;
1782}
1783
1784static int exp_tid_free(struct file *fp, struct hfi1_tid_info *tinfo)
1785{
1786 struct hfi1_filedata *fd = fp->private_data;
1787 struct hfi1_ctxtdata *uctxt = fd->uctxt;
1788 struct hfi1_devdata *dd = uctxt->dd;
1789 unsigned long tidmap[uctxt->tidmapcnt];
1790 struct page **pages;
1791 dma_addr_t *phys;
1792 u16 idx, bitidx, tid;
1793 int ret = 0;
1794
1795 if (copy_from_user(&tidmap, (void __user *)(unsigned long)
1796 tinfo->tidmap,
1797 sizeof(tidmap[0]) * uctxt->tidmapcnt)) {
1798 ret = -EFAULT;
1799 goto done;
1800 }
1801 for (idx = 0; idx < uctxt->tidmapcnt; idx++) {
1802 unsigned long map;
1803
1804 bitidx = 0;
1805 if (!tidmap[idx])
1806 continue;
1807 map = tidmap[idx];
1808 while ((bitidx = tzcnt(map)) < BITS_PER_LONG) {
1809 int i, pcount = 0;
1810 struct page *pshadow[dd->rcv_entries.group_size];
1811 unsigned offset = ((idx * BITS_PER_LONG) + bitidx) *
1812 dd->rcv_entries.group_size;
1813
1814 pages = uctxt->tid_pg_list + offset;
1815 phys = uctxt->physshadow + offset;
1816 tid = uctxt->expected_base + offset;
1817 for (i = 0; i < dd->rcv_entries.group_size;
1818 i++, tid++) {
1819 if (pages[i]) {
1820 hfi1_put_tid(dd, tid, PT_INVALID,
1821 0, 0);
1822 trace_hfi1_exp_rcv_free(uctxt->ctxt,
1823 fd->subctxt,
1824 tid, phys[i],
1825 pages[i]);
1826 pci_unmap_page(dd->pcidev, phys[i],
1827 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1828 pshadow[pcount] = pages[i];
1829 pages[i] = NULL;
1830 pcount++;
1831 phys[i] = 0;
1832 }
1833 }
1834 flush_wc();
1835 hfi1_release_user_pages(pshadow, pcount, true);
1836 clear_bit(bitidx, &uctxt->tidusemap[idx]);
1837 map &= ~(1ULL<<bitidx);
1838 }
1839 }
1840 trace_hfi1_exp_tid_map(uctxt->ctxt, fd->subctxt, 1, uctxt->tidusemap,
1841 uctxt->tidmapcnt);
1842done:
1843 return ret;
1844}
1845
1846static void unlock_exp_tids(struct hfi1_ctxtdata *uctxt)
1847{
1848 struct hfi1_devdata *dd = uctxt->dd;
1849 unsigned tid;
1850
1851 dd_dev_info(dd, "ctxt %u unlocking any locked expTID pages\n",
1852 uctxt->ctxt);
1853 for (tid = 0; tid < uctxt->expected_count; tid++) {
1854 struct page *p = uctxt->tid_pg_list[tid];
1855 dma_addr_t phys;
1856
1857 if (!p)
1858 continue;
1859
1860 phys = uctxt->physshadow[tid];
1861 uctxt->physshadow[tid] = 0;
1862 uctxt->tid_pg_list[tid] = NULL;
1863 pci_unmap_page(dd->pcidev, phys, PAGE_SIZE, PCI_DMA_FROMDEVICE);
1864 hfi1_release_user_pages(&p, 1, true);
1865 }
1866}
1867
1868static int set_ctxt_pkey(struct hfi1_ctxtdata *uctxt, unsigned subctxt, 1525static int set_ctxt_pkey(struct hfi1_ctxtdata *uctxt, unsigned subctxt,
1869 u16 pkey) 1526 u16 pkey)
1870{ 1527{
@@ -1933,10 +1590,9 @@ static loff_t ui_lseek(struct file *filp, loff_t offset, int whence)
1933 return filp->f_pos; 1590 return filp->f_pos;
1934} 1591}
1935 1592
1936
1937/* NOTE: assumes unsigned long is 8 bytes */ 1593/* NOTE: assumes unsigned long is 8 bytes */
1938static ssize_t ui_read(struct file *filp, char __user *buf, size_t count, 1594static ssize_t ui_read(struct file *filp, char __user *buf, size_t count,
1939 loff_t *f_pos) 1595 loff_t *f_pos)
1940{ 1596{
1941 struct hfi1_devdata *dd = filp->private_data; 1597 struct hfi1_devdata *dd = filp->private_data;
1942 void __iomem *base = dd->kregbase; 1598 void __iomem *base = dd->kregbase;
@@ -1972,12 +1628,12 @@ static ssize_t ui_read(struct file *filp, char __user *buf, size_t count,
1972 * them. These registers are defined as having a read value 1628 * them. These registers are defined as having a read value
1973 * of 0. 1629 * of 0.
1974 */ 1630 */
1975 else if (csr_off == ASIC_GPIO_CLEAR 1631 else if (csr_off == ASIC_GPIO_CLEAR ||
1976 || csr_off == ASIC_GPIO_FORCE 1632 csr_off == ASIC_GPIO_FORCE ||
1977 || csr_off == ASIC_QSFP1_CLEAR 1633 csr_off == ASIC_QSFP1_CLEAR ||
1978 || csr_off == ASIC_QSFP1_FORCE 1634 csr_off == ASIC_QSFP1_FORCE ||
1979 || csr_off == ASIC_QSFP2_CLEAR 1635 csr_off == ASIC_QSFP2_CLEAR ||
1980 || csr_off == ASIC_QSFP2_FORCE) 1636 csr_off == ASIC_QSFP2_FORCE)
1981 data = 0; 1637 data = 0;
1982 else if (csr_off >= barlen) { 1638 else if (csr_off >= barlen) {
1983 /* 1639 /*
diff --git a/drivers/staging/rdma/hfi1/firmware.c b/drivers/staging/rdma/hfi1/firmware.c
index 28ae42faa018..3040162cb326 100644
--- a/drivers/staging/rdma/hfi1/firmware.c
+++ b/drivers/staging/rdma/hfi1/firmware.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -77,7 +74,13 @@ static uint fw_8051_load = 1;
77static uint fw_fabric_serdes_load = 1; 74static uint fw_fabric_serdes_load = 1;
78static uint fw_pcie_serdes_load = 1; 75static uint fw_pcie_serdes_load = 1;
79static uint fw_sbus_load = 1; 76static uint fw_sbus_load = 1;
80static uint platform_config_load = 1; 77
78/*
79 * Access required in platform.c
80 * Maintains state of whether the platform config was fetched via the
81 * fallback option
82 */
83uint platform_config_load;
81 84
82/* Firmware file names get set in hfi1_firmware_init() based on the above */ 85/* Firmware file names get set in hfi1_firmware_init() based on the above */
83static char *fw_8051_name; 86static char *fw_8051_name;
@@ -107,6 +110,7 @@ struct css_header {
107 u32 exponent_size; /* in DWORDs */ 110 u32 exponent_size; /* in DWORDs */
108 u32 reserved[22]; 111 u32 reserved[22];
109}; 112};
113
110/* expected field values */ 114/* expected field values */
111#define CSS_MODULE_TYPE 0x00000006 115#define CSS_MODULE_TYPE 0x00000006
112#define CSS_HEADER_LEN 0x000000a1 116#define CSS_HEADER_LEN 0x000000a1
@@ -166,6 +170,7 @@ enum fw_state {
166 FW_FINAL, 170 FW_FINAL,
167 FW_ERR 171 FW_ERR
168}; 172};
173
169static enum fw_state fw_state = FW_EMPTY; 174static enum fw_state fw_state = FW_EMPTY;
170static int fw_err; 175static int fw_err;
171static struct firmware_details fw_8051; 176static struct firmware_details fw_8051;
@@ -193,7 +198,7 @@ static const struct firmware *platform_config;
193#define RSA_ENGINE_TIMEOUT 100 /* ms */ 198#define RSA_ENGINE_TIMEOUT 100 /* ms */
194 199
195/* hardware mutex timeout, in ms */ 200/* hardware mutex timeout, in ms */
196#define HM_TIMEOUT 4000 /* 4 s */ 201#define HM_TIMEOUT 10 /* ms */
197 202
198/* 8051 memory access timeout, in us */ 203/* 8051 memory access timeout, in us */
199#define DC8051_ACCESS_TIMEOUT 100 /* us */ 204#define DC8051_ACCESS_TIMEOUT 100 /* us */
@@ -233,6 +238,8 @@ static const u8 all_pcie_serdes_broadcast = 0xe0;
233 238
234/* forwards */ 239/* forwards */
235static void dispose_one_firmware(struct firmware_details *fdet); 240static void dispose_one_firmware(struct firmware_details *fdet);
241static int load_fabric_serdes_firmware(struct hfi1_devdata *dd,
242 struct firmware_details *fdet);
236 243
237/* 244/*
238 * Read a single 64-bit value from 8051 data memory. 245 * Read a single 64-bit value from 8051 data memory.
@@ -372,8 +379,8 @@ static int invalid_header(struct hfi1_devdata *dd, const char *what,
372 return 0; 379 return 0;
373 380
374 dd_dev_err(dd, 381 dd_dev_err(dd,
375 "invalid firmware header field %s: expected 0x%x, actual 0x%x\n", 382 "invalid firmware header field %s: expected 0x%x, actual 0x%x\n",
376 what, expected, actual); 383 what, expected, actual);
377 return 1; 384 return 1;
378} 385}
379 386
@@ -383,19 +390,19 @@ static int invalid_header(struct hfi1_devdata *dd, const char *what,
383static int verify_css_header(struct hfi1_devdata *dd, struct css_header *css) 390static int verify_css_header(struct hfi1_devdata *dd, struct css_header *css)
384{ 391{
385 /* verify CSS header fields (most sizes are in DW, so add /4) */ 392 /* verify CSS header fields (most sizes are in DW, so add /4) */
386 if (invalid_header(dd, "module_type", css->module_type, CSS_MODULE_TYPE) 393 if (invalid_header(dd, "module_type", css->module_type,
387 || invalid_header(dd, "header_len", css->header_len, 394 CSS_MODULE_TYPE) ||
388 (sizeof(struct firmware_file)/4)) 395 invalid_header(dd, "header_len", css->header_len,
389 || invalid_header(dd, "header_version", 396 (sizeof(struct firmware_file) / 4)) ||
390 css->header_version, CSS_HEADER_VERSION) 397 invalid_header(dd, "header_version", css->header_version,
391 || invalid_header(dd, "module_vendor", 398 CSS_HEADER_VERSION) ||
392 css->module_vendor, CSS_MODULE_VENDOR) 399 invalid_header(dd, "module_vendor", css->module_vendor,
393 || invalid_header(dd, "key_size", 400 CSS_MODULE_VENDOR) ||
394 css->key_size, KEY_SIZE/4) 401 invalid_header(dd, "key_size", css->key_size, KEY_SIZE / 4) ||
395 || invalid_header(dd, "modulus_size", 402 invalid_header(dd, "modulus_size", css->modulus_size,
396 css->modulus_size, KEY_SIZE/4) 403 KEY_SIZE / 4) ||
397 || invalid_header(dd, "exponent_size", 404 invalid_header(dd, "exponent_size", css->exponent_size,
398 css->exponent_size, EXPONENT_SIZE/4)) { 405 EXPONENT_SIZE / 4)) {
399 return -EINVAL; 406 return -EINVAL;
400 } 407 }
401 return 0; 408 return 0;
@@ -410,8 +417,8 @@ static int payload_check(struct hfi1_devdata *dd, const char *name,
410 /* make sure we have some payload */ 417 /* make sure we have some payload */
411 if (prefix_size >= file_size) { 418 if (prefix_size >= file_size) {
412 dd_dev_err(dd, 419 dd_dev_err(dd,
413 "firmware \"%s\", size %ld, must be larger than %ld bytes\n", 420 "firmware \"%s\", size %ld, must be larger than %ld bytes\n",
414 name, file_size, prefix_size); 421 name, file_size, prefix_size);
415 return -EINVAL; 422 return -EINVAL;
416 } 423 }
417 424
@@ -433,8 +440,8 @@ static int obtain_one_firmware(struct hfi1_devdata *dd, const char *name,
433 440
434 ret = request_firmware(&fdet->fw, name, &dd->pcidev->dev); 441 ret = request_firmware(&fdet->fw, name, &dd->pcidev->dev);
435 if (ret) { 442 if (ret) {
436 dd_dev_err(dd, "cannot find firmware \"%s\", err %d\n", 443 dd_dev_warn(dd, "cannot find firmware \"%s\", err %d\n",
437 name, ret); 444 name, ret);
438 return ret; 445 return ret;
439 } 446 }
440 447
@@ -480,14 +487,14 @@ static int obtain_one_firmware(struct hfi1_devdata *dd, const char *name,
480 ret = verify_css_header(dd, css); 487 ret = verify_css_header(dd, css);
481 if (ret) { 488 if (ret) {
482 dd_dev_info(dd, "Invalid CSS header for \"%s\"\n", name); 489 dd_dev_info(dd, "Invalid CSS header for \"%s\"\n", name);
483 } else if ((css->size*4) == fdet->fw->size) { 490 } else if ((css->size * 4) == fdet->fw->size) {
484 /* non-augmented firmware file */ 491 /* non-augmented firmware file */
485 struct firmware_file *ff = (struct firmware_file *) 492 struct firmware_file *ff = (struct firmware_file *)
486 fdet->fw->data; 493 fdet->fw->data;
487 494
488 /* make sure there are bytes in the payload */ 495 /* make sure there are bytes in the payload */
489 ret = payload_check(dd, name, fdet->fw->size, 496 ret = payload_check(dd, name, fdet->fw->size,
490 sizeof(struct firmware_file)); 497 sizeof(struct firmware_file));
491 if (ret == 0) { 498 if (ret == 0) {
492 fdet->css_header = css; 499 fdet->css_header = css;
493 fdet->modulus = ff->modulus; 500 fdet->modulus = ff->modulus;
@@ -505,14 +512,14 @@ static int obtain_one_firmware(struct hfi1_devdata *dd, const char *name,
505 dd_dev_err(dd, "driver is unable to validate firmware without r2 and mu (not in firmware file)\n"); 512 dd_dev_err(dd, "driver is unable to validate firmware without r2 and mu (not in firmware file)\n");
506 ret = -EINVAL; 513 ret = -EINVAL;
507 } 514 }
508 } else if ((css->size*4) + AUGMENT_SIZE == fdet->fw->size) { 515 } else if ((css->size * 4) + AUGMENT_SIZE == fdet->fw->size) {
509 /* augmented firmware file */ 516 /* augmented firmware file */
510 struct augmented_firmware_file *aff = 517 struct augmented_firmware_file *aff =
511 (struct augmented_firmware_file *)fdet->fw->data; 518 (struct augmented_firmware_file *)fdet->fw->data;
512 519
513 /* make sure there are bytes in the payload */ 520 /* make sure there are bytes in the payload */
514 ret = payload_check(dd, name, fdet->fw->size, 521 ret = payload_check(dd, name, fdet->fw->size,
515 sizeof(struct augmented_firmware_file)); 522 sizeof(struct augmented_firmware_file));
516 if (ret == 0) { 523 if (ret == 0) {
517 fdet->css_header = css; 524 fdet->css_header = css;
518 fdet->modulus = aff->modulus; 525 fdet->modulus = aff->modulus;
@@ -527,9 +534,10 @@ static int obtain_one_firmware(struct hfi1_devdata *dd, const char *name,
527 } else { 534 } else {
528 /* css->size check failed */ 535 /* css->size check failed */
529 dd_dev_err(dd, 536 dd_dev_err(dd,
530 "invalid firmware header field size: expected 0x%lx or 0x%lx, actual 0x%x\n", 537 "invalid firmware header field size: expected 0x%lx or 0x%lx, actual 0x%x\n",
531 fdet->fw->size/4, (fdet->fw->size - AUGMENT_SIZE)/4, 538 fdet->fw->size / 4,
532 css->size); 539 (fdet->fw->size - AUGMENT_SIZE) / 4,
540 css->size);
533 541
534 ret = -EINVAL; 542 ret = -EINVAL;
535 } 543 }
@@ -572,7 +580,7 @@ retry:
572 * We tried the original and it failed. Move to the 580 * We tried the original and it failed. Move to the
573 * alternate. 581 * alternate.
574 */ 582 */
575 dd_dev_info(dd, "using alternate firmware names\n"); 583 dd_dev_warn(dd, "using alternate firmware names\n");
576 /* 584 /*
577 * Let others run. Some systems, when missing firmware, does 585 * Let others run. Some systems, when missing firmware, does
578 * something that holds for 30 seconds. If we do that twice 586 * something that holds for 30 seconds. If we do that twice
@@ -593,27 +601,27 @@ retry:
593 fw_pcie_serdes_name = ALT_FW_PCIE_NAME; 601 fw_pcie_serdes_name = ALT_FW_PCIE_NAME;
594 } 602 }
595 603
596 if (fw_8051_load) { 604 if (fw_sbus_load) {
597 err = obtain_one_firmware(dd, fw_8051_name, &fw_8051); 605 err = obtain_one_firmware(dd, fw_sbus_name, &fw_sbus);
598 if (err) 606 if (err)
599 goto done; 607 goto done;
600 } 608 }
601 609
602 if (fw_fabric_serdes_load) { 610 if (fw_pcie_serdes_load) {
603 err = obtain_one_firmware(dd, fw_fabric_serdes_name, 611 err = obtain_one_firmware(dd, fw_pcie_serdes_name, &fw_pcie);
604 &fw_fabric);
605 if (err) 612 if (err)
606 goto done; 613 goto done;
607 } 614 }
608 615
609 if (fw_sbus_load) { 616 if (fw_fabric_serdes_load) {
610 err = obtain_one_firmware(dd, fw_sbus_name, &fw_sbus); 617 err = obtain_one_firmware(dd, fw_fabric_serdes_name,
618 &fw_fabric);
611 if (err) 619 if (err)
612 goto done; 620 goto done;
613 } 621 }
614 622
615 if (fw_pcie_serdes_load) { 623 if (fw_8051_load) {
616 err = obtain_one_firmware(dd, fw_pcie_serdes_name, &fw_pcie); 624 err = obtain_one_firmware(dd, fw_8051_name, &fw_8051);
617 if (err) 625 if (err)
618 goto done; 626 goto done;
619 } 627 }
@@ -621,16 +629,18 @@ retry:
621done: 629done:
622 if (err) { 630 if (err) {
623 /* oops, had problems obtaining a firmware */ 631 /* oops, had problems obtaining a firmware */
624 if (fw_state == FW_EMPTY) { 632 if (fw_state == FW_EMPTY && dd->icode == ICODE_RTL_SILICON) {
625 /* retry with alternate */ 633 /* retry with alternate (RTL only) */
626 fw_state = FW_TRY; 634 fw_state = FW_TRY;
627 goto retry; 635 goto retry;
628 } 636 }
637 dd_dev_err(dd, "unable to obtain working firmware\n");
629 fw_state = FW_ERR; 638 fw_state = FW_ERR;
630 fw_err = -ENOENT; 639 fw_err = -ENOENT;
631 } else { 640 } else {
632 /* success */ 641 /* success */
633 if (fw_state == FW_EMPTY) 642 if (fw_state == FW_EMPTY &&
643 dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
634 fw_state = FW_TRY; /* may retry later */ 644 fw_state = FW_TRY; /* may retry later */
635 else 645 else
636 fw_state = FW_FINAL; /* cannot try again */ 646 fw_state = FW_FINAL; /* cannot try again */
@@ -673,10 +683,15 @@ static int obtain_firmware(struct hfi1_devdata *dd)
673 } 683 }
674 /* not in FW_TRY state */ 684 /* not in FW_TRY state */
675 685
676 if (fw_state == FW_FINAL) 686 if (fw_state == FW_FINAL) {
687 if (platform_config) {
688 dd->platform_config.data = platform_config->data;
689 dd->platform_config.size = platform_config->size;
690 }
677 goto done; /* already acquired */ 691 goto done; /* already acquired */
678 else if (fw_state == FW_ERR) 692 } else if (fw_state == FW_ERR) {
679 goto done; /* already tried and failed */ 693 goto done; /* already tried and failed */
694 }
680 /* fw_state is FW_EMPTY */ 695 /* fw_state is FW_EMPTY */
681 696
682 /* set fw_state to FW_TRY, FW_FINAL, or FW_ERR, and fw_err */ 697 /* set fw_state to FW_TRY, FW_FINAL, or FW_ERR, and fw_err */
@@ -685,9 +700,13 @@ static int obtain_firmware(struct hfi1_devdata *dd)
685 if (platform_config_load) { 700 if (platform_config_load) {
686 platform_config = NULL; 701 platform_config = NULL;
687 err = request_firmware(&platform_config, platform_config_name, 702 err = request_firmware(&platform_config, platform_config_name,
688 &dd->pcidev->dev); 703 &dd->pcidev->dev);
689 if (err) 704 if (err) {
690 platform_config = NULL; 705 platform_config = NULL;
706 goto done;
707 }
708 dd->platform_config.data = platform_config->data;
709 dd->platform_config.size = platform_config->size;
691 } 710 }
692 711
693done: 712done:
@@ -761,7 +780,7 @@ static int retry_firmware(struct hfi1_devdata *dd, int load_result)
761static void write_rsa_data(struct hfi1_devdata *dd, int what, 780static void write_rsa_data(struct hfi1_devdata *dd, int what,
762 const u8 *data, int nbytes) 781 const u8 *data, int nbytes)
763{ 782{
764 int qw_size = nbytes/8; 783 int qw_size = nbytes / 8;
765 int i; 784 int i;
766 785
767 if (((unsigned long)data & 0x7) == 0) { 786 if (((unsigned long)data & 0x7) == 0) {
@@ -769,14 +788,14 @@ static void write_rsa_data(struct hfi1_devdata *dd, int what,
769 u64 *ptr = (u64 *)data; 788 u64 *ptr = (u64 *)data;
770 789
771 for (i = 0; i < qw_size; i++, ptr++) 790 for (i = 0; i < qw_size; i++, ptr++)
772 write_csr(dd, what + (8*i), *ptr); 791 write_csr(dd, what + (8 * i), *ptr);
773 } else { 792 } else {
774 /* not aligned */ 793 /* not aligned */
775 for (i = 0; i < qw_size; i++, data += 8) { 794 for (i = 0; i < qw_size; i++, data += 8) {
776 u64 value; 795 u64 value;
777 796
778 memcpy(&value, data, 8); 797 memcpy(&value, data, 8);
779 write_csr(dd, what + (8*i), value); 798 write_csr(dd, what + (8 * i), value);
780 } 799 }
781 } 800 }
782} 801}
@@ -789,7 +808,7 @@ static void write_streamed_rsa_data(struct hfi1_devdata *dd, int what,
789 const u8 *data, int nbytes) 808 const u8 *data, int nbytes)
790{ 809{
791 u64 *ptr = (u64 *)data; 810 u64 *ptr = (u64 *)data;
792 int qw_size = nbytes/8; 811 int qw_size = nbytes / 8;
793 812
794 for (; qw_size > 0; qw_size--, ptr++) 813 for (; qw_size > 0; qw_size--, ptr++)
795 write_csr(dd, what, *ptr); 814 write_csr(dd, what, *ptr);
@@ -822,7 +841,7 @@ static int run_rsa(struct hfi1_devdata *dd, const char *who,
822 >> MISC_CFG_FW_CTRL_RSA_STATUS_SHIFT; 841 >> MISC_CFG_FW_CTRL_RSA_STATUS_SHIFT;
823 if (status != RSA_STATUS_IDLE) { 842 if (status != RSA_STATUS_IDLE) {
824 dd_dev_err(dd, "%s security engine not idle - giving up\n", 843 dd_dev_err(dd, "%s security engine not idle - giving up\n",
825 who); 844 who);
826 return -EBUSY; 845 return -EBUSY;
827 } 846 }
828 847
@@ -859,7 +878,7 @@ static int run_rsa(struct hfi1_devdata *dd, const char *who,
859 if (status == RSA_STATUS_IDLE) { 878 if (status == RSA_STATUS_IDLE) {
860 /* should not happen */ 879 /* should not happen */
861 dd_dev_err(dd, "%s firmware security bad idle state\n", 880 dd_dev_err(dd, "%s firmware security bad idle state\n",
862 who); 881 who);
863 ret = -EINVAL; 882 ret = -EINVAL;
864 break; 883 break;
865 } else if (status == RSA_STATUS_DONE) { 884 } else if (status == RSA_STATUS_DONE) {
@@ -893,19 +912,20 @@ static int run_rsa(struct hfi1_devdata *dd, const char *who,
893 * is not keeping the error high. 912 * is not keeping the error high.
894 */ 913 */
895 write_csr(dd, MISC_ERR_CLEAR, 914 write_csr(dd, MISC_ERR_CLEAR,
896 MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK 915 MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK |
897 | MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK); 916 MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK);
898 /* 917 /*
899 * All that is left are the current errors. Print failure details, 918 * All that is left are the current errors. Print warnings on
900 * if any. 919 * authorization failure details, if any. Firmware authorization
920 * can be retried, so these are only warnings.
901 */ 921 */
902 reg = read_csr(dd, MISC_ERR_STATUS); 922 reg = read_csr(dd, MISC_ERR_STATUS);
903 if (ret) { 923 if (ret) {
904 if (reg & MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK) 924 if (reg & MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK)
905 dd_dev_err(dd, "%s firmware authorization failed\n", 925 dd_dev_warn(dd, "%s firmware authorization failed\n",
906 who); 926 who);
907 if (reg & MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK) 927 if (reg & MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK)
908 dd_dev_err(dd, "%s firmware key mismatch\n", who); 928 dd_dev_warn(dd, "%s firmware key mismatch\n", who);
909 } 929 }
910 930
911 return ret; 931 return ret;
@@ -922,7 +942,8 @@ static void load_security_variables(struct hfi1_devdata *dd,
922 write_rsa_data(dd, MISC_CFG_RSA_MU, fdet->mu, MU_SIZE); 942 write_rsa_data(dd, MISC_CFG_RSA_MU, fdet->mu, MU_SIZE);
923 /* Security variables d. Write the header */ 943 /* Security variables d. Write the header */
924 write_streamed_rsa_data(dd, MISC_CFG_SHA_PRELOAD, 944 write_streamed_rsa_data(dd, MISC_CFG_SHA_PRELOAD,
925 (u8 *)fdet->css_header, sizeof(struct css_header)); 945 (u8 *)fdet->css_header,
946 sizeof(struct css_header));
926} 947}
927 948
928/* return the 8051 firmware state */ 949/* return the 8051 firmware state */
@@ -1002,7 +1023,7 @@ static int load_8051_firmware(struct hfi1_devdata *dd,
1002 1023
1003 /* Firmware load steps 3-5 */ 1024 /* Firmware load steps 3-5 */
1004 ret = write_8051(dd, 1/*code*/, 0, fdet->firmware_ptr, 1025 ret = write_8051(dd, 1/*code*/, 0, fdet->firmware_ptr,
1005 fdet->firmware_len); 1026 fdet->firmware_len);
1006 if (ret) 1027 if (ret)
1007 return ret; 1028 return ret;
1008 1029
@@ -1029,13 +1050,13 @@ static int load_8051_firmware(struct hfi1_devdata *dd,
1029 ret = wait_fm_ready(dd, TIMEOUT_8051_START); 1050 ret = wait_fm_ready(dd, TIMEOUT_8051_START);
1030 if (ret) { /* timed out */ 1051 if (ret) { /* timed out */
1031 dd_dev_err(dd, "8051 start timeout, current state 0x%x\n", 1052 dd_dev_err(dd, "8051 start timeout, current state 0x%x\n",
1032 get_firmware_state(dd)); 1053 get_firmware_state(dd));
1033 return -ETIMEDOUT; 1054 return -ETIMEDOUT;
1034 } 1055 }
1035 1056
1036 read_misc_status(dd, &ver_a, &ver_b); 1057 read_misc_status(dd, &ver_a, &ver_b);
1037 dd_dev_info(dd, "8051 firmware version %d.%d\n", 1058 dd_dev_info(dd, "8051 firmware version %d.%d\n",
1038 (int)ver_b, (int)ver_a); 1059 (int)ver_b, (int)ver_a);
1039 dd->dc8051_ver = dc8051_ver(ver_b, ver_a); 1060 dd->dc8051_ver = dc8051_ver(ver_b, ver_a);
1040 1061
1041 return 0; 1062 return 0;
@@ -1050,11 +1071,11 @@ void sbus_request(struct hfi1_devdata *dd,
1050 u8 receiver_addr, u8 data_addr, u8 command, u32 data_in) 1071 u8 receiver_addr, u8 data_addr, u8 command, u32 data_in)
1051{ 1072{
1052 write_csr(dd, ASIC_CFG_SBUS_REQUEST, 1073 write_csr(dd, ASIC_CFG_SBUS_REQUEST,
1053 ((u64)data_in << ASIC_CFG_SBUS_REQUEST_DATA_IN_SHIFT) 1074 ((u64)data_in << ASIC_CFG_SBUS_REQUEST_DATA_IN_SHIFT) |
1054 | ((u64)command << ASIC_CFG_SBUS_REQUEST_COMMAND_SHIFT) 1075 ((u64)command << ASIC_CFG_SBUS_REQUEST_COMMAND_SHIFT) |
1055 | ((u64)data_addr << ASIC_CFG_SBUS_REQUEST_DATA_ADDR_SHIFT) 1076 ((u64)data_addr << ASIC_CFG_SBUS_REQUEST_DATA_ADDR_SHIFT) |
1056 | ((u64)receiver_addr 1077 ((u64)receiver_addr <<
1057 << ASIC_CFG_SBUS_REQUEST_RECEIVER_ADDR_SHIFT)); 1078 ASIC_CFG_SBUS_REQUEST_RECEIVER_ADDR_SHIFT));
1058} 1079}
1059 1080
1060/* 1081/*
@@ -1072,14 +1093,14 @@ static void turn_off_spicos(struct hfi1_devdata *dd, int flags)
1072 return; 1093 return;
1073 1094
1074 dd_dev_info(dd, "Turning off spicos:%s%s\n", 1095 dd_dev_info(dd, "Turning off spicos:%s%s\n",
1075 flags & SPICO_SBUS ? " SBus" : "", 1096 flags & SPICO_SBUS ? " SBus" : "",
1076 flags & SPICO_FABRIC ? " fabric" : ""); 1097 flags & SPICO_FABRIC ? " fabric" : "");
1077 1098
1078 write_csr(dd, MISC_CFG_FW_CTRL, ENABLE_SPICO_SMASK); 1099 write_csr(dd, MISC_CFG_FW_CTRL, ENABLE_SPICO_SMASK);
1079 /* disable SBus spico */ 1100 /* disable SBus spico */
1080 if (flags & SPICO_SBUS) 1101 if (flags & SPICO_SBUS)
1081 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01, 1102 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01,
1082 WRITE_SBUS_RECEIVER, 0x00000040); 1103 WRITE_SBUS_RECEIVER, 0x00000040);
1083 1104
1084 /* disable the fabric serdes spicos */ 1105 /* disable the fabric serdes spicos */
1085 if (flags & SPICO_FABRIC) 1106 if (flags & SPICO_FABRIC)
@@ -1089,29 +1110,60 @@ static void turn_off_spicos(struct hfi1_devdata *dd, int flags)
1089} 1110}
1090 1111
1091/* 1112/*
1092 * Reset all of the fabric serdes for our HFI. 1113 * Reset all of the fabric serdes for this HFI in preparation to take the
1114 * link to Polling.
1115 *
1116 * To do a reset, we need to write to to the serdes registers. Unfortunately,
1117 * the fabric serdes download to the other HFI on the ASIC will have turned
1118 * off the firmware validation on this HFI. This means we can't write to the
1119 * registers to reset the serdes. Work around this by performing a complete
1120 * re-download and validation of the fabric serdes firmware. This, as a
1121 * by-product, will reset the serdes. NOTE: the re-download requires that
1122 * the 8051 be in the Offline state. I.e. not actively trying to use the
1123 * serdes. This routine is called at the point where the link is Offline and
1124 * is getting ready to go to Polling.
1093 */ 1125 */
1094void fabric_serdes_reset(struct hfi1_devdata *dd) 1126void fabric_serdes_reset(struct hfi1_devdata *dd)
1095{ 1127{
1096 u8 ra; 1128 int ret;
1097 1129
1098 if (dd->icode != ICODE_RTL_SILICON) /* only for RTL */ 1130 if (!fw_fabric_serdes_load)
1099 return; 1131 return;
1100 1132
1101 ra = fabric_serdes_broadcast[dd->hfi1_id]; 1133 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1102 1134 if (ret) {
1103 acquire_hw_mutex(dd); 1135 dd_dev_err(dd,
1136 "Cannot acquire SBus resource to reset fabric SerDes - perhaps you should reboot\n");
1137 return;
1138 }
1104 set_sbus_fast_mode(dd); 1139 set_sbus_fast_mode(dd);
1105 /* place SerDes in reset and disable SPICO */ 1140
1106 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000011); 1141 if (is_ax(dd)) {
1107 /* wait 100 refclk cycles @ 156.25MHz => 640ns */ 1142 /* A0 serdes do not work with a re-download */
1108 udelay(1); 1143 u8 ra = fabric_serdes_broadcast[dd->hfi1_id];
1109 /* remove SerDes reset */ 1144
1110 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000010); 1145 /* place SerDes in reset and disable SPICO */
1111 /* turn SPICO enable on */ 1146 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000011);
1112 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000002); 1147 /* wait 100 refclk cycles @ 156.25MHz => 640ns */
1148 udelay(1);
1149 /* remove SerDes reset */
1150 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000010);
1151 /* turn SPICO enable on */
1152 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000002);
1153 } else {
1154 turn_off_spicos(dd, SPICO_FABRIC);
1155 /*
1156 * No need for firmware retry - what to download has already
1157 * been decided.
1158 * No need to pay attention to the load return - the only
1159 * failure is a validation failure, which has already been
1160 * checked by the initial download.
1161 */
1162 (void)load_fabric_serdes_firmware(dd, &fw_fabric);
1163 }
1164
1113 clear_sbus_fast_mode(dd); 1165 clear_sbus_fast_mode(dd);
1114 release_hw_mutex(dd); 1166 release_chip_resource(dd, CR_SBUS);
1115} 1167}
1116 1168
1117/* Access to the SBus in this routine should probably be serialized */ 1169/* Access to the SBus in this routine should probably be serialized */
@@ -1120,6 +1172,9 @@ int sbus_request_slow(struct hfi1_devdata *dd,
1120{ 1172{
1121 u64 reg, count = 0; 1173 u64 reg, count = 0;
1122 1174
1175 /* make sure fast mode is clear */
1176 clear_sbus_fast_mode(dd);
1177
1123 sbus_request(dd, receiver_addr, data_addr, command, data_in); 1178 sbus_request(dd, receiver_addr, data_addr, command, data_in);
1124 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 1179 write_csr(dd, ASIC_CFG_SBUS_EXECUTE,
1125 ASIC_CFG_SBUS_EXECUTE_EXECUTE_SMASK); 1180 ASIC_CFG_SBUS_EXECUTE_EXECUTE_SMASK);
@@ -1177,7 +1232,7 @@ static int load_fabric_serdes_firmware(struct hfi1_devdata *dd,
1177 /* step 5: download SerDes machine code */ 1232 /* step 5: download SerDes machine code */
1178 for (i = 0; i < fdet->firmware_len; i += 4) { 1233 for (i = 0; i < fdet->firmware_len; i += 4) {
1179 sbus_request(dd, ra, 0x0a, WRITE_SBUS_RECEIVER, 1234 sbus_request(dd, ra, 0x0a, WRITE_SBUS_RECEIVER,
1180 *(u32 *)&fdet->firmware_ptr[i]); 1235 *(u32 *)&fdet->firmware_ptr[i]);
1181 } 1236 }
1182 /* step 6: IMEM override off */ 1237 /* step 6: IMEM override off */
1183 sbus_request(dd, ra, 0x00, WRITE_SBUS_RECEIVER, 0x00000000); 1238 sbus_request(dd, ra, 0x00, WRITE_SBUS_RECEIVER, 0x00000000);
@@ -1216,7 +1271,7 @@ static int load_sbus_firmware(struct hfi1_devdata *dd,
1216 /* step 5: download the SBus Master machine code */ 1271 /* step 5: download the SBus Master machine code */
1217 for (i = 0; i < fdet->firmware_len; i += 4) { 1272 for (i = 0; i < fdet->firmware_len; i += 4) {
1218 sbus_request(dd, ra, 0x14, WRITE_SBUS_RECEIVER, 1273 sbus_request(dd, ra, 0x14, WRITE_SBUS_RECEIVER,
1219 *(u32 *)&fdet->firmware_ptr[i]); 1274 *(u32 *)&fdet->firmware_ptr[i]);
1220 } 1275 }
1221 /* step 6: set IMEM_CNTL_EN off */ 1276 /* step 6: set IMEM_CNTL_EN off */
1222 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000040); 1277 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000040);
@@ -1249,19 +1304,23 @@ static int load_pcie_serdes_firmware(struct hfi1_devdata *dd,
1249 /* step 3: enable XDMEM access */ 1304 /* step 3: enable XDMEM access */
1250 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000d40); 1305 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000d40);
1251 /* step 4: load firmware into SBus Master XDMEM */ 1306 /* step 4: load firmware into SBus Master XDMEM */
1252 /* NOTE: the dmem address, write_en, and wdata are all pre-packed, 1307 /*
1253 we only need to pick up the bytes and write them */ 1308 * NOTE: the dmem address, write_en, and wdata are all pre-packed,
1309 * we only need to pick up the bytes and write them
1310 */
1254 for (i = 0; i < fdet->firmware_len; i += 4) { 1311 for (i = 0; i < fdet->firmware_len; i += 4) {
1255 sbus_request(dd, ra, 0x04, WRITE_SBUS_RECEIVER, 1312 sbus_request(dd, ra, 0x04, WRITE_SBUS_RECEIVER,
1256 *(u32 *)&fdet->firmware_ptr[i]); 1313 *(u32 *)&fdet->firmware_ptr[i]);
1257 } 1314 }
1258 /* step 5: disable XDMEM access */ 1315 /* step 5: disable XDMEM access */
1259 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000140); 1316 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000140);
1260 /* step 6: allow SBus Spico to run */ 1317 /* step 6: allow SBus Spico to run */
1261 sbus_request(dd, ra, 0x05, WRITE_SBUS_RECEIVER, 0x00000000); 1318 sbus_request(dd, ra, 0x05, WRITE_SBUS_RECEIVER, 0x00000000);
1262 1319
1263 /* steps 7-11: run RSA, if it succeeds, firmware is available to 1320 /*
1264 be swapped */ 1321 * steps 7-11: run RSA, if it succeeds, firmware is available to
1322 * be swapped
1323 */
1265 return run_rsa(dd, "PCIe serdes", fdet->signature); 1324 return run_rsa(dd, "PCIe serdes", fdet->signature);
1266} 1325}
1267 1326
@@ -1285,7 +1344,7 @@ static void set_serdes_broadcast(struct hfi1_devdata *dd, u8 bg1, u8 bg2,
1285 * 23:16 BROADCAST_GROUP_2 (default 0xff) 1344 * 23:16 BROADCAST_GROUP_2 (default 0xff)
1286 */ 1345 */
1287 sbus_request(dd, addrs[count], 0xfd, WRITE_SBUS_RECEIVER, 1346 sbus_request(dd, addrs[count], 0xfd, WRITE_SBUS_RECEIVER,
1288 (u32)bg1 << 4 | (u32)bg2 << 16); 1347 (u32)bg1 << 4 | (u32)bg2 << 16);
1289 } 1348 }
1290} 1349}
1291 1350
@@ -1310,8 +1369,8 @@ retry:
1310 1369
1311 /* timed out */ 1370 /* timed out */
1312 dd_dev_err(dd, 1371 dd_dev_err(dd,
1313 "Unable to acquire hardware mutex, mutex mask %u, my mask %u (%s)\n", 1372 "Unable to acquire hardware mutex, mutex mask %u, my mask %u (%s)\n",
1314 (u32)user, (u32)mask, (try == 0) ? "retrying" : "giving up"); 1373 (u32)user, (u32)mask, (try == 0) ? "retrying" : "giving up");
1315 1374
1316 if (try == 0) { 1375 if (try == 0) {
1317 /* break mutex and retry */ 1376 /* break mutex and retry */
@@ -1328,10 +1387,197 @@ void release_hw_mutex(struct hfi1_devdata *dd)
1328 write_csr(dd, ASIC_CFG_MUTEX, 0); 1387 write_csr(dd, ASIC_CFG_MUTEX, 0);
1329} 1388}
1330 1389
1390/* return the given resource bit(s) as a mask for the given HFI */
1391static inline u64 resource_mask(u32 hfi1_id, u32 resource)
1392{
1393 return ((u64)resource) << (hfi1_id ? CR_DYN_SHIFT : 0);
1394}
1395
1396static void fail_mutex_acquire_message(struct hfi1_devdata *dd,
1397 const char *func)
1398{
1399 dd_dev_err(dd,
1400 "%s: hardware mutex stuck - suggest rebooting the machine\n",
1401 func);
1402}
1403
1404/*
1405 * Acquire access to a chip resource.
1406 *
1407 * Return 0 on success, -EBUSY if resource busy, -EIO if mutex acquire failed.
1408 */
1409static int __acquire_chip_resource(struct hfi1_devdata *dd, u32 resource)
1410{
1411 u64 scratch0, all_bits, my_bit;
1412 int ret;
1413
1414 if (resource & CR_DYN_MASK) {
1415 /* a dynamic resource is in use if either HFI has set the bit */
1416 all_bits = resource_mask(0, resource) |
1417 resource_mask(1, resource);
1418 my_bit = resource_mask(dd->hfi1_id, resource);
1419 } else {
1420 /* non-dynamic resources are not split between HFIs */
1421 all_bits = resource;
1422 my_bit = resource;
1423 }
1424
1425 /* lock against other callers within the driver wanting a resource */
1426 mutex_lock(&dd->asic_data->asic_resource_mutex);
1427
1428 ret = acquire_hw_mutex(dd);
1429 if (ret) {
1430 fail_mutex_acquire_message(dd, __func__);
1431 ret = -EIO;
1432 goto done;
1433 }
1434
1435 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1436 if (scratch0 & all_bits) {
1437 ret = -EBUSY;
1438 } else {
1439 write_csr(dd, ASIC_CFG_SCRATCH, scratch0 | my_bit);
1440 /* force write to be visible to other HFI on another OS */
1441 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1442 }
1443
1444 release_hw_mutex(dd);
1445
1446done:
1447 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1448 return ret;
1449}
1450
1451/*
1452 * Acquire access to a chip resource, wait up to mswait milliseconds for
1453 * the resource to become available.
1454 *
1455 * Return 0 on success, -EBUSY if busy (even after wait), -EIO if mutex
1456 * acquire failed.
1457 */
1458int acquire_chip_resource(struct hfi1_devdata *dd, u32 resource, u32 mswait)
1459{
1460 unsigned long timeout;
1461 int ret;
1462
1463 timeout = jiffies + msecs_to_jiffies(mswait);
1464 while (1) {
1465 ret = __acquire_chip_resource(dd, resource);
1466 if (ret != -EBUSY)
1467 return ret;
1468 /* resource is busy, check our timeout */
1469 if (time_after_eq(jiffies, timeout))
1470 return -EBUSY;
1471 usleep_range(80, 120); /* arbitrary delay */
1472 }
1473}
1474
1475/*
1476 * Release access to a chip resource
1477 */
1478void release_chip_resource(struct hfi1_devdata *dd, u32 resource)
1479{
1480 u64 scratch0, bit;
1481
1482 /* only dynamic resources should ever be cleared */
1483 if (!(resource & CR_DYN_MASK)) {
1484 dd_dev_err(dd, "%s: invalid resource 0x%x\n", __func__,
1485 resource);
1486 return;
1487 }
1488 bit = resource_mask(dd->hfi1_id, resource);
1489
1490 /* lock against other callers within the driver wanting a resource */
1491 mutex_lock(&dd->asic_data->asic_resource_mutex);
1492
1493 if (acquire_hw_mutex(dd)) {
1494 fail_mutex_acquire_message(dd, __func__);
1495 goto done;
1496 }
1497
1498 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1499 if ((scratch0 & bit) != 0) {
1500 scratch0 &= ~bit;
1501 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
1502 /* force write to be visible to other HFI on another OS */
1503 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1504 } else {
1505 dd_dev_warn(dd, "%s: id %d, resource 0x%x: bit not set\n",
1506 __func__, dd->hfi1_id, resource);
1507 }
1508
1509 release_hw_mutex(dd);
1510
1511done:
1512 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1513}
1514
1515/*
1516 * Return true if resource is set, false otherwise. Print a warning
1517 * if not set and a function is supplied.
1518 */
1519bool check_chip_resource(struct hfi1_devdata *dd, u32 resource,
1520 const char *func)
1521{
1522 u64 scratch0, bit;
1523
1524 if (resource & CR_DYN_MASK)
1525 bit = resource_mask(dd->hfi1_id, resource);
1526 else
1527 bit = resource;
1528
1529 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1530 if ((scratch0 & bit) == 0) {
1531 if (func)
1532 dd_dev_warn(dd,
1533 "%s: id %d, resource 0x%x, not acquired!\n",
1534 func, dd->hfi1_id, resource);
1535 return false;
1536 }
1537 return true;
1538}
1539
1540static void clear_chip_resources(struct hfi1_devdata *dd, const char *func)
1541{
1542 u64 scratch0;
1543
1544 /* lock against other callers within the driver wanting a resource */
1545 mutex_lock(&dd->asic_data->asic_resource_mutex);
1546
1547 if (acquire_hw_mutex(dd)) {
1548 fail_mutex_acquire_message(dd, func);
1549 goto done;
1550 }
1551
1552 /* clear all dynamic access bits for this HFI */
1553 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1554 scratch0 &= ~resource_mask(dd->hfi1_id, CR_DYN_MASK);
1555 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
1556 /* force write to be visible to other HFI on another OS */
1557 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1558
1559 release_hw_mutex(dd);
1560
1561done:
1562 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1563}
1564
1565void init_chip_resources(struct hfi1_devdata *dd)
1566{
1567 /* clear any holds left by us */
1568 clear_chip_resources(dd, __func__);
1569}
1570
1571void finish_chip_resources(struct hfi1_devdata *dd)
1572{
1573 /* clear any holds left by us */
1574 clear_chip_resources(dd, __func__);
1575}
1576
1331void set_sbus_fast_mode(struct hfi1_devdata *dd) 1577void set_sbus_fast_mode(struct hfi1_devdata *dd)
1332{ 1578{
1333 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 1579 write_csr(dd, ASIC_CFG_SBUS_EXECUTE,
1334 ASIC_CFG_SBUS_EXECUTE_FAST_MODE_SMASK); 1580 ASIC_CFG_SBUS_EXECUTE_FAST_MODE_SMASK);
1335} 1581}
1336 1582
1337void clear_sbus_fast_mode(struct hfi1_devdata *dd) 1583void clear_sbus_fast_mode(struct hfi1_devdata *dd)
@@ -1354,23 +1600,23 @@ int load_firmware(struct hfi1_devdata *dd)
1354 int ret; 1600 int ret;
1355 1601
1356 if (fw_fabric_serdes_load) { 1602 if (fw_fabric_serdes_load) {
1357 ret = acquire_hw_mutex(dd); 1603 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1358 if (ret) 1604 if (ret)
1359 return ret; 1605 return ret;
1360 1606
1361 set_sbus_fast_mode(dd); 1607 set_sbus_fast_mode(dd);
1362 1608
1363 set_serdes_broadcast(dd, all_fabric_serdes_broadcast, 1609 set_serdes_broadcast(dd, all_fabric_serdes_broadcast,
1364 fabric_serdes_broadcast[dd->hfi1_id], 1610 fabric_serdes_broadcast[dd->hfi1_id],
1365 fabric_serdes_addrs[dd->hfi1_id], 1611 fabric_serdes_addrs[dd->hfi1_id],
1366 NUM_FABRIC_SERDES); 1612 NUM_FABRIC_SERDES);
1367 turn_off_spicos(dd, SPICO_FABRIC); 1613 turn_off_spicos(dd, SPICO_FABRIC);
1368 do { 1614 do {
1369 ret = load_fabric_serdes_firmware(dd, &fw_fabric); 1615 ret = load_fabric_serdes_firmware(dd, &fw_fabric);
1370 } while (retry_firmware(dd, ret)); 1616 } while (retry_firmware(dd, ret));
1371 1617
1372 clear_sbus_fast_mode(dd); 1618 clear_sbus_fast_mode(dd);
1373 release_hw_mutex(dd); 1619 release_chip_resource(dd, CR_SBUS);
1374 if (ret) 1620 if (ret)
1375 return ret; 1621 return ret;
1376 } 1622 }
@@ -1419,18 +1665,57 @@ int hfi1_firmware_init(struct hfi1_devdata *dd)
1419 return obtain_firmware(dd); 1665 return obtain_firmware(dd);
1420} 1666}
1421 1667
1668/*
1669 * This function is a helper function for parse_platform_config(...) and
1670 * does not check for validity of the platform configuration cache
1671 * (because we know it is invalid as we are building up the cache).
1672 * As such, this should not be called from anywhere other than
1673 * parse_platform_config
1674 */
1675static int check_meta_version(struct hfi1_devdata *dd, u32 *system_table)
1676{
1677 u32 meta_ver, meta_ver_meta, ver_start, ver_len, mask;
1678 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1679
1680 if (!system_table)
1681 return -EINVAL;
1682
1683 meta_ver_meta =
1684 *(pcfgcache->config_tables[PLATFORM_CONFIG_SYSTEM_TABLE].table_metadata
1685 + SYSTEM_TABLE_META_VERSION);
1686
1687 mask = ((1 << METADATA_TABLE_FIELD_START_LEN_BITS) - 1);
1688 ver_start = meta_ver_meta & mask;
1689
1690 meta_ver_meta >>= METADATA_TABLE_FIELD_LEN_SHIFT;
1691
1692 mask = ((1 << METADATA_TABLE_FIELD_LEN_LEN_BITS) - 1);
1693 ver_len = meta_ver_meta & mask;
1694
1695 ver_start /= 8;
1696 meta_ver = *((u8 *)system_table + ver_start) & ((1 << ver_len) - 1);
1697
1698 if (meta_ver < 5) {
1699 dd_dev_info(
1700 dd, "%s:Please update platform config\n", __func__);
1701 return -EINVAL;
1702 }
1703 return 0;
1704}
1705
1422int parse_platform_config(struct hfi1_devdata *dd) 1706int parse_platform_config(struct hfi1_devdata *dd)
1423{ 1707{
1424 struct platform_config_cache *pcfgcache = &dd->pcfg_cache; 1708 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1425 u32 *ptr = NULL; 1709 u32 *ptr = NULL;
1426 u32 header1 = 0, header2 = 0, magic_num = 0, crc = 0; 1710 u32 header1 = 0, header2 = 0, magic_num = 0, crc = 0, file_length = 0;
1427 u32 record_idx = 0, table_type = 0, table_length_dwords = 0; 1711 u32 record_idx = 0, table_type = 0, table_length_dwords = 0;
1712 int ret = -EINVAL; /* assume failure */
1428 1713
1429 if (platform_config == NULL) { 1714 if (!dd->platform_config.data) {
1430 dd_dev_info(dd, "%s: Missing config file\n", __func__); 1715 dd_dev_info(dd, "%s: Missing config file\n", __func__);
1431 goto bail; 1716 goto bail;
1432 } 1717 }
1433 ptr = (u32 *)platform_config->data; 1718 ptr = (u32 *)dd->platform_config.data;
1434 1719
1435 magic_num = *ptr; 1720 magic_num = *ptr;
1436 ptr++; 1721 ptr++;
@@ -1439,12 +1724,32 @@ int parse_platform_config(struct hfi1_devdata *dd)
1439 goto bail; 1724 goto bail;
1440 } 1725 }
1441 1726
1442 while (ptr < (u32 *)(platform_config->data + platform_config->size)) { 1727 /* Field is file size in DWORDs */
1728 file_length = (*ptr) * 4;
1729 ptr++;
1730
1731 if (file_length > dd->platform_config.size) {
1732 dd_dev_info(dd, "%s:File claims to be larger than read size\n",
1733 __func__);
1734 goto bail;
1735 } else if (file_length < dd->platform_config.size) {
1736 dd_dev_info(dd,
1737 "%s:File claims to be smaller than read size, continuing\n",
1738 __func__);
1739 }
1740 /* exactly equal, perfection */
1741
1742 /*
1743 * In both cases where we proceed, using the self-reported file length
1744 * is the safer option
1745 */
1746 while (ptr < (u32 *)(dd->platform_config.data + file_length)) {
1443 header1 = *ptr; 1747 header1 = *ptr;
1444 header2 = *(ptr + 1); 1748 header2 = *(ptr + 1);
1445 if (header1 != ~header2) { 1749 if (header1 != ~header2) {
1446 dd_dev_info(dd, "%s: Failed validation at offset %ld\n", 1750 dd_dev_info(dd, "%s: Failed validation at offset %ld\n",
1447 __func__, (ptr - (u32 *)platform_config->data)); 1751 __func__, (ptr - (u32 *)
1752 dd->platform_config.data));
1448 goto bail; 1753 goto bail;
1449 } 1754 }
1450 1755
@@ -1467,6 +1772,9 @@ int parse_platform_config(struct hfi1_devdata *dd)
1467 case PLATFORM_CONFIG_SYSTEM_TABLE: 1772 case PLATFORM_CONFIG_SYSTEM_TABLE:
1468 pcfgcache->config_tables[table_type].num_table = 1773 pcfgcache->config_tables[table_type].num_table =
1469 1; 1774 1;
1775 ret = check_meta_version(dd, ptr);
1776 if (ret)
1777 goto bail;
1470 break; 1778 break;
1471 case PLATFORM_CONFIG_PORT_TABLE: 1779 case PLATFORM_CONFIG_PORT_TABLE:
1472 pcfgcache->config_tables[table_type].num_table = 1780 pcfgcache->config_tables[table_type].num_table =
@@ -1484,9 +1792,10 @@ int parse_platform_config(struct hfi1_devdata *dd)
1484 break; 1792 break;
1485 default: 1793 default:
1486 dd_dev_info(dd, 1794 dd_dev_info(dd,
1487 "%s: Unknown data table %d, offset %ld\n", 1795 "%s: Unknown data table %d, offset %ld\n",
1488 __func__, table_type, 1796 __func__, table_type,
1489 (ptr - (u32 *)platform_config->data)); 1797 (ptr - (u32 *)
1798 dd->platform_config.data));
1490 goto bail; /* We don't trust this file now */ 1799 goto bail; /* We don't trust this file now */
1491 } 1800 }
1492 pcfgcache->config_tables[table_type].table = ptr; 1801 pcfgcache->config_tables[table_type].table = ptr;
@@ -1507,9 +1816,10 @@ int parse_platform_config(struct hfi1_devdata *dd)
1507 break; 1816 break;
1508 default: 1817 default:
1509 dd_dev_info(dd, 1818 dd_dev_info(dd,
1510 "%s: Unknown metadata table %d, offset %ld\n", 1819 "%s: Unknown meta table %d, offset %ld\n",
1511 __func__, table_type, 1820 __func__, table_type,
1512 (ptr - (u32 *)platform_config->data)); 1821 (ptr -
1822 (u32 *)dd->platform_config.data));
1513 goto bail; /* We don't trust this file now */ 1823 goto bail; /* We don't trust this file now */
1514 } 1824 }
1515 pcfgcache->config_tables[table_type].table_metadata = 1825 pcfgcache->config_tables[table_type].table_metadata =
@@ -1518,14 +1828,16 @@ int parse_platform_config(struct hfi1_devdata *dd)
1518 1828
1519 /* Calculate and check table crc */ 1829 /* Calculate and check table crc */
1520 crc = crc32_le(~(u32)0, (unsigned char const *)ptr, 1830 crc = crc32_le(~(u32)0, (unsigned char const *)ptr,
1521 (table_length_dwords * 4)); 1831 (table_length_dwords * 4));
1522 crc ^= ~(u32)0; 1832 crc ^= ~(u32)0;
1523 1833
1524 /* Jump the table */ 1834 /* Jump the table */
1525 ptr += table_length_dwords; 1835 ptr += table_length_dwords;
1526 if (crc != *ptr) { 1836 if (crc != *ptr) {
1527 dd_dev_info(dd, "%s: Failed CRC check at offset %ld\n", 1837 dd_dev_info(dd, "%s: Failed CRC check at offset %ld\n",
1528 __func__, (ptr - (u32 *)platform_config->data)); 1838 __func__, (ptr -
1839 (u32 *)
1840 dd->platform_config.data));
1529 goto bail; 1841 goto bail;
1530 } 1842 }
1531 /* Jump the CRC DWORD */ 1843 /* Jump the CRC DWORD */
@@ -1536,11 +1848,12 @@ int parse_platform_config(struct hfi1_devdata *dd)
1536 return 0; 1848 return 0;
1537bail: 1849bail:
1538 memset(pcfgcache, 0, sizeof(struct platform_config_cache)); 1850 memset(pcfgcache, 0, sizeof(struct platform_config_cache));
1539 return -EINVAL; 1851 return ret;
1540} 1852}
1541 1853
1542static int get_platform_fw_field_metadata(struct hfi1_devdata *dd, int table, 1854static int get_platform_fw_field_metadata(struct hfi1_devdata *dd, int table,
1543 int field, u32 *field_len_bits, u32 *field_start_bits) 1855 int field, u32 *field_len_bits,
1856 u32 *field_start_bits)
1544{ 1857{
1545 struct platform_config_cache *pcfgcache = &dd->pcfg_cache; 1858 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1546 u32 *src_ptr = NULL; 1859 u32 *src_ptr = NULL;
@@ -1600,8 +1913,9 @@ static int get_platform_fw_field_metadata(struct hfi1_devdata *dd, int table,
1600 * @len: length of memory pointed by @data in bytes. 1913 * @len: length of memory pointed by @data in bytes.
1601 */ 1914 */
1602int get_platform_config_field(struct hfi1_devdata *dd, 1915int get_platform_config_field(struct hfi1_devdata *dd,
1603 enum platform_config_table_type_encoding table_type, 1916 enum platform_config_table_type_encoding
1604 int table_index, int field_index, u32 *data, u32 len) 1917 table_type, int table_index, int field_index,
1918 u32 *data, u32 len)
1605{ 1919{
1606 int ret = 0, wlen = 0, seek = 0; 1920 int ret = 0, wlen = 0, seek = 0;
1607 u32 field_len_bits = 0, field_start_bits = 0, *src_ptr = NULL; 1921 u32 field_len_bits = 0, field_start_bits = 0, *src_ptr = NULL;
@@ -1613,7 +1927,8 @@ int get_platform_config_field(struct hfi1_devdata *dd,
1613 return -EINVAL; 1927 return -EINVAL;
1614 1928
1615 ret = get_platform_fw_field_metadata(dd, table_type, field_index, 1929 ret = get_platform_fw_field_metadata(dd, table_type, field_index,
1616 &field_len_bits, &field_start_bits); 1930 &field_len_bits,
1931 &field_start_bits);
1617 if (ret) 1932 if (ret)
1618 return -EINVAL; 1933 return -EINVAL;
1619 1934
@@ -1629,19 +1944,21 @@ int get_platform_config_field(struct hfi1_devdata *dd,
1629 if (len < field_len_bits) 1944 if (len < field_len_bits)
1630 return -EINVAL; 1945 return -EINVAL;
1631 1946
1632 seek = field_start_bits/8; 1947 seek = field_start_bits / 8;
1633 wlen = field_len_bits/8; 1948 wlen = field_len_bits / 8;
1634 1949
1635 src_ptr = (u32 *)((u8 *)src_ptr + seek); 1950 src_ptr = (u32 *)((u8 *)src_ptr + seek);
1636 1951
1637 /* We expect the field to be byte aligned and whole byte 1952 /*
1638 * lengths if we are here */ 1953 * We expect the field to be byte aligned and whole byte
1954 * lengths if we are here
1955 */
1639 memcpy(data, src_ptr, wlen); 1956 memcpy(data, src_ptr, wlen);
1640 return 0; 1957 return 0;
1641 } 1958 }
1642 break; 1959 break;
1643 case PLATFORM_CONFIG_PORT_TABLE: 1960 case PLATFORM_CONFIG_PORT_TABLE:
1644 /* Port table is 4 DWORDS in META_VERSION 0 */ 1961 /* Port table is 4 DWORDS */
1645 src_ptr = dd->hfi1_id ? 1962 src_ptr = dd->hfi1_id ?
1646 pcfgcache->config_tables[table_type].table + 4 : 1963 pcfgcache->config_tables[table_type].table + 4 :
1647 pcfgcache->config_tables[table_type].table; 1964 pcfgcache->config_tables[table_type].table;
@@ -1669,7 +1986,7 @@ int get_platform_config_field(struct hfi1_devdata *dd,
1669 if (!src_ptr || len < field_len_bits) 1986 if (!src_ptr || len < field_len_bits)
1670 return -EINVAL; 1987 return -EINVAL;
1671 1988
1672 src_ptr += (field_start_bits/32); 1989 src_ptr += (field_start_bits / 32);
1673 *data = (*src_ptr >> (field_start_bits % 32)) & 1990 *data = (*src_ptr >> (field_start_bits % 32)) &
1674 ((1 << field_len_bits) - 1); 1991 ((1 << field_len_bits) - 1);
1675 1992
@@ -1680,7 +1997,7 @@ int get_platform_config_field(struct hfi1_devdata *dd,
1680 * Download the firmware needed for the Gen3 PCIe SerDes. An update 1997 * Download the firmware needed for the Gen3 PCIe SerDes. An update
1681 * to the SBus firmware is needed before updating the PCIe firmware. 1998 * to the SBus firmware is needed before updating the PCIe firmware.
1682 * 1999 *
1683 * Note: caller must be holding the HW mutex. 2000 * Note: caller must be holding the SBus resource.
1684 */ 2001 */
1685int load_pcie_firmware(struct hfi1_devdata *dd) 2002int load_pcie_firmware(struct hfi1_devdata *dd)
1686{ 2003{
@@ -1701,9 +2018,9 @@ int load_pcie_firmware(struct hfi1_devdata *dd)
1701 if (fw_pcie_serdes_load) { 2018 if (fw_pcie_serdes_load) {
1702 dd_dev_info(dd, "Setting PCIe SerDes broadcast\n"); 2019 dd_dev_info(dd, "Setting PCIe SerDes broadcast\n");
1703 set_serdes_broadcast(dd, all_pcie_serdes_broadcast, 2020 set_serdes_broadcast(dd, all_pcie_serdes_broadcast,
1704 pcie_serdes_broadcast[dd->hfi1_id], 2021 pcie_serdes_broadcast[dd->hfi1_id],
1705 pcie_serdes_addrs[dd->hfi1_id], 2022 pcie_serdes_addrs[dd->hfi1_id],
1706 NUM_PCIE_SERDES); 2023 NUM_PCIE_SERDES);
1707 do { 2024 do {
1708 ret = load_pcie_serdes_firmware(dd, &fw_pcie); 2025 ret = load_pcie_serdes_firmware(dd, &fw_pcie);
1709 } while (retry_firmware(dd, ret)); 2026 } while (retry_firmware(dd, ret));
@@ -1724,9 +2041,9 @@ void read_guid(struct hfi1_devdata *dd)
1724{ 2041{
1725 /* Take the DC out of reset to get a valid GUID value */ 2042 /* Take the DC out of reset to get a valid GUID value */
1726 write_csr(dd, CCE_DC_CTRL, 0); 2043 write_csr(dd, CCE_DC_CTRL, 0);
1727 (void) read_csr(dd, CCE_DC_CTRL); 2044 (void)read_csr(dd, CCE_DC_CTRL);
1728 2045
1729 dd->base_guid = read_csr(dd, DC_DC8051_CFG_LOCAL_GUID); 2046 dd->base_guid = read_csr(dd, DC_DC8051_CFG_LOCAL_GUID);
1730 dd_dev_info(dd, "GUID %llx", 2047 dd_dev_info(dd, "GUID %llx",
1731 (unsigned long long)dd->base_guid); 2048 (unsigned long long)dd->base_guid);
1732} 2049}
diff --git a/drivers/staging/rdma/hfi1/hfi.h b/drivers/staging/rdma/hfi1/hfi.h
index d4826a9ab8d3..16cbdc4073e0 100644
--- a/drivers/staging/rdma/hfi1/hfi.h
+++ b/drivers/staging/rdma/hfi1/hfi.h
@@ -1,14 +1,13 @@
1#ifndef _HFI1_KERNEL_H 1#ifndef _HFI1_KERNEL_H
2#define _HFI1_KERNEL_H 2#define _HFI1_KERNEL_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -65,6 +62,7 @@
65#include <linux/cdev.h> 62#include <linux/cdev.h>
66#include <linux/delay.h> 63#include <linux/delay.h>
67#include <linux/kthread.h> 64#include <linux/kthread.h>
65#include <rdma/rdma_vt.h>
68 66
69#include "chip_registers.h" 67#include "chip_registers.h"
70#include "common.h" 68#include "common.h"
@@ -73,7 +71,8 @@
73#include "chip.h" 71#include "chip.h"
74#include "mad.h" 72#include "mad.h"
75#include "qsfp.h" 73#include "qsfp.h"
76#include "platform_config.h" 74#include "platform.h"
75#include "affinity.h"
77 76
78/* bumped 1 from s/w major version of TrueScale */ 77/* bumped 1 from s/w major version of TrueScale */
79#define HFI1_CHIP_VERS_MAJ 3U 78#define HFI1_CHIP_VERS_MAJ 3U
@@ -98,6 +97,8 @@ extern unsigned long hfi1_cap_mask;
98#define HFI1_CAP_IS_USET(cap) (!!HFI1_CAP_UGET(cap)) 97#define HFI1_CAP_IS_USET(cap) (!!HFI1_CAP_UGET(cap))
99#define HFI1_MISC_GET() ((hfi1_cap_mask >> HFI1_CAP_MISC_SHIFT) & \ 98#define HFI1_MISC_GET() ((hfi1_cap_mask >> HFI1_CAP_MISC_SHIFT) & \
100 HFI1_CAP_MISC_MASK) 99 HFI1_CAP_MISC_MASK)
100/* Offline Disabled Reason is 4-bits */
101#define HFI1_ODR_MASK(rsn) ((rsn) & OPA_PI_MASK_OFFLINE_REASON)
101 102
102/* 103/*
103 * Control context is always 0 and handles the error packets. 104 * Control context is always 0 and handles the error packets.
@@ -177,6 +178,11 @@ struct ctxt_eager_bufs {
177 } *rcvtids; 178 } *rcvtids;
178}; 179};
179 180
181struct exp_tid_set {
182 struct list_head list;
183 u32 count;
184};
185
180struct hfi1_ctxtdata { 186struct hfi1_ctxtdata {
181 /* shadow the ctxt's RcvCtrl register */ 187 /* shadow the ctxt's RcvCtrl register */
182 u64 rcvctrl; 188 u64 rcvctrl;
@@ -233,20 +239,13 @@ struct hfi1_ctxtdata {
233 u32 expected_count; 239 u32 expected_count;
234 /* index of first expected TID entry. */ 240 /* index of first expected TID entry. */
235 u32 expected_base; 241 u32 expected_base;
236 /* cursor into the exp group sets */ 242
237 atomic_t tidcursor; 243 struct exp_tid_set tid_group_list;
238 /* number of exp TID groups assigned to the ctxt */ 244 struct exp_tid_set tid_used_list;
239 u16 numtidgroups; 245 struct exp_tid_set tid_full_list;
240 /* size of exp TID group fields in tidusemap */ 246
241 u16 tidmapcnt;
242 /* exp TID group usage bitfield array */
243 unsigned long *tidusemap;
244 /* pinned pages for exp sends, allocated at open */
245 struct page **tid_pg_list;
246 /* dma handles for exp tid pages */
247 dma_addr_t *physshadow;
248 /* lock protecting all Expected TID data */ 247 /* lock protecting all Expected TID data */
249 spinlock_t exp_lock; 248 struct mutex exp_lock;
250 /* number of pio bufs for this ctxt (all procs, if shared) */ 249 /* number of pio bufs for this ctxt (all procs, if shared) */
251 u32 piocnt; 250 u32 piocnt;
252 /* first pio buffer for this ctxt */ 251 /* first pio buffer for this ctxt */
@@ -311,8 +310,24 @@ struct hfi1_ctxtdata {
311 */ 310 */
312 struct task_struct *progress; 311 struct task_struct *progress;
313 struct list_head sdma_queues; 312 struct list_head sdma_queues;
313 /* protect sdma queues */
314 spinlock_t sdma_qlock; 314 spinlock_t sdma_qlock;
315 315
316 /* Is ASPM interrupt supported for this context */
317 bool aspm_intr_supported;
318 /* ASPM state (enabled/disabled) for this context */
319 bool aspm_enabled;
320 /* Timer for re-enabling ASPM if interrupt activity quietens down */
321 struct timer_list aspm_timer;
322 /* Lock to serialize between intr, timer intr and user threads */
323 spinlock_t aspm_lock;
324 /* Is ASPM processing enabled for this context (in intr context) */
325 bool aspm_intr_enable;
326 /* Last interrupt timestamp */
327 ktime_t aspm_ts_last_intr;
328 /* Last timestamp at which we scheduled a timer for this context */
329 ktime_t aspm_ts_timer_sched;
330
316 /* 331 /*
317 * The interrupt handler for a particular receive context can vary 332 * The interrupt handler for a particular receive context can vary
318 * throughout it's lifetime. This is not a lock protected data member so 333 * throughout it's lifetime. This is not a lock protected data member so
@@ -335,7 +350,7 @@ struct hfi1_packet {
335 void *hdr; 350 void *hdr;
336 struct hfi1_ctxtdata *rcd; 351 struct hfi1_ctxtdata *rcd;
337 __le32 *rhf_addr; 352 __le32 *rhf_addr;
338 struct hfi1_qp *qp; 353 struct rvt_qp *qp;
339 struct hfi1_other_headers *ohdr; 354 struct hfi1_other_headers *ohdr;
340 u64 rhf; 355 u64 rhf;
341 u32 maxcnt; 356 u32 maxcnt;
@@ -363,6 +378,7 @@ struct hfi1_snoop_data {
363 int mode_flag; 378 int mode_flag;
364 struct cdev cdev; 379 struct cdev cdev;
365 struct device *class_dev; 380 struct device *class_dev;
381 /* protect snoop data */
366 spinlock_t snoop_lock; 382 spinlock_t snoop_lock;
367 struct list_head queue; 383 struct list_head queue;
368 wait_queue_head_t waitq; 384 wait_queue_head_t waitq;
@@ -375,7 +391,7 @@ struct hfi1_snoop_data {
375#define HFI1_PORT_SNOOP_MODE 1U 391#define HFI1_PORT_SNOOP_MODE 1U
376#define HFI1_PORT_CAPTURE_MODE 2U 392#define HFI1_PORT_CAPTURE_MODE 2U
377 393
378struct hfi1_sge_state; 394struct rvt_sge_state;
379 395
380/* 396/*
381 * Get/Set IB link-level config parameters for f_get/set_ib_cfg() 397 * Get/Set IB link-level config parameters for f_get/set_ib_cfg()
@@ -424,17 +440,17 @@ struct hfi1_sge_state;
424#define __HLS_GOING_OFFLINE_BP 9 440#define __HLS_GOING_OFFLINE_BP 9
425#define __HLS_LINK_COOLDOWN_BP 10 441#define __HLS_LINK_COOLDOWN_BP 10
426 442
427#define HLS_UP_INIT (1 << __HLS_UP_INIT_BP) 443#define HLS_UP_INIT BIT(__HLS_UP_INIT_BP)
428#define HLS_UP_ARMED (1 << __HLS_UP_ARMED_BP) 444#define HLS_UP_ARMED BIT(__HLS_UP_ARMED_BP)
429#define HLS_UP_ACTIVE (1 << __HLS_UP_ACTIVE_BP) 445#define HLS_UP_ACTIVE BIT(__HLS_UP_ACTIVE_BP)
430#define HLS_DN_DOWNDEF (1 << __HLS_DN_DOWNDEF_BP) /* link down default */ 446#define HLS_DN_DOWNDEF BIT(__HLS_DN_DOWNDEF_BP) /* link down default */
431#define HLS_DN_POLL (1 << __HLS_DN_POLL_BP) 447#define HLS_DN_POLL BIT(__HLS_DN_POLL_BP)
432#define HLS_DN_DISABLE (1 << __HLS_DN_DISABLE_BP) 448#define HLS_DN_DISABLE BIT(__HLS_DN_DISABLE_BP)
433#define HLS_DN_OFFLINE (1 << __HLS_DN_OFFLINE_BP) 449#define HLS_DN_OFFLINE BIT(__HLS_DN_OFFLINE_BP)
434#define HLS_VERIFY_CAP (1 << __HLS_VERIFY_CAP_BP) 450#define HLS_VERIFY_CAP BIT(__HLS_VERIFY_CAP_BP)
435#define HLS_GOING_UP (1 << __HLS_GOING_UP_BP) 451#define HLS_GOING_UP BIT(__HLS_GOING_UP_BP)
436#define HLS_GOING_OFFLINE (1 << __HLS_GOING_OFFLINE_BP) 452#define HLS_GOING_OFFLINE BIT(__HLS_GOING_OFFLINE_BP)
437#define HLS_LINK_COOLDOWN (1 << __HLS_LINK_COOLDOWN_BP) 453#define HLS_LINK_COOLDOWN BIT(__HLS_LINK_COOLDOWN_BP)
438 454
439#define HLS_UP (HLS_UP_INIT | HLS_UP_ARMED | HLS_UP_ACTIVE) 455#define HLS_UP (HLS_UP_INIT | HLS_UP_ARMED | HLS_UP_ACTIVE)
440 456
@@ -490,6 +506,7 @@ struct hfi1_sge_state;
490#define CNTR_DISABLED 0x2 /* Disable this counter */ 506#define CNTR_DISABLED 0x2 /* Disable this counter */
491#define CNTR_32BIT 0x4 /* Simulate 64 bits for this counter */ 507#define CNTR_32BIT 0x4 /* Simulate 64 bits for this counter */
492#define CNTR_VL 0x8 /* Per VL counter */ 508#define CNTR_VL 0x8 /* Per VL counter */
509#define CNTR_SDMA 0x10
493#define CNTR_INVALID_VL -1 /* Specifies invalid VL */ 510#define CNTR_INVALID_VL -1 /* Specifies invalid VL */
494#define CNTR_MODE_W 0x0 511#define CNTR_MODE_W 0x0
495#define CNTR_MODE_R 0x1 512#define CNTR_MODE_R 0x1
@@ -512,10 +529,11 @@ static inline void incr_cntr32(u32 *cntr)
512 529
513#define MAX_NAME_SIZE 64 530#define MAX_NAME_SIZE 64
514struct hfi1_msix_entry { 531struct hfi1_msix_entry {
532 enum irq_type type;
515 struct msix_entry msix; 533 struct msix_entry msix;
516 void *arg; 534 void *arg;
517 char name[MAX_NAME_SIZE]; 535 char name[MAX_NAME_SIZE];
518 cpumask_var_t mask; 536 cpumask_t mask;
519}; 537};
520 538
521/* per-SL CCA information */ 539/* per-SL CCA information */
@@ -542,6 +560,7 @@ enum {
542}; 560};
543 561
544struct vl_arb_cache { 562struct vl_arb_cache {
563 /* protect vl arb cache */
545 spinlock_t lock; 564 spinlock_t lock;
546 struct ib_vl_weight_elem table[VL_ARB_TABLE_SIZE]; 565 struct ib_vl_weight_elem table[VL_ARB_TABLE_SIZE];
547}; 566};
@@ -561,7 +580,8 @@ struct hfi1_pportdata {
561 struct kobject sl2sc_kobj; 580 struct kobject sl2sc_kobj;
562 struct kobject vl2mtu_kobj; 581 struct kobject vl2mtu_kobj;
563 582
564 /* QSFP support */ 583 /* PHY support */
584 u32 port_type;
565 struct qsfp_data qsfp_info; 585 struct qsfp_data qsfp_info;
566 586
567 /* GUID for this interface, in host order */ 587 /* GUID for this interface, in host order */
@@ -586,6 +606,7 @@ struct hfi1_pportdata {
586 struct work_struct link_vc_work; 606 struct work_struct link_vc_work;
587 struct work_struct link_up_work; 607 struct work_struct link_up_work;
588 struct work_struct link_down_work; 608 struct work_struct link_down_work;
609 struct work_struct dc_host_req_work;
589 struct work_struct sma_message_work; 610 struct work_struct sma_message_work;
590 struct work_struct freeze_work; 611 struct work_struct freeze_work;
591 struct work_struct link_downgrade_work; 612 struct work_struct link_downgrade_work;
@@ -623,6 +644,7 @@ struct hfi1_pportdata {
623 u16 link_speed_active; 644 u16 link_speed_active;
624 u8 vls_supported; 645 u8 vls_supported;
625 u8 vls_operational; 646 u8 vls_operational;
647 u8 actual_vls_operational;
626 /* LID mask control */ 648 /* LID mask control */
627 u8 lmc; 649 u8 lmc;
628 /* Rx Polarity inversion (compensate for ~tx on partner) */ 650 /* Rx Polarity inversion (compensate for ~tx on partner) */
@@ -642,19 +664,23 @@ struct hfi1_pportdata {
642 u8 link_enabled; /* link enabled? */ 664 u8 link_enabled; /* link enabled? */
643 u8 linkinit_reason; 665 u8 linkinit_reason;
644 u8 local_tx_rate; /* rate given to 8051 firmware */ 666 u8 local_tx_rate; /* rate given to 8051 firmware */
667 u8 last_pstate; /* info only */
645 668
646 /* placeholders for IB MAD packet settings */ 669 /* placeholders for IB MAD packet settings */
647 u8 overrun_threshold; 670 u8 overrun_threshold;
648 u8 phy_error_threshold; 671 u8 phy_error_threshold;
649 672
650 /* used to override LED behavior */ 673 /* Used to override LED behavior for things like maintenance beaconing*/
651 u8 led_override; /* Substituted for normal value, if non-zero */ 674 /*
652 u16 led_override_timeoff; /* delta to next timer event */ 675 * Alternates per phase of blink
653 u8 led_override_vals[2]; /* Alternates per blink-frame */ 676 * [0] holds LED off duration, [1] holds LED on duration
654 u8 led_override_phase; /* Just counts, LSB picks from vals[] */ 677 */
678 unsigned long led_override_vals[2];
679 u8 led_override_phase; /* LSB picks from vals[] */
655 atomic_t led_override_timer_active; 680 atomic_t led_override_timer_active;
656 /* Used to flash LEDs in override mode */ 681 /* Used to flash LEDs in override mode */
657 struct timer_list led_override_timer; 682 struct timer_list led_override_timer;
683
658 u32 sm_trap_qp; 684 u32 sm_trap_qp;
659 u32 sa_qp; 685 u32 sa_qp;
660 686
@@ -689,10 +715,12 @@ struct hfi1_pportdata {
689 /* CA's max number of 64 entry units in the congestion control table */ 715 /* CA's max number of 64 entry units in the congestion control table */
690 u8 cc_max_table_entries; 716 u8 cc_max_table_entries;
691 717
692 /* begin congestion log related entries 718 /*
693 * cc_log_lock protects all congestion log related data */ 719 * begin congestion log related entries
720 * cc_log_lock protects all congestion log related data
721 */
694 spinlock_t cc_log_lock ____cacheline_aligned_in_smp; 722 spinlock_t cc_log_lock ____cacheline_aligned_in_smp;
695 u8 threshold_cong_event_map[OPA_MAX_SLS/8]; 723 u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
696 u16 threshold_event_counter; 724 u16 threshold_event_counter;
697 struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS]; 725 struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS];
698 int cc_log_idx; /* index for logging events */ 726 int cc_log_idx; /* index for logging events */
@@ -705,8 +733,9 @@ struct hfi1_pportdata {
705 u64 *cntrs; 733 u64 *cntrs;
706 /* port relative synthetic counter buffer */ 734 /* port relative synthetic counter buffer */
707 u64 *scntrs; 735 u64 *scntrs;
708 /* we synthesize port_xmit_discards from several egress errors */ 736 /* port_xmit_discards are synthesized from different egress errors */
709 u64 port_xmit_discards; 737 u64 port_xmit_discards;
738 u64 port_xmit_discards_vl[C_VL_COUNT];
710 u64 port_xmit_constraint_errors; 739 u64 port_xmit_constraint_errors;
711 u64 port_rcv_constraint_errors; 740 u64 port_rcv_constraint_errors;
712 /* count of 'link_err' interrupts from DC */ 741 /* count of 'link_err' interrupts from DC */
@@ -728,6 +757,9 @@ struct hfi1_pportdata {
728 u8 remote_link_down_reason; 757 u8 remote_link_down_reason;
729 /* Error events that will cause a port bounce. */ 758 /* Error events that will cause a port bounce. */
730 u32 port_error_action; 759 u32 port_error_action;
760 struct work_struct linkstate_active_work;
761 /* Does this port need to prescan for FECNs */
762 bool cc_prescan;
731}; 763};
732 764
733typedef int (*rhf_rcv_function_ptr)(struct hfi1_packet *packet); 765typedef int (*rhf_rcv_function_ptr)(struct hfi1_packet *packet);
@@ -773,6 +805,12 @@ struct hfi1_temp {
773 u8 triggers; /* temperature triggers */ 805 u8 triggers; /* temperature triggers */
774}; 806};
775 807
808/* common data between shared ASIC HFIs */
809struct hfi1_asic_data {
810 struct hfi1_devdata *dds[2]; /* back pointers */
811 struct mutex asic_resource_mutex;
812};
813
776/* device data struct now contains only "general per-device" info. 814/* device data struct now contains only "general per-device" info.
777 * fields related to a physical IB port are in a hfi1_pportdata struct. 815 * fields related to a physical IB port are in a hfi1_pportdata struct.
778 */ 816 */
@@ -782,6 +820,7 @@ struct sdma_vl_map;
782#define BOARD_VERS_MAX 96 /* how long the version string can be */ 820#define BOARD_VERS_MAX 96 /* how long the version string can be */
783#define SERIAL_MAX 16 /* length of the serial number */ 821#define SERIAL_MAX 16 /* length of the serial number */
784 822
823typedef int (*send_routine)(struct rvt_qp *, struct hfi1_pkt_state *, u64);
785struct hfi1_devdata { 824struct hfi1_devdata {
786 struct hfi1_ibdev verbs_dev; /* must be first */ 825 struct hfi1_ibdev verbs_dev; /* must be first */
787 struct list_head list; 826 struct list_head list;
@@ -811,6 +850,12 @@ struct hfi1_devdata {
811 spinlock_t sc_lock; 850 spinlock_t sc_lock;
812 /* Per VL data. Enough for all VLs but not all elements are set/used. */ 851 /* Per VL data. Enough for all VLs but not all elements are set/used. */
813 struct per_vl_data vld[PER_VL_SEND_CONTEXTS]; 852 struct per_vl_data vld[PER_VL_SEND_CONTEXTS];
853 /* lock for pio_map */
854 spinlock_t pio_map_lock;
855 /* array of kernel send contexts */
856 struct send_context **kernel_send_context;
857 /* array of vl maps */
858 struct pio_vl_map __rcu *pio_map;
814 /* seqlock for sc2vl */ 859 /* seqlock for sc2vl */
815 seqlock_t sc2vl_lock; 860 seqlock_t sc2vl_lock;
816 u64 sc2vl[4]; 861 u64 sc2vl[4];
@@ -841,6 +886,8 @@ struct hfi1_devdata {
841 wait_queue_head_t sdma_unfreeze_wq; 886 wait_queue_head_t sdma_unfreeze_wq;
842 atomic_t sdma_unfreeze_count; 887 atomic_t sdma_unfreeze_count;
843 888
889 /* common data between shared ASIC HFIs in this OS */
890 struct hfi1_asic_data *asic_data;
844 891
845 /* hfi1_pportdata, points to array of (physical) port-specific 892 /* hfi1_pportdata, points to array of (physical) port-specific
846 * data structs, indexed by pidx (0..n-1) 893 * data structs, indexed by pidx (0..n-1)
@@ -873,10 +920,11 @@ struct hfi1_devdata {
873 /* reset value */ 920 /* reset value */
874 u64 z_int_counter; 921 u64 z_int_counter;
875 u64 z_rcv_limit; 922 u64 z_rcv_limit;
923 u64 z_send_schedule;
876 /* percpu int_counter */ 924 /* percpu int_counter */
877 u64 __percpu *int_counter; 925 u64 __percpu *int_counter;
878 u64 __percpu *rcv_limit; 926 u64 __percpu *rcv_limit;
879 927 u64 __percpu *send_schedule;
880 /* number of receive contexts in use by the driver */ 928 /* number of receive contexts in use by the driver */
881 u32 num_rcv_contexts; 929 u32 num_rcv_contexts;
882 /* number of pio send contexts in use by the driver */ 930 /* number of pio send contexts in use by the driver */
@@ -885,6 +933,8 @@ struct hfi1_devdata {
885 * number of ctxts available for PSM open 933 * number of ctxts available for PSM open
886 */ 934 */
887 u32 freectxts; 935 u32 freectxts;
936 /* total number of available user/PSM contexts */
937 u32 num_user_contexts;
888 /* base receive interrupt timeout, in CSR units */ 938 /* base receive interrupt timeout, in CSR units */
889 u32 rcv_intr_timeout_csr; 939 u32 rcv_intr_timeout_csr;
890 940
@@ -996,9 +1046,8 @@ struct hfi1_devdata {
996 u16 irev; /* implementation revision */ 1046 u16 irev; /* implementation revision */
997 u16 dc8051_ver; /* 8051 firmware version */ 1047 u16 dc8051_ver; /* 8051 firmware version */
998 1048
1049 struct platform_config platform_config;
999 struct platform_config_cache pcfg_cache; 1050 struct platform_config_cache pcfg_cache;
1000 /* control high-level access to qsfp */
1001 struct mutex qsfp_i2c_mutex;
1002 1051
1003 struct diag_client *diag_client; 1052 struct diag_client *diag_client;
1004 spinlock_t hfi1_diag_trans_lock; /* protect diag observer ops */ 1053 spinlock_t hfi1_diag_trans_lock; /* protect diag observer ops */
@@ -1008,8 +1057,6 @@ struct hfi1_devdata {
1008 u16 psxmitwait_check_rate; 1057 u16 psxmitwait_check_rate;
1009 /* high volume overflow errors deferred to tasklet */ 1058 /* high volume overflow errors deferred to tasklet */
1010 struct tasklet_struct error_tasklet; 1059 struct tasklet_struct error_tasklet;
1011 /* per device cq worker */
1012 struct kthread_worker *worker;
1013 1060
1014 /* MSI-X information */ 1061 /* MSI-X information */
1015 struct hfi1_msix_entry *msix_entries; 1062 struct hfi1_msix_entry *msix_entries;
@@ -1090,10 +1137,8 @@ struct hfi1_devdata {
1090 * Handlers for outgoing data so that snoop/capture does not 1137 * Handlers for outgoing data so that snoop/capture does not
1091 * have to have its hooks in the send path 1138 * have to have its hooks in the send path
1092 */ 1139 */
1093 int (*process_pio_send)(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 1140 send_routine process_pio_send;
1094 u64 pbc); 1141 send_routine process_dma_send;
1095 int (*process_dma_send)(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1096 u64 pbc);
1097 void (*pio_inline_send)(struct hfi1_devdata *dd, struct pio_buf *pbuf, 1142 void (*pio_inline_send)(struct hfi1_devdata *dd, struct pio_buf *pbuf,
1098 u64 pbc, const void *from, size_t count); 1143 u64 pbc, const void *from, size_t count);
1099 1144
@@ -1105,7 +1150,6 @@ struct hfi1_devdata {
1105 struct timer_list rcverr_timer; 1150 struct timer_list rcverr_timer;
1106 u32 rcv_ovfl_cnt; 1151 u32 rcv_ovfl_cnt;
1107 1152
1108 int assigned_node_id;
1109 wait_queue_head_t event_queue; 1153 wait_queue_head_t event_queue;
1110 1154
1111 /* Save the enabled LCB error bits */ 1155 /* Save the enabled LCB error bits */
@@ -1115,6 +1159,16 @@ struct hfi1_devdata {
1115 /* receive context tail dummy address */ 1159 /* receive context tail dummy address */
1116 __le64 *rcvhdrtail_dummy_kvaddr; 1160 __le64 *rcvhdrtail_dummy_kvaddr;
1117 dma_addr_t rcvhdrtail_dummy_physaddr; 1161 dma_addr_t rcvhdrtail_dummy_physaddr;
1162
1163 bool eprom_available; /* true if EPROM is available for this device */
1164 bool aspm_supported; /* Does HW support ASPM */
1165 bool aspm_enabled; /* ASPM state: enabled/disabled */
1166 /* Serialize ASPM enable/disable between multiple verbs contexts */
1167 spinlock_t aspm_lock;
1168 /* Number of verbs contexts which have disabled ASPM */
1169 atomic_t aspm_disabled_cnt;
1170
1171 struct hfi1_affinity *affinity;
1118}; 1172};
1119 1173
1120/* 8051 firmware version helper */ 1174/* 8051 firmware version helper */
@@ -1125,6 +1179,9 @@ struct hfi1_devdata {
1125#define PT_EAGER 1 1179#define PT_EAGER 1
1126#define PT_INVALID 2 1180#define PT_INVALID 2
1127 1181
1182struct tid_rb_node;
1183struct mmu_rb_node;
1184
1128/* Private data for file operations */ 1185/* Private data for file operations */
1129struct hfi1_filedata { 1186struct hfi1_filedata {
1130 struct hfi1_ctxtdata *uctxt; 1187 struct hfi1_ctxtdata *uctxt;
@@ -1133,6 +1190,16 @@ struct hfi1_filedata {
1133 struct hfi1_user_sdma_pkt_q *pq; 1190 struct hfi1_user_sdma_pkt_q *pq;
1134 /* for cpu affinity; -1 if none */ 1191 /* for cpu affinity; -1 if none */
1135 int rec_cpu_num; 1192 int rec_cpu_num;
1193 u32 tid_n_pinned;
1194 struct rb_root tid_rb_root;
1195 struct tid_rb_node **entry_to_rb;
1196 spinlock_t tid_lock; /* protect tid_[limit,used] counters */
1197 u32 tid_limit;
1198 u32 tid_used;
1199 u32 *invalid_tids;
1200 u32 invalid_tid_idx;
1201 /* protect invalid_tids array and invalid_tid_idx */
1202 spinlock_t invalid_lock;
1136}; 1203};
1137 1204
1138extern struct list_head hfi1_dev_list; 1205extern struct list_head hfi1_dev_list;
@@ -1156,7 +1223,7 @@ void handle_user_interrupt(struct hfi1_ctxtdata *rcd);
1156int hfi1_create_rcvhdrq(struct hfi1_devdata *, struct hfi1_ctxtdata *); 1223int hfi1_create_rcvhdrq(struct hfi1_devdata *, struct hfi1_ctxtdata *);
1157int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *); 1224int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *);
1158int hfi1_create_ctxts(struct hfi1_devdata *dd); 1225int hfi1_create_ctxts(struct hfi1_devdata *dd);
1159struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *, u32); 1226struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *, u32, int);
1160void hfi1_init_pportdata(struct pci_dev *, struct hfi1_pportdata *, 1227void hfi1_init_pportdata(struct pci_dev *, struct hfi1_pportdata *,
1161 struct hfi1_devdata *, u8, u8); 1228 struct hfi1_devdata *, u8, u8);
1162void hfi1_free_ctxtdata(struct hfi1_devdata *, struct hfi1_ctxtdata *); 1229void hfi1_free_ctxtdata(struct hfi1_devdata *, struct hfi1_ctxtdata *);
@@ -1164,6 +1231,7 @@ void hfi1_free_ctxtdata(struct hfi1_devdata *, struct hfi1_ctxtdata *);
1164int handle_receive_interrupt(struct hfi1_ctxtdata *, int); 1231int handle_receive_interrupt(struct hfi1_ctxtdata *, int);
1165int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *, int); 1232int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *, int);
1166int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *, int); 1233int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *, int);
1234void set_all_slowpath(struct hfi1_devdata *dd);
1167 1235
1168/* receive packet handler dispositions */ 1236/* receive packet handler dispositions */
1169#define RCV_PKT_OK 0x0 /* keep going */ 1237#define RCV_PKT_OK 0x0 /* keep going */
@@ -1184,6 +1252,15 @@ static inline u32 driver_lstate(struct hfi1_pportdata *ppd)
1184 return ppd->lstate; /* use the cached value */ 1252 return ppd->lstate; /* use the cached value */
1185} 1253}
1186 1254
1255void receive_interrupt_work(struct work_struct *work);
1256
1257/* extract service channel from header and rhf */
1258static inline int hdr2sc(struct hfi1_message_header *hdr, u64 rhf)
1259{
1260 return ((be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf) |
1261 ((!!(rhf & RHF_DC_INFO_MASK)) << 4);
1262}
1263
1187static inline u16 generate_jkey(kuid_t uid) 1264static inline u16 generate_jkey(kuid_t uid)
1188{ 1265{
1189 return from_kuid(current_user_ns(), uid) & 0xffff; 1266 return from_kuid(current_user_ns(), uid) & 0xffff;
@@ -1253,7 +1330,7 @@ static inline u32 egress_cycles(u32 len, u32 rate)
1253void set_link_ipg(struct hfi1_pportdata *ppd); 1330void set_link_ipg(struct hfi1_pportdata *ppd);
1254void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn, 1331void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
1255 u32 rqpn, u8 svc_type); 1332 u32 rqpn, u8 svc_type);
1256void return_cnp(struct hfi1_ibport *ibp, struct hfi1_qp *qp, u32 remote_qpn, 1333void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
1257 u32 pkey, u32 slid, u32 dlid, u8 sc5, 1334 u32 pkey, u32 slid, u32 dlid, u8 sc5,
1258 const struct ib_grh *old_grh); 1335 const struct ib_grh *old_grh);
1259 1336
@@ -1424,6 +1501,7 @@ static inline int valid_ib_mtu(unsigned int mtu)
1424 mtu == 1024 || mtu == 2048 || 1501 mtu == 1024 || mtu == 2048 ||
1425 mtu == 4096; 1502 mtu == 4096;
1426} 1503}
1504
1427static inline int valid_opa_max_mtu(unsigned int mtu) 1505static inline int valid_opa_max_mtu(unsigned int mtu)
1428{ 1506{
1429 return mtu >= 2048 && 1507 return mtu >= 2048 &&
@@ -1445,12 +1523,13 @@ void reset_link_credits(struct hfi1_devdata *dd);
1445void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu); 1523void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu);
1446 1524
1447int snoop_recv_handler(struct hfi1_packet *packet); 1525int snoop_recv_handler(struct hfi1_packet *packet);
1448int snoop_send_dma_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 1526int snoop_send_dma_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1449 u64 pbc); 1527 u64 pbc);
1450int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 1528int snoop_send_pio_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1451 u64 pbc); 1529 u64 pbc);
1452void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf, 1530void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf,
1453 u64 pbc, const void *from, size_t count); 1531 u64 pbc, const void *from, size_t count);
1532int set_buffer_control(struct hfi1_pportdata *ppd, struct buffer_control *bc);
1454 1533
1455static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd) 1534static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd)
1456{ 1535{
@@ -1472,6 +1551,11 @@ static inline struct hfi1_pportdata *ppd_from_ibp(struct hfi1_ibport *ibp)
1472 return container_of(ibp, struct hfi1_pportdata, ibport_data); 1551 return container_of(ibp, struct hfi1_pportdata, ibport_data);
1473} 1552}
1474 1553
1554static inline struct hfi1_ibdev *dev_from_rdi(struct rvt_dev_info *rdi)
1555{
1556 return container_of(rdi, struct hfi1_ibdev, rdi);
1557}
1558
1475static inline struct hfi1_ibport *to_iport(struct ib_device *ibdev, u8 port) 1559static inline struct hfi1_ibport *to_iport(struct ib_device *ibdev, u8 port)
1476{ 1560{
1477 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1561 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
@@ -1515,12 +1599,10 @@ static inline struct cc_state *get_cc_state(struct hfi1_pportdata *ppd)
1515#define HFI1_HAS_SDMA_TIMEOUT 0x8 1599#define HFI1_HAS_SDMA_TIMEOUT 0x8
1516#define HFI1_HAS_SEND_DMA 0x10 /* Supports Send DMA */ 1600#define HFI1_HAS_SEND_DMA 0x10 /* Supports Send DMA */
1517#define HFI1_FORCED_FREEZE 0x80 /* driver forced freeze mode */ 1601#define HFI1_FORCED_FREEZE 0x80 /* driver forced freeze mode */
1518#define HFI1_DO_INIT_ASIC 0x100 /* This device will init the ASIC */
1519 1602
1520/* IB dword length mask in PBC (lower 11 bits); same for all chips */ 1603/* IB dword length mask in PBC (lower 11 bits); same for all chips */
1521#define HFI1_PBC_LENGTH_MASK ((1 << 11) - 1) 1604#define HFI1_PBC_LENGTH_MASK ((1 << 11) - 1)
1522 1605
1523
1524/* ctxt_flag bit offsets */ 1606/* ctxt_flag bit offsets */
1525 /* context has been setup */ 1607 /* context has been setup */
1526#define HFI1_CTXT_SETUP_DONE 1 1608#define HFI1_CTXT_SETUP_DONE 1
@@ -1538,14 +1620,10 @@ void hfi1_free_devdata(struct hfi1_devdata *);
1538void cc_state_reclaim(struct rcu_head *rcu); 1620void cc_state_reclaim(struct rcu_head *rcu);
1539struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra); 1621struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra);
1540 1622
1541/* 1623/* LED beaconing functions */
1542 * Set LED override, only the two LSBs have "public" meaning, but 1624void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon,
1543 * any non-zero value substitutes them for the Link and LinkTrain 1625 unsigned int timeoff);
1544 * LED states. 1626void shutdown_led_override(struct hfi1_pportdata *ppd);
1545 */
1546#define HFI1_LED_PHYS 1 /* Physical (linktraining) GREEN LED */
1547#define HFI1_LED_LOG 2 /* Logical (link) YELLOW LED */
1548void hfi1_set_led_override(struct hfi1_pportdata *ppd, unsigned int val);
1549 1627
1550#define HFI1_CREDIT_RETURN_RATE (100) 1628#define HFI1_CREDIT_RETURN_RATE (100)
1551 1629
@@ -1587,12 +1665,13 @@ void hfi1_set_led_override(struct hfi1_pportdata *ppd, unsigned int val);
1587 */ 1665 */
1588#define DEFAULT_RCVHDR_ENTSIZE 32 1666#define DEFAULT_RCVHDR_ENTSIZE 32
1589 1667
1668bool hfi1_can_pin_pages(struct hfi1_devdata *, u32, u32);
1590int hfi1_acquire_user_pages(unsigned long, size_t, bool, struct page **); 1669int hfi1_acquire_user_pages(unsigned long, size_t, bool, struct page **);
1591void hfi1_release_user_pages(struct page **, size_t, bool); 1670void hfi1_release_user_pages(struct mm_struct *, struct page **, size_t, bool);
1592 1671
1593static inline void clear_rcvhdrtail(const struct hfi1_ctxtdata *rcd) 1672static inline void clear_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
1594{ 1673{
1595 *((u64 *) rcd->rcvhdrtail_kvaddr) = 0ULL; 1674 *((u64 *)rcd->rcvhdrtail_kvaddr) = 0ULL;
1596} 1675}
1597 1676
1598static inline u32 get_rcvhdrtail(const struct hfi1_ctxtdata *rcd) 1677static inline u32 get_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
@@ -1601,7 +1680,7 @@ static inline u32 get_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
1601 * volatile because it's a DMA target from the chip, routine is 1680 * volatile because it's a DMA target from the chip, routine is
1602 * inlined, and don't want register caching or reordering. 1681 * inlined, and don't want register caching or reordering.
1603 */ 1682 */
1604 return (u32) le64_to_cpu(*rcd->rcvhdrtail_kvaddr); 1683 return (u32)le64_to_cpu(*rcd->rcvhdrtail_kvaddr);
1605} 1684}
1606 1685
1607/* 1686/*
@@ -1633,12 +1712,13 @@ void restore_pci_variables(struct hfi1_devdata *dd);
1633int do_pcie_gen3_transition(struct hfi1_devdata *dd); 1712int do_pcie_gen3_transition(struct hfi1_devdata *dd);
1634int parse_platform_config(struct hfi1_devdata *dd); 1713int parse_platform_config(struct hfi1_devdata *dd);
1635int get_platform_config_field(struct hfi1_devdata *dd, 1714int get_platform_config_field(struct hfi1_devdata *dd,
1636 enum platform_config_table_type_encoding table_type, 1715 enum platform_config_table_type_encoding
1637 int table_index, int field_index, u32 *data, u32 len); 1716 table_type, int table_index, int field_index,
1717 u32 *data, u32 len);
1638 1718
1639dma_addr_t hfi1_map_page(struct pci_dev *, struct page *, unsigned long,
1640 size_t, int);
1641const char *get_unit_name(int unit); 1719const char *get_unit_name(int unit);
1720const char *get_card_name(struct rvt_dev_info *rdi);
1721struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi);
1642 1722
1643/* 1723/*
1644 * Flush write combining store buffers (if present) and perform a write 1724 * Flush write combining store buffers (if present) and perform a write
@@ -1659,7 +1739,7 @@ int process_receive_invalid(struct hfi1_packet *packet);
1659 1739
1660extern rhf_rcv_function_ptr snoop_rhf_rcv_functions[8]; 1740extern rhf_rcv_function_ptr snoop_rhf_rcv_functions[8];
1661 1741
1662void update_sge(struct hfi1_sge_state *ss, u32 length); 1742void update_sge(struct rvt_sge_state *ss, u32 length);
1663 1743
1664/* global module parameter variables */ 1744/* global module parameter variables */
1665extern unsigned int hfi1_max_mtu; 1745extern unsigned int hfi1_max_mtu;
@@ -1667,7 +1747,7 @@ extern unsigned int hfi1_cu;
1667extern unsigned int user_credit_return_threshold; 1747extern unsigned int user_credit_return_threshold;
1668extern int num_user_contexts; 1748extern int num_user_contexts;
1669extern unsigned n_krcvqs; 1749extern unsigned n_krcvqs;
1670extern u8 krcvqs[]; 1750extern uint krcvqs[];
1671extern int krcvqsset; 1751extern int krcvqsset;
1672extern uint kdeth_qp; 1752extern uint kdeth_qp;
1673extern uint loopback; 1753extern uint loopback;
@@ -1829,13 +1909,14 @@ static inline void hfi1_reset_cpu_counters(struct hfi1_devdata *dd)
1829 1909
1830 dd->z_int_counter = get_all_cpu_total(dd->int_counter); 1910 dd->z_int_counter = get_all_cpu_total(dd->int_counter);
1831 dd->z_rcv_limit = get_all_cpu_total(dd->rcv_limit); 1911 dd->z_rcv_limit = get_all_cpu_total(dd->rcv_limit);
1912 dd->z_send_schedule = get_all_cpu_total(dd->send_schedule);
1832 1913
1833 ppd = (struct hfi1_pportdata *)(dd + 1); 1914 ppd = (struct hfi1_pportdata *)(dd + 1);
1834 for (i = 0; i < dd->num_pports; i++, ppd++) { 1915 for (i = 0; i < dd->num_pports; i++, ppd++) {
1835 ppd->ibport_data.z_rc_acks = 1916 ppd->ibport_data.rvp.z_rc_acks =
1836 get_all_cpu_total(ppd->ibport_data.rc_acks); 1917 get_all_cpu_total(ppd->ibport_data.rvp.rc_acks);
1837 ppd->ibport_data.z_rc_qacks = 1918 ppd->ibport_data.rvp.z_rc_qacks =
1838 get_all_cpu_total(ppd->ibport_data.rc_qacks); 1919 get_all_cpu_total(ppd->ibport_data.rvp.rc_qacks);
1839 } 1920 }
1840} 1921}
1841 1922
@@ -1848,6 +1929,18 @@ static inline void setextled(struct hfi1_devdata *dd, u32 on)
1848 write_csr(dd, DCC_CFG_LED_CNTRL, 0x10); 1929 write_csr(dd, DCC_CFG_LED_CNTRL, 0x10);
1849} 1930}
1850 1931
1932/* return the i2c resource given the target */
1933static inline u32 i2c_target(u32 target)
1934{
1935 return target ? CR_I2C2 : CR_I2C1;
1936}
1937
1938/* return the i2c chain chip resource that this HFI uses for QSFP */
1939static inline u32 qsfp_resource(struct hfi1_devdata *dd)
1940{
1941 return i2c_target(dd->hfi1_id);
1942}
1943
1851int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp); 1944int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp);
1852 1945
1853#endif /* _HFI1_KERNEL_H */ 1946#endif /* _HFI1_KERNEL_H */
diff --git a/drivers/staging/rdma/hfi1/init.c b/drivers/staging/rdma/hfi1/init.c
index 02df291eb172..cfcdc16b41c3 100644
--- a/drivers/staging/rdma/hfi1/init.c
+++ b/drivers/staging/rdma/hfi1/init.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -56,6 +53,7 @@
56#include <linux/module.h> 53#include <linux/module.h>
57#include <linux/printk.h> 54#include <linux/printk.h>
58#include <linux/hrtimer.h> 55#include <linux/hrtimer.h>
56#include <rdma/rdma_vt.h>
59 57
60#include "hfi.h" 58#include "hfi.h"
61#include "device.h" 59#include "device.h"
@@ -65,6 +63,7 @@
65#include "sdma.h" 63#include "sdma.h"
66#include "debugfs.h" 64#include "debugfs.h"
67#include "verbs.h" 65#include "verbs.h"
66#include "aspm.h"
68 67
69#undef pr_fmt 68#undef pr_fmt
70#define pr_fmt(fmt) DRIVER_NAME ": " fmt 69#define pr_fmt(fmt) DRIVER_NAME ": " fmt
@@ -75,6 +74,7 @@
75#define HFI1_MIN_USER_CTXT_BUFCNT 7 74#define HFI1_MIN_USER_CTXT_BUFCNT 7
76 75
77#define HFI1_MIN_HDRQ_EGRBUF_CNT 2 76#define HFI1_MIN_HDRQ_EGRBUF_CNT 2
77#define HFI1_MAX_HDRQ_EGRBUF_CNT 16352
78#define HFI1_MIN_EAGER_BUFFER_SIZE (4 * 1024) /* 4KB */ 78#define HFI1_MIN_EAGER_BUFFER_SIZE (4 * 1024) /* 4KB */
79#define HFI1_MAX_EAGER_BUFFER_SIZE (256 * 1024) /* 256KB */ 79#define HFI1_MAX_EAGER_BUFFER_SIZE (256 * 1024) /* 256KB */
80 80
@@ -87,9 +87,9 @@ module_param_named(num_user_contexts, num_user_contexts, uint, S_IRUGO);
87MODULE_PARM_DESC( 87MODULE_PARM_DESC(
88 num_user_contexts, "Set max number of user contexts to use"); 88 num_user_contexts, "Set max number of user contexts to use");
89 89
90u8 krcvqs[RXE_NUM_DATA_VL]; 90uint krcvqs[RXE_NUM_DATA_VL];
91int krcvqsset; 91int krcvqsset;
92module_param_array(krcvqs, byte, &krcvqsset, S_IRUGO); 92module_param_array(krcvqs, uint, &krcvqsset, S_IRUGO);
93MODULE_PARM_DESC(krcvqs, "Array of the number of non-control kernel receive queues by VL"); 93MODULE_PARM_DESC(krcvqs, "Array of the number of non-control kernel receive queues by VL");
94 94
95/* computed based on above array */ 95/* computed based on above array */
@@ -128,16 +128,12 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
128{ 128{
129 unsigned i; 129 unsigned i;
130 int ret; 130 int ret;
131 int local_node_id = pcibus_to_node(dd->pcidev->bus);
132 131
133 /* Control context has to be always 0 */ 132 /* Control context has to be always 0 */
134 BUILD_BUG_ON(HFI1_CTRL_CTXT != 0); 133 BUILD_BUG_ON(HFI1_CTRL_CTXT != 0);
135 134
136 if (local_node_id < 0) 135 dd->rcd = kzalloc_node(dd->num_rcv_contexts * sizeof(*dd->rcd),
137 local_node_id = numa_node_id(); 136 GFP_KERNEL, dd->node);
138 dd->assigned_node_id = local_node_id;
139
140 dd->rcd = kcalloc(dd->num_rcv_contexts, sizeof(*dd->rcd), GFP_KERNEL);
141 if (!dd->rcd) 137 if (!dd->rcd)
142 goto nomem; 138 goto nomem;
143 139
@@ -147,10 +143,10 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
147 struct hfi1_ctxtdata *rcd; 143 struct hfi1_ctxtdata *rcd;
148 144
149 ppd = dd->pport + (i % dd->num_pports); 145 ppd = dd->pport + (i % dd->num_pports);
150 rcd = hfi1_create_ctxtdata(ppd, i); 146 rcd = hfi1_create_ctxtdata(ppd, i, dd->node);
151 if (!rcd) { 147 if (!rcd) {
152 dd_dev_err(dd, 148 dd_dev_err(dd,
153 "Unable to allocate kernel receive context, failing\n"); 149 "Unable to allocate kernel receive context, failing\n");
154 goto nomem; 150 goto nomem;
155 } 151 }
156 /* 152 /*
@@ -171,7 +167,7 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
171 rcd->sc = sc_alloc(dd, SC_ACK, rcd->rcvhdrqentsize, dd->node); 167 rcd->sc = sc_alloc(dd, SC_ACK, rcd->rcvhdrqentsize, dd->node);
172 if (!rcd->sc) { 168 if (!rcd->sc) {
173 dd_dev_err(dd, 169 dd_dev_err(dd,
174 "Unable to allocate kernel send context, failing\n"); 170 "Unable to allocate kernel send context, failing\n");
175 dd->rcd[rcd->ctxt] = NULL; 171 dd->rcd[rcd->ctxt] = NULL;
176 hfi1_free_ctxtdata(dd, rcd); 172 hfi1_free_ctxtdata(dd, rcd);
177 goto nomem; 173 goto nomem;
@@ -189,6 +185,12 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
189 } 185 }
190 } 186 }
191 187
188 /*
189 * Initialize aspm, to be done after gen3 transition and setting up
190 * contexts and before enabling interrupts
191 */
192 aspm_init(dd);
193
192 return 0; 194 return 0;
193nomem: 195nomem:
194 ret = -ENOMEM; 196 ret = -ENOMEM;
@@ -201,7 +203,8 @@ bail:
201/* 203/*
202 * Common code for user and kernel context setup. 204 * Common code for user and kernel context setup.
203 */ 205 */
204struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt) 206struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt,
207 int numa)
205{ 208{
206 struct hfi1_devdata *dd = ppd->dd; 209 struct hfi1_devdata *dd = ppd->dd;
207 struct hfi1_ctxtdata *rcd; 210 struct hfi1_ctxtdata *rcd;
@@ -224,10 +227,10 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt)
224 rcd->cnt = 1; 227 rcd->cnt = 1;
225 rcd->ctxt = ctxt; 228 rcd->ctxt = ctxt;
226 dd->rcd[ctxt] = rcd; 229 dd->rcd[ctxt] = rcd;
227 rcd->numa_id = numa_node_id(); 230 rcd->numa_id = numa;
228 rcd->rcv_array_groups = dd->rcv_entries.ngroups; 231 rcd->rcv_array_groups = dd->rcv_entries.ngroups;
229 232
230 spin_lock_init(&rcd->exp_lock); 233 mutex_init(&rcd->exp_lock);
231 234
232 /* 235 /*
233 * Calculate the context's RcvArray entry starting point. 236 * Calculate the context's RcvArray entry starting point.
@@ -260,7 +263,7 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt)
260 /* Validate and initialize Rcv Hdr Q variables */ 263 /* Validate and initialize Rcv Hdr Q variables */
261 if (rcvhdrcnt % HDRQ_INCREMENT) { 264 if (rcvhdrcnt % HDRQ_INCREMENT) {
262 dd_dev_err(dd, 265 dd_dev_err(dd,
263 "ctxt%u: header queue count %d must be divisible by %d\n", 266 "ctxt%u: header queue count %d must be divisible by %lu\n",
264 rcd->ctxt, rcvhdrcnt, HDRQ_INCREMENT); 267 rcd->ctxt, rcvhdrcnt, HDRQ_INCREMENT);
265 goto bail; 268 goto bail;
266 } 269 }
@@ -379,7 +382,7 @@ void set_link_ipg(struct hfi1_pportdata *ppd)
379 382
380 cc_state = get_cc_state(ppd); 383 cc_state = get_cc_state(ppd);
381 384
382 if (cc_state == NULL) 385 if (!cc_state)
383 /* 386 /*
384 * This should _never_ happen - rcu_read_lock() is held, 387 * This should _never_ happen - rcu_read_lock() is held,
385 * and set_link_ipg() should not be called if cc_state 388 * and set_link_ipg() should not be called if cc_state
@@ -431,7 +434,7 @@ static enum hrtimer_restart cca_timer_fn(struct hrtimer *t)
431 434
432 cc_state = get_cc_state(ppd); 435 cc_state = get_cc_state(ppd);
433 436
434 if (cc_state == NULL) { 437 if (!cc_state) {
435 rcu_read_unlock(); 438 rcu_read_unlock();
436 return HRTIMER_NORESTART; 439 return HRTIMER_NORESTART;
437 } 440 }
@@ -493,14 +496,19 @@ void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
493 INIT_WORK(&ppd->link_vc_work, handle_verify_cap); 496 INIT_WORK(&ppd->link_vc_work, handle_verify_cap);
494 INIT_WORK(&ppd->link_up_work, handle_link_up); 497 INIT_WORK(&ppd->link_up_work, handle_link_up);
495 INIT_WORK(&ppd->link_down_work, handle_link_down); 498 INIT_WORK(&ppd->link_down_work, handle_link_down);
499 INIT_WORK(&ppd->dc_host_req_work, handle_8051_request);
496 INIT_WORK(&ppd->freeze_work, handle_freeze); 500 INIT_WORK(&ppd->freeze_work, handle_freeze);
497 INIT_WORK(&ppd->link_downgrade_work, handle_link_downgrade); 501 INIT_WORK(&ppd->link_downgrade_work, handle_link_downgrade);
498 INIT_WORK(&ppd->sma_message_work, handle_sma_message); 502 INIT_WORK(&ppd->sma_message_work, handle_sma_message);
499 INIT_WORK(&ppd->link_bounce_work, handle_link_bounce); 503 INIT_WORK(&ppd->link_bounce_work, handle_link_bounce);
504 INIT_WORK(&ppd->linkstate_active_work, receive_interrupt_work);
505 INIT_WORK(&ppd->qsfp_info.qsfp_work, qsfp_event);
506
500 mutex_init(&ppd->hls_lock); 507 mutex_init(&ppd->hls_lock);
501 spin_lock_init(&ppd->sdma_alllock); 508 spin_lock_init(&ppd->sdma_alllock);
502 spin_lock_init(&ppd->qsfp_info.qsfp_lock); 509 spin_lock_init(&ppd->qsfp_info.qsfp_lock);
503 510
511 ppd->qsfp_info.ppd = ppd;
504 ppd->sm_trap_qp = 0x0; 512 ppd->sm_trap_qp = 0x0;
505 ppd->sa_qp = 0x1; 513 ppd->sa_qp = 0x1;
506 514
@@ -582,8 +590,8 @@ static void enable_chip(struct hfi1_devdata *dd)
582 * Enable kernel ctxts' receive and receive interrupt. 590 * Enable kernel ctxts' receive and receive interrupt.
583 * Other ctxts done as user opens and initializes them. 591 * Other ctxts done as user opens and initializes them.
584 */ 592 */
585 rcvmask = HFI1_RCVCTRL_CTXT_ENB | HFI1_RCVCTRL_INTRAVAIL_ENB;
586 for (i = 0; i < dd->first_user_ctxt; ++i) { 593 for (i = 0; i < dd->first_user_ctxt; ++i) {
594 rcvmask = HFI1_RCVCTRL_CTXT_ENB | HFI1_RCVCTRL_INTRAVAIL_ENB;
587 rcvmask |= HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, DMA_RTAIL) ? 595 rcvmask |= HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, DMA_RTAIL) ?
588 HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS; 596 HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
589 if (!HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, MULTI_PKT_EGR)) 597 if (!HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, MULTI_PKT_EGR))
@@ -729,7 +737,7 @@ int hfi1_init(struct hfi1_devdata *dd, int reinit)
729 lastfail = hfi1_setup_eagerbufs(rcd); 737 lastfail = hfi1_setup_eagerbufs(rcd);
730 if (lastfail) 738 if (lastfail)
731 dd_dev_err(dd, 739 dd_dev_err(dd,
732 "failed to allocate kernel ctxt's rcvhdrq and/or egr bufs\n"); 740 "failed to allocate kernel ctxt's rcvhdrq and/or egr bufs\n");
733 } 741 }
734 if (lastfail) 742 if (lastfail)
735 ret = lastfail; 743 ret = lastfail;
@@ -762,7 +770,6 @@ int hfi1_init(struct hfi1_devdata *dd, int reinit)
762 /* enable chip even if we have an error, so we can debug cause */ 770 /* enable chip even if we have an error, so we can debug cause */
763 enable_chip(dd); 771 enable_chip(dd);
764 772
765 ret = hfi1_cq_init(dd);
766done: 773done:
767 /* 774 /*
768 * Set status even if port serdes is not initialized 775 * Set status even if port serdes is not initialized
@@ -779,20 +786,15 @@ done:
779 for (pidx = 0; pidx < dd->num_pports; ++pidx) { 786 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
780 ppd = dd->pport + pidx; 787 ppd = dd->pport + pidx;
781 788
782 /* initialize the qsfp if it exists 789 /*
783 * Requires interrupts to be enabled so we are notified 790 * start the serdes - must be after interrupts are
784 * when the QSFP completes reset, and has 791 * enabled so we are notified when the link goes up
785 * to be done before bringing up the SERDES
786 */ 792 */
787 init_qsfp(ppd);
788
789 /* start the serdes - must be after interrupts are
790 enabled so we are notified when the link goes up */
791 lastfail = bringup_serdes(ppd); 793 lastfail = bringup_serdes(ppd);
792 if (lastfail) 794 if (lastfail)
793 dd_dev_info(dd, 795 dd_dev_info(dd,
794 "Failed to bring up port %u\n", 796 "Failed to bring up port %u\n",
795 ppd->port); 797 ppd->port);
796 798
797 /* 799 /*
798 * Set status even if port serdes is not initialized 800 * Set status even if port serdes is not initialized
@@ -904,6 +906,8 @@ static void shutdown_device(struct hfi1_devdata *dd)
904 /* disable the send device */ 906 /* disable the send device */
905 pio_send_control(dd, PSC_GLOBAL_DISABLE); 907 pio_send_control(dd, PSC_GLOBAL_DISABLE);
906 908
909 shutdown_led_override(ppd);
910
907 /* 911 /*
908 * Clear SerdesEnable. 912 * Clear SerdesEnable.
909 * We can't count on interrupts since we are stopping. 913 * We can't count on interrupts since we are stopping.
@@ -961,17 +965,33 @@ void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
961 kfree(rcd->egrbufs.buffers); 965 kfree(rcd->egrbufs.buffers);
962 966
963 sc_free(rcd->sc); 967 sc_free(rcd->sc);
964 vfree(rcd->physshadow);
965 vfree(rcd->tid_pg_list);
966 vfree(rcd->user_event_mask); 968 vfree(rcd->user_event_mask);
967 vfree(rcd->subctxt_uregbase); 969 vfree(rcd->subctxt_uregbase);
968 vfree(rcd->subctxt_rcvegrbuf); 970 vfree(rcd->subctxt_rcvegrbuf);
969 vfree(rcd->subctxt_rcvhdr_base); 971 vfree(rcd->subctxt_rcvhdr_base);
970 kfree(rcd->tidusemap);
971 kfree(rcd->opstats); 972 kfree(rcd->opstats);
972 kfree(rcd); 973 kfree(rcd);
973} 974}
974 975
976/*
977 * Release our hold on the shared asic data. If we are the last one,
978 * free the structure. Must be holding hfi1_devs_lock.
979 */
980static void release_asic_data(struct hfi1_devdata *dd)
981{
982 int other;
983
984 if (!dd->asic_data)
985 return;
986 dd->asic_data->dds[dd->hfi1_id] = NULL;
987 other = dd->hfi1_id ? 0 : 1;
988 if (!dd->asic_data->dds[other]) {
989 /* we are the last holder, free it */
990 kfree(dd->asic_data);
991 }
992 dd->asic_data = NULL;
993}
994
975void hfi1_free_devdata(struct hfi1_devdata *dd) 995void hfi1_free_devdata(struct hfi1_devdata *dd)
976{ 996{
977 unsigned long flags; 997 unsigned long flags;
@@ -979,12 +999,15 @@ void hfi1_free_devdata(struct hfi1_devdata *dd)
979 spin_lock_irqsave(&hfi1_devs_lock, flags); 999 spin_lock_irqsave(&hfi1_devs_lock, flags);
980 idr_remove(&hfi1_unit_table, dd->unit); 1000 idr_remove(&hfi1_unit_table, dd->unit);
981 list_del(&dd->list); 1001 list_del(&dd->list);
1002 release_asic_data(dd);
982 spin_unlock_irqrestore(&hfi1_devs_lock, flags); 1003 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
983 hfi1_dbg_ibdev_exit(&dd->verbs_dev); 1004 free_platform_config(dd);
984 rcu_barrier(); /* wait for rcu callbacks to complete */ 1005 rcu_barrier(); /* wait for rcu callbacks to complete */
985 free_percpu(dd->int_counter); 1006 free_percpu(dd->int_counter);
986 free_percpu(dd->rcv_limit); 1007 free_percpu(dd->rcv_limit);
987 ib_dealloc_device(&dd->verbs_dev.ibdev); 1008 hfi1_dev_affinity_free(dd);
1009 free_percpu(dd->send_schedule);
1010 ib_dealloc_device(&dd->verbs_dev.rdi.ibdev);
988} 1011}
989 1012
990/* 1013/*
@@ -999,19 +1022,19 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra)
999{ 1022{
1000 unsigned long flags; 1023 unsigned long flags;
1001 struct hfi1_devdata *dd; 1024 struct hfi1_devdata *dd;
1002 int ret; 1025 int ret, nports;
1003 1026
1004 dd = (struct hfi1_devdata *)ib_alloc_device(sizeof(*dd) + extra); 1027 /* extra is * number of ports */
1028 nports = extra / sizeof(struct hfi1_pportdata);
1029
1030 dd = (struct hfi1_devdata *)rvt_alloc_device(sizeof(*dd) + extra,
1031 nports);
1005 if (!dd) 1032 if (!dd)
1006 return ERR_PTR(-ENOMEM); 1033 return ERR_PTR(-ENOMEM);
1007 /* extra is * number of ports */ 1034 dd->num_pports = nports;
1008 dd->num_pports = extra / sizeof(struct hfi1_pportdata);
1009 dd->pport = (struct hfi1_pportdata *)(dd + 1); 1035 dd->pport = (struct hfi1_pportdata *)(dd + 1);
1010 1036
1011 INIT_LIST_HEAD(&dd->list); 1037 INIT_LIST_HEAD(&dd->list);
1012 dd->node = dev_to_node(&pdev->dev);
1013 if (dd->node < 0)
1014 dd->node = 0;
1015 idr_preload(GFP_KERNEL); 1038 idr_preload(GFP_KERNEL);
1016 spin_lock_irqsave(&hfi1_devs_lock, flags); 1039 spin_lock_irqsave(&hfi1_devs_lock, flags);
1017 1040
@@ -1041,9 +1064,9 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra)
1041 spin_lock_init(&dd->sc_init_lock); 1064 spin_lock_init(&dd->sc_init_lock);
1042 spin_lock_init(&dd->dc8051_lock); 1065 spin_lock_init(&dd->dc8051_lock);
1043 spin_lock_init(&dd->dc8051_memlock); 1066 spin_lock_init(&dd->dc8051_memlock);
1044 mutex_init(&dd->qsfp_i2c_mutex);
1045 seqlock_init(&dd->sc2vl_lock); 1067 seqlock_init(&dd->sc2vl_lock);
1046 spin_lock_init(&dd->sde_map_lock); 1068 spin_lock_init(&dd->sde_map_lock);
1069 spin_lock_init(&dd->pio_map_lock);
1047 init_waitqueue_head(&dd->event_queue); 1070 init_waitqueue_head(&dd->event_queue);
1048 1071
1049 dd->int_counter = alloc_percpu(u64); 1072 dd->int_counter = alloc_percpu(u64);
@@ -1062,6 +1085,14 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra)
1062 goto bail; 1085 goto bail;
1063 } 1086 }
1064 1087
1088 dd->send_schedule = alloc_percpu(u64);
1089 if (!dd->send_schedule) {
1090 ret = -ENOMEM;
1091 hfi1_early_err(&pdev->dev,
1092 "Could not allocate per-cpu int_counter\n");
1093 goto bail;
1094 }
1095
1065 if (!hfi1_cpulist_count) { 1096 if (!hfi1_cpulist_count) {
1066 u32 count = num_online_cpus(); 1097 u32 count = num_online_cpus();
1067 1098
@@ -1074,13 +1105,12 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra)
1074 &pdev->dev, 1105 &pdev->dev,
1075 "Could not alloc cpulist info, cpu affinity might be wrong\n"); 1106 "Could not alloc cpulist info, cpu affinity might be wrong\n");
1076 } 1107 }
1077 hfi1_dbg_ibdev_init(&dd->verbs_dev);
1078 return dd; 1108 return dd;
1079 1109
1080bail: 1110bail:
1081 if (!list_empty(&dd->list)) 1111 if (!list_empty(&dd->list))
1082 list_del_init(&dd->list); 1112 list_del_init(&dd->list);
1083 ib_dealloc_device(&dd->verbs_dev.ibdev); 1113 ib_dealloc_device(&dd->verbs_dev.rdi.ibdev);
1084 return ERR_PTR(ret); 1114 return ERR_PTR(ret);
1085} 1115}
1086 1116
@@ -1173,8 +1203,10 @@ static int __init hfi1_mod_init(void)
1173 user_credit_return_threshold = 100; 1203 user_credit_return_threshold = 100;
1174 1204
1175 compute_krcvqs(); 1205 compute_krcvqs();
1176 /* sanitize receive interrupt count, time must wait until after 1206 /*
1177 the hardware type is known */ 1207 * sanitize receive interrupt count, time must wait until after
1208 * the hardware type is known
1209 */
1178 if (rcv_intr_count > RCV_HDR_HEAD_COUNTER_MASK) 1210 if (rcv_intr_count > RCV_HDR_HEAD_COUNTER_MASK)
1179 rcv_intr_count = RCV_HDR_HEAD_COUNTER_MASK; 1211 rcv_intr_count = RCV_HDR_HEAD_COUNTER_MASK;
1180 /* reject invalid combinations */ 1212 /* reject invalid combinations */
@@ -1209,6 +1241,9 @@ static int __init hfi1_mod_init(void)
1209 idr_init(&hfi1_unit_table); 1241 idr_init(&hfi1_unit_table);
1210 1242
1211 hfi1_dbg_init(); 1243 hfi1_dbg_init();
1244 ret = hfi1_wss_init();
1245 if (ret < 0)
1246 goto bail_wss;
1212 ret = pci_register_driver(&hfi1_pci_driver); 1247 ret = pci_register_driver(&hfi1_pci_driver);
1213 if (ret < 0) { 1248 if (ret < 0) {
1214 pr_err("Unable to register driver: error %d\n", -ret); 1249 pr_err("Unable to register driver: error %d\n", -ret);
@@ -1217,6 +1252,8 @@ static int __init hfi1_mod_init(void)
1217 goto bail; /* all OK */ 1252 goto bail; /* all OK */
1218 1253
1219bail_dev: 1254bail_dev:
1255 hfi1_wss_exit();
1256bail_wss:
1220 hfi1_dbg_exit(); 1257 hfi1_dbg_exit();
1221 idr_destroy(&hfi1_unit_table); 1258 idr_destroy(&hfi1_unit_table);
1222 dev_cleanup(); 1259 dev_cleanup();
@@ -1232,6 +1269,7 @@ module_init(hfi1_mod_init);
1232static void __exit hfi1_mod_cleanup(void) 1269static void __exit hfi1_mod_cleanup(void)
1233{ 1270{
1234 pci_unregister_driver(&hfi1_pci_driver); 1271 pci_unregister_driver(&hfi1_pci_driver);
1272 hfi1_wss_exit();
1235 hfi1_dbg_exit(); 1273 hfi1_dbg_exit();
1236 hfi1_cpulist_count = 0; 1274 hfi1_cpulist_count = 0;
1237 kfree(hfi1_cpulist); 1275 kfree(hfi1_cpulist);
@@ -1303,16 +1341,18 @@ static void cleanup_device_data(struct hfi1_devdata *dd)
1303 } 1341 }
1304 } 1342 }
1305 kfree(tmp); 1343 kfree(tmp);
1344 free_pio_map(dd);
1306 /* must follow rcv context free - need to remove rcv's hooks */ 1345 /* must follow rcv context free - need to remove rcv's hooks */
1307 for (ctxt = 0; ctxt < dd->num_send_contexts; ctxt++) 1346 for (ctxt = 0; ctxt < dd->num_send_contexts; ctxt++)
1308 sc_free(dd->send_contexts[ctxt].sc); 1347 sc_free(dd->send_contexts[ctxt].sc);
1309 dd->num_send_contexts = 0; 1348 dd->num_send_contexts = 0;
1310 kfree(dd->send_contexts); 1349 kfree(dd->send_contexts);
1311 dd->send_contexts = NULL; 1350 dd->send_contexts = NULL;
1351 kfree(dd->hw_to_sw);
1352 dd->hw_to_sw = NULL;
1312 kfree(dd->boardname); 1353 kfree(dd->boardname);
1313 vfree(dd->events); 1354 vfree(dd->events);
1314 vfree(dd->status); 1355 vfree(dd->status);
1315 hfi1_cq_exit(dd);
1316} 1356}
1317 1357
1318/* 1358/*
@@ -1346,6 +1386,13 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1346 ret = -EINVAL; 1386 ret = -EINVAL;
1347 goto bail; 1387 goto bail;
1348 } 1388 }
1389 if (rcvhdrcnt > HFI1_MAX_HDRQ_EGRBUF_CNT) {
1390 hfi1_early_err(&pdev->dev,
1391 "Receive header queue count cannot be greater than %u\n",
1392 HFI1_MAX_HDRQ_EGRBUF_CNT);
1393 ret = -EINVAL;
1394 goto bail;
1395 }
1349 /* use the encoding function as a sanitization check */ 1396 /* use the encoding function as a sanitization check */
1350 if (!encode_rcv_header_entry_size(hfi1_hdrq_entsize)) { 1397 if (!encode_rcv_header_entry_size(hfi1_hdrq_entsize)) {
1351 hfi1_early_err(&pdev->dev, "Invalid HdrQ Entry size %u\n", 1398 hfi1_early_err(&pdev->dev, "Invalid HdrQ Entry size %u\n",
@@ -1422,8 +1469,11 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1422 * we still create devices, so diags, etc. can be used 1469 * we still create devices, so diags, etc. can be used
1423 * to determine cause of problem. 1470 * to determine cause of problem.
1424 */ 1471 */
1425 if (!initfail && !ret) 1472 if (!initfail && !ret) {
1426 dd->flags |= HFI1_INITTED; 1473 dd->flags |= HFI1_INITTED;
1474 /* create debufs files after init and ib register */
1475 hfi1_dbg_ibdev_init(&dd->verbs_dev);
1476 }
1427 1477
1428 j = hfi1_device_create(dd); 1478 j = hfi1_device_create(dd);
1429 if (j) 1479 if (j)
@@ -1464,6 +1514,8 @@ static void remove_one(struct pci_dev *pdev)
1464{ 1514{
1465 struct hfi1_devdata *dd = pci_get_drvdata(pdev); 1515 struct hfi1_devdata *dd = pci_get_drvdata(pdev);
1466 1516
1517 /* close debugfs files before ib unregister */
1518 hfi1_dbg_ibdev_exit(&dd->verbs_dev);
1467 /* unregister from IB core */ 1519 /* unregister from IB core */
1468 hfi1_unregister_ib_device(dd); 1520 hfi1_unregister_ib_device(dd);
1469 1521
@@ -1516,18 +1568,11 @@ int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
1516 1568
1517 if (!rcd->rcvhdrq) { 1569 if (!rcd->rcvhdrq) {
1518 dd_dev_err(dd, 1570 dd_dev_err(dd,
1519 "attempt to allocate %d bytes for ctxt %u rcvhdrq failed\n", 1571 "attempt to allocate %d bytes for ctxt %u rcvhdrq failed\n",
1520 amt, rcd->ctxt); 1572 amt, rcd->ctxt);
1521 goto bail; 1573 goto bail;
1522 } 1574 }
1523 1575
1524 /* Event mask is per device now and is in hfi1_devdata */
1525 /*if (rcd->ctxt >= dd->first_user_ctxt) {
1526 rcd->user_event_mask = vmalloc_user(PAGE_SIZE);
1527 if (!rcd->user_event_mask)
1528 goto bail_free_hdrq;
1529 }*/
1530
1531 if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { 1576 if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
1532 rcd->rcvhdrtail_kvaddr = dma_zalloc_coherent( 1577 rcd->rcvhdrtail_kvaddr = dma_zalloc_coherent(
1533 &dd->pcidev->dev, PAGE_SIZE, &phys_hdrqtail, 1578 &dd->pcidev->dev, PAGE_SIZE, &phys_hdrqtail,
@@ -1568,8 +1613,8 @@ int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
1568 1613
1569bail_free: 1614bail_free:
1570 dd_dev_err(dd, 1615 dd_dev_err(dd,
1571 "attempt to allocate 1 page for ctxt %u rcvhdrqtailaddr failed\n", 1616 "attempt to allocate 1 page for ctxt %u rcvhdrqtailaddr failed\n",
1572 rcd->ctxt); 1617 rcd->ctxt);
1573 vfree(rcd->user_event_mask); 1618 vfree(rcd->user_event_mask);
1574 rcd->user_event_mask = NULL; 1619 rcd->user_event_mask = NULL;
1575 dma_free_coherent(&dd->pcidev->dev, amt, rcd->rcvhdrq, 1620 dma_free_coherent(&dd->pcidev->dev, amt, rcd->rcvhdrq,
@@ -1659,7 +1704,7 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)
1659 if (rcd->egrbufs.rcvtid_size == round_mtu || 1704 if (rcd->egrbufs.rcvtid_size == round_mtu ||
1660 !HFI1_CAP_KGET_MASK(rcd->flags, MULTI_PKT_EGR)) { 1705 !HFI1_CAP_KGET_MASK(rcd->flags, MULTI_PKT_EGR)) {
1661 dd_dev_err(dd, "ctxt%u: Failed to allocate eager buffers\n", 1706 dd_dev_err(dd, "ctxt%u: Failed to allocate eager buffers\n",
1662 rcd->ctxt); 1707 rcd->ctxt);
1663 goto bail_rcvegrbuf_phys; 1708 goto bail_rcvegrbuf_phys;
1664 } 1709 }
1665 1710
@@ -1694,8 +1739,9 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)
1694 rcd->egrbufs.buffers[j].len)) { 1739 rcd->egrbufs.buffers[j].len)) {
1695 j++; 1740 j++;
1696 offset = 0; 1741 offset = 0;
1697 } else 1742 } else {
1698 offset += new_size; 1743 offset += new_size;
1744 }
1699 } 1745 }
1700 rcd->egrbufs.rcvtid_size = new_size; 1746 rcd->egrbufs.rcvtid_size = new_size;
1701 } 1747 }
@@ -1708,7 +1754,6 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)
1708 rcd->ctxt, rcd->egrbufs.alloced, rcd->egrbufs.rcvtid_size, 1754 rcd->ctxt, rcd->egrbufs.alloced, rcd->egrbufs.rcvtid_size,
1709 rcd->egrbufs.size); 1755 rcd->egrbufs.size);
1710 1756
1711
1712 /* 1757 /*
1713 * Set the contexts rcv array head update threshold to the closest 1758 * Set the contexts rcv array head update threshold to the closest
1714 * power of 2 (so we can use a mask instead of modulo) below half 1759 * power of 2 (so we can use a mask instead of modulo) below half
@@ -1742,14 +1787,14 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)
1742 1787
1743 for (idx = 0; idx < rcd->egrbufs.alloced; idx++) { 1788 for (idx = 0; idx < rcd->egrbufs.alloced; idx++) {
1744 hfi1_put_tid(dd, rcd->eager_base + idx, PT_EAGER, 1789 hfi1_put_tid(dd, rcd->eager_base + idx, PT_EAGER,
1745 rcd->egrbufs.rcvtids[idx].phys, order); 1790 rcd->egrbufs.rcvtids[idx].phys, order);
1746 cond_resched(); 1791 cond_resched();
1747 } 1792 }
1748 goto bail; 1793 goto bail;
1749 1794
1750bail_rcvegrbuf_phys: 1795bail_rcvegrbuf_phys:
1751 for (idx = 0; idx < rcd->egrbufs.alloced && 1796 for (idx = 0; idx < rcd->egrbufs.alloced &&
1752 rcd->egrbufs.buffers[idx].addr; 1797 rcd->egrbufs.buffers[idx].addr;
1753 idx++) { 1798 idx++) {
1754 dma_free_coherent(&dd->pcidev->dev, 1799 dma_free_coherent(&dd->pcidev->dev,
1755 rcd->egrbufs.buffers[idx].len, 1800 rcd->egrbufs.buffers[idx].len,
diff --git a/drivers/staging/rdma/hfi1/intr.c b/drivers/staging/rdma/hfi1/intr.c
index 426582b9ab65..65348d16ab2f 100644
--- a/drivers/staging/rdma/hfi1/intr.c
+++ b/drivers/staging/rdma/hfi1/intr.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -98,7 +95,7 @@ static void signal_ib_event(struct hfi1_pportdata *ppd, enum ib_event_type ev)
98 */ 95 */
99 if (!(dd->flags & HFI1_INITTED)) 96 if (!(dd->flags & HFI1_INITTED))
100 return; 97 return;
101 event.device = &dd->verbs_dev.ibdev; 98 event.device = &dd->verbs_dev.rdi.ibdev;
102 event.element.port_num = ppd->port; 99 event.element.port_num = ppd->port;
103 event.event = ev; 100 event.event = ev;
104 ib_dispatch_event(&event); 101 ib_dispatch_event(&event);
@@ -131,28 +128,26 @@ void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
131 * NOTE: This uses this device's vAU, vCU, and vl15_init for 128 * NOTE: This uses this device's vAU, vCU, and vl15_init for
132 * the remote values. Both sides must be using the values. 129 * the remote values. Both sides must be using the values.
133 */ 130 */
134 if (quick_linkup 131 if (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
135 || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
136 set_up_vl15(dd, dd->vau, dd->vl15_init); 132 set_up_vl15(dd, dd->vau, dd->vl15_init);
137 assign_remote_cm_au_table(dd, dd->vcu); 133 assign_remote_cm_au_table(dd, dd->vcu);
138 ppd->neighbor_guid = 134 ppd->neighbor_guid =
139 read_csr(dd, 135 read_csr(dd, DC_DC8051_STS_REMOTE_GUID);
140 DC_DC8051_STS_REMOTE_GUID);
141 ppd->neighbor_type = 136 ppd->neighbor_type =
142 read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) & 137 read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
143 DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK; 138 DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
144 ppd->neighbor_port_number = 139 ppd->neighbor_port_number =
145 read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) & 140 read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
146 DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK; 141 DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
147 dd_dev_info(dd, 142 dd_dev_info(dd, "Neighbor GUID: %llx Neighbor type %d\n",
148 "Neighbor GUID: %llx Neighbor type %d\n", 143 ppd->neighbor_guid,
149 ppd->neighbor_guid, 144 ppd->neighbor_type);
150 ppd->neighbor_type);
151 } 145 }
152 146
153 /* physical link went up */ 147 /* physical link went up */
154 ppd->linkup = 1; 148 ppd->linkup = 1;
155 ppd->offline_disabled_reason = OPA_LINKDOWN_REASON_NONE; 149 ppd->offline_disabled_reason =
150 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
156 151
157 /* link widths are not available until the link is fully up */ 152 /* link widths are not available until the link is fully up */
158 get_linkup_link_widths(ppd); 153 get_linkup_link_widths(ppd);
@@ -165,7 +160,7 @@ void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
165 reset_link_credits(dd); 160 reset_link_credits(dd);
166 161
167 /* freeze after a link down to guarantee a clean egress */ 162 /* freeze after a link down to guarantee a clean egress */
168 start_freeze_handling(ppd, FREEZE_SELF|FREEZE_LINK_DOWN); 163 start_freeze_handling(ppd, FREEZE_SELF | FREEZE_LINK_DOWN);
169 164
170 ev = IB_EVENT_PORT_ERR; 165 ev = IB_EVENT_PORT_ERR;
171 166
@@ -177,8 +172,6 @@ void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
177 /* notify IB of the link change */ 172 /* notify IB of the link change */
178 signal_ib_event(ppd, ev); 173 signal_ib_event(ppd, ev);
179 } 174 }
180
181
182} 175}
183 176
184/* 177/*
diff --git a/drivers/staging/rdma/hfi1/iowait.h b/drivers/staging/rdma/hfi1/iowait.h
index e8ba5606d08d..2ec6ef38d389 100644
--- a/drivers/staging/rdma/hfi1/iowait.h
+++ b/drivers/staging/rdma/hfi1/iowait.h
@@ -1,14 +1,13 @@
1#ifndef _HFI1_IOWAIT_H 1#ifndef _HFI1_IOWAIT_H
2#define _HFI1_IOWAIT_H 2#define _HFI1_IOWAIT_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -54,6 +51,8 @@
54#include <linux/workqueue.h> 51#include <linux/workqueue.h>
55#include <linux/sched.h> 52#include <linux/sched.h>
56 53
54#include "sdma_txreq.h"
55
57/* 56/*
58 * typedef (*restart_t)() - restart callback 57 * typedef (*restart_t)() - restart callback
59 * @work: pointer to work structure 58 * @work: pointer to work structure
@@ -67,9 +66,11 @@ struct sdma_engine;
67 * @list: used to add/insert into QP/PQ wait lists 66 * @list: used to add/insert into QP/PQ wait lists
68 * @tx_head: overflow list of sdma_txreq's 67 * @tx_head: overflow list of sdma_txreq's
69 * @sleep: no space callback 68 * @sleep: no space callback
70 * @wakeup: space callback 69 * @wakeup: space callback wakeup
70 * @sdma_drained: sdma count drained
71 * @iowork: workqueue overhead 71 * @iowork: workqueue overhead
72 * @wait_dma: wait for sdma_busy == 0 72 * @wait_dma: wait for sdma_busy == 0
73 * @wait_pio: wait for pio_busy == 0
73 * @sdma_busy: # of packets in flight 74 * @sdma_busy: # of packets in flight
74 * @count: total number of descriptors in tx_head'ed list 75 * @count: total number of descriptors in tx_head'ed list
75 * @tx_limit: limit for overflow queuing 76 * @tx_limit: limit for overflow queuing
@@ -101,9 +102,12 @@ struct iowait {
101 struct sdma_txreq *tx, 102 struct sdma_txreq *tx,
102 unsigned seq); 103 unsigned seq);
103 void (*wakeup)(struct iowait *wait, int reason); 104 void (*wakeup)(struct iowait *wait, int reason);
105 void (*sdma_drained)(struct iowait *wait);
104 struct work_struct iowork; 106 struct work_struct iowork;
105 wait_queue_head_t wait_dma; 107 wait_queue_head_t wait_dma;
108 wait_queue_head_t wait_pio;
106 atomic_t sdma_busy; 109 atomic_t sdma_busy;
110 atomic_t pio_busy;
107 u32 count; 111 u32 count;
108 u32 tx_limit; 112 u32 tx_limit;
109 u32 tx_count; 113 u32 tx_count;
@@ -117,7 +121,7 @@ struct iowait {
117 * @tx_limit: limit for overflow queuing 121 * @tx_limit: limit for overflow queuing
118 * @func: restart function for workqueue 122 * @func: restart function for workqueue
119 * @sleep: sleep function for no space 123 * @sleep: sleep function for no space
120 * @wakeup: wakeup function for no space 124 * @resume: wakeup function for no space
121 * 125 *
122 * This function initializes the iowait 126 * This function initializes the iowait
123 * structure embedded in the QP or PQ. 127 * structure embedded in the QP or PQ.
@@ -133,17 +137,21 @@ static inline void iowait_init(
133 struct iowait *wait, 137 struct iowait *wait,
134 struct sdma_txreq *tx, 138 struct sdma_txreq *tx,
135 unsigned seq), 139 unsigned seq),
136 void (*wakeup)(struct iowait *wait, int reason)) 140 void (*wakeup)(struct iowait *wait, int reason),
141 void (*sdma_drained)(struct iowait *wait))
137{ 142{
138 wait->count = 0; 143 wait->count = 0;
139 INIT_LIST_HEAD(&wait->list); 144 INIT_LIST_HEAD(&wait->list);
140 INIT_LIST_HEAD(&wait->tx_head); 145 INIT_LIST_HEAD(&wait->tx_head);
141 INIT_WORK(&wait->iowork, func); 146 INIT_WORK(&wait->iowork, func);
142 init_waitqueue_head(&wait->wait_dma); 147 init_waitqueue_head(&wait->wait_dma);
148 init_waitqueue_head(&wait->wait_pio);
143 atomic_set(&wait->sdma_busy, 0); 149 atomic_set(&wait->sdma_busy, 0);
150 atomic_set(&wait->pio_busy, 0);
144 wait->tx_limit = tx_limit; 151 wait->tx_limit = tx_limit;
145 wait->sleep = sleep; 152 wait->sleep = sleep;
146 wait->wakeup = wakeup; 153 wait->wakeup = wakeup;
154 wait->sdma_drained = sdma_drained;
147} 155}
148 156
149/** 157/**
@@ -174,6 +182,88 @@ static inline void iowait_sdma_drain(struct iowait *wait)
174} 182}
175 183
176/** 184/**
185 * iowait_sdma_pending() - return sdma pending count
186 *
187 * @wait: iowait structure
188 *
189 */
190static inline int iowait_sdma_pending(struct iowait *wait)
191{
192 return atomic_read(&wait->sdma_busy);
193}
194
195/**
196 * iowait_sdma_inc - note sdma io pending
197 * @wait: iowait structure
198 */
199static inline void iowait_sdma_inc(struct iowait *wait)
200{
201 atomic_inc(&wait->sdma_busy);
202}
203
204/**
205 * iowait_sdma_add - add count to pending
206 * @wait: iowait structure
207 */
208static inline void iowait_sdma_add(struct iowait *wait, int count)
209{
210 atomic_add(count, &wait->sdma_busy);
211}
212
213/**
214 * iowait_sdma_dec - note sdma complete
215 * @wait: iowait structure
216 */
217static inline int iowait_sdma_dec(struct iowait *wait)
218{
219 return atomic_dec_and_test(&wait->sdma_busy);
220}
221
222/**
223 * iowait_pio_drain() - wait for pios to drain
224 *
225 * @wait: iowait structure
226 *
227 * This will delay until the iowait pios have
228 * completed.
229 */
230static inline void iowait_pio_drain(struct iowait *wait)
231{
232 wait_event_timeout(wait->wait_pio,
233 !atomic_read(&wait->pio_busy),
234 HZ);
235}
236
237/**
238 * iowait_pio_pending() - return pio pending count
239 *
240 * @wait: iowait structure
241 *
242 */
243static inline int iowait_pio_pending(struct iowait *wait)
244{
245 return atomic_read(&wait->pio_busy);
246}
247
248/**
249 * iowait_pio_inc - note pio pending
250 * @wait: iowait structure
251 */
252static inline void iowait_pio_inc(struct iowait *wait)
253{
254 atomic_inc(&wait->pio_busy);
255}
256
257/**
258 * iowait_sdma_dec - note pio complete
259 * @wait: iowait structure
260 */
261static inline int iowait_pio_dec(struct iowait *wait)
262{
263 return atomic_dec_and_test(&wait->pio_busy);
264}
265
266/**
177 * iowait_drain_wakeup() - trigger iowait_drain() waiter 267 * iowait_drain_wakeup() - trigger iowait_drain() waiter
178 * 268 *
179 * @wait: iowait structure 269 * @wait: iowait structure
@@ -183,6 +273,28 @@ static inline void iowait_sdma_drain(struct iowait *wait)
183static inline void iowait_drain_wakeup(struct iowait *wait) 273static inline void iowait_drain_wakeup(struct iowait *wait)
184{ 274{
185 wake_up(&wait->wait_dma); 275 wake_up(&wait->wait_dma);
276 wake_up(&wait->wait_pio);
277 if (wait->sdma_drained)
278 wait->sdma_drained(wait);
279}
280
281/**
282 * iowait_get_txhead() - get packet off of iowait list
283 *
284 * @wait wait struture
285 */
286static inline struct sdma_txreq *iowait_get_txhead(struct iowait *wait)
287{
288 struct sdma_txreq *tx = NULL;
289
290 if (!list_empty(&wait->tx_head)) {
291 tx = list_first_entry(
292 &wait->tx_head,
293 struct sdma_txreq,
294 list);
295 list_del_init(&tx->list);
296 }
297 return tx;
186} 298}
187 299
188#endif 300#endif
diff --git a/drivers/staging/rdma/hfi1/keys.c b/drivers/staging/rdma/hfi1/keys.c
deleted file mode 100644
index e34f093a6b55..000000000000
--- a/drivers/staging/rdma/hfi1/keys.c
+++ /dev/null
@@ -1,356 +0,0 @@
1/*
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * BSD LICENSE
20 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include "hfi.h"
52
53/**
54 * hfi1_alloc_lkey - allocate an lkey
55 * @mr: memory region that this lkey protects
56 * @dma_region: 0->normal key, 1->restricted DMA key
57 *
58 * Returns 0 if successful, otherwise returns -errno.
59 *
60 * Increments mr reference count as required.
61 *
62 * Sets the lkey field mr for non-dma regions.
63 *
64 */
65
66int hfi1_alloc_lkey(struct hfi1_mregion *mr, int dma_region)
67{
68 unsigned long flags;
69 u32 r;
70 u32 n;
71 int ret = 0;
72 struct hfi1_ibdev *dev = to_idev(mr->pd->device);
73 struct hfi1_lkey_table *rkt = &dev->lk_table;
74
75 hfi1_get_mr(mr);
76 spin_lock_irqsave(&rkt->lock, flags);
77
78 /* special case for dma_mr lkey == 0 */
79 if (dma_region) {
80 struct hfi1_mregion *tmr;
81
82 tmr = rcu_access_pointer(dev->dma_mr);
83 if (!tmr) {
84 rcu_assign_pointer(dev->dma_mr, mr);
85 mr->lkey_published = 1;
86 } else {
87 hfi1_put_mr(mr);
88 }
89 goto success;
90 }
91
92 /* Find the next available LKEY */
93 r = rkt->next;
94 n = r;
95 for (;;) {
96 if (!rcu_access_pointer(rkt->table[r]))
97 break;
98 r = (r + 1) & (rkt->max - 1);
99 if (r == n)
100 goto bail;
101 }
102 rkt->next = (r + 1) & (rkt->max - 1);
103 /*
104 * Make sure lkey is never zero which is reserved to indicate an
105 * unrestricted LKEY.
106 */
107 rkt->gen++;
108 /*
109 * bits are capped in verbs.c to ensure enough bits for
110 * generation number
111 */
112 mr->lkey = (r << (32 - hfi1_lkey_table_size)) |
113 ((((1 << (24 - hfi1_lkey_table_size)) - 1) & rkt->gen)
114 << 8);
115 if (mr->lkey == 0) {
116 mr->lkey = 1 << 8;
117 rkt->gen++;
118 }
119 rcu_assign_pointer(rkt->table[r], mr);
120 mr->lkey_published = 1;
121success:
122 spin_unlock_irqrestore(&rkt->lock, flags);
123out:
124 return ret;
125bail:
126 hfi1_put_mr(mr);
127 spin_unlock_irqrestore(&rkt->lock, flags);
128 ret = -ENOMEM;
129 goto out;
130}
131
132/**
133 * hfi1_free_lkey - free an lkey
134 * @mr: mr to free from tables
135 */
136void hfi1_free_lkey(struct hfi1_mregion *mr)
137{
138 unsigned long flags;
139 u32 lkey = mr->lkey;
140 u32 r;
141 struct hfi1_ibdev *dev = to_idev(mr->pd->device);
142 struct hfi1_lkey_table *rkt = &dev->lk_table;
143 int freed = 0;
144
145 spin_lock_irqsave(&rkt->lock, flags);
146 if (!mr->lkey_published)
147 goto out;
148 if (lkey == 0)
149 RCU_INIT_POINTER(dev->dma_mr, NULL);
150 else {
151 r = lkey >> (32 - hfi1_lkey_table_size);
152 RCU_INIT_POINTER(rkt->table[r], NULL);
153 }
154 mr->lkey_published = 0;
155 freed++;
156out:
157 spin_unlock_irqrestore(&rkt->lock, flags);
158 if (freed) {
159 synchronize_rcu();
160 hfi1_put_mr(mr);
161 }
162}
163
164/**
165 * hfi1_lkey_ok - check IB SGE for validity and initialize
166 * @rkt: table containing lkey to check SGE against
167 * @pd: protection domain
168 * @isge: outgoing internal SGE
169 * @sge: SGE to check
170 * @acc: access flags
171 *
172 * Return 1 if valid and successful, otherwise returns 0.
173 *
174 * increments the reference count upon success
175 *
176 * Check the IB SGE for validity and initialize our internal version
177 * of it.
178 */
179int hfi1_lkey_ok(struct hfi1_lkey_table *rkt, struct hfi1_pd *pd,
180 struct hfi1_sge *isge, struct ib_sge *sge, int acc)
181{
182 struct hfi1_mregion *mr;
183 unsigned n, m;
184 size_t off;
185
186 /*
187 * We use LKEY == zero for kernel virtual addresses
188 * (see hfi1_get_dma_mr and dma.c).
189 */
190 rcu_read_lock();
191 if (sge->lkey == 0) {
192 struct hfi1_ibdev *dev = to_idev(pd->ibpd.device);
193
194 if (pd->user)
195 goto bail;
196 mr = rcu_dereference(dev->dma_mr);
197 if (!mr)
198 goto bail;
199 atomic_inc(&mr->refcount);
200 rcu_read_unlock();
201
202 isge->mr = mr;
203 isge->vaddr = (void *) sge->addr;
204 isge->length = sge->length;
205 isge->sge_length = sge->length;
206 isge->m = 0;
207 isge->n = 0;
208 goto ok;
209 }
210 mr = rcu_dereference(
211 rkt->table[(sge->lkey >> (32 - hfi1_lkey_table_size))]);
212 if (unlikely(!mr || mr->lkey != sge->lkey || mr->pd != &pd->ibpd))
213 goto bail;
214
215 off = sge->addr - mr->user_base;
216 if (unlikely(sge->addr < mr->user_base ||
217 off + sge->length > mr->length ||
218 (mr->access_flags & acc) != acc))
219 goto bail;
220 atomic_inc(&mr->refcount);
221 rcu_read_unlock();
222
223 off += mr->offset;
224 if (mr->page_shift) {
225 /*
226 page sizes are uniform power of 2 so no loop is necessary
227 entries_spanned_by_off is the number of times the loop below
228 would have executed.
229 */
230 size_t entries_spanned_by_off;
231
232 entries_spanned_by_off = off >> mr->page_shift;
233 off -= (entries_spanned_by_off << mr->page_shift);
234 m = entries_spanned_by_off / HFI1_SEGSZ;
235 n = entries_spanned_by_off % HFI1_SEGSZ;
236 } else {
237 m = 0;
238 n = 0;
239 while (off >= mr->map[m]->segs[n].length) {
240 off -= mr->map[m]->segs[n].length;
241 n++;
242 if (n >= HFI1_SEGSZ) {
243 m++;
244 n = 0;
245 }
246 }
247 }
248 isge->mr = mr;
249 isge->vaddr = mr->map[m]->segs[n].vaddr + off;
250 isge->length = mr->map[m]->segs[n].length - off;
251 isge->sge_length = sge->length;
252 isge->m = m;
253 isge->n = n;
254ok:
255 return 1;
256bail:
257 rcu_read_unlock();
258 return 0;
259}
260
261/**
262 * hfi1_rkey_ok - check the IB virtual address, length, and RKEY
263 * @qp: qp for validation
264 * @sge: SGE state
265 * @len: length of data
266 * @vaddr: virtual address to place data
267 * @rkey: rkey to check
268 * @acc: access flags
269 *
270 * Return 1 if successful, otherwise 0.
271 *
272 * increments the reference count upon success
273 */
274int hfi1_rkey_ok(struct hfi1_qp *qp, struct hfi1_sge *sge,
275 u32 len, u64 vaddr, u32 rkey, int acc)
276{
277 struct hfi1_lkey_table *rkt = &to_idev(qp->ibqp.device)->lk_table;
278 struct hfi1_mregion *mr;
279 unsigned n, m;
280 size_t off;
281
282 /*
283 * We use RKEY == zero for kernel virtual addresses
284 * (see hfi1_get_dma_mr and dma.c).
285 */
286 rcu_read_lock();
287 if (rkey == 0) {
288 struct hfi1_pd *pd = to_ipd(qp->ibqp.pd);
289 struct hfi1_ibdev *dev = to_idev(pd->ibpd.device);
290
291 if (pd->user)
292 goto bail;
293 mr = rcu_dereference(dev->dma_mr);
294 if (!mr)
295 goto bail;
296 atomic_inc(&mr->refcount);
297 rcu_read_unlock();
298
299 sge->mr = mr;
300 sge->vaddr = (void *) vaddr;
301 sge->length = len;
302 sge->sge_length = len;
303 sge->m = 0;
304 sge->n = 0;
305 goto ok;
306 }
307
308 mr = rcu_dereference(
309 rkt->table[(rkey >> (32 - hfi1_lkey_table_size))]);
310 if (unlikely(!mr || mr->lkey != rkey || qp->ibqp.pd != mr->pd))
311 goto bail;
312
313 off = vaddr - mr->iova;
314 if (unlikely(vaddr < mr->iova || off + len > mr->length ||
315 (mr->access_flags & acc) == 0))
316 goto bail;
317 atomic_inc(&mr->refcount);
318 rcu_read_unlock();
319
320 off += mr->offset;
321 if (mr->page_shift) {
322 /*
323 page sizes are uniform power of 2 so no loop is necessary
324 entries_spanned_by_off is the number of times the loop below
325 would have executed.
326 */
327 size_t entries_spanned_by_off;
328
329 entries_spanned_by_off = off >> mr->page_shift;
330 off -= (entries_spanned_by_off << mr->page_shift);
331 m = entries_spanned_by_off / HFI1_SEGSZ;
332 n = entries_spanned_by_off % HFI1_SEGSZ;
333 } else {
334 m = 0;
335 n = 0;
336 while (off >= mr->map[m]->segs[n].length) {
337 off -= mr->map[m]->segs[n].length;
338 n++;
339 if (n >= HFI1_SEGSZ) {
340 m++;
341 n = 0;
342 }
343 }
344 }
345 sge->mr = mr;
346 sge->vaddr = mr->map[m]->segs[n].vaddr + off;
347 sge->length = mr->map[m]->segs[n].length - off;
348 sge->sge_length = len;
349 sge->m = m;
350 sge->n = n;
351ok:
352 return 1;
353bail:
354 rcu_read_unlock();
355 return 0;
356}
diff --git a/drivers/staging/rdma/hfi1/mad.c b/drivers/staging/rdma/hfi1/mad.c
index 77700b818e3d..d1e7f4d7cf6f 100644
--- a/drivers/staging/rdma/hfi1/mad.c
+++ b/drivers/staging/rdma/hfi1/mad.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -55,6 +52,7 @@
55#include "hfi.h" 52#include "hfi.h"
56#include "mad.h" 53#include "mad.h"
57#include "trace.h" 54#include "trace.h"
55#include "qp.h"
58 56
59/* the reset value from the FM is supposed to be 0xffff, handle both */ 57/* the reset value from the FM is supposed to be 0xffff, handle both */
60#define OPA_LINK_WIDTH_RESET_OLD 0x0fff 58#define OPA_LINK_WIDTH_RESET_OLD 0x0fff
@@ -91,7 +89,7 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
91 int pkey_idx; 89 int pkey_idx;
92 u32 qpn = ppd_from_ibp(ibp)->sm_trap_qp; 90 u32 qpn = ppd_from_ibp(ibp)->sm_trap_qp;
93 91
94 agent = ibp->send_agent; 92 agent = ibp->rvp.send_agent;
95 if (!agent) 93 if (!agent)
96 return; 94 return;
97 95
@@ -100,7 +98,8 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
100 return; 98 return;
101 99
102 /* o14-2 */ 100 /* o14-2 */
103 if (ibp->trap_timeout && time_before(jiffies, ibp->trap_timeout)) 101 if (ibp->rvp.trap_timeout && time_before(jiffies,
102 ibp->rvp.trap_timeout))
104 return; 103 return;
105 104
106 pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY); 105 pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY);
@@ -121,42 +120,43 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
121 smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; 120 smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
122 smp->class_version = OPA_SMI_CLASS_VERSION; 121 smp->class_version = OPA_SMI_CLASS_VERSION;
123 smp->method = IB_MGMT_METHOD_TRAP; 122 smp->method = IB_MGMT_METHOD_TRAP;
124 ibp->tid++; 123 ibp->rvp.tid++;
125 smp->tid = cpu_to_be64(ibp->tid); 124 smp->tid = cpu_to_be64(ibp->rvp.tid);
126 smp->attr_id = IB_SMP_ATTR_NOTICE; 125 smp->attr_id = IB_SMP_ATTR_NOTICE;
127 /* o14-1: smp->mkey = 0; */ 126 /* o14-1: smp->mkey = 0; */
128 memcpy(smp->route.lid.data, data, len); 127 memcpy(smp->route.lid.data, data, len);
129 128
130 spin_lock_irqsave(&ibp->lock, flags); 129 spin_lock_irqsave(&ibp->rvp.lock, flags);
131 if (!ibp->sm_ah) { 130 if (!ibp->rvp.sm_ah) {
132 if (ibp->sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) { 131 if (ibp->rvp.sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
133 struct ib_ah *ah; 132 struct ib_ah *ah;
134 133
135 ah = hfi1_create_qp0_ah(ibp, ibp->sm_lid); 134 ah = hfi1_create_qp0_ah(ibp, ibp->rvp.sm_lid);
136 if (IS_ERR(ah)) 135 if (IS_ERR(ah)) {
137 ret = PTR_ERR(ah); 136 ret = PTR_ERR(ah);
138 else { 137 } else {
139 send_buf->ah = ah; 138 send_buf->ah = ah;
140 ibp->sm_ah = to_iah(ah); 139 ibp->rvp.sm_ah = ibah_to_rvtah(ah);
141 ret = 0; 140 ret = 0;
142 } 141 }
143 } else 142 } else {
144 ret = -EINVAL; 143 ret = -EINVAL;
144 }
145 } else { 145 } else {
146 send_buf->ah = &ibp->sm_ah->ibah; 146 send_buf->ah = &ibp->rvp.sm_ah->ibah;
147 ret = 0; 147 ret = 0;
148 } 148 }
149 spin_unlock_irqrestore(&ibp->lock, flags); 149 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
150 150
151 if (!ret) 151 if (!ret)
152 ret = ib_post_send_mad(send_buf, NULL); 152 ret = ib_post_send_mad(send_buf, NULL);
153 if (!ret) { 153 if (!ret) {
154 /* 4.096 usec. */ 154 /* 4.096 usec. */
155 timeout = (4096 * (1UL << ibp->subnet_timeout)) / 1000; 155 timeout = (4096 * (1UL << ibp->rvp.subnet_timeout)) / 1000;
156 ibp->trap_timeout = jiffies + usecs_to_jiffies(timeout); 156 ibp->rvp.trap_timeout = jiffies + usecs_to_jiffies(timeout);
157 } else { 157 } else {
158 ib_free_send_mad(send_buf); 158 ib_free_send_mad(send_buf);
159 ibp->trap_timeout = 0; 159 ibp->rvp.trap_timeout = 0;
160 } 160 }
161} 161}
162 162
@@ -174,10 +174,10 @@ void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
174 memset(&data, 0, sizeof(data)); 174 memset(&data, 0, sizeof(data));
175 175
176 if (trap_num == OPA_TRAP_BAD_P_KEY) 176 if (trap_num == OPA_TRAP_BAD_P_KEY)
177 ibp->pkey_violations++; 177 ibp->rvp.pkey_violations++;
178 else 178 else
179 ibp->qkey_violations++; 179 ibp->rvp.qkey_violations++;
180 ibp->n_pkt_drops++; 180 ibp->rvp.n_pkt_drops++;
181 181
182 /* Send violation trap */ 182 /* Send violation trap */
183 data.generic_type = IB_NOTICE_TYPE_SECURITY; 183 data.generic_type = IB_NOTICE_TYPE_SECURITY;
@@ -233,9 +233,12 @@ static void bad_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad,
233/* 233/*
234 * Send a Port Capability Mask Changed trap (ch. 14.3.11). 234 * Send a Port Capability Mask Changed trap (ch. 14.3.11).
235 */ 235 */
236void hfi1_cap_mask_chg(struct hfi1_ibport *ibp) 236void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num)
237{ 237{
238 struct opa_mad_notice_attr data; 238 struct opa_mad_notice_attr data;
239 struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
240 struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
241 struct hfi1_ibport *ibp = &dd->pport[port_num - 1].ibport_data;
239 u32 lid = ppd_from_ibp(ibp)->lid; 242 u32 lid = ppd_from_ibp(ibp)->lid;
240 243
241 memset(&data, 0, sizeof(data)); 244 memset(&data, 0, sizeof(data));
@@ -245,7 +248,7 @@ void hfi1_cap_mask_chg(struct hfi1_ibport *ibp)
245 data.trap_num = OPA_TRAP_CHANGE_CAPABILITY; 248 data.trap_num = OPA_TRAP_CHANGE_CAPABILITY;
246 data.issuer_lid = cpu_to_be32(lid); 249 data.issuer_lid = cpu_to_be32(lid);
247 data.ntc_144.lid = data.issuer_lid; 250 data.ntc_144.lid = data.issuer_lid;
248 data.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags); 251 data.ntc_144.new_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
249 252
250 send_trap(ibp, &data, sizeof(data)); 253 send_trap(ibp, &data, sizeof(data));
251} 254}
@@ -407,37 +410,38 @@ static int check_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad,
407 int ret = 0; 410 int ret = 0;
408 411
409 /* Is the mkey in the process of expiring? */ 412 /* Is the mkey in the process of expiring? */
410 if (ibp->mkey_lease_timeout && 413 if (ibp->rvp.mkey_lease_timeout &&
411 time_after_eq(jiffies, ibp->mkey_lease_timeout)) { 414 time_after_eq(jiffies, ibp->rvp.mkey_lease_timeout)) {
412 /* Clear timeout and mkey protection field. */ 415 /* Clear timeout and mkey protection field. */
413 ibp->mkey_lease_timeout = 0; 416 ibp->rvp.mkey_lease_timeout = 0;
414 ibp->mkeyprot = 0; 417 ibp->rvp.mkeyprot = 0;
415 } 418 }
416 419
417 if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->mkey == 0 || 420 if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->rvp.mkey == 0 ||
418 ibp->mkey == mkey) 421 ibp->rvp.mkey == mkey)
419 valid_mkey = 1; 422 valid_mkey = 1;
420 423
421 /* Unset lease timeout on any valid Get/Set/TrapRepress */ 424 /* Unset lease timeout on any valid Get/Set/TrapRepress */
422 if (valid_mkey && ibp->mkey_lease_timeout && 425 if (valid_mkey && ibp->rvp.mkey_lease_timeout &&
423 (mad->method == IB_MGMT_METHOD_GET || 426 (mad->method == IB_MGMT_METHOD_GET ||
424 mad->method == IB_MGMT_METHOD_SET || 427 mad->method == IB_MGMT_METHOD_SET ||
425 mad->method == IB_MGMT_METHOD_TRAP_REPRESS)) 428 mad->method == IB_MGMT_METHOD_TRAP_REPRESS))
426 ibp->mkey_lease_timeout = 0; 429 ibp->rvp.mkey_lease_timeout = 0;
427 430
428 if (!valid_mkey) { 431 if (!valid_mkey) {
429 switch (mad->method) { 432 switch (mad->method) {
430 case IB_MGMT_METHOD_GET: 433 case IB_MGMT_METHOD_GET:
431 /* Bad mkey not a violation below level 2 */ 434 /* Bad mkey not a violation below level 2 */
432 if (ibp->mkeyprot < 2) 435 if (ibp->rvp.mkeyprot < 2)
433 break; 436 break;
434 case IB_MGMT_METHOD_SET: 437 case IB_MGMT_METHOD_SET:
435 case IB_MGMT_METHOD_TRAP_REPRESS: 438 case IB_MGMT_METHOD_TRAP_REPRESS:
436 if (ibp->mkey_violations != 0xFFFF) 439 if (ibp->rvp.mkey_violations != 0xFFFF)
437 ++ibp->mkey_violations; 440 ++ibp->rvp.mkey_violations;
438 if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period) 441 if (!ibp->rvp.mkey_lease_timeout &&
439 ibp->mkey_lease_timeout = jiffies + 442 ibp->rvp.mkey_lease_period)
440 ibp->mkey_lease_period * HZ; 443 ibp->rvp.mkey_lease_timeout = jiffies +
444 ibp->rvp.mkey_lease_period * HZ;
441 /* Generate a trap notice. */ 445 /* Generate a trap notice. */
442 bad_mkey(ibp, mad, mkey, dr_slid, return_path, 446 bad_mkey(ibp, mad, mkey, dr_slid, return_path,
443 hop_cnt); 447 hop_cnt);
@@ -501,16 +505,6 @@ void read_ltp_rtt(struct hfi1_devdata *dd)
501 write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, reg); 505 write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, reg);
502} 506}
503 507
504static u8 __opa_porttype(struct hfi1_pportdata *ppd)
505{
506 if (qsfp_mod_present(ppd)) {
507 if (ppd->qsfp_info.cache_valid)
508 return OPA_PORT_TYPE_STANDARD;
509 return OPA_PORT_TYPE_DISCONNECTED;
510 }
511 return OPA_PORT_TYPE_UNKNOWN;
512}
513
514static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data, 508static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
515 struct ib_device *ibdev, u8 port, 509 struct ib_device *ibdev, u8 port,
516 u32 *resp_len) 510 u32 *resp_len)
@@ -522,6 +516,7 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
522 struct opa_port_info *pi = (struct opa_port_info *)data; 516 struct opa_port_info *pi = (struct opa_port_info *)data;
523 u8 mtu; 517 u8 mtu;
524 u8 credit_rate; 518 u8 credit_rate;
519 u8 is_beaconing_active;
525 u32 state; 520 u32 state;
526 u32 num_ports = OPA_AM_NPORT(am); 521 u32 num_ports = OPA_AM_NPORT(am);
527 u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); 522 u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
@@ -538,8 +533,8 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
538 ppd = dd->pport + (port - 1); 533 ppd = dd->pport + (port - 1);
539 ibp = &ppd->ibport_data; 534 ibp = &ppd->ibport_data;
540 535
541 if (ppd->vls_supported/2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) || 536 if (ppd->vls_supported / 2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) ||
542 ppd->vls_supported > ARRAY_SIZE(dd->vld)) { 537 ppd->vls_supported > ARRAY_SIZE(dd->vld)) {
543 smp->status |= IB_SMP_INVALID_FIELD; 538 smp->status |= IB_SMP_INVALID_FIELD;
544 return reply((struct ib_mad_hdr *)smp); 539 return reply((struct ib_mad_hdr *)smp);
545 } 540 }
@@ -548,14 +543,14 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
548 543
549 /* Only return the mkey if the protection field allows it. */ 544 /* Only return the mkey if the protection field allows it. */
550 if (!(smp->method == IB_MGMT_METHOD_GET && 545 if (!(smp->method == IB_MGMT_METHOD_GET &&
551 ibp->mkey != smp->mkey && 546 ibp->rvp.mkey != smp->mkey &&
552 ibp->mkeyprot == 1)) 547 ibp->rvp.mkeyprot == 1))
553 pi->mkey = ibp->mkey; 548 pi->mkey = ibp->rvp.mkey;
554 549
555 pi->subnet_prefix = ibp->gid_prefix; 550 pi->subnet_prefix = ibp->rvp.gid_prefix;
556 pi->sm_lid = cpu_to_be32(ibp->sm_lid); 551 pi->sm_lid = cpu_to_be32(ibp->rvp.sm_lid);
557 pi->ib_cap_mask = cpu_to_be32(ibp->port_cap_flags); 552 pi->ib_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
558 pi->mkey_lease_period = cpu_to_be16(ibp->mkey_lease_period); 553 pi->mkey_lease_period = cpu_to_be16(ibp->rvp.mkey_lease_period);
559 pi->sm_trap_qp = cpu_to_be32(ppd->sm_trap_qp); 554 pi->sm_trap_qp = cpu_to_be32(ppd->sm_trap_qp);
560 pi->sa_qp = cpu_to_be32(ppd->sa_qp); 555 pi->sa_qp = cpu_to_be32(ppd->sa_qp);
561 556
@@ -581,38 +576,45 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
581 if (start_of_sm_config && (state == IB_PORT_INIT)) 576 if (start_of_sm_config && (state == IB_PORT_INIT))
582 ppd->is_sm_config_started = 1; 577 ppd->is_sm_config_started = 1;
583 578
584 pi->port_phys_conf = __opa_porttype(ppd) & 0xf; 579 pi->port_phys_conf = (ppd->port_type & 0xf);
585 580
586#if PI_LED_ENABLE_SUP 581#if PI_LED_ENABLE_SUP
587 pi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4; 582 pi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4;
588 pi->port_states.ledenable_offlinereason |= 583 pi->port_states.ledenable_offlinereason |=
589 ppd->is_sm_config_started << 5; 584 ppd->is_sm_config_started << 5;
585 /*
586 * This pairs with the memory barrier in hfi1_start_led_override to
587 * ensure that we read the correct state of LED beaconing represented
588 * by led_override_timer_active
589 */
590 smp_rmb();
591 is_beaconing_active = !!atomic_read(&ppd->led_override_timer_active);
592 pi->port_states.ledenable_offlinereason |= is_beaconing_active << 6;
590 pi->port_states.ledenable_offlinereason |= 593 pi->port_states.ledenable_offlinereason |=
591 ppd->offline_disabled_reason & OPA_PI_MASK_OFFLINE_REASON; 594 ppd->offline_disabled_reason;
592#else 595#else
593 pi->port_states.offline_reason = ppd->neighbor_normal << 4; 596 pi->port_states.offline_reason = ppd->neighbor_normal << 4;
594 pi->port_states.offline_reason |= ppd->is_sm_config_started << 5; 597 pi->port_states.offline_reason |= ppd->is_sm_config_started << 5;
595 pi->port_states.offline_reason |= ppd->offline_disabled_reason & 598 pi->port_states.offline_reason |= ppd->offline_disabled_reason;
596 OPA_PI_MASK_OFFLINE_REASON;
597#endif /* PI_LED_ENABLE_SUP */ 599#endif /* PI_LED_ENABLE_SUP */
598 600
599 pi->port_states.portphysstate_portstate = 601 pi->port_states.portphysstate_portstate =
600 (hfi1_ibphys_portstate(ppd) << 4) | state; 602 (hfi1_ibphys_portstate(ppd) << 4) | state;
601 603
602 pi->mkeyprotect_lmc = (ibp->mkeyprot << 6) | ppd->lmc; 604 pi->mkeyprotect_lmc = (ibp->rvp.mkeyprot << 6) | ppd->lmc;
603 605
604 memset(pi->neigh_mtu.pvlx_to_mtu, 0, sizeof(pi->neigh_mtu.pvlx_to_mtu)); 606 memset(pi->neigh_mtu.pvlx_to_mtu, 0, sizeof(pi->neigh_mtu.pvlx_to_mtu));
605 for (i = 0; i < ppd->vls_supported; i++) { 607 for (i = 0; i < ppd->vls_supported; i++) {
606 mtu = mtu_to_enum(dd->vld[i].mtu, HFI1_DEFAULT_ACTIVE_MTU); 608 mtu = mtu_to_enum(dd->vld[i].mtu, HFI1_DEFAULT_ACTIVE_MTU);
607 if ((i % 2) == 0) 609 if ((i % 2) == 0)
608 pi->neigh_mtu.pvlx_to_mtu[i/2] |= (mtu << 4); 610 pi->neigh_mtu.pvlx_to_mtu[i / 2] |= (mtu << 4);
609 else 611 else
610 pi->neigh_mtu.pvlx_to_mtu[i/2] |= mtu; 612 pi->neigh_mtu.pvlx_to_mtu[i / 2] |= mtu;
611 } 613 }
612 /* don't forget VL 15 */ 614 /* don't forget VL 15 */
613 mtu = mtu_to_enum(dd->vld[15].mtu, 2048); 615 mtu = mtu_to_enum(dd->vld[15].mtu, 2048);
614 pi->neigh_mtu.pvlx_to_mtu[15/2] |= mtu; 616 pi->neigh_mtu.pvlx_to_mtu[15 / 2] |= mtu;
615 pi->smsl = ibp->sm_sl & OPA_PI_MASK_SMSL; 617 pi->smsl = ibp->rvp.sm_sl & OPA_PI_MASK_SMSL;
616 pi->operational_vls = hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS); 618 pi->operational_vls = hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS);
617 pi->partenforce_filterraw |= 619 pi->partenforce_filterraw |=
618 (ppd->linkinit_reason & OPA_PI_MASK_LINKINIT_REASON); 620 (ppd->linkinit_reason & OPA_PI_MASK_LINKINIT_REASON);
@@ -620,17 +622,17 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
620 pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_IN; 622 pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_IN;
621 if (ppd->part_enforce & HFI1_PART_ENFORCE_OUT) 623 if (ppd->part_enforce & HFI1_PART_ENFORCE_OUT)
622 pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_OUT; 624 pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_OUT;
623 pi->mkey_violations = cpu_to_be16(ibp->mkey_violations); 625 pi->mkey_violations = cpu_to_be16(ibp->rvp.mkey_violations);
624 /* P_KeyViolations are counted by hardware. */ 626 /* P_KeyViolations are counted by hardware. */
625 pi->pkey_violations = cpu_to_be16(ibp->pkey_violations); 627 pi->pkey_violations = cpu_to_be16(ibp->rvp.pkey_violations);
626 pi->qkey_violations = cpu_to_be16(ibp->qkey_violations); 628 pi->qkey_violations = cpu_to_be16(ibp->rvp.qkey_violations);
627 629
628 pi->vl.cap = ppd->vls_supported; 630 pi->vl.cap = ppd->vls_supported;
629 pi->vl.high_limit = cpu_to_be16(ibp->vl_high_limit); 631 pi->vl.high_limit = cpu_to_be16(ibp->rvp.vl_high_limit);
630 pi->vl.arb_high_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_CAP); 632 pi->vl.arb_high_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_CAP);
631 pi->vl.arb_low_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_LOW_CAP); 633 pi->vl.arb_low_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_LOW_CAP);
632 634
633 pi->clientrereg_subnettimeout = ibp->subnet_timeout; 635 pi->clientrereg_subnettimeout = ibp->rvp.subnet_timeout;
634 636
635 pi->port_link_mode = cpu_to_be16(OPA_PORT_LINK_MODE_OPA << 10 | 637 pi->port_link_mode = cpu_to_be16(OPA_PORT_LINK_MODE_OPA << 10 |
636 OPA_PORT_LINK_MODE_OPA << 5 | 638 OPA_PORT_LINK_MODE_OPA << 5 |
@@ -701,8 +703,10 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
701 /* read the cached value of DC_LCB_STS_ROUND_TRIP_LTP_CNT */ 703 /* read the cached value of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
702 read_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, &tmp); 704 read_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, &tmp);
703 705
704 /* this counter is 16 bits wide, but the replay_depth.wire 706 /*
705 * variable is only 8 bits */ 707 * this counter is 16 bits wide, but the replay_depth.wire
708 * variable is only 8 bits
709 */
706 if (tmp > 0xff) 710 if (tmp > 0xff)
707 tmp = 0xff; 711 tmp = 0xff;
708 pi->replay_depth.wire = tmp; 712 pi->replay_depth.wire = tmp;
@@ -749,7 +753,7 @@ static int __subn_get_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
749 return reply((struct ib_mad_hdr *)smp); 753 return reply((struct ib_mad_hdr *)smp);
750 } 754 }
751 755
752 n_blocks_avail = (u16) (npkeys/OPA_PARTITION_TABLE_BLK_SIZE) + 1; 756 n_blocks_avail = (u16)(npkeys / OPA_PARTITION_TABLE_BLK_SIZE) + 1;
753 757
754 size = (n_blocks_req * OPA_PARTITION_TABLE_BLK_SIZE) * sizeof(u16); 758 size = (n_blocks_req * OPA_PARTITION_TABLE_BLK_SIZE) * sizeof(u16);
755 759
@@ -763,7 +767,7 @@ static int __subn_get_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
763 return reply((struct ib_mad_hdr *)smp); 767 return reply((struct ib_mad_hdr *)smp);
764 } 768 }
765 769
766 p = (__be16 *) data; 770 p = (__be16 *)data;
767 q = (u16 *)data; 771 q = (u16 *)data;
768 /* get the real pkeys if we are requesting the first block */ 772 /* get the real pkeys if we are requesting the first block */
769 if (start_block == 0) { 773 if (start_block == 0) {
@@ -772,9 +776,9 @@ static int __subn_get_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
772 p[i] = cpu_to_be16(q[i]); 776 p[i] = cpu_to_be16(q[i]);
773 if (resp_len) 777 if (resp_len)
774 *resp_len += size; 778 *resp_len += size;
775 } else 779 } else {
776 smp->status |= IB_SMP_INVALID_FIELD; 780 smp->status |= IB_SMP_INVALID_FIELD;
777 781 }
778 return reply((struct ib_mad_hdr *)smp); 782 return reply((struct ib_mad_hdr *)smp);
779} 783}
780 784
@@ -901,8 +905,8 @@ static int port_states_transition_allowed(struct hfi1_pportdata *ppd,
901 u32 logical_old = driver_logical_state(ppd); 905 u32 logical_old = driver_logical_state(ppd);
902 int ret, logical_allowed, physical_allowed; 906 int ret, logical_allowed, physical_allowed;
903 907
904 logical_allowed = ret = 908 ret = logical_transition_allowed(logical_old, logical_new);
905 logical_transition_allowed(logical_old, logical_new); 909 logical_allowed = ret;
906 910
907 if (ret == HFI_TRANSITION_DISALLOWED || 911 if (ret == HFI_TRANSITION_DISALLOWED ||
908 ret == HFI_TRANSITION_UNDEFINED) { 912 ret == HFI_TRANSITION_UNDEFINED) {
@@ -912,8 +916,8 @@ static int port_states_transition_allowed(struct hfi1_pportdata *ppd,
912 return ret; 916 return ret;
913 } 917 }
914 918
915 physical_allowed = ret = 919 ret = physical_transition_allowed(physical_old, physical_new);
916 physical_transition_allowed(physical_old, physical_new); 920 physical_allowed = ret;
917 921
918 if (ret == HFI_TRANSITION_DISALLOWED || 922 if (ret == HFI_TRANSITION_DISALLOWED ||
919 ret == HFI_TRANSITION_UNDEFINED) { 923 ret == HFI_TRANSITION_UNDEFINED) {
@@ -928,6 +932,14 @@ static int port_states_transition_allowed(struct hfi1_pportdata *ppd,
928 return HFI_TRANSITION_IGNORED; 932 return HFI_TRANSITION_IGNORED;
929 933
930 /* 934 /*
935 * A change request of Physical Port State from
936 * 'Offline' to 'Polling' should be ignored.
937 */
938 if ((physical_old == OPA_PORTPHYSSTATE_OFFLINE) &&
939 (physical_new == IB_PORTPHYSSTATE_POLLING))
940 return HFI_TRANSITION_IGNORED;
941
942 /*
931 * Either physical_allowed or logical_allowed is 943 * Either physical_allowed or logical_allowed is
932 * HFI_TRANSITION_ALLOWED. 944 * HFI_TRANSITION_ALLOWED.
933 */ 945 */
@@ -972,16 +984,15 @@ static int set_port_states(struct hfi1_pportdata *ppd, struct opa_smp *smp,
972 break; 984 break;
973 /* FALLTHROUGH */ 985 /* FALLTHROUGH */
974 case IB_PORT_DOWN: 986 case IB_PORT_DOWN:
975 if (phys_state == IB_PORTPHYSSTATE_NOP) 987 if (phys_state == IB_PORTPHYSSTATE_NOP) {
976 link_state = HLS_DN_DOWNDEF; 988 link_state = HLS_DN_DOWNDEF;
977 else if (phys_state == IB_PORTPHYSSTATE_POLLING) { 989 } else if (phys_state == IB_PORTPHYSSTATE_POLLING) {
978 link_state = HLS_DN_POLL; 990 link_state = HLS_DN_POLL;
979 set_link_down_reason(ppd, 991 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_FM_BOUNCE,
980 OPA_LINKDOWN_REASON_FM_BOUNCE, 0, 992 0, OPA_LINKDOWN_REASON_FM_BOUNCE);
981 OPA_LINKDOWN_REASON_FM_BOUNCE); 993 } else if (phys_state == IB_PORTPHYSSTATE_DISABLED) {
982 } else if (phys_state == IB_PORTPHYSSTATE_DISABLED)
983 link_state = HLS_DN_DISABLE; 994 link_state = HLS_DN_DISABLE;
984 else { 995 } else {
985 pr_warn("SubnSet(OPA_PortInfo) invalid physical state 0x%x\n", 996 pr_warn("SubnSet(OPA_PortInfo) invalid physical state 0x%x\n",
986 phys_state); 997 phys_state);
987 smp->status |= IB_SMP_INVALID_FIELD; 998 smp->status |= IB_SMP_INVALID_FIELD;
@@ -991,11 +1002,11 @@ static int set_port_states(struct hfi1_pportdata *ppd, struct opa_smp *smp,
991 set_link_state(ppd, link_state); 1002 set_link_state(ppd, link_state);
992 if (link_state == HLS_DN_DISABLE && 1003 if (link_state == HLS_DN_DISABLE &&
993 (ppd->offline_disabled_reason > 1004 (ppd->offline_disabled_reason >
994 OPA_LINKDOWN_REASON_SMA_DISABLED || 1005 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED) ||
995 ppd->offline_disabled_reason == 1006 ppd->offline_disabled_reason ==
996 OPA_LINKDOWN_REASON_NONE)) 1007 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
997 ppd->offline_disabled_reason = 1008 ppd->offline_disabled_reason =
998 OPA_LINKDOWN_REASON_SMA_DISABLED; 1009 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
999 /* 1010 /*
1000 * Don't send a reply if the response would be sent 1011 * Don't send a reply if the response would be sent
1001 * through the disabled port. 1012 * through the disabled port.
@@ -1091,13 +1102,13 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1091 1102
1092 ls_old = driver_lstate(ppd); 1103 ls_old = driver_lstate(ppd);
1093 1104
1094 ibp->mkey = pi->mkey; 1105 ibp->rvp.mkey = pi->mkey;
1095 ibp->gid_prefix = pi->subnet_prefix; 1106 ibp->rvp.gid_prefix = pi->subnet_prefix;
1096 ibp->mkey_lease_period = be16_to_cpu(pi->mkey_lease_period); 1107 ibp->rvp.mkey_lease_period = be16_to_cpu(pi->mkey_lease_period);
1097 1108
1098 /* Must be a valid unicast LID address. */ 1109 /* Must be a valid unicast LID address. */
1099 if ((lid == 0 && ls_old > IB_PORT_INIT) || 1110 if ((lid == 0 && ls_old > IB_PORT_INIT) ||
1100 lid >= HFI1_MULTICAST_LID_BASE) { 1111 lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
1101 smp->status |= IB_SMP_INVALID_FIELD; 1112 smp->status |= IB_SMP_INVALID_FIELD;
1102 pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n", 1113 pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n",
1103 lid); 1114 lid);
@@ -1130,23 +1141,23 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1130 1141
1131 /* Must be a valid unicast LID address. */ 1142 /* Must be a valid unicast LID address. */
1132 if ((smlid == 0 && ls_old > IB_PORT_INIT) || 1143 if ((smlid == 0 && ls_old > IB_PORT_INIT) ||
1133 smlid >= HFI1_MULTICAST_LID_BASE) { 1144 smlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
1134 smp->status |= IB_SMP_INVALID_FIELD; 1145 smp->status |= IB_SMP_INVALID_FIELD;
1135 pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid); 1146 pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid);
1136 } else if (smlid != ibp->sm_lid || msl != ibp->sm_sl) { 1147 } else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) {
1137 pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid); 1148 pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid);
1138 spin_lock_irqsave(&ibp->lock, flags); 1149 spin_lock_irqsave(&ibp->rvp.lock, flags);
1139 if (ibp->sm_ah) { 1150 if (ibp->rvp.sm_ah) {
1140 if (smlid != ibp->sm_lid) 1151 if (smlid != ibp->rvp.sm_lid)
1141 ibp->sm_ah->attr.dlid = smlid; 1152 ibp->rvp.sm_ah->attr.dlid = smlid;
1142 if (msl != ibp->sm_sl) 1153 if (msl != ibp->rvp.sm_sl)
1143 ibp->sm_ah->attr.sl = msl; 1154 ibp->rvp.sm_ah->attr.sl = msl;
1144 } 1155 }
1145 spin_unlock_irqrestore(&ibp->lock, flags); 1156 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
1146 if (smlid != ibp->sm_lid) 1157 if (smlid != ibp->rvp.sm_lid)
1147 ibp->sm_lid = smlid; 1158 ibp->rvp.sm_lid = smlid;
1148 if (msl != ibp->sm_sl) 1159 if (msl != ibp->rvp.sm_sl)
1149 ibp->sm_sl = msl; 1160 ibp->rvp.sm_sl = msl;
1150 event.event = IB_EVENT_SM_CHANGE; 1161 event.event = IB_EVENT_SM_CHANGE;
1151 ib_dispatch_event(&event); 1162 ib_dispatch_event(&event);
1152 } 1163 }
@@ -1167,8 +1178,8 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1167 ppd->port_error_action = be32_to_cpu(pi->port_error_action); 1178 ppd->port_error_action = be32_to_cpu(pi->port_error_action);
1168 lwe = be16_to_cpu(pi->link_width.enabled); 1179 lwe = be16_to_cpu(pi->link_width.enabled);
1169 if (lwe) { 1180 if (lwe) {
1170 if (lwe == OPA_LINK_WIDTH_RESET 1181 if (lwe == OPA_LINK_WIDTH_RESET ||
1171 || lwe == OPA_LINK_WIDTH_RESET_OLD) 1182 lwe == OPA_LINK_WIDTH_RESET_OLD)
1172 set_link_width_enabled(ppd, ppd->link_width_supported); 1183 set_link_width_enabled(ppd, ppd->link_width_supported);
1173 else if ((lwe & ~ppd->link_width_supported) == 0) 1184 else if ((lwe & ~ppd->link_width_supported) == 0)
1174 set_link_width_enabled(ppd, lwe); 1185 set_link_width_enabled(ppd, lwe);
@@ -1177,19 +1188,21 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1177 } 1188 }
1178 lwe = be16_to_cpu(pi->link_width_downgrade.enabled); 1189 lwe = be16_to_cpu(pi->link_width_downgrade.enabled);
1179 /* LWD.E is always applied - 0 means "disabled" */ 1190 /* LWD.E is always applied - 0 means "disabled" */
1180 if (lwe == OPA_LINK_WIDTH_RESET 1191 if (lwe == OPA_LINK_WIDTH_RESET ||
1181 || lwe == OPA_LINK_WIDTH_RESET_OLD) { 1192 lwe == OPA_LINK_WIDTH_RESET_OLD) {
1182 set_link_width_downgrade_enabled(ppd, 1193 set_link_width_downgrade_enabled(ppd,
1183 ppd->link_width_downgrade_supported); 1194 ppd->
1195 link_width_downgrade_supported
1196 );
1184 } else if ((lwe & ~ppd->link_width_downgrade_supported) == 0) { 1197 } else if ((lwe & ~ppd->link_width_downgrade_supported) == 0) {
1185 /* only set and apply if something changed */ 1198 /* only set and apply if something changed */
1186 if (lwe != ppd->link_width_downgrade_enabled) { 1199 if (lwe != ppd->link_width_downgrade_enabled) {
1187 set_link_width_downgrade_enabled(ppd, lwe); 1200 set_link_width_downgrade_enabled(ppd, lwe);
1188 call_link_downgrade_policy = 1; 1201 call_link_downgrade_policy = 1;
1189 } 1202 }
1190 } else 1203 } else {
1191 smp->status |= IB_SMP_INVALID_FIELD; 1204 smp->status |= IB_SMP_INVALID_FIELD;
1192 1205 }
1193 lse = be16_to_cpu(pi->link_speed.enabled); 1206 lse = be16_to_cpu(pi->link_speed.enabled);
1194 if (lse) { 1207 if (lse) {
1195 if (lse & be16_to_cpu(pi->link_speed.supported)) 1208 if (lse & be16_to_cpu(pi->link_speed.supported))
@@ -1198,22 +1211,24 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1198 smp->status |= IB_SMP_INVALID_FIELD; 1211 smp->status |= IB_SMP_INVALID_FIELD;
1199 } 1212 }
1200 1213
1201 ibp->mkeyprot = (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6; 1214 ibp->rvp.mkeyprot =
1202 ibp->vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF; 1215 (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6;
1216 ibp->rvp.vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF;
1203 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_LIMIT, 1217 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_LIMIT,
1204 ibp->vl_high_limit); 1218 ibp->rvp.vl_high_limit);
1205 1219
1206 if (ppd->vls_supported/2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) || 1220 if (ppd->vls_supported / 2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) ||
1207 ppd->vls_supported > ARRAY_SIZE(dd->vld)) { 1221 ppd->vls_supported > ARRAY_SIZE(dd->vld)) {
1208 smp->status |= IB_SMP_INVALID_FIELD; 1222 smp->status |= IB_SMP_INVALID_FIELD;
1209 return reply((struct ib_mad_hdr *)smp); 1223 return reply((struct ib_mad_hdr *)smp);
1210 } 1224 }
1211 for (i = 0; i < ppd->vls_supported; i++) { 1225 for (i = 0; i < ppd->vls_supported; i++) {
1212 if ((i % 2) == 0) 1226 if ((i % 2) == 0)
1213 mtu = enum_to_mtu((pi->neigh_mtu.pvlx_to_mtu[i/2] >> 4) 1227 mtu = enum_to_mtu((pi->neigh_mtu.pvlx_to_mtu[i / 2] >>
1214 & 0xF); 1228 4) & 0xF);
1215 else 1229 else
1216 mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[i/2] & 0xF); 1230 mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[i / 2] &
1231 0xF);
1217 if (mtu == 0xffff) { 1232 if (mtu == 0xffff) {
1218 pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n", 1233 pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n",
1219 mtu, 1234 mtu,
@@ -1223,8 +1238,8 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1223 } 1238 }
1224 if (dd->vld[i].mtu != mtu) { 1239 if (dd->vld[i].mtu != mtu) {
1225 dd_dev_info(dd, 1240 dd_dev_info(dd,
1226 "MTU change on vl %d from %d to %d\n", 1241 "MTU change on vl %d from %d to %d\n",
1227 i, dd->vld[i].mtu, mtu); 1242 i, dd->vld[i].mtu, mtu);
1228 dd->vld[i].mtu = mtu; 1243 dd->vld[i].mtu = mtu;
1229 call_set_mtu++; 1244 call_set_mtu++;
1230 } 1245 }
@@ -1232,13 +1247,13 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1232 /* As per OPAV1 spec: VL15 must support and be configured 1247 /* As per OPAV1 spec: VL15 must support and be configured
1233 * for operation with a 2048 or larger MTU. 1248 * for operation with a 2048 or larger MTU.
1234 */ 1249 */
1235 mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[15/2] & 0xF); 1250 mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[15 / 2] & 0xF);
1236 if (mtu < 2048 || mtu == 0xffff) 1251 if (mtu < 2048 || mtu == 0xffff)
1237 mtu = 2048; 1252 mtu = 2048;
1238 if (dd->vld[15].mtu != mtu) { 1253 if (dd->vld[15].mtu != mtu) {
1239 dd_dev_info(dd, 1254 dd_dev_info(dd,
1240 "MTU change on vl 15 from %d to %d\n", 1255 "MTU change on vl 15 from %d to %d\n",
1241 dd->vld[15].mtu, mtu); 1256 dd->vld[15].mtu, mtu);
1242 dd->vld[15].mtu = mtu; 1257 dd->vld[15].mtu = mtu;
1243 call_set_mtu++; 1258 call_set_mtu++;
1244 } 1259 }
@@ -1254,21 +1269,21 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
1254 smp->status |= IB_SMP_INVALID_FIELD; 1269 smp->status |= IB_SMP_INVALID_FIELD;
1255 } else { 1270 } else {
1256 if (hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS, 1271 if (hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS,
1257 vls) == -EINVAL) 1272 vls) == -EINVAL)
1258 smp->status |= IB_SMP_INVALID_FIELD; 1273 smp->status |= IB_SMP_INVALID_FIELD;
1259 } 1274 }
1260 } 1275 }
1261 1276
1262 if (pi->mkey_violations == 0) 1277 if (pi->mkey_violations == 0)
1263 ibp->mkey_violations = 0; 1278 ibp->rvp.mkey_violations = 0;
1264 1279
1265 if (pi->pkey_violations == 0) 1280 if (pi->pkey_violations == 0)
1266 ibp->pkey_violations = 0; 1281 ibp->rvp.pkey_violations = 0;
1267 1282
1268 if (pi->qkey_violations == 0) 1283 if (pi->qkey_violations == 0)
1269 ibp->qkey_violations = 0; 1284 ibp->rvp.qkey_violations = 0;
1270 1285
1271 ibp->subnet_timeout = 1286 ibp->rvp.subnet_timeout =
1272 pi->clientrereg_subnettimeout & OPA_PI_MASK_SUBNET_TIMEOUT; 1287 pi->clientrereg_subnettimeout & OPA_PI_MASK_SUBNET_TIMEOUT;
1273 1288
1274 crc_enabled = be16_to_cpu(pi->port_ltp_crc_mode); 1289 crc_enabled = be16_to_cpu(pi->port_ltp_crc_mode);
@@ -1388,7 +1403,7 @@ static int set_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys)
1388 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0); 1403 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
1389 1404
1390 event.event = IB_EVENT_PKEY_CHANGE; 1405 event.event = IB_EVENT_PKEY_CHANGE;
1391 event.device = &dd->verbs_dev.ibdev; 1406 event.device = &dd->verbs_dev.rdi.ibdev;
1392 event.element.port_num = port; 1407 event.element.port_num = port;
1393 ib_dispatch_event(&event); 1408 ib_dispatch_event(&event);
1394 } 1409 }
@@ -1402,7 +1417,7 @@ static int __subn_set_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
1402 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1417 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1403 u32 n_blocks_sent = OPA_AM_NBLK(am); 1418 u32 n_blocks_sent = OPA_AM_NBLK(am);
1404 u32 start_block = am & 0x7ff; 1419 u32 start_block = am & 0x7ff;
1405 u16 *p = (u16 *) data; 1420 u16 *p = (u16 *)data;
1406 __be16 *q = (__be16 *)data; 1421 __be16 *q = (__be16 *)data;
1407 int i; 1422 int i;
1408 u16 n_blocks_avail; 1423 u16 n_blocks_avail;
@@ -1415,7 +1430,7 @@ static int __subn_set_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
1415 return reply((struct ib_mad_hdr *)smp); 1430 return reply((struct ib_mad_hdr *)smp);
1416 } 1431 }
1417 1432
1418 n_blocks_avail = (u16)(npkeys/OPA_PARTITION_TABLE_BLK_SIZE) + 1; 1433 n_blocks_avail = (u16)(npkeys / OPA_PARTITION_TABLE_BLK_SIZE) + 1;
1419 1434
1420 if (start_block + n_blocks_sent > n_blocks_avail || 1435 if (start_block + n_blocks_sent > n_blocks_avail ||
1421 n_blocks_sent > OPA_NUM_PKEY_BLOCKS_PER_SMP) { 1436 n_blocks_sent > OPA_NUM_PKEY_BLOCKS_PER_SMP) {
@@ -1514,14 +1529,22 @@ static int __subn_set_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data,
1514 struct hfi1_ibport *ibp = to_iport(ibdev, port); 1529 struct hfi1_ibport *ibp = to_iport(ibdev, port);
1515 u8 *p = data; 1530 u8 *p = data;
1516 int i; 1531 int i;
1532 u8 sc;
1517 1533
1518 if (am) { 1534 if (am) {
1519 smp->status |= IB_SMP_INVALID_FIELD; 1535 smp->status |= IB_SMP_INVALID_FIELD;
1520 return reply((struct ib_mad_hdr *)smp); 1536 return reply((struct ib_mad_hdr *)smp);
1521 } 1537 }
1522 1538
1523 for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) 1539 for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) {
1524 ibp->sl_to_sc[i] = *p++; 1540 sc = *p++;
1541 if (ibp->sl_to_sc[i] != sc) {
1542 ibp->sl_to_sc[i] = sc;
1543
1544 /* Put all stale qps into error state */
1545 hfi1_error_port_qps(ibp, i);
1546 }
1547 }
1525 1548
1526 return __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, resp_len); 1549 return __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, resp_len);
1527} 1550}
@@ -1574,7 +1597,7 @@ static int __subn_get_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data,
1574{ 1597{
1575 u32 n_blocks = OPA_AM_NBLK(am); 1598 u32 n_blocks = OPA_AM_NBLK(am);
1576 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1599 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1577 void *vp = (void *) data; 1600 void *vp = (void *)data;
1578 size_t size = 4 * sizeof(u64); 1601 size_t size = 4 * sizeof(u64);
1579 1602
1580 if (n_blocks != 1) { 1603 if (n_blocks != 1) {
@@ -1597,7 +1620,7 @@ static int __subn_set_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data,
1597 u32 n_blocks = OPA_AM_NBLK(am); 1620 u32 n_blocks = OPA_AM_NBLK(am);
1598 int async_update = OPA_AM_ASYNC(am); 1621 int async_update = OPA_AM_ASYNC(am);
1599 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1622 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1600 void *vp = (void *) data; 1623 void *vp = (void *)data;
1601 struct hfi1_pportdata *ppd; 1624 struct hfi1_pportdata *ppd;
1602 int lstate; 1625 int lstate;
1603 1626
@@ -1609,8 +1632,10 @@ static int __subn_set_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data,
1609 /* IB numbers ports from 1, hw from 0 */ 1632 /* IB numbers ports from 1, hw from 0 */
1610 ppd = dd->pport + (port - 1); 1633 ppd = dd->pport + (port - 1);
1611 lstate = driver_lstate(ppd); 1634 lstate = driver_lstate(ppd);
1612 /* it's known that async_update is 0 by this point, but include 1635 /*
1613 * the explicit check for clarity */ 1636 * it's known that async_update is 0 by this point, but include
1637 * the explicit check for clarity
1638 */
1614 if (!async_update && 1639 if (!async_update &&
1615 (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE)) { 1640 (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE)) {
1616 smp->status |= IB_SMP_INVALID_FIELD; 1641 smp->status |= IB_SMP_INVALID_FIELD;
@@ -1629,7 +1654,7 @@ static int __subn_get_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data,
1629 u32 n_blocks = OPA_AM_NPORT(am); 1654 u32 n_blocks = OPA_AM_NPORT(am);
1630 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1655 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1631 struct hfi1_pportdata *ppd; 1656 struct hfi1_pportdata *ppd;
1632 void *vp = (void *) data; 1657 void *vp = (void *)data;
1633 int size; 1658 int size;
1634 1659
1635 if (n_blocks != 1) { 1660 if (n_blocks != 1) {
@@ -1654,7 +1679,7 @@ static int __subn_set_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data,
1654 u32 n_blocks = OPA_AM_NPORT(am); 1679 u32 n_blocks = OPA_AM_NPORT(am);
1655 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1680 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1656 struct hfi1_pportdata *ppd; 1681 struct hfi1_pportdata *ppd;
1657 void *vp = (void *) data; 1682 void *vp = (void *)data;
1658 int lstate; 1683 int lstate;
1659 1684
1660 if (n_blocks != 1) { 1685 if (n_blocks != 1) {
@@ -1687,7 +1712,7 @@ static int __subn_get_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
1687 u32 lstate; 1712 u32 lstate;
1688 struct hfi1_ibport *ibp; 1713 struct hfi1_ibport *ibp;
1689 struct hfi1_pportdata *ppd; 1714 struct hfi1_pportdata *ppd;
1690 struct opa_port_state_info *psi = (struct opa_port_state_info *) data; 1715 struct opa_port_state_info *psi = (struct opa_port_state_info *)data;
1691 1716
1692 if (nports != 1) { 1717 if (nports != 1) {
1693 smp->status |= IB_SMP_INVALID_FIELD; 1718 smp->status |= IB_SMP_INVALID_FIELD;
@@ -1707,12 +1732,11 @@ static int __subn_get_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
1707 psi->port_states.ledenable_offlinereason |= 1732 psi->port_states.ledenable_offlinereason |=
1708 ppd->is_sm_config_started << 5; 1733 ppd->is_sm_config_started << 5;
1709 psi->port_states.ledenable_offlinereason |= 1734 psi->port_states.ledenable_offlinereason |=
1710 ppd->offline_disabled_reason & OPA_PI_MASK_OFFLINE_REASON; 1735 ppd->offline_disabled_reason;
1711#else 1736#else
1712 psi->port_states.offline_reason = ppd->neighbor_normal << 4; 1737 psi->port_states.offline_reason = ppd->neighbor_normal << 4;
1713 psi->port_states.offline_reason |= ppd->is_sm_config_started << 5; 1738 psi->port_states.offline_reason |= ppd->is_sm_config_started << 5;
1714 psi->port_states.offline_reason |= ppd->offline_disabled_reason & 1739 psi->port_states.offline_reason |= ppd->offline_disabled_reason;
1715 OPA_PI_MASK_OFFLINE_REASON;
1716#endif /* PI_LED_ENABLE_SUP */ 1740#endif /* PI_LED_ENABLE_SUP */
1717 1741
1718 psi->port_states.portphysstate_portstate = 1742 psi->port_states.portphysstate_portstate =
@@ -1737,7 +1761,7 @@ static int __subn_set_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
1737 u8 ls_new, ps_new; 1761 u8 ls_new, ps_new;
1738 struct hfi1_ibport *ibp; 1762 struct hfi1_ibport *ibp;
1739 struct hfi1_pportdata *ppd; 1763 struct hfi1_pportdata *ppd;
1740 struct opa_port_state_info *psi = (struct opa_port_state_info *) data; 1764 struct opa_port_state_info *psi = (struct opa_port_state_info *)data;
1741 int ret, invalid = 0; 1765 int ret, invalid = 0;
1742 1766
1743 if (nports != 1) { 1767 if (nports != 1) {
@@ -1782,14 +1806,16 @@ static int __subn_get_opa_cable_info(struct opa_smp *smp, u32 am, u8 *data,
1782 u32 len = OPA_AM_CI_LEN(am) + 1; 1806 u32 len = OPA_AM_CI_LEN(am) + 1;
1783 int ret; 1807 int ret;
1784 1808
1785#define __CI_PAGE_SIZE (1 << 7) /* 128 bytes */ 1809#define __CI_PAGE_SIZE BIT(7) /* 128 bytes */
1786#define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1) 1810#define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1)
1787#define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK) 1811#define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK)
1788 1812
1789 /* check that addr is within spec, and 1813 /*
1790 * addr and (addr + len - 1) are on the same "page" */ 1814 * check that addr is within spec, and
1815 * addr and (addr + len - 1) are on the same "page"
1816 */
1791 if (addr >= 4096 || 1817 if (addr >= 4096 ||
1792 (__CI_PAGE_NUM(addr) != __CI_PAGE_NUM(addr + len - 1))) { 1818 (__CI_PAGE_NUM(addr) != __CI_PAGE_NUM(addr + len - 1))) {
1793 smp->status |= IB_SMP_INVALID_FIELD; 1819 smp->status |= IB_SMP_INVALID_FIELD;
1794 return reply((struct ib_mad_hdr *)smp); 1820 return reply((struct ib_mad_hdr *)smp);
1795 } 1821 }
@@ -1823,7 +1849,7 @@ static int __subn_get_opa_bct(struct opa_smp *smp, u32 am, u8 *data,
1823 u32 num_ports = OPA_AM_NPORT(am); 1849 u32 num_ports = OPA_AM_NPORT(am);
1824 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1850 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1825 struct hfi1_pportdata *ppd; 1851 struct hfi1_pportdata *ppd;
1826 struct buffer_control *p = (struct buffer_control *) data; 1852 struct buffer_control *p = (struct buffer_control *)data;
1827 int size; 1853 int size;
1828 1854
1829 if (num_ports != 1) { 1855 if (num_ports != 1) {
@@ -1846,7 +1872,7 @@ static int __subn_set_opa_bct(struct opa_smp *smp, u32 am, u8 *data,
1846 u32 num_ports = OPA_AM_NPORT(am); 1872 u32 num_ports = OPA_AM_NPORT(am);
1847 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1873 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1848 struct hfi1_pportdata *ppd; 1874 struct hfi1_pportdata *ppd;
1849 struct buffer_control *p = (struct buffer_control *) data; 1875 struct buffer_control *p = (struct buffer_control *)data;
1850 1876
1851 if (num_ports != 1) { 1877 if (num_ports != 1) {
1852 smp->status |= IB_SMP_INVALID_FIELD; 1878 smp->status |= IB_SMP_INVALID_FIELD;
@@ -1919,13 +1945,15 @@ static int __subn_set_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data,
1919 1945
1920 switch (section) { 1946 switch (section) {
1921 case OPA_VLARB_LOW_ELEMENTS: 1947 case OPA_VLARB_LOW_ELEMENTS:
1922 (void) fm_set_table(ppd, FM_TBL_VL_LOW_ARB, p); 1948 (void)fm_set_table(ppd, FM_TBL_VL_LOW_ARB, p);
1923 break; 1949 break;
1924 case OPA_VLARB_HIGH_ELEMENTS: 1950 case OPA_VLARB_HIGH_ELEMENTS:
1925 (void) fm_set_table(ppd, FM_TBL_VL_HIGH_ARB, p); 1951 (void)fm_set_table(ppd, FM_TBL_VL_HIGH_ARB, p);
1926 break; 1952 break;
1927 /* neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX 1953 /*
1928 * can be changed from the default values */ 1954 * neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX
1955 * can be changed from the default values
1956 */
1929 case OPA_VLARB_PREEMPT_ELEMENTS: 1957 case OPA_VLARB_PREEMPT_ELEMENTS:
1930 /* FALLTHROUGH */ 1958 /* FALLTHROUGH */
1931 case OPA_VLARB_PREEMPT_MATRIX: 1959 case OPA_VLARB_PREEMPT_MATRIX:
@@ -2137,8 +2165,10 @@ struct opa_port_data_counters_msg {
2137}; 2165};
2138 2166
2139struct opa_port_error_counters64_msg { 2167struct opa_port_error_counters64_msg {
2140 /* Request contains first two fields, response contains the 2168 /*
2141 * whole magilla */ 2169 * Request contains first two fields, response contains the
2170 * whole magilla
2171 */
2142 __be64 port_select_mask[4]; 2172 __be64 port_select_mask[4];
2143 __be32 vl_select_mask; 2173 __be32 vl_select_mask;
2144 2174
@@ -2172,7 +2202,6 @@ struct opa_port_error_info_msg {
2172 __be32 error_info_select_mask; 2202 __be32 error_info_select_mask;
2173 __be32 reserved1; 2203 __be32 reserved1;
2174 struct _port_ei { 2204 struct _port_ei {
2175
2176 u8 port_number; 2205 u8 port_number;
2177 u8 reserved2[7]; 2206 u8 reserved2[7];
2178 2207
@@ -2251,7 +2280,7 @@ enum error_info_selects {
2251}; 2280};
2252 2281
2253static int pma_get_opa_classportinfo(struct opa_pma_mad *pmp, 2282static int pma_get_opa_classportinfo(struct opa_pma_mad *pmp,
2254 struct ib_device *ibdev, u32 *resp_len) 2283 struct ib_device *ibdev, u32 *resp_len)
2255{ 2284{
2256 struct opa_class_port_info *p = 2285 struct opa_class_port_info *p =
2257 (struct opa_class_port_info *)pmp->data; 2286 (struct opa_class_port_info *)pmp->data;
@@ -2299,9 +2328,9 @@ static void a0_portstatus(struct hfi1_pportdata *ppd,
2299 } 2328 }
2300} 2329}
2301 2330
2302
2303static int pma_get_opa_portstatus(struct opa_pma_mad *pmp, 2331static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
2304 struct ib_device *ibdev, u8 port, u32 *resp_len) 2332 struct ib_device *ibdev,
2333 u8 port, u32 *resp_len)
2305{ 2334{
2306 struct opa_port_status_req *req = 2335 struct opa_port_status_req *req =
2307 (struct opa_port_status_req *)pmp->data; 2336 (struct opa_port_status_req *)pmp->data;
@@ -2326,8 +2355,8 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
2326 return reply((struct ib_mad_hdr *)pmp); 2355 return reply((struct ib_mad_hdr *)pmp);
2327 } 2356 }
2328 2357
2329 if (nports != 1 || (port_num && port_num != port) 2358 if (nports != 1 || (port_num && port_num != port) ||
2330 || num_vls > OPA_MAX_VLS || (vl_select_mask & ~VL_MASK_ALL)) { 2359 num_vls > OPA_MAX_VLS || (vl_select_mask & ~VL_MASK_ALL)) {
2331 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; 2360 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
2332 return reply((struct ib_mad_hdr *)pmp); 2361 return reply((struct ib_mad_hdr *)pmp);
2333 } 2362 }
@@ -2357,7 +2386,7 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
2357 CNTR_INVALID_VL)); 2386 CNTR_INVALID_VL));
2358 rsp->port_multicast_xmit_pkts = 2387 rsp->port_multicast_xmit_pkts =
2359 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS, 2388 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS,
2360 CNTR_INVALID_VL)); 2389 CNTR_INVALID_VL));
2361 rsp->port_multicast_rcv_pkts = 2390 rsp->port_multicast_rcv_pkts =
2362 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS, 2391 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS,
2363 CNTR_INVALID_VL)); 2392 CNTR_INVALID_VL));
@@ -2386,7 +2415,7 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
2386 } 2415 }
2387 tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); 2416 tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
2388 tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, 2417 tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
2389 CNTR_INVALID_VL); 2418 CNTR_INVALID_VL);
2390 if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) { 2419 if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) {
2391 /* overflow/wrapped */ 2420 /* overflow/wrapped */
2392 rsp->link_error_recovery = cpu_to_be32(~0); 2421 rsp->link_error_recovery = cpu_to_be32(~0);
@@ -2401,13 +2430,13 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
2401 cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR, 2430 cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR,
2402 CNTR_INVALID_VL)); 2431 CNTR_INVALID_VL));
2403 rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN, 2432 rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN,
2404 CNTR_INVALID_VL)); 2433 CNTR_INVALID_VL));
2405 2434
2406 /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */ 2435 /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */
2407 tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); 2436 tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
2408 rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff; 2437 rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff;
2409 2438
2410 vlinfo = &(rsp->vls[0]); 2439 vlinfo = &rsp->vls[0];
2411 vfi = 0; 2440 vfi = 0;
2412 /* The vl_select_mask has been checked above, and we know 2441 /* The vl_select_mask has been checked above, and we know
2413 * that it contains only entries which represent valid VLs. 2442 * that it contains only entries which represent valid VLs.
@@ -2423,27 +2452,27 @@ static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
2423 2452
2424 rsp->vls[vfi].port_vl_rcv_pkts = 2453 rsp->vls[vfi].port_vl_rcv_pkts =
2425 cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL, 2454 cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL,
2426 idx_from_vl(vl))); 2455 idx_from_vl(vl)));
2427 2456
2428 rsp->vls[vfi].port_vl_xmit_data = 2457 rsp->vls[vfi].port_vl_xmit_data =
2429 cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL, 2458 cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL,
2430 idx_from_vl(vl))); 2459 idx_from_vl(vl)));
2431 2460
2432 rsp->vls[vfi].port_vl_xmit_pkts = 2461 rsp->vls[vfi].port_vl_xmit_pkts =
2433 cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL, 2462 cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL,
2434 idx_from_vl(vl))); 2463 idx_from_vl(vl)));
2435 2464
2436 rsp->vls[vfi].port_vl_xmit_wait = 2465 rsp->vls[vfi].port_vl_xmit_wait =
2437 cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL, 2466 cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL,
2438 idx_from_vl(vl))); 2467 idx_from_vl(vl)));
2439 2468
2440 rsp->vls[vfi].port_vl_rcv_fecn = 2469 rsp->vls[vfi].port_vl_rcv_fecn =
2441 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL, 2470 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL,
2442 idx_from_vl(vl))); 2471 idx_from_vl(vl)));
2443 2472
2444 rsp->vls[vfi].port_vl_rcv_becn = 2473 rsp->vls[vfi].port_vl_rcv_becn =
2445 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL, 2474 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL,
2446 idx_from_vl(vl))); 2475 idx_from_vl(vl)));
2447 2476
2448 vlinfo++; 2477 vlinfo++;
2449 vfi++; 2478 vfi++;
@@ -2473,7 +2502,7 @@ static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port,
2473 error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, 2502 error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
2474 CNTR_INVALID_VL); 2503 CNTR_INVALID_VL);
2475 error_counter_summary += read_dev_cntr(dd, C_DC_RMT_PHY_ERR, 2504 error_counter_summary += read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
2476 CNTR_INVALID_VL); 2505 CNTR_INVALID_VL);
2477 /* local link integrity must be right-shifted by the lli resolution */ 2506 /* local link integrity must be right-shifted by the lli resolution */
2478 tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL); 2507 tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL);
2479 tmp += read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL); 2508 tmp += read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL);
@@ -2483,10 +2512,10 @@ static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port,
2483 tmp += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL); 2512 tmp += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL);
2484 error_counter_summary += (tmp >> res_ler); 2513 error_counter_summary += (tmp >> res_ler);
2485 error_counter_summary += read_dev_cntr(dd, C_DC_RCV_ERR, 2514 error_counter_summary += read_dev_cntr(dd, C_DC_RCV_ERR,
2486 CNTR_INVALID_VL); 2515 CNTR_INVALID_VL);
2487 error_counter_summary += read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL); 2516 error_counter_summary += read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
2488 error_counter_summary += read_dev_cntr(dd, C_DC_FM_CFG_ERR, 2517 error_counter_summary += read_dev_cntr(dd, C_DC_FM_CFG_ERR,
2489 CNTR_INVALID_VL); 2518 CNTR_INVALID_VL);
2490 /* ppd->link_downed is a 32-bit value */ 2519 /* ppd->link_downed is a 32-bit value */
2491 error_counter_summary += read_port_cntr(ppd, C_SW_LINK_DOWN, 2520 error_counter_summary += read_port_cntr(ppd, C_SW_LINK_DOWN,
2492 CNTR_INVALID_VL); 2521 CNTR_INVALID_VL);
@@ -2512,7 +2541,7 @@ static void a0_datacounters(struct hfi1_pportdata *ppd, struct _port_dctrs *rsp,
2512 idx_from_vl(vl)); 2541 idx_from_vl(vl));
2513 if (tmp < sum_vl_xmit_wait) { 2542 if (tmp < sum_vl_xmit_wait) {
2514 /* we wrapped */ 2543 /* we wrapped */
2515 sum_vl_xmit_wait = (u64) ~0; 2544 sum_vl_xmit_wait = (u64)~0;
2516 break; 2545 break;
2517 } 2546 }
2518 sum_vl_xmit_wait = tmp; 2547 sum_vl_xmit_wait = tmp;
@@ -2522,8 +2551,30 @@ static void a0_datacounters(struct hfi1_pportdata *ppd, struct _port_dctrs *rsp,
2522 } 2551 }
2523} 2552}
2524 2553
2554static void pma_get_opa_port_dctrs(struct ib_device *ibdev,
2555 struct _port_dctrs *rsp)
2556{
2557 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
2558
2559 rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS,
2560 CNTR_INVALID_VL));
2561 rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS,
2562 CNTR_INVALID_VL));
2563 rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS,
2564 CNTR_INVALID_VL));
2565 rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS,
2566 CNTR_INVALID_VL));
2567 rsp->port_multicast_xmit_pkts =
2568 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS,
2569 CNTR_INVALID_VL));
2570 rsp->port_multicast_rcv_pkts =
2571 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS,
2572 CNTR_INVALID_VL));
2573}
2574
2525static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, 2575static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
2526 struct ib_device *ibdev, u8 port, u32 *resp_len) 2576 struct ib_device *ibdev,
2577 u8 port, u32 *resp_len)
2527{ 2578{
2528 struct opa_port_data_counters_msg *req = 2579 struct opa_port_data_counters_msg *req =
2529 (struct opa_port_data_counters_msg *)pmp->data; 2580 (struct opa_port_data_counters_msg *)pmp->data;
@@ -2590,39 +2641,19 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
2590 */ 2641 */
2591 hfi1_read_link_quality(dd, &lq); 2642 hfi1_read_link_quality(dd, &lq);
2592 rsp->link_quality_indicator = cpu_to_be32((u32)lq); 2643 rsp->link_quality_indicator = cpu_to_be32((u32)lq);
2644 pma_get_opa_port_dctrs(ibdev, rsp);
2593 2645
2594 /* rsp->sw_port_congestion is 0 for HFIs */
2595 /* rsp->port_xmit_time_cong is 0 for HFIs */
2596 /* rsp->port_xmit_wasted_bw ??? */
2597 /* rsp->port_xmit_wait_data ??? */
2598 /* rsp->port_mark_fecn is 0 for HFIs */
2599
2600 rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS,
2601 CNTR_INVALID_VL));
2602 rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS,
2603 CNTR_INVALID_VL));
2604 rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS,
2605 CNTR_INVALID_VL));
2606 rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS,
2607 CNTR_INVALID_VL));
2608 rsp->port_multicast_xmit_pkts =
2609 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS,
2610 CNTR_INVALID_VL));
2611 rsp->port_multicast_rcv_pkts =
2612 cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS,
2613 CNTR_INVALID_VL));
2614 rsp->port_xmit_wait = 2646 rsp->port_xmit_wait =
2615 cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL)); 2647 cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL));
2616 rsp->port_rcv_fecn = 2648 rsp->port_rcv_fecn =
2617 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL)); 2649 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL));
2618 rsp->port_rcv_becn = 2650 rsp->port_rcv_becn =
2619 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL)); 2651 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL));
2620
2621 rsp->port_error_counter_summary = 2652 rsp->port_error_counter_summary =
2622 cpu_to_be64(get_error_counter_summary(ibdev, port, 2653 cpu_to_be64(get_error_counter_summary(ibdev, port,
2623 res_lli, res_ler)); 2654 res_lli, res_ler));
2624 2655
2625 vlinfo = &(rsp->vls[0]); 2656 vlinfo = &rsp->vls[0];
2626 vfi = 0; 2657 vfi = 0;
2627 /* The vl_select_mask has been checked above, and we know 2658 /* The vl_select_mask has been checked above, and we know
2628 * that it contains only entries which represent valid VLs. 2659 * that it contains only entries which represent valid VLs.
@@ -2630,44 +2661,45 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
2630 * any additional checks for vl. 2661 * any additional checks for vl.
2631 */ 2662 */
2632 for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), 2663 for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
2633 8 * sizeof(req->vl_select_mask)) { 2664 8 * sizeof(req->vl_select_mask)) {
2634 memset(vlinfo, 0, sizeof(*vlinfo)); 2665 memset(vlinfo, 0, sizeof(*vlinfo));
2635 2666
2636 rsp->vls[vfi].port_vl_xmit_data = 2667 rsp->vls[vfi].port_vl_xmit_data =
2637 cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL, 2668 cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL,
2638 idx_from_vl(vl))); 2669 idx_from_vl(vl)));
2639 2670
2640 rsp->vls[vfi].port_vl_rcv_data = 2671 rsp->vls[vfi].port_vl_rcv_data =
2641 cpu_to_be64(read_dev_cntr(dd, C_DC_RX_FLIT_VL, 2672 cpu_to_be64(read_dev_cntr(dd, C_DC_RX_FLIT_VL,
2642 idx_from_vl(vl))); 2673 idx_from_vl(vl)));
2643 2674
2644 rsp->vls[vfi].port_vl_xmit_pkts = 2675 rsp->vls[vfi].port_vl_xmit_pkts =
2645 cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL, 2676 cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL,
2646 idx_from_vl(vl))); 2677 idx_from_vl(vl)));
2647 2678
2648 rsp->vls[vfi].port_vl_rcv_pkts = 2679 rsp->vls[vfi].port_vl_rcv_pkts =
2649 cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL, 2680 cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL,
2650 idx_from_vl(vl))); 2681 idx_from_vl(vl)));
2651 2682
2652 rsp->vls[vfi].port_vl_xmit_wait = 2683 rsp->vls[vfi].port_vl_xmit_wait =
2653 cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL, 2684 cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL,
2654 idx_from_vl(vl))); 2685 idx_from_vl(vl)));
2655 2686
2656 rsp->vls[vfi].port_vl_rcv_fecn = 2687 rsp->vls[vfi].port_vl_rcv_fecn =
2657 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL, 2688 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL,
2658 idx_from_vl(vl))); 2689 idx_from_vl(vl)));
2659 rsp->vls[vfi].port_vl_rcv_becn = 2690 rsp->vls[vfi].port_vl_rcv_becn =
2660 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL, 2691 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL,
2661 idx_from_vl(vl))); 2692 idx_from_vl(vl)));
2662 2693
2663 /* rsp->port_vl_xmit_time_cong is 0 for HFIs */ 2694 /* rsp->port_vl_xmit_time_cong is 0 for HFIs */
2664 /* rsp->port_vl_xmit_wasted_bw ??? */ 2695 /* rsp->port_vl_xmit_wasted_bw ??? */
2665 /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? 2696 /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ???
2666 * does this differ from rsp->vls[vfi].port_vl_xmit_wait */ 2697 * does this differ from rsp->vls[vfi].port_vl_xmit_wait
2698 */
2667 /*rsp->vls[vfi].port_vl_mark_fecn = 2699 /*rsp->vls[vfi].port_vl_mark_fecn =
2668 cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT 2700 * cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT
2669 + offset)); 2701 * + offset));
2670 */ 2702 */
2671 vlinfo++; 2703 vlinfo++;
2672 vfi++; 2704 vfi++;
2673 } 2705 }
@@ -2680,12 +2712,88 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
2680 return reply((struct ib_mad_hdr *)pmp); 2712 return reply((struct ib_mad_hdr *)pmp);
2681} 2713}
2682 2714
2715static int pma_get_ib_portcounters_ext(struct ib_pma_mad *pmp,
2716 struct ib_device *ibdev, u8 port)
2717{
2718 struct ib_pma_portcounters_ext *p = (struct ib_pma_portcounters_ext *)
2719 pmp->data;
2720 struct _port_dctrs rsp;
2721
2722 if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
2723 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
2724 goto bail;
2725 }
2726
2727 memset(&rsp, 0, sizeof(rsp));
2728 pma_get_opa_port_dctrs(ibdev, &rsp);
2729
2730 p->port_xmit_data = rsp.port_xmit_data;
2731 p->port_rcv_data = rsp.port_rcv_data;
2732 p->port_xmit_packets = rsp.port_xmit_pkts;
2733 p->port_rcv_packets = rsp.port_rcv_pkts;
2734 p->port_unicast_xmit_packets = 0;
2735 p->port_unicast_rcv_packets = 0;
2736 p->port_multicast_xmit_packets = rsp.port_multicast_xmit_pkts;
2737 p->port_multicast_rcv_packets = rsp.port_multicast_rcv_pkts;
2738
2739bail:
2740 return reply((struct ib_mad_hdr *)pmp);
2741}
2742
2743static void pma_get_opa_port_ectrs(struct ib_device *ibdev,
2744 struct _port_ectrs *rsp, u8 port)
2745{
2746 u64 tmp, tmp2;
2747 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
2748 struct hfi1_ibport *ibp = to_iport(ibdev, port);
2749 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
2750
2751 tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
2752 tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
2753 CNTR_INVALID_VL);
2754 if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) {
2755 /* overflow/wrapped */
2756 rsp->link_error_recovery = cpu_to_be32(~0);
2757 } else {
2758 rsp->link_error_recovery = cpu_to_be32(tmp2);
2759 }
2760
2761 rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN,
2762 CNTR_INVALID_VL));
2763 rsp->port_rcv_errors =
2764 cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL));
2765 rsp->port_rcv_remote_physical_errors =
2766 cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
2767 CNTR_INVALID_VL));
2768 rsp->port_rcv_switch_relay_errors = 0;
2769 rsp->port_xmit_discards =
2770 cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD,
2771 CNTR_INVALID_VL));
2772 rsp->port_xmit_constraint_errors =
2773 cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
2774 CNTR_INVALID_VL));
2775 rsp->port_rcv_constraint_errors =
2776 cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
2777 CNTR_INVALID_VL));
2778 tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL);
2779 tmp2 = tmp + read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL);
2780 if (tmp2 < tmp) {
2781 /* overflow/wrapped */
2782 rsp->local_link_integrity_errors = cpu_to_be64(~0);
2783 } else {
2784 rsp->local_link_integrity_errors = cpu_to_be64(tmp2);
2785 }
2786 rsp->excessive_buffer_overruns =
2787 cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL));
2788}
2789
2683static int pma_get_opa_porterrors(struct opa_pma_mad *pmp, 2790static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
2684 struct ib_device *ibdev, u8 port, u32 *resp_len) 2791 struct ib_device *ibdev,
2792 u8 port, u32 *resp_len)
2685{ 2793{
2686 size_t response_data_size; 2794 size_t response_data_size;
2687 struct _port_ectrs *rsp; 2795 struct _port_ectrs *rsp;
2688 unsigned long port_num; 2796 u8 port_num;
2689 struct opa_port_error_counters64_msg *req; 2797 struct opa_port_error_counters64_msg *req;
2690 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 2798 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
2691 u32 num_ports; 2799 u32 num_ports;
@@ -2695,7 +2803,7 @@ static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
2695 struct hfi1_pportdata *ppd; 2803 struct hfi1_pportdata *ppd;
2696 struct _vls_ectrs *vlinfo; 2804 struct _vls_ectrs *vlinfo;
2697 unsigned long vl; 2805 unsigned long vl;
2698 u64 port_mask, tmp, tmp2; 2806 u64 port_mask, tmp;
2699 u32 vl_select_mask; 2807 u32 vl_select_mask;
2700 int vfi; 2808 int vfi;
2701 2809
@@ -2724,9 +2832,9 @@ static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
2724 */ 2832 */
2725 port_mask = be64_to_cpu(req->port_select_mask[3]); 2833 port_mask = be64_to_cpu(req->port_select_mask[3]);
2726 port_num = find_first_bit((unsigned long *)&port_mask, 2834 port_num = find_first_bit((unsigned long *)&port_mask,
2727 sizeof(port_mask)); 2835 sizeof(port_mask));
2728 2836
2729 if ((u8)port_num != port) { 2837 if (port_num != port) {
2730 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; 2838 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
2731 return reply((struct ib_mad_hdr *)pmp); 2839 return reply((struct ib_mad_hdr *)pmp);
2732 } 2840 }
@@ -2737,46 +2845,18 @@ static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
2737 ppd = ppd_from_ibp(ibp); 2845 ppd = ppd_from_ibp(ibp);
2738 2846
2739 memset(rsp, 0, sizeof(*rsp)); 2847 memset(rsp, 0, sizeof(*rsp));
2740 rsp->port_number = (u8)port_num; 2848 rsp->port_number = port_num;
2849
2850 pma_get_opa_port_ectrs(ibdev, rsp, port_num);
2741 2851
2742 rsp->port_rcv_constraint_errors =
2743 cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
2744 CNTR_INVALID_VL));
2745 /* port_rcv_switch_relay_errors is 0 for HFIs */
2746 rsp->port_xmit_discards =
2747 cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD,
2748 CNTR_INVALID_VL));
2749 rsp->port_rcv_remote_physical_errors = 2852 rsp->port_rcv_remote_physical_errors =
2750 cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR, 2853 cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
2751 CNTR_INVALID_VL)); 2854 CNTR_INVALID_VL));
2752 tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL);
2753 tmp2 = tmp + read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL);
2754 if (tmp2 < tmp) {
2755 /* overflow/wrapped */
2756 rsp->local_link_integrity_errors = cpu_to_be64(~0);
2757 } else {
2758 rsp->local_link_integrity_errors = cpu_to_be64(tmp2);
2759 }
2760 tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
2761 tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
2762 CNTR_INVALID_VL);
2763 if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) {
2764 /* overflow/wrapped */
2765 rsp->link_error_recovery = cpu_to_be32(~0);
2766 } else {
2767 rsp->link_error_recovery = cpu_to_be32(tmp2);
2768 }
2769 rsp->port_xmit_constraint_errors =
2770 cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
2771 CNTR_INVALID_VL));
2772 rsp->excessive_buffer_overruns =
2773 cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL));
2774 rsp->fm_config_errors = 2855 rsp->fm_config_errors =
2775 cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR, 2856 cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR,
2776 CNTR_INVALID_VL)); 2857 CNTR_INVALID_VL));
2777 rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN,
2778 CNTR_INVALID_VL));
2779 tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); 2858 tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
2859
2780 rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff; 2860 rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff;
2781 2861
2782 vlinfo = &rsp->vls[0]; 2862 vlinfo = &rsp->vls[0];
@@ -2796,8 +2876,94 @@ static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
2796 return reply((struct ib_mad_hdr *)pmp); 2876 return reply((struct ib_mad_hdr *)pmp);
2797} 2877}
2798 2878
2879static int pma_get_ib_portcounters(struct ib_pma_mad *pmp,
2880 struct ib_device *ibdev, u8 port)
2881{
2882 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
2883 pmp->data;
2884 struct _port_ectrs rsp;
2885 u64 temp_link_overrun_errors;
2886 u64 temp_64;
2887 u32 temp_32;
2888
2889 memset(&rsp, 0, sizeof(rsp));
2890 pma_get_opa_port_ectrs(ibdev, &rsp, port);
2891
2892 if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
2893 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
2894 goto bail;
2895 }
2896
2897 p->symbol_error_counter = 0; /* N/A for OPA */
2898
2899 temp_32 = be32_to_cpu(rsp.link_error_recovery);
2900 if (temp_32 > 0xFFUL)
2901 p->link_error_recovery_counter = 0xFF;
2902 else
2903 p->link_error_recovery_counter = (u8)temp_32;
2904
2905 temp_32 = be32_to_cpu(rsp.link_downed);
2906 if (temp_32 > 0xFFUL)
2907 p->link_downed_counter = 0xFF;
2908 else
2909 p->link_downed_counter = (u8)temp_32;
2910
2911 temp_64 = be64_to_cpu(rsp.port_rcv_errors);
2912 if (temp_64 > 0xFFFFUL)
2913 p->port_rcv_errors = cpu_to_be16(0xFFFF);
2914 else
2915 p->port_rcv_errors = cpu_to_be16((u16)temp_64);
2916
2917 temp_64 = be64_to_cpu(rsp.port_rcv_remote_physical_errors);
2918 if (temp_64 > 0xFFFFUL)
2919 p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
2920 else
2921 p->port_rcv_remphys_errors = cpu_to_be16((u16)temp_64);
2922
2923 temp_64 = be64_to_cpu(rsp.port_rcv_switch_relay_errors);
2924 p->port_rcv_switch_relay_errors = cpu_to_be16((u16)temp_64);
2925
2926 temp_64 = be64_to_cpu(rsp.port_xmit_discards);
2927 if (temp_64 > 0xFFFFUL)
2928 p->port_xmit_discards = cpu_to_be16(0xFFFF);
2929 else
2930 p->port_xmit_discards = cpu_to_be16((u16)temp_64);
2931
2932 temp_64 = be64_to_cpu(rsp.port_xmit_constraint_errors);
2933 if (temp_64 > 0xFFUL)
2934 p->port_xmit_constraint_errors = 0xFF;
2935 else
2936 p->port_xmit_constraint_errors = (u8)temp_64;
2937
2938 temp_64 = be64_to_cpu(rsp.port_rcv_constraint_errors);
2939 if (temp_64 > 0xFFUL)
2940 p->port_rcv_constraint_errors = 0xFFUL;
2941 else
2942 p->port_rcv_constraint_errors = (u8)temp_64;
2943
2944 /* LocalLink: 7:4, BufferOverrun: 3:0 */
2945 temp_64 = be64_to_cpu(rsp.local_link_integrity_errors);
2946 if (temp_64 > 0xFUL)
2947 temp_64 = 0xFUL;
2948
2949 temp_link_overrun_errors = temp_64 << 4;
2950
2951 temp_64 = be64_to_cpu(rsp.excessive_buffer_overruns);
2952 if (temp_64 > 0xFUL)
2953 temp_64 = 0xFUL;
2954 temp_link_overrun_errors |= temp_64;
2955
2956 p->link_overrun_errors = (u8)temp_link_overrun_errors;
2957
2958 p->vl15_dropped = 0; /* N/A for OPA */
2959
2960bail:
2961 return reply((struct ib_mad_hdr *)pmp);
2962}
2963
2799static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp, 2964static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
2800 struct ib_device *ibdev, u8 port, u32 *resp_len) 2965 struct ib_device *ibdev,
2966 u8 port, u32 *resp_len)
2801{ 2967{
2802 size_t response_data_size; 2968 size_t response_data_size;
2803 struct _port_ei *rsp; 2969 struct _port_ei *rsp;
@@ -2805,7 +2971,7 @@ static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
2805 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 2971 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
2806 u64 port_mask; 2972 u64 port_mask;
2807 u32 num_ports; 2973 u32 num_ports;
2808 unsigned long port_num; 2974 u8 port_num;
2809 u8 num_pslm; 2975 u8 num_pslm;
2810 u64 reg; 2976 u64 reg;
2811 2977
@@ -2838,7 +3004,7 @@ static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
2838 port_num = find_first_bit((unsigned long *)&port_mask, 3004 port_num = find_first_bit((unsigned long *)&port_mask,
2839 sizeof(port_mask)); 3005 sizeof(port_mask));
2840 3006
2841 if ((u8)port_num != port) { 3007 if (port_num != port) {
2842 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; 3008 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
2843 return reply((struct ib_mad_hdr *)pmp); 3009 return reply((struct ib_mad_hdr *)pmp);
2844 } 3010 }
@@ -2847,15 +3013,17 @@ static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
2847 rsp->port_rcv_ei.status_and_code = 3013 rsp->port_rcv_ei.status_and_code =
2848 dd->err_info_rcvport.status_and_code; 3014 dd->err_info_rcvport.status_and_code;
2849 memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit1, 3015 memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit1,
2850 &dd->err_info_rcvport.packet_flit1, sizeof(u64)); 3016 &dd->err_info_rcvport.packet_flit1, sizeof(u64));
2851 memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit2, 3017 memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit2,
2852 &dd->err_info_rcvport.packet_flit2, sizeof(u64)); 3018 &dd->err_info_rcvport.packet_flit2, sizeof(u64));
2853 3019
2854 /* ExcessiverBufferOverrunInfo */ 3020 /* ExcessiverBufferOverrunInfo */
2855 reg = read_csr(dd, RCV_ERR_INFO); 3021 reg = read_csr(dd, RCV_ERR_INFO);
2856 if (reg & RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK) { 3022 if (reg & RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK) {
2857 /* if the RcvExcessBufferOverrun bit is set, save SC of 3023 /*
2858 * first pkt that encountered an excess buffer overrun */ 3024 * if the RcvExcessBufferOverrun bit is set, save SC of
3025 * first pkt that encountered an excess buffer overrun
3026 */
2859 u8 tmp = (u8)reg; 3027 u8 tmp = (u8)reg;
2860 3028
2861 tmp &= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK; 3029 tmp &= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK;
@@ -2892,7 +3060,8 @@ static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
2892} 3060}
2893 3061
2894static int pma_set_opa_portstatus(struct opa_pma_mad *pmp, 3062static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
2895 struct ib_device *ibdev, u8 port, u32 *resp_len) 3063 struct ib_device *ibdev,
3064 u8 port, u32 *resp_len)
2896{ 3065{
2897 struct opa_clear_port_status *req = 3066 struct opa_clear_port_status *req =
2898 (struct opa_clear_port_status *)pmp->data; 3067 (struct opa_clear_port_status *)pmp->data;
@@ -2951,8 +3120,9 @@ static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
2951 write_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL, 0); 3120 write_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL, 0);
2952 3121
2953 /* Only applicable for switch */ 3122 /* Only applicable for switch */
2954 /*if (counter_select & CS_PORT_MARK_FECN) 3123 /* if (counter_select & CS_PORT_MARK_FECN)
2955 write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);*/ 3124 * write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);
3125 */
2956 3126
2957 if (counter_select & CS_PORT_RCV_CONSTRAINT_ERRORS) 3127 if (counter_select & CS_PORT_RCV_CONSTRAINT_ERRORS)
2958 write_port_cntr(ppd, C_SW_RCV_CSTR_ERR, CNTR_INVALID_VL, 0); 3128 write_port_cntr(ppd, C_SW_RCV_CSTR_ERR, CNTR_INVALID_VL, 0);
@@ -2975,7 +3145,7 @@ static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
2975 if (counter_select & CS_LINK_ERROR_RECOVERY) { 3145 if (counter_select & CS_LINK_ERROR_RECOVERY) {
2976 write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0); 3146 write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0);
2977 write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, 3147 write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
2978 CNTR_INVALID_VL, 0); 3148 CNTR_INVALID_VL, 0);
2979 } 3149 }
2980 3150
2981 if (counter_select & CS_PORT_RCV_ERRORS) 3151 if (counter_select & CS_PORT_RCV_ERRORS)
@@ -2997,7 +3167,6 @@ static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
2997 3167
2998 for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), 3168 for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
2999 8 * sizeof(vl_select_mask)) { 3169 8 * sizeof(vl_select_mask)) {
3000
3001 if (counter_select & CS_PORT_XMIT_DATA) 3170 if (counter_select & CS_PORT_XMIT_DATA)
3002 write_port_cntr(ppd, C_TX_FLIT_VL, idx_from_vl(vl), 0); 3171 write_port_cntr(ppd, C_TX_FLIT_VL, idx_from_vl(vl), 0);
3003 3172
@@ -3026,9 +3195,9 @@ static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
3026 if (counter_select & CS_PORT_RCV_BUBBLE) 3195 if (counter_select & CS_PORT_RCV_BUBBLE)
3027 write_dev_cntr(dd, C_DC_RCV_BBL_VL, idx_from_vl(vl), 0); 3196 write_dev_cntr(dd, C_DC_RCV_BBL_VL, idx_from_vl(vl), 0);
3028 3197
3029 /*if (counter_select & CS_PORT_MARK_FECN) 3198 /* if (counter_select & CS_PORT_MARK_FECN)
3030 write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0); 3199 * write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0);
3031 */ 3200 */
3032 /* port_vl_xmit_discards ??? */ 3201 /* port_vl_xmit_discards ??? */
3033 } 3202 }
3034 3203
@@ -3039,14 +3208,15 @@ static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
3039} 3208}
3040 3209
3041static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp, 3210static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp,
3042 struct ib_device *ibdev, u8 port, u32 *resp_len) 3211 struct ib_device *ibdev,
3212 u8 port, u32 *resp_len)
3043{ 3213{
3044 struct _port_ei *rsp; 3214 struct _port_ei *rsp;
3045 struct opa_port_error_info_msg *req; 3215 struct opa_port_error_info_msg *req;
3046 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 3216 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
3047 u64 port_mask; 3217 u64 port_mask;
3048 u32 num_ports; 3218 u32 num_ports;
3049 unsigned long port_num; 3219 u8 port_num;
3050 u8 num_pslm; 3220 u8 num_pslm;
3051 u32 error_info_select; 3221 u32 error_info_select;
3052 3222
@@ -3071,7 +3241,7 @@ static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp,
3071 port_num = find_first_bit((unsigned long *)&port_mask, 3241 port_num = find_first_bit((unsigned long *)&port_mask,
3072 sizeof(port_mask)); 3242 sizeof(port_mask));
3073 3243
3074 if ((u8)port_num != port) { 3244 if (port_num != port) {
3075 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; 3245 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
3076 return reply((struct ib_mad_hdr *)pmp); 3246 return reply((struct ib_mad_hdr *)pmp);
3077 } 3247 }
@@ -3085,8 +3255,10 @@ static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp,
3085 3255
3086 /* ExcessiverBufferOverrunInfo */ 3256 /* ExcessiverBufferOverrunInfo */
3087 if (error_info_select & ES_EXCESSIVE_BUFFER_OVERRUN_INFO) 3257 if (error_info_select & ES_EXCESSIVE_BUFFER_OVERRUN_INFO)
3088 /* status bit is essentially kept in the h/w - bit 5 of 3258 /*
3089 * RCV_ERR_INFO */ 3259 * status bit is essentially kept in the h/w - bit 5 of
3260 * RCV_ERR_INFO
3261 */
3090 write_csr(dd, RCV_ERR_INFO, 3262 write_csr(dd, RCV_ERR_INFO,
3091 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK); 3263 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
3092 3264
@@ -3138,13 +3310,12 @@ static int __subn_get_opa_cong_info(struct opa_smp *smp, u32 am, u8 *data,
3138} 3310}
3139 3311
3140static int __subn_get_opa_cong_setting(struct opa_smp *smp, u32 am, 3312static int __subn_get_opa_cong_setting(struct opa_smp *smp, u32 am,
3141 u8 *data, 3313 u8 *data, struct ib_device *ibdev,
3142 struct ib_device *ibdev, 3314 u8 port, u32 *resp_len)
3143 u8 port, u32 *resp_len)
3144{ 3315{
3145 int i; 3316 int i;
3146 struct opa_congestion_setting_attr *p = 3317 struct opa_congestion_setting_attr *p =
3147 (struct opa_congestion_setting_attr *) data; 3318 (struct opa_congestion_setting_attr *)data;
3148 struct hfi1_ibport *ibp = to_iport(ibdev, port); 3319 struct hfi1_ibport *ibp = to_iport(ibdev, port);
3149 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 3320 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
3150 struct opa_congestion_setting_entry_shadow *entries; 3321 struct opa_congestion_setting_entry_shadow *entries;
@@ -3154,7 +3325,7 @@ static int __subn_get_opa_cong_setting(struct opa_smp *smp, u32 am,
3154 3325
3155 cc_state = get_cc_state(ppd); 3326 cc_state = get_cc_state(ppd);
3156 3327
3157 if (cc_state == NULL) { 3328 if (!cc_state) {
3158 rcu_read_unlock(); 3329 rcu_read_unlock();
3159 return reply((struct ib_mad_hdr *)smp); 3330 return reply((struct ib_mad_hdr *)smp);
3160 } 3331 }
@@ -3183,7 +3354,7 @@ static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data,
3183 u32 *resp_len) 3354 u32 *resp_len)
3184{ 3355{
3185 struct opa_congestion_setting_attr *p = 3356 struct opa_congestion_setting_attr *p =
3186 (struct opa_congestion_setting_attr *) data; 3357 (struct opa_congestion_setting_attr *)data;
3187 struct hfi1_ibport *ibp = to_iport(ibdev, port); 3358 struct hfi1_ibport *ibp = to_iport(ibdev, port);
3188 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 3359 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
3189 struct opa_congestion_setting_entry_shadow *entries; 3360 struct opa_congestion_setting_entry_shadow *entries;
@@ -3245,7 +3416,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
3245 continue; 3416 continue;
3246 memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3); 3417 memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3);
3247 memcpy(cong_log->events[i].remote_qp_number_cn_entry, 3418 memcpy(cong_log->events[i].remote_qp_number_cn_entry,
3248 &cce->rqpn, 3); 3419 &cce->rqpn, 3);
3249 cong_log->events[i].sl_svc_type_cn_entry = 3420 cong_log->events[i].sl_svc_type_cn_entry =
3250 ((cce->sl & 0x1f) << 3) | (cce->svc_type & 0x7); 3421 ((cce->sl & 0x1f) << 3) | (cce->svc_type & 0x7);
3251 cong_log->events[i].remote_lid_cn_entry = 3422 cong_log->events[i].remote_lid_cn_entry =
@@ -3275,7 +3446,7 @@ static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
3275 u32 *resp_len) 3446 u32 *resp_len)
3276{ 3447{
3277 struct ib_cc_table_attr *cc_table_attr = 3448 struct ib_cc_table_attr *cc_table_attr =
3278 (struct ib_cc_table_attr *) data; 3449 (struct ib_cc_table_attr *)data;
3279 struct hfi1_ibport *ibp = to_iport(ibdev, port); 3450 struct hfi1_ibport *ibp = to_iport(ibdev, port);
3280 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 3451 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
3281 u32 start_block = OPA_AM_START_BLK(am); 3452 u32 start_block = OPA_AM_START_BLK(am);
@@ -3296,7 +3467,7 @@ static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
3296 3467
3297 cc_state = get_cc_state(ppd); 3468 cc_state = get_cc_state(ppd);
3298 3469
3299 if (cc_state == NULL) { 3470 if (!cc_state) {
3300 rcu_read_unlock(); 3471 rcu_read_unlock();
3301 return reply((struct ib_mad_hdr *)smp); 3472 return reply((struct ib_mad_hdr *)smp);
3302 } 3473 }
@@ -3316,7 +3487,7 @@ static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
3316 rcu_read_unlock(); 3487 rcu_read_unlock();
3317 3488
3318 if (resp_len) 3489 if (resp_len)
3319 *resp_len += sizeof(u16)*(IB_CCT_ENTRIES * n_blocks + 1); 3490 *resp_len += sizeof(u16) * (IB_CCT_ENTRIES * n_blocks + 1);
3320 3491
3321 return reply((struct ib_mad_hdr *)smp); 3492 return reply((struct ib_mad_hdr *)smp);
3322} 3493}
@@ -3332,7 +3503,7 @@ static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
3332 struct ib_device *ibdev, u8 port, 3503 struct ib_device *ibdev, u8 port,
3333 u32 *resp_len) 3504 u32 *resp_len)
3334{ 3505{
3335 struct ib_cc_table_attr *p = (struct ib_cc_table_attr *) data; 3506 struct ib_cc_table_attr *p = (struct ib_cc_table_attr *)data;
3336 struct hfi1_ibport *ibp = to_iport(ibdev, port); 3507 struct hfi1_ibport *ibp = to_iport(ibdev, port);
3337 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 3508 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
3338 u32 start_block = OPA_AM_START_BLK(am); 3509 u32 start_block = OPA_AM_START_BLK(am);
@@ -3362,14 +3533,14 @@ static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
3362 } 3533 }
3363 3534
3364 new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL); 3535 new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL);
3365 if (new_cc_state == NULL) 3536 if (!new_cc_state)
3366 goto getit; 3537 goto getit;
3367 3538
3368 spin_lock(&ppd->cc_state_lock); 3539 spin_lock(&ppd->cc_state_lock);
3369 3540
3370 old_cc_state = get_cc_state(ppd); 3541 old_cc_state = get_cc_state(ppd);
3371 3542
3372 if (old_cc_state == NULL) { 3543 if (!old_cc_state) {
3373 spin_unlock(&ppd->cc_state_lock); 3544 spin_unlock(&ppd->cc_state_lock);
3374 kfree(new_cc_state); 3545 kfree(new_cc_state);
3375 return reply((struct ib_mad_hdr *)smp); 3546 return reply((struct ib_mad_hdr *)smp);
@@ -3409,26 +3580,31 @@ struct opa_led_info {
3409}; 3580};
3410 3581
3411#define OPA_LED_SHIFT 31 3582#define OPA_LED_SHIFT 31
3412#define OPA_LED_MASK (1 << OPA_LED_SHIFT) 3583#define OPA_LED_MASK BIT(OPA_LED_SHIFT)
3413 3584
3414static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data, 3585static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
3415 struct ib_device *ibdev, u8 port, 3586 struct ib_device *ibdev, u8 port,
3416 u32 *resp_len) 3587 u32 *resp_len)
3417{ 3588{
3418 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 3589 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
3419 struct opa_led_info *p = (struct opa_led_info *) data; 3590 struct hfi1_pportdata *ppd = dd->pport;
3591 struct opa_led_info *p = (struct opa_led_info *)data;
3420 u32 nport = OPA_AM_NPORT(am); 3592 u32 nport = OPA_AM_NPORT(am);
3421 u64 reg; 3593 u32 is_beaconing_active;
3422 3594
3423 if (nport != 1) { 3595 if (nport != 1) {
3424 smp->status |= IB_SMP_INVALID_FIELD; 3596 smp->status |= IB_SMP_INVALID_FIELD;
3425 return reply((struct ib_mad_hdr *)smp); 3597 return reply((struct ib_mad_hdr *)smp);
3426 } 3598 }
3427 3599
3428 reg = read_csr(dd, DCC_CFG_LED_CNTRL); 3600 /*
3429 if ((reg & DCC_CFG_LED_CNTRL_LED_CNTRL_SMASK) && 3601 * This pairs with the memory barrier in hfi1_start_led_override to
3430 ((reg & DCC_CFG_LED_CNTRL_LED_SW_BLINK_RATE_SMASK) == 0xf)) 3602 * ensure that we read the correct state of LED beaconing represented
3431 p->rsvd_led_mask = cpu_to_be32(OPA_LED_MASK); 3603 * by led_override_timer_active
3604 */
3605 smp_rmb();
3606 is_beaconing_active = !!atomic_read(&ppd->led_override_timer_active);
3607 p->rsvd_led_mask = cpu_to_be32(is_beaconing_active << OPA_LED_SHIFT);
3432 3608
3433 if (resp_len) 3609 if (resp_len)
3434 *resp_len += sizeof(struct opa_led_info); 3610 *resp_len += sizeof(struct opa_led_info);
@@ -3441,7 +3617,7 @@ static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
3441 u32 *resp_len) 3617 u32 *resp_len)
3442{ 3618{
3443 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 3619 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
3444 struct opa_led_info *p = (struct opa_led_info *) data; 3620 struct opa_led_info *p = (struct opa_led_info *)data;
3445 u32 nport = OPA_AM_NPORT(am); 3621 u32 nport = OPA_AM_NPORT(am);
3446 int on = !!(be32_to_cpu(p->rsvd_led_mask) & OPA_LED_MASK); 3622 int on = !!(be32_to_cpu(p->rsvd_led_mask) & OPA_LED_MASK);
3447 3623
@@ -3450,7 +3626,10 @@ static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
3450 return reply((struct ib_mad_hdr *)smp); 3626 return reply((struct ib_mad_hdr *)smp);
3451 } 3627 }
3452 3628
3453 setextled(dd, on); 3629 if (on)
3630 hfi1_start_led_override(dd->pport, 2000, 1500);
3631 else
3632 shutdown_led_override(dd->pport);
3454 3633
3455 return __subn_get_opa_led_info(smp, am, data, ibdev, port, resp_len); 3634 return __subn_get_opa_led_info(smp, am, data, ibdev, port, resp_len);
3456} 3635}
@@ -3493,7 +3672,7 @@ static int subn_get_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
3493 break; 3672 break;
3494 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP: 3673 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP:
3495 ret = __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port, 3674 ret = __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port,
3496 resp_len); 3675 resp_len);
3497 break; 3676 break;
3498 case OPA_ATTRIB_ID_PORT_STATE_INFO: 3677 case OPA_ATTRIB_ID_PORT_STATE_INFO:
3499 ret = __subn_get_opa_psi(smp, am, data, ibdev, port, 3678 ret = __subn_get_opa_psi(smp, am, data, ibdev, port,
@@ -3532,9 +3711,9 @@ static int subn_get_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
3532 resp_len); 3711 resp_len);
3533 break; 3712 break;
3534 case IB_SMP_ATTR_SM_INFO: 3713 case IB_SMP_ATTR_SM_INFO:
3535 if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) 3714 if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
3536 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; 3715 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
3537 if (ibp->port_cap_flags & IB_PORT_SM) 3716 if (ibp->rvp.port_cap_flags & IB_PORT_SM)
3538 return IB_MAD_RESULT_SUCCESS; 3717 return IB_MAD_RESULT_SUCCESS;
3539 /* FALLTHROUGH */ 3718 /* FALLTHROUGH */
3540 default: 3719 default:
@@ -3575,7 +3754,7 @@ static int subn_set_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
3575 break; 3754 break;
3576 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP: 3755 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP:
3577 ret = __subn_set_opa_sc_to_vlnt(smp, am, data, ibdev, port, 3756 ret = __subn_set_opa_sc_to_vlnt(smp, am, data, ibdev, port,
3578 resp_len); 3757 resp_len);
3579 break; 3758 break;
3580 case OPA_ATTRIB_ID_PORT_STATE_INFO: 3759 case OPA_ATTRIB_ID_PORT_STATE_INFO:
3581 ret = __subn_set_opa_psi(smp, am, data, ibdev, port, 3760 ret = __subn_set_opa_psi(smp, am, data, ibdev, port,
@@ -3602,9 +3781,9 @@ static int subn_set_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
3602 resp_len); 3781 resp_len);
3603 break; 3782 break;
3604 case IB_SMP_ATTR_SM_INFO: 3783 case IB_SMP_ATTR_SM_INFO:
3605 if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) 3784 if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
3606 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; 3785 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
3607 if (ibp->port_cap_flags & IB_PORT_SM) 3786 if (ibp->rvp.port_cap_flags & IB_PORT_SM)
3608 return IB_MAD_RESULT_SUCCESS; 3787 return IB_MAD_RESULT_SUCCESS;
3609 /* FALLTHROUGH */ 3788 /* FALLTHROUGH */
3610 default: 3789 default:
@@ -3654,14 +3833,13 @@ static int subn_get_opa_aggregate(struct opa_smp *smp,
3654 /* zero the payload for this segment */ 3833 /* zero the payload for this segment */
3655 memset(next_smp + sizeof(*agg), 0, agg_data_len); 3834 memset(next_smp + sizeof(*agg), 0, agg_data_len);
3656 3835
3657 (void) subn_get_opa_sma(agg->attr_id, smp, am, agg->data, 3836 (void)subn_get_opa_sma(agg->attr_id, smp, am, agg->data,
3658 ibdev, port, NULL); 3837 ibdev, port, NULL);
3659 if (smp->status & ~IB_SMP_DIRECTION) { 3838 if (smp->status & ~IB_SMP_DIRECTION) {
3660 set_aggr_error(agg); 3839 set_aggr_error(agg);
3661 return reply((struct ib_mad_hdr *)smp); 3840 return reply((struct ib_mad_hdr *)smp);
3662 } 3841 }
3663 next_smp += agg_size; 3842 next_smp += agg_size;
3664
3665 } 3843 }
3666 3844
3667 return reply((struct ib_mad_hdr *)smp); 3845 return reply((struct ib_mad_hdr *)smp);
@@ -3698,14 +3876,13 @@ static int subn_set_opa_aggregate(struct opa_smp *smp,
3698 return reply((struct ib_mad_hdr *)smp); 3876 return reply((struct ib_mad_hdr *)smp);
3699 } 3877 }
3700 3878
3701 (void) subn_set_opa_sma(agg->attr_id, smp, am, agg->data, 3879 (void)subn_set_opa_sma(agg->attr_id, smp, am, agg->data,
3702 ibdev, port, NULL); 3880 ibdev, port, NULL);
3703 if (smp->status & ~IB_SMP_DIRECTION) { 3881 if (smp->status & ~IB_SMP_DIRECTION) {
3704 set_aggr_error(agg); 3882 set_aggr_error(agg);
3705 return reply((struct ib_mad_hdr *)smp); 3883 return reply((struct ib_mad_hdr *)smp);
3706 } 3884 }
3707 next_smp += agg_size; 3885 next_smp += agg_size;
3708
3709 } 3886 }
3710 3887
3711 return reply((struct ib_mad_hdr *)smp); 3888 return reply((struct ib_mad_hdr *)smp);
@@ -3823,7 +4000,7 @@ static int process_subn_opa(struct ib_device *ibdev, int mad_flags,
3823 if (smp->class_version != OPA_SMI_CLASS_VERSION) { 4000 if (smp->class_version != OPA_SMI_CLASS_VERSION) {
3824 smp->status |= IB_SMP_UNSUP_VERSION; 4001 smp->status |= IB_SMP_UNSUP_VERSION;
3825 ret = reply((struct ib_mad_hdr *)smp); 4002 ret = reply((struct ib_mad_hdr *)smp);
3826 goto bail; 4003 return ret;
3827 } 4004 }
3828 ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, smp->mkey, 4005 ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, smp->mkey,
3829 smp->route.dr.dr_slid, smp->route.dr.return_path, 4006 smp->route.dr.dr_slid, smp->route.dr.return_path,
@@ -3843,13 +4020,13 @@ static int process_subn_opa(struct ib_device *ibdev, int mad_flags,
3843 smp->method == IB_MGMT_METHOD_SET) && 4020 smp->method == IB_MGMT_METHOD_SET) &&
3844 port_num && port_num <= ibdev->phys_port_cnt && 4021 port_num && port_num <= ibdev->phys_port_cnt &&
3845 port != port_num) 4022 port != port_num)
3846 (void) check_mkey(to_iport(ibdev, port_num), 4023 (void)check_mkey(to_iport(ibdev, port_num),
3847 (struct ib_mad_hdr *)smp, 0, 4024 (struct ib_mad_hdr *)smp, 0,
3848 smp->mkey, smp->route.dr.dr_slid, 4025 smp->mkey, smp->route.dr.dr_slid,
3849 smp->route.dr.return_path, 4026 smp->route.dr.return_path,
3850 smp->hop_cnt); 4027 smp->hop_cnt);
3851 ret = IB_MAD_RESULT_FAILURE; 4028 ret = IB_MAD_RESULT_FAILURE;
3852 goto bail; 4029 return ret;
3853 } 4030 }
3854 4031
3855 *resp_len = opa_get_smp_header_size(smp); 4032 *resp_len = opa_get_smp_header_size(smp);
@@ -3861,23 +4038,25 @@ static int process_subn_opa(struct ib_device *ibdev, int mad_flags,
3861 clear_opa_smp_data(smp); 4038 clear_opa_smp_data(smp);
3862 ret = subn_get_opa_sma(attr_id, smp, am, data, 4039 ret = subn_get_opa_sma(attr_id, smp, am, data,
3863 ibdev, port, resp_len); 4040 ibdev, port, resp_len);
3864 goto bail; 4041 break;
3865 case OPA_ATTRIB_ID_AGGREGATE: 4042 case OPA_ATTRIB_ID_AGGREGATE:
3866 ret = subn_get_opa_aggregate(smp, ibdev, port, 4043 ret = subn_get_opa_aggregate(smp, ibdev, port,
3867 resp_len); 4044 resp_len);
3868 goto bail; 4045 break;
3869 } 4046 }
4047 break;
3870 case IB_MGMT_METHOD_SET: 4048 case IB_MGMT_METHOD_SET:
3871 switch (attr_id) { 4049 switch (attr_id) {
3872 default: 4050 default:
3873 ret = subn_set_opa_sma(attr_id, smp, am, data, 4051 ret = subn_set_opa_sma(attr_id, smp, am, data,
3874 ibdev, port, resp_len); 4052 ibdev, port, resp_len);
3875 goto bail; 4053 break;
3876 case OPA_ATTRIB_ID_AGGREGATE: 4054 case OPA_ATTRIB_ID_AGGREGATE:
3877 ret = subn_set_opa_aggregate(smp, ibdev, port, 4055 ret = subn_set_opa_aggregate(smp, ibdev, port,
3878 resp_len); 4056 resp_len);
3879 goto bail; 4057 break;
3880 } 4058 }
4059 break;
3881 case IB_MGMT_METHOD_TRAP: 4060 case IB_MGMT_METHOD_TRAP:
3882 case IB_MGMT_METHOD_REPORT: 4061 case IB_MGMT_METHOD_REPORT:
3883 case IB_MGMT_METHOD_REPORT_RESP: 4062 case IB_MGMT_METHOD_REPORT_RESP:
@@ -3888,13 +4067,13 @@ static int process_subn_opa(struct ib_device *ibdev, int mad_flags,
3888 * Just tell the caller to process it normally. 4067 * Just tell the caller to process it normally.
3889 */ 4068 */
3890 ret = IB_MAD_RESULT_SUCCESS; 4069 ret = IB_MAD_RESULT_SUCCESS;
3891 goto bail; 4070 break;
3892 default: 4071 default:
3893 smp->status |= IB_SMP_UNSUP_METHOD; 4072 smp->status |= IB_SMP_UNSUP_METHOD;
3894 ret = reply((struct ib_mad_hdr *)smp); 4073 ret = reply((struct ib_mad_hdr *)smp);
4074 break;
3895 } 4075 }
3896 4076
3897bail:
3898 return ret; 4077 return ret;
3899} 4078}
3900 4079
@@ -3910,7 +4089,7 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
3910 if (smp->class_version != 1) { 4089 if (smp->class_version != 1) {
3911 smp->status |= IB_SMP_UNSUP_VERSION; 4090 smp->status |= IB_SMP_UNSUP_VERSION;
3912 ret = reply((struct ib_mad_hdr *)smp); 4091 ret = reply((struct ib_mad_hdr *)smp);
3913 goto bail; 4092 return ret;
3914 } 4093 }
3915 4094
3916 ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, 4095 ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags,
@@ -3931,13 +4110,13 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
3931 smp->method == IB_MGMT_METHOD_SET) && 4110 smp->method == IB_MGMT_METHOD_SET) &&
3932 port_num && port_num <= ibdev->phys_port_cnt && 4111 port_num && port_num <= ibdev->phys_port_cnt &&
3933 port != port_num) 4112 port != port_num)
3934 (void) check_mkey(to_iport(ibdev, port_num), 4113 (void)check_mkey(to_iport(ibdev, port_num),
3935 (struct ib_mad_hdr *)smp, 0, 4114 (struct ib_mad_hdr *)smp, 0,
3936 smp->mkey, 4115 smp->mkey,
3937 (__force __be32)smp->dr_slid, 4116 (__force __be32)smp->dr_slid,
3938 smp->return_path, smp->hop_cnt); 4117 smp->return_path, smp->hop_cnt);
3939 ret = IB_MAD_RESULT_FAILURE; 4118 ret = IB_MAD_RESULT_FAILURE;
3940 goto bail; 4119 return ret;
3941 } 4120 }
3942 4121
3943 switch (smp->method) { 4122 switch (smp->method) {
@@ -3945,15 +4124,77 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
3945 switch (smp->attr_id) { 4124 switch (smp->attr_id) {
3946 case IB_SMP_ATTR_NODE_INFO: 4125 case IB_SMP_ATTR_NODE_INFO:
3947 ret = subn_get_nodeinfo(smp, ibdev, port); 4126 ret = subn_get_nodeinfo(smp, ibdev, port);
3948 goto bail; 4127 break;
3949 default: 4128 default:
3950 smp->status |= IB_SMP_UNSUP_METH_ATTR; 4129 smp->status |= IB_SMP_UNSUP_METH_ATTR;
3951 ret = reply((struct ib_mad_hdr *)smp); 4130 ret = reply((struct ib_mad_hdr *)smp);
3952 goto bail; 4131 break;
3953 } 4132 }
4133 break;
4134 }
4135
4136 return ret;
4137}
4138
4139static int process_perf(struct ib_device *ibdev, u8 port,
4140 const struct ib_mad *in_mad,
4141 struct ib_mad *out_mad)
4142{
4143 struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad;
4144 struct ib_class_port_info *cpi = (struct ib_class_port_info *)
4145 &pmp->data;
4146 int ret = IB_MAD_RESULT_FAILURE;
4147
4148 *out_mad = *in_mad;
4149 if (pmp->mad_hdr.class_version != 1) {
4150 pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
4151 ret = reply((struct ib_mad_hdr *)pmp);
4152 return ret;
4153 }
4154
4155 switch (pmp->mad_hdr.method) {
4156 case IB_MGMT_METHOD_GET:
4157 switch (pmp->mad_hdr.attr_id) {
4158 case IB_PMA_PORT_COUNTERS:
4159 ret = pma_get_ib_portcounters(pmp, ibdev, port);
4160 break;
4161 case IB_PMA_PORT_COUNTERS_EXT:
4162 ret = pma_get_ib_portcounters_ext(pmp, ibdev, port);
4163 break;
4164 case IB_PMA_CLASS_PORT_INFO:
4165 cpi->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
4166 ret = reply((struct ib_mad_hdr *)pmp);
4167 break;
4168 default:
4169 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
4170 ret = reply((struct ib_mad_hdr *)pmp);
4171 break;
4172 }
4173 break;
4174
4175 case IB_MGMT_METHOD_SET:
4176 if (pmp->mad_hdr.attr_id) {
4177 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
4178 ret = reply((struct ib_mad_hdr *)pmp);
4179 }
4180 break;
4181
4182 case IB_MGMT_METHOD_TRAP:
4183 case IB_MGMT_METHOD_GET_RESP:
4184 /*
4185 * The ib_mad module will call us to process responses
4186 * before checking for other consumers.
4187 * Just tell the caller to process it normally.
4188 */
4189 ret = IB_MAD_RESULT_SUCCESS;
4190 break;
4191
4192 default:
4193 pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
4194 ret = reply((struct ib_mad_hdr *)pmp);
4195 break;
3954 } 4196 }
3955 4197
3956bail:
3957 return ret; 4198 return ret;
3958} 4199}
3959 4200
@@ -3978,44 +4219,46 @@ static int process_perf_opa(struct ib_device *ibdev, u8 port,
3978 switch (pmp->mad_hdr.attr_id) { 4219 switch (pmp->mad_hdr.attr_id) {
3979 case IB_PMA_CLASS_PORT_INFO: 4220 case IB_PMA_CLASS_PORT_INFO:
3980 ret = pma_get_opa_classportinfo(pmp, ibdev, resp_len); 4221 ret = pma_get_opa_classportinfo(pmp, ibdev, resp_len);
3981 goto bail; 4222 break;
3982 case OPA_PM_ATTRIB_ID_PORT_STATUS: 4223 case OPA_PM_ATTRIB_ID_PORT_STATUS:
3983 ret = pma_get_opa_portstatus(pmp, ibdev, port, 4224 ret = pma_get_opa_portstatus(pmp, ibdev, port,
3984 resp_len); 4225 resp_len);
3985 goto bail; 4226 break;
3986 case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS: 4227 case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS:
3987 ret = pma_get_opa_datacounters(pmp, ibdev, port, 4228 ret = pma_get_opa_datacounters(pmp, ibdev, port,
3988 resp_len); 4229 resp_len);
3989 goto bail; 4230 break;
3990 case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS: 4231 case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS:
3991 ret = pma_get_opa_porterrors(pmp, ibdev, port, 4232 ret = pma_get_opa_porterrors(pmp, ibdev, port,
3992 resp_len); 4233 resp_len);
3993 goto bail; 4234 break;
3994 case OPA_PM_ATTRIB_ID_ERROR_INFO: 4235 case OPA_PM_ATTRIB_ID_ERROR_INFO:
3995 ret = pma_get_opa_errorinfo(pmp, ibdev, port, 4236 ret = pma_get_opa_errorinfo(pmp, ibdev, port,
3996 resp_len); 4237 resp_len);
3997 goto bail; 4238 break;
3998 default: 4239 default:
3999 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; 4240 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
4000 ret = reply((struct ib_mad_hdr *)pmp); 4241 ret = reply((struct ib_mad_hdr *)pmp);
4001 goto bail; 4242 break;
4002 } 4243 }
4244 break;
4003 4245
4004 case IB_MGMT_METHOD_SET: 4246 case IB_MGMT_METHOD_SET:
4005 switch (pmp->mad_hdr.attr_id) { 4247 switch (pmp->mad_hdr.attr_id) {
4006 case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS: 4248 case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS:
4007 ret = pma_set_opa_portstatus(pmp, ibdev, port, 4249 ret = pma_set_opa_portstatus(pmp, ibdev, port,
4008 resp_len); 4250 resp_len);
4009 goto bail; 4251 break;
4010 case OPA_PM_ATTRIB_ID_ERROR_INFO: 4252 case OPA_PM_ATTRIB_ID_ERROR_INFO:
4011 ret = pma_set_opa_errorinfo(pmp, ibdev, port, 4253 ret = pma_set_opa_errorinfo(pmp, ibdev, port,
4012 resp_len); 4254 resp_len);
4013 goto bail; 4255 break;
4014 default: 4256 default:
4015 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; 4257 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
4016 ret = reply((struct ib_mad_hdr *)pmp); 4258 ret = reply((struct ib_mad_hdr *)pmp);
4017 goto bail; 4259 break;
4018 } 4260 }
4261 break;
4019 4262
4020 case IB_MGMT_METHOD_TRAP: 4263 case IB_MGMT_METHOD_TRAP:
4021 case IB_MGMT_METHOD_GET_RESP: 4264 case IB_MGMT_METHOD_GET_RESP:
@@ -4025,14 +4268,14 @@ static int process_perf_opa(struct ib_device *ibdev, u8 port,
4025 * Just tell the caller to process it normally. 4268 * Just tell the caller to process it normally.
4026 */ 4269 */
4027 ret = IB_MAD_RESULT_SUCCESS; 4270 ret = IB_MAD_RESULT_SUCCESS;
4028 goto bail; 4271 break;
4029 4272
4030 default: 4273 default:
4031 pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD; 4274 pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
4032 ret = reply((struct ib_mad_hdr *)pmp); 4275 ret = reply((struct ib_mad_hdr *)pmp);
4276 break;
4033 } 4277 }
4034 4278
4035bail:
4036 return ret; 4279 return ret;
4037} 4280}
4038 4281
@@ -4097,12 +4340,15 @@ static int hfi1_process_ib_mad(struct ib_device *ibdev, int mad_flags, u8 port,
4097 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE: 4340 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
4098 case IB_MGMT_CLASS_SUBN_LID_ROUTED: 4341 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
4099 ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad); 4342 ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad);
4100 goto bail; 4343 break;
4344 case IB_MGMT_CLASS_PERF_MGMT:
4345 ret = process_perf(ibdev, port, in_mad, out_mad);
4346 break;
4101 default: 4347 default:
4102 ret = IB_MAD_RESULT_SUCCESS; 4348 ret = IB_MAD_RESULT_SUCCESS;
4349 break;
4103 } 4350 }
4104 4351
4105bail:
4106 return ret; 4352 return ret;
4107} 4353}
4108 4354
@@ -4154,66 +4400,3 @@ int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
4154 4400
4155 return IB_MAD_RESULT_FAILURE; 4401 return IB_MAD_RESULT_FAILURE;
4156} 4402}
4157
4158static void send_handler(struct ib_mad_agent *agent,
4159 struct ib_mad_send_wc *mad_send_wc)
4160{
4161 ib_free_send_mad(mad_send_wc->send_buf);
4162}
4163
4164int hfi1_create_agents(struct hfi1_ibdev *dev)
4165{
4166 struct hfi1_devdata *dd = dd_from_dev(dev);
4167 struct ib_mad_agent *agent;
4168 struct hfi1_ibport *ibp;
4169 int p;
4170 int ret;
4171
4172 for (p = 0; p < dd->num_pports; p++) {
4173 ibp = &dd->pport[p].ibport_data;
4174 agent = ib_register_mad_agent(&dev->ibdev, p + 1, IB_QPT_SMI,
4175 NULL, 0, send_handler,
4176 NULL, NULL, 0);
4177 if (IS_ERR(agent)) {
4178 ret = PTR_ERR(agent);
4179 goto err;
4180 }
4181
4182 ibp->send_agent = agent;
4183 }
4184
4185 return 0;
4186
4187err:
4188 for (p = 0; p < dd->num_pports; p++) {
4189 ibp = &dd->pport[p].ibport_data;
4190 if (ibp->send_agent) {
4191 agent = ibp->send_agent;
4192 ibp->send_agent = NULL;
4193 ib_unregister_mad_agent(agent);
4194 }
4195 }
4196
4197 return ret;
4198}
4199
4200void hfi1_free_agents(struct hfi1_ibdev *dev)
4201{
4202 struct hfi1_devdata *dd = dd_from_dev(dev);
4203 struct ib_mad_agent *agent;
4204 struct hfi1_ibport *ibp;
4205 int p;
4206
4207 for (p = 0; p < dd->num_pports; p++) {
4208 ibp = &dd->pport[p].ibport_data;
4209 if (ibp->send_agent) {
4210 agent = ibp->send_agent;
4211 ibp->send_agent = NULL;
4212 ib_unregister_mad_agent(agent);
4213 }
4214 if (ibp->sm_ah) {
4215 ib_destroy_ah(&ibp->sm_ah->ibah);
4216 ibp->sm_ah = NULL;
4217 }
4218 }
4219}
diff --git a/drivers/staging/rdma/hfi1/mad.h b/drivers/staging/rdma/hfi1/mad.h
index f0317750e2fc..55ee08675333 100644
--- a/drivers/staging/rdma/hfi1/mad.h
+++ b/drivers/staging/rdma/hfi1/mad.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -51,8 +48,10 @@
51#define _HFI1_MAD_H 48#define _HFI1_MAD_H
52 49
53#include <rdma/ib_pma.h> 50#include <rdma/ib_pma.h>
54#define USE_PI_LED_ENABLE 1 /* use led enabled bit in struct 51#define USE_PI_LED_ENABLE 1 /*
55 * opa_port_states, if available */ 52 * use led enabled bit in struct
53 * opa_port_states, if available
54 */
56#include <rdma/opa_smi.h> 55#include <rdma/opa_smi.h>
57#include <rdma/opa_port_info.h> 56#include <rdma/opa_port_info.h>
58#ifndef PI_LED_ENABLE_SUP 57#ifndef PI_LED_ENABLE_SUP
@@ -235,7 +234,6 @@ struct ib_pma_portcounters_cong {
235#define IB_CC_SVCTYPE_RD 0x2 234#define IB_CC_SVCTYPE_RD 0x2
236#define IB_CC_SVCTYPE_UD 0x3 235#define IB_CC_SVCTYPE_UD 0x3
237 236
238
239/* 237/*
240 * There should be an equivalent IB #define for the following, but 238 * There should be an equivalent IB #define for the following, but
241 * I cannot find it. 239 * I cannot find it.
@@ -267,7 +265,7 @@ struct opa_hfi1_cong_log {
267 u8 congestion_flags; 265 u8 congestion_flags;
268 __be16 threshold_event_counter; 266 __be16 threshold_event_counter;
269 __be32 current_time_stamp; 267 __be32 current_time_stamp;
270 u8 threshold_cong_event_map[OPA_MAX_SLS/8]; 268 u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
271 struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS]; 269 struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS];
272} __packed; 270} __packed;
273 271
diff --git a/drivers/staging/rdma/hfi1/mmu_rb.c b/drivers/staging/rdma/hfi1/mmu_rb.c
new file mode 100644
index 000000000000..c7ad0164ea9a
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/mmu_rb.c
@@ -0,0 +1,292 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#include <linux/list.h>
48#include <linux/mmu_notifier.h>
49#include <linux/interval_tree_generic.h>
50
51#include "mmu_rb.h"
52#include "trace.h"
53
54struct mmu_rb_handler {
55 struct list_head list;
56 struct mmu_notifier mn;
57 struct rb_root *root;
58 spinlock_t lock; /* protect the RB tree */
59 struct mmu_rb_ops *ops;
60};
61
62static LIST_HEAD(mmu_rb_handlers);
63static DEFINE_SPINLOCK(mmu_rb_lock); /* protect mmu_rb_handlers list */
64
65static unsigned long mmu_node_start(struct mmu_rb_node *);
66static unsigned long mmu_node_last(struct mmu_rb_node *);
67static struct mmu_rb_handler *find_mmu_handler(struct rb_root *);
68static inline void mmu_notifier_page(struct mmu_notifier *, struct mm_struct *,
69 unsigned long);
70static inline void mmu_notifier_range_start(struct mmu_notifier *,
71 struct mm_struct *,
72 unsigned long, unsigned long);
73static void mmu_notifier_mem_invalidate(struct mmu_notifier *,
74 unsigned long, unsigned long);
75static struct mmu_rb_node *__mmu_rb_search(struct mmu_rb_handler *,
76 unsigned long, unsigned long);
77
78static struct mmu_notifier_ops mn_opts = {
79 .invalidate_page = mmu_notifier_page,
80 .invalidate_range_start = mmu_notifier_range_start,
81};
82
83INTERVAL_TREE_DEFINE(struct mmu_rb_node, node, unsigned long, __last,
84 mmu_node_start, mmu_node_last, static, __mmu_int_rb);
85
86static unsigned long mmu_node_start(struct mmu_rb_node *node)
87{
88 return node->addr & PAGE_MASK;
89}
90
91static unsigned long mmu_node_last(struct mmu_rb_node *node)
92{
93 return PAGE_ALIGN((node->addr & PAGE_MASK) + node->len) - 1;
94}
95
96int hfi1_mmu_rb_register(struct rb_root *root, struct mmu_rb_ops *ops)
97{
98 struct mmu_rb_handler *handlr;
99 unsigned long flags;
100
101 if (!ops->invalidate)
102 return -EINVAL;
103
104 handlr = kmalloc(sizeof(*handlr), GFP_KERNEL);
105 if (!handlr)
106 return -ENOMEM;
107
108 handlr->root = root;
109 handlr->ops = ops;
110 INIT_HLIST_NODE(&handlr->mn.hlist);
111 spin_lock_init(&handlr->lock);
112 handlr->mn.ops = &mn_opts;
113 spin_lock_irqsave(&mmu_rb_lock, flags);
114 list_add_tail(&handlr->list, &mmu_rb_handlers);
115 spin_unlock_irqrestore(&mmu_rb_lock, flags);
116
117 return mmu_notifier_register(&handlr->mn, current->mm);
118}
119
120void hfi1_mmu_rb_unregister(struct rb_root *root)
121{
122 struct mmu_rb_handler *handler = find_mmu_handler(root);
123 unsigned long flags;
124
125 if (!handler)
126 return;
127
128 spin_lock_irqsave(&mmu_rb_lock, flags);
129 list_del(&handler->list);
130 spin_unlock_irqrestore(&mmu_rb_lock, flags);
131
132 if (!RB_EMPTY_ROOT(root)) {
133 struct rb_node *node;
134 struct mmu_rb_node *rbnode;
135
136 while ((node = rb_first(root))) {
137 rbnode = rb_entry(node, struct mmu_rb_node, node);
138 rb_erase(node, root);
139 if (handler->ops->remove)
140 handler->ops->remove(root, rbnode, false);
141 }
142 }
143
144 if (current->mm)
145 mmu_notifier_unregister(&handler->mn, current->mm);
146 kfree(handler);
147}
148
149int hfi1_mmu_rb_insert(struct rb_root *root, struct mmu_rb_node *mnode)
150{
151 struct mmu_rb_handler *handler = find_mmu_handler(root);
152 struct mmu_rb_node *node;
153 unsigned long flags;
154 int ret = 0;
155
156 if (!handler)
157 return -EINVAL;
158
159 spin_lock_irqsave(&handler->lock, flags);
160 hfi1_cdbg(MMU, "Inserting node addr 0x%llx, len %u", mnode->addr,
161 mnode->len);
162 node = __mmu_rb_search(handler, mnode->addr, mnode->len);
163 if (node) {
164 ret = -EINVAL;
165 goto unlock;
166 }
167 __mmu_int_rb_insert(mnode, root);
168
169 if (handler->ops->insert) {
170 ret = handler->ops->insert(root, mnode);
171 if (ret)
172 __mmu_int_rb_remove(mnode, root);
173 }
174unlock:
175 spin_unlock_irqrestore(&handler->lock, flags);
176 return ret;
177}
178
179/* Caller must host handler lock */
180static struct mmu_rb_node *__mmu_rb_search(struct mmu_rb_handler *handler,
181 unsigned long addr,
182 unsigned long len)
183{
184 struct mmu_rb_node *node = NULL;
185
186 hfi1_cdbg(MMU, "Searching for addr 0x%llx, len %u", addr, len);
187 if (!handler->ops->filter) {
188 node = __mmu_int_rb_iter_first(handler->root, addr,
189 (addr + len) - 1);
190 } else {
191 for (node = __mmu_int_rb_iter_first(handler->root, addr,
192 (addr + len) - 1);
193 node;
194 node = __mmu_int_rb_iter_next(node, addr,
195 (addr + len) - 1)) {
196 if (handler->ops->filter(node, addr, len))
197 return node;
198 }
199 }
200 return node;
201}
202
203static void __mmu_rb_remove(struct mmu_rb_handler *handler,
204 struct mmu_rb_node *node, bool arg)
205{
206 /* Validity of handler and node pointers has been checked by caller. */
207 hfi1_cdbg(MMU, "Removing node addr 0x%llx, len %u", node->addr,
208 node->len);
209 __mmu_int_rb_remove(node, handler->root);
210 if (handler->ops->remove)
211 handler->ops->remove(handler->root, node, arg);
212}
213
214struct mmu_rb_node *hfi1_mmu_rb_search(struct rb_root *root, unsigned long addr,
215 unsigned long len)
216{
217 struct mmu_rb_handler *handler = find_mmu_handler(root);
218 struct mmu_rb_node *node;
219 unsigned long flags;
220
221 if (!handler)
222 return ERR_PTR(-EINVAL);
223
224 spin_lock_irqsave(&handler->lock, flags);
225 node = __mmu_rb_search(handler, addr, len);
226 spin_unlock_irqrestore(&handler->lock, flags);
227
228 return node;
229}
230
231void hfi1_mmu_rb_remove(struct rb_root *root, struct mmu_rb_node *node)
232{
233 struct mmu_rb_handler *handler = find_mmu_handler(root);
234 unsigned long flags;
235
236 if (!handler || !node)
237 return;
238
239 spin_lock_irqsave(&handler->lock, flags);
240 __mmu_rb_remove(handler, node, false);
241 spin_unlock_irqrestore(&handler->lock, flags);
242}
243
244static struct mmu_rb_handler *find_mmu_handler(struct rb_root *root)
245{
246 struct mmu_rb_handler *handler;
247 unsigned long flags;
248
249 spin_lock_irqsave(&mmu_rb_lock, flags);
250 list_for_each_entry(handler, &mmu_rb_handlers, list) {
251 if (handler->root == root)
252 goto unlock;
253 }
254 handler = NULL;
255unlock:
256 spin_unlock_irqrestore(&mmu_rb_lock, flags);
257 return handler;
258}
259
260static inline void mmu_notifier_page(struct mmu_notifier *mn,
261 struct mm_struct *mm, unsigned long addr)
262{
263 mmu_notifier_mem_invalidate(mn, addr, addr + PAGE_SIZE);
264}
265
266static inline void mmu_notifier_range_start(struct mmu_notifier *mn,
267 struct mm_struct *mm,
268 unsigned long start,
269 unsigned long end)
270{
271 mmu_notifier_mem_invalidate(mn, start, end);
272}
273
274static void mmu_notifier_mem_invalidate(struct mmu_notifier *mn,
275 unsigned long start, unsigned long end)
276{
277 struct mmu_rb_handler *handler =
278 container_of(mn, struct mmu_rb_handler, mn);
279 struct rb_root *root = handler->root;
280 struct mmu_rb_node *node;
281 unsigned long flags;
282
283 spin_lock_irqsave(&handler->lock, flags);
284 for (node = __mmu_int_rb_iter_first(root, start, end - 1); node;
285 node = __mmu_int_rb_iter_next(node, start, end - 1)) {
286 hfi1_cdbg(MMU, "Invalidating node addr 0x%llx, len %u",
287 node->addr, node->len);
288 if (handler->ops->invalidate(root, node))
289 __mmu_rb_remove(handler, node, true);
290 }
291 spin_unlock_irqrestore(&handler->lock, flags);
292}
diff --git a/drivers/staging/rdma/hfi1/mmu_rb.h b/drivers/staging/rdma/hfi1/mmu_rb.h
new file mode 100644
index 000000000000..f8523fdb8a18
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/mmu_rb.h
@@ -0,0 +1,73 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#ifndef _HFI1_MMU_RB_H
48#define _HFI1_MMU_RB_H
49
50#include "hfi.h"
51
52struct mmu_rb_node {
53 unsigned long addr;
54 unsigned long len;
55 unsigned long __last;
56 struct rb_node node;
57};
58
59struct mmu_rb_ops {
60 bool (*filter)(struct mmu_rb_node *, unsigned long, unsigned long);
61 int (*insert)(struct rb_root *, struct mmu_rb_node *);
62 void (*remove)(struct rb_root *, struct mmu_rb_node *, bool);
63 int (*invalidate)(struct rb_root *, struct mmu_rb_node *);
64};
65
66int hfi1_mmu_rb_register(struct rb_root *root, struct mmu_rb_ops *ops);
67void hfi1_mmu_rb_unregister(struct rb_root *);
68int hfi1_mmu_rb_insert(struct rb_root *, struct mmu_rb_node *);
69void hfi1_mmu_rb_remove(struct rb_root *, struct mmu_rb_node *);
70struct mmu_rb_node *hfi1_mmu_rb_search(struct rb_root *, unsigned long,
71 unsigned long);
72
73#endif /* _HFI1_MMU_RB_H */
diff --git a/drivers/staging/rdma/hfi1/mr.c b/drivers/staging/rdma/hfi1/mr.c
deleted file mode 100644
index 38253212af7a..000000000000
--- a/drivers/staging/rdma/hfi1/mr.c
+++ /dev/null
@@ -1,473 +0,0 @@
1/*
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * BSD LICENSE
20 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/ib_umem.h>
52#include <rdma/ib_smi.h>
53
54#include "hfi.h"
55
56/* Fast memory region */
57struct hfi1_fmr {
58 struct ib_fmr ibfmr;
59 struct hfi1_mregion mr; /* must be last */
60};
61
62static inline struct hfi1_fmr *to_ifmr(struct ib_fmr *ibfmr)
63{
64 return container_of(ibfmr, struct hfi1_fmr, ibfmr);
65}
66
67static int init_mregion(struct hfi1_mregion *mr, struct ib_pd *pd,
68 int count)
69{
70 int m, i = 0;
71 int rval = 0;
72
73 m = DIV_ROUND_UP(count, HFI1_SEGSZ);
74 for (; i < m; i++) {
75 mr->map[i] = kzalloc(sizeof(*mr->map[0]), GFP_KERNEL);
76 if (!mr->map[i])
77 goto bail;
78 }
79 mr->mapsz = m;
80 init_completion(&mr->comp);
81 /* count returning the ptr to user */
82 atomic_set(&mr->refcount, 1);
83 mr->pd = pd;
84 mr->max_segs = count;
85out:
86 return rval;
87bail:
88 while (i)
89 kfree(mr->map[--i]);
90 rval = -ENOMEM;
91 goto out;
92}
93
94static void deinit_mregion(struct hfi1_mregion *mr)
95{
96 int i = mr->mapsz;
97
98 mr->mapsz = 0;
99 while (i)
100 kfree(mr->map[--i]);
101}
102
103
104/**
105 * hfi1_get_dma_mr - get a DMA memory region
106 * @pd: protection domain for this memory region
107 * @acc: access flags
108 *
109 * Returns the memory region on success, otherwise returns an errno.
110 * Note that all DMA addresses should be created via the
111 * struct ib_dma_mapping_ops functions (see dma.c).
112 */
113struct ib_mr *hfi1_get_dma_mr(struct ib_pd *pd, int acc)
114{
115 struct hfi1_mr *mr = NULL;
116 struct ib_mr *ret;
117 int rval;
118
119 if (to_ipd(pd)->user) {
120 ret = ERR_PTR(-EPERM);
121 goto bail;
122 }
123
124 mr = kzalloc(sizeof(*mr), GFP_KERNEL);
125 if (!mr) {
126 ret = ERR_PTR(-ENOMEM);
127 goto bail;
128 }
129
130 rval = init_mregion(&mr->mr, pd, 0);
131 if (rval) {
132 ret = ERR_PTR(rval);
133 goto bail;
134 }
135
136
137 rval = hfi1_alloc_lkey(&mr->mr, 1);
138 if (rval) {
139 ret = ERR_PTR(rval);
140 goto bail_mregion;
141 }
142
143 mr->mr.access_flags = acc;
144 ret = &mr->ibmr;
145done:
146 return ret;
147
148bail_mregion:
149 deinit_mregion(&mr->mr);
150bail:
151 kfree(mr);
152 goto done;
153}
154
155static struct hfi1_mr *alloc_mr(int count, struct ib_pd *pd)
156{
157 struct hfi1_mr *mr;
158 int rval = -ENOMEM;
159 int m;
160
161 /* Allocate struct plus pointers to first level page tables. */
162 m = DIV_ROUND_UP(count, HFI1_SEGSZ);
163 mr = kzalloc(sizeof(*mr) + m * sizeof(mr->mr.map[0]), GFP_KERNEL);
164 if (!mr)
165 goto bail;
166
167 rval = init_mregion(&mr->mr, pd, count);
168 if (rval)
169 goto bail;
170
171 rval = hfi1_alloc_lkey(&mr->mr, 0);
172 if (rval)
173 goto bail_mregion;
174 mr->ibmr.lkey = mr->mr.lkey;
175 mr->ibmr.rkey = mr->mr.lkey;
176done:
177 return mr;
178
179bail_mregion:
180 deinit_mregion(&mr->mr);
181bail:
182 kfree(mr);
183 mr = ERR_PTR(rval);
184 goto done;
185}
186
187/**
188 * hfi1_reg_user_mr - register a userspace memory region
189 * @pd: protection domain for this memory region
190 * @start: starting userspace address
191 * @length: length of region to register
192 * @mr_access_flags: access flags for this memory region
193 * @udata: unused by the driver
194 *
195 * Returns the memory region on success, otherwise returns an errno.
196 */
197struct ib_mr *hfi1_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
198 u64 virt_addr, int mr_access_flags,
199 struct ib_udata *udata)
200{
201 struct hfi1_mr *mr;
202 struct ib_umem *umem;
203 struct scatterlist *sg;
204 int n, m, entry;
205 struct ib_mr *ret;
206
207 if (length == 0) {
208 ret = ERR_PTR(-EINVAL);
209 goto bail;
210 }
211
212 umem = ib_umem_get(pd->uobject->context, start, length,
213 mr_access_flags, 0);
214 if (IS_ERR(umem))
215 return (void *) umem;
216
217 n = umem->nmap;
218
219 mr = alloc_mr(n, pd);
220 if (IS_ERR(mr)) {
221 ret = (struct ib_mr *)mr;
222 ib_umem_release(umem);
223 goto bail;
224 }
225
226 mr->mr.user_base = start;
227 mr->mr.iova = virt_addr;
228 mr->mr.length = length;
229 mr->mr.offset = ib_umem_offset(umem);
230 mr->mr.access_flags = mr_access_flags;
231 mr->umem = umem;
232
233 if (is_power_of_2(umem->page_size))
234 mr->mr.page_shift = ilog2(umem->page_size);
235 m = 0;
236 n = 0;
237 for_each_sg(umem->sg_head.sgl, sg, umem->nmap, entry) {
238 void *vaddr;
239
240 vaddr = page_address(sg_page(sg));
241 if (!vaddr) {
242 ret = ERR_PTR(-EINVAL);
243 goto bail;
244 }
245 mr->mr.map[m]->segs[n].vaddr = vaddr;
246 mr->mr.map[m]->segs[n].length = umem->page_size;
247 n++;
248 if (n == HFI1_SEGSZ) {
249 m++;
250 n = 0;
251 }
252 }
253 ret = &mr->ibmr;
254
255bail:
256 return ret;
257}
258
259/**
260 * hfi1_dereg_mr - unregister and free a memory region
261 * @ibmr: the memory region to free
262 *
263 * Returns 0 on success.
264 *
265 * Note that this is called to free MRs created by hfi1_get_dma_mr()
266 * or hfi1_reg_user_mr().
267 */
268int hfi1_dereg_mr(struct ib_mr *ibmr)
269{
270 struct hfi1_mr *mr = to_imr(ibmr);
271 int ret = 0;
272 unsigned long timeout;
273
274 hfi1_free_lkey(&mr->mr);
275
276 hfi1_put_mr(&mr->mr); /* will set completion if last */
277 timeout = wait_for_completion_timeout(&mr->mr.comp,
278 5 * HZ);
279 if (!timeout) {
280 dd_dev_err(
281 dd_from_ibdev(mr->mr.pd->device),
282 "hfi1_dereg_mr timeout mr %p pd %p refcount %u\n",
283 mr, mr->mr.pd, atomic_read(&mr->mr.refcount));
284 hfi1_get_mr(&mr->mr);
285 ret = -EBUSY;
286 goto out;
287 }
288 deinit_mregion(&mr->mr);
289 if (mr->umem)
290 ib_umem_release(mr->umem);
291 kfree(mr);
292out:
293 return ret;
294}
295
296/*
297 * Allocate a memory region usable with the
298 * IB_WR_REG_MR send work request.
299 *
300 * Return the memory region on success, otherwise return an errno.
301 * FIXME: IB_WR_REG_MR is not supported
302 */
303struct ib_mr *hfi1_alloc_mr(struct ib_pd *pd,
304 enum ib_mr_type mr_type,
305 u32 max_num_sg)
306{
307 struct hfi1_mr *mr;
308
309 if (mr_type != IB_MR_TYPE_MEM_REG)
310 return ERR_PTR(-EINVAL);
311
312 mr = alloc_mr(max_num_sg, pd);
313 if (IS_ERR(mr))
314 return (struct ib_mr *)mr;
315
316 return &mr->ibmr;
317}
318
319/**
320 * hfi1_alloc_fmr - allocate a fast memory region
321 * @pd: the protection domain for this memory region
322 * @mr_access_flags: access flags for this memory region
323 * @fmr_attr: fast memory region attributes
324 *
325 * Returns the memory region on success, otherwise returns an errno.
326 */
327struct ib_fmr *hfi1_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
328 struct ib_fmr_attr *fmr_attr)
329{
330 struct hfi1_fmr *fmr;
331 int m;
332 struct ib_fmr *ret;
333 int rval = -ENOMEM;
334
335 /* Allocate struct plus pointers to first level page tables. */
336 m = DIV_ROUND_UP(fmr_attr->max_pages, HFI1_SEGSZ);
337 fmr = kzalloc(sizeof(*fmr) + m * sizeof(fmr->mr.map[0]), GFP_KERNEL);
338 if (!fmr)
339 goto bail;
340
341 rval = init_mregion(&fmr->mr, pd, fmr_attr->max_pages);
342 if (rval)
343 goto bail;
344
345 /*
346 * ib_alloc_fmr() will initialize fmr->ibfmr except for lkey &
347 * rkey.
348 */
349 rval = hfi1_alloc_lkey(&fmr->mr, 0);
350 if (rval)
351 goto bail_mregion;
352 fmr->ibfmr.rkey = fmr->mr.lkey;
353 fmr->ibfmr.lkey = fmr->mr.lkey;
354 /*
355 * Resources are allocated but no valid mapping (RKEY can't be
356 * used).
357 */
358 fmr->mr.access_flags = mr_access_flags;
359 fmr->mr.max_segs = fmr_attr->max_pages;
360 fmr->mr.page_shift = fmr_attr->page_shift;
361
362 ret = &fmr->ibfmr;
363done:
364 return ret;
365
366bail_mregion:
367 deinit_mregion(&fmr->mr);
368bail:
369 kfree(fmr);
370 ret = ERR_PTR(rval);
371 goto done;
372}
373
374/**
375 * hfi1_map_phys_fmr - set up a fast memory region
376 * @ibmfr: the fast memory region to set up
377 * @page_list: the list of pages to associate with the fast memory region
378 * @list_len: the number of pages to associate with the fast memory region
379 * @iova: the virtual address of the start of the fast memory region
380 *
381 * This may be called from interrupt context.
382 */
383
384int hfi1_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
385 int list_len, u64 iova)
386{
387 struct hfi1_fmr *fmr = to_ifmr(ibfmr);
388 struct hfi1_lkey_table *rkt;
389 unsigned long flags;
390 int m, n, i;
391 u32 ps;
392 int ret;
393
394 i = atomic_read(&fmr->mr.refcount);
395 if (i > 2)
396 return -EBUSY;
397
398 if (list_len > fmr->mr.max_segs) {
399 ret = -EINVAL;
400 goto bail;
401 }
402 rkt = &to_idev(ibfmr->device)->lk_table;
403 spin_lock_irqsave(&rkt->lock, flags);
404 fmr->mr.user_base = iova;
405 fmr->mr.iova = iova;
406 ps = 1 << fmr->mr.page_shift;
407 fmr->mr.length = list_len * ps;
408 m = 0;
409 n = 0;
410 for (i = 0; i < list_len; i++) {
411 fmr->mr.map[m]->segs[n].vaddr = (void *) page_list[i];
412 fmr->mr.map[m]->segs[n].length = ps;
413 if (++n == HFI1_SEGSZ) {
414 m++;
415 n = 0;
416 }
417 }
418 spin_unlock_irqrestore(&rkt->lock, flags);
419 ret = 0;
420
421bail:
422 return ret;
423}
424
425/**
426 * hfi1_unmap_fmr - unmap fast memory regions
427 * @fmr_list: the list of fast memory regions to unmap
428 *
429 * Returns 0 on success.
430 */
431int hfi1_unmap_fmr(struct list_head *fmr_list)
432{
433 struct hfi1_fmr *fmr;
434 struct hfi1_lkey_table *rkt;
435 unsigned long flags;
436
437 list_for_each_entry(fmr, fmr_list, ibfmr.list) {
438 rkt = &to_idev(fmr->ibfmr.device)->lk_table;
439 spin_lock_irqsave(&rkt->lock, flags);
440 fmr->mr.user_base = 0;
441 fmr->mr.iova = 0;
442 fmr->mr.length = 0;
443 spin_unlock_irqrestore(&rkt->lock, flags);
444 }
445 return 0;
446}
447
448/**
449 * hfi1_dealloc_fmr - deallocate a fast memory region
450 * @ibfmr: the fast memory region to deallocate
451 *
452 * Returns 0 on success.
453 */
454int hfi1_dealloc_fmr(struct ib_fmr *ibfmr)
455{
456 struct hfi1_fmr *fmr = to_ifmr(ibfmr);
457 int ret = 0;
458 unsigned long timeout;
459
460 hfi1_free_lkey(&fmr->mr);
461 hfi1_put_mr(&fmr->mr); /* will set completion if last */
462 timeout = wait_for_completion_timeout(&fmr->mr.comp,
463 5 * HZ);
464 if (!timeout) {
465 hfi1_get_mr(&fmr->mr);
466 ret = -EBUSY;
467 goto out;
468 }
469 deinit_mregion(&fmr->mr);
470 kfree(fmr);
471out:
472 return ret;
473}
diff --git a/drivers/staging/rdma/hfi1/opa_compat.h b/drivers/staging/rdma/hfi1/opa_compat.h
index f64eec1c2951..6ef3c1cbdcd7 100644
--- a/drivers/staging/rdma/hfi1/opa_compat.h
+++ b/drivers/staging/rdma/hfi1/opa_compat.h
@@ -1,14 +1,13 @@
1#ifndef _LINUX_H 1#ifndef _LINUX_H
2#define _LINUX_H 2#define _LINUX_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -111,19 +108,4 @@ enum opa_port_phys_state {
111 /* values 12-15 are reserved/ignored */ 108 /* values 12-15 are reserved/ignored */
112}; 109};
113 110
114/* OPA_PORT_TYPE_* definitions - these belong in opa_port_info.h */
115#define OPA_PORT_TYPE_UNKNOWN 0
116#define OPA_PORT_TYPE_DISCONNECTED 1
117/* port is not currently usable, CableInfo not available */
118#define OPA_PORT_TYPE_FIXED 2
119/* A fixed backplane port in a director class switch. All OPA ASICS */
120#define OPA_PORT_TYPE_VARIABLE 3
121/* A backplane port in a blade system, possibly mixed configuration */
122#define OPA_PORT_TYPE_STANDARD 4
123/* implies a SFF-8636 defined format for CableInfo (QSFP) */
124#define OPA_PORT_TYPE_SI_PHOTONICS 5
125/* A silicon photonics module implies TBD defined format for CableInfo
126 * as defined by Intel SFO group */
127/* 6 - 15 are reserved */
128
129#endif /* _LINUX_H */ 111#endif /* _LINUX_H */
diff --git a/drivers/staging/rdma/hfi1/pcie.c b/drivers/staging/rdma/hfi1/pcie.c
index 47ca6314e328..0bac21e6a658 100644
--- a/drivers/staging/rdma/hfi1/pcie.c
+++ b/drivers/staging/rdma/hfi1/pcie.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -57,6 +54,7 @@
57 54
58#include "hfi.h" 55#include "hfi.h"
59#include "chip_registers.h" 56#include "chip_registers.h"
57#include "aspm.h"
60 58
61/* link speed vector for Gen3 speed - not in Linux headers */ 59/* link speed vector for Gen3 speed - not in Linux headers */
62#define GEN1_SPEED_VECTOR 0x1 60#define GEN1_SPEED_VECTOR 0x1
@@ -122,8 +120,9 @@ int hfi1_pcie_init(struct pci_dev *pdev, const struct pci_device_id *ent)
122 goto bail; 120 goto bail;
123 } 121 }
124 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 122 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
125 } else 123 } else {
126 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 124 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
125 }
127 if (ret) { 126 if (ret) {
128 hfi1_early_err(&pdev->dev, 127 hfi1_early_err(&pdev->dev,
129 "Unable to set DMA consistent mask: %d\n", ret); 128 "Unable to set DMA consistent mask: %d\n", ret);
@@ -131,13 +130,7 @@ int hfi1_pcie_init(struct pci_dev *pdev, const struct pci_device_id *ent)
131 } 130 }
132 131
133 pci_set_master(pdev); 132 pci_set_master(pdev);
134 ret = pci_enable_pcie_error_reporting(pdev); 133 (void)pci_enable_pcie_error_reporting(pdev);
135 if (ret) {
136 hfi1_early_err(&pdev->dev,
137 "Unable to enable pcie error reporting: %d\n",
138 ret);
139 ret = 0;
140 }
141 goto done; 134 goto done;
142 135
143bail: 136bail:
@@ -222,10 +215,9 @@ int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev,
222 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &dd->pcie_devctl); 215 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &dd->pcie_devctl);
223 pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL, &dd->pcie_lnkctl); 216 pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL, &dd->pcie_lnkctl);
224 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL2, 217 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL2,
225 &dd->pcie_devctl2); 218 &dd->pcie_devctl2);
226 pci_read_config_dword(dd->pcidev, PCI_CFG_MSIX0, &dd->pci_msix0); 219 pci_read_config_dword(dd->pcidev, PCI_CFG_MSIX0, &dd->pci_msix0);
227 pci_read_config_dword(dd->pcidev, PCIE_CFG_SPCIE1, 220 pci_read_config_dword(dd->pcidev, PCIE_CFG_SPCIE1, &dd->pci_lnkctl3);
228 &dd->pci_lnkctl3);
229 pci_read_config_dword(dd->pcidev, PCIE_CFG_TPH2, &dd->pci_tph2); 221 pci_read_config_dword(dd->pcidev, PCIE_CFG_TPH2, &dd->pci_tph2);
230 222
231 return 0; 223 return 0;
@@ -238,7 +230,7 @@ int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev,
238 */ 230 */
239void hfi1_pcie_ddcleanup(struct hfi1_devdata *dd) 231void hfi1_pcie_ddcleanup(struct hfi1_devdata *dd)
240{ 232{
241 u64 __iomem *base = (void __iomem *) dd->kregbase; 233 u64 __iomem *base = (void __iomem *)dd->kregbase;
242 234
243 dd->flags &= ~HFI1_PRESENT; 235 dd->flags &= ~HFI1_PRESENT;
244 dd->kregbase = NULL; 236 dd->kregbase = NULL;
@@ -274,7 +266,7 @@ void hfi1_pcie_flr(struct hfi1_devdata *dd)
274 266
275clear: 267clear:
276 pcie_capability_set_word(dd->pcidev, PCI_EXP_DEVCTL, 268 pcie_capability_set_word(dd->pcidev, PCI_EXP_DEVCTL,
277 PCI_EXP_DEVCTL_BCR_FLR); 269 PCI_EXP_DEVCTL_BCR_FLR);
278 /* PCIe spec requires the function to be back within 100ms */ 270 /* PCIe spec requires the function to be back within 100ms */
279 msleep(100); 271 msleep(100);
280} 272}
@@ -287,9 +279,11 @@ static void msix_setup(struct hfi1_devdata *dd, int pos, u32 *msixcnt,
287 struct msix_entry *msix_entry; 279 struct msix_entry *msix_entry;
288 int i; 280 int i;
289 281
290 /* We can't pass hfi1_msix_entry array to msix_setup 282 /*
283 * We can't pass hfi1_msix_entry array to msix_setup
291 * so use a dummy msix_entry array and copy the allocated 284 * so use a dummy msix_entry array and copy the allocated
292 * irq back to the hfi1_msix_entry array. */ 285 * irq back to the hfi1_msix_entry array.
286 */
293 msix_entry = kmalloc_array(nvec, sizeof(*msix_entry), GFP_KERNEL); 287 msix_entry = kmalloc_array(nvec, sizeof(*msix_entry), GFP_KERNEL);
294 if (!msix_entry) { 288 if (!msix_entry) {
295 ret = -ENOMEM; 289 ret = -ENOMEM;
@@ -319,7 +313,6 @@ do_intx:
319 nvec, ret); 313 nvec, ret);
320 *msixcnt = 0; 314 *msixcnt = 0;
321 hfi1_enable_intx(dd->pcidev); 315 hfi1_enable_intx(dd->pcidev);
322
323} 316}
324 317
325/* return the PCIe link speed from the given link status */ 318/* return the PCIe link speed from the given link status */
@@ -367,6 +360,7 @@ static void update_lbus_info(struct hfi1_devdata *dd)
367int pcie_speeds(struct hfi1_devdata *dd) 360int pcie_speeds(struct hfi1_devdata *dd)
368{ 361{
369 u32 linkcap; 362 u32 linkcap;
363 struct pci_dev *parent = dd->pcidev->bus->self;
370 364
371 if (!pci_is_pcie(dd->pcidev)) { 365 if (!pci_is_pcie(dd->pcidev)) {
372 dd_dev_err(dd, "Can't find PCI Express capability!\n"); 366 dd_dev_err(dd, "Can't find PCI Express capability!\n");
@@ -379,15 +373,15 @@ int pcie_speeds(struct hfi1_devdata *dd)
379 pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &linkcap); 373 pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &linkcap);
380 if ((linkcap & PCI_EXP_LNKCAP_SLS) != GEN3_SPEED_VECTOR) { 374 if ((linkcap & PCI_EXP_LNKCAP_SLS) != GEN3_SPEED_VECTOR) {
381 dd_dev_info(dd, 375 dd_dev_info(dd,
382 "This HFI is not Gen3 capable, max speed 0x%x, need 0x3\n", 376 "This HFI is not Gen3 capable, max speed 0x%x, need 0x3\n",
383 linkcap & PCI_EXP_LNKCAP_SLS); 377 linkcap & PCI_EXP_LNKCAP_SLS);
384 dd->link_gen3_capable = 0; 378 dd->link_gen3_capable = 0;
385 } 379 }
386 380
387 /* 381 /*
388 * bus->max_bus_speed is set from the bridge's linkcap Max Link Speed 382 * bus->max_bus_speed is set from the bridge's linkcap Max Link Speed
389 */ 383 */
390 if (dd->pcidev->bus->max_bus_speed != PCIE_SPEED_8_0GT) { 384 if (parent && dd->pcidev->bus->max_bus_speed != PCIE_SPEED_8_0GT) {
391 dd_dev_info(dd, "Parent PCIe bridge does not support Gen3\n"); 385 dd_dev_info(dd, "Parent PCIe bridge does not support Gen3\n");
392 dd->link_gen3_capable = 0; 386 dd->link_gen3_capable = 0;
393 } 387 }
@@ -395,9 +389,7 @@ int pcie_speeds(struct hfi1_devdata *dd)
395 /* obtain the link width and current speed */ 389 /* obtain the link width and current speed */
396 update_lbus_info(dd); 390 update_lbus_info(dd);
397 391
398 /* check against expected pcie width and complain if "wrong" */ 392 dd_dev_info(dd, "%s\n", dd->lbus_info);
399 if (dd->lbus_width < 16)
400 dd_dev_err(dd, "PCIe width %u (x16 HFI)\n", dd->lbus_width);
401 393
402 return 0; 394 return 0;
403} 395}
@@ -436,23 +428,18 @@ void hfi1_enable_intx(struct pci_dev *pdev)
436void restore_pci_variables(struct hfi1_devdata *dd) 428void restore_pci_variables(struct hfi1_devdata *dd)
437{ 429{
438 pci_write_config_word(dd->pcidev, PCI_COMMAND, dd->pci_command); 430 pci_write_config_word(dd->pcidev, PCI_COMMAND, dd->pci_command);
439 pci_write_config_dword(dd->pcidev, 431 pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0, dd->pcibar0);
440 PCI_BASE_ADDRESS_0, dd->pcibar0); 432 pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1, dd->pcibar1);
441 pci_write_config_dword(dd->pcidev, 433 pci_write_config_dword(dd->pcidev, PCI_ROM_ADDRESS, dd->pci_rom);
442 PCI_BASE_ADDRESS_1, dd->pcibar1);
443 pci_write_config_dword(dd->pcidev,
444 PCI_ROM_ADDRESS, dd->pci_rom);
445 pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, dd->pcie_devctl); 434 pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, dd->pcie_devctl);
446 pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL, dd->pcie_lnkctl); 435 pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL, dd->pcie_lnkctl);
447 pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL2, 436 pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL2,
448 dd->pcie_devctl2); 437 dd->pcie_devctl2);
449 pci_write_config_dword(dd->pcidev, PCI_CFG_MSIX0, dd->pci_msix0); 438 pci_write_config_dword(dd->pcidev, PCI_CFG_MSIX0, dd->pci_msix0);
450 pci_write_config_dword(dd->pcidev, PCIE_CFG_SPCIE1, 439 pci_write_config_dword(dd->pcidev, PCIE_CFG_SPCIE1, dd->pci_lnkctl3);
451 dd->pci_lnkctl3);
452 pci_write_config_dword(dd->pcidev, PCIE_CFG_TPH2, dd->pci_tph2); 440 pci_write_config_dword(dd->pcidev, PCIE_CFG_TPH2, dd->pci_tph2);
453} 441}
454 442
455
456/* 443/*
457 * BIOS may not set PCIe bus-utilization parameters for best performance. 444 * BIOS may not set PCIe bus-utilization parameters for best performance.
458 * Check and optionally adjust them to maximize our throughput. 445 * Check and optionally adjust them to maximize our throughput.
@@ -461,6 +448,10 @@ static int hfi1_pcie_caps;
461module_param_named(pcie_caps, hfi1_pcie_caps, int, S_IRUGO); 448module_param_named(pcie_caps, hfi1_pcie_caps, int, S_IRUGO);
462MODULE_PARM_DESC(pcie_caps, "Max PCIe tuning: Payload (0..3), ReadReq (4..7)"); 449MODULE_PARM_DESC(pcie_caps, "Max PCIe tuning: Payload (0..3), ReadReq (4..7)");
463 450
451uint aspm_mode = ASPM_MODE_DISABLED;
452module_param_named(aspm, aspm_mode, uint, S_IRUGO);
453MODULE_PARM_DESC(aspm, "PCIe ASPM: 0: disable, 1: enable, 2: dynamic");
454
464static void tune_pcie_caps(struct hfi1_devdata *dd) 455static void tune_pcie_caps(struct hfi1_devdata *dd)
465{ 456{
466 struct pci_dev *parent; 457 struct pci_dev *parent;
@@ -479,6 +470,12 @@ static void tune_pcie_caps(struct hfi1_devdata *dd)
479 } 470 }
480 /* Find out supported and configured values for parent (root) */ 471 /* Find out supported and configured values for parent (root) */
481 parent = dd->pcidev->bus->self; 472 parent = dd->pcidev->bus->self;
473 /*
474 * The driver cannot perform the tuning if it does not have
475 * access to the upstream component.
476 */
477 if (!parent)
478 return;
482 if (!pci_is_root_bus(parent->bus)) { 479 if (!pci_is_root_bus(parent->bus)) {
483 dd_dev_info(dd, "Parent not root\n"); 480 dd_dev_info(dd, "Parent not root\n");
484 return; 481 return;
@@ -532,6 +529,7 @@ static void tune_pcie_caps(struct hfi1_devdata *dd)
532 pcie_set_readrq(dd->pcidev, ep_mrrs); 529 pcie_set_readrq(dd->pcidev, ep_mrrs);
533 } 530 }
534} 531}
532
535/* End of PCIe capability tuning */ 533/* End of PCIe capability tuning */
536 534
537/* 535/*
@@ -746,21 +744,22 @@ static int load_eq_table(struct hfi1_devdata *dd, const u8 eq[11][3], u8 fs,
746 c0 = fs - (eq[i][PREC] / div) - (eq[i][POST] / div); 744 c0 = fs - (eq[i][PREC] / div) - (eq[i][POST] / div);
747 c_plus1 = eq[i][POST] / div; 745 c_plus1 = eq[i][POST] / div;
748 pci_write_config_dword(pdev, PCIE_CFG_REG_PL102, 746 pci_write_config_dword(pdev, PCIE_CFG_REG_PL102,
749 eq_value(c_minus1, c0, c_plus1)); 747 eq_value(c_minus1, c0, c_plus1));
750 /* check if these coefficients violate EQ rules */ 748 /* check if these coefficients violate EQ rules */
751 pci_read_config_dword(dd->pcidev, PCIE_CFG_REG_PL105, 749 pci_read_config_dword(dd->pcidev, PCIE_CFG_REG_PL105,
752 &violation); 750 &violation);
753 if (violation 751 if (violation
754 & PCIE_CFG_REG_PL105_GEN3_EQ_VIOLATE_COEF_RULES_SMASK){ 752 & PCIE_CFG_REG_PL105_GEN3_EQ_VIOLATE_COEF_RULES_SMASK){
755 if (hit_error == 0) { 753 if (hit_error == 0) {
756 dd_dev_err(dd, 754 dd_dev_err(dd,
757 "Gen3 EQ Table Coefficient rule violations\n"); 755 "Gen3 EQ Table Coefficient rule violations\n");
758 dd_dev_err(dd, " prec attn post\n"); 756 dd_dev_err(dd, " prec attn post\n");
759 } 757 }
760 dd_dev_err(dd, " p%02d: %02x %02x %02x\n", 758 dd_dev_err(dd, " p%02d: %02x %02x %02x\n",
761 i, (u32)eq[i][0], (u32)eq[i][1], (u32)eq[i][2]); 759 i, (u32)eq[i][0], (u32)eq[i][1],
760 (u32)eq[i][2]);
762 dd_dev_err(dd, " %02x %02x %02x\n", 761 dd_dev_err(dd, " %02x %02x %02x\n",
763 (u32)c_minus1, (u32)c0, (u32)c_plus1); 762 (u32)c_minus1, (u32)c0, (u32)c_plus1);
764 hit_error = 1; 763 hit_error = 1;
765 } 764 }
766 } 765 }
@@ -772,7 +771,7 @@ static int load_eq_table(struct hfi1_devdata *dd, const u8 eq[11][3], u8 fs,
772/* 771/*
773 * Steps to be done after the PCIe firmware is downloaded and 772 * Steps to be done after the PCIe firmware is downloaded and
774 * before the SBR for the Pcie Gen3. 773 * before the SBR for the Pcie Gen3.
775 * The hardware mutex is already being held. 774 * The SBus resource is already being held.
776 */ 775 */
777static void pcie_post_steps(struct hfi1_devdata *dd) 776static void pcie_post_steps(struct hfi1_devdata *dd)
778{ 777{
@@ -815,8 +814,8 @@ static int trigger_sbr(struct hfi1_devdata *dd)
815 list_for_each_entry(pdev, &dev->bus->devices, bus_list) 814 list_for_each_entry(pdev, &dev->bus->devices, bus_list)
816 if (pdev != dev) { 815 if (pdev != dev) {
817 dd_dev_err(dd, 816 dd_dev_err(dd,
818 "%s: another device is on the same bus\n", 817 "%s: another device is on the same bus\n",
819 __func__); 818 __func__);
820 return -ENOTTY; 819 return -ENOTTY;
821 } 820 }
822 821
@@ -840,8 +839,8 @@ static void write_gasket_interrupt(struct hfi1_devdata *dd, int index,
840 u16 code, u16 data) 839 u16 code, u16 data)
841{ 840{
842 write_csr(dd, ASIC_PCIE_SD_INTRPT_LIST + (index * 8), 841 write_csr(dd, ASIC_PCIE_SD_INTRPT_LIST + (index * 8),
843 (((u64)code << ASIC_PCIE_SD_INTRPT_LIST_INTRPT_CODE_SHIFT) 842 (((u64)code << ASIC_PCIE_SD_INTRPT_LIST_INTRPT_CODE_SHIFT) |
844 |((u64)data << ASIC_PCIE_SD_INTRPT_LIST_INTRPT_DATA_SHIFT))); 843 ((u64)data << ASIC_PCIE_SD_INTRPT_LIST_INTRPT_DATA_SHIFT)));
845} 844}
846 845
847/* 846/*
@@ -851,14 +850,13 @@ static void arm_gasket_logic(struct hfi1_devdata *dd)
851{ 850{
852 u64 reg; 851 u64 reg;
853 852
854 reg = (((u64)1 << dd->hfi1_id) 853 reg = (((u64)1 << dd->hfi1_id) <<
855 << ASIC_PCIE_SD_HOST_CMD_INTRPT_CMD_SHIFT) 854 ASIC_PCIE_SD_HOST_CMD_INTRPT_CMD_SHIFT) |
856 | ((u64)pcie_serdes_broadcast[dd->hfi1_id] 855 ((u64)pcie_serdes_broadcast[dd->hfi1_id] <<
857 << ASIC_PCIE_SD_HOST_CMD_SBUS_RCVR_ADDR_SHIFT 856 ASIC_PCIE_SD_HOST_CMD_SBUS_RCVR_ADDR_SHIFT |
858 | ASIC_PCIE_SD_HOST_CMD_SBR_MODE_SMASK 857 ASIC_PCIE_SD_HOST_CMD_SBR_MODE_SMASK |
859 | ((u64)SBR_DELAY_US & ASIC_PCIE_SD_HOST_CMD_TIMER_MASK) 858 ((u64)SBR_DELAY_US & ASIC_PCIE_SD_HOST_CMD_TIMER_MASK) <<
860 << ASIC_PCIE_SD_HOST_CMD_TIMER_SHIFT 859 ASIC_PCIE_SD_HOST_CMD_TIMER_SHIFT);
861 );
862 write_csr(dd, ASIC_PCIE_SD_HOST_CMD, reg); 860 write_csr(dd, ASIC_PCIE_SD_HOST_CMD, reg);
863 /* read back to push the write */ 861 /* read back to push the write */
864 read_csr(dd, ASIC_PCIE_SD_HOST_CMD); 862 read_csr(dd, ASIC_PCIE_SD_HOST_CMD);
@@ -946,7 +944,7 @@ static void write_xmt_margin(struct hfi1_devdata *dd, const char *fname)
946 */ 944 */
947int do_pcie_gen3_transition(struct hfi1_devdata *dd) 945int do_pcie_gen3_transition(struct hfi1_devdata *dd)
948{ 946{
949 struct pci_dev *parent; 947 struct pci_dev *parent = dd->pcidev->bus->self;
950 u64 fw_ctrl; 948 u64 fw_ctrl;
951 u64 reg, therm; 949 u64 reg, therm;
952 u32 reg32, fs, lf; 950 u32 reg32, fs, lf;
@@ -955,8 +953,7 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
955 int do_retry, retry_count = 0; 953 int do_retry, retry_count = 0;
956 uint default_pset; 954 uint default_pset;
957 u16 target_vector, target_speed; 955 u16 target_vector, target_speed;
958 u16 lnkctl, lnkctl2, vendor; 956 u16 lnkctl2, vendor;
959 u8 nsbr = 1;
960 u8 div; 957 u8 div;
961 const u8 (*eq)[3]; 958 const u8 (*eq)[3];
962 int return_error = 0; 959 int return_error = 0;
@@ -983,17 +980,21 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
983 /* if already at target speed, done (unless forced) */ 980 /* if already at target speed, done (unless forced) */
984 if (dd->lbus_speed == target_speed) { 981 if (dd->lbus_speed == target_speed) {
985 dd_dev_info(dd, "%s: PCIe already at gen%d, %s\n", __func__, 982 dd_dev_info(dd, "%s: PCIe already at gen%d, %s\n", __func__,
986 pcie_target, 983 pcie_target,
987 pcie_force ? "re-doing anyway" : "skipping"); 984 pcie_force ? "re-doing anyway" : "skipping");
988 if (!pcie_force) 985 if (!pcie_force)
989 return 0; 986 return 0;
990 } 987 }
991 988
992 /* 989 /*
993 * A0 needs an additional SBR 990 * The driver cannot do the transition if it has no access to the
991 * upstream component
994 */ 992 */
995 if (is_ax(dd)) 993 if (!parent) {
996 nsbr++; 994 dd_dev_info(dd, "%s: No upstream, Can't do gen3 transition\n",
995 __func__);
996 return 0;
997 }
997 998
998 /* 999 /*
999 * Do the Gen3 transition. Steps are those of the PCIe Gen3 1000 * Do the Gen3 transition. Steps are those of the PCIe Gen3
@@ -1009,10 +1010,13 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
1009 goto done_no_mutex; 1010 goto done_no_mutex;
1010 } 1011 }
1011 1012
1012 /* hold the HW mutex across the firmware download and SBR */ 1013 /* hold the SBus resource across the firmware download and SBR */
1013 ret = acquire_hw_mutex(dd); 1014 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1014 if (ret) 1015 if (ret) {
1016 dd_dev_err(dd, "%s: unable to acquire SBus resource\n",
1017 __func__);
1015 return ret; 1018 return ret;
1019 }
1016 1020
1017 /* make sure thermal polling is not causing interrupts */ 1021 /* make sure thermal polling is not causing interrupts */
1018 therm = read_csr(dd, ASIC_CFG_THERM_POLL_EN); 1022 therm = read_csr(dd, ASIC_CFG_THERM_POLL_EN);
@@ -1030,8 +1034,11 @@ retry:
1030 /* step 4: download PCIe Gen3 SerDes firmware */ 1034 /* step 4: download PCIe Gen3 SerDes firmware */
1031 dd_dev_info(dd, "%s: downloading firmware\n", __func__); 1035 dd_dev_info(dd, "%s: downloading firmware\n", __func__);
1032 ret = load_pcie_firmware(dd); 1036 ret = load_pcie_firmware(dd);
1033 if (ret) 1037 if (ret) {
1038 /* do not proceed if the firmware cannot be downloaded */
1039 return_error = 1;
1034 goto done; 1040 goto done;
1041 }
1035 1042
1036 /* step 5: set up device parameter settings */ 1043 /* step 5: set up device parameter settings */
1037 dd_dev_info(dd, "%s: setting PCIe registers\n", __func__); 1044 dd_dev_info(dd, "%s: setting PCIe registers\n", __func__);
@@ -1091,8 +1098,10 @@ retry:
1091 default_pset = DEFAULT_MCP_PSET; 1098 default_pset = DEFAULT_MCP_PSET;
1092 } 1099 }
1093 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL101, 1100 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL101,
1094 (fs << PCIE_CFG_REG_PL101_GEN3_EQ_LOCAL_FS_SHIFT) 1101 (fs <<
1095 | (lf << PCIE_CFG_REG_PL101_GEN3_EQ_LOCAL_LF_SHIFT)); 1102 PCIE_CFG_REG_PL101_GEN3_EQ_LOCAL_FS_SHIFT) |
1103 (lf <<
1104 PCIE_CFG_REG_PL101_GEN3_EQ_LOCAL_LF_SHIFT));
1096 ret = load_eq_table(dd, eq, fs, div); 1105 ret = load_eq_table(dd, eq, fs, div);
1097 if (ret) 1106 if (ret)
1098 goto done; 1107 goto done;
@@ -1106,15 +1115,15 @@ retry:
1106 pcie_pset = default_pset; 1115 pcie_pset = default_pset;
1107 if (pcie_pset > 10) { /* valid range is 0-10, inclusive */ 1116 if (pcie_pset > 10) { /* valid range is 0-10, inclusive */
1108 dd_dev_err(dd, "%s: Invalid Eq Pset %u, setting to %d\n", 1117 dd_dev_err(dd, "%s: Invalid Eq Pset %u, setting to %d\n",
1109 __func__, pcie_pset, default_pset); 1118 __func__, pcie_pset, default_pset);
1110 pcie_pset = default_pset; 1119 pcie_pset = default_pset;
1111 } 1120 }
1112 dd_dev_info(dd, "%s: using EQ Pset %u\n", __func__, pcie_pset); 1121 dd_dev_info(dd, "%s: using EQ Pset %u\n", __func__, pcie_pset);
1113 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL106, 1122 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL106,
1114 ((1 << pcie_pset) 1123 ((1 << pcie_pset) <<
1115 << PCIE_CFG_REG_PL106_GEN3_EQ_PSET_REQ_VEC_SHIFT) 1124 PCIE_CFG_REG_PL106_GEN3_EQ_PSET_REQ_VEC_SHIFT) |
1116 | PCIE_CFG_REG_PL106_GEN3_EQ_EVAL2MS_DISABLE_SMASK 1125 PCIE_CFG_REG_PL106_GEN3_EQ_EVAL2MS_DISABLE_SMASK |
1117 | PCIE_CFG_REG_PL106_GEN3_EQ_PHASE23_EXIT_MODE_SMASK); 1126 PCIE_CFG_REG_PL106_GEN3_EQ_PHASE23_EXIT_MODE_SMASK);
1118 1127
1119 /* 1128 /*
1120 * step 5b: Do post firmware download steps via SBus 1129 * step 5b: Do post firmware download steps via SBus
@@ -1142,11 +1151,12 @@ retry:
1142 */ 1151 */
1143 write_xmt_margin(dd, __func__); 1152 write_xmt_margin(dd, __func__);
1144 1153
1145 /* step 5e: disable active state power management (ASPM) */ 1154 /*
1155 * step 5e: disable active state power management (ASPM). It
1156 * will be enabled if required later
1157 */
1146 dd_dev_info(dd, "%s: clearing ASPM\n", __func__); 1158 dd_dev_info(dd, "%s: clearing ASPM\n", __func__);
1147 pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL, &lnkctl); 1159 aspm_hw_disable_l1(dd);
1148 lnkctl &= ~PCI_EXP_LNKCTL_ASPMC;
1149 pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL, lnkctl);
1150 1160
1151 /* 1161 /*
1152 * step 5f: clear DirectSpeedChange 1162 * step 5f: clear DirectSpeedChange
@@ -1165,16 +1175,15 @@ retry:
1165 * that it is Gen3 capable earlier. 1175 * that it is Gen3 capable earlier.
1166 */ 1176 */
1167 dd_dev_info(dd, "%s: setting parent target link speed\n", __func__); 1177 dd_dev_info(dd, "%s: setting parent target link speed\n", __func__);
1168 parent = dd->pcidev->bus->self;
1169 pcie_capability_read_word(parent, PCI_EXP_LNKCTL2, &lnkctl2); 1178 pcie_capability_read_word(parent, PCI_EXP_LNKCTL2, &lnkctl2);
1170 dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__, 1179 dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__,
1171 (u32)lnkctl2); 1180 (u32)lnkctl2);
1172 /* only write to parent if target is not as high as ours */ 1181 /* only write to parent if target is not as high as ours */
1173 if ((lnkctl2 & LNKCTL2_TARGET_LINK_SPEED_MASK) < target_vector) { 1182 if ((lnkctl2 & LNKCTL2_TARGET_LINK_SPEED_MASK) < target_vector) {
1174 lnkctl2 &= ~LNKCTL2_TARGET_LINK_SPEED_MASK; 1183 lnkctl2 &= ~LNKCTL2_TARGET_LINK_SPEED_MASK;
1175 lnkctl2 |= target_vector; 1184 lnkctl2 |= target_vector;
1176 dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__, 1185 dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
1177 (u32)lnkctl2); 1186 (u32)lnkctl2);
1178 pcie_capability_write_word(parent, PCI_EXP_LNKCTL2, lnkctl2); 1187 pcie_capability_write_word(parent, PCI_EXP_LNKCTL2, lnkctl2);
1179 } else { 1188 } else {
1180 dd_dev_info(dd, "%s: ..target speed is OK\n", __func__); 1189 dd_dev_info(dd, "%s: ..target speed is OK\n", __func__);
@@ -1183,17 +1192,17 @@ retry:
1183 dd_dev_info(dd, "%s: setting target link speed\n", __func__); 1192 dd_dev_info(dd, "%s: setting target link speed\n", __func__);
1184 pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL2, &lnkctl2); 1193 pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL2, &lnkctl2);
1185 dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__, 1194 dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__,
1186 (u32)lnkctl2); 1195 (u32)lnkctl2);
1187 lnkctl2 &= ~LNKCTL2_TARGET_LINK_SPEED_MASK; 1196 lnkctl2 &= ~LNKCTL2_TARGET_LINK_SPEED_MASK;
1188 lnkctl2 |= target_vector; 1197 lnkctl2 |= target_vector;
1189 dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__, 1198 dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
1190 (u32)lnkctl2); 1199 (u32)lnkctl2);
1191 pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL2, lnkctl2); 1200 pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL2, lnkctl2);
1192 1201
1193 /* step 5h: arm gasket logic */ 1202 /* step 5h: arm gasket logic */
1194 /* hold DC in reset across the SBR */ 1203 /* hold DC in reset across the SBR */
1195 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK); 1204 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
1196 (void) read_csr(dd, CCE_DC_CTRL); /* DC reset hold */ 1205 (void)read_csr(dd, CCE_DC_CTRL); /* DC reset hold */
1197 /* save firmware control across the SBR */ 1206 /* save firmware control across the SBR */
1198 fw_ctrl = read_csr(dd, MISC_CFG_FW_CTRL); 1207 fw_ctrl = read_csr(dd, MISC_CFG_FW_CTRL);
1199 1208
@@ -1224,8 +1233,8 @@ retry:
1224 ret = pci_read_config_word(dd->pcidev, PCI_VENDOR_ID, &vendor); 1233 ret = pci_read_config_word(dd->pcidev, PCI_VENDOR_ID, &vendor);
1225 if (ret) { 1234 if (ret) {
1226 dd_dev_info(dd, 1235 dd_dev_info(dd,
1227 "%s: read of VendorID failed after SBR, err %d\n", 1236 "%s: read of VendorID failed after SBR, err %d\n",
1228 __func__, ret); 1237 __func__, ret);
1229 return_error = 1; 1238 return_error = 1;
1230 goto done; 1239 goto done;
1231 } 1240 }
@@ -1265,8 +1274,7 @@ retry:
1265 write_csr(dd, CCE_DC_CTRL, 0); 1274 write_csr(dd, CCE_DC_CTRL, 0);
1266 1275
1267 /* Set the LED off */ 1276 /* Set the LED off */
1268 if (is_ax(dd)) 1277 setextled(dd, 0);
1269 setextled(dd, 0);
1270 1278
1271 /* check for any per-lane errors */ 1279 /* check for any per-lane errors */
1272 pci_read_config_dword(dd->pcidev, PCIE_CFG_SPCIE2, &reg32); 1280 pci_read_config_dword(dd->pcidev, PCIE_CFG_SPCIE2, &reg32);
@@ -1277,8 +1285,8 @@ retry:
1277 & ASIC_PCIE_SD_HOST_STATUS_FW_DNLD_STS_MASK; 1285 & ASIC_PCIE_SD_HOST_STATUS_FW_DNLD_STS_MASK;
1278 if ((status & (1 << dd->hfi1_id)) == 0) { 1286 if ((status & (1 << dd->hfi1_id)) == 0) {
1279 dd_dev_err(dd, 1287 dd_dev_err(dd,
1280 "%s: gasket status 0x%x, expecting 0x%x\n", 1288 "%s: gasket status 0x%x, expecting 0x%x\n",
1281 __func__, status, 1 << dd->hfi1_id); 1289 __func__, status, 1 << dd->hfi1_id);
1282 ret = -EIO; 1290 ret = -EIO;
1283 goto done; 1291 goto done;
1284 } 1292 }
@@ -1295,13 +1303,13 @@ retry:
1295 /* update our link information cache */ 1303 /* update our link information cache */
1296 update_lbus_info(dd); 1304 update_lbus_info(dd);
1297 dd_dev_info(dd, "%s: new speed and width: %s\n", __func__, 1305 dd_dev_info(dd, "%s: new speed and width: %s\n", __func__,
1298 dd->lbus_info); 1306 dd->lbus_info);
1299 1307
1300 if (dd->lbus_speed != target_speed) { /* not target */ 1308 if (dd->lbus_speed != target_speed) { /* not target */
1301 /* maybe retry */ 1309 /* maybe retry */
1302 do_retry = retry_count < pcie_retry; 1310 do_retry = retry_count < pcie_retry;
1303 dd_dev_err(dd, "PCIe link speed did not switch to Gen%d%s\n", 1311 dd_dev_err(dd, "PCIe link speed did not switch to Gen%d%s\n",
1304 pcie_target, do_retry ? ", retrying" : ""); 1312 pcie_target, do_retry ? ", retrying" : "");
1305 retry_count++; 1313 retry_count++;
1306 if (do_retry) { 1314 if (do_retry) {
1307 msleep(100); /* allow time to settle */ 1315 msleep(100); /* allow time to settle */
@@ -1317,7 +1325,7 @@ done:
1317 dd_dev_info(dd, "%s: Re-enable therm polling\n", 1325 dd_dev_info(dd, "%s: Re-enable therm polling\n",
1318 __func__); 1326 __func__);
1319 } 1327 }
1320 release_hw_mutex(dd); 1328 release_chip_resource(dd, CR_SBUS);
1321done_no_mutex: 1329done_no_mutex:
1322 /* return no error if it is OK to be at current speed */ 1330 /* return no error if it is OK to be at current speed */
1323 if (ret && !return_error) { 1331 if (ret && !return_error) {
diff --git a/drivers/staging/rdma/hfi1/pio.c b/drivers/staging/rdma/hfi1/pio.c
index b51a4416312b..c6849ce9e5eb 100644
--- a/drivers/staging/rdma/hfi1/pio.c
+++ b/drivers/staging/rdma/hfi1/pio.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -101,7 +98,7 @@ void pio_send_control(struct hfi1_devdata *dd, int op)
101 /* Fall through */ 98 /* Fall through */
102 case PSC_DATA_VL_ENABLE: 99 case PSC_DATA_VL_ENABLE:
103 /* Disallow sending on VLs not enabled */ 100 /* Disallow sending on VLs not enabled */
104 mask = (((~0ull)<<num_vls) & SEND_CTRL_UNSUPPORTED_VL_MASK)<< 101 mask = (((~0ull) << num_vls) & SEND_CTRL_UNSUPPORTED_VL_MASK) <<
105 SEND_CTRL_UNSUPPORTED_VL_SHIFT; 102 SEND_CTRL_UNSUPPORTED_VL_SHIFT;
106 reg = (reg & ~SEND_CTRL_UNSUPPORTED_VL_SMASK) | mask; 103 reg = (reg & ~SEND_CTRL_UNSUPPORTED_VL_SMASK) | mask;
107 break; 104 break;
@@ -130,7 +127,7 @@ void pio_send_control(struct hfi1_devdata *dd, int op)
130 if (write) { 127 if (write) {
131 write_csr(dd, SEND_CTRL, reg); 128 write_csr(dd, SEND_CTRL, reg);
132 if (flush) 129 if (flush)
133 (void) read_csr(dd, SEND_CTRL); /* flush write */ 130 (void)read_csr(dd, SEND_CTRL); /* flush write */
134 } 131 }
135 132
136 spin_unlock_irqrestore(&dd->sendctrl_lock, flags); 133 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
@@ -177,8 +174,10 @@ static struct mem_pool_config sc_mem_pool_config[NUM_SC_POOLS] = {
177 174
178/* memory pool information, used when calculating final sizes */ 175/* memory pool information, used when calculating final sizes */
179struct mem_pool_info { 176struct mem_pool_info {
180 int centipercent; /* 100th of 1% of memory to use, -1 if blocks 177 int centipercent; /*
181 already set */ 178 * 100th of 1% of memory to use, -1 if blocks
179 * already set
180 */
182 int count; /* count of contexts in the pool */ 181 int count; /* count of contexts in the pool */
183 int blocks; /* block size of the pool */ 182 int blocks; /* block size of the pool */
184 int size; /* context size, in blocks */ 183 int size; /* context size, in blocks */
@@ -312,7 +311,7 @@ int init_sc_pools_and_sizes(struct hfi1_devdata *dd)
312 if (i == SC_ACK) { 311 if (i == SC_ACK) {
313 count = dd->n_krcv_queues; 312 count = dd->n_krcv_queues;
314 } else if (i == SC_KERNEL) { 313 } else if (i == SC_KERNEL) {
315 count = num_vls + 1 /* VL15 */; 314 count = (INIT_SC_PER_VL * num_vls) + 1 /* VL15 */;
316 } else if (count == SCC_PER_CPU) { 315 } else if (count == SCC_PER_CPU) {
317 count = dd->num_rcv_contexts - dd->n_krcv_queues; 316 count = dd->num_rcv_contexts - dd->n_krcv_queues;
318 } else if (count < 0) { 317 } else if (count < 0) {
@@ -509,7 +508,7 @@ static void sc_hw_free(struct hfi1_devdata *dd, u32 sw_index, u32 hw_context)
509 sci = &dd->send_contexts[sw_index]; 508 sci = &dd->send_contexts[sw_index];
510 if (!sci->allocated) { 509 if (!sci->allocated) {
511 dd_dev_err(dd, "%s: sw_index %u not allocated? hw_context %u\n", 510 dd_dev_err(dd, "%s: sw_index %u not allocated? hw_context %u\n",
512 __func__, sw_index, hw_context); 511 __func__, sw_index, hw_context);
513 } 512 }
514 sci->allocated = 0; 513 sci->allocated = 0;
515 dd->hw_to_sw[hw_context] = INVALID_SCI; 514 dd->hw_to_sw[hw_context] = INVALID_SCI;
@@ -625,7 +624,7 @@ void sc_set_cr_threshold(struct send_context *sc, u32 new_threshold)
625 & SC(CREDIT_CTRL_THRESHOLD_MASK)) 624 & SC(CREDIT_CTRL_THRESHOLD_MASK))
626 << SC(CREDIT_CTRL_THRESHOLD_SHIFT)); 625 << SC(CREDIT_CTRL_THRESHOLD_SHIFT));
627 write_kctxt_csr(sc->dd, sc->hw_context, 626 write_kctxt_csr(sc->dd, sc->hw_context,
628 SC(CREDIT_CTRL), sc->credit_ctrl); 627 SC(CREDIT_CTRL), sc->credit_ctrl);
629 628
630 /* force a credit return on change to avoid a possible stall */ 629 /* force a credit return on change to avoid a possible stall */
631 force_return = 1; 630 force_return = 1;
@@ -700,7 +699,7 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
700 if (dd->flags & HFI1_FROZEN) 699 if (dd->flags & HFI1_FROZEN)
701 return NULL; 700 return NULL;
702 701
703 sc = kzalloc_node(sizeof(struct send_context), GFP_KERNEL, numa); 702 sc = kzalloc_node(sizeof(*sc), GFP_KERNEL, numa);
704 if (!sc) 703 if (!sc)
705 return NULL; 704 return NULL;
706 705
@@ -763,9 +762,9 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
763 762
764 /* set the default partition key */ 763 /* set the default partition key */
765 write_kctxt_csr(dd, hw_context, SC(CHECK_PARTITION_KEY), 764 write_kctxt_csr(dd, hw_context, SC(CHECK_PARTITION_KEY),
766 (DEFAULT_PKEY & 765 (SC(CHECK_PARTITION_KEY_VALUE_MASK) &
767 SC(CHECK_PARTITION_KEY_VALUE_MASK)) 766 DEFAULT_PKEY) <<
768 << SC(CHECK_PARTITION_KEY_VALUE_SHIFT)); 767 SC(CHECK_PARTITION_KEY_VALUE_SHIFT));
769 768
770 /* per context type checks */ 769 /* per context type checks */
771 if (type == SC_USER) { 770 if (type == SC_USER) {
@@ -778,8 +777,8 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
778 777
779 /* set the send context check opcode mask and value */ 778 /* set the send context check opcode mask and value */
780 write_kctxt_csr(dd, hw_context, SC(CHECK_OPCODE), 779 write_kctxt_csr(dd, hw_context, SC(CHECK_OPCODE),
781 ((u64)opmask << SC(CHECK_OPCODE_MASK_SHIFT)) | 780 ((u64)opmask << SC(CHECK_OPCODE_MASK_SHIFT)) |
782 ((u64)opval << SC(CHECK_OPCODE_VALUE_SHIFT))); 781 ((u64)opval << SC(CHECK_OPCODE_VALUE_SHIFT)));
783 782
784 /* set up credit return */ 783 /* set up credit return */
785 reg = pa & SC(CREDIT_RETURN_ADDR_ADDRESS_SMASK); 784 reg = pa & SC(CREDIT_RETURN_ADDR_ADDRESS_SMASK);
@@ -797,7 +796,7 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
797 thresh = sc_percent_to_threshold(sc, 50); 796 thresh = sc_percent_to_threshold(sc, 50);
798 } else if (type == SC_USER) { 797 } else if (type == SC_USER) {
799 thresh = sc_percent_to_threshold(sc, 798 thresh = sc_percent_to_threshold(sc,
800 user_credit_return_threshold); 799 user_credit_return_threshold);
801 } else { /* kernel */ 800 } else { /* kernel */
802 thresh = sc_mtu_to_threshold(sc, hfi1_max_mtu, hdrqentsize); 801 thresh = sc_mtu_to_threshold(sc, hfi1_max_mtu, hdrqentsize);
803 } 802 }
@@ -852,7 +851,6 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
852 sc->credit_ctrl, 851 sc->credit_ctrl,
853 thresh); 852 thresh);
854 853
855
856 return sc; 854 return sc;
857} 855}
858 856
@@ -971,11 +969,11 @@ static void sc_wait_for_packet_egress(struct send_context *sc, int pause)
971 if (loop > 500) { 969 if (loop > 500) {
972 /* timed out - bounce the link */ 970 /* timed out - bounce the link */
973 dd_dev_err(dd, 971 dd_dev_err(dd,
974 "%s: context %u(%u) timeout waiting for packets to egress, remaining count %u, bouncing link\n", 972 "%s: context %u(%u) timeout waiting for packets to egress, remaining count %u, bouncing link\n",
975 __func__, sc->sw_index, 973 __func__, sc->sw_index,
976 sc->hw_context, (u32)reg); 974 sc->hw_context, (u32)reg);
977 queue_work(dd->pport->hfi1_wq, 975 queue_work(dd->pport->hfi1_wq,
978 &dd->pport->link_bounce_work); 976 &dd->pport->link_bounce_work);
979 break; 977 break;
980 } 978 }
981 loop++; 979 loop++;
@@ -1021,7 +1019,7 @@ int sc_restart(struct send_context *sc)
1021 return -EINVAL; 1019 return -EINVAL;
1022 1020
1023 dd_dev_info(dd, "restarting send context %u(%u)\n", sc->sw_index, 1021 dd_dev_info(dd, "restarting send context %u(%u)\n", sc->sw_index,
1024 sc->hw_context); 1022 sc->hw_context);
1025 1023
1026 /* 1024 /*
1027 * Step 1: Wait for the context to actually halt. 1025 * Step 1: Wait for the context to actually halt.
@@ -1036,7 +1034,7 @@ int sc_restart(struct send_context *sc)
1036 break; 1034 break;
1037 if (loop > 100) { 1035 if (loop > 100) {
1038 dd_dev_err(dd, "%s: context %u(%u) not halting, skipping\n", 1036 dd_dev_err(dd, "%s: context %u(%u) not halting, skipping\n",
1039 __func__, sc->sw_index, sc->hw_context); 1037 __func__, sc->sw_index, sc->hw_context);
1040 return -ETIME; 1038 return -ETIME;
1041 } 1039 }
1042 loop++; 1040 loop++;
@@ -1062,9 +1060,9 @@ int sc_restart(struct send_context *sc)
1062 break; 1060 break;
1063 if (loop > 100) { 1061 if (loop > 100) {
1064 dd_dev_err(dd, 1062 dd_dev_err(dd,
1065 "%s: context %u(%u) timeout waiting for PIO buffers to zero, remaining %d\n", 1063 "%s: context %u(%u) timeout waiting for PIO buffers to zero, remaining %d\n",
1066 __func__, sc->sw_index, 1064 __func__, sc->sw_index,
1067 sc->hw_context, count); 1065 sc->hw_context, count);
1068 } 1066 }
1069 loop++; 1067 loop++;
1070 udelay(1); 1068 udelay(1);
@@ -1177,18 +1175,18 @@ void pio_reset_all(struct hfi1_devdata *dd)
1177 if (ret == -EIO) { 1175 if (ret == -EIO) {
1178 /* clear the error */ 1176 /* clear the error */
1179 write_csr(dd, SEND_PIO_ERR_CLEAR, 1177 write_csr(dd, SEND_PIO_ERR_CLEAR,
1180 SEND_PIO_ERR_CLEAR_PIO_INIT_SM_IN_ERR_SMASK); 1178 SEND_PIO_ERR_CLEAR_PIO_INIT_SM_IN_ERR_SMASK);
1181 } 1179 }
1182 1180
1183 /* reset init all */ 1181 /* reset init all */
1184 write_csr(dd, SEND_PIO_INIT_CTXT, 1182 write_csr(dd, SEND_PIO_INIT_CTXT,
1185 SEND_PIO_INIT_CTXT_PIO_ALL_CTXT_INIT_SMASK); 1183 SEND_PIO_INIT_CTXT_PIO_ALL_CTXT_INIT_SMASK);
1186 udelay(2); 1184 udelay(2);
1187 ret = pio_init_wait_progress(dd); 1185 ret = pio_init_wait_progress(dd);
1188 if (ret < 0) { 1186 if (ret < 0) {
1189 dd_dev_err(dd, 1187 dd_dev_err(dd,
1190 "PIO send context init %s while initializing all PIO blocks\n", 1188 "PIO send context init %s while initializing all PIO blocks\n",
1191 ret == -ETIMEDOUT ? "is stuck" : "had an error"); 1189 ret == -ETIMEDOUT ? "is stuck" : "had an error");
1192 } 1190 }
1193} 1191}
1194 1192
@@ -1236,8 +1234,7 @@ int sc_enable(struct send_context *sc)
1236 */ 1234 */
1237 reg = read_kctxt_csr(dd, sc->hw_context, SC(ERR_STATUS)); 1235 reg = read_kctxt_csr(dd, sc->hw_context, SC(ERR_STATUS));
1238 if (reg) 1236 if (reg)
1239 write_kctxt_csr(dd, sc->hw_context, SC(ERR_CLEAR), 1237 write_kctxt_csr(dd, sc->hw_context, SC(ERR_CLEAR), reg);
1240 reg);
1241 1238
1242 /* 1239 /*
1243 * The HW PIO initialization engine can handle only one init 1240 * The HW PIO initialization engine can handle only one init
@@ -1295,7 +1292,7 @@ void sc_return_credits(struct send_context *sc)
1295 1292
1296 /* a 0->1 transition schedules a credit return */ 1293 /* a 0->1 transition schedules a credit return */
1297 write_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE), 1294 write_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE),
1298 SC(CREDIT_FORCE_FORCE_RETURN_SMASK)); 1295 SC(CREDIT_FORCE_FORCE_RETURN_SMASK));
1299 /* 1296 /*
1300 * Ensure that the write is flushed and the credit return is 1297 * Ensure that the write is flushed and the credit return is
1301 * scheduled. We care more about the 0 -> 1 transition. 1298 * scheduled. We care more about the 0 -> 1 transition.
@@ -1321,7 +1318,7 @@ void sc_drop(struct send_context *sc)
1321 return; 1318 return;
1322 1319
1323 dd_dev_info(sc->dd, "%s: context %u(%u) - not implemented\n", 1320 dd_dev_info(sc->dd, "%s: context %u(%u) - not implemented\n",
1324 __func__, sc->sw_index, sc->hw_context); 1321 __func__, sc->sw_index, sc->hw_context);
1325} 1322}
1326 1323
1327/* 1324/*
@@ -1346,7 +1343,7 @@ void sc_stop(struct send_context *sc, int flag)
1346 wake_up(&sc->halt_wait); 1343 wake_up(&sc->halt_wait);
1347} 1344}
1348 1345
1349#define BLOCK_DWORDS (PIO_BLOCK_SIZE/sizeof(u32)) 1346#define BLOCK_DWORDS (PIO_BLOCK_SIZE / sizeof(u32))
1350#define dwords_to_blocks(x) DIV_ROUND_UP(x, BLOCK_DWORDS) 1347#define dwords_to_blocks(x) DIV_ROUND_UP(x, BLOCK_DWORDS)
1351 1348
1352/* 1349/*
@@ -1430,8 +1427,10 @@ retry:
1430 next = head + 1; 1427 next = head + 1;
1431 if (next >= sc->sr_size) 1428 if (next >= sc->sr_size)
1432 next = 0; 1429 next = 0;
1433 /* update the head - must be last! - the releaser can look at fields 1430 /*
1434 in pbuf once we move the head */ 1431 * update the head - must be last! - the releaser can look at fields
1432 * in pbuf once we move the head
1433 */
1435 smp_wmb(); 1434 smp_wmb();
1436 sc->sr_head = next; 1435 sc->sr_head = next;
1437 spin_unlock_irqrestore(&sc->alloc_lock, flags); 1436 spin_unlock_irqrestore(&sc->alloc_lock, flags);
@@ -1469,7 +1468,7 @@ void sc_add_credit_return_intr(struct send_context *sc)
1469 if (sc->credit_intr_count == 0) { 1468 if (sc->credit_intr_count == 0) {
1470 sc->credit_ctrl |= SC(CREDIT_CTRL_CREDIT_INTR_SMASK); 1469 sc->credit_ctrl |= SC(CREDIT_CTRL_CREDIT_INTR_SMASK);
1471 write_kctxt_csr(sc->dd, sc->hw_context, 1470 write_kctxt_csr(sc->dd, sc->hw_context,
1472 SC(CREDIT_CTRL), sc->credit_ctrl); 1471 SC(CREDIT_CTRL), sc->credit_ctrl);
1473 } 1472 }
1474 sc->credit_intr_count++; 1473 sc->credit_intr_count++;
1475 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); 1474 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags);
@@ -1491,7 +1490,7 @@ void sc_del_credit_return_intr(struct send_context *sc)
1491 if (sc->credit_intr_count == 0) { 1490 if (sc->credit_intr_count == 0) {
1492 sc->credit_ctrl &= ~SC(CREDIT_CTRL_CREDIT_INTR_SMASK); 1491 sc->credit_ctrl &= ~SC(CREDIT_CTRL_CREDIT_INTR_SMASK);
1493 write_kctxt_csr(sc->dd, sc->hw_context, 1492 write_kctxt_csr(sc->dd, sc->hw_context,
1494 SC(CREDIT_CTRL), sc->credit_ctrl); 1493 SC(CREDIT_CTRL), sc->credit_ctrl);
1495 } 1494 }
1496 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); 1495 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags);
1497} 1496}
@@ -1526,8 +1525,9 @@ static void sc_piobufavail(struct send_context *sc)
1526 struct hfi1_devdata *dd = sc->dd; 1525 struct hfi1_devdata *dd = sc->dd;
1527 struct hfi1_ibdev *dev = &dd->verbs_dev; 1526 struct hfi1_ibdev *dev = &dd->verbs_dev;
1528 struct list_head *list; 1527 struct list_head *list;
1529 struct hfi1_qp *qps[PIO_WAIT_BATCH_SIZE]; 1528 struct rvt_qp *qps[PIO_WAIT_BATCH_SIZE];
1530 struct hfi1_qp *qp; 1529 struct rvt_qp *qp;
1530 struct hfi1_qp_priv *priv;
1531 unsigned long flags; 1531 unsigned long flags;
1532 unsigned i, n = 0; 1532 unsigned i, n = 0;
1533 1533
@@ -1545,24 +1545,28 @@ static void sc_piobufavail(struct send_context *sc)
1545 struct iowait *wait; 1545 struct iowait *wait;
1546 1546
1547 if (n == ARRAY_SIZE(qps)) 1547 if (n == ARRAY_SIZE(qps))
1548 goto full; 1548 break;
1549 wait = list_first_entry(list, struct iowait, list); 1549 wait = list_first_entry(list, struct iowait, list);
1550 qp = container_of(wait, struct hfi1_qp, s_iowait); 1550 qp = iowait_to_qp(wait);
1551 list_del_init(&qp->s_iowait.list); 1551 priv = qp->priv;
1552 list_del_init(&priv->s_iowait.list);
1552 /* refcount held until actual wake up */ 1553 /* refcount held until actual wake up */
1553 qps[n++] = qp; 1554 qps[n++] = qp;
1554 } 1555 }
1555 /* 1556 /*
1556 * Counting: only call wantpiobuf_intr() if there were waiters and they 1557 * If there had been waiters and there are more
1557 * are now all gone. 1558 * insure that we redo the force to avoid a potential hang.
1558 */ 1559 */
1559 if (n) 1560 if (n) {
1560 hfi1_sc_wantpiobuf_intr(sc, 0); 1561 hfi1_sc_wantpiobuf_intr(sc, 0);
1561full: 1562 if (!list_empty(list))
1563 hfi1_sc_wantpiobuf_intr(sc, 1);
1564 }
1562 write_sequnlock_irqrestore(&dev->iowait_lock, flags); 1565 write_sequnlock_irqrestore(&dev->iowait_lock, flags);
1563 1566
1564 for (i = 0; i < n; i++) 1567 for (i = 0; i < n; i++)
1565 hfi1_qp_wakeup(qps[i], HFI1_S_WAIT_PIO); 1568 hfi1_qp_wakeup(qps[i],
1569 RVT_S_WAIT_PIO | RVT_S_WAIT_PIO_DRAIN);
1566} 1570}
1567 1571
1568/* translate a send credit update to a bit code of reasons */ 1572/* translate a send credit update to a bit code of reasons */
@@ -1661,7 +1665,7 @@ void sc_group_release_update(struct hfi1_devdata *dd, u32 hw_context)
1661 sw_index = dd->hw_to_sw[hw_context]; 1665 sw_index = dd->hw_to_sw[hw_context];
1662 if (unlikely(sw_index >= dd->num_send_contexts)) { 1666 if (unlikely(sw_index >= dd->num_send_contexts)) {
1663 dd_dev_err(dd, "%s: invalid hw (%u) to sw (%u) mapping\n", 1667 dd_dev_err(dd, "%s: invalid hw (%u) to sw (%u) mapping\n",
1664 __func__, hw_context, sw_index); 1668 __func__, hw_context, sw_index);
1665 goto done; 1669 goto done;
1666 } 1670 }
1667 sc = dd->send_contexts[sw_index].sc; 1671 sc = dd->send_contexts[sw_index].sc;
@@ -1674,8 +1678,8 @@ void sc_group_release_update(struct hfi1_devdata *dd, u32 hw_context)
1674 sw_index = dd->hw_to_sw[gc]; 1678 sw_index = dd->hw_to_sw[gc];
1675 if (unlikely(sw_index >= dd->num_send_contexts)) { 1679 if (unlikely(sw_index >= dd->num_send_contexts)) {
1676 dd_dev_err(dd, 1680 dd_dev_err(dd,
1677 "%s: invalid hw (%u) to sw (%u) mapping\n", 1681 "%s: invalid hw (%u) to sw (%u) mapping\n",
1678 __func__, hw_context, sw_index); 1682 __func__, hw_context, sw_index);
1679 continue; 1683 continue;
1680 } 1684 }
1681 sc_release_update(dd->send_contexts[sw_index].sc); 1685 sc_release_update(dd->send_contexts[sw_index].sc);
@@ -1684,11 +1688,217 @@ done:
1684 spin_unlock(&dd->sc_lock); 1688 spin_unlock(&dd->sc_lock);
1685} 1689}
1686 1690
1691/*
1692 * pio_select_send_context_vl() - select send context
1693 * @dd: devdata
1694 * @selector: a spreading factor
1695 * @vl: this vl
1696 *
1697 * This function returns a send context based on the selector and a vl.
1698 * The mapping fields are protected by RCU
1699 */
1700struct send_context *pio_select_send_context_vl(struct hfi1_devdata *dd,
1701 u32 selector, u8 vl)
1702{
1703 struct pio_vl_map *m;
1704 struct pio_map_elem *e;
1705 struct send_context *rval;
1706
1707 /*
1708 * NOTE This should only happen if SC->VL changed after the initial
1709 * checks on the QP/AH
1710 * Default will return VL0's send context below
1711 */
1712 if (unlikely(vl >= num_vls)) {
1713 rval = NULL;
1714 goto done;
1715 }
1716
1717 rcu_read_lock();
1718 m = rcu_dereference(dd->pio_map);
1719 if (unlikely(!m)) {
1720 rcu_read_unlock();
1721 return dd->vld[0].sc;
1722 }
1723 e = m->map[vl & m->mask];
1724 rval = e->ksc[selector & e->mask];
1725 rcu_read_unlock();
1726
1727done:
1728 rval = !rval ? dd->vld[0].sc : rval;
1729 return rval;
1730}
1731
1732/*
1733 * pio_select_send_context_sc() - select send context
1734 * @dd: devdata
1735 * @selector: a spreading factor
1736 * @sc5: the 5 bit sc
1737 *
1738 * This function returns an send context based on the selector and an sc
1739 */
1740struct send_context *pio_select_send_context_sc(struct hfi1_devdata *dd,
1741 u32 selector, u8 sc5)
1742{
1743 u8 vl = sc_to_vlt(dd, sc5);
1744
1745 return pio_select_send_context_vl(dd, selector, vl);
1746}
1747
1748/*
1749 * Free the indicated map struct
1750 */
1751static void pio_map_free(struct pio_vl_map *m)
1752{
1753 int i;
1754
1755 for (i = 0; m && i < m->actual_vls; i++)
1756 kfree(m->map[i]);
1757 kfree(m);
1758}
1759
1760/*
1761 * Handle RCU callback
1762 */
1763static void pio_map_rcu_callback(struct rcu_head *list)
1764{
1765 struct pio_vl_map *m = container_of(list, struct pio_vl_map, list);
1766
1767 pio_map_free(m);
1768}
1769
1770/*
1771 * pio_map_init - called when #vls change
1772 * @dd: hfi1_devdata
1773 * @port: port number
1774 * @num_vls: number of vls
1775 * @vl_scontexts: per vl send context mapping (optional)
1776 *
1777 * This routine changes the mapping based on the number of vls.
1778 *
1779 * vl_scontexts is used to specify a non-uniform vl/send context
1780 * loading. NULL implies auto computing the loading and giving each
1781 * VL an uniform distribution of send contexts per VL.
1782 *
1783 * The auto algorithm computers the sc_per_vl and the number of extra
1784 * send contexts. Any extra send contexts are added from the last VL
1785 * on down
1786 *
1787 * rcu locking is used here to control access to the mapping fields.
1788 *
1789 * If either the num_vls or num_send_contexts are non-power of 2, the
1790 * array sizes in the struct pio_vl_map and the struct pio_map_elem are
1791 * rounded up to the next highest power of 2 and the first entry is
1792 * reused in a round robin fashion.
1793 *
1794 * If an error occurs the map change is not done and the mapping is not
1795 * chaged.
1796 *
1797 */
1798int pio_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls, u8 *vl_scontexts)
1799{
1800 int i, j;
1801 int extra, sc_per_vl;
1802 int scontext = 1;
1803 int num_kernel_send_contexts = 0;
1804 u8 lvl_scontexts[OPA_MAX_VLS];
1805 struct pio_vl_map *oldmap, *newmap;
1806
1807 if (!vl_scontexts) {
1808 /* send context 0 reserved for VL15 */
1809 for (i = 1; i < dd->num_send_contexts; i++)
1810 if (dd->send_contexts[i].type == SC_KERNEL)
1811 num_kernel_send_contexts++;
1812 /* truncate divide */
1813 sc_per_vl = num_kernel_send_contexts / num_vls;
1814 /* extras */
1815 extra = num_kernel_send_contexts % num_vls;
1816 vl_scontexts = lvl_scontexts;
1817 /* add extras from last vl down */
1818 for (i = num_vls - 1; i >= 0; i--, extra--)
1819 vl_scontexts[i] = sc_per_vl + (extra > 0 ? 1 : 0);
1820 }
1821 /* build new map */
1822 newmap = kzalloc(sizeof(*newmap) +
1823 roundup_pow_of_two(num_vls) *
1824 sizeof(struct pio_map_elem *),
1825 GFP_KERNEL);
1826 if (!newmap)
1827 goto bail;
1828 newmap->actual_vls = num_vls;
1829 newmap->vls = roundup_pow_of_two(num_vls);
1830 newmap->mask = (1 << ilog2(newmap->vls)) - 1;
1831 for (i = 0; i < newmap->vls; i++) {
1832 /* save for wrap around */
1833 int first_scontext = scontext;
1834
1835 if (i < newmap->actual_vls) {
1836 int sz = roundup_pow_of_two(vl_scontexts[i]);
1837
1838 /* only allocate once */
1839 newmap->map[i] = kzalloc(sizeof(*newmap->map[i]) +
1840 sz * sizeof(struct
1841 send_context *),
1842 GFP_KERNEL);
1843 if (!newmap->map[i])
1844 goto bail;
1845 newmap->map[i]->mask = (1 << ilog2(sz)) - 1;
1846 /* assign send contexts */
1847 for (j = 0; j < sz; j++) {
1848 if (dd->kernel_send_context[scontext])
1849 newmap->map[i]->ksc[j] =
1850 dd->kernel_send_context[scontext];
1851 if (++scontext >= first_scontext +
1852 vl_scontexts[i])
1853 /* wrap back to first send context */
1854 scontext = first_scontext;
1855 }
1856 } else {
1857 /* just re-use entry without allocating */
1858 newmap->map[i] = newmap->map[i % num_vls];
1859 }
1860 scontext = first_scontext + vl_scontexts[i];
1861 }
1862 /* newmap in hand, save old map */
1863 spin_lock_irq(&dd->pio_map_lock);
1864 oldmap = rcu_dereference_protected(dd->pio_map,
1865 lockdep_is_held(&dd->pio_map_lock));
1866
1867 /* publish newmap */
1868 rcu_assign_pointer(dd->pio_map, newmap);
1869
1870 spin_unlock_irq(&dd->pio_map_lock);
1871 /* success, free any old map after grace period */
1872 if (oldmap)
1873 call_rcu(&oldmap->list, pio_map_rcu_callback);
1874 return 0;
1875bail:
1876 /* free any partial allocation */
1877 pio_map_free(newmap);
1878 return -ENOMEM;
1879}
1880
1881void free_pio_map(struct hfi1_devdata *dd)
1882{
1883 /* Free PIO map if allocated */
1884 if (rcu_access_pointer(dd->pio_map)) {
1885 spin_lock_irq(&dd->pio_map_lock);
1886 pio_map_free(rcu_access_pointer(dd->pio_map));
1887 RCU_INIT_POINTER(dd->pio_map, NULL);
1888 spin_unlock_irq(&dd->pio_map_lock);
1889 synchronize_rcu();
1890 }
1891 kfree(dd->kernel_send_context);
1892 dd->kernel_send_context = NULL;
1893}
1894
1687int init_pervl_scs(struct hfi1_devdata *dd) 1895int init_pervl_scs(struct hfi1_devdata *dd)
1688{ 1896{
1689 int i; 1897 int i;
1690 u64 mask, all_vl_mask = (u64) 0x80ff; /* VLs 0-7, 15 */ 1898 u64 mask, all_vl_mask = (u64)0x80ff; /* VLs 0-7, 15 */
1899 u64 data_vls_mask = (u64)0x00ff; /* VLs 0-7 */
1691 u32 ctxt; 1900 u32 ctxt;
1901 struct hfi1_pportdata *ppd = dd->pport;
1692 1902
1693 dd->vld[15].sc = sc_alloc(dd, SC_KERNEL, 1903 dd->vld[15].sc = sc_alloc(dd, SC_KERNEL,
1694 dd->rcd[0]->rcvhdrqentsize, dd->node); 1904 dd->rcd[0]->rcvhdrqentsize, dd->node);
@@ -1696,6 +1906,12 @@ int init_pervl_scs(struct hfi1_devdata *dd)
1696 goto nomem; 1906 goto nomem;
1697 hfi1_init_ctxt(dd->vld[15].sc); 1907 hfi1_init_ctxt(dd->vld[15].sc);
1698 dd->vld[15].mtu = enum_to_mtu(OPA_MTU_2048); 1908 dd->vld[15].mtu = enum_to_mtu(OPA_MTU_2048);
1909
1910 dd->kernel_send_context = kmalloc_node(dd->num_send_contexts *
1911 sizeof(struct send_context *),
1912 GFP_KERNEL, dd->node);
1913 dd->kernel_send_context[0] = dd->vld[15].sc;
1914
1699 for (i = 0; i < num_vls; i++) { 1915 for (i = 0; i < num_vls; i++) {
1700 /* 1916 /*
1701 * Since this function does not deal with a specific 1917 * Since this function does not deal with a specific
@@ -1708,12 +1924,19 @@ int init_pervl_scs(struct hfi1_devdata *dd)
1708 dd->rcd[0]->rcvhdrqentsize, dd->node); 1924 dd->rcd[0]->rcvhdrqentsize, dd->node);
1709 if (!dd->vld[i].sc) 1925 if (!dd->vld[i].sc)
1710 goto nomem; 1926 goto nomem;
1711 1927 dd->kernel_send_context[i + 1] = dd->vld[i].sc;
1712 hfi1_init_ctxt(dd->vld[i].sc); 1928 hfi1_init_ctxt(dd->vld[i].sc);
1713
1714 /* non VL15 start with the max MTU */ 1929 /* non VL15 start with the max MTU */
1715 dd->vld[i].mtu = hfi1_max_mtu; 1930 dd->vld[i].mtu = hfi1_max_mtu;
1716 } 1931 }
1932 for (i = num_vls; i < INIT_SC_PER_VL * num_vls; i++) {
1933 dd->kernel_send_context[i + 1] =
1934 sc_alloc(dd, SC_KERNEL, dd->rcd[0]->rcvhdrqentsize, dd->node);
1935 if (!dd->kernel_send_context[i + 1])
1936 goto nomem;
1937 hfi1_init_ctxt(dd->kernel_send_context[i + 1]);
1938 }
1939
1717 sc_enable(dd->vld[15].sc); 1940 sc_enable(dd->vld[15].sc);
1718 ctxt = dd->vld[15].sc->hw_context; 1941 ctxt = dd->vld[15].sc->hw_context;
1719 mask = all_vl_mask & ~(1LL << 15); 1942 mask = all_vl_mask & ~(1LL << 15);
@@ -1721,17 +1944,29 @@ int init_pervl_scs(struct hfi1_devdata *dd)
1721 dd_dev_info(dd, 1944 dd_dev_info(dd,
1722 "Using send context %u(%u) for VL15\n", 1945 "Using send context %u(%u) for VL15\n",
1723 dd->vld[15].sc->sw_index, ctxt); 1946 dd->vld[15].sc->sw_index, ctxt);
1947
1724 for (i = 0; i < num_vls; i++) { 1948 for (i = 0; i < num_vls; i++) {
1725 sc_enable(dd->vld[i].sc); 1949 sc_enable(dd->vld[i].sc);
1726 ctxt = dd->vld[i].sc->hw_context; 1950 ctxt = dd->vld[i].sc->hw_context;
1727 mask = all_vl_mask & ~(1LL << i); 1951 mask = all_vl_mask & ~(data_vls_mask);
1728 write_kctxt_csr(dd, ctxt, SC(CHECK_VL), mask); 1952 write_kctxt_csr(dd, ctxt, SC(CHECK_VL), mask);
1729 } 1953 }
1954 for (i = num_vls; i < INIT_SC_PER_VL * num_vls; i++) {
1955 sc_enable(dd->kernel_send_context[i + 1]);
1956 ctxt = dd->kernel_send_context[i + 1]->hw_context;
1957 mask = all_vl_mask & ~(data_vls_mask);
1958 write_kctxt_csr(dd, ctxt, SC(CHECK_VL), mask);
1959 }
1960
1961 if (pio_map_init(dd, ppd->port - 1, num_vls, NULL))
1962 goto nomem;
1730 return 0; 1963 return 0;
1731nomem: 1964nomem:
1732 sc_free(dd->vld[15].sc); 1965 sc_free(dd->vld[15].sc);
1733 for (i = 0; i < num_vls; i++) 1966 for (i = 0; i < num_vls; i++)
1734 sc_free(dd->vld[i].sc); 1967 sc_free(dd->vld[i].sc);
1968 for (i = num_vls; i < INIT_SC_PER_VL * num_vls; i++)
1969 sc_free(dd->kernel_send_context[i + 1]);
1735 return -ENOMEM; 1970 return -ENOMEM;
1736} 1971}
1737 1972
@@ -1769,11 +2004,11 @@ int init_credit_return(struct hfi1_devdata *dd)
1769 bytes, 2004 bytes,
1770 &dd->cr_base[i].pa, 2005 &dd->cr_base[i].pa,
1771 GFP_KERNEL); 2006 GFP_KERNEL);
1772 if (dd->cr_base[i].va == NULL) { 2007 if (!dd->cr_base[i].va) {
1773 set_dev_node(&dd->pcidev->dev, dd->node); 2008 set_dev_node(&dd->pcidev->dev, dd->node);
1774 dd_dev_err(dd, 2009 dd_dev_err(dd,
1775 "Unable to allocate credit return DMA range for NUMA %d\n", 2010 "Unable to allocate credit return DMA range for NUMA %d\n",
1776 i); 2011 i);
1777 ret = -ENOMEM; 2012 ret = -ENOMEM;
1778 goto done; 2013 goto done;
1779 } 2014 }
@@ -1797,10 +2032,10 @@ void free_credit_return(struct hfi1_devdata *dd)
1797 for (i = 0; i < num_numa; i++) { 2032 for (i = 0; i < num_numa; i++) {
1798 if (dd->cr_base[i].va) { 2033 if (dd->cr_base[i].va) {
1799 dma_free_coherent(&dd->pcidev->dev, 2034 dma_free_coherent(&dd->pcidev->dev,
1800 TXE_NUM_CONTEXTS 2035 TXE_NUM_CONTEXTS *
1801 * sizeof(struct credit_return), 2036 sizeof(struct credit_return),
1802 dd->cr_base[i].va, 2037 dd->cr_base[i].va,
1803 dd->cr_base[i].pa); 2038 dd->cr_base[i].pa);
1804 } 2039 }
1805 } 2040 }
1806 kfree(dd->cr_base); 2041 kfree(dd->cr_base);
diff --git a/drivers/staging/rdma/hfi1/pio.h b/drivers/staging/rdma/hfi1/pio.h
index 53d3e0a79375..0026976ce4f6 100644
--- a/drivers/staging/rdma/hfi1/pio.h
+++ b/drivers/staging/rdma/hfi1/pio.h
@@ -1,14 +1,13 @@
1#ifndef _PIO_H 1#ifndef _PIO_H
2#define _PIO_H 2#define _PIO_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -50,7 +47,6 @@
50 * 47 *
51 */ 48 */
52 49
53
54/* send context types */ 50/* send context types */
55#define SC_KERNEL 0 51#define SC_KERNEL 0
56#define SC_ACK 1 52#define SC_ACK 1
@@ -106,6 +102,7 @@ struct send_context {
106 struct hfi1_devdata *dd; /* device */ 102 struct hfi1_devdata *dd; /* device */
107 void __iomem *base_addr; /* start of PIO memory */ 103 void __iomem *base_addr; /* start of PIO memory */
108 union pio_shadow_ring *sr; /* shadow ring */ 104 union pio_shadow_ring *sr; /* shadow ring */
105
109 volatile __le64 *hw_free; /* HW free counter */ 106 volatile __le64 *hw_free; /* HW free counter */
110 struct work_struct halt_work; /* halted context work queue entry */ 107 struct work_struct halt_work; /* halted context work queue entry */
111 unsigned long flags; /* flags */ 108 unsigned long flags; /* flags */
@@ -165,6 +162,112 @@ struct sc_config_sizes {
165 short int count; 162 short int count;
166}; 163};
167 164
165/*
166 * The diagram below details the relationship of the mapping structures
167 *
168 * Since the mapping now allows for non-uniform send contexts per vl, the
169 * number of send contexts for a vl is either the vl_scontexts[vl] or
170 * a computation based on num_kernel_send_contexts/num_vls:
171 *
172 * For example:
173 * nactual = vl_scontexts ? vl_scontexts[vl] : num_kernel_send_contexts/num_vls
174 *
175 * n = roundup to next highest power of 2 using nactual
176 *
177 * In the case where there are num_kernel_send_contexts/num_vls doesn't divide
178 * evenly, the extras are added from the last vl downward.
179 *
180 * For the case where n > nactual, the send contexts are assigned
181 * in a round robin fashion wrapping back to the first send context
182 * for a particular vl.
183 *
184 * dd->pio_map
185 * | pio_map_elem[0]
186 * | +--------------------+
187 * v | mask |
188 * pio_vl_map |--------------------|
189 * +--------------------------+ | ksc[0] -> sc 1 |
190 * | list (RCU) | |--------------------|
191 * |--------------------------| ->| ksc[1] -> sc 2 |
192 * | mask | --/ |--------------------|
193 * |--------------------------| -/ | * |
194 * | actual_vls (max 8) | -/ |--------------------|
195 * |--------------------------| --/ | ksc[n] -> sc n |
196 * | vls (max 8) | -/ +--------------------+
197 * |--------------------------| --/
198 * | map[0] |-/
199 * |--------------------------| +--------------------+
200 * | map[1] |--- | mask |
201 * |--------------------------| \---- |--------------------|
202 * | * | \-- | ksc[0] -> sc 1+n |
203 * | * | \---- |--------------------|
204 * | * | \->| ksc[1] -> sc 2+n |
205 * |--------------------------| |--------------------|
206 * | map[vls - 1] |- | * |
207 * +--------------------------+ \- |--------------------|
208 * \- | ksc[m] -> sc m+n |
209 * \ +--------------------+
210 * \-
211 * \
212 * \- +--------------------+
213 * \- | mask |
214 * \ |--------------------|
215 * \- | ksc[0] -> sc 1+m+n |
216 * \- |--------------------|
217 * >| ksc[1] -> sc 2+m+n |
218 * |--------------------|
219 * | * |
220 * |--------------------|
221 * | ksc[o] -> sc o+m+n |
222 * +--------------------+
223 *
224 */
225
226/* Initial number of send contexts per VL */
227#define INIT_SC_PER_VL 2
228
229/*
230 * struct pio_map_elem - mapping for a vl
231 * @mask - selector mask
232 * @ksc - array of kernel send contexts for this vl
233 *
234 * The mask is used to "mod" the selector to
235 * produce index into the trailing array of
236 * kscs
237 */
238struct pio_map_elem {
239 u32 mask;
240 struct send_context *ksc[0];
241};
242
243/*
244 * struct pio_vl_map - mapping for a vl
245 * @list - rcu head for free callback
246 * @mask - vl mask to "mod" the vl to produce an index to map array
247 * @actual_vls - number of vls
248 * @vls - numbers of vls rounded to next power of 2
249 * @map - array of pio_map_elem entries
250 *
251 * This is the parent mapping structure. The trailing members of the
252 * struct point to pio_map_elem entries, which in turn point to an
253 * array of kscs for that vl.
254 */
255struct pio_vl_map {
256 struct rcu_head list;
257 u32 mask;
258 u8 actual_vls;
259 u8 vls;
260 struct pio_map_elem *map[0];
261};
262
263int pio_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls,
264 u8 *vl_scontexts);
265void free_pio_map(struct hfi1_devdata *dd);
266struct send_context *pio_select_send_context_vl(struct hfi1_devdata *dd,
267 u32 selector, u8 vl);
268struct send_context *pio_select_send_context_sc(struct hfi1_devdata *dd,
269 u32 selector, u8 sc5);
270
168/* send context functions */ 271/* send context functions */
169int init_credit_return(struct hfi1_devdata *dd); 272int init_credit_return(struct hfi1_devdata *dd);
170void free_credit_return(struct hfi1_devdata *dd); 273void free_credit_return(struct hfi1_devdata *dd);
@@ -183,7 +286,7 @@ void sc_flush(struct send_context *sc);
183void sc_drop(struct send_context *sc); 286void sc_drop(struct send_context *sc);
184void sc_stop(struct send_context *sc, int bit); 287void sc_stop(struct send_context *sc, int bit);
185struct pio_buf *sc_buffer_alloc(struct send_context *sc, u32 dw_len, 288struct pio_buf *sc_buffer_alloc(struct send_context *sc, u32 dw_len,
186 pio_release_cb cb, void *arg); 289 pio_release_cb cb, void *arg);
187void sc_release_update(struct send_context *sc); 290void sc_release_update(struct send_context *sc);
188void sc_return_credits(struct send_context *sc); 291void sc_return_credits(struct send_context *sc);
189void sc_group_release_update(struct hfi1_devdata *dd, u32 hw_context); 292void sc_group_release_update(struct hfi1_devdata *dd, u32 hw_context);
@@ -212,12 +315,11 @@ void pio_kernel_unfreeze(struct hfi1_devdata *dd);
212void __cm_reset(struct hfi1_devdata *dd, u64 sendctrl); 315void __cm_reset(struct hfi1_devdata *dd, u64 sendctrl);
213void pio_send_control(struct hfi1_devdata *dd, int op); 316void pio_send_control(struct hfi1_devdata *dd, int op);
214 317
215
216/* PIO copy routines */ 318/* PIO copy routines */
217void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc, 319void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc,
218 const void *from, size_t count); 320 const void *from, size_t count);
219void seg_pio_copy_start(struct pio_buf *pbuf, u64 pbc, 321void seg_pio_copy_start(struct pio_buf *pbuf, u64 pbc,
220 const void *from, size_t nbytes); 322 const void *from, size_t nbytes);
221void seg_pio_copy_mid(struct pio_buf *pbuf, const void *from, size_t nbytes); 323void seg_pio_copy_mid(struct pio_buf *pbuf, const void *from, size_t nbytes);
222void seg_pio_copy_end(struct pio_buf *pbuf); 324void seg_pio_copy_end(struct pio_buf *pbuf);
223 325
diff --git a/drivers/staging/rdma/hfi1/pio_copy.c b/drivers/staging/rdma/hfi1/pio_copy.c
index 64bef6c26653..8c25e1b58849 100644
--- a/drivers/staging/rdma/hfi1/pio_copy.c
+++ b/drivers/staging/rdma/hfi1/pio_copy.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -52,9 +49,9 @@
52 49
53/* additive distance between non-SOP and SOP space */ 50/* additive distance between non-SOP and SOP space */
54#define SOP_DISTANCE (TXE_PIO_SIZE / 2) 51#define SOP_DISTANCE (TXE_PIO_SIZE / 2)
55#define PIO_BLOCK_MASK (PIO_BLOCK_SIZE-1) 52#define PIO_BLOCK_MASK (PIO_BLOCK_SIZE - 1)
56/* number of QUADWORDs in a block */ 53/* number of QUADWORDs in a block */
57#define PIO_BLOCK_QWS (PIO_BLOCK_SIZE/sizeof(u64)) 54#define PIO_BLOCK_QWS (PIO_BLOCK_SIZE / sizeof(u64))
58 55
59/** 56/**
60 * pio_copy - copy data block to MMIO space 57 * pio_copy - copy data block to MMIO space
@@ -83,11 +80,13 @@ void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc,
83 dest += sizeof(u64); 80 dest += sizeof(u64);
84 81
85 /* calculate where the QWORD data ends - in SOP=1 space */ 82 /* calculate where the QWORD data ends - in SOP=1 space */
86 dend = dest + ((count>>1) * sizeof(u64)); 83 dend = dest + ((count >> 1) * sizeof(u64));
87 84
88 if (dend < send) { 85 if (dend < send) {
89 /* all QWORD data is within the SOP block, does *not* 86 /*
90 reach the end of the SOP block */ 87 * all QWORD data is within the SOP block, does *not*
88 * reach the end of the SOP block
89 */
91 90
92 while (dest < dend) { 91 while (dest < dend) {
93 writeq(*(u64 *)from, dest); 92 writeq(*(u64 *)from, dest);
@@ -152,8 +151,10 @@ void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc,
152 writeq(val.val64, dest); 151 writeq(val.val64, dest);
153 dest += sizeof(u64); 152 dest += sizeof(u64);
154 } 153 }
155 /* fill in rest of block, no need to check pbuf->end 154 /*
156 as we only wrap on a block boundary */ 155 * fill in rest of block, no need to check pbuf->end
156 * as we only wrap on a block boundary
157 */
157 while (((unsigned long)dest & PIO_BLOCK_MASK) != 0) { 158 while (((unsigned long)dest & PIO_BLOCK_MASK) != 0) {
158 writeq(0, dest); 159 writeq(0, dest);
159 dest += sizeof(u64); 160 dest += sizeof(u64);
@@ -177,7 +178,7 @@ void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc,
177 * "zero" shift - bit shift used to zero out upper bytes. Input is 178 * "zero" shift - bit shift used to zero out upper bytes. Input is
178 * the count of LSB bytes to preserve. 179 * the count of LSB bytes to preserve.
179 */ 180 */
180#define zshift(x) (8 * (8-(x))) 181#define zshift(x) (8 * (8 - (x)))
181 182
182/* 183/*
183 * "merge" shift - bit shift used to merge with carry bytes. Input is 184 * "merge" shift - bit shift used to merge with carry bytes. Input is
@@ -196,7 +197,7 @@ void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc,
196 * o nbytes must not span a QW boundary 197 * o nbytes must not span a QW boundary
197 */ 198 */
198static inline void read_low_bytes(struct pio_buf *pbuf, const void *from, 199static inline void read_low_bytes(struct pio_buf *pbuf, const void *from,
199 unsigned int nbytes) 200 unsigned int nbytes)
200{ 201{
201 unsigned long off; 202 unsigned long off;
202 203
@@ -223,7 +224,7 @@ static inline void read_low_bytes(struct pio_buf *pbuf, const void *from,
223 * o nbytes may span a QW boundary 224 * o nbytes may span a QW boundary
224 */ 225 */
225static inline void read_extra_bytes(struct pio_buf *pbuf, 226static inline void read_extra_bytes(struct pio_buf *pbuf,
226 const void *from, unsigned int nbytes) 227 const void *from, unsigned int nbytes)
227{ 228{
228 unsigned long off = (unsigned long)from & 0x7; 229 unsigned long off = (unsigned long)from & 0x7;
229 unsigned int room, xbytes; 230 unsigned int room, xbytes;
@@ -244,7 +245,7 @@ static inline void read_extra_bytes(struct pio_buf *pbuf,
244 pbuf->carry.val64 |= (((*(u64 *)from) 245 pbuf->carry.val64 |= (((*(u64 *)from)
245 >> mshift(off)) 246 >> mshift(off))
246 << zshift(xbytes)) 247 << zshift(xbytes))
247 >> zshift(xbytes+pbuf->carry_bytes); 248 >> zshift(xbytes + pbuf->carry_bytes);
248 off = 0; 249 off = 0;
249 pbuf->carry_bytes += xbytes; 250 pbuf->carry_bytes += xbytes;
250 nbytes -= xbytes; 251 nbytes -= xbytes;
@@ -362,7 +363,7 @@ static inline void jcopy(u8 *dest, const u8 *src, u32 n)
362 * o from may _not_ be u64 aligned. 363 * o from may _not_ be u64 aligned.
363 */ 364 */
364static inline void read_low_bytes(struct pio_buf *pbuf, const void *from, 365static inline void read_low_bytes(struct pio_buf *pbuf, const void *from,
365 unsigned int nbytes) 366 unsigned int nbytes)
366{ 367{
367 jcopy(&pbuf->carry.val8[0], from, nbytes); 368 jcopy(&pbuf->carry.val8[0], from, nbytes);
368 pbuf->carry_bytes = nbytes; 369 pbuf->carry_bytes = nbytes;
@@ -377,7 +378,7 @@ static inline void read_low_bytes(struct pio_buf *pbuf, const void *from,
377 * o nbytes may span a QW boundary 378 * o nbytes may span a QW boundary
378 */ 379 */
379static inline void read_extra_bytes(struct pio_buf *pbuf, 380static inline void read_extra_bytes(struct pio_buf *pbuf,
380 const void *from, unsigned int nbytes) 381 const void *from, unsigned int nbytes)
381{ 382{
382 jcopy(&pbuf->carry.val8[pbuf->carry_bytes], from, nbytes); 383 jcopy(&pbuf->carry.val8[pbuf->carry_bytes], from, nbytes);
383 pbuf->carry_bytes += nbytes; 384 pbuf->carry_bytes += nbytes;
@@ -411,7 +412,7 @@ static inline void merge_write8(
411 412
412 jcopy(&pbuf->carry.val8[pbuf->carry_bytes], src, remainder); 413 jcopy(&pbuf->carry.val8[pbuf->carry_bytes], src, remainder);
413 writeq(pbuf->carry.val64, dest); 414 writeq(pbuf->carry.val64, dest);
414 jcopy(&pbuf->carry.val8[0], src+remainder, pbuf->carry_bytes); 415 jcopy(&pbuf->carry.val8[0], src + remainder, pbuf->carry_bytes);
415} 416}
416 417
417/* 418/*
@@ -433,7 +434,7 @@ static inline int carry_write8(struct pio_buf *pbuf, void *dest)
433 u64 zero = 0; 434 u64 zero = 0;
434 435
435 jcopy(&pbuf->carry.val8[pbuf->carry_bytes], (u8 *)&zero, 436 jcopy(&pbuf->carry.val8[pbuf->carry_bytes], (u8 *)&zero,
436 8 - pbuf->carry_bytes); 437 8 - pbuf->carry_bytes);
437 writeq(pbuf->carry.val64, dest); 438 writeq(pbuf->carry.val64, dest);
438 return 1; 439 return 1;
439 } 440 }
@@ -453,7 +454,7 @@ static inline int carry_write8(struct pio_buf *pbuf, void *dest)
453 * @nbytes: bytes to copy 454 * @nbytes: bytes to copy
454 */ 455 */
455void seg_pio_copy_start(struct pio_buf *pbuf, u64 pbc, 456void seg_pio_copy_start(struct pio_buf *pbuf, u64 pbc,
456 const void *from, size_t nbytes) 457 const void *from, size_t nbytes)
457{ 458{
458 void __iomem *dest = pbuf->start + SOP_DISTANCE; 459 void __iomem *dest = pbuf->start + SOP_DISTANCE;
459 void __iomem *send = dest + PIO_BLOCK_SIZE; 460 void __iomem *send = dest + PIO_BLOCK_SIZE;
@@ -463,11 +464,13 @@ void seg_pio_copy_start(struct pio_buf *pbuf, u64 pbc,
463 dest += sizeof(u64); 464 dest += sizeof(u64);
464 465
465 /* calculate where the QWORD data ends - in SOP=1 space */ 466 /* calculate where the QWORD data ends - in SOP=1 space */
466 dend = dest + ((nbytes>>3) * sizeof(u64)); 467 dend = dest + ((nbytes >> 3) * sizeof(u64));
467 468
468 if (dend < send) { 469 if (dend < send) {
469 /* all QWORD data is within the SOP block, does *not* 470 /*
470 reach the end of the SOP block */ 471 * all QWORD data is within the SOP block, does *not*
472 * reach the end of the SOP block
473 */
471 474
472 while (dest < dend) { 475 while (dest < dend) {
473 writeq(*(u64 *)from, dest); 476 writeq(*(u64 *)from, dest);
@@ -562,8 +565,10 @@ static void mid_copy_mix(struct pio_buf *pbuf, const void *from, size_t nbytes)
562 void __iomem *send; /* SOP end */ 565 void __iomem *send; /* SOP end */
563 void __iomem *xend; 566 void __iomem *xend;
564 567
565 /* calculate the end of data or end of block, whichever 568 /*
566 comes first */ 569 * calculate the end of data or end of block, whichever
570 * comes first
571 */
567 send = pbuf->start + PIO_BLOCK_SIZE; 572 send = pbuf->start + PIO_BLOCK_SIZE;
568 xend = min(send, dend); 573 xend = min(send, dend);
569 574
@@ -639,13 +644,13 @@ static void mid_copy_mix(struct pio_buf *pbuf, const void *from, size_t nbytes)
639 * Must handle nbytes < 8. 644 * Must handle nbytes < 8.
640 */ 645 */
641static void mid_copy_straight(struct pio_buf *pbuf, 646static void mid_copy_straight(struct pio_buf *pbuf,
642 const void *from, size_t nbytes) 647 const void *from, size_t nbytes)
643{ 648{
644 void __iomem *dest = pbuf->start + (pbuf->qw_written * sizeof(u64)); 649 void __iomem *dest = pbuf->start + (pbuf->qw_written * sizeof(u64));
645 void __iomem *dend; /* 8-byte data end */ 650 void __iomem *dend; /* 8-byte data end */
646 651
647 /* calculate 8-byte data end */ 652 /* calculate 8-byte data end */
648 dend = dest + ((nbytes>>3) * sizeof(u64)); 653 dend = dest + ((nbytes >> 3) * sizeof(u64));
649 654
650 if (pbuf->qw_written < PIO_BLOCK_QWS) { 655 if (pbuf->qw_written < PIO_BLOCK_QWS) {
651 /* 656 /*
@@ -656,8 +661,10 @@ static void mid_copy_straight(struct pio_buf *pbuf,
656 void __iomem *send; /* SOP end */ 661 void __iomem *send; /* SOP end */
657 void __iomem *xend; 662 void __iomem *xend;
658 663
659 /* calculate the end of data or end of block, whichever 664 /*
660 comes first */ 665 * calculate the end of data or end of block, whichever
666 * comes first
667 */
661 send = pbuf->start + PIO_BLOCK_SIZE; 668 send = pbuf->start + PIO_BLOCK_SIZE;
662 xend = min(send, dend); 669 xend = min(send, dend);
663 670
@@ -713,7 +720,7 @@ static void mid_copy_straight(struct pio_buf *pbuf,
713 /* we know carry_bytes was zero on entry to this routine */ 720 /* we know carry_bytes was zero on entry to this routine */
714 read_low_bytes(pbuf, from, nbytes & 0x7); 721 read_low_bytes(pbuf, from, nbytes & 0x7);
715 722
716 pbuf->qw_written += nbytes>>3; 723 pbuf->qw_written += nbytes >> 3;
717} 724}
718 725
719/* 726/*
diff --git a/drivers/staging/rdma/hfi1/platform.c b/drivers/staging/rdma/hfi1/platform.c
new file mode 100644
index 000000000000..0a1d074583e4
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/platform.c
@@ -0,0 +1,893 @@
1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include "hfi.h"
49#include "efivar.h"
50
51void get_platform_config(struct hfi1_devdata *dd)
52{
53 int ret = 0;
54 unsigned long size = 0;
55 u8 *temp_platform_config = NULL;
56
57 ret = read_hfi1_efi_var(dd, "configuration", &size,
58 (void **)&temp_platform_config);
59 if (ret) {
60 dd_dev_info(dd,
61 "%s: Failed to get platform config from UEFI, falling back to request firmware\n",
62 __func__);
63 /* fall back to request firmware */
64 platform_config_load = 1;
65 goto bail;
66 }
67
68 dd->platform_config.data = temp_platform_config;
69 dd->platform_config.size = size;
70
71bail:
72 /* exit */;
73}
74
75void free_platform_config(struct hfi1_devdata *dd)
76{
77 if (!platform_config_load) {
78 /*
79 * was loaded from EFI, release memory
80 * allocated by read_efi_var
81 */
82 kfree(dd->platform_config.data);
83 }
84 /*
85 * else do nothing, dispose_firmware will release
86 * struct firmware platform_config on driver exit
87 */
88}
89
90int set_qsfp_tx(struct hfi1_pportdata *ppd, int on)
91{
92 u8 tx_ctrl_byte = on ? 0x0 : 0xF;
93 int ret = 0;
94
95 ret = qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_TX_CTRL_BYTE_OFFS,
96 &tx_ctrl_byte, 1);
97 /* we expected 1, so consider 0 an error */
98 if (ret == 0)
99 ret = -EIO;
100 else if (ret == 1)
101 ret = 0;
102 return ret;
103}
104
105static int qual_power(struct hfi1_pportdata *ppd)
106{
107 u32 cable_power_class = 0, power_class_max = 0;
108 u8 *cache = ppd->qsfp_info.cache;
109 int ret = 0;
110
111 ret = get_platform_config_field(
112 ppd->dd, PLATFORM_CONFIG_SYSTEM_TABLE, 0,
113 SYSTEM_TABLE_QSFP_POWER_CLASS_MAX, &power_class_max, 4);
114 if (ret)
115 return ret;
116
117 if (QSFP_HIGH_PWR(cache[QSFP_MOD_PWR_OFFS]) != 4)
118 cable_power_class = QSFP_HIGH_PWR(cache[QSFP_MOD_PWR_OFFS]);
119 else
120 cable_power_class = QSFP_PWR(cache[QSFP_MOD_PWR_OFFS]);
121
122 if (cable_power_class <= 3 && cable_power_class > (power_class_max - 1))
123 ppd->offline_disabled_reason =
124 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY);
125 else if (cable_power_class > 4 && cable_power_class > (power_class_max))
126 ppd->offline_disabled_reason =
127 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY);
128 /*
129 * cable_power_class will never have value 4 as this simply
130 * means the high power settings are unused
131 */
132
133 if (ppd->offline_disabled_reason ==
134 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY)) {
135 dd_dev_info(
136 ppd->dd,
137 "%s: Port disabled due to system power restrictions\n",
138 __func__);
139 ret = -EPERM;
140 }
141 return ret;
142}
143
144static int qual_bitrate(struct hfi1_pportdata *ppd)
145{
146 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
147 u8 *cache = ppd->qsfp_info.cache;
148
149 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G) &&
150 cache[QSFP_NOM_BIT_RATE_250_OFFS] < 0x64)
151 ppd->offline_disabled_reason =
152 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
153
154 if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G) &&
155 cache[QSFP_NOM_BIT_RATE_100_OFFS] < 0x7D)
156 ppd->offline_disabled_reason =
157 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
158
159 if (ppd->offline_disabled_reason ==
160 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY)) {
161 dd_dev_info(
162 ppd->dd,
163 "%s: Cable failed bitrate check, disabling port\n",
164 __func__);
165 return -EPERM;
166 }
167 return 0;
168}
169
170static int set_qsfp_high_power(struct hfi1_pportdata *ppd)
171{
172 u8 cable_power_class = 0, power_ctrl_byte = 0;
173 u8 *cache = ppd->qsfp_info.cache;
174 int ret;
175
176 if (QSFP_HIGH_PWR(cache[QSFP_MOD_PWR_OFFS]) != 4)
177 cable_power_class = QSFP_HIGH_PWR(cache[QSFP_MOD_PWR_OFFS]);
178 else
179 cable_power_class = QSFP_PWR(cache[QSFP_MOD_PWR_OFFS]);
180
181 if (cable_power_class) {
182 power_ctrl_byte = cache[QSFP_PWR_CTRL_BYTE_OFFS];
183
184 power_ctrl_byte |= 1;
185 power_ctrl_byte &= ~(0x2);
186
187 ret = qsfp_write(ppd, ppd->dd->hfi1_id,
188 QSFP_PWR_CTRL_BYTE_OFFS,
189 &power_ctrl_byte, 1);
190 if (ret != 1)
191 return -EIO;
192
193 if (cable_power_class > 3) {
194 /* > power class 4*/
195 power_ctrl_byte |= (1 << 2);
196 ret = qsfp_write(ppd, ppd->dd->hfi1_id,
197 QSFP_PWR_CTRL_BYTE_OFFS,
198 &power_ctrl_byte, 1);
199 if (ret != 1)
200 return -EIO;
201 }
202
203 /* SFF 8679 rev 1.7 LPMode Deassert time */
204 msleep(300);
205 }
206 return 0;
207}
208
209static void apply_rx_cdr(struct hfi1_pportdata *ppd,
210 u32 rx_preset_index,
211 u8 *cdr_ctrl_byte)
212{
213 u32 rx_preset;
214 u8 *cache = ppd->qsfp_info.cache;
215
216 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x4) &&
217 (cache[QSFP_CDR_INFO_OFFS] & 0x40)))
218 return;
219
220 /* rx_preset preset to zero to catch error */
221 get_platform_config_field(
222 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
223 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR_APPLY,
224 &rx_preset, 4);
225
226 if (!rx_preset) {
227 dd_dev_info(
228 ppd->dd,
229 "%s: RX_CDR_APPLY is set to disabled\n",
230 __func__);
231 return;
232 }
233 get_platform_config_field(
234 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
235 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR,
236 &rx_preset, 4);
237
238 /* Expand cdr setting to all 4 lanes */
239 rx_preset = (rx_preset | (rx_preset << 1) |
240 (rx_preset << 2) | (rx_preset << 3));
241
242 if (rx_preset) {
243 *cdr_ctrl_byte |= rx_preset;
244 } else {
245 *cdr_ctrl_byte &= rx_preset;
246 /* Preserve current TX CDR status */
247 *cdr_ctrl_byte |= (cache[QSFP_CDR_CTRL_BYTE_OFFS] & 0xF0);
248 }
249}
250
251static void apply_tx_cdr(struct hfi1_pportdata *ppd,
252 u32 tx_preset_index,
253 u8 *ctr_ctrl_byte)
254{
255 u32 tx_preset;
256 u8 *cache = ppd->qsfp_info.cache;
257
258 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x8) &&
259 (cache[QSFP_CDR_INFO_OFFS] & 0x80)))
260 return;
261
262 get_platform_config_field(
263 ppd->dd,
264 PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
265 TX_PRESET_TABLE_QSFP_TX_CDR_APPLY, &tx_preset, 4);
266
267 if (!tx_preset) {
268 dd_dev_info(
269 ppd->dd,
270 "%s: TX_CDR_APPLY is set to disabled\n",
271 __func__);
272 return;
273 }
274 get_platform_config_field(
275 ppd->dd,
276 PLATFORM_CONFIG_TX_PRESET_TABLE,
277 tx_preset_index,
278 TX_PRESET_TABLE_QSFP_TX_CDR, &tx_preset, 4);
279
280 /* Expand cdr setting to all 4 lanes */
281 tx_preset = (tx_preset | (tx_preset << 1) |
282 (tx_preset << 2) | (tx_preset << 3));
283
284 if (tx_preset)
285 *ctr_ctrl_byte |= (tx_preset << 4);
286 else
287 /* Preserve current/determined RX CDR status */
288 *ctr_ctrl_byte &= ((tx_preset << 4) | 0xF);
289}
290
291static void apply_cdr_settings(
292 struct hfi1_pportdata *ppd, u32 rx_preset_index,
293 u32 tx_preset_index)
294{
295 u8 *cache = ppd->qsfp_info.cache;
296 u8 cdr_ctrl_byte = cache[QSFP_CDR_CTRL_BYTE_OFFS];
297
298 apply_rx_cdr(ppd, rx_preset_index, &cdr_ctrl_byte);
299
300 apply_tx_cdr(ppd, tx_preset_index, &cdr_ctrl_byte);
301
302 qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_CDR_CTRL_BYTE_OFFS,
303 &cdr_ctrl_byte, 1);
304}
305
306static void apply_tx_eq_auto(struct hfi1_pportdata *ppd)
307{
308 u8 *cache = ppd->qsfp_info.cache;
309 u8 tx_eq;
310
311 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x8))
312 return;
313 /* Disable adaptive TX EQ if present */
314 tx_eq = cache[(128 * 3) + 241];
315 tx_eq &= 0xF0;
316 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 241, &tx_eq, 1);
317}
318
319static void apply_tx_eq_prog(struct hfi1_pportdata *ppd, u32 tx_preset_index)
320{
321 u8 *cache = ppd->qsfp_info.cache;
322 u32 tx_preset;
323 u8 tx_eq;
324
325 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x4))
326 return;
327
328 get_platform_config_field(
329 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
330 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ_APPLY,
331 &tx_preset, 4);
332 if (!tx_preset) {
333 dd_dev_info(
334 ppd->dd,
335 "%s: TX_EQ_APPLY is set to disabled\n",
336 __func__);
337 return;
338 }
339 get_platform_config_field(
340 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
341 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ,
342 &tx_preset, 4);
343
344 if (((cache[(128 * 3) + 224] & 0xF0) >> 4) < tx_preset) {
345 dd_dev_info(
346 ppd->dd,
347 "%s: TX EQ %x unsupported\n",
348 __func__, tx_preset);
349
350 dd_dev_info(
351 ppd->dd,
352 "%s: Applying EQ %x\n",
353 __func__, cache[608] & 0xF0);
354
355 tx_preset = (cache[608] & 0xF0) >> 4;
356 }
357
358 tx_eq = tx_preset | (tx_preset << 4);
359 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 234, &tx_eq, 1);
360 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 235, &tx_eq, 1);
361}
362
363static void apply_rx_eq_emp(struct hfi1_pportdata *ppd, u32 rx_preset_index)
364{
365 u32 rx_preset;
366 u8 rx_eq, *cache = ppd->qsfp_info.cache;
367
368 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x2))
369 return;
370 get_platform_config_field(
371 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
372 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP_APPLY,
373 &rx_preset, 4);
374
375 if (!rx_preset) {
376 dd_dev_info(
377 ppd->dd,
378 "%s: RX_EMP_APPLY is set to disabled\n",
379 __func__);
380 return;
381 }
382 get_platform_config_field(
383 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
384 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP,
385 &rx_preset, 4);
386
387 if ((cache[(128 * 3) + 224] & 0xF) < rx_preset) {
388 dd_dev_info(
389 ppd->dd,
390 "%s: Requested RX EMP %x\n",
391 __func__, rx_preset);
392
393 dd_dev_info(
394 ppd->dd,
395 "%s: Applying supported EMP %x\n",
396 __func__, cache[608] & 0xF);
397
398 rx_preset = cache[608] & 0xF;
399 }
400
401 rx_eq = rx_preset | (rx_preset << 4);
402
403 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 236, &rx_eq, 1);
404 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 237, &rx_eq, 1);
405}
406
407static void apply_eq_settings(struct hfi1_pportdata *ppd,
408 u32 rx_preset_index, u32 tx_preset_index)
409{
410 u8 *cache = ppd->qsfp_info.cache;
411
412 /* no point going on w/o a page 3 */
413 if (cache[2] & 4) {
414 dd_dev_info(ppd->dd,
415 "%s: Upper page 03 not present\n",
416 __func__);
417 return;
418 }
419
420 apply_tx_eq_auto(ppd);
421
422 apply_tx_eq_prog(ppd, tx_preset_index);
423
424 apply_rx_eq_emp(ppd, rx_preset_index);
425}
426
427static void apply_rx_amplitude_settings(
428 struct hfi1_pportdata *ppd, u32 rx_preset_index,
429 u32 tx_preset_index)
430{
431 u32 rx_preset;
432 u8 rx_amp = 0, i = 0, preferred = 0, *cache = ppd->qsfp_info.cache;
433
434 /* no point going on w/o a page 3 */
435 if (cache[2] & 4) {
436 dd_dev_info(ppd->dd,
437 "%s: Upper page 03 not present\n",
438 __func__);
439 return;
440 }
441 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x1)) {
442 dd_dev_info(ppd->dd,
443 "%s: RX_AMP_APPLY is set to disabled\n",
444 __func__);
445 return;
446 }
447
448 get_platform_config_field(ppd->dd,
449 PLATFORM_CONFIG_RX_PRESET_TABLE,
450 rx_preset_index,
451 RX_PRESET_TABLE_QSFP_RX_AMP_APPLY,
452 &rx_preset, 4);
453
454 if (!rx_preset) {
455 dd_dev_info(ppd->dd,
456 "%s: RX_AMP_APPLY is set to disabled\n",
457 __func__);
458 return;
459 }
460 get_platform_config_field(ppd->dd,
461 PLATFORM_CONFIG_RX_PRESET_TABLE,
462 rx_preset_index,
463 RX_PRESET_TABLE_QSFP_RX_AMP,
464 &rx_preset, 4);
465
466 dd_dev_info(ppd->dd,
467 "%s: Requested RX AMP %x\n",
468 __func__,
469 rx_preset);
470
471 for (i = 0; i < 4; i++) {
472 if (cache[(128 * 3) + 225] & (1 << i)) {
473 preferred = i;
474 if (preferred == rx_preset)
475 break;
476 }
477 }
478
479 /*
480 * Verify that preferred RX amplitude is not just a
481 * fall through of the default
482 */
483 if (!preferred && !(cache[(128 * 3) + 225] & 0x1)) {
484 dd_dev_info(ppd->dd, "No supported RX AMP, not applying\n");
485 return;
486 }
487
488 dd_dev_info(ppd->dd,
489 "%s: Applying RX AMP %x\n", __func__, preferred);
490
491 rx_amp = preferred | (preferred << 4);
492 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 238, &rx_amp, 1);
493 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 239, &rx_amp, 1);
494}
495
496#define OPA_INVALID_INDEX 0xFFF
497
498static void apply_tx_lanes(struct hfi1_pportdata *ppd, u8 field_id,
499 u32 config_data, const char *message)
500{
501 u8 i;
502 int ret = HCMD_SUCCESS;
503
504 for (i = 0; i < 4; i++) {
505 ret = load_8051_config(ppd->dd, field_id, i, config_data);
506 if (ret != HCMD_SUCCESS) {
507 dd_dev_err(
508 ppd->dd,
509 "%s: %s for lane %u failed\n",
510 message, __func__, i);
511 }
512 }
513}
514
515static void apply_tunings(
516 struct hfi1_pportdata *ppd, u32 tx_preset_index,
517 u8 tuning_method, u32 total_atten, u8 limiting_active)
518{
519 int ret = 0;
520 u32 config_data = 0, tx_preset = 0;
521 u8 precur = 0, attn = 0, postcur = 0, external_device_config = 0;
522 u8 *cache = ppd->qsfp_info.cache;
523
524 /* Enable external device config if channel is limiting active */
525 read_8051_config(ppd->dd, LINK_OPTIMIZATION_SETTINGS,
526 GENERAL_CONFIG, &config_data);
527 config_data |= limiting_active;
528 ret = load_8051_config(ppd->dd, LINK_OPTIMIZATION_SETTINGS,
529 GENERAL_CONFIG, config_data);
530 if (ret != HCMD_SUCCESS)
531 dd_dev_err(
532 ppd->dd,
533 "%s: Failed to set enable external device config\n",
534 __func__);
535
536 config_data = 0; /* re-init */
537 /* Pass tuning method to 8051 */
538 read_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
539 &config_data);
540 config_data |= tuning_method;
541 ret = load_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
542 config_data);
543 if (ret != HCMD_SUCCESS)
544 dd_dev_err(ppd->dd, "%s: Failed to set tuning method\n",
545 __func__);
546
547 /* Set same channel loss for both TX and RX */
548 config_data = 0 | (total_atten << 16) | (total_atten << 24);
549 apply_tx_lanes(ppd, CHANNEL_LOSS_SETTINGS, config_data,
550 "Setting channel loss");
551
552 /* Inform 8051 of cable capabilities */
553 if (ppd->qsfp_info.cache_valid) {
554 external_device_config =
555 ((cache[QSFP_MOD_PWR_OFFS] & 0x4) << 3) |
556 ((cache[QSFP_MOD_PWR_OFFS] & 0x8) << 2) |
557 ((cache[QSFP_EQ_INFO_OFFS] & 0x2) << 1) |
558 (cache[QSFP_EQ_INFO_OFFS] & 0x4);
559 ret = read_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
560 GENERAL_CONFIG, &config_data);
561 /* Clear, then set the external device config field */
562 config_data &= ~(0xFF << 24);
563 config_data |= (external_device_config << 24);
564 ret = load_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
565 GENERAL_CONFIG, config_data);
566 if (ret != HCMD_SUCCESS)
567 dd_dev_info(ppd->dd,
568 "%s: Failed set ext device config params\n",
569 __func__);
570 }
571
572 if (tx_preset_index == OPA_INVALID_INDEX) {
573 if (ppd->port_type == PORT_TYPE_QSFP && limiting_active)
574 dd_dev_info(ppd->dd, "%s: Invalid Tx preset index\n",
575 __func__);
576 return;
577 }
578
579 /* Following for limiting active channels only */
580 get_platform_config_field(
581 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
582 TX_PRESET_TABLE_PRECUR, &tx_preset, 4);
583 precur = tx_preset;
584
585 get_platform_config_field(
586 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
587 tx_preset_index, TX_PRESET_TABLE_ATTN, &tx_preset, 4);
588 attn = tx_preset;
589
590 get_platform_config_field(
591 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
592 tx_preset_index, TX_PRESET_TABLE_POSTCUR, &tx_preset, 4);
593 postcur = tx_preset;
594
595 config_data = precur | (attn << 8) | (postcur << 16);
596
597 apply_tx_lanes(ppd, TX_EQ_SETTINGS, config_data,
598 "Applying TX settings");
599}
600
601static int tune_active_qsfp(struct hfi1_pportdata *ppd, u32 *ptr_tx_preset,
602 u32 *ptr_rx_preset, u32 *ptr_total_atten)
603{
604 int ret;
605 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
606 u8 *cache = ppd->qsfp_info.cache;
607
608 ret = acquire_chip_resource(ppd->dd, qsfp_resource(ppd->dd), QSFP_WAIT);
609 if (ret) {
610 dd_dev_err(ppd->dd, "%s: hfi%d: cannot lock i2c chain\n",
611 __func__, (int)ppd->dd->hfi1_id);
612 return ret;
613 }
614
615 ppd->qsfp_info.limiting_active = 1;
616
617 ret = set_qsfp_tx(ppd, 0);
618 if (ret)
619 goto bail_unlock;
620
621 ret = qual_power(ppd);
622 if (ret)
623 goto bail_unlock;
624
625 ret = qual_bitrate(ppd);
626 if (ret)
627 goto bail_unlock;
628
629 if (ppd->qsfp_info.reset_needed) {
630 reset_qsfp(ppd);
631 ppd->qsfp_info.reset_needed = 0;
632 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
633 } else {
634 ppd->qsfp_info.reset_needed = 1;
635 }
636
637 ret = set_qsfp_high_power(ppd);
638 if (ret)
639 goto bail_unlock;
640
641 if (cache[QSFP_EQ_INFO_OFFS] & 0x4) {
642 ret = get_platform_config_field(
643 ppd->dd,
644 PLATFORM_CONFIG_PORT_TABLE, 0,
645 PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ,
646 ptr_tx_preset, 4);
647 if (ret) {
648 *ptr_tx_preset = OPA_INVALID_INDEX;
649 goto bail_unlock;
650 }
651 } else {
652 ret = get_platform_config_field(
653 ppd->dd,
654 PLATFORM_CONFIG_PORT_TABLE, 0,
655 PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ,
656 ptr_tx_preset, 4);
657 if (ret) {
658 *ptr_tx_preset = OPA_INVALID_INDEX;
659 goto bail_unlock;
660 }
661 }
662
663 ret = get_platform_config_field(
664 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
665 PORT_TABLE_RX_PRESET_IDX, ptr_rx_preset, 4);
666 if (ret) {
667 *ptr_rx_preset = OPA_INVALID_INDEX;
668 goto bail_unlock;
669 }
670
671 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
672 get_platform_config_field(
673 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
674 PORT_TABLE_LOCAL_ATTEN_25G, ptr_total_atten, 4);
675 else if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G))
676 get_platform_config_field(
677 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
678 PORT_TABLE_LOCAL_ATTEN_12G, ptr_total_atten, 4);
679
680 apply_cdr_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
681
682 apply_eq_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
683
684 apply_rx_amplitude_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
685
686 ret = set_qsfp_tx(ppd, 1);
687
688bail_unlock:
689 release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
690 return ret;
691}
692
693static int tune_qsfp(struct hfi1_pportdata *ppd,
694 u32 *ptr_tx_preset, u32 *ptr_rx_preset,
695 u8 *ptr_tuning_method, u32 *ptr_total_atten)
696{
697 u32 cable_atten = 0, remote_atten = 0, platform_atten = 0;
698 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
699 int ret = 0;
700 u8 *cache = ppd->qsfp_info.cache;
701
702 switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
703 case 0xA ... 0xB:
704 ret = get_platform_config_field(
705 ppd->dd,
706 PLATFORM_CONFIG_PORT_TABLE, 0,
707 PORT_TABLE_LOCAL_ATTEN_25G,
708 &platform_atten, 4);
709 if (ret)
710 return ret;
711
712 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
713 cable_atten = cache[QSFP_CU_ATTEN_12G_OFFS];
714 else if ((lss & OPA_LINK_SPEED_12_5G) &&
715 (lse & OPA_LINK_SPEED_12_5G))
716 cable_atten = cache[QSFP_CU_ATTEN_7G_OFFS];
717
718 /* Fallback to configured attenuation if cable memory is bad */
719 if (cable_atten == 0 || cable_atten > 36) {
720 ret = get_platform_config_field(
721 ppd->dd,
722 PLATFORM_CONFIG_SYSTEM_TABLE, 0,
723 SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G,
724 &cable_atten, 4);
725 if (ret)
726 return ret;
727 }
728
729 ret = get_platform_config_field(
730 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
731 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
732 if (ret)
733 return ret;
734
735 *ptr_total_atten = platform_atten + cable_atten + remote_atten;
736
737 *ptr_tuning_method = OPA_PASSIVE_TUNING;
738 break;
739 case 0x0 ... 0x9: /* fallthrough */
740 case 0xC: /* fallthrough */
741 case 0xE:
742 ret = tune_active_qsfp(ppd, ptr_tx_preset, ptr_rx_preset,
743 ptr_total_atten);
744 if (ret)
745 return ret;
746
747 *ptr_tuning_method = OPA_ACTIVE_TUNING;
748 break;
749 case 0xD: /* fallthrough */
750 case 0xF:
751 default:
752 dd_dev_info(ppd->dd, "%s: Unknown/unsupported cable\n",
753 __func__);
754 break;
755 }
756 return ret;
757}
758
759/*
760 * This function communicates its success or failure via ppd->driver_link_ready
761 * Thus, it depends on its association with start_link(...) which checks
762 * driver_link_ready before proceeding with the link negotiation and
763 * initialization process.
764 */
765void tune_serdes(struct hfi1_pportdata *ppd)
766{
767 int ret = 0;
768 u32 total_atten = 0;
769 u32 remote_atten = 0, platform_atten = 0;
770 u32 rx_preset_index, tx_preset_index;
771 u8 tuning_method = 0, limiting_active = 0;
772 struct hfi1_devdata *dd = ppd->dd;
773
774 rx_preset_index = OPA_INVALID_INDEX;
775 tx_preset_index = OPA_INVALID_INDEX;
776
777 /* the link defaults to enabled */
778 ppd->link_enabled = 1;
779 /* the driver link ready state defaults to not ready */
780 ppd->driver_link_ready = 0;
781 ppd->offline_disabled_reason = HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
782
783 /* Skip the tuning for testing (loopback != none) and simulations */
784 if (loopback != LOOPBACK_NONE ||
785 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
786 ppd->driver_link_ready = 1;
787 return;
788 }
789
790 ret = get_platform_config_field(ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
791 PORT_TABLE_PORT_TYPE, &ppd->port_type,
792 4);
793 if (ret)
794 ppd->port_type = PORT_TYPE_UNKNOWN;
795
796 switch (ppd->port_type) {
797 case PORT_TYPE_DISCONNECTED:
798 ppd->offline_disabled_reason =
799 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_DISCONNECTED);
800 dd_dev_info(dd, "%s: Port disconnected, disabling port\n",
801 __func__);
802 goto bail;
803 case PORT_TYPE_FIXED:
804 /* platform_atten, remote_atten pre-zeroed to catch error */
805 get_platform_config_field(
806 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
807 PORT_TABLE_LOCAL_ATTEN_25G, &platform_atten, 4);
808
809 get_platform_config_field(
810 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
811 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
812
813 total_atten = platform_atten + remote_atten;
814
815 tuning_method = OPA_PASSIVE_TUNING;
816 break;
817 case PORT_TYPE_VARIABLE:
818 if (qsfp_mod_present(ppd)) {
819 /*
820 * platform_atten, remote_atten pre-zeroed to
821 * catch error
822 */
823 get_platform_config_field(
824 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
825 PORT_TABLE_LOCAL_ATTEN_25G,
826 &platform_atten, 4);
827
828 get_platform_config_field(
829 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
830 PORT_TABLE_REMOTE_ATTEN_25G,
831 &remote_atten, 4);
832
833 total_atten = platform_atten + remote_atten;
834
835 tuning_method = OPA_PASSIVE_TUNING;
836 } else
837 ppd->offline_disabled_reason =
838 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_CHASSIS_CONFIG);
839 break;
840 case PORT_TYPE_QSFP:
841 if (qsfp_mod_present(ppd)) {
842 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
843
844 if (ppd->qsfp_info.cache_valid) {
845 ret = tune_qsfp(ppd,
846 &tx_preset_index,
847 &rx_preset_index,
848 &tuning_method,
849 &total_atten);
850
851 /*
852 * We may have modified the QSFP memory, so
853 * update the cache to reflect the changes
854 */
855 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
856 if (ret)
857 goto bail;
858
859 limiting_active =
860 ppd->qsfp_info.limiting_active;
861 } else {
862 dd_dev_err(dd,
863 "%s: Reading QSFP memory failed\n",
864 __func__);
865 goto bail;
866 }
867 } else
868 ppd->offline_disabled_reason =
869 HFI1_ODR_MASK(
870 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
871 break;
872 default:
873 dd_dev_info(ppd->dd, "%s: Unknown port type\n", __func__);
874 ppd->port_type = PORT_TYPE_UNKNOWN;
875 tuning_method = OPA_UNKNOWN_TUNING;
876 total_atten = 0;
877 limiting_active = 0;
878 tx_preset_index = OPA_INVALID_INDEX;
879 break;
880 }
881
882 if (ppd->offline_disabled_reason ==
883 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
884 apply_tunings(ppd, tx_preset_index, tuning_method,
885 total_atten, limiting_active);
886
887 if (!ret)
888 ppd->driver_link_ready = 1;
889
890 return;
891bail:
892 ppd->driver_link_ready = 0;
893}
diff --git a/drivers/staging/rdma/hfi1/platform_config.h b/drivers/staging/rdma/hfi1/platform.h
index 8a94a8342052..19620cf546d5 100644
--- a/drivers/staging/rdma/hfi1/platform_config.h
+++ b/drivers/staging/rdma/hfi1/platform.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -47,8 +44,8 @@
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 * 45 *
49 */ 46 */
50#ifndef __PLATFORM_CONFIG_H 47#ifndef __PLATFORM_H
51#define __PLATFORM_CONFIG_H 48#define __PLATFORM_H
52 49
53#define METADATA_TABLE_FIELD_START_SHIFT 0 50#define METADATA_TABLE_FIELD_START_SHIFT 0
54#define METADATA_TABLE_FIELD_START_LEN_BITS 15 51#define METADATA_TABLE_FIELD_START_LEN_BITS 15
@@ -94,17 +91,18 @@ enum platform_config_system_table_fields {
94enum platform_config_port_table_fields { 91enum platform_config_port_table_fields {
95 PORT_TABLE_RESERVED, 92 PORT_TABLE_RESERVED,
96 PORT_TABLE_PORT_TYPE, 93 PORT_TABLE_PORT_TYPE,
97 PORT_TABLE_ATTENUATION_12G, 94 PORT_TABLE_LOCAL_ATTEN_12G,
98 PORT_TABLE_ATTENUATION_25G, 95 PORT_TABLE_LOCAL_ATTEN_25G,
99 PORT_TABLE_LINK_SPEED_SUPPORTED, 96 PORT_TABLE_LINK_SPEED_SUPPORTED,
100 PORT_TABLE_LINK_WIDTH_SUPPORTED, 97 PORT_TABLE_LINK_WIDTH_SUPPORTED,
98 PORT_TABLE_AUTO_LANE_SHEDDING_ENABLED,
99 PORT_TABLE_EXTERNAL_LOOPBACK_ALLOWED,
101 PORT_TABLE_VL_CAP, 100 PORT_TABLE_VL_CAP,
102 PORT_TABLE_MTU_CAP, 101 PORT_TABLE_MTU_CAP,
103 PORT_TABLE_TX_LANE_ENABLE_MASK, 102 PORT_TABLE_TX_LANE_ENABLE_MASK,
104 PORT_TABLE_LOCAL_MAX_TIMEOUT, 103 PORT_TABLE_LOCAL_MAX_TIMEOUT,
105 PORT_TABLE_AUTO_LANE_SHEDDING_ENABLED, 104 PORT_TABLE_REMOTE_ATTEN_12G,
106 PORT_TABLE_EXTERNAL_LOOPBACK_ALLOWED, 105 PORT_TABLE_REMOTE_ATTEN_25G,
107 PORT_TABLE_TX_PRESET_IDX_PASSIVE_CU,
108 PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ, 106 PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ,
109 PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ, 107 PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ,
110 PORT_TABLE_RX_PRESET_IDX, 108 PORT_TABLE_RX_PRESET_IDX,
@@ -115,10 +113,10 @@ enum platform_config_port_table_fields {
115enum platform_config_rx_preset_table_fields { 113enum platform_config_rx_preset_table_fields {
116 RX_PRESET_TABLE_RESERVED, 114 RX_PRESET_TABLE_RESERVED,
117 RX_PRESET_TABLE_QSFP_RX_CDR_APPLY, 115 RX_PRESET_TABLE_QSFP_RX_CDR_APPLY,
118 RX_PRESET_TABLE_QSFP_RX_EQ_APPLY, 116 RX_PRESET_TABLE_QSFP_RX_EMP_APPLY,
119 RX_PRESET_TABLE_QSFP_RX_AMP_APPLY, 117 RX_PRESET_TABLE_QSFP_RX_AMP_APPLY,
120 RX_PRESET_TABLE_QSFP_RX_CDR, 118 RX_PRESET_TABLE_QSFP_RX_CDR,
121 RX_PRESET_TABLE_QSFP_RX_EQ, 119 RX_PRESET_TABLE_QSFP_RX_EMP,
122 RX_PRESET_TABLE_QSFP_RX_AMP, 120 RX_PRESET_TABLE_QSFP_RX_AMP,
123 RX_PRESET_TABLE_MAX 121 RX_PRESET_TABLE_MAX
124}; 122};
@@ -149,6 +147,11 @@ enum platform_config_variable_settings_table_fields {
149 VARIABLE_SETTINGS_TABLE_MAX 147 VARIABLE_SETTINGS_TABLE_MAX
150}; 148};
151 149
150struct platform_config {
151 size_t size;
152 const u8 *data;
153};
154
152struct platform_config_data { 155struct platform_config_data {
153 u32 *table; 156 u32 *table;
154 u32 *table_metadata; 157 u32 *table_metadata;
@@ -179,9 +182,11 @@ static const u32 platform_config_table_limits[PLATFORM_CONFIG_TABLE_MAX] = {
179 * fields defined for each table above 182 * fields defined for each table above
180 */ 183 */
181 184
182/*===================================================== 185/*
186 * =====================================================
183 * System table encodings 187 * System table encodings
184 *====================================================*/ 188 * =====================================================
189 */
185#define PLATFORM_CONFIG_MAGIC_NUM 0x3d4f5041 190#define PLATFORM_CONFIG_MAGIC_NUM 0x3d4f5041
186#define PLATFORM_CONFIG_MAGIC_NUMBER_LEN 4 191#define PLATFORM_CONFIG_MAGIC_NUMBER_LEN 4
187 192
@@ -199,12 +204,13 @@ enum platform_config_qsfp_power_class_encoding {
199 QSFP_POWER_CLASS_7 204 QSFP_POWER_CLASS_7
200}; 205};
201 206
202 207/*
203/*===================================================== 208 * ====================================================
204 * Port table encodings 209 * Port table encodings
205 *==================================================== */ 210 * ====================================================
211 */
206enum platform_config_port_type_encoding { 212enum platform_config_port_type_encoding {
207 PORT_TYPE_RESERVED, 213 PORT_TYPE_UNKNOWN,
208 PORT_TYPE_DISCONNECTED, 214 PORT_TYPE_DISCONNECTED,
209 PORT_TYPE_FIXED, 215 PORT_TYPE_FIXED,
210 PORT_TYPE_VARIABLE, 216 PORT_TYPE_VARIABLE,
@@ -283,4 +289,16 @@ enum platform_config_local_max_timeout_encoding {
283 LOCAL_MAX_TIMEOUT_1000_S 289 LOCAL_MAX_TIMEOUT_1000_S
284}; 290};
285 291
286#endif /*__PLATFORM_CONFIG_H*/ 292enum link_tuning_encoding {
293 OPA_PASSIVE_TUNING,
294 OPA_ACTIVE_TUNING,
295 OPA_UNKNOWN_TUNING
296};
297
298/* platform.c */
299void get_platform_config(struct hfi1_devdata *dd);
300void free_platform_config(struct hfi1_devdata *dd);
301int set_qsfp_tx(struct hfi1_pportdata *ppd, int on);
302void tune_serdes(struct hfi1_pportdata *ppd);
303
304#endif /*__PLATFORM_H*/
diff --git a/drivers/staging/rdma/hfi1/qp.c b/drivers/staging/rdma/hfi1/qp.c
index ce036810d576..29a5ad28019b 100644
--- a/drivers/staging/rdma/hfi1/qp.c
+++ b/drivers/staging/rdma/hfi1/qp.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -54,31 +51,32 @@
54#include <linux/module.h> 51#include <linux/module.h>
55#include <linux/random.h> 52#include <linux/random.h>
56#include <linux/seq_file.h> 53#include <linux/seq_file.h>
54#include <rdma/rdma_vt.h>
55#include <rdma/rdmavt_qp.h>
57 56
58#include "hfi.h" 57#include "hfi.h"
59#include "qp.h" 58#include "qp.h"
60#include "trace.h" 59#include "trace.h"
61#include "sdma.h" 60#include "verbs_txreq.h"
62 61
63#define BITS_PER_PAGE (PAGE_SIZE*BITS_PER_BYTE) 62unsigned int hfi1_qp_table_size = 256;
64#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
65
66static unsigned int hfi1_qp_table_size = 256;
67module_param_named(qp_table_size, hfi1_qp_table_size, uint, S_IRUGO); 63module_param_named(qp_table_size, hfi1_qp_table_size, uint, S_IRUGO);
68MODULE_PARM_DESC(qp_table_size, "QP table size"); 64MODULE_PARM_DESC(qp_table_size, "QP table size");
69 65
70static void flush_tx_list(struct hfi1_qp *qp); 66static void flush_tx_list(struct rvt_qp *qp);
71static int iowait_sleep( 67static int iowait_sleep(
72 struct sdma_engine *sde, 68 struct sdma_engine *sde,
73 struct iowait *wait, 69 struct iowait *wait,
74 struct sdma_txreq *stx, 70 struct sdma_txreq *stx,
75 unsigned seq); 71 unsigned seq);
76static void iowait_wakeup(struct iowait *wait, int reason); 72static void iowait_wakeup(struct iowait *wait, int reason);
73static void iowait_sdma_drained(struct iowait *wait);
74static void qp_pio_drain(struct rvt_qp *qp);
77 75
78static inline unsigned mk_qpn(struct hfi1_qpn_table *qpt, 76static inline unsigned mk_qpn(struct rvt_qpn_table *qpt,
79 struct qpn_map *map, unsigned off) 77 struct rvt_qpn_map *map, unsigned off)
80{ 78{
81 return (map - qpt->map) * BITS_PER_PAGE + off; 79 return (map - qpt->map) * RVT_BITS_PER_PAGE + off;
82} 80}
83 81
84/* 82/*
@@ -118,437 +116,15 @@ static const u16 credit_table[31] = {
118 32768 /* 1E */ 116 32768 /* 1E */
119}; 117};
120 118
121static void get_map_page(struct hfi1_qpn_table *qpt, struct qpn_map *map) 119static void flush_tx_list(struct rvt_qp *qp)
122{
123 unsigned long page = get_zeroed_page(GFP_KERNEL);
124
125 /*
126 * Free the page if someone raced with us installing it.
127 */
128
129 spin_lock(&qpt->lock);
130 if (map->page)
131 free_page(page);
132 else
133 map->page = (void *)page;
134 spin_unlock(&qpt->lock);
135}
136
137/*
138 * Allocate the next available QPN or
139 * zero/one for QP type IB_QPT_SMI/IB_QPT_GSI.
140 */
141static int alloc_qpn(struct hfi1_devdata *dd, struct hfi1_qpn_table *qpt,
142 enum ib_qp_type type, u8 port)
143{
144 u32 i, offset, max_scan, qpn;
145 struct qpn_map *map;
146 u32 ret;
147
148 if (type == IB_QPT_SMI || type == IB_QPT_GSI) {
149 unsigned n;
150
151 ret = type == IB_QPT_GSI;
152 n = 1 << (ret + 2 * (port - 1));
153 spin_lock(&qpt->lock);
154 if (qpt->flags & n)
155 ret = -EINVAL;
156 else
157 qpt->flags |= n;
158 spin_unlock(&qpt->lock);
159 goto bail;
160 }
161
162 qpn = qpt->last + qpt->incr;
163 if (qpn >= QPN_MAX)
164 qpn = qpt->incr | ((qpt->last & 1) ^ 1);
165 /* offset carries bit 0 */
166 offset = qpn & BITS_PER_PAGE_MASK;
167 map = &qpt->map[qpn / BITS_PER_PAGE];
168 max_scan = qpt->nmaps - !offset;
169 for (i = 0;;) {
170 if (unlikely(!map->page)) {
171 get_map_page(qpt, map);
172 if (unlikely(!map->page))
173 break;
174 }
175 do {
176 if (!test_and_set_bit(offset, map->page)) {
177 qpt->last = qpn;
178 ret = qpn;
179 goto bail;
180 }
181 offset += qpt->incr;
182 /*
183 * This qpn might be bogus if offset >= BITS_PER_PAGE.
184 * That is OK. It gets re-assigned below
185 */
186 qpn = mk_qpn(qpt, map, offset);
187 } while (offset < BITS_PER_PAGE && qpn < QPN_MAX);
188 /*
189 * In order to keep the number of pages allocated to a
190 * minimum, we scan the all existing pages before increasing
191 * the size of the bitmap table.
192 */
193 if (++i > max_scan) {
194 if (qpt->nmaps == QPNMAP_ENTRIES)
195 break;
196 map = &qpt->map[qpt->nmaps++];
197 /* start at incr with current bit 0 */
198 offset = qpt->incr | (offset & 1);
199 } else if (map < &qpt->map[qpt->nmaps]) {
200 ++map;
201 /* start at incr with current bit 0 */
202 offset = qpt->incr | (offset & 1);
203 } else {
204 map = &qpt->map[0];
205 /* wrap to first map page, invert bit 0 */
206 offset = qpt->incr | ((offset & 1) ^ 1);
207 }
208 /* there can be no bits at shift and below */
209 WARN_ON(offset & (dd->qos_shift - 1));
210 qpn = mk_qpn(qpt, map, offset);
211 }
212
213 ret = -ENOMEM;
214
215bail:
216 return ret;
217}
218
219static void free_qpn(struct hfi1_qpn_table *qpt, u32 qpn)
220{
221 struct qpn_map *map;
222
223 map = qpt->map + qpn / BITS_PER_PAGE;
224 if (map->page)
225 clear_bit(qpn & BITS_PER_PAGE_MASK, map->page);
226}
227
228/*
229 * Put the QP into the hash table.
230 * The hash table holds a reference to the QP.
231 */
232static void insert_qp(struct hfi1_ibdev *dev, struct hfi1_qp *qp)
233{
234 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
235 unsigned long flags;
236
237 atomic_inc(&qp->refcount);
238 spin_lock_irqsave(&dev->qp_dev->qpt_lock, flags);
239
240 if (qp->ibqp.qp_num <= 1) {
241 rcu_assign_pointer(ibp->qp[qp->ibqp.qp_num], qp);
242 } else {
243 u32 n = qpn_hash(dev->qp_dev, qp->ibqp.qp_num);
244
245 qp->next = dev->qp_dev->qp_table[n];
246 rcu_assign_pointer(dev->qp_dev->qp_table[n], qp);
247 trace_hfi1_qpinsert(qp, n);
248 }
249
250 spin_unlock_irqrestore(&dev->qp_dev->qpt_lock, flags);
251}
252
253/*
254 * Remove the QP from the table so it can't be found asynchronously by
255 * the receive interrupt routine.
256 */
257static void remove_qp(struct hfi1_ibdev *dev, struct hfi1_qp *qp)
258{
259 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
260 u32 n = qpn_hash(dev->qp_dev, qp->ibqp.qp_num);
261 unsigned long flags;
262 int removed = 1;
263
264 spin_lock_irqsave(&dev->qp_dev->qpt_lock, flags);
265
266 if (rcu_dereference_protected(ibp->qp[0],
267 lockdep_is_held(&dev->qp_dev->qpt_lock)) == qp) {
268 RCU_INIT_POINTER(ibp->qp[0], NULL);
269 } else if (rcu_dereference_protected(ibp->qp[1],
270 lockdep_is_held(&dev->qp_dev->qpt_lock)) == qp) {
271 RCU_INIT_POINTER(ibp->qp[1], NULL);
272 } else {
273 struct hfi1_qp *q;
274 struct hfi1_qp __rcu **qpp;
275
276 removed = 0;
277 qpp = &dev->qp_dev->qp_table[n];
278 for (; (q = rcu_dereference_protected(*qpp,
279 lockdep_is_held(&dev->qp_dev->qpt_lock)))
280 != NULL;
281 qpp = &q->next)
282 if (q == qp) {
283 RCU_INIT_POINTER(*qpp,
284 rcu_dereference_protected(qp->next,
285 lockdep_is_held(&dev->qp_dev->qpt_lock)));
286 removed = 1;
287 trace_hfi1_qpremove(qp, n);
288 break;
289 }
290 }
291
292 spin_unlock_irqrestore(&dev->qp_dev->qpt_lock, flags);
293 if (removed) {
294 synchronize_rcu();
295 if (atomic_dec_and_test(&qp->refcount))
296 wake_up(&qp->wait);
297 }
298}
299
300/**
301 * free_all_qps - check for QPs still in use
302 * @qpt: the QP table to empty
303 *
304 * There should not be any QPs still in use.
305 * Free memory for table.
306 */
307static unsigned free_all_qps(struct hfi1_devdata *dd)
308{
309 struct hfi1_ibdev *dev = &dd->verbs_dev;
310 unsigned long flags;
311 struct hfi1_qp *qp;
312 unsigned n, qp_inuse = 0;
313
314 for (n = 0; n < dd->num_pports; n++) {
315 struct hfi1_ibport *ibp = &dd->pport[n].ibport_data;
316
317 if (!hfi1_mcast_tree_empty(ibp))
318 qp_inuse++;
319 rcu_read_lock();
320 if (rcu_dereference(ibp->qp[0]))
321 qp_inuse++;
322 if (rcu_dereference(ibp->qp[1]))
323 qp_inuse++;
324 rcu_read_unlock();
325 }
326
327 if (!dev->qp_dev)
328 goto bail;
329 spin_lock_irqsave(&dev->qp_dev->qpt_lock, flags);
330 for (n = 0; n < dev->qp_dev->qp_table_size; n++) {
331 qp = rcu_dereference_protected(dev->qp_dev->qp_table[n],
332 lockdep_is_held(&dev->qp_dev->qpt_lock));
333 RCU_INIT_POINTER(dev->qp_dev->qp_table[n], NULL);
334
335 for (; qp; qp = rcu_dereference_protected(qp->next,
336 lockdep_is_held(&dev->qp_dev->qpt_lock)))
337 qp_inuse++;
338 }
339 spin_unlock_irqrestore(&dev->qp_dev->qpt_lock, flags);
340 synchronize_rcu();
341bail:
342 return qp_inuse;
343}
344
345/**
346 * reset_qp - initialize the QP state to the reset state
347 * @qp: the QP to reset
348 * @type: the QP type
349 */
350static void reset_qp(struct hfi1_qp *qp, enum ib_qp_type type)
351{
352 qp->remote_qpn = 0;
353 qp->qkey = 0;
354 qp->qp_access_flags = 0;
355 iowait_init(
356 &qp->s_iowait,
357 1,
358 hfi1_do_send,
359 iowait_sleep,
360 iowait_wakeup);
361 qp->s_flags &= HFI1_S_SIGNAL_REQ_WR;
362 qp->s_hdrwords = 0;
363 qp->s_wqe = NULL;
364 qp->s_draining = 0;
365 qp->s_next_psn = 0;
366 qp->s_last_psn = 0;
367 qp->s_sending_psn = 0;
368 qp->s_sending_hpsn = 0;
369 qp->s_psn = 0;
370 qp->r_psn = 0;
371 qp->r_msn = 0;
372 if (type == IB_QPT_RC) {
373 qp->s_state = IB_OPCODE_RC_SEND_LAST;
374 qp->r_state = IB_OPCODE_RC_SEND_LAST;
375 } else {
376 qp->s_state = IB_OPCODE_UC_SEND_LAST;
377 qp->r_state = IB_OPCODE_UC_SEND_LAST;
378 }
379 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
380 qp->r_nak_state = 0;
381 qp->r_adefered = 0;
382 qp->r_aflags = 0;
383 qp->r_flags = 0;
384 qp->s_head = 0;
385 qp->s_tail = 0;
386 qp->s_cur = 0;
387 qp->s_acked = 0;
388 qp->s_last = 0;
389 qp->s_ssn = 1;
390 qp->s_lsn = 0;
391 clear_ahg(qp);
392 qp->s_mig_state = IB_MIG_MIGRATED;
393 memset(qp->s_ack_queue, 0, sizeof(qp->s_ack_queue));
394 qp->r_head_ack_queue = 0;
395 qp->s_tail_ack_queue = 0;
396 qp->s_num_rd_atomic = 0;
397 if (qp->r_rq.wq) {
398 qp->r_rq.wq->head = 0;
399 qp->r_rq.wq->tail = 0;
400 }
401 qp->r_sge.num_sge = 0;
402}
403
404static void clear_mr_refs(struct hfi1_qp *qp, int clr_sends)
405{
406 unsigned n;
407
408 if (test_and_clear_bit(HFI1_R_REWIND_SGE, &qp->r_aflags))
409 hfi1_put_ss(&qp->s_rdma_read_sge);
410
411 hfi1_put_ss(&qp->r_sge);
412
413 if (clr_sends) {
414 while (qp->s_last != qp->s_head) {
415 struct hfi1_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
416 unsigned i;
417
418 for (i = 0; i < wqe->wr.num_sge; i++) {
419 struct hfi1_sge *sge = &wqe->sg_list[i];
420
421 hfi1_put_mr(sge->mr);
422 }
423 if (qp->ibqp.qp_type == IB_QPT_UD ||
424 qp->ibqp.qp_type == IB_QPT_SMI ||
425 qp->ibqp.qp_type == IB_QPT_GSI)
426 atomic_dec(&to_iah(wqe->ud_wr.ah)->refcount);
427 if (++qp->s_last >= qp->s_size)
428 qp->s_last = 0;
429 }
430 if (qp->s_rdma_mr) {
431 hfi1_put_mr(qp->s_rdma_mr);
432 qp->s_rdma_mr = NULL;
433 }
434 }
435
436 if (qp->ibqp.qp_type != IB_QPT_RC)
437 return;
438
439 for (n = 0; n < ARRAY_SIZE(qp->s_ack_queue); n++) {
440 struct hfi1_ack_entry *e = &qp->s_ack_queue[n];
441
442 if (e->opcode == IB_OPCODE_RC_RDMA_READ_REQUEST &&
443 e->rdma_sge.mr) {
444 hfi1_put_mr(e->rdma_sge.mr);
445 e->rdma_sge.mr = NULL;
446 }
447 }
448}
449
450/**
451 * hfi1_error_qp - put a QP into the error state
452 * @qp: the QP to put into the error state
453 * @err: the receive completion error to signal if a RWQE is active
454 *
455 * Flushes both send and receive work queues.
456 * Returns true if last WQE event should be generated.
457 * The QP r_lock and s_lock should be held and interrupts disabled.
458 * If we are already in error state, just return.
459 */
460int hfi1_error_qp(struct hfi1_qp *qp, enum ib_wc_status err)
461{ 120{
462 struct hfi1_ibdev *dev = to_idev(qp->ibqp.device); 121 struct hfi1_qp_priv *priv = qp->priv;
463 struct ib_wc wc;
464 int ret = 0;
465
466 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET)
467 goto bail;
468
469 qp->state = IB_QPS_ERR;
470
471 if (qp->s_flags & (HFI1_S_TIMER | HFI1_S_WAIT_RNR)) {
472 qp->s_flags &= ~(HFI1_S_TIMER | HFI1_S_WAIT_RNR);
473 del_timer(&qp->s_timer);
474 }
475
476 if (qp->s_flags & HFI1_S_ANY_WAIT_SEND)
477 qp->s_flags &= ~HFI1_S_ANY_WAIT_SEND;
478
479 write_seqlock(&dev->iowait_lock);
480 if (!list_empty(&qp->s_iowait.list) && !(qp->s_flags & HFI1_S_BUSY)) {
481 qp->s_flags &= ~HFI1_S_ANY_WAIT_IO;
482 list_del_init(&qp->s_iowait.list);
483 if (atomic_dec_and_test(&qp->refcount))
484 wake_up(&qp->wait);
485 }
486 write_sequnlock(&dev->iowait_lock);
487
488 if (!(qp->s_flags & HFI1_S_BUSY)) {
489 qp->s_hdrwords = 0;
490 if (qp->s_rdma_mr) {
491 hfi1_put_mr(qp->s_rdma_mr);
492 qp->s_rdma_mr = NULL;
493 }
494 flush_tx_list(qp);
495 }
496
497 /* Schedule the sending tasklet to drain the send work queue. */
498 if (qp->s_last != qp->s_head)
499 hfi1_schedule_send(qp);
500
501 clear_mr_refs(qp, 0);
502
503 memset(&wc, 0, sizeof(wc));
504 wc.qp = &qp->ibqp;
505 wc.opcode = IB_WC_RECV;
506
507 if (test_and_clear_bit(HFI1_R_WRID_VALID, &qp->r_aflags)) {
508 wc.wr_id = qp->r_wr_id;
509 wc.status = err;
510 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
511 }
512 wc.status = IB_WC_WR_FLUSH_ERR;
513 122
514 if (qp->r_rq.wq) { 123 while (!list_empty(&priv->s_iowait.tx_head)) {
515 struct hfi1_rwq *wq;
516 u32 head;
517 u32 tail;
518
519 spin_lock(&qp->r_rq.lock);
520
521 /* sanity check pointers before trusting them */
522 wq = qp->r_rq.wq;
523 head = wq->head;
524 if (head >= qp->r_rq.size)
525 head = 0;
526 tail = wq->tail;
527 if (tail >= qp->r_rq.size)
528 tail = 0;
529 while (tail != head) {
530 wc.wr_id = get_rwqe_ptr(&qp->r_rq, tail)->wr_id;
531 if (++tail >= qp->r_rq.size)
532 tail = 0;
533 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
534 }
535 wq->tail = tail;
536
537 spin_unlock(&qp->r_rq.lock);
538 } else if (qp->ibqp.event_handler)
539 ret = 1;
540
541bail:
542 return ret;
543}
544
545static void flush_tx_list(struct hfi1_qp *qp)
546{
547 while (!list_empty(&qp->s_iowait.tx_head)) {
548 struct sdma_txreq *tx; 124 struct sdma_txreq *tx;
549 125
550 tx = list_first_entry( 126 tx = list_first_entry(
551 &qp->s_iowait.tx_head, 127 &priv->s_iowait.tx_head,
552 struct sdma_txreq, 128 struct sdma_txreq,
553 list); 129 list);
554 list_del_init(&tx->list); 130 list_del_init(&tx->list);
@@ -557,14 +133,15 @@ static void flush_tx_list(struct hfi1_qp *qp)
557 } 133 }
558} 134}
559 135
560static void flush_iowait(struct hfi1_qp *qp) 136static void flush_iowait(struct rvt_qp *qp)
561{ 137{
138 struct hfi1_qp_priv *priv = qp->priv;
562 struct hfi1_ibdev *dev = to_idev(qp->ibqp.device); 139 struct hfi1_ibdev *dev = to_idev(qp->ibqp.device);
563 unsigned long flags; 140 unsigned long flags;
564 141
565 write_seqlock_irqsave(&dev->iowait_lock, flags); 142 write_seqlock_irqsave(&dev->iowait_lock, flags);
566 if (!list_empty(&qp->s_iowait.list)) { 143 if (!list_empty(&priv->s_iowait.list)) {
567 list_del_init(&qp->s_iowait.list); 144 list_del_init(&priv->s_iowait.list);
568 if (atomic_dec_and_test(&qp->refcount)) 145 if (atomic_dec_and_test(&qp->refcount))
569 wake_up(&qp->wait); 146 wake_up(&qp->wait);
570 } 147 }
@@ -597,362 +174,106 @@ static inline int verbs_mtu_enum_to_int(struct ib_device *dev, enum ib_mtu mtu)
597 return ib_mtu_enum_to_int(mtu); 174 return ib_mtu_enum_to_int(mtu);
598} 175}
599 176
600 177int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
601/** 178 int attr_mask, struct ib_udata *udata)
602 * hfi1_modify_qp - modify the attributes of a queue pair
603 * @ibqp: the queue pair who's attributes we're modifying
604 * @attr: the new attributes
605 * @attr_mask: the mask of attributes to modify
606 * @udata: user data for libibverbs.so
607 *
608 * Returns 0 on success, otherwise returns an errno.
609 */
610int hfi1_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
611 int attr_mask, struct ib_udata *udata)
612{ 179{
180 struct ib_qp *ibqp = &qp->ibqp;
613 struct hfi1_ibdev *dev = to_idev(ibqp->device); 181 struct hfi1_ibdev *dev = to_idev(ibqp->device);
614 struct hfi1_qp *qp = to_iqp(ibqp);
615 enum ib_qp_state cur_state, new_state;
616 struct ib_event ev;
617 int lastwqe = 0;
618 int mig = 0;
619 int ret;
620 u32 pmtu = 0; /* for gcc warning only */
621 struct hfi1_devdata *dd = dd_from_dev(dev); 182 struct hfi1_devdata *dd = dd_from_dev(dev);
622 183 u8 sc;
623 spin_lock_irq(&qp->r_lock);
624 spin_lock(&qp->s_lock);
625
626 cur_state = attr_mask & IB_QP_CUR_STATE ?
627 attr->cur_qp_state : qp->state;
628 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
629
630 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
631 attr_mask, IB_LINK_LAYER_UNSPECIFIED))
632 goto inval;
633 184
634 if (attr_mask & IB_QP_AV) { 185 if (attr_mask & IB_QP_AV) {
635 u8 sc;
636
637 if (attr->ah_attr.dlid >= HFI1_MULTICAST_LID_BASE)
638 goto inval;
639 if (hfi1_check_ah(qp->ibqp.device, &attr->ah_attr))
640 goto inval;
641 sc = ah_to_sc(ibqp->device, &attr->ah_attr); 186 sc = ah_to_sc(ibqp->device, &attr->ah_attr);
187 if (sc == 0xf)
188 return -EINVAL;
189
642 if (!qp_to_sdma_engine(qp, sc) && 190 if (!qp_to_sdma_engine(qp, sc) &&
643 dd->flags & HFI1_HAS_SEND_DMA) 191 dd->flags & HFI1_HAS_SEND_DMA)
644 goto inval; 192 return -EINVAL;
193
194 if (!qp_to_send_context(qp, sc))
195 return -EINVAL;
645 } 196 }
646 197
647 if (attr_mask & IB_QP_ALT_PATH) { 198 if (attr_mask & IB_QP_ALT_PATH) {
648 u8 sc;
649
650 if (attr->alt_ah_attr.dlid >= HFI1_MULTICAST_LID_BASE)
651 goto inval;
652 if (hfi1_check_ah(qp->ibqp.device, &attr->alt_ah_attr))
653 goto inval;
654 if (attr->alt_pkey_index >= hfi1_get_npkeys(dd))
655 goto inval;
656 sc = ah_to_sc(ibqp->device, &attr->alt_ah_attr); 199 sc = ah_to_sc(ibqp->device, &attr->alt_ah_attr);
200 if (sc == 0xf)
201 return -EINVAL;
202
657 if (!qp_to_sdma_engine(qp, sc) && 203 if (!qp_to_sdma_engine(qp, sc) &&
658 dd->flags & HFI1_HAS_SEND_DMA) 204 dd->flags & HFI1_HAS_SEND_DMA)
659 goto inval; 205 return -EINVAL;
660 }
661
662 if (attr_mask & IB_QP_PKEY_INDEX)
663 if (attr->pkey_index >= hfi1_get_npkeys(dd))
664 goto inval;
665
666 if (attr_mask & IB_QP_MIN_RNR_TIMER)
667 if (attr->min_rnr_timer > 31)
668 goto inval;
669 206
670 if (attr_mask & IB_QP_PORT) 207 if (!qp_to_send_context(qp, sc))
671 if (qp->ibqp.qp_type == IB_QPT_SMI || 208 return -EINVAL;
672 qp->ibqp.qp_type == IB_QPT_GSI || 209 }
673 attr->port_num == 0 ||
674 attr->port_num > ibqp->device->phys_port_cnt)
675 goto inval;
676
677 if (attr_mask & IB_QP_DEST_QPN)
678 if (attr->dest_qp_num > HFI1_QPN_MASK)
679 goto inval;
680 210
681 if (attr_mask & IB_QP_RETRY_CNT) 211 return 0;
682 if (attr->retry_cnt > 7) 212}
683 goto inval;
684 213
685 if (attr_mask & IB_QP_RNR_RETRY) 214void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
686 if (attr->rnr_retry > 7) 215 int attr_mask, struct ib_udata *udata)
687 goto inval; 216{
217 struct ib_qp *ibqp = &qp->ibqp;
218 struct hfi1_qp_priv *priv = qp->priv;
688 219
689 /* 220 if (attr_mask & IB_QP_AV) {
690 * Don't allow invalid path_mtu values. OK to set greater 221 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
691 * than the active mtu (or even the max_cap, if we have tuned 222 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
692 * that to a small mtu. We'll set qp->path_mtu 223 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
693 * to the lesser of requested attribute mtu and active,
694 * for packetizing messages.
695 * Note that the QP port has to be set in INIT and MTU in RTR.
696 */
697 if (attr_mask & IB_QP_PATH_MTU) {
698 int mtu, pidx = qp->port_num - 1;
699
700 dd = dd_from_dev(dev);
701 mtu = verbs_mtu_enum_to_int(ibqp->device, attr->path_mtu);
702 if (mtu == -1)
703 goto inval;
704
705 if (mtu > dd->pport[pidx].ibmtu)
706 pmtu = mtu_to_enum(dd->pport[pidx].ibmtu, IB_MTU_2048);
707 else
708 pmtu = attr->path_mtu;
709 } 224 }
710 225
711 if (attr_mask & IB_QP_PATH_MIG_STATE) { 226 if (attr_mask & IB_QP_PATH_MIG_STATE &&
712 if (attr->path_mig_state == IB_MIG_REARM) { 227 attr->path_mig_state == IB_MIG_MIGRATED &&
713 if (qp->s_mig_state == IB_MIG_ARMED) 228 qp->s_mig_state == IB_MIG_ARMED) {
714 goto inval; 229 qp->s_flags |= RVT_S_AHG_CLEAR;
715 if (new_state != IB_QPS_RTS) 230 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
716 goto inval; 231 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
717 } else if (attr->path_mig_state == IB_MIG_MIGRATED) { 232 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
718 if (qp->s_mig_state == IB_MIG_REARM)
719 goto inval;
720 if (new_state != IB_QPS_RTS && new_state != IB_QPS_SQD)
721 goto inval;
722 if (qp->s_mig_state == IB_MIG_ARMED)
723 mig = 1;
724 } else
725 goto inval;
726 } 233 }
234}
727 235
728 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) 236/**
729 if (attr->max_dest_rd_atomic > HFI1_MAX_RDMA_ATOMIC) 237 * hfi1_check_send_wqe - validate wqe
730 goto inval; 238 * @qp - The qp
731 239 * @wqe - The built wqe
732 switch (new_state) { 240 *
733 case IB_QPS_RESET: 241 * validate wqe. This is called
734 if (qp->state != IB_QPS_RESET) { 242 * prior to inserting the wqe into
735 qp->state = IB_QPS_RESET; 243 * the ring but after the wqe has been
736 flush_iowait(qp); 244 * setup.
737 qp->s_flags &= ~(HFI1_S_TIMER | HFI1_S_ANY_WAIT); 245 *
738 spin_unlock(&qp->s_lock); 246 * Returns 0 on success, -EINVAL on failure
739 spin_unlock_irq(&qp->r_lock); 247 *
740 /* Stop the sending work queue and retry timer */ 248 */
741 cancel_work_sync(&qp->s_iowait.iowork); 249int hfi1_check_send_wqe(struct rvt_qp *qp,
742 del_timer_sync(&qp->s_timer); 250 struct rvt_swqe *wqe)
743 iowait_sdma_drain(&qp->s_iowait); 251{
744 flush_tx_list(qp); 252 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
745 remove_qp(dev, qp); 253 struct rvt_ah *ah;
746 wait_event(qp->wait, !atomic_read(&qp->refcount));
747 spin_lock_irq(&qp->r_lock);
748 spin_lock(&qp->s_lock);
749 clear_mr_refs(qp, 1);
750 clear_ahg(qp);
751 reset_qp(qp, ibqp->qp_type);
752 }
753 break;
754
755 case IB_QPS_RTR:
756 /* Allow event to re-trigger if QP set to RTR more than once */
757 qp->r_flags &= ~HFI1_R_COMM_EST;
758 qp->state = new_state;
759 break;
760
761 case IB_QPS_SQD:
762 qp->s_draining = qp->s_last != qp->s_cur;
763 qp->state = new_state;
764 break;
765 254
766 case IB_QPS_SQE: 255 switch (qp->ibqp.qp_type) {
767 if (qp->ibqp.qp_type == IB_QPT_RC) 256 case IB_QPT_RC:
768 goto inval; 257 case IB_QPT_UC:
769 qp->state = new_state; 258 if (wqe->length > 0x80000000U)
259 return -EINVAL;
770 break; 260 break;
771 261 case IB_QPT_SMI:
772 case IB_QPS_ERR: 262 ah = ibah_to_rvtah(wqe->ud_wr.ah);
773 lastwqe = hfi1_error_qp(qp, IB_WC_WR_FLUSH_ERR); 263 if (wqe->length > (1 << ah->log_pmtu))
264 return -EINVAL;
774 break; 265 break;
775 266 case IB_QPT_GSI:
267 case IB_QPT_UD:
268 ah = ibah_to_rvtah(wqe->ud_wr.ah);
269 if (wqe->length > (1 << ah->log_pmtu))
270 return -EINVAL;
271 if (ibp->sl_to_sc[ah->attr.sl] == 0xf)
272 return -EINVAL;
776 default: 273 default:
777 qp->state = new_state;
778 break; 274 break;
779 } 275 }
780 276 return wqe->length <= piothreshold;
781 if (attr_mask & IB_QP_PKEY_INDEX)
782 qp->s_pkey_index = attr->pkey_index;
783
784 if (attr_mask & IB_QP_PORT)
785 qp->port_num = attr->port_num;
786
787 if (attr_mask & IB_QP_DEST_QPN)
788 qp->remote_qpn = attr->dest_qp_num;
789
790 if (attr_mask & IB_QP_SQ_PSN) {
791 qp->s_next_psn = attr->sq_psn & PSN_MODIFY_MASK;
792 qp->s_psn = qp->s_next_psn;
793 qp->s_sending_psn = qp->s_next_psn;
794 qp->s_last_psn = qp->s_next_psn - 1;
795 qp->s_sending_hpsn = qp->s_last_psn;
796 }
797
798 if (attr_mask & IB_QP_RQ_PSN)
799 qp->r_psn = attr->rq_psn & PSN_MODIFY_MASK;
800
801 if (attr_mask & IB_QP_ACCESS_FLAGS)
802 qp->qp_access_flags = attr->qp_access_flags;
803
804 if (attr_mask & IB_QP_AV) {
805 qp->remote_ah_attr = attr->ah_attr;
806 qp->s_srate = attr->ah_attr.static_rate;
807 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate);
808 qp->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
809 qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc);
810 }
811
812 if (attr_mask & IB_QP_ALT_PATH) {
813 qp->alt_ah_attr = attr->alt_ah_attr;
814 qp->s_alt_pkey_index = attr->alt_pkey_index;
815 }
816
817 if (attr_mask & IB_QP_PATH_MIG_STATE) {
818 qp->s_mig_state = attr->path_mig_state;
819 if (mig) {
820 qp->remote_ah_attr = qp->alt_ah_attr;
821 qp->port_num = qp->alt_ah_attr.port_num;
822 qp->s_pkey_index = qp->s_alt_pkey_index;
823 qp->s_flags |= HFI1_S_AHG_CLEAR;
824 qp->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
825 qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc);
826 }
827 }
828
829 if (attr_mask & IB_QP_PATH_MTU) {
830 struct hfi1_ibport *ibp;
831 u8 sc, vl;
832 u32 mtu;
833
834 dd = dd_from_dev(dev);
835 ibp = &dd->pport[qp->port_num - 1].ibport_data;
836
837 sc = ibp->sl_to_sc[qp->remote_ah_attr.sl];
838 vl = sc_to_vlt(dd, sc);
839
840 mtu = verbs_mtu_enum_to_int(ibqp->device, pmtu);
841 if (vl < PER_VL_SEND_CONTEXTS)
842 mtu = min_t(u32, mtu, dd->vld[vl].mtu);
843 pmtu = mtu_to_enum(mtu, OPA_MTU_8192);
844
845 qp->path_mtu = pmtu;
846 qp->pmtu = mtu;
847 }
848
849 if (attr_mask & IB_QP_RETRY_CNT) {
850 qp->s_retry_cnt = attr->retry_cnt;
851 qp->s_retry = attr->retry_cnt;
852 }
853
854 if (attr_mask & IB_QP_RNR_RETRY) {
855 qp->s_rnr_retry_cnt = attr->rnr_retry;
856 qp->s_rnr_retry = attr->rnr_retry;
857 }
858
859 if (attr_mask & IB_QP_MIN_RNR_TIMER)
860 qp->r_min_rnr_timer = attr->min_rnr_timer;
861
862 if (attr_mask & IB_QP_TIMEOUT) {
863 qp->timeout = attr->timeout;
864 qp->timeout_jiffies =
865 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
866 1000UL);
867 }
868
869 if (attr_mask & IB_QP_QKEY)
870 qp->qkey = attr->qkey;
871
872 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
873 qp->r_max_rd_atomic = attr->max_dest_rd_atomic;
874
875 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
876 qp->s_max_rd_atomic = attr->max_rd_atomic;
877
878 spin_unlock(&qp->s_lock);
879 spin_unlock_irq(&qp->r_lock);
880
881 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
882 insert_qp(dev, qp);
883
884 if (lastwqe) {
885 ev.device = qp->ibqp.device;
886 ev.element.qp = &qp->ibqp;
887 ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
888 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
889 }
890 if (mig) {
891 ev.device = qp->ibqp.device;
892 ev.element.qp = &qp->ibqp;
893 ev.event = IB_EVENT_PATH_MIG;
894 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
895 }
896 ret = 0;
897 goto bail;
898
899inval:
900 spin_unlock(&qp->s_lock);
901 spin_unlock_irq(&qp->r_lock);
902 ret = -EINVAL;
903
904bail:
905 return ret;
906}
907
908int hfi1_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
909 int attr_mask, struct ib_qp_init_attr *init_attr)
910{
911 struct hfi1_qp *qp = to_iqp(ibqp);
912
913 attr->qp_state = qp->state;
914 attr->cur_qp_state = attr->qp_state;
915 attr->path_mtu = qp->path_mtu;
916 attr->path_mig_state = qp->s_mig_state;
917 attr->qkey = qp->qkey;
918 attr->rq_psn = mask_psn(qp->r_psn);
919 attr->sq_psn = mask_psn(qp->s_next_psn);
920 attr->dest_qp_num = qp->remote_qpn;
921 attr->qp_access_flags = qp->qp_access_flags;
922 attr->cap.max_send_wr = qp->s_size - 1;
923 attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1;
924 attr->cap.max_send_sge = qp->s_max_sge;
925 attr->cap.max_recv_sge = qp->r_rq.max_sge;
926 attr->cap.max_inline_data = 0;
927 attr->ah_attr = qp->remote_ah_attr;
928 attr->alt_ah_attr = qp->alt_ah_attr;
929 attr->pkey_index = qp->s_pkey_index;
930 attr->alt_pkey_index = qp->s_alt_pkey_index;
931 attr->en_sqd_async_notify = 0;
932 attr->sq_draining = qp->s_draining;
933 attr->max_rd_atomic = qp->s_max_rd_atomic;
934 attr->max_dest_rd_atomic = qp->r_max_rd_atomic;
935 attr->min_rnr_timer = qp->r_min_rnr_timer;
936 attr->port_num = qp->port_num;
937 attr->timeout = qp->timeout;
938 attr->retry_cnt = qp->s_retry_cnt;
939 attr->rnr_retry = qp->s_rnr_retry_cnt;
940 attr->alt_port_num = qp->alt_ah_attr.port_num;
941 attr->alt_timeout = qp->alt_timeout;
942
943 init_attr->event_handler = qp->ibqp.event_handler;
944 init_attr->qp_context = qp->ibqp.qp_context;
945 init_attr->send_cq = qp->ibqp.send_cq;
946 init_attr->recv_cq = qp->ibqp.recv_cq;
947 init_attr->srq = qp->ibqp.srq;
948 init_attr->cap = attr->cap;
949 if (qp->s_flags & HFI1_S_SIGNAL_REQ_WR)
950 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR;
951 else
952 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR;
953 init_attr->qp_type = qp->ibqp.qp_type;
954 init_attr->port_num = qp->port_num;
955 return 0;
956} 277}
957 278
958/** 279/**
@@ -961,7 +282,7 @@ int hfi1_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
961 * 282 *
962 * Returns the AETH. 283 * Returns the AETH.
963 */ 284 */
964__be32 hfi1_compute_aeth(struct hfi1_qp *qp) 285__be32 hfi1_compute_aeth(struct rvt_qp *qp)
965{ 286{
966 u32 aeth = qp->r_msn & HFI1_MSN_MASK; 287 u32 aeth = qp->r_msn & HFI1_MSN_MASK;
967 288
@@ -974,7 +295,7 @@ __be32 hfi1_compute_aeth(struct hfi1_qp *qp)
974 } else { 295 } else {
975 u32 min, max, x; 296 u32 min, max, x;
976 u32 credits; 297 u32 credits;
977 struct hfi1_rwq *wq = qp->r_rq.wq; 298 struct rvt_rwq *wq = qp->r_rq.wq;
978 u32 head; 299 u32 head;
979 u32 tail; 300 u32 tail;
980 301
@@ -1004,12 +325,13 @@ __be32 hfi1_compute_aeth(struct hfi1_qp *qp)
1004 x = (min + max) / 2; 325 x = (min + max) / 2;
1005 if (credit_table[x] == credits) 326 if (credit_table[x] == credits)
1006 break; 327 break;
1007 if (credit_table[x] > credits) 328 if (credit_table[x] > credits) {
1008 max = x; 329 max = x;
1009 else if (min == x) 330 } else {
1010 break; 331 if (min == x)
1011 else 332 break;
1012 min = x; 333 min = x;
334 }
1013 } 335 }
1014 aeth |= x << HFI1_AETH_CREDIT_SHIFT; 336 aeth |= x << HFI1_AETH_CREDIT_SHIFT;
1015 } 337 }
@@ -1017,348 +339,58 @@ __be32 hfi1_compute_aeth(struct hfi1_qp *qp)
1017} 339}
1018 340
1019/** 341/**
1020 * hfi1_create_qp - create a queue pair for a device 342 * _hfi1_schedule_send - schedule progress
1021 * @ibpd: the protection domain who's device we create the queue pair for 343 * @qp: the QP
1022 * @init_attr: the attributes of the queue pair
1023 * @udata: user data for libibverbs.so
1024 *
1025 * Returns the queue pair on success, otherwise returns an errno.
1026 *
1027 * Called by the ib_create_qp() core verbs function.
1028 */
1029struct ib_qp *hfi1_create_qp(struct ib_pd *ibpd,
1030 struct ib_qp_init_attr *init_attr,
1031 struct ib_udata *udata)
1032{
1033 struct hfi1_qp *qp;
1034 int err;
1035 struct hfi1_swqe *swq = NULL;
1036 struct hfi1_ibdev *dev;
1037 struct hfi1_devdata *dd;
1038 size_t sz;
1039 size_t sg_list_sz;
1040 struct ib_qp *ret;
1041
1042 if (init_attr->cap.max_send_sge > hfi1_max_sges ||
1043 init_attr->cap.max_send_wr > hfi1_max_qp_wrs ||
1044 init_attr->create_flags) {
1045 ret = ERR_PTR(-EINVAL);
1046 goto bail;
1047 }
1048
1049 /* Check receive queue parameters if no SRQ is specified. */
1050 if (!init_attr->srq) {
1051 if (init_attr->cap.max_recv_sge > hfi1_max_sges ||
1052 init_attr->cap.max_recv_wr > hfi1_max_qp_wrs) {
1053 ret = ERR_PTR(-EINVAL);
1054 goto bail;
1055 }
1056 if (init_attr->cap.max_send_sge +
1057 init_attr->cap.max_send_wr +
1058 init_attr->cap.max_recv_sge +
1059 init_attr->cap.max_recv_wr == 0) {
1060 ret = ERR_PTR(-EINVAL);
1061 goto bail;
1062 }
1063 }
1064
1065 switch (init_attr->qp_type) {
1066 case IB_QPT_SMI:
1067 case IB_QPT_GSI:
1068 if (init_attr->port_num == 0 ||
1069 init_attr->port_num > ibpd->device->phys_port_cnt) {
1070 ret = ERR_PTR(-EINVAL);
1071 goto bail;
1072 }
1073 case IB_QPT_UC:
1074 case IB_QPT_RC:
1075 case IB_QPT_UD:
1076 sz = sizeof(struct hfi1_sge) *
1077 init_attr->cap.max_send_sge +
1078 sizeof(struct hfi1_swqe);
1079 swq = vmalloc((init_attr->cap.max_send_wr + 1) * sz);
1080 if (swq == NULL) {
1081 ret = ERR_PTR(-ENOMEM);
1082 goto bail;
1083 }
1084 sz = sizeof(*qp);
1085 sg_list_sz = 0;
1086 if (init_attr->srq) {
1087 struct hfi1_srq *srq = to_isrq(init_attr->srq);
1088
1089 if (srq->rq.max_sge > 1)
1090 sg_list_sz = sizeof(*qp->r_sg_list) *
1091 (srq->rq.max_sge - 1);
1092 } else if (init_attr->cap.max_recv_sge > 1)
1093 sg_list_sz = sizeof(*qp->r_sg_list) *
1094 (init_attr->cap.max_recv_sge - 1);
1095 qp = kzalloc(sz + sg_list_sz, GFP_KERNEL);
1096 if (!qp) {
1097 ret = ERR_PTR(-ENOMEM);
1098 goto bail_swq;
1099 }
1100 RCU_INIT_POINTER(qp->next, NULL);
1101 qp->s_hdr = kzalloc(sizeof(*qp->s_hdr), GFP_KERNEL);
1102 if (!qp->s_hdr) {
1103 ret = ERR_PTR(-ENOMEM);
1104 goto bail_qp;
1105 }
1106 qp->timeout_jiffies =
1107 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
1108 1000UL);
1109 if (init_attr->srq)
1110 sz = 0;
1111 else {
1112 qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
1113 qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
1114 sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) +
1115 sizeof(struct hfi1_rwqe);
1116 qp->r_rq.wq = vmalloc_user(sizeof(struct hfi1_rwq) +
1117 qp->r_rq.size * sz);
1118 if (!qp->r_rq.wq) {
1119 ret = ERR_PTR(-ENOMEM);
1120 goto bail_qp;
1121 }
1122 }
1123
1124 /*
1125 * ib_create_qp() will initialize qp->ibqp
1126 * except for qp->ibqp.qp_num.
1127 */
1128 spin_lock_init(&qp->r_lock);
1129 spin_lock_init(&qp->s_lock);
1130 spin_lock_init(&qp->r_rq.lock);
1131 atomic_set(&qp->refcount, 0);
1132 init_waitqueue_head(&qp->wait);
1133 init_timer(&qp->s_timer);
1134 qp->s_timer.data = (unsigned long)qp;
1135 INIT_LIST_HEAD(&qp->rspwait);
1136 qp->state = IB_QPS_RESET;
1137 qp->s_wq = swq;
1138 qp->s_size = init_attr->cap.max_send_wr + 1;
1139 qp->s_max_sge = init_attr->cap.max_send_sge;
1140 if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR)
1141 qp->s_flags = HFI1_S_SIGNAL_REQ_WR;
1142 dev = to_idev(ibpd->device);
1143 dd = dd_from_dev(dev);
1144 err = alloc_qpn(dd, &dev->qp_dev->qpn_table, init_attr->qp_type,
1145 init_attr->port_num);
1146 if (err < 0) {
1147 ret = ERR_PTR(err);
1148 vfree(qp->r_rq.wq);
1149 goto bail_qp;
1150 }
1151 qp->ibqp.qp_num = err;
1152 qp->port_num = init_attr->port_num;
1153 reset_qp(qp, init_attr->qp_type);
1154
1155 break;
1156
1157 default:
1158 /* Don't support raw QPs */
1159 ret = ERR_PTR(-ENOSYS);
1160 goto bail;
1161 }
1162
1163 init_attr->cap.max_inline_data = 0;
1164
1165 /*
1166 * Return the address of the RWQ as the offset to mmap.
1167 * See hfi1_mmap() for details.
1168 */
1169 if (udata && udata->outlen >= sizeof(__u64)) {
1170 if (!qp->r_rq.wq) {
1171 __u64 offset = 0;
1172
1173 err = ib_copy_to_udata(udata, &offset,
1174 sizeof(offset));
1175 if (err) {
1176 ret = ERR_PTR(err);
1177 goto bail_ip;
1178 }
1179 } else {
1180 u32 s = sizeof(struct hfi1_rwq) + qp->r_rq.size * sz;
1181
1182 qp->ip = hfi1_create_mmap_info(dev, s,
1183 ibpd->uobject->context,
1184 qp->r_rq.wq);
1185 if (!qp->ip) {
1186 ret = ERR_PTR(-ENOMEM);
1187 goto bail_ip;
1188 }
1189
1190 err = ib_copy_to_udata(udata, &(qp->ip->offset),
1191 sizeof(qp->ip->offset));
1192 if (err) {
1193 ret = ERR_PTR(err);
1194 goto bail_ip;
1195 }
1196 }
1197 }
1198
1199 spin_lock(&dev->n_qps_lock);
1200 if (dev->n_qps_allocated == hfi1_max_qps) {
1201 spin_unlock(&dev->n_qps_lock);
1202 ret = ERR_PTR(-ENOMEM);
1203 goto bail_ip;
1204 }
1205
1206 dev->n_qps_allocated++;
1207 spin_unlock(&dev->n_qps_lock);
1208
1209 if (qp->ip) {
1210 spin_lock_irq(&dev->pending_lock);
1211 list_add(&qp->ip->pending_mmaps, &dev->pending_mmaps);
1212 spin_unlock_irq(&dev->pending_lock);
1213 }
1214
1215 ret = &qp->ibqp;
1216
1217 /*
1218 * We have our QP and its good, now keep track of what types of opcodes
1219 * can be processed on this QP. We do this by keeping track of what the
1220 * 3 high order bits of the opcode are.
1221 */
1222 switch (init_attr->qp_type) {
1223 case IB_QPT_SMI:
1224 case IB_QPT_GSI:
1225 case IB_QPT_UD:
1226 qp->allowed_ops = IB_OPCODE_UD_SEND_ONLY & OPCODE_QP_MASK;
1227 break;
1228 case IB_QPT_RC:
1229 qp->allowed_ops = IB_OPCODE_RC_SEND_ONLY & OPCODE_QP_MASK;
1230 break;
1231 case IB_QPT_UC:
1232 qp->allowed_ops = IB_OPCODE_UC_SEND_ONLY & OPCODE_QP_MASK;
1233 break;
1234 default:
1235 ret = ERR_PTR(-EINVAL);
1236 goto bail_ip;
1237 }
1238
1239 goto bail;
1240
1241bail_ip:
1242 if (qp->ip)
1243 kref_put(&qp->ip->ref, hfi1_release_mmap_info);
1244 else
1245 vfree(qp->r_rq.wq);
1246 free_qpn(&dev->qp_dev->qpn_table, qp->ibqp.qp_num);
1247bail_qp:
1248 kfree(qp->s_hdr);
1249 kfree(qp);
1250bail_swq:
1251 vfree(swq);
1252bail:
1253 return ret;
1254}
1255
1256/**
1257 * hfi1_destroy_qp - destroy a queue pair
1258 * @ibqp: the queue pair to destroy
1259 * 344 *
1260 * Returns 0 on success. 345 * This schedules qp progress w/o regard to the s_flags.
1261 * 346 *
1262 * Note that this can be called while the QP is actively sending or 347 * It is only used in the post send, which doesn't hold
1263 * receiving! 348 * the s_lock.
1264 */ 349 */
1265int hfi1_destroy_qp(struct ib_qp *ibqp) 350void _hfi1_schedule_send(struct rvt_qp *qp)
1266{ 351{
1267 struct hfi1_qp *qp = to_iqp(ibqp); 352 struct hfi1_qp_priv *priv = qp->priv;
1268 struct hfi1_ibdev *dev = to_idev(ibqp->device); 353 struct hfi1_ibport *ibp =
1269 354 to_iport(qp->ibqp.device, qp->port_num);
1270 /* Make sure HW and driver activity is stopped. */ 355 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1271 spin_lock_irq(&qp->r_lock); 356 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1272 spin_lock(&qp->s_lock);
1273 if (qp->state != IB_QPS_RESET) {
1274 qp->state = IB_QPS_RESET;
1275 flush_iowait(qp);
1276 qp->s_flags &= ~(HFI1_S_TIMER | HFI1_S_ANY_WAIT);
1277 spin_unlock(&qp->s_lock);
1278 spin_unlock_irq(&qp->r_lock);
1279 cancel_work_sync(&qp->s_iowait.iowork);
1280 del_timer_sync(&qp->s_timer);
1281 iowait_sdma_drain(&qp->s_iowait);
1282 flush_tx_list(qp);
1283 remove_qp(dev, qp);
1284 wait_event(qp->wait, !atomic_read(&qp->refcount));
1285 spin_lock_irq(&qp->r_lock);
1286 spin_lock(&qp->s_lock);
1287 clear_mr_refs(qp, 1);
1288 clear_ahg(qp);
1289 }
1290 spin_unlock(&qp->s_lock);
1291 spin_unlock_irq(&qp->r_lock);
1292
1293 /* all user's cleaned up, mark it available */
1294 free_qpn(&dev->qp_dev->qpn_table, qp->ibqp.qp_num);
1295 spin_lock(&dev->n_qps_lock);
1296 dev->n_qps_allocated--;
1297 spin_unlock(&dev->n_qps_lock);
1298 357
1299 if (qp->ip) 358 iowait_schedule(&priv->s_iowait, ppd->hfi1_wq,
1300 kref_put(&qp->ip->ref, hfi1_release_mmap_info); 359 priv->s_sde ?
1301 else 360 priv->s_sde->cpu :
1302 vfree(qp->r_rq.wq); 361 cpumask_first(cpumask_of_node(dd->node)));
1303 vfree(qp->s_wq);
1304 kfree(qp->s_hdr);
1305 kfree(qp);
1306 return 0;
1307} 362}
1308 363
1309/** 364static void qp_pio_drain(struct rvt_qp *qp)
1310 * init_qpn_table - initialize the QP number table for a device
1311 * @qpt: the QPN table
1312 */
1313static int init_qpn_table(struct hfi1_devdata *dd, struct hfi1_qpn_table *qpt)
1314{ 365{
1315 u32 offset, qpn, i; 366 struct hfi1_ibdev *dev;
1316 struct qpn_map *map; 367 struct hfi1_qp_priv *priv = qp->priv;
1317 int ret = 0;
1318 368
1319 spin_lock_init(&qpt->lock); 369 if (!priv->s_sendcontext)
1320 370 return;
1321 qpt->last = 0; 371 dev = to_idev(qp->ibqp.device);
1322 qpt->incr = 1 << dd->qos_shift; 372 while (iowait_pio_pending(&priv->s_iowait)) {
1323 373 write_seqlock_irq(&dev->iowait_lock);
1324 /* insure we don't assign QPs from KDETH 64K window */ 374 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 1);
1325 qpn = kdeth_qp << 16; 375 write_sequnlock_irq(&dev->iowait_lock);
1326 qpt->nmaps = qpn / BITS_PER_PAGE; 376 iowait_pio_drain(&priv->s_iowait);
1327 /* This should always be zero */ 377 write_seqlock_irq(&dev->iowait_lock);
1328 offset = qpn & BITS_PER_PAGE_MASK; 378 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 0);
1329 map = &qpt->map[qpt->nmaps]; 379 write_sequnlock_irq(&dev->iowait_lock);
1330 dd_dev_info(dd, "Reserving QPNs for KDETH window from 0x%x to 0x%x\n",
1331 qpn, qpn + 65535);
1332 for (i = 0; i < 65536; i++) {
1333 if (!map->page) {
1334 get_map_page(qpt, map);
1335 if (!map->page) {
1336 ret = -ENOMEM;
1337 break;
1338 }
1339 }
1340 set_bit(offset, map->page);
1341 offset++;
1342 if (offset == BITS_PER_PAGE) {
1343 /* next page */
1344 qpt->nmaps++;
1345 map++;
1346 offset = 0;
1347 }
1348 } 380 }
1349 return ret;
1350} 381}
1351 382
1352/** 383/**
1353 * free_qpn_table - free the QP number table for a device 384 * hfi1_schedule_send - schedule progress
1354 * @qpt: the QPN table 385 * @qp: the QP
386 *
387 * This schedules qp progress and caller should hold
388 * the s_lock.
1355 */ 389 */
1356static void free_qpn_table(struct hfi1_qpn_table *qpt) 390void hfi1_schedule_send(struct rvt_qp *qp)
1357{ 391{
1358 int i; 392 if (hfi1_send_ok(qp))
1359 393 _hfi1_schedule_send(qp);
1360 for (i = 0; i < ARRAY_SIZE(qpt->map); i++)
1361 free_page((unsigned long) qpt->map[i].page);
1362} 394}
1363 395
1364/** 396/**
@@ -1368,7 +400,7 @@ static void free_qpn_table(struct hfi1_qpn_table *qpt)
1368 * 400 *
1369 * The QP s_lock should be held. 401 * The QP s_lock should be held.
1370 */ 402 */
1371void hfi1_get_credit(struct hfi1_qp *qp, u32 aeth) 403void hfi1_get_credit(struct rvt_qp *qp, u32 aeth)
1372{ 404{
1373 u32 credit = (aeth >> HFI1_AETH_CREDIT_SHIFT) & HFI1_AETH_CREDIT_MASK; 405 u32 credit = (aeth >> HFI1_AETH_CREDIT_SHIFT) & HFI1_AETH_CREDIT_MASK;
1374 406
@@ -1378,27 +410,27 @@ void hfi1_get_credit(struct hfi1_qp *qp, u32 aeth)
1378 * honor the credit field. 410 * honor the credit field.
1379 */ 411 */
1380 if (credit == HFI1_AETH_CREDIT_INVAL) { 412 if (credit == HFI1_AETH_CREDIT_INVAL) {
1381 if (!(qp->s_flags & HFI1_S_UNLIMITED_CREDIT)) { 413 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) {
1382 qp->s_flags |= HFI1_S_UNLIMITED_CREDIT; 414 qp->s_flags |= RVT_S_UNLIMITED_CREDIT;
1383 if (qp->s_flags & HFI1_S_WAIT_SSN_CREDIT) { 415 if (qp->s_flags & RVT_S_WAIT_SSN_CREDIT) {
1384 qp->s_flags &= ~HFI1_S_WAIT_SSN_CREDIT; 416 qp->s_flags &= ~RVT_S_WAIT_SSN_CREDIT;
1385 hfi1_schedule_send(qp); 417 hfi1_schedule_send(qp);
1386 } 418 }
1387 } 419 }
1388 } else if (!(qp->s_flags & HFI1_S_UNLIMITED_CREDIT)) { 420 } else if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) {
1389 /* Compute new LSN (i.e., MSN + credit) */ 421 /* Compute new LSN (i.e., MSN + credit) */
1390 credit = (aeth + credit_table[credit]) & HFI1_MSN_MASK; 422 credit = (aeth + credit_table[credit]) & HFI1_MSN_MASK;
1391 if (cmp_msn(credit, qp->s_lsn) > 0) { 423 if (cmp_msn(credit, qp->s_lsn) > 0) {
1392 qp->s_lsn = credit; 424 qp->s_lsn = credit;
1393 if (qp->s_flags & HFI1_S_WAIT_SSN_CREDIT) { 425 if (qp->s_flags & RVT_S_WAIT_SSN_CREDIT) {
1394 qp->s_flags &= ~HFI1_S_WAIT_SSN_CREDIT; 426 qp->s_flags &= ~RVT_S_WAIT_SSN_CREDIT;
1395 hfi1_schedule_send(qp); 427 hfi1_schedule_send(qp);
1396 } 428 }
1397 } 429 }
1398 } 430 }
1399} 431}
1400 432
1401void hfi1_qp_wakeup(struct hfi1_qp *qp, u32 flag) 433void hfi1_qp_wakeup(struct rvt_qp *qp, u32 flag)
1402{ 434{
1403 unsigned long flags; 435 unsigned long flags;
1404 436
@@ -1421,16 +453,17 @@ static int iowait_sleep(
1421 unsigned seq) 453 unsigned seq)
1422{ 454{
1423 struct verbs_txreq *tx = container_of(stx, struct verbs_txreq, txreq); 455 struct verbs_txreq *tx = container_of(stx, struct verbs_txreq, txreq);
1424 struct hfi1_qp *qp; 456 struct rvt_qp *qp;
457 struct hfi1_qp_priv *priv;
1425 unsigned long flags; 458 unsigned long flags;
1426 int ret = 0; 459 int ret = 0;
1427 struct hfi1_ibdev *dev; 460 struct hfi1_ibdev *dev;
1428 461
1429 qp = tx->qp; 462 qp = tx->qp;
463 priv = qp->priv;
1430 464
1431 spin_lock_irqsave(&qp->s_lock, flags); 465 spin_lock_irqsave(&qp->s_lock, flags);
1432 if (ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK) { 466 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
1433
1434 /* 467 /*
1435 * If we couldn't queue the DMA request, save the info 468 * If we couldn't queue the DMA request, save the info
1436 * and try again later rather than destroying the 469 * and try again later rather than destroying the
@@ -1442,18 +475,18 @@ static int iowait_sleep(
1442 write_seqlock(&dev->iowait_lock); 475 write_seqlock(&dev->iowait_lock);
1443 if (sdma_progress(sde, seq, stx)) 476 if (sdma_progress(sde, seq, stx))
1444 goto eagain; 477 goto eagain;
1445 if (list_empty(&qp->s_iowait.list)) { 478 if (list_empty(&priv->s_iowait.list)) {
1446 struct hfi1_ibport *ibp = 479 struct hfi1_ibport *ibp =
1447 to_iport(qp->ibqp.device, qp->port_num); 480 to_iport(qp->ibqp.device, qp->port_num);
1448 481
1449 ibp->n_dmawait++; 482 ibp->rvp.n_dmawait++;
1450 qp->s_flags |= HFI1_S_WAIT_DMA_DESC; 483 qp->s_flags |= RVT_S_WAIT_DMA_DESC;
1451 list_add_tail(&qp->s_iowait.list, &sde->dmawait); 484 list_add_tail(&priv->s_iowait.list, &sde->dmawait);
1452 trace_hfi1_qpsleep(qp, HFI1_S_WAIT_DMA_DESC); 485 trace_hfi1_qpsleep(qp, RVT_S_WAIT_DMA_DESC);
1453 atomic_inc(&qp->refcount); 486 atomic_inc(&qp->refcount);
1454 } 487 }
1455 write_sequnlock(&dev->iowait_lock); 488 write_sequnlock(&dev->iowait_lock);
1456 qp->s_flags &= ~HFI1_S_BUSY; 489 qp->s_flags &= ~RVT_S_BUSY;
1457 spin_unlock_irqrestore(&qp->s_lock, flags); 490 spin_unlock_irqrestore(&qp->s_lock, flags);
1458 ret = -EBUSY; 491 ret = -EBUSY;
1459 } else { 492 } else {
@@ -1470,61 +503,25 @@ eagain:
1470 503
1471static void iowait_wakeup(struct iowait *wait, int reason) 504static void iowait_wakeup(struct iowait *wait, int reason)
1472{ 505{
1473 struct hfi1_qp *qp = container_of(wait, struct hfi1_qp, s_iowait); 506 struct rvt_qp *qp = iowait_to_qp(wait);
1474 507
1475 WARN_ON(reason != SDMA_AVAIL_REASON); 508 WARN_ON(reason != SDMA_AVAIL_REASON);
1476 hfi1_qp_wakeup(qp, HFI1_S_WAIT_DMA_DESC); 509 hfi1_qp_wakeup(qp, RVT_S_WAIT_DMA_DESC);
1477} 510}
1478 511
1479int hfi1_qp_init(struct hfi1_ibdev *dev) 512static void iowait_sdma_drained(struct iowait *wait)
1480{ 513{
1481 struct hfi1_devdata *dd = dd_from_dev(dev); 514 struct rvt_qp *qp = iowait_to_qp(wait);
1482 int i;
1483 int ret = -ENOMEM;
1484
1485 /* allocate parent object */
1486 dev->qp_dev = kzalloc(sizeof(*dev->qp_dev), GFP_KERNEL);
1487 if (!dev->qp_dev)
1488 goto nomem;
1489 /* allocate hash table */
1490 dev->qp_dev->qp_table_size = hfi1_qp_table_size;
1491 dev->qp_dev->qp_table_bits = ilog2(hfi1_qp_table_size);
1492 dev->qp_dev->qp_table =
1493 kmalloc(dev->qp_dev->qp_table_size *
1494 sizeof(*dev->qp_dev->qp_table),
1495 GFP_KERNEL);
1496 if (!dev->qp_dev->qp_table)
1497 goto nomem;
1498 for (i = 0; i < dev->qp_dev->qp_table_size; i++)
1499 RCU_INIT_POINTER(dev->qp_dev->qp_table[i], NULL);
1500 spin_lock_init(&dev->qp_dev->qpt_lock);
1501 /* initialize qpn map */
1502 ret = init_qpn_table(dd, &dev->qp_dev->qpn_table);
1503 if (ret)
1504 goto nomem;
1505 return ret;
1506nomem:
1507 if (dev->qp_dev) {
1508 kfree(dev->qp_dev->qp_table);
1509 free_qpn_table(&dev->qp_dev->qpn_table);
1510 kfree(dev->qp_dev);
1511 }
1512 return ret;
1513}
1514 515
1515void hfi1_qp_exit(struct hfi1_ibdev *dev) 516 /*
1516{ 517 * This happens when the send engine notes
1517 struct hfi1_devdata *dd = dd_from_dev(dev); 518 * a QP in the error state and cannot
1518 u32 qps_inuse; 519 * do the flush work until that QP's
1519 520 * sdma work has finished.
1520 qps_inuse = free_all_qps(dd); 521 */
1521 if (qps_inuse) 522 if (qp->s_flags & RVT_S_WAIT_DMA) {
1522 dd_dev_err(dd, "QP memory leak! %u still in use\n", 523 qp->s_flags &= ~RVT_S_WAIT_DMA;
1523 qps_inuse); 524 hfi1_schedule_send(qp);
1524 if (dev->qp_dev) {
1525 kfree(dev->qp_dev->qp_table);
1526 free_qpn_table(&dev->qp_dev->qpn_table);
1527 kfree(dev->qp_dev);
1528 } 525 }
1529} 526}
1530 527
@@ -1537,7 +534,7 @@ void hfi1_qp_exit(struct hfi1_ibdev *dev)
1537 * Return: 534 * Return:
1538 * A send engine for the qp or NULL for SMI type qp. 535 * A send engine for the qp or NULL for SMI type qp.
1539 */ 536 */
1540struct sdma_engine *qp_to_sdma_engine(struct hfi1_qp *qp, u8 sc5) 537struct sdma_engine *qp_to_sdma_engine(struct rvt_qp *qp, u8 sc5)
1541{ 538{
1542 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); 539 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1543 struct sdma_engine *sde; 540 struct sdma_engine *sde;
@@ -1554,9 +551,33 @@ struct sdma_engine *qp_to_sdma_engine(struct hfi1_qp *qp, u8 sc5)
1554 return sde; 551 return sde;
1555} 552}
1556 553
554/*
555 * qp_to_send_context - map a qp to a send context
556 * @qp: the QP
557 * @sc5: the 5 bit sc
558 *
559 * Return:
560 * A send context for the qp
561 */
562struct send_context *qp_to_send_context(struct rvt_qp *qp, u8 sc5)
563{
564 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
565
566 switch (qp->ibqp.qp_type) {
567 case IB_QPT_SMI:
568 /* SMA packets to VL15 */
569 return dd->vld[15].sc;
570 default:
571 break;
572 }
573
574 return pio_select_send_context_sc(dd, qp->ibqp.qp_num >> dd->qos_shift,
575 sc5);
576}
577
1557struct qp_iter { 578struct qp_iter {
1558 struct hfi1_ibdev *dev; 579 struct hfi1_ibdev *dev;
1559 struct hfi1_qp *qp; 580 struct rvt_qp *qp;
1560 int specials; 581 int specials;
1561 int n; 582 int n;
1562}; 583};
@@ -1570,7 +591,7 @@ struct qp_iter *qp_iter_init(struct hfi1_ibdev *dev)
1570 return NULL; 591 return NULL;
1571 592
1572 iter->dev = dev; 593 iter->dev = dev;
1573 iter->specials = dev->ibdev.phys_port_cnt * 2; 594 iter->specials = dev->rdi.ibdev.phys_port_cnt * 2;
1574 if (qp_iter_next(iter)) { 595 if (qp_iter_next(iter)) {
1575 kfree(iter); 596 kfree(iter);
1576 return NULL; 597 return NULL;
@@ -1584,8 +605,8 @@ int qp_iter_next(struct qp_iter *iter)
1584 struct hfi1_ibdev *dev = iter->dev; 605 struct hfi1_ibdev *dev = iter->dev;
1585 int n = iter->n; 606 int n = iter->n;
1586 int ret = 1; 607 int ret = 1;
1587 struct hfi1_qp *pqp = iter->qp; 608 struct rvt_qp *pqp = iter->qp;
1588 struct hfi1_qp *qp; 609 struct rvt_qp *qp;
1589 610
1590 /* 611 /*
1591 * The approach is to consider the special qps 612 * The approach is to consider the special qps
@@ -1597,11 +618,11 @@ int qp_iter_next(struct qp_iter *iter)
1597 * 618 *
1598 * n = 0..iter->specials is the special qp indices 619 * n = 0..iter->specials is the special qp indices
1599 * 620 *
1600 * n = iter->specials..dev->qp_dev->qp_table_size+iter->specials are 621 * n = iter->specials..dev->rdi.qp_dev->qp_table_size+iter->specials are
1601 * the potential hash bucket entries 622 * the potential hash bucket entries
1602 * 623 *
1603 */ 624 */
1604 for (; n < dev->qp_dev->qp_table_size + iter->specials; n++) { 625 for (; n < dev->rdi.qp_dev->qp_table_size + iter->specials; n++) {
1605 if (pqp) { 626 if (pqp) {
1606 qp = rcu_dereference(pqp->next); 627 qp = rcu_dereference(pqp->next);
1607 } else { 628 } else {
@@ -1610,17 +631,17 @@ int qp_iter_next(struct qp_iter *iter)
1610 struct hfi1_ibport *ibp; 631 struct hfi1_ibport *ibp;
1611 int pidx; 632 int pidx;
1612 633
1613 pidx = n % dev->ibdev.phys_port_cnt; 634 pidx = n % dev->rdi.ibdev.phys_port_cnt;
1614 ppd = &dd_from_dev(dev)->pport[pidx]; 635 ppd = &dd_from_dev(dev)->pport[pidx];
1615 ibp = &ppd->ibport_data; 636 ibp = &ppd->ibport_data;
1616 637
1617 if (!(n & 1)) 638 if (!(n & 1))
1618 qp = rcu_dereference(ibp->qp[0]); 639 qp = rcu_dereference(ibp->rvp.qp[0]);
1619 else 640 else
1620 qp = rcu_dereference(ibp->qp[1]); 641 qp = rcu_dereference(ibp->rvp.qp[1]);
1621 } else { 642 } else {
1622 qp = rcu_dereference( 643 qp = rcu_dereference(
1623 dev->qp_dev->qp_table[ 644 dev->rdi.qp_dev->qp_table[
1624 (n - iter->specials)]); 645 (n - iter->specials)]);
1625 } 646 }
1626 } 647 }
@@ -1638,7 +659,7 @@ static const char * const qp_type_str[] = {
1638 "SMI", "GSI", "RC", "UC", "UD", 659 "SMI", "GSI", "RC", "UC", "UD",
1639}; 660};
1640 661
1641static int qp_idle(struct hfi1_qp *qp) 662static int qp_idle(struct rvt_qp *qp)
1642{ 663{
1643 return 664 return
1644 qp->s_last == qp->s_acked && 665 qp->s_last == qp->s_acked &&
@@ -1649,14 +670,17 @@ static int qp_idle(struct hfi1_qp *qp)
1649 670
1650void qp_iter_print(struct seq_file *s, struct qp_iter *iter) 671void qp_iter_print(struct seq_file *s, struct qp_iter *iter)
1651{ 672{
1652 struct hfi1_swqe *wqe; 673 struct rvt_swqe *wqe;
1653 struct hfi1_qp *qp = iter->qp; 674 struct rvt_qp *qp = iter->qp;
675 struct hfi1_qp_priv *priv = qp->priv;
1654 struct sdma_engine *sde; 676 struct sdma_engine *sde;
677 struct send_context *send_context;
1655 678
1656 sde = qp_to_sdma_engine(qp, qp->s_sc); 679 sde = qp_to_sdma_engine(qp, priv->s_sc);
1657 wqe = get_swqe_ptr(qp, qp->s_last); 680 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
681 send_context = qp_to_send_context(qp, priv->s_sc);
1658 seq_printf(s, 682 seq_printf(s,
1659 "N %d %s QP%u R %u %s %u %u %u f=%x %u %u %u %u %u PSN %x %x %x %x %x (%u %u %u %u %u %u) QP%u LID %x SL %u MTU %d %u %u %u SDE %p,%u\n", 683 "N %d %s QP %x R %u %s %u %u %u f=%x %u %u %u %u %u %u PSN %x %x %x %x %x (%u %u %u %u %u %u %u) RQP %x LID %x SL %u MTU %u %u %u %u SDE %p,%u SC %p,%u SCQ %u %u PID %d\n",
1660 iter->n, 684 iter->n,
1661 qp_idle(qp) ? "I" : "B", 685 qp_idle(qp) ? "I" : "B",
1662 qp->ibqp.qp_num, 686 qp->ibqp.qp_num,
@@ -1666,8 +690,9 @@ void qp_iter_print(struct seq_file *s, struct qp_iter *iter)
1666 wqe ? wqe->wr.opcode : 0, 690 wqe ? wqe->wr.opcode : 0,
1667 qp->s_hdrwords, 691 qp->s_hdrwords,
1668 qp->s_flags, 692 qp->s_flags,
1669 atomic_read(&qp->s_iowait.sdma_busy), 693 iowait_sdma_pending(&priv->s_iowait),
1670 !list_empty(&qp->s_iowait.list), 694 iowait_pio_pending(&priv->s_iowait),
695 !list_empty(&priv->s_iowait.list),
1671 qp->timeout, 696 qp->timeout,
1672 wqe ? wqe->ssn : 0, 697 wqe ? wqe->ssn : 0,
1673 qp->s_lsn, 698 qp->s_lsn,
@@ -1676,20 +701,26 @@ void qp_iter_print(struct seq_file *s, struct qp_iter *iter)
1676 qp->s_sending_psn, qp->s_sending_hpsn, 701 qp->s_sending_psn, qp->s_sending_hpsn,
1677 qp->s_last, qp->s_acked, qp->s_cur, 702 qp->s_last, qp->s_acked, qp->s_cur,
1678 qp->s_tail, qp->s_head, qp->s_size, 703 qp->s_tail, qp->s_head, qp->s_size,
704 qp->s_avail,
1679 qp->remote_qpn, 705 qp->remote_qpn,
1680 qp->remote_ah_attr.dlid, 706 qp->remote_ah_attr.dlid,
1681 qp->remote_ah_attr.sl, 707 qp->remote_ah_attr.sl,
1682 qp->pmtu, 708 qp->pmtu,
709 qp->s_retry,
1683 qp->s_retry_cnt, 710 qp->s_retry_cnt,
1684 qp->timeout,
1685 qp->s_rnr_retry_cnt, 711 qp->s_rnr_retry_cnt,
1686 sde, 712 sde,
1687 sde ? sde->this_idx : 0); 713 sde ? sde->this_idx : 0,
714 send_context,
715 send_context ? send_context->sw_index : 0,
716 ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->head,
717 ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->tail,
718 qp->pid);
1688} 719}
1689 720
1690void qp_comm_est(struct hfi1_qp *qp) 721void qp_comm_est(struct rvt_qp *qp)
1691{ 722{
1692 qp->r_flags |= HFI1_R_COMM_EST; 723 qp->r_flags |= RVT_R_COMM_EST;
1693 if (qp->ibqp.event_handler) { 724 if (qp->ibqp.event_handler) {
1694 struct ib_event ev; 725 struct ib_event ev;
1695 726
@@ -1700,24 +731,241 @@ void qp_comm_est(struct hfi1_qp *qp)
1700 } 731 }
1701} 732}
1702 733
734void *qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp,
735 gfp_t gfp)
736{
737 struct hfi1_qp_priv *priv;
738
739 priv = kzalloc_node(sizeof(*priv), gfp, rdi->dparms.node);
740 if (!priv)
741 return ERR_PTR(-ENOMEM);
742
743 priv->owner = qp;
744
745 priv->s_hdr = kzalloc_node(sizeof(*priv->s_hdr), gfp, rdi->dparms.node);
746 if (!priv->s_hdr) {
747 kfree(priv);
748 return ERR_PTR(-ENOMEM);
749 }
750 setup_timer(&priv->s_rnr_timer, hfi1_rc_rnr_retry, (unsigned long)qp);
751 qp->s_timer.function = hfi1_rc_timeout;
752 return priv;
753}
754
755void qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp)
756{
757 struct hfi1_qp_priv *priv = qp->priv;
758
759 kfree(priv->s_hdr);
760 kfree(priv);
761}
762
763unsigned free_all_qps(struct rvt_dev_info *rdi)
764{
765 struct hfi1_ibdev *verbs_dev = container_of(rdi,
766 struct hfi1_ibdev,
767 rdi);
768 struct hfi1_devdata *dd = container_of(verbs_dev,
769 struct hfi1_devdata,
770 verbs_dev);
771 int n;
772 unsigned qp_inuse = 0;
773
774 for (n = 0; n < dd->num_pports; n++) {
775 struct hfi1_ibport *ibp = &dd->pport[n].ibport_data;
776
777 rcu_read_lock();
778 if (rcu_dereference(ibp->rvp.qp[0]))
779 qp_inuse++;
780 if (rcu_dereference(ibp->rvp.qp[1]))
781 qp_inuse++;
782 rcu_read_unlock();
783 }
784
785 return qp_inuse;
786}
787
788void flush_qp_waiters(struct rvt_qp *qp)
789{
790 flush_iowait(qp);
791 hfi1_stop_rc_timers(qp);
792}
793
794void stop_send_queue(struct rvt_qp *qp)
795{
796 struct hfi1_qp_priv *priv = qp->priv;
797
798 cancel_work_sync(&priv->s_iowait.iowork);
799 hfi1_del_timers_sync(qp);
800}
801
802void quiesce_qp(struct rvt_qp *qp)
803{
804 struct hfi1_qp_priv *priv = qp->priv;
805
806 iowait_sdma_drain(&priv->s_iowait);
807 qp_pio_drain(qp);
808 flush_tx_list(qp);
809}
810
811void notify_qp_reset(struct rvt_qp *qp)
812{
813 struct hfi1_qp_priv *priv = qp->priv;
814
815 iowait_init(
816 &priv->s_iowait,
817 1,
818 _hfi1_do_send,
819 iowait_sleep,
820 iowait_wakeup,
821 iowait_sdma_drained);
822 priv->r_adefered = 0;
823 clear_ahg(qp);
824}
825
1703/* 826/*
1704 * Switch to alternate path. 827 * Switch to alternate path.
1705 * The QP s_lock should be held and interrupts disabled. 828 * The QP s_lock should be held and interrupts disabled.
1706 */ 829 */
1707void hfi1_migrate_qp(struct hfi1_qp *qp) 830void hfi1_migrate_qp(struct rvt_qp *qp)
1708{ 831{
832 struct hfi1_qp_priv *priv = qp->priv;
1709 struct ib_event ev; 833 struct ib_event ev;
1710 834
1711 qp->s_mig_state = IB_MIG_MIGRATED; 835 qp->s_mig_state = IB_MIG_MIGRATED;
1712 qp->remote_ah_attr = qp->alt_ah_attr; 836 qp->remote_ah_attr = qp->alt_ah_attr;
1713 qp->port_num = qp->alt_ah_attr.port_num; 837 qp->port_num = qp->alt_ah_attr.port_num;
1714 qp->s_pkey_index = qp->s_alt_pkey_index; 838 qp->s_pkey_index = qp->s_alt_pkey_index;
1715 qp->s_flags |= HFI1_S_AHG_CLEAR; 839 qp->s_flags |= RVT_S_AHG_CLEAR;
1716 qp->s_sc = ah_to_sc(qp->ibqp.device, &qp->remote_ah_attr); 840 priv->s_sc = ah_to_sc(qp->ibqp.device, &qp->remote_ah_attr);
1717 qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc); 841 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
1718 842
1719 ev.device = qp->ibqp.device; 843 ev.device = qp->ibqp.device;
1720 ev.element.qp = &qp->ibqp; 844 ev.element.qp = &qp->ibqp;
1721 ev.event = IB_EVENT_PATH_MIG; 845 ev.event = IB_EVENT_PATH_MIG;
1722 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); 846 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
1723} 847}
848
849int mtu_to_path_mtu(u32 mtu)
850{
851 return mtu_to_enum(mtu, OPA_MTU_8192);
852}
853
854u32 mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu)
855{
856 u32 mtu;
857 struct hfi1_ibdev *verbs_dev = container_of(rdi,
858 struct hfi1_ibdev,
859 rdi);
860 struct hfi1_devdata *dd = container_of(verbs_dev,
861 struct hfi1_devdata,
862 verbs_dev);
863 struct hfi1_ibport *ibp;
864 u8 sc, vl;
865
866 ibp = &dd->pport[qp->port_num - 1].ibport_data;
867 sc = ibp->sl_to_sc[qp->remote_ah_attr.sl];
868 vl = sc_to_vlt(dd, sc);
869
870 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, pmtu);
871 if (vl < PER_VL_SEND_CONTEXTS)
872 mtu = min_t(u32, mtu, dd->vld[vl].mtu);
873 return mtu;
874}
875
876int get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
877 struct ib_qp_attr *attr)
878{
879 int mtu, pidx = qp->port_num - 1;
880 struct hfi1_ibdev *verbs_dev = container_of(rdi,
881 struct hfi1_ibdev,
882 rdi);
883 struct hfi1_devdata *dd = container_of(verbs_dev,
884 struct hfi1_devdata,
885 verbs_dev);
886 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, attr->path_mtu);
887 if (mtu == -1)
888 return -1; /* values less than 0 are error */
889
890 if (mtu > dd->pport[pidx].ibmtu)
891 return mtu_to_enum(dd->pport[pidx].ibmtu, IB_MTU_2048);
892 else
893 return attr->path_mtu;
894}
895
896void notify_error_qp(struct rvt_qp *qp)
897{
898 struct hfi1_ibdev *dev = to_idev(qp->ibqp.device);
899 struct hfi1_qp_priv *priv = qp->priv;
900
901 write_seqlock(&dev->iowait_lock);
902 if (!list_empty(&priv->s_iowait.list) && !(qp->s_flags & RVT_S_BUSY)) {
903 qp->s_flags &= ~RVT_S_ANY_WAIT_IO;
904 list_del_init(&priv->s_iowait.list);
905 if (atomic_dec_and_test(&qp->refcount))
906 wake_up(&qp->wait);
907 }
908 write_sequnlock(&dev->iowait_lock);
909
910 if (!(qp->s_flags & RVT_S_BUSY)) {
911 qp->s_hdrwords = 0;
912 if (qp->s_rdma_mr) {
913 rvt_put_mr(qp->s_rdma_mr);
914 qp->s_rdma_mr = NULL;
915 }
916 flush_tx_list(qp);
917 }
918}
919
920/**
921 * hfi1_error_port_qps - put a port's RC/UC qps into error state
922 * @ibp: the ibport.
923 * @sl: the service level.
924 *
925 * This function places all RC/UC qps with a given service level into error
926 * state. It is generally called to force upper lay apps to abandon stale qps
927 * after an sl->sc mapping change.
928 */
929void hfi1_error_port_qps(struct hfi1_ibport *ibp, u8 sl)
930{
931 struct rvt_qp *qp = NULL;
932 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
933 struct hfi1_ibdev *dev = &ppd->dd->verbs_dev;
934 int n;
935 int lastwqe;
936 struct ib_event ev;
937
938 rcu_read_lock();
939
940 /* Deal only with RC/UC qps that use the given SL. */
941 for (n = 0; n < dev->rdi.qp_dev->qp_table_size; n++) {
942 for (qp = rcu_dereference(dev->rdi.qp_dev->qp_table[n]); qp;
943 qp = rcu_dereference(qp->next)) {
944 if (qp->port_num == ppd->port &&
945 (qp->ibqp.qp_type == IB_QPT_UC ||
946 qp->ibqp.qp_type == IB_QPT_RC) &&
947 qp->remote_ah_attr.sl == sl &&
948 (ib_rvt_state_ops[qp->state] &
949 RVT_POST_SEND_OK)) {
950 spin_lock_irq(&qp->r_lock);
951 spin_lock(&qp->s_hlock);
952 spin_lock(&qp->s_lock);
953 lastwqe = rvt_error_qp(qp,
954 IB_WC_WR_FLUSH_ERR);
955 spin_unlock(&qp->s_lock);
956 spin_unlock(&qp->s_hlock);
957 spin_unlock_irq(&qp->r_lock);
958 if (lastwqe) {
959 ev.device = qp->ibqp.device;
960 ev.element.qp = &qp->ibqp;
961 ev.event =
962 IB_EVENT_QP_LAST_WQE_REACHED;
963 qp->ibqp.event_handler(&ev,
964 qp->ibqp.qp_context);
965 }
966 }
967 }
968 }
969
970 rcu_read_unlock();
971}
diff --git a/drivers/staging/rdma/hfi1/qp.h b/drivers/staging/rdma/hfi1/qp.h
index 62a94c5d7dca..e7bc8d6cf681 100644
--- a/drivers/staging/rdma/hfi1/qp.h
+++ b/drivers/staging/rdma/hfi1/qp.h
@@ -1,14 +1,13 @@
1#ifndef _QP_H 1#ifndef _QP_H
2#define _QP_H 2#define _QP_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -51,119 +48,33 @@
51 */ 48 */
52 49
53#include <linux/hash.h> 50#include <linux/hash.h>
51#include <rdma/rdmavt_qp.h>
54#include "verbs.h" 52#include "verbs.h"
55#include "sdma.h" 53#include "sdma.h"
56 54
57#define QPN_MAX (1 << 24) 55extern unsigned int hfi1_qp_table_size;
58#define QPNMAP_ENTRIES (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
59 56
60/* 57/*
61 * QPN-map pages start out as NULL, they get allocated upon 58 * free_ahg - clear ahg from QP
62 * first use and are never deallocated. This way,
63 * large bitmaps are not allocated unless large numbers of QPs are used.
64 */
65struct qpn_map {
66 void *page;
67};
68
69struct hfi1_qpn_table {
70 spinlock_t lock; /* protect changes in this struct */
71 unsigned flags; /* flags for QP0/1 allocated for each port */
72 u32 last; /* last QP number allocated */
73 u32 nmaps; /* size of the map table */
74 u16 limit;
75 u8 incr;
76 /* bit map of free QP numbers other than 0/1 */
77 struct qpn_map map[QPNMAP_ENTRIES];
78};
79
80struct hfi1_qp_ibdev {
81 u32 qp_table_size;
82 u32 qp_table_bits;
83 struct hfi1_qp __rcu **qp_table;
84 spinlock_t qpt_lock;
85 struct hfi1_qpn_table qpn_table;
86};
87
88static inline u32 qpn_hash(struct hfi1_qp_ibdev *dev, u32 qpn)
89{
90 return hash_32(qpn, dev->qp_table_bits);
91}
92
93/**
94 * hfi1_lookup_qpn - return the QP with the given QPN
95 * @ibp: the ibport
96 * @qpn: the QP number to look up
97 *
98 * The caller must hold the rcu_read_lock(), and keep the lock until
99 * the returned qp is no longer in use.
100 */ 59 */
101static inline struct hfi1_qp *hfi1_lookup_qpn(struct hfi1_ibport *ibp, 60static inline void clear_ahg(struct rvt_qp *qp)
102 u32 qpn) __must_hold(RCU)
103{ 61{
104 struct hfi1_qp *qp = NULL; 62 struct hfi1_qp_priv *priv = qp->priv;
105
106 if (unlikely(qpn <= 1)) {
107 qp = rcu_dereference(ibp->qp[qpn]);
108 } else {
109 struct hfi1_ibdev *dev = &ppd_from_ibp(ibp)->dd->verbs_dev;
110 u32 n = qpn_hash(dev->qp_dev, qpn);
111
112 for (qp = rcu_dereference(dev->qp_dev->qp_table[n]); qp;
113 qp = rcu_dereference(qp->next))
114 if (qp->ibqp.qp_num == qpn)
115 break;
116 }
117 return qp;
118}
119 63
120/** 64 priv->s_hdr->ahgcount = 0;
121 * clear_ahg - reset ahg status in qp 65 qp->s_flags &= ~(RVT_S_AHG_VALID | RVT_S_AHG_CLEAR);
122 * @qp - qp pointer 66 if (priv->s_sde && qp->s_ahgidx >= 0)
123 */ 67 sdma_ahg_free(priv->s_sde, qp->s_ahgidx);
124static inline void clear_ahg(struct hfi1_qp *qp)
125{
126 qp->s_hdr->ahgcount = 0;
127 qp->s_flags &= ~(HFI1_S_AHG_VALID | HFI1_S_AHG_CLEAR);
128 if (qp->s_sde && qp->s_ahgidx >= 0)
129 sdma_ahg_free(qp->s_sde, qp->s_ahgidx);
130 qp->s_ahgidx = -1; 68 qp->s_ahgidx = -1;
131} 69}
132 70
133/** 71/**
134 * hfi1_error_qp - put a QP into the error state
135 * @qp: the QP to put into the error state
136 * @err: the receive completion error to signal if a RWQE is active
137 *
138 * Flushes both send and receive work queues.
139 * Returns true if last WQE event should be generated.
140 * The QP r_lock and s_lock should be held and interrupts disabled.
141 * If we are already in error state, just return.
142 */
143int hfi1_error_qp(struct hfi1_qp *qp, enum ib_wc_status err);
144
145/**
146 * hfi1_modify_qp - modify the attributes of a queue pair
147 * @ibqp: the queue pair who's attributes we're modifying
148 * @attr: the new attributes
149 * @attr_mask: the mask of attributes to modify
150 * @udata: user data for libibverbs.so
151 *
152 * Returns 0 on success, otherwise returns an errno.
153 */
154int hfi1_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
155 int attr_mask, struct ib_udata *udata);
156
157int hfi1_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
158 int attr_mask, struct ib_qp_init_attr *init_attr);
159
160/**
161 * hfi1_compute_aeth - compute the AETH (syndrome + MSN) 72 * hfi1_compute_aeth - compute the AETH (syndrome + MSN)
162 * @qp: the queue pair to compute the AETH for 73 * @qp: the queue pair to compute the AETH for
163 * 74 *
164 * Returns the AETH. 75 * Returns the AETH.
165 */ 76 */
166__be32 hfi1_compute_aeth(struct hfi1_qp *qp); 77__be32 hfi1_compute_aeth(struct rvt_qp *qp);
167 78
168/** 79/**
169 * hfi1_create_qp - create a queue pair for a device 80 * hfi1_create_qp - create a queue pair for a device
@@ -179,45 +90,23 @@ struct ib_qp *hfi1_create_qp(struct ib_pd *ibpd,
179 struct ib_qp_init_attr *init_attr, 90 struct ib_qp_init_attr *init_attr,
180 struct ib_udata *udata); 91 struct ib_udata *udata);
181/** 92/**
182 * hfi1_destroy_qp - destroy a queue pair
183 * @ibqp: the queue pair to destroy
184 *
185 * Returns 0 on success.
186 *
187 * Note that this can be called while the QP is actively sending or
188 * receiving!
189 */
190int hfi1_destroy_qp(struct ib_qp *ibqp);
191
192/**
193 * hfi1_get_credit - flush the send work queue of a QP 93 * hfi1_get_credit - flush the send work queue of a QP
194 * @qp: the qp who's send work queue to flush 94 * @qp: the qp who's send work queue to flush
195 * @aeth: the Acknowledge Extended Transport Header 95 * @aeth: the Acknowledge Extended Transport Header
196 * 96 *
197 * The QP s_lock should be held. 97 * The QP s_lock should be held.
198 */ 98 */
199void hfi1_get_credit(struct hfi1_qp *qp, u32 aeth); 99void hfi1_get_credit(struct rvt_qp *qp, u32 aeth);
200
201/**
202 * hfi1_qp_init - allocate QP tables
203 * @dev: a pointer to the hfi1_ibdev
204 */
205int hfi1_qp_init(struct hfi1_ibdev *dev);
206
207/**
208 * hfi1_qp_exit - free the QP related structures
209 * @dev: a pointer to the hfi1_ibdev
210 */
211void hfi1_qp_exit(struct hfi1_ibdev *dev);
212 100
213/** 101/**
214 * hfi1_qp_wakeup - wake up on the indicated event 102 * hfi1_qp_wakeup - wake up on the indicated event
215 * @qp: the QP 103 * @qp: the QP
216 * @flag: flag the qp on which the qp is stalled 104 * @flag: flag the qp on which the qp is stalled
217 */ 105 */
218void hfi1_qp_wakeup(struct hfi1_qp *qp, u32 flag); 106void hfi1_qp_wakeup(struct rvt_qp *qp, u32 flag);
219 107
220struct sdma_engine *qp_to_sdma_engine(struct hfi1_qp *qp, u8 sc5); 108struct sdma_engine *qp_to_sdma_engine(struct rvt_qp *qp, u8 sc5);
109struct send_context *qp_to_send_context(struct rvt_qp *qp, u8 sc5);
221 110
222struct qp_iter; 111struct qp_iter;
223 112
@@ -244,43 +133,28 @@ void qp_iter_print(struct seq_file *s, struct qp_iter *iter);
244 * qp_comm_est - handle trap with QP established 133 * qp_comm_est - handle trap with QP established
245 * @qp: the QP 134 * @qp: the QP
246 */ 135 */
247void qp_comm_est(struct hfi1_qp *qp); 136void qp_comm_est(struct rvt_qp *qp);
248 137
249/** 138void _hfi1_schedule_send(struct rvt_qp *qp);
250 * _hfi1_schedule_send - schedule progress 139void hfi1_schedule_send(struct rvt_qp *qp);
251 * @qp: the QP
252 *
253 * This schedules qp progress w/o regard to the s_flags.
254 *
255 * It is only used in the post send, which doesn't hold
256 * the s_lock.
257 */
258static inline void _hfi1_schedule_send(struct hfi1_qp *qp)
259{
260 struct hfi1_ibport *ibp =
261 to_iport(qp->ibqp.device, qp->port_num);
262 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
263 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
264 140
265 iowait_schedule(&qp->s_iowait, ppd->hfi1_wq, 141void hfi1_migrate_qp(struct rvt_qp *qp);
266 qp->s_sde ?
267 qp->s_sde->cpu :
268 cpumask_first(cpumask_of_node(dd->assigned_node_id)));
269}
270
271/**
272 * hfi1_schedule_send - schedule progress
273 * @qp: the QP
274 *
275 * This schedules qp progress and caller should hold
276 * the s_lock.
277 */
278static inline void hfi1_schedule_send(struct hfi1_qp *qp)
279{
280 if (hfi1_send_ok(qp))
281 _hfi1_schedule_send(qp);
282}
283
284void hfi1_migrate_qp(struct hfi1_qp *qp);
285 142
143/*
144 * Functions provided by hfi1 driver for rdmavt to use
145 */
146void *qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp,
147 gfp_t gfp);
148void qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp);
149unsigned free_all_qps(struct rvt_dev_info *rdi);
150void notify_qp_reset(struct rvt_qp *qp);
151int get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
152 struct ib_qp_attr *attr);
153void flush_qp_waiters(struct rvt_qp *qp);
154void notify_error_qp(struct rvt_qp *qp);
155void stop_send_queue(struct rvt_qp *qp);
156void quiesce_qp(struct rvt_qp *qp);
157u32 mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu);
158int mtu_to_path_mtu(u32 mtu);
159void hfi1_error_port_qps(struct hfi1_ibport *ibp, u8 sl);
286#endif /* _QP_H */ 160#endif /* _QP_H */
diff --git a/drivers/staging/rdma/hfi1/qsfp.c b/drivers/staging/rdma/hfi1/qsfp.c
index 6326a915d7fd..9ed1963010fe 100644
--- a/drivers/staging/rdma/hfi1/qsfp.c
+++ b/drivers/staging/rdma/hfi1/qsfp.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -62,7 +59,7 @@
62#define I2C_MAX_RETRY 4 59#define I2C_MAX_RETRY 4
63 60
64/* 61/*
65 * Unlocked i2c write. Must hold dd->qsfp_i2c_mutex. 62 * Raw i2c write. No set-up or lock checking.
66 */ 63 */
67static int __i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr, 64static int __i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr,
68 int offset, void *bp, int len) 65 int offset, void *bp, int len)
@@ -71,14 +68,6 @@ static int __i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr,
71 int ret, cnt; 68 int ret, cnt;
72 u8 *buff = bp; 69 u8 *buff = bp;
73 70
74 /* Make sure TWSI bus is in sane state. */
75 ret = hfi1_twsi_reset(dd, target);
76 if (ret) {
77 hfi1_dev_porterr(dd, ppd->port,
78 "I2C interface Reset for write failed\n");
79 return -EIO;
80 }
81
82 cnt = 0; 71 cnt = 0;
83 while (cnt < len) { 72 while (cnt < len) {
84 int wlen = len - cnt; 73 int wlen = len - cnt;
@@ -99,48 +88,45 @@ static int __i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr,
99 return cnt; 88 return cnt;
100} 89}
101 90
91/*
92 * Caller must hold the i2c chain resource.
93 */
102int i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr, int offset, 94int i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr, int offset,
103 void *bp, int len) 95 void *bp, int len)
104{ 96{
105 struct hfi1_devdata *dd = ppd->dd;
106 int ret; 97 int ret;
107 98
108 ret = mutex_lock_interruptible(&dd->qsfp_i2c_mutex); 99 if (!check_chip_resource(ppd->dd, qsfp_resource(ppd->dd), __func__))
109 if (!ret) { 100 return -EACCES;
110 ret = __i2c_write(ppd, target, i2c_addr, offset, bp, len); 101
111 mutex_unlock(&dd->qsfp_i2c_mutex); 102 /* make sure the TWSI bus is in a sane state */
103 ret = hfi1_twsi_reset(ppd->dd, target);
104 if (ret) {
105 hfi1_dev_porterr(ppd->dd, ppd->port,
106 "I2C chain %d write interface reset failed\n",
107 target);
108 return ret;
112 } 109 }
113 110
114 return ret; 111 return __i2c_write(ppd, target, i2c_addr, offset, bp, len);
115} 112}
116 113
117/* 114/*
118 * Unlocked i2c read. Must hold dd->qsfp_i2c_mutex. 115 * Raw i2c read. No set-up or lock checking.
119 */ 116 */
120static int __i2c_read(struct hfi1_pportdata *ppd, u32 target, int i2c_addr, 117static int __i2c_read(struct hfi1_pportdata *ppd, u32 target, int i2c_addr,
121 int offset, void *bp, int len) 118 int offset, void *bp, int len)
122{ 119{
123 struct hfi1_devdata *dd = ppd->dd; 120 struct hfi1_devdata *dd = ppd->dd;
124 int ret, cnt, pass = 0; 121 int ret, cnt, pass = 0;
125 int stuck = 0; 122 int orig_offset = offset;
126 u8 *buff = bp;
127
128 /* Make sure TWSI bus is in sane state. */
129 ret = hfi1_twsi_reset(dd, target);
130 if (ret) {
131 hfi1_dev_porterr(dd, ppd->port,
132 "I2C interface Reset for read failed\n");
133 ret = -EIO;
134 stuck = 1;
135 goto exit;
136 }
137 123
138 cnt = 0; 124 cnt = 0;
139 while (cnt < len) { 125 while (cnt < len) {
140 int rlen = len - cnt; 126 int rlen = len - cnt;
141 127
142 ret = hfi1_twsi_blk_rd(dd, target, i2c_addr, offset, 128 ret = hfi1_twsi_blk_rd(dd, target, i2c_addr, offset,
143 buff + cnt, rlen); 129 bp + cnt, rlen);
144 /* Some QSFP's fail first try. Retry as experiment */ 130 /* Some QSFP's fail first try. Retry as experiment */
145 if (ret && cnt == 0 && ++pass < I2C_MAX_RETRY) 131 if (ret && cnt == 0 && ++pass < I2C_MAX_RETRY)
146 continue; 132 continue;
@@ -156,14 +142,11 @@ static int __i2c_read(struct hfi1_pportdata *ppd, u32 target, int i2c_addr,
156 ret = cnt; 142 ret = cnt;
157 143
158exit: 144exit:
159 if (stuck) 145 if (ret < 0) {
160 dd_dev_err(dd, "I2C interface bus stuck non-idle\n");
161
162 if (pass >= I2C_MAX_RETRY && ret)
163 hfi1_dev_porterr(dd, ppd->port, 146 hfi1_dev_porterr(dd, ppd->port,
164 "I2C failed even retrying\n"); 147 "I2C chain %d read failed, addr 0x%x, offset 0x%x, len %d\n",
165 else if (pass) 148 target, i2c_addr, orig_offset, len);
166 hfi1_dev_porterr(dd, ppd->port, "I2C retries: %d\n", pass); 149 }
167 150
168 /* Must wait min 20us between qsfp i2c transactions */ 151 /* Must wait min 20us between qsfp i2c transactions */
169 udelay(20); 152 udelay(20);
@@ -171,21 +154,35 @@ exit:
171 return ret; 154 return ret;
172} 155}
173 156
157/*
158 * Caller must hold the i2c chain resource.
159 */
174int i2c_read(struct hfi1_pportdata *ppd, u32 target, int i2c_addr, int offset, 160int i2c_read(struct hfi1_pportdata *ppd, u32 target, int i2c_addr, int offset,
175 void *bp, int len) 161 void *bp, int len)
176{ 162{
177 struct hfi1_devdata *dd = ppd->dd;
178 int ret; 163 int ret;
179 164
180 ret = mutex_lock_interruptible(&dd->qsfp_i2c_mutex); 165 if (!check_chip_resource(ppd->dd, qsfp_resource(ppd->dd), __func__))
181 if (!ret) { 166 return -EACCES;
182 ret = __i2c_read(ppd, target, i2c_addr, offset, bp, len); 167
183 mutex_unlock(&dd->qsfp_i2c_mutex); 168 /* make sure the TWSI bus is in a sane state */
169 ret = hfi1_twsi_reset(ppd->dd, target);
170 if (ret) {
171 hfi1_dev_porterr(ppd->dd, ppd->port,
172 "I2C chain %d read interface reset failed\n",
173 target);
174 return ret;
184 } 175 }
185 176
186 return ret; 177 return __i2c_read(ppd, target, i2c_addr, offset, bp, len);
187} 178}
188 179
180/*
181 * Write page n, offset m of QSFP memory as defined by SFF 8636
182 * by writing @addr = ((256 * n) + m)
183 *
184 * Caller must hold the i2c chain resource.
185 */
189int qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp, 186int qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
190 int len) 187 int len)
191{ 188{
@@ -195,50 +192,81 @@ int qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
195 int ret; 192 int ret;
196 u8 page; 193 u8 page;
197 194
198 ret = mutex_lock_interruptible(&ppd->dd->qsfp_i2c_mutex); 195 if (!check_chip_resource(ppd->dd, qsfp_resource(ppd->dd), __func__))
199 if (ret) 196 return -EACCES;
197
198 /* make sure the TWSI bus is in a sane state */
199 ret = hfi1_twsi_reset(ppd->dd, target);
200 if (ret) {
201 hfi1_dev_porterr(ppd->dd, ppd->port,
202 "QSFP chain %d write interface reset failed\n",
203 target);
200 return ret; 204 return ret;
205 }
201 206
202 while (count < len) { 207 while (count < len) {
203 /* 208 /*
204 * Set the qsfp page based on a zero-based addresss 209 * Set the qsfp page based on a zero-based address
205 * and a page size of QSFP_PAGESIZE bytes. 210 * and a page size of QSFP_PAGESIZE bytes.
206 */ 211 */
207 page = (u8)(addr / QSFP_PAGESIZE); 212 page = (u8)(addr / QSFP_PAGESIZE);
208 213
209 ret = __i2c_write(ppd, target, QSFP_DEV, 214 ret = __i2c_write(ppd, target, QSFP_DEV | QSFP_OFFSET_SIZE,
210 QSFP_PAGE_SELECT_BYTE_OFFS, &page, 1); 215 QSFP_PAGE_SELECT_BYTE_OFFS, &page, 1);
211 if (ret != 1) { 216 if (ret != 1) {
212 hfi1_dev_porterr( 217 hfi1_dev_porterr(ppd->dd, ppd->port,
213 ppd->dd, 218 "QSFP chain %d can't write QSFP_PAGE_SELECT_BYTE: %d\n",
214 ppd->port, 219 target, ret);
215 "can't write QSFP_PAGE_SELECT_BYTE: %d\n", ret);
216 ret = -EIO; 220 ret = -EIO;
217 break; 221 break;
218 } 222 }
219 223
220 /* truncate write to end of page if crossing page boundary */
221 offset = addr % QSFP_PAGESIZE; 224 offset = addr % QSFP_PAGESIZE;
222 nwrite = len - count; 225 nwrite = len - count;
223 if ((offset + nwrite) > QSFP_PAGESIZE) 226 /* truncate write to boundary if crossing boundary */
224 nwrite = QSFP_PAGESIZE - offset; 227 if (((addr % QSFP_RW_BOUNDARY) + nwrite) > QSFP_RW_BOUNDARY)
228 nwrite = QSFP_RW_BOUNDARY - (addr % QSFP_RW_BOUNDARY);
225 229
226 ret = __i2c_write(ppd, target, QSFP_DEV, offset, bp + count, 230 ret = __i2c_write(ppd, target, QSFP_DEV | QSFP_OFFSET_SIZE,
227 nwrite); 231 offset, bp + count, nwrite);
228 if (ret <= 0) /* stop on error or nothing read */ 232 if (ret <= 0) /* stop on error or nothing written */
229 break; 233 break;
230 234
231 count += ret; 235 count += ret;
232 addr += ret; 236 addr += ret;
233 } 237 }
234 238
235 mutex_unlock(&ppd->dd->qsfp_i2c_mutex);
236
237 if (ret < 0) 239 if (ret < 0)
238 return ret; 240 return ret;
239 return count; 241 return count;
240} 242}
241 243
244/*
245 * Perform a stand-alone single QSFP write. Acquire the resource, do the
246 * read, then release the resource.
247 */
248int one_qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
249 int len)
250{
251 struct hfi1_devdata *dd = ppd->dd;
252 u32 resource = qsfp_resource(dd);
253 int ret;
254
255 ret = acquire_chip_resource(dd, resource, QSFP_WAIT);
256 if (ret)
257 return ret;
258 ret = qsfp_write(ppd, target, addr, bp, len);
259 release_chip_resource(dd, resource);
260
261 return ret;
262}
263
264/*
265 * Access page n, offset m of QSFP memory as defined by SFF 8636
266 * by reading @addr = ((256 * n) + m)
267 *
268 * Caller must hold the i2c chain resource.
269 */
242int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp, 270int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
243 int len) 271 int len)
244{ 272{
@@ -248,9 +276,17 @@ int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
248 int ret; 276 int ret;
249 u8 page; 277 u8 page;
250 278
251 ret = mutex_lock_interruptible(&ppd->dd->qsfp_i2c_mutex); 279 if (!check_chip_resource(ppd->dd, qsfp_resource(ppd->dd), __func__))
252 if (ret) 280 return -EACCES;
281
282 /* make sure the TWSI bus is in a sane state */
283 ret = hfi1_twsi_reset(ppd->dd, target);
284 if (ret) {
285 hfi1_dev_porterr(ppd->dd, ppd->port,
286 "QSFP chain %d read interface reset failed\n",
287 target);
253 return ret; 288 return ret;
289 }
254 290
255 while (count < len) { 291 while (count < len) {
256 /* 292 /*
@@ -258,25 +294,26 @@ int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
258 * and a page size of QSFP_PAGESIZE bytes. 294 * and a page size of QSFP_PAGESIZE bytes.
259 */ 295 */
260 page = (u8)(addr / QSFP_PAGESIZE); 296 page = (u8)(addr / QSFP_PAGESIZE);
261 ret = __i2c_write(ppd, target, QSFP_DEV, 297 ret = __i2c_write(ppd, target, QSFP_DEV | QSFP_OFFSET_SIZE,
262 QSFP_PAGE_SELECT_BYTE_OFFS, &page, 1); 298 QSFP_PAGE_SELECT_BYTE_OFFS, &page, 1);
263 if (ret != 1) { 299 if (ret != 1) {
264 hfi1_dev_porterr( 300 hfi1_dev_porterr(ppd->dd, ppd->port,
265 ppd->dd, 301 "QSFP chain %d can't write QSFP_PAGE_SELECT_BYTE: %d\n",
266 ppd->port, 302 target, ret);
267 "can't write QSFP_PAGE_SELECT_BYTE: %d\n", ret);
268 ret = -EIO; 303 ret = -EIO;
269 break; 304 break;
270 } 305 }
271 306
272 /* truncate read to end of page if crossing page boundary */
273 offset = addr % QSFP_PAGESIZE; 307 offset = addr % QSFP_PAGESIZE;
274 nread = len - count; 308 nread = len - count;
275 if ((offset + nread) > QSFP_PAGESIZE) 309 /* truncate read to boundary if crossing boundary */
276 nread = QSFP_PAGESIZE - offset; 310 if (((addr % QSFP_RW_BOUNDARY) + nread) > QSFP_RW_BOUNDARY)
277 311 nread = QSFP_RW_BOUNDARY - (addr % QSFP_RW_BOUNDARY);
278 ret = __i2c_read(ppd, target, QSFP_DEV, offset, bp + count, 312
279 nread); 313 /* QSFPs require a 5-10msec delay after write operations */
314 mdelay(5);
315 ret = __i2c_read(ppd, target, QSFP_DEV | QSFP_OFFSET_SIZE,
316 offset, bp + count, nread);
280 if (ret <= 0) /* stop on error or nothing read */ 317 if (ret <= 0) /* stop on error or nothing read */
281 break; 318 break;
282 319
@@ -284,17 +321,40 @@ int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
284 addr += ret; 321 addr += ret;
285 } 322 }
286 323
287 mutex_unlock(&ppd->dd->qsfp_i2c_mutex);
288
289 if (ret < 0) 324 if (ret < 0)
290 return ret; 325 return ret;
291 return count; 326 return count;
292} 327}
293 328
294/* 329/*
330 * Perform a stand-alone single QSFP read. Acquire the resource, do the
331 * read, then release the resource.
332 */
333int one_qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
334 int len)
335{
336 struct hfi1_devdata *dd = ppd->dd;
337 u32 resource = qsfp_resource(dd);
338 int ret;
339
340 ret = acquire_chip_resource(dd, resource, QSFP_WAIT);
341 if (ret)
342 return ret;
343 ret = qsfp_read(ppd, target, addr, bp, len);
344 release_chip_resource(dd, resource);
345
346 return ret;
347}
348
349/*
295 * This function caches the QSFP memory range in 128 byte chunks. 350 * This function caches the QSFP memory range in 128 byte chunks.
296 * As an example, the next byte after address 255 is byte 128 from 351 * As an example, the next byte after address 255 is byte 128 from
297 * upper page 01H (if existing) rather than byte 0 from lower page 00H. 352 * upper page 01H (if existing) rather than byte 0 from lower page 00H.
353 * Access page n, offset m of QSFP memory as defined by SFF 8636
354 * in the cache by reading byte ((128 * n) + m)
355 * The calls to qsfp_{read,write} in this function correctly handle the
356 * address map difference between this mapping and the mapping implemented
357 * by those functions
298 */ 358 */
299int refresh_qsfp_cache(struct hfi1_pportdata *ppd, struct qsfp_data *cp) 359int refresh_qsfp_cache(struct hfi1_pportdata *ppd, struct qsfp_data *cp)
300{ 360{
@@ -304,79 +364,84 @@ int refresh_qsfp_cache(struct hfi1_pportdata *ppd, struct qsfp_data *cp)
304 u8 *cache = &cp->cache[0]; 364 u8 *cache = &cp->cache[0];
305 365
306 /* ensure sane contents on invalid reads, for cable swaps */ 366 /* ensure sane contents on invalid reads, for cable swaps */
307 memset(cache, 0, (QSFP_MAX_NUM_PAGES*128)); 367 memset(cache, 0, (QSFP_MAX_NUM_PAGES * 128));
308 dd_dev_info(ppd->dd, "%s: called\n", __func__); 368 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
369 ppd->qsfp_info.cache_valid = 0;
370 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
371
309 if (!qsfp_mod_present(ppd)) { 372 if (!qsfp_mod_present(ppd)) {
310 ret = -ENODEV; 373 ret = -ENODEV;
311 goto bail; 374 goto bail_no_release;
312 } 375 }
313 376
314 ret = qsfp_read(ppd, target, 0, cache, 256); 377 ret = acquire_chip_resource(ppd->dd, qsfp_resource(ppd->dd), QSFP_WAIT);
315 if (ret != 256) { 378 if (ret)
379 goto bail_no_release;
380
381 ret = qsfp_read(ppd, target, 0, cache, QSFP_PAGESIZE);
382 if (ret != QSFP_PAGESIZE) {
316 dd_dev_info(ppd->dd, 383 dd_dev_info(ppd->dd,
317 "%s: Read of pages 00H failed, expected 256, got %d\n", 384 "%s: Page 0 read failed, expected %d, got %d\n",
318 __func__, ret); 385 __func__, QSFP_PAGESIZE, ret);
319 goto bail; 386 goto bail;
320 } 387 }
321 388
322 if (cache[0] != 0x0C && cache[0] != 0x0D)
323 goto bail;
324
325 /* Is paging enabled? */ 389 /* Is paging enabled? */
326 if (!(cache[2] & 4)) { 390 if (!(cache[2] & 4)) {
327
328 /* Paging enabled, page 03 required */ 391 /* Paging enabled, page 03 required */
329 if ((cache[195] & 0xC0) == 0xC0) { 392 if ((cache[195] & 0xC0) == 0xC0) {
330 /* all */ 393 /* all */
331 ret = qsfp_read(ppd, target, 384, cache + 256, 128); 394 ret = qsfp_read(ppd, target, 384, cache + 256, 128);
332 if (ret <= 0 || ret != 128) { 395 if (ret <= 0 || ret != 128) {
333 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 396 dd_dev_info(ppd->dd, "%s failed\n", __func__);
334 goto bail; 397 goto bail;
335 } 398 }
336 ret = qsfp_read(ppd, target, 640, cache + 384, 128); 399 ret = qsfp_read(ppd, target, 640, cache + 384, 128);
337 if (ret <= 0 || ret != 128) { 400 if (ret <= 0 || ret != 128) {
338 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 401 dd_dev_info(ppd->dd, "%s failed\n", __func__);
339 goto bail; 402 goto bail;
340 } 403 }
341 ret = qsfp_read(ppd, target, 896, cache + 512, 128); 404 ret = qsfp_read(ppd, target, 896, cache + 512, 128);
342 if (ret <= 0 || ret != 128) { 405 if (ret <= 0 || ret != 128) {
343 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 406 dd_dev_info(ppd->dd, "%s failed\n", __func__);
344 goto bail; 407 goto bail;
345 } 408 }
346 } else if ((cache[195] & 0x80) == 0x80) { 409 } else if ((cache[195] & 0x80) == 0x80) {
347 /* only page 2 and 3 */ 410 /* only page 2 and 3 */
348 ret = qsfp_read(ppd, target, 640, cache + 384, 128); 411 ret = qsfp_read(ppd, target, 640, cache + 384, 128);
349 if (ret <= 0 || ret != 128) { 412 if (ret <= 0 || ret != 128) {
350 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 413 dd_dev_info(ppd->dd, "%s failed\n", __func__);
351 goto bail; 414 goto bail;
352 } 415 }
353 ret = qsfp_read(ppd, target, 896, cache + 512, 128); 416 ret = qsfp_read(ppd, target, 896, cache + 512, 128);
354 if (ret <= 0 || ret != 128) { 417 if (ret <= 0 || ret != 128) {
355 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 418 dd_dev_info(ppd->dd, "%s failed\n", __func__);
356 goto bail; 419 goto bail;
357 } 420 }
358 } else if ((cache[195] & 0x40) == 0x40) { 421 } else if ((cache[195] & 0x40) == 0x40) {
359 /* only page 1 and 3 */ 422 /* only page 1 and 3 */
360 ret = qsfp_read(ppd, target, 384, cache + 256, 128); 423 ret = qsfp_read(ppd, target, 384, cache + 256, 128);
361 if (ret <= 0 || ret != 128) { 424 if (ret <= 0 || ret != 128) {
362 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 425 dd_dev_info(ppd->dd, "%s failed\n", __func__);
363 goto bail; 426 goto bail;
364 } 427 }
365 ret = qsfp_read(ppd, target, 896, cache + 512, 128); 428 ret = qsfp_read(ppd, target, 896, cache + 512, 128);
366 if (ret <= 0 || ret != 128) { 429 if (ret <= 0 || ret != 128) {
367 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 430 dd_dev_info(ppd->dd, "%s failed\n", __func__);
368 goto bail; 431 goto bail;
369 } 432 }
370 } else { 433 } else {
371 /* only page 3 */ 434 /* only page 3 */
372 ret = qsfp_read(ppd, target, 896, cache + 512, 128); 435 ret = qsfp_read(ppd, target, 896, cache + 512, 128);
373 if (ret <= 0 || ret != 128) { 436 if (ret <= 0 || ret != 128) {
374 dd_dev_info(ppd->dd, "%s: failed\n", __func__); 437 dd_dev_info(ppd->dd, "%s failed\n", __func__);
375 goto bail; 438 goto bail;
376 } 439 }
377 } 440 }
378 } 441 }
379 442
443 release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
444
380 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags); 445 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
381 ppd->qsfp_info.cache_valid = 1; 446 ppd->qsfp_info.cache_valid = 1;
382 ppd->qsfp_info.cache_refresh_required = 0; 447 ppd->qsfp_info.cache_refresh_required = 0;
@@ -385,7 +450,9 @@ int refresh_qsfp_cache(struct hfi1_pportdata *ppd, struct qsfp_data *cp)
385 return 0; 450 return 0;
386 451
387bail: 452bail:
388 memset(cache, 0, (QSFP_MAX_NUM_PAGES*128)); 453 release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
454bail_no_release:
455 memset(cache, 0, (QSFP_MAX_NUM_PAGES * 128));
389 return ret; 456 return ret;
390} 457}
391 458
@@ -434,7 +501,7 @@ int get_cable_info(struct hfi1_devdata *dd, u32 port_num, u32 addr, u32 len,
434 501
435 if (port_num > dd->num_pports || port_num < 1) { 502 if (port_num > dd->num_pports || port_num < 1) {
436 dd_dev_info(dd, "%s: Invalid port number %d\n", 503 dd_dev_info(dd, "%s: Invalid port number %d\n",
437 __func__, port_num); 504 __func__, port_num);
438 ret = -EINVAL; 505 ret = -EINVAL;
439 goto set_zeroes; 506 goto set_zeroes;
440 } 507 }
@@ -485,7 +552,6 @@ int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len)
485 lenstr[1] = '\0'; 552 lenstr[1] = '\0';
486 553
487 if (ppd->qsfp_info.cache_valid) { 554 if (ppd->qsfp_info.cache_valid) {
488
489 if (QSFP_IS_CU(cache[QSFP_MOD_TECH_OFFS])) 555 if (QSFP_IS_CU(cache[QSFP_MOD_TECH_OFFS]))
490 sprintf(lenstr, "%dM ", cache[QSFP_MOD_LEN_OFFS]); 556 sprintf(lenstr, "%dM ", cache[QSFP_MOD_LEN_OFFS]);
491 557
@@ -529,7 +595,7 @@ int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len)
529 595
530 memcpy(bin_buff, &cache[bidx], QSFP_DUMP_CHUNK); 596 memcpy(bin_buff, &cache[bidx], QSFP_DUMP_CHUNK);
531 for (iidx = 0; iidx < QSFP_DUMP_CHUNK; ++iidx) { 597 for (iidx = 0; iidx < QSFP_DUMP_CHUNK; ++iidx) {
532 sofar += scnprintf(buf + sofar, len-sofar, 598 sofar += scnprintf(buf + sofar, len - sofar,
533 " %02X", bin_buff[iidx]); 599 " %02X", bin_buff[iidx]);
534 } 600 }
535 sofar += scnprintf(buf + sofar, len - sofar, "\n"); 601 sofar += scnprintf(buf + sofar, len - sofar, "\n");
diff --git a/drivers/staging/rdma/hfi1/qsfp.h b/drivers/staging/rdma/hfi1/qsfp.h
index d30c2a6baa0b..831fe4cf1345 100644
--- a/drivers/staging/rdma/hfi1/qsfp.h
+++ b/drivers/staging/rdma/hfi1/qsfp.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -59,23 +56,28 @@
59 * Below are masks for QSFP pins. Pins are the same for HFI0 and HFI1. 56 * Below are masks for QSFP pins. Pins are the same for HFI0 and HFI1.
60 * _N means asserted low 57 * _N means asserted low
61 */ 58 */
62#define QSFP_HFI0_I2CCLK (1 << 0) 59#define QSFP_HFI0_I2CCLK BIT(0)
63#define QSFP_HFI0_I2CDAT (1 << 1) 60#define QSFP_HFI0_I2CDAT BIT(1)
64#define QSFP_HFI0_RESET_N (1 << 2) 61#define QSFP_HFI0_RESET_N BIT(2)
65#define QSFP_HFI0_INT_N (1 << 3) 62#define QSFP_HFI0_INT_N BIT(3)
66#define QSFP_HFI0_MODPRST_N (1 << 4) 63#define QSFP_HFI0_MODPRST_N BIT(4)
67 64
68/* QSFP is paged at 256 bytes */ 65/* QSFP is paged at 256 bytes */
69#define QSFP_PAGESIZE 256 66#define QSFP_PAGESIZE 256
67/* Reads/writes cannot cross 128 byte boundaries */
68#define QSFP_RW_BOUNDARY 128
69
70/* number of bytes in i2c offset for QSFP devices */
71#define __QSFP_OFFSET_SIZE 1 /* num address bytes */
72#define QSFP_OFFSET_SIZE (__QSFP_OFFSET_SIZE << 8) /* shifted value */
70 73
71/* Defined fields that Intel requires of qualified cables */ 74/* Defined fields that Intel requires of qualified cables */
72/* Byte 0 is Identifier, not checked */ 75/* Byte 0 is Identifier, not checked */
73/* Byte 1 is reserved "status MSB" */ 76/* Byte 1 is reserved "status MSB" */
74/* Byte 2 is "status LSB" We only care that D2 "Flat Mem" is set. */ 77#define QSFP_TX_CTRL_BYTE_OFFS 86
75/* 78#define QSFP_PWR_CTRL_BYTE_OFFS 93
76 * Rest of first 128 not used, although 127 is reserved for page select 79#define QSFP_CDR_CTRL_BYTE_OFFS 98
77 * if module is not "Flat memory". 80
78 */
79#define QSFP_PAGE_SELECT_BYTE_OFFS 127 81#define QSFP_PAGE_SELECT_BYTE_OFFS 127
80/* Byte 128 is Identifier: must be 0x0c for QSFP, or 0x0d for QSFP+ */ 82/* Byte 128 is Identifier: must be 0x0c for QSFP, or 0x0d for QSFP+ */
81#define QSFP_MOD_ID_OFFS 128 83#define QSFP_MOD_ID_OFFS 128
@@ -87,7 +89,8 @@
87/* Byte 130 is Connector type. Not Intel req'd */ 89/* Byte 130 is Connector type. Not Intel req'd */
88/* Bytes 131..138 are Transceiver types, bit maps for various tech, none IB */ 90/* Bytes 131..138 are Transceiver types, bit maps for various tech, none IB */
89/* Byte 139 is encoding. code 0x01 is 8b10b. Not Intel req'd */ 91/* Byte 139 is encoding. code 0x01 is 8b10b. Not Intel req'd */
90/* byte 140 is nominal bit-rate, in units of 100Mbits/sec Not Intel req'd */ 92/* byte 140 is nominal bit-rate, in units of 100Mbits/sec */
93#define QSFP_NOM_BIT_RATE_100_OFFS 140
91/* Byte 141 is Extended Rate Select. Not Intel req'd */ 94/* Byte 141 is Extended Rate Select. Not Intel req'd */
92/* Bytes 142..145 are lengths for various fiber types. Not Intel req'd */ 95/* Bytes 142..145 are lengths for various fiber types. Not Intel req'd */
93/* Byte 146 is length for Copper. Units of 1 meter */ 96/* Byte 146 is length for Copper. Units of 1 meter */
@@ -135,11 +138,18 @@ extern const char *const hfi1_qsfp_devtech[16];
135 */ 138 */
136#define QSFP_ATTEN_OFFS 186 139#define QSFP_ATTEN_OFFS 186
137#define QSFP_ATTEN_LEN 2 140#define QSFP_ATTEN_LEN 2
138/* Bytes 188,189 are Wavelength tolerance, not Intel req'd */ 141/*
142 * Bytes 188,189 are Wavelength tolerance, if optical
143 * If copper, they are attenuation in dB:
144 * Byte 188 is at 12.5 Gb/s, Byte 189 at 25 Gb/s
145 */
146#define QSFP_CU_ATTEN_7G_OFFS 188
147#define QSFP_CU_ATTEN_12G_OFFS 189
139/* Byte 190 is Max Case Temp. Not Intel req'd */ 148/* Byte 190 is Max Case Temp. Not Intel req'd */
140/* Byte 191 is LSB of sum of bytes 128..190. Not Intel req'd */ 149/* Byte 191 is LSB of sum of bytes 128..190. Not Intel req'd */
141#define QSFP_CC_OFFS 191 150#define QSFP_CC_OFFS 191
142/* Bytes 192..195 are Options implemented in qsfp. Not Intel req'd */ 151#define QSFP_EQ_INFO_OFFS 193
152#define QSFP_CDR_INFO_OFFS 194
143/* Bytes 196..211 are Serial Number, String */ 153/* Bytes 196..211 are Serial Number, String */
144#define QSFP_SN_OFFS 196 154#define QSFP_SN_OFFS 196
145#define QSFP_SN_LEN 16 155#define QSFP_SN_LEN 16
@@ -150,6 +160,8 @@ extern const char *const hfi1_qsfp_devtech[16];
150#define QSFP_LOT_OFFS 218 160#define QSFP_LOT_OFFS 218
151#define QSFP_LOT_LEN 2 161#define QSFP_LOT_LEN 2
152/* Bytes 220, 221 indicate monitoring options, Not Intel req'd */ 162/* Bytes 220, 221 indicate monitoring options, Not Intel req'd */
163/* Byte 222 indicates nominal bitrate in units of 250Mbits/sec */
164#define QSFP_NOM_BIT_RATE_250_OFFS 222
153/* Byte 223 is LSB of sum of bytes 192..222 */ 165/* Byte 223 is LSB of sum of bytes 192..222 */
154#define QSFP_CC_EXT_OFFS 223 166#define QSFP_CC_EXT_OFFS 223
155 167
@@ -191,6 +203,7 @@ extern const char *const hfi1_qsfp_devtech[16];
191 */ 203 */
192 204
193#define QSFP_PWR(pbyte) (((pbyte) >> 6) & 3) 205#define QSFP_PWR(pbyte) (((pbyte) >> 6) & 3)
206#define QSFP_HIGH_PWR(pbyte) (((pbyte) & 3) | 4)
194#define QSFP_ATTEN_SDR(attenarray) (attenarray[0]) 207#define QSFP_ATTEN_SDR(attenarray) (attenarray[0])
195#define QSFP_ATTEN_DDR(attenarray) (attenarray[1]) 208#define QSFP_ATTEN_DDR(attenarray) (attenarray[1])
196 209
@@ -198,10 +211,12 @@ struct qsfp_data {
198 /* Helps to find our way */ 211 /* Helps to find our way */
199 struct hfi1_pportdata *ppd; 212 struct hfi1_pportdata *ppd;
200 struct work_struct qsfp_work; 213 struct work_struct qsfp_work;
201 u8 cache[QSFP_MAX_NUM_PAGES*128]; 214 u8 cache[QSFP_MAX_NUM_PAGES * 128];
215 /* protect qsfp data */
202 spinlock_t qsfp_lock; 216 spinlock_t qsfp_lock;
203 u8 check_interrupt_flags; 217 u8 check_interrupt_flags;
204 u8 qsfp_interrupt_functional; 218 u8 reset_needed;
219 u8 limiting_active;
205 u8 cache_valid; 220 u8 cache_valid;
206 u8 cache_refresh_required; 221 u8 cache_refresh_required;
207}; 222};
@@ -220,3 +235,7 @@ int qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
220 int len); 235 int len);
221int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp, 236int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
222 int len); 237 int len);
238int one_qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
239 int len);
240int one_qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp,
241 int len);
diff --git a/drivers/staging/rdma/hfi1/rc.c b/drivers/staging/rdma/hfi1/rc.c
index 6f4a155f7931..0d7e1017f3cb 100644
--- a/drivers/staging/rdma/hfi1/rc.c
+++ b/drivers/staging/rdma/hfi1/rc.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -49,18 +46,151 @@
49 */ 46 */
50 47
51#include <linux/io.h> 48#include <linux/io.h>
49#include <rdma/rdma_vt.h>
50#include <rdma/rdmavt_qp.h>
52 51
53#include "hfi.h" 52#include "hfi.h"
54#include "qp.h" 53#include "qp.h"
55#include "sdma.h" 54#include "verbs_txreq.h"
56#include "trace.h" 55#include "trace.h"
57 56
58/* cut down ridiculously long IB macro names */ 57/* cut down ridiculously long IB macro names */
59#define OP(x) IB_OPCODE_RC_##x 58#define OP(x) IB_OPCODE_RC_##x
60 59
61static void rc_timeout(unsigned long arg); 60/**
61 * hfi1_add_retry_timer - add/start a retry timer
62 * @qp - the QP
63 *
64 * add a retry timer on the QP
65 */
66static inline void hfi1_add_retry_timer(struct rvt_qp *qp)
67{
68 struct ib_qp *ibqp = &qp->ibqp;
69 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
70
71 qp->s_flags |= RVT_S_TIMER;
72 /* 4.096 usec. * (1 << qp->timeout) */
73 qp->s_timer.expires = jiffies + qp->timeout_jiffies +
74 rdi->busy_jiffies;
75 add_timer(&qp->s_timer);
76}
77
78/**
79 * hfi1_add_rnr_timer - add/start an rnr timer
80 * @qp - the QP
81 * @to - timeout in usecs
82 *
83 * add an rnr timer on the QP
84 */
85void hfi1_add_rnr_timer(struct rvt_qp *qp, u32 to)
86{
87 struct hfi1_qp_priv *priv = qp->priv;
88
89 qp->s_flags |= RVT_S_WAIT_RNR;
90 qp->s_timer.expires = jiffies + usecs_to_jiffies(to);
91 add_timer(&priv->s_rnr_timer);
92}
93
94/**
95 * hfi1_mod_retry_timer - mod a retry timer
96 * @qp - the QP
97 *
98 * Modify a potentially already running retry
99 * timer
100 */
101static inline void hfi1_mod_retry_timer(struct rvt_qp *qp)
102{
103 struct ib_qp *ibqp = &qp->ibqp;
104 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
105
106 qp->s_flags |= RVT_S_TIMER;
107 /* 4.096 usec. * (1 << qp->timeout) */
108 mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies +
109 rdi->busy_jiffies);
110}
111
112/**
113 * hfi1_stop_retry_timer - stop a retry timer
114 * @qp - the QP
115 *
116 * stop a retry timer and return if the timer
117 * had been pending.
118 */
119static inline int hfi1_stop_retry_timer(struct rvt_qp *qp)
120{
121 int rval = 0;
122
123 /* Remove QP from retry */
124 if (qp->s_flags & RVT_S_TIMER) {
125 qp->s_flags &= ~RVT_S_TIMER;
126 rval = del_timer(&qp->s_timer);
127 }
128 return rval;
129}
130
131/**
132 * hfi1_stop_rc_timers - stop all timers
133 * @qp - the QP
134 *
135 * stop any pending timers
136 */
137void hfi1_stop_rc_timers(struct rvt_qp *qp)
138{
139 struct hfi1_qp_priv *priv = qp->priv;
140
141 /* Remove QP from all timers */
142 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) {
143 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR);
144 del_timer(&qp->s_timer);
145 del_timer(&priv->s_rnr_timer);
146 }
147}
148
149/**
150 * hfi1_stop_rnr_timer - stop an rnr timer
151 * @qp - the QP
152 *
153 * stop an rnr timer and return if the timer
154 * had been pending.
155 */
156static inline int hfi1_stop_rnr_timer(struct rvt_qp *qp)
157{
158 int rval = 0;
159 struct hfi1_qp_priv *priv = qp->priv;
160
161 /* Remove QP from rnr timer */
162 if (qp->s_flags & RVT_S_WAIT_RNR) {
163 qp->s_flags &= ~RVT_S_WAIT_RNR;
164 rval = del_timer(&priv->s_rnr_timer);
165 }
166 return rval;
167}
168
169/**
170 * hfi1_del_timers_sync - wait for any timeout routines to exit
171 * @qp - the QP
172 */
173void hfi1_del_timers_sync(struct rvt_qp *qp)
174{
175 struct hfi1_qp_priv *priv = qp->priv;
176
177 del_timer_sync(&qp->s_timer);
178 del_timer_sync(&priv->s_rnr_timer);
179}
62 180
63static u32 restart_sge(struct hfi1_sge_state *ss, struct hfi1_swqe *wqe, 181/* only opcode mask for adaptive pio */
182const u32 rc_only_opcode =
183 BIT(OP(SEND_ONLY) & 0x1f) |
184 BIT(OP(SEND_ONLY_WITH_IMMEDIATE & 0x1f)) |
185 BIT(OP(RDMA_WRITE_ONLY & 0x1f)) |
186 BIT(OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE & 0x1f)) |
187 BIT(OP(RDMA_READ_REQUEST & 0x1f)) |
188 BIT(OP(ACKNOWLEDGE & 0x1f)) |
189 BIT(OP(ATOMIC_ACKNOWLEDGE & 0x1f)) |
190 BIT(OP(COMPARE_SWAP & 0x1f)) |
191 BIT(OP(FETCH_ADD & 0x1f));
192
193static u32 restart_sge(struct rvt_sge_state *ss, struct rvt_swqe *wqe,
64 u32 psn, u32 pmtu) 194 u32 psn, u32 pmtu)
65{ 195{
66 u32 len; 196 u32 len;
@@ -74,38 +204,32 @@ static u32 restart_sge(struct hfi1_sge_state *ss, struct hfi1_swqe *wqe,
74 return wqe->length - len; 204 return wqe->length - len;
75} 205}
76 206
77static void start_timer(struct hfi1_qp *qp)
78{
79 qp->s_flags |= HFI1_S_TIMER;
80 qp->s_timer.function = rc_timeout;
81 /* 4.096 usec. * (1 << qp->timeout) */
82 qp->s_timer.expires = jiffies + qp->timeout_jiffies;
83 add_timer(&qp->s_timer);
84}
85
86/** 207/**
87 * make_rc_ack - construct a response packet (ACK, NAK, or RDMA read) 208 * make_rc_ack - construct a response packet (ACK, NAK, or RDMA read)
88 * @dev: the device for this QP 209 * @dev: the device for this QP
89 * @qp: a pointer to the QP 210 * @qp: a pointer to the QP
90 * @ohdr: a pointer to the IB header being constructed 211 * @ohdr: a pointer to the IB header being constructed
91 * @pmtu: the path MTU 212 * @ps: the xmit packet state
92 * 213 *
93 * Return 1 if constructed; otherwise, return 0. 214 * Return 1 if constructed; otherwise, return 0.
94 * Note that we are in the responder's side of the QP context. 215 * Note that we are in the responder's side of the QP context.
95 * Note the QP s_lock must be held. 216 * Note the QP s_lock must be held.
96 */ 217 */
97static int make_rc_ack(struct hfi1_ibdev *dev, struct hfi1_qp *qp, 218static int make_rc_ack(struct hfi1_ibdev *dev, struct rvt_qp *qp,
98 struct hfi1_other_headers *ohdr, u32 pmtu) 219 struct hfi1_other_headers *ohdr,
220 struct hfi1_pkt_state *ps)
99{ 221{
100 struct hfi1_ack_entry *e; 222 struct rvt_ack_entry *e;
101 u32 hwords; 223 u32 hwords;
102 u32 len; 224 u32 len;
103 u32 bth0; 225 u32 bth0;
104 u32 bth2; 226 u32 bth2;
105 int middle = 0; 227 int middle = 0;
228 u32 pmtu = qp->pmtu;
229 struct hfi1_qp_priv *priv = qp->priv;
106 230
107 /* Don't send an ACK if we aren't supposed to. */ 231 /* Don't send an ACK if we aren't supposed to. */
108 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK)) 232 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
109 goto bail; 233 goto bail;
110 234
111 /* header size in 32-bit words LRH+BTH = (8+12)/4. */ 235 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
@@ -116,7 +240,7 @@ static int make_rc_ack(struct hfi1_ibdev *dev, struct hfi1_qp *qp,
116 case OP(RDMA_READ_RESPONSE_ONLY): 240 case OP(RDMA_READ_RESPONSE_ONLY):
117 e = &qp->s_ack_queue[qp->s_tail_ack_queue]; 241 e = &qp->s_ack_queue[qp->s_tail_ack_queue];
118 if (e->rdma_sge.mr) { 242 if (e->rdma_sge.mr) {
119 hfi1_put_mr(e->rdma_sge.mr); 243 rvt_put_mr(e->rdma_sge.mr);
120 e->rdma_sge.mr = NULL; 244 e->rdma_sge.mr = NULL;
121 } 245 }
122 /* FALLTHROUGH */ 246 /* FALLTHROUGH */
@@ -133,7 +257,7 @@ static int make_rc_ack(struct hfi1_ibdev *dev, struct hfi1_qp *qp,
133 case OP(ACKNOWLEDGE): 257 case OP(ACKNOWLEDGE):
134 /* Check for no next entry in the queue. */ 258 /* Check for no next entry in the queue. */
135 if (qp->r_head_ack_queue == qp->s_tail_ack_queue) { 259 if (qp->r_head_ack_queue == qp->s_tail_ack_queue) {
136 if (qp->s_flags & HFI1_S_ACK_PENDING) 260 if (qp->s_flags & RVT_S_ACK_PENDING)
137 goto normal; 261 goto normal;
138 goto bail; 262 goto bail;
139 } 263 }
@@ -152,9 +276,9 @@ static int make_rc_ack(struct hfi1_ibdev *dev, struct hfi1_qp *qp,
152 goto bail; 276 goto bail;
153 } 277 }
154 /* Copy SGE state in case we need to resend */ 278 /* Copy SGE state in case we need to resend */
155 qp->s_rdma_mr = e->rdma_sge.mr; 279 ps->s_txreq->mr = e->rdma_sge.mr;
156 if (qp->s_rdma_mr) 280 if (ps->s_txreq->mr)
157 hfi1_get_mr(qp->s_rdma_mr); 281 rvt_get_mr(ps->s_txreq->mr);
158 qp->s_ack_rdma_sge.sge = e->rdma_sge; 282 qp->s_ack_rdma_sge.sge = e->rdma_sge;
159 qp->s_ack_rdma_sge.num_sge = 1; 283 qp->s_ack_rdma_sge.num_sge = 1;
160 qp->s_cur_sge = &qp->s_ack_rdma_sge; 284 qp->s_cur_sge = &qp->s_ack_rdma_sge;
@@ -191,9 +315,9 @@ static int make_rc_ack(struct hfi1_ibdev *dev, struct hfi1_qp *qp,
191 /* FALLTHROUGH */ 315 /* FALLTHROUGH */
192 case OP(RDMA_READ_RESPONSE_MIDDLE): 316 case OP(RDMA_READ_RESPONSE_MIDDLE):
193 qp->s_cur_sge = &qp->s_ack_rdma_sge; 317 qp->s_cur_sge = &qp->s_ack_rdma_sge;
194 qp->s_rdma_mr = qp->s_ack_rdma_sge.sge.mr; 318 ps->s_txreq->mr = qp->s_ack_rdma_sge.sge.mr;
195 if (qp->s_rdma_mr) 319 if (ps->s_txreq->mr)
196 hfi1_get_mr(qp->s_rdma_mr); 320 rvt_get_mr(ps->s_txreq->mr);
197 len = qp->s_ack_rdma_sge.sge.sge_length; 321 len = qp->s_ack_rdma_sge.sge.sge_length;
198 if (len > pmtu) { 322 if (len > pmtu) {
199 len = pmtu; 323 len = pmtu;
@@ -218,7 +342,7 @@ normal:
218 * (see above). 342 * (see above).
219 */ 343 */
220 qp->s_ack_state = OP(SEND_ONLY); 344 qp->s_ack_state = OP(SEND_ONLY);
221 qp->s_flags &= ~HFI1_S_ACK_PENDING; 345 qp->s_flags &= ~RVT_S_ACK_PENDING;
222 qp->s_cur_sge = NULL; 346 qp->s_cur_sge = NULL;
223 if (qp->s_nak_state) 347 if (qp->s_nak_state)
224 ohdr->u.aeth = 348 ohdr->u.aeth =
@@ -234,20 +358,23 @@ normal:
234 } 358 }
235 qp->s_rdma_ack_cnt++; 359 qp->s_rdma_ack_cnt++;
236 qp->s_hdrwords = hwords; 360 qp->s_hdrwords = hwords;
361 ps->s_txreq->sde = priv->s_sde;
237 qp->s_cur_size = len; 362 qp->s_cur_size = len;
238 hfi1_make_ruc_header(qp, ohdr, bth0, bth2, middle); 363 hfi1_make_ruc_header(qp, ohdr, bth0, bth2, middle, ps);
364 /* pbc */
365 ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2;
239 return 1; 366 return 1;
240 367
241bail: 368bail:
242 qp->s_ack_state = OP(ACKNOWLEDGE); 369 qp->s_ack_state = OP(ACKNOWLEDGE);
243 /* 370 /*
244 * Ensure s_rdma_ack_cnt changes are committed prior to resetting 371 * Ensure s_rdma_ack_cnt changes are committed prior to resetting
245 * HFI1_S_RESP_PENDING 372 * RVT_S_RESP_PENDING
246 */ 373 */
247 smp_wmb(); 374 smp_wmb();
248 qp->s_flags &= ~(HFI1_S_RESP_PENDING 375 qp->s_flags &= ~(RVT_S_RESP_PENDING
249 | HFI1_S_ACK_PENDING 376 | RVT_S_ACK_PENDING
250 | HFI1_S_AHG_VALID); 377 | RVT_S_AHG_VALID);
251 return 0; 378 return 0;
252} 379}
253 380
@@ -255,14 +382,17 @@ bail:
255 * hfi1_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC) 382 * hfi1_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC)
256 * @qp: a pointer to the QP 383 * @qp: a pointer to the QP
257 * 384 *
385 * Assumes s_lock is held.
386 *
258 * Return 1 if constructed; otherwise, return 0. 387 * Return 1 if constructed; otherwise, return 0.
259 */ 388 */
260int hfi1_make_rc_req(struct hfi1_qp *qp) 389int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
261{ 390{
391 struct hfi1_qp_priv *priv = qp->priv;
262 struct hfi1_ibdev *dev = to_idev(qp->ibqp.device); 392 struct hfi1_ibdev *dev = to_idev(qp->ibqp.device);
263 struct hfi1_other_headers *ohdr; 393 struct hfi1_other_headers *ohdr;
264 struct hfi1_sge_state *ss; 394 struct rvt_sge_state *ss;
265 struct hfi1_swqe *wqe; 395 struct rvt_swqe *wqe;
266 /* header size in 32-bit words LRH+BTH = (8+12)/4. */ 396 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
267 u32 hwords = 5; 397 u32 hwords = 5;
268 u32 len; 398 u32 len;
@@ -270,51 +400,48 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
270 u32 bth2; 400 u32 bth2;
271 u32 pmtu = qp->pmtu; 401 u32 pmtu = qp->pmtu;
272 char newreq; 402 char newreq;
273 unsigned long flags;
274 int ret = 0;
275 int middle = 0; 403 int middle = 0;
276 int delta; 404 int delta;
277 405
278 ohdr = &qp->s_hdr->ibh.u.oth; 406 ps->s_txreq = get_txreq(ps->dev, qp);
279 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH) 407 if (IS_ERR(ps->s_txreq))
280 ohdr = &qp->s_hdr->ibh.u.l.oth; 408 goto bail_no_tx;
281 409
282 /* 410 ohdr = &ps->s_txreq->phdr.hdr.u.oth;
283 * The lock is needed to synchronize between the sending tasklet, 411 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
284 * the receive interrupt handler, and timeout re-sends. 412 ohdr = &ps->s_txreq->phdr.hdr.u.l.oth;
285 */
286 spin_lock_irqsave(&qp->s_lock, flags);
287 413
288 /* Sending responses has higher priority over sending requests. */ 414 /* Sending responses has higher priority over sending requests. */
289 if ((qp->s_flags & HFI1_S_RESP_PENDING) && 415 if ((qp->s_flags & RVT_S_RESP_PENDING) &&
290 make_rc_ack(dev, qp, ohdr, pmtu)) 416 make_rc_ack(dev, qp, ohdr, ps))
291 goto done; 417 return 1;
292 418
293 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_SEND_OK)) { 419 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) {
294 if (!(ib_hfi1_state_ops[qp->state] & HFI1_FLUSH_SEND)) 420 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
295 goto bail; 421 goto bail;
296 /* We are in the error state, flush the work request. */ 422 /* We are in the error state, flush the work request. */
297 if (qp->s_last == qp->s_head) 423 smp_read_barrier_depends(); /* see post_one_send() */
424 if (qp->s_last == ACCESS_ONCE(qp->s_head))
298 goto bail; 425 goto bail;
299 /* If DMAs are in progress, we can't flush immediately. */ 426 /* If DMAs are in progress, we can't flush immediately. */
300 if (atomic_read(&qp->s_iowait.sdma_busy)) { 427 if (iowait_sdma_pending(&priv->s_iowait)) {
301 qp->s_flags |= HFI1_S_WAIT_DMA; 428 qp->s_flags |= RVT_S_WAIT_DMA;
302 goto bail; 429 goto bail;
303 } 430 }
304 clear_ahg(qp); 431 clear_ahg(qp);
305 wqe = get_swqe_ptr(qp, qp->s_last); 432 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
306 hfi1_send_complete(qp, wqe, qp->s_last != qp->s_acked ? 433 hfi1_send_complete(qp, wqe, qp->s_last != qp->s_acked ?
307 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR); 434 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR);
308 /* will get called again */ 435 /* will get called again */
309 goto done; 436 goto done_free_tx;
310 } 437 }
311 438
312 if (qp->s_flags & (HFI1_S_WAIT_RNR | HFI1_S_WAIT_ACK)) 439 if (qp->s_flags & (RVT_S_WAIT_RNR | RVT_S_WAIT_ACK))
313 goto bail; 440 goto bail;
314 441
315 if (cmp_psn(qp->s_psn, qp->s_sending_hpsn) <= 0) { 442 if (cmp_psn(qp->s_psn, qp->s_sending_hpsn) <= 0) {
316 if (cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) { 443 if (cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) {
317 qp->s_flags |= HFI1_S_WAIT_PSN; 444 qp->s_flags |= RVT_S_WAIT_PSN;
318 goto bail; 445 goto bail;
319 } 446 }
320 qp->s_sending_psn = qp->s_psn; 447 qp->s_sending_psn = qp->s_psn;
@@ -322,10 +449,10 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
322 } 449 }
323 450
324 /* Send a request. */ 451 /* Send a request. */
325 wqe = get_swqe_ptr(qp, qp->s_cur); 452 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
326 switch (qp->s_state) { 453 switch (qp->s_state) {
327 default: 454 default:
328 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_NEXT_SEND_OK)) 455 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK))
329 goto bail; 456 goto bail;
330 /* 457 /*
331 * Resend an old request or start a new one. 458 * Resend an old request or start a new one.
@@ -347,11 +474,11 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
347 */ 474 */
348 if ((wqe->wr.send_flags & IB_SEND_FENCE) && 475 if ((wqe->wr.send_flags & IB_SEND_FENCE) &&
349 qp->s_num_rd_atomic) { 476 qp->s_num_rd_atomic) {
350 qp->s_flags |= HFI1_S_WAIT_FENCE; 477 qp->s_flags |= RVT_S_WAIT_FENCE;
351 goto bail; 478 goto bail;
352 } 479 }
353 wqe->psn = qp->s_next_psn;
354 newreq = 1; 480 newreq = 1;
481 qp->s_psn = wqe->psn;
355 } 482 }
356 /* 483 /*
357 * Note that we have to be careful not to modify the 484 * Note that we have to be careful not to modify the
@@ -365,21 +492,19 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
365 case IB_WR_SEND: 492 case IB_WR_SEND:
366 case IB_WR_SEND_WITH_IMM: 493 case IB_WR_SEND_WITH_IMM:
367 /* If no credit, return. */ 494 /* If no credit, return. */
368 if (!(qp->s_flags & HFI1_S_UNLIMITED_CREDIT) && 495 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
369 cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) { 496 cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) {
370 qp->s_flags |= HFI1_S_WAIT_SSN_CREDIT; 497 qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
371 goto bail; 498 goto bail;
372 } 499 }
373 wqe->lpsn = wqe->psn;
374 if (len > pmtu) { 500 if (len > pmtu) {
375 wqe->lpsn += (len - 1) / pmtu;
376 qp->s_state = OP(SEND_FIRST); 501 qp->s_state = OP(SEND_FIRST);
377 len = pmtu; 502 len = pmtu;
378 break; 503 break;
379 } 504 }
380 if (wqe->wr.opcode == IB_WR_SEND) 505 if (wqe->wr.opcode == IB_WR_SEND) {
381 qp->s_state = OP(SEND_ONLY); 506 qp->s_state = OP(SEND_ONLY);
382 else { 507 } else {
383 qp->s_state = OP(SEND_ONLY_WITH_IMMEDIATE); 508 qp->s_state = OP(SEND_ONLY_WITH_IMMEDIATE);
384 /* Immediate data comes after the BTH */ 509 /* Immediate data comes after the BTH */
385 ohdr->u.imm_data = wqe->wr.ex.imm_data; 510 ohdr->u.imm_data = wqe->wr.ex.imm_data;
@@ -393,14 +518,14 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
393 break; 518 break;
394 519
395 case IB_WR_RDMA_WRITE: 520 case IB_WR_RDMA_WRITE:
396 if (newreq && !(qp->s_flags & HFI1_S_UNLIMITED_CREDIT)) 521 if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
397 qp->s_lsn++; 522 qp->s_lsn++;
398 /* FALLTHROUGH */ 523 /* FALLTHROUGH */
399 case IB_WR_RDMA_WRITE_WITH_IMM: 524 case IB_WR_RDMA_WRITE_WITH_IMM:
400 /* If no credit, return. */ 525 /* If no credit, return. */
401 if (!(qp->s_flags & HFI1_S_UNLIMITED_CREDIT) && 526 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
402 cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) { 527 cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) {
403 qp->s_flags |= HFI1_S_WAIT_SSN_CREDIT; 528 qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
404 goto bail; 529 goto bail;
405 } 530 }
406 ohdr->u.rc.reth.vaddr = 531 ohdr->u.rc.reth.vaddr =
@@ -409,16 +534,14 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
409 cpu_to_be32(wqe->rdma_wr.rkey); 534 cpu_to_be32(wqe->rdma_wr.rkey);
410 ohdr->u.rc.reth.length = cpu_to_be32(len); 535 ohdr->u.rc.reth.length = cpu_to_be32(len);
411 hwords += sizeof(struct ib_reth) / sizeof(u32); 536 hwords += sizeof(struct ib_reth) / sizeof(u32);
412 wqe->lpsn = wqe->psn;
413 if (len > pmtu) { 537 if (len > pmtu) {
414 wqe->lpsn += (len - 1) / pmtu;
415 qp->s_state = OP(RDMA_WRITE_FIRST); 538 qp->s_state = OP(RDMA_WRITE_FIRST);
416 len = pmtu; 539 len = pmtu;
417 break; 540 break;
418 } 541 }
419 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) 542 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) {
420 qp->s_state = OP(RDMA_WRITE_ONLY); 543 qp->s_state = OP(RDMA_WRITE_ONLY);
421 else { 544 } else {
422 qp->s_state = 545 qp->s_state =
423 OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE); 546 OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
424 /* Immediate data comes after RETH */ 547 /* Immediate data comes after RETH */
@@ -440,19 +563,12 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
440 if (newreq) { 563 if (newreq) {
441 if (qp->s_num_rd_atomic >= 564 if (qp->s_num_rd_atomic >=
442 qp->s_max_rd_atomic) { 565 qp->s_max_rd_atomic) {
443 qp->s_flags |= HFI1_S_WAIT_RDMAR; 566 qp->s_flags |= RVT_S_WAIT_RDMAR;
444 goto bail; 567 goto bail;
445 } 568 }
446 qp->s_num_rd_atomic++; 569 qp->s_num_rd_atomic++;
447 if (!(qp->s_flags & HFI1_S_UNLIMITED_CREDIT)) 570 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
448 qp->s_lsn++; 571 qp->s_lsn++;
449 /*
450 * Adjust s_next_psn to count the
451 * expected number of responses.
452 */
453 if (len > pmtu)
454 qp->s_next_psn += (len - 1) / pmtu;
455 wqe->lpsn = qp->s_next_psn++;
456 } 572 }
457 ohdr->u.rc.reth.vaddr = 573 ohdr->u.rc.reth.vaddr =
458 cpu_to_be64(wqe->rdma_wr.remote_addr); 574 cpu_to_be64(wqe->rdma_wr.remote_addr);
@@ -477,13 +593,12 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
477 if (newreq) { 593 if (newreq) {
478 if (qp->s_num_rd_atomic >= 594 if (qp->s_num_rd_atomic >=
479 qp->s_max_rd_atomic) { 595 qp->s_max_rd_atomic) {
480 qp->s_flags |= HFI1_S_WAIT_RDMAR; 596 qp->s_flags |= RVT_S_WAIT_RDMAR;
481 goto bail; 597 goto bail;
482 } 598 }
483 qp->s_num_rd_atomic++; 599 qp->s_num_rd_atomic++;
484 if (!(qp->s_flags & HFI1_S_UNLIMITED_CREDIT)) 600 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
485 qp->s_lsn++; 601 qp->s_lsn++;
486 wqe->lpsn = wqe->psn;
487 } 602 }
488 if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP) { 603 if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
489 qp->s_state = OP(COMPARE_SWAP); 604 qp->s_state = OP(COMPARE_SWAP);
@@ -526,11 +641,8 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
526 } 641 }
527 if (wqe->wr.opcode == IB_WR_RDMA_READ) 642 if (wqe->wr.opcode == IB_WR_RDMA_READ)
528 qp->s_psn = wqe->lpsn + 1; 643 qp->s_psn = wqe->lpsn + 1;
529 else { 644 else
530 qp->s_psn++; 645 qp->s_psn++;
531 if (cmp_psn(qp->s_psn, qp->s_next_psn) > 0)
532 qp->s_next_psn = qp->s_psn;
533 }
534 break; 646 break;
535 647
536 case OP(RDMA_READ_RESPONSE_FIRST): 648 case OP(RDMA_READ_RESPONSE_FIRST):
@@ -550,8 +662,6 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
550 /* FALLTHROUGH */ 662 /* FALLTHROUGH */
551 case OP(SEND_MIDDLE): 663 case OP(SEND_MIDDLE):
552 bth2 = mask_psn(qp->s_psn++); 664 bth2 = mask_psn(qp->s_psn++);
553 if (cmp_psn(qp->s_psn, qp->s_next_psn) > 0)
554 qp->s_next_psn = qp->s_psn;
555 ss = &qp->s_sge; 665 ss = &qp->s_sge;
556 len = qp->s_len; 666 len = qp->s_len;
557 if (len > pmtu) { 667 if (len > pmtu) {
@@ -559,9 +669,9 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
559 middle = HFI1_CAP_IS_KSET(SDMA_AHG); 669 middle = HFI1_CAP_IS_KSET(SDMA_AHG);
560 break; 670 break;
561 } 671 }
562 if (wqe->wr.opcode == IB_WR_SEND) 672 if (wqe->wr.opcode == IB_WR_SEND) {
563 qp->s_state = OP(SEND_LAST); 673 qp->s_state = OP(SEND_LAST);
564 else { 674 } else {
565 qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE); 675 qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
566 /* Immediate data comes after the BTH */ 676 /* Immediate data comes after the BTH */
567 ohdr->u.imm_data = wqe->wr.ex.imm_data; 677 ohdr->u.imm_data = wqe->wr.ex.imm_data;
@@ -592,8 +702,6 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
592 /* FALLTHROUGH */ 702 /* FALLTHROUGH */
593 case OP(RDMA_WRITE_MIDDLE): 703 case OP(RDMA_WRITE_MIDDLE):
594 bth2 = mask_psn(qp->s_psn++); 704 bth2 = mask_psn(qp->s_psn++);
595 if (cmp_psn(qp->s_psn, qp->s_next_psn) > 0)
596 qp->s_next_psn = qp->s_psn;
597 ss = &qp->s_sge; 705 ss = &qp->s_sge;
598 len = qp->s_len; 706 len = qp->s_len;
599 if (len > pmtu) { 707 if (len > pmtu) {
@@ -601,9 +709,9 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
601 middle = HFI1_CAP_IS_KSET(SDMA_AHG); 709 middle = HFI1_CAP_IS_KSET(SDMA_AHG);
602 break; 710 break;
603 } 711 }
604 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) 712 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) {
605 qp->s_state = OP(RDMA_WRITE_LAST); 713 qp->s_state = OP(RDMA_WRITE_LAST);
606 else { 714 } else {
607 qp->s_state = OP(RDMA_WRITE_LAST_WITH_IMMEDIATE); 715 qp->s_state = OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
608 /* Immediate data comes after the BTH */ 716 /* Immediate data comes after the BTH */
609 ohdr->u.imm_data = wqe->wr.ex.imm_data; 717 ohdr->u.imm_data = wqe->wr.ex.imm_data;
@@ -648,13 +756,14 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
648 delta = delta_psn(bth2, wqe->psn); 756 delta = delta_psn(bth2, wqe->psn);
649 if (delta && delta % HFI1_PSN_CREDIT == 0) 757 if (delta && delta % HFI1_PSN_CREDIT == 0)
650 bth2 |= IB_BTH_REQ_ACK; 758 bth2 |= IB_BTH_REQ_ACK;
651 if (qp->s_flags & HFI1_S_SEND_ONE) { 759 if (qp->s_flags & RVT_S_SEND_ONE) {
652 qp->s_flags &= ~HFI1_S_SEND_ONE; 760 qp->s_flags &= ~RVT_S_SEND_ONE;
653 qp->s_flags |= HFI1_S_WAIT_ACK; 761 qp->s_flags |= RVT_S_WAIT_ACK;
654 bth2 |= IB_BTH_REQ_ACK; 762 bth2 |= IB_BTH_REQ_ACK;
655 } 763 }
656 qp->s_len -= len; 764 qp->s_len -= len;
657 qp->s_hdrwords = hwords; 765 qp->s_hdrwords = hwords;
766 ps->s_txreq->sde = priv->s_sde;
658 qp->s_cur_sge = ss; 767 qp->s_cur_sge = ss;
659 qp->s_cur_size = len; 768 qp->s_cur_size = len;
660 hfi1_make_ruc_header( 769 hfi1_make_ruc_header(
@@ -662,16 +771,25 @@ int hfi1_make_rc_req(struct hfi1_qp *qp)
662 ohdr, 771 ohdr,
663 bth0 | (qp->s_state << 24), 772 bth0 | (qp->s_state << 24),
664 bth2, 773 bth2,
665 middle); 774 middle,
666done: 775 ps);
667 ret = 1; 776 /* pbc */
668 goto unlock; 777 ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2;
778 return 1;
779
780done_free_tx:
781 hfi1_put_txreq(ps->s_txreq);
782 ps->s_txreq = NULL;
783 return 1;
669 784
670bail: 785bail:
671 qp->s_flags &= ~HFI1_S_BUSY; 786 hfi1_put_txreq(ps->s_txreq);
672unlock: 787
673 spin_unlock_irqrestore(&qp->s_lock, flags); 788bail_no_tx:
674 return ret; 789 ps->s_txreq = NULL;
790 qp->s_flags &= ~RVT_S_BUSY;
791 qp->s_hdrwords = 0;
792 return 0;
675} 793}
676 794
677/** 795/**
@@ -682,7 +800,7 @@ unlock:
682 * Note that RDMA reads and atomics are handled in the 800 * Note that RDMA reads and atomics are handled in the
683 * send side QP state and tasklet. 801 * send side QP state and tasklet.
684 */ 802 */
685void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct hfi1_qp *qp, 803void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct rvt_qp *qp,
686 int is_fecn) 804 int is_fecn)
687{ 805{
688 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 806 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
@@ -700,7 +818,7 @@ void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct hfi1_qp *qp,
700 unsigned long flags; 818 unsigned long flags;
701 819
702 /* Don't send ACK or NAK if a RDMA read or atomic is pending. */ 820 /* Don't send ACK or NAK if a RDMA read or atomic is pending. */
703 if (qp->s_flags & HFI1_S_RESP_PENDING) 821 if (qp->s_flags & RVT_S_RESP_PENDING)
704 goto queue_ack; 822 goto queue_ack;
705 823
706 /* Ensure s_rdma_ack_cnt changes are committed */ 824 /* Ensure s_rdma_ack_cnt changes are committed */
@@ -763,7 +881,7 @@ void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct hfi1_qp *qp,
763 goto queue_ack; 881 goto queue_ack;
764 } 882 }
765 883
766 trace_output_ibhdr(dd_from_ibdev(qp->ibqp.device), &hdr); 884 trace_ack_output_ibhdr(dd_from_ibdev(qp->ibqp.device), &hdr);
767 885
768 /* write the pbc and data */ 886 /* write the pbc and data */
769 ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc, &hdr, hwords); 887 ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc, &hdr, hwords);
@@ -771,13 +889,13 @@ void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct hfi1_qp *qp,
771 return; 889 return;
772 890
773queue_ack: 891queue_ack:
774 this_cpu_inc(*ibp->rc_qacks); 892 this_cpu_inc(*ibp->rvp.rc_qacks);
775 spin_lock_irqsave(&qp->s_lock, flags); 893 spin_lock_irqsave(&qp->s_lock, flags);
776 qp->s_flags |= HFI1_S_ACK_PENDING | HFI1_S_RESP_PENDING; 894 qp->s_flags |= RVT_S_ACK_PENDING | RVT_S_RESP_PENDING;
777 qp->s_nak_state = qp->r_nak_state; 895 qp->s_nak_state = qp->r_nak_state;
778 qp->s_ack_psn = qp->r_ack_psn; 896 qp->s_ack_psn = qp->r_ack_psn;
779 if (is_fecn) 897 if (is_fecn)
780 qp->s_flags |= HFI1_S_ECN; 898 qp->s_flags |= RVT_S_ECN;
781 899
782 /* Schedule the send tasklet. */ 900 /* Schedule the send tasklet. */
783 hfi1_schedule_send(qp); 901 hfi1_schedule_send(qp);
@@ -793,10 +911,10 @@ queue_ack:
793 * for the given QP. 911 * for the given QP.
794 * Called at interrupt level with the QP s_lock held. 912 * Called at interrupt level with the QP s_lock held.
795 */ 913 */
796static void reset_psn(struct hfi1_qp *qp, u32 psn) 914static void reset_psn(struct rvt_qp *qp, u32 psn)
797{ 915{
798 u32 n = qp->s_acked; 916 u32 n = qp->s_acked;
799 struct hfi1_swqe *wqe = get_swqe_ptr(qp, n); 917 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, n);
800 u32 opcode; 918 u32 opcode;
801 919
802 qp->s_cur = n; 920 qp->s_cur = n;
@@ -819,7 +937,7 @@ static void reset_psn(struct hfi1_qp *qp, u32 psn)
819 n = 0; 937 n = 0;
820 if (n == qp->s_tail) 938 if (n == qp->s_tail)
821 break; 939 break;
822 wqe = get_swqe_ptr(qp, n); 940 wqe = rvt_get_swqe_ptr(qp, n);
823 diff = cmp_psn(psn, wqe->psn); 941 diff = cmp_psn(psn, wqe->psn);
824 if (diff < 0) 942 if (diff < 0)
825 break; 943 break;
@@ -865,23 +983,23 @@ static void reset_psn(struct hfi1_qp *qp, u32 psn)
865done: 983done:
866 qp->s_psn = psn; 984 qp->s_psn = psn;
867 /* 985 /*
868 * Set HFI1_S_WAIT_PSN as rc_complete() may start the timer 986 * Set RVT_S_WAIT_PSN as rc_complete() may start the timer
869 * asynchronously before the send tasklet can get scheduled. 987 * asynchronously before the send tasklet can get scheduled.
870 * Doing it in hfi1_make_rc_req() is too late. 988 * Doing it in hfi1_make_rc_req() is too late.
871 */ 989 */
872 if ((cmp_psn(qp->s_psn, qp->s_sending_hpsn) <= 0) && 990 if ((cmp_psn(qp->s_psn, qp->s_sending_hpsn) <= 0) &&
873 (cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)) 991 (cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0))
874 qp->s_flags |= HFI1_S_WAIT_PSN; 992 qp->s_flags |= RVT_S_WAIT_PSN;
875 qp->s_flags &= ~HFI1_S_AHG_VALID; 993 qp->s_flags &= ~RVT_S_AHG_VALID;
876} 994}
877 995
878/* 996/*
879 * Back up requester to resend the last un-ACKed request. 997 * Back up requester to resend the last un-ACKed request.
880 * The QP r_lock and s_lock should be held and interrupts disabled. 998 * The QP r_lock and s_lock should be held and interrupts disabled.
881 */ 999 */
882static void restart_rc(struct hfi1_qp *qp, u32 psn, int wait) 1000static void restart_rc(struct rvt_qp *qp, u32 psn, int wait)
883{ 1001{
884 struct hfi1_swqe *wqe = get_swqe_ptr(qp, qp->s_acked); 1002 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
885 struct hfi1_ibport *ibp; 1003 struct hfi1_ibport *ibp;
886 1004
887 if (qp->s_retry == 0) { 1005 if (qp->s_retry == 0) {
@@ -890,42 +1008,44 @@ static void restart_rc(struct hfi1_qp *qp, u32 psn, int wait)
890 qp->s_retry = qp->s_retry_cnt; 1008 qp->s_retry = qp->s_retry_cnt;
891 } else if (qp->s_last == qp->s_acked) { 1009 } else if (qp->s_last == qp->s_acked) {
892 hfi1_send_complete(qp, wqe, IB_WC_RETRY_EXC_ERR); 1010 hfi1_send_complete(qp, wqe, IB_WC_RETRY_EXC_ERR);
893 hfi1_error_qp(qp, IB_WC_WR_FLUSH_ERR); 1011 rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
894 return; 1012 return;
895 } else /* need to handle delayed completion */ 1013 } else { /* need to handle delayed completion */
896 return; 1014 return;
897 } else 1015 }
1016 } else {
898 qp->s_retry--; 1017 qp->s_retry--;
1018 }
899 1019
900 ibp = to_iport(qp->ibqp.device, qp->port_num); 1020 ibp = to_iport(qp->ibqp.device, qp->port_num);
901 if (wqe->wr.opcode == IB_WR_RDMA_READ) 1021 if (wqe->wr.opcode == IB_WR_RDMA_READ)
902 ibp->n_rc_resends++; 1022 ibp->rvp.n_rc_resends++;
903 else 1023 else
904 ibp->n_rc_resends += delta_psn(qp->s_psn, psn); 1024 ibp->rvp.n_rc_resends += delta_psn(qp->s_psn, psn);
905 1025
906 qp->s_flags &= ~(HFI1_S_WAIT_FENCE | HFI1_S_WAIT_RDMAR | 1026 qp->s_flags &= ~(RVT_S_WAIT_FENCE | RVT_S_WAIT_RDMAR |
907 HFI1_S_WAIT_SSN_CREDIT | HFI1_S_WAIT_PSN | 1027 RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_PSN |
908 HFI1_S_WAIT_ACK); 1028 RVT_S_WAIT_ACK);
909 if (wait) 1029 if (wait)
910 qp->s_flags |= HFI1_S_SEND_ONE; 1030 qp->s_flags |= RVT_S_SEND_ONE;
911 reset_psn(qp, psn); 1031 reset_psn(qp, psn);
912} 1032}
913 1033
914/* 1034/*
915 * This is called from s_timer for missing responses. 1035 * This is called from s_timer for missing responses.
916 */ 1036 */
917static void rc_timeout(unsigned long arg) 1037void hfi1_rc_timeout(unsigned long arg)
918{ 1038{
919 struct hfi1_qp *qp = (struct hfi1_qp *)arg; 1039 struct rvt_qp *qp = (struct rvt_qp *)arg;
920 struct hfi1_ibport *ibp; 1040 struct hfi1_ibport *ibp;
921 unsigned long flags; 1041 unsigned long flags;
922 1042
923 spin_lock_irqsave(&qp->r_lock, flags); 1043 spin_lock_irqsave(&qp->r_lock, flags);
924 spin_lock(&qp->s_lock); 1044 spin_lock(&qp->s_lock);
925 if (qp->s_flags & HFI1_S_TIMER) { 1045 if (qp->s_flags & RVT_S_TIMER) {
926 ibp = to_iport(qp->ibqp.device, qp->port_num); 1046 ibp = to_iport(qp->ibqp.device, qp->port_num);
927 ibp->n_rc_timeouts++; 1047 ibp->rvp.n_rc_timeouts++;
928 qp->s_flags &= ~HFI1_S_TIMER; 1048 qp->s_flags &= ~RVT_S_TIMER;
929 del_timer(&qp->s_timer); 1049 del_timer(&qp->s_timer);
930 trace_hfi1_rc_timeout(qp, qp->s_last_psn + 1); 1050 trace_hfi1_rc_timeout(qp, qp->s_last_psn + 1);
931 restart_rc(qp, qp->s_last_psn + 1, 1); 1051 restart_rc(qp, qp->s_last_psn + 1, 1);
@@ -940,15 +1060,12 @@ static void rc_timeout(unsigned long arg)
940 */ 1060 */
941void hfi1_rc_rnr_retry(unsigned long arg) 1061void hfi1_rc_rnr_retry(unsigned long arg)
942{ 1062{
943 struct hfi1_qp *qp = (struct hfi1_qp *)arg; 1063 struct rvt_qp *qp = (struct rvt_qp *)arg;
944 unsigned long flags; 1064 unsigned long flags;
945 1065
946 spin_lock_irqsave(&qp->s_lock, flags); 1066 spin_lock_irqsave(&qp->s_lock, flags);
947 if (qp->s_flags & HFI1_S_WAIT_RNR) { 1067 hfi1_stop_rnr_timer(qp);
948 qp->s_flags &= ~HFI1_S_WAIT_RNR; 1068 hfi1_schedule_send(qp);
949 del_timer(&qp->s_timer);
950 hfi1_schedule_send(qp);
951 }
952 spin_unlock_irqrestore(&qp->s_lock, flags); 1069 spin_unlock_irqrestore(&qp->s_lock, flags);
953} 1070}
954 1071
@@ -956,14 +1073,14 @@ void hfi1_rc_rnr_retry(unsigned long arg)
956 * Set qp->s_sending_psn to the next PSN after the given one. 1073 * Set qp->s_sending_psn to the next PSN after the given one.
957 * This would be psn+1 except when RDMA reads are present. 1074 * This would be psn+1 except when RDMA reads are present.
958 */ 1075 */
959static void reset_sending_psn(struct hfi1_qp *qp, u32 psn) 1076static void reset_sending_psn(struct rvt_qp *qp, u32 psn)
960{ 1077{
961 struct hfi1_swqe *wqe; 1078 struct rvt_swqe *wqe;
962 u32 n = qp->s_last; 1079 u32 n = qp->s_last;
963 1080
964 /* Find the work request corresponding to the given PSN. */ 1081 /* Find the work request corresponding to the given PSN. */
965 for (;;) { 1082 for (;;) {
966 wqe = get_swqe_ptr(qp, n); 1083 wqe = rvt_get_swqe_ptr(qp, n);
967 if (cmp_psn(psn, wqe->lpsn) <= 0) { 1084 if (cmp_psn(psn, wqe->lpsn) <= 0) {
968 if (wqe->wr.opcode == IB_WR_RDMA_READ) 1085 if (wqe->wr.opcode == IB_WR_RDMA_READ)
969 qp->s_sending_psn = wqe->lpsn + 1; 1086 qp->s_sending_psn = wqe->lpsn + 1;
@@ -981,16 +1098,16 @@ static void reset_sending_psn(struct hfi1_qp *qp, u32 psn)
981/* 1098/*
982 * This should be called with the QP s_lock held and interrupts disabled. 1099 * This should be called with the QP s_lock held and interrupts disabled.
983 */ 1100 */
984void hfi1_rc_send_complete(struct hfi1_qp *qp, struct hfi1_ib_header *hdr) 1101void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_ib_header *hdr)
985{ 1102{
986 struct hfi1_other_headers *ohdr; 1103 struct hfi1_other_headers *ohdr;
987 struct hfi1_swqe *wqe; 1104 struct rvt_swqe *wqe;
988 struct ib_wc wc; 1105 struct ib_wc wc;
989 unsigned i; 1106 unsigned i;
990 u32 opcode; 1107 u32 opcode;
991 u32 psn; 1108 u32 psn;
992 1109
993 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_OR_FLUSH_SEND)) 1110 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND))
994 return; 1111 return;
995 1112
996 /* Find out where the BTH is */ 1113 /* Find out where the BTH is */
@@ -1016,22 +1133,30 @@ void hfi1_rc_send_complete(struct hfi1_qp *qp, struct hfi1_ib_header *hdr)
1016 */ 1133 */
1017 if ((psn & IB_BTH_REQ_ACK) && qp->s_acked != qp->s_tail && 1134 if ((psn & IB_BTH_REQ_ACK) && qp->s_acked != qp->s_tail &&
1018 !(qp->s_flags & 1135 !(qp->s_flags &
1019 (HFI1_S_TIMER | HFI1_S_WAIT_RNR | HFI1_S_WAIT_PSN)) && 1136 (RVT_S_TIMER | RVT_S_WAIT_RNR | RVT_S_WAIT_PSN)) &&
1020 (ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK)) 1137 (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
1021 start_timer(qp); 1138 hfi1_add_retry_timer(qp);
1022 1139
1023 while (qp->s_last != qp->s_acked) { 1140 while (qp->s_last != qp->s_acked) {
1024 wqe = get_swqe_ptr(qp, qp->s_last); 1141 u32 s_last;
1142
1143 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
1025 if (cmp_psn(wqe->lpsn, qp->s_sending_psn) >= 0 && 1144 if (cmp_psn(wqe->lpsn, qp->s_sending_psn) >= 0 &&
1026 cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) 1145 cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)
1027 break; 1146 break;
1147 s_last = qp->s_last;
1148 if (++s_last >= qp->s_size)
1149 s_last = 0;
1150 qp->s_last = s_last;
1151 /* see post_send() */
1152 barrier();
1028 for (i = 0; i < wqe->wr.num_sge; i++) { 1153 for (i = 0; i < wqe->wr.num_sge; i++) {
1029 struct hfi1_sge *sge = &wqe->sg_list[i]; 1154 struct rvt_sge *sge = &wqe->sg_list[i];
1030 1155
1031 hfi1_put_mr(sge->mr); 1156 rvt_put_mr(sge->mr);
1032 } 1157 }
1033 /* Post a send completion queue entry if requested. */ 1158 /* Post a send completion queue entry if requested. */
1034 if (!(qp->s_flags & HFI1_S_SIGNAL_REQ_WR) || 1159 if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) ||
1035 (wqe->wr.send_flags & IB_SEND_SIGNALED)) { 1160 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
1036 memset(&wc, 0, sizeof(wc)); 1161 memset(&wc, 0, sizeof(wc));
1037 wc.wr_id = wqe->wr.wr_id; 1162 wc.wr_id = wqe->wr.wr_id;
@@ -1039,26 +1164,24 @@ void hfi1_rc_send_complete(struct hfi1_qp *qp, struct hfi1_ib_header *hdr)
1039 wc.opcode = ib_hfi1_wc_opcode[wqe->wr.opcode]; 1164 wc.opcode = ib_hfi1_wc_opcode[wqe->wr.opcode];
1040 wc.byte_len = wqe->length; 1165 wc.byte_len = wqe->length;
1041 wc.qp = &qp->ibqp; 1166 wc.qp = &qp->ibqp;
1042 hfi1_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0); 1167 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc, 0);
1043 } 1168 }
1044 if (++qp->s_last >= qp->s_size)
1045 qp->s_last = 0;
1046 } 1169 }
1047 /* 1170 /*
1048 * If we were waiting for sends to complete before re-sending, 1171 * If we were waiting for sends to complete before re-sending,
1049 * and they are now complete, restart sending. 1172 * and they are now complete, restart sending.
1050 */ 1173 */
1051 trace_hfi1_rc_sendcomplete(qp, psn); 1174 trace_hfi1_rc_sendcomplete(qp, psn);
1052 if (qp->s_flags & HFI1_S_WAIT_PSN && 1175 if (qp->s_flags & RVT_S_WAIT_PSN &&
1053 cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) > 0) { 1176 cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
1054 qp->s_flags &= ~HFI1_S_WAIT_PSN; 1177 qp->s_flags &= ~RVT_S_WAIT_PSN;
1055 qp->s_sending_psn = qp->s_psn; 1178 qp->s_sending_psn = qp->s_psn;
1056 qp->s_sending_hpsn = qp->s_psn - 1; 1179 qp->s_sending_hpsn = qp->s_psn - 1;
1057 hfi1_schedule_send(qp); 1180 hfi1_schedule_send(qp);
1058 } 1181 }
1059} 1182}
1060 1183
1061static inline void update_last_psn(struct hfi1_qp *qp, u32 psn) 1184static inline void update_last_psn(struct rvt_qp *qp, u32 psn)
1062{ 1185{
1063 qp->s_last_psn = psn; 1186 qp->s_last_psn = psn;
1064} 1187}
@@ -1068,9 +1191,9 @@ static inline void update_last_psn(struct hfi1_qp *qp, u32 psn)
1068 * This is similar to hfi1_send_complete but has to check to be sure 1191 * This is similar to hfi1_send_complete but has to check to be sure
1069 * that the SGEs are not being referenced if the SWQE is being resent. 1192 * that the SGEs are not being referenced if the SWQE is being resent.
1070 */ 1193 */
1071static struct hfi1_swqe *do_rc_completion(struct hfi1_qp *qp, 1194static struct rvt_swqe *do_rc_completion(struct rvt_qp *qp,
1072 struct hfi1_swqe *wqe, 1195 struct rvt_swqe *wqe,
1073 struct hfi1_ibport *ibp) 1196 struct hfi1_ibport *ibp)
1074{ 1197{
1075 struct ib_wc wc; 1198 struct ib_wc wc;
1076 unsigned i; 1199 unsigned i;
@@ -1082,13 +1205,21 @@ static struct hfi1_swqe *do_rc_completion(struct hfi1_qp *qp,
1082 */ 1205 */
1083 if (cmp_psn(wqe->lpsn, qp->s_sending_psn) < 0 || 1206 if (cmp_psn(wqe->lpsn, qp->s_sending_psn) < 0 ||
1084 cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) > 0) { 1207 cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
1208 u32 s_last;
1209
1085 for (i = 0; i < wqe->wr.num_sge; i++) { 1210 for (i = 0; i < wqe->wr.num_sge; i++) {
1086 struct hfi1_sge *sge = &wqe->sg_list[i]; 1211 struct rvt_sge *sge = &wqe->sg_list[i];
1087 1212
1088 hfi1_put_mr(sge->mr); 1213 rvt_put_mr(sge->mr);
1089 } 1214 }
1215 s_last = qp->s_last;
1216 if (++s_last >= qp->s_size)
1217 s_last = 0;
1218 qp->s_last = s_last;
1219 /* see post_send() */
1220 barrier();
1090 /* Post a send completion queue entry if requested. */ 1221 /* Post a send completion queue entry if requested. */
1091 if (!(qp->s_flags & HFI1_S_SIGNAL_REQ_WR) || 1222 if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) ||
1092 (wqe->wr.send_flags & IB_SEND_SIGNALED)) { 1223 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
1093 memset(&wc, 0, sizeof(wc)); 1224 memset(&wc, 0, sizeof(wc));
1094 wc.wr_id = wqe->wr.wr_id; 1225 wc.wr_id = wqe->wr.wr_id;
@@ -1096,14 +1227,12 @@ static struct hfi1_swqe *do_rc_completion(struct hfi1_qp *qp,
1096 wc.opcode = ib_hfi1_wc_opcode[wqe->wr.opcode]; 1227 wc.opcode = ib_hfi1_wc_opcode[wqe->wr.opcode];
1097 wc.byte_len = wqe->length; 1228 wc.byte_len = wqe->length;
1098 wc.qp = &qp->ibqp; 1229 wc.qp = &qp->ibqp;
1099 hfi1_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0); 1230 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc, 0);
1100 } 1231 }
1101 if (++qp->s_last >= qp->s_size)
1102 qp->s_last = 0;
1103 } else { 1232 } else {
1104 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 1233 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1105 1234
1106 this_cpu_inc(*ibp->rc_delayed_comp); 1235 this_cpu_inc(*ibp->rvp.rc_delayed_comp);
1107 /* 1236 /*
1108 * If send progress not running attempt to progress 1237 * If send progress not running attempt to progress
1109 * SDMA queue. 1238 * SDMA queue.
@@ -1131,7 +1260,7 @@ static struct hfi1_swqe *do_rc_completion(struct hfi1_qp *qp,
1131 if (++qp->s_cur >= qp->s_size) 1260 if (++qp->s_cur >= qp->s_size)
1132 qp->s_cur = 0; 1261 qp->s_cur = 0;
1133 qp->s_acked = qp->s_cur; 1262 qp->s_acked = qp->s_cur;
1134 wqe = get_swqe_ptr(qp, qp->s_cur); 1263 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
1135 if (qp->s_acked != qp->s_tail) { 1264 if (qp->s_acked != qp->s_tail) {
1136 qp->s_state = OP(SEND_LAST); 1265 qp->s_state = OP(SEND_LAST);
1137 qp->s_psn = wqe->psn; 1266 qp->s_psn = wqe->psn;
@@ -1141,7 +1270,7 @@ static struct hfi1_swqe *do_rc_completion(struct hfi1_qp *qp,
1141 qp->s_acked = 0; 1270 qp->s_acked = 0;
1142 if (qp->state == IB_QPS_SQD && qp->s_acked == qp->s_cur) 1271 if (qp->state == IB_QPS_SQD && qp->s_acked == qp->s_cur)
1143 qp->s_draining = 0; 1272 qp->s_draining = 0;
1144 wqe = get_swqe_ptr(qp, qp->s_acked); 1273 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1145 } 1274 }
1146 return wqe; 1275 return wqe;
1147} 1276}
@@ -1157,21 +1286,16 @@ static struct hfi1_swqe *do_rc_completion(struct hfi1_qp *qp,
1157 * May be called at interrupt level, with the QP s_lock held. 1286 * May be called at interrupt level, with the QP s_lock held.
1158 * Returns 1 if OK, 0 if current operation should be aborted (NAK). 1287 * Returns 1 if OK, 0 if current operation should be aborted (NAK).
1159 */ 1288 */
1160static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode, 1289static int do_rc_ack(struct rvt_qp *qp, u32 aeth, u32 psn, int opcode,
1161 u64 val, struct hfi1_ctxtdata *rcd) 1290 u64 val, struct hfi1_ctxtdata *rcd)
1162{ 1291{
1163 struct hfi1_ibport *ibp; 1292 struct hfi1_ibport *ibp;
1164 enum ib_wc_status status; 1293 enum ib_wc_status status;
1165 struct hfi1_swqe *wqe; 1294 struct rvt_swqe *wqe;
1166 int ret = 0; 1295 int ret = 0;
1167 u32 ack_psn; 1296 u32 ack_psn;
1168 int diff; 1297 int diff;
1169 1298 unsigned long to;
1170 /* Remove QP from retry timer */
1171 if (qp->s_flags & (HFI1_S_TIMER | HFI1_S_WAIT_RNR)) {
1172 qp->s_flags &= ~(HFI1_S_TIMER | HFI1_S_WAIT_RNR);
1173 del_timer(&qp->s_timer);
1174 }
1175 1299
1176 /* 1300 /*
1177 * Note that NAKs implicitly ACK outstanding SEND and RDMA write 1301 * Note that NAKs implicitly ACK outstanding SEND and RDMA write
@@ -1182,7 +1306,7 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1182 ack_psn = psn; 1306 ack_psn = psn;
1183 if (aeth >> 29) 1307 if (aeth >> 29)
1184 ack_psn--; 1308 ack_psn--;
1185 wqe = get_swqe_ptr(qp, qp->s_acked); 1309 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1186 ibp = to_iport(qp->ibqp.device, qp->port_num); 1310 ibp = to_iport(qp->ibqp.device, qp->port_num);
1187 1311
1188 /* 1312 /*
@@ -1200,7 +1324,7 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1200 opcode == OP(RDMA_READ_RESPONSE_ONLY) && 1324 opcode == OP(RDMA_READ_RESPONSE_ONLY) &&
1201 diff == 0) { 1325 diff == 0) {
1202 ret = 1; 1326 ret = 1;
1203 goto bail; 1327 goto bail_stop;
1204 } 1328 }
1205 /* 1329 /*
1206 * If this request is a RDMA read or atomic, and the ACK is 1330 * If this request is a RDMA read or atomic, and the ACK is
@@ -1217,11 +1341,11 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1217 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) && 1341 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) &&
1218 (opcode != OP(ATOMIC_ACKNOWLEDGE) || diff != 0))) { 1342 (opcode != OP(ATOMIC_ACKNOWLEDGE) || diff != 0))) {
1219 /* Retry this request. */ 1343 /* Retry this request. */
1220 if (!(qp->r_flags & HFI1_R_RDMAR_SEQ)) { 1344 if (!(qp->r_flags & RVT_R_RDMAR_SEQ)) {
1221 qp->r_flags |= HFI1_R_RDMAR_SEQ; 1345 qp->r_flags |= RVT_R_RDMAR_SEQ;
1222 restart_rc(qp, qp->s_last_psn + 1, 0); 1346 restart_rc(qp, qp->s_last_psn + 1, 0);
1223 if (list_empty(&qp->rspwait)) { 1347 if (list_empty(&qp->rspwait)) {
1224 qp->r_flags |= HFI1_R_RSP_SEND; 1348 qp->r_flags |= RVT_R_RSP_SEND;
1225 atomic_inc(&qp->refcount); 1349 atomic_inc(&qp->refcount);
1226 list_add_tail(&qp->rspwait, 1350 list_add_tail(&qp->rspwait,
1227 &rcd->qp_wait_list); 1351 &rcd->qp_wait_list);
@@ -1231,7 +1355,7 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1231 * No need to process the ACK/NAK since we are 1355 * No need to process the ACK/NAK since we are
1232 * restarting an earlier request. 1356 * restarting an earlier request.
1233 */ 1357 */
1234 goto bail; 1358 goto bail_stop;
1235 } 1359 }
1236 if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP || 1360 if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
1237 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) { 1361 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
@@ -1244,14 +1368,14 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1244 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)) { 1368 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)) {
1245 qp->s_num_rd_atomic--; 1369 qp->s_num_rd_atomic--;
1246 /* Restart sending task if fence is complete */ 1370 /* Restart sending task if fence is complete */
1247 if ((qp->s_flags & HFI1_S_WAIT_FENCE) && 1371 if ((qp->s_flags & RVT_S_WAIT_FENCE) &&
1248 !qp->s_num_rd_atomic) { 1372 !qp->s_num_rd_atomic) {
1249 qp->s_flags &= ~(HFI1_S_WAIT_FENCE | 1373 qp->s_flags &= ~(RVT_S_WAIT_FENCE |
1250 HFI1_S_WAIT_ACK); 1374 RVT_S_WAIT_ACK);
1251 hfi1_schedule_send(qp); 1375 hfi1_schedule_send(qp);
1252 } else if (qp->s_flags & HFI1_S_WAIT_RDMAR) { 1376 } else if (qp->s_flags & RVT_S_WAIT_RDMAR) {
1253 qp->s_flags &= ~(HFI1_S_WAIT_RDMAR | 1377 qp->s_flags &= ~(RVT_S_WAIT_RDMAR |
1254 HFI1_S_WAIT_ACK); 1378 RVT_S_WAIT_ACK);
1255 hfi1_schedule_send(qp); 1379 hfi1_schedule_send(qp);
1256 } 1380 }
1257 } 1381 }
@@ -1262,40 +1386,43 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1262 1386
1263 switch (aeth >> 29) { 1387 switch (aeth >> 29) {
1264 case 0: /* ACK */ 1388 case 0: /* ACK */
1265 this_cpu_inc(*ibp->rc_acks); 1389 this_cpu_inc(*ibp->rvp.rc_acks);
1266 if (qp->s_acked != qp->s_tail) { 1390 if (qp->s_acked != qp->s_tail) {
1267 /* 1391 /*
1268 * We are expecting more ACKs so 1392 * We are expecting more ACKs so
1269 * reset the re-transmit timer. 1393 * mod the retry timer.
1270 */ 1394 */
1271 start_timer(qp); 1395 hfi1_mod_retry_timer(qp);
1272 /* 1396 /*
1273 * We can stop re-sending the earlier packets and 1397 * We can stop re-sending the earlier packets and
1274 * continue with the next packet the receiver wants. 1398 * continue with the next packet the receiver wants.
1275 */ 1399 */
1276 if (cmp_psn(qp->s_psn, psn) <= 0) 1400 if (cmp_psn(qp->s_psn, psn) <= 0)
1277 reset_psn(qp, psn + 1); 1401 reset_psn(qp, psn + 1);
1278 } else if (cmp_psn(qp->s_psn, psn) <= 0) { 1402 } else {
1279 qp->s_state = OP(SEND_LAST); 1403 /* No more acks - kill all timers */
1280 qp->s_psn = psn + 1; 1404 hfi1_stop_rc_timers(qp);
1405 if (cmp_psn(qp->s_psn, psn) <= 0) {
1406 qp->s_state = OP(SEND_LAST);
1407 qp->s_psn = psn + 1;
1408 }
1281 } 1409 }
1282 if (qp->s_flags & HFI1_S_WAIT_ACK) { 1410 if (qp->s_flags & RVT_S_WAIT_ACK) {
1283 qp->s_flags &= ~HFI1_S_WAIT_ACK; 1411 qp->s_flags &= ~RVT_S_WAIT_ACK;
1284 hfi1_schedule_send(qp); 1412 hfi1_schedule_send(qp);
1285 } 1413 }
1286 hfi1_get_credit(qp, aeth); 1414 hfi1_get_credit(qp, aeth);
1287 qp->s_rnr_retry = qp->s_rnr_retry_cnt; 1415 qp->s_rnr_retry = qp->s_rnr_retry_cnt;
1288 qp->s_retry = qp->s_retry_cnt; 1416 qp->s_retry = qp->s_retry_cnt;
1289 update_last_psn(qp, psn); 1417 update_last_psn(qp, psn);
1290 ret = 1; 1418 return 1;
1291 goto bail;
1292 1419
1293 case 1: /* RNR NAK */ 1420 case 1: /* RNR NAK */
1294 ibp->n_rnr_naks++; 1421 ibp->rvp.n_rnr_naks++;
1295 if (qp->s_acked == qp->s_tail) 1422 if (qp->s_acked == qp->s_tail)
1296 goto bail; 1423 goto bail_stop;
1297 if (qp->s_flags & HFI1_S_WAIT_RNR) 1424 if (qp->s_flags & RVT_S_WAIT_RNR)
1298 goto bail; 1425 goto bail_stop;
1299 if (qp->s_rnr_retry == 0) { 1426 if (qp->s_rnr_retry == 0) {
1300 status = IB_WC_RNR_RETRY_EXC_ERR; 1427 status = IB_WC_RNR_RETRY_EXC_ERR;
1301 goto class_b; 1428 goto class_b;
@@ -1306,28 +1433,27 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1306 /* The last valid PSN is the previous PSN. */ 1433 /* The last valid PSN is the previous PSN. */
1307 update_last_psn(qp, psn - 1); 1434 update_last_psn(qp, psn - 1);
1308 1435
1309 ibp->n_rc_resends += delta_psn(qp->s_psn, psn); 1436 ibp->rvp.n_rc_resends += delta_psn(qp->s_psn, psn);
1310 1437
1311 reset_psn(qp, psn); 1438 reset_psn(qp, psn);
1312 1439
1313 qp->s_flags &= ~(HFI1_S_WAIT_SSN_CREDIT | HFI1_S_WAIT_ACK); 1440 qp->s_flags &= ~(RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_ACK);
1314 qp->s_flags |= HFI1_S_WAIT_RNR; 1441 hfi1_stop_rc_timers(qp);
1315 qp->s_timer.function = hfi1_rc_rnr_retry; 1442 to =
1316 qp->s_timer.expires = jiffies + usecs_to_jiffies(
1317 ib_hfi1_rnr_table[(aeth >> HFI1_AETH_CREDIT_SHIFT) & 1443 ib_hfi1_rnr_table[(aeth >> HFI1_AETH_CREDIT_SHIFT) &
1318 HFI1_AETH_CREDIT_MASK]); 1444 HFI1_AETH_CREDIT_MASK];
1319 add_timer(&qp->s_timer); 1445 hfi1_add_rnr_timer(qp, to);
1320 goto bail; 1446 return 0;
1321 1447
1322 case 3: /* NAK */ 1448 case 3: /* NAK */
1323 if (qp->s_acked == qp->s_tail) 1449 if (qp->s_acked == qp->s_tail)
1324 goto bail; 1450 goto bail_stop;
1325 /* The last valid PSN is the previous PSN. */ 1451 /* The last valid PSN is the previous PSN. */
1326 update_last_psn(qp, psn - 1); 1452 update_last_psn(qp, psn - 1);
1327 switch ((aeth >> HFI1_AETH_CREDIT_SHIFT) & 1453 switch ((aeth >> HFI1_AETH_CREDIT_SHIFT) &
1328 HFI1_AETH_CREDIT_MASK) { 1454 HFI1_AETH_CREDIT_MASK) {
1329 case 0: /* PSN sequence error */ 1455 case 0: /* PSN sequence error */
1330 ibp->n_seq_naks++; 1456 ibp->rvp.n_seq_naks++;
1331 /* 1457 /*
1332 * Back up to the responder's expected PSN. 1458 * Back up to the responder's expected PSN.
1333 * Note that we might get a NAK in the middle of an 1459 * Note that we might get a NAK in the middle of an
@@ -1340,21 +1466,21 @@ static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
1340 1466
1341 case 1: /* Invalid Request */ 1467 case 1: /* Invalid Request */
1342 status = IB_WC_REM_INV_REQ_ERR; 1468 status = IB_WC_REM_INV_REQ_ERR;
1343 ibp->n_other_naks++; 1469 ibp->rvp.n_other_naks++;
1344 goto class_b; 1470 goto class_b;
1345 1471
1346 case 2: /* Remote Access Error */ 1472 case 2: /* Remote Access Error */
1347 status = IB_WC_REM_ACCESS_ERR; 1473 status = IB_WC_REM_ACCESS_ERR;
1348 ibp->n_other_naks++; 1474 ibp->rvp.n_other_naks++;
1349 goto class_b; 1475 goto class_b;
1350 1476
1351 case 3: /* Remote Operation Error */ 1477 case 3: /* Remote Operation Error */
1352 status = IB_WC_REM_OP_ERR; 1478 status = IB_WC_REM_OP_ERR;
1353 ibp->n_other_naks++; 1479 ibp->rvp.n_other_naks++;
1354class_b: 1480class_b:
1355 if (qp->s_last == qp->s_acked) { 1481 if (qp->s_last == qp->s_acked) {
1356 hfi1_send_complete(qp, wqe, status); 1482 hfi1_send_complete(qp, wqe, status);
1357 hfi1_error_qp(qp, IB_WC_WR_FLUSH_ERR); 1483 rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
1358 } 1484 }
1359 break; 1485 break;
1360 1486
@@ -1364,15 +1490,16 @@ class_b:
1364 } 1490 }
1365 qp->s_retry = qp->s_retry_cnt; 1491 qp->s_retry = qp->s_retry_cnt;
1366 qp->s_rnr_retry = qp->s_rnr_retry_cnt; 1492 qp->s_rnr_retry = qp->s_rnr_retry_cnt;
1367 goto bail; 1493 goto bail_stop;
1368 1494
1369 default: /* 2: reserved */ 1495 default: /* 2: reserved */
1370reserved: 1496reserved:
1371 /* Ignore reserved NAK codes. */ 1497 /* Ignore reserved NAK codes. */
1372 goto bail; 1498 goto bail_stop;
1373 } 1499 }
1374 1500 return ret;
1375bail: 1501bail_stop:
1502 hfi1_stop_rc_timers(qp);
1376 return ret; 1503 return ret;
1377} 1504}
1378 1505
@@ -1380,18 +1507,15 @@ bail:
1380 * We have seen an out of sequence RDMA read middle or last packet. 1507 * We have seen an out of sequence RDMA read middle or last packet.
1381 * This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE. 1508 * This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE.
1382 */ 1509 */
1383static void rdma_seq_err(struct hfi1_qp *qp, struct hfi1_ibport *ibp, u32 psn, 1510static void rdma_seq_err(struct rvt_qp *qp, struct hfi1_ibport *ibp, u32 psn,
1384 struct hfi1_ctxtdata *rcd) 1511 struct hfi1_ctxtdata *rcd)
1385{ 1512{
1386 struct hfi1_swqe *wqe; 1513 struct rvt_swqe *wqe;
1387 1514
1388 /* Remove QP from retry timer */ 1515 /* Remove QP from retry timer */
1389 if (qp->s_flags & (HFI1_S_TIMER | HFI1_S_WAIT_RNR)) { 1516 hfi1_stop_rc_timers(qp);
1390 qp->s_flags &= ~(HFI1_S_TIMER | HFI1_S_WAIT_RNR);
1391 del_timer(&qp->s_timer);
1392 }
1393 1517
1394 wqe = get_swqe_ptr(qp, qp->s_acked); 1518 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1395 1519
1396 while (cmp_psn(psn, wqe->lpsn) > 0) { 1520 while (cmp_psn(psn, wqe->lpsn) > 0) {
1397 if (wqe->wr.opcode == IB_WR_RDMA_READ || 1521 if (wqe->wr.opcode == IB_WR_RDMA_READ ||
@@ -1401,11 +1525,11 @@ static void rdma_seq_err(struct hfi1_qp *qp, struct hfi1_ibport *ibp, u32 psn,
1401 wqe = do_rc_completion(qp, wqe, ibp); 1525 wqe = do_rc_completion(qp, wqe, ibp);
1402 } 1526 }
1403 1527
1404 ibp->n_rdma_seq++; 1528 ibp->rvp.n_rdma_seq++;
1405 qp->r_flags |= HFI1_R_RDMAR_SEQ; 1529 qp->r_flags |= RVT_R_RDMAR_SEQ;
1406 restart_rc(qp, qp->s_last_psn + 1, 0); 1530 restart_rc(qp, qp->s_last_psn + 1, 0);
1407 if (list_empty(&qp->rspwait)) { 1531 if (list_empty(&qp->rspwait)) {
1408 qp->r_flags |= HFI1_R_RSP_SEND; 1532 qp->r_flags |= RVT_R_RSP_SEND;
1409 atomic_inc(&qp->refcount); 1533 atomic_inc(&qp->refcount);
1410 list_add_tail(&qp->rspwait, &rcd->qp_wait_list); 1534 list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
1411 } 1535 }
@@ -1429,11 +1553,11 @@ static void rdma_seq_err(struct hfi1_qp *qp, struct hfi1_ibport *ibp, u32 psn,
1429 */ 1553 */
1430static void rc_rcv_resp(struct hfi1_ibport *ibp, 1554static void rc_rcv_resp(struct hfi1_ibport *ibp,
1431 struct hfi1_other_headers *ohdr, 1555 struct hfi1_other_headers *ohdr,
1432 void *data, u32 tlen, struct hfi1_qp *qp, 1556 void *data, u32 tlen, struct rvt_qp *qp,
1433 u32 opcode, u32 psn, u32 hdrsize, u32 pmtu, 1557 u32 opcode, u32 psn, u32 hdrsize, u32 pmtu,
1434 struct hfi1_ctxtdata *rcd) 1558 struct hfi1_ctxtdata *rcd)
1435{ 1559{
1436 struct hfi1_swqe *wqe; 1560 struct rvt_swqe *wqe;
1437 enum ib_wc_status status; 1561 enum ib_wc_status status;
1438 unsigned long flags; 1562 unsigned long flags;
1439 int diff; 1563 int diff;
@@ -1446,7 +1570,8 @@ static void rc_rcv_resp(struct hfi1_ibport *ibp,
1446 trace_hfi1_rc_ack(qp, psn); 1570 trace_hfi1_rc_ack(qp, psn);
1447 1571
1448 /* Ignore invalid responses. */ 1572 /* Ignore invalid responses. */
1449 if (cmp_psn(psn, qp->s_next_psn) >= 0) 1573 smp_read_barrier_depends(); /* see post_one_send */
1574 if (cmp_psn(psn, ACCESS_ONCE(qp->s_next_psn)) >= 0)
1450 goto ack_done; 1575 goto ack_done;
1451 1576
1452 /* Ignore duplicate responses. */ 1577 /* Ignore duplicate responses. */
@@ -1465,15 +1590,15 @@ static void rc_rcv_resp(struct hfi1_ibport *ibp,
1465 * Skip everything other than the PSN we expect, if we are waiting 1590 * Skip everything other than the PSN we expect, if we are waiting
1466 * for a reply to a restarted RDMA read or atomic op. 1591 * for a reply to a restarted RDMA read or atomic op.
1467 */ 1592 */
1468 if (qp->r_flags & HFI1_R_RDMAR_SEQ) { 1593 if (qp->r_flags & RVT_R_RDMAR_SEQ) {
1469 if (cmp_psn(psn, qp->s_last_psn + 1) != 0) 1594 if (cmp_psn(psn, qp->s_last_psn + 1) != 0)
1470 goto ack_done; 1595 goto ack_done;
1471 qp->r_flags &= ~HFI1_R_RDMAR_SEQ; 1596 qp->r_flags &= ~RVT_R_RDMAR_SEQ;
1472 } 1597 }
1473 1598
1474 if (unlikely(qp->s_acked == qp->s_tail)) 1599 if (unlikely(qp->s_acked == qp->s_tail))
1475 goto ack_done; 1600 goto ack_done;
1476 wqe = get_swqe_ptr(qp, qp->s_acked); 1601 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1477 status = IB_WC_SUCCESS; 1602 status = IB_WC_SUCCESS;
1478 1603
1479 switch (opcode) { 1604 switch (opcode) {
@@ -1484,14 +1609,15 @@ static void rc_rcv_resp(struct hfi1_ibport *ibp,
1484 if (opcode == OP(ATOMIC_ACKNOWLEDGE)) { 1609 if (opcode == OP(ATOMIC_ACKNOWLEDGE)) {
1485 __be32 *p = ohdr->u.at.atomic_ack_eth; 1610 __be32 *p = ohdr->u.at.atomic_ack_eth;
1486 1611
1487 val = ((u64) be32_to_cpu(p[0]) << 32) | 1612 val = ((u64)be32_to_cpu(p[0]) << 32) |
1488 be32_to_cpu(p[1]); 1613 be32_to_cpu(p[1]);
1489 } else 1614 } else {
1490 val = 0; 1615 val = 0;
1616 }
1491 if (!do_rc_ack(qp, aeth, psn, opcode, val, rcd) || 1617 if (!do_rc_ack(qp, aeth, psn, opcode, val, rcd) ||
1492 opcode != OP(RDMA_READ_RESPONSE_FIRST)) 1618 opcode != OP(RDMA_READ_RESPONSE_FIRST))
1493 goto ack_done; 1619 goto ack_done;
1494 wqe = get_swqe_ptr(qp, qp->s_acked); 1620 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1495 if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ)) 1621 if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
1496 goto ack_op_err; 1622 goto ack_op_err;
1497 /* 1623 /*
@@ -1519,10 +1645,10 @@ read_middle:
1519 * We got a response so update the timeout. 1645 * We got a response so update the timeout.
1520 * 4.096 usec. * (1 << qp->timeout) 1646 * 4.096 usec. * (1 << qp->timeout)
1521 */ 1647 */
1522 qp->s_flags |= HFI1_S_TIMER; 1648 qp->s_flags |= RVT_S_TIMER;
1523 mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies); 1649 mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies);
1524 if (qp->s_flags & HFI1_S_WAIT_ACK) { 1650 if (qp->s_flags & RVT_S_WAIT_ACK) {
1525 qp->s_flags &= ~HFI1_S_WAIT_ACK; 1651 qp->s_flags &= ~RVT_S_WAIT_ACK;
1526 hfi1_schedule_send(qp); 1652 hfi1_schedule_send(qp);
1527 } 1653 }
1528 1654
@@ -1536,7 +1662,7 @@ read_middle:
1536 qp->s_rdma_read_len -= pmtu; 1662 qp->s_rdma_read_len -= pmtu;
1537 update_last_psn(qp, psn); 1663 update_last_psn(qp, psn);
1538 spin_unlock_irqrestore(&qp->s_lock, flags); 1664 spin_unlock_irqrestore(&qp->s_lock, flags);
1539 hfi1_copy_sge(&qp->s_rdma_read_sge, data, pmtu, 0); 1665 hfi1_copy_sge(&qp->s_rdma_read_sge, data, pmtu, 0, 0);
1540 goto bail; 1666 goto bail;
1541 1667
1542 case OP(RDMA_READ_RESPONSE_ONLY): 1668 case OP(RDMA_READ_RESPONSE_ONLY):
@@ -1556,7 +1682,7 @@ read_middle:
1556 * have to be careful to copy the data to the right 1682 * have to be careful to copy the data to the right
1557 * location. 1683 * location.
1558 */ 1684 */
1559 wqe = get_swqe_ptr(qp, qp->s_acked); 1685 wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
1560 qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge, 1686 qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge,
1561 wqe, psn, pmtu); 1687 wqe, psn, pmtu);
1562 goto read_last; 1688 goto read_last;
@@ -1580,9 +1706,9 @@ read_last:
1580 if (unlikely(tlen != qp->s_rdma_read_len)) 1706 if (unlikely(tlen != qp->s_rdma_read_len))
1581 goto ack_len_err; 1707 goto ack_len_err;
1582 aeth = be32_to_cpu(ohdr->u.aeth); 1708 aeth = be32_to_cpu(ohdr->u.aeth);
1583 hfi1_copy_sge(&qp->s_rdma_read_sge, data, tlen, 0); 1709 hfi1_copy_sge(&qp->s_rdma_read_sge, data, tlen, 0, 0);
1584 WARN_ON(qp->s_rdma_read_sge.num_sge); 1710 WARN_ON(qp->s_rdma_read_sge.num_sge);
1585 (void) do_rc_ack(qp, aeth, psn, 1711 (void)do_rc_ack(qp, aeth, psn,
1586 OP(RDMA_READ_RESPONSE_LAST), 0, rcd); 1712 OP(RDMA_READ_RESPONSE_LAST), 0, rcd);
1587 goto ack_done; 1713 goto ack_done;
1588 } 1714 }
@@ -1600,7 +1726,7 @@ ack_len_err:
1600ack_err: 1726ack_err:
1601 if (qp->s_last == qp->s_acked) { 1727 if (qp->s_last == qp->s_acked) {
1602 hfi1_send_complete(qp, wqe, status); 1728 hfi1_send_complete(qp, wqe, status);
1603 hfi1_error_qp(qp, IB_WC_WR_FLUSH_ERR); 1729 rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
1604 } 1730 }
1605ack_done: 1731ack_done:
1606 spin_unlock_irqrestore(&qp->s_lock, flags); 1732 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -1609,22 +1735,24 @@ bail:
1609} 1735}
1610 1736
1611static inline void rc_defered_ack(struct hfi1_ctxtdata *rcd, 1737static inline void rc_defered_ack(struct hfi1_ctxtdata *rcd,
1612 struct hfi1_qp *qp) 1738 struct rvt_qp *qp)
1613{ 1739{
1614 if (list_empty(&qp->rspwait)) { 1740 if (list_empty(&qp->rspwait)) {
1615 qp->r_flags |= HFI1_R_RSP_DEFERED_ACK; 1741 qp->r_flags |= RVT_R_RSP_NAK;
1616 atomic_inc(&qp->refcount); 1742 atomic_inc(&qp->refcount);
1617 list_add_tail(&qp->rspwait, &rcd->qp_wait_list); 1743 list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
1618 } 1744 }
1619} 1745}
1620 1746
1621static inline void rc_cancel_ack(struct hfi1_qp *qp) 1747static inline void rc_cancel_ack(struct rvt_qp *qp)
1622{ 1748{
1623 qp->r_adefered = 0; 1749 struct hfi1_qp_priv *priv = qp->priv;
1750
1751 priv->r_adefered = 0;
1624 if (list_empty(&qp->rspwait)) 1752 if (list_empty(&qp->rspwait))
1625 return; 1753 return;
1626 list_del_init(&qp->rspwait); 1754 list_del_init(&qp->rspwait);
1627 qp->r_flags &= ~HFI1_R_RSP_DEFERED_ACK; 1755 qp->r_flags &= ~RVT_R_RSP_NAK;
1628 if (atomic_dec_and_test(&qp->refcount)) 1756 if (atomic_dec_and_test(&qp->refcount))
1629 wake_up(&qp->wait); 1757 wake_up(&qp->wait);
1630} 1758}
@@ -1645,11 +1773,11 @@ static inline void rc_cancel_ack(struct hfi1_qp *qp)
1645 * schedule a response to be sent. 1773 * schedule a response to be sent.
1646 */ 1774 */
1647static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data, 1775static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
1648 struct hfi1_qp *qp, u32 opcode, u32 psn, int diff, 1776 struct rvt_qp *qp, u32 opcode, u32 psn,
1649 struct hfi1_ctxtdata *rcd) 1777 int diff, struct hfi1_ctxtdata *rcd)
1650{ 1778{
1651 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 1779 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
1652 struct hfi1_ack_entry *e; 1780 struct rvt_ack_entry *e;
1653 unsigned long flags; 1781 unsigned long flags;
1654 u8 i, prev; 1782 u8 i, prev;
1655 int old_req; 1783 int old_req;
@@ -1662,7 +1790,7 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
1662 * Don't queue the NAK if we already sent one. 1790 * Don't queue the NAK if we already sent one.
1663 */ 1791 */
1664 if (!qp->r_nak_state) { 1792 if (!qp->r_nak_state) {
1665 ibp->n_rc_seqnak++; 1793 ibp->rvp.n_rc_seqnak++;
1666 qp->r_nak_state = IB_NAK_PSN_ERROR; 1794 qp->r_nak_state = IB_NAK_PSN_ERROR;
1667 /* Use the expected PSN. */ 1795 /* Use the expected PSN. */
1668 qp->r_ack_psn = qp->r_psn; 1796 qp->r_ack_psn = qp->r_psn;
@@ -1694,7 +1822,7 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
1694 */ 1822 */
1695 e = NULL; 1823 e = NULL;
1696 old_req = 1; 1824 old_req = 1;
1697 ibp->n_rc_dupreq++; 1825 ibp->rvp.n_rc_dupreq++;
1698 1826
1699 spin_lock_irqsave(&qp->s_lock, flags); 1827 spin_lock_irqsave(&qp->s_lock, flags);
1700 1828
@@ -1747,7 +1875,7 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
1747 if (unlikely(offset + len != e->rdma_sge.sge_length)) 1875 if (unlikely(offset + len != e->rdma_sge.sge_length))
1748 goto unlock_done; 1876 goto unlock_done;
1749 if (e->rdma_sge.mr) { 1877 if (e->rdma_sge.mr) {
1750 hfi1_put_mr(e->rdma_sge.mr); 1878 rvt_put_mr(e->rdma_sge.mr);
1751 e->rdma_sge.mr = NULL; 1879 e->rdma_sge.mr = NULL;
1752 } 1880 }
1753 if (len != 0) { 1881 if (len != 0) {
@@ -1755,8 +1883,8 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
1755 u64 vaddr = be64_to_cpu(reth->vaddr); 1883 u64 vaddr = be64_to_cpu(reth->vaddr);
1756 int ok; 1884 int ok;
1757 1885
1758 ok = hfi1_rkey_ok(qp, &e->rdma_sge, len, vaddr, rkey, 1886 ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr, rkey,
1759 IB_ACCESS_REMOTE_READ); 1887 IB_ACCESS_REMOTE_READ);
1760 if (unlikely(!ok)) 1888 if (unlikely(!ok))
1761 goto unlock_done; 1889 goto unlock_done;
1762 } else { 1890 } else {
@@ -1778,7 +1906,7 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
1778 * or the send tasklet is already backed up to send an 1906 * or the send tasklet is already backed up to send an
1779 * earlier entry, we can ignore this request. 1907 * earlier entry, we can ignore this request.
1780 */ 1908 */
1781 if (!e || e->opcode != (u8) opcode || old_req) 1909 if (!e || e->opcode != (u8)opcode || old_req)
1782 goto unlock_done; 1910 goto unlock_done;
1783 qp->s_tail_ack_queue = prev; 1911 qp->s_tail_ack_queue = prev;
1784 break; 1912 break;
@@ -1810,7 +1938,7 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
1810 break; 1938 break;
1811 } 1939 }
1812 qp->s_ack_state = OP(ACKNOWLEDGE); 1940 qp->s_ack_state = OP(ACKNOWLEDGE);
1813 qp->s_flags |= HFI1_S_RESP_PENDING; 1941 qp->s_flags |= RVT_S_RESP_PENDING;
1814 qp->r_nak_state = 0; 1942 qp->r_nak_state = 0;
1815 hfi1_schedule_send(qp); 1943 hfi1_schedule_send(qp);
1816 1944
@@ -1823,13 +1951,13 @@ send_ack:
1823 return 0; 1951 return 0;
1824} 1952}
1825 1953
1826void hfi1_rc_error(struct hfi1_qp *qp, enum ib_wc_status err) 1954void hfi1_rc_error(struct rvt_qp *qp, enum ib_wc_status err)
1827{ 1955{
1828 unsigned long flags; 1956 unsigned long flags;
1829 int lastwqe; 1957 int lastwqe;
1830 1958
1831 spin_lock_irqsave(&qp->s_lock, flags); 1959 spin_lock_irqsave(&qp->s_lock, flags);
1832 lastwqe = hfi1_error_qp(qp, err); 1960 lastwqe = rvt_error_qp(qp, err);
1833 spin_unlock_irqrestore(&qp->s_lock, flags); 1961 spin_unlock_irqrestore(&qp->s_lock, flags);
1834 1962
1835 if (lastwqe) { 1963 if (lastwqe) {
@@ -1842,7 +1970,7 @@ void hfi1_rc_error(struct hfi1_qp *qp, enum ib_wc_status err)
1842 } 1970 }
1843} 1971}
1844 1972
1845static inline void update_ack_queue(struct hfi1_qp *qp, unsigned n) 1973static inline void update_ack_queue(struct rvt_qp *qp, unsigned n)
1846{ 1974{
1847 unsigned next; 1975 unsigned next;
1848 1976
@@ -1864,14 +1992,14 @@ static void log_cca_event(struct hfi1_pportdata *ppd, u8 sl, u32 rlid,
1864 1992
1865 spin_lock_irqsave(&ppd->cc_log_lock, flags); 1993 spin_lock_irqsave(&ppd->cc_log_lock, flags);
1866 1994
1867 ppd->threshold_cong_event_map[sl/8] |= 1 << (sl % 8); 1995 ppd->threshold_cong_event_map[sl / 8] |= 1 << (sl % 8);
1868 ppd->threshold_event_counter++; 1996 ppd->threshold_event_counter++;
1869 1997
1870 cc_event = &ppd->cc_events[ppd->cc_log_idx++]; 1998 cc_event = &ppd->cc_events[ppd->cc_log_idx++];
1871 if (ppd->cc_log_idx == OPA_CONG_LOG_ELEMS) 1999 if (ppd->cc_log_idx == OPA_CONG_LOG_ELEMS)
1872 ppd->cc_log_idx = 0; 2000 ppd->cc_log_idx = 0;
1873 cc_event->lqpn = lqpn & HFI1_QPN_MASK; 2001 cc_event->lqpn = lqpn & RVT_QPN_MASK;
1874 cc_event->rqpn = rqpn & HFI1_QPN_MASK; 2002 cc_event->rqpn = rqpn & RVT_QPN_MASK;
1875 cc_event->sl = sl; 2003 cc_event->sl = sl;
1876 cc_event->svc_type = svc_type; 2004 cc_event->svc_type = svc_type;
1877 cc_event->rlid = rlid; 2005 cc_event->rlid = rlid;
@@ -1897,7 +2025,7 @@ void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
1897 2025
1898 cc_state = get_cc_state(ppd); 2026 cc_state = get_cc_state(ppd);
1899 2027
1900 if (cc_state == NULL) 2028 if (!cc_state)
1901 return; 2029 return;
1902 2030
1903 /* 2031 /*
@@ -1957,7 +2085,7 @@ void hfi1_rc_rcv(struct hfi1_packet *packet)
1957 u32 rcv_flags = packet->rcv_flags; 2085 u32 rcv_flags = packet->rcv_flags;
1958 void *data = packet->ebuf; 2086 void *data = packet->ebuf;
1959 u32 tlen = packet->tlen; 2087 u32 tlen = packet->tlen;
1960 struct hfi1_qp *qp = packet->qp; 2088 struct rvt_qp *qp = packet->qp;
1961 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 2089 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
1962 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 2090 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1963 struct hfi1_other_headers *ohdr = packet->ohdr; 2091 struct hfi1_other_headers *ohdr = packet->ohdr;
@@ -1972,6 +2100,7 @@ void hfi1_rc_rcv(struct hfi1_packet *packet)
1972 unsigned long flags; 2100 unsigned long flags;
1973 u32 bth1; 2101 u32 bth1;
1974 int ret, is_fecn = 0; 2102 int ret, is_fecn = 0;
2103 int copy_last = 0;
1975 2104
1976 bth0 = be32_to_cpu(ohdr->bth[0]); 2105 bth0 = be32_to_cpu(ohdr->bth[0]);
1977 if (hfi1_ruc_check_hdr(ibp, hdr, rcv_flags & HFI1_HAS_GRH, qp, bth0)) 2106 if (hfi1_ruc_check_hdr(ibp, hdr, rcv_flags & HFI1_HAS_GRH, qp, bth0))
@@ -2054,13 +2183,13 @@ void hfi1_rc_rcv(struct hfi1_packet *packet)
2054 break; 2183 break;
2055 } 2184 }
2056 2185
2057 if (qp->state == IB_QPS_RTR && !(qp->r_flags & HFI1_R_COMM_EST)) 2186 if (qp->state == IB_QPS_RTR && !(qp->r_flags & RVT_R_COMM_EST))
2058 qp_comm_est(qp); 2187 qp_comm_est(qp);
2059 2188
2060 /* OK, process the packet. */ 2189 /* OK, process the packet. */
2061 switch (opcode) { 2190 switch (opcode) {
2062 case OP(SEND_FIRST): 2191 case OP(SEND_FIRST):
2063 ret = hfi1_get_rwqe(qp, 0); 2192 ret = hfi1_rvt_get_rwqe(qp, 0);
2064 if (ret < 0) 2193 if (ret < 0)
2065 goto nack_op_err; 2194 goto nack_op_err;
2066 if (!ret) 2195 if (!ret)
@@ -2076,12 +2205,12 @@ send_middle:
2076 qp->r_rcv_len += pmtu; 2205 qp->r_rcv_len += pmtu;
2077 if (unlikely(qp->r_rcv_len > qp->r_len)) 2206 if (unlikely(qp->r_rcv_len > qp->r_len))
2078 goto nack_inv; 2207 goto nack_inv;
2079 hfi1_copy_sge(&qp->r_sge, data, pmtu, 1); 2208 hfi1_copy_sge(&qp->r_sge, data, pmtu, 1, 0);
2080 break; 2209 break;
2081 2210
2082 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE): 2211 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
2083 /* consume RWQE */ 2212 /* consume RWQE */
2084 ret = hfi1_get_rwqe(qp, 1); 2213 ret = hfi1_rvt_get_rwqe(qp, 1);
2085 if (ret < 0) 2214 if (ret < 0)
2086 goto nack_op_err; 2215 goto nack_op_err;
2087 if (!ret) 2216 if (!ret)
@@ -2090,7 +2219,7 @@ send_middle:
2090 2219
2091 case OP(SEND_ONLY): 2220 case OP(SEND_ONLY):
2092 case OP(SEND_ONLY_WITH_IMMEDIATE): 2221 case OP(SEND_ONLY_WITH_IMMEDIATE):
2093 ret = hfi1_get_rwqe(qp, 0); 2222 ret = hfi1_rvt_get_rwqe(qp, 0);
2094 if (ret < 0) 2223 if (ret < 0)
2095 goto nack_op_err; 2224 goto nack_op_err;
2096 if (!ret) 2225 if (!ret)
@@ -2104,8 +2233,10 @@ send_last_imm:
2104 wc.ex.imm_data = ohdr->u.imm_data; 2233 wc.ex.imm_data = ohdr->u.imm_data;
2105 wc.wc_flags = IB_WC_WITH_IMM; 2234 wc.wc_flags = IB_WC_WITH_IMM;
2106 goto send_last; 2235 goto send_last;
2107 case OP(SEND_LAST):
2108 case OP(RDMA_WRITE_LAST): 2236 case OP(RDMA_WRITE_LAST):
2237 copy_last = ibpd_to_rvtpd(qp->ibqp.pd)->user;
2238 /* fall through */
2239 case OP(SEND_LAST):
2109no_immediate_data: 2240no_immediate_data:
2110 wc.wc_flags = 0; 2241 wc.wc_flags = 0;
2111 wc.ex.imm_data = 0; 2242 wc.ex.imm_data = 0;
@@ -2121,10 +2252,10 @@ send_last:
2121 wc.byte_len = tlen + qp->r_rcv_len; 2252 wc.byte_len = tlen + qp->r_rcv_len;
2122 if (unlikely(wc.byte_len > qp->r_len)) 2253 if (unlikely(wc.byte_len > qp->r_len))
2123 goto nack_inv; 2254 goto nack_inv;
2124 hfi1_copy_sge(&qp->r_sge, data, tlen, 1); 2255 hfi1_copy_sge(&qp->r_sge, data, tlen, 1, copy_last);
2125 hfi1_put_ss(&qp->r_sge); 2256 rvt_put_ss(&qp->r_sge);
2126 qp->r_msn++; 2257 qp->r_msn++;
2127 if (!test_and_clear_bit(HFI1_R_WRID_VALID, &qp->r_aflags)) 2258 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
2128 break; 2259 break;
2129 wc.wr_id = qp->r_wr_id; 2260 wc.wr_id = qp->r_wr_id;
2130 wc.status = IB_WC_SUCCESS; 2261 wc.status = IB_WC_SUCCESS;
@@ -2154,12 +2285,14 @@ send_last:
2154 wc.dlid_path_bits = 0; 2285 wc.dlid_path_bits = 0;
2155 wc.port_num = 0; 2286 wc.port_num = 0;
2156 /* Signal completion event if the solicited bit is set. */ 2287 /* Signal completion event if the solicited bit is set. */
2157 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 2288 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
2158 (bth0 & IB_BTH_SOLICITED) != 0); 2289 (bth0 & IB_BTH_SOLICITED) != 0);
2159 break; 2290 break;
2160 2291
2161 case OP(RDMA_WRITE_FIRST):
2162 case OP(RDMA_WRITE_ONLY): 2292 case OP(RDMA_WRITE_ONLY):
2293 copy_last = 1;
2294 /* fall through */
2295 case OP(RDMA_WRITE_FIRST):
2163 case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE): 2296 case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
2164 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) 2297 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
2165 goto nack_inv; 2298 goto nack_inv;
@@ -2174,8 +2307,8 @@ send_last:
2174 int ok; 2307 int ok;
2175 2308
2176 /* Check rkey & NAK */ 2309 /* Check rkey & NAK */
2177 ok = hfi1_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, vaddr, 2310 ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, vaddr,
2178 rkey, IB_ACCESS_REMOTE_WRITE); 2311 rkey, IB_ACCESS_REMOTE_WRITE);
2179 if (unlikely(!ok)) 2312 if (unlikely(!ok))
2180 goto nack_acc; 2313 goto nack_acc;
2181 qp->r_sge.num_sge = 1; 2314 qp->r_sge.num_sge = 1;
@@ -2190,7 +2323,7 @@ send_last:
2190 goto send_middle; 2323 goto send_middle;
2191 else if (opcode == OP(RDMA_WRITE_ONLY)) 2324 else if (opcode == OP(RDMA_WRITE_ONLY))
2192 goto no_immediate_data; 2325 goto no_immediate_data;
2193 ret = hfi1_get_rwqe(qp, 1); 2326 ret = hfi1_rvt_get_rwqe(qp, 1);
2194 if (ret < 0) 2327 if (ret < 0)
2195 goto nack_op_err; 2328 goto nack_op_err;
2196 if (!ret) 2329 if (!ret)
@@ -2200,7 +2333,7 @@ send_last:
2200 goto send_last; 2333 goto send_last;
2201 2334
2202 case OP(RDMA_READ_REQUEST): { 2335 case OP(RDMA_READ_REQUEST): {
2203 struct hfi1_ack_entry *e; 2336 struct rvt_ack_entry *e;
2204 u32 len; 2337 u32 len;
2205 u8 next; 2338 u8 next;
2206 2339
@@ -2218,7 +2351,7 @@ send_last:
2218 } 2351 }
2219 e = &qp->s_ack_queue[qp->r_head_ack_queue]; 2352 e = &qp->s_ack_queue[qp->r_head_ack_queue];
2220 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) { 2353 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
2221 hfi1_put_mr(e->rdma_sge.mr); 2354 rvt_put_mr(e->rdma_sge.mr);
2222 e->rdma_sge.mr = NULL; 2355 e->rdma_sge.mr = NULL;
2223 } 2356 }
2224 reth = &ohdr->u.rc.reth; 2357 reth = &ohdr->u.rc.reth;
@@ -2229,8 +2362,8 @@ send_last:
2229 int ok; 2362 int ok;
2230 2363
2231 /* Check rkey & NAK */ 2364 /* Check rkey & NAK */
2232 ok = hfi1_rkey_ok(qp, &e->rdma_sge, len, vaddr, 2365 ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr,
2233 rkey, IB_ACCESS_REMOTE_READ); 2366 rkey, IB_ACCESS_REMOTE_READ);
2234 if (unlikely(!ok)) 2367 if (unlikely(!ok))
2235 goto nack_acc_unlck; 2368 goto nack_acc_unlck;
2236 /* 2369 /*
@@ -2261,7 +2394,7 @@ send_last:
2261 qp->r_head_ack_queue = next; 2394 qp->r_head_ack_queue = next;
2262 2395
2263 /* Schedule the send tasklet. */ 2396 /* Schedule the send tasklet. */
2264 qp->s_flags |= HFI1_S_RESP_PENDING; 2397 qp->s_flags |= RVT_S_RESP_PENDING;
2265 hfi1_schedule_send(qp); 2398 hfi1_schedule_send(qp);
2266 2399
2267 spin_unlock_irqrestore(&qp->s_lock, flags); 2400 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -2273,7 +2406,7 @@ send_last:
2273 case OP(COMPARE_SWAP): 2406 case OP(COMPARE_SWAP):
2274 case OP(FETCH_ADD): { 2407 case OP(FETCH_ADD): {
2275 struct ib_atomic_eth *ateth; 2408 struct ib_atomic_eth *ateth;
2276 struct hfi1_ack_entry *e; 2409 struct rvt_ack_entry *e;
2277 u64 vaddr; 2410 u64 vaddr;
2278 atomic64_t *maddr; 2411 atomic64_t *maddr;
2279 u64 sdata; 2412 u64 sdata;
@@ -2293,29 +2426,29 @@ send_last:
2293 } 2426 }
2294 e = &qp->s_ack_queue[qp->r_head_ack_queue]; 2427 e = &qp->s_ack_queue[qp->r_head_ack_queue];
2295 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) { 2428 if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
2296 hfi1_put_mr(e->rdma_sge.mr); 2429 rvt_put_mr(e->rdma_sge.mr);
2297 e->rdma_sge.mr = NULL; 2430 e->rdma_sge.mr = NULL;
2298 } 2431 }
2299 ateth = &ohdr->u.atomic_eth; 2432 ateth = &ohdr->u.atomic_eth;
2300 vaddr = ((u64) be32_to_cpu(ateth->vaddr[0]) << 32) | 2433 vaddr = ((u64)be32_to_cpu(ateth->vaddr[0]) << 32) |
2301 be32_to_cpu(ateth->vaddr[1]); 2434 be32_to_cpu(ateth->vaddr[1]);
2302 if (unlikely(vaddr & (sizeof(u64) - 1))) 2435 if (unlikely(vaddr & (sizeof(u64) - 1)))
2303 goto nack_inv_unlck; 2436 goto nack_inv_unlck;
2304 rkey = be32_to_cpu(ateth->rkey); 2437 rkey = be32_to_cpu(ateth->rkey);
2305 /* Check rkey & NAK */ 2438 /* Check rkey & NAK */
2306 if (unlikely(!hfi1_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), 2439 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
2307 vaddr, rkey, 2440 vaddr, rkey,
2308 IB_ACCESS_REMOTE_ATOMIC))) 2441 IB_ACCESS_REMOTE_ATOMIC)))
2309 goto nack_acc_unlck; 2442 goto nack_acc_unlck;
2310 /* Perform atomic OP and save result. */ 2443 /* Perform atomic OP and save result. */
2311 maddr = (atomic64_t *) qp->r_sge.sge.vaddr; 2444 maddr = (atomic64_t *)qp->r_sge.sge.vaddr;
2312 sdata = be64_to_cpu(ateth->swap_data); 2445 sdata = be64_to_cpu(ateth->swap_data);
2313 e->atomic_data = (opcode == OP(FETCH_ADD)) ? 2446 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
2314 (u64) atomic64_add_return(sdata, maddr) - sdata : 2447 (u64)atomic64_add_return(sdata, maddr) - sdata :
2315 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr, 2448 (u64)cmpxchg((u64 *)qp->r_sge.sge.vaddr,
2316 be64_to_cpu(ateth->compare_data), 2449 be64_to_cpu(ateth->compare_data),
2317 sdata); 2450 sdata);
2318 hfi1_put_mr(qp->r_sge.sge.mr); 2451 rvt_put_mr(qp->r_sge.sge.mr);
2319 qp->r_sge.num_sge = 0; 2452 qp->r_sge.num_sge = 0;
2320 e->opcode = opcode; 2453 e->opcode = opcode;
2321 e->sent = 0; 2454 e->sent = 0;
@@ -2328,7 +2461,7 @@ send_last:
2328 qp->r_head_ack_queue = next; 2461 qp->r_head_ack_queue = next;
2329 2462
2330 /* Schedule the send tasklet. */ 2463 /* Schedule the send tasklet. */
2331 qp->s_flags |= HFI1_S_RESP_PENDING; 2464 qp->s_flags |= RVT_S_RESP_PENDING;
2332 hfi1_schedule_send(qp); 2465 hfi1_schedule_send(qp);
2333 2466
2334 spin_unlock_irqrestore(&qp->s_lock, flags); 2467 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -2347,11 +2480,13 @@ send_last:
2347 qp->r_nak_state = 0; 2480 qp->r_nak_state = 0;
2348 /* Send an ACK if requested or required. */ 2481 /* Send an ACK if requested or required. */
2349 if (psn & IB_BTH_REQ_ACK) { 2482 if (psn & IB_BTH_REQ_ACK) {
2483 struct hfi1_qp_priv *priv = qp->priv;
2484
2350 if (packet->numpkt == 0) { 2485 if (packet->numpkt == 0) {
2351 rc_cancel_ack(qp); 2486 rc_cancel_ack(qp);
2352 goto send_ack; 2487 goto send_ack;
2353 } 2488 }
2354 if (qp->r_adefered >= HFI1_PSN_CREDIT) { 2489 if (priv->r_adefered >= HFI1_PSN_CREDIT) {
2355 rc_cancel_ack(qp); 2490 rc_cancel_ack(qp);
2356 goto send_ack; 2491 goto send_ack;
2357 } 2492 }
@@ -2359,13 +2494,13 @@ send_last:
2359 rc_cancel_ack(qp); 2494 rc_cancel_ack(qp);
2360 goto send_ack; 2495 goto send_ack;
2361 } 2496 }
2362 qp->r_adefered++; 2497 priv->r_adefered++;
2363 rc_defered_ack(rcd, qp); 2498 rc_defered_ack(rcd, qp);
2364 } 2499 }
2365 return; 2500 return;
2366 2501
2367rnr_nak: 2502rnr_nak:
2368 qp->r_nak_state = IB_RNR_NAK | qp->r_min_rnr_timer; 2503 qp->r_nak_state = qp->r_min_rnr_timer | IB_RNR_NAK;
2369 qp->r_ack_psn = qp->r_psn; 2504 qp->r_ack_psn = qp->r_psn;
2370 /* Queue RNR NAK for later */ 2505 /* Queue RNR NAK for later */
2371 rc_defered_ack(rcd, qp); 2506 rc_defered_ack(rcd, qp);
@@ -2403,7 +2538,7 @@ void hfi1_rc_hdrerr(
2403 struct hfi1_ctxtdata *rcd, 2538 struct hfi1_ctxtdata *rcd,
2404 struct hfi1_ib_header *hdr, 2539 struct hfi1_ib_header *hdr,
2405 u32 rcv_flags, 2540 u32 rcv_flags,
2406 struct hfi1_qp *qp) 2541 struct rvt_qp *qp)
2407{ 2542{
2408 int has_grh = rcv_flags & HFI1_HAS_GRH; 2543 int has_grh = rcv_flags & HFI1_HAS_GRH;
2409 struct hfi1_other_headers *ohdr; 2544 struct hfi1_other_headers *ohdr;
@@ -2428,7 +2563,7 @@ void hfi1_rc_hdrerr(
2428 if (opcode < IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) { 2563 if (opcode < IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) {
2429 diff = delta_psn(psn, qp->r_psn); 2564 diff = delta_psn(psn, qp->r_psn);
2430 if (!qp->r_nak_state && diff >= 0) { 2565 if (!qp->r_nak_state && diff >= 0) {
2431 ibp->n_rc_seqnak++; 2566 ibp->rvp.n_rc_seqnak++;
2432 qp->r_nak_state = IB_NAK_PSN_ERROR; 2567 qp->r_nak_state = IB_NAK_PSN_ERROR;
2433 /* Use the expected PSN. */ 2568 /* Use the expected PSN. */
2434 qp->r_ack_psn = qp->r_psn; 2569 qp->r_ack_psn = qp->r_psn;
diff --git a/drivers/staging/rdma/hfi1/ruc.c b/drivers/staging/rdma/hfi1/ruc.c
index 4a91975b68d7..08813cdbd475 100644
--- a/drivers/staging/rdma/hfi1/ruc.c
+++ b/drivers/staging/rdma/hfi1/ruc.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -53,7 +50,8 @@
53#include "hfi.h" 50#include "hfi.h"
54#include "mad.h" 51#include "mad.h"
55#include "qp.h" 52#include "qp.h"
56#include "sdma.h" 53#include "verbs_txreq.h"
54#include "trace.h"
57 55
58/* 56/*
59 * Convert the AETH RNR timeout code into the number of microseconds. 57 * Convert the AETH RNR timeout code into the number of microseconds.
@@ -97,16 +95,16 @@ const u32 ib_hfi1_rnr_table[32] = {
97 * Validate a RWQE and fill in the SGE state. 95 * Validate a RWQE and fill in the SGE state.
98 * Return 1 if OK. 96 * Return 1 if OK.
99 */ 97 */
100static int init_sge(struct hfi1_qp *qp, struct hfi1_rwqe *wqe) 98static int init_sge(struct rvt_qp *qp, struct rvt_rwqe *wqe)
101{ 99{
102 int i, j, ret; 100 int i, j, ret;
103 struct ib_wc wc; 101 struct ib_wc wc;
104 struct hfi1_lkey_table *rkt; 102 struct rvt_lkey_table *rkt;
105 struct hfi1_pd *pd; 103 struct rvt_pd *pd;
106 struct hfi1_sge_state *ss; 104 struct rvt_sge_state *ss;
107 105
108 rkt = &to_idev(qp->ibqp.device)->lk_table; 106 rkt = &to_idev(qp->ibqp.device)->rdi.lkey_table;
109 pd = to_ipd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd); 107 pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd);
110 ss = &qp->r_sge; 108 ss = &qp->r_sge;
111 ss->sg_list = qp->r_sg_list; 109 ss->sg_list = qp->r_sg_list;
112 qp->r_len = 0; 110 qp->r_len = 0;
@@ -114,8 +112,8 @@ static int init_sge(struct hfi1_qp *qp, struct hfi1_rwqe *wqe)
114 if (wqe->sg_list[i].length == 0) 112 if (wqe->sg_list[i].length == 0)
115 continue; 113 continue;
116 /* Check LKEY */ 114 /* Check LKEY */
117 if (!hfi1_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge, 115 if (!rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge,
118 &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE)) 116 &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE))
119 goto bad_lkey; 117 goto bad_lkey;
120 qp->r_len += wqe->sg_list[i].length; 118 qp->r_len += wqe->sg_list[i].length;
121 j++; 119 j++;
@@ -127,9 +125,9 @@ static int init_sge(struct hfi1_qp *qp, struct hfi1_rwqe *wqe)
127 125
128bad_lkey: 126bad_lkey:
129 while (j) { 127 while (j) {
130 struct hfi1_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge; 128 struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge;
131 129
132 hfi1_put_mr(sge->mr); 130 rvt_put_mr(sge->mr);
133 } 131 }
134 ss->num_sge = 0; 132 ss->num_sge = 0;
135 memset(&wc, 0, sizeof(wc)); 133 memset(&wc, 0, sizeof(wc));
@@ -138,14 +136,14 @@ bad_lkey:
138 wc.opcode = IB_WC_RECV; 136 wc.opcode = IB_WC_RECV;
139 wc.qp = &qp->ibqp; 137 wc.qp = &qp->ibqp;
140 /* Signal solicited completion event. */ 138 /* Signal solicited completion event. */
141 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1); 139 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
142 ret = 0; 140 ret = 0;
143bail: 141bail:
144 return ret; 142 return ret;
145} 143}
146 144
147/** 145/**
148 * hfi1_get_rwqe - copy the next RWQE into the QP's RWQE 146 * hfi1_rvt_get_rwqe - copy the next RWQE into the QP's RWQE
149 * @qp: the QP 147 * @qp: the QP
150 * @wr_id_only: update qp->r_wr_id only, not qp->r_sge 148 * @wr_id_only: update qp->r_wr_id only, not qp->r_sge
151 * 149 *
@@ -154,19 +152,19 @@ bail:
154 * 152 *
155 * Can be called from interrupt level. 153 * Can be called from interrupt level.
156 */ 154 */
157int hfi1_get_rwqe(struct hfi1_qp *qp, int wr_id_only) 155int hfi1_rvt_get_rwqe(struct rvt_qp *qp, int wr_id_only)
158{ 156{
159 unsigned long flags; 157 unsigned long flags;
160 struct hfi1_rq *rq; 158 struct rvt_rq *rq;
161 struct hfi1_rwq *wq; 159 struct rvt_rwq *wq;
162 struct hfi1_srq *srq; 160 struct rvt_srq *srq;
163 struct hfi1_rwqe *wqe; 161 struct rvt_rwqe *wqe;
164 void (*handler)(struct ib_event *, void *); 162 void (*handler)(struct ib_event *, void *);
165 u32 tail; 163 u32 tail;
166 int ret; 164 int ret;
167 165
168 if (qp->ibqp.srq) { 166 if (qp->ibqp.srq) {
169 srq = to_isrq(qp->ibqp.srq); 167 srq = ibsrq_to_rvtsrq(qp->ibqp.srq);
170 handler = srq->ibsrq.event_handler; 168 handler = srq->ibsrq.event_handler;
171 rq = &srq->rq; 169 rq = &srq->rq;
172 } else { 170 } else {
@@ -176,7 +174,7 @@ int hfi1_get_rwqe(struct hfi1_qp *qp, int wr_id_only)
176 } 174 }
177 175
178 spin_lock_irqsave(&rq->lock, flags); 176 spin_lock_irqsave(&rq->lock, flags);
179 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK)) { 177 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
180 ret = 0; 178 ret = 0;
181 goto unlock; 179 goto unlock;
182 } 180 }
@@ -192,7 +190,7 @@ int hfi1_get_rwqe(struct hfi1_qp *qp, int wr_id_only)
192 } 190 }
193 /* Make sure entry is read after head index is read. */ 191 /* Make sure entry is read after head index is read. */
194 smp_rmb(); 192 smp_rmb();
195 wqe = get_rwqe_ptr(rq, tail); 193 wqe = rvt_get_rwqe_ptr(rq, tail);
196 /* 194 /*
197 * Even though we update the tail index in memory, the verbs 195 * Even though we update the tail index in memory, the verbs
198 * consumer is not supposed to post more entries until a 196 * consumer is not supposed to post more entries until a
@@ -208,7 +206,7 @@ int hfi1_get_rwqe(struct hfi1_qp *qp, int wr_id_only)
208 qp->r_wr_id = wqe->wr_id; 206 qp->r_wr_id = wqe->wr_id;
209 207
210 ret = 1; 208 ret = 1;
211 set_bit(HFI1_R_WRID_VALID, &qp->r_aflags); 209 set_bit(RVT_R_WRID_VALID, &qp->r_aflags);
212 if (handler) { 210 if (handler) {
213 u32 n; 211 u32 n;
214 212
@@ -265,7 +263,7 @@ static int gid_ok(union ib_gid *gid, __be64 gid_prefix, __be64 id)
265 * The s_lock will be acquired around the hfi1_migrate_qp() call. 263 * The s_lock will be acquired around the hfi1_migrate_qp() call.
266 */ 264 */
267int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr, 265int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr,
268 int has_grh, struct hfi1_qp *qp, u32 bth0) 266 int has_grh, struct rvt_qp *qp, u32 bth0)
269{ 267{
270 __be64 guid; 268 __be64 guid;
271 unsigned long flags; 269 unsigned long flags;
@@ -279,11 +277,13 @@ int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr,
279 if (!(qp->alt_ah_attr.ah_flags & IB_AH_GRH)) 277 if (!(qp->alt_ah_attr.ah_flags & IB_AH_GRH))
280 goto err; 278 goto err;
281 guid = get_sguid(ibp, qp->alt_ah_attr.grh.sgid_index); 279 guid = get_sguid(ibp, qp->alt_ah_attr.grh.sgid_index);
282 if (!gid_ok(&hdr->u.l.grh.dgid, ibp->gid_prefix, guid)) 280 if (!gid_ok(&hdr->u.l.grh.dgid, ibp->rvp.gid_prefix,
281 guid))
283 goto err; 282 goto err;
284 if (!gid_ok(&hdr->u.l.grh.sgid, 283 if (!gid_ok(
285 qp->alt_ah_attr.grh.dgid.global.subnet_prefix, 284 &hdr->u.l.grh.sgid,
286 qp->alt_ah_attr.grh.dgid.global.interface_id)) 285 qp->alt_ah_attr.grh.dgid.global.subnet_prefix,
286 qp->alt_ah_attr.grh.dgid.global.interface_id))
287 goto err; 287 goto err;
288 } 288 }
289 if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0, 289 if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0,
@@ -312,11 +312,13 @@ int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr,
312 goto err; 312 goto err;
313 guid = get_sguid(ibp, 313 guid = get_sguid(ibp,
314 qp->remote_ah_attr.grh.sgid_index); 314 qp->remote_ah_attr.grh.sgid_index);
315 if (!gid_ok(&hdr->u.l.grh.dgid, ibp->gid_prefix, guid)) 315 if (!gid_ok(&hdr->u.l.grh.dgid, ibp->rvp.gid_prefix,
316 guid))
316 goto err; 317 goto err;
317 if (!gid_ok(&hdr->u.l.grh.sgid, 318 if (!gid_ok(
318 qp->remote_ah_attr.grh.dgid.global.subnet_prefix, 319 &hdr->u.l.grh.sgid,
319 qp->remote_ah_attr.grh.dgid.global.interface_id)) 320 qp->remote_ah_attr.grh.dgid.global.subnet_prefix,
321 qp->remote_ah_attr.grh.dgid.global.interface_id))
320 goto err; 322 goto err;
321 } 323 }
322 if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0, 324 if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0,
@@ -355,12 +357,12 @@ err:
355 * receive interrupts since this is a connected protocol and all packets 357 * receive interrupts since this is a connected protocol and all packets
356 * will pass through here. 358 * will pass through here.
357 */ 359 */
358static void ruc_loopback(struct hfi1_qp *sqp) 360static void ruc_loopback(struct rvt_qp *sqp)
359{ 361{
360 struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num); 362 struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
361 struct hfi1_qp *qp; 363 struct rvt_qp *qp;
362 struct hfi1_swqe *wqe; 364 struct rvt_swqe *wqe;
363 struct hfi1_sge *sge; 365 struct rvt_sge *sge;
364 unsigned long flags; 366 unsigned long flags;
365 struct ib_wc wc; 367 struct ib_wc wc;
366 u64 sdata; 368 u64 sdata;
@@ -368,6 +370,8 @@ static void ruc_loopback(struct hfi1_qp *sqp)
368 enum ib_wc_status send_status; 370 enum ib_wc_status send_status;
369 int release; 371 int release;
370 int ret; 372 int ret;
373 int copy_last = 0;
374 u32 to;
371 375
372 rcu_read_lock(); 376 rcu_read_lock();
373 377
@@ -375,25 +379,27 @@ static void ruc_loopback(struct hfi1_qp *sqp)
375 * Note that we check the responder QP state after 379 * Note that we check the responder QP state after
376 * checking the requester's state. 380 * checking the requester's state.
377 */ 381 */
378 qp = hfi1_lookup_qpn(ibp, sqp->remote_qpn); 382 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp,
383 sqp->remote_qpn);
379 384
380 spin_lock_irqsave(&sqp->s_lock, flags); 385 spin_lock_irqsave(&sqp->s_lock, flags);
381 386
382 /* Return if we are already busy processing a work request. */ 387 /* Return if we are already busy processing a work request. */
383 if ((sqp->s_flags & (HFI1_S_BUSY | HFI1_S_ANY_WAIT)) || 388 if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) ||
384 !(ib_hfi1_state_ops[sqp->state] & HFI1_PROCESS_OR_FLUSH_SEND)) 389 !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND))
385 goto unlock; 390 goto unlock;
386 391
387 sqp->s_flags |= HFI1_S_BUSY; 392 sqp->s_flags |= RVT_S_BUSY;
388 393
389again: 394again:
390 if (sqp->s_last == sqp->s_head) 395 smp_read_barrier_depends(); /* see post_one_send() */
396 if (sqp->s_last == ACCESS_ONCE(sqp->s_head))
391 goto clr_busy; 397 goto clr_busy;
392 wqe = get_swqe_ptr(sqp, sqp->s_last); 398 wqe = rvt_get_swqe_ptr(sqp, sqp->s_last);
393 399
394 /* Return if it is not OK to start a new work request. */ 400 /* Return if it is not OK to start a new work request. */
395 if (!(ib_hfi1_state_ops[sqp->state] & HFI1_PROCESS_NEXT_SEND_OK)) { 401 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
396 if (!(ib_hfi1_state_ops[sqp->state] & HFI1_FLUSH_SEND)) 402 if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND))
397 goto clr_busy; 403 goto clr_busy;
398 /* We are in the error state, flush the work request. */ 404 /* We are in the error state, flush the work request. */
399 send_status = IB_WC_WR_FLUSH_ERR; 405 send_status = IB_WC_WR_FLUSH_ERR;
@@ -411,9 +417,9 @@ again:
411 } 417 }
412 spin_unlock_irqrestore(&sqp->s_lock, flags); 418 spin_unlock_irqrestore(&sqp->s_lock, flags);
413 419
414 if (!qp || !(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK) || 420 if (!qp || !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) ||
415 qp->ibqp.qp_type != sqp->ibqp.qp_type) { 421 qp->ibqp.qp_type != sqp->ibqp.qp_type) {
416 ibp->n_pkt_drops++; 422 ibp->rvp.n_pkt_drops++;
417 /* 423 /*
418 * For RC, the requester would timeout and retry so 424 * For RC, the requester would timeout and retry so
419 * shortcut the timeouts and just signal too many retries. 425 * shortcut the timeouts and just signal too many retries.
@@ -439,7 +445,7 @@ again:
439 wc.ex.imm_data = wqe->wr.ex.imm_data; 445 wc.ex.imm_data = wqe->wr.ex.imm_data;
440 /* FALLTHROUGH */ 446 /* FALLTHROUGH */
441 case IB_WR_SEND: 447 case IB_WR_SEND:
442 ret = hfi1_get_rwqe(qp, 0); 448 ret = hfi1_rvt_get_rwqe(qp, 0);
443 if (ret < 0) 449 if (ret < 0)
444 goto op_err; 450 goto op_err;
445 if (!ret) 451 if (!ret)
@@ -451,21 +457,24 @@ again:
451 goto inv_err; 457 goto inv_err;
452 wc.wc_flags = IB_WC_WITH_IMM; 458 wc.wc_flags = IB_WC_WITH_IMM;
453 wc.ex.imm_data = wqe->wr.ex.imm_data; 459 wc.ex.imm_data = wqe->wr.ex.imm_data;
454 ret = hfi1_get_rwqe(qp, 1); 460 ret = hfi1_rvt_get_rwqe(qp, 1);
455 if (ret < 0) 461 if (ret < 0)
456 goto op_err; 462 goto op_err;
457 if (!ret) 463 if (!ret)
458 goto rnr_nak; 464 goto rnr_nak;
459 /* FALLTHROUGH */ 465 /* skip copy_last set and qp_access_flags recheck */
466 goto do_write;
460 case IB_WR_RDMA_WRITE: 467 case IB_WR_RDMA_WRITE:
468 copy_last = ibpd_to_rvtpd(qp->ibqp.pd)->user;
461 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) 469 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
462 goto inv_err; 470 goto inv_err;
471do_write:
463 if (wqe->length == 0) 472 if (wqe->length == 0)
464 break; 473 break;
465 if (unlikely(!hfi1_rkey_ok(qp, &qp->r_sge.sge, wqe->length, 474 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length,
466 wqe->rdma_wr.remote_addr, 475 wqe->rdma_wr.remote_addr,
467 wqe->rdma_wr.rkey, 476 wqe->rdma_wr.rkey,
468 IB_ACCESS_REMOTE_WRITE))) 477 IB_ACCESS_REMOTE_WRITE)))
469 goto acc_err; 478 goto acc_err;
470 qp->r_sge.sg_list = NULL; 479 qp->r_sge.sg_list = NULL;
471 qp->r_sge.num_sge = 1; 480 qp->r_sge.num_sge = 1;
@@ -475,10 +484,10 @@ again:
475 case IB_WR_RDMA_READ: 484 case IB_WR_RDMA_READ:
476 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) 485 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ)))
477 goto inv_err; 486 goto inv_err;
478 if (unlikely(!hfi1_rkey_ok(qp, &sqp->s_sge.sge, wqe->length, 487 if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length,
479 wqe->rdma_wr.remote_addr, 488 wqe->rdma_wr.remote_addr,
480 wqe->rdma_wr.rkey, 489 wqe->rdma_wr.rkey,
481 IB_ACCESS_REMOTE_READ))) 490 IB_ACCESS_REMOTE_READ)))
482 goto acc_err; 491 goto acc_err;
483 release = 0; 492 release = 0;
484 sqp->s_sge.sg_list = NULL; 493 sqp->s_sge.sg_list = NULL;
@@ -493,20 +502,20 @@ again:
493 case IB_WR_ATOMIC_FETCH_AND_ADD: 502 case IB_WR_ATOMIC_FETCH_AND_ADD:
494 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) 503 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))
495 goto inv_err; 504 goto inv_err;
496 if (unlikely(!hfi1_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), 505 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
497 wqe->atomic_wr.remote_addr, 506 wqe->atomic_wr.remote_addr,
498 wqe->atomic_wr.rkey, 507 wqe->atomic_wr.rkey,
499 IB_ACCESS_REMOTE_ATOMIC))) 508 IB_ACCESS_REMOTE_ATOMIC)))
500 goto acc_err; 509 goto acc_err;
501 /* Perform atomic OP and save result. */ 510 /* Perform atomic OP and save result. */
502 maddr = (atomic64_t *) qp->r_sge.sge.vaddr; 511 maddr = (atomic64_t *)qp->r_sge.sge.vaddr;
503 sdata = wqe->atomic_wr.compare_add; 512 sdata = wqe->atomic_wr.compare_add;
504 *(u64 *) sqp->s_sge.sge.vaddr = 513 *(u64 *)sqp->s_sge.sge.vaddr =
505 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ? 514 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
506 (u64) atomic64_add_return(sdata, maddr) - sdata : 515 (u64)atomic64_add_return(sdata, maddr) - sdata :
507 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr, 516 (u64)cmpxchg((u64 *)qp->r_sge.sge.vaddr,
508 sdata, wqe->atomic_wr.swap); 517 sdata, wqe->atomic_wr.swap);
509 hfi1_put_mr(qp->r_sge.sge.mr); 518 rvt_put_mr(qp->r_sge.sge.mr);
510 qp->r_sge.num_sge = 0; 519 qp->r_sge.num_sge = 0;
511 goto send_comp; 520 goto send_comp;
512 521
@@ -524,17 +533,17 @@ again:
524 if (len > sge->sge_length) 533 if (len > sge->sge_length)
525 len = sge->sge_length; 534 len = sge->sge_length;
526 WARN_ON_ONCE(len == 0); 535 WARN_ON_ONCE(len == 0);
527 hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, release); 536 hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, release, copy_last);
528 sge->vaddr += len; 537 sge->vaddr += len;
529 sge->length -= len; 538 sge->length -= len;
530 sge->sge_length -= len; 539 sge->sge_length -= len;
531 if (sge->sge_length == 0) { 540 if (sge->sge_length == 0) {
532 if (!release) 541 if (!release)
533 hfi1_put_mr(sge->mr); 542 rvt_put_mr(sge->mr);
534 if (--sqp->s_sge.num_sge) 543 if (--sqp->s_sge.num_sge)
535 *sge = *sqp->s_sge.sg_list++; 544 *sge = *sqp->s_sge.sg_list++;
536 } else if (sge->length == 0 && sge->mr->lkey) { 545 } else if (sge->length == 0 && sge->mr->lkey) {
537 if (++sge->n >= HFI1_SEGSZ) { 546 if (++sge->n >= RVT_SEGSZ) {
538 if (++sge->m >= sge->mr->mapsz) 547 if (++sge->m >= sge->mr->mapsz)
539 break; 548 break;
540 sge->n = 0; 549 sge->n = 0;
@@ -547,9 +556,9 @@ again:
547 sqp->s_len -= len; 556 sqp->s_len -= len;
548 } 557 }
549 if (release) 558 if (release)
550 hfi1_put_ss(&qp->r_sge); 559 rvt_put_ss(&qp->r_sge);
551 560
552 if (!test_and_clear_bit(HFI1_R_WRID_VALID, &qp->r_aflags)) 561 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
553 goto send_comp; 562 goto send_comp;
554 563
555 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM) 564 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM)
@@ -565,12 +574,12 @@ again:
565 wc.sl = qp->remote_ah_attr.sl; 574 wc.sl = qp->remote_ah_attr.sl;
566 wc.port_num = 1; 575 wc.port_num = 1;
567 /* Signal completion event if the solicited bit is set. */ 576 /* Signal completion event if the solicited bit is set. */
568 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 577 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
569 wqe->wr.send_flags & IB_SEND_SOLICITED); 578 wqe->wr.send_flags & IB_SEND_SOLICITED);
570 579
571send_comp: 580send_comp:
572 spin_lock_irqsave(&sqp->s_lock, flags); 581 spin_lock_irqsave(&sqp->s_lock, flags);
573 ibp->n_loop_pkts++; 582 ibp->rvp.n_loop_pkts++;
574flush_send: 583flush_send:
575 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; 584 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt;
576 hfi1_send_complete(sqp, wqe, send_status); 585 hfi1_send_complete(sqp, wqe, send_status);
@@ -580,7 +589,7 @@ rnr_nak:
580 /* Handle RNR NAK */ 589 /* Handle RNR NAK */
581 if (qp->ibqp.qp_type == IB_QPT_UC) 590 if (qp->ibqp.qp_type == IB_QPT_UC)
582 goto send_comp; 591 goto send_comp;
583 ibp->n_rnr_naks++; 592 ibp->rvp.n_rnr_naks++;
584 /* 593 /*
585 * Note: we don't need the s_lock held since the BUSY flag 594 * Note: we don't need the s_lock held since the BUSY flag
586 * makes this single threaded. 595 * makes this single threaded.
@@ -592,13 +601,10 @@ rnr_nak:
592 if (sqp->s_rnr_retry_cnt < 7) 601 if (sqp->s_rnr_retry_cnt < 7)
593 sqp->s_rnr_retry--; 602 sqp->s_rnr_retry--;
594 spin_lock_irqsave(&sqp->s_lock, flags); 603 spin_lock_irqsave(&sqp->s_lock, flags);
595 if (!(ib_hfi1_state_ops[sqp->state] & HFI1_PROCESS_RECV_OK)) 604 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK))
596 goto clr_busy; 605 goto clr_busy;
597 sqp->s_flags |= HFI1_S_WAIT_RNR; 606 to = ib_hfi1_rnr_table[qp->r_min_rnr_timer];
598 sqp->s_timer.function = hfi1_rc_rnr_retry; 607 hfi1_add_rnr_timer(sqp, to);
599 sqp->s_timer.expires = jiffies +
600 usecs_to_jiffies(ib_hfi1_rnr_table[qp->r_min_rnr_timer]);
601 add_timer(&sqp->s_timer);
602 goto clr_busy; 608 goto clr_busy;
603 609
604op_err: 610op_err:
@@ -622,9 +628,9 @@ serr:
622 spin_lock_irqsave(&sqp->s_lock, flags); 628 spin_lock_irqsave(&sqp->s_lock, flags);
623 hfi1_send_complete(sqp, wqe, send_status); 629 hfi1_send_complete(sqp, wqe, send_status);
624 if (sqp->ibqp.qp_type == IB_QPT_RC) { 630 if (sqp->ibqp.qp_type == IB_QPT_RC) {
625 int lastwqe = hfi1_error_qp(sqp, IB_WC_WR_FLUSH_ERR); 631 int lastwqe = rvt_error_qp(sqp, IB_WC_WR_FLUSH_ERR);
626 632
627 sqp->s_flags &= ~HFI1_S_BUSY; 633 sqp->s_flags &= ~RVT_S_BUSY;
628 spin_unlock_irqrestore(&sqp->s_lock, flags); 634 spin_unlock_irqrestore(&sqp->s_lock, flags);
629 if (lastwqe) { 635 if (lastwqe) {
630 struct ib_event ev; 636 struct ib_event ev;
@@ -637,7 +643,7 @@ serr:
637 goto done; 643 goto done;
638 } 644 }
639clr_busy: 645clr_busy:
640 sqp->s_flags &= ~HFI1_S_BUSY; 646 sqp->s_flags &= ~RVT_S_BUSY;
641unlock: 647unlock:
642 spin_unlock_irqrestore(&sqp->s_lock, flags); 648 spin_unlock_irqrestore(&sqp->s_lock, flags);
643done: 649done:
@@ -666,7 +672,7 @@ u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
666 hdr->next_hdr = IB_GRH_NEXT_HDR; 672 hdr->next_hdr = IB_GRH_NEXT_HDR;
667 hdr->hop_limit = grh->hop_limit; 673 hdr->hop_limit = grh->hop_limit;
668 /* The SGID is 32-bit aligned. */ 674 /* The SGID is 32-bit aligned. */
669 hdr->sgid.global.subnet_prefix = ibp->gid_prefix; 675 hdr->sgid.global.subnet_prefix = ibp->rvp.gid_prefix;
670 hdr->sgid.global.interface_id = 676 hdr->sgid.global.interface_id =
671 grh->sgid_index && grh->sgid_index < ARRAY_SIZE(ibp->guids) ? 677 grh->sgid_index && grh->sgid_index < ARRAY_SIZE(ibp->guids) ?
672 ibp->guids[grh->sgid_index - 1] : 678 ibp->guids[grh->sgid_index - 1] :
@@ -690,29 +696,31 @@ u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
690 * Subsequent middles use the copied entry, editing the 696 * Subsequent middles use the copied entry, editing the
691 * PSN with 1 or 2 edits. 697 * PSN with 1 or 2 edits.
692 */ 698 */
693static inline void build_ahg(struct hfi1_qp *qp, u32 npsn) 699static inline void build_ahg(struct rvt_qp *qp, u32 npsn)
694{ 700{
695 if (unlikely(qp->s_flags & HFI1_S_AHG_CLEAR)) 701 struct hfi1_qp_priv *priv = qp->priv;
702
703 if (unlikely(qp->s_flags & RVT_S_AHG_CLEAR))
696 clear_ahg(qp); 704 clear_ahg(qp);
697 if (!(qp->s_flags & HFI1_S_AHG_VALID)) { 705 if (!(qp->s_flags & RVT_S_AHG_VALID)) {
698 /* first middle that needs copy */ 706 /* first middle that needs copy */
699 if (qp->s_ahgidx < 0) 707 if (qp->s_ahgidx < 0)
700 qp->s_ahgidx = sdma_ahg_alloc(qp->s_sde); 708 qp->s_ahgidx = sdma_ahg_alloc(priv->s_sde);
701 if (qp->s_ahgidx >= 0) { 709 if (qp->s_ahgidx >= 0) {
702 qp->s_ahgpsn = npsn; 710 qp->s_ahgpsn = npsn;
703 qp->s_hdr->tx_flags |= SDMA_TXREQ_F_AHG_COPY; 711 priv->s_hdr->tx_flags |= SDMA_TXREQ_F_AHG_COPY;
704 /* save to protect a change in another thread */ 712 /* save to protect a change in another thread */
705 qp->s_hdr->sde = qp->s_sde; 713 priv->s_hdr->sde = priv->s_sde;
706 qp->s_hdr->ahgidx = qp->s_ahgidx; 714 priv->s_hdr->ahgidx = qp->s_ahgidx;
707 qp->s_flags |= HFI1_S_AHG_VALID; 715 qp->s_flags |= RVT_S_AHG_VALID;
708 } 716 }
709 } else { 717 } else {
710 /* subsequent middle after valid */ 718 /* subsequent middle after valid */
711 if (qp->s_ahgidx >= 0) { 719 if (qp->s_ahgidx >= 0) {
712 qp->s_hdr->tx_flags |= SDMA_TXREQ_F_USE_AHG; 720 priv->s_hdr->tx_flags |= SDMA_TXREQ_F_USE_AHG;
713 qp->s_hdr->ahgidx = qp->s_ahgidx; 721 priv->s_hdr->ahgidx = qp->s_ahgidx;
714 qp->s_hdr->ahgcount++; 722 priv->s_hdr->ahgcount++;
715 qp->s_hdr->ahgdesc[0] = 723 priv->s_hdr->ahgdesc[0] =
716 sdma_build_ahg_descriptor( 724 sdma_build_ahg_descriptor(
717 (__force u16)cpu_to_be16((u16)npsn), 725 (__force u16)cpu_to_be16((u16)npsn),
718 BTH2_OFFSET, 726 BTH2_OFFSET,
@@ -720,8 +728,8 @@ static inline void build_ahg(struct hfi1_qp *qp, u32 npsn)
720 16); 728 16);
721 if ((npsn & 0xffff0000) != 729 if ((npsn & 0xffff0000) !=
722 (qp->s_ahgpsn & 0xffff0000)) { 730 (qp->s_ahgpsn & 0xffff0000)) {
723 qp->s_hdr->ahgcount++; 731 priv->s_hdr->ahgcount++;
724 qp->s_hdr->ahgdesc[1] = 732 priv->s_hdr->ahgdesc[1] =
725 sdma_build_ahg_descriptor( 733 sdma_build_ahg_descriptor(
726 (__force u16)cpu_to_be16( 734 (__force u16)cpu_to_be16(
727 (u16)(npsn >> 16)), 735 (u16)(npsn >> 16)),
@@ -733,10 +741,12 @@ static inline void build_ahg(struct hfi1_qp *qp, u32 npsn)
733 } 741 }
734} 742}
735 743
736void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr, 744void hfi1_make_ruc_header(struct rvt_qp *qp, struct hfi1_other_headers *ohdr,
737 u32 bth0, u32 bth2, int middle) 745 u32 bth0, u32 bth2, int middle,
746 struct hfi1_pkt_state *ps)
738{ 747{
739 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); 748 struct hfi1_qp_priv *priv = qp->priv;
749 struct hfi1_ibport *ibp = ps->ibp;
740 u16 lrh0; 750 u16 lrh0;
741 u32 nwords; 751 u32 nwords;
742 u32 extra_bytes; 752 u32 extra_bytes;
@@ -747,13 +757,14 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr,
747 nwords = (qp->s_cur_size + extra_bytes) >> 2; 757 nwords = (qp->s_cur_size + extra_bytes) >> 2;
748 lrh0 = HFI1_LRH_BTH; 758 lrh0 = HFI1_LRH_BTH;
749 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) { 759 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
750 qp->s_hdrwords += hfi1_make_grh(ibp, &qp->s_hdr->ibh.u.l.grh, 760 qp->s_hdrwords += hfi1_make_grh(ibp,
751 &qp->remote_ah_attr.grh, 761 &ps->s_txreq->phdr.hdr.u.l.grh,
752 qp->s_hdrwords, nwords); 762 &qp->remote_ah_attr.grh,
763 qp->s_hdrwords, nwords);
753 lrh0 = HFI1_LRH_GRH; 764 lrh0 = HFI1_LRH_GRH;
754 middle = 0; 765 middle = 0;
755 } 766 }
756 lrh0 |= (qp->s_sc & 0xf) << 12 | (qp->remote_ah_attr.sl & 0xf) << 4; 767 lrh0 |= (priv->s_sc & 0xf) << 12 | (qp->remote_ah_attr.sl & 0xf) << 4;
757 /* 768 /*
758 * reset s_hdr/AHG fields 769 * reset s_hdr/AHG fields
759 * 770 *
@@ -765,10 +776,10 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr,
765 * build_ahg() will modify as appropriate 776 * build_ahg() will modify as appropriate
766 * to use the AHG feature. 777 * to use the AHG feature.
767 */ 778 */
768 qp->s_hdr->tx_flags = 0; 779 priv->s_hdr->tx_flags = 0;
769 qp->s_hdr->ahgcount = 0; 780 priv->s_hdr->ahgcount = 0;
770 qp->s_hdr->ahgidx = 0; 781 priv->s_hdr->ahgidx = 0;
771 qp->s_hdr->sde = NULL; 782 priv->s_hdr->sde = NULL;
772 if (qp->s_mig_state == IB_MIG_MIGRATED) 783 if (qp->s_mig_state == IB_MIG_MIGRATED)
773 bth0 |= IB_BTH_MIG_REQ; 784 bth0 |= IB_BTH_MIG_REQ;
774 else 785 else
@@ -776,19 +787,19 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr,
776 if (middle) 787 if (middle)
777 build_ahg(qp, bth2); 788 build_ahg(qp, bth2);
778 else 789 else
779 qp->s_flags &= ~HFI1_S_AHG_VALID; 790 qp->s_flags &= ~RVT_S_AHG_VALID;
780 qp->s_hdr->ibh.lrh[0] = cpu_to_be16(lrh0); 791 ps->s_txreq->phdr.hdr.lrh[0] = cpu_to_be16(lrh0);
781 qp->s_hdr->ibh.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid); 792 ps->s_txreq->phdr.hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
782 qp->s_hdr->ibh.lrh[2] = 793 ps->s_txreq->phdr.hdr.lrh[2] =
783 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); 794 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
784 qp->s_hdr->ibh.lrh[3] = cpu_to_be16(ppd_from_ibp(ibp)->lid | 795 ps->s_txreq->phdr.hdr.lrh[3] = cpu_to_be16(ppd_from_ibp(ibp)->lid |
785 qp->remote_ah_attr.src_path_bits); 796 qp->remote_ah_attr.src_path_bits);
786 bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index); 797 bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index);
787 bth0 |= extra_bytes << 20; 798 bth0 |= extra_bytes << 20;
788 ohdr->bth[0] = cpu_to_be32(bth0); 799 ohdr->bth[0] = cpu_to_be32(bth0);
789 bth1 = qp->remote_qpn; 800 bth1 = qp->remote_qpn;
790 if (qp->s_flags & HFI1_S_ECN) { 801 if (qp->s_flags & RVT_S_ECN) {
791 qp->s_flags &= ~HFI1_S_ECN; 802 qp->s_flags &= ~RVT_S_ECN;
792 /* we recently received a FECN, so return a BECN */ 803 /* we recently received a FECN, so return a BECN */
793 bth1 |= (HFI1_BECN_MASK << HFI1_BECN_SHIFT); 804 bth1 |= (HFI1_BECN_MASK << HFI1_BECN_SHIFT);
794 } 805 }
@@ -799,6 +810,14 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr,
799/* when sending, force a reschedule every one of these periods */ 810/* when sending, force a reschedule every one of these periods */
800#define SEND_RESCHED_TIMEOUT (5 * HZ) /* 5s in jiffies */ 811#define SEND_RESCHED_TIMEOUT (5 * HZ) /* 5s in jiffies */
801 812
813void _hfi1_do_send(struct work_struct *work)
814{
815 struct iowait *wait = container_of(work, struct iowait, iowork);
816 struct rvt_qp *qp = iowait_to_qp(wait);
817
818 hfi1_do_send(qp);
819}
820
802/** 821/**
803 * hfi1_do_send - perform a send on a QP 822 * hfi1_do_send - perform a send on a QP
804 * @work: contains a pointer to the QP 823 * @work: contains a pointer to the QP
@@ -807,34 +826,45 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr,
807 * exhausted. Only allow one CPU to send a packet per QP (tasklet). 826 * exhausted. Only allow one CPU to send a packet per QP (tasklet).
808 * Otherwise, two threads could send packets out of order. 827 * Otherwise, two threads could send packets out of order.
809 */ 828 */
810void hfi1_do_send(struct work_struct *work) 829void hfi1_do_send(struct rvt_qp *qp)
811{ 830{
812 struct iowait *wait = container_of(work, struct iowait, iowork);
813 struct hfi1_qp *qp = container_of(wait, struct hfi1_qp, s_iowait);
814 struct hfi1_pkt_state ps; 831 struct hfi1_pkt_state ps;
815 int (*make_req)(struct hfi1_qp *qp); 832 struct hfi1_qp_priv *priv = qp->priv;
833 int (*make_req)(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
816 unsigned long flags; 834 unsigned long flags;
817 unsigned long timeout; 835 unsigned long timeout;
836 unsigned long timeout_int;
837 int cpu;
818 838
819 ps.dev = to_idev(qp->ibqp.device); 839 ps.dev = to_idev(qp->ibqp.device);
820 ps.ibp = to_iport(qp->ibqp.device, qp->port_num); 840 ps.ibp = to_iport(qp->ibqp.device, qp->port_num);
821 ps.ppd = ppd_from_ibp(ps.ibp); 841 ps.ppd = ppd_from_ibp(ps.ibp);
822 842
823 if ((qp->ibqp.qp_type == IB_QPT_RC || 843 switch (qp->ibqp.qp_type) {
824 qp->ibqp.qp_type == IB_QPT_UC) && 844 case IB_QPT_RC:
825 !loopback && 845 if (!loopback && ((qp->remote_ah_attr.dlid & ~((1 << ps.ppd->lmc
826 (qp->remote_ah_attr.dlid & ~((1 << ps.ppd->lmc) - 1)) == 846 ) - 1)) ==
827 ps.ppd->lid) { 847 ps.ppd->lid)) {
828 ruc_loopback(qp); 848 ruc_loopback(qp);
829 return; 849 return;
830 } 850 }
831
832 if (qp->ibqp.qp_type == IB_QPT_RC)
833 make_req = hfi1_make_rc_req; 851 make_req = hfi1_make_rc_req;
834 else if (qp->ibqp.qp_type == IB_QPT_UC) 852 timeout_int = (qp->timeout_jiffies);
853 break;
854 case IB_QPT_UC:
855 if (!loopback && ((qp->remote_ah_attr.dlid & ~((1 << ps.ppd->lmc
856 ) - 1)) ==
857 ps.ppd->lid)) {
858 ruc_loopback(qp);
859 return;
860 }
835 make_req = hfi1_make_uc_req; 861 make_req = hfi1_make_uc_req;
836 else 862 timeout_int = SEND_RESCHED_TIMEOUT;
863 break;
864 default:
837 make_req = hfi1_make_ud_req; 865 make_req = hfi1_make_ud_req;
866 timeout_int = SEND_RESCHED_TIMEOUT;
867 }
838 868
839 spin_lock_irqsave(&qp->s_lock, flags); 869 spin_lock_irqsave(&qp->s_lock, flags);
840 870
@@ -844,57 +874,83 @@ void hfi1_do_send(struct work_struct *work)
844 return; 874 return;
845 } 875 }
846 876
847 qp->s_flags |= HFI1_S_BUSY; 877 qp->s_flags |= RVT_S_BUSY;
848 878
849 spin_unlock_irqrestore(&qp->s_lock, flags); 879 timeout = jiffies + (timeout_int) / 8;
850 880 cpu = priv->s_sde ? priv->s_sde->cpu :
851 timeout = jiffies + SEND_RESCHED_TIMEOUT; 881 cpumask_first(cpumask_of_node(ps.ppd->dd->node));
882 /* insure a pre-built packet is handled */
883 ps.s_txreq = get_waiting_verbs_txreq(qp);
852 do { 884 do {
853 /* Check for a constructed packet to be sent. */ 885 /* Check for a constructed packet to be sent. */
854 if (qp->s_hdrwords != 0) { 886 if (qp->s_hdrwords != 0) {
887 spin_unlock_irqrestore(&qp->s_lock, flags);
855 /* 888 /*
856 * If the packet cannot be sent now, return and 889 * If the packet cannot be sent now, return and
857 * the send tasklet will be woken up later. 890 * the send tasklet will be woken up later.
858 */ 891 */
859 if (hfi1_verbs_send(qp, &ps)) 892 if (hfi1_verbs_send(qp, &ps))
860 break; 893 return;
861 /* Record that s_hdr is empty. */ 894 /* Record that s_hdr is empty. */
862 qp->s_hdrwords = 0; 895 qp->s_hdrwords = 0;
896 /* allow other tasks to run */
897 if (unlikely(time_after(jiffies, timeout))) {
898 if (workqueue_congested(cpu,
899 ps.ppd->hfi1_wq)) {
900 spin_lock_irqsave(&qp->s_lock, flags);
901 qp->s_flags &= ~RVT_S_BUSY;
902 hfi1_schedule_send(qp);
903 spin_unlock_irqrestore(&qp->s_lock,
904 flags);
905 this_cpu_inc(
906 *ps.ppd->dd->send_schedule);
907 return;
908 }
909 if (!irqs_disabled()) {
910 cond_resched();
911 this_cpu_inc(
912 *ps.ppd->dd->send_schedule);
913 }
914 timeout = jiffies + (timeout_int) / 8;
915 }
916 spin_lock_irqsave(&qp->s_lock, flags);
863 } 917 }
918 } while (make_req(qp, &ps));
864 919
865 /* allow other tasks to run */ 920 spin_unlock_irqrestore(&qp->s_lock, flags);
866 if (unlikely(time_after(jiffies, timeout))) {
867 cond_resched();
868 ps.ppd->dd->verbs_dev.n_send_schedule++;
869 timeout = jiffies + SEND_RESCHED_TIMEOUT;
870 }
871 } while (make_req(qp));
872} 921}
873 922
874/* 923/*
875 * This should be called with s_lock held. 924 * This should be called with s_lock held.
876 */ 925 */
877void hfi1_send_complete(struct hfi1_qp *qp, struct hfi1_swqe *wqe, 926void hfi1_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
878 enum ib_wc_status status) 927 enum ib_wc_status status)
879{ 928{
880 u32 old_last, last; 929 u32 old_last, last;
881 unsigned i; 930 unsigned i;
882 931
883 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_OR_FLUSH_SEND)) 932 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND))
884 return; 933 return;
885 934
935 last = qp->s_last;
936 old_last = last;
937 if (++last >= qp->s_size)
938 last = 0;
939 qp->s_last = last;
940 /* See post_send() */
941 barrier();
886 for (i = 0; i < wqe->wr.num_sge; i++) { 942 for (i = 0; i < wqe->wr.num_sge; i++) {
887 struct hfi1_sge *sge = &wqe->sg_list[i]; 943 struct rvt_sge *sge = &wqe->sg_list[i];
888 944
889 hfi1_put_mr(sge->mr); 945 rvt_put_mr(sge->mr);
890 } 946 }
891 if (qp->ibqp.qp_type == IB_QPT_UD || 947 if (qp->ibqp.qp_type == IB_QPT_UD ||
892 qp->ibqp.qp_type == IB_QPT_SMI || 948 qp->ibqp.qp_type == IB_QPT_SMI ||
893 qp->ibqp.qp_type == IB_QPT_GSI) 949 qp->ibqp.qp_type == IB_QPT_GSI)
894 atomic_dec(&to_iah(wqe->ud_wr.ah)->refcount); 950 atomic_dec(&ibah_to_rvtah(wqe->ud_wr.ah)->refcount);
895 951
896 /* See ch. 11.2.4.1 and 10.7.3.1 */ 952 /* See ch. 11.2.4.1 and 10.7.3.1 */
897 if (!(qp->s_flags & HFI1_S_SIGNAL_REQ_WR) || 953 if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) ||
898 (wqe->wr.send_flags & IB_SEND_SIGNALED) || 954 (wqe->wr.send_flags & IB_SEND_SIGNALED) ||
899 status != IB_WC_SUCCESS) { 955 status != IB_WC_SUCCESS) {
900 struct ib_wc wc; 956 struct ib_wc wc;
@@ -906,15 +962,10 @@ void hfi1_send_complete(struct hfi1_qp *qp, struct hfi1_swqe *wqe,
906 wc.qp = &qp->ibqp; 962 wc.qp = &qp->ibqp;
907 if (status == IB_WC_SUCCESS) 963 if (status == IB_WC_SUCCESS)
908 wc.byte_len = wqe->length; 964 wc.byte_len = wqe->length;
909 hfi1_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 965 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc,
910 status != IB_WC_SUCCESS); 966 status != IB_WC_SUCCESS);
911 } 967 }
912 968
913 last = qp->s_last;
914 old_last = last;
915 if (++last >= qp->s_size)
916 last = 0;
917 qp->s_last = last;
918 if (qp->s_acked == old_last) 969 if (qp->s_acked == old_last)
919 qp->s_acked = last; 970 qp->s_acked = last;
920 if (qp->s_cur == old_last) 971 if (qp->s_cur == old_last)
diff --git a/drivers/staging/rdma/hfi1/sdma.c b/drivers/staging/rdma/hfi1/sdma.c
index 9a15f1f32b45..abb8ebc1fcac 100644
--- a/drivers/staging/rdma/hfi1/sdma.c
+++ b/drivers/staging/rdma/hfi1/sdma.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -112,10 +109,10 @@ MODULE_PARM_DESC(desct_intr, "Number of SDMA descriptor before interrupt");
112 | SD(ENG_ERR_STATUS_SDMA_HEADER_REQUEST_FIFO_UNC_ERR_SMASK)) 109 | SD(ENG_ERR_STATUS_SDMA_HEADER_REQUEST_FIFO_UNC_ERR_SMASK))
113 110
114/* sdma_sendctrl operations */ 111/* sdma_sendctrl operations */
115#define SDMA_SENDCTRL_OP_ENABLE (1U << 0) 112#define SDMA_SENDCTRL_OP_ENABLE BIT(0)
116#define SDMA_SENDCTRL_OP_INTENABLE (1U << 1) 113#define SDMA_SENDCTRL_OP_INTENABLE BIT(1)
117#define SDMA_SENDCTRL_OP_HALT (1U << 2) 114#define SDMA_SENDCTRL_OP_HALT BIT(2)
118#define SDMA_SENDCTRL_OP_CLEANUP (1U << 3) 115#define SDMA_SENDCTRL_OP_CLEANUP BIT(3)
119 116
120/* handle long defines */ 117/* handle long defines */
121#define SDMA_EGRESS_PACKET_OCCUPANCY_SMASK \ 118#define SDMA_EGRESS_PACKET_OCCUPANCY_SMASK \
@@ -325,9 +322,9 @@ static void sdma_wait_for_packet_egress(struct sdma_engine *sde,
325 if (lcnt++ > 500) { 322 if (lcnt++ > 500) {
326 /* timed out - bounce the link */ 323 /* timed out - bounce the link */
327 dd_dev_err(dd, "%s: engine %u timeout waiting for packets to egress, remaining count %u, bouncing link\n", 324 dd_dev_err(dd, "%s: engine %u timeout waiting for packets to egress, remaining count %u, bouncing link\n",
328 __func__, sde->this_idx, (u32)reg); 325 __func__, sde->this_idx, (u32)reg);
329 queue_work(dd->pport->hfi1_wq, 326 queue_work(dd->pport->hfi1_wq,
330 &dd->pport->link_bounce_work); 327 &dd->pport->link_bounce_work);
331 break; 328 break;
332 } 329 }
333 udelay(1); 330 udelay(1);
@@ -361,6 +358,28 @@ static inline void sdma_set_desc_cnt(struct sdma_engine *sde, unsigned cnt)
361 write_sde_csr(sde, SD(DESC_CNT), reg); 358 write_sde_csr(sde, SD(DESC_CNT), reg);
362} 359}
363 360
361static inline void complete_tx(struct sdma_engine *sde,
362 struct sdma_txreq *tx,
363 int res)
364{
365 /* protect against complete modifying */
366 struct iowait *wait = tx->wait;
367 callback_t complete = tx->complete;
368
369#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
370 trace_hfi1_sdma_out_sn(sde, tx->sn);
371 if (WARN_ON_ONCE(sde->head_sn != tx->sn))
372 dd_dev_err(sde->dd, "expected %llu got %llu\n",
373 sde->head_sn, tx->sn);
374 sde->head_sn++;
375#endif
376 sdma_txclean(sde->dd, tx);
377 if (complete)
378 (*complete)(tx, res);
379 if (iowait_sdma_dec(wait) && wait)
380 iowait_drain_wakeup(wait);
381}
382
364/* 383/*
365 * Complete all the sdma requests with a SDMA_TXREQ_S_ABORTED status 384 * Complete all the sdma requests with a SDMA_TXREQ_S_ABORTED status
366 * 385 *
@@ -395,27 +414,8 @@ static void sdma_flush(struct sdma_engine *sde)
395 } 414 }
396 spin_unlock_irqrestore(&sde->flushlist_lock, flags); 415 spin_unlock_irqrestore(&sde->flushlist_lock, flags);
397 /* flush from flush list */ 416 /* flush from flush list */
398 list_for_each_entry_safe(txp, txp_next, &flushlist, list) { 417 list_for_each_entry_safe(txp, txp_next, &flushlist, list)
399 int drained = 0; 418 complete_tx(sde, txp, SDMA_TXREQ_S_ABORTED);
400 /* protect against complete modifying */
401 struct iowait *wait = txp->wait;
402
403 list_del_init(&txp->list);
404#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
405 trace_hfi1_sdma_out_sn(sde, txp->sn);
406 if (WARN_ON_ONCE(sde->head_sn != txp->sn))
407 dd_dev_err(sde->dd, "expected %llu got %llu\n",
408 sde->head_sn, txp->sn);
409 sde->head_sn++;
410#endif
411 sdma_txclean(sde->dd, txp);
412 if (wait)
413 drained = atomic_dec_and_test(&wait->sdma_busy);
414 if (txp->complete)
415 (*txp->complete)(txp, SDMA_TXREQ_S_ABORTED, drained);
416 if (wait && drained)
417 iowait_drain_wakeup(wait);
418 }
419} 419}
420 420
421/* 421/*
@@ -455,8 +455,8 @@ static void sdma_err_halt_wait(struct work_struct *work)
455 break; 455 break;
456 if (time_after(jiffies, timeout)) { 456 if (time_after(jiffies, timeout)) {
457 dd_dev_err(sde->dd, 457 dd_dev_err(sde->dd,
458 "SDMA engine %d - timeout waiting for engine to halt\n", 458 "SDMA engine %d - timeout waiting for engine to halt\n",
459 sde->this_idx); 459 sde->this_idx);
460 /* 460 /*
461 * Continue anyway. This could happen if there was 461 * Continue anyway. This could happen if there was
462 * an uncorrectable error in the wrong spot. 462 * an uncorrectable error in the wrong spot.
@@ -472,7 +472,6 @@ static void sdma_err_halt_wait(struct work_struct *work)
472static void sdma_err_progress_check_schedule(struct sdma_engine *sde) 472static void sdma_err_progress_check_schedule(struct sdma_engine *sde)
473{ 473{
474 if (!is_bx(sde->dd) && HFI1_CAP_IS_KSET(SDMA_AHG)) { 474 if (!is_bx(sde->dd) && HFI1_CAP_IS_KSET(SDMA_AHG)) {
475
476 unsigned index; 475 unsigned index;
477 struct hfi1_devdata *dd = sde->dd; 476 struct hfi1_devdata *dd = sde->dd;
478 477
@@ -531,7 +530,7 @@ static void sdma_err_progress_check(unsigned long data)
531 530
532static void sdma_hw_clean_up_task(unsigned long opaque) 531static void sdma_hw_clean_up_task(unsigned long opaque)
533{ 532{
534 struct sdma_engine *sde = (struct sdma_engine *) opaque; 533 struct sdma_engine *sde = (struct sdma_engine *)opaque;
535 u64 statuscsr; 534 u64 statuscsr;
536 535
537 while (1) { 536 while (1) {
@@ -577,31 +576,10 @@ static void sdma_flush_descq(struct sdma_engine *sde)
577 head = ++sde->descq_head & sde->sdma_mask; 576 head = ++sde->descq_head & sde->sdma_mask;
578 /* if now past this txp's descs, do the callback */ 577 /* if now past this txp's descs, do the callback */
579 if (txp && txp->next_descq_idx == head) { 578 if (txp && txp->next_descq_idx == head) {
580 int drained = 0;
581 /* protect against complete modifying */
582 struct iowait *wait = txp->wait;
583
584 /* remove from list */ 579 /* remove from list */
585 sde->tx_ring[sde->tx_head++ & sde->sdma_mask] = NULL; 580 sde->tx_ring[sde->tx_head++ & sde->sdma_mask] = NULL;
586 if (wait) 581 complete_tx(sde, txp, SDMA_TXREQ_S_ABORTED);
587 drained = atomic_dec_and_test(&wait->sdma_busy);
588#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
589 trace_hfi1_sdma_out_sn(sde, txp->sn);
590 if (WARN_ON_ONCE(sde->head_sn != txp->sn))
591 dd_dev_err(sde->dd, "expected %llu got %llu\n",
592 sde->head_sn, txp->sn);
593 sde->head_sn++;
594#endif
595 sdma_txclean(sde->dd, txp);
596 trace_hfi1_sdma_progress(sde, head, tail, txp); 582 trace_hfi1_sdma_progress(sde, head, tail, txp);
597 if (txp->complete)
598 (*txp->complete)(
599 txp,
600 SDMA_TXREQ_S_ABORTED,
601 drained);
602 if (wait && drained)
603 iowait_drain_wakeup(wait);
604 /* see if there is another txp */
605 txp = get_txhead(sde); 583 txp = get_txhead(sde);
606 } 584 }
607 progress++; 585 progress++;
@@ -612,7 +590,7 @@ static void sdma_flush_descq(struct sdma_engine *sde)
612 590
613static void sdma_sw_clean_up_task(unsigned long opaque) 591static void sdma_sw_clean_up_task(unsigned long opaque)
614{ 592{
615 struct sdma_engine *sde = (struct sdma_engine *) opaque; 593 struct sdma_engine *sde = (struct sdma_engine *)opaque;
616 unsigned long flags; 594 unsigned long flags;
617 595
618 spin_lock_irqsave(&sde->tail_lock, flags); 596 spin_lock_irqsave(&sde->tail_lock, flags);
@@ -627,7 +605,6 @@ static void sdma_sw_clean_up_task(unsigned long opaque)
627 * descq are ours to play with. 605 * descq are ours to play with.
628 */ 606 */
629 607
630
631 /* 608 /*
632 * In the error clean up sequence, software clean must be called 609 * In the error clean up sequence, software clean must be called
633 * before the hardware clean so we can use the hardware head in 610 * before the hardware clean so we can use the hardware head in
@@ -676,7 +653,7 @@ static void sdma_start_hw_clean_up(struct sdma_engine *sde)
676} 653}
677 654
678static void sdma_set_state(struct sdma_engine *sde, 655static void sdma_set_state(struct sdma_engine *sde,
679 enum sdma_states next_state) 656 enum sdma_states next_state)
680{ 657{
681 struct sdma_state *ss = &sde->state; 658 struct sdma_state *ss = &sde->state;
682 const struct sdma_set_state_action *action = sdma_action_table; 659 const struct sdma_set_state_action *action = sdma_action_table;
@@ -692,8 +669,8 @@ static void sdma_set_state(struct sdma_engine *sde,
692 ss->previous_op = ss->current_op; 669 ss->previous_op = ss->current_op;
693 ss->current_state = next_state; 670 ss->current_state = next_state;
694 671
695 if (ss->previous_state != sdma_state_s99_running 672 if (ss->previous_state != sdma_state_s99_running &&
696 && next_state == sdma_state_s99_running) 673 next_state == sdma_state_s99_running)
697 sdma_flush(sde); 674 sdma_flush(sde);
698 675
699 if (action[next_state].op_enable) 676 if (action[next_state].op_enable)
@@ -890,6 +867,9 @@ int sdma_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls, u8 *vl_engines)
890 newmap->actual_vls = num_vls; 867 newmap->actual_vls = num_vls;
891 newmap->vls = roundup_pow_of_two(num_vls); 868 newmap->vls = roundup_pow_of_two(num_vls);
892 newmap->mask = (1 << ilog2(newmap->vls)) - 1; 869 newmap->mask = (1 << ilog2(newmap->vls)) - 1;
870 /* initialize back-map */
871 for (i = 0; i < TXE_NUM_SDMA_ENGINES; i++)
872 newmap->engine_to_vl[i] = -1;
893 for (i = 0; i < newmap->vls; i++) { 873 for (i = 0; i < newmap->vls; i++) {
894 /* save for wrap around */ 874 /* save for wrap around */
895 int first_engine = engine; 875 int first_engine = engine;
@@ -913,6 +893,9 @@ int sdma_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls, u8 *vl_engines)
913 /* wrap back to first engine */ 893 /* wrap back to first engine */
914 engine = first_engine; 894 engine = first_engine;
915 } 895 }
896 /* assign back-map */
897 for (j = 0; j < vl_engines[i]; j++)
898 newmap->engine_to_vl[first_engine + j] = i;
916 } else { 899 } else {
917 /* just re-use entry without allocating */ 900 /* just re-use entry without allocating */
918 newmap->map[i] = newmap->map[i % num_vls]; 901 newmap->map[i] = newmap->map[i % num_vls];
@@ -922,7 +905,7 @@ int sdma_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls, u8 *vl_engines)
922 /* newmap in hand, save old map */ 905 /* newmap in hand, save old map */
923 spin_lock_irq(&dd->sde_map_lock); 906 spin_lock_irq(&dd->sde_map_lock);
924 oldmap = rcu_dereference_protected(dd->sdma_map, 907 oldmap = rcu_dereference_protected(dd->sdma_map,
925 lockdep_is_held(&dd->sde_map_lock)); 908 lockdep_is_held(&dd->sde_map_lock));
926 909
927 /* publish newmap */ 910 /* publish newmap */
928 rcu_assign_pointer(dd->sdma_map, newmap); 911 rcu_assign_pointer(dd->sdma_map, newmap);
@@ -983,7 +966,7 @@ static void sdma_clean(struct hfi1_devdata *dd, size_t num_engines)
983 sde->tx_ring = NULL; 966 sde->tx_ring = NULL;
984 } 967 }
985 spin_lock_irq(&dd->sde_map_lock); 968 spin_lock_irq(&dd->sde_map_lock);
986 kfree(rcu_access_pointer(dd->sdma_map)); 969 sdma_map_free(rcu_access_pointer(dd->sdma_map));
987 RCU_INIT_POINTER(dd->sdma_map, NULL); 970 RCU_INIT_POINTER(dd->sdma_map, NULL);
988 spin_unlock_irq(&dd->sde_map_lock); 971 spin_unlock_irq(&dd->sde_map_lock);
989 synchronize_rcu(); 972 synchronize_rcu();
@@ -1020,19 +1003,19 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
1020 return 0; 1003 return 0;
1021 } 1004 }
1022 if (mod_num_sdma && 1005 if (mod_num_sdma &&
1023 /* can't exceed chip support */ 1006 /* can't exceed chip support */
1024 mod_num_sdma <= dd->chip_sdma_engines && 1007 mod_num_sdma <= dd->chip_sdma_engines &&
1025 /* count must be >= vls */ 1008 /* count must be >= vls */
1026 mod_num_sdma >= num_vls) 1009 mod_num_sdma >= num_vls)
1027 num_engines = mod_num_sdma; 1010 num_engines = mod_num_sdma;
1028 1011
1029 dd_dev_info(dd, "SDMA mod_num_sdma: %u\n", mod_num_sdma); 1012 dd_dev_info(dd, "SDMA mod_num_sdma: %u\n", mod_num_sdma);
1030 dd_dev_info(dd, "SDMA chip_sdma_engines: %u\n", dd->chip_sdma_engines); 1013 dd_dev_info(dd, "SDMA chip_sdma_engines: %u\n", dd->chip_sdma_engines);
1031 dd_dev_info(dd, "SDMA chip_sdma_mem_size: %u\n", 1014 dd_dev_info(dd, "SDMA chip_sdma_mem_size: %u\n",
1032 dd->chip_sdma_mem_size); 1015 dd->chip_sdma_mem_size);
1033 1016
1034 per_sdma_credits = 1017 per_sdma_credits =
1035 dd->chip_sdma_mem_size/(num_engines * SDMA_BLOCK_SIZE); 1018 dd->chip_sdma_mem_size / (num_engines * SDMA_BLOCK_SIZE);
1036 1019
1037 /* set up freeze waitqueue */ 1020 /* set up freeze waitqueue */
1038 init_waitqueue_head(&dd->sdma_unfreeze_wq); 1021 init_waitqueue_head(&dd->sdma_unfreeze_wq);
@@ -1040,7 +1023,7 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
1040 1023
1041 descq_cnt = sdma_get_descq_cnt(); 1024 descq_cnt = sdma_get_descq_cnt();
1042 dd_dev_info(dd, "SDMA engines %zu descq_cnt %u\n", 1025 dd_dev_info(dd, "SDMA engines %zu descq_cnt %u\n",
1043 num_engines, descq_cnt); 1026 num_engines, descq_cnt);
1044 1027
1045 /* alloc memory for array of send engines */ 1028 /* alloc memory for array of send engines */
1046 dd->per_sdma = kcalloc(num_engines, sizeof(*dd->per_sdma), GFP_KERNEL); 1029 dd->per_sdma = kcalloc(num_engines, sizeof(*dd->per_sdma), GFP_KERNEL);
@@ -1061,18 +1044,18 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
1061 sde->desc_avail = sdma_descq_freecnt(sde); 1044 sde->desc_avail = sdma_descq_freecnt(sde);
1062 sde->sdma_shift = ilog2(descq_cnt); 1045 sde->sdma_shift = ilog2(descq_cnt);
1063 sde->sdma_mask = (1 << sde->sdma_shift) - 1; 1046 sde->sdma_mask = (1 << sde->sdma_shift) - 1;
1064 sde->descq_full_count = 0; 1047
1065 1048 /* Create a mask specifically for each interrupt source */
1066 /* Create a mask for all 3 chip interrupt sources */ 1049 sde->int_mask = (u64)1 << (0 * TXE_NUM_SDMA_ENGINES +
1067 sde->imask = (u64)1 << (0*TXE_NUM_SDMA_ENGINES + this_idx) 1050 this_idx);
1068 | (u64)1 << (1*TXE_NUM_SDMA_ENGINES + this_idx) 1051 sde->progress_mask = (u64)1 << (1 * TXE_NUM_SDMA_ENGINES +
1069 | (u64)1 << (2*TXE_NUM_SDMA_ENGINES + this_idx); 1052 this_idx);
1070 /* Create a mask specifically for sdma_idle */ 1053 sde->idle_mask = (u64)1 << (2 * TXE_NUM_SDMA_ENGINES +
1071 sde->idle_mask = 1054 this_idx);
1072 (u64)1 << (2*TXE_NUM_SDMA_ENGINES + this_idx); 1055 /* Create a combined mask to cover all 3 interrupt sources */
1073 /* Create a mask specifically for sdma_progress */ 1056 sde->imask = sde->int_mask | sde->progress_mask |
1074 sde->progress_mask = 1057 sde->idle_mask;
1075 (u64)1 << (TXE_NUM_SDMA_ENGINES + this_idx); 1058
1076 spin_lock_init(&sde->tail_lock); 1059 spin_lock_init(&sde->tail_lock);
1077 seqlock_init(&sde->head_lock); 1060 seqlock_init(&sde->head_lock);
1078 spin_lock_init(&sde->senddmactrl_lock); 1061 spin_lock_init(&sde->senddmactrl_lock);
@@ -1100,10 +1083,10 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
1100 SDMA_DESC1_INT_REQ_FLAG; 1083 SDMA_DESC1_INT_REQ_FLAG;
1101 1084
1102 tasklet_init(&sde->sdma_hw_clean_up_task, sdma_hw_clean_up_task, 1085 tasklet_init(&sde->sdma_hw_clean_up_task, sdma_hw_clean_up_task,
1103 (unsigned long)sde); 1086 (unsigned long)sde);
1104 1087
1105 tasklet_init(&sde->sdma_sw_clean_up_task, sdma_sw_clean_up_task, 1088 tasklet_init(&sde->sdma_sw_clean_up_task, sdma_sw_clean_up_task,
1106 (unsigned long)sde); 1089 (unsigned long)sde);
1107 INIT_WORK(&sde->err_halt_worker, sdma_err_halt_wait); 1090 INIT_WORK(&sde->err_halt_worker, sdma_err_halt_wait);
1108 INIT_WORK(&sde->flush_worker, sdma_field_flush); 1091 INIT_WORK(&sde->flush_worker, sdma_field_flush);
1109 1092
@@ -1251,11 +1234,10 @@ void sdma_exit(struct hfi1_devdata *dd)
1251 1234
1252 for (this_idx = 0; dd->per_sdma && this_idx < dd->num_sdma; 1235 for (this_idx = 0; dd->per_sdma && this_idx < dd->num_sdma;
1253 ++this_idx) { 1236 ++this_idx) {
1254
1255 sde = &dd->per_sdma[this_idx]; 1237 sde = &dd->per_sdma[this_idx];
1256 if (!list_empty(&sde->dmawait)) 1238 if (!list_empty(&sde->dmawait))
1257 dd_dev_err(dd, "sde %u: dmawait list not empty!\n", 1239 dd_dev_err(dd, "sde %u: dmawait list not empty!\n",
1258 sde->this_idx); 1240 sde->this_idx);
1259 sdma_process_event(sde, sdma_event_e00_go_hw_down); 1241 sdma_process_event(sde, sdma_event_e00_go_hw_down);
1260 1242
1261 del_timer_sync(&sde->err_progress_check_timer); 1243 del_timer_sync(&sde->err_progress_check_timer);
@@ -1358,8 +1340,8 @@ retry:
1358 use_dmahead = HFI1_CAP_IS_KSET(USE_SDMA_HEAD) && __sdma_running(sde) && 1340 use_dmahead = HFI1_CAP_IS_KSET(USE_SDMA_HEAD) && __sdma_running(sde) &&
1359 (dd->flags & HFI1_HAS_SDMA_TIMEOUT); 1341 (dd->flags & HFI1_HAS_SDMA_TIMEOUT);
1360 hwhead = use_dmahead ? 1342 hwhead = use_dmahead ?
1361 (u16) le64_to_cpu(*sde->head_dma) : 1343 (u16)le64_to_cpu(*sde->head_dma) :
1362 (u16) read_sde_csr(sde, SD(HEAD)); 1344 (u16)read_sde_csr(sde, SD(HEAD));
1363 1345
1364 if (unlikely(HFI1_CAP_IS_KSET(SDMA_HEAD_CHECK))) { 1346 if (unlikely(HFI1_CAP_IS_KSET(SDMA_HEAD_CHECK))) {
1365 u16 cnt; 1347 u16 cnt;
@@ -1385,9 +1367,9 @@ retry:
1385 1367
1386 if (unlikely(!sane)) { 1368 if (unlikely(!sane)) {
1387 dd_dev_err(dd, "SDMA(%u) bad head (%s) hwhd=%hu swhd=%hu swtl=%hu cnt=%hu\n", 1369 dd_dev_err(dd, "SDMA(%u) bad head (%s) hwhd=%hu swhd=%hu swtl=%hu cnt=%hu\n",
1388 sde->this_idx, 1370 sde->this_idx,
1389 use_dmahead ? "dma" : "kreg", 1371 use_dmahead ? "dma" : "kreg",
1390 hwhead, swhead, swtail, cnt); 1372 hwhead, swhead, swtail, cnt);
1391 if (use_dmahead) { 1373 if (use_dmahead) {
1392 /* try one more time, using csr */ 1374 /* try one more time, using csr */
1393 use_dmahead = 0; 1375 use_dmahead = 0;
@@ -1464,7 +1446,7 @@ static void sdma_make_progress(struct sdma_engine *sde, u64 status)
1464{ 1446{
1465 struct sdma_txreq *txp = NULL; 1447 struct sdma_txreq *txp = NULL;
1466 int progress = 0; 1448 int progress = 0;
1467 u16 hwhead, swhead, swtail; 1449 u16 hwhead, swhead;
1468 int idle_check_done = 0; 1450 int idle_check_done = 0;
1469 1451
1470 hwhead = sdma_gethead(sde); 1452 hwhead = sdma_gethead(sde);
@@ -1485,29 +1467,9 @@ retry:
1485 1467
1486 /* if now past this txp's descs, do the callback */ 1468 /* if now past this txp's descs, do the callback */
1487 if (txp && txp->next_descq_idx == swhead) { 1469 if (txp && txp->next_descq_idx == swhead) {
1488 int drained = 0;
1489 /* protect against complete modifying */
1490 struct iowait *wait = txp->wait;
1491
1492 /* remove from list */ 1470 /* remove from list */
1493 sde->tx_ring[sde->tx_head++ & sde->sdma_mask] = NULL; 1471 sde->tx_ring[sde->tx_head++ & sde->sdma_mask] = NULL;
1494 if (wait) 1472 complete_tx(sde, txp, SDMA_TXREQ_S_OK);
1495 drained = atomic_dec_and_test(&wait->sdma_busy);
1496#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
1497 trace_hfi1_sdma_out_sn(sde, txp->sn);
1498 if (WARN_ON_ONCE(sde->head_sn != txp->sn))
1499 dd_dev_err(sde->dd, "expected %llu got %llu\n",
1500 sde->head_sn, txp->sn);
1501 sde->head_sn++;
1502#endif
1503 sdma_txclean(sde->dd, txp);
1504 if (txp->complete)
1505 (*txp->complete)(
1506 txp,
1507 SDMA_TXREQ_S_OK,
1508 drained);
1509 if (wait && drained)
1510 iowait_drain_wakeup(wait);
1511 /* see if there is another txp */ 1473 /* see if there is another txp */
1512 txp = get_txhead(sde); 1474 txp = get_txhead(sde);
1513 } 1475 }
@@ -1525,6 +1487,8 @@ retry:
1525 * of sdma_make_progress(..) which is ensured by idle_check_done flag 1487 * of sdma_make_progress(..) which is ensured by idle_check_done flag
1526 */ 1488 */
1527 if ((status & sde->idle_mask) && !idle_check_done) { 1489 if ((status & sde->idle_mask) && !idle_check_done) {
1490 u16 swtail;
1491
1528 swtail = ACCESS_ONCE(sde->descq_tail) & sde->sdma_mask; 1492 swtail = ACCESS_ONCE(sde->descq_tail) & sde->sdma_mask;
1529 if (swtail != hwhead) { 1493 if (swtail != hwhead) {
1530 hwhead = (u16)read_sde_csr(sde, SD(HEAD)); 1494 hwhead = (u16)read_sde_csr(sde, SD(HEAD));
@@ -1552,6 +1516,12 @@ void sdma_engine_interrupt(struct sdma_engine *sde, u64 status)
1552 trace_hfi1_sdma_engine_interrupt(sde, status); 1516 trace_hfi1_sdma_engine_interrupt(sde, status);
1553 write_seqlock(&sde->head_lock); 1517 write_seqlock(&sde->head_lock);
1554 sdma_set_desc_cnt(sde, sdma_desct_intr); 1518 sdma_set_desc_cnt(sde, sdma_desct_intr);
1519 if (status & sde->idle_mask)
1520 sde->idle_int_cnt++;
1521 else if (status & sde->progress_mask)
1522 sde->progress_int_cnt++;
1523 else if (status & sde->int_mask)
1524 sde->sdma_int_cnt++;
1555 sdma_make_progress(sde, status); 1525 sdma_make_progress(sde, status);
1556 write_sequnlock(&sde->head_lock); 1526 write_sequnlock(&sde->head_lock);
1557} 1527}
@@ -1577,10 +1547,10 @@ void sdma_engine_error(struct sdma_engine *sde, u64 status)
1577 __sdma_process_event(sde, sdma_event_e60_hw_halted); 1547 __sdma_process_event(sde, sdma_event_e60_hw_halted);
1578 if (status & ~SD(ENG_ERR_STATUS_SDMA_HALT_ERR_SMASK)) { 1548 if (status & ~SD(ENG_ERR_STATUS_SDMA_HALT_ERR_SMASK)) {
1579 dd_dev_err(sde->dd, 1549 dd_dev_err(sde->dd,
1580 "SDMA (%u) engine error: 0x%llx state %s\n", 1550 "SDMA (%u) engine error: 0x%llx state %s\n",
1581 sde->this_idx, 1551 sde->this_idx,
1582 (unsigned long long)status, 1552 (unsigned long long)status,
1583 sdma_state_names[sde->state.current_state]); 1553 sdma_state_names[sde->state.current_state]);
1584 dump_sdma_state(sde); 1554 dump_sdma_state(sde);
1585 } 1555 }
1586 write_sequnlock(&sde->head_lock); 1556 write_sequnlock(&sde->head_lock);
@@ -1624,8 +1594,8 @@ static void sdma_sendctrl(struct sdma_engine *sde, unsigned op)
1624 1594
1625 if (op & SDMA_SENDCTRL_OP_CLEANUP) 1595 if (op & SDMA_SENDCTRL_OP_CLEANUP)
1626 write_sde_csr(sde, SD(CTRL), 1596 write_sde_csr(sde, SD(CTRL),
1627 sde->p_senddmactrl | 1597 sde->p_senddmactrl |
1628 SD(CTRL_SDMA_CLEANUP_SMASK)); 1598 SD(CTRL_SDMA_CLEANUP_SMASK));
1629 else 1599 else
1630 write_sde_csr(sde, SD(CTRL), sde->p_senddmactrl); 1600 write_sde_csr(sde, SD(CTRL), sde->p_senddmactrl);
1631 1601
@@ -1649,12 +1619,10 @@ static void sdma_setlengen(struct sdma_engine *sde)
1649 * generation counter. 1619 * generation counter.
1650 */ 1620 */
1651 write_sde_csr(sde, SD(LEN_GEN), 1621 write_sde_csr(sde, SD(LEN_GEN),
1652 (sde->descq_cnt/64) << SD(LEN_GEN_LENGTH_SHIFT) 1622 (sde->descq_cnt / 64) << SD(LEN_GEN_LENGTH_SHIFT));
1653 );
1654 write_sde_csr(sde, SD(LEN_GEN), 1623 write_sde_csr(sde, SD(LEN_GEN),
1655 ((sde->descq_cnt/64) << SD(LEN_GEN_LENGTH_SHIFT)) 1624 ((sde->descq_cnt / 64) << SD(LEN_GEN_LENGTH_SHIFT)) |
1656 | (4ULL << SD(LEN_GEN_GENERATION_SHIFT)) 1625 (4ULL << SD(LEN_GEN_GENERATION_SHIFT)));
1657 );
1658} 1626}
1659 1627
1660static inline void sdma_update_tail(struct sdma_engine *sde, u16 tail) 1628static inline void sdma_update_tail(struct sdma_engine *sde, u16 tail)
@@ -1714,7 +1682,6 @@ static void set_sdma_integrity(struct sdma_engine *sde)
1714 write_sde_csr(sde, SD(CHECK_ENABLE), reg); 1682 write_sde_csr(sde, SD(CHECK_ENABLE), reg);
1715} 1683}
1716 1684
1717
1718static void init_sdma_regs( 1685static void init_sdma_regs(
1719 struct sdma_engine *sde, 1686 struct sdma_engine *sde,
1720 u32 credits, 1687 u32 credits,
@@ -1735,17 +1702,16 @@ static void init_sdma_regs(
1735 write_sde_csr(sde, SD(DESC_CNT), 0); 1702 write_sde_csr(sde, SD(DESC_CNT), 0);
1736 write_sde_csr(sde, SD(HEAD_ADDR), sde->head_phys); 1703 write_sde_csr(sde, SD(HEAD_ADDR), sde->head_phys);
1737 write_sde_csr(sde, SD(MEMORY), 1704 write_sde_csr(sde, SD(MEMORY),
1738 ((u64)credits << 1705 ((u64)credits << SD(MEMORY_SDMA_MEMORY_CNT_SHIFT)) |
1739 SD(MEMORY_SDMA_MEMORY_CNT_SHIFT)) | 1706 ((u64)(credits * sde->this_idx) <<
1740 ((u64)(credits * sde->this_idx) << 1707 SD(MEMORY_SDMA_MEMORY_INDEX_SHIFT)));
1741 SD(MEMORY_SDMA_MEMORY_INDEX_SHIFT)));
1742 write_sde_csr(sde, SD(ENG_ERR_MASK), ~0ull); 1708 write_sde_csr(sde, SD(ENG_ERR_MASK), ~0ull);
1743 set_sdma_integrity(sde); 1709 set_sdma_integrity(sde);
1744 opmask = OPCODE_CHECK_MASK_DISABLED; 1710 opmask = OPCODE_CHECK_MASK_DISABLED;
1745 opval = OPCODE_CHECK_VAL_DISABLED; 1711 opval = OPCODE_CHECK_VAL_DISABLED;
1746 write_sde_csr(sde, SD(CHECK_OPCODE), 1712 write_sde_csr(sde, SD(CHECK_OPCODE),
1747 (opmask << SEND_CTXT_CHECK_OPCODE_MASK_SHIFT) | 1713 (opmask << SEND_CTXT_CHECK_OPCODE_MASK_SHIFT) |
1748 (opval << SEND_CTXT_CHECK_OPCODE_VALUE_SHIFT)); 1714 (opval << SEND_CTXT_CHECK_OPCODE_VALUE_SHIFT));
1749} 1715}
1750 1716
1751#ifdef CONFIG_SDMA_VERBOSITY 1717#ifdef CONFIG_SDMA_VERBOSITY
@@ -1824,12 +1790,9 @@ static void dump_sdma_state(struct sdma_engine *sde)
1824 descq = sde->descq; 1790 descq = sde->descq;
1825 1791
1826 dd_dev_err(sde->dd, 1792 dd_dev_err(sde->dd,
1827 "SDMA (%u) descq_head: %u descq_tail: %u freecnt: %u FLE %d\n", 1793 "SDMA (%u) descq_head: %u descq_tail: %u freecnt: %u FLE %d\n",
1828 sde->this_idx, 1794 sde->this_idx, head, tail, cnt,
1829 head, 1795 !list_empty(&sde->flushlist));
1830 tail,
1831 cnt,
1832 !list_empty(&sde->flushlist));
1833 1796
1834 /* print info for each entry in the descriptor queue */ 1797 /* print info for each entry in the descriptor queue */
1835 while (head != tail) { 1798 while (head != tail) {
@@ -1850,20 +1813,23 @@ static void dump_sdma_state(struct sdma_engine *sde)
1850 len = (desc[0] >> SDMA_DESC0_BYTE_COUNT_SHIFT) 1813 len = (desc[0] >> SDMA_DESC0_BYTE_COUNT_SHIFT)
1851 & SDMA_DESC0_BYTE_COUNT_MASK; 1814 & SDMA_DESC0_BYTE_COUNT_MASK;
1852 dd_dev_err(sde->dd, 1815 dd_dev_err(sde->dd,
1853 "SDMA sdmadesc[%u]: flags:%s addr:0x%016llx gen:%u len:%u bytes\n", 1816 "SDMA sdmadesc[%u]: flags:%s addr:0x%016llx gen:%u len:%u bytes\n",
1854 head, flags, addr, gen, len); 1817 head, flags, addr, gen, len);
1855 dd_dev_err(sde->dd, 1818 dd_dev_err(sde->dd,
1856 "\tdesc0:0x%016llx desc1 0x%016llx\n", 1819 "\tdesc0:0x%016llx desc1 0x%016llx\n",
1857 desc[0], desc[1]); 1820 desc[0], desc[1]);
1858 if (desc[0] & SDMA_DESC0_FIRST_DESC_FLAG) 1821 if (desc[0] & SDMA_DESC0_FIRST_DESC_FLAG)
1859 dd_dev_err(sde->dd, 1822 dd_dev_err(sde->dd,
1860 "\taidx: %u amode: %u alen: %u\n", 1823 "\taidx: %u amode: %u alen: %u\n",
1861 (u8)((desc[1] & SDMA_DESC1_HEADER_INDEX_SMASK) 1824 (u8)((desc[1] &
1862 >> SDMA_DESC1_HEADER_INDEX_SHIFT), 1825 SDMA_DESC1_HEADER_INDEX_SMASK) >>
1863 (u8)((desc[1] & SDMA_DESC1_HEADER_MODE_SMASK) 1826 SDMA_DESC1_HEADER_INDEX_SHIFT),
1864 >> SDMA_DESC1_HEADER_MODE_SHIFT), 1827 (u8)((desc[1] &
1865 (u8)((desc[1] & SDMA_DESC1_HEADER_DWS_SMASK) 1828 SDMA_DESC1_HEADER_MODE_SMASK) >>
1866 >> SDMA_DESC1_HEADER_DWS_SHIFT)); 1829 SDMA_DESC1_HEADER_MODE_SHIFT),
1830 (u8)((desc[1] &
1831 SDMA_DESC1_HEADER_DWS_SMASK) >>
1832 SDMA_DESC1_HEADER_DWS_SHIFT));
1867 head++; 1833 head++;
1868 head &= sde->sdma_mask; 1834 head &= sde->sdma_mask;
1869 } 1835 }
@@ -1890,29 +1856,26 @@ void sdma_seqfile_dump_sde(struct seq_file *s, struct sdma_engine *sde)
1890 head = sde->descq_head & sde->sdma_mask; 1856 head = sde->descq_head & sde->sdma_mask;
1891 tail = ACCESS_ONCE(sde->descq_tail) & sde->sdma_mask; 1857 tail = ACCESS_ONCE(sde->descq_tail) & sde->sdma_mask;
1892 seq_printf(s, SDE_FMT, sde->this_idx, 1858 seq_printf(s, SDE_FMT, sde->this_idx,
1893 sde->cpu, 1859 sde->cpu,
1894 sdma_state_name(sde->state.current_state), 1860 sdma_state_name(sde->state.current_state),
1895 (unsigned long long)read_sde_csr(sde, SD(CTRL)), 1861 (unsigned long long)read_sde_csr(sde, SD(CTRL)),
1896 (unsigned long long)read_sde_csr(sde, SD(STATUS)), 1862 (unsigned long long)read_sde_csr(sde, SD(STATUS)),
1897 (unsigned long long)read_sde_csr(sde, 1863 (unsigned long long)read_sde_csr(sde, SD(ENG_ERR_STATUS)),
1898 SD(ENG_ERR_STATUS)), 1864 (unsigned long long)read_sde_csr(sde, SD(TAIL)), tail,
1899 (unsigned long long)read_sde_csr(sde, SD(TAIL)), 1865 (unsigned long long)read_sde_csr(sde, SD(HEAD)), head,
1900 tail, 1866 (unsigned long long)le64_to_cpu(*sde->head_dma),
1901 (unsigned long long)read_sde_csr(sde, SD(HEAD)), 1867 (unsigned long long)read_sde_csr(sde, SD(MEMORY)),
1902 head, 1868 (unsigned long long)read_sde_csr(sde, SD(LEN_GEN)),
1903 (unsigned long long)le64_to_cpu(*sde->head_dma), 1869 (unsigned long long)read_sde_csr(sde, SD(RELOAD_CNT)),
1904 (unsigned long long)read_sde_csr(sde, SD(MEMORY)), 1870 (unsigned long long)sde->last_status,
1905 (unsigned long long)read_sde_csr(sde, SD(LEN_GEN)), 1871 (unsigned long long)sde->ahg_bits,
1906 (unsigned long long)read_sde_csr(sde, SD(RELOAD_CNT)), 1872 sde->tx_tail,
1907 (unsigned long long)sde->last_status, 1873 sde->tx_head,
1908 (unsigned long long)sde->ahg_bits, 1874 sde->descq_tail,
1909 sde->tx_tail, 1875 sde->descq_head,
1910 sde->tx_head,
1911 sde->descq_tail,
1912 sde->descq_head,
1913 !list_empty(&sde->flushlist), 1876 !list_empty(&sde->flushlist),
1914 sde->descq_full_count, 1877 sde->descq_full_count,
1915 (unsigned long long)read_sde_csr(sde, SEND_DMA_CHECK_SLID)); 1878 (unsigned long long)read_sde_csr(sde, SEND_DMA_CHECK_SLID));
1916 1879
1917 /* print info for each entry in the descriptor queue */ 1880 /* print info for each entry in the descriptor queue */
1918 while (head != tail) { 1881 while (head != tail) {
@@ -1933,14 +1896,16 @@ void sdma_seqfile_dump_sde(struct seq_file *s, struct sdma_engine *sde)
1933 len = (desc[0] >> SDMA_DESC0_BYTE_COUNT_SHIFT) 1896 len = (desc[0] >> SDMA_DESC0_BYTE_COUNT_SHIFT)
1934 & SDMA_DESC0_BYTE_COUNT_MASK; 1897 & SDMA_DESC0_BYTE_COUNT_MASK;
1935 seq_printf(s, 1898 seq_printf(s,
1936 "\tdesc[%u]: flags:%s addr:0x%016llx gen:%u len:%u bytes\n", 1899 "\tdesc[%u]: flags:%s addr:0x%016llx gen:%u len:%u bytes\n",
1937 head, flags, addr, gen, len); 1900 head, flags, addr, gen, len);
1938 if (desc[0] & SDMA_DESC0_FIRST_DESC_FLAG) 1901 if (desc[0] & SDMA_DESC0_FIRST_DESC_FLAG)
1939 seq_printf(s, "\t\tahgidx: %u ahgmode: %u\n", 1902 seq_printf(s, "\t\tahgidx: %u ahgmode: %u\n",
1940 (u8)((desc[1] & SDMA_DESC1_HEADER_INDEX_SMASK) 1903 (u8)((desc[1] &
1941 >> SDMA_DESC1_HEADER_INDEX_SHIFT), 1904 SDMA_DESC1_HEADER_INDEX_SMASK) >>
1942 (u8)((desc[1] & SDMA_DESC1_HEADER_MODE_SMASK) 1905 SDMA_DESC1_HEADER_INDEX_SHIFT),
1943 >> SDMA_DESC1_HEADER_MODE_SHIFT)); 1906 (u8)((desc[1] &
1907 SDMA_DESC1_HEADER_MODE_SMASK) >>
1908 SDMA_DESC1_HEADER_MODE_SHIFT));
1944 head = (head + 1) & sde->sdma_mask; 1909 head = (head + 1) & sde->sdma_mask;
1945 } 1910 }
1946} 1911}
@@ -2041,8 +2006,9 @@ static int sdma_check_progress(
2041 ret = wait->sleep(sde, wait, tx, seq); 2006 ret = wait->sleep(sde, wait, tx, seq);
2042 if (ret == -EAGAIN) 2007 if (ret == -EAGAIN)
2043 sde->desc_avail = sdma_descq_freecnt(sde); 2008 sde->desc_avail = sdma_descq_freecnt(sde);
2044 } else 2009 } else {
2045 ret = -EBUSY; 2010 ret = -EBUSY;
2011 }
2046 return ret; 2012 return ret;
2047} 2013}
2048 2014
@@ -2080,14 +2046,14 @@ retry:
2080 goto nodesc; 2046 goto nodesc;
2081 tail = submit_tx(sde, tx); 2047 tail = submit_tx(sde, tx);
2082 if (wait) 2048 if (wait)
2083 atomic_inc(&wait->sdma_busy); 2049 iowait_sdma_inc(wait);
2084 sdma_update_tail(sde, tail); 2050 sdma_update_tail(sde, tail);
2085unlock: 2051unlock:
2086 spin_unlock_irqrestore(&sde->tail_lock, flags); 2052 spin_unlock_irqrestore(&sde->tail_lock, flags);
2087 return ret; 2053 return ret;
2088unlock_noconn: 2054unlock_noconn:
2089 if (wait) 2055 if (wait)
2090 atomic_inc(&wait->sdma_busy); 2056 iowait_sdma_inc(wait);
2091 tx->next_descq_idx = 0; 2057 tx->next_descq_idx = 0;
2092#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER 2058#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
2093 tx->sn = sde->tail_sn++; 2059 tx->sn = sde->tail_sn++;
@@ -2132,13 +2098,12 @@ nodesc:
2132 * side locking. 2098 * side locking.
2133 * 2099 *
2134 * Return: 2100 * Return:
2135 * 0 - Success, -EINVAL - sdma_txreq incomplete, -EBUSY - no space in ring 2101 * > 0 - Success (value is number of sdma_txreq's submitted),
2136 * (wait == NULL) 2102 * -EINVAL - sdma_txreq incomplete, -EBUSY - no space in ring (wait == NULL)
2137 * -EIOCBQUEUED - tx queued to iowait, -ECOMM bad sdma state 2103 * -EIOCBQUEUED - tx queued to iowait, -ECOMM bad sdma state
2138 */ 2104 */
2139int sdma_send_txlist(struct sdma_engine *sde, 2105int sdma_send_txlist(struct sdma_engine *sde, struct iowait *wait,
2140 struct iowait *wait, 2106 struct list_head *tx_list)
2141 struct list_head *tx_list)
2142{ 2107{
2143 struct sdma_txreq *tx, *tx_next; 2108 struct sdma_txreq *tx, *tx_next;
2144 int ret = 0; 2109 int ret = 0;
@@ -2169,18 +2134,18 @@ retry:
2169 } 2134 }
2170update_tail: 2135update_tail:
2171 if (wait) 2136 if (wait)
2172 atomic_add(count, &wait->sdma_busy); 2137 iowait_sdma_add(wait, count);
2173 if (tail != INVALID_TAIL) 2138 if (tail != INVALID_TAIL)
2174 sdma_update_tail(sde, tail); 2139 sdma_update_tail(sde, tail);
2175 spin_unlock_irqrestore(&sde->tail_lock, flags); 2140 spin_unlock_irqrestore(&sde->tail_lock, flags);
2176 return ret; 2141 return ret == 0 ? count : ret;
2177unlock_noconn: 2142unlock_noconn:
2178 spin_lock(&sde->flushlist_lock); 2143 spin_lock(&sde->flushlist_lock);
2179 list_for_each_entry_safe(tx, tx_next, tx_list, list) { 2144 list_for_each_entry_safe(tx, tx_next, tx_list, list) {
2180 tx->wait = wait; 2145 tx->wait = wait;
2181 list_del_init(&tx->list); 2146 list_del_init(&tx->list);
2182 if (wait) 2147 if (wait)
2183 atomic_inc(&wait->sdma_busy); 2148 iowait_sdma_inc(wait);
2184 tx->next_descq_idx = 0; 2149 tx->next_descq_idx = 0;
2185#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER 2150#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
2186 tx->sn = sde->tail_sn++; 2151 tx->sn = sde->tail_sn++;
@@ -2206,8 +2171,7 @@ nodesc:
2206 goto update_tail; 2171 goto update_tail;
2207} 2172}
2208 2173
2209static void sdma_process_event(struct sdma_engine *sde, 2174static void sdma_process_event(struct sdma_engine *sde, enum sdma_events event)
2210 enum sdma_events event)
2211{ 2175{
2212 unsigned long flags; 2176 unsigned long flags;
2213 2177
@@ -2224,7 +2188,7 @@ static void sdma_process_event(struct sdma_engine *sde,
2224} 2188}
2225 2189
2226static void __sdma_process_event(struct sdma_engine *sde, 2190static void __sdma_process_event(struct sdma_engine *sde,
2227 enum sdma_events event) 2191 enum sdma_events event)
2228{ 2192{
2229 struct sdma_state *ss = &sde->state; 2193 struct sdma_state *ss = &sde->state;
2230 int need_progress = 0; 2194 int need_progress = 0;
@@ -2247,14 +2211,15 @@ static void __sdma_process_event(struct sdma_engine *sde,
2247 * of link up, then we need to start up. 2211 * of link up, then we need to start up.
2248 * This can happen when hw down is requested while 2212 * This can happen when hw down is requested while
2249 * bringing the link up with traffic active on 2213 * bringing the link up with traffic active on
2250 * 7220, e.g. */ 2214 * 7220, e.g.
2215 */
2251 ss->go_s99_running = 1; 2216 ss->go_s99_running = 1;
2252 /* fall through and start dma engine */ 2217 /* fall through and start dma engine */
2253 case sdma_event_e10_go_hw_start: 2218 case sdma_event_e10_go_hw_start:
2254 /* This reference means the state machine is started */ 2219 /* This reference means the state machine is started */
2255 sdma_get(&sde->state); 2220 sdma_get(&sde->state);
2256 sdma_set_state(sde, 2221 sdma_set_state(sde,
2257 sdma_state_s10_hw_start_up_halt_wait); 2222 sdma_state_s10_hw_start_up_halt_wait);
2258 break; 2223 break;
2259 case sdma_event_e15_hw_halt_done: 2224 case sdma_event_e15_hw_halt_done:
2260 break; 2225 break;
@@ -2292,7 +2257,7 @@ static void __sdma_process_event(struct sdma_engine *sde,
2292 break; 2257 break;
2293 case sdma_event_e15_hw_halt_done: 2258 case sdma_event_e15_hw_halt_done:
2294 sdma_set_state(sde, 2259 sdma_set_state(sde,
2295 sdma_state_s15_hw_start_up_clean_wait); 2260 sdma_state_s15_hw_start_up_clean_wait);
2296 sdma_start_hw_clean_up(sde); 2261 sdma_start_hw_clean_up(sde);
2297 break; 2262 break;
2298 case sdma_event_e25_hw_clean_up_done: 2263 case sdma_event_e25_hw_clean_up_done:
@@ -2767,7 +2732,7 @@ enomem:
2767 * This function calls _extend_sdma_tx_descs to extend or allocate 2732 * This function calls _extend_sdma_tx_descs to extend or allocate
2768 * coalesce buffer. If there is a allocated coalesce buffer, it will 2733 * coalesce buffer. If there is a allocated coalesce buffer, it will
2769 * copy the input packet data into the coalesce buffer. It also adds 2734 * copy the input packet data into the coalesce buffer. It also adds
2770 * coalesce buffer descriptor once whe whole packet is received. 2735 * coalesce buffer descriptor once when whole packet is received.
2771 * 2736 *
2772 * Return: 2737 * Return:
2773 * <0 - error 2738 * <0 - error
@@ -3030,7 +2995,8 @@ void sdma_freeze(struct hfi1_devdata *dd)
3030 * continuing. 2995 * continuing.
3031 */ 2996 */
3032 ret = wait_event_interruptible(dd->sdma_unfreeze_wq, 2997 ret = wait_event_interruptible(dd->sdma_unfreeze_wq,
3033 atomic_read(&dd->sdma_unfreeze_count) <= 0); 2998 atomic_read(&dd->sdma_unfreeze_count) <=
2999 0);
3034 /* interrupted or count is negative, then unloading - just exit */ 3000 /* interrupted or count is negative, then unloading - just exit */
3035 if (ret || atomic_read(&dd->sdma_unfreeze_count) < 0) 3001 if (ret || atomic_read(&dd->sdma_unfreeze_count) < 0)
3036 return; 3002 return;
@@ -3047,7 +3013,7 @@ void sdma_freeze(struct hfi1_devdata *dd)
3047 * software clean will read engine CSRs, so must be completed before 3013 * software clean will read engine CSRs, so must be completed before
3048 * the next step, which will clear the engine CSRs. 3014 * the next step, which will clear the engine CSRs.
3049 */ 3015 */
3050 (void) wait_event_interruptible(dd->sdma_unfreeze_wq, 3016 (void)wait_event_interruptible(dd->sdma_unfreeze_wq,
3051 atomic_read(&dd->sdma_unfreeze_count) <= 0); 3017 atomic_read(&dd->sdma_unfreeze_count) <= 0);
3052 /* no need to check results - done no matter what */ 3018 /* no need to check results - done no matter what */
3053} 3019}
@@ -3067,7 +3033,7 @@ void sdma_unfreeze(struct hfi1_devdata *dd)
3067 /* tell all engines start freeze clean up */ 3033 /* tell all engines start freeze clean up */
3068 for (i = 0; i < dd->num_sdma; i++) 3034 for (i = 0; i < dd->num_sdma; i++)
3069 sdma_process_event(&dd->per_sdma[i], 3035 sdma_process_event(&dd->per_sdma[i],
3070 sdma_event_e82_hw_unfreeze); 3036 sdma_event_e82_hw_unfreeze);
3071} 3037}
3072 3038
3073/** 3039/**
@@ -3081,5 +3047,6 @@ void _sdma_engine_progress_schedule(
3081 trace_hfi1_sdma_engine_progress(sde, sde->progress_mask); 3047 trace_hfi1_sdma_engine_progress(sde, sde->progress_mask);
3082 /* assume we have selected a good cpu */ 3048 /* assume we have selected a good cpu */
3083 write_csr(sde->dd, 3049 write_csr(sde->dd,
3084 CCE_INT_FORCE + (8*(IS_SDMA_START/64)), sde->progress_mask); 3050 CCE_INT_FORCE + (8 * (IS_SDMA_START / 64)),
3051 sde->progress_mask);
3085} 3052}
diff --git a/drivers/staging/rdma/hfi1/sdma.h b/drivers/staging/rdma/hfi1/sdma.h
index da89e6458162..8f50c99fe711 100644
--- a/drivers/staging/rdma/hfi1/sdma.h
+++ b/drivers/staging/rdma/hfi1/sdma.h
@@ -1,14 +1,13 @@
1#ifndef _HFI1_SDMA_H 1#ifndef _HFI1_SDMA_H
2#define _HFI1_SDMA_H 2#define _HFI1_SDMA_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -58,15 +55,13 @@
58 55
59#include "hfi.h" 56#include "hfi.h"
60#include "verbs.h" 57#include "verbs.h"
58#include "sdma_txreq.h"
61 59
62/* increased for AHG */
63#define NUM_DESC 6
64/* Hardware limit */ 60/* Hardware limit */
65#define MAX_DESC 64 61#define MAX_DESC 64
66/* Hardware limit for SDMA packet size */ 62/* Hardware limit for SDMA packet size */
67#define MAX_SDMA_PKT_SIZE ((16 * 1024) - 1) 63#define MAX_SDMA_PKT_SIZE ((16 * 1024) - 1)
68 64
69
70#define SDMA_TXREQ_S_OK 0 65#define SDMA_TXREQ_S_OK 0
71#define SDMA_TXREQ_S_SENDERROR 1 66#define SDMA_TXREQ_S_SENDERROR 1
72#define SDMA_TXREQ_S_ABORTED 2 67#define SDMA_TXREQ_S_ABORTED 2
@@ -109,8 +104,8 @@
109/* 104/*
110 * Bits defined in the send DMA descriptor. 105 * Bits defined in the send DMA descriptor.
111 */ 106 */
112#define SDMA_DESC0_FIRST_DESC_FLAG (1ULL << 63) 107#define SDMA_DESC0_FIRST_DESC_FLAG BIT_ULL(63)
113#define SDMA_DESC0_LAST_DESC_FLAG (1ULL << 62) 108#define SDMA_DESC0_LAST_DESC_FLAG BIT_ULL(62)
114#define SDMA_DESC0_BYTE_COUNT_SHIFT 48 109#define SDMA_DESC0_BYTE_COUNT_SHIFT 48
115#define SDMA_DESC0_BYTE_COUNT_WIDTH 14 110#define SDMA_DESC0_BYTE_COUNT_WIDTH 14
116#define SDMA_DESC0_BYTE_COUNT_MASK \ 111#define SDMA_DESC0_BYTE_COUNT_MASK \
@@ -154,8 +149,8 @@
154 ((1ULL << SDMA_DESC1_GENERATION_WIDTH) - 1) 149 ((1ULL << SDMA_DESC1_GENERATION_WIDTH) - 1)
155#define SDMA_DESC1_GENERATION_SMASK \ 150#define SDMA_DESC1_GENERATION_SMASK \
156 (SDMA_DESC1_GENERATION_MASK << SDMA_DESC1_GENERATION_SHIFT) 151 (SDMA_DESC1_GENERATION_MASK << SDMA_DESC1_GENERATION_SHIFT)
157#define SDMA_DESC1_INT_REQ_FLAG (1ULL << 1) 152#define SDMA_DESC1_INT_REQ_FLAG BIT_ULL(1)
158#define SDMA_DESC1_HEAD_TO_HOST_FLAG (1ULL << 0) 153#define SDMA_DESC1_HEAD_TO_HOST_FLAG BIT_ULL(0)
159 154
160enum sdma_states { 155enum sdma_states {
161 sdma_state_s00_hw_down, 156 sdma_state_s00_hw_down,
@@ -311,83 +306,6 @@ struct hw_sdma_desc {
311 __le64 qw[2]; 306 __le64 qw[2];
312}; 307};
313 308
314/*
315 * struct sdma_desc - canonical fragment descriptor
316 *
317 * This is the descriptor carried in the tx request
318 * corresponding to each fragment.
319 *
320 */
321struct sdma_desc {
322 /* private: don't use directly */
323 u64 qw[2];
324};
325
326struct sdma_txreq;
327typedef void (*callback_t)(struct sdma_txreq *, int, int);
328
329/**
330 * struct sdma_txreq - the sdma_txreq structure (one per packet)
331 * @list: for use by user and by queuing for wait
332 *
333 * This is the representation of a packet which consists of some
334 * number of fragments. Storage is provided to within the structure.
335 * for all fragments.
336 *
337 * The storage for the descriptors are automatically extended as needed
338 * when the currently allocation is exceeded.
339 *
340 * The user (Verbs or PSM) may overload this structure with fields
341 * specific to their use by putting this struct first in their struct.
342 * The method of allocation of the overloaded structure is user dependent
343 *
344 * The list is the only public field in the structure.
345 *
346 */
347
348struct sdma_txreq {
349 struct list_head list;
350 /* private: */
351 struct sdma_desc *descp;
352 /* private: */
353 void *coalesce_buf;
354 /* private: */
355 u16 coalesce_idx;
356 /* private: */
357 struct iowait *wait;
358 /* private: */
359 callback_t complete;
360#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
361 u64 sn;
362#endif
363 /* private: - used in coalesce/pad processing */
364 u16 packet_len;
365 /* private: - down-counted to trigger last */
366 u16 tlen;
367 /* private: flags */
368 u16 flags;
369 /* private: */
370 u16 num_desc;
371 /* private: */
372 u16 desc_limit;
373 /* private: */
374 u16 next_descq_idx;
375 /* private: */
376 struct sdma_desc descs[NUM_DESC];
377};
378
379struct verbs_txreq {
380 struct hfi1_pio_header phdr;
381 struct sdma_txreq txreq;
382 struct hfi1_qp *qp;
383 struct hfi1_swqe *wqe;
384 struct hfi1_mregion *mr;
385 struct hfi1_sge_state *ss;
386 struct sdma_engine *sde;
387 u16 hdr_dwords;
388 u16 hdr_inx;
389};
390
391/** 309/**
392 * struct sdma_engine - Data pertaining to each SDMA engine. 310 * struct sdma_engine - Data pertaining to each SDMA engine.
393 * @dd: a back-pointer to the device data 311 * @dd: a back-pointer to the device data
@@ -409,6 +327,7 @@ struct sdma_engine {
409 u64 imask; /* clear interrupt mask */ 327 u64 imask; /* clear interrupt mask */
410 u64 idle_mask; 328 u64 idle_mask;
411 u64 progress_mask; 329 u64 progress_mask;
330 u64 int_mask;
412 /* private: */ 331 /* private: */
413 volatile __le64 *head_dma; /* DMA'ed by chip */ 332 volatile __le64 *head_dma; /* DMA'ed by chip */
414 /* private: */ 333 /* private: */
@@ -465,6 +384,12 @@ struct sdma_engine {
465 u16 tx_head; 384 u16 tx_head;
466 /* private: */ 385 /* private: */
467 u64 last_status; 386 u64 last_status;
387 /* private */
388 u64 err_cnt;
389 /* private */
390 u64 sdma_int_cnt;
391 u64 idle_int_cnt;
392 u64 progress_int_cnt;
468 393
469 /* private: */ 394 /* private: */
470 struct list_head dmawait; 395 struct list_head dmawait;
@@ -484,12 +409,12 @@ struct sdma_engine {
484 u32 progress_check_head; 409 u32 progress_check_head;
485 /* private: */ 410 /* private: */
486 struct work_struct flush_worker; 411 struct work_struct flush_worker;
412 /* protect flush list */
487 spinlock_t flushlist_lock; 413 spinlock_t flushlist_lock;
488 /* private: */ 414 /* private: */
489 struct list_head flushlist; 415 struct list_head flushlist;
490}; 416};
491 417
492
493int sdma_init(struct hfi1_devdata *dd, u8 port); 418int sdma_init(struct hfi1_devdata *dd, u8 port);
494void sdma_start(struct hfi1_devdata *dd); 419void sdma_start(struct hfi1_devdata *dd);
495void sdma_exit(struct hfi1_devdata *dd); 420void sdma_exit(struct hfi1_devdata *dd);
@@ -535,7 +460,6 @@ static inline int __sdma_running(struct sdma_engine *engine)
535 return engine->state.current_state == sdma_state_s99_running; 460 return engine->state.current_state == sdma_state_s99_running;
536} 461}
537 462
538
539/** 463/**
540 * sdma_running() - state suitability test 464 * sdma_running() - state suitability test
541 * @engine: sdma engine 465 * @engine: sdma engine
@@ -565,7 +489,6 @@ void _sdma_txreq_ahgadd(
565 u32 *ahg, 489 u32 *ahg,
566 u8 ahg_hlen); 490 u8 ahg_hlen);
567 491
568
569/** 492/**
570 * sdma_txinit_ahg() - initialize an sdma_txreq struct with AHG 493 * sdma_txinit_ahg() - initialize an sdma_txreq struct with AHG
571 * @tx: tx request to initialize 494 * @tx: tx request to initialize
@@ -626,7 +549,7 @@ static inline int sdma_txinit_ahg(
626 u8 num_ahg, 549 u8 num_ahg,
627 u32 *ahg, 550 u32 *ahg,
628 u8 ahg_hlen, 551 u8 ahg_hlen,
629 void (*cb)(struct sdma_txreq *, int, int)) 552 void (*cb)(struct sdma_txreq *, int))
630{ 553{
631 if (tlen == 0) 554 if (tlen == 0)
632 return -ENODATA; 555 return -ENODATA;
@@ -640,7 +563,8 @@ static inline int sdma_txinit_ahg(
640 tx->complete = cb; 563 tx->complete = cb;
641 tx->coalesce_buf = NULL; 564 tx->coalesce_buf = NULL;
642 tx->wait = NULL; 565 tx->wait = NULL;
643 tx->tlen = tx->packet_len = tlen; 566 tx->packet_len = tlen;
567 tx->tlen = tx->packet_len;
644 tx->descs[0].qw[0] = SDMA_DESC0_FIRST_DESC_FLAG; 568 tx->descs[0].qw[0] = SDMA_DESC0_FIRST_DESC_FLAG;
645 tx->descs[0].qw[1] = 0; 569 tx->descs[0].qw[1] = 0;
646 if (flags & SDMA_TXREQ_F_AHG_COPY) 570 if (flags & SDMA_TXREQ_F_AHG_COPY)
@@ -689,7 +613,7 @@ static inline int sdma_txinit(
689 struct sdma_txreq *tx, 613 struct sdma_txreq *tx,
690 u16 flags, 614 u16 flags,
691 u16 tlen, 615 u16 tlen,
692 void (*cb)(struct sdma_txreq *, int, int)) 616 void (*cb)(struct sdma_txreq *, int))
693{ 617{
694 return sdma_txinit_ahg(tx, flags, tlen, 0, 0, NULL, 0, cb); 618 return sdma_txinit_ahg(tx, flags, tlen, 0, 0, NULL, 0, cb);
695} 619}
@@ -753,7 +677,7 @@ static inline void _sdma_close_tx(struct hfi1_devdata *dd,
753 dd->default_desc1; 677 dd->default_desc1;
754 if (tx->flags & SDMA_TXREQ_F_URGENT) 678 if (tx->flags & SDMA_TXREQ_F_URGENT)
755 tx->descp[tx->num_desc].qw[1] |= 679 tx->descp[tx->num_desc].qw[1] |=
756 (SDMA_DESC1_HEAD_TO_HOST_FLAG| 680 (SDMA_DESC1_HEAD_TO_HOST_FLAG |
757 SDMA_DESC1_INT_REQ_FLAG); 681 SDMA_DESC1_INT_REQ_FLAG);
758} 682}
759 683
@@ -1080,6 +1004,7 @@ struct sdma_map_elem {
1080 1004
1081/** 1005/**
1082 * struct sdma_map_el - mapping for a vl 1006 * struct sdma_map_el - mapping for a vl
1007 * @engine_to_vl - map of an engine to a vl
1083 * @list - rcu head for free callback 1008 * @list - rcu head for free callback
1084 * @mask - vl mask to "mod" the vl to produce an index to map array 1009 * @mask - vl mask to "mod" the vl to produce an index to map array
1085 * @actual_vls - number of vls 1010 * @actual_vls - number of vls
@@ -1091,6 +1016,7 @@ struct sdma_map_elem {
1091 * in turn point to an array of sde's for that vl. 1016 * in turn point to an array of sde's for that vl.
1092 */ 1017 */
1093struct sdma_vl_map { 1018struct sdma_vl_map {
1019 s8 engine_to_vl[TXE_NUM_SDMA_ENGINES];
1094 struct rcu_head list; 1020 struct rcu_head list;
1095 u32 mask; 1021 u32 mask;
1096 u8 actual_vls; 1022 u8 actual_vls;
diff --git a/drivers/staging/rdma/hfi1/sdma_txreq.h b/drivers/staging/rdma/hfi1/sdma_txreq.h
new file mode 100644
index 000000000000..bf7d777d756e
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/sdma_txreq.h
@@ -0,0 +1,135 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#ifndef HFI1_SDMA_TXREQ_H
49#define HFI1_SDMA_TXREQ_H
50
51/* increased for AHG */
52#define NUM_DESC 6
53
54/*
55 * struct sdma_desc - canonical fragment descriptor
56 *
57 * This is the descriptor carried in the tx request
58 * corresponding to each fragment.
59 *
60 */
61struct sdma_desc {
62 /* private: don't use directly */
63 u64 qw[2];
64};
65
66/**
67 * struct sdma_txreq - the sdma_txreq structure (one per packet)
68 * @list: for use by user and by queuing for wait
69 *
70 * This is the representation of a packet which consists of some
71 * number of fragments. Storage is provided to within the structure.
72 * for all fragments.
73 *
74 * The storage for the descriptors are automatically extended as needed
75 * when the currently allocation is exceeded.
76 *
77 * The user (Verbs or PSM) may overload this structure with fields
78 * specific to their use by putting this struct first in their struct.
79 * The method of allocation of the overloaded structure is user dependent
80 *
81 * The list is the only public field in the structure.
82 *
83 */
84
85#define SDMA_TXREQ_S_OK 0
86#define SDMA_TXREQ_S_SENDERROR 1
87#define SDMA_TXREQ_S_ABORTED 2
88#define SDMA_TXREQ_S_SHUTDOWN 3
89
90/* flags bits */
91#define SDMA_TXREQ_F_URGENT 0x0001
92#define SDMA_TXREQ_F_AHG_COPY 0x0002
93#define SDMA_TXREQ_F_USE_AHG 0x0004
94
95struct sdma_txreq;
96typedef void (*callback_t)(struct sdma_txreq *, int);
97
98struct iowait;
99struct sdma_txreq {
100 struct list_head list;
101 /* private: */
102 struct sdma_desc *descp;
103 /* private: */
104 void *coalesce_buf;
105 /* private: */
106 struct iowait *wait;
107 /* private: */
108 callback_t complete;
109#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
110 u64 sn;
111#endif
112 /* private: - used in coalesce/pad processing */
113 u16 packet_len;
114 /* private: - down-counted to trigger last */
115 u16 tlen;
116 /* private: */
117 u16 num_desc;
118 /* private: */
119 u16 desc_limit;
120 /* private: */
121 u16 next_descq_idx;
122 /* private: */
123 u16 coalesce_idx;
124 /* private: flags */
125 u16 flags;
126 /* private: */
127 struct sdma_desc descs[NUM_DESC];
128};
129
130static inline int sdma_txreq_built(struct sdma_txreq *tx)
131{
132 return tx->num_desc;
133}
134
135#endif /* HFI1_SDMA_TXREQ_H */
diff --git a/drivers/staging/rdma/hfi1/sysfs.c b/drivers/staging/rdma/hfi1/sysfs.c
index 1dd6727dd5ef..c7f1271190af 100644
--- a/drivers/staging/rdma/hfi1/sysfs.c
+++ b/drivers/staging/rdma/hfi1/sysfs.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -53,7 +50,6 @@
53#include "mad.h" 50#include "mad.h"
54#include "trace.h" 51#include "trace.h"
55 52
56
57/* 53/*
58 * Start of per-port congestion control structures and support code 54 * Start of per-port congestion control structures and support code
59 */ 55 */
@@ -62,8 +58,8 @@
62 * Congestion control table size followed by table entries 58 * Congestion control table size followed by table entries
63 */ 59 */
64static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj, 60static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj,
65 struct bin_attribute *bin_attr, 61 struct bin_attribute *bin_attr,
66 char *buf, loff_t pos, size_t count) 62 char *buf, loff_t pos, size_t count)
67{ 63{
68 int ret; 64 int ret;
69 struct hfi1_pportdata *ppd = 65 struct hfi1_pportdata *ppd =
@@ -84,7 +80,7 @@ static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj,
84 80
85 rcu_read_lock(); 81 rcu_read_lock();
86 cc_state = get_cc_state(ppd); 82 cc_state = get_cc_state(ppd);
87 if (cc_state == NULL) { 83 if (!cc_state) {
88 rcu_read_unlock(); 84 rcu_read_unlock();
89 return -EINVAL; 85 return -EINVAL;
90 } 86 }
@@ -99,10 +95,6 @@ static void port_release(struct kobject *kobj)
99 /* nothing to do since memory is freed by hfi1_free_devdata() */ 95 /* nothing to do since memory is freed by hfi1_free_devdata() */
100} 96}
101 97
102static struct kobj_type port_cc_ktype = {
103 .release = port_release,
104};
105
106static struct bin_attribute cc_table_bin_attr = { 98static struct bin_attribute cc_table_bin_attr = {
107 .attr = {.name = "cc_table_bin", .mode = 0444}, 99 .attr = {.name = "cc_table_bin", .mode = 0444},
108 .read = read_cc_table_bin, 100 .read = read_cc_table_bin,
@@ -115,8 +107,8 @@ static struct bin_attribute cc_table_bin_attr = {
115 * trigger threshold and the minimum injection rate delay. 107 * trigger threshold and the minimum injection rate delay.
116 */ 108 */
117static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj, 109static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj,
118 struct bin_attribute *bin_attr, 110 struct bin_attribute *bin_attr,
119 char *buf, loff_t pos, size_t count) 111 char *buf, loff_t pos, size_t count)
120{ 112{
121 int ret; 113 int ret;
122 struct hfi1_pportdata *ppd = 114 struct hfi1_pportdata *ppd =
@@ -135,7 +127,7 @@ static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj,
135 127
136 rcu_read_lock(); 128 rcu_read_lock();
137 cc_state = get_cc_state(ppd); 129 cc_state = get_cc_state(ppd);
138 if (cc_state == NULL) { 130 if (!cc_state) {
139 rcu_read_unlock(); 131 rcu_read_unlock();
140 return -EINVAL; 132 return -EINVAL;
141 } 133 }
@@ -151,6 +143,68 @@ static struct bin_attribute cc_setting_bin_attr = {
151 .size = PAGE_SIZE, 143 .size = PAGE_SIZE,
152}; 144};
153 145
146struct hfi1_port_attr {
147 struct attribute attr;
148 ssize_t (*show)(struct hfi1_pportdata *, char *);
149 ssize_t (*store)(struct hfi1_pportdata *, const char *, size_t);
150};
151
152static ssize_t cc_prescan_show(struct hfi1_pportdata *ppd, char *buf)
153{
154 return sprintf(buf, "%s\n", ppd->cc_prescan ? "on" : "off");
155}
156
157static ssize_t cc_prescan_store(struct hfi1_pportdata *ppd, const char *buf,
158 size_t count)
159{
160 if (!memcmp(buf, "on", 2))
161 ppd->cc_prescan = true;
162 else if (!memcmp(buf, "off", 3))
163 ppd->cc_prescan = false;
164
165 return count;
166}
167
168static struct hfi1_port_attr cc_prescan_attr =
169 __ATTR(cc_prescan, 0600, cc_prescan_show, cc_prescan_store);
170
171static ssize_t cc_attr_show(struct kobject *kobj, struct attribute *attr,
172 char *buf)
173{
174 struct hfi1_port_attr *port_attr =
175 container_of(attr, struct hfi1_port_attr, attr);
176 struct hfi1_pportdata *ppd =
177 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
178
179 return port_attr->show(ppd, buf);
180}
181
182static ssize_t cc_attr_store(struct kobject *kobj, struct attribute *attr,
183 const char *buf, size_t count)
184{
185 struct hfi1_port_attr *port_attr =
186 container_of(attr, struct hfi1_port_attr, attr);
187 struct hfi1_pportdata *ppd =
188 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
189
190 return port_attr->store(ppd, buf, count);
191}
192
193static const struct sysfs_ops port_cc_sysfs_ops = {
194 .show = cc_attr_show,
195 .store = cc_attr_store
196};
197
198static struct attribute *port_cc_default_attributes[] = {
199 &cc_prescan_attr.attr
200};
201
202static struct kobj_type port_cc_ktype = {
203 .release = port_release,
204 .sysfs_ops = &port_cc_sysfs_ops,
205 .default_attrs = port_cc_default_attributes
206};
207
154/* Start sc2vl */ 208/* Start sc2vl */
155#define HFI1_SC2VL_ATTR(N) \ 209#define HFI1_SC2VL_ATTR(N) \
156 static struct hfi1_sc2vl_attr hfi1_sc2vl_attr_##N = { \ 210 static struct hfi1_sc2vl_attr hfi1_sc2vl_attr_##N = { \
@@ -196,7 +250,6 @@ HFI1_SC2VL_ATTR(29);
196HFI1_SC2VL_ATTR(30); 250HFI1_SC2VL_ATTR(30);
197HFI1_SC2VL_ATTR(31); 251HFI1_SC2VL_ATTR(31);
198 252
199
200static struct attribute *sc2vl_default_attributes[] = { 253static struct attribute *sc2vl_default_attributes[] = {
201 &hfi1_sc2vl_attr_0.attr, 254 &hfi1_sc2vl_attr_0.attr,
202 &hfi1_sc2vl_attr_1.attr, 255 &hfi1_sc2vl_attr_1.attr,
@@ -302,7 +355,6 @@ HFI1_SL2SC_ATTR(29);
302HFI1_SL2SC_ATTR(30); 355HFI1_SL2SC_ATTR(30);
303HFI1_SL2SC_ATTR(31); 356HFI1_SL2SC_ATTR(31);
304 357
305
306static struct attribute *sl2sc_default_attributes[] = { 358static struct attribute *sl2sc_default_attributes[] = {
307 &hfi1_sl2sc_attr_0.attr, 359 &hfi1_sl2sc_attr_0.attr,
308 &hfi1_sl2sc_attr_1.attr, 360 &hfi1_sl2sc_attr_1.attr,
@@ -435,7 +487,6 @@ static struct kobj_type hfi1_vl2mtu_ktype = {
435 .default_attrs = vl2mtu_default_attributes 487 .default_attrs = vl2mtu_default_attributes
436}; 488};
437 489
438
439/* end of per-port file structures and support code */ 490/* end of per-port file structures and support code */
440 491
441/* 492/*
@@ -446,7 +497,7 @@ static ssize_t show_rev(struct device *device, struct device_attribute *attr,
446 char *buf) 497 char *buf)
447{ 498{
448 struct hfi1_ibdev *dev = 499 struct hfi1_ibdev *dev =
449 container_of(device, struct hfi1_ibdev, ibdev.dev); 500 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
450 501
451 return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev); 502 return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
452} 503}
@@ -455,7 +506,7 @@ static ssize_t show_hfi(struct device *device, struct device_attribute *attr,
455 char *buf) 506 char *buf)
456{ 507{
457 struct hfi1_ibdev *dev = 508 struct hfi1_ibdev *dev =
458 container_of(device, struct hfi1_ibdev, ibdev.dev); 509 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
459 struct hfi1_devdata *dd = dd_from_dev(dev); 510 struct hfi1_devdata *dd = dd_from_dev(dev);
460 int ret; 511 int ret;
461 512
@@ -470,19 +521,18 @@ static ssize_t show_boardversion(struct device *device,
470 struct device_attribute *attr, char *buf) 521 struct device_attribute *attr, char *buf)
471{ 522{
472 struct hfi1_ibdev *dev = 523 struct hfi1_ibdev *dev =
473 container_of(device, struct hfi1_ibdev, ibdev.dev); 524 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
474 struct hfi1_devdata *dd = dd_from_dev(dev); 525 struct hfi1_devdata *dd = dd_from_dev(dev);
475 526
476 /* The string printed here is already newline-terminated. */ 527 /* The string printed here is already newline-terminated. */
477 return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion); 528 return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion);
478} 529}
479 530
480
481static ssize_t show_nctxts(struct device *device, 531static ssize_t show_nctxts(struct device *device,
482 struct device_attribute *attr, char *buf) 532 struct device_attribute *attr, char *buf)
483{ 533{
484 struct hfi1_ibdev *dev = 534 struct hfi1_ibdev *dev =
485 container_of(device, struct hfi1_ibdev, ibdev.dev); 535 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
486 struct hfi1_devdata *dd = dd_from_dev(dev); 536 struct hfi1_devdata *dd = dd_from_dev(dev);
487 537
488 /* 538 /*
@@ -497,10 +547,10 @@ static ssize_t show_nctxts(struct device *device,
497} 547}
498 548
499static ssize_t show_nfreectxts(struct device *device, 549static ssize_t show_nfreectxts(struct device *device,
500 struct device_attribute *attr, char *buf) 550 struct device_attribute *attr, char *buf)
501{ 551{
502 struct hfi1_ibdev *dev = 552 struct hfi1_ibdev *dev =
503 container_of(device, struct hfi1_ibdev, ibdev.dev); 553 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
504 struct hfi1_devdata *dd = dd_from_dev(dev); 554 struct hfi1_devdata *dd = dd_from_dev(dev);
505 555
506 /* Return the number of free user ports (contexts) available. */ 556 /* Return the number of free user ports (contexts) available. */
@@ -511,11 +561,10 @@ static ssize_t show_serial(struct device *device,
511 struct device_attribute *attr, char *buf) 561 struct device_attribute *attr, char *buf)
512{ 562{
513 struct hfi1_ibdev *dev = 563 struct hfi1_ibdev *dev =
514 container_of(device, struct hfi1_ibdev, ibdev.dev); 564 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
515 struct hfi1_devdata *dd = dd_from_dev(dev); 565 struct hfi1_devdata *dd = dd_from_dev(dev);
516 566
517 return scnprintf(buf, PAGE_SIZE, "%s", dd->serial); 567 return scnprintf(buf, PAGE_SIZE, "%s", dd->serial);
518
519} 568}
520 569
521static ssize_t store_chip_reset(struct device *device, 570static ssize_t store_chip_reset(struct device *device,
@@ -523,7 +572,7 @@ static ssize_t store_chip_reset(struct device *device,
523 size_t count) 572 size_t count)
524{ 573{
525 struct hfi1_ibdev *dev = 574 struct hfi1_ibdev *dev =
526 container_of(device, struct hfi1_ibdev, ibdev.dev); 575 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
527 struct hfi1_devdata *dd = dd_from_dev(dev); 576 struct hfi1_devdata *dd = dd_from_dev(dev);
528 int ret; 577 int ret;
529 578
@@ -552,7 +601,7 @@ static ssize_t show_tempsense(struct device *device,
552 struct device_attribute *attr, char *buf) 601 struct device_attribute *attr, char *buf)
553{ 602{
554 struct hfi1_ibdev *dev = 603 struct hfi1_ibdev *dev =
555 container_of(device, struct hfi1_ibdev, ibdev.dev); 604 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
556 struct hfi1_devdata *dd = dd_from_dev(dev); 605 struct hfi1_devdata *dd = dd_from_dev(dev);
557 struct hfi1_temp temp; 606 struct hfi1_temp temp;
558 int ret; 607 int ret;
@@ -608,8 +657,8 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
608 657
609 if (!port_num || port_num > dd->num_pports) { 658 if (!port_num || port_num > dd->num_pports) {
610 dd_dev_err(dd, 659 dd_dev_err(dd,
611 "Skipping infiniband class with invalid port %u\n", 660 "Skipping infiniband class with invalid port %u\n",
612 port_num); 661 port_num);
613 return -ENODEV; 662 return -ENODEV;
614 } 663 }
615 ppd = &dd->pport[port_num - 1]; 664 ppd = &dd->pport[port_num - 1];
@@ -644,39 +693,36 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
644 } 693 }
645 kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD); 694 kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD);
646 695
647
648 ret = kobject_init_and_add(&ppd->pport_cc_kobj, &port_cc_ktype, 696 ret = kobject_init_and_add(&ppd->pport_cc_kobj, &port_cc_ktype,
649 kobj, "CCMgtA"); 697 kobj, "CCMgtA");
650 if (ret) { 698 if (ret) {
651 dd_dev_err(dd, 699 dd_dev_err(dd,
652 "Skipping Congestion Control sysfs info, (err %d) port %u\n", 700 "Skipping Congestion Control sysfs info, (err %d) port %u\n",
653 ret, port_num); 701 ret, port_num);
654 goto bail_vl2mtu; 702 goto bail_vl2mtu;
655 } 703 }
656 704
657 kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD); 705 kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
658 706
659 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, 707 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr);
660 &cc_setting_bin_attr);
661 if (ret) { 708 if (ret) {
662 dd_dev_err(dd, 709 dd_dev_err(dd,
663 "Skipping Congestion Control setting sysfs info, (err %d) port %u\n", 710 "Skipping Congestion Control setting sysfs info, (err %d) port %u\n",
664 ret, port_num); 711 ret, port_num);
665 goto bail_cc; 712 goto bail_cc;
666 } 713 }
667 714
668 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, 715 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_table_bin_attr);
669 &cc_table_bin_attr);
670 if (ret) { 716 if (ret) {
671 dd_dev_err(dd, 717 dd_dev_err(dd,
672 "Skipping Congestion Control table sysfs info, (err %d) port %u\n", 718 "Skipping Congestion Control table sysfs info, (err %d) port %u\n",
673 ret, port_num); 719 ret, port_num);
674 goto bail_cc_entry_bin; 720 goto bail_cc_entry_bin;
675 } 721 }
676 722
677 dd_dev_info(dd, 723 dd_dev_info(dd,
678 "IB%u: Congestion Control Agent enabled for port %d\n", 724 "IB%u: Congestion Control Agent enabled for port %d\n",
679 dd->unit, port_num); 725 dd->unit, port_num);
680 726
681 return 0; 727 return 0;
682 728
@@ -700,7 +746,7 @@ bail:
700 */ 746 */
701int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd) 747int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd)
702{ 748{
703 struct ib_device *dev = &dd->verbs_dev.ibdev; 749 struct ib_device *dev = &dd->verbs_dev.rdi.ibdev;
704 int i, ret; 750 int i, ret;
705 751
706 for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i) { 752 for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i) {
diff --git a/drivers/staging/rdma/hfi1/trace.c b/drivers/staging/rdma/hfi1/trace.c
index 10122e84cb2f..8b62fefcf903 100644
--- a/drivers/staging/rdma/hfi1/trace.c
+++ b/drivers/staging/rdma/hfi1/trace.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -109,17 +106,17 @@ const char *parse_everbs_hdrs(
109 case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE): 106 case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
110 case OP(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE): 107 case OP(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
111 trace_seq_printf(p, IMM_PRN, 108 trace_seq_printf(p, IMM_PRN,
112 be32_to_cpu(eh->imm_data)); 109 be32_to_cpu(eh->imm_data));
113 break; 110 break;
114 /* reth + imm */ 111 /* reth + imm */
115 case OP(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE): 112 case OP(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
116 case OP(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE): 113 case OP(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
117 trace_seq_printf(p, RETH_PRN " " IMM_PRN, 114 trace_seq_printf(p, RETH_PRN " " IMM_PRN,
118 (unsigned long long)ib_u64_get( 115 (unsigned long long)ib_u64_get(
119 (__be32 *)&eh->rc.reth.vaddr), 116 (__be32 *)&eh->rc.reth.vaddr),
120 be32_to_cpu(eh->rc.reth.rkey), 117 be32_to_cpu(eh->rc.reth.rkey),
121 be32_to_cpu(eh->rc.reth.length), 118 be32_to_cpu(eh->rc.reth.length),
122 be32_to_cpu(eh->rc.imm_data)); 119 be32_to_cpu(eh->rc.imm_data));
123 break; 120 break;
124 /* reth */ 121 /* reth */
125 case OP(RC, RDMA_READ_REQUEST): 122 case OP(RC, RDMA_READ_REQUEST):
@@ -128,10 +125,10 @@ const char *parse_everbs_hdrs(
128 case OP(RC, RDMA_WRITE_ONLY): 125 case OP(RC, RDMA_WRITE_ONLY):
129 case OP(UC, RDMA_WRITE_ONLY): 126 case OP(UC, RDMA_WRITE_ONLY):
130 trace_seq_printf(p, RETH_PRN, 127 trace_seq_printf(p, RETH_PRN,
131 (unsigned long long)ib_u64_get( 128 (unsigned long long)ib_u64_get(
132 (__be32 *)&eh->rc.reth.vaddr), 129 (__be32 *)&eh->rc.reth.vaddr),
133 be32_to_cpu(eh->rc.reth.rkey), 130 be32_to_cpu(eh->rc.reth.rkey),
134 be32_to_cpu(eh->rc.reth.length)); 131 be32_to_cpu(eh->rc.reth.length));
135 break; 132 break;
136 case OP(RC, RDMA_READ_RESPONSE_FIRST): 133 case OP(RC, RDMA_READ_RESPONSE_FIRST):
137 case OP(RC, RDMA_READ_RESPONSE_LAST): 134 case OP(RC, RDMA_READ_RESPONSE_LAST):
@@ -154,19 +151,20 @@ const char *parse_everbs_hdrs(
154 case OP(RC, COMPARE_SWAP): 151 case OP(RC, COMPARE_SWAP):
155 case OP(RC, FETCH_ADD): 152 case OP(RC, FETCH_ADD):
156 trace_seq_printf(p, ATOMICETH_PRN, 153 trace_seq_printf(p, ATOMICETH_PRN,
157 (unsigned long long)ib_u64_get(eh->atomic_eth.vaddr), 154 (unsigned long long)ib_u64_get(
158 eh->atomic_eth.rkey, 155 eh->atomic_eth.vaddr),
159 (unsigned long long)ib_u64_get( 156 eh->atomic_eth.rkey,
160 (__be32 *)&eh->atomic_eth.swap_data), 157 (unsigned long long)ib_u64_get(
161 (unsigned long long) ib_u64_get( 158 (__be32 *)&eh->atomic_eth.swap_data),
159 (unsigned long long)ib_u64_get(
162 (__be32 *)&eh->atomic_eth.compare_data)); 160 (__be32 *)&eh->atomic_eth.compare_data));
163 break; 161 break;
164 /* deth */ 162 /* deth */
165 case OP(UD, SEND_ONLY): 163 case OP(UD, SEND_ONLY):
166 case OP(UD, SEND_ONLY_WITH_IMMEDIATE): 164 case OP(UD, SEND_ONLY_WITH_IMMEDIATE):
167 trace_seq_printf(p, DETH_PRN, 165 trace_seq_printf(p, DETH_PRN,
168 be32_to_cpu(eh->ud.deth[0]), 166 be32_to_cpu(eh->ud.deth[0]),
169 be32_to_cpu(eh->ud.deth[1]) & HFI1_QPN_MASK); 167 be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK);
170 break; 168 break;
171 } 169 }
172 trace_seq_putc(p, 0); 170 trace_seq_putc(p, 0);
@@ -187,12 +185,12 @@ const char *parse_sdma_flags(
187 trace_seq_printf(p, "%s", flags); 185 trace_seq_printf(p, "%s", flags);
188 if (desc0 & SDMA_DESC0_FIRST_DESC_FLAG) 186 if (desc0 & SDMA_DESC0_FIRST_DESC_FLAG)
189 trace_seq_printf(p, " amode:%u aidx:%u alen:%u", 187 trace_seq_printf(p, " amode:%u aidx:%u alen:%u",
190 (u8)((desc1 >> SDMA_DESC1_HEADER_MODE_SHIFT) 188 (u8)((desc1 >> SDMA_DESC1_HEADER_MODE_SHIFT) &
191 & SDMA_DESC1_HEADER_MODE_MASK), 189 SDMA_DESC1_HEADER_MODE_MASK),
192 (u8)((desc1 >> SDMA_DESC1_HEADER_INDEX_SHIFT) 190 (u8)((desc1 >> SDMA_DESC1_HEADER_INDEX_SHIFT) &
193 & SDMA_DESC1_HEADER_INDEX_MASK), 191 SDMA_DESC1_HEADER_INDEX_MASK),
194 (u8)((desc1 >> SDMA_DESC1_HEADER_DWS_SHIFT) 192 (u8)((desc1 >> SDMA_DESC1_HEADER_DWS_SHIFT) &
195 & SDMA_DESC1_HEADER_DWS_MASK)); 193 SDMA_DESC1_HEADER_DWS_MASK));
196 return ret; 194 return ret;
197} 195}
198 196
@@ -234,3 +232,4 @@ __hfi1_trace_fn(DC8051);
234__hfi1_trace_fn(FIRMWARE); 232__hfi1_trace_fn(FIRMWARE);
235__hfi1_trace_fn(RCVCTRL); 233__hfi1_trace_fn(RCVCTRL);
236__hfi1_trace_fn(TID); 234__hfi1_trace_fn(TID);
235__hfi1_trace_fn(MMU);
diff --git a/drivers/staging/rdma/hfi1/trace.h b/drivers/staging/rdma/hfi1/trace.h
index 86c12ebfd4f0..963dc948c38a 100644
--- a/drivers/staging/rdma/hfi1/trace.h
+++ b/drivers/staging/rdma/hfi1/trace.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -76,304 +73,295 @@ __print_symbolic(etype, \
76#define TRACE_SYSTEM hfi1_rx 73#define TRACE_SYSTEM hfi1_rx
77 74
78TRACE_EVENT(hfi1_rcvhdr, 75TRACE_EVENT(hfi1_rcvhdr,
79 TP_PROTO(struct hfi1_devdata *dd, 76 TP_PROTO(struct hfi1_devdata *dd,
80 u64 eflags, 77 u64 eflags,
81 u32 ctxt, 78 u32 ctxt,
82 u32 etype, 79 u32 etype,
83 u32 hlen, 80 u32 hlen,
84 u32 tlen, 81 u32 tlen,
85 u32 updegr, 82 u32 updegr,
86 u32 etail), 83 u32 etail
87 TP_ARGS(dd, ctxt, eflags, etype, hlen, tlen, updegr, etail), 84 ),
88 TP_STRUCT__entry( 85 TP_ARGS(dd, ctxt, eflags, etype, hlen, tlen, updegr, etail),
89 DD_DEV_ENTRY(dd) 86 TP_STRUCT__entry(DD_DEV_ENTRY(dd)
90 __field(u64, eflags) 87 __field(u64, eflags)
91 __field(u32, ctxt) 88 __field(u32, ctxt)
92 __field(u32, etype) 89 __field(u32, etype)
93 __field(u32, hlen) 90 __field(u32, hlen)
94 __field(u32, tlen) 91 __field(u32, tlen)
95 __field(u32, updegr) 92 __field(u32, updegr)
96 __field(u32, etail) 93 __field(u32, etail)
97 ), 94 ),
98 TP_fast_assign( 95 TP_fast_assign(DD_DEV_ASSIGN(dd);
99 DD_DEV_ASSIGN(dd); 96 __entry->eflags = eflags;
100 __entry->eflags = eflags; 97 __entry->ctxt = ctxt;
101 __entry->ctxt = ctxt; 98 __entry->etype = etype;
102 __entry->etype = etype; 99 __entry->hlen = hlen;
103 __entry->hlen = hlen; 100 __entry->tlen = tlen;
104 __entry->tlen = tlen; 101 __entry->updegr = updegr;
105 __entry->updegr = updegr; 102 __entry->etail = etail;
106 __entry->etail = etail; 103 ),
107 ), 104 TP_printk(
108 TP_printk( 105 "[%s] ctxt %d eflags 0x%llx etype %d,%s hlen %d tlen %d updegr %d etail %d",
109"[%s] ctxt %d eflags 0x%llx etype %d,%s hlen %d tlen %d updegr %d etail %d", 106 __get_str(dev),
110 __get_str(dev), 107 __entry->ctxt,
111 __entry->ctxt, 108 __entry->eflags,
112 __entry->eflags, 109 __entry->etype, show_packettype(__entry->etype),
113 __entry->etype, show_packettype(__entry->etype), 110 __entry->hlen,
114 __entry->hlen, 111 __entry->tlen,
115 __entry->tlen, 112 __entry->updegr,
116 __entry->updegr, 113 __entry->etail
117 __entry->etail 114 )
118 )
119); 115);
120 116
121TRACE_EVENT(hfi1_receive_interrupt, 117TRACE_EVENT(hfi1_receive_interrupt,
122 TP_PROTO(struct hfi1_devdata *dd, u32 ctxt), 118 TP_PROTO(struct hfi1_devdata *dd, u32 ctxt),
123 TP_ARGS(dd, ctxt), 119 TP_ARGS(dd, ctxt),
124 TP_STRUCT__entry( 120 TP_STRUCT__entry(DD_DEV_ENTRY(dd)
125 DD_DEV_ENTRY(dd) 121 __field(u32, ctxt)
126 __field(u32, ctxt) 122 __field(u8, slow_path)
127 __field(u8, slow_path) 123 __field(u8, dma_rtail)
128 __field(u8, dma_rtail) 124 ),
129 ), 125 TP_fast_assign(DD_DEV_ASSIGN(dd);
130 TP_fast_assign( 126 __entry->ctxt = ctxt;
131 DD_DEV_ASSIGN(dd); 127 if (dd->rcd[ctxt]->do_interrupt ==
132 __entry->ctxt = ctxt; 128 &handle_receive_interrupt) {
133 if (dd->rcd[ctxt]->do_interrupt == 129 __entry->slow_path = 1;
134 &handle_receive_interrupt) { 130 __entry->dma_rtail = 0xFF;
135 __entry->slow_path = 1; 131 } else if (dd->rcd[ctxt]->do_interrupt ==
136 __entry->dma_rtail = 0xFF; 132 &handle_receive_interrupt_dma_rtail){
137 } else if (dd->rcd[ctxt]->do_interrupt == 133 __entry->dma_rtail = 1;
138 &handle_receive_interrupt_dma_rtail){ 134 __entry->slow_path = 0;
139 __entry->dma_rtail = 1; 135 } else if (dd->rcd[ctxt]->do_interrupt ==
140 __entry->slow_path = 0; 136 &handle_receive_interrupt_nodma_rtail) {
141 } else if (dd->rcd[ctxt]->do_interrupt == 137 __entry->dma_rtail = 0;
142 &handle_receive_interrupt_nodma_rtail) { 138 __entry->slow_path = 0;
143 __entry->dma_rtail = 0; 139 }
144 __entry->slow_path = 0; 140 ),
145 } 141 TP_printk("[%s] ctxt %d SlowPath: %d DmaRtail: %d",
146 ), 142 __get_str(dev),
147 TP_printk( 143 __entry->ctxt,
148 "[%s] ctxt %d SlowPath: %d DmaRtail: %d", 144 __entry->slow_path,
149 __get_str(dev), 145 __entry->dma_rtail
150 __entry->ctxt, 146 )
151 __entry->slow_path,
152 __entry->dma_rtail
153 )
154); 147);
155 148
156const char *print_u64_array(struct trace_seq *, u64 *, int); 149TRACE_EVENT(hfi1_exp_tid_reg,
150 TP_PROTO(unsigned ctxt, u16 subctxt, u32 rarr,
151 u32 npages, unsigned long va, unsigned long pa,
152 dma_addr_t dma),
153 TP_ARGS(ctxt, subctxt, rarr, npages, va, pa, dma),
154 TP_STRUCT__entry(
155 __field(unsigned, ctxt)
156 __field(u16, subctxt)
157 __field(u32, rarr)
158 __field(u32, npages)
159 __field(unsigned long, va)
160 __field(unsigned long, pa)
161 __field(dma_addr_t, dma)
162 ),
163 TP_fast_assign(
164 __entry->ctxt = ctxt;
165 __entry->subctxt = subctxt;
166 __entry->rarr = rarr;
167 __entry->npages = npages;
168 __entry->va = va;
169 __entry->pa = pa;
170 __entry->dma = dma;
171 ),
172 TP_printk("[%u:%u] entry:%u, %u pages @ 0x%lx, va:0x%lx dma:0x%llx",
173 __entry->ctxt,
174 __entry->subctxt,
175 __entry->rarr,
176 __entry->npages,
177 __entry->pa,
178 __entry->va,
179 __entry->dma
180 )
181 );
157 182
158TRACE_EVENT(hfi1_exp_tid_map, 183TRACE_EVENT(hfi1_exp_tid_unreg,
159 TP_PROTO(unsigned ctxt, u16 subctxt, int dir, 184 TP_PROTO(unsigned ctxt, u16 subctxt, u32 rarr, u32 npages,
160 unsigned long *maps, u16 count), 185 unsigned long va, unsigned long pa, dma_addr_t dma),
161 TP_ARGS(ctxt, subctxt, dir, maps, count), 186 TP_ARGS(ctxt, subctxt, rarr, npages, va, pa, dma),
162 TP_STRUCT__entry( 187 TP_STRUCT__entry(
163 __field(unsigned, ctxt) 188 __field(unsigned, ctxt)
164 __field(u16, subctxt) 189 __field(u16, subctxt)
165 __field(int, dir) 190 __field(u32, rarr)
166 __field(u16, count) 191 __field(u32, npages)
167 __dynamic_array(unsigned long, maps, sizeof(*maps) * count) 192 __field(unsigned long, va)
193 __field(unsigned long, pa)
194 __field(dma_addr_t, dma)
168 ), 195 ),
169 TP_fast_assign( 196 TP_fast_assign(
170 __entry->ctxt = ctxt; 197 __entry->ctxt = ctxt;
171 __entry->subctxt = subctxt; 198 __entry->subctxt = subctxt;
172 __entry->dir = dir; 199 __entry->rarr = rarr;
173 __entry->count = count; 200 __entry->npages = npages;
174 memcpy(__get_dynamic_array(maps), maps, 201 __entry->va = va;
175 sizeof(*maps) * count); 202 __entry->pa = pa;
203 __entry->dma = dma;
176 ), 204 ),
177 TP_printk("[%3u:%02u] %s tidmaps %s", 205 TP_printk("[%u:%u] entry:%u, %u pages @ 0x%lx, va:0x%lx dma:0x%llx",
178 __entry->ctxt, 206 __entry->ctxt,
179 __entry->subctxt, 207 __entry->subctxt,
180 (__entry->dir ? ">" : "<"), 208 __entry->rarr,
181 print_u64_array(p, __get_dynamic_array(maps), 209 __entry->npages,
182 __entry->count) 210 __entry->pa,
211 __entry->va,
212 __entry->dma
183 ) 213 )
184 ); 214 );
185 215
186TRACE_EVENT(hfi1_exp_rcv_set, 216TRACE_EVENT(hfi1_exp_tid_inval,
187 TP_PROTO(unsigned ctxt, u16 subctxt, u32 tid, 217 TP_PROTO(unsigned ctxt, u16 subctxt, unsigned long va, u32 rarr,
188 unsigned long vaddr, u64 phys_addr, void *page), 218 u32 npages, dma_addr_t dma),
189 TP_ARGS(ctxt, subctxt, tid, vaddr, phys_addr, page), 219 TP_ARGS(ctxt, subctxt, va, rarr, npages, dma),
190 TP_STRUCT__entry( 220 TP_STRUCT__entry(
191 __field(unsigned, ctxt) 221 __field(unsigned, ctxt)
192 __field(u16, subctxt) 222 __field(u16, subctxt)
193 __field(u32, tid) 223 __field(unsigned long, va)
194 __field(unsigned long, vaddr) 224 __field(u32, rarr)
195 __field(u64, phys_addr) 225 __field(u32, npages)
196 __field(void *, page) 226 __field(dma_addr_t, dma)
197 ), 227 ),
198 TP_fast_assign( 228 TP_fast_assign(
199 __entry->ctxt = ctxt; 229 __entry->ctxt = ctxt;
200 __entry->subctxt = subctxt; 230 __entry->subctxt = subctxt;
201 __entry->tid = tid; 231 __entry->va = va;
202 __entry->vaddr = vaddr; 232 __entry->rarr = rarr;
203 __entry->phys_addr = phys_addr; 233 __entry->npages = npages;
204 __entry->page = page; 234 __entry->dma = dma;
205 ), 235 ),
206 TP_printk("[%u:%u] TID %u, vaddrs 0x%lx, physaddr 0x%llx, pgp %p", 236 TP_printk("[%u:%u] entry:%u, %u pages @ 0x%lx dma: 0x%llx",
207 __entry->ctxt, 237 __entry->ctxt,
208 __entry->subctxt, 238 __entry->subctxt,
209 __entry->tid, 239 __entry->rarr,
210 __entry->vaddr, 240 __entry->npages,
211 __entry->phys_addr, 241 __entry->va,
212 __entry->page 242 __entry->dma
213 ) 243 )
214 ); 244 );
215 245
216TRACE_EVENT(hfi1_exp_rcv_free, 246TRACE_EVENT(hfi1_mmu_invalidate,
217 TP_PROTO(unsigned ctxt, u16 subctxt, u32 tid, 247 TP_PROTO(unsigned ctxt, u16 subctxt, const char *type,
218 unsigned long phys, void *page), 248 unsigned long start, unsigned long end),
219 TP_ARGS(ctxt, subctxt, tid, phys, page), 249 TP_ARGS(ctxt, subctxt, type, start, end),
220 TP_STRUCT__entry( 250 TP_STRUCT__entry(
221 __field(unsigned, ctxt) 251 __field(unsigned, ctxt)
222 __field(u16, subctxt) 252 __field(u16, subctxt)
223 __field(u32, tid) 253 __string(type, type)
224 __field(unsigned long, phys) 254 __field(unsigned long, start)
225 __field(void *, page) 255 __field(unsigned long, end)
226 ), 256 ),
227 TP_fast_assign( 257 TP_fast_assign(
228 __entry->ctxt = ctxt; 258 __entry->ctxt = ctxt;
229 __entry->subctxt = subctxt; 259 __entry->subctxt = subctxt;
230 __entry->tid = tid; 260 __assign_str(type, type);
231 __entry->phys = phys; 261 __entry->start = start;
232 __entry->page = page; 262 __entry->end = end;
233 ), 263 ),
234 TP_printk("[%u:%u] freeing TID %u, 0x%lx, pgp %p", 264 TP_printk("[%3u:%02u] MMU Invalidate (%s) 0x%lx - 0x%lx",
235 __entry->ctxt, 265 __entry->ctxt,
236 __entry->subctxt, 266 __entry->subctxt,
237 __entry->tid, 267 __get_str(type),
238 __entry->phys, 268 __entry->start,
239 __entry->page 269 __entry->end
240 ) 270 )
241 ); 271 );
272
242#undef TRACE_SYSTEM 273#undef TRACE_SYSTEM
243#define TRACE_SYSTEM hfi1_tx 274#define TRACE_SYSTEM hfi1_tx
244 275
245TRACE_EVENT(hfi1_piofree, 276TRACE_EVENT(hfi1_piofree,
246 TP_PROTO(struct send_context *sc, int extra), 277 TP_PROTO(struct send_context *sc, int extra),
247 TP_ARGS(sc, extra), 278 TP_ARGS(sc, extra),
248 TP_STRUCT__entry( 279 TP_STRUCT__entry(DD_DEV_ENTRY(sc->dd)
249 DD_DEV_ENTRY(sc->dd) 280 __field(u32, sw_index)
250 __field(u32, sw_index) 281 __field(u32, hw_context)
251 __field(u32, hw_context) 282 __field(int, extra)
252 __field(int, extra) 283 ),
253 ), 284 TP_fast_assign(DD_DEV_ASSIGN(sc->dd);
254 TP_fast_assign( 285 __entry->sw_index = sc->sw_index;
255 DD_DEV_ASSIGN(sc->dd); 286 __entry->hw_context = sc->hw_context;
256 __entry->sw_index = sc->sw_index; 287 __entry->extra = extra;
257 __entry->hw_context = sc->hw_context; 288 ),
258 __entry->extra = extra; 289 TP_printk("[%s] ctxt %u(%u) extra %d",
259 ), 290 __get_str(dev),
260 TP_printk( 291 __entry->sw_index,
261 "[%s] ctxt %u(%u) extra %d", 292 __entry->hw_context,
262 __get_str(dev), 293 __entry->extra
263 __entry->sw_index, 294 )
264 __entry->hw_context,
265 __entry->extra
266 )
267); 295);
268 296
269TRACE_EVENT(hfi1_wantpiointr, 297TRACE_EVENT(hfi1_wantpiointr,
270 TP_PROTO(struct send_context *sc, u32 needint, u64 credit_ctrl), 298 TP_PROTO(struct send_context *sc, u32 needint, u64 credit_ctrl),
271 TP_ARGS(sc, needint, credit_ctrl), 299 TP_ARGS(sc, needint, credit_ctrl),
272 TP_STRUCT__entry( 300 TP_STRUCT__entry(DD_DEV_ENTRY(sc->dd)
273 DD_DEV_ENTRY(sc->dd) 301 __field(u32, sw_index)
274 __field(u32, sw_index) 302 __field(u32, hw_context)
275 __field(u32, hw_context) 303 __field(u32, needint)
276 __field(u32, needint) 304 __field(u64, credit_ctrl)
277 __field(u64, credit_ctrl) 305 ),
278 ), 306 TP_fast_assign(DD_DEV_ASSIGN(sc->dd);
279 TP_fast_assign( 307 __entry->sw_index = sc->sw_index;
280 DD_DEV_ASSIGN(sc->dd); 308 __entry->hw_context = sc->hw_context;
281 __entry->sw_index = sc->sw_index; 309 __entry->needint = needint;
282 __entry->hw_context = sc->hw_context; 310 __entry->credit_ctrl = credit_ctrl;
283 __entry->needint = needint; 311 ),
284 __entry->credit_ctrl = credit_ctrl; 312 TP_printk("[%s] ctxt %u(%u) on %d credit_ctrl 0x%llx",
285 ), 313 __get_str(dev),
286 TP_printk( 314 __entry->sw_index,
287 "[%s] ctxt %u(%u) on %d credit_ctrl 0x%llx", 315 __entry->hw_context,
288 __get_str(dev), 316 __entry->needint,
289 __entry->sw_index, 317 (unsigned long long)__entry->credit_ctrl
290 __entry->hw_context, 318 )
291 __entry->needint,
292 (unsigned long long)__entry->credit_ctrl
293 )
294); 319);
295 320
296DECLARE_EVENT_CLASS(hfi1_qpsleepwakeup_template, 321DECLARE_EVENT_CLASS(hfi1_qpsleepwakeup_template,
297 TP_PROTO(struct hfi1_qp *qp, u32 flags), 322 TP_PROTO(struct rvt_qp *qp, u32 flags),
298 TP_ARGS(qp, flags), 323 TP_ARGS(qp, flags),
299 TP_STRUCT__entry( 324 TP_STRUCT__entry(
300 DD_DEV_ENTRY(dd_from_ibdev(qp->ibqp.device)) 325 DD_DEV_ENTRY(dd_from_ibdev(qp->ibqp.device))
301 __field(u32, qpn) 326 __field(u32, qpn)
302 __field(u32, flags) 327 __field(u32, flags)
303 __field(u32, s_flags) 328 __field(u32, s_flags)
304 ), 329 ),
305 TP_fast_assign( 330 TP_fast_assign(
306 DD_DEV_ASSIGN(dd_from_ibdev(qp->ibqp.device)) 331 DD_DEV_ASSIGN(dd_from_ibdev(qp->ibqp.device))
307 __entry->flags = flags; 332 __entry->flags = flags;
308 __entry->qpn = qp->ibqp.qp_num; 333 __entry->qpn = qp->ibqp.qp_num;
309 __entry->s_flags = qp->s_flags; 334 __entry->s_flags = qp->s_flags;
310 ), 335 ),
311 TP_printk( 336 TP_printk(
312 "[%s] qpn 0x%x flags 0x%x s_flags 0x%x", 337 "[%s] qpn 0x%x flags 0x%x s_flags 0x%x",
313 __get_str(dev), 338 __get_str(dev),
314 __entry->qpn, 339 __entry->qpn,
315 __entry->flags, 340 __entry->flags,
316 __entry->s_flags 341 __entry->s_flags
317 ) 342 )
318); 343);
319 344
320DEFINE_EVENT(hfi1_qpsleepwakeup_template, hfi1_qpwakeup, 345DEFINE_EVENT(hfi1_qpsleepwakeup_template, hfi1_qpwakeup,
321 TP_PROTO(struct hfi1_qp *qp, u32 flags), 346 TP_PROTO(struct rvt_qp *qp, u32 flags),
322 TP_ARGS(qp, flags)); 347 TP_ARGS(qp, flags));
323 348
324DEFINE_EVENT(hfi1_qpsleepwakeup_template, hfi1_qpsleep, 349DEFINE_EVENT(hfi1_qpsleepwakeup_template, hfi1_qpsleep,
325 TP_PROTO(struct hfi1_qp *qp, u32 flags), 350 TP_PROTO(struct rvt_qp *qp, u32 flags),
326 TP_ARGS(qp, flags)); 351 TP_ARGS(qp, flags));
327 352
328#undef TRACE_SYSTEM 353#undef TRACE_SYSTEM
329#define TRACE_SYSTEM hfi1_qphash
330DECLARE_EVENT_CLASS(hfi1_qphash_template,
331 TP_PROTO(struct hfi1_qp *qp, u32 bucket),
332 TP_ARGS(qp, bucket),
333 TP_STRUCT__entry(
334 DD_DEV_ENTRY(dd_from_ibdev(qp->ibqp.device))
335 __field(u32, qpn)
336 __field(u32, bucket)
337 ),
338 TP_fast_assign(
339 DD_DEV_ASSIGN(dd_from_ibdev(qp->ibqp.device))
340 __entry->qpn = qp->ibqp.qp_num;
341 __entry->bucket = bucket;
342 ),
343 TP_printk(
344 "[%s] qpn 0x%x bucket %u",
345 __get_str(dev),
346 __entry->qpn,
347 __entry->bucket
348 )
349);
350
351DEFINE_EVENT(hfi1_qphash_template, hfi1_qpinsert,
352 TP_PROTO(struct hfi1_qp *qp, u32 bucket),
353 TP_ARGS(qp, bucket));
354
355DEFINE_EVENT(hfi1_qphash_template, hfi1_qpremove,
356 TP_PROTO(struct hfi1_qp *qp, u32 bucket),
357 TP_ARGS(qp, bucket));
358
359#undef TRACE_SYSTEM
360#define TRACE_SYSTEM hfi1_ibhdrs 354#define TRACE_SYSTEM hfi1_ibhdrs
361 355
362u8 ibhdr_exhdr_len(struct hfi1_ib_header *hdr); 356u8 ibhdr_exhdr_len(struct hfi1_ib_header *hdr);
363const char *parse_everbs_hdrs( 357const char *parse_everbs_hdrs(struct trace_seq *p, u8 opcode, void *ehdrs);
364 struct trace_seq *p,
365 u8 opcode,
366 void *ehdrs);
367 358
368#define __parse_ib_ehdrs(op, ehdrs) parse_everbs_hdrs(p, op, ehdrs) 359#define __parse_ib_ehdrs(op, ehdrs) parse_everbs_hdrs(p, op, ehdrs)
369 360
370const char *parse_sdma_flags( 361const char *parse_sdma_flags(struct trace_seq *p, u64 desc0, u64 desc1);
371 struct trace_seq *p,
372 u64 desc0, u64 desc1);
373 362
374#define __parse_sdma_flags(desc0, desc1) parse_sdma_flags(p, desc0, desc1) 363#define __parse_sdma_flags(desc0, desc1) parse_sdma_flags(p, desc0, desc1)
375 364
376
377#define lrh_name(lrh) { HFI1_##lrh, #lrh } 365#define lrh_name(lrh) { HFI1_##lrh, #lrh }
378#define show_lnh(lrh) \ 366#define show_lnh(lrh) \
379__print_symbolic(lrh, \ 367__print_symbolic(lrh, \
@@ -420,7 +408,6 @@ __print_symbolic(opcode, \
420 ib_opcode_name(UD_SEND_ONLY_WITH_IMMEDIATE), \ 408 ib_opcode_name(UD_SEND_ONLY_WITH_IMMEDIATE), \
421 ib_opcode_name(CNP)) 409 ib_opcode_name(CNP))
422 410
423
424#define LRH_PRN "vl %d lver %d sl %d lnh %d,%s dlid %.4x len %d slid %.4x" 411#define LRH_PRN "vl %d lver %d sl %d lnh %d,%s dlid %.4x len %d slid %.4x"
425#define BTH_PRN \ 412#define BTH_PRN \
426 "op 0x%.2x,%s se %d m %d pad %d tver %d pkey 0x%.4x " \ 413 "op 0x%.2x,%s se %d m %d pad %d tver %d pkey 0x%.4x " \
@@ -428,124 +415,130 @@ __print_symbolic(opcode, \
428#define EHDR_PRN "%s" 415#define EHDR_PRN "%s"
429 416
430DECLARE_EVENT_CLASS(hfi1_ibhdr_template, 417DECLARE_EVENT_CLASS(hfi1_ibhdr_template,
431 TP_PROTO(struct hfi1_devdata *dd, 418 TP_PROTO(struct hfi1_devdata *dd,
432 struct hfi1_ib_header *hdr), 419 struct hfi1_ib_header *hdr),
433 TP_ARGS(dd, hdr), 420 TP_ARGS(dd, hdr),
434 TP_STRUCT__entry( 421 TP_STRUCT__entry(
435 DD_DEV_ENTRY(dd) 422 DD_DEV_ENTRY(dd)
436 /* LRH */ 423 /* LRH */
437 __field(u8, vl) 424 __field(u8, vl)
438 __field(u8, lver) 425 __field(u8, lver)
439 __field(u8, sl) 426 __field(u8, sl)
440 __field(u8, lnh) 427 __field(u8, lnh)
441 __field(u16, dlid) 428 __field(u16, dlid)
442 __field(u16, len) 429 __field(u16, len)
443 __field(u16, slid) 430 __field(u16, slid)
444 /* BTH */ 431 /* BTH */
445 __field(u8, opcode) 432 __field(u8, opcode)
446 __field(u8, se) 433 __field(u8, se)
447 __field(u8, m) 434 __field(u8, m)
448 __field(u8, pad) 435 __field(u8, pad)
449 __field(u8, tver) 436 __field(u8, tver)
450 __field(u16, pkey) 437 __field(u16, pkey)
451 __field(u8, f) 438 __field(u8, f)
452 __field(u8, b) 439 __field(u8, b)
453 __field(u32, qpn) 440 __field(u32, qpn)
454 __field(u8, a) 441 __field(u8, a)
455 __field(u32, psn) 442 __field(u32, psn)
456 /* extended headers */ 443 /* extended headers */
457 __dynamic_array(u8, ehdrs, ibhdr_exhdr_len(hdr)) 444 __dynamic_array(u8, ehdrs, ibhdr_exhdr_len(hdr))
458 ), 445 ),
459 TP_fast_assign( 446 TP_fast_assign(
460 struct hfi1_other_headers *ohdr; 447 struct hfi1_other_headers *ohdr;
461 448
462 DD_DEV_ASSIGN(dd); 449 DD_DEV_ASSIGN(dd);
463 /* LRH */ 450 /* LRH */
464 __entry->vl = 451 __entry->vl =
465 (u8)(be16_to_cpu(hdr->lrh[0]) >> 12); 452 (u8)(be16_to_cpu(hdr->lrh[0]) >> 12);
466 __entry->lver = 453 __entry->lver =
467 (u8)(be16_to_cpu(hdr->lrh[0]) >> 8) & 0xf; 454 (u8)(be16_to_cpu(hdr->lrh[0]) >> 8) & 0xf;
468 __entry->sl = 455 __entry->sl =
469 (u8)(be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf; 456 (u8)(be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf;
470 __entry->lnh = 457 __entry->lnh =
471 (u8)(be16_to_cpu(hdr->lrh[0]) & 3); 458 (u8)(be16_to_cpu(hdr->lrh[0]) & 3);
472 __entry->dlid = 459 __entry->dlid =
473 be16_to_cpu(hdr->lrh[1]); 460 be16_to_cpu(hdr->lrh[1]);
474 /* allow for larger len */ 461 /* allow for larger len */
475 __entry->len = 462 __entry->len =
476 be16_to_cpu(hdr->lrh[2]); 463 be16_to_cpu(hdr->lrh[2]);
477 __entry->slid = 464 __entry->slid =
478 be16_to_cpu(hdr->lrh[3]); 465 be16_to_cpu(hdr->lrh[3]);
479 /* BTH */ 466 /* BTH */
480 if (__entry->lnh == HFI1_LRH_BTH) 467 if (__entry->lnh == HFI1_LRH_BTH)
481 ohdr = &hdr->u.oth; 468 ohdr = &hdr->u.oth;
482 else 469 else
483 ohdr = &hdr->u.l.oth; 470 ohdr = &hdr->u.l.oth;
484 __entry->opcode = 471 __entry->opcode =
485 (be32_to_cpu(ohdr->bth[0]) >> 24) & 0xff; 472 (be32_to_cpu(ohdr->bth[0]) >> 24) & 0xff;
486 __entry->se = 473 __entry->se =
487 (be32_to_cpu(ohdr->bth[0]) >> 23) & 1; 474 (be32_to_cpu(ohdr->bth[0]) >> 23) & 1;
488 __entry->m = 475 __entry->m =
489 (be32_to_cpu(ohdr->bth[0]) >> 22) & 1; 476 (be32_to_cpu(ohdr->bth[0]) >> 22) & 1;
490 __entry->pad = 477 __entry->pad =
491 (be32_to_cpu(ohdr->bth[0]) >> 20) & 3; 478 (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
492 __entry->tver = 479 __entry->tver =
493 (be32_to_cpu(ohdr->bth[0]) >> 16) & 0xf; 480 (be32_to_cpu(ohdr->bth[0]) >> 16) & 0xf;
494 __entry->pkey = 481 __entry->pkey =
495 be32_to_cpu(ohdr->bth[0]) & 0xffff; 482 be32_to_cpu(ohdr->bth[0]) & 0xffff;
496 __entry->f = 483 __entry->f =
497 (be32_to_cpu(ohdr->bth[1]) >> HFI1_FECN_SHIFT) 484 (be32_to_cpu(ohdr->bth[1]) >> HFI1_FECN_SHIFT) &
498 & HFI1_FECN_MASK; 485 HFI1_FECN_MASK;
499 __entry->b = 486 __entry->b =
500 (be32_to_cpu(ohdr->bth[1]) >> HFI1_BECN_SHIFT) 487 (be32_to_cpu(ohdr->bth[1]) >> HFI1_BECN_SHIFT) &
501 & HFI1_BECN_MASK; 488 HFI1_BECN_MASK;
502 __entry->qpn = 489 __entry->qpn =
503 be32_to_cpu(ohdr->bth[1]) & HFI1_QPN_MASK; 490 be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
504 __entry->a = 491 __entry->a =
505 (be32_to_cpu(ohdr->bth[2]) >> 31) & 1; 492 (be32_to_cpu(ohdr->bth[2]) >> 31) & 1;
506 /* allow for larger PSN */ 493 /* allow for larger PSN */
507 __entry->psn = 494 __entry->psn =
508 be32_to_cpu(ohdr->bth[2]) & 0x7fffffff; 495 be32_to_cpu(ohdr->bth[2]) & 0x7fffffff;
509 /* extended headers */ 496 /* extended headers */
510 memcpy( 497 memcpy(__get_dynamic_array(ehdrs), &ohdr->u,
511 __get_dynamic_array(ehdrs), 498 ibhdr_exhdr_len(hdr));
512 &ohdr->u, 499 ),
513 ibhdr_exhdr_len(hdr)); 500 TP_printk("[%s] " LRH_PRN " " BTH_PRN " " EHDR_PRN,
514 ), 501 __get_str(dev),
515 TP_printk("[%s] " LRH_PRN " " BTH_PRN " " EHDR_PRN, 502 /* LRH */
516 __get_str(dev), 503 __entry->vl,
517 /* LRH */ 504 __entry->lver,
518 __entry->vl, 505 __entry->sl,
519 __entry->lver, 506 __entry->lnh, show_lnh(__entry->lnh),
520 __entry->sl, 507 __entry->dlid,
521 __entry->lnh, show_lnh(__entry->lnh), 508 __entry->len,
522 __entry->dlid, 509 __entry->slid,
523 __entry->len, 510 /* BTH */
524 __entry->slid, 511 __entry->opcode, show_ib_opcode(__entry->opcode),
525 /* BTH */ 512 __entry->se,
526 __entry->opcode, show_ib_opcode(__entry->opcode), 513 __entry->m,
527 __entry->se, 514 __entry->pad,
528 __entry->m, 515 __entry->tver,
529 __entry->pad, 516 __entry->pkey,
530 __entry->tver, 517 __entry->f,
531 __entry->pkey, 518 __entry->b,
532 __entry->f, 519 __entry->qpn,
533 __entry->b, 520 __entry->a,
534 __entry->qpn, 521 __entry->psn,
535 __entry->a, 522 /* extended headers */
536 __entry->psn, 523 __parse_ib_ehdrs(
537 /* extended headers */ 524 __entry->opcode,
538 __parse_ib_ehdrs( 525 (void *)__get_dynamic_array(ehdrs))
539 __entry->opcode, 526 )
540 (void *)__get_dynamic_array(ehdrs))
541 )
542); 527);
543 528
544DEFINE_EVENT(hfi1_ibhdr_template, input_ibhdr, 529DEFINE_EVENT(hfi1_ibhdr_template, input_ibhdr,
545 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr), 530 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
546 TP_ARGS(dd, hdr)); 531 TP_ARGS(dd, hdr));
547 532
548DEFINE_EVENT(hfi1_ibhdr_template, output_ibhdr, 533DEFINE_EVENT(hfi1_ibhdr_template, pio_output_ibhdr,
534 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
535 TP_ARGS(dd, hdr));
536
537DEFINE_EVENT(hfi1_ibhdr_template, ack_output_ibhdr,
538 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
539 TP_ARGS(dd, hdr));
540
541DEFINE_EVENT(hfi1_ibhdr_template, sdma_output_ibhdr,
549 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr), 542 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
550 TP_ARGS(dd, hdr)); 543 TP_ARGS(dd, hdr));
551 544
@@ -556,15 +549,14 @@ DEFINE_EVENT(hfi1_ibhdr_template, output_ibhdr,
556#undef TRACE_SYSTEM 549#undef TRACE_SYSTEM
557#define TRACE_SYSTEM hfi1_snoop 550#define TRACE_SYSTEM hfi1_snoop
558 551
559
560TRACE_EVENT(snoop_capture, 552TRACE_EVENT(snoop_capture,
561 TP_PROTO(struct hfi1_devdata *dd, 553 TP_PROTO(struct hfi1_devdata *dd,
562 int hdr_len, 554 int hdr_len,
563 struct hfi1_ib_header *hdr, 555 struct hfi1_ib_header *hdr,
564 int data_len, 556 int data_len,
565 void *data), 557 void *data),
566 TP_ARGS(dd, hdr_len, hdr, data_len, data), 558 TP_ARGS(dd, hdr_len, hdr, data_len, data),
567 TP_STRUCT__entry( 559 TP_STRUCT__entry(
568 DD_DEV_ENTRY(dd) 560 DD_DEV_ENTRY(dd)
569 __field(u16, slid) 561 __field(u16, slid)
570 __field(u16, dlid) 562 __field(u16, dlid)
@@ -577,8 +569,8 @@ TRACE_EVENT(snoop_capture,
577 __field(u8, lnh) 569 __field(u8, lnh)
578 __dynamic_array(u8, raw_hdr, hdr_len) 570 __dynamic_array(u8, raw_hdr, hdr_len)
579 __dynamic_array(u8, raw_pkt, data_len) 571 __dynamic_array(u8, raw_pkt, data_len)
580 ), 572 ),
581 TP_fast_assign( 573 TP_fast_assign(
582 struct hfi1_other_headers *ohdr; 574 struct hfi1_other_headers *ohdr;
583 575
584 __entry->lnh = (u8)(be16_to_cpu(hdr->lrh[0]) & 3); 576 __entry->lnh = (u8)(be16_to_cpu(hdr->lrh[0]) & 3);
@@ -589,7 +581,7 @@ TRACE_EVENT(snoop_capture,
589 DD_DEV_ASSIGN(dd); 581 DD_DEV_ASSIGN(dd);
590 __entry->slid = be16_to_cpu(hdr->lrh[3]); 582 __entry->slid = be16_to_cpu(hdr->lrh[3]);
591 __entry->dlid = be16_to_cpu(hdr->lrh[1]); 583 __entry->dlid = be16_to_cpu(hdr->lrh[1]);
592 __entry->qpn = be32_to_cpu(ohdr->bth[1]) & HFI1_QPN_MASK; 584 __entry->qpn = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
593 __entry->opcode = (be32_to_cpu(ohdr->bth[0]) >> 24) & 0xff; 585 __entry->opcode = (be32_to_cpu(ohdr->bth[0]) >> 24) & 0xff;
594 __entry->sl = (u8)(be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf; 586 __entry->sl = (u8)(be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf;
595 __entry->pkey = be32_to_cpu(ohdr->bth[0]) & 0xffff; 587 __entry->pkey = be32_to_cpu(ohdr->bth[0]) & 0xffff;
@@ -597,8 +589,9 @@ TRACE_EVENT(snoop_capture,
597 __entry->data_len = data_len; 589 __entry->data_len = data_len;
598 memcpy(__get_dynamic_array(raw_hdr), hdr, hdr_len); 590 memcpy(__get_dynamic_array(raw_hdr), hdr, hdr_len);
599 memcpy(__get_dynamic_array(raw_pkt), data, data_len); 591 memcpy(__get_dynamic_array(raw_pkt), data, data_len);
600 ), 592 ),
601 TP_printk("[%s] " SNOOP_PRN, 593 TP_printk(
594 "[%s] " SNOOP_PRN,
602 __get_str(dev), 595 __get_str(dev),
603 __entry->slid, 596 __entry->slid,
604 __entry->dlid, 597 __entry->dlid,
@@ -609,7 +602,7 @@ TRACE_EVENT(snoop_capture,
609 __entry->pkey, 602 __entry->pkey,
610 __entry->hdr_len, 603 __entry->hdr_len,
611 __entry->data_len 604 __entry->data_len
612 ) 605 )
613); 606);
614 607
615#undef TRACE_SYSTEM 608#undef TRACE_SYSTEM
@@ -621,41 +614,39 @@ TRACE_EVENT(snoop_capture,
621TRACE_EVENT(hfi1_uctxtdata, 614TRACE_EVENT(hfi1_uctxtdata,
622 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ctxtdata *uctxt), 615 TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ctxtdata *uctxt),
623 TP_ARGS(dd, uctxt), 616 TP_ARGS(dd, uctxt),
624 TP_STRUCT__entry( 617 TP_STRUCT__entry(DD_DEV_ENTRY(dd)
625 DD_DEV_ENTRY(dd) 618 __field(unsigned, ctxt)
626 __field(unsigned, ctxt) 619 __field(u32, credits)
627 __field(u32, credits) 620 __field(u64, hw_free)
628 __field(u64, hw_free) 621 __field(u64, piobase)
629 __field(u64, piobase) 622 __field(u16, rcvhdrq_cnt)
630 __field(u16, rcvhdrq_cnt) 623 __field(u64, rcvhdrq_phys)
631 __field(u64, rcvhdrq_phys) 624 __field(u32, eager_cnt)
632 __field(u32, eager_cnt) 625 __field(u64, rcvegr_phys)
633 __field(u64, rcvegr_phys) 626 ),
634 ), 627 TP_fast_assign(DD_DEV_ASSIGN(dd);
635 TP_fast_assign( 628 __entry->ctxt = uctxt->ctxt;
636 DD_DEV_ASSIGN(dd); 629 __entry->credits = uctxt->sc->credits;
637 __entry->ctxt = uctxt->ctxt; 630 __entry->hw_free = (u64)uctxt->sc->hw_free;
638 __entry->credits = uctxt->sc->credits; 631 __entry->piobase = (u64)uctxt->sc->base_addr;
639 __entry->hw_free = (u64)uctxt->sc->hw_free; 632 __entry->rcvhdrq_cnt = uctxt->rcvhdrq_cnt;
640 __entry->piobase = (u64)uctxt->sc->base_addr; 633 __entry->rcvhdrq_phys = uctxt->rcvhdrq_phys;
641 __entry->rcvhdrq_cnt = uctxt->rcvhdrq_cnt; 634 __entry->eager_cnt = uctxt->egrbufs.alloced;
642 __entry->rcvhdrq_phys = uctxt->rcvhdrq_phys; 635 __entry->rcvegr_phys =
643 __entry->eager_cnt = uctxt->egrbufs.alloced; 636 uctxt->egrbufs.rcvtids[0].phys;
644 __entry->rcvegr_phys = uctxt->egrbufs.rcvtids[0].phys; 637 ),
645 ), 638 TP_printk("[%s] ctxt %u " UCTXT_FMT,
646 TP_printk( 639 __get_str(dev),
647 "[%s] ctxt %u " UCTXT_FMT, 640 __entry->ctxt,
648 __get_str(dev), 641 __entry->credits,
649 __entry->ctxt, 642 __entry->hw_free,
650 __entry->credits, 643 __entry->piobase,
651 __entry->hw_free, 644 __entry->rcvhdrq_cnt,
652 __entry->piobase, 645 __entry->rcvhdrq_phys,
653 __entry->rcvhdrq_cnt, 646 __entry->eager_cnt,
654 __entry->rcvhdrq_phys, 647 __entry->rcvegr_phys
655 __entry->eager_cnt, 648 )
656 __entry->rcvegr_phys 649);
657 )
658 );
659 650
660#define CINFO_FMT \ 651#define CINFO_FMT \
661 "egrtids:%u, egr_size:%u, hdrq_cnt:%u, hdrq_size:%u, sdma_ring_size:%u" 652 "egrtids:%u, egr_size:%u, hdrq_cnt:%u, hdrq_size:%u, sdma_ring_size:%u"
@@ -663,38 +654,35 @@ TRACE_EVENT(hfi1_ctxt_info,
663 TP_PROTO(struct hfi1_devdata *dd, unsigned ctxt, unsigned subctxt, 654 TP_PROTO(struct hfi1_devdata *dd, unsigned ctxt, unsigned subctxt,
664 struct hfi1_ctxt_info cinfo), 655 struct hfi1_ctxt_info cinfo),
665 TP_ARGS(dd, ctxt, subctxt, cinfo), 656 TP_ARGS(dd, ctxt, subctxt, cinfo),
666 TP_STRUCT__entry( 657 TP_STRUCT__entry(DD_DEV_ENTRY(dd)
667 DD_DEV_ENTRY(dd) 658 __field(unsigned, ctxt)
668 __field(unsigned, ctxt) 659 __field(unsigned, subctxt)
669 __field(unsigned, subctxt) 660 __field(u16, egrtids)
670 __field(u16, egrtids) 661 __field(u16, rcvhdrq_cnt)
671 __field(u16, rcvhdrq_cnt) 662 __field(u16, rcvhdrq_size)
672 __field(u16, rcvhdrq_size) 663 __field(u16, sdma_ring_size)
673 __field(u16, sdma_ring_size) 664 __field(u32, rcvegr_size)
674 __field(u32, rcvegr_size) 665 ),
675 ), 666 TP_fast_assign(DD_DEV_ASSIGN(dd);
676 TP_fast_assign( 667 __entry->ctxt = ctxt;
677 DD_DEV_ASSIGN(dd); 668 __entry->subctxt = subctxt;
678 __entry->ctxt = ctxt; 669 __entry->egrtids = cinfo.egrtids;
679 __entry->subctxt = subctxt; 670 __entry->rcvhdrq_cnt = cinfo.rcvhdrq_cnt;
680 __entry->egrtids = cinfo.egrtids; 671 __entry->rcvhdrq_size = cinfo.rcvhdrq_entsize;
681 __entry->rcvhdrq_cnt = cinfo.rcvhdrq_cnt; 672 __entry->sdma_ring_size = cinfo.sdma_ring_size;
682 __entry->rcvhdrq_size = cinfo.rcvhdrq_entsize; 673 __entry->rcvegr_size = cinfo.rcvegr_size;
683 __entry->sdma_ring_size = cinfo.sdma_ring_size; 674 ),
684 __entry->rcvegr_size = cinfo.rcvegr_size; 675 TP_printk("[%s] ctxt %u:%u " CINFO_FMT,
685 ), 676 __get_str(dev),
686 TP_printk( 677 __entry->ctxt,
687 "[%s] ctxt %u:%u " CINFO_FMT, 678 __entry->subctxt,
688 __get_str(dev), 679 __entry->egrtids,
689 __entry->ctxt, 680 __entry->rcvegr_size,
690 __entry->subctxt, 681 __entry->rcvhdrq_cnt,
691 __entry->egrtids, 682 __entry->rcvhdrq_size,
692 __entry->rcvegr_size, 683 __entry->sdma_ring_size
693 __entry->rcvhdrq_cnt, 684 )
694 __entry->rcvhdrq_size, 685);
695 __entry->sdma_ring_size
696 )
697 );
698 686
699#undef TRACE_SYSTEM 687#undef TRACE_SYSTEM
700#define TRACE_SYSTEM hfi1_sma 688#define TRACE_SYSTEM hfi1_sma
@@ -708,52 +696,48 @@ TRACE_EVENT(hfi1_ctxt_info,
708 ) 696 )
709 697
710DECLARE_EVENT_CLASS(hfi1_bct_template, 698DECLARE_EVENT_CLASS(hfi1_bct_template,
711 TP_PROTO(struct hfi1_devdata *dd, struct buffer_control *bc), 699 TP_PROTO(struct hfi1_devdata *dd,
712 TP_ARGS(dd, bc), 700 struct buffer_control *bc),
713 TP_STRUCT__entry( 701 TP_ARGS(dd, bc),
714 DD_DEV_ENTRY(dd) 702 TP_STRUCT__entry(DD_DEV_ENTRY(dd)
715 __dynamic_array(u8, bct, sizeof(*bc)) 703 __dynamic_array(u8, bct, sizeof(*bc))
716 ), 704 ),
717 TP_fast_assign( 705 TP_fast_assign(DD_DEV_ASSIGN(dd);
718 DD_DEV_ASSIGN(dd); 706 memcpy(__get_dynamic_array(bct), bc,
719 memcpy( 707 sizeof(*bc));
720 __get_dynamic_array(bct), 708 ),
721 bc, 709 TP_printk(BCT_FORMAT,
722 sizeof(*bc)); 710 BCT(overall_shared_limit),
723 ), 711
724 TP_printk(BCT_FORMAT, 712 BCT(vl[0].dedicated),
725 BCT(overall_shared_limit), 713 BCT(vl[0].shared),
726 714
727 BCT(vl[0].dedicated), 715 BCT(vl[1].dedicated),
728 BCT(vl[0].shared), 716 BCT(vl[1].shared),
729 717
730 BCT(vl[1].dedicated), 718 BCT(vl[2].dedicated),
731 BCT(vl[1].shared), 719 BCT(vl[2].shared),
732 720
733 BCT(vl[2].dedicated), 721 BCT(vl[3].dedicated),
734 BCT(vl[2].shared), 722 BCT(vl[3].shared),
735 723
736 BCT(vl[3].dedicated), 724 BCT(vl[4].dedicated),
737 BCT(vl[3].shared), 725 BCT(vl[4].shared),
738 726
739 BCT(vl[4].dedicated), 727 BCT(vl[5].dedicated),
740 BCT(vl[4].shared), 728 BCT(vl[5].shared),
741 729
742 BCT(vl[5].dedicated), 730 BCT(vl[6].dedicated),
743 BCT(vl[5].shared), 731 BCT(vl[6].shared),
744 732
745 BCT(vl[6].dedicated), 733 BCT(vl[7].dedicated),
746 BCT(vl[6].shared), 734 BCT(vl[7].shared),
747 735
748 BCT(vl[7].dedicated), 736 BCT(vl[15].dedicated),
749 BCT(vl[7].shared), 737 BCT(vl[15].shared)
750 738 )
751 BCT(vl[15].dedicated),
752 BCT(vl[15].shared)
753 )
754); 739);
755 740
756
757DEFINE_EVENT(hfi1_bct_template, bct_set, 741DEFINE_EVENT(hfi1_bct_template, bct_set,
758 TP_PROTO(struct hfi1_devdata *dd, struct buffer_control *bc), 742 TP_PROTO(struct hfi1_devdata *dd, struct buffer_control *bc),
759 TP_ARGS(dd, bc)); 743 TP_ARGS(dd, bc));
@@ -766,252 +750,209 @@ DEFINE_EVENT(hfi1_bct_template, bct_get,
766#define TRACE_SYSTEM hfi1_sdma 750#define TRACE_SYSTEM hfi1_sdma
767 751
768TRACE_EVENT(hfi1_sdma_descriptor, 752TRACE_EVENT(hfi1_sdma_descriptor,
769 TP_PROTO( 753 TP_PROTO(struct sdma_engine *sde,
770 struct sdma_engine *sde, 754 u64 desc0,
771 u64 desc0, 755 u64 desc1,
772 u64 desc1, 756 u16 e,
773 u16 e, 757 void *descp),
774 void *descp),
775 TP_ARGS(sde, desc0, desc1, e, descp), 758 TP_ARGS(sde, desc0, desc1, e, descp),
776 TP_STRUCT__entry( 759 TP_STRUCT__entry(DD_DEV_ENTRY(sde->dd)
777 DD_DEV_ENTRY(sde->dd) 760 __field(void *, descp)
778 __field(void *, descp) 761 __field(u64, desc0)
779 __field(u64, desc0) 762 __field(u64, desc1)
780 __field(u64, desc1) 763 __field(u16, e)
781 __field(u16, e) 764 __field(u8, idx)
782 __field(u8, idx) 765 ),
783 ), 766 TP_fast_assign(DD_DEV_ASSIGN(sde->dd);
784 TP_fast_assign( 767 __entry->desc0 = desc0;
785 DD_DEV_ASSIGN(sde->dd); 768 __entry->desc1 = desc1;
786 __entry->desc0 = desc0; 769 __entry->idx = sde->this_idx;
787 __entry->desc1 = desc1; 770 __entry->descp = descp;
788 __entry->idx = sde->this_idx; 771 __entry->e = e;
789 __entry->descp = descp; 772 ),
790 __entry->e = e;
791 ),
792 TP_printk( 773 TP_printk(
793 "[%s] SDE(%u) flags:%s addr:0x%016llx gen:%u len:%u d0:%016llx d1:%016llx to %p,%u", 774 "[%s] SDE(%u) flags:%s addr:0x%016llx gen:%u len:%u d0:%016llx d1:%016llx to %p,%u",
794 __get_str(dev), 775 __get_str(dev),
795 __entry->idx, 776 __entry->idx,
796 __parse_sdma_flags(__entry->desc0, __entry->desc1), 777 __parse_sdma_flags(__entry->desc0, __entry->desc1),
797 (__entry->desc0 >> SDMA_DESC0_PHY_ADDR_SHIFT) 778 (__entry->desc0 >> SDMA_DESC0_PHY_ADDR_SHIFT) &
798 & SDMA_DESC0_PHY_ADDR_MASK, 779 SDMA_DESC0_PHY_ADDR_MASK,
799 (u8)((__entry->desc1 >> SDMA_DESC1_GENERATION_SHIFT) 780 (u8)((__entry->desc1 >> SDMA_DESC1_GENERATION_SHIFT) &
800 & SDMA_DESC1_GENERATION_MASK), 781 SDMA_DESC1_GENERATION_MASK),
801 (u16)((__entry->desc0 >> SDMA_DESC0_BYTE_COUNT_SHIFT) 782 (u16)((__entry->desc0 >> SDMA_DESC0_BYTE_COUNT_SHIFT) &
802 & SDMA_DESC0_BYTE_COUNT_MASK), 783 SDMA_DESC0_BYTE_COUNT_MASK),
803 __entry->desc0, 784 __entry->desc0,
804 __entry->desc1, 785 __entry->desc1,
805 __entry->descp, 786 __entry->descp,
806 __entry->e 787 __entry->e
807 ) 788 )
808); 789);
809 790
810TRACE_EVENT(hfi1_sdma_engine_select, 791TRACE_EVENT(hfi1_sdma_engine_select,
811 TP_PROTO(struct hfi1_devdata *dd, u32 sel, u8 vl, u8 idx), 792 TP_PROTO(struct hfi1_devdata *dd, u32 sel, u8 vl, u8 idx),
812 TP_ARGS(dd, sel, vl, idx), 793 TP_ARGS(dd, sel, vl, idx),
813 TP_STRUCT__entry( 794 TP_STRUCT__entry(DD_DEV_ENTRY(dd)
814 DD_DEV_ENTRY(dd) 795 __field(u32, sel)
815 __field(u32, sel) 796 __field(u8, vl)
816 __field(u8, vl) 797 __field(u8, idx)
817 __field(u8, idx) 798 ),
818 ), 799 TP_fast_assign(DD_DEV_ASSIGN(dd);
819 TP_fast_assign( 800 __entry->sel = sel;
820 DD_DEV_ASSIGN(dd); 801 __entry->vl = vl;
821 __entry->sel = sel; 802 __entry->idx = idx;
822 __entry->vl = vl; 803 ),
823 __entry->idx = idx; 804 TP_printk("[%s] selecting SDE %u sel 0x%x vl %u",
824 ), 805 __get_str(dev),
825 TP_printk( 806 __entry->idx,
826 "[%s] selecting SDE %u sel 0x%x vl %u", 807 __entry->sel,
827 __get_str(dev), 808 __entry->vl
828 __entry->idx, 809 )
829 __entry->sel,
830 __entry->vl
831 )
832); 810);
833 811
834DECLARE_EVENT_CLASS(hfi1_sdma_engine_class, 812DECLARE_EVENT_CLASS(hfi1_sdma_engine_class,
835 TP_PROTO( 813 TP_PROTO(struct sdma_engine *sde, u64 status),
836 struct sdma_engine *sde, 814 TP_ARGS(sde, status),
837 u64 status 815 TP_STRUCT__entry(DD_DEV_ENTRY(sde->dd)
838 ), 816 __field(u64, status)
839 TP_ARGS(sde, status), 817 __field(u8, idx)
840 TP_STRUCT__entry( 818 ),
841 DD_DEV_ENTRY(sde->dd) 819 TP_fast_assign(DD_DEV_ASSIGN(sde->dd);
842 __field(u64, status) 820 __entry->status = status;
843 __field(u8, idx) 821 __entry->idx = sde->this_idx;
844 ), 822 ),
845 TP_fast_assign( 823 TP_printk("[%s] SDE(%u) status %llx",
846 DD_DEV_ASSIGN(sde->dd); 824 __get_str(dev),
847 __entry->status = status; 825 __entry->idx,
848 __entry->idx = sde->this_idx; 826 (unsigned long long)__entry->status
849 ), 827 )
850 TP_printk(
851 "[%s] SDE(%u) status %llx",
852 __get_str(dev),
853 __entry->idx,
854 (unsigned long long)__entry->status
855 )
856); 828);
857 829
858DEFINE_EVENT(hfi1_sdma_engine_class, hfi1_sdma_engine_interrupt, 830DEFINE_EVENT(hfi1_sdma_engine_class, hfi1_sdma_engine_interrupt,
859 TP_PROTO( 831 TP_PROTO(struct sdma_engine *sde, u64 status),
860 struct sdma_engine *sde, 832 TP_ARGS(sde, status)
861 u64 status
862 ),
863 TP_ARGS(sde, status)
864); 833);
865 834
866DEFINE_EVENT(hfi1_sdma_engine_class, hfi1_sdma_engine_progress, 835DEFINE_EVENT(hfi1_sdma_engine_class, hfi1_sdma_engine_progress,
867 TP_PROTO( 836 TP_PROTO(struct sdma_engine *sde, u64 status),
868 struct sdma_engine *sde, 837 TP_ARGS(sde, status)
869 u64 status
870 ),
871 TP_ARGS(sde, status)
872); 838);
873 839
874DECLARE_EVENT_CLASS(hfi1_sdma_ahg_ad, 840DECLARE_EVENT_CLASS(hfi1_sdma_ahg_ad,
875 TP_PROTO( 841 TP_PROTO(struct sdma_engine *sde, int aidx),
876 struct sdma_engine *sde, 842 TP_ARGS(sde, aidx),
877 int aidx 843 TP_STRUCT__entry(DD_DEV_ENTRY(sde->dd)
878 ), 844 __field(int, aidx)
879 TP_ARGS(sde, aidx), 845 __field(u8, idx)
880 TP_STRUCT__entry( 846 ),
881 DD_DEV_ENTRY(sde->dd) 847 TP_fast_assign(DD_DEV_ASSIGN(sde->dd);
882 __field(int, aidx) 848 __entry->idx = sde->this_idx;
883 __field(u8, idx) 849 __entry->aidx = aidx;
884 ), 850 ),
885 TP_fast_assign( 851 TP_printk("[%s] SDE(%u) aidx %d",
886 DD_DEV_ASSIGN(sde->dd); 852 __get_str(dev),
887 __entry->idx = sde->this_idx; 853 __entry->idx,
888 __entry->aidx = aidx; 854 __entry->aidx
889 ), 855 )
890 TP_printk(
891 "[%s] SDE(%u) aidx %d",
892 __get_str(dev),
893 __entry->idx,
894 __entry->aidx
895 )
896); 856);
897 857
898DEFINE_EVENT(hfi1_sdma_ahg_ad, hfi1_ahg_allocate, 858DEFINE_EVENT(hfi1_sdma_ahg_ad, hfi1_ahg_allocate,
899 TP_PROTO( 859 TP_PROTO(struct sdma_engine *sde, int aidx),
900 struct sdma_engine *sde,
901 int aidx
902 ),
903 TP_ARGS(sde, aidx)); 860 TP_ARGS(sde, aidx));
904 861
905DEFINE_EVENT(hfi1_sdma_ahg_ad, hfi1_ahg_deallocate, 862DEFINE_EVENT(hfi1_sdma_ahg_ad, hfi1_ahg_deallocate,
906 TP_PROTO( 863 TP_PROTO(struct sdma_engine *sde, int aidx),
907 struct sdma_engine *sde,
908 int aidx
909 ),
910 TP_ARGS(sde, aidx)); 864 TP_ARGS(sde, aidx));
911 865
912#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER 866#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
913TRACE_EVENT(hfi1_sdma_progress, 867TRACE_EVENT(hfi1_sdma_progress,
914 TP_PROTO( 868 TP_PROTO(struct sdma_engine *sde,
915 struct sdma_engine *sde, 869 u16 hwhead,
916 u16 hwhead, 870 u16 swhead,
917 u16 swhead, 871 struct sdma_txreq *txp
918 struct sdma_txreq *txp 872 ),
919 ), 873 TP_ARGS(sde, hwhead, swhead, txp),
920 TP_ARGS(sde, hwhead, swhead, txp), 874 TP_STRUCT__entry(DD_DEV_ENTRY(sde->dd)
921 TP_STRUCT__entry( 875 __field(u64, sn)
922 DD_DEV_ENTRY(sde->dd) 876 __field(u16, hwhead)
923 __field(u64, sn) 877 __field(u16, swhead)
924 __field(u16, hwhead) 878 __field(u16, txnext)
925 __field(u16, swhead) 879 __field(u16, tx_tail)
926 __field(u16, txnext) 880 __field(u16, tx_head)
927 __field(u16, tx_tail) 881 __field(u8, idx)
928 __field(u16, tx_head) 882 ),
929 __field(u8, idx) 883 TP_fast_assign(DD_DEV_ASSIGN(sde->dd);
930 ), 884 __entry->hwhead = hwhead;
931 TP_fast_assign( 885 __entry->swhead = swhead;
932 DD_DEV_ASSIGN(sde->dd); 886 __entry->tx_tail = sde->tx_tail;
933 __entry->hwhead = hwhead; 887 __entry->tx_head = sde->tx_head;
934 __entry->swhead = swhead; 888 __entry->txnext = txp ? txp->next_descq_idx : ~0;
935 __entry->tx_tail = sde->tx_tail; 889 __entry->idx = sde->this_idx;
936 __entry->tx_head = sde->tx_head; 890 __entry->sn = txp ? txp->sn : ~0;
937 __entry->txnext = txp ? txp->next_descq_idx : ~0; 891 ),
938 __entry->idx = sde->this_idx; 892 TP_printk(
939 __entry->sn = txp ? txp->sn : ~0; 893 "[%s] SDE(%u) sn %llu hwhead %u swhead %u next_descq_idx %u tx_head %u tx_tail %u",
940 ), 894 __get_str(dev),
941 TP_printk( 895 __entry->idx,
942 "[%s] SDE(%u) sn %llu hwhead %u swhead %u next_descq_idx %u tx_head %u tx_tail %u", 896 __entry->sn,
943 __get_str(dev), 897 __entry->hwhead,
944 __entry->idx, 898 __entry->swhead,
945 __entry->sn, 899 __entry->txnext,
946 __entry->hwhead, 900 __entry->tx_head,
947 __entry->swhead, 901 __entry->tx_tail
948 __entry->txnext, 902 )
949 __entry->tx_head,
950 __entry->tx_tail
951 )
952); 903);
953#else 904#else
954TRACE_EVENT(hfi1_sdma_progress, 905TRACE_EVENT(hfi1_sdma_progress,
955 TP_PROTO( 906 TP_PROTO(struct sdma_engine *sde,
956 struct sdma_engine *sde, 907 u16 hwhead, u16 swhead,
957 u16 hwhead, 908 struct sdma_txreq *txp
958 u16 swhead,
959 struct sdma_txreq *txp
960 ), 909 ),
961 TP_ARGS(sde, hwhead, swhead, txp), 910 TP_ARGS(sde, hwhead, swhead, txp),
962 TP_STRUCT__entry( 911 TP_STRUCT__entry(DD_DEV_ENTRY(sde->dd)
963 DD_DEV_ENTRY(sde->dd) 912 __field(u16, hwhead)
964 __field(u16, hwhead) 913 __field(u16, swhead)
965 __field(u16, swhead) 914 __field(u16, txnext)
966 __field(u16, txnext) 915 __field(u16, tx_tail)
967 __field(u16, tx_tail) 916 __field(u16, tx_head)
968 __field(u16, tx_head) 917 __field(u8, idx)
969 __field(u8, idx) 918 ),
970 ), 919 TP_fast_assign(DD_DEV_ASSIGN(sde->dd);
971 TP_fast_assign( 920 __entry->hwhead = hwhead;
972 DD_DEV_ASSIGN(sde->dd); 921 __entry->swhead = swhead;
973 __entry->hwhead = hwhead; 922 __entry->tx_tail = sde->tx_tail;
974 __entry->swhead = swhead; 923 __entry->tx_head = sde->tx_head;
975 __entry->tx_tail = sde->tx_tail; 924 __entry->txnext = txp ? txp->next_descq_idx : ~0;
976 __entry->tx_head = sde->tx_head; 925 __entry->idx = sde->this_idx;
977 __entry->txnext = txp ? txp->next_descq_idx : ~0; 926 ),
978 __entry->idx = sde->this_idx;
979 ),
980 TP_printk( 927 TP_printk(
981 "[%s] SDE(%u) hwhead %u swhead %u next_descq_idx %u tx_head %u tx_tail %u", 928 "[%s] SDE(%u) hwhead %u swhead %u next_descq_idx %u tx_head %u tx_tail %u",
982 __get_str(dev), 929 __get_str(dev),
983 __entry->idx, 930 __entry->idx,
984 __entry->hwhead, 931 __entry->hwhead,
985 __entry->swhead, 932 __entry->swhead,
986 __entry->txnext, 933 __entry->txnext,
987 __entry->tx_head, 934 __entry->tx_head,
988 __entry->tx_tail 935 __entry->tx_tail
989 ) 936 )
990); 937);
991#endif 938#endif
992 939
993DECLARE_EVENT_CLASS(hfi1_sdma_sn, 940DECLARE_EVENT_CLASS(hfi1_sdma_sn,
994 TP_PROTO( 941 TP_PROTO(struct sdma_engine *sde, u64 sn),
995 struct sdma_engine *sde, 942 TP_ARGS(sde, sn),
996 u64 sn 943 TP_STRUCT__entry(DD_DEV_ENTRY(sde->dd)
997 ), 944 __field(u64, sn)
998 TP_ARGS(sde, sn), 945 __field(u8, idx)
999 TP_STRUCT__entry( 946 ),
1000 DD_DEV_ENTRY(sde->dd) 947 TP_fast_assign(DD_DEV_ASSIGN(sde->dd);
1001 __field(u64, sn) 948 __entry->sn = sn;
1002 __field(u8, idx) 949 __entry->idx = sde->this_idx;
1003 ), 950 ),
1004 TP_fast_assign( 951 TP_printk("[%s] SDE(%u) sn %llu",
1005 DD_DEV_ASSIGN(sde->dd); 952 __get_str(dev),
1006 __entry->sn = sn; 953 __entry->idx,
1007 __entry->idx = sde->this_idx; 954 __entry->sn
1008 ), 955 )
1009 TP_printk(
1010 "[%s] SDE(%u) sn %llu",
1011 __get_str(dev),
1012 __entry->idx,
1013 __entry->sn
1014 )
1015); 956);
1016 957
1017DEFINE_EVENT(hfi1_sdma_sn, hfi1_sdma_out_sn, 958DEFINE_EVENT(hfi1_sdma_sn, hfi1_sdma_out_sn,
@@ -1023,10 +964,7 @@ DEFINE_EVENT(hfi1_sdma_sn, hfi1_sdma_out_sn,
1023); 964);
1024 965
1025DEFINE_EVENT(hfi1_sdma_sn, hfi1_sdma_in_sn, 966DEFINE_EVENT(hfi1_sdma_sn, hfi1_sdma_in_sn,
1026 TP_PROTO( 967 TP_PROTO(struct sdma_engine *sde, u64 sn),
1027 struct sdma_engine *sde,
1028 u64 sn
1029 ),
1030 TP_ARGS(sde, sn) 968 TP_ARGS(sde, sn)
1031); 969);
1032 970
@@ -1227,88 +1165,85 @@ TRACE_EVENT(hfi1_sdma_user_header_ahg,
1227 ); 1165 );
1228 1166
1229TRACE_EVENT(hfi1_sdma_state, 1167TRACE_EVENT(hfi1_sdma_state,
1230 TP_PROTO( 1168 TP_PROTO(struct sdma_engine *sde,
1231 struct sdma_engine *sde, 1169 const char *cstate,
1232 const char *cstate, 1170 const char *nstate
1233 const char *nstate 1171 ),
1234 ), 1172 TP_ARGS(sde, cstate, nstate),
1235 TP_ARGS(sde, cstate, nstate), 1173 TP_STRUCT__entry(DD_DEV_ENTRY(sde->dd)
1236 TP_STRUCT__entry( 1174 __string(curstate, cstate)
1237 DD_DEV_ENTRY(sde->dd) 1175 __string(newstate, nstate)
1238 __string(curstate, cstate) 1176 ),
1239 __string(newstate, nstate) 1177 TP_fast_assign(DD_DEV_ASSIGN(sde->dd);
1240 ), 1178 __assign_str(curstate, cstate);
1241 TP_fast_assign( 1179 __assign_str(newstate, nstate);
1242 DD_DEV_ASSIGN(sde->dd); 1180 ),
1243 __assign_str(curstate, cstate);
1244 __assign_str(newstate, nstate);
1245 ),
1246 TP_printk("[%s] current state %s new state %s", 1181 TP_printk("[%s] current state %s new state %s",
1247 __get_str(dev), 1182 __get_str(dev),
1248 __get_str(curstate), 1183 __get_str(curstate),
1249 __get_str(newstate) 1184 __get_str(newstate)
1250 ) 1185 )
1251); 1186);
1252 1187
1253#undef TRACE_SYSTEM 1188#undef TRACE_SYSTEM
1254#define TRACE_SYSTEM hfi1_rc 1189#define TRACE_SYSTEM hfi1_rc
1255 1190
1256DECLARE_EVENT_CLASS(hfi1_rc_template, 1191DECLARE_EVENT_CLASS(hfi1_rc_template,
1257 TP_PROTO(struct hfi1_qp *qp, u32 psn), 1192 TP_PROTO(struct rvt_qp *qp, u32 psn),
1258 TP_ARGS(qp, psn), 1193 TP_ARGS(qp, psn),
1259 TP_STRUCT__entry( 1194 TP_STRUCT__entry(
1260 DD_DEV_ENTRY(dd_from_ibdev(qp->ibqp.device)) 1195 DD_DEV_ENTRY(dd_from_ibdev(qp->ibqp.device))
1261 __field(u32, qpn) 1196 __field(u32, qpn)
1262 __field(u32, s_flags) 1197 __field(u32, s_flags)
1263 __field(u32, psn) 1198 __field(u32, psn)
1264 __field(u32, s_psn) 1199 __field(u32, s_psn)
1265 __field(u32, s_next_psn) 1200 __field(u32, s_next_psn)
1266 __field(u32, s_sending_psn) 1201 __field(u32, s_sending_psn)
1267 __field(u32, s_sending_hpsn) 1202 __field(u32, s_sending_hpsn)
1268 __field(u32, r_psn) 1203 __field(u32, r_psn)
1269 ), 1204 ),
1270 TP_fast_assign( 1205 TP_fast_assign(
1271 DD_DEV_ASSIGN(dd_from_ibdev(qp->ibqp.device)) 1206 DD_DEV_ASSIGN(dd_from_ibdev(qp->ibqp.device))
1272 __entry->qpn = qp->ibqp.qp_num; 1207 __entry->qpn = qp->ibqp.qp_num;
1273 __entry->s_flags = qp->s_flags; 1208 __entry->s_flags = qp->s_flags;
1274 __entry->psn = psn; 1209 __entry->psn = psn;
1275 __entry->s_psn = qp->s_psn; 1210 __entry->s_psn = qp->s_psn;
1276 __entry->s_next_psn = qp->s_next_psn; 1211 __entry->s_next_psn = qp->s_next_psn;
1277 __entry->s_sending_psn = qp->s_sending_psn; 1212 __entry->s_sending_psn = qp->s_sending_psn;
1278 __entry->s_sending_hpsn = qp->s_sending_hpsn; 1213 __entry->s_sending_hpsn = qp->s_sending_hpsn;
1279 __entry->r_psn = qp->r_psn; 1214 __entry->r_psn = qp->r_psn;
1280 ), 1215 ),
1281 TP_printk( 1216 TP_printk(
1282 "[%s] qpn 0x%x s_flags 0x%x psn 0x%x s_psn 0x%x s_next_psn 0x%x s_sending_psn 0x%x sending_hpsn 0x%x r_psn 0x%x", 1217 "[%s] qpn 0x%x s_flags 0x%x psn 0x%x s_psn 0x%x s_next_psn 0x%x s_sending_psn 0x%x sending_hpsn 0x%x r_psn 0x%x",
1283 __get_str(dev), 1218 __get_str(dev),
1284 __entry->qpn, 1219 __entry->qpn,
1285 __entry->s_flags, 1220 __entry->s_flags,
1286 __entry->psn, 1221 __entry->psn,
1287 __entry->s_psn, 1222 __entry->s_psn,
1288 __entry->s_next_psn, 1223 __entry->s_next_psn,
1289 __entry->s_sending_psn, 1224 __entry->s_sending_psn,
1290 __entry->s_sending_hpsn, 1225 __entry->s_sending_hpsn,
1291 __entry->r_psn 1226 __entry->r_psn
1292 ) 1227 )
1293); 1228);
1294 1229
1295DEFINE_EVENT(hfi1_rc_template, hfi1_rc_sendcomplete, 1230DEFINE_EVENT(hfi1_rc_template, hfi1_rc_sendcomplete,
1296 TP_PROTO(struct hfi1_qp *qp, u32 psn), 1231 TP_PROTO(struct rvt_qp *qp, u32 psn),
1297 TP_ARGS(qp, psn) 1232 TP_ARGS(qp, psn)
1298); 1233);
1299 1234
1300DEFINE_EVENT(hfi1_rc_template, hfi1_rc_ack, 1235DEFINE_EVENT(hfi1_rc_template, hfi1_rc_ack,
1301 TP_PROTO(struct hfi1_qp *qp, u32 psn), 1236 TP_PROTO(struct rvt_qp *qp, u32 psn),
1302 TP_ARGS(qp, psn) 1237 TP_ARGS(qp, psn)
1303); 1238);
1304 1239
1305DEFINE_EVENT(hfi1_rc_template, hfi1_rc_timeout, 1240DEFINE_EVENT(hfi1_rc_template, hfi1_rc_timeout,
1306 TP_PROTO(struct hfi1_qp *qp, u32 psn), 1241 TP_PROTO(struct rvt_qp *qp, u32 psn),
1307 TP_ARGS(qp, psn) 1242 TP_ARGS(qp, psn)
1308); 1243);
1309 1244
1310DEFINE_EVENT(hfi1_rc_template, hfi1_rc_rcv_error, 1245DEFINE_EVENT(hfi1_rc_template, hfi1_rc_rcv_error,
1311 TP_PROTO(struct hfi1_qp *qp, u32 psn), 1246 TP_PROTO(struct rvt_qp *qp, u32 psn),
1312 TP_ARGS(qp, psn) 1247 TP_ARGS(qp, psn)
1313); 1248);
1314 1249
@@ -1316,21 +1251,20 @@ DEFINE_EVENT(hfi1_rc_template, hfi1_rc_rcv_error,
1316#define TRACE_SYSTEM hfi1_misc 1251#define TRACE_SYSTEM hfi1_misc
1317 1252
1318TRACE_EVENT(hfi1_interrupt, 1253TRACE_EVENT(hfi1_interrupt,
1319 TP_PROTO(struct hfi1_devdata *dd, const struct is_table *is_entry, 1254 TP_PROTO(struct hfi1_devdata *dd, const struct is_table *is_entry,
1320 int src), 1255 int src),
1321 TP_ARGS(dd, is_entry, src), 1256 TP_ARGS(dd, is_entry, src),
1322 TP_STRUCT__entry( 1257 TP_STRUCT__entry(DD_DEV_ENTRY(dd)
1323 DD_DEV_ENTRY(dd) 1258 __array(char, buf, 64)
1324 __array(char, buf, 64) 1259 __field(int, src)
1325 __field(int, src) 1260 ),
1326 ), 1261 TP_fast_assign(DD_DEV_ASSIGN(dd)
1327 TP_fast_assign( 1262 is_entry->is_name(__entry->buf, 64,
1328 DD_DEV_ASSIGN(dd) 1263 src - is_entry->start);
1329 is_entry->is_name(__entry->buf, 64, src - is_entry->start); 1264 __entry->src = src;
1330 __entry->src = src; 1265 ),
1331 ), 1266 TP_printk("[%s] source: %s [%d]", __get_str(dev), __entry->buf,
1332 TP_printk("[%s] source: %s [%d]", __get_str(dev), __entry->buf, 1267 __entry->src)
1333 __entry->src)
1334); 1268);
1335 1269
1336/* 1270/*
@@ -1345,21 +1279,21 @@ TRACE_EVENT(hfi1_interrupt,
1345#define MAX_MSG_LEN 512 1279#define MAX_MSG_LEN 512
1346 1280
1347DECLARE_EVENT_CLASS(hfi1_trace_template, 1281DECLARE_EVENT_CLASS(hfi1_trace_template,
1348 TP_PROTO(const char *function, struct va_format *vaf), 1282 TP_PROTO(const char *function, struct va_format *vaf),
1349 TP_ARGS(function, vaf), 1283 TP_ARGS(function, vaf),
1350 TP_STRUCT__entry( 1284 TP_STRUCT__entry(__string(function, function)
1351 __string(function, function) 1285 __dynamic_array(char, msg, MAX_MSG_LEN)
1352 __dynamic_array(char, msg, MAX_MSG_LEN) 1286 ),
1353 ), 1287 TP_fast_assign(__assign_str(function, function);
1354 TP_fast_assign( 1288 WARN_ON_ONCE(vsnprintf
1355 __assign_str(function, function); 1289 (__get_dynamic_array(msg),
1356 WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg), 1290 MAX_MSG_LEN, vaf->fmt,
1357 MAX_MSG_LEN, vaf->fmt, 1291 *vaf->va) >=
1358 *vaf->va) >= MAX_MSG_LEN); 1292 MAX_MSG_LEN);
1359 ), 1293 ),
1360 TP_printk("(%s) %s", 1294 TP_printk("(%s) %s",
1361 __get_str(function), 1295 __get_str(function),
1362 __get_str(msg)) 1296 __get_str(msg))
1363); 1297);
1364 1298
1365/* 1299/*
@@ -1406,6 +1340,7 @@ __hfi1_trace_def(DC8051);
1406__hfi1_trace_def(FIRMWARE); 1340__hfi1_trace_def(FIRMWARE);
1407__hfi1_trace_def(RCVCTRL); 1341__hfi1_trace_def(RCVCTRL);
1408__hfi1_trace_def(TID); 1342__hfi1_trace_def(TID);
1343__hfi1_trace_def(MMU);
1409 1344
1410#define hfi1_cdbg(which, fmt, ...) \ 1345#define hfi1_cdbg(which, fmt, ...) \
1411 __hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__) 1346 __hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
diff --git a/drivers/staging/rdma/hfi1/twsi.c b/drivers/staging/rdma/hfi1/twsi.c
index ea54fd2700ad..e82e52a63d35 100644
--- a/drivers/staging/rdma/hfi1/twsi.c
+++ b/drivers/staging/rdma/hfi1/twsi.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -119,9 +116,9 @@ static void scl_out(struct hfi1_devdata *dd, u32 target, u8 bit)
119 * Allow for slow slaves by simple 116 * Allow for slow slaves by simple
120 * delay for falling edge, sampling on rise. 117 * delay for falling edge, sampling on rise.
121 */ 118 */
122 if (!bit) 119 if (!bit) {
123 udelay(2); 120 udelay(2);
124 else { 121 } else {
125 int rise_usec; 122 int rise_usec;
126 123
127 for (rise_usec = SCL_WAIT_USEC; rise_usec > 0; rise_usec -= 2) { 124 for (rise_usec = SCL_WAIT_USEC; rise_usec > 0; rise_usec -= 2) {
@@ -131,11 +128,24 @@ static void scl_out(struct hfi1_devdata *dd, u32 target, u8 bit)
131 } 128 }
132 if (rise_usec <= 0) 129 if (rise_usec <= 0)
133 dd_dev_err(dd, "SCL interface stuck low > %d uSec\n", 130 dd_dev_err(dd, "SCL interface stuck low > %d uSec\n",
134 SCL_WAIT_USEC); 131 SCL_WAIT_USEC);
135 } 132 }
136 i2c_wait_for_writes(dd, target); 133 i2c_wait_for_writes(dd, target);
137} 134}
138 135
136static u8 scl_in(struct hfi1_devdata *dd, u32 target, int wait)
137{
138 u32 read_val, mask;
139
140 mask = QSFP_HFI0_I2CCLK;
141 /* SCL is meant to be bare-drain, so never set "OUT", just DIR */
142 hfi1_gpio_mod(dd, target, 0, 0, mask);
143 read_val = hfi1_gpio_mod(dd, target, 0, 0, 0);
144 if (wait)
145 i2c_wait_for_writes(dd, target);
146 return (read_val & mask) >> GPIO_SCL_NUM;
147}
148
139static void sda_out(struct hfi1_devdata *dd, u32 target, u8 bit) 149static void sda_out(struct hfi1_devdata *dd, u32 target, u8 bit)
140{ 150{
141 u32 mask; 151 u32 mask;
@@ -274,13 +284,12 @@ static void stop_cmd(struct hfi1_devdata *dd, u32 target)
274/** 284/**
275 * hfi1_twsi_reset - reset I2C communication 285 * hfi1_twsi_reset - reset I2C communication
276 * @dd: the hfi1_ib device 286 * @dd: the hfi1_ib device
287 * returns 0 if ok, -EIO on error
277 */ 288 */
278
279int hfi1_twsi_reset(struct hfi1_devdata *dd, u32 target) 289int hfi1_twsi_reset(struct hfi1_devdata *dd, u32 target)
280{ 290{
281 int clock_cycles_left = 9; 291 int clock_cycles_left = 9;
282 int was_high = 0; 292 u32 mask;
283 u32 pins, mask;
284 293
285 /* Both SCL and SDA should be high. If not, there 294 /* Both SCL and SDA should be high. If not, there
286 * is something wrong. 295 * is something wrong.
@@ -294,43 +303,23 @@ int hfi1_twsi_reset(struct hfi1_devdata *dd, u32 target)
294 */ 303 */
295 hfi1_gpio_mod(dd, target, 0, 0, mask); 304 hfi1_gpio_mod(dd, target, 0, 0, mask);
296 305
297 /* 306 /* Check if SCL is low, if it is low then we have a slave device
298 * Clock nine times to get all listeners into a sane state. 307 * misbehaving and there is not much we can do.
299 * If SDA does not go high at any point, we are wedged. 308 */
300 * One vendor recommends then issuing START followed by STOP. 309 if (!scl_in(dd, target, 0))
301 * we cannot use our "normal" functions to do that, because 310 return -EIO;
302 * if SCL drops between them, another vendor's part will 311
303 * wedge, dropping SDA and keeping it low forever, at the end of 312 /* Check if SDA is low, if it is low then we have to clock SDA
304 * the next transaction (even if it was not the device addressed). 313 * up to 9 times for the device to release the bus
305 * So our START and STOP take place with SCL held high.
306 */ 314 */
307 while (clock_cycles_left--) { 315 while (clock_cycles_left--) {
316 if (sda_in(dd, target, 0))
317 return 0;
308 scl_out(dd, target, 0); 318 scl_out(dd, target, 0);
309 scl_out(dd, target, 1); 319 scl_out(dd, target, 1);
310 /* Note if SDA is high, but keep clocking to sync slave */
311 was_high |= sda_in(dd, target, 0);
312 }
313
314 if (was_high) {
315 /*
316 * We saw a high, which we hope means the slave is sync'd.
317 * Issue START, STOP, pause for T_BUF.
318 */
319
320 pins = hfi1_gpio_mod(dd, target, 0, 0, 0);
321 if ((pins & mask) != mask)
322 dd_dev_err(dd, "GPIO pins not at rest: %d\n",
323 pins & mask);
324 /* Drop SDA to issue START */
325 udelay(1); /* Guarantee .6 uSec setup */
326 sda_out(dd, target, 0);
327 udelay(1); /* Guarantee .6 uSec hold */
328 /* At this point, SCL is high, SDA low. Raise SDA for STOP */
329 sda_out(dd, target, 1);
330 udelay(TWSI_BUF_WAIT_USEC);
331 } 320 }
332 321
333 return !was_high; 322 return -EIO;
334} 323}
335 324
336#define HFI1_TWSI_START 0x100 325#define HFI1_TWSI_START 0x100
@@ -365,17 +354,25 @@ static int twsi_wr(struct hfi1_devdata *dd, u32 target, int data, int flags)
365 * HFI1_TWSI_NO_DEV and does the correct operation for the legacy part, 354 * HFI1_TWSI_NO_DEV and does the correct operation for the legacy part,
366 * which responded to all TWSI device codes, interpreting them as 355 * which responded to all TWSI device codes, interpreting them as
367 * address within device. On all other devices found on board handled by 356 * address within device. On all other devices found on board handled by
368 * this driver, the device is followed by a one-byte "address" which selects 357 * this driver, the device is followed by a N-byte "address" which selects
369 * the "register" or "offset" within the device from which data should 358 * the "register" or "offset" within the device from which data should
370 * be read. 359 * be read.
371 */ 360 */
372int hfi1_twsi_blk_rd(struct hfi1_devdata *dd, u32 target, int dev, int addr, 361int hfi1_twsi_blk_rd(struct hfi1_devdata *dd, u32 target, int dev, int addr,
373 void *buffer, int len) 362 void *buffer, int len)
374{ 363{
375 int ret;
376 u8 *bp = buffer; 364 u8 *bp = buffer;
365 int ret = 1;
366 int i;
367 int offset_size;
368
369 /* obtain the offset size, strip it from the device address */
370 offset_size = (dev >> 8) & 0xff;
371 dev &= 0xff;
377 372
378 ret = 1; 373 /* allow at most a 2 byte offset */
374 if (offset_size > 2)
375 goto bail;
379 376
380 if (dev == HFI1_TWSI_NO_DEV) { 377 if (dev == HFI1_TWSI_NO_DEV) {
381 /* legacy not-really-I2C */ 378 /* legacy not-really-I2C */
@@ -383,34 +380,29 @@ int hfi1_twsi_blk_rd(struct hfi1_devdata *dd, u32 target, int dev, int addr,
383 ret = twsi_wr(dd, target, addr, HFI1_TWSI_START); 380 ret = twsi_wr(dd, target, addr, HFI1_TWSI_START);
384 } else { 381 } else {
385 /* Actual I2C */ 382 /* Actual I2C */
386 ret = twsi_wr(dd, target, dev | WRITE_CMD, HFI1_TWSI_START); 383 if (offset_size) {
387 if (ret) { 384 ret = twsi_wr(dd, target,
388 stop_cmd(dd, target); 385 dev | WRITE_CMD, HFI1_TWSI_START);
389 ret = 1; 386 if (ret) {
390 goto bail; 387 stop_cmd(dd, target);
391 } 388 goto bail;
392 /* 389 }
393 * SFF spec claims we do _not_ stop after the addr
394 * but simply issue a start with the "read" dev-addr.
395 * Since we are implicitly waiting for ACK here,
396 * we need t_buf (nominally 20uSec) before that start,
397 * and cannot rely on the delay built in to the STOP
398 */
399 ret = twsi_wr(dd, target, addr, 0);
400 udelay(TWSI_BUF_WAIT_USEC);
401 390
402 if (ret) { 391 for (i = 0; i < offset_size; i++) {
403 dd_dev_err(dd, 392 ret = twsi_wr(dd, target,
404 "Failed to write interface read addr %02X\n", 393 (addr >> (i * 8)) & 0xff, 0);
405 addr); 394 udelay(TWSI_BUF_WAIT_USEC);
406 ret = 1; 395 if (ret) {
407 goto bail; 396 dd_dev_err(dd, "Failed to write byte %d of offset 0x%04X\n",
397 i, addr);
398 goto bail;
399 }
400 }
408 } 401 }
409 ret = twsi_wr(dd, target, dev | READ_CMD, HFI1_TWSI_START); 402 ret = twsi_wr(dd, target, dev | READ_CMD, HFI1_TWSI_START);
410 } 403 }
411 if (ret) { 404 if (ret) {
412 stop_cmd(dd, target); 405 stop_cmd(dd, target);
413 ret = 1;
414 goto bail; 406 goto bail;
415 } 407 }
416 408
@@ -442,76 +434,55 @@ bail:
442 * HFI1_TWSI_NO_DEV and does the correct operation for the legacy part, 434 * HFI1_TWSI_NO_DEV and does the correct operation for the legacy part,
443 * which responded to all TWSI device codes, interpreting them as 435 * which responded to all TWSI device codes, interpreting them as
444 * address within device. On all other devices found on board handled by 436 * address within device. On all other devices found on board handled by
445 * this driver, the device is followed by a one-byte "address" which selects 437 * this driver, the device is followed by a N-byte "address" which selects
446 * the "register" or "offset" within the device to which data should 438 * the "register" or "offset" within the device to which data should
447 * be written. 439 * be written.
448 */ 440 */
449int hfi1_twsi_blk_wr(struct hfi1_devdata *dd, u32 target, int dev, int addr, 441int hfi1_twsi_blk_wr(struct hfi1_devdata *dd, u32 target, int dev, int addr,
450 const void *buffer, int len) 442 const void *buffer, int len)
451{ 443{
452 int sub_len;
453 const u8 *bp = buffer; 444 const u8 *bp = buffer;
454 int max_wait_time, i;
455 int ret = 1; 445 int ret = 1;
446 int i;
447 int offset_size;
456 448
457 while (len > 0) { 449 /* obtain the offset size, strip it from the device address */
458 if (dev == HFI1_TWSI_NO_DEV) { 450 offset_size = (dev >> 8) & 0xff;
459 if (twsi_wr(dd, target, (addr << 1) | WRITE_CMD, 451 dev &= 0xff;
460 HFI1_TWSI_START)) {
461 goto failed_write;
462 }
463 } else {
464 /* Real I2C */
465 if (twsi_wr(dd, target,
466 dev | WRITE_CMD, HFI1_TWSI_START))
467 goto failed_write;
468 ret = twsi_wr(dd, target, addr, 0);
469 if (ret) {
470 dd_dev_err(dd,
471 "Failed to write interface write addr %02X\n",
472 addr);
473 goto failed_write;
474 }
475 }
476
477 sub_len = min(len, 4);
478 addr += sub_len;
479 len -= sub_len;
480 452
481 for (i = 0; i < sub_len; i++) 453 /* allow at most a 2 byte offset */
482 if (twsi_wr(dd, target, *bp++, 0)) 454 if (offset_size > 2)
483 goto failed_write; 455 goto bail;
484 456
485 stop_cmd(dd, target); 457 if (dev == HFI1_TWSI_NO_DEV) {
458 if (twsi_wr(dd, target, (addr << 1) | WRITE_CMD,
459 HFI1_TWSI_START)) {
460 goto failed_write;
461 }
462 } else {
463 /* Real I2C */
464 if (twsi_wr(dd, target, dev | WRITE_CMD, HFI1_TWSI_START))
465 goto failed_write;
466 }
486 467
487 /* 468 for (i = 0; i < offset_size; i++) {
488 * Wait for write complete by waiting for a successful 469 ret = twsi_wr(dd, target, (addr >> (i * 8)) & 0xff, 0);
489 * read (the chip replies with a zero after the write 470 udelay(TWSI_BUF_WAIT_USEC);
490 * cmd completes, and before it writes to the eeprom. 471 if (ret) {
491 * The startcmd for the read will fail the ack until 472 dd_dev_err(dd, "Failed to write byte %d of offset 0x%04X\n",
492 * the writes have completed. We do this inline to avoid 473 i, addr);
493 * the debug prints that are in the real read routine 474 goto bail;
494 * if the startcmd fails.
495 * We also use the proper device address, so it doesn't matter
496 * whether we have real eeprom_dev. Legacy likes any address.
497 */
498 max_wait_time = 100;
499 while (twsi_wr(dd, target,
500 dev | READ_CMD, HFI1_TWSI_START)) {
501 stop_cmd(dd, target);
502 if (!--max_wait_time)
503 goto failed_write;
504 } 475 }
505 /* now read (and ignore) the resulting byte */
506 rd_byte(dd, target, 1);
507 } 476 }
508 477
478 for (i = 0; i < len; i++)
479 if (twsi_wr(dd, target, *bp++, 0))
480 goto failed_write;
481
509 ret = 0; 482 ret = 0;
510 goto bail;
511 483
512failed_write: 484failed_write:
513 stop_cmd(dd, target); 485 stop_cmd(dd, target);
514 ret = 1;
515 486
516bail: 487bail:
517 return ret; 488 return ret;
diff --git a/drivers/staging/rdma/hfi1/twsi.h b/drivers/staging/rdma/hfi1/twsi.h
index 5907e029613d..5b8a5b5e7eae 100644
--- a/drivers/staging/rdma/hfi1/twsi.h
+++ b/drivers/staging/rdma/hfi1/twsi.h
@@ -1,14 +1,13 @@
1#ifndef _TWSI_H 1#ifndef _TWSI_H
2#define _TWSI_H 2#define _TWSI_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -54,8 +51,9 @@
54 51
55struct hfi1_devdata; 52struct hfi1_devdata;
56 53
57/* Bit position of SDA pin in ASIC_QSFP* registers */ 54/* Bit position of SDA/SCL pins in ASIC_QSFP* registers */
58#define GPIO_SDA_NUM 1 55#define GPIO_SDA_NUM 1
56#define GPIO_SCL_NUM 0
59 57
60/* these functions must be called with qsfp_lock held */ 58/* these functions must be called with qsfp_lock held */
61int hfi1_twsi_reset(struct hfi1_devdata *dd, u32 target); 59int hfi1_twsi_reset(struct hfi1_devdata *dd, u32 target);
@@ -64,5 +62,4 @@ int hfi1_twsi_blk_rd(struct hfi1_devdata *dd, u32 target, int dev, int addr,
64int hfi1_twsi_blk_wr(struct hfi1_devdata *dd, u32 target, int dev, int addr, 62int hfi1_twsi_blk_wr(struct hfi1_devdata *dd, u32 target, int dev, int addr,
65 const void *buffer, int len); 63 const void *buffer, int len);
66 64
67
68#endif /* _TWSI_H */ 65#endif /* _TWSI_H */
diff --git a/drivers/staging/rdma/hfi1/uc.c b/drivers/staging/rdma/hfi1/uc.c
index 4f2a7889a852..df773d433297 100644
--- a/drivers/staging/rdma/hfi1/uc.c
+++ b/drivers/staging/rdma/hfi1/uc.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -49,71 +46,82 @@
49 */ 46 */
50 47
51#include "hfi.h" 48#include "hfi.h"
52#include "sdma.h" 49#include "verbs_txreq.h"
53#include "qp.h" 50#include "qp.h"
54 51
55/* cut down ridiculously long IB macro names */ 52/* cut down ridiculously long IB macro names */
56#define OP(x) IB_OPCODE_UC_##x 53#define OP(x) IB_OPCODE_UC_##x
57 54
55/* only opcode mask for adaptive pio */
56const u32 uc_only_opcode =
57 BIT(OP(SEND_ONLY) & 0x1f) |
58 BIT(OP(SEND_ONLY_WITH_IMMEDIATE & 0x1f)) |
59 BIT(OP(RDMA_WRITE_ONLY & 0x1f)) |
60 BIT(OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE & 0x1f));
61
58/** 62/**
59 * hfi1_make_uc_req - construct a request packet (SEND, RDMA write) 63 * hfi1_make_uc_req - construct a request packet (SEND, RDMA write)
60 * @qp: a pointer to the QP 64 * @qp: a pointer to the QP
61 * 65 *
66 * Assume s_lock is held.
67 *
62 * Return 1 if constructed; otherwise, return 0. 68 * Return 1 if constructed; otherwise, return 0.
63 */ 69 */
64int hfi1_make_uc_req(struct hfi1_qp *qp) 70int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
65{ 71{
72 struct hfi1_qp_priv *priv = qp->priv;
66 struct hfi1_other_headers *ohdr; 73 struct hfi1_other_headers *ohdr;
67 struct hfi1_swqe *wqe; 74 struct rvt_swqe *wqe;
68 unsigned long flags;
69 u32 hwords = 5; 75 u32 hwords = 5;
70 u32 bth0 = 0; 76 u32 bth0 = 0;
71 u32 len; 77 u32 len;
72 u32 pmtu = qp->pmtu; 78 u32 pmtu = qp->pmtu;
73 int ret = 0;
74 int middle = 0; 79 int middle = 0;
75 80
76 spin_lock_irqsave(&qp->s_lock, flags); 81 ps->s_txreq = get_txreq(ps->dev, qp);
82 if (IS_ERR(ps->s_txreq))
83 goto bail_no_tx;
77 84
78 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_SEND_OK)) { 85 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) {
79 if (!(ib_hfi1_state_ops[qp->state] & HFI1_FLUSH_SEND)) 86 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
80 goto bail; 87 goto bail;
81 /* We are in the error state, flush the work request. */ 88 /* We are in the error state, flush the work request. */
82 if (qp->s_last == qp->s_head) 89 smp_read_barrier_depends(); /* see post_one_send() */
90 if (qp->s_last == ACCESS_ONCE(qp->s_head))
83 goto bail; 91 goto bail;
84 /* If DMAs are in progress, we can't flush immediately. */ 92 /* If DMAs are in progress, we can't flush immediately. */
85 if (atomic_read(&qp->s_iowait.sdma_busy)) { 93 if (iowait_sdma_pending(&priv->s_iowait)) {
86 qp->s_flags |= HFI1_S_WAIT_DMA; 94 qp->s_flags |= RVT_S_WAIT_DMA;
87 goto bail; 95 goto bail;
88 } 96 }
89 clear_ahg(qp); 97 clear_ahg(qp);
90 wqe = get_swqe_ptr(qp, qp->s_last); 98 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
91 hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR); 99 hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
92 goto done; 100 goto done_free_tx;
93 } 101 }
94 102
95 ohdr = &qp->s_hdr->ibh.u.oth; 103 ohdr = &ps->s_txreq->phdr.hdr.u.oth;
96 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH) 104 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
97 ohdr = &qp->s_hdr->ibh.u.l.oth; 105 ohdr = &ps->s_txreq->phdr.hdr.u.l.oth;
98 106
99 /* Get the next send request. */ 107 /* Get the next send request. */
100 wqe = get_swqe_ptr(qp, qp->s_cur); 108 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
101 qp->s_wqe = NULL; 109 qp->s_wqe = NULL;
102 switch (qp->s_state) { 110 switch (qp->s_state) {
103 default: 111 default:
104 if (!(ib_hfi1_state_ops[qp->state] & 112 if (!(ib_rvt_state_ops[qp->state] &
105 HFI1_PROCESS_NEXT_SEND_OK)) 113 RVT_PROCESS_NEXT_SEND_OK))
106 goto bail; 114 goto bail;
107 /* Check if send work queue is empty. */ 115 /* Check if send work queue is empty. */
108 if (qp->s_cur == qp->s_head) { 116 smp_read_barrier_depends(); /* see post_one_send() */
117 if (qp->s_cur == ACCESS_ONCE(qp->s_head)) {
109 clear_ahg(qp); 118 clear_ahg(qp);
110 goto bail; 119 goto bail;
111 } 120 }
112 /* 121 /*
113 * Start a new request. 122 * Start a new request.
114 */ 123 */
115 wqe->psn = qp->s_next_psn; 124 qp->s_psn = wqe->psn;
116 qp->s_psn = qp->s_next_psn;
117 qp->s_sge.sge = wqe->sg_list[0]; 125 qp->s_sge.sge = wqe->sg_list[0];
118 qp->s_sge.sg_list = wqe->sg_list + 1; 126 qp->s_sge.sg_list = wqe->sg_list + 1;
119 qp->s_sge.num_sge = wqe->wr.num_sge; 127 qp->s_sge.num_sge = wqe->wr.num_sge;
@@ -128,9 +136,9 @@ int hfi1_make_uc_req(struct hfi1_qp *qp)
128 len = pmtu; 136 len = pmtu;
129 break; 137 break;
130 } 138 }
131 if (wqe->wr.opcode == IB_WR_SEND) 139 if (wqe->wr.opcode == IB_WR_SEND) {
132 qp->s_state = OP(SEND_ONLY); 140 qp->s_state = OP(SEND_ONLY);
133 else { 141 } else {
134 qp->s_state = 142 qp->s_state =
135 OP(SEND_ONLY_WITH_IMMEDIATE); 143 OP(SEND_ONLY_WITH_IMMEDIATE);
136 /* Immediate data comes after the BTH */ 144 /* Immediate data comes after the BTH */
@@ -157,9 +165,9 @@ int hfi1_make_uc_req(struct hfi1_qp *qp)
157 len = pmtu; 165 len = pmtu;
158 break; 166 break;
159 } 167 }
160 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) 168 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) {
161 qp->s_state = OP(RDMA_WRITE_ONLY); 169 qp->s_state = OP(RDMA_WRITE_ONLY);
162 else { 170 } else {
163 qp->s_state = 171 qp->s_state =
164 OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE); 172 OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
165 /* Immediate data comes after the RETH */ 173 /* Immediate data comes after the RETH */
@@ -188,9 +196,9 @@ int hfi1_make_uc_req(struct hfi1_qp *qp)
188 middle = HFI1_CAP_IS_KSET(SDMA_AHG); 196 middle = HFI1_CAP_IS_KSET(SDMA_AHG);
189 break; 197 break;
190 } 198 }
191 if (wqe->wr.opcode == IB_WR_SEND) 199 if (wqe->wr.opcode == IB_WR_SEND) {
192 qp->s_state = OP(SEND_LAST); 200 qp->s_state = OP(SEND_LAST);
193 else { 201 } else {
194 qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE); 202 qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
195 /* Immediate data comes after the BTH */ 203 /* Immediate data comes after the BTH */
196 ohdr->u.imm_data = wqe->wr.ex.imm_data; 204 ohdr->u.imm_data = wqe->wr.ex.imm_data;
@@ -213,9 +221,9 @@ int hfi1_make_uc_req(struct hfi1_qp *qp)
213 middle = HFI1_CAP_IS_KSET(SDMA_AHG); 221 middle = HFI1_CAP_IS_KSET(SDMA_AHG);
214 break; 222 break;
215 } 223 }
216 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) 224 if (wqe->wr.opcode == IB_WR_RDMA_WRITE) {
217 qp->s_state = OP(RDMA_WRITE_LAST); 225 qp->s_state = OP(RDMA_WRITE_LAST);
218 else { 226 } else {
219 qp->s_state = 227 qp->s_state =
220 OP(RDMA_WRITE_LAST_WITH_IMMEDIATE); 228 OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
221 /* Immediate data comes after the BTH */ 229 /* Immediate data comes after the BTH */
@@ -231,19 +239,28 @@ int hfi1_make_uc_req(struct hfi1_qp *qp)
231 } 239 }
232 qp->s_len -= len; 240 qp->s_len -= len;
233 qp->s_hdrwords = hwords; 241 qp->s_hdrwords = hwords;
242 ps->s_txreq->sde = priv->s_sde;
234 qp->s_cur_sge = &qp->s_sge; 243 qp->s_cur_sge = &qp->s_sge;
235 qp->s_cur_size = len; 244 qp->s_cur_size = len;
236 hfi1_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24), 245 hfi1_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24),
237 mask_psn(qp->s_next_psn++), middle); 246 mask_psn(qp->s_psn++), middle, ps);
238done: 247 /* pbc */
239 ret = 1; 248 ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2;
240 goto unlock; 249 return 1;
250
251done_free_tx:
252 hfi1_put_txreq(ps->s_txreq);
253 ps->s_txreq = NULL;
254 return 1;
241 255
242bail: 256bail:
243 qp->s_flags &= ~HFI1_S_BUSY; 257 hfi1_put_txreq(ps->s_txreq);
244unlock: 258
245 spin_unlock_irqrestore(&qp->s_lock, flags); 259bail_no_tx:
246 return ret; 260 ps->s_txreq = NULL;
261 qp->s_flags &= ~RVT_S_BUSY;
262 qp->s_hdrwords = 0;
263 return 0;
247} 264}
248 265
249/** 266/**
@@ -266,7 +283,7 @@ void hfi1_uc_rcv(struct hfi1_packet *packet)
266 u32 rcv_flags = packet->rcv_flags; 283 u32 rcv_flags = packet->rcv_flags;
267 void *data = packet->ebuf; 284 void *data = packet->ebuf;
268 u32 tlen = packet->tlen; 285 u32 tlen = packet->tlen;
269 struct hfi1_qp *qp = packet->qp; 286 struct rvt_qp *qp = packet->qp;
270 struct hfi1_other_headers *ohdr = packet->ohdr; 287 struct hfi1_other_headers *ohdr = packet->ohdr;
271 u32 bth0, opcode; 288 u32 bth0, opcode;
272 u32 hdrsize = packet->hlen; 289 u32 hdrsize = packet->hlen;
@@ -291,14 +308,14 @@ void hfi1_uc_rcv(struct hfi1_packet *packet)
291 u16 rlid = be16_to_cpu(hdr->lrh[3]); 308 u16 rlid = be16_to_cpu(hdr->lrh[3]);
292 u8 sl, sc5; 309 u8 sl, sc5;
293 310
294 lqpn = bth1 & HFI1_QPN_MASK; 311 lqpn = bth1 & RVT_QPN_MASK;
295 rqpn = qp->remote_qpn; 312 rqpn = qp->remote_qpn;
296 313
297 sc5 = ibp->sl_to_sc[qp->remote_ah_attr.sl]; 314 sc5 = ibp->sl_to_sc[qp->remote_ah_attr.sl];
298 sl = ibp->sc_to_sl[sc5]; 315 sl = ibp->sc_to_sl[sc5];
299 316
300 process_becn(ppd, sl, rlid, lqpn, rqpn, 317 process_becn(ppd, sl, rlid, lqpn, rqpn,
301 IB_CC_SVCTYPE_UC); 318 IB_CC_SVCTYPE_UC);
302 } 319 }
303 320
304 if (bth1 & HFI1_FECN_SMASK) { 321 if (bth1 & HFI1_FECN_SMASK) {
@@ -331,10 +348,11 @@ void hfi1_uc_rcv(struct hfi1_packet *packet)
331inv: 348inv:
332 if (qp->r_state == OP(SEND_FIRST) || 349 if (qp->r_state == OP(SEND_FIRST) ||
333 qp->r_state == OP(SEND_MIDDLE)) { 350 qp->r_state == OP(SEND_MIDDLE)) {
334 set_bit(HFI1_R_REWIND_SGE, &qp->r_aflags); 351 set_bit(RVT_R_REWIND_SGE, &qp->r_aflags);
335 qp->r_sge.num_sge = 0; 352 qp->r_sge.num_sge = 0;
336 } else 353 } else {
337 hfi1_put_ss(&qp->r_sge); 354 rvt_put_ss(&qp->r_sge);
355 }
338 qp->r_state = OP(SEND_LAST); 356 qp->r_state = OP(SEND_LAST);
339 switch (opcode) { 357 switch (opcode) {
340 case OP(SEND_FIRST): 358 case OP(SEND_FIRST):
@@ -381,7 +399,7 @@ inv:
381 goto inv; 399 goto inv;
382 } 400 }
383 401
384 if (qp->state == IB_QPS_RTR && !(qp->r_flags & HFI1_R_COMM_EST)) 402 if (qp->state == IB_QPS_RTR && !(qp->r_flags & RVT_R_COMM_EST))
385 qp_comm_est(qp); 403 qp_comm_est(qp);
386 404
387 /* OK, process the packet. */ 405 /* OK, process the packet. */
@@ -390,10 +408,10 @@ inv:
390 case OP(SEND_ONLY): 408 case OP(SEND_ONLY):
391 case OP(SEND_ONLY_WITH_IMMEDIATE): 409 case OP(SEND_ONLY_WITH_IMMEDIATE):
392send_first: 410send_first:
393 if (test_and_clear_bit(HFI1_R_REWIND_SGE, &qp->r_aflags)) 411 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) {
394 qp->r_sge = qp->s_rdma_read_sge; 412 qp->r_sge = qp->s_rdma_read_sge;
395 else { 413 } else {
396 ret = hfi1_get_rwqe(qp, 0); 414 ret = hfi1_rvt_get_rwqe(qp, 0);
397 if (ret < 0) 415 if (ret < 0)
398 goto op_err; 416 goto op_err;
399 if (!ret) 417 if (!ret)
@@ -417,7 +435,7 @@ send_first:
417 qp->r_rcv_len += pmtu; 435 qp->r_rcv_len += pmtu;
418 if (unlikely(qp->r_rcv_len > qp->r_len)) 436 if (unlikely(qp->r_rcv_len > qp->r_len))
419 goto rewind; 437 goto rewind;
420 hfi1_copy_sge(&qp->r_sge, data, pmtu, 0); 438 hfi1_copy_sge(&qp->r_sge, data, pmtu, 0, 0);
421 break; 439 break;
422 440
423 case OP(SEND_LAST_WITH_IMMEDIATE): 441 case OP(SEND_LAST_WITH_IMMEDIATE):
@@ -442,8 +460,8 @@ send_last:
442 if (unlikely(wc.byte_len > qp->r_len)) 460 if (unlikely(wc.byte_len > qp->r_len))
443 goto rewind; 461 goto rewind;
444 wc.opcode = IB_WC_RECV; 462 wc.opcode = IB_WC_RECV;
445 hfi1_copy_sge(&qp->r_sge, data, tlen, 0); 463 hfi1_copy_sge(&qp->r_sge, data, tlen, 0, 0);
446 hfi1_put_ss(&qp->s_rdma_read_sge); 464 rvt_put_ss(&qp->s_rdma_read_sge);
447last_imm: 465last_imm:
448 wc.wr_id = qp->r_wr_id; 466 wc.wr_id = qp->r_wr_id;
449 wc.status = IB_WC_SUCCESS; 467 wc.status = IB_WC_SUCCESS;
@@ -468,9 +486,9 @@ last_imm:
468 wc.dlid_path_bits = 0; 486 wc.dlid_path_bits = 0;
469 wc.port_num = 0; 487 wc.port_num = 0;
470 /* Signal completion event if the solicited bit is set. */ 488 /* Signal completion event if the solicited bit is set. */
471 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 489 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
472 (ohdr->bth[0] & 490 (ohdr->bth[0] &
473 cpu_to_be32(IB_BTH_SOLICITED)) != 0); 491 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
474 break; 492 break;
475 493
476 case OP(RDMA_WRITE_FIRST): 494 case OP(RDMA_WRITE_FIRST):
@@ -491,8 +509,8 @@ rdma_first:
491 int ok; 509 int ok;
492 510
493 /* Check rkey */ 511 /* Check rkey */
494 ok = hfi1_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, 512 ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len,
495 vaddr, rkey, IB_ACCESS_REMOTE_WRITE); 513 vaddr, rkey, IB_ACCESS_REMOTE_WRITE);
496 if (unlikely(!ok)) 514 if (unlikely(!ok))
497 goto drop; 515 goto drop;
498 qp->r_sge.num_sge = 1; 516 qp->r_sge.num_sge = 1;
@@ -503,9 +521,9 @@ rdma_first:
503 qp->r_sge.sge.length = 0; 521 qp->r_sge.sge.length = 0;
504 qp->r_sge.sge.sge_length = 0; 522 qp->r_sge.sge.sge_length = 0;
505 } 523 }
506 if (opcode == OP(RDMA_WRITE_ONLY)) 524 if (opcode == OP(RDMA_WRITE_ONLY)) {
507 goto rdma_last; 525 goto rdma_last;
508 else if (opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE)) { 526 } else if (opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE)) {
509 wc.ex.imm_data = ohdr->u.rc.imm_data; 527 wc.ex.imm_data = ohdr->u.rc.imm_data;
510 goto rdma_last_imm; 528 goto rdma_last_imm;
511 } 529 }
@@ -517,7 +535,7 @@ rdma_first:
517 qp->r_rcv_len += pmtu; 535 qp->r_rcv_len += pmtu;
518 if (unlikely(qp->r_rcv_len > qp->r_len)) 536 if (unlikely(qp->r_rcv_len > qp->r_len))
519 goto drop; 537 goto drop;
520 hfi1_copy_sge(&qp->r_sge, data, pmtu, 1); 538 hfi1_copy_sge(&qp->r_sge, data, pmtu, 1, 0);
521 break; 539 break;
522 540
523 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE): 541 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
@@ -535,10 +553,10 @@ rdma_last_imm:
535 tlen -= (hdrsize + pad + 4); 553 tlen -= (hdrsize + pad + 4);
536 if (unlikely(tlen + qp->r_rcv_len != qp->r_len)) 554 if (unlikely(tlen + qp->r_rcv_len != qp->r_len))
537 goto drop; 555 goto drop;
538 if (test_and_clear_bit(HFI1_R_REWIND_SGE, &qp->r_aflags)) 556 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) {
539 hfi1_put_ss(&qp->s_rdma_read_sge); 557 rvt_put_ss(&qp->s_rdma_read_sge);
540 else { 558 } else {
541 ret = hfi1_get_rwqe(qp, 1); 559 ret = hfi1_rvt_get_rwqe(qp, 1);
542 if (ret < 0) 560 if (ret < 0)
543 goto op_err; 561 goto op_err;
544 if (!ret) 562 if (!ret)
@@ -546,8 +564,8 @@ rdma_last_imm:
546 } 564 }
547 wc.byte_len = qp->r_len; 565 wc.byte_len = qp->r_len;
548 wc.opcode = IB_WC_RECV_RDMA_WITH_IMM; 566 wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;
549 hfi1_copy_sge(&qp->r_sge, data, tlen, 1); 567 hfi1_copy_sge(&qp->r_sge, data, tlen, 1, 0);
550 hfi1_put_ss(&qp->r_sge); 568 rvt_put_ss(&qp->r_sge);
551 goto last_imm; 569 goto last_imm;
552 570
553 case OP(RDMA_WRITE_LAST): 571 case OP(RDMA_WRITE_LAST):
@@ -562,8 +580,8 @@ rdma_last:
562 tlen -= (hdrsize + pad + 4); 580 tlen -= (hdrsize + pad + 4);
563 if (unlikely(tlen + qp->r_rcv_len != qp->r_len)) 581 if (unlikely(tlen + qp->r_rcv_len != qp->r_len))
564 goto drop; 582 goto drop;
565 hfi1_copy_sge(&qp->r_sge, data, tlen, 1); 583 hfi1_copy_sge(&qp->r_sge, data, tlen, 1, 0);
566 hfi1_put_ss(&qp->r_sge); 584 rvt_put_ss(&qp->r_sge);
567 break; 585 break;
568 586
569 default: 587 default:
@@ -575,14 +593,12 @@ rdma_last:
575 return; 593 return;
576 594
577rewind: 595rewind:
578 set_bit(HFI1_R_REWIND_SGE, &qp->r_aflags); 596 set_bit(RVT_R_REWIND_SGE, &qp->r_aflags);
579 qp->r_sge.num_sge = 0; 597 qp->r_sge.num_sge = 0;
580drop: 598drop:
581 ibp->n_pkt_drops++; 599 ibp->rvp.n_pkt_drops++;
582 return; 600 return;
583 601
584op_err: 602op_err:
585 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR); 603 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
586 return;
587
588} 604}
diff --git a/drivers/staging/rdma/hfi1/ud.c b/drivers/staging/rdma/hfi1/ud.c
index 25e6053c38db..ae8a70f703eb 100644
--- a/drivers/staging/rdma/hfi1/ud.c
+++ b/drivers/staging/rdma/hfi1/ud.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -53,6 +50,7 @@
53 50
54#include "hfi.h" 51#include "hfi.h"
55#include "mad.h" 52#include "mad.h"
53#include "verbs_txreq.h"
56#include "qp.h" 54#include "qp.h"
57 55
58/** 56/**
@@ -65,24 +63,25 @@
65 * Note that the receive interrupt handler may be calling hfi1_ud_rcv() 63 * Note that the receive interrupt handler may be calling hfi1_ud_rcv()
66 * while this is being called. 64 * while this is being called.
67 */ 65 */
68static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe) 66static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
69{ 67{
70 struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num); 68 struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
71 struct hfi1_pportdata *ppd; 69 struct hfi1_pportdata *ppd;
72 struct hfi1_qp *qp; 70 struct rvt_qp *qp;
73 struct ib_ah_attr *ah_attr; 71 struct ib_ah_attr *ah_attr;
74 unsigned long flags; 72 unsigned long flags;
75 struct hfi1_sge_state ssge; 73 struct rvt_sge_state ssge;
76 struct hfi1_sge *sge; 74 struct rvt_sge *sge;
77 struct ib_wc wc; 75 struct ib_wc wc;
78 u32 length; 76 u32 length;
79 enum ib_qp_type sqptype, dqptype; 77 enum ib_qp_type sqptype, dqptype;
80 78
81 rcu_read_lock(); 79 rcu_read_lock();
82 80
83 qp = hfi1_lookup_qpn(ibp, swqe->ud_wr.remote_qpn); 81 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp,
82 swqe->ud_wr.remote_qpn);
84 if (!qp) { 83 if (!qp) {
85 ibp->n_pkt_drops++; 84 ibp->rvp.n_pkt_drops++;
86 rcu_read_unlock(); 85 rcu_read_unlock();
87 return; 86 return;
88 } 87 }
@@ -93,12 +92,12 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe)
93 IB_QPT_UD : qp->ibqp.qp_type; 92 IB_QPT_UD : qp->ibqp.qp_type;
94 93
95 if (dqptype != sqptype || 94 if (dqptype != sqptype ||
96 !(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK)) { 95 !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
97 ibp->n_pkt_drops++; 96 ibp->rvp.n_pkt_drops++;
98 goto drop; 97 goto drop;
99 } 98 }
100 99
101 ah_attr = &to_iah(swqe->ud_wr.ah)->attr; 100 ah_attr = &ibah_to_rvtah(swqe->ud_wr.ah)->attr;
102 ppd = ppd_from_ibp(ibp); 101 ppd = ppd_from_ibp(ibp);
103 102
104 if (qp->ibqp.qp_num > 1) { 103 if (qp->ibqp.qp_num > 1) {
@@ -161,35 +160,36 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe)
161 /* 160 /*
162 * Get the next work request entry to find where to put the data. 161 * Get the next work request entry to find where to put the data.
163 */ 162 */
164 if (qp->r_flags & HFI1_R_REUSE_SGE) 163 if (qp->r_flags & RVT_R_REUSE_SGE) {
165 qp->r_flags &= ~HFI1_R_REUSE_SGE; 164 qp->r_flags &= ~RVT_R_REUSE_SGE;
166 else { 165 } else {
167 int ret; 166 int ret;
168 167
169 ret = hfi1_get_rwqe(qp, 0); 168 ret = hfi1_rvt_get_rwqe(qp, 0);
170 if (ret < 0) { 169 if (ret < 0) {
171 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR); 170 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
172 goto bail_unlock; 171 goto bail_unlock;
173 } 172 }
174 if (!ret) { 173 if (!ret) {
175 if (qp->ibqp.qp_num == 0) 174 if (qp->ibqp.qp_num == 0)
176 ibp->n_vl15_dropped++; 175 ibp->rvp.n_vl15_dropped++;
177 goto bail_unlock; 176 goto bail_unlock;
178 } 177 }
179 } 178 }
180 /* Silently drop packets which are too big. */ 179 /* Silently drop packets which are too big. */
181 if (unlikely(wc.byte_len > qp->r_len)) { 180 if (unlikely(wc.byte_len > qp->r_len)) {
182 qp->r_flags |= HFI1_R_REUSE_SGE; 181 qp->r_flags |= RVT_R_REUSE_SGE;
183 ibp->n_pkt_drops++; 182 ibp->rvp.n_pkt_drops++;
184 goto bail_unlock; 183 goto bail_unlock;
185 } 184 }
186 185
187 if (ah_attr->ah_flags & IB_AH_GRH) { 186 if (ah_attr->ah_flags & IB_AH_GRH) {
188 hfi1_copy_sge(&qp->r_sge, &ah_attr->grh, 187 hfi1_copy_sge(&qp->r_sge, &ah_attr->grh,
189 sizeof(struct ib_grh), 1); 188 sizeof(struct ib_grh), 1, 0);
190 wc.wc_flags |= IB_WC_GRH; 189 wc.wc_flags |= IB_WC_GRH;
191 } else 190 } else {
192 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1); 191 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
192 }
193 ssge.sg_list = swqe->sg_list + 1; 193 ssge.sg_list = swqe->sg_list + 1;
194 ssge.sge = *swqe->sg_list; 194 ssge.sge = *swqe->sg_list;
195 ssge.num_sge = swqe->wr.num_sge; 195 ssge.num_sge = swqe->wr.num_sge;
@@ -202,7 +202,7 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe)
202 if (len > sge->sge_length) 202 if (len > sge->sge_length)
203 len = sge->sge_length; 203 len = sge->sge_length;
204 WARN_ON_ONCE(len == 0); 204 WARN_ON_ONCE(len == 0);
205 hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, 1); 205 hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, 1, 0);
206 sge->vaddr += len; 206 sge->vaddr += len;
207 sge->length -= len; 207 sge->length -= len;
208 sge->sge_length -= len; 208 sge->sge_length -= len;
@@ -210,7 +210,7 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe)
210 if (--ssge.num_sge) 210 if (--ssge.num_sge)
211 *sge = *ssge.sg_list++; 211 *sge = *ssge.sg_list++;
212 } else if (sge->length == 0 && sge->mr->lkey) { 212 } else if (sge->length == 0 && sge->mr->lkey) {
213 if (++sge->n >= HFI1_SEGSZ) { 213 if (++sge->n >= RVT_SEGSZ) {
214 if (++sge->m >= sge->mr->mapsz) 214 if (++sge->m >= sge->mr->mapsz)
215 break; 215 break;
216 sge->n = 0; 216 sge->n = 0;
@@ -222,8 +222,8 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe)
222 } 222 }
223 length -= len; 223 length -= len;
224 } 224 }
225 hfi1_put_ss(&qp->r_sge); 225 rvt_put_ss(&qp->r_sge);
226 if (!test_and_clear_bit(HFI1_R_WRID_VALID, &qp->r_aflags)) 226 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
227 goto bail_unlock; 227 goto bail_unlock;
228 wc.wr_id = qp->r_wr_id; 228 wc.wr_id = qp->r_wr_id;
229 wc.status = IB_WC_SUCCESS; 229 wc.status = IB_WC_SUCCESS;
@@ -242,14 +242,14 @@ static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe)
242 wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1)); 242 wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1));
243 /* Check for loopback when the port lid is not set */ 243 /* Check for loopback when the port lid is not set */
244 if (wc.slid == 0 && sqp->ibqp.qp_type == IB_QPT_GSI) 244 if (wc.slid == 0 && sqp->ibqp.qp_type == IB_QPT_GSI)
245 wc.slid = HFI1_PERMISSIVE_LID; 245 wc.slid = be16_to_cpu(IB_LID_PERMISSIVE);
246 wc.sl = ah_attr->sl; 246 wc.sl = ah_attr->sl;
247 wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1); 247 wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1);
248 wc.port_num = qp->port_num; 248 wc.port_num = qp->port_num;
249 /* Signal completion event if the solicited bit is set. */ 249 /* Signal completion event if the solicited bit is set. */
250 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 250 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
251 swqe->wr.send_flags & IB_SEND_SOLICITED); 251 swqe->wr.send_flags & IB_SEND_SOLICITED);
252 ibp->n_loop_pkts++; 252 ibp->rvp.n_loop_pkts++;
253bail_unlock: 253bail_unlock:
254 spin_unlock_irqrestore(&qp->r_lock, flags); 254 spin_unlock_irqrestore(&qp->r_lock, flags);
255drop: 255drop:
@@ -260,47 +260,53 @@ drop:
260 * hfi1_make_ud_req - construct a UD request packet 260 * hfi1_make_ud_req - construct a UD request packet
261 * @qp: the QP 261 * @qp: the QP
262 * 262 *
263 * Assume s_lock is held.
264 *
263 * Return 1 if constructed; otherwise, return 0. 265 * Return 1 if constructed; otherwise, return 0.
264 */ 266 */
265int hfi1_make_ud_req(struct hfi1_qp *qp) 267int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
266{ 268{
269 struct hfi1_qp_priv *priv = qp->priv;
267 struct hfi1_other_headers *ohdr; 270 struct hfi1_other_headers *ohdr;
268 struct ib_ah_attr *ah_attr; 271 struct ib_ah_attr *ah_attr;
269 struct hfi1_pportdata *ppd; 272 struct hfi1_pportdata *ppd;
270 struct hfi1_ibport *ibp; 273 struct hfi1_ibport *ibp;
271 struct hfi1_swqe *wqe; 274 struct rvt_swqe *wqe;
272 unsigned long flags;
273 u32 nwords; 275 u32 nwords;
274 u32 extra_bytes; 276 u32 extra_bytes;
275 u32 bth0; 277 u32 bth0;
276 u16 lrh0; 278 u16 lrh0;
277 u16 lid; 279 u16 lid;
278 int ret = 0;
279 int next_cur; 280 int next_cur;
280 u8 sc5; 281 u8 sc5;
281 282
282 spin_lock_irqsave(&qp->s_lock, flags); 283 ps->s_txreq = get_txreq(ps->dev, qp);
284 if (IS_ERR(ps->s_txreq))
285 goto bail_no_tx;
283 286
284 if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_NEXT_SEND_OK)) { 287 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
285 if (!(ib_hfi1_state_ops[qp->state] & HFI1_FLUSH_SEND)) 288 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
286 goto bail; 289 goto bail;
287 /* We are in the error state, flush the work request. */ 290 /* We are in the error state, flush the work request. */
288 if (qp->s_last == qp->s_head) 291 smp_read_barrier_depends(); /* see post_one_send */
292 if (qp->s_last == ACCESS_ONCE(qp->s_head))
289 goto bail; 293 goto bail;
290 /* If DMAs are in progress, we can't flush immediately. */ 294 /* If DMAs are in progress, we can't flush immediately. */
291 if (atomic_read(&qp->s_iowait.sdma_busy)) { 295 if (iowait_sdma_pending(&priv->s_iowait)) {
292 qp->s_flags |= HFI1_S_WAIT_DMA; 296 qp->s_flags |= RVT_S_WAIT_DMA;
293 goto bail; 297 goto bail;
294 } 298 }
295 wqe = get_swqe_ptr(qp, qp->s_last); 299 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
296 hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR); 300 hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
297 goto done; 301 goto done_free_tx;
298 } 302 }
299 303
300 if (qp->s_cur == qp->s_head) 304 /* see post_one_send() */
305 smp_read_barrier_depends();
306 if (qp->s_cur == ACCESS_ONCE(qp->s_head))
301 goto bail; 307 goto bail;
302 308
303 wqe = get_swqe_ptr(qp, qp->s_cur); 309 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
304 next_cur = qp->s_cur + 1; 310 next_cur = qp->s_cur + 1;
305 if (next_cur >= qp->s_size) 311 if (next_cur >= qp->s_size)
306 next_cur = 0; 312 next_cur = 0;
@@ -308,13 +314,15 @@ int hfi1_make_ud_req(struct hfi1_qp *qp)
308 /* Construct the header. */ 314 /* Construct the header. */
309 ibp = to_iport(qp->ibqp.device, qp->port_num); 315 ibp = to_iport(qp->ibqp.device, qp->port_num);
310 ppd = ppd_from_ibp(ibp); 316 ppd = ppd_from_ibp(ibp);
311 ah_attr = &to_iah(wqe->ud_wr.ah)->attr; 317 ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
312 if (ah_attr->dlid < HFI1_MULTICAST_LID_BASE || 318 if (ah_attr->dlid < be16_to_cpu(IB_MULTICAST_LID_BASE) ||
313 ah_attr->dlid == HFI1_PERMISSIVE_LID) { 319 ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
314 lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1); 320 lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1);
315 if (unlikely(!loopback && (lid == ppd->lid || 321 if (unlikely(!loopback &&
316 (lid == HFI1_PERMISSIVE_LID && 322 (lid == ppd->lid ||
317 qp->ibqp.qp_type == IB_QPT_GSI)))) { 323 (lid == be16_to_cpu(IB_LID_PERMISSIVE) &&
324 qp->ibqp.qp_type == IB_QPT_GSI)))) {
325 unsigned long flags;
318 /* 326 /*
319 * If DMAs are in progress, we can't generate 327 * If DMAs are in progress, we can't generate
320 * a completion for the loopback packet since 328 * a completion for the loopback packet since
@@ -322,16 +330,17 @@ int hfi1_make_ud_req(struct hfi1_qp *qp)
322 * Instead of waiting, we could queue a 330 * Instead of waiting, we could queue a
323 * zero length descriptor so we get a callback. 331 * zero length descriptor so we get a callback.
324 */ 332 */
325 if (atomic_read(&qp->s_iowait.sdma_busy)) { 333 if (iowait_sdma_pending(&priv->s_iowait)) {
326 qp->s_flags |= HFI1_S_WAIT_DMA; 334 qp->s_flags |= RVT_S_WAIT_DMA;
327 goto bail; 335 goto bail;
328 } 336 }
329 qp->s_cur = next_cur; 337 qp->s_cur = next_cur;
338 local_irq_save(flags);
330 spin_unlock_irqrestore(&qp->s_lock, flags); 339 spin_unlock_irqrestore(&qp->s_lock, flags);
331 ud_loopback(qp, wqe); 340 ud_loopback(qp, wqe);
332 spin_lock_irqsave(&qp->s_lock, flags); 341 spin_lock_irqsave(&qp->s_lock, flags);
333 hfi1_send_complete(qp, wqe, IB_WC_SUCCESS); 342 hfi1_send_complete(qp, wqe, IB_WC_SUCCESS);
334 goto done; 343 goto done_free_tx;
335 } 344 }
336 } 345 }
337 346
@@ -353,11 +362,12 @@ int hfi1_make_ud_req(struct hfi1_qp *qp)
353 362
354 if (ah_attr->ah_flags & IB_AH_GRH) { 363 if (ah_attr->ah_flags & IB_AH_GRH) {
355 /* Header size in 32-bit words. */ 364 /* Header size in 32-bit words. */
356 qp->s_hdrwords += hfi1_make_grh(ibp, &qp->s_hdr->ibh.u.l.grh, 365 qp->s_hdrwords += hfi1_make_grh(ibp,
357 &ah_attr->grh, 366 &ps->s_txreq->phdr.hdr.u.l.grh,
358 qp->s_hdrwords, nwords); 367 &ah_attr->grh,
368 qp->s_hdrwords, nwords);
359 lrh0 = HFI1_LRH_GRH; 369 lrh0 = HFI1_LRH_GRH;
360 ohdr = &qp->s_hdr->ibh.u.l.oth; 370 ohdr = &ps->s_txreq->phdr.hdr.u.l.oth;
361 /* 371 /*
362 * Don't worry about sending to locally attached multicast 372 * Don't worry about sending to locally attached multicast
363 * QPs. It is unspecified by the spec. what happens. 373 * QPs. It is unspecified by the spec. what happens.
@@ -365,37 +375,42 @@ int hfi1_make_ud_req(struct hfi1_qp *qp)
365 } else { 375 } else {
366 /* Header size in 32-bit words. */ 376 /* Header size in 32-bit words. */
367 lrh0 = HFI1_LRH_BTH; 377 lrh0 = HFI1_LRH_BTH;
368 ohdr = &qp->s_hdr->ibh.u.oth; 378 ohdr = &ps->s_txreq->phdr.hdr.u.oth;
369 } 379 }
370 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) { 380 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
371 qp->s_hdrwords++; 381 qp->s_hdrwords++;
372 ohdr->u.ud.imm_data = wqe->wr.ex.imm_data; 382 ohdr->u.ud.imm_data = wqe->wr.ex.imm_data;
373 bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24; 383 bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
374 } else 384 } else {
375 bth0 = IB_OPCODE_UD_SEND_ONLY << 24; 385 bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
386 }
376 sc5 = ibp->sl_to_sc[ah_attr->sl]; 387 sc5 = ibp->sl_to_sc[ah_attr->sl];
377 lrh0 |= (ah_attr->sl & 0xf) << 4; 388 lrh0 |= (ah_attr->sl & 0xf) << 4;
378 if (qp->ibqp.qp_type == IB_QPT_SMI) { 389 if (qp->ibqp.qp_type == IB_QPT_SMI) {
379 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */ 390 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
380 qp->s_sc = 0xf; 391 priv->s_sc = 0xf;
381 } else { 392 } else {
382 lrh0 |= (sc5 & 0xf) << 12; 393 lrh0 |= (sc5 & 0xf) << 12;
383 qp->s_sc = sc5; 394 priv->s_sc = sc5;
384 } 395 }
385 qp->s_sde = qp_to_sdma_engine(qp, qp->s_sc); 396 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
386 qp->s_hdr->ibh.lrh[0] = cpu_to_be16(lrh0); 397 ps->s_txreq->sde = priv->s_sde;
387 qp->s_hdr->ibh.lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */ 398 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
388 qp->s_hdr->ibh.lrh[2] = 399 ps->s_txreq->psc = priv->s_sendcontext;
400 ps->s_txreq->phdr.hdr.lrh[0] = cpu_to_be16(lrh0);
401 ps->s_txreq->phdr.hdr.lrh[1] = cpu_to_be16(ah_attr->dlid);
402 ps->s_txreq->phdr.hdr.lrh[2] =
389 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); 403 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
390 if (ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) 404 if (ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
391 qp->s_hdr->ibh.lrh[3] = IB_LID_PERMISSIVE; 405 ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE;
392 else { 406 } else {
393 lid = ppd->lid; 407 lid = ppd->lid;
394 if (lid) { 408 if (lid) {
395 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1); 409 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1);
396 qp->s_hdr->ibh.lrh[3] = cpu_to_be16(lid); 410 ps->s_txreq->phdr.hdr.lrh[3] = cpu_to_be16(lid);
397 } else 411 } else {
398 qp->s_hdr->ibh.lrh[3] = IB_LID_PERMISSIVE; 412 ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE;
413 }
399 } 414 }
400 if (wqe->wr.send_flags & IB_SEND_SOLICITED) 415 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
401 bth0 |= IB_BTH_SOLICITED; 416 bth0 |= IB_BTH_SOLICITED;
@@ -406,7 +421,7 @@ int hfi1_make_ud_req(struct hfi1_qp *qp)
406 bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index); 421 bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index);
407 ohdr->bth[0] = cpu_to_be32(bth0); 422 ohdr->bth[0] = cpu_to_be32(bth0);
408 ohdr->bth[1] = cpu_to_be32(wqe->ud_wr.remote_qpn); 423 ohdr->bth[1] = cpu_to_be32(wqe->ud_wr.remote_qpn);
409 ohdr->bth[2] = cpu_to_be32(mask_psn(qp->s_next_psn++)); 424 ohdr->bth[2] = cpu_to_be32(mask_psn(wqe->psn));
410 /* 425 /*
411 * Qkeys with the high order bit set mean use the 426 * Qkeys with the high order bit set mean use the
412 * qkey from the QP context instead of the WR (see 10.2.5). 427 * qkey from the QP context instead of the WR (see 10.2.5).
@@ -415,20 +430,28 @@ int hfi1_make_ud_req(struct hfi1_qp *qp)
415 qp->qkey : wqe->ud_wr.remote_qkey); 430 qp->qkey : wqe->ud_wr.remote_qkey);
416 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num); 431 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
417 /* disarm any ahg */ 432 /* disarm any ahg */
418 qp->s_hdr->ahgcount = 0; 433 priv->s_hdr->ahgcount = 0;
419 qp->s_hdr->ahgidx = 0; 434 priv->s_hdr->ahgidx = 0;
420 qp->s_hdr->tx_flags = 0; 435 priv->s_hdr->tx_flags = 0;
421 qp->s_hdr->sde = NULL; 436 priv->s_hdr->sde = NULL;
437 /* pbc */
438 ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2;
439
440 return 1;
422 441
423done: 442done_free_tx:
424 ret = 1; 443 hfi1_put_txreq(ps->s_txreq);
425 goto unlock; 444 ps->s_txreq = NULL;
445 return 1;
426 446
427bail: 447bail:
428 qp->s_flags &= ~HFI1_S_BUSY; 448 hfi1_put_txreq(ps->s_txreq);
429unlock: 449
430 spin_unlock_irqrestore(&qp->s_lock, flags); 450bail_no_tx:
431 return ret; 451 ps->s_txreq = NULL;
452 qp->s_flags &= ~RVT_S_BUSY;
453 qp->s_hdrwords = 0;
454 return 0;
432} 455}
433 456
434/* 457/*
@@ -476,7 +499,7 @@ int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey)
476 return -1; 499 return -1;
477} 500}
478 501
479void return_cnp(struct hfi1_ibport *ibp, struct hfi1_qp *qp, u32 remote_qpn, 502void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
480 u32 pkey, u32 slid, u32 dlid, u8 sc5, 503 u32 pkey, u32 slid, u32 dlid, u8 sc5,
481 const struct ib_grh *old_grh) 504 const struct ib_grh *old_grh)
482{ 505{
@@ -550,7 +573,7 @@ void return_cnp(struct hfi1_ibport *ibp, struct hfi1_qp *qp, u32 remote_qpn,
550 * opa_smp_check() returns 0 if all checks succeed, 1 otherwise. 573 * opa_smp_check() returns 0 if all checks succeed, 1 otherwise.
551 */ 574 */
552static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5, 575static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5,
553 struct hfi1_qp *qp, u16 slid, struct opa_smp *smp) 576 struct rvt_qp *qp, u16 slid, struct opa_smp *smp)
554{ 577{
555 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 578 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
556 579
@@ -607,7 +630,7 @@ static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5,
607 case IB_MGMT_METHOD_TRAP: 630 case IB_MGMT_METHOD_TRAP:
608 case IB_MGMT_METHOD_GET_RESP: 631 case IB_MGMT_METHOD_GET_RESP:
609 case IB_MGMT_METHOD_REPORT_RESP: 632 case IB_MGMT_METHOD_REPORT_RESP:
610 if (ibp->port_cap_flags & IB_PORT_SM) 633 if (ibp->rvp.port_cap_flags & IB_PORT_SM)
611 return 0; 634 return 0;
612 if (pkey == FULL_MGMT_P_KEY) { 635 if (pkey == FULL_MGMT_P_KEY) {
613 smp->status |= IB_SMP_UNSUP_METHOD; 636 smp->status |= IB_SMP_UNSUP_METHOD;
@@ -624,7 +647,6 @@ static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5,
624 return 0; 647 return 0;
625} 648}
626 649
627
628/** 650/**
629 * hfi1_ud_rcv - receive an incoming UD packet 651 * hfi1_ud_rcv - receive an incoming UD packet
630 * @ibp: the port the packet came in on 652 * @ibp: the port the packet came in on
@@ -654,7 +676,7 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
654 u32 rcv_flags = packet->rcv_flags; 676 u32 rcv_flags = packet->rcv_flags;
655 void *data = packet->ebuf; 677 void *data = packet->ebuf;
656 u32 tlen = packet->tlen; 678 u32 tlen = packet->tlen;
657 struct hfi1_qp *qp = packet->qp; 679 struct rvt_qp *qp = packet->qp;
658 bool has_grh = rcv_flags & HFI1_HAS_GRH; 680 bool has_grh = rcv_flags & HFI1_HAS_GRH;
659 bool sc4_bit = has_sc4_bit(packet); 681 bool sc4_bit = has_sc4_bit(packet);
660 u8 sc; 682 u8 sc;
@@ -663,10 +685,10 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
663 struct ib_grh *grh = NULL; 685 struct ib_grh *grh = NULL;
664 686
665 qkey = be32_to_cpu(ohdr->u.ud.deth[0]); 687 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
666 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & HFI1_QPN_MASK; 688 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
667 dlid = be16_to_cpu(hdr->lrh[1]); 689 dlid = be16_to_cpu(hdr->lrh[1]);
668 is_mcast = (dlid > HFI1_MULTICAST_LID_BASE) && 690 is_mcast = (dlid > be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
669 (dlid != HFI1_PERMISSIVE_LID); 691 (dlid != be16_to_cpu(IB_LID_PERMISSIVE));
670 bth1 = be32_to_cpu(ohdr->bth[1]); 692 bth1 = be32_to_cpu(ohdr->bth[1]);
671 if (unlikely(bth1 & HFI1_BECN_SMASK)) { 693 if (unlikely(bth1 & HFI1_BECN_SMASK)) {
672 /* 694 /*
@@ -674,7 +696,7 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
674 * error path. 696 * error path.
675 */ 697 */
676 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 698 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
677 u32 lqpn = be32_to_cpu(ohdr->bth[1]) & HFI1_QPN_MASK; 699 u32 lqpn = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
678 u8 sl, sc5; 700 u8 sl, sc5;
679 701
680 sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf; 702 sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf;
@@ -750,7 +772,6 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
750 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey); 772 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
751 if (mgmt_pkey_idx < 0) 773 if (mgmt_pkey_idx < 0)
752 goto drop; 774 goto drop;
753
754 } 775 }
755 if (unlikely(qkey != qp->qkey)) { 776 if (unlikely(qkey != qp->qkey)) {
756 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey, 777 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey,
@@ -788,7 +809,6 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
788 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey); 809 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
789 if (mgmt_pkey_idx < 0) 810 if (mgmt_pkey_idx < 0)
790 goto drop; 811 goto drop;
791
792 } 812 }
793 813
794 if (qp->ibqp.qp_num > 1 && 814 if (qp->ibqp.qp_num > 1 &&
@@ -799,8 +819,9 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
799 } else if (opcode == IB_OPCODE_UD_SEND_ONLY) { 819 } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
800 wc.ex.imm_data = 0; 820 wc.ex.imm_data = 0;
801 wc.wc_flags = 0; 821 wc.wc_flags = 0;
802 } else 822 } else {
803 goto drop; 823 goto drop;
824 }
804 825
805 /* 826 /*
806 * A GRH is expected to precede the data even if not 827 * A GRH is expected to precede the data even if not
@@ -811,36 +832,38 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
811 /* 832 /*
812 * Get the next work request entry to find where to put the data. 833 * Get the next work request entry to find where to put the data.
813 */ 834 */
814 if (qp->r_flags & HFI1_R_REUSE_SGE) 835 if (qp->r_flags & RVT_R_REUSE_SGE) {
815 qp->r_flags &= ~HFI1_R_REUSE_SGE; 836 qp->r_flags &= ~RVT_R_REUSE_SGE;
816 else { 837 } else {
817 int ret; 838 int ret;
818 839
819 ret = hfi1_get_rwqe(qp, 0); 840 ret = hfi1_rvt_get_rwqe(qp, 0);
820 if (ret < 0) { 841 if (ret < 0) {
821 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR); 842 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
822 return; 843 return;
823 } 844 }
824 if (!ret) { 845 if (!ret) {
825 if (qp->ibqp.qp_num == 0) 846 if (qp->ibqp.qp_num == 0)
826 ibp->n_vl15_dropped++; 847 ibp->rvp.n_vl15_dropped++;
827 return; 848 return;
828 } 849 }
829 } 850 }
830 /* Silently drop packets which are too big. */ 851 /* Silently drop packets which are too big. */
831 if (unlikely(wc.byte_len > qp->r_len)) { 852 if (unlikely(wc.byte_len > qp->r_len)) {
832 qp->r_flags |= HFI1_R_REUSE_SGE; 853 qp->r_flags |= RVT_R_REUSE_SGE;
833 goto drop; 854 goto drop;
834 } 855 }
835 if (has_grh) { 856 if (has_grh) {
836 hfi1_copy_sge(&qp->r_sge, &hdr->u.l.grh, 857 hfi1_copy_sge(&qp->r_sge, &hdr->u.l.grh,
837 sizeof(struct ib_grh), 1); 858 sizeof(struct ib_grh), 1, 0);
838 wc.wc_flags |= IB_WC_GRH; 859 wc.wc_flags |= IB_WC_GRH;
839 } else 860 } else {
840 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1); 861 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
841 hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh), 1); 862 }
842 hfi1_put_ss(&qp->r_sge); 863 hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
843 if (!test_and_clear_bit(HFI1_R_WRID_VALID, &qp->r_aflags)) 864 1, 0);
865 rvt_put_ss(&qp->r_sge);
866 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
844 return; 867 return;
845 wc.wr_id = qp->r_wr_id; 868 wc.wr_id = qp->r_wr_id;
846 wc.status = IB_WC_SUCCESS; 869 wc.status = IB_WC_SUCCESS;
@@ -862,8 +885,9 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
862 } 885 }
863 } 886 }
864 wc.pkey_index = (unsigned)mgmt_pkey_idx; 887 wc.pkey_index = (unsigned)mgmt_pkey_idx;
865 } else 888 } else {
866 wc.pkey_index = 0; 889 wc.pkey_index = 0;
890 }
867 891
868 wc.slid = be16_to_cpu(hdr->lrh[3]); 892 wc.slid = be16_to_cpu(hdr->lrh[3]);
869 sc = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf; 893 sc = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf;
@@ -873,15 +897,15 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
873 /* 897 /*
874 * Save the LMC lower bits if the destination LID is a unicast LID. 898 * Save the LMC lower bits if the destination LID is a unicast LID.
875 */ 899 */
876 wc.dlid_path_bits = dlid >= HFI1_MULTICAST_LID_BASE ? 0 : 900 wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 :
877 dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1); 901 dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
878 wc.port_num = qp->port_num; 902 wc.port_num = qp->port_num;
879 /* Signal completion event if the solicited bit is set. */ 903 /* Signal completion event if the solicited bit is set. */
880 hfi1_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 904 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
881 (ohdr->bth[0] & 905 (ohdr->bth[0] &
882 cpu_to_be32(IB_BTH_SOLICITED)) != 0); 906 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
883 return; 907 return;
884 908
885drop: 909drop:
886 ibp->n_pkt_drops++; 910 ibp->rvp.n_pkt_drops++;
887} 911}
diff --git a/drivers/staging/rdma/hfi1/user_exp_rcv.c b/drivers/staging/rdma/hfi1/user_exp_rcv.c
new file mode 100644
index 000000000000..0861e095df8d
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/user_exp_rcv.c
@@ -0,0 +1,1044 @@
1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#include <asm/page.h>
48
49#include "user_exp_rcv.h"
50#include "trace.h"
51#include "mmu_rb.h"
52
53struct tid_group {
54 struct list_head list;
55 unsigned base;
56 u8 size;
57 u8 used;
58 u8 map;
59};
60
61struct tid_rb_node {
62 struct mmu_rb_node mmu;
63 unsigned long phys;
64 struct tid_group *grp;
65 u32 rcventry;
66 dma_addr_t dma_addr;
67 bool freed;
68 unsigned npages;
69 struct page *pages[0];
70};
71
72struct tid_pageset {
73 u16 idx;
74 u16 count;
75};
76
77#define EXP_TID_SET_EMPTY(set) (set.count == 0 && list_empty(&set.list))
78
79#define num_user_pages(vaddr, len) \
80 (1 + (((((unsigned long)(vaddr) + \
81 (unsigned long)(len) - 1) & PAGE_MASK) - \
82 ((unsigned long)vaddr & PAGE_MASK)) >> PAGE_SHIFT))
83
84static void unlock_exp_tids(struct hfi1_ctxtdata *, struct exp_tid_set *,
85 struct rb_root *);
86static u32 find_phys_blocks(struct page **, unsigned, struct tid_pageset *);
87static int set_rcvarray_entry(struct file *, unsigned long, u32,
88 struct tid_group *, struct page **, unsigned);
89static int mmu_rb_insert(struct rb_root *, struct mmu_rb_node *);
90static void mmu_rb_remove(struct rb_root *, struct mmu_rb_node *, bool);
91static int mmu_rb_invalidate(struct rb_root *, struct mmu_rb_node *);
92static int program_rcvarray(struct file *, unsigned long, struct tid_group *,
93 struct tid_pageset *, unsigned, u16, struct page **,
94 u32 *, unsigned *, unsigned *);
95static int unprogram_rcvarray(struct file *, u32, struct tid_group **);
96static void clear_tid_node(struct hfi1_filedata *, u16, struct tid_rb_node *);
97
98static struct mmu_rb_ops tid_rb_ops = {
99 .insert = mmu_rb_insert,
100 .remove = mmu_rb_remove,
101 .invalidate = mmu_rb_invalidate
102};
103
104static inline u32 rcventry2tidinfo(u32 rcventry)
105{
106 u32 pair = rcventry & ~0x1;
107
108 return EXP_TID_SET(IDX, pair >> 1) |
109 EXP_TID_SET(CTRL, 1 << (rcventry - pair));
110}
111
112static inline void exp_tid_group_init(struct exp_tid_set *set)
113{
114 INIT_LIST_HEAD(&set->list);
115 set->count = 0;
116}
117
118static inline void tid_group_remove(struct tid_group *grp,
119 struct exp_tid_set *set)
120{
121 list_del_init(&grp->list);
122 set->count--;
123}
124
125static inline void tid_group_add_tail(struct tid_group *grp,
126 struct exp_tid_set *set)
127{
128 list_add_tail(&grp->list, &set->list);
129 set->count++;
130}
131
132static inline struct tid_group *tid_group_pop(struct exp_tid_set *set)
133{
134 struct tid_group *grp =
135 list_first_entry(&set->list, struct tid_group, list);
136 list_del_init(&grp->list);
137 set->count--;
138 return grp;
139}
140
141static inline void tid_group_move(struct tid_group *group,
142 struct exp_tid_set *s1,
143 struct exp_tid_set *s2)
144{
145 tid_group_remove(group, s1);
146 tid_group_add_tail(group, s2);
147}
148
149/*
150 * Initialize context and file private data needed for Expected
151 * receive caching. This needs to be done after the context has
152 * been configured with the eager/expected RcvEntry counts.
153 */
154int hfi1_user_exp_rcv_init(struct file *fp)
155{
156 struct hfi1_filedata *fd = fp->private_data;
157 struct hfi1_ctxtdata *uctxt = fd->uctxt;
158 struct hfi1_devdata *dd = uctxt->dd;
159 unsigned tidbase;
160 int i, ret = 0;
161
162 spin_lock_init(&fd->tid_lock);
163 spin_lock_init(&fd->invalid_lock);
164 fd->tid_rb_root = RB_ROOT;
165
166 if (!uctxt->subctxt_cnt || !fd->subctxt) {
167 exp_tid_group_init(&uctxt->tid_group_list);
168 exp_tid_group_init(&uctxt->tid_used_list);
169 exp_tid_group_init(&uctxt->tid_full_list);
170
171 tidbase = uctxt->expected_base;
172 for (i = 0; i < uctxt->expected_count /
173 dd->rcv_entries.group_size; i++) {
174 struct tid_group *grp;
175
176 grp = kzalloc(sizeof(*grp), GFP_KERNEL);
177 if (!grp) {
178 /*
179 * If we fail here, the groups already
180 * allocated will be freed by the close
181 * call.
182 */
183 ret = -ENOMEM;
184 goto done;
185 }
186 grp->size = dd->rcv_entries.group_size;
187 grp->base = tidbase;
188 tid_group_add_tail(grp, &uctxt->tid_group_list);
189 tidbase += dd->rcv_entries.group_size;
190 }
191 }
192
193 fd->entry_to_rb = kcalloc(uctxt->expected_count,
194 sizeof(struct rb_node *),
195 GFP_KERNEL);
196 if (!fd->entry_to_rb)
197 return -ENOMEM;
198
199 if (!HFI1_CAP_IS_USET(TID_UNMAP)) {
200 fd->invalid_tid_idx = 0;
201 fd->invalid_tids = kzalloc(uctxt->expected_count *
202 sizeof(u32), GFP_KERNEL);
203 if (!fd->invalid_tids) {
204 ret = -ENOMEM;
205 goto done;
206 }
207
208 /*
209 * Register MMU notifier callbacks. If the registration
210 * fails, continue but turn off the TID caching for
211 * all user contexts.
212 */
213 ret = hfi1_mmu_rb_register(&fd->tid_rb_root, &tid_rb_ops);
214 if (ret) {
215 dd_dev_info(dd,
216 "Failed MMU notifier registration %d\n",
217 ret);
218 HFI1_CAP_USET(TID_UNMAP);
219 ret = 0;
220 }
221 }
222
223 /*
224 * PSM does not have a good way to separate, count, and
225 * effectively enforce a limit on RcvArray entries used by
226 * subctxts (when context sharing is used) when TID caching
227 * is enabled. To help with that, we calculate a per-process
228 * RcvArray entry share and enforce that.
229 * If TID caching is not in use, PSM deals with usage on its
230 * own. In that case, we allow any subctxt to take all of the
231 * entries.
232 *
233 * Make sure that we set the tid counts only after successful
234 * init.
235 */
236 spin_lock(&fd->tid_lock);
237 if (uctxt->subctxt_cnt && !HFI1_CAP_IS_USET(TID_UNMAP)) {
238 u16 remainder;
239
240 fd->tid_limit = uctxt->expected_count / uctxt->subctxt_cnt;
241 remainder = uctxt->expected_count % uctxt->subctxt_cnt;
242 if (remainder && fd->subctxt < remainder)
243 fd->tid_limit++;
244 } else {
245 fd->tid_limit = uctxt->expected_count;
246 }
247 spin_unlock(&fd->tid_lock);
248done:
249 return ret;
250}
251
252int hfi1_user_exp_rcv_free(struct hfi1_filedata *fd)
253{
254 struct hfi1_ctxtdata *uctxt = fd->uctxt;
255 struct tid_group *grp, *gptr;
256
257 /*
258 * The notifier would have been removed when the process'es mm
259 * was freed.
260 */
261 if (!HFI1_CAP_IS_USET(TID_UNMAP))
262 hfi1_mmu_rb_unregister(&fd->tid_rb_root);
263
264 kfree(fd->invalid_tids);
265
266 if (!uctxt->cnt) {
267 if (!EXP_TID_SET_EMPTY(uctxt->tid_full_list))
268 unlock_exp_tids(uctxt, &uctxt->tid_full_list,
269 &fd->tid_rb_root);
270 if (!EXP_TID_SET_EMPTY(uctxt->tid_used_list))
271 unlock_exp_tids(uctxt, &uctxt->tid_used_list,
272 &fd->tid_rb_root);
273 list_for_each_entry_safe(grp, gptr, &uctxt->tid_group_list.list,
274 list) {
275 list_del_init(&grp->list);
276 kfree(grp);
277 }
278 hfi1_clear_tids(uctxt);
279 }
280
281 kfree(fd->entry_to_rb);
282 return 0;
283}
284
285/*
286 * Write an "empty" RcvArray entry.
287 * This function exists so the TID registaration code can use it
288 * to write to unused/unneeded entries and still take advantage
289 * of the WC performance improvements. The HFI will ignore this
290 * write to the RcvArray entry.
291 */
292static inline void rcv_array_wc_fill(struct hfi1_devdata *dd, u32 index)
293{
294 /*
295 * Doing the WC fill writes only makes sense if the device is
296 * present and the RcvArray has been mapped as WC memory.
297 */
298 if ((dd->flags & HFI1_PRESENT) && dd->rcvarray_wc)
299 writeq(0, dd->rcvarray_wc + (index * 8));
300}
301
302/*
303 * RcvArray entry allocation for Expected Receives is done by the
304 * following algorithm:
305 *
306 * The context keeps 3 lists of groups of RcvArray entries:
307 * 1. List of empty groups - tid_group_list
308 * This list is created during user context creation and
309 * contains elements which describe sets (of 8) of empty
310 * RcvArray entries.
311 * 2. List of partially used groups - tid_used_list
312 * This list contains sets of RcvArray entries which are
313 * not completely used up. Another mapping request could
314 * use some of all of the remaining entries.
315 * 3. List of full groups - tid_full_list
316 * This is the list where sets that are completely used
317 * up go.
318 *
319 * An attempt to optimize the usage of RcvArray entries is
320 * made by finding all sets of physically contiguous pages in a
321 * user's buffer.
322 * These physically contiguous sets are further split into
323 * sizes supported by the receive engine of the HFI. The
324 * resulting sets of pages are stored in struct tid_pageset,
325 * which describes the sets as:
326 * * .count - number of pages in this set
327 * * .idx - starting index into struct page ** array
328 * of this set
329 *
330 * From this point on, the algorithm deals with the page sets
331 * described above. The number of pagesets is divided by the
332 * RcvArray group size to produce the number of full groups
333 * needed.
334 *
335 * Groups from the 3 lists are manipulated using the following
336 * rules:
337 * 1. For each set of 8 pagesets, a complete group from
338 * tid_group_list is taken, programmed, and moved to
339 * the tid_full_list list.
340 * 2. For all remaining pagesets:
341 * 2.1 If the tid_used_list is empty and the tid_group_list
342 * is empty, stop processing pageset and return only
343 * what has been programmed up to this point.
344 * 2.2 If the tid_used_list is empty and the tid_group_list
345 * is not empty, move a group from tid_group_list to
346 * tid_used_list.
347 * 2.3 For each group is tid_used_group, program as much as
348 * can fit into the group. If the group becomes fully
349 * used, move it to tid_full_list.
350 */
351int hfi1_user_exp_rcv_setup(struct file *fp, struct hfi1_tid_info *tinfo)
352{
353 int ret = 0, need_group = 0, pinned;
354 struct hfi1_filedata *fd = fp->private_data;
355 struct hfi1_ctxtdata *uctxt = fd->uctxt;
356 struct hfi1_devdata *dd = uctxt->dd;
357 unsigned npages, ngroups, pageidx = 0, pageset_count, npagesets,
358 tididx = 0, mapped, mapped_pages = 0;
359 unsigned long vaddr = tinfo->vaddr;
360 struct page **pages = NULL;
361 u32 *tidlist = NULL;
362 struct tid_pageset *pagesets = NULL;
363
364 /* Get the number of pages the user buffer spans */
365 npages = num_user_pages(vaddr, tinfo->length);
366 if (!npages)
367 return -EINVAL;
368
369 if (npages > uctxt->expected_count) {
370 dd_dev_err(dd, "Expected buffer too big\n");
371 return -EINVAL;
372 }
373
374 /* Verify that access is OK for the user buffer */
375 if (!access_ok(VERIFY_WRITE, (void __user *)vaddr,
376 npages * PAGE_SIZE)) {
377 dd_dev_err(dd, "Fail vaddr %p, %u pages, !access_ok\n",
378 (void *)vaddr, npages);
379 return -EFAULT;
380 }
381
382 pagesets = kcalloc(uctxt->expected_count, sizeof(*pagesets),
383 GFP_KERNEL);
384 if (!pagesets)
385 return -ENOMEM;
386
387 /* Allocate the array of struct page pointers needed for pinning */
388 pages = kcalloc(npages, sizeof(*pages), GFP_KERNEL);
389 if (!pages) {
390 ret = -ENOMEM;
391 goto bail;
392 }
393
394 /*
395 * Pin all the pages of the user buffer. If we can't pin all the
396 * pages, accept the amount pinned so far and program only that.
397 * User space knows how to deal with partially programmed buffers.
398 */
399 if (!hfi1_can_pin_pages(dd, fd->tid_n_pinned, npages))
400 return -ENOMEM;
401 pinned = hfi1_acquire_user_pages(vaddr, npages, true, pages);
402 if (pinned <= 0) {
403 ret = pinned;
404 goto bail;
405 }
406 fd->tid_n_pinned += npages;
407
408 /* Find sets of physically contiguous pages */
409 npagesets = find_phys_blocks(pages, pinned, pagesets);
410
411 /*
412 * We don't need to access this under a lock since tid_used is per
413 * process and the same process cannot be in hfi1_user_exp_rcv_clear()
414 * and hfi1_user_exp_rcv_setup() at the same time.
415 */
416 spin_lock(&fd->tid_lock);
417 if (fd->tid_used + npagesets > fd->tid_limit)
418 pageset_count = fd->tid_limit - fd->tid_used;
419 else
420 pageset_count = npagesets;
421 spin_unlock(&fd->tid_lock);
422
423 if (!pageset_count)
424 goto bail;
425
426 ngroups = pageset_count / dd->rcv_entries.group_size;
427 tidlist = kcalloc(pageset_count, sizeof(*tidlist), GFP_KERNEL);
428 if (!tidlist) {
429 ret = -ENOMEM;
430 goto nomem;
431 }
432
433 tididx = 0;
434
435 /*
436 * From this point on, we are going to be using shared (between master
437 * and subcontexts) context resources. We need to take the lock.
438 */
439 mutex_lock(&uctxt->exp_lock);
440 /*
441 * The first step is to program the RcvArray entries which are complete
442 * groups.
443 */
444 while (ngroups && uctxt->tid_group_list.count) {
445 struct tid_group *grp =
446 tid_group_pop(&uctxt->tid_group_list);
447
448 ret = program_rcvarray(fp, vaddr, grp, pagesets,
449 pageidx, dd->rcv_entries.group_size,
450 pages, tidlist, &tididx, &mapped);
451 /*
452 * If there was a failure to program the RcvArray
453 * entries for the entire group, reset the grp fields
454 * and add the grp back to the free group list.
455 */
456 if (ret <= 0) {
457 tid_group_add_tail(grp, &uctxt->tid_group_list);
458 hfi1_cdbg(TID,
459 "Failed to program RcvArray group %d", ret);
460 goto unlock;
461 }
462
463 tid_group_add_tail(grp, &uctxt->tid_full_list);
464 ngroups--;
465 pageidx += ret;
466 mapped_pages += mapped;
467 }
468
469 while (pageidx < pageset_count) {
470 struct tid_group *grp, *ptr;
471 /*
472 * If we don't have any partially used tid groups, check
473 * if we have empty groups. If so, take one from there and
474 * put in the partially used list.
475 */
476 if (!uctxt->tid_used_list.count || need_group) {
477 if (!uctxt->tid_group_list.count)
478 goto unlock;
479
480 grp = tid_group_pop(&uctxt->tid_group_list);
481 tid_group_add_tail(grp, &uctxt->tid_used_list);
482 need_group = 0;
483 }
484 /*
485 * There is an optimization opportunity here - instead of
486 * fitting as many page sets as we can, check for a group
487 * later on in the list that could fit all of them.
488 */
489 list_for_each_entry_safe(grp, ptr, &uctxt->tid_used_list.list,
490 list) {
491 unsigned use = min_t(unsigned, pageset_count - pageidx,
492 grp->size - grp->used);
493
494 ret = program_rcvarray(fp, vaddr, grp, pagesets,
495 pageidx, use, pages, tidlist,
496 &tididx, &mapped);
497 if (ret < 0) {
498 hfi1_cdbg(TID,
499 "Failed to program RcvArray entries %d",
500 ret);
501 ret = -EFAULT;
502 goto unlock;
503 } else if (ret > 0) {
504 if (grp->used == grp->size)
505 tid_group_move(grp,
506 &uctxt->tid_used_list,
507 &uctxt->tid_full_list);
508 pageidx += ret;
509 mapped_pages += mapped;
510 need_group = 0;
511 /* Check if we are done so we break out early */
512 if (pageidx >= pageset_count)
513 break;
514 } else if (WARN_ON(ret == 0)) {
515 /*
516 * If ret is 0, we did not program any entries
517 * into this group, which can only happen if
518 * we've screwed up the accounting somewhere.
519 * Warn and try to continue.
520 */
521 need_group = 1;
522 }
523 }
524 }
525unlock:
526 mutex_unlock(&uctxt->exp_lock);
527nomem:
528 hfi1_cdbg(TID, "total mapped: tidpairs:%u pages:%u (%d)", tididx,
529 mapped_pages, ret);
530 if (tididx) {
531 spin_lock(&fd->tid_lock);
532 fd->tid_used += tididx;
533 spin_unlock(&fd->tid_lock);
534 tinfo->tidcnt = tididx;
535 tinfo->length = mapped_pages * PAGE_SIZE;
536
537 if (copy_to_user((void __user *)(unsigned long)tinfo->tidlist,
538 tidlist, sizeof(tidlist[0]) * tididx)) {
539 /*
540 * On failure to copy to the user level, we need to undo
541 * everything done so far so we don't leak resources.
542 */
543 tinfo->tidlist = (unsigned long)&tidlist;
544 hfi1_user_exp_rcv_clear(fp, tinfo);
545 tinfo->tidlist = 0;
546 ret = -EFAULT;
547 goto bail;
548 }
549 }
550
551 /*
552 * If not everything was mapped (due to insufficient RcvArray entries,
553 * for example), unpin all unmapped pages so we can pin them nex time.
554 */
555 if (mapped_pages != pinned) {
556 hfi1_release_user_pages(current->mm, &pages[mapped_pages],
557 pinned - mapped_pages,
558 false);
559 fd->tid_n_pinned -= pinned - mapped_pages;
560 }
561bail:
562 kfree(pagesets);
563 kfree(pages);
564 kfree(tidlist);
565 return ret > 0 ? 0 : ret;
566}
567
568int hfi1_user_exp_rcv_clear(struct file *fp, struct hfi1_tid_info *tinfo)
569{
570 int ret = 0;
571 struct hfi1_filedata *fd = fp->private_data;
572 struct hfi1_ctxtdata *uctxt = fd->uctxt;
573 u32 *tidinfo;
574 unsigned tididx;
575
576 tidinfo = kcalloc(tinfo->tidcnt, sizeof(*tidinfo), GFP_KERNEL);
577 if (!tidinfo)
578 return -ENOMEM;
579
580 if (copy_from_user(tidinfo, (void __user *)(unsigned long)
581 tinfo->tidlist, sizeof(tidinfo[0]) *
582 tinfo->tidcnt)) {
583 ret = -EFAULT;
584 goto done;
585 }
586
587 mutex_lock(&uctxt->exp_lock);
588 for (tididx = 0; tididx < tinfo->tidcnt; tididx++) {
589 ret = unprogram_rcvarray(fp, tidinfo[tididx], NULL);
590 if (ret) {
591 hfi1_cdbg(TID, "Failed to unprogram rcv array %d",
592 ret);
593 break;
594 }
595 }
596 spin_lock(&fd->tid_lock);
597 fd->tid_used -= tididx;
598 spin_unlock(&fd->tid_lock);
599 tinfo->tidcnt = tididx;
600 mutex_unlock(&uctxt->exp_lock);
601done:
602 kfree(tidinfo);
603 return ret;
604}
605
606int hfi1_user_exp_rcv_invalid(struct file *fp, struct hfi1_tid_info *tinfo)
607{
608 struct hfi1_filedata *fd = fp->private_data;
609 struct hfi1_ctxtdata *uctxt = fd->uctxt;
610 unsigned long *ev = uctxt->dd->events +
611 (((uctxt->ctxt - uctxt->dd->first_user_ctxt) *
612 HFI1_MAX_SHARED_CTXTS) + fd->subctxt);
613 u32 *array;
614 int ret = 0;
615
616 if (!fd->invalid_tids)
617 return -EINVAL;
618
619 /*
620 * copy_to_user() can sleep, which will leave the invalid_lock
621 * locked and cause the MMU notifier to be blocked on the lock
622 * for a long time.
623 * Copy the data to a local buffer so we can release the lock.
624 */
625 array = kcalloc(uctxt->expected_count, sizeof(*array), GFP_KERNEL);
626 if (!array)
627 return -EFAULT;
628
629 spin_lock(&fd->invalid_lock);
630 if (fd->invalid_tid_idx) {
631 memcpy(array, fd->invalid_tids, sizeof(*array) *
632 fd->invalid_tid_idx);
633 memset(fd->invalid_tids, 0, sizeof(*fd->invalid_tids) *
634 fd->invalid_tid_idx);
635 tinfo->tidcnt = fd->invalid_tid_idx;
636 fd->invalid_tid_idx = 0;
637 /*
638 * Reset the user flag while still holding the lock.
639 * Otherwise, PSM can miss events.
640 */
641 clear_bit(_HFI1_EVENT_TID_MMU_NOTIFY_BIT, ev);
642 } else {
643 tinfo->tidcnt = 0;
644 }
645 spin_unlock(&fd->invalid_lock);
646
647 if (tinfo->tidcnt) {
648 if (copy_to_user((void __user *)tinfo->tidlist,
649 array, sizeof(*array) * tinfo->tidcnt))
650 ret = -EFAULT;
651 }
652 kfree(array);
653
654 return ret;
655}
656
657static u32 find_phys_blocks(struct page **pages, unsigned npages,
658 struct tid_pageset *list)
659{
660 unsigned pagecount, pageidx, setcount = 0, i;
661 unsigned long pfn, this_pfn;
662
663 if (!npages)
664 return 0;
665
666 /*
667 * Look for sets of physically contiguous pages in the user buffer.
668 * This will allow us to optimize Expected RcvArray entry usage by
669 * using the bigger supported sizes.
670 */
671 pfn = page_to_pfn(pages[0]);
672 for (pageidx = 0, pagecount = 1, i = 1; i <= npages; i++) {
673 this_pfn = i < npages ? page_to_pfn(pages[i]) : 0;
674
675 /*
676 * If the pfn's are not sequential, pages are not physically
677 * contiguous.
678 */
679 if (this_pfn != ++pfn) {
680 /*
681 * At this point we have to loop over the set of
682 * physically contiguous pages and break them down it
683 * sizes supported by the HW.
684 * There are two main constraints:
685 * 1. The max buffer size is MAX_EXPECTED_BUFFER.
686 * If the total set size is bigger than that
687 * program only a MAX_EXPECTED_BUFFER chunk.
688 * 2. The buffer size has to be a power of two. If
689 * it is not, round down to the closes power of
690 * 2 and program that size.
691 */
692 while (pagecount) {
693 int maxpages = pagecount;
694 u32 bufsize = pagecount * PAGE_SIZE;
695
696 if (bufsize > MAX_EXPECTED_BUFFER)
697 maxpages =
698 MAX_EXPECTED_BUFFER >>
699 PAGE_SHIFT;
700 else if (!is_power_of_2(bufsize))
701 maxpages =
702 rounddown_pow_of_two(bufsize) >>
703 PAGE_SHIFT;
704
705 list[setcount].idx = pageidx;
706 list[setcount].count = maxpages;
707 pagecount -= maxpages;
708 pageidx += maxpages;
709 setcount++;
710 }
711 pageidx = i;
712 pagecount = 1;
713 pfn = this_pfn;
714 } else {
715 pagecount++;
716 }
717 }
718 return setcount;
719}
720
721/**
722 * program_rcvarray() - program an RcvArray group with receive buffers
723 * @fp: file pointer
724 * @vaddr: starting user virtual address
725 * @grp: RcvArray group
726 * @sets: array of struct tid_pageset holding information on physically
727 * contiguous chunks from the user buffer
728 * @start: starting index into sets array
729 * @count: number of struct tid_pageset's to program
730 * @pages: an array of struct page * for the user buffer
731 * @tidlist: the array of u32 elements when the information about the
732 * programmed RcvArray entries is to be encoded.
733 * @tididx: starting offset into tidlist
734 * @pmapped: (output parameter) number of pages programmed into the RcvArray
735 * entries.
736 *
737 * This function will program up to 'count' number of RcvArray entries from the
738 * group 'grp'. To make best use of write-combining writes, the function will
739 * perform writes to the unused RcvArray entries which will be ignored by the
740 * HW. Each RcvArray entry will be programmed with a physically contiguous
741 * buffer chunk from the user's virtual buffer.
742 *
743 * Return:
744 * -EINVAL if the requested count is larger than the size of the group,
745 * -ENOMEM or -EFAULT on error from set_rcvarray_entry(), or
746 * number of RcvArray entries programmed.
747 */
748static int program_rcvarray(struct file *fp, unsigned long vaddr,
749 struct tid_group *grp,
750 struct tid_pageset *sets,
751 unsigned start, u16 count, struct page **pages,
752 u32 *tidlist, unsigned *tididx, unsigned *pmapped)
753{
754 struct hfi1_filedata *fd = fp->private_data;
755 struct hfi1_ctxtdata *uctxt = fd->uctxt;
756 struct hfi1_devdata *dd = uctxt->dd;
757 u16 idx;
758 u32 tidinfo = 0, rcventry, useidx = 0;
759 int mapped = 0;
760
761 /* Count should never be larger than the group size */
762 if (count > grp->size)
763 return -EINVAL;
764
765 /* Find the first unused entry in the group */
766 for (idx = 0; idx < grp->size; idx++) {
767 if (!(grp->map & (1 << idx))) {
768 useidx = idx;
769 break;
770 }
771 rcv_array_wc_fill(dd, grp->base + idx);
772 }
773
774 idx = 0;
775 while (idx < count) {
776 u16 npages, pageidx, setidx = start + idx;
777 int ret = 0;
778
779 /*
780 * If this entry in the group is used, move to the next one.
781 * If we go past the end of the group, exit the loop.
782 */
783 if (useidx >= grp->size) {
784 break;
785 } else if (grp->map & (1 << useidx)) {
786 rcv_array_wc_fill(dd, grp->base + useidx);
787 useidx++;
788 continue;
789 }
790
791 rcventry = grp->base + useidx;
792 npages = sets[setidx].count;
793 pageidx = sets[setidx].idx;
794
795 ret = set_rcvarray_entry(fp, vaddr + (pageidx * PAGE_SIZE),
796 rcventry, grp, pages + pageidx,
797 npages);
798 if (ret)
799 return ret;
800 mapped += npages;
801
802 tidinfo = rcventry2tidinfo(rcventry - uctxt->expected_base) |
803 EXP_TID_SET(LEN, npages);
804 tidlist[(*tididx)++] = tidinfo;
805 grp->used++;
806 grp->map |= 1 << useidx++;
807 idx++;
808 }
809
810 /* Fill the rest of the group with "blank" writes */
811 for (; useidx < grp->size; useidx++)
812 rcv_array_wc_fill(dd, grp->base + useidx);
813 *pmapped = mapped;
814 return idx;
815}
816
817static int set_rcvarray_entry(struct file *fp, unsigned long vaddr,
818 u32 rcventry, struct tid_group *grp,
819 struct page **pages, unsigned npages)
820{
821 int ret;
822 struct hfi1_filedata *fd = fp->private_data;
823 struct hfi1_ctxtdata *uctxt = fd->uctxt;
824 struct tid_rb_node *node;
825 struct hfi1_devdata *dd = uctxt->dd;
826 struct rb_root *root = &fd->tid_rb_root;
827 dma_addr_t phys;
828
829 /*
830 * Allocate the node first so we can handle a potential
831 * failure before we've programmed anything.
832 */
833 node = kzalloc(sizeof(*node) + (sizeof(struct page *) * npages),
834 GFP_KERNEL);
835 if (!node)
836 return -ENOMEM;
837
838 phys = pci_map_single(dd->pcidev,
839 __va(page_to_phys(pages[0])),
840 npages * PAGE_SIZE, PCI_DMA_FROMDEVICE);
841 if (dma_mapping_error(&dd->pcidev->dev, phys)) {
842 dd_dev_err(dd, "Failed to DMA map Exp Rcv pages 0x%llx\n",
843 phys);
844 kfree(node);
845 return -EFAULT;
846 }
847
848 node->mmu.addr = vaddr;
849 node->mmu.len = npages * PAGE_SIZE;
850 node->phys = page_to_phys(pages[0]);
851 node->npages = npages;
852 node->rcventry = rcventry;
853 node->dma_addr = phys;
854 node->grp = grp;
855 node->freed = false;
856 memcpy(node->pages, pages, sizeof(struct page *) * npages);
857
858 if (HFI1_CAP_IS_USET(TID_UNMAP))
859 ret = mmu_rb_insert(root, &node->mmu);
860 else
861 ret = hfi1_mmu_rb_insert(root, &node->mmu);
862
863 if (ret) {
864 hfi1_cdbg(TID, "Failed to insert RB node %u 0x%lx, 0x%lx %d",
865 node->rcventry, node->mmu.addr, node->phys, ret);
866 pci_unmap_single(dd->pcidev, phys, npages * PAGE_SIZE,
867 PCI_DMA_FROMDEVICE);
868 kfree(node);
869 return -EFAULT;
870 }
871 hfi1_put_tid(dd, rcventry, PT_EXPECTED, phys, ilog2(npages) + 1);
872 trace_hfi1_exp_tid_reg(uctxt->ctxt, fd->subctxt, rcventry, npages,
873 node->mmu.addr, node->phys, phys);
874 return 0;
875}
876
877static int unprogram_rcvarray(struct file *fp, u32 tidinfo,
878 struct tid_group **grp)
879{
880 struct hfi1_filedata *fd = fp->private_data;
881 struct hfi1_ctxtdata *uctxt = fd->uctxt;
882 struct hfi1_devdata *dd = uctxt->dd;
883 struct tid_rb_node *node;
884 u8 tidctrl = EXP_TID_GET(tidinfo, CTRL);
885 u32 tididx = EXP_TID_GET(tidinfo, IDX) << 1, rcventry;
886
887 if (tididx >= uctxt->expected_count) {
888 dd_dev_err(dd, "Invalid RcvArray entry (%u) index for ctxt %u\n",
889 tididx, uctxt->ctxt);
890 return -EINVAL;
891 }
892
893 if (tidctrl == 0x3)
894 return -EINVAL;
895
896 rcventry = tididx + (tidctrl - 1);
897
898 node = fd->entry_to_rb[rcventry];
899 if (!node || node->rcventry != (uctxt->expected_base + rcventry))
900 return -EBADF;
901 if (HFI1_CAP_IS_USET(TID_UNMAP))
902 mmu_rb_remove(&fd->tid_rb_root, &node->mmu, false);
903 else
904 hfi1_mmu_rb_remove(&fd->tid_rb_root, &node->mmu);
905
906 if (grp)
907 *grp = node->grp;
908 clear_tid_node(fd, fd->subctxt, node);
909 return 0;
910}
911
912static void clear_tid_node(struct hfi1_filedata *fd, u16 subctxt,
913 struct tid_rb_node *node)
914{
915 struct hfi1_ctxtdata *uctxt = fd->uctxt;
916 struct hfi1_devdata *dd = uctxt->dd;
917
918 trace_hfi1_exp_tid_unreg(uctxt->ctxt, fd->subctxt, node->rcventry,
919 node->npages, node->mmu.addr, node->phys,
920 node->dma_addr);
921
922 hfi1_put_tid(dd, node->rcventry, PT_INVALID, 0, 0);
923 /*
924 * Make sure device has seen the write before we unpin the
925 * pages.
926 */
927 flush_wc();
928
929 pci_unmap_single(dd->pcidev, node->dma_addr, node->mmu.len,
930 PCI_DMA_FROMDEVICE);
931 hfi1_release_user_pages(current->mm, node->pages, node->npages, true);
932 fd->tid_n_pinned -= node->npages;
933
934 node->grp->used--;
935 node->grp->map &= ~(1 << (node->rcventry - node->grp->base));
936
937 if (node->grp->used == node->grp->size - 1)
938 tid_group_move(node->grp, &uctxt->tid_full_list,
939 &uctxt->tid_used_list);
940 else if (!node->grp->used)
941 tid_group_move(node->grp, &uctxt->tid_used_list,
942 &uctxt->tid_group_list);
943 kfree(node);
944}
945
946static void unlock_exp_tids(struct hfi1_ctxtdata *uctxt,
947 struct exp_tid_set *set, struct rb_root *root)
948{
949 struct tid_group *grp, *ptr;
950 struct hfi1_filedata *fd = container_of(root, struct hfi1_filedata,
951 tid_rb_root);
952 int i;
953
954 list_for_each_entry_safe(grp, ptr, &set->list, list) {
955 list_del_init(&grp->list);
956
957 for (i = 0; i < grp->size; i++) {
958 if (grp->map & (1 << i)) {
959 u16 rcventry = grp->base + i;
960 struct tid_rb_node *node;
961
962 node = fd->entry_to_rb[rcventry -
963 uctxt->expected_base];
964 if (!node || node->rcventry != rcventry)
965 continue;
966 if (HFI1_CAP_IS_USET(TID_UNMAP))
967 mmu_rb_remove(&fd->tid_rb_root,
968 &node->mmu, false);
969 else
970 hfi1_mmu_rb_remove(&fd->tid_rb_root,
971 &node->mmu);
972 clear_tid_node(fd, -1, node);
973 }
974 }
975 }
976}
977
978static int mmu_rb_invalidate(struct rb_root *root, struct mmu_rb_node *mnode)
979{
980 struct hfi1_filedata *fdata =
981 container_of(root, struct hfi1_filedata, tid_rb_root);
982 struct hfi1_ctxtdata *uctxt = fdata->uctxt;
983 struct tid_rb_node *node =
984 container_of(mnode, struct tid_rb_node, mmu);
985
986 if (node->freed)
987 return 0;
988
989 trace_hfi1_exp_tid_inval(uctxt->ctxt, fdata->subctxt, node->mmu.addr,
990 node->rcventry, node->npages, node->dma_addr);
991 node->freed = true;
992
993 spin_lock(&fdata->invalid_lock);
994 if (fdata->invalid_tid_idx < uctxt->expected_count) {
995 fdata->invalid_tids[fdata->invalid_tid_idx] =
996 rcventry2tidinfo(node->rcventry - uctxt->expected_base);
997 fdata->invalid_tids[fdata->invalid_tid_idx] |=
998 EXP_TID_SET(LEN, node->npages);
999 if (!fdata->invalid_tid_idx) {
1000 unsigned long *ev;
1001
1002 /*
1003 * hfi1_set_uevent_bits() sets a user event flag
1004 * for all processes. Because calling into the
1005 * driver to process TID cache invalidations is
1006 * expensive and TID cache invalidations are
1007 * handled on a per-process basis, we can
1008 * optimize this to set the flag only for the
1009 * process in question.
1010 */
1011 ev = uctxt->dd->events +
1012 (((uctxt->ctxt - uctxt->dd->first_user_ctxt) *
1013 HFI1_MAX_SHARED_CTXTS) + fdata->subctxt);
1014 set_bit(_HFI1_EVENT_TID_MMU_NOTIFY_BIT, ev);
1015 }
1016 fdata->invalid_tid_idx++;
1017 }
1018 spin_unlock(&fdata->invalid_lock);
1019 return 0;
1020}
1021
1022static int mmu_rb_insert(struct rb_root *root, struct mmu_rb_node *node)
1023{
1024 struct hfi1_filedata *fdata =
1025 container_of(root, struct hfi1_filedata, tid_rb_root);
1026 struct tid_rb_node *tnode =
1027 container_of(node, struct tid_rb_node, mmu);
1028 u32 base = fdata->uctxt->expected_base;
1029
1030 fdata->entry_to_rb[tnode->rcventry - base] = tnode;
1031 return 0;
1032}
1033
1034static void mmu_rb_remove(struct rb_root *root, struct mmu_rb_node *node,
1035 bool notifier)
1036{
1037 struct hfi1_filedata *fdata =
1038 container_of(root, struct hfi1_filedata, tid_rb_root);
1039 struct tid_rb_node *tnode =
1040 container_of(node, struct tid_rb_node, mmu);
1041 u32 base = fdata->uctxt->expected_base;
1042
1043 fdata->entry_to_rb[tnode->rcventry - base] = NULL;
1044}
diff --git a/drivers/staging/rdma/hfi1/user_exp_rcv.h b/drivers/staging/rdma/hfi1/user_exp_rcv.h
index 4f4876e1d353..9bc8d9fba87e 100644
--- a/drivers/staging/rdma/hfi1/user_exp_rcv.h
+++ b/drivers/staging/rdma/hfi1/user_exp_rcv.h
@@ -1,14 +1,13 @@
1#ifndef _HFI1_USER_EXP_RCV_H 1#ifndef _HFI1_USER_EXP_RCV_H
2#define _HFI1_USER_EXP_RCV_H 2#define _HFI1_USER_EXP_RCV_H
3/* 3/*
4 * Copyright(c) 2015, 2016 Intel Corporation.
4 * 5 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or 6 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license. 7 * redistributing this file, you may do so under either license.
7 * 8 *
8 * GPL LICENSE SUMMARY 9 * GPL LICENSE SUMMARY
9 * 10 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -20,8 +19,6 @@
20 * 19 *
21 * BSD LICENSE 20 * BSD LICENSE
22 * 21 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
27 * are met: 24 * are met:
@@ -50,6 +47,8 @@
50 * 47 *
51 */ 48 */
52 49
50#include "hfi.h"
51
53#define EXP_TID_TIDLEN_MASK 0x7FFULL 52#define EXP_TID_TIDLEN_MASK 0x7FFULL
54#define EXP_TID_TIDLEN_SHIFT 0 53#define EXP_TID_TIDLEN_SHIFT 0
55#define EXP_TID_TIDCTRL_MASK 0x3ULL 54#define EXP_TID_TIDCTRL_MASK 0x3ULL
@@ -71,4 +70,10 @@
71 (tid) |= EXP_TID_SET(field, (value)); \ 70 (tid) |= EXP_TID_SET(field, (value)); \
72 } while (0) 71 } while (0)
73 72
73int hfi1_user_exp_rcv_init(struct file *);
74int hfi1_user_exp_rcv_free(struct hfi1_filedata *);
75int hfi1_user_exp_rcv_setup(struct file *, struct hfi1_tid_info *);
76int hfi1_user_exp_rcv_clear(struct file *, struct hfi1_tid_info *);
77int hfi1_user_exp_rcv_invalid(struct file *, struct hfi1_tid_info *);
78
74#endif /* _HFI1_USER_EXP_RCV_H */ 79#endif /* _HFI1_USER_EXP_RCV_H */
diff --git a/drivers/staging/rdma/hfi1/user_pages.c b/drivers/staging/rdma/hfi1/user_pages.c
index 8ebfe9ee0d76..88e10b5f55f1 100644
--- a/drivers/staging/rdma/hfi1/user_pages.c
+++ b/drivers/staging/rdma/hfi1/user_pages.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -51,32 +48,62 @@
51#include <linux/mm.h> 48#include <linux/mm.h>
52#include <linux/sched.h> 49#include <linux/sched.h>
53#include <linux/device.h> 50#include <linux/device.h>
51#include <linux/module.h>
54 52
55#include "hfi.h" 53#include "hfi.h"
56 54
57/** 55static unsigned long cache_size = 256;
58 * hfi1_map_page - a safety wrapper around pci_map_page() 56module_param(cache_size, ulong, S_IRUGO | S_IWUSR);
57MODULE_PARM_DESC(cache_size, "Send and receive side cache size limit (in MB)");
58
59/*
60 * Determine whether the caller can pin pages.
61 *
62 * This function should be used in the implementation of buffer caches.
63 * The cache implementation should call this function prior to attempting
64 * to pin buffer pages in order to determine whether they should do so.
65 * The function computes cache limits based on the configured ulimit and
66 * cache size. Use of this function is especially important for caches
67 * which are not limited in any other way (e.g. by HW resources) and, thus,
68 * could keeping caching buffers.
59 * 69 *
60 */ 70 */
61dma_addr_t hfi1_map_page(struct pci_dev *hwdev, struct page *page, 71bool hfi1_can_pin_pages(struct hfi1_devdata *dd, u32 nlocked, u32 npages)
62 unsigned long offset, size_t size, int direction)
63{ 72{
64 return pci_map_page(hwdev, page, offset, size, direction); 73 unsigned long ulimit = rlimit(RLIMIT_MEMLOCK), pinned, cache_limit,
65} 74 size = (cache_size * (1UL << 20)); /* convert to bytes */
66 75 unsigned usr_ctxts = dd->num_rcv_contexts - dd->first_user_ctxt;
67int hfi1_acquire_user_pages(unsigned long vaddr, size_t npages, bool writable,
68 struct page **pages)
69{
70 unsigned long pinned, lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
71 bool can_lock = capable(CAP_IPC_LOCK); 76 bool can_lock = capable(CAP_IPC_LOCK);
72 int ret; 77
78 /*
79 * Calculate per-cache size. The calculation below uses only a quarter
80 * of the available per-context limit. This leaves space for other
81 * pinning. Should we worry about shared ctxts?
82 */
83 cache_limit = (ulimit / usr_ctxts) / 4;
84
85 /* If ulimit isn't set to "unlimited" and is smaller than cache_size. */
86 if (ulimit != (-1UL) && size > cache_limit)
87 size = cache_limit;
88
89 /* Convert to number of pages */
90 size = DIV_ROUND_UP(size, PAGE_SIZE);
73 91
74 down_read(&current->mm->mmap_sem); 92 down_read(&current->mm->mmap_sem);
75 pinned = current->mm->pinned_vm; 93 pinned = current->mm->pinned_vm;
76 up_read(&current->mm->mmap_sem); 94 up_read(&current->mm->mmap_sem);
77 95
78 if (pinned + npages > lock_limit && !can_lock) 96 /* First, check the absolute limit against all pinned pages. */
79 return -ENOMEM; 97 if (pinned + npages >= ulimit && !can_lock)
98 return false;
99
100 return ((nlocked + npages) <= size) || can_lock;
101}
102
103int hfi1_acquire_user_pages(unsigned long vaddr, size_t npages, bool writable,
104 struct page **pages)
105{
106 int ret;
80 107
81 ret = get_user_pages_fast(vaddr, npages, writable, pages); 108 ret = get_user_pages_fast(vaddr, npages, writable, pages);
82 if (ret < 0) 109 if (ret < 0)
@@ -89,7 +116,8 @@ int hfi1_acquire_user_pages(unsigned long vaddr, size_t npages, bool writable,
89 return ret; 116 return ret;
90} 117}
91 118
92void hfi1_release_user_pages(struct page **p, size_t npages, bool dirty) 119void hfi1_release_user_pages(struct mm_struct *mm, struct page **p,
120 size_t npages, bool dirty)
93{ 121{
94 size_t i; 122 size_t i;
95 123
@@ -99,9 +127,9 @@ void hfi1_release_user_pages(struct page **p, size_t npages, bool dirty)
99 put_page(p[i]); 127 put_page(p[i]);
100 } 128 }
101 129
102 if (current->mm) { /* during close after signal, mm can be NULL */ 130 if (mm) { /* during close after signal, mm can be NULL */
103 down_write(&current->mm->mmap_sem); 131 down_write(&mm->mmap_sem);
104 current->mm->pinned_vm -= npages; 132 mm->pinned_vm -= npages;
105 up_write(&current->mm->mmap_sem); 133 up_write(&mm->mmap_sem);
106 } 134 }
107} 135}
diff --git a/drivers/staging/rdma/hfi1/user_sdma.c b/drivers/staging/rdma/hfi1/user_sdma.c
index 9d4f5d6aaf33..ab6b6a42000f 100644
--- a/drivers/staging/rdma/hfi1/user_sdma.c
+++ b/drivers/staging/rdma/hfi1/user_sdma.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -70,6 +67,7 @@
70#include "verbs.h" /* for the headers */ 67#include "verbs.h" /* for the headers */
71#include "common.h" /* for struct hfi1_tid_info */ 68#include "common.h" /* for struct hfi1_tid_info */
72#include "trace.h" 69#include "trace.h"
70#include "mmu_rb.h"
73 71
74static uint hfi1_sdma_comp_ring_size = 128; 72static uint hfi1_sdma_comp_ring_size = 128;
75module_param_named(sdma_comp_size, hfi1_sdma_comp_ring_size, uint, S_IRUGO); 73module_param_named(sdma_comp_size, hfi1_sdma_comp_ring_size, uint, S_IRUGO);
@@ -146,7 +144,6 @@ MODULE_PARM_DESC(sdma_comp_size, "Size of User SDMA completion ring. Default: 12
146 144
147/* Last packet in the request */ 145/* Last packet in the request */
148#define TXREQ_FLAGS_REQ_LAST_PKT BIT(0) 146#define TXREQ_FLAGS_REQ_LAST_PKT BIT(0)
149#define TXREQ_FLAGS_IOVEC_LAST_PKT BIT(0)
150 147
151#define SDMA_REQ_IN_USE 0 148#define SDMA_REQ_IN_USE 0
152#define SDMA_REQ_FOR_THREAD 1 149#define SDMA_REQ_FOR_THREAD 1
@@ -170,16 +167,28 @@ static unsigned initial_pkt_count = 8;
170#define SDMA_IOWAIT_TIMEOUT 1000 /* in milliseconds */ 167#define SDMA_IOWAIT_TIMEOUT 1000 /* in milliseconds */
171 168
172struct user_sdma_iovec { 169struct user_sdma_iovec {
170 struct list_head list;
173 struct iovec iov; 171 struct iovec iov;
174 /* number of pages in this vector */ 172 /* number of pages in this vector */
175 unsigned npages; 173 unsigned npages;
176 /* array of pinned pages for this vector */ 174 /* array of pinned pages for this vector */
177 struct page **pages; 175 struct page **pages;
178 /* offset into the virtual address space of the vector at 176 /*
179 * which we last left off. */ 177 * offset into the virtual address space of the vector at
178 * which we last left off.
179 */
180 u64 offset; 180 u64 offset;
181}; 181};
182 182
183struct sdma_mmu_node {
184 struct mmu_rb_node rb;
185 struct list_head list;
186 struct hfi1_user_sdma_pkt_q *pq;
187 atomic_t refcount;
188 struct page **pages;
189 unsigned npages;
190};
191
183struct user_sdma_request { 192struct user_sdma_request {
184 struct sdma_req_info info; 193 struct sdma_req_info info;
185 struct hfi1_user_sdma_pkt_q *pq; 194 struct hfi1_user_sdma_pkt_q *pq;
@@ -213,15 +222,6 @@ struct user_sdma_request {
213 */ 222 */
214 u8 omfactor; 223 u8 omfactor;
215 /* 224 /*
216 * pointer to the user's mm_struct. We are going to
217 * get a reference to it so it doesn't get freed
218 * since we might not be in process context when we
219 * are processing the iov's.
220 * Using this mm_struct, we can get vma based on the
221 * iov's address (find_vma()).
222 */
223 struct mm_struct *user_mm;
224 /*
225 * We copy the iovs for this request (based on 225 * We copy the iovs for this request (based on
226 * info.iovcnt). These are only the data vectors 226 * info.iovcnt). These are only the data vectors
227 */ 227 */
@@ -238,13 +238,12 @@ struct user_sdma_request {
238 u16 tididx; 238 u16 tididx;
239 u32 sent; 239 u32 sent;
240 u64 seqnum; 240 u64 seqnum;
241 u64 seqcomp;
242 u64 seqsubmitted;
241 struct list_head txps; 243 struct list_head txps;
242 spinlock_t txcmp_lock; /* protect txcmp list */
243 struct list_head txcmp;
244 unsigned long flags; 244 unsigned long flags;
245 /* status of the last txreq completed */ 245 /* status of the last txreq completed */
246 int status; 246 int status;
247 struct work_struct worker;
248}; 247};
249 248
250/* 249/*
@@ -259,11 +258,6 @@ struct user_sdma_txreq {
259 struct sdma_txreq txreq; 258 struct sdma_txreq txreq;
260 struct list_head list; 259 struct list_head list;
261 struct user_sdma_request *req; 260 struct user_sdma_request *req;
262 struct {
263 struct user_sdma_iovec *vec;
264 u8 flags;
265 } iovecs[3];
266 int idx;
267 u16 flags; 261 u16 flags;
268 unsigned busycount; 262 unsigned busycount;
269 u64 seqnum; 263 u64 seqnum;
@@ -279,21 +273,21 @@ struct user_sdma_txreq {
279 273
280static int user_sdma_send_pkts(struct user_sdma_request *, unsigned); 274static int user_sdma_send_pkts(struct user_sdma_request *, unsigned);
281static int num_user_pages(const struct iovec *); 275static int num_user_pages(const struct iovec *);
282static void user_sdma_txreq_cb(struct sdma_txreq *, int, int); 276static void user_sdma_txreq_cb(struct sdma_txreq *, int);
283static void user_sdma_delayed_completion(struct work_struct *); 277static inline void pq_update(struct hfi1_user_sdma_pkt_q *);
284static void user_sdma_free_request(struct user_sdma_request *); 278static void user_sdma_free_request(struct user_sdma_request *, bool);
285static int pin_vector_pages(struct user_sdma_request *, 279static int pin_vector_pages(struct user_sdma_request *,
286 struct user_sdma_iovec *); 280 struct user_sdma_iovec *);
287static void unpin_vector_pages(struct user_sdma_request *, 281static void unpin_vector_pages(struct mm_struct *, struct page **, unsigned);
288 struct user_sdma_iovec *);
289static int check_header_template(struct user_sdma_request *, 282static int check_header_template(struct user_sdma_request *,
290 struct hfi1_pkt_header *, u32, u32); 283 struct hfi1_pkt_header *, u32, u32);
291static int set_txreq_header(struct user_sdma_request *, 284static int set_txreq_header(struct user_sdma_request *,
292 struct user_sdma_txreq *, u32); 285 struct user_sdma_txreq *, u32);
293static int set_txreq_header_ahg(struct user_sdma_request *, 286static int set_txreq_header_ahg(struct user_sdma_request *,
294 struct user_sdma_txreq *, u32); 287 struct user_sdma_txreq *, u32);
295static inline void set_comp_state(struct user_sdma_request *, 288static inline void set_comp_state(struct hfi1_user_sdma_pkt_q *,
296 enum hfi1_sdma_comp_state, int); 289 struct hfi1_user_sdma_comp_q *,
290 u16, enum hfi1_sdma_comp_state, int);
297static inline u32 set_pkt_bth_psn(__be32, u8, u32); 291static inline u32 set_pkt_bth_psn(__be32, u8, u32);
298static inline u32 get_lrh_len(struct hfi1_pkt_header, u32 len); 292static inline u32 get_lrh_len(struct hfi1_pkt_header, u32 len);
299 293
@@ -303,6 +297,17 @@ static int defer_packet_queue(
303 struct sdma_txreq *, 297 struct sdma_txreq *,
304 unsigned seq); 298 unsigned seq);
305static void activate_packet_queue(struct iowait *, int); 299static void activate_packet_queue(struct iowait *, int);
300static bool sdma_rb_filter(struct mmu_rb_node *, unsigned long, unsigned long);
301static int sdma_rb_insert(struct rb_root *, struct mmu_rb_node *);
302static void sdma_rb_remove(struct rb_root *, struct mmu_rb_node *, bool);
303static int sdma_rb_invalidate(struct rb_root *, struct mmu_rb_node *);
304
305static struct mmu_rb_ops sdma_rb_ops = {
306 .filter = sdma_rb_filter,
307 .insert = sdma_rb_insert,
308 .remove = sdma_rb_remove,
309 .invalidate = sdma_rb_invalidate
310};
306 311
307static int defer_packet_queue( 312static int defer_packet_queue(
308 struct sdma_engine *sde, 313 struct sdma_engine *sde,
@@ -380,7 +385,7 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp)
380 goto pq_nomem; 385 goto pq_nomem;
381 386
382 memsize = sizeof(*pq->reqs) * hfi1_sdma_comp_ring_size; 387 memsize = sizeof(*pq->reqs) * hfi1_sdma_comp_ring_size;
383 pq->reqs = kmalloc(memsize, GFP_KERNEL); 388 pq->reqs = kzalloc(memsize, GFP_KERNEL);
384 if (!pq->reqs) 389 if (!pq->reqs)
385 goto pq_reqs_nomem; 390 goto pq_reqs_nomem;
386 391
@@ -392,9 +397,12 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp)
392 pq->state = SDMA_PKT_Q_INACTIVE; 397 pq->state = SDMA_PKT_Q_INACTIVE;
393 atomic_set(&pq->n_reqs, 0); 398 atomic_set(&pq->n_reqs, 0);
394 init_waitqueue_head(&pq->wait); 399 init_waitqueue_head(&pq->wait);
400 pq->sdma_rb_root = RB_ROOT;
401 INIT_LIST_HEAD(&pq->evict);
402 spin_lock_init(&pq->evict_lock);
395 403
396 iowait_init(&pq->busy, 0, NULL, defer_packet_queue, 404 iowait_init(&pq->busy, 0, NULL, defer_packet_queue,
397 activate_packet_queue); 405 activate_packet_queue, NULL);
398 pq->reqidx = 0; 406 pq->reqidx = 0;
399 snprintf(buf, 64, "txreq-kmem-cache-%u-%u-%u", dd->unit, uctxt->ctxt, 407 snprintf(buf, 64, "txreq-kmem-cache-%u-%u-%u", dd->unit, uctxt->ctxt,
400 fd->subctxt); 408 fd->subctxt);
@@ -421,6 +429,12 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp)
421 cq->nentries = hfi1_sdma_comp_ring_size; 429 cq->nentries = hfi1_sdma_comp_ring_size;
422 fd->cq = cq; 430 fd->cq = cq;
423 431
432 ret = hfi1_mmu_rb_register(&pq->sdma_rb_root, &sdma_rb_ops);
433 if (ret) {
434 dd_dev_err(dd, "Failed to register with MMU %d", ret);
435 goto done;
436 }
437
424 spin_lock_irqsave(&uctxt->sdma_qlock, flags); 438 spin_lock_irqsave(&uctxt->sdma_qlock, flags);
425 list_add(&pq->list, &uctxt->sdma_queues); 439 list_add(&pq->list, &uctxt->sdma_queues);
426 spin_unlock_irqrestore(&uctxt->sdma_qlock, flags); 440 spin_unlock_irqrestore(&uctxt->sdma_qlock, flags);
@@ -450,6 +464,7 @@ int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd)
450 hfi1_cdbg(SDMA, "[%u:%u:%u] Freeing user SDMA queues", uctxt->dd->unit, 464 hfi1_cdbg(SDMA, "[%u:%u:%u] Freeing user SDMA queues", uctxt->dd->unit,
451 uctxt->ctxt, fd->subctxt); 465 uctxt->ctxt, fd->subctxt);
452 pq = fd->pq; 466 pq = fd->pq;
467 hfi1_mmu_rb_unregister(&pq->sdma_rb_root);
453 if (pq) { 468 if (pq) {
454 spin_lock_irqsave(&uctxt->sdma_qlock, flags); 469 spin_lock_irqsave(&uctxt->sdma_qlock, flags);
455 if (!list_empty(&pq->list)) 470 if (!list_empty(&pq->list))
@@ -476,7 +491,7 @@ int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd)
476int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, 491int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec,
477 unsigned long dim, unsigned long *count) 492 unsigned long dim, unsigned long *count)
478{ 493{
479 int ret = 0, i = 0, sent; 494 int ret = 0, i = 0;
480 struct hfi1_filedata *fd = fp->private_data; 495 struct hfi1_filedata *fd = fp->private_data;
481 struct hfi1_ctxtdata *uctxt = fd->uctxt; 496 struct hfi1_ctxtdata *uctxt = fd->uctxt;
482 struct hfi1_user_sdma_pkt_q *pq = fd->pq; 497 struct hfi1_user_sdma_pkt_q *pq = fd->pq;
@@ -502,9 +517,11 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec,
502 dd->unit, uctxt->ctxt, fd->subctxt, ret); 517 dd->unit, uctxt->ctxt, fd->subctxt, ret);
503 return -EFAULT; 518 return -EFAULT;
504 } 519 }
520
505 trace_hfi1_sdma_user_reqinfo(dd, uctxt->ctxt, fd->subctxt, 521 trace_hfi1_sdma_user_reqinfo(dd, uctxt->ctxt, fd->subctxt,
506 (u16 *)&info); 522 (u16 *)&info);
507 if (cq->comps[info.comp_idx].status == QUEUED) { 523 if (cq->comps[info.comp_idx].status == QUEUED ||
524 test_bit(SDMA_REQ_IN_USE, &pq->reqs[info.comp_idx].flags)) {
508 hfi1_cdbg(SDMA, "[%u:%u:%u] Entry %u is in QUEUED state", 525 hfi1_cdbg(SDMA, "[%u:%u:%u] Entry %u is in QUEUED state",
509 dd->unit, uctxt->ctxt, fd->subctxt, 526 dd->unit, uctxt->ctxt, fd->subctxt,
510 info.comp_idx); 527 info.comp_idx);
@@ -531,10 +548,7 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec,
531 req->cq = cq; 548 req->cq = cq;
532 req->status = -1; 549 req->status = -1;
533 INIT_LIST_HEAD(&req->txps); 550 INIT_LIST_HEAD(&req->txps);
534 INIT_LIST_HEAD(&req->txcmp);
535 INIT_WORK(&req->worker, user_sdma_delayed_completion);
536 551
537 spin_lock_init(&req->txcmp_lock);
538 memcpy(&req->info, &info, sizeof(info)); 552 memcpy(&req->info, &info, sizeof(info));
539 553
540 if (req_opcode(info.ctrl) == EXPECTED) 554 if (req_opcode(info.ctrl) == EXPECTED)
@@ -593,8 +607,10 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec,
593 } 607 }
594 608
595 req->koffset = le32_to_cpu(req->hdr.kdeth.swdata[6]); 609 req->koffset = le32_to_cpu(req->hdr.kdeth.swdata[6]);
596 /* Calculate the initial TID offset based on the values of 610 /*
597 KDETH.OFFSET and KDETH.OM that are passed in. */ 611 * Calculate the initial TID offset based on the values of
612 * KDETH.OFFSET and KDETH.OM that are passed in.
613 */
598 req->tidoffset = KDETH_GET(req->hdr.kdeth.ver_tid_offset, OFFSET) * 614 req->tidoffset = KDETH_GET(req->hdr.kdeth.ver_tid_offset, OFFSET) *
599 (KDETH_GET(req->hdr.kdeth.ver_tid_offset, OM) ? 615 (KDETH_GET(req->hdr.kdeth.ver_tid_offset, OM) ?
600 KDETH_OM_LARGE : KDETH_OM_SMALL); 616 KDETH_OM_LARGE : KDETH_OM_SMALL);
@@ -603,8 +619,13 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec,
603 619
604 /* Save all the IO vector structures */ 620 /* Save all the IO vector structures */
605 while (i < req->data_iovs) { 621 while (i < req->data_iovs) {
622 INIT_LIST_HEAD(&req->iovs[i].list);
606 memcpy(&req->iovs[i].iov, iovec + idx++, sizeof(struct iovec)); 623 memcpy(&req->iovs[i].iov, iovec + idx++, sizeof(struct iovec));
607 req->iovs[i].offset = 0; 624 ret = pin_vector_pages(req, &req->iovs[i]);
625 if (ret) {
626 req->status = ret;
627 goto free_req;
628 }
608 req->data_len += req->iovs[i++].iov.iov_len; 629 req->data_len += req->iovs[i++].iov.iov_len;
609 } 630 }
610 SDMA_DBG(req, "total data length %u", req->data_len); 631 SDMA_DBG(req, "total data length %u", req->data_len);
@@ -668,52 +689,59 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec,
668 } 689 }
669 } 690 }
670 691
671 set_comp_state(req, QUEUED, 0); 692 set_comp_state(pq, cq, info.comp_idx, QUEUED, 0);
693 atomic_inc(&pq->n_reqs);
672 /* Send the first N packets in the request to buy us some time */ 694 /* Send the first N packets in the request to buy us some time */
673 sent = user_sdma_send_pkts(req, pcount); 695 ret = user_sdma_send_pkts(req, pcount);
674 if (unlikely(sent < 0)) { 696 if (unlikely(ret < 0 && ret != -EBUSY)) {
675 if (sent != -EBUSY) { 697 req->status = ret;
676 req->status = sent; 698 goto free_req;
677 set_comp_state(req, ERROR, req->status);
678 return sent;
679 } else
680 sent = 0;
681 } 699 }
682 atomic_inc(&pq->n_reqs);
683 xchg(&pq->state, SDMA_PKT_Q_ACTIVE);
684 700
685 if (sent < req->info.npkts) { 701 /*
686 /* 702 * It is possible that the SDMA engine would have processed all the
687 * This is a somewhat blocking send implementation. 703 * submitted packets by the time we get here. Therefore, only set
688 * The driver will block the caller until all packets of the 704 * packet queue state to ACTIVE if there are still uncompleted
689 * request have been submitted to the SDMA engine. However, it 705 * requests.
690 * will not wait for send completions. 706 */
691 */ 707 if (atomic_read(&pq->n_reqs))
692 while (!test_bit(SDMA_REQ_SEND_DONE, &req->flags)) { 708 xchg(&pq->state, SDMA_PKT_Q_ACTIVE);
693 ret = user_sdma_send_pkts(req, pcount); 709
694 if (ret < 0) { 710 /*
695 if (ret != -EBUSY) { 711 * This is a somewhat blocking send implementation.
696 req->status = ret; 712 * The driver will block the caller until all packets of the
697 return ret; 713 * request have been submitted to the SDMA engine. However, it
698 } 714 * will not wait for send completions.
699 wait_event_interruptible_timeout( 715 */
700 pq->busy.wait_dma, 716 while (!test_bit(SDMA_REQ_SEND_DONE, &req->flags)) {
701 (pq->state == SDMA_PKT_Q_ACTIVE), 717 ret = user_sdma_send_pkts(req, pcount);
702 msecs_to_jiffies( 718 if (ret < 0) {
703 SDMA_IOWAIT_TIMEOUT)); 719 if (ret != -EBUSY) {
720 req->status = ret;
721 set_bit(SDMA_REQ_DONE_ERROR, &req->flags);
722 if (ACCESS_ONCE(req->seqcomp) ==
723 req->seqsubmitted - 1)
724 goto free_req;
725 return ret;
704 } 726 }
727 wait_event_interruptible_timeout(
728 pq->busy.wait_dma,
729 (pq->state == SDMA_PKT_Q_ACTIVE),
730 msecs_to_jiffies(
731 SDMA_IOWAIT_TIMEOUT));
705 } 732 }
706
707 } 733 }
708 *count += idx; 734 *count += idx;
709 return 0; 735 return 0;
710free_req: 736free_req:
711 user_sdma_free_request(req); 737 user_sdma_free_request(req, true);
738 pq_update(pq);
739 set_comp_state(pq, cq, info.comp_idx, ERROR, req->status);
712 return ret; 740 return ret;
713} 741}
714 742
715static inline u32 compute_data_length(struct user_sdma_request *req, 743static inline u32 compute_data_length(struct user_sdma_request *req,
716 struct user_sdma_txreq *tx) 744 struct user_sdma_txreq *tx)
717{ 745{
718 /* 746 /*
719 * Determine the proper size of the packet data. 747 * Determine the proper size of the packet data.
@@ -731,8 +759,10 @@ static inline u32 compute_data_length(struct user_sdma_request *req,
731 } else if (req_opcode(req->info.ctrl) == EXPECTED) { 759 } else if (req_opcode(req->info.ctrl) == EXPECTED) {
732 u32 tidlen = EXP_TID_GET(req->tids[req->tididx], LEN) * 760 u32 tidlen = EXP_TID_GET(req->tids[req->tididx], LEN) *
733 PAGE_SIZE; 761 PAGE_SIZE;
734 /* Get the data length based on the remaining space in the 762 /*
735 * TID pair. */ 763 * Get the data length based on the remaining space in the
764 * TID pair.
765 */
736 len = min(tidlen - req->tidoffset, (u32)req->info.fragsize); 766 len = min(tidlen - req->tidoffset, (u32)req->info.fragsize);
737 /* If we've filled up the TID pair, move to the next one. */ 767 /* If we've filled up the TID pair, move to the next one. */
738 if (unlikely(!len) && ++req->tididx < req->n_tids && 768 if (unlikely(!len) && ++req->tididx < req->n_tids &&
@@ -742,12 +772,15 @@ static inline u32 compute_data_length(struct user_sdma_request *req,
742 req->tidoffset = 0; 772 req->tidoffset = 0;
743 len = min_t(u32, tidlen, req->info.fragsize); 773 len = min_t(u32, tidlen, req->info.fragsize);
744 } 774 }
745 /* Since the TID pairs map entire pages, make sure that we 775 /*
776 * Since the TID pairs map entire pages, make sure that we
746 * are not going to try to send more data that we have 777 * are not going to try to send more data that we have
747 * remaining. */ 778 * remaining.
779 */
748 len = min(len, req->data_len - req->sent); 780 len = min(len, req->data_len - req->sent);
749 } else 781 } else {
750 len = min(req->data_len - req->sent, (u32)req->info.fragsize); 782 len = min(req->data_len - req->sent, (u32)req->info.fragsize);
783 }
751 SDMA_DBG(req, "Data Length = %u", len); 784 SDMA_DBG(req, "Data Length = %u", len);
752 return len; 785 return len;
753} 786}
@@ -810,9 +843,7 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
810 tx->flags = 0; 843 tx->flags = 0;
811 tx->req = req; 844 tx->req = req;
812 tx->busycount = 0; 845 tx->busycount = 0;
813 tx->idx = -1;
814 INIT_LIST_HEAD(&tx->list); 846 INIT_LIST_HEAD(&tx->list);
815 memset(tx->iovecs, 0, sizeof(tx->iovecs));
816 847
817 if (req->seqnum == req->info.npkts - 1) 848 if (req->seqnum == req->info.npkts - 1)
818 tx->flags |= TXREQ_FLAGS_REQ_LAST_PKT; 849 tx->flags |= TXREQ_FLAGS_REQ_LAST_PKT;
@@ -833,18 +864,6 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
833 WARN_ON(iovec->offset); 864 WARN_ON(iovec->offset);
834 } 865 }
835 866
836 /*
837 * This request might include only a header and no user
838 * data, so pin pages only if there is data and it the
839 * pages have not been pinned already.
840 */
841 if (unlikely(!iovec->pages && iovec->iov.iov_len)) {
842 ret = pin_vector_pages(req, iovec);
843 if (ret)
844 goto free_tx;
845 }
846
847 tx->iovecs[++tx->idx].vec = iovec;
848 datalen = compute_data_length(req, tx); 867 datalen = compute_data_length(req, tx);
849 if (!datalen) { 868 if (!datalen) {
850 SDMA_DBG(req, 869 SDMA_DBG(req,
@@ -934,16 +953,8 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
934 iovec->pages[pageidx], 953 iovec->pages[pageidx],
935 offset, len); 954 offset, len);
936 if (ret) { 955 if (ret) {
937 int i;
938
939 SDMA_DBG(req, "SDMA txreq add page failed %d\n", 956 SDMA_DBG(req, "SDMA txreq add page failed %d\n",
940 ret); 957 ret);
941 /* Mark all assigned vectors as complete so they
942 * are unpinned in the callback. */
943 for (i = tx->idx; i >= 0; i--) {
944 tx->iovecs[i].flags |=
945 TXREQ_FLAGS_IOVEC_LAST_PKT;
946 }
947 goto free_txreq; 958 goto free_txreq;
948 } 959 }
949 iov_offset += len; 960 iov_offset += len;
@@ -951,19 +962,10 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
951 data_sent += len; 962 data_sent += len;
952 if (unlikely(queued < datalen && 963 if (unlikely(queued < datalen &&
953 pageidx == iovec->npages && 964 pageidx == iovec->npages &&
954 req->iov_idx < req->data_iovs - 1 && 965 req->iov_idx < req->data_iovs - 1)) {
955 tx->idx < ARRAY_SIZE(tx->iovecs))) {
956 iovec->offset += iov_offset; 966 iovec->offset += iov_offset;
957 tx->iovecs[tx->idx].flags |=
958 TXREQ_FLAGS_IOVEC_LAST_PKT;
959 iovec = &req->iovs[++req->iov_idx]; 967 iovec = &req->iovs[++req->iov_idx];
960 if (!iovec->pages) {
961 ret = pin_vector_pages(req, iovec);
962 if (ret)
963 goto free_txreq;
964 }
965 iov_offset = 0; 968 iov_offset = 0;
966 tx->iovecs[++tx->idx].vec = iovec;
967 } 969 }
968 } 970 }
969 /* 971 /*
@@ -974,28 +976,21 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
974 if (req_opcode(req->info.ctrl) == EXPECTED) 976 if (req_opcode(req->info.ctrl) == EXPECTED)
975 req->tidoffset += datalen; 977 req->tidoffset += datalen;
976 req->sent += data_sent; 978 req->sent += data_sent;
977 if (req->data_len) { 979 if (req->data_len)
978 tx->iovecs[tx->idx].vec->offset += iov_offset; 980 iovec->offset += iov_offset;
979 /* If we've reached the end of the io vector, mark it 981 list_add_tail(&tx->txreq.list, &req->txps);
980 * so the callback can unpin the pages and free it. */
981 if (tx->iovecs[tx->idx].vec->offset ==
982 tx->iovecs[tx->idx].vec->iov.iov_len)
983 tx->iovecs[tx->idx].flags |=
984 TXREQ_FLAGS_IOVEC_LAST_PKT;
985 }
986
987 /* 982 /*
988 * It is important to increment this here as it is used to 983 * It is important to increment this here as it is used to
989 * generate the BTH.PSN and, therefore, can't be bulk-updated 984 * generate the BTH.PSN and, therefore, can't be bulk-updated
990 * outside of the loop. 985 * outside of the loop.
991 */ 986 */
992 tx->seqnum = req->seqnum++; 987 tx->seqnum = req->seqnum++;
993 list_add_tail(&tx->txreq.list, &req->txps);
994 npkts++; 988 npkts++;
995 } 989 }
996dosend: 990dosend:
997 ret = sdma_send_txlist(req->sde, &pq->busy, &req->txps); 991 ret = sdma_send_txlist(req->sde, &pq->busy, &req->txps);
998 if (list_empty(&req->txps)) 992 if (list_empty(&req->txps)) {
993 req->seqsubmitted = req->seqnum;
999 if (req->seqnum == req->info.npkts) { 994 if (req->seqnum == req->info.npkts) {
1000 set_bit(SDMA_REQ_SEND_DONE, &req->flags); 995 set_bit(SDMA_REQ_SEND_DONE, &req->flags);
1001 /* 996 /*
@@ -1007,6 +1002,10 @@ dosend:
1007 if (test_bit(SDMA_REQ_HAVE_AHG, &req->flags)) 1002 if (test_bit(SDMA_REQ_HAVE_AHG, &req->flags))
1008 sdma_ahg_free(req->sde, req->ahg_idx); 1003 sdma_ahg_free(req->sde, req->ahg_idx);
1009 } 1004 }
1005 } else if (ret > 0) {
1006 req->seqsubmitted += ret;
1007 ret = 0;
1008 }
1010 return ret; 1009 return ret;
1011 1010
1012free_txreq: 1011free_txreq:
@@ -1021,7 +1020,7 @@ free_tx:
1021 */ 1020 */
1022static inline int num_user_pages(const struct iovec *iov) 1021static inline int num_user_pages(const struct iovec *iov)
1023{ 1022{
1024 const unsigned long addr = (unsigned long) iov->iov_base; 1023 const unsigned long addr = (unsigned long)iov->iov_base;
1025 const unsigned long len = iov->iov_len; 1024 const unsigned long len = iov->iov_len;
1026 const unsigned long spage = addr & PAGE_MASK; 1025 const unsigned long spage = addr & PAGE_MASK;
1027 const unsigned long epage = (addr + len - 1) & PAGE_MASK; 1026 const unsigned long epage = (addr + len - 1) & PAGE_MASK;
@@ -1029,64 +1028,129 @@ static inline int num_user_pages(const struct iovec *iov)
1029 return 1 + ((epage - spage) >> PAGE_SHIFT); 1028 return 1 + ((epage - spage) >> PAGE_SHIFT);
1030} 1029}
1031 1030
1032static int pin_vector_pages(struct user_sdma_request *req, 1031/* Caller must hold pq->evict_lock */
1033 struct user_sdma_iovec *iovec) { 1032static u32 sdma_cache_evict(struct hfi1_user_sdma_pkt_q *pq, u32 npages)
1034 int pinned, npages; 1033{
1034 u32 cleared = 0;
1035 struct sdma_mmu_node *node, *ptr;
1035 1036
1036 npages = num_user_pages(&iovec->iov); 1037 list_for_each_entry_safe_reverse(node, ptr, &pq->evict, list) {
1037 iovec->pages = kcalloc(npages, sizeof(*iovec->pages), GFP_KERNEL); 1038 /* Make sure that no one is still using the node. */
1038 if (!iovec->pages) { 1039 if (!atomic_read(&node->refcount)) {
1039 SDMA_DBG(req, "Failed page array alloc"); 1040 /*
1040 return -ENOMEM; 1041 * Need to use the page count now as the remove callback
1042 * will free the node.
1043 */
1044 cleared += node->npages;
1045 spin_unlock(&pq->evict_lock);
1046 hfi1_mmu_rb_remove(&pq->sdma_rb_root, &node->rb);
1047 spin_lock(&pq->evict_lock);
1048 if (cleared >= npages)
1049 break;
1050 }
1041 } 1051 }
1052 return cleared;
1053}
1042 1054
1043 /* 1055static int pin_vector_pages(struct user_sdma_request *req,
1044 * Get a reference to the process's mm so we can use it when 1056 struct user_sdma_iovec *iovec) {
1045 * unpinning the io vectors. 1057 int ret = 0, pinned, npages, cleared;
1046 */ 1058 struct page **pages;
1047 req->pq->user_mm = get_task_mm(current); 1059 struct hfi1_user_sdma_pkt_q *pq = req->pq;
1060 struct sdma_mmu_node *node = NULL;
1061 struct mmu_rb_node *rb_node;
1062
1063 rb_node = hfi1_mmu_rb_search(&pq->sdma_rb_root,
1064 (unsigned long)iovec->iov.iov_base,
1065 iovec->iov.iov_len);
1066 if (rb_node)
1067 node = container_of(rb_node, struct sdma_mmu_node, rb);
1068
1069 if (!node) {
1070 node = kzalloc(sizeof(*node), GFP_KERNEL);
1071 if (!node)
1072 return -ENOMEM;
1048 1073
1049 pinned = hfi1_acquire_user_pages((unsigned long)iovec->iov.iov_base, 1074 node->rb.addr = (unsigned long)iovec->iov.iov_base;
1050 npages, 0, iovec->pages); 1075 node->rb.len = iovec->iov.iov_len;
1076 node->pq = pq;
1077 atomic_set(&node->refcount, 0);
1078 INIT_LIST_HEAD(&node->list);
1079 }
1051 1080
1052 if (pinned < 0) 1081 npages = num_user_pages(&iovec->iov);
1053 return pinned; 1082 if (node->npages < npages) {
1083 pages = kcalloc(npages, sizeof(*pages), GFP_KERNEL);
1084 if (!pages) {
1085 SDMA_DBG(req, "Failed page array alloc");
1086 ret = -ENOMEM;
1087 goto bail;
1088 }
1089 memcpy(pages, node->pages, node->npages * sizeof(*pages));
1090
1091 npages -= node->npages;
1092retry:
1093 if (!hfi1_can_pin_pages(pq->dd, pq->n_locked, npages)) {
1094 spin_lock(&pq->evict_lock);
1095 cleared = sdma_cache_evict(pq, npages);
1096 spin_unlock(&pq->evict_lock);
1097 if (cleared >= npages)
1098 goto retry;
1099 }
1100 pinned = hfi1_acquire_user_pages(
1101 ((unsigned long)iovec->iov.iov_base +
1102 (node->npages * PAGE_SIZE)), npages, 0,
1103 pages + node->npages);
1104 if (pinned < 0) {
1105 kfree(pages);
1106 ret = pinned;
1107 goto bail;
1108 }
1109 if (pinned != npages) {
1110 unpin_vector_pages(current->mm, pages, pinned);
1111 ret = -EFAULT;
1112 goto bail;
1113 }
1114 kfree(node->pages);
1115 node->pages = pages;
1116 node->npages += pinned;
1117 npages = node->npages;
1118 spin_lock(&pq->evict_lock);
1119 if (!rb_node)
1120 list_add(&node->list, &pq->evict);
1121 else
1122 list_move(&node->list, &pq->evict);
1123 pq->n_locked += pinned;
1124 spin_unlock(&pq->evict_lock);
1125 }
1126 iovec->pages = node->pages;
1127 iovec->npages = npages;
1054 1128
1055 iovec->npages = pinned; 1129 if (!rb_node) {
1056 if (pinned != npages) { 1130 ret = hfi1_mmu_rb_insert(&req->pq->sdma_rb_root, &node->rb);
1057 SDMA_DBG(req, "Failed to pin pages (%d/%u)", pinned, npages); 1131 if (ret) {
1058 unpin_vector_pages(req, iovec); 1132 spin_lock(&pq->evict_lock);
1059 return -EFAULT; 1133 list_del(&node->list);
1134 pq->n_locked -= node->npages;
1135 spin_unlock(&pq->evict_lock);
1136 ret = 0;
1137 goto bail;
1138 }
1139 } else {
1140 atomic_inc(&node->refcount);
1060 } 1141 }
1061 return 0; 1142 return 0;
1143bail:
1144 if (!rb_node)
1145 kfree(node);
1146 return ret;
1062} 1147}
1063 1148
1064static void unpin_vector_pages(struct user_sdma_request *req, 1149static void unpin_vector_pages(struct mm_struct *mm, struct page **pages,
1065 struct user_sdma_iovec *iovec) 1150 unsigned npages)
1066{ 1151{
1067 /* 1152 hfi1_release_user_pages(mm, pages, npages, 0);
1068 * Unpinning is done through the workqueue so use the 1153 kfree(pages);
1069 * process's mm if we have a reference to it.
1070 */
1071 if ((current->flags & PF_KTHREAD) && req->pq->user_mm)
1072 use_mm(req->pq->user_mm);
1073
1074 hfi1_release_user_pages(iovec->pages, iovec->npages, 0);
1075
1076 /*
1077 * Unuse the user's mm (see above) and release the
1078 * reference to it.
1079 */
1080 if (req->pq->user_mm) {
1081 if (current->flags & PF_KTHREAD)
1082 unuse_mm(req->pq->user_mm);
1083 mmput(req->pq->user_mm);
1084 }
1085
1086 kfree(iovec->pages);
1087 iovec->pages = NULL;
1088 iovec->npages = 0;
1089 iovec->offset = 0;
1090} 1154}
1091 1155
1092static int check_header_template(struct user_sdma_request *req, 1156static int check_header_template(struct user_sdma_request *req,
@@ -1209,7 +1273,6 @@ static int set_txreq_header(struct user_sdma_request *req,
1209 if (ret) 1273 if (ret)
1210 return ret; 1274 return ret;
1211 goto done; 1275 goto done;
1212
1213 } 1276 }
1214 1277
1215 hdr->bth[2] = cpu_to_be32( 1278 hdr->bth[2] = cpu_to_be32(
@@ -1219,7 +1282,7 @@ static int set_txreq_header(struct user_sdma_request *req,
1219 1282
1220 /* Set ACK request on last packet */ 1283 /* Set ACK request on last packet */
1221 if (unlikely(tx->flags & TXREQ_FLAGS_REQ_LAST_PKT)) 1284 if (unlikely(tx->flags & TXREQ_FLAGS_REQ_LAST_PKT))
1222 hdr->bth[2] |= cpu_to_be32(1UL<<31); 1285 hdr->bth[2] |= cpu_to_be32(1UL << 31);
1223 1286
1224 /* Set the new offset */ 1287 /* Set the new offset */
1225 hdr->kdeth.swdata[6] = cpu_to_le32(req->koffset); 1288 hdr->kdeth.swdata[6] = cpu_to_le32(req->koffset);
@@ -1233,8 +1296,10 @@ static int set_txreq_header(struct user_sdma_request *req,
1233 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) * 1296 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) *
1234 PAGE_SIZE)) { 1297 PAGE_SIZE)) {
1235 req->tidoffset = 0; 1298 req->tidoffset = 0;
1236 /* Since we don't copy all the TIDs, all at once, 1299 /*
1237 * we have to check again. */ 1300 * Since we don't copy all the TIDs, all at once,
1301 * we have to check again.
1302 */
1238 if (++req->tididx > req->n_tids - 1 || 1303 if (++req->tididx > req->n_tids - 1 ||
1239 !req->tids[req->tididx]) { 1304 !req->tids[req->tididx]) {
1240 return -EINVAL; 1305 return -EINVAL;
@@ -1315,8 +1380,10 @@ static int set_txreq_header_ahg(struct user_sdma_request *req,
1315 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) * 1380 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) *
1316 PAGE_SIZE)) { 1381 PAGE_SIZE)) {
1317 req->tidoffset = 0; 1382 req->tidoffset = 0;
1318 /* Since we don't copy all the TIDs, all at once, 1383 /*
1319 * we have to check again. */ 1384 * Since we don't copy all the TIDs, all at once,
1385 * we have to check again.
1386 */
1320 if (++req->tididx > req->n_tids - 1 || 1387 if (++req->tididx > req->n_tids - 1 ||
1321 !req->tids[req->tididx]) { 1388 !req->tids[req->tididx]) {
1322 return -EINVAL; 1389 return -EINVAL;
@@ -1340,8 +1407,9 @@ static int set_txreq_header_ahg(struct user_sdma_request *req,
1340 INTR) >> 16); 1407 INTR) >> 16);
1341 val &= cpu_to_le16(~(1U << 13)); 1408 val &= cpu_to_le16(~(1U << 13));
1342 AHG_HEADER_SET(req->ahg, diff, 7, 16, 14, val); 1409 AHG_HEADER_SET(req->ahg, diff, 7, 16, 14, val);
1343 } else 1410 } else {
1344 AHG_HEADER_SET(req->ahg, diff, 7, 16, 12, val); 1411 AHG_HEADER_SET(req->ahg, diff, 7, 16, 12, val);
1412 }
1345 } 1413 }
1346 1414
1347 trace_hfi1_sdma_user_header_ahg(pq->dd, pq->ctxt, pq->subctxt, 1415 trace_hfi1_sdma_user_header_ahg(pq->dd, pq->ctxt, pq->subctxt,
@@ -1356,113 +1424,62 @@ static int set_txreq_header_ahg(struct user_sdma_request *req,
1356 * tx request have been processed by the DMA engine. Called in 1424 * tx request have been processed by the DMA engine. Called in
1357 * interrupt context. 1425 * interrupt context.
1358 */ 1426 */
1359static void user_sdma_txreq_cb(struct sdma_txreq *txreq, int status, 1427static void user_sdma_txreq_cb(struct sdma_txreq *txreq, int status)
1360 int drain)
1361{ 1428{
1362 struct user_sdma_txreq *tx = 1429 struct user_sdma_txreq *tx =
1363 container_of(txreq, struct user_sdma_txreq, txreq); 1430 container_of(txreq, struct user_sdma_txreq, txreq);
1364 struct user_sdma_request *req; 1431 struct user_sdma_request *req;
1365 bool defer; 1432 struct hfi1_user_sdma_pkt_q *pq;
1366 int i; 1433 struct hfi1_user_sdma_comp_q *cq;
1434 u16 idx;
1367 1435
1368 if (!tx->req) 1436 if (!tx->req)
1369 return; 1437 return;
1370 1438
1371 req = tx->req; 1439 req = tx->req;
1372 /* 1440 pq = req->pq;
1373 * If this is the callback for the last packet of the request, 1441 cq = req->cq;
1374 * queue up the request for clean up.
1375 */
1376 defer = (tx->seqnum == req->info.npkts - 1);
1377
1378 /*
1379 * If we have any io vectors associated with this txreq,
1380 * check whether they need to be 'freed'. We can't free them
1381 * here because the unpin function needs to be able to sleep.
1382 */
1383 for (i = tx->idx; i >= 0; i--) {
1384 if (tx->iovecs[i].flags & TXREQ_FLAGS_IOVEC_LAST_PKT) {
1385 defer = true;
1386 break;
1387 }
1388 }
1389 1442
1390 req->status = status;
1391 if (status != SDMA_TXREQ_S_OK) { 1443 if (status != SDMA_TXREQ_S_OK) {
1392 SDMA_DBG(req, "SDMA completion with error %d", 1444 SDMA_DBG(req, "SDMA completion with error %d",
1393 status); 1445 status);
1394 set_bit(SDMA_REQ_HAS_ERROR, &req->flags); 1446 set_bit(SDMA_REQ_HAS_ERROR, &req->flags);
1395 defer = true;
1396 } 1447 }
1397 1448
1398 /* 1449 req->seqcomp = tx->seqnum;
1399 * Defer the clean up of the iovectors and the request until later 1450 kmem_cache_free(pq->txreq_cache, tx);
1400 * so it can be done outside of interrupt context. 1451 tx = NULL;
1401 */ 1452
1402 if (defer) { 1453 idx = req->info.comp_idx;
1403 spin_lock(&req->txcmp_lock); 1454 if (req->status == -1 && status == SDMA_TXREQ_S_OK) {
1404 list_add_tail(&tx->list, &req->txcmp); 1455 if (req->seqcomp == req->info.npkts - 1) {
1405 spin_unlock(&req->txcmp_lock); 1456 req->status = 0;
1406 schedule_work(&req->worker); 1457 user_sdma_free_request(req, false);
1458 pq_update(pq);
1459 set_comp_state(pq, cq, idx, COMPLETE, 0);
1460 }
1407 } else { 1461 } else {
1408 kmem_cache_free(req->pq->txreq_cache, tx); 1462 if (status != SDMA_TXREQ_S_OK)
1463 req->status = status;
1464 if (req->seqcomp == (ACCESS_ONCE(req->seqsubmitted) - 1) &&
1465 (test_bit(SDMA_REQ_SEND_DONE, &req->flags) ||
1466 test_bit(SDMA_REQ_DONE_ERROR, &req->flags))) {
1467 user_sdma_free_request(req, false);
1468 pq_update(pq);
1469 set_comp_state(pq, cq, idx, ERROR, req->status);
1470 }
1409 } 1471 }
1410} 1472}
1411 1473
1412static void user_sdma_delayed_completion(struct work_struct *work) 1474static inline void pq_update(struct hfi1_user_sdma_pkt_q *pq)
1413{ 1475{
1414 struct user_sdma_request *req = 1476 if (atomic_dec_and_test(&pq->n_reqs)) {
1415 container_of(work, struct user_sdma_request, worker);
1416 struct hfi1_user_sdma_pkt_q *pq = req->pq;
1417 struct user_sdma_txreq *tx = NULL;
1418 unsigned long flags;
1419 u64 seqnum;
1420 int i;
1421
1422 while (1) {
1423 spin_lock_irqsave(&req->txcmp_lock, flags);
1424 if (!list_empty(&req->txcmp)) {
1425 tx = list_first_entry(&req->txcmp,
1426 struct user_sdma_txreq, list);
1427 list_del(&tx->list);
1428 }
1429 spin_unlock_irqrestore(&req->txcmp_lock, flags);
1430 if (!tx)
1431 break;
1432
1433 for (i = tx->idx; i >= 0; i--)
1434 if (tx->iovecs[i].flags & TXREQ_FLAGS_IOVEC_LAST_PKT)
1435 unpin_vector_pages(req, tx->iovecs[i].vec);
1436
1437 seqnum = tx->seqnum;
1438 kmem_cache_free(pq->txreq_cache, tx);
1439 tx = NULL;
1440
1441 if (req->status != SDMA_TXREQ_S_OK) {
1442 if (seqnum == ACCESS_ONCE(req->seqnum) &&
1443 test_bit(SDMA_REQ_DONE_ERROR, &req->flags)) {
1444 atomic_dec(&pq->n_reqs);
1445 set_comp_state(req, ERROR, req->status);
1446 user_sdma_free_request(req);
1447 break;
1448 }
1449 } else {
1450 if (seqnum == req->info.npkts - 1) {
1451 atomic_dec(&pq->n_reqs);
1452 set_comp_state(req, COMPLETE, 0);
1453 user_sdma_free_request(req);
1454 break;
1455 }
1456 }
1457 }
1458
1459 if (!atomic_read(&pq->n_reqs)) {
1460 xchg(&pq->state, SDMA_PKT_Q_INACTIVE); 1477 xchg(&pq->state, SDMA_PKT_Q_INACTIVE);
1461 wake_up(&pq->wait); 1478 wake_up(&pq->wait);
1462 } 1479 }
1463} 1480}
1464 1481
1465static void user_sdma_free_request(struct user_sdma_request *req) 1482static void user_sdma_free_request(struct user_sdma_request *req, bool unpin)
1466{ 1483{
1467 if (!list_empty(&req->txps)) { 1484 if (!list_empty(&req->txps)) {
1468 struct sdma_txreq *t, *p; 1485 struct sdma_txreq *t, *p;
@@ -1476,25 +1493,87 @@ static void user_sdma_free_request(struct user_sdma_request *req)
1476 } 1493 }
1477 } 1494 }
1478 if (req->data_iovs) { 1495 if (req->data_iovs) {
1496 struct sdma_mmu_node *node;
1497 struct mmu_rb_node *mnode;
1479 int i; 1498 int i;
1480 1499
1481 for (i = 0; i < req->data_iovs; i++) 1500 for (i = 0; i < req->data_iovs; i++) {
1482 if (req->iovs[i].npages && req->iovs[i].pages) 1501 mnode = hfi1_mmu_rb_search(
1483 unpin_vector_pages(req, &req->iovs[i]); 1502 &req->pq->sdma_rb_root,
1503 (unsigned long)req->iovs[i].iov.iov_base,
1504 req->iovs[i].iov.iov_len);
1505 if (!mnode)
1506 continue;
1507
1508 node = container_of(mnode, struct sdma_mmu_node, rb);
1509 if (unpin)
1510 hfi1_mmu_rb_remove(&req->pq->sdma_rb_root,
1511 &node->rb);
1512 else
1513 atomic_dec(&node->refcount);
1514 }
1484 } 1515 }
1485 kfree(req->tids); 1516 kfree(req->tids);
1486 clear_bit(SDMA_REQ_IN_USE, &req->flags); 1517 clear_bit(SDMA_REQ_IN_USE, &req->flags);
1487} 1518}
1488 1519
1489static inline void set_comp_state(struct user_sdma_request *req, 1520static inline void set_comp_state(struct hfi1_user_sdma_pkt_q *pq,
1490 enum hfi1_sdma_comp_state state, 1521 struct hfi1_user_sdma_comp_q *cq,
1491 int ret) 1522 u16 idx, enum hfi1_sdma_comp_state state,
1523 int ret)
1492{ 1524{
1493 SDMA_DBG(req, "Setting completion status %u %d", state, ret); 1525 hfi1_cdbg(SDMA, "[%u:%u:%u:%u] Setting completion status %u %d",
1494 req->cq->comps[req->info.comp_idx].status = state; 1526 pq->dd->unit, pq->ctxt, pq->subctxt, idx, state, ret);
1527 cq->comps[idx].status = state;
1495 if (state == ERROR) 1528 if (state == ERROR)
1496 req->cq->comps[req->info.comp_idx].errcode = -ret; 1529 cq->comps[idx].errcode = -ret;
1497 trace_hfi1_sdma_user_completion(req->pq->dd, req->pq->ctxt, 1530 trace_hfi1_sdma_user_completion(pq->dd, pq->ctxt, pq->subctxt,
1498 req->pq->subctxt, req->info.comp_idx, 1531 idx, state, ret);
1499 state, ret); 1532}
1533
1534static bool sdma_rb_filter(struct mmu_rb_node *node, unsigned long addr,
1535 unsigned long len)
1536{
1537 return (bool)(node->addr == addr);
1538}
1539
1540static int sdma_rb_insert(struct rb_root *root, struct mmu_rb_node *mnode)
1541{
1542 struct sdma_mmu_node *node =
1543 container_of(mnode, struct sdma_mmu_node, rb);
1544
1545 atomic_inc(&node->refcount);
1546 return 0;
1547}
1548
1549static void sdma_rb_remove(struct rb_root *root, struct mmu_rb_node *mnode,
1550 bool notifier)
1551{
1552 struct sdma_mmu_node *node =
1553 container_of(mnode, struct sdma_mmu_node, rb);
1554
1555 spin_lock(&node->pq->evict_lock);
1556 list_del(&node->list);
1557 node->pq->n_locked -= node->npages;
1558 spin_unlock(&node->pq->evict_lock);
1559
1560 unpin_vector_pages(notifier ? NULL : current->mm, node->pages,
1561 node->npages);
1562 /*
1563 * If called by the MMU notifier, we have to adjust the pinned
1564 * page count ourselves.
1565 */
1566 if (notifier)
1567 current->mm->pinned_vm -= node->npages;
1568 kfree(node);
1569}
1570
1571static int sdma_rb_invalidate(struct rb_root *root, struct mmu_rb_node *mnode)
1572{
1573 struct sdma_mmu_node *node =
1574 container_of(mnode, struct sdma_mmu_node, rb);
1575
1576 if (!atomic_read(&node->refcount))
1577 return 1;
1578 return 0;
1500} 1579}
diff --git a/drivers/staging/rdma/hfi1/user_sdma.h b/drivers/staging/rdma/hfi1/user_sdma.h
index 0afa28508a8a..b9240e351161 100644
--- a/drivers/staging/rdma/hfi1/user_sdma.h
+++ b/drivers/staging/rdma/hfi1/user_sdma.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -69,7 +66,11 @@ struct hfi1_user_sdma_pkt_q {
69 struct iowait busy; 66 struct iowait busy;
70 unsigned state; 67 unsigned state;
71 wait_queue_head_t wait; 68 wait_queue_head_t wait;
72 struct mm_struct *user_mm; 69 unsigned long unpinned;
70 struct rb_root sdma_rb_root;
71 u32 n_locked;
72 struct list_head evict;
73 spinlock_t evict_lock; /* protect evict and n_locked */
73}; 74};
74 75
75struct hfi1_user_sdma_comp_q { 76struct hfi1_user_sdma_comp_q {
diff --git a/drivers/staging/rdma/hfi1/verbs.c b/drivers/staging/rdma/hfi1/verbs.c
index 176168614b5a..89f2aad45c1b 100644
--- a/drivers/staging/rdma/hfi1/verbs.c
+++ b/drivers/staging/rdma/hfi1/verbs.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -63,9 +60,9 @@
63#include "device.h" 60#include "device.h"
64#include "trace.h" 61#include "trace.h"
65#include "qp.h" 62#include "qp.h"
66#include "sdma.h" 63#include "verbs_txreq.h"
67 64
68unsigned int hfi1_lkey_table_size = 16; 65static unsigned int hfi1_lkey_table_size = 16;
69module_param_named(lkey_table_size, hfi1_lkey_table_size, uint, 66module_param_named(lkey_table_size, hfi1_lkey_table_size, uint,
70 S_IRUGO); 67 S_IRUGO);
71MODULE_PARM_DESC(lkey_table_size, 68MODULE_PARM_DESC(lkey_table_size,
@@ -124,45 +121,181 @@ unsigned int hfi1_max_srq_wrs = 0x1FFFF;
124module_param_named(max_srq_wrs, hfi1_max_srq_wrs, uint, S_IRUGO); 121module_param_named(max_srq_wrs, hfi1_max_srq_wrs, uint, S_IRUGO);
125MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support"); 122MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
126 123
124unsigned short piothreshold = 256;
125module_param(piothreshold, ushort, S_IRUGO);
126MODULE_PARM_DESC(piothreshold, "size used to determine sdma vs. pio");
127
128#define COPY_CACHELESS 1
129#define COPY_ADAPTIVE 2
130static unsigned int sge_copy_mode;
131module_param(sge_copy_mode, uint, S_IRUGO);
132MODULE_PARM_DESC(sge_copy_mode,
133 "Verbs copy mode: 0 use memcpy, 1 use cacheless copy, 2 adapt based on WSS");
134
127static void verbs_sdma_complete( 135static void verbs_sdma_complete(
128 struct sdma_txreq *cookie, 136 struct sdma_txreq *cookie,
129 int status, 137 int status);
130 int drained); 138
139static int pio_wait(struct rvt_qp *qp,
140 struct send_context *sc,
141 struct hfi1_pkt_state *ps,
142 u32 flag);
131 143
132/* Length of buffer to create verbs txreq cache name */ 144/* Length of buffer to create verbs txreq cache name */
133#define TXREQ_NAME_LEN 24 145#define TXREQ_NAME_LEN 24
134 146
147static uint wss_threshold;
148module_param(wss_threshold, uint, S_IRUGO);
149MODULE_PARM_DESC(wss_threshold, "Percentage (1-100) of LLC to use as a threshold for a cacheless copy");
150static uint wss_clean_period = 256;
151module_param(wss_clean_period, uint, S_IRUGO);
152MODULE_PARM_DESC(wss_clean_period, "Count of verbs copies before an entry in the page copy table is cleaned");
153
154/* memory working set size */
155struct hfi1_wss {
156 unsigned long *entries;
157 atomic_t total_count;
158 atomic_t clean_counter;
159 atomic_t clean_entry;
160
161 int threshold;
162 int num_entries;
163 long pages_mask;
164};
165
166static struct hfi1_wss wss;
167
168int hfi1_wss_init(void)
169{
170 long llc_size;
171 long llc_bits;
172 long table_size;
173 long table_bits;
174
175 /* check for a valid percent range - default to 80 if none or invalid */
176 if (wss_threshold < 1 || wss_threshold > 100)
177 wss_threshold = 80;
178 /* reject a wildly large period */
179 if (wss_clean_period > 1000000)
180 wss_clean_period = 256;
181 /* reject a zero period */
182 if (wss_clean_period == 0)
183 wss_clean_period = 1;
184
185 /*
186 * Calculate the table size - the next power of 2 larger than the
187 * LLC size. LLC size is in KiB.
188 */
189 llc_size = wss_llc_size() * 1024;
190 table_size = roundup_pow_of_two(llc_size);
191
192 /* one bit per page in rounded up table */
193 llc_bits = llc_size / PAGE_SIZE;
194 table_bits = table_size / PAGE_SIZE;
195 wss.pages_mask = table_bits - 1;
196 wss.num_entries = table_bits / BITS_PER_LONG;
197
198 wss.threshold = (llc_bits * wss_threshold) / 100;
199 if (wss.threshold == 0)
200 wss.threshold = 1;
201
202 atomic_set(&wss.clean_counter, wss_clean_period);
203
204 wss.entries = kcalloc(wss.num_entries, sizeof(*wss.entries),
205 GFP_KERNEL);
206 if (!wss.entries) {
207 hfi1_wss_exit();
208 return -ENOMEM;
209 }
210
211 return 0;
212}
213
214void hfi1_wss_exit(void)
215{
216 /* coded to handle partially initialized and repeat callers */
217 kfree(wss.entries);
218 wss.entries = NULL;
219}
220
135/* 221/*
136 * Note that it is OK to post send work requests in the SQE and ERR 222 * Advance the clean counter. When the clean period has expired,
137 * states; hfi1_do_send() will process them and generate error 223 * clean an entry.
138 * completions as per IB 1.2 C10-96. 224 *
225 * This is implemented in atomics to avoid locking. Because multiple
226 * variables are involved, it can be racy which can lead to slightly
227 * inaccurate information. Since this is only a heuristic, this is
228 * OK. Any innaccuracies will clean themselves out as the counter
229 * advances. That said, it is unlikely the entry clean operation will
230 * race - the next possible racer will not start until the next clean
231 * period.
232 *
233 * The clean counter is implemented as a decrement to zero. When zero
234 * is reached an entry is cleaned.
139 */ 235 */
140const int ib_hfi1_state_ops[IB_QPS_ERR + 1] = { 236static void wss_advance_clean_counter(void)
141 [IB_QPS_RESET] = 0, 237{
142 [IB_QPS_INIT] = HFI1_POST_RECV_OK, 238 int entry;
143 [IB_QPS_RTR] = HFI1_POST_RECV_OK | HFI1_PROCESS_RECV_OK, 239 int weight;
144 [IB_QPS_RTS] = HFI1_POST_RECV_OK | HFI1_PROCESS_RECV_OK | 240 unsigned long bits;
145 HFI1_POST_SEND_OK | HFI1_PROCESS_SEND_OK |
146 HFI1_PROCESS_NEXT_SEND_OK,
147 [IB_QPS_SQD] = HFI1_POST_RECV_OK | HFI1_PROCESS_RECV_OK |
148 HFI1_POST_SEND_OK | HFI1_PROCESS_SEND_OK,
149 [IB_QPS_SQE] = HFI1_POST_RECV_OK | HFI1_PROCESS_RECV_OK |
150 HFI1_POST_SEND_OK | HFI1_FLUSH_SEND,
151 [IB_QPS_ERR] = HFI1_POST_RECV_OK | HFI1_FLUSH_RECV |
152 HFI1_POST_SEND_OK | HFI1_FLUSH_SEND,
153};
154 241
155struct hfi1_ucontext { 242 /* become the cleaner if we decrement the counter to zero */
156 struct ib_ucontext ibucontext; 243 if (atomic_dec_and_test(&wss.clean_counter)) {
157}; 244 /*
245 * Set, not add, the clean period. This avoids an issue
246 * where the counter could decrement below the clean period.
247 * Doing a set can result in lost decrements, slowing the
248 * clean advance. Since this a heuristic, this possible
249 * slowdown is OK.
250 *
251 * An alternative is to loop, advancing the counter by a
252 * clean period until the result is > 0. However, this could
253 * lead to several threads keeping another in the clean loop.
254 * This could be mitigated by limiting the number of times
255 * we stay in the loop.
256 */
257 atomic_set(&wss.clean_counter, wss_clean_period);
158 258
159static inline struct hfi1_ucontext *to_iucontext(struct ib_ucontext 259 /*
160 *ibucontext) 260 * Uniquely grab the entry to clean and move to next.
261 * The current entry is always the lower bits of
262 * wss.clean_entry. The table size, wss.num_entries,
263 * is always a power-of-2.
264 */
265 entry = (atomic_inc_return(&wss.clean_entry) - 1)
266 & (wss.num_entries - 1);
267
268 /* clear the entry and count the bits */
269 bits = xchg(&wss.entries[entry], 0);
270 weight = hweight64((u64)bits);
271 /* only adjust the contended total count if needed */
272 if (weight)
273 atomic_sub(weight, &wss.total_count);
274 }
275}
276
277/*
278 * Insert the given address into the working set array.
279 */
280static void wss_insert(void *address)
161{ 281{
162 return container_of(ibucontext, struct hfi1_ucontext, ibucontext); 282 u32 page = ((unsigned long)address >> PAGE_SHIFT) & wss.pages_mask;
283 u32 entry = page / BITS_PER_LONG; /* assumes this ends up a shift */
284 u32 nr = page & (BITS_PER_LONG - 1);
285
286 if (!test_and_set_bit(nr, &wss.entries[entry]))
287 atomic_inc(&wss.total_count);
288
289 wss_advance_clean_counter();
163} 290}
164 291
165static inline void _hfi1_schedule_send(struct hfi1_qp *qp); 292/*
293 * Is the working set larger than the threshold?
294 */
295static inline int wss_exceeds_threshold(void)
296{
297 return atomic_read(&wss.total_count) >= wss.threshold;
298}
166 299
167/* 300/*
168 * Translate ib_wr_opcode into ib_wc_opcode. 301 * Translate ib_wr_opcode into ib_wc_opcode.
@@ -274,14 +407,47 @@ __be64 ib_hfi1_sys_image_guid;
274 * @ss: the SGE state 407 * @ss: the SGE state
275 * @data: the data to copy 408 * @data: the data to copy
276 * @length: the length of the data 409 * @length: the length of the data
410 * @copy_last: do a separate copy of the last 8 bytes
277 */ 411 */
278void hfi1_copy_sge( 412void hfi1_copy_sge(
279 struct hfi1_sge_state *ss, 413 struct rvt_sge_state *ss,
280 void *data, u32 length, 414 void *data, u32 length,
281 int release) 415 int release,
416 int copy_last)
282{ 417{
283 struct hfi1_sge *sge = &ss->sge; 418 struct rvt_sge *sge = &ss->sge;
419 int in_last = 0;
420 int i;
421 int cacheless_copy = 0;
422
423 if (sge_copy_mode == COPY_CACHELESS) {
424 cacheless_copy = length >= PAGE_SIZE;
425 } else if (sge_copy_mode == COPY_ADAPTIVE) {
426 if (length >= PAGE_SIZE) {
427 /*
428 * NOTE: this *assumes*:
429 * o The first vaddr is the dest.
430 * o If multiple pages, then vaddr is sequential.
431 */
432 wss_insert(sge->vaddr);
433 if (length >= (2 * PAGE_SIZE))
434 wss_insert(sge->vaddr + PAGE_SIZE);
435
436 cacheless_copy = wss_exceeds_threshold();
437 } else {
438 wss_advance_clean_counter();
439 }
440 }
441 if (copy_last) {
442 if (length > 8) {
443 length -= 8;
444 } else {
445 copy_last = 0;
446 in_last = 1;
447 }
448 }
284 449
450again:
285 while (length) { 451 while (length) {
286 u32 len = sge->length; 452 u32 len = sge->length;
287 453
@@ -290,17 +456,25 @@ void hfi1_copy_sge(
290 if (len > sge->sge_length) 456 if (len > sge->sge_length)
291 len = sge->sge_length; 457 len = sge->sge_length;
292 WARN_ON_ONCE(len == 0); 458 WARN_ON_ONCE(len == 0);
293 memcpy(sge->vaddr, data, len); 459 if (unlikely(in_last)) {
460 /* enforce byte transfer ordering */
461 for (i = 0; i < len; i++)
462 ((u8 *)sge->vaddr)[i] = ((u8 *)data)[i];
463 } else if (cacheless_copy) {
464 cacheless_memcpy(sge->vaddr, data, len);
465 } else {
466 memcpy(sge->vaddr, data, len);
467 }
294 sge->vaddr += len; 468 sge->vaddr += len;
295 sge->length -= len; 469 sge->length -= len;
296 sge->sge_length -= len; 470 sge->sge_length -= len;
297 if (sge->sge_length == 0) { 471 if (sge->sge_length == 0) {
298 if (release) 472 if (release)
299 hfi1_put_mr(sge->mr); 473 rvt_put_mr(sge->mr);
300 if (--ss->num_sge) 474 if (--ss->num_sge)
301 *sge = *ss->sg_list++; 475 *sge = *ss->sg_list++;
302 } else if (sge->length == 0 && sge->mr->lkey) { 476 } else if (sge->length == 0 && sge->mr->lkey) {
303 if (++sge->n >= HFI1_SEGSZ) { 477 if (++sge->n >= RVT_SEGSZ) {
304 if (++sge->m >= sge->mr->mapsz) 478 if (++sge->m >= sge->mr->mapsz)
305 break; 479 break;
306 sge->n = 0; 480 sge->n = 0;
@@ -313,6 +487,13 @@ void hfi1_copy_sge(
313 data += len; 487 data += len;
314 length -= len; 488 length -= len;
315 } 489 }
490
491 if (copy_last) {
492 copy_last = 0;
493 in_last = 1;
494 length = 8;
495 goto again;
496 }
316} 497}
317 498
318/** 499/**
@@ -320,9 +501,9 @@ void hfi1_copy_sge(
320 * @ss: the SGE state 501 * @ss: the SGE state
321 * @length: the number of bytes to skip 502 * @length: the number of bytes to skip
322 */ 503 */
323void hfi1_skip_sge(struct hfi1_sge_state *ss, u32 length, int release) 504void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, int release)
324{ 505{
325 struct hfi1_sge *sge = &ss->sge; 506 struct rvt_sge *sge = &ss->sge;
326 507
327 while (length) { 508 while (length) {
328 u32 len = sge->length; 509 u32 len = sge->length;
@@ -337,11 +518,11 @@ void hfi1_skip_sge(struct hfi1_sge_state *ss, u32 length, int release)
337 sge->sge_length -= len; 518 sge->sge_length -= len;
338 if (sge->sge_length == 0) { 519 if (sge->sge_length == 0) {
339 if (release) 520 if (release)
340 hfi1_put_mr(sge->mr); 521 rvt_put_mr(sge->mr);
341 if (--ss->num_sge) 522 if (--ss->num_sge)
342 *sge = *ss->sg_list++; 523 *sge = *ss->sg_list++;
343 } else if (sge->length == 0 && sge->mr->lkey) { 524 } else if (sge->length == 0 && sge->mr->lkey) {
344 if (++sge->n >= HFI1_SEGSZ) { 525 if (++sge->n >= RVT_SEGSZ) {
345 if (++sge->m >= sge->mr->mapsz) 526 if (++sge->m >= sge->mr->mapsz)
346 break; 527 break;
347 sge->n = 0; 528 sge->n = 0;
@@ -355,231 +536,6 @@ void hfi1_skip_sge(struct hfi1_sge_state *ss, u32 length, int release)
355 } 536 }
356} 537}
357 538
358/**
359 * post_one_send - post one RC, UC, or UD send work request
360 * @qp: the QP to post on
361 * @wr: the work request to send
362 */
363static int post_one_send(struct hfi1_qp *qp, struct ib_send_wr *wr)
364{
365 struct hfi1_swqe *wqe;
366 u32 next;
367 int i;
368 int j;
369 int acc;
370 struct hfi1_lkey_table *rkt;
371 struct hfi1_pd *pd;
372 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
373 struct hfi1_pportdata *ppd;
374 struct hfi1_ibport *ibp;
375
376 /* IB spec says that num_sge == 0 is OK. */
377 if (unlikely(wr->num_sge > qp->s_max_sge))
378 return -EINVAL;
379
380 ppd = &dd->pport[qp->port_num - 1];
381 ibp = &ppd->ibport_data;
382
383 /*
384 * Don't allow RDMA reads or atomic operations on UC or
385 * undefined operations.
386 * Make sure buffer is large enough to hold the result for atomics.
387 */
388 if (qp->ibqp.qp_type == IB_QPT_UC) {
389 if ((unsigned) wr->opcode >= IB_WR_RDMA_READ)
390 return -EINVAL;
391 } else if (qp->ibqp.qp_type != IB_QPT_RC) {
392 /* Check IB_QPT_SMI, IB_QPT_GSI, IB_QPT_UD opcode */
393 if (wr->opcode != IB_WR_SEND &&
394 wr->opcode != IB_WR_SEND_WITH_IMM)
395 return -EINVAL;
396 /* Check UD destination address PD */
397 if (qp->ibqp.pd != ud_wr(wr)->ah->pd)
398 return -EINVAL;
399 } else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD)
400 return -EINVAL;
401 else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
402 (wr->num_sge == 0 ||
403 wr->sg_list[0].length < sizeof(u64) ||
404 wr->sg_list[0].addr & (sizeof(u64) - 1)))
405 return -EINVAL;
406 else if (wr->opcode >= IB_WR_RDMA_READ && !qp->s_max_rd_atomic)
407 return -EINVAL;
408
409 next = qp->s_head + 1;
410 if (next >= qp->s_size)
411 next = 0;
412 if (next == qp->s_last)
413 return -ENOMEM;
414
415 rkt = &to_idev(qp->ibqp.device)->lk_table;
416 pd = to_ipd(qp->ibqp.pd);
417 wqe = get_swqe_ptr(qp, qp->s_head);
418
419
420 if (qp->ibqp.qp_type != IB_QPT_UC &&
421 qp->ibqp.qp_type != IB_QPT_RC)
422 memcpy(&wqe->ud_wr, ud_wr(wr), sizeof(wqe->ud_wr));
423 else if (wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
424 wr->opcode == IB_WR_RDMA_WRITE ||
425 wr->opcode == IB_WR_RDMA_READ)
426 memcpy(&wqe->rdma_wr, rdma_wr(wr), sizeof(wqe->rdma_wr));
427 else if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
428 wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD)
429 memcpy(&wqe->atomic_wr, atomic_wr(wr), sizeof(wqe->atomic_wr));
430 else
431 memcpy(&wqe->wr, wr, sizeof(wqe->wr));
432
433 wqe->length = 0;
434 j = 0;
435 if (wr->num_sge) {
436 acc = wr->opcode >= IB_WR_RDMA_READ ?
437 IB_ACCESS_LOCAL_WRITE : 0;
438 for (i = 0; i < wr->num_sge; i++) {
439 u32 length = wr->sg_list[i].length;
440 int ok;
441
442 if (length == 0)
443 continue;
444 ok = hfi1_lkey_ok(rkt, pd, &wqe->sg_list[j],
445 &wr->sg_list[i], acc);
446 if (!ok)
447 goto bail_inval_free;
448 wqe->length += length;
449 j++;
450 }
451 wqe->wr.num_sge = j;
452 }
453 if (qp->ibqp.qp_type == IB_QPT_UC ||
454 qp->ibqp.qp_type == IB_QPT_RC) {
455 if (wqe->length > 0x80000000U)
456 goto bail_inval_free;
457 } else {
458 struct hfi1_ah *ah = to_iah(ud_wr(wr)->ah);
459
460 atomic_inc(&ah->refcount);
461 }
462 wqe->ssn = qp->s_ssn++;
463 qp->s_head = next;
464
465 return 0;
466
467bail_inval_free:
468 /* release mr holds */
469 while (j) {
470 struct hfi1_sge *sge = &wqe->sg_list[--j];
471
472 hfi1_put_mr(sge->mr);
473 }
474 return -EINVAL;
475}
476
477/**
478 * post_send - post a send on a QP
479 * @ibqp: the QP to post the send on
480 * @wr: the list of work requests to post
481 * @bad_wr: the first bad WR is put here
482 *
483 * This may be called from interrupt context.
484 */
485static int post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
486 struct ib_send_wr **bad_wr)
487{
488 struct hfi1_qp *qp = to_iqp(ibqp);
489 int err = 0;
490 int call_send;
491 unsigned long flags;
492 unsigned nreq = 0;
493
494 spin_lock_irqsave(&qp->s_lock, flags);
495
496 /* Check that state is OK to post send. */
497 if (unlikely(!(ib_hfi1_state_ops[qp->state] & HFI1_POST_SEND_OK))) {
498 spin_unlock_irqrestore(&qp->s_lock, flags);
499 return -EINVAL;
500 }
501
502 /* sq empty and not list -> call send */
503 call_send = qp->s_head == qp->s_last && !wr->next;
504
505 for (; wr; wr = wr->next) {
506 err = post_one_send(qp, wr);
507 if (unlikely(err)) {
508 *bad_wr = wr;
509 goto bail;
510 }
511 nreq++;
512 }
513bail:
514 spin_unlock_irqrestore(&qp->s_lock, flags);
515 if (nreq && !call_send)
516 _hfi1_schedule_send(qp);
517 if (nreq && call_send)
518 hfi1_do_send(&qp->s_iowait.iowork);
519 return err;
520}
521
522/**
523 * post_receive - post a receive on a QP
524 * @ibqp: the QP to post the receive on
525 * @wr: the WR to post
526 * @bad_wr: the first bad WR is put here
527 *
528 * This may be called from interrupt context.
529 */
530static int post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
531 struct ib_recv_wr **bad_wr)
532{
533 struct hfi1_qp *qp = to_iqp(ibqp);
534 struct hfi1_rwq *wq = qp->r_rq.wq;
535 unsigned long flags;
536 int ret;
537
538 /* Check that state is OK to post receive. */
539 if (!(ib_hfi1_state_ops[qp->state] & HFI1_POST_RECV_OK) || !wq) {
540 *bad_wr = wr;
541 ret = -EINVAL;
542 goto bail;
543 }
544
545 for (; wr; wr = wr->next) {
546 struct hfi1_rwqe *wqe;
547 u32 next;
548 int i;
549
550 if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
551 *bad_wr = wr;
552 ret = -EINVAL;
553 goto bail;
554 }
555
556 spin_lock_irqsave(&qp->r_rq.lock, flags);
557 next = wq->head + 1;
558 if (next >= qp->r_rq.size)
559 next = 0;
560 if (next == wq->tail) {
561 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
562 *bad_wr = wr;
563 ret = -ENOMEM;
564 goto bail;
565 }
566
567 wqe = get_rwqe_ptr(&qp->r_rq, wq->head);
568 wqe->wr_id = wr->wr_id;
569 wqe->num_sge = wr->num_sge;
570 for (i = 0; i < wr->num_sge; i++)
571 wqe->sg_list[i] = wr->sg_list[i];
572 /* Make sure queue entry is written before the head index. */
573 smp_wmb();
574 wq->head = next;
575 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
576 }
577 ret = 0;
578
579bail:
580 return ret;
581}
582
583/* 539/*
584 * Make sure the QP is ready and able to accept the given opcode. 540 * Make sure the QP is ready and able to accept the given opcode.
585 */ 541 */
@@ -587,18 +543,17 @@ static inline int qp_ok(int opcode, struct hfi1_packet *packet)
587{ 543{
588 struct hfi1_ibport *ibp; 544 struct hfi1_ibport *ibp;
589 545
590 if (!(ib_hfi1_state_ops[packet->qp->state] & HFI1_PROCESS_RECV_OK)) 546 if (!(ib_rvt_state_ops[packet->qp->state] & RVT_PROCESS_RECV_OK))
591 goto dropit; 547 goto dropit;
592 if (((opcode & OPCODE_QP_MASK) == packet->qp->allowed_ops) || 548 if (((opcode & OPCODE_QP_MASK) == packet->qp->allowed_ops) ||
593 (opcode == IB_OPCODE_CNP)) 549 (opcode == IB_OPCODE_CNP))
594 return 1; 550 return 1;
595dropit: 551dropit:
596 ibp = &packet->rcd->ppd->ibport_data; 552 ibp = &packet->rcd->ppd->ibport_data;
597 ibp->n_pkt_drops++; 553 ibp->rvp.n_pkt_drops++;
598 return 0; 554 return 0;
599} 555}
600 556
601
602/** 557/**
603 * hfi1_ib_rcv - process an incoming packet 558 * hfi1_ib_rcv - process an incoming packet
604 * @packet: data packet information 559 * @packet: data packet information
@@ -614,6 +569,7 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
614 u32 tlen = packet->tlen; 569 u32 tlen = packet->tlen;
615 struct hfi1_pportdata *ppd = rcd->ppd; 570 struct hfi1_pportdata *ppd = rcd->ppd;
616 struct hfi1_ibport *ibp = &ppd->ibport_data; 571 struct hfi1_ibport *ibp = &ppd->ibport_data;
572 struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi;
617 unsigned long flags; 573 unsigned long flags;
618 u32 qp_num; 574 u32 qp_num;
619 int lnh; 575 int lnh;
@@ -622,9 +578,9 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
622 578
623 /* Check for GRH */ 579 /* Check for GRH */
624 lnh = be16_to_cpu(hdr->lrh[0]) & 3; 580 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
625 if (lnh == HFI1_LRH_BTH) 581 if (lnh == HFI1_LRH_BTH) {
626 packet->ohdr = &hdr->u.oth; 582 packet->ohdr = &hdr->u.oth;
627 else if (lnh == HFI1_LRH_GRH) { 583 } else if (lnh == HFI1_LRH_GRH) {
628 u32 vtf; 584 u32 vtf;
629 585
630 packet->ohdr = &hdr->u.l.oth; 586 packet->ohdr = &hdr->u.l.oth;
@@ -634,8 +590,9 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
634 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION) 590 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
635 goto drop; 591 goto drop;
636 packet->rcv_flags |= HFI1_HAS_GRH; 592 packet->rcv_flags |= HFI1_HAS_GRH;
637 } else 593 } else {
638 goto drop; 594 goto drop;
595 }
639 596
640 trace_input_ibhdr(rcd->dd, hdr); 597 trace_input_ibhdr(rcd->dd, hdr);
641 598
@@ -643,17 +600,17 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
643 inc_opstats(tlen, &rcd->opstats->stats[opcode]); 600 inc_opstats(tlen, &rcd->opstats->stats[opcode]);
644 601
645 /* Get the destination QP number. */ 602 /* Get the destination QP number. */
646 qp_num = be32_to_cpu(packet->ohdr->bth[1]) & HFI1_QPN_MASK; 603 qp_num = be32_to_cpu(packet->ohdr->bth[1]) & RVT_QPN_MASK;
647 lid = be16_to_cpu(hdr->lrh[1]); 604 lid = be16_to_cpu(hdr->lrh[1]);
648 if (unlikely((lid >= HFI1_MULTICAST_LID_BASE) && 605 if (unlikely((lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
649 (lid != HFI1_PERMISSIVE_LID))) { 606 (lid != be16_to_cpu(IB_LID_PERMISSIVE)))) {
650 struct hfi1_mcast *mcast; 607 struct rvt_mcast *mcast;
651 struct hfi1_mcast_qp *p; 608 struct rvt_mcast_qp *p;
652 609
653 if (lnh != HFI1_LRH_GRH) 610 if (lnh != HFI1_LRH_GRH)
654 goto drop; 611 goto drop;
655 mcast = hfi1_mcast_find(ibp, &hdr->u.l.grh.dgid); 612 mcast = rvt_mcast_find(&ibp->rvp, &hdr->u.l.grh.dgid);
656 if (mcast == NULL) 613 if (!mcast)
657 goto drop; 614 goto drop;
658 list_for_each_entry_rcu(p, &mcast->qp_list, list) { 615 list_for_each_entry_rcu(p, &mcast->qp_list, list) {
659 packet->qp = p->qp; 616 packet->qp = p->qp;
@@ -663,14 +620,14 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
663 spin_unlock_irqrestore(&packet->qp->r_lock, flags); 620 spin_unlock_irqrestore(&packet->qp->r_lock, flags);
664 } 621 }
665 /* 622 /*
666 * Notify hfi1_multicast_detach() if it is waiting for us 623 * Notify rvt_multicast_detach() if it is waiting for us
667 * to finish. 624 * to finish.
668 */ 625 */
669 if (atomic_dec_return(&mcast->refcount) <= 1) 626 if (atomic_dec_return(&mcast->refcount) <= 1)
670 wake_up(&mcast->wait); 627 wake_up(&mcast->wait);
671 } else { 628 } else {
672 rcu_read_lock(); 629 rcu_read_lock();
673 packet->qp = hfi1_lookup_qpn(ibp, qp_num); 630 packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
674 if (!packet->qp) { 631 if (!packet->qp) {
675 rcu_read_unlock(); 632 rcu_read_unlock();
676 goto drop; 633 goto drop;
@@ -684,7 +641,7 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
684 return; 641 return;
685 642
686drop: 643drop:
687 ibp->n_pkt_drops++; 644 ibp->rvp.n_pkt_drops++;
688} 645}
689 646
690/* 647/*
@@ -695,15 +652,17 @@ static void mem_timer(unsigned long data)
695{ 652{
696 struct hfi1_ibdev *dev = (struct hfi1_ibdev *)data; 653 struct hfi1_ibdev *dev = (struct hfi1_ibdev *)data;
697 struct list_head *list = &dev->memwait; 654 struct list_head *list = &dev->memwait;
698 struct hfi1_qp *qp = NULL; 655 struct rvt_qp *qp = NULL;
699 struct iowait *wait; 656 struct iowait *wait;
700 unsigned long flags; 657 unsigned long flags;
658 struct hfi1_qp_priv *priv;
701 659
702 write_seqlock_irqsave(&dev->iowait_lock, flags); 660 write_seqlock_irqsave(&dev->iowait_lock, flags);
703 if (!list_empty(list)) { 661 if (!list_empty(list)) {
704 wait = list_first_entry(list, struct iowait, list); 662 wait = list_first_entry(list, struct iowait, list);
705 qp = container_of(wait, struct hfi1_qp, s_iowait); 663 qp = iowait_to_qp(wait);
706 list_del_init(&qp->s_iowait.list); 664 priv = qp->priv;
665 list_del_init(&priv->s_iowait.list);
707 /* refcount held until actual wake up */ 666 /* refcount held until actual wake up */
708 if (!list_empty(list)) 667 if (!list_empty(list))
709 mod_timer(&dev->mem_timer, jiffies + 1); 668 mod_timer(&dev->mem_timer, jiffies + 1);
@@ -711,12 +670,12 @@ static void mem_timer(unsigned long data)
711 write_sequnlock_irqrestore(&dev->iowait_lock, flags); 670 write_sequnlock_irqrestore(&dev->iowait_lock, flags);
712 671
713 if (qp) 672 if (qp)
714 hfi1_qp_wakeup(qp, HFI1_S_WAIT_KMEM); 673 hfi1_qp_wakeup(qp, RVT_S_WAIT_KMEM);
715} 674}
716 675
717void update_sge(struct hfi1_sge_state *ss, u32 length) 676void update_sge(struct rvt_sge_state *ss, u32 length)
718{ 677{
719 struct hfi1_sge *sge = &ss->sge; 678 struct rvt_sge *sge = &ss->sge;
720 679
721 sge->vaddr += length; 680 sge->vaddr += length;
722 sge->length -= length; 681 sge->length -= length;
@@ -725,7 +684,7 @@ void update_sge(struct hfi1_sge_state *ss, u32 length)
725 if (--ss->num_sge) 684 if (--ss->num_sge)
726 *sge = *ss->sg_list++; 685 *sge = *ss->sg_list++;
727 } else if (sge->length == 0 && sge->mr->lkey) { 686 } else if (sge->length == 0 && sge->mr->lkey) {
728 if (++sge->n >= HFI1_SEGSZ) { 687 if (++sge->n >= RVT_SEGSZ) {
729 if (++sge->m >= sge->mr->mapsz) 688 if (++sge->m >= sge->mr->mapsz)
730 return; 689 return;
731 sge->n = 0; 690 sge->n = 0;
@@ -735,143 +694,55 @@ void update_sge(struct hfi1_sge_state *ss, u32 length)
735 } 694 }
736} 695}
737 696
738static noinline struct verbs_txreq *__get_txreq(struct hfi1_ibdev *dev,
739 struct hfi1_qp *qp)
740{
741 struct verbs_txreq *tx;
742 unsigned long flags;
743
744 tx = kmem_cache_alloc(dev->verbs_txreq_cache, GFP_ATOMIC);
745 if (!tx) {
746 spin_lock_irqsave(&qp->s_lock, flags);
747 write_seqlock(&dev->iowait_lock);
748 if (ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK &&
749 list_empty(&qp->s_iowait.list)) {
750 dev->n_txwait++;
751 qp->s_flags |= HFI1_S_WAIT_TX;
752 list_add_tail(&qp->s_iowait.list, &dev->txwait);
753 trace_hfi1_qpsleep(qp, HFI1_S_WAIT_TX);
754 atomic_inc(&qp->refcount);
755 }
756 qp->s_flags &= ~HFI1_S_BUSY;
757 write_sequnlock(&dev->iowait_lock);
758 spin_unlock_irqrestore(&qp->s_lock, flags);
759 tx = ERR_PTR(-EBUSY);
760 }
761 return tx;
762}
763
764static inline struct verbs_txreq *get_txreq(struct hfi1_ibdev *dev,
765 struct hfi1_qp *qp)
766{
767 struct verbs_txreq *tx;
768
769 tx = kmem_cache_alloc(dev->verbs_txreq_cache, GFP_ATOMIC);
770 if (!tx) {
771 /* call slow path to get the lock */
772 tx = __get_txreq(dev, qp);
773 if (IS_ERR(tx))
774 return tx;
775 }
776 tx->qp = qp;
777 return tx;
778}
779
780void hfi1_put_txreq(struct verbs_txreq *tx)
781{
782 struct hfi1_ibdev *dev;
783 struct hfi1_qp *qp;
784 unsigned long flags;
785 unsigned int seq;
786
787 qp = tx->qp;
788 dev = to_idev(qp->ibqp.device);
789
790 if (tx->mr) {
791 hfi1_put_mr(tx->mr);
792 tx->mr = NULL;
793 }
794 sdma_txclean(dd_from_dev(dev), &tx->txreq);
795
796 /* Free verbs_txreq and return to slab cache */
797 kmem_cache_free(dev->verbs_txreq_cache, tx);
798
799 do {
800 seq = read_seqbegin(&dev->iowait_lock);
801 if (!list_empty(&dev->txwait)) {
802 struct iowait *wait;
803
804 write_seqlock_irqsave(&dev->iowait_lock, flags);
805 /* Wake up first QP wanting a free struct */
806 wait = list_first_entry(&dev->txwait, struct iowait,
807 list);
808 qp = container_of(wait, struct hfi1_qp, s_iowait);
809 list_del_init(&qp->s_iowait.list);
810 /* refcount held until actual wake up */
811 write_sequnlock_irqrestore(&dev->iowait_lock, flags);
812 hfi1_qp_wakeup(qp, HFI1_S_WAIT_TX);
813 break;
814 }
815 } while (read_seqretry(&dev->iowait_lock, seq));
816}
817
818/* 697/*
819 * This is called with progress side lock held. 698 * This is called with progress side lock held.
820 */ 699 */
821/* New API */ 700/* New API */
822static void verbs_sdma_complete( 701static void verbs_sdma_complete(
823 struct sdma_txreq *cookie, 702 struct sdma_txreq *cookie,
824 int status, 703 int status)
825 int drained)
826{ 704{
827 struct verbs_txreq *tx = 705 struct verbs_txreq *tx =
828 container_of(cookie, struct verbs_txreq, txreq); 706 container_of(cookie, struct verbs_txreq, txreq);
829 struct hfi1_qp *qp = tx->qp; 707 struct rvt_qp *qp = tx->qp;
830 708
831 spin_lock(&qp->s_lock); 709 spin_lock(&qp->s_lock);
832 if (tx->wqe) 710 if (tx->wqe) {
833 hfi1_send_complete(qp, tx->wqe, IB_WC_SUCCESS); 711 hfi1_send_complete(qp, tx->wqe, IB_WC_SUCCESS);
834 else if (qp->ibqp.qp_type == IB_QPT_RC) { 712 } else if (qp->ibqp.qp_type == IB_QPT_RC) {
835 struct hfi1_ib_header *hdr; 713 struct hfi1_ib_header *hdr;
836 714
837 hdr = &tx->phdr.hdr; 715 hdr = &tx->phdr.hdr;
838 hfi1_rc_send_complete(qp, hdr); 716 hfi1_rc_send_complete(qp, hdr);
839 } 717 }
840 if (drained) {
841 /*
842 * This happens when the send engine notes
843 * a QP in the error state and cannot
844 * do the flush work until that QP's
845 * sdma work has finished.
846 */
847 if (qp->s_flags & HFI1_S_WAIT_DMA) {
848 qp->s_flags &= ~HFI1_S_WAIT_DMA;
849 hfi1_schedule_send(qp);
850 }
851 }
852 spin_unlock(&qp->s_lock); 718 spin_unlock(&qp->s_lock);
853 719
854 hfi1_put_txreq(tx); 720 hfi1_put_txreq(tx);
855} 721}
856 722
857static int wait_kmem(struct hfi1_ibdev *dev, struct hfi1_qp *qp) 723static int wait_kmem(struct hfi1_ibdev *dev,
724 struct rvt_qp *qp,
725 struct hfi1_pkt_state *ps)
858{ 726{
727 struct hfi1_qp_priv *priv = qp->priv;
859 unsigned long flags; 728 unsigned long flags;
860 int ret = 0; 729 int ret = 0;
861 730
862 spin_lock_irqsave(&qp->s_lock, flags); 731 spin_lock_irqsave(&qp->s_lock, flags);
863 if (ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK) { 732 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
864 write_seqlock(&dev->iowait_lock); 733 write_seqlock(&dev->iowait_lock);
865 if (list_empty(&qp->s_iowait.list)) { 734 list_add_tail(&ps->s_txreq->txreq.list,
735 &priv->s_iowait.tx_head);
736 if (list_empty(&priv->s_iowait.list)) {
866 if (list_empty(&dev->memwait)) 737 if (list_empty(&dev->memwait))
867 mod_timer(&dev->mem_timer, jiffies + 1); 738 mod_timer(&dev->mem_timer, jiffies + 1);
868 qp->s_flags |= HFI1_S_WAIT_KMEM; 739 qp->s_flags |= RVT_S_WAIT_KMEM;
869 list_add_tail(&qp->s_iowait.list, &dev->memwait); 740 list_add_tail(&priv->s_iowait.list, &dev->memwait);
870 trace_hfi1_qpsleep(qp, HFI1_S_WAIT_KMEM); 741 trace_hfi1_qpsleep(qp, RVT_S_WAIT_KMEM);
871 atomic_inc(&qp->refcount); 742 atomic_inc(&qp->refcount);
872 } 743 }
873 write_sequnlock(&dev->iowait_lock); 744 write_sequnlock(&dev->iowait_lock);
874 qp->s_flags &= ~HFI1_S_BUSY; 745 qp->s_flags &= ~RVT_S_BUSY;
875 ret = -EBUSY; 746 ret = -EBUSY;
876 } 747 }
877 spin_unlock_irqrestore(&qp->s_lock, flags); 748 spin_unlock_irqrestore(&qp->s_lock, flags);
@@ -884,14 +755,14 @@ static int wait_kmem(struct hfi1_ibdev *dev, struct hfi1_qp *qp)
884 * 755 *
885 * Add failures will revert the sge cursor 756 * Add failures will revert the sge cursor
886 */ 757 */
887static int build_verbs_ulp_payload( 758static noinline int build_verbs_ulp_payload(
888 struct sdma_engine *sde, 759 struct sdma_engine *sde,
889 struct hfi1_sge_state *ss, 760 struct rvt_sge_state *ss,
890 u32 length, 761 u32 length,
891 struct verbs_txreq *tx) 762 struct verbs_txreq *tx)
892{ 763{
893 struct hfi1_sge *sg_list = ss->sg_list; 764 struct rvt_sge *sg_list = ss->sg_list;
894 struct hfi1_sge sge = ss->sge; 765 struct rvt_sge sge = ss->sge;
895 u8 num_sge = ss->num_sge; 766 u8 num_sge = ss->num_sge;
896 u32 len; 767 u32 len;
897 int ret = 0; 768 int ret = 0;
@@ -928,23 +799,21 @@ bail_txadd:
928 * NOTE: DMA mapping is held in the tx until completed in the ring or 799 * NOTE: DMA mapping is held in the tx until completed in the ring or
929 * the tx desc is freed without having been submitted to the ring 800 * the tx desc is freed without having been submitted to the ring
930 * 801 *
931 * This routine insures the following all the helper routine 802 * This routine ensures all the helper routine calls succeed.
932 * calls succeed.
933 */ 803 */
934/* New API */ 804/* New API */
935static int build_verbs_tx_desc( 805static int build_verbs_tx_desc(
936 struct sdma_engine *sde, 806 struct sdma_engine *sde,
937 struct hfi1_sge_state *ss, 807 struct rvt_sge_state *ss,
938 u32 length, 808 u32 length,
939 struct verbs_txreq *tx, 809 struct verbs_txreq *tx,
940 struct ahg_ib_header *ahdr, 810 struct ahg_ib_header *ahdr,
941 u64 pbc) 811 u64 pbc)
942{ 812{
943 int ret = 0; 813 int ret = 0;
944 struct hfi1_pio_header *phdr; 814 struct hfi1_pio_header *phdr = &tx->phdr;
945 u16 hdrbytes = tx->hdr_dwords << 2; 815 u16 hdrbytes = tx->hdr_dwords << 2;
946 816
947 phdr = &tx->phdr;
948 if (!ahdr->ahgcount) { 817 if (!ahdr->ahgcount) {
949 ret = sdma_txinit_ahg( 818 ret = sdma_txinit_ahg(
950 &tx->txreq, 819 &tx->txreq,
@@ -958,29 +827,14 @@ static int build_verbs_tx_desc(
958 if (ret) 827 if (ret)
959 goto bail_txadd; 828 goto bail_txadd;
960 phdr->pbc = cpu_to_le64(pbc); 829 phdr->pbc = cpu_to_le64(pbc);
961 memcpy(&phdr->hdr, &ahdr->ibh, hdrbytes - sizeof(phdr->pbc));
962 /* add the header */
963 ret = sdma_txadd_kvaddr( 830 ret = sdma_txadd_kvaddr(
964 sde->dd, 831 sde->dd,
965 &tx->txreq, 832 &tx->txreq,
966 &tx->phdr, 833 phdr,
967 tx->hdr_dwords << 2); 834 hdrbytes);
968 if (ret) 835 if (ret)
969 goto bail_txadd; 836 goto bail_txadd;
970 } else { 837 } else {
971 struct hfi1_other_headers *sohdr = &ahdr->ibh.u.oth;
972 struct hfi1_other_headers *dohdr = &phdr->hdr.u.oth;
973
974 /* needed in rc_send_complete() */
975 phdr->hdr.lrh[0] = ahdr->ibh.lrh[0];
976 if ((be16_to_cpu(phdr->hdr.lrh[0]) & 3) == HFI1_LRH_GRH) {
977 sohdr = &ahdr->ibh.u.l.oth;
978 dohdr = &phdr->hdr.u.l.oth;
979 }
980 /* opcode */
981 dohdr->bth[0] = sohdr->bth[0];
982 /* PSN/ACK */
983 dohdr->bth[2] = sohdr->bth[2];
984 ret = sdma_txinit_ahg( 838 ret = sdma_txinit_ahg(
985 &tx->txreq, 839 &tx->txreq,
986 ahdr->tx_flags, 840 ahdr->tx_flags,
@@ -1001,80 +855,75 @@ bail_txadd:
1001 return ret; 855 return ret;
1002} 856}
1003 857
1004int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 858int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1005 u64 pbc) 859 u64 pbc)
1006{ 860{
1007 struct ahg_ib_header *ahdr = qp->s_hdr; 861 struct hfi1_qp_priv *priv = qp->priv;
862 struct ahg_ib_header *ahdr = priv->s_hdr;
1008 u32 hdrwords = qp->s_hdrwords; 863 u32 hdrwords = qp->s_hdrwords;
1009 struct hfi1_sge_state *ss = qp->s_cur_sge; 864 struct rvt_sge_state *ss = qp->s_cur_sge;
1010 u32 len = qp->s_cur_size; 865 u32 len = qp->s_cur_size;
1011 u32 plen = hdrwords + ((len + 3) >> 2) + 2; /* includes pbc */ 866 u32 plen = hdrwords + ((len + 3) >> 2) + 2; /* includes pbc */
1012 struct hfi1_ibdev *dev = ps->dev; 867 struct hfi1_ibdev *dev = ps->dev;
1013 struct hfi1_pportdata *ppd = ps->ppd; 868 struct hfi1_pportdata *ppd = ps->ppd;
1014 struct verbs_txreq *tx; 869 struct verbs_txreq *tx;
1015 struct sdma_txreq *stx;
1016 u64 pbc_flags = 0; 870 u64 pbc_flags = 0;
1017 u8 sc5 = qp->s_sc; 871 u8 sc5 = priv->s_sc;
872
1018 int ret; 873 int ret;
1019 874
1020 if (!list_empty(&qp->s_iowait.tx_head)) { 875 tx = ps->s_txreq;
1021 stx = list_first_entry( 876 if (!sdma_txreq_built(&tx->txreq)) {
1022 &qp->s_iowait.tx_head, 877 if (likely(pbc == 0)) {
1023 struct sdma_txreq, 878 u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5);
1024 list); 879 /* No vl15 here */
1025 list_del_init(&stx->list); 880 /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */
1026 tx = container_of(stx, struct verbs_txreq, txreq); 881 pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
1027 ret = sdma_send_txreq(tx->sde, &qp->s_iowait, stx); 882
1028 if (unlikely(ret == -ECOMM)) 883 pbc = create_pbc(ppd,
884 pbc_flags,
885 qp->srate_mbps,
886 vl,
887 plen);
888 }
889 tx->wqe = qp->s_wqe;
890 ret = build_verbs_tx_desc(tx->sde, ss, len, tx, ahdr, pbc);
891 if (unlikely(ret))
892 goto bail_build;
893 }
894 ret = sdma_send_txreq(tx->sde, &priv->s_iowait, &tx->txreq);
895 if (unlikely(ret < 0)) {
896 if (ret == -ECOMM)
1029 goto bail_ecomm; 897 goto bail_ecomm;
1030 return ret; 898 return ret;
1031 } 899 }
1032 900 trace_sdma_output_ibhdr(dd_from_ibdev(qp->ibqp.device),
1033 tx = get_txreq(dev, qp); 901 &ps->s_txreq->phdr.hdr);
1034 if (IS_ERR(tx))
1035 goto bail_tx;
1036
1037 tx->sde = qp->s_sde;
1038
1039 if (likely(pbc == 0)) {
1040 u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5);
1041 /* No vl15 here */
1042 /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */
1043 pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
1044
1045 pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
1046 }
1047 tx->wqe = qp->s_wqe;
1048 tx->mr = qp->s_rdma_mr;
1049 if (qp->s_rdma_mr)
1050 qp->s_rdma_mr = NULL;
1051 tx->hdr_dwords = hdrwords + 2;
1052 ret = build_verbs_tx_desc(tx->sde, ss, len, tx, ahdr, pbc);
1053 if (unlikely(ret))
1054 goto bail_build;
1055 trace_output_ibhdr(dd_from_ibdev(qp->ibqp.device), &ahdr->ibh);
1056 ret = sdma_send_txreq(tx->sde, &qp->s_iowait, &tx->txreq);
1057 if (unlikely(ret == -ECOMM))
1058 goto bail_ecomm;
1059 return ret; 902 return ret;
1060 903
1061bail_ecomm: 904bail_ecomm:
1062 /* The current one got "sent" */ 905 /* The current one got "sent" */
1063 return 0; 906 return 0;
1064bail_build: 907bail_build:
1065 /* kmalloc or mapping fail */ 908 ret = wait_kmem(dev, qp, ps);
1066 hfi1_put_txreq(tx); 909 if (!ret) {
1067 return wait_kmem(dev, qp); 910 /* free txreq - bad state */
1068bail_tx: 911 hfi1_put_txreq(ps->s_txreq);
1069 return PTR_ERR(tx); 912 ps->s_txreq = NULL;
913 }
914 return ret;
1070} 915}
1071 916
1072/* 917/*
1073 * If we are now in the error state, return zero to flush the 918 * If we are now in the error state, return zero to flush the
1074 * send work request. 919 * send work request.
1075 */ 920 */
1076static int no_bufs_available(struct hfi1_qp *qp, struct send_context *sc) 921static int pio_wait(struct rvt_qp *qp,
922 struct send_context *sc,
923 struct hfi1_pkt_state *ps,
924 u32 flag)
1077{ 925{
926 struct hfi1_qp_priv *priv = qp->priv;
1078 struct hfi1_devdata *dd = sc->dd; 927 struct hfi1_devdata *dd = sc->dd;
1079 struct hfi1_ibdev *dev = &dd->verbs_dev; 928 struct hfi1_ibdev *dev = &dd->verbs_dev;
1080 unsigned long flags; 929 unsigned long flags;
@@ -1087,74 +936,89 @@ static int no_bufs_available(struct hfi1_qp *qp, struct send_context *sc)
1087 * enabling the PIO avail interrupt. 936 * enabling the PIO avail interrupt.
1088 */ 937 */
1089 spin_lock_irqsave(&qp->s_lock, flags); 938 spin_lock_irqsave(&qp->s_lock, flags);
1090 if (ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK) { 939 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
1091 write_seqlock(&dev->iowait_lock); 940 write_seqlock(&dev->iowait_lock);
1092 if (list_empty(&qp->s_iowait.list)) { 941 list_add_tail(&ps->s_txreq->txreq.list,
942 &priv->s_iowait.tx_head);
943 if (list_empty(&priv->s_iowait.list)) {
1093 struct hfi1_ibdev *dev = &dd->verbs_dev; 944 struct hfi1_ibdev *dev = &dd->verbs_dev;
1094 int was_empty; 945 int was_empty;
1095 946
947 dev->n_piowait += !!(flag & RVT_S_WAIT_PIO);
948 dev->n_piodrain += !!(flag & RVT_S_WAIT_PIO_DRAIN);
1096 dev->n_piowait++; 949 dev->n_piowait++;
1097 qp->s_flags |= HFI1_S_WAIT_PIO; 950 qp->s_flags |= flag;
1098 was_empty = list_empty(&sc->piowait); 951 was_empty = list_empty(&sc->piowait);
1099 list_add_tail(&qp->s_iowait.list, &sc->piowait); 952 list_add_tail(&priv->s_iowait.list, &sc->piowait);
1100 trace_hfi1_qpsleep(qp, HFI1_S_WAIT_PIO); 953 trace_hfi1_qpsleep(qp, RVT_S_WAIT_PIO);
1101 atomic_inc(&qp->refcount); 954 atomic_inc(&qp->refcount);
1102 /* counting: only call wantpiobuf_intr if first user */ 955 /* counting: only call wantpiobuf_intr if first user */
1103 if (was_empty) 956 if (was_empty)
1104 hfi1_sc_wantpiobuf_intr(sc, 1); 957 hfi1_sc_wantpiobuf_intr(sc, 1);
1105 } 958 }
1106 write_sequnlock(&dev->iowait_lock); 959 write_sequnlock(&dev->iowait_lock);
1107 qp->s_flags &= ~HFI1_S_BUSY; 960 qp->s_flags &= ~RVT_S_BUSY;
1108 ret = -EBUSY; 961 ret = -EBUSY;
1109 } 962 }
1110 spin_unlock_irqrestore(&qp->s_lock, flags); 963 spin_unlock_irqrestore(&qp->s_lock, flags);
1111 return ret; 964 return ret;
1112} 965}
1113 966
1114struct send_context *qp_to_send_context(struct hfi1_qp *qp, u8 sc5) 967static void verbs_pio_complete(void *arg, int code)
1115{ 968{
1116 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); 969 struct rvt_qp *qp = (struct rvt_qp *)arg;
1117 struct hfi1_pportdata *ppd = dd->pport + (qp->port_num - 1); 970 struct hfi1_qp_priv *priv = qp->priv;
1118 u8 vl;
1119 971
1120 vl = sc_to_vlt(dd, sc5); 972 if (iowait_pio_dec(&priv->s_iowait))
1121 if (vl >= ppd->vls_supported && vl != 15) 973 iowait_drain_wakeup(&priv->s_iowait);
1122 return NULL;
1123 return dd->vld[vl].sc;
1124} 974}
1125 975
1126int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 976int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1127 u64 pbc) 977 u64 pbc)
1128{ 978{
1129 struct ahg_ib_header *ahdr = qp->s_hdr; 979 struct hfi1_qp_priv *priv = qp->priv;
1130 u32 hdrwords = qp->s_hdrwords; 980 u32 hdrwords = qp->s_hdrwords;
1131 struct hfi1_sge_state *ss = qp->s_cur_sge; 981 struct rvt_sge_state *ss = qp->s_cur_sge;
1132 u32 len = qp->s_cur_size; 982 u32 len = qp->s_cur_size;
1133 u32 dwords = (len + 3) >> 2; 983 u32 dwords = (len + 3) >> 2;
1134 u32 plen = hdrwords + dwords + 2; /* includes pbc */ 984 u32 plen = hdrwords + dwords + 2; /* includes pbc */
1135 struct hfi1_pportdata *ppd = ps->ppd; 985 struct hfi1_pportdata *ppd = ps->ppd;
1136 u32 *hdr = (u32 *)&ahdr->ibh; 986 u32 *hdr = (u32 *)&ps->s_txreq->phdr.hdr;
1137 u64 pbc_flags = 0; 987 u64 pbc_flags = 0;
1138 u32 sc5; 988 u8 sc5;
1139 unsigned long flags = 0; 989 unsigned long flags = 0;
1140 struct send_context *sc; 990 struct send_context *sc;
1141 struct pio_buf *pbuf; 991 struct pio_buf *pbuf;
1142 int wc_status = IB_WC_SUCCESS; 992 int wc_status = IB_WC_SUCCESS;
993 int ret = 0;
994 pio_release_cb cb = NULL;
995
996 /* only RC/UC use complete */
997 switch (qp->ibqp.qp_type) {
998 case IB_QPT_RC:
999 case IB_QPT_UC:
1000 cb = verbs_pio_complete;
1001 break;
1002 default:
1003 break;
1004 }
1143 1005
1144 /* vl15 special case taken care of in ud.c */ 1006 /* vl15 special case taken care of in ud.c */
1145 sc5 = qp->s_sc; 1007 sc5 = priv->s_sc;
1146 sc = qp_to_send_context(qp, sc5); 1008 sc = ps->s_txreq->psc;
1147 1009
1148 if (!sc)
1149 return -EINVAL;
1150 if (likely(pbc == 0)) { 1010 if (likely(pbc == 0)) {
1151 u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5); 1011 u8 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5);
1152 /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */ 1012 /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */
1153 pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT; 1013 pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
1154 pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen); 1014 pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
1155 } 1015 }
1156 pbuf = sc_buffer_alloc(sc, plen, NULL, NULL); 1016 if (cb)
1157 if (unlikely(pbuf == NULL)) { 1017 iowait_pio_inc(&priv->s_iowait);
1018 pbuf = sc_buffer_alloc(sc, plen, cb, qp);
1019 if (unlikely(!pbuf)) {
1020 if (cb)
1021 verbs_pio_complete(qp, 0);
1158 if (ppd->host_link_state != HLS_UP_ACTIVE) { 1022 if (ppd->host_link_state != HLS_UP_ACTIVE) {
1159 /* 1023 /*
1160 * If we have filled the PIO buffers to capacity and are 1024 * If we have filled the PIO buffers to capacity and are
@@ -1174,7 +1038,12 @@ int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1174 * so lets continue to queue the request. 1038 * so lets continue to queue the request.
1175 */ 1039 */
1176 hfi1_cdbg(PIO, "alloc failed. state active, queuing"); 1040 hfi1_cdbg(PIO, "alloc failed. state active, queuing");
1177 return no_bufs_available(qp, sc); 1041 ret = pio_wait(qp, sc, ps, RVT_S_WAIT_PIO);
1042 if (!ret)
1043 /* txreq not queued - free */
1044 goto bail;
1045 /* tx consumed in wait */
1046 return ret;
1178 } 1047 }
1179 } 1048 }
1180 1049
@@ -1182,7 +1051,7 @@ int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1182 pio_copy(ppd->dd, pbuf, pbc, hdr, hdrwords); 1051 pio_copy(ppd->dd, pbuf, pbc, hdr, hdrwords);
1183 } else { 1052 } else {
1184 if (ss) { 1053 if (ss) {
1185 seg_pio_copy_start(pbuf, pbc, hdr, hdrwords*4); 1054 seg_pio_copy_start(pbuf, pbc, hdr, hdrwords * 4);
1186 while (len) { 1055 while (len) {
1187 void *addr = ss->sge.vaddr; 1056 void *addr = ss->sge.vaddr;
1188 u32 slen = ss->sge.length; 1057 u32 slen = ss->sge.length;
@@ -1197,12 +1066,8 @@ int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1197 } 1066 }
1198 } 1067 }
1199 1068
1200 trace_output_ibhdr(dd_from_ibdev(qp->ibqp.device), &ahdr->ibh); 1069 trace_pio_output_ibhdr(dd_from_ibdev(qp->ibqp.device),
1201 1070 &ps->s_txreq->phdr.hdr);
1202 if (qp->s_rdma_mr) {
1203 hfi1_put_mr(qp->s_rdma_mr);
1204 qp->s_rdma_mr = NULL;
1205 }
1206 1071
1207pio_bail: 1072pio_bail:
1208 if (qp->s_wqe) { 1073 if (qp->s_wqe) {
@@ -1211,10 +1076,15 @@ pio_bail:
1211 spin_unlock_irqrestore(&qp->s_lock, flags); 1076 spin_unlock_irqrestore(&qp->s_lock, flags);
1212 } else if (qp->ibqp.qp_type == IB_QPT_RC) { 1077 } else if (qp->ibqp.qp_type == IB_QPT_RC) {
1213 spin_lock_irqsave(&qp->s_lock, flags); 1078 spin_lock_irqsave(&qp->s_lock, flags);
1214 hfi1_rc_send_complete(qp, &ahdr->ibh); 1079 hfi1_rc_send_complete(qp, &ps->s_txreq->phdr.hdr);
1215 spin_unlock_irqrestore(&qp->s_lock, flags); 1080 spin_unlock_irqrestore(&qp->s_lock, flags);
1216 } 1081 }
1217 return 0; 1082
1083 ret = 0;
1084
1085bail:
1086 hfi1_put_txreq(ps->s_txreq);
1087 return ret;
1218} 1088}
1219 1089
1220/* 1090/*
@@ -1247,13 +1117,14 @@ static inline int egress_pkey_matches_entry(u16 pkey, u16 ent)
1247 */ 1117 */
1248static inline int egress_pkey_check(struct hfi1_pportdata *ppd, 1118static inline int egress_pkey_check(struct hfi1_pportdata *ppd,
1249 struct hfi1_ib_header *hdr, 1119 struct hfi1_ib_header *hdr,
1250 struct hfi1_qp *qp) 1120 struct rvt_qp *qp)
1251{ 1121{
1122 struct hfi1_qp_priv *priv = qp->priv;
1252 struct hfi1_other_headers *ohdr; 1123 struct hfi1_other_headers *ohdr;
1253 struct hfi1_devdata *dd; 1124 struct hfi1_devdata *dd;
1254 int i = 0; 1125 int i = 0;
1255 u16 pkey; 1126 u16 pkey;
1256 u8 lnh, sc5 = qp->s_sc; 1127 u8 lnh, sc5 = priv->s_sc;
1257 1128
1258 if (!(ppd->part_enforce & HFI1_PART_ENFORCE_OUT)) 1129 if (!(ppd->part_enforce & HFI1_PART_ENFORCE_OUT))
1259 return 0; 1130 return 0;
@@ -1271,14 +1142,14 @@ static inline int egress_pkey_check(struct hfi1_pportdata *ppd,
1271 if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK)) 1142 if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
1272 goto bad; 1143 goto bad;
1273 1144
1274
1275 /* Is the pkey = 0x0, or 0x8000? */ 1145 /* Is the pkey = 0x0, or 0x8000? */
1276 if ((pkey & PKEY_LOW_15_MASK) == 0) 1146 if ((pkey & PKEY_LOW_15_MASK) == 0)
1277 goto bad; 1147 goto bad;
1278 1148
1279 /* The most likely matching pkey has index qp->s_pkey_index */ 1149 /* The most likely matching pkey has index qp->s_pkey_index */
1280 if (unlikely(!egress_pkey_matches_entry(pkey, 1150 if (unlikely(!egress_pkey_matches_entry(pkey,
1281 ppd->pkeys[qp->s_pkey_index]))) { 1151 ppd->pkeys
1152 [qp->s_pkey_index]))) {
1282 /* no match - try the entire table */ 1153 /* no match - try the entire table */
1283 for (; i < MAX_PKEY_VALUES; i++) { 1154 for (; i < MAX_PKEY_VALUES; i++) {
1284 if (egress_pkey_matches_entry(pkey, ppd->pkeys[i])) 1155 if (egress_pkey_matches_entry(pkey, ppd->pkeys[i]))
@@ -1302,31 +1173,65 @@ bad:
1302} 1173}
1303 1174
1304/** 1175/**
1176 * get_send_routine - choose an egress routine
1177 *
1178 * Choose an egress routine based on QP type
1179 * and size
1180 */
1181static inline send_routine get_send_routine(struct rvt_qp *qp,
1182 struct verbs_txreq *tx)
1183{
1184 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1185 struct hfi1_qp_priv *priv = qp->priv;
1186 struct hfi1_ib_header *h = &tx->phdr.hdr;
1187
1188 if (unlikely(!(dd->flags & HFI1_HAS_SEND_DMA)))
1189 return dd->process_pio_send;
1190 switch (qp->ibqp.qp_type) {
1191 case IB_QPT_SMI:
1192 return dd->process_pio_send;
1193 case IB_QPT_GSI:
1194 case IB_QPT_UD:
1195 break;
1196 case IB_QPT_RC:
1197 if (piothreshold &&
1198 qp->s_cur_size <= min(piothreshold, qp->pmtu) &&
1199 (BIT(get_opcode(h) & 0x1f) & rc_only_opcode) &&
1200 iowait_sdma_pending(&priv->s_iowait) == 0 &&
1201 !sdma_txreq_built(&tx->txreq))
1202 return dd->process_pio_send;
1203 break;
1204 case IB_QPT_UC:
1205 if (piothreshold &&
1206 qp->s_cur_size <= min(piothreshold, qp->pmtu) &&
1207 (BIT(get_opcode(h) & 0x1f) & uc_only_opcode) &&
1208 iowait_sdma_pending(&priv->s_iowait) == 0 &&
1209 !sdma_txreq_built(&tx->txreq))
1210 return dd->process_pio_send;
1211 break;
1212 default:
1213 break;
1214 }
1215 return dd->process_dma_send;
1216}
1217
1218/**
1305 * hfi1_verbs_send - send a packet 1219 * hfi1_verbs_send - send a packet
1306 * @qp: the QP to send on 1220 * @qp: the QP to send on
1307 * @ps: the state of the packet to send 1221 * @ps: the state of the packet to send
1308 * 1222 *
1309 * Return zero if packet is sent or queued OK. 1223 * Return zero if packet is sent or queued OK.
1310 * Return non-zero and clear qp->s_flags HFI1_S_BUSY otherwise. 1224 * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise.
1311 */ 1225 */
1312int hfi1_verbs_send(struct hfi1_qp *qp, struct hfi1_pkt_state *ps) 1226int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
1313{ 1227{
1314 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device); 1228 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1315 struct ahg_ib_header *ahdr = qp->s_hdr; 1229 struct hfi1_qp_priv *priv = qp->priv;
1230 send_routine sr;
1316 int ret; 1231 int ret;
1317 int pio = 0;
1318 unsigned long flags = 0;
1319
1320 /*
1321 * VL15 packets (IB_QPT_SMI) will always use PIO, so we
1322 * can defer SDMA restart until link goes ACTIVE without
1323 * worrying about just how we got there.
1324 */
1325 if ((qp->ibqp.qp_type == IB_QPT_SMI) ||
1326 !(dd->flags & HFI1_HAS_SEND_DMA))
1327 pio = 1;
1328 1232
1329 ret = egress_pkey_check(dd->pport, &ahdr->ibh, qp); 1233 sr = get_send_routine(qp, ps->s_txreq);
1234 ret = egress_pkey_check(dd->pport, &ps->s_txreq->phdr.hdr, qp);
1330 if (unlikely(ret)) { 1235 if (unlikely(ret)) {
1331 /* 1236 /*
1332 * The value we are returning here does not get propagated to 1237 * The value we are returning here does not get propagated to
@@ -1336,7 +1241,9 @@ int hfi1_verbs_send(struct hfi1_qp *qp, struct hfi1_pkt_state *ps)
1336 * mechanism for handling the errors. So for SDMA we can just 1241 * mechanism for handling the errors. So for SDMA we can just
1337 * return. 1242 * return.
1338 */ 1243 */
1339 if (pio) { 1244 if (sr == dd->process_pio_send) {
1245 unsigned long flags;
1246
1340 hfi1_cdbg(PIO, "%s() Failed. Completing with err", 1247 hfi1_cdbg(PIO, "%s() Failed. Completing with err",
1341 __func__); 1248 __func__);
1342 spin_lock_irqsave(&qp->s_lock, flags); 1249 spin_lock_irqsave(&qp->s_lock, flags);
@@ -1345,71 +1252,57 @@ int hfi1_verbs_send(struct hfi1_qp *qp, struct hfi1_pkt_state *ps)
1345 } 1252 }
1346 return -EINVAL; 1253 return -EINVAL;
1347 } 1254 }
1348 1255 if (sr == dd->process_dma_send && iowait_pio_pending(&priv->s_iowait))
1349 if (pio) { 1256 return pio_wait(qp,
1350 ret = dd->process_pio_send(qp, ps, 0); 1257 ps->s_txreq->psc,
1351 } else { 1258 ps,
1352#ifdef CONFIG_SDMA_VERBOSITY 1259 RVT_S_WAIT_PIO_DRAIN);
1353 dd_dev_err(dd, "CONFIG SDMA %s:%d %s()\n", 1260 return sr(qp, ps, 0);
1354 slashstrip(__FILE__), __LINE__, __func__);
1355 dd_dev_err(dd, "SDMA hdrwords = %u, len = %u\n", qp->s_hdrwords,
1356 qp->s_cur_size);
1357#endif
1358 ret = dd->process_dma_send(qp, ps, 0);
1359 }
1360
1361 return ret;
1362} 1261}
1363 1262
1364static int query_device(struct ib_device *ibdev, 1263/**
1365 struct ib_device_attr *props, 1264 * hfi1_fill_device_attr - Fill in rvt dev info device attributes.
1366 struct ib_udata *uhw) 1265 * @dd: the device data structure
1266 */
1267static void hfi1_fill_device_attr(struct hfi1_devdata *dd)
1367{ 1268{
1368 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1269 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
1369 struct hfi1_ibdev *dev = to_idev(ibdev); 1270
1370 1271 memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props));
1371 if (uhw->inlen || uhw->outlen) 1272
1372 return -EINVAL; 1273 rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1373 memset(props, 0, sizeof(*props)); 1274 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1374 1275 IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
1375 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR | 1276 IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE;
1376 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT | 1277 rdi->dparms.props.page_size_cap = PAGE_SIZE;
1377 IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN | 1278 rdi->dparms.props.vendor_id = dd->oui1 << 16 | dd->oui2 << 8 | dd->oui3;
1378 IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE; 1279 rdi->dparms.props.vendor_part_id = dd->pcidev->device;
1379 1280 rdi->dparms.props.hw_ver = dd->minrev;
1380 props->page_size_cap = PAGE_SIZE; 1281 rdi->dparms.props.sys_image_guid = ib_hfi1_sys_image_guid;
1381 props->vendor_id = 1282 rdi->dparms.props.max_mr_size = ~0ULL;
1382 dd->oui1 << 16 | dd->oui2 << 8 | dd->oui3; 1283 rdi->dparms.props.max_qp = hfi1_max_qps;
1383 props->vendor_part_id = dd->pcidev->device; 1284 rdi->dparms.props.max_qp_wr = hfi1_max_qp_wrs;
1384 props->hw_ver = dd->minrev; 1285 rdi->dparms.props.max_sge = hfi1_max_sges;
1385 props->sys_image_guid = ib_hfi1_sys_image_guid; 1286 rdi->dparms.props.max_sge_rd = hfi1_max_sges;
1386 props->max_mr_size = ~0ULL; 1287 rdi->dparms.props.max_cq = hfi1_max_cqs;
1387 props->max_qp = hfi1_max_qps; 1288 rdi->dparms.props.max_ah = hfi1_max_ahs;
1388 props->max_qp_wr = hfi1_max_qp_wrs; 1289 rdi->dparms.props.max_cqe = hfi1_max_cqes;
1389 props->max_sge = hfi1_max_sges; 1290 rdi->dparms.props.max_mr = rdi->lkey_table.max;
1390 props->max_sge_rd = hfi1_max_sges; 1291 rdi->dparms.props.max_fmr = rdi->lkey_table.max;
1391 props->max_cq = hfi1_max_cqs; 1292 rdi->dparms.props.max_map_per_fmr = 32767;
1392 props->max_ah = hfi1_max_ahs; 1293 rdi->dparms.props.max_pd = hfi1_max_pds;
1393 props->max_cqe = hfi1_max_cqes; 1294 rdi->dparms.props.max_qp_rd_atom = HFI1_MAX_RDMA_ATOMIC;
1394 props->max_mr = dev->lk_table.max; 1295 rdi->dparms.props.max_qp_init_rd_atom = 255;
1395 props->max_fmr = dev->lk_table.max; 1296 rdi->dparms.props.max_srq = hfi1_max_srqs;
1396 props->max_map_per_fmr = 32767; 1297 rdi->dparms.props.max_srq_wr = hfi1_max_srq_wrs;
1397 props->max_pd = hfi1_max_pds; 1298 rdi->dparms.props.max_srq_sge = hfi1_max_srq_sges;
1398 props->max_qp_rd_atom = HFI1_MAX_RDMA_ATOMIC; 1299 rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB;
1399 props->max_qp_init_rd_atom = 255; 1300 rdi->dparms.props.max_pkeys = hfi1_get_npkeys(dd);
1400 /* props->max_res_rd_atom */ 1301 rdi->dparms.props.max_mcast_grp = hfi1_max_mcast_grps;
1401 props->max_srq = hfi1_max_srqs; 1302 rdi->dparms.props.max_mcast_qp_attach = hfi1_max_mcast_qp_attached;
1402 props->max_srq_wr = hfi1_max_srq_wrs; 1303 rdi->dparms.props.max_total_mcast_qp_attach =
1403 props->max_srq_sge = hfi1_max_srq_sges; 1304 rdi->dparms.props.max_mcast_qp_attach *
1404 /* props->local_ca_ack_delay */ 1305 rdi->dparms.props.max_mcast_grp;
1405 props->atomic_cap = IB_ATOMIC_GLOB;
1406 props->max_pkeys = hfi1_get_npkeys(dd);
1407 props->max_mcast_grp = hfi1_max_mcast_grps;
1408 props->max_mcast_qp_attach = hfi1_max_mcast_qp_attached;
1409 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
1410 props->max_mcast_grp;
1411
1412 return 0;
1413} 1306}
1414 1307
1415static inline u16 opa_speed_to_ib(u16 in) 1308static inline u16 opa_speed_to_ib(u16 in)
@@ -1443,33 +1336,24 @@ static inline u16 opa_width_to_ib(u16 in)
1443 } 1336 }
1444} 1337}
1445 1338
1446static int query_port(struct ib_device *ibdev, u8 port, 1339static int query_port(struct rvt_dev_info *rdi, u8 port_num,
1447 struct ib_port_attr *props) 1340 struct ib_port_attr *props)
1448{ 1341{
1449 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1342 struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
1450 struct hfi1_ibport *ibp = to_iport(ibdev, port); 1343 struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
1451 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 1344 struct hfi1_pportdata *ppd = &dd->pport[port_num - 1];
1452 u16 lid = ppd->lid; 1345 u16 lid = ppd->lid;
1453 1346
1454 memset(props, 0, sizeof(*props));
1455 props->lid = lid ? lid : 0; 1347 props->lid = lid ? lid : 0;
1456 props->lmc = ppd->lmc; 1348 props->lmc = ppd->lmc;
1457 props->sm_lid = ibp->sm_lid;
1458 props->sm_sl = ibp->sm_sl;
1459 /* OPA logical states match IB logical states */ 1349 /* OPA logical states match IB logical states */
1460 props->state = driver_lstate(ppd); 1350 props->state = driver_lstate(ppd);
1461 props->phys_state = hfi1_ibphys_portstate(ppd); 1351 props->phys_state = hfi1_ibphys_portstate(ppd);
1462 props->port_cap_flags = ibp->port_cap_flags;
1463 props->gid_tbl_len = HFI1_GUIDS_PER_PORT; 1352 props->gid_tbl_len = HFI1_GUIDS_PER_PORT;
1464 props->max_msg_sz = 0x80000000;
1465 props->pkey_tbl_len = hfi1_get_npkeys(dd);
1466 props->bad_pkey_cntr = ibp->pkey_violations;
1467 props->qkey_viol_cntr = ibp->qkey_violations;
1468 props->active_width = (u8)opa_width_to_ib(ppd->link_width_active); 1353 props->active_width = (u8)opa_width_to_ib(ppd->link_width_active);
1469 /* see rate_show() in ib core/sysfs.c */ 1354 /* see rate_show() in ib core/sysfs.c */
1470 props->active_speed = (u8)opa_speed_to_ib(ppd->link_speed_active); 1355 props->active_speed = (u8)opa_speed_to_ib(ppd->link_speed_active);
1471 props->max_vl_num = ppd->vls_supported; 1356 props->max_vl_num = ppd->vls_supported;
1472 props->init_type_reply = 0;
1473 1357
1474 /* Once we are a "first class" citizen and have added the OPA MTUs to 1358 /* Once we are a "first class" citizen and have added the OPA MTUs to
1475 * the core we can advertise the larger MTU enum to the ULPs, for now 1359 * the core we can advertise the larger MTU enum to the ULPs, for now
@@ -1483,27 +1367,6 @@ static int query_port(struct ib_device *ibdev, u8 port,
1483 4096 : hfi1_max_mtu), IB_MTU_4096); 1367 4096 : hfi1_max_mtu), IB_MTU_4096);
1484 props->active_mtu = !valid_ib_mtu(ppd->ibmtu) ? props->max_mtu : 1368 props->active_mtu = !valid_ib_mtu(ppd->ibmtu) ? props->max_mtu :
1485 mtu_to_enum(ppd->ibmtu, IB_MTU_2048); 1369 mtu_to_enum(ppd->ibmtu, IB_MTU_2048);
1486 props->subnet_timeout = ibp->subnet_timeout;
1487
1488 return 0;
1489}
1490
1491static int port_immutable(struct ib_device *ibdev, u8 port_num,
1492 struct ib_port_immutable *immutable)
1493{
1494 struct ib_port_attr attr;
1495 int err;
1496
1497 err = query_port(ibdev, port_num, &attr);
1498 if (err)
1499 return err;
1500
1501 memset(immutable, 0, sizeof(*immutable));
1502
1503 immutable->pkey_tbl_len = attr.pkey_tbl_len;
1504 immutable->gid_tbl_len = attr.gid_tbl_len;
1505 immutable->core_cap_flags = RDMA_CORE_PORT_INTEL_OPA;
1506 immutable->max_mad_size = OPA_MGMT_MAD_SIZE;
1507 1370
1508 return 0; 1371 return 0;
1509} 1372}
@@ -1547,102 +1410,31 @@ bail:
1547 return ret; 1410 return ret;
1548} 1411}
1549 1412
1550static int modify_port(struct ib_device *ibdev, u8 port, 1413static int shut_down_port(struct rvt_dev_info *rdi, u8 port_num)
1551 int port_modify_mask, struct ib_port_modify *props)
1552{
1553 struct hfi1_ibport *ibp = to_iport(ibdev, port);
1554 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1555 int ret = 0;
1556
1557 ibp->port_cap_flags |= props->set_port_cap_mask;
1558 ibp->port_cap_flags &= ~props->clr_port_cap_mask;
1559 if (props->set_port_cap_mask || props->clr_port_cap_mask)
1560 hfi1_cap_mask_chg(ibp);
1561 if (port_modify_mask & IB_PORT_SHUTDOWN) {
1562 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_UNKNOWN, 0,
1563 OPA_LINKDOWN_REASON_UNKNOWN);
1564 ret = set_link_state(ppd, HLS_DN_DOWNDEF);
1565 }
1566 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
1567 ibp->qkey_violations = 0;
1568 return ret;
1569}
1570
1571static int query_gid(struct ib_device *ibdev, u8 port,
1572 int index, union ib_gid *gid)
1573{ 1414{
1574 struct hfi1_devdata *dd = dd_from_ibdev(ibdev); 1415 struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
1575 int ret = 0; 1416 struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
1576 1417 struct hfi1_pportdata *ppd = &dd->pport[port_num - 1];
1577 if (!port || port > dd->num_pports) 1418 int ret;
1578 ret = -EINVAL;
1579 else {
1580 struct hfi1_ibport *ibp = to_iport(ibdev, port);
1581 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1582
1583 gid->global.subnet_prefix = ibp->gid_prefix;
1584 if (index == 0)
1585 gid->global.interface_id = cpu_to_be64(ppd->guid);
1586 else if (index < HFI1_GUIDS_PER_PORT)
1587 gid->global.interface_id = ibp->guids[index - 1];
1588 else
1589 ret = -EINVAL;
1590 }
1591
1592 return ret;
1593}
1594
1595static struct ib_pd *alloc_pd(struct ib_device *ibdev,
1596 struct ib_ucontext *context,
1597 struct ib_udata *udata)
1598{
1599 struct hfi1_ibdev *dev = to_idev(ibdev);
1600 struct hfi1_pd *pd;
1601 struct ib_pd *ret;
1602
1603 /*
1604 * This is actually totally arbitrary. Some correctness tests
1605 * assume there's a maximum number of PDs that can be allocated.
1606 * We don't actually have this limit, but we fail the test if
1607 * we allow allocations of more than we report for this value.
1608 */
1609
1610 pd = kmalloc(sizeof(*pd), GFP_KERNEL);
1611 if (!pd) {
1612 ret = ERR_PTR(-ENOMEM);
1613 goto bail;
1614 }
1615
1616 spin_lock(&dev->n_pds_lock);
1617 if (dev->n_pds_allocated == hfi1_max_pds) {
1618 spin_unlock(&dev->n_pds_lock);
1619 kfree(pd);
1620 ret = ERR_PTR(-ENOMEM);
1621 goto bail;
1622 }
1623
1624 dev->n_pds_allocated++;
1625 spin_unlock(&dev->n_pds_lock);
1626
1627 /* ib_alloc_pd() will initialize pd->ibpd. */
1628 pd->user = udata != NULL;
1629
1630 ret = &pd->ibpd;
1631 1419
1632bail: 1420 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_UNKNOWN, 0,
1421 OPA_LINKDOWN_REASON_UNKNOWN);
1422 ret = set_link_state(ppd, HLS_DN_DOWNDEF);
1633 return ret; 1423 return ret;
1634} 1424}
1635 1425
1636static int dealloc_pd(struct ib_pd *ibpd) 1426static int hfi1_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
1427 int guid_index, __be64 *guid)
1637{ 1428{
1638 struct hfi1_pd *pd = to_ipd(ibpd); 1429 struct hfi1_ibport *ibp = container_of(rvp, struct hfi1_ibport, rvp);
1639 struct hfi1_ibdev *dev = to_idev(ibpd->device); 1430 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1640
1641 spin_lock(&dev->n_pds_lock);
1642 dev->n_pds_allocated--;
1643 spin_unlock(&dev->n_pds_lock);
1644 1431
1645 kfree(pd); 1432 if (guid_index == 0)
1433 *guid = cpu_to_be64(ppd->guid);
1434 else if (guid_index < HFI1_GUIDS_PER_PORT)
1435 *guid = ibp->guids[guid_index - 1];
1436 else
1437 return -EINVAL;
1646 1438
1647 return 0; 1439 return 0;
1648} 1440}
@@ -1657,101 +1449,57 @@ u8 ah_to_sc(struct ib_device *ibdev, struct ib_ah_attr *ah)
1657 return ibp->sl_to_sc[ah->sl]; 1449 return ibp->sl_to_sc[ah->sl];
1658} 1450}
1659 1451
1660int hfi1_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr) 1452static int hfi1_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr)
1661{ 1453{
1662 struct hfi1_ibport *ibp; 1454 struct hfi1_ibport *ibp;
1663 struct hfi1_pportdata *ppd; 1455 struct hfi1_pportdata *ppd;
1664 struct hfi1_devdata *dd; 1456 struct hfi1_devdata *dd;
1665 u8 sc5; 1457 u8 sc5;
1666 1458
1667 /* A multicast address requires a GRH (see ch. 8.4.1). */
1668 if (ah_attr->dlid >= HFI1_MULTICAST_LID_BASE &&
1669 ah_attr->dlid != HFI1_PERMISSIVE_LID &&
1670 !(ah_attr->ah_flags & IB_AH_GRH))
1671 goto bail;
1672 if ((ah_attr->ah_flags & IB_AH_GRH) &&
1673 ah_attr->grh.sgid_index >= HFI1_GUIDS_PER_PORT)
1674 goto bail;
1675 if (ah_attr->dlid == 0)
1676 goto bail;
1677 if (ah_attr->port_num < 1 ||
1678 ah_attr->port_num > ibdev->phys_port_cnt)
1679 goto bail;
1680 if (ah_attr->static_rate != IB_RATE_PORT_CURRENT &&
1681 ib_rate_to_mbps(ah_attr->static_rate) < 0)
1682 goto bail;
1683 if (ah_attr->sl >= OPA_MAX_SLS)
1684 goto bail;
1685 /* test the mapping for validity */ 1459 /* test the mapping for validity */
1686 ibp = to_iport(ibdev, ah_attr->port_num); 1460 ibp = to_iport(ibdev, ah_attr->port_num);
1687 ppd = ppd_from_ibp(ibp); 1461 ppd = ppd_from_ibp(ibp);
1688 sc5 = ibp->sl_to_sc[ah_attr->sl]; 1462 sc5 = ibp->sl_to_sc[ah_attr->sl];
1689 dd = dd_from_ppd(ppd); 1463 dd = dd_from_ppd(ppd);
1690 if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf) 1464 if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf)
1691 goto bail; 1465 return -EINVAL;
1692 return 0; 1466 return 0;
1693bail:
1694 return -EINVAL;
1695} 1467}
1696 1468
1697/** 1469static void hfi1_notify_new_ah(struct ib_device *ibdev,
1698 * create_ah - create an address handle 1470 struct ib_ah_attr *ah_attr,
1699 * @pd: the protection domain 1471 struct rvt_ah *ah)
1700 * @ah_attr: the attributes of the AH
1701 *
1702 * This may be called from interrupt context.
1703 */
1704static struct ib_ah *create_ah(struct ib_pd *pd,
1705 struct ib_ah_attr *ah_attr)
1706{ 1472{
1707 struct hfi1_ah *ah; 1473 struct hfi1_ibport *ibp;
1708 struct ib_ah *ret; 1474 struct hfi1_pportdata *ppd;
1709 struct hfi1_ibdev *dev = to_idev(pd->device); 1475 struct hfi1_devdata *dd;
1710 unsigned long flags; 1476 u8 sc5;
1711
1712 if (hfi1_check_ah(pd->device, ah_attr)) {
1713 ret = ERR_PTR(-EINVAL);
1714 goto bail;
1715 }
1716
1717 ah = kmalloc(sizeof(*ah), GFP_ATOMIC);
1718 if (!ah) {
1719 ret = ERR_PTR(-ENOMEM);
1720 goto bail;
1721 }
1722
1723 spin_lock_irqsave(&dev->n_ahs_lock, flags);
1724 if (dev->n_ahs_allocated == hfi1_max_ahs) {
1725 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1726 kfree(ah);
1727 ret = ERR_PTR(-ENOMEM);
1728 goto bail;
1729 }
1730
1731 dev->n_ahs_allocated++;
1732 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1733
1734 /* ib_create_ah() will initialize ah->ibah. */
1735 ah->attr = *ah_attr;
1736 atomic_set(&ah->refcount, 0);
1737 1477
1738 ret = &ah->ibah; 1478 /*
1479 * Do not trust reading anything from rvt_ah at this point as it is not
1480 * done being setup. We can however modify things which we need to set.
1481 */
1739 1482
1740bail: 1483 ibp = to_iport(ibdev, ah_attr->port_num);
1741 return ret; 1484 ppd = ppd_from_ibp(ibp);
1485 sc5 = ibp->sl_to_sc[ah->attr.sl];
1486 dd = dd_from_ppd(ppd);
1487 ah->vl = sc_to_vlt(dd, sc5);
1488 if (ah->vl < num_vls || ah->vl == 15)
1489 ah->log_pmtu = ilog2(dd->vld[ah->vl].mtu);
1742} 1490}
1743 1491
1744struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u16 dlid) 1492struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u16 dlid)
1745{ 1493{
1746 struct ib_ah_attr attr; 1494 struct ib_ah_attr attr;
1747 struct ib_ah *ah = ERR_PTR(-EINVAL); 1495 struct ib_ah *ah = ERR_PTR(-EINVAL);
1748 struct hfi1_qp *qp0; 1496 struct rvt_qp *qp0;
1749 1497
1750 memset(&attr, 0, sizeof(attr)); 1498 memset(&attr, 0, sizeof(attr));
1751 attr.dlid = dlid; 1499 attr.dlid = dlid;
1752 attr.port_num = ppd_from_ibp(ibp)->port; 1500 attr.port_num = ppd_from_ibp(ibp)->port;
1753 rcu_read_lock(); 1501 rcu_read_lock();
1754 qp0 = rcu_dereference(ibp->qp[0]); 1502 qp0 = rcu_dereference(ibp->rvp.qp[0]);
1755 if (qp0) 1503 if (qp0)
1756 ah = ib_create_ah(qp0->ibqp.pd, &attr); 1504 ah = ib_create_ah(qp0->ibqp.pd, &attr);
1757 rcu_read_unlock(); 1505 rcu_read_unlock();
@@ -1759,51 +1507,6 @@ struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u16 dlid)
1759} 1507}
1760 1508
1761/** 1509/**
1762 * destroy_ah - destroy an address handle
1763 * @ibah: the AH to destroy
1764 *
1765 * This may be called from interrupt context.
1766 */
1767static int destroy_ah(struct ib_ah *ibah)
1768{
1769 struct hfi1_ibdev *dev = to_idev(ibah->device);
1770 struct hfi1_ah *ah = to_iah(ibah);
1771 unsigned long flags;
1772
1773 if (atomic_read(&ah->refcount) != 0)
1774 return -EBUSY;
1775
1776 spin_lock_irqsave(&dev->n_ahs_lock, flags);
1777 dev->n_ahs_allocated--;
1778 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1779
1780 kfree(ah);
1781
1782 return 0;
1783}
1784
1785static int modify_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1786{
1787 struct hfi1_ah *ah = to_iah(ibah);
1788
1789 if (hfi1_check_ah(ibah->device, ah_attr))
1790 return -EINVAL;
1791
1792 ah->attr = *ah_attr;
1793
1794 return 0;
1795}
1796
1797static int query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1798{
1799 struct hfi1_ah *ah = to_iah(ibah);
1800
1801 *ah_attr = ah->attr;
1802
1803 return 0;
1804}
1805
1806/**
1807 * hfi1_get_npkeys - return the size of the PKEY table for context 0 1510 * hfi1_get_npkeys - return the size of the PKEY table for context 0
1808 * @dd: the hfi1_ib device 1511 * @dd: the hfi1_ib device
1809 */ 1512 */
@@ -1812,54 +1515,6 @@ unsigned hfi1_get_npkeys(struct hfi1_devdata *dd)
1812 return ARRAY_SIZE(dd->pport[0].pkeys); 1515 return ARRAY_SIZE(dd->pport[0].pkeys);
1813} 1516}
1814 1517
1815static int query_pkey(struct ib_device *ibdev, u8 port, u16 index,
1816 u16 *pkey)
1817{
1818 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1819 int ret;
1820
1821 if (index >= hfi1_get_npkeys(dd)) {
1822 ret = -EINVAL;
1823 goto bail;
1824 }
1825
1826 *pkey = hfi1_get_pkey(to_iport(ibdev, port), index);
1827 ret = 0;
1828
1829bail:
1830 return ret;
1831}
1832
1833/**
1834 * alloc_ucontext - allocate a ucontest
1835 * @ibdev: the infiniband device
1836 * @udata: not used by the driver
1837 */
1838
1839static struct ib_ucontext *alloc_ucontext(struct ib_device *ibdev,
1840 struct ib_udata *udata)
1841{
1842 struct hfi1_ucontext *context;
1843 struct ib_ucontext *ret;
1844
1845 context = kmalloc(sizeof(*context), GFP_KERNEL);
1846 if (!context) {
1847 ret = ERR_PTR(-ENOMEM);
1848 goto bail;
1849 }
1850
1851 ret = &context->ibucontext;
1852
1853bail:
1854 return ret;
1855}
1856
1857static int dealloc_ucontext(struct ib_ucontext *context)
1858{
1859 kfree(to_iucontext(context));
1860 return 0;
1861}
1862
1863static void init_ibport(struct hfi1_pportdata *ppd) 1518static void init_ibport(struct hfi1_pportdata *ppd)
1864{ 1519{
1865 struct hfi1_ibport *ibp = &ppd->ibport_data; 1520 struct hfi1_ibport *ibp = &ppd->ibport_data;
@@ -1871,28 +1526,21 @@ static void init_ibport(struct hfi1_pportdata *ppd)
1871 ibp->sc_to_sl[i] = i; 1526 ibp->sc_to_sl[i] = i;
1872 } 1527 }
1873 1528
1874 spin_lock_init(&ibp->lock); 1529 spin_lock_init(&ibp->rvp.lock);
1875 /* Set the prefix to the default value (see ch. 4.1.1) */ 1530 /* Set the prefix to the default value (see ch. 4.1.1) */
1876 ibp->gid_prefix = IB_DEFAULT_GID_PREFIX; 1531 ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX;
1877 ibp->sm_lid = 0; 1532 ibp->rvp.sm_lid = 0;
1878 /* Below should only set bits defined in OPA PortInfo.CapabilityMask */ 1533 /* Below should only set bits defined in OPA PortInfo.CapabilityMask */
1879 ibp->port_cap_flags = IB_PORT_AUTO_MIGR_SUP | 1534 ibp->rvp.port_cap_flags = IB_PORT_AUTO_MIGR_SUP |
1880 IB_PORT_CAP_MASK_NOTICE_SUP; 1535 IB_PORT_CAP_MASK_NOTICE_SUP;
1881 ibp->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA; 1536 ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
1882 ibp->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA; 1537 ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
1883 ibp->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS; 1538 ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
1884 ibp->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS; 1539 ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
1885 ibp->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT; 1540 ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
1886 1541
1887 RCU_INIT_POINTER(ibp->qp[0], NULL); 1542 RCU_INIT_POINTER(ibp->rvp.qp[0], NULL);
1888 RCU_INIT_POINTER(ibp->qp[1], NULL); 1543 RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
1889}
1890
1891static void verbs_txreq_kmem_cache_ctor(void *obj)
1892{
1893 struct verbs_txreq *tx = obj;
1894
1895 memset(tx, 0, sizeof(*tx));
1896} 1544}
1897 1545
1898/** 1546/**
@@ -1903,74 +1551,26 @@ static void verbs_txreq_kmem_cache_ctor(void *obj)
1903int hfi1_register_ib_device(struct hfi1_devdata *dd) 1551int hfi1_register_ib_device(struct hfi1_devdata *dd)
1904{ 1552{
1905 struct hfi1_ibdev *dev = &dd->verbs_dev; 1553 struct hfi1_ibdev *dev = &dd->verbs_dev;
1906 struct ib_device *ibdev = &dev->ibdev; 1554 struct ib_device *ibdev = &dev->rdi.ibdev;
1907 struct hfi1_pportdata *ppd = dd->pport; 1555 struct hfi1_pportdata *ppd = dd->pport;
1908 unsigned i, lk_tab_size; 1556 unsigned i;
1909 int ret; 1557 int ret;
1910 size_t lcpysz = IB_DEVICE_NAME_MAX; 1558 size_t lcpysz = IB_DEVICE_NAME_MAX;
1911 u16 descq_cnt;
1912 char buf[TXREQ_NAME_LEN];
1913
1914 ret = hfi1_qp_init(dev);
1915 if (ret)
1916 goto err_qp_init;
1917
1918 1559
1919 for (i = 0; i < dd->num_pports; i++) 1560 for (i = 0; i < dd->num_pports; i++)
1920 init_ibport(ppd + i); 1561 init_ibport(ppd + i);
1921 1562
1922 /* Only need to initialize non-zero fields. */ 1563 /* Only need to initialize non-zero fields. */
1923 spin_lock_init(&dev->n_pds_lock); 1564
1924 spin_lock_init(&dev->n_ahs_lock);
1925 spin_lock_init(&dev->n_cqs_lock);
1926 spin_lock_init(&dev->n_qps_lock);
1927 spin_lock_init(&dev->n_srqs_lock);
1928 spin_lock_init(&dev->n_mcast_grps_lock);
1929 setup_timer(&dev->mem_timer, mem_timer, (unsigned long)dev); 1565 setup_timer(&dev->mem_timer, mem_timer, (unsigned long)dev);
1930 1566
1931 /*
1932 * The top hfi1_lkey_table_size bits are used to index the
1933 * table. The lower 8 bits can be owned by the user (copied from
1934 * the LKEY). The remaining bits act as a generation number or tag.
1935 */
1936 spin_lock_init(&dev->lk_table.lock);
1937 dev->lk_table.max = 1 << hfi1_lkey_table_size;
1938 /* ensure generation is at least 4 bits (keys.c) */
1939 if (hfi1_lkey_table_size > MAX_LKEY_TABLE_BITS) {
1940 dd_dev_warn(dd, "lkey bits %u too large, reduced to %u\n",
1941 hfi1_lkey_table_size, MAX_LKEY_TABLE_BITS);
1942 hfi1_lkey_table_size = MAX_LKEY_TABLE_BITS;
1943 }
1944 lk_tab_size = dev->lk_table.max * sizeof(*dev->lk_table.table);
1945 dev->lk_table.table = (struct hfi1_mregion __rcu **)
1946 vmalloc(lk_tab_size);
1947 if (dev->lk_table.table == NULL) {
1948 ret = -ENOMEM;
1949 goto err_lk;
1950 }
1951 RCU_INIT_POINTER(dev->dma_mr, NULL);
1952 for (i = 0; i < dev->lk_table.max; i++)
1953 RCU_INIT_POINTER(dev->lk_table.table[i], NULL);
1954 INIT_LIST_HEAD(&dev->pending_mmaps);
1955 spin_lock_init(&dev->pending_lock);
1956 seqlock_init(&dev->iowait_lock); 1567 seqlock_init(&dev->iowait_lock);
1957 dev->mmap_offset = PAGE_SIZE;
1958 spin_lock_init(&dev->mmap_offset_lock);
1959 INIT_LIST_HEAD(&dev->txwait); 1568 INIT_LIST_HEAD(&dev->txwait);
1960 INIT_LIST_HEAD(&dev->memwait); 1569 INIT_LIST_HEAD(&dev->memwait);
1961 1570
1962 descq_cnt = sdma_get_descq_cnt(); 1571 ret = verbs_txreq_init(dev);
1963 1572 if (ret)
1964 snprintf(buf, sizeof(buf), "hfi1_%u_vtxreq_cache", dd->unit);
1965 /* SLAB_HWCACHE_ALIGN for AHG */
1966 dev->verbs_txreq_cache = kmem_cache_create(buf,
1967 sizeof(struct verbs_txreq),
1968 0, SLAB_HWCACHE_ALIGN,
1969 verbs_txreq_kmem_cache_ctor);
1970 if (!dev->verbs_txreq_cache) {
1971 ret = -ENOMEM;
1972 goto err_verbs_txreq; 1573 goto err_verbs_txreq;
1973 }
1974 1574
1975 /* 1575 /*
1976 * The system image GUID is supposed to be the same for all 1576 * The system image GUID is supposed to be the same for all
@@ -1983,142 +1583,119 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
1983 strlcpy(ibdev->name + lcpysz, "_%d", IB_DEVICE_NAME_MAX - lcpysz); 1583 strlcpy(ibdev->name + lcpysz, "_%d", IB_DEVICE_NAME_MAX - lcpysz);
1984 ibdev->owner = THIS_MODULE; 1584 ibdev->owner = THIS_MODULE;
1985 ibdev->node_guid = cpu_to_be64(ppd->guid); 1585 ibdev->node_guid = cpu_to_be64(ppd->guid);
1986 ibdev->uverbs_abi_ver = HFI1_UVERBS_ABI_VERSION;
1987 ibdev->uverbs_cmd_mask =
1988 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
1989 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
1990 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
1991 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
1992 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
1993 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
1994 (1ull << IB_USER_VERBS_CMD_MODIFY_AH) |
1995 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
1996 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
1997 (1ull << IB_USER_VERBS_CMD_REG_MR) |
1998 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
1999 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
2000 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
2001 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
2002 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
2003 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
2004 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
2005 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
2006 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
2007 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
2008 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
2009 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
2010 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
2011 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
2012 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
2013 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
2014 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
2015 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
2016 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
2017 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
2018 ibdev->node_type = RDMA_NODE_IB_CA;
2019 ibdev->phys_port_cnt = dd->num_pports; 1586 ibdev->phys_port_cnt = dd->num_pports;
2020 ibdev->num_comp_vectors = 1;
2021 ibdev->dma_device = &dd->pcidev->dev; 1587 ibdev->dma_device = &dd->pcidev->dev;
2022 ibdev->query_device = query_device;
2023 ibdev->modify_device = modify_device; 1588 ibdev->modify_device = modify_device;
2024 ibdev->query_port = query_port; 1589
2025 ibdev->modify_port = modify_port; 1590 /* keep process mad in the driver */
2026 ibdev->query_pkey = query_pkey;
2027 ibdev->query_gid = query_gid;
2028 ibdev->alloc_ucontext = alloc_ucontext;
2029 ibdev->dealloc_ucontext = dealloc_ucontext;
2030 ibdev->alloc_pd = alloc_pd;
2031 ibdev->dealloc_pd = dealloc_pd;
2032 ibdev->create_ah = create_ah;
2033 ibdev->destroy_ah = destroy_ah;
2034 ibdev->modify_ah = modify_ah;
2035 ibdev->query_ah = query_ah;
2036 ibdev->create_srq = hfi1_create_srq;
2037 ibdev->modify_srq = hfi1_modify_srq;
2038 ibdev->query_srq = hfi1_query_srq;
2039 ibdev->destroy_srq = hfi1_destroy_srq;
2040 ibdev->create_qp = hfi1_create_qp;
2041 ibdev->modify_qp = hfi1_modify_qp;
2042 ibdev->query_qp = hfi1_query_qp;
2043 ibdev->destroy_qp = hfi1_destroy_qp;
2044 ibdev->post_send = post_send;
2045 ibdev->post_recv = post_receive;
2046 ibdev->post_srq_recv = hfi1_post_srq_receive;
2047 ibdev->create_cq = hfi1_create_cq;
2048 ibdev->destroy_cq = hfi1_destroy_cq;
2049 ibdev->resize_cq = hfi1_resize_cq;
2050 ibdev->poll_cq = hfi1_poll_cq;
2051 ibdev->req_notify_cq = hfi1_req_notify_cq;
2052 ibdev->get_dma_mr = hfi1_get_dma_mr;
2053 ibdev->reg_user_mr = hfi1_reg_user_mr;
2054 ibdev->dereg_mr = hfi1_dereg_mr;
2055 ibdev->alloc_mr = hfi1_alloc_mr;
2056 ibdev->alloc_fmr = hfi1_alloc_fmr;
2057 ibdev->map_phys_fmr = hfi1_map_phys_fmr;
2058 ibdev->unmap_fmr = hfi1_unmap_fmr;
2059 ibdev->dealloc_fmr = hfi1_dealloc_fmr;
2060 ibdev->attach_mcast = hfi1_multicast_attach;
2061 ibdev->detach_mcast = hfi1_multicast_detach;
2062 ibdev->process_mad = hfi1_process_mad; 1591 ibdev->process_mad = hfi1_process_mad;
2063 ibdev->mmap = hfi1_mmap;
2064 ibdev->dma_ops = &hfi1_dma_mapping_ops;
2065 ibdev->get_port_immutable = port_immutable;
2066 1592
2067 strncpy(ibdev->node_desc, init_utsname()->nodename, 1593 strncpy(ibdev->node_desc, init_utsname()->nodename,
2068 sizeof(ibdev->node_desc)); 1594 sizeof(ibdev->node_desc));
2069 1595
2070 ret = ib_register_device(ibdev, hfi1_create_port_files); 1596 /*
2071 if (ret) 1597 * Fill in rvt info object.
2072 goto err_reg; 1598 */
2073 1599 dd->verbs_dev.rdi.driver_f.port_callback = hfi1_create_port_files;
2074 ret = hfi1_create_agents(dev); 1600 dd->verbs_dev.rdi.driver_f.get_card_name = get_card_name;
1601 dd->verbs_dev.rdi.driver_f.get_pci_dev = get_pci_dev;
1602 dd->verbs_dev.rdi.driver_f.check_ah = hfi1_check_ah;
1603 dd->verbs_dev.rdi.driver_f.notify_new_ah = hfi1_notify_new_ah;
1604 dd->verbs_dev.rdi.driver_f.get_guid_be = hfi1_get_guid_be;
1605 dd->verbs_dev.rdi.driver_f.query_port_state = query_port;
1606 dd->verbs_dev.rdi.driver_f.shut_down_port = shut_down_port;
1607 dd->verbs_dev.rdi.driver_f.cap_mask_chg = hfi1_cap_mask_chg;
1608 /*
1609 * Fill in rvt info device attributes.
1610 */
1611 hfi1_fill_device_attr(dd);
1612
1613 /* queue pair */
1614 dd->verbs_dev.rdi.dparms.qp_table_size = hfi1_qp_table_size;
1615 dd->verbs_dev.rdi.dparms.qpn_start = 0;
1616 dd->verbs_dev.rdi.dparms.qpn_inc = 1;
1617 dd->verbs_dev.rdi.dparms.qos_shift = dd->qos_shift;
1618 dd->verbs_dev.rdi.dparms.qpn_res_start = kdeth_qp << 16;
1619 dd->verbs_dev.rdi.dparms.qpn_res_end =
1620 dd->verbs_dev.rdi.dparms.qpn_res_start + 65535;
1621 dd->verbs_dev.rdi.dparms.max_rdma_atomic = HFI1_MAX_RDMA_ATOMIC;
1622 dd->verbs_dev.rdi.dparms.psn_mask = PSN_MASK;
1623 dd->verbs_dev.rdi.dparms.psn_shift = PSN_SHIFT;
1624 dd->verbs_dev.rdi.dparms.psn_modify_mask = PSN_MODIFY_MASK;
1625 dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_INTEL_OPA;
1626 dd->verbs_dev.rdi.dparms.max_mad_size = OPA_MGMT_MAD_SIZE;
1627
1628 dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qp_priv_alloc;
1629 dd->verbs_dev.rdi.driver_f.qp_priv_free = qp_priv_free;
1630 dd->verbs_dev.rdi.driver_f.free_all_qps = free_all_qps;
1631 dd->verbs_dev.rdi.driver_f.notify_qp_reset = notify_qp_reset;
1632 dd->verbs_dev.rdi.driver_f.do_send = hfi1_do_send;
1633 dd->verbs_dev.rdi.driver_f.schedule_send = hfi1_schedule_send;
1634 dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _hfi1_schedule_send;
1635 dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = get_pmtu_from_attr;
1636 dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp;
1637 dd->verbs_dev.rdi.driver_f.flush_qp_waiters = flush_qp_waiters;
1638 dd->verbs_dev.rdi.driver_f.stop_send_queue = stop_send_queue;
1639 dd->verbs_dev.rdi.driver_f.quiesce_qp = quiesce_qp;
1640 dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp;
1641 dd->verbs_dev.rdi.driver_f.mtu_from_qp = mtu_from_qp;
1642 dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = mtu_to_path_mtu;
1643 dd->verbs_dev.rdi.driver_f.check_modify_qp = hfi1_check_modify_qp;
1644 dd->verbs_dev.rdi.driver_f.modify_qp = hfi1_modify_qp;
1645 dd->verbs_dev.rdi.driver_f.check_send_wqe = hfi1_check_send_wqe;
1646
1647 /* completeion queue */
1648 snprintf(dd->verbs_dev.rdi.dparms.cq_name,
1649 sizeof(dd->verbs_dev.rdi.dparms.cq_name),
1650 "hfi1_cq%d", dd->unit);
1651 dd->verbs_dev.rdi.dparms.node = dd->node;
1652
1653 /* misc settings */
1654 dd->verbs_dev.rdi.flags = 0; /* Let rdmavt handle it all */
1655 dd->verbs_dev.rdi.dparms.lkey_table_size = hfi1_lkey_table_size;
1656 dd->verbs_dev.rdi.dparms.nports = dd->num_pports;
1657 dd->verbs_dev.rdi.dparms.npkeys = hfi1_get_npkeys(dd);
1658
1659 ppd = dd->pport;
1660 for (i = 0; i < dd->num_pports; i++, ppd++)
1661 rvt_init_port(&dd->verbs_dev.rdi,
1662 &ppd->ibport_data.rvp,
1663 i,
1664 ppd->pkeys);
1665
1666 ret = rvt_register_device(&dd->verbs_dev.rdi);
2075 if (ret) 1667 if (ret)
2076 goto err_agents; 1668 goto err_verbs_txreq;
2077 1669
2078 ret = hfi1_verbs_register_sysfs(dd); 1670 ret = hfi1_verbs_register_sysfs(dd);
2079 if (ret) 1671 if (ret)
2080 goto err_class; 1672 goto err_class;
2081 1673
2082 goto bail; 1674 return ret;
2083 1675
2084err_class: 1676err_class:
2085 hfi1_free_agents(dev); 1677 rvt_unregister_device(&dd->verbs_dev.rdi);
2086err_agents:
2087 ib_unregister_device(ibdev);
2088err_reg:
2089err_verbs_txreq: 1678err_verbs_txreq:
2090 kmem_cache_destroy(dev->verbs_txreq_cache); 1679 verbs_txreq_exit(dev);
2091 vfree(dev->lk_table.table);
2092err_lk:
2093 hfi1_qp_exit(dev);
2094err_qp_init:
2095 dd_dev_err(dd, "cannot register verbs: %d!\n", -ret); 1680 dd_dev_err(dd, "cannot register verbs: %d!\n", -ret);
2096bail:
2097 return ret; 1681 return ret;
2098} 1682}
2099 1683
2100void hfi1_unregister_ib_device(struct hfi1_devdata *dd) 1684void hfi1_unregister_ib_device(struct hfi1_devdata *dd)
2101{ 1685{
2102 struct hfi1_ibdev *dev = &dd->verbs_dev; 1686 struct hfi1_ibdev *dev = &dd->verbs_dev;
2103 struct ib_device *ibdev = &dev->ibdev;
2104 1687
2105 hfi1_verbs_unregister_sysfs(dd); 1688 hfi1_verbs_unregister_sysfs(dd);
2106 1689
2107 hfi1_free_agents(dev); 1690 rvt_unregister_device(&dd->verbs_dev.rdi);
2108
2109 ib_unregister_device(ibdev);
2110 1691
2111 if (!list_empty(&dev->txwait)) 1692 if (!list_empty(&dev->txwait))
2112 dd_dev_err(dd, "txwait list not empty!\n"); 1693 dd_dev_err(dd, "txwait list not empty!\n");
2113 if (!list_empty(&dev->memwait)) 1694 if (!list_empty(&dev->memwait))
2114 dd_dev_err(dd, "memwait list not empty!\n"); 1695 dd_dev_err(dd, "memwait list not empty!\n");
2115 if (dev->dma_mr)
2116 dd_dev_err(dd, "DMA MR not NULL!\n");
2117 1696
2118 hfi1_qp_exit(dev);
2119 del_timer_sync(&dev->mem_timer); 1697 del_timer_sync(&dev->mem_timer);
2120 kmem_cache_destroy(dev->verbs_txreq_cache); 1698 verbs_txreq_exit(dev);
2121 vfree(dev->lk_table.table);
2122} 1699}
2123 1700
2124void hfi1_cnp_rcv(struct hfi1_packet *packet) 1701void hfi1_cnp_rcv(struct hfi1_packet *packet)
@@ -2126,7 +1703,7 @@ void hfi1_cnp_rcv(struct hfi1_packet *packet)
2126 struct hfi1_ibport *ibp = &packet->rcd->ppd->ibport_data; 1703 struct hfi1_ibport *ibp = &packet->rcd->ppd->ibport_data;
2127 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); 1704 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
2128 struct hfi1_ib_header *hdr = packet->hdr; 1705 struct hfi1_ib_header *hdr = packet->hdr;
2129 struct hfi1_qp *qp = packet->qp; 1706 struct rvt_qp *qp = packet->qp;
2130 u32 lqpn, rqpn = 0; 1707 u32 lqpn, rqpn = 0;
2131 u16 rlid = 0; 1708 u16 rlid = 0;
2132 u8 sl, sc5, sc4_bit, svc_type; 1709 u8 sl, sc5, sc4_bit, svc_type;
@@ -2149,7 +1726,7 @@ void hfi1_cnp_rcv(struct hfi1_packet *packet)
2149 svc_type = IB_CC_SVCTYPE_UD; 1726 svc_type = IB_CC_SVCTYPE_UD;
2150 break; 1727 break;
2151 default: 1728 default:
2152 ibp->n_pkt_drops++; 1729 ibp->rvp.n_pkt_drops++;
2153 return; 1730 return;
2154 } 1731 }
2155 1732
diff --git a/drivers/staging/rdma/hfi1/verbs.h b/drivers/staging/rdma/hfi1/verbs.h
index 286e468b0479..6c4670fffdbb 100644
--- a/drivers/staging/rdma/hfi1/verbs.h
+++ b/drivers/staging/rdma/hfi1/verbs.h
@@ -1,12 +1,11 @@
1/* 1/*
2 * Copyright(c) 2015, 2016 Intel Corporation.
2 * 3 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license. 5 * redistributing this file, you may do so under either license.
5 * 6 *
6 * GPL LICENSE SUMMARY 7 * GPL LICENSE SUMMARY
7 * 8 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 10 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -18,8 +17,6 @@
18 * 17 *
19 * BSD LICENSE 18 * BSD LICENSE
20 * 19 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without 20 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 21 * modification, are permitted provided that the following conditions
25 * are met: 22 * are met:
@@ -59,9 +56,13 @@
59#include <linux/workqueue.h> 56#include <linux/workqueue.h>
60#include <linux/kthread.h> 57#include <linux/kthread.h>
61#include <linux/completion.h> 58#include <linux/completion.h>
59#include <linux/slab.h>
62#include <rdma/ib_pack.h> 60#include <rdma/ib_pack.h>
63#include <rdma/ib_user_verbs.h> 61#include <rdma/ib_user_verbs.h>
64#include <rdma/ib_mad.h> 62#include <rdma/ib_mad.h>
63#include <rdma/rdma_vt.h>
64#include <rdma/rdmavt_qp.h>
65#include <rdma/rdmavt_cq.h>
65 66
66struct hfi1_ctxtdata; 67struct hfi1_ctxtdata;
67struct hfi1_pportdata; 68struct hfi1_pportdata;
@@ -79,12 +80,6 @@ struct hfi1_packet;
79 */ 80 */
80#define HFI1_UVERBS_ABI_VERSION 2 81#define HFI1_UVERBS_ABI_VERSION 2
81 82
82/*
83 * Define an ib_cq_notify value that is not valid so we know when CQ
84 * notifications are armed.
85 */
86#define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1)
87
88#define IB_SEQ_NAK (3 << 29) 83#define IB_SEQ_NAK (3 << 29)
89 84
90/* AETH NAK opcode values */ 85/* AETH NAK opcode values */
@@ -95,17 +90,6 @@ struct hfi1_packet;
95#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63 90#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
96#define IB_NAK_INVALID_RD_REQUEST 0x64 91#define IB_NAK_INVALID_RD_REQUEST 0x64
97 92
98/* Flags for checking QP state (see ib_hfi1_state_ops[]) */
99#define HFI1_POST_SEND_OK 0x01
100#define HFI1_POST_RECV_OK 0x02
101#define HFI1_PROCESS_RECV_OK 0x04
102#define HFI1_PROCESS_SEND_OK 0x08
103#define HFI1_PROCESS_NEXT_SEND_OK 0x10
104#define HFI1_FLUSH_SEND 0x20
105#define HFI1_FLUSH_RECV 0x40
106#define HFI1_PROCESS_OR_FLUSH_SEND \
107 (HFI1_PROCESS_SEND_OK | HFI1_FLUSH_SEND)
108
109/* IB Performance Manager status values */ 93/* IB Performance Manager status values */
110#define IB_PMA_SAMPLE_STATUS_DONE 0x00 94#define IB_PMA_SAMPLE_STATUS_DONE 0x00
111#define IB_PMA_SAMPLE_STATUS_STARTED 0x01 95#define IB_PMA_SAMPLE_STATUS_STARTED 0x01
@@ -208,341 +192,18 @@ struct hfi1_pio_header {
208} __packed; 192} __packed;
209 193
210/* 194/*
211 * used for force cacheline alignment for AHG 195 * hfi1 specific data structures that will be hidden from rvt after the queue
212 */ 196 * pair is made common
213struct tx_pio_header {
214 struct hfi1_pio_header phdr;
215} ____cacheline_aligned;
216
217/*
218 * There is one struct hfi1_mcast for each multicast GID.
219 * All attached QPs are then stored as a list of
220 * struct hfi1_mcast_qp.
221 */
222struct hfi1_mcast_qp {
223 struct list_head list;
224 struct hfi1_qp *qp;
225};
226
227struct hfi1_mcast {
228 struct rb_node rb_node;
229 union ib_gid mgid;
230 struct list_head qp_list;
231 wait_queue_head_t wait;
232 atomic_t refcount;
233 int n_attached;
234};
235
236/* Protection domain */
237struct hfi1_pd {
238 struct ib_pd ibpd;
239 int user; /* non-zero if created from user space */
240};
241
242/* Address Handle */
243struct hfi1_ah {
244 struct ib_ah ibah;
245 struct ib_ah_attr attr;
246 atomic_t refcount;
247};
248
249/*
250 * This structure is used by hfi1_mmap() to validate an offset
251 * when an mmap() request is made. The vm_area_struct then uses
252 * this as its vm_private_data.
253 */
254struct hfi1_mmap_info {
255 struct list_head pending_mmaps;
256 struct ib_ucontext *context;
257 void *obj;
258 __u64 offset;
259 struct kref ref;
260 unsigned size;
261};
262
263/*
264 * This structure is used to contain the head pointer, tail pointer,
265 * and completion queue entries as a single memory allocation so
266 * it can be mmap'ed into user space.
267 */
268struct hfi1_cq_wc {
269 u32 head; /* index of next entry to fill */
270 u32 tail; /* index of next ib_poll_cq() entry */
271 union {
272 /* these are actually size ibcq.cqe + 1 */
273 struct ib_uverbs_wc uqueue[0];
274 struct ib_wc kqueue[0];
275 };
276};
277
278/*
279 * The completion queue structure.
280 */
281struct hfi1_cq {
282 struct ib_cq ibcq;
283 struct kthread_work comptask;
284 struct hfi1_devdata *dd;
285 spinlock_t lock; /* protect changes in this struct */
286 u8 notify;
287 u8 triggered;
288 struct hfi1_cq_wc *queue;
289 struct hfi1_mmap_info *ip;
290};
291
292/*
293 * A segment is a linear region of low physical memory.
294 * Used by the verbs layer.
295 */
296struct hfi1_seg {
297 void *vaddr;
298 size_t length;
299};
300
301/* The number of hfi1_segs that fit in a page. */
302#define HFI1_SEGSZ (PAGE_SIZE / sizeof(struct hfi1_seg))
303
304struct hfi1_segarray {
305 struct hfi1_seg segs[HFI1_SEGSZ];
306};
307
308struct hfi1_mregion {
309 struct ib_pd *pd; /* shares refcnt of ibmr.pd */
310 u64 user_base; /* User's address for this region */
311 u64 iova; /* IB start address of this region */
312 size_t length;
313 u32 lkey;
314 u32 offset; /* offset (bytes) to start of region */
315 int access_flags;
316 u32 max_segs; /* number of hfi1_segs in all the arrays */
317 u32 mapsz; /* size of the map array */
318 u8 page_shift; /* 0 - non unform/non powerof2 sizes */
319 u8 lkey_published; /* in global table */
320 struct completion comp; /* complete when refcount goes to zero */
321 atomic_t refcount;
322 struct hfi1_segarray *map[0]; /* the segments */
323};
324
325/*
326 * These keep track of the copy progress within a memory region.
327 * Used by the verbs layer.
328 */
329struct hfi1_sge {
330 struct hfi1_mregion *mr;
331 void *vaddr; /* kernel virtual address of segment */
332 u32 sge_length; /* length of the SGE */
333 u32 length; /* remaining length of the segment */
334 u16 m; /* current index: mr->map[m] */
335 u16 n; /* current index: mr->map[m]->segs[n] */
336};
337
338/* Memory region */
339struct hfi1_mr {
340 struct ib_mr ibmr;
341 struct ib_umem *umem;
342 struct hfi1_mregion mr; /* must be last */
343};
344
345/*
346 * Send work request queue entry.
347 * The size of the sg_list is determined when the QP is created and stored
348 * in qp->s_max_sge.
349 */
350struct hfi1_swqe {
351 union {
352 struct ib_send_wr wr; /* don't use wr.sg_list */
353 struct ib_rdma_wr rdma_wr;
354 struct ib_atomic_wr atomic_wr;
355 struct ib_ud_wr ud_wr;
356 };
357 u32 psn; /* first packet sequence number */
358 u32 lpsn; /* last packet sequence number */
359 u32 ssn; /* send sequence number */
360 u32 length; /* total length of data in sg_list */
361 struct hfi1_sge sg_list[0];
362};
363
364/*
365 * Receive work request queue entry.
366 * The size of the sg_list is determined when the QP (or SRQ) is created
367 * and stored in qp->r_rq.max_sge (or srq->rq.max_sge).
368 */
369struct hfi1_rwqe {
370 u64 wr_id;
371 u8 num_sge;
372 struct ib_sge sg_list[0];
373};
374
375/*
376 * This structure is used to contain the head pointer, tail pointer,
377 * and receive work queue entries as a single memory allocation so
378 * it can be mmap'ed into user space.
379 * Note that the wq array elements are variable size so you can't
380 * just index into the array to get the N'th element;
381 * use get_rwqe_ptr() instead.
382 */ 197 */
383struct hfi1_rwq { 198struct hfi1_qp_priv {
384 u32 head; /* new work requests posted to the head */ 199 struct ahg_ib_header *s_hdr; /* next header to send */
385 u32 tail; /* receives pull requests from here. */ 200 struct sdma_engine *s_sde; /* current sde */
386 struct hfi1_rwqe wq[0]; 201 struct send_context *s_sendcontext; /* current sendcontext */
387}; 202 u8 s_sc; /* SC[0..4] for next packet */
388 203 u8 r_adefered; /* number of acks defered */
389struct hfi1_rq {
390 struct hfi1_rwq *wq;
391 u32 size; /* size of RWQE array */
392 u8 max_sge;
393 /* protect changes in this struct */
394 spinlock_t lock ____cacheline_aligned_in_smp;
395};
396
397struct hfi1_srq {
398 struct ib_srq ibsrq;
399 struct hfi1_rq rq;
400 struct hfi1_mmap_info *ip;
401 /* send signal when number of RWQEs < limit */
402 u32 limit;
403};
404
405struct hfi1_sge_state {
406 struct hfi1_sge *sg_list; /* next SGE to be used if any */
407 struct hfi1_sge sge; /* progress state for the current SGE */
408 u32 total_len;
409 u8 num_sge;
410};
411
412/*
413 * This structure holds the information that the send tasklet needs
414 * to send a RDMA read response or atomic operation.
415 */
416struct hfi1_ack_entry {
417 u8 opcode;
418 u8 sent;
419 u32 psn;
420 u32 lpsn;
421 union {
422 struct hfi1_sge rdma_sge;
423 u64 atomic_data;
424 };
425};
426
427/*
428 * Variables prefixed with s_ are for the requester (sender).
429 * Variables prefixed with r_ are for the responder (receiver).
430 * Variables prefixed with ack_ are for responder replies.
431 *
432 * Common variables are protected by both r_rq.lock and s_lock in that order
433 * which only happens in modify_qp() or changing the QP 'state'.
434 */
435struct hfi1_qp {
436 struct ib_qp ibqp;
437 /* read mostly fields above and below */
438 struct ib_ah_attr remote_ah_attr;
439 struct ib_ah_attr alt_ah_attr;
440 struct hfi1_qp __rcu *next; /* link list for QPN hash table */
441 struct hfi1_swqe *s_wq; /* send work queue */
442 struct hfi1_mmap_info *ip;
443 struct ahg_ib_header *s_hdr; /* next packet header to send */
444 /* sc for UC/RC QPs - based on ah for UD */
445 u8 s_sc;
446 unsigned long timeout_jiffies; /* computed from timeout */
447
448 enum ib_mtu path_mtu;
449 int srate_mbps; /* s_srate (below) converted to Mbit/s */
450 u32 remote_qpn;
451 u32 pmtu; /* decoded from path_mtu */
452 u32 qkey; /* QKEY for this QP (for UD or RD) */
453 u32 s_size; /* send work queue size */
454 u32 s_rnr_timeout; /* number of milliseconds for RNR timeout */
455 u32 s_ahgpsn; /* set to the psn in the copy of the header */
456
457 u8 state; /* QP state */
458 u8 allowed_ops; /* high order bits of allowed opcodes */
459 u8 qp_access_flags;
460 u8 alt_timeout; /* Alternate path timeout for this QP */
461 u8 timeout; /* Timeout for this QP */
462 u8 s_srate;
463 u8 s_mig_state;
464 u8 port_num;
465 u8 s_pkey_index; /* PKEY index to use */
466 u8 s_alt_pkey_index; /* Alternate path PKEY index to use */
467 u8 r_max_rd_atomic; /* max number of RDMA read/atomic to receive */
468 u8 s_max_rd_atomic; /* max number of RDMA read/atomic to send */
469 u8 s_retry_cnt; /* number of times to retry */
470 u8 s_rnr_retry_cnt;
471 u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */
472 u8 s_max_sge; /* size of s_wq->sg_list */
473 u8 s_draining;
474
475 /* start of read/write fields */
476 atomic_t refcount ____cacheline_aligned_in_smp;
477 wait_queue_head_t wait;
478
479
480 struct hfi1_ack_entry s_ack_queue[HFI1_MAX_RDMA_ATOMIC + 1]
481 ____cacheline_aligned_in_smp;
482 struct hfi1_sge_state s_rdma_read_sge;
483
484 spinlock_t r_lock ____cacheline_aligned_in_smp; /* used for APM */
485 unsigned long r_aflags;
486 u64 r_wr_id; /* ID for current receive WQE */
487 u32 r_ack_psn; /* PSN for next ACK or atomic ACK */
488 u32 r_len; /* total length of r_sge */
489 u32 r_rcv_len; /* receive data len processed */
490 u32 r_psn; /* expected rcv packet sequence number */
491 u32 r_msn; /* message sequence number */
492
493 u8 r_adefered; /* number of acks defered */
494 u8 r_state; /* opcode of last packet received */
495 u8 r_flags;
496 u8 r_head_ack_queue; /* index into s_ack_queue[] */
497
498 struct list_head rspwait; /* link for waiting to respond */
499
500 struct hfi1_sge_state r_sge; /* current receive data */
501 struct hfi1_rq r_rq; /* receive work queue */
502
503 spinlock_t s_lock ____cacheline_aligned_in_smp;
504 struct hfi1_sge_state *s_cur_sge;
505 u32 s_flags;
506 struct hfi1_swqe *s_wqe;
507 struct hfi1_sge_state s_sge; /* current send request data */
508 struct hfi1_mregion *s_rdma_mr;
509 struct sdma_engine *s_sde; /* current sde */
510 u32 s_cur_size; /* size of send packet in bytes */
511 u32 s_len; /* total length of s_sge */
512 u32 s_rdma_read_len; /* total length of s_rdma_read_sge */
513 u32 s_next_psn; /* PSN for next request */
514 u32 s_last_psn; /* last response PSN processed */
515 u32 s_sending_psn; /* lowest PSN that is being sent */
516 u32 s_sending_hpsn; /* highest PSN that is being sent */
517 u32 s_psn; /* current packet sequence number */
518 u32 s_ack_rdma_psn; /* PSN for sending RDMA read responses */
519 u32 s_ack_psn; /* PSN for acking sends and RDMA writes */
520 u32 s_head; /* new entries added here */
521 u32 s_tail; /* next entry to process */
522 u32 s_cur; /* current work queue entry */
523 u32 s_acked; /* last un-ACK'ed entry */
524 u32 s_last; /* last completed entry */
525 u32 s_ssn; /* SSN of tail entry */
526 u32 s_lsn; /* limit sequence number (credit) */
527 u16 s_hdrwords; /* size of s_hdr in 32 bit words */
528 u16 s_rdma_ack_cnt;
529 s8 s_ahgidx;
530 u8 s_state; /* opcode of last packet sent */
531 u8 s_ack_state; /* opcode of packet to ACK */
532 u8 s_nak_state; /* non-zero if NAK is pending */
533 u8 r_nak_state; /* non-zero if NAK is pending */
534 u8 s_retry; /* requester retry counter */
535 u8 s_rnr_retry; /* requester RNR retry counter */
536 u8 s_num_rd_atomic; /* number of RDMA read/atomic pending */
537 u8 s_tail_ack_queue; /* index into s_ack_queue[] */
538
539 struct hfi1_sge_state s_ack_rdma_sge;
540 struct timer_list s_timer;
541
542 struct iowait s_iowait; 204 struct iowait s_iowait;
543 205 struct timer_list s_rnr_timer;
544 struct hfi1_sge r_sg_list[0] /* verified SGEs */ 206 struct rvt_qp *owner;
545 ____cacheline_aligned_in_smp;
546}; 207};
547 208
548/* 209/*
@@ -553,123 +214,11 @@ struct hfi1_pkt_state {
553 struct hfi1_ibdev *dev; 214 struct hfi1_ibdev *dev;
554 struct hfi1_ibport *ibp; 215 struct hfi1_ibport *ibp;
555 struct hfi1_pportdata *ppd; 216 struct hfi1_pportdata *ppd;
217 struct verbs_txreq *s_txreq;
556}; 218};
557 219
558/*
559 * Atomic bit definitions for r_aflags.
560 */
561#define HFI1_R_WRID_VALID 0
562#define HFI1_R_REWIND_SGE 1
563
564/*
565 * Bit definitions for r_flags.
566 */
567#define HFI1_R_REUSE_SGE 0x01
568#define HFI1_R_RDMAR_SEQ 0x02
569/* defer ack until end of interrupt session */
570#define HFI1_R_RSP_DEFERED_ACK 0x04
571/* relay ack to send engine */
572#define HFI1_R_RSP_SEND 0x08
573#define HFI1_R_COMM_EST 0x10
574
575/*
576 * Bit definitions for s_flags.
577 *
578 * HFI1_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
579 * HFI1_S_BUSY - send tasklet is processing the QP
580 * HFI1_S_TIMER - the RC retry timer is active
581 * HFI1_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
582 * HFI1_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
583 * before processing the next SWQE
584 * HFI1_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
585 * before processing the next SWQE
586 * HFI1_S_WAIT_RNR - waiting for RNR timeout
587 * HFI1_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
588 * HFI1_S_WAIT_DMA - waiting for send DMA queue to drain before generating
589 * next send completion entry not via send DMA
590 * HFI1_S_WAIT_PIO - waiting for a send buffer to be available
591 * HFI1_S_WAIT_TX - waiting for a struct verbs_txreq to be available
592 * HFI1_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
593 * HFI1_S_WAIT_KMEM - waiting for kernel memory to be available
594 * HFI1_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
595 * HFI1_S_WAIT_ACK - waiting for an ACK packet before sending more requests
596 * HFI1_S_SEND_ONE - send one packet, request ACK, then wait for ACK
597 * HFI1_S_ECN - a BECN was queued to the send engine
598 */
599#define HFI1_S_SIGNAL_REQ_WR 0x0001
600#define HFI1_S_BUSY 0x0002
601#define HFI1_S_TIMER 0x0004
602#define HFI1_S_RESP_PENDING 0x0008
603#define HFI1_S_ACK_PENDING 0x0010
604#define HFI1_S_WAIT_FENCE 0x0020
605#define HFI1_S_WAIT_RDMAR 0x0040
606#define HFI1_S_WAIT_RNR 0x0080
607#define HFI1_S_WAIT_SSN_CREDIT 0x0100
608#define HFI1_S_WAIT_DMA 0x0200
609#define HFI1_S_WAIT_PIO 0x0400
610#define HFI1_S_WAIT_TX 0x0800
611#define HFI1_S_WAIT_DMA_DESC 0x1000
612#define HFI1_S_WAIT_KMEM 0x2000
613#define HFI1_S_WAIT_PSN 0x4000
614#define HFI1_S_WAIT_ACK 0x8000
615#define HFI1_S_SEND_ONE 0x10000
616#define HFI1_S_UNLIMITED_CREDIT 0x20000
617#define HFI1_S_AHG_VALID 0x40000
618#define HFI1_S_AHG_CLEAR 0x80000
619#define HFI1_S_ECN 0x100000
620
621/*
622 * Wait flags that would prevent any packet type from being sent.
623 */
624#define HFI1_S_ANY_WAIT_IO (HFI1_S_WAIT_PIO | HFI1_S_WAIT_TX | \
625 HFI1_S_WAIT_DMA_DESC | HFI1_S_WAIT_KMEM)
626
627/*
628 * Wait flags that would prevent send work requests from making progress.
629 */
630#define HFI1_S_ANY_WAIT_SEND (HFI1_S_WAIT_FENCE | HFI1_S_WAIT_RDMAR | \
631 HFI1_S_WAIT_RNR | HFI1_S_WAIT_SSN_CREDIT | HFI1_S_WAIT_DMA | \
632 HFI1_S_WAIT_PSN | HFI1_S_WAIT_ACK)
633
634#define HFI1_S_ANY_WAIT (HFI1_S_ANY_WAIT_IO | HFI1_S_ANY_WAIT_SEND)
635
636#define HFI1_PSN_CREDIT 16 220#define HFI1_PSN_CREDIT 16
637 221
638/*
639 * Since struct hfi1_swqe is not a fixed size, we can't simply index into
640 * struct hfi1_qp.s_wq. This function does the array index computation.
641 */
642static inline struct hfi1_swqe *get_swqe_ptr(struct hfi1_qp *qp,
643 unsigned n)
644{
645 return (struct hfi1_swqe *)((char *)qp->s_wq +
646 (sizeof(struct hfi1_swqe) +
647 qp->s_max_sge *
648 sizeof(struct hfi1_sge)) * n);
649}
650
651/*
652 * Since struct hfi1_rwqe is not a fixed size, we can't simply index into
653 * struct hfi1_rwq.wq. This function does the array index computation.
654 */
655static inline struct hfi1_rwqe *get_rwqe_ptr(struct hfi1_rq *rq, unsigned n)
656{
657 return (struct hfi1_rwqe *)
658 ((char *) rq->wq->wq +
659 (sizeof(struct hfi1_rwqe) +
660 rq->max_sge * sizeof(struct ib_sge)) * n);
661}
662
663#define MAX_LKEY_TABLE_BITS 23
664
665struct hfi1_lkey_table {
666 spinlock_t lock; /* protect changes in this struct */
667 u32 next; /* next unused index (speeds search) */
668 u32 gen; /* generation count */
669 u32 max; /* size of the table */
670 struct hfi1_mregion __rcu **table;
671};
672
673struct hfi1_opcode_stats { 222struct hfi1_opcode_stats {
674 u64 n_packets; /* number of packets */ 223 u64 n_packets; /* number of packets */
675 u64 n_bytes; /* total number of bytes */ 224 u64 n_bytes; /* total number of bytes */
@@ -690,75 +239,20 @@ static inline void inc_opstats(
690} 239}
691 240
692struct hfi1_ibport { 241struct hfi1_ibport {
693 struct hfi1_qp __rcu *qp[2]; 242 struct rvt_qp __rcu *qp[2];
694 struct ib_mad_agent *send_agent; /* agent for SMI (traps) */ 243 struct rvt_ibport rvp;
695 struct hfi1_ah *sm_ah; 244
696 struct hfi1_ah *smi_ah;
697 struct rb_root mcast_tree;
698 spinlock_t lock; /* protect changes in this struct */
699
700 /* non-zero when timer is set */
701 unsigned long mkey_lease_timeout;
702 unsigned long trap_timeout;
703 __be64 gid_prefix; /* in network order */
704 __be64 mkey;
705 __be64 guids[HFI1_GUIDS_PER_PORT - 1]; /* writable GUIDs */ 245 __be64 guids[HFI1_GUIDS_PER_PORT - 1]; /* writable GUIDs */
706 u64 tid; /* TID for traps */ 246
707 u64 n_rc_resends;
708 u64 n_seq_naks;
709 u64 n_rdma_seq;
710 u64 n_rnr_naks;
711 u64 n_other_naks;
712 u64 n_loop_pkts;
713 u64 n_pkt_drops;
714 u64 n_vl15_dropped;
715 u64 n_rc_timeouts;
716 u64 n_dmawait;
717 u64 n_unaligned;
718 u64 n_rc_dupreq;
719 u64 n_rc_seqnak;
720
721 /* Hot-path per CPU counters to avoid cacheline trading to update */
722 u64 z_rc_acks;
723 u64 z_rc_qacks;
724 u64 z_rc_delayed_comp;
725 u64 __percpu *rc_acks;
726 u64 __percpu *rc_qacks;
727 u64 __percpu *rc_delayed_comp;
728
729 u32 port_cap_flags;
730 u32 pma_sample_start;
731 u32 pma_sample_interval;
732 __be16 pma_counter_select[5];
733 u16 pma_tag;
734 u16 pkey_violations;
735 u16 qkey_violations;
736 u16 mkey_violations;
737 u16 mkey_lease_period;
738 u16 sm_lid;
739 u16 repress_traps;
740 u8 sm_sl;
741 u8 mkeyprot;
742 u8 subnet_timeout;
743 u8 vl_high_limit;
744 /* the first 16 entries are sl_to_vl for !OPA */ 247 /* the first 16 entries are sl_to_vl for !OPA */
745 u8 sl_to_sc[32]; 248 u8 sl_to_sc[32];
746 u8 sc_to_sl[32]; 249 u8 sc_to_sl[32];
747}; 250};
748 251
749
750struct hfi1_qp_ibdev;
751struct hfi1_ibdev { 252struct hfi1_ibdev {
752 struct ib_device ibdev; 253 struct rvt_dev_info rdi; /* Must be first */
753 struct list_head pending_mmaps;
754 spinlock_t mmap_offset_lock; /* protect mmap_offset */
755 u32 mmap_offset;
756 struct hfi1_mregion __rcu *dma_mr;
757
758 struct hfi1_qp_ibdev *qp_dev;
759 254
760 /* QP numbers are shared by all IB ports */ 255 /* QP numbers are shared by all IB ports */
761 struct hfi1_lkey_table lk_table;
762 /* protect wait lists */ 256 /* protect wait lists */
763 seqlock_t iowait_lock; 257 seqlock_t iowait_lock;
764 struct list_head txwait; /* list for wait verbs_txreq */ 258 struct list_head txwait; /* list for wait verbs_txreq */
@@ -767,26 +261,11 @@ struct hfi1_ibdev {
767 struct kmem_cache *verbs_txreq_cache; 261 struct kmem_cache *verbs_txreq_cache;
768 struct timer_list mem_timer; 262 struct timer_list mem_timer;
769 263
770 /* other waiters */
771 spinlock_t pending_lock;
772
773 u64 n_piowait; 264 u64 n_piowait;
265 u64 n_piodrain;
774 u64 n_txwait; 266 u64 n_txwait;
775 u64 n_kmem_wait; 267 u64 n_kmem_wait;
776 u64 n_send_schedule; 268
777
778 u32 n_pds_allocated; /* number of PDs allocated for device */
779 spinlock_t n_pds_lock;
780 u32 n_ahs_allocated; /* number of AHs allocated for device */
781 spinlock_t n_ahs_lock;
782 u32 n_cqs_allocated; /* number of CQs allocated for device */
783 spinlock_t n_cqs_lock;
784 u32 n_qps_allocated; /* number of QPs allocated for device */
785 spinlock_t n_qps_lock;
786 u32 n_srqs_allocated; /* number of SRQs allocated for device */
787 spinlock_t n_srqs_lock;
788 u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
789 spinlock_t n_mcast_grps_lock;
790#ifdef CONFIG_DEBUG_FS 269#ifdef CONFIG_DEBUG_FS
791 /* per HFI debugfs */ 270 /* per HFI debugfs */
792 struct dentry *hfi1_ibdev_dbg; 271 struct dentry *hfi1_ibdev_dbg;
@@ -795,66 +274,31 @@ struct hfi1_ibdev {
795#endif 274#endif
796}; 275};
797 276
798struct hfi1_verbs_counters { 277static inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev)
799 u64 symbol_error_counter;
800 u64 link_error_recovery_counter;
801 u64 link_downed_counter;
802 u64 port_rcv_errors;
803 u64 port_rcv_remphys_errors;
804 u64 port_xmit_discards;
805 u64 port_xmit_data;
806 u64 port_rcv_data;
807 u64 port_xmit_packets;
808 u64 port_rcv_packets;
809 u32 local_link_integrity_errors;
810 u32 excessive_buffer_overrun_errors;
811 u32 vl15_dropped;
812};
813
814static inline struct hfi1_mr *to_imr(struct ib_mr *ibmr)
815{
816 return container_of(ibmr, struct hfi1_mr, ibmr);
817}
818
819static inline struct hfi1_pd *to_ipd(struct ib_pd *ibpd)
820{
821 return container_of(ibpd, struct hfi1_pd, ibpd);
822}
823
824static inline struct hfi1_ah *to_iah(struct ib_ah *ibah)
825{
826 return container_of(ibah, struct hfi1_ah, ibah);
827}
828
829static inline struct hfi1_cq *to_icq(struct ib_cq *ibcq)
830{ 278{
831 return container_of(ibcq, struct hfi1_cq, ibcq); 279 struct rvt_dev_info *rdi;
832}
833 280
834static inline struct hfi1_srq *to_isrq(struct ib_srq *ibsrq) 281 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
835{ 282 return container_of(rdi, struct hfi1_ibdev, rdi);
836 return container_of(ibsrq, struct hfi1_srq, ibsrq);
837} 283}
838 284
839static inline struct hfi1_qp *to_iqp(struct ib_qp *ibqp) 285static inline struct rvt_qp *iowait_to_qp(struct iowait *s_iowait)
840{ 286{
841 return container_of(ibqp, struct hfi1_qp, ibqp); 287 struct hfi1_qp_priv *priv;
842}
843 288
844static inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev) 289 priv = container_of(s_iowait, struct hfi1_qp_priv, s_iowait);
845{ 290 return priv->owner;
846 return container_of(ibdev, struct hfi1_ibdev, ibdev);
847} 291}
848 292
849/* 293/*
850 * Send if not busy or waiting for I/O and either 294 * Send if not busy or waiting for I/O and either
851 * a RC response is pending or we can process send work requests. 295 * a RC response is pending or we can process send work requests.
852 */ 296 */
853static inline int hfi1_send_ok(struct hfi1_qp *qp) 297static inline int hfi1_send_ok(struct rvt_qp *qp)
854{ 298{
855 return !(qp->s_flags & (HFI1_S_BUSY | HFI1_S_ANY_WAIT_IO)) && 299 return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) &&
856 (qp->s_hdrwords || (qp->s_flags & HFI1_S_RESP_PENDING) || 300 (qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) ||
857 !(qp->s_flags & HFI1_S_ANY_WAIT_SEND)); 301 !(qp->s_flags & RVT_S_ANY_WAIT_SEND));
858} 302}
859 303
860/* 304/*
@@ -862,7 +306,7 @@ static inline int hfi1_send_ok(struct hfi1_qp *qp)
862 */ 306 */
863void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl, 307void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
864 u32 qp1, u32 qp2, u16 lid1, u16 lid2); 308 u32 qp1, u32 qp2, u16 lid1, u16 lid2);
865void hfi1_cap_mask_chg(struct hfi1_ibport *ibp); 309void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
866void hfi1_sys_guid_chg(struct hfi1_ibport *ibp); 310void hfi1_sys_guid_chg(struct hfi1_ibport *ibp);
867void hfi1_node_desc_chg(struct hfi1_ibport *ibp); 311void hfi1_node_desc_chg(struct hfi1_ibport *ibp);
868int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port, 312int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
@@ -870,8 +314,6 @@ int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
870 const struct ib_mad_hdr *in_mad, size_t in_mad_size, 314 const struct ib_mad_hdr *in_mad, size_t in_mad_size,
871 struct ib_mad_hdr *out_mad, size_t *out_mad_size, 315 struct ib_mad_hdr *out_mad, size_t *out_mad_size,
872 u16 *out_mad_pkey_index); 316 u16 *out_mad_pkey_index);
873int hfi1_create_agents(struct hfi1_ibdev *dev);
874void hfi1_free_agents(struct hfi1_ibdev *dev);
875 317
876/* 318/*
877 * The PSN_MASK and PSN_SHIFT allow for 319 * The PSN_MASK and PSN_SHIFT allow for
@@ -901,7 +343,7 @@ void hfi1_free_agents(struct hfi1_ibdev *dev);
901 */ 343 */
902static inline int cmp_msn(u32 a, u32 b) 344static inline int cmp_msn(u32 a, u32 b)
903{ 345{
904 return (((int) a) - ((int) b)) << 8; 346 return (((int)a) - ((int)b)) << 8;
905} 347}
906 348
907/* 349/*
@@ -910,7 +352,7 @@ static inline int cmp_msn(u32 a, u32 b)
910 */ 352 */
911static inline int cmp_psn(u32 a, u32 b) 353static inline int cmp_psn(u32 a, u32 b)
912{ 354{
913 return (((int) a) - ((int) b)) << PSN_SHIFT; 355 return (((int)a) - ((int)b)) << PSN_SHIFT;
914} 356}
915 357
916/* 358/*
@@ -929,23 +371,15 @@ static inline u32 delta_psn(u32 a, u32 b)
929 return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT; 371 return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT;
930} 372}
931 373
932struct hfi1_mcast *hfi1_mcast_find(struct hfi1_ibport *ibp, union ib_gid *mgid);
933
934int hfi1_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
935
936int hfi1_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
937
938int hfi1_mcast_tree_empty(struct hfi1_ibport *ibp);
939
940struct verbs_txreq; 374struct verbs_txreq;
941void hfi1_put_txreq(struct verbs_txreq *tx); 375void hfi1_put_txreq(struct verbs_txreq *tx);
942 376
943int hfi1_verbs_send(struct hfi1_qp *qp, struct hfi1_pkt_state *ps); 377int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
944 378
945void hfi1_copy_sge(struct hfi1_sge_state *ss, void *data, u32 length, 379void hfi1_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
946 int release); 380 int release, int copy_last);
947 381
948void hfi1_skip_sge(struct hfi1_sge_state *ss, u32 length, int release); 382void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
949 383
950void hfi1_cnp_rcv(struct hfi1_packet *packet); 384void hfi1_cnp_rcv(struct hfi1_packet *packet);
951 385
@@ -957,147 +391,75 @@ void hfi1_rc_hdrerr(
957 struct hfi1_ctxtdata *rcd, 391 struct hfi1_ctxtdata *rcd,
958 struct hfi1_ib_header *hdr, 392 struct hfi1_ib_header *hdr,
959 u32 rcv_flags, 393 u32 rcv_flags,
960 struct hfi1_qp *qp); 394 struct rvt_qp *qp);
961 395
962u8 ah_to_sc(struct ib_device *ibdev, struct ib_ah_attr *ah_attr); 396u8 ah_to_sc(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
963 397
964int hfi1_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
965
966struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u16 dlid); 398struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u16 dlid);
967 399
968void hfi1_rc_rnr_retry(unsigned long arg); 400void hfi1_rc_rnr_retry(unsigned long arg);
401void hfi1_add_rnr_timer(struct rvt_qp *qp, u32 to);
402void hfi1_rc_timeout(unsigned long arg);
403void hfi1_del_timers_sync(struct rvt_qp *qp);
404void hfi1_stop_rc_timers(struct rvt_qp *qp);
969 405
970void hfi1_rc_send_complete(struct hfi1_qp *qp, struct hfi1_ib_header *hdr); 406void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_ib_header *hdr);
971 407
972void hfi1_rc_error(struct hfi1_qp *qp, enum ib_wc_status err); 408void hfi1_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
973 409
974void hfi1_ud_rcv(struct hfi1_packet *packet); 410void hfi1_ud_rcv(struct hfi1_packet *packet);
975 411
976int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey); 412int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey);
977 413
978int hfi1_alloc_lkey(struct hfi1_mregion *mr, int dma_region); 414int hfi1_rvt_get_rwqe(struct rvt_qp *qp, int wr_id_only);
979
980void hfi1_free_lkey(struct hfi1_mregion *mr);
981
982int hfi1_lkey_ok(struct hfi1_lkey_table *rkt, struct hfi1_pd *pd,
983 struct hfi1_sge *isge, struct ib_sge *sge, int acc);
984
985int hfi1_rkey_ok(struct hfi1_qp *qp, struct hfi1_sge *sge,
986 u32 len, u64 vaddr, u32 rkey, int acc);
987
988int hfi1_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
989 struct ib_recv_wr **bad_wr);
990
991struct ib_srq *hfi1_create_srq(struct ib_pd *ibpd,
992 struct ib_srq_init_attr *srq_init_attr,
993 struct ib_udata *udata);
994
995int hfi1_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
996 enum ib_srq_attr_mask attr_mask,
997 struct ib_udata *udata);
998
999int hfi1_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
1000
1001int hfi1_destroy_srq(struct ib_srq *ibsrq);
1002
1003int hfi1_cq_init(struct hfi1_devdata *dd);
1004
1005void hfi1_cq_exit(struct hfi1_devdata *dd);
1006
1007void hfi1_cq_enter(struct hfi1_cq *cq, struct ib_wc *entry, int sig);
1008
1009int hfi1_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
1010
1011struct ib_cq *hfi1_create_cq(
1012 struct ib_device *ibdev,
1013 const struct ib_cq_init_attr *attr,
1014 struct ib_ucontext *context,
1015 struct ib_udata *udata);
1016
1017int hfi1_destroy_cq(struct ib_cq *ibcq);
1018
1019int hfi1_req_notify_cq(
1020 struct ib_cq *ibcq,
1021 enum ib_cq_notify_flags notify_flags);
1022
1023int hfi1_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
1024
1025struct ib_mr *hfi1_get_dma_mr(struct ib_pd *pd, int acc);
1026
1027struct ib_mr *hfi1_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1028 u64 virt_addr, int mr_access_flags,
1029 struct ib_udata *udata);
1030 415
1031int hfi1_dereg_mr(struct ib_mr *ibmr); 416void hfi1_migrate_qp(struct rvt_qp *qp);
1032 417
1033struct ib_mr *hfi1_alloc_mr(struct ib_pd *pd, 418int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
1034 enum ib_mr_type mr_type, 419 int attr_mask, struct ib_udata *udata);
1035 u32 max_entries);
1036 420
1037struct ib_fmr *hfi1_alloc_fmr(struct ib_pd *pd, int mr_access_flags, 421void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
1038 struct ib_fmr_attr *fmr_attr); 422 int attr_mask, struct ib_udata *udata);
1039 423
1040int hfi1_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, 424int hfi1_check_send_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe);
1041 int list_len, u64 iova);
1042 425
1043int hfi1_unmap_fmr(struct list_head *fmr_list); 426extern const u32 rc_only_opcode;
427extern const u32 uc_only_opcode;
1044 428
1045int hfi1_dealloc_fmr(struct ib_fmr *ibfmr); 429static inline u8 get_opcode(struct hfi1_ib_header *h)
1046
1047static inline void hfi1_get_mr(struct hfi1_mregion *mr)
1048{
1049 atomic_inc(&mr->refcount);
1050}
1051
1052static inline void hfi1_put_mr(struct hfi1_mregion *mr)
1053{ 430{
1054 if (unlikely(atomic_dec_and_test(&mr->refcount))) 431 u16 lnh = be16_to_cpu(h->lrh[0]) & 3;
1055 complete(&mr->comp);
1056}
1057 432
1058static inline void hfi1_put_ss(struct hfi1_sge_state *ss) 433 if (lnh == IB_LNH_IBA_LOCAL)
1059{ 434 return be32_to_cpu(h->u.oth.bth[0]) >> 24;
1060 while (ss->num_sge) { 435 else
1061 hfi1_put_mr(ss->sge.mr); 436 return be32_to_cpu(h->u.l.oth.bth[0]) >> 24;
1062 if (--ss->num_sge)
1063 ss->sge = *ss->sg_list++;
1064 }
1065} 437}
1066 438
1067void hfi1_release_mmap_info(struct kref *ref);
1068
1069struct hfi1_mmap_info *hfi1_create_mmap_info(struct hfi1_ibdev *dev, u32 size,
1070 struct ib_ucontext *context,
1071 void *obj);
1072
1073void hfi1_update_mmap_info(struct hfi1_ibdev *dev, struct hfi1_mmap_info *ip,
1074 u32 size, void *obj);
1075
1076int hfi1_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
1077
1078int hfi1_get_rwqe(struct hfi1_qp *qp, int wr_id_only);
1079
1080int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr, 439int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr,
1081 int has_grh, struct hfi1_qp *qp, u32 bth0); 440 int has_grh, struct rvt_qp *qp, u32 bth0);
1082 441
1083u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr, 442u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
1084 struct ib_global_route *grh, u32 hwords, u32 nwords); 443 struct ib_global_route *grh, u32 hwords, u32 nwords);
1085 444
1086void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr, 445void hfi1_make_ruc_header(struct rvt_qp *qp, struct hfi1_other_headers *ohdr,
1087 u32 bth0, u32 bth2, int middle); 446 u32 bth0, u32 bth2, int middle,
447 struct hfi1_pkt_state *ps);
1088 448
1089void hfi1_do_send(struct work_struct *work); 449void _hfi1_do_send(struct work_struct *work);
1090 450
1091void hfi1_send_complete(struct hfi1_qp *qp, struct hfi1_swqe *wqe, 451void hfi1_do_send(struct rvt_qp *qp);
452
453void hfi1_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
1092 enum ib_wc_status status); 454 enum ib_wc_status status);
1093 455
1094void hfi1_send_rc_ack(struct hfi1_ctxtdata *, struct hfi1_qp *qp, int is_fecn); 456void hfi1_send_rc_ack(struct hfi1_ctxtdata *, struct rvt_qp *qp, int is_fecn);
1095 457
1096int hfi1_make_rc_req(struct hfi1_qp *qp); 458int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
1097 459
1098int hfi1_make_uc_req(struct hfi1_qp *qp); 460int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
1099 461
1100int hfi1_make_ud_req(struct hfi1_qp *qp); 462int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
1101 463
1102int hfi1_register_ib_device(struct hfi1_devdata *); 464int hfi1_register_ib_device(struct hfi1_devdata *);
1103 465
@@ -1107,24 +469,42 @@ void hfi1_ib_rcv(struct hfi1_packet *packet);
1107 469
1108unsigned hfi1_get_npkeys(struct hfi1_devdata *); 470unsigned hfi1_get_npkeys(struct hfi1_devdata *);
1109 471
1110int hfi1_verbs_send_dma(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 472int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1111 u64 pbc); 473 u64 pbc);
1112 474
1113int hfi1_verbs_send_pio(struct hfi1_qp *qp, struct hfi1_pkt_state *ps, 475int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1114 u64 pbc); 476 u64 pbc);
1115 477
1116struct send_context *qp_to_send_context(struct hfi1_qp *qp, u8 sc5); 478int hfi1_wss_init(void);
479void hfi1_wss_exit(void);
480
481/* platform specific: return the lowest level cache (llc) size, in KiB */
482static inline int wss_llc_size(void)
483{
484 /* assume that the boot CPU value is universal for all CPUs */
485 return boot_cpu_data.x86_cache_size;
486}
487
488/* platform specific: cacheless copy */
489static inline void cacheless_memcpy(void *dst, void *src, size_t n)
490{
491 /*
492 * Use the only available X64 cacheless copy. Add a __user cast
493 * to quiet sparse. The src agument is already in the kernel so
494 * there are no security issues. The extra fault recovery machinery
495 * is not invoked.
496 */
497 __copy_user_nocache(dst, (void __user *)src, n, 0);
498}
1117 499
1118extern const enum ib_wc_opcode ib_hfi1_wc_opcode[]; 500extern const enum ib_wc_opcode ib_hfi1_wc_opcode[];
1119 501
1120extern const u8 hdr_len_by_opcode[]; 502extern const u8 hdr_len_by_opcode[];
1121 503
1122extern const int ib_hfi1_state_ops[]; 504extern const int ib_rvt_state_ops[];
1123 505
1124extern __be64 ib_hfi1_sys_image_guid; /* in network order */ 506extern __be64 ib_hfi1_sys_image_guid; /* in network order */
1125 507
1126extern unsigned int hfi1_lkey_table_size;
1127
1128extern unsigned int hfi1_max_cqes; 508extern unsigned int hfi1_max_cqes;
1129 509
1130extern unsigned int hfi1_max_cqs; 510extern unsigned int hfi1_max_cqs;
@@ -1145,8 +525,8 @@ extern unsigned int hfi1_max_srq_sges;
1145 525
1146extern unsigned int hfi1_max_srq_wrs; 526extern unsigned int hfi1_max_srq_wrs;
1147 527
1148extern const u32 ib_hfi1_rnr_table[]; 528extern unsigned short piothreshold;
1149 529
1150extern struct ib_dma_mapping_ops hfi1_dma_mapping_ops; 530extern const u32 ib_hfi1_rnr_table[];
1151 531
1152#endif /* HFI1_VERBS_H */ 532#endif /* HFI1_VERBS_H */
diff --git a/drivers/staging/rdma/hfi1/verbs_txreq.c b/drivers/staging/rdma/hfi1/verbs_txreq.c
new file mode 100644
index 000000000000..bc95c4112c61
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/verbs_txreq.c
@@ -0,0 +1,149 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include "hfi.h"
49#include "verbs_txreq.h"
50#include "qp.h"
51#include "trace.h"
52
53#define TXREQ_LEN 24
54
55void hfi1_put_txreq(struct verbs_txreq *tx)
56{
57 struct hfi1_ibdev *dev;
58 struct rvt_qp *qp;
59 unsigned long flags;
60 unsigned int seq;
61 struct hfi1_qp_priv *priv;
62
63 qp = tx->qp;
64 dev = to_idev(qp->ibqp.device);
65
66 if (tx->mr)
67 rvt_put_mr(tx->mr);
68
69 sdma_txclean(dd_from_dev(dev), &tx->txreq);
70
71 /* Free verbs_txreq and return to slab cache */
72 kmem_cache_free(dev->verbs_txreq_cache, tx);
73
74 do {
75 seq = read_seqbegin(&dev->iowait_lock);
76 if (!list_empty(&dev->txwait)) {
77 struct iowait *wait;
78
79 write_seqlock_irqsave(&dev->iowait_lock, flags);
80 wait = list_first_entry(&dev->txwait, struct iowait,
81 list);
82 qp = iowait_to_qp(wait);
83 priv = qp->priv;
84 list_del_init(&priv->s_iowait.list);
85 /* refcount held until actual wake up */
86 write_sequnlock_irqrestore(&dev->iowait_lock, flags);
87 hfi1_qp_wakeup(qp, RVT_S_WAIT_TX);
88 break;
89 }
90 } while (read_seqretry(&dev->iowait_lock, seq));
91}
92
93struct verbs_txreq *__get_txreq(struct hfi1_ibdev *dev,
94 struct rvt_qp *qp)
95{
96 struct verbs_txreq *tx = ERR_PTR(-EBUSY);
97 unsigned long flags;
98
99 spin_lock_irqsave(&qp->s_lock, flags);
100 write_seqlock(&dev->iowait_lock);
101 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
102 struct hfi1_qp_priv *priv;
103
104 tx = kmem_cache_alloc(dev->verbs_txreq_cache, GFP_ATOMIC);
105 if (tx)
106 goto out;
107 priv = qp->priv;
108 if (list_empty(&priv->s_iowait.list)) {
109 dev->n_txwait++;
110 qp->s_flags |= RVT_S_WAIT_TX;
111 list_add_tail(&priv->s_iowait.list, &dev->txwait);
112 trace_hfi1_qpsleep(qp, RVT_S_WAIT_TX);
113 atomic_inc(&qp->refcount);
114 }
115 qp->s_flags &= ~RVT_S_BUSY;
116 }
117out:
118 write_sequnlock(&dev->iowait_lock);
119 spin_unlock_irqrestore(&qp->s_lock, flags);
120 return tx;
121}
122
123static void verbs_txreq_kmem_cache_ctor(void *obj)
124{
125 struct verbs_txreq *tx = (struct verbs_txreq *)obj;
126
127 memset(tx, 0, sizeof(*tx));
128}
129
130int verbs_txreq_init(struct hfi1_ibdev *dev)
131{
132 char buf[TXREQ_LEN];
133 struct hfi1_devdata *dd = dd_from_dev(dev);
134
135 snprintf(buf, sizeof(buf), "hfi1_%u_vtxreq_cache", dd->unit);
136 dev->verbs_txreq_cache = kmem_cache_create(buf,
137 sizeof(struct verbs_txreq),
138 0, SLAB_HWCACHE_ALIGN,
139 verbs_txreq_kmem_cache_ctor);
140 if (!dev->verbs_txreq_cache)
141 return -ENOMEM;
142 return 0;
143}
144
145void verbs_txreq_exit(struct hfi1_ibdev *dev)
146{
147 kmem_cache_destroy(dev->verbs_txreq_cache);
148 dev->verbs_txreq_cache = NULL;
149}
diff --git a/drivers/staging/rdma/hfi1/verbs_txreq.h b/drivers/staging/rdma/hfi1/verbs_txreq.h
new file mode 100644
index 000000000000..1cf69b2fe4a5
--- /dev/null
+++ b/drivers/staging/rdma/hfi1/verbs_txreq.h
@@ -0,0 +1,116 @@
1/*
2 * Copyright(c) 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#ifndef HFI1_VERBS_TXREQ_H
49#define HFI1_VERBS_TXREQ_H
50
51#include <linux/types.h>
52#include <linux/slab.h>
53
54#include "verbs.h"
55#include "sdma_txreq.h"
56#include "iowait.h"
57
58struct verbs_txreq {
59 struct hfi1_pio_header phdr;
60 struct sdma_txreq txreq;
61 struct rvt_qp *qp;
62 struct rvt_swqe *wqe;
63 struct rvt_mregion *mr;
64 struct rvt_sge_state *ss;
65 struct sdma_engine *sde;
66 struct send_context *psc;
67 u16 hdr_dwords;
68};
69
70struct hfi1_ibdev;
71struct verbs_txreq *__get_txreq(struct hfi1_ibdev *dev,
72 struct rvt_qp *qp);
73
74static inline struct verbs_txreq *get_txreq(struct hfi1_ibdev *dev,
75 struct rvt_qp *qp)
76{
77 struct verbs_txreq *tx;
78 struct hfi1_qp_priv *priv = qp->priv;
79
80 tx = kmem_cache_alloc(dev->verbs_txreq_cache, GFP_ATOMIC);
81 if (unlikely(!tx)) {
82 /* call slow path to get the lock */
83 tx = __get_txreq(dev, qp);
84 if (IS_ERR(tx))
85 return tx;
86 }
87 tx->qp = qp;
88 tx->mr = NULL;
89 tx->sde = priv->s_sde;
90 tx->psc = priv->s_sendcontext;
91 /* so that we can test if the sdma decriptors are there */
92 tx->txreq.num_desc = 0;
93 return tx;
94}
95
96static inline struct sdma_txreq *get_sdma_txreq(struct verbs_txreq *tx)
97{
98 return &tx->txreq;
99}
100
101static inline struct verbs_txreq *get_waiting_verbs_txreq(struct rvt_qp *qp)
102{
103 struct sdma_txreq *stx;
104 struct hfi1_qp_priv *priv = qp->priv;
105
106 stx = iowait_get_txhead(&priv->s_iowait);
107 if (stx)
108 return container_of(stx, struct verbs_txreq, txreq);
109 return NULL;
110}
111
112void hfi1_put_txreq(struct verbs_txreq *tx);
113int verbs_txreq_init(struct hfi1_ibdev *dev);
114void verbs_txreq_exit(struct hfi1_ibdev *dev);
115
116#endif /* HFI1_VERBS_TXREQ_H */
diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h
index 02ac3000ee3c..8156e3c9239c 100644
--- a/include/linux/mlx5/device.h
+++ b/include/linux/mlx5/device.h
@@ -1236,6 +1236,8 @@ enum mlx5_cap_type {
1236 MLX5_CAP_FLOW_TABLE, 1236 MLX5_CAP_FLOW_TABLE,
1237 MLX5_CAP_ESWITCH_FLOW_TABLE, 1237 MLX5_CAP_ESWITCH_FLOW_TABLE,
1238 MLX5_CAP_ESWITCH, 1238 MLX5_CAP_ESWITCH,
1239 MLX5_CAP_RESERVED,
1240 MLX5_CAP_VECTOR_CALC,
1239 /* NUM OF CAP Types */ 1241 /* NUM OF CAP Types */
1240 MLX5_CAP_NUM 1242 MLX5_CAP_NUM
1241}; 1243};
@@ -1298,6 +1300,10 @@ enum mlx5_cap_type {
1298#define MLX5_CAP_ODP(mdev, cap)\ 1300#define MLX5_CAP_ODP(mdev, cap)\
1299 MLX5_GET(odp_cap, mdev->hca_caps_cur[MLX5_CAP_ODP], cap) 1301 MLX5_GET(odp_cap, mdev->hca_caps_cur[MLX5_CAP_ODP], cap)
1300 1302
1303#define MLX5_CAP_VECTOR_CALC(mdev, cap) \
1304 MLX5_GET(vector_calc_cap, \
1305 mdev->hca_caps_cur[MLX5_CAP_VECTOR_CALC], cap)
1306
1301enum { 1307enum {
1302 MLX5_CMD_STAT_OK = 0x0, 1308 MLX5_CMD_STAT_OK = 0x0,
1303 MLX5_CMD_STAT_INT_ERR = 0x1, 1309 MLX5_CMD_STAT_INT_ERR = 0x1,
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 3a954465b2bf..dcd5ac8d3b14 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -613,7 +613,10 @@ struct mlx5_pas {
613}; 613};
614 614
615enum port_state_policy { 615enum port_state_policy {
616 MLX5_AAA_000 616 MLX5_POLICY_DOWN = 0,
617 MLX5_POLICY_UP = 1,
618 MLX5_POLICY_FOLLOW = 2,
619 MLX5_POLICY_INVALID = 0xffffffff
617}; 620};
618 621
619enum phy_port_state { 622enum phy_port_state {
@@ -706,8 +709,7 @@ void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
706void mlx5_cmd_use_polling(struct mlx5_core_dev *dev); 709void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
707int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr); 710int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr);
708int mlx5_cmd_status_to_err_v2(void *ptr); 711int mlx5_cmd_status_to_err_v2(void *ptr);
709int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type, 712int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
710 enum mlx5_cap_mode cap_mode);
711int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, 713int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
712 int out_size); 714 int out_size);
713int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size, 715int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h
index e52730e01ed6..c15b8a864937 100644
--- a/include/linux/mlx5/mlx5_ifc.h
+++ b/include/linux/mlx5/mlx5_ifc.h
@@ -618,6 +618,33 @@ struct mlx5_ifc_odp_cap_bits {
618 u8 reserved_at_e0[0x720]; 618 u8 reserved_at_e0[0x720];
619}; 619};
620 620
621struct mlx5_ifc_calc_op {
622 u8 reserved_at_0[0x10];
623 u8 reserved_at_10[0x9];
624 u8 op_swap_endianness[0x1];
625 u8 op_min[0x1];
626 u8 op_xor[0x1];
627 u8 op_or[0x1];
628 u8 op_and[0x1];
629 u8 op_max[0x1];
630 u8 op_add[0x1];
631};
632
633struct mlx5_ifc_vector_calc_cap_bits {
634 u8 calc_matrix[0x1];
635 u8 reserved_at_1[0x1f];
636 u8 reserved_at_20[0x8];
637 u8 max_vec_count[0x8];
638 u8 reserved_at_30[0xd];
639 u8 max_chunk_size[0x3];
640 struct mlx5_ifc_calc_op calc0;
641 struct mlx5_ifc_calc_op calc1;
642 struct mlx5_ifc_calc_op calc2;
643 struct mlx5_ifc_calc_op calc3;
644
645 u8 reserved_at_e0[0x720];
646};
647
621enum { 648enum {
622 MLX5_WQ_TYPE_LINKED_LIST = 0x0, 649 MLX5_WQ_TYPE_LINKED_LIST = 0x0,
623 MLX5_WQ_TYPE_CYCLIC = 0x1, 650 MLX5_WQ_TYPE_CYCLIC = 0x1,
@@ -784,7 +811,8 @@ struct mlx5_ifc_cmd_hca_cap_bits {
784 u8 cd[0x1]; 811 u8 cd[0x1];
785 u8 reserved_at_22c[0x1]; 812 u8 reserved_at_22c[0x1];
786 u8 apm[0x1]; 813 u8 apm[0x1];
787 u8 reserved_at_22e[0x2]; 814 u8 vector_calc[0x1];
815 u8 reserved_at_22f[0x1];
788 u8 imaicl[0x1]; 816 u8 imaicl[0x1];
789 u8 reserved_at_231[0x4]; 817 u8 reserved_at_231[0x4];
790 u8 qkv[0x1]; 818 u8 qkv[0x1];
@@ -1954,6 +1982,7 @@ union mlx5_ifc_hca_cap_union_bits {
1954 struct mlx5_ifc_flow_table_nic_cap_bits flow_table_nic_cap; 1982 struct mlx5_ifc_flow_table_nic_cap_bits flow_table_nic_cap;
1955 struct mlx5_ifc_flow_table_eswitch_cap_bits flow_table_eswitch_cap; 1983 struct mlx5_ifc_flow_table_eswitch_cap_bits flow_table_eswitch_cap;
1956 struct mlx5_ifc_e_switch_cap_bits e_switch_cap; 1984 struct mlx5_ifc_e_switch_cap_bits e_switch_cap;
1985 struct mlx5_ifc_vector_calc_cap_bits vector_calc_cap;
1957 u8 reserved_at_0[0x8000]; 1986 u8 reserved_at_0[0x8000];
1958}; 1987};
1959 1988
@@ -3681,6 +3710,12 @@ struct mlx5_ifc_query_hca_vport_pkey_in_bits {
3681 u8 pkey_index[0x10]; 3710 u8 pkey_index[0x10];
3682}; 3711};
3683 3712
3713enum {
3714 MLX5_HCA_VPORT_SEL_PORT_GUID = 1 << 0,
3715 MLX5_HCA_VPORT_SEL_NODE_GUID = 1 << 1,
3716 MLX5_HCA_VPORT_SEL_STATE_POLICY = 1 << 2,
3717};
3718
3684struct mlx5_ifc_query_hca_vport_gid_out_bits { 3719struct mlx5_ifc_query_hca_vport_gid_out_bits {
3685 u8 status[0x8]; 3720 u8 status[0x8];
3686 u8 reserved_at_8[0x18]; 3721 u8 reserved_at_8[0x18];
diff --git a/include/linux/mlx5/vport.h b/include/linux/mlx5/vport.h
index a9f2bcc98cab..bd93e6323603 100644
--- a/include/linux/mlx5/vport.h
+++ b/include/linux/mlx5/vport.h
@@ -93,6 +93,11 @@ int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
93int mlx5_nic_vport_enable_roce(struct mlx5_core_dev *mdev); 93int mlx5_nic_vport_enable_roce(struct mlx5_core_dev *mdev);
94int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev); 94int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev);
95int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport, 95int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
96 u8 port_num, void *out, size_t out_sz); 96 int vf, u8 port_num, void *out,
97 size_t out_sz);
98int mlx5_core_modify_hca_vport_context(struct mlx5_core_dev *dev,
99 u8 other_vport, u8 port_num,
100 int vf,
101 struct mlx5_hca_vport_context *req);
97 102
98#endif /* __MLX5_VPORT_H__ */ 103#endif /* __MLX5_VPORT_H__ */
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index be693b34662f..009c85adae4c 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1176,6 +1176,9 @@ struct net_device_ops {
1176 struct nlattr *port[]); 1176 struct nlattr *port[]);
1177 int (*ndo_get_vf_port)(struct net_device *dev, 1177 int (*ndo_get_vf_port)(struct net_device *dev,
1178 int vf, struct sk_buff *skb); 1178 int vf, struct sk_buff *skb);
1179 int (*ndo_set_vf_guid)(struct net_device *dev,
1180 int vf, u64 guid,
1181 int guid_type);
1179 int (*ndo_set_vf_rss_query_en)( 1182 int (*ndo_set_vf_rss_query_en)(
1180 struct net_device *dev, 1183 struct net_device *dev,
1181 int vf, bool setting); 1184 int vf, bool setting);
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 3a03c1d18afa..fb2cef4e9747 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -56,6 +56,7 @@
56#include <linux/string.h> 56#include <linux/string.h>
57#include <linux/slab.h> 57#include <linux/slab.h>
58 58
59#include <linux/if_link.h>
59#include <linux/atomic.h> 60#include <linux/atomic.h>
60#include <linux/mmu_notifier.h> 61#include <linux/mmu_notifier.h>
61#include <asm/uaccess.h> 62#include <asm/uaccess.h>
@@ -97,6 +98,11 @@ enum rdma_node_type {
97 RDMA_NODE_USNIC_UDP, 98 RDMA_NODE_USNIC_UDP,
98}; 99};
99 100
101enum {
102 /* set the local administered indication */
103 IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2,
104};
105
100enum rdma_transport_type { 106enum rdma_transport_type {
101 RDMA_TRANSPORT_IB, 107 RDMA_TRANSPORT_IB,
102 RDMA_TRANSPORT_IWARP, 108 RDMA_TRANSPORT_IWARP,
@@ -213,6 +219,7 @@ enum ib_device_cap_flags {
213 IB_DEVICE_SIGNATURE_HANDOVER = (1 << 30), 219 IB_DEVICE_SIGNATURE_HANDOVER = (1 << 30),
214 IB_DEVICE_ON_DEMAND_PAGING = (1 << 31), 220 IB_DEVICE_ON_DEMAND_PAGING = (1 << 31),
215 IB_DEVICE_SG_GAPS_REG = (1ULL << 32), 221 IB_DEVICE_SG_GAPS_REG = (1ULL << 32),
222 IB_DEVICE_VIRTUAL_FUNCTION = ((u64)1 << 33),
216}; 223};
217 224
218enum ib_signature_prot_cap { 225enum ib_signature_prot_cap {
@@ -274,7 +281,7 @@ struct ib_device_attr {
274 u32 hw_ver; 281 u32 hw_ver;
275 int max_qp; 282 int max_qp;
276 int max_qp_wr; 283 int max_qp_wr;
277 int device_cap_flags; 284 u64 device_cap_flags;
278 int max_sge; 285 int max_sge;
279 int max_sge_rd; 286 int max_sge_rd;
280 int max_cq; 287 int max_cq;
@@ -490,6 +497,7 @@ union rdma_protocol_stats {
490 | RDMA_CORE_CAP_OPA_MAD) 497 | RDMA_CORE_CAP_OPA_MAD)
491 498
492struct ib_port_attr { 499struct ib_port_attr {
500 u64 subnet_prefix;
493 enum ib_port_state state; 501 enum ib_port_state state;
494 enum ib_mtu max_mtu; 502 enum ib_mtu max_mtu;
495 enum ib_mtu active_mtu; 503 enum ib_mtu active_mtu;
@@ -509,6 +517,7 @@ struct ib_port_attr {
509 u8 active_width; 517 u8 active_width;
510 u8 active_speed; 518 u8 active_speed;
511 u8 phys_state; 519 u8 phys_state;
520 bool grh_required;
512}; 521};
513 522
514enum ib_device_modify_flags { 523enum ib_device_modify_flags {
@@ -614,6 +623,7 @@ enum {
614}; 623};
615 624
616#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF) 625#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
626#define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000)
617 627
618enum ib_ah_flags { 628enum ib_ah_flags {
619 IB_AH_GRH = 1 629 IB_AH_GRH = 1
@@ -1860,6 +1870,14 @@ struct ib_device {
1860 void (*disassociate_ucontext)(struct ib_ucontext *ibcontext); 1870 void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
1861 void (*drain_rq)(struct ib_qp *qp); 1871 void (*drain_rq)(struct ib_qp *qp);
1862 void (*drain_sq)(struct ib_qp *qp); 1872 void (*drain_sq)(struct ib_qp *qp);
1873 int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
1874 int state);
1875 int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
1876 struct ifla_vf_info *ivf);
1877 int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
1878 struct ifla_vf_stats *stats);
1879 int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
1880 int type);
1863 1881
1864 struct ib_dma_mapping_ops *dma_ops; 1882 struct ib_dma_mapping_ops *dma_ops;
1865 1883
@@ -2303,6 +2321,15 @@ int ib_query_gid(struct ib_device *device,
2303 u8 port_num, int index, union ib_gid *gid, 2321 u8 port_num, int index, union ib_gid *gid,
2304 struct ib_gid_attr *attr); 2322 struct ib_gid_attr *attr);
2305 2323
2324int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
2325 int state);
2326int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
2327 struct ifla_vf_info *info);
2328int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
2329 struct ifla_vf_stats *stats);
2330int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
2331 int type);
2332
2306int ib_query_pkey(struct ib_device *device, 2333int ib_query_pkey(struct ib_device *device,
2307 u8 port_num, u16 index, u16 *pkey); 2334 u8 port_num, u16 index, u16 *pkey);
2308 2335
diff --git a/include/rdma/opa_port_info.h b/include/rdma/opa_port_info.h
index a0fa975cd1c1..2b95c2c336eb 100644
--- a/include/rdma/opa_port_info.h
+++ b/include/rdma/opa_port_info.h
@@ -97,7 +97,7 @@
97#define OPA_LINKDOWN_REASON_WIDTH_POLICY 41 97#define OPA_LINKDOWN_REASON_WIDTH_POLICY 41
98/* 42-48 reserved */ 98/* 42-48 reserved */
99#define OPA_LINKDOWN_REASON_DISCONNECTED 49 99#define OPA_LINKDOWN_REASON_DISCONNECTED 49
100#define OPA_LINKDOWN_REASONLOCAL_MEDIA_NOT_INSTALLED 50 100#define OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED 50
101#define OPA_LINKDOWN_REASON_NOT_INSTALLED 51 101#define OPA_LINKDOWN_REASON_NOT_INSTALLED 51
102#define OPA_LINKDOWN_REASON_CHASSIS_CONFIG 52 102#define OPA_LINKDOWN_REASON_CHASSIS_CONFIG 52
103/* 53 reserved */ 103/* 53 reserved */
diff --git a/include/rdma/rdma_vt.h b/include/rdma/rdma_vt.h
new file mode 100644
index 000000000000..a8696551abb1
--- /dev/null
+++ b/include/rdma/rdma_vt.h
@@ -0,0 +1,481 @@
1#ifndef DEF_RDMA_VT_H
2#define DEF_RDMA_VT_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51/*
52 * Structure that low level drivers will populate in order to register with the
53 * rdmavt layer.
54 */
55
56#include <linux/spinlock.h>
57#include <linux/list.h>
58#include <linux/hash.h>
59#include <rdma/ib_verbs.h>
60#include <rdma/rdmavt_mr.h>
61#include <rdma/rdmavt_qp.h>
62
63#define RVT_MAX_PKEY_VALUES 16
64
65struct rvt_ibport {
66 struct rvt_qp __rcu *qp[2];
67 struct ib_mad_agent *send_agent; /* agent for SMI (traps) */
68 struct rb_root mcast_tree;
69 spinlock_t lock; /* protect changes in this struct */
70
71 /* non-zero when timer is set */
72 unsigned long mkey_lease_timeout;
73 unsigned long trap_timeout;
74 __be64 gid_prefix; /* in network order */
75 __be64 mkey;
76 u64 tid;
77 u32 port_cap_flags;
78 u32 pma_sample_start;
79 u32 pma_sample_interval;
80 __be16 pma_counter_select[5];
81 u16 pma_tag;
82 u16 mkey_lease_period;
83 u16 sm_lid;
84 u8 sm_sl;
85 u8 mkeyprot;
86 u8 subnet_timeout;
87 u8 vl_high_limit;
88
89 /*
90 * Driver is expected to keep these up to date. These
91 * counters are informational only and not required to be
92 * completely accurate.
93 */
94 u64 n_rc_resends;
95 u64 n_seq_naks;
96 u64 n_rdma_seq;
97 u64 n_rnr_naks;
98 u64 n_other_naks;
99 u64 n_loop_pkts;
100 u64 n_pkt_drops;
101 u64 n_vl15_dropped;
102 u64 n_rc_timeouts;
103 u64 n_dmawait;
104 u64 n_unaligned;
105 u64 n_rc_dupreq;
106 u64 n_rc_seqnak;
107 u16 pkey_violations;
108 u16 qkey_violations;
109 u16 mkey_violations;
110
111 /* Hot-path per CPU counters to avoid cacheline trading to update */
112 u64 z_rc_acks;
113 u64 z_rc_qacks;
114 u64 z_rc_delayed_comp;
115 u64 __percpu *rc_acks;
116 u64 __percpu *rc_qacks;
117 u64 __percpu *rc_delayed_comp;
118
119 void *priv; /* driver private data */
120
121 /*
122 * The pkey table is allocated and maintained by the driver. Drivers
123 * need to have access to this before registering with rdmav. However
124 * rdmavt will need access to it so drivers need to proviee this during
125 * the attach port API call.
126 */
127 u16 *pkey_table;
128
129 struct rvt_ah *sm_ah;
130};
131
132#define RVT_CQN_MAX 16 /* maximum length of cq name */
133
134/*
135 * Things that are driver specific, module parameters in hfi1 and qib
136 */
137struct rvt_driver_params {
138 struct ib_device_attr props;
139
140 /*
141 * Anything driver specific that is not covered by props
142 * For instance special module parameters. Goes here.
143 */
144 unsigned int lkey_table_size;
145 unsigned int qp_table_size;
146 int qpn_start;
147 int qpn_inc;
148 int qpn_res_start;
149 int qpn_res_end;
150 int nports;
151 int npkeys;
152 u8 qos_shift;
153 char cq_name[RVT_CQN_MAX];
154 int node;
155 int max_rdma_atomic;
156 int psn_mask;
157 int psn_shift;
158 int psn_modify_mask;
159 u32 core_cap_flags;
160 u32 max_mad_size;
161};
162
163/* Protection domain */
164struct rvt_pd {
165 struct ib_pd ibpd;
166 int user; /* non-zero if created from user space */
167};
168
169/* Address handle */
170struct rvt_ah {
171 struct ib_ah ibah;
172 struct ib_ah_attr attr;
173 atomic_t refcount;
174 u8 vl;
175 u8 log_pmtu;
176};
177
178struct rvt_dev_info;
179struct rvt_swqe;
180struct rvt_driver_provided {
181 /*
182 * Which functions are required depends on which verbs rdmavt is
183 * providing and which verbs the driver is overriding. See
184 * check_support() for details.
185 */
186
187 /* Passed to ib core registration. Callback to create syfs files */
188 int (*port_callback)(struct ib_device *, u8, struct kobject *);
189
190 /*
191 * Returns a string to represent the device for which is being
192 * registered. This is primarily used for error and debug messages on
193 * the console.
194 */
195 const char * (*get_card_name)(struct rvt_dev_info *rdi);
196
197 /*
198 * Returns a pointer to the undelying hardware's PCI device. This is
199 * used to display information as to what hardware is being referenced
200 * in an output message
201 */
202 struct pci_dev * (*get_pci_dev)(struct rvt_dev_info *rdi);
203
204 /*
205 * Allocate a private queue pair data structure for driver specific
206 * information which is opaque to rdmavt.
207 */
208 void * (*qp_priv_alloc)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
209 gfp_t gfp);
210
211 /*
212 * Free the driver's private qp structure.
213 */
214 void (*qp_priv_free)(struct rvt_dev_info *rdi, struct rvt_qp *qp);
215
216 /*
217 * Inform the driver the particular qp in quesiton has been reset so
218 * that it can clean up anything it needs to.
219 */
220 void (*notify_qp_reset)(struct rvt_qp *qp);
221
222 /*
223 * Give the driver a notice that there is send work to do. It is up to
224 * the driver to generally push the packets out, this just queues the
225 * work with the driver. There are two variants here. The no_lock
226 * version requires the s_lock not to be held. The other assumes the
227 * s_lock is held.
228 */
229 void (*schedule_send)(struct rvt_qp *qp);
230 void (*schedule_send_no_lock)(struct rvt_qp *qp);
231
232 /*
233 * Sometimes rdmavt needs to kick the driver's send progress. That is
234 * done by this call back.
235 */
236 void (*do_send)(struct rvt_qp *qp);
237
238 /*
239 * Get a path mtu from the driver based on qp attributes.
240 */
241 int (*get_pmtu_from_attr)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
242 struct ib_qp_attr *attr);
243
244 /*
245 * Notify driver that it needs to flush any outstanding IO requests that
246 * are waiting on a qp.
247 */
248 void (*flush_qp_waiters)(struct rvt_qp *qp);
249
250 /*
251 * Notify driver to stop its queue of sending packets. Nothing else
252 * should be posted to the queue pair after this has been called.
253 */
254 void (*stop_send_queue)(struct rvt_qp *qp);
255
256 /*
257 * Have the drivr drain any in progress operations
258 */
259 void (*quiesce_qp)(struct rvt_qp *qp);
260
261 /*
262 * Inform the driver a qp has went to error state.
263 */
264 void (*notify_error_qp)(struct rvt_qp *qp);
265
266 /*
267 * Get an MTU for a qp.
268 */
269 u32 (*mtu_from_qp)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
270 u32 pmtu);
271 /*
272 * Convert an mtu to a path mtu
273 */
274 int (*mtu_to_path_mtu)(u32 mtu);
275
276 /*
277 * Get the guid of a port in big endian byte order
278 */
279 int (*get_guid_be)(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
280 int guid_index, __be64 *guid);
281
282 /*
283 * Query driver for the state of the port.
284 */
285 int (*query_port_state)(struct rvt_dev_info *rdi, u8 port_num,
286 struct ib_port_attr *props);
287
288 /*
289 * Tell driver to shutdown a port
290 */
291 int (*shut_down_port)(struct rvt_dev_info *rdi, u8 port_num);
292
293 /* Tell driver to send a trap for changed port capabilities */
294 void (*cap_mask_chg)(struct rvt_dev_info *rdi, u8 port_num);
295
296 /*
297 * The following functions can be safely ignored completely. Any use of
298 * these is checked for NULL before blindly calling. Rdmavt should also
299 * be functional if drivers omit these.
300 */
301
302 /* Called to inform the driver that all qps should now be freed. */
303 unsigned (*free_all_qps)(struct rvt_dev_info *rdi);
304
305 /* Driver specific AH validation */
306 int (*check_ah)(struct ib_device *, struct ib_ah_attr *);
307
308 /* Inform the driver a new AH has been created */
309 void (*notify_new_ah)(struct ib_device *, struct ib_ah_attr *,
310 struct rvt_ah *);
311
312 /* Let the driver pick the next queue pair number*/
313 int (*alloc_qpn)(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
314 enum ib_qp_type type, u8 port_num, gfp_t gfp);
315
316 /* Determine if its safe or allowed to modify the qp */
317 int (*check_modify_qp)(struct rvt_qp *qp, struct ib_qp_attr *attr,
318 int attr_mask, struct ib_udata *udata);
319
320 /* Driver specific QP modification/notification-of */
321 void (*modify_qp)(struct rvt_qp *qp, struct ib_qp_attr *attr,
322 int attr_mask, struct ib_udata *udata);
323
324 /* Driver specific work request checking */
325 int (*check_send_wqe)(struct rvt_qp *qp, struct rvt_swqe *wqe);
326
327 /* Notify driver a mad agent has been created */
328 void (*notify_create_mad_agent)(struct rvt_dev_info *rdi, int port_idx);
329
330 /* Notify driver a mad agent has been removed */
331 void (*notify_free_mad_agent)(struct rvt_dev_info *rdi, int port_idx);
332
333};
334
335struct rvt_dev_info {
336 struct ib_device ibdev; /* Keep this first. Nothing above here */
337
338 /*
339 * Prior to calling for registration the driver will be responsible for
340 * allocating space for this structure.
341 *
342 * The driver will also be responsible for filling in certain members of
343 * dparms.props. The driver needs to fill in dparms exactly as it would
344 * want values reported to a ULP. This will be returned to the caller
345 * in rdmavt's device. The driver should also therefore refrain from
346 * modifying this directly after registration with rdmavt.
347 */
348
349 /* Driver specific properties */
350 struct rvt_driver_params dparms;
351
352 struct rvt_mregion __rcu *dma_mr;
353 struct rvt_lkey_table lkey_table;
354
355 /* Driver specific helper functions */
356 struct rvt_driver_provided driver_f;
357
358 /* Internal use */
359 int n_pds_allocated;
360 spinlock_t n_pds_lock; /* Protect pd allocated count */
361
362 int n_ahs_allocated;
363 spinlock_t n_ahs_lock; /* Protect ah allocated count */
364
365 u32 n_srqs_allocated;
366 spinlock_t n_srqs_lock; /* Protect srqs allocated count */
367
368 int flags;
369 struct rvt_ibport **ports;
370
371 /* QP */
372 struct rvt_qp_ibdev *qp_dev;
373 u32 n_qps_allocated; /* number of QPs allocated for device */
374 u32 n_rc_qps; /* number of RC QPs allocated for device */
375 u32 busy_jiffies; /* timeout scaling based on RC QP count */
376 spinlock_t n_qps_lock; /* protect qps, rc qps and busy jiffy counts */
377
378 /* memory maps */
379 struct list_head pending_mmaps;
380 spinlock_t mmap_offset_lock; /* protect mmap_offset */
381 u32 mmap_offset;
382 spinlock_t pending_lock; /* protect pending mmap list */
383
384 /* CQ */
385 struct kthread_worker *worker; /* per device cq worker */
386 u32 n_cqs_allocated; /* number of CQs allocated for device */
387 spinlock_t n_cqs_lock; /* protect count of in use cqs */
388
389 /* Multicast */
390 u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
391 spinlock_t n_mcast_grps_lock;
392
393};
394
395static inline struct rvt_pd *ibpd_to_rvtpd(struct ib_pd *ibpd)
396{
397 return container_of(ibpd, struct rvt_pd, ibpd);
398}
399
400static inline struct rvt_ah *ibah_to_rvtah(struct ib_ah *ibah)
401{
402 return container_of(ibah, struct rvt_ah, ibah);
403}
404
405static inline struct rvt_dev_info *ib_to_rvt(struct ib_device *ibdev)
406{
407 return container_of(ibdev, struct rvt_dev_info, ibdev);
408}
409
410static inline struct rvt_srq *ibsrq_to_rvtsrq(struct ib_srq *ibsrq)
411{
412 return container_of(ibsrq, struct rvt_srq, ibsrq);
413}
414
415static inline struct rvt_qp *ibqp_to_rvtqp(struct ib_qp *ibqp)
416{
417 return container_of(ibqp, struct rvt_qp, ibqp);
418}
419
420static inline unsigned rvt_get_npkeys(struct rvt_dev_info *rdi)
421{
422 /*
423 * All ports have same number of pkeys.
424 */
425 return rdi->dparms.npkeys;
426}
427
428/*
429 * Return the indexed PKEY from the port PKEY table.
430 */
431static inline u16 rvt_get_pkey(struct rvt_dev_info *rdi,
432 int port_index,
433 unsigned index)
434{
435 if (index >= rvt_get_npkeys(rdi))
436 return 0;
437 else
438 return rdi->ports[port_index]->pkey_table[index];
439}
440
441/**
442 * rvt_lookup_qpn - return the QP with the given QPN
443 * @ibp: the ibport
444 * @qpn: the QP number to look up
445 *
446 * The caller must hold the rcu_read_lock(), and keep the lock until
447 * the returned qp is no longer in use.
448 */
449/* TODO: Remove this and put in rdmavt/qp.h when no longer needed by drivers */
450static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi,
451 struct rvt_ibport *rvp,
452 u32 qpn) __must_hold(RCU)
453{
454 struct rvt_qp *qp = NULL;
455
456 if (unlikely(qpn <= 1)) {
457 qp = rcu_dereference(rvp->qp[qpn]);
458 } else {
459 u32 n = hash_32(qpn, rdi->qp_dev->qp_table_bits);
460
461 for (qp = rcu_dereference(rdi->qp_dev->qp_table[n]); qp;
462 qp = rcu_dereference(qp->next))
463 if (qp->ibqp.qp_num == qpn)
464 break;
465 }
466 return qp;
467}
468
469struct rvt_dev_info *rvt_alloc_device(size_t size, int nports);
470int rvt_register_device(struct rvt_dev_info *rvd);
471void rvt_unregister_device(struct rvt_dev_info *rvd);
472int rvt_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
473int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
474 int port_index, u16 *pkey_table);
475int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
476 u32 len, u64 vaddr, u32 rkey, int acc);
477int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd,
478 struct rvt_sge *isge, struct ib_sge *sge, int acc);
479struct rvt_mcast *rvt_mcast_find(struct rvt_ibport *ibp, union ib_gid *mgid);
480
481#endif /* DEF_RDMA_VT_H */
diff --git a/include/rdma/rdmavt_cq.h b/include/rdma/rdmavt_cq.h
new file mode 100644
index 000000000000..51fd00b243d0
--- /dev/null
+++ b/include/rdma/rdmavt_cq.h
@@ -0,0 +1,99 @@
1#ifndef DEF_RDMAVT_INCCQ_H
2#define DEF_RDMAVT_INCCQ_H
3
4/*
5 *
6 * This file is provided under a dual BSD/GPLv2 license. When using or
7 * redistributing this file, you may do so under either license.
8 *
9 * GPL LICENSE SUMMARY
10 *
11 * Copyright(c) 2016 Intel Corporation.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * BSD LICENSE
23 *
24 * Copyright(c) 2015 Intel Corporation.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 *
30 * - Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * - Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in
34 * the documentation and/or other materials provided with the
35 * distribution.
36 * - Neither the name of Intel Corporation nor the names of its
37 * contributors may be used to endorse or promote products derived
38 * from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 *
52 */
53
54#include <linux/kthread.h>
55#include <rdma/ib_user_verbs.h>
56
57/*
58 * Define an ib_cq_notify value that is not valid so we know when CQ
59 * notifications are armed.
60 */
61#define RVT_CQ_NONE (IB_CQ_NEXT_COMP + 1)
62
63/*
64 * This structure is used to contain the head pointer, tail pointer,
65 * and completion queue entries as a single memory allocation so
66 * it can be mmap'ed into user space.
67 */
68struct rvt_cq_wc {
69 u32 head; /* index of next entry to fill */
70 u32 tail; /* index of next ib_poll_cq() entry */
71 union {
72 /* these are actually size ibcq.cqe + 1 */
73 struct ib_uverbs_wc uqueue[0];
74 struct ib_wc kqueue[0];
75 };
76};
77
78/*
79 * The completion queue structure.
80 */
81struct rvt_cq {
82 struct ib_cq ibcq;
83 struct kthread_work comptask;
84 spinlock_t lock; /* protect changes in this struct */
85 u8 notify;
86 u8 triggered;
87 struct rvt_dev_info *rdi;
88 struct rvt_cq_wc *queue;
89 struct rvt_mmap_info *ip;
90};
91
92static inline struct rvt_cq *ibcq_to_rvtcq(struct ib_cq *ibcq)
93{
94 return container_of(ibcq, struct rvt_cq, ibcq);
95}
96
97void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited);
98
99#endif /* DEF_RDMAVT_INCCQH */
diff --git a/include/rdma/rdmavt_mr.h b/include/rdma/rdmavt_mr.h
new file mode 100644
index 000000000000..5edffdca8c53
--- /dev/null
+++ b/include/rdma/rdmavt_mr.h
@@ -0,0 +1,139 @@
1#ifndef DEF_RDMAVT_INCMR_H
2#define DEF_RDMAVT_INCMR_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51/*
52 * For Memory Regions. This stuff should probably be moved into rdmavt/mr.h once
53 * drivers no longer need access to the MR directly.
54 */
55
56/*
57 * A segment is a linear region of low physical memory.
58 * Used by the verbs layer.
59 */
60struct rvt_seg {
61 void *vaddr;
62 size_t length;
63};
64
65/* The number of rvt_segs that fit in a page. */
66#define RVT_SEGSZ (PAGE_SIZE / sizeof(struct rvt_seg))
67
68struct rvt_segarray {
69 struct rvt_seg segs[RVT_SEGSZ];
70};
71
72struct rvt_mregion {
73 struct ib_pd *pd; /* shares refcnt of ibmr.pd */
74 u64 user_base; /* User's address for this region */
75 u64 iova; /* IB start address of this region */
76 size_t length;
77 u32 lkey;
78 u32 offset; /* offset (bytes) to start of region */
79 int access_flags;
80 u32 max_segs; /* number of rvt_segs in all the arrays */
81 u32 mapsz; /* size of the map array */
82 u8 page_shift; /* 0 - non unform/non powerof2 sizes */
83 u8 lkey_published; /* in global table */
84 struct completion comp; /* complete when refcount goes to zero */
85 atomic_t refcount;
86 struct rvt_segarray *map[0]; /* the segments */
87};
88
89#define RVT_MAX_LKEY_TABLE_BITS 23
90
91struct rvt_lkey_table {
92 spinlock_t lock; /* protect changes in this struct */
93 u32 next; /* next unused index (speeds search) */
94 u32 gen; /* generation count */
95 u32 max; /* size of the table */
96 struct rvt_mregion __rcu **table;
97};
98
99/*
100 * These keep track of the copy progress within a memory region.
101 * Used by the verbs layer.
102 */
103struct rvt_sge {
104 struct rvt_mregion *mr;
105 void *vaddr; /* kernel virtual address of segment */
106 u32 sge_length; /* length of the SGE */
107 u32 length; /* remaining length of the segment */
108 u16 m; /* current index: mr->map[m] */
109 u16 n; /* current index: mr->map[m]->segs[n] */
110};
111
112struct rvt_sge_state {
113 struct rvt_sge *sg_list; /* next SGE to be used if any */
114 struct rvt_sge sge; /* progress state for the current SGE */
115 u32 total_len;
116 u8 num_sge;
117};
118
119static inline void rvt_put_mr(struct rvt_mregion *mr)
120{
121 if (unlikely(atomic_dec_and_test(&mr->refcount)))
122 complete(&mr->comp);
123}
124
125static inline void rvt_get_mr(struct rvt_mregion *mr)
126{
127 atomic_inc(&mr->refcount);
128}
129
130static inline void rvt_put_ss(struct rvt_sge_state *ss)
131{
132 while (ss->num_sge) {
133 rvt_put_mr(ss->sge.mr);
134 if (--ss->num_sge)
135 ss->sge = *ss->sg_list++;
136 }
137}
138
139#endif /* DEF_RDMAVT_INCMRH */
diff --git a/include/rdma/rdmavt_qp.h b/include/rdma/rdmavt_qp.h
new file mode 100644
index 000000000000..497e59065c2c
--- /dev/null
+++ b/include/rdma/rdmavt_qp.h
@@ -0,0 +1,446 @@
1#ifndef DEF_RDMAVT_INCQP_H
2#define DEF_RDMAVT_INCQP_H
3
4/*
5 * Copyright(c) 2016 Intel Corporation.
6 *
7 * This file is provided under a dual BSD/GPLv2 license. When using or
8 * redistributing this file, you may do so under either license.
9 *
10 * GPL LICENSE SUMMARY
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51#include <rdma/rdma_vt.h>
52#include <rdma/ib_pack.h>
53#include <rdma/ib_verbs.h>
54/*
55 * Atomic bit definitions for r_aflags.
56 */
57#define RVT_R_WRID_VALID 0
58#define RVT_R_REWIND_SGE 1
59
60/*
61 * Bit definitions for r_flags.
62 */
63#define RVT_R_REUSE_SGE 0x01
64#define RVT_R_RDMAR_SEQ 0x02
65#define RVT_R_RSP_NAK 0x04
66#define RVT_R_RSP_SEND 0x08
67#define RVT_R_COMM_EST 0x10
68
69/*
70 * Bit definitions for s_flags.
71 *
72 * RVT_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
73 * RVT_S_BUSY - send tasklet is processing the QP
74 * RVT_S_TIMER - the RC retry timer is active
75 * RVT_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
76 * RVT_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
77 * before processing the next SWQE
78 * RVT_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
79 * before processing the next SWQE
80 * RVT_S_WAIT_RNR - waiting for RNR timeout
81 * RVT_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
82 * RVT_S_WAIT_DMA - waiting for send DMA queue to drain before generating
83 * next send completion entry not via send DMA
84 * RVT_S_WAIT_PIO - waiting for a send buffer to be available
85 * RVT_S_WAIT_PIO_DRAIN - waiting for a qp to drain pio packets
86 * RVT_S_WAIT_TX - waiting for a struct verbs_txreq to be available
87 * RVT_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
88 * RVT_S_WAIT_KMEM - waiting for kernel memory to be available
89 * RVT_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
90 * RVT_S_WAIT_ACK - waiting for an ACK packet before sending more requests
91 * RVT_S_SEND_ONE - send one packet, request ACK, then wait for ACK
92 * RVT_S_ECN - a BECN was queued to the send engine
93 */
94#define RVT_S_SIGNAL_REQ_WR 0x0001
95#define RVT_S_BUSY 0x0002
96#define RVT_S_TIMER 0x0004
97#define RVT_S_RESP_PENDING 0x0008
98#define RVT_S_ACK_PENDING 0x0010
99#define RVT_S_WAIT_FENCE 0x0020
100#define RVT_S_WAIT_RDMAR 0x0040
101#define RVT_S_WAIT_RNR 0x0080
102#define RVT_S_WAIT_SSN_CREDIT 0x0100
103#define RVT_S_WAIT_DMA 0x0200
104#define RVT_S_WAIT_PIO 0x0400
105#define RVT_S_WAIT_PIO_DRAIN 0x0800
106#define RVT_S_WAIT_TX 0x1000
107#define RVT_S_WAIT_DMA_DESC 0x2000
108#define RVT_S_WAIT_KMEM 0x4000
109#define RVT_S_WAIT_PSN 0x8000
110#define RVT_S_WAIT_ACK 0x10000
111#define RVT_S_SEND_ONE 0x20000
112#define RVT_S_UNLIMITED_CREDIT 0x40000
113#define RVT_S_AHG_VALID 0x80000
114#define RVT_S_AHG_CLEAR 0x100000
115#define RVT_S_ECN 0x200000
116
117/*
118 * Wait flags that would prevent any packet type from being sent.
119 */
120#define RVT_S_ANY_WAIT_IO (RVT_S_WAIT_PIO | RVT_S_WAIT_TX | \
121 RVT_S_WAIT_DMA_DESC | RVT_S_WAIT_KMEM)
122
123/*
124 * Wait flags that would prevent send work requests from making progress.
125 */
126#define RVT_S_ANY_WAIT_SEND (RVT_S_WAIT_FENCE | RVT_S_WAIT_RDMAR | \
127 RVT_S_WAIT_RNR | RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_DMA | \
128 RVT_S_WAIT_PSN | RVT_S_WAIT_ACK)
129
130#define RVT_S_ANY_WAIT (RVT_S_ANY_WAIT_IO | RVT_S_ANY_WAIT_SEND)
131
132/* Number of bits to pay attention to in the opcode for checking qp type */
133#define RVT_OPCODE_QP_MASK 0xE0
134
135/* Flags for checking QP state (see ib_rvt_state_ops[]) */
136#define RVT_POST_SEND_OK 0x01
137#define RVT_POST_RECV_OK 0x02
138#define RVT_PROCESS_RECV_OK 0x04
139#define RVT_PROCESS_SEND_OK 0x08
140#define RVT_PROCESS_NEXT_SEND_OK 0x10
141#define RVT_FLUSH_SEND 0x20
142#define RVT_FLUSH_RECV 0x40
143#define RVT_PROCESS_OR_FLUSH_SEND \
144 (RVT_PROCESS_SEND_OK | RVT_FLUSH_SEND)
145
146/*
147 * Send work request queue entry.
148 * The size of the sg_list is determined when the QP is created and stored
149 * in qp->s_max_sge.
150 */
151struct rvt_swqe {
152 union {
153 struct ib_send_wr wr; /* don't use wr.sg_list */
154 struct ib_ud_wr ud_wr;
155 struct ib_reg_wr reg_wr;
156 struct ib_rdma_wr rdma_wr;
157 struct ib_atomic_wr atomic_wr;
158 };
159 u32 psn; /* first packet sequence number */
160 u32 lpsn; /* last packet sequence number */
161 u32 ssn; /* send sequence number */
162 u32 length; /* total length of data in sg_list */
163 struct rvt_sge sg_list[0];
164};
165
166/*
167 * Receive work request queue entry.
168 * The size of the sg_list is determined when the QP (or SRQ) is created
169 * and stored in qp->r_rq.max_sge (or srq->rq.max_sge).
170 */
171struct rvt_rwqe {
172 u64 wr_id;
173 u8 num_sge;
174 struct ib_sge sg_list[0];
175};
176
177/*
178 * This structure is used to contain the head pointer, tail pointer,
179 * and receive work queue entries as a single memory allocation so
180 * it can be mmap'ed into user space.
181 * Note that the wq array elements are variable size so you can't
182 * just index into the array to get the N'th element;
183 * use get_rwqe_ptr() instead.
184 */
185struct rvt_rwq {
186 u32 head; /* new work requests posted to the head */
187 u32 tail; /* receives pull requests from here. */
188 struct rvt_rwqe wq[0];
189};
190
191struct rvt_rq {
192 struct rvt_rwq *wq;
193 u32 size; /* size of RWQE array */
194 u8 max_sge;
195 /* protect changes in this struct */
196 spinlock_t lock ____cacheline_aligned_in_smp;
197};
198
199/*
200 * This structure is used by rvt_mmap() to validate an offset
201 * when an mmap() request is made. The vm_area_struct then uses
202 * this as its vm_private_data.
203 */
204struct rvt_mmap_info {
205 struct list_head pending_mmaps;
206 struct ib_ucontext *context;
207 void *obj;
208 __u64 offset;
209 struct kref ref;
210 unsigned size;
211};
212
213#define RVT_MAX_RDMA_ATOMIC 16
214
215/*
216 * This structure holds the information that the send tasklet needs
217 * to send a RDMA read response or atomic operation.
218 */
219struct rvt_ack_entry {
220 u8 opcode;
221 u8 sent;
222 u32 psn;
223 u32 lpsn;
224 union {
225 struct rvt_sge rdma_sge;
226 u64 atomic_data;
227 };
228};
229
230#define RC_QP_SCALING_INTERVAL 5
231
232/*
233 * Variables prefixed with s_ are for the requester (sender).
234 * Variables prefixed with r_ are for the responder (receiver).
235 * Variables prefixed with ack_ are for responder replies.
236 *
237 * Common variables are protected by both r_rq.lock and s_lock in that order
238 * which only happens in modify_qp() or changing the QP 'state'.
239 */
240struct rvt_qp {
241 struct ib_qp ibqp;
242 void *priv; /* Driver private data */
243 /* read mostly fields above and below */
244 struct ib_ah_attr remote_ah_attr;
245 struct ib_ah_attr alt_ah_attr;
246 struct rvt_qp __rcu *next; /* link list for QPN hash table */
247 struct rvt_swqe *s_wq; /* send work queue */
248 struct rvt_mmap_info *ip;
249
250 unsigned long timeout_jiffies; /* computed from timeout */
251
252 enum ib_mtu path_mtu;
253 int srate_mbps; /* s_srate (below) converted to Mbit/s */
254 pid_t pid; /* pid for user mode QPs */
255 u32 remote_qpn;
256 u32 qkey; /* QKEY for this QP (for UD or RD) */
257 u32 s_size; /* send work queue size */
258 u32 s_ahgpsn; /* set to the psn in the copy of the header */
259
260 u16 pmtu; /* decoded from path_mtu */
261 u8 log_pmtu; /* shift for pmtu */
262 u8 state; /* QP state */
263 u8 allowed_ops; /* high order bits of allowed opcodes */
264 u8 qp_access_flags;
265 u8 alt_timeout; /* Alternate path timeout for this QP */
266 u8 timeout; /* Timeout for this QP */
267 u8 s_srate;
268 u8 s_mig_state;
269 u8 port_num;
270 u8 s_pkey_index; /* PKEY index to use */
271 u8 s_alt_pkey_index; /* Alternate path PKEY index to use */
272 u8 r_max_rd_atomic; /* max number of RDMA read/atomic to receive */
273 u8 s_max_rd_atomic; /* max number of RDMA read/atomic to send */
274 u8 s_retry_cnt; /* number of times to retry */
275 u8 s_rnr_retry_cnt;
276 u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */
277 u8 s_max_sge; /* size of s_wq->sg_list */
278 u8 s_draining;
279
280 /* start of read/write fields */
281 atomic_t refcount ____cacheline_aligned_in_smp;
282 wait_queue_head_t wait;
283
284 struct rvt_ack_entry s_ack_queue[RVT_MAX_RDMA_ATOMIC + 1]
285 ____cacheline_aligned_in_smp;
286 struct rvt_sge_state s_rdma_read_sge;
287
288 spinlock_t r_lock ____cacheline_aligned_in_smp; /* used for APM */
289 u32 r_psn; /* expected rcv packet sequence number */
290 unsigned long r_aflags;
291 u64 r_wr_id; /* ID for current receive WQE */
292 u32 r_ack_psn; /* PSN for next ACK or atomic ACK */
293 u32 r_len; /* total length of r_sge */
294 u32 r_rcv_len; /* receive data len processed */
295 u32 r_msn; /* message sequence number */
296
297 u8 r_state; /* opcode of last packet received */
298 u8 r_flags;
299 u8 r_head_ack_queue; /* index into s_ack_queue[] */
300
301 struct list_head rspwait; /* link for waiting to respond */
302
303 struct rvt_sge_state r_sge; /* current receive data */
304 struct rvt_rq r_rq; /* receive work queue */
305
306 /* post send line */
307 spinlock_t s_hlock ____cacheline_aligned_in_smp;
308 u32 s_head; /* new entries added here */
309 u32 s_next_psn; /* PSN for next request */
310 u32 s_avail; /* number of entries avail */
311 u32 s_ssn; /* SSN of tail entry */
312
313 spinlock_t s_lock ____cacheline_aligned_in_smp;
314 u32 s_flags;
315 struct rvt_sge_state *s_cur_sge;
316 struct rvt_swqe *s_wqe;
317 struct rvt_sge_state s_sge; /* current send request data */
318 struct rvt_mregion *s_rdma_mr;
319 u32 s_cur_size; /* size of send packet in bytes */
320 u32 s_len; /* total length of s_sge */
321 u32 s_rdma_read_len; /* total length of s_rdma_read_sge */
322 u32 s_last_psn; /* last response PSN processed */
323 u32 s_sending_psn; /* lowest PSN that is being sent */
324 u32 s_sending_hpsn; /* highest PSN that is being sent */
325 u32 s_psn; /* current packet sequence number */
326 u32 s_ack_rdma_psn; /* PSN for sending RDMA read responses */
327 u32 s_ack_psn; /* PSN for acking sends and RDMA writes */
328 u32 s_tail; /* next entry to process */
329 u32 s_cur; /* current work queue entry */
330 u32 s_acked; /* last un-ACK'ed entry */
331 u32 s_last; /* last completed entry */
332 u32 s_lsn; /* limit sequence number (credit) */
333 u16 s_hdrwords; /* size of s_hdr in 32 bit words */
334 u16 s_rdma_ack_cnt;
335 s8 s_ahgidx;
336 u8 s_state; /* opcode of last packet sent */
337 u8 s_ack_state; /* opcode of packet to ACK */
338 u8 s_nak_state; /* non-zero if NAK is pending */
339 u8 r_nak_state; /* non-zero if NAK is pending */
340 u8 s_retry; /* requester retry counter */
341 u8 s_rnr_retry; /* requester RNR retry counter */
342 u8 s_num_rd_atomic; /* number of RDMA read/atomic pending */
343 u8 s_tail_ack_queue; /* index into s_ack_queue[] */
344
345 struct rvt_sge_state s_ack_rdma_sge;
346 struct timer_list s_timer;
347
348 /*
349 * This sge list MUST be last. Do not add anything below here.
350 */
351 struct rvt_sge r_sg_list[0] /* verified SGEs */
352 ____cacheline_aligned_in_smp;
353};
354
355struct rvt_srq {
356 struct ib_srq ibsrq;
357 struct rvt_rq rq;
358 struct rvt_mmap_info *ip;
359 /* send signal when number of RWQEs < limit */
360 u32 limit;
361};
362
363#define RVT_QPN_MAX BIT(24)
364#define RVT_QPNMAP_ENTRIES (RVT_QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
365#define RVT_BITS_PER_PAGE (PAGE_SIZE * BITS_PER_BYTE)
366#define RVT_BITS_PER_PAGE_MASK (RVT_BITS_PER_PAGE - 1)
367#define RVT_QPN_MASK 0xFFFFFF
368
369/*
370 * QPN-map pages start out as NULL, they get allocated upon
371 * first use and are never deallocated. This way,
372 * large bitmaps are not allocated unless large numbers of QPs are used.
373 */
374struct rvt_qpn_map {
375 void *page;
376};
377
378struct rvt_qpn_table {
379 spinlock_t lock; /* protect changes to the qp table */
380 unsigned flags; /* flags for QP0/1 allocated for each port */
381 u32 last; /* last QP number allocated */
382 u32 nmaps; /* size of the map table */
383 u16 limit;
384 u8 incr;
385 /* bit map of free QP numbers other than 0/1 */
386 struct rvt_qpn_map map[RVT_QPNMAP_ENTRIES];
387};
388
389struct rvt_qp_ibdev {
390 u32 qp_table_size;
391 u32 qp_table_bits;
392 struct rvt_qp __rcu **qp_table;
393 spinlock_t qpt_lock; /* qptable lock */
394 struct rvt_qpn_table qpn_table;
395};
396
397/*
398 * There is one struct rvt_mcast for each multicast GID.
399 * All attached QPs are then stored as a list of
400 * struct rvt_mcast_qp.
401 */
402struct rvt_mcast_qp {
403 struct list_head list;
404 struct rvt_qp *qp;
405};
406
407struct rvt_mcast {
408 struct rb_node rb_node;
409 union ib_gid mgid;
410 struct list_head qp_list;
411 wait_queue_head_t wait;
412 atomic_t refcount;
413 int n_attached;
414};
415
416/*
417 * Since struct rvt_swqe is not a fixed size, we can't simply index into
418 * struct rvt_qp.s_wq. This function does the array index computation.
419 */
420static inline struct rvt_swqe *rvt_get_swqe_ptr(struct rvt_qp *qp,
421 unsigned n)
422{
423 return (struct rvt_swqe *)((char *)qp->s_wq +
424 (sizeof(struct rvt_swqe) +
425 qp->s_max_sge *
426 sizeof(struct rvt_sge)) * n);
427}
428
429/*
430 * Since struct rvt_rwqe is not a fixed size, we can't simply index into
431 * struct rvt_rwq.wq. This function does the array index computation.
432 */
433static inline struct rvt_rwqe *rvt_get_rwqe_ptr(struct rvt_rq *rq, unsigned n)
434{
435 return (struct rvt_rwqe *)
436 ((char *)rq->wq->wq +
437 (sizeof(struct rvt_rwqe) +
438 rq->max_sge * sizeof(struct ib_sge)) * n);
439}
440
441extern const int ib_rvt_state_ops[];
442
443struct rvt_dev_info;
444int rvt_error_qp(struct rvt_qp *qp, enum ib_wc_status err);
445
446#endif /* DEF_RDMAVT_INCQP_H */
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 8e3f88fa5b59..a62a0129d614 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -599,6 +599,8 @@ enum {
599 */ 599 */
600 IFLA_VF_STATS, /* network device statistics */ 600 IFLA_VF_STATS, /* network device statistics */
601 IFLA_VF_TRUST, /* Trust VF */ 601 IFLA_VF_TRUST, /* Trust VF */
602 IFLA_VF_IB_NODE_GUID, /* VF Infiniband node GUID */
603 IFLA_VF_IB_PORT_GUID, /* VF Infiniband port GUID */
602 __IFLA_VF_MAX, 604 __IFLA_VF_MAX,
603}; 605};
604 606
@@ -631,6 +633,11 @@ struct ifla_vf_spoofchk {
631 __u32 setting; 633 __u32 setting;
632}; 634};
633 635
636struct ifla_vf_guid {
637 __u32 vf;
638 __u64 guid;
639};
640
634enum { 641enum {
635 IFLA_VF_LINK_STATE_AUTO, /* link state of the uplink */ 642 IFLA_VF_LINK_STATE_AUTO, /* link state of the uplink */
636 IFLA_VF_LINK_STATE_ENABLE, /* link always up */ 643 IFLA_VF_LINK_STATE_ENABLE, /* link always up */
diff --git a/include/uapi/rdma/hfi/hfi1_user.h b/include/uapi/rdma/hfi/hfi1_user.h
index 288694e422fb..a533cecab14f 100644
--- a/include/uapi/rdma/hfi/hfi1_user.h
+++ b/include/uapi/rdma/hfi/hfi1_user.h
@@ -66,7 +66,7 @@
66 * The major version changes when data structures change in an incompatible 66 * The major version changes when data structures change in an incompatible
67 * way. The driver must be the same for initialization to succeed. 67 * way. The driver must be the same for initialization to succeed.
68 */ 68 */
69#define HFI1_USER_SWMAJOR 4 69#define HFI1_USER_SWMAJOR 5
70 70
71/* 71/*
72 * Minor version differences are always compatible 72 * Minor version differences are always compatible
@@ -93,7 +93,7 @@
93#define HFI1_CAP_MULTI_PKT_EGR (1UL << 7) /* Enable multi-packet Egr buffs*/ 93#define HFI1_CAP_MULTI_PKT_EGR (1UL << 7) /* Enable multi-packet Egr buffs*/
94#define HFI1_CAP_NODROP_RHQ_FULL (1UL << 8) /* Don't drop on Hdr Q full */ 94#define HFI1_CAP_NODROP_RHQ_FULL (1UL << 8) /* Don't drop on Hdr Q full */
95#define HFI1_CAP_NODROP_EGR_FULL (1UL << 9) /* Don't drop on EGR buffs full */ 95#define HFI1_CAP_NODROP_EGR_FULL (1UL << 9) /* Don't drop on EGR buffs full */
96#define HFI1_CAP_TID_UNMAP (1UL << 10) /* Enable Expected TID caching */ 96#define HFI1_CAP_TID_UNMAP (1UL << 10) /* Disable Expected TID caching */
97#define HFI1_CAP_PRINT_UNIMPL (1UL << 11) /* Show for unimplemented feats */ 97#define HFI1_CAP_PRINT_UNIMPL (1UL << 11) /* Show for unimplemented feats */
98#define HFI1_CAP_ALLOW_PERM_JKEY (1UL << 12) /* Allow use of permissive JKEY */ 98#define HFI1_CAP_ALLOW_PERM_JKEY (1UL << 12) /* Allow use of permissive JKEY */
99#define HFI1_CAP_NO_INTEGRITY (1UL << 13) /* Enable ctxt integrity checks */ 99#define HFI1_CAP_NO_INTEGRITY (1UL << 13) /* Enable ctxt integrity checks */
@@ -134,6 +134,7 @@
134#define HFI1_CMD_ACK_EVENT 10 /* ack & clear user status bits */ 134#define HFI1_CMD_ACK_EVENT 10 /* ack & clear user status bits */
135#define HFI1_CMD_SET_PKEY 11 /* set context's pkey */ 135#define HFI1_CMD_SET_PKEY 11 /* set context's pkey */
136#define HFI1_CMD_CTXT_RESET 12 /* reset context's HW send context */ 136#define HFI1_CMD_CTXT_RESET 12 /* reset context's HW send context */
137#define HFI1_CMD_TID_INVAL_READ 13 /* read TID cache invalidations */
137/* separate EPROM commands from normal PSM commands */ 138/* separate EPROM commands from normal PSM commands */
138#define HFI1_CMD_EP_INFO 64 /* read EPROM device ID */ 139#define HFI1_CMD_EP_INFO 64 /* read EPROM device ID */
139#define HFI1_CMD_EP_ERASE_CHIP 65 /* erase whole EPROM */ 140#define HFI1_CMD_EP_ERASE_CHIP 65 /* erase whole EPROM */
@@ -147,13 +148,15 @@
147#define _HFI1_EVENT_LID_CHANGE_BIT 2 148#define _HFI1_EVENT_LID_CHANGE_BIT 2
148#define _HFI1_EVENT_LMC_CHANGE_BIT 3 149#define _HFI1_EVENT_LMC_CHANGE_BIT 3
149#define _HFI1_EVENT_SL2VL_CHANGE_BIT 4 150#define _HFI1_EVENT_SL2VL_CHANGE_BIT 4
150#define _HFI1_MAX_EVENT_BIT _HFI1_EVENT_SL2VL_CHANGE_BIT 151#define _HFI1_EVENT_TID_MMU_NOTIFY_BIT 5
152#define _HFI1_MAX_EVENT_BIT _HFI1_EVENT_TID_MMU_NOTIFY_BIT
151 153
152#define HFI1_EVENT_FROZEN (1UL << _HFI1_EVENT_FROZEN_BIT) 154#define HFI1_EVENT_FROZEN (1UL << _HFI1_EVENT_FROZEN_BIT)
153#define HFI1_EVENT_LINKDOWN (1UL << _HFI1_EVENT_LINKDOWN_BIT) 155#define HFI1_EVENT_LINKDOWN (1UL << _HFI1_EVENT_LINKDOWN_BIT)
154#define HFI1_EVENT_LID_CHANGE (1UL << _HFI1_EVENT_LID_CHANGE_BIT) 156#define HFI1_EVENT_LID_CHANGE (1UL << _HFI1_EVENT_LID_CHANGE_BIT)
155#define HFI1_EVENT_LMC_CHANGE (1UL << _HFI1_EVENT_LMC_CHANGE_BIT) 157#define HFI1_EVENT_LMC_CHANGE (1UL << _HFI1_EVENT_LMC_CHANGE_BIT)
156#define HFI1_EVENT_SL2VL_CHANGE (1UL << _HFI1_EVENT_SL2VL_CHANGE_BIT) 158#define HFI1_EVENT_SL2VL_CHANGE (1UL << _HFI1_EVENT_SL2VL_CHANGE_BIT)
159#define HFI1_EVENT_TID_MMU_NOTIFY (1UL << _HFI1_EVENT_TID_MMU_NOTIFY_BIT)
157 160
158/* 161/*
159 * These are the status bits readable (in ASCII form, 64bit value) 162 * These are the status bits readable (in ASCII form, 64bit value)
@@ -238,11 +241,6 @@ struct hfi1_tid_info {
238 __u32 tidcnt; 241 __u32 tidcnt;
239 /* length of transfer buffer programmed by this request */ 242 /* length of transfer buffer programmed by this request */
240 __u32 length; 243 __u32 length;
241 /*
242 * pointer to bitmap of TIDs used for this call;
243 * checked for being large enough at open
244 */
245 __u64 tidmap;
246}; 244};
247 245
248struct hfi1_cmd { 246struct hfi1_cmd {
diff --git a/include/uapi/rdma/rdma_netlink.h b/include/uapi/rdma/rdma_netlink.h
index f7d7b6fec935..6e373d151cad 100644
--- a/include/uapi/rdma/rdma_netlink.h
+++ b/include/uapi/rdma/rdma_netlink.h
@@ -8,6 +8,7 @@ enum {
8 RDMA_NL_IWCM, 8 RDMA_NL_IWCM,
9 RDMA_NL_RSVD, 9 RDMA_NL_RSVD,
10 RDMA_NL_LS, /* RDMA Local Services */ 10 RDMA_NL_LS, /* RDMA Local Services */
11 RDMA_NL_I40IW,
11 RDMA_NL_NUM_CLIENTS 12 RDMA_NL_NUM_CLIENTS
12}; 13};
13 14
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index d2d9e5ebf58e..167883e09317 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1389,6 +1389,8 @@ static const struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
1389 [IFLA_VF_RSS_QUERY_EN] = { .len = sizeof(struct ifla_vf_rss_query_en) }, 1389 [IFLA_VF_RSS_QUERY_EN] = { .len = sizeof(struct ifla_vf_rss_query_en) },
1390 [IFLA_VF_STATS] = { .type = NLA_NESTED }, 1390 [IFLA_VF_STATS] = { .type = NLA_NESTED },
1391 [IFLA_VF_TRUST] = { .len = sizeof(struct ifla_vf_trust) }, 1391 [IFLA_VF_TRUST] = { .len = sizeof(struct ifla_vf_trust) },
1392 [IFLA_VF_IB_NODE_GUID] = { .len = sizeof(struct ifla_vf_guid) },
1393 [IFLA_VF_IB_PORT_GUID] = { .len = sizeof(struct ifla_vf_guid) },
1392}; 1394};
1393 1395
1394static const struct nla_policy ifla_port_policy[IFLA_PORT_MAX+1] = { 1396static const struct nla_policy ifla_port_policy[IFLA_PORT_MAX+1] = {
@@ -1593,6 +1595,22 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
1593 return 0; 1595 return 0;
1594} 1596}
1595 1597
1598static int handle_infiniband_guid(struct net_device *dev, struct ifla_vf_guid *ivt,
1599 int guid_type)
1600{
1601 const struct net_device_ops *ops = dev->netdev_ops;
1602
1603 return ops->ndo_set_vf_guid(dev, ivt->vf, ivt->guid, guid_type);
1604}
1605
1606static int handle_vf_guid(struct net_device *dev, struct ifla_vf_guid *ivt, int guid_type)
1607{
1608 if (dev->type != ARPHRD_INFINIBAND)
1609 return -EOPNOTSUPP;
1610
1611 return handle_infiniband_guid(dev, ivt, guid_type);
1612}
1613
1596static int do_setvfinfo(struct net_device *dev, struct nlattr **tb) 1614static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
1597{ 1615{
1598 const struct net_device_ops *ops = dev->netdev_ops; 1616 const struct net_device_ops *ops = dev->netdev_ops;
@@ -1695,6 +1713,24 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
1695 return err; 1713 return err;
1696 } 1714 }
1697 1715
1716 if (tb[IFLA_VF_IB_NODE_GUID]) {
1717 struct ifla_vf_guid *ivt = nla_data(tb[IFLA_VF_IB_NODE_GUID]);
1718
1719 if (!ops->ndo_set_vf_guid)
1720 return -EOPNOTSUPP;
1721
1722 return handle_vf_guid(dev, ivt, IFLA_VF_IB_NODE_GUID);
1723 }
1724
1725 if (tb[IFLA_VF_IB_PORT_GUID]) {
1726 struct ifla_vf_guid *ivt = nla_data(tb[IFLA_VF_IB_PORT_GUID]);
1727
1728 if (!ops->ndo_set_vf_guid)
1729 return -EOPNOTSUPP;
1730
1731 return handle_vf_guid(dev, ivt, IFLA_VF_IB_PORT_GUID);
1732 }
1733
1698 return err; 1734 return err;
1699} 1735}
1700 1736