2 Copyright (c) Realtek Semiconductor Corp. All rights reserved.
8 Hardware Initialization and Hardware IO for RTL8185B
12 ---------- --------------- -------------------------------
13 2006-11-15 Xiong Created
16 This file is ported from RTL8185B Windows driver.
21 /*--------------------------Include File------------------------------------*/
22 #include <linux/spinlock.h>
25 #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */
26 #include "r8180_93cx6.h" /* Card EEPROM */
29 #include "ieee80211/dot11d.h"
32 /* #define CONFIG_RTL8180_IO_MAP */
34 #define TC_3W_POLL_MAX_TRY_CNT 5
35 static u8 MAC_REG_TABLE[][2] = {
37 /* 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in HwConfigureRTL8185() */
38 /* 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185(). */
39 /* 0x1F0~0x1F8 set in MacConfig_85BASIC() */
40 {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42},
41 {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03},
42 {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03},
43 {0x94, 0x0F}, {0x95, 0x32},
44 {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00},
45 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32},
46 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4},
47 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00},
51 /* For Flextronics system Logo PCIHCT failure: */
52 /* 0x1C4~0x1CD set no-zero value to avoid PCI configuration space 0x45[7]=1 */
54 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24},
55 {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF},
56 {0x82, 0xFF}, {0x83, 0x03},
57 {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, /* lzm add 080826 */
58 {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22},/* lzm add 080826 */
64 {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5},
65 {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff},
66 {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08},
67 {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f},
68 {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f},
69 {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff},
70 {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00},
73 {0x5e, 0x00}, {0x9f, 0x03}
77 static u8 ZEBRA_AGC[] = {
79 0x7E, 0x7E, 0x7E, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72,
80 0x71, 0x70, 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62,
81 0x48, 0x47, 0x46, 0x45, 0x44, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x08, 0x07,
82 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x15, 0x16,
84 0x17, 0x17, 0x18, 0x18, 0x19, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1e, 0x1e,
85 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x23, 0x23, 0x24,
86 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F
89 static u32 ZEBRA_RF_RX_GAIN_TABLE[] = {
90 0x0096, 0x0076, 0x0056, 0x0036, 0x0016, 0x01f6, 0x01d6, 0x01b6,
91 0x0196, 0x0176, 0x00F7, 0x00D7, 0x00B7, 0x0097, 0x0077, 0x0057,
92 0x0037, 0x00FB, 0x00DB, 0x00BB, 0x00FF, 0x00E3, 0x00C3, 0x00A3,
93 0x0083, 0x0063, 0x0043, 0x0023, 0x0003, 0x01E3, 0x01C3, 0x01A3,
94 0x0183, 0x0163, 0x0143, 0x0123, 0x0103
97 static u8 OFDM_CONFIG[] = {
98 /* OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX */
99 /* OFDM reg0x3C[4]=1'b1: Enable RX power saving mode */
100 /* ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test */
103 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50,
104 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00,
106 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26,
107 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB,
109 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00,
110 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00,
112 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e,
113 0xD8, 0x3C, 0x7B, 0x10, 0x10
116 /* ---------------------------------------------------------------
118 * the code is ported from Windows source code
119 ----------------------------------------------------------------*/
122 PlatformIOWrite1Byte(
123 struct net_device *dev,
128 write_nic_byte(dev, offset, data);
129 read_nic_byte(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
134 PlatformIOWrite2Byte(
135 struct net_device *dev,
140 write_nic_word(dev, offset, data);
141 read_nic_word(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
145 u8 PlatformIORead1Byte(struct net_device *dev, u32 offset);
148 PlatformIOWrite4Byte(
149 struct net_device *dev,
155 if (offset == PhyAddr) {
156 /* For Base Band configuration. */
157 unsigned char cmdByte;
158 unsigned long dataBytes;
162 cmdByte = (u8)(data & 0x000000ff);
167 The critical section is only BB read/write race condition.
169 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for
170 acquiring the spinlock in such context.
171 2. PlatformIOWrite4Byte() MUST NOT be recursive.
173 /* NdisAcquireSpinLock( &(pDevice->IoSpinLock) ); */
175 for (idx = 0; idx < 30; idx++) {
176 /* Make sure command bit is clear before access it. */
177 u1bTmp = PlatformIORead1Byte(dev, PhyAddr);
178 if ((u1bTmp & BIT7) == 0)
184 for (idx = 0; idx < 3; idx++)
185 PlatformIOWrite1Byte(dev, offset+1+idx, ((u8 *)&dataBytes)[idx]);
187 write_nic_byte(dev, offset, cmdByte);
189 /* NdisReleaseSpinLock( &(pDevice->IoSpinLock) ); */
193 write_nic_dword(dev, offset, data);
194 read_nic_dword(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
200 struct net_device *dev,
206 data = read_nic_byte(dev, offset);
214 struct net_device *dev,
220 data = read_nic_word(dev, offset);
228 struct net_device *dev,
234 data = read_nic_dword(dev, offset);
240 void SetOutputEnableOfRfPins(struct net_device *dev)
242 write_nic_word(dev, RFPinsEnable, 0x1bff);
247 struct net_device *dev,
259 /* Check if WE and RE are cleared. */
260 for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) {
261 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
262 if ((u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0)
267 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
268 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
270 /* RTL8187S HSSI Read/Write Function */
271 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
274 u1bTmp |= RF_SW_CFG_SI; /* reg08[1]=1 Serial Interface(SI) */
277 u1bTmp &= ~RF_SW_CFG_SI; /* reg08[1]=0 Parallel Interface(PI) */
280 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
283 /* jong: HW SI read must set reg84[3]=0. */
284 u1bTmp = read_nic_byte(dev, RFPinsSelect);
286 write_nic_byte(dev, RFPinsSelect, u1bTmp);
288 /* Fill up data buffer for write operation. */
291 if (nDataBufBitCnt == 16) {
292 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
293 } else if (nDataBufBitCnt == 64) {
294 /* RTL8187S shouldn't enter this case */
295 write_nic_dword(dev, SW_3W_DB0, *((u32 *)pDataBuf));
296 write_nic_dword(dev, SW_3W_DB1, *((u32 *)(pDataBuf + 4)));
299 int ByteCnt = nDataBufBitCnt / 8;
300 /* printk("%d\n",nDataBufBitCnt); */
301 if ((nDataBufBitCnt % 8) != 0)
302 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
305 if (nDataBufBitCnt > 64)
306 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
309 for (idx = 0; idx < ByteCnt; idx++)
310 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
315 /* SI - reg274[3:0] : RF register's Address */
316 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
318 /* PI - reg274[15:12] : RF register's Address */
319 write_nic_word(dev, SW_3W_DB0, (*((u16 *)pDataBuf)) << 12);
323 /* Set up command: WE or RE. */
325 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
328 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
331 /* Check if DONE is set. */
332 for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) {
333 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
334 if ((u1bTmp & SW_3W_CMD1_DONE) != 0)
340 write_nic_byte(dev, SW_3W_CMD1, 0);
342 /* Read back data for read operation. */
345 /* Serial Interface : reg363_362[11:0] */
346 *((u16 *)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
348 /* Parallel Interface : reg361_360[11:0] */
349 *((u16 *)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
352 *((u16 *)pDataBuf) &= 0x0FFF;
361 RF_WriteReg(struct net_device *dev, u8 offset, u32 data)
366 /* Pure HW 3-wire. */
367 data2Write = (data << 4) | (u32)(offset & 0x0f);
370 HwHSSIThreeWire(dev, (u8 *)(&data2Write), len, 1, 1);
373 u32 RF_ReadReg(struct net_device *dev, u8 offset)
379 data2Write = ((u32)(offset & 0x0f));
381 HwHSSIThreeWire(dev, (u8 *)(&data2Write), wlen, 1, 0);
382 dataRead = data2Write;
388 /* by Owen on 04/07/14 for writing BB register successfully */
391 struct net_device *dev,
395 /* u8 TimeoutCounter; */
399 UCharData = (u8)((Data & 0x0000ff00) >> 8);
400 PlatformIOWrite4Byte(dev, PhyAddr, Data);
401 /* for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--) */
403 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
404 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
405 /*if(UCharData == RegisterContent) */
412 struct net_device *dev,
416 /*u8 TimeoutCounter; */
419 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
420 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
422 return RegisterContent;
427 Perform Antenna settings with antenna diversity on 87SE.
428 Created by Roger, 2008.01.25.
431 SetAntennaConfig87SE(
432 struct net_device *dev,
433 u8 DefaultAnt, /* 0: Main, 1: Aux. */
434 bool bAntDiversity /* 1:Enable, 0: Disable. */
437 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
438 bool bAntennaSwitched = true;
440 /* printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity); */
442 /* Threshold for antenna diversity. */
443 write_phy_cck(dev, 0x0c, 0x09); /* Reg0c : 09 */
445 if (bAntDiversity) { /* Enable Antenna Diversity. */
446 if (DefaultAnt == 1) { /* aux antenna */
448 /* Mac register, aux antenna */
449 write_nic_byte(dev, ANTSEL, 0x00);
451 /* Config CCK RX antenna. */
452 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */
453 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */
455 /* Config OFDM RX antenna. */
456 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */
457 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */
458 } else { /* use main antenna */
459 /* Mac register, main antenna */
460 write_nic_byte(dev, ANTSEL, 0x03);
462 /* Config CCK RX antenna. */
463 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */
464 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */
466 /* Config OFDM RX antenna. */
467 write_phy_ofdm(dev, 0x0d, 0x5c); /* Reg0d : 5c */
468 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */
471 /* Disable Antenna Diversity. */
472 if (DefaultAnt == 1) { /* aux Antenna */
473 /* Mac register, aux antenna */
474 write_nic_byte(dev, ANTSEL, 0x00);
476 /* Config CCK RX antenna. */
477 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */
478 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */
480 /* Config OFDM RX antenna. */
481 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */
482 write_phy_ofdm(dev, 0x18, 0x32); /* Reg18 : 32 */
483 } else { /* main Antenna */
484 /* Mac register, main antenna */
485 write_nic_byte(dev, ANTSEL, 0x03);
487 /* Config CCK RX antenna. */
488 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */
489 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */
491 /* Config OFDM RX antenna. */
492 write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */
493 write_phy_ofdm(dev, 0x18, 0x32); /*Reg18 : 32 */
496 priv->CurrAntennaIndex = DefaultAnt; /* Update default settings. */
497 return bAntennaSwitched;
501 ---------------------------------------------------------------
502 * Hardware Initialization.
503 * the code is ported from Windows source code
504 ----------------------------------------------------------------*/
507 ZEBRA_Config_85BASIC_HardCode(
508 struct net_device *dev
512 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
515 u32 u4bRegOffset, u4bRegValue, u4bRF23, u4bRF24;
521 =============================================================================
522 87S_PCIE :: RADIOCFG.TXT
523 =============================================================================
527 /* Page1 : reg16-reg30 */
528 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); /* switch to page1 */
529 u4bRF23 = RF_ReadReg(dev, 0x08); mdelay(1);
530 u4bRF24 = RF_ReadReg(dev, 0x09); mdelay(1);
532 if (u4bRF23 == 0x818 && u4bRF24 == 0x70C) {
534 printk(KERN_INFO "rtl8187se: card type changed from C- to D-cut\n");
537 /* Page0 : reg0-reg15 */
539 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);/* 1 */
541 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
543 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);/* 2 */
545 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);/* 3 */
547 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
548 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
549 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
550 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
551 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
552 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
553 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
554 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
555 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
556 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
557 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
558 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
561 /* Page1 : reg16-reg30 */
562 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
564 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
566 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
567 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
568 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
571 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
572 /* Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl. */
573 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
574 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
577 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
578 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
579 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); /* RX LO buffer */
581 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
582 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
583 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); /* RX LO buffer */
586 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
588 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1); /* 6 */
590 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
591 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
592 for (i = 0; i <= 36; i++) {
593 RF_WriteReg(dev, 0x01, i); mdelay(1);
594 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
597 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /* 203, 343 */
598 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); /* 400 */
600 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); /* switch to reg16-reg30, and HSSI disable 137 */
601 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
603 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); /* Z4 synthesizer loop filter setting, 392 */
604 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
606 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); /* switch to reg0-reg15, and HSSI disable */
607 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
609 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); /* CBC on, Tx Rx disable, High gain */
610 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
612 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); /* Z4 setted channel 1 */
613 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
615 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); /* LC calibration */
616 mdelay(200); /* Deay 200 ms. */ /* 0xfd */
617 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
618 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
620 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); /* switch to reg16-reg30 137, and HSSI disable 137 */
621 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
623 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
624 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
625 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
626 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
628 /* DAC calibration off 20070702 */
629 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
630 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
632 /* For crystal calibration, added by Roger, 2007.12.11. */
633 if (priv->bXtalCalibration) { /* reg 30. */
634 /* enable crystal calibration.
635 RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
636 (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
637 (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
638 So we should minus 4 BITs offset. */
639 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11 | BIT9); mdelay(1);
640 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
641 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11 | BIT9);
643 /* using default value. Xin=6, Xout=6. */
644 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
648 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); /* switch to reg0-reg15, and HSSI enable */
649 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); /* Rx BB start calibration, 00c//+edward */
650 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); /* temperature meter off */
651 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); /* Rx mode */
652 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */
653 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */
654 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */
655 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); /* Rx mode*/ /*+edward */
656 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); /* Rx mode*/ /*+edward */
657 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); /* Rx mode*/ /*+edward */
659 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); /* Rx mode*/ /*+edward */
660 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); /* Rx mode*/ /*+edward */
661 /* power save parameters. */
662 u1b24E = read_nic_byte(dev, 0x24E);
663 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
665 /*=============================================================================
667 =============================================================================
669 =============================================================================
671 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
672 CCK reg0x00[7]=1'b1 :power saving for TX (default)
673 CCK reg0x00[6]=1'b1: power saving for RX (default)
674 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
675 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
676 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
679 write_phy_cck(dev, 0x00, 0xc8);
680 write_phy_cck(dev, 0x06, 0x1c);
681 write_phy_cck(dev, 0x10, 0x78);
682 write_phy_cck(dev, 0x2e, 0xd0);
683 write_phy_cck(dev, 0x2f, 0x06);
684 write_phy_cck(dev, 0x01, 0x46);
687 write_nic_byte(dev, CCK_TXAGC, 0x10);
688 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
689 write_nic_byte(dev, ANTSEL, 0x03);
694 =============================================================================
696 =============================================================================
699 write_phy_ofdm(dev, 0x00, 0x12);
701 for (i = 0; i < 128; i++) {
703 data = ZEBRA_AGC[i+1];
705 data = data | 0x0000008F;
707 addr = i + 0x80; /* enable writing AGC table */
709 addr = addr | 0x0000008E;
711 WriteBBPortUchar(dev, data);
712 WriteBBPortUchar(dev, addr);
713 WriteBBPortUchar(dev, 0x0000008E);
716 PlatformIOWrite4Byte(dev, PhyAddr, 0x00001080); /* Annie, 2006-05-05 */
719 =============================================================================
721 =============================================================================
723 =============================================================================
726 for (i = 0; i < 60; i++) {
728 u4bRegValue = OFDM_CONFIG[i];
730 WriteBBPortUchar(dev,
732 (u4bRegOffset & 0x7f) |
733 ((u4bRegValue & 0xff) << 8)));
737 =============================================================================
739 =============================================================================
742 /* Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26. */
743 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
745 /* by amy for antenna */
751 struct net_device *dev
754 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
757 if (priv->eRFPowerState != eRfOn) {
758 /* Don't access BB/RF under disable PLL situation.
759 RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
760 Back to the original state
762 priv->InitialGain = priv->InitialGainBackUp;
766 switch (priv->InitialGain) {
767 case 1: /* m861dBm */
768 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
769 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
770 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
773 case 2: /* m862dBm */
774 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
775 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
776 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
779 case 3: /* m863dBm */
780 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
781 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
782 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
785 case 4: /* m864dBm */
786 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
787 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
788 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
792 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
793 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
794 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
798 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
799 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
800 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
804 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
805 write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1);
806 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
810 write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
811 write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1);
812 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
816 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
817 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
818 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
824 Tx Power tracking mechanism routine on 87SE.
825 Created by Roger, 2007.12.11.
828 InitTxPwrTracking87SE(
829 struct net_device *dev
834 u4bRfReg = RF_ReadReg(dev, 0x02);
836 /* Enable Thermal meter indication. */
837 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
842 struct net_device *dev
845 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
846 write_nic_dword(dev, RCR, priv->ReceiveConfig);
847 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
849 ZEBRA_Config_85BASIC_HardCode(dev);
851 /* Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06. */
852 if (priv->bDigMechanism) {
853 if (priv->InitialGain == 0)
854 priv->InitialGain = 4;
858 Enable thermal meter indication to implement TxPower tracking on 87SE.
859 We initialize thermal meter here to avoid unsuccessful configuration.
860 Added by Roger, 2007.12.11.
862 if (priv->bTxPowerTrack)
863 InitTxPwrTracking87SE(dev);
866 priv->InitialGainBackUp = priv->InitialGain;
867 UpdateInitialGain(dev);
874 struct net_device *dev
877 /* RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control. */
878 u8 bUNIVERSAL_CONTROL_RL = 0;
879 u8 bUNIVERSAL_CONTROL_AGC = 1;
880 u8 bUNIVERSAL_CONTROL_ANT = 1;
881 u8 bAUTO_RATE_FALLBACK_CTL = 1;
883 write_nic_word(dev, BRSR, 0x0fff);
885 val8 = read_nic_byte(dev, CW_CONF);
887 if (bUNIVERSAL_CONTROL_RL)
892 write_nic_byte(dev, CW_CONF, val8);
895 val8 = read_nic_byte(dev, TXAGC_CTL);
896 if (bUNIVERSAL_CONTROL_AGC) {
897 write_nic_byte(dev, CCK_TXAGC, 128);
898 write_nic_byte(dev, OFDM_TXAGC, 128);
905 write_nic_byte(dev, TXAGC_CTL, val8);
907 /* Tx Antenna including Feedback control */
908 val8 = read_nic_byte(dev, TXAGC_CTL);
910 if (bUNIVERSAL_CONTROL_ANT) {
911 write_nic_byte(dev, ANTSEL, 0x00);
914 val8 = val8 & (val8|0x02); /* xiong-2006-11-15 */
917 write_nic_byte(dev, TXAGC_CTL, val8);
919 /* Auto Rate fallback control */
920 val8 = read_nic_byte(dev, RATE_FALLBACK);
922 if (bAUTO_RATE_FALLBACK_CTL) {
923 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
925 /* <RJ_TODO_8185B> We shall set up the ARFR according to user's setting. */
926 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); /* set 1M ~ 54Mbps. */
928 write_nic_byte(dev, RATE_FALLBACK, val8);
932 MacConfig_85BASIC_HardCode(
933 struct net_device *dev)
936 ============================================================================
938 ============================================================================
942 u32 u4bRegOffset, u4bRegValue, u4bPageIndex = 0;
945 nLinesRead = sizeof(MAC_REG_TABLE)/2;
947 for (i = 0; i < nLinesRead; i++) { /* nLinesRead=101 */
948 u4bRegOffset = MAC_REG_TABLE[i][0];
949 u4bRegValue = MAC_REG_TABLE[i][1];
951 if (u4bRegOffset == 0x5e)
952 u4bPageIndex = u4bRegValue;
955 u4bRegOffset |= (u4bPageIndex << 8);
957 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
959 /* ============================================================================ */
964 struct net_device *dev)
968 MacConfig_85BASIC_HardCode(dev);
970 /* ============================================================================ */
972 /* Follow TID_AC_MAP of WMac. */
973 write_nic_word(dev, TID_AC_MAP, 0xfa50);
975 /* Interrupt Migration, Jong suggested we use set 0x0000 first, 2005.12.14, by rcnjko. */
976 write_nic_word(dev, IntMig, 0x0000);
978 /* Prevent TPC to cause CRC error. Added by Annie, 2006-06-10. */
979 PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000);
980 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
981 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
983 /* Asked for by SD3 CM Lin, 2006.06.27, by rcnjko. */
984 /* power save parameter based on "87SE power save parameters 20071127.doc", as follow. */
986 /* Enable DA10 TX power saving */
987 u1DA = read_nic_byte(dev, PHYPR);
988 write_nic_byte(dev, PHYPR, (u1DA | BIT2));
991 write_nic_word(dev, 0x360, 0x1000);
992 write_nic_word(dev, 0x362, 0x1000);
995 write_nic_word(dev, 0x370, 0x0560);
996 write_nic_word(dev, 0x372, 0x0560);
997 write_nic_word(dev, 0x374, 0x0DA4);
998 write_nic_word(dev, 0x376, 0x0DA4);
999 write_nic_word(dev, 0x378, 0x0560);
1000 write_nic_word(dev, 0x37A, 0x0560);
1001 write_nic_word(dev, 0x37C, 0x00EC);
1002 write_nic_word(dev, 0x37E, 0x00EC); /*+edward */
1003 write_nic_byte(dev, 0x24E, 0x01);
1007 GetSupportedWirelessMode8185(
1008 struct net_device *dev
1011 u8 btSupportedWirelessMode = 0;
1013 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
1014 return btSupportedWirelessMode;
1018 ActUpdateChannelAccessSetting(
1019 struct net_device *dev,
1020 WIRELESS_MODE WirelessMode,
1021 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
1024 struct r8180_priv *priv = ieee80211_priv(dev);
1025 struct ieee80211_device *ieee = priv->ieee80211;
1028 u8 bFollowLegacySetting = 0;
1033 TODO: We still don't know how to set up these registers, just follow WMAC to
1037 Jong said CWmin/CWmax register are not functional in 8185B,
1038 so we shall fill channel access realted register into AC parameter registers,
1041 ChnlAccessSetting->SIFS_Timer = 0x22; /* Suggested by Jong, 2005.12.08. */
1042 ChnlAccessSetting->DIFS_Timer = 0x1C; /* 2006.06.02, by rcnjko. */
1043 ChnlAccessSetting->SlotTimeTimer = 9; /* 2006.06.02, by rcnjko. */
1044 ChnlAccessSetting->EIFS_Timer = 0x5B; /* Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */
1045 ChnlAccessSetting->CWminIndex = 3; /* 2006.06.02, by rcnjko. */
1046 ChnlAccessSetting->CWmaxIndex = 7; /* 2006.06.02, by rcnjko. */
1048 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
1049 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); /* Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29. */
1051 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer);
1053 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
1055 write_nic_byte(dev, AckTimeOutReg, 0x5B); /* <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */
1057 { /* Legacy 802.11. */
1058 bFollowLegacySetting = 1;
1062 /* this setting is copied from rtl8187B. xiong-2006-11-13 */
1063 if (bFollowLegacySetting) {
1066 Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
1067 2005.12.01, by rcnjko.
1069 AcParam.longData = 0;
1070 AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */
1071 AcParam.f.AciAifsn.f.ACM = 0;
1072 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; /* Follow 802.11 CWmin. */
1073 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; /* Follow 802.11 CWmax. */
1074 AcParam.f.TXOPLimit = 0;
1076 /* lzm reserved 080826 */
1077 /* For turbo mode setting. port from 87B by Isaiah 2008-08-01 */
1078 if (ieee->current_network.Turbo_Enable == 1)
1079 AcParam.f.TXOPLimit = 0x01FF;
1080 /* For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB) */
1081 if (ieee->iw_mode == IW_MODE_ADHOC)
1082 AcParam.f.TXOPLimit = 0x0020;
1084 for (eACI = 0; eACI < AC_MAX; eACI++) {
1085 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
1087 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
1092 /* Retrive paramters to udpate. */
1093 eACI = pAcParam->f.AciAifsn.f.ACI;
1094 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
1095 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
1096 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
1097 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
1098 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
1102 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
1106 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
1110 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
1114 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
1118 DMESGW("SetHwReg8185(): invalid ACI: %d !\n", eACI);
1122 /* Cehck ACM bit. */
1123 /* If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13. */
1125 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
1126 AC_CODING eACI = pAciAifsn->f.ACI;
1128 /*modified Joseph */
1129 /*for 8187B AsynIORead issue */
1131 if (pAciAifsn->f.ACM) {
1135 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); /* or 0x21 */
1139 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); /* or 0x42 */
1143 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); /* or 0x84 */
1147 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI);
1154 AcmCtrl &= ((~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xDE */
1158 AcmCtrl &= ((~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xBD */
1162 AcmCtrl &= ((~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0x7B */
1169 write_nic_byte(dev, ACM_CONTROL, 0);
1177 ActSetWirelessMode8185(
1178 struct net_device *dev,
1182 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1183 struct ieee80211_device *ieee = priv->ieee80211;
1184 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1186 if ((btWirelessMode & btSupportedWirelessMode) == 0) {
1187 /* Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko. */
1188 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
1189 btWirelessMode, btSupportedWirelessMode);
1193 /* 1. Assign wireless mode to swtich if necessary. */
1194 if (btWirelessMode == WIRELESS_MODE_AUTO) {
1195 if ((btSupportedWirelessMode & WIRELESS_MODE_A)) {
1196 btWirelessMode = WIRELESS_MODE_A;
1197 } else if (btSupportedWirelessMode & WIRELESS_MODE_G) {
1198 btWirelessMode = WIRELESS_MODE_G;
1200 } else if ((btSupportedWirelessMode & WIRELESS_MODE_B)) {
1201 btWirelessMode = WIRELESS_MODE_B;
1203 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
1204 btSupportedWirelessMode);
1205 btWirelessMode = WIRELESS_MODE_B;
1209 /* 2. Swtich band: RF or BB specific actions,
1210 * for example, refresh tables in omc8255, or change initial gain if necessary.
1211 * Nothing to do for Zebra to switch band.
1212 * Update current wireless mode if we swtich to specified band successfully. */
1214 ieee->mode = (WIRELESS_MODE)btWirelessMode;
1216 /* 3. Change related setting. */
1217 if( ieee->mode == WIRELESS_MODE_A ) {
1218 DMESG("WIRELESS_MODE_A\n");
1219 } else if( ieee->mode == WIRELESS_MODE_B ) {
1220 DMESG("WIRELESS_MODE_B\n");
1221 } else if( ieee->mode == WIRELESS_MODE_G ) {
1222 DMESG("WIRELESS_MODE_G\n");
1224 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
1227 void rtl8185b_irq_enable(struct net_device *dev)
1229 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1231 priv->irq_enabled = 1;
1232 write_nic_dword(dev, IMR, priv->IntrMask);
1234 /* by amy for power save */
1236 DrvIFIndicateDisassociation(
1237 struct net_device *dev,
1241 /* nothing is needed after disassociation request. */
1245 struct net_device *dev
1248 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1251 DrvIFIndicateDisassociation(dev, unspec_reason);
1253 for (i = 0; i < 6 ; i++)
1254 priv->ieee80211->current_network.bssid[i] = 0x55;
1258 priv->ieee80211->state = IEEE80211_NOLINK;
1262 Vista add a Adhoc profile, HW radio off untill OID_DOT11_RESET_REQUEST
1263 Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
1264 Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
1266 Disable Beacon Queue Own bit, suggested by jong */
1267 ieee80211_stop_send_beacons(priv->ieee80211);
1269 priv->ieee80211->link_change(dev);
1270 notify_wx_assoc_event(priv->ieee80211);
1273 MlmeDisassociateRequest(
1274 struct net_device *dev,
1279 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1282 SendDisassociation(priv->ieee80211, asSta, asRsn);
1284 if (memcmp(priv->ieee80211->current_network.bssid, asSta, 6) == 0) {
1285 /*ShuChen TODO: change media status. */
1286 /*ShuChen TODO: What to do when disassociate. */
1287 DrvIFIndicateDisassociation(dev, unspec_reason);
1291 for (i = 0; i < 6; i++)
1292 priv->ieee80211->current_network.bssid[i] = 0x22;
1294 ieee80211_disassociate(priv->ieee80211);
1301 struct net_device *dev,
1305 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1308 Commented out by rcnjko, 2005.01.27:
1309 I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
1311 2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
1313 In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
1314 2004.10.11, by rcnjko. */
1315 MlmeDisassociateRequest(dev, priv->ieee80211->current_network.bssid, asRsn);
1317 priv->ieee80211->state = IEEE80211_NOLINK;
1321 struct net_device *dev,
1325 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1327 Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
1330 if (IS_DOT11D_ENABLE(priv->ieee80211))
1331 Dot11d_Reset(priv->ieee80211);
1332 /* In adhoc mode, update beacon frame. */
1333 if (priv->ieee80211->state == IEEE80211_LINKED) {
1334 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1335 MgntDisconnectIBSS(dev);
1337 if (priv->ieee80211->iw_mode == IW_MODE_INFRA) {
1338 /* We clear key here instead of MgntDisconnectAP() because that
1339 MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
1340 e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
1341 used to handle disassociation related things to AP, e.g. send Disassoc
1342 frame to AP. 2005.01.27, by rcnjko. */
1343 MgntDisconnectAP(dev, asRsn);
1345 /* Inidicate Disconnect, 2005.02.23, by rcnjko. */
1351 Chang RF Power State.
1352 Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
1359 struct net_device *dev,
1360 RT_RF_POWER_STATE eRFPowerState
1363 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1364 bool bResult = false;
1366 if (eRFPowerState == priv->eRFPowerState)
1369 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
1374 HalEnableRx8185Dummy(
1375 struct net_device *dev
1380 HalDisableRx8185Dummy(
1381 struct net_device *dev
1387 MgntActSet_RF_State(
1388 struct net_device *dev,
1389 RT_RF_POWER_STATE StateToSet,
1393 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1394 bool bActionAllowed = false;
1395 bool bConnectBySSID = false;
1396 RT_RF_POWER_STATE rtState;
1397 u16 RFWaitCounter = 0;
1400 Prevent the race condition of RF state change. By Bruce, 2007-11-28.
1401 Only one thread can change the RF state at one time, and others should wait to be executed.
1404 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1405 if (priv->RFChangeInProgress) {
1406 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1407 /* Set RF after the previous action is done. */
1408 while (priv->RFChangeInProgress) {
1410 udelay(1000); /* 1 ms */
1412 /* Wait too long, return FALSE to avoid to be stuck here. */
1413 if (RFWaitCounter > 1000) { /* 1sec */
1414 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
1415 /* TODO: Reset RF state? */
1420 priv->RFChangeInProgress = true;
1421 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1425 rtState = priv->eRFPowerState;
1427 switch (StateToSet) {
1430 Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
1431 the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
1433 priv->RfOffReason &= (~ChangeSource);
1435 if (!priv->RfOffReason) {
1436 priv->RfOffReason = 0;
1437 bActionAllowed = true;
1439 if (rtState == eRfOff && ChangeSource >= RF_CHANGE_BY_HW && !priv->bInHctTest)
1440 bConnectBySSID = true;
1447 /* 070125, rcnjko: we always keep connected in AP mode. */
1449 if (priv->RfOffReason > RF_CHANGE_BY_IPS) {
1452 Disconnect to current BSS when radio off. Asked by QuanTa.
1454 Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
1455 because we do NOT need to set ssid to dummy ones.
1457 MgntDisconnect(dev, disas_lv_ss);
1459 /* Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI. */
1462 priv->RfOffReason |= ChangeSource;
1463 bActionAllowed = true;
1466 priv->RfOffReason |= ChangeSource;
1467 bActionAllowed = true;
1473 if (bActionAllowed) {
1474 /* Config HW to the specified mode. */
1475 SetRFPowerState(dev, StateToSet);
1478 if (StateToSet == eRfOn) {
1479 HalEnableRx8185Dummy(dev);
1480 if (bConnectBySSID) {
1481 /* by amy not supported */
1485 else if (StateToSet == eRfOff)
1486 HalDisableRx8185Dummy(dev);
1490 /* Release RF spinlock */
1491 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1492 priv->RFChangeInProgress = false;
1493 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1494 return bActionAllowed;
1498 struct net_device *dev
1501 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1503 This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
1504 is really scheduled.
1505 The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
1506 previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
1507 blocks the IPS procedure of switching RF.
1509 priv->bSwRfProcessing = true;
1511 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
1514 To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
1517 priv->bSwRfProcessing = false;
1522 Enter the inactive power save mode. RF will be off
1526 struct net_device *dev
1529 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1530 RT_RF_POWER_STATE rtState;
1531 if (priv->bInactivePs) {
1532 rtState = priv->eRFPowerState;
1535 Do not enter IPS in the following conditions:
1536 (1) RF is already OFF or Sleep
1537 (2) bSwRfProcessing (indicates the IPS is still under going)
1538 (3) Connectted (only disconnected can trigger IPS)
1539 (4) IBSS (send Beacon)
1540 (5) AP mode (send Beacon)
1542 if (rtState == eRfOn && !priv->bSwRfProcessing
1543 && (priv->ieee80211->state != IEEE80211_LINKED)) {
1544 priv->eInactivePowerState = eRfOff;
1545 InactivePowerSave(dev);
1551 struct net_device *dev
1554 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1555 RT_RF_POWER_STATE rtState;
1556 if (priv->bInactivePs) {
1557 rtState = priv->eRFPowerState;
1558 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS) {
1559 priv->eInactivePowerState = eRfOn;
1560 InactivePowerSave(dev);
1565 void rtl8185b_adapter_start(struct net_device *dev)
1567 struct r8180_priv *priv = ieee80211_priv(dev);
1568 struct ieee80211_device *ieee = priv->ieee80211;
1570 u8 SupportedWirelessMode;
1571 u8 InitWirelessMode;
1572 u8 bInvalidWirelessMode = 0;
1578 write_nic_byte(dev, 0x24e, (BIT5|BIT6|BIT0));
1581 priv->dma_poll_mask = 0;
1582 priv->dma_poll_stop_mask = 0;
1584 HwConfigureRTL8185(dev);
1585 write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
1586 write_nic_word(dev, MAC4, ((u32 *)dev->dev_addr)[1] & 0xffff);
1587 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); /* default network type to 'No Link' */
1588 write_nic_word(dev, BcnItv, 100);
1589 write_nic_word(dev, AtimWnd, 2);
1590 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
1591 write_nic_byte(dev, WPA_CONFIG, 0);
1592 MacConfig_85BASIC(dev);
1593 /* Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko. */
1594 /* BT_DEMO_BOARD type */
1595 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
1598 -----------------------------------------------------------------------------
1600 -----------------------------------------------------------------------------
1602 /* Enable Config3.PARAM_En to revise AnaaParm. */
1603 write_nic_byte(dev, CR9346, 0xc0); /* enable config register write */
1604 tmpu8 = read_nic_byte(dev, CONFIG3);
1605 write_nic_byte(dev, CONFIG3, (tmpu8 | CONFIG3_PARM_En));
1606 /* Turn on Analog power. */
1607 /* Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko. */
1608 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
1609 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
1610 write_nic_word(dev, ANAPARAM3, 0x0010);
1612 write_nic_byte(dev, CONFIG3, tmpu8);
1613 write_nic_byte(dev, CR9346, 0x00);
1614 /* enable EEM0 and EEM1 in 9346CR */
1615 btCR9346 = read_nic_byte(dev, CR9346);
1616 write_nic_byte(dev, CR9346, (btCR9346 | 0xC0));
1618 /* B cut use LED1 to control HW RF on/off */
1619 TmpU1b = read_nic_byte(dev, CONFIG5);
1620 TmpU1b = TmpU1b & ~BIT3;
1621 write_nic_byte(dev, CONFIG5, TmpU1b);
1623 /* disable EEM0 and EEM1 in 9346CR */
1624 btCR9346 &= ~(0xC0);
1625 write_nic_byte(dev, CR9346, btCR9346);
1627 /* Enable Led (suggested by Jong) */
1628 /* B-cut RF Radio on/off 5e[3]=0 */
1629 btPSR = read_nic_byte(dev, PSR);
1630 write_nic_byte(dev, PSR, (btPSR | BIT3));
1631 /* setup initial timing for RFE. */
1632 write_nic_word(dev, RFPinsOutput, 0x0480);
1633 SetOutputEnableOfRfPins(dev);
1634 write_nic_word(dev, RFPinsSelect, 0x2488);
1640 We assume RegWirelessMode has already been initialized before,
1641 however, we has to validate the wireless mode here and provide a
1642 reasonable initialized value if necessary. 2005.01.13, by rcnjko.
1644 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1645 if ((ieee->mode != WIRELESS_MODE_B) &&
1646 (ieee->mode != WIRELESS_MODE_G) &&
1647 (ieee->mode != WIRELESS_MODE_A) &&
1648 (ieee->mode != WIRELESS_MODE_AUTO)) {
1649 /* It should be one of B, G, A, or AUTO. */
1650 bInvalidWirelessMode = 1;
1652 /* One of B, G, A, or AUTO. */
1653 /* Check if the wireless mode is supported by RF. */
1654 if ((ieee->mode != WIRELESS_MODE_AUTO) &&
1655 (ieee->mode & SupportedWirelessMode) == 0) {
1656 bInvalidWirelessMode = 1;
1660 if (bInvalidWirelessMode || ieee->mode == WIRELESS_MODE_AUTO) {
1661 /* Auto or other invalid value. */
1662 /* Assigne a wireless mode to initialize. */
1663 if ((SupportedWirelessMode & WIRELESS_MODE_A)) {
1664 InitWirelessMode = WIRELESS_MODE_A;
1665 } else if ((SupportedWirelessMode & WIRELESS_MODE_G)) {
1666 InitWirelessMode = WIRELESS_MODE_G;
1667 } else if ((SupportedWirelessMode & WIRELESS_MODE_B)) {
1668 InitWirelessMode = WIRELESS_MODE_B;
1670 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
1671 SupportedWirelessMode);
1672 InitWirelessMode = WIRELESS_MODE_B;
1675 /* Initialize RegWirelessMode if it is not a valid one. */
1676 if (bInvalidWirelessMode)
1677 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
1680 /* One of B, G, A. */
1681 InitWirelessMode = ieee->mode;
1683 /* by amy for power save */
1684 priv->eRFPowerState = eRfOff;
1685 priv->RfOffReason = 0;
1687 MgntActSet_RF_State(dev, eRfOn, 0);
1690 If inactive power mode is enabled, disable rf while in disconnected state.
1692 if (priv->bInactivePs)
1693 MgntActSet_RF_State(dev , eRfOff, RF_CHANGE_BY_IPS);
1695 /* by amy for power save */
1697 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
1699 /* ----------------------------------------------------------------------------- */
1701 rtl8185b_irq_enable(dev);
1703 netif_start_queue(dev);
1706 void rtl8185b_rx_enable(struct net_device *dev)
1709 /* for now we accept data, management & ctl frame*/
1710 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1713 if (dev->flags & IFF_PROMISC)
1714 DMESG("NIC in promisc mode");
1716 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1717 dev->flags & IFF_PROMISC) {
1718 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
1719 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
1722 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1723 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | RCR_APWRMGT | RCR_AICV;
1726 if (priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1727 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32;
1729 write_nic_dword(dev, RCR, priv->ReceiveConfig);
1733 cmd = read_nic_byte(dev, CMD);
1734 write_nic_byte(dev, CMD, cmd | (1<<CMD_RX_ENABLE_SHIFT));
1738 void rtl8185b_tx_enable(struct net_device *dev)
1742 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1744 write_nic_dword(dev, TCR, priv->TransmitConfig);
1745 byte = read_nic_byte(dev, MSR);
1746 byte |= MSR_LINK_ENEDCA;
1747 write_nic_byte(dev, MSR, byte);
1751 cmd = read_nic_byte(dev, CMD);
1752 write_nic_byte(dev, CMD, cmd | (1<<CMD_TX_ENABLE_SHIFT));