• Home
  • Raw
  • Download

Lines Matching +full:open +full:- +full:circuit

1 // SPDX-License-Identifier: GPL-2.0
3 * chaoskey - driver for ChaosKey device from Altus Metrum.
6 * on a reverse-biased p-n junction in avalanche breakdown. More
31 dev_dbg(&(usb_if)->dev, format, ## arg)
34 dev_err(&(usb_if)->dev, format, ## arg)
73 /* Driver-local specific stuff */
79 int open; /* open count */ member
97 usb_dbg(dev->interface, "free"); in chaoskey_free()
98 usb_free_urb(dev->urb); in chaoskey_free()
99 kfree(dev->name); in chaoskey_free()
100 kfree(dev->buf); in chaoskey_free()
101 usb_put_intf(dev->interface); in chaoskey_free()
110 struct usb_host_interface *altsetting = interface->cur_altsetting; in chaoskey_probe()
114 int result = -ENOMEM; in chaoskey_probe()
118 usb_dbg(interface, "probe %s-%s", udev->product, udev->serial); in chaoskey_probe()
133 return -ENODEV; in chaoskey_probe()
149 dev->interface = usb_get_intf(interface); in chaoskey_probe()
151 dev->buf = kmalloc(size, GFP_KERNEL); in chaoskey_probe()
153 if (dev->buf == NULL) in chaoskey_probe()
156 dev->urb = usb_alloc_urb(0, GFP_KERNEL); in chaoskey_probe()
158 if (!dev->urb) in chaoskey_probe()
161 usb_fill_bulk_urb(dev->urb, in chaoskey_probe()
164 dev->buf, in chaoskey_probe()
173 if (udev->product && udev->serial) { in chaoskey_probe()
174 dev->name = kasprintf(GFP_KERNEL, "%s-%s", udev->product, in chaoskey_probe()
175 udev->serial); in chaoskey_probe()
176 if (dev->name == NULL) in chaoskey_probe()
180 dev->in_ep = in_ep; in chaoskey_probe()
182 if (le16_to_cpu(udev->descriptor.idVendor) != ALEA_VENDOR_ID) in chaoskey_probe()
183 dev->reads_started = true; in chaoskey_probe()
185 dev->size = size; in chaoskey_probe()
186 dev->present = true; in chaoskey_probe()
188 init_waitqueue_head(&dev->wait_q); in chaoskey_probe()
190 mutex_init(&dev->lock); in chaoskey_probe()
191 mutex_init(&dev->rng_lock); in chaoskey_probe()
201 dev->hwrng.name = dev->name ? dev->name : chaoskey_driver.name; in chaoskey_probe()
202 dev->hwrng.read = chaoskey_rng_read; in chaoskey_probe()
203 dev->hwrng.quality = 1024; in chaoskey_probe()
205 dev->hwrng_registered = (hwrng_register(&dev->hwrng) == 0); in chaoskey_probe()
206 if (!dev->hwrng_registered) in chaoskey_probe()
211 usb_dbg(interface, "chaoskey probe success, size %d", dev->size); in chaoskey_probe()
227 usb_dbg(interface, "disconnect failed - no dev"); in chaoskey_disconnect()
231 if (dev->hwrng_registered) in chaoskey_disconnect()
232 hwrng_unregister(&dev->hwrng); in chaoskey_disconnect()
237 mutex_lock(&dev->lock); in chaoskey_disconnect()
239 dev->present = false; in chaoskey_disconnect()
240 usb_poison_urb(dev->urb); in chaoskey_disconnect()
242 if (!dev->open) { in chaoskey_disconnect()
243 mutex_unlock(&dev->lock); in chaoskey_disconnect()
246 mutex_unlock(&dev->lock); in chaoskey_disconnect()
259 return -ENODEV; in chaoskey_open()
261 usb_dbg(interface, "open"); in chaoskey_open()
265 usb_dbg(interface, "open (dev)"); in chaoskey_open()
266 return -ENODEV; in chaoskey_open()
269 file->private_data = dev; in chaoskey_open()
270 mutex_lock(&dev->lock); in chaoskey_open()
271 ++dev->open; in chaoskey_open()
272 mutex_unlock(&dev->lock); in chaoskey_open()
274 usb_dbg(interface, "open success"); in chaoskey_open()
280 struct chaoskey *dev = file->private_data; in chaoskey_release()
284 return -ENODEV; in chaoskey_release()
286 interface = dev->interface; in chaoskey_release()
290 mutex_lock(&dev->lock); in chaoskey_release()
292 usb_dbg(interface, "open count at release is %d", dev->open); in chaoskey_release()
294 if (dev->open <= 0) { in chaoskey_release()
295 usb_dbg(interface, "invalid open count (%d)", dev->open); in chaoskey_release()
296 mutex_unlock(&dev->lock); in chaoskey_release()
297 return -ENODEV; in chaoskey_release()
300 --dev->open; in chaoskey_release()
302 if (!dev->present) { in chaoskey_release()
303 if (dev->open == 0) { in chaoskey_release()
304 mutex_unlock(&dev->lock); in chaoskey_release()
307 mutex_unlock(&dev->lock); in chaoskey_release()
309 mutex_unlock(&dev->lock); in chaoskey_release()
317 struct chaoskey *dev = urb->context; in chaos_read_callback()
318 int status = urb->status; in chaos_read_callback()
320 usb_dbg(dev->interface, "callback status (%d)", status); in chaos_read_callback()
323 dev->valid = urb->actual_length; in chaos_read_callback()
325 dev->valid = 0; in chaos_read_callback()
327 dev->used = 0; in chaos_read_callback()
332 dev->reading = false; in chaos_read_callback()
333 wake_up(&dev->wait_q); in chaos_read_callback()
336 /* Fill the buffer. Called with dev->lock held
344 usb_dbg(dev->interface, "fill"); in _chaoskey_fill()
348 if (dev->valid != dev->used) { in _chaoskey_fill()
349 usb_dbg(dev->interface, "not empty yet (valid %d used %d)", in _chaoskey_fill()
350 dev->valid, dev->used); in _chaoskey_fill()
355 if (!dev->present) { in _chaoskey_fill()
356 usb_dbg(dev->interface, "device not present"); in _chaoskey_fill()
357 return -ENODEV; in _chaoskey_fill()
361 result = usb_autopm_get_interface(dev->interface); in _chaoskey_fill()
363 usb_dbg(dev->interface, "wakeup failed (result %d)", result); in _chaoskey_fill()
367 dev->reading = true; in _chaoskey_fill()
368 result = usb_submit_urb(dev->urb, GFP_KERNEL); in _chaoskey_fill()
371 dev->reading = false; in _chaoskey_fill()
377 * though. Presumably the entropy-generating circuit needs in _chaoskey_fill()
380 started = dev->reads_started; in _chaoskey_fill()
381 dev->reads_started = true; in _chaoskey_fill()
383 dev->wait_q, in _chaoskey_fill()
384 !dev->reading, in _chaoskey_fill()
388 usb_kill_urb(dev->urb); in _chaoskey_fill()
393 result = -ETIMEDOUT; in _chaoskey_fill()
394 usb_kill_urb(dev->urb); in _chaoskey_fill()
396 result = dev->valid; in _chaoskey_fill()
400 usb_autopm_put_interface(dev->interface); in _chaoskey_fill()
402 usb_dbg(dev->interface, "read %d bytes", dev->valid); in _chaoskey_fill()
418 dev = file->private_data; in chaoskey_read()
420 if (dev == NULL || !dev->present) in chaoskey_read()
421 return -ENODEV; in chaoskey_read()
423 usb_dbg(dev->interface, "read %zu", count); in chaoskey_read()
430 result = mutex_lock_interruptible(&dev->rng_lock); in chaoskey_read()
433 mutex_unlock(&dev->rng_lock); in chaoskey_read()
435 result = mutex_lock_interruptible(&dev->lock); in chaoskey_read()
438 if (dev->valid == dev->used) { in chaoskey_read()
441 mutex_unlock(&dev->lock); in chaoskey_read()
446 this_time = dev->valid - dev->used; in chaoskey_read()
450 remain = copy_to_user(buffer, dev->buf + dev->used, this_time); in chaoskey_read()
452 result = -EFAULT; in chaoskey_read()
457 dev->used += this_time - remain; in chaoskey_read()
458 mutex_unlock(&dev->lock); in chaoskey_read()
462 count -= this_time; in chaoskey_read()
465 dev->used += this_time; in chaoskey_read()
466 mutex_unlock(&dev->lock); in chaoskey_read()
470 usb_dbg(dev->interface, "read %zu bytes", read_count); in chaoskey_read()
473 usb_dbg(dev->interface, "empty read, result %d", result); in chaoskey_read()
474 if (result == -ETIMEDOUT) in chaoskey_read()
475 result = -EAGAIN; in chaoskey_read()
485 usb_dbg(dev->interface, "rng_read max %zu wait %d", max, wait); in chaoskey_rng_read()
487 if (!dev->present) { in chaoskey_rng_read()
488 usb_dbg(dev->interface, "device not present"); in chaoskey_rng_read()
496 mutex_lock(&dev->rng_lock); in chaoskey_rng_read()
498 mutex_lock(&dev->lock); in chaoskey_rng_read()
500 mutex_unlock(&dev->rng_lock); in chaoskey_rng_read()
506 if (dev->valid == dev->used) in chaoskey_rng_read()
509 this_time = dev->valid - dev->used; in chaoskey_rng_read()
513 memcpy(data, dev->buf + dev->used, this_time); in chaoskey_rng_read()
515 dev->used += this_time; in chaoskey_rng_read()
517 mutex_unlock(&dev->lock); in chaoskey_rng_read()
519 usb_dbg(dev->interface, "rng_read this_time %d\n", this_time); in chaoskey_rng_read()
545 if (le16_to_cpu(udev->descriptor.idVendor) == ALEA_VENDOR_ID) in chaoskey_resume()
546 dev->reads_started = false; in chaoskey_resume()
559 .open = chaoskey_open,