📄 device_main.c
字号:
static void device_init_rd0_ring(PSDevice pDevice);
static void device_init_rd1_ring(PSDevice pDevice);
static void device_init_defrag_cb(PSDevice pDevice);
static void device_init_td0_ring(PSDevice pDevice);
static void device_init_td1_ring(PSDevice pDevice);
#ifndef PRIVATE_OBJ
static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
#endif
static int ethtool_ioctl(struct net_device *dev, void *useraddr);
static int device_rx_srv(PSDevice pDevice, UINT uIdx);
static int device_tx_srv(PSDevice pDevice, UINT uIdx);
static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
static void device_free_td0_ring(PSDevice pDevice);
static void device_free_td1_ring(PSDevice pDevice);
static void device_free_rd0_ring(PSDevice pDevice);
static void device_free_rd1_ring(PSDevice pDevice);
static void device_free_rings(PSDevice pDevice);
static void device_free_frag_buf(PSDevice pDevice);
/*--------------------- Export Variables --------------------------*/
/*--------------------- Export Functions --------------------------*/
#ifndef PRIVATE_OBJ
static char* get_chip_name(int chip_id) {
int i;
for (i=0;chip_info_table[i].name!=NULL;i++)
if (chip_info_table[i].chip_id==chip_id)
break;
return chip_info_table[i].name;
}
static void __devexit device_remove1(struct pci_dev *pcid)
{
PSDevice pDevice=pci_get_drvdata(pcid);
if (pDevice==NULL)
return;
device_free_info(pDevice);
}
#endif
static void
device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
if (val==-1)
*opt=def;
else if (val<min || val>max) {
DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
devname,name, min,max);
*opt=def;
} else {
DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
devname, name, val);
*opt=val;
}
}
static void
device_set_bool_opt(PU32 opt, int val,BOOL def,U32 flag, char* name,char* devname) {
(*opt)&=(~flag);
if (val==-1)
*opt|=(def ? flag : 0);
else if (val<0 || val>1) {
DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE
"%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
*opt|=(def ? flag : 0);
} else {
DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
devname,name , val ? "TRUE" : "FALSE");
*opt|=(val ? flag : 0);
}
}
static void
device_get_options(PSDevice pDevice, int index, char* devname) {
POPTIONS pOpts = &(pDevice->sOpts);
device_set_int_opt(&pOpts->nRxDescs0,RxDescriptors0[index],
RX_DESC_MIN0, RX_DESC_MAX0, RX_DESC_DEF0, "RxDescriptors0",devname);
device_set_int_opt(&pOpts->nRxDescs1,RxDescriptors1[index],
RX_DESC_MIN1, RX_DESC_MAX1, RX_DESC_DEF1, "RxDescriptors1",devname);
device_set_int_opt(&pOpts->nTxDescs[0],TxDescriptors0[index],
TX_DESC_MIN0, TX_DESC_MAX0, TX_DESC_DEF0, "TxDescriptors0",devname);
device_set_int_opt(&pOpts->nTxDescs[1],TxDescriptors1[index],
TX_DESC_MIN1, TX_DESC_MAX1, TX_DESC_DEF1, "TxDescriptors1",devname);
device_set_bool_opt(&pOpts->flags,IP_byte_align[index],
IP_ALIG_DEF, DEVICE_FLAGS_IP_ALIGN, "IP_byte_align",devname);
device_set_int_opt(&pOpts->int_works,int_works[index],
INT_WORKS_MIN, INT_WORKS_MAX, INT_WORKS_DEF,"Interrupt service works",devname);
device_set_int_opt(&pOpts->rts_thresh, RTSThreshold[index],
RTS_THRESH_MIN, RTS_THRESH_MAX, RTS_THRESH_DEF, "RTS threshold",devname);
device_set_int_opt(&pOpts->frag_thresh, FragThreshold[index],
FRAG_THRESH_MIN, FRAG_THRESH_MAX, FRAG_THRESH_DEF, "Fragmentation threshold",devname);
device_set_int_opt(&pOpts->data_rate, ConnectionRate[index],
DATA_RATE_MIN, DATA_RATE_MAX, DATA_RATE_DEF, "Connection data rate",devname);
device_set_int_opt(&pOpts->channel_num, Channel[index],
CHANNEL_MIN, CHANNEL_MAX, CHANNEL_DEF, "Channel number",devname);
device_set_bool_opt(&pOpts->flags,PreambleType[index],
PREAMBLE_TYPE_DEF, DEVICE_FLAGS_PREAMBLE_TYPE, "Preamble Type",devname);
device_set_bool_opt(&pOpts->flags, OPMode[index],
OP_MODE_DEF, DEVICE_FLAGS_OP_MODE, "Infrastruct or adhoc mode",devname);
device_set_bool_opt(&pOpts->flags, PSMode[index],
PS_MODE_DEF, DEVICE_FLAGS_PS_MODE, "Power saving mode enable",devname);
device_set_int_opt(&pOpts->short_retry, ShortRetryLimit[index],
SHORT_RETRY_MIN, SHORT_RETRY_MAX, SHORT_RETRY_DEF, "Short frame retry limits",devname);
device_set_int_opt(&pOpts->long_retry, LongRetryLimit[index],
LONG_RETRY_MIN, LONG_RETRY_MAX, LONG_RETRY_DEF, "long frame retry limits",devname);
device_set_int_opt(&pOpts->bbp_type, BasebandType[index],
BBP_TYPE_MIN, BBP_TYPE_MAX, BBP_TYPE_DEF, "baseband type",devname);
device_set_bool_opt(&pOpts->flags, b80211hEnable[index],
X80211h_MODE_DEF, DEVICE_FLAGS_80211h_MODE, "80211h mode enable",devname);
device_set_bool_opt(&pOpts->flags, bDiversityANTEnable[index],
DIVERSITY_ANT_DEF, DEVICE_FLAGS_DiversityANT, "Diversity ANT enable",devname);
}
static void
device_set_options(PSDevice pDevice) {
BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
pDevice->uChannel = pDevice->sOpts.channel_num;
pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
pDevice->uConnectionRate = pDevice->sOpts.data_rate;
if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
pDevice->byBBType = pDevice->sOpts.bbp_type;
pDevice->byPacketType = pDevice->byBBType;
pDevice->byAutoFBCtrl = AUTO_FB_0;
pDevice->bUpdateBBVGA = TRUE;
pDevice->byFOETuning = 0;
pDevice->wCTSDuration = 0;
pDevice->byPreambleType = 0;
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
}
static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
{
UINT ii;
DWORD dwDuration = 0;
BYTE byRPI0 = 0;
for(ii=1;ii<8;ii++) {
pDevice->dwRPIs[ii] *= 255;
dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
dwDuration <<= 10;
pDevice->dwRPIs[ii] /= dwDuration;
pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
byRPI0 += pDevice->abyRPIs[ii];
}
pDevice->abyRPIs[0] = (0xFF - byRPI0);
if (pDevice->uNumOfMeasureEIDs == 0) {
VNTWIFIbMeasureReport( pDevice->pMgmt,
TRUE,
pDevice->pCurrMeasureEID,
byResult,
pDevice->byBasicMap,
pDevice->byCCAFraction,
pDevice->abyRPIs
);
} else {
VNTWIFIbMeasureReport( pDevice->pMgmt,
FALSE,
pDevice->pCurrMeasureEID,
byResult,
pDevice->byBasicMap,
pDevice->byCCAFraction,
pDevice->abyRPIs
);
CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
}
}
//
// Initialiation of MAC & BBP registers
//
static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
{
UINT ii;
BYTE byValue;
BYTE byCCKPwrdBm = 0;
BYTE byOFDMPwrdBm = 0;
MACbShutdown(pDevice->PortOffset);
BBvSoftwareReset(pDevice->PortOffset);
if ((InitType == DEVICE_INIT_COLD) ||
(InitType == DEVICE_INIT_DXPL)) {
// Do MACbSoftwareReset in MACvInitialize
MACbSoftwareReset(pDevice->PortOffset);
// force CCK
pDevice->bCCK = TRUE;
pDevice->bAES = FALSE;
pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
pDevice->bNonERPPresent = FALSE;
pDevice->bBarkerPreambleMd = FALSE;
pDevice->wCurrentRate = RATE_1M;
pDevice->byTopOFDMBasicRate = RATE_24M;
pDevice->byTopCCKBasicRate = RATE_1M;
pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
// init MAC
MACvInitialize(pDevice->PortOffset);
// Get Local ID
VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
// Get Channel range
pDevice->byMinChannel = 1;
pDevice->byMaxChannel = CB_MAX_CHANNEL;
// Get Antena
byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
if (byValue & EEP_ANTINV)
pDevice->bTxRxAntInv = TRUE;
else
pDevice->bTxRxAntInv = FALSE;
byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
if (byValue == 0) // if not set default is All
byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
pDevice->ulSQ3TH = 0;//(ULONG) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
pDevice->byAntennaCount = 2;
pDevice->byTxAntennaMode = ANT_B;
pDevice->dwTxAntennaSel = 1;
pDevice->dwRxAntennaSel = 1;
if (pDevice->bTxRxAntInv == TRUE)
pDevice->byRxAntennaMode = ANT_A;
else
pDevice->byRxAntennaMode = ANT_B;
if (pDevice->bDiversityRegCtlON)
pDevice->bDiversityEnable = TRUE;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
else
pDevice->bDiversityEnable = FALSE;
} else {
pDevice->bDiversityEnable = FALSE;
pDevice->byAntennaCount = 1;
pDevice->dwTxAntennaSel = 0;
pDevice->dwRxAntennaSel = 0;
if (byValue & EEP_ANTENNA_AUX) {
pDevice->byTxAntennaMode = ANT_A;
if (pDevice->bTxRxAntInv == TRUE)
pDevice->byRxAntennaMode = ANT_B;
else
pDevice->byRxAntennaMode = ANT_A;
} else {
pDevice->byTxAntennaMode = ANT_B;
if (pDevice->bTxRxAntInv == TRUE)
pDevice->byRxAntennaMode = ANT_A;
else
pDevice->byRxAntennaMode = ANT_B;
}
}
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
// Get RFType
pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
if ((pDevice->byRFType & RF_EMU) != 0) {
// force change RevID for VT3253 emu
pDevice->byRevId = 0x80;
}
pDevice->byRFType &= RF_MASK;
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
if (pDevice->bZoneRegExist == FALSE) {
pDevice->byZoneType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE);
}
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
//Init RF module
RFbInit(pDevice);
//Get Desire Power Value
pDevice->byCurPwr = 0xFF;
pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
// Load power Table
for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
}
pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
}
pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
}
// Load OFDM A Power Table
for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -