net: dsa: microchip: DSA driver support for LAN937x
Subsystems (6)
v13 cover net: dsa: microchip: DSA driver support for LAN937x
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 v13:
- Fixed the compilation issue in patch 5 and 6
Changes in v12:
- Removed the reduntant spi indirect enable in lan937x_init
- Used the ksz_port_stp_state_set function
- Apply rgmii internal delay only if it is rgmii port
- Set the bit for 100baseTx in phylink_get_caps
- Moved the ethtool related API from patch 5 to 7
- Moved lan_alu_entry struct in lan937x_dev.h from patch 5 to 9
- Moved lan_vlan_entry in lan937x_dev.h from patch 5 to 10
- Used the ksz_get_stats64 function for get_stats64 hook
- Splitted the patch 5. one for port configuration, spi driver, phy read & write and mtu configuration.
- Updated the indentation in ethernet-controller.yaml
- lan937x.yaml: Removed the blank lines, updated the ethernet handle to macb0. Added the rgmii internal delay only for the ports.
Changes in v11:
- Tagged as RFC to get the feedback for the subpatches 1/10, 5/10 and 6/10
Changes in v10:
- dsa.yaml: dropped moving mdio properties to dsa.yaml as per the feedback
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/#24787466
- microchip,lan937x.yaml: Naming convention changes in the example
- lan937x_main.c: Moving configurations from lan937x_reset_switch() to setup()
- lan937x_main.c: helper function has been introduced for lan937x_internal_phy_read & write
- lan937x_dev.h: lan_alu_struct struct data type changes
- lan937x_main.c: lan937x_get_stats64 make non blocking
- lan937x_main.c: modified lan937x_port_mirror_add to include extack
Changes in v9:
- lan937x_main.c: of_node_put() correction in lan937x_parse_dt_rgmii_delay
- lan937x_dev.c: removed the interface checks from lan937x_apply_rgmii_delay.
- changes in ethernet-controller.yaml and dsa.yaml
Changes in v8:
- lan937x_dev.c: fixed lan937x_r_mib_pkt warning in the sub patches
- lan937x_main.c: phylink_autoneg_inband() check removed in lan937x_phylink_mac_link_up()
- lan937x_main.c: made legacy_pre_march2020 = false as this is non-legacy driver and indentation correction in lan937x_phylink_mac_link_up()
- removed unnecessary parenthesis in lan937x_get_strings()
Changes in v7:
- microchip,lan937x.yaml: *-internal-delay-ps enum values & commit messages corrections
- lan937x_main.c: removed phylink_validate() and added phylink_get_caps()
- lan937x_main.c: added support for ethtool standard stats (get_eth_*_stats
and get_stats64)
- lan937x_main.c: removed unnecessary PVID read from lan937x_port_vlan_del()
- integrated the changes of ksz9477 multi bridging support to lan937x dev and tested both multi bridging and STP
- lan937x_port_vlan_del - dummy pvid read removed
Changes in v6:
- microchip_t1.c: There was new merge done in the net-next tree for microchip_1.c after the v5 submission. Hence rebased it for v6.
Changes in v5:
- microchip,lan937x.yaml: Added mdio properties detail
- microchip,lan937x.yaml: *-internal-delay-ps added under port node
- lan937x_dev.c: changed devm_mdiobus_alloc from of_mdiobus_register as suggested by Vladimir
- lan937x_dev.c: added dev_info for rgmii internal delay & error message to user in case of out of range values
- lan937x_dev.c: return -EOPNOTSUPP for C45 regnum values for lan937x_sw_mdio_read & write operations
- return from function with out storing in a variable
- lan937x_main.c: Added vlan_enable info in vlan_filtering API
- lan937x_main.c: lan937x_port_vlan_del: removed unintended PVID write
Changes in v4:
- tag_ksz.c: cpu_to_be16 to put_unaligned_be16
- correct spacing in comments
- tag_ksz.c: NETIF_F_HW_CSUM fix is integrated
- lan937x_dev.c: mdio_np is removed from global and handled locally
- lan937x_dev.c: unused functions removed lan937x_cfg32 & lan937x_port_cfg32
- lan937x_dev.c: lan937x_is_internal_100BTX_phy_port function name changes
- lan937x_dev.c: RGMII internal delay handling for MAC. Delay values are retrieved from DTS and updated
- lan937x_dev.c: corrected mutex operations for few dev variables
- microchip,lan937x.yaml: introduced rx-internal-delay-ps & tx-internal-delay-ps for RGMII internal delay
- lan937x_dev.c: Unnecessary mutex_lock has been removed
- lan937x_main.c: PHY_INTERFACE_MODE_NA handling for lan937x_phylink_validate
- lan937x_main.c: PORT_MIRROR_SNIFFER check in right place
- lan937x_main.c: memset is used instead of writing 0's individually in lan937x_port_fdb_add function
- lan937x_main.c: Removed \n from NL_SET_ERR_MSG_MOD calls
Changes in v3:
- Removed settings of cnt_ptr to zero and the memset() added a cleanup patch which moves this into ksz_init_mib_timer().
- Used ret everywhere instead of rc
- microchip,lan937x.yaml: Remove mdio compatible
- microchip_t1.c: Renaming standard phy registers
- tag_ksz.c: LAN937X_TAIL_TAG_OVERRIDE renaming LAN937X_TAIL_TAG_BLOCKING_OVERRIDE
- tag_ksz.c: Changed Ingress and Egress naming convention based on Host
- tag_ksz.c: converted to skb_mac_header(skb) from (is_link_local_ether_addr(hdr->h_dest))
- lan937x_dev.c: Removed BCAST Storm protection settings since we have Tc commands for them
- lan937x_dev.c: Flow control setting in lan937x_port_setup function
- lan937x_dev.c: RGMII internal delay added only for cpu port,
- lan937x_dev.c: of_get_compatible_child(node, "microchip,lan937x-mdio") to of_get_child_by_name(node, "mdio");
- lan937x_dev.c:lan937x_get_interface API: returned PHY_INTERFACE_MODE_INTERNAL instead of PHY_INTERFACE_MODE_NA
- lan937x_main.c: Removed compat interface implementation in lan937x_config_cpu_port() API & dev_info corrected as well
- lan937x_main.c: deleted ds->configure_vlan_while_not_filtering = true
- lan937x_main.c: Added explanation for lan937x_setup lines
- lan937x_main.c: FR_MAX_SIZE correction in lan937x_get_max_mtu API
- lan937x_main.c: removed lan937x_port_bridge_flags dummy functions
- lan937x_spi.c - mdiobus_unregister to be added to spi_remove function
- lan937x_main.c: phy link layer changes
- lan937x_main.c: port mirroring: sniff port selection limiting to one port
- lan937x_main.c: Changed to global vlan filtering
- lan937x_main.c: vlan_table array to structure
- lan937x_main.c -Use extack instead of reporting errors to Console
- lan937x_main.c - Remove cpu_port addition in vlan_add api
- lan937x_main.c - removed pvid resetting
Changes in v2:
- return check for register read/writes
- dt compatible compatible check is added against chip id value
- lan937x_internal_t1_tx_phy_write() is renamed to lan937x_internal_phy_write()
- lan937x_is_internal_tx_phy_port is renamed to lan937x_is_internal_100BTX_phy_port as it is 100Base-Tx phy
- Return value for lan937x_internal_phy_write() is -EOPNOTSUPP in case of failures
- Return value for lan937x_internal_phy_read() is 0xffff for non existent phy
- cpu_port checking is removed from lan937x_port_stp_state_set()
- lan937x_phy_link_validate: 100baseT_Full to 100baseT1_Full
- T1 Phy driver is moved to drivers/net/phy/microchip_t1.c
- Tx phy driver support will be added later
- Legacy switch checkings in dts file are removed.
- tag_ksz.c: Re-used ksz9477_rcv for lan937x_rcv
- tag_ksz.c: Xmit() & rcv() Comments are corrected w.r.to host
- net/dsa/Kconfig: Family skew numbers altered in ascending order
- microchip,lan937x.yaml: eth is replaced with ethernet
- microchip,lan937x.yaml: spi1 is replaced with spi
- microchip,lan937x.yaml: cpu labelling is removed
- microchip,lan937x.yaml: port@x value will match the reg value now
Arun Ramadoss (4):
net: dsa: microchip: add DSA support for microchip LAN937x
net: dsa: microchip: add support for phy read and write
net: dsa: microchip: add LAN937x SPI driver
net: dsa: microchip: add support for MTU configuration and fast_age
Prasanna Vengateshan (9):
dt-bindings: net: make internal-delay-ps based on phy-mode
dt-bindings: net: dsa: dt bindings for microchip lan937x
net: dsa: move mib->cnt_ptr reset code to ksz_common.c
net: dsa: tag_ksz: add tag handling for Microchip LAN937x
net: dsa: microchip: add 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 | 192 +++ .../bindings/net/ethernet-controller.yaml | 35 +- 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 | 4 + drivers/net/dsa/microchip/lan937x_dev.c | 738 ++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 121 ++ drivers/net/dsa/microchip/lan937x_main.c | 1242 +++++++++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 688 +++++++++ drivers/net/dsa/microchip/lan937x_spi.c | 236 ++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 4 +- net/dsa/tag_ksz.c | 59 + 17 files changed, 3332 insertions(+), 20 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml create mode 100644 drivers/net/dsa/microchip/lan937x_dev.c create mode 100644 drivers/net/dsa/microchip/lan937x_dev.h create mode 100644 drivers/net/dsa/microchip/lan937x_main.c create mode 100644 drivers/net/dsa/microchip/lan937x_reg.h create mode 100644 drivers/net/dsa/microchip/lan937x_spi.c
base-commit: a37f37a2e7f5ea3ae2a1278f552aa21a8e32c221
Signature · 1 line
2.33.0
PATCH v13 1/13 dt-bindings: net: make internal-delay-ps based on phy-mode
From: Prasanna Vengateshan <[email protected]>
*-internal-delay-ps properties would be applicable only for RGMII interface modes.
It is changed as per the request,
https://lore.kernel.org/netdev/[email protected]/
Ran dt_binding_check to confirm nothing is broken.
--- .../bindings/net/ethernet-controller.yaml | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-)
Documentation/devicetree/bindings/net/ethernet-controller.yaml +23 -12
@@ -133,12 +133,6 @@ properties: and is useful for determining certain configuration settings such as flow control thresholds. - rx-internal-delay-ps: - description: | - RGMII Receive Clock Delay defined in pico seconds. - This is used for controllers that have configurable RX internal delays. - If this property is present then the MAC applies the RX delay. - sfp: $ref: /schemas/types.yaml#/definitions/phandle description:
@@ -150,12 +144,6 @@ properties: The size of the controller\'s transmit fifo in bytes. This is used for components that can have configurable fifo sizes. - tx-internal-delay-ps: - description: | - RGMII Transmit Clock Delay defined in pico seconds. - This is used for controllers that have configurable TX internal delays. - If this property is present then the MAC applies the TX delay. - managed: description: Specifies the PHY management type. If auto is set and fixed-link
@@ -232,6 +220,29 @@ properties: required: - speed +allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id + then: + properties: + rx-internal-delay-ps: + description: + RGMII Receive Clock Delay defined in pico seconds.This is used for + controllers that have configurable RX internal delays. If this + property is present then the MAC applies the RX delay. + tx-internal-delay-ps: + description: + RGMII Transmit Clock Delay defined in pico seconds.This is used for + controllers that have configurable TX internal delays. If this + property is present then the MAC applies the TX delay. + additionalProperties: true ...
Signature · 1 line
2.33.0
PATCH v13 2/13 dt-bindings: net: dsa: dt bindings for microchip lan937x
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
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 | 192 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 193 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +192 -0
@@ -0,0 +1,192 @@ +# 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-9]+$": + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-id + - rgmii-txid + - rgmii-rxid + then: + properties: + rx-internal-delay-ps: + enum: [0, 2000] + default: 0 + tx-internal-delay-ps: + enum: [0, 2000] + default: 0 + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + macb0 { + #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"; + tx-internal-delay-ps = <2000>; + rx-internal-delay-ps = <2000>; + ethernet = <&macb0>; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + + port@5 { + reg = <5>; + label = "lan7"; + phy-mode = "rgmii"; + tx-internal-delay-ps = <2000>; + rx-internal-delay-ps = <2000>; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + + port@6 { + reg = <6>; + label = "lan5"; + phy-mode = "internal"; + phy-handle = <&t1phy6>; + }; + + port@7 { + reg = <7>; + label = "lan3"; + phy-mode = "internal"; + phy-handle = <&t1phy7>; + }; + }; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + t1phy0: ethernet-phy@0{ + reg = <0x0>; + }; + + t1phy1: ethernet-phy@1{ + reg = <0x1>; + }; + + t1phy2: ethernet-phy@2{ + reg = <0x2>; + }; + + t1phy3: ethernet-phy@3{ + reg = <0x3>; + }; + + t1phy6: ethernet-phy@6{ + reg = <0x6>; + }; + + t1phy7: ethernet-phy@7{ + reg = <0x7>; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -12909,6 +12909,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.33.0
PATCH v13 3/13 net: dsa: move mib->cnt_ptr reset code to ksz_common.c
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
mib->cnt_ptr resetting is handled in multiple places as part of port_init_cnt(). Hence moved mib->cnt_ptr code to ksz common layer and removed from individual product files.
--- drivers/net/dsa/microchip/ksz8795.c | 2 -- drivers/net/dsa/microchip/ksz9477.c | 3 --- drivers/net/dsa/microchip/ksz_common.c | 8 +++++++- 3 files changed, 7 insertions(+), 6 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +0 -2
@@ -468,8 +468,6 @@ static void ksz8_port_init_cnt(struct ksz_device *dev, int port) dropped, &mib->counters[mib->cnt_ptr]); ++mib->cnt_ptr; } - mib->cnt_ptr =0 ; -memset (mib->counters,0 , dev->mib_cnt *sizeof (u64)); }static void ksz8_r_table (struct ksz_device *dev,int table,u16 addr,u64 *data)
drivers/net/dsa/microchip/ksz9477.c +0 -3
@@ -316,9 +316,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
@@ -242,8 +242,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.33.0
PATCH v13 4/13 net: dsa: tag_ksz: add tag handling for Microchip LAN937x
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
The Microchip LAN937X switches have a tagging protocol which is very similar to KSZ tagging. So that the implementation is added to tag_ksz.c and reused common APIs
--- include/net/dsa.h | 2 ++ net/dsa/Kconfig | 4 ++-- net/dsa/tag_ksz.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-)
include/net/dsa.h +2 -0
@@ -53,6 +53,7 @@ struct phylink_link_state;#define DSA_TAG_PROTO_SJA1110_VALUE 23#define DSA_TAG_PROTO_RTL8_4_VALUE 24#define DSA_TAG_PROTO_RTL8_4T_VALUE 25 +#define DSA_TAG_PROTO_LAN937X_VALUE 26enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -81,6 +82,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_SJA1110 =DSA_TAG_PROTO_SJA1110_VALUE ,DSA_TAG_PROTO_RTL8_4 =DSA_TAG_PROTO_RTL8_4_VALUE ,DSA_TAG_PROTO_RTL8_4T =DSA_TAG_PROTO_RTL8_4T_VALUE , + DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +2 -2
@@ -87,10 +87,10 @@ config NET_DSA_TAG_MTK Mediatek switches. config NET_DSA_TAG_KSZ - tristate "Tag driver for Microchip 8795/9477/9893 families of switches" + tristate "Tag driver for Microchip 8795/937x/9477/9893 families of switches" help Say Y if you want to enable support for tagging frames for the - Microchip 8795/9477/9893 families of switches. + Microchip 8795/937x/9477/9893 families of switches. config NET_DSA_TAG_OCELOT tristate "Tag driver for Ocelot family of switches, using NPI port"
net/dsa/tag_ksz.c +59 -0
69 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH v13 5/13 net: dsa: microchip: add DSA support for microchip LAN937x
In reply to Arun RamadossBasic 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().
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 | 4 + drivers/net/dsa/microchip/ksz_common.h | 3 + drivers/net/dsa/microchip/lan937x_dev.c | 244 ++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 36 ++ drivers/net/dsa/microchip/lan937x_main.c | 216 +++++++ drivers/net/dsa/microchip/lan937x_reg.h | 688 +++++++++++++++++++++++ 7 files changed, 1203 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
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 +4 -0
@@ -6,3 +6,7 @@ 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
drivers/net/dsa/microchip/ksz_common.h +3 -0
@@ -42,6 +42,8 @@ struct ksz_port {struct ksz_port_mib mib;phy_interface_t interface;u16 max_frame; +u32 rgmii_tx_val; +u32 rgmii_rx_val; };struct ksz_device {
@@ -148,6 +150,7 @@ 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);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 +244 -0
244 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_dev.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Microchip lan937x dev ops headers +* Copyright (C) 2019-2021 Microchip Technology Inc. +*/ + +#ifndef __LAN937X_CFG_H +#define __LAN937X_CFG_H + +int lan937x_cfg (struct ksz_device *dev,u32 addr,u8 bits,bool set); +int lan937x_port_cfg (struct ksz_device *dev,int port,int offset, +u8 bits,bool set); +int lan937x_pread8 (struct ksz_device *dev,int port,int offset, +u8 *data); +int lan937x_pread16 (struct ksz_device *dev,int port,int offset, +u16 *data); +int lan937x_pread32 (struct ksz_device *dev,int port,int offset, +u32 *data); +int lan937x_pwrite8 (struct ksz_device *dev,int port, +int offset,u8 data); +int lan937x_pwrite16 (struct ksz_device *dev,int port, +int offset,u16 data); +int lan937x_pwrite32 (struct ksz_device *dev,int port, +int offset,u32 data); +bool lan937x_is_internal_phy_port (struct ksz_device *dev,int port); +bool lan937x_is_internal_base_tx_phy_port (struct ksz_device *dev,int port); +bool lan937x_is_internal_base_t1_phy_port (struct ksz_device *dev,int port); +bool lan937x_is_rgmii_port (struct ksz_device *dev,int port); +int lan937x_reset_switch (struct ksz_device *dev); +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); + +extern const struct dsa_switch_ops lan937x_switch_ops; +extern const struct ksz_dev_ops lan937x_dev_ops; + +#endif
drivers/net/dsa/microchip/lan937x_main.c new file +216 -0
216 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
Signature · 1 line
2.33.0
Re: [Patch net-next v13 05/13] net: dsa: microchip: add DSA support for microchip LAN937x
Quoted 15 lines · Arun Ramadoss
Basic DSA driver support for lan937x and the device will be configured through SPI interface.
drivers/net/dsa/microchip/path is already part ofMAINTAINERS& the new files come under this path. Hence no update needed to theMAINTAINERSReused KSZ APIs for
port_bridge_join()&port_bridge_leave()and added support forport_stp_state_set().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/
Quoted 6 lines
It supports standard delay 2ns only. If the property is not found, the value will be forced to 0.
Signed-off-by Prasanna Vengateshan <[email protected]>Signed-off-by Arun Ramadoss <[email protected]>---
PATCH v13 6/13 net: dsa: microchip: add support for phy read and write
In reply to Arun RamadossThis patch add support for the writing and reading of the phy registers. LAN937x uses the Vphy indirect addressing method for accessing the phys. And mdio bus is registered in this patch, mdio read and write inturn uses the vphy.
--- drivers/net/dsa/microchip/lan937x_dev.c | 198 ++++++++++++++++++++++- drivers/net/dsa/microchip/lan937x_dev.h | 4 + drivers/net/dsa/microchip/lan937x_main.c | 23 +++ 3 files changed, 223 insertions(+), 2 deletions(-)
drivers/net/dsa/microchip/lan937x_dev.c +196 -2
@@ -121,6 +121,36 @@ static void lan937x_switch_exit(struct ksz_device *dev)lan937x_reset_switch (dev); } +static int lan937x_enable_spi_indirect_access (struct ksz_device *dev) +{ +u16 data16; +u8 data8; +int ret; + + ret =ksz_read8 (dev,REG_GLOBAL_CTRL_0 , &data8); +if (ret <0 ) +return ret; + +/* Check if PHY register is blocked */ +if (data8 &SW_PHY_REG_BLOCK ) { +/* Enable Phy access through SPI */ + data8 &= ~SW_PHY_REG_BLOCK ; + + ret =ksz_write8 (dev,REG_GLOBAL_CTRL_0 , data8); +if (ret <0 ) +return ret; + } + + ret =ksz_read16 (dev,REG_VPHY_SPECIAL_CTRL__2 , &data16); +if (ret <0 ) +return ret; + +/* Allow SPI access */ + data16 |=VPHY_SPI_INDIRECT_ENABLE ; + +return ksz_write16 (dev,REG_VPHY_SPECIAL_CTRL__2 , data16); +} +static u32 lan937x_get_port_addr (int port,int offset) {return PORT_CTRL_ADDR (port, offset);
@@ -171,6 +201,88 @@ bool lan937x_is_internal_base_t1_phy_port(struct ksz_device *dev, int port)return false; } +static int lan937x_vphy_ind_addr_wr (struct ksz_device *dev,int addr,int reg) +{ +u16 temp, addr_base; + +if (lan937x_is_internal_base_tx_phy_port (dev, addr)) + addr_base =REG_PORT_TX_PHY_CTRL_BASE ; +else + addr_base =REG_PORT_T1_PHY_CTRL_BASE ; + +/* get register address based on the logical port */ + temp =PORT_CTRL_ADDR (addr, (addr_base + (reg <<2 ))); + +return ksz_write16 (dev,REG_VPHY_IND_ADDR__2 , temp); +} + +int lan937x_internal_phy_write (struct ksz_device *dev,int addr,int reg, +u16 val) +{ +unsigned int value; +int ret; + +/* Check for internal phy port */ +if (!lan937x_is_internal_phy_port (dev, addr)) +return -EOPNOTSUPP ; + + ret =lan937x_vphy_ind_addr_wr (dev, addr, reg); +if (ret <0 ) +return ret; + +/* Write the data to be written to the VPHY reg */ + ret =ksz_write16 (dev,REG_VPHY_IND_DATA__2 , val); +if (ret <0 ) +return ret; + +/* Write the Write En and Busy bit */ + ret =ksz_write16 (dev,REG_VPHY_IND_CTRL__2 , + (VPHY_IND_WRITE |VPHY_IND_BUSY )); +if (ret <0 ) +return ret; + + ret =regmap_read_poll_timeout (dev->regmap[1 ],REG_VPHY_IND_CTRL__2 , + value, !(value &VPHY_IND_BUSY ),10 , +1000 ); +if (ret <0 ) { +dev_err (dev->dev,"Failed to write phy register\n" ); +return ret; + } + +return 0 ; +} + +int lan937x_internal_phy_read (struct ksz_device *dev,int addr,int reg, +u16 *val) +{ +unsigned int value; +int ret; + +/* Check for internal phy port, return 0xffff for non-existent phy */ +if (!lan937x_is_internal_phy_port (dev, addr)) +return 0xffff ; + + ret =lan937x_vphy_ind_addr_wr (dev, addr, reg); +if (ret <0 ) +return ret; + +/* Write Read and Busy bit to start the transaction */ + ret =ksz_write16 (dev,REG_VPHY_IND_CTRL__2 ,VPHY_IND_BUSY ); +if (ret <0 ) +return ret; + + ret =regmap_read_poll_timeout (dev->regmap[1 ],REG_VPHY_IND_CTRL__2 , + value, !(value &VPHY_IND_BUSY ),10 , +1000 ); +if (ret <0 ) { +dev_err (dev->dev,"Failed to read phy register\n" ); +return ret; + } + +/* Read the VPHY register which has the PHY data */ +return ksz_read16 (dev,REG_VPHY_IND_DATA__2 , val); +} +void lan937x_port_setup (struct ksz_device *dev,int port,bool cpu_port) {struct dsa_switch *ds = dev->ds;
@@ -205,6 +317,73 @@ void lan937x_port_setup(struct ksz_device *dev, int port, bool cpu_port)lan937x_cfg_port_member (dev, port, member); } +static int lan937x_sw_mdio_read (struct mii_bus *bus,int addr,int regnum) +{ +struct ksz_device *dev = bus->priv; +u16 val; +int ret; + +if (regnum &MII_ADDR_C45 ) +return -EOPNOTSUPP ; + + ret =lan937x_internal_phy_read (dev, addr, regnum, &val); +if (ret <0 ) +return ret; + +return val; +} + +static int lan937x_sw_mdio_write (struct mii_bus *bus,int addr,int regnum, +u16 val) +{ +struct ksz_device *dev = bus->priv; + +if (regnum &MII_ADDR_C45 ) +return -EOPNOTSUPP ; + +return lan937x_internal_phy_write (dev, addr, regnum, val); +} + +static int lan937x_mdio_register (struct ksz_device *dev) +{ +struct dsa_switch *ds = dev->ds; +struct device_node *mdio_np; +struct mii_bus *bus; +int ret; + + mdio_np =of_get_child_by_name (dev->dev->of_node,"mdio" ); +if (!mdio_np) { +dev_err (ds->dev,"no MDIO bus node\n" ); +return -ENODEV ; + } + + bus =devm_mdiobus_alloc (ds->dev); +if (!bus) { +of_node_put (mdio_np); +return -ENOMEM ; + } + + bus->priv = dev; + bus->read = lan937x_sw_mdio_read; + bus->write = lan937x_sw_mdio_write; + bus->name ="lan937x slave smi" ; +snprintf (bus->id,MII_BUS_ID_SIZE ,"SMI-%d" , ds->index); + bus->parent = ds->dev; + bus->phy_mask = ~ds->phys_mii_mask; + + ds->slave_mii_bus = bus; + + ret =devm_of_mdiobus_register (ds->dev, bus, mdio_np); +if (ret) { +dev_err (ds->dev,"unable to register MDIO bus %s\n" , + bus->id); + } + +of_node_put (mdio_np); + +return ret; +} +static int lan937x_switch_init (struct ksz_device *dev) { dev->ds->ops = &lan937x_switch_ops;
@@ -227,10 +406,25 @@ static int lan937x_init(struct ksz_device *dev)int ret; ret =lan937x_switch_init (dev); -if (ret <0 ) +if (ret <0 ) {dev_err (dev->dev,"failed to initialize the switch" ); +return ret; + } -return ret; +/* enable Indirect Access from SPI to the VPHY registers */ + ret =lan937x_enable_spi_indirect_access (dev); +if (ret <0 ) { +dev_err (dev->dev,"failed to enable spi indirect access" ); +return ret; + } + + ret =lan937x_mdio_register (dev); +if (ret <0 ) { +dev_err (dev->dev,"failed to register the mdio" ); +return ret; + } + +return 0 ; }const struct ksz_dev_ops lan937x_dev_ops = {
drivers/net/dsa/microchip/lan937x_dev.h +4 -0
@@ -21,6 +21,10 @@ int lan937x_pwrite16(struct ksz_device *dev, int port, int offset, u16 data);int lan937x_pwrite32 (struct ksz_device *dev,int port,int offset,u32 data); +int lan937x_internal_phy_write (struct ksz_device *dev,int addr, +int reg,u16 val); +int lan937x_internal_phy_read (struct ksz_device *dev,int addr, +int reg,u16 *val);bool lan937x_is_internal_phy_port (struct ksz_device *dev,int port);bool lan937x_is_internal_base_tx_phy_port (struct ksz_device *dev,int port);bool lan937x_is_internal_base_t1_phy_port (struct ksz_device *dev,int port);
drivers/net/dsa/microchip/lan937x_main.c +23 -0
@@ -23,6 +23,27 @@ static enum dsa_tag_protocol lan937x_get_tag_protocol(struct dsa_switch *ds,return DSA_TAG_PROTO_LAN937X_VALUE ; } +static int lan937x_phy_read16 (struct dsa_switch *ds,int addr,int reg) +{ +struct ksz_device *dev = ds->priv; +u16 val; +int ret; + + ret =lan937x_internal_phy_read (dev, addr, reg, &val); +if (ret <0 ) +return ret; + +return val; +} + +static int lan937x_phy_write16 (struct dsa_switch *ds,int addr,int reg, +u16 val) +{ +struct ksz_device *dev = ds->priv; + +return lan937x_internal_phy_write (dev, addr, reg, val); +} +static void lan937x_port_stp_state_set (struct dsa_switch *ds,int port,u8 state) {
@@ -199,6 +220,8 @@ static int lan937x_setup(struct dsa_switch *ds)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, .port_bridge_join = ksz_port_bridge_join, .port_bridge_leave = ksz_port_bridge_leave,
Signature · 1 line
2.33.0
PATCH v13 7/13 net: dsa: microchip: add LAN937x SPI driver
In reply to Arun RamadossThis patch add the SPI driver for the LAN937x switches. It uses the lan937x_main.c and lan937x_dev.c functions.
--- drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/ksz_common.h | 1 + drivers/net/dsa/microchip/lan937x_dev.c | 7 + drivers/net/dsa/microchip/lan937x_spi.c | 236 ++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 drivers/net/dsa/microchip/lan937x_spi.c
drivers/net/dsa/microchip/Makefile +1 -0
@@ -10,3 +10,4 @@ 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 +1 -0
@@ -151,6 +151,7 @@ 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 +7 -0
@@ -386,8 +386,15 @@ static int lan937x_mdio_register(struct ksz_device *dev)static int lan937x_switch_init (struct ksz_device *dev) { +int ret; + dev->ds->ops = &lan937x_switch_ops; +/* Check device tree */ + ret =lan937x_check_device_id (dev); +if (ret <0 ) +return ret; + dev->port_mask = (1 << dev->port_cnt) -1 ; dev->ports = devm_kzalloc(dev->dev,
drivers/net/dsa/microchip/lan937x_spi.c new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
2.33.0
Vladimir Oltean
maintainerRe: [Patch net-next v13 07/13] net: dsa: microchip: add LAN937x SPI driver
Quoted 40 lines · Arun Ramadoss
This patch add the SPI driver for the LAN937x switches. It uses the
lan937x_main.candlan937x_dev.cfunctions.Signed-off-by Arun Ramadoss <[email protected]>--- drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/ksz_common.h | 1 + drivers/net/dsa/microchip/lan937x_dev.c | 7 + drivers/net/dsa/microchip/lan937x_spi.c | 236 ++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 drivers/net/dsa/microchip/lan937x_spi.cdrivers/net/dsa/microchip/Makefile +1
-0@@ -10,3 +10,4 @@ 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.odrivers/net/dsa/microchip/ksz_common.h +1
-0@@ -151,6 +151,7 @@ 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 +0
-0@@ -386,8 +386,15 @@ static int lan937x_mdio_register(struct ksz_device *dev)static int lan937x_switch_init (struct ksz_device *dev)
drivers/net/dsa/microchip/lan937x_dev.c static int lan937x_mdio_register(struct ksz_device *dev) · line 397
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_dev.c +7
-0{ +int ret; + dev->ds->ops = &lan937x_switch_ops; +/* Check device tree */ + ret =lan937x_check_device_id (dev); +if (ret <0 ) +return ret; +
Can't this be called from lan937x_spi_probe() directly, why do you need to go through lan937x_switch_register() first?
Quoted 3 lines
drivers/net/dsa/microchip/lan937x_dev.c +0
-0dev->port_mask = (1 << dev->port_cnt) -1 ; dev->ports = devm_kzalloc(dev->dev,
Re: [Patch net-next v13 07/13] net: dsa: microchip: add LAN937x SPI driver
Hi Vladimir,
Thanks for the comment.
Quoted 55 lines · Vladimir Oltean
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 51 lines · Arun Ramadoss
This patch add the SPI driver for the LAN937x switches. It uses the
lan937x_main.candlan937x_dev.cfunctions.Signed-off-by Arun Ramadoss <[email protected]>--- drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/ksz_common.h | 1 + drivers/net/dsa/microchip/lan937x_dev.c | 7 + drivers/net/dsa/microchip/lan937x_spi.c | 236 ++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 drivers/net/dsa/microchip/lan937x_spi.cdrivers/net/dsa/microchip/Makefile +0
-0@@ -10,3 +10,4 @@ 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.odrivers/net/dsa/microchip/Makefile +1
-0+lan937x-objs += lan937x_spi.odrivers/net/dsa/microchip/ksz_common.h +1
-0@@ -151,6 +151,7 @@ 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 +2
-0@@ -386,8 +386,15 @@ static int lan937x_mdio_register(struct ksz_device *dev)static int lan937x_switch_init (struct ksz_device *dev) { +int ret; + dev->ds->ops = &lan937x_switch_ops;
Quoted 9 lines
drivers/net/dsa/microchip/lan937x_dev.c static int lan937x_mdio_register(struct ksz_device *dev) · line 397
Quoted 5 lines
drivers/net/dsa/microchip/lan937x_dev.c +5
-0+/* Check device tree */ + ret =lan937x_check_device_id (dev); +if (ret <0 ) +return ret; +Can't this be called from
lan937x_spi_probe()directly, why do you need
to go throughlan937x_switch_register()first?
lan937x_check_device_id function compares the dev->chip_id with the lan937x_switch_chip array and populate the some of the parameters of struct ksz_dev. The dev->chip_id is populated using the dev->dev_ops-
Quoted 1 line
detect in the
ksz_switch_registerfunction. Iflan937x_check_device_id
needs to be called in spi_probe, then chip_id has to be identified as part of spi_probe function. Since ksz_switch_register handles the identifying the chip_id, checking the device_id is part of switch_init.
if (dev->dev_ops->detect(dev))
return -EINVAL;
ret = dev->dev_ops->init(dev);
if (ret)
return ret;
As per the comment, enable_spi_indirect_access function called twice
https://lore.kernel.org/netdev/20220408232557.b62l3lksotq5vuvm@skbuf/
I have removed the enable_spi_indirect_access in the lan937x_setup function in v13 patch 6. But it actually failed our regression. The SPI indirect is required for accessing the Internal phy registers. We have enabled it in lan937x_init before registering the mdio_register. We need it for reading the phy id.
And another place enabled in lan937x_setup after lan937x_switch_reset function. When I removed enabling in setup function, switch_reset disables the spi indirecting addressing. Because of that further phy register r/w fails. In Summary, we need to enable spi indirect access in both the places, one for mdio_register and another after switch_reset.
Can I enable it both the places? Kindly suggest.
Quoted 4 lines
Quoted 4 lines
drivers/net/dsa/microchip/lan937x_dev.c +0
-0dev->port_mask = (1 << dev->port_cnt) -1 ;dev->ports = devm_kzalloc(dev->dev,
Vladimir Oltean
maintainerRe: [Patch net-next v13 07/13] net: dsa: microchip: add LAN937x SPI driver
Quoted 24 lines · On Thu, May 05, 2022 at 10:32:17AM +0000, [email protected] wrote:
Quoted 6 lines
Quoted 6 lines
static int
lan937x_switch_init(struct ksz_device *dev){drivers/net/dsa/microchip/lan937x_dev.c +2
-0+int ret; + dev->ds->ops = &lan937x_switch_ops;Quoted 9 lines
drivers/net/dsa/microchip/lan937x_dev.c static int lan937x_mdio_register(struct ksz_device *dev) · line 397
Quoted 5 lines
drivers/net/dsa/microchip/lan937x_dev.c +5
-0+/* Check device tree */ + ret =lan937x_check_device_id (dev); +if (ret <0 ) +return ret; +Can't this be called from
lan937x_spi_probe()directly, why do you need
to go throughlan937x_switch_register()first?
lan937x_check_device_idfunction compares thedev->chip_idwith thelan937x_switch_chiparray and populate the some of the parameters of structksz_dev. Thedev->chip_idis populated using the dev->dev_ops-Quoted 1 line
detect in the
ksz_switch_registerfunction. Iflan937x_check_device_idneeds to be called in
spi_probe, thenchip_idhas to be identified as part ofspi_probefunction. Sinceksz_switch_registerhandles the identifying thechip_id, checking thedevice_idis part ofswitch_init.
Quoted 6 lines
if (
dev->dev_ops->detect(dev))return -EINVAL;ret =
dev->dev_ops->init(dev);
if (ret)return ret;
Whatever you do, please use a common pattern for all of ksz9477, ksz8, and your lan937x. This includes validation of chip id, placement of the chip_data and dev_ops structures, and reuse as much logic as possible. The key is to limit the chip-specific information to structured data (tables) wherever possible and let common code deal with them.
For example there is no reason why struct ksz_chip_data is redefined for every switch, why copying from "chip" to "dev" is duplicated for every switch, and yet, why every other switch copies from "chip" to "dev" in the "switch_init" function yet lan937x does it from "check_device_id". So much boilerplate, yet different in subtle ways, makes the code very unpleasant to review.
I'm sure you'll find a straightforward way to code up a probing function.
Quoted 14 lines
As per the comment,
enable_spi_indirect_accessfunction called twice
https://lore.kernel.org/netdev/20220408232557.b62l3lksotq5vuvm@skbuf/
I have removed theenable_spi_indirect_accessin thelan937x_setupfunction in v13 patch 6. But it actually failed our regression. The SPI indirect is required for accessing the Internal phy registers. We have enabled it inlan937x_initbefore registering themdio_register. We need it for reading the phy id.
And another place enabled inlan937x_setupafterlan937x_switch_resetfunction. When I removed enabling in setup function,switch_resetdisables the spi indirecting addressing. Because of that further phy register r/w fails. In Summary, we need to enable spi indirect access in both the places, one formdio_registerand another afterswitch_reset.
Quoted 1 line
Can I enable it both the places? Kindly suggest.
So you call lan937x_reset_switch() as the first thing in ds->ops->setup(), and this momentarily breaks the earlier MDIO bus setup done from probe -> ksz_switch_register() -> dev_ops->init().
So why don't you move the lan937x_enable_spi_indirect_access() and lan937x_mdio_register() calls to ds->ops->setup(), _after_ the switch soft reset, then?
PATCH v13 8/13 net: dsa: microchip: add support for MTU configuration and fast_age
In reply to Arun RamadossThis patch add the support for port_max_mtu, port_change_mtu and port_fast_age dsa functionality.
--- drivers/net/dsa/microchip/lan937x_dev.c | 31 +++++++++++++++++ drivers/net/dsa/microchip/lan937x_main.c | 44 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
drivers/net/dsa/microchip/lan937x_dev.c +31 -0
@@ -63,6 +63,36 @@ void lan937x_cfg_port_member(struct ksz_device *dev, int port, u8 member)lan937x_pwrite32 (dev, port,REG_PORT_VLAN_MEMBERSHIP__4 , member); } +static void lan937x_flush_dyn_mac_table (struct ksz_device *dev,int port) +{ +unsigned int value; +u8 data; + +regmap_update_bits (dev->regmap[0 ],REG_SW_LUE_CTRL_2 , +SW_FLUSH_OPTION_M <<SW_FLUSH_OPTION_S , +SW_FLUSH_OPTION_DYN_MAC <<SW_FLUSH_OPTION_S ); + +if (port < dev->port_cnt) { +/* flush individual port */ +lan937x_pread8 (dev, port,P_STP_CTRL , &data); +if (!(data &PORT_LEARN_DISABLE )) +lan937x_pwrite8 (dev, port,P_STP_CTRL , + (data |PORT_LEARN_DISABLE )); +lan937x_cfg (dev,S_FLUSH_TABLE_CTRL ,SW_FLUSH_DYN_MAC_TABLE , + true); + +regmap_read_poll_timeout (dev->regmap[0 ],S_FLUSH_TABLE_CTRL , + value, + !(value &SW_FLUSH_DYN_MAC_TABLE ),10 , +1000 ); + +lan937x_pwrite8 (dev, port,P_STP_CTRL , data); + }else { +/* flush all */ +lan937x_cfg (dev,S_FLUSH_TABLE_CTRL ,SW_FLUSH_STP_TABLE , true); + } +} +int lan937x_reset_switch (struct ksz_device *dev) {u32 data32;
@@ -437,6 +467,7 @@ static int lan937x_init(struct ksz_device *dev)const struct ksz_dev_ops lan937x_dev_ops = { .get_port_addr = lan937x_get_port_addr, .cfg_port_member = lan937x_cfg_port_member, + .flush_dyn_mac_table = lan937x_flush_dyn_mac_table, .port_setup = lan937x_port_setup, .shutdown = lan937x_reset_switch, .detect = lan937x_switch_detect,
drivers/net/dsa/microchip/lan937x_main.c +44 -0
62 lines not on this page · raw message
Signature · 1 line
2.33.0
Re: [Patch net-next v13 08/13] net: dsa: microchip: add support for MTU configuration and fast_age
Quoted 5 lines · Arun Ramadoss
This patch add the support for
port_max_mtu,port_change_mtuandport_fast_agedsa functionality.Signed-off-by Arun Ramadoss <[email protected]>---
PATCH v13 9/13 net: dsa: microchip: add support for phylink management
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
phylink_get_caps() is implemented and reused KSZ common 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 | 157 +++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 5 + drivers/net/dsa/microchip/lan937x_main.c | 66 ++++++++++ 3 files changed, 228 insertions(+)
drivers/net/dsa/microchip/lan937x_dev.c +157 -0
@@ -313,6 +313,163 @@ 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,u8 val) +{ +struct ksz_port *p = &dev->ports[port]; + +/* Clear Ingress & Egress internal delay enabled bits */ + val &= ~(PORT_RGMII_ID_EG_ENABLE |PORT_RGMII_ID_IG_ENABLE ); + +/* if the delay is 0, do not enable DLL */ +if (p->rgmii_tx_val) { +lan937x_update_rgmii_tx_rx_delay (dev, port, true); +dev_info (dev->dev,"Applied rgmii tx delay for the port %d\n" , + port); + val |=PORT_RGMII_ID_EG_ENABLE ; + } + +/* if the delay is 0, do not enable DLL */ +if (p->rgmii_rx_val) { +lan937x_update_rgmii_tx_rx_delay (dev, port, false); +dev_info (dev->dev,"Applied rgmii rx delay for the port %d\n" , + port); + val |=PORT_RGMII_ID_IG_ENABLE ; + } + +/* Enable RGMII internal delays */ +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_1 , val); +} + +void lan937x_mac_config (struct ksz_device *dev,int port, +phy_interface_t interface) +{ +u8 data8; + +lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_1 , &data8); + +/* clear MII selection & set it based on interface later */ + data8 &= ~PORT_MII_SEL_M ; + +/* configure MAC based on interface */ +switch (interface) { +case PHY_INTERFACE_MODE_MII : +lan937x_config_gbit (dev, false, &data8); + data8 |=PORT_MII_SEL ; +break ; +case PHY_INTERFACE_MODE_RMII : +lan937x_config_gbit (dev, false, &data8); + data8 |=PORT_RMII_SEL ; +break ; +case PHY_INTERFACE_MODE_RGMII : +case PHY_INTERFACE_MODE_RGMII_ID : +case PHY_INTERFACE_MODE_RGMII_TXID : +case PHY_INTERFACE_MODE_RGMII_RXID : +lan937x_config_gbit (dev, true, &data8); + data8 |=PORT_RGMII_SEL ; + +/* Apply rgmii internal delay for the mac */ +lan937x_apply_rgmii_delay (dev, port, data8); + +/* rgmii delay configuration is already applied above, +* hence return from here as no changes required +*/ +return ; +default : +dev_err (dev->dev,"Unsupported interface '%s' for port %d\n" , +phy_modes (interface), port); +return ; + } + +/* Write the updated value */ +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_1 , data8); +} + +void lan937x_config_interface (struct ksz_device *dev,int port, +int speed,int duplex, +bool tx_pause,bool rx_pause) +{ +u8 xmii_ctrl0, xmii_ctrl1; + +lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_0 , &xmii_ctrl0); +lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_1 , &xmii_ctrl1); + +switch (speed) { +case SPEED_1000 : +lan937x_config_gbit (dev, true, &xmii_ctrl1); +break ; +case SPEED_100 : +lan937x_config_gbit (dev, false, &xmii_ctrl1); + xmii_ctrl0 |=PORT_MAC_SPEED_100 ; +break ; +case SPEED_10 : +lan937x_config_gbit (dev, false, &xmii_ctrl1); + xmii_ctrl0 &= ~PORT_MAC_SPEED_100 ; +break ; +default : +dev_err (dev->dev,"Unsupported speed on port %d: %d\n" , + port, speed); +return ; + } + +if (duplex) + xmii_ctrl0 |=PORT_FULL_DUPLEX ; +else + xmii_ctrl0 &= ~PORT_FULL_DUPLEX ; + +if (tx_pause) + xmii_ctrl0 |=PORT_TX_FLOW_CTRL ; +else + xmii_ctrl1 &= ~PORT_TX_FLOW_CTRL ; + +if (rx_pause) + xmii_ctrl0 |=PORT_RX_FLOW_CTRL ; +else + xmii_ctrl0 &= ~PORT_RX_FLOW_CTRL ; + +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_0 , xmii_ctrl0); +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_1 , xmii_ctrl1); +} +void lan937x_port_setup (struct ksz_device *dev,int port,bool cpu_port) {struct dsa_switch *ds = dev->ds;
drivers/net/dsa/microchip/lan937x_dev.h +5 -0
@@ -33,6 +33,11 @@ int lan937x_reset_switch(struct ksz_device *dev);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); +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);extern const struct dsa_switch_ops lan937x_switch_ops;extern const struct ksz_dev_ops lan937x_dev_ops;
drivers/net/dsa/microchip/lan937x_main.c +66 -0
78 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH v13 10/13 net: dsa: microchip: add support for ethtool port counters
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
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 for get_strings()
--- drivers/net/dsa/microchip/lan937x_dev.c | 107 +++++++++++++++++++++- drivers/net/dsa/microchip/lan937x_dev.h | 47 ++++++++++ drivers/net/dsa/microchip/lan937x_main.c | 109 +++++++++++++++++++++++ 3 files changed, 262 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/lan937x_dev.c +106 -1
@@ -16,6 +16,45 @@#include "ksz_common.h" #include "lan937x_dev.h" +const struct mib_names lan937x_mib_names[] = { + {0x00 ,"rx_hi" }, + {0x01 ,"rx_undersize" }, + {0x02 ,"rx_fragments" }, + {0x03 ,"rx_oversize" }, + {0x04 ,"rx_jabbers" }, + {0x05 ,"rx_symbol_err" }, + {0x06 ,"rx_crc_err" }, + {0x07 ,"rx_align_err" }, + {0x08 ,"rx_mac_ctrl" }, + {0x09 ,"rx_pause" }, + {0x0A ,"rx_bcast" }, + {0x0B ,"rx_mcast" }, + {0x0C ,"rx_ucast" }, + {0x0D ,"rx_64_or_less" }, + {0x0E ,"rx_65_127" }, + {0x0F ,"rx_128_255" }, + {0x10 ,"rx_256_511" }, + {0x11 ,"rx_512_1023" }, + {0x12 ,"rx_1024_1522" }, + {0x13 ,"rx_1523_2000" }, + {0x14 ,"rx_2001" }, + {0x15 ,"tx_hi" }, + {0x16 ,"tx_late_col" }, + {0x17 ,"tx_pause" }, + {0x18 ,"tx_bcast" }, + {0x19 ,"tx_mcast" }, + {0x1A ,"tx_ucast" }, + {0x1B ,"tx_deferred" }, + {0x1C ,"tx_total_col" }, + {0x1D ,"tx_exc_col" }, + {0x1E ,"tx_single_col" }, + {0x1F ,"tx_mult_col" }, + {0x80 ,"rx_total" }, + {0x81 ,"tx_total" }, + {0x82 ,"rx_discards" }, + {0x83 ,"tx_discards" }, +}; +int lan937x_cfg (struct ksz_device *dev,u32 addr,u8 bits,bool set) {return regmap_update_bits (dev->regmap[0 ], addr, bits, set ? bits :0 );
@@ -93,6 +132,53 @@ static void lan937x_flush_dyn_mac_table(struct ksz_device *dev, int port) } } +static void lan937x_r_mib_cnt (struct ksz_device *dev,int port,u16 addr, +u64 *cnt) +{ +unsigned int val; +u32 data; +int ret; + +/* Enable MIB Counter read */ + data =MIB_COUNTER_READ ; + data |= (addr <<MIB_COUNTER_INDEX_S ); +lan937x_pwrite32 (dev, port,REG_PORT_MIB_CTRL_STAT , data); + + ret =regmap_read_poll_timeout (dev->regmap[2 ], +PORT_CTRL_ADDR (port, +REG_PORT_MIB_CTRL_STAT ), + val, !(val &MIB_COUNTER_READ ), +10 ,1000 ); +if (ret) { +dev_err (dev->dev,"Failed to get MIB\n" ); +return ; + } + +/* count resets upon read */ +lan937x_pread32 (dev, port,REG_PORT_MIB_DATA , &data); + *cnt += data; +} + +void lan937x_r_mib_pkt (struct ksz_device *dev,int port,u16 addr, +u64 *dropped,u64 *cnt) +{ + addr = lan937x_mib_names[addr].index; +lan937x_r_mib_cnt (dev, port, addr, cnt); +} + +static void lan937x_port_init_cnt (struct ksz_device *dev,int port) +{ +struct ksz_port_mib *mib = &dev->ports[port].mib; + +/* flush all enabled port MIB counters */ +mutex_lock (&mib->cnt_mutex); +lan937x_pwrite32 (dev, port,REG_PORT_MIB_CTRL_STAT , +MIB_COUNTER_FLUSH_FREEZE ); +ksz_write8 (dev,REG_SW_MAC_CTRL_6 ,SW_MIB_COUNTER_FLUSH ); +lan937x_pwrite32 (dev, port,REG_PORT_MIB_CTRL_STAT ,0 ); +mutex_unlock (&mib->cnt_mutex); +} +int lan937x_reset_switch (struct ksz_device *dev) {u32 data32;
@@ -573,7 +659,7 @@ static int lan937x_mdio_register(struct ksz_device *dev)static int lan937x_switch_init (struct ksz_device *dev) { -int ret; +int i, ret; dev->ds->ops = &lan937x_switch_ops;
@@ -584,12 +670,27 @@ static int lan937x_switch_init(struct ksz_device *dev) dev->port_mask = (1 << dev->port_cnt) -1 ; + dev->reg_mib_cnt =SWITCH_COUNTER_NUM ; + dev->mib_cnt =ARRAY_SIZE (lan937x_mib_names); + dev->ports =devm_kzalloc (dev->dev, dev->port_cnt *sizeof (struct ksz_port ),GFP_KERNEL );if (!dev->ports)return -ENOMEM ; +for (i =0 ; i < dev->port_cnt; i++) { +spin_lock_init (&dev->ports[i].mib.stats64_lock); +mutex_init (&dev->ports[i].mib.cnt_mutex); + dev->ports[i].mib.counters = +devm_kzalloc (dev->dev, +sizeof (u64) * (dev->mib_cnt +1 ), +GFP_KERNEL ); + +if (!dev->ports[i].mib.counters) +return -ENOMEM ; + } +/* set the real number of ports */ dev->ds->num_ports = dev->port_cnt;return 0 ;
@@ -626,6 +727,10 @@ const struct ksz_dev_ops lan937x_dev_ops = { .cfg_port_member = lan937x_cfg_port_member, .flush_dyn_mac_table = lan937x_flush_dyn_mac_table, .port_setup = lan937x_port_setup, + .r_mib_cnt = lan937x_r_mib_cnt, + .r_mib_pkt = lan937x_r_mib_pkt, + .port_init_cnt = lan937x_port_init_cnt, + .r_mib_stat64 = ksz_r_mib_stats64, .shutdown = lan937x_reset_switch, .detect = lan937x_switch_detect, .init = lan937x_init,
drivers/net/dsa/microchip/lan937x_dev.h +47 -0
55 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_main.c +109 -0
133 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH v13 11/13 net: dsa: microchip: add support for port mirror operations
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
Added support for port_mirror_add() and port_mirror_del operations
Sniffing is limited to one port & alert the user if any new sniffing port is selected
--- drivers/net/dsa/microchip/lan937x_main.c | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +83 -0
@@ -65,6 +65,87 @@ static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port,ksz_port_stp_state_set (ds, port, state,P_STP_CTRL ); } +static int lan937x_port_mirror_add (struct dsa_switch *ds,int port, +struct dsa_mall_mirror_tc_entry *mirror, +bool ingress,struct netlink_ext_ack *extack) +{ +struct ksz_device *dev = ds->priv; +int ret, p; +u8 data; + +/* Limit to one sniffer port +* Check if any of the port is already set for sniffing +* If yes, instruct the user to remove the previous entry & exit +*/ +for (p =0 ; p < dev->port_cnt; p++) { +/* Skip the current sniffing port */ +if (p == mirror->to_local_port) +continue ; + + ret =lan937x_pread8 (dev, p,P_MIRROR_CTRL , &data); +if (ret <0 ) +return ret; + +if (data &PORT_MIRROR_SNIFFER ) { +NL_SET_ERR_MSG_MOD (extack, +"Sniffer port is already configured, delete existing rules & retry" ); +return -EBUSY ; + } + } + +/* Configure ingress/egress mirroring */ +if (ingress) + ret =lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_RX , + true); +else + ret =lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_TX , + true); +if (ret <0 ) +return ret; + +/* Configure sniffer port as other ports do not have +* PORT_MIRROR_SNIFFER is set +*/ + ret =lan937x_port_cfg (dev, mirror->to_local_port,P_MIRROR_CTRL , +PORT_MIRROR_SNIFFER , true); +if (ret <0 ) +return ret; + +return lan937x_cfg (dev,S_MIRROR_CTRL ,SW_MIRROR_RX_TX , false); +} + +static void lan937x_port_mirror_del (struct dsa_switch *ds,int port, +struct dsa_mall_mirror_tc_entry *mirror) +{ +struct ksz_device *dev = ds->priv; +bool in_use = false; +u8 data; +int p; + +/* clear ingress/egress mirroring port */ +if (mirror->ingress) +lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_RX , + false); +else +lan937x_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_TX , + false); + +/* Check if any of the port is still referring to sniffer port */ +for (p =0 ; p < dev->port_cnt; p++) { +lan937x_pread8 (dev, p,P_MIRROR_CTRL , &data); + +if ((data & (PORT_MIRROR_RX |PORT_MIRROR_TX ))) { + in_use = true; +break ; + } + } + +/* delete sniffing if there are no other mirroring rule exist */ +if (!in_use) +lan937x_port_cfg (dev, mirror->to_local_port,P_MIRROR_CTRL , +PORT_MIRROR_SNIFFER , false); +} +static void lan937x_config_cpu_port (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv;
@@ -439,6 +520,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.33.0
PATCH v13 12/13 net: dsa: microchip: add support for fdb and mdb management
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
Support 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 up to 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_dev.h | 19 + drivers/net/dsa/microchip/lan937x_main.c | 515 +++++++++++++++++++++++ 2 files changed, 534 insertions(+)
drivers/net/dsa/microchip/lan937x_dev.h +19 -0
@@ -85,6 +85,25 @@ enum lan937x_mib_list { lan937x_mib_tx_discard, }; +struct lan_alu_struct { +/* entry 1 */ +u32 is_static:1 ; +u32 is_src_filter:1 ; +u32 is_dst_filter:1 ; +u32 prio_age:3 ; +u32 _reserv_0_1:23 ; +u32 mstp:3 ; +/* entry 2 */ +u32 is_override:1 ; +u32 is_use_fid:1 ; +u32 _reserv_1_1:22 ; +u32 port_forward:8 ; +/* entry 3 & 4*/ +u32 _reserv_2_1:9 ; +u32 fid:7 ; +u8 mac[ETH_ALEN ]; +}; +extern const struct dsa_switch_ops lan937x_switch_ops;extern const struct ksz_dev_ops lan937x_dev_ops;extern const struct mib_names lan937x_mib_names[];
drivers/net/dsa/microchip/lan937x_main.c +515 -0
533 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH v13 13/13 net: dsa: microchip: add support for vlan operations
In reply to Arun RamadossFrom: Prasanna Vengateshan <[email protected]>
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_global is made as true in lan937x_setup function.
--- drivers/net/dsa/microchip/lan937x_dev.h | 10 ++ drivers/net/dsa/microchip/lan937x_main.c | 186 +++++++++++++++++++++++ 2 files changed, 196 insertions(+)
drivers/net/dsa/microchip/lan937x_dev.h +10 -0
@@ -104,6 +104,16 @@ struct lan_alu_struct {u8 mac[ETH_ALEN ]; }; +struct lan937x_vlan { +/* entry 1 */ +bool valid; +u8 fid; +/* entry 2 */ +u32 untag_prtmap; +/* entry 3 */ +u32 fwd_map; +}; +extern const struct dsa_switch_ops lan937x_switch_ops;extern const struct ksz_dev_ops lan937x_dev_ops;extern const struct mib_names lan937x_mib_names[];
drivers/net/dsa/microchip/lan937x_main.c +186 -0
210 lines not on this page · raw message
Signature · 1 line
2.33.0