Skip to contentSkip to conversation

Introduce AMD Pensando RDMA driver

PATCH Superseded Abhijit Gangurde 4 participants 26 messages May 8, 2025 – May 28, 2025

Subsystems (6)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Abhijit Gangurde

author maintainer
#0 lore raw

v2 cover Introduce AMD Pensando RDMA driver

This patchset introduces an RDMA driver for the AMD Pensando adapter. An AMD Pensando Ethernet device with RDMA capabilities extends its functionality through an auxiliary device.

The first 6 patches of the series modify the ionic Ethernet driver to support the RDMA driver. The ionic RDMA driver implementation is split into the remaining 8 patches.

v1->v2
- Removed netdev references from ionic RDMA driver
- Moved to ionic_lif* instead of void* to convey information between aux devices and drivers.

Abhijit Gangurde (14):
net: ionic: Create an auxiliary device for rdma driver
net: ionic: Update LIF identity with additional RDMA capabilities
net: ionic: Export the APIs from net driver to support device commands
net: ionic: Provide RDMA reset support for the RDMA driver
net: ionic: Provide interrupt allocation support for the RDMA driver
net: ionic: Provide doorbell and CMB region information
RDMA: Add IONIC to rdma_driver_id definition
RDMA/ionic: Register auxiliary module for ionic ethernet adapter RDMA/ionic: Create device queues to support admin operations RDMA/ionic: Register device ops for control path RDMA/ionic: Register device ops for datapath
RDMA/ionic: Register device ops for miscellaneous functionality RDMA/ionic: Implement device stats ops
RDMA/ionic: Add Makefile/Kconfig to kernel build environment

 .../ethernet/pensando/ionic_rdma.rst          |   43 +
 MAINTAINERS                                   |    9 +
 drivers/infiniband/Kconfig                    |    1 +
 drivers/infiniband/hw/Makefile                |    1 +
 drivers/infiniband/hw/ionic/Kconfig           |   17 +
 drivers/infiniband/hw/ionic/Makefile          |    9 +
 drivers/infiniband/hw/ionic/ionic_admin.c     | 1241 +++++++
 .../infiniband/hw/ionic/ionic_controlpath.c   | 2929 +++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_datapath.c  | 1422 ++++++++
 drivers/infiniband/hw/ionic/ionic_fw.h        | 1031 ++++++
 drivers/infiniband/hw/ionic/ionic_hw_stats.c  |  484 +++
 drivers/infiniband/hw/ionic/ionic_ibdev.c     |  489 +++
 drivers/infiniband/hw/ionic/ionic_ibdev.h     |  506 +++
 drivers/infiniband/hw/ionic/ionic_lif_cfg.c   |  131 +
 drivers/infiniband/hw/ionic/ionic_lif_cfg.h   |   67 +
 drivers/infiniband/hw/ionic/ionic_pgtbl.c     |  143 +
 drivers/infiniband/hw/ionic/ionic_queue.c     |   52 +
 drivers/infiniband/hw/ionic/ionic_queue.h     |  234 ++
 drivers/infiniband/hw/ionic/ionic_res.c       |   42 +
 drivers/infiniband/hw/ionic/ionic_res.h       |  182 +
 drivers/net/ethernet/pensando/Kconfig         |    1 +
 drivers/net/ethernet/pensando/ionic/Makefile  |    2 +-
 drivers/net/ethernet/pensando/ionic/ionic.h   |    7 -
 .../net/ethernet/pensando/ionic/ionic_api.h   |  131 +
 .../net/ethernet/pensando/ionic/ionic_aux.c   |  117 +
 .../net/ethernet/pensando/ionic/ionic_aux.h   |   10 +
 .../ethernet/pensando/ionic/ionic_bus_pci.c   |    7 +
 .../net/ethernet/pensando/ionic/ionic_dev.c   |  270 +-
 .../net/ethernet/pensando/ionic/ionic_dev.h   |   28 +-
 .../net/ethernet/pensando/ionic/ionic_if.h    |  118 +-
 .../net/ethernet/pensando/ionic/ionic_lif.c   |   47 +-
 .../net/ethernet/pensando/ionic/ionic_lif.h   |    3 +
 .../net/ethernet/pensando/ionic/ionic_main.c  |    4 +-
 include/uapi/rdma/ib_user_ioctl_verbs.h       |    1 +
 include/uapi/rdma/ionic-abi.h                 |  115 +
 35 files changed, 9830 insertions(+), 64 deletions(-)
 create mode 100644 Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst
 create mode 100644 drivers/infiniband/hw/ionic/Kconfig
 create mode 100644 drivers/infiniband/hw/ionic/Makefile
 create mode 100644 drivers/infiniband/hw/ionic/ionic_admin.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_controlpath.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_datapath.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_fw.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_hw_stats.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_pgtbl.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_queue.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_queue.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_res.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_res.h
 create mode 100644 drivers/net/ethernet/pensando/ionic/ionic_api.h
 create mode 100644 drivers/net/ethernet/pensando/ionic/ionic_aux.c
 create mode 100644 drivers/net/ethernet/pensando/ionic/ionic_aux.h
 create mode 100644 include/uapi/rdma/ionic-abi.h
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 1/14 net: ionic: Create an auxiliary device for rdma driver

To support RDMA capable ethernet device, create an auxiliary device in the ionic Ethernet driver. The RDMA device is modeled as an auxiliary device to the Ethernet device.

---
 drivers/net/ethernet/pensando/Kconfig         |  1 +
 drivers/net/ethernet/pensando/ionic/Makefile  |  2 +-
 .../net/ethernet/pensando/ionic/ionic_api.h   | 21 ++++
 .../net/ethernet/pensando/ionic/ionic_aux.c   | 95 +++++++++++++++++++
 .../net/ethernet/pensando/ionic/ionic_aux.h   | 10 ++
 .../ethernet/pensando/ionic/ionic_bus_pci.c   |  5 +
 .../net/ethernet/pensando/ionic/ionic_lif.c   |  7 ++
 .../net/ethernet/pensando/ionic/ionic_lif.h   |  3 +
 8 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/pensando/ionic/ionic_api.h
 create mode 100644 drivers/net/ethernet/pensando/ionic/ionic_aux.c
 create mode 100644 drivers/net/ethernet/pensando/ionic/ionic_aux.h
drivers/net/ethernet/pensando/Kconfig +1 -0
index 01fe76786f77..c99758adf3ad 100644
@@ -24,6 +24,7 @@ config IONIC
 	select NET_DEVLINK
 	select DIMLIB
 	select PAGE_POOL
+	select AUXILIARY_BUS
 	help
 	  This enables the support for the Pensando family of Ethernet
 	  adapters.  More specific information on this driver can be
drivers/net/ethernet/pensando/ionic/Makefile +1 -1
index 4e7642a2d25f..a598972fef41 100644
@@ -5,5 +5,5 @@ obj-$(CONFIG_IONIC) := ionic.o
 
 ionic-y := ionic_main.o ionic_bus_pci.o ionic_devlink.o ionic_dev.o \
 	   ionic_debugfs.o ionic_lif.o ionic_rx_filter.o ionic_ethtool.o \
-	   ionic_txrx.o ionic_stats.o ionic_fw.o
+	   ionic_txrx.o ionic_stats.o ionic_fw.o ionic_aux.o
 ionic-$(CONFIG_PTP_1588_CLOCK) += ionic_phc.o
drivers/net/ethernet/pensando/ionic/ionic_api.h new file +21 -0
new file mode 100644
index 000000000000..f9fcd1b67b35
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#ifndef _IONIC_API_H_
+#define _IONIC_API_H_
+
+#include <linux/auxiliary_bus.h>
+
+/**
+ * struct ionic_aux_dev - Auxiliary device information
+ * @lif:        Logical interface
+ * @idx:        Index identifier
+ * @adev:       Auxiliary device
+ */
+struct ionic_aux_dev {
+	struct ionic_lif *lif;
+	int idx;
+	struct auxiliary_device adev;
+};
+
+#endif /* _IONIC_API_H_ */
drivers/net/ethernet/pensando/ionic/ionic_aux.c new file +95 -0

95 lines not on this page · raw message

drivers/net/ethernet/pensando/ionic/ionic_aux.h new file +10 -0
new file mode 100644
index 000000000000..f5528a9f187d
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#ifndef _IONIC_AUX_H_
+#define _IONIC_AUX_H_
+
+int ionic_auxbus_register(struct ionic_lif *lif);
+void ionic_auxbus_unregister(struct ionic_lif *lif);
+
+#endif /* _IONIC_AUX_H_ */
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +5 -0
index 4c377bdc62c8..bb75044dfb82 100644
@@ -9,6 +9,7 @@
 #include "ionic.h"
 #include "ionic_bus.h"
 #include "ionic_lif.h"
+#include "ionic_aux.h"
 #include "ionic_debugfs.h"
 
 /* Supported devices */
@@ -375,6 +376,8 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto err_out_deregister_devlink;
 	}
 
+	ionic_auxbus_register(ionic->lif);
+
 	mod_timer(&ionic->watchdog_timer,
 		  round_jiffies(jiffies + ionic->watchdog_period));
 	ionic_queue_doorbell_check(ionic, IONIC_NAPI_DEADLINE);
@@ -415,6 +418,7 @@ static void ionic_remove(struct pci_dev *pdev)
 
 		if (ionic->lif->doorbell_wa)
 			cancel_delayed_work_sync(&ionic->doorbell_check_dwork);
+		ionic_auxbus_unregister(ionic->lif);
 		ionic_lif_unregister(ionic->lif);
 		ionic_devlink_unregister(ionic);
 		ionic_lif_deinit(ionic->lif);
@@ -444,6 +448,7 @@ static void ionic_reset_prepare(struct pci_dev *pdev)
 	timer_delete_sync(&ionic->watchdog_timer);
 	cancel_work_sync(&lif->deferred.work);
 
+	ionic_auxbus_unregister(ionic->lif);
 	mutex_lock(&lif->queue_lock);
 	ionic_stop_queues_reconfig(lif);
 	ionic_txrx_free(lif);
drivers/net/ethernet/pensando/ionic/ionic_lif.c +7 -0
index 7707a9e53c43..146659f6862a 100644
@@ -19,6 +19,7 @@
 #include "ionic_bus.h"
 #include "ionic_dev.h"
 #include "ionic_lif.h"
+#include "ionic_aux.h"
 #include "ionic_txrx.h"
 #include "ionic_ethtool.h"
 #include "ionic_debugfs.h"
@@ -3293,6 +3294,7 @@ int ionic_lif_alloc(struct ionic *ionic)
 
 	mutex_init(&lif->queue_lock);
 	mutex_init(&lif->config_lock);
+	mutex_init(&lif->adev_lock);
 
 	spin_lock_init(&lif->adminq_lock);
 
@@ -3349,6 +3351,7 @@ int ionic_lif_alloc(struct ionic *ionic)
 	lif->info = NULL;
 	lif->info_pa = 0;
 err_out_free_mutex:
+	mutex_destroy(&lif->adev_lock);
 	mutex_destroy(&lif->config_lock);
 	mutex_destroy(&lif->queue_lock);
 err_out_free_netdev:
@@ -3384,6 +3387,7 @@ static void ionic_lif_handle_fw_down(struct ionic_lif *lif)
 
 	netif_device_detach(lif->netdev);
 
+	ionic_auxbus_unregister(ionic->lif);
 	mutex_lock(&lif->queue_lock);
 	if (test_bit(IONIC_LIF_F_UP, lif->state)) {
 		dev_info(ionic->dev, "Surprise FW stop, stopping queues\n");
@@ -3446,6 +3450,8 @@ int ionic_restart_lif(struct ionic_lif *lif)
 	netif_device_attach(lif->netdev);
 	ionic_queue_doorbell_check(ionic, IONIC_NAPI_DEADLINE);
 
+	ionic_auxbus_register(ionic->lif);
+
 	return 0;
 
 err_txrx_free:
@@ -3532,6 +3538,7 @@ void ionic_lif_free(struct ionic_lif *lif)
 
 	mutex_destroy(&lif->config_lock);
 	mutex_destroy(&lif->queue_lock);
+	mutex_destroy(&lif->adev_lock);
 
 	/* free netdev & lif */
 	ionic_debugfs_del_lif(lif);
drivers/net/ethernet/pensando/ionic/ionic_lif.h +3 -0
index e01756fb7fdd..43bdd0fb8733 100644
@@ -10,6 +10,7 @@
 #include <linux/dim.h>
 #include <linux/pci.h>
 #include "ionic_rx_filter.h"
+#include "ionic_api.h"
 
 #define IONIC_ADMINQ_LENGTH	16	/* must be a power of two */
 #define IONIC_NOTIFYQ_LENGTH	64	/* must be a power of two */
@@ -225,6 +226,8 @@ struct ionic_lif {
 	dma_addr_t info_pa;
 	u32 info_sz;
 	struct ionic_qtype_info qtype_info[IONIC_QTYPE_MAX];
+	struct ionic_aux_dev *ionic_adev;
+	struct mutex adev_lock;	/* lock for aux_dev actions */
 
 	u8 rss_hash_key[IONIC_RSS_HASH_KEY_SIZE];
 	u8 *rss_ind_tbl;
Signature · 1 line
2.34.1
reviewer
#2 lore raw

Re: [PATCH v2 01/14] net: ionic: Create an auxiliary device for rdma driver

Quoted 6 lines · Abhijit Gangurde

To support RDMA capable ethernet device, create an auxiliary device in the ionic Ethernet driver. The RDMA device is modeled as an auxiliary device to the Ethernet device.

...

Quoted 21 lines
drivers/net/ethernet/pensando/ionic/ionic_aux.c new file +15 -0
new file mode 100644
index 000000000000..ba29c456de00
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/kernel.h>
+#include "ionic.h"
+#include "ionic_lif.h"
+#include "ionic_aux.h"
+
+static DEFINE_IDA(aux_ida);
+
+static void ionic_auxbus_release(struct device *dev)
+{
+	struct ionic_aux_dev *ionic_adev;
+
+	ionic_adev = container_of(dev, struct ionic_aux_dev, adev.dev);

drivers/net/ethernet/pensando/ionic/ionic_aux.c line 25

Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_aux.c new file +10 -0
+	kfree(ionic_adev);
+}
+
+int ionic_auxbus_register(struct ionic_lif *lif)
+{
+	struct ionic_aux_dev *ionic_adev;
+	struct auxiliary_device *aux_dev;
+	int err, id;
+
+	if (!(lif->ionic->ident.lif.capabilities & IONIC_LIF_CAP_RDMA))

Hi Abhijit,

There is an endian mismatch here: .capabilities is a __le64, whereas IONIC_LIF_CAP_RDMA is host byte order.

Flagged by Sparse

...

author maintainer
#3 lore raw

Re: [PATCH v2 01/14] net: ionic: Create an auxiliary device for rdma driver

Quoted 42 lines · Simon Horman
Quoted 6 lines · Abhijit Gangurde

To support RDMA capable ethernet device, create an auxiliary device in the ionic Ethernet driver. The RDMA device is modeled as an auxiliary device to the Ethernet device.

...

Quoted 21 lines
drivers/net/ethernet/pensando/ionic/ionic_aux.c new file +15 -0
new file mode 100644
index 000000000000..ba29c456de00
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/kernel.h>
+#include "ionic.h"
+#include "ionic_lif.h"
+#include "ionic_aux.h"
+
+static DEFINE_IDA(aux_ida);
+
+static void ionic_auxbus_release(struct device *dev)
+{
+	struct ionic_aux_dev *ionic_adev;
+
+	ionic_adev = container_of(dev, struct ionic_aux_dev, adev.dev);

drivers/net/ethernet/pensando/ionic/ionic_aux.c line 25

Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_aux.c new file +10 -0
+	kfree(ionic_adev);
+}
+
+int ionic_auxbus_register(struct ionic_lif *lif)
+{
+	struct ionic_aux_dev *ionic_adev;
+	struct auxiliary_device *aux_dev;
+	int err, id;
+
+	if (!(lif->ionic->ident.lif.capabilities & IONIC_LIF_CAP_RDMA))

Hi Abhijit,

Quoted 6 lines

There is an endian mismatch here: .capabilities is a __le64, whereas IONIC_LIF_CAP_RDMA is host byte order.

Flagged by Sparse

...

Thanks Simon. I will fix this in the next spin and make sure to run sparse on it.

Abhijit.

author maintainer
#4 lore raw

PATCH v2 2/14 net: ionic: Update LIF identity with additional RDMA capabilities

In reply to Abhijit Gangurde

Firmware sends the RDMA capability in a response for LIF_IDENTIFY device command. Update the LIF indentify with additional RDMA capabilities used by driver and firmware.

---
 .../net/ethernet/pensando/ionic/ionic_if.h    | 29 +++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_if.h +24 -5
index 830c8adbfbee..02cda3536dcb 100644
@@ -494,6 +494,16 @@ union ionic_lif_config {
 	__le32 words[64];
 };
 
+/**
+ * enum ionic_lif_rdma_cap_stats - LIF stat type
+ * @IONIC_LIF_RDMA_STAT_GLOBAL:     Global stats
+ * @IONIC_LIF_RDMA_STAT_QP:         Queue pair stats
+ */
+enum ionic_lif_rdma_cap_stats {
+	IONIC_LIF_RDMA_STAT_GLOBAL = BIT(0),
+	IONIC_LIF_RDMA_STAT_QP = BIT(1),
+};
+
 /**
  * struct ionic_lif_identity - LIF identity information (type-specific)
  *
@@ -513,10 +523,10 @@ union ionic_lif_config {
  *	@eth.config:             LIF config struct with features, mtu, mac, q counts
  *
  * @rdma:                RDMA identify structure
- *	@rdma.version:         RDMA version of opcodes and queue descriptors
+ *	@rdma.version:         RDMA capability version
  *	@rdma.qp_opcodes:      Number of RDMA queue pair opcodes supported
  *	@rdma.admin_opcodes:   Number of RDMA admin opcodes supported
- *	@rdma.rsvd:            reserved byte(s)
+ *	@rdma.minor_version:   RDMA capability minor version
  *	@rdma.npts_per_lif:    Page table size per LIF
  *	@rdma.nmrs_per_lif:    Number of memory regions per LIF
  *	@rdma.nahs_per_lif:    Number of address handles per LIF
@@ -526,12 +536,17 @@ union ionic_lif_config {
  *	@rdma.rrq_stride:      Remote RQ work request stride
  *	@rdma.rsq_stride:      Remote SQ work request stride
  *	@rdma.dcqcn_profiles:  Number of DCQCN profiles
- *	@rdma.rsvd_dimensions: reserved byte(s)
+ *	@rdma.udma_shift:      Log2 number of queues per queue group
+ *	@rdma.rsvd_dimensions: Reserved byte
+ *	@rdma.page_size_cap:   Supported page sizes
  *	@rdma.aq_qtype:        RDMA Admin Qtype
  *	@rdma.sq_qtype:        RDMA Send Qtype
  *	@rdma.rq_qtype:        RDMA Receive Qtype
  *	@rdma.cq_qtype:        RDMA Completion Qtype
  *	@rdma.eq_qtype:        RDMA Event Qtype
+ *	@rdma.stats_type:      Supported statistics type
+ *	                       (enum ionic_lif_rdma_cap_stats)
+ *	@rdma.rsvd1:           Reserved byte(s)
  * @words:               word access to struct contents
  */
 union ionic_lif_identity {
@@ -557,7 +572,7 @@ union ionic_lif_identity {
 			u8 version;
 			u8 qp_opcodes;
 			u8 admin_opcodes;
-			u8 rsvd;
+			u8 minor_version;
 			__le32 npts_per_lif;
 			__le32 nmrs_per_lif;
 			__le32 nahs_per_lif;
@@ -567,12 +582,16 @@ union ionic_lif_identity {
 			u8 rrq_stride;
 			u8 rsq_stride;
 			u8 dcqcn_profiles;
-			u8 rsvd_dimensions[10];
+			u8 udma_shift;
+			u8 rsvd_dimensions;
+			__le64 page_size_cap;
 			struct ionic_lif_logical_qtype aq_qtype;
 			struct ionic_lif_logical_qtype sq_qtype;
 			struct ionic_lif_logical_qtype rq_qtype;
 			struct ionic_lif_logical_qtype cq_qtype;
 			struct ionic_lif_logical_qtype eq_qtype;
+			__le16 stats_type;
+			u8 rsvd1[162];
 		} __packed rdma;
 	} __packed;
 	__le32 words[478];
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH v2 3/14 net: ionic: Export the APIs from net driver to support device commands

In reply to Abhijit Gangurde

RDMA driver needs to establish admin queues to support admin operations. Export the APIs to send device commands for the RDMA driver.

---
 drivers/net/ethernet/pensando/ionic/ionic.h   |  7 ----
 .../net/ethernet/pensando/ionic/ionic_api.h   | 36 +++++++++++++++++++
 .../net/ethernet/pensando/ionic/ionic_dev.h   |  1 +
 .../net/ethernet/pensando/ionic/ionic_main.c  |  4 ++-
 4 files changed, 40 insertions(+), 8 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic.h +0 -7
index 04f00ea94230..85198e6a806e 100644
@@ -65,16 +65,9 @@ struct ionic {
 	int watchdog_period;
 };
 
-struct ionic_admin_ctx {
-	struct completion work;
-	union ionic_adminq_cmd cmd;
-	union ionic_adminq_comp comp;
-};
-
 int ionic_adminq_post(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
 int ionic_adminq_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx,
 		      const int err, const bool do_msg);
-int ionic_adminq_post_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
 int ionic_adminq_post_wait_nomsg(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
 void ionic_adminq_netdev_err_print(struct ionic_lif *lif, u8 opcode,
 				   u8 status, int err);
drivers/net/ethernet/pensando/ionic/ionic_api.h +36 -0
index f9fcd1b67b35..d75902ca34af 100644
@@ -5,6 +5,8 @@
 #define _IONIC_API_H_
 
 #include <linux/auxiliary_bus.h>
+#include "ionic_if.h"
+#include "ionic_regs.h"
 
 /**
  * struct ionic_aux_dev - Auxiliary device information
@@ -18,4 +20,38 @@ struct ionic_aux_dev {
 	struct auxiliary_device adev;
 };
 
+/**
+ * struct ionic_admin_ctx - Admin command context
+ * @work:       Work completion wait queue element
+ * @cmd:        Admin command (64B) to be copied to the queue
+ * @comp:       Admin completion (16B) copied from the queue
+ */
+struct ionic_admin_ctx {
+	struct completion work;
+	union ionic_adminq_cmd cmd;
+	union ionic_adminq_comp comp;
+};
+
+/**
+ * ionic_adminq_post_wait - Post an admin command and wait for response
+ * @lif:        Logical interface
+ * @ctx:        API admin command context
+ *
+ * Post the command to an admin queue in the ethernet driver.  If this command
+ * succeeds, then the command has been posted, but that does not indicate a
+ * completion.  If this command returns success, then the completion callback
+ * will eventually be called.
+ *
+ * Return: zero or negative error status
+ */
+int ionic_adminq_post_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
+
+/**
+ * ionic_error_to_errno - Transform ionic_if errors to os errno
+ * @code:       Ionic error number
+ *
+ * Return:      Negative OS error number or zero
+ */
+int ionic_error_to_errno(enum ionic_status_code code);
+
 #endif /* _IONIC_API_H_ */
drivers/net/ethernet/pensando/ionic/ionic_dev.h +1 -0
index c8c710cfe70c..bc26eb8f5779 100644
@@ -12,6 +12,7 @@
 
 #include "ionic_if.h"
 #include "ionic_regs.h"
+#include "ionic_api.h"
 
 #define IONIC_MAX_TX_DESC		8192
 #define IONIC_MAX_RX_DESC		16384
drivers/net/ethernet/pensando/ionic/ionic_main.c +3 -1
index daf1e82cb76b..60fc232338b9 100644
@@ -72,7 +72,7 @@ static const char *ionic_error_to_str(enum ionic_status_code code)
 	}
 }
 
-static int ionic_error_to_errno(enum ionic_status_code code)
+int ionic_error_to_errno(enum ionic_status_code code)
 {
 	switch (code) {
 	case IONIC_RC_SUCCESS:
@@ -114,6 +114,7 @@ static int ionic_error_to_errno(enum ionic_status_code code)
 		return -EIO;
 	}
 }
+EXPORT_SYMBOL_NS(ionic_error_to_errno, "NET_IONIC");
 
 static const char *ionic_opcode_to_str(enum ionic_cmd_opcode opcode)
 {
@@ -480,6 +481,7 @@ int ionic_adminq_post_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx)
 {
 	return __ionic_adminq_post_wait(lif, ctx, true);
 }
+EXPORT_SYMBOL_NS(ionic_adminq_post_wait, "NET_IONIC");
 
 int ionic_adminq_post_wait_nomsg(struct ionic_lif *lif, struct ionic_admin_ctx *ctx)
 {
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH v2 4/14 net: ionic: Provide RDMA reset support for the RDMA driver

In reply to Abhijit Gangurde

The Ethernet driver holds the privilege to execute the device commands. Export the function to execute RDMA reset command for use by RDMA driver.

---
 .../net/ethernet/pensando/ionic/ionic_api.h   |  9 ++++++++
 .../net/ethernet/pensando/ionic/ionic_aux.c   | 22 +++++++++++++++++++
 2 files changed, 31 insertions(+)
drivers/net/ethernet/pensando/ionic/ionic_api.h +9 -0
index d75902ca34af..e0b766d1769f 100644
@@ -54,4 +54,13 @@ int ionic_adminq_post_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
  */
 int ionic_error_to_errno(enum ionic_status_code code);
 
+/**
+ * ionic_request_rdma_reset - request reset or disable the device or lif
+ * @lif:        Logical interface
+ *
+ * The reset is triggered asynchronously. It will wait until reset request
+ * completes or times out.
+ */
+void ionic_request_rdma_reset(struct ionic_lif *lif);
+
 #endif /* _IONIC_API_H_ */
drivers/net/ethernet/pensando/ionic/ionic_aux.c +22 -0
index ba29c456de00..bbad848d2dce 100644
@@ -93,3 +93,25 @@ void ionic_auxbus_unregister(struct ionic_lif *lif)
 out:
 	mutex_unlock(&lif->adev_lock);
 }
+
+void ionic_request_rdma_reset(struct ionic_lif *lif)
+{
+	struct ionic *ionic = lif->ionic;
+	int err;
+
+	union ionic_dev_cmd cmd = {
+		.cmd.opcode = IONIC_CMD_RDMA_RESET_LIF,
+		.cmd.lif_index = cpu_to_le16(lif->index),
+	};
+
+	mutex_lock(&ionic->dev_cmd_lock);
+
+	ionic_dev_cmd_go(&ionic->idev, &cmd);
+	err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
+
+	mutex_unlock(&ionic->dev_cmd_lock);
+
+	if (err)
+		pr_warn("%s request_reset: error %d\n", __func__, err);
+}
+EXPORT_SYMBOL_NS(ionic_request_rdma_reset, "NET_IONIC");
Signature · 1 line
2.34.1
author maintainer
#7 lore raw

PATCH v2 5/14 net: ionic: Provide interrupt allocation support for the RDMA driver

In reply to Abhijit Gangurde

RDMA driver needs an interrupt for an event queue. Export function from net driver to allocate an interrupt.

---
 .../net/ethernet/pensando/ionic/ionic_api.h   | 43 +++++++++++++++++++
 .../net/ethernet/pensando/ionic/ionic_dev.h   | 13 ------
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 38 ++++++++--------
 3 files changed, 62 insertions(+), 32 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_api.h +43 -0
index e0b766d1769f..5fd23aa8c5a1 100644
@@ -32,6 +32,29 @@ struct ionic_admin_ctx {
 	union ionic_adminq_comp comp;
 };
 
+#define IONIC_INTR_INDEX_NOT_ASSIGNED	-1
+#define IONIC_INTR_NAME_MAX_SZ		32
+
+/**
+ * struct ionic_intr_info - Interrupt information
+ * @name:          Name identifier
+ * @rearm_count:   Interrupt rearm count
+ * @index:         Interrupt index position
+ * @vector:        Interrupt number
+ * @dim_coal_hw:   Interrupt coalesce value in hardware units
+ * @affinity_mask: CPU affinity mask
+ * @aff_notify:    context for notification of IRQ affinity changes
+ */
+struct ionic_intr_info {
+	char name[IONIC_INTR_NAME_MAX_SZ];
+	u64 rearm_count;
+	unsigned int index;
+	unsigned int vector;
+	u32 dim_coal_hw;
+	cpumask_var_t *affinity_mask;
+	struct irq_affinity_notify aff_notify;
+};
+
 /**
  * ionic_adminq_post_wait - Post an admin command and wait for response
  * @lif:        Logical interface
@@ -63,4 +86,24 @@ int ionic_error_to_errno(enum ionic_status_code code);
  */
 void ionic_request_rdma_reset(struct ionic_lif *lif);
 
+/**
+ * ionic_intr_alloc - Reserve a device interrupt
+ * @lif:        Logical interface
+ * @intr:       Reserved ionic interrupt structure
+ *
+ * Reserve an interrupt index and get irq number for that index.
+ *
+ * Return: zero or negative error status
+ */
+int ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr);
+
+/**
+ * ionic_intr_free - Release a device interrupt index
+ * @lif:        Logical interface
+ * @intr:       Interrupt index
+ *
+ * Mark the interrupt index unused so that it can be reserved again.
+ */
+void ionic_intr_free(struct ionic_lif *lif, int intr);
+
 #endif /* _IONIC_API_H_ */
drivers/net/ethernet/pensando/ionic/ionic_dev.h +0 -13
index bc26eb8f5779..68cf4da3c6b3 100644
@@ -274,19 +274,6 @@ struct ionic_queue {
 	char name[IONIC_QUEUE_NAME_MAX_SZ];
 } ____cacheline_aligned_in_smp;
 
-#define IONIC_INTR_INDEX_NOT_ASSIGNED	-1
-#define IONIC_INTR_NAME_MAX_SZ		32
-
-struct ionic_intr_info {
-	char name[IONIC_INTR_NAME_MAX_SZ];
-	u64 rearm_count;
-	unsigned int index;
-	unsigned int vector;
-	u32 dim_coal_hw;
-	cpumask_var_t *affinity_mask;
-	struct irq_affinity_notify aff_notify;
-};
-
 struct ionic_cq {
 	struct ionic_lif *lif;
 	struct ionic_queue *bound_q;
drivers/net/ethernet/pensando/ionic/ionic_lif.c +19 -19
index 146659f6862a..f89b458bd20a 100644
@@ -244,29 +244,36 @@ static int ionic_request_irq(struct ionic_lif *lif, struct ionic_qcq *qcq)
 				0, intr->name, &qcq->napi);
 }
 
-static int ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr)
+int ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr)
 {
 	struct ionic *ionic = lif->ionic;
-	int index;
+	int index, err;
 
 	index = find_first_zero_bit(ionic->intrs, ionic->nintrs);
-	if (index == ionic->nintrs) {
-		netdev_warn(lif->netdev, "%s: no intr, index=%d nintrs=%d\n",
-			    __func__, index, ionic->nintrs);
+	if (index == ionic->nintrs)
 		return -ENOSPC;
-	}
 
 	set_bit(index, ionic->intrs);
 	ionic_intr_init(&ionic->idev, intr, index);
 
+	err = ionic_bus_get_irq(ionic, intr->index);
+	if (err < 0) {
+		clear_bit(index, ionic->intrs);
+		return err;
+	}
+
+	intr->vector = err;
+
 	return 0;
 }
+EXPORT_SYMBOL_NS(ionic_intr_alloc, "NET_IONIC");
 
-static void ionic_intr_free(struct ionic *ionic, int index)
+void ionic_intr_free(struct ionic_lif *lif, int index)
 {
-	if (index != IONIC_INTR_INDEX_NOT_ASSIGNED && index < ionic->nintrs)
-		clear_bit(index, ionic->intrs);
+	if (index != IONIC_INTR_INDEX_NOT_ASSIGNED && index < lif->ionic->nintrs)
+		clear_bit(index, lif->ionic->intrs);
 }
+EXPORT_SYMBOL_NS(ionic_intr_free, "NET_IONIC");
 
 static void ionic_irq_aff_notify(struct irq_affinity_notify *notify,
 				 const cpumask_t *mask)
