Home | History | Annotate | Download | only in usb

Lines Matching defs:usc

247 	struct athn_usb_softc *usc;
253 usc = device_private(self);
254 sc = &usc->usc_sc;
257 usc->usc_udev = uaa->uaa_device;
262 devinfop = usbd_devinfo_alloc(usc->usc_udev, 0);
268 usc->usc_init_state = ATHN_INIT_NONE;
269 usc->usc_athn_attached = 0;
270 usc->usc_flags = athn_usb_lookup(uaa->uaa_vendor, uaa->uaa_product)->flags;
282 mutex_init(&usc->usc_lock, MUTEX_DEFAULT, IPL_NONE);
284 cv_init(&usc->usc_wmi_cv, "athnwmi");
285 cv_init(&usc->usc_htc_cv, "athnhtc");
287 cv_init(&usc->usc_cmd_cv, "athncmd");
288 mutex_init(&usc->usc_cmd_mtx, MUTEX_DEFAULT, IPL_SOFTUSB);
289 cv_init(&usc->usc_msg_cv, "athnmsg");
290 mutex_init(&usc->usc_msg_mtx, MUTEX_DEFAULT, IPL_SOFTUSB);
292 cv_init(&usc->usc_task_cv, "athntsk");
293 mutex_init(&usc->usc_task_mtx, MUTEX_DEFAULT, IPL_NET);
294 mutex_init(&usc->usc_tx_mtx, MUTEX_DEFAULT, IPL_NONE);
296 usb_init_task(&usc->usc_task, athn_usb_task, usc, 0);
298 if (usbd_set_config_no(usc->usc_udev, 1, 0) != 0) {
305 error = usbd_device2interface_handle(usc->usc_udev, 0, &usc->usc_iface);
312 if (athn_usb_open_pipes(usc) != 0)
316 if (athn_usb_alloc_tx_cmd(usc) != 0)
320 if (athn_usb_alloc_tx_msg(usc) != 0)
324 error = athn_usb_alloc_rx_list(usc);
327 error = athn_usb_alloc_tx_list(usc);
333 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, usc->usc_udev, sc->sc_dev);
337 usc->usc_init_state = ATHN_INIT_INITED;
344 athn_usb_abort_pipes(usc);
345 athn_usb_free_tx_list(usc);
346 athn_usb_free_rx_list(usc);
347 athn_usb_free_tx_cmd(usc);
348 athn_usb_free_tx_msg(usc);
349 athn_usb_close_pipes(usc);
350 usb_rem_task_wait(usc->usc_udev, &usc->usc_task, USB_TASKQ_DRIVER,
353 cv_destroy(&usc->usc_cmd_cv);
354 cv_destroy(&usc->usc_msg_cv);
356 cv_destroy(&usc->usc_wmi_cv);
357 cv_destroy(&usc->usc_htc_cv);
358 mutex_destroy(&usc->usc_lock);
360 mutex_destroy(&usc->usc_cmd_mtx);
361 mutex_destroy(&usc->usc_msg_mtx);
362 mutex_destroy(&usc->usc_tx_mtx);
363 mutex_destroy(&usc->usc_task_mtx);
367 athn_usb_node_cleanup_cb(struct athn_usb_softc *usc, void *arg)
371 DPRINTFN(DBG_FN, usc, "\n");
372 DPRINTFN(DBG_NODES, usc, "removing node %u\n", sta_index);
373 athn_usb_remove_hw_node(usc, &sta_index);
379 struct athn_usb_softc *usc;
383 usc = ATHN_USB_SOFTC(ni->ni_ic->ic_ifp->if_softc);
384 ic = &ATHN_SOFTC(usc)->sc_ic;
386 DPRINTFN(DBG_FN, usc, "\n");
391 athn_usb_do_async(usc, athn_usb_node_cleanup_cb,
394 usc->usc_node_cleanup(ni);
400 struct athn_usb_softc *usc = device_private(arg);
401 struct athn_softc *sc = &usc->usc_sc;
408 if (usc->usc_dying)
411 DPRINTFN(DBG_FN, usc, "\n");
414 error = athn_usb_load_firmware(usc);
422 error = athn_usb_htc_setup(usc);
443 usc->usc_athn_attached = 1;
447 usc->usc_node_cleanup = ic->ic_node_cleanup;
483 struct athn_usb_softc *usc = device_private(self);
484 struct athn_softc *sc = &usc->usc_sc;
487 DPRINTFN(DBG_FN, usc, "\n");
489 if (usc->usc_init_state < ATHN_INIT_INITED)
494 mutex_enter(&usc->usc_lock);
495 usc->usc_dying = 1;
496 mutex_exit(&usc->usc_lock);
498 mutex_enter(&usc->usc_cmd_mtx);
499 while (usc->usc_wmiactive) {
500 error = cv_timedwait(&usc->usc_wmi_cv, &usc->usc_cmd_mtx, hz);
503 mutex_exit(&usc->usc_cmd_mtx);
507 mutex_exit(&usc->usc_cmd_mtx);
509 mutex_enter(&usc->usc_msg_mtx);
510 while (usc->usc_htcactive) {
511 error = cv_timedwait(&usc->usc_htc_cv, &usc->usc_msg_mtx, hz);
514 mutex_exit(&usc->usc_msg_mtx);
518 mutex_exit(&usc->usc_msg_mtx);
520 athn_usb_wait_async(usc);
523 usb_rem_task_wait(usc->usc_udev, &usc->usc_task, USB_TASKQ_DRIVER,
527 athn_usb_abort_pipes(usc);
529 if (usc->usc_athn_attached) {
530 usc->usc_athn_attached = 0;
535 athn_usb_free_rx_list(usc);
536 usc);
537 athn_usb_free_tx_cmd(usc);
538 athn_usb_free_tx_msg(usc);
541 athn_usb_close_pipes(usc);
543 mutex_destroy(&usc->usc_tx_mtx);
544 cv_destroy(&usc->usc_task_cv);
545 mutex_destroy(&usc->usc_task_mtx);
547 mutex_destroy(&usc->usc_cmd_mtx);
548 cv_destroy(&usc->usc_cmd_cv);
549 mutex_destroy(&usc->usc_msg_mtx);
550 cv_destroy(&usc->usc_msg_cv);
552 cv_destroy(&usc->usc_wmi_cv);
553 mutex_destroy(&usc->usc_lock);
555 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, usc->usc_udev, sc->sc_dev);
562 struct athn_usb_softc *usc = device_private(self);
563 struct athn_softc *sc = &usc->usc_sc;
565 DPRINTFN(DBG_FN, usc, "\n");
570 usc->usc_dying = 1;
578 athn_usb_open_pipes(struct athn_usb_softc *usc)
583 DPRINTFN(DBG_FN, usc, "\n");
585 error = usbd_open_pipe(usc->usc_iface, AR_PIPE_TX_DATA, 0,
586 &usc->usc_tx_data_pipe);
588 aprint_error_dev(usc->usc_dev,
593 error = usbd_open_pipe(usc->usc_iface, AR_PIPE_RX_DATA, 0,
594 &usc->usc_rx_data_pipe);
596 aprint_error_dev(usc->usc_dev,
601 ed = usbd_get_endpoint_descriptor(usc->usc_iface, AR_PIPE_RX_INTR);
603 aprint_error_dev(usc->usc_dev,
607 usc->usc_ibufsize = UGETW(ed->wMaxPacketSize);
608 if (usc->usc_ibufsize == 0) {
609 aprint_error_dev(usc->usc_dev,
613 usc->usc_ibuf = kmem_alloc(usc->usc_ibufsize, KM_SLEEP);
615 error = usbd_open_pipe_intr(usc->usc_iface, AR_PIPE_RX_INTR,
616 USBD_SHORT_XFER_OK, &usc->usc_rx_intr_pipe, usc, usc->usc_ibuf,
617 usc->usc_ibufsize, athn_usb_intr, USBD_DEFAULT_INTERVAL);
619 aprint_error_dev(usc->usc_dev,
623 error = usbd_open_pipe(usc->usc_iface, AR_PIPE_TX_INTR, 0,
624 &usc->usc_tx_intr_pipe);
626 aprint_error_dev(usc->usc_dev,
632 athn_usb_abort_pipes(usc);
633 athn_usb_close_pipes(usc);
650 athn_usb_abort_pipes(struct athn_usb_softc *usc)
652 DPRINTFN(DBG_FN, usc, "\n");
654 if (usc->usc_tx_data_pipe != NULL)
655 usbd_abort_pipe(usc->usc_tx_data_pipe);
656 if (usc->usc_rx_data_pipe != NULL)
657 usbd_abort_pipe(usc->usc_rx_data_pipe);
658 if (usc->usc_tx_intr_pipe != NULL)
659 usbd_abort_pipe(usc->usc_tx_intr_pipe);
660 if (usc->usc_rx_intr_pipe != NULL)
661 usbd_abort_pipe(usc->usc_rx_intr_pipe);
665 athn_usb_close_pipes(struct athn_usb_softc *usc)
669 DPRINTFN(DBG_FN, usc, "\n");
671 athn_usb_kill_pipe(&usc->usc_tx_data_pipe);
672 athn_usb_kill_pipe(&usc->usc_rx_data_pipe);
673 athn_usb_kill_pipe(&usc->usc_tx_intr_pipe);
674 athn_usb_kill_pipe(&usc->usc_rx_intr_pipe);
675 ibuf = atomic_swap_ptr(&usc->usc_ibuf, NULL);
677 kmem_free(ibuf, usc->usc_ibufsize);
681 athn_usb_alloc_rx_list(struct athn_usb_softc *usc)
687 DPRINTFN(DBG_FN, usc, "\n");
690 data = &usc->usc_rx_data[i];
692 data->sc = usc; /* Backpointer for callbacks. */
694 error = usbd_create_xfer(usc->usc_rx_data_pipe,
697 aprint_error_dev(usc->usc_dev,
704 athn_usb_free_rx_list(usc);
709 athn_usb_free_rx_list(struct athn_usb_softc *usc)
714 DPRINTFN(DBG_FN, usc, "\n");
719 xfer = atomic_swap_ptr(&usc->usc_rx_data[i].xfer, NULL);
726 athn_usb_alloc_tx_list(struct athn_usb_softc *usc)
732 DPRINTFN(DBG_FN, usc, "\n");
734 mutex_enter(&usc->usc_tx_mtx);
735 TAILQ_INIT(&usc->usc_tx_free_list);
737 data = &usc->usc_tx_data[i];
739 data->sc = usc; /* Backpointer for callbacks. */
741 error = usbd_create_xfer(usc->usc_tx_data_pipe,
744 aprint_error_dev(usc->usc_dev,
751 TAILQ_INSERT_TAIL(&usc->usc_tx_free_list, data, next);
755 usc->usc_tx_bcn = TAILQ_FIRST(&usc->usc_tx_free_list);
756 TAILQ_REMOVE(&usc->usc_tx_free_list, usc->usc_tx_bcn, next);
758 athn_usb_free_tx_list(usc);
760 mutex_exit(&usc->usc_tx_mtx);
766 athn_usb_free_tx_list(struct athn_usb_softc *usc)
771 DPRINTFN(DBG_FN, usc, "\n");
776 xfer = atomic_swap_ptr(&usc->usc_tx_data[i].xfer, NULL);
783 athn_usb_alloc_tx_cmd(struct athn_usb_softc *usc)
785 struct athn_usb_tx_data *data = &usc->usc_tx_cmd;
787 DPRINTFN(DBG_FN, usc, "\n");
789 data->sc = usc; /* Backpointer for callbacks. */
791 int err = usbd_create_xfer(usc->usc_tx_intr_pipe, ATHN_USB_TXCMDSZ,
794 aprint_error_dev(usc->usc_dev,
804 athn_usb_free_tx_cmd(struct athn_usb_softc *usc)
808 DPRINTFN(DBG_FN, usc, "\n");
811 xfer = atomic_swap_ptr(&usc->usc_tx_cmd.xfer, NULL);
817 athn_usb_alloc_tx_msg(struct athn_usb_softc *usc)
819 struct athn_usb_tx_data *data = &usc->usc_tx_msg;
821 DPRINTFN(DBG_FN, usc, "\n");
823 data->sc = usc; /* Backpointer for callbacks. */
825 int err = usbd_create_xfer(usc->usc_tx_intr_pipe, ATHN_USB_TXCMDSZ,
828 aprint_error_dev(usc->usc_dev,
838 athn_usb_free_tx_msg(struct athn_usb_softc *usc)
842 DPRINTFN(DBG_FN, usc, "\n");
845 xfer = atomic_swap_ptr(&usc->usc_tx_msg.xfer, NULL);
853 struct athn_usb_softc *usc = arg;
854 struct athn_usb_host_cmd_ring *ring = &usc->usc_cmdq;
857 DPRINTFN(DBG_FN, usc, "\n");
860 mutex_spin_enter(&usc->usc_task_mtx);
863 mutex_spin_exit(&usc->usc_task_mtx);
866 if (!usc->usc_dying)
867 cmd->cb(usc, cmd->data);
869 mutex_spin_enter(&usc->usc_task_mtx);
873 cv_broadcast(&usc->usc_task_cv);
874 mutex_spin_exit(&usc->usc_task_mtx);
878 athn_usb_do_async(struct athn_usb_softc *usc,
881 struct athn_usb_host_cmd_ring *ring = &usc->usc_cmdq;
884 if (usc->usc_dying)
887 DPRINTFN(DBG_FN, usc, "\n");
889 mutex_spin_enter(&usc->usc_task_mtx);
898 usb_add_task(usc->usc_udev, &usc->usc_task, USB_TASKQ_DRIVER);
900 mutex_spin_exit(&usc->usc_task_mtx);
904 athn_usb_wait_async(struct athn_usb_softc *usc)
907 DPRINTFN(DBG_FN, usc, "\n");
910 mutex_spin_enter(&usc->usc_task_mtx);
911 while (usc->usc_cmdq.queued > 0)
912 cv_wait(&usc->usc_task_cv, &usc->usc_task_mtx);
913 mutex_spin_exit(&usc->usc_task_mtx);
917 athn_usb_load_firmware(struct athn_usb_softc *usc)
919 struct athn_softc *sc = &usc->usc_sc;
932 if (usc->usc_flags & ATHN_USB_FLAG_AR7010) {
933 dd = usbd_get_device_descriptor(usc->usc_udev);
950 aprint_error_dev(usc->usc_dev,
958 aprint_error_dev(usc->usc_dev,
976 error = usbd_do_request(usc->usc_udev, &req, ptr);
988 if (usc->usc_flags & ATHN_USB_FLAG_AR7010)
998 mutex_enter(&usc->usc_msg_mtx);
999 while (usc->usc_htcactive) {
1000 error = cv_timedwait(&usc->usc_htc_cv, &usc->usc_msg_mtx, hz);
1003 mutex_exit(&usc->usc_msg_mtx);
1008 usc->usc_htcactive = true;
1010 KASSERT(usc->usc_wait_msg_id == 0);
1011 usc->usc_wait_msg_id = AR_HTC_MSG_READY;
1012 mutex_exit(&usc->usc_msg_mtx);
1014 error = usbd_do_request(usc->usc_udev, &req, NULL);
1016 mutex_enter(&usc->usc_msg_mtx);
1019 error = athn_usb_wait_msg(usc);
1021 usc->usc_htcactive = false;
1022 cv_broadcast(&usc->usc_htc_cv);
1023 mutex_exit(&usc->usc_msg_mtx);
1031 athn_usb_htc_msg(struct athn_usb_softc *usc, uint16_t msg_id, void *buf,
1034 struct athn_usb_tx_data *data = &usc->usc_tx_msg;
1038 if (usc->usc_dying)
1041 DPRINTFN(DBG_FN, usc, "\n");
1062 athn_usb_htc_setup(struct athn_usb_softc *usc)
1067 mutex_enter(&usc->usc_msg_mtx);
1068 while (usc->usc_htcactive) {
1069 error = cv_timedwait(&usc->usc_htc_cv, &usc->usc_msg_mtx, hz);
1072 mutex_exit(&usc->usc_msg_mtx);
1076 usc->usc_htcactive = true;
1077 mutex_exit(&usc->usc_msg_mtx);
1082 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_CONTROL,
1083 AR_PIPE_TX_INTR, AR_PIPE_RX_INTR, &usc->usc_ep_ctrl);
1086 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_BEACON,
1087 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_bcn);
1090 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_CAB,
1091 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_cab);
1094 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_UAPSD,
1095 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_uapsd);
1098 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_MGMT,
1099 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_mgmt);
1102 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_DATA_BE,
1103 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_data[WME_AC_BE]);
1106 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_DATA_BK,
1107 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_data[WME_AC_BK]);
1110 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_DATA_VI,
1111 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_data[WME_AC_VI]);
1114 error = athn_usb_htc_connect_svc(usc, AR_SVC_WMI_DATA_VO,
1115 AR_PIPE_TX_DATA, AR_PIPE_RX_DATA, &usc->usc_ep_data[WME_AC_VO]);
1122 cfg.credits = (usc->usc_flags & ATHN_USB_FLAG_AR7010) ? 45 : 33;
1124 mutex_enter(&usc->usc_msg_mtx);
1126 KASSERT(usc->usc_wait_msg_id == 0);
1127 usc->usc_wait_msg_id = AR_HTC_MSG_CONF_PIPE_RSP;
1128 mutex_exit(&usc->usc_msg_mtx);
1130 error = athn_usb_htc_msg(usc, AR_HTC_MSG_CONF_PIPE, &cfg, sizeof(cfg));
1133 aprint_error_dev(usc->usc_dev, "could not request pipe configurations\n");
1137 mutex_enter(&usc->usc_msg_mtx);
1138 error = athn_usb_wait_msg(usc);
1140 mutex_exit(&usc->usc_msg_mtx);
1144 mutex_exit(&usc->usc_msg_mtx);
1145 error = athn_usb_htc_msg(usc, AR_HTC_MSG_SETUP_COMPLETE, NULL, 0);
1147 aprint_error_dev(usc->usc_dev, "could not request complete setup\n");
1150 mutex_enter(&usc->usc_msg_mtx);
1151 error = athn_usb_wait_msg(usc);
1153 mutex_exit(&usc->usc_msg_mtx);
1157 usc->usc_htcactive = false;
1158 cv_broadcast(&usc->usc_htc_cv);
1159 mutex_exit(&usc->usc_msg_mtx);
1165 athn_usb_htc_connect_svc(struct athn_usb_softc *usc, uint16_t svc_id,
1172 DPRINTFN(DBG_FN, usc, "\n");
1179 mutex_enter(&usc->usc_msg_mtx);
1180 KASSERT(usc->usc_wait_msg_id == 0);
1181 usc->usc_msg_conn_svc_rsp = &rsp;
1182 usc->usc_wait_msg_id = AR_HTC_MSG_CONN_SVC_RSP;
1183 mutex_exit(&usc->usc_msg_mtx);
1185 error = athn_usb_htc_msg(usc, AR_HTC_MSG_CONN_SVC, &msg, sizeof(msg));
1187 mutex_enter(&usc->usc_msg_mtx);
1189 error = athn_usb_wait_msg(usc);
1191 mutex_exit(&usc->usc_msg_mtx);
1194 aprint_error_dev(usc->usc_dev,
1199 aprint_error_dev(usc->usc_dev,
1204 DPRINTFN(DBG_INIT, usc,
1214 athn_usb_wait_msg(struct athn_usb_softc *usc)
1216 DPRINTFN(DBG_FN, usc, "\n");
1218 KASSERT(mutex_owned(&usc->usc_msg_mtx));
1221 while (usc->usc_wait_msg_id)
1222 error = cv_timedwait(&usc->usc_msg_cv, &usc->usc_msg_mtx, hz);
1231 struct athn_usb_softc *usc = priv;
1233 DPRINTFN(DBG_FN, usc, "\n");
1236 usbd_clear_endpoint_stall_async(usc->usc_tx_intr_pipe);
1240 athn_usb_wmi_xcmd(struct athn_usb_softc *usc, uint16_t cmd_id, void *ibuf,
1243 struct athn_usb_tx_data *data = &usc->usc_tx_cmd;
1248 if (usc->usc_dying)
1251 DPRINTFN(DBG_FN, usc, "cmd_id %#x\n", cmd_id);
1255 htc->endpoint_id = usc->usc_ep_ctrl;
1260 usc->usc_wmi_seq_no++;
1261 wmi->seq_no = htobe16(usc->usc_wmi_seq_no);
1265 usbd_setup_xfer(data->xfer, usc, data->buf,
1270 mutex_enter(&usc->usc_cmd_mtx);
1271 while (usc->usc_wmiactive) {
1272 error = cv_timedwait(&usc->usc_wmi_cv, &usc->usc_cmd_mtx, hz);
1275 mutex_exit(&usc->usc_cmd_mtx);
1279 usc->usc_wmiactive = true;
1281 KASSERT(usc->usc_wait_cmd_id == 0);
1282 usc->usc_wait_cmd_id = cmd_id;
1283 usc->usc_obuf = obuf;
1284 mutex_exit(&usc->usc_cmd_mtx);
1288 DPRINTFN(DBG_FN, usc, "transfer error %d\n", error);
1293 mutex_enter(&usc->usc_cmd_mtx);
1294 while (usc->usc_wait_cmd_id)
1295 error = cv_timedwait(&usc->usc_cmd_cv, &usc->usc_cmd_mtx, hz);
1297 usc->usc_wmiactive = false;
1298 cv_broadcast(&usc->usc_wmi_cv);
1299 mutex_exit(&usc->usc_cmd_mtx);
1308 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1322 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_REG_READ,
1336 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1340 if (usc->usc_dying)
1349 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_REG_READ,
1363 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1365 if (usc->usc_dying)
1370 usc->usc_wbuf[usc->usc_wcount].addr = htobe32(addr);
1371 usc->usc_wbuf[usc->usc_wcount].val = htobe32(val);
1372 if (++usc->usc_wcount == AR_MAX_WRITE_COUNT)
1379 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1381 if (usc->usc_dying)
1384 DPRINTFN(DBG_FN, sc, "usc_wcount %d\n", usc->usc_wcount);
1386 if (usc->usc_wcount == 0)
1389 (void)athn_usb_wmi_xcmd(usc, AR_WMI_CMD_REG_WRITE,
1390 usc->usc_wbuf, usc->usc_wcount * sizeof(usc->usc_wbuf[0]), NULL);
1392 usc->usc_wcount = 0; /* Always flush buffer. */
1399 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1402 if (usc->usc_dying)
1420 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1428 athn_usb_do_async(usc, athn_usb_newstate_cb, &cmd, sizeof(cmd));
1433 athn_usb_newstate_cb(struct athn_usb_softc *usc, void *arg)
1436 struct athn_softc *sc = &usc->usc_sc;
1450 DPRINTFN(DBG_STM, usc, "newstate %s(%d) -> %s(%d)\n",
1458 DPRINTFN(DBG_NODES, usc, "removing node %u\n", sta_index);
1459 athn_usb_remove_hw_node(usc, &sta_index);
1470 if (!usc->usc_dying)
1488 athn_usb_create_node(usc, ic->ic_bss); /* XXX: handle error? */
1491 athn_usb_wmi_cmd(usc, AR_WMI_CMD_DISABLE_INTR);
1511 athn_usb_wmi_xcmd(usc, AR_WMI_CMD_ENABLE_INTR,
1515 if (!usc->usc_dying)
1525 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1534 athn_usb_do_async(usc, athn_usb_newassoc_cb, &ni, sizeof(ni));
1538 athn_usb_newassoc_cb(struct athn_usb_softc *usc, void *arg)
1543 DPRINTFN(DBG_FN, usc, "\n");
1548 DPRINTFN(DBG_NODES, usc, "creating node for AID=%#x\n",
1550 (void)athn_usb_create_node(usc, ni); /* XXX: handle error? */
1562 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1571 athn_usb_do_async(usc, athn_usb_ampdu_tx_start_cb, &cmd, sizeof(cmd));
1576 athn_usb_ampdu_tx_start_cb(struct athn_usb_softc *usc, void *arg)
1581 DPRINTFN(DBG_FN, usc, "\n");
1587 (void)athn_usb_wmi_xcmd(usc, AR_WMI_CMD_TX_AGGR_ENABLE,
1596 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1605 athn_usb_do_async(usc, athn_usb_ampdu_tx_stop_cb, &cmd, sizeof(cmd));
1609 athn_usb_ampdu_tx_stop_cb(struct athn_usb_softc *usc, void *arg)
1614 DPRINTFN(DBG_FN, usc, "\n");
1620 (void)athn_usb_wmi_xcmd(usc, AR_WMI_CMD_TX_AGGR_ENABLE,
1626 athn_usb_remove_hw_node(struct athn_usb_softc *usc, uint8_t *sta_idx)
1630 DPRINTFN(DBG_FN, usc, "\n");
1632 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_NODE_REMOVE,
1635 DPRINTFN(DBG_NODES, usc, "node=%u error=%d\n",
1641 athn_usb_create_hw_node(struct athn_usb_softc *usc,
1646 DPRINTFN(DBG_FN, usc, "\n");
1648 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_NODE_CREATE,
1651 DPRINTFN(DBG_NODES, usc, "node=%u error=%d\n",
1658 athn_usb_create_node(struct athn_usb_softc *usc, struct ieee80211_node *ni)
1665 DPRINTFN(DBG_FN | DBG_NODES, usc, "AID=%#x\n", ni->ni_associd);
1677 if (ATHN_SOFTC(usc)->sc_ic.ic_opmode == IEEE80211_M_HOSTAP)
1696 error = athn_usb_create_hw_node(usc, &sta);
1722 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_RC_RATE_UPDATE,
1741 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1748 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_DISABLE_INTR);
1752 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_DRAIN_TXQ_ALL);
1756 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_STOP_RECV);
1778 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_START_RECV);
1785 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_SET_MODE,
1791 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_ENABLE_INTR);
1800 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1805 athn_usb_do_async(usc, athn_usb_updateedca_cb, NULL, 0);
1809 athn_usb_updateedca_cb(struct athn_usb_softc *usc, void *arg)
1813 DPRINTFN(DBG_FN, usc, "\n");
1816 athn_updateedca(&usc->usc_sc.sc_ic);
1825 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1838 if (usc->usc_athn_attached)
1839 athn_usb_do_async(usc, athn_usb_updateslot_cb, NULL, 0);
1843 athn_usb_updateslot_cb(struct athn_usb_softc *usc, void *arg)
1847 DPRINTFN(DBG_FN, usc, "\n");
1850 athn_updateslot(&usc->usc_sc.sc_if);
1860 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1861 struct ifnet *ifp = &usc->usc_sc.sc_if;
1873 athn_usb_do_async(usc, athn_usb_set_key_cb, &cmd, sizeof(cmd));
1878 athn_usb_set_key_cb(struct athn_usb_softc *usc, void *arg)
1880 usc->usc_sc.sc_ic;
1884 DPRINTFN(DBG_FN, usc, "\n");
1898 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
1899 struct ifnet *ifp = &usc->usc_sc.sc_if;
1911 athn_usb_do_async(usc, athn_usb_delete_key_cb, &cmd, sizeof(cmd));
1915 athn_usb_delete_key_cb(struct athn_usb_softc *usc, void *arg)
1917 struct ieee80211com *ic = &usc->usc_sc.sc_ic;
1921 DPRINTFN(DBG_FN, usc, "\n");
1937 struct athn_usb_softc *usc = data->sc;
1939 DPRINTFN(DBG_FN, usc, "\n");
1942 usbd_clear_endpoint_stall_async(usc->usc_tx_data_pipe);
1943 usc->usc_tx_bcn = data;
1950 athn_usb_swba(struct athn_usb_softc *usc)
1952 struct athn_softc *sc = &usc->usc_sc;
1963 if (usc->usc_dying)
1974 if (usc->usc_tx_bcn == NULL)
1976 data = usc->usc_tx_bcn;
1998 htc->endpoint_id = usc->usc_ep_bcn;
2013 usc->usc_tx_bcn = NULL;
2016 usc->usc_tx_bcn = data;
2021 athn_usb_rx_wmi_ctrl(struct athn_usb_softc *usc, uint8_t *buf, size_t len)
2029 if (usc->usc_dying)
2032 DPRINTFN(DBG_FN, usc, "\n");
2040 mutex_enter(&usc->usc_cmd_mtx);
2041 if (usc->usc_wait_cmd_id == cmd_id) {
2043 if (usc->usc_obuf != NULL) {
2045 memcpy(usc->usc_obuf, &wmi[1], len - sizeof(*wmi));
2048 usc->usc_wait_cmd_id = 0;
2049 cv_broadcast(&usc->usc_cmd_cv);
2051 mutex_exit(&usc->usc_cmd_mtx);
2061 athn_usb_swba(usc);
2065 aprint_error_dev(usc->usc_dev, "fatal firmware error\n");
2070 DPRINTFN(DBG_TX, usc, "txrate=%d\n", be32toh(txrate->txrate));
2074 DPRINTFN(DBG_TX, usc, "WMI event %#x (%d) ignored\n", cmd_id, cmd_id);
2083 struct athn_usb_softc *usc = priv;
2086 uint8_t *buf = usc->usc_ibuf;
2090 if (usc->usc_dying)
2093 DPRINTFN(DBG_FN, usc, "\n");
2096 DPRINTFN(DBG_INTR, usc, "intr status=%d\n", status);
2098 usbd_clear_endpoint_stall_async(usc->usc_rx_intr_pipe);
2116 if (__predict_false(htc->endpoint_id != usc->usc_ep_ctrl)) {
2117 DPRINTFN(DBG_RX, usc, "Rx %d != %d\n",
2118 htc->endpoint_id, usc->usc_ep_ctrl);
2124 DPRINTFN(DBG_RX, usc, "Rx trailer %d < %d\n",
2130 athn_usb_rx_wmi_ctrl(usc, buf, len);
2141 DPRINTFN(DBG_RX, usc, "Rx HTC message %d\n", msg_id);
2145 mutex_enter(&usc->usc_msg_mtx);
2146 DPRINTFN(DBG_RX, usc, "AR_HTC_MSG_READY: %d vs %d\n",
2147 usc->usc_wait_msg_id, msg_id);
2148 if (usc->usc_wait_msg_id == msg_id) {
2149 usc->usc_wait_msg_id = 0;
2150 cv_broadcast(&usc->usc_msg_cv);
2152 mutex_exit(&usc->usc_msg_mtx);
2155 mutex_enter(&usc->usc_msg_mtx);
2156 DPRINTFN(DBG_RX, usc, "AR_HTC_MSG_CONN_SVC_RSP: %d vs %d\n",
2157 usc->usc_wait_msg_id, msg_id);
2158 if (usc->usc_wait_msg_id == msg_id) {
2159 if (usc->usc_msg_conn_svc_rsp != NULL) {
2160 memcpy(usc->usc_msg_conn_svc_rsp, &msg[1],
2161 sizeof(*usc->usc_msg_conn_svc_rsp));
2163 usc->usc_wait_msg_id = 0;
2164 cv_broadcast(&usc->usc_msg_cv);
2166 mutex_exit(&usc->usc_msg_mtx);
2169 DPRINTFN(DBG_RX, usc, "HTC message %d ignored\n", msg_id);
2224 athn_usb_rx_frame(struct athn_usb_softc *usc, struct mbuf *m)
2226 struct athn_softc *sc = &usc->usc_sc;
2305 struct athn_usb_softc *usc = data->sc;
2306 struct athn_usb_rx_stream *stream = &usc->usc_rx_stream;
2313 if (usc->usc_dying)
2316 DPRINTFN(DBG_FN, usc, "\n");
2319 DPRINTFN(DBG_RX, usc, "RX status=%d\n", status);
2321 usbd_clear_endpoint_stall_async(usc->usc_rx_data_pipe);
2334 athn_usb_rx_frame(usc, stream->m);
2357 DPRINTFN(DBG_RX, usc, "invalid tag %#x\n", hdr->tag);
2396 athn_usb_rx_frame(usc, m);
2417 struct athn_usb_softc *usc = data->sc;
2418 struct athn_softc *sc = &usc->usc_sc;
2422 if (usc->usc_dying)
2425 DPRINTFN(DBG_FN, usc, "\n");
2429 mutex_enter(&usc->usc_tx_mtx);
2430 TAILQ_INSERT_TAIL(&usc->usc_tx_free_list, data, next);
2431 mutex_exit(&usc->usc_tx_mtx);
2436 usbd_clear_endpoint_stall_async(usc->usc_tx_data_pipe);
2457 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
2517 htc->endpoint_id = usc->usc_ep_data[qid];
2536 htc->endpoint_id = usc->usc_ep_mgmt;
2570 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
2577 if (usc->usc_dying)
2587 mutex_enter(&usc->usc_tx_mtx);
2588 if (data == NULL && !TAILQ_EMPTY(&usc->usc_tx_free_list)) {
2589 data = TAILQ_FIRST(&usc->usc_tx_free_list);
2590 TAILQ_REMOVE(&usc->usc_tx_free_list, data, next);
2592 mutex_exit(&usc->usc_tx_mtx);
2651 mutex_enter(&usc->usc_tx_mtx);
2652 TAILQ_INSERT_TAIL(&usc->usc_tx_free_list, data, next);
2653 mutex_exit(&usc->usc_tx_mtx);
2681 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
2685 if (usc->usc_dying)
2738 mutex_enter(&usc->usc_lock);
2741 mutex_exit(&usc->usc_lock);
2752 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
2754 mutex_enter(&usc->usc_lock);
2756 mutex_exit(&usc->usc_lock);
2765 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
2777 if (usc->usc_dying)
2783 mutex_spin_enter(&usc->usc_task_mtx);
2784 usc->usc_cmdq.cur = usc->usc_cmdq.next = usc->usc_cmdq.queued = 0;
2785 mutex_spin_exit(&usc->usc_task_mtx);
2797 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_FLUSH_RECV);
2809 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_SET_MODE,
2814 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_ATH_INIT);
2818 error = athn_usb_wmi_cmd(usc, AR_WMI_CMD_START_RECV);
2849 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_VAP_CREATE,
2864 error = athn_usb_create_hw_node(usc, &sta);
2878 error = athn_usb_wmi_xcmd(usc, AR_WMI_CMD_TARGET_IC_UPDATE,
2886 data = &usc->usc_rx_data[i];
2915 athn_usb_wait_async(usc);
2926 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
2928 mutex_enter(&usc->usc_lock);
2930 mutex_exit(&usc->usc_lock);
2937 struct athn_usb_softc *usc = ATHN_USB_SOFTC(sc);
2948 athn_usb_wait_async(usc);
2959 usbd_abort_pipe(usc->usc_tx_data_pipe);
2960 usbd_abort_pipe(usc->usc_rx_data_pipe);
2964 m = atomic_swap_ptr(&usc->usc_rx_stream.m, NULL);
2966 usc->usc_rx_stream.left = 0;
2972 (void)athn_usb_wmi_xcmd(usc, AR_WMI_CMD_VAP_REMOVE,
2977 DPRINTFN(DBG_NODES, usc, "removing node %u\n", sta_index);
2978 (void)athn_usb_remove_hw_node(usc, &sta_index);
2980 (void)athn_usb_wmi_cmd(usc, AR_WMI_CMD_DISABLE_INTR);
2981 (void)athn_usb_wmi_cmd(usc, AR_WMI_CMD_DRAIN_TXQ_ALL);
2982 (void)athn_usb_wmi_cmd(usc, AR_WMI_CMD_STOP_RECV);