3 * Copyright (c) 2004-2006 Kip Macy
7 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
10 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
11 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
12 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
16 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 #include <sys/cdefs.h>
21 __FBSDID("$FreeBSD$");
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/sockio.h>
27 #include <sys/malloc.h>
28 #include <sys/kernel.h>
29 #include <sys/socket.h>
30 #include <sys/queue.h>
34 #include <net/if_arp.h>
35 #include <net/ethernet.h>
36 #include <net/if_dl.h>
37 #include <net/if_media.h>
41 #include <net/if_types.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/in.h>
46 #include <netinet/ip.h>
47 #include <netinet/if_ether.h>
52 #include <machine/clock.h> /* for DELAY */
53 #include <machine/bus.h>
54 #include <machine/resource.h>
55 #include <machine/frame.h>
56 #include <machine/vmparam.h>
61 #include <machine/intr_machdep.h>
63 #include <machine/xen/xen-os.h>
64 #include <machine/xen/hypervisor.h>
65 #include <machine/xen/xen_intr.h>
66 #include <machine/xen/evtchn.h>
67 #include <machine/xen/xenbus.h>
68 #include <xen/gnttab.h>
69 #include <xen/interface/memory.h>
70 #include <dev/xen/netfront/mbufq.h>
71 #include <machine/xen/features.h>
72 #include <xen/interface/io/netif.h>
75 #define GRANT_INVALID_REF 0
77 #define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
78 #define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
81 static int MODPARM_rx_copy = 0;
82 module_param_named(rx_copy, MODPARM_rx_copy, bool, 0);
83 MODULE_PARM_DESC(rx_copy, "Copy packets from network card (rather than flip)");
84 static int MODPARM_rx_flip = 0;
85 module_param_named(rx_flip, MODPARM_rx_flip, bool, 0);
86 MODULE_PARM_DESC(rx_flip, "Flip packets from network card (rather than copy)");
88 static const int MODPARM_rx_copy = 1;
89 static const int MODPARM_rx_flip = 0;
92 #define RX_COPY_THRESHOLD 256
94 #define net_ratelimit() 0
97 struct netfront_rx_info;
99 static void xn_txeof(struct netfront_info *);
100 static void xn_rxeof(struct netfront_info *);
101 static void network_alloc_rx_buffers(struct netfront_info *);
103 static void xn_tick_locked(struct netfront_info *);
104 static void xn_tick(void *);
106 static void xn_intr(void *);
107 static void xn_start_locked(struct ifnet *);
108 static void xn_start(struct ifnet *);
109 static int xn_ioctl(struct ifnet *, u_long, caddr_t);
110 static void xn_ifinit_locked(struct netfront_info *);
111 static void xn_ifinit(void *);
112 static void xn_stop(struct netfront_info *);
114 static void xn_watchdog(struct ifnet *);
117 static void show_device(struct netfront_info *sc);
119 static void netfront_closing(struct xenbus_device *dev);
121 static void netif_free(struct netfront_info *info);
122 static int netfront_remove(struct xenbus_device *dev);
124 static int talk_to_backend(struct xenbus_device *dev, struct netfront_info *info);
125 static int create_netdev(struct xenbus_device *dev, struct ifnet **ifp);
126 static void netif_disconnect_backend(struct netfront_info *info);
127 static int setup_device(struct xenbus_device *dev, struct netfront_info *info);
128 static void end_access(int ref, void *page);
130 /* Xenolinux helper functions */
131 static int network_connect(struct ifnet *ifp);
133 static void xn_free_rx_ring(struct netfront_info *);
135 static void xn_free_tx_ring(struct netfront_info *);
137 static int xennet_get_responses(struct netfront_info *np,
138 struct netfront_rx_info *rinfo, RING_IDX rp, struct mbuf **list,
139 int *pages_flipped_p);
141 #define virt_to_mfn(x) (vtomach(x) >> PAGE_SHIFT)
143 #define INVALID_P2M_ENTRY (~0UL)
146 * Mbuf pointers. We need these to keep track of the virtual addresses
147 * of our mbuf chains since we can only convert from virtual to physical,
148 * not the other way around. The size must track the free index arrays.
150 struct xn_chain_data {
151 struct mbuf *xn_tx_chain[NET_TX_RING_SIZE+1];
152 struct mbuf *xn_rx_chain[NET_RX_RING_SIZE+1];
156 struct net_device_stats
158 u_long rx_packets; /* total packets received */
159 u_long tx_packets; /* total packets transmitted */
160 u_long rx_bytes; /* total bytes received */
161 u_long tx_bytes; /* total bytes transmitted */
162 u_long rx_errors; /* bad packets received */
163 u_long tx_errors; /* packet transmit problems */
164 u_long rx_dropped; /* no space in linux buffers */
165 u_long tx_dropped; /* no space available in linux */
166 u_long multicast; /* multicast packets received */
169 /* detailed rx_errors: */
170 u_long rx_length_errors;
171 u_long rx_over_errors; /* receiver ring buff overflow */
172 u_long rx_crc_errors; /* recved pkt with crc error */
173 u_long rx_frame_errors; /* recv'd frame alignment error */
174 u_long rx_fifo_errors; /* recv'r fifo overrun */
175 u_long rx_missed_errors; /* receiver missed packet */
177 /* detailed tx_errors */
178 u_long tx_aborted_errors;
179 u_long tx_carrier_errors;
180 u_long tx_fifo_errors;
181 u_long tx_heartbeat_errors;
182 u_long tx_window_errors;
185 u_long rx_compressed;
186 u_long tx_compressed;
189 struct netfront_info {
191 struct ifnet *xn_ifp;
193 struct net_device_stats stats;
196 netif_tx_front_ring_t tx;
197 netif_rx_front_ring_t rx;
205 u_int copying_receiver;
208 /* Receive-ring batched refills. */
209 #define RX_MIN_TARGET 32
210 #define RX_MAX_TARGET NET_RX_RING_SIZE
211 int rx_min_target, rx_max_target, rx_target;
214 * {tx,rx}_skbs store outstanding skbuffs. The first entry in each
215 * array is an index into a chain of free entries.
218 grant_ref_t gref_tx_head;
219 grant_ref_t grant_tx_ref[NET_TX_RING_SIZE + 1];
220 grant_ref_t gref_rx_head;
221 grant_ref_t grant_rx_ref[NET_TX_RING_SIZE + 1];
223 #define TX_MAX_TARGET min(NET_RX_RING_SIZE, 256)
224 struct xenbus_device *xbdev;
227 uint8_t mac[ETHER_ADDR_LEN];
228 struct xn_chain_data xn_cdata; /* mbufs */
229 struct mbuf_head xn_rx_batch; /* head of the batch queue */
232 struct callout xn_stat_ch;
234 u_long rx_pfn_array[NET_RX_RING_SIZE];
235 multicall_entry_t rx_mcl[NET_RX_RING_SIZE+1];
236 mmu_update_t rx_mmu[NET_RX_RING_SIZE];
239 #define rx_mbufs xn_cdata.xn_rx_chain
240 #define tx_mbufs xn_cdata.xn_tx_chain
242 #define XN_LOCK_INIT(_sc, _name) \
243 mtx_init(&(_sc)->tx_lock, #_name"_tx", "network transmit lock", MTX_DEF); \
244 mtx_init(&(_sc)->rx_lock, #_name"_rx", "network receive lock", MTX_DEF); \
245 sx_init(&(_sc)->sc_lock, #_name"_rx")
247 #define XN_RX_LOCK(_sc) mtx_lock(&(_sc)->rx_lock)
248 #define XN_RX_UNLOCK(_sc) mtx_unlock(&(_sc)->rx_lock)
250 #define XN_TX_LOCK(_sc) mtx_lock(&(_sc)->tx_lock)
251 #define XN_TX_UNLOCK(_sc) mtx_unlock(&(_sc)->tx_lock)
253 #define XN_LOCK(_sc) sx_xlock(&(_sc)->sc_lock);
254 #define XN_UNLOCK(_sc) sx_xunlock(&(_sc)->sc_lock);
256 #define XN_LOCK_ASSERT(_sc) sx_assert(&(_sc)->sc_lock, SX_LOCKED);
257 #define XN_RX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->rx_lock, MA_OWNED);
258 #define XN_TX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->tx_lock, MA_OWNED);
259 #define XN_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->rx_lock); \
260 mtx_destroy(&(_sc)->tx_lock); \
261 sx_destroy(&(_sc)->sc_lock);
263 struct netfront_rx_info {
264 struct netif_rx_response rx;
265 struct netif_extra_info extras[XEN_NETIF_EXTRA_TYPE_MAX - 1];
268 #define netfront_carrier_on(netif) ((netif)->carrier = 1)
269 #define netfront_carrier_off(netif) ((netif)->carrier = 0)
270 #define netfront_carrier_ok(netif) ((netif)->carrier)
272 /* Access macros for acquiring freeing slots in xn_free_{tx,rx}_idxs[]. */
277 * Access macros for acquiring freeing slots in tx_skbs[].
281 add_id_to_freelist(struct mbuf **list, unsigned short id)
284 list[0] = (void *)(u_long)id;
287 static inline unsigned short
288 get_id_from_freelist(struct mbuf **list)
290 u_int id = (u_int)(u_long)list[0];
296 xennet_rxidx(RING_IDX idx)
298 return idx & (NET_RX_RING_SIZE - 1);
301 static inline struct mbuf *
302 xennet_get_rx_mbuf(struct netfront_info *np,
305 int i = xennet_rxidx(ri);
309 np->rx_mbufs[i] = NULL;
313 static inline grant_ref_t
314 xennet_get_rx_ref(struct netfront_info *np, RING_IDX ri)
316 int i = xennet_rxidx(ri);
317 grant_ref_t ref = np->grant_rx_ref[i];
318 np->grant_rx_ref[i] = GRANT_INVALID_REF;
325 #define IPRINTK(fmt, args...) \
326 printf("[XEN] " fmt, ##args)
327 #define WPRINTK(fmt, args...) \
328 printf("[XEN] " fmt, ##args)
329 #define DPRINTK(fmt, args...) \
330 printf("[XEN] " fmt, ##args)
333 static __inline struct mbuf*
334 makembuf (struct mbuf *buf)
336 struct mbuf *m = NULL;
338 MGETHDR (m, M_DONTWAIT, MT_DATA);
343 M_MOVE_PKTHDR(m, buf);
345 m_cljget(m, M_DONTWAIT, MJUMPAGESIZE);
346 m->m_pkthdr.len = buf->m_pkthdr.len;
347 m->m_len = buf->m_len;
348 m_copydata(buf, 0, buf->m_pkthdr.len, mtod(m,caddr_t) );
350 m->m_ext.ext_arg1 = (caddr_t *)(uintptr_t)(vtophys(mtod(m,caddr_t)) >> PAGE_SHIFT);
356 * Read the 'mac' node at the given device's node in the store, and parse that
357 * as colon-separated octets, placing result the given mac array. mac must be
358 * a preallocated array of length ETH_ALEN (as declared in linux/if_ether.h).
359 * Return 0 on success, or errno on error.
362 xen_net_read_mac(struct xenbus_device *dev, uint8_t mac[])
367 char *macstr = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL);
368 if (IS_ERR(macstr)) {
369 return PTR_ERR(macstr);
372 for (i = 0; i < ETHER_ADDR_LEN; i++) {
373 mac[i] = strtoul(s, &e, 16);
374 if (s == e || (e[0] != ':' && e[0] != 0)) {
375 free(macstr, M_DEVBUF);
380 free(macstr, M_DEVBUF);
385 * Entry point to this code when a new device is created. Allocate the basic
386 * structures and the ring buffers for communication with the backend, and
387 * inform the backend of the appropriate details for those. Switch to
391 netfront_probe(struct xenbus_device *dev, const struct xenbus_device_id *id)
395 struct netfront_info *info;
397 printf("netfront_probe() \n");
399 err = create_netdev(dev, &ifp);
401 xenbus_dev_fatal(dev, err, "creating netdev");
405 info = ifp->if_softc;
406 dev->dev_driver_data = info;
413 * We are reconnecting to the backend, due to a suspend/resume, or a backend
414 * driver restart. We tear down our netif structure and recreate it, but
415 * leave the device-layer structures intact so that this is transparent to the
416 * rest of the kernel.
419 netfront_resume(struct xenbus_device *dev)
421 struct netfront_info *info = dev->dev_driver_data;
423 DPRINTK("%s\n", dev->nodename);
425 netif_disconnect_backend(info);
430 /* Common code used when first setting up, and when resuming. */
432 talk_to_backend(struct xenbus_device *dev, struct netfront_info *info)
435 struct xenbus_transaction xbt;
438 err = xen_net_read_mac(dev, info->mac);
440 xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
444 /* Create shared ring, alloc event channel. */
445 err = setup_device(dev, info);
450 err = xenbus_transaction_start(&xbt);
452 xenbus_dev_fatal(dev, err, "starting transaction");
455 err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref","%u",
458 message = "writing tx ring-ref";
459 goto abort_transaction;
461 err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref","%u",
464 message = "writing rx ring-ref";
465 goto abort_transaction;
467 err = xenbus_printf(xbt, dev->nodename,
468 "event-channel", "%u", irq_to_evtchn_port(info->irq));
470 message = "writing event-channel";
471 goto abort_transaction;
473 err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
474 info->copying_receiver);
476 message = "writing request-rx-copy";
477 goto abort_transaction;
479 err = xenbus_printf(xbt, dev->nodename, "feature-rx-notify", "%d", 1);
481 message = "writing feature-rx-notify";
482 goto abort_transaction;
484 err = xenbus_printf(xbt, dev->nodename, "feature-no-csum-offload", "%d", 1);
486 message = "writing feature-no-csum-offload";
487 goto abort_transaction;
489 err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1);
491 message = "writing feature-sg";
492 goto abort_transaction;
495 err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1);
497 message = "writing feature-gso-tcpv4";
498 goto abort_transaction;
502 err = xenbus_transaction_end(xbt, 0);
506 xenbus_dev_fatal(dev, err, "completing transaction");
513 xenbus_transaction_end(xbt, 1);
514 xenbus_dev_fatal(dev, err, "%s", message);
523 setup_device(struct xenbus_device *dev, struct netfront_info *info)
525 netif_tx_sring_t *txs;
526 netif_rx_sring_t *rxs;
532 info->tx_ring_ref = GRANT_INVALID_REF;
533 info->rx_ring_ref = GRANT_INVALID_REF;
534 info->rx.sring = NULL;
535 info->tx.sring = NULL;
538 txs = (netif_tx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO);
541 xenbus_dev_fatal(dev, err, "allocating tx ring page");
544 SHARED_RING_INIT(txs);
545 FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
546 err = xenbus_grant_ring(dev, virt_to_mfn(txs));
549 info->tx_ring_ref = err;
551 rxs = (netif_rx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO);
554 xenbus_dev_fatal(dev, err, "allocating rx ring page");
557 SHARED_RING_INIT(rxs);
558 FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
560 err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
563 info->rx_ring_ref = err;
566 network_connect(ifp);
568 err = bind_listening_port_to_irqhandler(dev->otherend_id,
569 "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, NULL);
572 xenbus_dev_fatal(dev, err,
573 "bind_evtchn_to_irqhandler failed");
588 * Callback received when the backend's state changes.
591 backend_changed(struct xenbus_device *dev,
592 XenbusState backend_state)
594 struct netfront_info *sc = dev->dev_driver_data;
598 switch (backend_state) {
599 case XenbusStateInitialising:
600 case XenbusStateInitialised:
601 case XenbusStateConnected:
602 case XenbusStateUnknown:
603 case XenbusStateClosed:
604 case XenbusStateReconfigured:
605 case XenbusStateReconfiguring:
607 case XenbusStateInitWait:
608 if (dev->state != XenbusStateInitialising)
610 if (network_connect(sc->xn_ifp) != 0)
612 xenbus_switch_state(dev, XenbusStateConnected);
614 (void)send_fake_arp(netdev);
617 case XenbusStateClosing:
618 xenbus_frontend_closed(dev);
624 xn_free_rx_ring(struct netfront_info *sc)
629 for (i = 0; i < NET_RX_RING_SIZE; i++) {
630 if (sc->xn_cdata.xn_rx_chain[i] != NULL) {
631 m_freem(sc->xn_cdata.xn_rx_chain[i]);
632 sc->xn_cdata.xn_rx_chain[i] = NULL;
637 sc->xn_rx_if->req_prod = 0;
638 sc->xn_rx_if->event = sc->rx.rsp_cons ;
643 xn_free_tx_ring(struct netfront_info *sc)
648 for (i = 0; i < NET_TX_RING_SIZE; i++) {
649 if (sc->xn_cdata.xn_tx_chain[i] != NULL) {
650 m_freem(sc->xn_cdata.xn_tx_chain[i]);
651 sc->xn_cdata.xn_tx_chain[i] = NULL;
660 netfront_tx_slot_available(struct netfront_info *np)
662 return ((np->tx.req_prod_pvt - np->tx.rsp_cons) <
663 (TX_MAX_TARGET - /* MAX_SKB_FRAGS */ 24 - 2));
666 netif_release_tx_bufs(struct netfront_info *np)
671 for (i = 1; i <= NET_TX_RING_SIZE; i++) {
672 m = np->xn_cdata.xn_tx_chain[i];
674 if (((u_long)m) < KERNBASE)
676 gnttab_grant_foreign_access_ref(np->grant_tx_ref[i],
677 np->xbdev->otherend_id, virt_to_mfn(mtod(m, vm_offset_t)),
679 gnttab_release_grant_reference(&np->gref_tx_head,
680 np->grant_tx_ref[i]);
681 np->grant_tx_ref[i] = GRANT_INVALID_REF;
682 add_id_to_freelist(np->tx_mbufs, i);
688 network_alloc_rx_buffers(struct netfront_info *sc)
692 int i, batch_target, notify;
694 struct xen_memory_reservation reservation;
697 netif_rx_request_t *req;
701 req_prod = sc->rx.req_prod_pvt;
703 if (unlikely(sc->carrier == 0))
707 * Allocate skbuffs greedily, even though we batch updates to the
708 * receive ring. This creates a less bursty demand on the memory
709 * allocator, so should reduce the chance of failed allocation
710 * requests both for ourself and for other kernel subsystems.
712 batch_target = sc->rx_target - (req_prod - sc->rx.rsp_cons);
713 for (i = mbufq_len(&sc->xn_rx_batch); i < batch_target; i++) {
714 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
718 m_cljget(m_new, M_DONTWAIT, MJUMPAGESIZE);
719 if ((m_new->m_flags & M_EXT) == 0) {
730 m_new->m_len = m_new->m_pkthdr.len = MJUMPAGESIZE;
732 /* queue the mbufs allocated */
733 mbufq_tail(&sc->xn_rx_batch, m_new);
736 /* Is the batch large enough to be worthwhile? */
737 if (i < (sc->rx_target/2)) {
738 if (req_prod >sc->rx.sring->req_prod)
742 /* Adjust floating fill target if we risked running out of buffers. */
743 if ( ((req_prod - sc->rx.sring->rsp_prod) < (sc->rx_target / 4)) &&
744 ((sc->rx_target *= 2) > sc->rx_max_target) )
745 sc->rx_target = sc->rx_max_target;
748 for (nr_flips = i = 0; ; i++) {
749 if ((m_new = mbufq_dequeue(&sc->xn_rx_batch)) == NULL)
752 m_new->m_ext.ext_arg1 = (vm_paddr_t *)(uintptr_t)(
753 vtophys(m_new->m_ext.ext_buf) >> PAGE_SHIFT);
755 id = xennet_rxidx(req_prod + i);
757 KASSERT(sc->xn_cdata.xn_rx_chain[id] == NULL,
758 ("non-NULL xm_rx_chain"));
759 sc->xn_cdata.xn_rx_chain[id] = m_new;
761 ref = gnttab_claim_grant_reference(&sc->gref_rx_head);
762 KASSERT((short)ref >= 0, ("negative ref"));
763 sc->grant_rx_ref[id] = ref;
765 vaddr = mtod(m_new, vm_offset_t);
766 pfn = vtophys(vaddr) >> PAGE_SHIFT;
767 req = RING_GET_REQUEST(&sc->rx, req_prod + i);
769 if (sc->copying_receiver == 0) {
770 gnttab_grant_foreign_transfer_ref(ref,
771 sc->xbdev->otherend_id, pfn);
772 sc->rx_pfn_array[nr_flips] = PFNTOMFN(pfn);
773 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
774 /* Remove this page before passing
777 set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
778 MULTI_update_va_mapping(&sc->rx_mcl[i],
783 gnttab_grant_foreign_access_ref(ref,
784 sc->xbdev->otherend_id,
790 sc->rx_pfn_array[i] =
791 vtomach(mtod(m_new,vm_offset_t)) >> PAGE_SHIFT;
794 KASSERT(i, ("no mbufs processed")); /* should have returned earlier */
795 KASSERT(mbufq_len(&sc->xn_rx_batch) == 0, ("not all mbufs processed"));
797 * We may have allocated buffers which have entries outstanding
798 * in the page * update queue -- make sure we flush those first!
803 /* Tell the ballon driver what is going on. */
804 balloon_update_driver_allowance(i);
806 set_xen_guest_handle(reservation.extent_start, sc->rx_pfn_array);
807 reservation.nr_extents = i;
808 reservation.extent_order = 0;
809 reservation.address_bits = 0;
810 reservation.domid = DOMID_SELF;
812 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
814 /* After all PTEs have been zapped, flush the TLB. */
815 sc->rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] =
816 UVMF_TLB_FLUSH|UVMF_ALL;
818 /* Give away a batch of pages. */
819 sc->rx_mcl[i].op = __HYPERVISOR_memory_op;
820 sc->rx_mcl[i].args[0] = XENMEM_decrease_reservation;
821 sc->rx_mcl[i].args[1] = (u_long)&reservation;
822 /* Zap PTEs and give away pages in one big multicall. */
823 (void)HYPERVISOR_multicall(sc->rx_mcl, i+1);
825 /* Check return status of HYPERVISOR_dom_mem_op(). */
826 if (unlikely(sc->rx_mcl[i].result != i))
827 panic("Unable to reduce memory reservation\n");
829 if (HYPERVISOR_memory_op(
830 XENMEM_decrease_reservation, &reservation)
832 panic("Unable to reduce memory "
839 /* Above is a suitable barrier to ensure backend will see requests. */
840 sc->rx.req_prod_pvt = req_prod + i;
842 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&sc->rx, notify);
844 notify_remote_via_irq(sc->irq);
848 xn_rxeof(struct netfront_info *np)
851 struct netfront_rx_info rinfo;
852 struct netif_rx_response *rx = &rinfo.rx;
853 struct netif_extra_info *extras = rinfo.extras;
855 multicall_entry_t *mcl;
857 struct mbuf_head rxq, errq;
858 int err, pages_flipped = 0;
860 XN_RX_LOCK_ASSERT(np);
861 if (!netfront_carrier_ok(np))
869 rp = np->rx.sring->rsp_prod;
870 rmb(); /* Ensure we see queued responses up to 'rp'. */
874 memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx));
875 memset(extras, 0, sizeof(rinfo.extras));
878 err = xennet_get_responses(np, &rinfo, rp, &m,
883 mbufq_tail(&errq, m);
884 np->stats.rx_errors++;
889 m->m_pkthdr.rcvif = ifp;
890 if ( rx->flags & NETRXF_data_validated ) {
891 /* Tell the stack the checksums are okay */
893 * XXX this isn't necessarily the case - need to add
897 m->m_pkthdr.csum_flags |=
898 (CSUM_IP_CHECKED | CSUM_IP_VALID | CSUM_DATA_VALID
900 m->m_pkthdr.csum_data = 0xffff;
903 np->stats.rx_packets++;
904 np->stats.rx_bytes += m->m_pkthdr.len;
907 np->rx.rsp_cons = ++i;
911 /* Some pages are no longer absent... */
913 balloon_update_driver_allowance(-pages_flipped);
915 /* Do all the remapping work, and M->P updates, in one big
918 if (!!xen_feature(XENFEAT_auto_translated_physmap)) {
919 mcl = np->rx_mcl + pages_flipped;
920 mcl->op = __HYPERVISOR_mmu_update;
921 mcl->args[0] = (u_long)np->rx_mmu;
922 mcl->args[1] = pages_flipped;
924 mcl->args[3] = DOMID_SELF;
925 (void)HYPERVISOR_multicall(np->rx_mcl,
930 while ((m = mbufq_dequeue(&errq)))
934 * Process all the mbufs after the remapping is complete.
935 * Break the mbuf chain first though.
937 while ((m = mbufq_dequeue(&rxq)) != NULL) {
941 * Do we really need to drop the rx lock?
945 (*ifp->if_input)(ifp, m);
952 /* If we get a callback with very few responses, reduce fill target. */
953 /* NB. Note exponential increase, linear decrease. */
954 if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) >
955 ((3*np->rx_target) / 4)) && (--np->rx_target < np->rx_min_target))
956 np->rx_target = np->rx_min_target;
959 network_alloc_rx_buffers(np);
961 np->rx.sring->rsp_event = i + 1;
965 xn_txeof(struct netfront_info *np)
972 XN_TX_LOCK_ASSERT(np);
974 if (!netfront_carrier_ok(np))
981 prod = np->tx.sring->rsp_prod;
982 rmb(); /* Ensure we see responses up to 'rp'. */
984 for (i = np->tx.rsp_cons; i != prod; i++) {
985 id = RING_GET_RESPONSE(&np->tx, i)->id;
986 m = np->xn_cdata.xn_tx_chain[id];
989 KASSERT(m != NULL, ("mbuf not found in xn_tx_chain"));
991 if (unlikely(gnttab_query_foreign_access(
992 np->grant_tx_ref[id]) != 0)) {
993 printf("network_tx_buf_gc: warning "
994 "-- grant still in use by backend "
998 gnttab_end_foreign_access_ref(
999 np->grant_tx_ref[id]);
1000 gnttab_release_grant_reference(
1001 &np->gref_tx_head, np->grant_tx_ref[id]);
1002 np->grant_tx_ref[id] = GRANT_INVALID_REF;
1004 np->xn_cdata.xn_tx_chain[id] = NULL;
1005 add_id_to_freelist(np->xn_cdata.xn_tx_chain, id);
1008 np->tx.rsp_cons = prod;
1011 * Set a new event, then check for race with update of
1012 * tx_cons. Note that it is essential to schedule a
1013 * callback, no matter how few buffers are pending. Even if
1014 * there is space in the transmit ring, higher layers may
1015 * be blocked because too much data is outstanding: in such
1016 * cases notification from Xen is likely to be the only kick
1019 np->tx.sring->rsp_event =
1020 prod + ((np->tx.sring->req_prod - prod) >> 1) + 1;
1024 } while (prod != np->tx.sring->rsp_prod);
1028 ((np->tx.sring->req_prod - prod) < NET_TX_RING_SIZE)) {
1031 if (np->user_state == UST_OPEN)
1032 netif_wake_queue(dev);
1041 struct netfront_info *np = xsc;
1042 struct ifnet *ifp = np->xn_ifp;
1045 if (!(np->rx.rsp_cons != np->rx.sring->rsp_prod &&
1046 likely(netfront_carrier_ok(np)) &&
1047 ifp->if_drv_flags & IFF_DRV_RUNNING))
1050 if (np->tx.rsp_cons != np->tx.sring->rsp_prod) {
1060 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1061 !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1067 xennet_move_rx_slot(struct netfront_info *np, struct mbuf *m,
1070 int new = xennet_rxidx(np->rx.req_prod_pvt);
1072 KASSERT(np->rx_mbufs[new] == NULL, ("rx_mbufs != NULL"));
1073 np->rx_mbufs[new] = m;
1074 np->grant_rx_ref[new] = ref;
1075 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id = new;
1076 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->gref = ref;
1077 np->rx.req_prod_pvt++;
1081 xennet_get_extras(struct netfront_info *np,
1082 struct netif_extra_info *extras, RING_IDX rp)
1084 struct netif_extra_info *extra;
1085 RING_IDX cons = np->rx.rsp_cons;
1093 if (unlikely(cons + 1 == rp)) {
1095 if (net_ratelimit())
1096 WPRINTK("Missing extra info\n");
1102 extra = (struct netif_extra_info *)
1103 RING_GET_RESPONSE(&np->rx, ++cons);
1105 if (unlikely(!extra->type ||
1106 extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
1108 if (net_ratelimit())
1109 WPRINTK("Invalid extra type: %d\n",
1114 memcpy(&extras[extra->type - 1], extra, sizeof(*extra));
1117 m = xennet_get_rx_mbuf(np, cons);
1118 ref = xennet_get_rx_ref(np, cons);
1119 xennet_move_rx_slot(np, m, ref);
1120 } while (extra->flags & XEN_NETIF_EXTRA_FLAG_MORE);
1122 np->rx.rsp_cons = cons;
1127 xennet_get_responses(struct netfront_info *np,
1128 struct netfront_rx_info *rinfo, RING_IDX rp,
1130 int *pages_flipped_p)
1132 int pages_flipped = *pages_flipped_p;
1133 struct mmu_update *mmu;
1134 struct multicall_entry *mcl;
1135 struct netif_rx_response *rx = &rinfo->rx;
1136 struct netif_extra_info *extras = rinfo->extras;
1137 RING_IDX cons = np->rx.rsp_cons;
1138 struct mbuf *m, *m0, *m_prev;
1139 grant_ref_t ref = xennet_get_rx_ref(np, cons);
1140 int max = 5 /* MAX_SKB_FRAGS + (rx->status <= RX_COPY_THRESHOLD) */;
1145 m0 = m = m_prev = xennet_get_rx_mbuf(np, cons);
1148 if (rx->flags & NETRXF_extra_info) {
1149 err = xennet_get_extras(np, extras, rp);
1150 cons = np->rx.rsp_cons;
1155 m0->m_pkthdr.len = 0;
1163 printf("rx->status=%hd rx->offset=%hu frags=%u\n",
1164 rx->status, rx->offset, frags);
1166 if (unlikely(rx->status < 0 ||
1167 rx->offset + rx->status > PAGE_SIZE)) {
1169 if (net_ratelimit())
1170 WPRINTK("rx->offset: %x, size: %u\n",
1171 rx->offset, rx->status);
1173 xennet_move_rx_slot(np, m, ref);
1179 * This definitely indicates a bug, either in this driver or in
1180 * the backend driver. In future this should flag the bad
1181 * situation to the system controller to reboot the backed.
1183 if (ref == GRANT_INVALID_REF) {
1185 if (net_ratelimit())
1186 WPRINTK("Bad rx response id %d.\n", rx->id);
1192 if (!np->copying_receiver) {
1193 /* Memory pressure, insufficient buffer
1196 if (!(mfn = gnttab_end_foreign_transfer_ref(ref))) {
1197 if (net_ratelimit())
1198 WPRINTK("Unfulfilled rx req "
1199 "(id=%d, st=%d).\n",
1200 rx->id, rx->status);
1201 xennet_move_rx_slot(np, m, ref);
1206 if (!xen_feature( XENFEAT_auto_translated_physmap)) {
1207 /* Remap the page. */
1208 void *vaddr = mtod(m, void *);
1211 mcl = np->rx_mcl + pages_flipped;
1212 mmu = np->rx_mmu + pages_flipped;
1214 MULTI_update_va_mapping(mcl, (u_long)vaddr,
1215 (((vm_paddr_t)mfn) << PAGE_SHIFT) | PG_RW |
1216 PG_V | PG_M | PG_A, 0);
1217 pfn = (uint32_t)m->m_ext.ext_arg1;
1218 mmu->ptr = ((vm_paddr_t)mfn << PAGE_SHIFT) |
1219 MMU_MACHPHYS_UPDATE;
1222 set_phys_to_machine(pfn, mfn);
1226 ret = gnttab_end_foreign_access_ref(ref);
1227 KASSERT(ret, ("ret != 0"));
1230 gnttab_release_grant_reference(&np->gref_rx_head, ref);
1234 m->m_len = rx->status;
1235 m->m_data += rx->offset;
1236 m0->m_pkthdr.len += rx->status;
1239 if (!(rx->flags & NETRXF_more_data))
1242 if (cons + frags == rp) {
1243 if (net_ratelimit())
1244 WPRINTK("Need more frags\n");
1250 rx = RING_GET_RESPONSE(&np->rx, cons + frags);
1251 m = xennet_get_rx_mbuf(np, cons + frags);
1255 ref = xennet_get_rx_ref(np, cons + frags);
1260 if (unlikely(frags > max)) {
1261 if (net_ratelimit())
1262 WPRINTK("Too many frags\n");
1267 np->rx.rsp_cons = cons + frags;
1269 *pages_flipped_p = pages_flipped;
1275 xn_tick_locked(struct netfront_info *sc)
1277 XN_RX_LOCK_ASSERT(sc);
1278 callout_reset(&sc->xn_stat_ch, hz, xn_tick, sc);
1280 /* XXX placeholder for printing debug information */
1288 struct netfront_info *sc;
1297 xn_start_locked(struct ifnet *ifp)
1300 struct mbuf *m_head, *new_m;
1301 struct netfront_info *sc;
1302 netif_tx_request_t *tx;
1305 u_long mfn, tx_bytes;
1311 if (!netfront_carrier_ok(sc))
1314 for (i = sc->tx.req_prod_pvt; TRUE; i++) {
1315 IF_DEQUEUE(&ifp->if_snd, m_head);
1319 if (!netfront_tx_slot_available(sc)) {
1320 IF_PREPEND(&ifp->if_snd, m_head);
1321 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1325 id = get_id_from_freelist(sc->xn_cdata.xn_tx_chain);
1328 * Start packing the mbufs in this chain into
1329 * the fragment pointers. Stop when we run out
1330 * of fragments or hit the end of the mbuf chain.
1332 new_m = makembuf(m_head);
1333 tx = RING_GET_REQUEST(&sc->tx, i);
1335 ref = gnttab_claim_grant_reference(&sc->gref_tx_head);
1336 KASSERT((short)ref >= 0, ("Negative ref"));
1337 mfn = virt_to_mfn(mtod(new_m, vm_offset_t));
1338 gnttab_grant_foreign_access_ref(ref, sc->xbdev->otherend_id,
1339 mfn, GNTMAP_readonly);
1340 tx->gref = sc->grant_tx_ref[id] = ref;
1341 tx->size = new_m->m_pkthdr.len;
1343 tx->flags = (skb->ip_summed == CHECKSUM_HW) ? NETTXF_csum_blank : 0;
1346 new_m->m_next = NULL;
1347 new_m->m_nextpkt = NULL;
1351 sc->xn_cdata.xn_tx_chain[id] = new_m;
1352 BPF_MTAP(ifp, new_m);
1354 sc->stats.tx_bytes += new_m->m_pkthdr.len;
1355 sc->stats.tx_packets++;
1358 sc->tx.req_prod_pvt = i;
1359 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&sc->tx, notify);
1361 notify_remote_via_irq(sc->irq);
1365 if (RING_FULL(&sc->tx)) {
1368 netif_stop_queue(dev);
1376 xn_start(struct ifnet *ifp)
1378 struct netfront_info *sc;
1381 xn_start_locked(ifp);
1385 /* equivalent of network_open() in Linux */
1387 xn_ifinit_locked(struct netfront_info *sc)
1395 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1400 network_alloc_rx_buffers(sc);
1401 sc->rx.sring->rsp_event = sc->rx.rsp_cons + 1;
1403 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1404 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1406 callout_reset(&sc->xn_stat_ch, hz, xn_tick, sc);
1412 xn_ifinit(void *xsc)
1414 struct netfront_info *sc = xsc;
1417 xn_ifinit_locked(sc);
1424 xn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
1426 struct netfront_info *sc = ifp->if_softc;
1427 struct ifreq *ifr = (struct ifreq *) data;
1428 struct ifaddr *ifa = (struct ifaddr *)data;
1430 int mask, error = 0;
1435 if (ifa->ifa_addr->sa_family == AF_INET) {
1436 ifp->if_flags |= IFF_UP;
1437 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
1438 xn_ifinit_locked(sc);
1439 arp_ifinit(ifp, ifa);
1441 error = ether_ioctl(ifp, cmd, data);
1445 /* XXX can we alter the MTU on a VN ?*/
1447 if (ifr->ifr_mtu > XN_JUMBO_MTU)
1452 ifp->if_mtu = ifr->ifr_mtu;
1453 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1459 if (ifp->if_flags & IFF_UP) {
1461 * If only the state of the PROMISC flag changed,
1462 * then just use the 'set promisc mode' command
1463 * instead of reinitializing the entire NIC. Doing
1464 * a full re-init means reloading the firmware and
1465 * waiting for it to start up, which may take a
1469 /* No promiscuous mode with Xen */
1470 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1471 ifp->if_flags & IFF_PROMISC &&
1472 !(sc->xn_if_flags & IFF_PROMISC)) {
1473 XN_SETBIT(sc, XN_RX_MODE,
1474 XN_RXMODE_RX_PROMISC);
1475 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1476 !(ifp->if_flags & IFF_PROMISC) &&
1477 sc->xn_if_flags & IFF_PROMISC) {
1478 XN_CLRBIT(sc, XN_RX_MODE,
1479 XN_RXMODE_RX_PROMISC);
1482 xn_ifinit_locked(sc);
1484 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1488 sc->xn_if_flags = ifp->if_flags;
1493 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1494 if (mask & IFCAP_HWCSUM) {
1495 if (IFCAP_HWCSUM & ifp->if_capenable)
1496 ifp->if_capenable &= ~IFCAP_HWCSUM;
1498 ifp->if_capenable |= IFCAP_HWCSUM;
1505 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1518 error = ether_ioctl(ifp, cmd, data);
1525 xn_stop(struct netfront_info *sc)
1533 callout_stop(&sc->xn_stat_ch);
1535 xn_free_rx_ring(sc);
1536 xn_free_tx_ring(sc);
1538 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1541 /* START of Xenolinux helper functions adapted to FreeBSD */
1543 network_connect(struct ifnet *ifp)
1545 struct netfront_info *np;
1546 int i, requeue_idx, err;
1548 netif_rx_request_t *req;
1549 u_int feature_rx_copy, feature_rx_flip;
1551 printf("network_connect\n");
1554 err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1555 "feature-rx-copy", "%u", &feature_rx_copy);
1557 feature_rx_copy = 0;
1558 err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1559 "feature-rx-flip", "%u", &feature_rx_flip);
1561 feature_rx_flip = 1;
1564 * Copy packets on receive path if:
1565 * (a) This was requested by user, and the backend supports it; or
1566 * (b) Flipping was requested, but this is unsupported by the backend.
1568 np->copying_receiver = ((MODPARM_rx_copy && feature_rx_copy) ||
1569 (MODPARM_rx_flip && !feature_rx_flip));
1572 /* Recovery procedure: */
1573 err = talk_to_backend(np->xbdev, np);
1577 /* Step 1: Reinitialise variables. */
1578 netif_release_tx_bufs(np);
1580 /* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
1581 for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
1584 if (np->rx_mbufs[i] == NULL)
1587 m = np->rx_mbufs[requeue_idx] = xennet_get_rx_mbuf(np, i);
1588 ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i);
1589 req = RING_GET_REQUEST(&np->rx, requeue_idx);
1591 if (!np->copying_receiver) {
1592 gnttab_grant_foreign_transfer_ref(ref,
1593 np->xbdev->otherend_id,
1594 vtophys(mtod(m, vm_offset_t)));
1596 gnttab_grant_foreign_access_ref(ref,
1597 np->xbdev->otherend_id,
1598 vtophys(mtod(m, vm_offset_t)), 0);
1601 req->id = requeue_idx;
1606 np->rx.req_prod_pvt = requeue_idx;
1608 /* Step 3: All public and private state should now be sane. Get
1609 * ready to start sending and receiving packets and give the driver
1610 * domain a kick because we've probably just requeued some
1613 netfront_carrier_on(np);
1614 notify_remote_via_irq(np->irq);
1618 network_alloc_rx_buffers(np);
1626 show_device(struct netfront_info *sc)
1630 IPRINTK("<vif handle=%u %s(%s) evtchn=%u irq=%u tx=%p rx=%p>\n",
1632 be_state_name[sc->xn_backend_state],
1633 sc->xn_user_state ? "open" : "closed",
1639 IPRINTK("<vif NULL>\n");
1644 static int ifno = 0;
1646 /** Create a network device.
1647 * @param handle device handle
1650 create_netdev(struct xenbus_device *dev, struct ifnet **ifpp)
1653 struct netfront_info *np;
1657 np = (struct netfront_info *)malloc(sizeof(struct netfront_info),
1658 M_DEVBUF, M_NOWAIT);
1662 memset(np, 0, sizeof(struct netfront_info));
1666 XN_LOCK_INIT(np, xennetif);
1667 np->rx_target = RX_MIN_TARGET;
1668 np->rx_min_target = RX_MIN_TARGET;
1669 np->rx_max_target = RX_MAX_TARGET;
1671 /* Initialise {tx,rx}_skbs to be a free chain containing every entry. */
1672 for (i = 0; i <= NET_TX_RING_SIZE; i++) {
1673 np->tx_mbufs[i] = (void *) ((u_long) i+1);
1674 np->grant_tx_ref[i] = GRANT_INVALID_REF;
1676 for (i = 0; i <= NET_RX_RING_SIZE; i++) {
1677 np->rx_mbufs[i] = NULL;
1678 np->grant_rx_ref[i] = GRANT_INVALID_REF;
1680 /* A grant for every tx ring slot */
1681 if (gnttab_alloc_grant_references(TX_MAX_TARGET,
1682 &np->gref_tx_head) < 0) {
1683 printf("#### netfront can't alloc tx grant refs\n");
1687 /* A grant for every rx ring slot */
1688 if (gnttab_alloc_grant_references(RX_MAX_TARGET,
1689 &np->gref_rx_head) < 0) {
1690 printf("#### netfront can't alloc rx grant refs\n");
1691 gnttab_free_grant_references(np->gref_tx_head);
1696 err = xen_net_read_mac(dev, np->mac);
1698 xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
1702 /* Set up ifnet structure */
1703 *ifpp = ifp = np->xn_ifp = if_alloc(IFT_ETHER);
1705 if_initname(ifp, "xn", ifno++/* ifno */);
1706 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
1707 ifp->if_ioctl = xn_ioctl;
1708 ifp->if_output = ether_output;
1709 ifp->if_start = xn_start;
1711 ifp->if_watchdog = xn_watchdog;
1713 ifp->if_init = xn_ifinit;
1714 ifp->if_mtu = ETHERMTU;
1715 ifp->if_snd.ifq_maxlen = NET_TX_RING_SIZE - 1;
1718 ifp->if_hwassist = XN_CSUM_FEATURES;
1719 ifp->if_capabilities = IFCAP_HWCSUM;
1720 ifp->if_capenable = ifp->if_capabilities;
1723 ether_ifattach(ifp, np->mac);
1724 callout_init(&np->xn_stat_ch, CALLOUT_MPSAFE);
1725 netfront_carrier_off(np);
1730 gnttab_free_grant_references(np->gref_tx_head);
1732 panic("do something smart");
1737 * Handle the change of state of the backend to Closing. We must delete our
1738 * device-layer structures now, to ensure that writes are flushed through to
1739 * the backend. Once is this done, we can switch to Closed in
1743 static void netfront_closing(struct xenbus_device *dev)
1746 struct netfront_info *info = dev->dev_driver_data;
1748 DPRINTK("netfront_closing: %s removed\n", dev->nodename);
1752 xenbus_switch_state(dev, XenbusStateClosed);
1756 static int netfront_remove(struct xenbus_device *dev)
1758 struct netfront_info *info = dev->dev_driver_data;
1760 DPRINTK("%s\n", dev->nodename);
1763 free(info, M_DEVBUF);
1769 static void netif_free(struct netfront_info *info)
1771 netif_disconnect_backend(info);
1779 static void netif_disconnect_backend(struct netfront_info *info)
1782 end_access(info->tx_ring_ref, info->tx.sring);
1783 end_access(info->rx_ring_ref, info->rx.sring);
1784 info->tx_ring_ref = GRANT_INVALID_REF;
1785 info->rx_ring_ref = GRANT_INVALID_REF;
1786 info->tx.sring = NULL;
1787 info->rx.sring = NULL;
1791 unbind_from_irqhandler(info->irq, info->netdev);
1799 static void end_access(int ref, void *page)
1801 if (ref != GRANT_INVALID_REF)
1802 gnttab_end_foreign_access(ref, page);
1806 /* ** Driver registration ** */
1809 static struct xenbus_device_id netfront_ids[] = {
1815 static struct xenbus_driver netfront = {
1817 .ids = netfront_ids,
1818 .probe = netfront_probe,
1819 .remove = netfront_remove,
1820 .resume = netfront_resume,
1821 .otherend_changed = backend_changed,
1825 netif_init(void *unused)
1827 if (!is_running_on_xen())
1830 if (is_initial_xendomain())
1833 IPRINTK("Initialising virtual ethernet driver.\n");
1835 xenbus_register_frontend(&netfront);
1838 SYSINIT(xennetif, SI_SUB_PSEUDO, SI_ORDER_SECOND, netif_init, NULL);
1844 * c-set-style: "BSD"
1847 * indent-tabs-mode: t