Lines Matching refs:xnb
142 static void xnb_attach_failed(struct xnb_softc *xnb,
145 static int xnb_shutdown(struct xnb_softc *xnb);
541 struct xnb_softc const* xnb = (struct xnb_softc*)arg1; in xnb_dump_rings() local
543 &xnb->ring_configs[XNB_RING_TYPE_RX].back_ring.rx_ring; in xnb_dump_rings()
545 &xnb->ring_configs[XNB_RING_TYPE_TX].back_ring.tx_ring; in xnb_dump_rings()
618 xnb_free_communication_mem(struct xnb_softc *xnb) in xnb_free_communication_mem() argument
620 if (xnb->kva != 0) { in xnb_free_communication_mem()
621 if (xnb->pseudo_phys_res != NULL) { in xnb_free_communication_mem()
622 xenmem_free(xnb->dev, xnb->pseudo_phys_res_id, in xnb_free_communication_mem()
623 xnb->pseudo_phys_res); in xnb_free_communication_mem()
624 xnb->pseudo_phys_res = NULL; in xnb_free_communication_mem()
627 xnb->kva = 0; in xnb_free_communication_mem()
628 xnb->gnt_base_addr = 0; in xnb_free_communication_mem()
637 xnb_disconnect(struct xnb_softc *xnb) in xnb_disconnect() argument
643 if (xnb->xen_intr_handle != NULL) in xnb_disconnect()
644 xen_intr_unbind(&xnb->xen_intr_handle); in xnb_disconnect()
652 mtx_lock(&xnb->tx_lock); in xnb_disconnect()
653 mtx_unlock(&xnb->tx_lock); in xnb_disconnect()
654 mtx_lock(&xnb->rx_lock); in xnb_disconnect()
655 mtx_unlock(&xnb->rx_lock); in xnb_disconnect()
657 mtx_lock(&xnb->sc_lock); in xnb_disconnect()
659 if (xnb->bridge != NULL) { in xnb_disconnect()
660 free(xnb->bridge, M_XENSTORE); in xnb_disconnect()
661 xnb->bridge = NULL; in xnb_disconnect()
666 gnts[i].host_addr = xnb->ring_configs[i].gnt_addr; in xnb_disconnect()
667 gnts[i].dev_bus_addr = xnb->ring_configs[i].bus_addr; in xnb_disconnect()
668 gnts[i].handle = xnb->ring_configs[i].handle; in xnb_disconnect()
674 xnb_free_communication_mem(xnb); in xnb_disconnect()
679 bzero(&xnb->ring_configs[XNB_RING_TYPE_TX], in xnb_disconnect()
681 bzero(&xnb->ring_configs[XNB_RING_TYPE_RX], in xnb_disconnect()
684 xnb->flags &= ~XNBF_RING_CONNECTED; in xnb_disconnect()
685 mtx_unlock(&xnb->sc_lock); in xnb_disconnect()
699 xnb_connect_ring(struct xnb_softc *xnb, xnb_ring_type_t ring_type) in xnb_connect_ring() argument
702 struct xnb_ring_config *ring = &xnb->ring_configs[ring_type]; in xnb_connect_ring()
706 ring->va = xnb->kva + ring_type * PAGE_SIZE; in xnb_connect_ring()
707 ring->gnt_addr = xnb->gnt_base_addr + ring_type * PAGE_SIZE; in xnb_connect_ring()
712 gnt.dom = xnb->otherend_id; in xnb_connect_ring()
721 xenbus_dev_fatal(xnb->dev, error, in xnb_connect_ring()
737 xenbus_dev_fatal(xnb->dev, error, in xnb_connect_ring()
752 xnb_connect_comms(struct xnb_softc *xnb) in xnb_connect_comms() argument
757 if ((xnb->flags & XNBF_RING_CONNECTED) != 0) in xnb_connect_comms()
765 error = xnb_connect_ring(xnb, i); in xnb_connect_comms()
770 xnb->flags |= XNBF_RING_CONNECTED; in xnb_connect_comms()
772 error = xen_intr_bind_remote_port(xnb->dev, in xnb_connect_comms()
773 xnb->otherend_id, in xnb_connect_comms()
774 xnb->evtchn, in xnb_connect_comms()
776 xnb_intr, /*arg*/xnb, in xnb_connect_comms()
778 &xnb->xen_intr_handle); in xnb_connect_comms()
780 (void)xnb_disconnect(xnb); in xnb_connect_comms()
781 xenbus_dev_fatal(xnb->dev, error, "binding event channel"); in xnb_connect_comms()
801 xnb_alloc_communication_mem(struct xnb_softc *xnb) in xnb_alloc_communication_mem() argument
805 xnb->kva_size = 0; in xnb_alloc_communication_mem()
807 xnb->kva_size += xnb->ring_configs[i].ring_pages * PAGE_SIZE; in xnb_alloc_communication_mem()
817 xnb->pseudo_phys_res_id = 0; in xnb_alloc_communication_mem()
818 xnb->pseudo_phys_res = xenmem_alloc(xnb->dev, &xnb->pseudo_phys_res_id, in xnb_alloc_communication_mem()
819 xnb->kva_size); in xnb_alloc_communication_mem()
820 if (xnb->pseudo_phys_res == NULL) { in xnb_alloc_communication_mem()
821 xnb->kva = 0; in xnb_alloc_communication_mem()
824 xnb->kva = (vm_offset_t)rman_get_virtual(xnb->pseudo_phys_res); in xnb_alloc_communication_mem()
825 xnb->gnt_base_addr = rman_get_start(xnb->pseudo_phys_res); in xnb_alloc_communication_mem()
835 xnb_collect_xenstore_info(struct xnb_softc *xnb) in xnb_collect_xenstore_info() argument
848 otherend_path = xenbus_get_otherend_path(xnb->dev); in xnb_collect_xenstore_info()
849 our_path = xenbus_get_node(xnb->dev); in xnb_collect_xenstore_info()
854 &xnb->ring_configs[XNB_RING_TYPE_TX].ring_ref, in xnb_collect_xenstore_info()
856 &xnb->ring_configs[XNB_RING_TYPE_RX].ring_ref, in xnb_collect_xenstore_info()
857 "event-channel", "%" PRIu32, &xnb->evtchn, in xnb_collect_xenstore_info()
860 xenbus_dev_fatal(xnb->dev, err, in xnb_collect_xenstore_info()
868 err = xs_scanf(XST_NIL, our_path, "handle", NULL, "%li", &xnb->handle); in xnb_collect_xenstore_info()
870 xenbus_dev_fatal(xnb->dev, err, in xnb_collect_xenstore_info()
880 (void**)&xnb->bridge); in xnb_collect_xenstore_info()
882 xnb->bridge = NULL; in xnb_collect_xenstore_info()
895 xenbus_dev_fatal(xnb->dev, err, "reading %s/request-rx-copy", in xnb_collect_xenstore_info()
911 "%hhu", &xnb->can_sg) < 0) in xnb_collect_xenstore_info()
912 xnb->can_sg = 0; in xnb_collect_xenstore_info()
916 "%hhu", &xnb->gso) < 0) in xnb_collect_xenstore_info()
917 xnb->gso = 0; in xnb_collect_xenstore_info()
920 "%hhu", &xnb->gso_prefix) < 0) in xnb_collect_xenstore_info()
921 xnb->gso_prefix = 0; in xnb_collect_xenstore_info()
926 xnb->ip_csum = (no_csum_offload == 0); in xnb_collect_xenstore_info()
938 xnb_publish_backend_info(struct xnb_softc *xnb) in xnb_publish_backend_info() argument
944 our_path = xenbus_get_node(xnb->dev); in xnb_publish_backend_info()
949 xenbus_dev_fatal(xnb->dev, error, in xnb_publish_backend_info()
977 xenbus_dev_fatal(xnb->dev, error, "ending transaction"); in xnb_publish_backend_info()
993 xnb_connect(struct xnb_softc *xnb) in xnb_connect() argument
997 if (xenbus_get_state(xnb->dev) == XenbusStateConnected) in xnb_connect()
1000 if (xnb_collect_xenstore_info(xnb) != 0) in xnb_connect()
1003 xnb->flags &= ~XNBF_SHUTDOWN; in xnb_connect()
1008 error = xnb_alloc_communication_mem(xnb); in xnb_connect()
1010 xenbus_dev_fatal(xnb->dev, error, in xnb_connect()
1018 error = xnb_connect_comms(xnb); in xnb_connect()
1023 xnb->carrier = 1; in xnb_connect()
1026 xenbus_set_state(xnb->dev, XenbusStateConnected); in xnb_connect()
1040 xnb_shutdown(struct xnb_softc *xnb) in xnb_shutdown() argument
1049 if ((xnb->flags & XNBF_IN_SHUTDOWN) != 0) in xnb_shutdown()
1052 xnb->flags |= XNBF_SHUTDOWN; in xnb_shutdown()
1054 xnb->flags |= XNBF_IN_SHUTDOWN; in xnb_shutdown()
1056 mtx_unlock(&xnb->sc_lock); in xnb_shutdown()
1058 xnb->carrier = 0; in xnb_shutdown()
1059 if (xnb->xnb_ifp != NULL) { in xnb_shutdown()
1060 ether_ifdetach(xnb->xnb_ifp); in xnb_shutdown()
1061 if_free(xnb->xnb_ifp); in xnb_shutdown()
1062 xnb->xnb_ifp = NULL; in xnb_shutdown()
1065 xnb_disconnect(xnb); in xnb_shutdown()
1067 if (xenbus_get_state(xnb->dev) < XenbusStateClosing) in xnb_shutdown()
1068 xenbus_set_state(xnb->dev, XenbusStateClosing); in xnb_shutdown()
1069 mtx_lock(&xnb->sc_lock); in xnb_shutdown()
1071 xnb->flags &= ~XNBF_IN_SHUTDOWN; in xnb_shutdown()
1074 wakeup(xnb); in xnb_shutdown()
1088 xnb_attach_failed(struct xnb_softc *xnb, int err, const char *fmt, ...) in xnb_attach_failed() argument
1095 xs_vprintf(XST_NIL, xenbus_get_node(xnb->dev), in xnb_attach_failed()
1098 (void)xs_printf(XST_NIL, xenbus_get_node(xnb->dev), in xnb_attach_failed()
1101 xenbus_dev_vfatal(xnb->dev, err, fmt, ap); in xnb_attach_failed()
1104 (void)xs_printf(XST_NIL, xenbus_get_node(xnb->dev), "online", "0"); in xnb_attach_failed()
1105 xnb_detach(xnb->dev); in xnb_attach_failed()
1136 xnb_setup_sysctl(struct xnb_softc *xnb) in xnb_setup_sysctl() argument
1141 sysctl_ctx = device_get_sysctl_ctx(xnb->dev); in xnb_setup_sysctl()
1145 sysctl_tree = device_get_sysctl_tree(xnb->dev); in xnb_setup_sysctl()
1155 xnb, in xnb_setup_sysctl()
1166 xnb, in xnb_setup_sysctl()
1182 struct xnb_softc *xnb; in create_netdev() local
1186 xnb = device_get_softc(dev); in create_netdev()
1187 mtx_init(&xnb->sc_lock, "xnb_softc", "xen netback softc lock", MTX_DEF); in create_netdev()
1188 mtx_init(&xnb->tx_lock, "xnb_tx", "xen netback tx lock", MTX_DEF); in create_netdev()
1189 mtx_init(&xnb->rx_lock, "xnb_rx", "xen netback rx lock", MTX_DEF); in create_netdev()
1191 xnb->dev = dev; in create_netdev()
1193 ifmedia_init(&xnb->sc_media, 0, xnb_ifmedia_upd, xnb_ifmedia_sts); in create_netdev()
1194 ifmedia_add(&xnb->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL); in create_netdev()
1195 ifmedia_set(&xnb->sc_media, IFM_ETHER|IFM_MANUAL); in create_netdev()
1207 bzero(&xnb->mac[0], sizeof(xnb->mac)); in create_netdev()
1215 err = xs_scanf(XST_NIL, xenbus_get_node(xnb->dev), "handle", NULL, in create_netdev()
1219 snprintf(xnb->if_name, IFNAMSIZ, "xnb%" PRIu16 ".%" PRIu32, in create_netdev()
1224 ifp = xnb->xnb_ifp = if_alloc(IFT_ETHER); in create_netdev()
1225 if_setsoftc(ifp, xnb); in create_netdev()
1226 if_initname(ifp, xnb->if_name, IF_DUNIT_NONE); in create_netdev()
1238 ether_ifattach(ifp, xnb->mac); in create_netdev()
1239 xnb->carrier = 0; in create_netdev()
1255 struct xnb_softc *xnb; in xnb_attach() local
1272 xnb = device_get_softc(dev); in xnb_attach()
1273 xnb->otherend_id = xenbus_get_otherend_id(dev); in xnb_attach()
1275 xnb->ring_configs[i].ring_pages = 1; in xnb_attach()
1281 xnb_setup_sysctl(xnb); in xnb_attach()
1284 error = xs_printf(XST_NIL, xenbus_get_node(xnb->dev), in xnb_attach()
1287 xnb_attach_failed(xnb, error, "writing %s/hotplug-status", in xnb_attach()
1288 xenbus_get_node(xnb->dev)); in xnb_attach()
1292 if ((error = xnb_publish_backend_info(xnb)) != 0) { in xnb_attach()
1298 xnb_attach_failed(xnb, error, in xnb_attach()
1300 xenbus_get_node(xnb->dev)); in xnb_attach()
1326 struct xnb_softc *xnb; in xnb_detach() local
1330 xnb = device_get_softc(dev); in xnb_detach()
1331 mtx_lock(&xnb->sc_lock); in xnb_detach()
1332 while (xnb_shutdown(xnb) == EAGAIN) { in xnb_detach()
1333 msleep(xnb, &xnb->sc_lock, /*wakeup prio unchanged*/0, in xnb_detach()
1336 mtx_unlock(&xnb->sc_lock); in xnb_detach()
1339 mtx_destroy(&xnb->tx_lock); in xnb_detach()
1340 mtx_destroy(&xnb->rx_lock); in xnb_detach()
1341 mtx_destroy(&xnb->sc_lock); in xnb_detach()
1383 struct xnb_softc *xnb; in xnb_frontend_changed() local
1385 xnb = device_get_softc(dev); in xnb_frontend_changed()
1389 xenbus_strstate(xenbus_get_state(xnb->dev))); in xnb_frontend_changed()
1396 xnb_connect(xnb); in xnb_frontend_changed()
1400 mtx_lock(&xnb->sc_lock); in xnb_frontend_changed()
1401 xnb_shutdown(xnb); in xnb_frontend_changed()
1402 mtx_unlock(&xnb->sc_lock); in xnb_frontend_changed()
1404 xenbus_set_state(xnb->dev, XenbusStateClosed); in xnb_frontend_changed()
1407 xenbus_dev_fatal(xnb->dev, EINVAL, "saw state %d at frontend", in xnb_frontend_changed()
1425 struct xnb_softc *xnb; in xnb_intr() local
1430 xnb = (struct xnb_softc *)arg; in xnb_intr()
1431 ifp = xnb->xnb_ifp; in xnb_intr()
1432 txb = &xnb->ring_configs[XNB_RING_TYPE_TX].back_ring.tx_ring; in xnb_intr()
1434 mtx_lock(&xnb->tx_lock); in xnb_intr()
1444 err = xnb_recv(txb, xnb->otherend_id, &mbufc, ifp, in xnb_intr()
1445 xnb->tx_gnttab); in xnb_intr()
1450 if_input(xnb->xnb_ifp, mbufc); in xnb_intr()
1455 xen_intr_signal(xnb->xen_intr_handle); in xnb_intr()
1460 mtx_unlock(&xnb->tx_lock); in xnb_intr()
2188 xnb_stop(struct xnb_softc *xnb) in xnb_stop() argument
2192 mtx_assert(&xnb->sc_lock, MA_OWNED); in xnb_stop()
2193 ifp = xnb->xnb_ifp; in xnb_stop()
2201 struct xnb_softc *xnb = if_getsoftc(ifp); in xnb_ioctl() local
2210 mtx_lock(&xnb->sc_lock); in xnb_ioctl()
2212 xnb_ifinit_locked(xnb); in xnb_ioctl()
2215 xnb_stop(xnb); in xnb_ioctl()
2222 mtx_unlock(&xnb->sc_lock); in xnb_ioctl()
2226 mtx_lock(&xnb->sc_lock); in xnb_ioctl()
2240 mtx_unlock(&xnb->sc_lock); in xnb_ioctl()
2242 mtx_unlock(&xnb->sc_lock); in xnb_ioctl()
2250 mtx_lock(&xnb->sc_lock); in xnb_ioctl()
2288 mtx_unlock(&xnb->sc_lock); in xnb_ioctl()
2293 xnb_ifinit(xnb); in xnb_ioctl()
2300 error = ifmedia_ioctl(ifp, ifr, &xnb->sc_media, cmd); in xnb_ioctl()
2313 struct xnb_softc *xnb; in xnb_start_locked() local
2317 xnb = if_getsoftc(ifp); in xnb_start_locked()
2318 rxb = &xnb->ring_configs[XNB_RING_TYPE_RX].back_ring.rx_ring; in xnb_start_locked()
2320 if (!xnb->carrier) in xnb_start_locked()
2334 error = xnb_send(rxb, xnb->otherend_id, mbufc, in xnb_start_locked()
2335 xnb->rx_gnttab); in xnb_start_locked()
2370 xen_intr_signal(xnb->xen_intr_handle); in xnb_start_locked()
2417 struct xnb_softc *xnb; in xnb_start() local
2419 xnb = if_getsoftc(ifp); in xnb_start()
2420 mtx_lock(&xnb->rx_lock); in xnb_start()
2422 mtx_unlock(&xnb->rx_lock); in xnb_start()
2427 xnb_ifinit_locked(struct xnb_softc *xnb) in xnb_ifinit_locked() argument
2431 ifp = xnb->xnb_ifp; in xnb_ifinit_locked()
2433 mtx_assert(&xnb->sc_lock, MA_OWNED); in xnb_ifinit_locked()
2438 xnb_stop(xnb); in xnb_ifinit_locked()
2448 struct xnb_softc *xnb = xsc; in xnb_ifinit() local
2450 mtx_lock(&xnb->sc_lock); in xnb_ifinit()
2451 xnb_ifinit_locked(xnb); in xnb_ifinit()
2452 mtx_unlock(&xnb->sc_lock); in xnb_ifinit()
2498 DRIVER_MODULE(xnb, xenbusb_back, xnb_driver, 0, 0);