net:wireless:Support eswin usb wifi ECR6600U
[platform/kernel/linux-starfive.git] / drivers / net / wireless / eswin / ecrnx_mu_group.h
1 /**
2  ******************************************************************************
3  *
4  * @file ecrnx_mu_group.h
5  *
6  * Copyright (C) ESWIN 2015-2020
7  *
8  ******************************************************************************
9  */
10 #ifndef _ECRNX_MU_GROUP_H_
11 #define _ECRNX_MU_GROUP_H_
12
13 #include <linux/workqueue.h>
14 #include <linux/semaphore.h>
15
16 struct ecrnx_hw;
17 struct ecrnx_sta;
18
19 #ifdef CONFIG_ECRNX_MUMIMO_TX
20
21 /**
22  * struct ecrnx_sta_group_info - Group Information for a STA
23  *
24  * @active: node for @mu->active_sta list
25  * @update: node for @mu->update_sta list
26  * @cnt: Number of groups the STA belongs to
27  * @map: Bitfield of groups the sta belongs to
28  * @traffic: Number of buffers sent since previous group selection
29  * @group: Id of the group selected by previous group selection
30  *         (cf @ecrnx_mu_group_sta_select)
31  */
32 struct ecrnx_sta_group_info {
33     struct list_head active;
34     struct list_head update;
35     u16 last_update;
36     int cnt;
37     u64 map;
38     int traffic;
39     u8  group;
40 };
41
42 /**
43  * struct mu_group_info - Information about the users of a group
44  *
45  * @list: node for mu->active_groups
46  * @group_id: Group identifier
47  * @user_cnt: Number of the users in the group
48  * @users: Pointer to the sta, ordered by user position
49  */
50 struct ecrnx_mu_group {
51     struct list_head list;
52     int group_id;
53     int user_cnt;
54     struct ecrnx_sta *users[CONFIG_USER_MAX];
55 };
56
57 /**
58  * struct ecrnx_mu_info - Information about all MU group
59  *
60  * @active_groups: List of all possible groups. Ordered from the most recently
61  *                 used one to the least one (and possibly never used)
62  * @active_sta: List of MU beamformee sta that have been active (since previous
63  *              group update). Ordered from the most recently active.
64  * @update_sta: List of sta whose group information has changed and need to be
65  *              updated at fw level
66  * @groups: Table of all groups
67  * @group_work: Work item used to schedule group update
68  * @update_count: Counter used to identify the last group formation update.
69  *                (cf ecrnx_sta_group_info.last_update)
70  * @lock: Lock taken during group update. If tx happens lock is taken, then tx
71  *        will not used MU.
72  * @next_group_assign: Next time the group selection should be run
73  *                     (ref @ecrnx_mu_group_sta_select)
74  * @group_cnt: Number of group created
75  */
76 struct ecrnx_mu_info {
77     struct list_head active_groups;
78     struct list_head active_sta;
79     struct list_head update_sta;
80     struct ecrnx_mu_group groups[NX_MU_GROUP_MAX];
81     struct delayed_work group_work;
82     u16 update_count;
83     struct semaphore lock;
84     unsigned long next_group_select;
85     u8 group_cnt;
86 };
87
88 #define ECRNX_SU_GROUP BIT_ULL(0)
89 #define ECRNX_MU_GROUP_MASK 0x7ffffffffffffffeULL
90 #define ECRNX_MU_GROUP_INTERVAL 200 /* in ms */
91 #define ECRNX_MU_GROUP_SELECT_INTERVAL 100 /* in ms */
92 // minimum traffic in a ECRNX_MU_GROUP_SELECT_INTERVAL to consider the sta
93 #define ECRNX_MU_GROUP_MIN_TRAFFIC 50 /* in number of packet */
94
95
96 #define ECRNX_GET_FIRST_GROUP_ID(map) (fls64(map) - 1)
97
98 #define group_sta_for_each(sta, id, map)                                \
99     map = sta->group_info.map & ECRNX_MU_GROUP_MASK;                     \
100     for (id = (fls64(map) - 1) ; id > 0 ;                               \
101          map &= ~(u64)BIT_ULL(id), id = (fls64(map) - 1))
102
103 #define group_for_each(id, map)                                         \
104     for (id = (fls64(map) - 1) ; id > 0 ;                               \
105          map &= ~(u64)BIT_ULL(id), id = (fls64(map) - 1))
106
107 #define ECRNX_MUMIMO_INFO_POS_ID(info) (((info) >> 6) & 0x3)
108 #define ECRNX_MUMIMO_INFO_GROUP_ID(info) ((info) & 0x3f)
109
110 static inline
111 struct ecrnx_mu_group *ecrnx_mu_group_from_id(struct ecrnx_mu_info *mu, int id)
112 {
113     if (id > NX_MU_GROUP_MAX)
114         return NULL;
115
116     return &mu->groups[id - 1];
117 }
118
119
120 void ecrnx_mu_group_sta_init(struct ecrnx_sta *sta,
121                             const struct ieee80211_vht_cap *vht_cap);
122 void ecrnx_mu_group_sta_del(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta);
123 u64 ecrnx_mu_group_sta_get_map(struct ecrnx_sta *sta);
124 int ecrnx_mu_group_sta_get_pos(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta,
125                               int group_id);
126
127 void ecrnx_mu_group_init(struct ecrnx_hw *ecrnx_hw);
128
129 void ecrnx_mu_set_active_sta(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta,
130                             int traffic);
131 void ecrnx_mu_set_active_group(struct ecrnx_hw *ecrnx_hw, int group_id);
132 void ecrnx_mu_group_sta_select(struct ecrnx_hw *ecrnx_hw);
133
134
135 #else /* ! CONFIG_ECRNX_MUMIMO_TX */
136
137 static inline
138 void ecrnx_mu_group_sta_init(struct ecrnx_sta *sta,
139                             const struct ieee80211_vht_cap *vht_cap)
140 {}
141
142 static inline
143 void ecrnx_mu_group_sta_del(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta)
144 {}
145
146 static inline
147 u64 ecrnx_mu_group_sta_get_map(struct ecrnx_sta *sta)
148 {
149     return 0;
150 }
151
152 static inline
153 int ecrnx_mu_group_sta_get_pos(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta,
154                               int group_id)
155 {
156     return 0;
157 }
158
159 static inline
160 void ecrnx_mu_group_init(struct ecrnx_hw *ecrnx_hw)
161 {}
162
163 static inline
164 void ecrnx_mu_set_active_sta(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta,
165                             int traffic)
166 {}
167
168 static inline
169 void ecrnx_mu_set_active_group(struct ecrnx_hw *ecrnx_hw, int group_id)
170 {}
171
172 static inline
173 void ecrnx_mu_group_sta_select(struct ecrnx_hw *ecrnx_hw)
174 {}
175
176 #endif /* CONFIG_ECRNX_MUMIMO_TX */
177
178 #endif /* _ECRNX_MU_GROUP_H_ */
179