Commit d9e5b6bf authored by Kylene Hall's avatar Kylene Hall Committed by Linus Torvalds

[PATCH] tpm: add cancel function

This patch provides the logic to check if an operation has been canceled while
waiting for the response to arrive.
Signed-off-by: default avatarKylene Hall <kjhall@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6659ca2a
...@@ -141,7 +141,7 @@ EXPORT_SYMBOL_GPL(tpm_lpc_bus_init); ...@@ -141,7 +141,7 @@ EXPORT_SYMBOL_GPL(tpm_lpc_bus_init);
static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
size_t bufsiz) size_t bufsiz)
{ {
ssize_t len; ssize_t rc;
u32 count; u32 count;
unsigned long stop; unsigned long stop;
...@@ -157,10 +157,10 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, ...@@ -157,10 +157,10 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
down(&chip->tpm_mutex); down(&chip->tpm_mutex);
if ((len = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) {
dev_err(&chip->pci_dev->dev, dev_err(&chip->pci_dev->dev,
"tpm_transmit: tpm_send: error %zd\n", len); "tpm_transmit: tpm_send: error %zd\n", rc);
return len; goto out;
} }
stop = jiffies + 2 * 60 * HZ; stop = jiffies + 2 * 60 * HZ;
...@@ -170,23 +170,31 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, ...@@ -170,23 +170,31 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
chip->vendor->req_complete_val) { chip->vendor->req_complete_val) {
goto out_recv; goto out_recv;
} }
if ((status == chip->vendor->req_canceled)) {
dev_err(&chip->pci_dev->dev, "Operation Canceled\n");
rc = -ECANCELED;
goto out;
}
msleep(TPM_TIMEOUT); /* CHECK */ msleep(TPM_TIMEOUT); /* CHECK */
rmb(); rmb();
} while (time_before(jiffies, stop)); } while (time_before(jiffies, stop));
chip->vendor->cancel(chip); chip->vendor->cancel(chip);
dev_err(&chip->pci_dev->dev, "Time expired\n"); dev_err(&chip->pci_dev->dev, "Operation Timed out\n");
up(&chip->tpm_mutex); rc = -ETIME;
return -EIO; goto out;
out_recv: out_recv:
len = chip->vendor->recv(chip, (u8 *) buf, bufsiz); rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz);
if (len < 0) if (rc < 0)
dev_err(&chip->pci_dev->dev, dev_err(&chip->pci_dev->dev,
"tpm_transmit: tpm_recv: error %zd\n", len); "tpm_transmit: tpm_recv: error %zd\n", rc);
out:
up(&chip->tpm_mutex); up(&chip->tpm_mutex);
return len; return rc;
} }
#define TPM_DIGEST_SIZE 20 #define TPM_DIGEST_SIZE 20
......
...@@ -49,6 +49,7 @@ struct tpm_chip; ...@@ -49,6 +49,7 @@ struct tpm_chip;
struct tpm_vendor_specific { struct tpm_vendor_specific {
u8 req_complete_mask; u8 req_complete_mask;
u8 req_complete_val; u8 req_complete_val;
u8 req_canceled;
u16 base; /* TPM base address */ u16 base; /* TPM base address */
int (*recv) (struct tpm_chip *, u8 *, size_t); int (*recv) (struct tpm_chip *, u8 *, size_t);
......
...@@ -147,6 +147,7 @@ static struct tpm_vendor_specific tpm_atmel = { ...@@ -147,6 +147,7 @@ static struct tpm_vendor_specific tpm_atmel = {
.cancel = tpm_atml_cancel, .cancel = tpm_atml_cancel,
.req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL, .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
.req_complete_val = ATML_STATUS_DATA_AVAIL, .req_complete_val = ATML_STATUS_DATA_AVAIL,
.req_canceled = ATML_STATUS_READY,
.base = TPM_ATML_BASE, .base = TPM_ATML_BASE,
.attr_group = &atmel_attr_grp, .attr_group = &atmel_attr_grp,
.miscdev = { .fops = &atmel_ops, }, .miscdev = { .fops = &atmel_ops, },
......
...@@ -245,6 +245,7 @@ static struct tpm_vendor_specific tpm_nsc = { ...@@ -245,6 +245,7 @@ static struct tpm_vendor_specific tpm_nsc = {
.cancel = tpm_nsc_cancel, .cancel = tpm_nsc_cancel,
.req_complete_mask = NSC_STATUS_OBF, .req_complete_mask = NSC_STATUS_OBF,
.req_complete_val = NSC_STATUS_OBF, .req_complete_val = NSC_STATUS_OBF,
.req_canceled = NSC_STATUS_RDY,
.base = TPM_NSC_BASE, .base = TPM_NSC_BASE,
.attr_group = &nsc_attr_grp, .attr_group = &nsc_attr_grp,
.miscdev = { .fops = &nsc_ops, }, .miscdev = { .fops = &nsc_ops, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment