From patchwork Thu May 24 06:56:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 136711 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1823707lji; Wed, 23 May 2018 23:56:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrnyFrQuguzERIFze8zXrQJVcalDHE5ejOMyzGQmymQqo7sLOwe453yani+jz4cpZuzQ94L X-Received: by 2002:a65:5002:: with SMTP id f2-v6mr4705875pgo.38.1527145009031; Wed, 23 May 2018 23:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527145009; cv=none; d=google.com; s=arc-20160816; b=Huxg1O8bGBUtbfB+kRv+b3gys+VeOC9kbpndRMOYtNs6jW2gjaNMhkCJ00aSos0cuA uyTXJAaO2o/Ph+CsMvHhReg0KXXBuF/Vx/KK8Rqaw/ouOBgSy7oUjCtBRfiDtWBbpVDX DN4pipd0SLzfKROnU5ORpMPrjtOy18AB6cYX1Yterc89OrZGfC4EMemS10m97FQLmzLh QQuHsOrGZgaWqmlyR0n1P7q/8xf8k7gRc129znfbN/asT9yLKBxMOcGiFz2kfFYapTtj wvpNPv6yHJ8IMof4sawYNAYDtRayfvM73x1BOJyzjbTwDBH8A3ar/voWgdA6rVAZNp1q 57ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=6DZQ8MU0f2IdRnyACXRr/kFKgxcXpV6iT3dSNDS4xn4=; b=gPtrnJocMN/jDMGcUFge/nUly2azBWWalPZTeGD4ywNO+QextFdO7fIZnCrnqSWFsn bWymF9IogCbM4/5JW5X8YL51SDl5P5z8GezBCwjeML1gKJW4TvhFJTf8prkM8mNkli/2 vIjlqNle3+zrcOzW7EwdvZuQRdK0BdbFfsngK1IWRCYP0UpnI+SAO2UuHkGhgrwoRtdn zxjWqostsFqnhZboWhHMtxWkqvzdMekk1YCBud1tmLk2B2pI2e5Rzsxs0rl7NEYQrc+J fU53/rdPXBBDWr5J6G3/YD5gxR0Tl9+LCt5cTXKlJ3s1yB/IxSkjxYnJbvFRNWF44vvk 5f2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kDfjPZW1; 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 v2-v6si8349741plo.577.2018.05.23.23.56.48; Wed, 23 May 2018 23:56:49 -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=kDfjPZW1; 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 S964820AbeEXG4q (ORCPT + 9 others); Thu, 24 May 2018 02:56:46 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:32772 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935530AbeEXG4j (ORCPT ); Thu, 24 May 2018 02:56:39 -0400 Received: by mail-wr0-f196.google.com with SMTP id a15-v6so997966wrm.0 for ; Wed, 23 May 2018 23:56:39 -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:in-reply-to:references; bh=6DZQ8MU0f2IdRnyACXRr/kFKgxcXpV6iT3dSNDS4xn4=; b=kDfjPZW1h37BSBMLzM2Gj3ycGPjzrG4Q7RfYzsDvbhmUpzzCAE7qgPptftOO9aSD3V 04rBIEI/oYl/CTBgqq69SPKFmphS44xCZMVOE3llULXDzO2HZgHh0Z0Uii+Ms0ScOx5x gojwgg6gIePXfF4kZ6zdjHkCLkT+rS205AVN4= 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; bh=6DZQ8MU0f2IdRnyACXRr/kFKgxcXpV6iT3dSNDS4xn4=; b=KwPrpZdWoTb68iHecz31vcliSlBqLGmPNqKoVm6u3sz10Vc+Dg4c8RY0bM8dDZAJ0K uWSvaIWeK0A5VuUwU/TmmrANZyWY3pwFmww4yjGZoxGW/V+2oTPgYw8Ux1RHdf/1eLCf w8P533T/lzYkkrpbjHwGIZxBuTDJYxJqimwA3GxjHLB8jFaQwvkX+cGBwe10hAkFlPRE BZrKqiKwg6EmO5t0cITGq8Phc6MBS/lWCOp+DCGRhGsCFrRQ/lKFtu40RJ38oZzXXoSF CalmVWr4E+S7EAQaTWJt6vfqdEdfBI5gpdv1sNQBMmdRFPWd3/91VWjJgddgI0mq0bJr j+rA== X-Gm-Message-State: ALKqPwf/LVN48kkkQyHYa/kIl/ZvYCWggiPp/2D1gMqAZT91zXMyTV2c 3vgKu7pZTxCWpiw1FCsLobby55ecHCM= X-Received: by 2002:adf:a645:: with SMTP id k63-v6mr1914966wrc.231.1527144998291; Wed, 23 May 2018 23:56:38 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:460a:f200:b540:ba10:add4:9422]) by smtp.gmail.com with ESMTPSA id t198-v6sm4795257wmt.23.2018.05.23.23.56.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 May 2018 23:56:37 -0700 (PDT) From: Ilias Apalodimas To: netdev@vger.kernel.org, grygorii.strashko@ti.com, ivan.khoronzhuk@linaro.org, nsekhar@ti.com, jiri@resnulli.us, ivecera@redhat.com Cc: francois.ozog@linaro.org, yogeshs@ti.com, spatton@ti.com, Ilias Apalodimas Subject: [PATCH 2/4] cpsw_ale: add support functions for switchdev Date: Thu, 24 May 2018 09:56:22 +0300 Message-Id: <1527144984-31236-3-git-send-email-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527144984-31236-1-git-send-email-ilias.apalodimas@linaro.org> References: <1527144984-31236-1-git-send-email-ilias.apalodimas@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Ilias Apalodimas --- drivers/net/ethernet/ti/cpsw_ale.c | 129 +++++++++++++++++++++++++++++++++++++ drivers/net/ethernet/ti/cpsw_ale.h | 8 +++ 2 files changed, 137 insertions(+) -- 2.7.4 diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c index 93dc05c..0b7383f 100644 --- a/drivers/net/ethernet/ti/cpsw_ale.c +++ b/drivers/net/ethernet/ti/cpsw_ale.c @@ -409,6 +409,41 @@ int cpsw_ale_del_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask, } EXPORT_SYMBOL_GPL(cpsw_ale_del_mcast); +static int cpsw_ale_read_mc(struct cpsw_ale *ale, u8 *addr, int flags, u16 vid) +{ + u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0}; + int idx; + + idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0); + if (idx >= 0) + cpsw_ale_read(ale, idx, ale_entry); + + return cpsw_ale_get_port_mask(ale_entry, ale->port_mask_bits); +} + +int cpsw_ale_mcast_add_modify(struct cpsw_ale *ale, u8 *addr, int port_mask, + int flags, u16 vid, int mcast_state) +{ + int mcast_members, ret; + + mcast_members = cpsw_ale_read_mc(ale, addr, flags, vid) | port_mask; + ret = cpsw_ale_add_mcast(ale, addr, mcast_members, flags, vid, 0); + + return ret; +} + +int cpsw_ale_mcast_del_modify(struct cpsw_ale *ale, u8 *addr, int port_mask, + int flags, u16 vid) +{ + int mcast_members, ret; + + mcast_members = cpsw_ale_read_mc(ale, addr, flags, vid) & ~port_mask; + ret = cpsw_ale_del_mcast(ale, addr, mcast_members, flags, vid); + + return ret; +} +EXPORT_SYMBOL_GPL(cpsw_ale_mcast_del_modify); + /* ALE NetCP NU switch specific vlan functions */ static void cpsw_ale_set_vlan_mcast(struct cpsw_ale *ale, u32 *ale_entry, int reg_mcast, int unreg_mcast) @@ -424,6 +459,52 @@ static void cpsw_ale_set_vlan_mcast(struct cpsw_ale *ale, u32 *ale_entry, writel(unreg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx)); } +static int cpsw_ale_read_untagged(struct cpsw_ale *ale, u16 vid) +{ + u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0}; + int idx; + + idx = cpsw_ale_match_vlan(ale, vid); + if (idx >= 0) + cpsw_ale_read(ale, idx, ale_entry); + + return cpsw_ale_get_vlan_untag_force(ale_entry, ale->vlan_field_bits); +} + +/* returns mask of current members for specificed vlan */ +static int cpsw_ale_read_vlan_members(struct cpsw_ale *ale, u16 vid) +{ + u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0}; + int idx; + + idx = cpsw_ale_match_vlan(ale, vid); + if (idx >= 0) + cpsw_ale_read(ale, idx, ale_entry); + + return cpsw_ale_get_vlan_member_list(ale_entry, ale->vlan_field_bits); +} + +/* returns mask of registered/unregistered multicast registration */ +static int cpsw_ale_read_reg_unreg_mc(struct cpsw_ale *ale, u16 vid, bool unreg) +{ + u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0}; + int idx; + int ret; + + idx = cpsw_ale_match_vlan(ale, vid); + if (idx >= 0) + cpsw_ale_read(ale, idx, ale_entry); + + if (unreg) + ret = cpsw_ale_get_vlan_unreg_mcast(ale_entry, + ale->vlan_field_bits); + else + ret = cpsw_ale_get_vlan_reg_mcast(ale_entry, + ale->vlan_field_bits); + + return ret; +} + int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port, int untag, int reg_mcast, int unreg_mcast) { @@ -482,6 +563,54 @@ int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port_mask) } EXPORT_SYMBOL_GPL(cpsw_ale_del_vlan); +int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask, + int untag_mask, int reg_mask, int unreg_mask) +{ + int ret = 0; + int vlan_members = cpsw_ale_read_vlan_members(ale, vid) & ~port_mask; + int reg_mcast_members = + cpsw_ale_read_reg_unreg_mc(ale, vid, 0) & ~port_mask; + int unreg_mcast_members = + cpsw_ale_read_reg_unreg_mc(ale, vid, 1) & ~port_mask; + int untag_members = cpsw_ale_read_untagged(ale, vid) & ~port_mask; + + vlan_members |= port_mask; + untag_members |= untag_mask; + reg_mcast_members |= reg_mask; + unreg_mcast_members |= unreg_mask; + + ret = cpsw_ale_add_vlan(ale, vid, vlan_members, untag_members, + reg_mcast_members, unreg_mcast_members); + if (ret) { + dev_err(ale->params.dev, "Unable to add vlan\n"); + return ret; + } + dev_dbg(ale->params.dev, "port mask 0x%x untag 0x%x\n", vlan_members, + untag_mask); + + return ret; +} +EXPORT_SYMBOL_GPL(cpsw_ale_vlan_add_modify); + +int cpsw_ale_vlan_del_modify(struct cpsw_ale *ale, u16 vid, int port_mask) +{ + int ret = 0; + int vlan_members; + + vlan_members = cpsw_ale_read_vlan_members(ale, vid); + vlan_members &= ~port_mask; + + ret = cpsw_ale_del_vlan(ale, vid, vlan_members); + if (ret) { + dev_err(ale->params.dev, "Unable to del vlan\n"); + return ret; + } + dev_dbg(ale->params.dev, "port mask 0x%x\n", port_mask); + + return ret; +} +EXPORT_SYMBOL_GPL(cpsw_ale_vlan_del_modify); + void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti) { u32 ale_entry[ALE_ENTRY_WORDS]; diff --git a/drivers/net/ethernet/ti/cpsw_ale.h b/drivers/net/ethernet/ti/cpsw_ale.h index d4fe901..bc29616 100644 --- a/drivers/net/ethernet/ti/cpsw_ale.h +++ b/drivers/net/ethernet/ti/cpsw_ale.h @@ -123,4 +123,12 @@ int cpsw_ale_control_set(struct cpsw_ale *ale, int port, int control, int value); void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data); +int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask, + int untag_mask, int reg_mcast, int unreg_mcast); +int cpsw_ale_vlan_del_modify(struct cpsw_ale *ale, u16 vid, int port_mask); +int cpsw_ale_mcast_add_modify(struct cpsw_ale *ale, u8 *addr, int port_mask, + int flags, u16 vid, int mcast_state); +int cpsw_ale_mcast_del_modify(struct cpsw_ale *ale, u8 *addr, int port, + int flags, u16 vid); + #endif