From patchwork Wed Jul 11 19:32:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 141766 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp674889ljj; Wed, 11 Jul 2018 12:34:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfo/AKKb7TzGUZ7yc9w08OvmLqtUYQ8FHpNdVlmXkvQ9iEDb7dbsWduUTbqx4FKEMpwvBpg X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr7428138pfa.238.1531337694449; Wed, 11 Jul 2018 12:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531337694; cv=none; d=google.com; s=arc-20160816; b=Zljyle2E9ojSbF8kvZdL06mYikT/tpwClcAxwVjHv/JQHgKgpAqMp2CTewOmu2cvkS YracfO5h/OfXHVX2LRvWkgA4W7S+wzV2xLdYIAQHu4rdQx0olJmZklqE2DFIkQ+p5Esn DOvdff234oMHIw9AMnCZFCPbYaYHE29IzPJuIimd4oSytJx42pdOZnrDZcEPi6B7aDZ/ xuFc1zcdJSwCHXJ7FaOnkCHwefOfl6XyrEYsn/LpE2RLlB37d/GeTJCEYUQJpA3BZHwU OJB2fpXg2RtUiSbomvP9NfEhqrsvLyxxNuwzcg6wx4hQdDbimNFhzu+PFCdg085Or05H Ypsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=CZUb51v93n+rUDv42hpfOAOUw7nXASqVU18EbpoVEe0=; b=qoQk8KX3ksbV2yMty6sVQHZDIxhYthUyQ9d980CMLIJDp8E2xMEZiHTTV2xLv9KzS6 qKkmpSBORZfrt3rnkk5rmqn811fad1lGGqbQQmLUrb6ntoD9NRgGCnJu0w9lHg+zGZEq nj7lE+keMXmopOkmaWDYziD77IblbeWOHAEEy86uC4noDhOCpcFn56x/C+pj8zyE9xaT asU4fk0+cvW0ey1MyxN0rdAPL0OaFkdTK9u7XUe/P3udk1G+kw43NLXyTbRdoYxLbTjl 69b4I9lQjR1vlmFnQ0V5F6Zzgcb52x6UVoaCerwHh6n+pDD4znGt0vvoRrB0U3RidwtA o0ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W6Ha42Px; 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 e88-v6si21175813pfb.185.2018.07.11.12.34.54; Wed, 11 Jul 2018 12:34:54 -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=W6Ha42Px; 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 S2388269AbeGKTkk (ORCPT + 10 others); Wed, 11 Jul 2018 15:40:40 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38394 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbeGKTkk (ORCPT ); Wed, 11 Jul 2018 15:40:40 -0400 Received: by mail-lj1-f196.google.com with SMTP id p6-v6so20266781ljc.5 for ; Wed, 11 Jul 2018 12:34: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:mime-version :content-transfer-encoding; bh=CZUb51v93n+rUDv42hpfOAOUw7nXASqVU18EbpoVEe0=; b=W6Ha42PxmGCKg6gYya7gQMTcY000eyIKxCSY71XASo0k8gVAm8s4bzOSI3rOry4Xsr SKnFdMFRnH2VyepnD85Z6fD7AaKvrp3BwZREGx1Q2ONx2qBhG6mYbOBGibqkdA/74wOG qANooEDFD3S9GkTxIl/FakWtI+j5SllGKcUJU= 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:mime-version :content-transfer-encoding; bh=CZUb51v93n+rUDv42hpfOAOUw7nXASqVU18EbpoVEe0=; b=M5BD8vF1bE8I3xyV6utWNlclLtkgKwmDqv4RlA1Ivo1+0z+nN4cWhIQc9Gzf9jXg+w HDOAK4lOC9/S61y32Wk3Ow0jNmeSZjOHdIsdE6Tb9nhu7uQfdYGr0HLWuhKFPulCOFXT IrnX0OSf//+Im5qTJtH8ZbXyq6o0xT/kpPSLrcXIzMWM0ihWCYJWJ0+HSgQIFlYUGhZ2 iEjSkJk4dk1ZTDYCsE8tr4kzKlI7UPIJKSlMSo/7xk4ShYLCo3w4QvQYJ00qFjaDzOkb G59KFSJoCeMJQsaDHNxHv8gIts8JuVp1mUvC/sfpVB+nxMmj7esDxFDxau2b6lVafjpk 2CAA== X-Gm-Message-State: APt69E2LVvAQy9oRPO09gB7d5Z/NJe9gWEYEevAcpnSCqJ31bVIKytQI sH6tc3eNgUl+AYbinjGVok1HBiS+zQY= X-Received: by 2002:a2e:2114:: with SMTP id h20-v6mr13932626ljh.135.1531337690335; Wed, 11 Jul 2018 12:34:50 -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 y5-v6sm5502299lfc.58.2018.07.11.12.34.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Jul 2018 12:34:49 -0700 (PDT) From: Linus Walleij To: netdev@vger.kernel.org, "David S . Miller" Cc: Hans Ulli Kroll , Florian Fainelli , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrew Lunn , Linus Walleij Subject: [PATCH net-next 1/5 v3] net: gemini: Look up L3 maxlen from table Date: Wed, 11 Jul 2018 21:32:41 +0200 Message-Id: <20180711193245.21980-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 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. Acked-by: Michał Mirosław Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Collected Michał's ACK. 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 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)