From patchwork Wed Oct 28 19:29:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 55717 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp138390lbr; Wed, 28 Oct 2015 12:34:34 -0700 (PDT) X-Received: by 10.140.31.196 with SMTP id f62mr58833292qgf.4.1446060873893; Wed, 28 Oct 2015 12:34:33 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u66si2065954qku.123.2015.10.28.12.34.33; Wed, 28 Oct 2015 12:34:33 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 7763961FE0; Wed, 28 Oct 2015 19:34:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4317062003; Wed, 28 Oct 2015 19:30:21 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 7420361D87; Wed, 28 Oct 2015 19:30:09 +0000 (UTC) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by lists.linaro.org (Postfix) with ESMTPS id 6FCBA61A06 for ; Wed, 28 Oct 2015 19:29:28 +0000 (UTC) Received: by wicll6 with SMTP id ll6so24645753wic.1 for ; Wed, 28 Oct 2015 12:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=mob3Udb3JnAaNscDUIgDNDSdFr5on3JFDnkTFCmRlZQ=; b=wEtwLuYvrUV9Mdh9afIv8+x1aXRXinTCZGpiNuNuNnVKwjbUV4g73uggi+0Ppc7oIF abBwAi18y16Q+iMqxANtqp3sg83QJew0/VY013cN4K4Vva/p9LaodXmzE+zzD1J0GUBv tHLr6+qUhFIJRWVzejXTa1Pb6T76MdBxeEH0ADpWzPALwFryvtHVsjc91I4p94izt8GX YszphHXk3OpalTzBHjems4mWSjlfH2D+RWJdU4lxJdW8Y6aQulyzpWCHjPzas74VNxMt aZuA/Mn39deZv6e8+GMr3VUDs1C5N4FC7otgDC5gDGybZ8yuL52H53c7xt9Jqtn7T+ZM RySQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=mob3Udb3JnAaNscDUIgDNDSdFr5on3JFDnkTFCmRlZQ=; b=HtZ8YPezccndGc2BxEs6m4rsao0tbpFo3vz+RIqaylTmHduLw0KiJR/MEV43bsnEkO GW2Xg9L84WSXhwdMKykLYLUzP/udoO+RyCUxZjsHvKYjqQrcUQ6QJejyvULLq89TdFnA xdUFPiaXW+M62b5hyjDmzNvT0O9zIo/fHQgw/sCUSkaLzKzL8AQ4azPdgUguE9Slg6Kk W5ABxHZvziYOqUNdaUhC3CiH7hI6aNA3IEXdRRsZNaz8uPb3qzumCFHsEJdi1hW9wGdK BucazYNIepibKMEpFfj15R5uBk5ZPi31Zf3IljgFS6t3ToQdi/Ho2MXW7wmFw7GQeFvx X2cQ== X-Gm-Message-State: ALoCoQkcR9nqFgKPuznURSMD967KTUqST88gG3dqxPWzVbzU3na7ARZF38xaY3h4UQG1K2TI/wSx X-Received: by 10.180.74.80 with SMTP id r16mr4658788wiv.88.1446060567680; Wed, 28 Oct 2015 12:29:27 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id h4sm31286154wjx.41.2015.10.28.12.29.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Oct 2015 12:29:27 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Wed, 28 Oct 2015 19:29:09 +0000 Message-Id: <1446060551-21029-8-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1446060551-21029-1-git-send-email-stuart.haslam@linaro.org> References: <1446060551-21029-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 7/9] linux-generic: netmap: support segmented packets X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Replace the nm_inject() helper with our own version so that odp_packet_copydata_out() can be used as this understands segmented packets. Signed-off-by: Stuart Haslam --- platform/linux-generic/pktio/netmap.c | 59 ++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index 7d47fc1..d72af3d 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -268,32 +268,81 @@ static int netmap_recv(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[], return args.nb_rx; } +static struct netmap_ring *netmap_tx_ring(struct nm_desc *d) +{ + unsigned c, n = d->last_tx_ring - d->first_tx_ring + 1; + + for (c = 0; c < n ; c++) { + struct netmap_ring *ring; + unsigned ri = d->cur_tx_ring + c; + + if (ri > d->last_tx_ring) + ri = d->first_tx_ring; + ring = NETMAP_TXRING(d->nifp, ri); + if (nm_ring_empty(ring)) + continue; + + return ring; + } + + return NULL; +} + +static int netmap_inject(struct nm_desc *d, odp_packet_t pkt) +{ + struct netmap_ring *ring; + unsigned i; + uint32_t pkt_len = odp_packet_len(pkt); + uint32_t offset = 0; + char *buf; + + ring = netmap_tx_ring(d); + if (!ring) + return 0; + + if (pkt_len > ring->nr_buf_size) { + __odp_errno = -EMSGSIZE; + return 0; + } + + i = ring->cur; + ring->slot[i].flags = 0; + ring->slot[i].len = pkt_len; + buf = NETMAP_BUF(ring, ring->slot[i].buf_idx); + + if (odp_packet_copydata_out(pkt, offset, pkt_len, buf)) + return 0; + + ring->cur = nm_ring_next(ring, i); + ring->head = ring->cur; + + return 1; +} + static int netmap_send(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[], unsigned num) { struct pollfd polld; struct nm_desc *nm_desc = pktio_entry->s.pkt_nm.tx_desc; unsigned i, nb_tx; - uint8_t *frame; - uint32_t frame_len; polld.fd = nm_desc->fd; polld.events = POLLOUT; for (nb_tx = 0; nb_tx < num; nb_tx++) { - frame_len = 0; - frame = odp_packet_l2_ptr(pkt_table[nb_tx], &frame_len); for (i = 0; i < NM_INJECT_RETRIES; i++) { - if (nm_inject(nm_desc, frame, frame_len) == 0) + if (netmap_inject(nm_desc, pkt_table[nb_tx]) == 0) poll(&polld, 1, 0); else break; } + if (odp_unlikely(i == NM_INJECT_RETRIES)) { ioctl(nm_desc->fd, NIOCTXSYNC, NULL); break; } } + /* Send pending packets */ poll(&polld, 1, 0);