net: dsa: microchip: DSA driver support for LAN937x switch
Subsystems (5)
v10 cover net: dsa: microchip: DSA driver support for LAN937x switch
LAN937x is a Multi-Port 100BASE-T1 Ethernet Physical Layer switch compliant with the IEEE 802.3bw-2015 specification. The device provides 100 Mbit/s transmit and receive capability over a single Unshielded Twisted Pair (UTP) cable. LAN937x is successive revision of KSZ series switch. This series of patches provide the DSA driver support for Microchip LAN937X switch and it configures through SPI interface.
This driver shares some of the functions from KSZ common layer.
The LAN937x switch series family consists of following SKUs:
LAN9370:
- 4 T1 Phys
- 1 RGMII port
LAN9371:
- 3 T1 Phys & 1 TX Phy
- 2 RGMII ports
LAN9372:
- 5 T1 Phys & 1 TX Phy
- 2 RGMII ports
LAN9373:
- 5 T1 Phys
- 2 RGMII & 1 SGMII port
LAN9374:
- 6 T1 Phys
- 2 RGMII ports
More support will be added at a later stage.
Changes in v10:
- dsa.yaml: dropped moving mdio properties to dsa.yaml as per the feedback
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/#24787466
- microchip,lan937x.yaml: Naming convention changes in the example
- lan937x_main.c: Moving configurations from lan937x_reset_switch() to setup()
- lan937x_main.c: helper function has been introduced for lan937x_internal_phy_read & write
- lan937x_dev.h: lan_alu_struct struct data type changes
- lan937x_main.c: lan937x_get_stats64 make non blocking
- lan937x_main.c: modified lan937x_port_mirror_add to include extack
Changes in v9:
- lan937x_main.c: of_node_put() correction in lan937x_parse_dt_rgmii_delay
- lan937x_dev.c: removed the interface checks from lan937x_apply_rgmii_delay.
- changes in ethernet-controller.yaml and dsa.yaml
Changes in v8:
- lan937x_dev.c: fixed lan937x_r_mib_pkt warning in the sub patches
- lan937x_main.c: phylink_autoneg_inband() check removed in lan937x_phylink_mac_link_up()
- lan937x_main.c: made legacy_pre_march2020 = false as this is non-legacy driver and indentation correction in lan937x_phylink_mac_link_up()
- removed unnecessary parenthesis in lan937x_get_strings()
Changes in v7:
- microchip,lan937x.yaml: *-internal-delay-ps enum values & commit messages corrections
- lan937x_main.c: removed phylink_validate() and added phylink_get_caps()
- lan937x_main.c: added support for ethtool standard stats (get_eth_*_stats
and get_stats64)
- lan937x_main.c: removed unnecessary PVID read from lan937x_port_vlan_del()
- integrated the changes of ksz9477 multi bridging support to lan937x dev and tested both multi bridging and STP
- lan937x_port_vlan_del - dummy pvid read removed
Changes in v6:
- microchip_t1.c: There was new merge done in the net-next tree for microchip_1.c after the v5 submission. Hence rebased it for v6.
Changes in v5:
- microchip,lan937x.yaml: Added mdio properties detail
- microchip,lan937x.yaml: *-internal-delay-ps added under port node
- lan937x_dev.c: changed devm_mdiobus_alloc from of_mdiobus_register as suggested by Vladimir
- lan937x_dev.c: added dev_info for rgmii internal delay & error message to user in case of out of range values
- lan937x_dev.c: return -EOPNOTSUPP for C45 regnum values for lan937x_sw_mdio_read & write operations
- return from function with out storing in a variable
- lan937x_main.c: Added vlan_enable info in vlan_filtering API
- lan937x_main.c: lan937x_port_vlan_del: removed unintended PVID write
Changes in v4:
- tag_ksz.c: cpu_to_be16 to put_unaligned_be16
- correct spacing in comments
- tag_ksz.c: NETIF_F_HW_CSUM fix is integrated
- lan937x_dev.c: mdio_np is removed from global and handled locally
- lan937x_dev.c: unused functions removed lan937x_cfg32 & lan937x_port_cfg32
- lan937x_dev.c: lan937x_is_internal_100BTX_phy_port function name changes
- lan937x_dev.c: RGMII internal delay handling for MAC. Delay values are retrieved from DTS and updated
- lan937x_dev.c: corrected mutex operations for few dev variables
- microchip,lan937x.yaml: introduced rx-internal-delay-ps & tx-internal-delay-ps for RGMII internal delay
- lan937x_dev.c: Unnecessary mutex_lock has been removed
- lan937x_main.c: PHY_INTERFACE_MODE_NA handling for lan937x_phylink_validate
- lan937x_main.c: PORT_MIRROR_SNIFFER check in right place
- lan937x_main.c: memset is used instead of writing 0's individually in lan937x_port_fdb_add function
- lan937x_main.c: Removed \n from NL_SET_ERR_MSG_MOD calls
Changes in v3:
- Removed settings of cnt_ptr to zero and the memset() added a cleanup patch which moves this into ksz_init_mib_timer().
- Used ret everywhere instead of rc
- microchip,lan937x.yaml: Remove mdio compatible
- microchip_t1.c: Renaming standard phy registers
- tag_ksz.c: LAN937X_TAIL_TAG_OVERRIDE renaming LAN937X_TAIL_TAG_BLOCKING_OVERRIDE
- tag_ksz.c: Changed Ingress and Egress naming convention based on Host
- tag_ksz.c: converted to skb_mac_header(skb) from (is_link_local_ether_addr(hdr->h_dest))
- lan937x_dev.c: Removed BCAST Storm protection settings since we have Tc commands for them
- lan937x_dev.c: Flow control setting in lan937x_port_setup function
- lan937x_dev.c: RGMII internal delay added only for cpu port,
- lan937x_dev.c: of_get_compatible_child(node, "microchip,lan937x-mdio") to of_get_child_by_name(node, "mdio");
- lan937x_dev.c:lan937x_get_interface API: returned PHY_INTERFACE_MODE_INTERNAL instead of PHY_INTERFACE_MODE_NA
- lan937x_main.c: Removed compat interface implementation in lan937x_config_cpu_port() API & dev_info corrected as well
- lan937x_main.c: deleted ds->configure_vlan_while_not_filtering = true
- lan937x_main.c: Added explanation for lan937x_setup lines
- lan937x_main.c: FR_MAX_SIZE correction in lan937x_get_max_mtu API
- lan937x_main.c: removed lan937x_port_bridge_flags dummy functions
- lan937x_spi.c - mdiobus_unregister to be added to spi_remove function
- lan937x_main.c: phy link layer changes
- lan937x_main.c: port mirroring: sniff port selection limiting to one port
- lan937x_main.c: Changed to global vlan filtering
- lan937x_main.c: vlan_table array to structure
- lan937x_main.c -Use extack instead of reporting errors to Console
- lan937x_main.c - Remove cpu_port addition in vlan_add api
- lan937x_main.c - removed pvid resetting
Changes in v2:
- return check for register read/writes
- dt compatible compatible check is added against chip id value
- lan937x_internal_t1_tx_phy_write() is renamed to lan937x_internal_phy_write()
- lan937x_is_internal_tx_phy_port is renamed to lan937x_is_internal_100BTX_phy_port as it is 100Base-Tx phy
- Return value for lan937x_internal_phy_write() is -EOPNOTSUPP in case of failures
- Return value for lan937x_internal_phy_read() is 0xffff for non existent phy
- cpu_port checking is removed from lan937x_port_stp_state_set()
- lan937x_phy_link_validate: 100baseT_Full to 100baseT1_Full
- T1 Phy driver is moved to drivers/net/phy/microchip_t1.c
- Tx phy driver support will be added later
- Legacy switch checkings in dts file are removed.
- tag_ksz.c: Re-used ksz9477_rcv for lan937x_rcv
- tag_ksz.c: Xmit() & rcv() Comments are corrected w.r.to host
- net/dsa/Kconfig: Family skew numbers altered in ascending order
- microchip,lan937x.yaml: eth is replaced with ethernet
- microchip,lan937x.yaml: spi1 is replaced with spi
- microchip,lan937x.yaml: cpu labelling is removed
- microchip,lan937x.yaml: port@x value will match the reg value now
Prasanna Vengateshan (10):
dt-bindings: net: make internal-delay-ps based on phy-mode
dt-bindings: net: dsa: dt bindings for microchip lan937x
net: dsa: move mib->cnt_ptr reset code to ksz_common.c
net: dsa: tag_ksz: add tag handling for Microchip LAN937x
net: dsa: microchip: add DSA support for microchip lan937x
net: dsa: microchip: add support for phylink management
net: dsa: microchip: add support for ethtool port counters
net: dsa: microchip: add support for port mirror operations
net: dsa: microchip: add support for fdb and mdb management
net: dsa: microchip: add support for vlan operations
.../bindings/net/dsa/microchip,lan937x.yaml | 160 ++ .../bindings/net/ethernet-controller.yaml | 37 +- MAINTAINERS | 1 + drivers/net/dsa/microchip/Kconfig | 12 + drivers/net/dsa/microchip/Makefile | 5 + drivers/net/dsa/microchip/ksz8795.c | 2 - drivers/net/dsa/microchip/ksz9477.c | 3 - drivers/net/dsa/microchip/ksz_common.c | 8 +- drivers/net/dsa/microchip/ksz_common.h | 5 + drivers/net/dsa/microchip/lan937x_dev.c | 789 ++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 122 ++ drivers/net/dsa/microchip/lan937x_main.c | 1288 +++++++++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 688 +++++++++ drivers/net/dsa/microchip/lan937x_spi.c | 236 +++ include/net/dsa.h | 2 + net/dsa/Kconfig | 4 +- net/dsa/tag_ksz.c | 59 + 17 files changed, 3401 insertions(+), 20 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml create mode 100644 drivers/net/dsa/microchip/lan937x_dev.c create mode 100644 drivers/net/dsa/microchip/lan937x_dev.h create mode 100644 drivers/net/dsa/microchip/lan937x_main.c create mode 100644 drivers/net/dsa/microchip/lan937x_reg.h create mode 100644 drivers/net/dsa/microchip/lan937x_spi.c
Signature · 1 line
2.30.2
PATCH v10 1/10 dt-bindings: net: make internal-delay-ps based on phy-mode
*-internal-delay-ps properties would be applicable only for RGMII interface modes.
It is changed as per the request,
https://lore.kernel.org/netdev/[email protected]/
Ran dt_binding_check to confirm nothing is broken.
--- .../bindings/net/ethernet-controller.yaml | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-)
Documentation/devicetree/bindings/net/ethernet-controller.yaml +25 -12
@@ -123,12 +123,6 @@ properties: and is useful for determining certain configuration settings such as flow control thresholds. - rx-internal-delay-ps: - description: | - RGMII Receive Clock Delay defined in pico seconds. - This is used for controllers that have configurable RX internal delays. - If this property is present then the MAC applies the RX delay. - sfp: $ref: /schemas/types.yaml#/definitions/phandle description:
@@ -140,12 +134,6 @@ properties: The size of the controller\'s transmit fifo in bytes. This is used for components that can have configurable fifo sizes. - tx-internal-delay-ps: - description: | - RGMII Transmit Clock Delay defined in pico seconds. - This is used for controllers that have configurable TX internal delays. - If this property is present then the MAC applies the TX delay. - managed: description: Specifies the PHY management type. If auto is set and fixed-link
@@ -222,6 +210,31 @@ properties: required: - speed +allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id + then: + properties: + rx-internal-delay-ps: + description: + RGMII Receive Clock Delay defined in pico seconds.This is + used for controllers that have configurable RX internal + delays. If this property is present then the MAC applies + the RX delay. + tx-internal-delay-ps: + description: + RGMII Transmit Clock Delay defined in pico seconds.This is + used for controllers that have configurable TX internal + delays. If this property is present then the MAC applies + the TX delay. + additionalProperties: true ...
Signature · 1 line
2.30.2
PATCH v10 2/10 dt-bindings: net: dsa: dt bindings for microchip lan937x
In reply to Prasanna VengateshanDocumentation in .yaml format and updates to the MAINTAINERS Also 'make dt_binding_check' is passed.
RGMII internal delay values for the mac is retrieved from rx-internal-delay-ps & tx-internal-delay-ps as per the feedback from v3 patch series.
https://lore.kernel.org/netdev/20210802121550.gqgbipqdvp5x76ii@skbuf/
It supports only the delay value of 0ns and 2ns.
--- .../bindings/net/dsa/microchip,lan937x.yaml | 160 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 161 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +160 -0
@@ -0,0 +1,160 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/microchip,lan937x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LAN937x Ethernet Switch Series Tree Bindings + +maintainers: + - [email protected] + +allOf: + - $ref: dsa.yaml# + +properties: + compatible: + enum: + - microchip,lan9370 + - microchip,lan9371 + - microchip,lan9372 + - microchip,lan9373 + - microchip,lan9374 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 50000000 + + reset-gpios: + description: Optional gpio specifier for a reset line + maxItems: 1 + + mdio: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + + tx-internal-delay-ps: + enum: [0, 2000] + default: 0 + + rx-internal-delay-ps: + enum: [0, 2000] + default: 0 + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + //Ethernet switch connected via spi to the host + ethernet { + #address-cells = <1>; + #size-cells = <0>; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + + spi { + #address-cells = <1>; + #size-cells = <0>; + + lan9374: switch@0 { + compatible = "microchip,lan9374"; + reg = <0>; + + spi-max-frequency = <44000000>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&t1phy0>; + }; + port@1 { + reg = <1>; + label = "lan2"; + phy-mode = "internal"; + phy-handle = <&t1phy1>; + }; + port@2 { + reg = <2>; + label = "lan4"; + phy-mode = "internal"; + phy-handle = <&t1phy2>; + }; + port@3 { + reg = <3>; + label = "lan6"; + phy-mode = "internal"; + phy-handle = <&t1phy3>; + }; + port@4 { + reg = <4>; + phy-mode = "rgmii"; + ethernet = <ðernet>; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + port@5 { + reg = <5>; + label = "lan7"; + phy-mode = "rgmii"; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + port@6 { + reg = <6>; + label = "lan5"; + phy-mode = "internal"; + phy-handle = <&t1phy6>; + }; + port@7 { + reg = <7>; + label = "lan3"; + phy-mode = "internal"; + phy-handle = <&t1phy7>; + }; + }; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + t1phy0: ethernet-phy@0{ + reg = <0x0>; + }; + t1phy1: ethernet-phy@1{ + reg = <0x1>; + }; + t1phy2: ethernet-phy@2{ + reg = <0x2>; + }; + t1phy3: ethernet-phy@3{ + reg = <0x3>; + }; + t1phy6: ethernet-phy@6{ + reg = <0x6>; + }; + t1phy7: ethernet-phy@7{ + reg = <0x7>; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -12664,6 +12664,7 @@ M: [email protected] L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +F: Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml F: drivers/net/dsa/microchip/* F: include/linux/platform_data/microchip-ksz.h F: net/dsa/tag_ksz.c
Signature · 1 line
2.30.2
PATCH v10 3/10 net: dsa: move mib->cnt_ptr reset code to ksz_common.c
In reply to Prasanna Vengateshanmib->cnt_ptr resetting is handled in multiple places as part of port_init_cnt(). Hence moved mib->cnt_ptr code to ksz common layer and removed from individual product files.
--- drivers/net/dsa/microchip/ksz8795.c | 2 -- drivers/net/dsa/microchip/ksz9477.c | 3 --- drivers/net/dsa/microchip/ksz_common.c | 8 +++++++- 3 files changed, 7 insertions(+), 6 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +0 -2
@@ -468,8 +468,6 @@ static void ksz8_port_init_cnt(struct ksz_device *dev, int port) dropped, &mib->counters[mib->cnt_ptr]); ++mib->cnt_ptr; } - mib->cnt_ptr =0 ; -memset (mib->counters,0 , dev->mib_cnt *sizeof (u64)); }static void ksz8_r_table (struct ksz_device *dev,int table,u16 addr,u64 *data)
drivers/net/dsa/microchip/ksz9477.c +0 -3
@@ -410,9 +410,6 @@ static void ksz9477_port_init_cnt(struct ksz_device *dev, int port)ksz_write8 (dev,REG_SW_MAC_CTRL_6 ,SW_MIB_COUNTER_FLUSH );ksz_pwrite32 (dev, port,REG_PORT_MIB_CTRL_STAT__4 ,0 );mutex_unlock (&mib->cnt_mutex); - - mib->cnt_ptr =0 ; -memset (mib->counters,0 , dev->mib_cnt *sizeof (u64)); } static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds,
drivers/net/dsa/microchip/ksz_common.c +7 -1
@@ -146,8 +146,14 @@ void ksz_init_mib_timer(struct ksz_device *dev)INIT_DELAYED_WORK (&dev->mib_read, ksz_mib_read_work); -for (i =0 ; i < dev->port_cnt; i++) +for (i =0 ; i < dev->port_cnt; i++) { +struct ksz_port_mib *mib = &dev->ports[i].mib; + dev->dev_ops->port_init_cnt (dev, i); + + mib->cnt_ptr =0 ; +memset (mib->counters,0 , dev->mib_cnt *sizeof (u64)); + } }EXPORT_SYMBOL_GPL (ksz_init_mib_timer);
Signature · 1 line
2.30.2
PATCH v10 4/10 net: dsa: tag_ksz: add tag handling for Microchip LAN937x
In reply to Prasanna VengateshanThe Microchip LAN937X switches have a tagging protocol which is very similar to KSZ tagging. So that the implementation is added to tag_ksz.c and reused common APIs
--- include/net/dsa.h | 2 ++ net/dsa/Kconfig | 4 ++-- net/dsa/tag_ksz.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-)
include/net/dsa.h +2 -0
@@ -53,6 +53,7 @@ struct phylink_link_state;#define DSA_TAG_PROTO_SJA1110_VALUE 23#define DSA_TAG_PROTO_RTL8_4_VALUE 24#define DSA_TAG_PROTO_RTL8_4T_VALUE 25 +#define DSA_TAG_PROTO_LAN937X_VALUE 26enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -81,6 +82,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_SJA1110 =DSA_TAG_PROTO_SJA1110_VALUE ,DSA_TAG_PROTO_RTL8_4 =DSA_TAG_PROTO_RTL8_4_VALUE ,DSA_TAG_PROTO_RTL8_4T =DSA_TAG_PROTO_RTL8_4T_VALUE , + DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +2 -2
@@ -87,10 +87,10 @@ config NET_DSA_TAG_MTK Mediatek switches. config NET_DSA_TAG_KSZ - tristate "Tag driver for Microchip 8795/9477/9893 families of switches" + tristate "Tag driver for Microchip 8795/937x/9477/9893 families of switches" help Say Y if you want to enable support for tagging frames for the - Microchip 8795/9477/9893 families of switches. + Microchip 8795/937x/9477/9893 families of switches. config NET_DSA_TAG_OCELOT tristate "Tag driver for Ocelot family of switches, using NPI port"
net/dsa/tag_ksz.c +59 -0
69 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v10 5/10 net: dsa: microchip: add DSA support for microchip lan937x
In reply to Prasanna VengateshanBasic DSA driver support for lan937x and the device will be configured through SPI interface.
drivers/net/dsa/microchip/ path is already part of MAINTAINERS & the new files come under this path. Hence no update needed to the MAINTAINERS
Reused KSZ APIs for port_bridge_join() & port_bridge_leave() and added support for port_stp_state_set() & port_fast_age().
lan937x_flush_dyn_mac_table() which gets called from port_fast_age() of KSZ common layer, hence added support for it.
RGMII internal delay values for the mac is retrieved from rx-internal-delay-ps & tx-internal-delay-ps as per the feedback from v3 patch series.
https://lore.kernel.org/netdev/20210802121550.gqgbipqdvp5x76ii@skbuf/
It supports standard delay 2ns only. If the property is not found, the value will be forced to 0.
--- drivers/net/dsa/microchip/Kconfig | 12 + drivers/net/dsa/microchip/Makefile | 5 + drivers/net/dsa/microchip/ksz_common.h | 5 + drivers/net/dsa/microchip/lan937x_dev.c | 631 +++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 117 ++++ drivers/net/dsa/microchip/lan937x_main.c | 320 +++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 688 +++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_spi.c | 236 ++++++++ 8 files changed, 2014 insertions(+) create mode 100644 drivers/net/dsa/microchip/lan937x_dev.c create mode 100644 drivers/net/dsa/microchip/lan937x_dev.h create mode 100644 drivers/net/dsa/microchip/lan937x_main.c create mode 100644 drivers/net/dsa/microchip/lan937x_reg.h create mode 100644 drivers/net/dsa/microchip/lan937x_spi.c
drivers/net/dsa/microchip/Kconfig +12 -0
@@ -3,6 +3,18 @@ config NET_DSA_MICROCHIP_KSZ_COMMON select NET_DSA_TAG_KSZ tristate +config NET_DSA_MICROCHIP_LAN937X + tristate "Microchip LAN937X series SPI connected switch support" + depends on NET_DSA && SPI + select NET_DSA_MICROCHIP_KSZ_COMMON + select REGMAP_SPI + help + This driver adds support for Microchip LAN937X series + switch chips. + + Select to enable support for registering switches configured + through SPI. + menuconfig NET_DSA_MICROCHIP_KSZ9477 tristate "Microchip KSZ9477 series switch support" depends on NET_DSA
drivers/net/dsa/microchip/Makefile +5 -0
@@ -6,3 +6,8 @@ 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 + +obj-$(CONFIG_NET_DSA_MICROCHIP_LAN937X) += lan937x.o +lan937x-objs := lan937x_dev.o +lan937x-objs += lan937x_main.o +lan937x-objs += lan937x_spi.o
drivers/net/dsa/microchip/ksz_common.h +5 -0
@@ -42,6 +42,8 @@ struct ksz_port {struct ksz_port_mib mib;phy_interface_t interface;u16 max_frame; +u32 rgmii_tx_val; +u32 rgmii_rx_val; };struct ksz_device {
@@ -148,6 +150,9 @@ void ksz_switch_remove(struct ksz_device *dev);int ksz8_switch_register (struct ksz_device *dev);int ksz9477_switch_register (struct ksz_device *dev); +int lan937x_switch_register (struct ksz_device *dev); + +int lan937x_check_device_id (struct ksz_device *dev);void ksz_update_port_member (struct ksz_device *dev,int port);void ksz_init_mib_timer (struct ksz_device *dev);
drivers/net/dsa/microchip/lan937x_dev.c new file +631 -0
631 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_dev.h new file +117 -0
117 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_main.c new file +320 -0
320 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_reg.h new file +688 -0
688 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_spi.c new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v10 6/10 net: dsa: microchip: add support for phylink management
In reply to Prasanna Vengateshanphylink_get_caps() is implemented and reused KSZ commmon API for phylink_mac_link_down() operation
lan937x_phylink_mac_config configures the interface using lan937x_mac_config and lan937x_phylink_mac_link_up configures the speed/duplex/flow control.
Currently SGMII & in-band neg are not supported & it will be added later.
--- drivers/net/dsa/microchip/lan937x_dev.c | 158 +++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 5 + drivers/net/dsa/microchip/lan937x_main.c | 66 ++++++++++ 3 files changed, 229 insertions(+)
drivers/net/dsa/microchip/lan937x_dev.c +158 -0
@@ -449,6 +449,164 @@ int lan937x_internal_phy_read(struct ksz_device *dev, int addr, int reg,return ksz_read16 (dev,REG_VPHY_IND_DATA__2 , val); } +static void lan937x_config_gbit (struct ksz_device *dev,bool gbit,u8 *data) +{ +if (gbit) + *data &= ~PORT_MII_NOT_1GBIT ; +else + *data |=PORT_MII_NOT_1GBIT ; +} + +static void lan937x_update_rgmii_tx_rx_delay (struct ksz_device *dev,int port, +bool is_tx) +{ +u16 data16; +int reg; +u8 val; + +/* Apply different codes based on the ports as per characterization +* results +*/ +if (is_tx) { + reg =REG_PORT_XMII_CTRL_5 ; + val = (port ==LAN937X_RGMII_1_PORT ) ?RGMII_1_TX_DELAY_2NS : +RGMII_2_TX_DELAY_2NS ; + }else { + reg =REG_PORT_XMII_CTRL_4 ; + val = (port ==LAN937X_RGMII_1_PORT ) ?RGMII_1_RX_DELAY_2NS : +RGMII_2_RX_DELAY_2NS ; + } + +lan937x_pread16 (dev, port, reg, &data16); + +/* clear tune Adjust */ + data16 &= ~PORT_TUNE_ADJ ; + data16 |= (val <<7 ); +lan937x_pwrite16 (dev, port, reg, data16); + + data16 |=PORT_DLL_RESET ; +/* write DLL reset to take effect */ +lan937x_pwrite16 (dev, port, reg, data16); +} + +static void lan937x_apply_rgmii_delay (struct ksz_device *dev,int port, +phy_interface_t interface,u8 val) +{ +struct ksz_port *p = &dev->ports[port]; + +/* Clear Ingress & Egress internal delay enabled bits */ + val &= ~(PORT_RGMII_ID_EG_ENABLE |PORT_RGMII_ID_IG_ENABLE ); + +/* if the delay is 0, do not enable DLL */ +if (p->rgmii_tx_val) { +lan937x_update_rgmii_tx_rx_delay (dev, port, true); +dev_info (dev->dev,"Applied rgmii tx delay for the port %d\n" , + port); + val |=PORT_RGMII_ID_EG_ENABLE ; + } + +/* if the delay is 0, do not enable DLL */ +if (p->rgmii_rx_val) { +lan937x_update_rgmii_tx_rx_delay (dev, port, false); +dev_info (dev->dev,"Applied rgmii rx delay for the port %d\n" , + port); + val |=PORT_RGMII_ID_IG_ENABLE ; + } + +/* Enable RGMII internal delays */ +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_1 , val); +} + +void lan937x_mac_config (struct ksz_device *dev,int port, +phy_interface_t interface) +{ +u8 data8; + +lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_1 , &data8); + +/* clear MII selection & set it based on interface later */ + data8 &= ~PORT_MII_SEL_M ; + +/* configure MAC based on interface */ +switch (interface) { +case PHY_INTERFACE_MODE_MII : +lan937x_config_gbit (dev, false, &data8); + data8 |=PORT_MII_SEL ; +break ; +case PHY_INTERFACE_MODE_RMII : +lan937x_config_gbit (dev, false, &data8); + data8 |=PORT_RMII_SEL ; +break ; +case PHY_INTERFACE_MODE_RGMII : +case PHY_INTERFACE_MODE_RGMII_ID : +case PHY_INTERFACE_MODE_RGMII_TXID : +case PHY_INTERFACE_MODE_RGMII_RXID : +lan937x_config_gbit (dev, true, &data8); + data8 |=PORT_RGMII_SEL ; + +/* Apply rgmii internal delay for the mac */ +lan937x_apply_rgmii_delay (dev, port, interface, data8); + +/* rgmii delay configuration is already applied above, +* hence return from here as no changes required +*/ +return ; +default : +dev_err (dev->dev,"Unsupported interface '%s' for port %d\n" , +phy_modes (interface), port); +return ; + } + +/* Write the updated value */ +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_1 , data8); +} + +void lan937x_config_interface (struct ksz_device *dev,int port, +int speed,int duplex, +bool tx_pause,bool rx_pause) +{ +u8 xmii_ctrl0, xmii_ctrl1; + +lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_0 , &xmii_ctrl0); +lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_1 , &xmii_ctrl1); + +switch (speed) { +case SPEED_1000 : +lan937x_config_gbit (dev, true, &xmii_ctrl1); +break ; +case SPEED_100 : +lan937x_config_gbit (dev, false, &xmii_ctrl1); + xmii_ctrl0 |=PORT_MAC_SPEED_100 ; +break ; +case SPEED_10 : +lan937x_config_gbit (dev, false, &xmii_ctrl1); + xmii_ctrl0 &= ~PORT_MAC_SPEED_100 ; +break ; +default : +dev_err (dev->dev,"Unsupported speed on port %d: %d\n" , + port, speed); +return ; + } + +if (duplex) + xmii_ctrl0 |=PORT_FULL_DUPLEX ; +else + xmii_ctrl0 &= ~PORT_FULL_DUPLEX ; + +if (tx_pause) + xmii_ctrl0 |=PORT_TX_FLOW_CTRL ; +else + xmii_ctrl1 &= ~PORT_TX_FLOW_CTRL ; + +if (rx_pause) + xmii_ctrl0 |=PORT_RX_FLOW_CTRL ; +else + xmii_ctrl0 &= ~PORT_RX_FLOW_CTRL ; + +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_0 , xmii_ctrl0); +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_1 , xmii_ctrl1); +} +void lan937x_port_setup (struct ksz_device *dev,int port,bool cpu_port) {struct dsa_switch *ds = dev->ds;
drivers/net/dsa/microchip/lan937x_dev.h +5 -0
@@ -34,6 +34,11 @@ void lan937x_cfg_port_member(struct ksz_device *dev, int port, u8 member);void lan937x_port_setup (struct ksz_device *dev,int port,bool cpu_port);int lan937x_enable_spi_indirect_access (struct ksz_device *dev); +void lan937x_config_interface (struct ksz_device *dev,int port, +int speed,int duplex, +bool tx_pause,bool rx_pause); +void lan937x_mac_config (struct ksz_device *dev,int port, +phy_interface_t interface);void lan937x_r_mib_pkt (struct ksz_device *dev,int port,u16 addr,u64 *dropped,u64 *cnt);
drivers/net/dsa/microchip/lan937x_main.c +66 -0
78 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v10 7/10 net: dsa: microchip: add support for ethtool port counters
In reply to Prasanna VengateshanAdded support for get_eth_**_stats() (phy/mac/ctrl) and get_stats64()
Reused the KSZ common APIs for get_ethtool_stats() & get_sset_count() along with relevant lan937x hooks for KSZ common layer and added support for get_strings()
--- drivers/net/dsa/microchip/lan937x_main.c | 118 +++++++++++++++++++++++ 1 file changed, 118 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +118 -0
@@ -45,6 +45,20 @@ static int lan937x_phy_write16(struct dsa_switch *ds, int addr, int reg,return lan937x_internal_phy_write (dev, addr, reg, val); } +static void lan937x_get_strings (struct dsa_switch *ds,int port,u32 stringset, +u8 *buf) +{ +struct ksz_device *dev = ds->priv; +int i; + +if (stringset !=ETH_SS_STATS ) +return ; + +for (i =0 ; i < dev->mib_cnt; i++) +memcpy (buf + i *ETH_GSTRING_LEN , lan937x_mib_names[i].string, +ETH_GSTRING_LEN ); +} +static void lan937x_port_stp_state_set (struct dsa_switch *ds,int port,u8 state) {
@@ -357,12 +371,116 @@ static void lan937x_phylink_get_caps(struct dsa_switch *ds, int port, } } +static void lan937x_get_eth_phy_stats (struct dsa_switch *ds,int port, +struct ethtool_eth_phy_stats *phy_stats) +{ +struct ksz_device *dev = ds->priv; +struct ksz_port_mib *mib = &dev->ports[port].mib; +u64 *cnt; + +mutex_lock (&mib->cnt_mutex); + + cnt = &mib->counters[lan937x_mib_rx_sym_err]; +lan937x_r_mib_pkt (dev, port, lan937x_mib_rx_sym_err,NULL , cnt); + + phy_stats->SymbolErrorDuringCarrier = *cnt; + +mutex_unlock (&mib->cnt_mutex); +} + +static void lan937x_get_eth_mac_stats (struct dsa_switch *ds,int port, +struct ethtool_eth_mac_stats *mac_stats) +{ +struct ksz_device *dev = ds->priv; +struct ksz_port_mib *mib = &dev->ports[port].mib; +u64 *ctr = mib->counters; + +mutex_lock (&mib->cnt_mutex); + +while (mib->cnt_ptr < dev->mib_cnt) { +lan937x_r_mib_pkt (dev, port, mib->cnt_ptr, +NULL , &mib->counters[mib->cnt_ptr]); + ++mib->cnt_ptr; + } + + mac_stats->FramesTransmittedOK = ctr[lan937x_mib_tx_mcast] + + ctr[lan937x_mib_tx_bcast] + + ctr[lan937x_mib_tx_ucast] + + ctr[lan937x_mib_tx_pause]; + + mac_stats->SingleCollisionFrames = ctr[lan937x_mib_tx_single_col]; + mac_stats->MultipleCollisionFrames = ctr[lan937x_mib_tx_mult_col]; + + mac_stats->FramesReceivedOK = ctr[lan937x_mib_rx_mcast] + + ctr[lan937x_mib_rx_bcast] + + ctr[lan937x_mib_rx_ucast] + + ctr[lan937x_mib_rx_pause]; + + mac_stats->FrameCheckSequenceErrors = ctr[lan937x_mib_rx_crc_err]; + mac_stats->AlignmentErrors = ctr[lan937x_mib_rx_align_err]; + mac_stats->OctetsTransmittedOK = ctr[lan937x_mib_tx_total]; + mac_stats->FramesWithDeferredXmissions = ctr[lan937x_mib_tx_deferred]; + mac_stats->LateCollisions = ctr[lan937x_mib_tx_late_col]; + mac_stats->FramesAbortedDueToXSColls = ctr[lan937x_mib_tx_exc_col]; + mac_stats->FramesLostDueToIntMACXmitError = ctr[lan937x_mib_tx_discard]; + + mac_stats->OctetsReceivedOK = ctr[lan937x_mib_rx_total]; + mac_stats->FramesLostDueToIntMACRcvError = ctr[lan937x_mib_rx_discard]; + mac_stats->MulticastFramesXmittedOK = ctr[lan937x_mib_tx_mcast]; + mac_stats->BroadcastFramesXmittedOK = ctr[lan937x_mib_tx_bcast]; + + mac_stats->MulticastFramesReceivedOK = ctr[lan937x_mib_rx_mcast]; + mac_stats->BroadcastFramesReceivedOK = ctr[lan937x_mib_rx_bcast]; + mac_stats->InRangeLengthErrors = ctr[lan937x_mib_rx_fragments]; + + mib->cnt_ptr =0 ; +mutex_unlock (&mib->cnt_mutex); +} + +static void lan937x_get_eth_ctrl_stats (struct dsa_switch *ds,int port, +struct ethtool_eth_ctrl_stats *ctrl_sts) +{ +struct ksz_device *dev = ds->priv; +struct ksz_port_mib *mib = &dev->ports[port].mib; +u64 *cnt; + +mutex_lock (&mib->cnt_mutex); + + cnt = &mib->counters[lan937x_mib_rx_pause]; +lan937x_r_mib_pkt (dev, port, lan937x_mib_rx_pause,NULL , cnt); + ctrl_sts->MACControlFramesReceived = *cnt; + + cnt = &mib->counters[lan937x_mib_tx_pause]; +lan937x_r_mib_pkt (dev, port, lan937x_mib_tx_pause,NULL , cnt); + ctrl_sts->MACControlFramesTransmitted = *cnt; + +mutex_unlock (&mib->cnt_mutex); +} + +static void lan937x_get_stats64 (struct dsa_switch *ds,int port, +struct rtnl_link_stats64 *s) +{ +struct ksz_device *dev = ds->priv; +struct ksz_port_mib *mib = &dev->ports[port].mib; + +spin_lock (&mib->stats64_lock); +memcpy (s, &mib->stats64,sizeof (*s)); +spin_unlock (&mib->stats64_lock); +} +const struct dsa_switch_ops lan937x_switch_ops = { .get_tag_protocol = lan937x_get_tag_protocol, .setup = lan937x_setup, .phy_read = lan937x_phy_read16, .phy_write = lan937x_phy_write16, .port_enable = ksz_enable_port, + .get_strings = lan937x_get_strings, + .get_ethtool_stats = ksz_get_ethtool_stats, + .get_sset_count = ksz_sset_count, + .get_eth_ctrl_stats = lan937x_get_eth_ctrl_stats, + .get_eth_mac_stats = lan937x_get_eth_mac_stats, + .get_eth_phy_stats = lan937x_get_eth_phy_stats, + .get_stats64 = lan937x_get_stats64, .port_bridge_join = ksz_port_bridge_join, .port_bridge_leave = ksz_port_bridge_leave, .port_stp_state_set = lan937x_port_stp_state_set,
Signature · 1 line
2.30.2
PATCH v10 8/10 net: dsa: microchip: add support for port mirror operations
In reply to Prasanna VengateshanAdded support for port_mirror_add() and port_mirror_del operations
Sniffing is limited to one port & alert the user if any new sniffing port is selected
--- drivers/net/dsa/microchip/lan937x_main.c | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +83 -0
@@ -98,6 +98,87 @@ static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port,ksz_update_port_member (dev, port); } +static int lan937x_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, p; +u8 data; + +/* Limit to one sniffer port +* Check if any of the port is already set for sniffing +* If yes, instruct the user to remove the previous entry & exit +*/ +for (p =0 ; p < dev->port_cnt; p++) { +/* Skip the current sniffing port */ +if (p == mirror->to_local_port) +continue ; + + ret =lan937x_pread8 (dev, p,P_MIRROR_CTRL , &data); +if (ret <0 ) +return ret; + +if (data &PORT_MIRROR_SNIFFER ) { +NL_SET_ERR_MSG_MOD (extack, +"Sniffer port is already configured, delete existing rules & retry" ); +return -EBUSY ; + } + } + +/* Configure ingress/egress mirroring */ +if (ingress) + ret =lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_RX , + true); +else + ret =lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_TX , + true); +if (ret <0 ) +return ret; + +/* Configure sniffer port as other ports do not have +* PORT_MIRROR_SNIFFER is set +*/ + ret =lan937x_port_cfg (dev, mirror->to_local_port,P_MIRROR_CTRL , +PORT_MIRROR_SNIFFER , true); +if (ret <0 ) +return ret; + +return lan937x_cfg (dev,S_MIRROR_CTRL ,SW_MIRROR_RX_TX , false); +} + +static void lan937x_port_mirror_del (struct dsa_switch *ds,int port, +struct dsa_mall_mirror_tc_entry *mirror) +{ +struct ksz_device *dev = ds->priv; +bool in_use = false; +u8 data; +int p; + +/* clear ingress/egress mirroring port */ +if (mirror->ingress) +lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_RX , + false); +else +lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_TX , + false); + +/* Check if any of the port is still referring to sniffer port */ +for (p =0 ; p < dev->port_cnt; p++) { +lan937x_pread8 (dev, p,P_MIRROR_CTRL , &data); + +if ((data & (PORT_MIRROR_RX |PORT_MIRROR_TX ))) { + in_use = true; +break ; + } + } + +/* delete sniffing if there are no other mirroring rule exist */ +if (!in_use) +lan937x_port_cfg (dev, mirror->to_local_port,P_MIRROR_CTRL , +PORT_MIRROR_SNIFFER , false); +} +static void lan937x_config_cpu_port (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv;
@@ -485,6 +566,8 @@ const struct dsa_switch_ops lan937x_switch_ops = { .port_bridge_leave = ksz_port_bridge_leave, .port_stp_state_set = lan937x_port_stp_state_set, .port_fast_age = ksz_port_fast_age, + .port_mirror_add = lan937x_port_mirror_add, + .port_mirror_del = lan937x_port_mirror_del, .port_max_mtu = lan937x_get_max_mtu, .port_change_mtu = lan937x_change_mtu, .phylink_get_caps = lan937x_phylink_get_caps,
Signature · 1 line
2.30.2
PATCH v10 9/10 net: dsa: microchip: add support for fdb and mdb management
In reply to Prasanna VengateshanSupport for fdb_add, mdb_add, fdb_del, mdb_del and fdb_dump operations. ALU1 and ALU2 are used for fdb operations.
fdb_add: find any existing entries and update the port map. if ALU1 write is failed and attempt to write ALU2.
If ALU2 is also failed then exit. Clear WRITE_FAIL for both ALU1 & ALU2.
fdb_del: find the matching entry and clear the respective port in the port map by writing the ALU tables
fdb_dump: read and dump 2 ALUs upto last entry. ALU_START bit is used to find the last entry. If the read is timed out, then pass the error message.
mdb_add: Find the empty slot in ALU and update the port map & mac address by writing the ALU
mdb_del: find the matching entry and delete the respective port in port map by writing the ALU
For MAC address, could not use upper_32_bits() & lower_32_bits() as per Vladimir proposal since it gets accessed in terms of 16bits. I tried to have common API to get 16bits based on index but shifting seems to be straight-forward.
--- drivers/net/dsa/microchip/lan937x_main.c | 515 +++++++++++++++++++++++ 1 file changed, 515 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +515 -0
@@ -17,6 +17,70 @@#include "ksz_common.h" #include "lan937x_dev.h" +static u8 lan937x_get_fid (u16 vid) +{ +if (vid >ALU_FID_SIZE ) +return LAN937X_GET_FID (vid); +else +return vid; +} + +static int lan937x_read_table (struct ksz_device *dev,u32 *table) +{ +int ret; + +/* read alu table */ + ret =ksz_read32 (dev,REG_SW_ALU_VAL_A , &table[0 ]); +if (ret <0 ) +return ret; + + ret =ksz_read32 (dev,REG_SW_ALU_VAL_B , &table[1 ]); +if (ret <0 ) +return ret; + + ret =ksz_read32 (dev,REG_SW_ALU_VAL_C , &table[2 ]); +if (ret <0 ) +return ret; + +return ksz_read32 (dev,REG_SW_ALU_VAL_D , &table[3 ]); +} + +static int lan937x_write_table (struct ksz_device *dev,u32 *table) +{ +int ret; + +/* write alu table */ + ret =ksz_write32 (dev,REG_SW_ALU_VAL_A , table[0 ]); +if (ret <0 ) +return ret; + + ret =ksz_write32 (dev,REG_SW_ALU_VAL_B , table[1 ]); +if (ret <0 ) +return ret; + + ret =ksz_write32 (dev,REG_SW_ALU_VAL_C , table[2 ]); +if (ret <0 ) +return ret; + +return ksz_write32 (dev,REG_SW_ALU_VAL_D , table[3 ]); +} + +static int lan937x_wait_alu_ready (int alu,struct ksz_device *dev) +{ +unsigned int val; + +return regmap_read_poll_timeout (dev->regmap[2 ],REG_SW_ALU_CTRL (alu), + val, !(val &ALU_START ),10 ,1000 ); +} + +static int lan937x_wait_alu_sta_ready (struct ksz_device *dev) +{ +unsigned int val; + +return regmap_read_poll_timeout (dev->regmap[2 ],REG_SW_ALU_STAT_CTRL__4 , + val, !(val &ALU_STAT_START ),10 ,1000 ); +} +static enum dsa_tag_protocol lan937x_get_tag_protocol (struct dsa_switch *ds,int port,enum dsa_tag_protocol mp)
@@ -98,6 +162,452 @@ static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port,ksz_update_port_member (dev, port); } +static int lan937x_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; +u8 fid =lan937x_get_fid (vid); +u32 alu_table[4 ]; +int ret, i; +u32 data; +u8 val; + +mutex_lock (&dev->alu_mutex); + +/* Accessing two ALU tables through loop */ +for (i =0 ; i <ALU_STA_DYN_CNT ; i++) { +/* find any entry with mac & fid */ + data = fid <<ALU_FID_INDEX_S ; + data |= ((addr[0 ] <<8 ) | addr[1 ]); + + ret =ksz_write32 (dev,REG_SW_ALU_INDEX_0 , data); +if (ret <0 ) +break ; + + data = ((addr[2 ] <<24 ) | (addr[3 ] <<16 )); + data |= ((addr[4 ] <<8 ) | addr[5 ]); + + ret =ksz_write32 (dev,REG_SW_ALU_INDEX_1 , data); +if (ret <0 ) +break ; + +/* start read operation */ + ret =ksz_write32 (dev,REG_SW_ALU_CTRL (i), +ALU_READ |ALU_START ); +if (ret <0 ) +break ; + +/* wait to be finished */ + ret =lan937x_wait_alu_ready (i, dev); +if (ret <0 ) { +dev_err (dev->dev,"Failed to read ALU\n" ); +break ; + } + +/* read ALU entry */ + ret =lan937x_read_table (dev, alu_table); +if (ret <0 ) { +dev_err (dev->dev,"Failed to read ALU\n" ); +break ; + } + +/* update ALU entry */ + alu_table[0 ] =ALU_V_STATIC_VALID ; + +/* update port number */ + alu_table[1 ] |=BIT (port); + +if (fid) + alu_table[1 ] |=ALU_V_USE_FID ; + + alu_table[2 ] = (fid <<ALU_V_FID_S ); + alu_table[2 ] |= ((addr[0 ] <<8 ) | addr[1 ]); + alu_table[3 ] = ((addr[2 ] <<24 ) | (addr[3 ] <<16 )); + alu_table[3 ] |= ((addr[4 ] <<8 ) | addr[5 ]); + + ret =lan937x_write_table (dev, alu_table); +if (ret <0 ) +break ; + + ret =ksz_write32 (dev,REG_SW_ALU_CTRL (i), + (ALU_WRITE |ALU_START )); +if (ret <0 ) +break ; + +/* wait to be finished */ + ret =lan937x_wait_alu_ready (i, dev); +if (ret <0 ) { +dev_err (dev->dev,"Failed to write ALU\n" ); +break ; + } + + ret =ksz_read8 (dev,REG_SW_LUE_INT_STATUS__1 , &val); +if (ret <0 ) +break ; + +/* ALU2 write failed */ +if (val &WRITE_FAIL_INT && i ==1 ) +dev_err (dev->dev,"Failed to write ALU\n" ); + +/* if ALU1 write is failed and attempt to write ALU2, +* otherwise exit. Clear Write fail for both ALU1 & ALU2 +*/ +if (val &WRITE_FAIL_INT ) { +/* Write to clear the Write Fail */ + ret =ksz_write8 (dev,REG_SW_LUE_INT_STATUS__1 , +WRITE_FAIL_INT ); +if (ret <0 ) +break ; + }else { +break ; + } + } + +mutex_unlock (&dev->alu_mutex); + +return ret; +} + +static int lan937x_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; +u8 fid =lan937x_get_fid (vid); +u32 alu_table[4 ]; +int ret, i; +u32 data; + +mutex_lock (&dev->alu_mutex); + +/* Accessing two ALU tables through loop */ +for (i =0 ; i <ALU_STA_DYN_CNT ; i++) { +/* read any entry with mac & fid */ + data = fid <<ALU_FID_INDEX_S ; + data |= ((addr[0 ] <<8 ) | addr[1 ]); + ret =ksz_write32 (dev,REG_SW_ALU_INDEX_0 , data); +if (ret <0 ) +break ; + + data = ((addr[2 ] <<24 ) | (addr[3 ] <<16 )); + data |= ((addr[4 ] <<8 ) | addr[5 ]); + ret =ksz_write32 (dev,REG_SW_ALU_INDEX_1 , data); +if (ret <0 ) +break ; + +/* start read operation */ + ret =ksz_write32 (dev,REG_SW_ALU_CTRL (i), + (ALU_READ |ALU_START )); +if (ret <0 ) +break ; + +/* wait to be finished */ + ret =lan937x_wait_alu_ready (i, dev); +if (ret <0 ) { +dev_err (dev->dev,"Failed to read ALU\n" ); +break ; + } + + ret =ksz_read32 (dev,REG_SW_ALU_VAL_A , &alu_table[0 ]); +if (ret <0 ) +break ; + +if (alu_table[0 ] &ALU_V_STATIC_VALID ) { +/* read ALU entry */ + ret =lan937x_read_table (dev, alu_table); +if (ret <0 ) { +dev_err (dev->dev,"Failed to read ALU table\n" ); +break ; + } + +/* clear forwarding port */ + alu_table[1 ] &= ~BIT (port); + +/* if there is no port to forward, clear table */ +if ((alu_table[1 ] &ALU_V_PORT_MAP ) ==0 ) +memset (&alu_table,0 ,sizeof (alu_table)); + }else { +memset (&alu_table,0 ,sizeof (alu_table)); + } + + ret =lan937x_write_table (dev, alu_table); +if (ret <0 ) +break ; + + ret =ksz_write32 (dev,REG_SW_ALU_CTRL (i), + (ALU_WRITE |ALU_START )); +if (ret <0 ) +break ; + +/* wait to be finished */ + ret =lan937x_wait_alu_ready (i, dev); +if (ret <0 ) { +dev_err (dev->dev,"Failed to delete ALU Entries\n" ); +break ; + } + } + +mutex_unlock (&dev->alu_mutex); + +return ret; +} + +static void lan937x_convert_alu (struct lan_alu_struct *alu,u32 *alu_table) +{ + alu->is_static = !!(alu_table[0 ] &ALU_V_STATIC_VALID ); + alu->is_src_filter = !!(alu_table[0 ] &ALU_V_SRC_FILTER ); + alu->is_dst_filter = !!(alu_table[0 ] &ALU_V_DST_FILTER ); + alu->prio_age = (alu_table[0 ] >>ALU_V_PRIO_AGE_CNT_S ) & +ALU_V_PRIO_AGE_CNT_M ; + alu->mstp = alu_table[0 ] &ALU_V_MSTP_M ; + + alu->is_override = !!(alu_table[1 ] &ALU_V_OVERRIDE ); + alu->is_use_fid = !!(alu_table[1 ] &ALU_V_USE_FID ); + alu->port_forward = alu_table[1 ] &ALU_V_PORT_MAP ; + + alu->fid = (alu_table[2 ] >>ALU_V_FID_S ) &ALU_V_FID_M ; + + alu->mac[0 ] = (alu_table[2 ] >>8 ) &0xFF ; + alu->mac[1 ] = alu_table[2 ] &0xFF ; + alu->mac[2 ] = (alu_table[3 ] >>24 ) &0xFF ; + alu->mac[3 ] = (alu_table[3 ] >>16 ) &0xFF ; + alu->mac[4 ] = (alu_table[3 ] >>8 ) &0xFF ; + alu->mac[5 ] = alu_table[3 ] &0xFF ; +} + +static int lan937x_port_fdb_dump (struct dsa_switch *ds,int port, +dsa_fdb_dump_cb_t *cb,void *data) +{ +struct ksz_device *dev = ds->priv; +struct lan_alu_struct alu; +u32 lan937x_data; +u32 alu_table[4 ]; +int timeout; +int ret, i; + +mutex_lock (&dev->alu_mutex); + +/* Accessing two ALU tables through loop */ +for (i =0 ; i <ALU_STA_DYN_CNT ; i++) { +/* start ALU search */ + ret =ksz_write32 (dev,REG_SW_ALU_CTRL (i), + (ALU_START |ALU_SEARCH )); +if (ret <0 ) + goto exit; + +do { + timeout =1000 ; +do { + ret =ksz_read32 (dev,REG_SW_ALU_CTRL (i), + &lan937x_data); +if (ret <0 ) + goto exit; + +if ((lan937x_data &ALU_VALID ) || + !(lan937x_data &ALU_START )) +break ; +usleep_range (1 ,10 ); + }while (timeout-- >0 ); + +if (!timeout) { +dev_err (dev->dev,"Failed to search ALU\n" ); + ret = -ETIMEDOUT ; + goto exit; + } + +/* read ALU table */ + ret =lan937x_read_table (dev, alu_table); +if (ret <0 ) + goto exit; + +lan937x_convert_alu (&alu, alu_table); + +if (alu.port_forward &BIT (port)) { + ret =cb (alu.mac, alu.fid, alu.is_static, data); +if (ret) + goto exit; + } + }while (lan937x_data &ALU_START ); + +exit: +/* stop ALU search & continue to next ALU if available */ + ret =ksz_write32 (dev,REG_SW_ALU_CTRL (i),0 ); + } + +mutex_unlock (&dev->alu_mutex); + +return ret; +} + +static int lan937x_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; +u8 fid =lan937x_get_fid (mdb->vid); +u32 static_table[4 ]; +u32 mac_hi, mac_lo; +int index, ret; +u32 data; + + mac_hi = ((mdb->addr[0 ] <<8 ) | mdb->addr[1 ]); + mac_lo = ((mdb->addr[2 ] <<24 ) | (mdb->addr[3 ] <<16 )); + mac_lo |= ((mdb->addr[4 ] <<8 ) | mdb->addr[5 ]); + +mutex_lock (&dev->alu_mutex); + +/* Access the entries in the table */ +for (index =0 ; index < dev->num_statics; index++) { +/* find empty slot first */ + data = (index <<ALU_STAT_INDEX_S ) | +ALU_STAT_READ |ALU_STAT_START ; + + ret =ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data); +if (ret <0 ) + goto exit; + +/* wait to be finished */ + ret =lan937x_wait_alu_sta_ready (dev); +if (ret <0 ) { +dev_err (dev->dev,"Failed to read ALU STATIC\n" ); + goto exit; + } + +/* read ALU static table */ + ret =lan937x_read_table (dev, static_table); +if (ret <0 ) + goto exit; + +if (static_table[0 ] &ALU_V_STATIC_VALID ) { +/* check this has same fid & mac address */ +if (((static_table[2 ] >>ALU_V_FID_S ) == fid) && + ((static_table[2 ] &ALU_V_MAC_ADDR_HI ) == mac_hi) && + static_table[3 ] == mac_lo) { +/* found matching one */ +break ; + } + }else { +/* found empty one */ +break ; + } + } + +/* no available entry */ +if (index == dev->num_statics) { + ret = -ENOSPC ; + goto exit; + } + +/* add entry */ + static_table[0 ] =ALU_V_STATIC_VALID ; + + static_table[1 ] |=BIT (port); +if (fid) + static_table[1 ] |=ALU_V_USE_FID ; + static_table[2 ] = (fid <<ALU_V_FID_S ); + static_table[2 ] |= mac_hi; + static_table[3 ] = mac_lo; + + ret =lan937x_write_table (dev, static_table); +if (ret <0 ) + goto exit; + + data = (index <<ALU_STAT_INDEX_S ) |ALU_STAT_START ; + ret =ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data); +if (ret <0 ) + goto exit; + +/* wait to be finished */ + ret =lan937x_wait_alu_sta_ready (dev); +if (ret <0 ) +dev_err (dev->dev,"Failed to read ALU STATIC\n" ); + +exit: +mutex_unlock (&dev->alu_mutex); +return ret; +} + +static int lan937x_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; +u8 fid =lan937x_get_fid (mdb->vid); +u32 static_table[4 ]; +u32 mac_hi, mac_lo; +int index, ret; +u32 data; + + mac_hi = ((mdb->addr[0 ] <<8 ) | mdb->addr[1 ]); + mac_lo = ((mdb->addr[2 ] <<24 ) | (mdb->addr[3 ] <<16 )); + mac_lo |= ((mdb->addr[4 ] <<8 ) | mdb->addr[5 ]); + +mutex_lock (&dev->alu_mutex); + +/* Access the entries in the table */ +for (index =0 ; index < dev->num_statics; index++) { + data = (index <<ALU_STAT_INDEX_S ) | +ALU_STAT_READ |ALU_STAT_START ; + ret =ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data); +if (ret <0 ) + goto exit; + +/* wait to be finished */ + ret =lan937x_wait_alu_sta_ready (dev); +if (ret <0 ) { +dev_err (dev->dev,"Failed to read ALU STATIC\n" ); + goto exit; + } + +/* read ALU static table */ + ret =lan937x_read_table (dev, static_table); +if (ret <0 ) + goto exit; + +if (static_table[0 ] &ALU_V_STATIC_VALID ) { +/* check this has same fid & mac address */ +if (((static_table[2 ] >>ALU_V_FID_S ) == fid) && + ((static_table[2 ] &ALU_V_MAC_ADDR_HI ) == mac_hi) && + static_table[3 ] == mac_lo) { +/* found matching one */ +break ; + } + } + } + +/* no available entry */ +if (index == dev->num_statics) + goto exit; + +/* clear port based on port arg */ + static_table[1 ] &= ~BIT (port); + +if ((static_table[1 ] &ALU_V_PORT_MAP ) ==0 ) { +/* delete entry */ +memset (&static_table,0 ,sizeof (static_table)); + } + + ret =lan937x_write_table (dev, static_table); +if (ret <0 ) + goto exit; + + data = (index <<ALU_STAT_INDEX_S ) |ALU_STAT_START ; + ret =ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data); +if (ret <0 ) + goto exit; + +/* wait to be finished */ + ret =lan937x_wait_alu_sta_ready (dev); +if (ret <0 ) +dev_err (dev->dev,"Failed to read ALU STATIC\n" ); + +exit: +mutex_unlock (&dev->alu_mutex); + +return ret; +} +static int lan937x_port_mirror_add (struct dsa_switch *ds,int port,struct dsa_mall_mirror_tc_entry *mirror,bool ingress,struct netlink_ext_ack *extack)
@@ -566,6 +1076,11 @@ const struct dsa_switch_ops lan937x_switch_ops = { .port_bridge_leave = ksz_port_bridge_leave, .port_stp_state_set = lan937x_port_stp_state_set, .port_fast_age = ksz_port_fast_age, + .port_fdb_dump = lan937x_port_fdb_dump, + .port_fdb_add = lan937x_port_fdb_add, + .port_fdb_del = lan937x_port_fdb_del, + .port_mdb_add = lan937x_port_mdb_add, + .port_mdb_del = lan937x_port_mdb_del, .port_mirror_add = lan937x_port_mirror_add, .port_mirror_del = lan937x_port_mirror_del, .port_max_mtu = lan937x_get_max_mtu,
Signature · 1 line
2.30.2
PATCH v10 10/10 net: dsa: microchip: add support for vlan operations
In reply to Prasanna VengateshanSupport for VLAN add, del, prepare and filtering operations.
The VLAN aware is a global setting. Mixed vlan filterings are not supported. vlan_filtering_is_global is made as true in lan937x_setup function.
--- drivers/net/dsa/microchip/lan937x_main.c | 186 +++++++++++++++++++++++ 1 file changed, 186 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +186 -0
@@ -17,6 +17,14 @@#include "ksz_common.h" #include "lan937x_dev.h" +static int lan937x_wait_vlan_ctrl_ready (struct ksz_device *dev) +{ +unsigned int val; + +return regmap_read_poll_timeout (dev->regmap[0 ],REG_SW_VLAN_CTRL , val, + !(val &VLAN_START ),10 ,1000 ); +} +static u8 lan937x_get_fid (u16 vid) {if (vid >ALU_FID_SIZE )
@@ -25,6 +33,97 @@ static u8 lan937x_get_fid(u16 vid)return vid; } +static int lan937x_get_vlan_table (struct ksz_device *dev,u16 vid, +struct lan937x_vlan *vlan_entry) +{ +u32 data; +int ret; + +mutex_lock (&dev->vlan_mutex); + + ret =ksz_write16 (dev,REG_SW_VLAN_ENTRY_INDEX__2 , vid &VLAN_INDEX_M ); +if (ret <0 ) + goto exit; + + ret =ksz_write8 (dev,REG_SW_VLAN_CTRL ,VLAN_READ |VLAN_START ); +if (ret <0 ) + goto exit; + +/* wait to be cleared */ + ret =lan937x_wait_vlan_ctrl_ready (dev); +if (ret <0 ) + goto exit; + + ret =ksz_read32 (dev,REG_SW_VLAN_ENTRY__4 , &data); +if (ret <0 ) + goto exit; + + vlan_entry->valid = !!(data &VLAN_VALID ); + vlan_entry->fid = data &VLAN_FID_M ; + + ret =ksz_read32 (dev,REG_SW_VLAN_ENTRY_UNTAG__4 , + &vlan_entry->untag_prtmap); +if (ret <0 ) + goto exit; + + ret =ksz_read32 (dev,REG_SW_VLAN_ENTRY_PORTS__4 , + &vlan_entry->fwd_map); +if (ret <0 ) + goto exit; + + ret =ksz_write8 (dev,REG_SW_VLAN_CTRL ,0 ); +if (ret <0 ) + goto exit; + +exit: +mutex_unlock (&dev->vlan_mutex); + +return ret; +} + +static int lan937x_set_vlan_table (struct ksz_device *dev,u16 vid, +struct lan937x_vlan *vlan_entry) +{ +u32 data; +int ret; + +mutex_lock (&dev->vlan_mutex); + + data = vlan_entry->valid ?VLAN_VALID :0 ; + data |= vlan_entry->fid; + + ret =ksz_write32 (dev,REG_SW_VLAN_ENTRY__4 , data); +if (ret <0 ) + goto exit; + + ret =ksz_write32 (dev,REG_SW_VLAN_ENTRY_UNTAG__4 , + vlan_entry->untag_prtmap); +if (ret <0 ) + goto exit; + + ret =ksz_write32 (dev,REG_SW_VLAN_ENTRY_PORTS__4 , vlan_entry->fwd_map); +if (ret <0 ) + goto exit; + + ret =ksz_write16 (dev,REG_SW_VLAN_ENTRY_INDEX__2 , vid &VLAN_INDEX_M ); +if (ret <0 ) + goto exit; + + ret =ksz_write8 (dev,REG_SW_VLAN_CTRL ,VLAN_START |VLAN_WRITE ); +if (ret <0 ) + goto exit; + +/* wait to be cleared */ + ret =lan937x_wait_vlan_ctrl_ready (dev); +if (ret <0 ) + goto exit; + +exit: +mutex_unlock (&dev->vlan_mutex); + +return ret; +} +static int lan937x_read_table (struct ksz_device *dev,u32 *table) {int ret;
@@ -162,6 +261,90 @@ static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port,ksz_update_port_member (dev, port); } +static int lan937x_port_vlan_filtering (struct dsa_switch *ds,int port, +bool flag, +struct netlink_ext_ack *extack) +{ +struct ksz_device *dev = ds->priv; + +/* enable/disable VLAN mode, once enabled, look up process starts +* and then forwarding and discarding are done based on port +* membership of the VLAN table +*/ +return lan937x_cfg (dev,REG_SW_LUE_CTRL_0 ,SW_VLAN_ENABLE , flag); +} + +static int lan937x_port_vlan_add (struct dsa_switch *ds,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 lan937x_vlan vlan_entry; +int ret; + + ret =lan937x_get_vlan_table (dev, vlan->vid, &vlan_entry); +if (ret <0 ) { +NL_SET_ERR_MSG_MOD (extack,"Failed to get vlan table" ); +return ret; + } + + vlan_entry.fid =lan937x_get_fid (vlan->vid); + vlan_entry.valid = true; + +/* set/clear switch port when updating vlan table registers */ +if (untagged) + vlan_entry.untag_prtmap |=BIT (port); +else + vlan_entry.untag_prtmap &= ~BIT (port); + + vlan_entry.fwd_map |=BIT (port); + + ret =lan937x_set_vlan_table (dev, vlan->vid, &vlan_entry); +if (ret <0 ) { +NL_SET_ERR_MSG_MOD (extack,"Failed to set vlan table" ); +return ret; + } + +/* change PVID */ +if (vlan->flags &BRIDGE_VLAN_INFO_PVID ) { + ret =lan937x_pwrite16 (dev, port,REG_PORT_DEFAULT_VID , + vlan->vid); +if (ret <0 ) { +NL_SET_ERR_MSG_MOD (extack,"Failed to set pvid" ); +return ret; + } + } + +return 0 ; +} + +static int lan937x_port_vlan_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +struct ksz_device *dev = ds->priv; +struct lan937x_vlan vlan_entry; +int ret; + + ret =lan937x_get_vlan_table (dev, vlan->vid, &vlan_entry); +if (ret <0 ) { +dev_err (dev->dev,"Failed to get vlan table\n" ); +return ret; + } + +/* clear port fwd map & untag entries*/ + vlan_entry.fwd_map &= ~BIT (port); + vlan_entry.untag_prtmap &= ~BIT (port); + + ret =lan937x_set_vlan_table (dev, vlan->vid, &vlan_entry); +if (ret <0 ) { +dev_err (dev->dev,"Failed to set vlan table\n" ); +return ret; + } + +return 0 ; +} +static int lan937x_port_fdb_add (struct dsa_switch *ds,int port,const unsigned char *addr,u16 vid,struct dsa_db db)
@@ -1076,6 +1259,9 @@ const struct dsa_switch_ops lan937x_switch_ops = { .port_bridge_leave = ksz_port_bridge_leave, .port_stp_state_set = lan937x_port_stp_state_set, .port_fast_age = ksz_port_fast_age, + .port_vlan_filtering = lan937x_port_vlan_filtering, + .port_vlan_add = lan937x_port_vlan_add, + .port_vlan_del = lan937x_port_vlan_del, .port_fdb_dump = lan937x_port_fdb_dump, .port_fdb_add = lan937x_port_fdb_add, .port_fdb_del = lan937x_port_fdb_del,
Signature · 1 line
2.30.2
Jakub Kicinski
maintainerQuoted 10 lines · On Wed, 23 Mar 2022 01:24:45 +0530 Prasanna Vengateshan wrote:
LAN937x is a Multi-Port 100BASE-T1 Ethernet Physical Layer switch compliant with the IEEE 802.3bw-2015 specification. The device provides 100 Mbit/s transmit and receive capability over a single Unshielded Twisted Pair (UTP) cable. LAN937x is successive revision of KSZ series switch. This series of patches provide the DSA driver support for Microchip LAN937X switch and it configures through SPI interface.
This driver shares some of the functions from KSZ common layer.
net-next is closed during the merge window. You can continue code review by posing RFC patches but you'll have to repost for merging once 5.18-rc1 has been tagged.