cpsw_ale.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 reg_fields;
  11. struct cpsw_ale_params {
  12. struct device *dev;
  13. void __iomem *ale_regs;
  14. unsigned long ale_ageout; /* in secs */
  15. unsigned long ale_entries;
  16. unsigned long num_policers;
  17. unsigned long ale_ports;
  18. /* NU Switch has specific handling as number of bits in ALE entries
  19. * are different than other versions of ALE. Also there are specific
  20. * registers for unknown vlan specific fields. So use nu_switch_ale
  21. * to identify this hardware.
  22. */
  23. bool nu_switch_ale;
  24. const struct reg_field *reg_fields;
  25. int num_fields;
  26. const char *dev_id;
  27. unsigned long bus_freq;
  28. };
  29. struct ale_entry_fld;
  30. struct regmap;
  31. enum ale_fields {
  32. MINOR_VER,
  33. MAJOR_VER,
  34. ALE_ENTRIES,
  35. ALE_POLICERS,
  36. POL_PORT_MEN,
  37. POL_TRUNK_ID,
  38. POL_PORT_NUM,
  39. POL_PRI_MEN,
  40. POL_PRI_VAL,
  41. POL_OUI_MEN,
  42. POL_OUI_INDEX,
  43. POL_DST_MEN,
  44. POL_DST_INDEX,
  45. POL_SRC_MEN,
  46. POL_SRC_INDEX,
  47. POL_OVLAN_MEN,
  48. POL_OVLAN_INDEX,
  49. POL_IVLAN_MEN,
  50. POL_IVLAN_INDEX,
  51. POL_ETHERTYPE_MEN,
  52. POL_ETHERTYPE_INDEX,
  53. POL_IPSRC_MEN,
  54. POL_IPSRC_INDEX,
  55. POL_IPDST_MEN,
  56. POL_IPDST_INDEX,
  57. POL_EN,
  58. POL_RED_DROP_EN,
  59. POL_YELLOW_DROP_EN,
  60. POL_YELLOW_THRESH,
  61. POL_POL_MATCH_MODE,
  62. POL_PRIORITY_THREAD_EN,
  63. POL_MAC_ONLY_DEF_DIS,
  64. POL_TEST_CLR,
  65. POL_TEST_CLR_RED,
  66. POL_TEST_CLR_YELLOW,
  67. POL_TEST_CLR_SELECTED,
  68. POL_TEST_ENTRY,
  69. POL_STATUS_HIT,
  70. POL_STATUS_HIT_RED,
  71. POL_STATUS_HIT_YELLOW,
  72. ALE_DEFAULT_THREAD_EN,
  73. ALE_DEFAULT_THREAD_VAL,
  74. ALE_THREAD_CLASS_INDEX,
  75. ALE_THREAD_ENABLE,
  76. ALE_THREAD_VALUE,
  77. /* terminator */
  78. ALE_FIELDS_MAX,
  79. };
  80. struct cpsw_ale {
  81. struct cpsw_ale_params params;
  82. struct timer_list timer;
  83. struct regmap *regmap;
  84. struct regmap_field *fields[ALE_FIELDS_MAX];
  85. unsigned long ageout;
  86. u32 version;
  87. u32 features;
  88. /* These bits are different on NetCP NU Switch ALE */
  89. u32 port_mask_bits;
  90. u32 port_num_bits;
  91. u32 vlan_field_bits;
  92. unsigned long *p0_untag_vid_mask;
  93. const struct ale_entry_fld *vlan_entry_tbl;
  94. };
  95. enum cpsw_ale_control {
  96. /* global */
  97. ALE_ENABLE,
  98. ALE_CLEAR,
  99. ALE_AGEOUT,
  100. ALE_P0_UNI_FLOOD,
  101. ALE_VLAN_NOLEARN,
  102. ALE_NO_PORT_VLAN,
  103. ALE_OUI_DENY,
  104. ALE_BYPASS,
  105. ALE_RATE_LIMIT_TX,
  106. ALE_VLAN_AWARE,
  107. ALE_AUTH_ENABLE,
  108. ALE_RATE_LIMIT,
  109. /* port controls */
  110. ALE_PORT_STATE,
  111. ALE_PORT_DROP_UNTAGGED,
  112. ALE_PORT_DROP_UNKNOWN_VLAN,
  113. ALE_PORT_NOLEARN,
  114. ALE_PORT_NO_SA_UPDATE,
  115. ALE_PORT_UNKNOWN_VLAN_MEMBER,
  116. ALE_PORT_UNKNOWN_MCAST_FLOOD,
  117. ALE_PORT_UNKNOWN_REG_MCAST_FLOOD,
  118. ALE_PORT_UNTAGGED_EGRESS,
  119. ALE_PORT_MACONLY,
  120. ALE_PORT_MACONLY_CAF,
  121. ALE_PORT_BCAST_LIMIT,
  122. ALE_PORT_MCAST_LIMIT,
  123. ALE_DEFAULT_THREAD_ID,
  124. ALE_DEFAULT_THREAD_ENABLE,
  125. ALE_NUM_CONTROLS,
  126. };
  127. enum cpsw_ale_port_state {
  128. ALE_PORT_STATE_DISABLE = 0x00,
  129. ALE_PORT_STATE_BLOCK = 0x01,
  130. ALE_PORT_STATE_LEARN = 0x02,
  131. ALE_PORT_STATE_FORWARD = 0x03,
  132. };
  133. /* ALE unicast entry flags - passed into cpsw_ale_add_ucast() */
  134. #define ALE_SECURE BIT(0)
  135. #define ALE_BLOCKED BIT(1)
  136. #define ALE_SUPER BIT(2)
  137. #define ALE_VLAN BIT(3)
  138. #define ALE_PORT_HOST BIT(0)
  139. #define ALE_PORT_1 BIT(1)
  140. #define ALE_PORT_2 BIT(2)
  141. #define ALE_MCAST_FWD 0
  142. #define ALE_MCAST_BLOCK_LEARN_FWD 1
  143. #define ALE_MCAST_FWD_LEARN 2
  144. #define ALE_MCAST_FWD_2 3
  145. #define ALE_ENTRY_BITS 68
  146. #define ALE_ENTRY_WORDS DIV_ROUND_UP(ALE_ENTRY_BITS, 32)
  147. struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params);
  148. void cpsw_ale_start(struct cpsw_ale *ale);
  149. void cpsw_ale_stop(struct cpsw_ale *ale);
  150. int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid);
  151. int cpsw_ale_add_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
  152. int flags, u16 vid);
  153. int cpsw_ale_del_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
  154. int flags, u16 vid);
  155. int cpsw_ale_add_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
  156. int flags, u16 vid, int mcast_state);
  157. int cpsw_ale_del_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
  158. int flags, u16 vid);
  159. int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port, int untag,
  160. int reg_mcast, int unreg_mcast);
  161. int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port);
  162. void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti, int port);
  163. int cpsw_ale_rx_ratelimit_bc(struct cpsw_ale *ale, int port, unsigned int ratelimit_pps);
  164. int cpsw_ale_rx_ratelimit_mc(struct cpsw_ale *ale, int port, unsigned int ratelimit_pps);
  165. int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control);
  166. int cpsw_ale_control_set(struct cpsw_ale *ale, int port,
  167. int control, int value);
  168. void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data);
  169. void cpsw_ale_restore(struct cpsw_ale *ale, u32 *data);
  170. u32 cpsw_ale_get_num_entries(struct cpsw_ale *ale);
  171. static inline int cpsw_ale_get_vlan_p0_untag(struct cpsw_ale *ale, u16 vid)
  172. {
  173. return test_bit(vid, ale->p0_untag_vid_mask);
  174. }
  175. int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask,
  176. int untag_mask, int reg_mcast, int unreg_mcast);
  177. int cpsw_ale_vlan_del_modify(struct cpsw_ale *ale, u16 vid, int port_mask);
  178. void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask,
  179. bool add);
  180. void cpsw_ale_classifier_setup_default(struct cpsw_ale *ale, int num_rx_ch);
  181. #endif