staging: rtl8192e: Remove MAC_FMT and MAC_ARG for %pM
[pandora-kernel.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 void TsSetupTimeOut(unsigned long data)
24 {
25 }
26
27 void TsInactTimeout(unsigned long data)
28 {
29 }
30
31 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         struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
41         u8 index = 0;
42         bool bPktInBuf = false;
43
44         spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
45         if (pRxTs->RxTimeoutIndicateSeq != 0xffff) {
46                 while (!list_empty(&pRxTs->RxPendingPktList)) {
47                         pReorderEntry = (struct rx_reorder_entry *)
48                                         list_entry(pRxTs->RxPendingPktList.prev,
49                                         struct rx_reorder_entry, List);
50                         if (index == 0)
51                                 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
52
53                         if (SN_LESS(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) ||
54                                 SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq)) {
55                                 list_del_init(&pReorderEntry->List);
56
57                                 if (SN_EQUAL(pReorderEntry->SeqNum,
58                                     pRxTs->RxIndicateSeq))
59                                         pRxTs->RxIndicateSeq =
60                                               (pRxTs->RxIndicateSeq + 1) % 4096;
61
62                                 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate"
63                                              " SeqNum: %d\n", __func__,
64                                              pReorderEntry->SeqNum);
65                                 stats_IndicateArray[index] =
66                                                          pReorderEntry->prxb;
67                                 index++;
68
69                                 list_add_tail(&pReorderEntry->List,
70                                               &ieee->RxReorder_Unused_List);
71                         } else {
72                                 bPktInBuf = true;
73                                 break;
74                         }
75                 }
76         }
77
78         if (index > 0) {
79                 pRxTs->RxTimeoutIndicateSeq = 0xffff;
80
81                 if (index > REORDER_WIN_SIZE) {
82                         RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket():"
83                                      " Rx Reorer struct buffer full!!\n");
84                         spin_unlock_irqrestore(&(ieee->reorder_spinlock),
85                                                flags);
86                         return;
87                 }
88                 rtllib_indicate_packets(ieee, stats_IndicateArray, index);
89                 bPktInBuf = false;
90         }
91
92         if (bPktInBuf && (pRxTs->RxTimeoutIndicateSeq == 0xffff)) {
93                 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
94                 mod_timer(&pRxTs->RxPktPendingTimer,  jiffies +
95                           MSECS(ieee->pHTInfo->RxReorderPendingTime));
96         }
97         spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
98 }
99
100 void TsAddBaProcess(unsigned long data)
101 {
102         struct tx_ts_record *pTxTs = (struct tx_ts_record *)data;
103         u8 num = pTxTs->num;
104         struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device,
105                                      TxTsRecord[num]);
106
107         TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
108         RTLLIB_DEBUG(RTLLIB_DL_BA, "TsAddBaProcess(): ADDBA Req is "
109                      "started!!\n");
110 }
111
112 void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
113 {
114         memset(pTsCommonInfo->Addr, 0, 6);
115         memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
116         memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM);
117         pTsCommonInfo->TClasProc = 0;
118         pTsCommonInfo->TClasNum = 0;
119 }
120
121 void ResetTxTsEntry(struct tx_ts_record *pTS)
122 {
123         ResetTsCommonInfo(&pTS->TsCommonInfo);
124         pTS->TxCurSeq = 0;
125         pTS->bAddBaReqInProgress = false;
126         pTS->bAddBaReqDelayed = false;
127         pTS->bUsingBa = false;
128         pTS->bDisable_AddBa = false;
129         ResetBaEntry(&pTS->TxAdmittedBARecord);
130         ResetBaEntry(&pTS->TxPendingBARecord);
131 }
132
133 void ResetRxTsEntry(struct rx_ts_record *pTS)
134 {
135         ResetTsCommonInfo(&pTS->TsCommonInfo);
136         pTS->RxIndicateSeq = 0xffff;
137         pTS->RxTimeoutIndicateSeq = 0xffff;
138         ResetBaEntry(&pTS->RxAdmittedBARecord);
139 }
140
141 void TSInitialize(struct rtllib_device *ieee)
142 {
143         struct tx_ts_record *pTxTS  = ieee->TxTsRecord;
144         struct rx_ts_record *pRxTS  = ieee->RxTsRecord;
145         struct rx_reorder_entry *pRxReorderEntry = ieee->RxReorderEntry;
146         u8                              count = 0;
147         RTLLIB_DEBUG(RTLLIB_DL_TS, "==========>%s()\n", __func__);
148         INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
149         INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
150         INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
151
152         for (count = 0; count < TOTAL_TS_NUM; count++) {
153                 pTxTS->num = count;
154                 _setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
155                             TsSetupTimeOut,
156                             (unsigned long) pTxTS);
157
158                 _setup_timer(&pTxTS->TsCommonInfo.InactTimer,
159                             TsInactTimeout,
160                             (unsigned long) pTxTS);
161
162                 _setup_timer(&pTxTS->TsAddBaTimer,
163                             TsAddBaProcess,
164                             (unsigned long) pTxTS);
165
166                 _setup_timer(&pTxTS->TxPendingBARecord.Timer,
167                             BaSetupTimeOut,
168                             (unsigned long) pTxTS);
169                 _setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
170                             TxBaInactTimeout,
171                             (unsigned long) pTxTS);
172
173                 ResetTxTsEntry(pTxTS);
174                 list_add_tail(&pTxTS->TsCommonInfo.List,
175                                 &ieee->Tx_TS_Unused_List);
176                 pTxTS++;
177         }
178
179         INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
180         INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
181         INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
182         for (count = 0; count < TOTAL_TS_NUM; count++) {
183                 pRxTS->num = count;
184                 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
185
186                 _setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
187                             TsSetupTimeOut,
188                             (unsigned long) pRxTS);
189
190                 _setup_timer(&pRxTS->TsCommonInfo.InactTimer,
191                             TsInactTimeout,
192                             (unsigned long) pRxTS);
193
194                 _setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
195                             RxBaInactTimeout,
196                             (unsigned long) pRxTS);
197
198                 _setup_timer(&pRxTS->RxPktPendingTimer,
199                             RxPktPendingTimeout,
200                             (unsigned long) pRxTS);
201
202                 ResetRxTsEntry(pRxTS);
203                 list_add_tail(&pRxTS->TsCommonInfo.List,
204                               &ieee->Rx_TS_Unused_List);
205                 pRxTS++;
206         }
207         INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
208         for (count = 0; count < REORDER_ENTRY_NUM; count++) {
209                 list_add_tail(&pRxReorderEntry->List,
210                               &ieee->RxReorder_Unused_List);
211                 if (count == (REORDER_ENTRY_NUM-1))
212                         break;
213                 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
214         }
215
216 }
217
218 void AdmitTS(struct rtllib_device *ieee, struct ts_common_info *pTsCommonInfo,
219              u32 InactTime)
220 {
221         del_timer_sync(&pTsCommonInfo->SetupTimer);
222         del_timer_sync(&pTsCommonInfo->InactTimer);
223
224         if (InactTime != 0)
225                 mod_timer(&pTsCommonInfo->InactTimer, jiffies +
226                           MSECS(InactTime));
227 }
228
229 struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee, u8 *Addr,
230                                            u8 TID, enum tr_select TxRxSelect)
231 {
232         u8      dir;
233         bool    search_dir[4] = {0, 0, 0, 0};
234         struct list_head *psearch_list;
235         struct ts_common_info *pRet = NULL;
236         if (ieee->iw_mode == IW_MODE_MASTER) {
237                 if (TxRxSelect == TX_DIR) {
238                         search_dir[DIR_DOWN] = true;
239                         search_dir[DIR_BI_DIR] = true;
240                 } else {
241                         search_dir[DIR_UP] = true;
242                         search_dir[DIR_BI_DIR] = true;
243                 }
244         } else if (ieee->iw_mode == IW_MODE_ADHOC) {
245                 if (TxRxSelect == TX_DIR)
246                         search_dir[DIR_UP] = true;
247                 else
248                         search_dir[DIR_DOWN] = true;
249         } else {
250                 if (TxRxSelect == TX_DIR) {
251                         search_dir[DIR_UP] = true;
252                         search_dir[DIR_BI_DIR] = true;
253                         search_dir[DIR_DIRECT] = true;
254                 } else {
255                         search_dir[DIR_DOWN] = true;
256                         search_dir[DIR_BI_DIR] = true;
257                         search_dir[DIR_DIRECT] = true;
258                 }
259         }
260
261         if (TxRxSelect == TX_DIR)
262                 psearch_list = &ieee->Tx_TS_Admit_List;
263         else
264                 psearch_list = &ieee->Rx_TS_Admit_List;
265
266         for (dir = 0; dir <= DIR_BI_DIR; dir++) {
267                 if (search_dir[dir] == false)
268                         continue;
269                 list_for_each_entry(pRet, psearch_list, List) {
270                         if (memcmp(pRet->Addr, Addr, 6) == 0)
271                                 if (pRet->TSpec.f.TSInfo.field.ucTSID == TID)
272                                         if (pRet->TSpec.f.TSInfo.field.ucDirection == dir)
273                                                 break;
274
275                 }
276                 if (&pRet->List  != psearch_list)
277                         break;
278         }
279
280         if (&pRet->List  != psearch_list)
281                 return pRet ;
282         else
283                 return NULL;
284 }
285
286 void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
287                  union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
288                  u8 TCLAS_Num, u8 TCLAS_Proc)
289 {
290         u8      count;
291
292         if (pTsCommonInfo == NULL)
293                 return;
294
295         memcpy(pTsCommonInfo->Addr, Addr, 6);
296
297         if (pTSPEC != NULL)
298                 memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
299                         sizeof(union tspec_body));
300
301         for (count = 0; count < TCLAS_Num; count++)
302                 memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
303                        (u8 *)pTCLAS, sizeof(union qos_tclas));
304
305         pTsCommonInfo->TClasProc = TCLAS_Proc;
306         pTsCommonInfo->TClasNum = TCLAS_Num;
307 }
308
309 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
310            u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
311 {
312         u8      UP = 0;
313         if (is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr)) {
314                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! get TS for Broadcast or "
315                              "Multicast\n");
316                 return false;
317         }
318         if (ieee->current_network.qos_data.supported == 0) {
319                 UP = 0;
320         } else {
321                 if (!IsACValid(TID)) {
322                         RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! in %s(), TID(%d) is "
323                                      "not valid\n", __func__, TID);
324                         return false;
325                 }
326
327                 switch (TID) {
328                 case 0:
329                 case 3:
330                         UP = 0;
331                         break;
332                 case 1:
333                 case 2:
334                         UP = 2;
335                         break;
336                 case 4:
337                 case 5:
338                         UP = 5;
339                         break;
340                 case 6:
341                 case 7:
342                         UP = 7;
343                         break;
344                 }
345         }
346
347         *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
348         if (*ppTS != NULL) {
349                 return true;
350         } else {
351                 if (bAddNewTs == false) {
352                         RTLLIB_DEBUG(RTLLIB_DL_TS, "add new TS failed"
353                                      "(tid:%d)\n", UP);
354                         return false;
355                 } else {
356                         union tspec_body TSpec;
357                         union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
358                         struct list_head *pUnusedList =
359                                 (TxRxSelect == TX_DIR) ?
360                                 (&ieee->Tx_TS_Unused_List) :
361                                 (&ieee->Rx_TS_Unused_List);
362
363                         struct list_head *pAddmitList =
364                                 (TxRxSelect == TX_DIR) ?
365                                 (&ieee->Tx_TS_Admit_List) :
366                                 (&ieee->Rx_TS_Admit_List);
367
368                         enum direction_value Dir =
369                                  (ieee->iw_mode == IW_MODE_MASTER) ?
370                                  ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
371                                  ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
372                         RTLLIB_DEBUG(RTLLIB_DL_TS, "to add Ts\n");
373                         if (!list_empty(pUnusedList)) {
374                                 (*ppTS) = list_entry(pUnusedList->next,
375                                           struct ts_common_info, List);
376                                 list_del_init(&(*ppTS)->List);
377                                 if (TxRxSelect == TX_DIR) {
378                                         struct tx_ts_record *tmp =
379                                                 container_of(*ppTS,
380                                                 struct tx_ts_record,
381                                                 TsCommonInfo);
382                                         ResetTxTsEntry(tmp);
383                                 } else {
384                                         struct rx_ts_record *tmp =
385                                                  container_of(*ppTS,
386                                                  struct rx_ts_record,
387                                                  TsCommonInfo);
388                                         ResetRxTsEntry(tmp);
389                                 }
390
391                                 RTLLIB_DEBUG(RTLLIB_DL_TS, "to init current TS"
392                                              ", UP:%d, Dir:%d, addr: %pM"
393                                              " ppTs=%p\n", UP, Dir,
394                                               Addr, *ppTS);
395                                 pTSInfo->field.ucTrafficType = 0;
396                                 pTSInfo->field.ucTSID = UP;
397                                 pTSInfo->field.ucDirection = Dir;
398                                 pTSInfo->field.ucAccessPolicy = 1;
399                                 pTSInfo->field.ucAggregation = 0;
400                                 pTSInfo->field.ucPSB = 0;
401                                 pTSInfo->field.ucUP = UP;
402                                 pTSInfo->field.ucTSInfoAckPolicy = 0;
403                                 pTSInfo->field.ucSchedule = 0;
404
405                                 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
406                                 AdmitTS(ieee, *ppTS, 0);
407                                 list_add_tail(&((*ppTS)->List), pAddmitList);
408
409                                 return true;
410                         } else {
411                                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!in function "
412                                              "%s() There is not enough dir=%d"
413                                              "(0=up down=1) TS record to be "
414                                              "used!!", __func__, Dir);
415                                 return false;
416                         }
417                 }
418         }
419 }
420
421 void RemoveTsEntry(struct rtllib_device *ieee, struct ts_common_info *pTs,
422                    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                         RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Delete SeqNum "
440                                      "%d!\n", __func__,
441                                      pRxReorderEntry->SeqNum);
442                         list_del_init(&pRxReorderEntry->List);
443                         {
444                                 int i = 0;
445                                 struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
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                 del_timer_sync(&pTxTS->TsAddBaTimer);
459         }
460 }
461
462 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
463 {
464         struct ts_common_info *pTS, *pTmpTS;
465         printk(KERN_INFO "===========>RemovePeerTS, %pM\n", Addr);
466
467         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
468                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
469                         RemoveTsEntry(ieee, pTS, TX_DIR);
470                         list_del_init(&pTS->List);
471                         list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
472                 }
473         }
474
475         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
476                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
477                         printk(KERN_INFO "====>remove Tx_TS_admin_list\n");
478                         RemoveTsEntry(ieee, pTS, TX_DIR);
479                         list_del_init(&pTS->List);
480                         list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
481                 }
482         }
483
484         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
485                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
486                         RemoveTsEntry(ieee, pTS, RX_DIR);
487                         list_del_init(&pTS->List);
488                         list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
489                 }
490         }
491
492         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
493                 if (memcmp(pTS->Addr, Addr, 6) == 0) {
494                         RemoveTsEntry(ieee, pTS, RX_DIR);
495                         list_del_init(&pTS->List);
496                         list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
497                 }
498         }
499 }
500
501 void RemoveAllTS(struct rtllib_device *ieee)
502 {
503         struct ts_common_info *pTS, *pTmpTS;
504
505         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
506                 RemoveTsEntry(ieee, pTS, TX_DIR);
507                 list_del_init(&pTS->List);
508                 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
509         }
510
511         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
512                 RemoveTsEntry(ieee, pTS, TX_DIR);
513                 list_del_init(&pTS->List);
514                 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
515         }
516
517         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
518                 RemoveTsEntry(ieee, pTS, RX_DIR);
519                 list_del_init(&pTS->List);
520                 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
521         }
522
523         list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
524                 RemoveTsEntry(ieee, pTS, RX_DIR);
525                 list_del_init(&pTS->List);
526                 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
527         }
528 }
529
530 void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
531 {
532         if (pTxTS->bAddBaReqInProgress == false) {
533                 pTxTS->bAddBaReqInProgress = true;
534
535                 if (pTxTS->bAddBaReqDelayed) {
536                         RTLLIB_DEBUG(RTLLIB_DL_BA, "TsStartAddBaProcess(): "
537                                      "Delayed Start ADDBA after 60 sec!!\n");
538                         mod_timer(&pTxTS->TsAddBaTimer, jiffies +
539                                   MSECS(TS_ADDBA_DELAY));
540                 } else {
541                         RTLLIB_DEBUG(RTLLIB_DL_BA, "TsStartAddBaProcess(): "
542                                      "Immediately Start ADDBA now!!\n");
543                         mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
544                 }
545         } else
546                 RTLLIB_DEBUG(RTLLIB_DL_BA, "%s()==>BA timer is already added\n",
547                              __func__);
548 }