[v1] net/cpfl: get running host ID for CPFL PMD

Message ID 20240520044415.2307157-1-shaiq.wani@intel.com (mailing list archive)
State Changes Requested
Delegated to: Bruce Richardson
Headers
Series [v1] net/cpfl: get running host ID for CPFL PMD |

Checks

Context Check Description
ci/loongarch-compilation success Compilation OK
ci/checkpatch success coding style OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Shaiq Wani May 20, 2024, 4:44 a.m. UTC
  Check whether CPFL PMD is running on Host or ACC

Signed-off-by: Shaiq Wani <shaiq.wani@intel.com>
---
 drivers/net/cpfl/cpfl_ethdev.c | 25 +++++++++++++++++++++++++
 drivers/net/cpfl/cpfl_ethdev.h |  5 ++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
  

Comments

Stephen Hemminger May 20, 2024, 6:26 p.m. UTC | #1
On Mon, 20 May 2024 04:44:15 +0000
Shaiq Wani <shaiq.wani@intel.com> wrote:

> +static uint8_t
> +get_running_host_id(void)
> +{
> +	char buf[BUFSIZ];
> +	FILE *fd;
> +	uint8_t host_id = CPFL_INVALID_HOST_ID;
> +
> +	fd = fopen("/etc/issue.net", "r");
> +	if (fd == NULL) {
> +		PMD_INIT_LOG(ERR, "Cannot open /etc/issue.net\n");
> +		return host_id;
> +	}
>  
> +	if (fgets(buf, sizeof(buf), fd)) {
> +		/* get the first line */
> +		if (strstr(buf, "IMC"))
> +			PMD_INIT_LOG(ERR, "CPFL PMD cannot running on IMC.");
> +		else if (strstr(buf, "ACC"))
> +			host_id = CPFL_HOST_ID_ACC;
> +		else
> +			host_id = CPFL_HOST_ID_HOST;
> +	}
>  
> +	fclose(fd);
> +	return host_id;
> +}

This seems weird and problematic. You are making assumptions about /etc/issue.net
which the is the message file used by SSH for login message.

On an embedded firmware ROM this may work. But on other platforms this is
a user modifiable file.
  
Shaiq Wani May 21, 2024, 12:43 p.m. UTC | #2
-----Original Message-----
From: Stephen Hemminger <stephen@networkplumber.org> 
Sent: Monday, May 20, 2024 11:56 PM
To: Wani, Shaiq <shaiq.wani@intel.com>
Cc: dev@dpdk.org
Subject: Re: [PATCH v1] net/cpfl: get running host ID for CPFL PMD

On Mon, 20 May 2024 04:44:15 +0000
Shaiq Wani <shaiq.wani@intel.com> wrote:

> +static uint8_t
> +get_running_host_id(void)
> +{
> +	char buf[BUFSIZ];
> +	FILE *fd;
> +	uint8_t host_id = CPFL_INVALID_HOST_ID;
> +
> +	fd = fopen("/etc/issue.net", "r");
> +	if (fd == NULL) {
> +		PMD_INIT_LOG(ERR, "Cannot open /etc/issue.net\n");
> +		return host_id;
> +	}
>  
> +	if (fgets(buf, sizeof(buf), fd)) {
> +		/* get the first line */
> +		if (strstr(buf, "IMC"))
> +			PMD_INIT_LOG(ERR, "CPFL PMD cannot running on IMC.");
> +		else if (strstr(buf, "ACC"))
> +			host_id = CPFL_HOST_ID_ACC;
> +		else
> +			host_id = CPFL_HOST_ID_HOST;
> +	}
>  
> +	fclose(fd);
> +	return host_id;
> +}

This seems weird and problematic. You are making assumptions about /etc/issue.net which the is the message file used by SSH for login message.

On an embedded firmware ROM this may work. But on other platforms this is a user modifiable file.


Thanks for your comment.
I will look for another approach to implement this.
  

Patch

