Lines Matching refs:desc
115 struct wdm_device *desc; in wdm_find_device() local
118 list_for_each_entry(desc, &wdm_device_list, device_list) in wdm_find_device()
119 if (desc->intf == intf) in wdm_find_device()
121 desc = NULL; in wdm_find_device()
125 return desc; in wdm_find_device()
130 struct wdm_device *desc; in wdm_find_device_by_minor() local
133 list_for_each_entry(desc, &wdm_device_list, device_list) in wdm_find_device_by_minor()
134 if (desc->intf->minor == minor) in wdm_find_device_by_minor()
136 desc = NULL; in wdm_find_device_by_minor()
140 return desc; in wdm_find_device_by_minor()
146 struct wdm_device *desc; in wdm_out_callback() local
147 desc = urb->context; in wdm_out_callback()
148 spin_lock(&desc->iuspin); in wdm_out_callback()
149 desc->werr = urb->status; in wdm_out_callback()
150 spin_unlock(&desc->iuspin); in wdm_out_callback()
151 kfree(desc->outbuf); in wdm_out_callback()
152 desc->outbuf = NULL; in wdm_out_callback()
153 clear_bit(WDM_IN_USE, &desc->flags); in wdm_out_callback()
154 wake_up(&desc->wait); in wdm_out_callback()
159 struct wdm_device *desc = urb->context; in wdm_in_callback() local
163 spin_lock(&desc->iuspin); in wdm_in_callback()
164 clear_bit(WDM_RESPONDING, &desc->flags); in wdm_in_callback()
169 dev_dbg(&desc->intf->dev, in wdm_in_callback()
173 dev_dbg(&desc->intf->dev, in wdm_in_callback()
177 dev_dbg(&desc->intf->dev, in wdm_in_callback()
181 dev_err(&desc->intf->dev, in wdm_in_callback()
185 dev_err(&desc->intf->dev, in wdm_in_callback()
191 desc->rerr = status; in wdm_in_callback()
192 if (length + desc->length > desc->wMaxCommand) { in wdm_in_callback()
194 set_bit(WDM_OVERFLOW, &desc->flags); in wdm_in_callback()
197 if (!test_bit(WDM_OVERFLOW, &desc->flags)) { in wdm_in_callback()
198 memmove(desc->ubuf + desc->length, desc->inbuf, length); in wdm_in_callback()
199 desc->length += length; in wdm_in_callback()
200 desc->reslength = length; in wdm_in_callback()
204 wake_up(&desc->wait); in wdm_in_callback()
206 set_bit(WDM_READ, &desc->flags); in wdm_in_callback()
207 spin_unlock(&desc->iuspin); in wdm_in_callback()
215 struct wdm_device *desc; in wdm_int_callback() local
218 desc = urb->context; in wdm_int_callback()
219 dr = (struct usb_cdc_notification *)desc->sbuf; in wdm_int_callback()
228 set_bit(WDM_INT_STALL, &desc->flags); in wdm_int_callback()
229 dev_err(&desc->intf->dev, "Stall on int endpoint\n"); in wdm_int_callback()
232 dev_err(&desc->intf->dev, in wdm_int_callback()
239 dev_err(&desc->intf->dev, "wdm_int_callback - %d bytes\n", in wdm_int_callback()
246 dev_dbg(&desc->intf->dev, in wdm_int_callback()
253 dev_dbg(&desc->intf->dev, in wdm_int_callback()
258 dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)", in wdm_int_callback()
262 clear_bit(WDM_POLL_RUNNING, &desc->flags); in wdm_int_callback()
263 dev_err(&desc->intf->dev, in wdm_int_callback()
271 spin_lock(&desc->iuspin); in wdm_int_callback()
272 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); in wdm_int_callback()
273 if (!desc->resp_count++ && !responding in wdm_int_callback()
274 && !test_bit(WDM_DISCONNECTING, &desc->flags) in wdm_int_callback()
275 && !test_bit(WDM_SUSPENDING, &desc->flags)) { in wdm_int_callback()
276 rv = usb_submit_urb(desc->response, GFP_ATOMIC); in wdm_int_callback()
277 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", in wdm_int_callback()
280 spin_unlock(&desc->iuspin); in wdm_int_callback()
282 clear_bit(WDM_RESPONDING, &desc->flags); in wdm_int_callback()
287 rv = schedule_work(&desc->rxwork); in wdm_int_callback()
289 dev_err(&desc->intf->dev, in wdm_int_callback()
296 dev_err(&desc->intf->dev, in wdm_int_callback()
302 static void kill_urbs(struct wdm_device *desc) in kill_urbs() argument
305 usb_kill_urb(desc->command); in kill_urbs()
306 usb_kill_urb(desc->validity); in kill_urbs()
307 usb_kill_urb(desc->response); in kill_urbs()
310 static void free_urbs(struct wdm_device *desc) in free_urbs() argument
312 usb_free_urb(desc->validity); in free_urbs()
313 usb_free_urb(desc->response); in free_urbs()
314 usb_free_urb(desc->command); in free_urbs()
317 static void cleanup(struct wdm_device *desc) in cleanup() argument
319 kfree(desc->sbuf); in cleanup()
320 kfree(desc->inbuf); in cleanup()
321 kfree(desc->orq); in cleanup()
322 kfree(desc->irq); in cleanup()
323 kfree(desc->ubuf); in cleanup()
324 free_urbs(desc); in cleanup()
325 kfree(desc); in cleanup()
333 struct wdm_device *desc = file->private_data; in wdm_write() local
336 if (count > desc->wMaxCommand) in wdm_write()
337 count = desc->wMaxCommand; in wdm_write()
339 spin_lock_irq(&desc->iuspin); in wdm_write()
340 we = desc->werr; in wdm_write()
341 desc->werr = 0; in wdm_write()
342 spin_unlock_irq(&desc->iuspin); in wdm_write()
359 r = mutex_lock_interruptible(&desc->wlock); in wdm_write()
364 if (test_bit(WDM_DISCONNECTING, &desc->flags)) { in wdm_write()
369 r = usb_autopm_get_interface(desc->intf); in wdm_write()
376 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, in wdm_write()
377 &desc->flags)); in wdm_write()
379 if (test_bit(WDM_IN_USE, &desc->flags)) in wdm_write()
382 if (test_bit(WDM_RESETTING, &desc->flags)) in wdm_write()
390 req = desc->orq; in wdm_write()
392 desc->command, in wdm_write()
393 interface_to_usbdev(desc->intf), in wdm_write()
395 usb_sndctrlpipe(interface_to_usbdev(desc->intf), 0), in wdm_write()
400 desc in wdm_write()
407 req->wIndex = desc->inum; /* already converted */ in wdm_write()
409 set_bit(WDM_IN_USE, &desc->flags); in wdm_write()
410 desc->outbuf = buf; in wdm_write()
412 rv = usb_submit_urb(desc->command, GFP_KERNEL); in wdm_write()
414 desc->outbuf = NULL; in wdm_write()
415 clear_bit(WDM_IN_USE, &desc->flags); in wdm_write()
416 dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv); in wdm_write()
420 dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", in wdm_write()
424 usb_autopm_put_interface(desc->intf); in wdm_write()
425 mutex_unlock(&desc->wlock); in wdm_write()
430 usb_autopm_put_interface(desc->intf); in wdm_write()
432 mutex_unlock(&desc->wlock); in wdm_write()
444 static int clear_wdm_read_flag(struct wdm_device *desc) in clear_wdm_read_flag() argument
448 clear_bit(WDM_READ, &desc->flags); in clear_wdm_read_flag()
451 if (!desc->resp_count || !--desc->resp_count) in clear_wdm_read_flag()
454 set_bit(WDM_RESPONDING, &desc->flags); in clear_wdm_read_flag()
455 spin_unlock_irq(&desc->iuspin); in clear_wdm_read_flag()
456 rv = usb_submit_urb(desc->response, GFP_KERNEL); in clear_wdm_read_flag()
457 spin_lock_irq(&desc->iuspin); in clear_wdm_read_flag()
459 dev_err(&desc->intf->dev, in clear_wdm_read_flag()
463 clear_bit(WDM_RESPONDING, &desc->flags); in clear_wdm_read_flag()
464 desc->resp_count = 0; in clear_wdm_read_flag()
475 struct wdm_device *desc = file->private_data; in wdm_read() local
478 rv = mutex_lock_interruptible(&desc->rlock); /*concurrent reads */ in wdm_read()
482 cntr = ACCESS_ONCE(desc->length); in wdm_read()
484 desc->read = 0; in wdm_read()
486 if (test_bit(WDM_DISCONNECTING, &desc->flags)) { in wdm_read()
490 if (test_bit(WDM_OVERFLOW, &desc->flags)) { in wdm_read()
491 clear_bit(WDM_OVERFLOW, &desc->flags); in wdm_read()
497 if (!test_bit(WDM_READ, &desc->flags)) { in wdm_read()
503 rv = wait_event_interruptible(desc->wait, in wdm_read()
504 test_bit(WDM_READ, &desc->flags)); in wdm_read()
508 if (test_bit(WDM_DISCONNECTING, &desc->flags)) { in wdm_read()
512 if (test_bit(WDM_RESETTING, &desc->flags)) { in wdm_read()
516 usb_mark_last_busy(interface_to_usbdev(desc->intf)); in wdm_read()
522 spin_lock_irq(&desc->iuspin); in wdm_read()
524 if (desc->rerr) { /* read completed, error happened */ in wdm_read()
525 rv = usb_translate_errors(desc->rerr); in wdm_read()
526 desc->rerr = 0; in wdm_read()
527 spin_unlock_irq(&desc->iuspin); in wdm_read()
534 if (!test_bit(WDM_READ, &desc->flags)) { /* lost race */ in wdm_read()
535 spin_unlock_irq(&desc->iuspin); in wdm_read()
539 if (!desc->reslength) { /* zero length read */ in wdm_read()
540 dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__); in wdm_read()
541 rv = clear_wdm_read_flag(desc); in wdm_read()
542 spin_unlock_irq(&desc->iuspin); in wdm_read()
547 cntr = desc->length; in wdm_read()
548 spin_unlock_irq(&desc->iuspin); in wdm_read()
553 rv = copy_to_user(buffer, desc->ubuf, cntr); in wdm_read()
559 spin_lock_irq(&desc->iuspin); in wdm_read()
561 for (i = 0; i < desc->length - cntr; i++) in wdm_read()
562 desc->ubuf[i] = desc->ubuf[i + cntr]; in wdm_read()
564 desc->length -= cntr; in wdm_read()
566 if (!desc->length) in wdm_read()
567 clear_wdm_read_flag(desc); in wdm_read()
568 spin_unlock_irq(&desc->iuspin); in wdm_read()
572 mutex_unlock(&desc->rlock); in wdm_read()
578 struct wdm_device *desc = file->private_data; in wdm_flush() local
580 wait_event(desc->wait, !test_bit(WDM_IN_USE, &desc->flags)); in wdm_flush()
583 if (desc->werr < 0 && !test_bit(WDM_DISCONNECTING, &desc->flags)) in wdm_flush()
584 dev_err(&desc->intf->dev, "Error in flush path: %d\n", in wdm_flush()
585 desc->werr); in wdm_flush()
587 return usb_translate_errors(desc->werr); in wdm_flush()
592 struct wdm_device *desc = file->private_data; in wdm_poll() local
596 spin_lock_irqsave(&desc->iuspin, flags); in wdm_poll()
597 if (test_bit(WDM_DISCONNECTING, &desc->flags)) { in wdm_poll()
599 spin_unlock_irqrestore(&desc->iuspin, flags); in wdm_poll()
602 if (test_bit(WDM_READ, &desc->flags)) in wdm_poll()
604 if (desc->rerr || desc->werr) in wdm_poll()
606 if (!test_bit(WDM_IN_USE, &desc->flags)) in wdm_poll()
608 spin_unlock_irqrestore(&desc->iuspin, flags); in wdm_poll()
610 poll_wait(file, &desc->wait, wait); in wdm_poll()
621 struct wdm_device *desc; in wdm_open() local
624 desc = wdm_find_device_by_minor(minor); in wdm_open()
625 if (!desc) in wdm_open()
628 intf = desc->intf; in wdm_open()
629 if (test_bit(WDM_DISCONNECTING, &desc->flags)) in wdm_open()
631 file->private_data = desc; in wdm_open()
633 rv = usb_autopm_get_interface(desc->intf); in wdm_open()
635 dev_err(&desc->intf->dev, "Error autopm - %d\n", rv); in wdm_open()
640 mutex_lock(&desc->wlock); in wdm_open()
641 if (!desc->count++) { in wdm_open()
642 desc->werr = 0; in wdm_open()
643 desc->rerr = 0; in wdm_open()
644 rv = usb_submit_urb(desc->validity, GFP_KERNEL); in wdm_open()
646 desc->count--; in wdm_open()
647 dev_err(&desc->intf->dev, in wdm_open()
654 mutex_unlock(&desc->wlock); in wdm_open()
655 if (desc->count == 1) in wdm_open()
656 desc->manage_power(intf, 1); in wdm_open()
657 usb_autopm_put_interface(desc->intf); in wdm_open()
665 struct wdm_device *desc = file->private_data; in wdm_release() local
670 mutex_lock(&desc->wlock); in wdm_release()
671 desc->count--; in wdm_release()
672 mutex_unlock(&desc->wlock); in wdm_release()
674 if (!desc->count) { in wdm_release()
675 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { in wdm_release()
676 dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); in wdm_release()
677 kill_urbs(desc); in wdm_release()
678 spin_lock_irq(&desc->iuspin); in wdm_release()
679 desc->resp_count = 0; in wdm_release()
680 spin_unlock_irq(&desc->iuspin); in wdm_release()
681 desc->manage_power(desc->intf, 0); in wdm_release()
685 cleanup(desc); in wdm_release()
694 struct wdm_device *desc = file->private_data; in wdm_ioctl() local
699 if (copy_to_user((void __user *)arg, &desc->wMaxCommand, sizeof(desc->wMaxCommand))) in wdm_ioctl()
730 struct wdm_device *desc = container_of(work, struct wdm_device, rxwork); in wdm_rxwork() local
735 spin_lock_irqsave(&desc->iuspin, flags); in wdm_rxwork()
736 if (test_bit(WDM_DISCONNECTING, &desc->flags)) { in wdm_rxwork()
737 spin_unlock_irqrestore(&desc->iuspin, flags); in wdm_rxwork()
739 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); in wdm_rxwork()
740 spin_unlock_irqrestore(&desc->iuspin, flags); in wdm_rxwork()
742 rv = usb_submit_urb(desc->response, GFP_KERNEL); in wdm_rxwork()
744 spin_lock_irqsave(&desc->iuspin, flags); in wdm_rxwork()
745 clear_bit(WDM_RESPONDING, &desc->flags); in wdm_rxwork()
746 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) in wdm_rxwork()
747 schedule_work(&desc->rxwork); in wdm_rxwork()
748 spin_unlock_irqrestore(&desc->iuspin, flags); in wdm_rxwork()
759 struct wdm_device *desc; in wdm_create() local
761 desc = kzalloc(sizeof(struct wdm_device), GFP_KERNEL); in wdm_create()
762 if (!desc) in wdm_create()
764 INIT_LIST_HEAD(&desc->device_list); in wdm_create()
765 mutex_init(&desc->rlock); in wdm_create()
766 mutex_init(&desc->wlock); in wdm_create()
767 spin_lock_init(&desc->iuspin); in wdm_create()
768 init_waitqueue_head(&desc->wait); in wdm_create()
769 desc->wMaxCommand = bufsize; in wdm_create()
771 desc->inum = cpu_to_le16((u16)intf->cur_altsetting->desc.bInterfaceNumber); in wdm_create()
772 desc->intf = intf; in wdm_create()
773 INIT_WORK(&desc->rxwork, wdm_rxwork); in wdm_create()
779 desc->wMaxPacketSize = usb_endpoint_maxp(ep); in wdm_create()
781 desc->orq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); in wdm_create()
782 if (!desc->orq) in wdm_create()
784 desc->irq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); in wdm_create()
785 if (!desc->irq) in wdm_create()
788 desc->validity = usb_alloc_urb(0, GFP_KERNEL); in wdm_create()
789 if (!desc->validity) in wdm_create()
792 desc->response = usb_alloc_urb(0, GFP_KERNEL); in wdm_create()
793 if (!desc->response) in wdm_create()
796 desc->command = usb_alloc_urb(0, GFP_KERNEL); in wdm_create()
797 if (!desc->command) in wdm_create()
800 desc->ubuf = kmalloc(desc->wMaxCommand, GFP_KERNEL); in wdm_create()
801 if (!desc->ubuf) in wdm_create()
804 desc->sbuf = kmalloc(desc->wMaxPacketSize, GFP_KERNEL); in wdm_create()
805 if (!desc->sbuf) in wdm_create()
808 desc->inbuf = kmalloc(desc->wMaxCommand, GFP_KERNEL); in wdm_create()
809 if (!desc->inbuf) in wdm_create()
813 desc->validity, in wdm_create()
816 desc->sbuf, in wdm_create()
817 desc->wMaxPacketSize, in wdm_create()
819 desc, in wdm_create()
823 desc->irq->bRequestType = (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE); in wdm_create()
824 desc->irq->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; in wdm_create()
825 desc->irq->wValue = 0; in wdm_create()
826 desc->irq->wIndex = desc->inum; /* already converted */ in wdm_create()
827 desc->irq->wLength = cpu_to_le16(desc->wMaxCommand); in wdm_create()
830 desc->response, in wdm_create()
833 usb_rcvctrlpipe(interface_to_usbdev(desc->intf), 0), in wdm_create()
834 (unsigned char *)desc->irq, in wdm_create()
835 desc->inbuf, in wdm_create()
836 desc->wMaxCommand, in wdm_create()
838 desc in wdm_create()
841 desc->manage_power = manage_power; in wdm_create()
844 list_add(&desc->device_list, &wdm_device_list); in wdm_create()
856 list_del(&desc->device_list); in wdm_create()
858 cleanup(desc); in wdm_create()
912 if (iface->desc.bNumEndpoints != 1) in wdm_probe()
914 ep = &iface->endpoint[0].desc; in wdm_probe()
960 struct wdm_device *desc; in wdm_disconnect() local
964 desc = wdm_find_device(intf); in wdm_disconnect()
968 spin_lock_irqsave(&desc->iuspin, flags); in wdm_disconnect()
969 set_bit(WDM_DISCONNECTING, &desc->flags); in wdm_disconnect()
970 set_bit(WDM_READ, &desc->flags); in wdm_disconnect()
972 clear_bit(WDM_IN_USE, &desc->flags); in wdm_disconnect()
973 spin_unlock_irqrestore(&desc->iuspin, flags); in wdm_disconnect()
974 wake_up_all(&desc->wait); in wdm_disconnect()
975 mutex_lock(&desc->rlock); in wdm_disconnect()
976 mutex_lock(&desc->wlock); in wdm_disconnect()
977 kill_urbs(desc); in wdm_disconnect()
978 cancel_work_sync(&desc->rxwork); in wdm_disconnect()
979 mutex_unlock(&desc->wlock); in wdm_disconnect()
980 mutex_unlock(&desc->rlock); in wdm_disconnect()
984 list_del(&desc->device_list); in wdm_disconnect()
987 if (!desc->count) in wdm_disconnect()
988 cleanup(desc); in wdm_disconnect()
990 dev_dbg(&intf->dev, "%s: %d open files - postponing cleanup\n", __func__, desc->count); in wdm_disconnect()
997 struct wdm_device *desc = wdm_find_device(intf); in wdm_suspend() local
1000 dev_dbg(&desc->intf->dev, "wdm%d_suspend\n", intf->minor); in wdm_suspend()
1004 mutex_lock(&desc->rlock); in wdm_suspend()
1005 mutex_lock(&desc->wlock); in wdm_suspend()
1007 spin_lock_irq(&desc->iuspin); in wdm_suspend()
1010 (test_bit(WDM_IN_USE, &desc->flags) in wdm_suspend()
1011 || test_bit(WDM_RESPONDING, &desc->flags))) { in wdm_suspend()
1012 spin_unlock_irq(&desc->iuspin); in wdm_suspend()
1016 set_bit(WDM_SUSPENDING, &desc->flags); in wdm_suspend()
1017 spin_unlock_irq(&desc->iuspin); in wdm_suspend()
1019 kill_urbs(desc); in wdm_suspend()
1020 cancel_work_sync(&desc->rxwork); in wdm_suspend()
1023 mutex_unlock(&desc->wlock); in wdm_suspend()
1024 mutex_unlock(&desc->rlock); in wdm_suspend()
1031 static int recover_from_urb_loss(struct wdm_device *desc) in recover_from_urb_loss() argument
1035 if (desc->count) { in recover_from_urb_loss()
1036 rv = usb_submit_urb(desc->validity, GFP_NOIO); in recover_from_urb_loss()
1038 dev_err(&desc->intf->dev, in recover_from_urb_loss()
1047 struct wdm_device *desc = wdm_find_device(intf); in wdm_resume() local
1050 dev_dbg(&desc->intf->dev, "wdm%d_resume\n", intf->minor); in wdm_resume()
1052 clear_bit(WDM_SUSPENDING, &desc->flags); in wdm_resume()
1053 rv = recover_from_urb_loss(desc); in wdm_resume()
1061 struct wdm_device *desc = wdm_find_device(intf); in wdm_pre_reset() local
1069 spin_lock_irq(&desc->iuspin); in wdm_pre_reset()
1070 set_bit(WDM_RESETTING, &desc->flags); /* inform read/write */ in wdm_pre_reset()
1071 set_bit(WDM_READ, &desc->flags); /* unblock read */ in wdm_pre_reset()
1072 clear_bit(WDM_IN_USE, &desc->flags); /* unblock write */ in wdm_pre_reset()
1073 desc->rerr = -EINTR; in wdm_pre_reset()
1074 spin_unlock_irq(&desc->iuspin); in wdm_pre_reset()
1075 wake_up_all(&desc->wait); in wdm_pre_reset()
1076 mutex_lock(&desc->rlock); in wdm_pre_reset()
1077 mutex_lock(&desc->wlock); in wdm_pre_reset()
1078 kill_urbs(desc); in wdm_pre_reset()
1079 cancel_work_sync(&desc->rxwork); in wdm_pre_reset()
1085 struct wdm_device *desc = wdm_find_device(intf); in wdm_post_reset() local
1088 clear_bit(WDM_OVERFLOW, &desc->flags); in wdm_post_reset()
1089 clear_bit(WDM_RESETTING, &desc->flags); in wdm_post_reset()
1090 rv = recover_from_urb_loss(desc); in wdm_post_reset()
1091 mutex_unlock(&desc->wlock); in wdm_post_reset()
1092 mutex_unlock(&desc->rlock); in wdm_post_reset()