* [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format
@ 2017-02-24 19:35 ` Michal Suchanek
0 siblings, 0 replies; 26+ messages in thread
From: Michal Suchanek @ 2017-02-24 19:35 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ashley Lai, Peter Huewe, Marcel Selhorst, Jarkko Sakkinen,
Jason Gunthorpe, linuxppc-dev, tpmdd-devel, linux-kernel
Cc: Michal Suchanek
The crq is passed in registers and is the same on BE and LE hosts.
However, current implementation allocates a structure on-stack to
represent the crq, initializes the members swapping them to BE, and
loads the structure swapping it from BE. This is pointless and causes
GCC warnings about ununitialized members. Get rid of the structure and
the warnings.
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
v2
fix typos and spelling in comments
---
drivers/char/tpm/tpm_ibmvtpm.c | 96 ++++++++++++++++++++++++++----------------
1 file changed, 60 insertions(+), 36 deletions(-)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index 1b9d61ffe991..89027339d55f 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -39,19 +39,63 @@ static struct vio_device_id tpm_ibmvtpm_device_table[] = {
MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);
/**
+ *
+ * ibmvtpm_send_crq_word - Send a CRQ request
+ * @vdev: vio device struct
+ * @w1: pre-constructed first word of tpm crq (second word is reserved)
+ *
+ * Return:
+ * 0 - Success
+ * Non-zero - Failure
+ */
+static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
+{
+ return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, w1, 0);
+}
+
+/**
+ *
* ibmvtpm_send_crq - Send a CRQ request
*
* @vdev: vio device struct
- * @w1: first word
- * @w2: second word
+ * @valid: Valid field
+ * @msg: Type field
+ * @len: Length field
+ * @data: Data field
+ *
+ * The ibmvtpm crq is defined as follows:
+ *
+ * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
+ * -----------------------------------------------------------------------
+ * Word0 | Valid | Type | Length | Data
+ * -----------------------------------------------------------------------
+ * Word1 | Reserved
+ * -----------------------------------------------------------------------
+ *
+ * Which matches the following structure (on bigendian host):
+ *
+ * struct ibmvtpm_crq {
+ * u8 valid;
+ * u8 msg;
+ * __be16 len;
+ * __be32 data;
+ * __be64 reserved;
+ * } __attribute__((packed, aligned(8)));
+ *
+ * However, the value is passed in a register so just compute the numeric value
+ * to load into the register avoiding byteswap altogether. Endian only affects
+ * memory loads and stores - registers are internally represented the same.
*
* Return:
- * 0 -Sucess
+ * 0 (H_SUCCESS) - Success
* Non-zero - Failure
*/
-static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2)
+static int ibmvtpm_send_crq(struct vio_dev *vdev,
+ u8 valid, u8 msg, u16 len, u32 data)
{
- return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, w1, w2);
+ u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len << 32) |
+ (u64)data;
+ return ibmvtpm_send_crq_word(vdev, w1);
}
/**
@@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
{
struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
- struct ibmvtpm_crq crq;
- __be64 *word = (__be64 *)&crq;
int rc, sig;
if (!ibmvtpm->rtce_buf) {
@@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
spin_lock(&ibmvtpm->rtce_lock);
ibmvtpm->res_len = 0;
memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_TPM_COMMAND;
- crq.len = cpu_to_be16(count);
- crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
/*
* set the processing flag before the Hcall, since we may get the
@@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
*/
ibmvtpm->tpm_processing_cmd = true;
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
- be64_to_cpu(word[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
+ count, ibmvtpm->rtce_dma_handle);
if (rc != H_SUCCESS) {
dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
rc = 0;
@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip *chip)
*/
static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
{
- struct ibmvtpm_crq crq;
- u64 *buf = (u64 *) &crq;
int rc;
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE;
-
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
- cpu_to_be64(buf[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_GET_RTCE_BUFFER_SIZE, 0, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_get_rtce_size failed rc=%d\n", rc);
@@ -210,15 +244,10 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
*/
static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
{
- struct ibmvtpm_crq crq;
- u64 *buf = (u64 *) &crq;
int rc;
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_GET_VERSION;
-
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
- cpu_to_be64(buf[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_get_version failed rc=%d\n", rc);
@@ -238,7 +267,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm)
{
int rc;
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
+ rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_send_init_complete failed rc=%d\n", rc);
@@ -258,7 +287,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
{
int rc;
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
+ rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_send_init failed rc=%d\n", rc);
@@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev)
{
struct tpm_chip *chip = dev_get_drvdata(dev);
struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
- struct ibmvtpm_crq crq;
- u64 *buf = (u64 *) &crq;
int rc = 0;
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND;
-
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
- cpu_to_be64(buf[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND, 0, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"tpm_ibmvtpm_suspend failed rc=%d\n", rc);
--
2.10.2
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format
@ 2017-02-24 19:35 ` Michal Suchanek
0 siblings, 0 replies; 26+ messages in thread
From: Michal Suchanek @ 2017-02-24 19:35 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ashley Lai, Peter Huewe, Marcel Selhorst, Jarkko Sakkinen,
Jason Gunthorpe, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ,
tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Cc: Michal Suchanek
The crq is passed in registers and is the same on BE and LE hosts.
However, current implementation allocates a structure on-stack to
represent the crq, initializes the members swapping them to BE, and
loads the structure swapping it from BE. This is pointless and causes
GCC warnings about ununitialized members. Get rid of the structure and
the warnings.
Signed-off-by: Michal Suchanek <msuchanek-l3A5Bk7waGM@public.gmane.org>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
v2
fix typos and spelling in comments
---
drivers/char/tpm/tpm_ibmvtpm.c | 96 ++++++++++++++++++++++++++----------------
1 file changed, 60 insertions(+), 36 deletions(-)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index 1b9d61ffe991..89027339d55f 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -39,19 +39,63 @@ static struct vio_device_id tpm_ibmvtpm_device_table[] = {
MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);
/**
+ *
+ * ibmvtpm_send_crq_word - Send a CRQ request
+ * @vdev: vio device struct
+ * @w1: pre-constructed first word of tpm crq (second word is reserved)
+ *
+ * Return:
+ * 0 - Success
+ * Non-zero - Failure
+ */
+static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
+{
+ return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, w1, 0);
+}
+
+/**
+ *
* ibmvtpm_send_crq - Send a CRQ request
*
* @vdev: vio device struct
- * @w1: first word
- * @w2: second word
+ * @valid: Valid field
+ * @msg: Type field
+ * @len: Length field
+ * @data: Data field
+ *
+ * The ibmvtpm crq is defined as follows:
+ *
+ * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
+ * -----------------------------------------------------------------------
+ * Word0 | Valid | Type | Length | Data
+ * -----------------------------------------------------------------------
+ * Word1 | Reserved
+ * -----------------------------------------------------------------------
+ *
+ * Which matches the following structure (on bigendian host):
+ *
+ * struct ibmvtpm_crq {
+ * u8 valid;
+ * u8 msg;
+ * __be16 len;
+ * __be32 data;
+ * __be64 reserved;
+ * } __attribute__((packed, aligned(8)));
+ *
+ * However, the value is passed in a register so just compute the numeric value
+ * to load into the register avoiding byteswap altogether. Endian only affects
+ * memory loads and stores - registers are internally represented the same.
*
* Return:
- * 0 -Sucess
+ * 0 (H_SUCCESS) - Success
* Non-zero - Failure
*/
-static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2)
+static int ibmvtpm_send_crq(struct vio_dev *vdev,
+ u8 valid, u8 msg, u16 len, u32 data)
{
- return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, w1, w2);
+ u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len << 32) |
+ (u64)data;
+ return ibmvtpm_send_crq_word(vdev, w1);
}
/**
@@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
{
struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
- struct ibmvtpm_crq crq;
- __be64 *word = (__be64 *)&crq;
int rc, sig;
if (!ibmvtpm->rtce_buf) {
@@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
spin_lock(&ibmvtpm->rtce_lock);
ibmvtpm->res_len = 0;
memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_TPM_COMMAND;
- crq.len = cpu_to_be16(count);
- crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
/*
* set the processing flag before the Hcall, since we may get the
@@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
*/
ibmvtpm->tpm_processing_cmd = true;
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
- be64_to_cpu(word[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
+ count, ibmvtpm->rtce_dma_handle);
if (rc != H_SUCCESS) {
dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
rc = 0;
@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip *chip)
*/
static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
{
- struct ibmvtpm_crq crq;
- u64 *buf = (u64 *) &crq;
int rc;
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE;
-
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
- cpu_to_be64(buf[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_GET_RTCE_BUFFER_SIZE, 0, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_get_rtce_size failed rc=%d\n", rc);
@@ -210,15 +244,10 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
*/
static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
{
- struct ibmvtpm_crq crq;
- u64 *buf = (u64 *) &crq;
int rc;
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_GET_VERSION;
-
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
- cpu_to_be64(buf[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_get_version failed rc=%d\n", rc);
@@ -238,7 +267,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm)
{
int rc;
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
+ rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_send_init_complete failed rc=%d\n", rc);
@@ -258,7 +287,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
{
int rc;
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
+ rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"ibmvtpm_crq_send_init failed rc=%d\n", rc);
@@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev)
{
struct tpm_chip *chip = dev_get_drvdata(dev);
struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
- struct ibmvtpm_crq crq;
- u64 *buf = (u64 *) &crq;
int rc = 0;
- crq.valid = (u8)IBMVTPM_VALID_CMD;
- crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND;
-
- rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
- cpu_to_be64(buf[1]));
+ rc = ibmvtpm_send_crq(ibmvtpm->vdev,
+ IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND, 0, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
"tpm_ibmvtpm_suspend failed rc=%d\n", rc);
--
2.10.2
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix
@ 2017-07-29 7:24 SZ Lin
2017-02-24 19:35 ` Michal Suchanek
` (6 more replies)
0 siblings, 7 replies; 26+ messages in thread
From: SZ Lin @ 2017-07-29 7:24 UTC (permalink / raw)
To: ashleydlai
Cc: benh, paulus, mpe, peterhuewe, tpmdd, jarkko.sakkinen,
jgunthorpe, tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
Fix styling WARNINGs and Errors of tpm_ibmvtpm.c driver by using checkpatch.pl
SZ Lin (5):
Fix packed and aligned attribute warnings.
Fix "ERROR: code indent should use tabs where possible"
Fix 'void function return statements are not generally useful' warning
Remove unneccessary 'out of memory' message
Use __func__ instead of function name
drivers/char/tpm/tpm_ibmvtpm.c | 23 +++++++++--------------
drivers/char/tpm/tpm_ibmvtpm.h | 2 +-
2 files changed, 10 insertions(+), 15 deletions(-)
--
2.13.3
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH 1/5] Fix packed and aligned attribute warnings.
2017-07-29 7:24 [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix SZ Lin
2017-02-24 19:35 ` Michal Suchanek
@ 2017-07-29 7:24 ` SZ Lin
2017-07-31 13:27 ` David Laight
2017-07-29 7:24 ` [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible" SZ Lin
` (4 subsequent siblings)
6 siblings, 1 reply; 26+ messages in thread
From: SZ Lin @ 2017-07-29 7:24 UTC (permalink / raw)
To: ashleydlai
Cc: benh, paulus, mpe, peterhuewe, tpmdd, jarkko.sakkinen,
jgunthorpe, tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
WARNING: __packed is preferred over __attribute__((packed))
+} __attribute__((packed, aligned(8)));
WARNING: __aligned(size) is preferred over __attribute__((aligned(size)))
+} __attribute__((packed, aligned(8)));
Signed-off-by: SZ Lin <sz.lin@moxa.com>
---
drivers/char/tpm/tpm_ibmvtpm.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.h b/drivers/char/tpm/tpm_ibmvtpm.h
index 91dfe766d080..9f708ca3dc84 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.h
+++ b/drivers/char/tpm/tpm_ibmvtpm.h
@@ -25,7 +25,7 @@ struct ibmvtpm_crq {
__be16 len;
__be32 data;
__be64 reserved;
-} __attribute__((packed, aligned(8)));
+} __packed __aligned(8);
struct ibmvtpm_crq_queue {
struct ibmvtpm_crq *crq_addr;
--
2.13.3
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible"
2017-07-29 7:24 [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix SZ Lin
2017-02-24 19:35 ` Michal Suchanek
2017-07-29 7:24 ` [PATCH 1/5] Fix packed and aligned attribute warnings SZ Lin
@ 2017-07-29 7:24 ` SZ Lin
2017-07-31 10:25 ` Michael Ellerman
2017-07-29 7:24 ` [PATCH 3/5] Fix 'void function return statements are not generally useful' warning SZ Lin
` (3 subsequent siblings)
6 siblings, 1 reply; 26+ messages in thread
From: SZ Lin @ 2017-07-29 7:24 UTC (permalink / raw)
To: ashleydlai
Cc: benh, paulus, mpe, peterhuewe, tpmdd, jarkko.sakkinen,
jgunthorpe, tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
ERROR: code indent should use tabs where possible
+^I^I "Need to wait for TPM to finish\n");$
Signed-off-by: SZ Lin <sz.lin@moxa.com>
---
drivers/char/tpm/tpm_ibmvtpm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index f01d083eced2..23913fc86158 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -127,7 +127,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
if (ibmvtpm->tpm_processing_cmd) {
dev_info(ibmvtpm->dev,
- "Need to wait for TPM to finish\n");
+ "Need to wait for TPM to finish\n");
/* wait for previous command to finish */
sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);
if (sig)
--
2.13.3
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH 3/5] Fix 'void function return statements are not generally useful' warning
2017-07-29 7:24 [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix SZ Lin
` (2 preceding siblings ...)
2017-07-29 7:24 ` [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible" SZ Lin
@ 2017-07-29 7:24 ` SZ Lin
2017-07-29 7:24 ` [PATCH 4/5] Remove unneccessary 'out of memory' message SZ Lin
` (2 subsequent siblings)
6 siblings, 0 replies; 26+ messages in thread
From: SZ Lin @ 2017-07-29 7:24 UTC (permalink / raw)
To: ashleydlai
Cc: benh, paulus, mpe, peterhuewe, tpmdd, jarkko.sakkinen,
jgunthorpe, tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
WARNING: void function return statements are not generally useful
+ return;
+}
Signed-off-by: SZ Lin <sz.lin@moxa.com>
---
drivers/char/tpm/tpm_ibmvtpm.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index 23913fc86158..e53b9fb517d9 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -531,7 +531,6 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,
return;
}
}
- return;
}
/**
--
2.13.3
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH 4/5] Remove unneccessary 'out of memory' message
2017-07-29 7:24 [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix SZ Lin
` (3 preceding siblings ...)
2017-07-29 7:24 ` [PATCH 3/5] Fix 'void function return statements are not generally useful' warning SZ Lin
@ 2017-07-29 7:24 ` SZ Lin
2017-07-29 7:24 ` [PATCH 5/5] Use __func__ instead of function name SZ Lin
2017-08-02 12:36 ` [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix Jarkko Sakkinen
6 siblings, 0 replies; 26+ messages in thread
From: SZ Lin @ 2017-07-29 7:24 UTC (permalink / raw)
To: ashleydlai
Cc: benh, paulus, mpe, peterhuewe, tpmdd, jarkko.sakkinen,
jgunthorpe, tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
WARNING: Possible unnecessary 'out of memory' message
+ if (!ibmvtpm->rtce_buf) {
+ dev_err(ibmvtpm->dev, "Failed to allocate memory for rtce buffer\n");
WARNING: Possible unnecessary 'out of memory' message
+ if (!ibmvtpm) {
+ dev_err(dev, "kzalloc for ibmvtpm failed\n");
Signed-off-by: SZ Lin <sz.lin@moxa.com>
---
drivers/char/tpm/tpm_ibmvtpm.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index e53b9fb517d9..e75a674b44ac 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -501,10 +501,8 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,
ibmvtpm->rtce_size = be16_to_cpu(crq->len);
ibmvtpm->rtce_buf = kmalloc(ibmvtpm->rtce_size,
GFP_ATOMIC);
- if (!ibmvtpm->rtce_buf) {
- dev_err(ibmvtpm->dev, "Failed to allocate memory for rtce buffer\n");
+ if (!ibmvtpm->rtce_buf)
return;
- }
ibmvtpm->rtce_dma_handle = dma_map_single(ibmvtpm->dev,
ibmvtpm->rtce_buf, ibmvtpm->rtce_size,
@@ -584,10 +582,8 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
return PTR_ERR(chip);
ibmvtpm = kzalloc(sizeof(struct ibmvtpm_dev), GFP_KERNEL);
- if (!ibmvtpm) {
- dev_err(dev, "kzalloc for ibmvtpm failed\n");
+ if (!ibmvtpm)
goto cleanup;
- }
ibmvtpm->dev = dev;
ibmvtpm->vdev = vio_dev;
--
2.13.3
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH 5/5] Use __func__ instead of function name
2017-07-29 7:24 [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix SZ Lin
` (4 preceding siblings ...)
2017-07-29 7:24 ` [PATCH 4/5] Remove unneccessary 'out of memory' message SZ Lin
@ 2017-07-29 7:24 ` SZ Lin
2017-08-18 8:03 ` Michal Suchánek
2017-08-19 7:58 ` 김동현
2017-08-02 12:36 ` [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix Jarkko Sakkinen
6 siblings, 2 replies; 26+ messages in thread
From: SZ Lin @ 2017-07-29 7:24 UTC (permalink / raw)
To: ashleydlai
Cc: benh, paulus, mpe, peterhuewe, tpmdd, jarkko.sakkinen,
jgunthorpe, tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
Fix following checkpatch.pl warning:
WARNING: Prefer using '"%s...", __func__' to using
the function's name, in a string
Signed-off-by: SZ Lin <sz.lin@moxa.com>
---
drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index e75a674b44ac..2d33acc43e25 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
be64_to_cpu(word[1]));
if (rc != H_SUCCESS) {
- dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
+ dev_err(ibmvtpm->dev, "%s failed rc=%d\n", __func__, rc);
rc = 0;
ibmvtpm->tpm_processing_cmd = false;
} else
@@ -193,7 +193,7 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
cpu_to_be64(buf[1]));
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
- "ibmvtpm_crq_get_rtce_size failed rc=%d\n", rc);
+ "%s failed rc=%d\n", __func__, rc);
return rc;
}
@@ -221,7 +221,7 @@ static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
cpu_to_be64(buf[1]));
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
- "ibmvtpm_crq_get_version failed rc=%d\n", rc);
+ "%s failed rc=%d\n", __func__, rc);
return rc;
}
@@ -241,7 +241,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm)
rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
- "ibmvtpm_crq_send_init_complete failed rc=%d\n", rc);
+ "%s rc=%d\n", __func__, rc);
return rc;
}
@@ -261,7 +261,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
- "ibmvtpm_crq_send_init failed rc=%d\n", rc);
+ "%s failed rc=%d\n", __func__, rc);
return rc;
}
@@ -351,7 +351,7 @@ static int tpm_ibmvtpm_suspend(struct device *dev)
cpu_to_be64(buf[1]));
if (rc != H_SUCCESS)
dev_err(ibmvtpm->dev,
- "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
+ "%s failed rc=%d\n", __func__, rc);
return rc;
}
--
2.13.3
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible"
2017-07-29 7:24 ` [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible" SZ Lin
@ 2017-07-31 10:25 ` Michael Ellerman
0 siblings, 0 replies; 26+ messages in thread
From: Michael Ellerman @ 2017-07-31 10:25 UTC (permalink / raw)
To: SZ Lin, ashleydlai
Cc: benh, paulus, peterhuewe, tpmdd, jarkko.sakkinen, jgunthorpe,
tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
SZ Lin <sz.lin@moxa.com> writes:
> ERROR: code indent should use tabs where possible
> +^I^I "Need to wait for TPM to finish\n");$
>
> Signed-off-by: SZ Lin <sz.lin@moxa.com>
> ---
> drivers/char/tpm/tpm_ibmvtpm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
> index f01d083eced2..23913fc86158 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -127,7 +127,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
>
> if (ibmvtpm->tpm_processing_cmd) {
> dev_info(ibmvtpm->dev,
> - "Need to wait for TPM to finish\n");
> + "Need to wait for TPM to finish\n");
There's no reason for that to be on a separate line at all. Just make it
a single line dev_info( ... );
cheers
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible"
@ 2017-07-31 10:25 ` Michael Ellerman
0 siblings, 0 replies; 26+ messages in thread
From: Michael Ellerman @ 2017-07-31 10:25 UTC (permalink / raw)
To: ashleydlai
Cc: benh, paulus, peterhuewe, tpmdd, jarkko.sakkinen, jgunthorpe,
tpmdd-devel, linuxppc-dev, linux-kernel, SZ Lin
SZ Lin <sz.lin@moxa.com> writes:
> ERROR: code indent should use tabs where possible
> +^I^I "Need to wait for TPM to finish\n");$
>
> Signed-off-by: SZ Lin <sz.lin@moxa.com>
> ---
> drivers/char/tpm/tpm_ibmvtpm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
> index f01d083eced2..23913fc86158 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -127,7 +127,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
>
> if (ibmvtpm->tpm_processing_cmd) {
> dev_info(ibmvtpm->dev,
> - "Need to wait for TPM to finish\n");
> + "Need to wait for TPM to finish\n");
There's no reason for that to be on a separate line at all. Just make it
a single line dev_info( ... );
cheers
^ permalink raw reply [flat|nested] 26+ messages in thread
* RE: [PATCH 1/5] Fix packed and aligned attribute warnings.
2017-07-29 7:24 ` [PATCH 1/5] Fix packed and aligned attribute warnings SZ Lin
2017-07-31 13:27 ` David Laight
@ 2017-07-31 13:27 ` David Laight
0 siblings, 0 replies; 26+ messages in thread
From: David Laight @ 2017-07-31 13:27 UTC (permalink / raw)
To: 'SZ Lin', ashleydlai
Cc: linux-kernel, jarkko.sakkinen, jgunthorpe, tpmdd-devel, paulus,
peterhuewe, linuxppc-dev, tpmdd
From: SZ Lin
> Sent: 29 July 2017 08:24
...
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.h b/drivers/char/tpm/tpm_ibmvtpm.h
> index 91dfe766d080..9f708ca3dc84 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.h
> +++ b/drivers/char/tpm/tpm_ibmvtpm.h
> @@ -25,7 +25,7 @@ struct ibmvtpm_crq {
> __be16 len;
> __be32 data;
> __be64 reserved;
> -} __attribute__((packed, aligned(8)));
> +} __packed __aligned(8);
You can't need __packed and __aligned(8) on that structure.
There are no gaps and you are saying it is always aligned.
So just remove the pointless attributes.
David
^ permalink raw reply [flat|nested] 26+ messages in thread
* RE: [PATCH 1/5] Fix packed and aligned attribute warnings.
@ 2017-07-31 13:27 ` David Laight
0 siblings, 0 replies; 26+ messages in thread
From: David Laight @ 2017-07-31 13:27 UTC (permalink / raw)
To: 'SZ Lin', ashleydlai
Cc: linux-kernel, jarkko.sakkinen, jgunthorpe, tpmdd-devel, paulus,
peterhuewe, linuxppc-dev, tpmdd
From: SZ Lin
> Sent: 29 July 2017 08:24
...
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.h b/drivers/char/tpm/tpm_ibmvtp=
m.h
> index 91dfe766d080..9f708ca3dc84 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.h
> +++ b/drivers/char/tpm/tpm_ibmvtpm.h
> @@ -25,7 +25,7 @@ struct ibmvtpm_crq {
> __be16 len;
> __be32 data;
> __be64 reserved;
> -} __attribute__((packed, aligned(8)));
> +} __packed __aligned(8);
You can't need __packed and __aligned(8) on that structure.
There are no gaps and you are saying it is always aligned.
So just remove the pointless attributes.
David
^ permalink raw reply [flat|nested] 26+ messages in thread
* RE: [PATCH 1/5] Fix packed and aligned attribute warnings.
@ 2017-07-31 13:27 ` David Laight
0 siblings, 0 replies; 26+ messages in thread
From: David Laight @ 2017-07-31 13:27 UTC (permalink / raw)
To: 'SZ Lin', ashleydlai
Cc: linux-kernel, jarkko.sakkinen, jgunthorpe, tpmdd-devel, paulus,
peterhuewe, linuxppc-dev, tpmdd
From: SZ Lin
> Sent: 29 July 2017 08:24
...
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.h b/drivers/char/tpm/tpm_ibmvtpm.h
> index 91dfe766d080..9f708ca3dc84 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.h
> +++ b/drivers/char/tpm/tpm_ibmvtpm.h
> @@ -25,7 +25,7 @@ struct ibmvtpm_crq {
> __be16 len;
> __be32 data;
> __be64 reserved;
> -} __attribute__((packed, aligned(8)));
> +} __packed __aligned(8);
You can't need __packed and __aligned(8) on that structure.
There are no gaps and you are saying it is always aligned.
So just remove the pointless attributes.
David
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix
2017-07-29 7:24 [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix SZ Lin
` (5 preceding siblings ...)
2017-07-29 7:24 ` [PATCH 5/5] Use __func__ instead of function name SZ Lin
@ 2017-08-02 12:36 ` Jarkko Sakkinen
6 siblings, 0 replies; 26+ messages in thread
From: Jarkko Sakkinen @ 2017-08-02 12:36 UTC (permalink / raw)
To: SZ Lin
Cc: ashleydlai, benh, paulus, mpe, peterhuewe, tpmdd, jgunthorpe,
tpmdd-devel, linuxppc-dev, linux-kernel
On Sat, Jul 29, 2017 at 03:24:28PM +0800, SZ Lin wrote:
> Fix styling WARNINGs and Errors of tpm_ibmvtpm.c driver by using checkpatch.pl
Changes are great but you should revise the patch series so that you
expain in each commit what goes wrong instead of copy paste of the
checkpatch output and why your changes fixes the problem.
>
> SZ Lin (5):
> Fix packed and aligned attribute warnings.
> Fix "ERROR: code indent should use tabs where possible"
> Fix 'void function return statements are not generally useful' warning
> Remove unneccessary 'out of memory' message
> Use __func__ instead of function name
>
> drivers/char/tpm/tpm_ibmvtpm.c | 23 +++++++++--------------
> drivers/char/tpm/tpm_ibmvtpm.h | 2 +-
> 2 files changed, 10 insertions(+), 15 deletions(-)
>
> --
> 2.13.3
>
/Jarkko
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format
2017-02-24 19:35 ` Michal Suchanek
(?)
@ 2017-08-17 22:21 ` msuchanek
2017-08-19 17:18 ` Jarkko Sakkinen
-1 siblings, 1 reply; 26+ messages in thread
From: msuchanek @ 2017-08-17 22:21 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ashley Lai, Peter Huewe, Marcel Selhorst, Jarkko Sakkinen,
Jason Gunthorpe, linuxppc-dev, tpmdd-devel, linux-kernel
Cc: tpmdd
ping?
On Fri, 24 Feb 2017 20:35:16 +0100
Michal Suchanek <msuchanek@suse.de> wrote:
> The crq is passed in registers and is the same on BE and LE hosts.
> However, current implementation allocates a structure on-stack to
> represent the crq, initializes the members swapping them to BE, and
> loads the structure swapping it from BE. This is pointless and causes
> GCC warnings about ununitialized members. Get rid of the structure and
> the warnings.
>
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> v2
>
> fix typos and spelling in comments
> ---
> drivers/char/tpm/tpm_ibmvtpm.c | 96
> ++++++++++++++++++++++++++---------------- 1 file changed, 60
> insertions(+), 36 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> b/drivers/char/tpm/tpm_ibmvtpm.c index 1b9d61ffe991..89027339d55f
> 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -39,19 +39,63 @@ static struct vio_device_id
> tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio,
> tpm_ibmvtpm_device_table);
> /**
> + *
> + * ibmvtpm_send_crq_word - Send a CRQ request
> + * @vdev: vio device struct
> + * @w1: pre-constructed first word of tpm crq (second
> word is reserved)
> + *
> + * Return:
> + * 0 - Success
> + * Non-zero - Failure
> + */
> +static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
> +{
> + return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> w1, 0); +}
> +
> +/**
> + *
> * ibmvtpm_send_crq - Send a CRQ request
> *
> * @vdev: vio device struct
> - * @w1: first word
> - * @w2: second word
> + * @valid: Valid field
> + * @msg: Type field
> + * @len: Length field
> + * @data: Data field
> + *
> + * The ibmvtpm crq is defined as follows:
> + *
> + * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
> 7
> + *
> -----------------------------------------------------------------------
> + * Word0 | Valid | Type | Length | Data
> + *
> -----------------------------------------------------------------------
> + * Word1 | Reserved
> + *
> -----------------------------------------------------------------------
> + *
> + * Which matches the following structure (on bigendian host):
> + *
> + * struct ibmvtpm_crq {
> + * u8 valid;
> + * u8 msg;
> + * __be16 len;
> + * __be32 data;
> + * __be64 reserved;
> + * } __attribute__((packed, aligned(8)));
> + *
> + * However, the value is passed in a register so just compute the
> numeric value
> + * to load into the register avoiding byteswap altogether. Endian
> only affects
> + * memory loads and stores - registers are internally represented
> the same. *
> * Return:
> - * 0 -Sucess
> + * 0 (H_SUCCESS) - Success
> * Non-zero - Failure
> */
> -static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2)
> +static int ibmvtpm_send_crq(struct vio_dev *vdev,
> + u8 valid, u8 msg, u16 len, u32 data)
> {
> - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> w1, w2);
> + u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len
> << 32) |
> + (u64)data;
> + return ibmvtpm_send_crq_word(vdev, w1);
> }
>
> /**
> @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip
> *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(struct
> tpm_chip *chip, u8 *buf, size_t count) {
> struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> - struct ibmvtpm_crq crq;
> - __be64 *word = (__be64 *)&crq;
> int rc, sig;
>
> if (!ibmvtpm->rtce_buf) {
> @@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip
> *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock);
> ibmvtpm->res_len = 0;
> memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
> - crq.valid = (u8)IBMVTPM_VALID_CMD;
> - crq.msg = (u8)VTPM_TPM_COMMAND;
> - crq.len = cpu_to_be16(count);
> - crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
>
> /*
> * set the processing flag before the Hcall, since we may
> get the @@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct
> tpm_chip *chip, u8 *buf, size_t count) */
> ibmvtpm->tpm_processing_cmd = true;
>
> - rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> - be64_to_cpu(word[1]));
> + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> + IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
> + count, ibmvtpm->rtce_dma_handle);
> if (rc != H_SUCCESS) {
> dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed
> rc=%d\n", rc); rc = 0;
> @@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip
> *chip) */
> static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
> {
> - struct ibmvtpm_crq crq;
> - u64 *buf = (u64 *) &crq;
> int rc;
>
> - crq.valid = (u8)IBMVTPM_VALID_CMD;
> - crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE;
> -
> - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> - cpu_to_be64(buf[1]));
> + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> + IBMVTPM_VALID_CMD,
> VTPM_GET_RTCE_BUFFER_SIZE, 0, 0); if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> "ibmvtpm_crq_get_rtce_size failed rc=%d\n",
> rc); @@ -210,15 +244,10 @@ static int
> ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) */
> static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
> {
> - struct ibmvtpm_crq crq;
> - u64 *buf = (u64 *) &crq;
> int rc;
>
> - crq.valid = (u8)IBMVTPM_VALID_CMD;
> - crq.msg = (u8)VTPM_GET_VERSION;
> -
> - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> - cpu_to_be64(buf[1]));
> + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> + IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0);
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> "ibmvtpm_crq_get_version failed rc=%d\n",
> rc); @@ -238,7 +267,7 @@ static int
> ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) {
> int rc;
>
> - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
> + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD);
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> "ibmvtpm_crq_send_init_complete failed
> rc=%d\n", rc); @@ -258,7 +287,7 @@ static int
> ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) {
> int rc;
>
> - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
> + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> "ibmvtpm_crq_send_init failed rc=%d\n", rc);
> @@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device
> *dev) {
> struct tpm_chip *chip = dev_get_drvdata(dev);
> struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> - struct ibmvtpm_crq crq;
> - u64 *buf = (u64 *) &crq;
> int rc = 0;
>
> - crq.valid = (u8)IBMVTPM_VALID_CMD;
> - crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND;
> -
> - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> - cpu_to_be64(buf[1]));
> + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> + IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND,
> 0, 0); if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 5/5] Use __func__ instead of function name
2017-07-29 7:24 ` [PATCH 5/5] Use __func__ instead of function name SZ Lin
2017-08-18 8:03 ` Michal Suchánek
@ 2017-08-18 8:03 ` Michal Suchánek
1 sibling, 0 replies; 26+ messages in thread
From: Michal Suchánek @ 2017-08-18 8:03 UTC (permalink / raw)
To: SZ Lin
Cc: ashleydlai, linux-kernel, jarkko.sakkinen, jgunthorpe,
tpmdd-devel, paulus, peterhuewe, linuxppc-dev, tpmdd,
Linuxppc-dev
On 2017-07-29 09:24, SZ Lin wrote:
> Fix following checkpatch.pl warning:
> WARNING: Prefer using '"%s...", __func__' to using
> the function's name, in a string
>
> Signed-off-by: SZ Lin <sz.lin@moxa.com>
> ---
> drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> b/drivers/char/tpm/tpm_ibmvtpm.c
> index e75a674b44ac..2d33acc43e25 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
> u8 *buf, size_t count)
> rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> be64_to_cpu(word[1]));
> if (rc != H_SUCCESS) {
> - dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
> + dev_err(ibmvtpm->dev, "%s failed rc=%d\n", __func__, rc);
Can function name contain a %?
I would prefer dev_err(ibmvtpm->dev, __func__ " failed rc=%d\n", rc);
It's not what checkpatch advises in the above message, though.
Presumably with many messages from the same function using %s would
save space but that is not the usual case.
Thanks
Michal
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 5/5] Use __func__ instead of function name
@ 2017-08-18 8:03 ` Michal Suchánek
0 siblings, 0 replies; 26+ messages in thread
From: Michal Suchánek @ 2017-08-18 8:03 UTC (permalink / raw)
To: SZ Lin
Cc: ashleydlai, linux-kernel, jarkko.sakkinen, jgunthorpe,
tpmdd-devel, paulus, peterhuewe, linuxppc-dev, tpmdd,
Linuxppc-dev
On 2017-07-29 09:24, SZ Lin wrote:
> Fix following checkpatch.pl warning:
> WARNING: Prefer using '"%s...", __func__' to using
> the function's name, in a string
>
> Signed-off-by: SZ Lin <sz.lin@moxa.com>
> ---
> drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> b/drivers/char/tpm/tpm_ibmvtpm.c
> index e75a674b44ac..2d33acc43e25 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
> u8 *buf, size_t count)
> rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> be64_to_cpu(word[1]));
> if (rc != H_SUCCESS) {
> - dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
> + dev_err(ibmvtpm->dev, "%s failed rc=%d\n", __func__, rc);
Can function name contain a %?
I would prefer dev_err(ibmvtpm->dev, __func__ " failed rc=%d\n", rc);
It's not what checkpatch advises in the above message, though.
Presumably with many messages from the same function using %s would
save space but that is not the usual case.
Thanks
Michal
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 5/5] Use __func__ instead of function name
@ 2017-08-18 8:03 ` Michal Suchánek
0 siblings, 0 replies; 26+ messages in thread
From: Michal Suchánek @ 2017-08-18 8:03 UTC (permalink / raw)
To: SZ Lin
Cc: Linuxppc-dev, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA,
jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
paulus-eUNUBHrolfbYtjvyW6yDsg, ashleydlai-Re5JQEeQqe8AvxtiuMwx3w,
linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ,
tpmdd-yWjUBOtONeeDGRHsOpWV0g
On 2017-07-29 09:24, SZ Lin wrote:
> Fix following checkpatch.pl warning:
> WARNING: Prefer using '"%s...", __func__' to using
> the function's name, in a string
>
> Signed-off-by: SZ Lin <sz.lin-D4fb9hXD9d4@public.gmane.org>
> ---
> drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> b/drivers/char/tpm/tpm_ibmvtpm.c
> index e75a674b44ac..2d33acc43e25 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
> u8 *buf, size_t count)
> rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> be64_to_cpu(word[1]));
> if (rc != H_SUCCESS) {
> - dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
> + dev_err(ibmvtpm->dev, "%s failed rc=%d\n", __func__, rc);
Can function name contain a %?
I would prefer dev_err(ibmvtpm->dev, __func__ " failed rc=%d\n", rc);
It's not what checkpatch advises in the above message, though.
Presumably with many messages from the same function using %s would
save space but that is not the usual case.
Thanks
Michal
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 5/5] Use __func__ instead of function name
2017-08-18 8:03 ` Michal Suchánek
(?)
@ 2017-08-18 11:25 ` Michael Ellerman
-1 siblings, 0 replies; 26+ messages in thread
From: Michael Ellerman @ 2017-08-18 11:25 UTC (permalink / raw)
To: Michal Suchánek, SZ Lin
Cc: Linuxppc-dev, linux-kernel, jarkko.sakkinen, jgunthorpe,
tpmdd-devel, paulus, ashleydlai, peterhuewe, linuxppc-dev, tpmdd
Michal Suchánek <msuchanek@suse.de> writes:
> On 2017-07-29 09:24, SZ Lin wrote:
>> Fix following checkpatch.pl warning:
>> WARNING: Prefer using '"%s...", __func__' to using
>> the function's name, in a string
>>
>> Signed-off-by: SZ Lin <sz.lin@moxa.com>
>> ---
>> drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
>> b/drivers/char/tpm/tpm_ibmvtpm.c
>> index e75a674b44ac..2d33acc43e25 100644
>> --- a/drivers/char/tpm/tpm_ibmvtpm.c
>> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
>> @@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
>> u8 *buf, size_t count)
>> rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
>> be64_to_cpu(word[1]));
>> if (rc != H_SUCCESS) {
>> - dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
>> + dev_err(ibmvtpm->dev, "%s failed rc=%d\n", __func__, rc);
>
> Can function name contain a %?
Let's hope not.
$ git grep "%s.*__func__" | wc -l
16937
cheers
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 5/5] Use __func__ instead of function name
@ 2017-08-18 11:25 ` Michael Ellerman
0 siblings, 0 replies; 26+ messages in thread
From: Michael Ellerman @ 2017-08-18 11:25 UTC (permalink / raw)
To: Michal Suchánek, SZ Lin
Cc: Linuxppc-dev, linux-kernel, jarkko.sakkinen, jgunthorpe,
tpmdd-devel, paulus, ashleydlai, peterhuewe, linuxppc-dev, tpmdd
Michal Such=C3=A1nek <msuchanek@suse.de> writes:
> On 2017-07-29 09:24, SZ Lin wrote:
>> Fix following checkpatch.pl warning:
>> WARNING: Prefer using '"%s...", __func__' to using
>> the function's name, in a string
>>=20
>> Signed-off-by: SZ Lin <sz.lin@moxa.com>
>> ---
>> drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>=20
>> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c=20
>> b/drivers/char/tpm/tpm_ibmvtpm.c
>> index e75a674b44ac..2d33acc43e25 100644
>> --- a/drivers/char/tpm/tpm_ibmvtpm.c
>> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
>> @@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
>> u8 *buf, size_t count)
>> rc =3D ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
>> be64_to_cpu(word[1]));
>> if (rc !=3D H_SUCCESS) {
>> - dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=3D%d\n", rc);
>> + dev_err(ibmvtpm->dev, "%s failed rc=3D%d\n", __func__, rc);
>
> Can function name contain a %?
Let's hope not.
$ git grep "%s.*__func__" | wc -l
16937
cheers
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 5/5] Use __func__ instead of function name
@ 2017-08-18 11:25 ` Michael Ellerman
0 siblings, 0 replies; 26+ messages in thread
From: Michael Ellerman @ 2017-08-18 11:25 UTC (permalink / raw)
To: Michal Suchánek, SZ Lin
Cc: Linuxppc-dev, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA,
jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
paulus-eUNUBHrolfbYtjvyW6yDsg, ashleydlai-Re5JQEeQqe8AvxtiuMwx3w,
linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ,
tpmdd-yWjUBOtONeeDGRHsOpWV0g
Michal Suchánek <msuchanek@suse.de> writes:
> On 2017-07-29 09:24, SZ Lin wrote:
>> Fix following checkpatch.pl warning:
>> WARNING: Prefer using '"%s...", __func__' to using
>> the function's name, in a string
>>
>> Signed-off-by: SZ Lin <sz.lin@moxa.com>
>> ---
>> drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
>> b/drivers/char/tpm/tpm_ibmvtpm.c
>> index e75a674b44ac..2d33acc43e25 100644
>> --- a/drivers/char/tpm/tpm_ibmvtpm.c
>> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
>> @@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
>> u8 *buf, size_t count)
>> rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
>> be64_to_cpu(word[1]));
>> if (rc != H_SUCCESS) {
>> - dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
>> + dev_err(ibmvtpm->dev, "%s failed rc=%d\n", __func__, rc);
>
> Can function name contain a %?
Let's hope not.
$ git grep "%s.*__func__" | wc -l
16937
cheers
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 5/5] Use __func__ instead of function name
2017-07-29 7:24 ` [PATCH 5/5] Use __func__ instead of function name SZ Lin
2017-08-18 8:03 ` Michal Suchánek
@ 2017-08-19 7:58 ` 김동현
1 sibling, 0 replies; 26+ messages in thread
From: 김동현 @ 2017-08-19 7:58 UTC (permalink / raw)
To: SZ Lin
Cc: ashleydlai, benh, paulus, mpe, peterhuewe, tpmdd,
jarkko.sakkinen, jgunthorpe, tpmdd-devel, linuxppc-dev,
linux-kernel
I guess below code would be better idea to gather more debug information.
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index 643bba7..0aae785 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -141,6 +141,11 @@ static int tpm_ibmvtpm_send(struct tpm_chip
*chip, u8 *buf, size_t count)
return -EIO;
}
+ if (!buf) {
+ dev_err(ibmvtpm->dev, "%s buf null at %d \n",__func__,
rc, __LINE__);
+ return 0;
+ }
+
spin_lock(&ibmvtpm->rtce_lock);
memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
crq.valid = (u8)IBMVTPM_VALID_CMD;
@@ -150,8 +155,9 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
u8 *buf, size_t count)
rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
be64_to_cpu(word[1]));
+
if (rc != H_SUCCESS) {
- dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
+ dev_err(ibmvtpm->dev, "%s failed rc=%d at %d
\n",__func__, rc, __LINE__);
rc = 0;
} else
rc = count;
2017-07-29 16:24 GMT+09:00 SZ Lin <sz.lin@moxa.com>:
> Fix following checkpatch.pl warning:
> WARNING: Prefer using '"%s...", __func__' to using
> the function's name, in a string
>
> Signed-off-by: SZ Lin <sz.lin@moxa.com>
> ---
> drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
> index e75a674b44ac..2d33acc43e25 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
> rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> be64_to_cpu(word[1]));
> if (rc != H_SUCCESS) {
> - dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
> + dev_err(ibmvtpm->dev, "%s failed rc=%d\n", __func__, rc);
> rc = 0;
> ibmvtpm->tpm_processing_cmd = false;
> } else
> @@ -193,7 +193,7 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
> cpu_to_be64(buf[1]));
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> - "ibmvtpm_crq_get_rtce_size failed rc=%d\n", rc);
> + "%s failed rc=%d\n", __func__, rc);
>
> return rc;
> }
> @@ -221,7 +221,7 @@ static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
> cpu_to_be64(buf[1]));
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> - "ibmvtpm_crq_get_version failed rc=%d\n", rc);
> + "%s failed rc=%d\n", __func__, rc);
>
> return rc;
> }
> @@ -241,7 +241,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm)
> rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> - "ibmvtpm_crq_send_init_complete failed rc=%d\n", rc);
> + "%s rc=%d\n", __func__, rc);
>
> return rc;
> }
> @@ -261,7 +261,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
> rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> - "ibmvtpm_crq_send_init failed rc=%d\n", rc);
> + "%s failed rc=%d\n", __func__, rc);
>
> return rc;
> }
> @@ -351,7 +351,7 @@ static int tpm_ibmvtpm_suspend(struct device *dev)
> cpu_to_be64(buf[1]));
> if (rc != H_SUCCESS)
> dev_err(ibmvtpm->dev,
> - "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
> + "%s failed rc=%d\n", __func__, rc);
>
> return rc;
> }
> --
> 2.13.3
>
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format
2017-08-17 22:21 ` msuchanek
@ 2017-08-19 17:18 ` Jarkko Sakkinen
0 siblings, 0 replies; 26+ messages in thread
From: Jarkko Sakkinen @ 2017-08-19 17:18 UTC (permalink / raw)
To: msuchanek
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ashley Lai, Peter Huewe, Marcel Selhorst, Jason Gunthorpe,
linuxppc-dev, tpmdd-devel, linux-kernel, tpmdd
Ugh. I'll apply this. My apologies.
/Jarkko
On Fri, Aug 18, 2017 at 12:21:45AM +0200, msuchanek wrote:
> ping?
>
> On Fri, 24 Feb 2017 20:35:16 +0100
> Michal Suchanek <msuchanek@suse.de> wrote:
>
> > The crq is passed in registers and is the same on BE and LE hosts.
> > However, current implementation allocates a structure on-stack to
> > represent the crq, initializes the members swapping them to BE, and
> > loads the structure swapping it from BE. This is pointless and causes
> > GCC warnings about ununitialized members. Get rid of the structure and
> > the warnings.
> >
> > Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> > v2
> >
> > fix typos and spelling in comments
> > ---
> > drivers/char/tpm/tpm_ibmvtpm.c | 96
> > ++++++++++++++++++++++++++---------------- 1 file changed, 60
> > insertions(+), 36 deletions(-)
> >
> > diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> > b/drivers/char/tpm/tpm_ibmvtpm.c index 1b9d61ffe991..89027339d55f
> > 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c
> > +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> > @@ -39,19 +39,63 @@ static struct vio_device_id
> > tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio,
> > tpm_ibmvtpm_device_table);
> > /**
> > + *
> > + * ibmvtpm_send_crq_word - Send a CRQ request
> > + * @vdev: vio device struct
> > + * @w1: pre-constructed first word of tpm crq (second
> > word is reserved)
> > + *
> > + * Return:
> > + * 0 - Success
> > + * Non-zero - Failure
> > + */
> > +static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
> > +{
> > + return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > w1, 0); +}
> > +
> > +/**
> > + *
> > * ibmvtpm_send_crq - Send a CRQ request
> > *
> > * @vdev: vio device struct
> > - * @w1: first word
> > - * @w2: second word
> > + * @valid: Valid field
> > + * @msg: Type field
> > + * @len: Length field
> > + * @data: Data field
> > + *
> > + * The ibmvtpm crq is defined as follows:
> > + *
> > + * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
> > 7
> > + *
> > -----------------------------------------------------------------------
> > + * Word0 | Valid | Type | Length | Data
> > + *
> > -----------------------------------------------------------------------
> > + * Word1 | Reserved
> > + *
> > -----------------------------------------------------------------------
> > + *
> > + * Which matches the following structure (on bigendian host):
> > + *
> > + * struct ibmvtpm_crq {
> > + * u8 valid;
> > + * u8 msg;
> > + * __be16 len;
> > + * __be32 data;
> > + * __be64 reserved;
> > + * } __attribute__((packed, aligned(8)));
> > + *
> > + * However, the value is passed in a register so just compute the
> > numeric value
> > + * to load into the register avoiding byteswap altogether. Endian
> > only affects
> > + * memory loads and stores - registers are internally represented
> > the same. *
> > * Return:
> > - * 0 -Sucess
> > + * 0 (H_SUCCESS) - Success
> > * Non-zero - Failure
> > */
> > -static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2)
> > +static int ibmvtpm_send_crq(struct vio_dev *vdev,
> > + u8 valid, u8 msg, u16 len, u32 data)
> > {
> > - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > w1, w2);
> > + u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len
> > << 32) |
> > + (u64)data;
> > + return ibmvtpm_send_crq_word(vdev, w1);
> > }
> >
> > /**
> > @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip
> > *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(struct
> > tpm_chip *chip, u8 *buf, size_t count) {
> > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > - struct ibmvtpm_crq crq;
> > - __be64 *word = (__be64 *)&crq;
> > int rc, sig;
> >
> > if (!ibmvtpm->rtce_buf) {
> > @@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip
> > *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock);
> > ibmvtpm->res_len = 0;
> > memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_TPM_COMMAND;
> > - crq.len = cpu_to_be16(count);
> > - crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
> >
> > /*
> > * set the processing flag before the Hcall, since we may
> > get the @@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct
> > tpm_chip *chip, u8 *buf, size_t count) */
> > ibmvtpm->tpm_processing_cmd = true;
> >
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> > - be64_to_cpu(word[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
> > + count, ibmvtpm->rtce_dma_handle);
> > if (rc != H_SUCCESS) {
> > dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed
> > rc=%d\n", rc); rc = 0;
> > @@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip
> > *chip) */
> > static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
> > {
> > - struct ibmvtpm_crq crq;
> > - u64 *buf = (u64 *) &crq;
> > int rc;
> >
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE;
> > -
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > - cpu_to_be64(buf[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD,
> > VTPM_GET_RTCE_BUFFER_SIZE, 0, 0); if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_get_rtce_size failed rc=%d\n",
> > rc); @@ -210,15 +244,10 @@ static int
> > ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) */
> > static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
> > {
> > - struct ibmvtpm_crq crq;
> > - u64 *buf = (u64 *) &crq;
> > int rc;
> >
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_GET_VERSION;
> > -
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > - cpu_to_be64(buf[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0);
> > if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_get_version failed rc=%d\n",
> > rc); @@ -238,7 +267,7 @@ static int
> > ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) {
> > int rc;
> >
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
> > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD);
> > if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_send_init_complete failed
> > rc=%d\n", rc); @@ -258,7 +287,7 @@ static int
> > ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) {
> > int rc;
> >
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
> > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
> > if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_send_init failed rc=%d\n", rc);
> > @@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device
> > *dev) {
> > struct tpm_chip *chip = dev_get_drvdata(dev);
> > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > - struct ibmvtpm_crq crq;
> > - u64 *buf = (u64 *) &crq;
> > int rc = 0;
> >
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND;
> > -
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > - cpu_to_be64(buf[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND,
> > 0, 0); if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format
@ 2017-08-19 17:18 ` Jarkko Sakkinen
0 siblings, 0 replies; 26+ messages in thread
From: Jarkko Sakkinen @ 2017-08-19 17:18 UTC (permalink / raw)
To: msuchanek
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ashley Lai, Peter Huewe, Marcel Selhorst, Jason Gunthorpe,
linuxppc-dev, tpmdd-devel, linux-kernel
Ugh. I'll apply this. My apologies.
/Jarkko
On Fri, Aug 18, 2017 at 12:21:45AM +0200, msuchanek wrote:
> ping?
>
> On Fri, 24 Feb 2017 20:35:16 +0100
> Michal Suchanek <msuchanek@suse.de> wrote:
>
> > The crq is passed in registers and is the same on BE and LE hosts.
> > However, current implementation allocates a structure on-stack to
> > represent the crq, initializes the members swapping them to BE, and
> > loads the structure swapping it from BE. This is pointless and causes
> > GCC warnings about ununitialized members. Get rid of the structure and
> > the warnings.
> >
> > Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> > v2
> >
> > fix typos and spelling in comments
> > ---
> > drivers/char/tpm/tpm_ibmvtpm.c | 96
> > ++++++++++++++++++++++++++---------------- 1 file changed, 60
> > insertions(+), 36 deletions(-)
> >
> > diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> > b/drivers/char/tpm/tpm_ibmvtpm.c index 1b9d61ffe991..89027339d55f
> > 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c
> > +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> > @@ -39,19 +39,63 @@ static struct vio_device_id
> > tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio,
> > tpm_ibmvtpm_device_table);
> > /**
> > + *
> > + * ibmvtpm_send_crq_word - Send a CRQ request
> > + * @vdev: vio device struct
> > + * @w1: pre-constructed first word of tpm crq (second
> > word is reserved)
> > + *
> > + * Return:
> > + * 0 - Success
> > + * Non-zero - Failure
> > + */
> > +static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
> > +{
> > + return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > w1, 0); +}
> > +
> > +/**
> > + *
> > * ibmvtpm_send_crq - Send a CRQ request
> > *
> > * @vdev: vio device struct
> > - * @w1: first word
> > - * @w2: second word
> > + * @valid: Valid field
> > + * @msg: Type field
> > + * @len: Length field
> > + * @data: Data field
> > + *
> > + * The ibmvtpm crq is defined as follows:
> > + *
> > + * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
> > 7
> > + *
> > -----------------------------------------------------------------------
> > + * Word0 | Valid | Type | Length | Data
> > + *
> > -----------------------------------------------------------------------
> > + * Word1 | Reserved
> > + *
> > -----------------------------------------------------------------------
> > + *
> > + * Which matches the following structure (on bigendian host):
> > + *
> > + * struct ibmvtpm_crq {
> > + * u8 valid;
> > + * u8 msg;
> > + * __be16 len;
> > + * __be32 data;
> > + * __be64 reserved;
> > + * } __attribute__((packed, aligned(8)));
> > + *
> > + * However, the value is passed in a register so just compute the
> > numeric value
> > + * to load into the register avoiding byteswap altogether. Endian
> > only affects
> > + * memory loads and stores - registers are internally represented
> > the same. *
> > * Return:
> > - * 0 -Sucess
> > + * 0 (H_SUCCESS) - Success
> > * Non-zero - Failure
> > */
> > -static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2)
> > +static int ibmvtpm_send_crq(struct vio_dev *vdev,
> > + u8 valid, u8 msg, u16 len, u32 data)
> > {
> > - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > w1, w2);
> > + u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len
> > << 32) |
> > + (u64)data;
> > + return ibmvtpm_send_crq_word(vdev, w1);
> > }
> >
> > /**
> > @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip
> > *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(struct
> > tpm_chip *chip, u8 *buf, size_t count) {
> > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > - struct ibmvtpm_crq crq;
> > - __be64 *word = (__be64 *)&crq;
> > int rc, sig;
> >
> > if (!ibmvtpm->rtce_buf) {
> > @@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip
> > *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock);
> > ibmvtpm->res_len = 0;
> > memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_TPM_COMMAND;
> > - crq.len = cpu_to_be16(count);
> > - crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
> >
> > /*
> > * set the processing flag before the Hcall, since we may
> > get the @@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct
> > tpm_chip *chip, u8 *buf, size_t count) */
> > ibmvtpm->tpm_processing_cmd = true;
> >
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> > - be64_to_cpu(word[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
> > + count, ibmvtpm->rtce_dma_handle);
> > if (rc != H_SUCCESS) {
> > dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed
> > rc=%d\n", rc); rc = 0;
> > @@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip
> > *chip) */
> > static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
> > {
> > - struct ibmvtpm_crq crq;
> > - u64 *buf = (u64 *) &crq;
> > int rc;
> >
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE;
> > -
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > - cpu_to_be64(buf[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD,
> > VTPM_GET_RTCE_BUFFER_SIZE, 0, 0); if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_get_rtce_size failed rc=%d\n",
> > rc); @@ -210,15 +244,10 @@ static int
> > ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) */
> > static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
> > {
> > - struct ibmvtpm_crq crq;
> > - u64 *buf = (u64 *) &crq;
> > int rc;
> >
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_GET_VERSION;
> > -
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > - cpu_to_be64(buf[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0);
> > if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_get_version failed rc=%d\n",
> > rc); @@ -238,7 +267,7 @@ static int
> > ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) {
> > int rc;
> >
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
> > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD);
> > if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_send_init_complete failed
> > rc=%d\n", rc); @@ -258,7 +287,7 @@ static int
> > ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) {
> > int rc;
> >
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
> > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
> > if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "ibmvtpm_crq_send_init failed rc=%d\n", rc);
> > @@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device
> > *dev) {
> > struct tpm_chip *chip = dev_get_drvdata(dev);
> > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > - struct ibmvtpm_crq crq;
> > - u64 *buf = (u64 *) &crq;
> > int rc = 0;
> >
> > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > - crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND;
> > -
> > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > - cpu_to_be64(buf[1]));
> > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > + IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND,
> > 0, 0); if (rc != H_SUCCESS)
> > dev_err(ibmvtpm->dev,
> > "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format
2017-08-19 17:18 ` Jarkko Sakkinen
@ 2017-08-19 17:24 ` Jarkko Sakkinen
-1 siblings, 0 replies; 26+ messages in thread
From: Jarkko Sakkinen @ 2017-08-19 17:24 UTC (permalink / raw)
To: msuchanek
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ashley Lai, Peter Huewe, Marcel Selhorst, Jason Gunthorpe,
linuxppc-dev, tpmdd-devel, linux-kernel, tpmdd
Applied. I'll put this to 4.14 PR.
/Jarkko
On Sat, Aug 19, 2017 at 08:18:59PM +0300, Jarkko Sakkinen wrote:
> Ugh. I'll apply this. My apologies.
>
> /Jarkko
>
> On Fri, Aug 18, 2017 at 12:21:45AM +0200, msuchanek wrote:
> > ping?
> >
> > On Fri, 24 Feb 2017 20:35:16 +0100
> > Michal Suchanek <msuchanek@suse.de> wrote:
> >
> > > The crq is passed in registers and is the same on BE and LE hosts.
> > > However, current implementation allocates a structure on-stack to
> > > represent the crq, initializes the members swapping them to BE, and
> > > loads the structure swapping it from BE. This is pointless and causes
> > > GCC warnings about ununitialized members. Get rid of the structure and
> > > the warnings.
> > >
> > > Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > ---
> > > v2
> > >
> > > fix typos and spelling in comments
> > > ---
> > > drivers/char/tpm/tpm_ibmvtpm.c | 96
> > > ++++++++++++++++++++++++++---------------- 1 file changed, 60
> > > insertions(+), 36 deletions(-)
> > >
> > > diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> > > b/drivers/char/tpm/tpm_ibmvtpm.c index 1b9d61ffe991..89027339d55f
> > > 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c
> > > +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> > > @@ -39,19 +39,63 @@ static struct vio_device_id
> > > tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio,
> > > tpm_ibmvtpm_device_table);
> > > /**
> > > + *
> > > + * ibmvtpm_send_crq_word - Send a CRQ request
> > > + * @vdev: vio device struct
> > > + * @w1: pre-constructed first word of tpm crq (second
> > > word is reserved)
> > > + *
> > > + * Return:
> > > + * 0 - Success
> > > + * Non-zero - Failure
> > > + */
> > > +static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
> > > +{
> > > + return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > > w1, 0); +}
> > > +
> > > +/**
> > > + *
> > > * ibmvtpm_send_crq - Send a CRQ request
> > > *
> > > * @vdev: vio device struct
> > > - * @w1: first word
> > > - * @w2: second word
> > > + * @valid: Valid field
> > > + * @msg: Type field
> > > + * @len: Length field
> > > + * @data: Data field
> > > + *
> > > + * The ibmvtpm crq is defined as follows:
> > > + *
> > > + * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
> > > 7
> > > + *
> > > -----------------------------------------------------------------------
> > > + * Word0 | Valid | Type | Length | Data
> > > + *
> > > -----------------------------------------------------------------------
> > > + * Word1 | Reserved
> > > + *
> > > -----------------------------------------------------------------------
> > > + *
> > > + * Which matches the following structure (on bigendian host):
> > > + *
> > > + * struct ibmvtpm_crq {
> > > + * u8 valid;
> > > + * u8 msg;
> > > + * __be16 len;
> > > + * __be32 data;
> > > + * __be64 reserved;
> > > + * } __attribute__((packed, aligned(8)));
> > > + *
> > > + * However, the value is passed in a register so just compute the
> > > numeric value
> > > + * to load into the register avoiding byteswap altogether. Endian
> > > only affects
> > > + * memory loads and stores - registers are internally represented
> > > the same. *
> > > * Return:
> > > - * 0 -Sucess
> > > + * 0 (H_SUCCESS) - Success
> > > * Non-zero - Failure
> > > */
> > > -static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2)
> > > +static int ibmvtpm_send_crq(struct vio_dev *vdev,
> > > + u8 valid, u8 msg, u16 len, u32 data)
> > > {
> > > - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > > w1, w2);
> > > + u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len
> > > << 32) |
> > > + (u64)data;
> > > + return ibmvtpm_send_crq_word(vdev, w1);
> > > }
> > >
> > > /**
> > > @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip
> > > *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(struct
> > > tpm_chip *chip, u8 *buf, size_t count) {
> > > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > > - struct ibmvtpm_crq crq;
> > > - __be64 *word = (__be64 *)&crq;
> > > int rc, sig;
> > >
> > > if (!ibmvtpm->rtce_buf) {
> > > @@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip
> > > *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock);
> > > ibmvtpm->res_len = 0;
> > > memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_TPM_COMMAND;
> > > - crq.len = cpu_to_be16(count);
> > > - crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
> > >
> > > /*
> > > * set the processing flag before the Hcall, since we may
> > > get the @@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct
> > > tpm_chip *chip, u8 *buf, size_t count) */
> > > ibmvtpm->tpm_processing_cmd = true;
> > >
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> > > - be64_to_cpu(word[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
> > > + count, ibmvtpm->rtce_dma_handle);
> > > if (rc != H_SUCCESS) {
> > > dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed
> > > rc=%d\n", rc); rc = 0;
> > > @@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip
> > > *chip) */
> > > static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
> > > {
> > > - struct ibmvtpm_crq crq;
> > > - u64 *buf = (u64 *) &crq;
> > > int rc;
> > >
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE;
> > > -
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > > - cpu_to_be64(buf[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD,
> > > VTPM_GET_RTCE_BUFFER_SIZE, 0, 0); if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_get_rtce_size failed rc=%d\n",
> > > rc); @@ -210,15 +244,10 @@ static int
> > > ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) */
> > > static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
> > > {
> > > - struct ibmvtpm_crq crq;
> > > - u64 *buf = (u64 *) &crq;
> > > int rc;
> > >
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_GET_VERSION;
> > > -
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > > - cpu_to_be64(buf[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0);
> > > if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_get_version failed rc=%d\n",
> > > rc); @@ -238,7 +267,7 @@ static int
> > > ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) {
> > > int rc;
> > >
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
> > > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD);
> > > if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_send_init_complete failed
> > > rc=%d\n", rc); @@ -258,7 +287,7 @@ static int
> > > ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) {
> > > int rc;
> > >
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
> > > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
> > > if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_send_init failed rc=%d\n", rc);
> > > @@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device
> > > *dev) {
> > > struct tpm_chip *chip = dev_get_drvdata(dev);
> > > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > > - struct ibmvtpm_crq crq;
> > > - u64 *buf = (u64 *) &crq;
> > > int rc = 0;
> > >
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND;
> > > -
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > > - cpu_to_be64(buf[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND,
> > > 0, 0); if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
> >
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format
@ 2017-08-19 17:24 ` Jarkko Sakkinen
0 siblings, 0 replies; 26+ messages in thread
From: Jarkko Sakkinen @ 2017-08-19 17:24 UTC (permalink / raw)
To: msuchanek
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ashley Lai, Peter Huewe, Marcel Selhorst, Jason Gunthorpe,
linuxppc-dev, tpmdd-devel, linux-kernel
Applied. I'll put this to 4.14 PR.
/Jarkko
On Sat, Aug 19, 2017 at 08:18:59PM +0300, Jarkko Sakkinen wrote:
> Ugh. I'll apply this. My apologies.
>
> /Jarkko
>
> On Fri, Aug 18, 2017 at 12:21:45AM +0200, msuchanek wrote:
> > ping?
> >
> > On Fri, 24 Feb 2017 20:35:16 +0100
> > Michal Suchanek <msuchanek@suse.de> wrote:
> >
> > > The crq is passed in registers and is the same on BE and LE hosts.
> > > However, current implementation allocates a structure on-stack to
> > > represent the crq, initializes the members swapping them to BE, and
> > > loads the structure swapping it from BE. This is pointless and causes
> > > GCC warnings about ununitialized members. Get rid of the structure and
> > > the warnings.
> > >
> > > Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > ---
> > > v2
> > >
> > > fix typos and spelling in comments
> > > ---
> > > drivers/char/tpm/tpm_ibmvtpm.c | 96
> > > ++++++++++++++++++++++++++---------------- 1 file changed, 60
> > > insertions(+), 36 deletions(-)
> > >
> > > diff --git a/drivers/char/tpm/tpm_ibmvtpm.c
> > > b/drivers/char/tpm/tpm_ibmvtpm.c index 1b9d61ffe991..89027339d55f
> > > 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c
> > > +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> > > @@ -39,19 +39,63 @@ static struct vio_device_id
> > > tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio,
> > > tpm_ibmvtpm_device_table);
> > > /**
> > > + *
> > > + * ibmvtpm_send_crq_word - Send a CRQ request
> > > + * @vdev: vio device struct
> > > + * @w1: pre-constructed first word of tpm crq (second
> > > word is reserved)
> > > + *
> > > + * Return:
> > > + * 0 - Success
> > > + * Non-zero - Failure
> > > + */
> > > +static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
> > > +{
> > > + return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > > w1, 0); +}
> > > +
> > > +/**
> > > + *
> > > * ibmvtpm_send_crq - Send a CRQ request
> > > *
> > > * @vdev: vio device struct
> > > - * @w1: first word
> > > - * @w2: second word
> > > + * @valid: Valid field
> > > + * @msg: Type field
> > > + * @len: Length field
> > > + * @data: Data field
> > > + *
> > > + * The ibmvtpm crq is defined as follows:
> > > + *
> > > + * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
> > > 7
> > > + *
> > > -----------------------------------------------------------------------
> > > + * Word0 | Valid | Type | Length | Data
> > > + *
> > > -----------------------------------------------------------------------
> > > + * Word1 | Reserved
> > > + *
> > > -----------------------------------------------------------------------
> > > + *
> > > + * Which matches the following structure (on bigendian host):
> > > + *
> > > + * struct ibmvtpm_crq {
> > > + * u8 valid;
> > > + * u8 msg;
> > > + * __be16 len;
> > > + * __be32 data;
> > > + * __be64 reserved;
> > > + * } __attribute__((packed, aligned(8)));
> > > + *
> > > + * However, the value is passed in a register so just compute the
> > > numeric value
> > > + * to load into the register avoiding byteswap altogether. Endian
> > > only affects
> > > + * memory loads and stores - registers are internally represented
> > > the same. *
> > > * Return:
> > > - * 0 -Sucess
> > > + * 0 (H_SUCCESS) - Success
> > > * Non-zero - Failure
> > > */
> > > -static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2)
> > > +static int ibmvtpm_send_crq(struct vio_dev *vdev,
> > > + u8 valid, u8 msg, u16 len, u32 data)
> > > {
> > > - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,
> > > w1, w2);
> > > + u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len
> > > << 32) |
> > > + (u64)data;
> > > + return ibmvtpm_send_crq_word(vdev, w1);
> > > }
> > >
> > > /**
> > > @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip
> > > *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(struct
> > > tpm_chip *chip, u8 *buf, size_t count) {
> > > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > > - struct ibmvtpm_crq crq;
> > > - __be64 *word = (__be64 *)&crq;
> > > int rc, sig;
> > >
> > > if (!ibmvtpm->rtce_buf) {
> > > @@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip
> > > *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock);
> > > ibmvtpm->res_len = 0;
> > > memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_TPM_COMMAND;
> > > - crq.len = cpu_to_be16(count);
> > > - crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
> > >
> > > /*
> > > * set the processing flag before the Hcall, since we may
> > > get the @@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct
> > > tpm_chip *chip, u8 *buf, size_t count) */
> > > ibmvtpm->tpm_processing_cmd = true;
> > >
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
> > > - be64_to_cpu(word[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
> > > + count, ibmvtpm->rtce_dma_handle);
> > > if (rc != H_SUCCESS) {
> > > dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed
> > > rc=%d\n", rc); rc = 0;
> > > @@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip
> > > *chip) */
> > > static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
> > > {
> > > - struct ibmvtpm_crq crq;
> > > - u64 *buf = (u64 *) &crq;
> > > int rc;
> > >
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE;
> > > -
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > > - cpu_to_be64(buf[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD,
> > > VTPM_GET_RTCE_BUFFER_SIZE, 0, 0); if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_get_rtce_size failed rc=%d\n",
> > > rc); @@ -210,15 +244,10 @@ static int
> > > ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) */
> > > static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm)
> > > {
> > > - struct ibmvtpm_crq crq;
> > > - u64 *buf = (u64 *) &crq;
> > > int rc;
> > >
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_GET_VERSION;
> > > -
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > > - cpu_to_be64(buf[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0);
> > > if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_get_version failed rc=%d\n",
> > > rc); @@ -238,7 +267,7 @@ static int
> > > ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) {
> > > int rc;
> > >
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0);
> > > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD);
> > > if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_send_init_complete failed
> > > rc=%d\n", rc); @@ -258,7 +287,7 @@ static int
> > > ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) {
> > > int rc;
> > >
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0);
> > > + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
> > > if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "ibmvtpm_crq_send_init failed rc=%d\n", rc);
> > > @@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device
> > > *dev) {
> > > struct tpm_chip *chip = dev_get_drvdata(dev);
> > > struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
> > > - struct ibmvtpm_crq crq;
> > > - u64 *buf = (u64 *) &crq;
> > > int rc = 0;
> > >
> > > - crq.valid = (u8)IBMVTPM_VALID_CMD;
> > > - crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND;
> > > -
> > > - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]),
> > > - cpu_to_be64(buf[1]));
> > > + rc = ibmvtpm_send_crq(ibmvtpm->vdev,
> > > + IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND,
> > > 0, 0); if (rc != H_SUCCESS)
> > > dev_err(ibmvtpm->dev,
> > > "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
> >
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2017-08-19 17:24 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-29 7:24 [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix SZ Lin
2017-02-24 19:35 ` [RFT PATCH] tpm: ibmvtpm: simplify crq initialization and document crq format Michal Suchanek
2017-02-24 19:35 ` Michal Suchanek
2017-08-17 22:21 ` msuchanek
2017-08-19 17:18 ` Jarkko Sakkinen
2017-08-19 17:18 ` Jarkko Sakkinen
2017-08-19 17:24 ` Jarkko Sakkinen
2017-08-19 17:24 ` Jarkko Sakkinen
2017-07-29 7:24 ` [PATCH 1/5] Fix packed and aligned attribute warnings SZ Lin
2017-07-31 13:27 ` David Laight
2017-07-31 13:27 ` David Laight
2017-07-31 13:27 ` David Laight
2017-07-29 7:24 ` [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible" SZ Lin
2017-07-31 10:25 ` Michael Ellerman
2017-07-31 10:25 ` Michael Ellerman
2017-07-29 7:24 ` [PATCH 3/5] Fix 'void function return statements are not generally useful' warning SZ Lin
2017-07-29 7:24 ` [PATCH 4/5] Remove unneccessary 'out of memory' message SZ Lin
2017-07-29 7:24 ` [PATCH 5/5] Use __func__ instead of function name SZ Lin
2017-08-18 8:03 ` Michal Suchánek
2017-08-18 8:03 ` Michal Suchánek
2017-08-18 8:03 ` Michal Suchánek
2017-08-18 11:25 ` Michael Ellerman
2017-08-18 11:25 ` Michael Ellerman
2017-08-18 11:25 ` Michael Ellerman
2017-08-19 7:58 ` 김동현
2017-08-02 12:36 ` [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix Jarkko Sakkinen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.