@@ -401,7 +408,7 @@ static void ionic_qcq_intr_free(struct ionic_lif *lif, struct ionic_qcq *qcq)
 	irq_set_affinity_hint(qcq->intr.vector, NULL);
 	devm_free_irq(lif->ionic->dev, qcq->intr.vector, &qcq->napi);
 	qcq->intr.vector = 0;
-	ionic_intr_free(lif->ionic, qcq->intr.index);
+	ionic_intr_free(lif, qcq->intr.index);
 	qcq->intr.index = IONIC_INTR_INDEX_NOT_ASSIGNED;
 }
 
@@ -511,13 +518,6 @@ static int ionic_alloc_qcq_interrupt(struct ionic_lif *lif, struct ionic_qcq *qc
 		goto err_out;
 	}
 
-	err = ionic_bus_get_irq(lif->ionic, qcq->intr.index);
-	if (err < 0) {
-		netdev_warn(lif->netdev, "no vector for %s: %d\n",
-			    qcq->q.name, err);
-		goto err_out_free_intr;
-	}
-	qcq->intr.vector = err;
 	ionic_intr_mask_assert(lif->ionic->idev.intr_ctrl, qcq->intr.index,
 			       IONIC_INTR_MASK_SET);
 
@@ -546,7 +546,7 @@ static int ionic_alloc_qcq_interrupt(struct ionic_lif *lif, struct ionic_qcq *qc
 	return 0;
 
 err_out_free_intr:
-	ionic_intr_free(lif->ionic, qcq->intr.index);
+	ionic_intr_free(lif, qcq->intr.index);
 err_out:
 	return err;
 }
@@ -741,7 +741,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
 err_out_free_irq:
 	if (flags & IONIC_QCQ_F_INTR) {
 		devm_free_irq(dev, new->intr.vector, &new->napi);
-		ionic_intr_free(lif->ionic, new->intr.index);
+		ionic_intr_free(lif, new->intr.index);
 	}
 err_out_free_page_pool:
 	page_pool_destroy(new->q.page_pool);
Signature · 1 line
2.34.1
author maintainer
#8 lore raw

PATCH v2 6/14 net: ionic: Provide doorbell and CMB region information

In reply to Abhijit Gangurde

The RDMA device needs information of controller memory bar and doorbell capability to share with user context. Discover CMB regions and express doorbell capabilities on device init.

---
 .../net/ethernet/pensando/ionic/ionic_api.h   |  22 ++
 .../ethernet/pensando/ionic/ionic_bus_pci.c   |   2 +
 .../net/ethernet/pensando/ionic/ionic_dev.c   | 270 +++++++++++++++++-
 .../net/ethernet/pensando/ionic/ionic_dev.h   |  14 +-
 .../net/ethernet/pensando/ionic/ionic_if.h    |  89 ++++++
 .../net/ethernet/pensando/ionic/ionic_lif.c   |   2 +-
 6 files changed, 381 insertions(+), 18 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_api.h +22 -0
index 5fd23aa8c5a1..bd88666836b8 100644
@@ -106,4 +106,26 @@ int ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr);
  */
 void ionic_intr_free(struct ionic_lif *lif, int intr);
 
+/**
+ * ionic_get_cmb - Reserve cmb pages
+ * @lif:         Logical interface
+ * @pgid:        First page index
+ * @pgaddr:      First page bus addr (contiguous)
+ * @order:       Log base two number of pages (PAGE_SIZE)
+ * @stride_log2: Size of stride to determine CMB pool
+ * @expdb:       Will be set to true if this CMB region has expdb enabled
+ *
+ * Return: zero or negative error status
+ */
+int ionic_get_cmb(struct ionic_lif *lif, u32 *pgid, phys_addr_t *pgaddr,
+		  int order, u8 stride_log2, bool *expdb);
+
+/**
+ * ionic_put_cmb - Release cmb pages
+ * @lif:        Logical interface
+ * @pgid:       First page index
+ * @order:      Log base two number of pages (PAGE_SIZE)
+ */
+void ionic_put_cmb(struct ionic_lif *lif, u32 pgid, int order);
+
 #endif /* _IONIC_API_H_ */
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +2 -0
index bb75044dfb82..4f13dc908ed8 100644
@@ -272,6 +272,8 @@ static int ionic_setup_one(struct ionic *ionic)
 	}
 	ionic_debugfs_add_ident(ionic);
 
