[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC][PATCH 11/13] Kemari: XenbusStateAttached handler for netback
This patch implements XenbusStateAttached handler for netback. The procedure is almost the same as blkback except that it handles both tx and rx back-end rings. Signed-off-by: Yoshi Tamura <tamura.yoshiaki@xxxxxxxxxxxxx> Signed-off-by: Yoshisato Yanagisawa <yanagisawa.yoshisato@xxxxxxxxxxxxx> --- drivers/xen/netback/common.h | 2 drivers/xen/netback/interface.c | 58 +++++++++++++++++++++ drivers/xen/netback/netback.c | 3 + drivers/xen/netback/xenbus.c | 109 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 172 insertions(+) diff -r e410857fd83c drivers/xen/netback/common.h --- a/drivers/xen/netback/common.h Wed Oct 22 14:55:29 2008 +0100 +++ b/drivers/xen/netback/common.h Thu Mar 05 09:55:23 2009 +0900 @@ -182,6 +182,8 @@ netif_t *netif_alloc(domid_t domid, unsigned int handle); int netif_map(netif_t *netif, unsigned long tx_ring_ref, unsigned long rx_ring_ref, unsigned int evtchn); +int netif_attach(netif_t *netif, unsigned long tx_ring_ref, + unsigned long rx_ring_ref, unsigned int evtchn); #define netif_get(_b) (atomic_inc(&(_b)->refcnt)) #define netif_put(_b) \ diff -r e410857fd83c drivers/xen/netback/interface.c --- a/drivers/xen/netback/interface.c Wed Oct 22 14:55:29 2008 +0100 +++ b/drivers/xen/netback/interface.c Thu Mar 05 09:55:23 2009 +0900 @@ -303,6 +303,64 @@ return err; } +int netif_attach(netif_t *netif, unsigned long tx_ring_ref, + unsigned long rx_ring_ref, unsigned int evtchn) +{ + int err = -ENOMEM; + netif_tx_sring_t *txs; + netif_rx_sring_t *rxs; + + /* Already connected through? */ + if (netif->irq) + return 0; + + netif->tx_comms_area = alloc_vm_area(PAGE_SIZE); + if (netif->tx_comms_area == NULL) + return -ENOMEM; + netif->rx_comms_area = alloc_vm_area(PAGE_SIZE); + if (netif->rx_comms_area == NULL) + goto err_rx; + + err = map_frontend_pages(netif, tx_ring_ref, rx_ring_ref); + if (err) + goto err_map; + + err = bind_interdomain_evtchn_to_irqhandler( + netif->domid, evtchn, netif_be_int, 0, + netif->dev->name, netif); + if (err < 0) + goto err_hypervisor; + netif->irq = err; + disable_irq(netif->irq); + + txs = (netif_tx_sring_t *)netif->tx_comms_area->addr; + BACK_RING_ATTACH(&netif->tx, txs, PAGE_SIZE); + + rxs = (netif_rx_sring_t *) + ((char *)netif->rx_comms_area->addr); + BACK_RING_ATTACH(&netif->rx, rxs, PAGE_SIZE); + + netif->rx.req_cons = netif->rx.sring->rsp_prod; + netif->rx_req_cons_peek = netif->rx.req_cons; + + netif_get(netif); + + rtnl_lock(); + netback_carrier_on(netif); + if (netif_running(netif->dev)) + __netif_up(netif); + rtnl_unlock(); + + return 0; +err_hypervisor: + unmap_frontend_pages(netif); +err_map: + free_vm_area(netif->rx_comms_area); +err_rx: + free_vm_area(netif->tx_comms_area); + return err; +} + void netif_disconnect(netif_t *netif) { if (netback_carrier_ok(netif)) { diff -r e410857fd83c drivers/xen/netback/netback.c --- a/drivers/xen/netback/netback.c Wed Oct 22 14:55:29 2008 +0100 +++ b/drivers/xen/netback/netback.c Thu Mar 05 09:55:23 2009 +0900 @@ -396,6 +396,9 @@ copy_gop->dest.offset = 0; copy_gop->dest.u.ref = req->gref; copy_gop->len = size; + if (req->gref == 0) + printk("did%d,gref%d,size%d,rc%lu,i%d\n", + netif->domid, req->gref, size, netif->rx.req_cons, i); } else { meta->copy = 0; if (!xen_feature(XENFEAT_auto_translated_physmap)) { diff -r e410857fd83c drivers/xen/netback/xenbus.c --- a/drivers/xen/netback/xenbus.c Wed Oct 22 14:55:29 2008 +0100 +++ b/drivers/xen/netback/xenbus.c Thu Mar 05 09:55:23 2009 +0900 @@ -30,7 +30,9 @@ static int connect_rings(struct backend_info *); +static int attach_rings(struct backend_info *); static void connect(struct backend_info *); +static void attach(struct backend_info *); static void backend_create_netif(struct backend_info *be); static int netback_remove(struct xenbus_device *dev) @@ -239,6 +241,12 @@ connect(be); break; + case XenbusStateAttached: + backend_create_netif(be); + if (be->netif) + attach(be); + break; + case XenbusStateClosing: if (be->netif) { kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE); @@ -347,6 +355,29 @@ netif_wake_queue(be->netif->dev); } +static void attach(struct backend_info *be) +{ + int err; + struct xenbus_device *dev = be->dev; + + err = attach_rings(be); + if (err) + return; + + err = xen_net_read_mac(dev, be->netif->fe_dev_addr); + if (err) { + xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename); + return; + } + + xen_net_read_rate(dev, &be->netif->credit_bytes, + &be->netif->credit_usec); + be->netif->remaining_credit = be->netif->credit_bytes; + + xenbus_switch_state(dev, XenbusStateAttached); + + netif_wake_queue(be->netif->dev); +} static int connect_rings(struct backend_info *be) { @@ -427,6 +458,84 @@ return 0; } +static int attach_rings(struct backend_info *be) +{ + struct xenbus_device *dev = be->dev; + unsigned long tx_ring_ref, rx_ring_ref; + unsigned int evtchn, rx_copy; + int err; + int val; + + DPRINTK(""); + + err = xenbus_gather(XBT_NIL, dev->otherend, + "tx-ring-ref", "%lu", &tx_ring_ref, + "rx-ring-ref", "%lu", &rx_ring_ref, + "event-channel", "%u", &evtchn, NULL); + if (err) { + xenbus_dev_fatal(dev, err, + "reading %s/ring-ref and event-channel", + dev->otherend); + return err; + } + + err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u", + &rx_copy); + if (err == -ENOENT) { + err = 0; + rx_copy = 0; + } + if (err < 0) { + xenbus_dev_fatal(dev, err, "reading %s/request-rx-copy", + dev->otherend); + return err; + } + be->netif->copying_receiver = !!rx_copy; + + if (be->netif->dev->tx_queue_len != 0) { + if (xenbus_scanf(XBT_NIL, dev->otherend, + "feature-rx-notify", "%d", &val) < 0) + val = 0; + if (val) + be->netif->can_queue = 1; + else + /* Must be non-zero for pfifo_fast to work. */ + be->netif->dev->tx_queue_len = 1; + } + + if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg", "%d", &val) < 0) + val = 0; + if (val) { + be->netif->features |= NETIF_F_SG; + be->netif->dev->features |= NETIF_F_SG; + } + + if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv4", "%d", + &val) < 0) + val = 0; + if (val) { + be->netif->features |= NETIF_F_TSO; + be->netif->dev->features |= NETIF_F_TSO; + } + + if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-no-csum-offload", + "%d", &val) < 0) + val = 0; + if (val) { + be->netif->features &= ~NETIF_F_IP_CSUM; + be->netif->dev->features &= ~NETIF_F_IP_CSUM; + } + + /* Map the shared frame, irq etc. */ + err = netif_attach(be->netif, tx_ring_ref, rx_ring_ref, evtchn); + if (err) { + xenbus_dev_fatal(dev, err, + "mapping shared-frames %lu/%lu port %u", + tx_ring_ref, rx_ring_ref, evtchn); + return err; + } + return 0; +} /* ** Driver Registration ** */ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |