Lines Matching refs:chip

308 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,  in tpm_calc_ordinal_duration()  argument
320 duration = chip->vendor.duration[duration_idx]; in tpm_calc_ordinal_duration()
331 ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, in tpm_transmit() argument
346 dev_err(chip->pdev, in tpm_transmit()
351 mutex_lock(&chip->tpm_mutex); in tpm_transmit()
353 rc = chip->ops->send(chip, (u8 *) buf, count); in tpm_transmit()
355 dev_err(chip->pdev, in tpm_transmit()
360 if (chip->vendor.irq) in tpm_transmit()
363 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_transmit()
364 stop = jiffies + tpm2_calc_ordinal_duration(chip, ordinal); in tpm_transmit()
366 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); in tpm_transmit()
368 u8 status = chip->ops->status(chip); in tpm_transmit()
369 if ((status & chip->ops->req_complete_mask) == in tpm_transmit()
370 chip->ops->req_complete_val) in tpm_transmit()
373 if (chip->ops->req_canceled(chip, status)) { in tpm_transmit()
374 dev_err(chip->pdev, "Operation Canceled\n"); in tpm_transmit()
383 chip->ops->cancel(chip); in tpm_transmit()
384 dev_err(chip->pdev, "Operation Timed out\n"); in tpm_transmit()
389 rc = chip->ops->recv(chip, (u8 *) buf, bufsiz); in tpm_transmit()
391 dev_err(chip->pdev, in tpm_transmit()
394 mutex_unlock(&chip->tpm_mutex); in tpm_transmit()
401 ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd, in tpm_transmit_cmd() argument
407 len = tpm_transmit(chip, (u8 *) cmd, len); in tpm_transmit_cmd()
417 dev_err(chip->pdev, "A TPM error (%d) occurred %s\n", err, in tpm_transmit_cmd()
438 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_getcap() local
455 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, desc); in tpm_getcap()
461 void tpm_gen_interrupt(struct tpm_chip *chip) in tpm_gen_interrupt() argument
471 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, in tpm_gen_interrupt()
486 static int tpm_startup(struct tpm_chip *chip, __be16 startup_type) in tpm_startup() argument
492 return tpm_transmit_cmd(chip, &start_cmd, TPM_INTERNAL_RESULT_SIZE, in tpm_startup()
496 int tpm_get_timeouts(struct tpm_chip *chip) in tpm_get_timeouts() argument
508 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, NULL); in tpm_get_timeouts()
513 dev_info(chip->pdev, "Issuing TPM_STARTUP"); in tpm_get_timeouts()
514 if (tpm_startup(chip, TPM_ST_CLEAR)) in tpm_get_timeouts()
521 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, in tpm_get_timeouts()
525 dev_err(chip->pdev, in tpm_get_timeouts()
546 if (chip->ops->update_timeouts != NULL) in tpm_get_timeouts()
547 chip->vendor.timeout_adjusted = in tpm_get_timeouts()
548 chip->ops->update_timeouts(chip, new_timeout); in tpm_get_timeouts()
550 if (!chip->vendor.timeout_adjusted) { in tpm_get_timeouts()
558 chip->vendor.timeout_adjusted = true; in tpm_get_timeouts()
563 if (chip->vendor.timeout_adjusted) { in tpm_get_timeouts()
564 dev_info(chip->pdev, in tpm_get_timeouts()
572 chip->vendor.timeout_a = usecs_to_jiffies(new_timeout[0]); in tpm_get_timeouts()
573 chip->vendor.timeout_b = usecs_to_jiffies(new_timeout[1]); in tpm_get_timeouts()
574 chip->vendor.timeout_c = usecs_to_jiffies(new_timeout[2]); in tpm_get_timeouts()
575 chip->vendor.timeout_d = usecs_to_jiffies(new_timeout[3]); in tpm_get_timeouts()
583 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, in tpm_get_timeouts()
594 chip->vendor.duration[TPM_SHORT] = in tpm_get_timeouts()
596 chip->vendor.duration[TPM_MEDIUM] = in tpm_get_timeouts()
598 chip->vendor.duration[TPM_LONG] = in tpm_get_timeouts()
606 if (chip->vendor.duration[TPM_SHORT] < (HZ / 100)) { in tpm_get_timeouts()
607 chip->vendor.duration[TPM_SHORT] = HZ; in tpm_get_timeouts()
608 chip->vendor.duration[TPM_MEDIUM] *= 1000; in tpm_get_timeouts()
609 chip->vendor.duration[TPM_LONG] *= 1000; in tpm_get_timeouts()
610 chip->vendor.duration_adjusted = true; in tpm_get_timeouts()
611 dev_info(chip->pdev, "Adjusting TPM timeout parameters."); in tpm_get_timeouts()
633 static int tpm_continue_selftest(struct tpm_chip *chip) in tpm_continue_selftest() argument
639 rc = tpm_transmit_cmd(chip, &cmd, CONTINUE_SELFTEST_RESULT_SIZE, in tpm_continue_selftest()
652 int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) in tpm_pcr_read_dev() argument
659 rc = tpm_transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE, in tpm_pcr_read_dev()
681 struct tpm_chip *chip; in tpm_pcr_read() local
684 chip = tpm_chip_find_get(chip_num); in tpm_pcr_read()
685 if (chip == NULL) in tpm_pcr_read()
687 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_pcr_read()
688 rc = tpm2_pcr_read(chip, pcr_idx, res_buf); in tpm_pcr_read()
690 rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf); in tpm_pcr_read()
691 tpm_chip_put(chip); in tpm_pcr_read()
718 struct tpm_chip *chip; in tpm_pcr_extend() local
720 chip = tpm_chip_find_get(chip_num); in tpm_pcr_extend()
721 if (chip == NULL) in tpm_pcr_extend()
724 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pcr_extend()
725 rc = tpm2_pcr_extend(chip, pcr_idx, hash); in tpm_pcr_extend()
726 tpm_chip_put(chip); in tpm_pcr_extend()
733 rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE, in tpm_pcr_extend()
736 tpm_chip_put(chip); in tpm_pcr_extend()
749 int tpm_do_selftest(struct tpm_chip *chip) in tpm_do_selftest() argument
757 duration = tpm_calc_ordinal_duration(chip, TPM_ORD_CONTINUE_SELFTEST); in tpm_do_selftest()
761 rc = tpm_continue_selftest(chip); in tpm_do_selftest()
772 rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE); in tpm_do_selftest()
777 dev_info(chip->pdev, HW_ERR "TPM command timed out during continue self test"); in tpm_do_selftest()
787 dev_info(chip->pdev, in tpm_do_selftest()
806 struct tpm_chip *chip; in tpm_send() local
809 chip = tpm_chip_find_get(chip_num); in tpm_send()
810 if (chip == NULL) in tpm_send()
813 rc = tpm_transmit_cmd(chip, cmd, buflen, "attempting tpm_cmd"); in tpm_send()
815 tpm_chip_put(chip); in tpm_send()
820 static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, in wait_for_tpm_stat_cond() argument
823 u8 status = chip->ops->status(chip); in wait_for_tpm_stat_cond()
828 if (check_cancel && chip->ops->req_canceled(chip, status)) { in wait_for_tpm_stat_cond()
835 int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, in wait_for_tpm_stat() argument
844 status = chip->ops->status(chip); in wait_for_tpm_stat()
850 if (chip->vendor.irq) { in wait_for_tpm_stat()
856 wait_for_tpm_stat_cond(chip, mask, check_cancel, in wait_for_tpm_stat()
871 status = chip->ops->status(chip); in wait_for_tpm_stat()
895 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_suspend() local
901 if (chip == NULL) in tpm_pm_suspend()
904 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pm_suspend()
905 tpm2_shutdown(chip, TPM2_SU_STATE); in tpm_pm_suspend()
915 rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE, in tpm_pm_suspend()
922 rc = tpm_transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE, NULL); in tpm_pm_suspend()
940 dev_err(chip->pdev, in tpm_pm_suspend()
943 dev_warn(chip->pdev, "TPM savestate took %dms\n", in tpm_pm_suspend()
956 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_resume() local
958 if (chip == NULL) in tpm_pm_resume()
982 struct tpm_chip *chip; in tpm_get_random() local
991 chip = tpm_chip_find_get(chip_num); in tpm_get_random()
992 if (chip == NULL) in tpm_get_random()
995 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_get_random()
996 err = tpm2_get_random(chip, out, max); in tpm_get_random()
997 tpm_chip_put(chip); in tpm_get_random()
1005 err = tpm_transmit_cmd(chip, &tpm_cmd, in tpm_get_random()
1019 tpm_chip_put(chip); in tpm_get_random()