0033-dsa-multi-cpu.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. --- a/drivers/net/dsa/mt7530.c
  2. +++ b/drivers/net/dsa/mt7530.c
  3. @@ -670,6 +670,9 @@ static int
  4. mt7530_cpu_port_enable(struct mt7530_priv *priv,
  5. int port)
  6. {
  7. + u8 port_mask = 0;
  8. + int i;
  9. +
  10. /* Enable Mediatek header mode on the cpu port */
  11. mt7530_write(priv, MT7530_PVC_P(port),
  12. PORT_SPEC_TAG);
  13. @@ -686,8 +689,12 @@ mt7530_cpu_port_enable(struct mt7530_pri
  14. /* CPU port gets connected to all user ports of
  15. * the switch
  16. */
  17. + for (i = 0; i < MT7530_NUM_PORTS; i++)
  18. + if ((priv->ds->enabled_port_mask & BIT(i)) &&
  19. + (dsa_port_upstream_port(priv->ds, i) == port))
  20. + port_mask |= BIT(i);
  21. mt7530_write(priv, MT7530_PCR_P(port),
  22. - PCR_MATRIX(priv->ds->enabled_port_mask));
  23. + PCR_MATRIX(port_mask));
  24. return 0;
  25. }
  26. @@ -697,6 +704,7 @@ mt7530_port_enable(struct dsa_switch *ds
  27. struct phy_device *phy)
  28. {
  29. struct mt7530_priv *priv = ds->priv;
  30. + u8 upstream = dsa_port_upstream_port(ds, port);
  31. mutex_lock(&priv->reg_mutex);
  32. @@ -707,7 +715,7 @@ mt7530_port_enable(struct dsa_switch *ds
  33. * restore the port matrix if the port is the member of a certain
  34. * bridge.
  35. */
  36. - priv->ports[port].pm |= PCR_MATRIX(BIT(MT7530_CPU_PORT));
  37. + priv->ports[port].pm |= PCR_MATRIX(BIT(upstream));
  38. priv->ports[port].enable = true;
  39. mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
  40. priv->ports[port].pm);
  41. @@ -770,7 +778,8 @@ mt7530_port_bridge_join(struct dsa_switc
  42. struct net_device *bridge)
  43. {
  44. struct mt7530_priv *priv = ds->priv;
  45. - u32 port_bitmap = BIT(MT7530_CPU_PORT);
  46. + u8 upstream = dsa_port_upstream_port(ds, port);
  47. + u32 port_bitmap = BIT(upstream);
  48. int i;
  49. mutex_lock(&priv->reg_mutex);
  50. @@ -808,6 +817,7 @@ mt7530_port_bridge_leave(struct dsa_swit
  51. struct net_device *bridge)
  52. {
  53. struct mt7530_priv *priv = ds->priv;
  54. + u8 upstream = dsa_port_upstream_port(ds, port);
  55. int i;
  56. mutex_lock(&priv->reg_mutex);
  57. @@ -832,8 +842,8 @@ mt7530_port_bridge_leave(struct dsa_swit
  58. */
  59. if (priv->ports[port].enable)
  60. mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
  61. - PCR_MATRIX(BIT(MT7530_CPU_PORT)));
  62. - priv->ports[port].pm = PCR_MATRIX(BIT(MT7530_CPU_PORT));
  63. + PCR_MATRIX(BIT(upstream)));
  64. + priv->ports[port].pm = PCR_MATRIX(BIT(upstream));
  65. mutex_unlock(&priv->reg_mutex);
  66. }
  67. @@ -908,15 +918,7 @@ err:
  68. static enum dsa_tag_protocol
  69. mtk_get_tag_protocol(struct dsa_switch *ds)
  70. {
  71. - struct mt7530_priv *priv = ds->priv;
  72. -
  73. - if (!dsa_is_cpu_port(ds, MT7530_CPU_PORT)) {
  74. - dev_warn(priv->dev,
  75. - "port not matched with tagging CPU port\n");
  76. - return DSA_TAG_PROTO_NONE;
  77. - } else {
  78. - return DSA_TAG_PROTO_MTK;
  79. - }
  80. + return DSA_TAG_PROTO_MTK;
  81. }
  82. static int
  83. @@ -989,7 +991,7 @@ mt7530_setup(struct dsa_switch *ds)
  84. /* Enable Port 6 only; P5 as GMAC5 which currently is not supported */
  85. val = mt7530_read(priv, MT7530_MHWTRAP);
  86. - val &= ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS;
  87. + val &= ~MHWTRAP_P5_DIS & ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS;
  88. val |= MHWTRAP_MANUAL;
  89. if (!dsa_is_cpu_port(ds, 5)) {
  90. val |= MHWTRAP_P5_DIS;
  91. --- a/include/net/dsa.h
  92. +++ b/include/net/dsa.h
  93. @@ -185,6 +185,10 @@ struct dsa_port {
  94. u8 stp_state;
  95. struct net_device *bridge_dev;
  96. struct devlink_port devlink_port;
  97. +
  98. + struct net_device *ethernet;
  99. + int upstream;
  100. +
  101. /*
  102. * Original copy of the master netdev ethtool_ops
  103. */
  104. @@ -266,6 +270,11 @@ static inline bool dsa_is_normal_port(st
  105. return !dsa_is_cpu_port(ds, p) && !dsa_is_dsa_port(ds, p);
  106. }
  107. +static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int p)
  108. +{
  109. + return dsa_is_cpu_port(ds, p) || dsa_is_dsa_port(ds, p);
  110. +}
  111. +
  112. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  113. {
  114. struct dsa_switch_tree *dst = ds->dst;
  115. @@ -282,6 +291,18 @@ static inline u8 dsa_upstream_port(struc
  116. return ds->rtable[dst->cpu_dp->ds->index];
  117. }
  118. +static inline u8 dsa_port_upstream_port(struct dsa_switch *ds, int port)
  119. +{
  120. + /*
  121. + * If this port has a specific upstream cpu port, use it,
  122. + * otherwise use the switch default.
  123. + */
  124. + if (ds->ports[port].upstream)
  125. + return ds->ports[port].upstream;
  126. + else
  127. + return dsa_upstream_port(ds);
  128. +}
  129. +
  130. typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
  131. bool is_static, void *data);
  132. struct dsa_switch_ops {
  133. --- a/net/dsa/dsa2.c
  134. +++ b/net/dsa/dsa2.c
  135. @@ -253,6 +253,8 @@ static int dsa_cpu_port_apply(struct dsa
  136. memset(&port->devlink_port, 0, sizeof(port->devlink_port));
  137. err = devlink_port_register(ds->devlink, &port->devlink_port,
  138. port->index);
  139. + if (port->netdev)
  140. + port->netdev->dsa_ptr = ds->dst;
  141. return err;
  142. }
  143. @@ -262,6 +264,12 @@ static void dsa_cpu_port_unapply(struct
  144. dsa_cpu_dsa_destroy(port);
  145. port->ds->cpu_port_mask &= ~BIT(port->index);
  146. + if (port->netdev)
  147. + port->netdev->dsa_ptr = NULL;
  148. + if (port->ethernet) {
  149. + dev_put(port->ethernet);
  150. + port->ethernet = NULL;
  151. + }
  152. }
  153. static int dsa_user_port_apply(struct dsa_port *port)
  154. @@ -505,10 +513,9 @@ static int dsa_cpu_parse(struct dsa_port
  155. dev_put(ethernet_dev);
  156. }
  157. - if (!dst->cpu_dp) {
  158. + if (!dst->cpu_dp)
  159. dst->cpu_dp = port;
  160. - dst->cpu_dp->netdev = ethernet_dev;
  161. - }
  162. + port->netdev = ethernet_dev;
  163. /* Initialize cpu_port_mask now for drv->setup()
  164. * to have access to a correct value, just like what
  165. @@ -526,6 +533,29 @@ static int dsa_cpu_parse(struct dsa_port
  166. dst->rcv = dst->tag_ops->rcv;
  167. + dev_hold(ethernet_dev);
  168. + ds->ports[index].ethernet = ethernet_dev;
  169. + ds->cpu_port_mask |= BIT(index);
  170. +
  171. + return 0;
  172. +}
  173. +
  174. +static int dsa_user_parse(struct dsa_port *port, u32 index,
  175. + struct dsa_switch *ds)
  176. +{
  177. + struct device_node *cpu_port;
  178. + const unsigned int *cpu_port_reg;
  179. + int cpu_port_index;
  180. +
  181. + cpu_port = of_parse_phandle(port->dn, "cpu", 0);
  182. + if (cpu_port) {
  183. + cpu_port_reg = of_get_property(cpu_port, "reg", NULL);
  184. + if (!cpu_port_reg)
  185. + return -EINVAL;
  186. + cpu_port_index = be32_to_cpup(cpu_port_reg);
  187. + ds->ports[index].upstream = cpu_port_index;
  188. + }
  189. +
  190. return 0;
  191. }
  192. @@ -533,7 +563,7 @@ static int dsa_ds_parse(struct dsa_switc
  193. {
  194. struct dsa_port *port;
  195. u32 index;
  196. - int err;
  197. + int err = 0;
  198. for (index = 0; index < ds->num_ports; index++) {
  199. port = &ds->ports[index];
  200. @@ -546,6 +576,9 @@ static int dsa_ds_parse(struct dsa_switc
  201. if (err)
  202. return err;
  203. } else {
  204. + err = dsa_user_parse(port, index, ds);
  205. + if (err)
  206. + return err;
  207. /* Initialize enabled_port_mask now for drv->setup()
  208. * to have access to a correct value, just like what
  209. * net/dsa/dsa.c::dsa_switch_setup_one does.
  210. --- a/net/dsa/dsa_priv.h
  211. +++ b/net/dsa/dsa_priv.h
  212. @@ -91,6 +91,8 @@ struct dsa_slave_priv {
  213. /* TC context */
  214. struct list_head mall_tc_list;
  215. +
  216. + struct net_device *master;
  217. };
  218. /* dsa.c */
  219. @@ -177,6 +179,9 @@ extern const struct dsa_device_ops trail
  220. static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p)
  221. {
  222. + if (p->master)
  223. + return p->master;
  224. +
  225. return p->dp->cpu_dp->netdev;
  226. }
  227. --- a/net/dsa/slave.c
  228. +++ b/net/dsa/slave.c
  229. @@ -1267,7 +1267,7 @@ int dsa_slave_create(struct dsa_port *po
  230. int ret;
  231. cpu_dp = ds->dst->cpu_dp;
  232. - master = cpu_dp->netdev;
  233. + master = ds->ports[port->upstream].ethernet;
  234. if (!ds->num_tx_queues)
  235. ds->num_tx_queues = 1;
  236. @@ -1305,6 +1305,7 @@ int dsa_slave_create(struct dsa_port *po
  237. p->dp = port;
  238. INIT_LIST_HEAD(&p->mall_tc_list);
  239. p->xmit = dst->tag_ops->xmit;
  240. + p->master = master;
  241. p->old_pause = -1;
  242. p->old_link = -1;