Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5747776ybi; Wed, 31 Jul 2019 02:43:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXMWD6s3JB05ASuFTs6qcsFnezIMSXJBU/lkvtmVWyI1fIU4gvW0NiC06k41q8icSS009D X-Received: by 2002:a63:fc52:: with SMTP id r18mr112791030pgk.378.1564566181112; Wed, 31 Jul 2019 02:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564566181; cv=none; d=google.com; s=arc-20160816; b=fYmn2NyXOix10tb8iKo9FTVassl9SsoMdU1bSgPTqUtzaa1/UdVrxOzKVHUF9z2mn5 RJjfTlMDixsC8dDCqdUVfPidbDIV2U3IiYgwABsQrcLMzdViEvb8EOq9yOjOlKEWGrVO OIGGnoq6I3111X0kQ/Tn20DGcky7EXh/2CD6kUaREpCsAyrhoTQz88BkKp2ejzoo5Xo1 x0Bl5SqPIJPkTlPSlI8aTxsGFCUZ3vQ/QL/fxEuO6RWZEm0G7GzrzMFp2juaEznQxeTY 26SuYAAgvwtk6yYv4c3/X1ckqldJSjOVskLxE4eCNMRovXNHt9GvIDSL+sTRkUkRPxAO rAhg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P6ek7nCICloFfkqqmazjjgTrHsnrmhfYJ1DCm67jzWo=; b=0iFB4e2pj4KqTgyKhjGUcfe02nXcdlIEsVdBUElcGxkrwAo0x8+54/N/0Wq2Q//NJx F4juWAAfA0BzdSwzeQajPw67mlXRv4kP7Qwp14HepFoeDYMdLZDDtKa9sP2rE2GtWlYZ FfsEGdHr/jWbze7+oCz53rFrHgpOSUgFTIAQ6KP3Et4GL4y8iZdnIMeyb+c0Eb+Pi6lv nJJYmF16V82aKVEvzI+PY5g5YNaoh04EHEACAATwP9z7jFnI/4H8xNzG2DGZdb7xSONE /lxN0U0RzNHRjZ9d3AtRr7ZQjKXWtq1rSt0Wr2BI4T1si74HigeIYE6W+s5QFVeP07Ol YiMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fwRJHyPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r19si32881205pfh.50.2019.07.31.02.42.46; Wed, 31 Jul 2019 02:43:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@gmail.com header.s=20161025 header.b=fwRJHyPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727961AbfGaIZv (ORCPT + 99 others); Wed, 31 Jul 2019 04:25:51 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51758 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727802AbfGaIZt (ORCPT ); Wed, 31 Jul 2019 04:25:49 -0400 Received: by mail-wm1-f67.google.com with SMTP id 207so59800522wma.1; Wed, 31 Jul 2019 01:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P6ek7nCICloFfkqqmazjjgTrHsnrmhfYJ1DCm67jzWo=; b=fwRJHyPAgvG2HVANNI5oru7wb9ZEELk200qyHKkBMZMdPB/MYbp1BQmynFAKIarO3E 5QmzW8wq5sH/Sn1zGB3ZfTmsLErvg3+wRD/+lkbNms5PMHzZMl74KnUiGh+eUlzghPja Ro4oQ1Te1cZHmNa4yPvSbo8RMYekAlDRn893/DS62iZJrhqiTdZkj+S08l6sZZN+4ZPF QRuuDnFJbLMHdB4tHZIEZCyEL3cEViOJGco4Dr8IFWdeSWv5RIzG0dObOXEcHTXHw5gj Yh7e10pIrxCsBenstH6ESFddpe/iDoK8M9TvFQobmPSA8Knwl1oifLPxkIJbiGfKAnhw +P3g== 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:mime-version:content-transfer-encoding; bh=P6ek7nCICloFfkqqmazjjgTrHsnrmhfYJ1DCm67jzWo=; b=pKMBhc6ejXIAmTCa8GjrTvBf5yGJ4h/i6i+WRt9pWaMqProeW8t53IdYR7l/sA4NK2 FlRm4lMJOKQjSycnLWCYPmVgRBDgkpmkd/+pEQLtixWsrVVnAYPGn62AlYRw/1f4sQTG a39MA8fL0oS3fTX5ZITPARZTw1FrmbDLqRrLZHsFaDXu+zqPXVsd1VcXymV5rTNMwfAQ MyAX++QM8GV8G6nVxedu8lmfFcMuq8GHqNbOWtwwmS0MH6Yy8ISdnv7eC5igk7aEbmpR 8Rpnsy5ZQgauFvqQklsUHO0KBy7IbF2ZuX9XXW1MVbYo1CQkTNa6dLQkCjxGCds6mF2A 0IXA== X-Gm-Message-State: APjAAAXt2g1+ZsjL91TLN0riVmOojEANbRDKfQELZmeiGlFkgp5Dk26X rzyLQeoTmuSUZA+Rutsqy+3mqsUEDwI= X-Received: by 2002:a1c:6c08:: with SMTP id h8mr20660524wmc.62.1564561546821; Wed, 31 Jul 2019 01:25:46 -0700 (PDT) Received: from vd-lxpc-hfe.ad.vahle.at ([80.110.31.209]) by smtp.gmail.com with ESMTPSA id c78sm93223959wmd.16.2019.07.31.01.25.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 01:25:46 -0700 (PDT) From: Hubert Feurstein To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Hubert Feurstein , Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Rasmus Villemoes Subject: [PATCH net-next v2 3/6] net: dsa: mv88e6xxx: introduce invalid_port_mask in mv88e6xxx_info Date: Wed, 31 Jul 2019 10:23:48 +0200 Message-Id: <20190731082351.3157-4-h.feurstein@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190731082351.3157-1-h.feurstein@gmail.com> References: <20190731082351.3157-1-h.feurstein@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With this it is possible to mark certain chip ports as invalid. This is required for example for the MV88E6220 (which is in general a MV88E6250 with 7 ports) but the ports 2-4 are not routed to pins. If a user configures an invalid port, an error is returned. Signed-off-by: Hubert Feurstein --- drivers/net/dsa/mv88e6xxx/chip.c | 9 +++++++++ drivers/net/dsa/mv88e6xxx/chip.h | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index c8c176da0f1c..9fdcc21f0858 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2469,6 +2469,14 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) /* Setup Switch Port Registers */ for (i = 0; i < mv88e6xxx_num_ports(chip); i++) { + /* Prevent the use of an invalid port. */ + if (mv88e6xxx_is_invalid_port(chip, i) && + !dsa_is_unused_port(ds, i)) { + dev_err(chip->dev, "port %d is invalid\n", i); + err = -EINVAL; + goto unlock; + } + if (dsa_is_unused_port(ds, i)) { err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED); @@ -4270,6 +4278,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { */ .num_ports = 7, .num_internal_phys = 2, + .invalid_port_mask = BIT(2) | BIT(3) | BIT(4), .max_vid = 4095, .port_base_addr = 0x08, .phy_base_addr = 0x00, diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 2cc508a1cc32..359d258d7151 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -106,6 +106,11 @@ struct mv88e6xxx_info { unsigned int g2_irqs; bool pvt; + /* Mark certain ports as invalid. This is required for example for the + * MV88E6220 (which is in general a MV88E6250 with 7 ports) but the + * ports 2-4 are not routet to pins. + */ + unsigned int invalid_port_mask; /* Multi-chip Addressing Mode. * Some chips respond to only 2 registers of its own SMI device address * when it is non-zero, and use indirect access to internal registers. @@ -571,6 +576,11 @@ static inline unsigned int mv88e6xxx_num_gpio(struct mv88e6xxx_chip *chip) return chip->info->num_gpio; } +static inline bool mv88e6xxx_is_invalid_port(struct mv88e6xxx_chip *chip, int port) +{ + return (chip->info->invalid_port_mask & BIT(port)) != 0; +} + int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val); int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val); int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, -- 2.22.0