]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/rtl8192e/rtl819x_TSProc.c
Merge remote-tracking branch 'usb-chipidea-next/ci-for-usb-next'
[karo-tx-linux.git] / drivers / staging / rtl8192e / rtl819x_TSProc.c
1 /******************************************************************************
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * This program is distributed in the hope that it will be useful, but WITHOUT
5  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
7  * more details.
8  *
9  * You should have received a copy of the GNU General Public License along with
10  * this program; if not, write to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
12  *
13  * The full GNU General Public License is included in this distribution in the
14  * file called LICENSE.
15  *
16  * Contact Information:
17  * wlanfae <wlanfae@realtek.com>
18 ******************************************************************************/
19 #include "rtllib.h"
20 #include <linux/etherdevice.h>
21 #include "rtl819x_TS.h"
22
23 static void TsSetupTimeOut(unsigned long data)
24 {
25 }
26
27 static void TsInactTimeout(unsigned long data)
28 {
29 }
30
31 static void RxPktPendingTimeout(unsigned long data)
32 {
33         struct rx_ts_record *pRxTs = (struct rx_ts_record *)data;
34         struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device,
35                                                   RxTsRecord[pRxTs->num]);
36
37         struct rx_reorder_entry *pReorderEntry = NULL;
38
39         unsigned long flags = 0;
40         u8 index = 0;
41         bool bPktInBuf = false;
42
43         spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
44         if (pRxTs->RxTimeoutIndicateSeq != 0xffff) {
45                 while (!list_empty(&pRxTs->RxPendingPktList)) {
46                         pReorderEntry = (struct rx_reorder_entry *)
47                                         list_entry(pRxTs->RxPendingPktList.prev,
48                                         struct rx_reorder_entry, List);
49                         if (index == 0)
50                                 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
51
52                         if (SN_LESS(pReorderEntry->SeqNum,
53                                     pRxTs->RxIndicateSeq) ||
54                             SN_EQUAL(pReorderEntry->SeqNum,
55                                      pRxTs->RxIndicateSeq)) {
56                                 list_del_init(&pReorderEntry->List);
57
58                                 if (SN_EQUAL(pReorderEntry->SeqNum,
59                                     pRxTs->RxIndicateSeq))
60                                         pRxTs->RxIndicateSeq =
61                                               (pRxTs->RxIndicateSeq + 1) % 4096;
62
63                                 netdev_dbg(ieee->dev,
64                                            "%s(): Indicate SeqNum: %d\n",
65                                            __func__, pReorderEntry->SeqNum);
66                                 ieee->stats_IndicateArray[index] =
67                                                          pReorderEntry->prxb;
68                                 index++;
69
70                                 list_add_tail(&pReorderEntry->List,
71                                               &ieee->RxReorder_Unused_List);
72                         } else {
73                                 bPktInBuf = true;
74                                 break;
75                         }
76                 }
77         }
78
79         if (index > 0) {
80                 pRxTs->RxTimeoutIndicateSeq = 0xffff;
81
82                 if (index > REORDER_WIN_SIZE) {
83                         netdev_warn(ieee->dev,
84                                     "%s(): Rx Reorder struct buffer full\n",
85                                     __func__);
86                         spin_unlock_irqrestore(&(ieee->reorder_spinlock),
87                                                flags);
88                         return;
89                 }
90                 rtllib_indicate_packets(ieee, ieee->stats_IndicateArray, index);
91                 bPktInBuf = false;
92         }
93
94         if (bPktInBuf && (pRxTs->RxTimeoutIndicateSeq == 0xffff)) {
95                 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
96                 mod_timer(&pRxTs->RxPktPendingTimer,  jiffies +
97                           msecs_to_jiffies(ieee->pHTInfo->RxReorderPendingTime)
98                           );
99         }
100         spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
101 }
102
103 static void TsAddBaProcess(unsigned long data)
104 {
105         struct tx_ts_record *pTxTs = (struct tx_ts_record *)data;
106         u8 num = pTxTs->num;
107         struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device,
108                                      TxTsRecord[num]);
109
110         TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
111         netdev_dbg(ieee->dev, "%s(): ADDBA Req is started\n", __func__);
112 }
113
114 static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
115 {
116         eth_zero_addr(pTsCommonInfo->Addr);
117         memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
118         memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM);
119         pTsCommonInfo->TClasProc = 0;
120         pTsCommonInfo->TClasNum = 0;
121 }
122
123 static void ResetTxTsEntry(struct tx_ts_record *pTS)
124 {
125         ResetTsCommonInfo(&pTS->TsCommonInfo);
126         pTS->TxCurSeq = 0;
127         pTS->bAddBaReqInProgress = false;
128         pTS->bAddBaReqDelayed = false;
129         pTS->bUsingBa = false;
130         pTS->bDisable_AddBa = false;
131         ResetBaEntry(&pTS->TxAdmittedBARecord);
132         ResetBaEntry(&pTS->TxPendingBARecord);
133 }
134
135 static void ResetRxTsEntry(struct rx_ts_record *pTS)
136 {
137         ResetTsCommonInfo(&pTS->TsCommonInfo);
138         pTS->RxIndicateSeq = 0xffff;
139         pTS->RxTimeoutIndicateSeq = 0xffff;
140         ResetBaEntry(&pTS->RxAdmittedBARecord);
141 }
142
143 void TSInitialize(struct rtllib_device *ieee)
144 {
145         struct tx_ts_record *pTxTS  = ieee->TxTsRecord;
146         struct rx_ts_record *pRxTS  = ieee->RxTsRecord;
147         struct rx_reorder_entry *pRxReorderEntry = ieee->RxReorderEntry;
148         u8                              count = 0;
149
150         netdev_vdbg(ieee->dev, "%s()\n", __func__);
151         INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
152         INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
153         INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
154
155         for (count = 0; count < TOTAL_TS_NUM; count++) {
156                 pTxTS->num = count;
157                 setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
158                             TsSetupTimeOut,
159                             (unsigned long) pTxTS);
160
161                 setup_timer(&pTxTS->TsCommonInfo.InactTimer,
162                             TsInactTimeout,
163                             (unsigned long) pTxTS);
164
165                 setup_timer(&pTxTS->TsAddBaTimer,
166                             TsAddBaProcess,
167                             (unsigned long) pTxTS);
168
169                 setup_timer(&pTxTS->TxPendingBARecord.Timer,
170                             BaSetupTimeOut,
171                             (unsigned long) pTxTS);
172                 setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
173                             TxBaInactTimeout,
174                             (unsigned long) pTxTS);
175
176                 ResetTxTsEntry(pTxTS);
177                 list_add_tail(&pTxTS->TsCommonInfo.List,
178                                 &ieee->Tx_TS_Unused_List);
179                 pTxTS++;
180         }
181
182         INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
183         INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
184         INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
185         for (count = 0; count < TOTAL_TS_NUM; count++) {
186                 pRxTS->num = count;
187                 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
188
189                 setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
190                             TsSetupTimeOut,
191                             (unsigned long) pRxTS);
192
193                 setup_timer(&pRxTS->TsCommonInfo.InactTimer,
194                             TsInactTimeout,
195                             (unsigned long) pRxTS);
196
197                 setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
198                             RxBaInactTimeout,
199                             (unsigned long) pRxTS);
200
201                 setup_timer(&pRxTS->RxPktPendingTimer,
202                             RxPktPendingTimeout,
203                             (unsigned long) pRxTS);
204
205                 ResetRxTsEntry(pRxTS);
206                 list_add_tail(&pRxTS->TsCommonInfo.List,
207                               &ieee->Rx_TS_Unused_List);
208                 pRxTS++;
209         }
210         INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
211         for (count = 0; count < REORDER_ENTRY_NUM; count++) {
212                 list_add_tail(&pRxReorderEntry->List,
213                               &ieee->RxReorder_Unused_List);
214                 if (count == (REORDER_ENTRY_NUM-1))
215                         break;
216                 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
217         }
218
219 }
220
221 static void AdmitTS(struct rtllib_device *ieee,
222                     struct ts_common_info *pTsCommonInfo, u32 InactTime)
223 {
224         del_timer_sync(&pTsCommonInfo->SetupTimer);
225         del_timer_sync(&pTsCommonInfo->InactTimer);
226
227         if (InactTime != 0)
228                 mod_timer(&pTsCommonInfo->InactTimer, jiffies +
229                           msecs_to_jiffies(InactTime));
230 }
231
232 static struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee,
233                                                   u8 *Addr, u8 TID,
234                                                   enum tr_select TxRxSelect)
235 {
236         u8      dir;
237         bool    search_dir[4] = {0};
238         struct list_head *psearch_list;
239         struct ts_common_info *pRet = NULL;
240
241         if (ieee->iw_mode == IW_MODE_MASTER) {
242                 if (TxRxSelect == TX_DIR) {
243                         search_dir[DIR_DOWN] = true;
244                         search_dir[DIR_BI_DIR] = true;
245                 } else {
246                         search_dir[DIR_UP] = true;
247                         search_dir[DIR_BI_DIR] = true;
248                 }
249         } else if (ieee->iw_mode == IW_MODE_ADHOC) {
250                 if (TxRxSelect == TX_DIR)
251                         search_dir[DIR_UP] = true;
252                 else
253                         search_dir[DIR_DOWN] = true;
254         } else {
255                 if (TxRxSelect == TX_DIR) {
256                         search_dir[DIR_UP] = true;
257                         search_dir[DIR_BI_DIR] = true;
258                         search_dir[DIR_DIRECT] = true;
259                 } else {
260                         search_dir[DIR_DOWN] = true;
261                         search_dir[DIR_BI_DIR] = true;
262                         search_dir[DIR_DIRECT] = true;
263                 }
264         }
265
266         if (TxRxSelect == TX_DIR)
267                 psearch_list = &ieee->Tx_TS_Admit_List;
268         else
269                 psearch_list = &ieee->Rx_TS_Admit_List;
270
271         for (dir = 0; dir <= DIR_BI_DIR; dir++) {
272                 if (!search_dir[dir])
273                         continue;
274                 list_for_each_entry(pRet, psearch_list, List) {
275                         if (memcmp(pRet->Addr, Addr, 6) == 0 &&
276                             pRet->TSpec.f.TSInfo.field.ucTSID == TID &&
277                             pRet->TSpec.f.TSInfo.field.ucDirection == dir)
278                                 break;
279
280                 }
281                 if (&pRet->List  != psearch_list)
282                         break;
283         }
284
285         if (pRet && &pRet->List  != psearch_list)
286                 return pRet;
287         return NULL;
288 }
289
290 static void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
291                         union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
292                         u8 TCLAS_Num, u8 TCLAS_Proc)
293 {
294         u8      count;
295
296         if (pTsCommonInfo == NULL)
297                 return;
298
299         memcpy(pTsCommonInfo->Addr, Addr, 6);
300
301         if (pTSPEC != NULL)
302                 memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
303                         sizeof(union tspec_body));
304
305         for (count = 0; count < TCLAS_Num; count++)
306                 memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
307                        (u8 *)pTCLAS, sizeof(union qos_tclas));
308
309         pTsCommonInfo->TClasProc = TCLAS_Proc;
310         pTsCommonInfo->TClasNum = TCLAS_Num;
311 }
312
313 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
314            u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
315 {
316         u8      UP = 0;
317         union tspec_body TSpec;
318         union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
319         struct list_head *pUnusedList;
320         struct list_head *pAddmitList;
321         enum direction_value Dir;
322
323         if (is_multicast_ether_addr(Addr)) {
324                 netdev_warn(ieee->dev, "Get TS for Broadcast or Multicast\n");
325                 return false;
326         }
327         if (ieee->current_network.qos_data.supported == 0) {
328                 UP = 0;
329         } else {
330                 if (!IsACValid(TID)) {
331                         netdev_warn(ieee->dev, "%s(): TID(%d) is not valid\n",
332                                     __func__, TID);
333                         return false;
334                 }
335
336                 switch (TID) {
337                 case 0:
338                 case 3:
339                         UP = 0;
340                         break;
341                 case 1:
342                 case 2:
343                         UP = 2;
344                         break;
345                 case 4:
346                 case 5:
347                         UP = 5;
348                         break;
349                 case 6:
350                 case 7:
351                         UP = 7;
352                         break;
353                 }
354         }
355
356         *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
357         if (*ppTS != NULL)
358                 return true;
359
360         if (!bAddNewTs) {
361                 netdev_dbg(ieee->dev, "add new TS failed(tid:%d)\n", UP);
362                 return false;
363         }
364
365         pUnusedList = (TxRxSelect == TX_DIR) ?
366                                 (&ieee->Tx_TS_Unused_List) :
367                                 (&ieee->Rx_TS_Unused_List);
368
369         pAddmitList = (TxRxSelect == TX_DIR) ?
370                                 (&ieee->Tx_TS_Admit_List) :
371                                 (&ieee->Rx_TS_Admit_List);
372
373         Dir = (ieee->iw_mode == IW_MODE_MASTER) ?
374                                 ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
375                                 ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
376
377         if (!list_empty(pUnusedList)) {
378                 (*ppTS) = list_entry(pUnusedList->next,
379                           struct ts_common_info, List);
380                 list_del_init(&(*ppTS)->List);
381                 if (TxRxSelect == TX_DIR) {
382                         struct tx_ts_record *tmp =
383                                 container_of(*ppTS,
384                                 struct tx_ts_record,
385                                 TsCommonInfo);
386                         ResetTxTsEntry(tmp);
387                 } else {
388                         struct rx_ts_record *tmp =
389                                  container_of(*ppTS,
390                                  struct rx_ts_record,
391                                  TsCommonInfo);
392                         ResetRxTsEntry(tmp);
393                 }
394
395                 netdev_dbg(ieee->dev,
396                            "to init current TS, UP:%d, Dir:%d, addr: %pM ppTs=%p\n",
397                            UP, Dir, Addr, *ppTS);
398                 pTSInfo->field.ucTrafficType = 0;
399                 pTSInfo->field.ucTSID = UP;
400                 pTSInfo->field.ucDirection = Dir;
401                 pTSInfo->field.ucAccessPolicy = 1;
402                 pTSInfo->field.ucAggregation = 0;
403                 pTSInfo->field.ucPSB = 0;
404                 pTSInfo->field.ucUP = UP;
405                 pTSInfo->field.ucTSInfoAckPolicy = 0;
406                 pTSInfo->field.ucSchedule = 0;
407
408                 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
409                 AdmitTS(ieee, *ppTS, 0);
410                 list_add_tail(&((*ppTS)->List), pAddmitList);
411
412                 return true;
413         }
414
415         netdev_warn(ieee->dev,
416                     "There is not enough dir=%d(0=up down=1) TS record to be used!",
417                     Dir);
418         return false;
419 }
420
421 static void RemoveTsEntry(struct rtllib_device *ieee,
422                           struct ts_common_info *pTs, enum tr_select TxRxSelect)
423 {
424         del_timer_sync(&pTs->SetupTimer);
425         del_timer_sync(&pTs->InactTimer);
426         TsInitDelBA(ieee, pTs, TxRxSelect);
427
428         if (TxRxSelect == RX_DIR) {
429                 struct rx_reorder_entry *pRxReorderEntry;
430                 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
431
432                 if (timer_pending(&pRxTS->RxPktPendingTimer))
433                         del_timer_sync(&pRxTS->RxPktPendingTimer);
434
435                 while (!list_empty(&pRxTS->RxPendingPktList)) {
436                         pRxReorderEntry = (struct rx_reorder_entry *)
437                                         list_entry(pRxTS->RxPendingPktList.prev,
438                                         struct rx_reorder_entry, List);
439                         netdev_dbg(ieee->dev,  "%s(): Delete SeqNum %d!\n",
440                                    __func__, pRxReorderEntry->SeqNum);
441                         list_del_init(&pRxReorderEntry->List);
442                         {
443                                 int i = 0;
444                                 struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
445
446                                 if (unlikely(!prxb))
447                                         return;
448                                 for (i = 0; i < prxb->nr_subframes; i++)
449                                         dev_kfree_skb(prxb->subframes[i]);
450                                 kfree(prxb);
451                                 prxb = NULL;
452                         }
453                         list_add_tail(&pRxReorderEntry->List,
454                                       &ieee->RxReorder_Unused_List);
455                 }
456         } else {
457                 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
458
459                 del_timer_sync(&pTxTS->TsAddBaTimer);
460         }
461 }
462
463 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
464 {
465         struct ts_common_info *pTS, *pTmpTS;
466
467         netdev_info(ieee->dev, "===========>RemovePeerTS, %pM\n", Addr);
468
469         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
470                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
471                         RemoveTsEntry(ieee, pTS, TX_DIR);
472                         list_del_init(&pTS->List);
473                         list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
474                 }
475         }
476
477         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
478                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
479                         netdev_info(ieee->dev,
480                                     "====>remove Tx_TS_admin_list\n");
481                         RemoveTsEntry(ieee, pTS, TX_DIR);
482                         list_del_init(&pTS->List);
483                         list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
484                 }
485         }
486
487         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
488                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
489                         RemoveTsEntry(ieee, pTS, RX_DIR);
490                         list_del_init(&pTS->List);
491                         list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
492                 }
493         }
494
495         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
496                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
497                         RemoveTsEntry(ieee, pTS, RX_DIR);
498                         list_del_init(&pTS->List);
499                         list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
500                 }
501         }
502 }
503 EXPORT_SYMBOL(RemovePeerTS);
504
505 void RemoveAllTS(struct rtllib_device *ieee)
506 {
507         struct ts_common_info *pTS, *pTmpTS;
508
509         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
510                 RemoveTsEntry(ieee, pTS, TX_DIR);
511                 list_del_init(&pTS->List);
512                 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
513         }
514
515         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
516                 RemoveTsEntry(ieee, pTS, TX_DIR);
517                 list_del_init(&pTS->List);
518                 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
519         }
520
521         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
522                 RemoveTsEntry(ieee, pTS, RX_DIR);
523                 list_del_init(&pTS->List);
524                 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
525         }
526
527         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
528                 RemoveTsEntry(ieee, pTS, RX_DIR);
529                 list_del_init(&pTS->List);
530                 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
531         }
532 }
533
534 void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
535 {
536         if (pTxTS->bAddBaReqInProgress == false) {
537                 pTxTS->bAddBaReqInProgress = true;
538
539                 if (pTxTS->bAddBaReqDelayed) {
540                         netdev_dbg(ieee->dev, "Start ADDBA after 60 sec!!\n");
541                         mod_timer(&pTxTS->TsAddBaTimer, jiffies +
542                                   msecs_to_jiffies(TS_ADDBA_DELAY));
543                 } else {
544                         netdev_dbg(ieee->dev, "Immediately Start ADDBA\n");
545                         mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
546                 }
547         } else
548                 netdev_dbg(ieee->dev, "BA timer is already added\n");
549 }