mac.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  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. *
  20. * File: mac.c
  21. *
  22. * Purpose: MAC routines
  23. *
  24. * Author: Tevin Chen
  25. *
  26. * Date: May 21, 1996
  27. *
  28. * Functions:
  29. * MACbIsRegBitsOn - Test if All test Bits On
  30. * MACbIsRegBitsOff - Test if All test Bits Off
  31. * MACbIsIntDisable - Test if MAC interrupt disable
  32. * MACvSetShortRetryLimit - Set 802.11 Short Retry limit
  33. * MACvSetLongRetryLimit - Set 802.11 Long Retry limit
  34. * MACvSetLoopbackMode - Set MAC Loopback Mode
  35. * MACvSaveContext - Save Context of MAC Registers
  36. * MACvRestoreContext - Restore Context of MAC Registers
  37. * MACbSoftwareReset - Software Reset MAC
  38. * MACbSafeRxOff - Turn Off MAC Rx
  39. * MACbSafeTxOff - Turn Off MAC Tx
  40. * MACbSafeStop - Stop MAC function
  41. * MACbShutdown - Shut down MAC
  42. * MACvInitialize - Initialize MAC
  43. * MACvSetCurrRxDescAddr - Set Rx Descriptors Address
  44. * MACvSetCurrTx0DescAddr - Set Tx0 Descriptors Address
  45. * MACvSetCurrTx1DescAddr - Set Tx1 Descriptors Address
  46. * MACvTimer0MicroSDelay - Micro Second Delay Loop by MAC
  47. *
  48. * Revision History:
  49. * 08-22-2003 Kyle Hsu : Porting MAC functions from sim53
  50. * 09-03-2003 Bryan YC Fan : Add MACvClearBusSusInd()&
  51. * MACvEnableBusSusEn()
  52. * 09-18-2003 Jerry Chen : Add MACvSetKeyEntry & MACvDisableKeyEntry
  53. *
  54. */
  55. #include "tmacro.h"
  56. #include "mac.h"
  57. /*
  58. * Description:
  59. * Test if all test bits on
  60. *
  61. * Parameters:
  62. * In:
  63. * io_base - Base Address for MAC
  64. * byRegOfs - Offset of MAC Register
  65. * byTestBits - Test bits
  66. * Out:
  67. * none
  68. *
  69. * Return Value: true if all test bits On; otherwise false
  70. *
  71. */
  72. bool MACbIsRegBitsOn(struct vnt_private *priv, unsigned char byRegOfs,
  73. unsigned char byTestBits)
  74. {
  75. void __iomem *io_base = priv->PortOffset;
  76. return (ioread8(io_base + byRegOfs) & byTestBits) == byTestBits;
  77. }
  78. /*
  79. * Description:
  80. * Test if all test bits off
  81. *
  82. * Parameters:
  83. * In:
  84. * io_base - Base Address for MAC
  85. * byRegOfs - Offset of MAC Register
  86. * byTestBits - Test bits
  87. * Out:
  88. * none
  89. *
  90. * Return Value: true if all test bits Off; otherwise false
  91. *
  92. */
  93. bool MACbIsRegBitsOff(struct vnt_private *priv, unsigned char byRegOfs,
  94. unsigned char byTestBits)
  95. {
  96. void __iomem *io_base = priv->PortOffset;
  97. return !(ioread8(io_base + byRegOfs) & byTestBits);
  98. }
  99. /*
  100. * Description:
  101. * Test if MAC interrupt disable
  102. *
  103. * Parameters:
  104. * In:
  105. * io_base - Base Address for MAC
  106. * Out:
  107. * none
  108. *
  109. * Return Value: true if interrupt is disable; otherwise false
  110. *
  111. */
  112. bool MACbIsIntDisable(struct vnt_private *priv)
  113. {
  114. void __iomem *io_base = priv->PortOffset;
  115. if (ioread32(io_base + MAC_REG_IMR))
  116. return false;
  117. return true;
  118. }
  119. /*
  120. * Description:
  121. * Set 802.11 Short Retry Limit
  122. *
  123. * Parameters:
  124. * In:
  125. * io_base - Base Address for MAC
  126. * byRetryLimit- Retry Limit
  127. * Out:
  128. * none
  129. *
  130. * Return Value: none
  131. *
  132. */
  133. void MACvSetShortRetryLimit(struct vnt_private *priv,
  134. unsigned char byRetryLimit)
  135. {
  136. void __iomem *io_base = priv->PortOffset;
  137. /* set SRT */
  138. iowrite8(byRetryLimit, io_base + MAC_REG_SRT);
  139. }
  140. /*
  141. * Description:
  142. * Set 802.11 Long Retry Limit
  143. *
  144. * Parameters:
  145. * In:
  146. * io_base - Base Address for MAC
  147. * byRetryLimit- Retry Limit
  148. * Out:
  149. * none
  150. *
  151. * Return Value: none
  152. *
  153. */
  154. void MACvSetLongRetryLimit(struct vnt_private *priv,
  155. unsigned char byRetryLimit)
  156. {
  157. void __iomem *io_base = priv->PortOffset;
  158. /* set LRT */
  159. iowrite8(byRetryLimit, io_base + MAC_REG_LRT);
  160. }
  161. /*
  162. * Description:
  163. * Set MAC Loopback mode
  164. *
  165. * Parameters:
  166. * In:
  167. * io_base - Base Address for MAC
  168. * byLoopbackMode - Loopback Mode
  169. * Out:
  170. * none
  171. *
  172. * Return Value: none
  173. *
  174. */
  175. void MACvSetLoopbackMode(struct vnt_private *priv, unsigned char byLoopbackMode)
  176. {
  177. void __iomem *io_base = priv->PortOffset;
  178. byLoopbackMode <<= 6;
  179. /* set TCR */
  180. iowrite8((ioread8(io_base + MAC_REG_TEST) & 0x3f) | byLoopbackMode,
  181. io_base + MAC_REG_TEST);
  182. }
  183. /*
  184. * Description:
  185. * Save MAC registers to context buffer
  186. *
  187. * Parameters:
  188. * In:
  189. * io_base - Base Address for MAC
  190. * Out:
  191. * cxt_buf - Context buffer
  192. *
  193. * Return Value: none
  194. *
  195. */
  196. void MACvSaveContext(struct vnt_private *priv, unsigned char *cxt_buf)
  197. {
  198. void __iomem *io_base = priv->PortOffset;
  199. /* read page0 register */
  200. memcpy_fromio(cxt_buf, io_base, MAC_MAX_CONTEXT_SIZE_PAGE0);
  201. MACvSelectPage1(io_base);
  202. /* read page1 register */
  203. memcpy_fromio(cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0, io_base,
  204. MAC_MAX_CONTEXT_SIZE_PAGE1);
  205. MACvSelectPage0(io_base);
  206. }
  207. /*
  208. * Description:
  209. * Restore MAC registers from context buffer
  210. *
  211. * Parameters:
  212. * In:
  213. * io_base - Base Address for MAC
  214. * cxt_buf - Context buffer
  215. * Out:
  216. * none
  217. *
  218. * Return Value: none
  219. *
  220. */
  221. void MACvRestoreContext(struct vnt_private *priv, unsigned char *cxt_buf)
  222. {
  223. void __iomem *io_base = priv->PortOffset;
  224. MACvSelectPage1(io_base);
  225. /* restore page1 */
  226. memcpy_toio(io_base, cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0,
  227. MAC_MAX_CONTEXT_SIZE_PAGE1);
  228. MACvSelectPage0(io_base);
  229. /* restore RCR,TCR,IMR... */
  230. memcpy_toio(io_base + MAC_REG_RCR, cxt_buf + MAC_REG_RCR,
  231. MAC_REG_ISR - MAC_REG_RCR);
  232. /* restore MAC Config. */
  233. memcpy_toio(io_base + MAC_REG_LRT, cxt_buf + MAC_REG_LRT,
  234. MAC_REG_PAGE1SEL - MAC_REG_LRT);
  235. iowrite8(*(cxt_buf + MAC_REG_CFG), io_base + MAC_REG_CFG);
  236. /* restore PS Config. */
  237. memcpy_toio(io_base + MAC_REG_PSCFG, cxt_buf + MAC_REG_PSCFG,
  238. MAC_REG_BBREGCTL - MAC_REG_PSCFG);
  239. /* restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR */
  240. iowrite32(*(u32 *)(cxt_buf + MAC_REG_TXDMAPTR0),
  241. io_base + MAC_REG_TXDMAPTR0);
  242. iowrite32(*(u32 *)(cxt_buf + MAC_REG_AC0DMAPTR),
  243. io_base + MAC_REG_AC0DMAPTR);
  244. iowrite32(*(u32 *)(cxt_buf + MAC_REG_BCNDMAPTR),
  245. io_base + MAC_REG_BCNDMAPTR);
  246. iowrite32(*(u32 *)(cxt_buf + MAC_REG_RXDMAPTR0),
  247. io_base + MAC_REG_RXDMAPTR0);
  248. iowrite32(*(u32 *)(cxt_buf + MAC_REG_RXDMAPTR1),
  249. io_base + MAC_REG_RXDMAPTR1);
  250. }
  251. /*
  252. * Description:
  253. * Software Reset MAC
  254. *
  255. * Parameters:
  256. * In:
  257. * io_base - Base Address for MAC
  258. * Out:
  259. * none
  260. *
  261. * Return Value: true if Reset Success; otherwise false
  262. *
  263. */
  264. bool MACbSoftwareReset(struct vnt_private *priv)
  265. {
  266. void __iomem *io_base = priv->PortOffset;
  267. unsigned short ww;
  268. /* turn on HOSTCR_SOFTRST, just write 0x01 to reset */
  269. iowrite8(0x01, io_base + MAC_REG_HOSTCR);
  270. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  271. if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_SOFTRST))
  272. break;
  273. }
  274. if (ww == W_MAX_TIMEOUT)
  275. return false;
  276. return true;
  277. }
  278. /*
  279. * Description:
  280. * save some important register's value, then do reset, then restore
  281. * register's value
  282. *
  283. * Parameters:
  284. * In:
  285. * io_base - Base Address for MAC
  286. * Out:
  287. * none
  288. *
  289. * Return Value: true if success; otherwise false
  290. *
  291. */
  292. bool MACbSafeSoftwareReset(struct vnt_private *priv)
  293. {
  294. unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
  295. bool bRetVal;
  296. /* PATCH....
  297. * save some important register's value, then do
  298. * reset, then restore register's value
  299. */
  300. /* save MAC context */
  301. MACvSaveContext(priv, abyTmpRegData);
  302. /* do reset */
  303. bRetVal = MACbSoftwareReset(priv);
  304. /* restore MAC context, except CR0 */
  305. MACvRestoreContext(priv, abyTmpRegData);
  306. return bRetVal;
  307. }
  308. /*
  309. * Description:
  310. * Turn Off MAC Rx
  311. *
  312. * Parameters:
  313. * In:
  314. * io_base - Base Address for MAC
  315. * Out:
  316. * none
  317. *
  318. * Return Value: true if success; otherwise false
  319. *
  320. */
  321. bool MACbSafeRxOff(struct vnt_private *priv)
  322. {
  323. void __iomem *io_base = priv->PortOffset;
  324. unsigned short ww;
  325. /* turn off wow temp for turn off Rx safely */
  326. /* Clear RX DMA0,1 */
  327. iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_RXDMACTL0);
  328. iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_RXDMACTL1);
  329. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  330. if (!(ioread32(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
  331. break;
  332. }
  333. if (ww == W_MAX_TIMEOUT) {
  334. pr_debug(" DBG_PORT80(0x10)\n");
  335. return false;
  336. }
  337. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  338. if (!(ioread32(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
  339. break;
  340. }
  341. if (ww == W_MAX_TIMEOUT) {
  342. pr_debug(" DBG_PORT80(0x11)\n");
  343. return false;
  344. }
  345. /* try to safe shutdown RX */
  346. MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_RXON);
  347. /* W_MAX_TIMEOUT is the timeout period */
  348. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  349. if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_RXONST))
  350. break;
  351. }
  352. if (ww == W_MAX_TIMEOUT) {
  353. pr_debug(" DBG_PORT80(0x12)\n");
  354. return false;
  355. }
  356. return true;
  357. }
  358. /*
  359. * Description:
  360. * Turn Off MAC Tx
  361. *
  362. * Parameters:
  363. * In:
  364. * io_base - Base Address for MAC
  365. * Out:
  366. * none
  367. *
  368. * Return Value: true if success; otherwise false
  369. *
  370. */
  371. bool MACbSafeTxOff(struct vnt_private *priv)
  372. {
  373. void __iomem *io_base = priv->PortOffset;
  374. unsigned short ww;
  375. /* Clear TX DMA */
  376. /* Tx0 */
  377. iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_TXDMACTL0);
  378. /* AC0 */
  379. iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_AC0DMACTL);
  380. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  381. if (!(ioread32(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
  382. break;
  383. }
  384. if (ww == W_MAX_TIMEOUT) {
  385. pr_debug(" DBG_PORT80(0x20)\n");
  386. return false;
  387. }
  388. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  389. if (!(ioread32(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
  390. break;
  391. }
  392. if (ww == W_MAX_TIMEOUT) {
  393. pr_debug(" DBG_PORT80(0x21)\n");
  394. return false;
  395. }
  396. /* try to safe shutdown TX */
  397. MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_TXON);
  398. /* W_MAX_TIMEOUT is the timeout period */
  399. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  400. if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_TXONST))
  401. break;
  402. }
  403. if (ww == W_MAX_TIMEOUT) {
  404. pr_debug(" DBG_PORT80(0x24)\n");
  405. return false;
  406. }
  407. return true;
  408. }
  409. /*
  410. * Description:
  411. * Stop MAC function
  412. *
  413. * Parameters:
  414. * In:
  415. * io_base - Base Address for MAC
  416. * Out:
  417. * none
  418. *
  419. * Return Value: true if success; otherwise false
  420. *
  421. */
  422. bool MACbSafeStop(struct vnt_private *priv)
  423. {
  424. void __iomem *io_base = priv->PortOffset;
  425. MACvRegBitsOff(io_base, MAC_REG_TCR, TCR_AUTOBCNTX);
  426. if (!MACbSafeRxOff(priv)) {
  427. pr_debug(" MACbSafeRxOff == false)\n");
  428. MACbSafeSoftwareReset(priv);
  429. return false;
  430. }
  431. if (!MACbSafeTxOff(priv)) {
  432. pr_debug(" MACbSafeTxOff == false)\n");
  433. MACbSafeSoftwareReset(priv);
  434. return false;
  435. }
  436. MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_MACEN);
  437. return true;
  438. }
  439. /*
  440. * Description:
  441. * Shut Down MAC
  442. *
  443. * Parameters:
  444. * In:
  445. * io_base - Base Address for MAC
  446. * Out:
  447. * none
  448. *
  449. * Return Value: true if success; otherwise false
  450. *
  451. */
  452. bool MACbShutdown(struct vnt_private *priv)
  453. {
  454. void __iomem *io_base = priv->PortOffset;
  455. /* disable MAC IMR */
  456. MACvIntDisable(io_base);
  457. MACvSetLoopbackMode(priv, MAC_LB_INTERNAL);
  458. /* stop the adapter */
  459. if (!MACbSafeStop(priv)) {
  460. MACvSetLoopbackMode(priv, MAC_LB_NONE);
  461. return false;
  462. }
  463. MACvSetLoopbackMode(priv, MAC_LB_NONE);
  464. return true;
  465. }
  466. /*
  467. * Description:
  468. * Initialize MAC
  469. *
  470. * Parameters:
  471. * In:
  472. * io_base - Base Address for MAC
  473. * Out:
  474. * none
  475. *
  476. * Return Value: none
  477. *
  478. */
  479. void MACvInitialize(struct vnt_private *priv)
  480. {
  481. void __iomem *io_base = priv->PortOffset;
  482. /* clear sticky bits */
  483. MACvClearStckDS(io_base);
  484. /* disable force PME-enable */
  485. iowrite8(PME_OVR, io_base + MAC_REG_PMC1);
  486. /* only 3253 A */
  487. /* do reset */
  488. MACbSoftwareReset(priv);
  489. /* reset TSF counter */
  490. iowrite8(TFTCTL_TSFCNTRST, io_base + MAC_REG_TFTCTL);
  491. /* enable TSF counter */
  492. iowrite8(TFTCTL_TSFCNTREN, io_base + MAC_REG_TFTCTL);
  493. }
  494. /*
  495. * Description:
  496. * Set the chip with current rx descriptor address
  497. *
  498. * Parameters:
  499. * In:
  500. * io_base - Base Address for MAC
  501. * curr_desc_addr - Descriptor Address
  502. * Out:
  503. * none
  504. *
  505. * Return Value: none
  506. *
  507. */
  508. void MACvSetCurrRx0DescAddr(struct vnt_private *priv, u32 curr_desc_addr)
  509. {
  510. void __iomem *io_base = priv->PortOffset;
  511. unsigned short ww;
  512. unsigned char org_dma_ctl;
  513. org_dma_ctl = ioread8(io_base + MAC_REG_RXDMACTL0);
  514. if (org_dma_ctl & DMACTL_RUN)
  515. iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL0 + 2);
  516. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  517. if (!(ioread8(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
  518. break;
  519. }
  520. iowrite32(curr_desc_addr, io_base + MAC_REG_RXDMAPTR0);
  521. if (org_dma_ctl & DMACTL_RUN)
  522. iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL0);
  523. }
  524. /*
  525. * Description:
  526. * Set the chip with current rx descriptor address
  527. *
  528. * Parameters:
  529. * In:
  530. * io_base - Base Address for MAC
  531. * curr_desc_addr - Descriptor Address
  532. * Out:
  533. * none
  534. *
  535. * Return Value: none
  536. *
  537. */
  538. void MACvSetCurrRx1DescAddr(struct vnt_private *priv, u32 curr_desc_addr)
  539. {
  540. void __iomem *io_base = priv->PortOffset;
  541. unsigned short ww;
  542. unsigned char org_dma_ctl;
  543. org_dma_ctl = ioread8(io_base + MAC_REG_RXDMACTL1);
  544. if (org_dma_ctl & DMACTL_RUN)
  545. iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL1 + 2);
  546. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  547. if (!(ioread8(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
  548. break;
  549. }
  550. iowrite32(curr_desc_addr, io_base + MAC_REG_RXDMAPTR1);
  551. if (org_dma_ctl & DMACTL_RUN)
  552. iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL1);
  553. }
  554. /*
  555. * Description:
  556. * Set the chip with current tx0 descriptor address
  557. *
  558. * Parameters:
  559. * In:
  560. * io_base - Base Address for MAC
  561. * curr_desc_addr - Descriptor Address
  562. * Out:
  563. * none
  564. *
  565. * Return Value: none
  566. *
  567. */
  568. void MACvSetCurrTx0DescAddrEx(struct vnt_private *priv,
  569. u32 curr_desc_addr)
  570. {
  571. void __iomem *io_base = priv->PortOffset;
  572. unsigned short ww;
  573. unsigned char org_dma_ctl;
  574. org_dma_ctl = ioread8(io_base + MAC_REG_TXDMACTL0);
  575. if (org_dma_ctl & DMACTL_RUN)
  576. iowrite8(DMACTL_RUN, io_base + MAC_REG_TXDMACTL0 + 2);
  577. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  578. if (!(ioread8(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
  579. break;
  580. }
  581. iowrite32(curr_desc_addr, io_base + MAC_REG_TXDMAPTR0);
  582. if (org_dma_ctl & DMACTL_RUN)
  583. iowrite8(DMACTL_RUN, io_base + MAC_REG_TXDMACTL0);
  584. }
  585. /*
  586. * Description:
  587. * Set the chip with current AC0 descriptor address
  588. *
  589. * Parameters:
  590. * In:
  591. * io_base - Base Address for MAC
  592. * curr_desc_addr - Descriptor Address
  593. * Out:
  594. * none
  595. *
  596. * Return Value: none
  597. *
  598. */
  599. /* TxDMA1 = AC0DMA */
  600. void MACvSetCurrAC0DescAddrEx(struct vnt_private *priv,
  601. u32 curr_desc_addr)
  602. {
  603. void __iomem *io_base = priv->PortOffset;
  604. unsigned short ww;
  605. unsigned char org_dma_ctl;
  606. org_dma_ctl = ioread8(io_base + MAC_REG_AC0DMACTL);
  607. if (org_dma_ctl & DMACTL_RUN)
  608. iowrite8(DMACTL_RUN, io_base + MAC_REG_AC0DMACTL + 2);
  609. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  610. if (!(ioread8(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
  611. break;
  612. }
  613. if (ww == W_MAX_TIMEOUT)
  614. pr_debug(" DBG_PORT80(0x26)\n");
  615. iowrite32(curr_desc_addr, io_base + MAC_REG_AC0DMAPTR);
  616. if (org_dma_ctl & DMACTL_RUN)
  617. iowrite8(DMACTL_RUN, io_base + MAC_REG_AC0DMACTL);
  618. }
  619. void MACvSetCurrTXDescAddr(int iTxType, struct vnt_private *priv,
  620. u32 curr_desc_addr)
  621. {
  622. if (iTxType == TYPE_AC0DMA)
  623. MACvSetCurrAC0DescAddrEx(priv, curr_desc_addr);
  624. else if (iTxType == TYPE_TXDMA0)
  625. MACvSetCurrTx0DescAddrEx(priv, curr_desc_addr);
  626. }
  627. /*
  628. * Description:
  629. * Micro Second Delay via MAC
  630. *
  631. * Parameters:
  632. * In:
  633. * io_base - Base Address for MAC
  634. * uDelay - Delay time (timer resolution is 4 us)
  635. * Out:
  636. * none
  637. *
  638. * Return Value: none
  639. *
  640. */
  641. void MACvTimer0MicroSDelay(struct vnt_private *priv, unsigned int uDelay)
  642. {
  643. void __iomem *io_base = priv->PortOffset;
  644. unsigned char byValue;
  645. unsigned int uu, ii;
  646. iowrite8(0, io_base + MAC_REG_TMCTL0);
  647. iowrite32(uDelay, io_base + MAC_REG_TMDATA0);
  648. iowrite8((TMCTL_TMD | TMCTL_TE), io_base + MAC_REG_TMCTL0);
  649. for (ii = 0; ii < 66; ii++) { /* assume max PCI clock is 66Mhz */
  650. for (uu = 0; uu < uDelay; uu++) {
  651. byValue = ioread8(io_base + MAC_REG_TMCTL0);
  652. if ((byValue == 0) ||
  653. (byValue & TMCTL_TSUSP)) {
  654. iowrite8(0, io_base + MAC_REG_TMCTL0);
  655. return;
  656. }
  657. }
  658. }
  659. iowrite8(0, io_base + MAC_REG_TMCTL0);
  660. }
  661. /*
  662. * Description:
  663. * Micro Second One shot timer via MAC
  664. *
  665. * Parameters:
  666. * In:
  667. * io_base - Base Address for MAC
  668. * uDelay - Delay time
  669. * Out:
  670. * none
  671. *
  672. * Return Value: none
  673. *
  674. */
  675. void MACvOneShotTimer1MicroSec(struct vnt_private *priv,
  676. unsigned int uDelayTime)
  677. {
  678. void __iomem *io_base = priv->PortOffset;
  679. iowrite8(0, io_base + MAC_REG_TMCTL1);
  680. iowrite32(uDelayTime, io_base + MAC_REG_TMDATA1);
  681. iowrite8((TMCTL_TMD | TMCTL_TE), io_base + MAC_REG_TMCTL1);
  682. }
  683. void MACvSetMISCFifo(struct vnt_private *priv, unsigned short offset,
  684. u32 data)
  685. {
  686. void __iomem *io_base = priv->PortOffset;
  687. if (offset > 273)
  688. return;
  689. iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
  690. iowrite32(data, io_base + MAC_REG_MISCFFDATA);
  691. iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
  692. }
  693. bool MACbPSWakeup(struct vnt_private *priv)
  694. {
  695. void __iomem *io_base = priv->PortOffset;
  696. unsigned int ww;
  697. /* Read PSCTL */
  698. if (MACbIsRegBitsOff(priv, MAC_REG_PSCTL, PSCTL_PS))
  699. return true;
  700. /* Disable PS */
  701. MACvRegBitsOff(io_base, MAC_REG_PSCTL, PSCTL_PSEN);
  702. /* Check if SyncFlushOK */
  703. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  704. if (ioread8(io_base + MAC_REG_PSCTL) & PSCTL_WAKEDONE)
  705. break;
  706. }
  707. if (ww == W_MAX_TIMEOUT) {
  708. pr_debug(" DBG_PORT80(0x33)\n");
  709. return false;
  710. }
  711. return true;
  712. }
  713. /*
  714. * Description:
  715. * Set the Key by MISCFIFO
  716. *
  717. * Parameters:
  718. * In:
  719. * io_base - Base Address for MAC
  720. *
  721. * Out:
  722. * none
  723. *
  724. * Return Value: none
  725. *
  726. */
  727. void MACvSetKeyEntry(struct vnt_private *priv, unsigned short wKeyCtl,
  728. unsigned int uEntryIdx, unsigned int uKeyIdx,
  729. unsigned char *pbyAddr, u32 *pdwKey,
  730. unsigned char byLocalID)
  731. {
  732. void __iomem *io_base = priv->PortOffset;
  733. unsigned short offset;
  734. u32 data;
  735. int ii;
  736. if (byLocalID <= 1)
  737. return;
  738. pr_debug("MACvSetKeyEntry\n");
  739. offset = MISCFIFO_KEYETRY0;
  740. offset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
  741. data = 0;
  742. data |= wKeyCtl;
  743. data <<= 16;
  744. data |= MAKEWORD(*(pbyAddr + 4), *(pbyAddr + 5));
  745. pr_debug("1. offset: %d, Data: %X, KeyCtl:%X\n",
  746. offset, data, wKeyCtl);
  747. iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
  748. iowrite32(data, io_base + MAC_REG_MISCFFDATA);
  749. iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
  750. offset++;
  751. data = 0;
  752. data |= *(pbyAddr + 3);
  753. data <<= 8;
  754. data |= *(pbyAddr + 2);
  755. data <<= 8;
  756. data |= *(pbyAddr + 1);
  757. data <<= 8;
  758. data |= *pbyAddr;
  759. pr_debug("2. offset: %d, Data: %X\n", offset, data);
  760. iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
  761. iowrite32(data, io_base + MAC_REG_MISCFFDATA);
  762. iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
  763. offset++;
  764. offset += (uKeyIdx * 4);
  765. for (ii = 0; ii < 4; ii++) {
  766. /* always push 128 bits */
  767. pr_debug("3.(%d) offset: %d, Data: %X\n",
  768. ii, offset + ii, *pdwKey);
  769. iowrite16(offset + ii, io_base + MAC_REG_MISCFFNDEX);
  770. iowrite32(*pdwKey++, io_base + MAC_REG_MISCFFDATA);
  771. iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
  772. }
  773. }
  774. /*
  775. * Description:
  776. * Disable the Key Entry by MISCFIFO
  777. *
  778. * Parameters:
  779. * In:
  780. * io_base - Base Address for MAC
  781. *
  782. * Out:
  783. * none
  784. *
  785. * Return Value: none
  786. *
  787. */
  788. void MACvDisableKeyEntry(struct vnt_private *priv, unsigned int uEntryIdx)
  789. {
  790. void __iomem *io_base = priv->PortOffset;
  791. unsigned short offset;
  792. offset = MISCFIFO_KEYETRY0;
  793. offset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
  794. iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
  795. iowrite32(0, io_base + MAC_REG_MISCFFDATA);
  796. iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
  797. }