From patchwork Mon Jul 8 21:34:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168693 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7663222ilk; Mon, 8 Jul 2019 14:35:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZcwaCaw3INYRwWGERXrdWkSlYvJv+98qKjGolosmwHsRsGY5kgm/lPk0+w3BsAJguszR4 X-Received: by 2002:a17:902:8d92:: with SMTP id v18mr27770466plo.211.1562621719831; Mon, 08 Jul 2019 14:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562621719; cv=none; d=google.com; s=arc-20160816; b=EnMxnslv+sQcODqbBgTzPfkgMSAFO1Wm0bHcbLz6MOS8oNbcSe/rWh495AjnBhM5uf cRk3OG0AlTQ5ApdlpcGpPWg9gBjNI+DO7O1vMlos0nQbpqRPlH5MIHfF8PXdfZKy17Zw zrgm48gsS5K9oHVWQDSkRj2cwWoJ5PN9ibFS+e58H6WmGUt2e6Jv0xQEvPu5acwLvw9r 3c/Vjk9IDQsd45T8FI3Zgrn76klPfXajWaLfx0OMdNZtMaCodJjtSvr5fw8wEg9M14lz b14EMPRFmyOH94reveueUA8linOPLsbl05Isk7tkD4uUe873JetONWHLQnwbdMCflnTf d7yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=TtEMC/A+JhK+HQ0VPTIfb4ZXQAqVRYHsw4hUKce21to=; b=WNgk1OBys1rTXPZ2pACDIaXtdL4XNMa4fTxKDi7CwbrU4dzwamMHJYHiyGyWS3BijI rUZ3zh2DGYt+Hhltcpc9LRxa7deHQDwjZW0Q7Xi7tAdVzaP+xUUkjxieZkIJkIBaO/D6 OEMEjLBT9xMDR01i1yH0DfdWzUND7cGGGg0X0b6RlK8QTWdFKP8WhtP/VdTYSmElwjvU 6iy7f0Cn8eaLyeuVuJ3Wrr4iNmrzQU8/QqpROBjTHfAw6as1FiWRQWLynFFagn1s6lw/ rvKJAP+Jdd5ZRGnBukwjVI1c3tR3W6/GVVLOHpxymKdLkN1N+6XHQK/A4/LrX7wHE6yt ivTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YSEv7rUo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg3si11342064plb.83.2019.07.08.14.35.19; Mon, 08 Jul 2019 14:35:19 -0700 (PDT) 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=@linaro.org header.s=google header.b=YSEv7rUo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731847AbfGHVfR (ORCPT + 30 others); Mon, 8 Jul 2019 17:35:17 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:39295 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731830AbfGHVej (ORCPT ); Mon, 8 Jul 2019 17:34:39 -0400 Received: by mail-lf1-f67.google.com with SMTP id v85so8989029lfa.6 for ; Mon, 08 Jul 2019 14:34:38 -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=TtEMC/A+JhK+HQ0VPTIfb4ZXQAqVRYHsw4hUKce21to=; b=YSEv7rUonu0fSMJv1bvmY3wsBQPgbXIQKEuKbU69K2u4PKXKLUFQNCys92ak9xpxjy IXAX4aMAWUSx2ywf2UmCJlgJyAHfRnQGjJjtfoS53FsVEW2FDJanxhw3ozuZP6JWSZtC WNxHEB1LkkEvSPELZ8Dt3ajTUDsJLVKMkXGhraYtAJ/ZmLMVfykLzsdtanY0Glt9+/WC oihGOVG6XNojx85v11SHEWAj5NtOUJBJ8TJ4qQKWEnI7AHPuWUx5bKhpxgPPGTimYZAn A4qmWRNxJu9dLfecSulisXphrWak7gX9XQg8h7w4+FvlQJYAm2d+jBQ9Cdc2KtV5F2vv hT7Q== 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=TtEMC/A+JhK+HQ0VPTIfb4ZXQAqVRYHsw4hUKce21to=; b=umlJCF5m8ga9q1MycHMFSD4leDhWs06+wYRAkj3w7H/cwyrj/X+/GWXaZJhqzMV5Kc y1jQb/tzTaubmv9Fk/1fBh1SmBrHuPEnAmWGiwogoeijiCF0XZ7zm0T35lXE4Seaklk7 rZayQqurMd4yLRLbBXd9/we++PyIJjlGe3vnrFuTdUau5KkG79va1nMLHQNdyIq/EwiJ 020eeUwLg46JqWuDQ+B7EViKIXnAVrYcdtiY6rbCBtch7bqM561p2TxYccrV03cyXBgJ zyuG51aWgp1Shl9tGFrsKXXRSKfevKsOHRGIHkMUua+fV/TLh3Ginz3p/RJ3MNt539C4 jwwA== X-Gm-Message-State: APjAAAU4Z3QRIG/tPGv+HWfmZcN2Uz/uC5Ge09GHS0XAa+HqkwbcwBdB 5ErRbRCYH24aumiiTFveBcZAiw== X-Received: by 2002:a19:a83:: with SMTP id 125mr10080929lfk.150.1562621677203; Mon, 08 Jul 2019 14:34:37 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id o24sm3883096ljg.6.2019.07.08.14.34.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 14:34:36 -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 , Jesper Dangaard Brouer Subject: [PATCH v9 net-next 1/5] net: core: page_pool: add user refcnt and reintroduce page_pool_destroy Date: Tue, 9 Jul 2019 00:34:28 +0300 Message-Id: <20190708213432.8525-2-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190708213432.8525-1-ivan.khoronzhuk@linaro.org> References: <20190708213432.8525-1-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jesper recently removed page_pool_destroy() (from driver invocation) and moved shutdown and free of page_pool into xdp_rxq_info_unreg(), in-order to handle in-flight packets/pages. This created an asymmetry in drivers create/destroy pairs. This patch reintroduce page_pool_destroy and add page_pool user refcnt. This serves the purpose to simplify drivers error handling as driver now drivers always calls page_pool_destroy() and don't need to track if xdp_rxq_info_reg_mem_model() was unsuccessful. This could be used for a special cases where a single RX-queue (with a single page_pool) provides packets for two net_device'es, and thus needs to register the same page_pool twice with two xdp_rxq_info structures. This patch is primarily to ease API usage for drivers. The recently merged netsec driver, actually have a bug in this area, which is solved by this API change. This patch is a modified version of Ivan Khoronzhuk's original patch. Link: https://lore.kernel.org/netdev/20190625175948.24771-2-ivan.khoronzhuk@linaro.org/ Fixes: 5c67bf0ec4d0 ("net: netsec: Use page_pool API") Signed-off-by: Jesper Dangaard Brouer Reviewed-by: Ilias Apalodimas Acked-by: Jesper Dangaard Brouer Reviewed-by: Saeed Mahameed Signed-off-by: Ivan Khoronzhuk --- .../net/ethernet/mellanox/mlx5/core/en_main.c | 4 +-- drivers/net/ethernet/socionext/netsec.c | 8 ++---- include/net/page_pool.h | 25 +++++++++++++++++++ net/core/page_pool.c | 8 ++++++ net/core/xdp.c | 3 +++ 5 files changed, 40 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 83194d56434d..10efd69de7ef 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -577,8 +577,6 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c, } err = xdp_rxq_info_reg_mem_model(&rq->xdp_rxq, MEM_TYPE_PAGE_POOL, rq->page_pool); - if (err) - page_pool_free(rq->page_pool); } if (err) goto err_free; @@ -646,6 +644,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c, if (rq->xdp_prog) bpf_prog_put(rq->xdp_prog); xdp_rxq_info_unreg(&rq->xdp_rxq); + page_pool_destroy(rq->page_pool); mlx5_wq_destroy(&rq->wq_ctrl); return err; @@ -680,6 +679,7 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq) } xdp_rxq_info_unreg(&rq->xdp_rxq); + page_pool_destroy(rq->page_pool); mlx5_wq_destroy(&rq->wq_ctrl); } diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c index 460777449cd9..d7307ab90d74 100644 --- a/drivers/net/ethernet/socionext/netsec.c +++ b/drivers/net/ethernet/socionext/netsec.c @@ -1212,15 +1212,11 @@ static void netsec_uninit_pkt_dring(struct netsec_priv *priv, int id) } } - /* Rx is currently using page_pool - * since the pool is created during netsec_setup_rx_dring(), we need to - * free the pool manually if the registration failed - */ + /* Rx is currently using page_pool */ if (id == NETSEC_RING_RX) { if (xdp_rxq_info_is_reg(&dring->xdp_rxq)) xdp_rxq_info_unreg(&dring->xdp_rxq); - else - page_pool_free(dring->page_pool); + page_pool_destroy(dring->page_pool); } memset(dring->desc, 0, sizeof(struct netsec_desc) * DESC_NUM); diff --git a/include/net/page_pool.h b/include/net/page_pool.h index ee9c871d2043..2cbcdbdec254 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -101,6 +101,12 @@ struct page_pool { struct ptr_ring ring; atomic_t pages_state_release_cnt; + + /* A page_pool is strictly tied to a single RX-queue being + * protected by NAPI, due to above pp_alloc_cache. This + * refcnt serves purpose is to simplify drivers error handling. + */ + refcount_t user_cnt; }; struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp); @@ -134,6 +140,15 @@ static inline void page_pool_free(struct page_pool *pool) #endif } +/* Drivers use this instead of page_pool_free */ +static inline void page_pool_destroy(struct page_pool *pool) +{ + if (!pool) + return; + + page_pool_free(pool); +} + /* Never call this directly, use helpers below */ void __page_pool_put_page(struct page_pool *pool, struct page *page, bool allow_direct); @@ -201,4 +216,14 @@ static inline bool is_page_pool_compiled_in(void) #endif } +static inline void page_pool_get(struct page_pool *pool) +{ + refcount_inc(&pool->user_cnt); +} + +static inline bool page_pool_put(struct page_pool *pool) +{ + return refcount_dec_and_test(&pool->user_cnt); +} + #endif /* _NET_PAGE_POOL_H */ diff --git a/net/core/page_pool.c b/net/core/page_pool.c index b366f59885c1..3272dc7a8c81 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -49,6 +49,9 @@ static int page_pool_init(struct page_pool *pool, atomic_set(&pool->pages_state_release_cnt, 0); + /* Driver calling page_pool_create() also call page_pool_destroy() */ + refcount_set(&pool->user_cnt, 1); + if (pool->p.flags & PP_FLAG_DMA_MAP) get_device(pool->p.dev); @@ -70,6 +73,7 @@ struct page_pool *page_pool_create(const struct page_pool_params *params) kfree(pool); return ERR_PTR(err); } + return pool; } EXPORT_SYMBOL(page_pool_create); @@ -356,6 +360,10 @@ static void __warn_in_flight(struct page_pool *pool) void __page_pool_free(struct page_pool *pool) { + /* Only last user actually free/release resources */ + if (!page_pool_put(pool)) + return; + WARN(pool->alloc.count, "API usage violation"); WARN(!ptr_ring_empty(&pool->ring), "ptr_ring is not empty"); diff --git a/net/core/xdp.c b/net/core/xdp.c index 829377cc83db..d7bf62ffbb5e 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -370,6 +370,9 @@ int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq, goto err; } + if (type == MEM_TYPE_PAGE_POOL) + page_pool_get(xdp_alloc->page_pool); + mutex_unlock(&mem_id_lock); trace_mem_connect(xdp_alloc, xdp_rxq); From patchwork Mon Jul 8 21:34:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168689 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7662726ilk; Mon, 8 Jul 2019 14:34:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyN0twF6aPEfQXVw3DTtMpMzyhlhry9B4iflibGhgurZIiXxbiXlTyjUI0KNMU5hxdFxG0t X-Received: by 2002:a65:48c3:: with SMTP id o3mr26784163pgs.70.1562621688764; Mon, 08 Jul 2019 14:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562621688; cv=none; d=google.com; s=arc-20160816; b=iKi2hKFJgeSIUSZBMKQY3KlKaiuosWSHIn4raDy5njGtMam1Kc4hw6ECZTYVZpxPRA WRGv5/hfpXMYk/IEjOCYGNIrFaJ7nsuTaHodZXKTXQGAjbAfHeWaKb4ro7mf4xtgCn3n 46Xye2sBGkt9smZSthqZovuZeGiGXh2SRVKadVbIg/D7KKMklw/PAUPmYNyQsMqxG7YE 4KYwGAUWb2/b+QQb/yyLDf7AML0XX+72VOLl/F9fX92JlXZIzWQsGpwIWR5/vdJy99wh oteBze6aTJtp8jo0wmABhctNIm0JuiVevz4+sf+5DeeMUBsfafHYz1Pyn6oids6fG2Jn YLLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=7qz/APLz7I7SX2iw96+bUAJ1ELRKkJJTwc+HuPvzgEU=; b=bOcCVycI17I5YilxI+qC/QgCNmDY3rtRhNkeL51Zk6HWDhk+gZ+Na4wSEIX+bzqfP2 gX0iq4sqLJKYp82/bmI4JljCEhu/KrSLqsvNM9OJ+gOTHc1uEWiQyHrenFdMk30KWMDC B04+rn83ZsRB9x+tLON68N0+dOHCWVDk1wpz4sAfz2wTJWjnsc1KupFlZgnFBvjYC+va FtgeMBLrCb7pfY0ZTKEWgiabQpHZ+NycQoXWR/sZhHXKW6IeAhLE2ZZOFa9R/DmZRWWF pcS14e1BMuDZ124jdInL1me6Scnfg2H2qhsBTfzSlTSzAoz52rBcIFdvUnvNQNr5tbDA T1LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xJsh55Tw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9si19229033pgq.373.2019.07.08.14.34.48; Mon, 08 Jul 2019 14:34:48 -0700 (PDT) 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=@linaro.org header.s=google header.b=xJsh55Tw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405081AbfGHVep (ORCPT + 30 others); Mon, 8 Jul 2019 17:34:45 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:38389 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404652AbfGHVem (ORCPT ); Mon, 8 Jul 2019 17:34:42 -0400 Received: by mail-lj1-f193.google.com with SMTP id r9so17431925ljg.5 for ; Mon, 08 Jul 2019 14:34:40 -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=7qz/APLz7I7SX2iw96+bUAJ1ELRKkJJTwc+HuPvzgEU=; b=xJsh55Tw8wSEJOG/LnODO2oV2ggkkhZmpd+yHJBnBhrICWL9AbA7DT9wwdyWIX+XoD 6MHiaW4LwvqNu1nVC6hp5+APpJ+I9q6qOV0M3uRnHiDh3ynlOoEpF4/XNp/5EvAuagze UPx49jNDPPt7YMbhZNqHWBPuWDRz6h5yfHoPkcfMYm9Kus7Iv3FJj46PC6hg9MHS4Ae8 CT93qsImJs7JCZ+G2rBm7htmfc5ueXAYrLawU5aHdwQEnpQd8Q0dyoft12fp/z2ooyeM UOOthITDRr817X1AMOxYbr5CxiBsqnIKaiRcmi0X/JLG7tYqd8BY7/qt4asNd7V63o94 CMRg== 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=7qz/APLz7I7SX2iw96+bUAJ1ELRKkJJTwc+HuPvzgEU=; b=BLPZ3aSKyzudx6XmP7ythdjiburiFBuKsoOLkG51YVFNnToafnRVzU/VMA530Y9Eel PMwV+jdkfVCK9FeqoG/FOx31PAI0QNkhwpRp9EEr+GYMyBQxwh3KC6DLnC7OOBcUxA2B mJt65ueE6MhuhkmmUhUAsY2yAlwb55SzKW99xFxfpBND7frX3Jzk+qVPeRH+2PfdYSXX bFVXiQ3B+rb/DPyqQC+UsacF0th3+bgbez7G3SbpDp4iEPc5M/d7qQ94nDVTLOBP3Uwb 7nfklQhWzEPlZGrpptvh+KL0WrZAnPjybGxkC+qK4nLdezPi40aQb3Iq0h/bE6FcjCiM RMyg== X-Gm-Message-State: APjAAAXusfF/umf5opxLC6700NUJnZhK0E4wqpzuQC+OZos5RZoVSi1M 6WgA13OollGW7GUh4h7Gwc8Eng== X-Received: by 2002:a2e:7619:: with SMTP id r25mr11413154ljc.199.1562621679892; Mon, 08 Jul 2019 14:34:39 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id o24sm3883096ljg.6.2019.07.08.14.34.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 14:34:39 -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 v9 net-next 3/5] net: ethernet: ti: davinci_cpdma: allow desc split while down Date: Tue, 9 Jul 2019 00:34:30 +0300 Message-Id: <20190708213432.8525-4-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190708213432.8525-1-ivan.khoronzhuk@linaro.org> References: <20190708213432.8525-1-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org That's possible to set ring params while interfaces are down. When interface gets up it uses number of descs to fill rx queue and on later on changes to create rx pools. Usually, this resplit can happen after phy is up, but it can be needed before this, so allow it to happen while setting number of rx descs, when interfaces are down. Also, if no dependency on intf state, move it to cpdma layer, where it should be. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw_ethtool.c | 17 +++++++++++------ drivers/net/ethernet/ti/davinci_cpdma.c | 17 ++++++++++++++++- drivers/net/ethernet/ti/davinci_cpdma.h | 3 +-- 3 files changed, 28 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/drivers/net/ethernet/ti/cpsw_ethtool.c b/drivers/net/ethernet/ti/cpsw_ethtool.c index f60dc1dfc443..c477e6b620d6 100644 --- a/drivers/net/ethernet/ti/cpsw_ethtool.c +++ b/drivers/net/ethernet/ti/cpsw_ethtool.c @@ -650,7 +650,7 @@ int cpsw_set_ringparam(struct net_device *ndev, { struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = priv->cpsw; - int ret; + int descs_num, ret; /* ignore ering->tx_pending - only rx_pending adjustment is supported */ @@ -659,20 +659,25 @@ int cpsw_set_ringparam(struct net_device *ndev, ering->rx_pending > (cpsw->descs_pool_size - CPSW_MAX_QUEUES)) return -EINVAL; - if (ering->rx_pending == cpdma_get_num_rx_descs(cpsw->dma)) + descs_num = cpdma_get_num_rx_descs(cpsw->dma); + if (ering->rx_pending == descs_num) return 0; cpsw_suspend_data_pass(ndev); - cpdma_set_num_rx_descs(cpsw->dma, ering->rx_pending); + ret = cpdma_set_num_rx_descs(cpsw->dma, ering->rx_pending); + if (ret) { + if (cpsw_resume_data_pass(ndev)) + goto err; - if (cpsw->usage_count) - cpdma_chan_split_pool(cpsw->dma); + return ret; + } ret = cpsw_resume_data_pass(ndev); if (!ret) return 0; - +err: + cpdma_set_num_rx_descs(cpsw->dma, descs_num); dev_err(cpsw->dev, "cannot set ring params, closing device\n"); dev_close(ndev); return ret; diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 4e693c3aab27..0ca2a1a254de 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -1423,8 +1423,23 @@ int cpdma_get_num_tx_descs(struct cpdma_ctlr *ctlr) return ctlr->num_tx_desc; } -void cpdma_set_num_rx_descs(struct cpdma_ctlr *ctlr, int num_rx_desc) +int cpdma_set_num_rx_descs(struct cpdma_ctlr *ctlr, int num_rx_desc) { + unsigned long flags; + int temp, ret; + + spin_lock_irqsave(&ctlr->lock, flags); + + temp = ctlr->num_rx_desc; ctlr->num_rx_desc = num_rx_desc; ctlr->num_tx_desc = ctlr->pool->num_desc - ctlr->num_rx_desc; + ret = cpdma_chan_split_pool(ctlr); + if (ret) { + ctlr->num_rx_desc = temp; + ctlr->num_tx_desc = ctlr->pool->num_desc - ctlr->num_rx_desc; + } + + spin_unlock_irqrestore(&ctlr->lock, flags); + + return ret; } diff --git a/drivers/net/ethernet/ti/davinci_cpdma.h b/drivers/net/ethernet/ti/davinci_cpdma.h index 0271a20c2e09..d3cfe234d16a 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.h +++ b/drivers/net/ethernet/ti/davinci_cpdma.h @@ -116,8 +116,7 @@ enum cpdma_control { int cpdma_control_get(struct cpdma_ctlr *ctlr, int control); int cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value); int cpdma_get_num_rx_descs(struct cpdma_ctlr *ctlr); -void cpdma_set_num_rx_descs(struct cpdma_ctlr *ctlr, int num_rx_desc); +int cpdma_set_num_rx_descs(struct cpdma_ctlr *ctlr, int num_rx_desc); int cpdma_get_num_tx_descs(struct cpdma_ctlr *ctlr); -int cpdma_chan_split_pool(struct cpdma_ctlr *ctlr); #endif From patchwork Mon Jul 8 21:34:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168692 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7662974ilk; Mon, 8 Jul 2019 14:35:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzq3DlxqJwFCEoHt2JWQxtghMZcwfMkv6k3PqxVaf6pWpTROaKHu6KRHXzIyzo1VEQ0hmoY X-Received: by 2002:a17:902:549:: with SMTP id 67mr27534178plf.86.1562621705132; Mon, 08 Jul 2019 14:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562621705; cv=none; d=google.com; s=arc-20160816; b=ii3GmaUnPDnNi5HqAZzdVrfo9dpJeAUATxO8cinLbSJeCpBVxeFV07x8+4L/pFBoKS csXSyL36TLIzV+vNoHkzLlmZqRxnE517YV+oTCGP8Vvet6Z6d2zKJzBAA7p3fzS2fiGa /LQQds6OBAJO62uOKe//QqH1KXrUwnaS1hMrUAk3iozVBjhIAnmCoABNglosrsMciz7l SN5tJRseNwYr0V5q6pkZFooh2wjvdKaCiAKCpUV4yB9Rrst02QKlW1SxwaW76KR3Ny7I 9W76h1BVt39/NGEpwW6dmjJN2WsEL8r8tSTjAu6muY1ChyNYVe270e/ywwQ/zVHwky/V G/aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=h0qJMdNciD39g3Q1jo3+1MbbNG9llP7wamgm8+ijc+0=; b=GKmk78CBV7mspclA2XwftfFEamTYhwI+qm2FY4ylHkZEe+D/rbQmStXwcyZsz+TR+s KabUB/ohN7ZnHgNU7QSjlX5gFBiHDocIMredKej5cM9oQZTghZWG20KCzK4QVW3YfhKg bHBfS9cxssTIImORoYLY2BkLcX/mu822Ad7rJJ+dC7LuH963a3iPaS8PGIpTmHjQYSC5 nKudHcGJfWpBmXBd2T0b7ZFm3lE+Qp0ZLrV5R9mOIQYWLy4LAYDe2bDw74MET+X/I/y2 2HPHgK9N9ipNmg3ExBw8NAwRvnNBOwaTu5rPlQfI3vNqI6Ya1vf4Jwkyo6XYbKw3UZnW e42w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ui6Ji331; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z24si9693975pga.335.2019.07.08.14.35.04; Mon, 08 Jul 2019 14:35:05 -0700 (PDT) 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=@linaro.org header.s=google header.b=ui6Ji331; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405368AbfGHVfC (ORCPT + 30 others); Mon, 8 Jul 2019 17:35:02 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:45173 "EHLO mail-lf1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731786AbfGHVen (ORCPT ); Mon, 8 Jul 2019 17:34:43 -0400 Received: by mail-lf1-f42.google.com with SMTP id u10so11907222lfm.12 for ; Mon, 08 Jul 2019 14:34:41 -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=h0qJMdNciD39g3Q1jo3+1MbbNG9llP7wamgm8+ijc+0=; b=ui6Ji331Gj4iwXnkewrzPZ/m3RPsSXRJWkE7ReaRNP99ArpS/s3Y8NOJ1YBuphMqgG hs2b/ERPkCcI5cCgjFjbBnM6cgvYsVSaH2tw5e372IW2I8kz+60ZaJLQtuYXv6EYA8UN /o8YBdjETAyImMGUap37phy9QX7QkvEk55lFo7E9i91UC8z9XsIZXV5QaP20y7X8MGXf 2AfVXtFI887KCOJ3BIENfyL44EuD5nDPFaTfwfUy8sIK6I4H3VYBMjInQZrs3lqxF7iO RhQkAaavW480NkS+JEwqB6/IA8a9708QIoYKU8cdZ5fvQDX7T32VI/loHpxbusuvIqHr 3Xdw== 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=h0qJMdNciD39g3Q1jo3+1MbbNG9llP7wamgm8+ijc+0=; b=FF9wuEK/e7Nhwl7kw7UY6ziw2wNeW3rrkJQMA1jWk6w/a2qYKkYewBSEtTNL2i+Ecd fCvlO1zn5npyjCVBuNQhWfpZFnKkwFsrT/LHhM6eEEJgBprybIBj1NH5E9zQbaSeEMF/ 0ydflgGqOsUbVQZB2n2JdwB4Uy9PoP4KNHT3V5C+dkRphFe3KTWLPGoIusJ97+9kr07E flG17w3E1GlJvPZWmR75FylxKVshHgmgW+Gu66Sno4W5j8JiBzHviibT8IbF7sDSatEN nkJ/u12ZuPDshs/Dc8Dd0r2S399EBcLMGwQpsxJEjm4VXdevIrr9ynQ2wAUqMTD3gjJc S3GA== X-Gm-Message-State: APjAAAXhHPlhvhDEUm1cIO6Oavlxz+AGo4PzYXe2se1WpqyIVwCkU/44 fCy1haXmfA4NLO0ZrdrtbJk/kA== X-Received: by 2002:a19:c150:: with SMTP id r77mr10408764lff.76.1562621681121; Mon, 08 Jul 2019 14:34:41 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id o24sm3883096ljg.6.2019.07.08.14.34.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 14:34:40 -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 v9 net-next 4/5] net: ethernet: ti: cpsw_ethtool: allow res split while down Date: Tue, 9 Jul 2019 00:34:31 +0300 Message-Id: <20190708213432.8525-5-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190708213432.8525-1-ivan.khoronzhuk@linaro.org> References: <20190708213432.8525-1-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org That's possible to set channel num while interfaces are down. When interface gets up it should resplit budget. This resplit can happen after phy is up but only if speed is changed, so should be set before this, for this allow it to happen while changing number of channels, when interfaces are down. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw_ethtool.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/net/ethernet/ti/cpsw_ethtool.c b/drivers/net/ethernet/ti/cpsw_ethtool.c index c477e6b620d6..e4d7185fde49 100644 --- a/drivers/net/ethernet/ti/cpsw_ethtool.c +++ b/drivers/net/ethernet/ti/cpsw_ethtool.c @@ -620,8 +620,7 @@ int cpsw_set_channels_common(struct net_device *ndev, } } - if (cpsw->usage_count) - cpsw_split_res(cpsw); + cpsw_split_res(cpsw); ret = cpsw_resume_data_pass(ndev); if (!ret)