From patchwork Wed Jul 4 18:33:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 141082 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1096516ljj; Wed, 4 Jul 2018 11:35:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf/BScVjSq3nWnFQYjg4PTOVx2Ss588Rj4tkj3oGQlJwo4FnlJumbxCCV/weauvGyxbztrN X-Received: by 2002:a17:902:345:: with SMTP id 63-v6mr3184831pld.328.1530729336584; Wed, 04 Jul 2018 11:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530729336; cv=none; d=google.com; s=arc-20160816; b=Z0KvkkINRrzEIDOUNxf6f97qH6+gV7SnmIMPdD19iZYZq0ySzsmts2CvTEgHkrakuP IFEhPnzO8Dycj6E6z8nOjxlTN0TXp1Il5/YeXvuyYGsxHkpQD7vfBe1GkMsXRXdhrhxn mDDf9+pUW0fw9HJErKTY7UHDiKrS/0MswLdOocTTi/jJ5IDZcBbAcyWOgYfSzpfkhAzL 452+Ur7OV4AxDzz32HywHXrDY6f1XLh3l+ncUzALLJh2p+O8y2bFMmGseiWZ6GMUCsem 7mXGUHDGIbBQjnHgJFrQkMCmNNV+KZO3YpjsD9yarKFn7Ihu7c1wn2JsUsH6R6/azZ6M T0yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=TmRfJbI9A2u95XT6ot+9VMvVgQcawycnmBgnQFkZg1g=; b=pvwd8j5sDScthlvQbU1fchPnsejrQh+DWRJwrB2jCLb6pKmXROZvQtrpsorsw57YNY AY4lLxVMmcuTkmOkeW2nWfjcXSKDLSShZFQcgRHsM5FD2lZfQJmwewQYeyXEEaI9Bszh qU6tdS4k8OElzE/e4UHrpFnlBCBXczxUZCWe5jFQKRYa5c/JZgiSG+pIoESMCXQdYc1K 9Ceer0ZWEXmYpY1s6BGwOie9RcbCaWWaZ0ki8VuPguYjlE/bLxJ6BBBotuj5D4rXqntG qWCMP5gSY4+VlhHb28FHcSLEXUMFOMvcS6gnXxsW0GqUzQVS4UHMK396dyYbZqjLwbNm oBEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uh74O0HI; 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 d6-v6si3961989pgh.569.2018.07.04.11.35.36; Wed, 04 Jul 2018 11:35:36 -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=Uh74O0HI; 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 S1752533AbeGDSfe (ORCPT + 10 others); Wed, 4 Jul 2018 14:35:34 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:46082 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752165AbeGDSfd (ORCPT ); Wed, 4 Jul 2018 14:35:33 -0400 Received: by mail-lf0-f67.google.com with SMTP id l16-v6so5008513lfc.13 for ; Wed, 04 Jul 2018 11:35:32 -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; bh=TmRfJbI9A2u95XT6ot+9VMvVgQcawycnmBgnQFkZg1g=; b=Uh74O0HI8xcC2jZtKL04Jox5lofVEN2AKykXwsOIRaSAeN6x7jx9iF+vVzJU7mcB3C 47Yb5+LGVPKE8MjXbu2Qqd24oPsqw9OcwZ9cGdUb1t7ZHrT0rx45R+PLXV0hiEOAqQCc uZMbGKBP3HwL2h7tv8NO0zCi9P3KwDEK0Ebko= 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; bh=TmRfJbI9A2u95XT6ot+9VMvVgQcawycnmBgnQFkZg1g=; b=Lw7Qf9jjnCZOp8YRM8hawZv5Am+l+qfzaGSyGLt/newXjfhx1xkwWCJOrV6H+yuZcj /vRtnH05rWeIHqiegJUEyl/TR/VJC4hfKG13xBzJgEfQG+9/gayBZ5mPBOyNHp7je/LF Y6v8OY292nCaOlBhp6QUVwll4SHFiRiekEz3WO+RUddvIh/vYctsvLlEDqQ5O9NYSLD2 UvrGklaciLNwHZYtROd0aq6PtjPlaFTv6xqiurJS9gHzlAdUhqrzMJbff1HeBzTIET0v y48mUA+U5VKI5jAu36oeRd41ycs6QAyB7+C7R5jbqKtxuXoN2IOalUQSUSgoi+eY0Gd9 3ywA== X-Gm-Message-State: APt69E2mkhpX4Hh3yBTDSFbxjEopMYusfBu2NRXB4FiQygtADfV9UlRZ ebBxq0hgR+UulfwEdwenjj8+60uNwIk= X-Received: by 2002:a19:6b03:: with SMTP id d3-v6mr2236796lfa.81.1530729331681; Wed, 04 Jul 2018 11:35:31 -0700 (PDT) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id g2-v6sm681094ljj.53.2018.07.04.11.35.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Jul 2018 11:35:30 -0700 (PDT) From: Linus Walleij To: netdev@vger.kernel.org, "David S . Miller" , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: Janos Laube , Paulius Zaleckas , linux-arm-kernel@lists.infradead.org, Hans Ulli Kroll , Florian Fainelli , Linus Walleij Subject: [PATCH net-next 1/5 v2] net: gemini: Look up L3 maxlen from table Date: Wed, 4 Jul 2018 20:33:20 +0200 Message-Id: <20180704183324.10605-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The code to calculate the hardware register enumerator for the maximum L3 length isn't entirely simple to read. Use the existing defines and rewrite the function into a table look-up. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - No changes, just resending with the rest. --- drivers/net/ethernet/cortina/gemini.c | 61 ++++++++++++++++++++------- 1 file changed, 46 insertions(+), 15 deletions(-) -- 2.17.1 Acked-by: Michał Mirosław diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 6d7404f66f84..8fc31723f700 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -401,26 +401,57 @@ static int gmac_setup_phy(struct net_device *netdev) return 0; } -static int gmac_pick_rx_max_len(int max_l3_len) -{ - /* index = CONFIG_MAXLEN_XXX values */ - static const int max_len[8] = { - 1536, 1518, 1522, 1542, - 9212, 10236, 1518, 1518 - }; - int i, n = 5; +/* The maximum frame length is not logically enumerated in the + * hardware, so we do a table lookup to find the applicable max + * frame length. + */ +struct gmac_max_framelen { + unsigned int max_l3_len; + u8 val; +}; - max_l3_len += ETH_HLEN + VLAN_HLEN; +static const struct gmac_max_framelen gmac_maxlens[] = { + { + .max_l3_len = 1518, + .val = CONFIG0_MAXLEN_1518, + }, + { + .max_l3_len = 1522, + .val = CONFIG0_MAXLEN_1522, + }, + { + .max_l3_len = 1536, + .val = CONFIG0_MAXLEN_1536, + }, + { + .max_l3_len = 1542, + .val = CONFIG0_MAXLEN_1542, + }, + { + .max_l3_len = 9212, + .val = CONFIG0_MAXLEN_9k, + }, + { + .max_l3_len = 10236, + .val = CONFIG0_MAXLEN_10k, + }, +}; + +static int gmac_pick_rx_max_len(unsigned int max_l3_len) +{ + const struct gmac_max_framelen *maxlen; + int maxtot; + int i; - if (max_l3_len > max_len[n]) - return -1; + maxtot = max_l3_len + ETH_HLEN + VLAN_HLEN; - for (i = 0; i < 5; i++) { - if (max_len[i] >= max_l3_len && max_len[i] < max_len[n]) - n = i; + for (i = 0; i < ARRAY_SIZE(gmac_maxlens); i++) { + maxlen = &gmac_maxlens[i]; + if (maxtot <= maxlen->max_l3_len) + return maxlen->val; } - return n; + return -1; } static int gmac_init(struct net_device *netdev)