+	ionic_map_cmb(ionic);
+
 	err = ionic_init(ionic);
 	if (err) {
 		dev_err(dev, "Cannot init device: %d, aborting\n", err);
drivers/net/ethernet/pensando/ionic/ionic_dev.c +255 -15

324 lines not on this page · raw message

drivers/net/ethernet/pensando/ionic/ionic_dev.h +12 -2
index 68cf4da3c6b3..35566f97eaea 100644
@@ -35,6 +35,11 @@
 #define IONIC_RX_MIN_DOORBELL_DEADLINE	(HZ / 100)	/* 10ms */
 #define IONIC_RX_MAX_DOORBELL_DEADLINE	(HZ * 4)	/* 4s */
 
+#define IONIC_EXPDB_64B_WQE_LG2		6
+#define IONIC_EXPDB_128B_WQE_LG2	7
+#define IONIC_EXPDB_256B_WQE_LG2	8
+#define IONIC_EXPDB_512B_WQE_LG2	9
+
 struct ionic_dev_bar {
 	void __iomem *vaddr;
 	phys_addr_t bus_addr;
@@ -171,6 +176,11 @@ struct ionic_dev {
 	dma_addr_t phy_cmb_pages;
 	u32 cmb_npages;
 
+	dma_addr_t phy_cmb_expdb64_pages;
+	dma_addr_t phy_cmb_expdb128_pages;
+	dma_addr_t phy_cmb_expdb256_pages;
+	dma_addr_t phy_cmb_expdb512_pages;
+
 	u32 port_info_sz;
 	struct ionic_port_info *port_info;
 	dma_addr_t port_info_pa;
@@ -351,8 +361,8 @@ void ionic_dev_cmd_adminq_init(struct ionic_dev *idev, struct ionic_qcq *qcq,
 
 int ionic_db_page_num(struct ionic_lif *lif, int pid);
 
-int ionic_get_cmb(struct ionic_lif *lif, u32 *pgid, phys_addr_t *pgaddr, int order);
-void ionic_put_cmb(struct ionic_lif *lif, u32 pgid, int order);
+void ionic_dev_cmd_discover_cmb(struct ionic_dev *idev);
+void ionic_map_cmb(struct ionic *ionic);
 
 int ionic_cq_init(struct ionic_lif *lif, struct ionic_cq *cq,
 		  struct ionic_intr_info *intr,
drivers/net/ethernet/pensando/ionic/ionic_if.h +89 -0

146 lines not on this page · raw message

drivers/net/ethernet/pensando/ionic/ionic_lif.c +1 -1
index f89b458bd20a..1bd2202f263a 100644
@@ -673,7 +673,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
 			new->cmb_order = order_base_2(new->cmb_q_size / PAGE_SIZE);
 
 			err = ionic_get_cmb(lif, &new->cmb_pgid, &new->cmb_q_base_pa,
-					    new->cmb_order);
+					    new->cmb_order, 0, NULL);
 			if (err) {
 				netdev_err(lif->netdev,
 					   "Cannot allocate queue order %d from cmb: err %d\n",
Signature · 1 line
2.34.1
author maintainer
#9 lore raw

PATCH v2 7/14 RDMA: Add IONIC to rdma_driver_id definition

In reply to Abhijit Gangurde

Define RDMA_DRIVER_IONIC in enum rdma_driver_id.

---
 include/uapi/rdma/ib_user_ioctl_verbs.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/rdma/ib_user_ioctl_verbs.h +1 -0
index fe15bc7e9f70..89e6a3f13191 100644
@@ -255,6 +255,7 @@ enum rdma_driver_id {
 	RDMA_DRIVER_SIW,
 	RDMA_DRIVER_ERDMA,
 	RDMA_DRIVER_MANA,
+	RDMA_DRIVER_IONIC,
 };
 
 enum ib_uverbs_gid_type {
Signature · 1 line
2.34.1
author maintainer
#10 lore raw

PATCH v2 8/14 RDMA/ionic: Register auxiliary module for ionic ethernet adapter

In reply to Abhijit Gangurde

Register auxiliary module to create ibdevice for ionic ethernet adapter.

---
v1->v2
- Removed netdev references from ionic RDMA driver
- Moved to ionic_lif* instead of void* to convey information between aux devices and drivers.

 drivers/infiniband/hw/ionic/ionic_ibdev.c   | 135 ++++++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_ibdev.h   |  21 +++
 drivers/infiniband/hw/ionic/ionic_lif_cfg.c | 121 ++++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_lif_cfg.h |  65 ++++++++++
 4 files changed, 342 insertions(+)
 create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.h
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +135 -0
new file mode 100644
index 000000000000..ca047a789378
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/module.h>
+#include <linux/printk.h>
+#include <net/addrconf.h>
+
+#include "ionic_ibdev.h"
+
+#define DRIVER_DESCRIPTION "AMD Pensando RoCE HCA driver"
+#define DEVICE_DESCRIPTION "AMD Pensando RoCE HCA"
+
+MODULE_AUTHOR("Allen Hubbe <[email protected]>");
+MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("NET_IONIC");
+
+static const struct auxiliary_device_id ionic_aux_id_table[] = {
+	{ .name = "ionic.rdma", },
+	{},
+};
+
+MODULE_DEVICE_TABLE(auxiliary, ionic_aux_id_table);
+
+static void ionic_destroy_ibdev(struct ionic_ibdev *dev)
+{
+	ib_unregister_device(&dev->ibdev);
+	ib_dealloc_device(&dev->ibdev);
+}
+
+static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
+{
+	struct ib_device *ibdev;
+	struct ionic_ibdev *dev;
+	int rc;
+
+	rc = ionic_version_check(&ionic_adev->adev.dev, ionic_adev->lif);
+	if (rc)
+		goto err_dev;
+
+	dev = ib_alloc_device(ionic_ibdev, ibdev);
+	if (!dev) {
+		rc = -ENOMEM;
+		goto err_dev;
+	}
+
+	ionic_fill_lif_cfg(ionic_adev->lif, &dev->lif_cfg);
+
+	ibdev = &dev->ibdev;
+	ibdev->dev.parent = dev->lif_cfg.hwdev;
+
+	strscpy(ibdev->name, "ionic_%d", IB_DEVICE_NAME_MAX);
+	strscpy(ibdev->node_desc, DEVICE_DESCRIPTION, IB_DEVICE_NODE_DESC_MAX);
+
+	ibdev->node_type = RDMA_NODE_IB_CA;
+	ibdev->phys_port_cnt = 1;
+
+	/* the first two eq are reserved for async events */
+	ibdev->num_comp_vectors = dev->lif_cfg.eq_count - 2;
+
+	addrconf_ifid_eui48((u8 *)&ibdev->node_guid,
+			    ionic_lif_netdev(ionic_adev->lif));
+
+	rc = ib_device_set_netdev(ibdev, ionic_lif_netdev(ionic_adev->lif), 1);
+	if (rc)
+		goto err_admin;
+
+	rc = ib_register_device(ibdev, "ionic_%d", ibdev->dev.parent);
+	if (rc)
+		goto err_register;
+
+	return dev;
+
+err_register:
+err_admin:
+	ib_dealloc_device(&dev->ibdev);
+err_dev:
+	return ERR_PTR(rc);
+}
+
+static int ionic_aux_probe(struct auxiliary_device *adev,
+			   const struct auxiliary_device_id *id)
+{
+	struct ionic_aux_dev *ionic_adev;
+	struct ionic_ibdev *dev;
+
+	ionic_adev = container_of(adev, struct ionic_aux_dev, adev);
+	dev = ionic_create_ibdev(ionic_adev);
+	if (IS_ERR(dev))
+		return dev_err_probe(&adev->dev, PTR_ERR(dev),
+				     "Failed to register ibdev\n");
+
+	auxiliary_set_drvdata(adev, dev);
+	ibdev_dbg(&dev->ibdev, "registered\n");
+
+	return 0;
+}
+
+static void ionic_aux_remove(struct auxiliary_device *adev)
+{
+	struct ionic_ibdev *dev = auxiliary_get_drvdata(adev);
+
+	dev_dbg(&adev->dev, "unregister ibdev\n");
+	ionic_destroy_ibdev(dev);
+	dev_dbg(&adev->dev, "unregistered\n");
+}
+
+static struct auxiliary_driver ionic_aux_r_driver = {
+	.name = "rdma",
+	.probe = ionic_aux_probe,
+	.remove = ionic_aux_remove,
+	.id_table = ionic_aux_id_table,
+};
+
+static int __init ionic_mod_init(void)
+{
+	int rc;
+
+	rc = auxiliary_driver_register(&ionic_aux_r_driver);
+	if (rc)
+		goto err_aux;
+
+	return 0;
+
+err_aux:
+	return rc;
+}
+
+static void __exit ionic_mod_exit(void)
+{
+	auxiliary_driver_unregister(&ionic_aux_r_driver);
+}
+
+module_init(ionic_mod_init);
+module_exit(ionic_mod_exit);
drivers/infiniband/hw/ionic/ionic_ibdev.h new file +21 -0
new file mode 100644
index 000000000000..e13adff390d7
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#ifndef _IONIC_IBDEV_H_
+#define _IONIC_IBDEV_H_
+
+#include <rdma/ib_verbs.h>
+#include <ionic_api.h>
+
+#include "ionic_lif_cfg.h"
+
+#define IONIC_MIN_RDMA_VERSION	0
+#define IONIC_MAX_RDMA_VERSION	2
+
+struct ionic_ibdev {
+	struct ib_device	ibdev;
+
+	struct ionic_lif_cfg	lif_cfg;
+};
+
+#endif /* _IONIC_IBDEV_H_ */
drivers/infiniband/hw/ionic/ionic_lif_cfg.c new file +121 -0

121 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_lif_cfg.h new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH v2 08/14] RDMA/ionic: Register auxiliary module for ionic ethernet adapter

Quoted 60 lines · Abhijit Gangurde

Register auxiliary module to create ibdevice for ionic ethernet adapter.

---
v1->v2
- Removed netdev references from ionic RDMA driver
- Moved to ionic_lif* instead of void* to convey information between aux devices and drivers.

 drivers/infiniband/hw/ionic/ionic_ibdev.c   | 135 ++++++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_ibdev.h   |  21 +++
 drivers/infiniband/hw/ionic/ionic_lif_cfg.c | 121 ++++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_lif_cfg.h |  65 ++++++++++
 4 files changed, 342 insertions(+)
 create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.h
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +29 -0
new file mode 100644
index 000000000000..ca047a789378
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/module.h>
+#include <linux/printk.h>
+#include <net/addrconf.h>
+
+#include "ionic_ibdev.h"
+
+#define DRIVER_DESCRIPTION "AMD Pensando RoCE HCA driver"
+#define DEVICE_DESCRIPTION "AMD Pensando RoCE HCA"
+
+MODULE_AUTHOR("Allen Hubbe <[email protected]>");
+MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("NET_IONIC");
+
+static const struct auxiliary_device_id ionic_aux_id_table[] = {
+       { .name = "ionic.rdma", },
+       {},
+};
+
+MODULE_DEVICE_TABLE(auxiliary, ionic_aux_id_table);
+
+static void ionic_destroy_ibdev(struct ionic_ibdev *dev)
+{
+       ib_unregister_device(&dev->ibdev);
+       ib_dealloc_device(&dev->ibdev);
+}

drivers/infiniband/hw/ionic/ionic_ibdev.c line 39

Quoted 10 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +10 -0
+
+static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
+{
+       struct ib_device *ibdev;
+       struct ionic_ibdev *dev;
+       int rc;
+
+       rc = ionic_version_check(&ionic_adev->adev.dev, ionic_adev->lif);
+       if (rc)
+               goto err_dev;

You can return directly from here

drivers/infiniband/hw/ionic/ionic_ibdev.c line 44

Quoted 5 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +5 -0
+
+       dev = ib_alloc_device(ionic_ibdev, ibdev);
+       if (!dev) {
+               rc = -ENOMEM;
+               goto err_dev;

You can return directly from here

Quoted 20 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +20 -0
+       }
+
+       ionic_fill_lif_cfg(ionic_adev->lif, &dev->lif_cfg);
+
+       ibdev = &dev->ibdev;
+       ibdev->dev.parent = dev->lif_cfg.hwdev;
+
+       strscpy(ibdev->name, "ionic_%d", IB_DEVICE_NAME_MAX);
+       strscpy(ibdev->node_desc, DEVICE_DESCRIPTION, IB_DEVICE_NODE_DESC_MAX);
+
+       ibdev->node_type = RDMA_NODE_IB_CA;
+       ibdev->phys_port_cnt = 1;
+
+       /* the first two eq are reserved for async events */
+       ibdev->num_comp_vectors = dev->lif_cfg.eq_count - 2;
+
+       addrconf_ifid_eui48((u8 *)&ibdev->node_guid,
+                           ionic_lif_netdev(ionic_adev->lif));
+
+       rc = ib_device_set_netdev(ibdev, ionic_lif_netdev(ionic_adev->lif), 1);

drivers/infiniband/hw/ionic/ionic_ibdev.c line 74

Quoted 10 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +10 -0
+       if (rc)
+               goto err_admin;
+
+       rc = ib_register_device(ibdev, "ionic_%d", ibdev->dev.parent);
+       if (rc)
+               goto err_register;
+
+       return dev;
+
+err_register:

Unnecessary label

Quoted 42 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +42 -0
+err_admin:
+       ib_dealloc_device(&dev->ibdev);
+err_dev:
+       return ERR_PTR(rc);
+}
+
+static int ionic_aux_probe(struct auxiliary_device *adev,
+                          const struct auxiliary_device_id *id)
+{
+       struct ionic_aux_dev *ionic_adev;
+       struct ionic_ibdev *dev;
+
+       ionic_adev = container_of(adev, struct ionic_aux_dev, adev);
+       dev = ionic_create_ibdev(ionic_adev);
+       if (IS_ERR(dev))
+               return dev_err_probe(&adev->dev, PTR_ERR(dev),
+                                    "Failed to register ibdev\n");
+
+       auxiliary_set_drvdata(adev, dev);
+       ibdev_dbg(&dev->ibdev, "registered\n");
+
+       return 0;
+}
+
+static void ionic_aux_remove(struct auxiliary_device *adev)
+{
+       struct ionic_ibdev *dev = auxiliary_get_drvdata(adev);
+
+       dev_dbg(&adev->dev, "unregister ibdev\n");
+       ionic_destroy_ibdev(dev);
+       dev_dbg(&adev->dev, "unregistered\n");
+}
+
+static struct auxiliary_driver ionic_aux_r_driver = {
+       .name = "rdma",
+       .probe = ionic_aux_probe,
+       .remove = ionic_aux_remove,
+       .id_table = ionic_aux_id_table,
+};
+
+static int __init ionic_mod_init(void)
+{

drivers/infiniband/hw/ionic/ionic_ibdev.c line 126

Quoted 10 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +10 -0
+       int rc;
+
+       rc = auxiliary_driver_register(&ionic_aux_r_driver);
+       if (rc)
+               goto err_aux;
+
+       return 0;
+
+err_aux:
+       return rc;

You can simplify this function as "return
auxiliary_driver_register(&ionic_aux_r_driver);"

Quoted 135 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +9 -0
+}
+
+static void __exit ionic_mod_exit(void)
+{
+       auxiliary_driver_unregister(&ionic_aux_r_driver);
+}
+
+module_init(ionic_mod_init);
+module_exit(ionic_mod_exit);
drivers/infiniband/hw/ionic/ionic_ibdev.h new file +21 -0
new file mode 100644
index 000000000000..e13adff390d7
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#ifndef _IONIC_IBDEV_H_
+#define _IONIC_IBDEV_H_
+
+#include <rdma/ib_verbs.h>
+#include <ionic_api.h>
+
+#include "ionic_lif_cfg.h"
+
+#define IONIC_MIN_RDMA_VERSION 0
+#define IONIC_MAX_RDMA_VERSION 2
+
+struct ionic_ibdev {
+       struct ib_device        ibdev;
+
+       struct ionic_lif_cfg    lif_cfg;
+};
+
+#endif /* _IONIC_IBDEV_H_ */
drivers/infiniband/hw/ionic/ionic_lif_cfg.c new file +93 -0
new file mode 100644
index 000000000000..a02eb2f5bd45
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/kernel.h>
+
+#include <ionic.h>
+#include <ionic_lif.h>
+
+#include "ionic_lif_cfg.h"
+
+#define IONIC_MIN_RDMA_VERSION 0
+#define IONIC_MAX_RDMA_VERSION 2
+
+static u8 ionic_get_expdb(struct ionic_lif *lif)
+{
+       u8 expdb_support = 0;
+
+       if (lif->ionic->idev.phy_cmb_expdb64_pages)
+               expdb_support |= IONIC_EXPDB_64B_WQE;
+       if (lif->ionic->idev.phy_cmb_expdb128_pages)
+               expdb_support |= IONIC_EXPDB_128B_WQE;
+       if (lif->ionic->idev.phy_cmb_expdb256_pages)
+               expdb_support |= IONIC_EXPDB_256B_WQE;
+       if (lif->ionic->idev.phy_cmb_expdb512_pages)
+               expdb_support |= IONIC_EXPDB_512B_WQE;
+
+       return expdb_support;
+}
+
+void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg)
+{
+       union ionic_lif_identity *ident = &lif->ionic->ident.lif;
+
+       cfg->lif = lif;
+       cfg->hwdev = &lif->ionic->pdev->dev;
+       cfg->lif_index = lif->index;
+       cfg->lif_hw_index = lif->hw_index;
+
+       cfg->dbid = lif->kern_pid;
+       cfg->dbid_count = le32_to_cpu(lif->ionic->ident.dev.ndbpgs_per_lif);
+       cfg->dbpage = lif->kern_dbpage;
+       cfg->intr_ctrl = lif->ionic->idev.intr_ctrl;
+
+       cfg->db_phys = lif->ionic->bars[IONIC_PCI_BAR_DBELL].bus_addr;
+
+       if (IONIC_VERSION(ident->rdma.version, ident->rdma.minor_version) >=
+           IONIC_VERSION(2, 1))
+               cfg->page_size_supported =
+                   cpu_to_le64(ident->rdma.page_size_cap);
+       else
+               cfg->page_size_supported = IONIC_PAGE_SIZE_SUPPORTED;
+
+       cfg->rdma_version = ident->rdma.version;
+       cfg->qp_opcodes = ident->rdma.qp_opcodes;
+       cfg->admin_opcodes = ident->rdma.admin_opcodes;
+
+       cfg->stats_type = cpu_to_le16(ident->rdma.stats_type);
+       cfg->npts_per_lif = le32_to_cpu(ident->rdma.npts_per_lif);
+       cfg->nmrs_per_lif = le32_to_cpu(ident->rdma.nmrs_per_lif);
+       cfg->nahs_per_lif = le32_to_cpu(ident->rdma.nahs_per_lif);
+
+       cfg->aq_base = le32_to_cpu(ident->rdma.aq_qtype.qid_base);
+       cfg->cq_base = le32_to_cpu(ident->rdma.cq_qtype.qid_base);
+       cfg->eq_base = le32_to_cpu(ident->rdma.eq_qtype.qid_base);
+
+       /*
+        * ionic_create_rdma_admin() may reduce aq_count or eq_count if
+        * it is unable to allocate all that were requested.
+        * aq_count is tunable; see ionic_aq_count
+        * eq_count is tunable; see ionic_eq_count
+        */
+       cfg->aq_count = le32_to_cpu(ident->rdma.aq_qtype.qid_count);
+       cfg->eq_count = le32_to_cpu(ident->rdma.eq_qtype.qid_count);
+       cfg->cq_count = le32_to_cpu(ident->rdma.cq_qtype.qid_count);
+       cfg->qp_count = le32_to_cpu(ident->rdma.sq_qtype.qid_count);
+       cfg->dbid_count = le32_to_cpu(lif->ionic->ident.dev.ndbpgs_per_lif);
+
+       cfg->aq_qtype = ident->rdma.aq_qtype.qtype;
+       cfg->sq_qtype = ident->rdma.sq_qtype.qtype;
+       cfg->rq_qtype = ident->rdma.rq_qtype.qtype;
+       cfg->cq_qtype = ident->rdma.cq_qtype.qtype;
+       cfg->eq_qtype = ident->rdma.eq_qtype.qtype;
+       cfg->udma_qgrp_shift = ident->rdma.udma_shift;
+       cfg->udma_count = 2;
+
+       cfg->max_stride = ident->rdma.max_stride;
+       cfg->expdb_mask = ionic_get_expdb(lif);
+
+       cfg->sq_expdb =
+           !!(lif->qtype_info[IONIC_QTYPE_TXQ].features & IONIC_QIDENT_F_EXPDB);
+       cfg->rq_expdb =
+           !!(lif->qtype_info[IONIC_QTYPE_RXQ].features & IONIC_QIDENT_F_EXPDB);
+}

drivers/infiniband/hw/ionic/ionic_lif_cfg.c line 103

Quoted 10 lines
drivers/infiniband/hw/ionic/ionic_lif_cfg.c new file +10 -0
+
+struct net_device *ionic_lif_netdev(struct ionic_lif *lif)
+{
+       return lif->netdev;
+}
+
+int ionic_version_check(const struct device *dev, struct ionic_lif *lif)
+{
+       union ionic_lif_identity *ident = &lif->ionic->ident.lif;
+       int rc;

local variable "rc" is not needed here, you can return directly.

Quoted 93 lines
drivers/infiniband/hw/ionic/ionic_lif_cfg.c new file +18 -0
+
+       if (ident->rdma.version < IONIC_MIN_RDMA_VERSION ||
+           ident->rdma.version > IONIC_MAX_RDMA_VERSION) {
+               rc = -EINVAL;
+               dev_err_probe(dev, rc,
+                             "ionic_rdma: incompatible version, fw ver %u\n",
+                             ident->rdma.version);
+               dev_err_probe(dev, rc,
+                             "ionic_rdma: Driver Min Version %u\n",
+                             IONIC_MIN_RDMA_VERSION);
+               dev_err_probe(dev, rc,
+                             "ionic_rdma: Driver Max Version %u\n",
+                             IONIC_MAX_RDMA_VERSION);
+               return rc;
+       }
+
+       return 0;
+}
drivers/infiniband/hw/ionic/ionic_lif_cfg.h new file +65 -1
new file mode 100644
index 000000000000..b095637c54cf
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#ifndef _IONIC_LIF_CFG_H_
+
+#define IONIC_VERSION(a, b) (((a) << 16) + ((b) << 8))
+#define IONIC_PAGE_SIZE_SUPPORTED      0x40201000 /* 4kb, 2Mb, 1Gb */
+
+#define IONIC_EXPDB_64B_WQE    BIT(0)
+#define IONIC_EXPDB_128B_WQE   BIT(1)
+#define IONIC_EXPDB_256B_WQE   BIT(2)
+#define IONIC_EXPDB_512B_WQE   BIT(3)
+
+struct ionic_lif_cfg {
+       struct device *hwdev;
+       struct ionic_lif *lif;
+
+       int lif_index;
+       int lif_hw_index;
+
+       u32 dbid;
+       int dbid_count;
+       u64 __iomem *dbpage;
+       struct ionic_intr __iomem *intr_ctrl;
+       phys_addr_t db_phys;
+
+       u64 page_size_supported;
+       u32 npts_per_lif;
+       u32 nmrs_per_lif;
+       u32 nahs_per_lif;
+
+       u32 aq_base;
+       u32 cq_base;
+       u32 eq_base;
+
+       int aq_count;
+       int eq_count;
+       int cq_count;
+       int qp_count;
+
+       u16 stats_type;
+       u8 aq_qtype;
+       u8 sq_qtype;
+       u8 rq_qtype;
+       u8 cq_qtype;
+       u8 eq_qtype;
+
+       u8 udma_count;
+       u8 udma_qgrp_shift;
+
+       u8 rdma_version;
+       u8 qp_opcodes;
+       u8 admin_opcodes;
+
+       u8 max_stride;
+       bool sq_expdb;
+       bool rq_expdb;
+       u8 expdb_mask;
+};
+
+int ionic_version_check(const struct device *dev, struct ionic_lif *lif);
+void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg);
+struct net_device *ionic_lif_netdev(struct ionic_lif *lif);
+
+#endif /* _IONIC_LIF_CFG_H_ */
--

2.34.1

Signature · 2 lines
Regards,
Kalesh AP
author maintainer
#12 lore raw

Re: [PATCH v2 08/14] RDMA/ionic: Register auxiliary module for ionic ethernet adapter

Quoted 64 lines · Kalesh Anakkur Purayil
Quoted 62 lines · Abhijit Gangurde

Register auxiliary module to create ibdevice for ionic ethernet adapter.

---
v1->v2
- Removed netdev references from ionic RDMA driver
- Moved to ionic_lif* instead of void* to convey information between aux devices and drivers.

  drivers/infiniband/hw/ionic/ionic_ibdev.c   | 135 ++++++++++++++++++++
  drivers/infiniband/hw/ionic/ionic_ibdev.h   |  21 +++
  drivers/infiniband/hw/ionic/ionic_lif_cfg.c | 121 ++++++++++++++++++
  drivers/infiniband/hw/ionic/ionic_lif_cfg.h |  65 ++++++++++
  4 files changed, 342 insertions(+)

create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.c create mode 100644 drivers/infiniband/hw/ionic/ionic_ibdev.h create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.c create mode 100644 drivers/infiniband/hw/ionic/ionic_lif_cfg.h

drivers/infiniband/hw/ionic/ionic_ibdev.c new file +32 -0
new file mode 100644
index 000000000000..ca047a789378
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/module.h>
+#include <linux/printk.h>
+#include <net/addrconf.h>
+
+#include "ionic_ibdev.h"
+
+#define DRIVER_DESCRIPTION "AMD Pensando RoCE HCA driver"
+#define DEVICE_DESCRIPTION "AMD Pensando RoCE HCA"
+
+MODULE_AUTHOR("Allen Hubbe <[email protected]>");
+MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("NET_IONIC");
+
+static const struct auxiliary_device_id ionic_aux_id_table[] = {
+       { .name = "ionic.rdma", },
+       {},
+};
+
+MODULE_DEVICE_TABLE(auxiliary, ionic_aux_id_table);
+
+static void ionic_destroy_ibdev(struct ionic_ibdev *dev)
+{
+       ib_unregister_device(&dev->ibdev);
+       ib_dealloc_device(&dev->ibdev);
+}
+
+static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
+{
Quoted 8 lines

drivers/infiniband/hw/ionic/ionic_ibdev.c line 39

Quoted 7 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +7 -0
+       struct ib_device *ibdev;
+       struct ionic_ibdev *dev;
+       int rc;
+
+       rc = ionic_version_check(&ionic_adev->adev.dev, ionic_adev->lif);
+       if (rc)
+               goto err_dev;

You can return directly from here

Sure. Will correct this.

Quoted 6 lines

drivers/infiniband/hw/ionic/ionic_ibdev.c line 44

Quoted 5 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +5 -0
+
+       dev = ib_alloc_device(ionic_ibdev, ibdev);
+       if (!dev) {
+               rc = -ENOMEM;
+               goto err_dev;

You can return directly from here

Sure. Will correct this.

Quoted 23 lines
Quoted 23 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +23 -0
+       }
+
+       ionic_fill_lif_cfg(ionic_adev->lif, &dev->lif_cfg);
+
+       ibdev = &dev->ibdev;
+       ibdev->dev.parent = dev->lif_cfg.hwdev;
+
+       strscpy(ibdev->name, "ionic_%d", IB_DEVICE_NAME_MAX);
+       strscpy(ibdev->node_desc, DEVICE_DESCRIPTION, IB_DEVICE_NODE_DESC_MAX);
+
+       ibdev->node_type = RDMA_NODE_IB_CA;
+       ibdev->phys_port_cnt = 1;
+
+       /* the first two eq are reserved for async events */
+       ibdev->num_comp_vectors = dev->lif_cfg.eq_count - 2;
+
+       addrconf_ifid_eui48((u8 *)&ibdev->node_guid,
+                           ionic_lif_netdev(ionic_adev->lif));
+
+       rc = ib_device_set_netdev(ibdev, ionic_lif_netdev(ionic_adev->lif), 1);
+       if (rc)
+               goto err_admin;
+
Quoted 8 lines

drivers/infiniband/hw/ionic/ionic_ibdev.c line 74

Quoted 7 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +7 -0
+       rc = ib_register_device(ibdev, "ionic_%d", ibdev->dev.parent);
+       if (rc)
+               goto err_register;
+
+       return dev;
+
+err_register:

Unnecessary label

Because of logical split , this used in patch #13.

Quoted 46 lines
Quoted 46 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +46 -0
+err_admin:
+       ib_dealloc_device(&dev->ibdev);
+err_dev:
+       return ERR_PTR(rc);
+}
+
+static int ionic_aux_probe(struct auxiliary_device *adev,
+                          const struct auxiliary_device_id *id)
+{
+       struct ionic_aux_dev *ionic_adev;
+       struct ionic_ibdev *dev;
+
+       ionic_adev = container_of(adev, struct ionic_aux_dev, adev);
+       dev = ionic_create_ibdev(ionic_adev);
+       if (IS_ERR(dev))
+               return dev_err_probe(&adev->dev, PTR_ERR(dev),
+                                    "Failed to register ibdev\n");
+
+       auxiliary_set_drvdata(adev, dev);
+       ibdev_dbg(&dev->ibdev, "registered\n");
+
+       return 0;
+}
+
+static void ionic_aux_remove(struct auxiliary_device *adev)
+{
+       struct ionic_ibdev *dev = auxiliary_get_drvdata(adev);
+
+       dev_dbg(&adev->dev, "unregister ibdev\n");
+       ionic_destroy_ibdev(dev);
+       dev_dbg(&adev->dev, "unregistered\n");
+}
+
+static struct auxiliary_driver ionic_aux_r_driver = {
+       .name = "rdma",
+       .probe = ionic_aux_probe,
+       .remove = ionic_aux_remove,
+       .id_table = ionic_aux_id_table,
+};
+
+static int __init ionic_mod_init(void)
+{
+       int rc;
+
+       rc = auxiliary_driver_register(&ionic_aux_r_driver);
+       if (rc)
Quoted 8 lines

drivers/infiniband/hw/ionic/ionic_ibdev.c line 126

Quoted 6 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +6 -0
+               goto err_aux;
+
+       return 0;
+
+err_aux:
+       return rc;

You can simplify this function as "return
auxiliary_driver_register(&ionic_aux_r_driver);"

Because of logical split, err_aux this used in patch #9.

Quoted 138 lines
Quoted 138 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c new file +9 -0
+}
+
+static void __exit ionic_mod_exit(void)
+{
+       auxiliary_driver_unregister(&ionic_aux_r_driver);
+}
+
+module_init(ionic_mod_init);
+module_exit(ionic_mod_exit);
drivers/infiniband/hw/ionic/ionic_ibdev.h new file +21 -0
new file mode 100644
index 000000000000..e13adff390d7
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#ifndef _IONIC_IBDEV_H_
+#define _IONIC_IBDEV_H_
+
+#include <rdma/ib_verbs.h>
+#include <ionic_api.h>
+
+#include "ionic_lif_cfg.h"
+
+#define IONIC_MIN_RDMA_VERSION 0
+#define IONIC_MAX_RDMA_VERSION 2
+
+struct ionic_ibdev {
+       struct ib_device        ibdev;
+
+       struct ionic_lif_cfg    lif_cfg;
+};
+
+#endif /* _IONIC_IBDEV_H_ */
drivers/infiniband/hw/ionic/ionic_lif_cfg.c new file +96 -0
new file mode 100644
index 000000000000..a02eb2f5bd45
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/kernel.h>
+
+#include <ionic.h>
+#include <ionic_lif.h>
+
+#include "ionic_lif_cfg.h"
+
+#define IONIC_MIN_RDMA_VERSION 0
+#define IONIC_MAX_RDMA_VERSION 2
+
+static u8 ionic_get_expdb(struct ionic_lif *lif)
+{
+       u8 expdb_support = 0;
+
+       if (lif->ionic->idev.phy_cmb_expdb64_pages)
+               expdb_support |= IONIC_EXPDB_64B_WQE;
+       if (lif->ionic->idev.phy_cmb_expdb128_pages)
+               expdb_support |= IONIC_EXPDB_128B_WQE;
+       if (lif->ionic->idev.phy_cmb_expdb256_pages)
+               expdb_support |= IONIC_EXPDB_256B_WQE;
+       if (lif->ionic->idev.phy_cmb_expdb512_pages)
+               expdb_support |= IONIC_EXPDB_512B_WQE;
+
+       return expdb_support;
+}
+
+void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg)
+{
+       union ionic_lif_identity *ident = &lif->ionic->ident.lif;
+
+       cfg->lif = lif;
+       cfg->hwdev = &lif->ionic->pdev->dev;
+       cfg->lif_index = lif->index;
+       cfg->lif_hw_index = lif->hw_index;
+
+       cfg->dbid = lif->kern_pid;
+       cfg->dbid_count = le32_to_cpu(lif->ionic->ident.dev.ndbpgs_per_lif);
+       cfg->dbpage = lif->kern_dbpage;
+       cfg->intr_ctrl = lif->ionic->idev.intr_ctrl;
+
+       cfg->db_phys = lif->ionic->bars[IONIC_PCI_BAR_DBELL].bus_addr;
+
+       if (IONIC_VERSION(ident->rdma.version, ident->rdma.minor_version) >=
+           IONIC_VERSION(2, 1))
+               cfg->page_size_supported =
+                   cpu_to_le64(ident->rdma.page_size_cap);
+       else
+               cfg->page_size_supported = IONIC_PAGE_SIZE_SUPPORTED;
+
+       cfg->rdma_version = ident->rdma.version;
+       cfg->qp_opcodes = ident->rdma.qp_opcodes;
+       cfg->admin_opcodes = ident->rdma.admin_opcodes;
+
+       cfg->stats_type = cpu_to_le16(ident->rdma.stats_type);
+       cfg->npts_per_lif = le32_to_cpu(ident->rdma.npts_per_lif);
+       cfg->nmrs_per_lif = le32_to_cpu(ident->rdma.nmrs_per_lif);
+       cfg->nahs_per_lif = le32_to_cpu(ident->rdma.nahs_per_lif);
+
+       cfg->aq_base = le32_to_cpu(ident->rdma.aq_qtype.qid_base);
+       cfg->cq_base = le32_to_cpu(ident->rdma.cq_qtype.qid_base);
+       cfg->eq_base = le32_to_cpu(ident->rdma.eq_qtype.qid_base);
+
+       /*
+        * ionic_create_rdma_admin() may reduce aq_count or eq_count if
+        * it is unable to allocate all that were requested.
+        * aq_count is tunable; see ionic_aq_count
+        * eq_count is tunable; see ionic_eq_count
+        */
+       cfg->aq_count = le32_to_cpu(ident->rdma.aq_qtype.qid_count);
+       cfg->eq_count = le32_to_cpu(ident->rdma.eq_qtype.qid_count);
+       cfg->cq_count = le32_to_cpu(ident->rdma.cq_qtype.qid_count);
+       cfg->qp_count = le32_to_cpu(ident->rdma.sq_qtype.qid_count);
+       cfg->dbid_count = le32_to_cpu(lif->ionic->ident.dev.ndbpgs_per_lif);
+
+       cfg->aq_qtype = ident->rdma.aq_qtype.qtype;
+       cfg->sq_qtype = ident->rdma.sq_qtype.qtype;
+       cfg->rq_qtype = ident->rdma.rq_qtype.qtype;
+       cfg->cq_qtype = ident->rdma.cq_qtype.qtype;
+       cfg->eq_qtype = ident->rdma.eq_qtype.qtype;
+       cfg->udma_qgrp_shift = ident->rdma.udma_shift;
+       cfg->udma_count = 2;
+
+       cfg->max_stride = ident->rdma.max_stride;
+       cfg->expdb_mask = ionic_get_expdb(lif);
+
+       cfg->sq_expdb =
+           !!(lif->qtype_info[IONIC_QTYPE_TXQ].features & IONIC_QIDENT_F_EXPDB);
+       cfg->rq_expdb =
+           !!(lif->qtype_info[IONIC_QTYPE_RXQ].features & IONIC_QIDENT_F_EXPDB);
+}
+
+struct net_device *ionic_lif_netdev(struct ionic_lif *lif)
+{
Quoted 8 lines

drivers/infiniband/hw/ionic/ionic_lif_cfg.c line 103

Quoted 7 lines
drivers/infiniband/hw/ionic/ionic_lif_cfg.c new file +7 -0
+       return lif->netdev;
+}
+
+int ionic_version_check(const struct device *dev, struct ionic_lif *lif)
+{
+       union ionic_lif_identity *ident = &lif->ionic->ident.lif;
+       int rc;

local variable "rc" is not needed here, you can return directly.

sure. Will remove it.

Thanks,
Abhijit

Quoted 94 lines
Quoted 93 lines
drivers/infiniband/hw/ionic/ionic_lif_cfg.c new file +18 -0
+
+       if (ident->rdma.version < IONIC_MIN_RDMA_VERSION ||
+           ident->rdma.version > IONIC_MAX_RDMA_VERSION) {
+               rc = -EINVAL;
+               dev_err_probe(dev, rc,
+                             "ionic_rdma: incompatible version, fw ver %u\n",
+                             ident->rdma.version);
+               dev_err_probe(dev, rc,
+                             "ionic_rdma: Driver Min Version %u\n",
+                             IONIC_MIN_RDMA_VERSION);
+               dev_err_probe(dev, rc,
+                             "ionic_rdma: Driver Max Version %u\n",
+                             IONIC_MAX_RDMA_VERSION);
+               return rc;
+       }
+
+       return 0;
+}
drivers/infiniband/hw/ionic/ionic_lif_cfg.h new file +65 -1
new file mode 100644
index 000000000000..b095637c54cf
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#ifndef _IONIC_LIF_CFG_H_
+
+#define IONIC_VERSION(a, b) (((a) << 16) + ((b) << 8))
+#define IONIC_PAGE_SIZE_SUPPORTED      0x40201000 /* 4kb, 2Mb, 1Gb */
+
+#define IONIC_EXPDB_64B_WQE    BIT(0)
+#define IONIC_EXPDB_128B_WQE   BIT(1)
+#define IONIC_EXPDB_256B_WQE   BIT(2)
+#define IONIC_EXPDB_512B_WQE   BIT(3)
+
+struct ionic_lif_cfg {
+       struct device *hwdev;
+       struct ionic_lif *lif;
+
+       int lif_index;
+       int lif_hw_index;
+
+       u32 dbid;
+       int dbid_count;
+       u64 __iomem *dbpage;
+       struct ionic_intr __iomem *intr_ctrl;
+       phys_addr_t db_phys;
+
+       u64 page_size_supported;
+       u32 npts_per_lif;
+       u32 nmrs_per_lif;
+       u32 nahs_per_lif;
+
+       u32 aq_base;
+       u32 cq_base;
+       u32 eq_base;
+
+       int aq_count;
+       int eq_count;
+       int cq_count;
+       int qp_count;
+
+       u16 stats_type;
+       u8 aq_qtype;
+       u8 sq_qtype;
+       u8 rq_qtype;
+       u8 cq_qtype;
+       u8 eq_qtype;
+
+       u8 udma_count;
+       u8 udma_qgrp_shift;
+
+       u8 rdma_version;
+       u8 qp_opcodes;
+       u8 admin_opcodes;
+
+       u8 max_stride;
+       bool sq_expdb;
+       bool rq_expdb;
+       u8 expdb_mask;
+};
+
+int ionic_version_check(const struct device *dev, struct ionic_lif *lif);
+void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg);
+struct net_device *ionic_lif_netdev(struct ionic_lif *lif);
+
+#endif /* _IONIC_LIF_CFG_H_ */
--

2.34.1

author maintainer
#13 lore raw

PATCH v2 9/14 RDMA/ionic: Create device queues to support admin operations

In reply to Abhijit Gangurde

Setup RDMA admin queues using device command exposed over auxiliary device and manage these queues using bit-map tracking structures.

---
 drivers/infiniband/hw/ionic/ionic_admin.c     | 1160 +++++++++++++++++
 .../infiniband/hw/ionic/ionic_controlpath.c   |  191 +++
 drivers/infiniband/hw/ionic/ionic_fw.h        |  164 +++
 drivers/infiniband/hw/ionic/ionic_ibdev.c     |  118 ++
 drivers/infiniband/hw/ionic/ionic_ibdev.h     |  245 ++++
 drivers/infiniband/hw/ionic/ionic_pgtbl.c     |  113 ++
 drivers/infiniband/hw/ionic/ionic_queue.c     |   52 +
 drivers/infiniband/hw/ionic/ionic_queue.h     |  234 ++++
 drivers/infiniband/hw/ionic/ionic_res.c       |   42 +
 drivers/infiniband/hw/ionic/ionic_res.h       |  182 +++
 10 files changed, 2501 insertions(+)
 create mode 100644 drivers/infiniband/hw/ionic/ionic_admin.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_controlpath.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_fw.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_pgtbl.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_queue.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_queue.h
 create mode 100644 drivers/infiniband/hw/ionic/ionic_res.c
 create mode 100644 drivers/infiniband/hw/ionic/ionic_res.h
drivers/infiniband/hw/ionic/ionic_admin.c new file +1160 -0
new file mode 100644
index 000000000000..5a414c0600a1
@@ -0,0 +1,1160 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/printk.h>
+
+#include "ionic_fw.h"
+#include "ionic_ibdev.h"
+
+#define IONIC_EQ_COUNT_MIN	4
+#define IONIC_AQ_COUNT_MIN	1
+
+/* not a valid queue position or negative error status */
+#define IONIC_ADMIN_POSTED	0x10000
+
+/* cpu can be held with irq disabled for COUNT * MS  (for create/destroy_ah) */
+#define IONIC_ADMIN_BUSY_RETRY_COUNT	2000
+#define IONIC_ADMIN_BUSY_RETRY_MS	1
+
+/* admin queue will be considered failed if a command takes longer */
+#define IONIC_ADMIN_TIMEOUT	(HZ * 2)
+#define IONIC_ADMIN_WARN	(HZ / 8)
+
+/* will poll for admin cq to tolerate and report from missed event */
+#define IONIC_ADMIN_DELAY	(HZ / 8)
+
+/* work queue for polling the event queue and admin cq */
+struct workqueue_struct *ionic_evt_workq;
+
+static void ionic_admin_timedout(struct ionic_aq *aq)
+{
+	struct ionic_cq *cq = &aq->vcq->cq[0];
+	struct ionic_ibdev *dev = aq->dev;
+	unsigned long irqflags;
+	u16 pos;
+
+	spin_lock_irqsave(&aq->lock, irqflags);
+	if (ionic_queue_empty(&aq->q))
+		goto out;
+
+	/* Reset ALL adminq if any one times out */
+	queue_work(ionic_evt_workq, &dev->reset_work);
+
+	ibdev_err(&dev->ibdev, "admin command timed out, aq %d\n", aq->aqid);
+
+	ibdev_warn(&dev->ibdev, "admin timeout was set for %ums\n",
+		   (u32)jiffies_to_msecs(IONIC_ADMIN_TIMEOUT));
+	ibdev_warn(&dev->ibdev, "admin inactivity for %ums\n",
+		   (u32)jiffies_to_msecs(jiffies - aq->stamp));
+
+	ibdev_warn(&dev->ibdev, "admin commands outstanding %u\n",
+		   ionic_queue_length(&aq->q));
+	ibdev_warn(&dev->ibdev, "%s more commands pending\n",
+		   list_empty(&aq->wr_post) ? "no" : "some");
+
+	pos = cq->q.prod;
+
+	ibdev_warn(&dev->ibdev, "admin cq pos %u (next to complete)\n", pos);
+	print_hex_dump(KERN_WARNING, "cqe ", DUMP_PREFIX_OFFSET, 16, 1,
+		       ionic_queue_at(&cq->q, pos),
+		       BIT(cq->q.stride_log2), true);
+
+	pos = (pos - 1) & cq->q.mask;
+
+	ibdev_warn(&dev->ibdev, "admin cq pos %u (last completed)\n", pos);
+	print_hex_dump(KERN_WARNING, "cqe ", DUMP_PREFIX_OFFSET, 16, 1,
+		       ionic_queue_at(&cq->q, pos),
+		       BIT(cq->q.stride_log2), true);
+
+	pos = aq->q.cons;
+
+	ibdev_warn(&dev->ibdev, "admin pos %u (next to complete)\n", pos);
+	print_hex_dump(KERN_WARNING, "cmd ", DUMP_PREFIX_OFFSET, 16, 1,
+		       ionic_queue_at(&aq->q, pos),
+		       BIT(aq->q.stride_log2), true);
+
+	pos = (aq->q.prod - 1) & aq->q.mask;
+	if (pos == aq->q.cons)
+		goto out;
+
+	ibdev_warn(&dev->ibdev, "admin pos %u (last posted)\n", pos);
+	print_hex_dump(KERN_WARNING, "cmd ", DUMP_PREFIX_OFFSET, 16, 1,
+		       ionic_queue_at(&aq->q, pos),
+		       BIT(aq->q.stride_log2), true);
+
+out:
+	spin_unlock_irqrestore(&aq->lock, irqflags);
+}
+
+static void ionic_admin_reset_dwork(struct ionic_ibdev *dev)
+{
+	if (dev->admin_state < IONIC_ADMIN_KILLED)
+		queue_delayed_work(ionic_evt_workq, &dev->admin_dwork,
+				   IONIC_ADMIN_DELAY);
+}
+
+static void ionic_admin_reset_wdog(struct ionic_aq *aq)
+{
+	aq->stamp = jiffies;
+	ionic_admin_reset_dwork(aq->dev);
+}
+
+static bool ionic_admin_next_cqe(struct ionic_ibdev *dev, struct ionic_cq *cq,
+				 struct ionic_v1_cqe **cqe)
+{
+	struct ionic_v1_cqe *qcqe = ionic_queue_at_prod(&cq->q);
+
+	if (unlikely(cq->color != ionic_v1_cqe_color(qcqe)))
+		return false;
+
+	/* Prevent out-of-order reads of the CQE */
+	rmb();
+
+	ibdev_dbg(&dev->ibdev, "poll admin cq %u prod %u\n",
+		  cq->cqid, cq->q.prod);
+	print_hex_dump_debug("cqe ", DUMP_PREFIX_OFFSET, 16, 1,
+			     qcqe, BIT(cq->q.stride_log2), true);
+	*cqe = qcqe;
+
+	return true;
+}
+
+static void ionic_admin_poll_locked(struct ionic_aq *aq)
+{
+	struct ionic_cq *cq = &aq->vcq->cq[0];
+	struct ionic_admin_wr *wr, *wr_next;
+	struct ionic_ibdev *dev = aq->dev;
+	u32 wr_strides, avlbl_strides;
+	struct ionic_v1_cqe *cqe;
+	u32 qtf, qid;
+	u16 old_prod;
+	u8 type;
+
+	if (dev->admin_state >= IONIC_ADMIN_KILLED) {
+		list_for_each_entry_safe(wr, wr_next, &aq->wr_prod, aq_ent) {
+			INIT_LIST_HEAD(&wr->aq_ent);
+			aq->q_wr[wr->status].wr = NULL;
+			wr->status = dev->admin_state;
+			complete_all(&wr->work);
+		}
+		INIT_LIST_HEAD(&aq->wr_prod);
+
+		list_for_each_entry_safe(wr, wr_next, &aq->wr_post, aq_ent) {
+			INIT_LIST_HEAD(&wr->aq_ent);
+			wr->status = dev->admin_state;
+			complete_all(&wr->work);
+		}
+		INIT_LIST_HEAD(&aq->wr_post);
+
+		return;
+	}
+
+	old_prod = cq->q.prod;
+
+	while (ionic_admin_next_cqe(dev, cq, &cqe)) {
+		qtf = ionic_v1_cqe_qtf(cqe);
+		qid = ionic_v1_cqe_qtf_qid(qtf);
+		type = ionic_v1_cqe_qtf_type(qtf);
+
+		if (unlikely(type != IONIC_V1_CQE_TYPE_ADMIN)) {
+			ibdev_warn_ratelimited(&dev->ibdev,
+					       "bad cqe type %u\n", type);
+			goto cq_next;
+		}
+
+		if (unlikely(qid != aq->aqid)) {
+			ibdev_warn_ratelimited(&dev->ibdev,
+					       "bad cqe qid %u\n", qid);
+			goto cq_next;
+		}
+
+		if (unlikely(be16_to_cpu(cqe->admin.cmd_idx) != aq->q.cons)) {
+			ibdev_warn_ratelimited(&dev->ibdev,
+					       "bad idx %u cons %u qid %u\n",
+					       be16_to_cpu(cqe->admin.cmd_idx),
+					       aq->q.cons, qid);
+			goto cq_next;
+		}
+
+		if (unlikely(ionic_queue_empty(&aq->q))) {
+			ibdev_warn_ratelimited(&dev->ibdev,
+					       "bad cqe for empty adminq\n");
+			goto cq_next;
+		}
+
+		wr = aq->q_wr[aq->q.cons].wr;
+		if (wr) {
+			aq->q_wr[aq->q.cons].wr = NULL;
+			list_del_init(&wr->aq_ent);
+
+			wr->cqe = *cqe;
+			wr->status = dev->admin_state;
+			complete_all(&wr->work);
+		}
+
+		ionic_queue_consume_entries(&aq->q,
+					    aq->q_wr[aq->q.cons].wqe_strides);
+
+cq_next:
+		ionic_queue_produce(&cq->q);
+		cq->color = ionic_color_wrap(cq->q.prod, cq->color);
+	}
+
+	if (old_prod != cq->q.prod) {
+		ionic_admin_reset_wdog(aq);
+		cq->q.cons = cq->q.prod;
+		ionic_dbell_ring(dev->lif_cfg.dbpage, dev->lif_cfg.cq_qtype,
+				 ionic_queue_dbell_val(&cq->q));
+		queue_work(ionic_evt_workq, &aq->work);
+	} else if (!aq->armed) {
+		aq->armed = true;
+		cq->arm_any_prod = ionic_queue_next(&cq->q, cq->arm_any_prod);
+		ionic_dbell_ring(dev->lif_cfg.dbpage, dev->lif_cfg.cq_qtype,
+				 cq->q.dbell | IONIC_CQ_RING_ARM |
+				 cq->arm_any_prod);
+		queue_work(ionic_evt_workq, &aq->work);
+	}
+
+	if (dev->admin_state != IONIC_ADMIN_ACTIVE)
+		return;
+
+	old_prod = aq->q.prod;
+
+	if (ionic_queue_empty(&aq->q) && !list_empty(&aq->wr_post))
+		ionic_admin_reset_wdog(aq);
+
+	if (list_empty(&aq->wr_post))
+		return;
+
+	do {
+		u8 *src;
+		int i, src_len;
+		size_t stride_len;
+
+		wr = list_first_entry(&aq->wr_post, struct ionic_admin_wr,
+				      aq_ent);
+		wr_strides = (wr->wqe.len + ADMIN_WQE_HDR_LEN +
+			     (ADMIN_WQE_STRIDE - 1)) >> aq->q.stride_log2;
+		avlbl_strides = ionic_queue_length_remaining(&aq->q);
+
+		if (wr_strides > avlbl_strides)
+			break;
+
+		list_move(&wr->aq_ent, &aq->wr_prod);
+		wr->status = aq->q.prod;
+		aq->q_wr[aq->q.prod].wr = wr;
+		aq->q_wr[aq->q.prod].wqe_strides = wr_strides;
+
+		src_len = wr->wqe.len;
+		src = (uint8_t *)&wr->wqe.cmd;
+
+		/* First stride */
+		memcpy(ionic_queue_at_prod(&aq->q), &wr->wqe,
+		       ADMIN_WQE_HDR_LEN);
+		stride_len = ADMIN_WQE_STRIDE - ADMIN_WQE_HDR_LEN;
+		if (stride_len > src_len)
+			stride_len = src_len;
+		memcpy(ionic_queue_at_prod(&aq->q) + ADMIN_WQE_HDR_LEN,
+		       src, stride_len);
+		ibdev_dbg(&dev->ibdev, "post admin prod %u (%u strides)\n",
+			  aq->q.prod, wr_strides);
+		print_hex_dump_debug("wqe ", DUMP_PREFIX_OFFSET, 16, 1,
+				     ionic_queue_at_prod(&aq->q),
+				     BIT(aq->q.stride_log2), true);
+		ionic_queue_produce(&aq->q);
+
+		/* Remaining strides */
+		for (i = stride_len; i < src_len; i += stride_len) {
+			stride_len = ADMIN_WQE_STRIDE;
+
+			if (i + stride_len > src_len)
+				stride_len = src_len - i;
+
+			memcpy(ionic_queue_at_prod(&aq->q), src + i,
+			       stride_len);
+			print_hex_dump_debug("wqe ", DUMP_PREFIX_OFFSET, 16, 1,
+					     ionic_queue_at_prod(&aq->q),
+					     BIT(aq->q.stride_log2), true);
+			ionic_queue_produce(&aq->q);
+		}
+	} while (!list_empty(&aq->wr_post));
+
+	if (old_prod != aq->q.prod)
+		ionic_dbell_ring(dev->lif_cfg.dbpage, dev->lif_cfg.aq_qtype,
+				 ionic_queue_dbell_val(&aq->q));
+}
+
+static void ionic_admin_dwork(struct work_struct *ws)
+{
+	struct ionic_ibdev *dev =
+		container_of(ws, struct ionic_ibdev, admin_dwork.work);
+	struct ionic_aq *aq, *bad_aq = NULL;
+	bool do_reschedule = false;
+	unsigned long irqflags;
+	bool do_reset = false;
+	u16 pos;
+	int i;
+
+	for (i = 0; i < dev->lif_cfg.aq_count; i++) {
+		aq = dev->aq_vec[i];
+
+		spin_lock_irqsave(&aq->lock, irqflags);
+
+		if (ionic_queue_empty(&aq->q))
+			goto next_aq;
+
+		/* Reschedule if any queue has outstanding work */
+		do_reschedule = true;
+
+		if (time_is_after_eq_jiffies(aq->stamp + IONIC_ADMIN_WARN))
+			/* Warning threshold not met, nothing to do */
+			goto next_aq;
+
+		/* See if polling now makes some progress */
+		pos = aq->q.cons;
+		ionic_admin_poll_locked(aq);
+		if (pos != aq->q.cons) {
+			ibdev_dbg(&dev->ibdev,
+				  "missed event for acq %d\n", aq->cqid);
+			goto next_aq;
+		}
+
+		if (time_is_after_eq_jiffies(aq->stamp +
+					     IONIC_ADMIN_TIMEOUT)) {
+			/* Timeout threshold not met */
+			ibdev_dbg(&dev->ibdev, "no progress after %ums\n",
+				  (u32)jiffies_to_msecs(jiffies - aq->stamp));
+			goto next_aq;
+		}
+
+		/* Queue timed out */
+		bad_aq = aq;
+		do_reset = true;
+next_aq:
+		spin_unlock_irqrestore(&aq->lock, irqflags);
+	}
+
+	if (do_reset)
+		/* Reset device on a timeout */
+		ionic_admin_timedout(bad_aq);
+	else if (do_reschedule)
+		/* Try to poll again later */
+		ionic_admin_reset_dwork(dev);
+}
+
+static void ionic_admin_work(struct work_struct *ws)
+{
+	struct ionic_aq *aq = container_of(ws, struct ionic_aq, work);
+	unsigned long irqflags;
+
+	spin_lock_irqsave(&aq->lock, irqflags);
+	ionic_admin_poll_locked(aq);
+	spin_unlock_irqrestore(&aq->lock, irqflags);
+}
+
+static void ionic_admin_post_aq(struct ionic_aq *aq, struct ionic_admin_wr *wr)
+{
+	unsigned long irqflags;
+	bool poll;
+
+	wr->status = IONIC_ADMIN_POSTED;
+	wr->aq = aq;
+
+	spin_lock_irqsave(&aq->lock, irqflags);
+	poll = list_empty(&aq->wr_post);
+	list_add(&wr->aq_ent, &aq->wr_post);
+	if (poll)
+		ionic_admin_poll_locked(aq);
+	spin_unlock_irqrestore(&aq->lock, irqflags);
+}
+
+void ionic_admin_post(struct ionic_ibdev *dev, struct ionic_admin_wr *wr)
+{
+	int aq_idx;
+
+	aq_idx = raw_smp_processor_id() % dev->lif_cfg.aq_count;
+	ionic_admin_post_aq(dev->aq_vec[aq_idx], wr);
+}
+
+static void ionic_admin_cancel(struct ionic_admin_wr *wr)
+{
+	struct ionic_aq *aq = wr->aq;
+	unsigned long irqflags;
+
+	spin_lock_irqsave(&aq->lock, irqflags);
+
+	if (!list_empty(&wr->aq_ent)) {
+		list_del(&wr->aq_ent);
+		if (wr->status != IONIC_ADMIN_POSTED)
+			aq->q_wr[wr->status].wr = NULL;
+	}
+
+	spin_unlock_irqrestore(&aq->lock, irqflags);
+}
+
+static int ionic_admin_busy_wait(struct ionic_admin_wr *wr)
+{
+	struct ionic_aq *aq = wr->aq;
+	unsigned long irqflags;
+	int try_i;
+
+	for (try_i = 0; try_i < IONIC_ADMIN_BUSY_RETRY_COUNT; ++try_i) {
+		if (completion_done(&wr->work))
+			return 0;
+
+		mdelay(IONIC_ADMIN_BUSY_RETRY_MS);
+
+		spin_lock_irqsave(&aq->lock, irqflags);
+		ionic_admin_poll_locked(aq);
+		spin_unlock_irqrestore(&aq->lock, irqflags);
+	}
+
+	/*
+	 * we timed out. Initiate RDMA LIF reset and indicate
+	 * error to caller.
+	 */
+	ionic_admin_timedout(aq);
+	return -ETIMEDOUT;
+}
+
+int ionic_admin_wait(struct ionic_ibdev *dev, struct ionic_admin_wr *wr,
+		     enum ionic_admin_flags flags)
+{
+	int rc, timo;
+
+	if (flags & IONIC_ADMIN_F_BUSYWAIT) {
+		/* Spin */
+		rc = ionic_admin_busy_wait(wr);
+	} else if (flags & IONIC_ADMIN_F_INTERRUPT) {
+		/*
+		 * Interruptible sleep, 1s timeout
+		 * This is used for commands which are safe for the caller
+		 * to clean up without killing and resetting the adminq.
+		 */
+		timo = wait_for_completion_interruptible_timeout(&wr->work,
+								 HZ);
+		if (timo > 0)
+			rc = 0;
+		else if (timo == 0)
+			rc = -ETIMEDOUT;
+		else
+			rc = timo;
+	} else {
+		/*
+		 * Uninterruptible sleep
+		 * This is used for commands which are NOT safe for the
+		 * caller to clean up. Cleanup must be handled by the
+		 * adminq kill and reset process so that host memory is
+		 * not corrupted by the device.
+		 */
+		wait_for_completion(&wr->work);
+		rc = 0;
+	}
+
+	if (rc) {
+		ibdev_warn(&dev->ibdev, "wait status %d\n", rc);
+		ionic_admin_cancel(wr);
+	} else if (wr->status == IONIC_ADMIN_KILLED) {
+		ibdev_dbg(&dev->ibdev, "admin killed\n");
+
+		/* No error if admin already killed during teardown */
+		rc = (flags & IONIC_ADMIN_F_TEARDOWN) ? 0 : -ENODEV;
+	} else if (ionic_v1_cqe_error(&wr->cqe)) {
+		ibdev_warn(&dev->ibdev, "opcode %u error %u\n",
+			   wr->wqe.op,
+			   be32_to_cpu(wr->cqe.status_length));
+		rc = -EINVAL;
+	}
+	return rc;
+}
+
+static int ionic_rdma_devcmd(struct ionic_ibdev *dev,
+			     struct ionic_admin_ctx *admin)
+{
+	int rc;
+
+	rc = ionic_adminq_post_wait(dev->lif_cfg.lif, admin);
+	if (rc)
+		return rc;
+
+	return ionic_error_to_errno(admin->comp.comp.status);
+}
+
+int ionic_rdma_reset_devcmd(struct ionic_ibdev *dev)
+{
+	struct ionic_admin_ctx admin = {
+		.work = COMPLETION_INITIALIZER_ONSTACK(admin.work),
+		.cmd.rdma_reset = {
+			.opcode = IONIC_CMD_RDMA_RESET_LIF,
+			.lif_index = cpu_to_le16(dev->lif_cfg.lif_index),
+		},
+	};
+
+	return ionic_rdma_devcmd(dev, &admin);
+}
+
+static int ionic_rdma_queue_devcmd(struct ionic_ibdev *dev,
+				   struct ionic_queue *q,
+				   u32 qid, u32 cid, u16 opcode)
+{
+	struct ionic_admin_ctx admin = {
+		.work = COMPLETION_INITIALIZER_ONSTACK(admin.work),
+		.cmd.rdma_queue = {
+			.opcode = opcode,
+			.lif_index = cpu_to_le16(dev->lif_cfg.lif_index),
+			.qid_ver = cpu_to_le32(qid),
+			.cid = cpu_to_le32(cid),
+			.dbid = cpu_to_le16(dev->lif_cfg.dbid),
+			.depth_log2 = q->depth_log2,
+			.stride_log2 = q->stride_log2,
+			.dma_addr = cpu_to_le64(q->dma),
+		},
+	};
+
+	return ionic_rdma_devcmd(dev, &admin);
+}
+
+static void ionic_rdma_admincq_comp(struct ib_cq *ibcq, void *cq_context)
+{
+	struct ionic_aq *aq = cq_context;
+	unsigned long irqflags;
+
+	spin_lock_irqsave(&aq->lock, irqflags);
+	aq->armed = false;
+	if (aq->dev->admin_state < IONIC_ADMIN_KILLED)
+		queue_work(ionic_evt_workq, &aq->work);
+	spin_unlock_irqrestore(&aq->lock, irqflags);
+}
+
+static void ionic_rdma_admincq_event(struct ib_event *event, void *cq_context)
+{
+	struct ionic_aq *aq = cq_context;
+
+	ibdev_err(&aq->dev->ibdev, "admincq event %d\n", event->event);
+}
+
+static struct ionic_vcq *ionic_create_rdma_admincq(struct ionic_ibdev *dev,
+						   int comp_vector)
+{
+	struct ib_cq_init_attr attr = {
+		.cqe = IONIC_AQ_DEPTH,
+		.comp_vector = comp_vector,
+	};
+	struct ionic_tbl_buf buf = {};
+	struct ionic_vcq *vcq;
+	struct ionic_cq *cq;
+	int rc;
+
+	vcq = kzalloc(sizeof(*vcq), GFP_KERNEL);
+	if (!vcq) {
+		rc = -ENOMEM;
+		goto err_alloc;
+	}
+
+	vcq->ibcq.device = &dev->ibdev;
+	vcq->ibcq.uobject = NULL;
+	vcq->ibcq.comp_handler = ionic_rdma_admincq_comp;
+	vcq->ibcq.event_handler = ionic_rdma_admincq_event;
+	vcq->ibcq.cq_context = NULL;
+	atomic_set(&vcq->ibcq.usecnt, 0);
+
+	vcq->udma_mask = 1;
+	cq = &vcq->cq[0];
+
+	rc = ionic_create_cq_common(vcq, &buf, &attr, NULL, NULL,
+				    NULL, NULL, 0);
+	if (rc)
+		goto err_init;
+
+	rc = ionic_rdma_queue_devcmd(dev, &cq->q, cq->cqid, cq->eqid,
+				     IONIC_CMD_RDMA_CREATE_CQ);
+	if (rc)
+		goto err_cmd;
+
+	return vcq;
+
+err_cmd:
+	ionic_destroy_cq_common(dev, cq);
+err_init:
+	kfree(vcq);
+err_alloc:
+	return ERR_PTR(rc);
+}
+
+static struct ionic_aq *__ionic_create_rdma_adminq(struct ionic_ibdev *dev,
+						   u32 aqid, u32 cqid)
+{
+	struct ionic_aq *aq;
+	int rc;
+
+	aq = kmalloc(sizeof(*aq), GFP_KERNEL);
+	if (!aq) {
+		rc = -ENOMEM;
+		goto err_aq;
+	}
+
+	aq->dev = dev;
+	aq->aqid = aqid;
+	aq->cqid = cqid;
+	spin_lock_init(&aq->lock);
+
+	rc = ionic_queue_init(&aq->q, dev->lif_cfg.hwdev, IONIC_EQ_DEPTH,
+			      ADMIN_WQE_STRIDE);
+	if (rc)
+		goto err_q;
+
+	ionic_queue_dbell_init(&aq->q, aq->aqid);
+
+	aq->q_wr = kcalloc((u32)aq->q.mask + 1, sizeof(*aq->q_wr), GFP_KERNEL);
+	if (!aq->q_wr) {
+		rc = -ENOMEM;
+		goto err_wr;
+	}
+
+	INIT_LIST_HEAD(&aq->wr_prod);
+	INIT_LIST_HEAD(&aq->wr_post);
+
+	INIT_WORK(&aq->work, ionic_admin_work);
+	aq->armed = false;
+
+	return aq;
+
+err_wr:
+	ionic_queue_destroy(&aq->q, dev->lif_cfg.hwdev);
+err_q:
+	kfree(aq);
+err_aq:
+	return ERR_PTR(rc);
+}
+
+static void __ionic_destroy_rdma_adminq(struct ionic_ibdev *dev,
+					struct ionic_aq *aq)
+{
+	ionic_queue_destroy(&aq->q, dev->lif_cfg.hwdev);
+	kfree(aq);
+}
+
+static struct ionic_aq *ionic_create_rdma_adminq(struct ionic_ibdev *dev,
+						 u32 aqid, u32 cqid)
+{
+	struct ionic_aq *aq;
+	int rc;
+
+	aq = __ionic_create_rdma_adminq(dev, aqid, cqid);
+	if (IS_ERR(aq)) {
+		rc = PTR_ERR(aq);
+		goto err_aq;
+	}
+
+	rc = ionic_rdma_queue_devcmd(dev, &aq->q, aq->aqid, aq->cqid,
+				     IONIC_CMD_RDMA_CREATE_ADMINQ);
+	if (rc)
+		goto err_cmd;
+
+	return aq;
+
+err_cmd:
+	__ionic_destroy_rdma_adminq(dev, aq);
+err_aq:
+	return ERR_PTR(rc);
+}
+
+static void ionic_kill_ibdev(struct ionic_ibdev *dev, bool fatal_path)
+{
+	unsigned long irqflags;
+	bool do_flush = false;
+	int i;
+
+	local_irq_save(irqflags);
+
+	/* Mark the admin queue, flushing at most once */
+	for (i = 0; i < dev->lif_cfg.aq_count; i++)
+		spin_lock(&dev->aq_vec[i]->lock);
+
+	if (dev->admin_state != IONIC_ADMIN_KILLED) {
+		dev->admin_state = IONIC_ADMIN_KILLED;
+		do_flush = true;
+	}
+
+	for (i = dev->lif_cfg.aq_count - 1; i >= 0; i--) {
+		/* Flush incomplete admin commands */
+		if (do_flush)
+			ionic_admin_poll_locked(dev->aq_vec[i]);
+		spin_unlock(&dev->aq_vec[i]->lock);
+	}
+
+	local_irq_restore(irqflags);
+
+	/* Post a fatal event if requested */
+	if (fatal_path)
+		ionic_port_event(dev, IB_EVENT_DEVICE_FATAL);
+}
+
+void ionic_kill_rdma_admin(struct ionic_ibdev *dev, bool fatal_path)
+{
+	unsigned long irqflags = 0;
+	bool do_reset = false;
+	int i, rc;
+
+	if (!dev->aq_vec)
+		return;
+
+	local_irq_save(irqflags);
+	for (i = 0; i < dev->lif_cfg.aq_count; i++)
+		spin_lock(&dev->aq_vec[i]->lock);
+
+	/* pause rdma admin queues to reset device */
+	if (dev->admin_state == IONIC_ADMIN_ACTIVE) {
+		dev->admin_state = IONIC_ADMIN_PAUSED;
+		do_reset = true;
+	}
+
+	while (i-- > 0)
+		spin_unlock(&dev->aq_vec[i]->lock);
+	local_irq_restore(irqflags);
+
+	if (!do_reset)
+		return;
+
+	/* After resetting the device, it will be safe to resume the rdma admin
+	 * queues in the killed state.	Commands will not be issued to the
+	 * device, but will complete locally with status IONIC_ADMIN_KILLED.
+	 * Handling completion will ensure that creating or modifying resources
+	 * fails, but destroying resources succeeds.
+	 *
+	 * If there was a failure resetting the device using this strategy,
+	 * then the state of the device is unknown.  The rdma admin queue is
+	 * left here in the paused state.  No new commands are issued to the
+	 * device, nor are any completed locally.  The eth driver will use a
+	 * different strategy to reset the device.  A callback from the eth
+	 * driver will indicate that the reset is done and it is safe to
+	 * continue.  Then, the rdma admin queue will be transitioned to the
+	 * killed state and new and outstanding commands will complete locally.
+	 */
+
+	rc = ionic_rdma_reset_devcmd(dev);
+	if (unlikely(rc)) {
+		ibdev_err(&dev->ibdev, "failed to reset rdma %d\n", rc);
+		ionic_request_rdma_reset(dev->lif_cfg.lif);
+	}
+
+	ionic_kill_ibdev(dev, fatal_path);
+}
+
+static void ionic_reset_work(struct work_struct *ws)
+{
+	struct ionic_ibdev *dev =
+		container_of(ws, struct ionic_ibdev, reset_work);
+
+	ionic_kill_rdma_admin(dev, true);
+}
+
+static bool ionic_next_eqe(struct ionic_eq *eq, struct ionic_v1_eqe *eqe)
+{
+	struct ionic_v1_eqe *qeqe;
+	bool color;
+
+	qeqe = ionic_queue_at_prod(&eq->q);
+	color = ionic_v1_eqe_color(qeqe);
+
+	/* cons is color for eq */
+	if (eq->q.cons != color)
+		return false;
+
+	/* Prevent out-of-order reads of the EQE */
+	rmb();
+
+	ibdev_dbg(&eq->dev->ibdev, "poll eq prod %u\n", eq->q.prod);
+	print_hex_dump_debug("eqe ", DUMP_PREFIX_OFFSET, 16, 1,
+			     qeqe, BIT(eq->q.stride_log2), true);
+	*eqe = *qeqe;
+
+	return true;
+}
+
+static void ionic_cq_event(struct ionic_ibdev *dev, u32 cqid, u8 code)
+{
+	unsigned long irqflags;
+	struct ib_event ibev;
+	struct ionic_cq *cq;
+
+	read_lock_irqsave(&dev->cq_tbl_rw, irqflags);
+	cq = xa_load(&dev->cq_tbl, cqid);
+	if (cq)
+		kref_get(&cq->cq_kref);
+	read_unlock_irqrestore(&dev->cq_tbl_rw, irqflags);
+
+	if (!cq) {
+		ibdev_dbg(&dev->ibdev,
+			  "missing cqid %#x code %u\n", cqid, code);
+		return;
+	}
+
+	switch (code) {
+	case IONIC_V1_EQE_CQ_NOTIFY:
+		if (cq->vcq->ibcq.comp_handler)
+			cq->vcq->ibcq.comp_handler(&cq->vcq->ibcq,
+						   cq->vcq->ibcq.cq_context);
+		break;
+
+	case IONIC_V1_EQE_CQ_ERR:
+		if (cq->vcq->ibcq.event_handler) {
+			ibev.event = IB_EVENT_CQ_ERR;
+			ibev.device = &dev->ibdev;
+			ibev.element.cq = &cq->vcq->ibcq;
+
+			cq->vcq->ibcq.event_handler(&ibev,
+						    cq->vcq->ibcq.cq_context);
+		}
+		break;
+
+	default:
+		ibdev_dbg(&dev->ibdev,
+			  "unrecognized cqid %#x code %u\n", cqid, code);
+		break;
+	}
+
+	kref_put(&cq->cq_kref, ionic_cq_complete);
+}
+
+static u16 ionic_poll_eq(struct ionic_eq *eq, u16 budget)
+{
+	struct ionic_ibdev *dev = eq->dev;
+	struct ionic_v1_eqe eqe;
+	u16 npolled = 0;
+	u8 type, code;
+	u32 evt, qid;
+
+	while (npolled < budget) {
+		if (!ionic_next_eqe(eq, &eqe))
+			break;
+
+		ionic_queue_produce(&eq->q);
+
+		/* cons is color for eq */
+		eq->q.cons = ionic_color_wrap(eq->q.prod, eq->q.cons);
+
+		++npolled;
+
+		evt = ionic_v1_eqe_evt(&eqe);
+		type = ionic_v1_eqe_evt_type(evt);
+		code = ionic_v1_eqe_evt_code(evt);
+		qid = ionic_v1_eqe_evt_qid(evt);
+
+		switch (type) {
+		case IONIC_V1_EQE_TYPE_CQ:
+			ionic_cq_event(dev, qid, code);
+			break;
+
+		default:
+			ibdev_dbg(&dev->ibdev,
+				  "unknown event %#x type %u\n", evt, type);
+		}
+	}
+
+	return npolled;
+}
+
+static void ionic_poll_eq_work(struct work_struct *work)
+{
+	struct ionic_eq *eq = container_of(work, struct ionic_eq, work);
+	u32 npolled;
+
+	if (unlikely(!eq->enable) || WARN_ON(eq->armed))
+		return;
+
+	npolled = ionic_poll_eq(eq, IONIC_EQ_WORK_BUDGET);
+	eq->poll_wq += npolled;
+	if (npolled == 1)
+		eq->poll_wq_single++;
+
+	if (npolled == IONIC_EQ_WORK_BUDGET) {
+		eq->poll_wq_full++;
+		ionic_intr_credits(eq->dev->lif_cfg.intr_ctrl, eq->intr,
+				   npolled, 0);
+		queue_work(ionic_evt_workq, &eq->work);
+	} else {
+		xchg(&eq->armed, true);
+		ionic_intr_credits(eq->dev->lif_cfg.intr_ctrl, eq->intr,
+				   0, IONIC_INTR_CRED_UNMASK);
+	}
+}
+
+static irqreturn_t ionic_poll_eq_isr(int irq, void *eqptr)
+{
+	struct ionic_eq *eq = eqptr;
+	bool was_armed;
+	u32 npolled;
+
+	was_armed = xchg(&eq->armed, false);
+
+	if (unlikely(!eq->enable) || !was_armed)
+		return IRQ_HANDLED;
+
+	npolled = ionic_poll_eq(eq, IONIC_EQ_ISR_BUDGET);
+	eq->poll_isr += npolled;
+	if (npolled == 1)
+		eq->poll_isr_single++;
+
+	if (npolled == IONIC_EQ_ISR_BUDGET) {
+		eq->poll_isr_full++;
+		ionic_intr_credits(eq->dev->lif_cfg.intr_ctrl, eq->intr,
+				   npolled, 0);
+		queue_work(ionic_evt_workq, &eq->work);
+	} else {
+		xchg(&eq->armed, true);
+		ionic_intr_credits(eq->dev->lif_cfg.intr_ctrl, eq->intr,
+				   0, IONIC_INTR_CRED_UNMASK);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static struct ionic_eq *ionic_create_eq(struct ionic_ibdev *dev, int eqid)
+{
+	struct ionic_intr_info intr_obj = { };
+	struct ionic_eq *eq;
+	int rc;
+
+	eq = kzalloc(sizeof(*eq), GFP_KERNEL);
+	if (!eq) {
+		rc = -ENOMEM;
+		goto err_eq;
+	}
+
+	eq->dev = dev;
+
+	rc = ionic_queue_init(&eq->q, dev->lif_cfg.hwdev, IONIC_EQ_DEPTH,
+			      sizeof(struct ionic_v1_eqe));
+	if (rc)
+		goto err_q;
+
+	eq->eqid = eqid;
+
+	eq->armed = true;
+	eq->enable = false;
+	INIT_WORK(&eq->work, ionic_poll_eq_work);
+
+	rc = ionic_intr_alloc(dev->lif_cfg.lif, &intr_obj);
+	if (rc < 0)
+		goto err_intr;
+
+	eq->irq = intr_obj.vector;
+	eq->intr = intr_obj.index;
+
+	ionic_queue_dbell_init(&eq->q, eq->eqid);
+
+	/* cons is color for eq */
+	eq->q.cons = true;
+
+	snprintf(eq->name, sizeof(eq->name), "%s-%d-%d-eq",
+		 DRIVER_SHORTNAME, dev->lif_cfg.lif_index, eq->eqid);
+
+	ionic_intr_mask(dev->lif_cfg.intr_ctrl, eq->intr, IONIC_INTR_MASK_SET);
+	ionic_intr_mask_assert(dev->lif_cfg.intr_ctrl, eq->intr, IONIC_INTR_MASK_SET);
+	ionic_intr_coal_init(dev->lif_cfg.intr_ctrl, eq->intr, 0);
+	ionic_intr_clean(dev->lif_cfg.intr_ctrl, eq->intr);
+
+	eq->enable = true;
+
+	rc = request_irq(eq->irq, ionic_poll_eq_isr, 0, eq->name, eq);
+	if (rc)
+		goto err_irq;
+
+	rc = ionic_rdma_queue_devcmd(dev, &eq->q, eq->eqid, eq->intr,
+				     IONIC_CMD_RDMA_CREATE_EQ);
+	if (rc)
+		goto err_cmd;
+
+	ionic_intr_mask(dev->lif_cfg.intr_ctrl, eq->intr, IONIC_INTR_MASK_CLEAR);
+
+	return eq;
+
+err_cmd:
+	eq->enable = false;
+	flush_work(&eq->work);
+	free_irq(eq->irq, eq);
+err_irq:
+	ionic_intr_free(dev->lif_cfg.lif, eq->intr);
+err_intr:
+	ionic_queue_destroy(&eq->q, dev->lif_cfg.hwdev);
+err_q:
+	kfree(eq);
+err_eq:
+	return ERR_PTR(rc);
+}
+
+static void ionic_destroy_eq(struct ionic_eq *eq)
+{
+	struct ionic_ibdev *dev = eq->dev;
+
+	eq->enable = false;
+	flush_work(&eq->work);
+	free_irq(eq->irq, eq);
+
+	ionic_intr_free(dev->lif_cfg.lif, eq->intr);
+	ionic_queue_destroy(&eq->q, dev->lif_cfg.hwdev);
+	kfree(eq);
+}
+
+int ionic_create_rdma_admin(struct ionic_ibdev *dev)
+{
+	int eq_i = 0, aq_i = 0, rc = 0;
+	struct ionic_vcq *vcq;
+	struct ionic_aq *aq;
+	struct ionic_eq *eq;
+
+	dev->eq_vec = NULL;
+	dev->aq_vec = NULL;
+
+	INIT_WORK(&dev->reset_work, ionic_reset_work);
+	INIT_DELAYED_WORK(&dev->admin_dwork, ionic_admin_dwork);
+	dev->admin_state = IONIC_ADMIN_KILLED;
+
+	if (dev->lif_cfg.aq_count > IONIC_AQ_COUNT) {
+		ibdev_dbg(&dev->ibdev, "limiting adminq count to %d\n",
+			  IONIC_AQ_COUNT);
+		dev->lif_cfg.aq_count = IONIC_AQ_COUNT;
+	}
+
+	if (dev->lif_cfg.eq_count > IONIC_EQ_COUNT) {
+		dev_dbg(&dev->ibdev.dev, "limiting eventq count to %d\n",
+			IONIC_EQ_COUNT);
+		dev->lif_cfg.eq_count = IONIC_EQ_COUNT;
+	}
+
+	/* need at least two eq and one aq */
+	if (dev->lif_cfg.eq_count < IONIC_EQ_COUNT_MIN ||
+	    dev->lif_cfg.aq_count < IONIC_AQ_COUNT_MIN) {
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dev->eq_vec = kmalloc_array(dev->lif_cfg.eq_count, sizeof(*dev->eq_vec),
+				    GFP_KERNEL);
+	if (!dev->eq_vec) {
+		rc = -ENOMEM;
+		goto out;
+	}
+
+	for (eq_i = 0; eq_i < dev->lif_cfg.eq_count; ++eq_i) {
+		eq = ionic_create_eq(dev, eq_i + dev->lif_cfg.eq_base);
+		if (IS_ERR(eq)) {
+			rc = PTR_ERR(eq);
+
+			if (eq_i < IONIC_EQ_COUNT_MIN) {
+				ibdev_err(&dev->ibdev,
+					  "fail create eq %d\n", rc);
+				goto out;
+			}
+
+			/* ok, just fewer eq than device supports */
+			ibdev_dbg(&dev->ibdev, "eq count %d want %d rc %d\n",
+				  eq_i, dev->lif_cfg.eq_count, rc);
+
+			rc = 0;
+			break;
+		}
+
+		dev->eq_vec[eq_i] = eq;
+	}
+
+	dev->lif_cfg.eq_count = eq_i;
+
+	dev->aq_vec = kmalloc_array(dev->lif_cfg.aq_count, sizeof(*dev->aq_vec),
+				    GFP_KERNEL);
+	if (!dev->aq_vec) {
+		rc = -ENOMEM;
+		goto out;
+	}
+
+	/* Create one CQ per AQ */
+	for (aq_i = 0; aq_i < dev->lif_cfg.aq_count; ++aq_i) {
+		vcq = ionic_create_rdma_admincq(dev, aq_i % eq_i);
+		if (IS_ERR(vcq)) {
+			rc = PTR_ERR(vcq);
+
+			if (!aq_i) {
+				ibdev_err(&dev->ibdev,
+					  "failed to create acq %d\n", rc);
+				goto out;
+			}
+
+			/* ok, just fewer adminq than device supports */
+			ibdev_dbg(&dev->ibdev, "acq count %d want %d rc %d\n",
+				  aq_i, dev->lif_cfg.aq_count, rc);
+			break;
+		}
+
+		aq = ionic_create_rdma_adminq(dev, aq_i + dev->lif_cfg.aq_base,
+					      vcq->cq[0].cqid);
+		if (IS_ERR(aq)) {
+			/* Clean up the dangling CQ */
+			ionic_destroy_cq_common(dev, &vcq->cq[0]);
+			kfree(vcq);
+
+			rc = PTR_ERR(aq);
+
+			if (!aq_i) {
+				ibdev_err(&dev->ibdev,
+					  "failed to create aq %d\n", rc);
+				goto out;
+			}
+
+			/* ok, just fewer adminq than device supports */
+			ibdev_dbg(&dev->ibdev, "aq count %d want %d rc %d\n",
+				  aq_i, dev->lif_cfg.aq_count, rc);
+			break;
+		}
+
+		vcq->ibcq.cq_context = aq;
+		aq->vcq = vcq;
+
+		dev->aq_vec[aq_i] = aq;
+	}
+
+	dev->admin_state = IONIC_ADMIN_ACTIVE;
+out:
+	dev->lif_cfg.eq_count = eq_i;
+	dev->lif_cfg.aq_count = aq_i;
+
+	return rc;
+}
+
+void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
+{
+	struct ionic_vcq *vcq;
+	struct ionic_aq *aq;
+	struct ionic_eq *eq;
+
+	cancel_delayed_work_sync(&dev->admin_dwork);
+	cancel_work_sync(&dev->reset_work);
+
+	if (dev->aq_vec) {
+		while (dev->lif_cfg.aq_count > 0) {
+			aq = dev->aq_vec[--dev->lif_cfg.aq_count];
+			vcq = aq->vcq;
+
+			cancel_work_sync(&aq->work);
+
+			__ionic_destroy_rdma_adminq(dev, aq);
+			if (vcq) {
+				ionic_destroy_cq_common(dev, &vcq->cq[0]);
+				kfree(vcq);
+			}
+		}
+
+		kfree(dev->aq_vec);
+	}
+
+	if (dev->eq_vec) {
+		while (dev->lif_cfg.eq_count > 0) {
+			eq = dev->eq_vec[--dev->lif_cfg.eq_count];
+			ionic_destroy_eq(eq);
+		}
+
+		kfree(dev->eq_vec);
+	}
+}
drivers/infiniband/hw/ionic/ionic_controlpath.c new file +191 -0

191 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_fw.h new file +164 -0

164 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_ibdev.c +118 -0

157 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_ibdev.h +245 -0

263 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_pgtbl.c new file +113 -0

113 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_queue.c new file +52 -0

52 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_queue.h new file +234 -0

234 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_res.c new file +42 -0

42 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_res.h new file +182 -0

182 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#14 lore raw

PATCH v2 10/14 RDMA/ionic: Register device ops for control path

In reply to Abhijit Gangurde

Implement device supported verb APIs for control path.

---
 drivers/infiniband/hw/ionic/ionic_admin.c     |   81 +
 .../infiniband/hw/ionic/ionic_controlpath.c   | 2738 +++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_fw.h        |  717 +++++
 drivers/infiniband/hw/ionic/ionic_ibdev.c     |    7 +
 drivers/infiniband/hw/ionic/ionic_ibdev.h     |  219 +-
 drivers/infiniband/hw/ionic/ionic_pgtbl.c     |   19 +
 include/uapi/rdma/ionic-abi.h                 |  115 +
 7 files changed, 3888 insertions(+), 8 deletions(-)
 create mode 100644 include/uapi/rdma/ionic-abi.h
drivers/infiniband/hw/ionic/ionic_admin.c +81 -0
index 5a414c0600a1..72daf03dc418 100644
@@ -685,6 +685,24 @@ static void ionic_kill_ibdev(struct ionic_ibdev *dev, bool fatal_path)
 		spin_unlock(&dev->aq_vec[i]->lock);
 	}
 
+	if (do_flush) {
+		struct ionic_qp *qp;
+		struct ionic_cq *cq;
+		unsigned long index;
+
+		/* Flush qp send and recv */
+		read_lock(&dev->qp_tbl_rw);
+		xa_for_each(&dev->qp_tbl, index, qp)
+			ionic_flush_qp(dev, qp);
+		read_unlock(&dev->qp_tbl_rw);
+
+		/* Notify completions */
+		read_lock(&dev->cq_tbl_rw);
+		xa_for_each(&dev->cq_tbl, index, cq)
+			ionic_notify_flush_cq(cq);
+		read_unlock(&dev->cq_tbl_rw);
+	}
+
 	local_irq_restore(irqflags);
 
 	/* Post a fatal event if requested */
@@ -819,6 +837,65 @@ static void ionic_cq_event(struct ionic_ibdev *dev, u32 cqid, u8 code)
 	kref_put(&cq->cq_kref, ionic_cq_complete);
 }
 
+static void ionic_qp_event(struct ionic_ibdev *dev, u32 qpid, u8 code)
+{
+	unsigned long irqflags;
+	struct ib_event ibev;
+	struct ionic_qp *qp;
+
+	read_lock_irqsave(&dev->qp_tbl_rw, irqflags);
+	qp = xa_load(&dev->qp_tbl, qpid);
+	if (qp)
+		kref_get(&qp->qp_kref);
+	read_unlock_irqrestore(&dev->qp_tbl_rw, irqflags);
+
+	if (!qp) {
+		ibdev_dbg(&dev->ibdev,
+			  "missing qpid %#x code %u\n", qpid, code);
+		return;
+	}
+
+	ibev.device = &dev->ibdev;
+	ibev.element.qp = &qp->ibqp;
+
+	switch (code) {
+	case IONIC_V1_EQE_SQ_DRAIN:
+		ibev.event = IB_EVENT_SQ_DRAINED;
+		break;
+
+	case IONIC_V1_EQE_QP_COMM_EST:
+		ibev.event = IB_EVENT_COMM_EST;
+		break;
+
+	case IONIC_V1_EQE_QP_LAST_WQE:
+		ibev.event = IB_EVENT_QP_LAST_WQE_REACHED;
+		break;
+
+	case IONIC_V1_EQE_QP_ERR:
+		ibev.event = IB_EVENT_QP_FATAL;
+		break;
+
+	case IONIC_V1_EQE_QP_ERR_REQUEST:
+		ibev.event = IB_EVENT_QP_REQ_ERR;
+		break;
+
+	case IONIC_V1_EQE_QP_ERR_ACCESS:
+		ibev.event = IB_EVENT_QP_ACCESS_ERR;
+		break;
+
+	default:
+		ibdev_dbg(&dev->ibdev,
+			  "unrecognized qpid %#x code %u\n", qpid, code);
+		goto out;
+	}
+
+	if (qp->ibqp.event_handler)
+		qp->ibqp.event_handler(&ibev, qp->ibqp.qp_context);
+
+out:
+	kref_put(&qp->qp_kref, ionic_qp_complete);
+}
+
 static u16 ionic_poll_eq(struct ionic_eq *eq, u16 budget)
 {
 	struct ionic_ibdev *dev = eq->dev;
@@ -848,6 +925,10 @@ static u16 ionic_poll_eq(struct ionic_eq *eq, u16 budget)
 			ionic_cq_event(dev, qid, code);
 			break;
 
+		case IONIC_V1_EQE_TYPE_QP:
+			ionic_qp_event(dev, qid, code);
+			break;
+
 		default:
 			ibdev_dbg(&dev->ibdev,
 				  "unknown event %#x type %u\n", evt, type);
drivers/infiniband/hw/ionic/ionic_controlpath.c +2738 -0

2,749 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_fw.h +717 -0

152 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_ibdev.c +7 -0
index 21d2820f36ce..358645881a24 100644

Lines of this file are not shown. View the raw message.

drivers/infiniband/hw/ionic/ionic_ibdev.h +211 -8

219 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_pgtbl.c +19 -0
index 11461f7642bc..a8eb73be6f86 100644

Lines of this file are not shown. View the raw message.

include/uapi/rdma/ionic-abi.h new file +115 -0

115 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.34.1

Part of the diff is not shown here. View the raw message.

author maintainer
#15 lore raw

PATCH v2 11/14 RDMA/ionic: Register device ops for datapath

In reply to Abhijit Gangurde

Implement device supported verb APIs for datapath.

---
 drivers/infiniband/hw/ionic/ionic_datapath.c | 1422 ++++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_fw.h       |  107 ++
 drivers/infiniband/hw/ionic/ionic_ibdev.c    |    1 +
 drivers/infiniband/hw/ionic/ionic_ibdev.h    |    9 +
 drivers/infiniband/hw/ionic/ionic_pgtbl.c    |   11 +
 5 files changed, 1550 insertions(+)
 create mode 100644 drivers/infiniband/hw/ionic/ionic_datapath.c
drivers/infiniband/hw/ionic/ionic_datapath.c new file +1422 -0
new file mode 100644
index 000000000000..1262ba30172d
@@ -0,0 +1,1422 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
+
+#include <linux/module.h>
+#include <linux/printk.h>
+#include <rdma/ib_addr.h>
+#include <rdma/ib_user_verbs.h>
+
+#include "ionic_fw.h"
+#include "ionic_ibdev.h"
+
+#define IONIC_OP(version, opname) \
+	((version) < 2 ? IONIC_V1_OP_##opname : IONIC_V2_OP_##opname)
+
+static bool ionic_next_cqe(struct ionic_ibdev *dev, struct ionic_cq *cq,
+			   struct ionic_v1_cqe **cqe)
+{
+	struct ionic_v1_cqe *qcqe = ionic_queue_at_prod(&cq->q);
+
+	if (unlikely(cq->color != ionic_v1_cqe_color(qcqe)))
+		return false;
+
+	/* Prevent out-of-order reads of the CQE */
+	rmb();
+
+	*cqe = qcqe;
+
+	return true;
+}
+
+static int ionic_flush_recv(struct ionic_qp *qp, struct ib_wc *wc)
+{
+	struct ionic_rq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+
+	if (!qp->rq_flush)
+		return 0;
+
+	if (ionic_queue_empty(&qp->rq))
+		return 0;
+
+	wqe = ionic_queue_at_cons(&qp->rq);
+
+	/* wqe_id must be a valid queue index */
+	if (unlikely(wqe->base.wqe_id >> qp->rq.depth_log2)) {
+		ibdev_warn(qp->ibqp.device,
+			   "flush qp %u recv index %llu invalid\n",
+			   qp->qpid, (unsigned long long)wqe->base.wqe_id);
+		return -EIO;
+	}
+
+	/* wqe_id must indicate a request that is outstanding */
+	meta = &qp->rq_meta[wqe->base.wqe_id];
+	if (unlikely(meta->next != IONIC_META_POSTED)) {
+		ibdev_warn(qp->ibqp.device,
+			   "flush qp %u recv index %llu not posted\n",
+			   qp->qpid, (unsigned long long)wqe->base.wqe_id);
+		return -EIO;
+	}
+
+	ionic_queue_consume(&qp->rq);
+
+	memset(wc, 0, sizeof(*wc));
+
+	wc->status = IB_WC_WR_FLUSH_ERR;
+	wc->wr_id = meta->wrid;
+	wc->qp = &qp->ibqp;
+
+	meta->next = qp->rq_meta_head;
+	qp->rq_meta_head = meta;
+
+	return 1;
+}
+
+static int ionic_flush_recv_many(struct ionic_qp *qp,
+				 struct ib_wc *wc, int nwc)
+{
+	int rc = 0, npolled = 0;
+
+	while (npolled < nwc) {
+		rc = ionic_flush_recv(qp, wc + npolled);
+		if (rc <= 0)
+			break;
+
+		npolled += rc;
+	}
+
+	return npolled ?: rc;
+}
+
+static int ionic_flush_send(struct ionic_qp *qp, struct ib_wc *wc)
+{
+	struct ionic_sq_meta *meta;
+
+	if (!qp->sq_flush)
+		return 0;
+
+	if (ionic_queue_empty(&qp->sq))
+		return 0;
+
+	meta = &qp->sq_meta[qp->sq.cons];
+
+	ionic_queue_consume(&qp->sq);
+
+	memset(wc, 0, sizeof(*wc));
+
+	wc->status = IB_WC_WR_FLUSH_ERR;
+	wc->wr_id = meta->wrid;
+	wc->qp = &qp->ibqp;
+
+	return 1;
+}
+
+static int ionic_flush_send_many(struct ionic_qp *qp,
+				 struct ib_wc *wc, int nwc)
+{
+	int rc = 0, npolled = 0;
+
+	while (npolled < nwc) {
+		rc = ionic_flush_send(qp, wc + npolled);
+		if (rc <= 0)
+			break;
+
+		npolled += rc;
+	}
+
+	return npolled ?: rc;
+}
+
+static int ionic_poll_recv(struct ionic_ibdev *dev, struct ionic_cq *cq,
+			   struct ionic_qp *cqe_qp, struct ionic_v1_cqe *cqe,
+			   struct ib_wc *wc)
+{
+	struct ionic_qp *qp = NULL;
+	struct ionic_rq_meta *meta;
+	u32 src_qpn, st_len;
+	u16 vlan_tag;
+	u8 op;
+
+	if (cqe_qp->rq_flush)
+		return 0;
+
+	qp = cqe_qp;
+
+	st_len = be32_to_cpu(cqe->status_length);
+
+	/* ignore wqe_id in case of flush error */
+	if (ionic_v1_cqe_error(cqe) && st_len == IONIC_STS_WQE_FLUSHED_ERR) {
+		cqe_qp->rq_flush = true;
+		cq->flush = true;
+		list_move_tail(&qp->cq_flush_rq, &cq->flush_rq);
+
+		/* posted recvs (if any) flushed by ionic_flush_recv */
+		return 0;
+	}
+
+	/* there had better be something in the recv queue to complete */
+	if (ionic_queue_empty(&qp->rq)) {
+		ibdev_warn(&dev->ibdev, "qp %u is empty\n", qp->qpid);
+		return -EIO;
+	}
+
+	/* wqe_id must be a valid queue index */
+	if (unlikely(cqe->recv.wqe_id >> qp->rq.depth_log2)) {
+		ibdev_warn(&dev->ibdev,
+			   "qp %u recv index %llu invalid\n",
+			   qp->qpid, (unsigned long long)cqe->recv.wqe_id);
+		return -EIO;
+	}
+
+	/* wqe_id must indicate a request that is outstanding */
+	meta = &qp->rq_meta[cqe->recv.wqe_id];
+	if (unlikely(meta->next != IONIC_META_POSTED)) {
+		ibdev_warn(&dev->ibdev,
+			   "qp %u recv index %llu not posted\n",
+			   qp->qpid, (unsigned long long)cqe->recv.wqe_id);
+		return -EIO;
+	}
+
+	meta->next = qp->rq_meta_head;
+	qp->rq_meta_head = meta;
+
+	memset(wc, 0, sizeof(*wc));
+
+	wc->wr_id = meta->wrid;
+
+	wc->qp = &cqe_qp->ibqp;
+
+	if (ionic_v1_cqe_error(cqe)) {
+		wc->vendor_err = st_len;
+		wc->status = ionic_to_ib_status(st_len);
+
+		cqe_qp->rq_flush = true;
+		cq->flush = true;
+		list_move_tail(&qp->cq_flush_rq, &cq->flush_rq);
+
+		ibdev_warn(&dev->ibdev,
+			   "qp %d recv cqe with error\n", qp->qpid);
+		print_hex_dump(KERN_WARNING, "cqe ", DUMP_PREFIX_OFFSET, 16, 1,
+			       cqe, BIT(cq->q.stride_log2), true);
+		goto out;
+	}
+
+	wc->vendor_err = 0;
+	wc->status = IB_WC_SUCCESS;
+
+	src_qpn = be32_to_cpu(cqe->recv.src_qpn_op);
+	op = src_qpn >> IONIC_V1_CQE_RECV_OP_SHIFT;
+
+	src_qpn &= IONIC_V1_CQE_RECV_QPN_MASK;
+	op &= IONIC_V1_CQE_RECV_OP_MASK;
+
+	wc->opcode = IB_WC_RECV;
+	switch (op) {
+	case IONIC_V1_CQE_RECV_OP_RDMA_IMM:
+		wc->opcode = IB_WC_RECV_RDMA_WITH_IMM;
+		wc->wc_flags |= IB_WC_WITH_IMM;
+		wc->ex.imm_data = cqe->recv.imm_data_rkey; /* be32 in wc */
+		break;
+	case IONIC_V1_CQE_RECV_OP_SEND_IMM:
+		wc->wc_flags |= IB_WC_WITH_IMM;
+		wc->ex.imm_data = cqe->recv.imm_data_rkey; /* be32 in wc */
+		break;
+	case IONIC_V1_CQE_RECV_OP_SEND_INV:
+		wc->wc_flags |= IB_WC_WITH_INVALIDATE;
+		wc->ex.invalidate_rkey = be32_to_cpu(cqe->recv.imm_data_rkey);
+		break;
+	}
+
+	wc->byte_len = st_len;
+	wc->src_qp = src_qpn;
+
+	if (qp->ibqp.qp_type == IB_QPT_UD ||
+	    qp->ibqp.qp_type == IB_QPT_GSI) {
+		wc->wc_flags |= IB_WC_GRH | IB_WC_WITH_SMAC;
+		ether_addr_copy(wc->smac, cqe->recv.src_mac);
+
+		wc->wc_flags |= IB_WC_WITH_NETWORK_HDR_TYPE;
+		if (ionic_v1_cqe_recv_is_ipv4(cqe))
+			wc->network_hdr_type = RDMA_NETWORK_IPV4;
+		else
+			wc->network_hdr_type = RDMA_NETWORK_IPV6;
+
+		if (ionic_v1_cqe_recv_is_vlan(cqe))
+			wc->wc_flags |= IB_WC_WITH_VLAN;
+
+		/* vlan_tag in cqe will be valid from dpath even if no vlan */
+		vlan_tag = be16_to_cpu(cqe->recv.vlan_tag);
+		wc->vlan_id = vlan_tag & 0xfff; /* 802.1q VID */
+		wc->sl = vlan_tag >> VLAN_PRIO_SHIFT; /* 802.1q PCP */
+	}
+
+	wc->pkey_index = 0;
+	wc->port_num = 1;
+
+out:
+	ionic_queue_consume(&qp->rq);
+
+	return 1;
+}
+
+static bool ionic_peek_send(struct ionic_qp *qp)
+{
+	struct ionic_sq_meta *meta;
+
+	if (qp->sq_flush)
+		return false;
+
+	/* completed all send queue requests */
+	if (ionic_queue_empty(&qp->sq))
+		return false;
+
+	meta = &qp->sq_meta[qp->sq.cons];
+
+	/* waiting for remote completion */
+	if (meta->remote && meta->seq == qp->sq_msn_cons)
+		return false;
+
+	/* waiting for local completion */
+	if (!meta->remote && !meta->local_comp)
+		return false;
+
+	return true;
+}
+
+static int ionic_poll_send(struct ionic_ibdev *dev, struct ionic_cq *cq,
+			   struct ionic_qp *qp, struct ib_wc *wc)
+{
+	struct ionic_sq_meta *meta;
+
+	if (qp->sq_flush)
+		return 0;
+
+	do {
+		/* completed all send queue requests */
+		if (ionic_queue_empty(&qp->sq))
+			goto out_empty;
+
+		meta = &qp->sq_meta[qp->sq.cons];
+
+		/* waiting for remote completion */
+		if (meta->remote && meta->seq == qp->sq_msn_cons)
+			goto out_empty;
+
+		/* waiting for local completion */
+		if (!meta->remote && !meta->local_comp)
+			goto out_empty;
+
+		ionic_queue_consume(&qp->sq);
+
+		/* produce wc only if signaled or error status */
+	} while (!meta->signal && meta->ibsts == IB_WC_SUCCESS);
+
+	memset(wc, 0, sizeof(*wc));
+
+	wc->status = meta->ibsts;
+	wc->wr_id = meta->wrid;
+	wc->qp = &qp->ibqp;
+
+	if (meta->ibsts == IB_WC_SUCCESS) {
+		wc->byte_len = meta->len;
+		wc->opcode = meta->ibop;
+	} else {
+		wc->vendor_err = meta->len;
+
+		qp->sq_flush = true;
+		cq->flush = true;
+		list_move_tail(&qp->cq_flush_sq, &cq->flush_sq);
+	}
+
+	return 1;
+
+out_empty:
+	if (qp->sq_flush_rcvd) {
+		qp->sq_flush = true;
+		cq->flush = true;
+		list_move_tail(&qp->cq_flush_sq, &cq->flush_sq);
+	}
+	return 0;
+}
+
+static int ionic_poll_send_many(struct ionic_ibdev *dev, struct ionic_cq *cq,
+				struct ionic_qp *qp, struct ib_wc *wc, int nwc)
+{
+	int rc = 0, npolled = 0;
+
+	while (npolled < nwc) {
+		rc = ionic_poll_send(dev, cq, qp, wc + npolled);
+		if (rc <= 0)
+			break;
+
+		npolled += rc;
+	}
+
+	return npolled ?: rc;
+}
+
+static int ionic_validate_cons(u16 prod, u16 cons,
+			       u16 comp, u16 mask)
+{
+	if (((prod - cons) & mask) <= ((comp - cons) & mask))
+		return -EIO;
+
+	return 0;
+}
+
+static int ionic_comp_msn(struct ionic_qp *qp, struct ionic_v1_cqe *cqe)
+{
+	struct ionic_sq_meta *meta;
+	u16 cqe_seq, cqe_idx;
+	int rc;
+
+	if (qp->sq_flush)
+		return 0;
+
+	cqe_seq = be32_to_cpu(cqe->send.msg_msn) & qp->sq.mask;
+
+	rc = ionic_validate_cons(qp->sq_msn_prod,
+				 qp->sq_msn_cons,
+				 cqe_seq - 1,
+				 qp->sq.mask);
+	if (rc) {
+		ibdev_warn(qp->ibqp.device,
+			   "qp %u bad msn %#x seq %u for prod %u cons %u\n",
+			   qp->qpid, be32_to_cpu(cqe->send.msg_msn),
+			   cqe_seq, qp->sq_msn_prod, qp->sq_msn_cons);
+		return rc;
+	}
+
+	qp->sq_msn_cons = cqe_seq;
+
+	if (ionic_v1_cqe_error(cqe)) {
+		cqe_idx = qp->sq_msn_idx[(cqe_seq - 1) & qp->sq.mask];
+
+		meta = &qp->sq_meta[cqe_idx];
+		meta->len = be32_to_cpu(cqe->status_length);
+		meta->ibsts = ionic_to_ib_status(meta->len);
+
+		ibdev_warn(qp->ibqp.device,
+			   "qp %d msn cqe with error\n", qp->qpid);
+		print_hex_dump(KERN_WARNING, "cqe ", DUMP_PREFIX_OFFSET, 16, 1,
+			       cqe, sizeof(*cqe), true);
+	}
+
+	return 0;
+}
+
+static int ionic_comp_npg(struct ionic_qp *qp, struct ionic_v1_cqe *cqe)
+{
+	struct ionic_sq_meta *meta;
+	u16 cqe_idx;
+	u32 st_len;
+
+	if (qp->sq_flush)
+		return 0;
+
+	st_len = be32_to_cpu(cqe->status_length);
+
+	if (ionic_v1_cqe_error(cqe) && st_len == IONIC_STS_WQE_FLUSHED_ERR) {
+		/*
+		 * Flush cqe does not consume a wqe on the device, and maybe
+		 * no such work request is posted.
+		 *
+		 * The driver should begin flushing after the last indicated
+		 * normal or error completion.	Here, only set a hint that the
+		 * flush request was indicated.	 In poll_send, if nothing more
+		 * can be polled normally, then begin flushing.
+		 */
+		qp->sq_flush_rcvd = true;
+		return 0;
+	}
+
+	cqe_idx = cqe->send.npg_wqe_id & qp->sq.mask;
+	meta = &qp->sq_meta[cqe_idx];
+	meta->local_comp = true;
+
+	if (ionic_v1_cqe_error(cqe)) {
+		meta->len = st_len;
+		meta->ibsts = ionic_to_ib_status(st_len);
+		meta->remote = false;
+		ibdev_warn(qp->ibqp.device,
+			   "qp %d npg cqe with error\n", qp->qpid);
+		print_hex_dump(KERN_WARNING, "cqe ", DUMP_PREFIX_OFFSET, 16, 1,
+			       cqe, sizeof(*cqe), true);
+	}
+
+	return 0;
+}
+
+static void ionic_reserve_sync_cq(struct ionic_ibdev *dev, struct ionic_cq *cq)
+{
+	if (!ionic_queue_empty(&cq->q)) {
+		cq->reserve += ionic_queue_length(&cq->q);
+		cq->q.cons = cq->q.prod;
+
+		ionic_dbell_ring(dev->lif_cfg.dbpage, dev->lif_cfg.cq_qtype,
+				 ionic_queue_dbell_val(&cq->q));
+	}
+}
+
+static void ionic_reserve_cq(struct ionic_ibdev *dev, struct ionic_cq *cq,
+			     int spend)
+{
+	cq->reserve -= spend;
+
+	if (cq->reserve <= 0)
+		ionic_reserve_sync_cq(dev, cq);
+}
+
+static int ionic_poll_vcq_cq(struct ionic_ibdev *dev,
+			     struct ionic_cq *cq,
+			     int nwc, struct ib_wc *wc)
+{
+	struct ionic_qp *qp, *qp_next;
+	struct ionic_v1_cqe *cqe;
+	int rc = 0, npolled = 0;
+	unsigned long irqflags;
+	u32 qtf, qid;
+	bool peek;
+	u8 type;
+
+	if (nwc < 1)
+		return 0;
+
+	spin_lock_irqsave(&cq->lock, irqflags);
+
+	/* poll already indicated work completions for send queue */
+	list_for_each_entry_safe(qp, qp_next, &cq->poll_sq, cq_poll_sq) {
+		if (npolled == nwc)
+			goto out;
+
+		spin_lock(&qp->sq_lock);
+		rc = ionic_poll_send_many(dev, cq, qp, wc + npolled,
+					  nwc - npolled);
+		spin_unlock(&qp->sq_lock);
+
+		if (rc > 0)
+			npolled += rc;
+
+		if (npolled < nwc)
+			list_del_init(&qp->cq_poll_sq);
+	}
+
+	/* poll for more work completions */
+	while (likely(ionic_next_cqe(dev, cq, &cqe))) {
+		if (npolled == nwc)
+			goto out;
+
+		qtf = ionic_v1_cqe_qtf(cqe);
+		qid = ionic_v1_cqe_qtf_qid(qtf);
+		type = ionic_v1_cqe_qtf_type(qtf);
+
+		qp = xa_load(&dev->qp_tbl, qid);
+		if (unlikely(!qp)) {
+			ibdev_dbg(&dev->ibdev, "missing qp for qid %u\n", qid);
+			goto cq_next;
+		}
+
+		switch (type) {
+		case IONIC_V1_CQE_TYPE_RECV:
+			spin_lock(&qp->rq_lock);
+			rc = ionic_poll_recv(dev, cq, qp, cqe, wc + npolled);
+			spin_unlock(&qp->rq_lock);
+
+			if (rc < 0)
+				goto out;
+
+			npolled += rc;
+
+			break;
+
+		case IONIC_V1_CQE_TYPE_SEND_MSN:
+			spin_lock(&qp->sq_lock);
+			rc = ionic_comp_msn(qp, cqe);
+			if (!rc) {
+				rc = ionic_poll_send_many(dev, cq, qp,
+							  wc + npolled,
+							  nwc - npolled);
+				peek = ionic_peek_send(qp);
+			}
+			spin_unlock(&qp->sq_lock);
+
+			if (rc < 0)
+				goto out;
+
+			npolled += rc;
+
+			if (peek)
+				list_move_tail(&qp->cq_poll_sq, &cq->poll_sq);
+			break;
+
+		case IONIC_V1_CQE_TYPE_SEND_NPG:
+			spin_lock(&qp->sq_lock);
+			rc = ionic_comp_npg(qp, cqe);
+			if (!rc) {
+				rc = ionic_poll_send_many(dev, cq, qp,
+							  wc + npolled,
+							  nwc - npolled);
+				peek = ionic_peek_send(qp);
+			}
+			spin_unlock(&qp->sq_lock);
+
+			if (rc < 0)
+				goto out;
+
+			npolled += rc;
+
+			if (peek)
+				list_move_tail(&qp->cq_poll_sq, &cq->poll_sq);
+			break;
+
+		default:
+			ibdev_warn(&dev->ibdev,
+				   "unexpected cqe type %u\n", type);
+			rc = -EIO;
+			goto out;
+		}
+
+cq_next:
+		ionic_queue_produce(&cq->q);
+		cq->color = ionic_color_wrap(cq->q.prod, cq->color);
+	}
+
+	/* lastly, flush send and recv queues */
+	if (likely(!cq->flush))
+		goto out;
+
+	cq->flush = false;
+
+	list_for_each_entry_safe(qp, qp_next, &cq->flush_sq, cq_flush_sq) {
+		if (npolled == nwc)
+			goto out;
+
+		spin_lock(&qp->sq_lock);
+		rc = ionic_flush_send_many(qp, wc + npolled, nwc - npolled);
+		spin_unlock(&qp->sq_lock);
+
+		if (rc > 0)
+			npolled += rc;
+
+		if (npolled < nwc)
+			list_del_init(&qp->cq_flush_sq);
+		else
+			cq->flush = true;
+	}
+
+	list_for_each_entry_safe(qp, qp_next, &cq->flush_rq, cq_flush_rq) {
+		if (npolled == nwc)
+			goto out;
+
+		spin_lock(&qp->rq_lock);
+		rc = ionic_flush_recv_many(qp, wc + npolled, nwc - npolled);
+		spin_unlock(&qp->rq_lock);
+
+		if (rc > 0)
+			npolled += rc;
+
+		if (npolled < nwc)
+			list_del_init(&qp->cq_flush_rq);
+		else
+			cq->flush = true;
+	}
+
+out:
+	/* in case reserve was depleted (more work posted than cq depth) */
+	if (cq->reserve <= 0)
+		ionic_reserve_sync_cq(dev, cq);
+
+	spin_unlock_irqrestore(&cq->lock, irqflags);
+
+	return npolled ?: rc;
+}
+
+static int ionic_poll_cq(struct ib_cq *ibcq, int nwc, struct ib_wc *wc)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibcq->device);
+	struct ionic_vcq *vcq = to_ionic_vcq(ibcq);
+	int rc_tmp, rc = 0, npolled = 0;
+	int cq_i, cq_x, cq_ix;
+
+	/* poll_idx is not protected by a lock, but a race is benign */
+	cq_x = vcq->poll_idx;
+
+	vcq->poll_idx ^= dev->lif_cfg.udma_count - 1;
+
+	for (cq_i = 0; npolled < nwc && cq_i < dev->lif_cfg.udma_count; ++cq_i) {
+		cq_ix = cq_i ^ cq_x;
+
+		if (!(vcq->udma_mask & BIT(cq_ix)))
+			continue;
+
+		rc_tmp = ionic_poll_vcq_cq(dev, &vcq->cq[cq_ix],
+					   nwc - npolled,
+					   wc + npolled);
+
+		if (rc_tmp >= 0)
+			npolled += rc_tmp;
+		else if (!rc)
+			rc = rc_tmp;
+	}
+
+	return npolled ?: rc;
+}
+
+static int ionic_req_notify_vcq_cq(struct ionic_ibdev *dev, struct ionic_cq *cq,
+				   enum ib_cq_notify_flags flags)
+{
+	u64 dbell_val = cq->q.dbell;
+
+	if (flags & IB_CQ_SOLICITED) {
+		cq->arm_sol_prod = ionic_queue_next(&cq->q, cq->arm_sol_prod);
+		dbell_val |= cq->arm_sol_prod | IONIC_CQ_RING_SOL;
+	} else {
+		cq->arm_any_prod = ionic_queue_next(&cq->q, cq->arm_any_prod);
+		dbell_val |= cq->arm_any_prod | IONIC_CQ_RING_ARM;
+	}
+
+	ionic_reserve_sync_cq(dev, cq);
+
+	ionic_dbell_ring(dev->lif_cfg.dbpage, dev->lif_cfg.cq_qtype, dbell_val);
+
+	/*
+	 * IB_CQ_REPORT_MISSED_EVENTS:
+	 *
+	 * The queue index in ring zero guarantees no missed events.
+	 *
+	 * Here, we check if the color bit in the next cqe is flipped.	If it
+	 * is flipped, then progress can be made by immediately polling the cq.
+	 * Still, the cq will be armed, and an event will be generated.	 The cq
+	 * may be empty when polled after the event, because the next poll
+	 * after arming the cq can empty it.
+	 */
+	return (flags & IB_CQ_REPORT_MISSED_EVENTS) &&
+		cq->color == ionic_v1_cqe_color(ionic_queue_at_prod(&cq->q));
+}
+
+static int ionic_req_notify_cq(struct ib_cq *ibcq,
+			       enum ib_cq_notify_flags flags)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibcq->device);
+	struct ionic_vcq *vcq = to_ionic_vcq(ibcq);
+	int rc = 0, cq_i;
+
+	for (cq_i = 0; cq_i < dev->lif_cfg.udma_count; ++cq_i) {
+		if (!(vcq->udma_mask & BIT(cq_i)))
+			continue;
+
+		if (ionic_req_notify_vcq_cq(dev, &vcq->cq[cq_i], flags))
+			rc = 1;
+	}
+
+	return rc;
+}
+
+static s64 ionic_prep_inline(void *data, u32 max_data,
+			     const struct ib_sge *ib_sgl, int num_sge)
+{
+	static const s64 bit_31 = 1u << 31;
+	s64 len = 0, sg_len;
+	int sg_i;
+
+	for (sg_i = 0; sg_i < num_sge; ++sg_i) {
+		sg_len = ib_sgl[sg_i].length;
+
+		/* sge length zero means 2GB */
+		if (unlikely(sg_len == 0))
+			sg_len = bit_31;
+
+		/* greater than max inline data is invalid */
+		if (unlikely(len + sg_len > max_data))
+			return -EINVAL;
+
+		memcpy(data + len, (void *)ib_sgl[sg_i].addr, sg_len);
+
+		len += sg_len;
+	}
+
+	return len;
+}
+
+static s64 ionic_prep_pld(struct ionic_v1_wqe *wqe,
+			  union ionic_v1_pld *pld,
+			  int spec, u32 max_sge,
+			  const struct ib_sge *ib_sgl,
+			  int num_sge)
+{
+	static const s64 bit_31 = 1l << 31;
+	struct ionic_sge *sgl;
+	__be32 *spec32 = NULL;
+	__be16 *spec16 = NULL;
+	s64 len = 0, sg_len;
+	int sg_i = 0;
+
+	if (unlikely(num_sge < 0 || (u32)num_sge > max_sge))
+		return -EINVAL;
+
+	if (spec && num_sge > IONIC_V1_SPEC_FIRST_SGE) {
+		sg_i = IONIC_V1_SPEC_FIRST_SGE;
+
+		if (num_sge > 8) {
+			wqe->base.flags |= cpu_to_be16(IONIC_V1_FLAG_SPEC16);
+			spec16 = pld->spec16;
+		} else {
+			wqe->base.flags |= cpu_to_be16(IONIC_V1_FLAG_SPEC32);
+			spec32 = pld->spec32;
+		}
+	}
+
+	sgl = &pld->sgl[sg_i];
+
+	for (sg_i = 0; sg_i < num_sge; ++sg_i) {
+		sg_len = ib_sgl[sg_i].length;
+
+		/* sge length zero means 2GB */
+		if (unlikely(sg_len == 0))
+			sg_len = bit_31;
+
+		/* greater than 2GB data is invalid */
+		if (unlikely(len + sg_len > bit_31))
+			return -EINVAL;
+
+		sgl[sg_i].va = cpu_to_be64(ib_sgl[sg_i].addr);
+		sgl[sg_i].len = cpu_to_be32(sg_len);
+		sgl[sg_i].lkey = cpu_to_be32(ib_sgl[sg_i].lkey);
+
+		if (spec32) {
+			spec32[sg_i] = sgl[sg_i].len;
+		} else if (spec16) {
+			if (unlikely(sg_len > U16_MAX))
+				return -EINVAL;
+			spec16[sg_i] = cpu_to_be16(sg_len);
+		}
+
+		len += sg_len;
+	}
+
+	return len;
+}
+
+static void ionic_prep_base(struct ionic_qp *qp,
+			    const struct ib_send_wr *wr,
+			    struct ionic_sq_meta *meta,
+			    struct ionic_v1_wqe *wqe)
+{
+	meta->wrid = wr->wr_id;
+	meta->ibsts = IB_WC_SUCCESS;
+	meta->signal = false;
+	meta->local_comp = false;
+
+	wqe->base.wqe_id = qp->sq.prod;
+
+	if (wr->send_flags & IB_SEND_FENCE)
+		wqe->base.flags |= cpu_to_be16(IONIC_V1_FLAG_FENCE);
+
+	if (wr->send_flags & IB_SEND_SOLICITED)
+		wqe->base.flags |= cpu_to_be16(IONIC_V1_FLAG_SOL);
+
+	if (qp->sig_all || wr->send_flags & IB_SEND_SIGNALED) {
+		wqe->base.flags |= cpu_to_be16(IONIC_V1_FLAG_SIG);
+		meta->signal = true;
+	}
+
+	meta->seq = qp->sq_msn_prod;
+	meta->remote =
+		qp->ibqp.qp_type != IB_QPT_UD &&
+		qp->ibqp.qp_type != IB_QPT_GSI &&
+		!ionic_ibop_is_local(wr->opcode);
+
+	if (meta->remote) {
+		qp->sq_msn_idx[meta->seq] = qp->sq.prod;
+		qp->sq_msn_prod = ionic_queue_next(&qp->sq, qp->sq_msn_prod);
+	}
+
+	ionic_queue_produce(&qp->sq);
+}
+
+static int ionic_prep_common(struct ionic_qp *qp,
+			     const struct ib_send_wr *wr,
+			     struct ionic_sq_meta *meta,
+			     struct ionic_v1_wqe *wqe)
+{
+	s64 signed_len;
+	u32 mval;
+
+	if (wr->send_flags & IB_SEND_INLINE) {
+		wqe->base.num_sge_key = 0;
+		wqe->base.flags |= cpu_to_be16(IONIC_V1_FLAG_INL);
+		mval = ionic_v1_send_wqe_max_data(qp->sq.stride_log2, false);
+		signed_len = ionic_prep_inline(wqe->common.pld.data, mval,
+					       wr->sg_list, wr->num_sge);
+	} else {
+		wqe->base.num_sge_key = wr->num_sge;
+		mval = ionic_v1_send_wqe_max_sge(qp->sq.stride_log2,
+						 qp->sq_spec,
+						 false);
+		signed_len = ionic_prep_pld(wqe, &wqe->common.pld,
+					    qp->sq_spec, mval,
+					    wr->sg_list, wr->num_sge);
+	}
+
+	if (unlikely(signed_len < 0))
+		return signed_len;
+
+	meta->len = signed_len;
+	wqe->common.length = cpu_to_be32(signed_len);
+
+	ionic_prep_base(qp, wr, meta, wqe);
+
+	return 0;
+}
+
+static void ionic_prep_sq_wqe(struct ionic_qp *qp, void *wqe)
+{
+	memset(wqe, 0, 1u << qp->sq.stride_log2);
+}
+
+static void ionic_prep_rq_wqe(struct ionic_qp *qp, void *wqe)
+{
+	memset(wqe, 0, 1u << qp->rq.stride_log2);
+}
+
+static int ionic_prep_send(struct ionic_qp *qp,
+			   const struct ib_send_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	struct ionic_sq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+
+	meta = &qp->sq_meta[qp->sq.prod];
+	wqe = ionic_queue_at_prod(&qp->sq);
+
+	ionic_prep_sq_wqe(qp, wqe);
+
+	meta->ibop = IB_WC_SEND;
+
+	switch (wr->opcode) {
+	case IB_WR_SEND:
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, SEND);
+		break;
+	case IB_WR_SEND_WITH_IMM:
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, SEND_IMM);
+		wqe->base.imm_data_key = wr->ex.imm_data;
+		break;
+	case IB_WR_SEND_WITH_INV:
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, SEND_INV);
+		wqe->base.imm_data_key =
+			cpu_to_be32(wr->ex.invalidate_rkey);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return ionic_prep_common(qp, wr, meta, wqe);
+}
+
+static int ionic_prep_send_ud(struct ionic_qp *qp,
+			      const struct ib_ud_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	struct ionic_sq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+	struct ionic_ah *ah;
+
+	if (unlikely(!wr->ah))
+		return -EINVAL;
+
+	ah = to_ionic_ah(wr->ah);
+
+	meta = &qp->sq_meta[qp->sq.prod];
+	wqe = ionic_queue_at_prod(&qp->sq);
+
+	ionic_prep_sq_wqe(qp, wqe);
+
+	wqe->common.send.ah_id = cpu_to_be32(ah->ahid);
+	wqe->common.send.dest_qpn = cpu_to_be32(wr->remote_qpn);
+	wqe->common.send.dest_qkey = cpu_to_be32(wr->remote_qkey);
+
+	meta->ibop = IB_WC_SEND;
+
+	switch (wr->wr.opcode) {
+	case IB_WR_SEND:
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, SEND);
+		break;
+	case IB_WR_SEND_WITH_IMM:
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, SEND_IMM);
+		wqe->base.imm_data_key = wr->wr.ex.imm_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return ionic_prep_common(qp, &wr->wr, meta, wqe);
+}
+
+static int ionic_prep_rdma(struct ionic_qp *qp,
+			   const struct ib_rdma_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	struct ionic_sq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+
+	meta = &qp->sq_meta[qp->sq.prod];
+	wqe = ionic_queue_at_prod(&qp->sq);
+
+	ionic_prep_sq_wqe(qp, wqe);
+
+	meta->ibop = IB_WC_RDMA_WRITE;
+
+	switch (wr->wr.opcode) {
+	case IB_WR_RDMA_READ:
+		if (wr->wr.send_flags & (IB_SEND_SOLICITED | IB_SEND_INLINE))
+			return -EINVAL;
+		meta->ibop = IB_WC_RDMA_READ;
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, RDMA_READ);
+		break;
+	case IB_WR_RDMA_WRITE:
+		if (wr->wr.send_flags & IB_SEND_SOLICITED)
+			return -EINVAL;
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, RDMA_WRITE);
+		break;
+	case IB_WR_RDMA_WRITE_WITH_IMM:
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, RDMA_WRITE_IMM);
+		wqe->base.imm_data_key = wr->wr.ex.imm_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	wqe->common.rdma.remote_va_high = cpu_to_be32(wr->remote_addr >> 32);
+	wqe->common.rdma.remote_va_low = cpu_to_be32(wr->remote_addr);
+	wqe->common.rdma.remote_rkey = cpu_to_be32(wr->rkey);
+
+	return ionic_prep_common(qp, &wr->wr, meta, wqe);
+}
+
+static int ionic_prep_atomic(struct ionic_qp *qp,
+			     const struct ib_atomic_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	struct ionic_sq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+
+	if (wr->wr.num_sge != 1 || wr->wr.sg_list[0].length != 8)
+		return -EINVAL;
+
+	if (wr->wr.send_flags & (IB_SEND_SOLICITED | IB_SEND_INLINE))
+		return -EINVAL;
+
+	meta = &qp->sq_meta[qp->sq.prod];
+	wqe = ionic_queue_at_prod(&qp->sq);
+
+	ionic_prep_sq_wqe(qp, wqe);
+
+	meta->ibop = IB_WC_RDMA_WRITE;
+
+	switch (wr->wr.opcode) {
+	case IB_WR_ATOMIC_CMP_AND_SWP:
+		meta->ibop = IB_WC_COMP_SWAP;
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, ATOMIC_CS);
+		wqe->atomic.swap_add_high = cpu_to_be32(wr->swap >> 32);
+		wqe->atomic.swap_add_low = cpu_to_be32(wr->swap);
+		wqe->atomic.compare_high = cpu_to_be32(wr->compare_add >> 32);
+		wqe->atomic.compare_low = cpu_to_be32(wr->compare_add);
+		break;
+	case IB_WR_ATOMIC_FETCH_AND_ADD:
+		meta->ibop = IB_WC_FETCH_ADD;
+		wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, ATOMIC_FA);
+		wqe->atomic.swap_add_high = cpu_to_be32(wr->compare_add >> 32);
+		wqe->atomic.swap_add_low = cpu_to_be32(wr->compare_add);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	wqe->atomic.remote_va_high = cpu_to_be32(wr->remote_addr >> 32);
+	wqe->atomic.remote_va_low = cpu_to_be32(wr->remote_addr);
+	wqe->atomic.remote_rkey = cpu_to_be32(wr->rkey);
+
+	wqe->base.num_sge_key = 1;
+	wqe->atomic.sge.va = cpu_to_be64(wr->wr.sg_list[0].addr);
+	wqe->atomic.sge.len = cpu_to_be32(8);
+	wqe->atomic.sge.lkey = cpu_to_be32(wr->wr.sg_list[0].lkey);
+
+	return ionic_prep_common(qp, &wr->wr, meta, wqe);
+}
+
+static int ionic_prep_inv(struct ionic_qp *qp,
+			  const struct ib_send_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	struct ionic_sq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+
+	if (wr->send_flags & (IB_SEND_SOLICITED | IB_SEND_INLINE))
+		return -EINVAL;
+
+	meta = &qp->sq_meta[qp->sq.prod];
+	wqe = ionic_queue_at_prod(&qp->sq);
+
+	ionic_prep_sq_wqe(qp, wqe);
+
+	wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, LOCAL_INV);
+	wqe->base.imm_data_key = cpu_to_be32(wr->ex.invalidate_rkey);
+
+	meta->len = 0;
+	meta->ibop = IB_WC_LOCAL_INV;
+
+	ionic_prep_base(qp, wr, meta, wqe);
+
+	return 0;
+}
+
+static int ionic_prep_reg(struct ionic_qp *qp,
+			  const struct ib_reg_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	struct ionic_mr *mr = to_ionic_mr(wr->mr);
+	struct ionic_sq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+	__le64 dma_addr;
+	int flags;
+
+	if (wr->wr.send_flags & (IB_SEND_SOLICITED | IB_SEND_INLINE))
+		return -EINVAL;
+
+	/* must call ib_map_mr_sg before posting reg wr */
+	if (!mr->buf.tbl_pages)
+		return -EINVAL;
+
+	meta = &qp->sq_meta[qp->sq.prod];
+	wqe = ionic_queue_at_prod(&qp->sq);
+
+	ionic_prep_sq_wqe(qp, wqe);
+
+	flags = to_ionic_mr_flags(wr->access);
+
+	wqe->base.op = IONIC_OP(dev->lif_cfg.rdma_version, REG_MR);
+	wqe->base.num_sge_key = wr->key;
+	wqe->base.imm_data_key = cpu_to_be32(mr->ibmr.lkey);
+	wqe->reg_mr.va = cpu_to_be64(mr->ibmr.iova);
+	wqe->reg_mr.length = cpu_to_be64(mr->ibmr.length);
+	wqe->reg_mr.offset = ionic_pgtbl_off(&mr->buf, mr->ibmr.iova);
+	dma_addr = ionic_pgtbl_dma(&mr->buf, mr->ibmr.iova);
+	wqe->reg_mr.dma_addr = cpu_to_be64(le64_to_cpu(dma_addr));
+
+	wqe->reg_mr.map_count = cpu_to_be32(mr->buf.tbl_pages);
+	wqe->reg_mr.flags = cpu_to_be16(flags);
+	wqe->reg_mr.dir_size_log2 = 0;
+	wqe->reg_mr.page_size_log2 = order_base_2(mr->ibmr.page_size);
+
+	meta->len = 0;
+	meta->ibop = IB_WC_REG_MR;
+
+	ionic_prep_base(qp, &wr->wr, meta, wqe);
+
+	return 0;
+}
+
+static int ionic_prep_one_rc(struct ionic_qp *qp,
+			     const struct ib_send_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	int rc = 0;
+
+	switch (wr->opcode) {
+	case IB_WR_SEND:
+	case IB_WR_SEND_WITH_IMM:
+	case IB_WR_SEND_WITH_INV:
+		rc = ionic_prep_send(qp, wr);
+		break;
+	case IB_WR_RDMA_READ:
+	case IB_WR_RDMA_WRITE:
+	case IB_WR_RDMA_WRITE_WITH_IMM:
+		rc = ionic_prep_rdma(qp, rdma_wr(wr));
+		break;
+	case IB_WR_ATOMIC_CMP_AND_SWP:
+	case IB_WR_ATOMIC_FETCH_AND_ADD:
+		rc = ionic_prep_atomic(qp, atomic_wr(wr));
+		break;
+	case IB_WR_LOCAL_INV:
+		rc = ionic_prep_inv(qp, wr);
+		break;
+	case IB_WR_REG_MR:
+		rc = ionic_prep_reg(qp, reg_wr(wr));
+		break;
+	default:
+		ibdev_dbg(&dev->ibdev, "invalid opcode %d\n", wr->opcode);
+		rc = -EINVAL;
+	}
+
+	return rc;
+}
+
+static int ionic_prep_one_ud(struct ionic_qp *qp,
+			     const struct ib_send_wr *wr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(qp->ibqp.device);
+	int rc = 0;
+
+	switch (wr->opcode) {
+	case IB_WR_SEND:
+	case IB_WR_SEND_WITH_IMM:
+		rc = ionic_prep_send_ud(qp, ud_wr(wr));
+		break;
+	default:
+		ibdev_dbg(&dev->ibdev, "invalid opcode %d\n", wr->opcode);
+		rc = -EINVAL;
+	}
+
+	return rc;
+}
+
+static int ionic_prep_recv(struct ionic_qp *qp,
+			   const struct ib_recv_wr *wr)
+{
+	struct ionic_rq_meta *meta;
+	struct ionic_v1_wqe *wqe;
+	s64 signed_len;
+	u32 mval;
+
+	wqe = ionic_queue_at_prod(&qp->rq);
+
+	/* if wqe is owned by device, caller can try posting again soon */
+	if (wqe->base.flags & cpu_to_be16(IONIC_V1_FLAG_FENCE))
+		return -EAGAIN;
+
+	meta = qp->rq_meta_head;
+	if (unlikely(meta == IONIC_META_LAST) ||
+	    unlikely(meta == IONIC_META_POSTED))
+		return -EIO;
+
+	ionic_prep_rq_wqe(qp, wqe);
+
+	mval = ionic_v1_recv_wqe_max_sge(qp->rq.stride_log2, qp->rq_spec,
+					 false);
+	signed_len = ionic_prep_pld(wqe, &wqe->recv.pld,
+				    qp->rq_spec, mval,
+				    wr->sg_list, wr->num_sge);
+	if (signed_len < 0)
+		return signed_len;
+
+	meta->wrid = wr->wr_id;
+
+	wqe->base.wqe_id = meta - qp->rq_meta;
+	wqe->base.num_sge_key = wr->num_sge;
+
+	/* total length for recv goes in base imm_data_key */
+	wqe->base.imm_data_key = cpu_to_be32(signed_len);
+
+	ionic_queue_produce(&qp->rq);
+
+	qp->rq_meta_head = meta->next;
+	meta->next = IONIC_META_POSTED;
+
+	return 0;
+}
+
+static int ionic_post_send_common(struct ionic_ibdev *dev,
+				  struct ionic_vcq *vcq,
+				  struct ionic_cq *cq,
+				  struct ionic_qp *qp,
+				  const struct ib_send_wr *wr,
+				  const struct ib_send_wr **bad)
+{
+	unsigned long irqflags;
+	bool notify = false;
+	int spend, rc = 0;
+
+	if (!bad)
+		return -EINVAL;
+
+	if (!qp->has_sq) {
+		*bad = wr;
+		return -EINVAL;
+	}
+
+	if (qp->state < IB_QPS_RTS) {
+		*bad = wr;
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&qp->sq_lock, irqflags);
+
+	while (wr) {
+		if (ionic_queue_full(&qp->sq)) {
+			ibdev_dbg(&dev->ibdev, "queue full");
+			rc = -ENOMEM;
+			goto out;
+		}
+
+		if (qp->ibqp.qp_type == IB_QPT_UD ||
+		    qp->ibqp.qp_type == IB_QPT_GSI)
+			rc = ionic_prep_one_ud(qp, wr);
+		else
+			rc = ionic_prep_one_rc(qp, wr);
+		if (rc)
+			goto out;
+
+		wr = wr->next;
+	}
+
+out:
+	/* irq remains saved here, not restored/saved again */
+	if (!spin_trylock(&cq->lock)) {
+		spin_unlock(&qp->sq_lock);
+		spin_lock(&cq->lock);
+		spin_lock(&qp->sq_lock);
+	}
+
+	if (likely(qp->sq.prod != qp->sq_old_prod)) {
+		/* ring cq doorbell just in time */
+		spend = (qp->sq.prod - qp->sq_old_prod) & qp->sq.mask;
+		ionic_reserve_cq(dev, cq, spend);
+
+		qp->sq_old_prod = qp->sq.prod;
+
+		ionic_dbell_ring(dev->lif_cfg.dbpage, dev->lif_cfg.sq_qtype,
+				 ionic_queue_dbell_val(&qp->sq));
+	}
+
+	if (qp->sq_flush) {
+		notify = true;
+		cq->flush = true;
+		list_move_tail(&qp->cq_flush_sq, &cq->flush_sq);
+	}
+
+	spin_unlock(&qp->sq_lock);
+	spin_unlock_irqrestore(&cq->lock, irqflags);
+
+	if (notify && vcq->ibcq.comp_handler)
+		vcq->ibcq.comp_handler(&vcq->ibcq, vcq->ibcq.cq_context);
+
+	*bad = wr;
+	return rc;
+}
+
+static int ionic_post_recv_common(struct ionic_ibdev *dev,
+				  struct ionic_vcq *vcq,
+				  struct ionic_cq *cq,
+				  struct ionic_qp *qp,
+				  const struct ib_recv_wr *wr,
+				  const struct ib_recv_wr **bad)
+{
+	unsigned long irqflags;
+	bool notify = false;
+	int spend, rc = 0;
+
+	if (!bad)
+		return -EINVAL;
+
+	if (!qp->has_rq) {
+		*bad = wr;
+		return -EINVAL;
+	}
+
+	if (qp->state < IB_QPS_INIT) {
+		*bad = wr;
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&qp->rq_lock, irqflags);
+
+	while (wr) {
+		if (ionic_queue_full(&qp->rq)) {
+			ibdev_dbg(&dev->ibdev, "queue full");
+			rc = -ENOMEM;
+			goto out;
+		}
+
+		rc = ionic_prep_recv(qp, wr);
+		if (rc)
+			goto out;
+
+		wr = wr->next;
+	}
+
+out:
+	if (!cq) {
+		spin_unlock_irqrestore(&qp->rq_lock, irqflags);
+		goto out_unlocked;
+	}
+
+	/* irq remains saved here, not restored/saved again */
+	if (!spin_trylock(&cq->lock)) {
+		spin_unlock(&qp->rq_lock);
+		spin_lock(&cq->lock);
+		spin_lock(&qp->rq_lock);
+	}
+
+	if (likely(qp->rq.prod != qp->rq_old_prod)) {
+		/* ring cq doorbell just in time */
+		spend = (qp->rq.prod - qp->rq_old_prod) & qp->rq.mask;
+		ionic_reserve_cq(dev, cq, spend);
+
+		qp->rq_old_prod = qp->rq.prod;
+
+		ionic_dbell_ring(dev->lif_cfg.dbpage, dev->lif_cfg.rq_qtype,
+				 ionic_queue_dbell_val(&qp->rq));
+	}
+
+	if (qp->rq_flush) {
+		notify = true;
+		cq->flush = true;
+		list_move_tail(&qp->cq_flush_rq, &cq->flush_rq);
+	}
+
+	spin_unlock(&qp->rq_lock);
+	spin_unlock_irqrestore(&cq->lock, irqflags);
+
+	if (notify && vcq->ibcq.comp_handler)
+		vcq->ibcq.comp_handler(&vcq->ibcq, vcq->ibcq.cq_context);
+
+out_unlocked:
+	*bad = wr;
+	return rc;
+}
+
+static int ionic_post_send(struct ib_qp *ibqp,
+			   const struct ib_send_wr *wr,
+			   const struct ib_send_wr **bad)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibqp->device);
+	struct ionic_vcq *vcq = to_ionic_vcq(ibqp->send_cq);
+	struct ionic_qp *qp = to_ionic_qp(ibqp);
+	struct ionic_cq *cq =
+		to_ionic_vcq_cq(ibqp->send_cq, qp->udma_idx);
+
+	return ionic_post_send_common(dev, vcq, cq, qp, wr, bad);
+}
+
+static int ionic_post_recv(struct ib_qp *ibqp,
+			   const struct ib_recv_wr *wr,
+			   const struct ib_recv_wr **bad)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibqp->device);
+	struct ionic_vcq *vcq = to_ionic_vcq(ibqp->recv_cq);
+	struct ionic_qp *qp = to_ionic_qp(ibqp);
+	struct ionic_cq *cq =
+		to_ionic_vcq_cq(ibqp->recv_cq, qp->udma_idx);
+
+	return ionic_post_recv_common(dev, vcq, cq, qp, wr, bad);
+}
+
+static const struct ib_device_ops ionic_datapath_ops = {
+	.driver_id = RDMA_DRIVER_IONIC,
+	.post_send = ionic_post_send,
+	.post_recv = ionic_post_recv,
+	.poll_cq = ionic_poll_cq,
+	.req_notify_cq = ionic_req_notify_cq,
+};
+
+void ionic_datapath_setops(struct ionic_ibdev *dev)
+{
+	ib_set_device_ops(&dev->ibdev, &ionic_datapath_ops);
+
+	dev->ibdev.uverbs_cmd_mask |=
+		BIT_ULL(IB_USER_VERBS_CMD_POST_SEND)		|
+		BIT_ULL(IB_USER_VERBS_CMD_POST_RECV)		|
+		BIT_ULL(IB_USER_VERBS_CMD_POLL_CQ)			|
+		BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ)	|
+		0;
+}
drivers/infiniband/hw/ionic/ionic_fw.h +107 -0

