From patchwork Sat Jun 30 16:18:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140681 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2138777ljj; Sat, 30 Jun 2018 09:20:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeqYiRQTicWOE/uC/ZLoHPQWzQ59c/xMi/DFG1CSF2HuI1B1gmEqS01z+3BNOR++8xvpVYD X-Received: by 2002:a65:4e84:: with SMTP id b4-v6mr14209764pgs.293.1530375642042; Sat, 30 Jun 2018 09:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530375642; cv=none; d=google.com; s=arc-20160816; b=tI7DYoVGhCo2TR4nJy09RKb1S3emy58OKR5ld6sjAipQh4mIi3PJizYH3iLDqujVRQ ic6ioLSV3N3A5SO45OAlT6Ua9W+wIH7wcRUeeY2IQE6ZEsRpR3PGrpnjN3mPRVv/A0fM 5Shst+5i2d0g9D81dwPe3ZKsfTnk5h2kNflXM9MZZpL6+AuJmHWQRHFN0jHN8tpgjT+w I86Fu0h19G2IdkPgjNmLnmx9u/ZxfK6NHUtp+0WcKHGAOikI1dTqXNFzDGbW7baAzZzQ efHXs27nGeiQI42hJX6UxwJ66e3AKiCyQzJmTxBMen/542OnqLmRRl4SFJXoJnQ6QuFj kWEg== 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=vTNCzfqgVI/ts3itcR8up9gaX2uJ8xL04YE+he4T6hc=; b=inUxluYsQyI/QWcE7sdb83oxUpo1JK1KYEaVzVUq89lsBX0zgi/8uXklPt4uEUKeof D3cXtZe3GmXQuEmQDjsVXN0jJ/zDevGqG3h+QIEsIXjRsduO9AzAp+3gi0b9inGmopb6 ODO9CnBREYRYt22H3FlHJ7ibwMiOeVyQ1i/NHmSf+Sg0xKgeRTUx5fK1AEuMiCijRVej jxUg7RJF4xSbf8gFXb6Rat8K2p6yidsWRM+gwX3kpb+C60RU2ywYO0PSS4JSQGoJik6t Opmlbw993VyOVmzViyuurAILb8Y5FGWMn1f7+pM75Bn/fHF1dxXejycezeVn2A0F9HHJ 2JFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LlsrEzjn; 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 l15-v6si3618264pgf.451.2018.06.30.09.20.41; Sat, 30 Jun 2018 09:20:42 -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=LlsrEzjn; 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 S1751241AbeF3QU3 (ORCPT + 9 others); Sat, 30 Jun 2018 12:20:29 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37795 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751113AbeF3QU1 (ORCPT ); Sat, 30 Jun 2018 12:20:27 -0400 Received: by mail-lj1-f193.google.com with SMTP id c11-v6so9540181lja.4 for ; Sat, 30 Jun 2018 09:20:26 -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=vTNCzfqgVI/ts3itcR8up9gaX2uJ8xL04YE+he4T6hc=; b=LlsrEzjn/g2c8IUXL7UQ7bBl0pe6Sj05Hwo/E/m50KnAaoXmCS+SDvOP1YoaSY+fdM A8+UrNp4nDmk+nL+3veCwsvt3p9j5/KUFwyd/70G4EmCkrFZUjDGxxJhT+MNoMFNkGrC J8Qi9Z1IXbCsE8f7xlXoyYaZS9OzuXldc5wDc= 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=vTNCzfqgVI/ts3itcR8up9gaX2uJ8xL04YE+he4T6hc=; b=byK0qbJ7NRYvSuiFFnIgvNnmwNCAx3HUyQusr39Hc2PjbTNRPJ6GTSTVaoChnErkUO 3cvaHGudA11o2AN71S19HhGzPnmOm0EH0SQgOk1WuxCEWDyuPfJmIEj2R4dXE9r364oe FO7n1WOA96+GjfX39JyElIBNEOksyU0XLpc2TGsLA0NZsQq8K8ZmZrUPanw4bCQ71/Yd kQQYSZILjTNEDJkTz56t8JxNt7d2mFx/0utXlJUgnvAA2K7vWdedqa60+675WyjI3fwT fTK1gGwmAsGC+aL2BFvKY9rf9j3nyPSsyRpXBMCBHd3iW9M7/fioIAWPxPy6s19aTknJ JrBA== X-Gm-Message-State: APt69E3XgpqQVLEo4vmo3ngm8ClrpotHlhBpMlu8Dc0avmxZDiQ7y7H+ lgBL7gufrmydrNbDSHoKe5eahjhgW70= X-Received: by 2002:a2e:330b:: with SMTP id d11-v6mr12473059ljc.67.1530375625350; Sat, 30 Jun 2018 09:20:25 -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 93-v6sm2271978lfy.64.2018.06.30.09.20.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Jun 2018 09:20:24 -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] net: gemini: Look up L3 maxlen from table Date: Sat, 30 Jun 2018 18:18:02 +0200 Message-Id: <20180630161806.24312-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 --- 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)