2023-06-06 14:19:46

by Gangurde, Abhijit

[permalink] [raw]
Subject: [PATCH v3] cdx: Rename MCDI_LOGGING to CDX_MCDI_LOGGING

MCDI_LOGGING is too generic considering other MCDI users
SFC_MCDI_LOGGING and SFC_SIENA_MCDI_LOGGING. Rename it to
CDX_MCDI_LOGGING makes it more domain specific.

Also, move CONFIG_CDX_MCDI_LOGGING to header file.

Fixes: eb96b740192b ("cdx: add MCDI protocol interface for firmware interaction")
Signed-off-by: Abhijit Gangurde <[email protected]>
Suggested-by: Geert Uytterhoeven <[email protected]>
Closes: https://lore.kernel.org/lkml/CAMuHMdWTCdQagFFANygMgA8D0sWaoGxWv2AjibC3vwSd0UxuRw@mail.gmail.com/
---
Changes v2->v3:
- Dropped sysfs entry changes from v2

Changes v1->v2:
- Moved CONFIG_CDX_MCDI_LOGGING flag to header file
- Added sysfs entry to enable/disable mcdi logging

drivers/cdx/controller/Kconfig | 2 +-
drivers/cdx/controller/mcdi.c | 41 ++++++++++++----------------------
drivers/cdx/controller/mcdi.h | 7 ++++--
3 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/drivers/cdx/controller/Kconfig b/drivers/cdx/controller/Kconfig
index c3e3b9ff8dfe..e7014e9819ea 100644
--- a/drivers/cdx/controller/Kconfig
+++ b/drivers/cdx/controller/Kconfig
@@ -18,7 +18,7 @@ config CDX_CONTROLLER

If unsure, say N.

-config MCDI_LOGGING
+config CDX_MCDI_LOGGING
bool "MCDI Logging for the CDX controller"
depends on CDX_CONTROLLER
help
diff --git a/drivers/cdx/controller/mcdi.c b/drivers/cdx/controller/mcdi.c
index a211a2ca762e..5a2d1fd46478 100644
--- a/drivers/cdx/controller/mcdi.c
+++ b/drivers/cdx/controller/mcdi.c
@@ -31,9 +31,7 @@ struct cdx_mcdi_copy_buffer {
struct cdx_dword buffer[DIV_ROUND_UP(MCDI_CTL_SDU_LEN_MAX, 4)];
};

-#ifdef CONFIG_MCDI_LOGGING
#define LOG_LINE_MAX (1024 - 32)
-#endif

static void cdx_mcdi_cancel_cmd(struct cdx_mcdi *cdx, struct cdx_mcdi_cmd *cmd);
static void cdx_mcdi_wait_for_cleanup(struct cdx_mcdi *cdx);
@@ -118,12 +116,14 @@ int cdx_mcdi_init(struct cdx_mcdi *cdx)

mcdi = cdx_mcdi_if(cdx);
mcdi->cdx = cdx;
+ mcdi->logging_enabled = !!CDX_MCDI_LOGGING;
+
+ if (mcdi->logging_enabled) {
+ mcdi->logging_buffer = kmalloc(LOG_LINE_MAX, GFP_KERNEL);
+ if (!mcdi->logging_buffer)
+ goto fail2;
+ }

-#ifdef CONFIG_MCDI_LOGGING
- mcdi->logging_buffer = kmalloc(LOG_LINE_MAX, GFP_KERNEL);
- if (!mcdi->logging_buffer)
- goto fail2;
-#endif
mcdi->workqueue = alloc_ordered_workqueue("mcdi_wq", 0);
if (!mcdi->workqueue)
goto fail3;
@@ -136,10 +136,8 @@ int cdx_mcdi_init(struct cdx_mcdi *cdx)

return 0;
fail3:
-#ifdef CONFIG_MCDI_LOGGING
kfree(mcdi->logging_buffer);
fail2:
-#endif
kfree(cdx->mcdi);
cdx->mcdi = NULL;
fail:
@@ -155,10 +153,7 @@ void cdx_mcdi_finish(struct cdx_mcdi *cdx)
return;

cdx_mcdi_wait_for_cleanup(cdx);
-
-#ifdef CONFIG_MCDI_LOGGING
kfree(mcdi->logging_buffer);
-#endif