131 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_ibdev.c +1 -0
index 358645881a24..e7c5b15b27cf 100644
@@ -174,6 +174,7 @@ static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
 	if (rc)
 		goto err_admin;
 
+	ionic_datapath_setops(dev);
 	ionic_controlpath_setops(dev);
 
 	rc = ib_register_device(ibdev, "ionic_%d", ibdev->dev.parent);
drivers/infiniband/hw/ionic/ionic_ibdev.h +9 -0
index 2c730d0fbae8..c476f3781090 100644
@@ -413,6 +413,11 @@ static inline u32 ionic_obj_dbid(struct ionic_ibdev *dev,
 	return ionic_ctx_dbid(dev, to_ionic_ctx_uobj(uobj));
 }
 
+static inline bool ionic_ibop_is_local(enum ib_wr_opcode op)
+{
+	return op == IB_WR_LOCAL_INV || op == IB_WR_REG_MR;
+}
+
 static inline void ionic_qp_complete(struct kref *kref)
 {
 	struct ionic_qp *qp = container_of(kref, struct ionic_qp, qp_kref);
@@ -453,8 +458,12 @@ void ionic_destroy_cq_common(struct ionic_ibdev *dev, struct ionic_cq *cq);
 void ionic_flush_qp(struct ionic_ibdev *dev, struct ionic_qp *qp);
 void ionic_notify_flush_cq(struct ionic_cq *cq);
 
+/* ionic_datapath.c */
+void ionic_datapath_setops(struct ionic_ibdev *dev);
+
 /* ionic_pgtbl.c */
 __le64 ionic_pgtbl_dma(struct ionic_tbl_buf *buf, u64 va);
+__be64 ionic_pgtbl_off(struct ionic_tbl_buf *buf, u64 va);
 int ionic_pgtbl_page(struct ionic_tbl_buf *buf, u64 dma);
 int ionic_pgtbl_init(struct ionic_ibdev *dev,
 		     struct ionic_tbl_buf *buf,
drivers/infiniband/hw/ionic/ionic_pgtbl.c +11 -0
index a8eb73be6f86..e74db73c9246 100644
@@ -26,6 +26,17 @@ __le64 ionic_pgtbl_dma(struct ionic_tbl_buf *buf, u64 va)
 	return cpu_to_le64(dma + (va & pg_mask));
 }
 
+__be64 ionic_pgtbl_off(struct ionic_tbl_buf *buf, u64 va)
+{
+	if (buf->tbl_pages > 1) {
+		u64 pg_mask = BIT_ULL(buf->page_size_log2) - 1;
+
+		return cpu_to_be64(va & pg_mask);
+	}
+
+	return 0;
+}
+
 int ionic_pgtbl_page(struct ionic_tbl_buf *buf, u64 dma)
 {
 	if (unlikely(buf->tbl_pages == buf->tbl_limit))
Signature · 1 line
2.34.1
author maintainer
#16 lore raw

PATCH v2 12/14 RDMA/ionic: Register device ops for miscellaneous functionality

In reply to Abhijit Gangurde

Implement idbdev ops for device and port information.

---
 drivers/infiniband/hw/ionic/ionic_ibdev.c   | 224 ++++++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_ibdev.h   |   5 +
 drivers/infiniband/hw/ionic/ionic_lif_cfg.c |  10 +
 drivers/infiniband/hw/ionic/ionic_lif_cfg.h |   2 +
 4 files changed, 241 insertions(+)
drivers/infiniband/hw/ionic/ionic_ibdev.c +224 -0
index e7c5b15b27cf..1fe58ca2238f 100644
@@ -3,7 +3,11 @@
 
 #include <linux/module.h>
 #include <linux/printk.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
 #include <net/addrconf.h>
+#include <rdma/ib_addr.h>
+#include <rdma/ib_mad.h>
 
 #include "ionic_ibdev.h"
 
@@ -33,6 +37,219 @@ void ionic_port_event(struct ionic_ibdev *dev, enum ib_event_type event)
 	ib_dispatch_event(&ev);
 }
 
+static int ionic_query_device(struct ib_device *ibdev,
+			      struct ib_device_attr *attr,
+			      struct ib_udata *udata)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
+
+	addrconf_ifid_eui48((u8 *)&attr->sys_image_guid,
+			    ionic_lif_netdev(dev->lif_cfg.lif));
+	attr->max_mr_size = dev->lif_cfg.npts_per_lif * PAGE_SIZE / 2;
+	attr->page_size_cap = dev->lif_cfg.page_size_supported;
+
+	attr->vendor_id = to_pci_dev(dev->lif_cfg.hwdev)->vendor;
+	attr->vendor_part_id = to_pci_dev(dev->lif_cfg.hwdev)->device;
+
+	attr->hw_ver = ionic_lif_asic_rev(dev->lif_cfg.lif);
+	attr->fw_ver = 0;
+	attr->max_qp = dev->lif_cfg.qp_count;
+	attr->max_qp_wr = IONIC_MAX_DEPTH;
+	attr->device_cap_flags =
+		IB_DEVICE_MEM_WINDOW |
+		IB_DEVICE_MEM_MGT_EXTENSIONS |
+		IB_DEVICE_MEM_WINDOW_TYPE_2B |
+		0;
+	attr->kernel_cap_flags = IBK_LOCAL_DMA_LKEY;
+	attr->max_send_sge =
+		min(ionic_v1_send_wqe_max_sge(dev->lif_cfg.max_stride, 0, false),
+		    IONIC_SPEC_HIGH);
+	attr->max_recv_sge =
+		min(ionic_v1_recv_wqe_max_sge(dev->lif_cfg.max_stride, 0, false),
+		    IONIC_SPEC_HIGH);
+	attr->max_sge_rd = attr->max_send_sge;
+	attr->max_cq = dev->lif_cfg.cq_count / dev->lif_cfg.udma_count;
+	attr->max_cqe = IONIC_MAX_CQ_DEPTH - IONIC_CQ_GRACE;
+	attr->max_mr = dev->lif_cfg.nmrs_per_lif;
+	attr->max_pd = IONIC_MAX_PD;
+	attr->max_qp_rd_atom = IONIC_MAX_RD_ATOM;
+	attr->max_ee_rd_atom = 0;
+	attr->max_res_rd_atom = IONIC_MAX_RD_ATOM;
+	attr->max_qp_init_rd_atom = IONIC_MAX_RD_ATOM;
+	attr->max_ee_init_rd_atom = 0;
+	attr->atomic_cap = IB_ATOMIC_GLOB;
+	attr->masked_atomic_cap = IB_ATOMIC_GLOB;
+	attr->max_mw = dev->lif_cfg.nmrs_per_lif;
+	attr->max_mcast_grp = 0;
+	attr->max_mcast_qp_attach = 0;
+	attr->max_ah = dev->lif_cfg.nahs_per_lif;
+	attr->max_fast_reg_page_list_len = dev->lif_cfg.npts_per_lif / 2;
+	attr->max_pkeys = IONIC_PKEY_TBL_LEN;
+
+	return 0;
+}
+
+static int ionic_query_port(struct ib_device *ibdev, u32 port,
+			    struct ib_port_attr *attr)
+{
+	struct net_device *ndev;
+
+	if (port != 1)
+		return -EINVAL;
+
+	ndev = ib_device_get_netdev(ibdev, port);
+
+	if (netif_running(ndev) && netif_carrier_ok(ndev)) {
+		attr->state = IB_PORT_ACTIVE;
+		attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
+	} else if (netif_running(ndev)) {
+		attr->state = IB_PORT_DOWN;
+		attr->phys_state = IB_PORT_PHYS_STATE_POLLING;
+	} else {
+		attr->state = IB_PORT_DOWN;
+		attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
+	}
+
+	attr->max_mtu = iboe_get_mtu(ndev->max_mtu);
+	attr->active_mtu = min(attr->max_mtu, iboe_get_mtu(ndev->mtu));
+	attr->gid_tbl_len = IONIC_GID_TBL_LEN;
+	attr->ip_gids = true;
+	attr->port_cap_flags = 0;
+	attr->max_msg_sz = 0x80000000;
+	attr->pkey_tbl_len = IONIC_PKEY_TBL_LEN;
+	attr->max_vl_num = 1;
+	attr->subnet_prefix = 0xfe80000000000000ull;
+
+	dev_put(ndev);
+
+	return ib_get_eth_speed(ibdev, port,
+				&attr->active_speed,
+				&attr->active_width);
+}
+
+static enum rdma_link_layer ionic_get_link_layer(struct ib_device *ibdev,
+						 u32 port)
+{
+	return IB_LINK_LAYER_ETHERNET;
+}
+
+static int ionic_query_pkey(struct ib_device *ibdev, u32 port, u16 index,
+			    u16 *pkey)
+{
+	if (port != 1)
+		return -EINVAL;
+
+	if (index != 0)
+		return -EINVAL;
+
+	*pkey = IB_DEFAULT_PKEY_FULL;
+
+	return 0;
+}
+
+static int ionic_modify_device(struct ib_device *ibdev, int mask,
+			       struct ib_device_modify *attr)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
+
+	if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
+		return -EOPNOTSUPP;
+
+	if (mask & IB_DEVICE_MODIFY_NODE_DESC)
+		memcpy(dev->ibdev.node_desc, attr->node_desc,
+		       IB_DEVICE_NODE_DESC_MAX);
+
+	return 0;
+}
+
+static int ionic_get_port_immutable(struct ib_device *ibdev, u32 port,
+				    struct ib_port_immutable *attr)
+{
+	if (port != 1)
+		return -EINVAL;
+
+	attr->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
+
+	attr->pkey_tbl_len = IONIC_PKEY_TBL_LEN;
+	attr->gid_tbl_len = IONIC_GID_TBL_LEN;
+	attr->max_mad_size = IB_MGMT_MAD_SIZE;
+
+	return 0;
+}
+
+static void ionic_get_dev_fw_str(struct ib_device *ibdev, char *str)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
+
+	ionic_lif_fw_version(dev->lif_cfg.lif, str, IB_FW_VERSION_NAME_MAX);
+}
+
+static const struct cpumask *ionic_get_vector_affinity(struct ib_device *ibdev,
+						       int comp_vector)
+{
+	struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
+
+	if (comp_vector < 0 || comp_vector >= dev->lif_cfg.eq_count)
+		return NULL;
+
+	return irq_get_affinity_mask(dev->eq_vec[comp_vector]->irq);
+}
+
+static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
+			   char *buf)
+{
+	struct ionic_ibdev *dev =
+		rdma_device_to_drv_device(device, struct ionic_ibdev, ibdev);
+
+	return sysfs_emit(buf, "0x%x\n", ionic_lif_asic_rev(dev->lif_cfg.lif));
+}
+static DEVICE_ATTR_RO(hw_rev);
+
+static ssize_t hca_type_show(struct device *device,
+			     struct device_attribute *attr, char *buf)
+{
+	struct ionic_ibdev *dev =
+		rdma_device_to_drv_device(device, struct ionic_ibdev, ibdev);
+
+	return sysfs_emit(buf, "%s\n", dev->ibdev.node_desc);
+}
+static DEVICE_ATTR_RO(hca_type);
+
+static struct attribute *ionic_rdma_attributes[] = {
+	&dev_attr_hw_rev.attr,
+	&dev_attr_hca_type.attr,
+	NULL
+};
+
+static const struct attribute_group ionic_rdma_attr_group = {
+	.attrs = ionic_rdma_attributes,
+};
+
+static void ionic_disassociate_ucontext(struct ib_ucontext *ibcontext)
+{
+	/*
+	 * Dummy define disassociate_ucontext so that it does not
+	 * wait for user context before cleaning up hw resources.
+	 */
+}
+
+static const struct ib_device_ops ionic_dev_ops = {
+	.owner = THIS_MODULE,
+	.driver_id = RDMA_DRIVER_IONIC,
+	.uverbs_abi_ver = IONIC_ABI_VERSION,
+	.query_device = ionic_query_device,
+	.query_port = ionic_query_port,
+	.get_link_layer = ionic_get_link_layer,
+	.query_pkey = ionic_query_pkey,
+	.modify_device = ionic_modify_device,
+
+	.get_port_immutable = ionic_get_port_immutable,
+	.get_dev_fw_str = ionic_get_dev_fw_str,
+	.get_vector_affinity = ionic_get_vector_affinity,
+	.device_group = &ionic_rdma_attr_group,
+	.disassociate_ucontext = ionic_disassociate_ucontext,
+};
+
 static int ionic_init_resids(struct ionic_ibdev *dev)
 {
 	int rc;
@@ -174,6 +391,13 @@ static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
 	if (rc)
 		goto err_admin;
 
+	ibdev->uverbs_cmd_mask =
+		BIT_ULL(IB_USER_VERBS_CMD_GET_CONTEXT)		|
+		BIT_ULL(IB_USER_VERBS_CMD_QUERY_DEVICE)		|
+		BIT_ULL(IB_USER_VERBS_CMD_QUERY_PORT)		|
+		0;
+
+	ib_set_device_ops(&dev->ibdev, &ionic_dev_ops);
 	ionic_datapath_setops(dev);
 	ionic_controlpath_setops(dev);
 
drivers/infiniband/hw/ionic/ionic_ibdev.h +5 -0
index c476f3781090..446cb8d5e334 100644
@@ -32,6 +32,11 @@
 #define IONIC_AQ_COUNT 4
 #define IONIC_EQ_ISR_BUDGET 10
 #define IONIC_EQ_WORK_BUDGET 1000
+#define IONIC_MAX_RD_ATOM 16
+#define IONIC_PKEY_TBL_LEN 1
+#define IONIC_GID_TBL_LEN 256
+
+#define IONIC_SPEC_HIGH 8
 #define IONIC_MAX_PD 1024
 #define IONIC_SPEC_HIGH 8
 #define IONIC_SQCMB_ORDER 5
drivers/infiniband/hw/ionic/ionic_lif_cfg.c +10 -0
index a02eb2f5bd45..a4246de26b9b 100644
@@ -119,3 +119,13 @@ int ionic_version_check(const struct device *dev, struct ionic_lif *lif)
 
 	return 0;
 }
