aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>2016-05-09 13:22:56 -0400
committerDavid S. Miller <davem@davemloft.net>2016-05-09 14:26:12 -0400
commita1a6a4d1f76aab009e6e0b1003b9c7bca3991e9c (patch)
tree19b16dca6438be0ab95f57eab88444ed50dcda2c
parent8698fd9595c3b90a76c878159328ac6ebd923963 (diff)
net: dsa: mv88e6xxx: factorize switch setup
Provide a shared mv88e6xxx_setup function to the drivers. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/dsa/mv88e6123.c16
-rw-r--r--drivers/net/dsa/mv88e6131.c16
-rw-r--r--drivers/net/dsa/mv88e6171.c16
-rw-r--r--drivers/net/dsa/mv88e6352.c16
-rw-r--r--drivers/net/dsa/mv88e6xxx.c69
-rw-r--r--drivers/net/dsa/mv88e6xxx.h3
6 files changed, 38 insertions, 98 deletions
diff --git a/drivers/net/dsa/mv88e6123.c b/drivers/net/dsa/mv88e6123.c
index 8f3a7c55c178..2bc407b5632d 100644
--- a/drivers/net/dsa/mv88e6123.c
+++ b/drivers/net/dsa/mv88e6123.c
@@ -51,24 +51,10 @@ static const char *mv88e6123_drv_probe(struct device *dsa_dev,
51 ARRAY_SIZE(mv88e6123_table)); 51 ARRAY_SIZE(mv88e6123_table));
52} 52}
53 53
54static int mv88e6123_setup(struct dsa_switch *ds)
55{
56 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
57 int ret;
58
59 ps->ds = ds;
60
61 ret = mv88e6xxx_setup_common(ps);
62 if (ret < 0)
63 return ret;
64
65 return mv88e6xxx_setup_ports(ds);
66}
67
68struct dsa_switch_driver mv88e6123_switch_driver = { 54struct dsa_switch_driver mv88e6123_switch_driver = {
69 .tag_protocol = DSA_TAG_PROTO_EDSA, 55 .tag_protocol = DSA_TAG_PROTO_EDSA,
70 .probe = mv88e6123_drv_probe, 56 .probe = mv88e6123_drv_probe,
71 .setup = mv88e6123_setup, 57 .setup = mv88e6xxx_setup,
72 .set_addr = mv88e6xxx_set_addr, 58 .set_addr = mv88e6xxx_set_addr,
73 .phy_read = mv88e6xxx_phy_read, 59 .phy_read = mv88e6xxx_phy_read,
74 .phy_write = mv88e6xxx_phy_write, 60 .phy_write = mv88e6xxx_phy_write,
diff --git a/drivers/net/dsa/mv88e6131.c b/drivers/net/dsa/mv88e6131.c
index da2832726672..22952be7f4de 100644
--- a/drivers/net/dsa/mv88e6131.c
+++ b/drivers/net/dsa/mv88e6131.c
@@ -58,24 +58,10 @@ static const char *mv88e6131_drv_probe(struct device *dsa_dev,
58 ARRAY_SIZE(mv88e6131_table)); 58 ARRAY_SIZE(mv88e6131_table));
59} 59}
60 60
61static int mv88e6131_setup(struct dsa_switch *ds)
62{
63 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
64 int ret;
65
66 ps->ds = ds;
67
68 ret = mv88e6xxx_setup_common(ps);
69 if (ret < 0)
70 return ret;
71
72 return mv88e6xxx_setup_ports(ds);
73}
74
75struct dsa_switch_driver mv88e6131_switch_driver = { 61struct dsa_switch_driver mv88e6131_switch_driver = {
76 .tag_protocol = DSA_TAG_PROTO_DSA, 62 .tag_protocol = DSA_TAG_PROTO_DSA,
77 .probe = mv88e6131_drv_probe, 63 .probe = mv88e6131_drv_probe,
78 .setup = mv88e6131_setup, 64 .setup = mv88e6xxx_setup,
79 .set_addr = mv88e6xxx_set_addr, 65 .set_addr = mv88e6xxx_set_addr,
80 .phy_read = mv88e6xxx_phy_read, 66 .phy_read = mv88e6xxx_phy_read,
81 .phy_write = mv88e6xxx_phy_write, 67 .phy_write = mv88e6xxx_phy_write,
diff --git a/drivers/net/dsa/mv88e6171.c b/drivers/net/dsa/mv88e6171.c
index 83678adfd97c..4bf517a86acb 100644
--- a/drivers/net/dsa/mv88e6171.c
+++ b/drivers/net/dsa/mv88e6171.c
@@ -58,24 +58,10 @@ static const char *mv88e6171_drv_probe(struct device *dsa_dev,
58 ARRAY_SIZE(mv88e6171_table)); 58 ARRAY_SIZE(mv88e6171_table));
59} 59}
60 60
61static int mv88e6171_setup(struct dsa_switch *ds)
62{
63 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
64 int ret;
65
66 ps->ds = ds;
67
68 ret = mv88e6xxx_setup_common(ps);
69 if (ret < 0)
70 return ret;
71
72 return mv88e6xxx_setup_ports(ds);
73}
74
75struct dsa_switch_driver mv88e6171_switch_driver = { 61struct dsa_switch_driver mv88e6171_switch_driver = {
76 .tag_protocol = DSA_TAG_PROTO_EDSA, 62 .tag_protocol = DSA_TAG_PROTO_EDSA,
77 .probe = mv88e6171_drv_probe, 63 .probe = mv88e6171_drv_probe,
78 .setup = mv88e6171_setup, 64 .setup = mv88e6xxx_setup,
79 .set_addr = mv88e6xxx_set_addr, 65 .set_addr = mv88e6xxx_set_addr,
80 .phy_read = mv88e6xxx_phy_read, 66 .phy_read = mv88e6xxx_phy_read,
81 .phy_write = mv88e6xxx_phy_write, 67 .phy_write = mv88e6xxx_phy_write,
diff --git a/drivers/net/dsa/mv88e6352.c b/drivers/net/dsa/mv88e6352.c
index 81810ddcc47e..d65a90dca0b4 100644
--- a/drivers/net/dsa/mv88e6352.c
+++ b/drivers/net/dsa/mv88e6352.c
@@ -77,24 +77,10 @@ static const char *mv88e6352_drv_probe(struct device *dsa_dev,
77 ARRAY_SIZE(mv88e6352_table)); 77 ARRAY_SIZE(mv88e6352_table));
78} 78}
79 79
80static int mv88e6352_setup(struct dsa_switch *ds)
81{
82 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
83 int ret;
84
85 ps->ds = ds;
86
87 ret = mv88e6xxx_setup_common(ps);
88 if (ret < 0)
89 return ret;
90
91 return mv88e6xxx_setup_ports(ds);
92}
93
94struct dsa_switch_driver mv88e6352_switch_driver = { 80struct dsa_switch_driver mv88e6352_switch_driver = {
95 .tag_protocol = DSA_TAG_PROTO_EDSA, 81 .tag_protocol = DSA_TAG_PROTO_EDSA,
96 .probe = mv88e6352_drv_probe, 82 .probe = mv88e6352_drv_probe,
97 .setup = mv88e6352_setup, 83 .setup = mv88e6xxx_setup,
98 .set_addr = mv88e6xxx_set_addr, 84 .set_addr = mv88e6xxx_set_addr,
99 .phy_read = mv88e6xxx_phy_read, 85 .phy_read = mv88e6xxx_phy_read,
100 .phy_write = mv88e6xxx_phy_write, 86 .phy_write = mv88e6xxx_phy_write,
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index d8bb4c8e005f..7ea30502d221 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -2640,14 +2640,12 @@ static int mv88e6xxx_power_on_serdes(struct mv88e6xxx_priv_state *ps)
2640 return ret; 2640 return ret;
2641} 2641}
2642 2642
2643static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) 2643static int mv88e6xxx_setup_port(struct mv88e6xxx_priv_state *ps, int port)
2644{ 2644{
2645 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 2645 struct dsa_switch *ds = ps->ds;
2646 int ret; 2646 int ret;
2647 u16 reg; 2647 u16 reg;
2648 2648
2649 mutex_lock(&ps->smi_mutex);
2650
2651 if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || 2649 if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) ||
2652 mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || 2650 mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) ||
2653 mv88e6xxx_6185_family(ps) || mv88e6xxx_6095_family(ps) || 2651 mv88e6xxx_6185_family(ps) || mv88e6xxx_6095_family(ps) ||
@@ -2676,7 +2674,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2676 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2674 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2677 PORT_PCS_CTRL, reg); 2675 PORT_PCS_CTRL, reg);
2678 if (ret) 2676 if (ret)
2679 goto abort; 2677 return ret;
2680 } 2678 }
2681 2679
2682 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock, 2680 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
@@ -2740,7 +2738,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2740 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2738 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2741 PORT_CONTROL, reg); 2739 PORT_CONTROL, reg);
2742 if (ret) 2740 if (ret)
2743 goto abort; 2741 return ret;
2744 } 2742 }
2745 2743
2746 /* If this port is connected to a SerDes, make sure the SerDes is not 2744 /* If this port is connected to a SerDes, make sure the SerDes is not
@@ -2749,14 +2747,14 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2749 if (mv88e6xxx_6352_family(ps)) { 2747 if (mv88e6xxx_6352_family(ps)) {
2750 ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_STATUS); 2748 ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_STATUS);
2751 if (ret < 0) 2749 if (ret < 0)
2752 goto abort; 2750 return ret;
2753 ret &= PORT_STATUS_CMODE_MASK; 2751 ret &= PORT_STATUS_CMODE_MASK;
2754 if ((ret == PORT_STATUS_CMODE_100BASE_X) || 2752 if ((ret == PORT_STATUS_CMODE_100BASE_X) ||
2755 (ret == PORT_STATUS_CMODE_1000BASE_X) || 2753 (ret == PORT_STATUS_CMODE_1000BASE_X) ||
2756 (ret == PORT_STATUS_CMODE_SGMII)) { 2754 (ret == PORT_STATUS_CMODE_SGMII)) {
2757 ret = mv88e6xxx_power_on_serdes(ps); 2755 ret = mv88e6xxx_power_on_serdes(ps);
2758 if (ret < 0) 2756 if (ret < 0)
2759 goto abort; 2757 return ret;
2760 } 2758 }
2761 } 2759 }
2762 2760
@@ -2793,7 +2791,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2793 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2791 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2794 PORT_CONTROL_2, reg); 2792 PORT_CONTROL_2, reg);
2795 if (ret) 2793 if (ret)
2796 goto abort; 2794 return ret;
2797 } 2795 }
2798 2796
2799 /* Port Association Vector: when learning source addresses 2797 /* Port Association Vector: when learning source addresses
@@ -2808,13 +2806,13 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2808 2806
2809 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_ASSOC_VECTOR, reg); 2807 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_ASSOC_VECTOR, reg);
2810 if (ret) 2808 if (ret)
2811 goto abort; 2809 return ret;
2812 2810
2813 /* Egress rate control 2: disable egress rate control. */ 2811 /* Egress rate control 2: disable egress rate control. */
2814 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_RATE_CONTROL_2, 2812 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_RATE_CONTROL_2,
2815 0x0000); 2813 0x0000);
2816 if (ret) 2814 if (ret)
2817 goto abort; 2815 return ret;
2818 2816
2819 if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || 2817 if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) ||
2820 mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || 2818 mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) ||
@@ -2826,7 +2824,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2826 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2824 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2827 PORT_PAUSE_CTRL, 0x0000); 2825 PORT_PAUSE_CTRL, 0x0000);
2828 if (ret) 2826 if (ret)
2829 goto abort; 2827 return ret;
2830 2828
2831 /* Port ATU control: disable limiting the number of 2829 /* Port ATU control: disable limiting the number of
2832 * address database entries that this port is allowed 2830 * address database entries that this port is allowed
@@ -2840,7 +2838,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2840 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2838 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2841 PORT_PRI_OVERRIDE, 0x0000); 2839 PORT_PRI_OVERRIDE, 0x0000);
2842 if (ret) 2840 if (ret)
2843 goto abort; 2841 return ret;
2844 2842
2845 /* Port Ethertype: use the Ethertype DSA Ethertype 2843 /* Port Ethertype: use the Ethertype DSA Ethertype
2846 * value. 2844 * value.
@@ -2848,14 +2846,14 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2848 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2846 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2849 PORT_ETH_TYPE, ETH_P_EDSA); 2847 PORT_ETH_TYPE, ETH_P_EDSA);
2850 if (ret) 2848 if (ret)
2851 goto abort; 2849 return ret;
2852 /* Tag Remap: use an identity 802.1p prio -> switch 2850 /* Tag Remap: use an identity 802.1p prio -> switch
2853 * prio mapping. 2851 * prio mapping.
2854 */ 2852 */
2855 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2853 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2856 PORT_TAG_REGMAP_0123, 0x3210); 2854 PORT_TAG_REGMAP_0123, 0x3210);
2857 if (ret) 2855 if (ret)
2858 goto abort; 2856 return ret;
2859 2857
2860 /* Tag Remap 2: use an identity 802.1p prio -> switch 2858 /* Tag Remap 2: use an identity 802.1p prio -> switch
2861 * prio mapping. 2859 * prio mapping.
@@ -2863,7 +2861,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2863 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2861 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2864 PORT_TAG_REGMAP_4567, 0x7654); 2862 PORT_TAG_REGMAP_4567, 0x7654);
2865 if (ret) 2863 if (ret)
2866 goto abort; 2864 return ret;
2867 } 2865 }
2868 2866
2869 if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || 2867 if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) ||
@@ -2874,7 +2872,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2874 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), 2872 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
2875 PORT_RATE_CONTROL, 0x0001); 2873 PORT_RATE_CONTROL, 0x0001);
2876 if (ret) 2874 if (ret)
2877 goto abort; 2875 return ret;
2878 } 2876 }
2879 2877
2880 /* Port Control 1: disable trunking, disable sending 2878 /* Port Control 1: disable trunking, disable sending
@@ -2882,7 +2880,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2882 */ 2880 */
2883 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL_1, 0x0000); 2881 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL_1, 0x0000);
2884 if (ret) 2882 if (ret)
2885 goto abort; 2883 return ret;
2886 2884
2887 /* Port based VLAN map: give each port the same default address 2885 /* Port based VLAN map: give each port the same default address
2888 * database, and allow bidirectional communication between the 2886 * database, and allow bidirectional communication between the
@@ -2890,33 +2888,20 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
2890 */ 2888 */
2891 ret = _mv88e6xxx_port_fid_set(ps, port, 0); 2889 ret = _mv88e6xxx_port_fid_set(ps, port, 0);
2892 if (ret) 2890 if (ret)
2893 goto abort; 2891 return ret;
2894 2892
2895 ret = _mv88e6xxx_port_based_vlan_map(ps, port); 2893 ret = _mv88e6xxx_port_based_vlan_map(ps, port);
2896 if (ret) 2894 if (ret)
2897 goto abort; 2895 return ret;
2898 2896
2899 /* Default VLAN ID and priority: don't set a default VLAN 2897 /* Default VLAN ID and priority: don't set a default VLAN
2900 * ID, and set the default packet priority to zero. 2898 * ID, and set the default packet priority to zero.
2901 */ 2899 */
2902 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_DEFAULT_VLAN, 2900 ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_DEFAULT_VLAN,
2903 0x0000); 2901 0x0000);
2904abort: 2902 if (ret)
2905 mutex_unlock(&ps->smi_mutex); 2903 return ret;
2906 return ret;
2907}
2908
2909int mv88e6xxx_setup_ports(struct dsa_switch *ds)
2910{
2911 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2912 int ret;
2913 int i;
2914 2904
2915 for (i = 0; i < ps->info->num_ports; i++) {
2916 ret = mv88e6xxx_setup_port(ds, i);
2917 if (ret < 0)
2918 return ret;
2919 }
2920 return 0; 2905 return 0;
2921} 2906}
2922 2907
@@ -3123,9 +3108,13 @@ static int mv88e6xxx_setup_global(struct mv88e6xxx_priv_state *ps)
3123 return err; 3108 return err;
3124} 3109}
3125 3110
3126int mv88e6xxx_setup_common(struct mv88e6xxx_priv_state *ps) 3111int mv88e6xxx_setup(struct dsa_switch *ds)
3127{ 3112{
3113 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
3128 int err; 3114 int err;
3115 int i;
3116
3117 ps->ds = ds;
3129 3118
3130 mutex_init(&ps->smi_mutex); 3119 mutex_init(&ps->smi_mutex);
3131 3120
@@ -3144,6 +3133,14 @@ int mv88e6xxx_setup_common(struct mv88e6xxx_priv_state *ps)
3144 goto unlock; 3133 goto unlock;
3145 3134
3146 err = mv88e6xxx_setup_global(ps); 3135 err = mv88e6xxx_setup_global(ps);
3136 if (err)
3137 goto unlock;
3138
3139 for (i = 0; i < ps->info->num_ports; i++) {
3140 err = mv88e6xxx_setup_port(ps, i);
3141 if (err)
3142 goto unlock;
3143 }
3147 3144
3148unlock: 3145unlock:
3149 mutex_unlock(&ps->smi_mutex); 3146 mutex_unlock(&ps->smi_mutex);
diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h
index 62f6fc9510aa..a131827cb26d 100644
--- a/drivers/net/dsa/mv88e6xxx.h
+++ b/drivers/net/dsa/mv88e6xxx.h
@@ -588,8 +588,7 @@ const char *mv88e6xxx_drv_probe(struct device *dsa_dev, struct device *host_dev,
588 const struct mv88e6xxx_info *table, 588 const struct mv88e6xxx_info *table,
589 unsigned int num); 589 unsigned int num);
590 590
591int mv88e6xxx_setup_ports(struct dsa_switch *ds); 591int mv88e6xxx_setup(struct dsa_switch *ds);
592int mv88e6xxx_setup_common(struct mv88e6xxx_priv_state *ps);
593int mv88e6xxx_reg_read(struct mv88e6xxx_priv_state *ps, int addr, int reg); 592int mv88e6xxx_reg_read(struct mv88e6xxx_priv_state *ps, int addr, int reg);
594int mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr, 593int mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr,
595 int reg, u16 val); 594 int reg, u16 val);