card.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * File: card.c
  20. * Purpose: Provide functions to setup NIC operation mode
  21. * Functions:
  22. * s_vSafeResetTx - Rest Tx
  23. * CARDvSetRSPINF - Set RSPINF
  24. * CARDvUpdateBasicTopRate - Update BasicTopRate
  25. * CARDbAddBasicRate - Add to BasicRateSet
  26. * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
  27. * CARDvSetLoopbackMode - Set Loopback mode
  28. * CARDbSoftwareReset - Sortware reset NIC
  29. * CARDqGetTSFOffset - Calculate TSFOffset
  30. * CARDbGetCurrentTSF - Read Current NIC TSF counter
  31. * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
  32. * CARDvSetFirstNextTBTT - Set NIC Beacon time
  33. * CARDvUpdateNextTBTT - Sync. NIC Beacon time
  34. * CARDbRadioPowerOff - Turn Off NIC Radio Power
  35. * CARDbRadioPowerOn - Turn On NIC Radio Power
  36. *
  37. * Revision History:
  38. * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
  39. * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
  40. * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
  41. *
  42. */
  43. #include "tmacro.h"
  44. #include "card.h"
  45. #include "baseband.h"
  46. #include "mac.h"
  47. #include "desc.h"
  48. #include "rf.h"
  49. #include "power.h"
  50. /*--------------------- Static Definitions -------------------------*/
  51. #define C_SIFS_A 16 /* micro sec. */
  52. #define C_SIFS_BG 10
  53. #define C_EIFS 80 /* micro sec. */
  54. #define C_SLOT_SHORT 9 /* micro sec. */
  55. #define C_SLOT_LONG 20
  56. #define C_CWMIN_A 15 /* slot time */
  57. #define C_CWMIN_B 31
  58. #define C_CWMAX 1023 /* slot time */
  59. #define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */
  60. /*--------------------- Static Variables --------------------------*/
  61. static const unsigned short cwRXBCNTSFOff[MAX_RATE] = {
  62. 17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
  63. /*--------------------- Static Functions --------------------------*/
  64. static
  65. void
  66. s_vCalculateOFDMRParameter(
  67. unsigned char byRate,
  68. u8 bb_type,
  69. unsigned char *pbyTxRate,
  70. unsigned char *pbyRsvTime
  71. );
  72. /*--------------------- Export Functions --------------------------*/
  73. /*
  74. * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
  75. *
  76. * Parameters:
  77. * In:
  78. * wRate - Tx Rate
  79. * byPktType - Tx Packet type
  80. * Out:
  81. * pbyTxRate - pointer to RSPINF TxRate field
  82. * pbyRsvTime - pointer to RSPINF RsvTime field
  83. *
  84. * Return Value: none
  85. */
  86. static
  87. void
  88. s_vCalculateOFDMRParameter(
  89. unsigned char byRate,
  90. u8 bb_type,
  91. unsigned char *pbyTxRate,
  92. unsigned char *pbyRsvTime
  93. )
  94. {
  95. switch (byRate) {
  96. case RATE_6M:
  97. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  98. *pbyTxRate = 0x9B;
  99. *pbyRsvTime = 44;
  100. } else {
  101. *pbyTxRate = 0x8B;
  102. *pbyRsvTime = 50;
  103. }
  104. break;
  105. case RATE_9M:
  106. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  107. *pbyTxRate = 0x9F;
  108. *pbyRsvTime = 36;
  109. } else {
  110. *pbyTxRate = 0x8F;
  111. *pbyRsvTime = 42;
  112. }
  113. break;
  114. case RATE_12M:
  115. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  116. *pbyTxRate = 0x9A;
  117. *pbyRsvTime = 32;
  118. } else {
  119. *pbyTxRate = 0x8A;
  120. *pbyRsvTime = 38;
  121. }
  122. break;
  123. case RATE_18M:
  124. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  125. *pbyTxRate = 0x9E;
  126. *pbyRsvTime = 28;
  127. } else {
  128. *pbyTxRate = 0x8E;
  129. *pbyRsvTime = 34;
  130. }
  131. break;
  132. case RATE_36M:
  133. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  134. *pbyTxRate = 0x9D;
  135. *pbyRsvTime = 24;
  136. } else {
  137. *pbyTxRate = 0x8D;
  138. *pbyRsvTime = 30;
  139. }
  140. break;
  141. case RATE_48M:
  142. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  143. *pbyTxRate = 0x98;
  144. *pbyRsvTime = 24;
  145. } else {
  146. *pbyTxRate = 0x88;
  147. *pbyRsvTime = 30;
  148. }
  149. break;
  150. case RATE_54M:
  151. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  152. *pbyTxRate = 0x9C;
  153. *pbyRsvTime = 24;
  154. } else {
  155. *pbyTxRate = 0x8C;
  156. *pbyRsvTime = 30;
  157. }
  158. break;
  159. case RATE_24M:
  160. default:
  161. if (bb_type == BB_TYPE_11A) { /* 5GHZ */
  162. *pbyTxRate = 0x99;
  163. *pbyRsvTime = 28;
  164. } else {
  165. *pbyTxRate = 0x89;
  166. *pbyRsvTime = 34;
  167. }
  168. break;
  169. }
  170. }
  171. /*--------------------- Export Functions --------------------------*/
  172. /*
  173. * Description: Update IFS
  174. *
  175. * Parameters:
  176. * In:
  177. * priv - The adapter to be set
  178. * Out:
  179. * none
  180. *
  181. * Return Value: None.
  182. */
  183. bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type)
  184. {
  185. unsigned char byCWMaxMin = 0;
  186. unsigned char bySlot = 0;
  187. unsigned char bySIFS = 0;
  188. unsigned char byDIFS = 0;
  189. unsigned char byData;
  190. int i;
  191. /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
  192. if (bb_type == BB_TYPE_11A) {
  193. if (priv->byRFType == RF_AIROHA7230) {
  194. /* AL7230 use single PAPE and connect to PAPE_2.4G */
  195. MACvSetBBType(priv->PortOffset, BB_TYPE_11G);
  196. priv->abyBBVGA[0] = 0x20;
  197. priv->abyBBVGA[2] = 0x10;
  198. priv->abyBBVGA[3] = 0x10;
  199. BBbReadEmbedded(priv, 0xE7, &byData);
  200. if (byData == 0x1C)
  201. BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
  202. } else if (priv->byRFType == RF_UW2452) {
  203. MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
  204. priv->abyBBVGA[0] = 0x18;
  205. BBbReadEmbedded(priv, 0xE7, &byData);
  206. if (byData == 0x14) {
  207. BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
  208. BBbWriteEmbedded(priv, 0xE1, 0x57);
  209. }
  210. } else {
  211. MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
  212. }
  213. BBbWriteEmbedded(priv, 0x88, 0x03);
  214. bySlot = C_SLOT_SHORT;
  215. bySIFS = C_SIFS_A;
  216. byDIFS = C_SIFS_A + 2 * C_SLOT_SHORT;
  217. byCWMaxMin = 0xA4;
  218. } else if (bb_type == BB_TYPE_11B) {
  219. MACvSetBBType(priv->PortOffset, BB_TYPE_11B);
  220. if (priv->byRFType == RF_AIROHA7230) {
  221. priv->abyBBVGA[0] = 0x1C;
  222. priv->abyBBVGA[2] = 0x00;
  223. priv->abyBBVGA[3] = 0x00;
  224. BBbReadEmbedded(priv, 0xE7, &byData);
  225. if (byData == 0x20)
  226. BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
  227. } else if (priv->byRFType == RF_UW2452) {
  228. priv->abyBBVGA[0] = 0x14;
  229. BBbReadEmbedded(priv, 0xE7, &byData);
  230. if (byData == 0x18) {
  231. BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
  232. BBbWriteEmbedded(priv, 0xE1, 0xD3);
  233. }
  234. }
  235. BBbWriteEmbedded(priv, 0x88, 0x02);
  236. bySlot = C_SLOT_LONG;
  237. bySIFS = C_SIFS_BG;
  238. byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
  239. byCWMaxMin = 0xA5;
  240. } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
  241. MACvSetBBType(priv->PortOffset, BB_TYPE_11G);
  242. if (priv->byRFType == RF_AIROHA7230) {
  243. priv->abyBBVGA[0] = 0x1C;
  244. priv->abyBBVGA[2] = 0x00;
  245. priv->abyBBVGA[3] = 0x00;
  246. BBbReadEmbedded(priv, 0xE7, &byData);
  247. if (byData == 0x20)
  248. BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
  249. } else if (priv->byRFType == RF_UW2452) {
  250. priv->abyBBVGA[0] = 0x14;
  251. BBbReadEmbedded(priv, 0xE7, &byData);
  252. if (byData == 0x18) {
  253. BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
  254. BBbWriteEmbedded(priv, 0xE1, 0xD3);
  255. }
  256. }
  257. BBbWriteEmbedded(priv, 0x88, 0x08);
  258. bySIFS = C_SIFS_BG;
  259. if (priv->bShortSlotTime) {
  260. bySlot = C_SLOT_SHORT;
  261. byDIFS = C_SIFS_BG + 2 * C_SLOT_SHORT;
  262. } else {
  263. bySlot = C_SLOT_LONG;
  264. byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
  265. }
  266. byCWMaxMin = 0xa4;
  267. for (i = RATE_54M; i >= RATE_6M; i--) {
  268. if (priv->basic_rates & ((u32)(0x1 << i))) {
  269. byCWMaxMin |= 0x1;
  270. break;
  271. }
  272. }
  273. }
  274. if (priv->byRFType == RF_RFMD2959) {
  275. /*
  276. * bcs TX_PE will reserve 3 us hardware's processing
  277. * time here is 2 us.
  278. */
  279. bySIFS -= 3;
  280. byDIFS -= 3;
  281. /*
  282. * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
  283. * better TX throughput; MAC will need 2 us to process, so the
  284. * SIFS, DIFS can be shorter by 2 us.
  285. */
  286. }
  287. if (priv->bySIFS != bySIFS) {
  288. priv->bySIFS = bySIFS;
  289. VNSvOutPortB(priv->PortOffset + MAC_REG_SIFS, priv->bySIFS);
  290. }
  291. if (priv->byDIFS != byDIFS) {
  292. priv->byDIFS = byDIFS;
  293. VNSvOutPortB(priv->PortOffset + MAC_REG_DIFS, priv->byDIFS);
  294. }
  295. if (priv->byEIFS != C_EIFS) {
  296. priv->byEIFS = C_EIFS;
  297. VNSvOutPortB(priv->PortOffset + MAC_REG_EIFS, priv->byEIFS);
  298. }
  299. if (priv->bySlot != bySlot) {
  300. priv->bySlot = bySlot;
  301. VNSvOutPortB(priv->PortOffset + MAC_REG_SLOT, priv->bySlot);
  302. BBvSetShortSlotTime(priv);
  303. }
  304. if (priv->byCWMaxMin != byCWMaxMin) {
  305. priv->byCWMaxMin = byCWMaxMin;
  306. VNSvOutPortB(priv->PortOffset + MAC_REG_CWMAXMIN0,
  307. priv->byCWMaxMin);
  308. }
  309. priv->byPacketType = CARDbyGetPktType(priv);
  310. CARDvSetRSPINF(priv, bb_type);
  311. return true;
  312. }
  313. /*
  314. * Description: Sync. TSF counter to BSS
  315. * Get TSF offset and write to HW
  316. *
  317. * Parameters:
  318. * In:
  319. * priv - The adapter to be sync.
  320. * byRxRate - data rate of receive beacon
  321. * qwBSSTimestamp - Rx BCN's TSF
  322. * qwLocalTSF - Local TSF
  323. * Out:
  324. * none
  325. *
  326. * Return Value: none
  327. */
  328. bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate,
  329. u64 qwBSSTimestamp)
  330. {
  331. u64 local_tsf;
  332. u64 qwTSFOffset = 0;
  333. CARDbGetCurrentTSF(priv, &local_tsf);
  334. if (qwBSSTimestamp != local_tsf) {
  335. qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp,
  336. local_tsf);
  337. /* adjust TSF, HW's TSF add TSF Offset reg */
  338. VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST,
  339. (u32)qwTSFOffset);
  340. VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST + 4,
  341. (u32)(qwTSFOffset >> 32));
  342. MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL,
  343. TFTCTL_TSFSYNCEN);
  344. }
  345. return true;
  346. }
  347. /*
  348. * Description: Set NIC TSF counter for first Beacon time
  349. * Get NEXTTBTT from adjusted TSF and Beacon Interval
  350. *
  351. * Parameters:
  352. * In:
  353. * priv - The adapter to be set.
  354. * wBeaconInterval - Beacon Interval
  355. * Out:
  356. * none
  357. *
  358. * Return Value: true if succeed; otherwise false
  359. */
  360. bool CARDbSetBeaconPeriod(struct vnt_private *priv,
  361. unsigned short wBeaconInterval)
  362. {
  363. u64 qwNextTBTT = 0;
  364. CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
  365. qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
  366. /* set HW beacon interval */
  367. VNSvOutPortW(priv->PortOffset + MAC_REG_BI, wBeaconInterval);
  368. priv->wBeaconInterval = wBeaconInterval;
  369. /* Set NextTBTT */
  370. VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
  371. VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT + 4,
  372. (u32)(qwNextTBTT >> 32));
  373. MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
  374. return true;
  375. }
  376. /*
  377. * Description: Turn off Radio power
  378. *
  379. * Parameters:
  380. * In:
  381. * priv - The adapter to be turned off
  382. * Out:
  383. * none
  384. *
  385. * Return Value: true if success; otherwise false
  386. */
  387. bool CARDbRadioPowerOff(struct vnt_private *priv)
  388. {
  389. bool bResult = true;
  390. if (priv->bRadioOff)
  391. return true;
  392. switch (priv->byRFType) {
  393. case RF_RFMD2959:
  394. MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
  395. SOFTPWRCTL_TXPEINV);
  396. MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
  397. SOFTPWRCTL_SWPE1);
  398. break;
  399. case RF_AIROHA:
  400. case RF_AL2230S:
  401. case RF_AIROHA7230:
  402. MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
  403. SOFTPWRCTL_SWPE2);
  404. MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
  405. SOFTPWRCTL_SWPE3);
  406. break;
  407. }
  408. MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
  409. BBvSetDeepSleep(priv, priv->byLocalID);
  410. priv->bRadioOff = true;
  411. pr_debug("chester power off\n");
  412. MACvRegBitsOn(priv->PortOffset, MAC_REG_GPIOCTL0,
  413. LED_ACTSET); /* LED issue */
  414. return bResult;
  415. }
  416. /*
  417. * Description: Turn on Radio power
  418. *
  419. * Parameters:
  420. * In:
  421. * priv - The adapter to be turned on
  422. * Out:
  423. * none
  424. *
  425. * Return Value: true if success; otherwise false
  426. */
  427. bool CARDbRadioPowerOn(struct vnt_private *priv)
  428. {
  429. bool bResult = true;
  430. pr_debug("chester power on\n");
  431. if (priv->bRadioControlOff) {
  432. if (priv->bHWRadioOff)
  433. pr_debug("chester bHWRadioOff\n");
  434. if (priv->bRadioControlOff)
  435. pr_debug("chester bRadioControlOff\n");
  436. return false; }
  437. if (!priv->bRadioOff) {
  438. pr_debug("chester pbRadioOff\n");
  439. return true; }
  440. BBvExitDeepSleep(priv, priv->byLocalID);
  441. MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
  442. switch (priv->byRFType) {
  443. case RF_RFMD2959:
  444. MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
  445. SOFTPWRCTL_TXPEINV);
  446. MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
  447. SOFTPWRCTL_SWPE1);
  448. break;
  449. case RF_AIROHA:
  450. case RF_AL2230S:
  451. case RF_AIROHA7230:
  452. MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
  453. (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
  454. break;
  455. }
  456. priv->bRadioOff = false;
  457. pr_debug("chester power on\n");
  458. MACvRegBitsOff(priv->PortOffset, MAC_REG_GPIOCTL0,
  459. LED_ACTSET); /* LED issue */
  460. return bResult;
  461. }
  462. void
  463. CARDvSafeResetTx(
  464. struct vnt_private *priv
  465. )
  466. {
  467. unsigned int uu;
  468. struct vnt_tx_desc *pCurrTD;
  469. /* initialize TD index */
  470. priv->apTailTD[0] = priv->apCurrTD[0] = &(priv->apTD0Rings[0]);
  471. priv->apTailTD[1] = priv->apCurrTD[1] = &(priv->apTD1Rings[0]);
  472. for (uu = 0; uu < TYPE_MAXTD; uu++)
  473. priv->iTDUsed[uu] = 0;
  474. for (uu = 0; uu < priv->opts.tx_descs[0]; uu++) {
  475. pCurrTD = &(priv->apTD0Rings[uu]);
  476. pCurrTD->td0.owner = OWNED_BY_HOST;
  477. /* init all Tx Packet pointer to NULL */
  478. }
  479. for (uu = 0; uu < priv->opts.tx_descs[1]; uu++) {
  480. pCurrTD = &(priv->apTD1Rings[uu]);
  481. pCurrTD->td0.owner = OWNED_BY_HOST;
  482. /* init all Tx Packet pointer to NULL */
  483. }
  484. /* set MAC TD pointer */
  485. MACvSetCurrTXDescAddr(TYPE_TXDMA0, priv, priv->td0_pool_dma);
  486. MACvSetCurrTXDescAddr(TYPE_AC0DMA, priv, priv->td1_pool_dma);
  487. /* set MAC Beacon TX pointer */
  488. MACvSetCurrBCNTxDescAddr(priv->PortOffset,
  489. (priv->tx_beacon_dma));
  490. }
  491. /*
  492. * Description:
  493. * Reset Rx
  494. *
  495. * Parameters:
  496. * In:
  497. * priv - Pointer to the adapter
  498. * Out:
  499. * none
  500. *
  501. * Return Value: none
  502. */
  503. void
  504. CARDvSafeResetRx(
  505. struct vnt_private *priv
  506. )
  507. {
  508. unsigned int uu;
  509. struct vnt_rx_desc *pDesc;
  510. /* initialize RD index */
  511. priv->pCurrRD[0] = &(priv->aRD0Ring[0]);
  512. priv->pCurrRD[1] = &(priv->aRD1Ring[0]);
  513. /* init state, all RD is chip's */
  514. for (uu = 0; uu < priv->opts.rx_descs0; uu++) {
  515. pDesc = &(priv->aRD0Ring[uu]);
  516. pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
  517. pDesc->rd0.owner = OWNED_BY_NIC;
  518. pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
  519. }
  520. /* init state, all RD is chip's */
  521. for (uu = 0; uu < priv->opts.rx_descs1; uu++) {
  522. pDesc = &(priv->aRD1Ring[uu]);
  523. pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
  524. pDesc->rd0.owner = OWNED_BY_NIC;
  525. pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
  526. }
  527. /* set perPkt mode */
  528. MACvRx0PerPktMode(priv->PortOffset);
  529. MACvRx1PerPktMode(priv->PortOffset);
  530. /* set MAC RD pointer */
  531. MACvSetCurrRx0DescAddr(priv, priv->rd0_pool_dma);
  532. MACvSetCurrRx1DescAddr(priv, priv->rd1_pool_dma);
  533. }
  534. /*
  535. * Description: Get response Control frame rate in CCK mode
  536. *
  537. * Parameters:
  538. * In:
  539. * priv - The adapter to be set
  540. * wRateIdx - Receiving data rate
  541. * Out:
  542. * none
  543. *
  544. * Return Value: response Control frame rate
  545. */
  546. static unsigned short CARDwGetCCKControlRate(struct vnt_private *priv,
  547. unsigned short wRateIdx)
  548. {
  549. unsigned int ui = (unsigned int)wRateIdx;
  550. while (ui > RATE_1M) {
  551. if (priv->basic_rates & ((u32)0x1 << ui))
  552. return (unsigned short)ui;
  553. ui--;
  554. }
  555. return (unsigned short)RATE_1M;
  556. }
  557. /*
  558. * Description: Get response Control frame rate in OFDM mode
  559. *
  560. * Parameters:
  561. * In:
  562. * priv - The adapter to be set
  563. * wRateIdx - Receiving data rate
  564. * Out:
  565. * none
  566. *
  567. * Return Value: response Control frame rate
  568. */
  569. static unsigned short CARDwGetOFDMControlRate(struct vnt_private *priv,
  570. unsigned short wRateIdx)
  571. {
  572. unsigned int ui = (unsigned int)wRateIdx;
  573. pr_debug("BASIC RATE: %X\n", priv->basic_rates);
  574. if (!CARDbIsOFDMinBasicRate((void *)priv)) {
  575. pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
  576. if (wRateIdx > RATE_24M)
  577. wRateIdx = RATE_24M;
  578. return wRateIdx;
  579. }
  580. while (ui > RATE_11M) {
  581. if (priv->basic_rates & ((u32)0x1 << ui)) {
  582. pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
  583. return (unsigned short)ui;
  584. }
  585. ui--;
  586. }
  587. pr_debug("CARDwGetOFDMControlRate: 6M\n");
  588. return (unsigned short)RATE_24M;
  589. }
  590. /*
  591. * Description: Set RSPINF
  592. *
  593. * Parameters:
  594. * In:
  595. * priv - The adapter to be set
  596. * Out:
  597. * none
  598. *
  599. * Return Value: None.
  600. */
  601. void CARDvSetRSPINF(struct vnt_private *priv, u8 bb_type)
  602. {
  603. union vnt_phy_field_swap phy;
  604. unsigned char byTxRate, byRsvTime; /* For OFDM */
  605. unsigned long flags;
  606. spin_lock_irqsave(&priv->lock, flags);
  607. /* Set to Page1 */
  608. MACvSelectPage1(priv->PortOffset);
  609. /* RSPINF_b_1 */
  610. vnt_get_phy_field(priv, 14,
  611. CARDwGetCCKControlRate(priv, RATE_1M),
  612. PK_TYPE_11B, &phy.field_read);
  613. /* swap over to get correct write order */
  614. swap(phy.swap[0], phy.swap[1]);
  615. VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
  616. /* RSPINF_b_2 */
  617. vnt_get_phy_field(priv, 14,
  618. CARDwGetCCKControlRate(priv, RATE_2M),
  619. PK_TYPE_11B, &phy.field_read);
  620. swap(phy.swap[0], phy.swap[1]);
  621. VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
  622. /* RSPINF_b_5 */
  623. vnt_get_phy_field(priv, 14,
  624. CARDwGetCCKControlRate(priv, RATE_5M),
  625. PK_TYPE_11B, &phy.field_read);
  626. swap(phy.swap[0], phy.swap[1]);
  627. VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
  628. /* RSPINF_b_11 */
  629. vnt_get_phy_field(priv, 14,
  630. CARDwGetCCKControlRate(priv, RATE_11M),
  631. PK_TYPE_11B, &phy.field_read);
  632. swap(phy.swap[0], phy.swap[1]);
  633. VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
  634. /* RSPINF_a_6 */
  635. s_vCalculateOFDMRParameter(RATE_6M,
  636. bb_type,
  637. &byTxRate,
  638. &byRsvTime);
  639. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_6,
  640. MAKEWORD(byTxRate, byRsvTime));
  641. /* RSPINF_a_9 */
  642. s_vCalculateOFDMRParameter(RATE_9M,
  643. bb_type,
  644. &byTxRate,
  645. &byRsvTime);
  646. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_9,
  647. MAKEWORD(byTxRate, byRsvTime));
  648. /* RSPINF_a_12 */
  649. s_vCalculateOFDMRParameter(RATE_12M,
  650. bb_type,
  651. &byTxRate,
  652. &byRsvTime);
  653. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_12,
  654. MAKEWORD(byTxRate, byRsvTime));
  655. /* RSPINF_a_18 */
  656. s_vCalculateOFDMRParameter(RATE_18M,
  657. bb_type,
  658. &byTxRate,
  659. &byRsvTime);
  660. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_18,
  661. MAKEWORD(byTxRate, byRsvTime));
  662. /* RSPINF_a_24 */
  663. s_vCalculateOFDMRParameter(RATE_24M,
  664. bb_type,
  665. &byTxRate,
  666. &byRsvTime);
  667. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_24,
  668. MAKEWORD(byTxRate, byRsvTime));
  669. /* RSPINF_a_36 */
  670. s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
  671. (void *)priv,
  672. RATE_36M),
  673. bb_type,
  674. &byTxRate,
  675. &byRsvTime);
  676. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_36,
  677. MAKEWORD(byTxRate, byRsvTime));
  678. /* RSPINF_a_48 */
  679. s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
  680. (void *)priv,
  681. RATE_48M),
  682. bb_type,
  683. &byTxRate,
  684. &byRsvTime);
  685. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_48,
  686. MAKEWORD(byTxRate, byRsvTime));
  687. /* RSPINF_a_54 */
  688. s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
  689. (void *)priv,
  690. RATE_54M),
  691. bb_type,
  692. &byTxRate,
  693. &byRsvTime);
  694. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_54,
  695. MAKEWORD(byTxRate, byRsvTime));
  696. /* RSPINF_a_72 */
  697. s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
  698. (void *)priv,
  699. RATE_54M),
  700. bb_type,
  701. &byTxRate,
  702. &byRsvTime);
  703. VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_72,
  704. MAKEWORD(byTxRate, byRsvTime));
  705. /* Set to Page0 */
  706. MACvSelectPage0(priv->PortOffset);
  707. spin_unlock_irqrestore(&priv->lock, flags);
  708. }
  709. void CARDvUpdateBasicTopRate(struct vnt_private *priv)
  710. {
  711. unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
  712. unsigned char ii;
  713. /* Determines the highest basic rate. */
  714. for (ii = RATE_54M; ii >= RATE_6M; ii--) {
  715. if ((priv->basic_rates) & ((u32)(1 << ii))) {
  716. byTopOFDM = ii;
  717. break;
  718. }
  719. }
  720. priv->byTopOFDMBasicRate = byTopOFDM;
  721. for (ii = RATE_11M;; ii--) {
  722. if ((priv->basic_rates) & ((u32)(1 << ii))) {
  723. byTopCCK = ii;
  724. break;
  725. }
  726. if (ii == RATE_1M)
  727. break;
  728. }
  729. priv->byTopCCKBasicRate = byTopCCK;
  730. }
  731. bool CARDbIsOFDMinBasicRate(struct vnt_private *priv)
  732. {
  733. int ii;
  734. for (ii = RATE_54M; ii >= RATE_6M; ii--) {
  735. if ((priv->basic_rates) & ((u32)BIT(ii)))
  736. return true;
  737. }
  738. return false;
  739. }
  740. unsigned char CARDbyGetPktType(struct vnt_private *priv)
  741. {
  742. if (priv->byBBType == BB_TYPE_11A || priv->byBBType == BB_TYPE_11B)
  743. return (unsigned char)priv->byBBType;
  744. else if (CARDbIsOFDMinBasicRate((void *)priv))
  745. return PK_TYPE_11GA;
  746. else
  747. return PK_TYPE_11GB;
  748. }
  749. /*
  750. * Description: Set NIC Loopback mode
  751. *
  752. * Parameters:
  753. * In:
  754. * priv - The adapter to be set
  755. * wLoopbackMode - Loopback mode to be set
  756. * Out:
  757. * none
  758. *
  759. * Return Value: none
  760. */
  761. void CARDvSetLoopbackMode(struct vnt_private *priv,
  762. unsigned short wLoopbackMode)
  763. {
  764. switch (wLoopbackMode) {
  765. case CARD_LB_NONE:
  766. case CARD_LB_MAC:
  767. case CARD_LB_PHY:
  768. break;
  769. default:
  770. break;
  771. }
  772. /* set MAC loopback */
  773. MACvSetLoopbackMode(priv, LOBYTE(wLoopbackMode));
  774. /* set Baseband loopback */
  775. }
  776. /*
  777. * Description: Software Reset NIC
  778. *
  779. * Parameters:
  780. * In:
  781. * priv - The adapter to be reset
  782. * Out:
  783. * none
  784. *
  785. * Return Value: none
  786. */
  787. bool CARDbSoftwareReset(struct vnt_private *priv)
  788. {
  789. /* reset MAC */
  790. if (!MACbSafeSoftwareReset(priv))
  791. return false;
  792. return true;
  793. }
  794. /*
  795. * Description: Calculate TSF offset of two TSF input
  796. * Get TSF Offset from RxBCN's TSF and local TSF
  797. *
  798. * Parameters:
  799. * In:
  800. * priv - The adapter to be sync.
  801. * qwTSF1 - Rx BCN's TSF
  802. * qwTSF2 - Local TSF
  803. * Out:
  804. * none
  805. *
  806. * Return Value: TSF Offset value
  807. */
  808. u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
  809. {
  810. u64 qwTSFOffset = 0;
  811. unsigned short wRxBcnTSFOffst;
  812. wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
  813. qwTSF2 += (u64)wRxBcnTSFOffst;
  814. qwTSFOffset = qwTSF1 - qwTSF2;
  815. return qwTSFOffset;
  816. }
  817. /*
  818. * Description: Read NIC TSF counter
  819. * Get local TSF counter
  820. *
  821. * Parameters:
  822. * In:
  823. * priv - The adapter to be read
  824. * Out:
  825. * qwCurrTSF - Current TSF counter
  826. *
  827. * Return Value: true if success; otherwise false
  828. */
  829. bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *pqwCurrTSF)
  830. {
  831. void __iomem *dwIoBase = priv->PortOffset;
  832. unsigned short ww;
  833. unsigned char byData;
  834. MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
  835. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  836. VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
  837. if (!(byData & TFTCTL_TSFCNTRRD))
  838. break;
  839. }
  840. if (ww == W_MAX_TIMEOUT)
  841. return false;
  842. VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
  843. VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
  844. return true;
  845. }
  846. /*
  847. * Description: Read NIC TSF counter
  848. * Get NEXTTBTT from adjusted TSF and Beacon Interval
  849. *
  850. * Parameters:
  851. * In:
  852. * qwTSF - Current TSF counter
  853. * wbeaconInterval - Beacon Interval
  854. * Out:
  855. * qwCurrTSF - Current TSF counter
  856. *
  857. * Return Value: TSF value of next Beacon
  858. */
  859. u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
  860. {
  861. u32 beacon_int;
  862. beacon_int = wBeaconInterval * 1024;
  863. if (beacon_int) {
  864. do_div(qwTSF, beacon_int);
  865. qwTSF += 1;
  866. qwTSF *= beacon_int;
  867. }
  868. return qwTSF;
  869. }
  870. /*
  871. * Description: Set NIC TSF counter for first Beacon time
  872. * Get NEXTTBTT from adjusted TSF and Beacon Interval
  873. *
  874. * Parameters:
  875. * In:
  876. * dwIoBase - IO Base
  877. * wBeaconInterval - Beacon Interval
  878. * Out:
  879. * none
  880. *
  881. * Return Value: none
  882. */
  883. void CARDvSetFirstNextTBTT(struct vnt_private *priv,
  884. unsigned short wBeaconInterval)
  885. {
  886. void __iomem *dwIoBase = priv->PortOffset;
  887. u64 qwNextTBTT = 0;
  888. CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
  889. qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
  890. /* Set NextTBTT */
  891. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
  892. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
  893. MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
  894. }
  895. /*
  896. * Description: Sync NIC TSF counter for Beacon time
  897. * Get NEXTTBTT and write to HW
  898. *
  899. * Parameters:
  900. * In:
  901. * priv - The adapter to be set
  902. * qwTSF - Current TSF counter
  903. * wBeaconInterval - Beacon Interval
  904. * Out:
  905. * none
  906. *
  907. * Return Value: none
  908. */
  909. void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 qwTSF,
  910. unsigned short wBeaconInterval)
  911. {
  912. void __iomem *dwIoBase = priv->PortOffset;
  913. qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
  914. /* Set NextTBTT */
  915. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
  916. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
  917. MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
  918. pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF);
  919. }