Lines Matching defs:aru
121 static void ar9170_usb_submit_urb(struct ar9170_usb *aru)
127 if (unlikely(!IS_STARTED(&aru->common)))
130 spin_lock_irqsave(&aru->tx_urb_lock, flags);
131 if (atomic_read(&aru->tx_submitted_urbs) >= AR9170_NUM_TX_URBS) {
132 spin_unlock_irqrestore(&aru->tx_urb_lock, flags);
135 atomic_inc(&aru->tx_submitted_urbs);
137 urb = usb_get_from_anchor(&aru->tx_pending);
139 atomic_dec(&aru->tx_submitted_urbs);
140 spin_unlock_irqrestore(&aru->tx_urb_lock, flags);
144 spin_unlock_irqrestore(&aru->tx_urb_lock, flags);
146 aru->tx_pending_urbs--;
147 usb_anchor_urb(urb, &aru->tx_submitted);
151 if (ar9170_nag_limiter(&aru->common))
152 dev_err(&aru->udev->dev, "submit_urb failed (%d).\n",
156 atomic_dec(&aru->tx_submitted_urbs);
157 ar9170_tx_callback(&aru->common, urb->context);
166 struct ar9170_usb *aru = (struct ar9170_usb *)
169 if (unlikely(!aru)) {
174 atomic_dec(&aru->tx_submitted_urbs);
176 ar9170_tx_callback(&aru->common, skb);
178 ar9170_usb_submit_urb(aru);
187 struct ar9170_usb *aru = urb->context;
205 ar9170_handle_command_response(&aru->common, urb->transfer_buffer,
209 usb_anchor_urb(urb, &aru->rx_submitted);
218 usb_free_coherent(aru->udev, 64, urb->transfer_buffer, urb->transfer_dma);
224 struct ar9170_usb *aru = (struct ar9170_usb *)
228 if (!aru)
248 ar9170_rx(&aru->common, skb);
254 usb_anchor_urb(urb, &aru->rx_submitted);
267 static int ar9170_usb_prep_rx_urb(struct ar9170_usb *aru,
279 usb_fill_bulk_urb(urb, aru->udev,
280 usb_rcvbulkpipe(aru->udev, AR9170_EP_RX),
288 static int ar9170_usb_alloc_rx_irq_urb(struct ar9170_usb *aru)
299 ibuf = usb_alloc_coherent(aru->udev, 64, GFP_KERNEL, &urb->transfer_dma);
303 usb_fill_int_urb(urb, aru->udev,
304 usb_rcvintpipe(aru->udev, AR9170_EP_IRQ), ibuf,
305 64, ar9170_usb_irq_completed, aru, 1);
308 usb_anchor_urb(urb, &aru->rx_submitted);
312 usb_free_coherent(aru->udev, 64, urb->transfer_buffer,
321 static int ar9170_usb_alloc_rx_bulk_urbs(struct ar9170_usb *aru)
333 err = ar9170_usb_prep_rx_urb(aru, urb, GFP_KERNEL);
339 usb_anchor_urb(urb, &aru->rx_submitted);
351 aru->common.state = AR9170_IDLE;
356 usb_kill_anchored_urbs(&aru->rx_submitted);
362 struct ar9170_usb *aru = (void *) ar;
367 aru->common.state = AR9170_IDLE;
369 usb_wait_anchor_empty_timeout(&aru->tx_pending,
371 while ((urb = usb_get_from_anchor(&aru->tx_pending))) {
372 ar9170_tx_callback(&aru->common, (void *) urb->context);
377 ret = usb_wait_anchor_empty_timeout(&aru->tx_submitted,
382 usb_kill_anchored_urbs(&aru->tx_submitted);
385 aru->common.state = AR9170_STARTED;
390 static void ar9170_usb_cancel_urbs(struct ar9170_usb *aru)
394 aru->common.state = AR9170_UNKNOWN_STATE;
396 err = ar9170_usb_flush(&aru->common);
398 dev_err(&aru->udev->dev, "stuck tx urbs!\n");
400 usb_poison_anchored_urbs(&aru->tx_submitted);
401 usb_poison_anchored_urbs(&aru->rx_submitted);
408 struct ar9170_usb *aru = (void *) ar;
429 spin_lock_irqsave(&aru->common.cmdlock, flags);
430 aru->readbuf = (u8 *)out;
431 aru->readlen = outlen;
432 spin_unlock_irqrestore(&aru->common.cmdlock, flags);
434 usb_fill_int_urb(urb, aru->udev,
435 usb_sndintpipe(aru->udev, AR9170_EP_CMD),
436 aru->common.cmdbuf, plen + 4,
439 usb_anchor_urb(urb, &aru->tx_submitted);
448 err = wait_for_completion_timeout(&aru->cmd_wait, HZ);
454 if (aru->readlen != outlen) {
464 dev_err(&aru->udev->dev, "no command feedback "
469 aru->common.cmdbuf, plen + 4);
474 spin_lock_irqsave(&aru->common.cmdlock, flags);
475 aru->readbuf = NULL;
476 aru->readlen = 0;
477 spin_unlock_irqrestore(&aru->common.cmdlock, flags);
486 struct ar9170_usb *aru = (struct ar9170_usb *) ar;
498 usb_fill_bulk_urb(urb, aru->udev,
499 usb_sndbulkpipe(aru->udev, AR9170_EP_TX),
504 usb_anchor_urb(urb, &aru->tx_pending);
505 aru->tx_pending_urbs++;
509 ar9170_usb_submit_urb(aru);
515 struct ar9170_usb *aru = (void *) ar;
528 if (aru->readlen >= 0) {
530 out |= aru->readlen;
542 dev_warn(&aru->udev->dev, "received invalid command response "
555 spin_lock_irqsave(&aru->common.cmdlock, flags);
556 if (aru->readbuf && len > 0) {
557 memcpy(aru->readbuf, buffer + 4, len - 4);
558 aru->readbuf = NULL;
560 complete(&aru->cmd_wait);
561 spin_unlock_irqrestore(&aru->common.cmdlock, flags);
564 static int ar9170_usb_upload(struct ar9170_usb *aru, const void *data,
577 err = usb_control_msg(aru->udev, usb_sndctrlpipe(aru->udev, 0),
593 err = usb_control_msg(aru->udev, usb_sndctrlpipe(aru->udev, 0),
601 static int ar9170_usb_reset(struct ar9170_usb *aru)
603 int ret, lock = (aru->intf->condition != USB_INTERFACE_BINDING);
606 ret = usb_lock_device_for_reset(aru->udev, aru->intf);
608 dev_err(&aru->udev->dev, "unable to lock device "
614 ret = usb_reset_device(aru->udev);
616 usb_unlock_device(aru->udev);
624 static int ar9170_usb_upload_firmware(struct ar9170_usb *aru)
628 if (!aru->init_values)
632 err = ar9170_usb_upload(aru, aru->init_values->data,
633 aru->init_values->size, 0x102800, false);
635 dev_err(&aru->udev->dev, "firmware part 1 "
643 return ar9170_usb_upload(aru, aru->firmware->data, aru->firmware->size,
647 static int ar9170_usb_init_transport(struct ar9170_usb *aru)
649 struct ar9170 *ar = (void *) &aru->common;
664 dev_err(&aru->udev->dev, "USB setup failed (%d).\n", err);
671 struct ar9170_usb *aru = (void *) ar;
675 aru->common.state = AR9170_STOPPED;
679 dev_err(&aru->udev->dev, "kill pending tx urbs.\n");
681 usb_poison_anchored_urbs(&aru->tx_submitted);
692 struct ar9170_usb *aru = (void *) ar;
695 usb_unpoison_anchored_urbs(&aru->tx_submitted);
696 err = ar9170_usb_init_transport(aru);
698 usb_poison_anchored_urbs(&aru->tx_submitted);
702 aru->common.state = AR9170_IDLE;
706 static int ar9170_usb_init_device(struct ar9170_usb *aru)
710 err = ar9170_usb_alloc_rx_irq_urb(aru);
714 err = ar9170_usb_alloc_rx_bulk_urbs(aru);
718 err = ar9170_usb_upload_firmware(aru);
720 err = ar9170_echo_test(&aru->common, 0x60d43110);
723 err = usb_driver_set_configuration(aru->udev, -1);
724 dev_err(&aru->udev->dev, "device is in a bad state. "
733 ar9170_usb_cancel_urbs(aru);
739 static void ar9170_usb_firmware_failed(struct ar9170_usb *aru)
741 struct device *parent = aru->udev->dev.parent;
748 * driver context (aru).
750 udev = aru->udev;
752 complete(&aru->firmware_loading_complete);
767 struct ar9170_usb *aru = context;
770 aru->firmware = fw;
773 dev_err(&aru->udev->dev, "firmware file not found.\n");
777 err = ar9170_usb_init_device(aru);
781 err = ar9170_usb_open(&aru->common);
785 err = ar9170_register(&aru->common, &aru->udev->dev);
787 ar9170_usb_stop(&aru->common);
791 complete(&aru->firmware_loading_complete);
792 usb_put_dev(aru->udev);
796 ar9170_usb_cancel_urbs(aru);
799 ar9170_usb_firmware_failed(aru);
805 struct ar9170_usb *aru = context;
809 dev_err(&aru->udev->dev, "file with init values not found.\n");
810 ar9170_usb_firmware_failed(aru);
814 aru->init_values = fw;
819 &aru->udev->dev, GFP_KERNEL, aru,
822 ar9170_usb_firmware_failed(aru);
827 struct ar9170_usb *aru = context;
835 if (aru->req_one_stage_fw) {
836 dev_err(&aru->udev->dev, "ar9170.fw firmware file "
838 ar9170_usb_firmware_failed(aru);
842 dev_err(&aru->udev->dev, "ar9170.fw firmware file "
846 &aru->udev->dev, GFP_KERNEL, aru,
849 ar9170_usb_firmware_failed(aru);
864 struct ar9170_usb *aru;
869 aru = ar9170_alloc(sizeof(*aru));
870 if (IS_ERR(aru)) {
871 err = PTR_ERR(aru);
877 aru->udev = udev;
878 aru->intf = intf;
879 ar = &aru->common;
881 aru->req_one_stage_fw = ar9170_requires_one_stage(id);
883 usb_set_intfdata(intf, aru);
886 init_usb_anchor(&aru->rx_submitted);
887 init_usb_anchor(&aru->tx_pending);
888 init_usb_anchor(&aru->tx_submitted);
889 init_completion(&aru->cmd_wait);
890 init_completion(&aru->firmware_loading_complete);
891 spin_lock_init(&aru->tx_urb_lock);
893 aru->tx_pending_urbs = 0;
894 atomic_set(&aru->tx_submitted_urbs, 0);
896 aru->common.stop = ar9170_usb_stop;
897 aru->common.flush = ar9170_usb_flush;
898 aru->common.open = ar9170_usb_open;
899 aru->common.tx = ar9170_usb_tx;
900 aru->common.exec_cmd = ar9170_usb_exec_cmd;
901 aru->common.callback_cmd = ar9170_usb_callback_cmd;
906 err = ar9170_usb_reset(aru);
910 usb_get_dev(aru->udev);
912 &aru->udev->dev, GFP_KERNEL, aru,
924 struct ar9170_usb *aru = usb_get_intfdata(intf);
926 if (!aru)
929 aru->common.state = AR9170_IDLE;
931 wait_for_completion(&aru->firmware_loading_complete);
933 ar9170_unregister(&aru->common);
934 ar9170_usb_cancel_urbs(aru);
936 usb_put_dev(aru->udev);
938 ieee80211_free_hw(aru->common.hw);
940 release_firmware(aru->init_values);
941 release_firmware(aru->firmware);
948 struct ar9170_usb *aru = usb_get_intfdata(intf);
950 if (!aru)
953 aru->common.state = AR9170_IDLE;
954 ar9170_usb_cancel_urbs(aru);
961 struct ar9170_usb *aru = usb_get_intfdata(intf);
964 if (!aru)
967 usb_unpoison_anchored_urbs(&aru->rx_submitted);
968 usb_unpoison_anchored_urbs(&aru->tx_submitted);
970 err = ar9170_usb_init_device(aru);
974 err = ar9170_usb_open(&aru->common);
981 aru->common.state = AR9170_IDLE;
982 ar9170_usb_cancel_urbs(aru);