Received: by 10.223.164.202 with SMTP id h10csp1966076wrb; Fri, 24 Nov 2017 04:05:33 -0800 (PST) X-Google-Smtp-Source: AGs4zMbngvaMnEgBKSAh+G8XiJbDdTijz2Uf3NrmTSzIngmg6wLIc9bnquvgT2V8OkOavderI57C X-Received: by 10.98.9.79 with SMTP id e76mr26838131pfd.70.1511525133625; Fri, 24 Nov 2017 04:05:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511525133; cv=none; d=google.com; s=arc-20160816; b=jeN8xEHMx2giECOOMktgrP3Kqb2hqfJdZsTokiTA9WpPYoay9gt6TWBv2J9iJL+9eM NS0/yhxZcFhJ1WsUgGwNgypVSABRVNcsjJg9GwI3amVvXOn/pLsNGnxbdRUPtXkPmhxm 58MFI6G5k5BkGA43iziCYH+5mf1wuDhXEPvsJoOH7lrUKqOF6Qy/bnWt2kfsMs5hijdY bUcYF7jAbk7Qh/g6rbTRDzPCYTpqBvW4B30drKMmN9DwzoqCWF9WHr1J5nTPkUClZrzm iuUmI6xcy7rJSsCJ+BZRJLJMRB7opNxEBAXBv8gsRDyqxR5vZT3k+X1wrlDz+CsepDZa IJ4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=C7UjBuEm+MbUYxpq9T1g5GnqzKr62xC5exe/5Y9uzCs=; b=fMjWLj+SM/xfwzkN2Df13CLgClyNF5qyOxdCI+eZNOdWJOucYyOXBZD/0l5jrw1LeU 19IO0a+y2bH0N3r/NZ3Gcy7ccOn5B4bYn2tAE6B4bBuGVsH0JSTDk8qA48vHVcqvco8C 3jXNnUjeQaNS5a/z02MkQlaV6GoLcdw/cZEvXPFDWBSowbfy7P6NrdfbW2laVjQMKx1m zbRz46mIVOLYhZ/utBoDrR3eozHVB5YZfbg/3mM1CWH4Kv6rjz5hs76pI02Q8Or9t23x IOmpqHmbshsC2+uB1GyoVg+SiFVeVGZ3rK8kn48dm36vmxR9zAEEoVHrhsEu39Bk7D4S 2/eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=WFDLljj2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si18494339plz.207.2017.11.24.04.05.22; Fri, 24 Nov 2017 04:05:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=WFDLljj2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753560AbdKXMD6 (ORCPT + 76 others); Fri, 24 Nov 2017 07:03:58 -0500 Received: from mail-sn1nam02on0046.outbound.protection.outlook.com ([104.47.36.46]:10368 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752762AbdKXMDz (ORCPT ); Fri, 24 Nov 2017 07:03:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=C7UjBuEm+MbUYxpq9T1g5GnqzKr62xC5exe/5Y9uzCs=; b=WFDLljj2tndXrx34pb+EHhdh0wcB2m6/hM+1rEV7p3UqgZfCcPf/1Ecnx0xKl4E2neVJ2DSgu2r/crmSMBPc1clx8/VxHsjOU8sI0IfvrEuFWTjpMfSRslmQkIQsC6ecXB/X7dTmUTp67oRwSkxbAkjVQvmP/X29vvas34zMtrA= Received: from localhost.localdomain (46.242.12.6) by SN2PR07MB2496.namprd07.prod.outlook.com (2603:10b6:804:6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Fri, 24 Nov 2017 12:03:50 +0000 From: Aleksey Makarov To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "Goutham, Sunil" , Robert Richter , Aleksey Makarov , cjacob , Sunil Goutham , linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next] net: thunderx: Add support for xdp redirect Date: Fri, 24 Nov 2017 15:03:26 +0300 Message-Id: <20171124120328.7600-1-aleksey.makarov@cavium.com> X-Mailer: git-send-email 2.15.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [46.242.12.6] X-ClientProxiedBy: AM5P190CA0017.EURP190.PROD.OUTLOOK.COM (2603:10a6:206:14::30) To SN2PR07MB2496.namprd07.prod.outlook.com (2603:10b6:804:6::20) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603199);SRVR:SN2PR07MB2496; X-Microsoft-Exchange-Diagnostics: 1;SN2PR07MB2496;3:mukqln01XvN6bptyUcIlhVey1/dQcYFAJeOdaH2Ok2qA3W1tHkC4x1jzQEY1yH15hLWo1sa41f5cL73tbX7iWSiITQg9H92Uvg++uVSJ+cDztahzrtvzcOzemsA5WbE5/o8gxtQxkxfOnhXJNSE56uSXz6VBqFelXzVTfm/331Z5RqSjJfEECSaC3VP0Eq5TZ+50U8qLXiCgafdMPHoqx3tP1dYstPJdbhOKwIZIk5wANt5e/kWsUQ6pBC6rtiKF;25:s9P/AohbwYD2/JCnSxnY6xyTJMdRhOtCKrpMcmqH5YqqQzspgOEojIXmMmIN58dK+sV93YkXLF5UZWjV2l+J7jUjIiAU/ZL+v51oVhRtfGLqBJ0xooEAK66k23MKgFkehTBzYn2aAYLSbXsWmAgT60mgAW7CyiT4M69VIacXxa4yE/OKN+gmj5YabGkiiQ0JEryrX6QqhWXoVs3N/ui0YWdbrAXxxvhvBl49gAmdmKz4XcXQQBrByXHg+CpIhwcbp6yqXb75ApLtYBnQmub0YmUvxuUu26dXJkdCLswK9SdVSyz4MPc9E5GvOfyB3O4wmvRA1RI/RHByiGqF4DKIL+i8de8muFG+PHNO/+KlenA=;31:J5m5vOtsmqy0pnFf0VXWNWBAh94odNab1Zo/pRf5QtBZVd4ymlpvSnJvsZrurGJYzT8PtfVBQjyCCPK+Qmz9SdfsiJ12dOmkRF8iqmhy5QkD53d6h9dVRPVrbCfFvaeRPk49XSbd09sXUsugVqSSSB3qqrGC9KhRQ0B2tPRKDYizXIUwue9BHR606olGGIrHgNVbUWjVDD2eneUKCtTm0GDSvCzD/VXpqnfoWF7iDQY= X-MS-TrafficTypeDiagnostic: SN2PR07MB2496: X-MS-Office365-Filtering-Correlation-Id: 658c25e3-e3a6-4de7-a2a0-08d533336e71 X-Microsoft-Exchange-Diagnostics: 1;SN2PR07MB2496;20:s0hvYI/h5VDXLQOKF0ITNlPZQLG0JE2TBMm0bEroAxKtWumkFHWdmyr/71qhuVq+HkUyEM4cyu7/0FNNDWQxZ8yPxhyzASYGP5xZKZW3mSVEBiKeDrCaql2tRbx43yZ2pQYft7IxNeBsp7anEXY2oEN8L2yNRlMEMahWI17mum2Oep82BO1cmWKxtnu0FWSbY60qci5jta35JBg+YpwI2DA5tWlmodiVbzR8jF5wZhRS0KGA3hVjjYk+kjrsttcnb1DuFIQRZoBkgY6TS/R0C89mmmBwLszUC545lCTW8Ta515osXazcAjOYh5QQw7hcs2aor15f1wAyukaTlWnZzHQnnVxSaWII0g8RdKLb8p6OpKNE3VRo4iLgfk4Kv8G4vYXJEAd74ymSCMY6w6kZPSLsjdryT+94qtk9Ho8v2TkYxz/oGPIWPm86vQX+pedtwWlQk4FVl68FxoBxwzDXqX1TS2OhTQ8fB3PLV/bJ4EZWcQYD6pzF+v6kDCcJqLdX;4:oDSjdOZ9e/wgJhzM67PSMCtcspm3mJQ+SlqHxqVND6mOP3JZRz9FTuTYz2RHFAYDbd92Rrpuqg8yo0DaHySOS0vYgGndXkVNBzPexItCzQLjNBiOXUYMbHDY7PbpZrp7ONn8SQFtCIavk9F2Sn9iEwb4uJbWjdPmLA6gbzIBW+7x0V4u6Sm7EyZmVxtUuigqdSVxGDIgyQAcozXi28YoauRtxlHTOESCwW6nZsiDnbIArzI5+BjmfQ4KYoXy0YJ5ip+IKmSDSTGnnnaeZ4ol6g== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231022)(6041248)(20161123555025)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:SN2PR07MB2496;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:SN2PR07MB2496; X-Forefront-PRVS: 05015EB482 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(6069001)(346002)(366004)(376002)(199003)(189002)(105586002)(68736007)(106356001)(2906002)(6916009)(6512007)(4326008)(6666003)(5660300001)(2351001)(8936002)(47776003)(51416003)(50986999)(50226002)(66066001)(6506006)(101416001)(53936002)(16526018)(48376002)(25786009)(305945005)(33646002)(6486002)(36756003)(1076002)(3846002)(189998001)(6116002)(86362001)(50466002)(7736002)(316002)(54906003)(52116002)(16586007)(97736004)(8676002)(478600001)(72206003)(81156014)(81166006)(2361001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR07MB2496;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Aleksey.Makarov@cavium.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR07MB2496;23:o6YvG53X31ROasUtpQxJPjgpG/qBP2dl49CGSneWB?= =?us-ascii?Q?h1fOFWLw3jBpyKkUQVfYtgdAsPeViSyNlCVoZTziUSEogizkgrGWI/X8e+/d?= =?us-ascii?Q?mKuk1PUYfxBZLSy+aGjOnPH4HtzzFubWxgwU3U8TnsjWpEn113R/JjXNypTe?= =?us-ascii?Q?JsbwF3sy4aJv90bN3D4wjy+iAqLyqrK1vEEEg0YDK269DP/bfzDQAOSPFSdn?= =?us-ascii?Q?rSIQl881i/5whyBnlXu1UiQbinotlkqMA6nqRWMOUngGtQzoohNHrzkAtFoQ?= =?us-ascii?Q?IqYampKVg/ZgLu8L/ks2icCKjioOfqbIBGgfklEUQZG0X+UDgF5b7EceI1qC?= =?us-ascii?Q?woNtqHWviQg6Zeqjhg9OY5x0xnnX3Gc26wRTjc+Fo/0t0sLaH8WfmJ/ikoLD?= =?us-ascii?Q?2D48PC3/rtJb1swS16VjZNYroCnWhX6nVUHrwOV1xIPr/t8yAI2vTCaTUHdt?= =?us-ascii?Q?mgV0aRHAiSZbx6/dPg6js11L4XoEeZfls1pLL4+uEhsDe7wXvRIv9F4jJgXX?= =?us-ascii?Q?tQ1BIyybXI8Sbompx8nTy9TTfTk+TQ5aK5yKKBu0Ci08zMcVXeAW6qCS1Smq?= =?us-ascii?Q?ZhoSb2gxaxHCdT8KNmAdHTlr/ULzfkX/C1BMexmuheq7U+yZ17PmcW4h6Q0j?= =?us-ascii?Q?tuwBTqkLA2jC/6N25Ff49hZWrTuW6AyzMD5vTatGvipnyAJfsrDikIz3Q36f?= =?us-ascii?Q?B5g1jTWb1kWuQm97361FUx4ZXeGN5HzYE+1kv8LYvuEsUZTyvMic4vPtnVnZ?= =?us-ascii?Q?uLWg5aDw0zZ5e1wW0OqMbQ1A6W+2gGM6t327Ed9lmCSjMNn4tg8f65i6CqxT?= =?us-ascii?Q?ijXpxDa1qsYAmM0Jvc53ddk9qaj8mpfsNqSHAftwWwnRWK4egKAKNUmiHCN9?= =?us-ascii?Q?4W25D59vs9VsfMpbTzCr4bI31bp2XoODh/ZiOD/K30U5CvAiyVSkxlhs2JZz?= =?us-ascii?Q?SgTgZwnFEbJt7Bw/5PxF6SoPoVU8K03qNFyskxcBLGHL6T1n9rqKbmNjcDbf?= =?us-ascii?Q?+Zp9cfCti34ZEsaJF4F9OKKdC+O5KIfaWWN5FtOyouvnJfCbxP8ilMUWmTAb?= =?us-ascii?Q?+BBcVTMaNOsvpaoejUeDipaLyc/cyBqi3DzJzBGxBCLUh5j0mABCy6xKUBaU?= =?us-ascii?Q?hhUqYLeYWRe+e38cCzyyrNm2S0eU9HIGQS4ia+cRPwjrAyI5W2yrQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;SN2PR07MB2496;6:hQIQXwV9+u1PA6YAQjdor9wbxX0o65fQzW9SHBuH/vl2i+d9D/KFHFp3MCNIjzRxNAzJ6kB+4HO1xAXpGrNsW7kOFER+0HnnvEWBe5n7AvEAsoactljrx3EU8/0SwbHIk906tMz5TH6dhhA6XHstqEJZa/7NCLfubhztEwBlUMhS/O0fna3xeSmuLECweZSgMhunsN0ArBGPtWmBiJtVRvbaw4fmZc9JhTaIn7BeAr5pvJM43MDKYYcWyXQwIH6c2pStDUIztOA06Hy/UOxBxHaD9GWvgUi2CcsizPM8z5CcGQTFp88nDZyPGfKo9Qhm/Bd8m4Xvrnvd0Fbjdcg1b3vCrnL6+U3uWv2C/cKpxGM=;5:WhCvUhNadG17jSm/r7jS4eUB1J4UWwh25qo/C5R0NvsZCi+Y4+pehfg6f7xeKTPDltbzRp6l4OnW2laO9e7aGtAl8rteYzlgUQK8Vm8SX+SaCSABZwAlNyggw4V0YgywtDUhv0KGKRiSRw70NoxfFvEXPTj0XVQC0PAKdoElKKE=;24:P2AMcSJeNlvbhQJ0jDP5crOi3Yl+FoEVlD9fRdXVUNVFeefGDh4A2i1CZl+8wA+TQ/EyTTIH6tYt5Q/3gNwHNCsiq685uK6K9OIjDPCdQb8=;7:hkmvkvPQqcXrg2jTvbyZfX+BXG8Vzo8O9tjNkW6WsBlLOV/lbyzKwpl6205yYiGwrf7HOWUIwJSo5dwtcKp2wUef7K2C5LRXTtY5GmXjp1TjpY6blkKqXl0O42hRZihTGqDikIEnrxptCrn20yaxscDDKUHHxS5OBhDguTm7okavKYcx12Wd4Zx+290uj9zHx3iaUPa0L5JyvA4+w9A7DqFa+LD3twiasIZk6ov+187bB8X3mQa+BMm+IB3EwmfE SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2017 12:03:50.5519 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 658c25e3-e3a6-4de7-a2a0-08d533336e71 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR07MB2496 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sunil Goutham This patch adds support for XDP_REDIRECT. Flush is not yet supported. Signed-off-by: Sunil Goutham Signed-off-by: cjacob Signed-off-by: Aleksey Makarov --- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 110 ++++++++++++++++----- drivers/net/ethernet/cavium/thunder/nicvf_queues.c | 11 ++- drivers/net/ethernet/cavium/thunder/nicvf_queues.h | 4 + 3 files changed, 94 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c index a063c36c4c58..b82e28262c57 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c @@ -65,6 +65,11 @@ module_param(cpi_alg, int, S_IRUGO); MODULE_PARM_DESC(cpi_alg, "PFC algorithm (0=none, 1=VLAN, 2=VLAN16, 3=IP Diffserv)"); +struct nicvf_xdp_tx { + u64 dma_addr; + u8 qidx; +}; + static inline u8 nicvf_netdev_qidx(struct nicvf *nic, u8 qidx) { if (nic->sqs_mode) @@ -500,14 +505,29 @@ static int nicvf_init_resources(struct nicvf *nic) return 0; } +static void nicvf_unmap_page(struct nicvf *nic, struct page *page, u64 dma_addr) +{ + /* Check if it's a recycled page, if not unmap the DMA mapping. + * Recycled page holds an extra reference. + */ + if (page_ref_count(page) == 1) { + dma_addr &= PAGE_MASK; + dma_unmap_page_attrs(&nic->pdev->dev, dma_addr, + RCV_FRAG_LEN + XDP_HEADROOM, + DMA_FROM_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC); + } +} + static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog, struct cqe_rx_t *cqe_rx, struct snd_queue *sq, struct sk_buff **skb) { struct xdp_buff xdp; struct page *page; + struct nicvf_xdp_tx *xdp_tx = NULL; u32 action; - u16 len, offset = 0; + u16 len, err, offset = 0; u64 dma_addr, cpu_addr; void *orig_data; @@ -521,7 +541,7 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog, cpu_addr = (u64)phys_to_virt(cpu_addr); page = virt_to_page((void *)cpu_addr); - xdp.data_hard_start = page_address(page); + xdp.data_hard_start = page_address(page) + RCV_BUF_HEADROOM; xdp.data = (void *)cpu_addr; xdp_set_data_meta_invalid(&xdp); xdp.data_end = xdp.data + len; @@ -540,18 +560,7 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog, switch (action) { case XDP_PASS: - /* Check if it's a recycled page, if not - * unmap the DMA mapping. - * - * Recycled page holds an extra reference. - */ - if (page_ref_count(page) == 1) { - dma_addr &= PAGE_MASK; - dma_unmap_page_attrs(&nic->pdev->dev, dma_addr, - RCV_FRAG_LEN + XDP_PACKET_HEADROOM, - DMA_FROM_DEVICE, - DMA_ATTR_SKIP_CPU_SYNC); - } + nicvf_unmap_page(nic, page, dma_addr); /* Build SKB and pass on packet to network stack */ *skb = build_skb(xdp.data, @@ -564,6 +573,20 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog, case XDP_TX: nicvf_xdp_sq_append_pkt(nic, sq, (u64)xdp.data, dma_addr, len); return true; + case XDP_REDIRECT: + /* Save DMA address for use while transmitting */ + xdp_tx = (struct nicvf_xdp_tx *)page_address(page); + xdp_tx->dma_addr = dma_addr; + xdp_tx->qidx = nicvf_netdev_qidx(nic, cqe_rx->rq_idx); + + err = xdp_do_redirect(nic->pnicvf->netdev, &xdp, prog); + if (!err) + return true; + + /* Free the page on error */ + nicvf_unmap_page(nic, page, dma_addr); + put_page(page); + break; default: bpf_warn_invalid_xdp_action(action); /* fall through */ @@ -571,18 +594,7 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog, trace_xdp_exception(nic->netdev, prog, action); /* fall through */ case XDP_DROP: - /* Check if it's a recycled page, if not - * unmap the DMA mapping. - * - * Recycled page holds an extra reference. - */ - if (page_ref_count(page) == 1) { - dma_addr &= PAGE_MASK; - dma_unmap_page_attrs(&nic->pdev->dev, dma_addr, - RCV_FRAG_LEN + XDP_PACKET_HEADROOM, - DMA_FROM_DEVICE, - DMA_ATTR_SKIP_CPU_SYNC); - } + nicvf_unmap_page(nic, page, dma_addr); put_page(page); return true; } @@ -1764,6 +1776,50 @@ static int nicvf_xdp(struct net_device *netdev, struct netdev_bpf *xdp) } } +static int nicvf_xdp_xmit(struct net_device *netdev, struct xdp_buff *xdp) +{ + struct nicvf *nic = netdev_priv(netdev); + struct nicvf *snic = nic; + struct nicvf_xdp_tx *xdp_tx; + struct snd_queue *sq; + struct page *page; + int err, qidx; + + if (!netif_running(netdev) || !nic->xdp_prog) + return -EINVAL; + + page = virt_to_page(xdp->data); + xdp_tx = (struct nicvf_xdp_tx *)page_address(page); + qidx = xdp_tx->qidx; + + if (xdp_tx->qidx >= nic->xdp_tx_queues) + return -EINVAL; + + /* Get secondary Qset's info */ + if (xdp_tx->qidx >= MAX_SND_QUEUES_PER_QS) { + qidx = xdp_tx->qidx / MAX_SND_QUEUES_PER_QS; + snic = (struct nicvf *)nic->snicvf[qidx - 1]; + if (!snic) + return -EINVAL; + qidx = xdp_tx->qidx % MAX_SND_QUEUES_PER_QS; + } + + sq = &snic->qs->sq[qidx]; + err = nicvf_xdp_sq_append_pkt(snic, sq, (u64)xdp->data, + xdp_tx->dma_addr, + xdp->data_end - xdp->data); + if (err) + return -ENOMEM; + + nicvf_xdp_sq_doorbell(snic, sq, qidx); + return 0; +} + +static void nicvf_xdp_flush(struct net_device *dev) +{ + return; +} + static const struct net_device_ops nicvf_netdev_ops = { .ndo_open = nicvf_open, .ndo_stop = nicvf_stop, @@ -1775,6 +1831,8 @@ static const struct net_device_ops nicvf_netdev_ops = { .ndo_fix_features = nicvf_fix_features, .ndo_set_features = nicvf_set_features, .ndo_bpf = nicvf_xdp, + .ndo_xdp_xmit = nicvf_xdp_xmit, + .ndo_xdp_flush = nicvf_xdp_flush, }; static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c index d4496e9afcdf..c47817ff5d55 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c @@ -204,7 +204,7 @@ static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, struct rbdr *rbdr, /* Reserve space for header modifications by BPF program */ if (rbdr->is_xdp) - buf_len += XDP_PACKET_HEADROOM; + buf_len += XDP_HEADROOM; /* Check if it's recycled */ if (pgcache) @@ -224,8 +224,9 @@ static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, struct rbdr *rbdr, nic->rb_page = NULL; return -ENOMEM; } + if (pgcache) - pgcache->dma_addr = *rbuf + XDP_PACKET_HEADROOM; + pgcache->dma_addr = *rbuf + XDP_HEADROOM; nic->rb_page_offset += buf_len; } @@ -1236,7 +1237,7 @@ int nicvf_xdp_sq_append_pkt(struct nicvf *nic, struct snd_queue *sq, int qentry; if (subdesc_cnt > sq->xdp_free_cnt) - return 0; + return -1; qentry = nicvf_get_sq_desc(sq, subdesc_cnt); @@ -1247,7 +1248,7 @@ int nicvf_xdp_sq_append_pkt(struct nicvf *nic, struct snd_queue *sq, sq->xdp_desc_cnt += subdesc_cnt; - return 1; + return 0; } /* Calculate no of SQ subdescriptors needed to transmit all @@ -1624,7 +1625,7 @@ static void nicvf_unmap_rcv_buffer(struct nicvf *nic, u64 dma_addr, if (page_ref_count(page) != 1) return; - len += XDP_PACKET_HEADROOM; + len += XDP_HEADROOM; /* Receive buffers in XDP mode are mapped from page start */ dma_addr &= PAGE_MASK; } diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h index 67d1a3230773..178ab6e8e3c5 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h +++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h @@ -11,6 +11,7 @@ #include #include +#include #include "q_struct.h" #define MAX_QUEUE_SET 128 @@ -92,6 +93,9 @@ #define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \ SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) +#define RCV_BUF_HEADROOM 128 /* To store dma address for XDP redirect */ +#define XDP_HEADROOM (XDP_PACKET_HEADROOM + RCV_BUF_HEADROOM) + #define MAX_CQES_FOR_TX ((SND_QUEUE_LEN / MIN_SQ_DESC_PER_PKT_XMIT) * \ MAX_CQE_PER_PKT_XMIT) -- 2.15.0 From 1586228676832682529@xxx Fri Dec 08 15:05:49 +0000 2017 X-GM-THRID: 1586209759947542554 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread