Lines Matching full:rng

31 /* the current rng has been explicitly chosen by user via sysfs */
38 /* Protects rng read functions, data_avail, rng_buffer and rng_fillbuf */
53 static int hwrng_init(struct hwrng *rng);
56 static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
64 static void add_early_randomness(struct hwrng *rng) in add_early_randomness() argument
70 bytes_read = rng_get_data(rng, rng_buffer, size, 0); in add_early_randomness()
78 struct hwrng *rng = container_of(kref, struct hwrng, ref); in cleanup_rng() local
80 if (rng->cleanup) in cleanup_rng()
81 rng->cleanup(rng); in cleanup_rng()
83 complete(&rng->cleanup_done); in cleanup_rng()
86 static int set_current_rng(struct hwrng *rng) in set_current_rng() argument
92 err = hwrng_init(rng); in set_current_rng()
97 current_rng = rng; in set_current_rng()
124 struct hwrng *rng; in get_current_rng() local
129 rng = get_current_rng_nolock(); in get_current_rng()
132 return rng; in get_current_rng()
135 static void put_rng(struct hwrng *rng) in put_rng() argument
139 * on rng again immediately. in put_rng()
142 if (rng) in put_rng()
143 kref_put(&rng->ref, cleanup_rng); in put_rng()
147 static int hwrng_init(struct hwrng *rng) in hwrng_init() argument
149 if (kref_get_unless_zero(&rng->ref)) in hwrng_init()
152 if (rng->init) { in hwrng_init()
155 ret = rng->init(rng); in hwrng_init()
160 kref_init(&rng->ref); in hwrng_init()
161 reinit_completion(&rng->cleanup_done); in hwrng_init()
164 current_quality = rng->quality ? : default_quality; in hwrng_init()
186 static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size, in rng_get_data() argument
191 if (rng->read) in rng_get_data()
192 return rng->read(rng, (void *)buffer, size, wait); in rng_get_data()
194 if (rng->data_present) in rng_get_data()
195 present = rng->data_present(rng, wait); in rng_get_data()
200 return rng->data_read(rng, (u32 *)buffer); in rng_get_data()
211 struct hwrng *rng; in rng_dev_read() local
214 rng = get_current_rng(); in rng_dev_read()
215 if (IS_ERR(rng)) { in rng_dev_read()
216 err = PTR_ERR(rng); in rng_dev_read()
219 if (!rng) { in rng_dev_read()
229 bytes_read = rng_get_data(rng, rng_buffer, in rng_dev_read()
262 put_rng(rng); in rng_dev_read()
278 put_rng(rng); in rng_dev_read()
327 struct hwrng *rng, *old_rng, *new_rng; in hwrng_attr_current_store() local
337 list_for_each_entry(rng, &rng_list, list) { in hwrng_attr_current_store()
338 if (sysfs_streq(rng->name, buf)) { in hwrng_attr_current_store()
340 err = set_current_rng(rng); in hwrng_attr_current_store()
362 struct hwrng *rng; in hwrng_attr_current_show() local
364 rng = get_current_rng(); in hwrng_attr_current_show()
365 if (IS_ERR(rng)) in hwrng_attr_current_show()
366 return PTR_ERR(rng); in hwrng_attr_current_show()
368 ret = snprintf(buf, PAGE_SIZE, "%s\n", rng ? rng->name : "none"); in hwrng_attr_current_show()
369 put_rng(rng); in hwrng_attr_current_show()
379 struct hwrng *rng; in hwrng_attr_available_show() local
385 list_for_each_entry(rng, &rng_list, list) { in hwrng_attr_available_show()
386 strlcat(buf, rng->name, PAGE_SIZE); in hwrng_attr_available_show()
436 struct hwrng *rng; in hwrng_fillfn() local
438 rng = get_current_rng(); in hwrng_fillfn()
439 if (IS_ERR(rng) || !rng) in hwrng_fillfn()
442 rc = rng_get_data(rng, rng_fillbuf, in hwrng_fillfn()
445 put_rng(rng); in hwrng_fillfn()
468 int hwrng_register(struct hwrng *rng) in hwrng_register() argument
475 if (!rng->name || (!rng->data_read && !rng->read)) in hwrng_register()
483 if (strcmp(tmp->name, rng->name) == 0) in hwrng_register()
487 init_completion(&rng->cleanup_done); in hwrng_register()
488 complete(&rng->cleanup_done); in hwrng_register()
493 if (tmp->quality < rng->quality) in hwrng_register()
496 list_add_tail(&rng->list, rng_list_ptr); in hwrng_register()
499 (!cur_rng_set_by_user && rng->quality > current_rng->quality)) { in hwrng_register()
501 * Set new rng as current as the new rng source in hwrng_register()
505 err = set_current_rng(rng); in hwrng_register()
512 kref_get(&rng->ref); in hwrng_register()
515 if (is_new_current || !rng->init) { in hwrng_register()
518 * the system. If this rng device isn't going to be in hwrng_register()
523 add_early_randomness(rng); in hwrng_register()
526 put_rng(rng); in hwrng_register()
535 void hwrng_unregister(struct hwrng *rng) in hwrng_unregister() argument
543 list_del(&rng->list); in hwrng_unregister()
544 if (current_rng == rng) { in hwrng_unregister()
566 wait_for_completion(&rng->cleanup_done); in hwrng_unregister()
585 int devm_hwrng_register(struct device *dev, struct hwrng *rng) in devm_hwrng_register() argument
594 error = hwrng_register(rng); in devm_hwrng_register()
600 *ptr = rng; in devm_hwrng_register()
606 void devm_hwrng_unregister(struct device *dev, struct hwrng *rng) in devm_hwrng_unregister() argument
608 devres_release(dev, devm_hwrng_release, devm_hwrng_match, rng); in devm_hwrng_unregister()
650 MODULE_DESCRIPTION("H/W Random Number Generator (RNG) driver");