aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-06-09 14:20:05 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-09 14:20:05 -0400
commit60d6f36f5c9768f16b45dac7ecb483cce3e250a4 (patch)
tree51bc6346ac2935961cc57bdc789d1647d16a78aa
parent9b15350f0d5c401c02eca15c4e6ca0603cff1a41 (diff)
parentd664b41e2adf5851e4d0d39f450b2f3f808b65d6 (diff)
Merge branch 'mlxsw-fixes'
Jiri Pirko says: ==================== mlxsw: couple of fixes Couple of fixes from Ido. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.c203
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.h5
2 files changed, 117 insertions, 91 deletions
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 4a7273771028..6f9e3ddff4a8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -247,15 +247,23 @@ static int mlxsw_sp_port_mtu_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mtu)
247 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmtu), pmtu_pl); 247 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmtu), pmtu_pl);
248} 248}
249 249
250static int mlxsw_sp_port_swid_set(struct mlxsw_sp_port *mlxsw_sp_port, u8 swid) 250static int __mlxsw_sp_port_swid_set(struct mlxsw_sp *mlxsw_sp, u8 local_port,
251 u8 swid)
251{ 252{
252 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
253 char pspa_pl[MLXSW_REG_PSPA_LEN]; 253 char pspa_pl[MLXSW_REG_PSPA_LEN];
254 254
255 mlxsw_reg_pspa_pack(pspa_pl, swid, mlxsw_sp_port->local_port); 255 mlxsw_reg_pspa_pack(pspa_pl, swid, local_port);
256 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pspa), pspa_pl); 256 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pspa), pspa_pl);
257} 257}
258 258
259static int mlxsw_sp_port_swid_set(struct mlxsw_sp_port *mlxsw_sp_port, u8 swid)
260{
261 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
262
263 return __mlxsw_sp_port_swid_set(mlxsw_sp, mlxsw_sp_port->local_port,
264 swid);
265}
266
259static int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, 267static int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port,
260 bool enable) 268 bool enable)
261{ 269{
@@ -305,9 +313,9 @@ mlxsw_sp_port_system_port_mapping_set(struct mlxsw_sp_port *mlxsw_sp_port)
305 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sspr), sspr_pl); 313 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sspr), sspr_pl);
306} 314}
307 315
308static int __mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, 316static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
309 u8 local_port, u8 *p_module, 317 u8 local_port, u8 *p_module,
310 u8 *p_width, u8 *p_lane) 318 u8 *p_width, u8 *p_lane)
311{ 319{
312 char pmlp_pl[MLXSW_REG_PMLP_LEN]; 320 char pmlp_pl[MLXSW_REG_PMLP_LEN];
313 int err; 321 int err;
@@ -322,16 +330,6 @@ static int __mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
322 return 0; 330 return 0;
323} 331}
324 332
325static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
326 u8 local_port, u8 *p_module,
327 u8 *p_width)
328{
329 u8 lane;
330
331 return __mlxsw_sp_port_module_info_get(mlxsw_sp, local_port, p_module,
332 p_width, &lane);
333}
334
335static int mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u8 local_port, 333static int mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u8 local_port,
336 u8 module, u8 width, u8 lane) 334 u8 module, u8 width, u8 lane)
337{ 335{
@@ -949,17 +947,11 @@ static int mlxsw_sp_port_get_phys_port_name(struct net_device *dev, char *name,
949 size_t len) 947 size_t len)
950{ 948{
951 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); 949 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
952 u8 module, width, lane; 950 u8 module = mlxsw_sp_port->mapping.module;
951 u8 width = mlxsw_sp_port->mapping.width;
952 u8 lane = mlxsw_sp_port->mapping.lane;
953 int err; 953 int err;
954 954
955 err = __mlxsw_sp_port_module_info_get(mlxsw_sp_port->mlxsw_sp,
956 mlxsw_sp_port->local_port,
957 &module, &width, &lane);
958 if (err) {
959 netdev_err(dev, "Failed to retrieve module information\n");
960 return err;
961 }
962
963 if (!mlxsw_sp_port->split) 955 if (!mlxsw_sp_port->split)
964 err = snprintf(name, len, "p%d", module + 1); 956 err = snprintf(name, len, "p%d", module + 1);
965 else 957 else
@@ -1681,8 +1673,8 @@ static int mlxsw_sp_port_ets_init(struct mlxsw_sp_port *mlxsw_sp_port)
1681 return 0; 1673 return 0;
1682} 1674}
1683 1675
1684static int __mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port, 1676static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1685 bool split, u8 module, u8 width) 1677 bool split, u8 module, u8 width, u8 lane)
1686{ 1678{
1687 struct mlxsw_sp_port *mlxsw_sp_port; 1679 struct mlxsw_sp_port *mlxsw_sp_port;
1688 struct net_device *dev; 1680 struct net_device *dev;
@@ -1697,6 +1689,9 @@ static int __mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1697 mlxsw_sp_port->mlxsw_sp = mlxsw_sp; 1689 mlxsw_sp_port->mlxsw_sp = mlxsw_sp;
1698 mlxsw_sp_port->local_port = local_port; 1690 mlxsw_sp_port->local_port = local_port;
1699 mlxsw_sp_port->split = split; 1691 mlxsw_sp_port->split = split;
1692 mlxsw_sp_port->mapping.module = module;
1693 mlxsw_sp_port->mapping.width = width;
1694 mlxsw_sp_port->mapping.lane = lane;
1700 bytes = DIV_ROUND_UP(VLAN_N_VID, BITS_PER_BYTE); 1695 bytes = DIV_ROUND_UP(VLAN_N_VID, BITS_PER_BYTE);
1701 mlxsw_sp_port->active_vlans = kzalloc(bytes, GFP_KERNEL); 1696 mlxsw_sp_port->active_vlans = kzalloc(bytes, GFP_KERNEL);
1702 if (!mlxsw_sp_port->active_vlans) { 1697 if (!mlxsw_sp_port->active_vlans) {
@@ -1839,28 +1834,6 @@ err_port_active_vlans_alloc:
1839 return err; 1834 return err;
1840} 1835}
1841 1836
1842static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1843 bool split, u8 module, u8 width, u8 lane)
1844{
1845 int err;
1846
1847 err = mlxsw_sp_port_module_map(mlxsw_sp, local_port, module, width,
1848 lane);
1849 if (err)
1850 return err;
1851
1852 err = __mlxsw_sp_port_create(mlxsw_sp, local_port, split, module,
1853 width);
1854 if (err)
1855 goto err_port_create;
1856
1857 return 0;
1858
1859err_port_create:
1860 mlxsw_sp_port_module_unmap(mlxsw_sp, local_port);
1861 return err;
1862}
1863
1864static void mlxsw_sp_port_vports_fini(struct mlxsw_sp_port *mlxsw_sp_port) 1837static void mlxsw_sp_port_vports_fini(struct mlxsw_sp_port *mlxsw_sp_port)
1865{ 1838{
1866 struct net_device *dev = mlxsw_sp_port->dev; 1839 struct net_device *dev = mlxsw_sp_port->dev;
@@ -1909,8 +1882,8 @@ static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
1909 1882
1910static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) 1883static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
1911{ 1884{
1885 u8 module, width, lane;
1912 size_t alloc_size; 1886 size_t alloc_size;
1913 u8 module, width;
1914 int i; 1887 int i;
1915 int err; 1888 int err;
1916 1889
@@ -1921,13 +1894,14 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
1921 1894
1922 for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++) { 1895 for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++) {
1923 err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, &module, 1896 err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, &module,
1924 &width); 1897 &width, &lane);
1925 if (err) 1898 if (err)
1926 goto err_port_module_info_get; 1899 goto err_port_module_info_get;
1927 if (!width) 1900 if (!width)
1928 continue; 1901 continue;
1929 mlxsw_sp->port_to_module[i] = module; 1902 mlxsw_sp->port_to_module[i] = module;
1930 err = __mlxsw_sp_port_create(mlxsw_sp, i, false, module, width); 1903 err = mlxsw_sp_port_create(mlxsw_sp, i, false, module, width,
1904 lane);
1931 if (err) 1905 if (err)
1932 goto err_port_create; 1906 goto err_port_create;
1933 } 1907 }
@@ -1948,12 +1922,85 @@ static u8 mlxsw_sp_cluster_base_port_get(u8 local_port)
1948 return local_port - offset; 1922 return local_port - offset;
1949} 1923}
1950 1924
1925static int mlxsw_sp_port_split_create(struct mlxsw_sp *mlxsw_sp, u8 base_port,
1926 u8 module, unsigned int count)
1927{
1928 u8 width = MLXSW_PORT_MODULE_MAX_WIDTH / count;
1929 int err, i;
1930
1931 for (i = 0; i < count; i++) {
1932 err = mlxsw_sp_port_module_map(mlxsw_sp, base_port + i, module,
1933 width, i * width);
1934 if (err)
1935 goto err_port_module_map;
1936 }
1937
1938 for (i = 0; i < count; i++) {
1939 err = __mlxsw_sp_port_swid_set(mlxsw_sp, base_port + i, 0);
1940 if (err)
1941 goto err_port_swid_set;
1942 }
1943
1944 for (i = 0; i < count; i++) {
1945 err = mlxsw_sp_port_create(mlxsw_sp, base_port + i, true,
1946 module, width, i * width);
1947 if (err)
1948 goto err_port_create;
1949 }
1950
1951 return 0;
1952
1953err_port_create:
1954 for (i--; i >= 0; i--)
1955 mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
1956 i = count;
1957err_port_swid_set:
1958 for (i--; i >= 0; i--)
1959 __mlxsw_sp_port_swid_set(mlxsw_sp, base_port + i,
1960 MLXSW_PORT_SWID_DISABLED_PORT);
1961 i = count;
1962err_port_module_map:
1963 for (i--; i >= 0; i--)
1964 mlxsw_sp_port_module_unmap(mlxsw_sp, base_port + i);
1965 return err;
1966}
1967
1968static void mlxsw_sp_port_unsplit_create(struct mlxsw_sp *mlxsw_sp,
1969 u8 base_port, unsigned int count)
1970{
1971 u8 local_port, module, width = MLXSW_PORT_MODULE_MAX_WIDTH;
1972 int i;
1973
1974 /* Split by four means we need to re-create two ports, otherwise
1975 * only one.
1976 */
1977 count = count / 2;
1978
1979 for (i = 0; i < count; i++) {
1980 local_port = base_port + i * 2;
1981 module = mlxsw_sp->port_to_module[local_port];
1982
1983 mlxsw_sp_port_module_map(mlxsw_sp, local_port, module, width,
1984 0);
1985 }
1986
1987 for (i = 0; i < count; i++)
1988 __mlxsw_sp_port_swid_set(mlxsw_sp, base_port + i * 2, 0);
1989
1990 for (i = 0; i < count; i++) {
1991 local_port = base_port + i * 2;
1992 module = mlxsw_sp->port_to_module[local_port];
1993
1994 mlxsw_sp_port_create(mlxsw_sp, local_port, false, module,
1995 width, 0);
1996 }
1997}
1998
1951static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port, 1999static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
1952 unsigned int count) 2000 unsigned int count)
1953{ 2001{
1954 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); 2002 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
1955 struct mlxsw_sp_port *mlxsw_sp_port; 2003 struct mlxsw_sp_port *mlxsw_sp_port;
1956 u8 width = MLXSW_PORT_MODULE_MAX_WIDTH / count;
1957 u8 module, cur_width, base_port; 2004 u8 module, cur_width, base_port;
1958 int i; 2005 int i;
1959 int err; 2006 int err;
@@ -1965,18 +2012,14 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
1965 return -EINVAL; 2012 return -EINVAL;
1966 } 2013 }
1967 2014
2015 module = mlxsw_sp_port->mapping.module;
2016 cur_width = mlxsw_sp_port->mapping.width;
2017
1968 if (count != 2 && count != 4) { 2018 if (count != 2 && count != 4) {
1969 netdev_err(mlxsw_sp_port->dev, "Port can only be split into 2 or 4 ports\n"); 2019 netdev_err(mlxsw_sp_port->dev, "Port can only be split into 2 or 4 ports\n");
1970 return -EINVAL; 2020 return -EINVAL;
1971 } 2021 }
1972 2022
1973 err = mlxsw_sp_port_module_info_get(mlxsw_sp, local_port, &module,
1974 &cur_width);
1975 if (err) {
1976 netdev_err(mlxsw_sp_port->dev, "Failed to get port's width\n");
1977 return err;
1978 }
1979
1980 if (cur_width != MLXSW_PORT_MODULE_MAX_WIDTH) { 2023 if (cur_width != MLXSW_PORT_MODULE_MAX_WIDTH) {
1981 netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n"); 2024 netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n");
1982 return -EINVAL; 2025 return -EINVAL;
@@ -2001,25 +2044,16 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
2001 for (i = 0; i < count; i++) 2044 for (i = 0; i < count; i++)
2002 mlxsw_sp_port_remove(mlxsw_sp, base_port + i); 2045 mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
2003 2046
2004 for (i = 0; i < count; i++) { 2047 err = mlxsw_sp_port_split_create(mlxsw_sp, base_port, module, count);
2005 err = mlxsw_sp_port_create(mlxsw_sp, base_port + i, true, 2048 if (err) {
2006 module, width, i * width); 2049 dev_err(mlxsw_sp->bus_info->dev, "Failed to create split ports\n");
2007 if (err) { 2050 goto err_port_split_create;
2008 dev_err(mlxsw_sp->bus_info->dev, "Failed to create split port\n");
2009 goto err_port_create;
2010 }
2011 } 2051 }
2012 2052
2013 return 0; 2053 return 0;
2014 2054
2015err_port_create: 2055err_port_split_create:
2016 for (i--; i >= 0; i--) 2056 mlxsw_sp_port_unsplit_create(mlxsw_sp, base_port, count);
2017 mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
2018 for (i = 0; i < count / 2; i++) {
2019 module = mlxsw_sp->port_to_module[base_port + i * 2];
2020 mlxsw_sp_port_create(mlxsw_sp, base_port + i * 2, false,
2021 module, MLXSW_PORT_MODULE_MAX_WIDTH, 0);
2022 }
2023 return err; 2057 return err;
2024} 2058}
2025 2059
@@ -2027,10 +2061,9 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
2027{ 2061{
2028 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); 2062 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
2029 struct mlxsw_sp_port *mlxsw_sp_port; 2063 struct mlxsw_sp_port *mlxsw_sp_port;
2030 u8 module, cur_width, base_port; 2064 u8 cur_width, base_port;
2031 unsigned int count; 2065 unsigned int count;
2032 int i; 2066 int i;
2033 int err;
2034 2067
2035 mlxsw_sp_port = mlxsw_sp->ports[local_port]; 2068 mlxsw_sp_port = mlxsw_sp->ports[local_port];
2036 if (!mlxsw_sp_port) { 2069 if (!mlxsw_sp_port) {
@@ -2044,12 +2077,7 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
2044 return -EINVAL; 2077 return -EINVAL;
2045 } 2078 }
2046 2079
2047 err = mlxsw_sp_port_module_info_get(mlxsw_sp, local_port, &module, 2080 cur_width = mlxsw_sp_port->mapping.width;
2048 &cur_width);
2049 if (err) {
2050 netdev_err(mlxsw_sp_port->dev, "Failed to get port's width\n");
2051 return err;
2052 }
2053 count = cur_width == 1 ? 4 : 2; 2081 count = cur_width == 1 ? 4 : 2;
2054 2082
2055 base_port = mlxsw_sp_cluster_base_port_get(local_port); 2083 base_port = mlxsw_sp_cluster_base_port_get(local_port);
@@ -2061,14 +2089,7 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
2061 for (i = 0; i < count; i++) 2089 for (i = 0; i < count; i++)
2062 mlxsw_sp_port_remove(mlxsw_sp, base_port + i); 2090 mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
2063 2091
2064 for (i = 0; i < count / 2; i++) { 2092 mlxsw_sp_port_unsplit_create(mlxsw_sp, base_port, count);
2065 module = mlxsw_sp->port_to_module[base_port + i * 2];
2066 err = mlxsw_sp_port_create(mlxsw_sp, base_port + i * 2, false,
2067 module, MLXSW_PORT_MODULE_MAX_WIDTH,
2068 0);
2069 if (err)
2070 dev_err(mlxsw_sp->bus_info->dev, "Failed to reinstantiate port\n");
2071 }
2072 2093
2073 return 0; 2094 return 0;
2074} 2095}
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index e2c022d3e2f3..13b30eaa13d4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -229,6 +229,11 @@ struct mlxsw_sp_port {
229 struct ieee_maxrate *maxrate; 229 struct ieee_maxrate *maxrate;
230 struct ieee_pfc *pfc; 230 struct ieee_pfc *pfc;
231 } dcb; 231 } dcb;
232 struct {
233 u8 module;
234 u8 width;
235 u8 lane;
236 } mapping;
232 /* 802.1Q bridge VLANs */ 237 /* 802.1Q bridge VLANs */
233 unsigned long *active_vlans; 238 unsigned long *active_vlans;
234 unsigned long *untagged_vlans; 239 unsigned long *untagged_vlans;