Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Xenbus code for netif backend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2005 XenSource Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) static int connect_data_rings(struct backend_info *be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 			      struct xenvif_queue *queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) static void connect(struct backend_info *be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) static int read_xenbus_vif_flags(struct backend_info *be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) static int backend_create_xenvif(struct backend_info *be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) static void unregister_hotplug_status_watch(struct backend_info *be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) static void xen_unregister_watchers(struct xenvif *vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) static void set_backend_state(struct backend_info *be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 			      enum xenbus_state state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) struct dentry *xen_netback_dbg_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) static int xenvif_read_io_ring(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 	struct xenvif_queue *queue = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 	struct xen_netif_tx_back_ring *tx_ring = &queue->tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 	struct xen_netif_rx_back_ring *rx_ring = &queue->rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	struct netdev_queue *dev_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	if (tx_ring->sring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 		struct xen_netif_tx_sring *sring = tx_ring->sring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 		seq_printf(m, "Queue %d\nTX: nr_ents %u\n", queue->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 			   tx_ring->nr_ents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 		seq_printf(m, "req prod %u (%d) cons %u (%d) event %u (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 			   sring->req_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 			   sring->req_prod - sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 			   tx_ring->req_cons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 			   tx_ring->req_cons - sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 			   sring->req_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 			   sring->req_event - sring->rsp_prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 		seq_printf(m, "rsp prod %u (base) pvt %u (%d) event %u (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 			   sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 			   tx_ring->rsp_prod_pvt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 			   tx_ring->rsp_prod_pvt - sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 			   sring->rsp_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 			   sring->rsp_event - sring->rsp_prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		seq_printf(m, "pending prod %u pending cons %u nr_pending_reqs %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 			   queue->pending_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 			   queue->pending_cons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 			   nr_pending_reqs(queue));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 		seq_printf(m, "dealloc prod %u dealloc cons %u dealloc_queue %u\n\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 			   queue->dealloc_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 			   queue->dealloc_cons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			   queue->dealloc_prod - queue->dealloc_cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	if (rx_ring->sring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 		struct xen_netif_rx_sring *sring = rx_ring->sring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		seq_printf(m, "RX: nr_ents %u\n", rx_ring->nr_ents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		seq_printf(m, "req prod %u (%d) cons %u (%d) event %u (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 			   sring->req_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 			   sring->req_prod - sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 			   rx_ring->req_cons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 			   rx_ring->req_cons - sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 			   sring->req_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 			   sring->req_event - sring->rsp_prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 		seq_printf(m, "rsp prod %u (base) pvt %u (%d) event %u (%d)\n\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 			   sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 			   rx_ring->rsp_prod_pvt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 			   rx_ring->rsp_prod_pvt - sring->rsp_prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 			   sring->rsp_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 			   sring->rsp_event - sring->rsp_prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	seq_printf(m, "NAPI state: %lx NAPI weight: %d TX queue len %u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 		   "Credit timer_pending: %d, credit: %lu, usec: %lu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		   "remaining: %lu, expires: %lu, now: %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		   queue->napi.state, queue->napi.weight,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		   skb_queue_len(&queue->tx_queue),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 		   timer_pending(&queue->credit_timeout),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 		   queue->credit_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 		   queue->credit_usec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		   queue->remaining_credit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		   queue->credit_timeout.expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 		   jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	dev_queue = netdev_get_tx_queue(queue->vif->dev, queue->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	seq_printf(m, "\nRx internal queue: len %u max %u pkts %u %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		   queue->rx_queue_len, queue->rx_queue_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		   skb_queue_len(&queue->rx_queue),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 		   netif_tx_queue_stopped(dev_queue) ? "stopped" : "running");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define XENVIF_KICK_STR "kick"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define BUFFER_SIZE     32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) xenvif_write_io_ring(struct file *filp, const char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		     loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	struct xenvif_queue *queue =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 		((struct seq_file *)filp->private_data)->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	char write[BUFFER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	/* don't allow partial writes and check the length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	if (*ppos != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	if (count >= sizeof(write))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	len = simple_write_to_buffer(write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 				     sizeof(write) - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 				     ppos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 				     buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 				     count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	write[len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	if (!strncmp(write, XENVIF_KICK_STR, sizeof(XENVIF_KICK_STR) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		xenvif_interrupt(0, (void *)queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		pr_warn("Unknown command to io_ring_q%d. Available: kick\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 			queue->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		count = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static int xenvif_io_ring_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	void *queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	if (inode->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		queue = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	ret = single_open(filp, xenvif_read_io_ring, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	filp->f_mode |= FMODE_PWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) static const struct file_operations xenvif_dbg_io_ring_ops_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	.open = xenvif_io_ring_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	.write = xenvif_write_io_ring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static int xenvif_ctrl_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	struct xenvif *vif = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	xenvif_dump_hash_info(vif, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) DEFINE_SHOW_ATTRIBUTE(xenvif_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) static void xenvif_debugfs_addif(struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	vif->xenvif_dbg_root = debugfs_create_dir(vif->dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 						  xen_netback_dbg_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	for (i = 0; i < vif->num_queues; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		char filename[sizeof("io_ring_q") + 4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		snprintf(filename, sizeof(filename), "io_ring_q%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		debugfs_create_file(filename, 0600, vif->xenvif_dbg_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 				    &vif->queues[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 				    &xenvif_dbg_io_ring_ops_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	if (vif->ctrl_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		debugfs_create_file("ctrl", 0400, vif->xenvif_dbg_root, vif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 				    &xenvif_ctrl_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) static void xenvif_debugfs_delif(struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	debugfs_remove_recursive(vif->xenvif_dbg_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	vif->xenvif_dbg_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) #endif /* CONFIG_DEBUG_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  * Handle the creation of the hotplug script environment.  We add the script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)  * and vif variables to the environment, for the benefit of the vif-* hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)  * scripts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) static int netback_uevent(struct xenbus_device *xdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 			  struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	struct backend_info *be = dev_get_drvdata(&xdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	if (!be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	if (add_uevent_var(env, "script=%s", be->hotplug_script))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	if (!be->vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	return add_uevent_var(env, "vif=%s", be->vif->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) static int backend_create_xenvif(struct backend_info *be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	long handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	struct xenbus_device *dev = be->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	struct xenvif *vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	if (be->vif != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	if (err != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		xenbus_dev_fatal(dev, err, "reading handle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		return (err < 0) ? err : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	vif = xenvif_alloc(&dev->dev, dev->otherend_id, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	if (IS_ERR(vif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		err = PTR_ERR(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		xenbus_dev_fatal(dev, err, "creating interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	be->vif = vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	vif->be = be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) static void backend_disconnect(struct backend_info *be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	struct xenvif *vif = be->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if (vif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		unsigned int num_queues = vif->num_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		unsigned int queue_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		xen_unregister_watchers(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		xenbus_rm(XBT_NIL, be->dev->nodename, "hotplug-status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		xenvif_debugfs_delif(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) #endif /* CONFIG_DEBUG_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		xenvif_disconnect_data(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		/* At this point some of the handlers may still be active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		 * so we need to have additional synchronization here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		vif->num_queues = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		for (queue_index = 0; queue_index < num_queues; ++queue_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			xenvif_deinit_queue(&vif->queues[queue_index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		vfree(vif->queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		vif->queues = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		xenvif_disconnect_ctrl(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) static void backend_connect(struct backend_info *be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	if (be->vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		connect(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) static inline void backend_switch_state(struct backend_info *be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 					enum xenbus_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	struct xenbus_device *dev = be->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	pr_debug("%s -> %s\n", dev->nodename, xenbus_strstate(state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	be->state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	/* If we are waiting for a hotplug script then defer the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	 * actual xenbus state change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	if (!be->have_hotplug_status_watch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		xenbus_switch_state(dev, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) /* Handle backend state transitions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304)  * The backend state starts in Initialising and the following transitions are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305)  * allowed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)  * Initialising -> InitWait -> Connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308)  *          \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309)  *           \        ^    \         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310)  *            \       |     \        |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311)  *             \      |      \       |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312)  *              \     |       \      |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313)  *               \    |        \     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314)  *                \   |         \    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)  *                 V  |          V   V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)  *                  Closed  <-> Closing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319)  * The state argument specifies the eventual state of the backend and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320)  * function transitions to that state via the shortest path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) static void set_backend_state(struct backend_info *be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			      enum xenbus_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	while (be->state != state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		switch (be->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		case XenbusStateInitialising:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			case XenbusStateInitWait:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			case XenbusStateConnected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			case XenbusStateClosing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 				backend_switch_state(be, XenbusStateInitWait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			case XenbusStateClosed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 				backend_switch_state(be, XenbusStateClosed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 				BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		case XenbusStateClosed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 			case XenbusStateInitWait:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 			case XenbusStateConnected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 				backend_switch_state(be, XenbusStateInitWait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			case XenbusStateClosing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 				backend_switch_state(be, XenbusStateClosing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 				BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		case XenbusStateInitWait:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 			switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			case XenbusStateConnected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 				backend_connect(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 				backend_switch_state(be, XenbusStateConnected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			case XenbusStateClosing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 			case XenbusStateClosed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 				backend_switch_state(be, XenbusStateClosing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 				BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		case XenbusStateConnected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			case XenbusStateInitWait:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			case XenbusStateClosing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			case XenbusStateClosed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 				backend_disconnect(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 				backend_switch_state(be, XenbusStateClosing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 				BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		case XenbusStateClosing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			case XenbusStateInitWait:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 			case XenbusStateConnected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			case XenbusStateClosed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 				backend_switch_state(be, XenbusStateClosed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 				BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) static void read_xenbus_frontend_xdp(struct backend_info *be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 				      struct xenbus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	struct xenvif *vif = be->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	u16 headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	err = xenbus_scanf(XBT_NIL, dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			   "xdp-headroom", "%hu", &headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	if (err != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		vif->xdp_headroom = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	if (headroom > XEN_NETIF_MAX_XDP_HEADROOM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		headroom = XEN_NETIF_MAX_XDP_HEADROOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	vif->xdp_headroom = headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)  * Callback received when the frontend's state changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) static void frontend_changed(struct xenbus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 			     enum xenbus_state frontend_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	struct backend_info *be = dev_get_drvdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	pr_debug("%s -> %s\n", dev->otherend, xenbus_strstate(frontend_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	be->frontend_state = frontend_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	switch (frontend_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	case XenbusStateInitialising:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		set_backend_state(be, XenbusStateInitWait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	case XenbusStateInitialised:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	case XenbusStateConnected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		set_backend_state(be, XenbusStateConnected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	case XenbusStateReconfiguring:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		read_xenbus_frontend_xdp(be, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		xenbus_switch_state(dev, XenbusStateReconfigured);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	case XenbusStateClosing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		set_backend_state(be, XenbusStateClosing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	case XenbusStateClosed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		set_backend_state(be, XenbusStateClosed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		if (xenbus_dev_is_online(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		fallthrough;	/* if not online */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	case XenbusStateUnknown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		set_backend_state(be, XenbusStateClosed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		device_unregister(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				 frontend_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) static void xen_net_read_rate(struct xenbus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			      unsigned long *bytes, unsigned long *usec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	char *s, *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	unsigned long b, u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	char *ratestr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	/* Default to unlimited bandwidth. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	*bytes = ~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	*usec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	ratestr = xenbus_read(XBT_NIL, dev->nodename, "rate", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	if (IS_ERR(ratestr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	s = ratestr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	b = simple_strtoul(s, &e, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	if ((s == e) || (*e != ','))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	s = e + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	u = simple_strtoul(s, &e, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	if ((s == e) || (*e != '\0'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	*bytes = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	*usec = u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	kfree(ratestr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	pr_warn("Failed to parse network rate limit. Traffic unlimited.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	kfree(ratestr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	char *s, *e, *macstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	macstr = s = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if (IS_ERR(macstr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		return PTR_ERR(macstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	for (i = 0; i < ETH_ALEN; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		mac[i] = simple_strtoul(s, &e, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			kfree(macstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		s = e+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	kfree(macstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) static void xen_net_rate_changed(struct xenbus_watch *watch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 				 const char *path, const char *token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	struct xenvif *vif = container_of(watch, struct xenvif, credit_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	struct xenbus_device *dev = xenvif_to_xenbus_device(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	unsigned long   credit_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	unsigned long   credit_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	unsigned int queue_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	for (queue_index = 0; queue_index < vif->num_queues; queue_index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		struct xenvif_queue *queue = &vif->queues[queue_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		queue->credit_bytes = credit_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		queue->credit_usec = credit_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		if (!mod_timer_pending(&queue->credit_timeout, jiffies) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			queue->remaining_credit > queue->credit_bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			queue->remaining_credit = queue->credit_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) static int xen_register_credit_watch(struct xenbus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 				     struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	char *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	unsigned maxlen = strlen(dev->nodename) + sizeof("/rate");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	if (vif->credit_watch.node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		return -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	node = kmalloc(maxlen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	snprintf(node, maxlen, "%s/rate", dev->nodename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	vif->credit_watch.node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	vif->credit_watch.will_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	vif->credit_watch.callback = xen_net_rate_changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	err = register_xenbus_watch(&vif->credit_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		pr_err("Failed to set watcher %s\n", vif->credit_watch.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		vif->credit_watch.node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		vif->credit_watch.will_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		vif->credit_watch.callback = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) static void xen_unregister_credit_watch(struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	if (vif->credit_watch.node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		unregister_xenbus_watch(&vif->credit_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		kfree(vif->credit_watch.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		vif->credit_watch.node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) static void xen_mcast_ctrl_changed(struct xenbus_watch *watch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 				   const char *path, const char *token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	struct xenvif *vif = container_of(watch, struct xenvif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 					  mcast_ctrl_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	struct xenbus_device *dev = xenvif_to_xenbus_device(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	vif->multicast_control = !!xenbus_read_unsigned(dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 					"request-multicast-control", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) static int xen_register_mcast_ctrl_watch(struct xenbus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 					 struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	char *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	unsigned maxlen = strlen(dev->otherend) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		sizeof("/request-multicast-control");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	if (vif->mcast_ctrl_watch.node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		pr_err_ratelimited("Watch is already registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		return -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	node = kmalloc(maxlen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	if (!node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		pr_err("Failed to allocate memory for watch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	snprintf(node, maxlen, "%s/request-multicast-control",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		 dev->otherend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	vif->mcast_ctrl_watch.node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	vif->mcast_ctrl_watch.will_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	vif->mcast_ctrl_watch.callback = xen_mcast_ctrl_changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	err = register_xenbus_watch(&vif->mcast_ctrl_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		pr_err("Failed to set watcher %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		       vif->mcast_ctrl_watch.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		vif->mcast_ctrl_watch.node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		vif->mcast_ctrl_watch.will_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		vif->mcast_ctrl_watch.callback = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) static void xen_unregister_mcast_ctrl_watch(struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	if (vif->mcast_ctrl_watch.node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		unregister_xenbus_watch(&vif->mcast_ctrl_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		kfree(vif->mcast_ctrl_watch.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		vif->mcast_ctrl_watch.node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) static void xen_register_watchers(struct xenbus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 				  struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	xen_register_credit_watch(dev, vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	xen_register_mcast_ctrl_watch(dev, vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) static void xen_unregister_watchers(struct xenvif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	xen_unregister_mcast_ctrl_watch(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	xen_unregister_credit_watch(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) static void unregister_hotplug_status_watch(struct backend_info *be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (be->have_hotplug_status_watch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		unregister_xenbus_watch(&be->hotplug_status_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		kfree(be->hotplug_status_watch.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	be->have_hotplug_status_watch = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) static void hotplug_status_changed(struct xenbus_watch *watch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 				   const char *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 				   const char *token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	struct backend_info *be = container_of(watch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 					       struct backend_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 					       hotplug_status_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	str = xenbus_read(XBT_NIL, be->dev->nodename, "hotplug-status", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	if (IS_ERR(str))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	if (len == sizeof("connected")-1 && !memcmp(str, "connected", len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		/* Complete any pending state change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		xenbus_switch_state(be->dev, be->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		/* Not interested in this watch anymore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		unregister_hotplug_status_watch(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	kfree(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) static int connect_ctrl_ring(struct backend_info *be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	struct xenbus_device *dev = be->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	struct xenvif *vif = be->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	grant_ref_t ring_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	unsigned int evtchn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	err = xenbus_scanf(XBT_NIL, dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			   "ctrl-ring-ref", "%u", &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		goto done; /* The frontend does not have a control ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	ring_ref = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	err = xenbus_scanf(XBT_NIL, dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			   "event-channel-ctrl", "%u", &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		xenbus_dev_fatal(dev, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 				 "reading %s/event-channel-ctrl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 				 dev->otherend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	evtchn = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	err = xenvif_connect_ctrl(vif, ring_ref, evtchn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		xenbus_dev_fatal(dev, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 				 "mapping shared-frame %u port %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 				 ring_ref, evtchn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) static void connect(struct backend_info *be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	struct xenbus_device *dev = be->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	unsigned long credit_bytes, credit_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	unsigned int queue_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	unsigned int requested_num_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	struct xenvif_queue *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	/* Check whether the frontend requested multiple queues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	 * and read the number requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	requested_num_queues = xenbus_read_unsigned(dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 					"multi-queue-num-queues", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	if (requested_num_queues > xenvif_max_queues) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		/* buggy or malicious guest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		xenbus_dev_fatal(dev, -EINVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 				 "guest requested %u queues, exceeding the maximum of %u.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 				 requested_num_queues, xenvif_max_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	xen_unregister_watchers(be->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	xen_register_watchers(dev, be->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	read_xenbus_vif_flags(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	err = connect_ctrl_ring(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		xenbus_dev_fatal(dev, err, "connecting control ring");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	/* Use the number of queues requested by the frontend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	be->vif->queues = vzalloc(array_size(requested_num_queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 					     sizeof(struct xenvif_queue)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	if (!be->vif->queues) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		xenbus_dev_fatal(dev, -ENOMEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 				 "allocating queues");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	be->vif->num_queues = requested_num_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	be->vif->stalled_queues = requested_num_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	for (queue_index = 0; queue_index < requested_num_queues; ++queue_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		queue = &be->vif->queues[queue_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		queue->vif = be->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		queue->id = queue_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		snprintf(queue->name, sizeof(queue->name), "%s-q%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 				be->vif->dev->name, queue->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		err = xenvif_init_queue(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 			/* xenvif_init_queue() cleans up after itself on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 			 * failure, but we need to clean up any previously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			 * initialised queues. Set num_queues to i so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			 * earlier queues can be destroyed using the regular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			 * disconnect logic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			be->vif->num_queues = queue_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		queue->credit_bytes = credit_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		queue->remaining_credit = credit_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		queue->credit_usec = credit_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		err = connect_data_rings(be, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 			/* connect_data_rings() cleans up after itself on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			 * failure, but we need to clean up after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			 * xenvif_init_queue() here, and also clean up any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			 * previously initialised queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			xenvif_deinit_queue(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 			be->vif->num_queues = queue_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	xenvif_debugfs_addif(be->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) #endif /* CONFIG_DEBUG_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	/* Initialisation completed, tell core driver the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	 * active queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	netif_set_real_num_tx_queues(be->vif->dev, requested_num_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	netif_set_real_num_rx_queues(be->vif->dev, requested_num_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	xenvif_carrier_on(be->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	unregister_hotplug_status_watch(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 				   hotplug_status_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 				   "%s/%s", dev->nodename, "hotplug-status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		be->have_hotplug_status_watch = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	netif_tx_wake_all_queues(be->vif->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (be->vif->num_queues > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		xenvif_disconnect_data(be->vif); /* Clean up existing queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		xenvif_deinit_queue(&be->vif->queues[queue_index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	vfree(be->vif->queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	be->vif->queues = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	be->vif->num_queues = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	xenvif_disconnect_ctrl(be->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) static int connect_data_rings(struct backend_info *be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			      struct xenvif_queue *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	struct xenbus_device *dev = be->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	unsigned int num_queues = queue->vif->num_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	unsigned long tx_ring_ref, rx_ring_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	unsigned int tx_evtchn, rx_evtchn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	char *xspath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	size_t xspathsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	const size_t xenstore_path_ext_size = 11; /* sufficient for "/queue-NNN" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	/* If the frontend requested 1 queue, or we have fallen back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	 * to single queue due to lack of frontend support for multi-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	 * queue, expect the remaining XenStore keys in the toplevel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	 * directory. Otherwise, expect them in a subdirectory called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	 * queue-N.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	if (num_queues == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		xspath = kzalloc(strlen(dev->otherend) + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		if (!xspath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			xenbus_dev_fatal(dev, -ENOMEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 					 "reading ring references");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		strcpy(xspath, dev->otherend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		xspathsize = strlen(dev->otherend) + xenstore_path_ext_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		xspath = kzalloc(xspathsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		if (!xspath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 			xenbus_dev_fatal(dev, -ENOMEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 					 "reading ring references");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		snprintf(xspath, xspathsize, "%s/queue-%u", dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			 queue->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	err = xenbus_gather(XBT_NIL, xspath,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			    "tx-ring-ref", "%lu", &tx_ring_ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 			    "rx-ring-ref", "%lu", &rx_ring_ref, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		xenbus_dev_fatal(dev, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 				 "reading %s/ring-ref",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 				 xspath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	/* Try split event channels first, then single event channel. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	err = xenbus_gather(XBT_NIL, xspath,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 			    "event-channel-tx", "%u", &tx_evtchn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			    "event-channel-rx", "%u", &rx_evtchn, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		err = xenbus_scanf(XBT_NIL, xspath,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 				   "event-channel", "%u", &tx_evtchn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 			xenbus_dev_fatal(dev, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 					 "reading %s/event-channel(-tx/rx)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 					 xspath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		rx_evtchn = tx_evtchn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	/* Map the shared frame, irq etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	err = xenvif_connect_data(queue, tx_ring_ref, rx_ring_ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 				  tx_evtchn, rx_evtchn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		xenbus_dev_fatal(dev, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 				 "mapping shared-frames %lu/%lu port tx %u rx %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 				 tx_ring_ref, rx_ring_ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 				 tx_evtchn, rx_evtchn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) err: /* Regular return falls through with err == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	kfree(xspath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) static int read_xenbus_vif_flags(struct backend_info *be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	struct xenvif *vif = be->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	struct xenbus_device *dev = be->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	unsigned int rx_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			   &rx_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	if (err == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		rx_copy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		xenbus_dev_fatal(dev, err, "reading %s/request-rx-copy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 				 dev->otherend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	if (!rx_copy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (!xenbus_read_unsigned(dev->otherend, "feature-rx-notify", 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		/* - Reduce drain timeout to poll more frequently for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		 *   Rx requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		 * - Disable Rx stall detection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		be->vif->drain_timeout = msecs_to_jiffies(30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		be->vif->stall_timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	vif->can_sg = !!xenbus_read_unsigned(dev->otherend, "feature-sg", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	vif->gso_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv4", 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		vif->gso_mask |= GSO_BIT(TCPV4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv6", 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		vif->gso_mask |= GSO_BIT(TCPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	vif->ip_csum = !xenbus_read_unsigned(dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 					     "feature-no-csum-offload", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	vif->ipv6_csum = !!xenbus_read_unsigned(dev->otherend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 						"feature-ipv6-csum-offload", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	read_xenbus_frontend_xdp(be, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) static int netback_remove(struct xenbus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	struct backend_info *be = dev_get_drvdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	unregister_hotplug_status_watch(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	if (be->vif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		backend_disconnect(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		xenvif_free(be->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		be->vif = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	kfree(be->hotplug_script);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	kfree(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	dev_set_drvdata(&dev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)  * Entry point to this code when a new device is created.  Allocate the basic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)  * structures and switch to InitWait.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static int netback_probe(struct xenbus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 			 const struct xenbus_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	const char *message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	struct xenbus_transaction xbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	int sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	const char *script;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	struct backend_info *be = kzalloc(sizeof(*be), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (!be) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		xenbus_dev_fatal(dev, -ENOMEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 				 "allocating backend structure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	be->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	dev_set_drvdata(&dev->dev, be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	sg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		err = xenbus_transaction_start(&xbt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 			xenbus_dev_fatal(dev, err, "starting transaction");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			message = "writing feature-sg";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 				    "%d", sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			message = "writing feature-gso-tcpv4";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 				    "%d", sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			message = "writing feature-gso-tcpv6";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		/* We support partial checksum setup for IPv6 packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		err = xenbus_printf(xbt, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 				    "feature-ipv6-csum-offload",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 				    "%d", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 			message = "writing feature-ipv6-csum-offload";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		/* We support rx-copy path. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		err = xenbus_printf(xbt, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 				    "feature-rx-copy", "%d", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 			message = "writing feature-rx-copy";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		/* we can adjust a headroom for netfront XDP processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		err = xenbus_printf(xbt, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 				    "feature-xdp-headroom", "%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 				    provides_xdp_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 			message = "writing feature-xdp-headroom";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		/* We don't support rx-flip path (except old guests who
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		 * don't grok this feature flag).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		err = xenbus_printf(xbt, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 				    "feature-rx-flip", "%d", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 			message = "writing feature-rx-flip";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		/* We support dynamic multicast-control. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		err = xenbus_printf(xbt, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 				    "feature-multicast-control", "%d", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 			message = "writing feature-multicast-control";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		err = xenbus_printf(xbt, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 				    "feature-dynamic-multicast-control",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 				    "%d", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			message = "writing feature-dynamic-multicast-control";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 			goto abort_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		err = xenbus_transaction_end(xbt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	} while (err == -EAGAIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		xenbus_dev_fatal(dev, err, "completing transaction");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	/* Split event channels support, this is optional so it is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	 * put inside the above loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	err = xenbus_printf(XBT_NIL, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			    "feature-split-event-channels",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 			    "%u", separate_tx_rx_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		pr_debug("Error writing feature-split-event-channels\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	/* Multi-queue support: This is an optional feature. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	err = xenbus_printf(XBT_NIL, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 			    "multi-queue-max-queues", "%u", xenvif_max_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		pr_debug("Error writing multi-queue-max-queues\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	err = xenbus_printf(XBT_NIL, dev->nodename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			    "feature-ctrl-ring",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 			    "%u", true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		pr_debug("Error writing feature-ctrl-ring\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	backend_switch_state(be, XenbusStateInitWait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	script = xenbus_read(XBT_NIL, dev->nodename, "script", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	if (IS_ERR(script)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		err = PTR_ERR(script);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		xenbus_dev_fatal(dev, err, "reading script");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	be->hotplug_script = script;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	/* This kicks hotplug scripts, so do it immediately. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	err = backend_create_xenvif(be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) abort_transaction:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	xenbus_transaction_end(xbt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	xenbus_dev_fatal(dev, err, "%s", message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	pr_debug("failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	netback_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) static const struct xenbus_device_id netback_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	{ "vif" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	{ "" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) static struct xenbus_driver netback_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	.ids = netback_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	.probe = netback_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	.remove = netback_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	.uevent = netback_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	.otherend_changed = frontend_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	.allow_rebind = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) int xenvif_xenbus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	return xenbus_register_backend(&netback_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) void xenvif_xenbus_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	return xenbus_unregister_driver(&netback_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }