cpsw_ale.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Texas Instruments N-Port Ethernet Switch Address Lookup Engine APIs
  4. *
  5. * Copyright (C) 2012 Texas Instruments
  6. *
  7. */
  8. #ifndef __TI_CPSW_ALE_H__
  9. #define __TI_CPSW_ALE_H__
  10. struct cpsw_ale_params {
  11. struct device *dev;
  12. void __iomem *ale_regs;
  13. unsigned long ale_ageout; /* in secs */
  14. unsigned long ale_entries;
  15. unsigned long ale_ports;
  16. /* NU Switch has specific handling as number of bits in ALE entries
  17. * are different than other versions of ALE. Also there are specific
  18. * registers for unknown vlan specific fields. So use nu_switch_ale
  19. * to identify this hardware.
  20. */
  21. bool nu_switch_ale;
  22. /* mask bit used in NU Switch ALE is 3 bits instead of 8 bits. So
  23. * pass it from caller.
  24. */
  25. u32 major_ver_mask;
  26. const char *dev_id;
  27. unsigned long bus_freq;
  28. };
  29. struct ale_entry_fld;
  30. struct cpsw_ale {
  31. struct cpsw_ale_params params;
  32. struct timer_list timer;
  33. unsigned long ageout;
  34. u32 version;
  35. u32 features;
  36. /* These bits are different on NetCP NU Switch ALE */
  37. u32 port_mask_bits;
  38. u32 port_num_bits;
  39. u32 vlan_field_bits;
  40. unsigned long *p0_untag_vid_mask;
  41. const struct ale_entry_fld *vlan_entry_tbl;
  42. };
  43. enum cpsw_ale_control {
  44. /* global */
  45. ALE_ENABLE,
  46. ALE_CLEAR,
  47. ALE_AGEOUT,
  48. ALE_P0_UNI_FLOOD,
  49. ALE_VLAN_NOLEARN,
  50. ALE_NO_PORT_VLAN,
  51. ALE_OUI_DENY,
  52. ALE_BYPASS,
  53. ALE_RATE_LIMIT_TX,
  54. ALE_VLAN_AWARE,
  55. ALE_AUTH_ENABLE,
  56. ALE_RATE_LIMIT,
  57. /* port controls */
  58. ALE_PORT_STATE,
  59. ALE_PORT_DROP_UNTAGGED,
  60. ALE_PORT_DROP_UNKNOWN_VLAN,
  61. ALE_PORT_NOLEARN,
  62. ALE_PORT_NO_SA_UPDATE,
  63. ALE_PORT_UNKNOWN_VLAN_MEMBER,
  64. ALE_PORT_UNKNOWN_MCAST_FLOOD,
  65. ALE_PORT_UNKNOWN_REG_MCAST_FLOOD,
  66. ALE_PORT_UNTAGGED_EGRESS,
  67. ALE_PORT_MACONLY,
  68. ALE_PORT_MACONLY_CAF,
  69. ALE_PORT_BCAST_LIMIT,
  70. ALE_PORT_MCAST_LIMIT,
  71. ALE_DEFAULT_THREAD_ID,
  72. ALE_DEFAULT_THREAD_ENABLE,
  73. ALE_NUM_CONTROLS,
  74. };
  75. enum cpsw_ale_port_state {
  76. ALE_PORT_STATE_DISABLE = 0x00,
  77. ALE_PORT_STATE_BLOCK = 0x01,
  78. ALE_PORT_STATE_LEARN = 0x02,
  79. ALE_PORT_STATE_FORWARD = 0x03,
  80. };
  81. /* ALE unicast entry flags - passed into cpsw_ale_add_ucast() */
  82. #define ALE_SECURE BIT(0)
  83. #define ALE_BLOCKED BIT(1)
  84. #define ALE_SUPER BIT(2)
  85. #define ALE_VLAN BIT(3)
  86. #define ALE_PORT_HOST BIT(0)
  87. #define ALE_PORT_1 BIT(1)
  88. #define ALE_PORT_2 BIT(2)
  89. #define ALE_MCAST_FWD 0
  90. #define ALE_MCAST_BLOCK_LEARN_FWD 1
  91. #define ALE_MCAST_FWD_LEARN 2
  92. #define ALE_MCAST_FWD_2 3
  93. #define ALE_ENTRY_BITS 68
  94. #define ALE_ENTRY_WORDS DIV_ROUND_UP(ALE_ENTRY_BITS, 32)
  95. struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params);
  96. void cpsw_ale_start(struct cpsw_ale *ale);
  97. void cpsw_ale_stop(struct cpsw_ale *ale);
  98. int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid);
  99. int cpsw_ale_add_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
  100. int flags, u16 vid);
  101. int cpsw_ale_del_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
  102. int flags, u16 vid);
  103. int cpsw_ale_add_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
  104. int flags, u16 vid, int mcast_state);
  105. int cpsw_ale_del_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
  106. int flags, u16 vid);
  107. int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port, int untag,
  108. int reg_mcast, int unreg_mcast);
  109. int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port);
  110. void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti, int port);
  111. int cpsw_ale_rx_ratelimit_bc(struct cpsw_ale *ale, int port, unsigned int ratelimit_pps);
  112. int cpsw_ale_rx_ratelimit_mc(struct cpsw_ale *ale, int port, unsigned int ratelimit_pps);
  113. int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control);
  114. int cpsw_ale_control_set(struct cpsw_ale *ale, int port,
  115. int control, int value);
  116. void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data);
  117. u32 cpsw_ale_get_num_entries(struct cpsw_ale *ale);
  118. static inline int cpsw_ale_get_vlan_p0_untag(struct cpsw_ale *ale, u16 vid)
  119. {
  120. return test_bit(vid, ale->p0_untag_vid_mask);
  121. }
  122. int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask,
  123. int untag_mask, int reg_mcast, int unreg_mcast);
  124. int cpsw_ale_vlan_del_modify(struct cpsw_ale *ale, u16 vid, int port_mask);
  125. void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask,
  126. bool add);
  127. #endif