virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: netdev@vger.kernel.org
Cc: Jesper Dangaard Brouer <hawk@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	virtualization@lists.linux-foundation.org,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	bpf@vger.kernel.org, Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 12/16] virtio_net: introduce virtnet_get_netdev()
Date: Tue, 28 Mar 2023 17:28:43 +0800	[thread overview]
Message-ID: <20230328092847.91643-13-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <20230328092847.91643-1-xuanzhuo@linux.alibaba.com>

Adding an API to get netdev_ops. Avoid to use the netdev_ops directly.

This is prepare for separating the virtio-related funcs.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 drivers/net/virtio/virtnet.c | 11 ++++++++---
 drivers/net/virtio/virtnet.h |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/virtio/virtnet.c b/drivers/net/virtio/virtnet.c
index 3f58af7d1550..5f508d9500f3 100644
--- a/drivers/net/virtio/virtnet.c
+++ b/drivers/net/virtio/virtnet.c
@@ -2054,7 +2054,7 @@ static void virtnet_freeze_down(struct virtio_device *vdev)
 	netif_device_detach(vi->dev);
 	netif_tx_unlock_bh(vi->dev);
 	if (netif_running(vi->dev))
-		virtnet_close(vi->dev);
+		virtnet_get_netdev()->ndo_stop(vi->dev);
 }
 
 static int init_vqs(struct virtnet_info *vi);
@@ -2073,7 +2073,7 @@ static int virtnet_restore_up(struct virtio_device *vdev)
 	enable_delayed_refill(vi);
 
 	if (netif_running(vi->dev)) {
-		err = virtnet_open(vi->dev);
+		err = virtnet_get_netdev()->ndo_open(vi->dev);
 		if (err)
 			return err;
 	}
@@ -2319,6 +2319,11 @@ static const struct net_device_ops virtnet_netdev = {
 	.ndo_tx_timeout		= virtnet_tx_timeout,
 };
 
+const struct net_device_ops *virtnet_get_netdev(void)
+{
+	return &virtnet_netdev;
+}
+
 static void virtnet_config_changed_work(struct work_struct *work)
 {
 	struct virtnet_info *vi =
@@ -2796,7 +2801,7 @@ static int virtnet_probe(struct virtio_device *vdev)
 	/* Set up network device as normal. */
 	dev->priv_flags |= IFF_UNICAST_FLT | IFF_LIVE_ADDR_CHANGE |
 			   IFF_TX_SKB_NO_LINEAR;
-	dev->netdev_ops = &virtnet_netdev;
+	dev->netdev_ops = virtnet_get_netdev();
 	dev->features = NETIF_F_HIGHDMA;
 
 	dev->ethtool_ops = virtnet_get_ethtool_ops();
diff --git a/drivers/net/virtio/virtnet.h b/drivers/net/virtio/virtnet.h
index 48e0c5ba346a..269ddc386418 100644
--- a/drivers/net/virtio/virtnet.h
+++ b/drivers/net/virtio/virtnet.h
@@ -185,4 +185,5 @@ int virtnet_rx_resize(struct virtnet_info *vi, struct virtnet_rq *rq, u32 ring_n
 int virtnet_tx_resize(struct virtnet_info *vi, struct virtnet_sq *sq, u32 ring_num);
 int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs);
 void virtnet_dev_rx_queue_group(struct virtnet_info *vi, struct net_device *dev);
+const struct net_device_ops *virtnet_get_netdev(void);
 #endif
-- 
2.32.0.3.g01195cf9f

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  parent reply	other threads:[~2023-03-28  9:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28  9:28 [PATCH 00/16] virtio-net: split virtio-net.c Xuan Zhuo
2023-03-28  9:28 ` [PATCH 01/16] virtio_net: add a separate directory for virtio-net Xuan Zhuo
2023-03-28  9:28 ` [PATCH 02/16] virtio_net: move struct to header file Xuan Zhuo
     [not found]   ` <20230329211826.0657f947@kernel.org>
2023-03-30  6:01     ` Xuan Zhuo
2023-03-28  9:28 ` [PATCH 03/16] virtio_net: add prefix to the struct inside " Xuan Zhuo
2023-03-28  9:28 ` [PATCH 04/16] virtio_net: separating cpu-related funs Xuan Zhuo
2023-03-28  9:28 ` [PATCH 05/16] virtio_net: separate virtnet_ctrl_set_queues() Xuan Zhuo
2023-03-28  9:28 ` [PATCH 06/16] virtio_net: separate virtnet_ctrl_set_mac_address() Xuan Zhuo
2023-03-28  9:28 ` [PATCH 07/16] virtio_net: remove lock from virtnet_ack_link_announce() Xuan Zhuo
2023-03-28  9:28 ` [PATCH 08/16] virtio_net: separating the APIs of cq Xuan Zhuo
2023-03-28  9:28 ` [PATCH 09/16] virtio_net: introduce virtnet_rq_update_stats() Xuan Zhuo
2023-03-28  9:28 ` [PATCH 10/16] virtio_net: separating the funcs of ethtool Xuan Zhuo
2023-03-28  9:28 ` [PATCH 11/16] virtio_net: introduce virtnet_dev_rx_queue_group() Xuan Zhuo
2023-03-28  9:28 ` Xuan Zhuo [this message]
     [not found]   ` <20230329212203.3c3bf199@kernel.org>
2023-03-30  6:01     ` [PATCH 12/16] virtio_net: introduce virtnet_get_netdev() Xuan Zhuo
2023-03-28  9:28 ` [PATCH 13/16] virtio_net: prepare for virtio Xuan Zhuo
2023-03-28  9:28 ` [PATCH 14/16] virtio_net: move virtnet_[en/dis]able_delayed_refill to header file Xuan Zhuo
2023-03-28  9:28 ` [PATCH 15/16] virtio_net: add APIs to register/unregister virtio driver Xuan Zhuo
2023-03-28  9:28 ` [PATCH 16/16] virtio_net: separating the virtio code Xuan Zhuo
     [not found]   ` <20230329211552.27efa412@kernel.org>
2023-03-30  6:00     ` Xuan Zhuo
2023-03-30  6:17 ` [PATCH 00/16] virtio-net: split virtio-net.c Michael S. Tsirkin
2023-03-31  7:21   ` Xuan Zhuo
2023-03-31  7:35     ` Jason Wang
2023-03-31  7:48       ` Xuan Zhuo
2023-03-31  8:00         ` Michael S. Tsirkin
2023-03-31  8:10           ` Xuan Zhuo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230328092847.91643-13-xuanzhuo@linux.alibaba.com \
    --to=xuanzhuo@linux.alibaba.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).