From patchwork Mon May 30 10:42:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864511 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04761C433F5 for ; Mon, 30 May 2022 10:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235306AbiE3Knd (ORCPT ); Mon, 30 May 2022 06:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235290AbiE3Knb (ORCPT ); Mon, 30 May 2022 06:43:31 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DCD7092E; Mon, 30 May 2022 03:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907409; x=1685443409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2+QyWHgpSaoljkbhS4MTjXOzmzlkFw8dFsY984H5Rqw=; b=tAwY1A3ip8XtGTpM+QZis61/Zy5wPac0pzafNvA2VVmprI2ItORCw2WF HBjRN5zEGG84nK9NZKFqipo0wjsNda+hEkhU6Xh9kYOQFtKlmbKtUQJBl L66LCzKIz05WKVTAnfSltNCgEN96W2wYyemdNu3Wn5qXGor4SbuzlOXD3 j/Tze93gcgIQTPR70AH12zUsq4EwIKOrJx9AGKsT27l1vxC7AvWu3y1gV zlEMNzZgriJAnX6AOi8XGfcu7HVSXvB8P+u9p16Je8gfzrjUy4ZZaaVng Do4jkVrQMlmXEwNV2NgUebgD6Phz2He0fe6NJXHdmueJv7tL1MDDD60TG Q==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="175662972" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:43:26 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:43:25 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:43:21 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect Date: Mon, 30 May 2022 16:12:43 +0530 Message-ID: <20220530104257.21485-2-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The ksz9477_switch_detect performs the detecting the chip id from the location 0x00 and also check gigabit compatibility check & number of ports based on the register global_options0. To prepare the common ksz switch detect function, routine other than chip id read is moved to ksz9477_switch_init. Signed-off-by: Arun Ramadoss Reviewed-by: Vladimir Oltean --- drivers/net/dsa/microchip/ksz9477.c | 48 +++++++++++++---------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index ab40b700cf1a..7afc06681c02 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1362,12 +1362,30 @@ static u32 ksz9477_get_port_addr(int port, int offset) static int ksz9477_switch_detect(struct ksz_device *dev) { - u8 data8; - u8 id_hi; - u8 id_lo; u32 id32; int ret; + /* read chip id */ + ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32); + if (ret) + return ret; + + dev_dbg(dev->dev, "Switch detect: ID=%08x\n", id32); + + dev->chip_id = id32 & 0x00FFFF00; + + return 0; +} + +static int ksz9477_switch_init(struct ksz_device *dev) +{ + u8 data8; + int ret; + + dev->ds->ops = &ksz9477_switch_ops; + + dev->port_mask = (1 << dev->info->port_cnt) - 1; + /* turn off SPI DO Edge select */ ret = ksz_read8(dev, REG_SW_GLOBAL_SERIAL_CTRL_0, &data8); if (ret) @@ -1378,10 +1396,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev) if (ret) return ret; - /* read chip id */ - ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32); - if (ret) - return ret; ret = ksz_read8(dev, REG_GLOBAL_OPTIONS, &data8); if (ret) return ret; @@ -1392,10 +1406,7 @@ static int ksz9477_switch_detect(struct ksz_device *dev) /* Default capability is gigabit capable. */ dev->features = GBIT_SUPPORT; - dev_dbg(dev->dev, "Switch detect: ID=%08x%02x\n", id32, data8); - id_hi = (u8)(id32 >> 16); - id_lo = (u8)(id32 >> 8); - if ((id_lo & 0xf) == 3) { + if (dev->chip_id == KSZ9893_CHIP_ID) { /* Chip is from KSZ9893 design. */ dev_info(dev->dev, "Found KSZ9893\n"); dev->features |= IS_9893; @@ -1413,21 +1424,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev) if (!(data8 & SW_GIGABIT_ABLE)) dev->features &= ~GBIT_SUPPORT; } - - /* Change chip id to known ones so it can be matched against them. */ - id32 = (id_hi << 16) | (id_lo << 8); - - dev->chip_id = id32; - - return 0; -} - -static int ksz9477_switch_init(struct ksz_device *dev) -{ - dev->ds->ops = &ksz9477_switch_ops; - - dev->port_mask = (1 << dev->info->port_cnt) - 1; - return 0; } From patchwork Mon May 30 10:42:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864512 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4D54C433EF for ; Mon, 30 May 2022 10:43:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235309AbiE3Kng (ORCPT ); Mon, 30 May 2022 06:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235300AbiE3Kne (ORCPT ); Mon, 30 May 2022 06:43:34 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6475176280; Mon, 30 May 2022 03:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907413; x=1685443413; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4SWaC9gWE/iDiogcXxavwBo/qrYz9X2kmDYIdlo+yvk=; b=Cg636Zp0cjxETe/or5irqOjkm8A0VWbzrIeTsxzwPLYZt+fdmC7nP8rC mhZ1B3+65tA87Mj8itjcx0ouUD7mu/dB8+lhY5KYHOQHjV4eN4bWvR9oR QLA6MKODnzBOKRkre//LnW+7fgIZZpdcuiXaG3QWQlyW8xbYliR13dMZC jWSCF2PSLTtNf4XLnzbjkzT+eqyTVSO8+TX86q1fhfOcF0cwCpX5jUg9g a8z+WKZz1FOUDLUTIYAKLT2jtY8Q/w87JVAtewOI0RSP0EDB+hPTTCd3M nEE8RSe+uAA5l2XOx8Uz1S+0KZcgZjuo8W9qFCa5GWg0V5xYLUKTRo+UF Q==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="158094365" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:43:32 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:43:32 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:43:27 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common Date: Mon, 30 May 2022 16:12:44 +0530 Message-ID: <20220530104257.21485-3-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC KSZ87xx and KSZ88xx have chip_id representation at reg location 0. And KSZ9477 compatible switch and LAN937x switch have same chip_id detection at location 0x01 and 0x02. To have the common switch detect functionality for ksz switches, ksz_switch_detect function is introduced. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8795.c | 46 --------------- drivers/net/dsa/microchip/ksz8795_reg.h | 13 ----- drivers/net/dsa/microchip/ksz9477.c | 21 ------- drivers/net/dsa/microchip/ksz9477_reg.h | 1 - drivers/net/dsa/microchip/ksz_common.c | 78 +++++++++++++++++++++++-- drivers/net/dsa/microchip/ksz_common.h | 19 +++++- 6 files changed, 92 insertions(+), 86 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 12a599d5e61a..927db57d02db 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -1424,51 +1424,6 @@ static u32 ksz8_get_port_addr(int port, int offset) return PORT_CTRL_ADDR(port, offset); } -static int ksz8_switch_detect(struct ksz_device *dev) -{ - u8 id1, id2; - u16 id16; - int ret; - - /* read chip id */ - ret = ksz_read16(dev, REG_CHIP_ID0, &id16); - if (ret) - return ret; - - id1 = id16 >> 8; - id2 = id16 & SW_CHIP_ID_M; - - switch (id1) { - case KSZ87_FAMILY_ID: - if ((id2 != CHIP_ID_94 && id2 != CHIP_ID_95)) - return -ENODEV; - - if (id2 == CHIP_ID_95) { - u8 val; - - id2 = 0x95; - ksz_read8(dev, REG_PORT_STATUS_0, &val); - if (val & PORT_FIBER_MODE) - id2 = 0x65; - } else if (id2 == CHIP_ID_94) { - id2 = 0x94; - } - break; - case KSZ88_FAMILY_ID: - if (id2 != CHIP_ID_63) - return -ENODEV; - break; - default: - dev_err(dev->dev, "invalid family id: %d\n", id1); - return -ENODEV; - } - id16 &= ~0xff; - id16 |= id2; - dev->chip_id = id16; - - return 0; -} - static int ksz8_switch_init(struct ksz_device *dev) { struct ksz8 *ksz8 = dev->priv; @@ -1522,7 +1477,6 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, .shutdown = ksz8_reset_switch, - .detect = ksz8_switch_detect, .init = ksz8_switch_init, .exit = ksz8_switch_exit, }; diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h index 4109433b6b6c..50cdc2a09f5a 100644 --- a/drivers/net/dsa/microchip/ksz8795_reg.h +++ b/drivers/net/dsa/microchip/ksz8795_reg.h @@ -14,23 +14,10 @@ #define KS_PRIO_M 0x3 #define KS_PRIO_S 2 -#define REG_CHIP_ID0 0x00 - -#define KSZ87_FAMILY_ID 0x87 -#define KSZ88_FAMILY_ID 0x88 - -#define REG_CHIP_ID1 0x01 - -#define SW_CHIP_ID_M 0xF0 -#define SW_CHIP_ID_S 4 #define SW_REVISION_M 0x0E #define SW_REVISION_S 1 #define SW_START 0x01 -#define CHIP_ID_94 0x60 -#define CHIP_ID_95 0x90 -#define CHIP_ID_63 0x30 - #define KSZ8863_REG_SW_RESET 0x43 #define KSZ8863_GLOBAL_SOFTWARE_RESET BIT(4) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 7afc06681c02..7d3c8f6908b6 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1360,23 +1360,6 @@ static u32 ksz9477_get_port_addr(int port, int offset) return PORT_CTRL_ADDR(port, offset); } -static int ksz9477_switch_detect(struct ksz_device *dev) -{ - u32 id32; - int ret; - - /* read chip id */ - ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32); - if (ret) - return ret; - - dev_dbg(dev->dev, "Switch detect: ID=%08x\n", id32); - - dev->chip_id = id32 & 0x00FFFF00; - - return 0; -} - static int ksz9477_switch_init(struct ksz_device *dev) { u8 data8; @@ -1407,8 +1390,6 @@ static int ksz9477_switch_init(struct ksz_device *dev) dev->features = GBIT_SUPPORT; if (dev->chip_id == KSZ9893_CHIP_ID) { - /* Chip is from KSZ9893 design. */ - dev_info(dev->dev, "Found KSZ9893\n"); dev->features |= IS_9893; /* Chip does not support gigabit. */ @@ -1416,7 +1397,6 @@ static int ksz9477_switch_init(struct ksz_device *dev) dev->features &= ~GBIT_SUPPORT; dev->phy_port_cnt = 2; } else { - dev_info(dev->dev, "Found KSZ9477 or compatible\n"); /* Chip uses new XMII register definitions. */ dev->features |= NEW_XMII; @@ -1443,7 +1423,6 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .freeze_mib = ksz9477_freeze_mib, .port_init_cnt = ksz9477_port_init_cnt, .shutdown = ksz9477_reset_switch, - .detect = ksz9477_switch_detect, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, }; diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h b/drivers/net/dsa/microchip/ksz9477_reg.h index 7a2c8d4767af..077e35ab11b5 100644 --- a/drivers/net/dsa/microchip/ksz9477_reg.h +++ b/drivers/net/dsa/microchip/ksz9477_reg.h @@ -25,7 +25,6 @@ #define REG_CHIP_ID2__1 0x0002 -#define CHIP_ID_63 0x63 #define CHIP_ID_66 0x66 #define CHIP_ID_67 0x67 #define CHIP_ID_77 0x77 diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 9ca8c8d7740f..9057cdb5971c 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -930,6 +930,72 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port, } EXPORT_SYMBOL_GPL(ksz_port_stp_state_set); +static int ksz_switch_detect(struct ksz_device *dev) +{ + u8 id1, id2; + u16 id16; + u32 id32; + int ret; + + /* read chip id */ + ret = ksz_read16(dev, REG_CHIP_ID0, &id16); + if (ret) + return ret; + + id1 = FIELD_GET(SW_FAMILY_ID_M, id16); + id2 = FIELD_GET(SW_CHIP_ID_M, id16); + + switch (id1) { + case KSZ87_FAMILY_ID: + if (id2 == CHIP_ID_95) { + u8 val; + + dev->chip_id = KSZ8795_CHIP_ID; + + ksz_read8(dev, KSZ8_PORT_STATUS_0, &val); + if (val & KSZ8_PORT_FIBER_MODE) + dev->chip_id = KSZ8765_CHIP_ID; + } else if (id2 == CHIP_ID_94) { + dev->chip_id = KSZ8794_CHIP_ID; + } else { + return -ENODEV; + } + break; + case KSZ88_FAMILY_ID: + if (id2 == CHIP_ID_63) + dev->chip_id = KSZ8830_CHIP_ID; + else + return -ENODEV; + break; + default: + ret = ksz_read32(dev, REG_CHIP_ID0, &id32); + if (ret) + return ret; + + dev->chip_rev = FIELD_GET(SW_REV_ID_M, id32); + id32 &= ~0xFF; + + switch (id32) { + case KSZ9477_CHIP_ID: + case KSZ9897_CHIP_ID: + case KSZ9893_CHIP_ID: + case KSZ9567_CHIP_ID: + case LAN9370_CHIP_ID: + case LAN9371_CHIP_ID: + case LAN9372_CHIP_ID: + case LAN9373_CHIP_ID: + case LAN9374_CHIP_ID: + dev->chip_id = id32; + break; + default: + dev_err(dev->dev, + "unsupported switch detected %x)\n", id32); + return -ENODEV; + } + } + return 0; +} + struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) { struct dsa_switch *ds; @@ -986,10 +1052,9 @@ int ksz_switch_register(struct ksz_device *dev, mutex_init(&dev->alu_mutex); mutex_init(&dev->vlan_mutex); - dev->dev_ops = ops; - - if (dev->dev_ops->detect(dev)) - return -EINVAL; + ret = ksz_switch_detect(dev); + if (ret) + return ret; info = ksz_lookup_info(dev->chip_id); if (!info) @@ -998,10 +1063,15 @@ int ksz_switch_register(struct ksz_device *dev, /* Update the compatible info with the probed one */ dev->info = info; + dev_info(dev->dev, "found switch: %s, rev %i\n", + dev->info->dev_name, dev->chip_rev); + ret = ksz_check_device_id(dev); if (ret) return ret; + dev->dev_ops = ops; + ret = dev->dev_ops->init(dev); if (ret) return ret; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 8500eaedad67..d16c095cdefb 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -90,6 +90,7 @@ struct ksz_device { /* chip specific data */ u32 chip_id; + u8 chip_rev; int cpu_port; /* port connected to CPU */ int phy_port_cnt; phy_interface_t compat_interface; @@ -182,7 +183,6 @@ struct ksz_dev_ops { void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); int (*shutdown)(struct ksz_device *dev); - int (*detect)(struct ksz_device *dev); int (*init)(struct ksz_device *dev); void (*exit)(struct ksz_device *dev); }; @@ -353,6 +353,23 @@ static inline void ksz_regmap_unlock(void *__mtx) #define PORT_RX_ENABLE BIT(1) #define PORT_LEARN_DISABLE BIT(0) +/* Switch ID Defines */ +#define REG_CHIP_ID0 0x00 + +#define SW_FAMILY_ID_M GENMASK(15, 8) +#define KSZ87_FAMILY_ID 0x87 +#define KSZ88_FAMILY_ID 0x88 + +#define KSZ8_PORT_STATUS_0 0x08 +#define KSZ8_PORT_FIBER_MODE BIT(7) + +#define SW_CHIP_ID_M GENMASK(7, 4) +#define CHIP_ID_94 0x6 +#define CHIP_ID_95 0x9 +#define CHIP_ID_63 0x3 + +#define SW_REV_ID_M GENMASK(7, 4) + /* Regmap tables generation */ #define KSZ_SPI_OP_RD 3 #define KSZ_SPI_OP_WR 2 From patchwork Mon May 30 10:42:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864513 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C37B3C433F5 for ; Mon, 30 May 2022 10:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235364AbiE3Kn4 (ORCPT ); Mon, 30 May 2022 06:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235330AbiE3Kny (ORCPT ); Mon, 30 May 2022 06:43:54 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 970F37C174; Mon, 30 May 2022 03:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907419; x=1685443419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FpYsCWC+30aXZIz3b7yNzZn1MmMwXyIwSgDyVY2tRfY=; b=cleXRr4MMLAgB0Vtd2goNq7ksezlL78p/trlmMdz838IFXxM4vNRb/iX +1dmLuRLSMLt81x7oD3CAsLzLQTJUIrUBXmsN+Iksfw9HIXdT/sYbUWox Gq40ACPNZvLxekmUEn3npm9TcoWANozCNpHqiJ4jSQExvALxPAaUdsMoT TRMs9PWtX71KHAP91mkLR1btQsFOPt2ovIHTaCmXVdVqkiHL4uCOXEdTG uHcGAM78BzOwzBX8fA2xyyybfgEyk1vk6KzWJKJVb90EvMnIh9zOxBdLC Qa4+nYMDagPS7TXQ625ro+bUpOo0CsaGGGoP74qU22O8h1FwTHy5j8EEs g==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="175663004" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:43:39 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:43:38 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:43:34 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write to ksz_common Date: Mon, 30 May 2022 16:12:45 +0530 Message-ID: <20220530104257.21485-4-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch move the dsa hook get_tag_protocol to ksz_common file. And the tag_protocol is returned based on the dev->chip_id. ksz8795 and ksz9477 implementation on phy read/write hooks are different. This patch modifies the ksz9477 implementation same as ksz8795 by updating the ksz9477_dev_ops structure. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8795.c | 13 +-------- drivers/net/dsa/microchip/ksz9477.c | 37 ++++++++------------------ drivers/net/dsa/microchip/ksz_common.c | 24 +++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 2 ++ 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 927db57d02db..6e5f665fa1f6 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -898,17 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) } } -static enum dsa_tag_protocol ksz8_get_tag_protocol(struct dsa_switch *ds, - int port, - enum dsa_tag_protocol mp) -{ - struct ksz_device *dev = ds->priv; - - /* ksz88x3 uses the same tag schema as KSZ9893 */ - return ksz_is_ksz88x3(dev) ? - DSA_TAG_PROTO_KSZ9893 : DSA_TAG_PROTO_KSZ8795; -} - static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port) { /* Silicon Errata Sheet (DS80000830A): @@ -1394,7 +1383,7 @@ static void ksz8_get_caps(struct dsa_switch *ds, int port, } static const struct dsa_switch_ops ksz8_switch_ops = { - .get_tag_protocol = ksz8_get_tag_protocol, + .get_tag_protocol = ksz_get_tag_protocol, .get_phy_flags = ksz8_sw_get_phy_flags, .setup = ksz8_setup, .phy_read = ksz_phy_read16, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 7d3c8f6908b6..4fb96e53487e 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -276,21 +276,8 @@ static void ksz9477_port_init_cnt(struct ksz_device *dev, int port) mutex_unlock(&mib->cnt_mutex); } -static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds, - int port, - enum dsa_tag_protocol mp) +static void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) { - enum dsa_tag_protocol proto = DSA_TAG_PROTO_KSZ9477; - struct ksz_device *dev = ds->priv; - - if (dev->features & IS_9893) - proto = DSA_TAG_PROTO_KSZ9893; - return proto; -} - -static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg) -{ - struct ksz_device *dev = ds->priv; u16 val = 0xffff; /* No real PHY after this. Simulate the PHY. @@ -335,24 +322,20 @@ static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg) ksz_pread16(dev, addr, 0x100 + (reg << 1), &val); } - return val; + *data = val; } -static int ksz9477_phy_write16(struct dsa_switch *ds, int addr, int reg, - u16 val) +static void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) { - struct ksz_device *dev = ds->priv; - /* No real PHY after this. */ if (addr >= dev->phy_port_cnt) - return 0; + return; /* No gigabit support. Do not write to this register. */ if (!(dev->features & GBIT_SUPPORT) && reg == MII_CTRL1000) - return 0; - ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val); + return; - return 0; + ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val); } static void ksz9477_cfg_port_member(struct ksz_device *dev, int port, @@ -1326,10 +1309,10 @@ static int ksz9477_setup(struct dsa_switch *ds) } static const struct dsa_switch_ops ksz9477_switch_ops = { - .get_tag_protocol = ksz9477_get_tag_protocol, + .get_tag_protocol = ksz_get_tag_protocol, .setup = ksz9477_setup, - .phy_read = ksz9477_phy_read16, - .phy_write = ksz9477_phy_write16, + .phy_read = ksz_phy_read16, + .phy_write = ksz_phy_write16, .phylink_mac_link_down = ksz_mac_link_down, .phylink_get_caps = ksz9477_get_caps, .port_enable = ksz_enable_port, @@ -1417,6 +1400,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .cfg_port_member = ksz9477_cfg_port_member, .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table, .port_setup = ksz9477_port_setup, + .r_phy = ksz9477_r_phy, + .w_phy = ksz9477_w_phy, .r_mib_cnt = ksz9477_r_mib_cnt, .r_mib_pkt = ksz9477_r_mib_pkt, .r_mib_stat64 = ksz_r_mib_stats64, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 9057cdb5971c..a43b01c2e67f 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -930,6 +930,30 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port, } EXPORT_SYMBOL_GPL(ksz_port_stp_state_set); +enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, + int port, enum dsa_tag_protocol mp) +{ + struct ksz_device *dev = ds->priv; + enum dsa_tag_protocol proto; + + if (dev->chip_id == KSZ8795_CHIP_ID || + dev->chip_id == KSZ8794_CHIP_ID || + dev->chip_id == KSZ8765_CHIP_ID) + proto = DSA_TAG_PROTO_KSZ8795; + + if (dev->chip_id == KSZ8830_CHIP_ID || + dev->chip_id == KSZ9893_CHIP_ID) + proto = DSA_TAG_PROTO_KSZ9893; + + if (dev->chip_id == KSZ9477_CHIP_ID || + dev->chip_id == KSZ9897_CHIP_ID || + dev->chip_id == KSZ9567_CHIP_ID) + proto = DSA_TAG_PROTO_KSZ9477; + + return proto; +} +EXPORT_SYMBOL_GPL(ksz_get_tag_protocol); + static int ksz_switch_detect(struct ksz_device *dev) { u8 id1, id2; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index d16c095cdefb..f253f3f22386 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -231,6 +231,8 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int port, int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy); void ksz_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *buf); +enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, + int port, enum dsa_tag_protocol mp); /* Common register access functions */ From patchwork Mon May 30 10:42:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864514 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9351CC433EF for ; Mon, 30 May 2022 10:44:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235399AbiE3KoY (ORCPT ); Mon, 30 May 2022 06:44:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235344AbiE3Knz (ORCPT ); Mon, 30 May 2022 06:43:55 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7793D7CB29; Mon, 30 May 2022 03:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907427; x=1685443427; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J9QShkTnOJrDGyfjbmKjZwhOxg4CtQ5nHxBThRK/WOQ=; b=UJnvnfAl4jnJ3sJfqUj526B+4frrgxWFuyFS3TYFfEADqMfWTbQDYO/K mSAaOxZ4Ymewau+2FFYjKoLBX2PdACTiwLDlWcszPFSJKfoZTg+nRK6I/ nWxxgHpCwwiQ1toDK5nGAjebIVcfNSNIOVd+ZJYcPa6BwnuH1C87vMQ5a A1XfB/olYk8UepkZYgJTuy94doVDrXsY9HqPiwdxP4t6LDDKqColmpXSI /bDWNAlNq5oaMIrLEE2l6bpTbA5ZQBbW26wkPwM4SvWsCRWkg2aKd1p9c 3DQvP7VuT8eJPmKYSHIe2BaRweSiH05T7qSf1h/Az1kC/kBZpXbntRZGF w==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="165913115" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:43:47 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:43:45 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:43:40 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 04/15] net: dsa: microchip: move vlan functionality to ksz_common Date: Mon, 30 May 2022 16:12:46 +0530 Message-ID: <20220530104257.21485-5-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch moves the vlan dsa_switch_ops such as vlan_add, vlan_del and vlan_filtering from the individual files ksz8795.c, ksz9477.c to ksz_common.c file. Signed-off-by: Arun Ramadoss Reviewed-by: Vladimir Oltean --- drivers/net/dsa/microchip/ksz8795.c | 19 ++++++------ drivers/net/dsa/microchip/ksz9477.c | 19 ++++++------ drivers/net/dsa/microchip/ksz_common.c | 40 ++++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 14 +++++++++ 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 6e5f665fa1f6..157d69e46793 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -958,11 +958,9 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) } } -static int ksz8_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag, +static int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag, struct netlink_ext_ack *extack) { - struct ksz_device *dev = ds->priv; - if (ksz_is_ksz88x3(dev)) return -ENOTSUPP; @@ -987,12 +985,11 @@ static void ksz8_port_enable_pvid(struct ksz_device *dev, int port, bool state) } } -static int ksz8_port_vlan_add(struct dsa_switch *ds, int port, +static int ksz8_port_vlan_add(struct ksz_device *dev, int port, const struct switchdev_obj_port_vlan *vlan, struct netlink_ext_ack *extack) { bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; - struct ksz_device *dev = ds->priv; struct ksz_port *p = &dev->ports[port]; u16 data, new_pvid = 0; u8 fid, member, valid; @@ -1060,10 +1057,9 @@ static int ksz8_port_vlan_add(struct dsa_switch *ds, int port, return 0; } -static int ksz8_port_vlan_del(struct dsa_switch *ds, int port, +static int ksz8_port_vlan_del(struct ksz_device *dev, int port, const struct switchdev_obj_port_vlan *vlan) { - struct ksz_device *dev = ds->priv; u16 data, pvid; u8 fid, member, valid; @@ -1398,9 +1394,9 @@ static const struct dsa_switch_ops ksz8_switch_ops = { .port_bridge_leave = ksz_port_bridge_leave, .port_stp_state_set = ksz8_port_stp_state_set, .port_fast_age = ksz_port_fast_age, - .port_vlan_filtering = ksz8_port_vlan_filtering, - .port_vlan_add = ksz8_port_vlan_add, - .port_vlan_del = ksz8_port_vlan_del, + .port_vlan_filtering = ksz_port_vlan_filtering, + .port_vlan_add = ksz_port_vlan_add, + .port_vlan_del = ksz_port_vlan_del, .port_fdb_dump = ksz_port_fdb_dump, .port_mdb_add = ksz_port_mdb_add, .port_mdb_del = ksz_port_mdb_del, @@ -1465,6 +1461,9 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .r_mib_pkt = ksz8_r_mib_pkt, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, + .vlan_filtering = ksz8_port_vlan_filtering, + .vlan_add = ksz8_port_vlan_add, + .vlan_del = ksz8_port_vlan_del, .shutdown = ksz8_reset_switch, .init = ksz8_switch_init, .exit = ksz8_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 4fb96e53487e..e230fe1d1917 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -372,12 +372,10 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) } } -static int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port, +static int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port, bool flag, struct netlink_ext_ack *extack) { - struct ksz_device *dev = ds->priv; - if (flag) { ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL, PORT_VLAN_LOOKUP_VID_0, true); @@ -391,11 +389,10 @@ static int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port, return 0; } -static int ksz9477_port_vlan_add(struct dsa_switch *ds, int port, +static int ksz9477_port_vlan_add(struct ksz_device *dev, int port, const struct switchdev_obj_port_vlan *vlan, struct netlink_ext_ack *extack) { - struct ksz_device *dev = ds->priv; u32 vlan_table[3]; bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; int err; @@ -428,10 +425,9 @@ static int ksz9477_port_vlan_add(struct dsa_switch *ds, int port, return 0; } -static int ksz9477_port_vlan_del(struct dsa_switch *ds, int port, +static int ksz9477_port_vlan_del(struct ksz_device *dev, int port, const struct switchdev_obj_port_vlan *vlan) { - struct ksz_device *dev = ds->priv; bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; u32 vlan_table[3]; u16 pvid; @@ -1323,9 +1319,9 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { .port_bridge_leave = ksz_port_bridge_leave, .port_stp_state_set = ksz9477_port_stp_state_set, .port_fast_age = ksz_port_fast_age, - .port_vlan_filtering = ksz9477_port_vlan_filtering, - .port_vlan_add = ksz9477_port_vlan_add, - .port_vlan_del = ksz9477_port_vlan_del, + .port_vlan_filtering = ksz_port_vlan_filtering, + .port_vlan_add = ksz_port_vlan_add, + .port_vlan_del = ksz_port_vlan_del, .port_fdb_dump = ksz9477_port_fdb_dump, .port_fdb_add = ksz9477_port_fdb_add, .port_fdb_del = ksz9477_port_fdb_del, @@ -1407,6 +1403,9 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .r_mib_stat64 = ksz_r_mib_stats64, .freeze_mib = ksz9477_freeze_mib, .port_init_cnt = ksz9477_port_init_cnt, + .vlan_filtering = ksz9477_port_vlan_filtering, + .vlan_add = ksz9477_port_vlan_add, + .vlan_del = ksz9477_port_vlan_del, .shutdown = ksz9477_reset_switch, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index a43b01c2e67f..a1fef9e4e36c 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -954,6 +954,46 @@ enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, } EXPORT_SYMBOL_GPL(ksz_get_tag_protocol); +int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, + bool flag, struct netlink_ext_ack *extack) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->vlan_filtering) + ret = dev->dev_ops->vlan_filtering(dev, port, flag, extack); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_port_vlan_filtering); + +int ksz_port_vlan_add(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->vlan_add) + ret = dev->dev_ops->vlan_add(dev, port, vlan, extack); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_port_vlan_add); + +int ksz_port_vlan_del(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->vlan_del) + ret = dev->dev_ops->vlan_del(dev, port, vlan); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_port_vlan_del); + static int ksz_switch_detect(struct ksz_device *dev) { u8 id1, id2; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index f253f3f22386..03e738c0cbb8 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -180,6 +180,13 @@ struct ksz_dev_ops { void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr, u64 *dropped, u64 *cnt); void (*r_mib_stat64)(struct ksz_device *dev, int port); + int (*vlan_filtering)(struct ksz_device *dev, int port, + bool flag, struct netlink_ext_ack *extack); + int (*vlan_add)(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack); + int (*vlan_del)(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan); void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); int (*shutdown)(struct ksz_device *dev); @@ -233,6 +240,13 @@ void ksz_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *buf); enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp); +int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, + bool flag, struct netlink_ext_ack *extack); +int ksz_port_vlan_add(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack); +int ksz_port_vlan_del(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan); /* Common register access functions */ From patchwork Mon May 30 10:42:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864515 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0542CC433F5 for ; Mon, 30 May 2022 10:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235337AbiE3Kof (ORCPT ); Mon, 30 May 2022 06:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235404AbiE3KoY (ORCPT ); Mon, 30 May 2022 06:44:24 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E8567CB6A; Mon, 30 May 2022 03:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907436; x=1685443436; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kOUxOz0CuZ6ZV6n9fE6Ut+b/Kon8oZeIxhvj1TjAWCo=; b=iNCBxLFtoAC7kAjtA8PW5MxFk8Tdc7pT8EXXO1iuByTcslnZ5m2dge1n J5A7is28Ff5A8Ff5pSX46gHAGUVu2m8Q+F8CrqRxGoA4csBVDvGu7FzKd M5+QqOy5QlivmWoDYKcS8Y8S9vHeV2WAwrj3vYHzOYN62bEkJWkmYr8RU WWl0v84OIIBZNbbEKLYcuJsbrSfqaxzESH5K1ZXeVfRiLAFa2UcbIfAai cwI5Fdm4K4cz6oijRwDPtinpIX5K3zgq6/0nnbT+9ZeQVre5VxOUvRSp3 8mGsvvLGUdYzjADB0vG6f0cv6nMZqDZnEq0l8bN16Miq4BVt1fxjZ+pXM Q==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="175663041" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:43:54 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:43:53 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:43:48 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror to ksz_common Date: Mon, 30 May 2022 16:12:47 +0530 Message-ID: <20220530104257.21485-6-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch updates the common port mirror add/del dsa_switch_ops in ksz_common.c. The individual switches implementation is executed based on the ksz_dev_ops function pointers. Signed-off-by: Arun Ramadoss Reviewed-by: Vladimir Oltean --- drivers/net/dsa/microchip/ksz8795.c | 13 ++++++------- drivers/net/dsa/microchip/ksz9477.c | 12 ++++++------ drivers/net/dsa/microchip/ksz_common.c | 25 +++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 10 ++++++++++ 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 157d69e46793..8657b520b336 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -1089,12 +1089,10 @@ static int ksz8_port_vlan_del(struct ksz_device *dev, int port, return 0; } -static int ksz8_port_mirror_add(struct dsa_switch *ds, int port, +static int ksz8_port_mirror_add(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror, bool ingress, struct netlink_ext_ack *extack) { - struct ksz_device *dev = ds->priv; - if (ingress) { ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, true); dev->mirror_rx |= BIT(port); @@ -1113,10 +1111,9 @@ static int ksz8_port_mirror_add(struct dsa_switch *ds, int port, return 0; } -static void ksz8_port_mirror_del(struct dsa_switch *ds, int port, +static void ksz8_port_mirror_del(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror) { - struct ksz_device *dev = ds->priv; u8 data; if (mirror->ingress) { @@ -1400,8 +1397,8 @@ static const struct dsa_switch_ops ksz8_switch_ops = { .port_fdb_dump = ksz_port_fdb_dump, .port_mdb_add = ksz_port_mdb_add, .port_mdb_del = ksz_port_mdb_del, - .port_mirror_add = ksz8_port_mirror_add, - .port_mirror_del = ksz8_port_mirror_del, + .port_mirror_add = ksz_port_mirror_add, + .port_mirror_del = ksz_port_mirror_del, }; static u32 ksz8_get_port_addr(int port, int offset) @@ -1464,6 +1461,8 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .vlan_filtering = ksz8_port_vlan_filtering, .vlan_add = ksz8_port_vlan_add, .vlan_del = ksz8_port_vlan_del, + .mirror_add = ksz8_port_mirror_add, + .mirror_del = ksz8_port_mirror_del, .shutdown = ksz8_reset_switch, .init = ksz8_switch_init, .exit = ksz8_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index e230fe1d1917..6796c9d89ab9 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -811,11 +811,10 @@ static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port, return ret; } -static int ksz9477_port_mirror_add(struct dsa_switch *ds, int port, +static int ksz9477_port_mirror_add(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror, bool ingress, struct netlink_ext_ack *extack) { - struct ksz_device *dev = ds->priv; u8 data; int p; @@ -851,10 +850,9 @@ static int ksz9477_port_mirror_add(struct dsa_switch *ds, int port, return 0; } -static void ksz9477_port_mirror_del(struct dsa_switch *ds, int port, +static void ksz9477_port_mirror_del(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror) { - struct ksz_device *dev = ds->priv; bool in_use = false; u8 data; int p; @@ -1327,8 +1325,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { .port_fdb_del = ksz9477_port_fdb_del, .port_mdb_add = ksz9477_port_mdb_add, .port_mdb_del = ksz9477_port_mdb_del, - .port_mirror_add = ksz9477_port_mirror_add, - .port_mirror_del = ksz9477_port_mirror_del, + .port_mirror_add = ksz_port_mirror_add, + .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, .port_change_mtu = ksz9477_change_mtu, .port_max_mtu = ksz9477_max_mtu, @@ -1406,6 +1404,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .vlan_filtering = ksz9477_port_vlan_filtering, .vlan_add = ksz9477_port_vlan_add, .vlan_del = ksz9477_port_vlan_del, + .mirror_add = ksz9477_port_mirror_add, + .mirror_del = ksz9477_port_mirror_del, .shutdown = ksz9477_reset_switch, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index a1fef9e4e36c..1ed4cc94795e 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -994,6 +994,31 @@ int ksz_port_vlan_del(struct dsa_switch *ds, int port, } EXPORT_SYMBOL_GPL(ksz_port_vlan_del); +int ksz_port_mirror_add(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->mirror_add) + ret = dev->dev_ops->mirror_add(dev, port, mirror, ingress, + extack); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_port_mirror_add); + +void ksz_port_mirror_del(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror) +{ + struct ksz_device *dev = ds->priv; + + if (dev->dev_ops->mirror_del) + dev->dev_ops->mirror_del(dev, port, mirror); +} +EXPORT_SYMBOL_GPL(ksz_port_mirror_del); + static int ksz_switch_detect(struct ksz_device *dev) { u8 id1, id2; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 03e738c0cbb8..01080ec22bf1 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -187,6 +187,11 @@ struct ksz_dev_ops { struct netlink_ext_ack *extack); int (*vlan_del)(struct ksz_device *dev, int port, const struct switchdev_obj_port_vlan *vlan); + int (*mirror_add)(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack); + void (*mirror_del)(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror); void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); int (*shutdown)(struct ksz_device *dev); @@ -247,6 +252,11 @@ int ksz_port_vlan_add(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack); int ksz_port_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan); +int ksz_port_mirror_add(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack); +void ksz_port_mirror_del(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror); /* Common register access functions */ From patchwork Mon May 30 10:42:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864516 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4062DC433EF for ; Mon, 30 May 2022 10:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235386AbiE3Kox (ORCPT ); Mon, 30 May 2022 06:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235417AbiE3KoY (ORCPT ); Mon, 30 May 2022 06:44:24 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B42E7CDC4; Mon, 30 May 2022 03:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907444; x=1685443444; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AXEma/wXIo46/RpjwWuiE+84rIu0sswJH6jcqexjMHM=; b=WjOGHjz5mNO4rECDO4NOjmAFZ4gytLavh8NEyO+bvvMF2jNp1rbMmwf7 3lUvep6lhv0LplrhRmUZl/xv1j0LFYtxFTPNjiEIHVF9vzs2cY9BdlLJs d/ymThY4VgkkQlMUTa8rIeB1va68nkmGmVWLFC/LtTiWar+T+rzpuY83j XxUBvuYCicgS7PK3n0vllVQNFYsH1yyuI2bwU61/QwBYhzVzPU9g6iqmn rGNdMShp/kqA+EI3iTIiKHFVYaaj9vbvYJ1hep9yokf1wPrMs1cZeNqwG WLfdQjqzhxejDX7d/2nfL11FzWYB4ty1iocJ7mWp6R7XRb9QDIugafJ+R Q==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="161124720" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:01 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:01 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:43:56 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops Date: Mon, 30 May 2022 16:12:48 +0530 Message-ID: <20220530104257.21485-7-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC At present, P_STP_CTRL register value is passed as parameter to ksz_port_stp_state from the individual dsa_switch_ops hooks. This patch update the function to retrieve the register value through the ksz_dev_ops function pointer. And add the static to ksz_update_port_member since it is not called outside the ksz_common. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8795.c | 9 +++++---- drivers/net/dsa/microchip/ksz9477.c | 10 +++++----- drivers/net/dsa/microchip/ksz_common.c | 9 +++++---- drivers/net/dsa/microchip/ksz_common.h | 5 ++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 8657b520b336..e6982fa9d382 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -920,9 +920,9 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) ksz_pwrite8(dev, port, P_MIRROR_CTRL, data); } -static void ksz8_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) +static int ksz8_get_stp_reg(void) { - ksz_port_stp_state_set(ds, port, state, P_STP_CTRL); + return P_STP_CTRL; } static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) @@ -1240,7 +1240,7 @@ static void ksz8_config_cpu_port(struct dsa_switch *ds) for (i = 0; i < dev->phy_port_cnt; i++) { p = &dev->ports[i]; - ksz8_port_stp_state_set(ds, i, BR_STATE_DISABLED); + ksz_port_stp_state_set(ds, i, BR_STATE_DISABLED); /* Last port may be disabled. */ if (i == dev->phy_port_cnt) @@ -1389,7 +1389,7 @@ static const struct dsa_switch_ops ksz8_switch_ops = { .get_sset_count = ksz_sset_count, .port_bridge_join = ksz_port_bridge_join, .port_bridge_leave = ksz_port_bridge_leave, - .port_stp_state_set = ksz8_port_stp_state_set, + .port_stp_state_set = ksz_port_stp_state_set, .port_fast_age = ksz_port_fast_age, .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, @@ -1463,6 +1463,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .vlan_del = ksz8_port_vlan_del, .mirror_add = ksz8_port_mirror_add, .mirror_del = ksz8_port_mirror_del, + .get_stp_reg = ksz8_get_stp_reg, .shutdown = ksz8_reset_switch, .init = ksz8_switch_init, .exit = ksz8_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 6796c9d89ab9..f08694aba6bb 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -344,10 +344,9 @@ static void ksz9477_cfg_port_member(struct ksz_device *dev, int port, ksz_pwrite32(dev, port, REG_PORT_VLAN_MEMBERSHIP__4, member); } -static void ksz9477_port_stp_state_set(struct dsa_switch *ds, int port, - u8 state) +static int ksz9477_get_stp_reg(void) { - ksz_port_stp_state_set(ds, port, state, P_STP_CTRL); + return P_STP_CTRL; } static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) @@ -1237,7 +1236,7 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds) continue; p = &dev->ports[i]; - ksz9477_port_stp_state_set(ds, i, BR_STATE_DISABLED); + ksz_port_stp_state_set(ds, i, BR_STATE_DISABLED); p->on = 1; if (i < dev->phy_port_cnt) p->phy = 1; @@ -1315,7 +1314,7 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { .get_sset_count = ksz_sset_count, .port_bridge_join = ksz_port_bridge_join, .port_bridge_leave = ksz_port_bridge_leave, - .port_stp_state_set = ksz9477_port_stp_state_set, + .port_stp_state_set = ksz_port_stp_state_set, .port_fast_age = ksz_port_fast_age, .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, @@ -1406,6 +1405,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .vlan_del = ksz9477_port_vlan_del, .mirror_add = ksz9477_port_mirror_add, .mirror_del = ksz9477_port_mirror_del, + .get_stp_reg = ksz9477_get_stp_reg, .shutdown = ksz9477_reset_switch, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 1ed4cc94795e..5cf183f753d9 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -532,7 +532,7 @@ void ksz_get_strings(struct dsa_switch *ds, int port, } EXPORT_SYMBOL_GPL(ksz_get_strings); -void ksz_update_port_member(struct ksz_device *dev, int port) +static void ksz_update_port_member(struct ksz_device *dev, int port) { struct ksz_port *p = &dev->ports[port]; struct dsa_switch *ds = dev->ds; @@ -589,7 +589,6 @@ void ksz_update_port_member(struct ksz_device *dev, int port) dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port); } -EXPORT_SYMBOL_GPL(ksz_update_port_member); static void port_r_cnt(struct ksz_device *dev, int port) { @@ -890,12 +889,14 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) } EXPORT_SYMBOL_GPL(ksz_enable_port); -void ksz_port_stp_state_set(struct dsa_switch *ds, int port, - u8 state, int reg) +void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) { struct ksz_device *dev = ds->priv; struct ksz_port *p; u8 data; + int reg; + + reg = dev->dev_ops->get_stp_reg(); ksz_pread8(dev, port, reg, &data); data &= ~(PORT_TX_ENABLE | PORT_RX_ENABLE | PORT_LEARN_DISABLE); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 01080ec22bf1..2727934b7171 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -192,6 +192,7 @@ struct ksz_dev_ops { bool ingress, struct netlink_ext_ack *extack); void (*mirror_del)(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror); + int (*get_stp_reg)(void); void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); int (*shutdown)(struct ksz_device *dev); @@ -207,7 +208,6 @@ void ksz_switch_remove(struct ksz_device *dev); int ksz8_switch_register(struct ksz_device *dev); int ksz9477_switch_register(struct ksz_device *dev); -void ksz_update_port_member(struct ksz_device *dev, int port); void ksz_init_mib_timer(struct ksz_device *dev); void ksz_r_mib_stats64(struct ksz_device *dev, int port); void ksz_get_stats64(struct dsa_switch *ds, int port, @@ -229,8 +229,7 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack); void ksz_port_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge); -void ksz_port_stp_state_set(struct dsa_switch *ds, int port, - u8 state, int reg); +void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state); void ksz_port_fast_age(struct dsa_switch *ds, int port); int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data); From patchwork Mon May 30 10:42:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864517 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64A0CC433EF for ; Mon, 30 May 2022 10:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234799AbiE3Kp2 (ORCPT ); Mon, 30 May 2022 06:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235448AbiE3KoZ (ORCPT ); Mon, 30 May 2022 06:44:25 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02BE97DE03; Mon, 30 May 2022 03:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907452; x=1685443452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E5BLy6gRUx5QYynXA0m1su3odBaUXpMPYruvosrgoeU=; b=2FQTRPt28pgcIjgt2/UENK8hnjHlGSAsuCiV8xAfHYIbUD0DyuYdD77+ Ko2AtXmu9SSu5kOC4tBtWWQD+FvVp8mSV0O/Gtwn3hdKS/zjp/WrEKvmC B8DTQErWRlvokzH/e3dpL8zDaWn0IJhp7xBoCYLvT1jySKTSJHxqWmrbn A/Z9iE9TsiBsk7NvUe6C2k7lX/vx0ntOUZu4HjDQjyC+erUTrWDheG2R6 w61aUdXzLJoMlPpUPSpz1KPF4c5vO5vyUTUE4SWjgOQNC9LnBgR+N0+P9 o2BaFlm6OrLhzXGagJUM+2nAYfVkz2YMh5BA7RlHNoIvb+OOPOLo1y/w6 A==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="165913165" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:10 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:08 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:03 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 07/15] net: dsa: microchip: update the ksz_phylink_get_caps Date: Mon, 30 May 2022 16:12:49 +0530 Message-ID: <20220530104257.21485-8-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch assigns the phylink_get_caps in ksz8795 and ksz9477 to ksz_phylink_get_caps. And update their mac_capabilities in the respective ksz_dev_ops. Signed-off-by: Arun Ramadoss Reviewed-by: Vladimir Oltean --- drivers/net/dsa/microchip/ksz8795.c | 9 +++------ drivers/net/dsa/microchip/ksz9477.c | 7 +++---- drivers/net/dsa/microchip/ksz_common.c | 3 +++ drivers/net/dsa/microchip/ksz_common.h | 2 ++ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index e6982fa9d382..25763d89c67a 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -1353,13 +1353,9 @@ static int ksz8_setup(struct dsa_switch *ds) return ksz8_handle_global_errata(ds); } -static void ksz8_get_caps(struct dsa_switch *ds, int port, +static void ksz8_get_caps(struct ksz_device *dev, int port, struct phylink_config *config) { - struct ksz_device *dev = ds->priv; - - ksz_phylink_get_caps(ds, port, config); - config->mac_capabilities = MAC_10 | MAC_100; /* Silicon Errata Sheet (DS80000830A): @@ -1381,7 +1377,7 @@ static const struct dsa_switch_ops ksz8_switch_ops = { .setup = ksz8_setup, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, - .phylink_get_caps = ksz8_get_caps, + .phylink_get_caps = ksz_phylink_get_caps, .phylink_mac_link_down = ksz_mac_link_down, .port_enable = ksz_enable_port, .get_strings = ksz_get_strings, @@ -1464,6 +1460,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .mirror_add = ksz8_port_mirror_add, .mirror_del = ksz8_port_mirror_del, .get_stp_reg = ksz8_get_stp_reg, + .get_caps = ksz8_get_caps, .shutdown = ksz8_reset_switch, .init = ksz8_switch_init, .exit = ksz8_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index f08694aba6bb..494f93e4c7f8 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1073,11 +1073,9 @@ static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port) ksz9477_port_mmd_write(dev, port, 0x1c, 0x20, 0xeeee); } -static void ksz9477_get_caps(struct dsa_switch *ds, int port, +static void ksz9477_get_caps(struct ksz_device *dev, int port, struct phylink_config *config) { - ksz_phylink_get_caps(ds, port, config); - config->mac_capabilities = MAC_10 | MAC_100 | MAC_1000FD | MAC_ASYM_PAUSE | MAC_SYM_PAUSE; } @@ -1307,7 +1305,7 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_mac_link_down = ksz_mac_link_down, - .phylink_get_caps = ksz9477_get_caps, + .phylink_get_caps = ksz_phylink_get_caps, .port_enable = ksz_enable_port, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, @@ -1406,6 +1404,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .mirror_add = ksz9477_port_mirror_add, .mirror_del = ksz9477_port_mirror_del, .get_stp_reg = ksz9477_get_stp_reg, + .get_caps = ksz9477_get_caps, .shutdown = ksz9477_reset_switch, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 5cf183f753d9..c1303a46a9b7 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -456,6 +456,9 @@ void ksz_phylink_get_caps(struct dsa_switch *ds, int port, if (dev->info->internal_phy[port]) __set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces); + + if (dev->dev_ops->get_caps) + dev->dev_ops->get_caps(dev, port, config); } EXPORT_SYMBOL_GPL(ksz_phylink_get_caps); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 2727934b7171..8124737a1170 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -193,6 +193,8 @@ struct ksz_dev_ops { void (*mirror_del)(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror); int (*get_stp_reg)(void); + void (*get_caps)(struct ksz_device *dev, int port, + struct phylink_config *config); void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); int (*shutdown)(struct ksz_device *dev); From patchwork Mon May 30 10:42:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864525 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E594C433EF for ; Mon, 30 May 2022 10:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235534AbiE3KrC (ORCPT ); Mon, 30 May 2022 06:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235470AbiE3Ko1 (ORCPT ); Mon, 30 May 2022 06:44:27 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04DC67DE2F; Mon, 30 May 2022 03:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907457; x=1685443457; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nfFN56cdL96YlVC1q3zRELQT8mXoBH4DJqgVjuk2bKc=; b=y14Fso+fBkLRuA+pMTK2aEAltWZVS4GLFPt8hCZu732agMEoCTW/ufkZ ZWDXze+nI0sGWDlGNBQYP2VLU59lXys6vj6c22tPO9jiLGxbkrQ5jSK3d Ey15uJMjNWpWHpAfEmce/YlGtZWzSFwt2+e/h7WmD53RJl0AYj3kivgci lV9T198dYxJwozPWXU77db+yQoRnaHp/Ogz7NVQXdTVb1DRMrkKLCn9Hs JyKutQokhqJeTsEUoHCxHSgpMoSW6xrMSj3Y7hAGgqEunx8EN8nTqaLQB to+zL2xsp+zs3PVTtCmeHkEFb4gX51k+4aV448kI57MpV8h5IEKkmUoIr A==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="165913210" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:16 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:14 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:10 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 08/15] net: dsa: microchip: update the ksz_port_mdb_add/del Date: Mon, 30 May 2022 16:12:50 +0530 Message-ID: <20220530104257.21485-9-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC ksz_mdb_add/del in ksz_common.c is specific for the ksz8795.c file. The ksz9477 has its separate ksz9477_port_mdb_add/del functions. This patch moves the ksz8795 specific mdb functionality from ksz_common to ksz8795. And this dsa_switch_ops hooks for ksz8795/ksz9477 are invoked through the ksz_port_mdb_add/del. Signed-off-by: Arun Ramadoss Reviewed-by: Vladimir Oltean --- drivers/net/dsa/microchip/ksz8795.c | 76 ++++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz9477.c | 20 +++---- drivers/net/dsa/microchip/ksz_common.c | 66 +++------------------- drivers/net/dsa/microchip/ksz_common.h | 6 ++ 4 files changed, 100 insertions(+), 68 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 25763d89c67a..abd28dc44eb5 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -958,6 +958,80 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) } } +static int ksz8_mdb_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db) +{ + struct alu_struct alu; + int index; + int empty = 0; + + alu.port_forward = 0; + for (index = 0; index < dev->info->num_statics; index++) { + if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) { + /* Found one already in static MAC table. */ + if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) && + alu.fid == mdb->vid) + break; + /* Remember the first empty entry. */ + } else if (!empty) { + empty = index + 1; + } + } + + /* no available entry */ + if (index == dev->info->num_statics && !empty) + return -ENOSPC; + + /* add entry */ + if (index == dev->info->num_statics) { + index = empty - 1; + memset(&alu, 0, sizeof(alu)); + memcpy(alu.mac, mdb->addr, ETH_ALEN); + alu.is_static = true; + } + alu.port_forward |= BIT(port); + if (mdb->vid) { + alu.is_use_fid = true; + + /* Need a way to map VID to FID. */ + alu.fid = mdb->vid; + } + dev->dev_ops->w_sta_mac_table(dev, index, &alu); + + return 0; +} + +static int ksz8_mdb_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db) +{ + struct alu_struct alu; + int index; + + for (index = 0; index < dev->info->num_statics; index++) { + if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) { + /* Found one already in static MAC table. */ + if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) && + alu.fid == mdb->vid) + break; + } + } + + /* no available entry */ + if (index == dev->info->num_statics) + goto exit; + + /* clear port */ + alu.port_forward &= ~BIT(port); + if (!alu.port_forward) + alu.is_static = false; + dev->dev_ops->w_sta_mac_table(dev, index, &alu); + +exit: + return 0; +} + static int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag, struct netlink_ext_ack *extack) { @@ -1454,6 +1528,8 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .r_mib_pkt = ksz8_r_mib_pkt, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, + .mdb_add = ksz8_mdb_add, + .mdb_del = ksz8_mdb_del, .vlan_filtering = ksz8_port_vlan_filtering, .vlan_add = ksz8_port_vlan_add, .vlan_del = ksz8_port_vlan_del, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 494f93e4c7f8..045856656466 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -658,11 +658,10 @@ static int ksz9477_port_fdb_dump(struct dsa_switch *ds, int port, return ret; } -static int ksz9477_port_mdb_add(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +static int ksz9477_mdb_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db) { - struct ksz_device *dev = ds->priv; u32 static_table[4]; u32 data; int index; @@ -734,11 +733,10 @@ static int ksz9477_port_mdb_add(struct dsa_switch *ds, int port, return err; } -static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +static int ksz9477_mdb_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db) { - struct ksz_device *dev = ds->priv; u32 static_table[4]; u32 data; int index; @@ -1320,8 +1318,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { .port_fdb_dump = ksz9477_port_fdb_dump, .port_fdb_add = ksz9477_port_fdb_add, .port_fdb_del = ksz9477_port_fdb_del, - .port_mdb_add = ksz9477_port_mdb_add, - .port_mdb_del = ksz9477_port_mdb_del, + .port_mdb_add = ksz_port_mdb_add, + .port_mdb_del = ksz_port_mdb_del, .port_mirror_add = ksz_port_mirror_add, .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, @@ -1405,6 +1403,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .mirror_del = ksz9477_port_mirror_del, .get_stp_reg = ksz9477_get_stp_reg, .get_caps = ksz9477_get_caps, + .mdb_add = ksz9477_mdb_add, + .mdb_del = ksz9477_mdb_del, .shutdown = ksz9477_reset_switch, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index c1303a46a9b7..b9082952db0f 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -801,44 +801,12 @@ int ksz_port_mdb_add(struct dsa_switch *ds, int port, struct dsa_db db) { struct ksz_device *dev = ds->priv; - struct alu_struct alu; - int index; - int empty = 0; - - alu.port_forward = 0; - for (index = 0; index < dev->info->num_statics; index++) { - if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) { - /* Found one already in static MAC table. */ - if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) && - alu.fid == mdb->vid) - break; - /* Remember the first empty entry. */ - } else if (!empty) { - empty = index + 1; - } - } - - /* no available entry */ - if (index == dev->info->num_statics && !empty) - return -ENOSPC; - - /* add entry */ - if (index == dev->info->num_statics) { - index = empty - 1; - memset(&alu, 0, sizeof(alu)); - memcpy(alu.mac, mdb->addr, ETH_ALEN); - alu.is_static = true; - } - alu.port_forward |= BIT(port); - if (mdb->vid) { - alu.is_use_fid = true; + int ret = -EOPNOTSUPP; - /* Need a way to map VID to FID. */ - alu.fid = mdb->vid; - } - dev->dev_ops->w_sta_mac_table(dev, index, &alu); + if (dev->dev_ops->mdb_add) + ret = dev->dev_ops->mdb_add(dev, port, mdb, db); - return 0; + return ret; } EXPORT_SYMBOL_GPL(ksz_port_mdb_add); @@ -847,30 +815,12 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int port, struct dsa_db db) { struct ksz_device *dev = ds->priv; - struct alu_struct alu; - int index; - - for (index = 0; index < dev->info->num_statics; index++) { - if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) { - /* Found one already in static MAC table. */ - if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) && - alu.fid == mdb->vid) - break; - } - } - - /* no available entry */ - if (index == dev->info->num_statics) - goto exit; + int ret = -EOPNOTSUPP; - /* clear port */ - alu.port_forward &= ~BIT(port); - if (!alu.port_forward) - alu.is_static = false; - dev->dev_ops->w_sta_mac_table(dev, index, &alu); + if (dev->dev_ops->mdb_del) + ret = dev->dev_ops->mdb_del(dev, port, mdb, db); -exit: - return 0; + return ret; } EXPORT_SYMBOL_GPL(ksz_port_mdb_del); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 8124737a1170..816581dd7f8e 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -192,6 +192,12 @@ struct ksz_dev_ops { bool ingress, struct netlink_ext_ack *extack); void (*mirror_del)(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror); + int (*mdb_add)(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db); + int (*mdb_del)(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db); int (*get_stp_reg)(void); void (*get_caps)(struct ksz_device *dev, int port, struct phylink_config *config); From patchwork Mon May 30 10:42:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864523 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D932AC433F5 for ; Mon, 30 May 2022 10:47:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235371AbiE3Kq6 (ORCPT ); Mon, 30 May 2022 06:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235340AbiE3Koc (ORCPT ); Mon, 30 May 2022 06:44:32 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CA9E7E1CE; Mon, 30 May 2022 03:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907463; x=1685443463; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L/qfF6l2+Qd+DdGpCGovzCwJFmvLnsE3RDiGUt0tx/4=; b=kRWGitNXWrKxJq4tmFO8SXK3/Lrn+/jnNt2EqhRHShbvfsbgCv8/04sF o0XhR2QUMSUZxX4liP/5qr1uj3j6fG//8s4BASbPJhhicvJrr7pCo2sD7 +lsy0LFk+ZTBn5mjYPpa1MzVACYf50Tis86JUDx4tEDBx+CMqKFlYYGkm QuR+t8BOsD2GLRL5/RU1c+MKXvpY0Q/USmoKb6z4EVH7KR207ayzHw4N3 hx1Q4i0lQ3Qovt4yp43wkpkqBXSkAv0E5UiOjRizmLg7HwDXsDxECQV6b 63Z92fBCYPx1TLfcz+yzGlhx+nuFWhZe0LXD/AercjLBf5WS4n3BGPF9G A==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="165913242" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:23 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:21 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:16 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common Date: Mon, 30 May 2022 16:12:51 +0530 Message-ID: <20220530104257.21485-10-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch makes the dsa_switch_hook for fdbs to use ksz_common.c file. And from ksz_common, individual switches fdb functions are called using the dev->dev_ops. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8795.c | 30 +++++++++++++++ drivers/net/dsa/microchip/ksz9477.c | 28 +++++++------- drivers/net/dsa/microchip/ksz_common.c | 52 +++++++++++++++----------- drivers/net/dsa/microchip/ksz_common.h | 10 +++++ 4 files changed, 84 insertions(+), 36 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index abd28dc44eb5..528de481b319 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -958,6 +958,35 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) } } +static int ksz8_fdb_dump(struct ksz_device *dev, int port, + dsa_fdb_dump_cb_t *cb, void *data) +{ + int ret = 0; + u16 i = 0; + u16 entries = 0; + u8 timestamp = 0; + u8 fid; + u8 member; + struct alu_struct alu; + + do { + alu.is_static = false; + ret = dev->dev_ops->r_dyn_mac_table(dev, i, alu.mac, &fid, + &member, ×tamp, + &entries); + if (!ret && (member & BIT(port))) { + ret = cb(alu.mac, alu.fid, alu.is_static, data); + if (ret) + break; + } + i++; + } while (i < entries); + if (i >= entries) + ret = 0; + + return ret; +} + static int ksz8_mdb_add(struct ksz_device *dev, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) @@ -1528,6 +1557,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .r_mib_pkt = ksz8_r_mib_pkt, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, + .fdb_dump = ksz8_fdb_dump, .mdb_add = ksz8_mdb_add, .mdb_del = ksz8_mdb_del, .vlan_filtering = ksz8_port_vlan_filtering, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 045856656466..d70e0c32b309 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -457,11 +457,10 @@ static int ksz9477_port_vlan_del(struct ksz_device *dev, int port, return 0; } -static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port, - const unsigned char *addr, u16 vid, - struct dsa_db db) +static int ksz9477_fdb_add(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, + struct dsa_db db) { - struct ksz_device *dev = ds->priv; u32 alu_table[4]; u32 data; int ret = 0; @@ -515,11 +514,10 @@ static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port, return ret; } -static int ksz9477_port_fdb_del(struct dsa_switch *ds, int port, - const unsigned char *addr, u16 vid, - struct dsa_db db) +static int ksz9477_fdb_del(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, + struct dsa_db db) { - struct ksz_device *dev = ds->priv; u32 alu_table[4]; u32 data; int ret = 0; @@ -606,10 +604,9 @@ static void ksz9477_convert_alu(struct alu_struct *alu, u32 *alu_table) alu->mac[5] = alu_table[3] & 0xFF; } -static int ksz9477_port_fdb_dump(struct dsa_switch *ds, int port, - dsa_fdb_dump_cb_t *cb, void *data) +static int ksz9477_fdb_dump(struct ksz_device *dev, int port, + dsa_fdb_dump_cb_t *cb, void *data) { - struct ksz_device *dev = ds->priv; int ret = 0; u32 ksz_data; u32 alu_table[4]; @@ -1315,9 +1312,9 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, .port_vlan_del = ksz_port_vlan_del, - .port_fdb_dump = ksz9477_port_fdb_dump, - .port_fdb_add = ksz9477_port_fdb_add, - .port_fdb_del = ksz9477_port_fdb_del, + .port_fdb_dump = ksz_port_fdb_dump, + .port_fdb_add = ksz_port_fdb_add, + .port_fdb_del = ksz_port_fdb_del, .port_mdb_add = ksz_port_mdb_add, .port_mdb_del = ksz_port_mdb_del, .port_mirror_add = ksz_port_mirror_add, @@ -1403,6 +1400,9 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .mirror_del = ksz9477_port_mirror_del, .get_stp_reg = ksz9477_get_stp_reg, .get_caps = ksz9477_get_caps, + .fdb_dump = ksz9477_fdb_dump, + .fdb_add = ksz9477_fdb_add, + .fdb_del = ksz9477_fdb_del, .mdb_add = ksz9477_mdb_add, .mdb_del = ksz9477_mdb_del, .shutdown = ksz9477_reset_switch, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index b9082952db0f..8f79ff1ac648 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -765,32 +765,40 @@ void ksz_port_fast_age(struct dsa_switch *ds, int port) } EXPORT_SYMBOL_GPL(ksz_port_fast_age); +int ksz_port_fdb_add(struct dsa_switch *ds, int port, + const unsigned char *addr, u16 vid, struct dsa_db db) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->fdb_add) + ret = dev->dev_ops->fdb_add(dev, port, addr, vid, db); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_port_fdb_add); + +int ksz_port_fdb_del(struct dsa_switch *ds, int port, + const unsigned char *addr, u16 vid, struct dsa_db db) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->fdb_del) + ret = dev->dev_ops->fdb_del(dev, port, addr, vid, db); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_port_fdb_del); + int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data) { struct ksz_device *dev = ds->priv; - int ret = 0; - u16 i = 0; - u16 entries = 0; - u8 timestamp = 0; - u8 fid; - u8 member; - struct alu_struct alu; - - do { - alu.is_static = false; - ret = dev->dev_ops->r_dyn_mac_table(dev, i, alu.mac, &fid, - &member, ×tamp, - &entries); - if (!ret && (member & BIT(port))) { - ret = cb(alu.mac, alu.fid, alu.is_static, data); - if (ret) - break; - } - i++; - } while (i < entries); - if (i >= entries) - ret = 0; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->fdb_dump) + ret = dev->dev_ops->fdb_dump(dev, port, cb, data); return ret; } diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 816581dd7f8e..133b1a257868 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -192,6 +192,12 @@ struct ksz_dev_ops { bool ingress, struct netlink_ext_ack *extack); void (*mirror_del)(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror); + int (*fdb_add)(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, struct dsa_db db); + int (*fdb_del)(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, struct dsa_db db); + int (*fdb_dump)(struct ksz_device *dev, int port, + dsa_fdb_dump_cb_t *cb, void *data); int (*mdb_add)(struct ksz_device *dev, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); @@ -239,6 +245,10 @@ void ksz_port_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge); void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state); void ksz_port_fast_age(struct dsa_switch *ds, int port); +int ksz_port_fdb_add(struct dsa_switch *ds, int port, + const unsigned char *addr, u16 vid, struct dsa_db db); +int ksz_port_fdb_del(struct dsa_switch *ds, int port, + const unsigned char *addr, u16 vid, struct dsa_db db); int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data); int ksz_port_mdb_add(struct dsa_switch *ds, int port, From patchwork Mon May 30 10:42:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864524 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 124FFC433F5 for ; Mon, 30 May 2022 10:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235512AbiE3KrA (ORCPT ); Mon, 30 May 2022 06:47:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235366AbiE3Kop (ORCPT ); Mon, 30 May 2022 06:44:45 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF682737AD; Mon, 30 May 2022 03:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907468; x=1685443468; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uic6oDeWS+H0LA/TvhlzAfI4UGeugTgDQ5T8H6H+DWg=; b=QBIwPQrG3ZPBzJ/9xYOG0ADM7oIsy9CEUJUMSTl8b25Q5ibx5DL+ccwQ ee7VmiQ0UBKHoHLBZDy2TsUTNbQIo8U1Qrc7edpGBkvWbMchlQ3oQQ57d CnvXMxnjqLmInlQsgN4BtylVnQVbHxlOCsCzm/SS3J0jGs9zVwf6LOb2P Wp0o5QRNTjPXRN8jg5N+phPMvKWjJmAM2+lrCVWugfl6pktPLeBIW5Aik Y/AZvNhlanIf70dfVzW1mxHp1cre3IuhuiW0/oC/lGXU6IuNUd+mooOTI l7szKuuQ9ETFlszV6xDS6Zzhsi4nI/i5rHEFKz52jZzLY9Y4e6WmyQj0r A==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="166258859" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:27 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:27 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:22 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common Date: Mon, 30 May 2022 16:12:52 +0530 Message-ID: <20220530104257.21485-11-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch assigns the .setup, get_phy_flags & mtu hook of ksz8795 and ksz9477 in dsa_switch_ops to ksz_common. And the individual switches setup implementations are called based on the ksz_dev_ops. For get_phy_flags hooks,checks whether the chip is ksz8863/kss8793 then it returns error for port1. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8795.c | 17 ++------- drivers/net/dsa/microchip/ksz9477.c | 14 ++++---- drivers/net/dsa/microchip/ksz_common.c | 50 ++++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 7 ++++ 4 files changed, 68 insertions(+), 20 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 528de481b319..1058b6883caa 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -898,18 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) } } -static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port) -{ - /* Silicon Errata Sheet (DS80000830A): - * Port 1 does not work with LinkMD Cable-Testing. - * Port 1 does not respond to received PAUSE control frames. - */ - if (!port) - return MICREL_KSZ8_P1_ERRATA; - - return 0; -} - static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) { u8 data; @@ -1476,8 +1464,8 @@ static void ksz8_get_caps(struct ksz_device *dev, int port, static const struct dsa_switch_ops ksz8_switch_ops = { .get_tag_protocol = ksz_get_tag_protocol, - .get_phy_flags = ksz8_sw_get_phy_flags, - .setup = ksz8_setup, + .get_phy_flags = ksz_get_phy_flags, + .setup = ksz_setup, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_get_caps = ksz_phylink_get_caps, @@ -1544,6 +1532,7 @@ static void ksz8_switch_exit(struct ksz_device *dev) } static const struct ksz_dev_ops ksz8_dev_ops = { + .setup = ksz8_setup, .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, .flush_dyn_mac_table = ksz8_flush_dyn_mac_table, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index d70e0c32b309..d7474d9d4384 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -47,9 +47,8 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset, bits, set ? bits : 0); } -static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu) +static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu) { - struct ksz_device *dev = ds->priv; u16 frame_size, max_frame = 0; int i; @@ -65,7 +64,7 @@ static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu) REG_SW_MTU_MASK, max_frame); } -static int ksz9477_max_mtu(struct dsa_switch *ds, int port) +static int ksz9477_max_mtu(struct ksz_device *dev, int port) { return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN; } @@ -1296,7 +1295,7 @@ static int ksz9477_setup(struct dsa_switch *ds) static const struct dsa_switch_ops ksz9477_switch_ops = { .get_tag_protocol = ksz_get_tag_protocol, - .setup = ksz9477_setup, + .setup = ksz_setup, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_mac_link_down = ksz_mac_link_down, @@ -1320,8 +1319,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { .port_mirror_add = ksz_port_mirror_add, .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, - .port_change_mtu = ksz9477_change_mtu, - .port_max_mtu = ksz9477_max_mtu, + .port_change_mtu = ksz_change_mtu, + .port_max_mtu = ksz_max_mtu, }; static u32 ksz9477_get_port_addr(int port, int offset) @@ -1382,6 +1381,7 @@ static void ksz9477_switch_exit(struct ksz_device *dev) } static const struct ksz_dev_ops ksz9477_dev_ops = { + .setup = ksz9477_setup, .get_port_addr = ksz9477_get_port_addr, .cfg_port_member = ksz9477_cfg_port_member, .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table, @@ -1405,6 +1405,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .fdb_del = ksz9477_fdb_del, .mdb_add = ksz9477_mdb_add, .mdb_del = ksz9477_mdb_del, + .change_mtu = ksz9477_change_mtu, + .max_mtu = ksz9477_max_mtu, .shutdown = ksz9477_reset_switch, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 8f79ff1ac648..19f8e492d3aa 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -593,6 +594,14 @@ static void ksz_update_port_member(struct ksz_device *dev, int port) dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port); } +int ksz_setup(struct dsa_switch *ds) +{ + struct ksz_device *dev = ds->priv; + + return dev->dev_ops->setup(ds); +} +EXPORT_SYMBOL_GPL(ksz_setup); + static void port_r_cnt(struct ksz_device *dev, int port) { struct ksz_port_mib *mib = &dev->ports[port].mib; @@ -692,6 +701,23 @@ int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) } EXPORT_SYMBOL_GPL(ksz_phy_write16); +u32 ksz_get_phy_flags(struct dsa_switch *ds, int port) +{ + struct ksz_device *dev = ds->priv; + + if (dev->chip_id == KSZ8830_CHIP_ID) { + /* Silicon Errata Sheet (DS80000830A): + * Port 1 does not work with LinkMD Cable-Testing. + * Port 1 does not respond to received PAUSE control frames. + */ + if (!port) + return MICREL_KSZ8_P1_ERRATA; + } + + return 0; +} +EXPORT_SYMBOL_GPL(ksz_get_phy_flags); + void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, phy_interface_t interface) { @@ -981,6 +1007,30 @@ void ksz_port_mirror_del(struct dsa_switch *ds, int port, } EXPORT_SYMBOL_GPL(ksz_port_mirror_del); +int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->change_mtu) + ret = dev->dev_ops->change_mtu(dev, port, mtu); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_change_mtu); + +int ksz_max_mtu(struct dsa_switch *ds, int port) +{ + struct ksz_device *dev = ds->priv; + int ret = -EOPNOTSUPP; + + if (dev->dev_ops->max_mtu) + ret = dev->dev_ops->max_mtu(dev, port); + + return ret; +} +EXPORT_SYMBOL_GPL(ksz_max_mtu); + static int ksz_switch_detect(struct ksz_device *dev) { u8 id1, id2; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 133b1a257868..f7275c4f633a 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -161,6 +161,7 @@ struct alu_struct { }; struct ksz_dev_ops { + int (*setup)(struct dsa_switch *ds); u32 (*get_port_addr)(int port, int offset); void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member); void (*flush_dyn_mac_table)(struct ksz_device *dev, int port); @@ -207,6 +208,8 @@ struct ksz_dev_ops { int (*get_stp_reg)(void); void (*get_caps)(struct ksz_device *dev, int port, struct phylink_config *config); + int (*change_mtu)(struct ksz_device *dev, int port, int mtu); + int (*max_mtu)(struct ksz_device *dev, int port); void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); int (*shutdown)(struct ksz_device *dev); @@ -232,8 +235,10 @@ extern const struct ksz_chip_data ksz_switch_chips[]; /* Common DSA access functions */ +int ksz_setup(struct dsa_switch *ds); int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg); int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val); +u32 ksz_get_phy_flags(struct dsa_switch *ds, int port); void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, phy_interface_t interface); int ksz_sset_count(struct dsa_switch *ds, int port, int sset); @@ -274,6 +279,8 @@ int ksz_port_mirror_add(struct dsa_switch *ds, int port, bool ingress, struct netlink_ext_ack *extack); void ksz_port_mirror_del(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror); +int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu); +int ksz_max_mtu(struct dsa_switch *ds, int port); /* Common register access functions */ From patchwork Mon May 30 10:42:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864522 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F5C4C433FE for ; Mon, 30 May 2022 10:45:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235413AbiE3Kph (ORCPT ); Mon, 30 May 2022 06:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235410AbiE3KpD (ORCPT ); Mon, 30 May 2022 06:45:03 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8781574DD4; Mon, 30 May 2022 03:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907474; x=1685443474; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NX2PocqHXtKSOyWv1XcvF00LetrsGgNxCVl0boJYNfI=; b=ahuivi3J9XJ+NJrFu73Wvu3dU1UQhO9UaH3rIlZyQTzGwWT/UjS2Z7ku 7w0ZHca0cfmtuIsQN0lAjfvaF7heorODZ45QUzv+AxX6P8gQfd/wt5fu3 NCNM1mVOuchTq4KkDCSkgj9jNDSUQtLsNJ8I5iusDot2nLcbqQ6bM6FXn /yk99NqkNK6FS62Renj7+GxjP0/PLjhk3DxXb95Am9zfzZNJ2LoKtDnxn DZTOBUxrjE6xtqChMgJl3BBoW4qVgLFixRtHli5CchkFx8uQZOlsLzEGV aM8snik7JeUg0/k5dzkwIpfzUvsrVfF2xM6jQdEA8YwaswhlWRlE2Zjef A==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="166258881" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:33 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:33 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:29 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 11/15] net: dsa: microchip: common dsa_switch_ops for ksz switches Date: Mon, 30 May 2022 16:12:53 +0530 Message-ID: <20220530104257.21485-12-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC At present, ksz8795.c and ksz9477.c have separate dsa_switch_ops structure initialization. This patch modifies the files such a way that ksz switches has common dsa_switch_ops in the ksz_common.c file. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8795.c | 28 ----- drivers/net/dsa/microchip/ksz9477.c | 33 +---- drivers/net/dsa/microchip/ksz_common.c | 164 +++++++++++++------------ drivers/net/dsa/microchip/ksz_common.h | 54 +------- 4 files changed, 89 insertions(+), 190 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 1058b6883caa..ff4b33a3b1b4 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -1462,32 +1462,6 @@ static void ksz8_get_caps(struct ksz_device *dev, int port, config->mac_capabilities |= MAC_ASYM_PAUSE; } -static const struct dsa_switch_ops ksz8_switch_ops = { - .get_tag_protocol = ksz_get_tag_protocol, - .get_phy_flags = ksz_get_phy_flags, - .setup = ksz_setup, - .phy_read = ksz_phy_read16, - .phy_write = ksz_phy_write16, - .phylink_get_caps = ksz_phylink_get_caps, - .phylink_mac_link_down = ksz_mac_link_down, - .port_enable = ksz_enable_port, - .get_strings = ksz_get_strings, - .get_ethtool_stats = ksz_get_ethtool_stats, - .get_sset_count = ksz_sset_count, - .port_bridge_join = ksz_port_bridge_join, - .port_bridge_leave = ksz_port_bridge_leave, - .port_stp_state_set = ksz_port_stp_state_set, - .port_fast_age = ksz_port_fast_age, - .port_vlan_filtering = ksz_port_vlan_filtering, - .port_vlan_add = ksz_port_vlan_add, - .port_vlan_del = ksz_port_vlan_del, - .port_fdb_dump = ksz_port_fdb_dump, - .port_mdb_add = ksz_port_mdb_add, - .port_mdb_del = ksz_port_mdb_del, - .port_mirror_add = ksz_port_mirror_add, - .port_mirror_del = ksz_port_mirror_del, -}; - static u32 ksz8_get_port_addr(int port, int offset) { return PORT_CTRL_ADDR(port, offset); @@ -1497,8 +1471,6 @@ static int ksz8_switch_init(struct ksz_device *dev) { struct ksz8 *ksz8 = dev->priv; - dev->ds->ops = &ksz8_switch_ops; - dev->cpu_port = fls(dev->info->cpu_ports) - 1; dev->phy_port_cnt = dev->info->port_cnt - 1; dev->port_mask = (BIT(dev->phy_port_cnt) - 1) | dev->info->cpu_ports; diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index d7474d9d4384..ecce99b77ef6 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1293,36 +1293,6 @@ static int ksz9477_setup(struct dsa_switch *ds) return 0; } -static const struct dsa_switch_ops ksz9477_switch_ops = { - .get_tag_protocol = ksz_get_tag_protocol, - .setup = ksz_setup, - .phy_read = ksz_phy_read16, - .phy_write = ksz_phy_write16, - .phylink_mac_link_down = ksz_mac_link_down, - .phylink_get_caps = ksz_phylink_get_caps, - .port_enable = ksz_enable_port, - .get_strings = ksz_get_strings, - .get_ethtool_stats = ksz_get_ethtool_stats, - .get_sset_count = ksz_sset_count, - .port_bridge_join = ksz_port_bridge_join, - .port_bridge_leave = ksz_port_bridge_leave, - .port_stp_state_set = ksz_port_stp_state_set, - .port_fast_age = ksz_port_fast_age, - .port_vlan_filtering = ksz_port_vlan_filtering, - .port_vlan_add = ksz_port_vlan_add, - .port_vlan_del = ksz_port_vlan_del, - .port_fdb_dump = ksz_port_fdb_dump, - .port_fdb_add = ksz_port_fdb_add, - .port_fdb_del = ksz_port_fdb_del, - .port_mdb_add = ksz_port_mdb_add, - .port_mdb_del = ksz_port_mdb_del, - .port_mirror_add = ksz_port_mirror_add, - .port_mirror_del = ksz_port_mirror_del, - .get_stats64 = ksz_get_stats64, - .port_change_mtu = ksz_change_mtu, - .port_max_mtu = ksz_max_mtu, -}; - static u32 ksz9477_get_port_addr(int port, int offset) { return PORT_CTRL_ADDR(port, offset); @@ -1333,8 +1303,6 @@ static int ksz9477_switch_init(struct ksz_device *dev) u8 data8; int ret; - dev->ds->ops = &ksz9477_switch_ops; - dev->port_mask = (1 << dev->info->port_cnt) - 1; /* turn off SPI DO Edge select */ @@ -1372,6 +1340,7 @@ static int ksz9477_switch_init(struct ksz_device *dev) if (!(data8 & SW_GIGABIT_ABLE)) dev->features &= ~GBIT_SUPPORT; } + return 0; } diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 19f8e492d3aa..ace5cf0ad5a8 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -437,8 +437,8 @@ static int ksz_check_device_id(struct ksz_device *dev) return 0; } -void ksz_phylink_get_caps(struct dsa_switch *ds, int port, - struct phylink_config *config) +static void ksz_phylink_get_caps(struct dsa_switch *ds, int port, + struct phylink_config *config) { struct ksz_device *dev = ds->priv; @@ -461,7 +461,6 @@ void ksz_phylink_get_caps(struct dsa_switch *ds, int port, if (dev->dev_ops->get_caps) dev->dev_ops->get_caps(dev, port, config); } -EXPORT_SYMBOL_GPL(ksz_phylink_get_caps); void ksz_r_mib_stats64(struct ksz_device *dev, int port) { @@ -506,8 +505,8 @@ void ksz_r_mib_stats64(struct ksz_device *dev, int port) } EXPORT_SYMBOL_GPL(ksz_r_mib_stats64); -void ksz_get_stats64(struct dsa_switch *ds, int port, - struct rtnl_link_stats64 *s) +static void ksz_get_stats64(struct dsa_switch *ds, int port, + struct rtnl_link_stats64 *s) { struct ksz_device *dev = ds->priv; struct ksz_port_mib *mib; @@ -518,10 +517,9 @@ void ksz_get_stats64(struct dsa_switch *ds, int port, memcpy(s, &mib->stats64, sizeof(*s)); spin_unlock(&mib->stats64_lock); } -EXPORT_SYMBOL_GPL(ksz_get_stats64); -void ksz_get_strings(struct dsa_switch *ds, int port, - u32 stringset, uint8_t *buf) +static void ksz_get_strings(struct dsa_switch *ds, int port, + u32 stringset, uint8_t *buf) { struct ksz_device *dev = ds->priv; int i; @@ -534,7 +532,6 @@ void ksz_get_strings(struct dsa_switch *ds, int port, dev->info->mib_names[i].string, ETH_GSTRING_LEN); } } -EXPORT_SYMBOL_GPL(ksz_get_strings); static void ksz_update_port_member(struct ksz_device *dev, int port) { @@ -594,13 +591,12 @@ static void ksz_update_port_member(struct ksz_device *dev, int port) dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port); } -int ksz_setup(struct dsa_switch *ds) +static int ksz_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; return dev->dev_ops->setup(ds); } -EXPORT_SYMBOL_GPL(ksz_setup); static void port_r_cnt(struct ksz_device *dev, int port) { @@ -680,7 +676,7 @@ void ksz_init_mib_timer(struct ksz_device *dev) } EXPORT_SYMBOL_GPL(ksz_init_mib_timer); -int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg) +static int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg) { struct ksz_device *dev = ds->priv; u16 val = 0xffff; @@ -689,9 +685,8 @@ int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg) return val; } -EXPORT_SYMBOL_GPL(ksz_phy_read16); -int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) +static int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) { struct ksz_device *dev = ds->priv; @@ -699,9 +694,8 @@ int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) return 0; } -EXPORT_SYMBOL_GPL(ksz_phy_write16); -u32 ksz_get_phy_flags(struct dsa_switch *ds, int port) +static u32 ksz_get_phy_flags(struct dsa_switch *ds, int port) { struct ksz_device *dev = ds->priv; @@ -716,10 +710,9 @@ u32 ksz_get_phy_flags(struct dsa_switch *ds, int port) return 0; } -EXPORT_SYMBOL_GPL(ksz_get_phy_flags); -void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, - phy_interface_t interface) +static void ksz_mac_link_down(struct dsa_switch *ds, int port, + unsigned int mode, phy_interface_t interface) { struct ksz_device *dev = ds->priv; struct ksz_port *p = &dev->ports[port]; @@ -730,9 +723,8 @@ void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, if (dev->mib_read_interval) schedule_delayed_work(&dev->mib_read, 0); } -EXPORT_SYMBOL_GPL(ksz_mac_link_down); -int ksz_sset_count(struct dsa_switch *ds, int port, int sset) +static int ksz_sset_count(struct dsa_switch *ds, int port, int sset) { struct ksz_device *dev = ds->priv; @@ -741,9 +733,9 @@ int ksz_sset_count(struct dsa_switch *ds, int port, int sset) return dev->info->mib_cnt; } -EXPORT_SYMBOL_GPL(ksz_sset_count); -void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf) +static void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, + uint64_t *buf) { const struct dsa_port *dp = dsa_to_port(ds, port); struct ksz_device *dev = ds->priv; @@ -759,12 +751,11 @@ void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf) memcpy(buf, mib->counters, dev->info->mib_cnt * sizeof(u64)); mutex_unlock(&mib->cnt_mutex); } -EXPORT_SYMBOL_GPL(ksz_get_ethtool_stats); -int ksz_port_bridge_join(struct dsa_switch *ds, int port, - struct dsa_bridge bridge, - bool *tx_fwd_offload, - struct netlink_ext_ack *extack) +static int ksz_port_bridge_join(struct dsa_switch *ds, int port, + struct dsa_bridge bridge, + bool *tx_fwd_offload, + struct netlink_ext_ack *extack) { /* port_stp_state_set() will be called after to put the port in * appropriate state so there is no need to do anything. @@ -772,27 +763,25 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port, return 0; } -EXPORT_SYMBOL_GPL(ksz_port_bridge_join); -void ksz_port_bridge_leave(struct dsa_switch *ds, int port, - struct dsa_bridge bridge) +static void ksz_port_bridge_leave(struct dsa_switch *ds, int port, + struct dsa_bridge bridge) { /* port_stp_state_set() will be called after to put the port in * forwarding state so there is no need to do anything. */ } -EXPORT_SYMBOL_GPL(ksz_port_bridge_leave); -void ksz_port_fast_age(struct dsa_switch *ds, int port) +static void ksz_port_fast_age(struct dsa_switch *ds, int port) { struct ksz_device *dev = ds->priv; dev->dev_ops->flush_dyn_mac_table(dev, port); } -EXPORT_SYMBOL_GPL(ksz_port_fast_age); -int ksz_port_fdb_add(struct dsa_switch *ds, int port, - const unsigned char *addr, u16 vid, struct dsa_db db) +static int ksz_port_fdb_add(struct dsa_switch *ds, int port, + const unsigned char *addr, u16 vid, + struct dsa_db db) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -802,10 +791,10 @@ int ksz_port_fdb_add(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_fdb_add); -int ksz_port_fdb_del(struct dsa_switch *ds, int port, - const unsigned char *addr, u16 vid, struct dsa_db db) +static int ksz_port_fdb_del(struct dsa_switch *ds, int port, + const unsigned char *addr, + u16 vid, struct dsa_db db) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -815,10 +804,9 @@ int ksz_port_fdb_del(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_fdb_del); -int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, - void *data) +static int ksz_port_fdb_dump(struct dsa_switch *ds, int port, + dsa_fdb_dump_cb_t *cb, void *data) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -828,11 +816,10 @@ int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_fdb_dump); -int ksz_port_mdb_add(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +static int ksz_port_mdb_add(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -842,11 +829,10 @@ int ksz_port_mdb_add(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_mdb_add); -int ksz_port_mdb_del(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +static int ksz_port_mdb_del(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_mdb *mdb, + struct dsa_db db) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -856,9 +842,9 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_mdb_del); -int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) +static int ksz_enable_port(struct dsa_switch *ds, int port, + struct phy_device *phy) { struct ksz_device *dev = ds->priv; @@ -874,7 +860,6 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) return 0; } -EXPORT_SYMBOL_GPL(ksz_enable_port); void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) { @@ -918,8 +903,9 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) } EXPORT_SYMBOL_GPL(ksz_port_stp_state_set); -enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, - int port, enum dsa_tag_protocol mp) +static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, + int port, + enum dsa_tag_protocol mp) { struct ksz_device *dev = ds->priv; enum dsa_tag_protocol proto; @@ -940,10 +926,9 @@ enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, return proto; } -EXPORT_SYMBOL_GPL(ksz_get_tag_protocol); -int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, - bool flag, struct netlink_ext_ack *extack) +static int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, + bool flag, struct netlink_ext_ack *extack) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -953,11 +938,10 @@ int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_vlan_filtering); -int ksz_port_vlan_add(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_vlan *vlan, - struct netlink_ext_ack *extack) +static int ksz_port_vlan_add(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -967,10 +951,9 @@ int ksz_port_vlan_add(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_vlan_add); -int ksz_port_vlan_del(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_vlan *vlan) +static int ksz_port_vlan_del(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -980,11 +963,10 @@ int ksz_port_vlan_del(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_vlan_del); -int ksz_port_mirror_add(struct dsa_switch *ds, int port, - struct dsa_mall_mirror_tc_entry *mirror, - bool ingress, struct netlink_ext_ack *extack) +static int ksz_port_mirror_add(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -995,19 +977,17 @@ int ksz_port_mirror_add(struct dsa_switch *ds, int port, return ret; } -EXPORT_SYMBOL_GPL(ksz_port_mirror_add); -void ksz_port_mirror_del(struct dsa_switch *ds, int port, - struct dsa_mall_mirror_tc_entry *mirror) +static void ksz_port_mirror_del(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror) { struct ksz_device *dev = ds->priv; if (dev->dev_ops->mirror_del) dev->dev_ops->mirror_del(dev, port, mirror); } -EXPORT_SYMBOL_GPL(ksz_port_mirror_del); -int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu) +static int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -1017,9 +997,8 @@ int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu) return ret; } -EXPORT_SYMBOL_GPL(ksz_change_mtu); -int ksz_max_mtu(struct dsa_switch *ds, int port) +static int ksz_max_mtu(struct dsa_switch *ds, int port) { struct ksz_device *dev = ds->priv; int ret = -EOPNOTSUPP; @@ -1029,7 +1008,6 @@ int ksz_max_mtu(struct dsa_switch *ds, int port) return ret; } -EXPORT_SYMBOL_GPL(ksz_max_mtu); static int ksz_switch_detect(struct ksz_device *dev) { @@ -1097,6 +1075,37 @@ static int ksz_switch_detect(struct ksz_device *dev) return 0; } +static const struct dsa_switch_ops ksz_switch_ops = { + .get_tag_protocol = ksz_get_tag_protocol, + .get_phy_flags = ksz_get_phy_flags, + .setup = ksz_setup, + .phy_read = ksz_phy_read16, + .phy_write = ksz_phy_write16, + .phylink_get_caps = ksz_phylink_get_caps, + .phylink_mac_link_down = ksz_mac_link_down, + .port_enable = ksz_enable_port, + .get_strings = ksz_get_strings, + .get_ethtool_stats = ksz_get_ethtool_stats, + .get_sset_count = ksz_sset_count, + .port_bridge_join = ksz_port_bridge_join, + .port_bridge_leave = ksz_port_bridge_leave, + .port_stp_state_set = ksz_port_stp_state_set, + .port_fast_age = ksz_port_fast_age, + .port_vlan_filtering = ksz_port_vlan_filtering, + .port_vlan_add = ksz_port_vlan_add, + .port_vlan_del = ksz_port_vlan_del, + .port_fdb_dump = ksz_port_fdb_dump, + .port_fdb_add = ksz_port_fdb_add, + .port_fdb_del = ksz_port_fdb_del, + .port_mdb_add = ksz_port_mdb_add, + .port_mdb_del = ksz_port_mdb_del, + .port_mirror_add = ksz_port_mirror_add, + .port_mirror_del = ksz_port_mirror_del, + .get_stats64 = ksz_get_stats64, + .port_change_mtu = ksz_change_mtu, + .port_max_mtu = ksz_max_mtu, +}; + struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) { struct dsa_switch *ds; @@ -1108,6 +1117,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) ds->dev = base; ds->num_ports = DSA_MAX_PORTS; + ds->ops = &ksz_switch_ops; swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL); if (!swdev) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index f7275c4f633a..872d378ac45c 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -227,60 +227,8 @@ int ksz9477_switch_register(struct ksz_device *dev); void ksz_init_mib_timer(struct ksz_device *dev); void ksz_r_mib_stats64(struct ksz_device *dev, int port); -void ksz_get_stats64(struct dsa_switch *ds, int port, - struct rtnl_link_stats64 *s); -void ksz_phylink_get_caps(struct dsa_switch *ds, int port, - struct phylink_config *config); -extern const struct ksz_chip_data ksz_switch_chips[]; - -/* Common DSA access functions */ - -int ksz_setup(struct dsa_switch *ds); -int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg); -int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val); -u32 ksz_get_phy_flags(struct dsa_switch *ds, int port); -void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, - phy_interface_t interface); -int ksz_sset_count(struct dsa_switch *ds, int port, int sset); -void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf); -int ksz_port_bridge_join(struct dsa_switch *ds, int port, - struct dsa_bridge bridge, bool *tx_fwd_offload, - struct netlink_ext_ack *extack); -void ksz_port_bridge_leave(struct dsa_switch *ds, int port, - struct dsa_bridge bridge); void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state); -void ksz_port_fast_age(struct dsa_switch *ds, int port); -int ksz_port_fdb_add(struct dsa_switch *ds, int port, - const unsigned char *addr, u16 vid, struct dsa_db db); -int ksz_port_fdb_del(struct dsa_switch *ds, int port, - const unsigned char *addr, u16 vid, struct dsa_db db); -int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, - void *data); -int ksz_port_mdb_add(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db); -int ksz_port_mdb_del(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db); -int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy); -void ksz_get_strings(struct dsa_switch *ds, int port, - u32 stringset, uint8_t *buf); -enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, - int port, enum dsa_tag_protocol mp); -int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, - bool flag, struct netlink_ext_ack *extack); -int ksz_port_vlan_add(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_vlan *vlan, - struct netlink_ext_ack *extack); -int ksz_port_vlan_del(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_vlan *vlan); -int ksz_port_mirror_add(struct dsa_switch *ds, int port, - struct dsa_mall_mirror_tc_entry *mirror, - bool ingress, struct netlink_ext_ack *extack); -void ksz_port_mirror_del(struct dsa_switch *ds, int port, - struct dsa_mall_mirror_tc_entry *mirror); -int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu); -int ksz_max_mtu(struct dsa_switch *ds, int port); +extern const struct ksz_chip_data ksz_switch_chips[]; /* Common register access functions */ From patchwork Mon May 30 10:42:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864519 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A3E3C4332F for ; Mon, 30 May 2022 10:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234211AbiE3Kpb (ORCPT ); Mon, 30 May 2022 06:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235523AbiE3KpK (ORCPT ); Mon, 30 May 2022 06:45:10 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A443B7CB16; Mon, 30 May 2022 03:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907483; x=1685443483; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RwQc5FyNxnZwDYZUUhQH6gr1/5DebPTnHa51OwkXzy0=; b=gpicyVzhuwnWBM7adP49h0YOI8QG5YYOwp0D72YE018IPbVTrSSEuLd3 l7V5Oi5f1NVsAJ2r+jjtqyYE8cPdeLamWj8XlZ2jYfCzuwwo1RlToKLu2 d4/aI7WqI+B+0kSP/f4Wucppkf0wjY1q7RhbpjZIhNcAQ3SzF6qKW5vEy JXU0xZ9Z+V5FGddnF16bfTtFWv5rKvqDAUGPEHundBa2a+aAMecqEaPZV ICBxnzkMISV44o1blhIpsKPNH4gdwafW9zaPrto+RA8ZUf2tw53337KMC xpzdyHP55WNDgcqIceSkEfODUPu1sJL8H+HvAQ9XVDpzMUuOPzvNwQ+kV Q==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="166258930" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:42 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:41 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:37 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register Date: Mon, 30 May 2022 16:12:54 +0530 Message-ID: <20220530104257.21485-13-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC As per 'commit 3506b2f42dff ("net: dsa: microchip: call phy_remove_link_mode during probe")' phy_remove_link_mode is added in the switch_register function after dsa_switch_register. In order to have the common switch register function, moving this phy init after dsa_register_switch using the new ksz_dev_ops.dsa_init hook. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz9477.c | 49 ++++++++++++++------------ drivers/net/dsa/microchip/ksz_common.c | 5 ++- drivers/net/dsa/microchip/ksz_common.h | 1 + 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index ecce99b77ef6..c87ce0e2afd8 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1349,6 +1349,30 @@ static void ksz9477_switch_exit(struct ksz_device *dev) ksz9477_reset_switch(dev); } +static int ksz9477_dsa_init(struct ksz_device *dev) +{ + struct phy_device *phydev; + int i; + + for (i = 0; i < dev->phy_port_cnt; ++i) { + if (!dsa_is_user_port(dev->ds, i)) + continue; + + phydev = dsa_to_port(dev->ds, i)->slave->phydev; + + /* The MAC actually cannot run in 1000 half-duplex mode. */ + phy_remove_link_mode(phydev, + ETHTOOL_LINK_MODE_1000baseT_Half_BIT); + + /* PHY does not support gigabit. */ + if (!(dev->features & GBIT_SUPPORT)) + phy_remove_link_mode(phydev, + ETHTOOL_LINK_MODE_1000baseT_Full_BIT); + } + + return 0; +} + static const struct ksz_dev_ops ksz9477_dev_ops = { .setup = ksz9477_setup, .get_port_addr = ksz9477_get_port_addr, @@ -1377,35 +1401,14 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .change_mtu = ksz9477_change_mtu, .max_mtu = ksz9477_max_mtu, .shutdown = ksz9477_reset_switch, + .dsa_init = ksz9477_dsa_init, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit, }; int ksz9477_switch_register(struct ksz_device *dev) { - int ret, i; - struct phy_device *phydev; - - ret = ksz_switch_register(dev, &ksz9477_dev_ops); - if (ret) - return ret; - - for (i = 0; i < dev->phy_port_cnt; ++i) { - if (!dsa_is_user_port(dev->ds, i)) - continue; - - phydev = dsa_to_port(dev->ds, i)->slave->phydev; - - /* The MAC actually cannot run in 1000 half-duplex mode. */ - phy_remove_link_mode(phydev, - ETHTOOL_LINK_MODE_1000baseT_Half_BIT); - - /* PHY does not support gigabit. */ - if (!(dev->features & GBIT_SUPPORT)) - phy_remove_link_mode(phydev, - ETHTOOL_LINK_MODE_1000baseT_Full_BIT); - } - return ret; + return ksz_switch_register(dev, &ksz9477_dev_ops); } EXPORT_SYMBOL(ksz9477_switch_register); diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index ace5cf0ad5a8..f40d64858d35 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -1253,7 +1253,10 @@ int ksz_switch_register(struct ksz_device *dev, /* Start the MIB timer. */ schedule_delayed_work(&dev->mib_read, 0); - return 0; + if (dev->dev_ops->dsa_init) + ret = dev->dev_ops->dsa_init(dev); + + return ret; } EXPORT_SYMBOL(ksz_switch_register); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 872d378ac45c..23962f47df46 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -213,6 +213,7 @@ struct ksz_dev_ops { void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); int (*shutdown)(struct ksz_device *dev); + int (*dsa_init)(struct ksz_device *dev); int (*init)(struct ksz_device *dev); void (*exit)(struct ksz_device *dev); }; From patchwork Mon May 30 10:42:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864518 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE5C8C433EF for ; Mon, 30 May 2022 10:45:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235326AbiE3Kp3 (ORCPT ); Mon, 30 May 2022 06:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235529AbiE3KpK (ORCPT ); Mon, 30 May 2022 06:45:10 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B522F7CB5F; Mon, 30 May 2022 03:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907489; x=1685443489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2Otoz5YtUY5UHAOLNEZxCRuGxLKPnn/UlxdImZmJO1I=; b=XPDf/ci9TxW16DAF0iQ1VR029DKRoxw9N3beVl07QZZiuDu1GmeqLpxl b8rBBoyknQBQFd52fTNUZ+TphFUPC7j8LU+dlSCmLQqdxRBGGBpkGTT5c 6uEjasDOGx4NrUQ+ELSppmDXLY5Z4nf3ZqtEB0tXp51D4kvnVFCIbybU8 jDJRonWP3TlqdrRMu/qPppBdCIVwLaUwIxw1cAgD6aRhdvniIkZTYuxvA SXB33e3LxRYMFHk6TV+tgUX+nsIDvL/bjFy78JckEBY/+5nH+FK1Fmh/4 nyUT/xBZbQZUnMB9f6y8aUJWmc9unP49cvRlooXt/1CVdvusnI80XfCf9 A==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="161124788" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:44:48 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:48 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:44 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 13/15] net: dsa: microchip: common menuconfig for ksz series switch Date: Mon, 30 May 2022 16:12:55 +0530 Message-ID: <20220530104257.21485-14-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch replaces the two different menuconfig for ksz9477 and ksz8795 to single ksz_common. so that it can be extended for the other switch like lan937x. And removes the export_symbols for the extern functions in the ksz_common.h. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/Kconfig | 28 +++++++++----------------- drivers/net/dsa/microchip/Makefile | 7 ++++--- drivers/net/dsa/microchip/ksz_common.c | 3 --- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/drivers/net/dsa/microchip/Kconfig b/drivers/net/dsa/microchip/Kconfig index c9e2a8989556..d21ff069e5aa 100644 --- a/drivers/net/dsa/microchip/Kconfig +++ b/drivers/net/dsa/microchip/Kconfig @@ -1,39 +1,29 @@ # SPDX-License-Identifier: GPL-2.0-only -config NET_DSA_MICROCHIP_KSZ_COMMON - select NET_DSA_TAG_KSZ - tristate - -menuconfig NET_DSA_MICROCHIP_KSZ9477 - tristate "Microchip KSZ9477 series switch support" +menuconfig NET_DSA_MICROCHIP_KSZ_COMMON + tristate "Microchip KSZ8795/KSZ9477 series switch support" depends on NET_DSA - select NET_DSA_MICROCHIP_KSZ_COMMON + select NET_DSA_TAG_KSZ help - This driver adds support for Microchip KSZ9477 switch chips. + This driver adds support for Microchip KSZ9477 series switch and + KSZ8795/KSZ88x3 switch chips. config NET_DSA_MICROCHIP_KSZ9477_I2C tristate "KSZ9477 series I2C connected switch driver" - depends on NET_DSA_MICROCHIP_KSZ9477 && I2C + depends on NET_DSA_MICROCHIP_KSZ_COMMON && I2C select REGMAP_I2C help Select to enable support for registering switches configured through I2C. config NET_DSA_MICROCHIP_KSZ9477_SPI tristate "KSZ9477 series SPI connected switch driver" - depends on NET_DSA_MICROCHIP_KSZ9477 && SPI + depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI select REGMAP_SPI help Select to enable support for registering switches configured through SPI. -menuconfig NET_DSA_MICROCHIP_KSZ8795 - tristate "Microchip KSZ8795 series switch support" - depends on NET_DSA - select NET_DSA_MICROCHIP_KSZ_COMMON - help - This driver adds support for Microchip KSZ8795/KSZ88X3 switch chips. - config NET_DSA_MICROCHIP_KSZ8795_SPI tristate "KSZ8795 series SPI connected switch driver" - depends on NET_DSA_MICROCHIP_KSZ8795 && SPI + depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI select REGMAP_SPI help This driver accesses KSZ8795 chip through SPI. @@ -43,7 +33,7 @@ config NET_DSA_MICROCHIP_KSZ8795_SPI config NET_DSA_MICROCHIP_KSZ8863_SMI tristate "KSZ series SMI connected switch driver" - depends on NET_DSA_MICROCHIP_KSZ8795 + depends on NET_DSA_MICROCHIP_KSZ_COMMON select MDIO_BITBANG help Select to enable support for registering switches configured through diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip/Makefile index 2a03b21a3386..4cf4755e6426 100644 --- a/drivers/net/dsa/microchip/Makefile +++ b/drivers/net/dsa/microchip/Makefile @@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON) += ksz_common.o -obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477) += ksz9477.o +obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON) += ksz_switch.o +ksz_switch-objs := ksz_common.o +ksz_switch-objs += ksz9477.o +ksz_switch-objs += ksz8795.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI) += ksz9477_spi.o -obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795) += ksz8795.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795_SPI) += ksz8795_spi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index f40d64858d35..8f852649c217 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -503,7 +503,6 @@ void ksz_r_mib_stats64(struct ksz_device *dev, int port) spin_unlock(&mib->stats64_lock); } -EXPORT_SYMBOL_GPL(ksz_r_mib_stats64); static void ksz_get_stats64(struct dsa_switch *ds, int port, struct rtnl_link_stats64 *s) @@ -674,7 +673,6 @@ void ksz_init_mib_timer(struct ksz_device *dev) memset(mib->counters, 0, dev->info->mib_cnt * sizeof(u64)); } } -EXPORT_SYMBOL_GPL(ksz_init_mib_timer); static int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg) { @@ -901,7 +899,6 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) ksz_update_port_member(dev, port); } -EXPORT_SYMBOL_GPL(ksz_port_stp_state_set); static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds, int port, From patchwork Mon May 30 10:42:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864521 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B519C433F5 for ; Mon, 30 May 2022 10:45:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235382AbiE3Kpg (ORCPT ); Mon, 30 May 2022 06:45:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235553AbiE3KpN (ORCPT ); Mon, 30 May 2022 06:45:13 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A70017CDD9; Mon, 30 May 2022 03:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907501; x=1685443501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yD+UidQ4JHeg1ql64Js19oGacUngysc4A0+nvKOShHo=; b=TitAMymqVjm+YU+/ZJikIEo1xjJMLvgW1sSvT5MhC+VkgNAjVY2dCWKC FpMjgL8h4Z9u696f5UkDV3DHRjhYyOBEbbiYb76ceTq0IEypLwP4z0kXg XOXJP5Chv0gF41hw0YUcShvUWchAKmH6l7QpgmaLFz/90syz9VK+BTzBi yJqU3XkiL5F+/VUMUHFPJklWLUTDyyCR4Rh6Nfti/MUdvCcBjZ5hGgOEE fQtfnlw0OzIW3iWwI798m36t13sdYe/qMVhWKmnHXJJ0/jTwR6FyNKtmk dbjREGSE19T3KlwZSEv0yd7L+zqsHcp8lag8koFwAmXpwNECUkZuSA2uR A==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="165913274" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:45:00 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:44:58 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:44:53 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 14/15] net: dsa: microchip: move ksz_dev_ops to ksz_common.c Date: Mon, 30 May 2022 16:12:56 +0530 Message-ID: <20220530104257.21485-15-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch move the ksz_dev_ops from individual files to ksz_common.c. And the dev_ops is assigned to ksz_device based on the switch detect. This reduces the redundant function and allows to reuse the functionality for LAN937x which has similar register set. And deletes the ksz8_switch_register and ksz9477_switch_register since both are calling the ksz_switch_register function. Instead the ksz_switch_register is called from the probe function. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8.h | 46 ++++++++ drivers/net/dsa/microchip/ksz8795.c | 123 ++++++++-------------- drivers/net/dsa/microchip/ksz8795_spi.c | 2 +- drivers/net/dsa/microchip/ksz8863_smi.c | 2 +- drivers/net/dsa/microchip/ksz9477.c | 133 ++++++++---------------- drivers/net/dsa/microchip/ksz9477.h | 58 +++++++++++ drivers/net/dsa/microchip/ksz9477_i2c.c | 2 +- drivers/net/dsa/microchip/ksz9477_spi.c | 2 +- drivers/net/dsa/microchip/ksz_common.c | 78 +++++++++++++- drivers/net/dsa/microchip/ksz_common.h | 7 +- 10 files changed, 271 insertions(+), 182 deletions(-) create mode 100644 drivers/net/dsa/microchip/ksz9477.h diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h index 03da369675c6..90d5c7ea7850 100644 --- a/drivers/net/dsa/microchip/ksz8.h +++ b/drivers/net/dsa/microchip/ksz8.h @@ -8,6 +8,8 @@ #ifndef __KSZ8XXX_H #define __KSZ8XXX_H #include +#include +#include "ksz_common.h" enum ksz_regs { REG_IND_CTRL_0, @@ -67,4 +69,48 @@ struct ksz8 { void *priv; }; +int ksz8_setup(struct dsa_switch *ds); +u32 ksz8_get_port_addr(int port, int offset); +void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member); +void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port); +void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port); +void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val); +void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val); +int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr, + u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries); +int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, + struct alu_struct *alu); +void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr, + struct alu_struct *alu); +void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt); +void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, + u64 *dropped, u64 *cnt); +void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze); +void ksz8_port_init_cnt(struct ksz_device *dev, int port); +int ksz8_fdb_dump(struct ksz_device *dev, int port, + dsa_fdb_dump_cb_t *cb, void *data); +int ksz8_mdb_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); +int ksz8_mdb_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); +int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag, + struct netlink_ext_ack *extack); +int ksz8_port_vlan_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack); +int ksz8_port_vlan_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan); +int ksz8_port_mirror_add(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack); +void ksz8_port_mirror_del(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror); +int ksz8_get_stp_reg(void); +void ksz8_get_caps(struct ksz_device *dev, int port, + struct phylink_config *config); +int ksz8_reset_switch(struct ksz_device *dev); +int ksz8_switch_detect(struct ksz_device *dev); +int ksz8_switch_init(struct ksz_device *dev); +void ksz8_switch_exit(struct ksz_device *dev); + #endif diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index ff4b33a3b1b4..3c9d32caa9ad 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -162,7 +162,7 @@ static int ksz8_ind_write8(struct ksz_device *dev, u8 table, u16 addr, u8 data) return ret; } -static int ksz8_reset_switch(struct ksz_device *dev) +int ksz8_reset_switch(struct ksz_device *dev) { if (ksz_is_ksz88x3(dev)) { /* reset switch */ @@ -213,7 +213,7 @@ static void ksz8795_set_prio_queue(struct ksz_device *dev, int port, int queue) true); } -static void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt) +void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt) { struct ksz8 *ksz8 = dev->priv; const u32 *masks; @@ -334,8 +334,8 @@ static void ksz8863_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, } } -static void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, - u64 *dropped, u64 *cnt) +void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, + u64 *dropped, u64 *cnt) { if (ksz_is_ksz88x3(dev)) ksz8863_r_mib_pkt(dev, port, addr, dropped, cnt); @@ -343,7 +343,7 @@ static void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, ksz8795_r_mib_pkt(dev, port, addr, dropped, cnt); } -static void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze) +void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze) { if (ksz_is_ksz88x3(dev)) return; @@ -358,7 +358,7 @@ static void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze) ksz_cfg(dev, REG_SW_CTRL_6, BIT(port), false); } -static void ksz8_port_init_cnt(struct ksz_device *dev, int port) +void ksz8_port_init_cnt(struct ksz_device *dev, int port) { struct ksz_port_mib *mib = &dev->ports[port].mib; u64 *dropped; @@ -447,9 +447,8 @@ static int ksz8_valid_dyn_entry(struct ksz_device *dev, u8 *data) return 0; } -static int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, - u8 *mac_addr, u8 *fid, u8 *src_port, - u8 *timestamp, u16 *entries) +int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr, + u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries) { struct ksz8 *ksz8 = dev->priv; u32 data_hi, data_lo; @@ -512,8 +511,8 @@ static int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, return rc; } -static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, - struct alu_struct *alu) +int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, + struct alu_struct *alu) { struct ksz8 *ksz8 = dev->priv; u32 data_hi, data_lo; @@ -551,8 +550,8 @@ static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, return -ENXIO; } -static void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr, - struct alu_struct *alu) +void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr, + struct alu_struct *alu) { struct ksz8 *ksz8 = dev->priv; u32 data_hi, data_lo; @@ -663,7 +662,7 @@ static void ksz8_w_vlan_table(struct ksz_device *dev, u16 vid, u16 vlan) ksz8_w_table(dev, TABLE_VLAN, addr, buf); } -static void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) +void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) { struct ksz8 *ksz8 = dev->priv; u8 restart, speed, ctrl, link; @@ -786,7 +785,7 @@ static void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) *val = data; } -static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) +void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) { struct ksz8 *ksz8 = dev->priv; u8 restart, speed, ctrl, data; @@ -898,7 +897,7 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) } } -static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) +void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) { u8 data; @@ -908,12 +907,12 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) ksz_pwrite8(dev, port, P_MIRROR_CTRL, data); } -static int ksz8_get_stp_reg(void) +int ksz8_get_stp_reg(void) { return P_STP_CTRL; } -static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) +void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) { u8 learn[DSA_MAX_PORTS]; int first, index, cnt; @@ -946,8 +945,8 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) } } -static int ksz8_fdb_dump(struct ksz_device *dev, int port, - dsa_fdb_dump_cb_t *cb, void *data) +int ksz8_fdb_dump(struct ksz_device *dev, int port, + dsa_fdb_dump_cb_t *cb, void *data) { int ret = 0; u16 i = 0; @@ -975,9 +974,8 @@ static int ksz8_fdb_dump(struct ksz_device *dev, int port, return ret; } -static int ksz8_mdb_add(struct ksz_device *dev, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +int ksz8_mdb_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { struct alu_struct alu; int index; @@ -1019,9 +1017,8 @@ static int ksz8_mdb_add(struct ksz_device *dev, int port, return 0; } -static int ksz8_mdb_del(struct ksz_device *dev, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +int ksz8_mdb_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { struct alu_struct alu; int index; @@ -1049,8 +1046,8 @@ static int ksz8_mdb_del(struct ksz_device *dev, int port, return 0; } -static int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag, - struct netlink_ext_ack *extack) +int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag, + struct netlink_ext_ack *extack) { if (ksz_is_ksz88x3(dev)) return -ENOTSUPP; @@ -1076,9 +1073,9 @@ static void ksz8_port_enable_pvid(struct ksz_device *dev, int port, bool state) } } -static int ksz8_port_vlan_add(struct ksz_device *dev, int port, - const struct switchdev_obj_port_vlan *vlan, - struct netlink_ext_ack *extack) +int ksz8_port_vlan_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack) { bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; struct ksz_port *p = &dev->ports[port]; @@ -1148,8 +1145,8 @@ static int ksz8_port_vlan_add(struct ksz_device *dev, int port, return 0; } -static int ksz8_port_vlan_del(struct ksz_device *dev, int port, - const struct switchdev_obj_port_vlan *vlan) +int ksz8_port_vlan_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan) { u16 data, pvid; u8 fid, member, valid; @@ -1180,9 +1177,9 @@ static int ksz8_port_vlan_del(struct ksz_device *dev, int port, return 0; } -static int ksz8_port_mirror_add(struct ksz_device *dev, int port, - struct dsa_mall_mirror_tc_entry *mirror, - bool ingress, struct netlink_ext_ack *extack) +int ksz8_port_mirror_add(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack) { if (ingress) { ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, true); @@ -1202,8 +1199,8 @@ static int ksz8_port_mirror_add(struct ksz_device *dev, int port, return 0; } -static void ksz8_port_mirror_del(struct ksz_device *dev, int port, - struct dsa_mall_mirror_tc_entry *mirror) +void ksz8_port_mirror_del(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror) { u8 data; @@ -1270,7 +1267,7 @@ static void ksz8795_cpu_interface_select(struct ksz_device *dev, int port) p->phydev.duplex = 1; } -static void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) +void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) { struct dsa_switch *ds = dev->ds; struct ksz8 *ksz8 = dev->priv; @@ -1374,7 +1371,7 @@ static int ksz8_handle_global_errata(struct dsa_switch *ds) return ret; } -static int ksz8_setup(struct dsa_switch *ds) +int ksz8_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; struct alu_struct alu; @@ -1444,8 +1441,8 @@ static int ksz8_setup(struct dsa_switch *ds) return ksz8_handle_global_errata(ds); } -static void ksz8_get_caps(struct ksz_device *dev, int port, - struct phylink_config *config) +void ksz8_get_caps(struct ksz_device *dev, int port, + struct phylink_config *config) { config->mac_capabilities = MAC_10 | MAC_100; @@ -1462,12 +1459,12 @@ static void ksz8_get_caps(struct ksz_device *dev, int port, config->mac_capabilities |= MAC_ASYM_PAUSE; } -static u32 ksz8_get_port_addr(int port, int offset) +u32 ksz8_get_port_addr(int port, int offset) { return PORT_CTRL_ADDR(port, offset); } -static int ksz8_switch_init(struct ksz_device *dev) +int ksz8_switch_init(struct ksz_device *dev) { struct ksz8 *ksz8 = dev->priv; @@ -1498,47 +1495,11 @@ static int ksz8_switch_init(struct ksz_device *dev) return 0; } -static void ksz8_switch_exit(struct ksz_device *dev) +void ksz8_switch_exit(struct ksz_device *dev) { ksz8_reset_switch(dev); } -static const struct ksz_dev_ops ksz8_dev_ops = { - .setup = ksz8_setup, - .get_port_addr = ksz8_get_port_addr, - .cfg_port_member = ksz8_cfg_port_member, - .flush_dyn_mac_table = ksz8_flush_dyn_mac_table, - .port_setup = ksz8_port_setup, - .r_phy = ksz8_r_phy, - .w_phy = ksz8_w_phy, - .r_dyn_mac_table = ksz8_r_dyn_mac_table, - .r_sta_mac_table = ksz8_r_sta_mac_table, - .w_sta_mac_table = ksz8_w_sta_mac_table, - .r_mib_cnt = ksz8_r_mib_cnt, - .r_mib_pkt = ksz8_r_mib_pkt, - .freeze_mib = ksz8_freeze_mib, - .port_init_cnt = ksz8_port_init_cnt, - .fdb_dump = ksz8_fdb_dump, - .mdb_add = ksz8_mdb_add, - .mdb_del = ksz8_mdb_del, - .vlan_filtering = ksz8_port_vlan_filtering, - .vlan_add = ksz8_port_vlan_add, - .vlan_del = ksz8_port_vlan_del, - .mirror_add = ksz8_port_mirror_add, - .mirror_del = ksz8_port_mirror_del, - .get_stp_reg = ksz8_get_stp_reg, - .get_caps = ksz8_get_caps, - .shutdown = ksz8_reset_switch, - .init = ksz8_switch_init, - .exit = ksz8_switch_exit, -}; - -int ksz8_switch_register(struct ksz_device *dev) -{ - return ksz_switch_register(dev, &ksz8_dev_ops); -} -EXPORT_SYMBOL(ksz8_switch_register); - MODULE_AUTHOR("Tristram Ha "); MODULE_DESCRIPTION("Microchip KSZ8795 Series Switch DSA Driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/microchip/ksz8795_spi.c b/drivers/net/dsa/microchip/ksz8795_spi.c index 961a74c359a8..3a816661989c 100644 --- a/drivers/net/dsa/microchip/ksz8795_spi.c +++ b/drivers/net/dsa/microchip/ksz8795_spi.c @@ -82,7 +82,7 @@ static int ksz8795_spi_probe(struct spi_device *spi) if (ret) return ret; - ret = ksz8_switch_register(dev); + ret = ksz_switch_register(dev); /* Main DSA driver may not be started yet. */ if (ret) diff --git a/drivers/net/dsa/microchip/ksz8863_smi.c b/drivers/net/dsa/microchip/ksz8863_smi.c index b6f99e641dca..d71df05b8b7b 100644 --- a/drivers/net/dsa/microchip/ksz8863_smi.c +++ b/drivers/net/dsa/microchip/ksz8863_smi.c @@ -174,7 +174,7 @@ static int ksz8863_smi_probe(struct mdio_device *mdiodev) if (mdiodev->dev.platform_data) dev->pdata = mdiodev->dev.platform_data; - ret = ksz8_switch_register(dev); + ret = ksz_switch_register(dev); /* Main DSA driver may not be started yet. */ if (ret) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index c87ce0e2afd8..430dcbf48a46 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -17,6 +17,7 @@ #include "ksz9477_reg.h" #include "ksz_common.h" +#include "ksz9477.h" /* Used with variable features to indicate capabilities. */ #define GBIT_SUPPORT BIT(0) @@ -47,7 +48,7 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset, bits, set ? bits : 0); } -static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu) +int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu) { u16 frame_size, max_frame = 0; int i; @@ -64,7 +65,7 @@ static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu) REG_SW_MTU_MASK, max_frame); } -static int ksz9477_max_mtu(struct ksz_device *dev, int port) +int ksz9477_max_mtu(struct ksz_device *dev, int port) { return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN; } @@ -174,7 +175,7 @@ static int ksz9477_wait_alu_sta_ready(struct ksz_device *dev) 10, 1000); } -static int ksz9477_reset_switch(struct ksz_device *dev) +int ksz9477_reset_switch(struct ksz_device *dev) { u8 data8; u32 data32; @@ -213,8 +214,7 @@ static int ksz9477_reset_switch(struct ksz_device *dev) return 0; } -static void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, - u64 *cnt) +void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt) { struct ksz_port *p = &dev->ports[port]; unsigned int val; @@ -241,14 +241,14 @@ static void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, *cnt += data; } -static void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, - u64 *dropped, u64 *cnt) +void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, + u64 *dropped, u64 *cnt) { addr = dev->info->mib_names[addr].index; ksz9477_r_mib_cnt(dev, port, addr, cnt); } -static void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze) +void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze) { u32 val = freeze ? MIB_COUNTER_FLUSH_FREEZE : 0; struct ksz_port *p = &dev->ports[port]; @@ -262,7 +262,7 @@ static void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze) mutex_unlock(&p->mib.cnt_mutex); } -static void ksz9477_port_init_cnt(struct ksz_device *dev, int port) +void ksz9477_port_init_cnt(struct ksz_device *dev, int port) { struct ksz_port_mib *mib = &dev->ports[port].mib; @@ -275,7 +275,7 @@ static void ksz9477_port_init_cnt(struct ksz_device *dev, int port) mutex_unlock(&mib->cnt_mutex); } -static void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) +void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) { u16 val = 0xffff; @@ -324,7 +324,7 @@ static void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) *data = val; } -static void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) +void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) { /* No real PHY after this. */ if (addr >= dev->phy_port_cnt) @@ -337,18 +337,17 @@ static void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val); } -static void ksz9477_cfg_port_member(struct ksz_device *dev, int port, - u8 member) +void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member) { ksz_pwrite32(dev, port, REG_PORT_VLAN_MEMBERSHIP__4, member); } -static int ksz9477_get_stp_reg(void) +int ksz9477_get_stp_reg(void) { return P_STP_CTRL; } -static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) +void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) { u8 data; @@ -370,9 +369,8 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) } } -static int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port, - bool flag, - struct netlink_ext_ack *extack) +int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port, + bool flag, struct netlink_ext_ack *extack) { if (flag) { ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL, @@ -387,9 +385,9 @@ static int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port, return 0; } -static int ksz9477_port_vlan_add(struct ksz_device *dev, int port, - const struct switchdev_obj_port_vlan *vlan, - struct netlink_ext_ack *extack) +int ksz9477_port_vlan_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack) { u32 vlan_table[3]; bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; @@ -423,8 +421,8 @@ static int ksz9477_port_vlan_add(struct ksz_device *dev, int port, return 0; } -static int ksz9477_port_vlan_del(struct ksz_device *dev, int port, - const struct switchdev_obj_port_vlan *vlan) +int ksz9477_port_vlan_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan) { bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; u32 vlan_table[3]; @@ -456,9 +454,8 @@ static int ksz9477_port_vlan_del(struct ksz_device *dev, int port, return 0; } -static int ksz9477_fdb_add(struct ksz_device *dev, int port, - const unsigned char *addr, u16 vid, - struct dsa_db db) +int ksz9477_fdb_add(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, struct dsa_db db) { u32 alu_table[4]; u32 data; @@ -513,9 +510,8 @@ static int ksz9477_fdb_add(struct ksz_device *dev, int port, return ret; } -static int ksz9477_fdb_del(struct ksz_device *dev, int port, - const unsigned char *addr, u16 vid, - struct dsa_db db) +int ksz9477_fdb_del(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, struct dsa_db db) { u32 alu_table[4]; u32 data; @@ -603,8 +599,8 @@ static void ksz9477_convert_alu(struct alu_struct *alu, u32 *alu_table) alu->mac[5] = alu_table[3] & 0xFF; } -static int ksz9477_fdb_dump(struct ksz_device *dev, int port, - dsa_fdb_dump_cb_t *cb, void *data) +int ksz9477_fdb_dump(struct ksz_device *dev, int port, + dsa_fdb_dump_cb_t *cb, void *data) { int ret = 0; u32 ksz_data; @@ -654,9 +650,8 @@ static int ksz9477_fdb_dump(struct ksz_device *dev, int port, return ret; } -static int ksz9477_mdb_add(struct ksz_device *dev, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +int ksz9477_mdb_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { u32 static_table[4]; u32 data; @@ -729,9 +724,8 @@ static int ksz9477_mdb_add(struct ksz_device *dev, int port, return err; } -static int ksz9477_mdb_del(struct ksz_device *dev, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db) +int ksz9477_mdb_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { u32 static_table[4]; u32 data; @@ -804,9 +798,9 @@ static int ksz9477_mdb_del(struct ksz_device *dev, int port, return ret; } -static int ksz9477_port_mirror_add(struct ksz_device *dev, int port, - struct dsa_mall_mirror_tc_entry *mirror, - bool ingress, struct netlink_ext_ack *extack) +int ksz9477_port_mirror_add(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack) { u8 data; int p; @@ -843,8 +837,8 @@ static int ksz9477_port_mirror_add(struct ksz_device *dev, int port, return 0; } -static void ksz9477_port_mirror_del(struct ksz_device *dev, int port, - struct dsa_mall_mirror_tc_entry *mirror) +void ksz9477_port_mirror_del(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror) { bool in_use = false; u8 data; @@ -1067,14 +1061,14 @@ static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port) ksz9477_port_mmd_write(dev, port, 0x1c, 0x20, 0xeeee); } -static void ksz9477_get_caps(struct ksz_device *dev, int port, - struct phylink_config *config) +void ksz9477_get_caps(struct ksz_device *dev, int port, + struct phylink_config *config) { config->mac_capabilities = MAC_10 | MAC_100 | MAC_1000FD | MAC_ASYM_PAUSE | MAC_SYM_PAUSE; } -static void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port) +void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port) { struct ksz_port *p = &dev->ports[port]; struct dsa_switch *ds = dev->ds; @@ -1241,7 +1235,7 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds) } } -static int ksz9477_setup(struct dsa_switch *ds) +int ksz9477_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; int ret = 0; @@ -1293,12 +1287,12 @@ static int ksz9477_setup(struct dsa_switch *ds) return 0; } -static u32 ksz9477_get_port_addr(int port, int offset) +u32 ksz9477_get_port_addr(int port, int offset) { return PORT_CTRL_ADDR(port, offset); } -static int ksz9477_switch_init(struct ksz_device *dev) +int ksz9477_switch_init(struct ksz_device *dev) { u8 data8; int ret; @@ -1344,12 +1338,12 @@ static int ksz9477_switch_init(struct ksz_device *dev) return 0; } -static void ksz9477_switch_exit(struct ksz_device *dev) +void ksz9477_switch_exit(struct ksz_device *dev) { ksz9477_reset_switch(dev); } -static int ksz9477_dsa_init(struct ksz_device *dev) +int ksz9477_dsa_init(struct ksz_device *dev) { struct phy_device *phydev; int i; @@ -1373,45 +1367,6 @@ static int ksz9477_dsa_init(struct ksz_device *dev) return 0; } -static const struct ksz_dev_ops ksz9477_dev_ops = { - .setup = ksz9477_setup, - .get_port_addr = ksz9477_get_port_addr, - .cfg_port_member = ksz9477_cfg_port_member, - .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table, - .port_setup = ksz9477_port_setup, - .r_phy = ksz9477_r_phy, - .w_phy = ksz9477_w_phy, - .r_mib_cnt = ksz9477_r_mib_cnt, - .r_mib_pkt = ksz9477_r_mib_pkt, - .r_mib_stat64 = ksz_r_mib_stats64, - .freeze_mib = ksz9477_freeze_mib, - .port_init_cnt = ksz9477_port_init_cnt, - .vlan_filtering = ksz9477_port_vlan_filtering, - .vlan_add = ksz9477_port_vlan_add, - .vlan_del = ksz9477_port_vlan_del, - .mirror_add = ksz9477_port_mirror_add, - .mirror_del = ksz9477_port_mirror_del, - .get_stp_reg = ksz9477_get_stp_reg, - .get_caps = ksz9477_get_caps, - .fdb_dump = ksz9477_fdb_dump, - .fdb_add = ksz9477_fdb_add, - .fdb_del = ksz9477_fdb_del, - .mdb_add = ksz9477_mdb_add, - .mdb_del = ksz9477_mdb_del, - .change_mtu = ksz9477_change_mtu, - .max_mtu = ksz9477_max_mtu, - .shutdown = ksz9477_reset_switch, - .dsa_init = ksz9477_dsa_init, - .init = ksz9477_switch_init, - .exit = ksz9477_switch_exit, -}; - -int ksz9477_switch_register(struct ksz_device *dev) -{ - return ksz_switch_register(dev, &ksz9477_dev_ops); -} -EXPORT_SYMBOL(ksz9477_switch_register); - MODULE_AUTHOR("Woojung Huh "); MODULE_DESCRIPTION("Microchip KSZ9477 Series Switch DSA Driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h new file mode 100644 index 000000000000..feb5464e8c2b --- /dev/null +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Microchip KSZ9477 series Header file + * + * Copyright (C) 2017-2022 Microchip Technology Inc. + */ + +#ifndef __KSZ9477_H +#define __KSZ9477_H + +#include +#include "ksz_common.h" + +int ksz9477_setup(struct dsa_switch *ds); +u32 ksz9477_get_port_addr(int port, int offset); +void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member); +void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port); +void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port); +void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data); +void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val); +void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt); +void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, + u64 *dropped, u64 *cnt); +void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze); +void ksz9477_port_init_cnt(struct ksz_device *dev, int port); +int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port, + bool flag, struct netlink_ext_ack *extack); +int ksz9477_port_vlan_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack); +int ksz9477_port_vlan_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_vlan *vlan); +int ksz9477_port_mirror_add(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack); +void ksz9477_port_mirror_del(struct ksz_device *dev, int port, + struct dsa_mall_mirror_tc_entry *mirror); +int ksz9477_get_stp_reg(void); +void ksz9477_get_caps(struct ksz_device *dev, int port, + struct phylink_config *config); +int ksz9477_fdb_dump(struct ksz_device *dev, int port, + dsa_fdb_dump_cb_t *cb, void *data); +int ksz9477_fdb_add(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, struct dsa_db db); +int ksz9477_fdb_del(struct ksz_device *dev, int port, + const unsigned char *addr, u16 vid, struct dsa_db db); +int ksz9477_mdb_add(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); +int ksz9477_mdb_del(struct ksz_device *dev, int port, + const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); +int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu); +int ksz9477_max_mtu(struct ksz_device *dev, int port); +int ksz9477_reset_switch(struct ksz_device *dev); +int ksz9477_dsa_init(struct ksz_device *dev); +int ksz9477_switch_init(struct ksz_device *dev); +void ksz9477_switch_exit(struct ksz_device *dev); + +#endif diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c index faa3163c86b0..984fe5df1643 100644 --- a/drivers/net/dsa/microchip/ksz9477_i2c.c +++ b/drivers/net/dsa/microchip/ksz9477_i2c.c @@ -41,7 +41,7 @@ static int ksz9477_i2c_probe(struct i2c_client *i2c, if (i2c->dev.platform_data) dev->pdata = i2c->dev.platform_data; - ret = ksz9477_switch_register(dev); + ret = ksz_switch_register(dev); /* Main DSA driver may not be started yet. */ if (ret) diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c index 1bc8b0cbe458..2ee0601bc014 100644 --- a/drivers/net/dsa/microchip/ksz9477_spi.c +++ b/drivers/net/dsa/microchip/ksz9477_spi.c @@ -54,7 +54,7 @@ static int ksz9477_spi_probe(struct spi_device *spi) if (ret) return ret; - ret = ksz9477_switch_register(dev); + ret = ksz_switch_register(dev); /* Main DSA driver may not be started yet. */ if (ret) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 8f852649c217..44d62ceff427 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -21,6 +21,8 @@ #include #include "ksz_common.h" +#include "ksz8.h" +#include "ksz9477.h" #define MIB_COUNTER_NUM 0x20 @@ -139,6 +141,69 @@ static const struct ksz_mib_names ksz9477_mib_names[] = { { 0x83, "tx_discards" }, }; +static const struct ksz_dev_ops ksz8_dev_ops = { + .setup = ksz8_setup, + .get_port_addr = ksz8_get_port_addr, + .cfg_port_member = ksz8_cfg_port_member, + .flush_dyn_mac_table = ksz8_flush_dyn_mac_table, + .port_setup = ksz8_port_setup, + .r_phy = ksz8_r_phy, + .w_phy = ksz8_w_phy, + .r_dyn_mac_table = ksz8_r_dyn_mac_table, + .r_sta_mac_table = ksz8_r_sta_mac_table, + .w_sta_mac_table = ksz8_w_sta_mac_table, + .r_mib_cnt = ksz8_r_mib_cnt, + .r_mib_pkt = ksz8_r_mib_pkt, + .freeze_mib = ksz8_freeze_mib, + .port_init_cnt = ksz8_port_init_cnt, + .fdb_dump = ksz8_fdb_dump, + .mdb_add = ksz8_mdb_add, + .mdb_del = ksz8_mdb_del, + .vlan_filtering = ksz8_port_vlan_filtering, + .vlan_add = ksz8_port_vlan_add, + .vlan_del = ksz8_port_vlan_del, + .mirror_add = ksz8_port_mirror_add, + .mirror_del = ksz8_port_mirror_del, + .get_stp_reg = ksz8_get_stp_reg, + .get_caps = ksz8_get_caps, + .shutdown = ksz8_reset_switch, + .init = ksz8_switch_init, + .exit = ksz8_switch_exit, +}; + +static const struct ksz_dev_ops ksz9477_dev_ops = { + .setup = ksz9477_setup, + .get_port_addr = ksz9477_get_port_addr, + .cfg_port_member = ksz9477_cfg_port_member, + .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table, + .port_setup = ksz9477_port_setup, + .r_phy = ksz9477_r_phy, + .w_phy = ksz9477_w_phy, + .r_mib_cnt = ksz9477_r_mib_cnt, + .r_mib_pkt = ksz9477_r_mib_pkt, + .r_mib_stat64 = ksz_r_mib_stats64, + .freeze_mib = ksz9477_freeze_mib, + .port_init_cnt = ksz9477_port_init_cnt, + .vlan_filtering = ksz9477_port_vlan_filtering, + .vlan_add = ksz9477_port_vlan_add, + .vlan_del = ksz9477_port_vlan_del, + .mirror_add = ksz9477_port_mirror_add, + .mirror_del = ksz9477_port_mirror_del, + .get_stp_reg = ksz9477_get_stp_reg, + .get_caps = ksz9477_get_caps, + .fdb_dump = ksz9477_fdb_dump, + .fdb_add = ksz9477_fdb_add, + .fdb_del = ksz9477_fdb_del, + .mdb_add = ksz9477_mdb_add, + .mdb_del = ksz9477_mdb_del, + .change_mtu = ksz9477_change_mtu, + .max_mtu = ksz9477_max_mtu, + .shutdown = ksz9477_reset_switch, + .dsa_init = ksz9477_dsa_init, + .init = ksz9477_switch_init, + .exit = ksz9477_switch_exit, +}; + const struct ksz_chip_data ksz_switch_chips[] = { [KSZ8795] = { .chip_id = KSZ8795_CHIP_ID, @@ -148,6 +213,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 8, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ + .ops = &ksz8_dev_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names, .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), @@ -180,6 +246,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 8, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ + .ops = &ksz8_dev_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names, .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), @@ -198,6 +265,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 8, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ + .ops = &ksz8_dev_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names, .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), @@ -216,6 +284,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 8, .cpu_ports = 0x4, /* can be configured as cpu port */ .port_cnt = 3, + .ops = &ksz8_dev_ops, .mib_names = ksz88xx_mib_names, .mib_cnt = ARRAY_SIZE(ksz88xx_mib_names), .reg_mib_cnt = MIB_COUNTER_NUM, @@ -232,6 +301,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 16, .cpu_ports = 0x7F, /* can be configured as cpu port */ .port_cnt = 7, /* total physical port count */ + .ops = &ksz9477_dev_ops, .phy_errata_9477 = true, .mib_names = ksz9477_mib_names, .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), @@ -254,6 +324,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 16, .cpu_ports = 0x7F, /* can be configured as cpu port */ .port_cnt = 7, /* total physical port count */ + .ops = &ksz9477_dev_ops, .phy_errata_9477 = true, .mib_names = ksz9477_mib_names, .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), @@ -276,6 +347,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 16, .cpu_ports = 0x07, /* can be configured as cpu port */ .port_cnt = 3, /* total port count */ + .ops = &ksz9477_dev_ops, .mib_names = ksz9477_mib_names, .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .reg_mib_cnt = MIB_COUNTER_NUM, @@ -293,6 +365,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .num_statics = 16, .cpu_ports = 0x7F, /* can be configured as cpu port */ .port_cnt = 7, /* total physical port count */ + .ops = &ksz9477_dev_ops, .phy_errata_9477 = true, .mib_names = ksz9477_mib_names, .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), @@ -1130,8 +1203,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) } EXPORT_SYMBOL(ksz_switch_alloc); -int ksz_switch_register(struct ksz_device *dev, - const struct ksz_dev_ops *ops) +int ksz_switch_register(struct ksz_device *dev) { const struct ksz_chip_data *info; struct device_node *port, *ports; @@ -1178,7 +1250,7 @@ int ksz_switch_register(struct ksz_device *dev, if (ret) return ret; - dev->dev_ops = ops; + dev->dev_ops = dev->info->ops; ret = dev->dev_ops->init(dev); if (ret) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 23962f47df46..dbd194e4039a 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -41,6 +41,7 @@ struct ksz_chip_data { int num_statics; int cpu_ports; int port_cnt; + const struct ksz_dev_ops *ops; bool phy_errata_9477; bool ksz87xx_eee_link_erratum; const struct ksz_mib_names *mib_names; @@ -219,13 +220,9 @@ struct ksz_dev_ops { }; struct ksz_device *ksz_switch_alloc(struct device *base, void *priv); -int ksz_switch_register(struct ksz_device *dev, - const struct ksz_dev_ops *ops); +int ksz_switch_register(struct ksz_device *dev); void ksz_switch_remove(struct ksz_device *dev); -int ksz8_switch_register(struct ksz_device *dev); -int ksz9477_switch_register(struct ksz_device *dev); - void ksz_init_mib_timer(struct ksz_device *dev); void ksz_r_mib_stats64(struct ksz_device *dev, int port); void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state); From patchwork Mon May 30 10:42:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12864520 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A932C433EF for ; Mon, 30 May 2022 10:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235367AbiE3Kpe (ORCPT ); Mon, 30 May 2022 06:45:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235560AbiE3KpN (ORCPT ); Mon, 30 May 2022 06:45:13 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DC997CB28; Mon, 30 May 2022 03:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1653907506; x=1685443506; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oSaXWSwiwW3AyXGv4J1904kAivyPS9dvImVl4oEtyzg=; b=bcoa+wR46/pSt7HH09StznHs2fQTVI1B8/XgWw0CECsb5lPXuSzDWTjB vNPWLuDBLPuHcGJh7CuCA8OF1xBgbfwU5Tb+PV7OMuj8eOyHns9t8HN9P Cnkh3fdc1DPSnwiwxngoZKhm/G/pcQ5O2OGVs2ZqtYm8GdHFnVJDbagku noIjpx1khrKFlUmb5RKvcXhMLIE5rgpUmiirvE9qcUJJoWKYgpsDyq9aR FblEQ1fQRne5GUYkdSuCJqtDp19n5xwzbl7yAlgK6jR5tP3Xvn2oRNi6J 5E85+dNxOa69Yr/ZWcCbGRyqbfrN7DHY1sTVoS4RADkzrxfGX2EZIKydv Q==; X-IronPort-AV: E=Sophos;i="5.91,262,1647327600"; d="scan'208";a="161124812" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2022 03:45:05 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 30 May 2022 03:45:05 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 30 May 2022 03:45:00 -0700 From: Arun Ramadoss To: , CC: Woojung Huh , , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King" Subject: [RFC Patch net-next v2 15/15] net: dsa: microchip: common ksz_spi_probe for ksz switches Date: Mon, 30 May 2022 16:12:57 +0530 Message-ID: <20220530104257.21485-16-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530104257.21485-1-arun.ramadoss@microchip.com> References: <20220530104257.21485-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC As of now, there are two spi probes, one ksz8795_spi.c and other ksz9477_spi.c. This patch combines two files into single ksz_spi.c. The difference between the two are regmap config and struct ksz8. The regmap config is assigned based on the platform data. And struct ksz8 is left untouched, as it is used only ksz8795.c. It can be used for all other switches also in future. Signed-off-by: Arun Ramadoss --- drivers/net/dsa/microchip/Kconfig | 16 +- drivers/net/dsa/microchip/Makefile | 3 +- drivers/net/dsa/microchip/ksz9477_spi.c | 150 ------------------ .../microchip/{ksz8795_spi.c => ksz_spi.c} | 83 +++++++--- 4 files changed, 69 insertions(+), 183 deletions(-) delete mode 100644 drivers/net/dsa/microchip/ksz9477_spi.c rename drivers/net/dsa/microchip/{ksz8795_spi.c => ksz_spi.c} (61%) diff --git a/drivers/net/dsa/microchip/Kconfig b/drivers/net/dsa/microchip/Kconfig index d21ff069e5aa..2edb88080790 100644 --- a/drivers/net/dsa/microchip/Kconfig +++ b/drivers/net/dsa/microchip/Kconfig @@ -8,29 +8,19 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON KSZ8795/KSZ88x3 switch chips. config NET_DSA_MICROCHIP_KSZ9477_I2C - tristate "KSZ9477 series I2C connected switch driver" + tristate "KSZ series I2C connected switch driver" depends on NET_DSA_MICROCHIP_KSZ_COMMON && I2C select REGMAP_I2C help Select to enable support for registering switches configured through I2C. -config NET_DSA_MICROCHIP_KSZ9477_SPI - tristate "KSZ9477 series SPI connected switch driver" +config NET_DSA_MICROCHIP_KSZ_SPI + tristate "KSZ series SPI connected switch driver" depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI select REGMAP_SPI help Select to enable support for registering switches configured through SPI. -config NET_DSA_MICROCHIP_KSZ8795_SPI - tristate "KSZ8795 series SPI connected switch driver" - depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI - select REGMAP_SPI - help - This driver accesses KSZ8795 chip through SPI. - - It is required to use the KSZ8795 switch driver as the only access - is through SPI. - config NET_DSA_MICROCHIP_KSZ8863_SMI tristate "KSZ series SMI connected switch driver" depends on NET_DSA_MICROCHIP_KSZ_COMMON diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip/Makefile index 4cf4755e6426..b2ba7c1bcb93 100644 --- a/drivers/net/dsa/microchip/Makefile +++ b/drivers/net/dsa/microchip/Makefile @@ -4,6 +4,5 @@ ksz_switch-objs := ksz_common.o ksz_switch-objs += ksz9477.o ksz_switch-objs += ksz8795.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o -obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI) += ksz9477_spi.o -obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795_SPI) += ksz8795_spi.o +obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI) += ksz_spi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c deleted file mode 100644 index 2ee0601bc014..000000000000 --- a/drivers/net/dsa/microchip/ksz9477_spi.c +++ /dev/null @@ -1,150 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Microchip KSZ9477 series register access through SPI - * - * Copyright (C) 2017-2019 Microchip Technology Inc. - */ - -#include - -#include -#include -#include -#include -#include - -#include "ksz_common.h" - -#define SPI_ADDR_SHIFT 24 -#define SPI_ADDR_ALIGN 3 -#define SPI_TURNAROUND_SHIFT 5 - -KSZ_REGMAP_TABLE(ksz9477, 32, SPI_ADDR_SHIFT, - SPI_TURNAROUND_SHIFT, SPI_ADDR_ALIGN); - -static int ksz9477_spi_probe(struct spi_device *spi) -{ - struct regmap_config rc; - struct ksz_device *dev; - int i, ret; - - dev = ksz_switch_alloc(&spi->dev, spi); - if (!dev) - return -ENOMEM; - - for (i = 0; i < ARRAY_SIZE(ksz9477_regmap_config); i++) { - rc = ksz9477_regmap_config[i]; - rc.lock_arg = &dev->regmap_mutex; - dev->regmap[i] = devm_regmap_init_spi(spi, &rc); - if (IS_ERR(dev->regmap[i])) { - ret = PTR_ERR(dev->regmap[i]); - dev_err(&spi->dev, - "Failed to initialize regmap%i: %d\n", - ksz9477_regmap_config[i].val_bits, ret); - return ret; - } - } - - if (spi->dev.platform_data) - dev->pdata = spi->dev.platform_data; - - /* setup spi */ - spi->mode = SPI_MODE_3; - ret = spi_setup(spi); - if (ret) - return ret; - - ret = ksz_switch_register(dev); - - /* Main DSA driver may not be started yet. */ - if (ret) - return ret; - - spi_set_drvdata(spi, dev); - - return 0; -} - -static void ksz9477_spi_remove(struct spi_device *spi) -{ - struct ksz_device *dev = spi_get_drvdata(spi); - - if (dev) - ksz_switch_remove(dev); - - spi_set_drvdata(spi, NULL); -} - -static void ksz9477_spi_shutdown(struct spi_device *spi) -{ - struct ksz_device *dev = spi_get_drvdata(spi); - - if (dev) - dsa_switch_shutdown(dev->ds); - - spi_set_drvdata(spi, NULL); -} - -static const struct of_device_id ksz9477_dt_ids[] = { - { - .compatible = "microchip,ksz9477", - .data = &ksz_switch_chips[KSZ9477] - }, - { - .compatible = "microchip,ksz9897", - .data = &ksz_switch_chips[KSZ9897] - }, - { - .compatible = "microchip,ksz9893", - .data = &ksz_switch_chips[KSZ9893] - }, - { - .compatible = "microchip,ksz9563", - .data = &ksz_switch_chips[KSZ9893] - }, - { - .compatible = "microchip,ksz8563", - .data = &ksz_switch_chips[KSZ9893] - }, - { - .compatible = "microchip,ksz9567", - .data = &ksz_switch_chips[KSZ9567] - }, - {}, -}; -MODULE_DEVICE_TABLE(of, ksz9477_dt_ids); - -static const struct spi_device_id ksz9477_spi_ids[] = { - { "ksz9477" }, - { "ksz9897" }, - { "ksz9893" }, - { "ksz9563" }, - { "ksz8563" }, - { "ksz9567" }, - { }, -}; -MODULE_DEVICE_TABLE(spi, ksz9477_spi_ids); - -static struct spi_driver ksz9477_spi_driver = { - .driver = { - .name = "ksz9477-switch", - .owner = THIS_MODULE, - .of_match_table = of_match_ptr(ksz9477_dt_ids), - }, - .id_table = ksz9477_spi_ids, - .probe = ksz9477_spi_probe, - .remove = ksz9477_spi_remove, - .shutdown = ksz9477_spi_shutdown, -}; - -module_spi_driver(ksz9477_spi_driver); - -MODULE_ALIAS("spi:ksz9477"); -MODULE_ALIAS("spi:ksz9897"); -MODULE_ALIAS("spi:ksz9893"); -MODULE_ALIAS("spi:ksz9563"); -MODULE_ALIAS("spi:ksz8563"); -MODULE_ALIAS("spi:ksz9567"); -MODULE_AUTHOR("Woojung Huh "); -MODULE_DESCRIPTION("Microchip KSZ9477 Series Switch SPI access Driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/microchip/ksz8795_spi.c b/drivers/net/dsa/microchip/ksz_spi.c similarity index 61% rename from drivers/net/dsa/microchip/ksz8795_spi.c rename to drivers/net/dsa/microchip/ksz_spi.c index 3a816661989c..baec2fbf9537 100644 --- a/drivers/net/dsa/microchip/ksz8795_spi.c +++ b/drivers/net/dsa/microchip/ksz_spi.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Microchip KSZ8795 series register access through SPI + * Microchip ksz series register access through SPI * * Copyright (C) 2017 Microchip Technology Inc. * Tristram Ha @@ -25,13 +25,20 @@ #define KSZ8863_SPI_ADDR_ALIGN 8 #define KSZ8863_SPI_TURNAROUND_SHIFT 0 +#define KSZ9477_SPI_ADDR_SHIFT 24 +#define KSZ9477_SPI_ADDR_ALIGN 3 +#define KSZ9477_SPI_TURNAROUND_SHIFT 5 + KSZ_REGMAP_TABLE(ksz8795, 16, KSZ8795_SPI_ADDR_SHIFT, KSZ8795_SPI_TURNAROUND_SHIFT, KSZ8795_SPI_ADDR_ALIGN); KSZ_REGMAP_TABLE(ksz8863, 16, KSZ8863_SPI_ADDR_SHIFT, KSZ8863_SPI_TURNAROUND_SHIFT, KSZ8863_SPI_ADDR_ALIGN); -static int ksz8795_spi_probe(struct spi_device *spi) +KSZ_REGMAP_TABLE(ksz9477, 32, KSZ9477_SPI_ADDR_SHIFT, + KSZ9477_SPI_TURNAROUND_SHIFT, KSZ9477_SPI_ADDR_ALIGN); + +static int ksz_spi_probe(struct spi_device *spi) { const struct regmap_config *regmap_config; const struct ksz_chip_data *chip; @@ -57,8 +64,12 @@ static int ksz8795_spi_probe(struct spi_device *spi) if (chip->chip_id == KSZ8830_CHIP_ID) regmap_config = ksz8863_regmap_config; - else + else if (chip->chip_id == KSZ8795_CHIP_ID || + chip->chip_id == KSZ8794_CHIP_ID || + chip->chip_id == KSZ8765_CHIP_ID) regmap_config = ksz8795_regmap_config; + else + regmap_config = ksz9477_regmap_config; for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) { rc = regmap_config[i]; @@ -93,7 +104,7 @@ static int ksz8795_spi_probe(struct spi_device *spi) return 0; } -static void ksz8795_spi_remove(struct spi_device *spi) +static void ksz_spi_remove(struct spi_device *spi) { struct ksz_device *dev = spi_get_drvdata(spi); @@ -103,7 +114,7 @@ static void ksz8795_spi_remove(struct spi_device *spi) spi_set_drvdata(spi, NULL); } -static void ksz8795_spi_shutdown(struct spi_device *spi) +static void ksz_spi_shutdown(struct spi_device *spi) { struct ksz_device *dev = spi_get_drvdata(spi); @@ -118,7 +129,7 @@ static void ksz8795_spi_shutdown(struct spi_device *spi) spi_set_drvdata(spi, NULL); } -static const struct of_device_id ksz8795_dt_ids[] = { +static const struct of_device_id ksz_dt_ids[] = { { .compatible = "microchip,ksz8765", .data = &ksz_switch_chips[KSZ8765] @@ -139,34 +150,70 @@ static const struct of_device_id ksz8795_dt_ids[] = { .compatible = "microchip,ksz8873", .data = &ksz_switch_chips[KSZ8830] }, + { + .compatible = "microchip,ksz9477", + .data = &ksz_switch_chips[KSZ9477] + }, + { + .compatible = "microchip,ksz9897", + .data = &ksz_switch_chips[KSZ9897] + }, + { + .compatible = "microchip,ksz9893", + .data = &ksz_switch_chips[KSZ9893] + }, + { + .compatible = "microchip,ksz9563", + .data = &ksz_switch_chips[KSZ9893] + }, + { + .compatible = "microchip,ksz8563", + .data = &ksz_switch_chips[KSZ9893] + }, + { + .compatible = "microchip,ksz9567", + .data = &ksz_switch_chips[KSZ9567] + }, {}, }; -MODULE_DEVICE_TABLE(of, ksz8795_dt_ids); +MODULE_DEVICE_TABLE(of, ksz_dt_ids); -static const struct spi_device_id ksz8795_spi_ids[] = { +static const struct spi_device_id ksz_spi_ids[] = { { "ksz8765" }, { "ksz8794" }, { "ksz8795" }, { "ksz8863" }, { "ksz8873" }, + { "ksz9477" }, + { "ksz9897" }, + { "ksz9893" }, + { "ksz9563" }, + { "ksz8563" }, + { "ksz9567" }, { }, }; -MODULE_DEVICE_TABLE(spi, ksz8795_spi_ids); +MODULE_DEVICE_TABLE(spi, ksz_spi_ids); -static struct spi_driver ksz8795_spi_driver = { +static struct spi_driver ksz_spi_driver = { .driver = { - .name = "ksz8795-switch", + .name = "ksz-switch", .owner = THIS_MODULE, - .of_match_table = of_match_ptr(ksz8795_dt_ids), + .of_match_table = of_match_ptr(ksz_dt_ids), }, - .id_table = ksz8795_spi_ids, - .probe = ksz8795_spi_probe, - .remove = ksz8795_spi_remove, - .shutdown = ksz8795_spi_shutdown, + .id_table = ksz_spi_ids, + .probe = ksz_spi_probe, + .remove = ksz_spi_remove, + .shutdown = ksz_spi_shutdown, }; -module_spi_driver(ksz8795_spi_driver); +module_spi_driver(ksz_spi_driver); +MODULE_ALIAS("spi:ksz9477"); +MODULE_ALIAS("spi:ksz9897"); +MODULE_ALIAS("spi:ksz9893"); +MODULE_ALIAS("spi:ksz9563"); +MODULE_ALIAS("spi:ksz8563"); +MODULE_ALIAS("spi:ksz9567"); MODULE_AUTHOR("Tristram Ha "); -MODULE_DESCRIPTION("Microchip KSZ8795 Series Switch SPI Driver"); +MODULE_DESCRIPTION("Microchip ksz Series Switch SPI Driver"); MODULE_LICENSE("GPL");