2
0

storm.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <asm/mach-rtl838x/mach-rtl83xx.h>
  3. #include "rtl83xx.h"
  4. static void rtl83xx_storm_enable(struct rtl838x_switch_priv *priv, int port, bool enable)
  5. {
  6. // Enable Storm control for that port for UC, MC, and BC
  7. if (enable)
  8. sw_w32(0x7, RTL838X_STORM_CTRL_LB_CTRL(port));
  9. else
  10. sw_w32(0x0, RTL838X_STORM_CTRL_LB_CTRL(port));
  11. }
  12. void __init rtl83xx_storm_control_init(struct rtl838x_switch_priv *priv)
  13. {
  14. int i;
  15. pr_debug("Enabling Storm control\n");
  16. // TICK_PERIOD_PPS
  17. if (priv->id == 0x8380)
  18. sw_w32_mask(0x3ff << 20, 434 << 20, RTL838X_SCHED_LB_TICK_TKN_CTRL_0);
  19. // Set burst rate
  20. sw_w32(0x00008000, RTL838X_STORM_CTRL_BURST_0); // UC
  21. sw_w32(0x80008000, RTL838X_STORM_CTRL_BURST_1); // MC and BC
  22. // Set burst Packets per Second to 32
  23. sw_w32(0x00000020, RTL838X_STORM_CTRL_BURST_PPS_0); // UC
  24. sw_w32(0x00200020, RTL838X_STORM_CTRL_BURST_PPS_1); // MC and BC
  25. // Include IFG in storm control
  26. sw_w32_mask(0, BIT(6), RTL838X_STORM_CTRL);
  27. // Rate control is based on bytes/s (0 = packets)
  28. sw_w32_mask(0, BIT(5), RTL838X_STORM_CTRL);
  29. // Bandwidth control includes preamble and IFG (10 Bytes)
  30. sw_w32_mask(0, 1, RTL838X_SCHED_CTRL);
  31. // On SoCs except RTL8382M, set burst size of port egress
  32. if (priv->id != 0x8382)
  33. sw_w32_mask(0xffff, 0x800, RTL838X_SCHED_LB_THR);
  34. /* Enable storm control on all ports with a PHY and limit rates,
  35. * for UC and MC for both known and unknown addresses */
  36. for (i = 0; i < priv->cpu_port; i++) {
  37. if (priv->ports[i].phy) {
  38. sw_w32(BIT(18) | 0x8000, RTL838X_STORM_CTRL_PORT_UC(i));
  39. sw_w32(BIT(18) | 0x8000, RTL838X_STORM_CTRL_PORT_MC(i));
  40. sw_w32(0x000, RTL838X_STORM_CTRL_PORT_BC(i));
  41. rtl83xx_storm_enable(priv, i, true);
  42. }
  43. }
  44. // Attack prevention, enable all attack prevention measures
  45. //sw_w32(0x1ffff, RTL838X_ATK_PRVNT_CTRL);
  46. /* Attack prevention, drop (bit = 0) problematic packets on all ports.
  47. * Setting bit = 1 means: trap to CPU
  48. */
  49. //sw_w32(0, RTL838X_ATK_PRVNT_ACT);
  50. // Enable attack prevention on all ports
  51. //sw_w32(0x0fffffff, RTL838X_ATK_PRVNT_PORT_EN);
  52. }