Lines Matching +full:three +full:- +full:state

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* n2-drv.c: Niagara-2 RNG driver.
37 /* The Niagara2 RNG provides a 64-bit read-only random number
46 * The oscillator in each of the three raw entropy sources run at
47 * different frequencies. Normally, all three generator outputs are
49 * which is the 64-bit read-only register.
52 * such that a full 64-bits of entropy are available in the register.
58 * operation, and to enable diagnostic modes. Each of the three raw
65 * all three entropy sources enabled, and the interlock time set
77 * one at a time, to the actual RNG_CTL register. The first three
85 * And then the fourth value sets the final chip state and enables
95 return -EAGAIN; in n2rng_hv_err_trans()
97 return -EPERM; in n2rng_hv_err_trans()
99 return -EIO; in n2rng_hv_err_trans()
101 return -EBUSY; in n2rng_hv_err_trans()
104 return -EFAULT; in n2rng_hv_err_trans()
106 return -EINVAL; in n2rng_hv_err_trans()
113 unsigned long hv_err, state, ticks, watchdog_delta, watchdog_status; in n2rng_generic_read_control_v2() local
117 hv_err = sun4v_rng_ctl_read_v2(ra, unit, &state, in n2rng_generic_read_control_v2()
141 /* In multi-socket situations, the hypervisor might need to
150 unsigned long ra = __pa(&np->scratch_control[0]); in n2rng_control_settle_v2()
156 unsigned long state, in n2rng_write_ctl_one() argument
163 if (np->hvapi_major == 1) { in n2rng_write_ctl_one()
164 hv_err = sun4v_rng_ctl_write_v1(control_ra, state, in n2rng_write_ctl_one()
167 hv_err = sun4v_rng_ctl_write_v2(control_ra, state, in n2rng_write_ctl_one()
189 return -EWOULDBLOCK; in n2rng_generic_read_data()
192 return -EPERM; in n2rng_generic_read_data()
195 return -EIO; in n2rng_generic_read_data()
198 return -ENODEV; in n2rng_generic_read_data()
210 if (np->hvapi_major == 1) { in n2rng_read_diag_data_one()
238 return -EWOULDBLOCK; in n2rng_generic_read_diag_data()
241 return -EPERM; in n2rng_generic_read_diag_data()
243 return -EIO; in n2rng_generic_read_diag_data()
245 return -ENODEV; in n2rng_generic_read_diag_data()
253 unsigned long state) in n2rng_generic_write_control() argument
259 hv_err = n2rng_write_ctl_one(np, unit, state, control_ra, in n2rng_generic_write_control()
260 np->wd_timeo, &ticks); in n2rng_generic_write_control()
266 return -EWOULDBLOCK; in n2rng_generic_write_control()
270 return -EBUSY; in n2rng_generic_write_control()
273 return -ENODEV; in n2rng_generic_write_control()
285 if (np->hvapi_major == 1) { in n2rng_try_read_ctl()
311 if (np->data->chip_version == 1) { in n2rng_control_default()
363 np->flags |= N2RNG_FLAG_CONTROL; in n2rng_control_swstate_init()
365 np->health_check_sec = N2RNG_HEALTH_CHECK_SEC_DEFAULT; in n2rng_control_swstate_init()
366 np->accum_cycles = N2RNG_ACCUM_CYCLES_DEFAULT; in n2rng_control_swstate_init()
367 np->wd_timeo = N2RNG_WD_TIMEO_DEFAULT; in n2rng_control_swstate_init()
369 for (i = 0; i < np->num_units; i++) { in n2rng_control_swstate_init()
370 struct n2rng_unit *up = &np->units[i]; in n2rng_control_swstate_init()
372 up->control[0] = n2rng_control_default(np, 0); in n2rng_control_swstate_init()
373 up->control[1] = n2rng_control_default(np, 1); in n2rng_control_swstate_init()
374 up->control[2] = n2rng_control_default(np, 2); in n2rng_control_swstate_init()
375 up->control[3] = n2rng_control_default(np, 3); in n2rng_control_swstate_init()
378 np->hv_state = HV_RNG_STATE_UNCONFIGURED; in n2rng_control_swstate_init()
383 int i, busy_count, err = -ENODEV; in n2rng_grab_diag_control()
388 if (err != -EAGAIN) in n2rng_grab_diag_control()
392 dev_err(&np->op->dev, in n2rng_grab_diag_control()
394 return -ENODEV; in n2rng_grab_diag_control()
410 if (err == -EPERM) in n2rng_init_control()
422 struct n2rng *np = (struct n2rng *) rng->priv; in n2rng_data_read()
423 unsigned long ra = __pa(&np->test_data); in n2rng_data_read()
426 if (!(np->flags & N2RNG_FLAG_READY)) { in n2rng_data_read()
428 } else if (np->flags & N2RNG_FLAG_BUFFER_VALID) { in n2rng_data_read()
429 np->flags &= ~N2RNG_FLAG_BUFFER_VALID; in n2rng_data_read()
430 *data = np->buffer; in n2rng_data_read()
435 np->flags |= N2RNG_FLAG_BUFFER_VALID; in n2rng_data_read()
436 np->buffer = np->test_data >> 32; in n2rng_data_read()
437 *data = np->test_data & 0xffffffff; in n2rng_data_read()
440 dev_err(&np->op->dev, "RNG error, retesting\n"); in n2rng_data_read()
441 np->flags &= ~N2RNG_FLAG_READY; in n2rng_data_read()
442 if (!(np->flags & N2RNG_FLAG_SHUTDOWN)) in n2rng_data_read()
443 schedule_delayed_work(&np->work, 0); in n2rng_data_read()
458 unsigned long ra = __pa(&np->test_data); in n2rng_guest_check()
507 if (np->test_buffer[i] == val) in n2rng_test_buffer_find()
518 dev_err(&np->op->dev, "Test buffer slot %d [0x%016llx]\n", in n2rng_dump_test_buffer()
519 i, np->test_buffer[i]); in n2rng_dump_test_buffer()
527 switch (np->data->id) { in n2rng_check_selftest_buffer()
549 err = -ENODEV; in n2rng_check_selftest_buffer()
550 dev_err(&np->op->dev, "Selftest failed on unit %lu\n", unit); in n2rng_check_selftest_buffer()
553 dev_info(&np->op->dev, "Selftest passed on unit %lu\n", unit); in n2rng_check_selftest_buffer()
563 switch (np->data->id) { in n2rng_control_selftest()
569 ((RNG_v1_SELFTEST_TICKS - 2) << RNG_v1_CTL_WAIT_SHIFT); in n2rng_control_selftest()
574 ((RNG_v1_SELFTEST_TICKS - 2) << RNG_v2_CTL_WAIT_SHIFT); in n2rng_control_selftest()
583 np->test_control[0] = base; in n2rng_control_selftest()
584 np->test_control[1] = base; in n2rng_control_selftest()
585 np->test_control[2] = base; in n2rng_control_selftest()
586 np->test_control[3] = base3; in n2rng_control_selftest()
588 err = n2rng_entropy_diag_read(np, unit, np->test_control, in n2rng_control_selftest()
590 np->test_buffer, in n2rng_control_selftest()
591 sizeof(np->test_buffer), in n2rng_control_selftest()
592 &np->units[unit].control[0], in n2rng_control_selftest()
593 np->hv_state); in n2rng_control_selftest()
604 for (i = 0; i < np->num_units; i++) { in n2rng_control_check()
620 for (unit = 0; unit < np->num_units; unit++) { in n2rng_control_configure_units()
621 struct n2rng_unit *up = &np->units[unit]; in n2rng_control_configure_units()
622 unsigned long ctl_ra = __pa(&up->control[0]); in n2rng_control_configure_units()
626 if (np->data->chip_version == 1) { in n2rng_control_configure_units()
627 base = ((np->accum_cycles << RNG_v1_CTL_WAIT_SHIFT) | in n2rng_control_configure_units()
632 base = ((np->accum_cycles << RNG_v2_CTL_WAIT_SHIFT) | in n2rng_control_configure_units()
644 up->control[esrc] = base | in n2rng_control_configure_units()
648 up->control[3] = base | in n2rng_control_configure_units()
666 if (!(np->flags & N2RNG_FLAG_CONTROL)) { in n2rng_work()
678 np->flags |= N2RNG_FLAG_READY; in n2rng_work()
679 dev_info(&np->op->dev, "RNG ready\n"); in n2rng_work()
682 if (--retries == 0) in n2rng_work()
683 dev_err(&np->op->dev, "Self-test retries failed, RNG not ready\n"); in n2rng_work()
684 else if (err && !(np->flags & N2RNG_FLAG_SHUTDOWN)) in n2rng_work()
685 schedule_delayed_work(&np->work, HZ * 2); in n2rng_work()
699 int err = -ENOMEM; in n2rng_probe()
703 np = devm_kzalloc(&op->dev, sizeof(*np), GFP_KERNEL); in n2rng_probe()
706 np->op = op; in n2rng_probe()
707 np->data = (struct n2rng_template *)device_get_match_data(&op->dev); in n2rng_probe()
709 INIT_DELAYED_WORK(&np->work, n2rng_work); in n2rng_probe()
711 if (np->data->multi_capable) in n2rng_probe()
712 np->flags |= N2RNG_FLAG_MULTI; in n2rng_probe()
714 err = -ENODEV; in n2rng_probe()
715 np->hvapi_major = 2; in n2rng_probe()
717 np->hvapi_major, in n2rng_probe()
718 &np->hvapi_minor)) { in n2rng_probe()
719 np->hvapi_major = 1; in n2rng_probe()
721 np->hvapi_major, in n2rng_probe()
722 &np->hvapi_minor)) { in n2rng_probe()
723 dev_err(&op->dev, "Cannot register suitable " in n2rng_probe()
729 if (np->flags & N2RNG_FLAG_MULTI) { in n2rng_probe()
730 if (np->hvapi_major < 2) { in n2rng_probe()
731 dev_err(&op->dev, "multi-unit-capable RNG requires " in n2rng_probe()
733 np->hvapi_major); in n2rng_probe()
736 np->num_units = of_getintprop_default(op->dev.of_node, in n2rng_probe()
737 "rng-#units", 0); in n2rng_probe()
738 if (!np->num_units) { in n2rng_probe()
739 dev_err(&op->dev, "VF RNG lacks rng-#units property\n"); in n2rng_probe()
743 np->num_units = 1; in n2rng_probe()
746 dev_info(&op->dev, "Registered RNG HVAPI major %lu minor %lu\n", in n2rng_probe()
747 np->hvapi_major, np->hvapi_minor); in n2rng_probe()
748 np->units = devm_kcalloc(&op->dev, np->num_units, sizeof(*np->units), in n2rng_probe()
750 err = -ENOMEM; in n2rng_probe()
751 if (!np->units) in n2rng_probe()
758 dev_info(&op->dev, "Found %s RNG, units: %d\n", in n2rng_probe()
759 ((np->flags & N2RNG_FLAG_MULTI) ? in n2rng_probe()
760 "multi-unit-capable" : "single-unit"), in n2rng_probe()
761 np->num_units); in n2rng_probe()
763 np->hwrng.name = DRV_MODULE_NAME; in n2rng_probe()
764 np->hwrng.data_read = n2rng_data_read; in n2rng_probe()
765 np->hwrng.priv = (unsigned long) np; in n2rng_probe()
767 err = devm_hwrng_register(&op->dev, &np->hwrng); in n2rng_probe()
773 schedule_delayed_work(&np->work, 0); in n2rng_probe()
788 np->flags |= N2RNG_FLAG_SHUTDOWN; in n2rng_remove()
790 cancel_delayed_work_sync(&np->work); in n2rng_remove()
827 .name = "random-number-generator",
828 .compatible = "SUNW,n2-rng",
832 .name = "random-number-generator",
833 .compatible = "SUNW,vf-rng",
837 .name = "random-number-generator",
838 .compatible = "SUNW,kt-rng",
842 .name = "random-number-generator",
843 .compatible = "ORCL,m4-rng",
847 .name = "random-number-generator",
848 .compatible = "ORCL,m7-rng",