spectrum_router.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
  2. /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
  3. #ifndef _MLXSW_ROUTER_H_
  4. #define _MLXSW_ROUTER_H_
  5. #include "spectrum.h"
  6. #include "reg.h"
  7. enum mlxsw_sp_l3proto {
  8. MLXSW_SP_L3_PROTO_IPV4,
  9. MLXSW_SP_L3_PROTO_IPV6,
  10. #define MLXSW_SP_L3_PROTO_MAX (MLXSW_SP_L3_PROTO_IPV6 + 1)
  11. };
  12. union mlxsw_sp_l3addr {
  13. __be32 addr4;
  14. struct in6_addr addr6;
  15. };
  16. struct mlxsw_sp_rif_ipip_lb;
  17. struct mlxsw_sp_rif_ipip_lb_config {
  18. enum mlxsw_reg_ritr_loopback_ipip_type lb_ipipt;
  19. u32 okey;
  20. enum mlxsw_sp_l3proto ul_protocol; /* Underlay. */
  21. union mlxsw_sp_l3addr saddr;
  22. };
  23. enum mlxsw_sp_rif_counter_dir {
  24. MLXSW_SP_RIF_COUNTER_INGRESS,
  25. MLXSW_SP_RIF_COUNTER_EGRESS,
  26. };
  27. struct mlxsw_sp_neigh_entry;
  28. struct mlxsw_sp_nexthop;
  29. struct mlxsw_sp_ipip_entry;
  30. struct mlxsw_sp_rif *mlxsw_sp_rif_find_by_dev(const struct mlxsw_sp *mlxsw_sp,
  31. const struct net_device *dev);
  32. struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp,
  33. u16 rif_index);
  34. u16 mlxsw_sp_rif_index(const struct mlxsw_sp_rif *rif);
  35. u16 mlxsw_sp_ipip_lb_rif_index(const struct mlxsw_sp_rif_ipip_lb *rif);
  36. u16 mlxsw_sp_ipip_lb_ul_vr_id(const struct mlxsw_sp_rif_ipip_lb *rif);
  37. u32 mlxsw_sp_ipip_dev_ul_tb_id(const struct net_device *ol_dev);
  38. int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif);
  39. u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
  40. const struct net_device *mlxsw_sp_rif_dev(const struct mlxsw_sp_rif *rif);
  41. struct mlxsw_sp_fid *mlxsw_sp_rif_fid(const struct mlxsw_sp_rif *rif);
  42. int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp,
  43. struct mlxsw_sp_rif *rif,
  44. enum mlxsw_sp_rif_counter_dir dir,
  45. u64 *cnt);
  46. void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp,
  47. struct mlxsw_sp_rif *rif,
  48. enum mlxsw_sp_rif_counter_dir dir);
  49. int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp,
  50. struct mlxsw_sp_rif *rif,
  51. enum mlxsw_sp_rif_counter_dir dir);
  52. struct mlxsw_sp_neigh_entry *
  53. mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
  54. struct mlxsw_sp_neigh_entry *neigh_entry);
  55. int mlxsw_sp_neigh_entry_type(struct mlxsw_sp_neigh_entry *neigh_entry);
  56. unsigned char *
  57. mlxsw_sp_neigh_entry_ha(struct mlxsw_sp_neigh_entry *neigh_entry);
  58. u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
  59. struct in6_addr *
  60. mlxsw_sp_neigh6_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
  61. #define mlxsw_sp_rif_neigh_for_each(neigh_entry, rif) \
  62. for (neigh_entry = mlxsw_sp_rif_neigh_next(rif, NULL); neigh_entry; \
  63. neigh_entry = mlxsw_sp_rif_neigh_next(rif, neigh_entry))
  64. int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
  65. struct mlxsw_sp_neigh_entry *neigh_entry,
  66. u64 *p_counter);
  67. void
  68. mlxsw_sp_neigh_entry_counter_update(struct mlxsw_sp *mlxsw_sp,
  69. struct mlxsw_sp_neigh_entry *neigh_entry,
  70. bool adding);
  71. bool mlxsw_sp_neigh_ipv6_ignore(struct mlxsw_sp_neigh_entry *neigh_entry);
  72. int __mlxsw_sp_ipip_entry_update_tunnel(struct mlxsw_sp *mlxsw_sp,
  73. struct mlxsw_sp_ipip_entry *ipip_entry,
  74. bool recreate_loopback,
  75. bool keep_encap,
  76. bool update_nexthops,
  77. struct netlink_ext_ack *extack);
  78. void mlxsw_sp_ipip_entry_demote_tunnel(struct mlxsw_sp *mlxsw_sp,
  79. struct mlxsw_sp_ipip_entry *ipip_entry);
  80. bool
  81. mlxsw_sp_ipip_demote_tunnel_by_saddr(struct mlxsw_sp *mlxsw_sp,
  82. enum mlxsw_sp_l3proto ul_proto,
  83. union mlxsw_sp_l3addr saddr,
  84. u32 ul_tb_id,
  85. const struct mlxsw_sp_ipip_entry *except);
  86. struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,
  87. struct mlxsw_sp_nexthop *nh);
  88. bool mlxsw_sp_nexthop_offload(struct mlxsw_sp_nexthop *nh);
  89. unsigned char *mlxsw_sp_nexthop_ha(struct mlxsw_sp_nexthop *nh);
  90. int mlxsw_sp_nexthop_indexes(struct mlxsw_sp_nexthop *nh, u32 *p_adj_index,
  91. u32 *p_adj_size, u32 *p_adj_hash_index);
  92. struct mlxsw_sp_rif *mlxsw_sp_nexthop_rif(struct mlxsw_sp_nexthop *nh);
  93. bool mlxsw_sp_nexthop_group_has_ipip(struct mlxsw_sp_nexthop *nh);
  94. #define mlxsw_sp_nexthop_for_each(nh, router) \
  95. for (nh = mlxsw_sp_nexthop_next(router, NULL); nh; \
  96. nh = mlxsw_sp_nexthop_next(router, nh))
  97. int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
  98. struct mlxsw_sp_nexthop *nh, u64 *p_counter);
  99. int mlxsw_sp_nexthop_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
  100. struct mlxsw_sp_nexthop *nh);
  101. void mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp,
  102. struct mlxsw_sp_nexthop *nh);
  103. void mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
  104. struct mlxsw_sp_nexthop *nh);
  105. static inline bool mlxsw_sp_l3addr_eq(const union mlxsw_sp_l3addr *addr1,
  106. const union mlxsw_sp_l3addr *addr2)
  107. {
  108. return !memcmp(addr1, addr2, sizeof(*addr1));
  109. }
  110. #endif /* _MLXSW_ROUTER_H_*/