net: dsa: microchip: DSA driver support for LAN937x switch
Subsystems (7)
v4 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 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 | 160 ++ 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 | 725 +++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 80 + drivers/net/dsa/microchip/lan937x_main.c | 1310 +++++++++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 683 +++++++++ drivers/net/dsa/microchip/lan937x_spi.c | 227 +++ drivers/net/phy/microchip_t1.c | 339 ++++- include/net/dsa.h | 2 + net/dsa/Kconfig | 4 +- net/dsa/tag_ksz.c | 59 + 17 files changed, 3554 insertions(+), 71 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.27.0
PATCH v4 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.
Introduced rx-internal-delay-ps & tx-internal-delay-ps for RGMII internal delay along with min/max values. This is to address the Vladimir proposal from the previous revision.
Hence Reviewed-by tag is not added as it needs a review again.
--- .../bindings/net/dsa/microchip,lan937x.yaml | 160 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 161 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +160 -0
@@ -0,0 +1,160 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/microchip,lan937x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LAN937x Ethernet Switch Series Tree Bindings + +maintainers: + - [email protected] + +allOf: + - $ref: dsa.yaml# + +properties: + compatible: + enum: + - microchip,lan9370 + - microchip,lan9371 + - microchip,lan9372 + - microchip,lan9373 + - microchip,lan9374 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 50000000 + + reset-gpios: + description: Optional gpio specifier for a reset line + maxItems: 1 + + rx-internal-delay-ps: + description: Delay is in pico seconds + minimum: 2170 + maximum: 4000 + default: 0 + + tx-internal-delay-ps: + description: Delay is in pico seconds + minimum: 2170 + maximum: 4000 + default: 0 + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + //Ethernet switch connected via spi to the host + ethernet { + #address-cells = <1>; + #size-cells = <0>; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + + spi { + #address-cells = <1>; + #size-cells = <0>; + + lan9374: switch@0 { + compatible = "microchip,lan9374"; + reg = <0>; + + spi-max-frequency = <44000000>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&t1phy0>; + }; + port@1 { + reg = <1>; + label = "lan2"; + phy-mode = "internal"; + phy-handle = <&t1phy1>; + }; + port@2 { + reg = <2>; + label = "lan4"; + phy-mode = "internal"; + phy-handle = <&t1phy2>; + }; + port@3 { + reg = <3>; + label = "lan6"; + phy-mode = "internal"; + phy-handle = <&t1phy3>; + }; + port@4 { + reg = <4>; + phy-mode = "rgmii"; + ethernet = <ðernet>; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + port@5 { + reg = <5>; + label = "lan7"; + phy-mode = "rgmii"; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + port@6 { + reg = <6>; + label = "lan5"; + phy-mode = "internal"; + phy-handle = <&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
@@ -12286,6 +12286,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.27.0
Andrew Lunn
maintainerRe: [PATCH v4 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Quoted 34 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +34
-0+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>; + };
...
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml line 142
Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +7
-0+ mdio { + #address-cells = <1>; + #size-cells = <0>; + + t1phy0: ethernet-phy@0{ + reg = <0x0>; + };
Does this pass Rob's DT schema proof tools? You don't have any description of the mdio properties.
Maybe look at nxp,sja1105.yaml
Andrew
Rob Herring
maintainerRe: [PATCH v4 net-next 01/10] dt-bindings: net: dsa: dt bindings for microchip lan937x
Quoted 45 lines · Andrew Lunn
Quoted 34 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +34
-0+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>; + };...
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml line 142
Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml new file +7
-0+ mdio { + #address-cells = <1>; + #size-cells = <0>; + + t1phy0: ethernet-phy@0{ + reg = <0x0>; + };
Quoted 2 lines
Does this pass Rob's DT schema proof tools? You don't have any description of the mdio properties.
Good catch. It will pass ATM only because 'unevaluatedProperties' is not yet implemented (should be in place soon). So it needs:
mdio:
$ref: /schemas/net/mdio.yaml#
unevaluatedProperties: false
Otherwise, this looks fine.
Rob
PATCH v4 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
@@ -447,8 +447,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
@@ -289,9 +289,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
@@ -103,8 +103,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.27.0
PATCH v4 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 | 339 +++++++++++++++++++++++++++------ 1 file changed, 276 insertions(+), 63 deletions(-)
drivers/net/phy/microchip_t1.c +276 -63
@@ -30,15 +30,59 @@#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#define PHYACC_ATTR_BANK_PCS 2#define PHYACC_ATTR_BANK_AFE 3 +#define PHYACC_ATTR_BANK_DSP 4#define PHYACC_ATTR_BANK_MAX 7 +#define T1_M_CTRL_REG 0x09 +#define T1_M_CFG BIT(11) + +#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;
@@ -51,12 +95,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);
@@ -66,16 +114,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;
@@ -104,64 +179,159 @@ 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_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 }, + {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 }, +/* 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_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 ) {
@@ -169,6 +339,11 @@ static int lan87xx_phy_init(struct phy_device *phydev) init[i].offset, init[i].val, init[i].mask); + }else 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);
@@ -223,32 +398,70 @@ 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 ; } -static struct phy_driver microchip_t1_phy_driver[] = { - { - .phy_id =0x0007c150 , - .phy_id_mask =0xfffffff0 , - .name ="Microchip LAN87xx T1" , +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" , + .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, + }, + { + .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.27.0
PATCH v4 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
@@ -51,6 +51,7 @@ struct phylink_link_state;#define DSA_TAG_PROTO_SEVILLE_VALUE 21#define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22#define DSA_TAG_PROTO_SJA1110_VALUE 23 +#define DSA_TAG_PROTO_LAN937X_VALUE 24enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -77,6 +78,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_OCELOT_8021Q =DSA_TAG_PROTO_OCELOT_8021Q_VALUE ,DSA_TAG_PROTO_SEVILLE =DSA_TAG_PROTO_SEVILLE_VALUE ,DSA_TAG_PROTO_SJA1110 =DSA_TAG_PROTO_SJA1110_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_RTL4_A tristate "Tag driver for Realtek 4 byte protocol A tags"
net/dsa/tag_ksz.c +59 -0
69 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH v4 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]>---
PATCH v4 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/
Min and max values of RGMII internal delay are arrived from characterisation results. 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 | 576 +++++++++++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 75 +++ drivers/net/dsa/microchip/lan937x_main.c | 397 +++++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 683 +++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_spi.c | 227 ++++++++ 8 files changed, 1980 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
@@ -41,6 +41,8 @@ struct ksz_port {struct ksz_port_mib mib;phy_interface_t interface; +u8 rgmii_tx_val; +u8 rgmii_rx_val; };struct ksz_device {
@@ -146,6 +148,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 +576 -0
576 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_dev.h new file +75 -0
75 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_main.c new file +397 -0
397 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_reg.h new file +683 -0
683 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_spi.c new file +227 -0
227 lines not on this page · raw message
Signature · 1 line
2.27.0
Vladimir Oltean
maintainerRe: [PATCH v4 net-next 05/10] net: dsa: microchip: add DSA support for microchip lan937x
Quoted 14 lines · Prasanna Vengateshan
drivers/net/dsa/microchip/lan937x_dev.c new file +14
-0+static int lan937x_mdio_register (struct dsa_switch *ds) +{ +struct device_node *mdio_np; +int ret; + + mdio_np =of_get_child_by_name (ds->dev->of_node,"mdio" ); +if (!mdio_np) { +dev_err (ds->dev,"no MDIO bus node\n" ); +return -ENODEV ; + } + + ds->slave_mii_bus =devm_mdiobus_alloc (ds->dev); +if (!ds->slave_mii_bus) +return -ENOMEM ;
drivers/net/dsa/microchip/lan937x_dev.c line 489
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_dev.c new file +10
-0+ + ds->slave_mii_bus->priv = ds->priv; + ds->slave_mii_bus->read = lan937x_sw_mdio_read; + ds->slave_mii_bus->write = lan937x_sw_mdio_write; + ds->slave_mii_bus->name ="lan937x slave smi" ; +snprintf (ds->slave_mii_bus->id,MII_BUS_ID_SIZE ,"SMI-%d" , ds->index); + ds->slave_mii_bus->parent = ds->dev; + ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask; + + ret =of_mdiobus_register (ds->slave_mii_bus, mdio_np);
Please use devm_of_mdiobus_register if you're going to use devm_mdiobus_alloc, or no devres at all.
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 8 lines
drivers/net/dsa/microchip/lan937x_dev.c new file +8
-0+if (ret) { +dev_err (ds->dev,"unable to register MDIO bus %s\n" , + ds->slave_mii_bus->id); + } + +of_node_put (mdio_np); + +return ret;
drivers/net/dsa/microchip/lan937x_dev.c
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_dev.c new file +10
-0+} + +static phy_interface_t lan937x_get_interface (struct ksz_device *dev,int port) +{ +phy_interface_t interface; +u8 data8; +int ret; + +if (lan937x_is_internal_phy_port (dev, port)) +return PHY_INTERFACE_MODE_NA ;
Typically we use PHY_INTERFACE_MODE_INTERNAL.
Quoted 42 lines
drivers/net/dsa/microchip/lan937x_main.c new file +42
-0+ +/* read interface from REG_PORT_XMII_CTRL_1 register */ + ret =lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_1 , &data8); +if (ret <0 ) +return PHY_INTERFACE_MODE_NA ; + +switch (data8 &PORT_MII_SEL_M ) { +case PORT_RMII_SEL : + interface =PHY_INTERFACE_MODE_RMII ; +break ; +case PORT_RGMII_SEL : + interface =PHY_INTERFACE_MODE_RGMII ; +if (data8 &PORT_RGMII_ID_EG_ENABLE ) + interface =PHY_INTERFACE_MODE_RGMII_TXID ; +if (data8 &PORT_RGMII_ID_IG_ENABLE ) { + interface =PHY_INTERFACE_MODE_RGMII_RXID ; +if (data8 &PORT_RGMII_ID_EG_ENABLE ) + interface =PHY_INTERFACE_MODE_RGMII_ID ; + } +break ; +case PORT_MII_SEL : +default : +/* Interface is MII */ + interface =PHY_INTERFACE_MODE_MII ; +break ; + } + +return interface; +} + +static void lan937x_config_cpu_port (struct dsa_switch *ds) +{ +struct ksz_device *dev = ds->priv; +struct ksz_port *p; +int i; + + ds->num_ports = dev->port_cnt; + +for (i =0 ; i < dev->port_cnt; i++) { +if (dsa_is_cpu_port (ds, i) && (dev->cpu_ports & (1 << i))) { +phy_interface_t interface; +
drivers/net/dsa/microchip/lan937x_main.c line 172
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_main.c new file +10
-0+ dev->cpu_port = i; + dev->host_mask = (1 << dev->cpu_port); + dev->port_mask |= dev->host_mask; + p = &dev->ports[i]; + +/* Check if the device tree have specific interface +* setting otherwise read & assign from XMII register +* for host port interface +*/ + interface =lan937x_get_interface (dev, i);
What does the CPU port have so special that you override it here? Again some compatibility with out-of-tree DT bindings?
Quoted 15 lines
drivers/net/dsa/microchip/lan937x_main.c new file +15
-0+if (!p->interface) + p->interface = interface; + +dev_info (dev->dev, +"Port%d: using phy mode %s\n" , + i, +phy_modes (p->interface)); + +/* enable cpu port */ +lan937x_port_setup (dev, i, true); + p->vid_member = dev->port_mask; + } + } + +static u8 lan937x_rgmii_dly_reg_val (int port,u32 val)
drivers/net/dsa/microchip/lan937x_main.c line 213
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_main.c new file +10
-0+{ +u8 reg_val; + +/* force minimum delay if delay is less than min delay */ +if (val && val <2170 ) + val =2170 ; + +/* maximum delay is 4ns */ +if (val >4000 ) + val =4000 ;
These bindings are new. Given that you also document their min and max values, why don't you just error out on out-of-range values instead of silently doing what you think is going to be fine?
Re: [PATCH v4 net-next 05/10] net: dsa: microchip: add DSA support for microchip lan937x
Quoted 4 lines · Vladimir Oltean
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
On Thu, Oct 07, 2021 at 08:41:55PM +0530, Prasanna Vengateshan wrote:
Quoted 8 lines
drivers/net/dsa/microchip/lan937x_dev.c line 489
Quoted 4 lines
drivers/net/dsa/microchip/lan937x_dev.c new file +3
-0+static int lan937x_mdio_register (struct dsa_switch *ds) + + ret = of_mdiobus_register(ds->slave_mii_bus, mdio_np);Please use
devm_of_mdiobus_registerif you're going to usedevm_mdiobus_alloc, or no devres at all.
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Sure, Will change it to devm_of_mdiobus_register.
Quoted 8 lines
Quoted 7 lines
+
+ /* Check if the device tree have specific interface + * setting otherwise read & assign from XMII register + * for host port interface
+ */
+ interface =lan937x_get_interface(dev, i);
Quoted 4 lines
What does the CPU port have so special that you override it here? Again some compatibility with out-of-tree DT bindings?
Quoted 1 line
Device strapping method cannot be used since the phy-mode is expected to be present in the DT. So above assignment have to be removed along with lan937x_get_interface function.
Quoted 8 lines
Quoted 4 lines
+
+ /* maximum delay is 4ns */
+ if (val > 4000)
+ val = 4000;These bindings are new. Given that you also document their min and max values, why don't you just error out on out-of-range values instead of silently doing what you think is going to be fine?
Sure, i think the driver can also notify rx/tx internal delay applied message using dev_info.
Andrew Lunn
maintainerRe: [PATCH v4 net-next 05/10] net: dsa: microchip: add DSA support for microchip lan937x
In reply to Prasanna Vengateshandrivers/net/dsa/microchip/lan937x_dev.c line 450
Quoted 6 lines
drivers/net/dsa/microchip/lan937x_dev.c new file +6
-0+static int lan937x_sw_mdio_read (struct mii_bus *bus,int addr,int regnum) +{ +struct ksz_device *dev = bus->priv; +u16 val; +int ret; +
It would be good to check for C45 regnum values and return -EOPNOTSUPP.
drivers/net/dsa/microchip/lan937x_dev.c line 462
Quoted 12 lines
drivers/net/dsa/microchip/lan937x_dev.c new file +12
-0+ 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; +
Same here.
Andrew
PATCH v4 6/10 net: dsa: microchip: add support for phylink management
In reply to Prasanna VengateshanSupport for phylink_validate() 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 | 149 +++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_dev.h | 5 + drivers/net/dsa/microchip/lan937x_main.c | 98 +++++++++++++++ 3 files changed, 252 insertions(+)
drivers/net/dsa/microchip/lan937x_dev.c +149 -0
@@ -405,6 +405,155 @@ int lan937x_internal_phy_read(struct ksz_device *dev, int addr, int reg,return ret; } +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_delay (struct ksz_device *dev,int port, +bool is_tx) +{ +struct ksz_port *p = &dev->ports[port]; +u16 data16; +int reg; + +/* choose register based on tx/rx */ +if (is_tx) + reg =REG_PORT_XMII_CTRL_5 ; +else + reg =REG_PORT_XMII_CTRL_4 ; + +lan937x_pread16 (dev, port, reg, &data16); + +/* clear tune Adjust */ + data16 &= ~PORT_TUNE_ADJ ; + + data16 |= (p->rgmii_tx_val <<7 ); + +/* write tune Adjust */ +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) +{ +struct ksz_port *p = &dev->ports[port]; +u8 data8; + +/* clear the bits */ +lan937x_pread8 (dev, port,REG_PORT_XMII_CTRL_1 , &data8); + data8 &= ~(PORT_RGMII_ID_EG_ENABLE |PORT_RGMII_ID_IG_ENABLE ); + +if (p->rgmii_tx_val) { +lan937x_update_rgmii_delay (dev, port, true); + data8 |=PORT_RGMII_ID_EG_ENABLE ; + } + +if (p->rgmii_rx_val) { +lan937x_update_rgmii_delay (dev, port, false); + data8 |=PORT_RGMII_ID_IG_ENABLE ; + } + +/* Enable RGMII internal delays */ +lan937x_pwrite8 (dev, port,REG_PORT_XMII_CTRL_1 , data8); +} + +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); +break ; +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 ksz_port *p = &dev->ports[port];
drivers/net/dsa/microchip/lan937x_dev.h +5 -0
@@ -33,6 +33,11 @@ void lan937x_cfg_port_member(struct ksz_device *dev, int port, u8 member);void lan937x_port_setup (struct ksz_device *dev,int port,bool cpu_port);int lan937x_enable_spi_indirect_access (struct ksz_device *dev); +void lan937x_config_interface (struct ksz_device *dev,int port, +int speed,int duplex, +bool tx_pause,bool rx_pause); +void lan937x_mac_config (struct ksz_device *dev,int port, +phy_interface_t interface);struct mib_names {int index;
drivers/net/dsa/microchip/lan937x_main.c +98 -0
110 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 7/10 net: dsa: microchip: add support for ethtool port counters
In reply to Prasanna VengateshanReused 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +18 -0
@@ -45,6 +45,21 @@ 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, +uint8_t *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) {
@@ -472,6 +487,9 @@ const struct dsa_switch_ops lan937x_switch_ops = { .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, .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.27.0
PATCH v4 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
@@ -125,6 +125,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 phy_interface_t lan937x_get_interface (struct ksz_device *dev,int port) {phy_interface_t interface;
@@ -494,6 +576,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_validate = lan937x_phylink_validate,
Signature · 1 line
2.27.0
Re: [PATCH v4 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]>---
PATCH v4 9/10 net: dsa: microchip: add support for fdb and mdb management
In reply to Prasanna VengateshanSupport for fdb_add, mdb_add, fdb_del, mdb_del and fdb_dump operations. ALU1 and ALU2 are used for fdb operations.
fdb_add: find any existing entries and update the port map. if ALU1 write is failed and attempt to write ALU2.
If ALU2 is also failed then exit. Clear WRITE_FAIL for both ALU1 & ALU2.
fdb_del: find the matching entry and clear the respective port in the port map by writing the ALU tables
fdb_dump: read and dump 2 ALUs upto last entry. ALU_START bit is used to find the last entry. If the read is timed out, then pass the error message.
mdb_add: Find the empty slot in ALU and update the port map & mac address by writing the ALU
mdb_del: find the matching entry and delete the respective port in port map by writing the ALU
For MAC address, could not use upper_32_bits() & lower_32_bits() as per Vladimir proposal since it gets accessed in terms of 16bits. I tried to have common API to get 16bits based on index but shifting seems to be straight-forward.
--- drivers/net/dsa/microchip/lan937x_main.c | 515 +++++++++++++++++++++++ 1 file changed, 515 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +515 -0
@@ -17,6 +17,74 @@#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; + + ret =ksz_read32 (dev,REG_SW_ALU_VAL_D , &table[3 ]); + +return ret; +} + +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; + + ret =ksz_write32 (dev,REG_SW_ALU_VAL_D , table[3 ]); + +return ret; +} + +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)
@@ -125,6 +193,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)
@@ -576,6 +1086,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.27.0
Re: [PATCH v4 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]>---
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 456
Quoted 6 lines
drivers/net/dsa/microchip/lan937x_main.c +5
-0+static int lan937x_port_fdb_dump (struct dsa_switch *ds,int port, +dsa_fdb_dump_cb_t *cb,void *data) +{ +if (alu.port_forward &BIT (port)) { + ret =cb (alu.mac, alu.fid, alu.is_static, data);
A bit strange that you report the FID and not the VID here.
Quoted 14 lines
drivers/net/dsa/microchip/lan937x_main.c +14
-0+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; +}
PATCH v4 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 | 198 +++++++++++++++++++++++ 1 file changed, 198 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +198 -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;
@@ -193,6 +292,102 @@ 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; +int ret; + + ret =lan937x_cfg (dev,REG_SW_LUE_CTRL_0 ,SW_VLAN_ENABLE , + flag); + +return ret; +} + +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) +{ +bool untagged = vlan->flags &BRIDGE_VLAN_INFO_UNTAGGED ; +struct ksz_device *dev = ds->priv; +struct lan937x_vlan vlan_entry; +u16 pvid; +int ret; + +lan937x_pread16 (dev, port,REG_PORT_DEFAULT_VID , &pvid); + pvid &=0xFFF ; + + 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 */ + vlan_entry.fwd_map &= ~BIT (port); + +if (untagged) + 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; + } + + ret =lan937x_pwrite16 (dev, port,REG_PORT_DEFAULT_VID , pvid); +if (ret <0 ) { +dev_err (dev->dev,"Failed to set pvid\n" ); +return ret; + } + +return 0 ; +} +static int lan937x_port_fdb_add (struct dsa_switch *ds,int port,const unsigned char *addr,u16 vid) {
@@ -1086,6 +1281,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.27.0
Vladimir Oltean
maintainerRe: [PATCH v4 net-next 10/10] net: dsa: microchip: add support for vlan operations
Quoted 6 lines · Prasanna Vengateshan
static int
lan937x_read_table(struct ksz_device *dev, u32 *table){drivers/net/dsa/microchip/lan937x_main.c +0
-0int ret;@@ -193,6 +292,102 @@ static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port,ksz_update_port_member (dev, port); }
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 303
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_main.c +9
-0+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; +int ret; + + ret =lan937x_cfg (dev,REG_SW_LUE_CTRL_0 ,SW_VLAN_ENABLE , + flag);
If you're going to resend anyway, can you please check the entire submission for this pattern, where you can eliminate the intermediary "ret" variable and just return the function call directly?
return lan937x_cfg(...)
Do you have an explanation for what SW_VLAN_ENABLE does exactly?
Quoted 61 lines
drivers/net/dsa/microchip/lan937x_main.c +61
-0+ +return ret; +} + +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) +{ +bool untagged = vlan->flags &BRIDGE_VLAN_INFO_UNTAGGED ; +struct ksz_device *dev = ds->priv; +struct lan937x_vlan vlan_entry; +u16 pvid; +int ret; + +lan937x_pread16 (dev, port,REG_PORT_DEFAULT_VID , &pvid); + pvid &=0xFFF ; +
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 374
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_main.c +10
-0+ 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 */ + vlan_entry.fwd_map &= ~BIT (port); + +if (untagged) + vlan_entry.untag_prtmap &= ~BIT (port);
This is bogus.
The user can add a VLAN entry using:
bridge vlan add dev lan0 vid 100 pvid untagged
and remove it using
bridge vlan del dev lan0 vid 100
so BRIDGE_VLAN_INFO_UNTAGGED is not set on removal.
Considering the fact that it doesn't matter whether the port is egress-tagged or not when it isn't in the fwd_map in the first place, I suggest you completely drop this condition.
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 382
Quoted 8 lines
drivers/net/dsa/microchip/lan937x_main.c +8
-0+ + 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; + } + + ret =lan937x_pwrite16 (dev, port,REG_PORT_DEFAULT_VID , pvid);
What is the point of reading the pvid and writing it back unmodified? Is the AND-ing with 0xFFF supposed to do anything? Because when you write to REG_PORT_DEFAULT_VID, you write it with nothing in the upper bits, so I expect there to be nothing in the upper bits when you read it back either.
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 389
Quoted 7 lines
drivers/net/dsa/microchip/lan937x_main.c +7
-0+if (ret <0 ) { +dev_err (dev->dev,"Failed to set pvid\n" ); +return ret; + } + +return 0 ; +}
Also, consider the following set of commands:
ip link add br0 type bridge vlan_filtering 1
ip link set lan0 master br0
bridge vlan add dev lan0 vid 100 pvid untagged
bridge vlan del dev lan0 vid 100
ip link set br0 type bridge vlan_filtering 0
The expectation is that the switch, being VLAN-unaware as it is currently configured, receives and sends any packet regardless of VLAN ID. If you put an IP on br0 in this state, are you able to ping an outside host?
Re: [PATCH v4 net-next 10/10] net: dsa: microchip: add support for vlan operations
Quoted 17 lines · Vladimir Oltean
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 303
Quoted 9 lines
drivers/net/dsa/microchip/lan937x_main.c +9
-0+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; + int ret; + + ret = lan937x_cfg(dev, REG_SW_LUE_CTRL_0, SW_VLAN_ENABLE, + flag);If you're going to resend anyway, can you please check the entire submission for this pattern, where you can eliminate the intermediary "ret" variable and just return the function call directly?
Quoted 1 line
return
lan937x_cfg(...)
Sure
Quoted 1 line
Do you have an explanation for what
SW_VLAN_ENABLEdoes exactly?
Enabling the VLAN mode and then act as per the VLAN table. Do you want me to add this explanation as a comment? or?
Quoted 32 lines
Quoted 14 lines
drivers/net/dsa/microchip/lan937x_main.c +12
-0+static int lan937x_port_vlan_del (struct dsa_switch *ds,int port, + const struct switchdev_obj_port_vlan *vlan) +{ + bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; + struct ksz_device *dev = ds->priv; + struct lan937x_vlan vlan_entry; + u16 pvid; + int ret; + + lan937x_pread16(dev, port, REG_PORT_DEFAULT_VID, &pvid); + pvid &= 0xFFF; +drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 374
Quoted 10 lines
drivers/net/dsa/microchip/lan937x_main.c +10
-0+ 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 */ + vlan_entry.fwd_map &= ~BIT(port); + + if (untagged) + vlan_entry.untag_prtmap &= ~BIT(port);This is bogus.
The user can add a VLAN entry using:bridge vlan add dev lan0 vid 100 pvid untagged
and remove it using
Quoted 7 lines
bridge vlan del dev lan0 vid 100
so
BRIDGE_VLAN_INFO_UNTAGGEDis not set on removal.Considering the fact that it doesn't matter whether the port is egress-tagged or not when it isn't in the
fwd_mapin the first place, I suggest you completely drop this condition.
Sure, i agree with you.
Quoted 15 lines
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 382
Quoted 9 lines
drivers/net/dsa/microchip/lan937x_main.c +8
-0+ + 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; + } + + ret = lan937x_pwrite16(dev, port, REG_PORT_DEFAULT_VID, pvid);What is the point of reading the pvid and writing it back unmodified? Is the AND-ing with
0xFFFsupposed to do anything? Because when you write toREG_PORT_DEFAULT_VID, you write it with nothing in the upper bits, so I expect there to be nothing in the upper bits when you read it back either.
I had a feedback for not to reset the PVID as per the switchdev documentation during vlan del. As part of the fix , i just removed PVID reset code alone but missed these. Read/write PVID to be completely removed. I had a test case to make sure that the PVID is not reset during vlan del. Since this is reading/writing back the same values, could not catch them. I will clean up in the next patch.
Quoted 11 lines
drivers/net/dsa/microchip/lan937x_main.c static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port, · line 351
Quoted 8 lines
+ if (ret < 0) {
+dev_err(dev->dev, "Failed to set pvid\n"); + return ret;
+ }drivers/net/dsa/microchip/lan937x_main.c +3
-0+ + return 0; +}Also, consider the following set of commands:
Step (0)
Quoted 3 lines
ip link add br0 type bridge
vlan_filtering1
ip link set lan0 master br0
bridge vlan add dev lan0 vid 100 pvid untagged
Step (1)
Quoted 1 line
bridge vlan del dev lan0 vid 100
Step (2)
Quoted 5 lines
ip link set br0 type bridge
vlan_filtering0The expectation is that the switch, being VLAN-unaware as it is currently configured, receives and sends any packet regardless of VLAN ID. If you put an IP on br0 in this state, are you able to ping an outside host?
I have numbered the commands above.
Results are,
Before Step (0). Am able to ping outside.
After Step (0). Am not able to ping outside because the vlan table is set After Step (1). Am not able to ping outside
After Step (2). Am able to ping outside because of vlan unaware mode.
Vladimir Oltean
maintainerRe: [PATCH v4 net-next 10/10] net: dsa: microchip: add support for vlan operations
Quoted 3 lines · Prasanna Vengateshan
Quoted 1 line
Do you have an explanation for what
SW_VLAN_ENABLEdoes exactly?Enabling the VLAN mode and then act as per the VLAN table. Do you want me to add this explanation as a comment? or?
Yes, not all switches have the same knobs, it would be good to have a comment about what you are changing.
Quoted 13 lines
Step (0)
Quoted 3 lines
ip link add br0 type bridge
vlan_filtering1
ip link set lan0 master br0
bridge vlan add dev lan0 vid 100 pvid untaggedStep (1)
Quoted 1 line
bridge vlan del dev lan0 vid 100
Step (2)
Quoted 5 lines
ip link set br0 type bridge
vlan_filtering0The expectation is that the switch, being VLAN-unaware as it is currently configured, receives and sends any packet regardless of VLAN ID. If you put an IP on br0 in this state, are you able to ping an outside host?
Quoted 6 lines
I have numbered the commands above.
Results are,
Before Step (0). Am able to ping outside.
After Step (0). Am not able to ping outside because the vlan table is set After Step (1). Am not able to ping outside
After Step (2). Am able to ping outside because of vlan unaware mode.
This sounds okay.