Lines Matching refs:dln2
123 struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent); in dln2_register_event_cb() local
136 spin_lock_irqsave(&dln2->event_cb_lock, flags); in dln2_register_event_cb()
138 list_for_each_entry(i, &dln2->event_cb_list, list) { in dln2_register_event_cb()
146 list_add_rcu(&entry->list, &dln2->event_cb_list); in dln2_register_event_cb()
148 spin_unlock_irqrestore(&dln2->event_cb_lock, flags); in dln2_register_event_cb()
159 struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent); in dln2_unregister_event_cb() local
164 spin_lock_irqsave(&dln2->event_cb_lock, flags); in dln2_unregister_event_cb()
166 list_for_each_entry(i, &dln2->event_cb_list, list) { in dln2_unregister_event_cb()
174 spin_unlock_irqrestore(&dln2->event_cb_lock, flags); in dln2_unregister_event_cb()
188 static bool dln2_transfer_complete(struct dln2_dev *dln2, struct urb *urb, in dln2_transfer_complete() argument
191 struct device *dev = &dln2->interface->dev; in dln2_transfer_complete()
192 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle]; in dln2_transfer_complete()
217 static void dln2_run_event_callbacks(struct dln2_dev *dln2, u16 id, u16 echo, in dln2_run_event_callbacks() argument
224 list_for_each_entry_rcu(i, &dln2->event_cb_list, list) { in dln2_run_event_callbacks()
236 struct dln2_dev *dln2 = urb->context; in dln2_rx() local
238 struct device *dev = &dln2->interface->dev; in dln2_rx()
287 spin_lock_irqsave(&dln2->event_cb_lock, flags); in dln2_rx()
288 dln2_run_event_callbacks(dln2, id, echo, data, len); in dln2_rx()
289 spin_unlock_irqrestore(&dln2->event_cb_lock, flags); in dln2_rx()
292 if (dln2_transfer_complete(dln2, urb, handle, echo)) in dln2_rx()
327 static int dln2_send_wait(struct dln2_dev *dln2, u16 handle, u16 cmd, u16 echo, in dln2_send_wait() argument
339 ret = usb_bulk_msg(dln2->usb_dev, in dln2_send_wait()
340 usb_sndbulkpipe(dln2->usb_dev, dln2->ep_out), in dln2_send_wait()
348 static bool find_free_slot(struct dln2_dev *dln2, u16 handle, int *slot) in find_free_slot() argument
353 if (dln2->disconnect) { in find_free_slot()
358 rxs = &dln2->mod_rx_slots[handle]; in find_free_slot()
376 static int alloc_rx_slot(struct dln2_dev *dln2, u16 handle) in alloc_rx_slot() argument
385 ret = wait_event_interruptible(dln2->mod_rx_slots[handle].wq, in alloc_rx_slot()
386 find_free_slot(dln2, handle, &slot)); in alloc_rx_slot()
393 static void free_rx_slot(struct dln2_dev *dln2, u16 handle, int slot) in free_rx_slot() argument
400 rxs = &dln2->mod_rx_slots[handle]; in free_rx_slot()
416 struct device *dev = &dln2->interface->dev; in free_rx_slot()
426 static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd, in _dln2_transfer() argument
434 struct device *dev = &dln2->interface->dev; in _dln2_transfer()
436 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle]; in _dln2_transfer()
439 spin_lock(&dln2->disconnect_lock); in _dln2_transfer()
440 if (!dln2->disconnect) in _dln2_transfer()
441 dln2->active_transfers++; in _dln2_transfer()
444 spin_unlock(&dln2->disconnect_lock); in _dln2_transfer()
449 rx_slot = alloc_rx_slot(dln2, handle); in _dln2_transfer()
455 ret = dln2_send_wait(dln2, handle, cmd, rx_slot, obuf, obuf_len); in _dln2_transfer()
472 if (dln2->disconnect) { in _dln2_transfer()
502 free_rx_slot(dln2, handle, rx_slot); in _dln2_transfer()
504 spin_lock(&dln2->disconnect_lock); in _dln2_transfer()
505 dln2->active_transfers--; in _dln2_transfer()
506 spin_unlock(&dln2->disconnect_lock); in _dln2_transfer()
507 if (dln2->disconnect) in _dln2_transfer()
508 wake_up(&dln2->disconnect_wq); in _dln2_transfer()
518 struct dln2_dev *dln2; in dln2_transfer() local
521 dln2 = dev_get_drvdata(pdev->dev.parent); in dln2_transfer()
525 return _dln2_transfer(dln2, handle, cmd, obuf, obuf_len, ibuf, in dln2_transfer()
530 static int dln2_check_hw(struct dln2_dev *dln2) in dln2_check_hw() argument
536 ret = _dln2_transfer(dln2, DLN2_HANDLE_CTRL, CMD_GET_DEVICE_VER, in dln2_check_hw()
544 dev_err(&dln2->interface->dev, "Device ID 0x%x not supported\n", in dln2_check_hw()
552 static int dln2_print_serialno(struct dln2_dev *dln2) in dln2_print_serialno() argument
557 struct device *dev = &dln2->interface->dev; in dln2_print_serialno()
559 ret = _dln2_transfer(dln2, DLN2_HANDLE_CTRL, CMD_GET_DEVICE_SN, NULL, 0, in dln2_print_serialno()
571 static int dln2_hw_init(struct dln2_dev *dln2) in dln2_hw_init() argument
575 ret = dln2_check_hw(dln2); in dln2_hw_init()
579 return dln2_print_serialno(dln2); in dln2_hw_init()
582 static void dln2_free_rx_urbs(struct dln2_dev *dln2) in dln2_free_rx_urbs() argument
587 usb_free_urb(dln2->rx_urb[i]); in dln2_free_rx_urbs()
588 kfree(dln2->rx_buf[i]); in dln2_free_rx_urbs()
592 static void dln2_stop_rx_urbs(struct dln2_dev *dln2) in dln2_stop_rx_urbs() argument
597 usb_kill_urb(dln2->rx_urb[i]); in dln2_stop_rx_urbs()
600 static void dln2_free(struct dln2_dev *dln2) in dln2_free() argument
602 dln2_free_rx_urbs(dln2); in dln2_free()
603 usb_put_dev(dln2->usb_dev); in dln2_free()
604 kfree(dln2); in dln2_free()
607 static int dln2_setup_rx_urbs(struct dln2_dev *dln2, in dln2_setup_rx_urbs() argument
614 dln2->rx_buf[i] = kmalloc(rx_max_size, GFP_KERNEL); in dln2_setup_rx_urbs()
615 if (!dln2->rx_buf[i]) in dln2_setup_rx_urbs()
618 dln2->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); in dln2_setup_rx_urbs()
619 if (!dln2->rx_urb[i]) in dln2_setup_rx_urbs()
622 usb_fill_bulk_urb(dln2->rx_urb[i], dln2->usb_dev, in dln2_setup_rx_urbs()
623 usb_rcvbulkpipe(dln2->usb_dev, dln2->ep_in), in dln2_setup_rx_urbs()
624 dln2->rx_buf[i], rx_max_size, dln2_rx, dln2); in dln2_setup_rx_urbs()
630 static int dln2_start_rx_urbs(struct dln2_dev *dln2, gfp_t gfp) in dln2_start_rx_urbs() argument
632 struct device *dev = &dln2->interface->dev; in dln2_start_rx_urbs()
637 ret = usb_submit_urb(dln2->rx_urb[i], gfp); in dln2_start_rx_urbs()
719 static void dln2_stop(struct dln2_dev *dln2) in dln2_stop() argument
724 spin_lock(&dln2->disconnect_lock); in dln2_stop()
725 dln2->disconnect = true; in dln2_stop()
726 spin_unlock(&dln2->disconnect_lock); in dln2_stop()
730 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[i]; in dln2_stop()
747 wait_event(dln2->disconnect_wq, !dln2->active_transfers); in dln2_stop()
749 dln2_stop_rx_urbs(dln2); in dln2_stop()
754 struct dln2_dev *dln2 = usb_get_intfdata(interface); in dln2_disconnect() local
756 dln2_stop(dln2); in dln2_disconnect()
760 dln2_free(dln2); in dln2_disconnect()
770 struct dln2_dev *dln2; in dln2_probe() local
781 dln2 = kzalloc(sizeof(*dln2), GFP_KERNEL); in dln2_probe()
782 if (!dln2) in dln2_probe()
785 dln2->ep_out = epout->bEndpointAddress; in dln2_probe()
786 dln2->ep_in = epin->bEndpointAddress; in dln2_probe()
787 dln2->usb_dev = usb_get_dev(interface_to_usbdev(interface)); in dln2_probe()
788 dln2->interface = interface; in dln2_probe()
789 usb_set_intfdata(interface, dln2); in dln2_probe()
790 init_waitqueue_head(&dln2->disconnect_wq); in dln2_probe()
793 init_waitqueue_head(&dln2->mod_rx_slots[i].wq); in dln2_probe()
794 spin_lock_init(&dln2->mod_rx_slots[i].lock); in dln2_probe()
796 init_completion(&dln2->mod_rx_slots[i].slots[j].done); in dln2_probe()
799 spin_lock_init(&dln2->event_cb_lock); in dln2_probe()
800 spin_lock_init(&dln2->disconnect_lock); in dln2_probe()
801 INIT_LIST_HEAD(&dln2->event_cb_list); in dln2_probe()
803 ret = dln2_setup_rx_urbs(dln2, hostif); in dln2_probe()
807 ret = dln2_start_rx_urbs(dln2, GFP_KERNEL); in dln2_probe()
811 ret = dln2_hw_init(dln2); in dln2_probe()
826 dln2_stop_rx_urbs(dln2); in dln2_probe()
829 dln2_free(dln2); in dln2_probe()
836 struct dln2_dev *dln2 = usb_get_intfdata(iface); in dln2_suspend() local
838 dln2_stop(dln2); in dln2_suspend()
845 struct dln2_dev *dln2 = usb_get_intfdata(iface); in dln2_resume() local
847 dln2->disconnect = false; in dln2_resume()
849 return dln2_start_rx_urbs(dln2, GFP_NOIO); in dln2_resume()