]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/rt2870/common/rtusb_io.c
Staging: rt2870sta: constify RTUSBMultiWrite(), RTUSBFirmwareWrite()
[net-next-2.6.git] / drivers / staging / rt2870 / common / rtusb_io.c
CommitLineData
c55519ff
GKH
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtusb_io.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Paul Lin 06-25-2004 created
37*/
38
ca97b838
BZ
39#ifdef RTMP_MAC_USB
40
c55519ff
GKH
41#include "../rt_config.h"
42
c55519ff
GKH
43/*
44 ========================================================================
45
46 Routine Description: NIC initialization complete
47
48 Arguments:
49
50 Return Value:
51
52 IRQL =
53
54 Note:
55
56 ========================================================================
57*/
58
62eb734b 59static int RTUSBFirmwareRun(struct rt_rtmp_adapter *pAd)
c55519ff 60{
51126deb 61 int Status;
66cd8d6e
BZ
62
63 Status = RTUSB_VendorRequest(pAd,
64 USBD_TRANSFER_DIRECTION_OUT,
65 DEVICE_VENDOR_REQUEST_OUT,
66 0x01, 0x8, 0, NULL, 0);
c55519ff
GKH
67
68 return Status;
69}
70
c55519ff
GKH
71/*
72 ========================================================================
73
74 Routine Description: Write Firmware to NIC.
75
76 Arguments:
77
78 Return Value:
79
80 IRQL =
81
82 Note:
83
84 ========================================================================
85*/
62eb734b 86int RTUSBFirmwareWrite(struct rt_rtmp_adapter *pAd,
8838d256 87 const u8 *pFwImage, unsigned long FwLen)
c55519ff 88{
51126deb
BZ
89 u32 MacReg;
90 int Status;
91/* unsigned long i; */
92 u16 writeLen;
c55519ff
GKH
93
94 Status = RTUSBReadMACRegister(pAd, MAC_CSR0, &MacReg);
95
c55519ff
GKH
96 writeLen = FwLen;
97 RTUSBMultiWrite(pAd, FIRMWARE_IMAGE_BASE, pFwImage, writeLen);
98
99 Status = RTUSBWriteMACRegister(pAd, 0x7014, 0xffffffff);
100 Status = RTUSBWriteMACRegister(pAd, 0x701c, 0xffffffff);
101 Status = RTUSBFirmwareRun(pAd);
102
9f548a2a 103 /*2008/11/28:KH add to fix the dead rf frequency offset bug<-- */
ffbc7b85 104 RTMPusecDelay(10000);
66cd8d6e 105 RTUSBWriteMACRegister(pAd, H2M_MAILBOX_CSR, 0);
9f548a2a
BZ
106 AsicSendCommandToMcu(pAd, 0x72, 0x00, 0x00, 0x00); /*reset rf by MCU supported by new firmware */
107 /*2008/11/28:KH add to fix the dead rf frequency offset bug--> */
ffbc7b85 108
c55519ff
GKH
109 return Status;
110}
111
62eb734b 112int RTUSBVenderReset(struct rt_rtmp_adapter *pAd)
c55519ff 113{
51126deb 114 int Status;
c55519ff 115 DBGPRINT_RAW(RT_DEBUG_ERROR, ("-->RTUSBVenderReset\n"));
66cd8d6e
BZ
116 Status = RTUSB_VendorRequest(pAd,
117 USBD_TRANSFER_DIRECTION_OUT,
118 DEVICE_VENDOR_REQUEST_OUT,
119 0x01, 0x1, 0, NULL, 0);
c55519ff
GKH
120
121 DBGPRINT_RAW(RT_DEBUG_ERROR, ("<--RTUSBVenderReset\n"));
122 return Status;
123}
66cd8d6e 124
c55519ff
GKH
125/*
126 ========================================================================
127
128 Routine Description: Read various length data from RT2573
129
130 Arguments:
131
132 Return Value:
133
134 IRQL =
135
136 Note:
137
138 ========================================================================
139*/
62eb734b 140int RTUSBMultiRead(struct rt_rtmp_adapter *pAd,
51126deb 141 u16 Offset, u8 *pData, u16 length)
c55519ff 142{
51126deb 143 int Status;
66cd8d6e
BZ
144
145 Status = RTUSB_VendorRequest(pAd,
146 (USBD_TRANSFER_DIRECTION_IN |
147 USBD_SHORT_TRANSFER_OK),
148 DEVICE_VENDOR_REQUEST_IN, 0x7, 0, Offset,
149 pData, length);
c55519ff
GKH
150
151 return Status;
152}
153
154/*
155 ========================================================================
156
157 Routine Description: Write various length data to RT2573
158
159 Arguments:
160
161 Return Value:
162
163 IRQL =
164
165 Note:
166
167 ========================================================================
168*/
62eb734b 169int RTUSBMultiWrite_OneByte(struct rt_rtmp_adapter *pAd,
8838d256 170 u16 Offset, const u8 *pData)
c55519ff 171{
51126deb 172 int Status;
c55519ff 173
9f548a2a 174 /* TODO: In 2870, use this funciton carefully cause it's not stable. */
66cd8d6e
BZ
175 Status = RTUSB_VendorRequest(pAd,
176 USBD_TRANSFER_DIRECTION_OUT,
177 DEVICE_VENDOR_REQUEST_OUT,
8838d256 178 0x6, 0, Offset, (u8 *)pData, 1);
c55519ff
GKH
179
180 return Status;
181}
182
62eb734b 183int RTUSBMultiWrite(struct rt_rtmp_adapter *pAd,
8838d256 184 u16 Offset, const u8 *pData, u16 length)
c55519ff 185{
51126deb 186 int Status;
66cd8d6e 187
51126deb 188 u16 index = 0, Value;
8838d256 189 const u8 *pSrc = pData;
51126deb 190 u16 resude = 0;
66cd8d6e
BZ
191
192 resude = length % 2;
193 length += resude;
194 do {
51126deb 195 Value = (u16)(*pSrc | (*(pSrc + 1) << 8));
66cd8d6e
BZ
196 Status = RTUSBSingleWrite(pAd, Offset + index, Value);
197 index += 2;
198 length -= 2;
199 pSrc = pSrc + 2;
200 } while (length > 0);
c55519ff
GKH
201
202 return Status;
203}
204
62eb734b 205int RTUSBSingleWrite(struct rt_rtmp_adapter *pAd,
51126deb 206 u16 Offset, u16 Value)
c55519ff 207{
51126deb 208 int Status;
66cd8d6e
BZ
209
210 Status = RTUSB_VendorRequest(pAd,
211 USBD_TRANSFER_DIRECTION_OUT,
212 DEVICE_VENDOR_REQUEST_OUT,
213 0x2, Value, Offset, NULL, 0);
c55519ff
GKH
214
215 return Status;
216
217}
218
c55519ff
GKH
219/*
220 ========================================================================
221
222 Routine Description: Read 32-bit MAC register
223
224 Arguments:
225
226 Return Value:
227
228 IRQL =
229
230 Note:
231
232 ========================================================================
233*/
62eb734b 234int RTUSBReadMACRegister(struct rt_rtmp_adapter *pAd,
51126deb 235 u16 Offset, u32 *pValue)
c55519ff 236{
51126deb
BZ
237 int Status = 0;
238 u32 localVal;
c55519ff 239
66cd8d6e
BZ
240 Status = RTUSB_VendorRequest(pAd,
241 (USBD_TRANSFER_DIRECTION_IN |
242 USBD_SHORT_TRANSFER_OK),
243 DEVICE_VENDOR_REQUEST_IN, 0x7, 0, Offset,
244 &localVal, 4);
c55519ff 245
66cd8d6e 246 *pValue = le2cpu32(localVal);
c55519ff
GKH
247
248 if (Status < 0)
249 *pValue = 0xffffffff;
250
251 return Status;
252}
253
c55519ff
GKH
254/*
255 ========================================================================
256
257 Routine Description: Write 32-bit MAC register
258
259 Arguments:
260
261 Return Value:
262
263 IRQL =
264
265 Note:
266
267 ========================================================================
268*/
62eb734b 269int RTUSBWriteMACRegister(struct rt_rtmp_adapter *pAd,
51126deb 270 u16 Offset, u32 Value)
c55519ff 271{
51126deb
BZ
272 int Status;
273 u32 localVal;
c55519ff
GKH
274
275 localVal = Value;
276
51126deb 277 Status = RTUSBSingleWrite(pAd, Offset, (u16)(localVal & 0xffff));
66cd8d6e
BZ
278 Status =
279 RTUSBSingleWrite(pAd, Offset + 2,
51126deb 280 (u16)((localVal & 0xffff0000) >> 16));
c55519ff
GKH
281
282 return Status;
283}
284
c55519ff
GKH
285/*
286 ========================================================================
287
288 Routine Description: Read 8-bit BBP register
289
290 Arguments:
291
292 Return Value:
293
294 IRQL =
295
296 Note:
297
298 ========================================================================
299*/
62eb734b 300int RTUSBReadBBPRegister(struct rt_rtmp_adapter *pAd,
51126deb 301 u8 Id, u8 *pValue)
c55519ff 302{
66cd8d6e 303 BBP_CSR_CFG_STRUC BbpCsr;
51126deb
BZ
304 u32 i = 0;
305 int status;
c55519ff 306
9f548a2a 307 /* Verify the busy condition */
66cd8d6e 308 do {
c55519ff 309 status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
66cd8d6e
BZ
310 if (status >= 0) {
311 if (!(BbpCsr.field.Busy == BUSY))
312 break;
c55519ff 313 }
66cd8d6e
BZ
314 DBGPRINT(RT_DEBUG_TRACE,
315 ("RTUSBReadBBPRegister(BBP_CSR_CFG_1):retry count=%d!\n",
316 i));
c55519ff 317 i++;
66cd8d6e
BZ
318 } while ((i < RETRY_LIMIT)
319 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
c55519ff 320
66cd8d6e
BZ
321 if ((i == RETRY_LIMIT)
322 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
9f548a2a
BZ
323 /* */
324 /* Read failed then Return Default value. */
325 /* */
c55519ff
GKH
326 *pValue = pAd->BbpWriteLatch[Id];
327
66cd8d6e
BZ
328 DBGPRINT_RAW(RT_DEBUG_ERROR,
329 ("Retry count exhausted or device removed!!!\n"));
c55519ff
GKH
330 return STATUS_UNSUCCESSFUL;
331 }
9f548a2a 332 /* Prepare for write material */
66cd8d6e
BZ
333 BbpCsr.word = 0;
334 BbpCsr.field.fRead = 1;
335 BbpCsr.field.Busy = 1;
336 BbpCsr.field.RegNum = Id;
c55519ff
GKH
337 RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
338
339 i = 0;
9f548a2a 340 /* Verify the busy condition */
66cd8d6e 341 do {
c55519ff 342 status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
66cd8d6e
BZ
343 if (status >= 0) {
344 if (!(BbpCsr.field.Busy == BUSY)) {
51126deb 345 *pValue = (u8)BbpCsr.field.Value;
66cd8d6e
BZ
346 break;
347 }
c55519ff 348 }
66cd8d6e
BZ
349 DBGPRINT(RT_DEBUG_TRACE,
350 ("RTUSBReadBBPRegister(BBP_CSR_CFG_2):retry count=%d!\n",
351 i));
c55519ff 352 i++;
66cd8d6e
BZ
353 } while ((i < RETRY_LIMIT)
354 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
c55519ff 355
66cd8d6e
BZ
356 if ((i == RETRY_LIMIT)
357 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
9f548a2a
BZ
358 /* */
359 /* Read failed then Return Default value. */
360 /* */
c55519ff
GKH
361 *pValue = pAd->BbpWriteLatch[Id];
362
66cd8d6e
BZ
363 DBGPRINT_RAW(RT_DEBUG_ERROR,
364 ("Retry count exhausted or device removed!!!\n"));
c55519ff
GKH
365 return STATUS_UNSUCCESSFUL;
366 }
367
368 return STATUS_SUCCESS;
369}
c55519ff 370
c55519ff
GKH
371/*
372 ========================================================================
373
374 Routine Description: Write 8-bit BBP register
375
376 Arguments:
377
378 Return Value:
379
380 IRQL =
381
382 Note:
383
384 ========================================================================
385*/
62eb734b 386int RTUSBWriteBBPRegister(struct rt_rtmp_adapter *pAd,
51126deb 387 u8 Id, u8 Value)
c55519ff 388{
66cd8d6e 389 BBP_CSR_CFG_STRUC BbpCsr;
51126deb
BZ
390 u32 i = 0;
391 int status;
9f548a2a 392 /* Verify the busy condition */
66cd8d6e 393 do {
c55519ff 394 status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
66cd8d6e
BZ
395 if (status >= 0) {
396 if (!(BbpCsr.field.Busy == BUSY))
397 break;
c55519ff 398 }
66cd8d6e
BZ
399 DBGPRINT(RT_DEBUG_TRACE,
400 ("RTUSBWriteBBPRegister(BBP_CSR_CFG):retry count=%d!\n",
401 i));
c55519ff
GKH
402 i++;
403 }
66cd8d6e
BZ
404 while ((i < RETRY_LIMIT)
405 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
c55519ff 406
66cd8d6e
BZ
407 if ((i == RETRY_LIMIT)
408 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
409 DBGPRINT_RAW(RT_DEBUG_ERROR,
410 ("Retry count exhausted or device removed!!!\n"));
c55519ff
GKH
411 return STATUS_UNSUCCESSFUL;
412 }
9f548a2a 413 /* Prepare for write material */
66cd8d6e
BZ
414 BbpCsr.word = 0;
415 BbpCsr.field.fRead = 0;
416 BbpCsr.field.Value = Value;
417 BbpCsr.field.Busy = 1;
418 BbpCsr.field.RegNum = Id;
c55519ff
GKH
419 RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
420
421 pAd->BbpWriteLatch[Id] = Value;
422
423 return STATUS_SUCCESS;
424}
66cd8d6e 425
c55519ff
GKH
426/*
427 ========================================================================
428
429 Routine Description: Write RF register through MAC
430
431 Arguments:
432
433 Return Value:
434
435 IRQL =
436
437 Note:
438
439 ========================================================================
440*/
62eb734b 441int RTUSBWriteRFRegister(struct rt_rtmp_adapter *pAd, u32 Value)
c55519ff 442{
66cd8d6e 443 PHY_CSR4_STRUC PhyCsr4;
51126deb
BZ
444 u32 i = 0;
445 int status;
c55519ff
GKH
446
447 NdisZeroMemory(&PhyCsr4, sizeof(PHY_CSR4_STRUC));
66cd8d6e 448 do {
c55519ff 449 status = RTUSBReadMACRegister(pAd, RF_CSR_CFG0, &PhyCsr4.word);
66cd8d6e
BZ
450 if (status >= 0) {
451 if (!(PhyCsr4.field.Busy))
452 break;
c55519ff 453 }
66cd8d6e
BZ
454 DBGPRINT(RT_DEBUG_TRACE,
455 ("RTUSBWriteRFRegister(RF_CSR_CFG0):retry count=%d!\n",
456 i));
c55519ff
GKH
457 i++;
458 }
66cd8d6e
BZ
459 while ((i < RETRY_LIMIT)
460 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
c55519ff 461
66cd8d6e
BZ
462 if ((i == RETRY_LIMIT)
463 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
464 DBGPRINT_RAW(RT_DEBUG_ERROR,
465 ("Retry count exhausted or device removed!!!\n"));
c55519ff
GKH
466 return STATUS_UNSUCCESSFUL;
467 }
468
469 RTUSBWriteMACRegister(pAd, RF_CSR_CFG0, Value);
470
471 return STATUS_SUCCESS;
472}
473
c55519ff
GKH
474/*
475 ========================================================================
476
477 Routine Description:
478
479 Arguments:
480
481 Return Value:
482
483 IRQL =
484
485 Note:
486
487 ========================================================================
488*/
62eb734b 489int RTUSBReadEEPROM(struct rt_rtmp_adapter *pAd,
51126deb 490 u16 Offset, u8 *pData, u16 length)
c55519ff 491{
51126deb 492 int Status = STATUS_SUCCESS;
66cd8d6e
BZ
493
494 Status = RTUSB_VendorRequest(pAd,
495 (USBD_TRANSFER_DIRECTION_IN |
496 USBD_SHORT_TRANSFER_OK),
497 DEVICE_VENDOR_REQUEST_IN, 0x9, 0, Offset,
498 pData, length);
c55519ff
GKH
499
500 return Status;
501}
502
503/*
504 ========================================================================
505
506 Routine Description:
507
508 Arguments:
509
510 Return Value:
511
512 IRQL =
513
514 Note:
515
516 ========================================================================
517*/
62eb734b 518int RTUSBWriteEEPROM(struct rt_rtmp_adapter *pAd,
51126deb 519 u16 Offset, u8 *pData, u16 length)
c55519ff 520{
51126deb 521 int Status = STATUS_SUCCESS;
66cd8d6e
BZ
522
523 Status = RTUSB_VendorRequest(pAd,
524 USBD_TRANSFER_DIRECTION_OUT,
525 DEVICE_VENDOR_REQUEST_OUT,
526 0x8, 0, Offset, pData, length);
c55519ff
GKH
527
528 return Status;
529}
530
62eb734b 531int RTUSBReadEEPROM16(struct rt_rtmp_adapter *pAd,
51126deb 532 u16 offset, u16 *pData)
ca97b838 533{
51126deb
BZ
534 int status;
535 u16 localData;
ca97b838 536
51126deb 537 status = RTUSBReadEEPROM(pAd, offset, (u8 *)(&localData), 2);
ca97b838
BZ
538 if (status == STATUS_SUCCESS)
539 *pData = le2cpu16(localData);
540
541 return status;
542
543}
544
c55519ff
GKH
545/*
546 ========================================================================
547
548 Routine Description:
549
550 Arguments:
551
552 Return Value:
553
554 IRQL =
555
556 Note:
557
558 ========================================================================
559*/
62eb734b 560void RTUSBPutToSleep(struct rt_rtmp_adapter *pAd)
c55519ff 561{
51126deb 562 u32 value;
c55519ff 563
9f548a2a 564 /* Timeout 0x40 x 50us */
66cd8d6e 565 value = (SLEEPCID << 16) + (OWNERMCU << 24) + (0x40 << 8) + 1;
c55519ff
GKH
566 RTUSBWriteMACRegister(pAd, 0x7010, value);
567 RTUSBWriteMACRegister(pAd, 0x404, 0x30);
9f548a2a 568 /*RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); */
c55519ff
GKH
569 DBGPRINT_RAW(RT_DEBUG_ERROR, ("Sleep Mailbox testvalue %x\n", value));
570
571}
572
573/*
574 ========================================================================
575
576 Routine Description:
577
578 Arguments:
579
580 Return Value:
581
582 IRQL =
583
584 Note:
585
586 ========================================================================
587*/
62eb734b 588int RTUSBWakeUp(struct rt_rtmp_adapter *pAd)
c55519ff 589{
51126deb 590 int Status;
66cd8d6e
BZ
591
592 Status = RTUSB_VendorRequest(pAd,
593 USBD_TRANSFER_DIRECTION_OUT,
594 DEVICE_VENDOR_REQUEST_OUT,
595 0x01, 0x09, 0, NULL, 0);
c55519ff
GKH
596
597 return Status;
598}
599
600/*
601 ========================================================================
602
603 Routine Description:
604
605 Arguments:
606
607 Return Value:
608
609 IRQL =
610
611 Note:
612
613 ========================================================================
614*/
62eb734b 615void RTUSBInitializeCmdQ(struct rt_cmdq *cmdq)
c55519ff
GKH
616{
617 cmdq->head = NULL;
618 cmdq->tail = NULL;
619 cmdq->size = 0;
ca97b838 620 cmdq->CmdQState = RTMP_TASK_STAT_INITED;
c55519ff
GKH
621}
622
623/*
624 ========================================================================
625
626 Routine Description:
627
628 Arguments:
629
630 Return Value:
631
632 IRQL =
633
634 Note:
635
636 ========================================================================
637*/
62eb734b 638int RTUSBEnqueueCmdFromNdis(struct rt_rtmp_adapter *pAd,
66cd8d6e
BZ
639 IN NDIS_OID Oid,
640 IN BOOLEAN SetInformation,
51126deb
BZ
641 void *pInformationBuffer,
642 u32 InformationBufferLength)
c55519ff 643{
51126deb 644 int status;
62eb734b
BZ
645 struct rt_cmdqelmt *cmdqelmt = NULL;
646 struct rt_rtmp_os_task *pTask = &pAd->cmdQTask;
c55519ff 647
ca97b838
BZ
648#ifdef KTHREAD_SUPPORT
649 if (pTask->kthread_task == NULL)
650#else
66cd8d6e 651 CHECK_PID_LEGALITY(pTask->taskPID) {
ca97b838
BZ
652 }
653 else
654#endif
66cd8d6e 655 return (NDIS_STATUS_RESOURCES);
c55519ff 656
62eb734b 657 status = os_alloc_mem(pAd, (u8 **) (&cmdqelmt), sizeof(struct rt_cmdqelmt));
c55519ff
GKH
658 if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
659 return (NDIS_STATUS_RESOURCES);
660
66cd8d6e
BZ
661 cmdqelmt->buffer = NULL;
662 if (pInformationBuffer != NULL) {
663 status =
51126deb 664 os_alloc_mem(pAd, (u8 **) & cmdqelmt->buffer,
66cd8d6e
BZ
665 InformationBufferLength);
666 if ((status != NDIS_STATUS_SUCCESS)
667 || (cmdqelmt->buffer == NULL)) {
668 kfree(cmdqelmt);
669 return (NDIS_STATUS_RESOURCES);
670 } else {
671 NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer,
672 InformationBufferLength);
673 cmdqelmt->bufferlength = InformationBufferLength;
c55519ff 674 }
66cd8d6e
BZ
675 } else
676 cmdqelmt->bufferlength = 0;
c55519ff
GKH
677
678 cmdqelmt->command = Oid;
679 cmdqelmt->CmdFromNdis = TRUE;
680 if (SetInformation == TRUE)
681 cmdqelmt->SetOperation = TRUE;
682 else
683 cmdqelmt->SetOperation = FALSE;
684
685 NdisAcquireSpinLock(&pAd->CmdQLock);
66cd8d6e 686 if (pAd->CmdQ.CmdQState & RTMP_TASK_CAN_DO_INSERT) {
c55519ff
GKH
687 EnqueueCmd((&pAd->CmdQ), cmdqelmt);
688 status = NDIS_STATUS_SUCCESS;
66cd8d6e 689 } else {
c55519ff
GKH
690 status = NDIS_STATUS_FAILURE;
691 }
692 NdisReleaseSpinLock(&pAd->CmdQLock);
693
66cd8d6e 694 if (status == NDIS_STATUS_FAILURE) {
c55519ff 695 if (cmdqelmt->buffer)
ca97b838
BZ
696 os_free_mem(pAd, cmdqelmt->buffer);
697 os_free_mem(pAd, cmdqelmt);
66cd8d6e
BZ
698 } else
699 RTUSBCMDUp(pAd);
c55519ff 700
66cd8d6e 701 return (NDIS_STATUS_SUCCESS);
c55519ff
GKH
702}
703
704/*
705 ========================================================================
706
707 Routine Description:
708
709 Arguments:
710
711 Return Value:
712
713 IRQL =
714
715 Note:
716
717 ========================================================================
718*/
62eb734b 719int RTUSBEnqueueInternalCmd(struct rt_rtmp_adapter *pAd,
66cd8d6e 720 IN NDIS_OID Oid,
51126deb
BZ
721 void *pInformationBuffer,
722 u32 InformationBufferLength)
c55519ff 723{
51126deb 724 int status;
62eb734b 725 struct rt_cmdqelmt *cmdqelmt = NULL;
c55519ff 726
62eb734b 727 status = os_alloc_mem(pAd, (u8 **) & cmdqelmt, sizeof(struct rt_cmdqelmt));
c55519ff
GKH
728 if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
729 return (NDIS_STATUS_RESOURCES);
62eb734b 730 NdisZeroMemory(cmdqelmt, sizeof(struct rt_cmdqelmt));
c55519ff 731
66cd8d6e
BZ
732 if (InformationBufferLength > 0) {
733 status =
51126deb 734 os_alloc_mem(pAd, (u8 **) & cmdqelmt->buffer,
66cd8d6e
BZ
735 InformationBufferLength);
736 if ((status != NDIS_STATUS_SUCCESS)
737 || (cmdqelmt->buffer == NULL)) {
ca97b838 738 os_free_mem(pAd, cmdqelmt);
c55519ff 739 return (NDIS_STATUS_RESOURCES);
66cd8d6e
BZ
740 } else {
741 NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer,
742 InformationBufferLength);
c55519ff
GKH
743 cmdqelmt->bufferlength = InformationBufferLength;
744 }
66cd8d6e 745 } else {
c55519ff
GKH
746 cmdqelmt->buffer = NULL;
747 cmdqelmt->bufferlength = 0;
748 }
749
750 cmdqelmt->command = Oid;
751 cmdqelmt->CmdFromNdis = FALSE;
752
66cd8d6e 753 if (cmdqelmt != NULL) {
c55519ff 754 NdisAcquireSpinLock(&pAd->CmdQLock);
66cd8d6e 755 if (pAd->CmdQ.CmdQState & RTMP_TASK_CAN_DO_INSERT) {
c55519ff
GKH
756 EnqueueCmd((&pAd->CmdQ), cmdqelmt);
757 status = NDIS_STATUS_SUCCESS;
66cd8d6e 758 } else {
c55519ff
GKH
759 status = NDIS_STATUS_FAILURE;
760 }
761 NdisReleaseSpinLock(&pAd->CmdQLock);
762
66cd8d6e 763 if (status == NDIS_STATUS_FAILURE) {
c55519ff 764 if (cmdqelmt->buffer)
ca97b838
BZ
765 os_free_mem(pAd, cmdqelmt->buffer);
766 os_free_mem(pAd, cmdqelmt);
66cd8d6e
BZ
767 } else
768 RTUSBCMDUp(pAd);
c55519ff 769 }
66cd8d6e 770 return (NDIS_STATUS_SUCCESS);
c55519ff
GKH
771}
772
773/*
774 ========================================================================
775
776 Routine Description:
777
778 Arguments:
779
780 Return Value:
781
782 IRQL =
783
784 Note:
785
786 ========================================================================
787*/
62eb734b 788void RTUSBDequeueCmd(struct rt_cmdq *cmdq, struct rt_cmdqelmt * * pcmdqelmt)
c55519ff
GKH
789{
790 *pcmdqelmt = cmdq->head;
791
66cd8d6e 792 if (*pcmdqelmt != NULL) {
c55519ff
GKH
793 cmdq->head = cmdq->head->next;
794 cmdq->size--;
795 if (cmdq->size == 0)
796 cmdq->tail = NULL;
797 }
798}
799
800/*
801 ========================================================================
802 usb_control_msg - Builds a control urb, sends it off and waits for completion
803 @dev: pointer to the usb device to send the message to
804 @pipe: endpoint "pipe" to send the message to
805 @request: USB message request value
806 @requesttype: USB message request type value
807 @value: USB message value
808 @index: USB message index value
809 @data: pointer to the data to send
810 @size: length in bytes of the data to send
811 @timeout: time in jiffies to wait for the message to complete before
812 timing out (if 0 the wait is forever)
813 Context: !in_interrupt ()
814
815 This function sends a simple control message to a specified endpoint
816 and waits for the message to complete, or timeout.
817 If successful, it returns the number of bytes transferred, otherwise a negative error number.
818
819 Don't use this function from within an interrupt context, like a
820 bottom half handler. If you need an asynchronous message, or need to send
821 a message from within interrupt context, use usb_submit_urb()
822 If a thread in your driver uses this call, make sure your disconnect()
823 method can wait for it to complete. Since you don't have a handle on
824 the URB used, you can't cancel the request.
825
c55519ff
GKH
826 Routine Description:
827
828 Arguments:
829
830 Return Value:
831
832 Note:
833
834 ========================================================================
835*/
62eb734b 836int RTUSB_VendorRequest(struct rt_rtmp_adapter *pAd,
51126deb
BZ
837 u32 TransferFlags,
838 u8 RequestType,
839 u8 Request,
840 u16 Value,
841 u16 Index,
842 void *TransferBuffer,
843 u32 TransferBufferLength)
c55519ff 844{
66cd8d6e 845 int ret = 0;
8a10a546 846 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
c55519ff 847
66cd8d6e 848 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) {
c55519ff
GKH
849 DBGPRINT(RT_DEBUG_ERROR, ("device disconnected\n"));
850 return -1;
66cd8d6e
BZ
851 } else if (in_interrupt()) {
852 DBGPRINT(RT_DEBUG_ERROR,
853 ("in_interrupt, RTUSB_VendorRequest Request%02x Value%04x Offset%04x\n",
854 Request, Value, Index));
c55519ff
GKH
855
856 return -1;
66cd8d6e 857 } else {
c55519ff
GKH
858#define MAX_RETRY_COUNT 10
859
860 int retryCount = 0;
66cd8d6e 861 void *tmpBuf = TransferBuffer;
c55519ff 862
ca97b838 863 ret = down_interruptible(&(pAd->UsbVendorReq_semaphore));
66cd8d6e
BZ
864 if (pAd->UsbVendorReqBuf) {
865 ASSERT(TransferBufferLength < MAX_PARAM_BUFFER_SIZE);
ca97b838
BZ
866
867 tmpBuf = (void *)pAd->UsbVendorReqBuf;
66cd8d6e
BZ
868 NdisZeroMemory(pAd->UsbVendorReqBuf,
869 TransferBufferLength);
ca97b838
BZ
870
871 if (RequestType == DEVICE_VENDOR_REQUEST_OUT)
66cd8d6e
BZ
872 NdisMoveMemory(tmpBuf, TransferBuffer,
873 TransferBufferLength);
ca97b838
BZ
874 }
875
c55519ff 876 do {
66cd8d6e
BZ
877 if (RequestType == DEVICE_VENDOR_REQUEST_OUT)
878 ret =
879 usb_control_msg(pObj->pUsb_Dev,
880 usb_sndctrlpipe(pObj->
881 pUsb_Dev,
882 0), Request,
883 RequestType, Value, Index,
884 tmpBuf,
885 TransferBufferLength,
886 CONTROL_TIMEOUT_JIFFIES);
887 else if (RequestType == DEVICE_VENDOR_REQUEST_IN)
888 ret =
889 usb_control_msg(pObj->pUsb_Dev,
890 usb_rcvctrlpipe(pObj->
891 pUsb_Dev,
892 0), Request,
893 RequestType, Value, Index,
894 tmpBuf,
895 TransferBufferLength,
896 CONTROL_TIMEOUT_JIFFIES);
897 else {
898 DBGPRINT(RT_DEBUG_ERROR,
899 ("vendor request direction is failed\n"));
900 ret = -1;
901 }
c55519ff
GKH
902
903 retryCount++;
904 if (ret < 0) {
ca97b838 905 DBGPRINT(RT_DEBUG_OFF, ("#\n"));
c55519ff
GKH
906 RTMPusecDelay(5000);
907 }
66cd8d6e 908 } while ((ret < 0) && (retryCount < MAX_RETRY_COUNT));
c55519ff 909
66cd8d6e
BZ
910 if ((pAd->UsbVendorReqBuf)
911 && (RequestType == DEVICE_VENDOR_REQUEST_IN))
912 NdisMoveMemory(TransferBuffer, tmpBuf,
913 TransferBufferLength);
ca97b838
BZ
914 up(&(pAd->UsbVendorReq_semaphore));
915
66cd8d6e
BZ
916 if (ret < 0) {
917 DBGPRINT(RT_DEBUG_ERROR,
918 ("RTUSB_VendorRequest failed(%d),TxFlags=0x%x, ReqType=%s, Req=0x%x, Index=0x%x\n",
919 ret, TransferFlags,
920 (RequestType ==
921 DEVICE_VENDOR_REQUEST_OUT ? "OUT" : "IN"),
922 Request, Index));
c55519ff 923 if (Request == 0x2)
66cd8d6e
BZ
924 DBGPRINT(RT_DEBUG_ERROR,
925 ("\tRequest Value=0x%04x!\n", Value));
ca97b838 926
66cd8d6e
BZ
927 if ((TransferBuffer != NULL)
928 && (TransferBufferLength > 0))
929 hex_dump("Failed TransferBuffer value",
930 TransferBuffer, TransferBufferLength);
931 }
ca97b838 932
c55519ff 933 }
ca97b838
BZ
934
935 if (ret != -1)
936 return STATUS_SUCCESS;
937 else
938 return STATUS_UNSUCCESSFUL;
c55519ff
GKH
939}
940
941/*
942 ========================================================================
943
944 Routine Description:
945 Creates an IRP to submite an IOCTL_INTERNAL_USB_RESET_PORT
946 synchronously. Callers of this function must be running at
947 PASSIVE LEVEL.
948
949 Arguments:
950
951 Return Value:
952
953 Note:
954
955 ========================================================================
956*/
62eb734b 957int RTUSB_ResetDevice(struct rt_rtmp_adapter *pAd)
c55519ff 958{
51126deb 959 int Status = TRUE;
c55519ff
GKH
960
961 DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->USB_ResetDevice\n"));
9f548a2a 962 /*RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS); */
c55519ff
GKH
963 return Status;
964}
965
62eb734b 966void CMDHandler(struct rt_rtmp_adapter *pAd)
c55519ff 967{
62eb734b 968 struct rt_cmdqelmt *cmdqelmt;
51126deb
BZ
969 u8 *pData;
970 int NdisStatus = NDIS_STATUS_SUCCESS;
971/* unsigned long Now = 0; */
972 int ntStatus;
9f548a2a 973/* unsigned long IrqFlags; */
66cd8d6e
BZ
974
975 while (pAd && pAd->CmdQ.size > 0) {
c55519ff
GKH
976 NdisStatus = NDIS_STATUS_SUCCESS;
977
978 NdisAcquireSpinLock(&pAd->CmdQLock);
979 RTUSBDequeueCmd(&pAd->CmdQ, &cmdqelmt);
980 NdisReleaseSpinLock(&pAd->CmdQLock);
981
982 if (cmdqelmt == NULL)
983 break;
984
985 pData = cmdqelmt->buffer;
986
66cd8d6e
BZ
987 if (!
988 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)
989 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) {
990 switch (cmdqelmt->command) {
991 case CMDTHREAD_CHECK_GPIO:
992 {
51126deb 993 u32 data;
c55519ff 994
66cd8d6e 995 {
9f548a2a 996 /* Read GPIO pin2 as Hardware controlled radio state */
66cd8d6e
BZ
997
998 RTUSBReadMACRegister(pAd,
999 GPIO_CTRL_CFG,
1000 &data);
1001
1002 if (data & 0x04) {
1003 pAd->StaCfg.bHwRadio =
1004 TRUE;
1005 } else {
1006 pAd->StaCfg.bHwRadio =
1007 FALSE;
1008 }
c55519ff 1009
66cd8d6e
BZ
1010 if (pAd->StaCfg.bRadio !=
1011 (pAd->StaCfg.bHwRadio
1012 && pAd->StaCfg.bSwRadio)) {
1013 pAd->StaCfg.bRadio =
1014 (pAd->StaCfg.
1015 bHwRadio
1016 && pAd->StaCfg.
1017 bSwRadio);
1018 if (pAd->StaCfg.
1019 bRadio == TRUE) {
1020 DBGPRINT_RAW
1021 (RT_DEBUG_ERROR,
1022 ("!!! Radio On !!!\n"));
1023
1024 MlmeRadioOn
1025 (pAd);
9f548a2a 1026 /* Update extra information */
66cd8d6e
BZ
1027 pAd->ExtraInfo =
1028 EXTRA_INFO_CLEAR;
1029 } else {
1030 DBGPRINT_RAW
1031 (RT_DEBUG_ERROR,
1032 ("!!! Radio Off !!!\n"));
1033
1034 MlmeRadioOff
1035 (pAd);
9f548a2a 1036 /* Update extra information */
66cd8d6e
BZ
1037 pAd->ExtraInfo =
1038 HW_RADIO_OFF;
c55519ff
GKH
1039 }
1040 }
c55519ff 1041 }
66cd8d6e
BZ
1042 }
1043 break;
1044
1045 case CMDTHREAD_QKERIODIC_EXECUT:
1046 {
1047 StaQuickResponeForRateUpExec(NULL, pAd,
1048 NULL,
1049 NULL);
1050 }
1051 break;
1052
1053 case CMDTHREAD_RESET_BULK_OUT:
1054 {
51126deb
BZ
1055 u32 MACValue;
1056 u8 Index;
66cd8d6e 1057 int ret = 0;
62eb734b
BZ
1058 struct rt_ht_tx_context *pHTTXContext;
1059/* struct rt_rtmp_tx_ring *pTxRing; */
66cd8d6e
BZ
1060 unsigned long IrqFlags;
1061
1062 DBGPRINT_RAW(RT_DEBUG_TRACE,
1063 ("CmdThread : CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n",
1064 pAd->bulkResetPipeid));
9f548a2a
BZ
1065 /* All transfers must be aborted or cancelled before attempting to reset the pipe. */
1066 /*RTUSBCancelPendingBulkOutIRP(pAd); */
1067 /* Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007 */
66cd8d6e
BZ
1068 Index = 0;
1069 do {
1070 RTUSBReadMACRegister(pAd,
1071 TXRXQ_PCNT,
1072 &MACValue);
1073 if ((MACValue & 0xf00000
1074 /*0x800000 */ ) == 0)
1075 break;
1076 Index++;
1077 RTMPusecDelay(10000);
1078 } while (Index < 100);
1079 MACValue = 0;
1080 RTUSBReadMACRegister(pAd, USB_DMA_CFG,
1081 &MACValue);
9f548a2a 1082 /* To prevent Read Register error, we 2nd check the validity. */
66cd8d6e
BZ
1083 if ((MACValue & 0xc00000) == 0)
1084 RTUSBReadMACRegister(pAd,
1085 USB_DMA_CFG,
1086 &MACValue);
9f548a2a 1087 /* To prevent Read Register error, we 3rd check the validity. */
66cd8d6e
BZ
1088 if ((MACValue & 0xc00000) == 0)
1089 RTUSBReadMACRegister(pAd,
1090 USB_DMA_CFG,
1091 &MACValue);
1092 MACValue |= 0x80000;
1093 RTUSBWriteMACRegister(pAd, USB_DMA_CFG,
1094 MACValue);
1095
9f548a2a 1096 /* Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 */
66cd8d6e
BZ
1097 RTMPusecDelay(1000);
1098
1099 MACValue &= (~0x80000);
1100 RTUSBWriteMACRegister(pAd, USB_DMA_CFG,
1101 MACValue);
1102 DBGPRINT_RAW(RT_DEBUG_TRACE,
1103 ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n"));
1104
9f548a2a
BZ
1105 /* Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 */
1106 /*RTMPusecDelay(5000); */
66cd8d6e
BZ
1107
1108 if ((pAd->
1109 bulkResetPipeid &
1110 BULKOUT_MGMT_RESET_FLAG) ==
1111 BULKOUT_MGMT_RESET_FLAG) {
1112 RTMP_CLEAR_FLAG(pAd,
1113 fRTMP_ADAPTER_BULKOUT_RESET);
1114 if (pAd->MgmtRing.TxSwFreeIdx <
1115 MGMT_RING_SIZE
1116 /* pMLMEContext->bWaitingBulkOut == TRUE */
1117 ) {
1118 RTUSB_SET_BULK_FLAG(pAd,
1119 fRTUSB_BULK_OUT_MLME);
1120 }
1121 RTUSBKickBulkOut(pAd);
1122
1123 DBGPRINT_RAW(RT_DEBUG_TRACE,
1124 ("\tTX MGMT RECOVER Done!\n"));
1125 } else {
1126 pHTTXContext =
1127 &(pAd->
1128 TxContext[pAd->
1129 bulkResetPipeid]);
9f548a2a 1130 /*NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */
66cd8d6e
BZ
1131 RTMP_INT_LOCK(&pAd->
1132 BulkOutLock[pAd->
1133 bulkResetPipeid],
1134 IrqFlags);
1135 if (pAd->
1136 BulkOutPending[pAd->
1137 bulkResetPipeid]
1138 == FALSE) {
1139 pAd->
1140 BulkOutPending[pAd->
1141 bulkResetPipeid]
1142 = TRUE;
1143 pHTTXContext->
1144 IRPPending = TRUE;
1145 pAd->
1146 watchDogTxPendingCnt
1147 [pAd->
1148 bulkResetPipeid] =
1149 1;
c55519ff 1150
9f548a2a 1151 /* no matter what, clean the flag */
66cd8d6e
BZ
1152 RTMP_CLEAR_FLAG(pAd,
1153 fRTMP_ADAPTER_BULKOUT_RESET);
1154
9f548a2a 1155 /*NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */
66cd8d6e
BZ
1156 RTMP_INT_UNLOCK(&pAd->
1157 BulkOutLock
1158 [pAd->
1159 bulkResetPipeid],
1160 IrqFlags);
c55519ff 1161 {
66cd8d6e
BZ
1162 RTUSBInitHTTxDesc
1163 (pAd,
1164 pHTTXContext,
1165 pAd->
1166 bulkResetPipeid,
1167 pHTTXContext->
1168 BulkOutSize,
1169 (usb_complete_t)
1170 RTUSBBulkOutDataPacketComplete);
1171
1172 if ((ret =
1173 RTUSB_SUBMIT_URB
1174 (pHTTXContext->
1175 pUrb)) !=
1176 0) {
1177 RTMP_INT_LOCK
1178 (&pAd->
1179 BulkOutLock
1180 [pAd->
1181 bulkResetPipeid],
1182 IrqFlags);
1183 pAd->
1184 BulkOutPending
1185 [pAd->
1186 bulkResetPipeid]
1187 =
1188 FALSE;
1189 pHTTXContext->
1190 IRPPending
1191 =
1192 FALSE;
1193 pAd->
1194 watchDogTxPendingCnt
1195 [pAd->
1196 bulkResetPipeid]
1197 = 0;
1198 RTMP_INT_UNLOCK
1199 (&pAd->
1200 BulkOutLock
1201 [pAd->
1202 bulkResetPipeid],
1203 IrqFlags);
1204
1205 DBGPRINT
1206 (RT_DEBUG_ERROR,
1207 ("CmdThread : CMDTHREAD_RESET_BULK_OUT: Submit Tx URB failed %d\n",
1208 ret));
1209 } else {
1210 RTMP_IRQ_LOCK
1211 (&pAd->
1212 BulkOutLock
1213 [pAd->
1214 bulkResetPipeid],
1215 IrqFlags);
1216 DBGPRINT_RAW
1217 (RT_DEBUG_TRACE,
1218 ("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n",
1219 pAd->
1220 bulkResetPipeid,
1221 pHTTXContext->
1222 CurWritePosition,
1223 pHTTXContext->
1224 NextBulkOutPosition,
1225 pHTTXContext->
1226 ENextBulkOutPosition,
1227 pHTTXContext->
1228 bCopySavePad,
1229 pAd->
1230 BulkOutPending
1231 [pAd->
1232 bulkResetPipeid]));
1233 DBGPRINT_RAW
1234 (RT_DEBUG_TRACE,
1235 ("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n",
1236 pAd->
1237 BulkOutReq,
1238 pAd->
1239 BulkOutComplete,
1240 pAd->
1241 BulkOutCompleteOther));
1242 RTMP_IRQ_UNLOCK
1243 (&pAd->
1244 BulkOutLock
1245 [pAd->
1246 bulkResetPipeid],
1247 IrqFlags);
1248 DBGPRINT_RAW
1249 (RT_DEBUG_TRACE,
1250 ("\tCMDTHREAD_RESET_BULK_OUT: Submit Tx DATA URB for failed BulkReq(0x%lx) Done, status=%d!\n",
1251 pAd->
1252 bulkResetReq
1253 [pAd->
1254 bulkResetPipeid],
1255 pHTTXContext->
1256 pUrb->
1257 status));
c55519ff 1258
c55519ff
GKH
1259 }
1260 }
66cd8d6e 1261 } else {
9f548a2a
BZ
1262 /*NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */
1263 /*RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); */
66cd8d6e
BZ
1264
1265 DBGPRINT_RAW
1266 (RT_DEBUG_ERROR,
1267 ("CmdThread : TX DATA RECOVER FAIL for BulkReq(0x%lx) because BulkOutPending[%d] is TRUE!\n",
1268 pAd->
1269 bulkResetReq[pAd->
1270 bulkResetPipeid],
1271 pAd->
1272 bulkResetPipeid));
1273 if (pAd->
1274 bulkResetPipeid ==
1275 0) {
51126deb 1276 u8
66cd8d6e
BZ
1277 pendingContext
1278 = 0;
62eb734b 1279 struct rt_ht_tx_context *
66cd8d6e
BZ
1280 pHTTXContext
1281 =
62eb734b 1282 (struct rt_ht_tx_context *)
66cd8d6e
BZ
1283 (&pAd->
1284 TxContext
1285 [pAd->
1286 bulkResetPipeid]);
62eb734b 1287 struct rt_tx_context *
66cd8d6e
BZ
1288 pMLMEContext
1289 =
62eb734b 1290 (struct rt_tx_context *)
66cd8d6e
BZ
1291 (pAd->
1292 MgmtRing.
1293 Cell[pAd->
1294 MgmtRing.
1295 TxDmaIdx].
1296 AllocVa);
62eb734b 1297 struct rt_tx_context *
66cd8d6e
BZ
1298 pNULLContext
1299 =
62eb734b 1300 (struct rt_tx_context *)
66cd8d6e
BZ
1301 (&pAd->
1302 PsPollContext);
62eb734b 1303 struct rt_tx_context *
66cd8d6e
BZ
1304 pPsPollContext
1305 =
62eb734b 1306 (struct rt_tx_context *)
66cd8d6e
BZ
1307 (&pAd->
1308 NullContext);
1309
1310 if (pHTTXContext->IRPPending)
1311 pendingContext
1312 |=
1313 1;
1314 else if
1315 (pMLMEContext->
1316 IRPPending)
1317 pendingContext
1318 |=
1319 2;
1320 else if
1321 (pNULLContext->
1322 IRPPending)
1323 pendingContext
1324 |=
1325 4;
1326 else if
1327 (pPsPollContext->
1328 IRPPending)
1329 pendingContext
1330 |=
1331 8;
1332 else
1333 pendingContext
1334 = 0;
c55519ff 1335
66cd8d6e
BZ
1336 DBGPRINT_RAW
1337 (RT_DEBUG_ERROR,
1338 ("\tTX Occupied by %d!\n",
1339 pendingContext));
c55519ff 1340 }
9f548a2a 1341 /* no matter what, clean the flag */
66cd8d6e
BZ
1342 RTMP_CLEAR_FLAG(pAd,
1343 fRTMP_ADAPTER_BULKOUT_RESET);
1344
1345 RTMP_INT_UNLOCK(&pAd->
1346 BulkOutLock
1347 [pAd->
1348 bulkResetPipeid],
1349 IrqFlags);
1350
1351 RTUSB_SET_BULK_FLAG(pAd,
1352 (fRTUSB_BULK_OUT_DATA_NORMAL
1353 <<
1354 pAd->
1355 bulkResetPipeid));
c55519ff
GKH
1356 }
1357
66cd8d6e
BZ
1358 RTMPDeQueuePacket(pAd, FALSE,
1359 NUM_OF_TX_RING,
1360 MAX_TX_PROCESS);
9f548a2a 1361 /*RTUSBKickBulkOut(pAd); */
c55519ff 1362 }
c55519ff 1363
66cd8d6e
BZ
1364 }
1365 /*
1366 // Don't cancel BULKIN.
1367 while ((atomic_read(&pAd->PendingRx) > 0) &&
1368 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
1369 {
1370 if (atomic_read(&pAd->PendingRx) > 0)
1371 {
1372 DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n"));
1373 RTUSBCancelPendingBulkInIRP(pAd);
1374 }
1375 RTMPusecDelay(100000);
1376 }
1377
1378 if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)))
1379 {
51126deb 1380 u8 i;
66cd8d6e
BZ
1381 RTUSBRxPacket(pAd);
1382 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1383 pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
1384 for (i = 0; i < (RX_RING_SIZE); i++)
1385 {
62eb734b 1386 struct rt_rx_context *pRxContext = &(pAd->RxContext[i]);
66cd8d6e
BZ
1387
1388 pRxContext->pAd = pAd;
1389 pRxContext->InUse = FALSE;
1390 pRxContext->IRPPending = FALSE;
1391 pRxContext->Readable = FALSE;
1392 pRxContext->ReorderInUse = FALSE;
1393
1394 }
1395 RTUSBBulkReceive(pAd);
1396 DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n"));
1397 } */
1398 DBGPRINT_RAW(RT_DEBUG_TRACE,
1399 ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n"));
1400 break;
1401
1402 case CMDTHREAD_RESET_BULK_IN:
1403 DBGPRINT_RAW(RT_DEBUG_TRACE,
1404 ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n"));
1405
9f548a2a 1406 /* All transfers must be aborted or cancelled before attempting to reset the pipe. */
66cd8d6e 1407 {
51126deb 1408 u32 MACValue;
c55519ff 1409
c55519ff 1410 {
9f548a2a 1411 /*while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) */
66cd8d6e
BZ
1412 if ((pAd->PendingRx > 0)
1413 &&
1414 (!RTMP_TEST_FLAG
1415 (pAd,
1416 fRTMP_ADAPTER_NIC_NOT_EXIST)))
c55519ff 1417 {
66cd8d6e
BZ
1418 DBGPRINT_RAW
1419 (RT_DEBUG_ERROR,
1420 ("BulkIn IRP Pending!!!\n"));
1421 RTUSBCancelPendingBulkInIRP
1422 (pAd);
c55519ff
GKH
1423 RTMPusecDelay(100000);
1424 pAd->PendingRx = 0;
1425 }
66cd8d6e 1426 }
c55519ff 1427
9f548a2a 1428 /* Wait 10ms before reading register. */
66cd8d6e
BZ
1429 RTMPusecDelay(10000);
1430 ntStatus =
1431 RTUSBReadMACRegister(pAd, MAC_CSR0,
1432 &MACValue);
1433
1434 if ((NT_SUCCESS(ntStatus) == TRUE) &&
1435 (!(RTMP_TEST_FLAG
1436 (pAd,
1437 (fRTMP_ADAPTER_RESET_IN_PROGRESS
1438 | fRTMP_ADAPTER_RADIO_OFF |
1439 fRTMP_ADAPTER_HALT_IN_PROGRESS
1440 |
1441 fRTMP_ADAPTER_NIC_NOT_EXIST)))))
1442 {
51126deb 1443 u8 i;
66cd8d6e
BZ
1444
1445 if (RTMP_TEST_FLAG
1446 (pAd,
1447 (fRTMP_ADAPTER_RESET_IN_PROGRESS
1448 | fRTMP_ADAPTER_RADIO_OFF
1449 |
1450 fRTMP_ADAPTER_HALT_IN_PROGRESS
1451 |
1452 fRTMP_ADAPTER_NIC_NOT_EXIST)))
1453 break;
1454 pAd->NextRxBulkInPosition =
1455 pAd->RxContext[pAd->
1456 NextRxBulkInIndex].
1457 BulkInOffset;
1458 DBGPRINT(RT_DEBUG_TRACE,
1459 ("BULK_IN_RESET: NBIIdx=0x%x,NBIRIdx=0x%x, BIRPos=0x%lx. BIReq=x%lx, BIComplete=0x%lx, BICFail0x%lx\n",
1460 pAd->
1461 NextRxBulkInIndex,
1462 pAd->
1463 NextRxBulkInReadIndex,
1464 pAd->
1465 NextRxBulkInPosition,
1466 pAd->BulkInReq,
1467 pAd->BulkInComplete,
1468 pAd->
1469 BulkInCompleteFail));
1470 for (i = 0; i < RX_RING_SIZE;
1471 i++) {
1472 DBGPRINT(RT_DEBUG_TRACE,
1473 ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n",
1474 i,
1475 pAd->
1476 RxContext[i].
1477 IRPPending,
1478 pAd->
1479 RxContext[i].
1480 InUse,
1481 pAd->
1482 RxContext[i].
1483 Readable));
1484 }
1485 /*
1486
1487 DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n"));
1488
1489 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1490 pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
1491 for (i = 0; i < (RX_RING_SIZE); i++)
1492 {
62eb734b 1493 struct rt_rx_context *pRxContext = &(pAd->RxContext[i]);
66cd8d6e
BZ
1494
1495 pRxContext->pAd = pAd;
1496 pRxContext->InUse = FALSE;
1497 pRxContext->IRPPending = FALSE;
1498 pRxContext->Readable = FALSE;
1499 pRxContext->ReorderInUse = FALSE;
1500
1501 } */
1502 RTMP_CLEAR_FLAG(pAd,
1503 fRTMP_ADAPTER_BULKIN_RESET);
1504 for (i = 0;
1505 i <
1506 pAd->CommonCfg.
1507 NumOfBulkInIRP; i++) {
9f548a2a 1508 /*RTUSBBulkReceive(pAd); */
62eb734b 1509 struct rt_rx_context *pRxContext;
66cd8d6e
BZ
1510 PURB pUrb;
1511 int ret = 0;
1512 unsigned long IrqFlags;
1513
1514 RTMP_IRQ_LOCK(&pAd->
1515 BulkInLock,
1516 IrqFlags);
1517 pRxContext =
1518 &(pAd->
1519 RxContext[pAd->
1520 NextRxBulkInIndex]);
1521 if ((pAd->PendingRx > 0)
1522 || (pRxContext->
1523 Readable ==
1524 TRUE)
1525 || (pRxContext->
1526 InUse ==
1527 TRUE)) {
1528 RTMP_IRQ_UNLOCK
1529 (&pAd->
1530 BulkInLock,
1531 IrqFlags);
c55519ff 1532 break;
c55519ff 1533 }
66cd8d6e
BZ
1534 pRxContext->InUse =
1535 TRUE;
1536 pRxContext->IRPPending =
1537 TRUE;
1538 pAd->PendingRx++;
1539 pAd->BulkInReq++;
1540 RTMP_IRQ_UNLOCK(&pAd->
1541 BulkInLock,
1542 IrqFlags);
1543
9f548a2a 1544 /* Init Rx context descriptor */
66cd8d6e
BZ
1545 RTUSBInitRxDesc(pAd,
1546 pRxContext);
1547 pUrb = pRxContext->pUrb;
9f548a2a 1548 if ((ret = RTUSB_SUBMIT_URB(pUrb)) != 0) { /* fail */
66cd8d6e
BZ
1549
1550 RTMP_IRQ_LOCK
1551 (&pAd->
1552 BulkInLock,
1553 IrqFlags);
1554 pRxContext->
1555 InUse =
1556 FALSE;
1557 pRxContext->
1558 IRPPending =
1559 FALSE;
1560 pAd->
1561 PendingRx--;
1562 pAd->
1563 BulkInReq--;
1564 RTMP_IRQ_UNLOCK
1565 (&pAd->
1566 BulkInLock,
1567 IrqFlags);
1568 DBGPRINT
1569 (RT_DEBUG_ERROR,
1570 ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n",
1571 ret,
1572 pUrb->
1573 status));
9f548a2a
BZ
1574 } else { /* success */
1575 /*DBGPRINT(RT_DEBUG_TRACE, ("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", */
1576 /* pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex)); */
66cd8d6e
BZ
1577 DBGPRINT_RAW
1578 (RT_DEBUG_TRACE,
1579 ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n",
1580 pUrb->
1581 status));
1582 ASSERT((pRxContext->InUse == pRxContext->IRPPending));
c55519ff 1583 }
c55519ff 1584 }
c55519ff 1585
66cd8d6e 1586 } else {
9f548a2a 1587 /* Card must be removed */
66cd8d6e
BZ
1588 if (NT_SUCCESS(ntStatus) !=
1589 TRUE) {
1590 RTMP_SET_FLAG(pAd,
1591 fRTMP_ADAPTER_NIC_NOT_EXIST);
1592 DBGPRINT_RAW
1593 (RT_DEBUG_ERROR,
1594 ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n"));
1595 } else {
1596 DBGPRINT_RAW
1597 (RT_DEBUG_ERROR,
1598 ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n",
1599 pAd->Flags));
c55519ff 1600 }
c55519ff 1601 }
66cd8d6e
BZ
1602 }
1603 DBGPRINT_RAW(RT_DEBUG_TRACE,
1604 ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n"));
1605 break;
1606
1607 case CMDTHREAD_SET_ASIC_WCID:
1608 {
62eb734b 1609 struct rt_set_asic_wcid SetAsicWcid;
51126deb
BZ
1610 u16 offset;
1611 u32 MACValue, MACRValue = 0;
66cd8d6e 1612 SetAsicWcid =
62eb734b 1613 *((struct rt_set_asic_wcid *)(pData));
66cd8d6e
BZ
1614
1615 if (SetAsicWcid.WCID >=
1616 MAX_LEN_OF_MAC_TABLE)
1617 return;
1618
1619 offset =
1620 MAC_WCID_BASE +
51126deb 1621 ((u8)SetAsicWcid.WCID) *
66cd8d6e
BZ
1622 HW_WCID_ENTRY_SIZE;
1623
1624 DBGPRINT_RAW(RT_DEBUG_TRACE,
1625 ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n",
1626 SetAsicWcid.WCID,
1627 SetAsicWcid.SetTid,
1628 SetAsicWcid.DeleteTid));
1629 MACValue =
1630 (pAd->MacTab.
1631 Content[SetAsicWcid.WCID].
1632 Addr[3] << 24) +
1633 (pAd->MacTab.
1634 Content[SetAsicWcid.WCID].
1635 Addr[2] << 16) +
1636 (pAd->MacTab.
1637 Content[SetAsicWcid.WCID].
1638 Addr[1] << 8) +
1639 (pAd->MacTab.
1640 Content[SetAsicWcid.WCID].Addr[0]);
1641 DBGPRINT_RAW(RT_DEBUG_TRACE,
1642 ("1-MACValue= %x,\n",
1643 MACValue));
1644 RTUSBWriteMACRegister(pAd, offset,
1645 MACValue);
9f548a2a 1646 /* Read bitmask */
66cd8d6e
BZ
1647 RTUSBReadMACRegister(pAd, offset + 4,
1648 &MACRValue);
1649 if (SetAsicWcid.DeleteTid != 0xffffffff)
1650 MACRValue &=
1651 (~SetAsicWcid.DeleteTid);
1652 if (SetAsicWcid.SetTid != 0xffffffff)
1653 MACRValue |=
1654 (SetAsicWcid.SetTid);
1655 MACRValue &= 0xffff0000;
1656
1657 MACValue =
1658 (pAd->MacTab.
1659 Content[SetAsicWcid.WCID].
1660 Addr[5] << 8) +
1661 pAd->MacTab.Content[SetAsicWcid.
1662 WCID].Addr[4];
1663 MACValue |= MACRValue;
1664 RTUSBWriteMACRegister(pAd, offset + 4,
1665 MACValue);
1666
1667 DBGPRINT_RAW(RT_DEBUG_TRACE,
1668 ("2-MACValue= %x,\n",
1669 MACValue));
1670 }
1671 break;
1672
1673 case CMDTHREAD_SET_ASIC_WCID_CIPHER:
1674 {
62eb734b 1675 struct rt_set_asic_wcid_attri SetAsicWcidAttri;
51126deb
BZ
1676 u16 offset;
1677 u32 MACRValue = 0;
66cd8d6e
BZ
1678 SHAREDKEY_MODE_STRUC csr1;
1679 SetAsicWcidAttri =
62eb734b 1680 *((struct rt_set_asic_wcid_attri *)
66cd8d6e
BZ
1681 (pData));
1682
1683 if (SetAsicWcidAttri.WCID >=
1684 MAX_LEN_OF_MAC_TABLE)
1685 return;
1686
1687 offset =
1688 MAC_WCID_ATTRIBUTE_BASE +
51126deb 1689 ((u8)SetAsicWcidAttri.WCID) *
66cd8d6e
BZ
1690 HW_WCID_ATTRI_SIZE;
1691
1692 DBGPRINT_RAW(RT_DEBUG_TRACE,
1693 ("Cmd : CMDTHREAD_SET_ASIC_WCID_CIPHER : WCID = %ld, Cipher = %lx.\n",
1694 SetAsicWcidAttri.WCID,
1695 SetAsicWcidAttri.Cipher));
9f548a2a 1696 /* Read bitmask */
66cd8d6e
BZ
1697 RTUSBReadMACRegister(pAd, offset,
1698 &MACRValue);
1699 MACRValue = 0;
1700 MACRValue |=
51126deb 1701 (((u8)SetAsicWcidAttri.
66cd8d6e
BZ
1702 Cipher) << 1);
1703
1704 RTUSBWriteMACRegister(pAd, offset,
1705 MACRValue);
1706 DBGPRINT_RAW(RT_DEBUG_TRACE,
1707 ("2-offset = %x , MACValue= %x,\n",
1708 offset, MACRValue));
1709
1710 offset =
1711 PAIRWISE_IVEIV_TABLE_BASE +
51126deb 1712 ((u8)SetAsicWcidAttri.WCID) *
66cd8d6e
BZ
1713 HW_IVEIV_ENTRY_SIZE;
1714 MACRValue = 0;
1715 if ((SetAsicWcidAttri.Cipher <=
1716 CIPHER_WEP128))
1717 MACRValue |=
1718 (pAd->StaCfg.
1719 DefaultKeyId << 30);
1720 else
1721 MACRValue |= (0x20000000);
1722 RTUSBWriteMACRegister(pAd, offset,
1723 MACRValue);
1724 DBGPRINT_RAW(RT_DEBUG_TRACE,
1725 ("2-offset = %x , MACValue= %x,\n",
1726 offset, MACRValue));
1727
9f548a2a
BZ
1728 /* */
1729 /* Update cipher algorithm. WSTA always use BSS0 */
1730 /* */
1731 /* for adhoc mode only ,because wep status slow than add key, when use zero config */
66cd8d6e
BZ
1732 if (pAd->StaCfg.BssType == BSS_ADHOC) {
1733 offset =
1734 MAC_WCID_ATTRIBUTE_BASE;
1735
1736 RTUSBReadMACRegister(pAd,
1737 offset,
1738 &MACRValue);
1739 MACRValue &= (~0xe);
1740 MACRValue |=
51126deb 1741 (((u8)SetAsicWcidAttri.
66cd8d6e
BZ
1742 Cipher) << 1);
1743
1744 RTUSBWriteMACRegister(pAd,
1745 offset,
1746 MACRValue);
1747
9f548a2a 1748 /*Update group key cipher,,because wep status slow than add key, when use zero config */
66cd8d6e
BZ
1749 RTUSBReadMACRegister(pAd,
1750 SHARED_KEY_MODE_BASE
1751 +
1752 4 * (0 /
1753 2),
1754 &csr1.
1755 word);
1756
1757 csr1.field.Bss0Key0CipherAlg =
1758 SetAsicWcidAttri.Cipher;
1759 csr1.field.Bss0Key1CipherAlg =
1760 SetAsicWcidAttri.Cipher;
1761
1762 RTUSBWriteMACRegister(pAd,
1763 SHARED_KEY_MODE_BASE
1764 +
1765 4 * (0 /
1766 2),
1767 csr1.
1768 word);
ca97b838 1769 }
66cd8d6e
BZ
1770 }
1771 break;
ca97b838 1772
9f548a2a
BZ
1773/*Benson modified for USB interface, avoid in interrupt when write key, 20080724 --> */
1774 case RT_CMD_SET_KEY_TABLE: /*General call for AsicAddPairwiseKeyEntry() */
66cd8d6e 1775 {
62eb734b 1776 struct rt_add_pairwise_key_entry KeyInfo;
66cd8d6e 1777 KeyInfo =
62eb734b 1778 *((struct rt_add_pairwise_key_entry *)
66cd8d6e
BZ
1779 (pData));
1780 AsicAddPairwiseKeyEntry(pAd,
1781 KeyInfo.MacAddr,
51126deb 1782 (u8)KeyInfo.
66cd8d6e
BZ
1783 MacTabMatchWCID,
1784 &KeyInfo.
1785 CipherKey);
1786 }
1787 break;
1788
9f548a2a 1789 case RT_CMD_SET_RX_WCID_TABLE: /*General call for RTMPAddWcidAttributeEntry() */
66cd8d6e 1790 {
62eb734b 1791 struct rt_mac_table_entry *pEntry;
51126deb
BZ
1792 u8 KeyIdx = 0;
1793 u8 CipherAlg = CIPHER_NONE;
1794 u8 ApIdx = BSS0;
66cd8d6e 1795
62eb734b 1796 pEntry = (struct rt_mac_table_entry *)(pData);
66cd8d6e
BZ
1797
1798 RTMPAddWcidAttributeEntry(pAd,
1799 ApIdx,
1800 KeyIdx,
1801 CipherAlg,
1802 pEntry);
1803 }
1804 break;
9f548a2a 1805/*Benson modified for USB interface, avoid in interrupt when write key, 20080724 <-- */
ca97b838 1806
66cd8d6e
BZ
1807 case CMDTHREAD_SET_CLIENT_MAC_ENTRY:
1808 {
62eb734b
BZ
1809 struct rt_mac_table_entry *pEntry;
1810 pEntry = (struct rt_mac_table_entry *)pData;
c55519ff 1811
66cd8d6e
BZ
1812 {
1813 AsicRemovePairwiseKeyEntry(pAd,
1814 pEntry->
1815 apidx,
51126deb 1816 (u8)
66cd8d6e
BZ
1817 pEntry->
1818 Aid);
1819 if ((pEntry->AuthMode <=
1820 Ndis802_11AuthModeAutoSwitch)
1821 && (pEntry->WepStatus ==
1822 Ndis802_11Encryption1Enabled))
c55519ff 1823 {
51126deb
BZ
1824 u32 uIV = 1;
1825 u8 *ptr;
66cd8d6e 1826
51126deb 1827 ptr = (u8 *)& uIV;
66cd8d6e
BZ
1828 *(ptr + 3) =
1829 (pAd->StaCfg.
1830 DefaultKeyId << 6);
1831 AsicUpdateWCIDIVEIV(pAd,
1832 pEntry->
1833 Aid,
1834 uIV,
1835 0);
1836 AsicUpdateWCIDAttribute
1837 (pAd, pEntry->Aid,
1838 BSS0,
1839 pAd->
1840 SharedKey[BSS0]
1841 [pAd->StaCfg.
1842 DefaultKeyId].
1843 CipherAlg, FALSE);
1844 } else if (pEntry->AuthMode ==
1845 Ndis802_11AuthModeWPANone)
1846 {
51126deb
BZ
1847 u32 uIV = 1;
1848 u8 *ptr;
66cd8d6e 1849
51126deb 1850 ptr = (u8 *)& uIV;
66cd8d6e
BZ
1851 *(ptr + 3) =
1852 (pAd->StaCfg.
1853 DefaultKeyId << 6);
1854 AsicUpdateWCIDIVEIV(pAd,
1855 pEntry->
1856 Aid,
1857 uIV,
1858 0);
1859 AsicUpdateWCIDAttribute
1860 (pAd, pEntry->Aid,
1861 BSS0,
1862 pAd->
1863 SharedKey[BSS0]
1864 [pAd->StaCfg.
1865 DefaultKeyId].
1866 CipherAlg, FALSE);
1867 } else {
9f548a2a
BZ
1868 /* */
1869 /* Other case, disable engine. */
1870 /* Don't worry WPA key, we will add WPA Key after 4-Way handshaking. */
1871 /* */
51126deb 1872 u16 offset;
66cd8d6e
BZ
1873 offset =
1874 MAC_WCID_ATTRIBUTE_BASE
1875 +
1876 (pEntry->Aid *
1877 HW_WCID_ATTRI_SIZE);
9f548a2a 1878 /* RX_PKEY_MODE:0 for no security; RX_KEY_TAB:0 for shared key table; BSS_IDX:0 */
66cd8d6e
BZ
1879 RTUSBWriteMACRegister
1880 (pAd, offset, 0);
c55519ff 1881 }
c55519ff 1882 }
66cd8d6e
BZ
1883
1884 AsicUpdateRxWCIDTable(pAd, pEntry->Aid,
1885 pEntry->Addr);
1886 DBGPRINT(RT_DEBUG_TRACE,
1887 ("UpdateRxWCIDTable(): Aid=%d, Addr=%02x:%02x:%02x:%02x:%02x:%02x!\n",
1888 pEntry->Aid, pEntry->Addr[0],
1889 pEntry->Addr[1],
1890 pEntry->Addr[2],
1891 pEntry->Addr[3],
1892 pEntry->Addr[4],
1893 pEntry->Addr[5]));
1894 }
1895 break;
ca97b838 1896
9f548a2a 1897/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */
66cd8d6e
BZ
1898 case CMDTHREAD_UPDATE_PROTECT:
1899 {
1900 AsicUpdateProtect(pAd, 0,
1901 (ALLN_SETPROTECT),
1902 TRUE, 0);
1903 }
1904 break;
9f548a2a 1905/* end johnli */
ca97b838 1906
66cd8d6e
BZ
1907 case OID_802_11_ADD_WEP:
1908 {
51126deb
BZ
1909 u32 i;
1910 u32 KeyIdx;
62eb734b 1911 struct rt_ndis_802_11_wep *pWepKey;
66cd8d6e
BZ
1912
1913 DBGPRINT(RT_DEBUG_TRACE,
1914 ("CmdThread::OID_802_11_ADD_WEP \n"));
1915
62eb734b 1916 pWepKey = (struct rt_ndis_802_11_wep *)pData;
66cd8d6e
BZ
1917 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
1918
9f548a2a 1919 /* it is a shared key */
66cd8d6e
BZ
1920 if ((KeyIdx >= 4)
1921 || ((pWepKey->KeyLength != 5)
1922 && (pWepKey->KeyLength !=
1923 13))) {
1924 NdisStatus =
1925 NDIS_STATUS_INVALID_DATA;
1926 DBGPRINT(RT_DEBUG_ERROR,
1927 ("CmdThread::OID_802_11_ADD_WEP, INVALID_DATA!!\n"));
1928 } else {
51126deb 1929 u8 CipherAlg;
66cd8d6e
BZ
1930 pAd->SharedKey[BSS0][KeyIdx].
1931 KeyLen =
51126deb 1932 (u8)pWepKey->KeyLength;
66cd8d6e
BZ
1933 NdisMoveMemory(pAd->
1934 SharedKey[BSS0]
1935 [KeyIdx].Key,
1936 &pWepKey->
1937 KeyMaterial,
1938 pWepKey->
1939 KeyLength);
1940 CipherAlg =
1941 (pAd->
1942 SharedKey[BSS0][KeyIdx].
1943 KeyLen ==
1944 5) ? CIPHER_WEP64 :
1945 CIPHER_WEP128;
c55519ff 1946
9f548a2a
BZ
1947 /* */
1948 /* Change the WEP cipher to CKIP cipher if CKIP KP on. */
1949 /* Funk UI or Meetinghouse UI will add ckip key from this path. */
1950 /* */
c55519ff 1951
66cd8d6e
BZ
1952 if (pAd->OpMode == OPMODE_STA) {
1953 pAd->MacTab.
1954 Content[BSSID_WCID].
1955 PairwiseKey.
1956 CipherAlg =
1957 pAd->
1958 SharedKey[BSS0]
1959 [KeyIdx].CipherAlg;
1960 pAd->MacTab.
1961 Content[BSSID_WCID].
1962 PairwiseKey.KeyLen =
1963 pAd->
1964 SharedKey[BSS0]
1965 [KeyIdx].KeyLen;
c55519ff 1966 }
66cd8d6e
BZ
1967 pAd->SharedKey[BSS0][KeyIdx].
1968 CipherAlg = CipherAlg;
1969 if (pWepKey->
1970 KeyIndex & 0x80000000) {
9f548a2a 1971 /* Default key for tx (shared key) */
51126deb
BZ
1972 u8 IVEIV[8];
1973 u32 WCIDAttri, Value;
1974 u16 offset, offset2;
66cd8d6e
BZ
1975 NdisZeroMemory(IVEIV,
1976 8);
1977 pAd->StaCfg.
1978 DefaultKeyId =
51126deb 1979 (u8)KeyIdx;
9f548a2a
BZ
1980 /* Add BSSID to WCTable. because this is Tx wep key. */
1981 /* WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0 */
66cd8d6e
BZ
1982 WCIDAttri =
1983 (CipherAlg << 1) |
1984 SHAREDKEYTABLE;
1985
1986 offset =
1987 MAC_WCID_ATTRIBUTE_BASE
1988 +
1989 (BSSID_WCID *
1990 HW_WCID_ATTRI_SIZE);
1991 RTUSBWriteMACRegister
1992 (pAd, offset,
1993 WCIDAttri);
9f548a2a
BZ
1994 /* 1. IV/EIV */
1995 /* Specify key index to find shared key. */
51126deb 1996 IVEIV[3] = (u8)(KeyIdx << 6); /*WEP Eiv bit off. groupkey index is not 0 */
66cd8d6e
BZ
1997 offset =
1998 PAIRWISE_IVEIV_TABLE_BASE
1999 +
2000 (BSS0Mcast_WCID *
2001 HW_IVEIV_ENTRY_SIZE);
2002 offset2 =
2003 PAIRWISE_IVEIV_TABLE_BASE
2004 +
2005 (BSSID_WCID *
2006 HW_IVEIV_ENTRY_SIZE);
2007 for (i = 0; i < 8;) {
2008 Value =
2009 IVEIV[i];
2010 Value +=
2011 (IVEIV
2012 [i +
2013 1] << 8);
2014 Value +=
2015 (IVEIV
2016 [i +
2017 2] << 16);
2018 Value +=
2019 (IVEIV
2020 [i +
2021 3] << 24);
2022 RTUSBWriteMACRegister
2023 (pAd,
2024 offset + i,
2025 Value);
2026 RTUSBWriteMACRegister
2027 (pAd,
2028 offset2 +
2029 i, Value);
2030 i += 4;
c55519ff 2031 }
ca97b838 2032
9f548a2a 2033 /* 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0 */
66cd8d6e
BZ
2034 WCIDAttri =
2035 (pAd->
2036 SharedKey[BSS0]
2037 [KeyIdx].
2038 CipherAlg << 1) |
2039 SHAREDKEYTABLE;
2040 offset =
2041 MAC_WCID_ATTRIBUTE_BASE
2042 +
2043 (BSS0Mcast_WCID *
2044 HW_WCID_ATTRI_SIZE);
2045 DBGPRINT(RT_DEBUG_TRACE,
2046 ("BSS0Mcast_WCID : offset = %x, WCIDAttri = %x\n",
2047 offset,
2048 WCIDAttri));
2049 RTUSBWriteMACRegister
2050 (pAd, offset,
2051 WCIDAttri);
ca97b838 2052
66cd8d6e
BZ
2053 }
2054 AsicAddSharedKeyEntry(pAd, BSS0,
51126deb 2055 (u8)
66cd8d6e
BZ
2056 KeyIdx,
2057 CipherAlg,
2058 pWepKey->
2059 KeyMaterial,
2060 NULL,
2061 NULL);
2062 DBGPRINT(RT_DEBUG_TRACE,
2063 ("CmdThread::OID_802_11_ADD_WEP (KeyIdx=%d, Len=%d-byte)\n",
2064 KeyIdx,
2065 pWepKey->KeyLength));
ca97b838 2066 }
66cd8d6e
BZ
2067 }
2068 break;
2069
2070 case CMDTHREAD_802_11_COUNTER_MEASURE:
2071 break;
2072
2073 case CMDTHREAD_SET_GROUP_KEY:
2074 WpaStaGroupKeySetting(pAd);
2075 break;
2076
2077 case CMDTHREAD_SET_PAIRWISE_KEY:
2078 WpaStaPairwiseKeySetting(pAd);
2079 break;
2080
2081 case CMDTHREAD_SET_PSM_BIT:
2082 {
51126deb 2083 u16 *pPsm = (u16 *) pData;
66cd8d6e
BZ
2084 MlmeSetPsmBit(pAd, *pPsm);
2085 }
2086 break;
2087 case CMDTHREAD_FORCE_WAKE_UP:
2088 AsicForceWakeup(pAd, TRUE);
2089 break;
2090
2091 default:
2092 DBGPRINT(RT_DEBUG_ERROR,
2093 ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n",
2094 cmdqelmt->command));
2095 break;
c55519ff
GKH
2096 }
2097 }
2098
66cd8d6e
BZ
2099 if (cmdqelmt->CmdFromNdis == TRUE) {
2100 if (cmdqelmt->buffer != NULL)
ca97b838
BZ
2101 os_free_mem(pAd, cmdqelmt->buffer);
2102 os_free_mem(pAd, cmdqelmt);
66cd8d6e
BZ
2103 } else {
2104 if ((cmdqelmt->buffer != NULL)
2105 && (cmdqelmt->bufferlength != 0))
ca97b838
BZ
2106 os_free_mem(pAd, cmdqelmt->buffer);
2107 os_free_mem(pAd, cmdqelmt);
c55519ff 2108 }
66cd8d6e 2109 } /* end of while */
c55519ff
GKH
2110}
2111
9f548a2a 2112#endif /* RTMP_MAC_USB // */