@@ -1800,7 +1800,8 @@ static int
18001800qca8k_setup (struct dsa_switch * ds )
18011801{
18021802 struct qca8k_priv * priv = ds -> priv ;
1803- int cpu_port , ret , i ;
1803+ struct dsa_port * dp ;
1804+ int cpu_port , ret ;
18041805 u32 mask ;
18051806
18061807 cpu_port = qca8k_find_cpu_port (ds );
@@ -1855,27 +1856,27 @@ qca8k_setup(struct dsa_switch *ds)
18551856 dev_warn (priv -> dev , "mib init failed" );
18561857
18571858 /* Initial setup of all ports */
1858- for ( i = 0 ; i < QCA8K_NUM_PORTS ; i ++ ) {
1859+ dsa_switch_for_each_port ( dp , ds ) {
18591860 /* Disable forwarding by default on all ports */
1860- ret = qca8k_rmw (priv , QCA8K_PORT_LOOKUP_CTRL (i ),
1861+ ret = qca8k_rmw (priv , QCA8K_PORT_LOOKUP_CTRL (dp -> index ),
18611862 QCA8K_PORT_LOOKUP_MEMBER , 0 );
18621863 if (ret )
18631864 return ret ;
1865+ }
18641866
1865- /* Enable QCA header mode on all cpu ports */
1866- if (dsa_is_cpu_port (ds , i )) {
1867- ret = qca8k_write (priv , QCA8K_REG_PORT_HDR_CTRL (i ),
1868- FIELD_PREP (QCA8K_PORT_HDR_CTRL_TX_MASK , QCA8K_PORT_HDR_CTRL_ALL ) |
1869- FIELD_PREP (QCA8K_PORT_HDR_CTRL_RX_MASK , QCA8K_PORT_HDR_CTRL_ALL ));
1870- if (ret ) {
1871- dev_err (priv -> dev , "failed enabling QCA header mode" );
1872- return ret ;
1873- }
1867+ /* Disable MAC by default on all user ports */
1868+ dsa_switch_for_each_user_port (dp , ds )
1869+ qca8k_port_set_status (priv , dp -> index , 0 );
1870+
1871+ /* Enable QCA header mode on all cpu ports */
1872+ dsa_switch_for_each_cpu_port (dp , ds ) {
1873+ ret = qca8k_write (priv , QCA8K_REG_PORT_HDR_CTRL (dp -> index ),
1874+ FIELD_PREP (QCA8K_PORT_HDR_CTRL_TX_MASK , QCA8K_PORT_HDR_CTRL_ALL ) |
1875+ FIELD_PREP (QCA8K_PORT_HDR_CTRL_RX_MASK , QCA8K_PORT_HDR_CTRL_ALL ));
1876+ if (ret ) {
1877+ dev_err (priv -> dev , "failed enabling QCA header mode on port %d" , dp -> index );
1878+ return ret ;
18741879 }
1875-
1876- /* Disable MAC by default on all user ports */
1877- if (dsa_is_user_port (ds , i ))
1878- qca8k_port_set_status (priv , i , 0 );
18791880 }
18801881
18811882 /* Forward all unknown frames to CPU port for Linux processing
@@ -1897,48 +1898,48 @@ qca8k_setup(struct dsa_switch *ds)
18971898 return ret ;
18981899
18991900 /* Setup connection between CPU port & user ports
1900- * Configure specific switch configuration for ports
1901+ * Individual user ports get connected to CPU port only
19011902 */
1902- for (i = 0 ; i < QCA8K_NUM_PORTS ; i ++ ) {
1903- /* Individual user ports get connected to CPU port only */
1904- if (dsa_is_user_port (ds , i )) {
1905- ret = qca8k_rmw (priv , QCA8K_PORT_LOOKUP_CTRL (i ),
1906- QCA8K_PORT_LOOKUP_MEMBER ,
1907- BIT (cpu_port ));
1908- if (ret )
1909- return ret ;
1910-
1911- ret = regmap_clear_bits (priv -> regmap , QCA8K_PORT_LOOKUP_CTRL (i ),
1912- QCA8K_PORT_LOOKUP_LEARN );
1913- if (ret )
1914- return ret ;
1915-
1916- /* For port based vlans to work we need to set the
1917- * default egress vid
1918- */
1919- ret = qca8k_rmw (priv , QCA8K_EGRESS_VLAN (i ),
1920- QCA8K_EGREES_VLAN_PORT_MASK (i ),
1921- QCA8K_EGREES_VLAN_PORT (i , QCA8K_PORT_VID_DEF ));
1922- if (ret )
1923- return ret ;
1924-
1925- ret = qca8k_write (priv , QCA8K_REG_PORT_VLAN_CTRL0 (i ),
1926- QCA8K_PORT_VLAN_CVID (QCA8K_PORT_VID_DEF ) |
1927- QCA8K_PORT_VLAN_SVID (QCA8K_PORT_VID_DEF ));
1928- if (ret )
1929- return ret ;
1930- }
1903+ dsa_switch_for_each_user_port (dp , ds ) {
1904+ u8 port = dp -> index ;
1905+
1906+ ret = qca8k_rmw (priv , QCA8K_PORT_LOOKUP_CTRL (port ),
1907+ QCA8K_PORT_LOOKUP_MEMBER ,
1908+ BIT (cpu_port ));
1909+ if (ret )
1910+ return ret ;
1911+
1912+ ret = regmap_clear_bits (priv -> regmap , QCA8K_PORT_LOOKUP_CTRL (port ),
1913+ QCA8K_PORT_LOOKUP_LEARN );
1914+ if (ret )
1915+ return ret ;
19311916
1932- /* The port 5 of the qca8337 have some problem in flood condition. The
1933- * original legacy driver had some specific buffer and priority settings
1934- * for the different port suggested by the QCA switch team. Add this
1935- * missing settings to improve switch stability under load condition.
1936- * This problem is limited to qca8337 and other qca8k switch are not affected.
1917+ /* For port based vlans to work we need to set the
1918+ * default egress vid
19371919 */
1938- if (priv -> switch_id == QCA8K_ID_QCA8337 )
1939- qca8k_setup_hol_fixup (priv , i );
1920+ ret = qca8k_rmw (priv , QCA8K_EGRESS_VLAN (port ),
1921+ QCA8K_EGREES_VLAN_PORT_MASK (port ),
1922+ QCA8K_EGREES_VLAN_PORT (port , QCA8K_PORT_VID_DEF ));
1923+ if (ret )
1924+ return ret ;
1925+
1926+ ret = qca8k_write (priv , QCA8K_REG_PORT_VLAN_CTRL0 (port ),
1927+ QCA8K_PORT_VLAN_CVID (QCA8K_PORT_VID_DEF ) |
1928+ QCA8K_PORT_VLAN_SVID (QCA8K_PORT_VID_DEF ));
1929+ if (ret )
1930+ return ret ;
19401931 }
19411932
1933+ /* The port 5 of the qca8337 have some problem in flood condition. The
1934+ * original legacy driver had some specific buffer and priority settings
1935+ * for the different port suggested by the QCA switch team. Add this
1936+ * missing settings to improve switch stability under load condition.
1937+ * This problem is limited to qca8337 and other qca8k switch are not affected.
1938+ */
1939+ if (priv -> switch_id == QCA8K_ID_QCA8337 )
1940+ dsa_switch_for_each_available_port (dp , ds )
1941+ qca8k_setup_hol_fixup (priv , dp -> index );
1942+
19421943 /* Special GLOBAL_FC_THRESH value are needed for ar8327 switch */
19431944 if (priv -> switch_id == QCA8K_ID_QCA8327 ) {
19441945 mask = QCA8K_GLOBAL_FC_GOL_XON_THRES (288 ) |
0 commit comments