Skip to contentSkip to conversation

Broadcom User Space RoCE Driver

PATCH RESEND Superseded Devesh Sharma 3 participants 15 messages Apr 21, 2017 – Apr 24, 2017 7 messages not in the archive InfiniBand

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Broadcom User Space RoCE Driver

This series introduces the user space RoCE driver for the Broadcom NetXtreme-E 10/25/40/50 RDMA Ethernet Controller. This driver is dependent on the bnxt_re driver posted earlier to linux-rdma community and is under reveiw.

This patch series is based on the latest master of rdma-core repository hosted at https://github.com/linux-rdma/rdma-core.git

The GIT for this library is hosted at following URL on github
https://github.com/dsharma283/bnxtre-rdma-core.git
branch: bnxtre-v4

Please review and give your valuable feedback for the betterment.

v3->v4
-- Call correct memory-barrier functions before
db ring and before CQE read.
-- Fix sparse warnings.
-- Fix ABI structures and allow byte conversion
when assiging the actual values to the device
specific data-structures.
-- Drop "0009-Add support for SRQ in user lib".

v2->v3
-- Take care of build failure with travis
-- moved wmb() closer to DB rings and used
udma_ordering_write_barrier() instead.
-- Rebased to tip of git tree.

v1->v2
-- Rename directory from bnxtre to bnxt_re
-- Squashed byte-order conversion patch
-- Removed version.h file

Devesh Sharma (8):
libbnxt_re: introduce bnxtre user space RDMA provider
libbnxt_re: Add support for user memory regions
libbnxt_re: Add support for CQ and QP management
libbnxt_re: Add support for posting and polling
libbnxt_re: Allow apps to poll for flushed completions
libbnxt_re: Enable UD control path and wqe posting
libbnxt_re: Enable polling for UD completions
libbnxt_re: Add support for atomic operations

 CMakeLists.txt                   |    1 +
 MAINTAINERS                      |    5 +
 providers/bnxt_re/CMakeLists.txt |    6 +
 providers/bnxt_re/bnxt_re-abi.h  |  353 ++++++++++
 providers/bnxt_re/db.c           |   93 +++
 providers/bnxt_re/flush.h        |   85 +++
 providers/bnxt_re/main.c         |  218 ++++++
 providers/bnxt_re/main.h         |  376 +++++++++++
 providers/bnxt_re/memory.c       |   76 +++
 providers/bnxt_re/memory.h       |  122 ++++
 providers/bnxt_re/verbs.c        | 1385 ++++++++++++++++++++++++++++++++++++++
 providers/bnxt_re/verbs.h        |  101 +++
 12 files changed, 2821 insertions(+)
 create mode 100644 providers/bnxt_re/CMakeLists.txt
 create mode 100644 providers/bnxt_re/bnxt_re-abi.h
 create mode 100644 providers/bnxt_re/db.c
 create mode 100644 providers/bnxt_re/flush.h
 create mode 100644 providers/bnxt_re/main.c
 create mode 100644 providers/bnxt_re/main.h
 create mode 100644 providers/bnxt_re/memory.c
 create mode 100644 providers/bnxt_re/memory.h
 create mode 100644 providers/bnxt_re/verbs.c
 create mode 100644 providers/bnxt_re/verbs.h
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1492801032-17587-1-git-send-email-devesh.sharma-dY08KVG/lbpWk0Htik3J/[email protected]

#2 lore raw

PATCH RESEND v4 1/8 libbnxt_re: introduce bnxtre user space RDMA provider

libnxtre is a user-space driver which provides RDMA capability to user applications. The current framework has following parts working:

-Basic Cmake framework to build and install the library. -Register and unregister user-space driver with uverbs
interface.
-List all available bnxt_re devices using "ibv_devinfo"
admin command.
-List all the device and port attributes using
"ibv_devinfo" admin command.
-Support allocate/free of protection domains. -Check ABI version between library and kernel module. -Update MAINTAINERS file

v3->v4
-- Changed "bnxtre" to "bnxt_re" in main.h and main.c

v1->v2:
--Deleted bnxtre.driver file
--Dropped HAVE_CONFIG_H macro and cna_table declaration --Renamed abi.h to bnxt_re-abi.h

---
 CMakeLists.txt                   |   1 +
 MAINTAINERS                      |   5 +
 providers/bnxt_re/CMakeLists.txt |   4 +
 providers/bnxt_re/bnxt_re-abi.h  |  59 ++++++++++
 providers/bnxt_re/main.c         | 190 ++++++++++++++++++++++++++++++
 providers/bnxt_re/main.h         | 110 ++++++++++++++++++
 providers/bnxt_re/verbs.c        | 244 +++++++++++++++++++++++++++++++++++++++
 providers/bnxt_re/verbs.h        | 101 ++++++++++++++++
 8 files changed, 714 insertions(+)
 create mode 100644 providers/bnxt_re/CMakeLists.txt
 create mode 100644 providers/bnxt_re/bnxt_re-abi.h
 create mode 100644 providers/bnxt_re/main.c
 create mode 100644 providers/bnxt_re/main.h
 create mode 100644 providers/bnxt_re/verbs.c
 create mode 100644 providers/bnxt_re/verbs.h
CMakeLists.txt +1 -0
index 1ff3189..29c6164 100644
@@ -376,6 +376,7 @@ add_subdirectory(libibcm)
 
 # Providers
 if (HAVE_COHERENT_DMA)
+add_subdirectory(providers/bnxt_re)
 add_subdirectory(providers/cxgb3) # NO SPARSE
 add_subdirectory(providers/cxgb4) # NO SPARSE
 add_subdirectory(providers/hns) # NO SPARSE
MAINTAINERS +5 -0
index 2ae504c..19fe88d 100644
@@ -40,6 +40,11 @@ F:	*/CMakeLists.txt
 F:	*/lib*.map
 F:	buildlib/
 
+BNXT_RE USERSPACE PROVIDER (for bnxt_re.ko)
+M:	Devesh Sharma  <Devesh.sharma-dY08KVG/lbpWk0Htik3J/[email protected]>
+S:	Supported
+F:	providers/bnxt_re/
+
 CXGB3 USERSPACE PROVIDER (for iw_cxgb3.ko)
 M:	Steve Wise <[email protected]>
 S:	Supported
providers/bnxt_re/CMakeLists.txt new file +4 -0
new file mode 100644
index 0000000..45e609d
@@ -0,0 +1,4 @@
+rdma_provider(bnxt_re
+	main.c
+	verbs.c
+)
providers/bnxt_re/bnxt_re-abi.h new file +59 -0

59 lines not on this page · raw message

providers/bnxt_re/main.c new file +190 -0

190 lines not on this page · raw message

providers/bnxt_re/main.h new file +110 -0

110 lines not on this page · raw message

providers/bnxt_re/verbs.c new file +244 -0

244 lines not on this page · raw message

providers/bnxt_re/verbs.h new file +101 -0

101 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH RESEND v4 2/8 libbnxt_re: Add support for user memory regions

In reply to a message not in the archive

This patch adds code to allow user applications to register and unregister memory buffers with the HCA. Following functions are now supported:
- ibv_reg_mr()
- ibv_dereg_mr()

---
 providers/bnxt_re/bnxt_re-abi.h |  4 ++++
 providers/bnxt_re/verbs.c       | 26 ++++++++++++++++++++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)
providers/bnxt_re/bnxt_re-abi.h +4 -0
index 05a0888..53645d5 100644
@@ -56,4 +56,8 @@ struct bnxt_re_pd_resp {
 	__u64 dbr;
 };
 
+struct bnxt_re_mr_resp {
+	struct ibv_reg_mr_resp resp;
+};
+
 #endif
providers/bnxt_re/verbs.c +24 -2
index 3993c61..f67e37d 100644
@@ -131,12 +131,34 @@ int bnxt_re_free_pd(struct ibv_pd *ibvpd)
 struct ibv_mr *bnxt_re_reg_mr(struct ibv_pd *ibvpd, void *sva, size_t len,
 			      int access)
 {
-	return NULL;
+	struct bnxt_re_mr *mr;
+	struct ibv_reg_mr cmd;
+	struct bnxt_re_mr_resp resp;
+
+	mr = calloc(1, sizeof(*mr));
+	if (!mr)
+		return NULL;
+
+	if (ibv_cmd_reg_mr(ibvpd, sva, len, (uintptr_t)sva, access, &mr->ibvmr,
+			   &cmd, sizeof(cmd), &resp.resp, sizeof(resp))) {
+		free(mr);
+		return NULL;
+	}
+
+	return &mr->ibvmr;
 }
 
 int bnxt_re_dereg_mr(struct ibv_mr *ibvmr)
 {
-	return -ENOSYS;
+	struct bnxt_re_mr *mr = (struct bnxt_re_mr *)ibvmr;
+	int status;
+
+	status = ibv_cmd_dereg_mr(ibvmr);
+	if (status)
+		return status;
+	free(mr);
+
+	return 0;
 }
 
 struct ibv_cq *bnxt_re_create_cq(struct ibv_context *ibvctx, int ncqe,
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH RESEND v4 3/8 libbnxt_re: Add support for CQ and QP management

In reply to a message not in the archive

This patch adds support for completion queue creation and destruction following are the changes:

- Added User/Kernel ABI to communicate CQ specific parameters.
- Added a function in a new file to allocate Page-Aligned address space.
- Added a function to free page-aligned address space.
- Added function to create and destroy completion queue.
- Add ABI to for QP creation and WQE/RQE format.
- Add functions to allocate SQ, RQ and Search PSN address space.
- Add functions to store/clean qp-handles in the form of a linear table. There is table maintained in every instance of ucontext.
- CQ and QP contexts now hold a pointer to the DPI mapped during PD allocation.
- Removed hard-coding of page size during mapping DB page.
- Renamed a variable in PD code.
- Add support for create-qp.
- Add support for destroy-qp.
- Add support for modify-qp.
- Add support for query-qp.

v3->v4
-- change ABI declarations to use __leXX typedef
v1->v2
-- Sorted file list
-- Removed inline functions from ahi.h

---
 providers/bnxt_re/CMakeLists.txt |   1 +
 providers/bnxt_re/bnxt_re-abi.h  | 106 ++++++++++++++++++
 providers/bnxt_re/main.c         |   5 +
 providers/bnxt_re/main.h         |  73 ++++++++++--
 providers/bnxt_re/memory.c       |  76 +++++++++++++
 providers/bnxt_re/memory.h       |  76 +++++++++++++
 providers/bnxt_re/verbs.c        | 236 ++++++++++++++++++++++++++++++++++++++-
 7 files changed, 555 insertions(+), 18 deletions(-)
 create mode 100644 providers/bnxt_re/memory.c
 create mode 100644 providers/bnxt_re/memory.h
providers/bnxt_re/CMakeLists.txt +1 -0
index 45e609d..7ea5ed8 100644
@@ -1,4 +1,5 @@
 rdma_provider(bnxt_re
 	main.c
+	memory.c
 	verbs.c
 )
providers/bnxt_re/bnxt_re-abi.h +106 -0

116 lines not on this page · raw message

providers/bnxt_re/main.c +5 -0
index 4e12e87..34f75fd 100644
@@ -110,8 +110,10 @@ static int bnxt_re_init_context(struct verbs_device *vdev,
 {
 	struct ibv_get_context cmd;
 	struct bnxt_re_cntx_resp resp;
+	struct bnxt_re_dev *dev;
 	struct bnxt_re_context *cntx;
 
+	dev = to_bnxt_re_dev(&vdev->device);
 	cntx = to_bnxt_re_context(ibvctx);
 
 	memset(&resp, 0, sizeof(resp));
@@ -122,6 +124,9 @@ static int bnxt_re_init_context(struct verbs_device *vdev,
 
 	cntx->dev_id = resp.dev_id;
 	cntx->max_qp = resp.max_qp;
+	dev->pg_size = resp.pg_size;
+	dev->cqe_size = resp.cqe_size;
+	dev->max_cq_depth = resp.max_cqd;
 	ibvctx->ops = bnxt_re_cntx_ops;
 
 	return 0;
providers/bnxt_re/main.h +61 -12

102 lines not on this page · raw message

providers/bnxt_re/memory.c new file +76 -0

76 lines not on this page · raw message

providers/bnxt_re/memory.h new file +76 -0

76 lines not on this page · raw message

providers/bnxt_re/verbs.c +230 -6

296 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

PATCH RESEND v4 4/8 libbnxt_re: Add support for posting and polling

In reply to a message not in the archive

This patch adds code to support ibv_post_recv(), ibv_post_send(), ibv_poll_cq() and ibv_arm_cq() routines. With this patch applications are able to enqueue RQE or WQE ring doorbells and poll for completions from CQ. Currently, this code do not support SRQ, UD service and and flush completions. Following are the major changes:

- Added most of the enums to handle device specific opcodes, masks, shifts and data structures.
- Added a new file to define DB related routines.
- Added routines to handle circular queue operations.
- Added enums and few utility functions.
- Added bnxt_re_post_recv().
- Add code to build and post SQEs for RDMA-WRITE, RDMA-READ, SEND through bnxt_re_post_send() routine.
- Fixed couple of bugs in create-qp and modify-qp.
- bnxt_re_create_qp() now check the limits.
- Add polling support for RC send completions.
- Add polling support for RC Recv completions.
- Add support to ARM completion queue.
- Cleanup CQ while QP is being destroyed.
- Add utility functions to convert chip specific completion codes to IB stack specific codes.

v3->v4
-- change the write memory barrier and read memory barrier
calls.
-- removed one time byte-order conversion, convert while
assigning instead.
-- take care of sparse error and warnnings.

v1->v2
-- Delete redefinition of "true" and "false" -- Removed unwanted wmb()
-- Removed dead code and fixed return type mismatch.

---
 providers/bnxt_re/CMakeLists.txt |   1 +
 providers/bnxt_re/bnxt_re-abi.h  | 174 ++++++++++-
 providers/bnxt_re/db.c           |  93 ++++++
 providers/bnxt_re/main.c         |   1 +
 providers/bnxt_re/main.h         | 201 +++++++++++-
 providers/bnxt_re/memory.h       |  31 ++
 providers/bnxt_re/verbs.c        | 654 ++++++++++++++++++++++++++++++++++++---
 7 files changed, 1114 insertions(+), 41 deletions(-)
 create mode 100644 providers/bnxt_re/db.c
providers/bnxt_re/CMakeLists.txt +1 -0
index 7ea5ed8..13ad287 100644
@@ -1,4 +1,5 @@
 rdma_provider(bnxt_re
+	db.c
 	main.c
 	memory.c
 	verbs.c
providers/bnxt_re/bnxt_re-abi.h +172 -2

196 lines not on this page · raw message

providers/bnxt_re/db.c new file +93 -0

93 lines not on this page · raw message

providers/bnxt_re/main.c +1 -0
index 34f75fd..73bab84 100644
@@ -105,6 +105,7 @@ static struct ibv_context_ops bnxt_re_cntx_ops = {
 	.destroy_ah    = bnxt_re_destroy_ah
 };
 
+/* Context Init functions */
 static int bnxt_re_init_context(struct verbs_device *vdev,
 				struct ibv_context *ibvctx, int cmd_fd)
 {
providers/bnxt_re/main.h +197 -4

242 lines not on this page · raw message

providers/bnxt_re/memory.h +31 -0
index ea29a24..4d6ab4d 100644
@@ -73,4 +73,35 @@ static inline unsigned long roundup_pow_of_two(unsigned long val)
 int bnxt_re_alloc_aligned(struct bnxt_re_queue *que, uint32_t pg_size);
 void bnxt_re_free_aligned(struct bnxt_re_queue *que);
 
+static inline void iowrite64(__u64 *dst, __le64 *src)
+{
+	*(volatile __le64 *)dst = *src;
+}
+
+static inline void iowrite32(__u32 *dst, __le32 *src)
+{
+	*(volatile __le32 *)dst = *src;
+}
+
+/* Basic queue operation */
+static inline uint32_t bnxt_re_is_que_full(struct bnxt_re_queue *que)
+{
+	return (((que->tail + 1) & (que->depth - 1)) == que->head);
+}
+
+static inline uint32_t bnxt_re_incr(uint32_t val, uint32_t max)
+{
+	return (++val & (max - 1));
+}
+
+static inline void bnxt_re_incr_tail(struct bnxt_re_queue *que)
+{
+	que->tail = bnxt_re_incr(que->tail, que->depth);
+}
+
+static inline void bnxt_re_incr_head(struct bnxt_re_queue *que)
+{
+	que->head = bnxt_re_incr(que->head, que->depth);
+}
+
 #endif
providers/bnxt_re/verbs.c +619 -35

741 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1492801032-17587-5-git-send-email-devesh.sharma-dY08KVG/lbpWk0Htik3J/[email protected]

#7 lore raw

Re: [RESEND rdma-core v4 4/8] libbnxt_re: Add support for posting and polling

providers/bnxt_re/db.c line 52

Quoted 11 lines · Devesh Sharma
providers/bnxt_re/db.c new file +11 -0
+static void bnxt_re_ring_db(struct bnxt_re_dpi *dpi,
+			    struct bnxt_re_db_hdr *hdr)
+{
+	__le64 *dbval;
+
+	pthread_spin_lock(&dpi->db_lock);
+	dbval = (__le64 *)&hdr->indx;
+	udma_to_device_barrier();
+	iowrite64(dpi->dbpage, dbval);
+	pthread_spin_unlock(&dpi->db_lock);
+}

What are you expecting this db_lock to do?

Is 'dbpage' UC or WC memory?

If this is UC memory then writing 64 bit values concurrently from multiple threads is OK and this lock does nothing.

If this is WC memory then you need to use mmio_wc_spinlock / mmio_wc_spinunlock instead, or the lock doesn't work right.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20170421192255.GA12079-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org

#9 lore raw

Re: [RESEND rdma-core v4 4/8] libbnxt_re: Add support for posting and polling

Quoted 16 lines · Jason Gunthorpe

providers/bnxt_re/db.c line 52

Quoted 11 lines · Devesh Sharma
providers/bnxt_re/db.c new file +11 -0
+static void bnxt_re_ring_db(struct bnxt_re_dpi *dpi,
+                         struct bnxt_re_db_hdr *hdr)
+{
+     __le64 *dbval;
+
+     pthread_spin_lock(&dpi->db_lock);
+     dbval = (__le64 *)&hdr->indx;
+     udma_to_device_barrier();
+     iowrite64(dpi->dbpage, dbval);
+     pthread_spin_unlock(&dpi->db_lock);
+}

What are you expecting this db_lock to do?

Quoted 1 line

Is 'dbpage' UC or WC memory?

Driver re-maps it as "UC-" where strong ordering is guaranteed. How system would handle 64-bit writes will it issue two 32-bit consecutive writes on the bus?

Quoted 8 lines

If this is UC memory then writing 64 bit values concurrently from multiple threads is OK and this lock does nothing.

If this is WC memory then you need to use mmio_wc_spinlock / mmio_wc_spinunlock instead, or the lock doesn't work right.

Jason

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CANjDDBiG_0C1DTYKgwCPuUzs34yb1b-iBpxRpU=XXZnm-JcOfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#11 lore raw

Re: [RESEND rdma-core v4 4/8] libbnxt_re: Add support for posting and polling

Quoted 18 lines · Devesh Sharma
Quoted 16 lines · Jason Gunthorpe

providers/bnxt_re/db.c line 52

Quoted 11 lines · Devesh Sharma
providers/bnxt_re/db.c new file +11 -0
+static void bnxt_re_ring_db(struct bnxt_re_dpi *dpi,
+                         struct bnxt_re_db_hdr *hdr)
+{
+     __le64 *dbval;
+
+     pthread_spin_lock(&dpi->db_lock);
+     dbval = (__le64 *)&hdr->indx;
+     udma_to_device_barrier();
+     iowrite64(dpi->dbpage, dbval);
+     pthread_spin_unlock(&dpi->db_lock);
+}

What are you expecting this db_lock to do?

Quoted 5 lines
Quoted 1 line

Is 'dbpage' UC or WC memory?

Driver re-maps it as "UC-" where strong ordering is guaranteed. How system would handle 64-bit writes will it issue two 32-bit consecutive writes on the bus?

64 bit systems support 64 bit writes as a single TLP on the PCI-E, so the lock is not required.

If the write is broken up into two 32 bit transfers (eg as on a 32 bit processor) then the device usually requires them to be presented in address increasing order, however the compiler does not guarentee that with a simple 64 bit store as above.

Going forward we will merge the new shared mmio accessors:

https://github.com/jgunthorpe/rdma-plumbing/blob/mmio/util/mmio.h

Which provides sane common implementations for these operations.

For this reason I don't think there is much point in your spending time to open code a solution in your driver. Now that I know the lock is not doing anything it can just be dropped when the mmio accessors are merged.

Jasn
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20170424163416.GA23048-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org

#13 lore raw

Re: [RESEND rdma-core v4 4/8] libbnxt_re: Add support for posting and polling

Quoted 35 lines · Jason Gunthorpe
Quoted 18 lines · Devesh Sharma
Quoted 16 lines · Jason Gunthorpe

Review

Quoted 11 lines · Devesh Sharma
(quoted diff) +11 -0
+static void bnxt_re_ring_db(struct bnxt_re_dpi *dpi,
+                         struct bnxt_re_db_hdr *hdr)
+{
+     __le64 *dbval;
+
+     pthread_spin_lock(&dpi->db_lock);
+     dbval = (__le64 *)&hdr->indx;
+     udma_to_device_barrier();
+     iowrite64(dpi->dbpage, dbval);
+     pthread_spin_unlock(&dpi->db_lock);
+}

What are you expecting this db_lock to do?

Quoted 5 lines
Quoted 1 line

Is 'dbpage' UC or WC memory?

Driver re-maps it as "UC-" where strong ordering is guaranteed. How system would handle 64-bit writes will it issue two 32-bit consecutive writes on the bus?

64 bit systems support 64 bit writes as a single TLP on the PCI-E, so the lock is not required.

If the write is broken up into two 32 bit transfers (eg as on a 32 bit processor) then the device usually requires them to be presented in address increasing order, however the compiler does not guarentee that with a simple 64 bit store as above.

Going forward we will merge the new shared mmio accessors:

Quoted 8 lines

https://github.com/jgunthorpe/rdma-plumbing/blob/mmio/util/mmio.h

Which provides sane common implementations for these operations.

For this reason I don't think there is much point in your spending time to open code a solution in your driver. Now that I know the lock is not doing anything it can just be dropped when the mmio accessors are merged.

Okay, Thanks for the explanation, I will take care of Leon's comments and send out a v5, leaving the lock as it is for now.

Quoted 2 lines

Jasn

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

PATCH RESEND v4 5/8 libbnxt_re: Allow apps to poll for flushed completions

In reply to a message not in the archive

This patch adds support for reporting flush completions. following is the overview of the algorithm used.

Step-1: Poll a completion from h/w CQ.
Step-2: check the status, if it is error goto step3 else report
completion to user based on the con_idx reported.
Step-3: Report the completion with actual error to consumer, and
without bothering about the con_idx reported in the completion do following:
3a. Add this QP to the CQ flush list if it was not there
already. If this is req-error, add the QP to send-flush list, else add it to recv-flush-list.
3b. Change QP-soft-state to ERROR if it was not in error
already.

Step-4: If next CQE is TERM CQE, extract this CQE. make sure this CQE
is not reported to the consumer. Do the following steps as further processing:
4a. Add this QP to both send-flush-list and recv-flush-list
if QP is absent from any of the flush lists.
4b. Change QP-soft-state to ERROR if it was not in error
already.
Step5: Continue polling from both h/w CQ and flush-lists until
all the queues are empty.

The QP is removed from the flush list during destroy-qp.

Further, it adds network to host format conversion on the received immediate data.

This patch also takes care of Hardware specific requirement to skip reporting h/w flush error CQEs to consumer but ring the CQ-DB for them.

v1->v2
-- Used ccan/list.h instead.

---
 providers/bnxt_re/flush.h  |  85 ++++++++++++++++
 providers/bnxt_re/main.c   |   5 +
 providers/bnxt_re/main.h   |   6 ++
 providers/bnxt_re/memory.h |   5 +
 providers/bnxt_re/verbs.c  | 245 ++++++++++++++++++++++++++++++++++++++++-----
 5 files changed, 322 insertions(+), 24 deletions(-)
 create mode 100644 providers/bnxt_re/flush.h
providers/bnxt_re/flush.h new file +85 -0
new file mode 100644
index 0000000..a39ea71
@@ -0,0 +1,85 @@
+/*
+ * Broadcom NetXtreme-E User Space RoCE driver
+ *
+ * Copyright (c) 2015-2017, Broadcom. All rights reserved.  The term
+ * Broadcom refers to Broadcom Limited and/or its subsidiaries.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Description: A few wrappers for flush queue management
+ */
+
+#ifndef __FLUSH_H__
+#define __FLUSH_H__
+
+#include <ccan/list.h>
+
+struct bnxt_re_fque_node {
+	uint8_t valid;
+	struct list_node list;
+};
+
+static inline void fque_init_node(struct bnxt_re_fque_node *node)
+{
+	list_node_init(&node->list);
+	node->valid = false;
+}
+
+static inline void fque_add_node_tail(struct list_head *head,
+				      struct bnxt_re_fque_node *new)
+{
+	list_add_tail(head, &new->list);
+	new->valid = true;
+}
+
+static inline void fque_del_node(struct bnxt_re_fque_node *entry)
+{
+	entry->valid = false;
+	list_del(&entry->list);
+}
+
+static inline uint8_t _fque_node_valid(struct bnxt_re_fque_node *node)
+{
+	return node->valid;
+}
+
+static inline void bnxt_re_fque_add_node(struct list_head *head,
+					 struct bnxt_re_fque_node *node)
+{
+	if (!_fque_node_valid(node))
+		fque_add_node_tail(head, node);
+}
+
+static inline void bnxt_re_fque_del_node(struct bnxt_re_fque_node *node)
+{
+	if (_fque_node_valid(node))
+		fque_del_node(node);
+}
+#endif	/* __FLUSH_H__ */
providers/bnxt_re/main.c +5 -0
index 73bab84..e4c63f6 100644
@@ -128,6 +128,7 @@ static int bnxt_re_init_context(struct verbs_device *vdev,
 	dev->pg_size = resp.pg_size;
 	dev->cqe_size = resp.cqe_size;
 	dev->max_cq_depth = resp.max_cqd;
+	pthread_spin_init(&cntx->fqlock, PTHREAD_PROCESS_PRIVATE);
 	ibvctx->ops = bnxt_re_cntx_ops;
 
 	return 0;
@@ -136,7 +137,11 @@ static int bnxt_re_init_context(struct verbs_device *vdev,
 static void bnxt_re_uninit_context(struct verbs_device *vdev,
 				   struct ibv_context *ibvctx)
 {
+	struct bnxt_re_context *cntx;
+
+	cntx = to_bnxt_re_context(ibvctx);
 	/* Unmap if anything device specific was mapped in init_context. */
+	pthread_spin_destroy(&cntx->fqlock);
 }
 
 static struct verbs_device_ops bnxt_re_dev_ops = {
providers/bnxt_re/main.h +6 -0
index ee73282..7c05034 100644
@@ -50,6 +50,7 @@
 
 #include "bnxt_re-abi.h"
 #include "memory.h"
+#include "flush.h"
 
 #define DEV	"bnxt_re : "
 
@@ -69,6 +70,8 @@ struct bnxt_re_cq {
 	uint32_t cqid;
 	struct bnxt_re_queue cqq;
 	struct bnxt_re_dpi *udpi;
+	struct list_head sfhead;
+	struct list_head rfhead;
 	uint32_t cqe_size;
 	uint8_t  phase;
 };
@@ -104,6 +107,8 @@ struct bnxt_re_qp {
 	struct bnxt_re_cq *rcq;
 	struct bnxt_re_dpi *udpi;
 	struct bnxt_re_qpcap cap;
+	struct bnxt_re_fque_node snode;
+	struct bnxt_re_fque_node rnode;
 	uint32_t qpid;
 	uint32_t tbl_indx;
 	uint32_t sq_psn;
@@ -133,6 +138,7 @@ struct bnxt_re_context {
 	uint32_t max_qp;
 	uint32_t max_srq;
 	struct bnxt_re_dpi udpi;
+	pthread_spinlock_t fqlock;
 };
 
 /* DB ring functions used internally*/
providers/bnxt_re/memory.h +5 -0
index 4d6ab4d..0150d80 100644
@@ -89,6 +89,11 @@ static inline uint32_t bnxt_re_is_que_full(struct bnxt_re_queue *que)
 	return (((que->tail + 1) & (que->depth - 1)) == que->head);
 }
 
+static inline uint32_t bnxt_re_is_que_empty(struct bnxt_re_queue *que)
+{
+	return que->tail == que->head;
+}
+
 static inline uint32_t bnxt_re_incr(uint32_t val, uint32_t max)
 {
 	return (++val & (max - 1));
providers/bnxt_re/verbs.c +221 -24

318 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#15 lore raw

PATCH RESEND v4 6/8 libbnxt_re: Enable UD control path and wqe posting

In reply to a message not in the archive

This patch adds infrastructure needed to enable unreliable datagram control path. It also adds support to allow posting Send WQEs to UD QPs. Following are the major changes:

- Mmap the shared page exported from kernel driver to read AH-ID from kernel space.
- Adds support to create-AH and destroy-AH.
- Add support to allow posting UD WQEs.
- Do not use search-psn memory for UD QPs.

v1->v2
--Removed extra ref of PD in ah structure

---
 providers/bnxt_re/bnxt_re-abi.h |  7 ++++
 providers/bnxt_re/main.c        | 17 ++++++++
 providers/bnxt_re/main.h        | 12 ++++++
 providers/bnxt_re/verbs.c       | 91 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 113 insertions(+), 14 deletions(-)
providers/bnxt_re/bnxt_re-abi.h +7 -0
index 7062f3b..36b74cd 100644
@@ -174,6 +174,13 @@ enum bnxt_re_ud_flags_mask {
 	BNXT_RE_UD_FLAGS_ROCE_IPV6	= 0x03
 };
 
+enum bnxt_re_shpg_offt {
+	BNXT_RE_SHPG_BEG_RESV_OFFT	= 0x00,
+	BNXT_RE_SHPG_AVID_OFFT		= 0x10,
+	BNXT_RE_SHPG_AVID_SIZE		= 0x04,
+	BNXT_RE_SHPG_END_RESV_OFFT	= 0xFF0
+};
+
 struct bnxt_re_db_hdr {
 	__le32 indx;
 	__le32 typ_qid; /* typ: 4, qid:20*/
providers/bnxt_re/main.c +17 -0
index e4c63f6..da4dd06 100644
@@ -129,18 +129,35 @@ static int bnxt_re_init_context(struct verbs_device *vdev,
 	dev->cqe_size = resp.cqe_size;
 	dev->max_cq_depth = resp.max_cqd;
 	pthread_spin_init(&cntx->fqlock, PTHREAD_PROCESS_PRIVATE);
+	/* mmap shared page. */
+	cntx->shpg = mmap(NULL, dev->pg_size, PROT_READ | PROT_WRITE,
+			  MAP_SHARED, cmd_fd, 0);
+	if (cntx->shpg == MAP_FAILED) {
+		cntx->shpg = NULL;
+		goto failed;
+	}
+	pthread_mutex_init(&cntx->shlock, NULL);
+
 	ibvctx->ops = bnxt_re_cntx_ops;
 
 	return 0;
+failed:
+	fprintf(stderr, DEV "Failed to allocate context for device\n");
+	return errno;
 }
 
 static void bnxt_re_uninit_context(struct verbs_device *vdev,
 				   struct ibv_context *ibvctx)
 {
+	struct bnxt_re_dev *dev;
 	struct bnxt_re_context *cntx;
 
+	dev = to_bnxt_re_dev(&vdev->device);
 	cntx = to_bnxt_re_context(ibvctx);
 	/* Unmap if anything device specific was mapped in init_context. */
+	pthread_mutex_destroy(&cntx->shlock);
+	if (cntx->shpg)
+		munmap(cntx->shpg, dev->pg_size);
 	pthread_spin_destroy(&cntx->fqlock);
 }
 
providers/bnxt_re/main.h +12 -0
index 7c05034..1a4dc06 100644
@@ -123,6 +123,11 @@ struct bnxt_re_mr {
 	struct ibv_mr ibvmr;
 };
 
+struct bnxt_re_ah {
+	struct ibv_ah ibvah;
+	uint32_t avid;
+};
+
 struct bnxt_re_dev {
 	struct verbs_device vdev;
 	uint8_t abi_version;
@@ -138,6 +143,8 @@ struct bnxt_re_context {
 	uint32_t max_qp;
 	uint32_t max_srq;
 	struct bnxt_re_dpi udpi;
+	void *shpg;
+	pthread_mutex_t shlock;
 	pthread_spinlock_t fqlock;
 };
 
@@ -175,6 +182,11 @@ static inline struct bnxt_re_qp *to_bnxt_re_qp(struct ibv_qp *ibvqp)
 	return container_of(ibvqp, struct bnxt_re_qp, ibvqp);
 }
 
+static inline struct bnxt_re_ah *to_bnxt_re_ah(struct ibv_ah *ibvah)
+{
+        return container_of(ibvah, struct bnxt_re_ah, ibvah);
+}
+
 static inline uint32_t bnxt_re_get_sqe_sz(void)
 {
 	return sizeof(struct bnxt_re_bsqe) +
providers/bnxt_re/verbs.c +77 -14

134 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#16 lore raw

PATCH RESEND v4 7/8 libbnxt_re: Enable polling for UD completions

In reply to a message not in the archive

This patch adds support to allow polling of send
and recv completions for a UD qp.

---
 providers/bnxt_re/bnxt_re-abi.h |  6 ++++++
 providers/bnxt_re/verbs.c       | 43 +++++++++++++++++++++++++++--------------
 2 files changed, 35 insertions(+), 14 deletions(-)
providers/bnxt_re/bnxt_re-abi.h +6 -0
index 36b74cd..db11322 100644
@@ -174,6 +174,12 @@ enum bnxt_re_ud_flags_mask {
 	BNXT_RE_UD_FLAGS_ROCE_IPV6	= 0x03
 };
 
+enum bnxt_re_ud_cqe_mask {
+	BNXT_RE_UD_CQE_MAC_MASK		= 0xFFFFFFFFFFFFULL,
+	BNXT_RE_UD_CQE_SRCQPLO_MASK	= 0xFFFF,
+	BNXT_RE_UD_CQE_SRCQPLO_SHIFT	= 0x30
+};
+
 enum bnxt_re_shpg_offt {
 	BNXT_RE_SHPG_BEG_RESV_OFFT	= 0x00,
 	BNXT_RE_SHPG_AVID_OFFT		= 0x10,
providers/bnxt_re/verbs.c +29 -14

102 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

PATCH RESEND v4 8/8 libbnxt_re: Add support for atomic operations

In reply to a message not in the archive

This patch adds support for compare-and-swap and fetch-and-add atomic operations in user library.

v3->v4
-- Changed weq init code to match the DMA ABI.
v1->v2
-- Fixed the missing "break"
-- Changed macros to inline function

---
 providers/bnxt_re/bnxt_re-abi.h |  3 ++-
 providers/bnxt_re/main.h        |  8 ++++++-
 providers/bnxt_re/memory.h      | 10 ++++++++
 providers/bnxt_re/verbs.c       | 52 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 63 insertions(+), 10 deletions(-)
providers/bnxt_re/bnxt_re-abi.h +2 -1
index db11322..205d8c4 100644
@@ -54,7 +54,8 @@ enum bnxt_re_wr_opcode {
 	BNXT_RE_WR_OPCD_ATOMIC_FA	= 0x0B,
 	BNXT_RE_WR_OPCD_LOC_INVAL	= 0x0C,
 	BNXT_RE_WR_OPCD_BIND		= 0x0E,
-	BNXT_RE_WR_OPCD_RECV		= 0x80
+	BNXT_RE_WR_OPCD_RECV		= 0x80,
+	BNXT_RE_WR_OPCD_INVAL		= 0xFF
 };
 
 enum bnxt_re_wr_flags {
providers/bnxt_re/main.h +7 -1
index 1a4dc06..4cc8abd 100644
@@ -236,9 +236,15 @@ static inline uint8_t bnxt_re_ibv_to_bnxt_wr_opcd(uint8_t ibv_opcd)
 	case IBV_WR_RDMA_READ:
 		bnxt_opcd = BNXT_RE_WR_OPCD_RDMA_READ;
 		break;
+	case IBV_WR_ATOMIC_CMP_AND_SWP:
+		bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_CS;
+		break;
+	case IBV_WR_ATOMIC_FETCH_AND_ADD:
+		bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_FA;
+		break;
 		/* TODO: Add other opcodes */
 	default:
-		bnxt_opcd = 0xFF;
+		bnxt_opcd = BNXT_RE_WR_OPCD_INVAL;
 		break;
 	};
 
providers/bnxt_re/memory.h +10 -0
index 0150d80..dc5b352 100644
@@ -83,6 +83,16 @@ static inline void iowrite32(__u32 *dst, __le32 *src)
 	*(volatile __le32 *)dst = *src;
 }
 
+static inline __u32 upper_32_bits(uint64_t n)
+{
+	return (__u32)((n >> 16) >> 16);
+}
+
+static inline __u32 lower_32_bits(uint64_t n)
+{
+	return (__u32)(n & 0xFFFFFFFFUL);
+}
+
 /* Basic queue operation */
 static inline uint32_t bnxt_re_is_que_full(struct bnxt_re_queue *que)
 {
providers/bnxt_re/verbs.c +44 -8

83 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1492801032-17587-9-git-send-email-devesh.sharma-dY08KVG/lbpWk0Htik3J/[email protected]

#19 lore raw

Re: [RESEND rdma-core v4 8/8] libbnxt_re: Add support for atomic operations

Quoted 63 lines · Devesh Sharma

This patch adds support for compare-and-swap and fetch-and-add atomic operations in user library.

v3->v4
-- Changed weq init code to match the DMA ABI.
v1->v2
-- Fixed the missing "break"
-- Changed macros to inline function

---
 providers/bnxt_re/bnxt_re-abi.h |  3 ++-
 providers/bnxt_re/main.h        |  8 ++++++-
 providers/bnxt_re/memory.h      | 10 ++++++++
 providers/bnxt_re/verbs.c       | 52 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 63 insertions(+), 10 deletions(-)
providers/bnxt_re/bnxt_re-abi.h +2 -1
index db11322..205d8c4 100644
@@ -54,7 +54,8 @@ enum bnxt_re_wr_opcode {
 	BNXT_RE_WR_OPCD_ATOMIC_FA	= 0x0B,
 	BNXT_RE_WR_OPCD_LOC_INVAL	= 0x0C,
 	BNXT_RE_WR_OPCD_BIND		= 0x0E,
-	BNXT_RE_WR_OPCD_RECV		= 0x80
+	BNXT_RE_WR_OPCD_RECV		= 0x80,
+	BNXT_RE_WR_OPCD_INVAL		= 0xFF
 };
 
 enum bnxt_re_wr_flags {
providers/bnxt_re/main.h +7 -1
index 1a4dc06..4cc8abd 100644
@@ -236,9 +236,15 @@ static inline uint8_t bnxt_re_ibv_to_bnxt_wr_opcd(uint8_t ibv_opcd)
 	case IBV_WR_RDMA_READ:
 		bnxt_opcd = BNXT_RE_WR_OPCD_RDMA_READ;
 		break;
+	case IBV_WR_ATOMIC_CMP_AND_SWP:
+		bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_CS;
+		break;
+	case IBV_WR_ATOMIC_FETCH_AND_ADD:
+		bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_FA;
+		break;
 		/* TODO: Add other opcodes */
 	default:
-		bnxt_opcd = 0xFF;
+		bnxt_opcd = BNXT_RE_WR_OPCD_INVAL;
 		break;
 	};
 
providers/bnxt_re/memory.h +0 -0
index 0150d80..dc5b352 100644
@@ -83,6 +83,16 @@ static inline void iowrite32(__u32 *dst, __le32 *src)
 	*(volatile __le32 *)dst = *src;
 }
 

providers/bnxt_re/memory.h static inline void iowrite32(__u32 *dst, __le32 *src) · line 95

Quoted 10 lines
providers/bnxt_re/memory.h +10 -0
+static inline __u32 upper_32_bits(uint64_t n)
+{
+	return (__u32)((n >> 16) >> 16);
+}
+
+static inline __u32 lower_32_bits(uint64_t n)
+{
+	return (__u32)(n & 0xFFFFFFFFUL);
+}
+

It looks like leftovers, I don't see any usage of it.

Quoted 100 lines
providers/bnxt_re/memory.h +0 -0
 /* Basic queue operation */
 static inline uint32_t bnxt_re_is_que_full(struct bnxt_re_queue *que)
 {
providers/bnxt_re/verbs.c +44 -9
index 1f8ff8e..2768a56 100644
@@ -1068,6 +1068,8 @@ static int bnxt_re_build_send_sqe(struct bnxt_re_qp *qp, void *wqe,
 
 	/* Fill Header */
 	opcode = bnxt_re_ibv_to_bnxt_wr_opcd(wr->opcode);
+	if (opcode == BNXT_RE_WR_OPCD_INVAL)
+		return -EINVAL;
 	hdrval = (opcode & BNXT_RE_HDR_WT_MASK);
 
 	if (is_inline) {
@@ -1115,6 +1117,39 @@ static int bnxt_re_build_rdma_sqe(struct bnxt_re_qp *qp, void *wqe,
 	return len;
 }
 
+static int bnxt_re_build_cns_sqe(struct bnxt_re_qp *qp, void *wqe,
+				 struct ibv_send_wr *wr)
+{
+	struct bnxt_re_bsqe *hdr = wqe;
+	struct bnxt_re_atomic *sqe = ((void *)wqe +
+				      sizeof(struct bnxt_re_bsqe));
+	int len;
+
+	len = bnxt_re_build_send_sqe(qp, wqe, wr, false);
+	hdr->key_immd = htole32(wr->wr.atomic.rkey);
+	sqe->rva = htole64(wr->wr.atomic.remote_addr);
+	sqe->cmp_dt = htole64(wr->wr.atomic.compare_add);
+	sqe->swp_dt = htole64(wr->wr.atomic.swap);
+
+	return len;
+}
+
+static int bnxt_re_build_fna_sqe(struct bnxt_re_qp *qp, void *wqe,
+				 struct ibv_send_wr *wr)
+{
+	struct bnxt_re_bsqe *hdr = wqe;
+	struct bnxt_re_atomic *sqe = ((void *)wqe +
+				      sizeof(struct bnxt_re_bsqe));
+	int len;
+
+	len = bnxt_re_build_send_sqe(qp, wqe, wr, false);
+	hdr->key_immd = htole32(wr->wr.atomic.rkey);
+	sqe->rva = htole64(wr->wr.atomic.remote_addr);
+	sqe->cmp_dt = htole64(wr->wr.atomic.compare_add);
+
+	return len;
+}
+
 int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
 		      struct ibv_send_wr **bad)
 {
@@ -1168,27 +1203,28 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
 			else
 				bytes = bnxt_re_build_send_sqe(qp, sqe, wr,
 							       is_inline);
-			if (bytes < 0)
-				ret = (bytes == -EINVAL) ? EINVAL : ENOMEM;
 			break;
 		case IBV_WR_RDMA_WRITE_WITH_IMM:
 			hdr->key_immd = htole32(be32toh(wr->imm_data));
 		case IBV_WR_RDMA_WRITE:
 			bytes = bnxt_re_build_rdma_sqe(qp, sqe, wr, is_inline);
-			if (bytes < 0)
-				ret = ENOMEM;
 			break;
 		case IBV_WR_RDMA_READ:
 			bytes = bnxt_re_build_rdma_sqe(qp, sqe, wr, false);
-			if (bytes < 0)
-				ret = ENOMEM;
+			break;
+		case IBV_WR_ATOMIC_CMP_AND_SWP:
+			bytes = bnxt_re_build_cns_sqe(qp, sqe, wr);
+			break;
+		case IBV_WR_ATOMIC_FETCH_AND_ADD:
+			bytes = bnxt_re_build_fna_sqe(qp, sqe, wr);
 			break;
 		default:
-			ret = EINVAL;
+			bytes = -EINVAL;
 			break;
 		}
 
-		if (ret) {
+		if (bytes < 0) {
+			ret = (bytes == -EINVAL) ? EINVAL : ENOMEM;
 			*bad = wr;
 			break;
 		}
--

1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20170422103309.GX14088-U/[email protected]

#21 lore raw

Re: [RESEND rdma-core v4 8/8] libbnxt_re: Add support for atomic operations

Quoted 65 lines · Leon Romanovsky
Quoted 63 lines · Devesh Sharma

This patch adds support for compare-and-swap and fetch-and-add atomic operations in user library.

v3->v4
-- Changed weq init code to match the DMA ABI.
v1->v2
-- Fixed the missing "break"
-- Changed macros to inline function

---
 providers/bnxt_re/bnxt_re-abi.h |  3 ++-
 providers/bnxt_re/main.h        |  8 ++++++-
 providers/bnxt_re/memory.h      | 10 ++++++++
 providers/bnxt_re/verbs.c       | 52 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 63 insertions(+), 10 deletions(-)
providers/bnxt_re/bnxt_re-abi.h +2 -1
index db11322..205d8c4 100644
@@ -54,7 +54,8 @@ enum bnxt_re_wr_opcode {
      BNXT_RE_WR_OPCD_ATOMIC_FA       = 0x0B,
      BNXT_RE_WR_OPCD_LOC_INVAL       = 0x0C,
      BNXT_RE_WR_OPCD_BIND            = 0x0E,
-     BNXT_RE_WR_OPCD_RECV            = 0x80
+     BNXT_RE_WR_OPCD_RECV            = 0x80,
+     BNXT_RE_WR_OPCD_INVAL           = 0xFF
 };
 
 enum bnxt_re_wr_flags {
providers/bnxt_re/main.h +7 -1
index 1a4dc06..4cc8abd 100644
@@ -236,9 +236,15 @@ static inline uint8_t bnxt_re_ibv_to_bnxt_wr_opcd(uint8_t ibv_opcd)
      case IBV_WR_RDMA_READ:
              bnxt_opcd = BNXT_RE_WR_OPCD_RDMA_READ;
              break;
+     case IBV_WR_ATOMIC_CMP_AND_SWP:
+             bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_CS;
+             break;
+     case IBV_WR_ATOMIC_FETCH_AND_ADD:
+             bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_FA;
+             break;
              /* TODO: Add other opcodes */
      default:
-             bnxt_opcd = 0xFF;
+             bnxt_opcd = BNXT_RE_WR_OPCD_INVAL;
              break;
      };
 
providers/bnxt_re/memory.h +0 -0
index 0150d80..dc5b352 100644
@@ -83,6 +83,16 @@ static inline void iowrite32(__u32 *dst, __le32 *src)
      *(volatile __le32 *)dst = *src;
 }
 
Quoted 12 lines

providers/bnxt_re/memory.h static inline void iowrite32(__u32 *dst, __le32 *src) · line 95

Quoted 10 lines
providers/bnxt_re/memory.h +10 -0
+static inline __u32 upper_32_bits(uint64_t n)
+{
+     return (__u32)((n >> 16) >> 16);
+}
+
+static inline __u32 lower_32_bits(uint64_t n)
+{
+     return (__u32)(n & 0xFFFFFFFFUL);
+}
+

It looks like leftovers, I don't see any usage of it.

Certainly it is, will remove that...

Quoted 98 lines
Quoted 98 lines
providers/bnxt_re/memory.h +0 -0
 /* Basic queue operation */
 static inline uint32_t bnxt_re_is_que_full(struct bnxt_re_queue *que)
 {
providers/bnxt_re/verbs.c +44 -9
index 1f8ff8e..2768a56 100644
@@ -1068,6 +1068,8 @@ static int bnxt_re_build_send_sqe(struct bnxt_re_qp *qp, void *wqe,
 
      /* Fill Header */
      opcode = bnxt_re_ibv_to_bnxt_wr_opcd(wr->opcode);
+     if (opcode == BNXT_RE_WR_OPCD_INVAL)
+             return -EINVAL;
      hdrval = (opcode & BNXT_RE_HDR_WT_MASK);
 
      if (is_inline) {
@@ -1115,6 +1117,39 @@ static int bnxt_re_build_rdma_sqe(struct bnxt_re_qp *qp, void *wqe,
      return len;
 }
 
+static int bnxt_re_build_cns_sqe(struct bnxt_re_qp *qp, void *wqe,
+                              struct ibv_send_wr *wr)
+{
+     struct bnxt_re_bsqe *hdr = wqe;
+     struct bnxt_re_atomic *sqe = ((void *)wqe +
+                                   sizeof(struct bnxt_re_bsqe));
+     int len;
+
+     len = bnxt_re_build_send_sqe(qp, wqe, wr, false);
+     hdr->key_immd = htole32(wr->wr.atomic.rkey);
+     sqe->rva = htole64(wr->wr.atomic.remote_addr);
+     sqe->cmp_dt = htole64(wr->wr.atomic.compare_add);
+     sqe->swp_dt = htole64(wr->wr.atomic.swap);
+
+     return len;
+}
+
+static int bnxt_re_build_fna_sqe(struct bnxt_re_qp *qp, void *wqe,
+                              struct ibv_send_wr *wr)
+{
+     struct bnxt_re_bsqe *hdr = wqe;
+     struct bnxt_re_atomic *sqe = ((void *)wqe +
+                                   sizeof(struct bnxt_re_bsqe));
+     int len;
+
+     len = bnxt_re_build_send_sqe(qp, wqe, wr, false);
+     hdr->key_immd = htole32(wr->wr.atomic.rkey);
+     sqe->rva = htole64(wr->wr.atomic.remote_addr);
+     sqe->cmp_dt = htole64(wr->wr.atomic.compare_add);
+
+     return len;
+}
+
 int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
                    struct ibv_send_wr **bad)
 {
@@ -1168,27 +1203,28 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
                      else
                              bytes = bnxt_re_build_send_sqe(qp, sqe, wr,
                                                             is_inline);
-                     if (bytes < 0)
-                             ret = (bytes == -EINVAL) ? EINVAL : ENOMEM;
                      break;
              case IBV_WR_RDMA_WRITE_WITH_IMM:
                      hdr->key_immd = htole32(be32toh(wr->imm_data));
              case IBV_WR_RDMA_WRITE:
                      bytes = bnxt_re_build_rdma_sqe(qp, sqe, wr, is_inline);
-                     if (bytes < 0)
-                             ret = ENOMEM;
                      break;
              case IBV_WR_RDMA_READ:
                      bytes = bnxt_re_build_rdma_sqe(qp, sqe, wr, false);
-                     if (bytes < 0)
-                             ret = ENOMEM;
+                     break;
+             case IBV_WR_ATOMIC_CMP_AND_SWP:
+                     bytes = bnxt_re_build_cns_sqe(qp, sqe, wr);
+                     break;
+             case IBV_WR_ATOMIC_FETCH_AND_ADD:
+                     bytes = bnxt_re_build_fna_sqe(qp, sqe, wr);
                      break;
              default:
-                     ret = EINVAL;
+                     bytes = -EINVAL;
                      break;
              }
 
-             if (ret) {
+             if (bytes < 0) {
+                     ret = (bytes == -EINVAL) ? EINVAL : ENOMEM;
                      *bad = wr;
                      break;
              }
--

1.8.3.1

Quoted 4 lines
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html