Lines Matching full:netdev
72 static void net_tx_response(struct XenNetDev *netdev, netif_tx_request_t *txp, int8_t st) in OBJECT_DECLARE_SIMPLE_TYPE()
74 RING_IDX i = netdev->tx_ring.rsp_prod_pvt; in OBJECT_DECLARE_SIMPLE_TYPE()
78 resp = RING_GET_RESPONSE(&netdev->tx_ring, i); in OBJECT_DECLARE_SIMPLE_TYPE()
84 RING_GET_RESPONSE(&netdev->tx_ring, ++i)->status = NETIF_RSP_NULL; in OBJECT_DECLARE_SIMPLE_TYPE()
88 netdev->tx_ring.rsp_prod_pvt = ++i; in OBJECT_DECLARE_SIMPLE_TYPE()
89 RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->tx_ring, notify); in OBJECT_DECLARE_SIMPLE_TYPE()
91 xen_device_notify_event_channel(XEN_DEVICE(netdev), in OBJECT_DECLARE_SIMPLE_TYPE()
92 netdev->event_channel, NULL); in OBJECT_DECLARE_SIMPLE_TYPE()
95 if (i == netdev->tx_ring.req_cons) { in OBJECT_DECLARE_SIMPLE_TYPE()
97 RING_FINAL_CHECK_FOR_REQUESTS(&netdev->tx_ring, more_to_do); in OBJECT_DECLARE_SIMPLE_TYPE()
99 netdev->tx_work++; in OBJECT_DECLARE_SIMPLE_TYPE()
104 static void net_tx_error(struct XenNetDev *netdev, netif_tx_request_t *txp, RING_IDX end) in net_tx_error() argument
111 RING_IDX cons = netdev->tx_ring.req_cons; in net_tx_error()
118 txp = RING_GET_REQUEST(&netdev->tx_ring, cons++); in net_tx_error()
120 netdev->tx_ring.req_cons = cons; in net_tx_error()
124 net_tx_response(netdev, txp, NETIF_RSP_ERROR); in net_tx_error()
128 static bool net_tx_packets(struct XenNetDev *netdev) in net_tx_packets() argument
139 rc = netdev->tx_ring.req_cons; in net_tx_packets()
140 rp = netdev->tx_ring.sring->req_prod; in net_tx_packets()
144 if (RING_REQUEST_CONS_OVERFLOW(&netdev->tx_ring, rc)) { in net_tx_packets()
147 memcpy(&txreq, RING_GET_REQUEST(&netdev->tx_ring, rc), sizeof(txreq)); in net_tx_packets()
148 netdev->tx_ring.req_cons = ++rc; in net_tx_packets()
156 netdev->dev); in net_tx_packets()
157 net_tx_error(netdev, &txreq, rc); in net_tx_packets()
162 netdev->dev); in net_tx_packets()
163 net_tx_error(netdev, &txreq, rc); in net_tx_packets()
170 netdev->dev, txreq.size); in net_tx_packets()
171 net_tx_error(netdev, &txreq, rc); in net_tx_packets()
177 netdev->dev); in net_tx_packets()
178 net_tx_error(netdev, &txreq, rc); in net_tx_packets()
182 trace_xen_netdev_tx(netdev->dev, txreq.gref, txreq.offset, in net_tx_packets()
189 page = xen_device_map_grant_refs(&netdev->xendev, &txreq.gref, 1, in net_tx_packets()
194 netdev->dev, txreq.gref); in net_tx_packets()
195 net_tx_error(netdev, &txreq, rc); in net_tx_packets()
205 qemu_send_packet(qemu_get_queue(netdev->nic), tmpbuf, in net_tx_packets()
208 qemu_send_packet(qemu_get_queue(netdev->nic), in net_tx_packets()
211 xen_device_unmap_grant_refs(&netdev->xendev, page, &txreq.gref, 1, in net_tx_packets()
213 net_tx_response(netdev, &txreq, NETIF_RSP_OKAY); in net_tx_packets()
215 if (!netdev->tx_work) { in net_tx_packets()
218 netdev->tx_work = 0; in net_tx_packets()
226 static void net_rx_response(struct XenNetDev *netdev, in net_rx_response() argument
231 RING_IDX i = netdev->rx_ring.rsp_prod_pvt; in net_rx_response()
235 resp = RING_GET_RESPONSE(&netdev->rx_ring, i); in net_rx_response()
244 trace_xen_netdev_rx(netdev->dev, i, resp->status, resp->flags); in net_rx_response()
246 netdev->rx_ring.rsp_prod_pvt = ++i; in net_rx_response()
247 RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->rx_ring, notify); in net_rx_response()
249 xen_device_notify_event_channel(XEN_DEVICE(netdev), in net_rx_response()
250 netdev->event_channel, NULL); in net_rx_response()
258 struct XenNetDev *netdev = qemu_get_nic_opaque(nc); in net_rx_packet() local
265 if (xen_device_backend_get_state(&netdev->xendev) != XenbusStateConnected) { in net_rx_packet()
269 rc = netdev->rx_ring.req_cons; in net_rx_packet()
270 rp = netdev->rx_ring.sring->req_prod; in net_rx_packet()
273 if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) { in net_rx_packet()
278 netdev->dev, (unsigned long)size, in net_rx_packet()
283 memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq)); in net_rx_packet()
284 netdev->rx_ring.req_cons = ++rc; in net_rx_packet()
286 page = xen_device_map_grant_refs(&netdev->xendev, &rxreq.gref, 1, in net_rx_packet()
291 netdev->dev, rxreq.gref); in net_rx_packet()
292 net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); in net_rx_packet()
296 xen_device_unmap_grant_refs(&netdev->xendev, page, &rxreq.gref, 1, NULL); in net_rx_packet()
297 net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0); in net_rx_packet()
313 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_realize() local
316 qemu_macaddr_default_if_unset(&netdev->conf.macaddr); in xen_netdev_realize()
319 netdev->conf.macaddr.a[0], in xen_netdev_realize()
320 netdev->conf.macaddr.a[1], in xen_netdev_realize()
321 netdev->conf.macaddr.a[2], in xen_netdev_realize()
322 netdev->conf.macaddr.a[3], in xen_netdev_realize()
323 netdev->conf.macaddr.a[4], in xen_netdev_realize()
324 netdev->conf.macaddr.a[5]); in xen_netdev_realize()
326 netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf, in xen_netdev_realize()
329 &xendev->qdev.mem_reentrancy_guard, netdev); in xen_netdev_realize()
331 nc = qemu_get_queue(netdev->nic); in xen_netdev_realize()
332 qemu_format_nic_info_str(nc, netdev->conf.macaddr.a); in xen_netdev_realize()
338 trace_xen_netdev_realize(netdev->dev, nc->info_str, nc->peer ? in xen_netdev_realize()
344 XenNetDev *netdev = XEN_NET_DEVICE(_xendev); in net_event() local
347 done_something = net_tx_packets(netdev); in net_event()
348 qemu_flush_queued_packets(qemu_get_queue(netdev->nic)); in net_event()
355 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_connect() local
361 &netdev->tx_ring_ref) != 1) { in xen_netdev_connect()
367 &netdev->rx_ring_ref) != 1) { in xen_netdev_connect()
387 netdev->txs = xen_device_map_grant_refs(xendev, in xen_netdev_connect()
388 &netdev->tx_ring_ref, 1, in xen_netdev_connect()
391 if (!netdev->txs) { in xen_netdev_connect()
396 netdev->rxs = xen_device_map_grant_refs(xendev, in xen_netdev_connect()
397 &netdev->rx_ring_ref, 1, in xen_netdev_connect()
400 if (!netdev->rxs) { in xen_netdev_connect()
405 BACK_RING_INIT(&netdev->tx_ring, netdev->txs, XEN_PAGE_SIZE); in xen_netdev_connect()
406 BACK_RING_INIT(&netdev->rx_ring, netdev->rxs, XEN_PAGE_SIZE); in xen_netdev_connect()
408 netdev->event_channel = xen_device_bind_event_channel(xendev, port, in xen_netdev_connect()
410 netdev, in xen_netdev_connect()
412 if (!netdev->event_channel) { in xen_netdev_connect()
416 trace_xen_netdev_connect(netdev->dev, netdev->tx_ring_ref, in xen_netdev_connect()
417 netdev->rx_ring_ref, port); in xen_netdev_connect()
419 net_tx_packets(netdev); in xen_netdev_connect()
425 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_disconnect() local
427 trace_xen_netdev_disconnect(netdev->dev); in xen_netdev_disconnect()
431 netdev->tx_ring.sring = NULL; in xen_netdev_disconnect()
432 netdev->rx_ring.sring = NULL; in xen_netdev_disconnect()
434 if (netdev->event_channel) { in xen_netdev_disconnect()
435 xen_device_unbind_event_channel(xendev, netdev->event_channel, in xen_netdev_disconnect()
437 netdev->event_channel = NULL; in xen_netdev_disconnect()
439 if (netdev->txs) { in xen_netdev_disconnect()
440 xen_device_unmap_grant_refs(xendev, netdev->txs, in xen_netdev_disconnect()
441 &netdev->tx_ring_ref, 1, errp); in xen_netdev_disconnect()
442 netdev->txs = NULL; in xen_netdev_disconnect()
444 if (netdev->rxs) { in xen_netdev_disconnect()
445 xen_device_unmap_grant_refs(xendev, netdev->rxs, in xen_netdev_disconnect()
446 &netdev->rx_ring_ref, 1, errp); in xen_netdev_disconnect()
447 netdev->rxs = NULL; in xen_netdev_disconnect()
509 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_get_name() local
511 if (netdev->dev == -1) { in xen_netdev_get_name()
525 netdev->dev = idx; in xen_netdev_get_name()
535 error_setg(errp, "cannot find device index for netdev device"); in xen_netdev_get_name()
539 return g_strdup_printf("%u", netdev->dev); in xen_netdev_get_name()
544 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_unrealize() local
546 trace_xen_netdev_unrealize(netdev->dev); in xen_netdev_unrealize()
551 if (netdev->nic) { in xen_netdev_unrealize()
552 qemu_del_nic(netdev->nic); in xen_netdev_unrealize()
651 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_net_device_destroy() local
653 trace_xen_netdev_destroy(netdev->dev); in xen_net_device_destroy()