Lines Matching +full:usb +full:- +full:attach

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
53 #include <dev/usb/usb.h>
54 #include <dev/usb/usbdi.h>
56 #include <dev/usb/usb_process.h>
57 #include <dev/usb/net/usb_ethernet.h>
60 "USB Ethernet parameters");
62 #define UE_LOCK(_ue) mtx_lock((_ue)->ue_mtx)
63 #define UE_UNLOCK(_ue) mtx_unlock((_ue)->ue_mtx)
64 #define UE_LOCK_ASSERT(_ue, t) mtx_assert((_ue)->ue_mtx, t)
66 MODULE_DEPEND(uether, usb, 1, 1, 1);
92 if (usb_proc_is_gone(&ue->ue_tq)) { in uether_pause()
96 usb_pause_mtx(ue->ue_mtx, _ticks); in uether_pause()
109 if (usb_proc_is_gone(&ue->ue_tq)) { in ue_queue_command()
118 usb_proc_msignal(&ue->ue_tq, t0, t1); in ue_queue_command()
121 task->hdr.pm_callback = fn; in ue_queue_command()
122 task->ue = ue; in ue_queue_command()
128 usb_proc_mwait(&ue->ue_tq, t0, t1); in ue_queue_command()
134 return (ue->ue_ifp); in uether_getifp()
140 return (device_get_softc(ue->ue_miibus)); in uether_getmii()
146 return (ue->ue_sc); in uether_getsc()
155 name = device_get_nameunit(ue->ue_dev); in ue_sysctl_parent()
165 if ((ue->ue_dev == NULL) || in uether_ifattach()
166 (ue->ue_udev == NULL) || in uether_ifattach()
167 (ue->ue_mtx == NULL) || in uether_ifattach()
168 (ue->ue_methods == NULL)) in uether_ifattach()
171 error = usb_proc_create(&ue->ue_tq, ue->ue_mtx, in uether_ifattach()
172 device_get_nameunit(ue->ue_dev), USB_PRI_MED); in uether_ifattach()
174 device_printf(ue->ue_dev, "could not setup taskqueue\n"); in uether_ifattach()
178 /* fork rest of the attach code */ in uether_ifattach()
181 &ue->ue_sync_task[0].hdr, in uether_ifattach()
182 &ue->ue_sync_task[1].hdr); in uether_ifattach()
194 usb_proc_mwait(&ue->ue_tq, in uether_ifattach_wait()
195 &ue->ue_sync_task[0].hdr, in uether_ifattach_wait()
196 &ue->ue_sync_task[1].hdr); in uether_ifattach_wait()
205 struct usb_ether *ue = task->ue; in ue_attach_post_task()
210 /* first call driver's post attach routine */ in ue_attach_post_task()
211 ue->ue_methods->ue_attach_post(ue); in ue_attach_post_task()
215 ue->ue_unit = alloc_unr(ueunit); in ue_attach_post_task()
216 usb_callout_init_mtx(&ue->ue_watchdog, ue->ue_mtx, 0); in ue_attach_post_task()
217 sysctl_ctx_init(&ue->ue_sysctl_ctx); in ue_attach_post_task()
218 mbufq_init(&ue->ue_rxq, 0 /* unlimited length */); in ue_attach_post_task()
224 if_initname(ifp, "ue", ue->ue_unit); in ue_attach_post_task()
225 if (ue->ue_methods->ue_attach_post_sub != NULL) { in ue_attach_post_task()
226 ue->ue_ifp = ifp; in ue_attach_post_task()
227 error = ue->ue_methods->ue_attach_post_sub(ue); in ue_attach_post_task()
230 if (ue->ue_methods->ue_ioctl != NULL) in ue_attach_post_task()
231 if_setioctlfn(ifp, ue->ue_methods->ue_ioctl); in ue_attach_post_task()
238 ue->ue_ifp = ifp; in ue_attach_post_task()
240 if (ue->ue_methods->ue_mii_upd != NULL && in ue_attach_post_task()
241 ue->ue_methods->ue_mii_sts != NULL) { in ue_attach_post_task()
243 error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, in ue_attach_post_task()
244 ue_ifmedia_upd, ue->ue_methods->ue_mii_sts, in ue_attach_post_task()
251 device_printf(ue->ue_dev, "attaching PHYs failed\n"); in ue_attach_post_task()
255 if_printf(ifp, "<USB Ethernet> on %s\n", device_get_nameunit(ue->ue_dev)); in ue_attach_post_task()
256 ether_ifattach(ifp, ue->ue_eaddr); in ue_attach_post_task()
263 snprintf(num, sizeof(num), "%u", ue->ue_unit); in ue_attach_post_task()
264 ue->ue_sysctl_oid = SYSCTL_ADD_NODE(&ue->ue_sysctl_ctx, in ue_attach_post_task()
267 SYSCTL_ADD_PROC(&ue->ue_sysctl_ctx, in ue_attach_post_task()
268 SYSCTL_CHILDREN(ue->ue_sysctl_oid), OID_AUTO, "%parent", in ue_attach_post_task()
279 mbufq_drain(&ue->ue_rxq); in ue_attach_post_task()
282 free_unr(ueunit, ue->ue_unit); in ue_attach_post_task()
283 if (ue->ue_ifp != NULL) { in ue_attach_post_task()
284 if_free(ue->ue_ifp); in ue_attach_post_task()
285 ue->ue_ifp = NULL; in ue_attach_post_task()
296 /* wait for any post attach or other command to complete */ in uether_ifdetach()
297 usb_proc_drain(&ue->ue_tq); in uether_ifdetach()
300 ifp = ue->ue_ifp; in uether_ifdetach()
309 usb_callout_drain(&ue->ue_watchdog); in uether_ifdetach()
313 * user-space: in uether_ifdetach()
319 bus_generic_detach(ue->ue_dev); in uether_ifdetach()
326 sysctl_ctx_free(&ue->ue_sysctl_ctx); in uether_ifdetach()
329 mbufq_drain(&ue->ue_rxq); in uether_ifdetach()
332 free_unr(ueunit, ue->ue_unit); in uether_ifdetach()
336 usb_proc_free(&ue->ue_tq); in uether_ifdetach()
342 return (usb_proc_is_gone(&ue->ue_tq)); in uether_is_gone()
359 &ue->ue_sync_task[0].hdr, in ue_init()
360 &ue->ue_sync_task[1].hdr); in ue_init()
369 struct usb_ether *ue = task->ue; in ue_start_task()
370 if_t ifp = ue->ue_ifp; in ue_start_task()
374 ue->ue_methods->ue_init(ue); in ue_start_task()
379 if (ue->ue_methods->ue_tick != NULL) in ue_start_task()
380 usb_callout_reset(&ue->ue_watchdog, hz, ue_watchdog, ue); in ue_start_task()
388 struct usb_ether *ue = task->ue; in ue_stop_task()
392 usb_callout_stop(&ue->ue_watchdog); in ue_stop_task()
394 ue->ue_methods->ue_stop(ue); in ue_stop_task()
413 ue->ue_methods->ue_start(ue); in ue_start()
422 struct usb_ether *ue = task->ue; in ue_promisc_task()
424 ue->ue_methods->ue_setpromisc(ue); in ue_promisc_task()
432 struct usb_ether *ue = task->ue; in ue_setmulti_task()
434 ue->ue_methods->ue_setmulti(ue); in ue_setmulti_task()
452 &ue->ue_media_task[0].hdr, in ue_ifmedia_upd()
453 &ue->ue_media_task[1].hdr); in ue_ifmedia_upd()
464 struct usb_ether *ue = task->ue; in ue_ifmedia_task()
465 if_t ifp = ue->ue_ifp; in ue_ifmedia_task()
467 ue->ue_methods->ue_mii_upd(ifp); in ue_ifmedia_task()
474 if_t ifp = ue->ue_ifp; in ue_watchdog()
480 &ue->ue_tick_task[0].hdr, in ue_watchdog()
481 &ue->ue_tick_task[1].hdr); in ue_watchdog()
483 usb_callout_reset(&ue->ue_watchdog, hz, ue_watchdog, ue); in ue_watchdog()
491 struct usb_ether *ue = task->ue; in ue_tick_task()
492 if_t ifp = ue->ue_ifp; in ue_tick_task()
497 ue->ue_methods->ue_tick(ue); in ue_tick_task()
514 &ue->ue_promisc_task[0].hdr, in uether_ioctl()
515 &ue->ue_promisc_task[1].hdr); in uether_ioctl()
518 &ue->ue_sync_task[0].hdr, in uether_ioctl()
519 &ue->ue_sync_task[1].hdr); in uether_ioctl()
522 &ue->ue_sync_task[0].hdr, in uether_ioctl()
523 &ue->ue_sync_task[1].hdr); in uether_ioctl()
531 &ue->ue_multi_task[0].hdr, in uether_ioctl()
532 &ue->ue_multi_task[1].hdr); in uether_ioctl()
537 if (ue->ue_miibus != NULL) { in uether_ioctl()
538 mii = device_get_softc(ue->ue_miibus); in uether_ioctl()
539 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); in uether_ioctl()
579 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; in uether_newbuf()
589 if_t ifp = ue->ue_ifp; in uether_rxmbuf()
595 m->m_pkthdr.rcvif = ifp; in uether_rxmbuf()
596 m->m_pkthdr.len = m->m_len = len; in uether_rxmbuf()
599 (void)mbufq_enqueue(&ue->ue_rxq, m); in uether_rxmbuf()
607 if_t ifp = ue->ue_ifp; in uether_rxbuf()
612 if (len < ETHER_HDR_LEN || len > MCLBYTES - ETHER_ALIGN) in uether_rxbuf()
625 m->m_pkthdr.rcvif = ifp; in uether_rxbuf()
626 m->m_pkthdr.len = m->m_len = len; in uether_rxbuf()
629 (void)mbufq_enqueue(&ue->ue_rxq, m); in uether_rxbuf()
636 if_t ifp = ue->ue_ifp; in uether_rxflush()
642 n = mbufq_flush(&ue->ue_rxq); in uether_rxflush()
647 m->m_nextpkt = NULL; in uether_rxflush()
655 * USB net drivers are run by DRIVER_MODULE() thus SI_SUB_DRIVERS,