Lines Matching +full:poll +full:- +full:retry +full:- +full:count

1 // SPDX-License-Identifier: GPL-2.0-only
12 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
22 #include <linux/poll.h>
33 * Bug workaround - some TPM's don't flush the most
35 * with an extend to the selected _unused_ non-volatile pcr.
43 * tpm_calc_ordinal_duration() - calculate the maximum command duration
54 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_calc_ordinal_duration()
66 u32 count, ordinal; in tpm_try_transmit() local
70 return -EINVAL; in tpm_try_transmit()
75 count = be32_to_cpu(header->length); in tpm_try_transmit()
76 ordinal = be32_to_cpu(header->ordinal); in tpm_try_transmit()
77 if (count == 0) in tpm_try_transmit()
78 return -ENODATA; in tpm_try_transmit()
79 if (count > bufsiz) { in tpm_try_transmit()
80 dev_err(&chip->dev, in tpm_try_transmit()
81 "invalid count value %x %zx\n", count, bufsiz); in tpm_try_transmit()
82 return -E2BIG; in tpm_try_transmit()
85 rc = chip->ops->send(chip, buf, count); in tpm_try_transmit()
87 if (rc != -EPIPE) in tpm_try_transmit()
88 dev_err(&chip->dev, in tpm_try_transmit()
97 dev_warn(&chip->dev, in tpm_try_transmit()
102 if (chip->flags & TPM_CHIP_FLAG_IRQ) in tpm_try_transmit()
107 u8 status = chip->ops->status(chip); in tpm_try_transmit()
108 if ((status & chip->ops->req_complete_mask) == in tpm_try_transmit()
109 chip->ops->req_complete_val) in tpm_try_transmit()
112 if (chip->ops->req_canceled(chip, status)) { in tpm_try_transmit()
113 dev_err(&chip->dev, "Operation Canceled\n"); in tpm_try_transmit()
114 return -ECANCELED; in tpm_try_transmit()
121 chip->ops->cancel(chip); in tpm_try_transmit()
122 dev_err(&chip->dev, "Operation Timed out\n"); in tpm_try_transmit()
123 return -ETIME; in tpm_try_transmit()
126 len = chip->ops->recv(chip, buf, bufsiz); in tpm_try_transmit()
129 dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); in tpm_try_transmit()
130 } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) in tpm_try_transmit()
131 rc = -EFAULT; in tpm_try_transmit()
137 * tpm_transmit - Internal kernel interface to transmit TPM commands.
146 * Note that TPM 1.x never returns TPM2_RC_RETRY so the retry logic is TPM 2.0
150 * * The response length - OK
151 * * -errno - A system error
163 u32 cc = be32_to_cpu(header->return_code); in tpm_transmit()
176 rc = be32_to_cpu(header->return_code); in tpm_transmit()
188 dev_err(&chip->dev, "in retry loop\n"); in tpm_transmit()
190 dev_err(&chip->dev, in tpm_transmit()
202 * tpm_transmit_cmd - send a tpm command to the device
209 * * 0 - OK
210 * * -errno - A system error
211 * * TPM_RC - A TPM error
216 const struct tpm_header *header = (struct tpm_header *)buf->data; in tpm_transmit_cmd()
220 len = tpm_transmit(chip, buf->data, PAGE_SIZE); in tpm_transmit_cmd()
224 err = be32_to_cpu(header->return_code); in tpm_transmit_cmd()
227 dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err, in tpm_transmit_cmd()
233 return -EFAULT; in tpm_transmit_cmd()
235 buf->length = len; in tpm_transmit_cmd()
242 if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) in tpm_get_timeouts()
245 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_timeouts()
253 * tpm_is_tpm2 - do we a have a TPM2 chip?
267 return -ENODEV; in tpm_is_tpm2()
269 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; in tpm_is_tpm2()
278 * tpm_pcr_read - read a PCR value from SHA1 bank
292 return -ENODEV; in tpm_pcr_read()
294 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_pcr_read()
297 rc = tpm1_pcr_read(chip, pcr_idx, digest->digest); in tpm_pcr_read()
305 * tpm_pcr_extend - extend a PCR value in SHA1 bank.
311 * order of the banks in chip->allocated_banks.
323 return -ENODEV; in tpm_pcr_extend()
325 for (i = 0; i < chip->nr_allocated_banks; i++) { in tpm_pcr_extend()
326 if (digests[i].alg_id != chip->allocated_banks[i].alg_id) { in tpm_pcr_extend()
327 rc = -EINVAL; in tpm_pcr_extend()
332 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pcr_extend()
350 if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP)) in tpm_auto_startup()
353 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_auto_startup()
371 return -ENODEV; in tpm_pm_suspend()
376 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
380 if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED) in tpm_pm_suspend()
383 if ((chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED) && in tpm_pm_suspend()
387 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pm_suspend()
396 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
415 return -ENODEV; in tpm_pm_resume()
417 chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_resume()
430 * tpm_get_random() - get random bytes from the TPM's RNG
442 return -EINVAL; in tpm_get_random()
446 return -ENODEV; in tpm_get_random()
449 if (chip->flags & TPM_CHIP_FLAG_SUSPENDED) { in tpm_get_random()
454 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_random()