mm-only debug patch...
[mmotm.git] / drivers / staging / vt6656 / mac.c
blob55a798668fa5efeac4953a50353d749619f79b13
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
20 * File: mac.c
22 * Purpose: MAC routines
24 * Author: Tevin Chen
26 * Date: May 21, 1996
28 * Functions:
30 * Revision History:
33 #include "tmacro.h"
34 #include "tether.h"
35 #include "desc.h"
36 #include "mac.h"
37 #include "80211hdr.h"
38 #include "rndis.h"
39 #include "control.h"
41 /*--------------------- Static Definitions -------------------------*/
42 //static int msglevel =MSG_LEVEL_DEBUG;
43 static int msglevel =MSG_LEVEL_INFO;
44 /*--------------------- Static Classes ----------------------------*/
46 /*--------------------- Static Variables --------------------------*/
48 /*--------------------- Static Functions --------------------------*/
50 /*--------------------- Export Variables --------------------------*/
52 /*--------------------- Export Functions --------------------------*/
59 * Description:
60 * Set this hash index into multicast address register bit
62 * Parameters:
63 * In:
64 * byHashIdx - Hash index to set
65 * Out:
66 * none
68 * Return Value: none
71 void MACvSetMultiAddrByHash (PSDevice pDevice, BYTE byHashIdx)
73 UINT uByteIdx;
74 BYTE byBitMask;
75 BYTE pbyData[2];
78 // calculate byte position
79 uByteIdx = byHashIdx / 8;
81 // calculate bit position
82 byBitMask = 1;
83 byBitMask <<= (byHashIdx % 8);
84 // turn on the bit
86 pbyData[0] = byBitMask;
87 pbyData[1] = byBitMask;
89 CONTROLnsRequestOut(pDevice,
90 MESSAGE_TYPE_WRITE_MASK,
91 (WORD) (MAC_REG_MAR0 + uByteIdx),
92 MESSAGE_REQUEST_MACREG,
94 pbyData);
100 * Description:
101 * Write MAC Multicast Address Mask
103 * Parameters:
104 * In:
105 * uByteidx - Index of Mask
106 * byData - Mask Value to write
107 * Out:
108 * none
110 * Return Value: none
113 VOID MACvWriteMultiAddr (PSDevice pDevice, UINT uByteIdx, BYTE byData)
115 BYTE byData1;
117 byData1 = byData;
118 CONTROLnsRequestOut(pDevice,
119 MESSAGE_TYPE_WRITE,
120 (WORD) (MAC_REG_MAR0 + uByteIdx),
121 MESSAGE_REQUEST_MACREG,
123 &byData1);
128 * Description:
129 * Shut Down MAC
131 * Parameters:
132 * In:
133 * Out:
134 * none
136 * Return Value: TRUE if success; otherwise FALSE
139 BOOL MACbShutdown (PSDevice pDevice)
141 CONTROLnsRequestOutAsyn(pDevice,
142 MESSAGE_TYPE_MACSHUTDOWN,
146 NULL
148 return TRUE;
151 void MACvSetBBType(PSDevice pDevice,BYTE byType)
153 BYTE pbyData[2];
156 pbyData[0] = byType;
157 pbyData[1] = EnCFG_BBType_MASK;
159 CONTROLnsRequestOut(pDevice,
160 MESSAGE_TYPE_WRITE_MASK,
161 MAC_REG_ENCFG0,
162 MESSAGE_REQUEST_MACREG,
164 pbyData
168 void MACvSetMISCFifo (PSDevice pDevice, WORD wOffset, DWORD dwData)
170 BYTE pbyData[4];
172 if (wOffset > 273)
173 return;
174 pbyData[0] = (BYTE)dwData;
175 pbyData[1] = (BYTE)(dwData>>8);
176 pbyData[2] = (BYTE)(dwData>>16);
177 pbyData[3] = (BYTE)(dwData>>24);
179 CONTROLnsRequestOut(pDevice,
180 MESSAGE_TYPE_WRITE_MISCFF,
181 wOffset,
184 pbyData
189 * Description:
190 * Disable the Key Entry by MISCFIFO
192 * Parameters:
193 * In:
194 * dwIoBase - Base Address for MAC
196 * Out:
197 * none
199 * Return Value: none
202 void MACvDisableKeyEntry (PSDevice pDevice, UINT uEntryIdx)
204 WORD wOffset;
205 BYTE byData;
208 byData = (BYTE) uEntryIdx;
210 wOffset = MISCFIFO_KEYETRY0;
211 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
213 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
214 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
215 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
217 //issue write misc fifo command to device
218 CONTROLnsRequestOut(pDevice,
219 MESSAGE_TYPE_CLRKEYENTRY,
223 &byData
229 * Description:
230 * Set the Key by MISCFIFO
232 * Parameters:
233 * In:
234 * dwIoBase - Base Address for MAC
236 * Out:
237 * none
239 * Return Value: none
242 void MACvSetKeyEntry (PSDevice pDevice, WORD wKeyCtl, UINT uEntryIdx, UINT uKeyIdx, PBYTE pbyAddr, PDWORD pdwKey)
244 PBYTE pbyKey;
245 WORD wOffset;
246 DWORD dwData1,dwData2;
247 int ii;
248 BYTE pbyData[24];
254 if ( pDevice->byLocalID <= MAC_REVISION_A1 ) {
255 if ( pDevice->sMgmtObj.byCSSPK == KEY_CTL_CCMP )
256 return;
259 wOffset = MISCFIFO_KEYETRY0;
260 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
262 dwData1 = 0;
263 dwData1 |= wKeyCtl;
264 dwData1 <<= 16;
265 dwData1 |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData1, wKeyCtl);
269 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
270 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
271 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
273 //wOffset++;
275 dwData2 = 0;
276 dwData2 |= *(pbyAddr+3);
277 dwData2 <<= 8;
278 dwData2 |= *(pbyAddr+2);
279 dwData2 <<= 8;
280 dwData2 |= *(pbyAddr+1);
281 dwData2 <<= 8;
282 dwData2 |= *(pbyAddr+0);
284 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2. wOffset: %d, Data: %lX\n", wOffset, dwData2);
286 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
287 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
288 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
290 //wOffset++;
292 //wOffset += (uKeyIdx * 4);
293 /* for (ii=0;ii<4;ii++) {
294 // alway push 128 bits
295 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
296 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
297 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
298 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
301 pbyKey = (PBYTE)pdwKey;
303 pbyData[0] = (BYTE)dwData1;
304 pbyData[1] = (BYTE)(dwData1>>8);
305 pbyData[2] = (BYTE)(dwData1>>16);
306 pbyData[3] = (BYTE)(dwData1>>24);
307 pbyData[4] = (BYTE)dwData2;
308 pbyData[5] = (BYTE)(dwData2>>8);
309 pbyData[6] = (BYTE)(dwData2>>16);
310 pbyData[7] = (BYTE)(dwData2>>24);
311 for(ii=8;ii<24;ii++)
312 pbyData[ii] = *pbyKey++;
314 CONTROLnsRequestOut(pDevice,
315 MESSAGE_TYPE_SETKEY,
316 wOffset,
317 (WORD)uKeyIdx,
319 pbyData
326 void MACvRegBitsOff(PSDevice pDevice, BYTE byRegOfs, BYTE byBits)
328 BYTE pbyData[2];
330 pbyData[0] = 0;
331 pbyData[1] = byBits;
333 CONTROLnsRequestOut(pDevice,
334 MESSAGE_TYPE_WRITE_MASK,
335 byRegOfs,
336 MESSAGE_REQUEST_MACREG,
338 pbyData
343 void MACvRegBitsOn(PSDevice pDevice, BYTE byRegOfs, BYTE byBits)
345 BYTE pbyData[2];
348 pbyData[0] = byBits;
349 pbyData[1] = byBits;
351 CONTROLnsRequestOut(pDevice,
352 MESSAGE_TYPE_WRITE_MASK,
353 byRegOfs,
354 MESSAGE_REQUEST_MACREG,
356 pbyData
360 void MACvWriteWord(PSDevice pDevice, BYTE byRegOfs, WORD wData)
362 BYTE pbyData[2];
365 pbyData[0] = (BYTE)(wData & 0xff);
366 pbyData[1] = (BYTE)(wData >> 8);
368 CONTROLnsRequestOut(pDevice,
369 MESSAGE_TYPE_WRITE,
370 byRegOfs,
371 MESSAGE_REQUEST_MACREG,
373 pbyData
378 void MACvWriteBSSIDAddress(PSDevice pDevice, PBYTE pbyEtherAddr)
380 BYTE pbyData[6];
383 pbyData[0] = *((PBYTE)pbyEtherAddr);
384 pbyData[1] = *((PBYTE)pbyEtherAddr+1);
385 pbyData[2] = *((PBYTE)pbyEtherAddr+2);
386 pbyData[3] = *((PBYTE)pbyEtherAddr+3);
387 pbyData[4] = *((PBYTE)pbyEtherAddr+4);
388 pbyData[5] = *((PBYTE)pbyEtherAddr+5);
390 CONTROLnsRequestOut(pDevice,
391 MESSAGE_TYPE_WRITE,
392 MAC_REG_BSSID0,
393 MESSAGE_REQUEST_MACREG,
395 pbyData
399 void MACvEnableProtectMD(PSDevice pDevice)
401 BYTE pbyData[2];
404 pbyData[0] = EnCFG_ProtectMd;
405 pbyData[1] = EnCFG_ProtectMd;
407 CONTROLnsRequestOut(pDevice,
408 MESSAGE_TYPE_WRITE_MASK,
409 MAC_REG_ENCFG0,
410 MESSAGE_REQUEST_MACREG,
412 pbyData
416 void MACvDisableProtectMD(PSDevice pDevice)
418 BYTE pbyData[2];
421 pbyData[0] = 0;
422 pbyData[1] = EnCFG_ProtectMd;
424 CONTROLnsRequestOut(pDevice,
425 MESSAGE_TYPE_WRITE_MASK,
426 MAC_REG_ENCFG0,
427 MESSAGE_REQUEST_MACREG,
429 pbyData
433 void MACvEnableBarkerPreambleMd(PSDevice pDevice)
435 BYTE pbyData[2];
438 pbyData[0] = EnCFG_BarkerPream;
439 pbyData[1] = EnCFG_BarkerPream;
441 CONTROLnsRequestOut(pDevice,
442 MESSAGE_TYPE_WRITE_MASK,
443 MAC_REG_ENCFG2,
444 MESSAGE_REQUEST_MACREG,
446 pbyData
450 void MACvDisableBarkerPreambleMd(PSDevice pDevice)
452 BYTE pbyData[2];
455 pbyData[0] = 0;
456 pbyData[1] = EnCFG_BarkerPream;
458 CONTROLnsRequestOut(pDevice,
459 MESSAGE_TYPE_WRITE_MASK,
460 MAC_REG_ENCFG2,
461 MESSAGE_REQUEST_MACREG,
463 pbyData
468 void MACvWriteBeaconInterval(PSDevice pDevice, WORD wInterval)
470 BYTE pbyData[2];
472 pbyData[0] = (BYTE) (wInterval & 0xff);
473 pbyData[1] = (BYTE) (wInterval >> 8);
475 CONTROLnsRequestOut(pDevice,
476 MESSAGE_TYPE_WRITE,
477 MAC_REG_BI,
478 MESSAGE_REQUEST_MACREG,
480 pbyData