MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zdreq.c
blobaacd5df99e30b44b4aef95189892fadd9a9f497b
1 /* src/zdreq.c
5 * Copyright (C) 2004 ZyDAS Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * -------------------------------------------------------------------- */
33 #include "zd1205.h"
34 #include "zdhw.h"
35 #include "zdhci.h"
36 #include "zddebug.h"
37 #include "zdreq.h"
38 #include "zdsm.h"
39 #include "zdbuf.h"
40 #ifdef PRODUCTION
41 extern zd_80211Obj_t dot11Obj;
42 extern U8 mMacMode;
43 extern void zd1205_CollectHwTally(struct zd1205_private *macp);
44 //extern void zd1205_SoftwareReset(struct zd1205_private *macp);
46 /* In fact, these global variables should be avoided. The should be
47 * removed to the context of adapter.
50 //extern U8 IntValue[14];
51 int zdproduction_ioctl(struct zd1205_private *macp, struct zd_point *p)
53 NDIS_STATUS status;
54 oid_wrap_t *param;
55 int ret = 0;
57 printk(KERN_ERR "zdproduction_ioctl, length: %d\n", p->length);
59 if (p->length < sizeof(oid_wrap_t) || !p->pointer)
61 printk(KERN_ERR "Something Wrong,%d,%d\n",p->length,sizeof(oid_wrap_t));
62 return -EINVAL;
65 param = (oid_wrap_t *) kmalloc(p->length, GFP_ATOMIC);
67 if (param == NULL)
69 printk(KERN_ERR "Buf is NULL\n");
70 return -ENOMEM;
73 if (copy_from_user(param, p->pointer, p->length))
75 printk(KERN_ERR "copy_from_user error\n");
76 ret = -EFAULT;
77 goto out;
80 /* Dump the content */
81 #if 0
82 ZDPRODUCTDBG("\r\n");
84 int ii;
85 u8 *pp = (u8 *) param;
87 for(ii = 0; ii < p->length;)
89 ZDPRODUCTDBG("0x%02x ", pp[ii]);
91 if((++ii % 16) == 0)
92 ZDPRODUCTDBG("\r\n");
94 ZDPRODUCTDBG("\r\n");
96 #endif
98 /* Dump the data structure of UDP request. */
99 ZDPRODUCTDBG("request: 0x%04x\n", le16_to_cpu(param->request));
100 ZDPRODUCTDBG("seq: 0x%04x\n", le16_to_cpu(param->seq));
101 ZDPRODUCTDBG("oid: 0x%08x\n", le32_to_cpu(param->u.info.oid));
102 ZDPRODUCTDBG("status: 0x%08x\n", le32_to_cpu(param->u.info.status));
103 ZDPRODUCTDBG("length: 0x%08x\n", le32_to_cpu(param->u.info.length));
105 /* Query command */
106 if (le16_to_cpu(param->request) == CMD_QUERY_INFORMATION)
108 NDIS_OID Oid = le32_to_cpu(param->u.info.oid);
109 PVOID InformationBuffer = param->u.info.data;
110 ULONG InformationBufferLength = le32_to_cpu(param->u.info.length);
111 ULONG BytesWritten;
112 ULONG BytesNeeded;
114 status = ZD1205EM_Custom_QueryInformation((PVOID) macp,
115 Oid,
116 InformationBuffer,
117 InformationBufferLength,
118 &BytesWritten,
119 &BytesNeeded);
121 param->u.info.status = cpu_to_le32(status);
122 if (status == NDIS_STATUS_SUCCESS)
124 /* Update information */
125 param->u.info.length = cpu_to_le32(BytesWritten);
126 p->length = ZD_GENERIC_OID_HDR_LEN + BytesWritten;
127 ret = 1;
129 else
131 /* If the status is not NDIS_STATUS_SUCCESS,
132 we don't change the length field. */
133 p->length = ZD_GENERIC_OID_HDR_LEN + sizeof(ZD_RD_STRUCT);
134 ret = 1;
137 else if (le16_to_cpu(param->request) == CMD_SET_INFORMATION)
139 NDIS_OID Oid = le32_to_cpu(param->u.info.oid);
140 PVOID InformationBuffer = param->u.info.data;
141 ULONG InformationBufferLength = le32_to_cpu(param->u.info.length);
142 ULONG BytesWritten;
143 ULONG BytesNeeded;
145 status = ZD1205EM_Custom_SetInformation((PVOID) macp,
146 Oid,
147 InformationBuffer,
148 InformationBufferLength,
149 &BytesWritten,
150 &BytesNeeded);
152 param->u.info.status = cpu_to_le32(status);
154 /* Update information */
155 p->length = ZD_GENERIC_OID_HDR_LEN;
156 ret = 1;
159 if (ret == 1)
161 if (copy_to_user(p->pointer, param, p->length))
163 ret = -EFAULT;
164 goto out;
166 else
167 ret = 0;
170 out:
171 kfree(param);
172 return ret;
175 #if 0 //Replace by SoftwareReset in zdmain.c
176 void SoftwareReset(zd1205_private_t *macp)
178 void *reg = macp->regp;
179 U32 tmpvalue;
181 acquire_ctrl_of_phy_req(reg);
182 dot11Obj.SetReg(reg,ZD1205_PHY_END, 0x8);
183 release_ctrl_of_phy_req(reg);
185 tmpvalue = dot11Obj.GetReg(reg, PS_Ctrl);
186 dot11Obj.SetReg(reg, PS_Ctrl, (tmpvalue | BIT_5));
188 acquire_ctrl_of_phy_req(reg);
189 dot11Obj.SetReg(reg, ZD1205_PHY_END, 0x0);
190 release_ctrl_of_phy_req(reg);
192 /* Recycle Tx process */
193 ZD1205_recycle_tx(macp);
195 /* Recycle Rx process */
196 ZD1205_recycle_rx(macp);
198 #endif
201 UCHAR Rate_Convert_to_MS(UCHAR rate_in_drv)
203 UCHAR rate;
205 switch (rate_in_drv)
207 case RATE_1M:
208 rate = 2; // 1M
209 break;
210 case RATE_2M:
211 rate = 4; // 2M
212 break;
213 case RATE_5M:
214 rate = 11; // 5.5M
215 break;
216 case RATE_11M:
217 rate = 22; // 11M
218 break;
219 case RATE_6M:
220 rate = 12; // 6M
221 break;
222 case RATE_9M:
223 rate = 18; // 9M
224 break;
225 case RATE_12M:
226 rate = 24; // 12M
227 break;
228 case RATE_18M:
229 rate = 36; // 18M
230 break;
231 case RATE_24M:
232 rate = 48; // 24M
233 break;
234 case RATE_36M:
235 rate = 72; // 36M
236 break;
237 case RATE_48M:
238 rate = 96; // 48M
239 break;
240 case RATE_54M:
241 rate = 108; // 54M
242 break;
243 default:
244 rate = 108; // 54M
245 break;
248 return rate;
252 UCHAR Rate_Convert(UCHAR rate)
254 switch(rate)
256 case 2: return 0; // 1M
257 case 4: return 1; // 2M
258 case 11: return 2; // 5.5M
259 case 22: return 3; // 11M
260 case 12: return 4; // 6M
261 case 18: return 5; // 9M
262 case 24: return 6; // 12M
263 case 36: return 7; // 18M
264 case 48: return 8; // 24M
265 case 72: return 9; // 36M
266 case 96: return 0xa; // 48M
267 case 108: return 0xb; // 54M
268 default: return 0xb; // 54M
273 void Reset_Tally(zd1205_private_t *macp)
275 void *reg = macp->regp;
277 macp->txUnicastFrm = 0;
278 macp->txMulticastFrm = 0;
279 macp->txUnicastOctets = 0;
280 macp->txMulticastOctets = 0;
281 macp->retryFailCnt = 0;
282 macp->hwTotalTxFrm = 0;
283 macp->hwRetryCnt = 0;
284 macp->hwUnderrunCnt = 0;
285 macp->DriverRxFrmCnt = 0;
286 macp->rxUnicastFrm = 0;
287 macp->rxMulticastFrm = 0;
288 macp->rxCnt = 0;
289 macp->rxUnicastOctets = 0;
290 macp->rxMulticastOctets = 0;
291 macp->invalid_frame_good_crc = 0;
292 macp->ErrShortFrmCnt = 0;
293 macp->ErrLongFrmCnt = 0;
294 macp->rxBroadcastFrm = 0;
295 macp->rxBroadcastOctets = 0;
296 macp->rx11bDataFrame = 0;
297 macp->rxOFDMDataFrame = 0;
298 macp->rxNeedFrag = 0;
299 macp->rxMgtFrm = 0;
301 macp->hwTotalRxFrm = 0;
302 macp->hwCRC16Cnt = 0;
303 macp->hwCRC32Cnt = 0;
304 macp->hwDecrypErr_UNI = 0;
305 macp->hwDecrypErr_Mul = 0;
306 macp->hwRxFIFOOverrun = 0;
307 /* Debug counter */
308 macp->rxDiscardByNotPIBSS = 0;
309 macp->rxDiscardByAllocateBuf = 0;
311 /* Read clear those hardware counters */
312 dot11Obj.GetReg(reg, TotalRxFrm);
313 dot11Obj.GetReg(reg, CRC32Cnt);
314 dot11Obj.GetReg(reg, CRC16Cnt);
315 dot11Obj.GetReg(reg, DecrypErr_UNI);
316 dot11Obj.GetReg(reg, DecrypErr_Mul);
317 dot11Obj.GetReg(reg, RxFIFOOverrun);
318 dot11Obj.GetReg(reg, TotalTxFrm);
319 dot11Obj.GetReg(reg, UnderrunCnt);
320 dot11Obj.GetReg(reg, RetryCnt);
324 NDIS_STATUS ZD1205EM_Custom_QueryInformation(
325 PVOID NDIS_HANDLE,
326 NDIS_OID Oid,
327 PVOID InformationBuffer,
328 ULONG InformationBufferLength,
329 PULONG BytesWritten,
330 PULONG BytesNeeded
333 NDIS_STATUS Status;
334 ULONG GenericUlong;
335 ULONG IoAddress;
336 //ULONG IoValue;
337 //PVOID MoveSource = (PVOID) (&GenericUlong);
338 //ULONG MoveBytes = sizeof(GenericUlong);
340 zd1205_private_t *macp = (zd1205_private_t *) NDIS_HANDLE;
341 void *reg = macp->regp;
343 NDIS_802_11_CONFIGURATION *pConfiguration;
344 ZD_CUSTOM_STRUCT *pZDCustom;
345 ZD_RD_STRUCT *pZDRD;
346 RID_STRUCT *rid_p;
347 LOCAL_TALLY_STRUCT *pLocalTally;
349 U8 macmode;
350 int i;
352 ZDPRODUCTDBG("****** ZD1205EM_Custom_QueryInformation ******\r\n");
354 /* DUMP InformationBuffer */
355 #if 0
357 int ii;
358 UCHAR *p = (UCHAR *) InformationBuffer;
360 for(ii = 0; ii < InformationBufferLength;)
362 ZDPRODUCTDBG("0x%02x ", p[ii]);
364 if ((++ii % 16) == 0)
365 ZDPRODUCTDBG("\n");
369 #endif
371 Status = NDIS_STATUS_SUCCESS;
373 switch(Oid)
375 case OID_GEN_MEDIA_CONNECT_STATUS:
376 printk(KERN_ERR "OID_GEN_MEDIA_CONNECT_STATUS\n");
377 //if (macp->adapterReady == TRUE)
378 GenericUlong = cpu_to_le32(NdisMediaStateConnected);
379 //else
380 // GenericUlong = NdisMediaStateDisconnected;
382 memcpy(InformationBuffer, &GenericUlong, sizeof(GenericUlong));
383 *BytesWritten = sizeof(GenericUlong);
384 *BytesNeeded = 0;
385 Status = NDIS_STATUS_SUCCESS;
386 break;
388 case OID_GEN_DRIVER_VERSION:
389 ZDPRODUCTDBG("OID_GEN_DRIVER_VERSION\r\n");
391 GenericUlong = cpu_to_le32(ZD1205_DRIVER_VERSION);
392 memcpy(InformationBuffer, &GenericUlong, sizeof(GenericUlong));
393 *BytesWritten = sizeof(GenericUlong);
394 *BytesNeeded = 0;
395 Status = NDIS_STATUS_SUCCESS;
396 break;
398 case OID_802_11_DESIRED_RATES:
399 ZDPRODUCTDBG("OID_802_11_DESIRED_RATES\r\n");
401 if (InformationBuffer == 0 || ((UINT)InformationBufferLength < macp->AllowRateArrayCount))
403 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
404 *BytesWritten = 0;
405 *BytesNeeded = macp->AllowRateArrayCount;
406 break;
409 ZDPRODUCTDBG("OID_802_11_DESIRED_RATES %d\r\n", macp->cardSetting.FixedRate);
411 //for(i = 0; i < macp->AllowRateArrayCount; i++){
412 *((PUCHAR)InformationBuffer) = Rate_Convert_to_MS(macp->cardSetting.FixedRate);
415 // need to check
416 *BytesWritten = macp->AllowRateArrayCount;
417 //*BytesWritten = 1;
418 *BytesNeeded = 0;
419 Status = NDIS_STATUS_SUCCESS;
420 break;
422 case OID_802_11_CONFIGURATION:
423 case OID_ZDX_802_11_CONFIGURATION:
424 ZDPRODUCTDBG("OID_802_11_CONFIGURATION\r\n");
425 if (InformationBuffer == NULL ||
426 (InformationBufferLength < sizeof(NDIS_802_11_CONFIGURATION)))
428 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
430 *BytesWritten = 0;
431 *BytesNeeded = sizeof(NDIS_802_11_CONFIGURATION);
432 break;
435 pConfiguration = (PNDIS_802_11_CONFIGURATION)InformationBuffer;
436 pConfiguration->Length = cpu_to_le32(sizeof(NDIS_802_11_CONFIGURATION));
437 pConfiguration->BeaconPeriod = cpu_to_le32(macp->cardSetting.BeaconInterval);
438 pConfiguration->ATIMWindow = cpu_to_le32(macp->cardSetting.ATIMWindow);
439 pConfiguration->DSConfig = cpu_to_le32((2412+(macp->cardSetting.Channel-1)*5)*1000);
441 if (macp->cardSetting.Channel == 14)
442 pConfiguration->DSConfig = cpu_to_le32(2484000);
443 #ifdef ZDCONF_80211A_SUPPORT
444 if(mMacMode == PURE_A_MODE)
445 pConfiguration->DSConfig = channel_11A_to_Freq(macp->cardSetting.Channel)*1000;
446 #endif
447 *BytesWritten = sizeof(NDIS_802_11_CONFIGURATION);
448 *BytesNeeded = 0;
449 return NDIS_STATUS_SUCCESS;
451 case OID_802_11_INFRASTRUCTURE_MODE:
452 case OID_ZDX_802_11_INFRASTRUCTURE_MODE:
453 ZDPRODUCTDBG("OID_802_11_INFRASTRUCTURE_MODE\r\n");
455 macmode = macp->cardSetting.BssType;
456 switch(macmode)
458 case INDEPENDENT_BSS:
459 GenericUlong = cpu_to_le32(Ndis802_11IBSS);
460 break;
462 case INFRASTRUCTURE_BSS:
463 GenericUlong = cpu_to_le32(Ndis802_11Infrastructure);
464 break;
466 case AP_BSS:
467 GenericUlong = cpu_to_le32(AP_BSS);
468 break;
470 case PSEUDO_IBSS:
471 GenericUlong = cpu_to_le32(PSEUDO_IBSS);
472 break;
475 memcpy(InformationBuffer, &GenericUlong, sizeof(GenericUlong));
476 *BytesWritten = sizeof(GenericUlong);
477 *BytesNeeded = 0;
478 Status = NDIS_STATUS_SUCCESS;
479 break;
481 case OID_ZDX_802_11_SSID:
482 case OID_802_11_NETWORK_TYPE_IN_USE:
483 ZDPRODUCTDBG("OID_ZDX_802_11_SSID\r\n");
485 // 11G
486 GenericUlong = cpu_to_le32(Ndis802_11OFDM24);
488 memcpy(InformationBuffer, &GenericUlong, sizeof(GenericUlong));
489 *BytesWritten = sizeof(GenericUlong);
490 *BytesNeeded = 0;
491 Status = NDIS_STATUS_SUCCESS;
492 break;
493 case OID_802_3_CURRENT_ADDRESS:
494 ZDPRODUCTDBG("OID_802_3_CURRENT_ADDRESS\n");
495 GenericUlong = zd_readl(E2P_MACADDR_P1);
496 ((u8 *)InformationBuffer)[0]= (u8)GenericUlong ;
497 ((u8 *)InformationBuffer)[1]= (u8)(GenericUlong >> 8);
498 ((u8 *)InformationBuffer)[2]= (u8)(GenericUlong >> 16);
499 ((u8 *)InformationBuffer)[3]= (u8)(GenericUlong >> 24);
501 GenericUlong= zd_readl(E2P_MACADDR_P2);
502 ((u8 *)InformationBuffer)[4]= (u8)GenericUlong ;
503 ((u8 *)InformationBuffer)[5]= (u8)(GenericUlong >> 8);
505 *BytesWritten = ETH_ALEN;
506 *BytesNeeded = 0;
507 Status = NDIS_STATUS_SUCCESS;
508 break;
510 case OID_ZD_RD:
511 ZDPRODUCTDBG("OID_ZD_RD\r\n");
513 if (InformationBufferLength < sizeof(ZD_RD_STRUCT)-4)
515 ZDPRODUCTDBG("OID_ZD_RD: NDIS_STATUS_BUFFER_TOO_SHORT,%d,%d\r\n",InformationBufferLength,sizeof(ZD_RD_STRUCT));
516 *BytesNeeded = sizeof(ZD_RD_STRUCT);
517 *BytesWritten = 0;
518 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
519 break;
522 pZDRD = (PZD_RD_STRUCT)InformationBuffer;
524 switch (le32_to_cpu(pZDRD->ZDRdFuncId))
526 case ZDAccessPHYRegister1B:
527 ZDPRODUCTDBG("ZDAccessPHYRegister1B\r\n");
529 if (le32_to_cpu(pZDRD->ZDRdLength) < sizeof(ZD_RD_STRUCT))
531 ZDPRODUCTDBG("ZDAccessPHYRegister1B: NDIS_STATUS_BUFFER_TOO_SHORT\r\n");
532 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
533 *BytesNeeded = sizeof(ZD_RD_STRUCT);
534 *BytesWritten = 0;
535 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
536 break;
539 // Write PHY registers
540 LockPhyReg(&dot11Obj);
542 /* Remap some special PHY registers */
543 switch(le32_to_cpu(pZDRD->Buffer[0]))
545 case 4: //CR4
546 IoAddress = 0x20;
547 break;
548 case 5: //CR5
549 IoAddress = 0x10;
550 break;
551 case 6: //CR6
552 IoAddress = 0x14;
553 break;
554 case 7: //CR7
555 IoAddress = 0x18;
556 break;
557 case 8: //CR8
558 IoAddress = 0x1C;
559 break;
560 case 132: //CR132
561 IoAddress = 0x0210;
563 default:
564 IoAddress = le32_to_cpu(pZDRD->Buffer[0]) << 2;
565 break;
567 //if (!NeedReadProtection(Adapter, IoAddress, &(pZDRD->Buffer[1]))){
568 pZDRD->Buffer[1] = dot11Obj.GetReg(reg, IoAddress);
571 pZDRD->Buffer[1] &= 0xFFFF;
572 ZDPRODUCTDBG("Read Phy Reg (0x%x) = %x\r\n", IoAddress, pZDRD->Buffer[1]);
573 UnLockPhyReg(&dot11Obj);
575 pZDRD->Buffer[1] = cpu_to_le32(pZDRD->Buffer[1]);
576 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
577 *BytesWritten = sizeof(ZD_RD_STRUCT);
578 *BytesNeeded = 0;
579 Status = NDIS_STATUS_SUCCESS;
581 break;
583 case ZDAccessMACRegister4B:
584 ZDPRODUCTDBG("ZDAccessMACRegister4B\r\n");
586 if (le32_to_cpu(pZDRD->ZDRdLength) < (sizeof(ZD_RD_STRUCT)))
588 ZDPRODUCTDBG("ZDAccessMACRegister4B: NDIS_STATUS_BUFFER_TOO_SHORT\r\n");
589 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
590 *BytesNeeded = sizeof(ZD_RD_STRUCT);
591 *BytesWritten = 0;
592 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
593 break;
596 if (le32_to_cpu(pZDRD->Buffer[0]) < 0x1000)
598 pZDRD->Buffer[1] = cpu_to_le32(dot11Obj.GetReg(reg, le32_to_cpu(pZDRD->Buffer[0])));
600 //else if (!NeedReadProtection(Adapter, pZDRD->Buffer[0], &(pZDRD->Buffer[1]))){
601 //pZDRD->Buffer[1] = dot11Obj.GetReg(reg, pZDRD->Buffer[0]);
602 else
603 pZDRD->Buffer[1] = 0;
605 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
606 *BytesWritten = sizeof(ZD_RD_STRUCT);
607 *BytesNeeded = 0;
608 Status = NDIS_STATUS_SUCCESS;
609 break;
610 case ZDAccessROMData:
612 ZDPRODUCTDBG("ZDAccessROM read\r\n");
614 if (le32_to_cpu(pZDRD->ZDRdLength) < (sizeof(ZD_RD_STRUCT) + 4))
616 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT) + 4);
617 *BytesNeeded = (sizeof(ZD_RD_STRUCT) + 4);
618 *BytesWritten = 0;
619 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
620 break;
624 int ReadLength = le32_to_cpu(pZDRD->Buffer[1]);
625 //int ReadOffset = le32_to_cpu(pZDRD->Buffer[0]);
626 PUCHAR pDataPtr = (PUCHAR)(pZDRD+1);
627 ULONG tmpULONG;
628 PUCHAR pTmpBuffer = 0, pOldTmpBuffer;
630 /* Update the total EEPROM content */
631 //ORIGION NOT MARK
632 //RamAddr is 2nd argument, it differs from Win
633 HW_EEPROM_ACCESS(&dot11Obj, cFIRMWARE_EEPROM_OFFSET, cEPDATA_OFFSET, (E2P_END-E2P_SUBID)/2, 0);
634 //ZD1205_WriteE2P(&dot11Obj);
636 pTmpBuffer = kmalloc(E2P_END - E2P_SUBID+1, GFP_ATOMIC);
638 if (!pTmpBuffer)
640 Status = NDIS_STATUS_RESOURCES;
641 break;
644 pOldTmpBuffer = pTmpBuffer;
646 for (i = E2P_SUBID; i < E2P_END; i += 4)
648 tmpULONG = dot11Obj.GetReg(reg, i);
649 *pTmpBuffer = (UCHAR)(tmpULONG & 0xFF);
650 pTmpBuffer++;
651 *pTmpBuffer = (UCHAR)((tmpULONG >> 8) & 0xFF);
652 pTmpBuffer++;
653 *pTmpBuffer = (UCHAR)((tmpULONG >> 16) & 0xFF);
654 pTmpBuffer++;
655 *pTmpBuffer = (UCHAR)((tmpULONG >> 24) & 0xFF);
656 pTmpBuffer++;
659 memcpy(pDataPtr, pOldTmpBuffer, (E2P_END - E2P_SUBID + 1) );
660 kfree(pOldTmpBuffer);
661 *BytesWritten = sizeof(ZD_RD_STRUCT) + ReadLength;
662 *BytesNeeded = 0;
663 Status = NDIS_STATUS_SUCCESS;
666 break;
668 case ZDGetNICAdapterTally:
669 ZDPRODUCTDBG("ZDGetNICAdapterTally\r\n");
671 //ZD_RD_STRUCT contain one ULONG
672 if (le32_to_cpu(pZDRD->ZDRdLength) < (sizeof(ZD_RD_STRUCT) + sizeof(ULONG)*36))
674 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT) + sizeof(ULONG)*36);
675 *BytesNeeded = (sizeof(ZD_RD_STRUCT) + sizeof(ULONG)*37);
676 *BytesWritten = 0;
677 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
678 ZDPRODUCTDBG("ZDGetNICAdapterTally BUFFER_TOO_SHORT\r\n");
679 break;
682 zd1205_CollectHwTally(macp);
684 //txUnicastFrames
685 pZDRD->Buffer[0] = cpu_to_le32(macp->txUnicastFrm);
686 //txMulticastFrames
687 pZDRD->Buffer[1] = cpu_to_le32(macp->txMulticastFrm);
688 //txUniOctets byte size
689 pZDRD->Buffer[2] = cpu_to_le32(macp->txUnicastOctets);
690 //txMultiOctets byte size
691 pZDRD->Buffer[3] = cpu_to_le32(macp->txMulticastOctets);
692 pZDRD->Buffer[4] = 0; //txFrmUpperNDIS
693 //txFrmDrvMgt
694 pZDRD->Buffer[5] = cpu_to_le32(macp->txFrmDrvMgt);
695 pZDRD->Buffer[6] = cpu_to_le32(macp->retryFailCnt);
696 //Hardware total Tx Frame
697 pZDRD->Buffer[7] = cpu_to_le32(macp->hwTotalTxFrm);
698 //txMultipleRetriesFrames
699 pZDRD->Buffer[8] = cpu_to_le32(macp->hwRetryCnt);
701 pZDRD->Buffer[9] = cpu_to_le32(macp->hwUnderrunCnt);
703 pZDRD->Buffer[10] = cpu_to_le32(macp->DriverRxFrmCnt);
704 //rxUnicastFrames
705 pZDRD->Buffer[11] = cpu_to_le32(macp->rxUnicastFrm);
706 //rxMulticastFrames
707 pZDRD->Buffer[12] = cpu_to_le32(macp->rxMulticastFrm);
708 //rxTotalCnt
709 pZDRD->Buffer[13] = cpu_to_le32(macp->rxUnicastFrm+macp->rxMulticastFrm);
710 //NotifyNDISRxFrmCnt
711 pZDRD->Buffer[14] = cpu_to_le32(macp->rxCnt);
712 //rxUniOctets byte size
713 pZDRD->Buffer[15] = cpu_to_le32(macp->rxUnicastOctets);
714 //rxMultiOctets byte size
715 pZDRD->Buffer[16] = cpu_to_le32(macp->rxMulticastOctets);
716 // Discard by ValidateFrame
717 pZDRD->Buffer[17] = cpu_to_le32(macp->invalid_frame_good_crc);
719 pZDRD->Buffer[18] = cpu_to_le32(macp->ErrShortFrmCnt);
721 pZDRD->Buffer[19] = cpu_to_le32(macp->ErrLongFrmCnt);
722 pZDRD->Buffer[20] = 0; //DriverDiscardedFrmCauseByMulticastList
723 pZDRD->Buffer[21] = 0; //DriverDiscardedFrmCauseByFrmCtrl
724 //rxNeedFrgFrm
725 pZDRD->Buffer[22] = cpu_to_le32(macp->rxNeedFrag);
726 //DriverRxMgtFrmCnt
727 pZDRD->Buffer[23] = cpu_to_le32(macp->rxMgtFrm);
728 //Receive broadcast frame count
729 pZDRD->Buffer[24] = cpu_to_le32(macp->rxBroadcastFrm);
730 //Receive broadcast frame byte size
731 pZDRD->Buffer[25] = cpu_to_le32(macp->rxBroadcastOctets);
732 //Measured quality 11b data frame count
733 pZDRD->Buffer[26] = cpu_to_le32(macp->rx11bDataFrame);
734 //Measured quality 11g data frame count
735 pZDRD->Buffer[27] = cpu_to_le32(macp->rxOFDMDataFrame);
738 pZDRD->Buffer[28] = cpu_to_le32(macp->hwTotalRxFrm);
739 //rxPLCPCRCErrCnt
740 pZDRD->Buffer[29] = cpu_to_le32(macp->hwCRC16Cnt);
741 //rxCRC32ErrCnt
742 pZDRD->Buffer[30] = cpu_to_le32(macp->hwCRC32Cnt);
744 pZDRD->Buffer[31] = cpu_to_le32(macp->hwDecrypErr_UNI);
746 pZDRD->Buffer[32] = cpu_to_le32(macp->hwDecrypErr_Mul);
747 //rxDecrypFailCnt
748 pZDRD->Buffer[33] = cpu_to_le32(macp->hwDecrypErr_UNI+macp->hwDecrypErr_Mul);
750 pZDRD->Buffer[34] = cpu_to_le32(macp->hwRxFIFOOverrun);
751 pZDRD->Buffer[35] = 0; //LossAP
752 pZDRD->Buffer[36] = cpu_to_le32(macp->rxDiscardByNotPIBSS);
753 pZDRD->Buffer[37] = cpu_to_le32(macp->rxDiscardByAllocateBuf);;
755 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT) + sizeof(ULONG)*36);
756 *BytesWritten = sizeof(ZD_RD_STRUCT) + sizeof(ULONG)*36;
757 break;
759 case ZDContinuousTx:
760 ZDPRODUCTDBG("ZDContinuousTx\r\n");
762 if (le32_to_cpu(pZDRD->ZDRdLength) < sizeof(ZD_RD_STRUCT))
764 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
765 *BytesNeeded = sizeof(ZD_RD_STRUCT);
766 *BytesWritten = 0;
767 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
768 break;
771 pZDRD->Buffer[0] = cpu_to_le32(macp->bContinueTxMode);
772 if(macp->bContinueTx == 1)
773 pZDRD->Buffer[1] = 0x00;
774 else
775 pZDRD->Buffer[1] = cpu_to_le32(0x01);
777 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
778 break;
780 default:
781 ZDPRODUCTDBG("Unknown FunctionID: 0x%08x\r\n", le32_to_cpu(pZDRD->ZDRdFuncId));
782 break;
784 break;
786 case OID_ZD_CUSTOM:
787 ZDPRODUCTDBG("OID_ZD_CUSTOM\r\n");
789 pZDCustom = (ZD_CUSTOM_STRUCT *) InformationBuffer;
791 switch (le32_to_cpu(pZDCustom->ZDFuncId))
793 case ZDPreambleMode:
795 ZDPRODUCTDBG("ZDPreambleMode\r\n");
796 switch (macp->cardSetting.PreambleType)
798 case LONG_PREAMBLE:
799 pZDCustom->DataBuffer[0] = cpu_to_le32(ZD_PreambleLong);
800 break;
802 case SHORT_PREAMBLE:
803 pZDCustom->DataBuffer[0] = cpu_to_le32(ZD_PreambleShort);
804 break;
806 default:
807 pZDCustom->DataBuffer[0] = cpu_to_le32(ZD_PreambleAuto);
808 break;
810 break;
811 case ZDAdapterRegion:
812 ZDPRODUCTDBG("ZDAdapterRegion 0x%x\r\n", macp->RegionCode);
813 pZDCustom->DataBuffer[0] = cpu_to_le32(macp->RegionCode);
814 *BytesWritten = sizeof(macp->RegionCode);
815 break;
817 case ZDAdapterSupportChannel:
819 int i;
820 int AllowChannelCount = 0;
821 ULONG tmpAllowChannel = dot11Obj.AllowedChannel;
822 char *pChannelNumber = (char *)(pZDCustom->DataBuffer);
824 printk(KERN_ERR "ZDAdapterSupportChannel\n");
826 for (i = 0; i < 14; i++)
828 if (tmpAllowChannel & (1 << i))
829 AllowChannelCount++;
832 if (pZDCustom->ZDCustomLength < (AllowChannelCount + sizeof(ZD_RD_STRUCT) - sizeof(ULONG)))
834 pZDCustom->ZDCustomLength = (AllowChannelCount + sizeof(ZD_RD_STRUCT) - sizeof(ULONG));
836 *BytesNeeded = pZDCustom->ZDCustomLength;
837 *BytesWritten = 0;
838 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
839 break;
842 for (i = 0; i < 14; i++)
844 if (tmpAllowChannel & (1 << i))
845 *(pChannelNumber++) = i+1;
848 pZDCustom->ZDCustomLength = (AllowChannelCount + sizeof(ZD_RD_STRUCT) - sizeof(ULONG));
849 *BytesWritten = pZDCustom->ZDCustomLength;
852 break;
855 break;
857 case OID_ZD_GETRID:
858 ZDPRODUCTDBG("OID_ZD_GETRID\r\n");
859 rid_p = (PRID_STRUCT)InformationBuffer;
861 switch(le16_to_cpu(rid_p->rid))
863 case RID_MONITOR:
864 ZDPRODUCTDBG("RID_MONITOR\r\n");
866 zd1205_CollectHwTally(macp);
868 rid_p->data[0] = (USHORT)macp->hwCRC32Cnt;
869 rid_p->data[1] = (USHORT)macp->hwCRC16Cnt;
870 rid_p->data[2] = (USHORT)macp->hwRetryCnt;
871 rid_p->data[3] = (USHORT)macp->hwTotalRxFrm;
872 rid_p->data[4] = (USHORT)macp->hwTotalTxFrm;
873 rid_p->data[5] = 0;
874 rid_p->data[6] = 0;
875 rid_p->data[7] = 0;
876 rid_p->data[8] = 0;
877 rid_p->data[9] = 0;
879 Reset_Tally(macp);
880 *BytesWritten = sizeof(RID_STRUCT);
881 break;
883 case 0xFC7F:
884 ZDPRODUCTDBG("Get UDP Port\r\n");
886 rid_p->data[0] = 0;
887 *BytesWritten = sizeof(RID_STRUCT);
888 break;
889 default:
890 ZDPRODUCTDBG("RID: 0x%04x not support\r\n", le16_to_cpu(rid_p->rid));
891 Status = NDIS_STATUS_NOT_SUPPORTED;
892 break;
894 break;
895 case OID_ZD_GET_TALLIES:
896 ZDPRODUCTDBG("OID_ZD_GET_TALLIES\r\n");
898 pLocalTally = (PLOCAL_TALLY_STRUCT)InformationBuffer;
900 /* Zero the buffer */
901 memset(pLocalTally, 0, sizeof(LOCAL_TALLY_STRUCT));
903 zd1205_CollectHwTally(macp);
905 #if (defined(GCCK) && defined(OFDM))
906 pLocalTally->reserved2_L = cpu_to_le32(macp->rx11bDataFrame);
907 pLocalTally->reserved3_L = cpu_to_le32(macp->rxOFDMDataFrame);
908 #else
909 //pLocalTally->reserved2 = 0;
910 //pLocalTally->reserved3 = 0;
911 #endif
913 pLocalTally->reserved7_L = cpu_to_le32(macp->rxBroadcastFrm);
914 pLocalTally->reserved8_L = cpu_to_le32(macp->rxBroadcastOctets);
915 pLocalTally->rxCRC32ErrCnt_L = cpu_to_le32(macp->hwCRC32Cnt);
916 pLocalTally->rxDecrypFailCnt_L = cpu_to_le32(macp->hwDecrypErr_UNI+macp->hwDecrypErr_Mul);
917 // macp->DriverDiscardedFrm
918 pLocalTally->rxDiscardedCnt_L = cpu_to_le32(macp->invalid_frame_good_crc);
919 pLocalTally->rxMulticastFrames_L = cpu_to_le32(macp->rxMulticastFrm);
920 pLocalTally->rxMultiOctets_L = cpu_to_le32(macp->rxMulticastOctets);
921 pLocalTally->rxPLCPCRCErrCnt_L = cpu_to_le32(macp->hwCRC16Cnt);
922 //(macp->rxMulticastFrm+macp->rxUnicastFrm)
923 pLocalTally->rxTotalCnt_L = cpu_to_le32(macp->rxMulticastFrm+macp->rxUnicastFrm);
924 //macp->rxUnicastFrm
925 pLocalTally->rxUnicastFrames_L = cpu_to_le32(macp->rxUnicastFrm);
926 // macp->rxUnicastOctets
927 pLocalTally->rxUniOctets_L = cpu_to_le32(macp->rxUnicastOctets);
928 //pLocalTally->txMulticastFrames = 0; // macp->txMulticastFrm
929 //pLocalTally->txMultiOctets = 0; // macp->txMulticastOctets
930 pLocalTally->txMultipleRetriesFrames_L = cpu_to_le32(macp->hwRetryCnt);
931 pLocalTally->txRetryLimitExceeded_L = cpu_to_le32(macp->retryFailCnt);
932 //pLocalTally->txUnicastFrames = 0; // macp->txUnicastFrm
933 //pLocalTally->txUniOctets = 0; // macp->txUnicastOctets
935 *BytesWritten = sizeof(LOCAL_TALLY_STRUCT);
936 break;
938 default:
939 ZDPRODUCTDBG("%s Unknown OID = 0x%08x\r\n", "ZD1205EM_Custom_QueryInfo", Oid);
940 Status = NDIS_STATUS_NOT_SUPPORTED;
941 break;
944 return Status;
948 NDIS_STATUS ZD1205EM_Custom_SetInformation(
949 PVOID NDIS_HANDLE,
950 NDIS_OID Oid,
951 PVOID InformationBuffer,
952 ULONG InformationBufferLength,
953 PULONG BytesRead,
954 PULONG BytesNeeded
957 NDIS_STATUS Status;
958 ULONG GenericUlong;
959 ULONG IoAddress;
960 ULONG IoValue;
961 U8 SSIDLen;
963 zd1205_private_t *macp = (zd1205_private_t *) NDIS_HANDLE;
964 void *reg = macp->regp;
966 NDIS_802_11_CONFIGURATION *pConfiguration;
967 NDIS_802_11_SSID *pSSID;
968 ZD_CUSTOM_STRUCT *pZDCustom;
969 ZD_RD_STRUCT *pZDRD;
970 RID_STRUCT *rid_p;
971 //int flags;
973 Status = NDIS_STATUS_SUCCESS;
975 ZDPRODUCTDBG("***** ZD1205EM_Custom_SetInformation ******\r\n");
976 switch(Oid)
978 case OID_802_11_DESIRED_RATES:
979 ZDPRODUCTDBG("OID_802_11_DESIRED_RATES\r\n");
981 /* Fixed the Tx rate */
982 GenericUlong = le32_to_cpu(*((ULONG*) InformationBuffer));
984 macp->cardSetting.FixedRate = Rate_Convert((GenericUlong & 0x7f));
985 macp->bFixedRate = 1;
986 ZDPRODUCTDBG("Rate: 0x%08x\r\n", macp->cardSetting.FixedRate);
988 Status = NDIS_STATUS_SUCCESS;
989 break;
991 case OID_802_11_CONFIGURATION:
992 case OID_ZDX_802_11_CONFIGURATION:
993 ZDPRODUCTDBG("OID_802_11_CONFIGURATION\r\n");
995 if (InformationBuffer == NULL ||
996 (InformationBufferLength < sizeof(NDIS_802_11_CONFIGURATION)))
998 Status = NDIS_STATUS_INVALID_LENGTH;
999 break;
1002 pConfiguration = (PNDIS_802_11_CONFIGURATION) InformationBuffer;
1004 /* Update Beacon */
1006 //U16 p = (U16) le32_to_cpu(pConfiguration->BeaconPeriod);
1007 //U8 BcnInterval[2];
1008 //U16 *p = (U16 *)&BcnInterval;
1010 //BcnInterval[0] = (U8)(pConfiguration->BeaconPeriod);
1011 //BcnInterval[1] = (U8)(pConfiguration->BeaconPeriod >> 8);
1013 //HW_UpdateBcnInterval(&dot11Obj, *p);
1015 /* Update ATIMWindow */
1017 //U16 p = (U16) le32_to_cpu(pConfiguration->ATIMWindow);
1018 //U8 ATIMWindow[2];
1019 //U16 *p = (U16 *)&ATIMWindow;
1021 //ATIMWindow[0] = (U8)(pConfiguration->ATIMWindow);
1022 //ATIMWindow[1] = (U8)(pConfiguration->ATIMWindow >> 8);
1024 //HW_UpdateATIMWindow(&dot11Obj, *p);
1026 /* Update Channel */
1028 ULONG ChannelNo=0;
1029 UCHAR IntValue = 0xFF;
1030 #ifdef ZDCONF_80211A_SUPPORT
1031 ChannelNo = Freq_11A_to_channel(pConfiguration->DSConfig/1000);
1032 #endif
1033 if(!ChannelNo)
1034 ChannelNo=(le32_to_cpu(pConfiguration->DSConfig)/1000-2412)/5+1;
1036 /* If the desired channel is 14 */
1037 if (le32_to_cpu(pConfiguration->DSConfig) == 2484000)
1039 //macp->SaveChannel = 14;
1040 //Set_RF_Channel(Adapter, 14, (U8)dot11Obj.rfMode, 1);
1041 ChannelNo = 14;
1042 macp->cardSetting.Channel = 14;
1043 HW_SwitchChannel(&dot11Obj, 14, 1,1);
1045 else
1047 //macp->SaveChannel = (U8) ChannelNo;
1048 macp->cardSetting.Channel = ChannelNo;
1049 if(pConfiguration->DSConfig/1000> 4000)
1051 if(mMacMode != PURE_A_MODE)
1053 mMacMode = PURE_A_MODE;
1054 ChangeMacMode( PURE_A_MODE, ChannelNo);
1055 HW_SwitchChannel(&dot11Obj, ChannelNo, 1,PURE_A_MODE);
1057 else
1059 //For update iwconfig information only
1060 ChangeMacMode(PURE_A_MODE, ChannelNo);
1061 HW_SwitchChannel(&dot11Obj, ChannelNo, 1,PURE_A_MODE);
1064 else
1066 if(mMacMode == PURE_A_MODE)
1068 mMacMode = MIXED_MODE;
1069 ChangeMacMode(MIXED_MODE, ChannelNo);
1070 HW_SwitchChannel(&dot11Obj, ChannelNo, 1,MIXED_MODE);
1072 else
1074 //For update iwconfig information only
1075 ChangeMacMode(MIXED_MODE, ChannelNo);
1076 HW_SwitchChannel(&dot11Obj, ChannelNo, 1,MIXED_MODE);
1080 /* Reset the Integration value */
1081 if(pConfiguration->DSConfig/1000 < 4000)
1082 IntValue = dot11Obj.IntValue[ChannelNo-1];
1083 #ifdef ZDCONF_80211A_SUPPORT
1084 if(pConfiguration->DSConfig/1000>4000)
1086 u8 useless;
1087 if(0xff == a_OSC_get_cal_int(ChannelNo, RATE_1M, &IntValue, &useless))
1088 printk("Read a_OSC_get_cal_int fail\n");;
1089 IntValue=20; //When Initial value is too larget. The Pwr Meter will be down
1091 #endif
1092 dot11Obj.TxGainSetting = IntValue;
1093 dot11Obj.TxGainSetting2 = IntValue;
1095 LockPhyReg(&dot11Obj);
1096 dot11Obj.SetReg(reg, IntValue, ZD_CR31);
1097 //reg->CR31 = IntValue[ChannelNo-1];
1098 UnLockPhyReg(&dot11Obj);
1101 Status = NDIS_STATUS_SUCCESS;
1102 break;
1104 case OID_802_11_INFRASTRUCTURE_MODE:
1105 case OID_ZDX_802_11_INFRASTRUCTURE_MODE:
1106 ZDPRODUCTDBG("OID_802_11_INFRASTRUCTURE_MODE\r\n");
1108 if (InformationBuffer == NULL)
1110 Status = (NDIS_STATUS_INVALID_LENGTH);
1111 break;
1114 switch(le32_to_cpu(*(PULONG)InformationBuffer))
1116 case Ndis802_11IBSS:
1117 ZDPRODUCTDBG("Ndis802_11IBSS\r\n");
1118 macp->cardSetting.BssType = INDEPENDENT_BSS;
1119 zd_writel(STA_RX_FILTER, Rx_Filter);
1120 break;
1121 case Ndis802_11Infrastructure:
1122 case Ndis802_11AutoUnknown:
1123 ZDPRODUCTDBG("Ndis802_11Infrastructure\r\n");
1124 macp->cardSetting.BssType = INFRASTRUCTURE_BSS;
1125 macp->cardSetting.AuthMode = 0;
1126 zd_writel(STA_RX_FILTER, Rx_Filter);
1127 break;
1128 case AP_BSS:
1129 ZDPRODUCTDBG("AP_BSS\r\n");
1130 macp->cardSetting.BssType = AP_BSS;
1131 /* Set bssid = MacAddress */
1132 macp->BSSID[0] = macp->macAdr[0];
1133 macp->BSSID[1] = macp->macAdr[1];
1134 macp->BSSID[2] = macp->macAdr[2];
1135 macp->BSSID[3] = macp->macAdr[3];
1136 macp->BSSID[4] = macp->macAdr[4];
1137 macp->BSSID[5] = macp->macAdr[5];
1139 zd_writel(cpu_to_le32(*(u32 *)&macp->macAdr[0]), BSSID_P1);
1140 zd_writel(cpu_to_le32(*(u32 *)&macp->macAdr[4]), BSSID_P2);
1141 macp->cardSetting.AuthMode = 2;//auto auth
1142 break;
1143 default:
1144 ZDPRODUCTDBG("PSEUDO_IBSS\r\n");
1145 macp->cardSetting.BssType = PSEUDO_IBSS;
1146 macp->bPseudoIBSSMode = 1;
1147 /* Disable beacon */
1148 //GenericUlong = reg->BCNInterval;
1149 GenericUlong = dot11Obj.GetReg(reg, BCNInterval);
1150 GenericUlong &= ~BIT_24;
1151 GenericUlong &= ~BIT_25;
1152 dot11Obj.SetReg(reg, GenericUlong, BCNInterval);
1153 dot11Obj.SetReg(reg, 0, Rx_Filter);
1154 //reg->BCNInterval = GenericUlong;
1155 //zd_writel(STA_RX_FILTER, Rx_Filter);
1156 //reg->Rx_Filter = 0;
1157 break;
1160 zd_UpdateCardSetting(&macp->cardSetting);
1161 Status = NDIS_STATUS_SUCCESS;
1162 break;
1164 case OID_ZDX_802_11_SSID:
1165 ZDPRODUCTDBG("OID_ZDX_802_11_SSID\r\n");
1167 if (InformationBufferLength < sizeof(NDIS_802_11_SSID))
1169 Status = (NDIS_STATUS_INVALID_LENGTH);
1170 break;
1173 pSSID = (PNDIS_802_11_SSID)InformationBuffer;
1174 SSIDLen = le32_to_cpu(pSSID->SsidLength);
1176 if (SSIDLen > 32)
1178 SSIDLen = 32;
1181 zd1205_lock(macp);
1182 memcpy(&macp->cardSetting.Info_SSID[2], pSSID->Ssid, SSIDLen);
1183 macp->cardSetting.Info_SSID[1] = SSIDLen;
1184 zd1205_unlock(macp);
1186 Status = NDIS_STATUS_SUCCESS;
1187 break;
1189 case OID_802_11_NETWORK_TYPE_IN_USE:
1190 printk(KERN_ERR "OID_802_11_NETWORK_TYPE_IN_USE\n");
1192 //Status = NDIS_STATUS_NOT_SUPPORTED;
1193 //Linux doesn't have NETWORK_TYPE_IN_USE variable
1194 //But we need to reture a success result to GoGo
1195 Status = NDIS_STATUS_SUCCESS;
1196 break;
1198 case OID_ZD_RD:
1199 ZDPRODUCTDBG("OID_ZD_RD\r\n");
1201 if (le32_to_cpu(InformationBufferLength) < sizeof(ZD_RD_STRUCT)-4)
1203 *BytesNeeded = sizeof(ZD_RD_STRUCT);
1204 *BytesRead = 0;
1205 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
1206 break;
1209 pZDRD = (PZD_RD_STRUCT)InformationBuffer;
1211 switch (le32_to_cpu(pZDRD->ZDRdFuncId))
1213 case ZDAccessPHYRegister1B:
1214 ZDPRODUCTDBG("ZDAccessPHYRegister1B\r\n");
1216 if (le32_to_cpu(pZDRD->ZDRdLength) < sizeof(ZD_RD_STRUCT))
1218 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
1219 *BytesNeeded = (sizeof(ZD_RD_STRUCT) + sizeof(ULONG));
1220 *BytesRead = 0;
1221 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
1222 break;
1225 // Write PHY registers
1226 LockPhyReg(&dot11Obj);
1228 switch(pZDRD->Buffer[0])
1230 case 4: //CR4
1231 IoAddress = 0x20;
1232 break;
1233 case 5: //CR5
1234 IoAddress = 0x10;
1235 break;
1236 case 6: //CR6
1237 IoAddress = 0x14;
1238 break;
1239 case 7: //CR7
1240 IoAddress = 0x18;
1241 break;
1242 case 8: //CR8
1243 IoAddress = 0x1C;
1244 break;
1245 case 132: //CR132
1246 IoAddress = 0x0210;
1248 default:
1249 IoAddress = le32_to_cpu(pZDRD->Buffer[0]) << 2;
1250 break;
1252 //if (!NeedWriteProtection(Adapter, IoAddress, pZDRD->Buffer[1])){
1253 dot11Obj.SetReg(reg, IoAddress, le32_to_cpu(pZDRD->Buffer[1]));
1256 ZDPRODUCTDBG("Write Phy Reg (%x) = %x\n", le32_to_cpu(IoAddress), le32_to_cpu(pZDRD->Buffer[1]));
1257 UnLockPhyReg(&dot11Obj);
1259 *BytesRead = sizeof(ZD_RD_STRUCT);
1261 break;
1263 case ZDAccessMACRegister4B:
1264 ZDPRODUCTDBG("ZDAccessMACRegister4B\r\n");
1266 if (le32_to_cpu(pZDRD->ZDRdLength) < sizeof(ZD_RD_STRUCT))
1268 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
1269 *BytesNeeded = sizeof(ZD_RD_STRUCT);
1270 *BytesRead = 0;
1271 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
1272 break;
1274 if (le32_to_cpu(pZDRD->Buffer[0]) < 0x1000)
1276 dot11Obj.SetReg(reg, le32_to_cpu(pZDRD->Buffer[0]), le32_to_cpu(pZDRD->Buffer[1]));
1278 //else if (!NeedWriteProtection(Adapter, pZDRD->Buffer[0], pZDRD->Buffer[1])){
1279 // dot11Obj.SetReg(reg, pZDRD->Buffer[0], (pZDRD->Buffer[1]));
1282 *BytesRead = sizeof(ZD_RD_STRUCT);
1283 break;
1284 case ZDAccessROMData:
1285 ZDPRODUCTDBG("ZDAccessROM Write\r\n");
1287 if (le32_to_cpu(pZDRD->ZDRdLength) < (sizeof(ZD_RD_STRUCT) + 4))
1289 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT) + 4);
1290 *BytesNeeded = (sizeof(ZD_RD_STRUCT) + 4);
1291 *BytesRead = 0;
1292 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
1293 break;
1296 int i;
1297 int WriteLength = le32_to_cpu(pZDRD->Buffer[1]);
1298 int WriteOffset = le32_to_cpu(pZDRD->Buffer[0]);
1299 PUCHAR pDataPtr = (PUCHAR) (pZDRD+1);
1300 ULONG tmpULONG;
1301 PUCHAR pTmpBuffer = 0, pOldTmpBuffer;
1303 pTmpBuffer = kmalloc(E2P_END - E2P_SUBID+1, GFP_ATOMIC);
1305 if (!pTmpBuffer)
1307 Status = NDIS_STATUS_RESOURCES;
1308 break;
1311 pOldTmpBuffer = pTmpBuffer;
1313 for (i = E2P_SUBID; i < E2P_END; i += 4)
1315 tmpULONG = dot11Obj.GetReg(reg, i);
1316 *pTmpBuffer = (UCHAR)(tmpULONG & 0xFF);
1317 pTmpBuffer++;
1318 *pTmpBuffer = (UCHAR)((tmpULONG >> 8) & 0xFF);
1319 pTmpBuffer++;
1320 *pTmpBuffer = (UCHAR)((tmpULONG >> 16) & 0xFF);
1321 pTmpBuffer++;
1322 *pTmpBuffer = (UCHAR)((tmpULONG >> 24) & 0xFF);
1323 pTmpBuffer++;
1326 pTmpBuffer = pOldTmpBuffer;
1328 if ((WriteOffset+WriteLength) <= (E2P_END - E2P_SUBID+1))
1329 memcpy(pTmpBuffer+WriteOffset, pDataPtr, WriteLength);
1330 else
1331 Status = NDIS_STATUS_INVALID_LENGTH;
1333 for (i = E2P_SUBID; i <= E2P_END; i += 4)
1335 tmpULONG = *pTmpBuffer;
1336 pTmpBuffer++;
1337 tmpULONG |= ((ULONG)(*pTmpBuffer)) << 8;
1338 pTmpBuffer++;
1339 tmpULONG |= ((ULONG)(*pTmpBuffer)) << 16;
1340 pTmpBuffer++;
1341 tmpULONG |= ((ULONG)(*pTmpBuffer)) << 24;
1342 pTmpBuffer++;
1344 dot11Obj.SetReg(reg, i, tmpULONG);
1345 dot11Obj.DelayUs(10);
1346 ZDPRODUCTDBG("Write 0x%x with 0x%x\n", i, tmpULONG);
1349 /* Update the total EEPROM content */
1350 //RamAddr is 2nd argument, it differs from Win
1351 HW_EEPROM_ACCESS(&dot11Obj, cFIRMWARE_EEPROM_OFFSET, cEPDATA_OFFSET, (E2P_END-E2P_SUBID)/2, 1);
1352 //ZD1205_WriteE2P(&dot11Obj);
1353 kfree(pOldTmpBuffer);
1355 break;
1356 case ZDROMUpdate:
1358 ZDPRODUCTDBG("ZDROMUpdate Write\r\n");
1360 int i;
1361 PUCHAR pImage = (PUCHAR)pZDRD->Buffer;
1362 USHORT ImageLen = (USHORT)le32_to_cpu(pZDRD->ZDRdLength)-sizeof(ZD_RD_STRUCT)+8;
1363 PUCHAR pBuffer;
1364 ULONG tmpULONG;
1366 pBuffer = pImage;
1368 if (ImageLen > EEPROM_SIZE)
1370 Status = NDIS_STATUS_INVALID_LENGTH;
1371 ZDPRODUCTDBG("ImageLen>EEPROM_SIZE in ZDROMUpdate Write\n");
1372 ZDPRODUCTDBG("ImageLen:%d,EEPROM_SIZE:%d\n",ImageLen,EEPROM_SIZE);
1373 break;
1376 for (i = E2P_SUBID; i <= E2P_END; i += 4)
1378 tmpULONG = *pBuffer;
1379 pBuffer++;
1380 tmpULONG |= ((ULONG)(*pBuffer)) << 8;
1381 pBuffer++;
1382 tmpULONG |= ((ULONG)(*pBuffer)) << 16;
1383 pBuffer++;
1384 tmpULONG |= ((ULONG)(*pBuffer)) << 24;
1385 pBuffer++;
1387 dot11Obj.SetReg(reg, i, tmpULONG);
1388 dot11Obj.DelayUs(10);
1391 /* Update the total EEPROM content */
1392 //RamAddr is 2nd argument, it differs from Win
1393 HW_EEPROM_ACCESS(&dot11Obj, cFIRMWARE_EEPROM_OFFSET, cEPDATA_OFFSET, (E2P_END-E2P_SUBID)/2, 1);
1394 //ZD1205_WriteE2P(&dot11Obj);
1395 ZDPRODUCTDBG("ZDROMUpdate Write Complete\n");
1397 break;
1398 case ZDSetMACAddress:
1399 ZDPRODUCTDBG("ZDSetMACAddress\r\n");
1401 ULONG j=0;
1402 u8 *p = (u8 *)pZDRD->Buffer;
1403 j+=p[3]; j<<=8;
1404 j+=p[2]; j<<=8;
1405 j+=p[1]; j<<=8;
1406 j+=p[0];
1407 dot11Obj.SetReg(reg,E2P_MACADDR_P1,j);
1408 dot11Obj.DelayUs(10);
1409 j=0;
1410 j+=p[5]; j<<=8;
1411 j+=p[4];
1413 dot11Obj.SetReg(reg,E2P_MACADDR_P2,j);
1414 dot11Obj.DelayUs(10);
1416 //HW_EEPROM_ACCESS(&dot11Obj, 0, 0, EEPROM_SIZE, 1);
1417 //RamAddr is 2nd argument, it differs from Win
1418 HW_EEPROM_ACCESS(&dot11Obj, cFIRMWARE_EEPROM_OFFSET, cEPDATA_OFFSET, (E2P_END-E2P_SUBID)/2, 1);
1419 //ZD1205_WriteE2P(&dot11Obj);
1421 break;
1422 case ZDEEPROMDataWrite:
1423 ZDPRODUCTDBG("ZDEEPROMDataWrite\r\n");
1425 if(le32_to_cpu(pZDRD->ZDRdLength) < (sizeof(ZD_RD_STRUCT) - 4))
1427 pZDRD->ZDRdLength = sizeof(ZD_RD_STRUCT);
1428 *BytesNeeded = sizeof(ZD_RD_STRUCT);
1429 *BytesRead = 0;
1430 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
1431 break;
1434 //RamAddr is 2nd argument, it differs from Win
1435 /* Update the total EEPROM content */
1436 HW_EEPROM_ACCESS(&dot11Obj, cFIRMWARE_EEPROM_OFFSET, cEPDATA_OFFSET, (E2P_END-E2P_SUBID)/2, 1);
1437 //ZD1205_WriteE2P(&dot11Obj);
1438 break;
1440 case ZDTxPowerGainControl:
1441 ZDPRODUCTDBG("ZDTxPowerGainControl\r\n");
1443 if(le32_to_cpu(pZDRD->ZDRdLength) < (sizeof(ZD_RD_STRUCT) - 4))
1445 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
1446 *BytesNeeded = sizeof(ZD_RD_STRUCT);
1447 *BytesRead = 0;
1448 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
1449 break;
1452 if(le32_to_cpu(pZDRD->Buffer[0]) == 0)
1454 zd1205_DecreaseTxPower(macp, cTX_CCK);
1455 #if fTX_GAIN_OFDM
1456 zd1205_DecreaseTxPower(macp, cTX_OFDM);
1457 #endif
1459 else
1461 zd1205_IncreaseTxPower(macp, cTX_CCK);
1462 #if fTX_GAIN_OFDM
1463 zd1205_IncreaseTxPower(macp, cTX_OFDM);
1464 #endif
1466 break;
1468 case ZDGetNICAdapterTally:
1469 printk("Clear Tally Information !!!!!!!!!!!!!!!!11\n");
1470 ZDPRODUCTDBG("ZDGetNICAdapterTally\r\n");
1472 Reset_Tally(macp);
1473 break;
1475 case ZDContinuousTx:
1476 printk(KERN_ERR "ZDContinuousTx\n");
1478 if (le32_to_cpu(pZDRD->ZDRdLength) < sizeof(ZD_RD_STRUCT))
1480 pZDRD->ZDRdLength = cpu_to_le32(sizeof(ZD_RD_STRUCT));
1481 *BytesNeeded = sizeof(ZD_RD_STRUCT);
1482 *BytesRead = 0;
1483 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
1484 break;
1487 macp->bContinueTxMode = le32_to_cpu(pZDRD->Buffer[0]);
1488 macp->bContinueTx = le32_to_cpu(pZDRD->Buffer[1]);
1490 /* Use the Fixed Rate instead of LastSentTxRate */
1491 //macp->LastZDContinuousTxRate = macp->cardSetting.LastSentTxRate;
1492 macp->LastZDContinuousTxRate = macp->cardSetting.FixedRate;
1494 if ((macp->RF_Mode == AL7230B_RF) && (mMacMode != PURE_A_MODE)) {
1495 if (macp->LastZDContinuousTxRate > 3) {
1496 HW_Set_IF_Synthesizer(&dot11Obj, 0x00093c);
1498 else if (macp->LastZDContinuousTxRate <= 3) {
1499 HW_Set_IF_Synthesizer(&dot11Obj, 0x000abc);
1502 #ifdef ZDCONF_BANDEDGE_ADJUST
1503 // if((macp->RF_Mode == AL7230B_RF) &&
1504 // (mMacMode == PURE_A_MODE) &&
1505 // (macp->LastZDContinuousTxRate == 4) &&
1506 // (macp->PHY_36M_Setpoint_Flag == 0)
1507 // )
1508 // macp->PHY_36M_Setpoint_Flag = 1;
1509 // else if((macp->RF_Mode == AL7230B_RF) &&
1510 // (mMacMode == PURE_A_MODE) &&
1511 // (macp->LastZDContinuousTxRate != 4) &&
1512 // (macp->PHY_36M_Setpoint_Flag == 2)
1513 // )
1514 // macp->PHY_36M_Setpoint_Flag = 3;
1516 if(dot11Obj.HWFeature & BIT_21) { //band edge adjust for calibration, the production test tool must do integration value /set point compensation for other channels which are not calibrated
1517 if( (macp->RF_Mode == AL7230B_RF) &&
1518 ((4 <= macp->LastZDContinuousTxRate) && (macp->LastZDContinuousTxRate <= 9)) &&
1519 (mMacMode != PURE_A_MODE) &&
1520 (macp->cardSetting.Channel == 1 || macp->cardSetting.Channel == 11)
1523 if(macp->cardSetting.Channel == 1)
1524 HW_Set_IF_Synthesizer(&dot11Obj, 0x000abc);
1525 LockPhyReg(&dot11Obj);
1526 dot11Obj.SetReg(dot11Obj.reg, ZD_CR128, 0x10);
1527 dot11Obj.SetReg(dot11Obj.reg, ZD_CR129, 0x10);
1528 UnLockPhyReg(&dot11Obj);
1530 else if((macp->RF_Mode == AL7230B_RF) &&
1531 (macp->LastZDContinuousTxRate > 3) &&
1532 (mMacMode != PURE_A_MODE))
1534 if((macp->LastZDContinuousTxRate > 9) ||
1535 (macp->cardSetting.Channel != 1 &&
1536 macp->cardSetting.Channel != 11))
1538 if(macp->cardSetting.Channel == 1)
1539 HW_Set_IF_Synthesizer(&dot11Obj, 0x00093c);
1540 LockPhyReg(&dot11Obj);
1541 dot11Obj.SetReg(&dot11Obj.reg, ZD_CR128, 0x14);
1542 dot11Obj.SetReg(&dot11Obj, ZD_CR129, 0x12);
1543 UnLockPhyReg(&dot11Obj);
1546 else if((macp->RF_Mode == AL7230B_RF) &&
1547 (macp->LastZDContinuousTxRate <=3) &&
1548 (mMacMode != PURE_A_MODE))
1550 LockPhyReg(&dot11Obj);
1551 dot11Obj.SetReg(&dot11Obj.reg, ZD_CR128, 0x14);
1552 dot11Obj.SetReg(&dot11Obj, ZD_CR129, 0x12);
1553 UnLockPhyReg(&dot11Obj);
1557 #elif !defined(ZDCONF_BANDEDGE_ADJUST)
1558 #error "Undefined ZDCONF_BANDEDGE_ADJUST"
1559 #endif
1560 // Roger 2004-11-10 , Set for Dr.Wang request , set 0x0001c4 when CCK mode with AL2230
1561 #ifdef ZDCONF_RF_AL2230_SUPPORT
1562 if (dot11Obj.rfMode == AL2230_RF || dot11Obj.rfMode == AL2230S_RF)
1564 //if (macp->cardSetting.LastSentTxRate > 3) {
1565 if (macp->LastZDContinuousTxRate > 3)
1567 HW_Set_IF_Synthesizer(&dot11Obj, 0x0005a4);
1569 //else if (macp->cardSetting.LastSentTxRate <= 3) {
1570 else if (macp->LastZDContinuousTxRate <= 3)
1572 HW_Set_IF_Synthesizer(&dot11Obj, 0x0001c4);
1575 #endif
1577 ZDPRODUCTDBG("ZDContinuousTx TxMode=%d TxStart=%d TxRate=0x%x\r\n",
1578 macp->bContinueTxMode,
1579 macp->bContinueTx,
1580 macp->LastZDContinuousTxRate);
1582 // Start
1583 if(le32_to_cpu(pZDRD->Buffer[1]) == ContTx_Start)
1585 UCHAR tmpChr = 0;
1586 UINT RateTmp= 0;
1587 ULONG tmpvalue;
1588 ULONG nLoop;
1589 LockPhyReg(&dot11Obj);
1590 dot11Obj.SetReg(reg, ZD1205_CR2, 0x3F);
1591 dot11Obj.SetReg(reg, ZD1205_CR138, 0x28);
1592 dot11Obj.SetReg(reg, ZD1205_CR33, 0x20);
1593 // Query CR60 until change to 0x04
1594 nLoop = 20;
1595 while(nLoop--)
1597 dot11Obj.DelayUs(10*1000);// sleep 10ms
1598 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR60);
1600 if(tmpvalue == 0x04)
1601 break;
1603 if(nLoop == 0) printk("nLoop count down to zero. But it still fails\n");
1605 UnLockPhyReg(&dot11Obj);
1606 switch(le32_to_cpu(pZDRD->Buffer[0]))
1608 case ContTx_Normal: // Normal continous transmit
1610 ZDPRODUCTDBG("Start ContTx_Normal\n");
1612 macp->bContinueTx = 1;
1613 LockPhyReg(&dot11Obj);
1614 macp->PHYTestTimer = 0;
1615 //ZD1205_WRITE_REGISTER(Adapter,CR122, 0xFF); 2004/10/22 mark
1616 UnLockPhyReg(&dot11Obj);
1618 LockPhyReg(&dot11Obj);
1619 /* In order to avoid the uninitial length problem,
1620 force to set length to 0x20.
1622 dot11Obj.SetReg(reg, ZD1205_CR134, 0x20);
1624 switch (macp->LastZDContinuousTxRate)
1626 case 4: //6M
1627 RateTmp = 0xB;
1628 break;
1629 case 5: //9M
1630 RateTmp = 0xF;
1631 break;
1632 case 6: //12M
1633 RateTmp = 0xA;
1634 break;
1635 case 7: //18M
1636 RateTmp = 0xE;
1637 break;
1638 case 8: //24M
1639 RateTmp = 0x9;
1640 break;
1641 case 9: //36M
1642 RateTmp = 0xD;
1643 break;
1645 case 0xA: //48M
1646 RateTmp = 0x8;
1647 break;
1649 case 0xB: //54M
1650 RateTmp = 0xC;
1651 break;
1653 default:
1654 RateTmp = 0;
1655 break;
1658 ZDPRODUCTDBG("RateTmp=0x%08x\n", RateTmp);
1660 if (RateTmp)
1662 dot11Obj.SetReg(reg, ZD1205_CR132, RateTmp);
1664 //AcquireCtrOfPhyReg(Adapter);
1665 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR159);
1666 tmpvalue &= ~(BIT_0 + BIT_1 );
1667 tmpvalue |= BIT_2;
1668 dot11Obj.SetReg(reg, ZD1205_CR159, tmpvalue);
1670 UnLockPhyReg(&dot11Obj);
1672 dot11Obj.SetReg(reg, 0x644, 7);
1674 tmpvalue = dot11Obj.GetReg(reg, 0x648);
1675 tmpvalue &= ~BIT_0;
1676 dot11Obj.SetReg(reg, 0x648, tmpvalue);
1678 break;
1681 tmpChr = macp->LastZDContinuousTxRate;
1682 ZDPRODUCTDBG("tmpChr=0x%x\n", tmpChr);
1684 #if 0
1685 if (macp->preambleMode == 1)
1686 macp->cardSetting.PreambleType = 0x00;
1687 else if (macp->preambleMode == 2)
1688 macp->cardSetting.PreambleType = 0x20;
1689 #endif
1691 if (macp->cardSetting.PreambleType == SHORT_PREAMBLE)
1693 // short premable
1694 tmpChr |= BIT_5;
1696 else
1698 // long premable
1699 tmpChr &= ~BIT_5;
1702 /*==prince delete
1703 if (macp->RegionCode == 0x10)
1704 tmpChr &= ~BIT_6;//USA
1705 if (macp->RegionCode == 0x40)
1706 tmpChr |= BIT_6;//japan
1707 ===============*/
1709 //prince add begin
1710 if ( macp->RegionCode == 0x10 ||
1711 macp->RegionCode == 0x50 ||
1712 macp->RegionCode == 0x51 )
1713 tmpChr &= ~BIT_6;//USA , Isreal , Mexcio
1714 if ( macp->RegionCode == 0x40 ||
1715 macp->RegionCode == 0x30 ||
1716 macp->RegionCode == 0x48 ||
1717 macp->RegionCode == 0x32 )
1718 tmpChr |= BIT_6;//japan ,Europe ,Tiwan,France
1719 //prince add end
1722 dot11Obj.SetReg(reg, ZD1205_CR5, tmpChr);
1723 UnLockPhyReg(&dot11Obj);
1725 dot11Obj.SetReg(reg, 0x644, 3);
1726 break;
1728 case ContTx_CW: // CW transmit
1729 ZDPRODUCTDBG("Start CW transmit\n");
1730 macp->bContinueTx = 1;
1732 LockPhyReg(&dot11Obj);
1733 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR9);
1734 tmpvalue |= 0x18;
1735 dot11Obj.SetReg(reg, ZD1205_CR9, tmpvalue);
1736 UnLockPhyReg(&dot11Obj);
1738 dot11Obj.SetReg(reg, 0x644, 0x3);
1739 break;
1741 // Carrier suppression
1742 case ContTx_CarrierSuppression:
1743 ZDPRODUCTDBG("Start Carrier suppression transmit\n");
1744 macp->bContinueTx = 1;
1746 LockPhyReg(&dot11Obj);
1747 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR9);
1748 tmpvalue &= ~0x10;
1749 tmpvalue |= 0x8;
1750 dot11Obj.SetReg(reg, ZD1205_CR9, tmpvalue);
1752 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR32);
1753 tmpvalue |= 0x4;
1754 dot11Obj.SetReg(reg, ZD1205_CR32, tmpvalue);
1755 UnLockPhyReg(&dot11Obj);
1757 dot11Obj.SetReg(reg, 0x644, 0x3);
1758 break;
1760 default:
1761 ZDPRODUCTDBG("Continuous Tx mode: %d not support\n", pZDRD->Buffer[0]);
1762 break;
1765 else
1767 ULONG tmpvalue;
1769 // Roger 2004-11-10 , Set for Dr.Wang request , set 0x0001c4 when CCK mode with AL2230
1770 #ifdef ZDCONF_RF_AL2230_SUPPORT
1771 if (dot11Obj.rfMode == AL2230_RF || dot11Obj.rfMode == AL2230S_RF)
1773 HW_Set_IF_Synthesizer(&dot11Obj, 0x0005a4);
1775 #endif
1777 LockPhyReg(&dot11Obj);
1778 dot11Obj.SetReg(reg, ZD1205_CR2, 0x26);
1779 dot11Obj.SetReg(reg, ZD1205_CR138, 0xA8);
1780 dot11Obj.SetReg(reg, ZD1205_CR33, 0x08);
1781 UnLockPhyReg(&dot11Obj);
1782 switch(pZDRD->Buffer[0])
1784 case ContTx_Normal: // Normal continous transmit
1785 ZDPRODUCTDBG("Stop Normal Continuous Transmit\n");
1787 macp->bContinueTx = 0;
1788 LockPhyReg(&dot11Obj);
1789 macp->PHYTestTimer = 30;
1790 // ZD1205_WRITE_REGISTER(Adapter,CR122, 0x0);
1791 UnLockPhyReg(&dot11Obj);
1793 if (macp->LastZDContinuousTxRate >= 4)
1795 LockPhyReg(&dot11Obj);
1796 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR159);
1797 tmpvalue &= ~(BIT_0 + BIT_1 + BIT_2 );
1798 dot11Obj.SetReg(reg, ZD1205_CR159, tmpvalue);
1799 UnLockPhyReg(&dot11Obj);
1801 dot11Obj.SetReg(reg, 0x644, 0);
1803 tmpvalue = dot11Obj.GetReg(reg, 0x648);
1804 tmpvalue |= BIT_0;
1805 dot11Obj.SetReg(reg, 0x648, tmpvalue);
1808 else
1811 dot11Obj.SetReg(reg, 0x644, 0);
1813 tmpvalue = dot11Obj.GetReg(reg, 0x648);
1814 tmpvalue |= BIT_0;
1815 dot11Obj.SetReg(reg, 0x648, tmpvalue);
1818 break;
1819 case ContTx_CW: // CW transmit
1820 ZDPRODUCTDBG("Stop CW transmit\n");
1821 macp->bContinueTx = 0;
1822 LockPhyReg(&dot11Obj);
1823 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR9);
1824 tmpvalue &= ~0x18;
1825 dot11Obj.SetReg(reg, ZD1205_CR9, tmpvalue);
1826 UnLockPhyReg(&dot11Obj);
1827 dot11Obj.SetReg(reg, 0x644, 0x0);
1828 break;
1830 // Carrier suppression
1831 case ContTx_CarrierSuppression:
1832 ZDPRODUCTDBG("Stop Carrier suppression transmit\n");
1833 macp->bContinueTx = 0;
1834 LockPhyReg(&dot11Obj);
1835 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR9);
1836 tmpvalue &= ~0x18;
1837 dot11Obj.SetReg(reg, ZD1205_CR9, tmpvalue);
1839 tmpvalue = dot11Obj.GetReg(reg, ZD1205_CR32);
1840 tmpvalue &= ~0x4;
1841 dot11Obj.SetReg(reg, ZD1205_CR32, tmpvalue);
1842 UnLockPhyReg(&dot11Obj);
1844 dot11Obj.SetReg(reg, 0x644, 0x0);
1845 break;
1846 default:
1847 ZDPRODUCTDBG("Continuous Tx mode: %d not support\r\n", le32_to_cpu(pZDRD->Buffer[0]));
1848 break;
1851 //dot11Obj.SetReg(reg, ZD_PS_Ctrl, 0x1);
1852 //Roger 2004-11-16 SoftwareReset here to solve RX fail after TxContinue problem
1853 zd1205_device_reset(macp);
1856 break;
1858 case OID_ZD_CUSTOM:
1859 ZDPRODUCTDBG("OID_ZD_CUSTOM\r\n");
1861 pZDCustom = (ZD_CUSTOM_STRUCT *) InformationBuffer;
1863 switch (le32_to_cpu(pZDCustom->ZDFuncId))
1865 case ZDPreambleMode:
1866 ZDPRODUCTDBG("ZDPreambleMode\r\n");
1867 switch (le32_to_cpu(pZDCustom->DataBuffer[0]))
1869 case ZD_PreambleLong:
1870 macp->cardSetting.PreambleType = LONG_PREAMBLE;
1871 break;
1873 case ZD_PreambleShort:
1874 macp->cardSetting.PreambleType = SHORT_PREAMBLE;
1875 break;
1877 case ZD_PreambleAuto:
1878 macp->cardSetting.PreambleType = 2;
1879 break;
1881 break;
1882 case ZDAdapterRegion:
1883 ZDPRODUCTDBG("ZDAdapterRegion\r\n");
1885 macp->RegionCode = (USHORT)pZDCustom->DataBuffer[0];
1887 if (macp->RegionCode == 0)
1889 ULONG tmpvalue = dot11Obj.GetReg(reg, E2P_SUBID);
1890 macp->RegionCode = (USHORT)(tmpvalue >> 16);
1891 ZDPRODUCTDBG("Restore OperationRegionCode=0x%x\n", macp->RegionCode);
1894 //HW_SetRfChannel(&dot11Obj, macp->cardSetting.Channel, 1);
1895 break;
1897 case ZDAdapterSupportChannel:
1899 int i;
1900 char *pChannelNumber = (char *)(pZDCustom->DataBuffer);
1901 UINT TotalChannel = le32_to_cpu(pZDCustom->ZDCustomLength) - sizeof(ZD_RD_STRUCT) + 8;
1903 printk(KERN_ERR "ZDAdapterSupportChannel\n");
1905 if (TotalChannel > 14)
1907 *BytesRead = 0;
1908 //Status = NDIS_STATUS_INVALID_LENGTH;
1909 Status = NDIS_STATUS_SUCCESS;
1910 break;
1913 if (TotalChannel == 0)
1915 dot11Obj.AllowedChannel = dot11Obj.GetReg(reg, E2P_ALLOWED_CHANNEL);
1916 ZDPRODUCTDBG("Restore RID_CHANNEL_LIST, dot11Obj.AllowedChannel = %x\n", dot11Obj.AllowedChannel);
1917 break;
1920 dot11Obj.AllowedChannel &= ~0xffff;
1922 for (i=0; i < TotalChannel; i++)
1924 dot11Obj.AllowedChannel |= (1 << (*(pChannelNumber)-1));
1925 ZDPRODUCTDBG("AllowedChannel = %x\n", *(pChannelNumber));
1926 pChannelNumber++;
1929 ZDPRODUCTDBG("Set RID_CHANNEL_LIST, dot11Obj.AllowedChannel = %x\n", dot11Obj.AllowedChannel);
1931 break;
1933 default:
1934 ZDPRODUCTDBG("Unsupport function code: 0x%08x\r\n", (U32) pZDCustom->ZDFuncId);
1935 break;
1938 break;
1940 case OID_ZD_IO32:
1941 IoAddress = le32_to_cpu((ULONG)(*((PULONG)InformationBuffer))) & 0xffffffff;
1942 IoValue = le32_to_cpu((ULONG)(*((PULONG)InformationBuffer+ 1)));
1944 ZDPRODUCTDBG("OID_ZD_IO32\r\n");
1946 /* Write command */
1947 if (IoAddress & 0x8000)
1949 IoAddress &= 0x7fff;
1951 if (IoAddress == 0x712)
1953 /* Disable all register access */
1954 macp->PHYTestTimer = (UCHAR) IoValue;
1956 else if (IoAddress == 0x730)
1958 macp->PHYLowPower = (UCHAR) IoValue;
1959 if (!(macp->PHYLowPower & BIT_1))
1961 dot11Obj.CR31Flag = 0;
1962 macp->bTraceSetPoint = 1;
1963 HW_UpdateIntegrationValue(&dot11Obj, dot11Obj.Channel,1);
1966 else if (IoAddress == 0x903)
1968 if (IoValue & 0x80)
1970 LockPhyReg(&dot11Obj);
1971 dot11Obj.SetReg(reg, ZD1205_CR30, 0x49);
1972 UnLockPhyReg(&dot11Obj);
1974 else
1976 LockPhyReg(&dot11Obj);
1977 dot11Obj.SetReg(reg, ZD1205_CR30, 0x4b);
1978 UnLockPhyReg(&dot11Obj);
1981 IoValue &= ~0x80;
1982 macp->cardSetting.FixedRate = (UCHAR)IoValue;
1983 macp->bFixedRate = 1;
1985 else if (IoAddress == 0xa00) {
1986 HW_Set_IF_Synthesizer(&dot11Obj, IoValue);
1987 LockPhyReg(&dot11Obj);
1988 if(dot11Obj.rfMode != UW2453_RF)
1990 dot11Obj.SetReg(reg, ZD1205_CR203, 0x06);
1992 else
1994 dot11Obj.SetReg(reg, ZD1205_CR101, 0x09);
1995 dot11Obj.SetReg(reg, ZD1205_CR109, 0x13);
1996 dot11Obj.SetReg(reg, ZD1205_CR110, 0x09);
1997 dot11Obj.SetReg(reg, ZD1205_CR111, 0x13);
1998 dot11Obj.SetReg(reg, ZD1205_CR113, 0x27);
1999 dot11Obj.SetReg(reg, ZD1205_CR117, 0xFA);
2000 dot11Obj.SetReg(reg, ZD1205_CR46, 0x92);
2001 dot11Obj.SetReg(reg, ZD1205_CR127, 0x03);
2004 UnLockPhyReg(&dot11Obj);
2005 dot11Obj.CR203Flag = 2;
2008 else if (IoAddress == 0xa1a)
2010 macp->EnableTxPwrCtrl = (U8) IoValue;
2012 else
2014 ZDPRODUCTDBG("Unknown IOAddress: 0x%08x\r\n", IoAddress);
2015 break;
2018 else
2020 ZDPRODUCTDBG("Unknow command: 0x%08x\r\n", IoAddress);
2022 break;
2024 case OID_ZD_SETRID:
2025 ZDPRODUCTDBG("OID_ZD_SETRID\r\n");
2026 rid_p = (RID_STRUCT *) InformationBuffer;
2028 switch(le16_to_cpu(rid_p->rid))
2030 default:
2031 ZDPRODUCTDBG("RID: 0x%04x not support\r\n", le16_to_cpu(rid_p->rid));
2032 Status = NDIS_STATUS_NOT_SUPPORTED;
2033 break;
2036 break;
2038 case OID_ZD_SET_TALLIES:
2039 ZDPRODUCTDBG("OID_ZD_SET_TALLIES\r\n");
2040 Status = NDIS_STATUS_SUCCESS;
2041 break;
2043 default:
2044 ZDPRODUCTDBG("%s Unknown OID = 0x%08x\r\n", "ZD1205EM_Custom_SetInformation", Oid);
2045 break;
2047 return Status;
2049 #endif