From: Gregory Haskins <ghaskins@novell.com>
To: linux-kernel@vger.kernel.org
Cc: agraf@suse.de, pmullaney@novell.com, pmorreale@novell.com,
anthony@codemonkey.ws, rusty@rustcorp.com.au,
netdev@vger.kernel.org, kvm@vger.kernel.org
Subject: [RFC PATCH 12/17] venettap: add scatter-gather support
Date: Tue, 31 Mar 2009 14:43:50 -0400 [thread overview]
Message-ID: <20090331184349.28333.41764.stgit@dev.haskins.net> (raw)
In-Reply-To: <20090331184057.28333.77287.stgit@dev.haskins.net>
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---
drivers/vbus/devices/venet-tap.c | 236 +++++++++++++++++++++++++++++++++++++-
1 files changed, 229 insertions(+), 7 deletions(-)
diff --git a/drivers/vbus/devices/venet-tap.c b/drivers/vbus/devices/venet-tap.c
index ccce58e..0ccb7ed 100644
--- a/drivers/vbus/devices/venet-tap.c
+++ b/drivers/vbus/devices/venet-tap.c
@@ -80,6 +80,13 @@ enum {
TX_IOQ_CONGESTED,
};
+struct venettap;
+
+struct venettap_rx_ops {
+ int (*decode)(struct venettap *priv, void *ptr, int len);
+ int (*import)(struct venettap *, struct sk_buff *, void *, int);
+};
+
struct venettap {
spinlock_t lock;
unsigned char hmac[ETH_ALEN]; /* host-mac */
@@ -107,6 +114,12 @@ struct venettap {
struct vbus_memctx *ctx;
struct venettap_queue rxq;
struct venettap_queue txq;
+ struct venettap_rx_ops *rx_ops;
+ struct {
+ struct venet_sg *desc;
+ size_t len;
+ int enabled:1;
+ } sg;
int connected:1;
int opened:1;
int link:1;
@@ -288,6 +301,183 @@ venettap_change_mtu(struct net_device *dev, int new_mtu)
}
/*
+ * ---------------------------
+ * Scatter-Gather support
+ * ---------------------------
+ */
+
+/* assumes reference to priv->vbus.conn held */
+static int
+venettap_sg_decode(struct venettap *priv, void *ptr, int len)
+{
+ struct venet_sg *vsg;
+ struct vbus_memctx *ctx;
+ int ret;
+
+ /*
+ * SG is enabled, so we need to pull in the venet_sg
+ * header before we can interpret the rest of the
+ * packet
+ *
+ * FIXME: Make sure this is not too big
+ */
+ if (unlikely(len > priv->vbus.sg.len)) {
+ kfree(priv->vbus.sg.desc);
+ priv->vbus.sg.desc = kzalloc(len, GFP_KERNEL);
+ }
+
+ vsg = priv->vbus.sg.desc;
+ ctx = priv->vbus.ctx;
+
+ ret = ctx->ops->copy_from(ctx, vsg, ptr, len);
+ BUG_ON(ret);
+
+ /*
+ * Non GSO type packets should be constrained by the MTU setting
+ * on the host
+ */
+ if (!(vsg->flags & VENET_SG_FLAG_GSO)
+ && (vsg->len > (priv->netif.dev->mtu + ETH_HLEN)))
+ return -1;
+
+ return vsg->len;
+}
+
+/*
+ * venettap_sg_import - import an skb in scatter-gather mode
+ *
+ * assumes reference to priv->vbus.conn held
+ */
+static int
+venettap_sg_import(struct venettap *priv, struct sk_buff *skb,
+ void *ptr, int len)
+{
+ struct venet_sg *vsg = priv->vbus.sg.desc;
+ struct vbus_memctx *ctx = priv->vbus.ctx;
+ int remain = len;
+ int ret;
+ int i;
+
+ PDEBUG("Importing %d bytes in %d segments\n", len, vsg->count);
+
+ for (i = 0; i < vsg->count; i++) {
+ struct venet_iov *iov = &vsg->iov[i];
+
+ if (remain < iov->len)
+ return -EINVAL;
+
+ PDEBUG("Segment %d: %p/%d\n", i, iov->ptr, iov->len);
+
+ ret = ctx->ops->copy_from(ctx, skb_tail_pointer(skb),
+ (void *)iov->ptr,
+ iov->len);
+ if (ret)
+ return -EFAULT;
+
+ skb_put(skb, iov->len);
+ remain -= iov->len;
+ }
+
+ if (vsg->flags & VENET_SG_FLAG_NEEDS_CSUM
+ && !skb_partial_csum_set(skb, vsg->csum.start, vsg->csum.offset))
+ return -EINVAL;
+
+ if (vsg->flags & VENET_SG_FLAG_GSO) {
+ struct skb_shared_info *sinfo = skb_shinfo(skb);
+
+ PDEBUG("GSO packet detected\n");
+
+ switch (vsg->gso.type) {
+ case VENET_GSO_TYPE_TCPV4:
+ sinfo->gso_type = SKB_GSO_TCPV4;
+ break;
+ case VENET_GSO_TYPE_TCPV6:
+ sinfo->gso_type = SKB_GSO_TCPV6;
+ break;
+ case VENET_GSO_TYPE_UDP:
+ sinfo->gso_type = SKB_GSO_UDP;
+ break;
+ default:
+ PDEBUG("Illegal GSO type: %d\n", vsg->gso.type);
+ priv->netif.stats.rx_frame_errors++;
+ kfree_skb(skb);
+ return -EINVAL;
+ }
+
+ if (vsg->flags & VENET_SG_FLAG_ECN)
+ sinfo->gso_type |= SKB_GSO_TCP_ECN;
+
+ sinfo->gso_size = vsg->gso.size;
+ if (skb_shinfo(skb)->gso_size == 0) {
+ PDEBUG("Illegal GSO size: %d\n", vsg->gso.size);
+ priv->netif.stats.rx_frame_errors++;
+ kfree_skb(skb);
+ return -EINVAL;
+ }
+
+ /* Header must be checked, and gso_segs computed. */
+ skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
+ skb_shinfo(skb)->gso_segs = 0;
+ }
+
+ return 0;
+}
+
+static struct venettap_rx_ops venettap_sg_rx_ops = {
+ .decode = venettap_sg_decode,
+ .import = venettap_sg_import,
+};
+
+/*
+ * ---------------------------
+ * Flat (non Scatter-Gather) support
+ * ---------------------------
+ */
+
+/* assumes reference to priv->vbus.conn held */
+static int
+venettap_flat_decode(struct venettap *priv, void *ptr, int len)
+{
+ size_t maxlen = priv->netif.dev->mtu + ETH_HLEN;
+
+ if (len > maxlen)
+ return -1;
+
+ /*
+ * If SG is *not* enabled, the length is simply the
+ * descriptor length
+ */
+
+ return len;
+}
+
+/*
+ * venettap_rx_flat - import an skb in non scatter-gather mode
+ *
+ * assumes reference to priv->vbus.conn held
+ */
+static int
+venettap_flat_import(struct venettap *priv, struct sk_buff *skb,
+ void *ptr, int len)
+{
+ struct vbus_memctx *ctx = priv->vbus.ctx;
+ int ret;
+
+ ret = ctx->ops->copy_from(ctx, skb_tail_pointer(skb), ptr, len);
+ if (ret)
+ return -EFAULT;
+
+ skb_put(skb, len);
+
+ return 0;
+}
+
+static struct venettap_rx_ops venettap_flat_rx_ops = {
+ .decode = venettap_flat_decode,
+ .import = venettap_flat_import,
+};
+
+/*
* The poll implementation.
*/
static int
@@ -301,6 +491,7 @@ venettap_rx(struct venettap *priv)
int ret;
unsigned long flags;
struct vbus_connection *conn;
+ struct venettap_rx_ops *rx_ops;
PDEBUG("polling...\n");
@@ -324,6 +515,8 @@ venettap_rx(struct venettap *priv)
ioq = priv->vbus.rxq.queue;
ctx = priv->vbus.ctx;
+ rx_ops = priv->vbus.rx_ops;
+
spin_unlock_irqrestore(&priv->lock, flags);
/* We want to iterate on the head of the in-use index */
@@ -338,11 +531,14 @@ venettap_rx(struct venettap *priv)
* the north side
*/
while (priv->vbus.link && iter.desc->sown) {
- size_t len = iter.desc->len;
- size_t maxlen = priv->netif.dev->mtu + ETH_HLEN;
struct sk_buff *skb = NULL;
+ size_t len;
- if (unlikely(len > maxlen)) {
+ len = rx_ops->decode(priv,
+ (void *)iter.desc->ptr,
+ iter.desc->len);
+
+ if (unlikely(len < 0)) {
priv->netif.stats.rx_errors++;
priv->netif.stats.rx_length_errors++;
goto next;
@@ -360,10 +556,8 @@ venettap_rx(struct venettap *priv)
/* align IP on 16B boundary */
skb_reserve(skb, 2);
- ret = ctx->ops->copy_from(ctx, skb->data,
- (void *)iter.desc->ptr,
- len);
- if (unlikely(ret)) {
+ ret = rx_ops->import(priv, skb, (void *)iter.desc->ptr, len);
+ if (unlikely(ret < 0)) {
priv->netif.stats.rx_errors++;
goto next;
}
@@ -843,6 +1037,23 @@ venettap_macquery(struct venettap *priv, void *data, unsigned long len)
return 0;
}
+static u32
+venettap_negcap_sg(struct venettap *priv, u32 requested)
+{
+ u32 available = VENET_CAP_SG|VENET_CAP_TSO4|VENET_CAP_TSO6
+ |VENET_CAP_ECN;
+ u32 ret;
+
+ ret = available & requested;
+
+ if (ret & VENET_CAP_SG) {
+ priv->vbus.sg.enabled = true;
+ priv->vbus.rx_ops = &venettap_sg_rx_ops;
+ }
+
+ return ret;
+}
+
/*
* Negotiate Capabilities - This function is provided so that the
* interface may be extended without breaking ABI compatability
@@ -870,6 +1081,9 @@ venettap_negcap(struct venettap *priv, void *data, unsigned long len)
return -EFAULT;
switch (caps.gid) {
+ case VENET_CAP_GROUP_SG:
+ caps.bits = venettap_negcap_sg(priv, caps.bits);
+ break;
default:
caps.bits = 0;
break;
@@ -1037,6 +1251,12 @@ venettap_vlink_release(struct vbus_connection *conn)
vbus_memctx_put(priv->vbus.ctx);
kobject_put(priv->vbus.dev.kobj);
+
+ priv->vbus.sg.enabled = false;
+ priv->vbus.rx_ops = &venettap_flat_rx_ops;
+ kfree(priv->vbus.sg.desc);
+ priv->vbus.sg.desc = NULL;
+ priv->vbus.sg.len = 0;
}
static struct vbus_connection_ops venettap_vbus_link_ops = {
@@ -1315,6 +1535,8 @@ venettap_device_create(struct vbus_devclass *dc,
_vdev->ops = &venettap_device_ops;
_vdev->attrs = &venettap_attr_group;
+ priv->vbus.rx_ops = &venettap_flat_rx_ops;
+
/*
* netif init
*/
next prev parent reply other threads:[~2009-03-31 18:43 UTC|newest]
Thread overview: 146+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-31 18:42 [RFC PATCH 00/17] virtual-bus Gregory Haskins
2009-03-31 18:42 ` [RFC PATCH 01/17] shm-signal: shared-memory signals Gregory Haskins
2009-03-31 20:44 ` Avi Kivity
2009-03-31 20:58 ` Gregory Haskins
2009-03-31 21:05 ` Avi Kivity
2009-04-01 12:12 ` Gregory Haskins
2009-04-01 12:24 ` Avi Kivity
2009-04-01 13:57 ` Gregory Haskins
2009-03-31 18:42 ` [RFC PATCH 02/17] vbus: add virtual-bus definitions Gregory Haskins
2009-04-02 16:06 ` Ben Hutchings
2009-04-02 18:13 ` Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 03/17] vbus: add connection-client helper infrastructure Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 04/17] vbus: add bus-registration notifiers Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 05/17] vbus: add a "vbus-proxy" bus model for vbus_driver objects Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 06/17] ioq: Add basic definitions for a shared-memory, lockless queue Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 07/17] ioq: add vbus helpers Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 08/17] venet: add the ABI definitions for an 802.x packet interface Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 09/17] net: Add vbus_enet driver Gregory Haskins
2009-03-31 20:39 ` Stephen Hemminger
2009-04-02 11:43 ` Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 10/17] venet-tap: Adds a "venet" compatible "tap" device to VBUS Gregory Haskins
2009-03-31 18:43 ` [RFC PATCH 11/17] venet: add scatter-gather support Gregory Haskins
2009-03-31 18:43 ` Gregory Haskins [this message]
2009-03-31 18:43 ` [RFC PATCH 13/17] x86: allow the irq->vector translation to be determined outside of ioapic Gregory Haskins
2009-03-31 19:16 ` Alan Cox
2009-03-31 20:02 ` Gregory Haskins
2009-03-31 18:44 ` [RFC PATCH 14/17] kvm: add a reset capability Gregory Haskins
2009-03-31 19:22 ` Avi Kivity
2009-03-31 20:02 ` Gregory Haskins
2009-03-31 20:18 ` Avi Kivity
2009-03-31 20:37 ` Gregory Haskins
2009-03-31 18:44 ` [RFC PATCH 15/17] kvm: add dynamic IRQ support Gregory Haskins
2009-03-31 19:20 ` Avi Kivity
2009-03-31 19:39 ` Gregory Haskins
2009-03-31 20:13 ` Avi Kivity
2009-03-31 20:32 ` Gregory Haskins
2009-03-31 20:59 ` Avi Kivity
2009-03-31 18:44 ` [RFC PATCH 16/17] kvm: Add VBUS support to the host Gregory Haskins
2009-03-31 18:44 ` [RFC PATCH 17/17] kvm: Add guest-side support for VBUS Gregory Haskins
2009-03-31 20:18 ` [RFC PATCH 00/17] virtual-bus Andi Kleen
2009-04-01 12:03 ` Gregory Haskins
2009-04-01 13:23 ` Andi Kleen
2009-04-01 14:19 ` Gregory Haskins
2009-04-01 14:42 ` Gregory Haskins
2009-04-01 17:01 ` Andi Kleen
2009-04-01 18:45 ` Anthony Liguori
2009-04-01 20:40 ` Chris Wright
2009-04-01 21:11 ` Gregory Haskins
2009-04-01 21:28 ` Chris Wright
2009-04-01 22:10 ` Gregory Haskins
2009-04-02 6:00 ` Chris Wright
2009-04-02 3:11 ` Herbert Xu
2009-04-01 21:09 ` Gregory Haskins
2009-04-02 0:29 ` Anthony Liguori
2009-04-02 3:11 ` Gregory Haskins
2009-04-02 6:51 ` Avi Kivity
2009-04-02 8:52 ` Herbert Xu
2009-04-02 9:02 ` Avi Kivity
2009-04-02 9:16 ` Herbert Xu
2009-04-02 9:27 ` Avi Kivity
2009-04-02 9:29 ` Herbert Xu
2009-04-02 9:33 ` Herbert Xu
2009-04-02 9:38 ` Avi Kivity
2009-04-02 9:41 ` Herbert Xu
2009-04-02 9:43 ` Avi Kivity
2009-04-02 9:44 ` Herbert Xu
2009-04-02 11:06 ` Gregory Haskins
2009-04-02 11:59 ` Avi Kivity
2009-04-02 12:30 ` Gregory Haskins
2009-04-02 12:43 ` Avi Kivity
2009-04-02 13:03 ` Gregory Haskins
2009-04-02 12:13 ` Rusty Russell
2009-04-02 12:50 ` Gregory Haskins
2009-04-02 12:52 ` Gregory Haskins
2009-04-02 13:07 ` Avi Kivity
2009-04-02 13:22 ` Gregory Haskins
2009-04-02 13:27 ` Avi Kivity
2009-04-02 14:05 ` Gregory Haskins
2009-04-02 14:50 ` Herbert Xu
2009-04-02 15:00 ` Avi Kivity
2009-04-02 15:40 ` Herbert Xu
2009-04-02 15:57 ` Avi Kivity
2009-04-02 16:09 ` Herbert Xu
2009-04-02 16:54 ` Avi Kivity
2009-04-02 17:06 ` Herbert Xu
2009-04-02 17:17 ` Herbert Xu
2009-04-03 12:25 ` Avi Kivity
2009-04-02 15:10 ` Michael S. Tsirkin
2009-04-03 4:43 ` Jeremy Fitzhardinge
2009-04-02 10:55 ` Gregory Haskins
2009-04-02 11:48 ` Avi Kivity
2009-04-03 10:58 ` Gerd Hoffmann
2009-04-03 11:03 ` Avi Kivity
2009-04-03 11:12 ` Herbert Xu
2009-04-03 11:46 ` Avi Kivity
2009-04-03 11:48 ` Herbert Xu
2009-04-03 11:54 ` Avi Kivity
2009-04-03 11:55 ` Herbert Xu
2009-04-03 12:02 ` Avi Kivity
2009-04-03 13:05 ` Herbert Xu
2009-04-03 11:18 ` Andi Kleen
2009-04-03 11:34 ` Herbert Xu
2009-04-03 11:46 ` Avi Kivity
2009-04-03 11:28 ` Gregory Haskins
2009-04-02 10:46 ` Gregory Haskins
2009-04-02 11:43 ` Avi Kivity
2009-04-02 12:22 ` Gregory Haskins
2009-04-02 12:42 ` Avi Kivity
2009-04-02 12:54 ` Gregory Haskins
2009-04-02 13:08 ` Avi Kivity
2009-04-02 13:36 ` Gregory Haskins
2009-04-02 13:45 ` Avi Kivity
2009-04-02 14:24 ` Gregory Haskins
2009-04-02 14:32 ` Avi Kivity
2009-04-02 14:41 ` Avi Kivity
2009-04-02 14:49 ` Anthony Liguori
2009-04-02 16:09 ` Anthony Liguori
2009-04-02 16:19 ` Avi Kivity
2009-04-02 18:18 ` Anthony Liguori
2009-04-03 1:11 ` Herbert Xu
2009-04-20 18:02 ` Alex Williamson
2009-04-03 12:03 ` Gregory Haskins
2009-04-03 12:15 ` Avi Kivity
2009-04-03 13:13 ` Gregory Haskins
2009-04-03 13:37 ` Avi Kivity
2009-04-03 16:28 ` Gregory Haskins
2009-04-05 10:00 ` Avi Kivity
2009-04-02 3:09 ` Herbert Xu
2009-04-02 6:46 ` Avi Kivity
2009-04-02 8:54 ` Herbert Xu
2009-04-02 9:03 ` Avi Kivity
2009-04-02 9:05 ` Herbert Xu
2009-04-01 20:29 ` Gregory Haskins
2009-04-01 22:23 ` Andi Kleen
2009-04-01 23:05 ` Gregory Haskins
2009-04-01 6:08 ` Rusty Russell
2009-04-01 11:35 ` Gregory Haskins
2009-04-02 1:24 ` Rusty Russell
2009-04-02 2:27 ` Gregory Haskins
2009-04-01 16:10 ` Anthony Liguori
2009-04-05 3:44 ` Rusty Russell
2009-04-05 8:06 ` Avi Kivity
2009-04-05 14:13 ` Anthony Liguori
2009-04-05 16:10 ` Avi Kivity
2009-04-05 16:45 ` Anthony Liguori
2009-04-02 3:15 ` Herbert Xu
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=20090331184349.28333.41764.stgit@dev.haskins.net \
--to=ghaskins@novell.com \
--cc=agraf@suse.de \
--cc=anthony@codemonkey.ws \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pmorreale@novell.com \
--cc=pmullaney@novell.com \
--cc=rusty@rustcorp.com.au \
/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).