+
+void ionic_lif_fw_version(struct ionic_lif *lif, char *str, size_t len)
+{
+	strscpy(str, lif->ionic->idev.dev_info.fw_version, len);
+}
+
+u8 ionic_lif_asic_rev(struct ionic_lif *lif)
+{
+	return lif->ionic->idev.dev_info.asic_rev;
+}
drivers/infiniband/hw/ionic/ionic_lif_cfg.h +2 -0
index b095637c54cf..f92d8aee5af9 100644
@@ -61,5 +61,7 @@ struct ionic_lif_cfg {
 int ionic_version_check(const struct device *dev, struct ionic_lif *lif);
 void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg);
 struct net_device *ionic_lif_netdev(struct ionic_lif *lif);
+void ionic_lif_fw_version(struct ionic_lif *lif, char *str, size_t len);
+u8 ionic_lif_asic_rev(struct ionic_lif *lif);
 
 #endif /* _IONIC_LIF_CFG_H_ */
Signature · 1 line
2.34.1
author maintainer
#17 lore raw

PATCH v2 13/14 RDMA/ionic: Implement device stats ops

In reply to Abhijit Gangurde

Implement device stats operations for hw stats and qp stats.

---
 drivers/infiniband/hw/ionic/ionic_fw.h       |  43 ++
 drivers/infiniband/hw/ionic/ionic_hw_stats.c | 484 +++++++++++++++++++
 drivers/infiniband/hw/ionic/ionic_ibdev.c    |   4 +
 drivers/infiniband/hw/ionic/ionic_ibdev.h    |  23 +
 4 files changed, 554 insertions(+)
 create mode 100644 drivers/infiniband/hw/ionic/ionic_hw_stats.c
