rtw_mesh_pathtbl.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #ifndef __RTW_MESH_PATHTBL_H_
  16. #define __RTW_MESH_PATHTBL_H_
  17. #ifndef DBG_RTW_MPATH
  18. #define DBG_RTW_MPATH 1
  19. #endif
  20. #if DBG_RTW_MPATH
  21. #define RTW_MPATH_DBG(fmt, arg...) RTW_PRINT(fmt, ##arg)
  22. #else
  23. #define RTW_MPATH_DBG(fmt, arg...) do {} while (0)
  24. #endif
  25. /**
  26. * enum rtw_mesh_path_flags - mesh path flags
  27. *
  28. * @RTW_MESH_PATH_ACTIVE: the mesh path can be used for forwarding
  29. * @RTW_MESH_PATH_RESOLVING: the discovery process is running for this mesh path
  30. * @RTW_MESH_PATH_SN_VALID: the mesh path contains a valid destination sequence
  31. * number
  32. * @RTW_MESH_PATH_FIXED: the mesh path has been manually set and should not be
  33. * modified
  34. * @RTW_MESH_PATH_RESOLVED: the mesh path can has been resolved
  35. * @RTW_MESH_PATH_REQ_QUEUED: there is an unsent path request for this destination
  36. * already queued up, waiting for the discovery process to start.
  37. * @RTW_MESH_PATH_DELETED: the mesh path has been deleted and should no longer
  38. * be used
  39. * @RTW_MESH_PATH_ROOT_ADD_CHK: root additional check in root mode.
  40. * With this flag, It will try the last used rann_snd_addr
  41. * @RTW_MESH_PATH_PEER_AKA: only used toward a peer, only used in active keep
  42. * alive mechanism. PREQ's da = path dst
  43. *
  44. * RTW_MESH_PATH_RESOLVED is used by the mesh path timer to
  45. * decide when to stop or cancel the mesh path discovery.
  46. */
  47. enum rtw_mesh_path_flags {
  48. RTW_MESH_PATH_ACTIVE = BIT(0),
  49. RTW_MESH_PATH_RESOLVING = BIT(1),
  50. RTW_MESH_PATH_SN_VALID = BIT(2),
  51. RTW_MESH_PATH_FIXED = BIT(3),
  52. RTW_MESH_PATH_RESOLVED = BIT(4),
  53. RTW_MESH_PATH_REQ_QUEUED = BIT(5),
  54. RTW_MESH_PATH_DELETED = BIT(6),
  55. RTW_MESH_PATH_ROOT_ADD_CHK = BIT(7),
  56. RTW_MESH_PATH_PEER_AKA = BIT(8),
  57. };
  58. /**
  59. * struct rtw_mesh_path - mesh path structure
  60. *
  61. * @dst: mesh path destination mac address
  62. * @mpp: mesh proxy mac address
  63. * @rhash: rhashtable list pointer
  64. * @gate_list: list pointer for known gates list
  65. * @sdata: mesh subif
  66. * @next_hop: mesh neighbor to which frames for this destination will be
  67. * forwarded
  68. * @timer: mesh path discovery timer
  69. * @frame_queue: pending queue for frames sent to this destination while the
  70. * path is unresolved
  71. * @rcu: rcu head for freeing mesh path
  72. * @sn: target sequence number
  73. * @metric: current metric to this destination
  74. * @hop_count: hops to destination
  75. * @exp_time: in jiffies, when the path will expire or when it expired
  76. * @discovery_timeout: timeout (lapse in jiffies) used for the last discovery
  77. * retry
  78. * @discovery_retries: number of discovery retries
  79. * @flags: mesh path flags, as specified on &enum rtw_mesh_path_flags
  80. * @state_lock: mesh path state lock used to protect changes to the
  81. * mpath itself. No need to take this lock when adding or removing
  82. * an mpath to a hash bucket on a path table.
  83. * @rann_snd_addr: the RANN sender address
  84. * @rann_metric: the aggregated path metric towards the root node
  85. * @last_preq_to_root: Timestamp of last PREQ sent to root
  86. * @is_root: the destination station of this path is a root node
  87. * @is_gate: the destination station of this path is a mesh gate
  88. *
  89. *
  90. * The dst address is unique in the mesh path table. Since the mesh_path is
  91. * protected by RCU, deleting the next_hop STA must remove / substitute the
  92. * mesh_path structure and wait until that is no longer reachable before
  93. * destroying the STA completely.
  94. */
  95. struct rtw_mesh_path {
  96. u8 dst[ETH_ALEN];
  97. u8 mpp[ETH_ALEN]; /* used for MPP or MAP */
  98. rtw_rhash_head rhash;
  99. rtw_hlist_node gate_list;
  100. _adapter *adapter;
  101. struct sta_info __rcu *next_hop;
  102. _timer timer;
  103. _queue frame_queue;
  104. u32 frame_queue_len;
  105. rtw_rcu_head rcu;
  106. u32 sn;
  107. u32 metric;
  108. u8 hop_count;
  109. systime exp_time;
  110. systime discovery_timeout;
  111. systime gate_timeout;
  112. u32 gate_ann_int; /* gate announce interval */
  113. u8 discovery_retries;
  114. enum rtw_mesh_path_flags flags;
  115. _lock state_lock;
  116. u8 rann_snd_addr[ETH_ALEN];
  117. #ifdef CONFIG_RTW_MESH_ADD_ROOT_CHK
  118. u8 add_chk_rann_snd_addr[ETH_ALEN];
  119. #endif
  120. u32 rann_metric;
  121. unsigned long last_preq_to_root;
  122. bool is_root;
  123. bool is_gate;
  124. bool gate_asked;
  125. };
  126. /**
  127. * struct rtw_mesh_table
  128. *
  129. * @known_gates: list of known mesh gates and their mpaths by the station. The
  130. * gate's mpath may or may not be resolved and active.
  131. * @gates_lock: protects updates to known_gates
  132. * @rhead: the rhashtable containing struct mesh_paths, keyed by dest addr
  133. * @entries: number of entries in the table
  134. */
  135. struct rtw_mesh_table {
  136. rtw_hlist_head known_gates;
  137. _lock gates_lock;
  138. rtw_rhashtable rhead;
  139. ATOMIC_T entries;
  140. };
  141. #define RTW_MESH_PATH_EXPIRE (600 * HZ)
  142. /* Maximum number of paths per interface */
  143. #define RTW_MESH_MAX_MPATHS 1024
  144. /* Number of frames buffered per destination for unresolved destinations */
  145. #define RTW_MESH_FRAME_QUEUE_LEN 10
  146. int rtw_mesh_nexthop_lookup(_adapter *adapter,
  147. const u8 *mda, const u8 *msa, u8 *ra);
  148. int rtw_mesh_nexthop_resolve(_adapter *adapter,
  149. struct xmit_frame *xframe);
  150. struct rtw_mesh_path *rtw_mesh_path_lookup(_adapter *adapter,
  151. const u8 *dst);
  152. struct rtw_mesh_path *rtw_mpp_path_lookup(_adapter *adapter,
  153. const u8 *dst);
  154. int rtw_mpp_path_add(_adapter *adapter,
  155. const u8 *dst, const u8 *mpp);
  156. void dump_mpp(void *sel, _adapter *adapter);
  157. struct rtw_mesh_path *
  158. rtw_mesh_path_lookup_by_idx(_adapter *adapter, int idx);
  159. struct rtw_mesh_path *
  160. rtw_mpp_path_lookup_by_idx(_adapter *adapter, int idx);
  161. void rtw_mesh_path_fix_nexthop(struct rtw_mesh_path *mpath, struct sta_info *next_hop);
  162. void rtw_mesh_path_expire(_adapter *adapter);
  163. struct rtw_mesh_path *
  164. rtw_mesh_path_add(_adapter *adapter, const u8 *dst);
  165. int rtw_mesh_path_add_gate(struct rtw_mesh_path *mpath);
  166. void rtw_mesh_gate_del(struct rtw_mesh_table *tbl, struct rtw_mesh_path *mpath);
  167. bool rtw_mesh_gate_search(struct rtw_mesh_table *tbl, const u8 *addr);
  168. int rtw_mesh_path_send_to_gates(struct rtw_mesh_path *mpath);
  169. int rtw_mesh_gate_num(_adapter *adapter);
  170. bool rtw_mesh_is_primary_gate(_adapter *adapter);
  171. void dump_known_gates(void *sel, _adapter *adapter);
  172. void rtw_mesh_plink_broken(struct sta_info *sta);
  173. void rtw_mesh_path_assign_nexthop(struct rtw_mesh_path *mpath, struct sta_info *sta);
  174. void rtw_mesh_path_flush_pending(struct rtw_mesh_path *mpath);
  175. void rtw_mesh_path_tx_pending(struct rtw_mesh_path *mpath);
  176. int rtw_mesh_pathtbl_init(_adapter *adapter);
  177. void rtw_mesh_pathtbl_unregister(_adapter *adapter);
  178. int rtw_mesh_path_del(_adapter *adapter, const u8 *addr);
  179. void rtw_mesh_path_flush_by_nexthop(struct sta_info *sta);
  180. void rtw_mesh_path_discard_frame(_adapter *adapter,
  181. struct xmit_frame *xframe);
  182. static inline void rtw_mesh_path_activate(struct rtw_mesh_path *mpath)
  183. {
  184. mpath->flags |= RTW_MESH_PATH_ACTIVE | RTW_MESH_PATH_RESOLVED;
  185. }
  186. void rtw_mesh_path_flush_by_iface(_adapter *adapter);
  187. #endif /* __RTW_MESH_PATHTBL_H_ */