From patchwork Fri Jan 22 18:48:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 60178 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp27480lbb; Fri, 22 Jan 2016 10:50:29 -0800 (PST) X-Received: by 10.50.134.41 with SMTP id ph9mr4750264igb.71.1453488629377; Fri, 22 Jan 2016 10:50:29 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l15si1147143igk.10.2016.01.22.10.50.27; Fri, 22 Jan 2016 10:50:29 -0800 (PST) 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 Received: by lists.linaro.org (Postfix, from userid 109) id 24E32618E0; Fri, 22 Jan 2016 18:50:27 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=I1UKB9yD; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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 EFD2B61945; Fri, 22 Jan 2016 18:48:32 +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 519B961915; Fri, 22 Jan 2016 18:48:26 +0000 (UTC) Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by lists.linaro.org (Postfix) with ESMTPS id B97E2618E3 for ; Fri, 22 Jan 2016 18:48:24 +0000 (UTC) Received: by mail-wm0-f49.google.com with SMTP id b14so146398531wmb.1 for ; Fri, 22 Jan 2016 10:48:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=3ar9xjKNqcqO95frKIOZNYXrU69s4PqCBCEDeTcvtaA=; b=I1UKB9yDN7OBsxgqEb4y+/eC8jkdoooYItC4rxtAyMjQW98q4NfFNeuwu/g0rQ/IDN KaT2QEKctsJZQCeZyqof/VrLyQNM0oIe0aDS9fhthqnIdicgWdUbjASoS4PkbSOuQKuC F1SgtNOvCwPNuwP/vaiFvHEN8Wf5HeOLb1lRs= 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=3ar9xjKNqcqO95frKIOZNYXrU69s4PqCBCEDeTcvtaA=; b=cEEj4OyXLga+m1nB/pVL5kqQlXQDYaGLVWI0J+y9rvYLKmVWVHQ94zwdHBPtqV0kze STkHm56KLcWRjBmSnGiiyXnxdhibTVi4YRCKYh9b1UfRNkrocDa/XuNtncVyrbV79oo6 jpCMv5I1fmaaoU9mIZXQFQw/YlUNL1EfDyc1BJtjwAkOxCGsRAWMvtRsfQhMUx+iYQjB y6P5yeHoubu4TVIZ6UzrNKfagW9D/C95ZHt5pm0NnVSpgcFzD4SsWpZQ+btCH59WGCvx EzsJZ18CI8wn56mnt0RNTqDq/0nqGGfOtFjAfC37AuJw5X3ccFgtGl+2Nm8VwmMbidx0 1erQ== X-Gm-Message-State: AG10YOR+ExP21gUyfEWknS86bzXG3ZwgnnwGAJom7TAmg3gCKeD24kK/xhJaEyybyECANhrba/A= X-Received: by 10.28.128.215 with SMTP id b206mr5552328wmd.52.1453488503805; Fri, 22 Jan 2016 10:48:23 -0800 (PST) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::1]) by smtp.gmail.com with ESMTPSA id p9sm7085262wjy.41.2016.01.22.10.48.22 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 10:48:22 -0800 (PST) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Fri, 22 Jan 2016 18:48:05 +0000 Message-Id: <1453488486-12176-5-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1453488486-12176-1-git-send-email-stuart.haslam@linaro.org> References: <1453488486-12176-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 4/5] 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 | 57 ++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index 639afa8..b7547e1 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -308,23 +308,70 @@ static int netmap_recv(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[], return num_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;