2 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
3 * Copyright (c) 2007-2008 Atheros Communications Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 /* Module Name : ud.c */
21 /* This module contains USB descriptor functions. */
26 /************************************************************************/
27 #include "../80211core/cprecomp.h"
31 extern void zfwUsbCmd(zdev_t
* dev
, u8_t endpt
, u32_t
* cmd
, u16_t cmdLen
);
33 extern void zfIdlRsp(zdev_t
* dev
, u32_t
* rsp
, u16_t rspLen
);
34 extern u16_t
zfDelayWriteInternalReg(zdev_t
* dev
, u32_t addr
, u32_t val
);
35 extern u16_t
zfFlushDelayWrite(zdev_t
* dev
);
38 #define USB_ENDPOINT_TX_INDEX 1
39 #define USB_ENDPOINT_RX_INDEX 2
40 #define USB_ENDPOINT_INT_INDEX 3
41 #define USB_ENDPOINT_CMD_INDEX 4
43 void zfIdlCmd(zdev_t
* dev
, u32_t
* cmd
, u16_t cmdLen
)
45 #if ZM_SW_LOOP_BACK != 1
46 zfwUsbCmd(dev
, USB_ENDPOINT_CMD_INDEX
, cmd
, cmdLen
);
53 /* zfAdjustCtrlSetting: fit OUTS format */
54 /* convert MIMO2 to OUTS */
55 void zfAdjustCtrlSetting(zdev_t
* dev
, u16_t
* header
, zbuf_t
* buf
)
57 /* MIMO2 => OUTS FB-50 */
58 /* length not change, only modify format */
67 struct zsHpPriv
* hpPriv
;
69 zmw_get_wlan_dev(dev
);
75 oldPhyCtrl
= zmw_buf_readh(dev
, buf
, 4) | ((u32_t
)zmw_buf_readh(dev
, buf
, 6) << 16);
79 oldPhyCtrl
= header
[2] | ((u32_t
)header
[3] <<16);
86 oldMT
= oldPhyCtrl
&0x3;
88 if ( oldMT
== 0x3 ) /* DL-OFDM (Duplicate Legacy OFDM) */
92 /* PT : Bit[2] HT PT: 0 Mixed mode 1 Green field */
93 phyCtrl
|= (oldPhyCtrl
&0x4);
95 /* Bandwidth control : Bit[4~3] */
96 if ( oldPhyCtrl
&0x800000 ) /* Bit23 : 40M */
98 if (oldMT
== 0x2 && ((struct zsHpPriv
*)wd
->hpPrivate
)->hwBw40
)
100 phyCtrl
|= (0x2<<3); /* 40M shared */
104 oldPhyCtrl
&= ~0x80000000;
107 /* MCS : Bit[24~18] */
108 oldMCS
= (oldPhyCtrl
&0x7f0000)>>16; /* Bit[22~16] */
109 phyCtrl
|= (oldMCS
<<18);
111 /* Short GI : Bit[31]*/
112 phyCtrl
|= (oldPhyCtrl
&0x80000000);
114 /* AM : Antenna mask */
115 //if ((oldMT == 2) && (oldMCS > 7))
116 if (hpPriv
->halCapability
& ZM_HP_CAP_11N_ONE_TX_STREAM
)
118 phyCtrl
|= (0x1<<15);
123 /* OFDM 6M/9M/12M/18M/24M Tx 2 chain */
124 /* OFDM 36M/48M/54M/ Tx 1 chain */
126 if ((oldMT
== 2) || (oldMT
== 3))
128 phyCtrl
|= (0x5<<15);
132 if ((oldMCS
== 0xb) || (oldMCS
== 0xf) ||
133 (oldMCS
== 0xa) || (oldMCS
== 0xe) ||
134 (oldMCS
== 0x9)) //6M/9M/12M/18M/24M
136 phyCtrl
|= (0x5<<15);
140 phyCtrl
|= (0x1<<15);
145 phyCtrl
|= (0x5<<15);
149 // phyCtrl |= (0x1<<15);
152 /* TODO : accelerating these code */
153 if (hpPriv
->hwFrequency
< 3000)
158 tpc
= (hpPriv
->tPow2xCck
[oldMCS
]&0x3f);
165 tpc
= (hpPriv
->tPow2x2g
[3]&0x3f);
167 else if (oldMCS
== 0x8)
169 tpc
= (hpPriv
->tPow2x2g
[2]&0x3f);
171 else if (oldMCS
== 0xd)
173 tpc
= (hpPriv
->tPow2x2g
[1]&0x3f);
175 else if (oldMCS
== 0x9)
177 tpc
= ((hpPriv
->tPow2x2g
[0]-hpPriv
->tPow2x2g24HeavyClipOffset
)&0x3f);
181 tpc
= (hpPriv
->tPow2x2g
[0]&0x3f);
186 if ( oldPhyCtrl
&0x800000 ) /* Bit23 : 40M */
189 tpc
= (hpPriv
->tPow2x2gHt40
[oldMCS
&0x7]&0x3f);
194 tpc
= (hpPriv
->tPow2x2gHt20
[oldMCS
&0x7]&0x3f);
205 tpc
= (hpPriv
->tPow2x5g
[3]&0x3f);
207 else if (oldMCS
== 0x8)
209 tpc
= (hpPriv
->tPow2x5g
[2]&0x3f);
211 else if (oldMCS
== 0xd)
213 tpc
= (hpPriv
->tPow2x5g
[1]&0x3f);
217 tpc
= (hpPriv
->tPow2x5g
[0]&0x3f);
222 if ( oldPhyCtrl
&0x800000 ) /* Bit23 : 40M */
225 tpc
= (hpPriv
->tPow2x5gHt40
[oldMCS
&0x7]&0x3f);
230 tpc
= (hpPriv
->tPow2x5gHt20
[oldMCS
&0x7]&0x3f);
235 /* Tx power adjust for HT40 */
237 if ((oldMT
==2) && (oldPhyCtrl
&0x800000) )
243 /* Evl force tx TPC */
246 tpc
= (u16_t
)(wd
->forceTxTPC
& 0x3f);
249 if (hpPriv
->hwFrequency
< 3000) {
250 wd
->maxTxPower2
&= 0x3f;
251 tpc
= (tpc
> wd
->maxTxPower2
)? wd
->maxTxPower2
: tpc
;
253 wd
->maxTxPower5
&= 0x3f;
254 tpc
= (tpc
> wd
->maxTxPower5
)? wd
->maxTxPower5
: tpc
;
259 #define ZM_TPC_OFFSET 5
260 #define ZM_SIGNAL_THRESHOLD 56
261 if ((wd
->sta
.bScheduleScan
== FALSE
) && (wd
->sta
.bChannelScan
== FALSE
))
263 if (( wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)
264 && (zfStaIsConnected(dev
))
265 && (wd
->SignalStrength
> ZM_SIGNAL_THRESHOLD
))
267 if (tpc
> ((ZM_MIN_TPC
+ZM_TPC_OFFSET
)*2))
269 tpc
-= (ZM_TPC_OFFSET
*2);
271 else if (tpc
> (ZM_MIN_TPC
*2))
273 tpc
= (ZM_MIN_TPC
*2);
279 #undef ZM_SIGNAL_THRESHOLD
281 #ifndef ZM_OTUS_LINUX_PHASE_2
282 phyCtrl
|= (tpc
& 0x3f) << 9;
285 /* Set bits[8:6]BF-MCS for heavy clip */
286 if ((phyCtrl
&0x3) == 2)
288 phyCtrl
|= ((phyCtrl
>> 12) & 0x1c0);
294 zmw_buf_writeh(dev
, buf
, 4, (u16_t
) (phyCtrl
&0xffff));
295 zmw_buf_writeh(dev
, buf
, 6, (u16_t
) (phyCtrl
>>16));
300 header
[2] = (u16_t
) (phyCtrl
&0xffff);
302 header
[3] = (u16_t
) (phyCtrl
>>16);
305 zm_msg2_tx(ZM_LV_2
, "old phy ctrl = ", oldPhyCtrl
);
306 zm_msg2_tx(ZM_LV_2
, "new phy ctrl = ", phyCtrl
);
307 //DbgPrint("old phy ctrl =%08x \n", oldPhyCtrl);
308 //DbgPrint("new phy ctrl =%08x \n", phyCtrl);
312 #define EXTRA_INFO_LEN 24 //RSSI(7) + EVM(12) + PHY(1) + MACStatus(4)
313 u16_t
zfHpSend(zdev_t
* dev
, u16_t
* header
, u16_t headerLen
,
314 u16_t
* snap
, u16_t snapLen
,
315 u16_t
* tail
, u16_t tailLen
, zbuf_t
* buf
, u16_t offset
,
316 u16_t bufType
, u8_t ac
, u8_t keyIdx
)
318 #if ZM_SW_LOOP_BACK == 1
326 #endif /* #if ZM_SW_LOOP_BACK == 1 */
327 struct zsHpPriv
* hpPriv
;
329 zmw_get_wlan_dev(dev
);
330 hpPriv
=wd
->hpPrivate
;
332 zm_msg1_tx(ZM_LV_1
, "zfHpSend(), len = ", 12 + headerLen
-8 + snapLen
+ zfwBufGetSize(dev
, buf
) + 4 + 8);
334 /* Adjust ctrl setting : 6N14 yjsung */
335 zfAdjustCtrlSetting(dev
, header
, buf
);
337 #if ZM_SW_LOOP_BACK != 1
338 hpPriv
->usbSendBytes
+= zfwBufGetSize(dev
, buf
);
339 hpPriv
->usbAcSendBytes
[ac
&0x3] += zfwBufGetSize(dev
, buf
);
341 /* Submit USB Out Urb */
342 zfwUsbSend(dev
, USB_ENDPOINT_TX_INDEX
, (u8_t
*)header
, headerLen
,
343 (u8_t
*)snap
, snapLen
, (u8_t
*)tail
, tailLen
, buf
, offset
);
346 #if ZM_SW_LOOP_BACK == 1
348 rxbuf
= zfwBufAllocate(dev
, plcplen
+ headerLen
-8 + snapLen
+ (zfwBufGetSize(dev
, buf
)-offset
) + 4 + EXTRA_INFO_LEN
);
349 pHdr
= (u8_t
*) header
+8;
350 psnap
= (u8_t
*) snap
;
352 zmw_enter_critical_section(dev
);
353 /* software loop back */
354 /* Copy WLAN header and packet buffer */
355 swlpOffset
= plcplen
;
357 for(i
= 0; i
< headerLen
-8; i
++)
359 zmw_rx_buf_writeb(dev
, rxbuf
, swlpOffset
+i
, pHdr
[i
]);
362 swlpOffset
+= headerLen
-8;
364 /* Copy SNAP header */
365 for(i
= 0; i
< snapLen
; i
++)
367 zmw_rx_buf_writeb(dev
, rxbuf
, swlpOffset
+i
, psnap
[i
]);
370 swlpOffset
+= snapLen
;
372 /* Copy body from tx buf to rxbuf */
373 for(i
= 0; i
< (zfwBufGetSize(dev
, buf
)-offset
); i
++)
375 u8_t value
= zmw_rx_buf_readb(dev
, buf
, i
+offset
);
376 zmw_rx_buf_writeb(dev
, rxbuf
, swlpOffset
+i
, value
);
379 /* total length = PLCP + MacHeader + Payload + FCS + RXstatus */
380 /* 12 + headerLen-8 + snapLen + buf length + 4 + 8 */
381 zfwSetBufSetSize(dev
, rxbuf
, swlpOffset
+ (zfwBufGetSize(dev
, buf
)-offset
) + 4 + EXTRA_INFO_LEN
);
383 zmw_leave_critical_section(dev
);
385 zfwBufFree(dev
, buf
, 0);
387 //zfwDumpBuf(dev, rxbuf);
388 //-------------------------------------------------
390 //zfCoreRecv(dev, rxbuf);
392 #endif /* #if ZM_SW_LOOP_BACK */
397 /* Report moniter Hal rx information about rssi, evm, bandwidth, SG etc */
398 void zfHpQueryMonHalRxInfo(zdev_t
* dev
, u8_t
*monHalRxInfo
)
400 zmw_get_wlan_dev(dev
);
401 zfMemoryCopy(monHalRxInfo
,
402 (u8_t
*)&(((struct zsHpPriv
*)wd
->hpPrivate
)->halRxInfo
),
403 sizeof(struct zsHalRxInfo
));
407 u8_t
zfIsDataFrame(zdev_t
* dev
, zbuf_t
* buf
)
412 mpduInd
= zmw_rx_buf_readb(dev
, buf
, zfwBufGetSize(dev
, buf
)-1);
414 /* sinlge or First */
415 if ((mpduInd
& 0x30) == 0x00 || (mpduInd
& 0x30) == 0x20)
417 frameType
= zmw_rx_buf_readb(dev
, buf
, 12);
421 frameType
= zmw_rx_buf_readb(dev
, buf
, 0);
424 if((frameType
& 0xf) == ZM_WLAN_DATA_FRAME
)
430 u32_t
zfcConvertRateOFDM(zdev_t
* dev
, zbuf_t
* buf
)
432 // What's the default value??
435 switch(zmw_rx_buf_readb(dev
, buf
, 0)& 0xf)
465 u16_t
zfHpGetPayloadLen(zdev_t
* dev
,
475 u8_t modulation
,mpduInd
;
476 u16_t low
, high
, msb
;
477 s16_t payloadLen
= 0;
479 zmw_get_wlan_dev(dev
);
481 mpduInd
= zmw_rx_buf_readb(dev
, buf
, len
-1);
482 modulation
= zmw_rx_buf_readb(dev
, buf
, (len
-1)) & 0x3;
485 //zm_debug_msg1(" modulation= ", modulation);
486 switch (modulation
) {
487 case 0: /* CCK Mode */
488 low
= zmw_rx_buf_readb(dev
, buf
, 2);
489 high
= zmw_rx_buf_readb(dev
, buf
, 3);
490 payloadLen
= (low
| high
<< 8) - 4;
491 if (wd
->enableHALDbgInfo
)
493 *rxMCS
= zmw_rx_buf_readb(dev
, buf
, 0);
498 case 1: /* Legacy-OFDM mode */
499 low
= zmw_rx_buf_readb(dev
, buf
, 0) >> 5;
500 high
= zmw_rx_buf_readb(dev
, buf
, 1);
501 msb
= zmw_rx_buf_readb(dev
, buf
, 2) & 0x1;
502 payloadLen
= (low
| (high
<< 3) | (msb
<< 11)) - 4;
503 if (wd
->enableHALDbgInfo
)
505 *rxMCS
= zfcConvertRateOFDM(dev
, buf
);
510 case 2: /* HT OFDM mode */
511 //zm_debug_msg1("aggregation= ", (zmw_rx_buf_readb(dev, buf, 6) >> 3) &0x1 );
512 if ((mpduInd
& 0x30) == 0x00 || (mpduInd
& 0x30) == 0x10) //single or last mpdu
513 payloadLen
= len
- 24 - 4 - plcpHdrLen
; // - rxStatus - fcs
515 payloadLen
= len
- 4 - 4 - plcpHdrLen
; // - rxStatus - fcs
516 //zm_debug_msg1("first or middle mpdu, plcpHdrLen= ", plcpHdrLen);
518 if (wd
->enableHALDbgInfo
)
520 *rxMCS
= zmw_rx_buf_readb(dev
, buf
, 3) & 0x7f;
521 *rxBW
= (zmw_rx_buf_readb(dev
, buf
, 3) >> 7) & 0x1;
522 *rxSG
= (zmw_rx_buf_readb(dev
, buf
, 6) >> 7) & 0x1;
529 /* return the payload length - FCS */
530 if (payloadLen
< 0) payloadLen
= 0;
534 /************************************************************************/
536 /* FUNCTION DESCRIPTION zfiUsbRecv */
537 /* Callback function for USB IN Transfer. */
540 /* dev: device pointer */
546 /* Yuan-Gu Wei ZyDAS Technology Corporation 2005.10 */
548 /************************************************************************/
549 #define ZM_INT_USE_EP2 1
550 #define ZM_INT_USE_EP2_HEADER_SIZE 12
552 #if ZM_INT_USE_EP2 == 1
553 void zfiUsbRegIn(zdev_t
* dev
, u32_t
* rsp
, u16_t rspLen
);
556 #ifdef ZM_OTUS_RX_STREAM_MODE
557 void zfiUsbRecvPerPkt(zdev_t
*dev
, zbuf_t
*buf
)
559 void zfiUsbRecv(zdev_t
*dev
, zbuf_t
*buf
)
564 #if ZM_FW_LOOP_BACK != 1
567 u16_t crcPlusRxStatusLen
;
568 u16_t len
, payloadLen
=0;
570 struct zsAdditionInfo addInfo
;
575 struct zsHpPriv
* hpPriv
;
577 zmw_get_wlan_dev(dev
);
578 hpPriv
=wd
->hpPrivate
;
580 //zm_msg0_rx(ZM_LV_0, "zfiUsbRecv()");
582 #if ZM_INT_USE_EP2 == 1
584 for (i
=0; i
<(ZM_INT_USE_EP2_HEADER_SIZE
>>1); i
++)
586 if (zmw_rx_buf_readh(dev
, buf
, i
*2) != 0xffff)
590 if (i
==(ZM_INT_USE_EP2_HEADER_SIZE
>>1))
592 u32_t rsp
[ZM_USB_MAX_EPINT_BUFFER
/4];
595 u8_t
* pdst
= (u8_t
*)rsp
;
598 rspLen
= (u16_t
) zfwBufGetSize(dev
, buf
)-ZM_INT_USE_EP2_HEADER_SIZE
;
602 zm_debug_msg1("Get error len by EP2 = \n", rspLen
);
604 zfwBufFree(dev
, buf
, 0);
608 for (rspi
=0; rspi
<rspLen
; rspi
++)
610 *pdst
= zmw_rx_buf_readb(dev
, buf
, rspi
+ZM_INT_USE_EP2_HEADER_SIZE
);
614 //if (adapter->zfcbUsbRegIn)
615 // adapter->zfcbUsbRegIn(adapter, rsp, rspLen);
616 zfiUsbRegIn(dev
, rsp
, rspLen
);
619 zfwBufFree(dev
, buf
, 0);
622 #endif /* end of #if ZM_INT_USE_EP2 == 1 */
624 ZM_PERFORMANCE_RX_MPDU(dev
, buf
);
628 /* airopeek: Report everything up */
629 if (wd
->zfcbRecv80211
!= NULL
)
631 wd
->zfcbRecv80211(dev
, buf
, NULL
);
635 /* Read the last byte */
636 len
= zfwBufGetSize(dev
, buf
);
637 mpduInd
= zmw_rx_buf_readb(dev
, buf
, len
-1);
640 if((mpduInd
& 0x30) == 0x20)
643 if (zmw_rx_buf_readb(dev
, buf
, 36) == 0) //AC = BE
645 duration
= zmw_rx_buf_readh(dev
, buf
, 14);
646 if (duration
> hpPriv
->aggMaxDurationBE
)
648 hpPriv
->aggMaxDurationBE
= duration
;
652 if (hpPriv
->aggMaxDurationBE
> 10)
654 hpPriv
->aggMaxDurationBE
--;
657 //DbgPrint("aggMaxDurationBE=%d", hpPriv->aggMaxDurationBE);
661 /* First MPDU or Single MPDU */
662 if(((mpduInd
& 0x30) == 0x00) || ((mpduInd
& 0x30) == 0x20))
663 //if ((mpduInd & 0x10) == 0x00)
665 plcpHdrLen
= 12; // PLCP header length
669 if (zmw_rx_buf_readh(dev
, buf
, 4) == wd
->macAddr
[0] &&
670 zmw_rx_buf_readh(dev
, buf
, 6) == wd
->macAddr
[1] &&
671 zmw_rx_buf_readh(dev
, buf
, 8) == wd
->macAddr
[2]) {
674 else if (zmw_rx_buf_readh(dev
, buf
, 16) == wd
->macAddr
[0] &&
675 zmw_rx_buf_readh(dev
, buf
, 18) == wd
->macAddr
[1] &&
676 zmw_rx_buf_readh(dev
, buf
, 20) == wd
->macAddr
[2]){
684 /* Last MPDU or Single MPDU */
685 if ((mpduInd
& 0x30) == 0x00 || (mpduInd
& 0x30) == 0x10)
687 crcPlusRxStatusLen
= EXTRA_INFO_LEN
+ 4; // Extra bytes + FCS
691 crcPlusRxStatusLen
= 4 + 4; // Extra 4 bytes + FCS
694 if (len
< (plcpHdrLen
+10+crcPlusRxStatusLen
))
696 zm_msg1_rx(ZM_LV_0
, "Invalid Rx length=", len
);
697 //zfwDumpBuf(dev, buf);
699 zfwBufFree(dev
, buf
, 0);
703 /* display RSSI combined */
705 * ¢z¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢{
706 * ¢x PLCP Header ¢x MPDU ¢x RSSI ¢x EVM ¢x PHY Err ¢x MAC Status ¢x
707 * ¢u¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢t
708 * ¢x 12 ¢x n ¢x 7 ¢x 12 ¢x 1 ¢x 4 ¢x
709 * ¢|¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢}
710 * RSSI filed (From BB and MAC just pass them to host)
711 * Byte1: RSSI for antenna 0.
712 * Byte2: RSSI for antenna 1.
713 * Byte3: RSSI for antenna 2.
714 * Byte4: RSSI for antenna 0 extension.
715 * Byte5: RSSI for antenna 1 extension.
716 * Byte6: RSSI for antenna 2 extension.
717 * Byte7: RSSI for antenna combined.
720 //zm_debug_msg1(" recv RSSI = ", zmw_rx_buf_readb(dev, buf, (len-1)-17));
722 payloadLen
= zfHpGetPayloadLen(dev
, buf
, len
, plcpHdrLen
, &rxMT
, &rxMCS
, &rxBW
, &rxSG
);
725 /* First MPDU or Single MPDU */
726 if(((mpduInd
& 0x30) == 0x00) || ((mpduInd
& 0x30) == 0x20))
728 if (wd
->enableHALDbgInfo
&& zfIsDataFrame(dev
, buf
))
730 ((struct zsHpPriv
*)wd
->hpPrivate
)->halRxInfo
.currentRxDataMT
= rxMT
;
731 ((struct zsHpPriv
*)wd
->hpPrivate
)->halRxInfo
.currentRxDataMCS
= rxMCS
;
732 ((struct zsHpPriv
*)wd
->hpPrivate
)->halRxInfo
.currentRxDataBW
= rxBW
;
733 ((struct zsHpPriv
*)wd
->hpPrivate
)->halRxInfo
.currentRxDataSG
= rxSG
;
737 if ((plcpHdrLen
+ payloadLen
) > len
) {
738 zm_msg1_rx(ZM_LV_0
, "Invalid payload length=", payloadLen
);
739 zfwBufFree(dev
, buf
, 0);
743 //Store Rx Tail Infomation before Remove--CWYang(+)
746 * Brief format of OUTS chip
747 * ¢z¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢{
748 * ¢x PLCP Header ¢x MPDU ¢x RSSI ¢x EVM ¢x PHY Err ¢x MAC Status ¢x
749 * ¢u¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢w¢w¢w¢q¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢t
750 * ¢x 12 ¢x n ¢x 7 ¢x 12 ¢x 1 ¢x 4 ¢x
751 * ¢|¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢w¢w¢w¢r¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢}
756 * Byte 4 antenna 0 extension
757 * Byte 5 antenna 1 extension
758 * Byte 6 antenna 2 extension
759 * Byte 7 antenna combined
761 * Byte 1 Stream 0 pilot 0
762 * Byte 2 Stream 0 pilot 1
763 * Byte 3 Stream 0 pilot 2
764 * Byte 4 Stream 0 pilot 3
765 * Byte 5 Stream 0 pilot 4
766 * Byte 6 Stream 0 pilot 5
767 * Byte 7 Stream 1 pilot 0
768 * Byte 8 Stream 1 pilot 1
769 * Byte 9 Stream 1 pilot 2
770 * Byte 10 Stream 1 pilot 3
771 * Byte 11 Stream 1 pilot 4
772 * Byte 12 Stream 1 pilot 5
775 /* Fill the Tail information */
776 /* Last MPDU or Single MPDU */
777 if ((mpduInd
& 0x30) == 0x00 || (mpduInd
& 0x30) == 0x10)
779 #define ZM_RX_RSSI_COMPENSATION 27
780 u8_t zm_rx_rssi_compensation
= ZM_RX_RSSI_COMPENSATION
;
782 /* RSSI information */
783 addInfo
.Tail
.Data
.SignalStrength1
= zmw_rx_buf_readb(dev
, buf
,
784 (len
-1) - 17) + ((hpPriv
->rxStrongRSSI
== 1)?zm_rx_rssi_compensation
:0);
785 #undef ZM_RX_RSSI_COMPENSATION
789 /* TODO: for RD/BB debug message */
790 /* save current rx hw infomration, report to DrvCore/Application */
791 if (wd
->enableHALDbgInfo
&& zfIsDataFrame(dev
, buf
))
796 trssi
= zmw_rx_buf_readb(dev
, buf
, (len
-1) - 23 + i
);
799 trssi
= ((~((u8_t
)trssi
) & 0x7f) + 1) & 0x7f;
801 ((struct zsHpPriv
*)wd
->hpPrivate
)->halRxInfo
.currentRSSI
[i
] = trssi
;
809 ((struct zsHpPriv
*)wd
->hpPrivate
)->halRxInfo
.currentRxEVM
[i
] =
810 zmw_rx_buf_readb(dev
, buf
, (len
-1) - 16 + i
);
814 // for (i=0; i<4; i++)
815 // ((struct zsHpPriv*)wd->hpPrivate)->halRxInfo.currentRxEVM[i] =
816 // zmw_rx_buf_readb(dev, buf, (len-1) - 16 + i);
820 } /* if (wd->enableHALDbgInfo && zfIsDataFrame(dev, buf)) */
825 /* Mid or First aggregate frame without phy rx information */
826 addInfo
.Tail
.Data
.SignalStrength1
= 0;
829 addInfo
.Tail
.Data
.SignalStrength2
= 0;
830 addInfo
.Tail
.Data
.SignalStrength3
= 0;
831 addInfo
.Tail
.Data
.SignalQuality
= 0;
833 addInfo
.Tail
.Data
.SAIndex
= zmw_rx_buf_readb(dev
, buf
, len
- 4);
834 addInfo
.Tail
.Data
.DAIndex
= zmw_rx_buf_readb(dev
, buf
, len
- 3);
835 addInfo
.Tail
.Data
.ErrorIndication
= zmw_rx_buf_readb(dev
, buf
, len
- 2);
836 addInfo
.Tail
.Data
.RxMacStatus
= zmw_rx_buf_readb(dev
, buf
, len
- 1);
837 /* Remove CRC and Rx Status */
838 zfwBufSetSize(dev
, buf
, (len
-crcPlusRxStatusLen
));
839 //zfwBufSetSize(dev, buf, payloadLen + plcpHdrLen); /* payloadLen + PLCP 12 - FCS 4*/
841 //Store PLCP Header Infomation before Remove--CWYang(+)
844 for (i
= 0; i
< plcpHdrLen
; i
++)
846 addInfo
.PlcpHeader
[i
] = zmw_rx_buf_readb(dev
, buf
, i
);
851 addInfo
.PlcpHeader
[0] = 0;
853 /* Remove PLCP header */
854 zfwBufRemoveHead(dev
, buf
, plcpHdrLen
);
856 /* handle 802.11 frame */
857 zfCoreRecv(dev
, buf
, &addInfo
);
860 /* Firmware loopback: Rx frame = Tx frame */
861 /* convert Rx frame to fit receive frame format */
863 u8_t ctrl_offset
= 8;
869 /* Tx: | ctrl_setting | Mac hdr | data | */
872 /* Rx: | PLCP | Mac hdr | data | FCS | Rxstatus | */
875 /* new allocate a rx format size buf */
876 new_buf
= zfwBufAllocate(dev
, zfwBufGetSize(dev
, buf
)-8+12+4+EXTRA_INFO_LEN
);
878 for (i
=0; i
<zfwBufGetSize(dev
, buf
)-ctrl_offset
; i
++)
880 data
= zmw_rx_buf_readb(dev
, buf
, ctrl_offset
+i
);
881 zmw_rx_buf_writeb(dev
, new_buf
, PLCP_Len
+i
, data
);
884 zfwBufSetSize(dev
, new_buf
, zfwBufGetSize(dev
, buf
)-8+12+4+EXTRA_INFO_LEN
);
886 zfwBufFree(dev
, buf
, 0);
888 /* receive the new_buf */
889 //zfCoreRecv(dev, new_buf);
895 #ifdef ZM_OTUS_RX_STREAM_MODE
896 void zfiUsbRecv(zdev_t
*dev
, zbuf_t
*buf
)
903 zbuf_t
*rxBufPool
[8];
904 u16_t rxBufPoolIndex
= 0;
905 struct zsHpPriv
*halPriv
;
908 u16_t usbRxRemainLen
;
911 zmw_get_wlan_dev(dev
);
913 halPriv
= (struct zsHpPriv
*)wd
->hpPrivate
;
914 srcBufPtr
= zmw_buf_get_buffer(dev
, buf
);
916 bufferLength
= zfwBufGetSize(dev
, buf
);
918 /* Zero Length Transfer */
921 zfwBufFree(dev
, buf
, 0);
925 usbRxRemainLen
= halPriv
->usbRxRemainLen
;
926 usbRxPktLen
= halPriv
->usbRxTransferLen
;
928 /* Check whether there is any data in the last transfer */
929 if (usbRxRemainLen
!= 0 )
931 zbuf_t
*remainBufPtr
= halPriv
->remainBuf
;
934 if ( remainBufPtr
!= NULL
)
936 BufPtr
= zmw_buf_get_buffer(dev
, remainBufPtr
);
939 index
= usbRxRemainLen
;
940 usbRxRemainLen
-= halPriv
->usbRxPadLen
;
943 if ( BufPtr
!= NULL
)
945 zfwMemoryCopy(&(BufPtr
[usbRxPktLen
]), srcBufPtr
, usbRxRemainLen
);
948 usbRxPktLen
+= usbRxRemainLen
;
949 halPriv
->usbRxRemainLen
= 0;
951 if ( remainBufPtr
!= NULL
)
953 zfwBufSetSize(dev
, remainBufPtr
, usbRxPktLen
);
954 rxBufPool
[rxBufPoolIndex
++] = remainBufPtr
;
956 halPriv
->remainBuf
= NULL
;
959 //zm_debug_msg1("length: %d\n", (int)pUsbRxTransfer->pRxUrb->UrbBulkOrInterruptTransfer.TransferBufferLength);
961 bufferLength
= zfwBufGetSize(dev
, buf
);
962 //printk("bufferLength %d\n", bufferLength);
963 while(index
< bufferLength
)
967 //u8_t *ptr = (u8_t*)((struct zsBuffer*)pUsbRxTransfer->buf)->data;
968 u8_t
*ptr
= srcBufPtr
;
970 /* Retrieve packet length and tag */
971 pktLen
= ptr
[index
] + (ptr
[index
+1] << 8);
972 pktTag
= ptr
[index
+2] + (ptr
[index
+3] << 8);
974 if (pktTag
== ZM_USB_STREAM_MODE_TAG
)
978 zm_assert(pktLen
< ZM_WLAN_MAX_RX_SIZE
);
980 //printk("Get a packet, pktLen: 0x%04x\n", pktLen);
982 /* Calcuate the padding length, in the current design,
983 the length should be padded to 4 byte boundray. */
984 padLen
= ZM_USB_STREAM_MODE_TAG_LEN
- (pktLen
& 0x3);
986 if(padLen
== ZM_USB_STREAM_MODE_TAG_LEN
)
990 index
= index
+ ZM_USB_STREAM_MODE_TAG_LEN
+ pktLen
+ padLen
;
992 if (chkIdx
> ZM_MAX_USB_IN_TRANSFER_SIZE
)
994 zm_debug_msg1("chkIdx is too large, chkIdx: %d\n", chkIdx
);
1000 if (index
> ZM_MAX_USB_IN_TRANSFER_SIZE
)
1002 //struct zsBuffer* BufPtr;
1003 //struct zsBuffer* UsbBufPtr;
1007 halPriv
->usbRxRemainLen
= index
- ZM_MAX_USB_IN_TRANSFER_SIZE
; // - padLen;
1008 halPriv
->usbRxTransferLen
= ZM_MAX_USB_IN_TRANSFER_SIZE
-
1009 chkIdx
- ZM_USB_STREAM_MODE_TAG_LEN
;
1010 halPriv
->usbRxPadLen
= padLen
;
1011 //check_index = index;
1013 if (halPriv
->usbRxTransferLen
> ZM_WLAN_MAX_RX_SIZE
)
1015 zm_debug_msg1("check_len is too large, chk_len: %d\n",
1016 halPriv
->usbRxTransferLen
);
1021 /* Allocate a skb buffer */
1022 newBuf
= zfwBufAllocate(dev
, ZM_WLAN_MAX_RX_SIZE
);
1024 if ( newBuf
!= NULL
)
1026 BufPtr
= zmw_buf_get_buffer(dev
, newBuf
);
1027 UsbBufPtr
= srcBufPtr
;
1029 /* Copy the buffer */
1030 zfwMemoryCopy(BufPtr
, &(UsbBufPtr
[chkIdx
+ZM_USB_STREAM_MODE_TAG_LEN
]), halPriv
->usbRxTransferLen
);
1032 /* Record the buffer pointer */
1033 halPriv
->remainBuf
= newBuf
;
1041 /* Allocate a skb buffer */
1042 newBuf
= zfwBufAllocate(dev
, ZM_WLAN_MAX_RX_SIZE
);
1043 if ( newBuf
!= NULL
)
1045 BufPtr
= zmw_buf_get_buffer(dev
, newBuf
);
1046 UsbBufPtr
= srcBufPtr
;
1048 /* Copy the buffer */
1049 zfwMemoryCopy(BufPtr
, &(UsbBufPtr
[chkIdx
+ZM_USB_STREAM_MODE_TAG_LEN
]), pktLen
);
1051 zfwBufSetSize(dev
, newBuf
, pktLen
);
1052 rxBufPool
[rxBufPoolIndex
++] = newBuf
;
1060 DbgPrint("Can't find tag, pkt_len: 0x%04x, tag: 0x%04x\n",
1069 //zfwBufFree(adapter, pUsbRxTransfer->buf, 0);
1070 zfwBufFree(dev
, buf
, 0);
1072 for(ii
= 0; ii
< rxBufPoolIndex
; ii
++)
1074 zfiUsbRecvPerPkt(dev
, rxBufPool
[ii
]);
1079 /************************************************************************/
1081 /* FUNCTION DESCRIPTION zfUsbInit */
1082 /* Initialize USB resource. */
1085 /* dev : device pointer */
1091 /* Stephen Chen ZyDAS Technology Corporation 2005.12 */
1093 /************************************************************************/
1094 void zfUsbInit(zdev_t
* dev
)
1096 /* Initialize Rx & INT endpoint for receiving data & interrupt */
1097 zfwUsbEnableRxEpt(dev
, USB_ENDPOINT_RX_INDEX
);
1098 zfwUsbEnableIntEpt(dev
, USB_ENDPOINT_INT_INDEX
);
1104 /************************************************************************/
1106 /* FUNCTION DESCRIPTION zfUsbFree */
1107 /* Free PCI resource. */
1110 /* dev : device pointer */
1116 /* Stephen Chen ZyDAS Technology Corporation 2005.12 */
1118 /************************************************************************/
1119 void zfUsbFree(zdev_t
* dev
)
1121 struct zsHpPriv
*halPriv
;
1123 zmw_get_wlan_dev(dev
);
1125 halPriv
= (struct zsHpPriv
*)wd
->hpPrivate
;
1127 #ifdef ZM_OTUS_RX_STREAM_MODE
1128 if ( halPriv
->remainBuf
!= NULL
)
1130 zfwBufFree(dev
, halPriv
->remainBuf
, 0);
1137 void zfHpSendBeacon(zdev_t
* dev
, zbuf_t
* buf
, u16_t len
)
1141 zmw_get_wlan_dev(dev
);
1143 /* Write to beacon buffer (ZM_BEACON_BUFFER_ADDRESS) */
1144 for (i
= 0; i
<len
; i
+=4)
1146 lw
= zmw_tx_buf_readh(dev
, buf
, i
);
1147 hw
= zmw_tx_buf_readh(dev
, buf
, i
+2);
1149 zfDelayWriteInternalReg(dev
, ZM_BEACON_BUFFER_ADDRESS
+i
, (hw
<<16)+lw
);
1152 /* Beacon PCLP header */
1153 if (((struct zsHpPriv
*)wd
->hpPrivate
)->hwFrequency
< 3000)
1155 zfDelayWriteInternalReg(dev
, ZM_MAC_REG_BCN_PLCP
, ((len
+4)<<(3+16))+0x0400);
1159 zfDelayWriteInternalReg(dev
, ZM_MAC_REG_BCN_PLCP
, ((len
+4)<<(16))+0x001b);
1162 /* Beacon length (include CRC32) */
1163 zfDelayWriteInternalReg(dev
, ZM_MAC_REG_BCN_LENGTH
, len
+4);
1166 zfDelayWriteInternalReg(dev
, ZM_MAC_REG_BCN_CTRL
, 1);
1167 zfFlushDelayWrite(dev
);
1169 /* Free beacon buf */
1170 zfwBufFree(dev
, buf
, 0);
1176 #define ZM_STATUS_TX_COMP 0x00
1177 #define ZM_STATUS_RETRY_COMP 0x01
1178 #define ZM_STATUS_TX_FAILED 0x02
1179 void zfiUsbRegIn(zdev_t
* dev
, u32_t
* rsp
, u16_t rspLen
)
1181 //u8_t len, type, i;
1186 zmw_get_wlan_dev(dev
);
1188 zm_msg0_mm(ZM_LV_3
, "zfiUsbRegIn()");
1190 u8rsp
= (u8_t
*)rsp
;
1197 /* Interrupt event */
1198 if ((type
& 0xC0) == 0xC0)
1202 zfCoreEvent(dev
, 0, u8rsp
);
1205 else if (type
== 0xC1)
1207 status
= (u16_t
)(rsp
[3] >> 16);
1210 rsp
[8] = rsp
[8] >> 2 | (rsp
[9] & 0x1) << 6;
1213 case ZM_STATUS_RETRY_COMP
:
1214 zfCoreEvent(dev
, 1, u8rsp
);
1216 case ZM_STATUS_TX_FAILED
:
1217 zfCoreEvent(dev
, 2, u8rsp
);
1219 case ZM_STATUS_TX_COMP
:
1220 zfCoreEvent(dev
, 3, u8rsp
);
1224 else if (type
== 0xC2)
1226 zfBeaconCfgInterrupt(dev
, u8rsp
);
1228 else if (type
== 0xC3)
1230 zfEndOfAtimWindowInterrupt(dev
);
1232 else if (type
== 0xC4)
1234 bitmap
= (rsp
[1] >> 16) + ((rsp
[2] & 0xFFFF) << 16 );
1235 //zfBawCore(dev, (u16_t)rsp[1] & 0xFFFF, bitmap, (u16_t)(rsp[2] >> 16) & 0xFF);
1237 else if (type
== 0xC5)
1240 for (i
=1; i
<(rspLen
/4); i
++) {
1241 u8rsp
= (u8_t
*)(rsp
+i
);
1242 //DbgPrint("0xC5:rsp[%d]=0x%lx\n", i, ((u32_t*)u8rsp)[0]);
1243 zfCoreEvent(dev
, 4, u8rsp
);
1246 else if (type
== 0xC6)
1248 zm_debug_msg0("\n\n WatchDog interrupt!!! : 0xC6 \n\n");
1249 if (wd
->zfcbHwWatchDogNotify
!= NULL
)
1251 wd
->zfcbHwWatchDogNotify(dev
);
1254 else if (type
== 0xC8)
1256 //PZSW_ADAPTER adapter;
1258 // for SPI flash program chk Flag
1259 zfwDbgProgrameFlashChkDone(dev
);
1261 else if (type
== 0xC9)
1263 struct zsHpPriv
* hpPriv
=wd
->hpPrivate
;
1265 zm_debug_msg0("##### Tx retransmission 5 times event #####");
1267 /* correct tx retransmission issue */
1268 hpPriv
->retransmissionEvent
= 1;
1273 zfIdlRsp(dev
, rsp
, rspLen
);
1278 #define ZM_PROGRAM_RAM_ADDR 0x200000 //0x1000 //0x700000
1279 #define FIRMWARE_DOWNLOAD 0x30
1280 #define FIRMWARE_DOWNLOAD_COMP 0x31
1281 #define FIRMWARE_CONFIRM 0x32
1283 u16_t
zfFirmwareDownload(zdev_t
* dev
, u32_t
* fw
, u32_t len
, u32_t offset
)
1285 u16_t ret
= ZM_SUCCESS
;
1286 u32_t uCodeOfst
= offset
;
1295 u32_t translen
= (len
> 4096) ? 4096 : len
;
1297 result
= zfwUsbSubmitControl(dev
, FIRMWARE_DOWNLOAD
,
1298 (u16_t
) (uCodeOfst
>> 8),
1299 0, image
, translen
);
1301 if (result
!= ZM_SUCCESS
)
1303 zm_msg0_init(ZM_LV_0
, "FIRMWARE_DOWNLOAD failed");
1310 uCodeOfst
+= translen
; // in Word (16 bit)
1315 /* If download firmware success, issue a command to firmware */
1318 result
= zfwUsbSubmitControl(dev
, FIRMWARE_DOWNLOAD_COMP
,
1321 if (result
!= ZM_SUCCESS
)
1323 zm_msg0_init(ZM_LV_0
, "FIRMWARE_DOWNLOAD_COMP failed");
1336 u16_t
zfFirmwareDownloadNotJump(zdev_t
* dev
, u32_t
* fw
, u32_t len
, u32_t offset
)
1338 u16_t ret
= ZM_SUCCESS
;
1339 u32_t uCodeOfst
= offset
;
1348 u32_t translen
= (len
> 4096) ? 4096 : len
;
1350 result
= zfwUsbSubmitControl(dev
, FIRMWARE_DOWNLOAD
,
1351 (u16_t
) (uCodeOfst
>> 8),
1352 0, image
, translen
);
1354 if (result
!= ZM_SUCCESS
)
1356 zm_msg0_init(ZM_LV_0
, "FIRMWARE_DOWNLOAD failed");
1363 uCodeOfst
+= translen
; // in Word (16 bit)
1374 /************************************************************************/
1376 /* FUNCTION DESCRIPTION zfIdlGetFreeTxdCount */
1377 /* Get free PCI PCI TxD count. */
1380 /* dev : device pointer */
1386 /* Stephen ZyDAS Technology Corporation 2006.6 */
1388 /************************************************************************/
1389 u32_t
zfHpGetFreeTxdCount(zdev_t
* dev
)
1391 return zfwUsbGetFreeTxQSize(dev
);
1394 u32_t
zfHpGetMaxTxdCount(zdev_t
* dev
)
1397 return zfwUsbGetMaxTxQSize(dev
);
1400 void zfiUsbRegOutComplete(zdev_t
* dev
)
1405 extern void zfPushVtxq(zdev_t
* dev
);
1407 void zfiUsbOutComplete(zdev_t
* dev
, zbuf_t
*buf
, u8_t status
, u8_t
*hdr
) {
1408 #ifndef ZM_ENABLE_AGGREGATION
1410 zfwBufFree(dev
, buf
, 0);
1413 #ifdef ZM_BYPASS_AGGR_SCHEDULING
1414 //Simply free the buf since BA retransmission is done in the firmware
1417 zfwBufFree(dev
, buf
, 0);
1421 zmw_get_wlan_dev(dev
);
1423 #ifdef ZM_ENABLE_FW_BA_RETRANSMISSION
1424 //Simply free the buf since BA retransmission is done in the firmware
1427 zfwBufFree(dev
, buf
, 0);
1434 zfwBufFree(dev
, buf
, 0);
1435 //zm_debug_msg0("buf Free due to hdr == NULL");
1440 frameType
= hdr
[8] & 0xf;
1441 agg
= (u8_t
)(hdr
[2] >> 5 ) & 0x1;
1442 //zm_debug_msg1("AGG=", agg);
1446 //delete buf in ba fail queue??
1450 zfwBufFree(dev
, buf
, 0);
1456 //zfwBufFree(dev, buf, 0);
1459 zfwBufFree(dev
, buf
, 0);
1465 if (wd
->state
!= ZM_WLAN_STATE_ENABLED
) {
1469 if( (wd
->wlanMode
== ZM_MODE_AP
) ||
1470 (wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
&& wd
->sta
.EnableHT
) ||
1471 (wd
->wlanMode
== ZM_MODE_PSEUDO
) ) {
1472 zfAggTxScheduler(dev
, 0);