From patchwork Thu May 30 18:20:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 10969167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BEB018EC for ; Thu, 30 May 2019 18:21:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EBA42003F for ; Thu, 30 May 2019 18:21:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3317728C01; Thu, 30 May 2019 18:21:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2587F28BF9 for ; Thu, 30 May 2019 18:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbfE3SUy (ORCPT ); Thu, 30 May 2019 14:20:54 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35417 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726563AbfE3SUx (ORCPT ); Thu, 30 May 2019 14:20:53 -0400 Received: by mail-lj1-f194.google.com with SMTP id h11so7043542ljb.2 for ; Thu, 30 May 2019 11:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AdSMTsu+LtgUCnPNRXGwSYsCPQyqbNfQqw5/RcvDJNQ=; b=NTEyy87mbpZennf/zO3UY3SG/jU34eWt9oBeag4D8YjahXlGpvo7jFJ45TsemIdnir GDDTpbKLurGeDuALSvM6j7s2xNdezurfEaq3Do0FdVu1zSrcVUfBnzEjlX9CPvMPhzYJ syvG28Ahiha6P8q/z1kIyl0178d00DQHN+sX/j5wk8ko44/63zLEGfJyi7VPUdIJ0LKG TgaTpYJ6tpJG3xAZrI95TMKLk8q+WGk0L19nUTHjuhUVz5EeWBCSPoZe7eWVxtRSZtYW kYjH1/WFTyKdQ+VO2y6VV9nuGp1SruffgOv8KjxhvVfDhLZ+qlpEcUfBKzBd6xbaakTA 2nxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AdSMTsu+LtgUCnPNRXGwSYsCPQyqbNfQqw5/RcvDJNQ=; b=atkEAd17L3Ot1URjgyv5ppJb7d1oozV0drsRSER3IkEcYvXagUi1lH0etc9Conul2l V5k57L212MzaiytXMmDk5elM6WPZacLd5QylDSnj8X9bN47gffHm9e3qOdR0XvHHWy6V YXnlDVjaMYdVWe6D2EEGN1oUHOVs732im+2SicwroyqOavjCx39MVyuV6WahTIp+fgON RhYhNahBz4FTGrQA4x6ZcDE6aZFret/FkZtMpE77w99Ue2uX6LLkFxSpsBRjOZdrJneI ikqxHXvwi0EgmgJkWFWgQHLwO3xt9erkAna8ZOUp5f0AABofLu3jHRN/S4ENHJSYUYbu hBhw== X-Gm-Message-State: APjAAAVRWGBXshsXC2xbfIHzk4KFir31kDkGceJkiETw9alScrPnK1tu qCj6ykuEqGgRxH72qT8qiQ4/eA== X-Google-Smtp-Source: APXvYqwcOOLVdQF2eRwE44U7qP1o+9tRsDYFuMaBYPD6l5MItx//FH0w80EsZyjHpAQDOz9EOA3SFQ== X-Received: by 2002:a2e:9756:: with SMTP id f22mr3083605ljj.30.1559240451067; Thu, 30 May 2019 11:20:51 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id v7sm388946lfe.11.2019.05.30.11.20.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 11:20:50 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Jesper Dangaard Brouer , Ivan Khoronzhuk Subject: [PATCH v2 net-next 1/7] net: page_pool: add helper function to retrieve dma addresses Date: Thu, 30 May 2019 21:20:33 +0300 Message-Id: <20190530182039.4945-2-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> References: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ilias Apalodimas On a previous patch dma addr was stored in 'struct page'. Use that to retrieve DMA addresses used by network drivers Signed-off-by: Ilias Apalodimas Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Ivan Khoronzhuk --- include/net/page_pool.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/net/page_pool.h b/include/net/page_pool.h index 694d055e01ef..b885d86cb7a1 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -132,6 +132,11 @@ static inline void page_pool_recycle_direct(struct page_pool *pool, __page_pool_put_page(pool, page, true); } +static inline dma_addr_t page_pool_get_dma_addr(struct page *page) +{ + return page->dma_addr; +} + static inline bool is_page_pool_compiled_in(void) { #ifdef CONFIG_PAGE_POOL From patchwork Thu May 30 18:20:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 10969169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF6E516C1 for ; Thu, 30 May 2019 18:21:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A17E62003F for ; Thu, 30 May 2019 18:21:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9637B26242; Thu, 30 May 2019 18:21:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45A0428BFC for ; Thu, 30 May 2019 18:21:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726125AbfE3SVp (ORCPT ); Thu, 30 May 2019 14:21:45 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:40478 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbfE3SUy (ORCPT ); Thu, 30 May 2019 14:20:54 -0400 Received: by mail-lf1-f66.google.com with SMTP id a9so4375301lff.7 for ; Thu, 30 May 2019 11:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J8udFRfvbZ6fXOojTQ4C0YPBDnze74Ovvj+f7jr19Fw=; b=wU1WwXoEjKxZ3uqM80S4B/iacjxdOKTanw/C0MhErCrltoOGbqOgl6D3+r1s/I5MDs 43CeGw6Y6RckooIj+upDJFUOq/x8S44sRl4IecU2CAs9bIntSdh8qHidWHvG+s5sZZwr tMo1h8S1ts9QZr8NNUvE3T9naG3R4FHAPT23kfi5+VV7aUci43qWu5ZZWJKAHQleHoEy /ajuUGqlAVxb3HPheATiiuEdAXwo7PokCTbdy4XNP9sZTvD5RheyUk1vZwg8Azp9xD2i pnBXFBTfRa7tQ02r91dRnH9CWokN/c7+ti7EZKQlpvZEfndG6pFqlRF4421kR1+T9DU1 CSjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J8udFRfvbZ6fXOojTQ4C0YPBDnze74Ovvj+f7jr19Fw=; b=O+NqlGja01yyuVieXE+tp/m5HwVJKQAjwgA4zpj8IeR9XzNw/d0BVHfObYjGOadVxc wDsSRMv4OmYbzmQnXJUQ99SDlXOSrFPUJsuQSj3Bnn4y3dLsd55iyY3HgiNyHwwwRn4b Db+jAoGPtndLPvRqX0aiKyzQlDlLcCmlwMFZ3xhWrQrF/MIzgivTHX+ED5H/O7BK+pWA C/iVMrCBKzTNQKEfbG5zextnnDECzh9WN0uWuNa998GVNMDKB/NAVFrteuLjIOWApD/U 8Qpx2jxIur5yM+ztZ5SeHJD8KMLUNrfdlbBcBbfUPmhWsFNHGzuXrwchR3rQKQ8V7mB4 Sgsw== X-Gm-Message-State: APjAAAWbivcoKA+7L1gW7J+5um+CcAbPXXYHe9d9mfDHTV2pesb69OwW nggJZKx2gJz431Ur3tLRJTEasA== X-Google-Smtp-Source: APXvYqzmIrTETx9SuLnFJbbk7eE7VgPvlT6tOo6LaT1WkjJJjIEn1SeLZrsHAr7qOO6dBn1fCt8qbg== X-Received: by 2002:ac2:494f:: with SMTP id o15mr2908131lfi.22.1559240452479; Thu, 30 May 2019 11:20:52 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id v7sm388946lfe.11.2019.05.30.11.20.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 11:20:51 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Jesper Dangaard Brouer , Ivan Khoronzhuk Subject: [PATCH v2 net-next 2/7] net: page_pool: add helper function to unmap dma addresses Date: Thu, 30 May 2019 21:20:34 +0300 Message-Id: <20190530182039.4945-3-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> References: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ilias Apalodimas On a previous patch dma addr was stored in 'struct page'. Use that to unmap DMA addresses used by network drivers Signed-off-by: Ilias Apalodimas Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Ivan Khoronzhuk --- include/net/page_pool.h | 1 + net/core/page_pool.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/net/page_pool.h b/include/net/page_pool.h index b885d86cb7a1..ad218cef88c5 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -110,6 +110,7 @@ static inline struct page *page_pool_dev_alloc_pages(struct page_pool *pool) struct page_pool *page_pool_create(const struct page_pool_params *params); void page_pool_destroy(struct page_pool *pool); +void page_pool_unmap_page(struct page_pool *pool, struct page *page); /* Never call this directly, use helpers below */ void __page_pool_put_page(struct page_pool *pool, diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 5b2252c6d49b..205af7bd6d09 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -190,6 +190,13 @@ static void __page_pool_clean_page(struct page_pool *pool, page->dma_addr = 0; } +/* unmap the page and clean our state */ +void page_pool_unmap_page(struct page_pool *pool, struct page *page) +{ + __page_pool_clean_page(pool, page); +} +EXPORT_SYMBOL(page_pool_unmap_page); + /* Return a page to the page allocator, cleaning up our state */ static void __page_pool_return_page(struct page_pool *pool, struct page *page) { From patchwork Thu May 30 18:20:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 10969165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13BB318EC for ; Thu, 30 May 2019 18:21:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 077C728BDD for ; Thu, 30 May 2019 18:21:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEA0928BE8; Thu, 30 May 2019 18:21:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9925B2003F for ; Thu, 30 May 2019 18:21:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726941AbfE3SVd (ORCPT ); Thu, 30 May 2019 14:21:33 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34314 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbfE3SUz (ORCPT ); Thu, 30 May 2019 14:20:55 -0400 Received: by mail-lj1-f196.google.com with SMTP id j24so7049758ljg.1 for ; Thu, 30 May 2019 11:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ksgNqXYuq7eYRSzBEvTxTsDgmGrsQMBHFwlmQvvNPkE=; b=GxvvJPDKMnF2Hc4YuIT4oM82YGKw8EcaMBLqKbLD6yc2xy1Jwtfbwfeyw6rJBMcxpP /8u5FHFV1Sy3qbcFK5Wmocu4voUWgTi5jFxXDOxc+ngyfsy4lqfvlE7oHUr+L6qZH+eX ueuXJk6RvJCOHnaTzXvc+TlemnLRktzO0mQfYVU9yC3NpOn2npdhCibuxqDZHEu55r80 3ZvBQY3uUcxW/C9LniDNuWN/a3zoHFJ2gJI3hYCe/2Td//7W/9ecVrlJaVueUFNuH3iF nCFCRSOlgR596k+Vvo6qoZ/d/mlLBZ1dEtqBninfkrngveooWNd17Db8p+jox/7w0ASv o/Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ksgNqXYuq7eYRSzBEvTxTsDgmGrsQMBHFwlmQvvNPkE=; b=KGkEc4OcUodS4XMHF+0t1Mb0rXej4c6WNLpcUujFwQZNZhBriiJuoh8p/A+Xbaq36V sq0MD475fnxATefsBACUwirkcIQ0nqF1Gg4wV9aFmlEshRUGddAWnGXoe7jw2eS6lYLV VGjT8QstIKGguWnZud2hiK4No+W9T/KlLP+k2kH/7wm/Gir/Lf4uI25ycEe/1Qb5YLTw A4oqITI2yWZt2Jm1i8FNYyAziLMUN6LXNNc3pB1Q20gcoBfpSfXalpYzKEFy3toVwqI8 93qvlNvQm+TZ3XzNQn79BQbfl0w9gDAeBG5N4kmrPUc+NTgE5JBdiEeHvFETKs9xBpzS msww== X-Gm-Message-State: APjAAAVKhdp6DW1HwzyeIiUStDDDT0ufxVeoLNlzGAezIcJNb+xfBk/2 PjAjBSEaoQfcZbqZ2SGL2WDYpA== X-Google-Smtp-Source: APXvYqy7hb7ALHTHh96K5zrKV05mrOIrhkcfG5OPW6qXfaO6Jy/BSI/AMhpabp61GGx5Y2leoIFiTA== X-Received: by 2002:a2e:88c7:: with SMTP id a7mr2713139ljk.118.1559240453797; Thu, 30 May 2019 11:20:53 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id v7sm388946lfe.11.2019.05.30.11.20.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 11:20:53 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Ivan Khoronzhuk Subject: [PATCH v2 net-next 3/7] net: ethernet: ti: cpsw: use cpsw as drv data Date: Thu, 30 May 2019 21:20:35 +0300 Message-Id: <20190530182039.4945-4-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> References: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No need to set ndev for drvdata when mainly cpsw reference is needed, so correct this legacy decision. Signed-off-by: Ivan Khoronzhuk Reviewed-by: Grygorii Strashko --- drivers/net/ethernet/ti/cpsw.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 6d3f1f3f90cb..3430503e1053 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -2265,8 +2265,7 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data, static void cpsw_remove_dt(struct platform_device *pdev) { - struct net_device *ndev = platform_get_drvdata(pdev); - struct cpsw_common *cpsw = ndev_to_cpsw(ndev); + struct cpsw_common *cpsw = platform_get_drvdata(pdev); struct cpsw_platform_data *data = &cpsw->data; struct device_node *node = pdev->dev.of_node; struct device_node *slave_node; @@ -2477,7 +2476,7 @@ static int cpsw_probe(struct platform_device *pdev) goto clean_cpts; } - platform_set_drvdata(pdev, ndev); + platform_set_drvdata(pdev, cpsw); priv = netdev_priv(ndev); priv->cpsw = cpsw; priv->ndev = ndev; @@ -2570,9 +2569,8 @@ static int cpsw_probe(struct platform_device *pdev) static int cpsw_remove(struct platform_device *pdev) { - struct net_device *ndev = platform_get_drvdata(pdev); - struct cpsw_common *cpsw = ndev_to_cpsw(ndev); - int ret; + struct cpsw_common *cpsw = platform_get_drvdata(pdev); + int i, ret; ret = pm_runtime_get_sync(&pdev->dev); if (ret < 0) { @@ -2580,9 +2578,9 @@ static int cpsw_remove(struct platform_device *pdev) return ret; } - if (cpsw->data.dual_emac) - unregister_netdev(cpsw->slaves[1].ndev); - unregister_netdev(ndev); + for (i = 0; i < cpsw->data.slaves; i++) + if (cpsw->slaves[i].ndev) + unregister_netdev(cpsw->slaves[i].ndev); cpts_release(cpsw->cpts); cpdma_ctlr_destroy(cpsw->dma); From patchwork Thu May 30 18:20:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 10969161 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1778112C for ; Thu, 30 May 2019 18:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B44CF28C0A for ; Thu, 30 May 2019 18:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A80F528BF2; Thu, 30 May 2019 18:21:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 358E228BEE for ; Thu, 30 May 2019 18:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbfE3SU5 (ORCPT ); Thu, 30 May 2019 14:20:57 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:45548 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726747AbfE3SU5 (ORCPT ); Thu, 30 May 2019 14:20:57 -0400 Received: by mail-lj1-f196.google.com with SMTP id r76so6996390lja.12 for ; Thu, 30 May 2019 11:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7Z+hJ2xpe6chUPepscBLPDGl6ohx6IXf3hvf84qy8k8=; b=uhOmPRjvEPSqocDDlrLrJvOMrG4BmMTmoKHMBhVYAOxkMPgQwKo8MLA+oUcoZpnE73 dmiFzXl+QuZrAp0Lgucvbbs/79sKAtpwEPKLe+oVyi9gpnJmlqdmQWFthozqsJ7vAlib O5ziXaNoSYxVerDq2kopFdPMRnnstnvVV+oXSSGa8KaD2zcWoIZqMQTCOKKkN2oZxBYH QXagZkmO/GrHY+9MvwRB2j/wtFTdc9VllDwFrNei7AQgikvYzJ4CyR3Aqnd1qkd/6ahV PUicArdA8GgZMhQv7A5UXBQJCzMMl0d5wd3whOjnjuW8jmjn5lApMHzCIAyDszBD+YcR T0hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7Z+hJ2xpe6chUPepscBLPDGl6ohx6IXf3hvf84qy8k8=; b=MqZ8wJnl6OmH0rHSh5syMvjFqeDauTGMpIAAlrknGew1KboHu/7tFVGMipUq5uyNf0 BHxTUJ8ddyzNMxeivat0P7pryNCFdud4tKszVoXrVR2/c0d4SqCfhrtM+Xt9gr+5oHwc hywvxjRV5sBiSaIhjwlrl67Tje7A/XI96va9URUxglYF2k8Fibg0LEI8Kv0NCpbuCIVJ ELKtv39cKq21GeWCEiBdabbzlsLKJyTbkeY3k5v1qAa9iWqfmFxHnXAdwqk/YOu20Ma7 AzPEEgIk1xptE5pzDBcydKqwtUfyTIaHzgIquDgQn2fsN3bx3nldn1EjTLFKkyEsh6Hd 7w2Q== X-Gm-Message-State: APjAAAWpA1CKrfxEtJrVOw8cnjE31TqPcj8paJBcohtTPYsEs0rWU5Po W0PPy8UyBSemZdNrgFmjY6QRhQ== X-Google-Smtp-Source: APXvYqwqZIOoXCsEeTno321JHOUaxvSb9pUFwirU22e1UX6ErOyOq9neJwpkmyIFY2XvP7TweKdhLw== X-Received: by 2002:a05:651c:93:: with SMTP id 19mr2944496ljq.213.1559240455046; Thu, 30 May 2019 11:20:55 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id v7sm388946lfe.11.2019.05.30.11.20.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 11:20:54 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Ivan Khoronzhuk Subject: [PATCH v2 net-next 4/7] net: ethernet: ti: cpsw_ethtool: simplify slave loops Date: Thu, 30 May 2019 21:20:36 +0300 Message-Id: <20190530182039.4945-5-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> References: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Only for consistency reasons, do it like in main cpsw.c module and use ndev reference but not by means of slave. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw_ethtool.c | 40 ++++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw_ethtool.c b/drivers/net/ethernet/ti/cpsw_ethtool.c index a4a7ec0d2531..c260bb32aacf 100644 --- a/drivers/net/ethernet/ti/cpsw_ethtool.c +++ b/drivers/net/ethernet/ti/cpsw_ethtool.c @@ -458,7 +458,6 @@ int cpsw_nway_reset(struct net_device *ndev) static void cpsw_suspend_data_pass(struct net_device *ndev) { struct cpsw_common *cpsw = ndev_to_cpsw(ndev); - struct cpsw_slave *slave; int i; /* Disable NAPI scheduling */ @@ -467,12 +466,13 @@ static void cpsw_suspend_data_pass(struct net_device *ndev) /* Stop all transmit queues for every network device. * Disable re-using rx descriptors with dormant_on. */ - for (i = cpsw->data.slaves, slave = cpsw->slaves; i; i--, slave++) { - if (!(slave->ndev && netif_running(slave->ndev))) + for (i = 0; i < cpsw->data.slaves; i++) { + ndev = cpsw->slaves[i].ndev; + if (!(ndev && netif_running(ndev))) continue; - netif_tx_stop_all_queues(slave->ndev); - netif_dormant_on(slave->ndev); + netif_tx_stop_all_queues(ndev); + netif_dormant_on(ndev); } /* Handle rest of tx packets and stop cpdma channels */ @@ -483,13 +483,14 @@ static int cpsw_resume_data_pass(struct net_device *ndev) { struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = priv->cpsw; - struct cpsw_slave *slave; int i, ret; /* Allow rx packets handling */ - for (i = cpsw->data.slaves, slave = cpsw->slaves; i; i--, slave++) - if (slave->ndev && netif_running(slave->ndev)) - netif_dormant_off(slave->ndev); + for (i = 0; i < cpsw->data.slaves; i++) { + ndev = cpsw->slaves[i].ndev; + if (ndev && netif_running(ndev)) + netif_dormant_off(ndev); + } /* After this receive is started */ if (cpsw->usage_count) { @@ -502,9 +503,11 @@ static int cpsw_resume_data_pass(struct net_device *ndev) } /* Resume transmit for every affected interface */ - for (i = cpsw->data.slaves, slave = cpsw->slaves; i; i--, slave++) - if (slave->ndev && netif_running(slave->ndev)) - netif_tx_start_all_queues(slave->ndev); + for (i = 0; i < cpsw->data.slaves; i++) { + ndev = cpsw->slaves[i].ndev; + if (ndev && netif_running(ndev)) + netif_tx_start_all_queues(ndev); + } return 0; } @@ -587,7 +590,6 @@ int cpsw_set_channels_common(struct net_device *ndev, { struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = priv->cpsw; - struct cpsw_slave *slave; int i, ret; ret = cpsw_check_ch_settings(cpsw, chs); @@ -604,20 +606,20 @@ int cpsw_set_channels_common(struct net_device *ndev, if (ret) goto err; - for (i = cpsw->data.slaves, slave = cpsw->slaves; i; i--, slave++) { - if (!(slave->ndev && netif_running(slave->ndev))) + for (i = 0; i < cpsw->data.slaves; i++) { + struct net_device *ndev = cpsw->slaves[i].ndev; + + if (!(ndev && netif_running(ndev))) continue; /* Inform stack about new count of queues */ - ret = netif_set_real_num_tx_queues(slave->ndev, - cpsw->tx_ch_num); + ret = netif_set_real_num_tx_queues(ndev, cpsw->tx_ch_num); if (ret) { dev_err(priv->dev, "cannot set real number of tx queues\n"); goto err; } - ret = netif_set_real_num_rx_queues(slave->ndev, - cpsw->rx_ch_num); + ret = netif_set_real_num_rx_queues(ndev, cpsw->rx_ch_num); if (ret) { dev_err(priv->dev, "cannot set real number of rx queues\n"); goto err; From patchwork Thu May 30 18:20:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 10969163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BB3F16C1 for ; Thu, 30 May 2019 18:21:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D8F928BE8 for ; Thu, 30 May 2019 18:21:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51E1828BEE; Thu, 30 May 2019 18:21:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDDB628C12 for ; Thu, 30 May 2019 18:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726275AbfE3SV1 (ORCPT ); Thu, 30 May 2019 14:21:27 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34316 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726784AbfE3SU6 (ORCPT ); Thu, 30 May 2019 14:20:58 -0400 Received: by mail-lj1-f195.google.com with SMTP id j24so7049857ljg.1 for ; Thu, 30 May 2019 11:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ExBErmLKvAHAcEzB9N5VayIpTNJEe2yiC9dz/BkkizE=; b=DcysaYWnCA1gnUMQaWDrdM5fQsKXmvdSPN7uBZWkhioCiDLFa/PZca+gwzO2ODZUGu BeqQ+XolNN1zZDMTBmlKogUA2ykS1A4uAec4bRAsZhEtEMqU59dDLFjPagim1uxmY0lL mYZK46TUMEvcTcJPNwOjwXTifyAGBy+Sf6AWebORVwLTh5xL5ZEd8YUB1gdlmYUz/HUN hrG5hxWv80I9c88FHZtuPOuKMIQY+GL7Pf5NNtewzWkmUTEa/0ufXtD0h/glN9glpD6N KvdKGzssnzlj4lACSGsq3eQP9WVFBfMKqdFZIwUMep/1p/kimoUqfozrxCBUHF9SNaD+ WadQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ExBErmLKvAHAcEzB9N5VayIpTNJEe2yiC9dz/BkkizE=; b=UpKlc6kDYtkpaA+j/QBrzq5aU9TkZrZaYPfWsSGlV9yw0xefKORgyVkgZCMrf9BDaO U1pTBXWFdMSqViSD8QyNT/+IJq0f1TY/gsOVvNvs3TWzDNCoWRbSJqUTxveT5FD+l6mr 4NPnHPOCdU+IYnJr1mTfROF+dPYx+beTWL+C5eaMxPOs5Z1YmyiDrxjlDn+HwuYNjZMM 8MZ2IdhfVWx+kvh4vYUGT/mCuPFdl9BWRiJSwJHy1/E0pMzwRxH4JsdH2Y4tK1CEmKOG dN3ioqnEmKV8WWOhGtFsVHG0NpC23kmTudu67SsHpCuVQq3rHOixAk2CBN1hERBHvtwD OMvg== X-Gm-Message-State: APjAAAWOZaQ7pnNMM3hcZroyo5vy8V/YoGi0GJZIhepQuATSLXEkRKBM l9xmc7Ed2SRR3oBvNg7vs64Few== X-Google-Smtp-Source: APXvYqybCMzLDu/j6u6rw70BPBf8lJXbao7SvLBHv4ExBZ/aAFxGO8ulZf+NzRyoc28S/5OHUWX0yg== X-Received: by 2002:a2e:8555:: with SMTP id u21mr2920911ljj.133.1559240456396; Thu, 30 May 2019 11:20:56 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id v7sm388946lfe.11.2019.05.30.11.20.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 11:20:55 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Ivan Khoronzhuk Subject: [PATCH v2 net-next 5/7] net: ethernet: ti: davinci_cpdma: add dma mapped submit Date: Thu, 30 May 2019 21:20:37 +0300 Message-Id: <20190530182039.4945-6-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> References: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case if dma mapped packet needs to be sent, like with XDP page pool, the "mapped" submit can be used. This patch adds dma mapped submit based on regular one. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/davinci_cpdma.c | 88 ++++++++++++++++++++----- drivers/net/ethernet/ti/davinci_cpdma.h | 2 + 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 35bf14d8e7af..7f89b2299f05 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -125,6 +125,15 @@ struct cpdma_chan { u32 rate; }; +struct submit_info { + struct cpdma_chan *chan; + int directed; + void *token; + void *data; + int flags; + int len; +}; + struct cpdma_control_info { u32 reg; u32 shift, mask; @@ -176,6 +185,8 @@ static struct cpdma_control_info controls[] = { (directed << CPDMA_TO_PORT_SHIFT)); \ } while (0) +#define CPDMA_DMA_EXT_MAP BIT(16) + static void cpdma_desc_pool_destroy(struct cpdma_ctlr *ctlr) { struct cpdma_desc_pool *pool = ctlr->pool; @@ -1002,10 +1013,12 @@ static void __cpdma_chan_submit(struct cpdma_chan *chan, } } -int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, - int len, int directed) +static int cpdma_chan_submit_si(struct submit_info *si) { + struct cpdma_chan *chan = si->chan; struct cpdma_ctlr *ctlr = chan->ctlr; + int len = si->len; + int swlen = len; struct cpdma_desc __iomem *desc; dma_addr_t buffer; unsigned long flags; @@ -1037,16 +1050,22 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, chan->stats.runt_transmit_buff++; } - buffer = dma_map_single(ctlr->dev, data, len, chan->dir); - ret = dma_mapping_error(ctlr->dev, buffer); - if (ret) { - cpdma_desc_free(ctlr->pool, desc, 1); - ret = -EINVAL; - goto unlock_ret; - } - mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; - cpdma_desc_to_port(chan, mode, directed); + cpdma_desc_to_port(chan, mode, si->directed); + + if (si->flags & CPDMA_DMA_EXT_MAP) { + buffer = (dma_addr_t)si->data; + dma_sync_single_for_device(ctlr->dev, buffer, len, chan->dir); + swlen |= CPDMA_DMA_EXT_MAP; + } else { + buffer = dma_map_single(ctlr->dev, si->data, len, chan->dir); + ret = dma_mapping_error(ctlr->dev, buffer); + if (ret) { + cpdma_desc_free(ctlr->pool, desc, 1); + ret = -EINVAL; + goto unlock_ret; + } + } /* Relaxed IO accessors can be used here as there is read barrier * at the end of write sequence. @@ -1055,9 +1074,9 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, writel_relaxed(buffer, &desc->hw_buffer); writel_relaxed(len, &desc->hw_len); writel_relaxed(mode | len, &desc->hw_mode); - writel_relaxed((uintptr_t)token, &desc->sw_token); + writel_relaxed((uintptr_t)si->token, &desc->sw_token); writel_relaxed(buffer, &desc->sw_buffer); - writel_relaxed(len, &desc->sw_len); + writel_relaxed(swlen, &desc->sw_len); desc_read(desc, sw_len); __cpdma_chan_submit(chan, desc); @@ -1072,6 +1091,38 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, return ret; } +int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, int len, + int directed) +{ + struct submit_info si; + + si.chan = chan; + si.token = token; + si.data = data; + si.len = len; + si.directed = directed; + si.flags = 0; + + return cpdma_chan_submit_si(&si); +} +EXPORT_SYMBOL_GPL(cpdma_chan_submit); + +int cpdma_chan_submit_mapped(struct cpdma_chan *chan, void *token, + dma_addr_t data, int len, int directed) +{ + struct submit_info si; + + si.chan = chan; + si.token = token; + si.data = (void *)data; + si.len = len; + si.directed = directed; + si.flags = CPDMA_DMA_EXT_MAP; + + return cpdma_chan_submit_si(&si); +} +EXPORT_SYMBOL_GPL(cpdma_chan_submit_mapped); + bool cpdma_check_free_tx_desc(struct cpdma_chan *chan) { struct cpdma_ctlr *ctlr = chan->ctlr; @@ -1097,10 +1148,17 @@ static void __cpdma_chan_free(struct cpdma_chan *chan, uintptr_t token; token = desc_read(desc, sw_token); - buff_dma = desc_read(desc, sw_buffer); origlen = desc_read(desc, sw_len); - dma_unmap_single(ctlr->dev, buff_dma, origlen, chan->dir); + buff_dma = desc_read(desc, sw_buffer); + if (origlen & CPDMA_DMA_EXT_MAP) { + origlen &= ~CPDMA_DMA_EXT_MAP; + dma_sync_single_for_cpu(ctlr->dev, buff_dma, origlen, + chan->dir); + } else { + dma_unmap_single(ctlr->dev, buff_dma, origlen, chan->dir); + } + cpdma_desc_free(pool, desc, 1); (*chan->handler)((void *)token, outlen, status); } diff --git a/drivers/net/ethernet/ti/davinci_cpdma.h b/drivers/net/ethernet/ti/davinci_cpdma.h index 10376062dafa..8f6f27185c63 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.h +++ b/drivers/net/ethernet/ti/davinci_cpdma.h @@ -77,6 +77,8 @@ int cpdma_chan_stop(struct cpdma_chan *chan); int cpdma_chan_get_stats(struct cpdma_chan *chan, struct cpdma_chan_stats *stats); +int cpdma_chan_submit_mapped(struct cpdma_chan *chan, void *token, + dma_addr_t data, int len, int directed); int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, int len, int directed); int cpdma_chan_process(struct cpdma_chan *chan, int quota); From patchwork Thu May 30 18:20:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 10969159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F30AF112C for ; Thu, 30 May 2019 18:21:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E18F028BEE for ; Thu, 30 May 2019 18:21:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4DCD28BE8; Thu, 30 May 2019 18:21:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0580728C02 for ; Thu, 30 May 2019 18:21:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726839AbfE3SVA (ORCPT ); Thu, 30 May 2019 14:21:00 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:40299 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726799AbfE3SVA (ORCPT ); Thu, 30 May 2019 14:21:00 -0400 Received: by mail-lj1-f193.google.com with SMTP id q62so7008501ljq.7 for ; Thu, 30 May 2019 11:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VwtitAHrkRTmSXybjYU2tYI3XhcpB8SZvJGlF0k7LR8=; b=BDljY3oUWcpSunX+BtsT3CUu8PlMz94C8FclzAwWRJkbl78QD3AXsjwE75dUI2Dqyg npYb2IV6svaRmO83F/ZPNySqRcy7YvA2+rlK2mI1mNNnH8+G4yara9URDlhWf+vqC+vS fZpWNJgofl1agt//ekdfueAUnvx9u3YirGyFAg1D1qzOkX9cz2Mi/b8IAdfAIt388pmL zDKPYy7xDfR6YPvMmWx32IPsyEo1ATPjq3neS6BAUd9+05qBGraq5mYLanHSBrHCWPXP 33Nz7aHrB08n9cDUEE4Q6usnwQZKe9aXG0iVSrmMsTlNoKL/ds+J9OcxxafkW3bc7JOo Fe0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VwtitAHrkRTmSXybjYU2tYI3XhcpB8SZvJGlF0k7LR8=; b=rAFUt2o/YnSDBPicUr/+NarQ5DNjyKeyH5bXio6AQ/axHVv6V+4tP0TElsMRRk2ati 7gmkhnyek197sUonYMXs/8JgiopfeM75jyDP+DeEsSrhNFWQWyWv9ps2hgoTEWgYVPkb CldDXBaCq3vrcd7KqJ5gdbLHskgWpkKgXVWlhhy9g0I3TtFw+itMt+ZhlWdJGAiUyY5G ZPPEeFpBN//fg+sfu8cNqeqGZqneky2Znwvw5ipJhwpLi9BIdAsMXWCnZBexlTs6APS9 1xAoquwFvr53FDK0TVTFWoUkw1OzkhPTzGw0H+g5XPU59gul8fYK6SbJfjy834PWfb9k 2cAw== X-Gm-Message-State: APjAAAW6zrz1tbrLxFTAolKMYfft1ENHTkzP2bYN9a+bEMP3+sDoUO0A FpRDw7ObZ5kt+lLPdVdVkZohYA== X-Google-Smtp-Source: APXvYqzfAktHqEgChn6MQOcHJmJcQV53y0dNuo1ujinr8fruawSyO7qQhcDlqMAkH3MmHLTKJxnZaA== X-Received: by 2002:a2e:9bc5:: with SMTP id w5mr3077209ljj.87.1559240457629; Thu, 30 May 2019 11:20:57 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id v7sm388946lfe.11.2019.05.30.11.20.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 11:20:57 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Ivan Khoronzhuk Subject: [PATCH v2 net-next 6/7] net: ethernet: ti: davinci_cpdma: return handler status Date: Thu, 30 May 2019 21:20:38 +0300 Message-Id: <20190530182039.4945-7-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> References: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change is needed to return flush status of rx handler for flushing redirected xdp frames after processing channel packets. Do it as separate patch for simplicity. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw.c | 23 +++++++++++------ drivers/net/ethernet/ti/cpsw_ethtool.c | 2 +- drivers/net/ethernet/ti/cpsw_priv.h | 2 +- drivers/net/ethernet/ti/davinci_cpdma.c | 34 +++++++++++++++---------- drivers/net/ethernet/ti/davinci_cpdma.h | 4 +-- drivers/net/ethernet/ti/davinci_emac.c | 18 ++++++++----- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 3430503e1053..d89ad428315c 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -337,7 +337,7 @@ void cpsw_intr_disable(struct cpsw_common *cpsw) return; } -void cpsw_tx_handler(void *token, int len, int status) +int cpsw_tx_handler(void *token, int len, int status) { struct netdev_queue *txq; struct sk_buff *skb = token; @@ -355,6 +355,7 @@ void cpsw_tx_handler(void *token, int len, int status) ndev->stats.tx_packets++; ndev->stats.tx_bytes += len; dev_kfree_skb_any(skb); + return 0; } static void cpsw_rx_vlan_encap(struct sk_buff *skb) @@ -400,7 +401,7 @@ static void cpsw_rx_vlan_encap(struct sk_buff *skb) } } -static void cpsw_rx_handler(void *token, int len, int status) +static int cpsw_rx_handler(void *token, int len, int status) { struct cpdma_chan *ch; struct sk_buff *skb = token; @@ -434,7 +435,7 @@ static void cpsw_rx_handler(void *token, int len, int status) /* the interface is going down, skbs are purged */ dev_kfree_skb_any(skb); - return; + return 0; } new_skb = netdev_alloc_skb_ip_align(ndev, cpsw->rx_packet_max); @@ -459,7 +460,7 @@ static void cpsw_rx_handler(void *token, int len, int status) requeue: if (netif_dormant(ndev)) { dev_kfree_skb_any(new_skb); - return; + return 0; } ch = cpsw->rxv[skb_get_queue_mapping(new_skb)].ch; @@ -467,6 +468,8 @@ static void cpsw_rx_handler(void *token, int len, int status) skb_tailroom(new_skb), 0); if (WARN_ON(ret < 0)) dev_kfree_skb_any(new_skb); + + return 0; } void cpsw_split_res(struct cpsw_common *cpsw) @@ -605,7 +608,8 @@ static int cpsw_tx_mq_poll(struct napi_struct *napi_tx, int budget) else cur_budget = txv->budget; - num_tx += cpdma_chan_process(txv->ch, cur_budget); + cpdma_chan_process(txv->ch, &cur_budget); + num_tx += cur_budget; if (num_tx >= budget) break; } @@ -623,7 +627,8 @@ static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget) struct cpsw_common *cpsw = napi_to_cpsw(napi_tx); int num_tx; - num_tx = cpdma_chan_process(cpsw->txv[0].ch, budget); + num_tx = budget; + cpdma_chan_process(cpsw->txv[0].ch, &num_tx); if (num_tx < budget) { napi_complete(napi_tx); writel(0xff, &cpsw->wr_regs->tx_en); @@ -655,7 +660,8 @@ static int cpsw_rx_mq_poll(struct napi_struct *napi_rx, int budget) else cur_budget = rxv->budget; - num_rx += cpdma_chan_process(rxv->ch, cur_budget); + cpdma_chan_process(rxv->ch, &cur_budget); + num_rx += cur_budget; if (num_rx >= budget) break; } @@ -673,7 +679,8 @@ static int cpsw_rx_poll(struct napi_struct *napi_rx, int budget) struct cpsw_common *cpsw = napi_to_cpsw(napi_rx); int num_rx; - num_rx = cpdma_chan_process(cpsw->rxv[0].ch, budget); + num_rx = budget; + cpdma_chan_process(cpsw->rxv[0].ch, &num_rx); if (num_rx < budget) { napi_complete_done(napi_rx, num_rx); writel(0xff, &cpsw->wr_regs->rx_en); diff --git a/drivers/net/ethernet/ti/cpsw_ethtool.c b/drivers/net/ethernet/ti/cpsw_ethtool.c index c260bb32aacf..1a7c4818c890 100644 --- a/drivers/net/ethernet/ti/cpsw_ethtool.c +++ b/drivers/net/ethernet/ti/cpsw_ethtool.c @@ -538,8 +538,8 @@ static int cpsw_update_channels_res(struct cpsw_priv *priv, int ch_num, int rx, cpdma_handler_fn rx_handler) { struct cpsw_common *cpsw = priv->cpsw; - void (*handler)(void *, int, int); struct netdev_queue *queue; + cpdma_handler_fn handler; struct cpsw_vector *vec; int ret, *ch, vch; diff --git a/drivers/net/ethernet/ti/cpsw_priv.h b/drivers/net/ethernet/ti/cpsw_priv.h index 04795b97ee71..2ecb3af59fe9 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.h +++ b/drivers/net/ethernet/ti/cpsw_priv.h @@ -390,7 +390,7 @@ void cpsw_split_res(struct cpsw_common *cpsw); int cpsw_fill_rx_channels(struct cpsw_priv *priv); void cpsw_intr_enable(struct cpsw_common *cpsw); void cpsw_intr_disable(struct cpsw_common *cpsw); -void cpsw_tx_handler(void *token, int len, int status); +int cpsw_tx_handler(void *token, int len, int status); /* ethtool */ u32 cpsw_get_msglevel(struct net_device *ndev); diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 7f89b2299f05..a59011d315d5 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -1137,15 +1137,16 @@ bool cpdma_check_free_tx_desc(struct cpdma_chan *chan) return free_tx_desc; } -static void __cpdma_chan_free(struct cpdma_chan *chan, - struct cpdma_desc __iomem *desc, - int outlen, int status) +static int __cpdma_chan_free(struct cpdma_chan *chan, + struct cpdma_desc __iomem *desc, int outlen, + int status) { struct cpdma_ctlr *ctlr = chan->ctlr; struct cpdma_desc_pool *pool = ctlr->pool; dma_addr_t buff_dma; int origlen; uintptr_t token; + int ret; token = desc_read(desc, sw_token); origlen = desc_read(desc, sw_len); @@ -1160,14 +1161,16 @@ static void __cpdma_chan_free(struct cpdma_chan *chan, } cpdma_desc_free(pool, desc, 1); - (*chan->handler)((void *)token, outlen, status); + ret = (*chan->handler)((void *)token, outlen, status); + + return ret; } static int __cpdma_chan_process(struct cpdma_chan *chan) { + int status, outlen, ret; struct cpdma_ctlr *ctlr = chan->ctlr; struct cpdma_desc __iomem *desc; - int status, outlen; int cb_status = 0; struct cpdma_desc_pool *pool = ctlr->pool; dma_addr_t desc_dma; @@ -1178,7 +1181,7 @@ static int __cpdma_chan_process(struct cpdma_chan *chan) desc = chan->head; if (!desc) { chan->stats.empty_dequeue++; - status = -ENOENT; + ret = -ENOENT; goto unlock_ret; } desc_dma = desc_phys(pool, desc); @@ -1187,7 +1190,7 @@ static int __cpdma_chan_process(struct cpdma_chan *chan) outlen = status & 0x7ff; if (status & CPDMA_DESC_OWNER) { chan->stats.busy_dequeue++; - status = -EBUSY; + ret = -EBUSY; goto unlock_ret; } @@ -1213,28 +1216,31 @@ static int __cpdma_chan_process(struct cpdma_chan *chan) else cb_status = status; - __cpdma_chan_free(chan, desc, outlen, cb_status); - return status; + ret = __cpdma_chan_free(chan, desc, outlen, cb_status); + return ret; unlock_ret: spin_unlock_irqrestore(&chan->lock, flags); - return status; + return ret; } -int cpdma_chan_process(struct cpdma_chan *chan, int quota) +int cpdma_chan_process(struct cpdma_chan *chan, int *quota) { - int used = 0, ret = 0; + int used = 0, ret = 0, res = 0; if (chan->state != CPDMA_STATE_ACTIVE) return -EINVAL; - while (used < quota) { + while (used < *quota) { ret = __cpdma_chan_process(chan); if (ret < 0) break; + res |= ret; used++; } - return used; + + *quota = used; + return res; } int cpdma_chan_start(struct cpdma_chan *chan) diff --git a/drivers/net/ethernet/ti/davinci_cpdma.h b/drivers/net/ethernet/ti/davinci_cpdma.h index 8f6f27185c63..56543d375923 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.h +++ b/drivers/net/ethernet/ti/davinci_cpdma.h @@ -61,7 +61,7 @@ struct cpdma_chan_stats { struct cpdma_ctlr; struct cpdma_chan; -typedef void (*cpdma_handler_fn)(void *token, int len, int status); +typedef int (*cpdma_handler_fn)(void *token, int len, int status); struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params); int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr); @@ -81,7 +81,7 @@ int cpdma_chan_submit_mapped(struct cpdma_chan *chan, void *token, dma_addr_t data, int len, int directed); int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, int len, int directed); -int cpdma_chan_process(struct cpdma_chan *chan, int quota); +int cpdma_chan_process(struct cpdma_chan *chan, int *quota); int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable); void cpdma_ctlr_eoi(struct cpdma_ctlr *ctlr, u32 value); diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c index 4bf65cab79e6..3592690b8dd8 100644 --- a/drivers/net/ethernet/ti/davinci_emac.c +++ b/drivers/net/ethernet/ti/davinci_emac.c @@ -860,7 +860,7 @@ static struct sk_buff *emac_rx_alloc(struct emac_priv *priv) return skb; } -static void emac_rx_handler(void *token, int len, int status) +static int emac_rx_handler(void *token, int len, int status) { struct sk_buff *skb = token; struct net_device *ndev = skb->dev; @@ -871,7 +871,7 @@ static void emac_rx_handler(void *token, int len, int status) /* free and bail if we are shutting down */ if (unlikely(!netif_running(ndev))) { dev_kfree_skb_any(skb); - return; + return 0; } /* recycle on receive error */ @@ -892,7 +892,7 @@ static void emac_rx_handler(void *token, int len, int status) if (!skb) { if (netif_msg_rx_err(priv) && net_ratelimit()) dev_err(emac_dev, "failed rx buffer alloc\n"); - return; + return 0; } recycle: @@ -902,9 +902,11 @@ static void emac_rx_handler(void *token, int len, int status) WARN_ON(ret == -ENOMEM); if (unlikely(ret < 0)) dev_kfree_skb_any(skb); + + return 0; } -static void emac_tx_handler(void *token, int len, int status) +static int emac_tx_handler(void *token, int len, int status) { struct sk_buff *skb = token; struct net_device *ndev = skb->dev; @@ -917,6 +919,7 @@ static void emac_tx_handler(void *token, int len, int status) ndev->stats.tx_packets++; ndev->stats.tx_bytes += len; dev_kfree_skb_any(skb); + return 0; } /** @@ -1237,8 +1240,8 @@ static int emac_poll(struct napi_struct *napi, int budget) mask = EMAC_DM646X_MAC_IN_VECTOR_TX_INT_VEC; if (status & mask) { - num_tx_pkts = cpdma_chan_process(priv->txchan, - EMAC_DEF_TX_MAX_SERVICE); + num_tx_pkts = EMAC_DEF_TX_MAX_SERVICE; + cpdma_chan_process(priv->txchan, &num_tx_pkts); } /* TX processing */ mask = EMAC_DM644X_MAC_IN_VECTOR_RX_INT_VEC; @@ -1247,7 +1250,8 @@ static int emac_poll(struct napi_struct *napi, int budget) mask = EMAC_DM646X_MAC_IN_VECTOR_RX_INT_VEC; if (status & mask) { - num_rx_pkts = cpdma_chan_process(priv->rxchan, budget); + num_rx_pkts = budget; + cpdma_chan_process(priv->rxchan, &num_rx_pkts); } /* RX processing */ mask = EMAC_DM644X_MAC_IN_VECTOR_HOST_INT; From patchwork Thu May 30 18:20:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 10969155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 403F4112C for ; Thu, 30 May 2019 18:21:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EFB528BF2 for ; Thu, 30 May 2019 18:21:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2339628BF9; Thu, 30 May 2019 18:21:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B3D228AFF for ; Thu, 30 May 2019 18:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbfE3SVC (ORCPT ); Thu, 30 May 2019 14:21:02 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:38489 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbfE3SVC (ORCPT ); Thu, 30 May 2019 14:21:02 -0400 Received: by mail-lf1-f68.google.com with SMTP id b11so5794764lfa.5 for ; Thu, 30 May 2019 11:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OkjGaEezUcQHsPgRSjppw0xXAMAfa6mWOcTKq++3vcA=; b=R8GtLY+mtgFLC+KUWPfw4x09obXlWwNIG9h2mVlNbxfhWYgXiu0p7Em1h2NRwVHZZl Hv5ugm0sW8me9xmIw6UekbDdWkuKjVQvLp3u7fKTzncXHdxiX1P7lDZ+sgFNQ5sid+18 S92U1ywV39YLF2+c8a3LLXTywRH+cjcwHdjTvLv7dzNngxV9sXMnNrqUnI30/aV9wCc3 V2+Li6GKt0kvOF/LmT1JswwN2u7O8/pPTOAe3/5p9W8NVUQc8NXNzchVLKw6RFP6XLsA to7FYjhDqD/vuVv9gR1vZP1FLG7M5mgmI+ekCwZ9lIKUrezieN1U2u+nN5D89T05br4M yVew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OkjGaEezUcQHsPgRSjppw0xXAMAfa6mWOcTKq++3vcA=; b=CAdma6vV7+6ZF3n4v7wHsG2FQ/jhNc24rIJYCdCegrLhnDkQyhhC9NPpn3pTW8YxC8 3jAqXdhUFOFq1llorUTfSCm6kJIe+PBjLSXerpthg+y7zJ+ll4Ga8XwUA3lwY3MLoORn lZDfmTxqHcIzZAD65TB9Em1rvXnu0a4NLMYgRt9MczEcejrPyQLACjD5ji8whNiUeGbQ eTYNNNbjn1j9jeegnMf1cw4jUWN6rg0E5yg0h8+aWaGWwXXEcbCq3BuhznRa91Lucysh QLbEi9DJJB9T/WVwIhaEL16x05n2C0GIndl4CqLdAOkLjE21e+t+FZxAUJS1AYvmiV9w nrpA== X-Gm-Message-State: APjAAAUeMSqBFiZVwwyWZjzDZVFhRPiQRTlfeKYIitM6AHlUG9NUivZj SgxHoCIG6vKAT6ZciT4XGpmj1g== X-Google-Smtp-Source: APXvYqxlGLRL8Jw25/ozZ9/SKjd8pPoixAYn+ft73B+O4L4ZlILUjazGvSqAoKaRp9ARWzIwwiOzrA== X-Received: by 2002:a19:5515:: with SMTP id n21mr2820213lfe.26.1559240458998; Thu, 30 May 2019 11:20:58 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id v7sm388946lfe.11.2019.05.30.11.20.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 11:20:58 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Ivan Khoronzhuk Subject: [PATCH v2 net-next 7/7] net: ethernet: ti: cpsw: add XDP support Date: Thu, 30 May 2019 21:20:39 +0300 Message-Id: <20190530182039.4945-8-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> References: <20190530182039.4945-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add XDP support based on rx page_pool allocator, one frame per page. Page pool allocator is used with assumption that only one rx_handler is running simultaneously. DMA map/unmap is reused from page pool despite there is no need to map whole page. Due to specific of cpsw, the same TX/RX handler can be used by 2 network devices, so special fields in buffer are added to identify an interface the frame is destined to. Thus XDP works for both interfaces, that allows to test xdp redirect between two interfaces easily. XDP prog is common for all channels till appropriate changes are added in XDP infrastructure. Also, once page_pool recycling becomes part of skb netstack some simplifications can be added marked with comments. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/Kconfig | 1 + drivers/net/ethernet/ti/cpsw.c | 506 ++++++++++++++++++++++--- drivers/net/ethernet/ti/cpsw_ethtool.c | 94 ++++- drivers/net/ethernet/ti/cpsw_priv.h | 10 + 4 files changed, 548 insertions(+), 63 deletions(-) diff --git a/drivers/net/ethernet/ti/Kconfig b/drivers/net/ethernet/ti/Kconfig index bd05a977ee7e..3cb8c5214835 100644 --- a/drivers/net/ethernet/ti/Kconfig +++ b/drivers/net/ethernet/ti/Kconfig @@ -50,6 +50,7 @@ config TI_CPSW depends on ARCH_DAVINCI || ARCH_OMAP2PLUS || COMPILE_TEST select TI_DAVINCI_MDIO select MFD_SYSCON + select PAGE_POOL select REGMAP ---help--- This driver supports TI's CPSW Ethernet Switch. diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index d89ad428315c..6eb7bde9409b 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -31,6 +31,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -60,6 +64,10 @@ static int descs_pool_size = CPSW_CPDMA_DESCS_POOL_SIZE_DEFAULT; module_param(descs_pool_size, int, 0444); MODULE_PARM_DESC(descs_pool_size, "Number of CPDMA CPPI descriptors in pool"); +/* The buf includes headroom compatible with both skb and xdpf */ +#define CPSW_HEADROOM_NA (max(XDP_PACKET_HEADROOM, NET_SKB_PAD) + NET_IP_ALIGN) +#define CPSW_HEADROOM ALIGN(CPSW_HEADROOM_NA, sizeof(long)) + #define for_each_slave(priv, func, arg...) \ do { \ struct cpsw_slave *slave; \ @@ -74,6 +82,13 @@ MODULE_PARM_DESC(descs_pool_size, "Number of CPDMA CPPI descriptors in pool"); (func)(slave++, ##arg); \ } while (0) +#define CPSW_XMETA_OFFSET ALIGN(sizeof(struct xdp_frame), sizeof(long)) + +#define CPSW_XDP_CONSUMED 1 +#define CPSW_XDP_CONSUMED_FLUSH 2 +#define CPSW_XDP_PASS 0 +#define CPSW_FLUSH_XDP_MAP 1 + static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid); @@ -337,24 +352,58 @@ void cpsw_intr_disable(struct cpsw_common *cpsw) return; } +static int cpsw_is_xdpf_handle(void *handle) +{ + return (unsigned long)handle & BIT(0); +} + +static void *cpsw_xdpf_to_handle(struct xdp_frame *xdpf) +{ + return (void *)((unsigned long)xdpf | BIT(0)); +} + +static struct xdp_frame *cpsw_handle_to_xdpf(void *handle) +{ + return (struct xdp_frame *)((unsigned long)handle & ~BIT(0)); +} + +struct __aligned(sizeof(long)) cpsw_meta_xdp { + struct net_device *ndev; + int ch; +}; + int cpsw_tx_handler(void *token, int len, int status) { + struct cpsw_meta_xdp *xmeta; + struct xdp_frame *xdpf; + struct net_device *ndev; struct netdev_queue *txq; - struct sk_buff *skb = token; - struct net_device *ndev = skb->dev; - struct cpsw_common *cpsw = ndev_to_cpsw(ndev); + struct sk_buff *skb; + int ch; + + if (cpsw_is_xdpf_handle(token)) { + xdpf = cpsw_handle_to_xdpf(token); + xmeta = (void *)xdpf + CPSW_XMETA_OFFSET; + ndev = xmeta->ndev; + ch = xmeta->ch; + xdp_return_frame_rx_napi(xdpf); + } else { + skb = token; + ndev = skb->dev; + ch = skb_get_queue_mapping(skb); + cpts_tx_timestamp(ndev_to_cpsw(ndev)->cpts, skb); + dev_kfree_skb_any(skb); + } /* Check whether the queue is stopped due to stalled tx dma, if the * queue is stopped then start the queue as we have free desc for tx */ - txq = netdev_get_tx_queue(ndev, skb_get_queue_mapping(skb)); + txq = netdev_get_tx_queue(ndev, ch); if (unlikely(netif_tx_queue_stopped(txq))) netif_tx_wake_queue(txq); - cpts_tx_timestamp(cpsw->cpts, skb); ndev->stats.tx_packets++; ndev->stats.tx_bytes += len; - dev_kfree_skb_any(skb); return 0; } @@ -401,22 +450,220 @@ static void cpsw_rx_vlan_encap(struct sk_buff *skb) } } +static int cpsw_xdp_tx_frame(struct cpsw_priv *priv, struct xdp_frame *xdpf, + struct page *page) +{ + struct cpsw_common *cpsw = priv->cpsw; + struct cpsw_meta_xdp *xmeta; + struct netdev_queue *txq; + struct cpdma_chan *txch; + dma_addr_t dma; + int ret, port; + + xmeta = (void *)xdpf + CPSW_XMETA_OFFSET; + xmeta->ch = 0; + txch = cpsw->txv[0].ch; + + port = priv->emac_port + cpsw->data.dual_emac; + if (page) { + dma = page_pool_get_dma_addr(page); + dma += xdpf->data - (void *)xdpf; + ret = cpdma_chan_submit_mapped(txch, cpsw_xdpf_to_handle(xdpf), + dma, xdpf->len, port); + } else { + if (sizeof(*xmeta) > xdpf->headroom) { + xdp_return_frame_rx_napi(xdpf); + return -EINVAL; + } + + xmeta->ndev = priv->ndev; + ret = cpdma_chan_submit(txch, cpsw_xdpf_to_handle(xdpf), + xdpf->data, xdpf->len, port); + } + + if (ret) { + xdp_return_frame_rx_napi(xdpf); + goto stop; + } + + /* no tx desc - stop sending us tx frames */ + if (unlikely(!cpdma_check_free_tx_desc(txch))) + goto stop; + + return ret; +stop: + txq = netdev_get_tx_queue(priv->ndev, 0); + netif_tx_stop_queue(txq); + + /* Barrier, so that stop_queue visible to other cpus */ + smp_mb__after_atomic(); + + if (cpdma_check_free_tx_desc(txch)) + netif_tx_wake_queue(txq); + + return ret; +} + +static int cpsw_run_xdp(struct cpsw_priv *priv, struct cpsw_vector *rxv, + struct xdp_buff *xdp, struct page *page) +{ + struct net_device *ndev = priv->ndev; + int ret = CPSW_XDP_CONSUMED; + struct xdp_frame *xdpf; + struct bpf_prog *prog; + u32 act; + + rcu_read_lock(); + + prog = READ_ONCE(priv->xdp_prog); + if (!prog) { + ret = CPSW_XDP_PASS; + goto out; + } + + act = bpf_prog_run_xdp(prog, xdp); + switch (act) { + case XDP_PASS: + ret = CPSW_XDP_PASS; + break; + case XDP_TX: + xdpf = convert_to_xdp_frame(xdp); + if (unlikely(!xdpf)) + goto drop; + + cpsw_xdp_tx_frame(priv, xdpf, page); + break; + case XDP_REDIRECT: + if (xdp_do_redirect(ndev, xdp, prog)) + goto drop; + + ret = CPSW_XDP_CONSUMED_FLUSH; + break; + default: + bpf_warn_invalid_xdp_action(act); + /* fall through */ + case XDP_ABORTED: + trace_xdp_exception(ndev, prog, act); + /* fall through -- handle aborts by dropping packet */ + case XDP_DROP: + goto drop; + } +out: + rcu_read_unlock(); + return ret; +drop: + rcu_read_unlock(); + page_pool_recycle_direct(priv->cpsw->page_pool, page); + return ret; +} + +static unsigned int cpsw_rxbuf_total_len(unsigned int len) +{ + len += CPSW_HEADROOM; + len += SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + + return SKB_DATA_ALIGN(len); +} + +void cpsw_xdp_unreg_rxqs(struct cpsw_priv *priv) +{ + struct cpsw_common *cpsw = priv->cpsw; + int i; + + for (i = 0; i < cpsw->rx_ch_num; i++) + xdp_rxq_info_unreg(&priv->xdp_rxq[i]); +} + +int cpsw_xdp_reg_rxq(struct cpsw_priv *priv, int ch) +{ + struct xdp_rxq_info *xdp_rxq = &priv->xdp_rxq[ch]; + struct cpsw_common *cpsw = priv->cpsw; + int ret; + + ret = xdp_rxq_info_reg(xdp_rxq, priv->ndev, ch); + if (ret) + goto err_cleanup; + + ret = xdp_rxq_info_reg_mem_model(xdp_rxq, MEM_TYPE_PAGE_POOL, + cpsw->page_pool); + if (ret) + goto err_cleanup; + + return 0; + +err_cleanup: + if (xdp_rxq_info_is_reg(xdp_rxq)) + xdp_rxq_info_unreg(xdp_rxq); + + return ret; +} + +int cpsw_xdp_reg_rxqs(struct cpsw_priv *priv) +{ + struct cpsw_common *cpsw = priv->cpsw; + struct xdp_rxq_info *xdp_rxq; + int i, ret; + + for (i = 0; i < cpsw->rx_ch_num; i++) { + ret = cpsw_xdp_reg_rxq(priv, i); + if (ret) + goto err_cleanup; + } + + return 0; + +err_cleanup: + while (i--) { + xdp_rxq = &priv->xdp_rxq[i]; + if (xdp_rxq_info_is_reg(xdp_rxq)) + xdp_rxq_info_unreg(xdp_rxq); + } + + return ret; +} + +struct page_pool *cpsw_create_page_pool(struct cpsw_common *cpsw, int size) +{ + struct page_pool_params pp_params = { 0 }; + struct page_pool *pool; + + pp_params.order = 0; + pp_params.flags = PP_FLAG_DMA_MAP; + + /* set it to number of RX descriptors, but can be more */ + pp_params.pool_size = size; + pp_params.nid = NUMA_NO_NODE; + pp_params.dma_dir = DMA_BIDIRECTIONAL; + pp_params.dev = cpsw->dev; + + pool = page_pool_create(&pp_params); + if (IS_ERR(pool)) + dev_err(cpsw->dev, "cannot create rx page pool\n"); + + return pool; +} + static int cpsw_rx_handler(void *token, int len, int status) { - struct cpdma_chan *ch; - struct sk_buff *skb = token; - struct sk_buff *new_skb; - struct net_device *ndev = skb->dev; - int ret = 0, port; - struct cpsw_common *cpsw = ndev_to_cpsw(ndev); + struct page *new_page, *page = token; + void *pa = page_address(page); + struct cpsw_meta_xdp *xmeta = pa + CPSW_XMETA_OFFSET; + struct cpsw_common *cpsw = ndev_to_cpsw(xmeta->ndev); + int pkt_size = cpsw->rx_packet_max; + int ret = 0, port, ch = xmeta->ch; + struct page_pool *pool = cpsw->page_pool; + int headroom = CPSW_HEADROOM; + struct net_device *ndev = xmeta->ndev; + int res = 0; struct cpsw_priv *priv; + struct sk_buff *skb; + struct xdp_buff xdp; + dma_addr_t dma; if (cpsw->data.dual_emac) { port = CPDMA_RX_SOURCE_PORT(status); - if (port) { + if (port) ndev = cpsw->slaves[--port].ndev; - skb->dev = ndev; - } } if (unlikely(status < 0) || unlikely(!netif_running(ndev))) { @@ -427,49 +674,97 @@ static int cpsw_rx_handler(void *token, int len, int status) * is already down and the other interface is up * and running, instead of freeing which results * in reducing of the number of rx descriptor in - * DMA engine, requeue skb back to cpdma. + * DMA engine, requeue page back to cpdma. */ - new_skb = skb; + new_page = page; goto requeue; } - /* the interface is going down, skbs are purged */ - dev_kfree_skb_any(skb); + /* the interface is going down, pages are purged */ + page_pool_recycle_direct(pool, page); return 0; } - new_skb = netdev_alloc_skb_ip_align(ndev, cpsw->rx_packet_max); - if (new_skb) { - skb_copy_queue_mapping(new_skb, skb); - skb_put(skb, len); - if (status & CPDMA_RX_VLAN_ENCAP) - cpsw_rx_vlan_encap(skb); - priv = netdev_priv(ndev); - if (priv->rx_ts_enabled) - cpts_rx_timestamp(cpsw->cpts, skb); - skb->protocol = eth_type_trans(skb, ndev); - netif_receive_skb(skb); - ndev->stats.rx_bytes += len; - ndev->stats.rx_packets++; - kmemleak_not_leak(new_skb); - } else { + new_page = page_pool_dev_alloc_pages(cpsw->page_pool); + if (unlikely(!new_page)) { + new_page = page; ndev->stats.rx_dropped++; - new_skb = skb; + goto requeue; } + priv = netdev_priv(ndev); + if (priv->xdp_prog) { + if (status & CPDMA_RX_VLAN_ENCAP) { + xdp.data = (void *)pa + CPSW_HEADROOM + + CPSW_RX_VLAN_ENCAP_HDR_SIZE; + xdp.data_end = xdp.data + len - + CPSW_RX_VLAN_ENCAP_HDR_SIZE; + } else { + xdp.data = (void *)pa + CPSW_HEADROOM; + xdp.data_end = xdp.data + len; + } + + xdp_set_data_meta_invalid(&xdp); + + xdp.data_hard_start = pa; + xdp.rxq = &priv->xdp_rxq[ch]; + + ret = cpsw_run_xdp(priv, &cpsw->rxv[ch], &xdp, page); + if (ret != CPSW_XDP_PASS) { + if (ret == CPSW_XDP_CONSUMED_FLUSH) + res = CPSW_FLUSH_XDP_MAP; + + goto requeue; + } + + /* XDP prog might have changed packet data and boundaries */ + len = xdp.data_end - xdp.data; + headroom = xdp.data - xdp.data_hard_start; + } + + /* Build skb and pass it to netstack if XDP off or XDP prog + * returned XDP_PASS + */ + skb = build_skb(pa, cpsw_rxbuf_total_len(pkt_size)); + if (!skb) { + ndev->stats.rx_dropped++; + page_pool_recycle_direct(pool, page); + goto requeue; + } + + skb_reserve(skb, headroom); + skb_put(skb, len); + skb->dev = ndev; + if (status & CPDMA_RX_VLAN_ENCAP) + cpsw_rx_vlan_encap(skb); + if (priv->rx_ts_enabled) + cpts_rx_timestamp(cpsw->cpts, skb); + skb->protocol = eth_type_trans(skb, ndev); + + /* unmap page as no skb page recycling */ + page_pool_unmap_page(pool, page); + netif_receive_skb(skb); + + ndev->stats.rx_bytes += len; + ndev->stats.rx_packets++; + requeue: if (netif_dormant(ndev)) { - dev_kfree_skb_any(new_skb); - return 0; + page_pool_recycle_direct(pool, new_page); + return res; } - ch = cpsw->rxv[skb_get_queue_mapping(new_skb)].ch; - ret = cpdma_chan_submit(ch, new_skb, new_skb->data, - skb_tailroom(new_skb), 0); + xmeta = page_address(new_page) + CPSW_XMETA_OFFSET; + xmeta->ndev = ndev; + xmeta->ch = ch; + + dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM; + ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma, + pkt_size, 0); if (WARN_ON(ret < 0)) - dev_kfree_skb_any(new_skb); + page_pool_recycle_direct(pool, new_page); - return 0; + return res; } void cpsw_split_res(struct cpsw_common *cpsw) @@ -644,8 +939,8 @@ static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget) static int cpsw_rx_mq_poll(struct napi_struct *napi_rx, int budget) { u32 ch_map; - int num_rx, cur_budget, ch; struct cpsw_common *cpsw = napi_to_cpsw(napi_rx); + int num_rx, cur_budget, ch, res; struct cpsw_vector *rxv; /* process every unprocessed channel */ @@ -660,8 +955,12 @@ static int cpsw_rx_mq_poll(struct napi_struct *napi_rx, int budget) else cur_budget = rxv->budget; - cpdma_chan_process(rxv->ch, &cur_budget); + res = cpdma_chan_process(rxv->ch, &cur_budget); num_rx += cur_budget; + + if (res & CPSW_FLUSH_XDP_MAP) + xdp_do_flush_map(); + if (num_rx >= budget) break; } @@ -677,10 +976,15 @@ static int cpsw_rx_mq_poll(struct napi_struct *napi_rx, int budget) static int cpsw_rx_poll(struct napi_struct *napi_rx, int budget) { struct cpsw_common *cpsw = napi_to_cpsw(napi_rx); - int num_rx; + struct cpsw_vector *rxv; + int num_rx, res; num_rx = budget; - cpdma_chan_process(cpsw->rxv[0].ch, &num_rx); + rxv = &cpsw->rxv[0]; + res = cpdma_chan_process(rxv->ch, &num_rx); + if (res & CPSW_FLUSH_XDP_MAP) + xdp_do_flush_map(); + if (num_rx < budget) { napi_complete_done(napi_rx, num_rx); writel(0xff, &cpsw->wr_regs->rx_en); @@ -1042,33 +1346,36 @@ static void cpsw_init_host_port(struct cpsw_priv *priv) int cpsw_fill_rx_channels(struct cpsw_priv *priv) { struct cpsw_common *cpsw = priv->cpsw; - struct sk_buff *skb; + struct cpsw_meta_xdp *xmeta; + struct page *page; int ch_buf_num; int ch, i, ret; + dma_addr_t dma; for (ch = 0; ch < cpsw->rx_ch_num; ch++) { ch_buf_num = cpdma_chan_get_rx_buf_num(cpsw->rxv[ch].ch); for (i = 0; i < ch_buf_num; i++) { - skb = __netdev_alloc_skb_ip_align(priv->ndev, - cpsw->rx_packet_max, - GFP_KERNEL); - if (!skb) { - cpsw_err(priv, ifup, "cannot allocate skb\n"); + page = page_pool_dev_alloc_pages(cpsw->page_pool); + if (!page) { + cpsw_err(priv, ifup, "allocate rx page err\n"); return -ENOMEM; } - skb_set_queue_mapping(skb, ch); - ret = cpdma_chan_submit(cpsw->rxv[ch].ch, skb, - skb->data, skb_tailroom(skb), - 0); + xmeta = page_address(page) + CPSW_XMETA_OFFSET; + xmeta->ndev = priv->ndev; + xmeta->ch = ch; + + dma = page_pool_get_dma_addr(page) + CPSW_HEADROOM; + ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, page, + dma, cpsw->rx_packet_max, + 0); if (ret < 0) { cpsw_err(priv, ifup, - "cannot submit skb to channel %d rx, error %d\n", + "cannot submit page to channel %d rx, error %d\n", ch, ret); - kfree_skb(skb); + page_pool_recycle_direct(cpsw->page_pool, page); return ret; } - kmemleak_not_leak(skb); } cpsw_info(priv, ifup, "ch %d rx, submitted %d descriptors\n", @@ -1338,7 +1645,7 @@ static int cpsw_ndo_open(struct net_device *ndev) { struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = priv->cpsw; - int ret; + int ret, pool_size; u32 reg; ret = pm_runtime_get_sync(cpsw->dev); @@ -1404,6 +1711,14 @@ static int cpsw_ndo_open(struct net_device *ndev) enable_irq(cpsw->irqs_table[0]); } + pool_size = cpdma_get_num_rx_descs(cpsw->dma); + cpsw->page_pool = cpsw_create_page_pool(cpsw, pool_size); + if (IS_ERR(cpsw->page_pool)) { + ret = PTR_ERR(cpsw->page_pool); + cpsw->page_pool = NULL; + goto err_cleanup; + } + ret = cpsw_fill_rx_channels(priv); if (ret < 0) goto err_cleanup; @@ -1423,6 +1738,10 @@ static int cpsw_ndo_open(struct net_device *ndev) cpsw_set_coalesce(ndev, &coal); } + ret = cpsw_xdp_reg_rxqs(priv); + if (ret) + goto err_cleanup; + cpdma_ctlr_start(cpsw->dma); cpsw_intr_enable(cpsw); cpsw->usage_count++; @@ -1432,9 +1751,11 @@ static int cpsw_ndo_open(struct net_device *ndev) err_cleanup: if (!cpsw->usage_count) { cpdma_ctlr_stop(cpsw->dma); - for_each_slave(priv, cpsw_slave_stop, cpsw); + if (cpsw->page_pool) + page_pool_destroy(cpsw->page_pool); } + for_each_slave(priv, cpsw_slave_stop, cpsw); pm_runtime_put_sync(cpsw->dev); netif_carrier_off(priv->ndev); return ret; @@ -1457,12 +1778,15 @@ static int cpsw_ndo_stop(struct net_device *ndev) cpsw_intr_disable(cpsw); cpdma_ctlr_stop(cpsw->dma); cpsw_ale_stop(cpsw->ale); + page_pool_destroy(cpsw->page_pool); } for_each_slave(priv, cpsw_slave_stop, cpsw); if (cpsw_need_resplit(cpsw)) cpsw_split_res(cpsw); + cpsw_xdp_unreg_rxqs(priv); + cpsw->usage_count--; pm_runtime_put_sync(cpsw->dev); return 0; @@ -2014,6 +2338,64 @@ static int cpsw_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type, } } +static int cpsw_xdp_prog_setup(struct cpsw_priv *priv, struct netdev_bpf *bpf) +{ + struct bpf_prog *prog = bpf->prog; + + if (!priv->xdpi.prog && !prog) + return 0; + + if (!xdp_attachment_flags_ok(&priv->xdpi, bpf)) + return -EBUSY; + + WRITE_ONCE(priv->xdp_prog, prog); + + xdp_attachment_setup(&priv->xdpi, bpf); + + return 0; +} + +static int cpsw_ndo_bpf(struct net_device *ndev, struct netdev_bpf *bpf) +{ + struct cpsw_priv *priv = netdev_priv(ndev); + + switch (bpf->command) { + case XDP_SETUP_PROG: + return cpsw_xdp_prog_setup(priv, bpf); + + case XDP_QUERY_PROG: + return xdp_attachment_query(&priv->xdpi, bpf); + + default: + return -EINVAL; + } +} + +static int cpsw_ndo_xdp_xmit(struct net_device *ndev, int n, + struct xdp_frame **frames, u32 flags) +{ + struct cpsw_priv *priv = netdev_priv(ndev); + struct xdp_frame *xdpf; + int i, drops = 0; + + if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) + return -EINVAL; + + for (i = 0; i < n; i++) { + xdpf = frames[i]; + if (xdpf->len < CPSW_MIN_PACKET_SIZE) { + xdp_return_frame_rx_napi(xdpf); + drops++; + continue; + } + + if (cpsw_xdp_tx_frame(priv, xdpf, NULL)) + drops++; + } + + return n - drops; +} + #ifdef CONFIG_NET_POLL_CONTROLLER static void cpsw_ndo_poll_controller(struct net_device *ndev) { @@ -2042,6 +2424,8 @@ static const struct net_device_ops cpsw_netdev_ops = { .ndo_vlan_rx_add_vid = cpsw_ndo_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = cpsw_ndo_vlan_rx_kill_vid, .ndo_setup_tc = cpsw_ndo_setup_tc, + .ndo_bpf = cpsw_ndo_bpf, + .ndo_xdp_xmit = cpsw_ndo_xdp_xmit, }; static void cpsw_get_drvinfo(struct net_device *ndev, diff --git a/drivers/net/ethernet/ti/cpsw_ethtool.c b/drivers/net/ethernet/ti/cpsw_ethtool.c index 1a7c4818c890..45028088b070 100644 --- a/drivers/net/ethernet/ti/cpsw_ethtool.c +++ b/drivers/net/ethernet/ti/cpsw_ethtool.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "cpsw.h" #include "cpts.h" @@ -534,6 +535,59 @@ static int cpsw_check_ch_settings(struct cpsw_common *cpsw, return 0; } +void cpsw_xdp_rxq_unreg(struct cpsw_common *cpsw, int ch) +{ + struct net_device *ndev; + struct cpsw_priv *priv; + int i; + + for (i = 0; i < cpsw->data.slaves; i++) { + ndev = cpsw->slaves[i].ndev; + if (!(ndev && netif_running(ndev))) + continue; + + priv = netdev_priv(ndev); + xdp_rxq_info_unreg(&priv->xdp_rxq[ch]); + } +} + +static int cpsw_xdp_sl_reg_rxq(struct cpsw_common *cpsw, int ch) +{ + struct net_device *ndev; + struct cpsw_priv *priv; + int i, ret; + + /* As channels are common for both ports sharing same queues, xdp_rxq + * information also becomes shared and used by every packet on this + * channel. But each xdp_rxq holds link on netdev, which by the theory + * can have different memory model and so, network device must hold it's + * own set of rxq and thus both netdevs should be prepared + */ + for (i = 0; i < cpsw->data.slaves; i++) { + ndev = cpsw->slaves[i].ndev; + if (!(ndev && netif_running(ndev))) + continue; + + ret = cpsw_xdp_reg_rxq(netdev_priv(ndev), ch); + if (ret) + goto err_cleanup; + } + + return 0; + +err_cleanup: + while (i--) { + ndev = cpsw->slaves[i].ndev; + if (!(ndev && netif_running(ndev))) + continue; + + priv = netdev_priv(ndev); + xdp_rxq_info_unreg(&priv->xdp_rxq[ch]); + } + + return ret; +} + static int cpsw_update_channels_res(struct cpsw_priv *priv, int ch_num, int rx, cpdma_handler_fn rx_handler) { @@ -565,6 +619,11 @@ static int cpsw_update_channels_res(struct cpsw_priv *priv, int ch_num, int rx, if (!vec[*ch].ch) return -EINVAL; + if (rx && cpsw_xdp_sl_reg_rxq(cpsw, *ch)) { + cpdma_chan_destroy(vec[*ch].ch); + return -EINVAL; + } + cpsw_info(priv, ifup, "created new %d %s channel\n", *ch, (rx ? "rx" : "tx")); (*ch)++; @@ -573,6 +632,9 @@ static int cpsw_update_channels_res(struct cpsw_priv *priv, int ch_num, int rx, while (*ch > ch_num) { (*ch)--; + if (rx) + cpsw_xdp_rxq_unreg(cpsw, *ch); + ret = cpdma_chan_destroy(vec[*ch].ch); if (ret) return ret; @@ -656,7 +718,8 @@ int cpsw_set_ringparam(struct net_device *ndev, { struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = priv->cpsw; - int ret; + struct page_pool *pool; + int ret, i; /* ignore ering->tx_pending - only rx_pending adjustment is supported */ @@ -668,6 +731,10 @@ int cpsw_set_ringparam(struct net_device *ndev, if (ering->rx_pending == cpdma_get_num_rx_descs(cpsw->dma)) return 0; + pool = cpsw_create_page_pool(cpsw, ering->rx_pending); + if (IS_ERR(pool)) + return PTR_ERR(pool); + cpsw_suspend_data_pass(ndev); cpdma_set_num_rx_descs(cpsw->dma, ering->rx_pending); @@ -675,10 +742,33 @@ int cpsw_set_ringparam(struct net_device *ndev, if (cpsw->usage_count) cpdma_chan_split_pool(cpsw->dma); + for (i = 0; i < cpsw->data.slaves; i++) { + struct net_device *ndev = cpsw->slaves[i].ndev; + + if (!(ndev && netif_running(ndev))) + continue; + + cpsw_xdp_unreg_rxqs(netdev_priv(ndev)); + } + + page_pool_destroy(cpsw->page_pool); + cpsw->page_pool = pool; + + for (i = 0; i < cpsw->data.slaves; i++) { + struct net_device *ndev = cpsw->slaves[i].ndev; + + if (!(ndev && netif_running(ndev))) + continue; + + ret = cpsw_xdp_reg_rxqs(netdev_priv(ndev)); + if (ret) + goto err; + } + ret = cpsw_resume_data_pass(ndev); if (!ret) return 0; - +err: dev_err(cpsw->dev, "cannot set ring params, closing device\n"); dev_close(ndev); return ret; diff --git a/drivers/net/ethernet/ti/cpsw_priv.h b/drivers/net/ethernet/ti/cpsw_priv.h index 2ecb3af59fe9..e59a54ee7540 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.h +++ b/drivers/net/ethernet/ti/cpsw_priv.h @@ -346,6 +346,7 @@ struct cpsw_common { int rx_ch_num, tx_ch_num; int speed; int usage_count; + struct page_pool *page_pool; }; struct cpsw_priv { @@ -360,6 +361,10 @@ struct cpsw_priv { int shp_cfg_speed; int tx_ts_enabled; int rx_ts_enabled; + struct bpf_prog *xdp_prog; + struct xdp_rxq_info xdp_rxq[CPSW_MAX_QUEUES]; + struct xdp_attachment_info xdpi; + u32 emac_port; struct cpsw_common *cpsw; }; @@ -391,6 +396,11 @@ int cpsw_fill_rx_channels(struct cpsw_priv *priv); void cpsw_intr_enable(struct cpsw_common *cpsw); void cpsw_intr_disable(struct cpsw_common *cpsw); int cpsw_tx_handler(void *token, int len, int status); +void cpsw_xdp_rxq_unreg(struct cpsw_common *cpsw, int ch); +struct page_pool *cpsw_create_page_pool(struct cpsw_common *cpsw, int size); +int cpsw_xdp_reg_rxq(struct cpsw_priv *priv, int ch); +int cpsw_xdp_reg_rxqs(struct cpsw_priv *priv); +void cpsw_xdp_unreg_rxqs(struct cpsw_priv *priv); /* ethtool */ u32 cpsw_get_msglevel(struct net_device *ndev);