diff mbox series

[rdma-core,4/8] verbs: Implement ibv_query_gid and ibv_query_gid_type over ioctl

Message ID 20200914063503.192997-5-yishaih@nvidia.com (mailing list archive)
State Superseded
Headers show
Series verbs: Query GID table API | expand

Commit Message

Yishai Hadas Sept. 14, 2020, 6:34 a.m. UTC
From: Avihai Horon <avihaih@nvidia.com>

Currently ibv_query_gid and ibv_query_gid_type are implemented over
sysfs. In order to improve their performance we implement them using the
new query GID entry API, so now they will use ioctl and fallback to
sysfs.

Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
---
 libibverbs/cmd_device.c |  4 ++--
 libibverbs/driver.h     |  6 +++++
 libibverbs/verbs.c      | 58 ++++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 60 insertions(+), 8 deletions(-)

Comments

Jason Gunthorpe Sept. 21, 2020, 4:53 p.m. UTC | #1
On Mon, Sep 14, 2020 at 09:34:59AM +0300, Yishai Hadas wrote:

> diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c
> index 9427aba..9dec4e6 100644
> +++ b/libibverbs/verbs.c
> @@ -216,10 +216,8 @@ LATEST_SYMVER_FUNC(ibv_query_port, 1_1, "IBVERBS_1.1",
>  				sizeof(*port_attr));
>  }
>  
> -LATEST_SYMVER_FUNC(ibv_query_gid, 1_1, "IBVERBS_1.1",
> -		   int,
> -		   struct ibv_context *context, uint8_t port_num,
> -		   int index, union ibv_gid *gid)
> +int _ibv_query_gid(struct ibv_context *context, uint8_t port_num, int index,
> +		   union ibv_gid *gid)
>  {
>  	struct verbs_device *verbs_device = verbs_get_device(context->device);
>  	char attr[41];
> @@ -240,6 +238,29 @@ LATEST_SYMVER_FUNC(ibv_query_gid, 1_1, "IBVERBS_1.1",
>  	return 0;
>  }

This should be moved to be near query_sysfs_gid_entry() and given a
better name

Jason
Yishai Hadas Sept. 22, 2020, 12:59 p.m. UTC | #2
On 9/21/2020 7:53 PM, Jason Gunthorpe wrote:
> On Mon, Sep 14, 2020 at 09:34:59AM +0300, Yishai Hadas wrote:
>
>> diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c
>> index 9427aba..9dec4e6 100644
>> +++ b/libibverbs/verbs.c
>> @@ -216,10 +216,8 @@ LATEST_SYMVER_FUNC(ibv_query_port, 1_1, "IBVERBS_1.1",
>>   				sizeof(*port_attr));
>>   }
>>   
>> -LATEST_SYMVER_FUNC(ibv_query_gid, 1_1, "IBVERBS_1.1",
>> -		   int,
>> -		   struct ibv_context *context, uint8_t port_num,
>> -		   int index, union ibv_gid *gid)
>> +int _ibv_query_gid(struct ibv_context *context, uint8_t port_num, int index,
>> +		   union ibv_gid *gid)
>>   {
>>   	struct verbs_device *verbs_device = verbs_get_device(context->device);
>>   	char attr[41];
>> @@ -240,6 +238,29 @@ LATEST_SYMVER_FUNC(ibv_query_gid, 1_1, "IBVERBS_1.1",
>>   	return 0;
>>   }
> This should be moved to be near query_sysfs_gid_entry() and given a
> better name
>
> Jason

OK, will rename it to be query_sysfs_gid() and will move it to be near 
the above which reads the full gid entry information.
In addition, will do the same for _ibv_query_gid_type(), will move to 
cmd_device.c and rename it to be query_sysfs_gid_type().

Yishai
diff mbox series

Patch

diff --git a/libibverbs/cmd_device.c b/libibverbs/cmd_device.c
index 06e6c5a..fb166bb 100644
--- a/libibverbs/cmd_device.c
+++ b/libibverbs/cmd_device.c
@@ -240,11 +240,11 @@  static int query_sysfs_gid_entry(struct ibv_context *context, uint32_t port_num,
 
 	entry->gid_index = gid_index;
 	entry->port_num = port_num;
-	ret = ibv_query_gid(context, port_num, gid_index, &entry->gid);
+	ret = _ibv_query_gid(context, port_num, gid_index, &entry->gid);
 	if (ret)
 		return EINVAL;
 
-	ret = ibv_query_gid_type(context, port_num, gid_index, &gid_type);
+	ret = _ibv_query_gid_type(context, port_num, gid_index, &gid_type);
 	if (ret)
 		return EINVAL;
 
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
index 13b5219..2ab0a89 100644
--- a/libibverbs/driver.h
+++ b/libibverbs/driver.h
@@ -659,6 +659,12 @@  static inline bool check_comp_mask(uint64_t input, uint64_t supported)
 int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
 		       unsigned int index, enum ibv_gid_type_sysfs *type);
 
+int _ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
+			unsigned int index, enum ibv_gid_type_sysfs *type);
+
+int _ibv_query_gid(struct ibv_context *context, uint8_t port_num, int index,
+		   union ibv_gid *gid);
+
 static inline int
 ibv_check_alloc_parent_domain(struct ibv_parent_domain_init_attr *attr)
 {
diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c
index 9427aba..9dec4e6 100644
--- a/libibverbs/verbs.c
+++ b/libibverbs/verbs.c
@@ -216,10 +216,8 @@  LATEST_SYMVER_FUNC(ibv_query_port, 1_1, "IBVERBS_1.1",
 				sizeof(*port_attr));
 }
 
