2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
22 * Purpose: MAC routines
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 --------------------------*/
60 * Set this hash index into multicast address register bit
64 * byHashIdx - Hash index to set
71 void MACvSetMultiAddrByHash (PSDevice pDevice
, BYTE byHashIdx
)
73 unsigned int uByteIdx
;
78 // calculate byte position
79 uByteIdx
= byHashIdx
/ 8;
81 // calculate bit position
83 byBitMask
<<= (byHashIdx
% 8);
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
,
101 * Write MAC Multicast Address Mask
105 * uByteidx - Index of Mask
106 * byData - Mask Value to write
113 void MACvWriteMultiAddr(PSDevice pDevice
, unsigned int uByteIdx
, BYTE byData
)
118 CONTROLnsRequestOut(pDevice
,
120 (WORD
) (MAC_REG_MAR0
+ uByteIdx
),
121 MESSAGE_REQUEST_MACREG
,
138 void MACbShutdown(PSDevice pDevice
)
140 CONTROLnsRequestOutAsyn(pDevice
,
141 MESSAGE_TYPE_MACSHUTDOWN
,
149 void MACvSetBBType(PSDevice pDevice
,BYTE byType
)
155 pbyData
[1] = EnCFG_BBType_MASK
;
157 CONTROLnsRequestOut(pDevice
,
158 MESSAGE_TYPE_WRITE_MASK
,
160 MESSAGE_REQUEST_MACREG
,
166 void MACvSetMISCFifo (PSDevice pDevice
, WORD wOffset
, DWORD dwData
)
172 pbyData
[0] = (BYTE
)dwData
;
173 pbyData
[1] = (BYTE
)(dwData
>>8);
174 pbyData
[2] = (BYTE
)(dwData
>>16);
175 pbyData
[3] = (BYTE
)(dwData
>>24);
177 CONTROLnsRequestOut(pDevice
,
178 MESSAGE_TYPE_WRITE_MISCFF
,
188 * Disable the Key Entry by MISCFIFO
192 * dwIoBase - Base Address for MAC
200 void MACvDisableKeyEntry(PSDevice pDevice
, unsigned int uEntryIdx
)
206 byData
= (BYTE
) uEntryIdx
;
208 wOffset
= MISCFIFO_KEYETRY0
;
209 wOffset
+= (uEntryIdx
* MISCFIFO_KEYENTRYSIZE
);
211 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
212 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
213 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
215 //issue write misc fifo command to device
216 CONTROLnsRequestOut(pDevice
,
217 MESSAGE_TYPE_CLRKEYENTRY
,
228 * Set the Key by MISCFIFO
232 * dwIoBase - Base Address for MAC
240 void MACvSetKeyEntry(PSDevice pDevice
, WORD wKeyCtl
,
241 unsigned int uEntryIdx
, unsigned int uKeyIdx
,
242 PBYTE pbyAddr
, PDWORD pdwKey
)
246 DWORD dwData1
,dwData2
;
250 if ( pDevice
->byLocalID
<= MAC_REVISION_A1
) {
251 if ( pDevice
->sMgmtObj
.byCSSPK
== KEY_CTL_CCMP
)
255 wOffset
= MISCFIFO_KEYETRY0
;
256 wOffset
+= (uEntryIdx
* MISCFIFO_KEYENTRYSIZE
);
261 dwData1
|= MAKEWORD(*(pbyAddr
+4), *(pbyAddr
+5));
263 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset
, dwData1
, wKeyCtl
);
265 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
266 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
267 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
272 dwData2
|= *(pbyAddr
+3);
274 dwData2
|= *(pbyAddr
+2);
276 dwData2
|= *(pbyAddr
+1);
278 dwData2
|= *(pbyAddr
+0);
280 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"2. wOffset: %d, Data: %lX\n", wOffset
, dwData2
);
282 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
283 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
284 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
288 //wOffset += (uKeyIdx * 4);
289 /* for (ii=0;ii<4;ii++) {
290 // alway push 128 bits
291 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
292 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
293 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
294 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
297 pbyKey
= (PBYTE
)pdwKey
;
299 pbyData
[0] = (BYTE
)dwData1
;
300 pbyData
[1] = (BYTE
)(dwData1
>>8);
301 pbyData
[2] = (BYTE
)(dwData1
>>16);
302 pbyData
[3] = (BYTE
)(dwData1
>>24);
303 pbyData
[4] = (BYTE
)dwData2
;
304 pbyData
[5] = (BYTE
)(dwData2
>>8);
305 pbyData
[6] = (BYTE
)(dwData2
>>16);
306 pbyData
[7] = (BYTE
)(dwData2
>>24);
307 for (ii
= 8; ii
< 24; ii
++)
308 pbyData
[ii
] = *pbyKey
++;
310 CONTROLnsRequestOut(pDevice
,
322 void MACvRegBitsOff(PSDevice pDevice
, BYTE byRegOfs
, BYTE byBits
)
329 CONTROLnsRequestOut(pDevice
,
330 MESSAGE_TYPE_WRITE_MASK
,
332 MESSAGE_REQUEST_MACREG
,
339 void MACvRegBitsOn(PSDevice pDevice
, BYTE byRegOfs
, BYTE byBits
)
347 CONTROLnsRequestOut(pDevice
,
348 MESSAGE_TYPE_WRITE_MASK
,
350 MESSAGE_REQUEST_MACREG
,
356 void MACvWriteWord(PSDevice pDevice
, BYTE byRegOfs
, WORD wData
)
361 pbyData
[0] = (BYTE
)(wData
& 0xff);
362 pbyData
[1] = (BYTE
)(wData
>> 8);
364 CONTROLnsRequestOut(pDevice
,
367 MESSAGE_REQUEST_MACREG
,
374 void MACvWriteBSSIDAddress(PSDevice pDevice
, PBYTE pbyEtherAddr
)
379 pbyData
[0] = *((PBYTE
)pbyEtherAddr
);
380 pbyData
[1] = *((PBYTE
)pbyEtherAddr
+1);
381 pbyData
[2] = *((PBYTE
)pbyEtherAddr
+2);
382 pbyData
[3] = *((PBYTE
)pbyEtherAddr
+3);
383 pbyData
[4] = *((PBYTE
)pbyEtherAddr
+4);
384 pbyData
[5] = *((PBYTE
)pbyEtherAddr
+5);
386 CONTROLnsRequestOut(pDevice
,
389 MESSAGE_REQUEST_MACREG
,
395 void MACvEnableProtectMD(PSDevice pDevice
)
400 pbyData
[0] = EnCFG_ProtectMd
;
401 pbyData
[1] = EnCFG_ProtectMd
;
403 CONTROLnsRequestOut(pDevice
,
404 MESSAGE_TYPE_WRITE_MASK
,
406 MESSAGE_REQUEST_MACREG
,
412 void MACvDisableProtectMD(PSDevice pDevice
)
418 pbyData
[1] = EnCFG_ProtectMd
;
420 CONTROLnsRequestOut(pDevice
,
421 MESSAGE_TYPE_WRITE_MASK
,
423 MESSAGE_REQUEST_MACREG
,
429 void MACvEnableBarkerPreambleMd(PSDevice pDevice
)
434 pbyData
[0] = EnCFG_BarkerPream
;
435 pbyData
[1] = EnCFG_BarkerPream
;
437 CONTROLnsRequestOut(pDevice
,
438 MESSAGE_TYPE_WRITE_MASK
,
440 MESSAGE_REQUEST_MACREG
,
446 void MACvDisableBarkerPreambleMd(PSDevice pDevice
)
452 pbyData
[1] = EnCFG_BarkerPream
;
454 CONTROLnsRequestOut(pDevice
,
455 MESSAGE_TYPE_WRITE_MASK
,
457 MESSAGE_REQUEST_MACREG
,
464 void MACvWriteBeaconInterval(PSDevice pDevice
, WORD wInterval
)
468 pbyData
[0] = (BYTE
) (wInterval
& 0xff);
469 pbyData
[1] = (BYTE
) (wInterval
>> 8);
471 CONTROLnsRequestOut(pDevice
,
474 MESSAGE_REQUEST_MACREG
,