From mboxrd@z Thu Jan 1 00:00:00 1970 From: 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> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Hans Ulli Kroll , Florian Fainelli , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Andrew Lunn , Linus Walleij To: netdev@vger.kernel.org, "David S . Miller" Return-path: 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) Sender: netdev-owner@vger.kernel.org List-ID: 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(-) 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) -- 2.17.1