Message ID | 20220317234049.69323-5-dave@stgolabs.net |
---|---|
State | Superseded |
Headers | show |
Series | cxl/mbox: Robustify handling of mbox_cmd.return_code | expand |
On Thu, Mar 17, 2022 at 04:40:48PM -0700, Davidlohr Bueso wrote: > Use the global cxl_mbox_cmd_rc table to improve debug messaging > in __cxl_pci_mbox_send_cmd() and allow cxl_mbox_send_cmd() > to map to proper kernel style errno codes - this patch > continues to use -ENXIO only so no change in semantics. > > Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> > --- > drivers/cxl/core/mbox.c | 7 ++++--- > drivers/cxl/pci.c | 3 ++- > 2 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c > index d4d4a16820b7..fa9e7043f158 100644 > --- a/drivers/cxl/core/mbox.c > +++ b/drivers/cxl/core/mbox.c > @@ -170,9 +170,10 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, > if (rc) > return rc; > > - /* TODO: Map return code to proper kernel style errno */ > - if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) > - return -ENXIO; > + if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) { > + int err = cxl_mbox_cmd_rc2errno(&mbox_cmd); > + return -err; > + } > > /* > * Variable sized commands can't be validated and so it's up to the > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > index 0c36d111232b..67ec0220826f 100644 > --- a/drivers/cxl/pci.c > +++ b/drivers/cxl/pci.c > @@ -178,7 +178,8 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, > FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg); > > if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) { > - dev_dbg(dev, "Mailbox operation had an error\n"); > + dev_dbg(dev, "Mailbox operation had an error: %s\n", > + cxl_mbox_cmd_rc2str(mbox_cmd)); > return 0; /* completed but caller must check return_code */ > } > > > -- > 2.26.2 > Looks good. Reviewed by: Adam Manzanares <a.manzanares@samsung.com>
On Thu, Mar 17, 2022 at 4:41 PM Davidlohr Bueso <dave@stgolabs.net> wrote: > > Use the global cxl_mbox_cmd_rc table to improve debug messaging > in __cxl_pci_mbox_send_cmd() and allow cxl_mbox_send_cmd() > to map to proper kernel style errno codes - this patch > continues to use -ENXIO only so no change in semantics. > > Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> > --- > drivers/cxl/core/mbox.c | 7 ++++--- > drivers/cxl/pci.c | 3 ++- > 2 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c > index d4d4a16820b7..fa9e7043f158 100644 > --- a/drivers/cxl/core/mbox.c > +++ b/drivers/cxl/core/mbox.c > @@ -170,9 +170,10 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, > if (rc) > return rc; > > - /* TODO: Map return code to proper kernel style errno */ > - if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) > - return -ENXIO; > + if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) { > + int err = cxl_mbox_cmd_rc2errno(&mbox_cmd); > + return -err; I don't like the need for a local variable and adding the negation. Just store the negative value directly and call the helper cxl_mbox_cmd_rc2err() so that this can just do "return cxl_mbox_cmd_rc2err(&mbox_cmd);". > + } > > /* > * Variable sized commands can't be validated and so it's up to the > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > index 0c36d111232b..67ec0220826f 100644 > --- a/drivers/cxl/pci.c > +++ b/drivers/cxl/pci.c > @@ -178,7 +178,8 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, > FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg); > > if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) { > - dev_dbg(dev, "Mailbox operation had an error\n"); > + dev_dbg(dev, "Mailbox operation had an error: %s\n", > + cxl_mbox_cmd_rc2str(mbox_cmd)); Looks good.
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index d4d4a16820b7..fa9e7043f158 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -170,9 +170,10 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, if (rc) return rc; - /* TODO: Map return code to proper kernel style errno */ - if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) - return -ENXIO; + if (mbox_cmd.return_code != CXL_MBOX_CMD_RC_SUCCESS) { + int err = cxl_mbox_cmd_rc2errno(&mbox_cmd); + return -err; + } /* * Variable sized commands can't be validated and so it's up to the diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 0c36d111232b..67ec0220826f 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -178,7 +178,8 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg); if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) { - dev_dbg(dev, "Mailbox operation had an error\n"); + dev_dbg(dev, "Mailbox operation had an error: %s\n", + cxl_mbox_cmd_rc2str(mbox_cmd)); return 0; /* completed but caller must check return_code */ }
Use the global cxl_mbox_cmd_rc table to improve debug messaging in __cxl_pci_mbox_send_cmd() and allow cxl_mbox_send_cmd() to map to proper kernel style errno codes - this patch continues to use -ENXIO only so no change in semantics. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> --- drivers/cxl/core/mbox.c | 7 ++++--- drivers/cxl/pci.c | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-)