Lines Matching refs: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()
354 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_connect() local
360 &netdev->tx_ring_ref) != 1) { in xen_netdev_connect()
366 &netdev->rx_ring_ref) != 1) { in xen_netdev_connect()
386 netdev->txs = xen_device_map_grant_refs(xendev, in xen_netdev_connect()
387 &netdev->tx_ring_ref, 1, in xen_netdev_connect()
390 if (!netdev->txs) { in xen_netdev_connect()
395 netdev->rxs = xen_device_map_grant_refs(xendev, in xen_netdev_connect()
396 &netdev->rx_ring_ref, 1, in xen_netdev_connect()
399 if (!netdev->rxs) { in xen_netdev_connect()
404 BACK_RING_INIT(&netdev->tx_ring, netdev->txs, XEN_PAGE_SIZE); in xen_netdev_connect()
405 BACK_RING_INIT(&netdev->rx_ring, netdev->rxs, XEN_PAGE_SIZE); in xen_netdev_connect()
407 netdev->event_channel = xen_device_bind_event_channel(xendev, port, in xen_netdev_connect()
409 netdev, in xen_netdev_connect()
411 if (!netdev->event_channel) { in xen_netdev_connect()
415 trace_xen_netdev_connect(netdev->dev, netdev->tx_ring_ref, in xen_netdev_connect()
416 netdev->rx_ring_ref, port); in xen_netdev_connect()
418 net_tx_packets(netdev); in xen_netdev_connect()
424 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_disconnect() local
426 trace_xen_netdev_disconnect(netdev->dev); in xen_netdev_disconnect()
430 netdev->tx_ring.sring = NULL; in xen_netdev_disconnect()
431 netdev->rx_ring.sring = NULL; in xen_netdev_disconnect()
433 if (netdev->event_channel) { in xen_netdev_disconnect()
434 xen_device_unbind_event_channel(xendev, netdev->event_channel, in xen_netdev_disconnect()
436 netdev->event_channel = NULL; in xen_netdev_disconnect()
438 if (netdev->txs) { in xen_netdev_disconnect()
439 xen_device_unmap_grant_refs(xendev, netdev->txs, in xen_netdev_disconnect()
440 &netdev->tx_ring_ref, 1, errp); in xen_netdev_disconnect()
441 netdev->txs = NULL; in xen_netdev_disconnect()
443 if (netdev->rxs) { in xen_netdev_disconnect()
444 xen_device_unmap_grant_refs(xendev, netdev->rxs, in xen_netdev_disconnect()
445 &netdev->rx_ring_ref, 1, errp); in xen_netdev_disconnect()
446 netdev->rxs = NULL; in xen_netdev_disconnect()
508 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_get_name() local
510 if (netdev->dev == -1) { in xen_netdev_get_name()
524 netdev->dev = idx; in xen_netdev_get_name()
538 return g_strdup_printf("%u", netdev->dev); in xen_netdev_get_name()
543 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_netdev_unrealize() local
545 trace_xen_netdev_unrealize(netdev->dev); in xen_netdev_unrealize()
550 if (netdev->nic) { in xen_netdev_unrealize()
551 qemu_del_nic(netdev->nic); in xen_netdev_unrealize()
650 XenNetDev *netdev = XEN_NET_DEVICE(xendev); in xen_net_device_destroy() local
652 trace_xen_netdev_destroy(netdev->dev); in xen_net_device_destroy()