drivers/infiniband/hw/ionic/ionic_fw.h +43 -0
index 9971e1ccf4ee..2d9a2e9a0b60 100644
@@ -661,6 +661,17 @@ static inline int ionic_v1_use_spec_sge(int min_sge, int spec)
 	return spec;
 }
 
+struct ionic_admin_stats_hdr {
+	__le64		dma_addr;
+	__le32		length;
+	__le32		id_ver;
+	__u8		type_state;
+} __packed;
+
+#define IONIC_ADMIN_STATS_HDRS_IN_V1_LEN 17
+static_assert(sizeof(struct ionic_admin_stats_hdr) ==
+	       IONIC_ADMIN_STATS_HDRS_IN_V1_LEN);
+
 struct ionic_admin_create_ah {
 	__le64		dma_addr;
 	__le32		length;
@@ -839,6 +850,7 @@ struct ionic_v1_admin_wqe {
 	__le16				len;
 
 	union {
+		struct ionic_admin_stats_hdr stats;
 		struct ionic_admin_create_ah create_ah;
 		struct ionic_admin_destroy_ah destroy_ah;
 		struct ionic_admin_query_ah query_ah;
@@ -985,4 +997,35 @@ static inline u32 ionic_v1_eqe_evt_qid(u32 evt)
 	return evt >> IONIC_V1_EQE_QID_SHIFT;
 }
 
+enum ionic_v1_stat_bits {
+	IONIC_V1_STAT_TYPE_SHIFT	= 28,
+	IONIC_V1_STAT_TYPE_NONE		= 0,
+	IONIC_V1_STAT_TYPE_8		= 1,
+	IONIC_V1_STAT_TYPE_LE16		= 2,
+	IONIC_V1_STAT_TYPE_LE32		= 3,
+	IONIC_V1_STAT_TYPE_LE64		= 4,
+	IONIC_V1_STAT_TYPE_BE16		= 5,
+	IONIC_V1_STAT_TYPE_BE32		= 6,
+	IONIC_V1_STAT_TYPE_BE64		= 7,
+	IONIC_V1_STAT_OFF_MASK		= BIT(IONIC_V1_STAT_TYPE_SHIFT) - 1,
+};
+
+struct ionic_v1_stat {
+	union {
+		__be32		be_type_off;
+		u32		type_off;
+	};
+	char			name[28];
+};
+
+static inline int ionic_v1_stat_type(struct ionic_v1_stat *hdr)
+{
+	return hdr->type_off >> IONIC_V1_STAT_TYPE_SHIFT;
+}
+
+static inline unsigned int ionic_v1_stat_off(struct ionic_v1_stat *hdr)
+{
+	return hdr->type_off & IONIC_V1_STAT_OFF_MASK;
+}
+
 #endif /* _IONIC_FW_H_ */
drivers/infiniband/hw/ionic/ionic_hw_stats.c new file +484 -0

484 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_ibdev.c +4 -0
index 1fe58ca2238f..e292278fcbba 100644
@@ -329,6 +329,7 @@ static void ionic_destroy_ibdev(struct ionic_ibdev *dev)
 {
 	ionic_kill_rdma_admin(dev, false);
 	ib_unregister_device(&dev->ibdev);
+	ionic_stats_cleanup(dev);
 	ionic_destroy_rdma_admin(dev);
 	ionic_destroy_resids(dev);
 	xa_destroy(&dev->qp_tbl);
@@ -401,6 +402,8 @@ static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
 	ionic_datapath_setops(dev);
 	ionic_controlpath_setops(dev);
 
+	ionic_stats_init(dev);
+
 	rc = ib_register_device(ibdev, "ionic_%d", ibdev->dev.parent);
 	if (rc)
 		goto err_register;
@@ -408,6 +411,7 @@ static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
 	return dev;
 
 err_register:
+	ionic_stats_cleanup(dev);
 err_admin:
 	ionic_kill_rdma_admin(dev, false);
 	ionic_destroy_rdma_admin(dev);
drivers/infiniband/hw/ionic/ionic_ibdev.h +23 -0
index 446cb8d5e334..803127c625cc 100644
@@ -36,6 +36,7 @@
 #define IONIC_PKEY_TBL_LEN 1
 #define IONIC_GID_TBL_LEN 256
 
+#define IONIC_MAX_QPID 0xffffff
 #define IONIC_SPEC_HIGH 8
 #define IONIC_MAX_PD 1024
 #define IONIC_SPEC_HIGH 8
@@ -120,6 +121,12 @@ struct ionic_ibdev {
 	enum ionic_admin_state	admin_state;
 
 	struct ionic_eq		**eq_vec;
+
+	struct ionic_v1_stat	*hw_stats;
+	void			*hw_stats_buf;
+	struct rdma_stat_desc	*hw_stats_hdrs;
+	struct ionic_counter_stats *counter_stats;
+	int			hw_stats_count;
 };
 
 struct ionic_eq {
@@ -346,6 +353,18 @@ struct ionic_mr {
 	bool			created;
 };
 
+struct ionic_counter_stats {
+	int queue_stats_count;
+	struct ionic_v1_stat *hdr;
+	struct rdma_stat_desc *stats_hdrs;
+	struct xarray xa_counters;
+};
+
+struct ionic_counter {
+	void *vals;
+	struct list_head qp_list;
+};
+
 static inline struct ionic_ibdev *to_ionic_ibdev(struct ib_device *ibdev)
 {
 	return container_of(ibdev, struct ionic_ibdev, ibdev);
@@ -466,6 +485,10 @@ void ionic_notify_flush_cq(struct ionic_cq *cq);
 /* ionic_datapath.c */
 void ionic_datapath_setops(struct ionic_ibdev *dev);
 
+/* ionic_hw_stats.c */
+void ionic_stats_init(struct ionic_ibdev *dev);
+void ionic_stats_cleanup(struct ionic_ibdev *dev);
+
 /* ionic_pgtbl.c */
 __le64 ionic_pgtbl_dma(struct ionic_tbl_buf *buf, u64 va);
 __be64 ionic_pgtbl_off(struct ionic_tbl_buf *buf, u64 va);
Signature · 1 line
2.34.1
author maintainer
#18 lore raw

PATCH v2 14/14 RDMA/ionic: Add Makefile/Kconfig to kernel build environment

In reply to Abhijit Gangurde

Add ionic to the kernel build environment.

---
 .../ethernet/pensando/ionic_rdma.rst          | 43 +++++++++++++++++++
 MAINTAINERS                                   |  9 ++++
 drivers/infiniband/Kconfig                    |  1 +
 drivers/infiniband/hw/Makefile                |  1 +
 drivers/infiniband/hw/ionic/Kconfig           | 17 ++++++++
 drivers/infiniband/hw/ionic/Makefile          |  9 ++++
 6 files changed, 80 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst
 create mode 100644 drivers/infiniband/hw/ionic/Kconfig
 create mode 100644 drivers/infiniband/hw/ionic/Makefile
Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst new file +43 -0
new file mode 100644
index 000000000000..80c4d9876d3e
@@ -0,0 +1,43 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+============================================================
+Linux Driver for the AMD Pensando(R) Ethernet adapter family
+============================================================
+
+AMD Pensando RDMA driver.
+Copyright (C) 2018-2025, Advanced Micro Devices, Inc.
+
+Contents
+========
+
+- Identifying the Adapter
+- Enabling the driver
+- Support
+
+Identifying the Adapter
+=======================
+
+See Documentation/networking/device_drivers/ethernet/pensando/ionic.rst
+for more information on identifying the adapter.
+
+Enabling the driver
+===================
+
+The driver is enabled via the standard kernel configuration system,
+using the make command::
+
+  make oldconfig/menuconfig/etc.
+
+The driver is located in the menu structure at:
+
+  -> Device Drivers
+    -> InfiniBand support
+      -> AMD Pensando DSC RDMA/RoCE Support
+
+Support
+=======
+
+For general Linux rdma support, please use the rdma mailing
+list, which is monitored by AMD Pensando personnel::
+
+  [email protected]
MAINTAINERS +9 -0
index 96b827049501..9859d9690d31 100644
@@ -1154,6 +1154,15 @@ F:	Documentation/networking/device_drivers/ethernet/amd/pds_core.rst
 F:	drivers/net/ethernet/amd/pds_core/
 F:	include/linux/pds/
 
+AMD PENSANDO RDMA DRIVER
+M:	Abhijit Gangurde <[email protected]>
+M:	Allen Hubbe <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst
+F:	drivers/infiniband/hw/ionic/
+F:	include/uapi/rdma/ionic-abi.h
+
 AMD PMC DRIVER
 M:	Shyam Sundar S K <[email protected]>
 L:	[email protected]
drivers/infiniband/Kconfig +1 -0
index a5827d11e934..f3035edfb742 100644
@@ -85,6 +85,7 @@ source "drivers/infiniband/hw/efa/Kconfig"
 source "drivers/infiniband/hw/erdma/Kconfig"
 source "drivers/infiniband/hw/hfi1/Kconfig"
 source "drivers/infiniband/hw/hns/Kconfig"
+source "drivers/infiniband/hw/ionic/Kconfig"
 source "drivers/infiniband/hw/irdma/Kconfig"
 source "drivers/infiniband/hw/mana/Kconfig"
 source "drivers/infiniband/hw/mlx4/Kconfig"
drivers/infiniband/hw/Makefile +1 -0
index aba96ca9bce5..c30489902653 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_INFINIBAND_HNS_HIP08)	+= hns/
 obj-$(CONFIG_INFINIBAND_QEDR)		+= qedr/
 obj-$(CONFIG_INFINIBAND_BNXT_RE)	+= bnxt_re/
 obj-$(CONFIG_INFINIBAND_ERDMA)		+= erdma/
+obj-$(CONFIG_INFINIBAND_IONIC)		+= ionic/
drivers/infiniband/hw/ionic/Kconfig new file +17 -0
new file mode 100644
index 000000000000..023a7fcdacb8
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2018-2025, Advanced Micro Devices, Inc.
+
+config INFINIBAND_IONIC
+	tristate "AMD Pensando DSC RDMA/RoCE Support"
+	depends on NETDEVICES && ETHERNET && PCI && INET && 64BIT
+	select NET_VENDOR_PENSANDO
+	select IONIC
+	help
+	  This enables RDMA/RoCE support for the AMD Pensando family of
+	  Distributed Services Cards (DSCs).
+
+	  To learn more, visit our website at
+	  <https://www.amd.com/en/products/accelerators/pensando.html>.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called ionic_rdma.
drivers/infiniband/hw/ionic/Makefile new file +9 -0
new file mode 100644
index 000000000000..d1588d4cdb0f
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ccflags-y :=  -I $(srctree)/drivers/net/ethernet/pensando/ionic
+
+obj-$(CONFIG_INFINIBAND_IONIC)	+= ionic_rdma.o
+
+ionic_rdma-y :=	\
+	ionic_ibdev.o ionic_lif_cfg.o ionic_queue.o ionic_pgtbl.o ionic_res.o	\
+	ionic_admin.o ionic_controlpath.o ionic_datapath.o ionic_hw_stats.o
Signature · 1 line
2.34.1
reviewer
#19 lore raw

Re: [PATCH v2 14/14] RDMA/ionic: Add Makefile/Kconfig to kernel build environment

Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst

Quoted 22 lines · Abhijit Gangurde

Add ionic to the kernel build environment.

---
 .../ethernet/pensando/ionic_rdma.rst          | 43 +++++++++++++++++++
 MAINTAINERS                                   |  9 ++++
 drivers/infiniband/Kconfig                    |  1 +
 drivers/infiniband/hw/Makefile                |  1 +
 drivers/infiniband/hw/ionic/Kconfig           | 17 ++++++++
 drivers/infiniband/hw/ionic/Makefile          |  9 ++++
 6 files changed, 80 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst
 create mode 100644 drivers/infiniband/hw/ionic/Kconfig
 create mode 100644 drivers/infiniband/hw/ionic/Makefile
Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst new file +0 -0
new file mode 100644
index 000000000000..80c4d9876d3e

Please add this new file to Documentation/networking/device_drivers/ethernet/index.rst (or some other index.rst).

Flagged by make htmldocs

...

author maintainer
#20 lore raw

Re: [PATCH v2 14/14] RDMA/ionic: Add Makefile/Kconfig to kernel build environment

Quoted 27 lines · Simon Horman

Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst

Quoted 22 lines · Abhijit Gangurde

Add ionic to the kernel build environment.

---
  .../ethernet/pensando/ionic_rdma.rst          | 43 +++++++++++++++++++
  MAINTAINERS                                   |  9 ++++
  drivers/infiniband/Kconfig                    |  1 +
  drivers/infiniband/hw/Makefile                |  1 +
  drivers/infiniband/hw/ionic/Kconfig           | 17 ++++++++
  drivers/infiniband/hw/ionic/Makefile          |  9 ++++
  6 files changed, 80 insertions(+)

create mode 100644 Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst create mode 100644 drivers/infiniband/hw/ionic/Kconfig
create mode 100644 drivers/infiniband/hw/ionic/Makefile

Documentation/networking/device_drivers/ethernet/pensando/ionic_rdma.rst new file +0 -0
new file mode 100644
index 000000000000..80c4d9876d3e

Please add this new file to Documentation/networking/device_drivers/ethernet/index.rst (or some other index.rst).

Quoted 3 lines

Flagged by make htmldocs

...

Thanks for pointing this. Will add the new file to Documentation/networking/device_drivers/index.rst in next spin.

Abhijit

maintainer
#21 lore raw
In reply to Abhijit Gangurde
Quoted 7 lines · Abhijit Gangurde

Abhijit Gangurde (14):
net: ionic: Create an auxiliary device for rdma driver
net: ionic: Update LIF identity with additional RDMA capabilities
net: ionic: Export the APIs from net driver to support device commands
net: ionic: Provide RDMA reset support for the RDMA driver
net: ionic: Provide interrupt allocation support for the RDMA driver
net: ionic: Provide doorbell and CMB region information

Quoted 8 lines

RDMA: Add IONIC to rdma_driver_id definition RDMA/ionic: Register auxiliary module for ionic ethernet adapter RDMA/ionic: Create device queues to support admin operations RDMA/ionic: Register device ops for control path RDMA/ionic: Register device ops for datapath RDMA/ionic: Register device ops for miscellaneous functionality RDMA/ionic: Implement device stats ops
RDMA/ionic: Add Makefile/Kconfig to kernel build environment

I went over this and I didn't think there was anything too unusual for a rdma driver. There are a number of things that need fixing up but overall it should be fine.

Please be careful with types. I see alot of just using 'int' even though that is not the correct type. Try not to implicitly cast things that are not int to int, try not use to signed types to hold unsigned values.

All the use of xarray looks ineffeicient to me. I noticed some things that show this probably hasn't been tested in debug kernels with lockdep. Please do that thoroughly before sending it again.

Since it is so big I reviewed the entire thing applied and made notes inline in a editor. Usually I will go back and turn these into proper contextual comments, but there are alot and I think you will be able to understand the remarks. At least it will be faster this way than waiting for me to break it up. Perhaps if a discussion is needed reply to the right line in the right message.

drivers/infiniband/hw/ionic/Kconfig +1 -0
index 023a7fcdacb88e..60e8f42e4f20de 100644
@@ -4,6 +4,7 @@
 config INFINIBAND_IONIC
 	tristate "AMD Pensando DSC RDMA/RoCE Support"
 	depends on NETDEVICES && ETHERNET && PCI && INET && 64BIT
+	# select should not be used on kconfigs with a help text
 	select NET_VENDOR_PENSANDO
 	select IONIC
 	help
drivers/infiniband/hw/ionic/ionic_admin.c +27 -0
index 72daf03dc418eb..bdaefc0a98c4ec 100644
@@ -110,6 +110,7 @@ static bool ionic_admin_next_cqe(struct ionic_ibdev *dev, struct ionic_cq *cq,
 		return false;
 
 	/* Prevent out-of-order reads of the CQE */
+	// similar comment dma_rmb() ?
 	rmb();
 
 	ibdev_dbg(&dev->ibdev, "poll admin cq %u prod %u\n",
@@ -132,6 +133,8 @@ static void ionic_admin_poll_locked(struct ionic_aq *aq)
 	u16 old_prod;
 	u8 type;
 
+	// locked by what? Add a lockdep assertion
+
 	if (dev->admin_state >= IONIC_ADMIN_KILLED) {
 		list_for_each_entry_safe(wr, wr_next, &aq->wr_prod, aq_ent) {
 			INIT_LIST_HEAD(&wr->aq_ent);
@@ -374,6 +377,7 @@ void ionic_admin_post(struct ionic_ibdev *dev, struct ionic_admin_wr *wr)
 {
 	int aq_idx;
 
+	// Probably deserves a comment why it is OK to do this. The ID can change before anything uses it.
 	aq_idx = raw_smp_processor_id() % dev->lif_cfg.aq_count;
 	ionic_admin_post_aq(dev->aq_vec[aq_idx], wr);
 }
@@ -406,6 +410,7 @@ static int ionic_admin_busy_wait(struct ionic_admin_wr *wr)
 
 		mdelay(IONIC_ADMIN_BUSY_RETRY_MS);
 
+		// cnod_resched?
 		spin_lock_irqsave(&aq->lock, irqflags);
 		ionic_admin_poll_locked(aq);
 		spin_unlock_irqrestore(&aq->lock, irqflags);
@@ -589,6 +594,7 @@ static struct ionic_aq *__ionic_create_rdma_adminq(struct ionic_ibdev *dev,
 	struct ionic_aq *aq;
 	int rc;
 
+	// Not kzalloc? Why not?
 	aq = kmalloc(sizeof(*aq), GFP_KERNEL);
 	if (!aq) {
 		rc = -ENOMEM;
@@ -669,6 +675,9 @@ static void ionic_kill_ibdev(struct ionic_ibdev *dev, bool fatal_path)
 
 	local_irq_save(irqflags);
 
+	/* Second time seeing this pattern, given it will need some commenting
+	and fixing to work with lockdep, suggest you make
+	lock_all_aq/unlock_all_aq functions */
 	/* Mark the admin queue, flushing at most once */
 	for (i = 0; i < dev->lif_cfg.aq_count; i++)
 		spin_lock(&dev->aq_vec[i]->lock);
@@ -703,6 +712,7 @@ static void ionic_kill_ibdev(struct ionic_ibdev *dev, bool fatal_path)
 		read_unlock(&dev->cq_tbl_rw);
 	}
 
+	// Weird to see the irq restore outlive any of the spinlocks, why? Add a comment.
 	local_irq_restore(irqflags);
 
 	/* Post a fatal event if requested */
@@ -720,6 +730,9 @@ void ionic_kill_rdma_admin(struct ionic_ibdev *dev, bool fatal_path)
 		return;
 
 	local_irq_save(irqflags);
+	/* I don't expect this works with lockdep turned on, does it? Please
+	make sure your driver passes tests with all sanitizers and lockdep. Be
+	sure to test unload too  */
 	for (i = 0; i < dev->lif_cfg.aq_count; i++)
 		spin_lock(&dev->aq_vec[i]->lock);
 
@@ -781,6 +794,7 @@ static bool ionic_next_eqe(struct ionic_eq *eq, struct ionic_v1_eqe *eqe)
 	if (eq->q.cons != color)
 		return false;
 
+	// Since HW is usually the thing writing to a EQE this should be dma_rmb()
 	/* Prevent out-of-order reads of the EQE */
 	rmb();
 
@@ -798,6 +812,9 @@ static void ionic_cq_event(struct ionic_ibdev *dev, u32 cqid, u8 code)
 	struct ib_event ibev;
 	struct ionic_cq *cq;
 
+	/* Weird to have a rcu protected xarray holding refcounted structs use
+	an external rwlock. Usually you'd use rcu. Didn't see a reason why this
+	needs a rwsem. */
 	read_lock_irqsave(&dev->cq_tbl_rw, irqflags);
 	cq = xa_load(&dev->cq_tbl, cqid);
 	if (cq)
@@ -843,6 +860,7 @@ static void ionic_qp_event(struct ionic_ibdev *dev, u32 qpid, u8 code)
 	struct ib_event ibev;
 	struct ionic_qp *qp;
 
+	// Same remark about RCU
 	read_lock_irqsave(&dev->qp_tbl_rw, irqflags);
 	qp = xa_load(&dev->qp_tbl, qpid);
 	if (qp)
@@ -1055,6 +1073,9 @@ static struct ionic_eq *ionic_create_eq(struct ionic_ibdev *dev, int eqid)
 
 err_cmd:
 	eq->enable = false;
+	/* This is backwards, the irq has to be stopped to make it stop queuing
+	work otherwise the work will still be running after flush. Furth since
+	the work itself requeus I'm not sure this works at all. */
 	flush_work(&eq->work);
 	free_irq(eq->irq, eq);
 err_irq:
@@ -1072,6 +1093,7 @@ static void ionic_destroy_eq(struct ionic_eq *eq)
 	struct ionic_ibdev *dev = eq->dev;
 
 	eq->enable = false;
+	// same remark about order, except here enable doesn't really do much since it isn't locked.
 	flush_work(&eq->work);
 	free_irq(eq->irq, eq);
 
@@ -1210,6 +1232,9 @@ void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
 	struct ionic_aq *aq;
 	struct ionic_eq *eq;
 
+	/* Something needs to prevent work from being queued before cancelling
+	it is meaningful, couldn't tell if that was happening. Add a comment and
+	probably a WARN_ON on the thing that prevents requeuing */
 	cancel_delayed_work_sync(&dev->admin_dwork);
 	cancel_work_sync(&dev->reset_work);
 
@@ -1218,6 +1243,7 @@ void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
 			aq = dev->aq_vec[--dev->lif_cfg.aq_count];
 			vcq = aq->vcq;
 
+			// Similar comment here.
 			cancel_work_sync(&aq->work);
 
 			__ionic_destroy_rdma_adminq(dev, aq);
@@ -1231,6 +1257,7 @@ void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
 	}
 
 	if (dev->eq_vec) {
+		// Locking? Add a lockdep assertion if caller is holding the lock
 		while (dev->lif_cfg.eq_count > 0) {
 			eq = dev->eq_vec[--dev->lif_cfg.eq_count];
 			ionic_destroy_eq(eq);
drivers/infiniband/hw/ionic/ionic_controlpath.c +36 -1
index cd2929e8033545..2ca41c64d963ed 100644
@@ -151,6 +151,7 @@ int ionic_create_cq_common(struct ionic_vcq *vcq,
 	init_completion(&cq->cq_rel_comp);
 	kref_init(&cq->cq_kref);
 
+	// More xarray weirdness
 	write_lock_irqsave(&dev->cq_tbl_rw, irqflags);
 	rc = xa_err(xa_store(&dev->cq_tbl, cq->cqid, cq, GFP_KERNEL));
 	write_unlock_irqrestore(&dev->cq_tbl_rw, irqflags);
@@ -432,6 +433,7 @@ static int ionic_alloc_ucontext(struct ib_ucontext *ibctx,
 
 err_resp:
 	ionic_put_dbid(dev, ctx->dbid);
+	// just return directly above
 err_dbid:
 err_ctx:
 	return rc;
@@ -465,6 +467,8 @@ static int ionic_mmap(struct ib_ucontext *ibctx, struct vm_area_struct *vma)
 		if (info->offset == offset)
 			goto found;
 
+	// No goto like this. Not kernel style
+
 	mutex_unlock(&ctx->mmap_mut);
 
 	/* not found */
@@ -473,6 +477,7 @@ static int ionic_mmap(struct ib_ucontext *ibctx, struct vm_area_struct *vma)
 	goto out;
 
 found:
+	// Don't do this info thing. Use the rdma_user_mmap_* API for all mmap stuff
 	list_del_init(&info->ctx_ent);
 	mutex_unlock(&ctx->mmap_mut);
 
@@ -491,6 +496,7 @@ static int ionic_mmap(struct ib_ucontext *ibctx, struct vm_area_struct *vma)
 
 	ibdev_dbg(&dev->ibdev, "remap st %#lx pf %#lx sz %#lx\n",
 		  vma->vm_start, info->pfn, size);
+	// Don't pass NULL, use the API properly
 	rc = rdma_user_mmap_io(&ctx->ibctx, vma, info->pfn, size,
 			       vma->vm_page_prot, NULL);
 	if (rc)
@@ -887,6 +893,8 @@ static struct ib_mr *ionic_get_dma_mr(struct ib_pd *ibpd, int access)
 	if (!mr)
 		return ERR_PTR(-ENOMEM);
 
+	// This seems strange, shouldn't this do something? If you don't support an all address MR then don't define this op.
+
 	return &mr->ibmr;
 }
 
@@ -927,6 +935,7 @@ static struct ib_mr *ionic_reg_user_mr(struct ib_pd *ibpd, u64 start,
 				       dev->lif_cfg.page_size_supported,
 				       addr);
 	if (!pg_sz) {
+		/* don't print on user errors */
 		ibdev_err(&dev->ibdev, "%s umem page size unsupported!",
 			  __func__);
 		rc = -EINVAL;
@@ -1002,6 +1011,7 @@ static struct ib_mr *ionic_reg_user_mr_dmabuf(struct ib_pd *ibpd, u64 offset,
 				       dev->lif_cfg.page_size_supported,
 				       addr);
 	if (!pg_sz) {
+		// don't print
 		ibdev_err(&dev->ibdev, "%s umem page size unsupported!",
 			  __func__);
 		rc = -EINVAL;
@@ -1080,6 +1090,7 @@ static struct ib_mr *ionic_rereg_user_mr(struct ib_mr *ibmr, int flags,
 	if (flags & IB_MR_REREG_TRANS) {
 		ionic_pgtbl_unbuf(dev, &mr->buf);
 
+		// What about dmabuf? Check the mlx5 implementation
 		if (mr->umem)
 			ib_umem_release(mr->umem);
 
@@ -1096,6 +1107,7 @@ static struct ib_mr *ionic_rereg_user_mr(struct ib_mr *ibmr, int flags,
 					       dev->lif_cfg.page_size_supported,
 					       addr);
 		if (!pg_sz) {
+			// no prints
 			ibdev_err(&dev->ibdev, "%s umem page size unsupported!",
 				  __func__);
 			rc = -EINVAL;
@@ -1454,11 +1466,15 @@ static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
 
 static bool pd_local_privileged(struct ib_pd *pd)
 {
+	/* That isn't how it works, only the lkey get_dma_mr() returns is
+	special and must be used on any WRs that require it. WRs refering to any
+	other lkeys must behave normally. */
 	return !pd->uobject;
 }
 
 static bool pd_remote_privileged(struct ib_pd *pd)
 {
+	/* Same comment, except about rkeys now. */
 	return pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY;
 }
 
@@ -2440,6 +2456,7 @@ static int ionic_create_qp(struct ib_qp *ibqp,
 			qp->sq_cmb_mmap.pfn = PHYS_PFN(qp->sq_cmb_addr);
 			if ((qp->sq_cmb & (IONIC_CMB_WC | IONIC_CMB_UC)) ==
 				(IONIC_CMB_WC | IONIC_CMB_UC)) {
+					// No warnings on user errors?
 				ibdev_warn(&dev->ibdev,
 					   "Both sq_cmb flags IONIC_CMB_WC and IONIC_CMB_UC are set, using default driver mapping\n");
 				qp->sq_cmb &= ~(IONIC_CMB_WC | IONIC_CMB_UC);
@@ -2457,6 +2474,7 @@ static int ionic_create_qp(struct ib_qp *ibqp,
 
 			mutex_lock(&ctx->mmap_mut);
 			qp->sq_cmb_mmap.offset = ctx->mmap_off;
+			// NO, use the rdma_user_mmap api for this stuff.
 			ctx->mmap_off += qp->sq.size;
 			list_add(&qp->sq_cmb_mmap.ctx_ent, &ctx->mmap_list);
 			mutex_unlock(&ctx->mmap_mut);
@@ -2514,13 +2532,23 @@ static int ionic_create_qp(struct ib_qp *ibqp,
 	kref_init(&qp->qp_kref);
 
 	write_lock_irqsave(&dev->qp_tbl_rw, irqflags);
+	// GFP_KERNEL is wrong, this is an atomic context becuse of the above. Should't a debug kernel catch this?
 	rc = xa_err(xa_store(&dev->qp_tbl, qp->qpid, qp, GFP_KERNEL));
+	// Poor use of xa_err, more like: (same for other xarrays)
+	ent = xa_store(&dev->qp_tbl, qp->qpid, qp, GFP_KERNEL);
+
 	write_unlock_irqrestore(&dev->qp_tbl_rw, irqflags);
-	if (rc)
+	if (ent) {
+		if (WARN_ON(!xa_is_err(ent)))
+			rc = -EINVAL;
+		else
+			rc = xa_err(ent);
 		goto err_xa;
+	}
 
 	if (qp->has_sq) {
 		cq = to_ionic_vcq_cq(attr->send_cq, qp->udma_idx);
+		// WTF is is? Needs a comment, but probably this is wrong.
 		spin_lock_irqsave(&cq->lock, irqflags);
 		spin_unlock_irqrestore(&cq->lock, irqflags);
 
@@ -2826,6 +2854,7 @@ static int ionic_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
 	if (rc)
 		return rc;
 
+	// You can also check that xa_erase returns qp and warn otherwise as something is corrupted.
 	write_lock_irqsave(&dev->qp_tbl_rw, irqflags);
 	xa_erase(&dev->qp_tbl, qp->qpid);
 	write_unlock_irqrestore(&dev->qp_tbl_rw, irqflags);
@@ -2903,8 +2932,14 @@ static const struct ib_device_ops ionic_controlpath_ops = {
 
 void ionic_controlpath_setops(struct ionic_ibdev *dev)
 {
+	/* This is not how set_device_ops is ment to be used. It should only be
+	used for things that are optional based on some runtime detection.
+	Always present ops should be hardwired into the main op. */
 	ib_set_device_ops(&dev->ibdev, &ionic_controlpath_ops);
 
+	/* This is old, drivers should not set these. Only a few special ones
+	need the driver to do anything. The core code computes this based on
+	what ops pointers are not null. Same for all places doing this */
 	dev->ibdev.uverbs_cmd_mask |=
 		BIT_ULL(IB_USER_VERBS_CMD_ALLOC_PD)		|
 		BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_PD)		|
drivers/infiniband/hw/ionic/ionic_datapath.c +3 -0
index 1262ba30172d77..ff6cff06c8575b 100644
@@ -21,6 +21,7 @@ static bool ionic_next_cqe(struct ionic_ibdev *dev, struct ionic_cq *cq,
 		return false;
 
 	/* Prevent out-of-order reads of the CQE */
+	// dma_rmb
 	rmb();
 
 	*cqe = qcqe;
@@ -639,6 +640,7 @@ static int ionic_poll_cq(struct ib_cq *ibcq, int nwc, struct ib_wc *wc)
 	int cq_i, cq_x, cq_ix;
 
 	/* poll_idx is not protected by a lock, but a race is benign */
+	// Use READ_ONCE and WRITE_ONCE then
 	cq_x = vcq->poll_idx;
 
 	vcq->poll_idx ^= dev->lif_cfg.udma_count - 1;
@@ -1411,6 +1413,7 @@ static const struct ib_device_ops ionic_datapath_ops = {
 
 void ionic_datapath_setops(struct ionic_ibdev *dev)
 {
+	// Same remark about ops and uverbs_cmd_mask
 	ib_set_device_ops(&dev->ibdev, &ionic_datapath_ops);
 
 	dev->ibdev.uverbs_cmd_mask |=
drivers/infiniband/hw/ionic/ionic_fw.h +1 -0
index 2d9a2e9a0b60cf..0b58cc66d04573 100644
@@ -974,6 +974,7 @@ enum ionic_tfp_csum_profiles {
 
 static inline bool ionic_v1_eqe_color(struct ionic_v1_eqe *eqe)
 {
+	// Don't need !! when casting to bool
 	return !!(eqe->evt & cpu_to_be32(IONIC_V1_EQE_COLOR));
 }
 
drivers/infiniband/hw/ionic/ionic_hw_stats.c +1 -0
index 29f2571463ac3a..facc015b970295 100644
@@ -464,6 +464,7 @@ void ionic_stats_init(struct ionic_ibdev *dev)
 
 		xa_init_flags(&dev->counter_stats->xa_counters, XA_FLAGS_ALLOC);
 
+		// This is the right usage since it is conditional
 		ib_set_device_ops(&dev->ibdev, &ionic_counter_stats_ops);
 	}
 }
drivers/infiniband/hw/ionic/ionic_ibdev.c +3 -1
index e292278fcbba4a..a8a8fc015c0e1e 100644
@@ -26,6 +26,7 @@ static const struct auxiliary_device_id ionic_aux_id_table[] = {
 
 MODULE_DEVICE_TABLE(auxiliary, ionic_aux_id_table);
 
+/* Why have this wrapper, just call the dispatch event from the only call site */
 void ionic_port_event(struct ionic_ibdev *dev, enum ib_event_type event)
 {
 	struct ib_event ev;
@@ -332,6 +333,7 @@ static void ionic_destroy_ibdev(struct ionic_ibdev *dev)
 	ionic_stats_cleanup(dev);
 	ionic_destroy_rdma_admin(dev);
 	ionic_destroy_resids(dev);
+	// Should WARN_ON(xa_is_empty()) to catch any bugs.
 	xa_destroy(&dev->qp_tbl);
 	xa_destroy(&dev->cq_tbl);
 	ib_dealloc_device(&dev->ibdev);
@@ -387,7 +389,7 @@ static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
 
 	addrconf_ifid_eui48((u8 *)&ibdev->node_guid,
 			    ionic_lif_netdev(ionic_adev->lif));
-
+mmap_off
 	rc = ib_device_set_netdev(ibdev, ionic_lif_netdev(ionic_adev->lif), 1);
 	if (rc)
 		goto err_admin;
drivers/infiniband/hw/ionic/ionic_ibdev.h +3 -0
index 803127c625cc2f..4d966c27c2791b 100644
@@ -137,6 +137,7 @@ struct ionic_eq {
 
 	struct ionic_queue	q;
 
+	// bool due to how xchg is used
 	int			armed;
 	bool			enable;
 
@@ -226,7 +227,9 @@ struct ionic_cq {
 	struct list_head	cq_list_ent;
 
 	struct ionic_queue	q;
+	// Linus has been known to complain about multiple bools in the same struct
 	bool			color;
+	// Why? This is not ABI?
 	int			reserve;
 	u16			arm_any_prod;
 	u16			arm_sol_prod;
drivers/infiniband/hw/ionic/ionic_res.c +6 -0
index a3b4f10aa4c84b..2d1559b42de537 100644
@@ -7,13 +7,17 @@
 
 #include "ionic_res.h"
 
+// None of these types should be int. Use unsigned long/int or size_t as appropriate. For everywhere.
 int ionic_resid_init(struct ionic_resid_bits *resid, int size)
 {
+	// sizeof(unsigned long)
+	// size_t not int
 	int size_bytes = sizeof(long) * BITS_TO_LONGS(size);
 
 	resid->next_id = 0;
 	resid->inuse_size = size;
 
+	// Use kcalloc 
 	resid->inuse = kzalloc(size_bytes, GFP_KERNEL);
 	if (!resid->inuse)
 		return -ENOMEM;
@@ -21,11 +25,13 @@ int ionic_resid_init(struct ionic_resid_bits *resid, int size)
 	return 0;
 }
 
+// All ints are unsigned 
 int ionic_resid_get_shared(struct ionic_resid_bits *resid, int wrap_id,
 			   int next_id, int size)
 {
 	int id;
 
+	/* Are you sure you don't want to use an IDR? */
 	id = find_next_zero_bit(resid->inuse, size, next_id);
 	if (id != size) {
 		set_bit(id, resid->inuse);
drivers/infiniband/hw/ionic/ionic_res.h +4 -0
index e833ced1466e89..1aa9118db25fbf 100644
@@ -4,6 +4,8 @@
 #ifndef _IONIC_RES_H_
 #define _IONIC_RES_H_
 
+/* Missing include files for header self compilation */
+
 /**
  * struct ionic_resid_bits - Number allocator based on find_first_zero_bit
  *
@@ -24,7 +26,9 @@
  * remains bounded by O(N^2) in the worst case.
  */
 struct ionic_resid_bits {
+	// unsigned int
 	int next_id;
+	// size_t
 	int inuse_size;
 	unsigned long *inuse;
 };
author maintainer
#22 lore raw
Quoted 29 lines · Jason Gunthorpe
Quoted 7 lines · Abhijit Gangurde

Abhijit Gangurde (14):
net: ionic: Create an auxiliary device for rdma driver
net: ionic: Update LIF identity with additional RDMA capabilities
net: ionic: Export the APIs from net driver to support device commands
net: ionic: Provide RDMA reset support for the RDMA driver
net: ionic: Provide interrupt allocation support for the RDMA driver
net: ionic: Provide doorbell and CMB region information

Quoted 8 lines

RDMA: Add IONIC to rdma_driver_id definition RDMA/ionic: Register auxiliary module for ionic ethernet adapter RDMA/ionic: Create device queues to support admin operations RDMA/ionic: Register device ops for control path RDMA/ionic: Register device ops for datapath RDMA/ionic: Register device ops for miscellaneous functionality RDMA/ionic: Implement device stats ops
RDMA/ionic: Add Makefile/Kconfig to kernel build environment

I went over this and I didn't think there was anything too unusual for a rdma driver. There are a number of things that need fixing up but overall it should be fine.

Please be careful with types. I see alot of just using 'int' even though that is not the correct type. Try not to implicitly cast things that are not int to int, try not use to signed types to hold unsigned values.

All the use of xarray looks ineffeicient to me. I noticed some things that show this probably hasn't been tested in debug kernels with lockdep. Please do that thoroughly before sending it again.

Quoted 6 lines

Since it is so big I reviewed the entire thing applied and made notes inline in a editor. Usually I will go back and turn these into proper contextual comments, but there are alot and I think you will be able to understand the remarks. At least it will be faster this way than waiting for me to break it up. Perhaps if a discussion is needed reply to the right line in the right message.

Thanks for the constructive feedback. Many of your comments are misses from our end and will fix those in v3. Some comments/queries inline.

Quoted 149 lines
drivers/infiniband/hw/ionic/Kconfig +1 -0
index 023a7fcdacb88e..60e8f42e4f20de 100644
@@ -4,6 +4,7 @@
  config INFINIBAND_IONIC
  	tristate "AMD Pensando DSC RDMA/RoCE Support"
  	depends on NETDEVICES && ETHERNET && PCI && INET && 64BIT
+	# select should not be used on kconfigs with a help text
  	select NET_VENDOR_PENSANDO
  	select IONIC
  	help
drivers/infiniband/hw/ionic/ionic_admin.c +26 -0
index 72daf03dc418eb..bdaefc0a98c4ec 100644
@@ -110,6 +110,7 @@ static bool ionic_admin_next_cqe(struct ionic_ibdev *dev, struct ionic_cq *cq,
  		return false;
 
  	/* Prevent out-of-order reads of the CQE */
+	// similar comment dma_rmb() ?
  	rmb();
 
  	ibdev_dbg(&dev->ibdev, "poll admin cq %u prod %u\n",
@@ -132,6 +133,8 @@ static void ionic_admin_poll_locked(struct ionic_aq *aq)
  	u16 old_prod;
  	u8 type;
 
+	// locked by what? Add a lockdep assertion
+
  	if (dev->admin_state >= IONIC_ADMIN_KILLED) {
  		list_for_each_entry_safe(wr, wr_next, &aq->wr_prod, aq_ent) {
  			INIT_LIST_HEAD(&wr->aq_ent);
@@ -374,6 +377,7 @@ void ionic_admin_post(struct ionic_ibdev *dev, struct ionic_admin_wr *wr)
  {
  	int aq_idx;
 
+	// Probably deserves a comment why it is OK to do this. The ID can change before anything uses it.
  	aq_idx = raw_smp_processor_id() % dev->lif_cfg.aq_count;
  	ionic_admin_post_aq(dev->aq_vec[aq_idx], wr);
  }
@@ -406,6 +410,7 @@ static int ionic_admin_busy_wait(struct ionic_admin_wr *wr)
 
  		mdelay(IONIC_ADMIN_BUSY_RETRY_MS);
 
+		// cnod_resched?
  		spin_lock_irqsave(&aq->lock, irqflags);
  		ionic_admin_poll_locked(aq);
  		spin_unlock_irqrestore(&aq->lock, irqflags);
@@ -589,6 +594,7 @@ static struct ionic_aq *__ionic_create_rdma_adminq(struct ionic_ibdev *dev,
  	struct ionic_aq *aq;
  	int rc;
 
+	// Not kzalloc? Why not?
  	aq = kmalloc(sizeof(*aq), GFP_KERNEL);
  	if (!aq) {
  		rc = -ENOMEM;
@@ -669,6 +675,9 @@ static void ionic_kill_ibdev(struct ionic_ibdev *dev, bool fatal_path)
 
  	local_irq_save(irqflags);
 
+	/* Second time seeing this pattern, given it will need some commenting
+	and fixing to work with lockdep, suggest you make
+	lock_all_aq/unlock_all_aq functions */
  	/* Mark the admin queue, flushing at most once */
  	for (i = 0; i < dev->lif_cfg.aq_count; i++)
  		spin_lock(&dev->aq_vec[i]->lock);
@@ -703,6 +712,7 @@ static void ionic_kill_ibdev(struct ionic_ibdev *dev, bool fatal_path)
  		read_unlock(&dev->cq_tbl_rw);
  	}
 
+	// Weird to see the irq restore outlive any of the spinlocks, why? Add a comment.
  	local_irq_restore(irqflags);
 
  	/* Post a fatal event if requested */
@@ -720,6 +730,9 @@ void ionic_kill_rdma_admin(struct ionic_ibdev *dev, bool fatal_path)
  		return;
 
  	local_irq_save(irqflags);
+	/* I don't expect this works with lockdep turned on, does it? Please
+	make sure your driver passes tests with all sanitizers and lockdep. Be
+	sure to test unload too  */
  	for (i = 0; i < dev->lif_cfg.aq_count; i++)
  		spin_lock(&dev->aq_vec[i]->lock);
 
@@ -781,6 +794,7 @@ static bool ionic_next_eqe(struct ionic_eq *eq, struct ionic_v1_eqe *eqe)
  	if (eq->q.cons != color)
  		return false;
 
+	// Since HW is usually the thing writing to a EQE this should be dma_rmb()
  	/* Prevent out-of-order reads of the EQE */
  	rmb();
 
@@ -798,6 +812,9 @@ static void ionic_cq_event(struct ionic_ibdev *dev, u32 cqid, u8 code)
  	struct ib_event ibev;
  	struct ionic_cq *cq;
 
+	/* Weird to have a rcu protected xarray holding refcounted structs use
+	an external rwlock. Usually you'd use rcu. Didn't see a reason why this
+	needs a rwsem. */
  	read_lock_irqsave(&dev->cq_tbl_rw, irqflags);
  	cq = xa_load(&dev->cq_tbl, cqid);
  	if (cq)
@@ -843,6 +860,7 @@ static void ionic_qp_event(struct ionic_ibdev *dev, u32 qpid, u8 code)
  	struct ib_event ibev;
  	struct ionic_qp *qp;
 
+	// Same remark about RCU
  	read_lock_irqsave(&dev->qp_tbl_rw, irqflags);
  	qp = xa_load(&dev->qp_tbl, qpid);
  	if (qp)
@@ -1055,6 +1073,9 @@ static struct ionic_eq *ionic_create_eq(struct ionic_ibdev *dev, int eqid)
 
  err_cmd:
  	eq->enable = false;
+	/* This is backwards, the irq has to be stopped to make it stop queuing
+	work otherwise the work will still be running after flush. Furth since
+	the work itself requeus I'm not sure this works at all. */
  	flush_work(&eq->work);
  	free_irq(eq->irq, eq);
  err_irq:
@@ -1072,6 +1093,7 @@ static void ionic_destroy_eq(struct ionic_eq *eq)
  	struct ionic_ibdev *dev = eq->dev;
 
  	eq->enable = false;
+	// same remark about order, except here enable doesn't really do much since it isn't locked.
  	flush_work(&eq->work);
  	free_irq(eq->irq, eq);
 
@@ -1210,6 +1232,9 @@ void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
  	struct ionic_aq *aq;
  	struct ionic_eq *eq;
 
+	/* Something needs to prevent work from being queued before cancelling
+	it is meaningful, couldn't tell if that was happening. Add a comment and
+	probably a WARN_ON on the thing that prevents requeuing */
  	cancel_delayed_work_sync(&dev->admin_dwork);
  	cancel_work_sync(&dev->reset_work);
 
@@ -1218,6 +1243,7 @@ void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
  			aq = dev->aq_vec[--dev->lif_cfg.aq_count];
  			vcq = aq->vcq;
 
+			// Similar comment here.
  			cancel_work_sync(&aq->work);
 
  			__ionic_destroy_rdma_adminq(dev, aq);

drivers/infiniband/hw/ionic/ionic_admin.c void ionic_destroy_rdma_admin(struct ionic_ibdev *dev) · line 1263

Quoted 7 lines
drivers/infiniband/hw/ionic/ionic_admin.c +1 -0
@@ -1231,6 +1257,7 @@ void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
  	}
 
  	if (dev->eq_vec) {
+		// Locking? Add a lockdep assertion if caller is holding the lock
  		while (dev->lif_cfg.eq_count > 0) {
  			eq = dev->eq_vec[--dev->lif_cfg.eq_count];
  			ionic_destroy_eq(eq);

I don't think there is a need for the lock here because the device is unregistered and the queues are all stopped.

Quoted 46 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +6 -0
index cd2929e8033545..2ca41c64d963ed 100644
@@ -151,6 +151,7 @@ int ionic_create_cq_common(struct ionic_vcq *vcq,
  	init_completion(&cq->cq_rel_comp);
  	kref_init(&cq->cq_kref);
 
+	// More xarray weirdness
  	write_lock_irqsave(&dev->cq_tbl_rw, irqflags);
  	rc = xa_err(xa_store(&dev->cq_tbl, cq->cqid, cq, GFP_KERNEL));
  	write_unlock_irqrestore(&dev->cq_tbl_rw, irqflags);
@@ -432,6 +433,7 @@ static int ionic_alloc_ucontext(struct ib_ucontext *ibctx,
 
  err_resp:
  	ionic_put_dbid(dev, ctx->dbid);
+	// just return directly above
  err_dbid:
  err_ctx:
  	return rc;
@@ -465,6 +467,8 @@ static int ionic_mmap(struct ib_ucontext *ibctx, struct vm_area_struct *vma)
  		if (info->offset == offset)
  			goto found;
 
+	// No goto like this. Not kernel style
+
  	mutex_unlock(&ctx->mmap_mut);
 
  	/* not found */
@@ -473,6 +477,7 @@ static int ionic_mmap(struct ib_ucontext *ibctx, struct vm_area_struct *vma)
  	goto out;
 
  found:
+	// Don't do this info thing. Use the rdma_user_mmap_* API for all mmap stuff
  	list_del_init(&info->ctx_ent);
  	mutex_unlock(&ctx->mmap_mut);
 
@@ -491,6 +496,7 @@ static int ionic_mmap(struct ib_ucontext *ibctx, struct vm_area_struct *vma)
 
  	ibdev_dbg(&dev->ibdev, "remap st %#lx pf %#lx sz %#lx\n",
  		  vma->vm_start, info->pfn, size);
+	// Don't pass NULL, use the API properly
  	rc = rdma_user_mmap_io(&ctx->ibctx, vma, info->pfn, size,
  			       vma->vm_page_prot, NULL);
  	if (rc)

drivers/infiniband/hw/ionic/ionic_controlpath.c static struct ib_mr *ionic_get_dma_mr(struct ib_pd *ibpd, int access) · line 899

Quoted 7 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +2 -0
@@ -887,6 +893,8 @@ static struct ib_mr *ionic_get_dma_mr(struct ib_pd *ibpd, int access)
  	if (!mr)
  		return ERR_PTR(-ENOMEM);
 
+	// This seems strange, shouldn't this do something? If you don't support an all address MR then don't define this op.
+
  	return &mr->ibmr;
  }

From hardware lkey zero is reserved as a local dma lkey for all address MR.  I would make it more explicit as mr.ibmr.lkey = IONIC_DMA_LKEY (same for RKEY) with that defined to be zero.

Quoted 38 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +5 -0
@@ -927,6 +935,7 @@ static struct ib_mr *ionic_reg_user_mr(struct ib_pd *ibpd, u64 start,
  				       dev->lif_cfg.page_size_supported,
  				       addr);
  	if (!pg_sz) {
+		/* don't print on user errors */
  		ibdev_err(&dev->ibdev, "%s umem page size unsupported!",
  			  __func__);
  		rc = -EINVAL;
@@ -1002,6 +1011,7 @@ static struct ib_mr *ionic_reg_user_mr_dmabuf(struct ib_pd *ibpd, u64 offset,
  				       dev->lif_cfg.page_size_supported,
  				       addr);
  	if (!pg_sz) {
+		// don't print
  		ibdev_err(&dev->ibdev, "%s umem page size unsupported!",
  			  __func__);
  		rc = -EINVAL;
@@ -1080,6 +1090,7 @@ static struct ib_mr *ionic_rereg_user_mr(struct ib_mr *ibmr, int flags,
  	if (flags & IB_MR_REREG_TRANS) {
  		ionic_pgtbl_unbuf(dev, &mr->buf);
 
+		// What about dmabuf? Check the mlx5 implementation
  		if (mr->umem)
  			ib_umem_release(mr->umem);
 
@@ -1096,6 +1107,7 @@ static struct ib_mr *ionic_rereg_user_mr(struct ib_mr *ibmr, int flags,
  					       dev->lif_cfg.page_size_supported,
  					       addr);
  		if (!pg_sz) {
+			// no prints
  			ibdev_err(&dev->ibdev, "%s umem page size unsupported!",
  				  __func__);
  			rc = -EINVAL;
@@ -1454,11 +1466,15 @@ static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
 
  static bool pd_local_privileged(struct ib_pd *pd)
  {
+	/* That isn't how it works, only the lkey get_dma_mr() returns is

drivers/infiniband/hw/ionic/ionic_controlpath.c static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) · line 1479

Quoted 10 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +3 -0
+	special and must be used on any WRs that require it. WRs refering to any
+	other lkeys must behave normally. */
  	return !pd->uobject;
  }
 
  static bool pd_remote_privileged(struct ib_pd *pd)
  {
+	/* Same comment, except about rkeys now. */
  	return pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY;
  }

This is how we allow the qp to use the dma lkey.  If the qp is a kernel space qp (its pd has no uobject) then we allow use of the dma lkey by that qp.  We do not allow use of dma lkey by user qps.  If the pd flags has the unsafe rkey flag, then we also allow the qp use it for remote access.

Quoted 138 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +20 -1
@@ -2440,6 +2456,7 @@ static int ionic_create_qp(struct ib_qp *ibqp,
  			qp->sq_cmb_mmap.pfn = PHYS_PFN(qp->sq_cmb_addr);
  			if ((qp->sq_cmb & (IONIC_CMB_WC | IONIC_CMB_UC)) ==
  				(IONIC_CMB_WC | IONIC_CMB_UC)) {
+					// No warnings on user errors?
  				ibdev_warn(&dev->ibdev,
  					   "Both sq_cmb flags IONIC_CMB_WC and IONIC_CMB_UC are set, using default driver mapping\n");
  				qp->sq_cmb &= ~(IONIC_CMB_WC | IONIC_CMB_UC);
@@ -2457,6 +2474,7 @@ static int ionic_create_qp(struct ib_qp *ibqp,
 
  			mutex_lock(&ctx->mmap_mut);
  			qp->sq_cmb_mmap.offset = ctx->mmap_off;
+			// NO, use the rdma_user_mmap api for this stuff.
  			ctx->mmap_off += qp->sq.size;
  			list_add(&qp->sq_cmb_mmap.ctx_ent, &ctx->mmap_list);
  			mutex_unlock(&ctx->mmap_mut);
@@ -2514,13 +2532,23 @@ static int ionic_create_qp(struct ib_qp *ibqp,
  	kref_init(&qp->qp_kref);
 
  	write_lock_irqsave(&dev->qp_tbl_rw, irqflags);
+	// GFP_KERNEL is wrong, this is an atomic context becuse of the above. Should't a debug kernel catch this?
  	rc = xa_err(xa_store(&dev->qp_tbl, qp->qpid, qp, GFP_KERNEL));
+	// Poor use of xa_err, more like: (same for other xarrays)
+	ent = xa_store(&dev->qp_tbl, qp->qpid, qp, GFP_KERNEL);
+
  	write_unlock_irqrestore(&dev->qp_tbl_rw, irqflags);
-	if (rc)
+	if (ent) {
+		if (WARN_ON(!xa_is_err(ent)))
+			rc = -EINVAL;
+		else
+			rc = xa_err(ent);
  		goto err_xa;
+	}
 
  	if (qp->has_sq) {
  		cq = to_ionic_vcq_cq(attr->send_cq, qp->udma_idx);
+		// WTF is is? Needs a comment, but probably this is wrong.
  		spin_lock_irqsave(&cq->lock, irqflags);
  		spin_unlock_irqrestore(&cq->lock, irqflags);
 
@@ -2826,6 +2854,7 @@ static int ionic_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
  	if (rc)
  		return rc;
 
+	// You can also check that xa_erase returns qp and warn otherwise as something is corrupted.
  	write_lock_irqsave(&dev->qp_tbl_rw, irqflags);
  	xa_erase(&dev->qp_tbl, qp->qpid);
  	write_unlock_irqrestore(&dev->qp_tbl_rw, irqflags);
@@ -2903,8 +2932,14 @@ static const struct ib_device_ops ionic_controlpath_ops = {
 
  void ionic_controlpath_setops(struct ionic_ibdev *dev)
  {
+	/* This is not how set_device_ops is ment to be used. It should only be
+	used for things that are optional based on some runtime detection.
+	Always present ops should be hardwired into the main op. */
  	ib_set_device_ops(&dev->ibdev, &ionic_controlpath_ops);
 
+	/* This is old, drivers should not set these. Only a few special ones
+	need the driver to do anything. The core code computes this based on
+	what ops pointers are not null. Same for all places doing this */
  	dev->ibdev.uverbs_cmd_mask |=
  		BIT_ULL(IB_USER_VERBS_CMD_ALLOC_PD)		|
  		BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_PD)		|
drivers/infiniband/hw/ionic/ionic_datapath.c +3 -0
index 1262ba30172d77..ff6cff06c8575b 100644
@@ -21,6 +21,7 @@ static bool ionic_next_cqe(struct ionic_ibdev *dev, struct ionic_cq *cq,
  		return false;
 
  	/* Prevent out-of-order reads of the CQE */
+	// dma_rmb
  	rmb();
 
  	*cqe = qcqe;
@@ -639,6 +640,7 @@ static int ionic_poll_cq(struct ib_cq *ibcq, int nwc, struct ib_wc *wc)
  	int cq_i, cq_x, cq_ix;
 
  	/* poll_idx is not protected by a lock, but a race is benign */
+	// Use READ_ONCE and WRITE_ONCE then
  	cq_x = vcq->poll_idx;
 
  	vcq->poll_idx ^= dev->lif_cfg.udma_count - 1;
@@ -1411,6 +1413,7 @@ static const struct ib_device_ops ionic_datapath_ops = {
 
  void ionic_datapath_setops(struct ionic_ibdev *dev)
  {
+	// Same remark about ops and uverbs_cmd_mask
  	ib_set_device_ops(&dev->ibdev, &ionic_datapath_ops);
 
  	dev->ibdev.uverbs_cmd_mask |=
drivers/infiniband/hw/ionic/ionic_fw.h +1 -0
index 2d9a2e9a0b60cf..0b58cc66d04573 100644
@@ -974,6 +974,7 @@ enum ionic_tfp_csum_profiles {
 
  static inline bool ionic_v1_eqe_color(struct ionic_v1_eqe *eqe)
  {
+	// Don't need !! when casting to bool
  	return !!(eqe->evt & cpu_to_be32(IONIC_V1_EQE_COLOR));
  }
 
drivers/infiniband/hw/ionic/ionic_hw_stats.c +1 -0
index 29f2571463ac3a..facc015b970295 100644
@@ -464,6 +464,7 @@ void ionic_stats_init(struct ionic_ibdev *dev)
 
  		xa_init_flags(&dev->counter_stats->xa_counters, XA_FLAGS_ALLOC);
 
+		// This is the right usage since it is conditional
  		ib_set_device_ops(&dev->ibdev, &ionic_counter_stats_ops);
  	}
  }
drivers/infiniband/hw/ionic/ionic_ibdev.c +2 -0
index e292278fcbba4a..a8a8fc015c0e1e 100644
@@ -26,6 +26,7 @@ static const struct auxiliary_device_id ionic_aux_id_table[] = {
 
  MODULE_DEVICE_TABLE(auxiliary, ionic_aux_id_table);
 
+/* Why have this wrapper, just call the dispatch event from the only call site */
  void ionic_port_event(struct ionic_ibdev *dev, enum ib_event_type event)
  {
  	struct ib_event ev;
@@ -332,6 +333,7 @@ static void ionic_destroy_ibdev(struct ionic_ibdev *dev)
  	ionic_stats_cleanup(dev);
  	ionic_destroy_rdma_admin(dev);
  	ionic_destroy_resids(dev);
+	// Should WARN_ON(xa_is_empty()) to catch any bugs.
  	xa_destroy(&dev->qp_tbl);
  	xa_destroy(&dev->cq_tbl);
  	ib_dealloc_device(&dev->ibdev);

drivers/infiniband/hw/ionic/ionic_ibdev.c static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev) · line 392

Quoted 5 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c +1 -1
@@ -387,7 +389,7 @@ static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
 
  	addrconf_ifid_eui48((u8 *)&ibdev->node_guid,
  			    ionic_lif_netdev(ionic_adev->lif));
-
+mmap_off

Assuming this was unintentional edit.

Quoted 16 lines
drivers/infiniband/hw/ionic/ionic_ibdev.c +0 -0
  	rc = ib_device_set_netdev(ibdev, ionic_lif_netdev(ionic_adev->lif), 1);
  	if (rc)
  		goto err_admin;
drivers/infiniband/hw/ionic/ionic_ibdev.h +1 -0
index 803127c625cc2f..4d966c27c2791b 100644
@@ -137,6 +137,7 @@ struct ionic_eq {
 
  	struct ionic_queue	q;
 
+	// bool due to how xchg is used
  	int			armed;
  	bool			enable;
 

drivers/infiniband/hw/ionic/ionic_ibdev.h struct ionic_cq { · line 232

Quoted 6 lines
drivers/infiniband/hw/ionic/ionic_ibdev.h +2 -0
@@ -226,7 +227,9 @@ struct ionic_cq {
  	struct list_head	cq_list_ent;
 
  	struct ionic_queue	q;
+	// Linus has been known to complain about multiple bools in the same struct
  	bool			color;
+	// Why? This is not ABI?

It is not meant as reserved. We will pick better name for it.

Thanks,
Abhijit

Quoted 63 lines
drivers/infiniband/hw/ionic/ionic_ibdev.h +0 -0
  	int			reserve;
  	u16			arm_any_prod;
  	u16			arm_sol_prod;
drivers/infiniband/hw/ionic/ionic_res.c +6 -0
index a3b4f10aa4c84b..2d1559b42de537 100644
@@ -7,13 +7,17 @@
 
  #include "ionic_res.h"
 
+// None of these types should be int. Use unsigned long/int or size_t as appropriate. For everywhere.
  int ionic_resid_init(struct ionic_resid_bits *resid, int size)
  {
+	// sizeof(unsigned long)
+	// size_t not int
  	int size_bytes = sizeof(long) * BITS_TO_LONGS(size);
 
  	resid->next_id = 0;
  	resid->inuse_size = size;
 
+	// Use kcalloc
  	resid->inuse = kzalloc(size_bytes, GFP_KERNEL);
  	if (!resid->inuse)
  		return -ENOMEM;
@@ -21,11 +25,13 @@ int ionic_resid_init(struct ionic_resid_bits *resid, int size)
  	return 0;
  }
 
+// All ints are unsigned
  int ionic_resid_get_shared(struct ionic_resid_bits *resid, int wrap_id,
  			   int next_id, int size)
  {
  	int id;
 
+	/* Are you sure you don't want to use an IDR? */
  	id = find_next_zero_bit(resid->inuse, size, next_id);
  	if (id != size) {
  		set_bit(id, resid->inuse);
drivers/infiniband/hw/ionic/ionic_res.h +4 -0
index e833ced1466e89..1aa9118db25fbf 100644
@@ -4,6 +4,8 @@
  #ifndef _IONIC_RES_H_
  #define _IONIC_RES_H_
 
+/* Missing include files for header self compilation */
+
  /**
   * struct ionic_resid_bits - Number allocator based on find_first_zero_bit
   *
@@ -24,7 +26,9 @@
   * remains bounded by O(N^2) in the worst case.
   */
  struct ionic_resid_bits {
+	// unsigned int
  	int next_id;
+	// size_t
  	int inuse_size;
  	unsigned long *inuse;
  };
maintainer
#23 lore raw
Quoted 9 lines · Abhijit Gangurde

drivers/infiniband/hw/ionic/ionic_admin.c void ionic_destroy_rdma_admin(struct ionic_ibdev *dev) · line 1262

Quoted 7 lines
drivers/infiniband/hw/ionic/ionic_admin.c +1 -0
@@ -1231,6 +1257,7 @@ void ionic_destroy_rdma_admin(struct ionic_ibdev *dev)
  	}
  	if (dev->eq_vec) {
+		// Locking? Add a lockdep assertion if caller is holding the lock
  		while (dev->lif_cfg.eq_count > 0) {
  			eq = dev->eq_vec[--dev->lif_cfg.eq_count];
  			ionic_destroy_eq(eq);

I don't think there is a need for the lock here because the device is unregistered and the queues are all stopped.

Add a comment then

Quoted 10 lines

drivers/infiniband/hw/ionic/ionic_controlpath.c static struct ib_mr *ionic_get_dma_mr(struct ib_pd *ibpd, int access) · line 898

Quoted 7 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +2 -0
@@ -887,6 +893,8 @@ static struct ib_mr *ionic_get_dma_mr(struct ib_pd *ibpd, int access)
  	if (!mr)
  		return ERR_PTR(-ENOMEM);
+	// This seems strange, shouldn't this do something? If you don't support an all address MR then don't define this op.
+
  	return &mr->ibmr;
  }

From hardware lkey zero is reserved as a local dma lkey for all address MR. I would make it more explicit as mr.ibmr.lkey = IONIC_DMA_LKEY (same for RKEY) with that defined to be zero.

Yeah, that's a lot clearer

Quoted 9 lines
Quoted 9 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +3 -0
@@ -1454,11 +1466,15 @@ static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
  static bool pd_local_privileged(struct ib_pd *pd)
  {
+	/* That isn't how it works, only the lkey get_dma_mr() returns is
+	special and must be used on any WRs that require it. WRs refering to any
+	other lkeys must behave normally. */
  	return !pd->uobject;
  }
  static bool pd_remote_privileged(struct ib_pd *pd)
Quoted 8 lines

drivers/infiniband/hw/ionic/ionic_controlpath.c static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) · line 1479

Quoted 4 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +1 -0
  {
+	/* Same comment, except about rkeys now. */
  	return pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY;
  }

This is how we allow the qp to use the dma lkey.  If the qp is a kernel space qp (its pd has no uobject) then we allow use of the dma lkey by that qp.  We do not allow use of dma lkey by user qps.  If the pd flags has the unsafe rkey flag, then we also allow the qp use it for remote access.

OK, so this is just about permissions because you don't attach the 0 l/rkey to a PD? Add a comment in the ionic_get_dma_mr() that the QP needs special flags to be allowed to use the 0 l/rkey.

Jason

maintainer
#24 lore raw
Quoted 8 lines · Jason Gunthorpe
Quoted 8 lines

drivers/infiniband/hw/ionic/ionic_controlpath.c static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) · line 1472

Quoted 8 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +3 -0
@@ -1454,11 +1466,15 @@ static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
  static bool pd_local_privileged(struct ib_pd *pd)
  {
+	/* That isn't how it works, only the lkey get_dma_mr() returns is
+	special and must be used on any WRs that require it. WRs refering to any
+	other lkeys must behave normally. */
  	return !pd->uobject;
  }

I was thinking about this some more, probably the call to get_dma_mr() should set a flag in the pd struct (you need a pds_pd struct) which indicates that the IONIC_DMA_LKEY is enabled on that PD. Then all QPs/etc created against the PD should allow using it.

Checking a uobject here is just a little weird.

Jason

author maintainer
#25 lore raw
Quoted 14 lines · Jason Gunthorpe
Quoted 8 lines · Jason Gunthorpe
Quoted 8 lines

drivers/infiniband/hw/ionic/ionic_controlpath.c static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) · line 1472

Quoted 8 lines
drivers/infiniband/hw/ionic/ionic_controlpath.c +3 -0
@@ -1454,11 +1466,15 @@ static int ionic_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
   static bool pd_local_privileged(struct ib_pd *pd)
   {
+	/* That isn't how it works, only the lkey get_dma_mr() returns is
+	special and must be used on any WRs that require it. WRs refering to any
+	other lkeys must behave normally. */
   	return !pd->uobject;
   }

I was thinking about this some more, probably the call to get_dma_mr() should set a flag in the pd struct (you need a pds_pd struct) which indicates that the IONIC_DMA_LKEY is enabled on that PD. Then all QPs/etc created against the PD should allow using it.

Quoted 3 lines

Checking a uobject here is just a little weird.

Jason

Sure. Will use a flag inside pd to indicate use of local key.

Thanks,
Abhijit