701-net-0238-net-mscc-ocelot-break-apart-ocelot_vlan_port_apply.patch 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. From d00ac78e74e433109307f365ba90d34cd73aaf20 Mon Sep 17 00:00:00 2001
  2. From: Vladimir Oltean <[email protected]>
  3. Date: Sat, 9 Nov 2019 15:02:47 +0200
  4. Subject: [PATCH] net: mscc: ocelot: break apart ocelot_vlan_port_apply
  5. This patch transforms the ocelot_vlan_port_apply function ("apply
  6. what?") into 3 standalone functions:
  7. - ocelot_port_vlan_filtering
  8. - ocelot_port_set_native_vlan
  9. - ocelot_port_set_pvid
  10. These functions have a prototype that is better aligned to the DSA API.
  11. The function also had some static initialization (TPID, drop frames with
  12. multicast source MAC) which was not being changed from any place, so
  13. that was just moved to ocelot_probe_port (one of the 6 callers of
  14. ocelot_vlan_port_apply).
  15. Signed-off-by: Vladimir Oltean <[email protected]>
  16. Signed-off-by: David S. Miller <[email protected]>
  17. ---
  18. drivers/net/ethernet/mscc/ocelot.c | 168 ++++++++++++++++++++++---------------
  19. 1 file changed, 100 insertions(+), 68 deletions(-)
  20. --- a/drivers/net/ethernet/mscc/ocelot.c
  21. +++ b/drivers/net/ethernet/mscc/ocelot.c
  22. @@ -185,65 +185,97 @@ static void ocelot_vlan_mode(struct ocel
  23. ocelot_write(ocelot, val, ANA_VLANMASK);
  24. }
  25. -static void ocelot_vlan_port_apply(struct ocelot *ocelot,
  26. - struct ocelot_port *port)
  27. +static void ocelot_port_vlan_filtering(struct ocelot *ocelot, int port,
  28. + bool vlan_aware)
  29. {
  30. + struct ocelot_port *ocelot_port = ocelot->ports[port];
  31. u32 val;
  32. - /* Ingress clasification (ANA_PORT_VLAN_CFG) */
  33. - /* Default vlan to clasify for untagged frames (may be zero) */
  34. - val = ANA_PORT_VLAN_CFG_VLAN_VID(port->pvid);
  35. - if (port->vlan_aware)
  36. - val |= ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
  37. - ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
  38. -
  39. + if (vlan_aware)
  40. + val = ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
  41. + ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
  42. + else
  43. + val = 0;
  44. ocelot_rmw_gix(ocelot, val,
  45. - ANA_PORT_VLAN_CFG_VLAN_VID_M |
  46. ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
  47. ANA_PORT_VLAN_CFG_VLAN_POP_CNT_M,
  48. - ANA_PORT_VLAN_CFG, port->chip_port);
  49. + ANA_PORT_VLAN_CFG, port);
  50. - /* Drop frames with multicast source address */
  51. - val = ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA;
  52. - if (port->vlan_aware && !port->vid)
  53. + if (vlan_aware && !ocelot_port->vid)
  54. /* If port is vlan-aware and tagged, drop untagged and priority
  55. * tagged frames.
  56. */
  57. - val |= ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
  58. + val = ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
  59. + ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
  60. + ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;
  61. + else
  62. + val = 0;
  63. + ocelot_rmw_gix(ocelot, val,
  64. + ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
  65. ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
  66. - ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;
  67. - ocelot_write_gix(ocelot, val, ANA_PORT_DROP_CFG, port->chip_port);
  68. -
  69. - /* Egress configuration (REW_TAG_CFG): VLAN tag type to 8021Q. */
  70. - val = REW_TAG_CFG_TAG_TPID_CFG(0);
  71. + ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA,
  72. + ANA_PORT_DROP_CFG, port);
  73. - if (port->vlan_aware) {
  74. - if (port->vid)
  75. + if (vlan_aware) {
  76. + if (ocelot_port->vid)
  77. /* Tag all frames except when VID == DEFAULT_VLAN */
  78. val |= REW_TAG_CFG_TAG_CFG(1);
  79. else
  80. /* Tag all frames */
  81. val |= REW_TAG_CFG_TAG_CFG(3);
  82. + } else {
  83. + /* Port tagging disabled. */
  84. + val = REW_TAG_CFG_TAG_CFG(0);
  85. }
  86. ocelot_rmw_gix(ocelot, val,
  87. - REW_TAG_CFG_TAG_TPID_CFG_M |
  88. REW_TAG_CFG_TAG_CFG_M,
  89. - REW_TAG_CFG, port->chip_port);
  90. + REW_TAG_CFG, port);
  91. - /* Set default VLAN and tag type to 8021Q. */
  92. - val = REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q) |
  93. - REW_PORT_VLAN_CFG_PORT_VID(port->vid);
  94. - ocelot_rmw_gix(ocelot, val,
  95. - REW_PORT_VLAN_CFG_PORT_TPID_M |
  96. + ocelot_port->vlan_aware = vlan_aware;
  97. +}
  98. +
  99. +static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,
  100. + u16 vid)
  101. +{
  102. + struct ocelot_port *ocelot_port = ocelot->ports[port];
  103. +
  104. + if (ocelot_port->vid != vid) {
  105. + /* Always permit deleting the native VLAN (vid = 0) */
  106. + if (ocelot_port->vid && vid) {
  107. + dev_err(ocelot->dev,
  108. + "Port already has a native VLAN: %d\n",
  109. + ocelot_port->vid);
  110. + return -EBUSY;
  111. + }
  112. + ocelot_port->vid = vid;
  113. + }
  114. +
  115. + ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(vid),
  116. REW_PORT_VLAN_CFG_PORT_VID_M,
  117. - REW_PORT_VLAN_CFG, port->chip_port);
  118. + REW_PORT_VLAN_CFG, port);
  119. +
  120. + return 0;
  121. +}
  122. +
  123. +/* Default vlan to clasify for untagged frames (may be zero) */
  124. +static void ocelot_port_set_pvid(struct ocelot *ocelot, int port, u16 pvid)
  125. +{
  126. + struct ocelot_port *ocelot_port = ocelot->ports[port];
  127. +
  128. + ocelot_rmw_gix(ocelot,
  129. + ANA_PORT_VLAN_CFG_VLAN_VID(pvid),
  130. + ANA_PORT_VLAN_CFG_VLAN_VID_M,
  131. + ANA_PORT_VLAN_CFG, port);
  132. +
  133. + ocelot_port->pvid = pvid;
  134. }
  135. static int ocelot_vlan_vid_add(struct net_device *dev, u16 vid, bool pvid,
  136. bool untagged)
  137. {
  138. - struct ocelot_port *port = netdev_priv(dev);
  139. - struct ocelot *ocelot = port->ocelot;
  140. + struct ocelot_port *ocelot_port = netdev_priv(dev);
  141. + struct ocelot *ocelot = ocelot_port->ocelot;
  142. + int port = ocelot_port->chip_port;
  143. int ret;
  144. /* Add the port MAC address to with the right VLAN information */
  145. @@ -251,35 +283,30 @@ static int ocelot_vlan_vid_add(struct ne
  146. ENTRYTYPE_LOCKED);
  147. /* Make the port a member of the VLAN */
  148. - ocelot->vlan_mask[vid] |= BIT(port->chip_port);
  149. + ocelot->vlan_mask[vid] |= BIT(port);
  150. ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
  151. if (ret)
  152. return ret;
  153. /* Default ingress vlan classification */
  154. if (pvid)
  155. - port->pvid = vid;
  156. + ocelot_port_set_pvid(ocelot, port, vid);
  157. /* Untagged egress vlan clasification */
  158. - if (untagged && port->vid != vid) {
  159. - if (port->vid) {
  160. - dev_err(ocelot->dev,
  161. - "Port already has a native VLAN: %d\n",
  162. - port->vid);
  163. - return -EBUSY;
  164. - }
  165. - port->vid = vid;
  166. + if (untagged) {
  167. + ret = ocelot_port_set_native_vlan(ocelot, port, vid);
  168. + if (ret)
  169. + return ret;
  170. }
  171. - ocelot_vlan_port_apply(ocelot, port);
  172. -
  173. return 0;
  174. }
  175. static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid)
  176. {
  177. - struct ocelot_port *port = netdev_priv(dev);
  178. - struct ocelot *ocelot = port->ocelot;
  179. + struct ocelot_port *ocelot_port = netdev_priv(dev);
  180. + struct ocelot *ocelot = ocelot_port->ocelot;
  181. + int port = ocelot_port->chip_port;
  182. int ret;
  183. /* 8021q removes VID 0 on module unload for all interfaces
  184. @@ -293,20 +320,18 @@ static int ocelot_vlan_vid_del(struct ne
  185. ocelot_mact_forget(ocelot, dev->dev_addr, vid);
  186. /* Stop the port from being a member of the vlan */
  187. - ocelot->vlan_mask[vid] &= ~BIT(port->chip_port);
  188. + ocelot->vlan_mask[vid] &= ~BIT(port);
  189. ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
  190. if (ret)
  191. return ret;
  192. /* Ingress */
  193. - if (port->pvid == vid)
  194. - port->pvid = 0;
  195. + if (ocelot_port->pvid == vid)
  196. + ocelot_port_set_pvid(ocelot, port, 0);
  197. /* Egress */
  198. - if (port->vid == vid)
  199. - port->vid = 0;
  200. -
  201. - ocelot_vlan_port_apply(ocelot, port);
  202. + if (ocelot_port->vid == vid)
  203. + ocelot_port_set_native_vlan(ocelot, port, 0);
  204. return 0;
  205. }
  206. @@ -1306,6 +1331,7 @@ static int ocelot_port_attr_set(struct n
  207. struct switchdev_trans *trans)
  208. {
  209. struct ocelot_port *ocelot_port = netdev_priv(dev);
  210. + struct ocelot *ocelot = ocelot_port->ocelot;
  211. int err = 0;
  212. switch (attr->id) {
  213. @@ -1317,8 +1343,8 @@ static int ocelot_port_attr_set(struct n
  214. ocelot_port_attr_ageing_set(ocelot_port, attr->u.ageing_time);
  215. break;
  216. case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
  217. - ocelot_port->vlan_aware = attr->u.vlan_filtering;
  218. - ocelot_vlan_port_apply(ocelot_port->ocelot, ocelot_port);
  219. + ocelot_port_vlan_filtering(ocelot, ocelot_port->chip_port,
  220. + attr->u.vlan_filtering);
  221. break;
  222. case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
  223. ocelot_port_attr_mc_set(ocelot_port, !attr->u.mc_disabled);
  224. @@ -1520,20 +1546,20 @@ static int ocelot_port_bridge_join(struc
  225. return 0;
  226. }
  227. -static void ocelot_port_bridge_leave(struct ocelot_port *ocelot_port,
  228. - struct net_device *bridge)
  229. +static int ocelot_port_bridge_leave(struct ocelot_port *ocelot_port,
  230. + struct net_device *bridge)
  231. {
  232. struct ocelot *ocelot = ocelot_port->ocelot;
  233. + int port = ocelot_port->chip_port;
  234. - ocelot->bridge_mask &= ~BIT(ocelot_port->chip_port);
  235. + ocelot->bridge_mask &= ~BIT(port);
  236. if (!ocelot->bridge_mask)
  237. ocelot->hw_bridge_dev = NULL;
  238. - /* Clear bridge vlan settings before calling ocelot_vlan_port_apply */
  239. - ocelot_port->vlan_aware = 0;
  240. - ocelot_port->pvid = 0;
  241. - ocelot_port->vid = 0;
  242. + ocelot_port_vlan_filtering(ocelot, port, 0);
  243. + ocelot_port_set_pvid(ocelot, port, 0);
  244. + return ocelot_port_set_native_vlan(ocelot, port, 0);
  245. }
  246. static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
  247. @@ -1687,11 +1713,8 @@ static int ocelot_netdevice_port_event(s
  248. err = ocelot_port_bridge_join(ocelot_port,
  249. info->upper_dev);
  250. else
  251. - ocelot_port_bridge_leave(ocelot_port,
  252. - info->upper_dev);
  253. -
  254. - ocelot_vlan_port_apply(ocelot_port->ocelot,
  255. - ocelot_port);
  256. + err = ocelot_port_bridge_leave(ocelot_port,
  257. + info->upper_dev);
  258. }
  259. if (netif_is_lag_master(info->upper_dev)) {
  260. if (info->linking)
  261. @@ -2009,6 +2032,7 @@ int ocelot_probe_port(struct ocelot *oce
  262. {
  263. struct ocelot_port *ocelot_port;
  264. struct net_device *dev;
  265. + u32 val;
  266. int err;
  267. dev = alloc_etherdev(sizeof(struct ocelot_port));
  268. @@ -2044,7 +2068,15 @@ int ocelot_probe_port(struct ocelot *oce
  269. }
  270. /* Basic L2 initialization */
  271. - ocelot_vlan_port_apply(ocelot, ocelot_port);
  272. +
  273. + /* Drop frames with multicast source address */
  274. + val = ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA;
  275. + ocelot_rmw_gix(ocelot, val, val, ANA_PORT_DROP_CFG, port);
  276. +
  277. + /* Set default VLAN and tag type to 8021Q. */
  278. + ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q),
  279. + REW_PORT_VLAN_CFG_PORT_TPID_M,
  280. + REW_PORT_VLAN_CFG, port);
  281. /* Enable vcap lookups */
  282. ocelot_vcap_enable(ocelot, ocelot_port);