* [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering
@ 2009-02-03 19:25 Alex Williamson
2009-02-03 19:25 ` [PATCH v4 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-03 19:25 UTC (permalink / raw)
To: rusty; +Cc: markmc, netdev, kvm
This series adds infrastructure for a new control virtqueue and
makes use of it to support set_rx_mode, unicast and multicast address
lists, and supporting a hypervisor based VLAN filter. The goal is to
make the virtio-net device support more of the features of a physical
NIC and allow the hypervisor to discard packets we don't want. These
patches are intended for 2.6.30.
This is the 4th and hopefully final revision, incorporating a few
more tweaks from Rusty. I've renamed VIRTIO_NET_MAX_CTRL_ARGS to
VIRTNET_SEND_COMMAND_SG_MAX and moved it into the c file. I've
added the flexible 2-dimensional array to virtio_net_ctrl_mac and
cleaned up the code to use it. I've retained the single scatterlist
parameter and out/in counts for virtnet_send_command() since the
current sg interface doesn't faciliate merging terminated sg[]s
together. However, this is an internal virtio_net API and can
easily be refined over time, the key is the separate sg entries
for unicast/multicast MACs for the hypervisor ABI. Thanks,
Alex
---
Alex Williamson (4):
virtio_net: Add support for VLAN filtering in the hypervisor
virtio_net: Add a MAC filter table
virtio_net: Add a set_rx_mode interface
virtio_net: Add a virtqueue for outbound control commands
drivers/net/virtio_net.c | 168 +++++++++++++++++++++++++++++++++++++++++++-
include/linux/virtio_net.h | 66 +++++++++++++++++
2 files changed, 231 insertions(+), 3 deletions(-)
--
Alex Williamson
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 1/4] virtio_net: Add a virtqueue for outbound control commands
2009-02-03 19:25 [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering Alex Williamson
@ 2009-02-03 19:25 ` Alex Williamson
2009-02-03 19:26 ` [PATCH v4 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
` (3 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-03 19:25 UTC (permalink / raw)
To: rusty; +Cc: markmc, netdev, kvm
This will be used for RX mode, MAC filter table, VLAN filtering, etc...
The control transaction consists of one or more "out" sg entries and
one or more "in" sg entries. The first out entry contains a header
defining the class and command. Additional out entries may provide
data for the command. The last in entry provides a status response
back from the command.
Virtqueues typically run asynchronous, running a callback function
when there's data in the channel. We can't readily make use of this
in the command paths where we need to use this. Instead, we kick
the virtqueue and spin. The kick causes an I/O write, triggering an
immediate trap into the hypervisor.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/net/virtio_net.c | 68 ++++++++++++++++++++++++++++++++++++++++++--
include/linux/virtio_net.h | 18 ++++++++++++
2 files changed, 83 insertions(+), 3 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 1b7e597..d31fc65 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -37,10 +37,12 @@ module_param(gso, bool, 0444);
#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN 128
+#define VIRTNET_SEND_COMMAND_SG_MAX 0
+
struct virtnet_info
{
struct virtio_device *vdev;
- struct virtqueue *rvq, *svq;
+ struct virtqueue *rvq, *svq, *cvq;
struct net_device *dev;
struct napi_struct napi;
unsigned int status;
@@ -605,6 +607,53 @@ static int virtnet_open(struct net_device *dev)
return 0;
}
+/*
+ * Send command via the control virtqueue and check status. Commands
+ * supported by the hypervisor, as indicated by feature bits, should
+ * never fail unless improperly formated.
+ */
+static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
+ struct scatterlist *data, int out, int in)
+{
+ struct scatterlist sg[VIRTNET_SEND_COMMAND_SG_MAX + 2];
+ struct virtio_net_ctrl_hdr ctrl;
+ virtio_net_ctrl_ack status = ~0;
+ unsigned int tmp;
+
+ if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
+ BUG(); /* Caller should know better */
+ return false;
+ }
+
+ BUG_ON(out + in > VIRTNET_SEND_COMMAND_SG_MAX);
+
+ out++; /* Add header */
+ in++; /* Add return status */
+
+ ctrl.class = class;
+ ctrl.cmd = cmd;
+
+ sg_init_table(sg, out + in);
+
+ sg_set_buf(&sg[0], &ctrl, sizeof(ctrl));
+ memcpy(&sg[1], data, sizeof(struct scatterlist) * (out + in - 2));
+ sg_set_buf(&sg[out + in - 1], &status, sizeof(status));
+
+ if (vi->cvq->vq_ops->add_buf(vi->cvq, sg, out, in, vi) != 0)
+ BUG();
+
+ vi->cvq->vq_ops->kick(vi->cvq);
+
+ /*
+ * Spin for a response, the kick causes an ioport write, trapping
+ * into the hypervisor, so the request should be handled immediately.
+ */
+ while (!vi->cvq->vq_ops->get_buf(vi->cvq, &tmp))
+ cpu_relax();
+
+ return status == VIRTIO_NET_OK;
+}
+
static int virtnet_close(struct net_device *dev)
{
struct virtnet_info *vi = netdev_priv(dev);
@@ -771,6 +820,14 @@ static int virtnet_probe(struct virtio_device *vdev)
goto free_recv;
}
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
+ vi->cvq = vdev->config->find_vq(vdev, 2, NULL);
+ if (IS_ERR(vi->cvq)) {
+ err = PTR_ERR(vi->svq);
+ goto free_send;
+ }
+ }
+
/* Initialize our empty receive and send queues. */
skb_queue_head_init(&vi->recv);
skb_queue_head_init(&vi->send);
@@ -783,7 +840,7 @@ static int virtnet_probe(struct virtio_device *vdev)
err = register_netdev(dev);
if (err) {
pr_debug("virtio_net: registering device failed\n");
- goto free_send;
+ goto free_ctrl;
}
/* Last of all, set up some receive buffers. */
@@ -803,6 +860,9 @@ static int virtnet_probe(struct virtio_device *vdev)
unregister:
unregister_netdev(dev);
+free_ctrl:
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
+ vdev->config->del_vq(vi->cvq);
free_send:
vdev->config->del_vq(vi->svq);
free_recv:
@@ -834,6 +894,8 @@ static void virtnet_remove(struct virtio_device *vdev)
vdev->config->del_vq(vi->svq);
vdev->config->del_vq(vi->rvq);
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
+ vdev->config->del_vq(vi->cvq);
unregister_netdev(vi->dev);
while (vi->pages)
@@ -853,7 +915,7 @@ static unsigned int features[] = {
VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
- VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS,
+ VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
VIRTIO_F_NOTIFY_ON_EMPTY,
};
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index d8e362d..245eda8 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -23,6 +23,7 @@
#define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */
#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */
#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
+#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
@@ -59,4 +60,21 @@ struct virtio_net_hdr_mrg_rxbuf {
__u16 num_buffers; /* Number of merged rx buffers */
};
+/*
+ * Control virtqueue data structures
+ *
+ * The control virtqueue expects a header in the first sg entry
+ * and an ack/status response in the last entry. Data for the
+ * command goes in between.
+ */
+struct virtio_net_ctrl_hdr {
+ __u8 class;
+ __u8 cmd;
+} __attribute__((packed));
+
+typedef __u8 virtio_net_ctrl_ack;
+
+#define VIRTIO_NET_OK 0
+#define VIRTIO_NET_ERR 1
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 2/4] virtio_net: Add a set_rx_mode interface
2009-02-03 19:25 [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering Alex Williamson
2009-02-03 19:25 ` [PATCH v4 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
@ 2009-02-03 19:26 ` Alex Williamson
2009-02-03 19:26 ` [PATCH v4 3/4] virtio_net: Add a MAC filter table Alex Williamson
` (2 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-03 19:26 UTC (permalink / raw)
To: rusty; +Cc: markmc, netdev, kvm
Make use of the RX_MODE control virtqueue class to enable the
set_rx_mode netdev interface. This allows us to selectively
enable/disable promiscuous and allmulti mode so we don't see
packets we don't want. For now, we automatically enable these
as needed if additional unicast or multicast addresses are
requested.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/net/virtio_net.c | 34 +++++++++++++++++++++++++++++++++-
include/linux/virtio_net.h | 11 +++++++++++
2 files changed, 44 insertions(+), 1 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index d31fc65..17058d7 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -37,7 +37,7 @@ module_param(gso, bool, 0444);
#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN 128
-#define VIRTNET_SEND_COMMAND_SG_MAX 0
+#define VIRTNET_SEND_COMMAND_SG_MAX 1
struct virtnet_info
{
@@ -674,6 +674,36 @@ static int virtnet_set_tx_csum(struct net_device *dev, u32 data)
return ethtool_op_set_tx_hw_csum(dev, data);
}
+static void virtnet_set_rx_mode(struct net_device *dev)
+{
+ struct virtnet_info *vi = netdev_priv(dev);
+ struct scatterlist sg;
+ u8 promisc, allmulti;
+
+ /* We can't dynamicaly set ndo_set_rx_mode, so return gracefully */
+ if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
+ return;
+
+ promisc = ((dev->flags & IFF_PROMISC) != 0 || dev->uc_count > 0);
+ allmulti = ((dev->flags & IFF_ALLMULTI) != 0 || dev->mc_count > 0);
+
+ sg_set_buf(&sg, &promisc, sizeof(promisc));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
+ VIRTIO_NET_CTRL_RX_PROMISC,
+ &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
+ promisc ? "en" : "dis");
+
+ sg_set_buf(&sg, &allmulti, sizeof(allmulti));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
+ VIRTIO_NET_CTRL_RX_ALLMULTI,
+ &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
+ allmulti ? "en" : "dis");
+}
+
static struct ethtool_ops virtnet_ethtool_ops = {
.set_tx_csum = virtnet_set_tx_csum,
.set_sg = ethtool_op_set_sg,
@@ -698,6 +728,7 @@ static const struct net_device_ops virtnet_netdev = {
.ndo_start_xmit = start_xmit,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = virtnet_set_mac_address,
+ .ndo_set_rx_mode = virtnet_set_rx_mode,
.ndo_change_mtu = virtnet_change_mtu,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = virtnet_netpoll,
@@ -916,6 +947,7 @@ static unsigned int features[] = {
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
+ VIRTIO_NET_F_CTRL_RX,
VIRTIO_F_NOTIFY_ON_EMPTY,
};
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 245eda8..63b2461 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -24,6 +24,7 @@
#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */
#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
+#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
@@ -77,4 +78,14 @@ typedef __u8 virtio_net_ctrl_ack;
#define VIRTIO_NET_OK 0
#define VIRTIO_NET_ERR 1
+/*
+ * Control the RX mode, ie. promisucous and allmulti. PROMISC and
+ * ALLMULTI commands require an "out" sg entry containing a 1 byte
+ * state value, zero = disable, non-zero = enable. These commands
+ * are supported with the VIRTIO_NET_F_CTRL_RX feature.
+ */
+#define VIRTIO_NET_CTRL_RX 0
+ #define VIRTIO_NET_CTRL_RX_PROMISC 0
+ #define VIRTIO_NET_CTRL_RX_ALLMULTI 1
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 3/4] virtio_net: Add a MAC filter table
2009-02-03 19:25 [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering Alex Williamson
2009-02-03 19:25 ` [PATCH v4 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
2009-02-03 19:26 ` [PATCH v4 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
@ 2009-02-03 19:26 ` Alex Williamson
2009-02-03 19:26 ` [PATCH v4 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson
2009-02-03 23:06 ` [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering David Miller
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-03 19:26 UTC (permalink / raw)
To: rusty; +Cc: markmc, netdev, kvm
Make use of the MAC control virtqueue class to support a MAC
filter table. The filter table is managed by the hypervisor.
We consider the table to be available if the CTRL_RX feature
bit is set. We leave it to the hypervisor to manage the table
and enable promiscuous or all-multi mode as necessary depending
on the resources available to it.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
---
drivers/net/virtio_net.c | 55 ++++++++++++++++++++++++++++++++++++++------
include/linux/virtio_net.h | 23 ++++++++++++++++++
2 files changed, 70 insertions(+), 8 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 17058d7..937a256 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -37,7 +37,7 @@ module_param(gso, bool, 0444);
#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN 128
-#define VIRTNET_SEND_COMMAND_SG_MAX 1
+#define VIRTNET_SEND_COMMAND_SG_MAX 2
struct virtnet_info
{
@@ -677,31 +677,70 @@ static int virtnet_set_tx_csum(struct net_device *dev, u32 data)
static void virtnet_set_rx_mode(struct net_device *dev)
{
struct virtnet_info *vi = netdev_priv(dev);
- struct scatterlist sg;
+ struct scatterlist sg[2];
u8 promisc, allmulti;
+ struct virtio_net_ctrl_mac *mac_data;
+ struct dev_addr_list *addr;
+ void *buf;
+ int i;
/* We can't dynamicaly set ndo_set_rx_mode, so return gracefully */
if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
return;
- promisc = ((dev->flags & IFF_PROMISC) != 0 || dev->uc_count > 0);
- allmulti = ((dev->flags & IFF_ALLMULTI) != 0 || dev->mc_count > 0);
+ promisc = ((dev->flags & IFF_PROMISC) != 0);
+ allmulti = ((dev->flags & IFF_ALLMULTI) != 0);
- sg_set_buf(&sg, &promisc, sizeof(promisc));
+ sg_set_buf(sg, &promisc, sizeof(promisc));
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
VIRTIO_NET_CTRL_RX_PROMISC,
- &sg, 1, 0))
+ sg, 1, 0))
dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
promisc ? "en" : "dis");
- sg_set_buf(&sg, &allmulti, sizeof(allmulti));
+ sg_set_buf(sg, &allmulti, sizeof(allmulti));
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
VIRTIO_NET_CTRL_RX_ALLMULTI,
- &sg, 1, 0))
+ sg, 1, 0))
dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
allmulti ? "en" : "dis");
+
+ /* MAC filter - use one buffer for both lists */
+ mac_data = buf = kzalloc(((dev->uc_count + dev->mc_count) * ETH_ALEN) +
+ (2 * sizeof(mac_data->entries)), GFP_ATOMIC);
+ if (!buf) {
+ dev_warn(&dev->dev, "No memory for MAC address buffer\n");
+ return;
+ }
+
+ /* Store the unicast list and count in the front of the buffer */
+ mac_data->entries = dev->uc_count;
+ addr = dev->uc_list;
+ for (i = 0; i < dev->uc_count; i++, addr = addr->next)
+ memcpy(&mac_data->macs[i][0], addr->da_addr, ETH_ALEN);
+
+ sg_set_buf(&sg[0], mac_data,
+ sizeof(mac_data->entries) + (dev->uc_count * ETH_ALEN));
+
+ /* multicast list and count fill the end */
+ mac_data = (void *)&mac_data->macs[dev->uc_count][0];
+
+ mac_data->entries = dev->mc_count;
+ addr = dev->mc_list;
+ for (i = 0; i < dev->mc_count; i++, addr = addr->next)
+ memcpy(&mac_data->macs[i][0], addr->da_addr, ETH_ALEN);
+
+ sg_set_buf(&sg[1], mac_data,
+ sizeof(mac_data->entries) + (dev->mc_count * ETH_ALEN));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC,
+ VIRTIO_NET_CTRL_MAC_TABLE_SET,
+ sg, 2, 0))
+ dev_warn(&dev->dev, "Failed to set MAC fitler table.\n");
+
+ kfree(buf);
}
static struct ethtool_ops virtnet_ethtool_ops = {
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 63b2461..ba82b65 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -88,4 +88,27 @@ typedef __u8 virtio_net_ctrl_ack;
#define VIRTIO_NET_CTRL_RX_PROMISC 0
#define VIRTIO_NET_CTRL_RX_ALLMULTI 1
+/*
+ * Control the MAC filter table.
+ *
+ * The MAC filter table is managed by the hypervisor, the guest should
+ * assume the size is infinite. Filtering should be considered
+ * non-perfect, ie. based on hypervisor resources, the guest may
+ * received packets from sources not specified in the filter list.
+ *
+ * In addition to the class/cmd header, the TABLE_SET command requires
+ * two out scatterlists. Each contains a 4 byte count of entries followed
+ * by a concatenated byte stream of the ETH_ALEN MAC addresses. The
+ * first sg list contains unicast addresses, the second is for multicast.
+ * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
+ * is available.
+ */
+struct virtio_net_ctrl_mac {
+ __u32 entries;
+ __u8 macs[][ETH_ALEN];
+} __attribute__((packed));
+
+#define VIRTIO_NET_CTRL_MAC 1
+ #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 4/4] virtio_net: Add support for VLAN filtering in the hypervisor
2009-02-03 19:25 [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering Alex Williamson
` (2 preceding siblings ...)
2009-02-03 19:26 ` [PATCH v4 3/4] virtio_net: Add a MAC filter table Alex Williamson
@ 2009-02-03 19:26 ` Alex Williamson
2009-02-03 23:06 ` [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering David Miller
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-03 19:26 UTC (permalink / raw)
To: rusty; +Cc: markmc, netdev, kvm
VLAN filtering allows the hypervisor to drop packets from VLANs
that we're not a part of, further reducing the number of extraneous
packets recieved. This makes use of the VLAN virtqueue command class.
The CTRL_VLAN feature bit tells us whether the backend supports VLAN
filtering.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
---
drivers/net/virtio_net.c | 31 ++++++++++++++++++++++++++++++-
include/linux/virtio_net.h | 14 ++++++++++++++
2 files changed, 44 insertions(+), 1 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 937a256..3d00339 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -743,6 +743,30 @@ static void virtnet_set_rx_mode(struct net_device *dev)
kfree(buf);
}
+static void virnet_vlan_rx_add_vid(struct net_device *dev, u16 vid)
+{
+ struct virtnet_info *vi = netdev_priv(dev);
+ struct scatterlist sg;
+
+ sg_set_buf(&sg, &vid, sizeof(vid));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
+ VIRTIO_NET_CTRL_VLAN_ADD, &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to add VLAN ID %d.\n", vid);
+}
+
+static void virnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid)
+{
+ struct virtnet_info *vi = netdev_priv(dev);
+ struct scatterlist sg;
+
+ sg_set_buf(&sg, &vid, sizeof(vid));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
+ VIRTIO_NET_CTRL_VLAN_DEL, &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to kill VLAN ID %d.\n", vid);
+}
+
static struct ethtool_ops virtnet_ethtool_ops = {
.set_tx_csum = virtnet_set_tx_csum,
.set_sg = ethtool_op_set_sg,
@@ -769,6 +793,8 @@ static const struct net_device_ops virtnet_netdev = {
.ndo_set_mac_address = virtnet_set_mac_address,
.ndo_set_rx_mode = virtnet_set_rx_mode,
.ndo_change_mtu = virtnet_change_mtu,
+ .ndo_vlan_rx_add_vid = virnet_vlan_rx_add_vid,
+ .ndo_vlan_rx_kill_vid = virnet_vlan_rx_kill_vid,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = virtnet_netpoll,
#endif
@@ -896,6 +922,9 @@ static int virtnet_probe(struct virtio_device *vdev)
err = PTR_ERR(vi->svq);
goto free_send;
}
+
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
+ dev->features |= NETIF_F_HW_VLAN_FILTER;
}
/* Initialize our empty receive and send queues. */
@@ -986,7 +1015,7 @@ static unsigned int features[] = {
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
- VIRTIO_NET_F_CTRL_RX,
+ VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
VIRTIO_F_NOTIFY_ON_EMPTY,
};
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index ba82b65..242348b 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -25,6 +25,7 @@
#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
+#define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */
#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
@@ -111,4 +112,17 @@ struct virtio_net_ctrl_mac {
#define VIRTIO_NET_CTRL_MAC 1
#define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
+/*
+ * Control VLAN filtering
+ *
+ * The VLAN filter table is controlled via a simple ADD/DEL interface.
+ * VLAN IDs not added may be filterd by the hypervisor. Del is the
+ * opposite of add. Both commands expect an out entry containing a 2
+ * byte VLAN ID. VLAN filterting is available with the
+ * VIRTIO_NET_F_CTRL_VLAN feature bit.
+ */
+#define VIRTIO_NET_CTRL_VLAN 2
+ #define VIRTIO_NET_CTRL_VLAN_ADD 0
+ #define VIRTIO_NET_CTRL_VLAN_DEL 1
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering
2009-02-03 19:25 [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering Alex Williamson
` (3 preceding siblings ...)
2009-02-03 19:26 ` [PATCH v4 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson
@ 2009-02-03 23:06 ` David Miller
2009-02-03 23:42 ` Alex Williamson
` (2 more replies)
4 siblings, 3 replies; 14+ messages in thread
From: David Miller @ 2009-02-03 23:06 UTC (permalink / raw)
To: alex.williamson; +Cc: rusty, markmc, netdev, kvm
From: Alex Williamson <alex.williamson@hp.com>
Date: Tue, 03 Feb 2009 12:25:50 -0700
> This series adds infrastructure for a new control virtqueue and
> makes use of it to support set_rx_mode, unicast and multicast address
> lists, and supporting a hypervisor based VLAN filter. The goal is to
> make the virtio-net device support more of the features of a physical
> NIC and allow the hypervisor to discard packets we don't want. These
> patches are intended for 2.6.30.
>
> This is the 4th and hopefully final revision, incorporating a few
> more tweaks from Rusty.
The second patch doesn't apply to the net-next-2.6 tree.
Please regenerate these against net-next-2.6 or -next and
I'll apply them, thanks.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering
2009-02-03 23:06 ` [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering David Miller
@ 2009-02-03 23:42 ` Alex Williamson
2009-02-04 4:03 ` Rusty Russell
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
2 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-03 23:42 UTC (permalink / raw)
To: David Miller; +Cc: rusty, markmc, netdev, kvm
On Tue, 2009-02-03 at 15:06 -0800, David Miller wrote:
> From: Alex Williamson <alex.williamson@hp.com>
> Date: Tue, 03 Feb 2009 12:25:50 -0700
>
> > This series adds infrastructure for a new control virtqueue and
> > makes use of it to support set_rx_mode, unicast and multicast address
> > lists, and supporting a hypervisor based VLAN filter. The goal is to
> > make the virtio-net device support more of the features of a physical
> > NIC and allow the hypervisor to discard packets we don't want. These
> > patches are intended for 2.6.30.
> >
> > This is the 4th and hopefully final revision, incorporating a few
> > more tweaks from Rusty.
>
> The second patch doesn't apply to the net-next-2.6 tree.
>
> Please regenerate these against net-next-2.6 or -next and
> I'll apply them, thanks.
Ack, sorry. I had dropped the original first patch that allows setting
the virtio_net MAC address since Rusty already accepted it into his
patch queue. I can easily munge these to not rely on that (context-only
changes), but that'll just leave Rusty with the merge conflict. Rusty,
which way do you want these to hit the tree? Thanks,
Alex
--
Alex Williamson HP Open Source & Linux Org.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering
2009-02-03 23:06 ` [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering David Miller
2009-02-03 23:42 ` Alex Williamson
@ 2009-02-04 4:03 ` Rusty Russell
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
2 siblings, 0 replies; 14+ messages in thread
From: Rusty Russell @ 2009-02-04 4:03 UTC (permalink / raw)
To: David Miller; +Cc: alex.williamson, markmc, netdev, kvm
On Wednesday 04 February 2009 09:36:36 David Miller wrote:
> The second patch doesn't apply to the net-next-2.6 tree.
>
> Please regenerate these against net-next-2.6 or -next and
> I'll apply them, thanks.
And FWIW:
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Thanks!
Rusty.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v5 0/4] virtio_net: Add MAC and VLAN filtering
2009-02-03 23:06 ` [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering David Miller
2009-02-03 23:42 ` Alex Williamson
2009-02-04 4:03 ` Rusty Russell
@ 2009-02-04 19:02 ` Alex Williamson
2009-02-04 19:02 ` [PATCH v5 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
` (4 more replies)
2 siblings, 5 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-04 19:02 UTC (permalink / raw)
To: davem; +Cc: rusty, markmc, netdev, kvm
This series adds infrastructure for a new control virtqueue and
makes use of it to support set_rx_mode, unicast and multicast address
lists, and supporting a hypervisor based VLAN filter. The goal is to
make the virtio-net device support more of the features of a physical
NIC and allow the hypervisor to discard packets we don't want. These
patches are intended for 2.6.30.
This version is just a rebase to current net-next-2.6.git. I'll send
Rusty an update to the patch in his queue that led to the patch
conflict, this series doesn't depend on it.
Alex
---
Alex Williamson (4):
virtio_net: Add support for VLAN filtering in the hypervisor
virtio_net: Add a MAC filter table
virtio_net: Add a set_rx_mode interface
virtio_net: Add a virtqueue for outbound control commands
drivers/net/virtio_net.c | 168 +++++++++++++++++++++++++++++++++++++++++++-
include/linux/virtio_net.h | 66 +++++++++++++++++
2 files changed, 231 insertions(+), 3 deletions(-)
--
Alex Williamson
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v5 1/4] virtio_net: Add a virtqueue for outbound control commands
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
@ 2009-02-04 19:02 ` Alex Williamson
2009-02-04 19:02 ` [PATCH v5 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
` (3 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-04 19:02 UTC (permalink / raw)
To: davem; +Cc: rusty, markmc, netdev, kvm
This will be used for RX mode, MAC filter table, VLAN filtering, etc...
The control transaction consists of one or more "out" sg entries and
one or more "in" sg entries. The first out entry contains a header
defining the class and command. Additional out entries may provide
data for the command. The last in entry provides a status response
back from the command.
Virtqueues typically run asynchronous, running a callback function
when there's data in the channel. We can't readily make use of this
in the command paths where we need to use this. Instead, we kick
the virtqueue and spin. The kick causes an I/O write, triggering an
immediate trap into the hypervisor.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/net/virtio_net.c | 68 ++++++++++++++++++++++++++++++++++++++++++--
include/linux/virtio_net.h | 18 ++++++++++++
2 files changed, 83 insertions(+), 3 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index fe576e7..67bb583 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -37,10 +37,12 @@ module_param(gso, bool, 0444);
#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN 128
+#define VIRTNET_SEND_COMMAND_SG_MAX 0
+
struct virtnet_info
{
struct virtio_device *vdev;
- struct virtqueue *rvq, *svq;
+ struct virtqueue *rvq, *svq, *cvq;
struct net_device *dev;
struct napi_struct napi;
unsigned int status;
@@ -589,6 +591,53 @@ static int virtnet_open(struct net_device *dev)
return 0;
}
+/*
+ * Send command via the control virtqueue and check status. Commands
+ * supported by the hypervisor, as indicated by feature bits, should
+ * never fail unless improperly formated.
+ */
+static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
+ struct scatterlist *data, int out, int in)
+{
+ struct scatterlist sg[VIRTNET_SEND_COMMAND_SG_MAX + 2];
+ struct virtio_net_ctrl_hdr ctrl;
+ virtio_net_ctrl_ack status = ~0;
+ unsigned int tmp;
+
+ if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
+ BUG(); /* Caller should know better */
+ return false;
+ }
+
+ BUG_ON(out + in > VIRTNET_SEND_COMMAND_SG_MAX);
+
+ out++; /* Add header */
+ in++; /* Add return status */
+
+ ctrl.class = class;
+ ctrl.cmd = cmd;
+
+ sg_init_table(sg, out + in);
+
+ sg_set_buf(&sg[0], &ctrl, sizeof(ctrl));
+ memcpy(&sg[1], data, sizeof(struct scatterlist) * (out + in - 2));
+ sg_set_buf(&sg[out + in - 1], &status, sizeof(status));
+
+ if (vi->cvq->vq_ops->add_buf(vi->cvq, sg, out, in, vi) != 0)
+ BUG();
+
+ vi->cvq->vq_ops->kick(vi->cvq);
+
+ /*
+ * Spin for a response, the kick causes an ioport write, trapping
+ * into the hypervisor, so the request should be handled immediately.
+ */
+ while (!vi->cvq->vq_ops->get_buf(vi->cvq, &tmp))
+ cpu_relax();
+
+ return status == VIRTIO_NET_OK;
+}
+
static int virtnet_close(struct net_device *dev)
{
struct virtnet_info *vi = netdev_priv(dev);
@@ -752,6 +801,14 @@ static int virtnet_probe(struct virtio_device *vdev)
goto free_recv;
}
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
+ vi->cvq = vdev->config->find_vq(vdev, 2, NULL);
+ if (IS_ERR(vi->cvq)) {
+ err = PTR_ERR(vi->svq);
+ goto free_send;
+ }
+ }
+
/* Initialize our empty receive and send queues. */
skb_queue_head_init(&vi->recv);
skb_queue_head_init(&vi->send);
@@ -764,7 +821,7 @@ static int virtnet_probe(struct virtio_device *vdev)
err = register_netdev(dev);
if (err) {
pr_debug("virtio_net: registering device failed\n");
- goto free_send;
+ goto free_ctrl;
}
/* Last of all, set up some receive buffers. */
@@ -784,6 +841,9 @@ static int virtnet_probe(struct virtio_device *vdev)
unregister:
unregister_netdev(dev);
+free_ctrl:
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
+ vdev->config->del_vq(vi->cvq);
free_send:
vdev->config->del_vq(vi->svq);
free_recv:
@@ -815,6 +875,8 @@ static void virtnet_remove(struct virtio_device *vdev)
vdev->config->del_vq(vi->svq);
vdev->config->del_vq(vi->rvq);
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
+ vdev->config->del_vq(vi->cvq);
unregister_netdev(vi->dev);
while (vi->pages)
@@ -834,7 +896,7 @@ static unsigned int features[] = {
VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
- VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS,
+ VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
VIRTIO_F_NOTIFY_ON_EMPTY,
};
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index d8e362d..245eda8 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -23,6 +23,7 @@
#define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */
#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */
#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
+#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
@@ -59,4 +60,21 @@ struct virtio_net_hdr_mrg_rxbuf {
__u16 num_buffers; /* Number of merged rx buffers */
};
+/*
+ * Control virtqueue data structures
+ *
+ * The control virtqueue expects a header in the first sg entry
+ * and an ack/status response in the last entry. Data for the
+ * command goes in between.
+ */
+struct virtio_net_ctrl_hdr {
+ __u8 class;
+ __u8 cmd;
+} __attribute__((packed));
+
+typedef __u8 virtio_net_ctrl_ack;
+
+#define VIRTIO_NET_OK 0
+#define VIRTIO_NET_ERR 1
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v5 2/4] virtio_net: Add a set_rx_mode interface
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
2009-02-04 19:02 ` [PATCH v5 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
@ 2009-02-04 19:02 ` Alex Williamson
2009-02-04 19:02 ` [PATCH v5 3/4] virtio_net: Add a MAC filter table Alex Williamson
` (2 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-04 19:02 UTC (permalink / raw)
To: davem; +Cc: rusty, markmc, netdev, kvm
Make use of the RX_MODE control virtqueue class to enable the
set_rx_mode netdev interface. This allows us to selectively
enable/disable promiscuous and allmulti mode so we don't see
packets we don't want. For now, we automatically enable these
as needed if additional unicast or multicast addresses are
requested.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/net/virtio_net.c | 34 +++++++++++++++++++++++++++++++++-
include/linux/virtio_net.h | 11 +++++++++++
2 files changed, 44 insertions(+), 1 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 67bb583..1abea9d 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -37,7 +37,7 @@ module_param(gso, bool, 0444);
#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN 128
-#define VIRTNET_SEND_COMMAND_SG_MAX 0
+#define VIRTNET_SEND_COMMAND_SG_MAX 1
struct virtnet_info
{
@@ -658,6 +658,36 @@ static int virtnet_set_tx_csum(struct net_device *dev, u32 data)
return ethtool_op_set_tx_hw_csum(dev, data);
}
+static void virtnet_set_rx_mode(struct net_device *dev)
+{
+ struct virtnet_info *vi = netdev_priv(dev);
+ struct scatterlist sg;
+ u8 promisc, allmulti;
+
+ /* We can't dynamicaly set ndo_set_rx_mode, so return gracefully */
+ if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
+ return;
+
+ promisc = ((dev->flags & IFF_PROMISC) != 0 || dev->uc_count > 0);
+ allmulti = ((dev->flags & IFF_ALLMULTI) != 0 || dev->mc_count > 0);
+
+ sg_set_buf(&sg, &promisc, sizeof(promisc));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
+ VIRTIO_NET_CTRL_RX_PROMISC,
+ &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
+ promisc ? "en" : "dis");
+
+ sg_set_buf(&sg, &allmulti, sizeof(allmulti));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
+ VIRTIO_NET_CTRL_RX_ALLMULTI,
+ &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
+ allmulti ? "en" : "dis");
+}
+
static struct ethtool_ops virtnet_ethtool_ops = {
.set_tx_csum = virtnet_set_tx_csum,
.set_sg = ethtool_op_set_sg,
@@ -682,6 +712,7 @@ static const struct net_device_ops virtnet_netdev = {
.ndo_start_xmit = start_xmit,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = eth_mac_addr,
+ .ndo_set_rx_mode = virtnet_set_rx_mode,
.ndo_change_mtu = virtnet_change_mtu,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = virtnet_netpoll,
@@ -897,6 +928,7 @@ static unsigned int features[] = {
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
+ VIRTIO_NET_F_CTRL_RX,
VIRTIO_F_NOTIFY_ON_EMPTY,
};
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 245eda8..63b2461 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -24,6 +24,7 @@
#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */
#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
+#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
@@ -77,4 +78,14 @@ typedef __u8 virtio_net_ctrl_ack;
#define VIRTIO_NET_OK 0
#define VIRTIO_NET_ERR 1
+/*
+ * Control the RX mode, ie. promisucous and allmulti. PROMISC and
+ * ALLMULTI commands require an "out" sg entry containing a 1 byte
+ * state value, zero = disable, non-zero = enable. These commands
+ * are supported with the VIRTIO_NET_F_CTRL_RX feature.
+ */
+#define VIRTIO_NET_CTRL_RX 0
+ #define VIRTIO_NET_CTRL_RX_PROMISC 0
+ #define VIRTIO_NET_CTRL_RX_ALLMULTI 1
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v5 3/4] virtio_net: Add a MAC filter table
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
2009-02-04 19:02 ` [PATCH v5 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
2009-02-04 19:02 ` [PATCH v5 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
@ 2009-02-04 19:02 ` Alex Williamson
2009-02-04 19:02 ` [PATCH v5 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson
2009-02-05 0:35 ` [PATCH v5 0/4] virtio_net: Add MAC and VLAN filtering David Miller
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-04 19:02 UTC (permalink / raw)
To: davem; +Cc: rusty, markmc, netdev, kvm
Make use of the MAC control virtqueue class to support a MAC
filter table. The filter table is managed by the hypervisor.
We consider the table to be available if the CTRL_RX feature
bit is set. We leave it to the hypervisor to manage the table
and enable promiscuous or all-multi mode as necessary depending
on the resources available to it.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/net/virtio_net.c | 55 ++++++++++++++++++++++++++++++++++++++------
include/linux/virtio_net.h | 23 ++++++++++++++++++
2 files changed, 70 insertions(+), 8 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 1abea9d..daab9c9 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -37,7 +37,7 @@ module_param(gso, bool, 0444);
#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN 128
-#define VIRTNET_SEND_COMMAND_SG_MAX 1
+#define VIRTNET_SEND_COMMAND_SG_MAX 2
struct virtnet_info
{
@@ -661,31 +661,70 @@ static int virtnet_set_tx_csum(struct net_device *dev, u32 data)
static void virtnet_set_rx_mode(struct net_device *dev)
{
struct virtnet_info *vi = netdev_priv(dev);
- struct scatterlist sg;
+ struct scatterlist sg[2];
u8 promisc, allmulti;
+ struct virtio_net_ctrl_mac *mac_data;
+ struct dev_addr_list *addr;
+ void *buf;
+ int i;
/* We can't dynamicaly set ndo_set_rx_mode, so return gracefully */
if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
return;
- promisc = ((dev->flags & IFF_PROMISC) != 0 || dev->uc_count > 0);
- allmulti = ((dev->flags & IFF_ALLMULTI) != 0 || dev->mc_count > 0);
+ promisc = ((dev->flags & IFF_PROMISC) != 0);
+ allmulti = ((dev->flags & IFF_ALLMULTI) != 0);
- sg_set_buf(&sg, &promisc, sizeof(promisc));
+ sg_set_buf(sg, &promisc, sizeof(promisc));
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
VIRTIO_NET_CTRL_RX_PROMISC,
- &sg, 1, 0))
+ sg, 1, 0))
dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
promisc ? "en" : "dis");
- sg_set_buf(&sg, &allmulti, sizeof(allmulti));
+ sg_set_buf(sg, &allmulti, sizeof(allmulti));
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
VIRTIO_NET_CTRL_RX_ALLMULTI,
- &sg, 1, 0))
+ sg, 1, 0))
dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
allmulti ? "en" : "dis");
+
+ /* MAC filter - use one buffer for both lists */
+ mac_data = buf = kzalloc(((dev->uc_count + dev->mc_count) * ETH_ALEN) +
+ (2 * sizeof(mac_data->entries)), GFP_ATOMIC);
+ if (!buf) {
+ dev_warn(&dev->dev, "No memory for MAC address buffer\n");
+ return;
+ }
+
+ /* Store the unicast list and count in the front of the buffer */
+ mac_data->entries = dev->uc_count;
+ addr = dev->uc_list;
+ for (i = 0; i < dev->uc_count; i++, addr = addr->next)
+ memcpy(&mac_data->macs[i][0], addr->da_addr, ETH_ALEN);
+
+ sg_set_buf(&sg[0], mac_data,
+ sizeof(mac_data->entries) + (dev->uc_count * ETH_ALEN));
+
+ /* multicast list and count fill the end */
+ mac_data = (void *)&mac_data->macs[dev->uc_count][0];
+
+ mac_data->entries = dev->mc_count;
+ addr = dev->mc_list;
+ for (i = 0; i < dev->mc_count; i++, addr = addr->next)
+ memcpy(&mac_data->macs[i][0], addr->da_addr, ETH_ALEN);
+
+ sg_set_buf(&sg[1], mac_data,
+ sizeof(mac_data->entries) + (dev->mc_count * ETH_ALEN));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC,
+ VIRTIO_NET_CTRL_MAC_TABLE_SET,
+ sg, 2, 0))
+ dev_warn(&dev->dev, "Failed to set MAC fitler table.\n");
+
+ kfree(buf);
}
static struct ethtool_ops virtnet_ethtool_ops = {
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 63b2461..ba82b65 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -88,4 +88,27 @@ typedef __u8 virtio_net_ctrl_ack;
#define VIRTIO_NET_CTRL_RX_PROMISC 0
#define VIRTIO_NET_CTRL_RX_ALLMULTI 1
+/*
+ * Control the MAC filter table.
+ *
+ * The MAC filter table is managed by the hypervisor, the guest should
+ * assume the size is infinite. Filtering should be considered
+ * non-perfect, ie. based on hypervisor resources, the guest may
+ * received packets from sources not specified in the filter list.
+ *
+ * In addition to the class/cmd header, the TABLE_SET command requires
+ * two out scatterlists. Each contains a 4 byte count of entries followed
+ * by a concatenated byte stream of the ETH_ALEN MAC addresses. The
+ * first sg list contains unicast addresses, the second is for multicast.
+ * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
+ * is available.
+ */
+struct virtio_net_ctrl_mac {
+ __u32 entries;
+ __u8 macs[][ETH_ALEN];
+} __attribute__((packed));
+
+#define VIRTIO_NET_CTRL_MAC 1
+ #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v5 4/4] virtio_net: Add support for VLAN filtering in the hypervisor
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
` (2 preceding siblings ...)
2009-02-04 19:02 ` [PATCH v5 3/4] virtio_net: Add a MAC filter table Alex Williamson
@ 2009-02-04 19:02 ` Alex Williamson
2009-02-05 0:35 ` [PATCH v5 0/4] virtio_net: Add MAC and VLAN filtering David Miller
4 siblings, 0 replies; 14+ messages in thread
From: Alex Williamson @ 2009-02-04 19:02 UTC (permalink / raw)
To: davem; +Cc: rusty, markmc, netdev, kvm
VLAN filtering allows the hypervisor to drop packets from VLANs
that we're not a part of, further reducing the number of extraneous
packets recieved. This makes use of the VLAN virtqueue command class.
The CTRL_VLAN feature bit tells us whether the backend supports VLAN
filtering.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/net/virtio_net.c | 31 ++++++++++++++++++++++++++++++-
include/linux/virtio_net.h | 14 ++++++++++++++
2 files changed, 44 insertions(+), 1 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index daab9c9..e68813a 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -727,6 +727,30 @@ static void virtnet_set_rx_mode(struct net_device *dev)
kfree(buf);
}
+static void virnet_vlan_rx_add_vid(struct net_device *dev, u16 vid)
+{
+ struct virtnet_info *vi = netdev_priv(dev);
+ struct scatterlist sg;
+
+ sg_set_buf(&sg, &vid, sizeof(vid));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
+ VIRTIO_NET_CTRL_VLAN_ADD, &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to add VLAN ID %d.\n", vid);
+}
+
+static void virnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid)
+{
+ struct virtnet_info *vi = netdev_priv(dev);
+ struct scatterlist sg;
+
+ sg_set_buf(&sg, &vid, sizeof(vid));
+
+ if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
+ VIRTIO_NET_CTRL_VLAN_DEL, &sg, 1, 0))
+ dev_warn(&dev->dev, "Failed to kill VLAN ID %d.\n", vid);
+}
+
static struct ethtool_ops virtnet_ethtool_ops = {
.set_tx_csum = virtnet_set_tx_csum,
.set_sg = ethtool_op_set_sg,
@@ -753,6 +777,8 @@ static const struct net_device_ops virtnet_netdev = {
.ndo_set_mac_address = eth_mac_addr,
.ndo_set_rx_mode = virtnet_set_rx_mode,
.ndo_change_mtu = virtnet_change_mtu,
+ .ndo_vlan_rx_add_vid = virnet_vlan_rx_add_vid,
+ .ndo_vlan_rx_kill_vid = virnet_vlan_rx_kill_vid,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = virtnet_netpoll,
#endif
@@ -877,6 +903,9 @@ static int virtnet_probe(struct virtio_device *vdev)
err = PTR_ERR(vi->svq);
goto free_send;
}
+
+ if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
+ dev->features |= NETIF_F_HW_VLAN_FILTER;
}
/* Initialize our empty receive and send queues. */
@@ -967,7 +996,7 @@ static unsigned int features[] = {
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
- VIRTIO_NET_F_CTRL_RX,
+ VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
VIRTIO_F_NOTIFY_ON_EMPTY,
};
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index ba82b65..242348b 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -25,6 +25,7 @@
#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
+#define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */
#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
@@ -111,4 +112,17 @@ struct virtio_net_ctrl_mac {
#define VIRTIO_NET_CTRL_MAC 1
#define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
+/*
+ * Control VLAN filtering
+ *
+ * The VLAN filter table is controlled via a simple ADD/DEL interface.
+ * VLAN IDs not added may be filterd by the hypervisor. Del is the
+ * opposite of add. Both commands expect an out entry containing a 2
+ * byte VLAN ID. VLAN filterting is available with the
+ * VIRTIO_NET_F_CTRL_VLAN feature bit.
+ */
+#define VIRTIO_NET_CTRL_VLAN 2
+ #define VIRTIO_NET_CTRL_VLAN_ADD 0
+ #define VIRTIO_NET_CTRL_VLAN_DEL 1
+
#endif /* _LINUX_VIRTIO_NET_H */
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v5 0/4] virtio_net: Add MAC and VLAN filtering
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
` (3 preceding siblings ...)
2009-02-04 19:02 ` [PATCH v5 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson
@ 2009-02-05 0:35 ` David Miller
4 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2009-02-05 0:35 UTC (permalink / raw)
To: alex.williamson; +Cc: rusty, markmc, netdev, kvm
From: Alex Williamson <alex.williamson@hp.com>
Date: Wed, 04 Feb 2009 12:02:29 -0700
> This series adds infrastructure for a new control virtqueue and
> makes use of it to support set_rx_mode, unicast and multicast address
> lists, and supporting a hypervisor based VLAN filter. The goal is to
> make the virtio-net device support more of the features of a physical
> NIC and allow the hypervisor to discard packets we don't want. These
> patches are intended for 2.6.30.
>
> This version is just a rebase to current net-next-2.6.git. I'll send
> Rusty an update to the patch in his queue that led to the patch
> conflict, this series doesn't depend on it.
All applied to net-next-2.6, thanks everyone!
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2009-02-05 0:35 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03 19:25 [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering Alex Williamson
2009-02-03 19:25 ` [PATCH v4 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
2009-02-03 19:26 ` [PATCH v4 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
2009-02-03 19:26 ` [PATCH v4 3/4] virtio_net: Add a MAC filter table Alex Williamson
2009-02-03 19:26 ` [PATCH v4 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson
2009-02-03 23:06 ` [PATCH v4 0/4] virtio_net: Add MAC and VLAN filtering David Miller
2009-02-03 23:42 ` Alex Williamson
2009-02-04 4:03 ` Rusty Russell
2009-02-04 19:02 ` [PATCH v5 " Alex Williamson
2009-02-04 19:02 ` [PATCH v5 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
2009-02-04 19:02 ` [PATCH v5 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
2009-02-04 19:02 ` [PATCH v5 3/4] virtio_net: Add a MAC filter table Alex Williamson
2009-02-04 19:02 ` [PATCH v5 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson
2009-02-05 0:35 ` [PATCH v5 0/4] virtio_net: Add MAC and VLAN filtering David Miller
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).