* [dpdk-dev] [PATCH] common/cnxk: add helpers for reading runplatform
@ 2021-10-01 20:24 Tomasz Duszynski
2021-10-08 8:16 ` Jerin Jacob
0 siblings, 1 reply; 2+ messages in thread
From: Tomasz Duszynski @ 2021-10-01 20:24 UTC (permalink / raw)
To: dev
Cc: jerinj, Tomasz Duszynski, Nithin Dabilpuram, Kiran Kumar K,
Sunil Kumar Kori, Satha Rao
Add helper functions that allow one to check platform
ROC is running on. Platform type is retrieved from device
tree attribute runplatform which is updated by EBF accordingly.
Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
Reviewed-by: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
---
drivers/common/cnxk/roc_model.c | 53 ++++++++++++++++++++++++++++++++-
drivers/common/cnxk/roc_model.h | 29 ++++++++++++++++++
2 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/drivers/common/cnxk/roc_model.c b/drivers/common/cnxk/roc_model.c
index e5aeabe2e2..447dc6e8bc 100644
--- a/drivers/common/cnxk/roc_model.c
+++ b/drivers/common/cnxk/roc_model.c
@@ -178,6 +178,55 @@ detect_invalid_config(void)
#endif
}
+static uint64_t
+env_lookup_flag(const char *name)
+{
+ unsigned int i;
+ struct {
+ const char *name;
+ uint64_t flag;
+ } envs[] = {
+ {"HW_PLATFORM", ROC_ENV_HW},
+ {"EMUL_PLATFORM", ROC_ENV_EMUL},
+ {"ASIM_PLATFORM", ROC_ENV_ASIM},
+ };
+
+ for (i = 0; i < PLT_DIM(envs); i++)
+ if (!strncmp(envs[i].name, name, strlen(envs[i].name)))
+ return envs[i].flag;
+
+ return 0;
+}
+
+static void
+of_env_get(struct roc_model *model)
+{
+ const char *const path = "/proc/device-tree/soc@0/runplatform";
+ uint64_t flag;
+ FILE *fp;
+
+ fp = fopen(path, "r");
+ if (!fp) {
+ plt_err("Failed to open %s", path);
+ return;
+ }
+
+ if (!fgets(model->env, sizeof(model->env), fp)) {
+ plt_err("Failed to read %s", path);
+ goto err;
+ }
+
+ flag = env_lookup_flag(model->env);
+ if (flag == 0) {
+ plt_err("Unknown platform: %s", model->env);
+ goto err;
+ }
+
+ model->flag |= flag;
+err:
+ fclose(fp);
+}
+
int
roc_model_init(struct roc_model *model)
{
@@ -197,8 +246,10 @@ roc_model_init(struct roc_model *model)
if (!populate_model(model, midr))
goto err;
+ of_env_get(model);
+
rc = 0;
- plt_info("RoC Model: %s", model->name);
+ plt_info("RoC Model: %s (%s)", model->name, model->env);
roc_model = model;
err:
return rc;
diff --git a/drivers/common/cnxk/roc_model.h b/drivers/common/cnxk/roc_model.h
index a54f435b46..3779a88bca 100644
--- a/drivers/common/cnxk/roc_model.h
+++ b/drivers/common/cnxk/roc_model.h
@@ -23,10 +23,15 @@ struct roc_model {
#define ROC_MODEL_CN106xx_A0 BIT_ULL(20)
#define ROC_MODEL_CNF105xx_A0 BIT_ULL(21)
#define ROC_MODEL_CNF105xxN_A0 BIT_ULL(22)
+/* Following flags describe platform code is running on */
+#define ROC_ENV_HW BIT_ULL(61)
+#define ROC_ENV_EMUL BIT_ULL(62)
+#define ROC_ENV_ASIM BIT_ULL(63)
uint64_t flag;
#define ROC_MODEL_STR_LEN_MAX 128
char name[ROC_MODEL_STR_LEN_MAX];
+ char env[ROC_MODEL_STR_LEN_MAX];
} __plt_cache_aligned;
#define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0)
@@ -158,6 +163,30 @@ roc_model_is_cnf10kb_a0(void)
return roc_model->flag & ROC_MODEL_CNF105xxN_A0;
}
+static inline bool
+roc_env_is_hw(void)
+{
+ return roc_model->flag & ROC_ENV_HW;
+}
+
+static inline bool
+roc_env_is_emulator(void)
+{
+ return roc_model->flag & ROC_ENV_EMUL;
+}
+
+static inline bool
+roc_env_is_asim(void)
+{
+ return roc_model->flag & ROC_ENV_ASIM;
+}
+
+static inline const char *
+roc_env_get(void)
+{
+ return roc_model->env;
+}
+
int roc_model_init(struct roc_model *model);
#endif
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [dpdk-dev] [PATCH] common/cnxk: add helpers for reading runplatform
2021-10-01 20:24 [dpdk-dev] [PATCH] common/cnxk: add helpers for reading runplatform Tomasz Duszynski
@ 2021-10-08 8:16 ` Jerin Jacob
0 siblings, 0 replies; 2+ messages in thread
From: Jerin Jacob @ 2021-10-08 8:16 UTC (permalink / raw)
To: Tomasz Duszynski, Ferruh Yigit
Cc: dpdk-dev, Jerin Jacob, Nithin Dabilpuram, Kiran Kumar K,
Sunil Kumar Kori, Satha Rao
On Sat, Oct 2, 2021 at 1:55 AM Tomasz Duszynski <tduszynski@marvell.com> wrote:
>
> Add helper functions that allow one to check platform
> ROC is running on. Platform type is retrieved from device
> tree attribute runplatform which is updated by EBF accordingly.
>
> Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
> Reviewed-by: Jerin Jacob <jerinj@marvell.com>
Applied to dpdk-next-net-mrvl/for-next-net. Thanks
> ---
> drivers/common/cnxk/roc_model.c | 53 ++++++++++++++++++++++++++++++++-
> drivers/common/cnxk/roc_model.h | 29 ++++++++++++++++++
> 2 files changed, 81 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/common/cnxk/roc_model.c b/drivers/common/cnxk/roc_model.c
> index e5aeabe2e2..447dc6e8bc 100644
> --- a/drivers/common/cnxk/roc_model.c
> +++ b/drivers/common/cnxk/roc_model.c
> @@ -178,6 +178,55 @@ detect_invalid_config(void)
> #endif
> }
>
> +static uint64_t
> +env_lookup_flag(const char *name)
> +{
> + unsigned int i;
> + struct {
> + const char *name;
> + uint64_t flag;
> + } envs[] = {
> + {"HW_PLATFORM", ROC_ENV_HW},
> + {"EMUL_PLATFORM", ROC_ENV_EMUL},
> + {"ASIM_PLATFORM", ROC_ENV_ASIM},
> + };
> +
> + for (i = 0; i < PLT_DIM(envs); i++)
> + if (!strncmp(envs[i].name, name, strlen(envs[i].name)))
> + return envs[i].flag;
> +
> + return 0;
> +}
> +
> +static void
> +of_env_get(struct roc_model *model)
> +{
> + const char *const path = "/proc/device-tree/soc@0/runplatform";
> + uint64_t flag;
> + FILE *fp;
> +
> + fp = fopen(path, "r");
> + if (!fp) {
> + plt_err("Failed to open %s", path);
> + return;
> + }
> +
> + if (!fgets(model->env, sizeof(model->env), fp)) {
> + plt_err("Failed to read %s", path);
> + goto err;
> + }
> +
> + flag = env_lookup_flag(model->env);
> + if (flag == 0) {
> + plt_err("Unknown platform: %s", model->env);
> + goto err;
> + }
> +
> + model->flag |= flag;
> +err:
> + fclose(fp);
> +}
> +
> int
> roc_model_init(struct roc_model *model)
> {
> @@ -197,8 +246,10 @@ roc_model_init(struct roc_model *model)
> if (!populate_model(model, midr))
> goto err;
>
> + of_env_get(model);
> +
> rc = 0;
> - plt_info("RoC Model: %s", model->name);
> + plt_info("RoC Model: %s (%s)", model->name, model->env);
> roc_model = model;
> err:
> return rc;
> diff --git a/drivers/common/cnxk/roc_model.h b/drivers/common/cnxk/roc_model.h
> index a54f435b46..3779a88bca 100644
> --- a/drivers/common/cnxk/roc_model.h
> +++ b/drivers/common/cnxk/roc_model.h
> @@ -23,10 +23,15 @@ struct roc_model {
> #define ROC_MODEL_CN106xx_A0 BIT_ULL(20)
> #define ROC_MODEL_CNF105xx_A0 BIT_ULL(21)
> #define ROC_MODEL_CNF105xxN_A0 BIT_ULL(22)
> +/* Following flags describe platform code is running on */
> +#define ROC_ENV_HW BIT_ULL(61)
> +#define ROC_ENV_EMUL BIT_ULL(62)
> +#define ROC_ENV_ASIM BIT_ULL(63)
>
> uint64_t flag;
> #define ROC_MODEL_STR_LEN_MAX 128
> char name[ROC_MODEL_STR_LEN_MAX];
> + char env[ROC_MODEL_STR_LEN_MAX];
> } __plt_cache_aligned;
>
> #define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0)
> @@ -158,6 +163,30 @@ roc_model_is_cnf10kb_a0(void)
> return roc_model->flag & ROC_MODEL_CNF105xxN_A0;
> }
>
> +static inline bool
> +roc_env_is_hw(void)
> +{
> + return roc_model->flag & ROC_ENV_HW;
> +}
> +
> +static inline bool
> +roc_env_is_emulator(void)
> +{
> + return roc_model->flag & ROC_ENV_EMUL;
> +}
> +
> +static inline bool
> +roc_env_is_asim(void)
> +{
> + return roc_model->flag & ROC_ENV_ASIM;
> +}
> +
> +static inline const char *
> +roc_env_get(void)
> +{
> + return roc_model->env;
> +}
> +
> int roc_model_init(struct roc_model *model);
>
> #endif
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-08 8:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 20:24 [dpdk-dev] [PATCH] common/cnxk: add helpers for reading runplatform Tomasz Duszynski
2021-10-08 8:16 ` Jerin Jacob
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).