diff --git a/drivers/net/cpfl/cpfl_ethdev.c b/drivers/net/cpfl/cpfl_ethdev.c
index ef19aa1b6a..7eb801bbde 100644
--- a/drivers/net/cpfl/cpfl_ethdev.c
+++ b/drivers/net/cpfl/cpfl_ethdev.c
@@ -2269,8 +2269,32 @@  cpfl_repr_allowlist_uninit(struct cpfl_adapter_ext *adapter)
 {
 	rte_hash_free(adapter->repr_allowlist_hash);
 }
+static uint8_t
+get_running_host_id(void)
+{
+	char buf[BUFSIZ];
+	FILE *fd;
+	uint8_t host_id = CPFL_INVALID_HOST_ID;
+
+	fd = fopen("/etc/issue.net", "r");
+	if (fd == NULL) {
+		PMD_INIT_LOG(ERR, "Cannot open /etc/issue.net\n");
+		return host_id;
+	}
 
+	if (fgets(buf, sizeof(buf), fd)) {
+		/* get the first line */
+		if (strstr(buf, "IMC"))
+			PMD_INIT_LOG(ERR, "CPFL PMD cannot running on IMC.");
+		else if (strstr(buf, "ACC"))
+			host_id = CPFL_HOST_ID_ACC;
+		else
+			host_id = CPFL_HOST_ID_HOST;
+	}
 
+	fclose(fd);
+	return host_id;
+}
 static int
 cpfl_adapter_ext_init(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapter,
 		      struct cpfl_devargs *devargs)
@@ -2289,6 +2313,7 @@  cpfl_adapter_ext_init(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *a
 	hw->vendor_id = pci_dev->id.vendor_id;
 	hw->device_id = pci_dev->id.device_id;
 	hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
+	adapter->host_id = get_running_host_id();
 
 	strncpy(adapter->name, pci_dev->device.name, PCI_PRI_STR_SIZE);
 
diff --git a/drivers/net/cpfl/cpfl_ethdev.h b/drivers/net/cpfl/cpfl_ethdev.h
index 457db6d6be..3f6f9ca5ea 100644
--- a/drivers/net/cpfl/cpfl_ethdev.h
+++ b/drivers/net/cpfl/cpfl_ethdev.h
@@ -66,6 +66,7 @@ 
 #define CPFL_PF_TYPE_NUM	2
 #define CPFL_HOST_ID_HOST	0
 #define CPFL_HOST_ID_ACC	1
+#define CPFL_INVALID_HOST_ID    UINT8_MAX
 #define CPFL_PF_TYPE_APF	0
 #define CPFL_PF_TYPE_CPF	1
 
@@ -230,6 +231,7 @@  struct cpfl_adapter_ext {
 	uint8_t ctrl_vport_recv_info[IDPF_DFLT_MBX_BUF_SIZE];
 	struct idpf_ctlq_info *ctlqp[CPFL_CFGQ_NUM];
 	struct cpfl_ctlq_create_info cfgq_info[CPFL_CFGQ_NUM];
+	uint8_t host_id;
 };
 
 TAILQ_HEAD(cpfl_adapter_list, cpfl_adapter_ext);
@@ -296,7 +298,8 @@  cpfl_get_vsi_id(struct cpfl_itf *itf)
 
 		vport_identity.func_type = CPCHNL2_FTYPE_LAN_PF;
 		/* host: CPFL_HOST0_CPF_ID, acc: CPFL_ACC_CPF_ID */
-		vport_identity.pf_id = CPFL_ACC_CPF_ID;
+		vport_identity.pf_id = (itf->adapter->host_id == CPFL_HOST_ID_ACC) ?
+								CPFL_ACC_CPF_ID : CPFL_HOST0_CPF_ID;
 		vport_identity.vf_id = 0;
 		vport_identity.vport_id = vport_id;
 		ret = rte_hash_lookup_data(itf->adapter->vport_map_hash,