From patchwork Thu Jul 4 23:14:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168497 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2795362ilk; Thu, 4 Jul 2019 16:14:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAAs1Vd4BxIYNmEt9p6U6fCnKBx0ry38UG2ystsg09/BQRjWfyAgNUcx/4P3CNGJCV2Y33 X-Received: by 2002:a17:90a:1785:: with SMTP id q5mr516331pja.106.1562282070130; Thu, 04 Jul 2019 16:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562282070; cv=none; d=google.com; s=arc-20160816; b=T+h+ZFn5ur2SixbMjmxjpg5dskXBvjVArLd427DON075SScA79LpPPy4hb9lt7l4CK 5UW2TIHUgAAf4ZOI+oy/FdURCo3VXtYcwKS56p2gqPOrRI7slcimwtybcQXO2v6nj2sy cIptZ9N7HxgTlDTBBjJa/7RIkaanWtJ5uWivRBkef2j+huCNEaVrIALFC579GEy7cN9V dW6NyrZpzMrXQlkNG9s9RnbmCiZfDEaHqN4Lw1NwSwNDbQPMAw3xFxZ0hnlFDDdJqBCZ 9EhA94XV/ZexkYdt3J3eHImXbGrExGR9/3ZkRal1sh70JCDM/RsZgKcIAFcdT/1OJ7oP GLgA== 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=SGQUYbY4XW1Z9XXXeZ4lJkDSGyOAypA/R60V5jpvUd8=; b=ggYhUz3zK40Nalm6X15tCs77AyFg346EJRHNRZ1cCih9yQaqD4kpxlutn6frpgA5Er A5MBsmBrbXl8ebrAG55nkhzE/JnvNm5ItK+wfKI7+xLfF28ki6IIbB14vX+HXzPWVOmv B1jk26oQAODQYNJjTL7UQo2gN+IdlEKUKJbV9wtyfZFLDnqoCXweaaOMi0R5P8sbzxlh vYb9imoD4qS81cjsOWaLIfAIPiyXQZkr0AmhT2bkHcU26vQWmhm0pPN7s97mVK8KGW/5 RzLrgJlwr1HkdsklLKKIVhSHkY//5Mpn1NbGigBisPe7xbGKuxQyizij9Wl1eCpVdBjq 6qpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xbu2Hxe0; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 a187si6843970pge.269.2019.07.04.16.14.29; Thu, 04 Jul 2019 16:14:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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=xbu2Hxe0; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 S1727598AbfGDXO3 (ORCPT + 9 others); Thu, 4 Jul 2019 19:14:29 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:35112 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbfGDXO2 (ORCPT ); Thu, 4 Jul 2019 19:14:28 -0400 Received: by mail-lj1-f196.google.com with SMTP id x25so687416ljh.2 for ; Thu, 04 Jul 2019 16:14:27 -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=SGQUYbY4XW1Z9XXXeZ4lJkDSGyOAypA/R60V5jpvUd8=; b=xbu2Hxe03NBLxwu4IknzvQfUw0/N7DIWdtGDkQd8QnxxNP2OpyAw8SqgFDQsg6EQ56 5TarBFeO2+7JhvInQOj3MxGr/inW24WnZgQxAurMpIOMyZ4bSIs49ORFP44KO2HkPLXU ENfegxzCxDICgc4zgNn9dcv6KBuDTCcAGHI/At2TazrwzSi2GDGeIJpNFQwmv5zMr9ZD VRWqXK57NTFitmqTaZ+ttr+RSMzTk8YEr0wHBVMEIkbYau2ZEEFc2U5Lr/szSADeshx/ ia+UDiHob74RrfXvx59Vi91wMOHisbcGTcciaP3slh6TyMzW5t0U0bFVjh9x7tf+dw79 9Wgw== 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=SGQUYbY4XW1Z9XXXeZ4lJkDSGyOAypA/R60V5jpvUd8=; b=hWMo9pdlfdfWdk8rlvNwr5DIZ9h7/O9EXuqrMve55BLoo7qqoNPyvSgGuOUcddOCsK QrnSXsaUIEqTmKEHKNApuOGI4leQVH7zPKkLzCXnL2SYnwdZz2JCsWiFgtTOP0uXwwb+ RaSZ0q1r8ghejGZNs2KzE13RyUbAbQsNAZL/MU2b6gZurOXMAkLWFLyIkgniJJrqj+AZ 9BOGbN6DIUSCuj/DdVtlKDmFQP+12bq3A7tnWOT2A+1QGJZwQdQM2z71AP9uhRzwjFok dgax22bVGYrCtp/97MR8eGbHjfipGyEG+E5Tx96fnt7Yid6GXymQUbvWYRV4M/ZUxHRp ELNQ== X-Gm-Message-State: APjAAAXzVCpg++wu1BwlmSZ1KmwuwZmb/20I2yLyRVoYNz+SVBeLT5CZ gpjYvYl525C8p50i2erLuJzgJQ== X-Received: by 2002:a2e:854d:: with SMTP id u13mr309338ljj.236.1562282066340; Thu, 04 Jul 2019 16:14:26 -0700 (PDT) Received: from localhost.localdomain ([46.211.39.135]) by smtp.gmail.com with ESMTPSA id q6sm1407269lji.70.2019.07.04.16.14.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 16:14:25 -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 v7 net-next 1/5] net: core: page_pool: add user refcnt and reintroduce page_pool_destroy Date: Fri, 5 Jul 2019 02:14:02 +0300 Message-Id: <20190704231406.27083-2-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190704231406.27083-1-ivan.khoronzhuk@linaro.org> References: <20190704231406.27083-1-ivan.khoronzhuk@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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 Khoronzhu'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 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 2f9093ba82aa..ac882b2341d0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -575,8 +575,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; @@ -644,6 +642,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; @@ -678,6 +677,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 5544a722543f..43ab0ce90704 100644 --- a/drivers/net/ethernet/socionext/netsec.c +++ b/drivers/net/ethernet/socionext/netsec.c @@ -1210,15 +1210,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 Thu Jul 4 23:14:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168498 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2795541ilk; Thu, 4 Jul 2019 16:14:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMFzNkwSxb/CBwkUkAlVxdsLmzBXdwEUT9ANkC+WGLsvn766tX67iVBfibmmfbZGiAftW0 X-Received: by 2002:a17:902:7d86:: with SMTP id a6mr732080plm.199.1562282087865; Thu, 04 Jul 2019 16:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562282087; cv=none; d=google.com; s=arc-20160816; b=a2+Vcu6Z2rU0WQJW8+36Zx3Fgt19APF609olArbu2BgeSlaZ2tRVYxUyintdcHrFCg gYC7dXz5ZsAEamj/A17SFYvv1aYQLE3rPy8ledzHZU9liuv+8aBfvGK489F4UTB/NdEg +j2+4nyACbv4MKqRnNM2OArNd98dnY7xicGMLa0LTv8vrCZMDlNn/bBGbpI39wIWqlEm C+W364JfIfBquFCn9ubC4YR4uLMwhUu0FNoXZ2PGfk6o6ZQRJsqYtmbyMd7SZxjmmcbk eqtyrtEKtmtZwBADpPNnXuw0xNTwXuRF+PrjwJxTvthTWZWt0ySE/csr78Lp+0EUwrBd EVtQ== 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=3MKWFq9DHUtTXp9RzrqM9cpDCCIlrZafhvrB3JiYBHI=; b=QQSNAaCLSHryrS9+i5l/mWGKqqbB+QzqnjQ+vQF0hO836aBqyrdbiBNu4076TilR5d RzCYVg1OEBfMadWlRZsxz0f5jVPuiFE9H/M2ByF1FdhWdVDU37Bh37bfLCSzR+owgnOL GbQZkCKxDRf+I40X8dxIMssbc2R3rKfrr8D0Ea1J2B9ECLt1CWDtNubPprJf8FNHiYqe idTgYpSwMahsXR4bWDiKPUnugVMogtqfaSZ2+OabAjZmaaMQs8R+u8g0hV/aCAFHbKiP t+iogvtgX8XKaIyDaofsahX2dqTToErt9rBej3cyfvr+3xXwOZo0aKk3fk6hsxPmb8Z2 P8Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=luSEBYWC; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 d18si6867233pfn.202.2019.07.04.16.14.47; Thu, 04 Jul 2019 16:14:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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=luSEBYWC; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 S1727688AbfGDXOi (ORCPT + 9 others); Thu, 4 Jul 2019 19:14:38 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:35123 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727642AbfGDXOh (ORCPT ); Thu, 4 Jul 2019 19:14:37 -0400 Received: by mail-lj1-f193.google.com with SMTP id x25so687626ljh.2 for ; Thu, 04 Jul 2019 16:14:35 -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=3MKWFq9DHUtTXp9RzrqM9cpDCCIlrZafhvrB3JiYBHI=; b=luSEBYWCfK2cKUnoHWoL56vfCR/h4ws0+NF0Fw4aCQ2ade4bm/G8dXaH+o4+SCePYb gm2fHnq+qTzUFXA5tV0g/itprk73XMOtK04bSrLlydGVaS7Z+zb67PGX5WWQlOs9B1tg pQRPlztmicp184qQ1hwaFgophdIMAi8b/Q97HSlL1Dg9+gI+iH/FW4tMD3fEFLVedOUI Incefd9h4l1bFUEUDeht6ktklb6K3fQeEmr1jHIUPfXxx90UzvLHWEJJYKd8lLQPjqTL RLv8c4HZY6QKeMoatYtCQ8t8JqnhFH7sIFtgBbWGSa59mJHOzg/b+bPiYLEUCJ/iQnvd HmOw== 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=3MKWFq9DHUtTXp9RzrqM9cpDCCIlrZafhvrB3JiYBHI=; b=au1YSMgOuYsJeQjkHj572q2ZfuhFjAmJz9Lku5ntcEH8pfPDJ9w4u5UYOFNF08h6pj gTGgLCrwpAIGy+07GAQpse6dQSmLCFRJ/5YdGb2TWndKi3ahJ9jTKp4jKIPhGNljTvdn NWkSf3VwGDZcYdSEG2GqcJUndFBKs0mF4suB7ZgRbK5Zub4NGaH8fZTfLk9wkAWXRtaq jm8ARc0I9dpZdUObUTW/lOtbQKGjz8wNhzuVizILUqHUXlmJg3s+7zvuv2whsrHBRA95 qoZ7MAlhNO2ik8gWdiQQXfO/ThEnImDO9a9rmvN2MY06lHogOhdH+H5MTl9wE9W/32x/ P2rA== X-Gm-Message-State: APjAAAW5RTwYUMlo8l7el1VNIWgpMJpASYYVzfKEK6HkSuCxgv2I1DfG B0mXpIx6q1rliHUEd/Y7H4hkVg== X-Received: by 2002:a2e:994:: with SMTP id 142mr300201ljj.130.1562282074688; Thu, 04 Jul 2019 16:14:34 -0700 (PDT) Received: from localhost.localdomain ([46.211.39.135]) by smtp.gmail.com with ESMTPSA id q6sm1407269lji.70.2019.07.04.16.14.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 16:14:34 -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 v7 net-next 3/5] net: ethernet: ti: davinci_cpdma: allow desc split while down Date: Fri, 5 Jul 2019 02:14:04 +0300 Message-Id: <20190704231406.27083-4-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190704231406.27083-1-ivan.khoronzhuk@linaro.org> References: <20190704231406.27083-1-ivan.khoronzhuk@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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 8da46394c0e7..a3b6aeb4e935 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 Thu Jul 4 23:14:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168499 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2795543ilk; Thu, 4 Jul 2019 16:14:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNdOeKUCes4WG+HPC1Qy4Kcq6jhqaAT26tV24FDOcJXAitPQd2JFg1FIiVQZHNWrq485+e X-Received: by 2002:a17:902:bcc6:: with SMTP id o6mr770457pls.268.1562282088141; Thu, 04 Jul 2019 16:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562282088; cv=none; d=google.com; s=arc-20160816; b=bCMxxts/++y57iy3OJrg1QXtkF1HBcAzqO90J52TI5ghvKAkdEFDGI+cypl994xJD3 r6Oi8V6uv20YW3WK1tKRPz5TIXQBwErOeL+tZI44MUk1z9qFUG5NS48HFW5yZdKGXku1 hddBHRPFB1bo2XEJqmufMcDN42u8U9ViCHWbrtnknDwbfNPquUEkOW1tqTiMFnlAyp8Z jYM5+twOZ81SV0QTlQgJmTqLaFdt7xFQj9ZLyfcXjxMeVeS82b46ZM4/KxhS8mTvIGGD mGT8kPneS2npYf1fZEExRHHanmd1pKkLPMLaQngqzAXR4+o/uOelYzlGmNMKPmCeS/aY 4LpA== 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=0f+V7415HRt6iVJlFMmXW4JvGULj18vT3LXuKCf2NTI91l5BVDqzPoW4QurTFBfgBu 79LNwB84F4aifwl8SJALB+75EaTXVocvLXjL63Fmshewn5a8fLteA0OZ4HMj1urMDEIq l8xdN7nS/7vV4BWIrv7wrjNRKIzQVVj2sMmX1EurfHsuoVLG7pbDfrFtS7r8zJKgr6TG vSJWHr4uKHy+OsN5ieORZNMnMwNk2VuFHUNx+++6ZqzfAocZG5ZkRZFHxUOeIB/wPOkx c5M26KNF3PSoi5umy3Q7KSTpMqsgS3gEhNYF4WUQrzUrcaXBx1+eP29JVtujyY9zC6jC 48eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQHpY4yA; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 d18si6867233pfn.202.2019.07.04.16.14.47; Thu, 04 Jul 2019 16:14:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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=kQHpY4yA; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 S1727700AbfGDXOj (ORCPT + 9 others); Thu, 4 Jul 2019 19:14:39 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:44928 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727675AbfGDXOi (ORCPT ); Thu, 4 Jul 2019 19:14:38 -0400 Received: by mail-lf1-f66.google.com with SMTP id r15so5089818lfm.11 for ; Thu, 04 Jul 2019 16:14:37 -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=kQHpY4yAX9tuFqi39cDVI528gNTKLvGMgp0fqlEEE4DscT2m11B0xfPLDzS1j+aNlZ UGMk4PmMzG9FjNTsoVkPBdsX5iAy54gTqfhQ/kkz1CJfRr6/yZPK6hdSNfh52Ye2n2Z/ 7K1NL3GmJfoDXyyJRppCGfHFJcBQmsQ46cOe6yjy7ZT9VnXN/dCd6d5C5H+OXYUSIcU/ HA/ERprLUpxQi6I5rKcKODbM6zC6zJ89Q9AXb1sKtMe4+xhPbdzfhVvc/TrPTPHtcCHR IOCXKtNAOOOZ5q4fu+AHhPqh1/fAlMu7ALbCkPIvW8scV45AIsE51nY0Q9hCsrzhCYk6 NKBA== 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=kn2ui3am7e6UBoae+2Jz7LLN/DsO5z4SDoWXa9upAgRsYi6gxitsLJ2JLigqTjyxNZ 0yvaAZtTv3drYe5XE/QKCjNOPZAJLDLZJWtiVOS5rYjbrdPteSTIt+H+9ei+CtL0ZAIq 1j2mMSNcSrf2CpeldZH5RADBxdUn3y82m/YLwgZKnEjFQXfhofGZZPOrtw8h1AGhCWeK 1fgnUyuJ00wNifSI7zGjZEfVCr514AAK9VR7/YtnKXD1zbDJWx9pz4PqTFE5rrz+o6tS saSedNTL7F8jdT3e9R6l6WBwk0nCFWkDOHjJAccCemO5QAJNNTsS0vVHshxBkVhbCTg5 oeiQ== X-Gm-Message-State: APjAAAXhx1Jrc/ACs9KAf6OKbUeUhkLkYSUhBeh0GBqC9UJPYjDcqe3v uq4IqiO8NzTYcSI2mjPWxDmicg== X-Received: by 2002:a05:6512:70:: with SMTP id i16mr413464lfo.26.1562282076772; Thu, 04 Jul 2019 16:14:36 -0700 (PDT) Received: from localhost.localdomain ([46.211.39.135]) by smtp.gmail.com with ESMTPSA id q6sm1407269lji.70.2019.07.04.16.14.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 16:14: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 Subject: [PATCH v7 net-next 4/5] net: ethernet: ti: cpsw_ethtool: allow res split while down Date: Fri, 5 Jul 2019 02:14:05 +0300 Message-Id: <20190704231406.27083-5-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190704231406.27083-1-ivan.khoronzhuk@linaro.org> References: <20190704231406.27083-1-ivan.khoronzhuk@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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)