-LATEST_SYMVER_FUNC(ibv_query_gid, 1_1, "IBVERBS_1.1",
-		   int,
-		   struct ibv_context *context, uint8_t port_num,
-		   int index, union ibv_gid *gid)
+int _ibv_query_gid(struct ibv_context *context, uint8_t port_num, int index,
+		   union ibv_gid *gid)
 {
 	struct verbs_device *verbs_device = verbs_get_device(context->device);
 	char attr[41];
@@ -240,6 +238,29 @@  LATEST_SYMVER_FUNC(ibv_query_gid, 1_1, "IBVERBS_1.1",
 	return 0;
 }
 
+LATEST_SYMVER_FUNC(ibv_query_gid, 1_1, "IBVERBS_1.1",
+		   int,
+		   struct ibv_context *context, uint8_t port_num,
+		   int index, union ibv_gid *gid)
+{
+	struct ibv_gid_entry entry = {};
+	int ret;
+
+	ret = ibv_cmd_query_gid_entry(context, port_num, index, &entry, 0,
+				      sizeof(entry));
+	/* Preserve API behavior for empty GID */
+	if (ret == ENODATA) {
+		memset(gid, 0, sizeof(*gid));
+		return 0;
+	}
+	if (ret)
+		return -1;
+
+	memcpy(gid, &entry.gid, sizeof(entry.gid));
+
+	return 0;
+}
+
 int _ibv_query_gid_ex(struct ibv_context *context, uint32_t port_num,
 		      uint32_t gid_index, struct ibv_gid_entry *entry,
 		      uint32_t flags, size_t entry_size)
@@ -711,8 +732,8 @@  LATEST_SYMVER_FUNC(ibv_create_ah, 1_1, "IBVERBS_1.1",
  */
 #define V1_TYPE "IB/RoCE v1"
 #define V2_TYPE "RoCE v2"
-int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
-		       unsigned int index, enum ibv_gid_type_sysfs *type)
+int _ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
+			unsigned int index, enum ibv_gid_type_sysfs *type)
 {
 	struct verbs_device *verbs_device = verbs_get_device(context->device);
 	char buff[11];
@@ -768,6 +789,31 @@  int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
 	return 0;
 }
 
+int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
+		       unsigned int index, enum ibv_gid_type_sysfs *type)
+{
+	struct ibv_gid_entry entry = {};
+	int ret;
+
+	ret = ibv_cmd_query_gid_entry(context, port_num, index, &entry, 0,
+				      sizeof(entry));
+	/* Preserve API behavior for empty GID */
+	if (ret == ENODATA) {
+		*type = IBV_GID_TYPE_SYSFS_IB_ROCE_V1;
+		return 0;
+	}
+	if (ret)
+		return -1;
+
+	if (entry.gid_type == IBV_GID_TYPE_IB ||
+	    entry.gid_type == IBV_GID_TYPE_ROCE_V1)
+		*type = IBV_GID_TYPE_SYSFS_IB_ROCE_V1;
+	else
+		*type = IBV_GID_TYPE_SYSFS_ROCE_V2;
+
+	return 0;
+}
+
 static int ibv_find_gid_index(struct ibv_context *context, uint8_t port_num,
 			      union ibv_gid *gid,
 			      enum ibv_gid_type_sysfs gid_type)