net: dsa: microchip: DSA driver support for LAN937x switch
Subsystems (7)
v8 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 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: dsa: dt bindings for microchip lan937x
net: dsa: move mib->cnt_ptr reset code to ksz_common.c
net: phy: Add support for LAN937x T1 phy driver
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 | 179 +++ 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 | 751 ++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 122 ++ drivers/net/dsa/microchip/lan937x_main.c | 1308 +++++++++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 688 +++++++++ drivers/net/dsa/microchip/lan937x_spi.c | 238 +++ drivers/net/phy/microchip_t1.c | 342 ++++- include/net/dsa.h | 2 + net/dsa/Kconfig | 4 +- net/dsa/tag_ksz.c | 59 + 17 files changed, 3652 insertions(+), 77 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 v8 1/10 dt-bindings: net: dsa: dt bindings for microchip lan937x
Documentation 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 | 179 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 180 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +179 -0
@@ -0,0 +1,179 @@ +# 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 + +patternProperties: + "^(ethernet-)?ports$": + patternProperties: + "^(ethernet-)?port@[0-7]+$": + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id + then: + properties: + rx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + +required: + - compatible + - reg + +$defs: + internal-delay-ps: + description: Delay is in pico seconds + enum: [0, 2000] + default: 0 + +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 = <&t1phy4>; + }; + port@7 { + reg = <7>; + label = "lan3"; + phy-mode = "internal"; + phy-handle = <&t1phy5>; + }; + }; + + 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>; + }; + t1phy4: ethernet-phy@6{ + reg = <0x6>; + }; + t1phy5: ethernet-phy@7{ + reg = <0x7>; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -12630,6 +12630,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
Re: [PATCH v8 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Quoted 50 lines · Prasanna Vengateshan
Documentation in .yaml format and updates to the
MAINTAINERSAlso 'makedt_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.
Signed-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Rob Herring <[email protected]>--- .../bindings/net/dsa/microchip,lan937x.yaml | 179 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 180 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yamlDocumentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +26
-0@@ -0,0 +1,179 @@ +# 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 +
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml line 36
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +10
-0+ 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
This should be moved to dsa.yaml since this is about describing the switch's internal MDIO bus controller. This is applicable to any switch, really.
Quoted 11 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +11
-0+ +patternProperties: + "^(ethernet-)?ports$": + patternProperties: + "^(ethernet-)?port@[0-7]+$": + allOf: + - if: + properties: + phy-mode: + contains: + enum:
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml line 57
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +10
-0+ - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id + then: + properties: + rx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps"
Likewise, this should actually be changed in ethernet-controller.yaml
Signature · 1 line
Florian
Re: [PATCH v8 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Quoted 29 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 16 lines · Prasanna Vengateshan
Documentation in .yaml format and updates to the
MAINTAINERSAlso 'makedt_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.
Signed-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Rob Herring <[email protected]>---
.../bindings/net/dsa/microchip,lan937x.yaml | 179 ++++++++++++++++++ MAINTAINERS | 1 +2 files changed, 180 insertions(+)Quoted 8 lines
create mode 100644
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml+ maxItems: 1
+
+ mdio:
+ $ref: /schemas/net/mdio.yaml#
+ unevaluatedProperties: false
Quoted 3 lines
This should be moved to
dsa.yamlsince this is about describing the switch's internal MDIO bus controller. This is applicable to any switch, really.
Thanks for your review and feedback. Do you mean that 'mdio' to be added in dsa.yaml instead adding here?
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +15
-0+ +patternProperties: + "^(ethernet-)?ports$": + patternProperties: + "^(ethernet-)?port@[0-7]+$": + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id
Quoted 8 lines
Quoted 6 lines
+ then:
+ properties:
+ rx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps"Likewise, this should actually be changed in
ethernet-controller.yaml
There is *-internal-delay-ps property defined for mac in ethernet- controller.yaml. Should that be changed like above?
Prasanna V
Re: [PATCH v8 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Quoted 30 lines · Prasanna Vengateshan
Quoted 29 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 24 lines · Prasanna Vengateshan
Documentation in .yaml format and updates to the
MAINTAINERSAlso 'makedt_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.
Signed-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Rob Herring <[email protected]>--- .../bindings/net/dsa/microchip,lan937x.yaml | 179 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 180 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml+ maxItems: 1
+
+ mdio:
+ $ref: /schemas/net/mdio.yaml#
+ unevaluatedProperties: false
Quoted 6 lines
Quoted 3 lines
This should be moved to
dsa.yamlsince this is about describing the switch's internal MDIO bus controller. This is applicable to any switch, really.Thanks for your review and feedback. Do you mean that 'mdio' to be added in
dsa.yamlinstead adding here?
Yes indeed, since this is a common property of all DSA switches, it can be defined or not depending on whether the switch does have an internal MDIO bus controller or not.
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +15
-0+ +patternProperties: + "^(ethernet-)?ports$": + patternProperties: + "^(ethernet-)?port@[0-7]+$": + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-idQuoted 8 lines
Quoted 6 lines
+ then:
+ properties:
+ rx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps"Likewise, this should actually be changed in
ethernet-controller.yaml
Quoted 2 lines
There is *-internal-delay-ps property defined for mac in ethernet-
controller.yaml. Should that be changed like above?
It seems to me that these properties override whatever 'phy-mode' property is defined, but in premise you are right that this is largely applicable to RGMII only. I seem to recall that the QCA8K driver had some sort of similar delay being applied even in SGMII mode but I am not sure if we got to the bottom of this.
Please make sure that this does not create regressions for other DTS in the tree before going with that change in ethernet-controller.yaml.
Thanks!
Signature · 1 line
Florian
Re: [PATCH v8 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Quoted 16 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 11 lines · Prasanna Vengateshan
Quoted 7 lines · Florian Fainelli
Quoted 5 lines
+ rx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps"Likewise, this should actually be changed in
ethernet-controller.yamlThere is *-internal-delay-ps property defined for mac in ethernet-
controller.yaml. Should that be changed like above?
Quoted 8 lines
It seems to me that these properties override whatever 'phy-mode' property is defined, but in premise you are right that this is largely applicable to RGMII only. I seem to recall that the QCA8K driver had some sort of similar delay being applied even in SGMII mode but I am not sure if we got to the bottom of this.
Please make sure that this does not create regressions for other DTS in the tree before going with that change in
ethernet-controller.yaml.
Okay, Can these be submitted as a seperate patch?
Prasanna V
Re: [PATCH v8 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Quoted 23 lines · Prasanna Vengateshan
Quoted 22 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 11 lines · Prasanna Vengateshan
Quoted 7 lines · Florian Fainelli
Quoted 5 lines
+ rx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps"Likewise, this should actually be changed in
ethernet-controller.yamlThere is *-internal-delay-ps property defined for mac in ethernet-
controller.yaml. Should that be changed like above?It seems to me that these properties override whatever 'phy-mode' property is defined, but in premise you are right that this is largely applicable to RGMII only. I seem to recall that the QCA8K driver had some sort of similar delay being applied even in SGMII mode but I am not sure if we got to the bottom of this.
Quoted 4 lines
Quoted 2 lines
Please make sure that this does not create regressions for other DTS in the tree before going with that change in
ethernet-controller.yaml.Okay, Can these be submitted as a seperate patch?
Well yes, it has to be a separate patch, but it should be part of the same series as this one, otherwise your patch adding the binding for lan937x would fail validation.
Signature · 1 line
Florian
Re: [PATCH v8 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
In reply to Florian FainelliHi Rob and Florian,
Quoted 74 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 30 lines · Prasanna Vengateshan
Quoted 29 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 24 lines · Prasanna Vengateshan
Documentation in .yaml format and updates to the
MAINTAINERSAlso 'makedt_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.
Signed-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Rob Herring <[email protected]>---
.../bindings/net/dsa/microchip,lan937x.yaml | 179 ++++++++++++++++++ MAINTAINERS | 1 +2 files changed, 180 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml+ maxItems: 1
+
+ mdio:
+ $ref: /schemas/net/mdio.yaml#
+ unevaluatedProperties: falseQuoted 6 lines
Quoted 3 lines
This should be moved to
dsa.yamlsince this is about describing the switch's internal MDIO bus controller. This is applicable to any switch, really.Thanks for your review and feedback. Do you mean that 'mdio' to be added in
dsa.yamlinstead adding here?Yes indeed, since this is a common property of all DSA switches, it can be defined or not depending on whether the switch does have an internal MDIO bus controller or not.
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +15
-0+ +patternProperties: + "^(ethernet-)?ports$": + patternProperties: + "^(ethernet-)?port@[0-7]+$": + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-idQuoted 8 lines
Quoted 6 lines
+ then:
+ properties:
+ rx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps"Likewise, this should actually be changed in
ethernet-controller.yamlQuoted 2 lines
There is *-internal-delay-ps property defined for mac in ethernet-
controller.yaml. Should that be changed like above?
Quoted 9 lines
It seems to me that these properties override whatever 'phy-mode' property is defined, but in premise you are right that this is largely applicable to RGMII only. I seem to recall that the QCA8K driver had some sort of similar delay being applied even in SGMII mode but I am not sure if we got to the bottom of this.
Please make sure that this does not create regressions for other DTS in the tree before going with that change in
ethernet-controller.yaml.
I just tried changing rx-internal-delay-ps & tx-internal-delay-ps on conditional basis like above in the ethernet-controller.yaml and it passed 'make dt_binding_check' as well.
It would be like below if existing *-internal-delay-ps are removed from ethernet-controller.yaml.
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.
After the above changes, these two properties descriptions are different compare to other properties. So i just wanted to know whether i am following the right approach or are there any other proposal available? Thanks.
Prasanna V
Re: [PATCH v8 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Hi Rob/Florian,
Quoted 124 lines · Prasanna Vengateshan
Hi Rob and Florian,
Quoted 78 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 33 lines · Prasanna Vengateshan
Quoted 32 lines · Florian Fainelli
EXTERNAL EMAIL: Do not click links or open attachments unless you know the
content is safeQuoted 26 lines · Prasanna Vengateshan
Documentation in .yaml format and updates to the
MAINTAINERSAlso 'makedt_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.
Signed-off-by: Prasanna Vengateshan <
[email protected]>Reviewed-by Rob Herring <[email protected]>---
.../bindings/net/dsa/microchip,lan937x.yaml | 179
++++++++++++++++++
MAINTAINERS | 1 +2 files changed, 180 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml+ maxItems: 1
+
+ mdio:
+ $ref: /schemas/net/mdio.yaml#
+ unevaluatedProperties: falseQuoted 7 lines
Quoted 3 lines
This should be moved to
dsa.yamlsince this is about describing the switch's internal MDIO bus controller. This is applicable to any switch, really.Thanks for your review and feedback. Do you mean that 'mdio' to be added in
dsa.yamlinstead adding here?Yes indeed, since this is a common property of all DSA switches, it can be defined or not depending on whether the switch does have an internal MDIO bus controller or not.
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +15
-0+ +patternProperties: + "^(ethernet-)?ports$": + patternProperties: + "^(ethernet-)?port@[0-7]+$": + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-idQuoted 8 lines
Quoted 6 lines
+ then:
+ properties:
+ rx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps:
+ $ref: "#/$defs/internal-delay-ps"Likewise, this should actually be changed in
ethernet-controller.yamlQuoted 2 lines
There is *-internal-delay-ps property defined for mac in ethernet-
controller.yaml. Should that be changed like above?Quoted 9 lines
It seems to me that these properties override whatever 'phy-mode' property is defined, but in premise you are right that this is largely applicable to RGMII only. I seem to recall that the QCA8K driver had some sort of similar delay being applied even in SGMII mode but I am not sure if we got to the bottom of this.
Please make sure that this does not create regressions for other DTS in the tree before going with that change in
ethernet-controller.yaml.I just tried changing rx-internal-delay-ps & tx-internal-delay-ps on conditional
basis like above in theethernet-controller.yamland it passed 'makedt_binding_check' as well.It would be like below if existing *-internal-delay-ps are removed from
ethernet-controller.yaml.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.
Quoted 7 lines
After the above changes, these two properties descriptions are different compare
to other properties. So i just wanted to know whether i am following the right approach or are there any other proposal available? Thanks.Prasanna V
Is the above method looking good? Your feedback will be helpful. Thanks.
Prasanna V
PATCH v8 2/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
@@ -448,8 +448,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
@@ -292,9 +292,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
@@ -122,8 +122,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
Re: [PATCH v8 net-next 02/10] net: dsa: move mib->cnt_ptr reset code to ksz_common.c
Quoted 6 lines · Prasanna Vengateshan
mib->cnt_ptrresetting is handled in multiple places as part ofport_init_cnt(). Hence movedmib->cnt_ptrcode to ksz common layer and removed from individual product files.Signed-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
PATCH v8 3/10 net: phy: Add support for LAN937x T1 phy driver
In reply to Prasanna VengateshanAdded support for Microchip LAN937x T1 phy driver. The sequence of initialization is used commonly for both LAN87xx and LAN937x drivers. The new initialization sequence is an improvement to existing LAN87xx and it is shared with LAN937x.
Also relevant comments are added in the existing code and existing soft-reset customized code has been replaced with genphy_soft_reset().
access_ereg_clr_poll_timeout() API is introduced for polling phy bank write and this is linked with PHYACC_ATTR_MODE_POLL.
Finally introduced function table for LAN937X_T1_PHY_ID along with microchip_t1_phy_driver struct.
--- drivers/net/phy/microchip_t1.c | 342 ++++++++++++++++++++++++++------- 1 file changed, 273 insertions(+), 69 deletions(-)
drivers/net/phy/microchip_t1.c +273 -69
@@ -37,6 +37,7 @@#define PHYACC_ATTR_MODE_READ 0#define PHYACC_ATTR_MODE_WRITE 1#define PHYACC_ATTR_MODE_MODIFY 2 +#define PHYACC_ATTR_MODE_POLL 3#define PHYACC_ATTR_BANK_SMI 0#define PHYACC_ATTR_BANK_MISC 1
@@ -50,8 +51,47 @@#define LAN87XX_CABLE_TEST_OPEN 1#define LAN87XX_CABLE_TEST_SAME_SHORT 2 +#define T1_MODE_STAT_REG 0x11 +#define T1_DSCR_LOCK_STATUS_MSK BIT(3) +#define T1_LINK_UP_MSK BIT(0) + +#define T1_REG_BANK_SEL_MASK 0x7 +#define T1_REG_BANK_SEL 8 +#define T1_REG_ADDR_MASK 0xFF + +#define T1_M_STATUS_REG 0x0A +#define T1_LOCAL_RX_OK BIT(13) +#define T1_REMOTE_RX_OK BIT(12) + +#define LAN87XX_PHY_ID 0x0007c150 +#define LAN937X_T1_PHY_ID 0x0007c181 +#define LAN87XX_PHY_ID_MASK 0xfffffff0 +#define LAN937X_PHY_ID_MASK 0xfffffff0 + +/* T1 Registers */ +#define T1_AFE_PORT_CFG1_REG 0x0B +#define T1_POWER_DOWN_CONTROL_REG 0x1A +#define T1_SLV_FD_MULT_CFG_REG 0x18 +#define T1_CDR_CFG_PRE_LOCK_REG 0x05 +#define T1_CDR_CFG_POST_LOCK_REG 0x06 +#define T1_LCK_STG2_MUFACT_CFG_REG 0x1A +#define T1_LCK_STG3_MUFACT_CFG_REG 0x1B +#define T1_POST_LCK_MUFACT_CFG_REG 0x1C +#define T1_TX_RX_FIFO_CFG_REG 0x02 +#define T1_TX_LPF_FIR_CFG_REG 0x55 +#define T1_SQI_CONFIG_REG 0x2E +#define T1_MDIO_CONTROL2_REG 0x10 +#define T1_INTERRUPT_SOURCE_REG 0x18 +#define T1_INTERRUPT2_SOURCE_REG 0x08 +#define T1_EQ_FD_STG1_FRZ_CFG 0x69 +#define T1_EQ_FD_STG2_FRZ_CFG 0x6A +#define T1_EQ_FD_STG3_FRZ_CFG 0x6B +#define T1_EQ_FD_STG4_FRZ_CFG 0x6C +#define T1_EQ_WT_FD_LCK_FRZ_CFG 0x6D +#define T1_PST_EQ_LCK_STG1_FRZ_CFG 0x6E +#define DRIVER_AUTHOR "Nisar Sayed <[email protected]>" -#define DRIVER_DESC "Microchip LAN87XX T1 PHY driver" +#define DRIVER_DESC "Microchip LAN87XX/LAN937X T1 PHY driver"struct access_ereg_val {u8 mode;
@@ -64,12 +104,16 @@ struct access_ereg_val {static int access_ereg (struct phy_device *phydev,u8 mode,u8 bank,u8 offset,u16 val) { +u8 prev_bank;u16 ereg =0 ;int rc =0 ; +u16 t; +/* return if mode and bank are invalid */ if (mode >PHYACC_ATTR_MODE_WRITE || bank >PHYACC_ATTR_BANK_MAX )return -EINVAL ; +/* if the bank is SMI, then call phy_read() & phy_write() directly */ if (bank ==PHYACC_ATTR_BANK_SMI ) {if (mode ==PHYACC_ATTR_MODE_WRITE ) rc =phy_write (phydev, offset, val);
@@ -79,16 +123,43 @@ static int access_ereg(struct phy_device *phydev, u8 mode, u8 bank, }if (mode ==PHYACC_ATTR_MODE_WRITE ) { +/* Initialize to Write Mode */ ereg =LAN87XX_EXT_REG_CTL_WR_CTL ; + +/* Write the data to be written in to the Bank */ rc =phy_write (phydev,LAN87XX_EXT_REG_WR_DATA , val);if (rc <0 )return rc; }else { +/* Initialize to Read Mode */ ereg =LAN87XX_EXT_REG_CTL_RD_CTL ; } ereg |= (bank <<8 ) | offset; +/* DSP bank access workaround for lan937x */ +if (phydev->phy_id ==LAN937X_T1_PHY_ID ) { +/* Read previous selected bank */ + rc =phy_read (phydev,LAN87XX_EXT_REG_CTL ); +if (rc <0 ) +return rc; + +/* store the prev_bank */ + prev_bank = (rc >>T1_REG_BANK_SEL ) &T1_REG_BANK_SEL_MASK ; + +if (bank != prev_bank && bank ==PHYACC_ATTR_BANK_DSP ) { + t = ereg & ~T1_REG_ADDR_MASK ; + + t &= ~LAN87XX_EXT_REG_CTL_WR_CTL ; + t |=LAN87XX_EXT_REG_CTL_RD_CTL ; + +/* access twice for DSP bank change,dummy access */ + rc =phy_write (phydev,LAN87XX_EXT_REG_CTL , t); +if (rc <0 ) +return rc; + } + } + rc =phy_write (phydev,LAN87XX_EXT_REG_CTL , ereg);if (rc <0 )return rc;
@@ -117,6 +188,18 @@ static int access_ereg_modify_changed(struct phy_device *phydev,return rc; } +static int access_ereg_clr_poll_timeout (struct phy_device *phydev,u8 bank, +u8 offset,u16 mask,u16 clr) +{ +int val; + +if (bank !=PHYACC_ATTR_BANK_SMI ) +return -EINVAL ; + +return phy_read_poll_timeout (phydev, offset, val, (val & mask) == clr, +150 ,30000 , true); +} +static int lan87xx_config_rgmii_delay (struct phy_device *phydev) {int rc;
@@ -157,68 +240,151 @@ static int lan87xx_config_rgmii_delay(struct phy_device *phydev)static int lan87xx_phy_init (struct phy_device *phydev) {static const struct access_ereg_val init[] = { -/* TX Amplitude = 5 */ - {PHYACC_ATTR_MODE_MODIFY ,PHYACC_ATTR_BANK_AFE ,0x0B , -0x000A ,0x001E }, -/* Clear SMI interrupts */ - {PHYACC_ATTR_MODE_READ ,PHYACC_ATTR_BANK_SMI ,0x18 , -0 ,0 }, -/* Clear MISC interrupts */ - {PHYACC_ATTR_MODE_READ ,PHYACC_ATTR_BANK_MISC ,0x08 , -0 ,0 }, -/* Turn on TC10 Ring Oscillator (ROSC) */ - {PHYACC_ATTR_MODE_MODIFY ,PHYACC_ATTR_BANK_MISC ,0x20 , -0x0020 ,0x0020 }, -/* WUR Detect Length to 1.2uS, LPC Detect Length to 1.09uS */ - {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_PCS ,0x20 , -0x283C ,0 }, -/* Wake_In Debounce Length to 39uS, Wake_Out Length to 79uS */ - {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_MISC ,0x21 , -0x274F ,0 }, -/* Enable Auto Wake Forward to Wake_Out, ROSC on, Sleep, -* and Wake_In to wake PHY -*/ - {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_MISC ,0x20 , -0x80A7 ,0 }, -/* Enable WUP Auto Fwd, Enable Wake on MDI, Wakeup Debouncer -* to 128 uS -*/ - {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_MISC ,0x24 , -0xF110 ,0 }, -/* Enable HW Init */ - {PHYACC_ATTR_MODE_MODIFY ,PHYACC_ATTR_BANK_SMI ,0x1A , -0x0100 ,0x0100 }, +/* TXPD/TXAMP6 Configs */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_AFE , +T1_AFE_PORT_CFG1_REG ,0x002D ,0 }, +/* HW_Init Hi and Force_ED */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_SMI , +T1_POWER_DOWN_CONTROL_REG ,0x0308 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_EQ_FD_STG1_FRZ_CFG ,0x0002 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_EQ_FD_STG2_FRZ_CFG ,0x0002 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_EQ_FD_STG3_FRZ_CFG ,0x0002 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_EQ_FD_STG4_FRZ_CFG ,0x0002 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_EQ_WT_FD_LCK_FRZ_CFG ,0x0002 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_PST_EQ_LCK_STG1_FRZ_CFG ,0x0002 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_SLV_FD_MULT_CFG_REG ,0x0D53 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_CDR_CFG_PRE_LOCK_REG ,0x0AB2 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_CDR_CFG_POST_LOCK_REG ,0x0AB3 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_LCK_STG2_MUFACT_CFG_REG ,0x0AEA ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_LCK_STG3_MUFACT_CFG_REG ,0x0AEB ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_POST_LCK_MUFACT_CFG_REG ,0x0AEB ,0 }, +/* Pointer delay */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_RX_FIFO_CFG_REG ,0x1C00 ,0 }, +/* Tx iir edits */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1000 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1861 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1061 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1922 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1122 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1983 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1183 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1944 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1144 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x18c5 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x10c5 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1846 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1046 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1807 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1007 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1808 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1008 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1809 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1009 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x180A ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x100A ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x180B ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x100B ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x180C ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x100C ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x180D ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x100D ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x180E ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x100E ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x180F ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x100F ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1810 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1010 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1811 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1011 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_TX_LPF_FIR_CFG_REG ,0x1000 ,0 }, +/* SQI enable */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_DSP , +T1_SQI_CONFIG_REG ,0x9572 ,0 }, +/* Flag LPS and WUR as idle errors */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_SMI , +T1_MDIO_CONTROL2_REG ,0x0014 ,0 }, +/* Restore state machines without clearing registers */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_SMI , +T1_POWER_DOWN_CONTROL_REG ,0x0200 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_SMI , +T1_MDIO_CONTROL2_REG ,0x0094 ,0 }, + {PHYACC_ATTR_MODE_POLL ,PHYACC_ATTR_BANK_SMI , +T1_MDIO_CONTROL2_REG ,0x0080 ,0 }, + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_AFE , +T1_AFE_PORT_CFG1_REG ,0x000C ,0 }, +/* Read INTERRUPT_SOURCE Register */ + {PHYACC_ATTR_MODE_READ ,PHYACC_ATTR_BANK_SMI , +T1_INTERRUPT_SOURCE_REG ,0 ,0 }, +/* Read INTERRUPT_SOURCE Register */ + {PHYACC_ATTR_MODE_READ ,PHYACC_ATTR_BANK_MISC , +T1_INTERRUPT2_SOURCE_REG ,0 ,0 }, +/* HW_Init Hi */ + {PHYACC_ATTR_MODE_WRITE ,PHYACC_ATTR_BANK_SMI , +T1_POWER_DOWN_CONTROL_REG ,0x0300 ,0 }, };int rc, i; -/* Start manual initialization procedures in Managed Mode */ - rc =access_ereg_modify_changed (phydev,PHYACC_ATTR_BANK_SMI , -0x1a ,0x0000 ,0x0100 ); -if (rc <0 ) -return rc; - -/* Soft Reset the SMI block */ - rc =access_ereg_modify_changed (phydev,PHYACC_ATTR_BANK_SMI , -0x00 ,0x8000 ,0x8000 ); +/* phy Soft reset */ + rc =genphy_soft_reset (phydev);if (rc <0 )return rc; -/* Check to see if the self-clearing bit is cleared */ -usleep_range (1000 ,2000 ); - rc =access_ereg (phydev,PHYACC_ATTR_MODE_READ , -PHYACC_ATTR_BANK_SMI ,0x00 ,0 ); -if (rc <0 ) -return rc; -if ((rc &0x8000 ) !=0 ) -return -ETIMEDOUT ; -/* PHY Initialization */ for (i =0 ; i <ARRAY_SIZE (init); i++) { -if (init[i].mode ==PHYACC_ATTR_MODE_MODIFY ) { - rc =access_ereg_modify_changed (phydev, init[i].bank, - init[i].offset, - init[i].val, - init[i].mask); +if (init[i].mode ==PHYACC_ATTR_MODE_POLL ) { + rc =access_ereg_clr_poll_timeout (phydev, init[i].bank, + init[i].offset, + init[i].val, + init[i].mask); }else { rc =access_ereg (phydev, init[i].mode, init[i].bank, init[i].offset, init[i].val);
@@ -273,6 +439,9 @@ static int lan87xx_config_init(struct phy_device *phydev) {int rc =lan87xx_phy_init (phydev); +if (rc <0 ) +phydev_err (phydev,"failed to initialize phy\n" ); +return rc <0 ? rc :0 ; }
@@ -504,32 +673,67 @@ static int lan87xx_cable_test_get_status(struct phy_device *phydev,return 0 ; } -static struct phy_driver microchip_t1_phy_driver[] = { - { - .phy_id =0x0007c150 , - .phy_id_mask =0xfffffff0 , - .name ="Microchip LAN87xx T1" , - .flags =PHY_POLL_CABLE_TEST , +static int lan937x_read_status (struct phy_device *phydev) +{ +int val; - .features =PHY_BASIC_T1_FEATURES , + val =phy_read (phydev,T1_MODE_STAT_REG ); - .config_init = lan87xx_config_init, +if (val <0 ) +return val; - .config_intr = lan87xx_phy_config_intr, - .handle_interrupt = lan87xx_handle_interrupt, +if (val &T1_LINK_UP_MSK ) + phydev->link =1 ; +else + phydev->link =0 ; + + phydev->duplex =DUPLEX_FULL ; + phydev->speed =SPEED_100 ; + phydev->pause =0 ; + phydev->asym_pause =0 ; - .suspend = genphy_suspend, - .resume = genphy_resume, +return 0 ; +} + +static int lan937x_config_init (struct phy_device *phydev) +{ +/* lan87xx & lan937x follows same init sequence */ +return lan87xx_config_init (phydev); +} + +static struct phy_driver microchip_t1_phy_driver[] = { + { + .phy_id =LAN87XX_PHY_ID , + .phy_id_mask =LAN87XX_PHY_ID_MASK , + .name ="LAN87xx T1" , + .flags =PHY_POLL_CABLE_TEST , + .features =PHY_BASIC_T1_FEATURES , + .config_init = lan87xx_config_init, + .config_intr = lan87xx_phy_config_intr, + .handle_interrupt = lan87xx_handle_interrupt, + .suspend = genphy_suspend, + .resume = genphy_resume, .cable_test_start = lan87xx_cable_test_start, .cable_test_get_status = lan87xx_cable_test_get_status, + }, + { + .phy_id =LAN937X_T1_PHY_ID , + .phy_id_mask =LAN937X_PHY_ID_MASK , + .name ="LAN937x T1" , + .read_status = lan937x_read_status, + .features =PHY_BASIC_T1_FEATURES , + .config_init = lan937x_config_init, + .suspend = genphy_suspend, + .resume = genphy_resume, } };module_phy_driver (microchip_t1_phy_driver);static struct mdio_device_id __maybe_unused microchip_t1_tbl[] = { - {0x0007c150 ,0xfffffff0 }, - { } + {LAN87XX_PHY_ID ,LAN87XX_PHY_ID_MASK }, + {LAN937X_T1_PHY_ID ,LAN937X_PHY_ID_MASK }, + {} };MODULE_DEVICE_TABLE (mdio, microchip_t1_tbl);
Signature · 1 line
2.30.2
Andrew Lunn
maintainerRe: [PATCH v8 net-next 03/10] net: phy: Add support for LAN937x T1 phy driver
Quoted 9 lines · Prasanna Vengateshan
Added support for Microchip LAN937x T1 phy driver. The sequence of initialization is used commonly for both LAN87xx and LAN937x drivers. The new initialization sequence is an improvement to existing LAN87xx and it is shared with LAN937x.
Also relevant comments are added in the existing code and existing soft-reset customized code has been replaced with
genphy_soft_reset().
Quoted 5 lines
access_ereg_clr_poll_timeout()API is introduced for polling phy bank write and this is linked withPHYACC_ATTR_MODE_POLL.Finally introduced function table for
LAN937X_T1_PHY_IDalong withmicrochip_t1_phy_driverstruct.
Hi Prasanna
That is a lot of changes in one patch.
I would suggest you make this a patch series of its own. It should be independent of the switch changes. And then you can break this patch up into a number of smaller patches.
Thanks
Andrew
Re: [PATCH v8 net-next 03/10] net: phy: Add support for LAN937x T1 phy driver
Quoted 21 lines · Andrew Lunn
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 9 lines · Prasanna Vengateshan
Added support for Microchip LAN937x T1 phy driver. The sequence of initialization is used commonly for both LAN87xx and LAN937x drivers. The new initialization sequence is an improvement to existing LAN87xx and it is shared with LAN937x.
Also relevant comments are added in the existing code and existing soft-reset customized code has been replaced with
genphy_soft_reset().Quoted 5 lines
access_ereg_clr_poll_timeout()API is introduced for polling phy bank write and this is linked withPHYACC_ATTR_MODE_POLL.Finally introduced function table for
LAN937X_T1_PHY_IDalong withmicrochip_t1_phy_driverstruct.Hi Prasanna
Quoted 8 lines
That is a lot of changes in one patch.
I would suggest you make this a patch series of its own. It should be independent of the switch changes. And then you can break this patch up into a number of smaller patches.
Thanks
Andrew
Sure, i will submit as a seperate patch series and i will remove from this patch. Thanks.
Prasanna V
PATCH v8 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
@@ -52,6 +52,7 @@ struct phylink_link_state;#define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22#define DSA_TAG_PROTO_SJA1110_VALUE 23#define DSA_TAG_PROTO_RTL8_4_VALUE 24 +#define DSA_TAG_PROTO_LAN937X_VALUE 25enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -79,6 +80,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_SEVILLE =DSA_TAG_PROTO_SEVILLE_VALUE ,DSA_TAG_PROTO_SJA1110 =DSA_TAG_PROTO_SJA1110_VALUE ,DSA_TAG_PROTO_RTL8_4 =DSA_TAG_PROTO_RTL8_4_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
Re: [PATCH v8 net-next 04/10] net: dsa: tag_ksz: add tag handling for Microchip LAN937x
Quoted 6 lines · Prasanna Vengateshan
The Microchip LAN937X switches have a tagging protocol which is very similar to KSZ tagging. So that the implementation is added to
tag_ksz.cand reused common APIsSigned-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
PATCH v8 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 | 584 +++++++++++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 116 ++++ drivers/net/dsa/microchip/lan937x_main.c | 297 ++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 688 +++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_spi.c | 238 ++++++++ 8 files changed, 1945 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
@@ -39,6 +39,8 @@ struct ksz_port {struct ksz_port_mib mib;phy_interface_t interface; +u32 rgmii_tx_val; +u32 rgmii_rx_val; };struct ksz_device {
@@ -143,6 +145,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 +584 -0
584 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_dev.h new file +116 -0
116 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_main.c new file +297 -0
297 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 +238 -0
238 lines not on this page · raw message
Signature · 1 line
2.30.2
Vladimir Oltean
maintainerRe: [PATCH v8 net-next 05/10] net: dsa: microchip: add DSA support for microchip lan937x
Quoted 23 lines · Prasanna Vengateshan
drivers/net/dsa/microchip/lan937x_main.c new file +23
-0+static int lan937x_parse_dt_rgmii_delay (struct ksz_device *dev) +{ +struct device_node *ports, *port; +int err, p; +u32 val; + + ports =of_get_child_by_name (dev->dev->of_node,"ports" ); +if (!ports) + ports =of_get_child_by_name (dev->dev->of_node, +"ethernet-ports" ); +if (!ports) { +dev_err (dev->dev,"no ports child node found\n" ); +return -EINVAL ; + } + +for_each_available_child_of_node (ports, port) { + err =of_property_read_u32 (port,"reg" , &p); +if (err) { +dev_err (dev->dev,"Port num not defined in the DT, \"reg\" property\n" ); +of_node_put (ports); +of_node_put (port); +return err; + }
drivers/net/dsa/microchip/lan937x_main.c line 166
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_main.c new file +10
-0+ +/* skip for internal ports */ +if (lan937x_is_internal_phy_port (dev, p)) +continue ; + +if (of_property_read_u32 (port,"rx-internal-delay-ps" , &val)) + val =0 ; + + err =lan937x_set_rgmii_delay (dev, p, val, false); +if (err)
I think this call and the one below are missing calls to of_node_put() on error.
Quoted 13 lines
drivers/net/dsa/microchip/lan937x_main.c new file +13
-0+return err; + +if (of_property_read_u32 (port,"tx-internal-delay-ps" , &val)) + val =0 ; + + err =lan937x_set_rgmii_delay (dev, p, val, true); +if (err) +return err; + } + +of_node_put (ports); +return 0 ; +}
PATCH v8 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 | 167 +++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 6 + drivers/net/dsa/microchip/lan937x_main.c | 66 +++++++++ 3 files changed, 239 insertions(+)
drivers/net/dsa/microchip/lan937x_dev.c +167 -0
@@ -401,6 +401,173 @@ 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 (interface ==PHY_INTERFACE_MODE_RGMII_TXID || + interface ==PHY_INTERFACE_MODE_RGMII_ID ) { +/* if the delay is 0, let us 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 (interface ==PHY_INTERFACE_MODE_RGMII_RXID || + interface ==PHY_INTERFACE_MODE_RGMII_ID ) { +/* if the delay is 0, let us 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 : +lan937x_config_gbit (dev, true, &data8); + data8 |=PORT_RGMII_SEL ; +break ; +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 +6 -0
@@ -34,8 +34,14 @@ 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); +struct mib_names {int index;char string[ETH_GSTRING_LEN ];
drivers/net/dsa/microchip/lan937x_main.c +66 -0
78 lines not on this page · raw message
Signature · 1 line
2.30.2
Vladimir Oltean
maintainerRe: [PATCH v8 net-next 06/10] net: dsa: microchip: add support for phylink management
Quoted 56 lines · Prasanna Vengateshan
drivers/net/dsa/microchip/lan937x_dev.c +56
-0+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 (interface ==PHY_INTERFACE_MODE_RGMII_TXID || + interface ==PHY_INTERFACE_MODE_RGMII_ID ) { +/* if the delay is 0, let us 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 (interface ==PHY_INTERFACE_MODE_RGMII_RXID || + interface ==PHY_INTERFACE_MODE_RGMII_ID ) { +/* if the delay is 0, let us 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 : +lan937x_config_gbit (dev, true, &data8);
drivers/net/dsa/microchip/lan937x_dev.c int lan937x_internal_phy_read(struct ksz_device *dev, int addr, int reg, · line 509
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_dev.c +10
-0+ data8 |=PORT_RGMII_SEL ; +break ; +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);
I think the agreement from previous discussions was to apply RGMII delay _exclusively_ based on the 'rx-internal-delay-ps' and 'tx-internal-delay-ps' properties, at least for new drivers with no legacy. You are omitting to apply delays in phy-mode = "rgmii", which contradicts that agreement. I think you should treat all 4 RGMII cases the same, and remove the interface checks from lan937x_apply_rgmii_delay.
Quoted 14 lines
drivers/net/dsa/microchip/lan937x_dev.c +14
-0+ +/* 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); +}
Re: [PATCH v8 net-next 06/10] net: dsa: microchip: add support for phylink management
Quoted 28 lines · Vladimir Oltean
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 24 lines · Prasanna Vengateshan
ased on interface later */
+ data8 &= ~PORT_MII_SEL_M;drivers/net/dsa/microchip/lan937x_dev.c +22
-0+ + /* 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: + lan937x_config_gbit(dev, true, &data8); + data8 |= PORT_RGMII_SEL; + break; + 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 */
Quoted 8 lines
Quoted 1 line
+
lan937x_apply_rgmii_delay(dev, port, interface, data8);I think the agreement from previous discussions was to apply RGMII delay _exclusively_ based on the 'rx-internal-delay-ps' and 'tx-internal-delay-ps' properties, at least for new drivers with no legacy. You are omitting to apply delays in phy-mode = "rgmii", which contradicts that agreement. I think you should treat all 4 RGMII cases the same, and remove the interface checks from
lan937x_apply_rgmii_delay.
Thanks for the feedback. Yes, you are right. Regardless of the phy-mode, mac should apply its delay from the device tree. I will change both of the places in the next revision.
Prasanna V
Quoted 1 line
PATCH v8 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 | 164 +++++++++++++++++++++++ 1 file changed, 164 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +164 -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) {
@@ -334,12 +348,162 @@ 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; +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; + } + + s->rx_packets = ctr[lan937x_mib_rx_mcast] + + ctr[lan937x_mib_rx_bcast] + + ctr[lan937x_mib_rx_ucast] + + ctr[lan937x_mib_rx_pause]; + + s->tx_packets = ctr[lan937x_mib_tx_mcast] + + ctr[lan937x_mib_tx_bcast] + + ctr[lan937x_mib_tx_ucast] + + ctr[lan937x_mib_tx_pause]; + + s->rx_bytes = ctr[lan937x_mib_rx_total]; + s->tx_bytes = ctr[lan937x_mib_tx_total]; + + s->rx_errors = ctr[lan937x_mib_rx_fragments] + + ctr[lan937x_mib_rx_jabbers] + + ctr[lan937x_mib_rx_sym_err] + + ctr[lan937x_mib_rx_align_err] + + ctr[lan937x_mib_rx_crc_err]; + + s->tx_errors = ctr[lan937x_mib_tx_exc_col] + + ctr[lan937x_mib_tx_late_col]; + + s->rx_dropped = ctr[lan937x_mib_rx_discard]; + s->tx_dropped = ctr[lan937x_mib_tx_discard]; + s->multicast = ctr[lan937x_mib_rx_mcast]; + + s->collisions = ctr[lan937x_mib_tx_late_col] + + ctr[lan937x_mib_tx_single_col] + + ctr[lan937x_mib_tx_mult_col]; + + s->rx_length_errors = ctr[lan937x_mib_rx_fragments] + + ctr[lan937x_mib_rx_jabbers]; + + s->rx_crc_errors = ctr[lan937x_mib_rx_crc_err]; + s->rx_frame_errors = ctr[lan937x_mib_rx_align_err]; + s->tx_aborted_errors = ctr[lan937x_mib_tx_exc_col]; + s->tx_window_errors = ctr[lan937x_mib_tx_late_col]; + + mib->cnt_ptr =0 ; +mutex_unlock (&mib->cnt_mutex); +} +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
Re: [PATCH v8 net-next 07/10] net: dsa: microchip: add support for ethtool port counters
Quoted 8 lines · Prasanna Vengateshan
Added 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 forget_strings()Signed-off-by Prasanna Vengateshan <[email protected]>
Signature · 1 line
Florian
PATCH v8 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 | 84 ++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +84 -0
@@ -98,6 +98,88 @@ 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 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 ) { +dev_err (dev->dev, +"Delete existing rules towards %s & try\n" , +dsa_to_port (ds, p)->name); +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;
@@ -508,6 +590,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
Re: [PATCH v8 net-next 08/10] net: dsa: microchip: add support for port mirror operations
Quoted 7 lines · Prasanna Vengateshan
Added support for
port_mirror_add()andport_mirror_deloperationsSniffing is limited to one port & alert the user if any new sniffing port is selected
Signed-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
PATCH v8 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 | 511 +++++++++++++++++++++++ 1 file changed, 511 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +511 -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,448 @@ 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 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 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 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 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)
@@ -590,6 +1096,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
Re: [PATCH v8 net-next 09/10] net: dsa: microchip: add support for fdb and mdb management
Quoted 21 lines · Prasanna Vengateshan
Support for
fdb_add,mdb_add,fdb_del,mdb_delandfdb_dumpoperations. 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. ClearWRITE_FAILfor 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_STARTbit 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
Quoted 7 lines
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.Signed-off-by Prasanna Vengateshan <[email protected]>Reviewed-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
PATCH v8 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) {
@@ -1096,6 +1279,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
Re: [PATCH v8 net-next 10/10] net: dsa: microchip: add support for vlan operations
Quoted 7 lines · Prasanna Vengateshan
Support for VLAN add, del, prepare and filtering operations.
The VLAN aware is a global setting. Mixed vlan filterings are not supported.
vlan_filtering_is_globalis made as true inlan937x_setupfunction.Signed-off-by Prasanna Vengateshan <[email protected]>
Signature · 1 line
Florian