Lines Matching +full:- +full:- +full:-

18  *  Contributions after 2012-01-13 are licensed under the terms of the
23 #include "qemu/main-loop.h"
26 #include "qemu/qemu-print.h"
38 #include "hw/xen/xen-backend.h"
39 #include "hw/xen/xen-bus-helper.h"
40 #include "hw/qdev-properties.h"
41 #include "hw/qdev-properties-system.h"
48 /* ------------------------------------------------------------- */
67 #define TYPE_XEN_NET_DEVICE "xen-net-device"
70 /* ------------------------------------------------------------- */ 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()
79 resp->id = txp->id; in OBJECT_DECLARE_SIMPLE_TYPE()
80 resp->status = st; in OBJECT_DECLARE_SIMPLE_TYPE()
83 if (txp->flags & NETTXF_extra_info) { 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()
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()
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()
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()
153 * feature-{sg,gso,whatelse} flags in xenstore (yet?) */ in net_tx_packets()
156 netdev->dev); in net_tx_packets()
162 netdev->dev); in net_tx_packets()
170 netdev->dev, txreq.size); in net_tx_packets()
177 netdev->dev); 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()
199 /* have read-only mapping -> can't fill checksum in-place */ 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()
215 if (!netdev->tx_work) { in net_tx_packets()
218 netdev->tx_work = 0; in net_tx_packets()
224 /* ------------------------------------------------------------- */
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()
236 resp->offset = offset; in net_rx_response()
237 resp->flags = flags; in net_rx_response()
238 resp->id = req->id; in net_rx_response()
239 resp->status = (int16_t)size; in net_rx_response()
241 resp->status = (int16_t)st; 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()
250 netdev->event_channel, NULL); in net_rx_response()
265 if (xen_device_backend_get_state(&netdev->xendev) != XenbusStateConnected) { in net_rx_packet()
266 return -1; 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()
276 if (size > XEN_PAGE_SIZE - NET_IP_ALIGN) { in net_rx_packet()
278 netdev->dev, (unsigned long)size, in net_rx_packet()
279 XEN_PAGE_SIZE - NET_IP_ALIGN); in net_rx_packet()
280 return -1; 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()
293 return -1; in net_rx_packet()
296 xen_device_unmap_grant_refs(&netdev->xendev, page, &rxreq.gref, 1, NULL); in net_rx_packet()
302 /* ------------------------------------------------------------- */
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()
328 DEVICE(xendev)->id, 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()
335 xen_device_backend_printf(xendev, "feature-rx-copy", "%u", 1); in xen_netdev_realize()
336 xen_device_backend_printf(xendev, "feature-rx-flip", "%u", 0); in xen_netdev_realize()
338 trace_xen_netdev_realize(netdev->dev, nc->info_str, nc->peer ? in xen_netdev_realize()
339 nc->peer->name : "(none)"); in xen_netdev_realize()
348 qemu_flush_queued_packets(qemu_get_queue(netdev->nic)); in net_event()
360 if (xen_device_frontend_scanf(xendev, "tx-ring-ref", "%u", in xen_netdev_connect()
361 &netdev->tx_ring_ref) != 1) { in xen_netdev_connect()
362 error_setg(errp, "failed to read tx-ring-ref"); in xen_netdev_connect()
366 if (xen_device_frontend_scanf(xendev, "rx-ring-ref", "%u", in xen_netdev_connect()
367 &netdev->rx_ring_ref) != 1) { in xen_netdev_connect()
368 error_setg(errp, "failed to read rx-ring-ref"); in xen_netdev_connect()
372 if (xen_device_frontend_scanf(xendev, "event-channel", "%u", in xen_netdev_connect()
374 error_setg(errp, "failed to read event-channel"); in xen_netdev_connect()
378 if (xen_device_frontend_scanf(xendev, "request-rx-copy", "%u", in xen_netdev_connect()
383 error_setg(errp, "frontend doesn't support rx-copy"); 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()
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()
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()
451 /* -------------------------------------------------------------------- */
461 trace_xen_netdev_frontend_changed(xendev->name, frontend_state); in xen_netdev_frontend_changed()
511 if (netdev->dev == -1) { in xen_netdev_get_name()
519 value = xs_node_read(xenbus->xsh, XBT_NULL, NULL, &local_err, in xen_netdev_get_name()
521 xendev->frontend_id, idx); 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()
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()
555 /* ------------------------------------------------------------- */
559 DEFINE_PROP_INT32("idx", XenNetDev, dev, -1),
567 xendev_class->backend = "qnic"; in xen_netdev_class_init()
568 xendev_class->device = "vif"; in xen_netdev_class_init()
569 xendev_class->get_name = xen_netdev_get_name; in xen_netdev_class_init()
570 xendev_class->realize = xen_netdev_realize; in xen_netdev_class_init()
571 xendev_class->frontend_changed = xen_netdev_frontend_changed; in xen_netdev_class_init()
572 xendev_class->unrealize = xen_netdev_unrealize; in xen_netdev_class_init()
573 set_bit(DEVICE_CATEGORY_NETWORK, dev_class->categories); in xen_netdev_class_init()
574 dev_class->user_creatable = true; in xen_netdev_class_init()
627 net->dev = number; in type_init()
628 memcpy(&net->conf.macaddr, &mac, sizeof(mac)); in type_init()
651 trace_xen_netdev_destroy(netdev->dev); in xen_net_device_destroy()