Lines Matching refs:np
147 static unsigned long n2rng_control_settle_v2(struct n2rng *np, int unit) in n2rng_control_settle_v2() argument
149 unsigned long ra = __pa(&np->scratch_control[0]); in n2rng_control_settle_v2()
154 static unsigned long n2rng_write_ctl_one(struct n2rng *np, int unit, in n2rng_write_ctl_one() argument
162 if (np->hvapi_major == 1) { in n2rng_write_ctl_one()
169 hv_err = n2rng_control_settle_v2(np, unit); in n2rng_write_ctl_one()
201 static unsigned long n2rng_read_diag_data_one(struct n2rng *np, in n2rng_read_diag_data_one() argument
209 if (np->hvapi_major == 1) { in n2rng_read_diag_data_one()
220 static int n2rng_generic_read_diag_data(struct n2rng *np, in n2rng_generic_read_diag_data() argument
229 hv_err = n2rng_read_diag_data_one(np, unit, in n2rng_generic_read_diag_data()
249 static int n2rng_generic_write_control(struct n2rng *np, in n2rng_generic_write_control() argument
258 hv_err = n2rng_write_ctl_one(np, unit, state, control_ra, in n2rng_generic_write_control()
259 np->wd_timeo, &ticks); in n2rng_generic_write_control()
279 static int n2rng_try_read_ctl(struct n2rng *np) in n2rng_try_read_ctl() argument
284 if (np->hvapi_major == 1) { in n2rng_try_read_ctl()
306 static u64 n2rng_control_default(struct n2rng *np, int ctl) in n2rng_control_default() argument
310 if (np->data->chip_version == 1) { in n2rng_control_default()
358 static void n2rng_control_swstate_init(struct n2rng *np) in n2rng_control_swstate_init() argument
362 np->flags |= N2RNG_FLAG_CONTROL; in n2rng_control_swstate_init()
364 np->health_check_sec = N2RNG_HEALTH_CHECK_SEC_DEFAULT; in n2rng_control_swstate_init()
365 np->accum_cycles = N2RNG_ACCUM_CYCLES_DEFAULT; in n2rng_control_swstate_init()
366 np->wd_timeo = N2RNG_WD_TIMEO_DEFAULT; in n2rng_control_swstate_init()
368 for (i = 0; i < np->num_units; i++) { in n2rng_control_swstate_init()
369 struct n2rng_unit *up = &np->units[i]; in n2rng_control_swstate_init()
371 up->control[0] = n2rng_control_default(np, 0); in n2rng_control_swstate_init()
372 up->control[1] = n2rng_control_default(np, 1); in n2rng_control_swstate_init()
373 up->control[2] = n2rng_control_default(np, 2); in n2rng_control_swstate_init()
374 up->control[3] = n2rng_control_default(np, 3); in n2rng_control_swstate_init()
377 np->hv_state = HV_RNG_STATE_UNCONFIGURED; in n2rng_control_swstate_init()
380 static int n2rng_grab_diag_control(struct n2rng *np) in n2rng_grab_diag_control() argument
386 err = n2rng_try_read_ctl(np); in n2rng_grab_diag_control()
391 dev_err(&np->op->dev, in n2rng_grab_diag_control()
402 static int n2rng_init_control(struct n2rng *np) in n2rng_init_control() argument
404 int err = n2rng_grab_diag_control(np); in n2rng_init_control()
414 n2rng_control_swstate_init(np); in n2rng_init_control()
421 struct n2rng *np = (struct n2rng *) rng->priv; in n2rng_data_read() local
422 unsigned long ra = __pa(&np->test_data); in n2rng_data_read()
425 if (!(np->flags & N2RNG_FLAG_READY)) { in n2rng_data_read()
427 } else if (np->flags & N2RNG_FLAG_BUFFER_VALID) { in n2rng_data_read()
428 np->flags &= ~N2RNG_FLAG_BUFFER_VALID; in n2rng_data_read()
429 *data = np->buffer; in n2rng_data_read()
434 np->flags |= N2RNG_FLAG_BUFFER_VALID; in n2rng_data_read()
435 np->buffer = np->test_data >> 32; in n2rng_data_read()
436 *data = np->test_data & 0xffffffff; in n2rng_data_read()
439 dev_err(&np->op->dev, "RNG error, retesting\n"); in n2rng_data_read()
440 np->flags &= ~N2RNG_FLAG_READY; in n2rng_data_read()
441 if (!(np->flags & N2RNG_FLAG_SHUTDOWN)) in n2rng_data_read()
442 schedule_delayed_work(&np->work, 0); in n2rng_data_read()
455 static int n2rng_guest_check(struct n2rng *np) in n2rng_guest_check() argument
457 unsigned long ra = __pa(&np->test_data); in n2rng_guest_check()
462 static int n2rng_entropy_diag_read(struct n2rng *np, unsigned long unit, in n2rng_entropy_diag_read() argument
472 err = n2rng_generic_write_control(np, pre_ctl_ra, unit, pre_state); in n2rng_entropy_diag_read()
476 err = n2rng_generic_read_diag_data(np, unit, in n2rng_entropy_diag_read()
479 (void) n2rng_generic_write_control(np, post_ctl_ra, unit, in n2rng_entropy_diag_read()
500 static int n2rng_test_buffer_find(struct n2rng *np, u64 val) in n2rng_test_buffer_find() argument
506 if (np->test_buffer[i] == val) in n2rng_test_buffer_find()
512 static void n2rng_dump_test_buffer(struct n2rng *np) in n2rng_dump_test_buffer() argument
517 dev_err(&np->op->dev, "Test buffer slot %d [0x%016llx]\n", in n2rng_dump_test_buffer()
518 i, np->test_buffer[i]); in n2rng_dump_test_buffer()
521 static int n2rng_check_selftest_buffer(struct n2rng *np, unsigned long unit) in n2rng_check_selftest_buffer() argument
526 switch (np->data->id) { in n2rng_check_selftest_buffer()
540 matches += n2rng_test_buffer_find(np, val); in n2rng_check_selftest_buffer()
549 dev_err(&np->op->dev, "Selftest failed on unit %lu\n", unit); in n2rng_check_selftest_buffer()
550 n2rng_dump_test_buffer(np); in n2rng_check_selftest_buffer()
552 dev_info(&np->op->dev, "Selftest passed on unit %lu\n", unit); in n2rng_check_selftest_buffer()
557 static int n2rng_control_selftest(struct n2rng *np, unsigned long unit) in n2rng_control_selftest() argument
562 switch (np->data->id) { in n2rng_control_selftest()
582 np->test_control[0] = base; in n2rng_control_selftest()
583 np->test_control[1] = base; in n2rng_control_selftest()
584 np->test_control[2] = base; in n2rng_control_selftest()
585 np->test_control[3] = base3; in n2rng_control_selftest()
587 err = n2rng_entropy_diag_read(np, unit, np->test_control, in n2rng_control_selftest()
589 np->test_buffer, in n2rng_control_selftest()
590 sizeof(np->test_buffer), in n2rng_control_selftest()
591 &np->units[unit].control[0], in n2rng_control_selftest()
592 np->hv_state); in n2rng_control_selftest()
596 return n2rng_check_selftest_buffer(np, unit); in n2rng_control_selftest()
599 static int n2rng_control_check(struct n2rng *np) in n2rng_control_check() argument
603 for (i = 0; i < np->num_units; i++) { in n2rng_control_check()
604 int err = n2rng_control_selftest(np, i); in n2rng_control_check()
614 static int n2rng_control_configure_units(struct n2rng *np) in n2rng_control_configure_units() argument
619 for (unit = 0; unit < np->num_units; unit++) { in n2rng_control_configure_units()
620 struct n2rng_unit *up = &np->units[unit]; in n2rng_control_configure_units()
625 if (np->data->chip_version == 1) { in n2rng_control_configure_units()
626 base = ((np->accum_cycles << RNG_v1_CTL_WAIT_SHIFT) | in n2rng_control_configure_units()
631 base = ((np->accum_cycles << RNG_v2_CTL_WAIT_SHIFT) | in n2rng_control_configure_units()
650 err = n2rng_generic_write_control(np, ctl_ra, unit, in n2rng_control_configure_units()
661 struct n2rng *np = container_of(work, struct n2rng, work.work); in n2rng_work() local
665 if (!(np->flags & N2RNG_FLAG_CONTROL)) { in n2rng_work()
666 err = n2rng_guest_check(np); in n2rng_work()
669 err = n2rng_control_check(np); in n2rng_work()
673 err = n2rng_control_configure_units(np); in n2rng_work()
677 np->flags |= N2RNG_FLAG_READY; in n2rng_work()
678 dev_info(&np->op->dev, "RNG ready\n"); in n2rng_work()
682 dev_err(&np->op->dev, "Self-test retries failed, RNG not ready\n"); in n2rng_work()
683 else if (err && !(np->flags & N2RNG_FLAG_SHUTDOWN)) in n2rng_work()
684 schedule_delayed_work(&np->work, HZ * 2); in n2rng_work()
700 struct n2rng *np; in n2rng_probe() local
707 np = devm_kzalloc(&op->dev, sizeof(*np), GFP_KERNEL); in n2rng_probe()
708 if (!np) in n2rng_probe()
710 np->op = op; in n2rng_probe()
711 np->data = (struct n2rng_template *)match->data; in n2rng_probe()
713 INIT_DELAYED_WORK(&np->work, n2rng_work); in n2rng_probe()
715 if (np->data->multi_capable) in n2rng_probe()
716 np->flags |= N2RNG_FLAG_MULTI; in n2rng_probe()
719 np->hvapi_major = 2; in n2rng_probe()
721 np->hvapi_major, in n2rng_probe()
722 &np->hvapi_minor)) { in n2rng_probe()
723 np->hvapi_major = 1; in n2rng_probe()
725 np->hvapi_major, in n2rng_probe()
726 &np->hvapi_minor)) { in n2rng_probe()
733 if (np->flags & N2RNG_FLAG_MULTI) { in n2rng_probe()
734 if (np->hvapi_major < 2) { in n2rng_probe()
737 np->hvapi_major); in n2rng_probe()
740 np->num_units = of_getintprop_default(op->dev.of_node, in n2rng_probe()
742 if (!np->num_units) { in n2rng_probe()
747 np->num_units = 1; in n2rng_probe()
751 np->hvapi_major, np->hvapi_minor); in n2rng_probe()
752 np->units = devm_kcalloc(&op->dev, np->num_units, sizeof(*np->units), in n2rng_probe()
755 if (!np->units) in n2rng_probe()
758 err = n2rng_init_control(np); in n2rng_probe()
763 ((np->flags & N2RNG_FLAG_MULTI) ? in n2rng_probe()
765 np->num_units); in n2rng_probe()
767 np->hwrng.name = DRV_MODULE_NAME; in n2rng_probe()
768 np->hwrng.data_read = n2rng_data_read; in n2rng_probe()
769 np->hwrng.priv = (unsigned long) np; in n2rng_probe()
771 err = devm_hwrng_register(&op->dev, &np->hwrng); in n2rng_probe()
775 platform_set_drvdata(op, np); in n2rng_probe()
777 schedule_delayed_work(&np->work, 0); in n2rng_probe()
790 struct n2rng *np = platform_get_drvdata(op); in n2rng_remove() local
792 np->flags |= N2RNG_FLAG_SHUTDOWN; in n2rng_remove()
794 cancel_delayed_work_sync(&np->work); in n2rng_remove()