RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / otus / hal / hpusb.c
blobf8dcc1a52c51a589584ad2a9e06a0431567fb045
1 /*
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.
17 /* */
18 /* Module Name : ud.c */
19 /* */
20 /* Abstract */
21 /* This module contains USB descriptor functions. */
22 /* */
23 /* NOTES */
24 /* None */
25 /* */
26 /************************************************************************/
27 #include "../80211core/cprecomp.h"
28 #include "hpani.h"
29 #include "hpusb.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);
47 #endif
49 return;
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 */
60 u32_t oldMT;
61 u32_t oldMCS;
63 u32_t phyCtrl;
64 u32_t oldPhyCtrl;
66 u16_t tpc = 0;
67 struct zsHpPriv* hpPriv;
69 zmw_get_wlan_dev(dev);
70 hpPriv=wd->hpPrivate;
72 /* mm */
73 if (header == NULL)
75 oldPhyCtrl = zmw_buf_readh(dev, buf, 4) | ((u32_t)zmw_buf_readh(dev, buf, 6) << 16);
77 else
79 oldPhyCtrl = header[2] | ((u32_t)header[3] <<16);
82 phyCtrl = 0;
85 /* MT : Bit[1~0] */
86 oldMT = oldPhyCtrl&0x3;
87 phyCtrl |= oldMT;
88 if ( oldMT == 0x3 ) /* DL-OFDM (Duplicate Legacy OFDM) */
89 phyCtrl |= 0x1;
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 */
103 else {
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);
120 else
122 /* HT Tx 2 chain */
123 /* OFDM 6M/9M/12M/18M/24M Tx 2 chain */
124 /* OFDM 36M/48M/54M/ Tx 1 chain */
125 /* CCK Tx 2 chain */
126 if ((oldMT == 2) || (oldMT == 3))
128 phyCtrl |= (0x5<<15);
130 else if (oldMT == 1)
132 if ((oldMCS == 0xb) || (oldMCS == 0xf) ||
133 (oldMCS == 0xa) || (oldMCS == 0xe) ||
134 (oldMCS == 0x9)) //6M/9M/12M/18M/24M
136 phyCtrl |= (0x5<<15);
138 else
140 phyCtrl |= (0x1<<15);
143 else //(oldMT==0)
145 phyCtrl |= (0x5<<15);
148 //else
149 // phyCtrl |= (0x1<<15);
151 /* TPC */
152 /* TODO : accelerating these code */
153 if (hpPriv->hwFrequency < 3000)
155 if (oldMT == 0)
157 /* CCK */
158 tpc = (hpPriv->tPow2xCck[oldMCS]&0x3f);
160 else if (oldMT == 1)
162 /* OFDM */
163 if (oldMCS == 0xc)
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);
179 else
181 tpc = (hpPriv->tPow2x2g[0]&0x3f);
184 else if (oldMT == 2)
186 if ( oldPhyCtrl&0x800000 ) /* Bit23 : 40M */
188 /* HT 40 */
189 tpc = (hpPriv->tPow2x2gHt40[oldMCS&0x7]&0x3f);
191 else
193 /* HT 20 */
194 tpc = (hpPriv->tPow2x2gHt20[oldMCS&0x7]&0x3f);
198 else //5GHz
200 if (oldMT == 1)
202 /* OFDM */
203 if (oldMCS == 0xc)
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);
215 else
217 tpc = (hpPriv->tPow2x5g[0]&0x3f);
220 else if (oldMT == 2)
222 if ( oldPhyCtrl&0x800000 ) /* Bit23 : 40M */
224 /* HT 40 */
225 tpc = (hpPriv->tPow2x5gHt40[oldMCS&0x7]&0x3f);
227 else
229 /* HT 20 */
230 tpc = (hpPriv->tPow2x5gHt20[oldMCS&0x7]&0x3f);
235 /* Tx power adjust for HT40 */
236 /* HT40 +1dBm */
237 if ((oldMT==2) && (oldPhyCtrl&0x800000) )
239 tpc += 2;
241 tpc &= 0x3f;
243 /* Evl force tx TPC */
244 if(wd->forceTxTPC)
246 tpc = (u16_t)(wd->forceTxTPC & 0x3f);
249 if (hpPriv->hwFrequency < 3000) {
250 wd->maxTxPower2 &= 0x3f;
251 tpc = (tpc > wd->maxTxPower2)? wd->maxTxPower2 : tpc;
252 } else {
253 wd->maxTxPower5 &= 0x3f;
254 tpc = (tpc > wd->maxTxPower5)? wd->maxTxPower5 : tpc;
258 #define ZM_MIN_TPC 5
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);
277 #undef ZM_MIN_TPC
278 #undef ZM_TPC_OFFSET
279 #undef ZM_SIGNAL_THRESHOLD
281 #ifndef ZM_OTUS_LINUX_PHASE_2
282 phyCtrl |= (tpc & 0x3f) << 9;
283 #endif
285 /* Set bits[8:6]BF-MCS for heavy clip */
286 if ((phyCtrl&0x3) == 2)
288 phyCtrl |= ((phyCtrl >> 12) & 0x1c0);
291 /* PHY control */
292 if (header == NULL)
294 zmw_buf_writeh(dev, buf, 4, (u16_t) (phyCtrl&0xffff));
295 zmw_buf_writeh(dev, buf, 6, (u16_t) (phyCtrl>>16));
297 else
299 //PHY control L
300 header[2] = (u16_t) (phyCtrl&0xffff);
301 //PHY control H
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
319 zbuf_t *rxbuf;
320 u8_t *puRxBuf;
321 u8_t *pHdr;
322 u8_t *psnap;
323 u16_t plcplen = 12;
324 u16_t i;
325 u16_t swlpOffset;
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);
344 #endif
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 */
394 return ZM_SUCCESS;
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)
409 u8_t frameType;
410 u8_t mpduInd;
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);
419 else
421 frameType = zmw_rx_buf_readb(dev, buf, 0);
424 if((frameType & 0xf) == ZM_WLAN_DATA_FRAME)
425 return 1;
426 else
427 return 0;
430 u32_t zfcConvertRateOFDM(zdev_t* dev, zbuf_t* buf)
432 // What's the default value??
433 u32_t MCS = 0;
435 switch(zmw_rx_buf_readb(dev, buf, 0)& 0xf)
437 case 0xb:
438 MCS = 0x4;
439 break;
440 case 0xf:
441 MCS = 0x5;
442 break;
443 case 0xa:
444 MCS = 0x6;
445 break;
446 case 0xe:
447 MCS = 0x7;
448 break;
449 case 0x9:
450 MCS = 0x8;
451 break;
452 case 0xd:
453 MCS = 0x9;
454 break;
455 case 0x8:
456 MCS = 0xa;
457 break;
458 case 0xc:
459 MCS = 0xb;
460 break;
462 return MCS;
465 u16_t zfHpGetPayloadLen(zdev_t* dev,
466 zbuf_t* buf,
467 u16_t len,
468 u16_t plcpHdrLen,
469 u32_t *rxMT,
470 u32_t *rxMCS,
471 u32_t *rxBW,
472 u32_t *rxSG
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;
483 *rxMT = modulation;
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);
494 *rxBW = 0;
495 *rxSG = 0;
497 break;
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);
506 *rxBW = 0;
507 *rxSG = 0;
509 break;
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
514 else {
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;
524 break;
525 default:
526 break;
529 /* return the payload length - FCS */
530 if (payloadLen < 0) payloadLen = 0;
531 return payloadLen;
534 /************************************************************************/
535 /* */
536 /* FUNCTION DESCRIPTION zfiUsbRecv */
537 /* Callback function for USB IN Transfer. */
538 /* */
539 /* INPUTS */
540 /* dev: device pointer */
541 /* */
542 /* OUTPUTS */
543 /* None */
544 /* */
545 /* AUTHOR */
546 /* Yuan-Gu Wei ZyDAS Technology Corporation 2005.10 */
547 /* */
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);
554 #endif
556 #ifdef ZM_OTUS_RX_STREAM_MODE
557 void zfiUsbRecvPerPkt(zdev_t *dev, zbuf_t *buf)
558 #else
559 void zfiUsbRecv(zdev_t *dev, zbuf_t *buf)
560 #endif
564 #if ZM_FW_LOOP_BACK != 1
565 u8_t mpduInd;
566 u16_t plcpHdrLen;
567 u16_t crcPlusRxStatusLen;
568 u16_t len, payloadLen=0;
569 u16_t i; //CWYang(+)
570 struct zsAdditionInfo addInfo;
571 u32_t rxMT;
572 u32_t rxMCS;
573 u32_t rxBW;
574 u32_t rxSG;
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)
587 break;
590 if (i==(ZM_INT_USE_EP2_HEADER_SIZE>>1))
592 u32_t rsp[ZM_USB_MAX_EPINT_BUFFER/4];
593 u16_t rspLen;
594 u32_t rspi;
595 u8_t* pdst = (u8_t*)rsp;
597 /* Interrupt Rsp */
598 rspLen = (u16_t) zfwBufGetSize(dev, buf)-ZM_INT_USE_EP2_HEADER_SIZE;
600 if (rspLen > 60)
602 zm_debug_msg1("Get error len by EP2 = \n", rspLen);
603 /* free USB buf */
604 zfwBufFree(dev, buf, 0);
605 return;
608 for (rspi=0; rspi<rspLen; rspi++)
610 *pdst = zmw_rx_buf_readb(dev, buf, rspi+ZM_INT_USE_EP2_HEADER_SIZE);
611 pdst++;
614 //if (adapter->zfcbUsbRegIn)
615 // adapter->zfcbUsbRegIn(adapter, rsp, rspLen);
616 zfiUsbRegIn(dev, rsp, rspLen);
618 /* free USB buf */
619 zfwBufFree(dev, buf, 0);
620 return;
622 #endif /* end of #if ZM_INT_USE_EP2 == 1 */
624 ZM_PERFORMANCE_RX_MPDU(dev, buf);
626 if (wd->swSniffer)
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);
639 /* First MPDU */
640 if((mpduInd & 0x30) == 0x20)
642 u16_t duration;
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;
650 else
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
667 else
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]) {
672 plcpHdrLen = 0;
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]){
677 plcpHdrLen = 12;
679 else {
680 plcpHdrLen = 0;
684 /* Last MPDU or Single MPDU */
685 if ((mpduInd & 0x30) == 0x00 || (mpduInd & 0x30) == 0x10)
687 crcPlusRxStatusLen = EXTRA_INFO_LEN + 4; // Extra bytes + FCS
689 else
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);
700 return;
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);
724 /* Hal Rx info */
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);
740 return;
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¢}
752 * RSSI:
753 * Byte 1 antenna 0
754 * Byte 2 antenna 1
755 * Byte 3 antenna 2
756 * Byte 4 antenna 0 extension
757 * Byte 5 antenna 1 extension
758 * Byte 6 antenna 2 extension
759 * Byte 7 antenna combined
760 * EVM:
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
787 /* EVM */
789 /* TODO: for RD/BB debug message */
790 /* save current rx hw infomration, report to DrvCore/Application */
791 if (wd->enableHALDbgInfo && zfIsDataFrame(dev, buf))
793 u8_t trssi;
794 for (i=0; i<7; i++)
796 trssi = zmw_rx_buf_readb(dev, buf, (len-1) - 23 + i);
797 if (trssi&0x80)
799 trssi = ((~((u8_t)trssi) & 0x7f) + 1) & 0x7f;
801 ((struct zsHpPriv*)wd->hpPrivate)->halRxInfo.currentRSSI[i] = trssi;
804 if (rxMT==2)
806 //if (rxBW)
808 for (i=0; i<12; i++)
809 ((struct zsHpPriv*)wd->hpPrivate)->halRxInfo.currentRxEVM[i] =
810 zmw_rx_buf_readb(dev, buf, (len-1) - 16 + i);
812 //else
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)) */
823 else
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(+)
842 if (plcpHdrLen != 0)
844 for (i = 0; i < plcpHdrLen; i++)
846 addInfo.PlcpHeader[i] = zmw_rx_buf_readb(dev, buf, i);
849 else
851 addInfo.PlcpHeader[0] = 0;
853 /* Remove PLCP header */
854 zfwBufRemoveHead(dev, buf, plcpHdrLen);
856 /* handle 802.11 frame */
857 zfCoreRecv(dev, buf, &addInfo);
859 #else
860 /* Firmware loopback: Rx frame = Tx frame */
861 /* convert Rx frame to fit receive frame format */
862 zbuf_t *new_buf;
863 u8_t ctrl_offset = 8;
864 u8_t PLCP_Len = 12;
865 u8_t data;
866 u8_t i;
869 /* Tx: | ctrl_setting | Mac hdr | data | */
870 /* 8 24 x */
872 /* Rx: | PLCP | Mac hdr | data | FCS | Rxstatus | */
873 /* 12 24 x 4 8 */
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);
891 #endif
895 #ifdef ZM_OTUS_RX_STREAM_MODE
896 void zfiUsbRecv(zdev_t *dev, zbuf_t *buf)
898 u16_t index = 0;
899 u16_t chkIdx;
900 u32_t status = 0;
901 u16_t ii;
902 zbuf_t *newBuf;
903 zbuf_t *rxBufPool[8];
904 u16_t rxBufPoolIndex = 0;
905 struct zsHpPriv *halPriv;
906 u8_t *srcBufPtr;
907 u32_t bufferLength;
908 u16_t usbRxRemainLen;
909 u16_t usbRxPktLen;
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 */
919 if (!bufferLength)
921 zfwBufFree(dev, buf, 0);
922 return;
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;
932 u8_t* BufPtr = NULL;
934 if ( remainBufPtr != NULL )
936 BufPtr = zmw_buf_get_buffer(dev, remainBufPtr);
939 index = usbRxRemainLen;
940 usbRxRemainLen -= halPriv->usbRxPadLen;
942 /* Copy data */
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)
965 u16_t pktLen;
966 u16_t pktTag;
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)
976 u16_t padLen;
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)
987 padLen = 0;
989 chkIdx = index;
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);
995 zm_assert(0);
996 status = 1;
997 break;
1000 if (index > ZM_MAX_USB_IN_TRANSFER_SIZE)
1002 //struct zsBuffer* BufPtr;
1003 //struct zsBuffer* UsbBufPtr;
1004 u8_t *BufPtr;
1005 u8_t *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);
1017 status = 1;
1018 break;
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;
1036 else
1038 u8_t* BufPtr;
1039 u8_t* UsbBufPtr;
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;
1056 else
1058 u16_t i;
1060 DbgPrint("Can't find tag, pkt_len: 0x%04x, tag: 0x%04x\n",
1061 pktLen, pktTag);
1064 break;
1068 /* Free buffer */
1069 //zfwBufFree(adapter, pUsbRxTransfer->buf, 0);
1070 zfwBufFree(dev, buf, 0);
1072 for(ii = 0; ii < rxBufPoolIndex; ii++)
1074 zfiUsbRecvPerPkt(dev, rxBufPool[ii]);
1077 #endif
1079 /************************************************************************/
1080 /* */
1081 /* FUNCTION DESCRIPTION zfUsbInit */
1082 /* Initialize USB resource. */
1083 /* */
1084 /* INPUTS */
1085 /* dev : device pointer */
1086 /* */
1087 /* OUTPUTS */
1088 /* None */
1089 /* */
1090 /* AUTHOR */
1091 /* Stephen Chen ZyDAS Technology Corporation 2005.12 */
1092 /* */
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);
1100 return;
1104 /************************************************************************/
1105 /* */
1106 /* FUNCTION DESCRIPTION zfUsbFree */
1107 /* Free PCI resource. */
1108 /* */
1109 /* INPUTS */
1110 /* dev : device pointer */
1111 /* */
1112 /* OUTPUTS */
1113 /* None */
1114 /* */
1115 /* AUTHOR */
1116 /* Stephen Chen ZyDAS Technology Corporation 2005.12 */
1117 /* */
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);
1132 #endif
1134 return;
1137 void zfHpSendBeacon(zdev_t* dev, zbuf_t* buf, u16_t len)
1139 u32_t hw, lw;
1140 u16_t i;
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);
1157 else
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);
1165 /* Beacon Ready */
1166 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_CTRL, 1);
1167 zfFlushDelayWrite(dev);
1169 /* Free beacon buf */
1170 zfwBufFree(dev, buf, 0);
1172 return;
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;
1182 u8_t type;
1183 u8_t *u8rsp;
1184 u16_t status;
1185 u32_t bitmap;
1186 zmw_get_wlan_dev(dev);
1188 zm_msg0_mm(ZM_LV_3, "zfiUsbRegIn()");
1190 u8rsp = (u8_t *)rsp;
1192 //len = *u8rsp;
1193 type = *(u8rsp+1);
1194 u8rsp = u8rsp+4;
1197 /* Interrupt event */
1198 if ((type & 0xC0) == 0xC0)
1200 if (type == 0xC0)
1202 zfCoreEvent(dev, 0, u8rsp);
1205 else if (type == 0xC1)
1207 status = (u16_t)(rsp[3] >> 16);
1209 ////6789
1210 rsp[8] = rsp[8] >> 2 | (rsp[9] & 0x1) << 6;
1211 switch (status)
1213 case ZM_STATUS_RETRY_COMP :
1214 zfCoreEvent(dev, 1, u8rsp);
1215 break;
1216 case ZM_STATUS_TX_FAILED :
1217 zfCoreEvent(dev, 2, u8rsp);
1218 break;
1219 case ZM_STATUS_TX_COMP :
1220 zfCoreEvent(dev, 3, u8rsp);
1221 break;
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)
1239 u16_t i;
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;
1271 else
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;
1287 u8_t *image, *ptr;
1288 u32_t result;
1290 image = (u8_t*) fw;
1291 ptr = image;
1293 while (len > 0)
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");
1304 ret = 1;
1305 goto exit;
1308 len -= translen;
1309 image += translen;
1310 uCodeOfst += translen; // in Word (16 bit)
1312 result = 0;
1315 /* If download firmware success, issue a command to firmware */
1316 if (ret == 0)
1318 result = zfwUsbSubmitControl(dev, FIRMWARE_DOWNLOAD_COMP,
1319 0, 0, NULL, 0);
1321 if (result != ZM_SUCCESS)
1323 zm_msg0_init(ZM_LV_0, "FIRMWARE_DOWNLOAD_COMP failed");
1324 ret = 1;
1325 goto exit;
1330 exit:
1332 return ret;
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;
1340 u8_t *image, *ptr;
1341 u32_t result;
1343 image = (u8_t*) fw;
1344 ptr = image;
1346 while (len > 0)
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");
1357 ret = 1;
1358 goto exit;
1361 len -= translen;
1362 image += translen;
1363 uCodeOfst += translen; // in Word (16 bit)
1365 result = 0;
1368 exit:
1370 return ret;
1374 /************************************************************************/
1375 /* */
1376 /* FUNCTION DESCRIPTION zfIdlGetFreeTxdCount */
1377 /* Get free PCI PCI TxD count. */
1378 /* */
1379 /* INPUTS */
1380 /* dev : device pointer */
1381 /* */
1382 /* OUTPUTS */
1383 /* None */
1384 /* */
1385 /* AUTHOR */
1386 /* Stephen ZyDAS Technology Corporation 2006.6 */
1387 /* */
1388 /************************************************************************/
1389 u32_t zfHpGetFreeTxdCount(zdev_t* dev)
1391 return zfwUsbGetFreeTxQSize(dev);
1394 u32_t zfHpGetMaxTxdCount(zdev_t* dev)
1396 //return 8;
1397 return zfwUsbGetMaxTxQSize(dev);
1400 void zfiUsbRegOutComplete(zdev_t* dev)
1402 return;
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
1409 if (buf) {
1410 zfwBufFree(dev, buf, 0);
1412 #else
1413 #ifdef ZM_BYPASS_AGGR_SCHEDULING
1414 //Simply free the buf since BA retransmission is done in the firmware
1415 if (buf)
1417 zfwBufFree(dev, buf, 0);
1419 zfPushVtxq(dev);
1420 #else
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
1425 if (buf)
1427 zfwBufFree(dev, buf, 0);
1429 #else
1430 u8_t agg;
1431 u16_t frameType;
1433 if(!hdr && buf) {
1434 zfwBufFree(dev, buf, 0);
1435 //zm_debug_msg0("buf Free due to hdr == NULL");
1436 return;
1439 if(hdr && buf) {
1440 frameType = hdr[8] & 0xf;
1441 agg = (u8_t)(hdr[2] >> 5 ) & 0x1;
1442 //zm_debug_msg1("AGG=", agg);
1444 if (!status) {
1445 if (agg) {
1446 //delete buf in ba fail queue??
1447 //not ganna happen?
1449 else {
1450 zfwBufFree(dev, buf, 0);
1453 else {
1454 if (agg) {
1455 //don't do anything
1456 //zfwBufFree(dev, buf, 0);
1458 else {
1459 zfwBufFree(dev, buf, 0);
1463 #endif
1465 if (wd->state != ZM_WLAN_STATE_ENABLED) {
1466 return;
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);
1474 #endif
1475 #endif
1477 return;