destroy_workqueue(mcdi->workqueue);
kfree(cdx->mcdi);
@@ -246,15 +241,9 @@ static void cdx_mcdi_send_request(struct cdx_mcdi *cdx,
size_t hdr_len;
bool not_epoch;
u32 xflags;
-#ifdef CONFIG_MCDI_LOGGING
- char *buf;
-#endif

if (!mcdi)
return;
-#ifdef CONFIG_MCDI_LOGGING
- buf = mcdi->logging_buffer; /* page-sized */
-#endif

mcdi->prev_seq = cmd->seq;
mcdi->seq_held_by[cmd->seq] = cmd;
@@ -281,10 +270,10 @@ static void cdx_mcdi_send_request(struct cdx_mcdi *cdx,
MC_CMD_V2_EXTN_IN_MCDI_MESSAGE_TYPE_PLATFORM);
hdr_len = 8;

-#ifdef CONFIG_MCDI_LOGGING
- if (!WARN_ON_ONCE(!buf)) {
+ if (mcdi->logging_enabled) {
const struct cdx_dword *frags[] = { hdr, inbuf };
const size_t frag_len[] = { hdr_len, round_up(inlen, 4) };
+ char *log = mcdi->logging_buffer;
int bytes = 0;
int i, j;

@@ -300,18 +289,18 @@ static void cdx_mcdi_send_request(struct cdx_mcdi *cdx,
* The string before that is just over 70 bytes.
*/
if ((bytes + 75) > LOG_LINE_MAX) {
- pr_info("MCDI RPC REQ:%s \\\n", buf);
+ pr_info("MCDI RPC REQ:%s \\\n", log);
bytes = 0;
}
- bytes += snprintf(buf + bytes,
+ bytes += snprintf(log + bytes,
LOG_LINE_MAX - bytes, " %08x",
le32_to_cpu(frag[i].cdx_u32));
}
}

- pr_info("MCDI RPC REQ:%s\n", buf);
+ pr_info("MCDI RPC REQ:%s\n", log);
}
-#endif
+
hdr[0].cdx_u32 |= (__force __le32)(cdx_mcdi_payload_csum(hdr, hdr_len, inbuf, inlen) <<
MCDI_HEADER_XFLAGS_LBN);
cdx->mcdi_ops->mcdi_request(cdx, hdr, hdr_len, inbuf, inlen);
@@ -700,8 +689,7 @@ static bool cdx_mcdi_complete_cmd(struct cdx_mcdi_iface *mcdi,
resp_data_len = 0;
}

-#ifdef CONFIG_MCDI_LOGGING
- if (!WARN_ON_ONCE(!mcdi->logging_buffer)) {
+ if (mcdi->logging_enabled) {
char *log = mcdi->logging_buffer;
int i, bytes = 0;
size_t rlen;
@@ -721,7 +709,6 @@ static bool cdx_mcdi_complete_cmd(struct cdx_mcdi_iface *mcdi,

pr_info("MCDI RPC RESP:%s\n", log);
}
-#endif

if (error && resp_data_len == 0) {
/* MC rebooted during command */
diff --git a/drivers/cdx/controller/mcdi.h b/drivers/cdx/controller/mcdi.h
index 0bfbeab04e43..f9d90dfa19dd 100644
--- a/drivers/cdx/controller/mcdi.h
+++ b/drivers/cdx/controller/mcdi.h
@@ -22,6 +22,11 @@
#define CDX_WARN_ON_PARANOID(x) do {} while (0)
#endif

+#ifdef CONFIG_CDX_MCDI_LOGGING
+#define CDX_MCDI_LOGGING 1
+#else
+#define CDX_MCDI_LOGGING 0
+#endif
/**
* enum cdx_mcdi_mode - MCDI transaction mode
* @MCDI_MODE_EVENTS: wait for an mcdi response callback.
@@ -170,10 +175,8 @@ struct cdx_mcdi_iface {
enum cdx_mcdi_mode mode;
u8 prev_seq;
bool new_epoch;
-#ifdef CONFIG_MCDI_LOGGING
bool logging_enabled;
char *logging_buffer;
-#endif
};

/**
--
2.25.1



2023-06-07 10:21:54

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v3] cdx: Rename MCDI_LOGGING to CDX_MCDI_LOGGING

On Tue, Jun 06, 2023 at 07:31:37PM +0530, Abhijit Gangurde wrote:
> MCDI_LOGGING is too generic considering other MCDI users
> SFC_MCDI_LOGGING and SFC_SIENA_MCDI_LOGGING. Rename it to
> CDX_MCDI_LOGGING makes it more domain specific.
>
> Also, move CONFIG_CDX_MCDI_LOGGING to header file.
>
> Fixes: eb96b740192b ("cdx: add MCDI protocol interface for firmware interaction")
> Signed-off-by: Abhijit Gangurde <[email protected]>
> Suggested-by: Geert Uytterhoeven <[email protected]>
> Closes: https://lore.kernel.org/lkml/CAMuHMdWTCdQagFFANygMgA8D0sWaoGxWv2AjibC3vwSd0UxuRw@mail.gmail.com/
> ---
> Changes v2->v3:
> - Dropped sysfs entry changes from v2

Where is patch 2/2 in this series that moves to use dynamic debugging
instead of this custom mess?

This shouln't be a config option at all, as no one will be able to
enable it on a real system.

thanks,

greg k-h

2023-06-12 08:29:02

by Gangurde, Abhijit

[permalink] [raw]
Subject: RE: [PATCH v3] cdx: Rename MCDI_LOGGING to CDX_MCDI_LOGGING

[AMD Official Use Only - General]

> On Tue, Jun 06, 2023 at 07:31:37PM +0530, Abhijit Gangurde wrote:
> > MCDI_LOGGING is too generic considering other MCDI users
> > SFC_MCDI_LOGGING and SFC_SIENA_MCDI_LOGGING. Rename it to
> > CDX_MCDI_LOGGING makes it more domain specific.
> >
> > Also, move CONFIG_CDX_MCDI_LOGGING to header file.
> >
> > Fixes: eb96b740192b ("cdx: add MCDI protocol interface for firmware
> interaction")
> > Signed-off-by: Abhijit Gangurde <[email protected]>
> > Suggested-by: Geert Uytterhoeven <[email protected]>
> > Closes:
> https://lore.kernel.org/lkml/CAMuHMdWTCdQagFFANygMgA8D0sWaoGxWv
> [email protected]/
> > ---
> > Changes v2->v3:
> > - Dropped sysfs entry changes from v2
>
> Where is patch 2/2 in this series that moves to use dynamic debugging
> instead of this custom mess?
>
> This shouln't be a config option at all, as no one will be able to
> enable it on a real system.
>

Will send v4 with completely removing custom logging and use the dynamic debugging.

Thanks,
Abhijit